Node.js library for the Modern Treasury API.

Overview

ModernTreasury Node API Library

NPM version

The ModernTreasury Node library provides convenient access to the ModernTreasury REST API from applications written in server-side JavaScript. It includes TypeScript definitions for all request params and response fields.

Documentation

The API documentation can be found here.

Installation

npm install --save modern-treasury
# or
yarn add modern-treasury

Usage

import ModernTreasury from 'modern-treasury';

const modernTreasury = new ModernTreasury({
  apiKey: 'my api key', // defaults to process.env["MODERN_TREASURY_API_KEY"]
  organizationId: 'my-organization-ID',
});

async function main() {
  const counterparty = await modernTreasury.counterparties.create({
    name: 'my first counterparty',
  });

  console.log(counterparty.id);
}
main().catch(console.error)

Usage with TypeScript

Importing, instantiating, and interacting with the library are the same as above. If you like, you may reference our types directly:

import ModernTreasury from 'modern-treasury';

const modernTreasury = new ModernTreasury({
  apiKey: 'my api key', // defaults to process.env["MODERN_TREASURY_API_KEY"]
  organizationId: 'my-organization-ID',
});

async function main() {
  const params: ModernTreasury.CounterpartyCreateParams = { name: 'my first counterparty' };

  const counterparty: ModernTreasury.Counterparty = await modernTreasury.counterparties.create(params);
}
main().catch(console.error)

Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.

Handling errors

When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), a subclass of APIError will be thrown:

async function main() {
  const externalAccount = await modernTreasury.externalAccounts.create({ counterparty_id: 'missing' })
    .catch((err) => {
      if (err instanceof ModernTreasury.APIError) {
        console.log(err.status); // 400
        console.log(err.name); // BadRequestError

        console.log(err.headers); // {server: 'nginx', ...}
      }
    })

}
main().catch(console.error)

Error codes are as followed:

Status Code Error Type
400 BadRequestError
401 AuthenticationError
403 PermissionDeniedError
404 NotFoundError
422 UnprocessableEntityError
429 RateLimitError
>=500 InternalServerError
N/A APIConnectionError

Retries

Certain errors will be automatically retried 2 times by default, with a short exponential backoff. Connection errors (for example, due to a network connectivity problem), 409 Conflict, 429 Rate Limit, and >=500 Internal errors will all be retried by default.

You can use the maxRetries option to configure or disable this:

// Configure the default for all requests:
const modernTreasury = new ModernTreasury({
  maxRetries: 0, // default is 2
  organizationId: 'my-organization-ID',
});

// Or, configure per-request:
modernTreasury.externalAccounts.list({
  maxRetries: 5,
});

Timeouts

Requests time out after 60 seconds by default. You can configure this with a timeout option:

// Configure the default for all requests:
const modernTreasury = new ModernTreasury({
  timeout: 20 * 1000, // 20 seconds (default is 60s)
  organizationId: 'my-organization-ID',
});

// Override per-request:
modernTreasury.externalAccounts.list({ party_name: 'my bank' }, {
  timeout: 5 * 1000,
});

On timeout, an APIConnectionTimeoutError is thrown.

Note that requests which time out will be retried twice by default.

Auto-pagination

List methods in the ModernTreasury API are paginated. Use for await … of syntax to iterate through items across all pages.

async function fetchAllExternalAccounts(params) {
  const allExternalAccounts = [];
  // Automatically fetches more pages as needed.
  for await (const externalAccount of modernTreasury.externalAccounts.list()) {
    allExternalAccounts.push(externalAccount);
  }
  return allExternalAccounts;
};

Configuring an HTTP(S) Agent (e.g., for proxies)

By default, this library uses a stable agent for all http/https requests to reuse TCP connections, eliminating many TCP & TLS handshakes and shaving around 100ms off most requests.

If you would like to disable or customize this behavior, for example to use the API behind a proxy, you can pass an httpAgent which is used for all requests (be they http or https), for example:

import http from 'http';
import HttpsProxyAgent from 'https-proxy-agent';

// Configure the default for all requests:
const modernTreasury = new ModernTreasury({
  httpAgent: new HttpsProxyAgent(process.env.PROXY_URL),
  organizationId: 'my-organization-ID',
});

// Override per-request:
modernTreasury.externalAccounts.list({
  baseURL: 'http://localhost:8080/test-api',
  httpAgent: new http.Agent({ keepAlive: false }),
})

Status

This package is in beta. Its internals and interfaces are not stable and subject to change without a major semver bump; please reach out if you rely on any undocumented behavior.

We are keen for your feedback; please email us at [email protected] or open an issue with questions, bugs, or suggestions.

Requirements

Node.js version 12 or higher.

If you are interested in other runtime environments, please open or upvote an issue on Github.

You might also like...

A modern solidjs based UI library ~ it is very lightweight!

🚧 目前正在开发中,敬请期待~ cerises-ui 一个现代的基于 solidjs 的 UI 库~它是非常轻量级的! 官网:https://cerises-ui.edoc.wiki 目前计划组件 组件 说明 认领人 进度 Review & Unit Test Button、ButtonGroup

Jul 19, 2022

Lightweight, Modern Multicall3 Typescript Library

Lightweight, Modern Multicall3 Typescript Library

pilum • Lightweight, Modern Multicall3 Typescript Library published on npm. Multicall3 flexibly aggregates results from multiple smart contract functi

Nov 15, 2022

An authorization library that supports access control models like ACL, RBAC, ABAC in modern JavaScript platforms

An authorization library that supports access control models like ACL, RBAC, ABAC in modern JavaScript platforms

Casbin-Core 💖 Looking for an open-source identity and access management solution like Okta, Auth0, Keycloak ? Learn more about: Casdoor News: still w

Oct 20, 2022

Create HTML from CSS! A modern javascript library you'd expect Facebook to invent.

Create HTML from CSS! A modern javascript library you'd expect Facebook to invent.

Create HTML from CSS! A modern javascript library you'd expect Facebook to invent. Slowly build modern websites without ever leaving your CSS, with HeadwindHTML

Dec 30, 2022

A modern lazy loading library for images.

Layzr.js A modern lazy loading library for images. Demo Page Getting Started Follow these steps: Install Setup Images Instantiate Review Options Revie

Dec 25, 2022

A tiny, lightning fast jQuery-like library for modern browsers.

Sprint.js Sprint is a high-performance, 5KB (gzipped) DOM library for modern browsers. Sprint notably shines on bandwidth and resource constrained dev

Jan 3, 2023

A lightweight, modern and customizable JavaScript slider library.

NSlider NSlider is a lightweight ( 10 KB), modern and customizable JavaScript slider library. CDN Development https://cdn.jsdelivr.net/gh/fatihege/ns

Jan 20, 2022

Flexible, powerful and modern library for creating the running horizontal blocks effect, also known as ticker or the «marquee effect».

Flexible, powerful and modern library for creating the running horizontal blocks effect, also known as ticker or the «marquee effect».

Cuberto Reeller Flexible, powerful and modern library for creating the running horizontal blocks effect, also known as ticker or the «marquee effect».

Jan 4, 2023

Simple modern JavaScript ES6 library that fetches JSON data into an HTML table which displays nicely within a Bootstrap 4 Card.

Simple modern JavaScript ES6 library that fetches JSON data into an HTML table which displays nicely within a Bootstrap 4 Card. Uses simplenotsimpler/modern-table library.

Feb 17, 2022
Owner
Modern Treasury
Modern Treasury builds payment operations software. Use our web application or API to manage the full cycle of money movement.
Modern Treasury
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Zepto.js is a minimalist JavaScript library for modern browsers, with a jQuery-compatible API

Zepto.js – a minimalist JavaScript library Zepto is a minimalist JavaScript library for modern browsers with a largely jQuery-compatible API. If you u

Thomas Fuchs 15k Dec 31, 2022
This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js

This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js. But in most cases, I would recommend you to use something like Express in a production project for productivity purposes.

Eduardo Dantas 7 Jul 19, 2022
Javascript client for Sanity. Works in node.js and modern browsers (older browsers needs a Promise polyfill).

@sanity/client Javascript client for Sanity. Works in node.js and modern browsers (older browsers needs a Promise polyfill). Requirements Sanity Clien

Sanity 23 Nov 29, 2022
A modern SQLite store for node-cache-manager

SQLite store for node cache manager A modern SQlite cache store for node-cache-manager. Featuring: Async SQLite3 using sqlite3 async/await support wit

Zohaib Sibte Hassan 40 Oct 31, 2022
NoExGen is a node.js express application generator with modern folder structure, namespace/project mapping and much more! It contains preconfigured Settings and Routing files, ready to be used in any project.

Installation $ npm install -g noexgen Quick Start You can use Node Package Execution to create your node-express application as shown below: Create th

Souvik Sen 7 Oct 8, 2022
radiQL, your one-stop-shop for migrating from a legacy REST backend to an efficient and modern GraphQL API

Welcome to radiQL, the one-stop solution for setting up GraphQL on a PostgreSQL database. Check out our Medium article here. At A Glance: Give us your

OSLabs Beta 90 Nov 14, 2022
Node 18's node:test, as a node module

node-core-test This is a user-land port of node:test, the experimental test runner introduced in Node.js 18. This module makes it available in Node.js

Julian Gruber 62 Dec 15, 2022