@financeable/aggregation 0.2.0 → 0.2.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.
- package/FUNCTIONS.md +0 -4
- package/README.md +945 -28
- package/docs/sdks/applications/README.md +0 -8
- package/jsr.json +1 -1
- package/lib/config.d.ts +3 -3
- package/lib/config.js +3 -3
- package/models/components/applicationresourcebulksubmission.d.ts +0 -6
- package/models/components/applicationresourcebulksubmission.d.ts.map +1 -1
- package/models/components/applicationresourcebulksubmission.js +0 -6
- package/models/components/applicationresourcebulksubmission.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/config.ts +3 -3
- package/src/models/components/applicationresourcebulksubmission.ts +0 -12
- package/financeable-typescript/.devcontainer/README.md +0 -30
- package/financeable-typescript/FUNCTIONS.md +0 -205
- package/financeable-typescript/README.md +0 -895
- package/financeable-typescript/RUNTIMES.md +0 -22
- package/financeable-typescript/docs/sdks/applications/README.md +0 -427
- package/financeable-typescript/docs/sdks/financeable/README.md +0 -5
- package/financeable-typescript/src/core.ts +0 -13
- package/financeable-typescript/src/funcs/applicationsCreate.ts +0 -124
- package/financeable-typescript/src/funcs/applicationsGet.ts +0 -128
- package/financeable-typescript/src/funcs/applicationsList.ts +0 -126
- package/financeable-typescript/src/hooks/hooks.ts +0 -129
- package/financeable-typescript/src/hooks/index.ts +0 -6
- package/financeable-typescript/src/hooks/types.ts +0 -109
- package/financeable-typescript/src/index.ts +0 -7
- package/financeable-typescript/src/lib/base64.ts +0 -37
- package/financeable-typescript/src/lib/config.ts +0 -59
- package/financeable-typescript/src/lib/dlv.ts +0 -53
- package/financeable-typescript/src/lib/encodings.ts +0 -449
- package/financeable-typescript/src/lib/env.ts +0 -37
- package/financeable-typescript/src/lib/files.ts +0 -40
- package/financeable-typescript/src/lib/http.ts +0 -323
- package/financeable-typescript/src/lib/is-plain-object.ts +0 -43
- package/financeable-typescript/src/lib/logger.ts +0 -9
- package/financeable-typescript/src/lib/matchers.ts +0 -322
- package/financeable-typescript/src/lib/primitives.ts +0 -122
- package/financeable-typescript/src/lib/retries.ts +0 -219
- package/financeable-typescript/src/lib/schemas.ts +0 -86
- package/financeable-typescript/src/lib/sdks.ts +0 -392
- package/financeable-typescript/src/lib/security.ts +0 -227
- package/financeable-typescript/src/lib/url.ts +0 -33
- package/financeable-typescript/src/models/components/addressattributes.ts +0 -148
- package/financeable-typescript/src/models/components/apierrorlinks.ts +0 -65
- package/financeable-typescript/src/models/components/applicationattributes.ts +0 -128
- package/financeable-typescript/src/models/components/applicationattributescreate.ts +0 -90
- package/financeable-typescript/src/models/components/applicationresourcebulksubmission.ts +0 -1000
- package/financeable-typescript/src/models/components/applicationstatus.ts +0 -39
- package/financeable-typescript/src/models/components/applicationtype.ts +0 -33
- package/financeable-typescript/src/models/components/assetattributes.ts +0 -400
- package/financeable-typescript/src/models/components/customerattributes.ts +0 -171
- package/financeable-typescript/src/models/components/customertitle.ts +0 -35
- package/financeable-typescript/src/models/components/errorsource.ts +0 -79
- package/financeable-typescript/src/models/components/forbiddenerror.ts +0 -207
- package/financeable-typescript/src/models/components/frequencytype.ts +0 -40
- package/financeable-typescript/src/models/components/index.ts +0 -20
- package/financeable-typescript/src/models/components/links.ts +0 -72
- package/financeable-typescript/src/models/components/loandetailsattributes.ts +0 -187
- package/financeable-typescript/src/models/components/repaymentstructure.ts +0 -40
- package/financeable-typescript/src/models/errors/apierror.ts +0 -27
- package/financeable-typescript/src/models/errors/createapplication.ts +0 -76
- package/financeable-typescript/src/models/errors/getapplication.ts +0 -76
- package/financeable-typescript/src/models/errors/getapplications.ts +0 -76
- package/financeable-typescript/src/models/errors/httpclienterrors.ts +0 -62
- package/financeable-typescript/src/models/errors/index.ts +0 -10
- package/financeable-typescript/src/models/errors/sdkvalidationerror.ts +0 -97
- package/financeable-typescript/src/models/operations/createapplication.ts +0 -1649
- package/financeable-typescript/src/models/operations/getapplication.ts +0 -1829
- package/financeable-typescript/src/models/operations/getapplications.ts +0 -1790
- package/financeable-typescript/src/models/operations/index.ts +0 -7
- package/financeable-typescript/src/sdk/applications.ts +0 -55
- package/financeable-typescript/src/sdk/index.ts +0 -5
- package/financeable-typescript/src/sdk/sdk.ts +0 -13
- package/financeable-typescript/src/types/blobs.ts +0 -31
- package/financeable-typescript/src/types/constdatetime.ts +0 -15
- package/financeable-typescript/src/types/enums.ts +0 -16
- package/financeable-typescript/src/types/fp.ts +0 -50
- package/financeable-typescript/src/types/index.ts +0 -11
- package/financeable-typescript/src/types/operations.ts +0 -105
- package/financeable-typescript/src/types/rfcdate.ts +0 -54
- package/financeable-typescript/src/types/streams.ts +0 -21
|
@@ -1,392 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { SDKHooks } from "../hooks/hooks.js";
|
|
6
|
-
import { HookContext } from "../hooks/types.js";
|
|
7
|
-
import {
|
|
8
|
-
ConnectionError,
|
|
9
|
-
InvalidRequestError,
|
|
10
|
-
RequestAbortedError,
|
|
11
|
-
RequestTimeoutError,
|
|
12
|
-
UnexpectedClientError,
|
|
13
|
-
} from "../models/errors/httpclienterrors.js";
|
|
14
|
-
import { ERR, OK, Result } from "../types/fp.js";
|
|
15
|
-
import { stringToBase64 } from "./base64.js";
|
|
16
|
-
import { SDK_METADATA, SDKOptions, serverURLFromOptions } from "./config.js";
|
|
17
|
-
import { encodeForm } from "./encodings.js";
|
|
18
|
-
import { env } from "./env.js";
|
|
19
|
-
import {
|
|
20
|
-
HTTPClient,
|
|
21
|
-
isAbortError,
|
|
22
|
-
isConnectionError,
|
|
23
|
-
isTimeoutError,
|
|
24
|
-
matchContentType,
|
|
25
|
-
matchStatusCode,
|
|
26
|
-
} from "./http.js";
|
|
27
|
-
import { Logger } from "./logger.js";
|
|
28
|
-
import { retry, RetryConfig } from "./retries.js";
|
|
29
|
-
import { SecurityState } from "./security.js";
|
|
30
|
-
|
|
31
|
-
export type RequestOptions = {
|
|
32
|
-
/**
|
|
33
|
-
* Sets a timeout, in milliseconds, on HTTP requests made by an SDK method. If
|
|
34
|
-
* `fetchOptions.signal` is set then it will take precedence over this option.
|
|
35
|
-
*/
|
|
36
|
-
timeoutMs?: number;
|
|
37
|
-
/**
|
|
38
|
-
* Set or override a retry policy on HTTP calls.
|
|
39
|
-
*/
|
|
40
|
-
retries?: RetryConfig;
|
|
41
|
-
/**
|
|
42
|
-
* Specifies the status codes which should be retried using the given retry policy.
|
|
43
|
-
*/
|
|
44
|
-
retryCodes?: string[];
|
|
45
|
-
/**
|
|
46
|
-
* Sets various request options on the `fetch` call made by an SDK method.
|
|
47
|
-
*
|
|
48
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options|Request}
|
|
49
|
-
*/
|
|
50
|
-
fetchOptions?: Omit<RequestInit, "method" | "body">;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
type RequestConfig = {
|
|
54
|
-
method: string;
|
|
55
|
-
path: string;
|
|
56
|
-
baseURL?: string | URL;
|
|
57
|
-
query?: string;
|
|
58
|
-
body?: RequestInit["body"];
|
|
59
|
-
headers?: HeadersInit;
|
|
60
|
-
security?: SecurityState | null;
|
|
61
|
-
uaHeader?: string;
|
|
62
|
-
timeoutMs?: number;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const gt: unknown = typeof globalThis === "undefined" ? null : globalThis;
|
|
66
|
-
const webWorkerLike = typeof gt === "object"
|
|
67
|
-
&& gt != null
|
|
68
|
-
&& "importScripts" in gt
|
|
69
|
-
&& typeof gt["importScripts"] === "function";
|
|
70
|
-
const isBrowserLike = webWorkerLike
|
|
71
|
-
|| (typeof navigator !== "undefined" && "serviceWorker" in navigator)
|
|
72
|
-
|| (typeof window === "object" && typeof window.document !== "undefined");
|
|
73
|
-
|
|
74
|
-
export class ClientSDK {
|
|
75
|
-
readonly #httpClient: HTTPClient;
|
|
76
|
-
readonly #hooks: SDKHooks;
|
|
77
|
-
readonly #logger?: Logger | undefined;
|
|
78
|
-
protected readonly _baseURL: URL | null;
|
|
79
|
-
public readonly _options: SDKOptions & { hooks?: SDKHooks };
|
|
80
|
-
|
|
81
|
-
constructor(options: SDKOptions = {}) {
|
|
82
|
-
const opt = options as unknown;
|
|
83
|
-
if (
|
|
84
|
-
typeof opt === "object"
|
|
85
|
-
&& opt != null
|
|
86
|
-
&& "hooks" in opt
|
|
87
|
-
&& opt.hooks instanceof SDKHooks
|
|
88
|
-
) {
|
|
89
|
-
this.#hooks = opt.hooks;
|
|
90
|
-
} else {
|
|
91
|
-
this.#hooks = new SDKHooks();
|
|
92
|
-
}
|
|
93
|
-
this._options = { ...options, hooks: this.#hooks };
|
|
94
|
-
|
|
95
|
-
const url = serverURLFromOptions(options);
|
|
96
|
-
if (url) {
|
|
97
|
-
url.pathname = url.pathname.replace(/\/+$/, "") + "/";
|
|
98
|
-
}
|
|
99
|
-
const { baseURL, client } = this.#hooks.sdkInit({
|
|
100
|
-
baseURL: url,
|
|
101
|
-
client: options.httpClient || new HTTPClient(),
|
|
102
|
-
});
|
|
103
|
-
this._baseURL = baseURL;
|
|
104
|
-
this.#httpClient = client;
|
|
105
|
-
this.#logger = options.debugLogger;
|
|
106
|
-
if (!this.#logger && env().FINANCEABLE_DEBUG) {
|
|
107
|
-
this.#logger = console;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
public _createRequest(
|
|
112
|
-
context: HookContext,
|
|
113
|
-
conf: RequestConfig,
|
|
114
|
-
options?: RequestOptions,
|
|
115
|
-
): Result<Request, InvalidRequestError | UnexpectedClientError> {
|
|
116
|
-
const { method, path, query, headers: opHeaders, security } = conf;
|
|
117
|
-
|
|
118
|
-
const base = conf.baseURL ?? this._baseURL;
|
|
119
|
-
if (!base) {
|
|
120
|
-
return ERR(new InvalidRequestError("No base URL provided for operation"));
|
|
121
|
-
}
|
|
122
|
-
const reqURL = new URL(base);
|
|
123
|
-
const inputURL = new URL(path, reqURL);
|
|
124
|
-
|
|
125
|
-
if (path) {
|
|
126
|
-
reqURL.pathname += inputURL.pathname.replace(/^\/+/, "");
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
let finalQuery = query || "";
|
|
130
|
-
|
|
131
|
-
const secQuery: string[] = [];
|
|
132
|
-
for (const [k, v] of Object.entries(security?.queryParams || {})) {
|
|
133
|
-
secQuery.push(encodeForm(k, v, { charEncoding: "percent" }));
|
|
134
|
-
}
|
|
135
|
-
if (secQuery.length) {
|
|
136
|
-
finalQuery += `&${secQuery.join("&")}`;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (finalQuery) {
|
|
140
|
-
const q = finalQuery.startsWith("&") ? finalQuery.slice(1) : finalQuery;
|
|
141
|
-
reqURL.search = `?${q}`;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const headers = new Headers(opHeaders);
|
|
145
|
-
|
|
146
|
-
const username = security?.basic.username;
|
|
147
|
-
const password = security?.basic.password;
|
|
148
|
-
if (username != null || password != null) {
|
|
149
|
-
const encoded = stringToBase64(
|
|
150
|
-
[username || "", password || ""].join(":"),
|
|
151
|
-
);
|
|
152
|
-
headers.set("Authorization", `Basic ${encoded}`);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const securityHeaders = new Headers(security?.headers || {});
|
|
156
|
-
for (const [k, v] of securityHeaders) {
|
|
157
|
-
headers.set(k, v);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
let cookie = headers.get("cookie") || "";
|
|
161
|
-
for (const [k, v] of Object.entries(security?.cookies || {})) {
|
|
162
|
-
cookie += `; ${k}=${v}`;
|
|
163
|
-
}
|
|
164
|
-
cookie = cookie.startsWith("; ") ? cookie.slice(2) : cookie;
|
|
165
|
-
headers.set("cookie", cookie);
|
|
166
|
-
|
|
167
|
-
const userHeaders = new Headers(options?.fetchOptions?.headers);
|
|
168
|
-
for (const [k, v] of userHeaders) {
|
|
169
|
-
headers.set(k, v);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Only set user agent header in non-browser-like environments since CORS
|
|
173
|
-
// policy disallows setting it in browsers e.g. Chrome throws an error.
|
|
174
|
-
if (!isBrowserLike) {
|
|
175
|
-
headers.set(conf.uaHeader ?? "user-agent", SDK_METADATA.userAgent);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
let fetchOptions = options?.fetchOptions;
|
|
179
|
-
if (!fetchOptions?.signal && conf.timeoutMs && conf.timeoutMs > 0) {
|
|
180
|
-
const timeoutSignal = AbortSignal.timeout(conf.timeoutMs);
|
|
181
|
-
if (!fetchOptions) {
|
|
182
|
-
fetchOptions = { signal: timeoutSignal };
|
|
183
|
-
} else {
|
|
184
|
-
fetchOptions.signal = timeoutSignal;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (conf.body instanceof ReadableStream) {
|
|
189
|
-
if (!fetchOptions) {
|
|
190
|
-
fetchOptions = {
|
|
191
|
-
// @ts-expect-error see https://github.com/node-fetch/node-fetch/issues/1769
|
|
192
|
-
duplex: "half",
|
|
193
|
-
};
|
|
194
|
-
} else {
|
|
195
|
-
// @ts-expect-error see https://github.com/node-fetch/node-fetch/issues/1769
|
|
196
|
-
fetchOptions.duplex = "half";
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
let input;
|
|
201
|
-
try {
|
|
202
|
-
input = this.#hooks.beforeCreateRequest(context, {
|
|
203
|
-
url: reqURL,
|
|
204
|
-
options: {
|
|
205
|
-
...fetchOptions,
|
|
206
|
-
body: conf.body ?? null,
|
|
207
|
-
headers,
|
|
208
|
-
method,
|
|
209
|
-
},
|
|
210
|
-
});
|
|
211
|
-
} catch (err: unknown) {
|
|
212
|
-
return ERR(
|
|
213
|
-
new UnexpectedClientError("Create request hook failed to execute", {
|
|
214
|
-
cause: err,
|
|
215
|
-
}),
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
return OK(new Request(input.url, input.options));
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
public async _do(
|
|
223
|
-
request: Request,
|
|
224
|
-
options: {
|
|
225
|
-
context: HookContext;
|
|
226
|
-
errorCodes: number | string | (number | string)[];
|
|
227
|
-
retryConfig: RetryConfig;
|
|
228
|
-
retryCodes: string[];
|
|
229
|
-
},
|
|
230
|
-
): Promise<
|
|
231
|
-
Result<
|
|
232
|
-
Response,
|
|
233
|
-
| RequestAbortedError
|
|
234
|
-
| RequestTimeoutError
|
|
235
|
-
| ConnectionError
|
|
236
|
-
| UnexpectedClientError
|
|
237
|
-
>
|
|
238
|
-
> {
|
|
239
|
-
const { context, errorCodes } = options;
|
|
240
|
-
|
|
241
|
-
return retry(
|
|
242
|
-
async () => {
|
|
243
|
-
const req = await this.#hooks.beforeRequest(context, request.clone());
|
|
244
|
-
await logRequest(this.#logger, req).catch((e) =>
|
|
245
|
-
this.#logger?.log("Failed to log request:", e)
|
|
246
|
-
);
|
|
247
|
-
|
|
248
|
-
let response = await this.#httpClient.request(req);
|
|
249
|
-
|
|
250
|
-
try {
|
|
251
|
-
if (matchStatusCode(response, errorCodes)) {
|
|
252
|
-
const result = await this.#hooks.afterError(
|
|
253
|
-
context,
|
|
254
|
-
response,
|
|
255
|
-
null,
|
|
256
|
-
);
|
|
257
|
-
if (result.error) {
|
|
258
|
-
throw result.error;
|
|
259
|
-
}
|
|
260
|
-
response = result.response || response;
|
|
261
|
-
} else {
|
|
262
|
-
response = await this.#hooks.afterSuccess(context, response);
|
|
263
|
-
}
|
|
264
|
-
} finally {
|
|
265
|
-
await logResponse(this.#logger, response, req)
|
|
266
|
-
.catch(e => this.#logger?.log("Failed to log response:", e));
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
return response;
|
|
270
|
-
},
|
|
271
|
-
{ config: options.retryConfig, statusCodes: options.retryCodes },
|
|
272
|
-
).then(
|
|
273
|
-
(r) => OK(r),
|
|
274
|
-
(err) => {
|
|
275
|
-
switch (true) {
|
|
276
|
-
case isAbortError(err):
|
|
277
|
-
return ERR(
|
|
278
|
-
new RequestAbortedError("Request aborted by client", {
|
|
279
|
-
cause: err,
|
|
280
|
-
}),
|
|
281
|
-
);
|
|
282
|
-
case isTimeoutError(err):
|
|
283
|
-
return ERR(
|
|
284
|
-
new RequestTimeoutError("Request timed out", { cause: err }),
|
|
285
|
-
);
|
|
286
|
-
case isConnectionError(err):
|
|
287
|
-
return ERR(
|
|
288
|
-
new ConnectionError("Unable to make request", { cause: err }),
|
|
289
|
-
);
|
|
290
|
-
default:
|
|
291
|
-
return ERR(
|
|
292
|
-
new UnexpectedClientError("Unexpected HTTP client error", {
|
|
293
|
-
cause: err,
|
|
294
|
-
}),
|
|
295
|
-
);
|
|
296
|
-
}
|
|
297
|
-
},
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
const jsonLikeContentTypeRE = /^application\/(?:.{0,100}\+)?json/;
|
|
303
|
-
async function logRequest(logger: Logger | undefined, req: Request) {
|
|
304
|
-
if (!logger) {
|
|
305
|
-
return;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
const contentType = req.headers.get("content-type");
|
|
309
|
-
const ct = contentType?.split(";")[0] || "";
|
|
310
|
-
|
|
311
|
-
logger.group(`> Request: ${req.method} ${req.url}`);
|
|
312
|
-
|
|
313
|
-
logger.group("Headers:");
|
|
314
|
-
for (const [k, v] of req.headers.entries()) {
|
|
315
|
-
logger.log(`${k}: ${v}`);
|
|
316
|
-
}
|
|
317
|
-
logger.groupEnd();
|
|
318
|
-
|
|
319
|
-
logger.group("Body:");
|
|
320
|
-
switch (true) {
|
|
321
|
-
case jsonLikeContentTypeRE.test(ct):
|
|
322
|
-
logger.log(await req.clone().json());
|
|
323
|
-
break;
|
|
324
|
-
case ct.startsWith("text/"):
|
|
325
|
-
logger.log(await req.clone().text());
|
|
326
|
-
break;
|
|
327
|
-
case ct === "multipart/form-data": {
|
|
328
|
-
const body = await req.clone().formData();
|
|
329
|
-
for (const [k, v] of body) {
|
|
330
|
-
const vlabel = v instanceof Blob ? "<Blob>" : v;
|
|
331
|
-
logger.log(`${k}: ${vlabel}`);
|
|
332
|
-
}
|
|
333
|
-
break;
|
|
334
|
-
}
|
|
335
|
-
default:
|
|
336
|
-
logger.log(`<${contentType}>`);
|
|
337
|
-
break;
|
|
338
|
-
}
|
|
339
|
-
logger.groupEnd();
|
|
340
|
-
|
|
341
|
-
logger.groupEnd();
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
async function logResponse(
|
|
345
|
-
logger: Logger | undefined,
|
|
346
|
-
res: Response,
|
|
347
|
-
req: Request,
|
|
348
|
-
) {
|
|
349
|
-
if (!logger) {
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
const contentType = res.headers.get("content-type");
|
|
354
|
-
const ct = contentType?.split(";")[0] || "";
|
|
355
|
-
|
|
356
|
-
logger.group(`< Response: ${req.method} ${req.url}`);
|
|
357
|
-
logger.log("Status Code:", res.status, res.statusText);
|
|
358
|
-
|
|
359
|
-
logger.group("Headers:");
|
|
360
|
-
for (const [k, v] of res.headers.entries()) {
|
|
361
|
-
logger.log(`${k}: ${v}`);
|
|
362
|
-
}
|
|
363
|
-
logger.groupEnd();
|
|
364
|
-
|
|
365
|
-
logger.group("Body:");
|
|
366
|
-
switch (true) {
|
|
367
|
-
case matchContentType(res, "application/json")
|
|
368
|
-
|| jsonLikeContentTypeRE.test(ct):
|
|
369
|
-
logger.log(await res.clone().json());
|
|
370
|
-
break;
|
|
371
|
-
case matchContentType(res, "text/event-stream"):
|
|
372
|
-
logger.log(`<${contentType}>`);
|
|
373
|
-
break;
|
|
374
|
-
case matchContentType(res, "text/*"):
|
|
375
|
-
logger.log(await res.clone().text());
|
|
376
|
-
break;
|
|
377
|
-
case matchContentType(res, "multipart/form-data"): {
|
|
378
|
-
const body = await res.clone().formData();
|
|
379
|
-
for (const [k, v] of body) {
|
|
380
|
-
const vlabel = v instanceof Blob ? "<Blob>" : v;
|
|
381
|
-
logger.log(`${k}: ${vlabel}`);
|
|
382
|
-
}
|
|
383
|
-
break;
|
|
384
|
-
}
|
|
385
|
-
default:
|
|
386
|
-
logger.log(`<${contentType}>`);
|
|
387
|
-
break;
|
|
388
|
-
}
|
|
389
|
-
logger.groupEnd();
|
|
390
|
-
|
|
391
|
-
logger.groupEnd();
|
|
392
|
-
}
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
type OAuth2PasswordFlow = {
|
|
6
|
-
username: string;
|
|
7
|
-
password?: string | undefined;
|
|
8
|
-
clientID: string;
|
|
9
|
-
clientSecret?: string | undefined;
|
|
10
|
-
tokenURL: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export enum SecurityErrorCode {
|
|
14
|
-
Incomplete = "incomplete",
|
|
15
|
-
UnrecognisedSecurityType = "unrecognized_security_type",
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class SecurityError extends Error {
|
|
19
|
-
constructor(
|
|
20
|
-
public code: SecurityErrorCode,
|
|
21
|
-
message: string,
|
|
22
|
-
) {
|
|
23
|
-
super(message);
|
|
24
|
-
this.name = "SecurityError";
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
static incomplete(): SecurityError {
|
|
28
|
-
return new SecurityError(
|
|
29
|
-
SecurityErrorCode.Incomplete,
|
|
30
|
-
"Security requirements not met in order to perform the operation",
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
static unrecognizedType(type: string): SecurityError {
|
|
34
|
-
return new SecurityError(
|
|
35
|
-
SecurityErrorCode.UnrecognisedSecurityType,
|
|
36
|
-
`Unrecognised security type: ${type}`,
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export type SecurityState = {
|
|
42
|
-
basic: { username?: string | undefined; password?: string | undefined };
|
|
43
|
-
headers: Record<string, string>;
|
|
44
|
-
queryParams: Record<string, string>;
|
|
45
|
-
cookies: Record<string, string>;
|
|
46
|
-
oauth2: ({ type: "password" } & OAuth2PasswordFlow) | { type: "none" };
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
type SecurityInputBasic = {
|
|
50
|
-
type: "http:basic";
|
|
51
|
-
value:
|
|
52
|
-
| { username?: string | undefined; password?: string | undefined }
|
|
53
|
-
| null
|
|
54
|
-
| undefined;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
type SecurityInputBearer = {
|
|
58
|
-
type: "http:bearer";
|
|
59
|
-
value: string | null | undefined;
|
|
60
|
-
fieldName: string;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
type SecurityInputAPIKey = {
|
|
64
|
-
type: "apiKey:header" | "apiKey:query" | "apiKey:cookie";
|
|
65
|
-
value: string | null | undefined;
|
|
66
|
-
fieldName: string;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
type SecurityInputOIDC = {
|
|
70
|
-
type: "openIdConnect";
|
|
71
|
-
value: string | null | undefined;
|
|
72
|
-
fieldName: string;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
type SecurityInputOAuth2 = {
|
|
76
|
-
type: "oauth2";
|
|
77
|
-
value: string | null | undefined;
|
|
78
|
-
fieldName: string;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
type SecurityInputOAuth2ClientCredentials = {
|
|
82
|
-
type: "oauth2:client_credentials";
|
|
83
|
-
value:
|
|
84
|
-
| { clientID?: string | undefined; clientSecret?: string | undefined }
|
|
85
|
-
| null
|
|
86
|
-
| undefined;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
type SecurityInputOAuth2PasswordCredentials = {
|
|
90
|
-
type: "oauth2:password";
|
|
91
|
-
value:
|
|
92
|
-
| string
|
|
93
|
-
| null
|
|
94
|
-
| undefined;
|
|
95
|
-
fieldName: string;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
type SecurityInputCustom = {
|
|
99
|
-
type: "http:custom";
|
|
100
|
-
value: any | null | undefined;
|
|
101
|
-
fieldName: string;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
export type SecurityInput =
|
|
105
|
-
| SecurityInputBasic
|
|
106
|
-
| SecurityInputBearer
|
|
107
|
-
| SecurityInputAPIKey
|
|
108
|
-
| SecurityInputOAuth2
|
|
109
|
-
| SecurityInputOAuth2ClientCredentials
|
|
110
|
-
| SecurityInputOAuth2PasswordCredentials
|
|
111
|
-
| SecurityInputOIDC
|
|
112
|
-
| SecurityInputCustom;
|
|
113
|
-
|
|
114
|
-
export function resolveSecurity(
|
|
115
|
-
...options: SecurityInput[][]
|
|
116
|
-
): SecurityState | null {
|
|
117
|
-
const state: SecurityState = {
|
|
118
|
-
basic: { username: "", password: "" },
|
|
119
|
-
headers: {},
|
|
120
|
-
queryParams: {},
|
|
121
|
-
cookies: {},
|
|
122
|
-
oauth2: { type: "none" },
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const option = options.find((opts) => {
|
|
126
|
-
return opts.every((o) => {
|
|
127
|
-
if (o.value == null) {
|
|
128
|
-
return false;
|
|
129
|
-
} else if (o.type === "http:basic") {
|
|
130
|
-
return o.value.username != null || o.value.password != null;
|
|
131
|
-
} else if (o.type === "http:custom") {
|
|
132
|
-
return null;
|
|
133
|
-
} else if (o.type === "oauth2:password") {
|
|
134
|
-
return (
|
|
135
|
-
typeof o.value === "string" && !!o.value
|
|
136
|
-
);
|
|
137
|
-
} else if (o.type === "oauth2:client_credentials") {
|
|
138
|
-
return o.value.clientID != null || o.value.clientSecret != null;
|
|
139
|
-
} else if (typeof o.value === "string") {
|
|
140
|
-
return !!o.value;
|
|
141
|
-
} else {
|
|
142
|
-
throw new Error(
|
|
143
|
-
`Unrecognized security type: ${o.type} (value type: ${typeof o
|
|
144
|
-
.value})`,
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
if (option == null) {
|
|
150
|
-
return null;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
option.forEach((spec) => {
|
|
154
|
-
if (spec.value == null) {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const { type } = spec;
|
|
159
|
-
|
|
160
|
-
switch (type) {
|
|
161
|
-
case "apiKey:header":
|
|
162
|
-
state.headers[spec.fieldName] = spec.value;
|
|
163
|
-
break;
|
|
164
|
-
case "apiKey:query":
|
|
165
|
-
state.queryParams[spec.fieldName] = spec.value;
|
|
166
|
-
break;
|
|
167
|
-
case "apiKey:cookie":
|
|
168
|
-
state.cookies[spec.fieldName] = spec.value;
|
|
169
|
-
break;
|
|
170
|
-
case "http:basic":
|
|
171
|
-
applyBasic(state, spec);
|
|
172
|
-
break;
|
|
173
|
-
case "http:custom":
|
|
174
|
-
break;
|
|
175
|
-
case "http:bearer":
|
|
176
|
-
applyBearer(state, spec);
|
|
177
|
-
break;
|
|
178
|
-
case "oauth2":
|
|
179
|
-
applyBearer(state, spec);
|
|
180
|
-
break;
|
|
181
|
-
case "oauth2:password":
|
|
182
|
-
applyBearer(state, spec);
|
|
183
|
-
break;
|
|
184
|
-
case "oauth2:client_credentials":
|
|
185
|
-
break;
|
|
186
|
-
case "openIdConnect":
|
|
187
|
-
applyBearer(state, spec);
|
|
188
|
-
break;
|
|
189
|
-
default:
|
|
190
|
-
spec satisfies never;
|
|
191
|
-
throw SecurityError.unrecognizedType(type);
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
return state;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function applyBasic(
|
|
199
|
-
state: SecurityState,
|
|
200
|
-
spec: SecurityInputBasic,
|
|
201
|
-
) {
|
|
202
|
-
if (spec.value == null) {
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
state.basic = spec.value;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
function applyBearer(
|
|
210
|
-
state: SecurityState,
|
|
211
|
-
spec:
|
|
212
|
-
| SecurityInputBearer
|
|
213
|
-
| SecurityInputOAuth2
|
|
214
|
-
| SecurityInputOIDC
|
|
215
|
-
| SecurityInputOAuth2PasswordCredentials,
|
|
216
|
-
) {
|
|
217
|
-
if (typeof spec.value !== "string" || !spec.value) {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
let value = spec.value;
|
|
222
|
-
if (value.slice(0, 7).toLowerCase() !== "bearer ") {
|
|
223
|
-
value = `Bearer ${value}`;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
state.headers[spec.fieldName] = value;
|
|
227
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const hasOwn = Object.prototype.hasOwnProperty;
|
|
6
|
-
|
|
7
|
-
export type Params = Partial<Record<string, string | number>>;
|
|
8
|
-
|
|
9
|
-
export function pathToFunc(
|
|
10
|
-
pathPattern: string,
|
|
11
|
-
options?: { charEncoding?: "percent" | "none" },
|
|
12
|
-
): (params?: Params) => string {
|
|
13
|
-
const paramRE = /\{([a-zA-Z0-9_]+?)\}/g;
|
|
14
|
-
|
|
15
|
-
return function buildURLPath(params: Record<string, unknown> = {}): string {
|
|
16
|
-
return pathPattern.replace(paramRE, function (_, placeholder) {
|
|
17
|
-
if (!hasOwn.call(params, placeholder)) {
|
|
18
|
-
throw new Error(`Parameter '${placeholder}' is required`);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const value = params[placeholder];
|
|
22
|
-
if (typeof value !== "string" && typeof value !== "number") {
|
|
23
|
-
throw new Error(
|
|
24
|
-
`Parameter '${placeholder}' must be a string or number`,
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return options?.charEncoding === "percent"
|
|
29
|
-
? encodeURIComponent(`${value}`)
|
|
30
|
-
: `${value}`;
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
}
|