modern-treasury 2.2.0 → 2.3.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 +44 -0
- package/README.md +41 -15
- 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 +78 -29
- package/core.d.ts.map +1 -1
- package/core.js +185 -61
- package/core.js.map +1 -1
- package/core.mjs +179 -61
- package/core.mjs.map +1 -1
- package/index.d.mts +1 -2
- package/index.d.ts +1 -2
- package/index.d.ts.map +1 -1
- package/index.js +4 -4
- package/index.js.map +1 -1
- package/index.mjs +4 -4
- 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 +5 -5
- package/pagination.js.map +1 -1
- package/pagination.mjs +5 -5
- package/pagination.mjs.map +1 -1
- package/resources/account-collection-flows.d.ts +6 -6
- package/resources/account-collection-flows.d.ts.map +1 -1
- package/resources/account-details.d.ts +5 -5
- package/resources/account-details.d.ts.map +1 -1
- package/resources/connections.d.ts +5 -2
- package/resources/connections.d.ts.map +1 -1
- package/resources/connections.js.map +1 -1
- package/resources/connections.mjs.map +1 -1
- package/resources/counterparties.d.ts +11 -11
- package/resources/counterparties.d.ts.map +1 -1
- package/resources/counterparties.js.map +1 -1
- package/resources/counterparties.mjs.map +1 -1
- package/resources/documents.d.ts +4 -4
- package/resources/documents.d.ts.map +1 -1
- package/resources/documents.js +2 -2
- package/resources/documents.js.map +1 -1
- package/resources/documents.mjs +2 -2
- package/resources/documents.mjs.map +1 -1
- package/resources/events.d.ts +3 -3
- package/resources/events.d.ts.map +1 -1
- package/resources/expected-payments.d.ts +7 -7
- package/resources/expected-payments.d.ts.map +1 -1
- package/resources/external-accounts.d.ts +10 -10
- package/resources/external-accounts.d.ts.map +1 -1
- package/resources/incoming-payment-details.d.ts +11 -7
- package/resources/incoming-payment-details.d.ts.map +1 -1
- package/resources/incoming-payment-details.js.map +1 -1
- package/resources/incoming-payment-details.mjs.map +1 -1
- package/resources/index.d.ts +0 -1
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs.map +1 -1
- package/resources/internal-accounts/balance-reports.d.ts +6 -3
- package/resources/internal-accounts/balance-reports.d.ts.map +1 -1
- package/resources/internal-accounts/balance-reports.js.map +1 -1
- package/resources/internal-accounts/balance-reports.mjs.map +1 -1
- package/resources/internal-accounts/internal-accounts.d.ts +6 -6
- package/resources/internal-accounts/internal-accounts.d.ts.map +1 -1
- package/resources/invoices/invoices.d.ts +46 -13
- package/resources/invoices/invoices.d.ts.map +1 -1
- package/resources/invoices/invoices.js.map +1 -1
- package/resources/invoices/invoices.mjs.map +1 -1
- package/resources/invoices/line-items.d.ts +23 -171
- package/resources/invoices/line-items.d.ts.map +1 -1
- package/resources/invoices/line-items.js.map +1 -1
- package/resources/invoices/line-items.mjs.map +1 -1
- package/resources/ledger-account-categories.d.ts +39 -74
- package/resources/ledger-account-categories.d.ts.map +1 -1
- package/resources/ledger-account-categories.js +11 -13
- package/resources/ledger-account-categories.js.map +1 -1
- package/resources/ledger-account-categories.mjs +11 -13
- package/resources/ledger-account-categories.mjs.map +1 -1
- package/resources/ledger-account-payouts.d.ts +22 -6
- package/resources/ledger-account-payouts.d.ts.map +1 -1
- package/resources/ledger-account-payouts.js.map +1 -1
- package/resources/ledger-account-payouts.mjs.map +1 -1
- package/resources/ledger-account-statements.d.ts +2 -2
- package/resources/ledger-account-statements.d.ts.map +1 -1
- package/resources/ledger-accounts.d.ts +17 -12
- package/resources/ledger-accounts.d.ts.map +1 -1
- package/resources/ledger-accounts.js.map +1 -1
- package/resources/ledger-accounts.mjs.map +1 -1
- package/resources/ledger-entries.d.ts +20 -6
- package/resources/ledger-entries.d.ts.map +1 -1
- package/resources/ledger-entries.js.map +1 -1
- package/resources/ledger-entries.mjs.map +1 -1
- package/resources/ledger-event-handlers.d.ts +7 -8
- package/resources/ledger-event-handlers.d.ts.map +1 -1
- package/resources/ledger-event-handlers.js.map +1 -1
- package/resources/ledger-event-handlers.mjs.map +1 -1
- package/resources/ledger-transactions/ledger-transactions.d.ts +35 -18
- package/resources/ledger-transactions/ledger-transactions.d.ts.map +1 -1
- package/resources/ledger-transactions/ledger-transactions.js +3 -3
- package/resources/ledger-transactions/ledger-transactions.js.map +1 -1
- package/resources/ledger-transactions/ledger-transactions.mjs +3 -3
- package/resources/ledger-transactions/ledger-transactions.mjs.map +1 -1
- package/resources/ledger-transactions/versions.d.ts +4 -2
- package/resources/ledger-transactions/versions.d.ts.map +1 -1
- package/resources/ledger-transactions/versions.js.map +1 -1
- package/resources/ledger-transactions/versions.mjs.map +1 -1
- package/resources/ledgerable-events.d.ts +2 -2
- package/resources/ledgerable-events.d.ts.map +1 -1
- package/resources/ledgers.d.ts +12 -11
- package/resources/ledgers.d.ts.map +1 -1
- package/resources/ledgers.js.map +1 -1
- package/resources/ledgers.mjs.map +1 -1
- package/resources/line-items.d.ts +5 -5
- package/resources/line-items.d.ts.map +1 -1
- package/resources/paper-items.d.ts +6 -3
- package/resources/paper-items.d.ts.map +1 -1
- package/resources/paper-items.js.map +1 -1
- package/resources/paper-items.mjs.map +1 -1
- package/resources/payment-flows.d.ts +9 -9
- package/resources/payment-flows.d.ts.map +1 -1
- package/resources/payment-flows.js.map +1 -1
- package/resources/payment-flows.mjs.map +1 -1
- package/resources/payment-orders/payment-orders.d.ts +30 -24
- package/resources/payment-orders/payment-orders.d.ts.map +1 -1
- package/resources/payment-orders/payment-orders.js +3 -5
- package/resources/payment-orders/payment-orders.js.map +1 -1
- package/resources/payment-orders/payment-orders.mjs +3 -5
- package/resources/payment-orders/payment-orders.mjs.map +1 -1
- package/resources/payment-orders/reversals.d.ts +14 -9
- package/resources/payment-orders/reversals.d.ts.map +1 -1
- package/resources/payment-orders/reversals.js.map +1 -1
- package/resources/payment-orders/reversals.mjs.map +1 -1
- package/resources/payment-references.d.ts +3 -3
- package/resources/payment-references.d.ts.map +1 -1
- package/resources/returns.d.ts +7 -4
- package/resources/returns.d.ts.map +1 -1
- package/resources/returns.js.map +1 -1
- package/resources/returns.mjs.map +1 -1
- package/resources/routing-details.d.ts +5 -5
- package/resources/routing-details.d.ts.map +1 -1
- package/resources/transactions/line-items.d.ts +5 -2
- package/resources/transactions/line-items.d.ts.map +1 -1
- package/resources/transactions/line-items.js.map +1 -1
- package/resources/transactions/line-items.mjs.map +1 -1
- package/resources/transactions/transactions.d.ts +8 -5
- package/resources/transactions/transactions.d.ts.map +1 -1
- package/resources/transactions/transactions.js.map +1 -1
- package/resources/transactions/transactions.mjs.map +1 -1
- package/resources/validations.d.ts +1 -1
- package/resources/validations.d.ts.map +1 -1
- package/resources/virtual-accounts.d.ts +7 -10
- package/resources/virtual-accounts.d.ts.map +1 -1
- package/resources/virtual-accounts.js.map +1 -1
- package/resources/virtual-accounts.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.node.d.ts +11 -1
- package/src/core.ts +244 -79
- package/src/index.ts +4 -5
- package/src/pagination.ts +6 -6
- package/src/resources/account-collection-flows.ts +8 -8
- package/src/resources/account-details.ts +6 -6
- package/src/resources/connections.ts +6 -3
- package/src/resources/counterparties.ts +13 -13
- package/src/resources/documents.ts +6 -9
- package/src/resources/events.ts +4 -4
- package/src/resources/expected-payments.ts +9 -9
- package/src/resources/external-accounts.ts +13 -13
- package/src/resources/incoming-payment-details.ts +15 -10
- package/src/resources/index.ts +0 -1
- package/src/resources/internal-accounts/balance-reports.ts +7 -4
- package/src/resources/internal-accounts/internal-accounts.ts +8 -8
- package/src/resources/invoices/invoices.ts +55 -15
- package/src/resources/invoices/line-items.ts +25 -207
- package/src/resources/ledger-account-categories.ts +47 -91
- package/src/resources/ledger-account-payouts.ts +27 -8
- package/src/resources/ledger-account-statements.ts +2 -2
- package/src/resources/ledger-accounts.ts +21 -15
- package/src/resources/ledger-entries.ts +24 -8
- package/src/resources/ledger-event-handlers.ts +8 -12
- package/src/resources/ledger-transactions/ledger-transactions.ts +46 -25
- package/src/resources/ledger-transactions/versions.ts +5 -3
- package/src/resources/ledgerable-events.ts +2 -2
- package/src/resources/ledgers.ts +15 -13
- package/src/resources/line-items.ts +7 -7
- package/src/resources/paper-items.ts +7 -4
- package/src/resources/payment-flows.ts +11 -11
- package/src/resources/payment-orders/payment-orders.ts +39 -36
- package/src/resources/payment-orders/reversals.ts +17 -11
- package/src/resources/payment-references.ts +4 -4
- package/src/resources/returns.ts +8 -5
- package/src/resources/routing-details.ts +6 -6
- package/src/resources/transactions/line-items.ts +6 -3
- package/src/resources/transactions/transactions.ts +10 -7
- package/src/resources/validations.ts +1 -1
- package/src/resources/virtual-accounts.ts +9 -12
- package/src/version.ts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
|
@@ -8,14 +8,11 @@ export declare class VirtualAccounts extends APIResource {
|
|
|
8
8
|
/**
|
|
9
9
|
* create virtual_account
|
|
10
10
|
*/
|
|
11
|
-
create(
|
|
12
|
-
params: VirtualAccountCreateParams,
|
|
13
|
-
options?: Core.RequestOptions,
|
|
14
|
-
): Promise<Core.APIResponse<VirtualAccount>>;
|
|
11
|
+
create(params: VirtualAccountCreateParams, options?: Core.RequestOptions): Core.APIPromise<VirtualAccount>;
|
|
15
12
|
/**
|
|
16
13
|
* get virtual_account
|
|
17
14
|
*/
|
|
18
|
-
retrieve(id: string, options?: Core.RequestOptions):
|
|
15
|
+
retrieve(id: string, options?: Core.RequestOptions): Core.APIPromise<VirtualAccount>;
|
|
19
16
|
/**
|
|
20
17
|
* update virtual_account
|
|
21
18
|
*/
|
|
@@ -23,20 +20,20 @@ export declare class VirtualAccounts extends APIResource {
|
|
|
23
20
|
id: string,
|
|
24
21
|
body?: VirtualAccountUpdateParams,
|
|
25
22
|
options?: Core.RequestOptions,
|
|
26
|
-
):
|
|
27
|
-
update(id: string, options?: Core.RequestOptions):
|
|
23
|
+
): Core.APIPromise<VirtualAccount>;
|
|
24
|
+
update(id: string, options?: Core.RequestOptions): Core.APIPromise<VirtualAccount>;
|
|
28
25
|
/**
|
|
29
26
|
* Get a list of virtual accounts.
|
|
30
27
|
*/
|
|
31
28
|
list(
|
|
32
29
|
query?: VirtualAccountListParams,
|
|
33
30
|
options?: Core.RequestOptions,
|
|
34
|
-
): Core.PagePromise<VirtualAccountsPage>;
|
|
35
|
-
list(options?: Core.RequestOptions): Core.PagePromise<VirtualAccountsPage>;
|
|
31
|
+
): Core.PagePromise<VirtualAccountsPage, VirtualAccount>;
|
|
32
|
+
list(options?: Core.RequestOptions): Core.PagePromise<VirtualAccountsPage, VirtualAccount>;
|
|
36
33
|
/**
|
|
37
34
|
* delete virtual_account
|
|
38
35
|
*/
|
|
39
|
-
del(id: string, options?: Core.RequestOptions):
|
|
36
|
+
del(id: string, options?: Core.RequestOptions): Core.APIPromise<VirtualAccount>;
|
|
40
37
|
}
|
|
41
38
|
export declare class VirtualAccountsPage extends Page<VirtualAccount> {}
|
|
42
39
|
type _VirtualAccountsPage = VirtualAccountsPage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-accounts.d.ts","sourceRoot":"","sources":["../src/resources/virtual-accounts.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,IAAI,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,W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GACd,KAAK,GACL,SAAS,GACT,OAAO,GACP,MAAM,GACN,aAAa,GACb,KAAK,GACL,KAAK,GACL,MAAM,GACN,QAAQ,GACR,MAAM,GACN,IAAI,CAAC;KACV;CACF;AAED,MAAM,WAAW,0BAA0B;IACzC,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAElC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,MAAM,WAAW,wBAAyB,SAAQ,UAAU;IAC1D,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED,yBAAiB,eAAe,CAAC;IAC/B,MAAM,QAAQ,cAAc,GAAG,GAAG,CAAC,cAAc,CAAC;IAClD,KAAY,mBAAmB,GAAG,oBAAoB,CAAC;IACvD,MAAM,QAAQ,0BAA0B,GAAG,GAAG,CAAC,0BAA0B,CAAC;IAC1E,MAAM,QAAQ,0BAA0B,GAAG,GAAG,CAAC,0BAA0B,CAAC;IAC1E,MAAM,QAAQ,wBAAwB,GAAG,GAAG,CAAC,wBAAwB,CAAC;CACvE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-accounts.js","sourceRoot":"","sources":["../src/resources/virtual-accounts.ts"],"names":[],"mappings":";AAAA,qDAAqD;;;AAGrD,uDAAuD;AACvD,+CAAwD;AAIxD,2DAA8D;AAE9D,MAAa,eAAgB,SAAQ,sBAAW;IAC9C;;OAEG;IACH,MAAM,
|
|
1
|
+
{"version":3,"file":"virtual-accounts.js","sourceRoot":"","sources":["../src/resources/virtual-accounts.ts"],"names":[],"mappings":";AAAA,qDAAqD;;;AAGrD,uDAAuD;AACvD,+CAAwD;AAIxD,2DAA8D;AAE9D,MAAa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EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;IAC7D,CAAC;CACF;AAhED,0CAgEC;AAED,MAAa,mBAAoB,SAAQ,iBAAoB;CAAG;AAAhE,kDAAgE;AAsNhE,WAAiB,eAAe;AAMhC,CAAC,EANgB,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAM/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-accounts.mjs","sourceRoot":"","sources":["../src/resources/virtual-accounts.ts"],"names":[],"mappings":"AAAA,qDAAqD;OAG9C,EAAE,WAAW,EAAE,MAAM,0BAA0B;OAC/C,EAAE,gBAAgB,EAAE,MAAM,sBAAsB;OAIhD,EAAE,IAAI,EAAc,MAAM,4BAA4B;AAE7D,MAAM,OAAO,eAAgB,SAAQ,WAAW;IAC9C;;OAEG;IACH,MAAM,
|
|
1
|
+
{"version":3,"file":"virtual-accounts.mjs","sourceRoot":"","sources":["../src/resources/virtual-accounts.ts"],"names":[],"mappings":"AAAA,qDAAqD;OAG9C,EAAE,WAAW,EAAE,MAAM,0BAA0B;OAC/C,EAAE,gBAAgB,EAAE,MAAM,sBAAsB;OAIhD,EAAE,IAAI,EAAc,MAAM,4BAA4B;AAE7D,MAAM,OAAO,eAAgB,SAAQ,WAAW;IAC9C;;OAEG;IACH,MAAM,CAAC,MAAkC,EAAE,OAA6B;QACtE,MAAM,EAAE,iBAAiB,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;QAC9D,OAAO,IAAI,CAAC,IAAI,CAAC,uBAAuB,EAAE;YACxC,IAAI;YACJ,GAAG,OAAO;YACV,OAAO,EAAE,EAAE,iBAAiB,EAAE,cAAc,IAAI,EAAE,EAAE,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,EAAE;SAC1E,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,EAAU,EAAE,OAA6B;QAChD,OAAO,IAAI,CAAC,GAAG,CAAC,yBAAyB,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IAWD,MAAM,CACJ,EAAU,EACV,OAAyD,EAAE,EAC3D,OAA6B;QAE7B,IAAI,gBAAgB,CAAC,IAAI,CAAC,EAAE;YAC1B,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;SAClC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,yBAAyB,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IACzE,CAAC;IAUD,IAAI,CACF,QAAwD,EAAE,EAC1D,OAA6B;QAE7B,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE;YAC3B,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;SAC7B;QACD,OAAO,IAAI,CAAC,UAAU,CAAC,uBAAuB,EAAE,mBAAmB,EAAE,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAC9F,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,EAAU,EAAE,OAA6B;QAC3C,OAAO,IAAI,CAAC,MAAM,CAAC,yBAAyB,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;IAC7D,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,IAAoB;CAAG;AAsNhE,WAAiB,eAAe;AAMhC,CAAC,EANgB,eAAe,KAAf,eAAe,QAM/B"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* >>> Confused? <<<
|
|
7
|
+
*
|
|
8
|
+
* If you're getting errors from these types, try adding "lib": ["DOM"]
|
|
9
|
+
* to your tsconfig.json, or otherwise configure the appropriate builtin
|
|
10
|
+
* `ReadableStream` type for your environment.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
type _ReadableStream<R = any> = unknown extends ReadableStream ? never : ReadableStream<R>;
|
|
15
|
+
declare const _ReadableStream: {
|
|
16
|
+
prototype: _ReadableStream;
|
|
17
|
+
new (
|
|
18
|
+
underlyingSource: _UnderlyingByteSource,
|
|
19
|
+
strategy?: { highWaterMark?: number },
|
|
20
|
+
): _ReadableStream<Uint8Array>;
|
|
21
|
+
new <R = any>(
|
|
22
|
+
underlyingSource: _UnderlyingDefaultSource<R>,
|
|
23
|
+
strategy?: _QueuingStrategy<R>,
|
|
24
|
+
): _ReadableStream<R>;
|
|
25
|
+
new <R = any>(underlyingSource?: _UnderlyingSource<R>, strategy?: _QueuingStrategy<R>): _ReadableStream<R>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
type _UnderlyingSource<R = any> = unknown extends UnderlyingSource ? never : UnderlyingSource<R>;
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
type _UnderlyingByteSource = unknown extends UnderlyingByteSource ? never : UnderlyingByteSource;
|
|
32
|
+
type _UnderlyingDefaultSource<R = any> =
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
unknown extends UnderlyingDefaultSource ? never : UnderlyingDefaultSource<R>;
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
type _QueuingStrategy<R = any> = unknown extends QueuingStrategy ? never : QueuingStrategy<R>;
|
|
37
|
+
|
|
38
|
+
export { _ReadableStream as ReadableStream };
|
package/src/_shims/fetch.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ type _Response = unknown extends Response ? never : Response;
|
|
|
26
26
|
// @ts-ignore
|
|
27
27
|
type _ResponseInit = unknown extends ResponseInit ? never : ResponseInit;
|
|
28
28
|
// @ts-ignore
|
|
29
|
+
type _ResponseType = unknown extends ResponseType ? never : ResponseType;
|
|
30
|
+
// @ts-ignore
|
|
29
31
|
type _BodyInit = unknown extends BodyInit ? never : BodyInit;
|
|
30
32
|
// @ts-ignore
|
|
31
33
|
type _Headers = unknown extends Headers ? never : Headers;
|
|
@@ -49,4 +51,9 @@ declare const _Headers: {
|
|
|
49
51
|
export const isPolyfilled = false;
|
|
50
52
|
|
|
51
53
|
export { _fetch as fetch, _Request as Request, _Response as Response, _Headers as Headers };
|
|
52
|
-
export type {
|
|
54
|
+
export type {
|
|
55
|
+
_RequestInit as RequestInit,
|
|
56
|
+
_RequestInfo as RequestInfo,
|
|
57
|
+
_ResponseType as ResponseType,
|
|
58
|
+
_BodyInit as BodyInit,
|
|
59
|
+
};
|
|
@@ -26,6 +26,11 @@ type _RequestInit = unknown extends RequestInit ? nf.RequestInit : RequestInit;
|
|
|
26
26
|
type _Response = unknown extends Response ? nf.Response : Response;
|
|
27
27
|
// @ts-ignore
|
|
28
28
|
type _ResponseInit = unknown extends ResponseInit ? nf.ResponseInit : ResponseInit;
|
|
29
|
+
type _ResponseType =
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
unknown extends ResponseType ? 'basic' | 'cors' | 'default' | 'error' | 'opaque' | 'opaqueredirect'
|
|
32
|
+
: // @ts-ignore
|
|
33
|
+
ResponseType;
|
|
29
34
|
// @ts-ignore
|
|
30
35
|
type _BodyInit = unknown extends BodyInit ? nf.BodyInit : BodyInit;
|
|
31
36
|
// @ts-ignore
|
|
@@ -50,4 +55,9 @@ declare const _Headers: {
|
|
|
50
55
|
export const isPolyfilled = false;
|
|
51
56
|
|
|
52
57
|
export { _fetch as fetch, _Request as Request, _Response as Response, _Headers as Headers };
|
|
53
|
-
export type {
|
|
58
|
+
export type {
|
|
59
|
+
_RequestInit as RequestInit,
|
|
60
|
+
_RequestInfo as RequestInfo,
|
|
61
|
+
_ResponseType as ResponseType,
|
|
62
|
+
_BodyInit as BodyInit,
|
|
63
|
+
};
|
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;
|
|
@@ -33,7 +128,7 @@ export abstract class APIClient {
|
|
|
33
128
|
constructor({
|
|
34
129
|
baseURL,
|
|
35
130
|
maxRetries,
|
|
36
|
-
timeout =
|
|
131
|
+
timeout = 60000, // 1 minute
|
|
37
132
|
httpAgent,
|
|
38
133
|
fetch: overridenFetch,
|
|
39
134
|
}: {
|
|
@@ -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);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
delete<Req extends {}, Rsp>(path: string, opts?: PromiseOrValue<RequestOptions<Req>>): APIPromise<Rsp> {
|
|
199
|
+
return this.methodRequest('delete', path, opts);
|
|
98
200
|
}
|
|
99
|
-
|
|
100
|
-
|
|
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
|
|
|
@@ -140,7 +247,10 @@ export abstract class APIClient {
|
|
|
140
247
|
const timeout = options.timeout ?? this.timeout;
|
|
141
248
|
const httpAgent = options.httpAgent ?? this.httpAgent ?? getDefaultAgent(url);
|
|
142
249
|
const minAgentTimeout = timeout + 1000;
|
|
143
|
-
if (
|
|
250
|
+
if (
|
|
251
|
+
typeof (httpAgent as any)?.options?.timeout === 'number' &&
|
|
252
|
+
minAgentTimeout > ((httpAgent as any).options.timeout ?? 0)
|
|
253
|
+
) {
|
|
144
254
|
// Allow any given request to bump our agent active socket timeout.
|
|
145
255
|
// This may seem strange, but leaking active sockets should be rare and not particularly problematic,
|
|
146
256
|
// and without mutating agent we would need to create more of them.
|
|
@@ -198,14 +308,27 @@ export abstract class APIClient {
|
|
|
198
308
|
return APIError.generate(status, error, message, headers);
|
|
199
309
|
}
|
|
200
310
|
|
|
201
|
-
|
|
202
|
-
options: FinalRequestOptions<Req
|
|
203
|
-
|
|
204
|
-
):
|
|
311
|
+
request<Req extends {}, Rsp>(
|
|
312
|
+
options: PromiseOrValue<FinalRequestOptions<Req>>,
|
|
313
|
+
remainingRetries: number | null = null,
|
|
314
|
+
): APIPromise<Rsp> {
|
|
315
|
+
return new APIPromise(this.makeRequest(options, remainingRetries));
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
private async makeRequest<T>(
|
|
319
|
+
optionsInput: PromiseOrValue<FinalRequestOptions>,
|
|
320
|
+
retriesRemaining: number | null,
|
|
321
|
+
): Promise<{ response: Response; options: FinalRequestOptions; controller: AbortController }> {
|
|
322
|
+
const options = await optionsInput;
|
|
323
|
+
if (retriesRemaining == null) {
|
|
324
|
+
retriesRemaining = options.maxRetries ?? this.maxRetries;
|
|
325
|
+
}
|
|
326
|
+
|
|
205
327
|
const { req, url, timeout } = this.buildRequest(options);
|
|
328
|
+
|
|
206
329
|
await this.prepareRequest(req, { url });
|
|
207
330
|
|
|
208
|
-
|
|
331
|
+
debug('request', url, options, req.headers);
|
|
209
332
|
|
|
210
333
|
if (options.signal?.aborted) {
|
|
211
334
|
throw new APIUserAbortError();
|
|
@@ -238,42 +361,21 @@ export abstract class APIClient {
|
|
|
238
361
|
const errJSON = safeJSON(errText);
|
|
239
362
|
const errMessage = errJSON ? undefined : errText;
|
|
240
363
|
|
|
241
|
-
|
|
364
|
+
debug('response', response.status, url, responseHeaders, errMessage);
|
|
242
365
|
|
|
243
366
|
const err = this.makeStatusError(response.status, errJSON, errMessage, responseHeaders);
|
|
244
367
|
throw err;
|
|
245
368
|
}
|
|
246
369
|
|
|
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>;
|
|
370
|
+
return { response, options, controller };
|
|
269
371
|
}
|
|
270
372
|
|
|
271
373
|
requestAPIList<Item = unknown, PageClass extends AbstractPage<Item> = AbstractPage<Item>>(
|
|
272
374
|
Page: new (...args: ConstructorParameters<typeof AbstractPage>) => PageClass,
|
|
273
375
|
options: FinalRequestOptions,
|
|
274
|
-
): PagePromise<PageClass> {
|
|
275
|
-
const
|
|
276
|
-
return new PagePromise(this,
|
|
376
|
+
): PagePromise<PageClass, Item> {
|
|
377
|
+
const request = this.makeRequest(options, null);
|
|
378
|
+
return new PagePromise<PageClass, Item>(this, request, Page);
|
|
277
379
|
}
|
|
278
380
|
|
|
279
381
|
buildURL<Req>(path: string, query: Req | undefined): string {
|
|
@@ -401,12 +503,6 @@ export abstract class APIClient {
|
|
|
401
503
|
private getUserAgent(): string {
|
|
402
504
|
return `${this.constructor.name}/JS ${VERSION}`;
|
|
403
505
|
}
|
|
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
506
|
}
|
|
411
507
|
|
|
412
508
|
export class APIResource {
|
|
@@ -436,9 +532,14 @@ export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
|
|
|
436
532
|
#client: APIClient;
|
|
437
533
|
protected options: FinalRequestOptions;
|
|
438
534
|
|
|
439
|
-
|
|
535
|
+
protected response: Response;
|
|
536
|
+
protected body: unknown;
|
|
537
|
+
|
|
538
|
+
constructor(client: APIClient, response: Response, body: unknown, options: FinalRequestOptions) {
|
|
440
539
|
this.#client = client;
|
|
441
540
|
this.options = options;
|
|
541
|
+
this.response = response;
|
|
542
|
+
this.body = body;
|
|
442
543
|
}
|
|
443
544
|
|
|
444
545
|
/**
|
|
@@ -495,35 +596,33 @@ export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
|
|
|
495
596
|
}
|
|
496
597
|
}
|
|
497
598
|
|
|
599
|
+
/**
|
|
600
|
+
* This subclass of Promise will resolve to an instantiated Page once the request completes.
|
|
601
|
+
*
|
|
602
|
+
* It also implements AsyncIterable to allow auto-paginating iteration on an unawaited list call, eg:
|
|
603
|
+
*
|
|
604
|
+
* for await (const item of client.items.list()) {
|
|
605
|
+
* console.log(item)
|
|
606
|
+
* }
|
|
607
|
+
*/
|
|
498
608
|
export class PagePromise<
|
|
499
609
|
PageClass extends AbstractPage<Item>,
|
|
500
610
|
Item = ReturnType<PageClass['getPaginatedItems']>[number],
|
|
501
611
|
>
|
|
502
|
-
extends
|
|
612
|
+
extends APIPromise<PageClass>
|
|
503
613
|
implements AsyncIterable<Item>
|
|
504
614
|
{
|
|
505
|
-
/**
|
|
506
|
-
* This subclass of Promise will resolve to an instantiated Page once the request completes.
|
|
507
|
-
*/
|
|
508
615
|
constructor(
|
|
509
616
|
client: APIClient,
|
|
510
|
-
|
|
511
|
-
options: FinalRequestOptions,
|
|
617
|
+
request: Promise<APIResponseProps>,
|
|
512
618
|
Page: new (...args: ConstructorParameters<typeof AbstractPage>) => PageClass,
|
|
513
619
|
) {
|
|
514
|
-
super(
|
|
515
|
-
|
|
620
|
+
super(
|
|
621
|
+
request,
|
|
622
|
+
async (props) => new Page(client, props.response, await defaultParseResponse(props), props.options),
|
|
516
623
|
);
|
|
517
624
|
}
|
|
518
625
|
|
|
519
|
-
/**
|
|
520
|
-
* Enable subclassing Promise.
|
|
521
|
-
* Ref: https://stackoverflow.com/a/60328122
|
|
522
|
-
*/
|
|
523
|
-
static get [Symbol.species]() {
|
|
524
|
-
return Promise;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
626
|
/**
|
|
528
627
|
* Allow auto-paginating iteration on an unawaited list call, eg:
|
|
529
628
|
*
|
|
@@ -610,11 +709,6 @@ export type FinalRequestOptions<Req extends {} = Record<string, unknown> | Reada
|
|
|
610
709
|
path: string;
|
|
611
710
|
};
|
|
612
711
|
|
|
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
712
|
declare const Deno: any;
|
|
619
713
|
declare const EdgeRuntime: any;
|
|
620
714
|
type Arch = 'x32' | 'x64' | 'arm' | 'arm64' | `other:${string}` | 'unknown';
|
|
@@ -628,12 +722,13 @@ type PlatformName =
|
|
|
628
722
|
| 'Android'
|
|
629
723
|
| `Other:${string}`
|
|
630
724
|
| 'Unknown';
|
|
725
|
+
type Browser = 'ie' | 'edge' | 'chrome' | 'firefox' | 'safari';
|
|
631
726
|
type PlatformProperties = {
|
|
632
727
|
'X-Stainless-Lang': 'js';
|
|
633
728
|
'X-Stainless-Package-Version': string;
|
|
634
729
|
'X-Stainless-OS': PlatformName;
|
|
635
730
|
'X-Stainless-Arch': Arch;
|
|
636
|
-
'X-Stainless-Runtime': 'node' | 'deno' | 'edge' | 'unknown';
|
|
731
|
+
'X-Stainless-Runtime': 'node' | 'deno' | 'edge' | `browser:${Browser}` | 'unknown';
|
|
637
732
|
'X-Stainless-Runtime-Version': string;
|
|
638
733
|
};
|
|
639
734
|
const getPlatformProperties = (): PlatformProperties => {
|
|
@@ -668,7 +763,20 @@ const getPlatformProperties = (): PlatformProperties => {
|
|
|
668
763
|
'X-Stainless-Runtime-Version': process.version,
|
|
669
764
|
};
|
|
670
765
|
}
|
|
671
|
-
|
|
766
|
+
|
|
767
|
+
const browserInfo = getBrowserInfo();
|
|
768
|
+
if (browserInfo) {
|
|
769
|
+
return {
|
|
770
|
+
'X-Stainless-Lang': 'js',
|
|
771
|
+
'X-Stainless-Package-Version': VERSION,
|
|
772
|
+
'X-Stainless-OS': 'Unknown',
|
|
773
|
+
'X-Stainless-Arch': 'unknown',
|
|
774
|
+
'X-Stainless-Runtime': `browser:${browserInfo.browser}`,
|
|
775
|
+
'X-Stainless-Runtime-Version': browserInfo.version,
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
// TODO add support for Cloudflare workers, etc.
|
|
672
780
|
return {
|
|
673
781
|
'X-Stainless-Lang': 'js',
|
|
674
782
|
'X-Stainless-Package-Version': VERSION,
|
|
@@ -679,6 +787,44 @@ const getPlatformProperties = (): PlatformProperties => {
|
|
|
679
787
|
};
|
|
680
788
|
};
|
|
681
789
|
|
|
790
|
+
type BrowserInfo = {
|
|
791
|
+
browser: Browser;
|
|
792
|
+
version: string;
|
|
793
|
+
};
|
|
794
|
+
|
|
795
|
+
declare const navigator: { userAgent: string } | undefined;
|
|
796
|
+
|
|
797
|
+
// Note: modified from https://github.com/JS-DevTools/host-environment/blob/b1ab79ecde37db5d6e163c050e54fe7d287d7c92/src/isomorphic.browser.ts
|
|
798
|
+
function getBrowserInfo(): BrowserInfo | null {
|
|
799
|
+
if (!navigator || typeof navigator === 'undefined') {
|
|
800
|
+
return null;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
// NOTE: The order matters here!
|
|
804
|
+
const browserPatterns = [
|
|
805
|
+
{ key: 'edge' as const, pattern: /Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
806
|
+
{ key: 'ie' as const, pattern: /MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
807
|
+
{ key: 'ie' as const, pattern: /Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
808
|
+
{ key: 'chrome' as const, pattern: /Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
809
|
+
{ key: 'firefox' as const, pattern: /Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
810
|
+
{ key: 'safari' as const, pattern: /(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/ },
|
|
811
|
+
];
|
|
812
|
+
|
|
813
|
+
// Find the FIRST matching browser
|
|
814
|
+
for (const { key, pattern } of browserPatterns) {
|
|
815
|
+
const match = pattern.exec(navigator.userAgent);
|
|
816
|
+
if (match) {
|
|
817
|
+
const major = match[1] || 0;
|
|
818
|
+
const minor = match[2] || 0;
|
|
819
|
+
const patch = match[3] || 0;
|
|
820
|
+
|
|
821
|
+
return { browser: key, version: `${major}.${minor}.${patch}` };
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
return null;
|
|
826
|
+
}
|
|
827
|
+
|
|
682
828
|
const normalizeArch = (arch: string): Arch => {
|
|
683
829
|
// Node docs:
|
|
684
830
|
// - https://nodejs.org/api/process.html#processarch
|
|
@@ -760,14 +906,16 @@ export const ensurePresent = <T>(value: T | null | undefined): T => {
|
|
|
760
906
|
/**
|
|
761
907
|
* Read an environment variable.
|
|
762
908
|
*
|
|
763
|
-
* Will return
|
|
909
|
+
* Will return undefined if the environment variable doesn't exist or cannot be accessed.
|
|
764
910
|
*/
|
|
765
911
|
export const readEnv = (env: string): string | undefined => {
|
|
766
|
-
if (typeof process
|
|
767
|
-
return undefined;
|
|
912
|
+
if (typeof process !== 'undefined') {
|
|
913
|
+
return process.env?.[env] ?? undefined;
|
|
768
914
|
}
|
|
769
|
-
|
|
770
|
-
|
|
915
|
+
if (typeof Deno !== 'undefined') {
|
|
916
|
+
return Deno.env?.get?.(env);
|
|
917
|
+
}
|
|
918
|
+
return undefined;
|
|
771
919
|
};
|
|
772
920
|
|
|
773
921
|
export const coerceInteger = (value: unknown): number => {
|
|
@@ -823,6 +971,12 @@ export function hasOwn(obj: Object, key: string): boolean {
|
|
|
823
971
|
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
824
972
|
}
|
|
825
973
|
|
|
974
|
+
export function debug(action: string, ...args: any[]) {
|
|
975
|
+
if (typeof process !== 'undefined' && process.env['DEBUG'] === 'true') {
|
|
976
|
+
console.log(`ModernTreasury:DEBUG:${action}`, ...args);
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
|
|
826
980
|
/**
|
|
827
981
|
* https://stackoverflow.com/a/2117523
|
|
828
982
|
*/
|
|
@@ -834,6 +988,17 @@ const uuid4 = () => {
|
|
|
834
988
|
});
|
|
835
989
|
};
|
|
836
990
|
|
|
991
|
+
export const isRunningInBrowser = () => {
|
|
992
|
+
return (
|
|
993
|
+
// @ts-ignore
|
|
994
|
+
typeof window !== 'undefined' &&
|
|
995
|
+
// @ts-ignore
|
|
996
|
+
typeof window.document !== 'undefined' &&
|
|
997
|
+
// @ts-ignore
|
|
998
|
+
typeof navigator !== 'undefined'
|
|
999
|
+
);
|
|
1000
|
+
};
|
|
1001
|
+
|
|
837
1002
|
export interface HeadersProtocol {
|
|
838
1003
|
get: (header: string) => string | null | undefined;
|
|
839
1004
|
}
|