@financeable/aggregation 0.8.3 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/FUNCTIONS.md +153 -36
- package/README.md +475 -94
- package/docs/sdks/applications/README.md +9 -15
- package/docs/sdks/oauthtoken/README.md +5 -9
- package/docs/sdks/supportingdocuments/README.md +9 -16
- package/funcs/applicationsCreate.d.ts +3 -3
- package/funcs/applicationsCreate.d.ts.map +1 -1
- package/funcs/applicationsCreate.js +4 -6
- package/funcs/applicationsCreate.js.map +1 -1
- package/funcs/oauthTokenGet.d.ts +3 -2
- package/funcs/oauthTokenGet.d.ts.map +1 -1
- package/funcs/oauthTokenGet.js +4 -2
- package/funcs/oauthTokenGet.js.map +1 -1
- package/funcs/supportingDocumentsCreate.d.ts +3 -3
- package/funcs/supportingDocumentsCreate.d.ts.map +1 -1
- package/funcs/supportingDocumentsCreate.js +5 -8
- package/funcs/supportingDocumentsCreate.js.map +1 -1
- package/hooks/types.d.ts +2 -0
- package/hooks/types.d.ts.map +1 -1
- package/index.d.ts +2 -0
- package/index.d.ts.map +1 -1
- package/index.js +3 -1
- package/index.js.map +1 -1
- package/jsr.json +1 -1
- package/lib/config.d.ts +7 -3
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +3 -3
- package/lib/config.js.map +1 -1
- package/lib/files.d.ts +5 -0
- package/lib/files.d.ts.map +1 -1
- package/lib/files.js +41 -0
- package/lib/files.js.map +1 -1
- package/lib/matchers.d.ts +3 -10
- package/lib/matchers.d.ts.map +1 -1
- package/lib/matchers.js +33 -31
- package/lib/matchers.js.map +1 -1
- package/lib/sdks.d.ts +1 -0
- package/lib/sdks.d.ts.map +1 -1
- package/lib/sdks.js +3 -3
- package/lib/sdks.js.map +1 -1
- package/lib/security.d.ts +2 -2
- package/lib/security.d.ts.map +1 -1
- package/models/components/addressattributes.d.ts +8 -8
- package/models/components/addressattributes.d.ts.map +1 -1
- package/models/components/addressattributes.js +14 -13
- package/models/components/addressattributes.js.map +1 -1
- package/models/components/badrequesterror.d.ts +24 -24
- package/models/components/badrequesterror.d.ts.map +1 -1
- package/models/components/badrequesterror.js +37 -38
- package/models/components/badrequesterror.js.map +1 -1
- package/models/components/commercialsecuredapplicationpayload.d.ts +8 -8
- package/models/components/commercialsecuredapplicationpayload.d.ts.map +1 -1
- package/models/components/commercialsecuredapplicationpayload.js +13 -14
- package/models/components/commercialsecuredapplicationpayload.js.map +1 -1
- package/models/components/commercialsecuredloancommercialapplicationrelationships.d.ts +90 -90
- package/models/components/commercialsecuredloancommercialapplicationrelationships.d.ts.map +1 -1
- package/models/components/commercialsecuredloancommercialapplicationrelationships.js +116 -118
- package/models/components/commercialsecuredloancommercialapplicationrelationships.js.map +1 -1
- package/models/components/customerattributes.d.ts +6 -0
- package/models/components/customerattributes.d.ts.map +1 -1
- package/models/components/customerattributes.js +3 -0
- package/models/components/customerattributes.js.map +1 -1
- package/models/components/forbiddenerror.d.ts +16 -16
- package/models/components/forbiddenerror.d.ts.map +1 -1
- package/models/components/forbiddenerror.js +25 -25
- package/models/components/forbiddenerror.js.map +1 -1
- package/models/components/loandetailsattributes.d.ts +8 -8
- package/models/components/loandetailsattributes.d.ts.map +1 -1
- package/models/components/loandetailsattributes.js +8 -8
- package/models/components/loandetailsattributes.js.map +1 -1
- package/models/components/supportingdocumentrelationships.d.ts +45 -45
- package/models/components/supportingdocumentrelationships.d.ts.map +1 -1
- package/models/components/supportingdocumentrelationships.js +54 -54
- package/models/components/supportingdocumentrelationships.js.map +1 -1
- package/models/components/supportingdocumentresource.d.ts +8 -8
- package/models/components/supportingdocumentresource.d.ts.map +1 -1
- package/models/components/supportingdocumentresource.js +13 -13
- package/models/components/supportingdocumentresource.js.map +1 -1
- package/models/errors/apierror.d.ts +8 -6
- package/models/errors/apierror.d.ts.map +1 -1
- package/models/errors/apierror.js +23 -10
- package/models/errors/apierror.js.map +1 -1
- package/models/errors/financeableerror.d.ts +19 -0
- package/models/errors/financeableerror.d.ts.map +1 -0
- package/models/errors/financeableerror.js +20 -0
- package/models/errors/financeableerror.js.map +1 -0
- package/models/errors/index.d.ts +1 -2
- package/models/errors/index.d.ts.map +1 -1
- package/models/errors/index.js +1 -2
- package/models/errors/index.js.map +1 -1
- package/models/errors/responsevalidationerror.d.ts +26 -0
- package/models/errors/responsevalidationerror.d.ts.map +1 -0
- package/models/errors/responsevalidationerror.js +66 -0
- package/models/errors/responsevalidationerror.js.map +1 -0
- package/models/errors/sdkvalidationerror.d.ts +1 -0
- package/models/errors/sdkvalidationerror.d.ts.map +1 -1
- package/models/errors/sdkvalidationerror.js +14 -0
- package/models/errors/sdkvalidationerror.js.map +1 -1
- package/models/operations/createapplication.d.ts +107 -30
- package/models/operations/createapplication.d.ts.map +1 -1
- package/models/operations/createapplication.js +125 -44
- package/models/operations/createapplication.js.map +1 -1
- package/models/operations/supportingdocumentscreate.d.ts +144 -0
- package/models/operations/supportingdocumentscreate.d.ts.map +1 -1
- package/models/operations/supportingdocumentscreate.js +186 -1
- package/models/operations/supportingdocumentscreate.js.map +1 -1
- package/package.json +1 -1
- package/sdk/applications.d.ts +1 -1
- package/sdk/applications.d.ts.map +1 -1
- package/sdk/sdk.d.ts +2 -2
- package/sdk/sdk.d.ts.map +1 -1
- package/sdk/sdk.js +3 -3
- package/sdk/sdk.js.map +1 -1
- package/sdk/supportingdocuments.d.ts +1 -1
- package/sdk/supportingdocuments.d.ts.map +1 -1
- package/src/funcs/applicationsCreate.ts +30 -40
- package/src/funcs/oauthTokenGet.ts +24 -20
- package/src/funcs/supportingDocumentsCreate.ts +31 -42
- package/src/hooks/types.ts +2 -0
- package/src/index.ts +2 -0
- package/src/lib/config.ts +7 -3
- package/src/lib/files.ts +42 -0
- package/src/lib/matchers.ts +44 -41
- package/src/lib/sdks.ts +10 -4
- package/src/lib/security.ts +2 -2
- package/src/models/components/addressattributes.ts +14 -18
- package/src/models/components/badrequesterror.ts +48 -44
- package/src/models/components/commercialsecuredapplicationpayload.ts +15 -20
- package/src/models/components/commercialsecuredloancommercialapplicationrelationships.ts +178 -238
- package/src/models/components/customerattributes.ts +12 -0
- package/src/models/components/forbiddenerror.ts +30 -32
- package/src/models/components/loandetailsattributes.ts +16 -16
- package/src/models/components/supportingdocumentrelationships.ts +117 -82
- package/src/models/components/supportingdocumentresource.ts +18 -15
- package/src/models/errors/apierror.ts +29 -16
- package/src/models/errors/financeableerror.ts +35 -0
- package/src/models/errors/index.ts +1 -2
- package/src/models/errors/responsevalidationerror.ts +50 -0
- package/src/models/errors/sdkvalidationerror.ts +12 -0
- package/src/models/operations/createapplication.ts +299 -64
- package/src/models/operations/supportingdocumentscreate.ts +386 -0
- package/src/sdk/applications.ts +1 -1
- package/src/sdk/sdk.ts +7 -7
- package/src/sdk/supportingdocuments.ts +1 -1
- package/src/types/constdatetime.ts +1 -1
- package/types/constdatetime.js +1 -1
- package/models/errors/createapplication.d.ts +0 -73
- package/models/errors/createapplication.d.ts.map +0 -1
- package/models/errors/createapplication.js +0 -120
- package/models/errors/createapplication.js.map +0 -1
- package/models/errors/supportingdocumentscreate.d.ts +0 -143
- package/models/errors/supportingdocumentscreate.d.ts.map +0 -1
- package/models/errors/supportingdocumentscreate.js +0 -225
- package/models/errors/supportingdocumentscreate.js.map +0 -1
- package/src/models/errors/createapplication.ts +0 -149
- package/src/models/errors/supportingdocumentscreate.ts +0 -342
|
@@ -10,7 +10,7 @@ import { safeParse } from "../lib/schemas.js";
|
|
|
10
10
|
import { RequestOptions } from "../lib/sdks.js";
|
|
11
11
|
import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js";
|
|
12
12
|
import { pathToFunc } from "../lib/url.js";
|
|
13
|
-
import {
|
|
13
|
+
import { FinanceableError } from "../models/errors/financeableerror.js";
|
|
14
14
|
import {
|
|
15
15
|
ConnectionError,
|
|
16
16
|
InvalidRequestError,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
RequestTimeoutError,
|
|
19
19
|
UnexpectedClientError,
|
|
20
20
|
} from "../models/errors/httpclienterrors.js";
|
|
21
|
-
import
|
|
21
|
+
import { ResponseValidationError } from "../models/errors/responsevalidationerror.js";
|
|
22
22
|
import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
|
|
23
23
|
import * as operations from "../models/operations/index.js";
|
|
24
24
|
import { APICall, APIPromise } from "../types/async.js";
|
|
@@ -33,16 +33,15 @@ export function supportingDocumentsCreate(
|
|
|
33
33
|
options?: RequestOptions,
|
|
34
34
|
): APIPromise<
|
|
35
35
|
Result<
|
|
36
|
-
operations.
|
|
37
|
-
|
|
|
38
|
-
|
|
|
39
|
-
|
|
|
40
|
-
| SDKValidationError
|
|
41
|
-
| UnexpectedClientError
|
|
42
|
-
| InvalidRequestError
|
|
36
|
+
operations.SupportingDocumentsCreateResponse,
|
|
37
|
+
| FinanceableError
|
|
38
|
+
| ResponseValidationError
|
|
39
|
+
| ConnectionError
|
|
43
40
|
| RequestAbortedError
|
|
44
41
|
| RequestTimeoutError
|
|
45
|
-
|
|
|
42
|
+
| InvalidRequestError
|
|
43
|
+
| UnexpectedClientError
|
|
44
|
+
| SDKValidationError
|
|
46
45
|
>
|
|
47
46
|
> {
|
|
48
47
|
return new APIPromise($do(
|
|
@@ -59,16 +58,15 @@ async function $do(
|
|
|
59
58
|
): Promise<
|
|
60
59
|
[
|
|
61
60
|
Result<
|
|
62
|
-
operations.
|
|
63
|
-
|
|
|
64
|
-
|
|
|
65
|
-
|
|
|
66
|
-
| SDKValidationError
|
|
67
|
-
| UnexpectedClientError
|
|
68
|
-
| InvalidRequestError
|
|
61
|
+
operations.SupportingDocumentsCreateResponse,
|
|
62
|
+
| FinanceableError
|
|
63
|
+
| ResponseValidationError
|
|
64
|
+
| ConnectionError
|
|
69
65
|
| RequestAbortedError
|
|
70
66
|
| RequestTimeoutError
|
|
71
|
-
|
|
|
67
|
+
| InvalidRequestError
|
|
68
|
+
| UnexpectedClientError
|
|
69
|
+
| SDKValidationError
|
|
72
70
|
>,
|
|
73
71
|
APICall,
|
|
74
72
|
]
|
|
@@ -85,7 +83,7 @@ async function $do(
|
|
|
85
83
|
const payload = parsed.value;
|
|
86
84
|
const body = encodeJSON("body", payload.RequestBody, { explode: true });
|
|
87
85
|
|
|
88
|
-
const path = pathToFunc("/")();
|
|
86
|
+
const path = pathToFunc("/supporting-documents")();
|
|
89
87
|
|
|
90
88
|
const query = encodeFormQuery({
|
|
91
89
|
"mimeType": payload.mimeType,
|
|
@@ -103,6 +101,7 @@ async function $do(
|
|
|
103
101
|
const requestSecurity = resolveGlobalSecurity(securityInput);
|
|
104
102
|
|
|
105
103
|
const context = {
|
|
104
|
+
options: client._options,
|
|
106
105
|
baseURL: options?.serverURL ?? client._baseURL ?? "",
|
|
107
106
|
operationID: "SupportingDocuments_create",
|
|
108
107
|
oAuth2Scopes: [],
|
|
@@ -124,6 +123,7 @@ async function $do(
|
|
|
124
123
|
headers: headers,
|
|
125
124
|
query: query,
|
|
126
125
|
body: body,
|
|
126
|
+
userAgent: client._options.userAgent,
|
|
127
127
|
timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
|
|
128
128
|
}, options);
|
|
129
129
|
if (!requestRes.ok) {
|
|
@@ -133,7 +133,7 @@ async function $do(
|
|
|
133
133
|
|
|
134
134
|
const doResult = await client._do(req, {
|
|
135
135
|
context,
|
|
136
|
-
errorCodes: [
|
|
136
|
+
errorCodes: [],
|
|
137
137
|
retryConfig: context.retryConfig,
|
|
138
138
|
retryCodes: context.retryCodes,
|
|
139
139
|
});
|
|
@@ -142,32 +142,21 @@ async function $do(
|
|
|
142
142
|
}
|
|
143
143
|
const response = doResult.value;
|
|
144
144
|
|
|
145
|
-
const responseFields = {
|
|
146
|
-
HttpMeta: { Response: response, Request: req },
|
|
147
|
-
};
|
|
148
|
-
|
|
149
145
|
const [result] = await M.match<
|
|
150
|
-
operations.
|
|
151
|
-
|
|
|
152
|
-
|
|
|
153
|
-
|
|
|
154
|
-
| SDKValidationError
|
|
155
|
-
| UnexpectedClientError
|
|
156
|
-
| InvalidRequestError
|
|
146
|
+
operations.SupportingDocumentsCreateResponse,
|
|
147
|
+
| FinanceableError
|
|
148
|
+
| ResponseValidationError
|
|
149
|
+
| ConnectionError
|
|
157
150
|
| RequestAbortedError
|
|
158
151
|
| RequestTimeoutError
|
|
159
|
-
|
|
|
152
|
+
| InvalidRequestError
|
|
153
|
+
| UnexpectedClientError
|
|
154
|
+
| SDKValidationError
|
|
160
155
|
>(
|
|
161
|
-
M.json(201, operations.
|
|
162
|
-
M.
|
|
163
|
-
M.
|
|
164
|
-
|
|
165
|
-
errors
|
|
166
|
-
.SupportingDocumentsCreateSupportingDocumentsResponseBody$inboundSchema,
|
|
167
|
-
),
|
|
168
|
-
M.fail("4XX"),
|
|
169
|
-
M.fail("5XX"),
|
|
170
|
-
)(response, { extraFields: responseFields });
|
|
156
|
+
M.json(201, operations.SupportingDocumentsCreateResponse$inboundSchema),
|
|
157
|
+
M.json(400, operations.SupportingDocumentsCreateResponse$inboundSchema),
|
|
158
|
+
M.json(404, operations.SupportingDocumentsCreateResponse$inboundSchema),
|
|
159
|
+
)(response, req);
|
|
171
160
|
if (!result.ok) {
|
|
172
161
|
return [result, { status: "complete", request: req, response }];
|
|
173
162
|
}
|
package/src/hooks/types.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import { SDKOptions } from "../lib/config.js";
|
|
5
6
|
import { HTTPClient, RequestInput } from "../lib/http.js";
|
|
6
7
|
import { RetryConfig } from "../lib/retries.js";
|
|
7
8
|
import { SecurityState } from "../lib/security.js";
|
|
@@ -13,6 +14,7 @@ export type HookContext = {
|
|
|
13
14
|
securitySource?: any | (() => Promise<any>);
|
|
14
15
|
retryConfig: RetryConfig;
|
|
15
16
|
resolvedSecurity: SecurityState | null;
|
|
17
|
+
options: SDKOptions;
|
|
16
18
|
};
|
|
17
19
|
|
|
18
20
|
export type Awaitable<T> = T | Promise<T>;
|
package/src/index.ts
CHANGED
package/src/lib/config.ts
CHANGED
|
@@ -26,6 +26,10 @@ export type SDKOptions = {
|
|
|
26
26
|
* Allows overriding the default server URL used by the SDK
|
|
27
27
|
*/
|
|
28
28
|
serverURL?: string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Allows overriding the default user agent used by the SDK
|
|
31
|
+
*/
|
|
32
|
+
userAgent?: string | undefined;
|
|
29
33
|
/**
|
|
30
34
|
* Allows overriding the default retry config used by the SDK
|
|
31
35
|
*/
|
|
@@ -54,8 +58,8 @@ export function serverURLFromOptions(options: SDKOptions): URL | null {
|
|
|
54
58
|
export const SDK_METADATA = {
|
|
55
59
|
language: "typescript",
|
|
56
60
|
openapiDocVersion: "0.4.0",
|
|
57
|
-
sdkVersion: "0.
|
|
58
|
-
genVersion: "2.
|
|
61
|
+
sdkVersion: "0.9.0",
|
|
62
|
+
genVersion: "2.647.2",
|
|
59
63
|
userAgent:
|
|
60
|
-
"speakeasy-sdk/typescript 0.
|
|
64
|
+
"speakeasy-sdk/typescript 0.9.0 2.647.2 0.4.0 @financeable/aggregation",
|
|
61
65
|
} as const;
|
package/src/lib/files.ts
CHANGED
|
@@ -38,3 +38,45 @@ export async function readableStreamToArrayBuffer(
|
|
|
38
38
|
|
|
39
39
|
return concatenatedChunks.buffer as ArrayBuffer;
|
|
40
40
|
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Determines the MIME content type based on a file's extension.
|
|
44
|
+
* Returns null if the extension is not recognized.
|
|
45
|
+
*/
|
|
46
|
+
export function getContentTypeFromFileName(fileName: string): string | null {
|
|
47
|
+
if (!fileName) return null;
|
|
48
|
+
|
|
49
|
+
const ext = fileName.toLowerCase().split(".").pop();
|
|
50
|
+
if (!ext) return null;
|
|
51
|
+
|
|
52
|
+
const mimeTypes: Record<string, string> = {
|
|
53
|
+
json: "application/json",
|
|
54
|
+
xml: "application/xml",
|
|
55
|
+
html: "text/html",
|
|
56
|
+
htm: "text/html",
|
|
57
|
+
txt: "text/plain",
|
|
58
|
+
csv: "text/csv",
|
|
59
|
+
pdf: "application/pdf",
|
|
60
|
+
png: "image/png",
|
|
61
|
+
jpg: "image/jpeg",
|
|
62
|
+
jpeg: "image/jpeg",
|
|
63
|
+
gif: "image/gif",
|
|
64
|
+
svg: "image/svg+xml",
|
|
65
|
+
js: "application/javascript",
|
|
66
|
+
css: "text/css",
|
|
67
|
+
zip: "application/zip",
|
|
68
|
+
tar: "application/x-tar",
|
|
69
|
+
gz: "application/gzip",
|
|
70
|
+
mp4: "video/mp4",
|
|
71
|
+
mp3: "audio/mpeg",
|
|
72
|
+
wav: "audio/wav",
|
|
73
|
+
webp: "image/webp",
|
|
74
|
+
ico: "image/x-icon",
|
|
75
|
+
woff: "font/woff",
|
|
76
|
+
woff2: "font/woff2",
|
|
77
|
+
ttf: "font/ttf",
|
|
78
|
+
otf: "font/otf",
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return mimeTypes[ext] || null;
|
|
82
|
+
}
|
package/src/lib/matchers.ts
CHANGED
|
@@ -3,11 +3,10 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { APIError } from "../models/errors/apierror.js";
|
|
6
|
-
import {
|
|
7
|
-
import { Result } from "../types/fp.js";
|
|
6
|
+
import { ResponseValidationError } from "../models/errors/responsevalidationerror.js";
|
|
7
|
+
import { ERR, OK, Result } from "../types/fp.js";
|
|
8
8
|
import { matchResponse, matchStatusCode, StatusCodePredicate } from "./http.js";
|
|
9
9
|
import { isPlainObject } from "./is-plain-object.js";
|
|
10
|
-
import { safeParse } from "./schemas.js";
|
|
11
10
|
|
|
12
11
|
export type Encoding =
|
|
13
12
|
| "jsonl"
|
|
@@ -176,17 +175,19 @@ export type MatchedError<Matchers> = Matchers extends Matcher<any, infer E>[]
|
|
|
176
175
|
: never;
|
|
177
176
|
export type MatchFunc<T, E> = (
|
|
178
177
|
response: Response,
|
|
178
|
+
request: Request,
|
|
179
179
|
options?: { resultKey?: string; extraFields?: Record<string, unknown> },
|
|
180
180
|
) => Promise<[result: Result<T, E>, raw: unknown]>;
|
|
181
181
|
|
|
182
182
|
export function match<T, E>(
|
|
183
183
|
...matchers: Array<Matcher<T, E>>
|
|
184
|
-
): MatchFunc<T, E | APIError |
|
|
184
|
+
): MatchFunc<T, E | APIError | ResponseValidationError> {
|
|
185
185
|
return async function matchFunc(
|
|
186
186
|
response: Response,
|
|
187
|
+
request: Request,
|
|
187
188
|
options?: { resultKey?: string; extraFields?: Record<string, unknown> },
|
|
188
189
|
): Promise<
|
|
189
|
-
[result: Result<T, E | APIError |
|
|
190
|
+
[result: Result<T, E | APIError | ResponseValidationError>, raw: unknown]
|
|
190
191
|
> {
|
|
191
192
|
let raw: unknown;
|
|
192
193
|
let matcher: Matcher<T, E> | undefined;
|
|
@@ -205,21 +206,22 @@ export function match<T, E>(
|
|
|
205
206
|
}
|
|
206
207
|
|
|
207
208
|
if (!matcher) {
|
|
208
|
-
const responseBody = await response.text();
|
|
209
209
|
return [{
|
|
210
210
|
ok: false,
|
|
211
|
-
error: new APIError(
|
|
212
|
-
"Unexpected API response status or content-type",
|
|
211
|
+
error: new APIError("Unexpected Status or Content-Type", {
|
|
213
212
|
response,
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
213
|
+
request,
|
|
214
|
+
body: await response.text().catch(() => ""),
|
|
215
|
+
}),
|
|
216
|
+
}, raw];
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
const encoding = matcher.enc;
|
|
220
|
+
let body = "";
|
|
220
221
|
switch (encoding) {
|
|
221
222
|
case "json":
|
|
222
|
-
|
|
223
|
+
body = await response.text();
|
|
224
|
+
raw = JSON.parse(body);
|
|
223
225
|
break;
|
|
224
226
|
case "jsonl":
|
|
225
227
|
raw = response.body;
|
|
@@ -231,16 +233,19 @@ export function match<T, E>(
|
|
|
231
233
|
raw = response.body;
|
|
232
234
|
break;
|
|
233
235
|
case "text":
|
|
234
|
-
|
|
236
|
+
body = await response.text();
|
|
237
|
+
raw = body;
|
|
235
238
|
break;
|
|
236
239
|
case "sse":
|
|
237
240
|
raw = response.body;
|
|
238
241
|
break;
|
|
239
242
|
case "nil":
|
|
240
|
-
|
|
243
|
+
body = await response.text();
|
|
244
|
+
raw = undefined;
|
|
241
245
|
break;
|
|
242
246
|
case "fail":
|
|
243
|
-
|
|
247
|
+
body = await response.text();
|
|
248
|
+
raw = body;
|
|
244
249
|
break;
|
|
245
250
|
default:
|
|
246
251
|
encoding satisfies never;
|
|
@@ -250,11 +255,7 @@ export function match<T, E>(
|
|
|
250
255
|
if (matcher.enc === "fail") {
|
|
251
256
|
return [{
|
|
252
257
|
ok: false,
|
|
253
|
-
error: new APIError(
|
|
254
|
-
"API error occurred",
|
|
255
|
-
response,
|
|
256
|
-
typeof raw === "string" ? raw : "",
|
|
257
|
-
),
|
|
258
|
+
error: new APIError("API error occurred", { request, response, body }),
|
|
258
259
|
}, raw];
|
|
259
260
|
}
|
|
260
261
|
|
|
@@ -266,6 +267,9 @@ export function match<T, E>(
|
|
|
266
267
|
...options?.extraFields,
|
|
267
268
|
...(matcher.hdrs ? { Headers: unpackHeaders(response.headers) } : null),
|
|
268
269
|
...(isPlainObject(raw) ? raw : null),
|
|
270
|
+
request$: request,
|
|
271
|
+
response$: response,
|
|
272
|
+
body$: body,
|
|
269
273
|
};
|
|
270
274
|
} else if (resultKey) {
|
|
271
275
|
data = {
|
|
@@ -284,18 +288,20 @@ export function match<T, E>(
|
|
|
284
288
|
}
|
|
285
289
|
|
|
286
290
|
if ("err" in matcher) {
|
|
287
|
-
const result =
|
|
291
|
+
const result = safeParseResponse(
|
|
288
292
|
data,
|
|
289
293
|
(v: unknown) => matcher.schema.parse(v),
|
|
290
294
|
"Response validation failed",
|
|
295
|
+
{ request, response, body },
|
|
291
296
|
);
|
|
292
297
|
return [result.ok ? { ok: false, error: result.value } : result, raw];
|
|
293
298
|
} else {
|
|
294
299
|
return [
|
|
295
|
-
|
|
300
|
+
safeParseResponse(
|
|
296
301
|
data,
|
|
297
302
|
(v: unknown) => matcher.schema.parse(v),
|
|
298
303
|
"Response validation failed",
|
|
304
|
+
{ request, response, body },
|
|
299
305
|
),
|
|
300
306
|
raw,
|
|
301
307
|
];
|
|
@@ -318,25 +324,22 @@ export function unpackHeaders(headers: Headers): Record<string, string[]> {
|
|
|
318
324
|
return out;
|
|
319
325
|
}
|
|
320
326
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
export async function discardResponseBody(res: Response) {
|
|
328
|
-
const reader = res.body?.getReader();
|
|
329
|
-
if (reader == null) {
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
|
|
327
|
+
function safeParseResponse<Inp, Out>(
|
|
328
|
+
rawValue: Inp,
|
|
329
|
+
fn: (value: Inp) => Out,
|
|
330
|
+
errorMessage: string,
|
|
331
|
+
httpMeta: { response: Response; request: Request; body: string },
|
|
332
|
+
): Result<Out, ResponseValidationError> {
|
|
333
333
|
try {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
334
|
+
return OK(fn(rawValue));
|
|
335
|
+
} catch (err) {
|
|
336
|
+
return ERR(
|
|
337
|
+
new ResponseValidationError(errorMessage, {
|
|
338
|
+
cause: err,
|
|
339
|
+
rawValue,
|
|
340
|
+
rawMessage: errorMessage,
|
|
341
|
+
...httpMeta,
|
|
342
|
+
}),
|
|
343
|
+
);
|
|
341
344
|
}
|
|
342
345
|
}
|
package/src/lib/sdks.ts
CHANGED
|
@@ -65,6 +65,7 @@ type RequestConfig = {
|
|
|
65
65
|
headers?: HeadersInit;
|
|
66
66
|
security?: SecurityState | null;
|
|
67
67
|
uaHeader?: string;
|
|
68
|
+
userAgent?: string | undefined;
|
|
68
69
|
timeoutMs?: number;
|
|
69
70
|
};
|
|
70
71
|
|
|
@@ -96,19 +97,21 @@ export class ClientSDK {
|
|
|
96
97
|
} else {
|
|
97
98
|
this.#hooks = new SDKHooks();
|
|
98
99
|
}
|
|
99
|
-
this._options = { ...options, hooks: this.#hooks };
|
|
100
|
-
|
|
101
100
|
const url = serverURLFromOptions(options);
|
|
102
101
|
if (url) {
|
|
103
102
|
url.pathname = url.pathname.replace(/\/+$/, "") + "/";
|
|
104
103
|
}
|
|
104
|
+
|
|
105
105
|
const { baseURL, client } = this.#hooks.sdkInit({
|
|
106
106
|
baseURL: url,
|
|
107
107
|
client: options.httpClient || new HTTPClient(),
|
|
108
108
|
});
|
|
109
109
|
this._baseURL = baseURL;
|
|
110
110
|
this.#httpClient = client;
|
|
111
|
-
|
|
111
|
+
|
|
112
|
+
this._options = { ...options, hooks: this.#hooks };
|
|
113
|
+
|
|
114
|
+
this.#logger = this._options.debugLogger;
|
|
112
115
|
if (!this.#logger && env().FINANCEABLE_DEBUG) {
|
|
113
116
|
this.#logger = console;
|
|
114
117
|
}
|
|
@@ -184,7 +187,10 @@ export class ClientSDK {
|
|
|
184
187
|
// Only set user agent header in non-browser-like environments since CORS
|
|
185
188
|
// policy disallows setting it in browsers e.g. Chrome throws an error.
|
|
186
189
|
if (!isBrowserLike) {
|
|
187
|
-
headers.set(
|
|
190
|
+
headers.set(
|
|
191
|
+
conf.uaHeader ?? "user-agent",
|
|
192
|
+
conf.userAgent ?? SDK_METADATA.userAgent,
|
|
193
|
+
);
|
|
188
194
|
}
|
|
189
195
|
|
|
190
196
|
const fetchOptions: Omit<RequestInit, "method" | "body"> = {
|
package/src/lib/security.ts
CHANGED
|
@@ -13,13 +13,11 @@ import {
|
|
|
13
13
|
AustralianStatesAndTerritories$outboundSchema,
|
|
14
14
|
} from "./australianstatesandterritories.js";
|
|
15
15
|
|
|
16
|
-
export const
|
|
16
|
+
export const Status = {
|
|
17
17
|
Current: "current",
|
|
18
18
|
Previous: "previous",
|
|
19
19
|
} as const;
|
|
20
|
-
export type
|
|
21
|
-
typeof AddressAttributesStatus
|
|
22
|
-
>;
|
|
20
|
+
export type Status = ClosedEnum<typeof Status>;
|
|
23
21
|
|
|
24
22
|
export type AddressAttributes = {
|
|
25
23
|
id?: string | undefined;
|
|
@@ -35,30 +33,28 @@ export type AddressAttributes = {
|
|
|
35
33
|
street: string;
|
|
36
34
|
state: AustralianStatesAndTerritories;
|
|
37
35
|
country: string;
|
|
38
|
-
status:
|
|
36
|
+
status: Status;
|
|
39
37
|
monthsAt?: number | undefined;
|
|
40
38
|
yearsAt?: number | undefined;
|
|
41
39
|
};
|
|
42
40
|
|
|
43
41
|
/** @internal */
|
|
44
|
-
export const
|
|
45
|
-
|
|
46
|
-
> = z.nativeEnum(AddressAttributesStatus);
|
|
42
|
+
export const Status$inboundSchema: z.ZodNativeEnum<typeof Status> = z
|
|
43
|
+
.nativeEnum(Status);
|
|
47
44
|
|
|
48
45
|
/** @internal */
|
|
49
|
-
export const
|
|
50
|
-
|
|
51
|
-
> = AddressAttributesStatus$inboundSchema;
|
|
46
|
+
export const Status$outboundSchema: z.ZodNativeEnum<typeof Status> =
|
|
47
|
+
Status$inboundSchema;
|
|
52
48
|
|
|
53
49
|
/**
|
|
54
50
|
* @internal
|
|
55
51
|
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
|
|
56
52
|
*/
|
|
57
|
-
export namespace
|
|
58
|
-
/** @deprecated use `
|
|
59
|
-
export const inboundSchema =
|
|
60
|
-
/** @deprecated use `
|
|
61
|
-
export const outboundSchema =
|
|
53
|
+
export namespace Status$ {
|
|
54
|
+
/** @deprecated use `Status$inboundSchema` instead. */
|
|
55
|
+
export const inboundSchema = Status$inboundSchema;
|
|
56
|
+
/** @deprecated use `Status$outboundSchema` instead. */
|
|
57
|
+
export const outboundSchema = Status$outboundSchema;
|
|
62
58
|
}
|
|
63
59
|
|
|
64
60
|
/** @internal */
|
|
@@ -80,7 +76,7 @@ export const AddressAttributes$inboundSchema: z.ZodType<
|
|
|
80
76
|
street: z.string(),
|
|
81
77
|
state: AustralianStatesAndTerritories$inboundSchema,
|
|
82
78
|
country: z.string(),
|
|
83
|
-
status:
|
|
79
|
+
status: Status$inboundSchema,
|
|
84
80
|
monthsAt: z.number().int().optional(),
|
|
85
81
|
yearsAt: z.number().int().optional(),
|
|
86
82
|
});
|
|
@@ -124,7 +120,7 @@ export const AddressAttributes$outboundSchema: z.ZodType<
|
|
|
124
120
|
street: z.string(),
|
|
125
121
|
state: AustralianStatesAndTerritories$outboundSchema,
|
|
126
122
|
country: z.string(),
|
|
127
|
-
status:
|
|
123
|
+
status: Status$outboundSchema,
|
|
128
124
|
monthsAt: z.number().int().optional(),
|
|
129
125
|
yearsAt: z.number().int().optional(),
|
|
130
126
|
});
|