@financeable/aggregation 0.8.3 → 0.9.1

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.
Files changed (156) hide show
  1. package/FUNCTIONS.md +153 -36
  2. package/README.md +475 -94
  3. package/docs/sdks/applications/README.md +9 -15
  4. package/docs/sdks/oauthtoken/README.md +5 -9
  5. package/docs/sdks/supportingdocuments/README.md +9 -16
  6. package/funcs/applicationsCreate.d.ts +3 -3
  7. package/funcs/applicationsCreate.d.ts.map +1 -1
  8. package/funcs/applicationsCreate.js +4 -6
  9. package/funcs/applicationsCreate.js.map +1 -1
  10. package/funcs/oauthTokenGet.d.ts +3 -2
  11. package/funcs/oauthTokenGet.d.ts.map +1 -1
  12. package/funcs/oauthTokenGet.js +4 -2
  13. package/funcs/oauthTokenGet.js.map +1 -1
  14. package/funcs/supportingDocumentsCreate.d.ts +3 -3
  15. package/funcs/supportingDocumentsCreate.d.ts.map +1 -1
  16. package/funcs/supportingDocumentsCreate.js +5 -8
  17. package/funcs/supportingDocumentsCreate.js.map +1 -1
  18. package/hooks/types.d.ts +2 -0
  19. package/hooks/types.d.ts.map +1 -1
  20. package/index.d.ts +2 -0
  21. package/index.d.ts.map +1 -1
  22. package/index.js +3 -1
  23. package/index.js.map +1 -1
  24. package/jsr.json +1 -1
  25. package/lib/config.d.ts +7 -3
  26. package/lib/config.d.ts.map +1 -1
  27. package/lib/config.js +3 -3
  28. package/lib/config.js.map +1 -1
  29. package/lib/files.d.ts +5 -0
  30. package/lib/files.d.ts.map +1 -1
  31. package/lib/files.js +41 -0
  32. package/lib/files.js.map +1 -1
  33. package/lib/matchers.d.ts +3 -10
  34. package/lib/matchers.d.ts.map +1 -1
  35. package/lib/matchers.js +33 -31
  36. package/lib/matchers.js.map +1 -1
  37. package/lib/sdks.d.ts +1 -0
  38. package/lib/sdks.d.ts.map +1 -1
  39. package/lib/sdks.js +3 -3
  40. package/lib/sdks.js.map +1 -1
  41. package/lib/security.d.ts +2 -2
  42. package/lib/security.d.ts.map +1 -1
  43. package/models/components/addressattributes.d.ts +8 -8
  44. package/models/components/addressattributes.d.ts.map +1 -1
  45. package/models/components/addressattributes.js +14 -13
  46. package/models/components/addressattributes.js.map +1 -1
  47. package/models/components/badrequesterror.d.ts +24 -24
  48. package/models/components/badrequesterror.d.ts.map +1 -1
  49. package/models/components/badrequesterror.js +37 -38
  50. package/models/components/badrequesterror.js.map +1 -1
  51. package/models/components/commercialsecuredapplicationpayload.d.ts +8 -8
  52. package/models/components/commercialsecuredapplicationpayload.d.ts.map +1 -1
  53. package/models/components/commercialsecuredapplicationpayload.js +13 -14
  54. package/models/components/commercialsecuredapplicationpayload.js.map +1 -1
  55. package/models/components/commercialsecuredloancommercialapplicationrelationships.d.ts +90 -90
  56. package/models/components/commercialsecuredloancommercialapplicationrelationships.d.ts.map +1 -1
  57. package/models/components/commercialsecuredloancommercialapplicationrelationships.js +116 -118
  58. package/models/components/commercialsecuredloancommercialapplicationrelationships.js.map +1 -1
  59. package/models/components/customerattributes.d.ts +12 -1
  60. package/models/components/customerattributes.d.ts.map +1 -1
  61. package/models/components/customerattributes.js +5 -0
  62. package/models/components/customerattributes.js.map +1 -1
  63. package/models/components/forbiddenerror.d.ts +16 -16
  64. package/models/components/forbiddenerror.d.ts.map +1 -1
  65. package/models/components/forbiddenerror.js +25 -25
  66. package/models/components/forbiddenerror.js.map +1 -1
  67. package/models/components/loandetailsattributes.d.ts +8 -8
  68. package/models/components/loandetailsattributes.d.ts.map +1 -1
  69. package/models/components/loandetailsattributes.js +8 -8
  70. package/models/components/loandetailsattributes.js.map +1 -1
  71. package/models/components/supportingdocumentrelationships.d.ts +45 -45
  72. package/models/components/supportingdocumentrelationships.d.ts.map +1 -1
  73. package/models/components/supportingdocumentrelationships.js +54 -54
  74. package/models/components/supportingdocumentrelationships.js.map +1 -1
  75. package/models/components/supportingdocumentresource.d.ts +8 -8
  76. package/models/components/supportingdocumentresource.d.ts.map +1 -1
  77. package/models/components/supportingdocumentresource.js +13 -13
  78. package/models/components/supportingdocumentresource.js.map +1 -1
  79. package/models/errors/apierror.d.ts +8 -6
  80. package/models/errors/apierror.d.ts.map +1 -1
  81. package/models/errors/apierror.js +23 -10
  82. package/models/errors/apierror.js.map +1 -1
  83. package/models/errors/financeableerror.d.ts +19 -0
  84. package/models/errors/financeableerror.d.ts.map +1 -0
  85. package/models/errors/financeableerror.js +20 -0
  86. package/models/errors/financeableerror.js.map +1 -0
  87. package/models/errors/index.d.ts +1 -2
  88. package/models/errors/index.d.ts.map +1 -1
  89. package/models/errors/index.js +1 -2
  90. package/models/errors/index.js.map +1 -1
  91. package/models/errors/responsevalidationerror.d.ts +26 -0
  92. package/models/errors/responsevalidationerror.d.ts.map +1 -0
  93. package/models/errors/responsevalidationerror.js +66 -0
  94. package/models/errors/responsevalidationerror.js.map +1 -0
  95. package/models/errors/sdkvalidationerror.d.ts +1 -0
  96. package/models/errors/sdkvalidationerror.d.ts.map +1 -1
  97. package/models/errors/sdkvalidationerror.js +14 -0
  98. package/models/errors/sdkvalidationerror.js.map +1 -1
  99. package/models/operations/createapplication.d.ts +107 -30
  100. package/models/operations/createapplication.d.ts.map +1 -1
  101. package/models/operations/createapplication.js +125 -44
  102. package/models/operations/createapplication.js.map +1 -1
  103. package/models/operations/supportingdocumentscreate.d.ts +144 -0
  104. package/models/operations/supportingdocumentscreate.d.ts.map +1 -1
  105. package/models/operations/supportingdocumentscreate.js +186 -1
  106. package/models/operations/supportingdocumentscreate.js.map +1 -1
  107. package/package.json +1 -1
  108. package/sdk/applications.d.ts +1 -1
  109. package/sdk/applications.d.ts.map +1 -1
  110. package/sdk/sdk.d.ts +2 -2
  111. package/sdk/sdk.d.ts.map +1 -1
  112. package/sdk/sdk.js +3 -3
  113. package/sdk/sdk.js.map +1 -1
  114. package/sdk/supportingdocuments.d.ts +1 -1
  115. package/sdk/supportingdocuments.d.ts.map +1 -1
  116. package/src/funcs/applicationsCreate.ts +30 -40
  117. package/src/funcs/oauthTokenGet.ts +24 -20
  118. package/src/funcs/supportingDocumentsCreate.ts +31 -42
  119. package/src/hooks/types.ts +2 -0
  120. package/src/index.ts +2 -0
  121. package/src/lib/config.ts +7 -3
  122. package/src/lib/files.ts +42 -0
  123. package/src/lib/matchers.ts +44 -41
  124. package/src/lib/sdks.ts +10 -4
  125. package/src/lib/security.ts +2 -2
  126. package/src/models/components/addressattributes.ts +14 -18
  127. package/src/models/components/badrequesterror.ts +48 -44
  128. package/src/models/components/commercialsecuredapplicationpayload.ts +15 -20
  129. package/src/models/components/commercialsecuredloancommercialapplicationrelationships.ts +178 -238
  130. package/src/models/components/customerattributes.ts +20 -1
  131. package/src/models/components/forbiddenerror.ts +30 -32
  132. package/src/models/components/loandetailsattributes.ts +16 -16
  133. package/src/models/components/supportingdocumentrelationships.ts +117 -82
  134. package/src/models/components/supportingdocumentresource.ts +18 -15
  135. package/src/models/errors/apierror.ts +29 -16
  136. package/src/models/errors/financeableerror.ts +35 -0
  137. package/src/models/errors/index.ts +1 -2
  138. package/src/models/errors/responsevalidationerror.ts +50 -0
  139. package/src/models/errors/sdkvalidationerror.ts +12 -0
  140. package/src/models/operations/createapplication.ts +299 -64
  141. package/src/models/operations/supportingdocumentscreate.ts +386 -0
  142. package/src/sdk/applications.ts +1 -1
  143. package/src/sdk/sdk.ts +7 -7
  144. package/src/sdk/supportingdocuments.ts +1 -1
  145. package/src/types/constdatetime.ts +1 -1
  146. package/types/constdatetime.js +1 -1
  147. package/models/errors/createapplication.d.ts +0 -73
  148. package/models/errors/createapplication.d.ts.map +0 -1
  149. package/models/errors/createapplication.js +0 -120
  150. package/models/errors/createapplication.js.map +0 -1
  151. package/models/errors/supportingdocumentscreate.d.ts +0 -143
  152. package/models/errors/supportingdocumentscreate.d.ts.map +0 -1
  153. package/models/errors/supportingdocumentscreate.js +0 -225
  154. package/models/errors/supportingdocumentscreate.js.map +0 -1
  155. package/src/models/errors/createapplication.ts +0 -149
  156. 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 { APIError } from "../models/errors/apierror.js";
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 * as errors from "../models/errors/index.js";
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.SupportingDocumentsCreateResponseBody,
37
- | errors.SupportingDocumentsCreateResponseBody
38
- | errors.SupportingDocumentsCreateSupportingDocumentsResponseBody
39
- | APIError
40
- | SDKValidationError
41
- | UnexpectedClientError
42
- | InvalidRequestError
36
+ operations.SupportingDocumentsCreateResponse,
37
+ | FinanceableError
38
+ | ResponseValidationError
39
+ | ConnectionError
43
40
  | RequestAbortedError
44
41
  | RequestTimeoutError
45
- | ConnectionError
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.SupportingDocumentsCreateResponseBody,
63
- | errors.SupportingDocumentsCreateResponseBody
64
- | errors.SupportingDocumentsCreateSupportingDocumentsResponseBody
65
- | APIError
66
- | SDKValidationError
67
- | UnexpectedClientError
68
- | InvalidRequestError
61
+ operations.SupportingDocumentsCreateResponse,
62
+ | FinanceableError
63
+ | ResponseValidationError
64
+ | ConnectionError
69
65
  | RequestAbortedError
70
66
  | RequestTimeoutError
71
- | ConnectionError
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: ["400", "404", "4XX", "5XX"],
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.SupportingDocumentsCreateResponseBody,
151
- | errors.SupportingDocumentsCreateResponseBody
152
- | errors.SupportingDocumentsCreateSupportingDocumentsResponseBody
153
- | APIError
154
- | SDKValidationError
155
- | UnexpectedClientError
156
- | InvalidRequestError
146
+ operations.SupportingDocumentsCreateResponse,
147
+ | FinanceableError
148
+ | ResponseValidationError
149
+ | ConnectionError
157
150
  | RequestAbortedError
158
151
  | RequestTimeoutError
159
- | ConnectionError
152
+ | InvalidRequestError
153
+ | UnexpectedClientError
154
+ | SDKValidationError
160
155
  >(
161
- M.json(201, operations.SupportingDocumentsCreateResponseBody$inboundSchema),
162
- M.jsonErr(400, errors.SupportingDocumentsCreateResponseBody$inboundSchema),
163
- M.jsonErr(
164
- 404,
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
  }
@@ -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
@@ -4,4 +4,6 @@
4
4
 
5
5
  export * from "./lib/config.js";
6
6
  export * as files from "./lib/files.js";
7
+ export { HTTPClient } from "./lib/http.js";
8
+ export type { Fetcher, HTTPClientOptions } from "./lib/http.js";
7
9
  export * from "./sdk/sdk.js";
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.8.3",
58
- genVersion: "2.610.0",
61
+ sdkVersion: "0.9.1",
62
+ genVersion: "2.648.1",
59
63
  userAgent:
60
- "speakeasy-sdk/typescript 0.8.3 2.610.0 0.4.0 @financeable/aggregation",
64
+ "speakeasy-sdk/typescript 0.9.1 2.648.1 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
+ }
@@ -3,11 +3,10 @@
3
3
  */
4
4
 
5
5
  import { APIError } from "../models/errors/apierror.js";
6
- import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
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 | SDKValidationError> {
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 | SDKValidationError>, raw: unknown]
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
- responseBody,
215
- ),
216
- }, responseBody];
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
- raw = await response.json();
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
- raw = await response.text();
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
- raw = await discardResponseBody(response);
243
+ body = await response.text();
244
+ raw = undefined;
241
245
  break;
242
246
  case "fail":
243
- raw = await response.text();
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 = safeParse(
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
- safeParse(
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
- * Discards the response body to free up resources.
323
- *
324
- * To learn why this is need, see the undici docs:
325
- * https://undici.nodejs.org/#/?id=garbage-collection
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
- let done = false;
335
- while (!done) {
336
- const res = await reader.read();
337
- done = res.done;
338
- }
339
- } finally {
340
- reader.releaseLock();
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
- this.#logger = options.debugLogger;
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(conf.uaHeader ?? "user-agent", SDK_METADATA.userAgent);
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"> = {
@@ -7,8 +7,8 @@ import { env } from "./env.js";
7
7
 
8
8
  type OAuth2PasswordFlow = {
9
9
  username: string;
10
- password?: string | undefined;
11
- clientID: string;
10
+ password: string;
11
+ clientID?: string | undefined;
12
12
  clientSecret?: string | undefined;
13
13
  tokenURL: string;
14
14
  };
@@ -13,13 +13,11 @@ import {
13
13
  AustralianStatesAndTerritories$outboundSchema,
14
14
  } from "./australianstatesandterritories.js";
15
15
 
16
- export const AddressAttributesStatus = {
16
+ export const Status = {
17
17
  Current: "current",
18
18
  Previous: "previous",
19
19
  } as const;
20
- export type AddressAttributesStatus = ClosedEnum<
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: AddressAttributesStatus;
36
+ status: Status;
39
37
  monthsAt?: number | undefined;
40
38
  yearsAt?: number | undefined;
41
39
  };
42
40
 
43
41
  /** @internal */
44
- export const AddressAttributesStatus$inboundSchema: z.ZodNativeEnum<
45
- typeof AddressAttributesStatus
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 AddressAttributesStatus$outboundSchema: z.ZodNativeEnum<
50
- typeof AddressAttributesStatus
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 AddressAttributesStatus$ {
58
- /** @deprecated use `AddressAttributesStatus$inboundSchema` instead. */
59
- export const inboundSchema = AddressAttributesStatus$inboundSchema;
60
- /** @deprecated use `AddressAttributesStatus$outboundSchema` instead. */
61
- export const outboundSchema = AddressAttributesStatus$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: AddressAttributesStatus$inboundSchema,
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: AddressAttributesStatus$outboundSchema,
123
+ status: Status$outboundSchema,
128
124
  monthsAt: z.number().int().optional(),
129
125
  yearsAt: z.number().int().optional(),
130
126
  });