@composio/core 0.31.0 → 0.33.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-9Vlb4XaS.mjs → CustomTool-B4dQn2M5.mjs} +1 -1
- package/dist/{CustomTool-Ds5aLDth.d.mts → CustomTool-C2kvAvzk.d.mts} +1 -1
- package/dist/{FileModifierErrors-WrqokuIF.mjs → FileModifierErrors-D-AKc3ds.mjs} +1 -1
- package/dist/{SsrfErrors-BSVMW915.mjs → SsrfErrors-BekZPeWY.mjs} +59 -12
- package/dist/{Telemetry-a7SOQXcg.mjs → Telemetry-CcCuFVUb.mjs} +2 -2
- package/dist/composio-BqE615oV.d.mts +20365 -0
- package/dist/{customTool.types-DHxXBU6E.d.mts → customTool.types-DnyEZmlx.d.mts} +510 -33
- package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +20 -12
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +28 -10
- package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +96 -40
- package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +8 -6
- package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +4 -3
- package/dist/docs/reference/sdk-reference/typescript/index.mdx +4 -2
- package/dist/docs/reference/sdk-reference/typescript/keyring.mdx +6 -3
- package/dist/docs/reference/sdk-reference/typescript/logs.mdx +5 -3
- package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +53 -42
- package/dist/docs/reference/sdk-reference/typescript/meta.json +1 -0
- package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +5 -14
- package/dist/docs/reference/sdk-reference/typescript/session-configs.mdx +5 -3
- package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +7 -5
- package/dist/docs/reference/sdk-reference/typescript/session-webhooks.mdx +64 -0
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +16 -16
- package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +36 -8
- package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +14 -11
- package/dist/docs/reference/sdk-reference/typescript/tools.mdx +16 -18
- package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +42 -30
- package/dist/docs/reference/sdk-reference/typescript/usage.mdx +6 -4
- package/dist/docs/reference/sdk-reference/typescript/webhook-endpoints.mdx +9 -7
- package/dist/docs/reference/sdk-reference/typescript/webhook-subscriptions.mdx +13 -9
- package/dist/docs/reference/sdk-reference/typescript/webhooks.mdx +3 -1
- package/dist/{errors-xC13uvaA.mjs → errors-CtIKA9BH.mjs} +2 -2
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-CAwIbWYH.mjs → fileUtils.node-DPMtE0ER.mjs} +7 -71
- package/dist/index.d.mts +7 -245
- package/dist/index.mjs +573 -251
- package/dist/jsonSchema-CDHLYm7d.d.mts +237 -0
- package/dist/{jsonSchema-Cc4EtHRw.mjs → jsonSchema-CfZwBS13.mjs} +7 -3
- package/dist/models/Files.node.mjs +3 -3
- package/dist/{sensitiveFileUploadPaths-CSyJ3Ku8.mjs → sensitiveFileUploadPaths-6NcnFSyX.mjs} +82 -85
- package/dist/{ssrfGuard.node-CdIkwqVu.mjs → ssrfGuard.node-B749ae5Q.mjs} +1 -1
- package/dist/{types-DcdZy5Nc.d.mts → types-Cwr_Makk.d.mts} +2 -2
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
- package/dist/utils/json-schema.d.mts +2 -1
- package/dist/utils/json-schema.mjs +2 -1
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.node.mjs +5 -5
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
- package/dist/utils/ssrfGuard.node.mjs +1 -1
- package/dist/utils/ssrfGuard.workerd.mjs +1 -1
- package/package.json +6 -6
- package/src/composio.ts +26 -7
- package/src/errors/ComposioError.ts +3 -2
- package/src/index.ts +19 -0
- package/src/lib/toolRouterParams.ts +38 -14
- package/src/models/AuthConfigs.ts +10 -3
- package/src/models/ConnectedAccounts.ts +101 -28
- package/src/models/CustomTool.ts +0 -10
- package/src/models/Keyring.ts +2 -1
- package/src/models/MCP.ts +43 -35
- package/src/models/SessionWebhooks.ts +136 -0
- package/src/models/ToolRouter.ts +39 -4
- package/src/models/ToolRouterSession.ts +2 -2
- package/src/models/ToolRouterSessionFileMount.ts +3 -1
- package/src/models/Toolkits.ts +1 -0
- package/src/models/Tools.ts +4 -8
- package/src/models/Triggers.ts +48 -213
- package/src/models/Webhooks.ts +2 -0
- package/src/provider/ComposioProvider.ts +0 -1
- package/src/telemetry/BatchProcessor.ts +1 -1
- package/src/telemetry/Telemetry.ts +1 -1
- package/src/types/connectedAccountAuthStates.types.ts +0 -1
- package/src/types/connectedAccounts.types.ts +59 -1
- package/src/types/provider.types.ts +0 -1
- package/src/types/sessionWebhooks.types.ts +292 -0
- package/src/types/toolRouter.types.ts +35 -5
- package/src/types/triggers.types.ts +4 -0
- package/src/utils/crypto.ts +6 -5
- package/src/utils/env.ts +2 -5
- package/src/utils/fileUtils.node.ts +5 -86
- package/src/utils/json-schema.ts +6 -0
- package/src/utils/jsonSchema.ts +17 -4
- package/src/utils/logger.ts +19 -9
- package/src/utils/mime.ts +25 -385
- package/src/utils/mimeTables.generated.ts +356 -0
- package/src/utils/pusher.ts +5 -2
- package/src/utils/readResponseBody.ts +30 -17
- package/src/utils/transformers/authConfigs.ts +0 -1
- package/src/utils/userCallback.ts +3 -1
- package/src/utils/webhookVerification.ts +211 -0
- package/dist/composio-Ba89XGHL.d.mts +0 -9736
package/src/composio.ts
CHANGED
|
@@ -31,7 +31,6 @@ import { checkForLatestVersionFromNPM } from './utils/version';
|
|
|
31
31
|
import { OpenAIProvider } from './provider/OpenAIProvider';
|
|
32
32
|
import { version } from '../package.json';
|
|
33
33
|
import type { ComposioRequestHeaders } from './types/composio.types';
|
|
34
|
-
import type { ComposioRequestOptions } from './types/requestOptions.types';
|
|
35
34
|
import { Files } from '#files';
|
|
36
35
|
import { getClientIdentity } from './utils/session';
|
|
37
36
|
import { ToolkitVersionParam } from './types/tool.types';
|
|
@@ -460,19 +459,31 @@ export class Composio<
|
|
|
460
459
|
*
|
|
461
460
|
* @example
|
|
462
461
|
* ```typescript
|
|
462
|
+
* import { Composio } from '@composio/core';
|
|
463
|
+
*
|
|
463
464
|
* // Initialize with default configuration
|
|
464
465
|
* const composio = new Composio();
|
|
466
|
+
* ```
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* ```typescript
|
|
470
|
+
* import { Composio } from '@composio/core';
|
|
465
471
|
*
|
|
466
472
|
* // Initialize with custom API key and base URL
|
|
467
473
|
* const composio = new Composio({
|
|
468
474
|
* apiKey: 'your-api-key',
|
|
469
475
|
* baseURL: 'https://api.composio.dev'
|
|
470
476
|
* });
|
|
477
|
+
* ```
|
|
471
478
|
*
|
|
472
|
-
*
|
|
479
|
+
* @example
|
|
480
|
+
* ```typescript
|
|
481
|
+
* import { Composio, OpenAIProvider } from '@composio/core';
|
|
482
|
+
*
|
|
483
|
+
* // Initialize with an explicit provider
|
|
473
484
|
* const composio = new Composio({
|
|
474
485
|
* apiKey: 'your-api-key',
|
|
475
|
-
* provider: new
|
|
486
|
+
* provider: new OpenAIProvider()
|
|
476
487
|
* });
|
|
477
488
|
* ```
|
|
478
489
|
*/
|
|
@@ -626,7 +637,7 @@ export class Composio<
|
|
|
626
637
|
|
|
627
638
|
// Check for the latest version of the Composio SDK from NPM.
|
|
628
639
|
if (!this.config.disableVersionCheck) {
|
|
629
|
-
checkForLatestVersionFromNPM(version);
|
|
640
|
+
void checkForLatestVersionFromNPM(version);
|
|
630
641
|
}
|
|
631
642
|
}
|
|
632
643
|
|
|
@@ -678,6 +689,8 @@ export class Composio<
|
|
|
678
689
|
*
|
|
679
690
|
* @example
|
|
680
691
|
* ```typescript
|
|
692
|
+
* import { Composio } from '@composio/core';
|
|
693
|
+
*
|
|
681
694
|
* // Create a base Composio instance
|
|
682
695
|
* const composio = new Composio({
|
|
683
696
|
* apiKey: 'your-api-key'
|
|
@@ -693,7 +706,7 @@ export class Composio<
|
|
|
693
706
|
* });
|
|
694
707
|
*
|
|
695
708
|
* // Use the session for making API calls with the custom headers
|
|
696
|
-
* await composioWithCustomHeaders.tools.
|
|
709
|
+
* await composioWithCustomHeaders.tools.getRawComposioTools({ toolkits: ['github'] });
|
|
697
710
|
* ```
|
|
698
711
|
*/
|
|
699
712
|
createSession(options?: { headers?: ComposioRequestHeaders }): Composio<TProvider> {
|
|
@@ -717,14 +730,20 @@ export class Composio<
|
|
|
717
730
|
* @returns {Promise<void>} A promise that resolves when all pending telemetry has been sent.
|
|
718
731
|
*
|
|
719
732
|
* @example
|
|
720
|
-
* ```typescript
|
|
733
|
+
* ```typescript nocheck="Cloudflare Worker handler; the checker has no Workers Env or ExecutionContext types"
|
|
734
|
+
* import { Composio } from '@composio/core';
|
|
735
|
+
*
|
|
721
736
|
* // In a Cloudflare Worker, use ctx.waitUntil to ensure telemetry is flushed
|
|
722
737
|
* export default {
|
|
723
738
|
* async fetch(request: Request, env: Env, ctx: ExecutionContext) {
|
|
724
739
|
* const composio = new Composio({ apiKey: env.COMPOSIO_API_KEY });
|
|
725
740
|
*
|
|
726
741
|
* // Do your work...
|
|
727
|
-
* const result = await composio.tools.execute(
|
|
742
|
+
* const result = await composio.tools.execute('GITHUB_GET_REPOS', {
|
|
743
|
+
* userId: 'user_123',
|
|
744
|
+
* version: '20250909_00',
|
|
745
|
+
* arguments: { owner: 'composio' },
|
|
746
|
+
* });
|
|
728
747
|
*
|
|
729
748
|
* // Ensure telemetry flushes before worker terminates
|
|
730
749
|
* ctx.waitUntil(composio.flush());
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* @module errors/ComposioError
|
|
9
9
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error}
|
|
10
10
|
*/
|
|
11
|
+
import { describeThrown } from '../utils/userCallback';
|
|
11
12
|
import pc from 'picocolors';
|
|
12
13
|
import { ZodError } from 'zod/v3';
|
|
13
14
|
import { APIError } from '@composio/client';
|
|
@@ -183,7 +184,7 @@ export class ComposioError extends Error {
|
|
|
183
184
|
? sanitizeApiErrorText(rawCause.message)
|
|
184
185
|
: rawCause instanceof Error
|
|
185
186
|
? rawCause.message
|
|
186
|
-
: sanitizeApiErrorText(
|
|
187
|
+
: sanitizeApiErrorText(describeThrown(rawCause));
|
|
187
188
|
}
|
|
188
189
|
|
|
189
190
|
// Add code if exists
|
|
@@ -424,7 +425,7 @@ export class ComposioError extends Error {
|
|
|
424
425
|
|
|
425
426
|
if (error !== null && error !== undefined) {
|
|
426
427
|
logger.error(pc.gray('Error details:'));
|
|
427
|
-
logger.error(' ' + pc.white(
|
|
428
|
+
logger.error(' ' + pc.white(describeThrown(error)));
|
|
428
429
|
}
|
|
429
430
|
|
|
430
431
|
logger.error(''); // Add a trailing empty line
|
package/src/index.ts
CHANGED
|
@@ -54,6 +54,7 @@ export { RemoteFile } from './models/RemoteFile';
|
|
|
54
54
|
export { createConnectionRequest } from './models/ConnectionRequest';
|
|
55
55
|
export { ToolRouterSession } from './models/ToolRouterSession';
|
|
56
56
|
export { Sessions } from './models/Sessions';
|
|
57
|
+
export { SessionWebhooks } from './models/SessionWebhooks';
|
|
57
58
|
export { SessionConfigs } from './models/SessionConfigs';
|
|
58
59
|
export * from './types/provider.types';
|
|
59
60
|
export * from './types/customTool.types';
|
|
@@ -66,6 +67,24 @@ export * from './types/toolkit.types';
|
|
|
66
67
|
export * from './types/triggers.types';
|
|
67
68
|
export * from './types/webhookEvents.types';
|
|
68
69
|
export * from './types/webhooks.types';
|
|
70
|
+
export { SessionWebhookEventTypes } from './types/sessionWebhooks.types';
|
|
71
|
+
export type {
|
|
72
|
+
ParseSessionWebhookParams,
|
|
73
|
+
SessionWebhookAfterExecuteEvent,
|
|
74
|
+
SessionWebhookAfterExecuteResponse,
|
|
75
|
+
SessionWebhookBeforeExecuteEvent,
|
|
76
|
+
SessionWebhookBeforeExecuteResponse,
|
|
77
|
+
SessionWebhookBlockResponse,
|
|
78
|
+
SessionWebhookEvent,
|
|
79
|
+
SessionWebhookEventType,
|
|
80
|
+
SessionWebhookHttpRequest,
|
|
81
|
+
SessionWebhookHttpRequestOverride,
|
|
82
|
+
SessionWebhookHttpResponse,
|
|
83
|
+
SessionWebhookHttpResponseOverride,
|
|
84
|
+
SessionWebhookMetadata,
|
|
85
|
+
SessionWebhookToolCall,
|
|
86
|
+
SessionWebhookToolResponse,
|
|
87
|
+
} from './types/sessionWebhooks.types';
|
|
69
88
|
export * from './types/logs.types';
|
|
70
89
|
export * from './types/usage.types';
|
|
71
90
|
export * from './types/keyring.types';
|
|
@@ -9,9 +9,6 @@ import {
|
|
|
9
9
|
ToolRouterToolsParam,
|
|
10
10
|
ToolRouterConfigManageConnectionsSchema,
|
|
11
11
|
ToolRouterCreateSessionConfigSchema,
|
|
12
|
-
ToolRouterToolkitsParamSchema,
|
|
13
|
-
ToolRouterToolkitsDisabledConfigSchema,
|
|
14
|
-
ToolRouterToolkitsEnabledConfigSchema,
|
|
15
12
|
ToolRouterUpdateSessionConfigSchema,
|
|
16
13
|
ToolRouterUpdateManageConnectionsConfig,
|
|
17
14
|
ToolRouterUpdateManageConnectionsSchema,
|
|
@@ -41,7 +38,7 @@ const requireApprovalParam = <T extends string>(
|
|
|
41
38
|
requireApproval !== undefined ? { require_approval: requireApproval } : {};
|
|
42
39
|
|
|
43
40
|
export const transformToolRouterToolsParams = (
|
|
44
|
-
params?: Record<string, ToolRouterToolsParam | ToolRouterConfigTools>
|
|
41
|
+
params?: Record<string, ToolRouterToolsParam | ToolRouterConfigTools>
|
|
45
42
|
): Record<string, SessionToolsEntry> | undefined => {
|
|
46
43
|
if (!params) {
|
|
47
44
|
return undefined;
|
|
@@ -104,7 +101,7 @@ export const transformToolRouterTagsParams = (
|
|
|
104
101
|
};
|
|
105
102
|
|
|
106
103
|
export const transformToolRouterManageConnectionsParams = (
|
|
107
|
-
params?:
|
|
104
|
+
params?: z.infer<typeof ToolRouterConfigManageConnectionsSchema>
|
|
108
105
|
): NonNullable<SessionCreateParams['manage_connections']> => {
|
|
109
106
|
if (params === undefined) {
|
|
110
107
|
// Default case when params is undefined
|
|
@@ -137,7 +134,7 @@ export const transformToolRouterManageConnectionsParams = (
|
|
|
137
134
|
|
|
138
135
|
export const resolveToolRouterSandboxConfig = (
|
|
139
136
|
config: Pick<ParsedCreateSessionConfig, 'sandbox' | 'workbench'>
|
|
140
|
-
): ParsedCreateSessionConfig['sandbox']
|
|
137
|
+
): ParsedCreateSessionConfig['sandbox'] => {
|
|
141
138
|
if (config.sandbox !== undefined && config.workbench !== undefined) {
|
|
142
139
|
throw new ValidationError(
|
|
143
140
|
'Pass either sandbox or workbench, not both. workbench is a backwards-compatible alias for sandbox.'
|
|
@@ -186,7 +183,7 @@ export const resolveLocalToolsOptions = (
|
|
|
186
183
|
};
|
|
187
184
|
|
|
188
185
|
export const transformToolRouterSandboxParams = (
|
|
189
|
-
params?: ParsedCreateSessionConfig['sandbox']
|
|
186
|
+
params?: ParsedCreateSessionConfig['sandbox']
|
|
190
187
|
): NonNullable<SessionCreateParams['workbench']> | undefined => {
|
|
191
188
|
if (!params) {
|
|
192
189
|
return undefined;
|
|
@@ -235,14 +232,40 @@ export type SessionPatchExperimentalBody = WithNull<
|
|
|
235
232
|
'permissions' | 'link_url_overwrite' | 'fast_mode' | 'submit_feedback'
|
|
236
233
|
>;
|
|
237
234
|
|
|
235
|
+
type GeneratedSessionHook = NonNullable<SessionCreateParams['hooks']>[number];
|
|
236
|
+
|
|
237
|
+
type SessionWebhookHandlerBody = {
|
|
238
|
+
type: 'webhook';
|
|
239
|
+
fallback_action: 'block' | 'continue';
|
|
240
|
+
timeout_ms?: number;
|
|
241
|
+
};
|
|
242
|
+
|
|
238
243
|
/**
|
|
239
|
-
* `hooks` as sent on create and update
|
|
240
|
-
*
|
|
244
|
+
* `hooks` as sent on create and update. Wider than the generated type by the
|
|
245
|
+
* `webhook` handler, which `@composio/client` does not declare until it picks
|
|
246
|
+
* up ComposioHQ/platform#15328.
|
|
241
247
|
*/
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
248
|
+
type SessionHooksBody = Array<
|
|
249
|
+
Omit<GeneratedSessionHook, 'handler'> & {
|
|
250
|
+
handler: GeneratedSessionHook['handler'] | SessionWebhookHandlerBody;
|
|
251
|
+
}
|
|
252
|
+
>;
|
|
253
|
+
|
|
254
|
+
export const transformToolRouterHooksParams = (hooks: ToolRouterHook[]): SessionHooksBody =>
|
|
255
|
+
hooks.map(({ appliesTo, handler, ...hook }) => ({
|
|
256
|
+
...hook,
|
|
257
|
+
applies_to: appliesTo,
|
|
258
|
+
handler:
|
|
259
|
+
handler.type === 'webhook'
|
|
260
|
+
? {
|
|
261
|
+
type: handler.type,
|
|
262
|
+
fallback_action: handler.fallbackAction,
|
|
263
|
+
...(handler.timeoutMs !== undefined && { timeout_ms: handler.timeoutMs }),
|
|
264
|
+
}
|
|
265
|
+
: handler,
|
|
266
|
+
}));
|
|
267
|
+
|
|
268
|
+
export type SessionCreateBody = Omit<SessionCreateParams, 'hooks'> & { hooks?: SessionHooksBody };
|
|
246
269
|
|
|
247
270
|
/**
|
|
248
271
|
* Request body of `session.update()`. Extends the generated `SessionPatchParams`
|
|
@@ -255,8 +278,9 @@ export type SessionPatchBody = Omit<
|
|
|
255
278
|
SessionPatchParams,
|
|
256
279
|
'toolkits' | 'tools' | 'tags' | 'auth_configs' | 'preload' | 'search' | 'execute'
|
|
257
280
|
>,
|
|
258
|
-
'manage_connections' | 'multi_account' | 'experimental'
|
|
281
|
+
'manage_connections' | 'multi_account' | 'experimental' | 'hooks'
|
|
259
282
|
> & {
|
|
283
|
+
hooks?: SessionHooksBody | null;
|
|
260
284
|
manage_connections?: SessionPatchManageConnectionsBody | null;
|
|
261
285
|
multi_account?: SessionPatchMultiAccountBody | null;
|
|
262
286
|
experimental?: SessionPatchExperimentalBody | null;
|
|
@@ -104,15 +104,19 @@ export class AuthConfigs {
|
|
|
104
104
|
* @returns {Promise<CreateAuthConfigResponse>} Created auth config
|
|
105
105
|
*
|
|
106
106
|
* @example
|
|
107
|
+
* import { AuthConfigTypes } from '@composio/core';
|
|
108
|
+
*
|
|
107
109
|
* // Use a specific Composio-managed app; omit managedAppId for the toolkit's default
|
|
108
110
|
* const { composioManagedAuth } = await composio.toolkits.get('slack');
|
|
109
|
-
* const slackAuthConfig = await authConfigs.create('slack', {
|
|
111
|
+
* const slackAuthConfig = await composio.authConfigs.create('slack', {
|
|
110
112
|
* type: AuthConfigTypes.COMPOSIO_MANAGED,
|
|
111
113
|
* managedAppId: composioManagedAuth?.find(app => !app.isDefault)?.managedAppId,
|
|
112
114
|
* });
|
|
113
115
|
*
|
|
114
116
|
* @example
|
|
115
|
-
*
|
|
117
|
+
* import { AuthConfigTypes, AuthSchemeTypes } from '@composio/core';
|
|
118
|
+
*
|
|
119
|
+
* const authConfig = await composio.authConfigs.create('my-toolkit', {
|
|
116
120
|
* type: AuthConfigTypes.CUSTOM,
|
|
117
121
|
* name: 'My Custom Auth Config',
|
|
118
122
|
* authScheme: AuthSchemeTypes.API_KEY,
|
|
@@ -232,11 +236,14 @@ export class AuthConfigs {
|
|
|
232
236
|
* apiKey: 'new-api-key-value'
|
|
233
237
|
* }
|
|
234
238
|
* });
|
|
239
|
+
* ```
|
|
235
240
|
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```typescript
|
|
236
243
|
* // Update a default auth config with new scopes
|
|
237
244
|
* const updatedConfig = await composio.authConfigs.update('auth_abc123', {
|
|
238
245
|
* type: 'default',
|
|
239
|
-
* scopes:
|
|
246
|
+
* scopes: 'read:user,repo'
|
|
240
247
|
* });
|
|
241
248
|
* ```
|
|
242
249
|
*/
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* @date 2025-05-05
|
|
6
6
|
* @module ConnectedAccounts
|
|
7
7
|
*/
|
|
8
|
+
import { z } from 'zod/v3';
|
|
8
9
|
import ComposioClient, { BadRequestError, ConflictError } from '@composio/client';
|
|
9
10
|
import type { APIPromise } from '@composio/client';
|
|
10
11
|
import {
|
|
@@ -34,6 +35,8 @@ import {
|
|
|
34
35
|
ConnectedAccountCompleteAuthParams,
|
|
35
36
|
ConnectedAccountCompleteAuthParamsSchema,
|
|
36
37
|
ConnectedAccountCompleteAuthResponse,
|
|
38
|
+
PatchConnectedAccountParams,
|
|
39
|
+
PatchConnectedAccountParamsSchema,
|
|
37
40
|
UpdateConnectedAccountAclParams,
|
|
38
41
|
UpdateConnectedAccountParams,
|
|
39
42
|
UpdateConnectedAccountParamsSchema,
|
|
@@ -67,6 +70,13 @@ import { ComposioRequestOptions } from '../types/requestOptions.types';
|
|
|
67
70
|
import { withCancellation } from '../utils/cancellation';
|
|
68
71
|
import { ComposioRequestCancelledError } from '../errors/SDKErrors';
|
|
69
72
|
|
|
73
|
+
const UpdateRequestSchema = z.union([
|
|
74
|
+
PatchConnectedAccountParamsSchema.transform(body => ({ endpoint: 'patch', body }) as const),
|
|
75
|
+
UpdateConnectedAccountParamsSchema.strict().transform(
|
|
76
|
+
body => ({ endpoint: 'status', body }) as const
|
|
77
|
+
),
|
|
78
|
+
]);
|
|
79
|
+
|
|
70
80
|
// One-time-per-process guard so long-running services don't spam the deprecation
|
|
71
81
|
// warning on every initiate() call.
|
|
72
82
|
let _legacyInitiateWarningEmitted = false;
|
|
@@ -171,6 +181,8 @@ export class ConnectedAccounts {
|
|
|
171
181
|
*
|
|
172
182
|
* @example
|
|
173
183
|
* ```typescript
|
|
184
|
+
* import { AuthScheme } from '@composio/core';
|
|
185
|
+
*
|
|
174
186
|
* // For OAuth2 authentication
|
|
175
187
|
* const connectionRequest = await composio.connectedAccounts.initiate(
|
|
176
188
|
* 'user_123',
|
|
@@ -183,17 +195,27 @@ export class ConnectedAccounts {
|
|
|
183
195
|
* })
|
|
184
196
|
* }
|
|
185
197
|
* );
|
|
198
|
+
* ```
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```typescript
|
|
202
|
+
* import { AuthScheme } from '@composio/core';
|
|
186
203
|
*
|
|
187
204
|
* // For API Key authentication
|
|
188
205
|
* const connectionRequest = await composio.connectedAccounts.initiate(
|
|
189
206
|
* 'user_123',
|
|
190
207
|
* 'auth_config_123',
|
|
191
208
|
* {
|
|
192
|
-
* config: AuthScheme.
|
|
209
|
+
* config: AuthScheme.APIKey({
|
|
193
210
|
* api_key: 'your_api_key'
|
|
194
211
|
* })
|
|
195
212
|
* }
|
|
196
213
|
* );
|
|
214
|
+
* ```
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```typescript
|
|
218
|
+
* import { AuthScheme } from '@composio/core';
|
|
197
219
|
*
|
|
198
220
|
* // For Basic authentication
|
|
199
221
|
* const connectionRequest = await composio.connectedAccounts.initiate(
|
|
@@ -470,7 +492,10 @@ export class ConnectedAccounts {
|
|
|
470
492
|
* ```typescript
|
|
471
493
|
* // Wait for a connection to complete with default timeout
|
|
472
494
|
* const connectedAccount = await composio.connectedAccounts.waitForConnection('conn_123abc');
|
|
495
|
+
* ```
|
|
473
496
|
*
|
|
497
|
+
* @example
|
|
498
|
+
* ```typescript
|
|
474
499
|
* // Wait with a custom timeout of 2 minutes
|
|
475
500
|
* const connectedAccount = await composio.connectedAccounts.waitForConnection('conn_123abc', 120000);
|
|
476
501
|
* ```
|
|
@@ -658,11 +683,16 @@ export class ConnectedAccounts {
|
|
|
658
683
|
*
|
|
659
684
|
* @example
|
|
660
685
|
* ```typescript
|
|
661
|
-
* //
|
|
662
|
-
*
|
|
663
|
-
*
|
|
664
|
-
* sessionUri
|
|
665
|
-
* }
|
|
686
|
+
* // Your verifier route, after authenticating the user
|
|
687
|
+
* export async function GET(request: Request) {
|
|
688
|
+
* // The session URI arrives as the `session_uri` query parameter of the verifier redirect
|
|
689
|
+
* const sessionUri = new URL(request.url).searchParams.get('session_uri') ?? '';
|
|
690
|
+
* const { connectedAccountId, toolkitSlug } = await composio.connectedAccounts.completeAuth({
|
|
691
|
+
* userId: 'user_123',
|
|
692
|
+
* sessionUri,
|
|
693
|
+
* });
|
|
694
|
+
* return new Response(`Connected ${toolkitSlug}: ${connectedAccountId}`);
|
|
695
|
+
* }
|
|
666
696
|
* ```
|
|
667
697
|
*/
|
|
668
698
|
async completeAuth(
|
|
@@ -702,10 +732,9 @@ export class ConnectedAccounts {
|
|
|
702
732
|
* enabled: true
|
|
703
733
|
* });
|
|
704
734
|
*
|
|
705
|
-
* // Disable a connected account
|
|
735
|
+
* // Disable a connected account
|
|
706
736
|
* const disabledAccount = await composio.connectedAccounts.updateStatus('conn_abc123', {
|
|
707
|
-
* enabled: false
|
|
708
|
-
* reason: 'Token expired'
|
|
737
|
+
* enabled: false
|
|
709
738
|
* });
|
|
710
739
|
* ```
|
|
711
740
|
*/
|
|
@@ -729,7 +758,7 @@ export class ConnectedAccounts {
|
|
|
729
758
|
* ```typescript
|
|
730
759
|
* // Enable a previously disabled connected account
|
|
731
760
|
* const enabledAccount = await composio.connectedAccounts.enable('conn_abc123');
|
|
732
|
-
* console.log(enabledAccount.
|
|
761
|
+
* console.log(enabledAccount.success); // true
|
|
733
762
|
* ```
|
|
734
763
|
*/
|
|
735
764
|
async enable(
|
|
@@ -751,13 +780,7 @@ export class ConnectedAccounts {
|
|
|
751
780
|
* ```typescript
|
|
752
781
|
* // Disable a connected account
|
|
753
782
|
* const disabledAccount = await composio.connectedAccounts.disable('conn_abc123');
|
|
754
|
-
* console.log(disabledAccount.
|
|
755
|
-
*
|
|
756
|
-
* // You can also use updateStatus with a reason
|
|
757
|
-
* // const disabledAccount = await composio.connectedAccounts.updateStatus('conn_abc123', {
|
|
758
|
-
* // enabled: false,
|
|
759
|
-
* // reason: 'No longer needed'
|
|
760
|
-
* // });
|
|
783
|
+
* console.log(disabledAccount.success); // true
|
|
761
784
|
* ```
|
|
762
785
|
*/
|
|
763
786
|
async disable(
|
|
@@ -808,34 +831,84 @@ export class ConnectedAccounts {
|
|
|
808
831
|
}
|
|
809
832
|
|
|
810
833
|
/**
|
|
811
|
-
*
|
|
834
|
+
* Update a connected account's alias, credentials, or both in one request.
|
|
835
|
+
* The response contains the account ID, status, and success flag.
|
|
812
836
|
*
|
|
813
|
-
*
|
|
837
|
+
* Pass `alias`, `connection`, or both. Set `alias` to an empty string to
|
|
838
|
+
* clear it. To update credentials, put the fields you want to change in
|
|
839
|
+
* `connection.state.val`. Set a field to `null` to remove it. Omitted fields
|
|
840
|
+
* keep their current values.
|
|
814
841
|
*
|
|
815
|
-
*
|
|
816
|
-
*
|
|
817
|
-
*
|
|
842
|
+
* Use `enable()` or `disable()` to change the account's status. The deprecated
|
|
843
|
+
* `update(id, { enabled })` overload accepts only `enabled` and logs a warning.
|
|
844
|
+
* The SDK throws `ValidationError` before sending a request if the input is
|
|
845
|
+
* empty or contains unsupported fields.
|
|
846
|
+
*
|
|
847
|
+
* Use `updateAcl()` to change access to a shared connected account.
|
|
848
|
+
*
|
|
849
|
+
* @param {string} nanoid - The connected account ID.
|
|
850
|
+
* @param {PatchConnectedAccountParams} params - The alias or credential fields to update.
|
|
851
|
+
* @returns {Promise<ConnectedAccountPatchResponse>}
|
|
818
852
|
*
|
|
819
853
|
* @example
|
|
820
854
|
* ```typescript
|
|
821
|
-
* //
|
|
822
|
-
* await composio.connectedAccounts.update('ca_abc123', {
|
|
855
|
+
* // Set an alias.
|
|
856
|
+
* await composio.connectedAccounts.update('ca_abc123', { alias: 'work-gmail' });
|
|
857
|
+
*
|
|
858
|
+
* // Clear the alias.
|
|
859
|
+
* await composio.connectedAccounts.update('ca_abc123', { alias: '' });
|
|
860
|
+
*
|
|
861
|
+
* // Replace the stored bearer token.
|
|
862
|
+
* await composio.connectedAccounts.update('ca_abc123', {
|
|
863
|
+
* connection: {
|
|
864
|
+
* state: {
|
|
865
|
+
* authScheme: 'BEARER_TOKEN',
|
|
866
|
+
* val: { token: 'new-access-token' },
|
|
867
|
+
* },
|
|
868
|
+
* },
|
|
869
|
+
* });
|
|
823
870
|
* ```
|
|
824
871
|
*/
|
|
825
872
|
async update(
|
|
826
873
|
nanoid: string,
|
|
827
|
-
params:
|
|
874
|
+
params: PatchConnectedAccountParams,
|
|
828
875
|
requestOptions?: ComposioRequestOptions
|
|
829
|
-
): Promise<
|
|
830
|
-
|
|
876
|
+
): Promise<ConnectedAccountPatchResponse>;
|
|
877
|
+
/**
|
|
878
|
+
* @deprecated Use `enable()` or `disable()` instead.
|
|
879
|
+
*/
|
|
880
|
+
async update(
|
|
881
|
+
nanoid: string,
|
|
882
|
+
params: UpdateConnectedAccountParams & { alias?: never; connection?: never },
|
|
883
|
+
requestOptions?: ComposioRequestOptions
|
|
884
|
+
): Promise<ConnectedAccountUpdateStatusResponse>;
|
|
885
|
+
async update(
|
|
886
|
+
nanoid: string,
|
|
887
|
+
params:
|
|
888
|
+
| PatchConnectedAccountParams
|
|
889
|
+
| (UpdateConnectedAccountParams & { alias?: never; connection?: never }),
|
|
890
|
+
requestOptions?: ComposioRequestOptions
|
|
891
|
+
): Promise<ConnectedAccountPatchResponse | ConnectedAccountUpdateStatusResponse> {
|
|
892
|
+
const parsedParams = UpdateRequestSchema.safeParse(params);
|
|
831
893
|
if (!parsedParams.success) {
|
|
832
894
|
throw new ValidationError('Failed to parse connected account update params', {
|
|
833
895
|
cause: parsedParams.error,
|
|
834
896
|
});
|
|
835
897
|
}
|
|
836
898
|
|
|
899
|
+
const request = parsedParams.data;
|
|
900
|
+
if (request.endpoint === 'status') {
|
|
901
|
+
logger.warn(
|
|
902
|
+
'connectedAccounts.update({ enabled }) is deprecated; use connectedAccounts.enable() or connectedAccounts.disable() instead.'
|
|
903
|
+
);
|
|
904
|
+
return withCancellation(
|
|
905
|
+
() => this.client.connectedAccounts.updateStatus(nanoid, request.body, requestOptions),
|
|
906
|
+
requestOptions?.signal
|
|
907
|
+
);
|
|
908
|
+
}
|
|
909
|
+
|
|
837
910
|
return withCancellation(
|
|
838
|
-
() => this.client.connectedAccounts.
|
|
911
|
+
() => this.client.connectedAccounts.patch(nanoid, request.body, requestOptions),
|
|
839
912
|
requestOptions?.signal
|
|
840
913
|
);
|
|
841
914
|
}
|
package/src/models/CustomTool.ts
CHANGED
|
@@ -52,16 +52,6 @@ export const LOCAL_TOOL_PREFIX = 'LOCAL_';
|
|
|
52
52
|
/** Maximum allowed length for the final prefixed slug. */
|
|
53
53
|
const MAX_SLUG_LENGTH = 60;
|
|
54
54
|
|
|
55
|
-
type InputParamsSchema = {
|
|
56
|
-
definitions: {
|
|
57
|
-
input: {
|
|
58
|
-
type: string;
|
|
59
|
-
properties: Record<string, unknown>;
|
|
60
|
-
required?: string[];
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
|
|
65
55
|
/**
|
|
66
56
|
* Compute the final slug length for a tool given its context.
|
|
67
57
|
* Returns the expected length of LOCAL_[TOOLKIT_]SLUG.
|
package/src/models/Keyring.ts
CHANGED
|
@@ -43,9 +43,10 @@ export class Keyring {
|
|
|
43
43
|
* @returns {Promise<KeyringTransferKeysResponse>} The active key ID and every accepted public JWK, newest first
|
|
44
44
|
*
|
|
45
45
|
* @example
|
|
46
|
-
* ```typescript
|
|
46
|
+
* ```typescript nocheck="Seals with the jose library, whose types the checker does not load"
|
|
47
47
|
* import { CompactEncrypt, importJWK } from 'jose';
|
|
48
48
|
*
|
|
49
|
+
* const secret = 'my-client-secret';
|
|
49
50
|
* const { activeKid, keys } = await composio.keyring.listTransferKeys();
|
|
50
51
|
* const jwk = keys.find(key => key.kid === activeKid)!;
|
|
51
52
|
* const sealed = await new CompactEncrypt(new TextEncoder().encode(secret))
|