@digifi/digifi-node-js
TypeScript icon, indicating that this package has built-in type declarations

5.1.0 • Public • Published

DigiFi Node.js Library

Version Build Status Downloads

The DigiFi Node library provides convenient access to the DigiFi API from applications written in server-side JavaScript.

Documentation

See the API docs.

Requirements

Node 12 or higher.

Installation

Install the package with:

npm install @digifi/digifi-node-js --save
# or
yarn add @digifi/digifi-node-js

Usage

This package provides API Clients and API Services to help you communicate with DigiFi platform.

First, you need to create API Client that requires url to DigiFi platform (this url can be different if you're using dedicated platform solution) and api-key.

After API Client was initialized - you can create API Service and start communication with to DigiFi platform API.

const Digifi = require('@digifi/digifi-node-js');

const apiClient = new Digifi.AuthorizedApiClient('https://cloud.digifi.io/api', 'digifi-...', {
  apiVersion: '2024-02-26',
});

const applicationsApi = new Digifi.ApplicationsApiService(apiClient);

const { items, total } = await applicationsApi.find({ productId: '63d...' });

console.log(items);

Usage with TypeScript

DigiFi maintains types for the latest API Version.

import { AuthorizedApiClient, CreateApplicationParams, Application, ApplicationsApiService } from '@digifi/digifi-node-js';

const apiClient = new AuthorizedApiClient('https://cloud.digifi.io/api', 'digifi-...', {
  apiVersion: '2024-02-26',
});

const applicationsApi = new ApplicationsApiService(apiClient);

const createApplication = async () => {
  const params: CreateApplicationParams = {
    productId: '63d288ae64f7677836046de7',
    ...,
  };

  const application: Application = await applicationsApi.create(params);

  console.log(application.id);
};

createApplication();

Configuration

To initialize API Service you need to create API client before. Here is an example how to achieve that:

new AuthorizedApiClient(baseUrl: string, apiKey: string, options: object) - default API client with authorization. Requires baseUrl of DigiFi Platform API endpoint as first argument, api-key as second argument and apiVersion in options object as third argument.

import { AuthorizedApiClient } from '@digifi/digifi-node-js';

const baseUrl = 'https://cloud.digifi.io/api';
const apiKey = 'digifi-cloud-...';

const authorizedApiClient = new AuthorizedApiClient(baseUrl, apiKey, {
  apiVersion: '2024-02-26',
});

Options

API client can be created with required options parameter that has this structure:

Option Default Required Description
apiVersion true Api version to use for client.
enableIdempotencyHeader false false If true is provided it allows POST requests to be idempotent
maxNetworkRetries 0 false The amount of times a request should be retried if error occured
logger null false Logger for tracing errors and requests

Idempotency

Idempotency Header can be enabled with the enableIdempotencyHeader to prevent duplication in cause of retry. Librabry will automatically assign idempotency header key (generated by UUID v4) to each POST request.

const apiClient = new AuthorizedApiClient('https://cloud.digifi.io/api', 'digifi-cloud-...', {
  apiVersion: '2024-02-26',
  enableIdempotencyHeader: true, // Will assign idempotency key to each POST request using UUID
});

Network retries

Automatic network retries can be enabled with the maxNetworkRetries config option. This will retry requests n times with exponential backoff if they fail due to an intermittent network problem.

const apiClient = new AuthorizedApiClient('https://cloud.digifi.io/api', 'digifi-cloud-...', {
  apiVersion: '2024-02-26',
  maxNetworkRetries: 2, // Retry a request twice before giving up
});

API Services

Api Service - class that provides you an interface which will simplify communicating with DigiFi Platform API without need to use AuthorizedApiClient directly. Each Api Service represent entity/domain in DigiFi system.

For example, if you need to create a borrower in DigiFi Platform you can use BorrowersApi:

const apiClient = new AuthorizedApiClient(...);
const borrowersApi = new BorrowersApiService(apiClient);

const borrowers = await borrowersApi.create({ ... });

console.log(borrower.id);

Note You can communicate with DigiFi Platform API directly by AuthorizedApiClient, since it provides method makeCall, but it's recommended to use API Services to make sure that you're using correct request structure.

Here the list of API Services that DigiFi Node JS Library provides:

  • new AccountsApi(apiClient: ApiClient, reference: 'borrowers' | 'intermediaries') - api service for borrower/intermediary (depends on reference argument) accounts.
    • findAccountByEmail(email: string) - returns borrower/intermediary (depends on reference passed to the service) account.
    • createAccount(accountParams: object, refreshTokenExpirationTimeMinutes?: number) - creates and returns borrower/intermediary (depends on reference passed to the service) account.
    • getCurrentUser(accountAccessToken: string) - returns current borrower/intermediary (depends on reference passed to the service) account by accountAccessToken.
    • sendUpdatePhoneNumberCode(phone: string, accountAccessToken: string, accountPasswordValidationToken: string) - send code that confirms phone update for borrower/intermediary (depends on reference passed to the service) account.
    • updatePhoneNumber(code: string, accountAccessToken: string) - confirms phone update for borrower/intermediary (depends on reference passed to the service) by code and accountAccessToken.
    • sendAddPhoneNumberCode(phone: string, accountAccessToken: string, accountPasswordValidationToken: string) - send code that confirms phone adding for borrower/intermediary (depends on reference passed to the service) account.
    • addPhoneNumber(code: string, accountAccessToken: string) - confirms add phone to borrower/intermediary (depends on reference passed to the service) by code and accountAccessToken.
    • deletePhoneNumber(phone: string, accountAccessToken: string, accountPasswordValidationToken: string) - deletes phone for borrower/intermediary (depends on reference passed to the service) by accountAccessToken and accountPasswordValidationToken.
    • sendUpdateEmailCode(email: string, accountAccessToken: string, accountPasswordValidationToken: string) - sends update email code for borrower/intermediary (depends on reference passed to the service) to account by accountAccessToken and accountPasswordValidationToken.
    • updateEmailAddress(code: string, accountAccessToken: string) - confirms email update for borrower/intermediary (depends on reference passed to the service) for account by accountAccessToken.
    • createPasswordValidationToken(password: string, accountAccessToken: string) - creates password validation token for borrower/intermediary (depends on reference passed to the service) account by password and accountAccessToken.
    • updatePassword(oldPassword: string, newPassword: string, accountAccessToken: string) - updates password for borrower/intermediary (depends on reference passed to the service) account.
    • find(params: object) - finds borrower/intermediary (depends on reference passed to the service) accounts by params object.
  • new EmailVerificationApi(apiClient: ApiClient, reference: 'borrowers' | 'intermediaries') - api service for borrower/intermediary (depends on reference argument) accounts email verification.
    • sendVerificationEmail(accountAccessToken: string) - sends verification email for borrower/intermediary (depends on reference passed to the service) account by accountAccessToken.
    • verifyEmail(code: string, accountAccessToken: string) - verifies email for borrower/intermediary (depends on reference passed to the service) account using code by accountAccessToken.
  • new InvitesApi(apiClient: ApiClient, reference: 'borrowers' | 'intermediaries') - api service for borrower/intermediary (depends on reference argument) invitation management.
    • acceptInvite(password: string, phone: string, token: string, refreshTokenExpirationTimeMinutes?: number) - accepts invite for borrower/intermediary (depends on reference passed to the service) account.
    • getInviteInfo(token: string) - retrieves invitation information for borrower/intermediary (depends on reference passed to the service) account by token.
  • new PhoneVerificationApi(apiClient: ApiClient, reference: 'borrowers' | 'intermediaries') - api service for borrower/intermediary (depends on reference argument) phone verification management.
    • sendMfaCode(phone: string, accountAccessToken: string) - sends mfa code for borrower/intermediary (depends on reference passed to the service) account phone by accountAccessToken.
    • verifyMfaCode(code: string, accountAccessToken: string) - verifies mfa code for borrower/intermediary (depends on reference passed to the service) account by accountAccessToken.
  • new ResetPasswordApi(apiClient: ApiClient, reference: 'borrowers' | 'intermediaries') - api service for borrower/intermediary (depends on reference argument) account reset password management.
    • sendResetPasswordLink(email: string) - sends reset password link to borrower/intermediary (depends on reference passed to the service) account email.
    • resetPassword(password: string, resetPasswordToken: string) - resets password for borrower/intermediary (depends on reference passed to the service) account by resetPasswordToken.
    • getResetPasswordTokenInfo(resetPasswordToken: string) - retrieves reset password token info for borrower/intermediary (depends on reference passed to the service) account by resetPasswordToken.
  • new SessionsApi(apiClient: ApiClient, reference: 'borrowers' | 'intermediaries') - api service for borrower/intermediary (depends on reference argument) account session management.
    • createSession(email: string, password: string, refreshTokenExpirationTimeMinutes?: number) - creates session for borrower/intermediary (depends on reference passed to the service) account.
    • createSessionWithPhoneVerificationCode(phoneVerificationCode: string, refreshTokenExpirationTimeMinutes?: number) - creates session for borrower/intermediary (depends on reference passed to the service) account by phoneVerificationCode.
    • sendPhoneVerificationCode(phone: string) - sends phone verification code for borrower/intermediary (depends on reference passed to the service) account by phone.
    • validateToken(accountAccessToken: string) - validates access token for borrower/intermediary (depends on reference passed to the service) account.
    • logout(accountAccessToken: string) - kills session associated with borrower/intermediary (depends on reference passed to the service) account by accountAccessToken.
    • resignAccessToken(accountRefreshToken: string) - resign access token for borrower/intermediary (depends on reference passed to the service) account by accountRefreshToken.
  • new UsersApi(apiClient: ApiClient) - api service for users management.
  • new VariablesApi(apiClient: ApiClient) - api service for variables management.
  • new DecisionsApi(apiClient: ApiClient) - api service for decisions management.
  • new BorrowerStandardPortalGeneralSettingsApi(apiClient: ApiClient) - api service for borrower standard portal settings management.
    • getGeneralSettings() - retrieves general settings of standard borrower portal for current organization.
  • new BorrowerStandardPortalLegalDocumentApi(apiClient) - api service for borrower standard portal legal documents management.
    • getLegalDocuments() - retrieves borrower standard portal legal documents for current organization.
  • new BrandingApi(apiClient: ApiClient) - api service for organization branding management.
  • new DecisionProcessingApi(apiClient: ApiClient) - api service for processing decisions.
  • new IntegrationFileDownloadApi(apiClient: ApiClient) - api service for integration files downloads management.
  • new IntegrationProcessingApi(apiClient: ApiClient) - api service for processing integrations.
  • new IntegrationResultFilesApi(apiClient: ApiClient) - api service for integration result files management.
  • new IntegrationResultsApi(apiClient: ApiClient) - api service for integration results management.
  • new ApplicationDecisionProcessingApi(apiClient: ApiClient) - api service for processing application decisions.
  • new ApplicationDocumentConfigurationApi(apiClient: ApiClient) - api service for application document configuration management.
  • new ApplicationDocumentsApi(apiClient: ApiClient) - api service for application documents management.
  • new ApplicationDocumentsDownloadsApi(apiClient: ApiClient) - api service for application documents download.
  • new ApplicationDocumentsPreviewApi(apiClient: ApiClient) - api service for document preview management.
  • new ApplicationIntegrationProcessingApi(apiClient: ApiClient) - api service for processing application integrations.
  • new ApplicationNotesApi(apiClient: ApiClient) - api service for application notes management.
  • new ApplicationsApiService(apiClient: ApiClient) - api service for applications management.
    • search(params: object) - search applications by params object.
    • list(params: object) - lists applications by params object.
    • findById(id: string) - finds application by id.
    • findByDisplayId(displayId: string) - finds application by displayId.
    • create(params: object) - creates application by params object.
    • update(id: string, params: object) - updates application by id and params object.
    • delete(id: string) - deletes application by id.
    • updateCoBorrowers(id: string, params: object) - updates application co-borrowers by id and params object.
    • updateIntermediary(id: string, params: object) - updates application intermediary by id and params object.
    • getVariables(id: string, variablesToInclude?: string[]) - retrieves application variables by id (optional argument variablesToInclude includes only specified variables).
    • runCalculations(id: string, params: object) - re-runs applications calculations by id and optional params object (provide variablesToRun in params object to re-run only specified variables).
    • addLabels(id: string, labelsIds: string[]) - adds labels to application by id.
    • addTeamMembers(id: string, teamMembersIds: string[]) - adds team members to application by id.
  • new ApplicationStatusesApi(apiClient: ApiClient) - api service for application statuses management.
    • find(productId: string) - finds application statuses for current organization and mode (depends on api-key provided to api client) by productId.
  • new BorrowersApiService(apiClient: ApiClient) - api service for borrowers management.
  • new CommentsApi(apiClient: ApiClient) - api service for comments management.
  • new IntermediariesApiService(apiClient: ApiClient) - api service for intermediaries management.
  • new LayoutConfigurationApi(apiClient: ApiClient) - api service for layout configuration management.
    • find(params: object) - finds layout configuration by params object.
  • new ProductCalculationsApi(apiClient: ApiClient) - api service for product calculations management.
    • find(productId: string) - finds product calculations for current organization and mode (depends on api-key provided to api client) by productId.
  • new ProductsApi(apiClient: ApiClient) - api service for products management.
    • find(params: object) - finds products for current organization and mode (depends on api-key provided to api client) by params.
    • findById(id: string) - finds product for current organization and mode (depends on api-key provided to api client) by id.
  • new TasksApiService(apiClient: ApiClient) - api service for application tasks management.
  • new WebhookEndpointsApi(apiClient: ApiClient) - api service for webhooks management.
    • find(params: object) - finds webhook endpoints by params object.
    • findById(id: string) - finds webhook endpoints by id.
    • create(params: object) - creates webhook endpoint by params object.
    • update(id: string, params: object) - updates webhook endpoints by id and params object.
    • delete(id: string) - deletes webhook endpoint by id.

Webhook signing

DigiFi can verify webhook events signature it sends to your endpoint, allowing you to validate that they were not sent by a third-party. You can read more about it here.

Please note that you must pass the raw request body, exactly as received from DigiFi, to the verifyWebhookSignature() function; this will not work with a parsed (i.e., JSON) request body.

Here is an example how to use it with express:

const express = require('express');
const digifi = require('digifi-node-js');
const bodyParser = require('body-parser');

const app = express();
const endpointSecret = '...';

app.post('/webhooks', bodyParser.raw({ type: 'application/json' }), (req, res) => {
  const timestamp = req.headers['x-digifi-event-timestamp'];
  const signature = req.headers['x-digifi-signature'];
  
  if (!digifi.verifyWebhookSignature(req.body, endpointSecret, timestamp, signature)) {
    res.status(400).send({ message: 'Invalid signature' });
    
    return;
  }
  
  if (!digifi.verifyWebhookTimestamp(timestamp)) {
    res.status(400).send({ message: 'Invalid timestamp' });
    
    return;
  }

  switch (req.body.eventType) {
    case 'application.created': {
      handleApplicationCreate();
    }
    case 'application.updated': {
      handleApplicationUpdate();
    }
  }

  res.status(200).send({});
});

app.listen(3000, () => {
  console.log(`Example app listening at http://localhost:3000`)
});

Support

New features and bug fixes are released on the latest major version of the @digifi/digifi-node-js package. If you are on an older major version, we recommend that you upgrade to the latest in order to use the new features and bug fixes including those for security vulnerabilities. Older major versions of the package will continue to be available for use, but will not be receiving any updates.

More Information

Readme

Keywords

none

Package Sidebar

Install

npm i @digifi/digifi-node-js

Weekly Downloads

399

Version

5.1.0

License

ISC

Unpacked Size

198 kB

Total Files

172

Last publish

Collaborators

  • katsiarynachka
  • d.lonski
  • eugeniakasperskaya
  • vladimir.nekhay
  • jjersey00
  • digifi-dmitry
  • alexey.maslovsky
  • promisefinorg
  • ilya.tishonok
  • dvovna