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
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import qs from 'qs';
|
|
4
|
+
import type { Agent } from 'http';
|
|
5
|
+
import type NodeFetch from 'node-fetch';
|
|
6
|
+
import type { RequestInfo, RequestInit, Response } from 'node-fetch';
|
|
7
|
+
import { Readable } from 'stream';
|
|
8
|
+
export declare abstract class APIClient {
|
|
9
|
+
apiKey: string | null;
|
|
10
|
+
baseURL: string;
|
|
11
|
+
maxRetries: number;
|
|
12
|
+
timeout: number;
|
|
13
|
+
httpAgent: Agent | undefined;
|
|
14
|
+
private fetch;
|
|
15
|
+
protected idempotencyHeader?: string;
|
|
16
|
+
constructor({
|
|
17
|
+
apiKey,
|
|
18
|
+
baseURL,
|
|
19
|
+
maxRetries,
|
|
20
|
+
timeout,
|
|
21
|
+
httpAgent,
|
|
22
|
+
}: {
|
|
23
|
+
apiKey: string | null;
|
|
24
|
+
baseURL: string;
|
|
25
|
+
maxRetries?: number;
|
|
26
|
+
timeout: number | undefined;
|
|
27
|
+
httpAgent: Agent | undefined;
|
|
28
|
+
});
|
|
29
|
+
protected authHeaders(): Headers;
|
|
30
|
+
/**
|
|
31
|
+
* Override this to add your own default headers, for example:
|
|
32
|
+
*
|
|
33
|
+
* {
|
|
34
|
+
* ...super.defaultHeaders(),
|
|
35
|
+
* Authorization: 'Bearer 123',
|
|
36
|
+
* }
|
|
37
|
+
*/
|
|
38
|
+
protected defaultHeaders(): Headers;
|
|
39
|
+
/**
|
|
40
|
+
* Override this to add your own qs.stringify options, for example:
|
|
41
|
+
*
|
|
42
|
+
* {
|
|
43
|
+
* ...super.qsOptions(),
|
|
44
|
+
* strictNullHandling: true,
|
|
45
|
+
* }
|
|
46
|
+
*/
|
|
47
|
+
protected qsOptions(): qs.IStringifyOptions | undefined;
|
|
48
|
+
protected defaultIdempotencyKey(): string;
|
|
49
|
+
get<Req, Rsp>(path: string, opts?: RequestOptions<Req>): Promise<Rsp>;
|
|
50
|
+
post<Req, Rsp>(path: string, opts?: RequestOptions<Req>): Promise<Rsp>;
|
|
51
|
+
patch<Req, Rsp>(path: string, opts?: RequestOptions<Req>): Promise<Rsp>;
|
|
52
|
+
put<Req, Rsp>(path: string, opts?: RequestOptions<Req>): Promise<Rsp>;
|
|
53
|
+
delete<Req, Rsp>(path: string, opts?: RequestOptions<Req>): Promise<Rsp>;
|
|
54
|
+
getAPIList<Item, PageClass extends AbstractPage<Item> = AbstractPage<Item>>(
|
|
55
|
+
path: string,
|
|
56
|
+
Page: new (...args: any[]) => PageClass,
|
|
57
|
+
opts?: RequestOptions<any>,
|
|
58
|
+
): PagePromise<PageClass>;
|
|
59
|
+
request<Req, Rsp>(options: FinalRequestOptions<Req>, retriesRemaining?: number): Promise<APIResponse<Rsp>>;
|
|
60
|
+
requestAPIList<Item = unknown, PageClass extends AbstractPage<Item> = AbstractPage<Item>>(
|
|
61
|
+
Page: new (...args: ConstructorParameters<typeof AbstractPage>) => PageClass,
|
|
62
|
+
options: FinalRequestOptions,
|
|
63
|
+
): PagePromise<PageClass>;
|
|
64
|
+
buildURL<Req>(path: string, query: Req | undefined): string;
|
|
65
|
+
fetchWithTimeout(
|
|
66
|
+
url: RequestInfo,
|
|
67
|
+
{ signal, ...options }: RequestInit | undefined,
|
|
68
|
+
ms: number,
|
|
69
|
+
): Promise<Response>;
|
|
70
|
+
private shouldRetry;
|
|
71
|
+
private retryRequest;
|
|
72
|
+
private calculateRetryTimeoutSeconds;
|
|
73
|
+
private getUserAgent;
|
|
74
|
+
private debug;
|
|
75
|
+
}
|
|
76
|
+
export declare class APIResource {
|
|
77
|
+
protected client: APIClient;
|
|
78
|
+
constructor(client: APIClient);
|
|
79
|
+
protected get: APIClient['get'];
|
|
80
|
+
protected post: APIClient['post'];
|
|
81
|
+
protected patch: APIClient['patch'];
|
|
82
|
+
protected put: APIClient['put'];
|
|
83
|
+
protected delete: APIClient['delete'];
|
|
84
|
+
protected getAPIList: APIClient['getAPIList'];
|
|
85
|
+
}
|
|
86
|
+
export declare abstract class AbstractPage<Item> implements AsyncIterable<Item> {
|
|
87
|
+
#private;
|
|
88
|
+
protected options: FinalRequestOptions;
|
|
89
|
+
constructor(client: APIClient, response: APIResponse<unknown>, options: FinalRequestOptions);
|
|
90
|
+
abstract nextPageParams(): Partial<Record<string, unknown>> | null;
|
|
91
|
+
abstract getPaginatedItems(): Item[];
|
|
92
|
+
hasNextPage(): boolean;
|
|
93
|
+
getNextPage(): Promise<AbstractPage<Item>>;
|
|
94
|
+
iterPages(): AsyncGenerator<AbstractPage<Item>, void, unknown>;
|
|
95
|
+
[Symbol.asyncIterator](): AsyncGenerator<Awaited<Item>, void, unknown>;
|
|
96
|
+
}
|
|
97
|
+
export declare class PagePromise<
|
|
98
|
+
PageClass extends AbstractPage<Item>,
|
|
99
|
+
Item = ReturnType<PageClass['getPaginatedItems']>[number],
|
|
100
|
+
>
|
|
101
|
+
extends Promise<PageClass>
|
|
102
|
+
implements AsyncIterable<Item>
|
|
103
|
+
{
|
|
104
|
+
/**
|
|
105
|
+
* This subclass of Promise will resolve to an instantiated Page once the request completes.
|
|
106
|
+
*/
|
|
107
|
+
constructor(
|
|
108
|
+
client: APIClient,
|
|
109
|
+
requestPromise: Promise<APIResponse<unknown>>,
|
|
110
|
+
options: FinalRequestOptions,
|
|
111
|
+
Page: new (...args: ConstructorParameters<typeof AbstractPage>) => PageClass,
|
|
112
|
+
);
|
|
113
|
+
/**
|
|
114
|
+
* Enable subclassing Promise.
|
|
115
|
+
* Ref: https://stackoverflow.com/a/60328122
|
|
116
|
+
*/
|
|
117
|
+
static get [Symbol.species](): PromiseConstructor;
|
|
118
|
+
/**
|
|
119
|
+
* Allow auto-paginating iteration on an unawaited list call, eg:
|
|
120
|
+
*
|
|
121
|
+
* for await (const item of client.items.list()) {
|
|
122
|
+
* console.log(item)
|
|
123
|
+
* }
|
|
124
|
+
*/
|
|
125
|
+
[Symbol.asyncIterator](): AsyncGenerator<Awaited<Item>, void, unknown>;
|
|
126
|
+
}
|
|
127
|
+
export declare const createResponseHeaders: (
|
|
128
|
+
headers: Awaited<ReturnType<typeof NodeFetch>>['headers'],
|
|
129
|
+
) => Record<string, string>;
|
|
130
|
+
declare type HTTPMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
131
|
+
export declare type Headers = Record<string, string | null | undefined>;
|
|
132
|
+
export declare type KeysEnum<T> = {
|
|
133
|
+
[P in keyof Required<T>]: true;
|
|
134
|
+
};
|
|
135
|
+
export declare type RequestOptions<Req extends {} = Record<string, unknown> | Readable> = {
|
|
136
|
+
method?: HTTPMethod;
|
|
137
|
+
path?: string;
|
|
138
|
+
query?: Req | undefined;
|
|
139
|
+
body?: Req | undefined;
|
|
140
|
+
headers?: Headers | undefined;
|
|
141
|
+
maxRetries?: number;
|
|
142
|
+
timeout?: number;
|
|
143
|
+
httpAgent?: Agent;
|
|
144
|
+
};
|
|
145
|
+
export declare const isRequestOptions: (
|
|
146
|
+
obj: unknown,
|
|
147
|
+
) => obj is RequestOptions<Readable | Record<string, unknown>>;
|
|
148
|
+
export declare type FinalRequestOptions<Req extends {} = Record<string, unknown> | Readable> =
|
|
149
|
+
RequestOptions<Req> & {
|
|
150
|
+
method: HTTPMethod;
|
|
151
|
+
path: string;
|
|
152
|
+
idempotencyKey?: string;
|
|
153
|
+
};
|
|
154
|
+
export declare type APIResponse<T> = T & {
|
|
155
|
+
responseHeaders: Headers;
|
|
156
|
+
};
|
|
157
|
+
export declare class APIError extends Error {
|
|
158
|
+
readonly status: number | undefined;
|
|
159
|
+
readonly headers: Headers | undefined;
|
|
160
|
+
readonly error: Object | undefined;
|
|
161
|
+
constructor(
|
|
162
|
+
status: number | undefined,
|
|
163
|
+
error: Object | undefined,
|
|
164
|
+
message: string | undefined,
|
|
165
|
+
headers: Headers | undefined,
|
|
166
|
+
);
|
|
167
|
+
static generate(
|
|
168
|
+
status: number | undefined,
|
|
169
|
+
error: Object | undefined,
|
|
170
|
+
message: string | undefined,
|
|
171
|
+
headers: Headers | undefined,
|
|
172
|
+
): APIError;
|
|
173
|
+
}
|
|
174
|
+
export declare class BadRequestError extends APIError {
|
|
175
|
+
readonly status: 400;
|
|
176
|
+
}
|
|
177
|
+
export declare class AuthenticationError extends APIError {
|
|
178
|
+
readonly status: 401;
|
|
179
|
+
}
|
|
180
|
+
export declare class PermissionDeniedError extends APIError {
|
|
181
|
+
readonly status: 403;
|
|
182
|
+
}
|
|
183
|
+
export declare class NotFoundError extends APIError {
|
|
184
|
+
readonly status: 404;
|
|
185
|
+
}
|
|
186
|
+
export declare class ConflictError extends APIError {
|
|
187
|
+
readonly status: 409;
|
|
188
|
+
}
|
|
189
|
+
export declare class UnprocessableEntityError extends APIError {
|
|
190
|
+
readonly status: 422;
|
|
191
|
+
}
|
|
192
|
+
export declare class RateLimitError extends APIError {
|
|
193
|
+
readonly status: 429;
|
|
194
|
+
}
|
|
195
|
+
export declare class InternalServerError extends APIError {}
|
|
196
|
+
export declare class APIConnectionError extends APIError {
|
|
197
|
+
readonly status: undefined;
|
|
198
|
+
constructor({ message, cause }: { message?: string; cause?: Error | undefined });
|
|
199
|
+
}
|
|
200
|
+
export declare class APIConnectionTimeoutError extends APIConnectionError {
|
|
201
|
+
constructor();
|
|
202
|
+
}
|
|
203
|
+
export declare const multipartFormRequestOptions: <T = Record<string, unknown>>(
|
|
204
|
+
opts: RequestOptions<T>,
|
|
205
|
+
) => RequestOptions<Readable | T>;
|
|
206
|
+
export declare const coerceInteger: (value: unknown) => number;
|
|
207
|
+
export declare function isEmptyObj(obj: Object | null | undefined): boolean;
|
|
208
|
+
export declare function hasOwn(obj: Object, key: string): boolean;
|
|
209
|
+
export interface HeadersProtocol {
|
|
210
|
+
get: (header: string) => string | null | undefined;
|
|
211
|
+
}
|
|
212
|
+
export declare type HeadersLike = Record<string, string | string[] | undefined> | HeadersProtocol;
|
|
213
|
+
export declare const isHeadersProtocol: (headers: any) => headers is HeadersProtocol;
|
|
214
|
+
export declare const getHeader: (headers: HeadersLike, key: string) => string | null | undefined;
|
|
215
|
+
export {};
|