modern-treasury 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +10 -0
- package/.prettierrc +6 -0
- package/LICENSE +7 -0
- package/README.md +198 -0
- package/build +10 -0
- package/core.ts +746 -0
- package/dist/cjs/core.d.ts +215 -0
- package/dist/cjs/core.js +815 -0
- package/dist/cjs/core.js.map +1 -0
- package/dist/cjs/index.d.ts +118 -0
- package/dist/cjs/index.js +128 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/pagination.d.ts +14 -0
- package/dist/cjs/pagination.js +22 -0
- package/dist/cjs/pagination.js.map +1 -0
- package/dist/cjs/resource.d.ts +11 -0
- package/dist/cjs/resource.js +16 -0
- package/dist/cjs/resource.js.map +1 -0
- package/dist/cjs/resources/counterparties.d.ts +500 -0
- package/dist/cjs/resources/counterparties.js +57 -0
- package/dist/cjs/resources/counterparties.js.map +1 -0
- package/dist/cjs/resources/documents.d.ts +66 -0
- package/dist/cjs/resources/documents.js +23 -0
- package/dist/cjs/resources/documents.js.map +1 -0
- package/dist/cjs/resources/events.d.ts +53 -0
- package/dist/cjs/resources/events.js +22 -0
- package/dist/cjs/resources/events.js.map +1 -0
- package/dist/cjs/resources/expected-payments.d.ts +928 -0
- package/dist/cjs/resources/expected-payments.js +31 -0
- package/dist/cjs/resources/expected-payments.js.map +1 -0
- package/dist/cjs/resources/external-accounts.d.ts +597 -0
- package/dist/cjs/resources/external-accounts.js +51 -0
- package/dist/cjs/resources/external-accounts.js.map +1 -0
- package/dist/cjs/resources/incoming-payment-details.d.ts +487 -0
- package/dist/cjs/resources/incoming-payment-details.js +35 -0
- package/dist/cjs/resources/incoming-payment-details.js.map +1 -0
- package/dist/cjs/resources/index.d.ts +15 -0
- package/dist/cjs/resources/index.js +46 -0
- package/dist/cjs/resources/index.js.map +1 -0
- package/dist/cjs/resources/internal-accounts.d.ts +666 -0
- package/dist/cjs/resources/internal-accounts.js +31 -0
- package/dist/cjs/resources/internal-accounts.js.map +1 -0
- package/dist/cjs/resources/line-items.d.ts +90 -0
- package/dist/cjs/resources/line-items.js +38 -0
- package/dist/cjs/resources/line-items.js.map +1 -0
- package/dist/cjs/resources/paper-items.d.ts +279 -0
- package/dist/cjs/resources/paper-items.js +25 -0
- package/dist/cjs/resources/paper-items.js.map +1 -0
- package/dist/cjs/resources/payment-orders/index.d.ts +2 -0
- package/dist/cjs/resources/payment-orders/index.js +33 -0
- package/dist/cjs/resources/payment-orders/index.js.map +1 -0
- package/dist/cjs/resources/payment-orders/payment-orders.d.ts +2180 -0
- package/dist/cjs/resources/payment-orders/payment-orders.js +56 -0
- package/dist/cjs/resources/payment-orders/payment-orders.js.map +1 -0
- package/dist/cjs/resources/payment-orders/reversals.d.ts +46 -0
- package/dist/cjs/resources/payment-orders/reversals.js +23 -0
- package/dist/cjs/resources/payment-orders/reversals.js.map +1 -0
- package/dist/cjs/resources/returns.d.ts +487 -0
- package/dist/cjs/resources/returns.js +31 -0
- package/dist/cjs/resources/returns.js.map +1 -0
- package/dist/cjs/resources/top-level.d.ts +3 -0
- package/dist/cjs/resources/top-level.js +4 -0
- package/dist/cjs/resources/top-level.js.map +1 -0
- package/dist/cjs/resources/transactions.d.ts +377 -0
- package/dist/cjs/resources/transactions.js +31 -0
- package/dist/cjs/resources/transactions.js.map +1 -0
- package/dist/cjs/resources/validations.d.ts +97 -0
- package/dist/cjs/resources/validations.js +16 -0
- package/dist/cjs/resources/validations.js.map +1 -0
- package/dist/cjs/resources/webhooks.d.ts +31 -0
- package/dist/cjs/resources/webhooks.js +44 -0
- package/dist/cjs/resources/webhooks.js.map +1 -0
- package/dist/cjs/tests/api-resources/counterparties.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/counterparties.test.js +275 -0
- package/dist/cjs/tests/api-resources/counterparties.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/documents.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/documents.test.js +78 -0
- package/dist/cjs/tests/api-resources/documents.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/events.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/events.test.js +100 -0
- package/dist/cjs/tests/api-resources/events.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/expected-payments.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/expected-payments.test.js +176 -0
- package/dist/cjs/tests/api-resources/expected-payments.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/external-accounts.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/external-accounts.test.js +248 -0
- package/dist/cjs/tests/api-resources/external-accounts.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/incoming-payment-details.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/incoming-payment-details.test.js +130 -0
- package/dist/cjs/tests/api-resources/incoming-payment-details.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/internal-accounts.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/internal-accounts.test.js +144 -0
- package/dist/cjs/tests/api-resources/internal-accounts.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/line-items.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/line-items.test.js +123 -0
- package/dist/cjs/tests/api-resources/line-items.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/paper-items.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/paper-items.test.js +96 -0
- package/dist/cjs/tests/api-resources/paper-items.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/payment-orders/payment-orders.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/payment-orders/payment-orders.test.js +77 -0
- package/dist/cjs/tests/api-resources/payment-orders/payment-orders.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/returns.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/returns.test.js +116 -0
- package/dist/cjs/tests/api-resources/returns.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/top-level.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/top-level.test.js +59 -0
- package/dist/cjs/tests/api-resources/top-level.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/transactions.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/transactions.test.js +134 -0
- package/dist/cjs/tests/api-resources/transactions.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/validations.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/validations.test.js +62 -0
- package/dist/cjs/tests/api-resources/validations.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/webhooks.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/webhooks.test.js +100 -0
- package/dist/cjs/tests/api-resources/webhooks.test.js.map +1 -0
- package/dist/cjs/tests/form.test.d.ts +1 -0
- package/dist/cjs/tests/form.test.js +61 -0
- package/dist/cjs/tests/form.test.js.map +1 -0
- package/dist/cjs/tests/index.test.d.ts +1 -0
- package/dist/cjs/tests/index.test.js +57 -0
- package/dist/cjs/tests/index.test.js.map +1 -0
- package/dist/cjs/tests/responses.test.d.ts +1 -0
- package/dist/cjs/tests/responses.test.js +60 -0
- package/dist/cjs/tests/responses.test.js.map +1 -0
- package/index.ts +175 -0
- package/jest.config.js +8 -0
- package/package.json +47 -0
- package/pagination.ts +36 -0
- package/resource.ts +22 -0
- package/resources/counterparties.ts +666 -0
- package/resources/documents.ts +97 -0
- package/resources/events.ts +86 -0
- package/resources/expected-payments.ts +1016 -0
- package/resources/external-accounts.ts +762 -0
- package/resources/incoming-payment-details.ts +592 -0
- package/resources/index.ts +16 -0
- package/resources/internal-accounts.ts +774 -0
- package/resources/line-items.ts +138 -0
- package/resources/paper-items.ts +317 -0
- package/resources/payment-orders/index.ts +3 -0
- package/resources/payment-orders/payment-orders.ts +2486 -0
- package/resources/payment-orders/reversals.ts +72 -0
- package/resources/returns.ts +545 -0
- package/resources/top-level.ts +5 -0
- package/resources/transactions.ts +441 -0
- package/resources/validations.ts +115 -0
- package/resources/webhooks.ts +48 -0
- package/tests/api-resources/counterparties.test.ts +237 -0
- package/tests/api-resources/documents.test.ts +40 -0
- package/tests/api-resources/events.test.ts +62 -0
- package/tests/api-resources/expected-payments.test.ts +138 -0
- package/tests/api-resources/external-accounts.test.ts +210 -0
- package/tests/api-resources/incoming-payment-details.test.ts +92 -0
- package/tests/api-resources/internal-accounts.test.ts +103 -0
- package/tests/api-resources/line-items.test.ts +85 -0
- package/tests/api-resources/paper-items.test.ts +58 -0
- package/tests/api-resources/payment-orders/payment-orders.test.ts +39 -0
- package/tests/api-resources/returns.test.ts +78 -0
- package/tests/api-resources/top-level.test.ts +21 -0
- package/tests/api-resources/transactions.test.ts +96 -0
- package/tests/api-resources/validations.test.ts +24 -0
- package/tests/api-resources/webhooks.test.ts +102 -0
- package/tests/form.test.ts +27 -0
- package/tests/index.test.ts +62 -0
- package/tests/responses.test.ts +25 -0
- package/tsconfig.cjs.json +8 -0
- package/tsconfig.json +36 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
parser: '@typescript-eslint/parser',
|
|
3
|
+
plugins: ['@typescript-eslint', 'unused-imports', 'prettier'],
|
|
4
|
+
rules: {
|
|
5
|
+
'no-unused-vars': 'off',
|
|
6
|
+
'prettier/prettier': 'error',
|
|
7
|
+
'unused-imports/no-unused-imports': 'error',
|
|
8
|
+
},
|
|
9
|
+
root: true,
|
|
10
|
+
};
|
package/.prettierrc
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2022 Modern Treasury
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# ModernTreasury Node API Library
|
|
2
|
+
|
|
3
|
+
[](https://npmjs.org/package/modern-treasury)
|
|
4
|
+
|
|
5
|
+
The ModernTreasury Node library provides convenient access to the ModernTreasury REST API from applications written in server-side JavaScript.
|
|
6
|
+
It includes TypeScript definitions for all request params and response fields.
|
|
7
|
+
|
|
8
|
+
## Documentation
|
|
9
|
+
|
|
10
|
+
The API documentation can be found [here](https://docs.moderntreasury.com).
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npm install --save modern-treasury
|
|
16
|
+
# or
|
|
17
|
+
yarn add modern-treasury
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import ModernTreasury from 'modern-treasury';
|
|
24
|
+
|
|
25
|
+
const modernTreasury = new ModernTreasury({
|
|
26
|
+
apiKey: 'my api key', // defaults to process.env["MODERN_TREASURY_API_KEY"]
|
|
27
|
+
organizationId: 'my organization id',
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
async function main() {
|
|
31
|
+
const externalAccount = await modernTreasury.externalAccounts.create({
|
|
32
|
+
counterparty_id: '123',
|
|
33
|
+
name: 'my bank',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
console.log(externalAccount.id);
|
|
37
|
+
}
|
|
38
|
+
main();
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Usage with TypeScript
|
|
42
|
+
|
|
43
|
+
Importing, instantiating, and interacting with the library are the same as above.
|
|
44
|
+
If you like, you may reference our types directly:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import ModernTreasury from 'modern-treasury';
|
|
48
|
+
|
|
49
|
+
const modernTreasury = new ModernTreasury({
|
|
50
|
+
apiKey: 'my api key', // defaults to process.env["MODERN_TREASURY_API_KEY"]
|
|
51
|
+
organizationId: 'my organization id',
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
async function main() {
|
|
55
|
+
const params: ModernTreasury.ExternalAccountCreateParams = { counterparty_id: '123', name: 'my bank' };
|
|
56
|
+
|
|
57
|
+
const externalAccount: ModernTreasury.ExternalAccount = await modernTreasury.externalAccounts.create(
|
|
58
|
+
params,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
main();
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
|
|
65
|
+
|
|
66
|
+
## Handling errors
|
|
67
|
+
|
|
68
|
+
When the library is unable to connect to the API,
|
|
69
|
+
or if the API returns a non-success status code (i.e., 4xx or 5xx response),
|
|
70
|
+
a subclass of `APIError` will be thrown:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
async function main() {
|
|
74
|
+
const externalAccount = await modernTreasury.externalAccounts
|
|
75
|
+
.create({ counterparty_id: 'missing' })
|
|
76
|
+
.catch((err) => {
|
|
77
|
+
if (err instanceof ModernTreasury.APIError) {
|
|
78
|
+
console.log(err.status); // 400
|
|
79
|
+
console.log(err.name); // BadRequestError
|
|
80
|
+
|
|
81
|
+
console.log(err.headers); // {server: 'nginx', ...}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
main();
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Error codes are as followed:
|
|
89
|
+
|
|
90
|
+
| Status Code | Error Type |
|
|
91
|
+
| ----------- | -------------------------- |
|
|
92
|
+
| 400 | `BadRequestError` |
|
|
93
|
+
| 401 | `AuthenticationError` |
|
|
94
|
+
| 403 | `PermissionDeniedError` |
|
|
95
|
+
| 404 | `NotFoundError` |
|
|
96
|
+
| 422 | `UnprocessableEntityError` |
|
|
97
|
+
| 429 | `RateLimitError` |
|
|
98
|
+
| >=500 | `InternalServerError` |
|
|
99
|
+
| N/A | `APIConnectionError` |
|
|
100
|
+
|
|
101
|
+
### Retries
|
|
102
|
+
|
|
103
|
+
Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
|
|
104
|
+
Connection errors (for example, due to a network connectivity problem), 409 Conflict, 429 Rate Limit,
|
|
105
|
+
and >=500 Internal errors will all be retried by default.
|
|
106
|
+
|
|
107
|
+
You can use the `maxRetries` option to configure or disable this:
|
|
108
|
+
|
|
109
|
+
<!-- prettier-ignore -->
|
|
110
|
+
```js
|
|
111
|
+
// Configure the default for all requests:
|
|
112
|
+
const modernTreasury = new ModernTreasury({
|
|
113
|
+
maxRetries: 0, // default is 2
|
|
114
|
+
organizationId: 'my organization id',
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Or, configure per-request:
|
|
118
|
+
modernTreasury.externalAccounts.list({
|
|
119
|
+
maxRetries: 5,
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Timeouts
|
|
124
|
+
|
|
125
|
+
Requests time out after 60 seconds by default. You can configure this with a `timeout` option:
|
|
126
|
+
|
|
127
|
+
<!-- prettier-ignore -->
|
|
128
|
+
```ts
|
|
129
|
+
// Configure the default for all requests:
|
|
130
|
+
const modernTreasury = new ModernTreasury({
|
|
131
|
+
timeout: 20 * 1000, // 20 seconds (default is 60s)
|
|
132
|
+
organizationId: 'my organization id',
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// Override per-request:
|
|
136
|
+
modernTreasury.externalAccounts.list({ party_name: 'my bank' }, {
|
|
137
|
+
timeout: 5 * 1000,
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
On timeout, an `APIConnectionTimeoutError` is thrown.
|
|
142
|
+
|
|
143
|
+
Note that requests which time out will be [retried twice by default](#retries).
|
|
144
|
+
|
|
145
|
+
## Auto-pagination
|
|
146
|
+
|
|
147
|
+
List methods in the ModernTreasury API are paginated.
|
|
148
|
+
Use `for await … of` syntax to iterate through items across all pages.
|
|
149
|
+
|
|
150
|
+
```js
|
|
151
|
+
async function fetchAllExternalAccounts(params) {
|
|
152
|
+
const allExternalAccounts = [];
|
|
153
|
+
// Automatically fetches more pages as needed.
|
|
154
|
+
for await (const externalAccount of modernTreasury.externalAccounts.list()) {
|
|
155
|
+
allExternalAccounts.push(externalAccount);
|
|
156
|
+
}
|
|
157
|
+
return allExternalAccounts;
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Configuring an HTTP(S) Agent (e.g., for proxies)
|
|
162
|
+
|
|
163
|
+
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.
|
|
164
|
+
|
|
165
|
+
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:
|
|
166
|
+
|
|
167
|
+
<!-- prettier-ignore -->
|
|
168
|
+
```ts
|
|
169
|
+
import http from 'http';
|
|
170
|
+
import HttpsProxyAgent from 'https-proxy-agent';
|
|
171
|
+
|
|
172
|
+
// Configure the default for all requests:
|
|
173
|
+
const modernTreasury = new ModernTreasury({
|
|
174
|
+
httpAgent: new HttpsProxyAgent(process.env.PROXY_URL),
|
|
175
|
+
organizationId: 'my organization id',
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// Override per-request:
|
|
179
|
+
modernTreasury.externalAccounts.list({
|
|
180
|
+
baseURL: 'http://localhost:8080/test-api',
|
|
181
|
+
httpAgent: new http.Agent({ keepAlive: false }),
|
|
182
|
+
})
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Status
|
|
186
|
+
|
|
187
|
+
This package is in beta. Its internals and interfaces are not stable
|
|
188
|
+
and subject to change without a major semver bump;
|
|
189
|
+
please reach out if you rely on any undocumented behavior.
|
|
190
|
+
|
|
191
|
+
We are keen for your feedback; please email us at [dev-feedback@moderntreasury.com](mailto:dev-feedback@moderntreasury.com)
|
|
192
|
+
or open an issue with questions, bugs, or suggestions.
|
|
193
|
+
|
|
194
|
+
## Requirements
|
|
195
|
+
|
|
196
|
+
Node.js version 12 or higher.
|
|
197
|
+
|
|
198
|
+
If you are interested in other runtime environments, please open or upvote an issue on Github.
|