npm.io
0.0.6 • Published 3 years ago

@oneboard/node-sdk

Licence
—
Version
0.0.6
Deps
2
Size
16 kB
Vulns
0
Weekly
0

@oneboard/node-sdk

Example

import OneBoard from '@oneboard/node-sdk';

const oneBoard = new OneBoard({
    privateKey: '<PrivateKey>',
    appPublicKey: '<AppPublicKey>',
    appToken: '<Token>',
  });

const result = await oneBoard.getVerificationRequestAccessToken(<UserId>);

Installing

npm install @oneboard/node-sdk

Configuration

Specify configuration options when creating a OneBoard instance

Example
new OneBoard({ ...options });
Options
Option Type Required Desciption
privateKey String Yes Privet key for sign requests
appPublicKey String Yes Public key for your OneBoard application
appToken String Yes OneBoard authorization token
webhookSecretKey String No Secret key for check webhook hash sum
testing Boolean No Flag for using the test server
apiOrigin String No You can provide custom OneBoard API url, if you use custom OneBoard instance

API

getVerificationRequestAccessToken(userId, [options])

Returns an Promise with an access token for the specified userId to work with a verification request

  • userId can be string or number
Example
await oneBoard.getVerificationRequestAccessToken(userId, {
  ttl: 3600,
  email: 'testmail123@mail.com',
});
Options
  • ttl: (Optional) Lifetime for access token in seconds. Defaults to 3600.
  • email: (Optional) Current user's mail.
request(requestOptions) / requestSigned(requestOptions)

Send http request to OneBoard API

  • request used for simple request
  • requestSigned used for signed request
  • Both methods use the same options and return the same response format
Example
await oneBoard.requestSigned({
  path: '/api/v1/...',
  method: 'POST',
  body: {
    foo: 1,
  },
});
checkWebhookHashSum(hashSum, params)

Check hash sum from webhook. Return boolean

  • hashSum string from X-App-Sig header from webhook request
  • params data for create test hash
Example
await oneBoard.checkWebhookHashSum(
  'rAxPRgdw1AYVoKSvoRoVDVOXS7PefCgFYSZMjfmclxE=',
  {
    url: 'https://test.com/oneboard/webhook',
    timestamp: '834007431',
    body: '{...}',
  }
);
Params
Option Type Required Desciption
url String Yes Full webhook url
timestamp String Yes Timestamp from X-App-Timestamp header from webhook request
body String Yes Webhook body
getWebhookHashSum(params)

Create hash sum from webhook request. Return string

  • params same format as checkWebhookHashSum method
Example
await oneBoard.getWebhookHashSum({
  url: 'https://test.com/oneboard/webhook',
  timestamp: '834007431',
  body: '{...}',
});