@devries-cameron20 / composio Mirror · read-only / commits / 655f24e90
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 22, 00:45 UTC

fix(core): restore safeParse validation, use AuthSchemeEnum from SDK types

Keep the codebase convention of Zod safeParse + ValidationError for consistency with other methods. The Zod schema uses AuthSchemeEnum (already defined in authConfigs.types.ts) instead of hardcoded strings. The TypeScript type is re-exported from @composio/client for type safety.

Dhawal Upadhyay committed Apr 10, 2026 at 10:55 UTC 655f24e90a1ceb994614259e543f95b3b6dcdf77
3 files changed +29 -3
ts/packages/core/src/models/ConnectedAccounts.ts
+9 -1
@@ -28,6 +28,7 @@ import {
28 ConnectedAccountRefreshOptions,
29 ConnectedAccountRefreshOptionsSchema,
30 UpdateConnectedAccountParams,
31 + UpdateConnectedAccountParamsSchema,
32 } from '../types/connectedAccounts.types';
33 import { ConnectionRequest } from '../types/connectionRequest.types';
34 import { createConnectionRequest } from './ConnectionRequest';
@@ -492,6 +493,13 @@ export class ConnectedAccounts {
493 nanoid: string,
494 params: UpdateConnectedAccountParams,
495 ): Promise<ConnectedAccountPatchResponse> {
495 - return this.client.connectedAccounts.patch(nanoid, params);
496 + const parsedParams = UpdateConnectedAccountParamsSchema.safeParse(params);
497 + if (!parsedParams.success) {
498 + throw new ValidationError('Failed to parse connected account update params', {
499 + cause: parsedParams.error,
500 + });
501 + }
502 +
503 + return this.client.connectedAccounts.patch(nanoid, parsedParams.data);
504 }
505 }
ts/packages/core/src/types/connectedAccounts.types.ts
+14 -2
@@ -213,8 +213,20 @@ export const ConnectedAccountRefreshOptionsSchema = z.object({
213 });
214 export type ConnectedAccountRefreshOptions = z.infer<typeof ConnectedAccountRefreshOptionsSchema>;
215
216 -// Re-export the Stainless-generated type directly so it stays in sync
217 -// with the API contract without hardcoding auth scheme strings.
216 +// Use the Stainless-generated type as the source of truth for update params.
217 +// The Zod schema mirrors it for runtime validation (consistent with other methods in this file).
218 export type { ConnectedAccountPatchParams as UpdateConnectedAccountParams } from '@composio/client/resources/connected-accounts';
219
220 +export const UpdateConnectedAccountParamsSchema = z.object({
221 + alias: z.string().optional(),
222 + connection: z
223 + .object({
224 + state: z.object({
225 + authScheme: AuthSchemeEnum,
226 + val: z.record(z.unknown()),
227 + }),
228 + })
229 + .optional(),
230 +});
231 +
232 // UpdateConnectedAccountResponse is now ConnectedAccountPatchResponse from @composio/client
ts/packages/core/test/connectedAccounts/connectedAccounts.test.ts
+6
@@ -984,6 +984,12 @@ describe('ConnectedAccounts', () => {
984 expect(extendedMockClient.connectedAccounts.patch).toHaveBeenCalledWith(nanoid, params);
985 expect(result).toEqual({ success: true, id: nanoid, status: 'ACTIVE' });
986 });
987 +
988 + it('should throw ValidationError for invalid params', async () => {
989 + await expect(connectedAccounts.update('conn_abc123', { alias: 123 } as any)).rejects.toThrow(
990 + 'Failed to parse connected account update params'
991 + );
992 + });
993 });
994
995 describe('link', () => {