@devries-cameron20 / composio Mirror · read-only / commits / 123b8d6f3
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 21:00 UTC

fix(connected-accounts): address review feedback on #3424

Six code-review nits from the multi-agent review on PR #3424: P1.1 — `experimental_updateAcl(composio, id, opts)` doesn't match the `experimental_createTool` precedent it cited. That export is a *pure factory* (returns a value object, no client, no I/O), whereas `updateAcl` takes a client and performs a network call. Costs the current shape was paying: - Awkward call site (composio passed as first arg every time) - Bypassed `telemetry.instrument(this, 'ConnectedAccounts')` — the proxy only wraps class methods - Diverged from the Python sibling (#3412) which mounts at `composio.experimental.update_acl(id, opts)` Moved to `composio.experimental.updateAcl(id, opts)` as a method on a new `Experimental` class. Top-level `experimental_*` prefix is now reserved for stateless factories, matching the Python parity. P2.2 — `ToolRouterSession.authorize` was re-inlining the same camelCase→snake_case wire mapping that `ConnectedAccounts.link` already encoded. Extracted `serializeExperimentalForWire` / `serializeAclConfigForWire` into `models/Experimental.ts` and imported both call sites from there. Next field added to the experimental block now lands in one place. P2.3 — `AuthorizeOptionsSchema` was a structural duplicate of `ConnectedAccountExperimentalSchema`. Composed from the canonical schema instead. P2.4 — Substring match `acl_config_for_shared is only valid on SHARED` extracted to `ACL_ONLY_FOR_SHARED_ERROR_FRAGMENT` in `models/Experimental.ts` and reused from `ConnectedAccounts.link`, `ToolRouterSession.authorize`, and `Experimental.updateAcl`. Single source of truth so a server-side message tweak doesn't silently downgrade three call sites to generic BadRequestError. P2.5 — `ConnectedAccountsErrors.ts` `possibleFixes` strings on `ComposioSharedAccessDeniedError` and `ComposioSharedConnectionNotAccessibleError` were pointing at `composio.connectedAccounts.updateAcl()` (method now removed). Rewrote to `composio.experimental.updateAcl()` so the typed-error hint compiles. P2.6 — Telemetry bypass auto-fixed by P1.1. `Experimental` is now an instrumented class; methods on it get the same telemetry proxy as `ConnectedAccounts`. P2.7 — Inline `import('../types/connectedAccounts.types')` type at the old `serializeExperimentalForWire` declaration is gone with the function move. Sibling models use plain top-level imports. Tests: 919/919 pass, typecheck clean. **Push-back on remaining findings:** - P2.8 (`ComposioFailedToCreateConnectedAccountLink` missing `Error` suffix) — pre-existing naming, not introduced by this PR. Rename with back-compat alias is bigger scope; deferred. - P2.9 (TS Zod caps vs Python no caps) — the TS caps are a UX win (clear ValidationError vs server 400). Better direction is adding the caps to Python in a follow-up, not dropping them from TS. - All P3 nice-to-haves deferred. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

venkat82 committed May 13, 2026 at 18:39 UTC 123b8d6f344965f0436f32ea10a4406f3ccb7c5a
7 files changed +241 -191
ts/packages/core/src/composio.ts
+10
@@ -5,6 +5,7 @@ import { Toolkits } from './models/Toolkits';
5 import { Triggers } from './models/Triggers';
6 import { AuthConfigs } from './models/AuthConfigs';
7 import { ConnectedAccounts } from './models/ConnectedAccounts';
8 +import { Experimental } from './models/Experimental';
9 import { MCP } from './models/MCP';
10 import { telemetry } from './telemetry/Telemetry';
11 import { getSDKConfig, getToolkitVersionsFromEnv } from './utils/sdk';
@@ -194,6 +195,14 @@ export class Composio<
195 authConfigs: AuthConfigs;
196 /** Manage authenticated connections */
197 connectedAccounts: ConnectedAccounts;
198 + /**
199 + * Experimental SDK methods whose shape may change in future releases.
200 + * Houses stateful operations like {@link Experimental.updateAcl} that
201 + * take a client and perform I/O. Stateless experimental factories
202 + * (e.g. `experimental_createTool`) stay at the top level.
203 + * @experimental
204 + */
205 + experimental: Experimental;
206 /** Model Context Protocol server management */
207 mcp: MCP;
208 /**
@@ -331,6 +340,7 @@ export class Composio<
340 fileDownloadDir: this.config.fileDownloadDir,
341 });
342 this.connectedAccounts = new ConnectedAccounts(this.client);
343 + this.experimental = new Experimental(this.client);
344 this.toolRouter = new ToolRouter(this.client, this.config);
345
346 /**
ts/packages/core/src/errors/ConnectedAccountsErrors.ts
+2 -2
@@ -74,7 +74,7 @@ export class ComposioSharedAccessDeniedError extends ComposioError {
74 code: ConnectedAccountErrorCodes.SHARED_ACCESS_DENIED,
75 statusCode: 403,
76 possibleFixes: options.possibleFixes || [
77 - "Ask the connection's creator to grant access via composio.connectedAccounts.updateAcl() — set allowAllUsers, add the userId to allowedUserIds, or remove it from notAllowedUserIds.",
77 + "Ask the connection's creator to grant access via composio.experimental.updateAcl() — set allowAllUsers, add the userId to allowedUserIds, or remove it from notAllowedUserIds.",
78 ],
79 });
80 this.name = 'ComposioSharedAccessDeniedError';
@@ -119,7 +119,7 @@ export class ComposioSharedConnectionNotAccessibleError extends ComposioError {
119 code: ConnectedAccountErrorCodes.SHARED_CONNECTION_NOT_ACCESSIBLE,
120 statusCode: 400,
121 possibleFixes: options.possibleFixes || [
122 - "Grant the session user access via composio.connectedAccounts.updateAcl() on the pinned connection, or pin a different connection the user can use.",
122 + 'Grant the session user access via composio.experimental.updateAcl() on the pinned connection, or pin a different connection the user can use.',
123 ],
124 });
125 this.name = 'ComposioSharedConnectionNotAccessibleError';
ts/packages/core/src/index.ts
+6 -2
@@ -38,8 +38,12 @@ export { default as logger } from './utils/logger';
38 export { createCustomTool as experimental_createTool } from './models/CustomTool';
39 export { createCustomToolkit as experimental_createToolkit } from './models/CustomTool';
40
41 -// Experimental shared connected accounts — shape may change in future releases
42 -export { experimental_updateAcl } from './models/ConnectedAccounts';
41 +// Experimental shared connected accounts — shape may change in future releases.
42 +// `updateAcl` is mounted as a method on `composio.experimental.updateAcl(...)`
43 +// because it takes a client and performs I/O. The `Experimental` class
44 +// itself is re-exported so callers can type their own composio handles
45 +// (e.g. in test helpers).
46 +export { Experimental } from './models/Experimental';
47
48 // Error handling exports
49 export * from './errors';
ts/packages/core/src/models/ConnectedAccounts.ts
+4 -141
@@ -9,8 +9,6 @@ import ComposioClient, { BadRequestError } from '@composio/client';
9 import {
10 ConnectedAccountCreateResponse,
11 ConnectedAccountDeleteResponse,
12 - ConnectedAccountPatchParams,
13 - ConnectedAccountPatchResponse,
12 ConnectedAccountRefreshParams,
13 ConnectedAccountRefreshResponse,
14 ConnectedAccountUpdateStatusParams,
@@ -32,11 +30,10 @@ import {
30 ConnectedAccountRefreshOptionsSchema,
31 UpdateConnectedAccountParams,
32 UpdateConnectedAccountParamsSchema,
35 - UpdateConnectedAccountAclParams,
36 - UpdateConnectedAccountAclParamsSchema,
33 } from '../types/connectedAccounts.types';
34 import { ConnectionRequest } from '../types/connectionRequest.types';
35 import { createConnectionRequest } from './ConnectionRequest';
36 +import { ACL_ONLY_FOR_SHARED_ERROR_FRAGMENT, serializeExperimentalForWire } from './Experimental';
37 import { ValidationError } from '../errors/ValidationErrors';
38 import { telemetry } from '../telemetry/Telemetry';
39 import {
@@ -56,51 +53,6 @@ import { ConnectionData } from '../types/connectedAccountAuthStates.types';
53 // warning on every initiate() call.
54 let _legacyInitiateWarningEmitted = false;
55
59 -/**
60 - * Serialise the SDK's `aclConfigForShared` (camelCase) to the wire's
61 - * `acl_config_for_shared` block. Returns `undefined` when the caller
62 - * didn't pass anything (PATCH-style "don't touch ACL"); returns `{}`
63 - * when the caller passed an explicit empty object — both mean
64 - * deny-by-default, but the explicit form preserves the caller's intent
65 - * in network traces.
66 - */
67 -export function serializeAclConfigForWire(
68 - acl:
69 - | {
70 - allowAllUsers?: boolean;
71 - allowedUserIds?: string[];
72 - notAllowedUserIds?: string[];
73 - }
74 - | undefined
75 -): LinkCreateParams.Experimental.ACLConfigForShared | undefined {
76 - if (acl === undefined) return undefined;
77 - return {
78 - ...(acl.allowAllUsers !== undefined && { allow_all_users: acl.allowAllUsers }),
79 - ...(acl.allowedUserIds !== undefined && { allowed_user_ids: acl.allowedUserIds }),
80 - ...(acl.notAllowedUserIds !== undefined && { not_allowed_user_ids: acl.notAllowedUserIds }),
81 - };
82 -}
83 -
84 -/**
85 - * Serialise the SDK's `experimental` block (camelCase) into the wire's
86 - * `experimental` block (snake_case). Returns `undefined` when the caller
87 - * didn't pass anything.
88 - */
89 -function serializeExperimentalForWire(
90 - experimental: import('../types/connectedAccounts.types').ConnectedAccountExperimental | undefined
91 -): LinkCreateParams.Experimental | undefined {
92 - if (experimental === undefined) return undefined;
93 - const aclWire = serializeAclConfigForWire(experimental.aclConfigForShared);
94 - const wire: LinkCreateParams.Experimental = {};
95 - if (experimental.accountType !== undefined) {
96 - wire.account_type = experimental.accountType;
97 - }
98 - if (aclWire !== undefined) {
99 - wire.acl_config_for_shared = aclWire;
100 - }
101 - return wire;
102 -}
103 -
56 /**
57 * ConnectedAccounts class
58 *
@@ -446,7 +398,7 @@ export class ConnectedAccounts {
398 if (
399 error instanceof BadRequestError &&
400 typeof error.message === 'string' &&
449 - error.message.includes('acl_config_for_shared is only valid on SHARED')
401 + error.message.includes(ACL_ONLY_FOR_SHARED_ERROR_FRAGMENT)
402 ) {
403 throw new ComposioAclOnlyForSharedError(error.message, { cause: error });
404 }
@@ -639,8 +591,8 @@ export class ConnectedAccounts {
591 /**
592 * Enable or disable a connected account. Accepts `{ enabled: boolean }`.
593 *
642 - * For ACL writes on SHARED connections, see `experimental_updateAcl`
643 - * exported at the top level of `@composio/core`.
594 + * For ACL writes on SHARED connections, see
595 + * `composio.experimental.updateAcl()`.
596 *
597 * @param {string} nanoid - The unique identifier of the connected account
598 * @param {UpdateConnectedAccountParams} params - The update parameters
@@ -666,92 +618,3 @@ export class ConnectedAccounts {
618 return this.client.connectedAccounts.updateStatus(nanoid, parsedParams.data);
619 }
620 }
669 -
670 -/**
671 - * Update the per-user ACL on a SHARED connected account. Experimental —
672 - * shape may change in future releases.
673 - *
674 - * Only meaningful for SHARED connections — calling this on a PRIVATE
675 - * connection raises `ComposioAclOnlyForSharedError` (400). ACL writes
676 - * require the connection's creator or an API key.
677 - *
678 - * PATCH semantics: omit a field to leave it unchanged; pass an empty array
679 - * to clear an allow/deny list. At least one field must be provided.
680 - *
681 - * Resolution rule (deny wins):
682 - * 1. requesting `userId` in `notAllowedUserIds` → DENY
683 - * 2. `allowAllUsers === true` → ALLOW
684 - * 3. requesting `userId` in `allowedUserIds` → ALLOW
685 - * 4. otherwise → DENY
686 - *
687 - * @example
688 - * ```typescript
689 - * import { Composio, experimental_updateAcl } from '@composio/core';
690 - *
691 - * const composio = new Composio({ apiKey: '...' });
692 - *
693 - * // Allow every userId to use this connection
694 - * await experimental_updateAcl(composio, 'ca_abc', { allowAllUsers: true });
695 - *
696 - * // Everyone except a specific user
697 - * await experimental_updateAcl(composio, 'ca_abc', {
698 - * allowAllUsers: true,
699 - * notAllowedUserIds: ['user_bob'],
700 - * });
701 - *
702 - * // Targeted allow
703 - * await experimental_updateAcl(composio, 'ca_abc', {
704 - * allowedUserIds: ['user_alice', 'user_bob'],
705 - * });
706 - *
707 - * // Revoke a previously-granted allow list (back to deny-by-default)
708 - * await experimental_updateAcl(composio, 'ca_abc', { allowedUserIds: [] });
709 - * ```
710 - *
711 - * **Empty-array semantics — read carefully.** Passing `[]` for either
712 - * list **replaces** the list, it does not extend it:
713 - *
714 - * - `allowedUserIds: []` → revoke all previously-granted user IDs (state
715 - * reverts to deny-by-default unless `allowAllUsers` is true).
716 - * - `notAllowedUserIds: []` → **clears the deny list**, which silently
717 - * re-grants access to users you previously blocked. Always pair an
718 - * empty deny list with a deliberate audit of the allow side.
719 - *
720 - * @returns The PATCH response (`{ id, status, success }`). To read the
721 - * updated ACL block, call `composio.connectedAccounts.get(nanoid)`
722 - * after the promise resolves and inspect `account.experimental?.aclConfigForShared`.
723 - */
724 -export async function experimental_updateAcl(
725 - composio: { getClient: () => ComposioClient },
726 - nanoid: string,
727 - params: UpdateConnectedAccountAclParams
728 -): Promise<ConnectedAccountPatchResponse> {
729 - const parsedParams = UpdateConnectedAccountAclParamsSchema.safeParse(params);
730 - if (!parsedParams.success) {
731 - throw new ValidationError('Failed to parse connected account ACL update params', {
732 - cause: parsedParams.error,
733 - });
734 - }
735 -
736 - const client = composio.getClient();
737 - const body: ConnectedAccountPatchParams = {
738 - experimental: {
739 - acl_config_for_shared: serializeAclConfigForWire(parsedParams.data),
740 - },
741 - };
742 -
743 - try {
744 - return await client.connectedAccounts.patch(nanoid, body);
745 - } catch (error) {
746 - // Same ACL-on-PRIVATE rejection the create path can hit — surface
747 - // it as a typed error.
748 - if (
749 - error instanceof BadRequestError &&
750 - typeof error.message === 'string' &&
751 - error.message.includes('acl_config_for_shared is only valid on SHARED')
752 - ) {
753 - throw new ComposioAclOnlyForSharedError(error.message, { cause: error });
754 - }
755 - throw error;
756 - }
757 -}
ts/packages/core/src/models/Experimental.ts new
+198
@@ -0,0 +1,198 @@
1 +/**
2 + * @fileoverview The `composio.experimental` namespace. Houses experimental
3 + * SDK methods whose shape may change in future releases.
4 + *
5 + * For experimental stateless factories (e.g. `experimental_createTool`),
6 + * see the top-level `experimental_*` exports from `@composio/core`.
7 + * Anything that takes a Composio client and performs I/O belongs here.
8 + */
9 +import ComposioClient, { BadRequestError } from '@composio/client';
10 +import {
11 + ConnectedAccountPatchParams,
12 + ConnectedAccountPatchResponse,
13 + ConnectedAccountListParams as ConnectedAccountListParamsRaw,
14 +} from '@composio/client/resources/connected-accounts';
15 +import { LinkCreateParams } from '@composio/client/resources/link';
16 +import { SessionLinkParams } from '@composio/client/resources/tool-router/session/session';
17 +import {
18 + ConnectedAccountExperimental,
19 + UpdateConnectedAccountAclParams,
20 + UpdateConnectedAccountAclParamsSchema,
21 +} from '../types/connectedAccounts.types';
22 +import { ValidationError } from '../errors/ValidationErrors';
23 +import { ComposioAclOnlyForSharedError } from '../errors';
24 +import { telemetry } from '../telemetry/Telemetry';
25 +
26 +/**
27 + * Server-side 400 message the API uses to reject ACL writes against a
28 + * PRIVATE connection. Substring-matched in `updateAcl` here, and in the
29 + * sibling `connectedAccounts.link()` / `session.authorize()` call sites
30 + * — kept as a single constant so a server-side message tweak only
31 + * requires one edit.
32 + */
33 +export const ACL_ONLY_FOR_SHARED_ERROR_FRAGMENT = 'acl_config_for_shared is only valid on SHARED';
34 +
35 +/**
36 + * Structural shape of the wire's experimental block on requests. Both
37 + * `LinkCreateParams.Experimental` and `SessionLinkParams.Experimental`
38 + * (Stainless-generated, nominally distinct) accept this shape.
39 + */
40 +type ExperimentalWire = {
41 + account_type?: 'PRIVATE' | 'SHARED';
42 + acl_config_for_shared?: {
43 + allow_all_users?: boolean;
44 + allowed_user_ids?: string[];
45 + not_allowed_user_ids?: string[];
46 + };
47 +};
48 +
49 +/**
50 + * Serialise the SDK's `aclConfigForShared` (camelCase) to the wire's
51 + * `acl_config_for_shared` block. Returns `undefined` when the caller
52 + * didn't pass anything (PATCH-style "don't touch ACL"); returns `{}`
53 + * when the caller passed an explicit empty object.
54 + */
55 +export function serializeAclConfigForWire(
56 + acl:
57 + | {
58 + allowAllUsers?: boolean;
59 + allowedUserIds?: string[];
60 + notAllowedUserIds?: string[];
61 + }
62 + | undefined
63 +): NonNullable<ExperimentalWire['acl_config_for_shared']> | undefined {
64 + if (acl === undefined) return undefined;
65 + return {
66 + ...(acl.allowAllUsers !== undefined && { allow_all_users: acl.allowAllUsers }),
67 + ...(acl.allowedUserIds !== undefined && { allowed_user_ids: acl.allowedUserIds }),
68 + ...(acl.notAllowedUserIds !== undefined && { not_allowed_user_ids: acl.notAllowedUserIds }),
69 + };
70 +}
71 +
72 +/**
73 + * Serialise the SDK's `experimental` options block (camelCase) to the
74 + * wire's `experimental` block (snake_case). Used by both
75 + * `connectedAccounts.link()` and `session.authorize()`. Returns
76 + * `undefined` when the caller didn't pass the block at all.
77 + */
78 +export function serializeExperimentalForWire(
79 + experimental: ConnectedAccountExperimental | undefined
80 +): ExperimentalWire | undefined {
81 + if (experimental === undefined) return undefined;
82 + const aclWire = serializeAclConfigForWire(experimental.aclConfigForShared);
83 + const wire: ExperimentalWire = {};
84 + if (experimental.accountType !== undefined) {
85 + wire.account_type = experimental.accountType;
86 + }
87 + if (aclWire !== undefined) {
88 + wire.acl_config_for_shared = aclWire;
89 + }
90 + return wire;
91 +}
92 +
93 +/**
94 + * `composio.experimental` namespace. Mirrors the Python SDK's
95 + * `composio.experimental` mount, with one method per experimental
96 + * surface. **Shape may change in future releases.**
97 + */
98 +export class Experimental {
99 + private client: ComposioClient;
100 +
101 + constructor(client: ComposioClient) {
102 + this.client = client;
103 + telemetry.instrument(this, 'Experimental');
104 + }
105 +
106 + /**
107 + * Update the per-user ACL on a SHARED connected account.
108 + * **Experimental — shape may change in future releases.**
109 + *
110 + * Only meaningful for SHARED connections — calling this on a PRIVATE
111 + * connection raises `ComposioAclOnlyForSharedError` (400). ACL writes
112 + * require the connection's creator or an API key.
113 + *
114 + * PATCH semantics: omit a field to leave it unchanged; pass an empty
115 + * array to clear an allow/deny list. At least one field must be
116 + * provided.
117 + *
118 + * Resolution rule (deny wins):
119 + * 1. requesting `userId` in `notAllowedUserIds` → DENY
120 + * 2. `allowAllUsers === true` → ALLOW
121 + * 3. requesting `userId` in `allowedUserIds` → ALLOW
122 + * 4. otherwise → DENY
123 + *
124 + * @example
125 + * ```typescript
126 + * import { Composio } from '@composio/core';
127 + *
128 + * const composio = new Composio({ apiKey: '...' });
129 + *
130 + * // Allow every userId to use this connection
131 + * await composio.experimental.updateAcl('ca_abc', { allowAllUsers: true });
132 + *
133 + * // Everyone except a specific user
134 + * await composio.experimental.updateAcl('ca_abc', {
135 + * allowAllUsers: true,
136 + * notAllowedUserIds: ['user_bob'],
137 + * });
138 + *
139 + * // Targeted allow
140 + * await composio.experimental.updateAcl('ca_abc', {
141 + * allowedUserIds: ['user_alice', 'user_bob'],
142 + * });
143 + *
144 + * // Revoke a previously-granted allow list (back to deny-by-default)
145 + * await composio.experimental.updateAcl('ca_abc', { allowedUserIds: [] });
146 + * ```
147 + *
148 + * **Empty-array semantics — read carefully.** Passing `[]` for either
149 + * list **replaces** the list, it does not extend it:
150 + *
151 + * - `allowedUserIds: []` → revoke all previously-granted user IDs (state
152 + * reverts to deny-by-default unless `allowAllUsers` is true).
153 + * - `notAllowedUserIds: []` → **clears the deny list**, which silently
154 + * re-grants access to users you previously blocked. Always pair an
155 + * empty deny list with a deliberate audit of the allow side.
156 + *
157 + * @returns The PATCH response (`{ id, status, success }`). To read
158 + * the updated ACL block, call
159 + * `composio.connectedAccounts.get(nanoid)` after the promise
160 + * resolves and inspect `account.experimental?.aclConfigForShared`.
161 + */
162 + async updateAcl(
163 + nanoid: string,
164 + params: UpdateConnectedAccountAclParams
165 + ): Promise<ConnectedAccountPatchResponse> {
166 + const parsedParams = UpdateConnectedAccountAclParamsSchema.safeParse(params);
167 + if (!parsedParams.success) {
168 + throw new ValidationError('Failed to parse connected account ACL update params', {
169 + cause: parsedParams.error,
170 + });
171 + }
172 +
173 + const body: ConnectedAccountPatchParams = {
174 + experimental: {
175 + acl_config_for_shared: serializeAclConfigForWire(parsedParams.data),
176 + },
177 + };
178 +
179 + try {
180 + return await this.client.connectedAccounts.patch(nanoid, body);
181 + } catch (error) {
182 + if (
183 + error instanceof BadRequestError &&
184 + typeof error.message === 'string' &&
185 + error.message.includes(ACL_ONLY_FOR_SHARED_ERROR_FRAGMENT)
186 + ) {
187 + throw new ComposioAclOnlyForSharedError(error.message, { cause: error });
188 + }
189 + throw error;
190 + }
191 + }
192 +}
193 +
194 +// Re-exports so the wire-shape helpers stay reachable from the existing
195 +// callsites in `models/` without bouncing through `experimental.ts` —
196 +// the canonical home is here, but the imports look unchanged at the
197 +// caller.
198 +export type { LinkCreateParams, SessionLinkParams, ConnectedAccountListParamsRaw };
ts/packages/core/src/models/ToolRouterSession.ts
+8 -34
@@ -27,12 +27,12 @@ import { SessionMetaToolOptions } from '../types/modifiers.types';
27 import { ConnectionRequest } from '../types/connectionRequest.types';
28 import { createConnectionRequest } from './ConnectionRequest';
29 import {
30 - ConnectedAccountAclConfigSchema,
30 + ConnectedAccountExperimentalSchema,
31 ConnectedAccountStatuses,
32 ConnectedAccountType,
33 - ConnectedAccountTypeSchema,
33 ConnectedAccountAclConfig,
34 } from '../types/connectedAccounts.types';
35 +import { ACL_ONLY_FOR_SHARED_ERROR_FRAGMENT, serializeExperimentalForWire } from './Experimental';
36 import { z } from 'zod/v3';
37 import { transform } from '../utils/transform';
38 import { ToolkitConnectionStateSchema } from '../types/toolRouter.types';
@@ -83,12 +83,7 @@ export const DIRECT_CUSTOM_TOOL_DESCRIPTION_PREFIX =
83 const AuthorizeOptionsSchema = z.object({
84 callbackUrl: z.string().optional(),
85 alias: z.string().optional(),
86 - experimental: z
87 - .object({
88 - accountType: ConnectedAccountTypeSchema.optional(),
89 - aclConfigForShared: ConnectedAccountAclConfigSchema.optional(),
90 - })
91 - .optional(),
86 + experimental: ConnectedAccountExperimentalSchema.optional(),
87 });
88
89 export class ToolRouterSession<
@@ -360,35 +355,14 @@ export class ToolRouterSession<
355 });
356 }
357 const opts = requestOptions.data;
363 - const experimentalIn = opts.experimental;
364 - const aclWire: SessionLinkParams.Experimental.ACLConfigForShared | undefined =
365 - experimentalIn?.aclConfigForShared === undefined
366 - ? undefined
367 - : {
368 - ...(experimentalIn.aclConfigForShared.allowAllUsers !== undefined && {
369 - allow_all_users: experimentalIn.aclConfigForShared.allowAllUsers,
370 - }),
371 - ...(experimentalIn.aclConfigForShared.allowedUserIds !== undefined && {
372 - allowed_user_ids: experimentalIn.aclConfigForShared.allowedUserIds,
373 - }),
374 - ...(experimentalIn.aclConfigForShared.notAllowedUserIds !== undefined && {
375 - not_allowed_user_ids: experimentalIn.aclConfigForShared.notAllowedUserIds,
376 - }),
377 - };
378 - const experimentalWire: SessionLinkParams.Experimental | undefined =
379 - experimentalIn === undefined
380 - ? undefined
381 - : {
382 - ...(experimentalIn.accountType !== undefined && {
383 - account_type: experimentalIn.accountType,
384 - }),
385 - ...(aclWire !== undefined && { acl_config_for_shared: aclWire }),
386 - };
358 + const experimentalWire = serializeExperimentalForWire(opts.experimental);
359 const body: SessionLinkParams = {
360 toolkit,
361 ...(opts.callbackUrl !== undefined && { callback_url: opts.callbackUrl }),
362 ...(opts.alias !== undefined && { alias: opts.alias }),
391 - ...(experimentalWire !== undefined && { experimental: experimentalWire }),
363 + ...(experimentalWire !== undefined && {
364 + experimental: experimentalWire as SessionLinkParams.Experimental,
365 + }),
366 };
367
368 let response;
@@ -400,7 +374,7 @@ export class ToolRouterSession<
374 if (
375 error instanceof BadRequestError &&
376 typeof error.message === 'string' &&
403 - error.message.includes('acl_config_for_shared is only valid on SHARED')
377 + error.message.includes(ACL_ONLY_FOR_SHARED_ERROR_FRAGMENT)
378 ) {
379 throw new ComposioAclOnlyForSharedError(error.message, { cause: error });
380 }
ts/packages/core/test/connectedAccounts/connectedAccounts.test.ts
+13 -12
@@ -1,6 +1,7 @@
1 import { describe, it, expect, vi, beforeEach } from 'vitest';
2 import { mockClient } from '../utils/mocks/client.mock';
3 -import { ConnectedAccounts, experimental_updateAcl } from '../../src/models/ConnectedAccounts';
3 +import { ConnectedAccounts } from '../../src/models/ConnectedAccounts';
4 +import { Experimental } from '../../src/models/Experimental';
5 import ComposioClient from '@composio/client';
6 import { ConnectedAccountRetrieveResponse } from '@composio/client/resources/connected-accounts.mjs';
7 import {
@@ -1677,11 +1678,11 @@ describe('ConnectedAccounts', () => {
1678 });
1679 });
1680
1680 - describe('experimental_updateAcl', () => {
1681 - let composioHandle: { getClient: () => typeof extendedMockClient };
1681 + describe('composio.experimental.updateAcl', () => {
1682 + let experimental: Experimental;
1683
1684 beforeEach(() => {
1684 - composioHandle = { getClient: () => extendedMockClient };
1685 + experimental = new Experimental(extendedMockClient as unknown as ComposioClient);
1686 });
1687
1688 it('serializes PATCH body under experimental.acl_config_for_shared', async () => {
@@ -1691,7 +1692,7 @@ describe('ConnectedAccounts', () => {
1692 success: true,
1693 });
1694
1694 - const result = await experimental_updateAcl(composioHandle, 'ca_abc', {
1695 + const result = await experimental.updateAcl('ca_abc', {
1696 allowAllUsers: true,
1697 notAllowedUserIds: ['user_bob'],
1698 });
@@ -1714,7 +1715,7 @@ describe('ConnectedAccounts', () => {
1715 success: true,
1716 });
1717
1717 - await experimental_updateAcl(composioHandle, 'ca_abc', { allowedUserIds: ['user_alice'] });
1718 + await experimental.updateAcl('ca_abc', { allowedUserIds: ['user_alice'] });
1719
1720 expect(extendedMockClient.connectedAccounts.patch).toHaveBeenCalledWith('ca_abc', {
1721 experimental: {
@@ -1730,7 +1731,7 @@ describe('ConnectedAccounts', () => {
1731 success: true,
1732 });
1733
1733 - await experimental_updateAcl(composioHandle, 'ca_abc', { allowedUserIds: [] });
1734 + await experimental.updateAcl('ca_abc', { allowedUserIds: [] });
1735
1736 expect(extendedMockClient.connectedAccounts.patch).toHaveBeenCalledWith('ca_abc', {
1737 experimental: { acl_config_for_shared: { allowed_user_ids: [] } },
@@ -1738,7 +1739,7 @@ describe('ConnectedAccounts', () => {
1739 });
1740
1741 it('rejects an empty params object via the refine', async () => {
1741 - await expect(experimental_updateAcl(composioHandle, 'ca_abc', {})).rejects.toMatchObject({
1742 + await expect(experimental.updateAcl('ca_abc', {})).rejects.toMatchObject({
1743 name: 'ValidationError',
1744 });
1745 expect(extendedMockClient.connectedAccounts.patch).not.toHaveBeenCalled();
@@ -1755,7 +1756,7 @@ describe('ConnectedAccounts', () => {
1756 );
1757
1758 await expect(
1758 - experimental_updateAcl(composioHandle, 'ca_abc', { allowAllUsers: true })
1759 + experimental.updateAcl('ca_abc', { allowAllUsers: true })
1760 ).rejects.toBeInstanceOf(ComposioAclOnlyForSharedError);
1761 });
1762
@@ -1763,9 +1764,9 @@ describe('ConnectedAccounts', () => {
1764 const otherError = new Error('connection lost');
1765 extendedMockClient.connectedAccounts.patch.mockRejectedValueOnce(otherError);
1766
1766 - await expect(
1767 - experimental_updateAcl(composioHandle, 'ca_abc', { allowAllUsers: true })
1768 - ).rejects.toBe(otherError);
1767 + await expect(experimental.updateAcl('ca_abc', { allowAllUsers: true })).rejects.toBe(
1768 + otherError
1769 + );
1770 });
1771 });
1772 });