@composio/core 0.18.1 → 0.19.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/dist/{CustomTool-Bz0f52QR.mjs → CustomTool-BMlZfJVz.mjs} +1 -1
- package/dist/{CustomTool-VRfWzMix.d.mts → CustomTool-CB5vm1Jc.d.mts} +1 -1
- package/dist/{FileModifierErrors-CwB-Inm9.mjs → FileModifierErrors-BqFmpRsm.mjs} +1 -1
- package/dist/{FileToolModifier.utils.neutral-D_YkHwZP.mjs → FileToolModifier.utils.neutral-DWFpnsj2.mjs} +4 -2
- package/dist/{SsrfErrors-xhdVE4yw.mjs → SsrfErrors-C91YhASE.mjs} +14 -10
- package/dist/{Telemetry-Dw9W5RSp.mjs → Telemetry-HlftxMx6.mjs} +2 -2
- package/dist/{cancellation-P5YUlcfz.mjs → cancellation-CXpfmiVo.mjs} +7 -5
- package/dist/{composio-Cb3d1jFe.d.mts → composio-DLGaeN70.d.mts} +327 -26
- package/dist/{customTool.types-B6ej_8XZ.d.mts → customTool.types-BAmEh3MB.d.mts} +95 -4
- package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +2 -2
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +3 -13
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +46 -3
- package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +4 -4
- package/dist/docs/reference/sdk-reference/typescript/tools.mdx +33 -23
- package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +3 -2
- package/dist/{errors-Ue9wMrPK.mjs → errors-BuEKehbI.mjs} +23 -3
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-KE5Fa-af.mjs → fileUtils.node-L7XD8UPr.mjs} +8 -6
- package/dist/index.d.mts +160 -101
- package/dist/index.mjs +336 -127
- package/dist/models/Files.node.d.mts +2 -3
- package/dist/models/Files.node.mjs +2 -2
- package/dist/models/Files.workerd.d.mts +2 -3
- package/dist/platform/node.d.mts +2 -3
- package/dist/platform/workerd.d.mts +2 -3
- package/dist/{sensitiveFileUploadPaths-QN7w4n8v.mjs → sensitiveFileUploadPaths-B6pBt9lO.mjs} +10 -7
- package/dist/{ssrfGuard.node-BLX6b-Rf.mjs → ssrfGuard.node-B9xQB4za.mjs} +104 -14
- package/dist/{types-CGdgK442.d.mts → types-CxLPO0Xq.d.mts} +2 -2
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +3 -4
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +3 -4
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +3 -4
- package/dist/utils/modifiers/FileToolModifier.node.mjs +6 -6
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +3 -4
- package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
- package/dist/utils/ssrfGuard.node.d.mts +19 -10
- package/dist/utils/ssrfGuard.node.mjs +1 -1
- package/dist/utils/ssrfGuard.workerd.d.mts +12 -4
- package/dist/utils/ssrfGuard.workerd.mjs +2 -2
- package/package.json +8 -8
- package/src/errors/ToolErrors.ts +24 -0
- package/src/index.ts +4 -0
- package/src/models/MCP.ts +29 -15
- package/src/models/ToolRouter.ts +1 -0
- package/src/models/ToolRouterSession.ts +106 -9
- package/src/models/Toolkits.ts +1 -2
- package/src/models/Tools.ts +55 -25
- package/src/models/Triggers.ts +7 -2
- package/src/services/pusher/Pusher.ts +29 -10
- package/src/types/toolRouter.types.ts +54 -3
- package/src/types/toolkit.types.ts +17 -0
- package/src/utils/jsonSchema.ts +4 -1
- package/src/utils/ssrfGuard.node.ts +127 -13
- package/src/utils/ssrfGuard.workerd.ts +11 -1
- package/src/utils/transformers/toolkits.ts +79 -2
|
@@ -66,10 +66,27 @@ export const ToolkitAuthFieldSchema = z.object({
|
|
|
66
66
|
name: z.string(),
|
|
67
67
|
type: z.string(),
|
|
68
68
|
default: z.string().nullable().optional(),
|
|
69
|
+
/**
|
|
70
|
+
* Whether this field holds a secret/credential value. Clients use it to
|
|
71
|
+
* decide whether to mask the input when collecting the value in their own
|
|
72
|
+
* UI. The property is absent when the API omits the flag for the field.
|
|
73
|
+
*/
|
|
74
|
+
isSecret: z.boolean().optional(),
|
|
75
|
+
/**
|
|
76
|
+
* The legacy template name the API reports for this field, mapped from
|
|
77
|
+
* `legacy_template_name`. The API declares it as an optional string without
|
|
78
|
+
* further documenting its semantics.
|
|
79
|
+
*/
|
|
80
|
+
legacyTemplateName: z.string().optional(),
|
|
69
81
|
});
|
|
70
82
|
export const ToolkitAuthConfigDetailsSchema = z.object({
|
|
71
83
|
name: z.string(),
|
|
72
84
|
mode: z.string(),
|
|
85
|
+
/**
|
|
86
|
+
* URL to a page where users can obtain or configure credentials for this
|
|
87
|
+
* authentication method, e.g. `https://github.com/settings/tokens`.
|
|
88
|
+
*/
|
|
89
|
+
authHintUrl: z.string().nullable().optional(),
|
|
73
90
|
fields: z.object({
|
|
74
91
|
authConfigCreation: z.object({
|
|
75
92
|
optional: z.array(ToolkitAuthFieldSchema),
|
package/src/utils/jsonSchema.ts
CHANGED
|
@@ -495,7 +495,10 @@ export function jsonSchemaToZodSchema<T extends z.ZodTypeAny>(
|
|
|
495
495
|
const zodSchema = jsonSchemaToZod(schema) as T;
|
|
496
496
|
return zodSchema;
|
|
497
497
|
} catch (error) {
|
|
498
|
-
|
|
498
|
+
// The cause names the offending property path; surface it in the message
|
|
499
|
+
// so a single malformed property is identifiable without unwrapping.
|
|
500
|
+
const detail = error instanceof Error ? `: ${error.message}` : '';
|
|
501
|
+
throw new JsonSchemaToZodError(`Failed to convert JSON Schema to Zod Schema${detail}`, {
|
|
499
502
|
cause: error,
|
|
500
503
|
});
|
|
501
504
|
}
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
* to a public address during validation and rebind to an internal one before
|
|
28
28
|
* the connect — a TOCTOU window the Python guard closes the same way.
|
|
29
29
|
*
|
|
30
|
-
*
|
|
30
|
+
* By default, a hop whose effective dispatcher is a configured route — a
|
|
31
31
|
* caller-supplied `init.dispatcher`, a non-stock global dispatcher (a
|
|
32
32
|
* `ProxyAgent` or `EnvHttpProxyAgent` installed via `setGlobalDispatcher`), or
|
|
33
33
|
* the runtime's env-proxy mode (automatic on Bun, opt-in via
|
|
@@ -35,11 +35,90 @@ import {
|
|
|
35
35
|
* pre-flight validation. Pinning would dial the validated address instead of
|
|
36
36
|
* the proxy, and the proxy resolves the hostname itself where the SDK cannot
|
|
37
37
|
* see or pin that resolution. The Python guard carries the same residual for
|
|
38
|
-
* the same reason (`_proxy_applies`).
|
|
38
|
+
* the same reason (`_proxy_applies`). Callers that cannot accept that residual
|
|
39
|
+
* can set `requirePinnedConnection`, which fails closed before fetching.
|
|
39
40
|
*/
|
|
40
41
|
|
|
41
42
|
const MAX_REDIRECTS = 5;
|
|
42
43
|
|
|
44
|
+
export interface SsrfSafeFetchOptions {
|
|
45
|
+
/** Maximum number of redirects to follow. Defaults to 5. */
|
|
46
|
+
maxRedirects?: number;
|
|
47
|
+
/**
|
|
48
|
+
* Refuse a request when a configured dispatcher or environment proxy means
|
|
49
|
+
* the connection cannot be pinned to the address validated by the guard.
|
|
50
|
+
*/
|
|
51
|
+
requirePinnedConnection?: boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The Fetch standard's "redirect status" set. A 3xx outside it is not a
|
|
56
|
+
* redirect to follow even when it carries a `location` — `304 Not Modified`
|
|
57
|
+
* and `305 Use Proxy` most of all, and following those would replay the
|
|
58
|
+
* request against a target the caller never asked for. The Python guard
|
|
59
|
+
* follows the same set (`_REDIRECT_STATUS_CODES`).
|
|
60
|
+
*/
|
|
61
|
+
const REDIRECT_STATUS_CODES = new Set([301, 302, 303, 307, 308]);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Headers that describe a request body, so they have to go when the body does:
|
|
65
|
+
* the Fetch standard's "request-body-header name" set, plus the two the Python
|
|
66
|
+
* guard also drops because `requests` recomputes them from the body it sends.
|
|
67
|
+
*/
|
|
68
|
+
const BODY_HEADERS = [
|
|
69
|
+
'content-encoding',
|
|
70
|
+
'content-language',
|
|
71
|
+
'content-length',
|
|
72
|
+
'content-location',
|
|
73
|
+
'content-type',
|
|
74
|
+
'transfer-encoding',
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The method the hop after a redirect uses, or `null` to replay as-is. A
|
|
79
|
+
* returned method also means the request body goes.
|
|
80
|
+
*
|
|
81
|
+
* These are the Fetch standard's redirect rules, which following redirects by
|
|
82
|
+
* hand (`redirect: 'manual'`) means `fetch` never applies for us: `303` points
|
|
83
|
+
* at a result URL that has no use for the original body, so every method loses
|
|
84
|
+
* it and everything but `HEAD` becomes a `GET`; `301`/`302` do the same to a
|
|
85
|
+
* `POST` only; `307`/`308` replay both. Without this, a `303` answering an
|
|
86
|
+
* upload would PUT the payload again at a URL that expects a GET. The Python
|
|
87
|
+
* guard applies the same rules in `safe_request`.
|
|
88
|
+
*/
|
|
89
|
+
const redirectRewrite = (status: number, method: string): string | null => {
|
|
90
|
+
if (status === 303) return method === 'HEAD' ? 'HEAD' : 'GET';
|
|
91
|
+
if ((status === 301 || status === 302) && method === 'POST') return 'GET';
|
|
92
|
+
return null;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Headers that carry a credential for the origin the request was addressed
|
|
97
|
+
* to, so they must not follow a redirect to a different origin. The Fetch
|
|
98
|
+
* standard strips `Authorization` on a cross-origin redirect; `Cookie` and
|
|
99
|
+
* `Proxy-Authorization` go with it the way `requests` and curl drop them on a
|
|
100
|
+
* host change. `redirect: 'manual'` means `fetch` never applies that rule for
|
|
101
|
+
* us either. The Python guard drops the same three (`_CREDENTIAL_HEADERS`).
|
|
102
|
+
*/
|
|
103
|
+
const CREDENTIAL_HEADERS = ['authorization', 'cookie', 'proxy-authorization'];
|
|
104
|
+
|
|
105
|
+
const applyRedirectSemantics = (
|
|
106
|
+
init: RequestInit,
|
|
107
|
+
status: number,
|
|
108
|
+
fromUrl: string,
|
|
109
|
+
toUrl: string
|
|
110
|
+
): RequestInit => {
|
|
111
|
+
const method = redirectRewrite(status, (init.method ?? 'GET').toUpperCase());
|
|
112
|
+
const crossOrigin = new URL(fromUrl).origin !== new URL(toUrl).origin;
|
|
113
|
+
if (method === null && !crossOrigin) return init;
|
|
114
|
+
|
|
115
|
+
const headers = new Headers(init.headers);
|
|
116
|
+
if (method !== null) for (const name of BODY_HEADERS) headers.delete(name);
|
|
117
|
+
if (crossOrigin) for (const name of CREDENTIAL_HEADERS) headers.delete(name);
|
|
118
|
+
if (method === null) return { ...init, headers };
|
|
119
|
+
return { ...init, method, body: undefined, headers };
|
|
120
|
+
};
|
|
121
|
+
|
|
43
122
|
/**
|
|
44
123
|
* Whether the runtime would route `url` through an env proxy the SDK cannot
|
|
45
124
|
* see into. Bun honors proxy environment variables automatically. Node's
|
|
@@ -77,6 +156,7 @@ const IPV4_BLOCKED_CIDRS: ReadonlyArray<readonly [string, number]> = [
|
|
|
77
156
|
['172.16.0.0', 12], // private
|
|
78
157
|
['192.0.0.0', 24], // IETF protocol assignments
|
|
79
158
|
['192.0.2.0', 24], // TEST-NET-1
|
|
159
|
+
['192.88.99.0', 24], // 6to4 relay anycast (deprecated, RFC 7526)
|
|
80
160
|
['192.168.0.0', 16], // private
|
|
81
161
|
['198.18.0.0', 15], // benchmarking
|
|
82
162
|
['198.51.100.0', 24], // TEST-NET-2
|
|
@@ -146,8 +226,20 @@ const isBlockedIpv6 = (ip: string): boolean => {
|
|
|
146
226
|
return isBlockedIpv4Long((((h[6] << 16) >>> 0) | h[7]) >>> 0);
|
|
147
227
|
}
|
|
148
228
|
|
|
229
|
+
// Transition and tunnel ranges. Each one either carries an arbitrary IPv4
|
|
230
|
+
// address in its low bits or is reserved, so a public-looking literal here
|
|
231
|
+
// can still name internal space: `2002:7f00:1::` is 6to4 for `127.0.0.1`.
|
|
232
|
+
// Blocking the whole range rather than decoding it matches the Python guard,
|
|
233
|
+
// where `ipaddress.is_global` already rejects all of them.
|
|
234
|
+
if (h[0] === 0x2001 && (h[1] & 0xfe00) === 0) return true; // IETF protocol assignments 2001::/23 (incl. Teredo)
|
|
235
|
+
if (h[0] === 0x2001 && h[1] === 0x0db8) return true; // documentation 2001:db8::/32
|
|
236
|
+
if (h[0] === 0x2002) return true; // 6to4 2002::/16
|
|
237
|
+
if (h[0] === 0x0064 && h[1] === 0xff9b && h[2] === 0x0001) return true; // local-use NAT64 64:ff9b:1::/48
|
|
238
|
+
if (h[0] === 0x0100 && h[1] === 0 && h[2] === 0 && h[3] === 0) return true; // discard-only 100::/64
|
|
239
|
+
|
|
149
240
|
if ((h[0] & 0xfe00) === 0xfc00) return true; // unique local fc00::/7
|
|
150
241
|
if ((h[0] & 0xffc0) === 0xfe80) return true; // link-local fe80::/10
|
|
242
|
+
if ((h[0] & 0xffc0) === 0xfec0) return true; // site-local fec0::/10 (deprecated)
|
|
151
243
|
if ((h[0] & 0xff00) === 0xff00) return true; // multicast ff00::/8
|
|
152
244
|
|
|
153
245
|
return false;
|
|
@@ -221,18 +313,27 @@ export const assertSafeFetchTarget = async (rawUrl: string): Promise<string[]> =
|
|
|
221
313
|
* connects to the address it validated, and re-validates and re-pins every
|
|
222
314
|
* redirect hop (redirects are followed manually up to {@link MAX_REDIRECTS}).
|
|
223
315
|
* Intermediate redirect bodies are cancelled; non-redirect responses are
|
|
224
|
-
* returned unchanged.
|
|
316
|
+
* returned unchanged. Each hop carries the method, body, and credential headers
|
|
317
|
+
* the Fetch standard says it should — see {@link applyRedirectSemantics}.
|
|
225
318
|
*
|
|
226
|
-
*
|
|
227
|
-
* `init.dispatcher`, non-stock global dispatcher, env-proxy
|
|
228
|
-
* pinned
|
|
319
|
+
* By default, a hop whose effective dispatcher is a configured route
|
|
320
|
+
* (caller-supplied `init.dispatcher`, non-stock global dispatcher, env-proxy
|
|
321
|
+
* mode) is *not* pinned. Set `requirePinnedConnection` to fail closed instead.
|
|
229
322
|
*/
|
|
230
323
|
export const ssrfSafeFetch = async (
|
|
231
324
|
rawUrl: string,
|
|
232
325
|
init: RequestInit = {},
|
|
233
|
-
|
|
326
|
+
optionsOrMaxRedirects: SsrfSafeFetchOptions | number = {}
|
|
234
327
|
): Promise<Response> => {
|
|
328
|
+
const options =
|
|
329
|
+
typeof optionsOrMaxRedirects === 'number'
|
|
330
|
+
? { maxRedirects: optionsOrMaxRedirects }
|
|
331
|
+
: optionsOrMaxRedirects;
|
|
332
|
+
const maxRedirects = options.maxRedirects ?? MAX_REDIRECTS;
|
|
235
333
|
let currentUrl = rawUrl;
|
|
334
|
+
// Rebound per hop: a redirect can drop the method and body (see
|
|
335
|
+
// `applyRedirectSemantics`), and the following hops must send what is left.
|
|
336
|
+
let currentInit = init;
|
|
236
337
|
|
|
237
338
|
for (let hop = 0; hop <= maxRedirects; hop++) {
|
|
238
339
|
const addresses = await assertSafeFetchTarget(currentUrl);
|
|
@@ -241,26 +342,37 @@ export const ssrfSafeFetch = async (
|
|
|
241
342
|
// Pinning replaces the connect target; through a configured route that
|
|
242
343
|
// would dial the validated origin instead of the route's next hop (the
|
|
243
344
|
// proxy), so those hops keep the pre-flight check only.
|
|
244
|
-
const callerDispatcher = (
|
|
345
|
+
const callerDispatcher = (currentInit as RequestInit & { dispatcher?: unknown }).dispatcher;
|
|
245
346
|
const respectConfiguredRoute =
|
|
246
347
|
callerDispatcher !== undefined ||
|
|
247
348
|
envProxyApplies(new URL(currentUrl), isBun) ||
|
|
248
349
|
hasCustomGlobalDispatcher();
|
|
249
350
|
|
|
351
|
+
if (options.requirePinnedConnection && respectConfiguredRoute) {
|
|
352
|
+
throw new ComposioBlockedInternalUrlError(
|
|
353
|
+
'Refusing to fetch through a configured network route because the validated address cannot be pinned',
|
|
354
|
+
{ url: currentUrl }
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
|
|
250
358
|
const dispatcher =
|
|
251
359
|
respectConfiguredRoute || isBun ? undefined : await createPinnedDispatcher(addresses);
|
|
252
360
|
|
|
253
361
|
let response: Response;
|
|
254
362
|
try {
|
|
255
363
|
if (isBun && !respectConfiguredRoute) {
|
|
256
|
-
response = await pinnedHttpFetch(
|
|
364
|
+
response = await pinnedHttpFetch(
|
|
365
|
+
currentUrl,
|
|
366
|
+
{ ...currentInit, redirect: 'manual' },
|
|
367
|
+
addresses
|
|
368
|
+
);
|
|
257
369
|
} else {
|
|
258
370
|
// `dispatcher` is a Node-only extension to `RequestInit`.
|
|
259
371
|
response = await fetch(
|
|
260
372
|
currentUrl,
|
|
261
373
|
(dispatcher === undefined
|
|
262
|
-
? { ...
|
|
263
|
-
: { ...
|
|
374
|
+
? { ...currentInit, redirect: 'manual' }
|
|
375
|
+
: { ...currentInit, redirect: 'manual', dispatcher }) as RequestInit
|
|
264
376
|
);
|
|
265
377
|
}
|
|
266
378
|
} catch (error) {
|
|
@@ -277,7 +389,7 @@ export const ssrfSafeFetch = async (
|
|
|
277
389
|
}
|
|
278
390
|
|
|
279
391
|
const isRedirect =
|
|
280
|
-
|
|
392
|
+
REDIRECT_STATUS_CODES.has(response.status) && response.headers.has('location');
|
|
281
393
|
if (!isRedirect) {
|
|
282
394
|
return response;
|
|
283
395
|
}
|
|
@@ -286,7 +398,9 @@ export const ssrfSafeFetch = async (
|
|
|
286
398
|
// than leaving it to the garbage collector (mirrors `readResponseBodyWithLimit`).
|
|
287
399
|
await response.body?.cancel().catch(() => undefined);
|
|
288
400
|
|
|
289
|
-
|
|
401
|
+
const nextUrl = new URL(response.headers.get('location')!, currentUrl).toString();
|
|
402
|
+
currentInit = applyRedirectSemantics(currentInit, response.status, currentUrl, nextUrl);
|
|
403
|
+
currentUrl = nextUrl;
|
|
290
404
|
}
|
|
291
405
|
|
|
292
406
|
throw new ComposioBlockedInternalUrlError(
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { ComposioBlockedInternalUrlError } from '../errors/SsrfErrors';
|
|
2
2
|
|
|
3
|
+
export interface SsrfSafeFetchOptions {
|
|
4
|
+
/** Maximum number of redirects to follow. Defaults to 5. */
|
|
5
|
+
maxRedirects?: number;
|
|
6
|
+
/**
|
|
7
|
+
* Refuse a request when a configured dispatcher or environment proxy means
|
|
8
|
+
* the connection cannot be pinned to the address validated by the guard.
|
|
9
|
+
*/
|
|
10
|
+
requirePinnedConnection?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
3
13
|
/**
|
|
4
14
|
* Edge runtimes do not expose the DNS resolution APIs needed to prove that a
|
|
5
15
|
* hostname is publicly routable before connecting. Fail closed instead of
|
|
@@ -8,7 +18,7 @@ import { ComposioBlockedInternalUrlError } from '../errors/SsrfErrors';
|
|
|
8
18
|
export const ssrfSafeFetch = async (
|
|
9
19
|
rawUrl: string,
|
|
10
20
|
_init: RequestInit = {},
|
|
11
|
-
|
|
21
|
+
_optionsOrMaxRedirects: SsrfSafeFetchOptions | number = {}
|
|
12
22
|
): Promise<Response> => {
|
|
13
23
|
throw new ComposioBlockedInternalUrlError(
|
|
14
24
|
'URL file uploads are not supported in edge runtimes because the destination cannot be safely validated',
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
import {
|
|
7
7
|
ToolKitListResponse,
|
|
8
8
|
ToolKitListResponseSchema,
|
|
9
|
+
ToolkitAuthField,
|
|
9
10
|
ToolkitRetrieveResponse,
|
|
10
11
|
ToolkitRetrieveResponseSchema,
|
|
11
12
|
ToolkitRetrieveCategoriesResponse,
|
|
@@ -13,6 +14,75 @@ import {
|
|
|
13
14
|
} from '../../types/toolkit.types';
|
|
14
15
|
import { transform } from '../transform';
|
|
15
16
|
|
|
17
|
+
type RawToolkitAuthConfigDetailFields = NonNullable<
|
|
18
|
+
RawToolkitRetrieveResponse['auth_config_details']
|
|
19
|
+
>[number]['fields'];
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A single auth form field as the API ships it, across all four groups. The
|
|
23
|
+
* generated client declares each group as its own interface; they are identical
|
|
24
|
+
* today, so the union costs nothing and keeps the mapping honest if they ever
|
|
25
|
+
* drift apart.
|
|
26
|
+
*
|
|
27
|
+
* Most keys are already camelCase on the wire (`displayName`), but `is_secret`
|
|
28
|
+
* and `legacy_template_name` are not, so the field needs an explicit mapping
|
|
29
|
+
* instead of a pass-through: a pass-through leaves them under keys the schema
|
|
30
|
+
* does not know and zod strips them while validating.
|
|
31
|
+
*
|
|
32
|
+
* `type-tests/toolkit-auth-field-mapping.test-d.ts` fails the build when the
|
|
33
|
+
* generated client grows a key in any of the four groups that is not listed
|
|
34
|
+
* there.
|
|
35
|
+
*/
|
|
36
|
+
type RawToolkitAuthField =
|
|
37
|
+
| RawToolkitAuthConfigDetailFields['auth_config_creation']['required'][number]
|
|
38
|
+
| RawToolkitAuthConfigDetailFields['auth_config_creation']['optional'][number]
|
|
39
|
+
| RawToolkitAuthConfigDetailFields['connected_account_initiation']['required'][number]
|
|
40
|
+
| RawToolkitAuthConfigDetailFields['connected_account_initiation']['optional'][number];
|
|
41
|
+
|
|
42
|
+
const transformToolkitAuthField = (field: RawToolkitAuthField): ToolkitAuthField => ({
|
|
43
|
+
name: field.name,
|
|
44
|
+
displayName: field.displayName,
|
|
45
|
+
description: field.description,
|
|
46
|
+
type: field.type,
|
|
47
|
+
required: field.required,
|
|
48
|
+
// Optional keys are spread conditionally rather than assigned. Assigning an
|
|
49
|
+
// absent wire key creates an own property holding `undefined`, which silently
|
|
50
|
+
// beats a caller's fallback in `{ default: 'fallback', ...field }`. JSON never
|
|
51
|
+
// carries an explicit `undefined`, so checking for it is the same test as
|
|
52
|
+
// asking whether the server sent the key at all — and `null` and `false`
|
|
53
|
+
// survive.
|
|
54
|
+
...(field.default !== undefined && { default: field.default }),
|
|
55
|
+
...(field.is_secret !== undefined && { isSecret: field.is_secret }),
|
|
56
|
+
...(field.legacy_template_name !== undefined && {
|
|
57
|
+
legacyTemplateName: field.legacy_template_name,
|
|
58
|
+
}),
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Normalize one field group to empty lists when the API omits it, the way this
|
|
63
|
+
* repo's own docs pipeline does (`docs/lib/toolkit-api.ts` defaults a missing
|
|
64
|
+
* group to `{ required: [], optional: [] }`).
|
|
65
|
+
*
|
|
66
|
+
* The generated client declares both groups and both lists as required, but a
|
|
67
|
+
* response that omits one reached zod and failed validation there. Mapping it
|
|
68
|
+
* eagerly would instead throw a `TypeError` on the property access, before
|
|
69
|
+
* validation, turning a handled validation error into a crash of
|
|
70
|
+
* `toolkits.get()`. Normalizing also leaves the other group usable, which is
|
|
71
|
+
* typically the one the caller asked for.
|
|
72
|
+
*/
|
|
73
|
+
const transformToolkitAuthFieldGroup = (
|
|
74
|
+
group:
|
|
75
|
+
| {
|
|
76
|
+
required?: Array<RawToolkitAuthField> | null;
|
|
77
|
+
optional?: Array<RawToolkitAuthField> | null;
|
|
78
|
+
}
|
|
79
|
+
| null
|
|
80
|
+
| undefined
|
|
81
|
+
) => ({
|
|
82
|
+
required: (group?.required ?? []).map(transformToolkitAuthField),
|
|
83
|
+
optional: (group?.optional ?? []).map(transformToolkitAuthField),
|
|
84
|
+
});
|
|
85
|
+
|
|
16
86
|
export const transformToolkitListResponse = (
|
|
17
87
|
response: RawToolkitListResponse
|
|
18
88
|
): ToolKitListResponse => {
|
|
@@ -70,9 +140,16 @@ export const transformToolkitRetrieveResponse = (
|
|
|
70
140
|
authConfigDetails: response.auth_config_details?.map(authConfig => ({
|
|
71
141
|
name: authConfig.name,
|
|
72
142
|
mode: authConfig.mode,
|
|
143
|
+
...(authConfig.auth_hint_url !== undefined && {
|
|
144
|
+
authHintUrl: authConfig.auth_hint_url,
|
|
145
|
+
}),
|
|
73
146
|
fields: {
|
|
74
|
-
authConfigCreation:
|
|
75
|
-
|
|
147
|
+
authConfigCreation: transformToolkitAuthFieldGroup(
|
|
148
|
+
authConfig.fields?.auth_config_creation
|
|
149
|
+
),
|
|
150
|
+
connectedAccountInitiation: transformToolkitAuthFieldGroup(
|
|
151
|
+
authConfig.fields?.connected_account_initiation
|
|
152
|
+
),
|
|
76
153
|
},
|
|
77
154
|
proxy: {
|
|
78
155
|
baseUrl: authConfig.proxy?.base_url,
|