An auto-generated TypeScript client for the infra-risk-vis backend API
This package is published through the GitHub npm package repository, in the @nismod scope.
The package is publicly available, but requires a GitHub Personal Access Token to install from the registry.
In order to install the API client package as a dependency of another package:
-
Create a GitHub Personal Access Token (classic) with the
read:packagespermission selected. It's recommended to set an expiration date for the token and repeat this process when the token expires. -
Set up the dependent repository to look for packages from the
@nismodscope in the GitHub npm registry. This can be done by creating an.npmrcfile in the project directory and adding to it a line such as@nismod:registry=https://npm.pkg.github.com -
Copy the generated token and instruct npm to use it when authenticating to the GitHub registry.
NOTE: the token should not be committed to source control.
- One option is to create an
.npmrcfile in the user's home directory (~/.npmrc), and place the following line in the file (replacing TOKEN with the generated token)//npm.pkg.github.com/:_authToken=TOKEN - Alternatively, npm supports environment variable interpolation in
.npmrcso the repo-local.npmrccould contain a linewhere the//npm.pkg.github.com/:_authToken=${GH_NPM_AUTH}GH_NPM_AUTHvariable needs to be set to the generated token when installing a package.
- One option is to create an
-
Finally, install the client package:
npm install -S @nismod/irv-api-client
Example usage:
import { ApiClient } from '@nismod/irv-api-client';
const apiClient = new ApiClient({
// optionally set API base URL - can be relative or absolute
BASE: '/api'
});
apiClient.
.colormaps
.colormapGetColormap({
colormap: 'reds',
stretchRange: '[0,1]'
})
.then((colormap) => {
// do something with the data
});- Obtain the
openapi.jsonfile describing the recent version of the API. For example, the live version of the API is available at https://global.infrastructureresilience.org/api/openapi.json - Run
npm run generate-client - Commit the
openapi.jsonand the updated source files - Run
npm version X.X.Xto update the version stored inpackage.jsonandpackage-lock.json. This creates a git commit and tag. - Push the changes to the repository - it is set up to automatically publish a package using GitHub Actions (see
.github/workflows/build_and_publish.yml).
If you want to share with other team members a version of the package that is currently under development, you can do that by publishing a development version of the package.
- Create a branch on which a new version of this package will be developed
- Update the version of the package to a pre-release version such as X.X.X-dev.X (e.g. 0.9.0-dev.1)
- Push branch to remote
- In GitHub Actions, manually trigger the
build_and_publish_dev.ymlworkflow. When prompted, choose the development branch as the target ref. There's another parameter for the tag to apply to the release, but the default ofdevcan be left unchanged. - Other developers can easily install projects that rely on the
0.9.0-dev.1version (as long as they have access to the package registry where this package is published)