The official Truework API Node.js SDK.
- 📚 API Documentation
- 🏠 Truework
- 👷♀️ Careers
npm i @truework/sdk --saveconst { truework } = require('@truework/sdk');
const client = truework({ token: TRUEWORK_ACCESS_TOKEN });By default, the SDK will use the latest version of our API. To request a different version, pass it when configuring your client.
const client = truework({
token: TRUEWORK_ACCESS_TOKEN,
version: '2019-10-15',
});To set a timeout on requests, pass in the timeout value in milliseconds when configuring the client. If a request times out, it will abort with got.TimeoutError. Most applicable when used in conjunction with synchronous creation of verifications.
const client = truework({
token: TRUEWORK_ACCESS_TOKEN,
timeout: 6000,
});To use the SDK to call the Truework Sandbox, configure the client for the sandbox environment.
const { truework, ENVIRONMENT } = require('@truework/sdk');
const client = truework({
token: TRUEWORK_SANDBOX_TOKEN,
environment: ENVIRONMENT.SANDBOX,
});Please review the API Documentation for all terminology. If you're using Typescript, have a look at the types.
All requests are made using got, and so responses implement a got response object.
const {
body: { count, results },
} = await client.verifications.get();Request
params-object- optionalstate-string- requiredlimit-numberoffset-number
Response
Returns a PaginatedResponse containing an array of Verifications.
Example
await client.verifications.get();
await client.verifications.get({ limit: 10 });Request
params-object- requiredid-string- required
Response
Returns a Verification object.
Example
await client.verifications.getOne({ id: 'abc123' });Request
params-object- requiredtype-VerificationType- requiredpermissible_purpose-PermissiblePurpose- requiredtarget-Target- requireddocuments-Documentadditional_information-string
Response
Returns the full Verification object.
Example
await client.verifications.create({
type: 'employment',
permissible_purpose: 'employment',
target: {
first_name: 'Megan',
last_name: 'Rapinoe',
social_security_number: '123121234',
company: {
name: 'USWNT',
},
},
additional_information: 'Lorem ipsum dolor...',
});Executes the request synchronously, attempting to return the completed verification rather than sending a webhook on
completion. It is recommended to use the client timeout param in conjunction with this method.
Request
params-object- requiredtype-VerificationType- requiredpermissible_purpose-PermissiblePurpose- requiredtarget-Target- requireddocuments-Documentadditional_information-string
syncParams-objectstrategy-RequestSyncStrategy
Response
Returns the full Verification object, with reports if successful.
Example
const {
truework,
REQUEST_SYNC_STRATEGIES,
VERIFICATION_TYPES,
PERMISSIBLE_PURPOSES,
} = require('@truework/sdk');
const client = truework({
token: TRUEWORK_ACCESS_TOKEN,
timeout: 6000,
});
const res = await client.verifications.create(
{
type: VERIFICATION_TYPES.EMPLOYMENT,
permissible_purpose: PERMISSIBLE_PURPOSES.EMPLOYMENT,
target: {
first_name: 'Megan',
last_name: 'Rapinoe',
social_security_number: '123121234',
date_of_birth: '1990-09-26',
},
additional_information: 'Lorem ipsum dolor...',
},
{
strategy: REQUEST_SYNC_STRATEGIES.SYNC,
}
);
if (res.body.reports?.length) {
// verification completed synchronously
}Request
params-object- requiredid-string- requiredcancellationReason-CancellationReason- requiredcancellationDetails-string
Response
Returns status code 200 on success.
Example
await client.verifications.cancel({
id: 'abc123',
cancellationReason: 'other',
});Request
params-object- requiredid-string- requiredreport_id-string- required
Response
Returns the full Verification object.
Example
await client.verifications.reverify({
id: 'abc123',
rerport_id: 'def123',
});Request
params-object- requiredid-string- required, the ID of the Verification
Response
Returns the full Report object associated with the Verification.
Example
await client.verifications.getReport({ id: 'abc123' });Request
params-object- requiredquery-string- requiredlimit-numberoffset-number
Response
Returns a PaginatedResponse containing an array of Companys.
Example
await client.companies.get({ query: 'USWNT' });Request
params-object- requiredtype-VerificationType- requiredpermissible_purpose-PermissiblePurpose- requireduse_case-UseCase- requiredtarget-Target- required
Response
Returns a CredentialsSession
Example
await client.credentials.createSession({
type: 'employment',
permissible_purpose: 'employment',
use_case: 'mortgage',
target: {
first_name: 'Megan',
last_name: 'Rapinoe',
social_security_number: '123121234',
date_of_birth: '2020-02-02',
company: {
name: 'USWNT',
},
},
});This SDK provides a naive "mock" mode that can be used for basic testing during CI, etc. It is stateless, meaning no data is persisted between API calls. When enabled, each SDK method will either return stub objects, or simple reflections of the data submitted.
To enable mock mode, initialize your SDK client like this:
const client = truework({
token: TRUEWORK_ACCESS_TOKEN,
mock: true,
});Returns a stubbed array of verifications, respective of all query params.
const res = await client.verifications.get({ state: 'processing', limit: 5 });
res.body.results.length; // => 5
res.body.results[0].state; // => processingReturns a stubbed verification object with the same id as is passed to
getOne({ id }).
Any id value is valid, except "AAAA", which will trigger a 404 error
response.
try {
await client.verifications.getOne({ id: 'AAAA' });
} catch (e) {
console.log(e.response); // error response body
}Returns a stubbed verification object.
To trigger an error response, do not pass a type property.
try {
await client.verifications.create(
// type: 'employment',
permissible_purpose: 'employment',
target: {
first_name: 'Megan',
last_name: 'Rapinoe',
social_security_number: '123121234',
company: {
name: 'USWNT',
},
},
additional_information: 'Lorem ipsum dolor...',
})
} catch (e) {
console.log(e.response) // error response body
}Returns 200 if successful.
Any id value is valid, except "AAAA", which will trigger an error response.
try {
await client.verifications.cancel({ id: 'AAAA' });
} catch (e) {
console.log(e.response); // error response body
}Returns a stubbed report object if successful.
Any id value is valid, except "AAAA", which will trigger an error response.
try {
await client.verifications.getReport({ id: 'AAAA' });
} catch (e) {
console.log(e.response); // error response body
}Returns a stubbed array of companies, respective of limit and offset query
params.
const res = await client.companies.get({ limit: 5 });
res.body.results.length; // => 5If you run into problems, or simply have a question, feel free to open an issue!
This repo uses commitizen to nicely
format commit messages. Upon making edits, stage your changes and simply run
git commit to enter the commitizen UI in your terminal.
Note: if you are not prompted with the commitizen UI, run npm ci to re-install
and run postinstall hooks to set it up.
This project is versioned and published automatically using
semantic-release. Via a
GitHub Action, semantic-release will use the commit message pattern provided
by commitizen to automatically version the package. It will then publish to
npm, as well as create a new
release here in the
main repo.
Do not publish this library manually from the command line.
MIT License © Truework