increase 0.8.0 → 0.9.0
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/CHANGELOG.md +63 -0
- package/README.md +37 -13
- package/_shims/ReadableStream.d.ts +38 -0
- package/_shims/ReadableStream.js +5 -0
- package/_shims/ReadableStream.mjs +7 -0
- package/_shims/ReadableStream.node.d.ts +6 -0
- package/_shims/ReadableStream.node.d.ts.map +1 -0
- package/_shims/ReadableStream.node.js +14 -0
- package/_shims/ReadableStream.node.js.map +1 -0
- package/_shims/ReadableStream.node.mjs +3 -0
- package/_shims/ReadableStream.node.mjs.map +1 -0
- package/_shims/fetch.d.ts +8 -1
- package/_shims/fetch.node.d.ts +11 -1
- package/core.d.ts +85 -27
- package/core.d.ts.map +1 -1
- package/core.js +208 -51
- package/core.js.map +1 -1
- package/core.mjs +194 -51
- package/core.mjs.map +1 -1
- package/error.d.ts +1 -0
- package/error.d.ts.map +1 -1
- package/error.js +12 -3
- package/error.js.map +1 -1
- package/error.mjs +12 -3
- package/error.mjs.map +1 -1
- package/index.d.mts +6 -1
- package/index.d.ts +6 -1
- package/index.d.ts.map +1 -1
- package/index.js +11 -8
- package/index.js.map +1 -1
- package/index.mjs +11 -8
- package/index.mjs.map +1 -1
- package/package.json +1 -1
- package/pagination.d.ts +2 -2
- package/pagination.d.ts.map +1 -1
- package/pagination.js +4 -4
- package/pagination.js.map +1 -1
- package/pagination.mjs +4 -4
- package/pagination.mjs.map +1 -1
- package/resources/account-numbers.d.ts +8 -8
- package/resources/account-numbers.d.ts.map +1 -1
- package/resources/account-numbers.js.map +1 -1
- package/resources/account-numbers.mjs.map +1 -1
- package/resources/account-statements.d.ts +3 -6
- package/resources/account-statements.d.ts.map +1 -1
- package/resources/account-statements.js.map +1 -1
- package/resources/account-statements.mjs.map +1 -1
- package/resources/account-transfers.d.ts +6 -18
- package/resources/account-transfers.d.ts.map +1 -1
- package/resources/account-transfers.js.map +1 -1
- package/resources/account-transfers.mjs.map +1 -1
- package/resources/accounts.d.ts +6 -6
- package/resources/accounts.d.ts.map +1 -1
- package/resources/ach-prenotifications.d.ts +51 -7
- package/resources/ach-prenotifications.d.ts.map +1 -1
- package/resources/ach-prenotifications.js.map +1 -1
- package/resources/ach-prenotifications.mjs.map +1 -1
- package/resources/ach-transfers.d.ts +16 -9
- package/resources/ach-transfers.d.ts.map +1 -1
- package/resources/ach-transfers.js.map +1 -1
- package/resources/ach-transfers.mjs.map +1 -1
- package/resources/balance-lookups.d.ts +1 -1
- package/resources/balance-lookups.d.ts.map +1 -1
- package/resources/bookkeeping-accounts.d.ts +3 -3
- package/resources/bookkeeping-accounts.d.ts.map +1 -1
- package/resources/bookkeeping-entries.d.ts +2 -2
- package/resources/bookkeeping-entries.d.ts.map +1 -1
- package/resources/bookkeeping-entry-sets.d.ts +1 -1
- package/resources/bookkeeping-entry-sets.d.ts.map +1 -1
- package/resources/card-disputes.d.ts +7 -7
- package/resources/card-disputes.d.ts.map +1 -1
- package/resources/card-disputes.js.map +1 -1
- package/resources/card-disputes.mjs.map +1 -1
- package/resources/card-profiles.d.ts +32 -11
- package/resources/card-profiles.d.ts.map +1 -1
- package/resources/card-profiles.js +6 -0
- package/resources/card-profiles.js.map +1 -1
- package/resources/card-profiles.mjs +6 -0
- package/resources/card-profiles.mjs.map +1 -1
- package/resources/card-purchase-supplements.d.ts +270 -0
- package/resources/card-purchase-supplements.d.ts.map +1 -0
- package/resources/card-purchase-supplements.js +28 -0
- package/resources/card-purchase-supplements.js.map +1 -0
- package/resources/card-purchase-supplements.mjs +21 -0
- package/resources/card-purchase-supplements.mjs.map +1 -0
- package/resources/cards.d.ts +6 -13
- package/resources/cards.d.ts.map +1 -1
- package/resources/cards.js.map +1 -1
- package/resources/cards.mjs.map +1 -1
- package/resources/check-deposits.d.ts +7 -7
- package/resources/check-deposits.d.ts.map +1 -1
- package/resources/check-deposits.js.map +1 -1
- package/resources/check-deposits.mjs.map +1 -1
- package/resources/check-transfers.d.ts +18 -11
- package/resources/check-transfers.d.ts.map +1 -1
- package/resources/check-transfers.js.map +1 -1
- package/resources/check-transfers.mjs.map +1 -1
- package/resources/declined-transactions.d.ts +25 -28
- package/resources/declined-transactions.d.ts.map +1 -1
- package/resources/declined-transactions.js.map +1 -1
- package/resources/declined-transactions.mjs.map +1 -1
- package/resources/digital-wallet-tokens.d.ts +3 -6
- package/resources/digital-wallet-tokens.d.ts.map +1 -1
- package/resources/digital-wallet-tokens.js.map +1 -1
- package/resources/digital-wallet-tokens.mjs.map +1 -1
- package/resources/documents.d.ts +3 -3
- package/resources/documents.d.ts.map +1 -1
- package/resources/entities/beneficial-owners.d.ts +215 -0
- package/resources/entities/beneficial-owners.d.ts.map +1 -0
- package/resources/entities/beneficial-owners.js +18 -0
- package/resources/entities/beneficial-owners.js.map +1 -0
- package/resources/entities/beneficial-owners.mjs +12 -0
- package/resources/entities/beneficial-owners.mjs.map +1 -0
- package/resources/entities/entities.d.ts +15 -11
- package/resources/entities/entities.d.ts.map +1 -1
- package/resources/entities/entities.js +9 -0
- package/resources/entities/entities.js.map +1 -1
- package/resources/entities/entities.mjs +9 -0
- package/resources/entities/entities.mjs.map +1 -1
- package/resources/entities/index.d.ts +1 -0
- package/resources/entities/index.d.ts.map +1 -1
- package/resources/entities/index.js +8 -0
- package/resources/entities/index.js.map +1 -1
- package/resources/entities/index.mjs +1 -0
- package/resources/entities/index.mjs.map +1 -1
- package/resources/entities/supplemental-documents.d.ts +2 -2
- package/resources/entities/supplemental-documents.d.ts.map +1 -1
- package/resources/event-subscriptions.d.ts +5 -8
- package/resources/event-subscriptions.d.ts.map +1 -1
- package/resources/event-subscriptions.js.map +1 -1
- package/resources/event-subscriptions.mjs.map +1 -1
- package/resources/events.d.ts +7 -5
- package/resources/events.d.ts.map +1 -1
- package/resources/events.js.map +1 -1
- package/resources/events.mjs.map +1 -1
- package/resources/exports.d.ts +4 -4
- package/resources/exports.d.ts.map +1 -1
- package/resources/external-accounts.d.ts +5 -11
- package/resources/external-accounts.d.ts.map +1 -1
- package/resources/external-accounts.js.map +1 -1
- package/resources/external-accounts.mjs.map +1 -1
- package/resources/files.d.ts +9 -4
- package/resources/files.d.ts.map +1 -1
- package/resources/files.js +2 -2
- package/resources/files.js.map +1 -1
- package/resources/files.mjs +2 -2
- package/resources/files.mjs.map +1 -1
- package/resources/groups.d.ts +1 -1
- package/resources/groups.d.ts.map +1 -1
- package/resources/inbound-ach-transfer-returns.d.ts +6 -4
- package/resources/inbound-ach-transfer-returns.d.ts.map +1 -1
- package/resources/inbound-ach-transfer-returns.js.map +1 -1
- package/resources/inbound-ach-transfer-returns.mjs.map +1 -1
- package/resources/inbound-wire-drawdown-requests.d.ts +5 -3
- package/resources/inbound-wire-drawdown-requests.d.ts.map +1 -1
- package/resources/inbound-wire-drawdown-requests.js.map +1 -1
- package/resources/inbound-wire-drawdown-requests.mjs.map +1 -1
- package/resources/index.d.ts +6 -0
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +18 -3
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +1 -0
- package/resources/index.mjs.map +1 -1
- package/resources/limits.d.ts +5 -9
- package/resources/limits.d.ts.map +1 -1
- package/resources/limits.js.map +1 -1
- package/resources/limits.mjs.map +1 -1
- package/resources/oauth-connections.d.ts +3 -6
- package/resources/oauth-connections.d.ts.map +1 -1
- package/resources/oauth-connections.js.map +1 -1
- package/resources/oauth-connections.mjs.map +1 -1
- package/resources/pending-transactions.d.ts +32 -37
- package/resources/pending-transactions.d.ts.map +1 -1
- package/resources/pending-transactions.js.map +1 -1
- package/resources/pending-transactions.mjs.map +1 -1
- package/resources/programs.d.ts +3 -3
- package/resources/programs.d.ts.map +1 -1
- package/resources/real-time-decisions.d.ts +2 -5
- package/resources/real-time-decisions.d.ts.map +1 -1
- package/resources/real-time-decisions.js.map +1 -1
- package/resources/real-time-decisions.mjs.map +1 -1
- package/resources/real-time-payments-transfers.d.ts +6 -4
- package/resources/real-time-payments-transfers.d.ts.map +1 -1
- package/resources/real-time-payments-transfers.js.map +1 -1
- package/resources/real-time-payments-transfers.mjs.map +1 -1
- package/resources/routing-numbers.d.ts +4 -1
- package/resources/routing-numbers.d.ts.map +1 -1
- package/resources/routing-numbers.js.map +1 -1
- package/resources/routing-numbers.mjs.map +1 -1
- package/resources/simulations/account-statements.d.ts +1 -1
- package/resources/simulations/account-statements.d.ts.map +1 -1
- package/resources/simulations/account-transfers.d.ts +1 -1
- package/resources/simulations/account-transfers.d.ts.map +1 -1
- package/resources/simulations/ach-transfers.d.ts +1063 -157
- package/resources/simulations/ach-transfers.d.ts.map +1 -1
- package/resources/simulations/ach-transfers.js.map +1 -1
- package/resources/simulations/ach-transfers.mjs.map +1 -1
- package/resources/simulations/card-disputes.d.ts +1 -1
- package/resources/simulations/card-disputes.d.ts.map +1 -1
- package/resources/simulations/card-profiles.d.ts +1 -4
- package/resources/simulations/card-profiles.d.ts.map +1 -1
- package/resources/simulations/card-profiles.js.map +1 -1
- package/resources/simulations/card-profiles.mjs.map +1 -1
- package/resources/simulations/card-refunds.d.ts +1 -1
- package/resources/simulations/card-refunds.d.ts.map +1 -1
- package/resources/simulations/cards.d.ts +53 -58
- package/resources/simulations/cards.d.ts.map +1 -1
- package/resources/simulations/cards.js.map +1 -1
- package/resources/simulations/cards.mjs.map +1 -1
- package/resources/simulations/check-deposits.d.ts +3 -12
- package/resources/simulations/check-deposits.d.ts.map +1 -1
- package/resources/simulations/check-transfers.d.ts +2 -2
- package/resources/simulations/check-transfers.d.ts.map +1 -1
- package/resources/simulations/digital-wallet-token-requests.d.ts +1 -1
- package/resources/simulations/digital-wallet-token-requests.d.ts.map +1 -1
- package/resources/simulations/documents.d.ts +1 -4
- package/resources/simulations/documents.d.ts.map +1 -1
- package/resources/simulations/documents.js.map +1 -1
- package/resources/simulations/documents.mjs.map +1 -1
- package/resources/simulations/inbound-funds-holds.d.ts +5 -1
- package/resources/simulations/inbound-funds-holds.d.ts.map +1 -1
- package/resources/simulations/inbound-funds-holds.js.map +1 -1
- package/resources/simulations/inbound-funds-holds.mjs.map +1 -1
- package/resources/simulations/inbound-wire-drawdown-requests.d.ts +1 -1
- package/resources/simulations/inbound-wire-drawdown-requests.d.ts.map +1 -1
- package/resources/simulations/interest-payments.d.ts +1047 -127
- package/resources/simulations/interest-payments.d.ts.map +1 -1
- package/resources/simulations/interest-payments.js.map +1 -1
- package/resources/simulations/interest-payments.mjs.map +1 -1
- package/resources/simulations/programs.d.ts +1 -4
- package/resources/simulations/programs.d.ts.map +1 -1
- package/resources/simulations/programs.js.map +1 -1
- package/resources/simulations/programs.mjs.map +1 -1
- package/resources/simulations/real-time-payments-transfers.d.ts +1062 -153
- package/resources/simulations/real-time-payments-transfers.d.ts.map +1 -1
- package/resources/simulations/real-time-payments-transfers.js.map +1 -1
- package/resources/simulations/real-time-payments-transfers.mjs.map +1 -1
- package/resources/simulations/simulations.d.ts.map +1 -1
- package/resources/simulations/simulations.js.map +1 -1
- package/resources/simulations/wire-transfers.d.ts +1039 -127
- package/resources/simulations/wire-transfers.d.ts.map +1 -1
- package/resources/simulations/wire-transfers.js.map +1 -1
- package/resources/simulations/wire-transfers.mjs.map +1 -1
- package/resources/transactions.d.ts +1044 -130
- package/resources/transactions.d.ts.map +1 -1
- package/resources/transactions.js.map +1 -1
- package/resources/transactions.mjs.map +1 -1
- package/resources/wire-drawdown-requests.d.ts +4 -4
- package/resources/wire-drawdown-requests.d.ts.map +1 -1
- package/resources/wire-transfers.d.ts +11 -11
- package/resources/wire-transfers.d.ts.map +1 -1
- package/resources/wire-transfers.js.map +1 -1
- package/resources/wire-transfers.mjs.map +1 -1
- package/src/_shims/ReadableStream.d.ts +38 -0
- package/src/_shims/ReadableStream.js +5 -0
- package/src/_shims/ReadableStream.mjs +7 -0
- package/src/_shims/ReadableStream.node.ts +6 -0
- package/src/_shims/fetch.d.ts +8 -1
- package/src/_shims/fetch.deno.ts +23 -0
- package/src/_shims/fetch.node.d.ts +11 -1
- package/src/_shims/formdata.deno.ts +16 -0
- package/src/core.ts +270 -74
- package/src/error.ts +11 -1
- package/src/index.ts +16 -9
- package/src/pagination.ts +5 -5
- package/src/resources/account-numbers.ts +10 -10
- package/src/resources/account-statements.ts +5 -8
- package/src/resources/account-transfers.ts +8 -20
- package/src/resources/accounts.ts +8 -8
- package/src/resources/ach-prenotifications.ts +57 -9
- package/src/resources/ach-transfers.ts +19 -11
- package/src/resources/balance-lookups.ts +2 -2
- package/src/resources/bookkeeping-accounts.ts +5 -5
- package/src/resources/bookkeeping-entries.ts +4 -4
- package/src/resources/bookkeeping-entry-sets.ts +2 -2
- package/src/resources/card-disputes.ts +9 -9
- package/src/resources/card-profiles.ts +39 -13
- package/src/resources/card-purchase-supplements.ts +331 -0
- package/src/resources/cards.ts +8 -15
- package/src/resources/check-deposits.ts +9 -9
- package/src/resources/check-transfers.ts +21 -13
- package/src/resources/declined-transactions.ts +27 -30
- package/src/resources/digital-wallet-tokens.ts +5 -8
- package/src/resources/documents.ts +5 -5
- package/src/resources/entities/beneficial-owners.ts +251 -0
- package/src/resources/entities/entities.ts +21 -13
- package/src/resources/entities/index.ts +1 -0
- package/src/resources/entities/supplemental-documents.ts +3 -3
- package/src/resources/event-subscriptions.ts +7 -10
- package/src/resources/events.ts +9 -7
- package/src/resources/exports.ts +6 -6
- package/src/resources/external-accounts.ts +7 -13
- package/src/resources/files.ts +12 -7
- package/src/resources/groups.ts +2 -2
- package/src/resources/inbound-ach-transfer-returns.ts +8 -6
- package/src/resources/inbound-wire-drawdown-requests.ts +7 -5
- package/src/resources/index.ts +6 -0
- package/src/resources/limits.ts +7 -11
- package/src/resources/oauth-connections.ts +5 -8
- package/src/resources/pending-transactions.ts +35 -39
- package/src/resources/programs.ts +5 -5
- package/src/resources/real-time-decisions.ts +3 -6
- package/src/resources/real-time-payments-transfers.ts +8 -6
- package/src/resources/routing-numbers.ts +5 -2
- package/src/resources/simulations/account-statements.ts +2 -2
- package/src/resources/simulations/account-transfers.ts +1 -1
- package/src/resources/simulations/ach-transfers.ts +1200 -160
- package/src/resources/simulations/card-disputes.ts +2 -2
- package/src/resources/simulations/card-profiles.ts +1 -4
- package/src/resources/simulations/card-refunds.ts +2 -2
- package/src/resources/simulations/cards.ts +55 -59
- package/src/resources/simulations/check-deposits.ts +3 -3
- package/src/resources/simulations/check-transfers.ts +2 -2
- package/src/resources/simulations/digital-wallet-token-requests.ts +2 -2
- package/src/resources/simulations/documents.ts +2 -5
- package/src/resources/simulations/inbound-funds-holds.ts +7 -2
- package/src/resources/simulations/inbound-wire-drawdown-requests.ts +2 -2
- package/src/resources/simulations/interest-payments.ts +1186 -130
- package/src/resources/simulations/programs.ts +2 -5
- package/src/resources/simulations/real-time-payments-transfers.ts +1199 -156
- package/src/resources/simulations/simulations.ts +1 -1
- package/src/resources/simulations/wire-transfers.ts +1176 -130
- package/src/resources/transactions.ts +1182 -134
- package/src/resources/wire-drawdown-requests.ts +6 -6
- package/src/resources/wire-transfers.ts +13 -13
- package/src/uploads.ts +7 -6
- package/src/version.ts +1 -1
- package/uploads.d.ts +5 -4
- package/uploads.d.ts.map +1 -1
- package/uploads.js +2 -2
- package/uploads.js.map +1 -1
- package/uploads.mjs +2 -2
- package/uploads.mjs.map +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/src/core.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
type RequestInit,
|
|
10
10
|
type Response,
|
|
11
11
|
} from './_shims/fetch.js';
|
|
12
|
+
export { type Response };
|
|
12
13
|
import { isMultipartBody } from './uploads';
|
|
13
14
|
export {
|
|
14
15
|
maybeMultipartFormRequestOptions,
|
|
@@ -21,6 +22,100 @@ const MAX_RETRIES = 2;
|
|
|
21
22
|
|
|
22
23
|
export type Fetch = (url: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
23
24
|
|
|
25
|
+
type PromiseOrValue<T> = T | Promise<T>;
|
|
26
|
+
|
|
27
|
+
type APIResponseProps = {
|
|
28
|
+
response: Response;
|
|
29
|
+
options: FinalRequestOptions;
|
|
30
|
+
controller: AbortController;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
async function defaultParseResponse<T>(props: APIResponseProps): Promise<T> {
|
|
34
|
+
const { response } = props;
|
|
35
|
+
const contentType = response.headers.get('content-type');
|
|
36
|
+
if (contentType?.includes('application/json')) {
|
|
37
|
+
const json = await response.json();
|
|
38
|
+
|
|
39
|
+
debug('response', response.status, response.url, response.headers, json);
|
|
40
|
+
|
|
41
|
+
return json as T;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// TODO handle blob, arraybuffer, other content types, etc.
|
|
45
|
+
const text = await response.text();
|
|
46
|
+
debug('response', response.status, response.url, response.headers, text);
|
|
47
|
+
return text as T;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A subclass of `Promise` providing additional helper methods
|
|
52
|
+
* for interacting with the SDK.
|
|
53
|
+
*/
|
|
54
|
+
export class APIPromise<T> extends Promise<T> {
|
|
55
|
+
private parsedPromise: Promise<T> | undefined;
|
|
56
|
+
|
|
57
|
+
constructor(
|
|
58
|
+
private responsePromise: Promise<APIResponseProps>,
|
|
59
|
+
private parseResponse: (props: APIResponseProps) => PromiseOrValue<T> = defaultParseResponse,
|
|
60
|
+
) {
|
|
61
|
+
super((resolve) => {
|
|
62
|
+
// this is maybe a bit weird but this has to be a no-op to not implicitly
|
|
63
|
+
// parse the response body; instead .then, .catch, .finally are overridden
|
|
64
|
+
// to parse the response
|
|
65
|
+
resolve(null as any);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
_thenUnwrap<U>(transform: (data: T) => U): APIPromise<U> {
|
|
70
|
+
return new APIPromise(this.responsePromise, async (props) => transform(await this.parseResponse(props)));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Gets the raw `Response` instance instead of parsing the response
|
|
75
|
+
* data.
|
|
76
|
+
*
|
|
77
|
+
* If you want to parse the response body but still get the `Response`
|
|
78
|
+
* instance, you can use {@link withResponse()}.
|
|
79
|
+
*/
|
|
80
|
+
asResponse(): Promise<Response> {
|
|
81
|
+
return this.responsePromise.then((p) => p.response);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Gets the parsed response data and the raw `Response` instance.
|
|
85
|
+
*
|
|
86
|
+
* If you just want to get the raw `Response` instance without parsing it,
|
|
87
|
+
* you can use {@link asResponse()}.
|
|
88
|
+
*/
|
|
89
|
+
async withResponse(): Promise<{ data: T; response: Response }> {
|
|
90
|
+
const [data, response] = await Promise.all([this.parse(), this.asResponse()]);
|
|
91
|
+
return { data, response };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private parse(): Promise<T> {
|
|
95
|
+
if (!this.parsedPromise) {
|
|
96
|
+
this.parsedPromise = this.responsePromise.then(this.parseResponse);
|
|
97
|
+
}
|
|
98
|
+
return this.parsedPromise;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
override then<TResult1 = T, TResult2 = never>(
|
|
102
|
+
onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null,
|
|
103
|
+
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null,
|
|
104
|
+
): Promise<TResult1 | TResult2> {
|
|
105
|
+
return this.parse().then(onfulfilled, onrejected);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
override catch<TResult = never>(
|
|
109
|
+
onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null,
|
|
110
|
+
): Promise<T | TResult> {
|
|
111
|
+
return this.parse().catch(onrejected);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
override finally(onfinally?: (() => void) | undefined | null): Promise<T> {
|
|
115
|
+
return this.parse().finally(onfinally);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
24
119
|
export abstract class APIClient {
|
|
25
120
|
baseURL: string;
|
|
26
121
|
maxRetries: number;
|
|
@@ -84,27 +179,39 @@ export abstract class APIClient {
|
|
|
84
179
|
return `stainless-node-retry-${uuid4()}`;
|
|
85
180
|
}
|
|
86
181
|
|
|
87
|
-
get<Req extends {}, Rsp>(path: string, opts?: RequestOptions<Req
|
|
88
|
-
return this.
|
|
182
|
+
get<Req extends {}, Rsp>(path: string, opts?: PromiseOrValue<RequestOptions<Req>>): APIPromise<Rsp> {
|
|
183
|
+
return this.methodRequest('get', path, opts);
|
|
89
184
|
}
|
|
90
|
-
|
|
91
|
-
|
|
185
|
+
|
|
186
|
+
post<Req extends {}, Rsp>(path: string, opts?: PromiseOrValue<RequestOptions<Req>>): APIPromise<Rsp> {
|
|
187
|
+
return this.methodRequest('post', path, opts);
|
|
92
188
|
}
|
|
93
|
-
|
|
94
|
-
|
|
189
|
+
|
|
190
|
+
patch<Req extends {}, Rsp>(path: string, opts?: PromiseOrValue<RequestOptions<Req>>): APIPromise<Rsp> {
|
|
191
|
+
return this.methodRequest('patch', path, opts);
|
|
95
192
|
}
|
|
96
|
-
|
|
97
|
-
|
|
193
|
+
|
|
194
|
+
put<Req extends {}, Rsp>(path: string, opts?: PromiseOrValue<RequestOptions<Req>>): APIPromise<Rsp> {
|
|
195
|
+
return this.methodRequest('put', path, opts);
|
|
98
196
|
}
|
|
99
|
-
|
|
100
|
-
|
|
197
|
+
|
|
198
|
+
delete<Req extends {}, Rsp>(path: string, opts?: PromiseOrValue<RequestOptions<Req>>): APIPromise<Rsp> {
|
|
199
|
+
return this.methodRequest('delete', path, opts);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private methodRequest<Req extends {}, Rsp>(
|
|
203
|
+
method: HTTPMethod,
|
|
204
|
+
path: string,
|
|
205
|
+
opts?: PromiseOrValue<RequestOptions<Req>>,
|
|
206
|
+
): APIPromise<Rsp> {
|
|
207
|
+
return this.request(Promise.resolve(opts).then((opts) => ({ method, path, ...opts })));
|
|
101
208
|
}
|
|
102
209
|
|
|
103
210
|
getAPIList<Item, PageClass extends AbstractPage<Item> = AbstractPage<Item>>(
|
|
104
211
|
path: string,
|
|
105
212
|
Page: new (...args: any[]) => PageClass,
|
|
106
213
|
opts?: RequestOptions<any>,
|
|
107
|
-
): PagePromise<PageClass> {
|
|
214
|
+
): PagePromise<PageClass, Item> {
|
|
108
215
|
return this.requestAPIList(Page, { method: 'get', path, ...opts });
|
|
109
216
|
}
|
|
110
217
|
|
|
@@ -198,14 +305,27 @@ export abstract class APIClient {
|
|
|
198
305
|
return APIError.generate(status, error, message, headers);
|
|
199
306
|
}
|
|
200
307
|
|
|
201
|
-
|
|
202
|
-
options: FinalRequestOptions<Req
|
|
203
|
-
|
|
204
|
-
):
|
|
308
|
+
request<Req extends {}, Rsp>(
|
|
309
|
+
options: PromiseOrValue<FinalRequestOptions<Req>>,
|
|
310
|
+
remainingRetries: number | null = null,
|
|
311
|
+
): APIPromise<Rsp> {
|
|
312
|
+
return new APIPromise(this.makeRequest(options, remainingRetries));
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
private async makeRequest<T>(
|
|
316
|
+
optionsInput: PromiseOrValue<FinalRequestOptions>,
|
|
317
|
+
retriesRemaining: number | null,
|
|
318
|
+
): Promise<{ response: Response; options: FinalRequestOptions; controller: AbortController }> {
|
|
319
|
+
const options = await optionsInput;
|
|
320
|
+
if (retriesRemaining == null) {
|
|
321
|
+
retriesRemaining = options.maxRetries ?? this.maxRetries;
|
|
322
|
+
}
|
|
323
|
+
|
|
205
324
|
const { req, url, timeout } = this.buildRequest(options);
|
|
325
|
+
|
|
206
326
|
await this.prepareRequest(req, { url });
|
|
207
327
|
|
|
208
|
-
|
|
328
|
+
debug('request', url, options, req.headers);
|
|
209
329
|
|
|
210
330
|
if (options.signal?.aborted) {
|
|
211
331
|
throw new APIUserAbortError();
|
|
@@ -238,42 +358,21 @@ export abstract class APIClient {
|
|
|
238
358
|
const errJSON = safeJSON(errText);
|
|
239
359
|
const errMessage = errJSON ? undefined : errText;
|
|
240
360
|
|
|
241
|
-
|
|
361
|
+
debug('response', response.status, url, responseHeaders, errMessage);
|
|
242
362
|
|
|
243
363
|
const err = this.makeStatusError(response.status, errJSON, errMessage, responseHeaders);
|
|
244
364
|
throw err;
|
|
245
365
|
}
|
|
246
366
|
|
|
247
|
-
|
|
248
|
-
if (contentType?.includes('application/json')) {
|
|
249
|
-
const json = await response.json();
|
|
250
|
-
|
|
251
|
-
if (typeof json === 'object' && json != null) {
|
|
252
|
-
/** @deprecated – we expect to change this interface in the near future. */
|
|
253
|
-
Object.defineProperty(json, 'responseHeaders', {
|
|
254
|
-
enumerable: false,
|
|
255
|
-
writable: false,
|
|
256
|
-
value: responseHeaders,
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
this.debug('response', response.status, url, responseHeaders, json);
|
|
261
|
-
|
|
262
|
-
return json as APIResponse<Rsp>;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// TODO handle blob, arraybuffer, other content types, etc.
|
|
266
|
-
const text = response.text();
|
|
267
|
-
this.debug('response', response.status, url, responseHeaders, text);
|
|
268
|
-
return text as Promise<any>;
|
|
367
|
+
return { response, options, controller };
|
|
269
368
|
}
|
|
270
369
|
|
|
271
370
|
requestAPIList<Item = unknown, PageClass extends AbstractPage<Item> = AbstractPage<Item>>(
|
|
272
371
|
Page: new (...args: ConstructorParameters<typeof AbstractPage>) => PageClass,
|
|
273
372
|
options: FinalRequestOptions,
|
|
274
|
-
): PagePromise<PageClass> {
|
|
275
|
-
const
|
|
276
|
-
return new PagePromise(this,
|
|
373
|
+
): PagePromise<PageClass, Item> {
|
|
374
|
+
const request = this.makeRequest(options, null);
|
|
375
|
+
return new PagePromise<PageClass, Item>(this, request, Page);
|
|
277
376
|
}
|
|
278
377
|
|
|
279
378
|
buildURL<Req>(path: string, query: Req | undefined): string {
|
|
@@ -401,12 +500,6 @@ export abstract class APIClient {
|
|
|
401
500
|
private getUserAgent(): string {
|
|
402
501
|
return `${this.constructor.name}/JS ${VERSION}`;
|
|
403
502
|
}
|
|
404
|
-
|
|
405
|
-
private debug(action: string, ...args: any[]) {
|
|
406
|
-
if (typeof process !== 'undefined' && process.env['DEBUG'] === 'true') {
|
|
407
|
-
console.log(`${this.constructor.name}:DEBUG:${action}`, ...args);
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
503
|
}
|
|
411
504
|
|
|
412
505
|
export class APIResource {
|
|
@@ -436,9 +529,14 @@ export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
|
|
|
436
529
|
#client: APIClient;
|
|
437
530
|
protected options: FinalRequestOptions;
|
|
438
531
|
|
|
439
|
-
|
|
532
|
+
protected response: Response;
|
|
533
|
+
protected body: unknown;
|
|
534
|
+
|
|
535
|
+
constructor(client: APIClient, response: Response, body: unknown, options: FinalRequestOptions) {
|
|
440
536
|
this.#client = client;
|
|
441
537
|
this.options = options;
|
|
538
|
+
this.response = response;
|
|
539
|
+
this.body = body;
|
|
442
540
|
}
|
|
443
541
|
|
|
444
542
|
/**
|
|
@@ -495,35 +593,33 @@ export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
|
|
|
495
593
|
}
|
|
496
594
|
}
|
|
497
595
|
|
|
596
|
+
/**
|
|
597
|
+
* This subclass of Promise will resolve to an instantiated Page once the request completes.
|
|
598
|
+
*
|
|
599
|
+
* It also implements AsyncIterable to allow auto-paginating iteration on an unawaited list call, eg:
|
|
600
|
+
*
|
|
601
|
+
* for await (const item of client.items.list()) {
|
|
602
|
+
* console.log(item)
|
|
603
|
+
* }
|
|
604
|
+
*/
|
|
498
605
|
export class PagePromise<
|
|
499
606
|
PageClass extends AbstractPage<Item>,
|
|
500
607
|
Item = ReturnType<PageClass['getPaginatedItems']>[number],
|
|
501
608
|
>
|
|
502
|
-
extends
|
|
609
|
+
extends APIPromise<PageClass>
|
|
503
610
|
implements AsyncIterable<Item>
|
|
504
611
|
{
|
|
505
|
-
/**
|
|
506
|
-
* This subclass of Promise will resolve to an instantiated Page once the request completes.
|
|
507
|
-
*/
|
|
508
612
|
constructor(
|
|
509
613
|
client: APIClient,
|
|
510
|
-
|
|
511
|
-
options: FinalRequestOptions,
|
|
614
|
+
request: Promise<APIResponseProps>,
|
|
512
615
|
Page: new (...args: ConstructorParameters<typeof AbstractPage>) => PageClass,
|
|
513
616
|
) {
|
|
514
|
-
super(
|
|
515
|
-
|
|
617
|
+
super(
|
|
618
|
+
request,
|
|
619
|
+
async (props) => new Page(client, props.response, await defaultParseResponse(props), props.options),
|
|
516
620
|
);
|
|
517
621
|
}
|
|
518
622
|
|
|
519
|
-
/**
|
|
520
|
-
* Enable subclassing Promise.
|
|
521
|
-
* Ref: https://stackoverflow.com/a/60328122
|
|
522
|
-
*/
|
|
523
|
-
static get [Symbol.species]() {
|
|
524
|
-
return Promise;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
623
|
/**
|
|
528
624
|
* Allow auto-paginating iteration on an unawaited list call, eg:
|
|
529
625
|
*
|
|
@@ -610,11 +706,6 @@ export type FinalRequestOptions<Req extends {} = Record<string, unknown> | Reada
|
|
|
610
706
|
path: string;
|
|
611
707
|
};
|
|
612
708
|
|
|
613
|
-
export type APIResponse<T> = T & {
|
|
614
|
-
/** @deprecated - we plan to add a different way to access raw response information shortly. */
|
|
615
|
-
responseHeaders: Headers;
|
|
616
|
-
};
|
|
617
|
-
|
|
618
709
|
declare const Deno: any;
|
|
619
710
|
declare const EdgeRuntime: any;
|
|
620
711
|
type Arch = 'x32' | 'x64' | 'arm' | 'arm64' | `other:${string}` | 'unknown';
|
|
@@ -628,12 +719,13 @@ type PlatformName =
|
|
|
628
719
|
| 'Android'
|
|
629
720
|
| `Other:${string}`
|
|
630
721
|
| 'Unknown';
|
|
722
|
+
type Browser = 'ie' | 'edge' | 'chrome' | 'firefox' | 'safari';
|
|
631
723
|
type PlatformProperties = {
|
|
632
724
|
'X-Stainless-Lang': 'js';
|
|
633
725
|
'X-Stainless-Package-Version': string;
|
|
634
726
|
'X-Stainless-OS': PlatformName;
|
|
635
727
|
'X-Stainless-Arch': Arch;
|
|
636
|
-
'X-Stainless-Runtime': 'node' | 'deno' | 'edge' | 'unknown';
|
|
728
|
+
'X-Stainless-Runtime': 'node' | 'deno' | 'edge' | `browser:${Browser}` | 'unknown';
|
|
637
729
|
'X-Stainless-Runtime-Version': string;
|
|
638
730
|
};
|
|
639
731
|
const getPlatformProperties = (): PlatformProperties => {
|
|
@@ -668,7 +760,20 @@ const getPlatformProperties = (): PlatformProperties => {
|
|
|
668
760
|
'X-Stainless-Runtime-Version': process.version,
|
|
669
761
|
};
|
|
670
762
|
}
|
|
671
|
-
|
|
763
|
+
|
|
764
|
+
const browserInfo = getBrowserInfo();
|
|
765
|
+
if (browserInfo) {
|
|
766
|
+
return {
|
|
767
|
+
'X-Stainless-Lang': 'js',
|
|
768
|
+
'X-Stainless-Package-Version': VERSION,
|
|
769
|
+
'X-Stainless-OS': 'Unknown',
|
|
770
|
+
'X-Stainless-Arch': 'unknown',
|
|
771
|
+
'X-Stainless-Runtime': `browser:${browserInfo.browser}`,
|
|
772
|
+
'X-Stainless-Runtime-Version': browserInfo.version,
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
// TODO add support for Cloudflare workers, etc.
|
|
672
777
|
return {
|
|
673
778
|
'X-Stainless-Lang': 'js',
|
|
674
779
|
'X-Stainless-Package-Version': VERSION,
|
|
@@ -679,6 +784,44 @@ const getPlatformProperties = (): PlatformProperties => {
|
|
|
679
784
|
};
|
|
680
785
|
};
|
|
681
786
|
|
|
787
|
+
type BrowserInfo = {
|
|
788
|
+
browser: Browser;
|
|
789
|
+
version: string;
|
|
790
|
+
};
|
|
791
|
+
|
|
792
|
+
declare const navigator: { userAgent: string } | undefined;
|
|
793
|
+
|
|
794
|
+
// Note: modified from https://github.com/JS-DevTools/host-environment/blob/b1ab79ecde37db5d6e163c050e54fe7d287d7c92/src/isomorphic.browser.ts
|
|
795
|
+
function getBrowserInfo(): BrowserInfo | null {
|
|
796
|
+
if (!navigator || typeof navigator === 'undefined') {
|
|
797
|
+
return null;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// NOTE: The order matters here!
|
|
801
|
+
const browserPatterns = [
|
|
802
|
+
{ key: 'edge' as const, pattern: /Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
803
|
+
{ key: 'ie' as const, pattern: /MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
804
|
+
{ key: 'ie' as const, pattern: /Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
805
|
+
{ key: 'chrome' as const, pattern: /Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
806
|
+
{ key: 'firefox' as const, pattern: /Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
807
|
+
{ key: 'safari' as const, pattern: /(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/ },
|
|
808
|
+
];
|
|
809
|
+
|
|
810
|
+
// Find the FIRST matching browser
|
|
811
|
+
for (const { key, pattern } of browserPatterns) {
|
|
812
|
+
const match = pattern.exec(navigator.userAgent);
|
|
813
|
+
if (match) {
|
|
814
|
+
const major = match[1] || 0;
|
|
815
|
+
const minor = match[2] || 0;
|
|
816
|
+
const patch = match[3] || 0;
|
|
817
|
+
|
|
818
|
+
return { browser: key, version: `${major}.${minor}.${patch}` };
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
return null;
|
|
823
|
+
}
|
|
824
|
+
|
|
682
825
|
const normalizeArch = (arch: string): Arch => {
|
|
683
826
|
// Node docs:
|
|
684
827
|
// - https://nodejs.org/api/process.html#processarch
|
|
@@ -737,8 +880,8 @@ const isAbsoluteURL = (url: string): boolean => {
|
|
|
737
880
|
|
|
738
881
|
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
739
882
|
|
|
740
|
-
const validatePositiveInteger = (name: string, n:
|
|
741
|
-
if (!Number.isInteger(n)) {
|
|
883
|
+
const validatePositiveInteger = (name: string, n: unknown): number => {
|
|
884
|
+
if (typeof n !== 'number' || !Number.isInteger(n)) {
|
|
742
885
|
throw new Error(`${name} must be an integer`);
|
|
743
886
|
}
|
|
744
887
|
if (n < 0) {
|
|
@@ -757,6 +900,21 @@ export const ensurePresent = <T>(value: T | null | undefined): T => {
|
|
|
757
900
|
return value;
|
|
758
901
|
};
|
|
759
902
|
|
|
903
|
+
/**
|
|
904
|
+
* Read an environment variable.
|
|
905
|
+
*
|
|
906
|
+
* Will return undefined if the environment variable doesn't exist or cannot be accessed.
|
|
907
|
+
*/
|
|
908
|
+
export const readEnv = (env: string): string | undefined => {
|
|
909
|
+
if (typeof process !== 'undefined') {
|
|
910
|
+
return process.env?.[env] ?? undefined;
|
|
911
|
+
}
|
|
912
|
+
if (typeof Deno !== 'undefined') {
|
|
913
|
+
return Deno.env?.get?.(env);
|
|
914
|
+
}
|
|
915
|
+
return undefined;
|
|
916
|
+
};
|
|
917
|
+
|
|
760
918
|
export const coerceInteger = (value: unknown): number => {
|
|
761
919
|
if (typeof value === 'number') return Math.round(value);
|
|
762
920
|
if (typeof value === 'string') return parseInt(value, 10);
|
|
@@ -777,6 +935,27 @@ export const coerceBoolean = (value: unknown): boolean => {
|
|
|
777
935
|
return Boolean(value);
|
|
778
936
|
};
|
|
779
937
|
|
|
938
|
+
export const maybeCoerceInteger = (value: unknown): number | undefined => {
|
|
939
|
+
if (value === undefined) {
|
|
940
|
+
return undefined;
|
|
941
|
+
}
|
|
942
|
+
return coerceInteger(value);
|
|
943
|
+
};
|
|
944
|
+
|
|
945
|
+
export const maybeCoerceFloat = (value: unknown): number | undefined => {
|
|
946
|
+
if (value === undefined) {
|
|
947
|
+
return undefined;
|
|
948
|
+
}
|
|
949
|
+
return coerceFloat(value);
|
|
950
|
+
};
|
|
951
|
+
|
|
952
|
+
export const maybeCoerceBoolean = (value: unknown): boolean | undefined => {
|
|
953
|
+
if (value === undefined) {
|
|
954
|
+
return undefined;
|
|
955
|
+
}
|
|
956
|
+
return coerceBoolean(value);
|
|
957
|
+
};
|
|
958
|
+
|
|
780
959
|
// https://stackoverflow.com/a/34491287
|
|
781
960
|
export function isEmptyObj(obj: Object | null | undefined): boolean {
|
|
782
961
|
if (!obj) return true;
|
|
@@ -789,6 +968,12 @@ export function hasOwn(obj: Object, key: string): boolean {
|
|
|
789
968
|
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
790
969
|
}
|
|
791
970
|
|
|
971
|
+
export function debug(action: string, ...args: any[]) {
|
|
972
|
+
if (typeof process !== 'undefined' && process.env['DEBUG'] === 'true') {
|
|
973
|
+
console.log(`Increase:DEBUG:${action}`, ...args);
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
|
|
792
977
|
/**
|
|
793
978
|
* https://stackoverflow.com/a/2117523
|
|
794
979
|
*/
|
|
@@ -800,6 +985,17 @@ const uuid4 = () => {
|
|
|
800
985
|
});
|
|
801
986
|
};
|
|
802
987
|
|
|
988
|
+
export const isRunningInBrowser = () => {
|
|
989
|
+
return (
|
|
990
|
+
// @ts-ignore
|
|
991
|
+
typeof window !== 'undefined' &&
|
|
992
|
+
// @ts-ignore
|
|
993
|
+
typeof window.document !== 'undefined' &&
|
|
994
|
+
// @ts-ignore
|
|
995
|
+
typeof navigator !== 'undefined'
|
|
996
|
+
);
|
|
997
|
+
};
|
|
998
|
+
|
|
803
999
|
export interface HeadersProtocol {
|
|
804
1000
|
get: (header: string) => string | null | undefined;
|
|
805
1001
|
}
|
package/src/error.ts
CHANGED
|
@@ -13,12 +13,22 @@ export class APIError extends Error {
|
|
|
13
13
|
message: string | undefined,
|
|
14
14
|
headers: Headers | undefined,
|
|
15
15
|
) {
|
|
16
|
-
super(
|
|
16
|
+
super(APIError.makeMessage(error, message));
|
|
17
17
|
this.status = status;
|
|
18
18
|
this.headers = headers;
|
|
19
19
|
this.error = error;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
private static makeMessage(error: any, message: string | undefined) {
|
|
23
|
+
return (
|
|
24
|
+
error?.message ?
|
|
25
|
+
typeof error.message === 'string' ? error.message
|
|
26
|
+
: JSON.stringify(error.message)
|
|
27
|
+
: error ? JSON.stringify(error)
|
|
28
|
+
: message || 'Unknown error occurred'
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
22
32
|
static generate(
|
|
23
33
|
status: number | undefined,
|
|
24
34
|
errorResponse: Object | undefined,
|
package/src/index.ts
CHANGED
|
@@ -89,19 +89,19 @@ export class Increase extends Core.APIClient {
|
|
|
89
89
|
|
|
90
90
|
private _options: ClientOptions;
|
|
91
91
|
|
|
92
|
-
constructor(opts
|
|
92
|
+
constructor({ apiKey = Core.readEnv('INCREASE_API_KEY'), ...opts }: ClientOptions = {}) {
|
|
93
|
+
if (apiKey === undefined) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
'The INCREASE_API_KEY environment variable is missing or empty; either provide it, or instantiate the Increase client with an apiKey option, like new Increase({ apiKey: undefined }).',
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
93
99
|
const options: ClientOptions = {
|
|
94
|
-
apiKey
|
|
100
|
+
apiKey,
|
|
95
101
|
environment: 'production',
|
|
96
102
|
...opts,
|
|
97
103
|
};
|
|
98
104
|
|
|
99
|
-
if (!options.apiKey && options.apiKey !== null) {
|
|
100
|
-
throw new Error(
|
|
101
|
-
"The INCREASE_API_KEY environment variable is missing or empty; either provide it, or instantiate the Increase client with an apiKey option, like new Increase({ apiKey: 'my api key' }).",
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
105
|
super({
|
|
106
106
|
baseURL: options.baseURL || environments[options.environment || 'production'],
|
|
107
107
|
timeout: options.timeout,
|
|
@@ -109,9 +109,10 @@ export class Increase extends Core.APIClient {
|
|
|
109
109
|
maxRetries: options.maxRetries,
|
|
110
110
|
fetch: options.fetch,
|
|
111
111
|
});
|
|
112
|
-
this.apiKey = options.apiKey;
|
|
113
112
|
this._options = options;
|
|
114
113
|
this.idempotencyHeader = 'Idempotency-Key';
|
|
114
|
+
|
|
115
|
+
this.apiKey = apiKey;
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
accounts: API.Accounts = new API.Accounts(this);
|
|
@@ -125,6 +126,7 @@ export class Increase extends Core.APIClient {
|
|
|
125
126
|
cards: API.Cards = new API.Cards(this);
|
|
126
127
|
cardDisputes: API.CardDisputes = new API.CardDisputes(this);
|
|
127
128
|
cardProfiles: API.CardProfiles = new API.CardProfiles(this);
|
|
129
|
+
cardPurchaseSupplements: API.CardPurchaseSupplements = new API.CardPurchaseSupplements(this);
|
|
128
130
|
externalAccounts: API.ExternalAccounts = new API.ExternalAccounts(this);
|
|
129
131
|
exports: API.Exports = new API.Exports(this);
|
|
130
132
|
digitalWalletTokens: API.DigitalWalletTokens = new API.DigitalWalletTokens(this);
|
|
@@ -304,6 +306,11 @@ export namespace Increase {
|
|
|
304
306
|
export import CardProfileCreateParams = API.CardProfileCreateParams;
|
|
305
307
|
export import CardProfileListParams = API.CardProfileListParams;
|
|
306
308
|
|
|
309
|
+
export import CardPurchaseSupplements = API.CardPurchaseSupplements;
|
|
310
|
+
export import CardPurchaseSupplement = API.CardPurchaseSupplement;
|
|
311
|
+
export import CardPurchaseSupplementsPage = API.CardPurchaseSupplementsPage;
|
|
312
|
+
export import CardPurchaseSupplementListParams = API.CardPurchaseSupplementListParams;
|
|
313
|
+
|
|
307
314
|
export import ExternalAccounts = API.ExternalAccounts;
|
|
308
315
|
export import ExternalAccount = API.ExternalAccount;
|
|
309
316
|
export import ExternalAccountsPage = API.ExternalAccountsPage;
|
package/src/pagination.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless.
|
|
2
2
|
|
|
3
|
-
import { AbstractPage,
|
|
3
|
+
import { AbstractPage, Response, APIClient, FinalRequestOptions, PageInfo } from './core';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* A list of Account objects
|
|
@@ -35,11 +35,11 @@ export class Page<Item> extends AbstractPage<Item> implements PageResponse<Item>
|
|
|
35
35
|
*/
|
|
36
36
|
next_cursor: string | null;
|
|
37
37
|
|
|
38
|
-
constructor(client: APIClient, response:
|
|
39
|
-
super(client, response, options);
|
|
38
|
+
constructor(client: APIClient, response: Response, body: PageResponse<Item>, options: FinalRequestOptions) {
|
|
39
|
+
super(client, response, body, options);
|
|
40
40
|
|
|
41
|
-
this.data =
|
|
42
|
-
this.next_cursor =
|
|
41
|
+
this.data = body.data;
|
|
42
|
+
this.next_cursor = body.next_cursor;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
getPaginatedItems(): Item[] {
|
|
@@ -3,24 +3,21 @@
|
|
|
3
3
|
import * as Core from '../core';
|
|
4
4
|
import { APIResource } from '../resource';
|
|
5
5
|
import { isRequestOptions } from '../core';
|
|
6
|
-
import * as API from '
|
|
6
|
+
import * as API from './index';
|
|
7
7
|
import { Page, PageParams } from '../pagination';
|
|
8
8
|
|
|
9
9
|
export class AccountNumbers extends APIResource {
|
|
10
10
|
/**
|
|
11
11
|
* Create an Account Number
|
|
12
12
|
*/
|
|
13
|
-
create(
|
|
14
|
-
body: AccountNumberCreateParams,
|
|
15
|
-
options?: Core.RequestOptions,
|
|
16
|
-
): Promise<Core.APIResponse<AccountNumber>> {
|
|
13
|
+
create(body: AccountNumberCreateParams, options?: Core.RequestOptions): Core.APIPromise<AccountNumber> {
|
|
17
14
|
return this.post('/account_numbers', { body, ...options });
|
|
18
15
|
}
|
|
19
16
|
|
|
20
17
|
/**
|
|
21
18
|
* Retrieve an Account Number
|
|
22
19
|
*/
|
|
23
|
-
retrieve(accountNumberId: string, options?: Core.RequestOptions):
|
|
20
|
+
retrieve(accountNumberId: string, options?: Core.RequestOptions): Core.APIPromise<AccountNumber> {
|
|
24
21
|
return this.get(`/account_numbers/${accountNumberId}`, options);
|
|
25
22
|
}
|
|
26
23
|
|
|
@@ -31,19 +28,22 @@ export class AccountNumbers extends APIResource {
|
|
|
31
28
|
accountNumberId: string,
|
|
32
29
|
body: AccountNumberUpdateParams,
|
|
33
30
|
options?: Core.RequestOptions,
|
|
34
|
-
):
|
|
31
|
+
): Core.APIPromise<AccountNumber> {
|
|
35
32
|
return this.patch(`/account_numbers/${accountNumberId}`, { body, ...options });
|
|
36
33
|
}
|
|
37
34
|
|
|
38
35
|
/**
|
|
39
36
|
* List Account Numbers
|
|
40
37
|
*/
|
|
41
|
-
list(
|
|
42
|
-
|
|
38
|
+
list(
|
|
39
|
+
query?: AccountNumberListParams,
|
|
40
|
+
options?: Core.RequestOptions,
|
|
41
|
+
): Core.PagePromise<AccountNumbersPage, AccountNumber>;
|
|
42
|
+
list(options?: Core.RequestOptions): Core.PagePromise<AccountNumbersPage, AccountNumber>;
|
|
43
43
|
list(
|
|
44
44
|
query: AccountNumberListParams | Core.RequestOptions = {},
|
|
45
45
|
options?: Core.RequestOptions,
|
|
46
|
-
): Core.PagePromise<AccountNumbersPage> {
|
|
46
|
+
): Core.PagePromise<AccountNumbersPage, AccountNumber> {
|
|
47
47
|
if (isRequestOptions(query)) {
|
|
48
48
|
return this.list({}, query);
|
|
49
49
|
}
|