Recommended versions node >=16 and npm >=8.
A stable 1.x version of this package is available as js-dataverse
at https://www.npmjs.com/package/js-dataverse
Install the package stable version using npm:
npm install js-dataverse
An unstable 2.x version of this package with breaking changes is under development.
Until a 2.0 version is officially released, it can be installed from https://github.com/IQSS/dataverse-client-javascript/pkgs/npm/dataverse-client-javascript
Two different versions are being pushed to the GitHub Packages registry:
-
PR-Generated Versions:
- These versions are generated from pull request commits.
- They follow the structure
2.0.0-pr<pr_number>.<commit_hash>
, wherepr_number
is the number of the pull request, andcommit_hash
is the specific commit hash from the PR branch. - These versions are unstable and correspond to the state of the package during the pull request.
-
Develop Alpha Versions:
- These versions are generated on every commit made to the
develop
branch, ideally after each pull request is merged. - They follow the structure
2.0.0-alpha.<number>
, wherenumber
is an incremental value that starts at 1 and increases with each build. - These versions are also unstable and represent the latest work in progress on the
develop
branch.
- These versions are generated on every commit made to the
To install the @iqss/dataverse-client-javascript
from the GitHub registry, follow these steps to create an .npmrc
file in the root of your project using your GitHub token.
-
Create
.npmrc
in your project's root directory.touch .npmrc
-
Replace the Token
Open the newly created
.npmrc
file and replaceYOUR_GITHUB_TOKEN
with your actual GitHub token.legacy-peer-deps=true //npm.pkg.github.com/:_authToken=<YOUR_GITHUB_AUTH_TOKEN> @iqss:registry=https://npm.pkg.github.com/
If you don't have a GitHub token yet, follow these steps:
-
Go to your GitHub account settings.
-
Navigate to "Developer settings" -> "Personal access tokens."
-
Click "Personal access tokens" -> "Tokens (classic)" -> "Generate new token (classic)".
-
Give the token a name and select the "read:packages" scope.
-
Copy the generated token.
-
Replace
YOUR_GITHUB_AUTH_TOKEN
in the.npmrc
file with the copied token.
Now, you should be able to install the Dataverse JavaScript client using npm.
Install the package development version using npm:
npm install @iqss/dataverse-client-javascript
In order for the package to connect to the Dataverse API, there is an APIConfig
object that should be initialized to set the preferred authentication mechanism with the associated credentials for connecting to the Dataverse API.
Currently, the supported authentication mechanisms are:
-
API Key: The recommended authentication mechanism. The API Key should correspond to a particular Dataverse user account.
-
Session Cookie: This is an experimental feature primarily designed for Dataverse SPA development. To use this mechanism, you must enable the corresponding feature flag in the Dataverse installation (See https://guides.dataverse.org/en/latest/installation/config.html?#feature-flags). It is recommended not to use this mechanism and instead use API Key authentication.
It is recommended to globally initialize the ApiConfig
object from the consuming application, as the configuration will be read on every API call made by the package's use cases.
For example, in a React application, we can globally initialize the ApiConfig
object in the App
file, like this:
ApiConfig.init(<DATAVERSE_API_BASE_URL>, DataverseApiAuthMechanism.API_KEY, <DATAVERSE_API_KEY>)
function App() {
/* Yor App code */
}
export default App
The same example but with example values set:
ApiConfig.init(
'http://localhost:8000/api/v1',
DataverseApiAuthMechanism.API_KEY,
'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
)
function App() {
/* Yor App code */
}
export default App
We can initialize the ApiConfig
object as an unauthenticated user, by setting undefined
as the API Key value.
This will allow use cases that do not require authentication to be successfully executed, but those that do require authentication will fail.