@financeable/aggregation 0.2.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/.devcontainer/README.md +35 -0
- package/.devcontainer/devcontainer.json +45 -0
- package/FUNCTIONS.md +225 -0
- package/README.md +967 -0
- package/RUNTIMES.md +48 -0
- package/core.d.ts +10 -0
- package/core.d.ts.map +1 -0
- package/core.js +17 -0
- package/core.js.map +1 -0
- package/docs/sdks/applications/README.md +467 -0
- package/docs/sdks/financeable/README.md +5 -0
- package/financeable-typescript/.devcontainer/README.md +30 -0
- package/financeable-typescript/FUNCTIONS.md +205 -0
- package/financeable-typescript/README.md +895 -0
- package/financeable-typescript/RUNTIMES.md +22 -0
- package/financeable-typescript/docs/sdks/applications/README.md +427 -0
- package/financeable-typescript/docs/sdks/financeable/README.md +5 -0
- package/financeable-typescript/src/core.ts +13 -0
- package/financeable-typescript/src/funcs/applicationsCreate.ts +124 -0
- package/financeable-typescript/src/funcs/applicationsGet.ts +128 -0
- package/financeable-typescript/src/funcs/applicationsList.ts +126 -0
- package/financeable-typescript/src/hooks/hooks.ts +129 -0
- package/financeable-typescript/src/hooks/index.ts +6 -0
- package/financeable-typescript/src/hooks/types.ts +109 -0
- package/financeable-typescript/src/index.ts +7 -0
- package/financeable-typescript/src/lib/base64.ts +37 -0
- package/financeable-typescript/src/lib/config.ts +59 -0
- package/financeable-typescript/src/lib/dlv.ts +53 -0
- package/financeable-typescript/src/lib/encodings.ts +449 -0
- package/financeable-typescript/src/lib/env.ts +37 -0
- package/financeable-typescript/src/lib/files.ts +40 -0
- package/financeable-typescript/src/lib/http.ts +323 -0
- package/financeable-typescript/src/lib/is-plain-object.ts +43 -0
- package/financeable-typescript/src/lib/logger.ts +9 -0
- package/financeable-typescript/src/lib/matchers.ts +322 -0
- package/financeable-typescript/src/lib/primitives.ts +122 -0
- package/financeable-typescript/src/lib/retries.ts +219 -0
- package/financeable-typescript/src/lib/schemas.ts +86 -0
- package/financeable-typescript/src/lib/sdks.ts +392 -0
- package/financeable-typescript/src/lib/security.ts +227 -0
- package/financeable-typescript/src/lib/url.ts +33 -0
- package/financeable-typescript/src/models/components/addressattributes.ts +148 -0
- package/financeable-typescript/src/models/components/apierrorlinks.ts +65 -0
- package/financeable-typescript/src/models/components/applicationattributes.ts +128 -0
- package/financeable-typescript/src/models/components/applicationattributescreate.ts +90 -0
- package/financeable-typescript/src/models/components/applicationresourcebulksubmission.ts +1000 -0
- package/financeable-typescript/src/models/components/applicationstatus.ts +39 -0
- package/financeable-typescript/src/models/components/applicationtype.ts +33 -0
- package/financeable-typescript/src/models/components/assetattributes.ts +400 -0
- package/financeable-typescript/src/models/components/customerattributes.ts +171 -0
- package/financeable-typescript/src/models/components/customertitle.ts +35 -0
- package/financeable-typescript/src/models/components/errorsource.ts +79 -0
- package/financeable-typescript/src/models/components/forbiddenerror.ts +207 -0
- package/financeable-typescript/src/models/components/frequencytype.ts +40 -0
- package/financeable-typescript/src/models/components/index.ts +20 -0
- package/financeable-typescript/src/models/components/links.ts +72 -0
- package/financeable-typescript/src/models/components/loandetailsattributes.ts +187 -0
- package/financeable-typescript/src/models/components/repaymentstructure.ts +40 -0
- package/financeable-typescript/src/models/errors/apierror.ts +27 -0
- package/financeable-typescript/src/models/errors/createapplication.ts +76 -0
- package/financeable-typescript/src/models/errors/getapplication.ts +76 -0
- package/financeable-typescript/src/models/errors/getapplications.ts +76 -0
- package/financeable-typescript/src/models/errors/httpclienterrors.ts +62 -0
- package/financeable-typescript/src/models/errors/index.ts +10 -0
- package/financeable-typescript/src/models/errors/sdkvalidationerror.ts +97 -0
- package/financeable-typescript/src/models/operations/createapplication.ts +1649 -0
- package/financeable-typescript/src/models/operations/getapplication.ts +1829 -0
- package/financeable-typescript/src/models/operations/getapplications.ts +1790 -0
- package/financeable-typescript/src/models/operations/index.ts +7 -0
- package/financeable-typescript/src/sdk/applications.ts +55 -0
- package/financeable-typescript/src/sdk/index.ts +5 -0
- package/financeable-typescript/src/sdk/sdk.ts +13 -0
- package/financeable-typescript/src/types/blobs.ts +31 -0
- package/financeable-typescript/src/types/constdatetime.ts +15 -0
- package/financeable-typescript/src/types/enums.ts +16 -0
- package/financeable-typescript/src/types/fp.ts +50 -0
- package/financeable-typescript/src/types/index.ts +11 -0
- package/financeable-typescript/src/types/operations.ts +105 -0
- package/financeable-typescript/src/types/rfcdate.ts +54 -0
- package/financeable-typescript/src/types/streams.ts +21 -0
- package/funcs/applicationsCreate.d.ts +14 -0
- package/funcs/applicationsCreate.d.ts.map +1 -0
- package/funcs/applicationsCreate.js +105 -0
- package/funcs/applicationsCreate.js.map +1 -0
- package/funcs/applicationsGet.d.ts +13 -0
- package/funcs/applicationsGet.d.ts.map +1 -0
- package/funcs/applicationsGet.js +109 -0
- package/funcs/applicationsGet.js.map +1 -0
- package/funcs/applicationsList.d.ts +13 -0
- package/funcs/applicationsList.d.ts.map +1 -0
- package/funcs/applicationsList.js +107 -0
- package/funcs/applicationsList.js.map +1 -0
- package/hooks/hooks.d.ts +24 -0
- package/hooks/hooks.d.ts.map +1 -0
- package/hooks/hooks.js +84 -0
- package/hooks/hooks.js.map +1 -0
- package/hooks/index.d.ts +3 -0
- package/hooks/index.d.ts.map +1 -0
- package/hooks/index.js +22 -0
- package/hooks/index.js.map +1 -0
- package/hooks/types.d.ts +78 -0
- package/hooks/types.d.ts.map +1 -0
- package/hooks/types.js +6 -0
- package/hooks/types.js.map +1 -0
- package/index.d.ts +4 -0
- package/index.d.ts.map +1 -0
- package/index.js +46 -0
- package/index.js.map +1 -0
- package/jsr.json +27 -0
- package/lib/base64.d.ts +10 -0
- package/lib/base64.d.ts.map +1 -0
- package/lib/base64.js +71 -0
- package/lib/base64.js.map +1 -0
- package/lib/config.d.ts +33 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +35 -0
- package/lib/config.js.map +1 -0
- package/lib/dlv.d.ts +14 -0
- package/lib/dlv.d.ts.map +1 -0
- package/lib/dlv.js +49 -0
- package/lib/dlv.js.map +1 -0
- package/lib/encodings.d.ts +52 -0
- package/lib/encodings.d.ts.map +1 -0
- package/lib/encodings.js +368 -0
- package/lib/encodings.js.map +1 -0
- package/lib/env.d.ts +14 -0
- package/lib/env.d.ts.map +1 -0
- package/lib/env.js +64 -0
- package/lib/env.js.map +1 -0
- package/lib/files.d.ts +8 -0
- package/lib/files.d.ts.map +1 -0
- package/lib/files.js +36 -0
- package/lib/files.js.map +1 -0
- package/lib/http.d.ts +67 -0
- package/lib/http.d.ts.map +1 -0
- package/lib/http.js +217 -0
- package/lib/http.js.map +1 -0
- package/lib/is-plain-object.d.ts +2 -0
- package/lib/is-plain-object.d.ts.map +1 -0
- package/lib/is-plain-object.js +41 -0
- package/lib/is-plain-object.js.map +1 -0
- package/lib/logger.d.ts +6 -0
- package/lib/logger.d.ts.map +1 -0
- package/lib/logger.js +6 -0
- package/lib/logger.js.map +1 -0
- package/lib/matchers.d.ts +64 -0
- package/lib/matchers.d.ts.map +1 -0
- package/lib/matchers.js +204 -0
- package/lib/matchers.js.map +1 -0
- package/lib/primitives.d.ts +23 -0
- package/lib/primitives.d.ts.map +1 -0
- package/lib/primitives.js +104 -0
- package/lib/primitives.js.map +1 -0
- package/lib/retries.d.ts +38 -0
- package/lib/retries.d.ts.map +1 -0
- package/lib/retries.js +153 -0
- package/lib/retries.js.map +1 -0
- package/lib/schemas.d.ts +19 -0
- package/lib/schemas.d.ts.map +1 -0
- package/lib/schemas.js +62 -0
- package/lib/schemas.js.map +1 -0
- package/lib/sdks.d.ts +60 -0
- package/lib/sdks.d.ts.map +1 -0
- package/lib/sdks.js +280 -0
- package/lib/sdks.js.map +1 -0
- package/lib/security.d.ts +79 -0
- package/lib/security.d.ts.map +1 -0
- package/lib/security.js +121 -0
- package/lib/security.js.map +1 -0
- package/lib/url.d.ts +5 -0
- package/lib/url.d.ts.map +1 -0
- package/lib/url.js +25 -0
- package/lib/url.js.map +1 -0
- package/models/components/addressattributes.d.ts +83 -0
- package/models/components/addressattributes.d.ts.map +1 -0
- package/models/components/addressattributes.js +117 -0
- package/models/components/addressattributes.js.map +1 -0
- package/models/components/apierrorlinks.d.ts +32 -0
- package/models/components/apierrorlinks.d.ts.map +1 -0
- package/models/components/apierrorlinks.js +69 -0
- package/models/components/apierrorlinks.js.map +1 -0
- package/models/components/applicationattributes.d.ts +69 -0
- package/models/components/applicationattributes.d.ts.map +1 -0
- package/models/components/applicationattributes.js +85 -0
- package/models/components/applicationattributes.js.map +1 -0
- package/models/components/applicationattributescreate.d.ts +43 -0
- package/models/components/applicationattributescreate.d.ts.map +1 -0
- package/models/components/applicationattributescreate.js +74 -0
- package/models/components/applicationattributescreate.js.map +1 -0
- package/models/components/applicationresourcebulksubmission.d.ts +456 -0
- package/models/components/applicationresourcebulksubmission.d.ts.map +1 -0
- package/models/components/applicationresourcebulksubmission.js +492 -0
- package/models/components/applicationresourcebulksubmission.js.map +1 -0
- package/models/components/applicationstatus.d.ts +46 -0
- package/models/components/applicationstatus.d.ts.map +1 -0
- package/models/components/applicationstatus.js +66 -0
- package/models/components/applicationstatus.js.map +1 -0
- package/models/components/applicationtype.d.ts +28 -0
- package/models/components/applicationtype.d.ts.map +1 -0
- package/models/components/applicationtype.js +60 -0
- package/models/components/applicationtype.js.map +1 -0
- package/models/components/assetattributes.d.ts +388 -0
- package/models/components/assetattributes.d.ts.map +1 -0
- package/models/components/assetattributes.js +244 -0
- package/models/components/assetattributes.js.map +1 -0
- package/models/components/customerattributes.d.ts +103 -0
- package/models/components/customerattributes.d.ts.map +1 -0
- package/models/components/customerattributes.js +120 -0
- package/models/components/customerattributes.js.map +1 -0
- package/models/components/customertitle.d.ts +34 -0
- package/models/components/customertitle.d.ts.map +1 -0
- package/models/components/customertitle.js +62 -0
- package/models/components/customertitle.js.map +1 -0
- package/models/components/errorsource.d.ts +42 -0
- package/models/components/errorsource.d.ts.map +1 -0
- package/models/components/errorsource.js +73 -0
- package/models/components/errorsource.js.map +1 -0
- package/models/components/forbiddenerror.d.ts +141 -0
- package/models/components/forbiddenerror.d.ts.map +1 -0
- package/models/components/forbiddenerror.js +158 -0
- package/models/components/forbiddenerror.js.map +1 -0
- package/models/components/frequencytype.d.ts +37 -0
- package/models/components/frequencytype.d.ts.map +1 -0
- package/models/components/frequencytype.js +64 -0
- package/models/components/frequencytype.js.map +1 -0
- package/models/components/index.d.ts +17 -0
- package/models/components/index.d.ts.map +1 -0
- package/models/components/index.js +36 -0
- package/models/components/index.js.map +1 -0
- package/models/components/links.d.ts +40 -0
- package/models/components/links.d.ts.map +1 -0
- package/models/components/links.js +72 -0
- package/models/components/links.js.map +1 -0
- package/models/components/loandetailsattributes.d.ts +112 -0
- package/models/components/loandetailsattributes.d.ts.map +1 -0
- package/models/components/loandetailsattributes.js +101 -0
- package/models/components/loandetailsattributes.js.map +1 -0
- package/models/components/repaymentstructure.d.ts +37 -0
- package/models/components/repaymentstructure.d.ts.map +1 -0
- package/models/components/repaymentstructure.js +64 -0
- package/models/components/repaymentstructure.js.map +1 -0
- package/models/errors/apierror.d.ts +8 -0
- package/models/errors/apierror.d.ts.map +1 -0
- package/models/errors/apierror.js +21 -0
- package/models/errors/apierror.js.map +1 -0
- package/models/errors/createapplication.d.ts +38 -0
- package/models/errors/createapplication.d.ts.map +1 -0
- package/models/errors/createapplication.js +81 -0
- package/models/errors/createapplication.js.map +1 -0
- package/models/errors/getapplication.d.ts +38 -0
- package/models/errors/getapplication.d.ts.map +1 -0
- package/models/errors/getapplication.js +81 -0
- package/models/errors/getapplication.js.map +1 -0
- package/models/errors/getapplications.d.ts +38 -0
- package/models/errors/getapplications.d.ts.map +1 -0
- package/models/errors/getapplications.js +81 -0
- package/models/errors/getapplications.js.map +1 -0
- package/models/errors/httpclienterrors.d.ts +44 -0
- package/models/errors/httpclienterrors.d.ts.map +1 -0
- package/models/errors/httpclienterrors.js +78 -0
- package/models/errors/httpclienterrors.js.map +1 -0
- package/models/errors/index.d.ts +7 -0
- package/models/errors/index.d.ts.map +1 -0
- package/models/errors/index.js +26 -0
- package/models/errors/index.js.map +1 -0
- package/models/errors/sdkvalidationerror.d.ts +20 -0
- package/models/errors/sdkvalidationerror.d.ts.map +1 -0
- package/models/errors/sdkvalidationerror.js +115 -0
- package/models/errors/sdkvalidationerror.js.map +1 -0
- package/models/operations/createapplication.d.ts +780 -0
- package/models/operations/createapplication.d.ts.map +1 -0
- package/models/operations/createapplication.js +834 -0
- package/models/operations/createapplication.js.map +1 -0
- package/models/operations/getapplication.d.ts +805 -0
- package/models/operations/getapplication.d.ts.map +1 -0
- package/models/operations/getapplication.js +861 -0
- package/models/operations/getapplication.js.map +1 -0
- package/models/operations/getapplications.d.ts +805 -0
- package/models/operations/getapplications.d.ts.map +1 -0
- package/models/operations/getapplications.js +864 -0
- package/models/operations/getapplications.js.map +1 -0
- package/models/operations/index.d.ts +4 -0
- package/models/operations/index.d.ts.map +1 -0
- package/models/operations/index.js +23 -0
- package/models/operations/index.js.map +1 -0
- package/package.json +30 -0
- package/sdk/applications.d.ts +18 -0
- package/sdk/applications.d.ts.map +1 -0
- package/sdk/applications.js +33 -0
- package/sdk/applications.js.map +1 -0
- package/sdk/index.d.ts +2 -0
- package/sdk/index.d.ts.map +1 -0
- package/sdk/index.js +21 -0
- package/sdk/index.js.map +1 -0
- package/sdk/sdk.d.ts +7 -0
- package/sdk/sdk.d.ts.map +1 -0
- package/sdk/sdk.js +15 -0
- package/sdk/sdk.js.map +1 -0
- package/src/core.ts +13 -0
- package/src/funcs/applicationsCreate.ts +128 -0
- package/src/funcs/applicationsGet.ts +132 -0
- package/src/funcs/applicationsList.ts +130 -0
- package/src/hooks/hooks.ts +129 -0
- package/src/hooks/index.ts +6 -0
- package/src/hooks/types.ts +110 -0
- package/src/index.ts +7 -0
- package/src/lib/base64.ts +37 -0
- package/src/lib/config.ts +59 -0
- package/src/lib/dlv.ts +53 -0
- package/src/lib/encodings.ts +483 -0
- package/src/lib/env.ts +37 -0
- package/src/lib/files.ts +40 -0
- package/src/lib/http.ts +323 -0
- package/src/lib/is-plain-object.ts +43 -0
- package/src/lib/logger.ts +9 -0
- package/src/lib/matchers.ts +322 -0
- package/src/lib/primitives.ts +136 -0
- package/src/lib/retries.ts +218 -0
- package/src/lib/schemas.ts +91 -0
- package/src/lib/sdks.ts +400 -0
- package/src/lib/security.ts +227 -0
- package/src/lib/url.ts +33 -0
- package/src/models/components/addressattributes.ts +148 -0
- package/src/models/components/apierrorlinks.ts +65 -0
- package/src/models/components/applicationattributes.ts +128 -0
- package/src/models/components/applicationattributescreate.ts +90 -0
- package/src/models/components/applicationresourcebulksubmission.ts +1000 -0
- package/src/models/components/applicationstatus.ts +39 -0
- package/src/models/components/applicationtype.ts +33 -0
- package/src/models/components/assetattributes.ts +400 -0
- package/src/models/components/customerattributes.ts +171 -0
- package/src/models/components/customertitle.ts +35 -0
- package/src/models/components/errorsource.ts +79 -0
- package/src/models/components/forbiddenerror.ts +207 -0
- package/src/models/components/frequencytype.ts +40 -0
- package/src/models/components/index.ts +20 -0
- package/src/models/components/links.ts +72 -0
- package/src/models/components/loandetailsattributes.ts +187 -0
- package/src/models/components/repaymentstructure.ts +40 -0
- package/src/models/errors/apierror.ts +27 -0
- package/src/models/errors/createapplication.ts +76 -0
- package/src/models/errors/getapplication.ts +76 -0
- package/src/models/errors/getapplications.ts +76 -0
- package/src/models/errors/httpclienterrors.ts +62 -0
- package/src/models/errors/index.ts +10 -0
- package/src/models/errors/sdkvalidationerror.ts +97 -0
- package/src/models/operations/createapplication.ts +1649 -0
- package/src/models/operations/getapplication.ts +1829 -0
- package/src/models/operations/getapplications.ts +1790 -0
- package/src/models/operations/index.ts +7 -0
- package/src/sdk/applications.ts +55 -0
- package/src/sdk/index.ts +5 -0
- package/src/sdk/sdk.ts +13 -0
- package/src/types/blobs.ts +31 -0
- package/src/types/constdatetime.ts +15 -0
- package/src/types/enums.ts +16 -0
- package/src/types/fp.ts +50 -0
- package/src/types/index.ts +11 -0
- package/src/types/operations.ts +105 -0
- package/src/types/rfcdate.ts +54 -0
- package/src/types/streams.ts +21 -0
- package/tsconfig.json +41 -0
- package/types/blobs.d.ts +4 -0
- package/types/blobs.d.ts.map +1 -0
- package/types/blobs.js +62 -0
- package/types/blobs.js.map +1 -0
- package/types/constdatetime.d.ts +3 -0
- package/types/constdatetime.d.ts.map +1 -0
- package/types/constdatetime.js +46 -0
- package/types/constdatetime.js.map +1 -0
- package/types/enums.d.ts +12 -0
- package/types/enums.d.ts.map +1 -0
- package/types/enums.js +10 -0
- package/types/enums.js.map +1 -0
- package/types/fp.d.ts +31 -0
- package/types/fp.d.ts.map +1 -0
- package/types/fp.js +37 -0
- package/types/fp.js.map +1 -0
- package/types/index.d.ts +8 -0
- package/types/index.d.ts.map +1 -0
- package/types/index.js +16 -0
- package/types/index.js.map +1 -0
- package/types/operations.d.ts +27 -0
- package/types/operations.d.ts.map +1 -0
- package/types/operations.js +83 -0
- package/types/operations.js.map +1 -0
- package/types/rfcdate.d.ts +21 -0
- package/types/rfcdate.d.ts.map +1 -0
- package/types/rfcdate.js +46 -0
- package/types/rfcdate.js.map +1 -0
- package/types/streams.d.ts +2 -0
- package/types/streams.d.ts.map +1 -0
- package/types/streams.js +18 -0
- package/types/streams.js.map +1 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
class InvariantError extends Error {
|
|
6
|
+
constructor(message: string) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "InvariantError";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function invariant(
|
|
13
|
+
condition: unknown,
|
|
14
|
+
message: string,
|
|
15
|
+
): asserts condition {
|
|
16
|
+
if (!condition) {
|
|
17
|
+
throw new InvariantError(message);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type ExactPartial<T> = {
|
|
22
|
+
[P in keyof T]?: T[P] | undefined;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type Remap<Inp, Mapping extends { [k in keyof Inp]?: string | null }> = {
|
|
26
|
+
[k in keyof Inp as Mapping[k] extends string /* if we have a string mapping for this key then use it */
|
|
27
|
+
? Mapping[k]
|
|
28
|
+
: Mapping[k] extends null /* if the mapping is to `null` then drop the key */
|
|
29
|
+
? never
|
|
30
|
+
: k /* otherwise keep the key as-is */]: Inp[k];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Converts or omits an object's keys according to a mapping.
|
|
35
|
+
*
|
|
36
|
+
* @param inp An object whose keys will be remapped
|
|
37
|
+
* @param mappings A mapping of original keys to new keys. If a key is not present in the mapping, it will be left as is. If a key is mapped to `null`, it will be removed in the resulting object.
|
|
38
|
+
* @returns A new object with keys remapped or omitted according to the mappings
|
|
39
|
+
*/
|
|
40
|
+
export function remap<
|
|
41
|
+
Inp extends Record<string, unknown>,
|
|
42
|
+
const Mapping extends { [k in keyof Inp]?: string | null },
|
|
43
|
+
>(inp: Inp, mappings: Mapping): Remap<Inp, Mapping> {
|
|
44
|
+
let out: any = {};
|
|
45
|
+
|
|
46
|
+
if (!Object.keys(mappings).length) {
|
|
47
|
+
out = inp;
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
for (const [k, v] of Object.entries(inp)) {
|
|
52
|
+
const j = mappings[k];
|
|
53
|
+
if (j === null) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
out[j ?? k] = v;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function combineSignals(
|
|
63
|
+
...signals: Array<AbortSignal | null | undefined>
|
|
64
|
+
): AbortSignal | null {
|
|
65
|
+
const filtered: AbortSignal[] = [];
|
|
66
|
+
for (const signal of signals) {
|
|
67
|
+
if (signal) {
|
|
68
|
+
filtered.push(signal);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
switch (filtered.length) {
|
|
73
|
+
case 0:
|
|
74
|
+
case 1:
|
|
75
|
+
return filtered[0] || null;
|
|
76
|
+
default:
|
|
77
|
+
if ("any" in AbortSignal && typeof AbortSignal.any === "function") {
|
|
78
|
+
return AbortSignal.any(filtered);
|
|
79
|
+
}
|
|
80
|
+
return abortSignalAny(filtered);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function abortSignalAny(signals: AbortSignal[]): AbortSignal {
|
|
85
|
+
const controller = new AbortController();
|
|
86
|
+
const result = controller.signal;
|
|
87
|
+
if (!signals.length) {
|
|
88
|
+
return controller.signal;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (signals.length === 1) {
|
|
92
|
+
return signals[0] || controller.signal;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
for (const signal of signals) {
|
|
96
|
+
if (signal.aborted) {
|
|
97
|
+
return signal;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function abort(this: AbortSignal) {
|
|
102
|
+
controller.abort(this.reason);
|
|
103
|
+
clean();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const signalRefs: WeakRef<AbortSignal>[] = [];
|
|
107
|
+
function clean() {
|
|
108
|
+
for (const signalRef of signalRefs) {
|
|
109
|
+
const signal = signalRef.deref();
|
|
110
|
+
if (signal) {
|
|
111
|
+
signal.removeEventListener("abort", abort);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
for (const signal of signals) {
|
|
117
|
+
signalRefs.push(new WeakRef(signal));
|
|
118
|
+
signal.addEventListener("abort", abort);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { isConnectionError, isTimeoutError } from "./http.js";
|
|
6
|
+
|
|
7
|
+
export type BackoffStrategy = {
|
|
8
|
+
initialInterval: number;
|
|
9
|
+
maxInterval: number;
|
|
10
|
+
exponent: number;
|
|
11
|
+
maxElapsedTime: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const defaultBackoff: BackoffStrategy = {
|
|
15
|
+
initialInterval: 500,
|
|
16
|
+
maxInterval: 60000,
|
|
17
|
+
exponent: 1.5,
|
|
18
|
+
maxElapsedTime: 3600000,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type RetryConfig =
|
|
22
|
+
| { strategy: "none" }
|
|
23
|
+
| {
|
|
24
|
+
strategy: "backoff";
|
|
25
|
+
backoff?: BackoffStrategy;
|
|
26
|
+
retryConnectionErrors?: boolean;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* PermanentError is an error that is not recoverable. Throwing this error will
|
|
31
|
+
* cause a retry loop to terminate.
|
|
32
|
+
*/
|
|
33
|
+
export class PermanentError extends Error {
|
|
34
|
+
/** The underlying cause of the error. */
|
|
35
|
+
override readonly cause: unknown;
|
|
36
|
+
|
|
37
|
+
constructor(message: string, options?: { cause?: unknown }) {
|
|
38
|
+
let msg = message;
|
|
39
|
+
if (options?.cause) {
|
|
40
|
+
msg += `: ${options.cause}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
super(msg, options);
|
|
44
|
+
this.name = "PermanentError";
|
|
45
|
+
// In older runtimes, the cause field would not have been assigned through
|
|
46
|
+
// the super() call.
|
|
47
|
+
if (typeof this.cause === "undefined") {
|
|
48
|
+
this.cause = options?.cause;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
Object.setPrototypeOf(this, PermanentError.prototype);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* TemporaryError is an error is used to signal that an HTTP request can be
|
|
57
|
+
* retried as part of a retry loop. If retry attempts are exhausted and this
|
|
58
|
+
* error is thrown, the response will be returned to the caller.
|
|
59
|
+
*/
|
|
60
|
+
export class TemporaryError extends Error {
|
|
61
|
+
response: Response;
|
|
62
|
+
|
|
63
|
+
constructor(message: string, response: Response) {
|
|
64
|
+
super(message);
|
|
65
|
+
this.response = response;
|
|
66
|
+
this.name = "TemporaryError";
|
|
67
|
+
|
|
68
|
+
Object.setPrototypeOf(this, TemporaryError.prototype);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export async function retry(
|
|
73
|
+
fetchFn: () => Promise<Response>,
|
|
74
|
+
options: {
|
|
75
|
+
config: RetryConfig;
|
|
76
|
+
statusCodes: string[];
|
|
77
|
+
},
|
|
78
|
+
): Promise<Response> {
|
|
79
|
+
switch (options.config.strategy) {
|
|
80
|
+
case "backoff":
|
|
81
|
+
return retryBackoff(
|
|
82
|
+
wrapFetcher(fetchFn, {
|
|
83
|
+
statusCodes: options.statusCodes,
|
|
84
|
+
retryConnectionErrors: !!options.config.retryConnectionErrors,
|
|
85
|
+
}),
|
|
86
|
+
options.config.backoff ?? defaultBackoff,
|
|
87
|
+
);
|
|
88
|
+
default:
|
|
89
|
+
return await fetchFn();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function wrapFetcher(
|
|
94
|
+
fn: () => Promise<Response>,
|
|
95
|
+
options: {
|
|
96
|
+
statusCodes: string[];
|
|
97
|
+
retryConnectionErrors: boolean;
|
|
98
|
+
},
|
|
99
|
+
): () => Promise<Response> {
|
|
100
|
+
return async () => {
|
|
101
|
+
try {
|
|
102
|
+
const res = await fn();
|
|
103
|
+
if (isRetryableResponse(res, options.statusCodes)) {
|
|
104
|
+
throw new TemporaryError(
|
|
105
|
+
"Response failed with retryable status code",
|
|
106
|
+
res,
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return res;
|
|
111
|
+
} catch (err: unknown) {
|
|
112
|
+
if (err instanceof TemporaryError) {
|
|
113
|
+
throw err;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (
|
|
117
|
+
options.retryConnectionErrors &&
|
|
118
|
+
(isTimeoutError(err) || isConnectionError(err))
|
|
119
|
+
) {
|
|
120
|
+
throw err;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
throw new PermanentError("Permanent error", { cause: err });
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const codeRangeRE = new RegExp("^[0-9]xx$", "i");
|
|
129
|
+
|
|
130
|
+
function isRetryableResponse(res: Response, statusCodes: string[]): boolean {
|
|
131
|
+
const actual = `${res.status}`;
|
|
132
|
+
|
|
133
|
+
return statusCodes.some((code) => {
|
|
134
|
+
if (!codeRangeRE.test(code)) {
|
|
135
|
+
return code === actual;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const expectFamily = code.charAt(0);
|
|
139
|
+
if (!expectFamily) {
|
|
140
|
+
throw new Error("Invalid status code range");
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const actualFamily = actual.charAt(0);
|
|
144
|
+
if (!actualFamily) {
|
|
145
|
+
throw new Error(`Invalid response status code: ${actual}`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return actualFamily === expectFamily;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function retryBackoff(
|
|
153
|
+
fn: () => Promise<Response>,
|
|
154
|
+
strategy: BackoffStrategy,
|
|
155
|
+
): Promise<Response> {
|
|
156
|
+
const { maxElapsedTime, initialInterval, exponent, maxInterval } = strategy;
|
|
157
|
+
|
|
158
|
+
const start = Date.now();
|
|
159
|
+
let x = 0;
|
|
160
|
+
|
|
161
|
+
// eslint-disable-next-line no-constant-condition
|
|
162
|
+
while (true) {
|
|
163
|
+
try {
|
|
164
|
+
const res = await fn();
|
|
165
|
+
return res;
|
|
166
|
+
} catch (err: unknown) {
|
|
167
|
+
if (err instanceof PermanentError) {
|
|
168
|
+
throw err.cause;
|
|
169
|
+
}
|
|
170
|
+
const elapsed = Date.now() - start;
|
|
171
|
+
if (elapsed > maxElapsedTime) {
|
|
172
|
+
if (err instanceof TemporaryError) {
|
|
173
|
+
return err.response;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
throw err;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
let retryInterval = 0;
|
|
180
|
+
if (err instanceof TemporaryError) {
|
|
181
|
+
retryInterval = retryIntervalFromResponse(err.response);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (retryInterval <= 0) {
|
|
185
|
+
retryInterval =
|
|
186
|
+
initialInterval * Math.pow(x, exponent) + Math.random() * 1000;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const d = Math.min(retryInterval, maxInterval);
|
|
190
|
+
|
|
191
|
+
await delay(d);
|
|
192
|
+
x++;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function retryIntervalFromResponse(res: Response): number {
|
|
198
|
+
const retryVal = res.headers.get("retry-after") || "";
|
|
199
|
+
if (!retryVal) {
|
|
200
|
+
return 0;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const parsedNumber = Number(retryVal);
|
|
204
|
+
if (Number.isInteger(parsedNumber)) {
|
|
205
|
+
return parsedNumber * 1000;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const parsedDate = Date.parse(retryVal);
|
|
209
|
+
if (Number.isInteger(parsedDate)) {
|
|
210
|
+
const deltaMS = parsedDate - Date.now();
|
|
211
|
+
return deltaMS > 0 ? Math.ceil(deltaMS) : 0;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return 0;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async function delay(delay: number): Promise<void> {
|
|
218
|
+
return new Promise((resolve) => setTimeout(resolve, delay));
|
|
219
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
output,
|
|
7
|
+
ZodEffects,
|
|
8
|
+
ZodError,
|
|
9
|
+
ZodObject,
|
|
10
|
+
ZodRawShape,
|
|
11
|
+
ZodTypeAny,
|
|
12
|
+
} from "zod";
|
|
13
|
+
import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
|
|
14
|
+
import { ERR, OK, Result } from "../types/fp.js";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Utility function that executes some code which may throw a ZodError. It
|
|
18
|
+
* intercepts this error and converts it to an SDKValidationError so as to not
|
|
19
|
+
* leak Zod implementation details to user code.
|
|
20
|
+
*/
|
|
21
|
+
export function parse<Inp, Out>(
|
|
22
|
+
rawValue: Inp,
|
|
23
|
+
fn: (value: Inp) => Out,
|
|
24
|
+
errorMessage: string,
|
|
25
|
+
): Out {
|
|
26
|
+
try {
|
|
27
|
+
return fn(rawValue);
|
|
28
|
+
} catch (err) {
|
|
29
|
+
if (err instanceof ZodError) {
|
|
30
|
+
throw new SDKValidationError(errorMessage, err, rawValue);
|
|
31
|
+
}
|
|
32
|
+
throw err;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Utility function that executes some code which may result in a ZodError. It
|
|
38
|
+
* intercepts this error and converts it to an SDKValidationError so as to not
|
|
39
|
+
* leak Zod implementation details to user code.
|
|
40
|
+
*/
|
|
41
|
+
export function safeParse<Inp, Out>(
|
|
42
|
+
rawValue: Inp,
|
|
43
|
+
fn: (value: Inp) => Out,
|
|
44
|
+
errorMessage: string,
|
|
45
|
+
): Result<Out, SDKValidationError> {
|
|
46
|
+
try {
|
|
47
|
+
return OK(fn(rawValue));
|
|
48
|
+
} catch (err) {
|
|
49
|
+
return ERR(new SDKValidationError(errorMessage, err, rawValue));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function collectExtraKeys<
|
|
54
|
+
Shape extends ZodRawShape,
|
|
55
|
+
Catchall extends ZodTypeAny,
|
|
56
|
+
K extends string,
|
|
57
|
+
>(
|
|
58
|
+
obj: ZodObject<Shape, "strip", Catchall>,
|
|
59
|
+
extrasKey: K,
|
|
60
|
+
): ZodEffects<
|
|
61
|
+
typeof obj,
|
|
62
|
+
& output<ZodObject<Shape, "strict">>
|
|
63
|
+
& {
|
|
64
|
+
[k in K]: Record<string, output<Catchall>>;
|
|
65
|
+
}
|
|
66
|
+
> {
|
|
67
|
+
return obj.transform((val) => {
|
|
68
|
+
const extras: Record<string, output<Catchall>> = {};
|
|
69
|
+
const { shape } = obj;
|
|
70
|
+
for (const [key] of Object.entries(val)) {
|
|
71
|
+
if (key in shape) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const v = val[key];
|
|
76
|
+
if (typeof v === "undefined") {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
extras[key] = v;
|
|
81
|
+
delete val[key];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return { ...val, [extrasKey]: extras };
|
|
85
|
+
});
|
|
86
|
+
}
|