@composio/core 1.0.0-beta.0 → 1.0.0-beta.1
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-l-j5HtEf.mjs → CustomTool-CM-roKk7.mjs} +16 -6
- package/dist/{CustomTool-CwpeQhz2.d.mts → CustomTool-yMQjEyMz.d.mts} +1 -1
- package/dist/{FileModifierErrors-B8V8_3VE.mjs → FileModifierErrors-CdGSABoq.mjs} +1 -1
- package/dist/{FileToolModifier.utils.neutral-D_YkHwZP.mjs → FileToolModifier.utils.neutral-DWFpnsj2.mjs} +4 -2
- package/dist/{SsrfErrors-DNJt57GL.mjs → SsrfErrors-DiQldIdC.mjs} +154 -19
- package/dist/{Telemetry-DK1uAWnD.mjs → Telemetry-JRJJYS4I.mjs} +28 -44
- package/dist/cancellation-BEpFk2S8.mjs +706 -0
- package/dist/{composio-XjF7EMEe.d.mts → composio-BVNJTVYa.d.mts} +2450 -119
- package/dist/{customTool.types-DpJbYY5m.d.mts → customTool.types-CY5SXFfF.d.mts} +143 -28
- package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +1 -1
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +4 -3
- package/dist/{errors-BcEUHZbq.mjs → errors-CvZjP9CH.mjs} +42 -4
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-BwpUOF0s.mjs → fileUtils.node-HQsywtTj.mjs} +11 -9
- package/dist/index.d.mts +393 -142
- package/dist/index.mjs +1945 -171
- package/dist/models/Files.node.d.mts +2 -3
- package/dist/models/Files.node.mjs +2 -2
- package/dist/models/Files.workerd.d.mts +2 -3
- package/dist/platform/node.d.mts +2 -3
- package/dist/platform/workerd.d.mts +2 -3
- package/dist/{sensitiveFileUploadPaths-B0w8dqpv.mjs → sensitiveFileUploadPaths-BlLp-Yo2.mjs} +10 -7
- package/dist/{ssrfGuard.node-DlxO8uzr.mjs → ssrfGuard.node-BK50mYTq.mjs} +187 -24
- package/dist/{types-C9kJAurw.d.mts → types-CqGfjlZg.d.mts} +2 -2
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +3 -4
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +3 -4
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +3 -4
- package/dist/utils/modifiers/FileToolModifier.node.mjs +6 -6
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +3 -4
- package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
- package/dist/utils/ssrfGuard.node.d.mts +7 -7
- package/dist/utils/ssrfGuard.node.mjs +1 -1
- package/dist/utils/ssrfGuard.workerd.d.mts +3 -4
- package/dist/utils/ssrfGuard.workerd.mjs +2 -2
- package/package.json +25 -7
- package/src/composio.ts +86 -2
- package/src/errors/ConnectedAccountsErrors.ts +47 -0
- package/src/errors/ToolErrors.ts +1 -0
- package/src/errors/ValidationErrors.ts +2 -0
- package/src/index.ts +21 -0
- package/src/models/ConnectedAccounts.ts +118 -2
- package/src/models/CustomTool.ts +41 -6
- 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 +54 -36
- package/src/models/ToolRouterSession.ts +60 -4
- package/src/models/Toolkits.ts +180 -0
- package/src/models/Tools.ts +3 -1
- package/src/models/Triggers.ts +17 -87
- package/src/models/Usage.ts +119 -0
- package/src/models/Webhooks.ts +520 -0
- package/src/services/telemetry/TelemetryService.ts +27 -12
- package/src/telemetry/redact.ts +133 -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/toolRouter.types.ts +49 -1
- package/src/types/toolkit.types.ts +131 -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/fileUtils.node.ts +10 -2
- package/src/utils/jsonSchema.ts +509 -28
- package/src/utils/logger.ts +45 -13
- package/src/utils/pinnedDispatcher.node.ts +109 -13
- package/src/utils/sdk.ts +1 -1
- package/src/utils/ssrfGuard.node.ts +124 -21
- package/src/utils/ssrfGuard.workerd.ts +5 -1
- 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/toolkits.ts +100 -1
- 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/dist/cancellation-C-qy8rcj.mjs +0 -364
package/src/composio.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { BaseComposioProvider } from './provider/BaseProvider';
|
|
2
2
|
import ComposioClient from '@composio/client';
|
|
3
|
+
import type { Logger as ClientLogger, LogLevel as ClientLogLevel } from '@composio/client';
|
|
3
4
|
import { Tools } from './models/Tools';
|
|
4
5
|
import { Toolkits } from './models/Toolkits';
|
|
5
6
|
import { Triggers } from './models/Triggers';
|
|
@@ -7,10 +8,14 @@ import { AuthConfigs } from './models/AuthConfigs';
|
|
|
7
8
|
import { ConnectedAccounts } from './models/ConnectedAccounts';
|
|
8
9
|
import { Experimental } from './models/Experimental';
|
|
9
10
|
import { MCP } from './models/MCP';
|
|
11
|
+
import { Webhooks } from './models/Webhooks';
|
|
12
|
+
import { Logs } from './models/Logs';
|
|
13
|
+
import { Keyring } from './models/Keyring';
|
|
10
14
|
import { telemetry } from './telemetry/Telemetry';
|
|
11
15
|
import { getSDKConfig, getToolkitVersionsFromEnv } from './utils/sdk';
|
|
12
16
|
import logger from './utils/logger';
|
|
13
|
-
import {
|
|
17
|
+
import type { ComposioLogger, LogLevel } from './utils/logger';
|
|
18
|
+
import { IS_DEVELOPMENT_OR_CI } from './utils/constants';
|
|
14
19
|
import { checkForLatestVersionFromNPM } from './utils/version';
|
|
15
20
|
import { OpenAIProvider } from './provider/OpenAIProvider';
|
|
16
21
|
import { version } from '../package.json';
|
|
@@ -156,6 +161,68 @@ export type ComposioConfig<
|
|
|
156
161
|
* ```
|
|
157
162
|
*/
|
|
158
163
|
toolkitVersions?: ToolkitVersionParam;
|
|
164
|
+
/**
|
|
165
|
+
* Destination for SDK log output. Messages are formatted and have
|
|
166
|
+
* credential-shaped values redacted before they reach the sink, so any
|
|
167
|
+
* object with `error`/`warn`/`info`/`debug` methods works (`console`, pino,
|
|
168
|
+
* winston, ...).
|
|
169
|
+
*
|
|
170
|
+
* Runtime deprecation warnings raised by the underlying API client (response
|
|
171
|
+
* `Deprecation`/`Sunset` headers and deprecated request inputs) are routed
|
|
172
|
+
* through this logger as well.
|
|
173
|
+
*
|
|
174
|
+
* The SDK logger is process-wide: configuring it on one `Composio` instance
|
|
175
|
+
* affects every instance, and the last configured instance wins.
|
|
176
|
+
*
|
|
177
|
+
* @default console
|
|
178
|
+
* @example
|
|
179
|
+
* ```typescript
|
|
180
|
+
* const composio = new Composio({
|
|
181
|
+
* apiKey: 'your-api-key',
|
|
182
|
+
* logger: pino(),
|
|
183
|
+
* logLevel: 'warn',
|
|
184
|
+
* });
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
logger?: ComposioLogger;
|
|
188
|
+
/**
|
|
189
|
+
* Minimum level to emit: `'silent' | 'error' | 'warn' | 'info' | 'debug'`.
|
|
190
|
+
* Takes precedence over the `COMPOSIO_LOG_LEVEL` environment variable.
|
|
191
|
+
* Also gates the API client's runtime deprecation warnings (`'silent'` turns
|
|
192
|
+
* them off). The client's per-request lifecycle logs are emitted at
|
|
193
|
+
* `'debug'` only.
|
|
194
|
+
*
|
|
195
|
+
* Like `logger`, this applies process-wide and the last configured instance
|
|
196
|
+
* wins. The API client's own level is fixed when each instance is created.
|
|
197
|
+
*
|
|
198
|
+
* @default 'info' (or `COMPOSIO_LOG_LEVEL` when set)
|
|
199
|
+
*/
|
|
200
|
+
logLevel?: LogLevel;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Level for the API client given the SDK level. The client logs each request's
|
|
205
|
+
* lifecycle at `info`, which is debug-grade for SDK users, so the client stays
|
|
206
|
+
* at `warn` unless the SDK is at `debug`. The client's `LogLevel` has
|
|
207
|
+
* `'off'` where the SDK has `'silent'`.
|
|
208
|
+
*/
|
|
209
|
+
const toClientLogLevel = (level: LogLevel): ClientLogLevel => {
|
|
210
|
+
if (level === 'silent') return 'off';
|
|
211
|
+
if (level === 'info') return 'warn';
|
|
212
|
+
return level;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Forwards the API client's log records to the SDK singleton so they pick up
|
|
217
|
+
* the SDK's formatting, redaction, and configured sink. Methods are looked up
|
|
218
|
+
* at call time so a later `logger.configure()` is honoured. The client's
|
|
219
|
+
* `info` records (per-request lifecycle) are forwarded as SDK `debug`.
|
|
220
|
+
*/
|
|
221
|
+
const clientLoggerAdapter: ClientLogger = {
|
|
222
|
+
error: (...args) => logger.error(...args),
|
|
223
|
+
warn: (...args) => logger.warn(...args),
|
|
224
|
+
info: (...args) => logger.debug(...args),
|
|
225
|
+
debug: (...args) => logger.debug(...args),
|
|
159
226
|
};
|
|
160
227
|
|
|
161
228
|
/**
|
|
@@ -195,6 +262,15 @@ export class Composio<
|
|
|
195
262
|
authConfigs: AuthConfigs;
|
|
196
263
|
/** Manage authenticated connections */
|
|
197
264
|
connectedAccounts: ConnectedAccounts;
|
|
265
|
+
/**
|
|
266
|
+
* Manage the project's webhook subscription (`webhooks.subscriptions`) and
|
|
267
|
+
* inbound per-toolkit webhook endpoints (`webhooks.endpoints`).
|
|
268
|
+
*/
|
|
269
|
+
webhooks: Webhooks;
|
|
270
|
+
/** Search and inspect tool-execution logs */
|
|
271
|
+
logs: Logs;
|
|
272
|
+
/** Public transfer keys of the organization's customer-managed keyring */
|
|
273
|
+
keyring: Keyring;
|
|
198
274
|
/**
|
|
199
275
|
* Experimental SDK methods whose shape may change in future releases.
|
|
200
276
|
* Prefer domain-specific mounts (for example
|
|
@@ -307,6 +383,10 @@ export class Composio<
|
|
|
307
383
|
config?.apiKey
|
|
308
384
|
);
|
|
309
385
|
|
|
386
|
+
if (config?.logger !== undefined || config?.logLevel !== undefined) {
|
|
387
|
+
logger.configure({ level: config.logLevel, sink: config.logger });
|
|
388
|
+
}
|
|
389
|
+
|
|
310
390
|
if (IS_DEVELOPMENT_OR_CI) {
|
|
311
391
|
logger.debug(`Initializing Composio w API Key: [REDACTED] and baseURL: ${baseURLParsed}`);
|
|
312
392
|
}
|
|
@@ -346,7 +426,8 @@ export class Composio<
|
|
|
346
426
|
apiKey: apiKeyParsed,
|
|
347
427
|
baseURL: baseURLParsed,
|
|
348
428
|
defaultHeaders: defaultHeaders,
|
|
349
|
-
|
|
429
|
+
logger: clientLoggerAdapter,
|
|
430
|
+
logLevel: toClientLogLevel(logger.getLevel()),
|
|
350
431
|
});
|
|
351
432
|
|
|
352
433
|
this.tools = new Tools(this.client, this.config);
|
|
@@ -360,6 +441,9 @@ export class Composio<
|
|
|
360
441
|
fileDownloadDir: this.config.fileDownloadDir,
|
|
361
442
|
});
|
|
362
443
|
this.connectedAccounts = new ConnectedAccounts(this.client);
|
|
444
|
+
this.webhooks = new Webhooks(this.client);
|
|
445
|
+
this.logs = new Logs(this.client);
|
|
446
|
+
this.keyring = new Keyring(this.client);
|
|
363
447
|
this.experimental = new Experimental(this.client);
|
|
364
448
|
this.sessions = new Sessions(this.client, this.config);
|
|
365
449
|
this.toolRouter = this.sessions;
|
|
@@ -8,6 +8,8 @@ export const ConnectedAccountErrorCodes = {
|
|
|
8
8
|
SHARED_ACCESS_DENIED: 'SHARED_ACCESS_DENIED',
|
|
9
9
|
ACL_ONLY_FOR_SHARED: 'ACL_ONLY_FOR_SHARED',
|
|
10
10
|
SHARED_CONNECTION_NOT_ACCESSIBLE: 'SHARED_CONNECTION_NOT_ACCESSIBLE',
|
|
11
|
+
REVOCATION_NOT_SUPPORTED: 'CONNECTED_ACCOUNT_REVOCATION_NOT_SUPPORTED',
|
|
12
|
+
NOT_REVOKABLE: 'CONNECTED_ACCOUNT_NOT_REVOKABLE',
|
|
11
13
|
} as const;
|
|
12
14
|
|
|
13
15
|
export class ComposioConnectedAccountNotFoundError extends ComposioError {
|
|
@@ -156,3 +158,48 @@ export class ComposioLegacyConnectedAccountsEndpointRetiredError extends Composi
|
|
|
156
158
|
this.name = 'ComposioLegacyConnectedAccountsEndpointRetiredError';
|
|
157
159
|
}
|
|
158
160
|
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Thrown by `composio.connectedAccounts.revoke()` when the toolkit behind the
|
|
164
|
+
* connection does not support programmatic revocation at the provider (API
|
|
165
|
+
* 400).
|
|
166
|
+
*/
|
|
167
|
+
export class ComposioConnectedAccountRevocationNotSupportedError extends ComposioError {
|
|
168
|
+
constructor(
|
|
169
|
+
message: string = 'This toolkit does not support programmatic revocation of connected accounts',
|
|
170
|
+
options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
|
|
171
|
+
) {
|
|
172
|
+
super(message, {
|
|
173
|
+
...options,
|
|
174
|
+
code: ConnectedAccountErrorCodes.REVOCATION_NOT_SUPPORTED,
|
|
175
|
+
statusCode: 400,
|
|
176
|
+
possibleFixes: options.possibleFixes || [
|
|
177
|
+
"Revoke the grant from the provider's own settings page, then disable or delete the connected account with composio.connectedAccounts.disable() / delete().",
|
|
178
|
+
],
|
|
179
|
+
});
|
|
180
|
+
this.name = 'ComposioConnectedAccountRevocationNotSupportedError';
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Thrown by `composio.connectedAccounts.revoke()` when the connection is not
|
|
186
|
+
* in a state that can be revoked (API 409), for example it never completed
|
|
187
|
+
* authentication. Revoking an already revoked connection is not an error: it
|
|
188
|
+
* returns an empty `revokedTokens` list.
|
|
189
|
+
*/
|
|
190
|
+
export class ComposioConnectedAccountNotRevokableError extends ComposioError {
|
|
191
|
+
constructor(
|
|
192
|
+
message: string = 'The connected account is not in a revokable state',
|
|
193
|
+
options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
|
|
194
|
+
) {
|
|
195
|
+
super(message, {
|
|
196
|
+
...options,
|
|
197
|
+
code: ConnectedAccountErrorCodes.NOT_REVOKABLE,
|
|
198
|
+
statusCode: 409,
|
|
199
|
+
possibleFixes: options.possibleFixes || [
|
|
200
|
+
'Check the connection status with composio.connectedAccounts.get(); only ACTIVE connections can be revoked.',
|
|
201
|
+
],
|
|
202
|
+
});
|
|
203
|
+
this.name = 'ComposioConnectedAccountNotRevokableError';
|
|
204
|
+
}
|
|
205
|
+
}
|
package/src/errors/ToolErrors.ts
CHANGED
|
@@ -204,6 +204,7 @@ export class ComposioToolVersionRequiredError extends ComposioError {
|
|
|
204
204
|
'Set dangerouslySkipVersionCheck to true (this might cause unexpected behavior when new versions of the tools are released)',
|
|
205
205
|
],
|
|
206
206
|
});
|
|
207
|
+
this.name = 'ComposioToolVersionRequiredError';
|
|
207
208
|
}
|
|
208
209
|
}
|
|
209
210
|
export interface ComposioAPIServerErrorBody {
|
|
@@ -78,6 +78,7 @@ export class JsonSchemaToZodError extends ComposioError {
|
|
|
78
78
|
...options,
|
|
79
79
|
code: options.code || ValidationErrorCodes.JSON_SCHEMA_TO_ZOD_ERROR,
|
|
80
80
|
});
|
|
81
|
+
this.name = 'JsonSchemaToZodError';
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
|
|
@@ -95,5 +96,6 @@ export class JsonSchemaRefResolutionError extends ComposioError {
|
|
|
95
96
|
...options,
|
|
96
97
|
code: options.code || ValidationErrorCodes.JSON_SCHEMA_REF_RESOLUTION_ERROR,
|
|
97
98
|
});
|
|
99
|
+
this.name = 'JsonSchemaRefResolutionError';
|
|
98
100
|
}
|
|
99
101
|
}
|
package/src/index.ts
CHANGED
|
@@ -9,12 +9,18 @@ export {
|
|
|
9
9
|
deduplicateJsonSchemaRequiredArrays,
|
|
10
10
|
ensureObjectTypeOnProperties,
|
|
11
11
|
jsonSchemaToZodSchema,
|
|
12
|
+
omitNullToolArguments,
|
|
12
13
|
removeNonRequiredProperties,
|
|
14
|
+
toStrictJsonSchema,
|
|
13
15
|
} from './utils/jsonSchema';
|
|
14
16
|
export type {
|
|
15
17
|
DereferenceJsonSchemaOptions,
|
|
16
18
|
UnresolvedRefReason,
|
|
17
19
|
UnresolvedRefStrategy,
|
|
20
|
+
StrictSchemaChange,
|
|
21
|
+
StrictSchemaChangeReason,
|
|
22
|
+
StrictSchemaIncompatibility,
|
|
23
|
+
StrictJsonSchemaResult,
|
|
18
24
|
} from './utils/jsonSchema';
|
|
19
25
|
export { getExtensionFromMimeType } from './utils/mime';
|
|
20
26
|
export { normalizeToolArguments } from './utils/toolArguments';
|
|
@@ -27,6 +33,10 @@ export {
|
|
|
27
33
|
isBlockedSensitiveFileUploadPath,
|
|
28
34
|
BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS,
|
|
29
35
|
} from './utils/sensitiveFileUploadPaths';
|
|
36
|
+
// Bounded response reader for files fetched from user-supplied URLs. Exported
|
|
37
|
+
// for the same reason as the denylist guard above: downstream packages read
|
|
38
|
+
// remote files too, and every such read must enforce the same size cap.
|
|
39
|
+
export { readResponseBodyWithLimit, MAX_URL_UPLOAD_SIZE_BYTES } from './utils/readResponseBody';
|
|
30
40
|
export {
|
|
31
41
|
sanitizeSchemaPropertyKeys,
|
|
32
42
|
restoreOriginalKeys,
|
|
@@ -35,6 +45,11 @@ export {
|
|
|
35
45
|
export type { KeyMapping, KeySanitizationPolicy } from './utils/schemaPropertyKeys';
|
|
36
46
|
export { AuthScheme } from './models/AuthScheme';
|
|
37
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';
|
|
38
53
|
export { RemoteFile } from './models/RemoteFile';
|
|
39
54
|
export { createConnectionRequest } from './models/ConnectionRequest';
|
|
40
55
|
export { ToolRouterSession } from './models/ToolRouterSession';
|
|
@@ -49,6 +64,11 @@ export * from './types/connectedAccounts.types';
|
|
|
49
64
|
export * from './types/toolkit.types';
|
|
50
65
|
export * from './types/triggers.types';
|
|
51
66
|
export * from './types/webhookEvents.types';
|
|
67
|
+
export * from './types/webhooks.types';
|
|
68
|
+
export * from './types/logs.types';
|
|
69
|
+
export * from './types/usage.types';
|
|
70
|
+
export * from './types/keyring.types';
|
|
71
|
+
export * from './types/customToolkits.types';
|
|
52
72
|
export * from './types/mcp.types';
|
|
53
73
|
export * from './types/files.types';
|
|
54
74
|
export * from './types/connectionRequest.types';
|
|
@@ -58,6 +78,7 @@ export * from './types/requestOptions.types';
|
|
|
58
78
|
export * as constants from './utils/constants';
|
|
59
79
|
|
|
60
80
|
export { default as logger } from './utils/logger';
|
|
81
|
+
export type { ComposioLogger, LogLevel } from './utils/logger';
|
|
61
82
|
export { telemetry } from './telemetry/Telemetry';
|
|
62
83
|
|
|
63
84
|
// Experimental custom tools — exported with experimental_ prefix for top-level import
|
|
@@ -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
|
package/src/models/CustomTool.ts
CHANGED
|
@@ -514,7 +514,11 @@ export function buildCustomToolsMapFromResponse(
|
|
|
514
514
|
}
|
|
515
515
|
}
|
|
516
516
|
|
|
517
|
-
const findHandle = (
|
|
517
|
+
const findHandle = (
|
|
518
|
+
finalSlug: string,
|
|
519
|
+
originalSlug: string,
|
|
520
|
+
toolkit?: string
|
|
521
|
+
): HandleMatch | undefined => {
|
|
518
522
|
const originalSlugKey = originalSlug.toUpperCase();
|
|
519
523
|
const qualifiedMatch = handlesByQualifiedOriginalSlug.get(
|
|
520
524
|
qualifiedOriginalSlugKey(toolkit, originalSlugKey)
|
|
@@ -522,13 +526,26 @@ export function buildCustomToolsMapFromResponse(
|
|
|
522
526
|
if (qualifiedMatch) return qualifiedMatch;
|
|
523
527
|
|
|
524
528
|
const bareMatches = handlesByOriginalSlug.get(originalSlugKey) ?? [];
|
|
525
|
-
|
|
529
|
+
// Response tool not defined locally; nothing to route in-process.
|
|
530
|
+
if (bareMatches.length === 0) return undefined;
|
|
531
|
+
// A bare match may only stand in when the response carries no toolkit identity.
|
|
532
|
+
// Binding a toolkit child to another toolkit's handler would silently execute
|
|
533
|
+
// the wrong implementation.
|
|
534
|
+
if (toolkit === undefined && bareMatches.length === 1) return bareMatches[0];
|
|
535
|
+
|
|
536
|
+
const registered = [
|
|
537
|
+
...new Set(bareMatches.map(m => (m.toolkit ?? 'custom').toUpperCase())),
|
|
538
|
+
].sort();
|
|
539
|
+
throw new ValidationError(
|
|
540
|
+
`Cannot map custom tool "${finalSlug}": original slug "${originalSlug}" for toolkit ` +
|
|
541
|
+
`"${toolkit ?? 'custom'}" has no exact local match. Registered for toolkits: ${registered.join(', ')}.`
|
|
542
|
+
);
|
|
526
543
|
};
|
|
527
544
|
|
|
528
545
|
const addEntry = (finalSlug: string, originalSlug: string, toolkit?: string | null) => {
|
|
529
546
|
const resolvedToolkit = toolkit ?? undefined;
|
|
530
|
-
const match = findHandle(originalSlug, resolvedToolkit);
|
|
531
|
-
if (!match) return;
|
|
547
|
+
const match = findHandle(finalSlug, originalSlug, resolvedToolkit);
|
|
548
|
+
if (!match) return;
|
|
532
549
|
|
|
533
550
|
const finalSlugKey = finalSlug.toUpperCase();
|
|
534
551
|
if (byFinalSlug.has(finalSlugKey)) {
|
|
@@ -537,13 +554,21 @@ export function buildCustomToolsMapFromResponse(
|
|
|
537
554
|
);
|
|
538
555
|
}
|
|
539
556
|
|
|
557
|
+
const entryToolkit = resolvedToolkit ?? match.toolkit;
|
|
558
|
+
const qualifiedKey = qualifiedOriginalSlugKey(entryToolkit, originalSlug);
|
|
559
|
+
if (byToolkitAndOriginalSlug.has(qualifiedKey)) {
|
|
560
|
+
throw new ValidationError(
|
|
561
|
+
`Custom tool slug collision: original slug "${match.handle.slug}" is already registered for toolkit "${entryToolkit ?? 'custom'}".`
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
|
|
540
565
|
const entry: CustomToolsMapEntry = {
|
|
541
566
|
handle: match.handle,
|
|
542
567
|
finalSlug,
|
|
543
|
-
toolkit:
|
|
568
|
+
toolkit: entryToolkit,
|
|
544
569
|
};
|
|
545
570
|
byFinalSlug.set(finalSlugKey, entry);
|
|
546
|
-
byToolkitAndOriginalSlug.set(
|
|
571
|
+
byToolkitAndOriginalSlug.set(qualifiedKey, entry);
|
|
547
572
|
addOriginalSlugAlias({ byOriginalSlug, ambiguousOriginalSlugs, originalSlug, entry });
|
|
548
573
|
};
|
|
549
574
|
|
|
@@ -563,6 +588,16 @@ export function buildCustomToolsMapFromResponse(
|
|
|
563
588
|
}
|
|
564
589
|
}
|
|
565
590
|
|
|
591
|
+
// Ambiguity follows the local definitions, not whichever subset the response
|
|
592
|
+
// happened to include: a shared child slug must never become callable by its
|
|
593
|
+
// bare name just because a sibling was omitted.
|
|
594
|
+
for (const [originalSlugKey, matches] of handlesByOriginalSlug) {
|
|
595
|
+
if (matches.length > 1) {
|
|
596
|
+
byOriginalSlug.delete(originalSlugKey);
|
|
597
|
+
ambiguousOriginalSlugs.add(originalSlugKey);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
|
|
566
601
|
return {
|
|
567
602
|
byFinalSlug,
|
|
568
603
|
byOriginalSlug,
|