@composio/core 0.19.0 → 0.21.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-BMlZfJVz.mjs → CustomTool-B-_VjWpy.mjs} +1 -1
- package/dist/{CustomTool-CB5vm1Jc.d.mts → CustomTool-BHOYxLZX.d.mts} +1 -1
- package/dist/{FileModifierErrors-BqFmpRsm.mjs → FileModifierErrors-CdGSABoq.mjs} +1 -1
- package/dist/{SsrfErrors-C91YhASE.mjs → SsrfErrors-DiQldIdC.mjs} +18 -7
- package/dist/{Telemetry-HlftxMx6.mjs → Telemetry-JRJJYS4I.mjs} +2 -2
- package/dist/{cancellation-CXpfmiVo.mjs → cancellation-DV8CIi52.mjs} +2 -2
- package/dist/{composio-DLGaeN70.d.mts → composio-BTZsFajb.d.mts} +3149 -117
- package/dist/{customTool.types-BAmEh3MB.d.mts → customTool.types-D_w21L56.d.mts} +784 -56
- package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +10 -10
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +7 -3
- package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +101 -18
- package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +123 -0
- package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +9 -2
- package/dist/docs/reference/sdk-reference/typescript/index.mdx +8 -0
- package/dist/docs/reference/sdk-reference/typescript/keyring.mdx +56 -0
- package/dist/docs/reference/sdk-reference/typescript/logs.mdx +78 -0
- package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +15 -15
- package/dist/docs/reference/sdk-reference/typescript/meta.json +9 -1
- package/dist/docs/reference/sdk-reference/typescript/session-configs.mdx +83 -0
- package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +10 -10
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +86 -27
- package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +26 -6
- package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +149 -12
- package/dist/docs/reference/sdk-reference/typescript/tools.mdx +18 -18
- package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +25 -25
- package/dist/docs/reference/sdk-reference/typescript/usage.mdx +78 -0
- package/dist/docs/reference/sdk-reference/typescript/webhook-endpoints.mdx +162 -0
- package/dist/docs/reference/sdk-reference/typescript/webhook-subscriptions.mdx +218 -0
- package/dist/docs/reference/sdk-reference/typescript/webhooks.mdx +20 -0
- package/dist/{errors-BuEKehbI.mjs → errors-Dyiu3ifQ.mjs} +127 -4
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-L7XD8UPr.mjs → fileUtils.node-DNLhLg0W.mjs} +4 -4
- package/dist/index.d.mts +281 -55
- package/dist/index.mjs +3552 -949
- package/dist/models/Files.node.mjs +2 -2
- package/dist/{sensitiveFileUploadPaths-B6pBt9lO.mjs → sensitiveFileUploadPaths-BlLp-Yo2.mjs} +1 -1
- package/dist/{ssrfGuard.node-B9xQB4za.mjs → ssrfGuard.node-BZ270bcu.mjs} +1 -1
- package/dist/{types-CxLPO0Xq.d.mts → types-CgRsUGqm.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/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 +4 -2
- package/src/composio.ts +215 -10
- package/src/errors/ConnectedAccountsErrors.ts +47 -0
- package/src/errors/SDKErrors.ts +52 -0
- package/src/errors/ToolRouterErrors.ts +61 -0
- package/src/errors/index.ts +3 -0
- package/src/index.ts +13 -0
- package/src/lib/sessionConfigConflict.ts +43 -0
- package/src/lib/toolRouterMcp.ts +132 -0
- package/src/lib/toolRouterParams.ts +149 -37
- package/src/lib/toolRouterSourceSessionConfig.ts +12 -0
- package/src/models/ConnectedAccounts.ts +118 -2
- package/src/models/CustomToolkits.ts +169 -0
- package/src/models/Experimental.ts +27 -0
- package/src/models/Keyring.ts +65 -0
- package/src/models/Logs.ts +101 -0
- package/src/models/RemoteFile.ts +25 -8
- package/src/models/SessionConfigs.ts +117 -0
- package/src/models/ToolRouter.ts +61 -17
- package/src/models/ToolRouterSession.ts +149 -14
- package/src/models/Toolkits.ts +180 -0
- package/src/models/Tools.ts +10 -6
- package/src/models/Triggers.ts +3 -88
- package/src/models/Usage.ts +119 -0
- package/src/models/Webhooks.ts +520 -0
- package/src/services/pusher/Pusher.ts +17 -6
- package/src/types/authConfigs.types.ts +2 -0
- package/src/types/connectedAccounts.types.ts +54 -0
- package/src/types/customToolkits.types.ts +102 -0
- package/src/types/keyring.types.ts +32 -0
- package/src/types/logs.types.ts +108 -0
- package/src/types/sessionConfigs.types.ts +81 -0
- package/src/types/tool.types.ts +2 -0
- package/src/types/toolRouter.types.ts +352 -16
- package/src/types/toolkit.types.ts +144 -0
- package/src/types/usage.types.ts +81 -0
- package/src/types/webhooks.types.ts +143 -0
- package/src/utils/constants.ts +1 -5
- package/src/utils/logger.ts +39 -7
- package/src/utils/safePath.ts +172 -0
- package/src/utils/sdk.ts +385 -22
- package/src/utils/transformers/connectedAccounts.ts +37 -2
- package/src/utils/transformers/customToolkits.ts +98 -0
- package/src/utils/transformers/keyring.ts +24 -0
- package/src/utils/transformers/logs.ts +85 -0
- package/src/utils/transformers/sessionConfigs.ts +54 -0
- package/src/utils/transformers/toolRouterResponseTransform.ts +6 -0
- package/src/utils/transformers/toolkits.ts +106 -3
- package/src/utils/transformers/triggers.ts +2 -2
- package/src/utils/transformers/usage.ts +77 -0
- package/src/utils/transformers/webhooks.ts +139 -0
package/src/index.ts
CHANGED
|
@@ -45,10 +45,16 @@ export {
|
|
|
45
45
|
export type { KeyMapping, KeySanitizationPolicy } from './utils/schemaPropertyKeys';
|
|
46
46
|
export { AuthScheme } from './models/AuthScheme';
|
|
47
47
|
export { MCP } from './models/MCP';
|
|
48
|
+
export { Webhooks, WebhookSubscriptions, WebhookEndpoints } from './models/Webhooks';
|
|
49
|
+
export { Logs } from './models/Logs';
|
|
50
|
+
export { Usage } from './models/Usage';
|
|
51
|
+
export { Keyring } from './models/Keyring';
|
|
52
|
+
export { CustomToolkits } from './models/CustomToolkits';
|
|
48
53
|
export { RemoteFile } from './models/RemoteFile';
|
|
49
54
|
export { createConnectionRequest } from './models/ConnectionRequest';
|
|
50
55
|
export { ToolRouterSession } from './models/ToolRouterSession';
|
|
51
56
|
export { Sessions } from './models/Sessions';
|
|
57
|
+
export { SessionConfigs } from './models/SessionConfigs';
|
|
52
58
|
export * from './types/provider.types';
|
|
53
59
|
export * from './types/customTool.types';
|
|
54
60
|
export * from './types/tool.types';
|
|
@@ -59,15 +65,22 @@ export * from './types/connectedAccounts.types';
|
|
|
59
65
|
export * from './types/toolkit.types';
|
|
60
66
|
export * from './types/triggers.types';
|
|
61
67
|
export * from './types/webhookEvents.types';
|
|
68
|
+
export * from './types/webhooks.types';
|
|
69
|
+
export * from './types/logs.types';
|
|
70
|
+
export * from './types/usage.types';
|
|
71
|
+
export * from './types/keyring.types';
|
|
72
|
+
export * from './types/customToolkits.types';
|
|
62
73
|
export * from './types/mcp.types';
|
|
63
74
|
export * from './types/files.types';
|
|
64
75
|
export * from './types/connectionRequest.types';
|
|
65
76
|
export * from './types/toolRouter.types';
|
|
77
|
+
export * from './types/sessionConfigs.types';
|
|
66
78
|
export * from './types/ToolRouterSessionFilesMount.types';
|
|
67
79
|
export * from './types/requestOptions.types';
|
|
68
80
|
export * as constants from './utils/constants';
|
|
69
81
|
|
|
70
82
|
export { default as logger } from './utils/logger';
|
|
83
|
+
export type { ComposioLogger, LogLevel } from './utils/logger';
|
|
71
84
|
export { telemetry } from './telemetry/Telemetry';
|
|
72
85
|
|
|
73
86
|
// Experimental custom tools — exported with experimental_ prefix for top-level import
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { z } from 'zod/v3';
|
|
2
|
+
import { ValidationError } from '../errors/ValidationErrors';
|
|
3
|
+
|
|
4
|
+
const SESSION_CONFIG_CONFLICT_MARKER = 'sessionConfigConflict';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Adds the issue raised when a saved Session config (`experimental.sessionConfigId`)
|
|
8
|
+
* is combined with inline access fields. `fields` lists every conflicting
|
|
9
|
+
* field that was provided; nothing is added when it is empty.
|
|
10
|
+
*/
|
|
11
|
+
export const addSessionConfigConflictIssue = (ctx: z.RefinementCtx, fields: string[]): void => {
|
|
12
|
+
if (fields.length === 0) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
ctx.addIssue({
|
|
16
|
+
code: z.ZodIssueCode.custom,
|
|
17
|
+
message: `experimental.sessionConfigId cannot be combined with ${fields.join(', ')}. A saved Session config sets the session's toolkit, tool and tag access; remove ${fields.length === 1 ? 'that field' : 'those fields'} or sessionConfigId`,
|
|
18
|
+
path: ['experimental', 'sessionConfigId'],
|
|
19
|
+
params: { [SESSION_CONFIG_CONFLICT_MARKER]: true },
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Parses session create or update input. A saved Session config combined with
|
|
25
|
+
* inline access fields throws `ValidationError`; any other failure rethrows the
|
|
26
|
+
* original `ZodError`, as `schema.parse()` would.
|
|
27
|
+
*/
|
|
28
|
+
export const parseSessionConfigInput = <TSchema extends z.ZodTypeAny>(
|
|
29
|
+
schema: TSchema,
|
|
30
|
+
input: unknown
|
|
31
|
+
): z.output<TSchema> => {
|
|
32
|
+
const result = schema.safeParse(input);
|
|
33
|
+
if (result.success) {
|
|
34
|
+
return result.data;
|
|
35
|
+
}
|
|
36
|
+
const isConflict = result.error.issues.some(
|
|
37
|
+
issue => issue.code === z.ZodIssueCode.custom && issue.params?.[SESSION_CONFIG_CONFLICT_MARKER]
|
|
38
|
+
);
|
|
39
|
+
if (isConflict) {
|
|
40
|
+
throw new ValidationError('Invalid session config', { cause: result.error });
|
|
41
|
+
}
|
|
42
|
+
throw result.error;
|
|
43
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { ComposioMCPDestinationError } from '../errors/ToolRouterErrors';
|
|
2
|
+
import type { ComposioRequestHeaders } from '../types/composio.types';
|
|
3
|
+
import type { MCPServerType, ToolRouterMCPServerConfig } from '../types/toolRouter.types';
|
|
4
|
+
import logger from '../utils/logger';
|
|
5
|
+
import { ORG_ID_HEADER, PROJECT_ID_HEADER, resolveCredentialHeaders } from '../utils/sdk';
|
|
6
|
+
|
|
7
|
+
type OriginRole = 'API base URL' | 'MCP URL';
|
|
8
|
+
|
|
9
|
+
type ParsedOrigin = { origin: string } | { error: ComposioMCPDestinationError };
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Returns the tuple origin (`scheme://host[:port]`) of an absolute URL.
|
|
13
|
+
*
|
|
14
|
+
* URLs without a tuple origin (`data:`, `file:`, `blob:` without a base, and
|
|
15
|
+
* similar) serialize their origin as the opaque string `null`. Two such URLs
|
|
16
|
+
* would compare equal, so they are rejected before any comparison happens.
|
|
17
|
+
*/
|
|
18
|
+
const parseOrigin = (url: string, role: OriginRole): ParsedOrigin => {
|
|
19
|
+
let parsed: URL;
|
|
20
|
+
try {
|
|
21
|
+
parsed = new URL(url);
|
|
22
|
+
} catch (_error) {
|
|
23
|
+
return {
|
|
24
|
+
error: new ComposioMCPDestinationError(`The ${role} is not a valid absolute URL`, {
|
|
25
|
+
meta: { role },
|
|
26
|
+
}),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (parsed.origin === 'null') {
|
|
30
|
+
return {
|
|
31
|
+
error: new ComposioMCPDestinationError(`The ${role} has an opaque origin`, {
|
|
32
|
+
meta: { role },
|
|
33
|
+
}),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return { origin: parsed.origin };
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Returns the error describing why the MCP URL must not receive the session
|
|
41
|
+
* credential, or `undefined` when it shares the API origin.
|
|
42
|
+
*/
|
|
43
|
+
const destinationRejection = (
|
|
44
|
+
apiBaseURL: string,
|
|
45
|
+
mcpUrl: string
|
|
46
|
+
): ComposioMCPDestinationError | undefined => {
|
|
47
|
+
const api = parseOrigin(apiBaseURL, 'API base URL');
|
|
48
|
+
if ('error' in api) {
|
|
49
|
+
return api.error;
|
|
50
|
+
}
|
|
51
|
+
const mcp = parseOrigin(mcpUrl, 'MCP URL');
|
|
52
|
+
if ('error' in mcp) {
|
|
53
|
+
return mcp.error;
|
|
54
|
+
}
|
|
55
|
+
if (mcp.origin === api.origin) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
return new ComposioMCPDestinationError(
|
|
59
|
+
`The session MCP endpoint origin ${mcp.origin} does not match the API origin ${api.origin}; the session credential was not attached`,
|
|
60
|
+
{ meta: { mcpOrigin: mcp.origin, apiOrigin: api.origin } }
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type MCPServerConfigInput = {
|
|
65
|
+
type: MCPServerType;
|
|
66
|
+
/** The MCP URL returned by the API for this session. */
|
|
67
|
+
url: string;
|
|
68
|
+
/** The API base URL the session request was sent to. */
|
|
69
|
+
apiBaseURL: string;
|
|
70
|
+
/** The project API key the session request authenticated with, or `null` when disabled. */
|
|
71
|
+
apiKey: string | null | undefined;
|
|
72
|
+
/** The user API key the client resolved (`userApiKey` option or `COMPOSIO_USER_API_KEY`). */
|
|
73
|
+
userApiKey: string | null | undefined;
|
|
74
|
+
/** The default headers configured on the SDK instance; only `x-user-api-key` is consulted. */
|
|
75
|
+
defaultHeaders: ComposioRequestHeaders | undefined;
|
|
76
|
+
/** Organization nano ID the instance is scoped to, if any. */
|
|
77
|
+
orgId: string | undefined;
|
|
78
|
+
/** Project nano ID the instance is scoped to, if any. */
|
|
79
|
+
projectId: string | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Whether the caller asked for the MCP endpoint (`mcp: true`). Decides how
|
|
82
|
+
* a rejected destination is reported: as a thrown error when `true`, as a
|
|
83
|
+
* warning and an empty header set otherwise.
|
|
84
|
+
*/
|
|
85
|
+
mcpRequested: boolean;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Builds the MCP server config exported on a session.
|
|
90
|
+
*
|
|
91
|
+
* The headers mirror the effective auth context of the session request: the
|
|
92
|
+
* project key as `x-api-key` when one is configured, otherwise the resolved
|
|
93
|
+
* user API key (the `userApiKey` option, then the `x-user-api-key` default
|
|
94
|
+
* header) as `x-user-api-key`, plus `x-org-id` / `x-project-id` when the
|
|
95
|
+
* instance carries an explicit scope. No other default header is copied and
|
|
96
|
+
* the environment is never re-read.
|
|
97
|
+
*
|
|
98
|
+
* The headers are only attached when the MCP URL has the same origin as the
|
|
99
|
+
* API base URL the session was created against, whatever scheme the caller
|
|
100
|
+
* configured: that origin already receives them on every SDK request. Any
|
|
101
|
+
* other destination (a different origin, an opaque origin, or a URL that does
|
|
102
|
+
* not parse) never receives the credential. When the caller asked for MCP
|
|
103
|
+
* (`mcpRequested`), that raises {@link ComposioMCPDestinationError} naming
|
|
104
|
+
* both origins; otherwise the session is returned with empty `headers` and a
|
|
105
|
+
* warning naming both origins is logged, so callers who only use the native
|
|
106
|
+
* tools are not blocked by an endpoint they never consume. The SDK itself
|
|
107
|
+
* never connects to the MCP URL and does not follow redirects for it; an MCP
|
|
108
|
+
* client consuming this config must not forward these headers to a different
|
|
109
|
+
* origin.
|
|
110
|
+
*/
|
|
111
|
+
export const buildMCPServerConfig = (input: MCPServerConfigInput): ToolRouterMCPServerConfig => {
|
|
112
|
+
const rejection = destinationRejection(input.apiBaseURL, input.url);
|
|
113
|
+
if (rejection) {
|
|
114
|
+
if (input.mcpRequested) {
|
|
115
|
+
throw rejection;
|
|
116
|
+
}
|
|
117
|
+
logger.warn(
|
|
118
|
+
`${rejection.message}. session.mcp.headers was left empty; pass \`mcp: true\` to make this an error`
|
|
119
|
+
);
|
|
120
|
+
return { type: input.type, url: input.url, headers: {} };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const headers = resolveCredentialHeaders(input);
|
|
124
|
+
if (input.orgId) {
|
|
125
|
+
headers[ORG_ID_HEADER] = input.orgId;
|
|
126
|
+
}
|
|
127
|
+
if (input.projectId) {
|
|
128
|
+
headers[PROJECT_ID_HEADER] = input.projectId;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return { type: input.type, url: input.url, headers };
|
|
132
|
+
};
|
|
@@ -8,15 +8,25 @@ import {
|
|
|
8
8
|
ToolRouterConfigToolsSchema,
|
|
9
9
|
ToolRouterToolsParam,
|
|
10
10
|
ToolRouterConfigManageConnectionsSchema,
|
|
11
|
-
|
|
11
|
+
ToolRouterCreateSessionConfigSchema,
|
|
12
12
|
ToolRouterToolkitsParamSchema,
|
|
13
13
|
ToolRouterToolkitsDisabledConfigSchema,
|
|
14
14
|
ToolRouterToolkitsEnabledConfigSchema,
|
|
15
|
-
|
|
15
|
+
ToolRouterUpdateSessionConfigSchema,
|
|
16
|
+
ToolRouterUpdateManageConnectionsConfig,
|
|
17
|
+
ToolRouterUpdateManageConnectionsSchema,
|
|
18
|
+
ToolRouterUpdateExperimentalConfig,
|
|
16
19
|
ToolRouterSandboxConfig,
|
|
20
|
+
ToolRouterPremiumUsage,
|
|
17
21
|
} from '../types/toolRouter.types';
|
|
18
22
|
import { ValidationError } from '../errors';
|
|
19
23
|
import { z } from 'zod';
|
|
24
|
+
import type { TypeOf } from 'zod/v3';
|
|
25
|
+
|
|
26
|
+
/** Parsed create input; the public `ToolRouterCreateSessionConfig` is a union over it. */
|
|
27
|
+
type ParsedCreateSessionConfig = TypeOf<typeof ToolRouterCreateSessionConfigSchema>;
|
|
28
|
+
/** Parsed update input; the public `ToolRouterUpdateSessionConfig` is a union over it. */
|
|
29
|
+
type ParsedUpdateSessionConfig = TypeOf<typeof ToolRouterUpdateSessionConfigSchema>;
|
|
20
30
|
|
|
21
31
|
export const transformToolRouterToolsParams = (
|
|
22
32
|
params?: Record<string, ToolRouterToolsParam | ToolRouterConfigTools> | undefined
|
|
@@ -117,8 +127,8 @@ export const transformToolRouterManageConnectionsParams = (
|
|
|
117
127
|
};
|
|
118
128
|
|
|
119
129
|
export const resolveToolRouterSandboxConfig = (
|
|
120
|
-
config: Pick<
|
|
121
|
-
):
|
|
130
|
+
config: Pick<ParsedCreateSessionConfig, 'sandbox' | 'workbench'>
|
|
131
|
+
): ParsedCreateSessionConfig['sandbox'] | ParsedCreateSessionConfig['workbench'] => {
|
|
122
132
|
if (config.sandbox !== undefined && config.workbench !== undefined) {
|
|
123
133
|
throw new ValidationError(
|
|
124
134
|
'Pass either sandbox or workbench, not both. workbench is a backwards-compatible alias for sandbox.'
|
|
@@ -128,7 +138,7 @@ export const resolveToolRouterSandboxConfig = (
|
|
|
128
138
|
};
|
|
129
139
|
|
|
130
140
|
export const transformToolRouterSandboxParams = (
|
|
131
|
-
params?:
|
|
141
|
+
params?: ParsedCreateSessionConfig['sandbox'] | ParsedCreateSessionConfig['workbench']
|
|
132
142
|
): SessionCreateParams.Workbench | undefined => {
|
|
133
143
|
if (!params) {
|
|
134
144
|
return undefined;
|
|
@@ -149,14 +159,73 @@ export const transformToolRouterWorkbenchParams = transformToolRouterSandboxPara
|
|
|
149
159
|
* PATCH-safe variant of transformToolRouterManageConnectionsParams.
|
|
150
160
|
* Does NOT apply defaults — only includes fields explicitly present in the input.
|
|
151
161
|
*/
|
|
162
|
+
/** Widens the listed keys of a generated request type so `null` can travel on the wire. */
|
|
163
|
+
type WithNull<T, K extends keyof T> = Omit<T, K> & { [P in K]?: NonNullable<T[P]> | null };
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* `manage_connections` as sent by `session.update()`. Only the supplied
|
|
167
|
+
* subfields travel; `callback_url: null` removes the stored callback, which
|
|
168
|
+
* the generated client types as string-only.
|
|
169
|
+
*/
|
|
170
|
+
export type SessionPatchManageConnectionsBody = WithNull<
|
|
171
|
+
SessionPatchParams.ManageConnections,
|
|
172
|
+
'callback_url'
|
|
173
|
+
>;
|
|
174
|
+
|
|
175
|
+
/** `multi_account` as sent by `session.update()`; `null` removes the stored maximum. */
|
|
176
|
+
export type SessionPatchMultiAccountBody = WithNull<
|
|
177
|
+
SessionPatchParams.MultiAccount,
|
|
178
|
+
'max_accounts_per_toolkit'
|
|
179
|
+
>;
|
|
180
|
+
|
|
181
|
+
/** `experimental` as sent by `session.update()`; `null` removes a stored leaf. */
|
|
182
|
+
export type SessionPatchExperimentalBody = WithNull<
|
|
183
|
+
SessionPatchParams.Experimental,
|
|
184
|
+
'permissions' | 'link_url_overwrite' | 'fast_mode' | 'submit_feedback'
|
|
185
|
+
>;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Request body of `session.update()`. Extends the generated `SessionPatchParams`
|
|
189
|
+
* with the nullable policy blocks (`null` removes the stored override) and the
|
|
190
|
+
* `expected_config_version` root precondition, none of which the generated
|
|
191
|
+
* client types yet.
|
|
192
|
+
*/
|
|
193
|
+
export type SessionPatchBody = Omit<
|
|
194
|
+
WithNull<
|
|
195
|
+
SessionPatchParams,
|
|
196
|
+
'toolkits' | 'tools' | 'tags' | 'auth_configs' | 'preload' | 'search' | 'execute'
|
|
197
|
+
>,
|
|
198
|
+
'manage_connections' | 'multi_account' | 'experimental'
|
|
199
|
+
> & {
|
|
200
|
+
manage_connections?: SessionPatchManageConnectionsBody | null;
|
|
201
|
+
multi_account?: SessionPatchMultiAccountBody | null;
|
|
202
|
+
experimental?: SessionPatchExperimentalBody | null;
|
|
203
|
+
expected_config_version?: number;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
export type SessionPremiumUsageBody = NonNullable<SessionPatchParams['premium_usage']>;
|
|
207
|
+
|
|
208
|
+
export const transformToolRouterPremiumUsageParams = (
|
|
209
|
+
config: ToolRouterPremiumUsage
|
|
210
|
+
): SessionPremiumUsageBody => {
|
|
211
|
+
if (config === false) return false;
|
|
212
|
+
return {
|
|
213
|
+
...(config.toolkits !== undefined && { toolkits: config.toolkits }),
|
|
214
|
+
...(config.tools !== undefined && { tools: config.tools }),
|
|
215
|
+
...(config.returnPremiumCharge !== undefined && {
|
|
216
|
+
return_premium_charge: config.returnPremiumCharge,
|
|
217
|
+
}),
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
|
|
152
221
|
export const transformToolRouterUpdateManageConnectionsParams = (
|
|
153
|
-
params: boolean |
|
|
154
|
-
):
|
|
222
|
+
params: boolean | ToolRouterUpdateManageConnectionsConfig
|
|
223
|
+
): SessionPatchManageConnectionsBody => {
|
|
155
224
|
if (typeof params === 'boolean') {
|
|
156
225
|
return { enable: params };
|
|
157
226
|
}
|
|
158
227
|
|
|
159
|
-
const parsedResult =
|
|
228
|
+
const parsedResult = ToolRouterUpdateManageConnectionsSchema.safeParse(params);
|
|
160
229
|
if (!parsedResult.success) {
|
|
161
230
|
throw new ValidationError('Failed to parse manage connections config', {
|
|
162
231
|
cause: parsedResult.error,
|
|
@@ -164,7 +233,7 @@ export const transformToolRouterUpdateManageConnectionsParams = (
|
|
|
164
233
|
}
|
|
165
234
|
|
|
166
235
|
const config = parsedResult.data;
|
|
167
|
-
const result:
|
|
236
|
+
const result: SessionPatchManageConnectionsBody = {};
|
|
168
237
|
if (config.enable !== undefined) {
|
|
169
238
|
result.enable = config.enable;
|
|
170
239
|
}
|
|
@@ -174,7 +243,32 @@ export const transformToolRouterUpdateManageConnectionsParams = (
|
|
|
174
243
|
if (config.waitForConnections !== undefined) {
|
|
175
244
|
result.enable_wait_for_connections = config.waitForConnections;
|
|
176
245
|
}
|
|
177
|
-
|
|
246
|
+
if (config.enableConnectionRemoval !== undefined) {
|
|
247
|
+
result.enable_connection_removal = config.enableConnectionRemoval;
|
|
248
|
+
}
|
|
249
|
+
return result;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
const transformToolRouterUpdateExperimentalParams = (
|
|
253
|
+
config: ToolRouterUpdateExperimentalConfig
|
|
254
|
+
): SessionPatchExperimentalBody => {
|
|
255
|
+
const result: SessionPatchExperimentalBody = {};
|
|
256
|
+
if (config.permissions !== undefined) {
|
|
257
|
+
result.permissions = config.permissions;
|
|
258
|
+
}
|
|
259
|
+
if (config.linkUrlOverwrite !== undefined) {
|
|
260
|
+
result.link_url_overwrite = config.linkUrlOverwrite;
|
|
261
|
+
}
|
|
262
|
+
if (config.fastMode !== undefined) {
|
|
263
|
+
result.fast_mode = config.fastMode;
|
|
264
|
+
}
|
|
265
|
+
if (config.submitFeedback !== undefined) {
|
|
266
|
+
result.submit_feedback = config.submitFeedback;
|
|
267
|
+
}
|
|
268
|
+
if (config.sessionConfigId !== undefined) {
|
|
269
|
+
result.session_config_id = config.sessionConfigId;
|
|
270
|
+
}
|
|
271
|
+
return result;
|
|
178
272
|
};
|
|
179
273
|
|
|
180
274
|
/**
|
|
@@ -204,7 +298,7 @@ export const transformToolRouterUpdateSandboxParams = (
|
|
|
204
298
|
export const transformToolRouterUpdateWorkbenchParams = transformToolRouterUpdateSandboxParams;
|
|
205
299
|
|
|
206
300
|
export const transformToolRouterMultiAccountParams = (
|
|
207
|
-
params?:
|
|
301
|
+
params?: ParsedCreateSessionConfig['multiAccount']
|
|
208
302
|
): SessionCreateParams.MultiAccount | undefined => {
|
|
209
303
|
if (!params) {
|
|
210
304
|
return undefined;
|
|
@@ -229,7 +323,7 @@ export const transformToolRouterMultiAccountParams = (
|
|
|
229
323
|
};
|
|
230
324
|
|
|
231
325
|
export const transformToolRouterToolkitsParams = (
|
|
232
|
-
params?:
|
|
326
|
+
params?: ParsedCreateSessionConfig['toolkits']
|
|
233
327
|
): SessionCreateParams.Enable | SessionCreateParams.Disable | undefined => {
|
|
234
328
|
if (!params) {
|
|
235
329
|
return undefined;
|
|
@@ -244,63 +338,81 @@ export const transformToolRouterToolkitsParams = (
|
|
|
244
338
|
return params as SessionCreateParams.Enable | SessionCreateParams.Disable;
|
|
245
339
|
};
|
|
246
340
|
|
|
341
|
+
/**
|
|
342
|
+
* Request body of `session.update()`. Every key present in `config` is sent,
|
|
343
|
+
* including `null` (remove the stored override) and empty collections (an
|
|
344
|
+
* empty toolkit allowlist denies every app toolkit). The
|
|
345
|
+
* `expectedConfigVersion` option is not a body field here: the session
|
|
346
|
+
* adds it only when the caller explicitly supplies a numeric version.
|
|
347
|
+
*/
|
|
247
348
|
export const transformToolRouterUpdateParams = (
|
|
248
|
-
config:
|
|
249
|
-
):
|
|
250
|
-
const params:
|
|
349
|
+
config: ParsedUpdateSessionConfig
|
|
350
|
+
): SessionPatchBody => {
|
|
351
|
+
const params: SessionPatchBody = {};
|
|
251
352
|
|
|
252
353
|
if (config.toolkits !== undefined) {
|
|
253
|
-
params.toolkits =
|
|
354
|
+
params.toolkits =
|
|
355
|
+
config.toolkits === null ? null : transformToolRouterToolkitsParams(config.toolkits);
|
|
356
|
+
}
|
|
357
|
+
if (config.premiumUsage !== undefined) {
|
|
358
|
+
params.premium_usage = transformToolRouterPremiumUsageParams(config.premiumUsage);
|
|
254
359
|
}
|
|
255
360
|
if (config.tools !== undefined) {
|
|
256
|
-
params.tools = transformToolRouterToolsParams(config.tools);
|
|
361
|
+
params.tools = config.tools === null ? null : transformToolRouterToolsParams(config.tools);
|
|
257
362
|
}
|
|
258
363
|
if (config.tags !== undefined) {
|
|
259
|
-
params.tags = transformToolRouterTagsParams(config.tags);
|
|
364
|
+
params.tags = config.tags === null ? null : transformToolRouterTagsParams(config.tags);
|
|
260
365
|
}
|
|
261
366
|
if (config.authConfigs !== undefined) {
|
|
262
367
|
params.auth_configs = config.authConfigs;
|
|
263
368
|
}
|
|
264
369
|
if (config.connectedAccounts !== undefined) {
|
|
265
|
-
|
|
266
|
-
for (const [k, v] of Object.entries(config.connectedAccounts)) {
|
|
267
|
-
coerced[k] = typeof v === 'string' ? [v] : v;
|
|
268
|
-
}
|
|
269
|
-
params.connected_accounts = coerced;
|
|
370
|
+
params.connected_accounts = config.connectedAccounts;
|
|
270
371
|
}
|
|
271
372
|
if (config.manageConnections !== undefined) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
config.manageConnections
|
|
277
|
-
);
|
|
278
|
-
}
|
|
373
|
+
params.manage_connections =
|
|
374
|
+
config.manageConnections === null
|
|
375
|
+
? null
|
|
376
|
+
: transformToolRouterUpdateManageConnectionsParams(config.manageConnections);
|
|
279
377
|
}
|
|
280
378
|
const sandboxConfig = config.sandbox !== undefined ? config.sandbox : config.workbench;
|
|
281
379
|
if (sandboxConfig !== undefined) {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
} else {
|
|
285
|
-
params.workbench = transformToolRouterUpdateSandboxParams(sandboxConfig);
|
|
286
|
-
}
|
|
380
|
+
params.workbench =
|
|
381
|
+
sandboxConfig === null ? null : transformToolRouterUpdateSandboxParams(sandboxConfig);
|
|
287
382
|
}
|
|
288
383
|
if (config.multiAccount !== undefined) {
|
|
289
384
|
if (config.multiAccount === null) {
|
|
290
385
|
params.multi_account = null;
|
|
291
386
|
} else {
|
|
292
|
-
const ma:
|
|
387
|
+
const ma: SessionPatchMultiAccountBody = {};
|
|
293
388
|
if (config.multiAccount.enable !== undefined) ma.enable = config.multiAccount.enable;
|
|
294
389
|
if (config.multiAccount.maxAccountsPerToolkit !== undefined)
|
|
295
390
|
ma.max_accounts_per_toolkit = config.multiAccount.maxAccountsPerToolkit;
|
|
296
391
|
if (config.multiAccount.requireExplicitSelection !== undefined)
|
|
297
392
|
ma.require_explicit_selection = config.multiAccount.requireExplicitSelection;
|
|
298
|
-
params.multi_account = ma
|
|
393
|
+
params.multi_account = ma;
|
|
299
394
|
}
|
|
300
395
|
}
|
|
301
396
|
if (config.preload !== undefined) {
|
|
302
397
|
params.preload = config.preload;
|
|
303
398
|
}
|
|
399
|
+
if (config.search !== undefined) {
|
|
400
|
+
params.search = config.search;
|
|
401
|
+
}
|
|
402
|
+
if (config.execute !== undefined) {
|
|
403
|
+
params.execute =
|
|
404
|
+
config.execute === null
|
|
405
|
+
? null
|
|
406
|
+
: config.execute.enableMultiExecute === undefined
|
|
407
|
+
? {}
|
|
408
|
+
: { enable_multi_execute: config.execute.enableMultiExecute };
|
|
409
|
+
}
|
|
410
|
+
if (config.experimental !== undefined) {
|
|
411
|
+
params.experimental =
|
|
412
|
+
config.experimental === null
|
|
413
|
+
? null
|
|
414
|
+
: transformToolRouterUpdateExperimentalParams(config.experimental);
|
|
415
|
+
}
|
|
304
416
|
|
|
305
417
|
return params;
|
|
306
418
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SessionExperimental } from '../types/toolRouter.types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Reads the saved Session config most recently applied to a session from a
|
|
5
|
+
* create, retrieve, attach or patch response. Copies only `id`.
|
|
6
|
+
*/
|
|
7
|
+
export const getSourceSessionConfig = (response: {
|
|
8
|
+
experimental?: { source_session_config?: { id: string } };
|
|
9
|
+
}): SessionExperimental['sourceSessionConfig'] => {
|
|
10
|
+
const source = response.experimental?.source_session_config;
|
|
11
|
+
return source ? { id: source.id } : undefined;
|
|
12
|
+
};
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @date 2025-05-05
|
|
6
6
|
* @module ConnectedAccounts
|
|
7
7
|
*/
|
|
8
|
-
import ComposioClient, { BadRequestError } from '@composio/client';
|
|
8
|
+
import ComposioClient, { BadRequestError, ConflictError } from '@composio/client';
|
|
9
9
|
import {
|
|
10
10
|
ConnectedAccountCreateResponse,
|
|
11
11
|
ConnectedAccountDeleteResponse,
|
|
@@ -29,6 +29,10 @@ import {
|
|
|
29
29
|
ConnectedAccountStatuses,
|
|
30
30
|
ConnectedAccountRefreshOptions,
|
|
31
31
|
ConnectedAccountRefreshOptionsSchema,
|
|
32
|
+
ConnectedAccountRevokeResponse,
|
|
33
|
+
ConnectedAccountCompleteAuthParams,
|
|
34
|
+
ConnectedAccountCompleteAuthParamsSchema,
|
|
35
|
+
ConnectedAccountCompleteAuthResponse,
|
|
32
36
|
UpdateConnectedAccountAclParams,
|
|
33
37
|
UpdateConnectedAccountParams,
|
|
34
38
|
UpdateConnectedAccountParamsSchema,
|
|
@@ -45,9 +49,13 @@ import { telemetry } from '../telemetry/Telemetry';
|
|
|
45
49
|
import {
|
|
46
50
|
transformConnectedAccountListResponse,
|
|
47
51
|
transformConnectedAccountResponse,
|
|
52
|
+
transformConnectedAccountRevokeResponse,
|
|
53
|
+
transformConnectedAccountCompleteAuthResponse,
|
|
48
54
|
} from '../utils/transformers/connectedAccounts';
|
|
49
55
|
import {
|
|
50
56
|
ComposioAclOnlyForSharedError,
|
|
57
|
+
ComposioConnectedAccountNotRevokableError,
|
|
58
|
+
ComposioConnectedAccountRevocationNotSupportedError,
|
|
51
59
|
ComposioFailedToCreateConnectedAccountLink,
|
|
52
60
|
ComposioLegacyConnectedAccountsEndpointRetiredError,
|
|
53
61
|
ComposioMultipleConnectedAccountsError,
|
|
@@ -554,6 +562,11 @@ export class ConnectedAccounts {
|
|
|
554
562
|
* // Refresh a connected account's credentials
|
|
555
563
|
* const refreshedAccount = await composio.connectedAccounts.refresh('conn_abc123');
|
|
556
564
|
* ```
|
|
565
|
+
*
|
|
566
|
+
* @deprecated The `POST /connected_accounts/{id}/refresh` endpoint is deprecated by the
|
|
567
|
+
* Composio API. Re-initiate authentication instead: `composio.connectedAccounts.link(userId, authConfigId)`
|
|
568
|
+
* for a fresh connection, or `session.authorize(toolkit)` from a session. Behaviour is unchanged
|
|
569
|
+
* while the endpoint remains available; do not generate new code against `refresh`.
|
|
557
570
|
*/
|
|
558
571
|
async refresh(
|
|
559
572
|
nanoid: string,
|
|
@@ -570,9 +583,14 @@ export class ConnectedAccounts {
|
|
|
570
583
|
});
|
|
571
584
|
}
|
|
572
585
|
|
|
586
|
+
if (parsedOptions.data.validateCredentials !== undefined) {
|
|
587
|
+
logger.warn(
|
|
588
|
+
'connectedAccounts.refresh(): the Composio API no longer accepts `validateCredentials`; the option is ignored.'
|
|
589
|
+
);
|
|
590
|
+
}
|
|
591
|
+
|
|
573
592
|
params = {
|
|
574
593
|
query_redirect_url: parsedOptions.data.redirectUrl,
|
|
575
|
-
validate_credentials: parsedOptions.data.validateCredentials,
|
|
576
594
|
};
|
|
577
595
|
}
|
|
578
596
|
|
|
@@ -582,6 +600,104 @@ export class ConnectedAccounts {
|
|
|
582
600
|
);
|
|
583
601
|
}
|
|
584
602
|
|
|
603
|
+
/**
|
|
604
|
+
* Revoke a connected account at the upstream provider.
|
|
605
|
+
*
|
|
606
|
+
* Best-effort upstream revocation of the stored tokens/credentials; on
|
|
607
|
+
* success the connection status becomes `REVOKED`. Revoking an already
|
|
608
|
+
* revoked connection returns an empty `revokedTokens` list without an
|
|
609
|
+
* upstream call.
|
|
610
|
+
*
|
|
611
|
+
* @param {string} nanoid - The unique identifier of the connected account to revoke
|
|
612
|
+
* @returns {Promise<ConnectedAccountRevokeResponse>} Which tokens were revoked and the resulting status
|
|
613
|
+
* @throws {ComposioConnectedAccountRevocationNotSupportedError} If the toolkit does not support programmatic revocation (400)
|
|
614
|
+
* @throws {ComposioConnectedAccountNotRevokableError} If the connection is not in a revokable state (409)
|
|
615
|
+
*
|
|
616
|
+
* @example
|
|
617
|
+
* ```typescript
|
|
618
|
+
* const result = await composio.connectedAccounts.revoke('conn_abc123');
|
|
619
|
+
* console.log(result.connectedAccount.status); // 'REVOKED'
|
|
620
|
+
* console.log(result.revokedTokens); // e.g. ['access_token', 'refresh_token']
|
|
621
|
+
* ```
|
|
622
|
+
*/
|
|
623
|
+
async revoke(
|
|
624
|
+
nanoid: string,
|
|
625
|
+
requestOptions?: ComposioRequestOptions
|
|
626
|
+
): Promise<ConnectedAccountRevokeResponse> {
|
|
627
|
+
try {
|
|
628
|
+
const result = await withCancellation(
|
|
629
|
+
() => this.client.connectedAccounts.revoke(nanoid, requestOptions),
|
|
630
|
+
requestOptions?.signal
|
|
631
|
+
);
|
|
632
|
+
return transformConnectedAccountRevokeResponse(result);
|
|
633
|
+
} catch (error) {
|
|
634
|
+
if (error instanceof BadRequestError) {
|
|
635
|
+
throw new ComposioConnectedAccountRevocationNotSupportedError(
|
|
636
|
+
`Connected account ${nanoid} cannot be revoked programmatically: ${error.message}`,
|
|
637
|
+
{ cause: error, meta: { nanoid } }
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
if (error instanceof ConflictError) {
|
|
641
|
+
throw new ComposioConnectedAccountNotRevokableError(
|
|
642
|
+
`Connected account ${nanoid} is not in a revokable state: ${error.message}`,
|
|
643
|
+
{ cause: error, meta: { nanoid } }
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
throw error;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
/**
|
|
651
|
+
* Complete a deferred OAuth connection once you have verified the user's
|
|
652
|
+
* identity.
|
|
653
|
+
*
|
|
654
|
+
* When your project has an OAuth callback verifier configured, Composio
|
|
655
|
+
* does not activate a new OAuth connection by itself: it redirects to your
|
|
656
|
+
* verifier with a single-use session URI. After confirming who the user is,
|
|
657
|
+
* redeem that session URI here; Composio checks that your project owns the
|
|
658
|
+
* pending connection and that `userId` is its owner, completes the token
|
|
659
|
+
* exchange, and the connection becomes `ACTIVE`.
|
|
660
|
+
*
|
|
661
|
+
* The session URI is single-use: redeeming it twice, or after it expires,
|
|
662
|
+
* fails with a 404 from the API.
|
|
663
|
+
*
|
|
664
|
+
* @param {ConnectedAccountCompleteAuthParams} params - `userId` the connection was initiated for and the verifier's `sessionUri`
|
|
665
|
+
* @returns {Promise<ConnectedAccountCompleteAuthResponse>} The completed connection's ID and toolkit
|
|
666
|
+
* @throws {ValidationError} If the params fail validation
|
|
667
|
+
*
|
|
668
|
+
* @example
|
|
669
|
+
* ```typescript
|
|
670
|
+
* // In your verifier route, after authenticating the user:
|
|
671
|
+
* const { connectedAccountId, toolkitSlug } = await composio.connectedAccounts.completeAuth({
|
|
672
|
+
* userId: 'user_123',
|
|
673
|
+
* sessionUri, // the session URI from the verifier redirect
|
|
674
|
+
* });
|
|
675
|
+
* ```
|
|
676
|
+
*/
|
|
677
|
+
async completeAuth(
|
|
678
|
+
params: ConnectedAccountCompleteAuthParams,
|
|
679
|
+
requestOptions?: ComposioRequestOptions
|
|
680
|
+
): Promise<ConnectedAccountCompleteAuthResponse> {
|
|
681
|
+
const parsedParams = ConnectedAccountCompleteAuthParamsSchema.safeParse(params);
|
|
682
|
+
if (!parsedParams.success) {
|
|
683
|
+
throw new ValidationError('Failed to parse connected account completeAuth params', {
|
|
684
|
+
cause: parsedParams.error,
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
const result = await withCancellation(
|
|
688
|
+
() =>
|
|
689
|
+
this.client.connectedAccounts.completeAuth(
|
|
690
|
+
{
|
|
691
|
+
user_id: parsedParams.data.userId,
|
|
692
|
+
session_uri: parsedParams.data.sessionUri,
|
|
693
|
+
},
|
|
694
|
+
requestOptions
|
|
695
|
+
),
|
|
696
|
+
requestOptions?.signal
|
|
697
|
+
);
|
|
698
|
+
return transformConnectedAccountCompleteAuthResponse(result);
|
|
699
|
+
}
|
|
700
|
+
|
|
585
701
|
/**
|
|
586
702
|
* Update the status of a connected account
|
|
587
703
|
* @param {string} nanoid - Unique identifier of the connected account
|