@harvard-lil/perma-js-sdk
v0.0.5
Published
A JavaScript library to interact with Perma.cc's REST API
Readme
perma-js-sdk
A JavaScript library to interact with Perma.cc's REST API.
⚠️ This is an early version.
Summary
- Getting started
- Stack and compatibility
- API documentation
- Development CLI
- Environment variables
- Publishing a new version
Getting started
Installation as a dependency
You may use npm or your favorite JavaScript package manager to install perma-js-sdk as a dependency.
npm install @harvard-lil/perma-js-sdkDirectly in the browser
This library can be imported directly in the browser.
You may use a service such as unpkg.com to import its latest version from npmjs.org.
import { PermaAPI } from "https://unpkg.com/@harvard-lil/perma-js-sdk@latest/index.js";Quick Example
Here a quick example of how to use the PermaAPI class to interact with Perma.cc's API.
See the API Documentation for details.
import { PermaAPI } from "@harvard-lil/perma-js-sdk";
try {
const api = new PermaAPI(API_KEY);
const archive = await api.createArchive("https://lil.harvard.edu");
console.log(`Archive created -- guid: ${archive.guid}`);
}
catch(err) {
// ...
}Stack and compatibility
Stack
This library, by design, has no runtime dependency and does not require a build step in most cases.
Compatibility notes
This library:
- [...] uses the Fetch API.Versions of Node.js that do not support
fetch()may instead usenode-fetchand make it globally accessible. - [...] is ES module-based and doesn't support CommonJS syntax.
- [...] was written so it can be run without transpiling in:
- Latest Chromium
- Latest Gecko
- Latest WebKit
- Latest Node.js (+ latest Node.js LTS with
node-fetch)
API documentation
Reference
PermaAPIclass documentation (Automatically generated)- Associated types documentation (Automatically generated)
Notes
Misc
Development CLI
docgen
npm run docgenRefreshes files under /doc using JSDoc comments in index.js and types.js.
test-unit
npm run test-unitRuns index.unit.test.js using Jest.
test-integration
npm run test-integrationRuns index.integration.test.js using Jest.
This test suite requires the TESTS_API_KEY and TESTS_FORCE_BASE_URL environment variables to be set.
test-integration-local
npm run test-integration-localSame as test-integration but:
- Reads environment variables from
.envfile if available - Ignores TLS certificates errors (so the tests can be run against a local instance of the Perma API)
Environment variables
Scope: Integration tests
The following environment variables are only used in the context of the integration tests suite.
| Name | Required? | Description |
| --- | --- | --- |
| TESTS_API_KEY | Yes | API key to be used to perform integration tests. Can be of any type of account. |
| TESTS_FORCE_BASE_URL | No | Base API url to be used to perform integration tests. If not set, will default to https://api.perma.cc. |
Publishing a new version
Once changes have been merged to develop and a new version is ready, please follow these steps to deploy a new version of the package:
- Run unit tests:
npm run test-unit - Run integration tests:
npm run test-integration-local - Update documentation:
npm run docgen - Update NPM package version number:
npm version patch --no-git-tag-version - Publish on NPM:
npm publish --access public - Commit and push changes to
develop - PR and merge to
main, with version number as PR title.
ℹ️ Steps 1-5 can be replaced by
./test-and-publish.sh
You will need access to the @harvard-lil organization on npmjs.org to publish new versions of the package.
