29
ConnectedAccountRefreshOptionsSchema,
30
UpdateConnectedAccountParams,
31
UpdateConnectedAccountParamsSchema,
32
+ UpdateConnectedAccountAclParams,
33
+ UpdateConnectedAccountAclParamsSchema,
34
} from '../types/connectedAccounts.types';
35
import { ConnectionRequest } from '../types/connectionRequest.types';
36
import { createConnectionRequest } from './ConnectionRequest';
52
// warning on every initiate() call.
53
let _legacyInitiateWarningEmitted = false;
54
55
+// Wire-level fields added by Hermes #9860 / #9882 (account_type) and #9902
56
+// (ACL). Once @composio/client is regenerated against a backend spec that
57
+// includes these, this local extension can be removed and we can rely on the
58
+// generated `LinkCreateParams` directly.
59
+type LinkCreateBodyWithAcl = ConnectedAccountCreateParamsRaw extends never
60
+ ? never
61
+ : Record<string, unknown> & {
62
+ auth_config_id: string;
63
+ user_id: string;
64
+ alias?: string;
65
+ callback_url?: string;
66
+ account_type?: 'PRIVATE' | 'SHARED';
67
+ allow_all_users?: boolean;
68
+ allowed_user_ids?: string[];
69
+ not_allowed_user_ids?: string[];
70
+ };
71
+
72
+// Wire-level body for PATCH /connected_accounts/{id} with ACL fields
73
+// (Hermes #9902). Mirrors the same forward-compat pattern as
74
+// `LinkCreateBodyWithAcl` above.
75
+type ConnectedAccountPatchBodyWithAcl = {
76
+ alias?: string;
77
+ allow_all_users?: boolean;
78
+ allowed_user_ids?: string[];
79
+ not_allowed_user_ids?: string[];
80
+};
81
+
82
/**
83
* ConnectedAccounts class
84
*
395
);
396
}
397
398
+ const opts = requestOptions.data;
399
+ const body: LinkCreateBodyWithAcl = {
400
+ auth_config_id: authConfigId,
401
+ user_id: userId,
402
+ ...(opts.callbackUrl && { callback_url: opts.callbackUrl }),
403
+ ...(opts.alias != null && { alias: opts.alias }),
404
+ ...(opts.accountType !== undefined && { account_type: opts.accountType }),
405
+ ...(opts.allowAllUsers !== undefined && { allow_all_users: opts.allowAllUsers }),
406
+ ...(opts.allowedUserIds !== undefined && { allowed_user_ids: opts.allowedUserIds }),
407
+ ...(opts.notAllowedUserIds !== undefined && {
408
+ not_allowed_user_ids: opts.notAllowedUserIds,
409
+ }),
410
+ };
411
+
412
try {
370
- const response = await this.client.link.create({
371
- auth_config_id: authConfigId,
372
- user_id: userId,
373
- ...(requestOptions?.data.callbackUrl && { callback_url: requestOptions.data.callbackUrl }),
374
- ...(requestOptions?.data.alias != null && { alias: requestOptions.data.alias }),
375
- });
413
+ // Cast retained until @composio/client adds account_type / ACL fields
414
+ // to LinkCreateParams.
415
+ const response = await this.client.link.create(body as unknown as Parameters<
416
+ typeof this.client.link.create
417
+ >[0]);
418
419
const connectionRequest = createConnectionRequest(
420
this.client,
636
637
return this.client.connectedAccounts.updateStatus(nanoid, parsedParams.data);
638
}
639
+
640
+ /**
641
+ * Update the per-user ACL on a SHARED connected account.
642
+ *
643
+ * Only meaningful for SHARED connections — the backend rejects ACL writes
644
+ * on PRIVATE rows with `ComposioAclOnlyForSharedError` (400). Auth gate is
645
+ * creator-or-API-key (a non-creator project member updating an alias on a
646
+ * SHARED row still works via {@link update}, but ACL writes do not).
647
+ *
648
+ * PATCH semantics: omit a field to leave it unchanged; pass an empty array
649
+ * to clear an allow/deny list. At least one field must be provided.
650
+ *
651
+ * Resolution rule (deny wins):
652
+ * 1. requesting userId in `notAllowedUserIds` → DENY
653
+ * 2. `allowAllUsers === true` → ALLOW
654
+ * 3. requesting userId in `allowedUserIds` → ALLOW
655
+ * 4. otherwise → DENY
656
+ *
657
+ * @example
658
+ * ```typescript
659
+ * // Open access to everyone in the project
660
+ * await composio.connectedAccounts.updateAcl('ca_abc', { allowAllUsers: true });
661
+ *
662
+ * // Everyone except a specific user
663
+ * await composio.connectedAccounts.updateAcl('ca_abc', {
664
+ * allowAllUsers: true,
665
+ * notAllowedUserIds: ['user_bob'],
666
+ * });
667
+ *
668
+ * // Targeted allow
669
+ * await composio.connectedAccounts.updateAcl('ca_abc', {
670
+ * allowedUserIds: ['user_alice', 'user_bob'],
671
+ * });
672
+ *
673
+ * // Revoke a previously-granted allow list (back to deny-by-default)
674
+ * await composio.connectedAccounts.updateAcl('ca_abc', { allowedUserIds: [] });
675
+ * ```
676
+ */
677
+ async updateAcl(nanoid: string, params: UpdateConnectedAccountAclParams): Promise<void> {
678
+ const parsedParams = UpdateConnectedAccountAclParamsSchema.safeParse(params);
679
+ if (!parsedParams.success) {
680
+ throw new ValidationError('Failed to parse connected account ACL update params', {
681
+ cause: parsedParams.error,
682
+ });
683
+ }
684
+
685
+ const body: ConnectedAccountPatchBodyWithAcl = {
686
+ ...(parsedParams.data.allowAllUsers !== undefined && {
687
+ allow_all_users: parsedParams.data.allowAllUsers,
688
+ }),
689
+ ...(parsedParams.data.allowedUserIds !== undefined && {
690
+ allowed_user_ids: parsedParams.data.allowedUserIds,
691
+ }),
692
+ ...(parsedParams.data.notAllowedUserIds !== undefined && {
693
+ not_allowed_user_ids: parsedParams.data.notAllowedUserIds,
694
+ }),
695
+ };
696
+
697
+ // Cast retained until @composio/client adds ACL fields to
698
+ // ConnectedAccountPatchParams.
699
+ await this.client.connectedAccounts.patch(
700
+ nanoid,
701
+ body as unknown as Parameters<typeof this.client.connectedAccounts.patch>[1]
702
+ );
703
+ }
704
}