yumisign v1.2.6
YumiSign Library
The YumiSign Node library provides convenient access to the YumiSign API from applications written in JavaScript.
Requirements
Node 12 or higher.
Installation
Install the package with:
npm install yumisign --save
Usage
The package needs to be configured with the corresponding YumiSign integration app client id and secret.
const yumisign = require('yumisign')({
clientId: 'client_id',
clientSecret: 'client_secret',
});
yumisign.workspaces.list()
.then(workspaces => console.log(workspaces))
.catch(error => console.error(error));
Or using ES modules and async
/await
:
import YumiSign from 'yumisign';
const yumisign = new YumiSign({
clientId: 'client_id',
clientSecret: 'client_secret',
});
const workspaces = await yumisign.workspaces.list();
console.log(workspaces);
Usage with TypeScript
import YumiSign from 'yumisign';
const yumisign = new YumiSign({
clientId: 'client_id',
clientSecret: 'client_secret',
});
const getWorkspaces = async () => {
const workspaces: YumiSign.Workspace[] = await yumisign.workspaces.list();
console.log(workspaces);
};
getWorkspaces();
Using Promises
Every method returns a chainable promise which can be used instead of a regular callback:
yumisign.workspaces
.list()
.then((workspaces) => {
// Add your custom logic here.
})
.catch((err) => {
// Handle error.
});
Webhook signing
YumiSign can optionally sign the webhook events it sends to your endpoint, allowing you to validate that they were not sent by a third-party.
Please note that you must pass the raw request body, exactly as received from YumiSign, to the constructEvent()
function; this will not work with a parsed (i.e., JSON) request body.
You can find the YumiSign signature header in the request header as YUMISIGN-SIGNATURE
.
import YumiSign from 'yumisign';
const yumisign = new YumiSign();
const event = yumisign.webhooks.constructEvent(
rawBody,
signatureHeader,
webhookSecret
);
Auto pagination
Some lists return a paginated response that can be handled automatically. Usage depends on Node versions and styles.
for await (const template of yumisign.templates.list()) {
handle(template);
if (stop()) {
break;
}
}
await yumisign.templates.list().each(async (template) => {
await handle(template);
if (stop()) {
return false;
}
});
yumisign.templates.list().each((template) =>
handle(template).then(() => {
if (stop()) {
return false;
}
})
);
For some cases if you expect a small number of items, you can directly retrieve items as array.
By default, the limit
is fixed to 1000 items and cannot be greater.
You can specify a different limit as an option.
const templates = await yumisign.templates.list().toArray({ limit: 1000 });
Configuration
The package can be initialized with several configurations:
const yumisign = YumiSign({
clientId: 'client_id',
clientSecret: 'client_secret',
baseUri: 'https://app.yumisign.com',
oAuthTokenStore: {
get: () => {
// Return the stored oauth token if exist
},
set: (oAuthToken) => {
// Save the oauth token in your store
},
del: () => {
// Remove the stored oauth token if exist
}
}
});
Parameter | Required | Default | Description |
---|---|---|---|
clientId | False | No default value | Your YumiSign integration app client id (Required for api requests) |
clientSecret | False | No default value | Your YumiSign integration app client secret (Required for api requests) |
baseUri | False | https://app.yumisign.com | Base uri of YumiSign website |
oAuthTokenStore | False | Local storage | A store object used to fetch save and remove your oauth token |
Development
Run tests:
npm install
npm run build
npm run test
Run a single test:
npm run mocha test/Errors.spec.ts
Run prettier:
npm run fix