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

6.7.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.

In order to start communication with DigiFi platform API you need to create DigiFi API Service by providing the url to the DigiFi platform (this url can be different if you're using dedicated platform solution) and api-key.

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

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

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

console.log(items);

Usage with TypeScript

DigiFi maintains types for the latest API Version.

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

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

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

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

  console.log(application.id);
};

createApplication();

Configuration

To initialize DigiFi API Service you need provide the following data:

  • baseUrl of DigiFi Platform API endpoint as first argument,
  • api-key as second argument and
  • apiVersion in options object as third argument.
import { DigifiApi } from '@digifi/digifi-node-js';

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

const digifiApi = new DigifiApi(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 digifiApi = new DigifiApi('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 digifiApi = new DigifiApi('https://cloud.digifi.io/api', 'digifi-cloud-...', {
  apiVersion: '2024-02-26',
  maxNetworkRetries: 2, // Retry a request twice before giving up
});

API Services

An instance of Digifi Api Service class has several properties, each of them represents entity/domain in DigiFi system

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

const digifiApi = new DigifiApi(...);

const borrowers = await digifiApi.borrowers.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 Digifi 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 DigifiApi.borrowerAccounts(...) - api for borrower accounts.
    • findAccountByEmail(email: string) - returns borrower account.
    • createAccount(accountParams: object, refreshTokenExpirationTimeMinutes?: number) - creates and returns borrower account.
    • getCurrentUser(accountAccessToken: string) - returns current borrower account by accountAccessToken.
    • sendUpdatePhoneNumberCode(phone: string, accountAccessToken: string, accountPasswordValidationToken: string) - send code that confirms phone update for borrower account.
    • updatePhoneNumber(code: string, accountAccessToken: string) - confirms phone update for borrower by code and accountAccessToken.
    • sendAddPhoneNumberCode(phone: string, accountAccessToken: string, accountPasswordValidationToken: string) - send code that confirms phone adding for borrower 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 by accountAccessToken and accountPasswordValidationToken.
    • sendUpdateEmailCode(email: string, accountAccessToken: string, accountPasswordValidationToken: string) - sends update email code for borrower to account by accountAccessToken and accountPasswordValidationToken.
    • updateEmailAddress(code: string, accountAccessToken: string) - confirms email update for borrower for account by accountAccessToken.
    • createPasswordValidationToken(password: string, accountAccessToken: string) - creates password validation token for borrower account by password and accountAccessToken.
    • updatePassword(oldPassword: string, newPassword: string, accountAccessToken: string) - updates password for borrower) account.
    • find(params: object) - finds borrower accounts by params object.
  • new DigifiApi.borrowerEmailVerification(...) - api for borrower accounts email verification.
    • sendVerificationEmail(accountAccessToken: string) - sends verification email for borrower account by accountAccessToken.
    • verifyEmail(code: string, accountAccessToken: string) - verifies email for borrower account using code by accountAccessToken.
  • new DigifiApi.borrowerInvites(apiClient: ApiClient) - api for borrower invitation management.
    • acceptInvite(inviteParams: object, refreshTokenExpirationTimeMinutes?: number) - accepts invite for borrower account.
    • getInviteInfo(token: string) - retrieves invitation information for borrower account by token.
  • new DigifiApi.borrowerPhoneVerification(...) - api for borrower phone verification management.
    • sendMfaCode(phone: string, accountAccessToken: string) - sends mfa code for borrower account phone by accountAccessToken.
    • verifyMfaCode(code: string, accountAccessToken: string) - verifies mfa code for borrower account by accountAccessToken.
  • new DigifiApi.borrowerResetPassword(...) - api for borrower account reset password management.
    • sendResetPasswordLink(email: string) - sends reset password link to borrower account email.
    • resetPassword(password: string, resetPasswordToken: string) - resets password for borrower account by resetPasswordToken.
    • getResetPasswordTokenInfo(resetPasswordToken: string) - retrieves reset password token info for borrower account by resetPasswordToken.
  • new DigifiApi.borrowerSessions(...) - api for borrower account session management.
    • createSession(email: string, password: string, refreshTokenExpirationTimeMinutes?: number) - creates session for borrower account.
    • createSessionWithPhoneVerificationCode(phoneVerificationCode: string, refreshTokenExpirationTimeMinutes?: number) - creates session for borrower account by phoneVerificationCode.
    • sendPhoneVerificationCode(phone: string) - sends phone verification code for borrower account by phone.
    • validateToken(accountAccessToken: string) - validates access token for borrower account.
    • logout(accountAccessToken: string) - kills session associated with borrower account by accountAccessToken.
    • resignAccessToken(accountRefreshToken: string) - resign access token for borrower account by accountRefreshToken.
  • new DigifiApi.intermediaryAccounts(...) - api for intermediary accounts.
    • findAccountByEmail(email: string) - returns intermediary account.
    • createAccount(accountParams: object, refreshTokenExpirationTimeMinutes?: number) - creates and returns intermediary account.
    • getCurrentUser(accountAccessToken: string) - returns current intermediary account by accountAccessToken.
    • sendUpdatePhoneNumberCode(phone: string, accountAccessToken: string, accountPasswordValidationToken: string) - send code that confirms phone update for intermediary account.
    • updatePhoneNumber(code: string, accountAccessToken: string) - confirms phone update for intermediary by code and accountAccessToken.
    • sendAddPhoneNumberCode(phone: string, accountAccessToken: string, accountPasswordValidationToken: string) - send code that confirms phone adding for intermediary account.
    • addPhoneNumber(code: string, accountAccessToken: string) - confirms add phone to intermediary by code and accountAccessToken.
    • deletePhoneNumber(phone: string, accountAccessToken: string, accountPasswordValidationToken: string) - deletes phone for intermediary by accountAccessToken and accountPasswordValidationToken.
    • sendUpdateEmailCode(email: string, accountAccessToken: string, accountPasswordValidationToken: string) - sends update email code for intermediary to account by accountAccessToken and accountPasswordValidationToken.
    • updateEmailAddress(code: string, accountAccessToken: string) - confirms email update for intermediaryfor account by accountAccessToken.
    • createPasswordValidationToken(password: string, accountAccessToken: string) - creates password validation token for intermediary account by password and accountAccessToken.
    • updatePassword(oldPassword: string, newPassword: string, accountAccessToken: string) - updates password forintermediary account.
    • find(params: object) - finds intermediary accounts by params object.
  • new DigifiApi.intermediaryEmailVerification(...) - api for intermediary accounts email verification.
    • sendVerificationEmail(accountAccessToken: string) - sends verification email for intermediary account by accountAccessToken.
    • verifyEmail(code: string, accountAccessToken: string) - verifies email for intermediary account using code by accountAccessToken.
  • new DigifiApi.intermediaryInvites(...) - api for intermediary invitation management.
    • acceptInvite(inviteParams: object, refreshTokenExpirationTimeMinutes?: number) - accepts invite for intermediary account.
    • getInviteInfo(token: string) - retrieves invitation information for intermediary account by token.
  • new DigifiApi.intermediaryPhoneVerification(...) - api for borrower/intermediary phone verification management.
    • sendMfaCode(phone: string, accountAccessToken: string) - sends mfa code for intermediary account phone by accountAccessToken.
    • verifyMfaCode(code: string, accountAccessToken: string) - verifies mfa code for intermediary account by accountAccessToken.
  • new DigifiApi.intermediaryResetPassword(...) - api for borrower/intermediary account reset password management.
    • sendResetPasswordLink(email: string) - sends reset password link to intermediary (depends on reference passed to the service) account email.
    • resetPassword(password: string, resetPasswordToken: string) - resets password for intermediary account by resetPasswordToken.
    • getResetPasswordTokenInfo(resetPasswordToken: string) - retrieves reset password token info for intermediary account by resetPasswordToken.
  • new DigifiApi.intermediarySessions(...) - api for intermediary account session management.
    • createSession(email: string, password: string, refreshTokenExpirationTimeMinutes?: number) - creates session for intermediary account.
    • createSessionWithPhoneVerificationCode(phoneVerificationCode: string, refreshTokenExpirationTimeMinutes?: number) - creates session for intermediary account by phoneVerificationCode.
    • sendPhoneVerificationCode(phone: string) - sends phone verification code for intermediary account by phone.
    • validateToken(accountAccessToken: string) - validates access token for intermediary account.
    • logout(accountAccessToken: string) - kills session associated with intermediary account by accountAccessToken.
    • resignAccessToken(accountRefreshToken: string) - resign access token for intermediary account by accountRefreshToken.
  • new DigifiApi.users(...) - api for users management.
  • new DigifiApi.variables(...) - api for variables management.
  • new DigifiApi.decisions(...) - api for decisions management.
  • new DigifiApi.borrowerStandardPortalGeneralSettings(...) - api for borrower standard portal settings management.
    • getGeneralSettings() - retrieves general settings of standard borrower portal for current organization.
  • new DigifiApi.borrowerStandardPortalLegalConsents(apiClient) - api for borrower standard portal legal consents management.
    • getLegalConsents() - retrieves borrower standard portal legal consents for current organization.
  • new DigifiApi.branding(...) - api for organization branding management.
  • new DigifiApi.decisionProcessing(...) - api for processing decisions.
  • new DigifiApi.integrationFileDownload(...) - api for integration files downloads management.
  • new DigifiApi.integrationProcessing(...) - api for processing integrations.
  • new DigifiApi.integrationResultFiles(...) - api for integration result files management.
  • new DigifiApi.integrationResults(...) - api for integration results management.
  • new DigifiApi.applicationDecisionProcessing(...) - api for processing application decisions.
  • new DigifiApi.applicationDocumentConfiguration(...) - api for application document configuration management.
  • new DigifiApi.applicationDocuments(...) - api for application documents management.
  • new DigifiApi.applicationDocumentsDownloads(...) - api for application documents download.
  • new DigifiApi.applicationDocumentsPreview(...) - api for document preview management.
  • new DigifiApi.applicationIntegrationProcessing(...) - api for processing application integrations.
  • new DigifiApi.applicationNotes(...) - api for application notes management.
  • new DigifiApi.applications(...) - api for applications management.
  • new DigifiApi.applicationStatuses(...) - api 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 DigifiApi.borrowers(...) - api for borrowers management.
  • new DigifiApi.comments(...) - api for comments management.
  • new DigifiApi.intermediaries(...) - api for intermediaries management.
  • new DigifiApi.layoutConfiguration(...) - api for layout configuration management.
    • find(params: object) - finds layout configuration by params object.
  • new DigifiApi.productCalculations(...) - api 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 DigifiApi.products(...) - api 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 DigifiApi.tasks(...) - api for application tasks management.
  • new DigifiApi.webhookEndpoints(...) - api 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

427

Version

6.7.0

License

ISC

Unpacked Size

228 kB

Total Files

194

Last publish

Collaborators

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