An auto-generated TypeScript client for the irv-autopkg 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:packages
permission 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
@nismod
scope in the GitHub npm registry. This can be done by creating an.npmrc
file 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
.npmrc
file 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
.npmrc
so the repo-local.npmrc
could contain a linewhere the//npm.pkg.github.com/:_authToken=${GH_NPM_AUTH}
GH_NPM_AUTH
variable 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-autopkg-client
Example usage:
import { AutoPkgClient } from '@nismod/irv-autopkg-client';
const autopkgClient = new AutoPkgClient({
// optionally set API base URL - can be relative or absolute
BASE: '/api'
});
autopkgClient
.boundaries
.getAllBoundarySummariesV1BoundariesGet()
.then((boundaries) => {
// do something with the data
});
- Obtain the
openapi.json
file describing the recent version of the API. For example, the live version of the API is available at https://global.infrastructureresilience.org/extract/openapi.json - Run
npm run generate-client
- Commit the
openapi.json
and the updated source files - Run
npm version X.X.X
to update the version stored inpackage.json
andpackage-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
).