@tryfinch/finch-api 5.1.0 → 5.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 +43 -0
- package/README.md +28 -21
- package/_shims/MultipartBody.d.ts +9 -0
- package/_shims/MultipartBody.d.ts.map +1 -0
- package/_shims/MultipartBody.js +16 -0
- package/_shims/MultipartBody.js.map +1 -0
- package/_shims/MultipartBody.mjs +12 -0
- package/_shims/MultipartBody.mjs.map +1 -0
- package/_shims/README.md +46 -0
- package/{src/_shims/ReadableStream-node.ts → _shims/auto/runtime-bun.d.ts} +2 -3
- package/_shims/auto/runtime-bun.d.ts.map +1 -0
- package/_shims/auto/runtime-bun.js +21 -0
- package/_shims/auto/runtime-bun.js.map +1 -0
- package/_shims/auto/runtime-bun.mjs +2 -0
- package/_shims/auto/runtime-bun.mjs.map +1 -0
- package/_shims/auto/runtime-node.d.ts +5 -0
- package/_shims/auto/runtime-node.d.ts.map +1 -0
- package/_shims/auto/runtime-node.js +21 -0
- package/_shims/auto/runtime-node.js.map +1 -0
- package/_shims/auto/runtime-node.mjs +2 -0
- package/_shims/auto/runtime-node.mjs.map +1 -0
- package/_shims/auto/runtime.d.ts +5 -0
- package/_shims/auto/runtime.d.ts.map +1 -0
- package/_shims/auto/runtime.js +21 -0
- package/_shims/auto/runtime.js.map +1 -0
- package/_shims/auto/runtime.mjs +2 -0
- package/_shims/auto/runtime.mjs.map +1 -0
- package/_shims/auto/types-node.d.ts +5 -0
- package/_shims/auto/types-node.d.ts.map +1 -0
- package/_shims/auto/types-node.js +21 -0
- package/_shims/auto/types-node.js.map +1 -0
- package/_shims/auto/types-node.mjs +2 -0
- package/_shims/auto/types-node.mjs.map +1 -0
- package/_shims/auto/types.d.ts +99 -0
- package/_shims/{ReadableStream.js → auto/types.js} +0 -2
- package/{src/_shims/ReadableStream.js → _shims/auto/types.mjs} +0 -2
- package/_shims/bun-runtime.d.ts +6 -0
- package/_shims/bun-runtime.d.ts.map +1 -0
- package/_shims/bun-runtime.js +14 -0
- package/_shims/bun-runtime.js.map +1 -0
- package/_shims/bun-runtime.mjs +10 -0
- package/_shims/bun-runtime.mjs.map +1 -0
- package/_shims/index.d.ts +79 -0
- package/_shims/index.js +13 -0
- package/_shims/index.mjs +7 -0
- package/_shims/manual-types.d.ts +12 -0
- package/_shims/manual-types.js +3 -0
- package/_shims/manual-types.mjs +3 -0
- package/_shims/node-runtime.d.ts +3 -0
- package/_shims/node-runtime.d.ts.map +1 -0
- package/_shims/node-runtime.js +87 -0
- package/_shims/node-runtime.js.map +1 -0
- package/_shims/node-runtime.mjs +54 -0
- package/_shims/node-runtime.mjs.map +1 -0
- package/_shims/node-types.d.ts +42 -0
- package/_shims/node-types.js +3 -0
- package/_shims/node-types.mjs +3 -0
- package/_shims/registry.d.ts +35 -0
- package/_shims/registry.d.ts.map +1 -0
- package/_shims/registry.js +39 -0
- package/_shims/registry.js.map +1 -0
- package/_shims/registry.mjs +35 -0
- package/_shims/registry.mjs.map +1 -0
- package/_shims/web-runtime.d.ts +5 -0
- package/_shims/web-runtime.d.ts.map +1 -0
- package/_shims/web-runtime.js +70 -0
- package/_shims/web-runtime.js.map +1 -0
- package/_shims/web-runtime.mjs +63 -0
- package/_shims/web-runtime.mjs.map +1 -0
- package/_shims/web-types.d.ts +82 -0
- package/_shims/web-types.js +3 -0
- package/_shims/web-types.mjs +3 -0
- package/core.d.ts +170 -223
- package/core.d.ts.map +1 -1
- package/core.js +682 -729
- package/core.js.map +1 -1
- package/core.mjs +676 -680
- package/core.mjs.map +1 -1
- package/error.d.ts +32 -32
- package/error.d.ts.map +1 -1
- package/error.js +95 -106
- package/error.js.map +1 -1
- package/error.mjs +91 -91
- package/error.mjs.map +1 -1
- package/index.d.mts +145 -178
- package/index.d.ts +145 -178
- package/index.d.ts.map +1 -1
- package/index.js +145 -201
- package/index.js.map +1 -1
- package/index.mjs +123 -149
- package/index.mjs.map +1 -1
- package/package.json +31 -23
- package/pagination.d.ts +47 -167
- package/pagination.d.ts.map +1 -1
- package/pagination.js +72 -202
- package/pagination.js.map +1 -1
- package/pagination.mjs +68 -187
- package/pagination.mjs.map +1 -1
- package/resource.d.ts +10 -10
- package/resource.js +12 -12
- package/resource.mjs +10 -10
- package/resources/account.d.ts +44 -44
- package/resources/account.js +20 -19
- package/resources/account.mjs +17 -16
- package/resources/hris/benefits/benefits.d.ts +127 -154
- package/resources/hris/benefits/benefits.js +74 -89
- package/resources/hris/benefits/benefits.mjs +50 -48
- package/resources/hris/benefits/index.d.ts +3 -28
- package/resources/hris/benefits/index.js +13 -55
- package/resources/hris/benefits/index.mjs +3 -8
- package/resources/hris/benefits/individuals.d.ts +129 -147
- package/resources/hris/benefits/individuals.js +59 -59
- package/resources/hris/benefits/individuals.mjs +53 -49
- package/resources/hris/company.d.ts +80 -80
- package/resources/hris/company.js +12 -13
- package/resources/hris/company.mjs +9 -8
- package/resources/hris/directory.d.ts +53 -55
- package/resources/hris/directory.js +13 -12
- package/resources/hris/directory.mjs +8 -7
- package/resources/hris/employments.d.ts +124 -126
- package/resources/hris/employments.js +23 -21
- package/resources/hris/employments.mjs +19 -17
- package/resources/hris/hris.d.ts +113 -123
- package/resources/hris/hris.js +54 -71
- package/resources/hris/hris.mjs +32 -32
- package/resources/hris/index.d.ts +9 -41
- package/resources/hris/index.js +26 -110
- package/resources/hris/index.mjs +9 -9
- package/resources/hris/individuals.d.ts +65 -67
- package/resources/hris/individuals.js +19 -17
- package/resources/hris/individuals.mjs +14 -12
- package/resources/hris/pay-statements.d.ts +146 -162
- package/resources/hris/pay-statements.js +22 -20
- package/resources/hris/pay-statements.mjs +18 -16
- package/resources/hris/payments.d.ts +47 -49
- package/resources/hris/payments.js +15 -13
- package/resources/hris/payments.mjs +11 -9
- package/resources/index.d.ts +5 -7
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +13 -51
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +5 -6
- package/resources/index.mjs.map +1 -1
- package/resources/providers.d.ts +43 -42
- package/resources/providers.js +15 -13
- package/resources/providers.mjs +11 -9
- package/resources/top-level.d.ts +1 -1
- package/resources/top-level.js +3 -3
- package/resources/top-level.mjs +1 -1
- package/resources/webhooks.d.ts +18 -18
- package/resources/webhooks.js +103 -107
- package/resources/webhooks.mjs +98 -102
- package/shims/node.d.ts +29 -0
- package/shims/node.d.ts.map +1 -0
- package/shims/node.js +31 -0
- package/shims/node.js.map +1 -0
- package/shims/node.mjs +5 -0
- package/shims/node.mjs.map +1 -0
- package/shims/web.d.ts +26 -0
- package/shims/web.d.ts.map +1 -0
- package/shims/web.js +31 -0
- package/shims/web.js.map +1 -0
- package/shims/web.mjs +5 -0
- package/shims/web.mjs.map +1 -0
- package/src/_shims/MultipartBody.ts +9 -0
- package/src/_shims/README.md +46 -0
- package/src/_shims/auto/runtime-bun.ts +4 -0
- package/src/_shims/auto/runtime-node.ts +4 -0
- package/src/_shims/auto/runtime.ts +4 -0
- package/src/_shims/auto/types-node.ts +4 -0
- package/src/_shims/auto/types.d.ts +99 -0
- package/src/_shims/auto/types.js +3 -0
- package/src/_shims/auto/types.mjs +3 -0
- package/src/_shims/bun-runtime.ts +14 -0
- package/src/_shims/index.d.ts +79 -0
- package/src/_shims/index.js +13 -0
- package/src/_shims/index.mjs +7 -0
- package/src/_shims/manual-types.d.ts +12 -0
- package/src/_shims/manual-types.js +3 -0
- package/src/_shims/manual-types.mjs +3 -0
- package/src/_shims/node-runtime.ts +79 -0
- package/src/_shims/node-types.d.ts +42 -0
- package/src/_shims/node-types.js +3 -0
- package/src/_shims/node-types.mjs +3 -0
- package/src/_shims/registry.ts +64 -0
- package/src/_shims/web-runtime.ts +91 -0
- package/src/_shims/web-types.d.ts +82 -0
- package/src/_shims/web-types.js +3 -0
- package/src/_shims/web-types.mjs +3 -0
- package/src/core.ts +75 -44
- package/src/error.ts +6 -4
- package/src/index.ts +8 -25
- package/src/pagination.ts +2 -261
- package/src/resource.ts +1 -1
- package/src/resources/account.ts +3 -3
- package/src/resources/hris/benefits/benefits.ts +6 -6
- package/src/resources/hris/benefits/index.ts +2 -2
- package/src/resources/hris/benefits/individuals.ts +6 -6
- package/src/resources/hris/company.ts +4 -4
- package/src/resources/hris/directory.ts +5 -5
- package/src/resources/hris/employments.ts +5 -5
- package/src/resources/hris/hris.ts +9 -9
- package/src/resources/hris/index.ts +8 -8
- package/src/resources/hris/individuals.ts +6 -6
- package/src/resources/hris/pay-statements.ts +6 -6
- package/src/resources/hris/payments.ts +5 -5
- package/src/resources/index.ts +4 -6
- package/src/resources/providers.ts +4 -4
- package/src/resources/webhooks.ts +2 -2
- package/src/shims/node.ts +50 -0
- package/src/shims/web.ts +50 -0
- package/src/uploads.ts +12 -16
- package/src/version.ts +1 -1
- package/uploads.d.ts +23 -39
- package/uploads.d.ts.map +1 -1
- package/uploads.js +115 -157
- package/uploads.js.map +1 -1
- package/uploads.mjs +111 -133
- package/uploads.mjs.map +1 -1
- package/version.d.ts +2 -2
- package/version.js +4 -4
- package/version.mjs +2 -2
- package/_shims/ReadableStream-node.d.ts +0 -6
- package/_shims/ReadableStream-node.d.ts.map +0 -1
- package/_shims/ReadableStream-node.js +0 -14
- package/_shims/ReadableStream-node.js.map +0 -1
- package/_shims/ReadableStream-node.mjs +0 -3
- package/_shims/ReadableStream-node.mjs.map +0 -1
- package/_shims/ReadableStream.d.ts +0 -38
- package/_shims/ReadableStream.mjs +0 -7
- package/_shims/agent-node.d.ts +0 -7
- package/_shims/agent-node.d.ts.map +0 -1
- package/_shims/agent-node.js +0 -28
- package/_shims/agent-node.js.map +0 -1
- package/_shims/agent-node.mjs +0 -16
- package/_shims/agent-node.mjs.map +0 -1
- package/_shims/agent.d.ts +0 -9
- package/_shims/agent.d.ts.map +0 -1
- package/_shims/agent.js +0 -14
- package/_shims/agent.js.map +0 -1
- package/_shims/agent.mjs +0 -10
- package/_shims/agent.mjs.map +0 -1
- package/_shims/fetch-node.d.ts +0 -64
- package/_shims/fetch-node.js +0 -12
- package/_shims/fetch-node.mjs +0 -14
- package/_shims/fetch.d.ts +0 -60
- package/_shims/fetch.js +0 -13
- package/_shims/fetch.mjs +0 -15
- package/_shims/fileFromPath-node.d.ts +0 -17
- package/_shims/fileFromPath-node.d.ts.map +0 -1
- package/_shims/fileFromPath-node.js +0 -17
- package/_shims/fileFromPath-node.js.map +0 -1
- package/_shims/fileFromPath-node.mjs +0 -13
- package/_shims/fileFromPath-node.mjs.map +0 -1
- package/_shims/fileFromPath.d.ts +0 -22
- package/_shims/fileFromPath.d.ts.map +0 -1
- package/_shims/fileFromPath.js +0 -16
- package/_shims/fileFromPath.js.map +0 -1
- package/_shims/fileFromPath.mjs +0 -12
- package/_shims/fileFromPath.mjs.map +0 -1
- package/_shims/form-data-node.d.ts +0 -45
- package/_shims/form-data-node.js +0 -11
- package/_shims/form-data-node.mjs +0 -9
- package/_shims/form-data.d.ts +0 -43
- package/_shims/form-data.js +0 -17
- package/_shims/form-data.mjs +0 -20
- package/_shims/getMultipartRequestOptions-node.d.ts +0 -10
- package/_shims/getMultipartRequestOptions-node.d.ts.map +0 -1
- package/_shims/getMultipartRequestOptions-node.js +0 -22
- package/_shims/getMultipartRequestOptions-node.js.map +0 -1
- package/_shims/getMultipartRequestOptions-node.mjs +0 -18
- package/_shims/getMultipartRequestOptions-node.mjs.map +0 -1
- package/_shims/getMultipartRequestOptions.d.ts +0 -10
- package/_shims/getMultipartRequestOptions.d.ts.map +0 -1
- package/_shims/getMultipartRequestOptions.js +0 -12
- package/_shims/getMultipartRequestOptions.js.map +0 -1
- package/_shims/getMultipartRequestOptions.mjs +0 -8
- package/_shims/getMultipartRequestOptions.mjs.map +0 -1
- package/_shims/node-readable-node.d.ts +0 -8
- package/_shims/node-readable-node.d.ts.map +0 -1
- package/_shims/node-readable-node.js +0 -9
- package/_shims/node-readable-node.js.map +0 -1
- package/_shims/node-readable-node.mjs +0 -5
- package/_shims/node-readable-node.mjs.map +0 -1
- package/_shims/node-readable.d.ts +0 -23
- package/_shims/node-readable.d.ts.map +0 -1
- package/_shims/node-readable.js +0 -11
- package/_shims/node-readable.js.map +0 -1
- package/_shims/node-readable.mjs +0 -7
- package/_shims/node-readable.mjs.map +0 -1
- package/resources/ats/applications.d.ts +0 -39
- package/resources/ats/applications.d.ts.map +0 -1
- package/resources/ats/applications.js +0 -24
- package/resources/ats/applications.js.map +0 -1
- package/resources/ats/applications.mjs +0 -20
- package/resources/ats/applications.mjs.map +0 -1
- package/resources/ats/ats.d.ts +0 -32
- package/resources/ats/ats.d.ts.map +0 -1
- package/resources/ats/ats.js +0 -71
- package/resources/ats/ats.js.map +0 -1
- package/resources/ats/ats.mjs +0 -27
- package/resources/ats/ats.mjs.map +0 -1
- package/resources/ats/candidates.d.ts +0 -53
- package/resources/ats/candidates.d.ts.map +0 -1
- package/resources/ats/candidates.js +0 -25
- package/resources/ats/candidates.js.map +0 -1
- package/resources/ats/candidates.mjs +0 -21
- package/resources/ats/candidates.mjs.map +0 -1
- package/resources/ats/index.d.ts +0 -7
- package/resources/ats/index.d.ts.map +0 -1
- package/resources/ats/index.js +0 -60
- package/resources/ats/index.js.map +0 -1
- package/resources/ats/index.mjs +0 -8
- package/resources/ats/index.mjs.map +0 -1
- package/resources/ats/jobs.d.ts +0 -47
- package/resources/ats/jobs.d.ts.map +0 -1
- package/resources/ats/jobs.js +0 -24
- package/resources/ats/jobs.js.map +0 -1
- package/resources/ats/jobs.mjs +0 -20
- package/resources/ats/jobs.mjs.map +0 -1
- package/resources/ats/offers.d.ts +0 -39
- package/resources/ats/offers.d.ts.map +0 -1
- package/resources/ats/offers.js +0 -24
- package/resources/ats/offers.js.map +0 -1
- package/resources/ats/offers.mjs +0 -20
- package/resources/ats/offers.mjs.map +0 -1
- package/resources/ats/stages.d.ts +0 -30
- package/resources/ats/stages.d.ts.map +0 -1
- package/resources/ats/stages.js +0 -22
- package/resources/ats/stages.js.map +0 -1
- package/resources/ats/stages.mjs +0 -17
- package/resources/ats/stages.mjs.map +0 -1
- package/src/_shims/ReadableStream.d.ts +0 -38
- package/src/_shims/ReadableStream.mjs +0 -7
- package/src/_shims/agent-node.ts +0 -22
- package/src/_shims/agent.ts +0 -12
- package/src/_shims/fetch-node.d.ts +0 -64
- package/src/_shims/fetch-node.js +0 -12
- package/src/_shims/fetch-node.mjs +0 -14
- package/src/_shims/fetch.d.ts +0 -60
- package/src/_shims/fetch.js +0 -13
- package/src/_shims/fetch.mjs +0 -15
- package/src/_shims/fileFromPath-node.ts +0 -29
- package/src/_shims/fileFromPath.ts +0 -29
- package/src/_shims/form-data-node.d.ts +0 -45
- package/src/_shims/form-data-node.js +0 -11
- package/src/_shims/form-data-node.mjs +0 -9
- package/src/_shims/form-data.d.ts +0 -43
- package/src/_shims/form-data.js +0 -17
- package/src/_shims/form-data.mjs +0 -20
- package/src/_shims/getMultipartRequestOptions-node.ts +0 -25
- package/src/_shims/getMultipartRequestOptions.ts +0 -14
- package/src/_shims/node-readable-node.ts +0 -10
- package/src/_shims/node-readable.ts +0 -30
- package/src/resources/ats/applications.ts +0 -64
- package/src/resources/ats/ats.ts +0 -39
- package/src/resources/ats/candidates.ts +0 -83
- package/src/resources/ats/index.ts +0 -8
- package/src/resources/ats/jobs.ts +0 -76
- package/src/resources/ats/offers.ts +0 -63
- package/src/resources/ats/stages.ts +0 -39
package/core.js
CHANGED
|
@@ -1,515 +1,457 @@
|
|
|
1
|
-
|
|
2
|
-
var __classPrivateFieldSet =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
value
|
|
14
|
-
);
|
|
15
|
-
};
|
|
16
|
-
var __classPrivateFieldGet =
|
|
17
|
-
(this && this.__classPrivateFieldGet) ||
|
|
18
|
-
function (receiver, state, kind, f) {
|
|
19
|
-
if (kind === 'a' && !f) throw new TypeError('Private accessor was defined without a getter');
|
|
20
|
-
if (typeof state === 'function' ? receiver !== state || !f : !state.has(receiver))
|
|
21
|
-
throw new TypeError('Cannot read private member from an object whose class did not declare it');
|
|
22
|
-
return (
|
|
23
|
-
kind === 'm' ? f
|
|
24
|
-
: kind === 'a' ? f.call(receiver)
|
|
25
|
-
: f ? f.value
|
|
26
|
-
: state.get(receiver)
|
|
27
|
-
);
|
|
28
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
29
13
|
var _AbstractPage_client;
|
|
30
|
-
Object.defineProperty(exports,
|
|
31
|
-
exports.toBase64 =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
exports.maybeCoerceInteger =
|
|
41
|
-
exports.coerceBoolean =
|
|
42
|
-
exports.coerceFloat =
|
|
43
|
-
exports.coerceInteger =
|
|
44
|
-
exports.readEnv =
|
|
45
|
-
exports.ensurePresent =
|
|
46
|
-
exports.castToError =
|
|
47
|
-
exports.sleep =
|
|
48
|
-
exports.safeJSON =
|
|
49
|
-
exports.isRequestOptions =
|
|
50
|
-
exports.createResponseHeaders =
|
|
51
|
-
exports.PagePromise =
|
|
52
|
-
exports.AbstractPage =
|
|
53
|
-
exports.APIResource =
|
|
54
|
-
exports.APIClient =
|
|
55
|
-
exports.APIPromise =
|
|
56
|
-
exports.createForm =
|
|
57
|
-
exports.multipartFormRequestOptions =
|
|
58
|
-
exports.maybeMultipartFormRequestOptions =
|
|
59
|
-
void 0;
|
|
60
|
-
const version_1 = require('./version.js');
|
|
61
|
-
const error_1 = require('./error.js');
|
|
62
|
-
const agent_1 = require('@tryfinch/finch-api/_shims/agent');
|
|
63
|
-
const fetch_1 = require('@tryfinch/finch-api/_shims/fetch');
|
|
64
|
-
const uploads_1 = require('./uploads.js');
|
|
65
|
-
var uploads_2 = require('./uploads.js');
|
|
66
|
-
Object.defineProperty(exports, 'maybeMultipartFormRequestOptions', {
|
|
67
|
-
enumerable: true,
|
|
68
|
-
get: function () {
|
|
69
|
-
return uploads_2.maybeMultipartFormRequestOptions;
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
Object.defineProperty(exports, 'multipartFormRequestOptions', {
|
|
73
|
-
enumerable: true,
|
|
74
|
-
get: function () {
|
|
75
|
-
return uploads_2.multipartFormRequestOptions;
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
Object.defineProperty(exports, 'createForm', {
|
|
79
|
-
enumerable: true,
|
|
80
|
-
get: function () {
|
|
81
|
-
return uploads_2.createForm;
|
|
82
|
-
},
|
|
83
|
-
});
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.toBase64 = exports.getHeader = exports.isHeadersProtocol = exports.isRunningInBrowser = exports.debug = exports.hasOwn = exports.isEmptyObj = exports.maybeCoerceBoolean = exports.maybeCoerceFloat = exports.maybeCoerceInteger = exports.coerceBoolean = exports.coerceFloat = exports.coerceInteger = exports.readEnv = exports.ensurePresent = exports.castToError = exports.sleep = exports.safeJSON = exports.isRequestOptions = exports.createResponseHeaders = exports.PagePromise = exports.AbstractPage = exports.APIResource = exports.APIClient = exports.APIPromise = exports.createForm = exports.multipartFormRequestOptions = exports.maybeMultipartFormRequestOptions = void 0;
|
|
16
|
+
const version_1 = require("./version.js");
|
|
17
|
+
const error_1 = require("./error.js");
|
|
18
|
+
const index_1 = require("./_shims/index.js");
|
|
19
|
+
const uploads_1 = require("./uploads.js");
|
|
20
|
+
var uploads_2 = require("./uploads.js");
|
|
21
|
+
Object.defineProperty(exports, "maybeMultipartFormRequestOptions", { enumerable: true, get: function () { return uploads_2.maybeMultipartFormRequestOptions; } });
|
|
22
|
+
Object.defineProperty(exports, "multipartFormRequestOptions", { enumerable: true, get: function () { return uploads_2.multipartFormRequestOptions; } });
|
|
23
|
+
Object.defineProperty(exports, "createForm", { enumerable: true, get: function () { return uploads_2.createForm; } });
|
|
84
24
|
const MAX_RETRIES = 2;
|
|
85
25
|
async function defaultParseResponse(props) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
26
|
+
const { response } = props;
|
|
27
|
+
const contentType = response.headers.get('content-type');
|
|
28
|
+
if (contentType === null || contentType === void 0 ? void 0 : contentType.includes('application/json')) {
|
|
29
|
+
const json = await response.json();
|
|
30
|
+
debug('response', response.status, response.url, response.headers, json);
|
|
31
|
+
return json;
|
|
32
|
+
}
|
|
33
|
+
// TODO handle blob, arraybuffer, other content types, etc.
|
|
34
|
+
const text = await response.text();
|
|
35
|
+
debug('response', response.status, response.url, response.headers, text);
|
|
36
|
+
return text;
|
|
97
37
|
}
|
|
98
38
|
/**
|
|
99
39
|
* A subclass of `Promise` providing additional helper methods
|
|
100
40
|
* for interacting with the SDK.
|
|
101
41
|
*/
|
|
102
42
|
class APIPromise extends Promise {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
43
|
+
constructor(responsePromise, parseResponse = defaultParseResponse) {
|
|
44
|
+
super((resolve) => {
|
|
45
|
+
// this is maybe a bit weird but this has to be a no-op to not implicitly
|
|
46
|
+
// parse the response body; instead .then, .catch, .finally are overridden
|
|
47
|
+
// to parse the response
|
|
48
|
+
resolve(null);
|
|
49
|
+
});
|
|
50
|
+
this.responsePromise = responsePromise;
|
|
51
|
+
this.parseResponse = parseResponse;
|
|
52
|
+
}
|
|
53
|
+
_thenUnwrap(transform) {
|
|
54
|
+
return new APIPromise(this.responsePromise, async (props) => transform(await this.parseResponse(props)));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Gets the raw `Response` instance instead of parsing the response
|
|
58
|
+
* data.
|
|
59
|
+
*
|
|
60
|
+
* If you want to parse the response body but still get the `Response`
|
|
61
|
+
* instance, you can use {@link withResponse()}.
|
|
62
|
+
*
|
|
63
|
+
* 👋 Getting the wrong TypeScript type for `Response`?
|
|
64
|
+
* Try setting `"moduleResolution": "NodeNext"` if you can,
|
|
65
|
+
* or add one of these imports before your first `import … from '@tryfinch/finch-api'`:
|
|
66
|
+
* - `import '@tryfinch/finch-api/shims/node'` (if you're running on Node)
|
|
67
|
+
* - `import '@tryfinch/finch-api/shims/web'` (otherwise)
|
|
68
|
+
*/
|
|
69
|
+
asResponse() {
|
|
70
|
+
return this.responsePromise.then((p) => p.response);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Gets the parsed response data and the raw `Response` instance.
|
|
74
|
+
*
|
|
75
|
+
* If you just want to get the raw `Response` instance without parsing it,
|
|
76
|
+
* you can use {@link asResponse()}.
|
|
77
|
+
*
|
|
78
|
+
*
|
|
79
|
+
* 👋 Getting the wrong TypeScript type for `Response`?
|
|
80
|
+
* Try setting `"moduleResolution": "NodeNext"` if you can,
|
|
81
|
+
* or add one of these imports before your first `import … from '@tryfinch/finch-api'`:
|
|
82
|
+
* - `import '@tryfinch/finch-api/shims/node'` (if you're running on Node)
|
|
83
|
+
* - `import '@tryfinch/finch-api/shims/web'` (otherwise)
|
|
84
|
+
*/
|
|
85
|
+
async withResponse() {
|
|
86
|
+
const [data, response] = await Promise.all([this.parse(), this.asResponse()]);
|
|
87
|
+
return { data, response };
|
|
88
|
+
}
|
|
89
|
+
parse() {
|
|
90
|
+
if (!this.parsedPromise) {
|
|
91
|
+
this.parsedPromise = this.responsePromise.then(this.parseResponse);
|
|
92
|
+
}
|
|
93
|
+
return this.parsedPromise;
|
|
94
|
+
}
|
|
95
|
+
then(onfulfilled, onrejected) {
|
|
96
|
+
return this.parse().then(onfulfilled, onrejected);
|
|
97
|
+
}
|
|
98
|
+
catch(onrejected) {
|
|
99
|
+
return this.parse().catch(onrejected);
|
|
100
|
+
}
|
|
101
|
+
finally(onfinally) {
|
|
102
|
+
return this.parse().finally(onfinally);
|
|
103
|
+
}
|
|
151
104
|
}
|
|
152
105
|
exports.APIPromise = APIPromise;
|
|
153
106
|
class APIClient {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
this.baseURL = baseURL;
|
|
162
|
-
this.maxRetries = validatePositiveInteger(
|
|
163
|
-
'maxRetries',
|
|
164
|
-
maxRetries !== null && maxRetries !== void 0 ? maxRetries : MAX_RETRIES,
|
|
165
|
-
);
|
|
166
|
-
this.timeout = validatePositiveInteger('timeout', timeout);
|
|
167
|
-
this.httpAgent = httpAgent;
|
|
168
|
-
this.fetch = overridenFetch !== null && overridenFetch !== void 0 ? overridenFetch : fetch_1.fetch;
|
|
169
|
-
}
|
|
170
|
-
authHeaders(opts) {
|
|
171
|
-
return {};
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Override this to add your own default headers, for example:
|
|
175
|
-
*
|
|
176
|
-
* {
|
|
177
|
-
* ...super.defaultHeaders(),
|
|
178
|
-
* Authorization: 'Bearer 123',
|
|
179
|
-
* }
|
|
180
|
-
*/
|
|
181
|
-
defaultHeaders(opts) {
|
|
182
|
-
return {
|
|
183
|
-
Accept: 'application/json',
|
|
184
|
-
'Content-Type': 'application/json',
|
|
185
|
-
'User-Agent': this.getUserAgent(),
|
|
186
|
-
...getPlatformHeaders(),
|
|
187
|
-
...this.authHeaders(opts),
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Override this to add your own headers validation:
|
|
192
|
-
*/
|
|
193
|
-
validateHeaders(headers, customHeaders) {}
|
|
194
|
-
defaultIdempotencyKey() {
|
|
195
|
-
return `stainless-node-retry-${uuid4()}`;
|
|
196
|
-
}
|
|
197
|
-
get(path, opts) {
|
|
198
|
-
return this.methodRequest('get', path, opts);
|
|
199
|
-
}
|
|
200
|
-
post(path, opts) {
|
|
201
|
-
return this.methodRequest('post', path, opts);
|
|
202
|
-
}
|
|
203
|
-
patch(path, opts) {
|
|
204
|
-
return this.methodRequest('patch', path, opts);
|
|
205
|
-
}
|
|
206
|
-
put(path, opts) {
|
|
207
|
-
return this.methodRequest('put', path, opts);
|
|
208
|
-
}
|
|
209
|
-
delete(path, opts) {
|
|
210
|
-
return this.methodRequest('delete', path, opts);
|
|
211
|
-
}
|
|
212
|
-
methodRequest(method, path, opts) {
|
|
213
|
-
return this.request(Promise.resolve(opts).then((opts) => ({ method, path, ...opts })));
|
|
214
|
-
}
|
|
215
|
-
getAPIList(path, Page, opts) {
|
|
216
|
-
return this.requestAPIList(Page, { method: 'get', path, ...opts });
|
|
217
|
-
}
|
|
218
|
-
calculateContentLength(body) {
|
|
219
|
-
if (typeof body === 'string') {
|
|
220
|
-
if (typeof Buffer !== 'undefined') {
|
|
221
|
-
return Buffer.byteLength(body, 'utf8').toString();
|
|
222
|
-
}
|
|
223
|
-
if (typeof TextEncoder !== 'undefined') {
|
|
224
|
-
const encoder = new TextEncoder();
|
|
225
|
-
const encoded = encoder.encode(body);
|
|
226
|
-
return encoded.length.toString();
|
|
227
|
-
}
|
|
107
|
+
constructor({ baseURL, maxRetries, timeout = 60000, // 1 minute
|
|
108
|
+
httpAgent, fetch: overridenFetch, }) {
|
|
109
|
+
this.baseURL = baseURL;
|
|
110
|
+
this.maxRetries = validatePositiveInteger('maxRetries', maxRetries !== null && maxRetries !== void 0 ? maxRetries : MAX_RETRIES);
|
|
111
|
+
this.timeout = validatePositiveInteger('timeout', timeout);
|
|
112
|
+
this.httpAgent = httpAgent;
|
|
113
|
+
this.fetch = overridenFetch !== null && overridenFetch !== void 0 ? overridenFetch : index_1.fetch;
|
|
228
114
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
370
|
-
stringifyQuery(query) {
|
|
371
|
-
return Object.entries(query)
|
|
372
|
-
.filter(([_, value]) => typeof value !== 'undefined')
|
|
373
|
-
.map(([key, value]) => {
|
|
374
|
-
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
375
|
-
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
115
|
+
authHeaders(opts) {
|
|
116
|
+
return {};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Override this to add your own default headers, for example:
|
|
120
|
+
*
|
|
121
|
+
* {
|
|
122
|
+
* ...super.defaultHeaders(),
|
|
123
|
+
* Authorization: 'Bearer 123',
|
|
124
|
+
* }
|
|
125
|
+
*/
|
|
126
|
+
defaultHeaders(opts) {
|
|
127
|
+
return {
|
|
128
|
+
Accept: 'application/json',
|
|
129
|
+
'Content-Type': 'application/json',
|
|
130
|
+
'User-Agent': this.getUserAgent(),
|
|
131
|
+
...getPlatformHeaders(),
|
|
132
|
+
...this.authHeaders(opts),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Override this to add your own headers validation:
|
|
137
|
+
*/
|
|
138
|
+
validateHeaders(headers, customHeaders) { }
|
|
139
|
+
defaultIdempotencyKey() {
|
|
140
|
+
return `stainless-node-retry-${uuid4()}`;
|
|
141
|
+
}
|
|
142
|
+
get(path, opts) {
|
|
143
|
+
return this.methodRequest('get', path, opts);
|
|
144
|
+
}
|
|
145
|
+
post(path, opts) {
|
|
146
|
+
return this.methodRequest('post', path, opts);
|
|
147
|
+
}
|
|
148
|
+
patch(path, opts) {
|
|
149
|
+
return this.methodRequest('patch', path, opts);
|
|
150
|
+
}
|
|
151
|
+
put(path, opts) {
|
|
152
|
+
return this.methodRequest('put', path, opts);
|
|
153
|
+
}
|
|
154
|
+
delete(path, opts) {
|
|
155
|
+
return this.methodRequest('delete', path, opts);
|
|
156
|
+
}
|
|
157
|
+
methodRequest(method, path, opts) {
|
|
158
|
+
return this.request(Promise.resolve(opts).then((opts) => ({ method, path, ...opts })));
|
|
159
|
+
}
|
|
160
|
+
getAPIList(path, Page, opts) {
|
|
161
|
+
return this.requestAPIList(Page, { method: 'get', path, ...opts });
|
|
162
|
+
}
|
|
163
|
+
calculateContentLength(body) {
|
|
164
|
+
if (typeof body === 'string') {
|
|
165
|
+
if (typeof Buffer !== 'undefined') {
|
|
166
|
+
return Buffer.byteLength(body, 'utf8').toString();
|
|
167
|
+
}
|
|
168
|
+
if (typeof TextEncoder !== 'undefined') {
|
|
169
|
+
const encoder = new TextEncoder();
|
|
170
|
+
const encoded = encoder.encode(body);
|
|
171
|
+
return encoded.length.toString();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
buildRequest(options) {
|
|
177
|
+
var _a, _b, _c, _d, _e, _f;
|
|
178
|
+
const { method, path, query, headers: headers = {} } = options;
|
|
179
|
+
const body = (0, uploads_1.isMultipartBody)(options.body) ? options.body.body
|
|
180
|
+
: options.body ? JSON.stringify(options.body, null, 2)
|
|
181
|
+
: null;
|
|
182
|
+
const contentLength = this.calculateContentLength(body);
|
|
183
|
+
const url = this.buildURL(path, query);
|
|
184
|
+
if ('timeout' in options)
|
|
185
|
+
validatePositiveInteger('timeout', options.timeout);
|
|
186
|
+
const timeout = (_a = options.timeout) !== null && _a !== void 0 ? _a : this.timeout;
|
|
187
|
+
const httpAgent = (_c = (_b = options.httpAgent) !== null && _b !== void 0 ? _b : this.httpAgent) !== null && _c !== void 0 ? _c : (0, index_1.getDefaultAgent)(url);
|
|
188
|
+
const minAgentTimeout = timeout + 1000;
|
|
189
|
+
if (typeof ((_d = httpAgent === null || httpAgent === void 0 ? void 0 : httpAgent.options) === null || _d === void 0 ? void 0 : _d.timeout) === 'number' &&
|
|
190
|
+
minAgentTimeout > ((_e = httpAgent.options.timeout) !== null && _e !== void 0 ? _e : 0)) {
|
|
191
|
+
// Allow any given request to bump our agent active socket timeout.
|
|
192
|
+
// This may seem strange, but leaking active sockets should be rare and not particularly problematic,
|
|
193
|
+
// and without mutating agent we would need to create more of them.
|
|
194
|
+
// This tradeoff optimizes for performance.
|
|
195
|
+
httpAgent.options.timeout = minAgentTimeout;
|
|
196
|
+
}
|
|
197
|
+
if (this.idempotencyHeader && method !== 'get') {
|
|
198
|
+
if (!options.idempotencyKey)
|
|
199
|
+
options.idempotencyKey = this.defaultIdempotencyKey();
|
|
200
|
+
headers[this.idempotencyHeader] = options.idempotencyKey;
|
|
201
|
+
}
|
|
202
|
+
const reqHeaders = {
|
|
203
|
+
...(contentLength && { 'Content-Length': contentLength }),
|
|
204
|
+
...this.defaultHeaders(options),
|
|
205
|
+
...headers,
|
|
206
|
+
};
|
|
207
|
+
// let builtin fetch set the Content-Type for multipart bodies
|
|
208
|
+
if ((0, uploads_1.isMultipartBody)(options.body) && index_1.kind !== 'node') {
|
|
209
|
+
delete reqHeaders['Content-Type'];
|
|
210
|
+
}
|
|
211
|
+
// Strip any headers being explicitly omitted with null
|
|
212
|
+
Object.keys(reqHeaders).forEach((key) => reqHeaders[key] === null && delete reqHeaders[key]);
|
|
213
|
+
const req = {
|
|
214
|
+
method,
|
|
215
|
+
...(body && { body: body }),
|
|
216
|
+
headers: reqHeaders,
|
|
217
|
+
...(httpAgent && { agent: httpAgent }),
|
|
218
|
+
// @ts-ignore node-fetch uses a custom AbortSignal type that is
|
|
219
|
+
// not compatible with standard web types
|
|
220
|
+
signal: (_f = options.signal) !== null && _f !== void 0 ? _f : null,
|
|
221
|
+
};
|
|
222
|
+
this.validateHeaders(reqHeaders, headers);
|
|
223
|
+
return { req, url, timeout };
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Used as a callback for mutating the given `RequestInit` object.
|
|
227
|
+
*
|
|
228
|
+
* This is useful for cases where you want to add certain headers based off of
|
|
229
|
+
* the request properties, e.g. `method` or `url`.
|
|
230
|
+
*/
|
|
231
|
+
async prepareRequest(request, { url, options }) { }
|
|
232
|
+
parseHeaders(headers) {
|
|
233
|
+
return (!headers ? {}
|
|
234
|
+
: Symbol.iterator in headers ?
|
|
235
|
+
Object.fromEntries(Array.from(headers).map((header) => [...header]))
|
|
236
|
+
: { ...headers });
|
|
237
|
+
}
|
|
238
|
+
makeStatusError(status, error, message, headers) {
|
|
239
|
+
return error_1.APIError.generate(status, error, message, headers);
|
|
240
|
+
}
|
|
241
|
+
request(options, remainingRetries = null) {
|
|
242
|
+
return new APIPromise(this.makeRequest(options, remainingRetries));
|
|
243
|
+
}
|
|
244
|
+
async makeRequest(optionsInput, retriesRemaining) {
|
|
245
|
+
var _a, _b, _c;
|
|
246
|
+
const options = await optionsInput;
|
|
247
|
+
if (retriesRemaining == null) {
|
|
248
|
+
retriesRemaining = (_a = options.maxRetries) !== null && _a !== void 0 ? _a : this.maxRetries;
|
|
249
|
+
}
|
|
250
|
+
const { req, url, timeout } = this.buildRequest(options);
|
|
251
|
+
await this.prepareRequest(req, { url, options });
|
|
252
|
+
debug('request', url, options, req.headers);
|
|
253
|
+
if ((_b = options.signal) === null || _b === void 0 ? void 0 : _b.aborted) {
|
|
254
|
+
throw new error_1.APIUserAbortError();
|
|
376
255
|
}
|
|
377
|
-
|
|
378
|
-
|
|
256
|
+
const controller = new AbortController();
|
|
257
|
+
const response = await this.fetchWithTimeout(url, req, timeout, controller).catch(exports.castToError);
|
|
258
|
+
if (response instanceof Error) {
|
|
259
|
+
if ((_c = options.signal) === null || _c === void 0 ? void 0 : _c.aborted) {
|
|
260
|
+
throw new error_1.APIUserAbortError();
|
|
261
|
+
}
|
|
262
|
+
if (retriesRemaining) {
|
|
263
|
+
return this.retryRequest(options, retriesRemaining);
|
|
264
|
+
}
|
|
265
|
+
if (response.name === 'AbortError') {
|
|
266
|
+
throw new error_1.APIConnectionTimeoutError();
|
|
267
|
+
}
|
|
268
|
+
throw new error_1.APIConnectionError({ cause: response });
|
|
379
269
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
270
|
+
const responseHeaders = (0, exports.createResponseHeaders)(response.headers);
|
|
271
|
+
if (!response.ok) {
|
|
272
|
+
if (retriesRemaining && this.shouldRetry(response)) {
|
|
273
|
+
return this.retryRequest(options, retriesRemaining, responseHeaders);
|
|
274
|
+
}
|
|
275
|
+
const errText = await response.text().catch((e) => (0, exports.castToError)(e).message);
|
|
276
|
+
const errJSON = (0, exports.safeJSON)(errText);
|
|
277
|
+
const errMessage = errJSON ? undefined : errText;
|
|
278
|
+
debug('response', response.status, url, responseHeaders, errMessage);
|
|
279
|
+
const err = this.makeStatusError(response.status, errJSON, errMessage, responseHeaders);
|
|
280
|
+
throw err;
|
|
281
|
+
}
|
|
282
|
+
return { response, options, controller };
|
|
283
|
+
}
|
|
284
|
+
requestAPIList(Page, options) {
|
|
285
|
+
const request = this.makeRequest(options, null);
|
|
286
|
+
return new PagePromise(this, request, Page);
|
|
287
|
+
}
|
|
288
|
+
buildURL(path, query) {
|
|
289
|
+
const url = isAbsoluteURL(path) ?
|
|
290
|
+
new URL(path)
|
|
291
|
+
: new URL(this.baseURL + (this.baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
|
|
292
|
+
const defaultQuery = this.defaultQuery();
|
|
293
|
+
if (!isEmptyObj(defaultQuery)) {
|
|
294
|
+
query = { ...defaultQuery, ...query };
|
|
295
|
+
}
|
|
296
|
+
if (query) {
|
|
297
|
+
url.search = this.stringifyQuery(query);
|
|
298
|
+
}
|
|
299
|
+
return url.toString();
|
|
300
|
+
}
|
|
301
|
+
stringifyQuery(query) {
|
|
302
|
+
return Object.entries(query)
|
|
303
|
+
.filter(([_, value]) => typeof value !== 'undefined')
|
|
304
|
+
.map(([key, value]) => {
|
|
305
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
306
|
+
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
307
|
+
}
|
|
308
|
+
if (value === null) {
|
|
309
|
+
return `${encodeURIComponent(key)}=`;
|
|
310
|
+
}
|
|
311
|
+
throw new error_1.FinchError(`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`);
|
|
312
|
+
})
|
|
313
|
+
.join('&');
|
|
314
|
+
}
|
|
315
|
+
async fetchWithTimeout(url, init, ms, controller) {
|
|
316
|
+
const { signal, ...options } = init || {};
|
|
317
|
+
if (signal)
|
|
318
|
+
signal.addEventListener('abort', () => controller.abort());
|
|
319
|
+
const timeout = setTimeout(() => controller.abort(), ms);
|
|
320
|
+
return (this.getRequestClient()
|
|
321
|
+
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
|
|
322
|
+
.fetch.call(undefined, url, { signal: controller.signal, ...options })
|
|
323
|
+
.finally(() => {
|
|
324
|
+
clearTimeout(timeout);
|
|
325
|
+
}));
|
|
326
|
+
}
|
|
327
|
+
getRequestClient() {
|
|
328
|
+
return { fetch: this.fetch };
|
|
329
|
+
}
|
|
330
|
+
shouldRetry(response) {
|
|
331
|
+
// Note this is not a standard header.
|
|
332
|
+
const shouldRetryHeader = response.headers.get('x-should-retry');
|
|
333
|
+
// If the server explicitly says whether or not to retry, obey.
|
|
334
|
+
if (shouldRetryHeader === 'true')
|
|
335
|
+
return true;
|
|
336
|
+
if (shouldRetryHeader === 'false')
|
|
337
|
+
return false;
|
|
338
|
+
// Retry on request timeouts.
|
|
339
|
+
if (response.status === 408)
|
|
340
|
+
return true;
|
|
341
|
+
// Retry on lock timeouts.
|
|
342
|
+
if (response.status === 409)
|
|
343
|
+
return true;
|
|
344
|
+
// Retry on rate limits.
|
|
345
|
+
if (response.status === 429)
|
|
346
|
+
return true;
|
|
347
|
+
// Retry internal errors.
|
|
348
|
+
if (response.status >= 500)
|
|
349
|
+
return true;
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
async retryRequest(options, retriesRemaining, responseHeaders) {
|
|
353
|
+
var _a;
|
|
354
|
+
retriesRemaining -= 1;
|
|
355
|
+
// About the Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
|
|
356
|
+
let timeoutMillis;
|
|
357
|
+
const retryAfterHeader = responseHeaders === null || responseHeaders === void 0 ? void 0 : responseHeaders['retry-after'];
|
|
358
|
+
if (retryAfterHeader) {
|
|
359
|
+
const timeoutSeconds = parseInt(retryAfterHeader);
|
|
360
|
+
if (!Number.isNaN(timeoutSeconds)) {
|
|
361
|
+
timeoutMillis = timeoutSeconds * 1000;
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
timeoutMillis = Date.parse(retryAfterHeader) - Date.now();
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
// If the API asks us to wait a certain amount of time (and it's a reasonable amount),
|
|
368
|
+
// just do what it says, but otherwise calculate a default
|
|
369
|
+
if (!timeoutMillis ||
|
|
370
|
+
!Number.isInteger(timeoutMillis) ||
|
|
371
|
+
timeoutMillis <= 0 ||
|
|
372
|
+
timeoutMillis > 60 * 1000) {
|
|
373
|
+
const maxRetries = (_a = options.maxRetries) !== null && _a !== void 0 ? _a : this.maxRetries;
|
|
374
|
+
timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
|
|
375
|
+
}
|
|
376
|
+
await (0, exports.sleep)(timeoutMillis);
|
|
377
|
+
return this.makeRequest(options, retriesRemaining);
|
|
378
|
+
}
|
|
379
|
+
calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries) {
|
|
380
|
+
const initialRetryDelay = 0.5;
|
|
381
|
+
const maxRetryDelay = 2;
|
|
382
|
+
const numRetries = maxRetries - retriesRemaining;
|
|
383
|
+
// Apply exponential backoff, but not more than the max.
|
|
384
|
+
const sleepSeconds = Math.min(initialRetryDelay * Math.pow(numRetries - 1, 2), maxRetryDelay);
|
|
385
|
+
// Apply some jitter, plus-or-minus half a second.
|
|
386
|
+
const jitter = Math.random() - 0.5;
|
|
387
|
+
return (sleepSeconds + jitter) * 1000;
|
|
388
|
+
}
|
|
389
|
+
getUserAgent() {
|
|
390
|
+
return `${this.constructor.name}/JS ${version_1.VERSION}`;
|
|
391
|
+
}
|
|
447
392
|
}
|
|
448
393
|
exports.APIClient = APIClient;
|
|
449
394
|
class APIResource {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
395
|
+
constructor(client) {
|
|
396
|
+
this.client = client;
|
|
397
|
+
this.get = client.get.bind(client);
|
|
398
|
+
this.post = client.post.bind(client);
|
|
399
|
+
this.patch = client.patch.bind(client);
|
|
400
|
+
this.put = client.put.bind(client);
|
|
401
|
+
this.delete = client.delete.bind(client);
|
|
402
|
+
this.getAPIList = client.getAPIList.bind(client);
|
|
403
|
+
}
|
|
459
404
|
}
|
|
460
405
|
exports.APIResource = APIResource;
|
|
461
406
|
class AbstractPage {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
}
|
|
407
|
+
constructor(client, response, body, options) {
|
|
408
|
+
_AbstractPage_client.set(this, void 0);
|
|
409
|
+
__classPrivateFieldSet(this, _AbstractPage_client, client, "f");
|
|
410
|
+
this.options = options;
|
|
411
|
+
this.response = response;
|
|
412
|
+
this.body = body;
|
|
413
|
+
}
|
|
414
|
+
hasNextPage() {
|
|
415
|
+
const items = this.getPaginatedItems();
|
|
416
|
+
if (!items.length)
|
|
417
|
+
return false;
|
|
418
|
+
return this.nextPageInfo() != null;
|
|
419
|
+
}
|
|
420
|
+
async getNextPage() {
|
|
421
|
+
const nextInfo = this.nextPageInfo();
|
|
422
|
+
if (!nextInfo) {
|
|
423
|
+
throw new error_1.FinchError('No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.');
|
|
424
|
+
}
|
|
425
|
+
const nextOptions = { ...this.options };
|
|
426
|
+
if ('params' in nextInfo) {
|
|
427
|
+
nextOptions.query = { ...nextOptions.query, ...nextInfo.params };
|
|
428
|
+
}
|
|
429
|
+
else if ('url' in nextInfo) {
|
|
430
|
+
const params = [...Object.entries(nextOptions.query || {}), ...nextInfo.url.searchParams.entries()];
|
|
431
|
+
for (const [key, value] of params) {
|
|
432
|
+
nextInfo.url.searchParams.set(key, value);
|
|
433
|
+
}
|
|
434
|
+
nextOptions.query = undefined;
|
|
435
|
+
nextOptions.path = nextInfo.url.toString();
|
|
436
|
+
}
|
|
437
|
+
return await __classPrivateFieldGet(this, _AbstractPage_client, "f").requestAPIList(this.constructor, nextOptions);
|
|
438
|
+
}
|
|
439
|
+
async *iterPages() {
|
|
440
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
441
|
+
let page = this;
|
|
442
|
+
yield page;
|
|
443
|
+
while (page.hasNextPage()) {
|
|
444
|
+
page = await page.getNextPage();
|
|
445
|
+
yield page;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
async *[(_AbstractPage_client = new WeakMap(), Symbol.asyncIterator)]() {
|
|
449
|
+
for await (const page of this.iterPages()) {
|
|
450
|
+
for (const item of page.getPaginatedItems()) {
|
|
451
|
+
yield item;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
513
455
|
}
|
|
514
456
|
exports.AbstractPage = AbstractPage;
|
|
515
457
|
/**
|
|
@@ -522,217 +464,222 @@ exports.AbstractPage = AbstractPage;
|
|
|
522
464
|
* }
|
|
523
465
|
*/
|
|
524
466
|
class PagePromise extends APIPromise {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
yield item;
|
|
542
|
-
}
|
|
543
|
-
}
|
|
467
|
+
constructor(client, request, Page) {
|
|
468
|
+
super(request, async (props) => new Page(client, props.response, await defaultParseResponse(props), props.options));
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Allow auto-paginating iteration on an unawaited list call, eg:
|
|
472
|
+
*
|
|
473
|
+
* for await (const item of client.items.list()) {
|
|
474
|
+
* console.log(item)
|
|
475
|
+
* }
|
|
476
|
+
*/
|
|
477
|
+
async *[Symbol.asyncIterator]() {
|
|
478
|
+
const page = await this;
|
|
479
|
+
for await (const item of page) {
|
|
480
|
+
yield item;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
544
483
|
}
|
|
545
484
|
exports.PagePromise = PagePromise;
|
|
546
485
|
const createResponseHeaders = (headers) => {
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
return target[key.toLowerCase()] || target[key];
|
|
556
|
-
},
|
|
557
|
-
},
|
|
558
|
-
);
|
|
486
|
+
return new Proxy(Object.fromEntries(
|
|
487
|
+
// @ts-ignore
|
|
488
|
+
headers.entries()), {
|
|
489
|
+
get(target, name) {
|
|
490
|
+
const key = name.toString();
|
|
491
|
+
return target[key.toLowerCase()] || target[key];
|
|
492
|
+
},
|
|
493
|
+
});
|
|
559
494
|
};
|
|
560
495
|
exports.createResponseHeaders = createResponseHeaders;
|
|
561
496
|
// This is required so that we can determine if a given object matches the RequestOptions
|
|
562
497
|
// type at runtime. While this requires duplication, it is enforced by the TypeScript
|
|
563
498
|
// compiler such that any missing / extraneous keys will cause an error.
|
|
564
499
|
const requestOptionsKeys = {
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
500
|
+
method: true,
|
|
501
|
+
path: true,
|
|
502
|
+
query: true,
|
|
503
|
+
body: true,
|
|
504
|
+
headers: true,
|
|
505
|
+
maxRetries: true,
|
|
506
|
+
stream: true,
|
|
507
|
+
timeout: true,
|
|
508
|
+
httpAgent: true,
|
|
509
|
+
signal: true,
|
|
510
|
+
idempotencyKey: true,
|
|
576
511
|
};
|
|
577
512
|
const isRequestOptions = (obj) => {
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
Object.keys(obj).every((k) => hasOwn(requestOptionsKeys, k))
|
|
583
|
-
);
|
|
513
|
+
return (typeof obj === 'object' &&
|
|
514
|
+
obj !== null &&
|
|
515
|
+
!isEmptyObj(obj) &&
|
|
516
|
+
Object.keys(obj).every((k) => hasOwn(requestOptionsKeys, k)));
|
|
584
517
|
};
|
|
585
518
|
exports.isRequestOptions = isRequestOptions;
|
|
586
519
|
const getPlatformProperties = () => {
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
520
|
+
if (typeof Deno !== 'undefined' && Deno.build != null) {
|
|
521
|
+
return {
|
|
522
|
+
'X-Stainless-Lang': 'js',
|
|
523
|
+
'X-Stainless-Package-Version': version_1.VERSION,
|
|
524
|
+
'X-Stainless-OS': normalizePlatform(Deno.build.os),
|
|
525
|
+
'X-Stainless-Arch': normalizeArch(Deno.build.arch),
|
|
526
|
+
'X-Stainless-Runtime': 'deno',
|
|
527
|
+
'X-Stainless-Runtime-Version': Deno.version,
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
if (typeof EdgeRuntime !== 'undefined') {
|
|
531
|
+
return {
|
|
532
|
+
'X-Stainless-Lang': 'js',
|
|
533
|
+
'X-Stainless-Package-Version': version_1.VERSION,
|
|
534
|
+
'X-Stainless-OS': 'Unknown',
|
|
535
|
+
'X-Stainless-Arch': `other:${EdgeRuntime}`,
|
|
536
|
+
'X-Stainless-Runtime': 'edge',
|
|
537
|
+
'X-Stainless-Runtime-Version': process.version,
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
// Check if Node.js
|
|
541
|
+
if (Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]') {
|
|
542
|
+
return {
|
|
543
|
+
'X-Stainless-Lang': 'js',
|
|
544
|
+
'X-Stainless-Package-Version': version_1.VERSION,
|
|
545
|
+
'X-Stainless-OS': normalizePlatform(process.platform),
|
|
546
|
+
'X-Stainless-Arch': normalizeArch(process.arch),
|
|
547
|
+
'X-Stainless-Runtime': 'node',
|
|
548
|
+
'X-Stainless-Runtime-Version': process.version,
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
const browserInfo = getBrowserInfo();
|
|
552
|
+
if (browserInfo) {
|
|
553
|
+
return {
|
|
554
|
+
'X-Stainless-Lang': 'js',
|
|
555
|
+
'X-Stainless-Package-Version': version_1.VERSION,
|
|
556
|
+
'X-Stainless-OS': 'Unknown',
|
|
557
|
+
'X-Stainless-Arch': 'unknown',
|
|
558
|
+
'X-Stainless-Runtime': `browser:${browserInfo.browser}`,
|
|
559
|
+
'X-Stainless-Runtime-Version': browserInfo.version,
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
// TODO add support for Cloudflare workers, etc.
|
|
620
563
|
return {
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
564
|
+
'X-Stainless-Lang': 'js',
|
|
565
|
+
'X-Stainless-Package-Version': version_1.VERSION,
|
|
566
|
+
'X-Stainless-OS': 'Unknown',
|
|
567
|
+
'X-Stainless-Arch': 'unknown',
|
|
568
|
+
'X-Stainless-Runtime': 'unknown',
|
|
569
|
+
'X-Stainless-Runtime-Version': 'unknown',
|
|
627
570
|
};
|
|
628
|
-
}
|
|
629
|
-
// TODO add support for Cloudflare workers, etc.
|
|
630
|
-
return {
|
|
631
|
-
'X-Stainless-Lang': 'js',
|
|
632
|
-
'X-Stainless-Package-Version': version_1.VERSION,
|
|
633
|
-
'X-Stainless-OS': 'Unknown',
|
|
634
|
-
'X-Stainless-Arch': 'unknown',
|
|
635
|
-
'X-Stainless-Runtime': 'unknown',
|
|
636
|
-
'X-Stainless-Runtime-Version': 'unknown',
|
|
637
|
-
};
|
|
638
571
|
};
|
|
639
572
|
// Note: modified from https://github.com/JS-DevTools/host-environment/blob/b1ab79ecde37db5d6e163c050e54fe7d287d7c92/src/isomorphic.browser.ts
|
|
640
573
|
function getBrowserInfo() {
|
|
641
|
-
|
|
574
|
+
if (typeof navigator === 'undefined' || !navigator) {
|
|
575
|
+
return null;
|
|
576
|
+
}
|
|
577
|
+
// NOTE: The order matters here!
|
|
578
|
+
const browserPatterns = [
|
|
579
|
+
{ key: 'edge', pattern: /Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
580
|
+
{ key: 'ie', pattern: /MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
581
|
+
{ key: 'ie', pattern: /Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
582
|
+
{ key: 'chrome', pattern: /Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
583
|
+
{ key: 'firefox', pattern: /Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
584
|
+
{ key: 'safari', pattern: /(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/ },
|
|
585
|
+
];
|
|
586
|
+
// Find the FIRST matching browser
|
|
587
|
+
for (const { key, pattern } of browserPatterns) {
|
|
588
|
+
const match = pattern.exec(navigator.userAgent);
|
|
589
|
+
if (match) {
|
|
590
|
+
const major = match[1] || 0;
|
|
591
|
+
const minor = match[2] || 0;
|
|
592
|
+
const patch = match[3] || 0;
|
|
593
|
+
return { browser: key, version: `${major}.${minor}.${patch}` };
|
|
594
|
+
}
|
|
595
|
+
}
|
|
642
596
|
return null;
|
|
643
|
-
}
|
|
644
|
-
// NOTE: The order matters here!
|
|
645
|
-
const browserPatterns = [
|
|
646
|
-
{ key: 'edge', pattern: /Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
647
|
-
{ key: 'ie', pattern: /MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
648
|
-
{ key: 'ie', pattern: /Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
649
|
-
{ key: 'chrome', pattern: /Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
650
|
-
{ key: 'firefox', pattern: /Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
651
|
-
{ key: 'safari', pattern: /(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/ },
|
|
652
|
-
];
|
|
653
|
-
// Find the FIRST matching browser
|
|
654
|
-
for (const { key, pattern } of browserPatterns) {
|
|
655
|
-
const match = pattern.exec(navigator.userAgent);
|
|
656
|
-
if (match) {
|
|
657
|
-
const major = match[1] || 0;
|
|
658
|
-
const minor = match[2] || 0;
|
|
659
|
-
const patch = match[3] || 0;
|
|
660
|
-
return { browser: key, version: `${major}.${minor}.${patch}` };
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
return null;
|
|
664
597
|
}
|
|
665
598
|
const normalizeArch = (arch) => {
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
599
|
+
// Node docs:
|
|
600
|
+
// - https://nodejs.org/api/process.html#processarch
|
|
601
|
+
// Deno docs:
|
|
602
|
+
// - https://doc.deno.land/deno/stable/~/Deno.build
|
|
603
|
+
if (arch === 'x32')
|
|
604
|
+
return 'x32';
|
|
605
|
+
if (arch === 'x86_64' || arch === 'x64')
|
|
606
|
+
return 'x64';
|
|
607
|
+
if (arch === 'arm')
|
|
608
|
+
return 'arm';
|
|
609
|
+
if (arch === 'aarch64' || arch === 'arm64')
|
|
610
|
+
return 'arm64';
|
|
611
|
+
if (arch)
|
|
612
|
+
return `other:${arch}`;
|
|
613
|
+
return 'unknown';
|
|
676
614
|
};
|
|
677
615
|
const normalizePlatform = (platform) => {
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
616
|
+
// Node platforms:
|
|
617
|
+
// - https://nodejs.org/api/process.html#processplatform
|
|
618
|
+
// Deno platforms:
|
|
619
|
+
// - https://doc.deno.land/deno/stable/~/Deno.build
|
|
620
|
+
// - https://github.com/denoland/deno/issues/14799
|
|
621
|
+
platform = platform.toLowerCase();
|
|
622
|
+
// NOTE: this iOS check is untested and may not work
|
|
623
|
+
// Node does not work natively on IOS, there is a fork at
|
|
624
|
+
// https://github.com/nodejs-mobile/nodejs-mobile
|
|
625
|
+
// however it is unknown at the time of writing how to detect if it is running
|
|
626
|
+
if (platform.includes('ios'))
|
|
627
|
+
return 'iOS';
|
|
628
|
+
if (platform === 'android')
|
|
629
|
+
return 'Android';
|
|
630
|
+
if (platform === 'darwin')
|
|
631
|
+
return 'MacOS';
|
|
632
|
+
if (platform === 'win32')
|
|
633
|
+
return 'Windows';
|
|
634
|
+
if (platform === 'freebsd')
|
|
635
|
+
return 'FreeBSD';
|
|
636
|
+
if (platform === 'openbsd')
|
|
637
|
+
return 'OpenBSD';
|
|
638
|
+
if (platform === 'linux')
|
|
639
|
+
return 'Linux';
|
|
640
|
+
if (platform)
|
|
641
|
+
return `Other:${platform}`;
|
|
642
|
+
return 'Unknown';
|
|
697
643
|
};
|
|
698
644
|
let _platformHeaders;
|
|
699
645
|
const getPlatformHeaders = () => {
|
|
700
|
-
|
|
701
|
-
_platformHeaders
|
|
702
|
-
: (_platformHeaders = getPlatformProperties());
|
|
646
|
+
return (_platformHeaders !== null && _platformHeaders !== void 0 ? _platformHeaders : (_platformHeaders = getPlatformProperties()));
|
|
703
647
|
};
|
|
704
648
|
const safeJSON = (text) => {
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
649
|
+
try {
|
|
650
|
+
return JSON.parse(text);
|
|
651
|
+
}
|
|
652
|
+
catch (err) {
|
|
653
|
+
return undefined;
|
|
654
|
+
}
|
|
710
655
|
};
|
|
711
656
|
exports.safeJSON = safeJSON;
|
|
712
657
|
// https://stackoverflow.com/a/19709846
|
|
713
658
|
const startsWithSchemeRegexp = new RegExp('^(?:[a-z]+:)?//', 'i');
|
|
714
659
|
const isAbsoluteURL = (url) => {
|
|
715
|
-
|
|
660
|
+
return startsWithSchemeRegexp.test(url);
|
|
716
661
|
};
|
|
717
662
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
718
663
|
exports.sleep = sleep;
|
|
719
664
|
const validatePositiveInteger = (name, n) => {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
665
|
+
if (typeof n !== 'number' || !Number.isInteger(n)) {
|
|
666
|
+
throw new error_1.FinchError(`${name} must be an integer`);
|
|
667
|
+
}
|
|
668
|
+
if (n < 0) {
|
|
669
|
+
throw new error_1.FinchError(`${name} must be a positive integer`);
|
|
670
|
+
}
|
|
671
|
+
return n;
|
|
727
672
|
};
|
|
728
673
|
const castToError = (err) => {
|
|
729
|
-
|
|
730
|
-
|
|
674
|
+
if (err instanceof Error)
|
|
675
|
+
return err;
|
|
676
|
+
return new Error(err);
|
|
731
677
|
};
|
|
732
678
|
exports.castToError = castToError;
|
|
733
679
|
const ensurePresent = (value) => {
|
|
734
|
-
|
|
735
|
-
|
|
680
|
+
if (value == null)
|
|
681
|
+
throw new error_1.FinchError(`Expected a value to be given but received ${value} instead.`);
|
|
682
|
+
return value;
|
|
736
683
|
};
|
|
737
684
|
exports.ensurePresent = ensurePresent;
|
|
738
685
|
/**
|
|
@@ -741,126 +688,132 @@ exports.ensurePresent = ensurePresent;
|
|
|
741
688
|
* Will return undefined if the environment variable doesn't exist or cannot be accessed.
|
|
742
689
|
*/
|
|
743
690
|
const readEnv = (env) => {
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
return
|
|
752
|
-
void 0
|
|
753
|
-
: _d.call(_c, env);
|
|
754
|
-
}
|
|
755
|
-
return undefined;
|
|
691
|
+
var _a, _b, _c, _d;
|
|
692
|
+
if (typeof process !== 'undefined') {
|
|
693
|
+
return (_b = (_a = process.env) === null || _a === void 0 ? void 0 : _a[env]) !== null && _b !== void 0 ? _b : undefined;
|
|
694
|
+
}
|
|
695
|
+
if (typeof Deno !== 'undefined') {
|
|
696
|
+
return (_d = (_c = Deno.env) === null || _c === void 0 ? void 0 : _c.get) === null || _d === void 0 ? void 0 : _d.call(_c, env);
|
|
697
|
+
}
|
|
698
|
+
return undefined;
|
|
756
699
|
};
|
|
757
700
|
exports.readEnv = readEnv;
|
|
758
701
|
const coerceInteger = (value) => {
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
702
|
+
if (typeof value === 'number')
|
|
703
|
+
return Math.round(value);
|
|
704
|
+
if (typeof value === 'string')
|
|
705
|
+
return parseInt(value, 10);
|
|
706
|
+
throw new error_1.FinchError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
762
707
|
};
|
|
763
708
|
exports.coerceInteger = coerceInteger;
|
|
764
709
|
const coerceFloat = (value) => {
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
710
|
+
if (typeof value === 'number')
|
|
711
|
+
return value;
|
|
712
|
+
if (typeof value === 'string')
|
|
713
|
+
return parseFloat(value);
|
|
714
|
+
throw new error_1.FinchError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
768
715
|
};
|
|
769
716
|
exports.coerceFloat = coerceFloat;
|
|
770
717
|
const coerceBoolean = (value) => {
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
718
|
+
if (typeof value === 'boolean')
|
|
719
|
+
return value;
|
|
720
|
+
if (typeof value === 'string')
|
|
721
|
+
return value === 'true';
|
|
722
|
+
return Boolean(value);
|
|
774
723
|
};
|
|
775
724
|
exports.coerceBoolean = coerceBoolean;
|
|
776
725
|
const maybeCoerceInteger = (value) => {
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
726
|
+
if (value === undefined) {
|
|
727
|
+
return undefined;
|
|
728
|
+
}
|
|
729
|
+
return (0, exports.coerceInteger)(value);
|
|
781
730
|
};
|
|
782
731
|
exports.maybeCoerceInteger = maybeCoerceInteger;
|
|
783
732
|
const maybeCoerceFloat = (value) => {
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
733
|
+
if (value === undefined) {
|
|
734
|
+
return undefined;
|
|
735
|
+
}
|
|
736
|
+
return (0, exports.coerceFloat)(value);
|
|
788
737
|
};
|
|
789
738
|
exports.maybeCoerceFloat = maybeCoerceFloat;
|
|
790
739
|
const maybeCoerceBoolean = (value) => {
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
740
|
+
if (value === undefined) {
|
|
741
|
+
return undefined;
|
|
742
|
+
}
|
|
743
|
+
return (0, exports.coerceBoolean)(value);
|
|
795
744
|
};
|
|
796
745
|
exports.maybeCoerceBoolean = maybeCoerceBoolean;
|
|
797
746
|
// https://stackoverflow.com/a/34491287
|
|
798
747
|
function isEmptyObj(obj) {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
748
|
+
if (!obj)
|
|
749
|
+
return true;
|
|
750
|
+
for (const _k in obj)
|
|
751
|
+
return false;
|
|
752
|
+
return true;
|
|
802
753
|
}
|
|
803
754
|
exports.isEmptyObj = isEmptyObj;
|
|
804
755
|
// https://eslint.org/docs/latest/rules/no-prototype-builtins
|
|
805
756
|
function hasOwn(obj, key) {
|
|
806
|
-
|
|
757
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
807
758
|
}
|
|
808
759
|
exports.hasOwn = hasOwn;
|
|
809
760
|
function debug(action, ...args) {
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
761
|
+
if (typeof process !== 'undefined' && process.env['DEBUG'] === 'true') {
|
|
762
|
+
console.log(`Finch:DEBUG:${action}`, ...args);
|
|
763
|
+
}
|
|
813
764
|
}
|
|
814
765
|
exports.debug = debug;
|
|
815
766
|
/**
|
|
816
767
|
* https://stackoverflow.com/a/2117523
|
|
817
768
|
*/
|
|
818
769
|
const uuid4 = () => {
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
770
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
771
|
+
const r = (Math.random() * 16) | 0;
|
|
772
|
+
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
773
|
+
return v.toString(16);
|
|
774
|
+
});
|
|
824
775
|
};
|
|
825
776
|
const isRunningInBrowser = () => {
|
|
826
|
-
|
|
777
|
+
return (
|
|
827
778
|
// @ts-ignore
|
|
828
779
|
typeof window !== 'undefined' &&
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
);
|
|
780
|
+
// @ts-ignore
|
|
781
|
+
typeof window.document !== 'undefined' &&
|
|
782
|
+
// @ts-ignore
|
|
783
|
+
typeof navigator !== 'undefined');
|
|
834
784
|
};
|
|
835
785
|
exports.isRunningInBrowser = isRunningInBrowser;
|
|
836
786
|
const isHeadersProtocol = (headers) => {
|
|
837
|
-
|
|
787
|
+
return typeof (headers === null || headers === void 0 ? void 0 : headers.get) === 'function';
|
|
838
788
|
};
|
|
839
789
|
exports.isHeadersProtocol = isHeadersProtocol;
|
|
840
790
|
const getHeader = (headers, key) => {
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
if (value
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
791
|
+
const lowerKey = key.toLowerCase();
|
|
792
|
+
if ((0, exports.isHeadersProtocol)(headers))
|
|
793
|
+
return headers.get(key) || headers.get(lowerKey);
|
|
794
|
+
const value = headers[key] || headers[lowerKey];
|
|
795
|
+
if (Array.isArray(value)) {
|
|
796
|
+
if (value.length <= 1)
|
|
797
|
+
return value[0];
|
|
798
|
+
console.warn(`Received ${value.length} entries for the ${key} header, using the first entry.`);
|
|
799
|
+
return value[0];
|
|
800
|
+
}
|
|
801
|
+
return value;
|
|
850
802
|
};
|
|
851
803
|
exports.getHeader = getHeader;
|
|
852
804
|
/**
|
|
853
805
|
* Encodes a string to Base64 format.
|
|
854
806
|
*/
|
|
855
807
|
const toBase64 = (str) => {
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
808
|
+
if (!str)
|
|
809
|
+
return '';
|
|
810
|
+
if (typeof Buffer !== 'undefined') {
|
|
811
|
+
return Buffer.from(str).toString('base64');
|
|
812
|
+
}
|
|
813
|
+
if (typeof btoa !== 'undefined') {
|
|
814
|
+
return btoa(str);
|
|
815
|
+
}
|
|
816
|
+
throw new error_1.FinchError('Cannot generate b64 string; Expected `Buffer` or `btoa` to be defined');
|
|
864
817
|
};
|
|
865
818
|
exports.toBase64 = toBase64;
|
|
866
|
-
//# sourceMappingURL=core.js.map
|
|
819
|
+
//# sourceMappingURL=core.js.map
|