@composio/core 0.11.0 → 0.13.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/BaseProvider-BBnsv9kS.d.mts +29425 -0
- package/dist/{BaseProvider-CVbQxTNa.d.cts → BaseProvider-Brb3o86-.d.mts} +91 -44
- package/dist/CustomTool-D9qwyMrv.mjs +468 -0
- package/dist/{CustomTool-C-IUByoU.d.cts → CustomTool-Dmi6ti3I.d.mts} +2 -4
- package/dist/{CustomTool-CChQSp44.d.mts → CustomTool-DrJpOhY2.d.mts} +2 -4
- package/dist/{FileModifierErrors-C7z16Dfi.mjs → FileModifierErrors-3fSwIWoa.mjs} +35 -36
- package/dist/{Telemetry-DQax33Gh.mjs → Telemetry-DhGI_J4G.mjs} +15 -15
- package/dist/{composio-pcA13w87.d.cts → composio-DHIKRdeG.d.mts} +641 -380
- package/dist/{composio-BlASKqjQ.d.mts → composio-vMwhASRc.d.mts} +1390 -1129
- package/dist/{customTool.types-QtkAZQma.d.cts → customTool.types-CKH2R2ia.d.mts} +487 -189
- package/dist/{customTool.types-DLIORcYN.d.mts → customTool.types-DXin7Cfc.d.mts} +924 -626
- package/dist/docs/error-consistency.md +97 -0
- package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +306 -0
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +205 -0
- package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +488 -0
- package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +94 -0
- package/dist/docs/reference/sdk-reference/typescript/index.mdx +67 -0
- package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +304 -0
- package/dist/docs/reference/sdk-reference/typescript/meta.json +17 -0
- package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +107 -0
- package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +163 -0
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +229 -0
- package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +131 -0
- package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +169 -0
- package/dist/docs/reference/sdk-reference/typescript/tools.mdx +453 -0
- package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +434 -0
- package/dist/{CustomTool-D5s-aADw.mjs → errors-DSIlYfl5.mjs} +72 -459
- package/dist/experimental/index.d.mts +2 -3
- package/dist/experimental/index.mjs +1 -3
- package/dist/{fileUtils.node-Dq7ebZPC.mjs → fileUtils.node-BiO1JQsJ.mjs} +26 -25
- package/dist/index.d.mts +1708 -2400
- package/dist/index.mjs +2632 -2006
- package/dist/jsonSchema-CFKdONpP.mjs +251 -0
- package/dist/models/Files.node.d.mts +1 -2
- package/dist/models/Files.node.mjs +3 -4
- package/dist/models/Files.workerd.d.mts +0 -1
- package/dist/platform/node.d.mts +1 -2
- package/dist/platform/workerd.d.mts +1 -2
- package/dist/{chunk-CWQeghP5.mjs → rolldown-runtime-w6R9maHv.mjs} +3 -5
- package/dist/{types-J2KCXP8R.d.mts → types-D4Id3wXA.d.mts} +2 -3
- package/dist/{types-DRG5qLxI.d.cts → types-qTbYYBJw.d.mts} +2 -3
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -4
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -4
- package/dist/utils/config-defaults/ConfigDefaults.workerd.mjs +3 -0
- package/dist/utils/json-schema.d.mts +2 -0
- package/dist/utils/json-schema.mjs +3 -0
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +3 -1
- package/dist/utils/modifiers/FileToolModifier.node.mjs +44 -24
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +3 -1
- package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
- package/docs/error-consistency.md +97 -0
- package/package.json +40 -88
- package/src/composio.ts +509 -0
- package/src/errors/AuthConfigErrors.ts +23 -0
- package/src/errors/ComposioError.ts +408 -0
- package/src/errors/ConnectedAccountsErrors.ts +158 -0
- package/src/errors/ConnectionRequestErrors.ts +32 -0
- package/src/errors/FileModifierErrors.ts +100 -0
- package/src/errors/PusherErrors.ts +28 -0
- package/src/errors/RemoteFileErrors.ts +62 -0
- package/src/errors/SDKErrors.ts +92 -0
- package/src/errors/ToolErrors.ts +244 -0
- package/src/errors/ToolkitErrors.ts +39 -0
- package/src/errors/TriggerErrors.ts +120 -0
- package/src/errors/ValidationErrors.ts +99 -0
- package/src/errors/index.ts +41 -0
- package/src/experimental/index.ts +28 -0
- package/src/index.ts +64 -0
- package/src/lib/toolRouterConstants.ts +1 -0
- package/src/lib/toolRouterParams.ts +306 -0
- package/src/models/AuthConfigs.ts +398 -0
- package/src/models/AuthScheme.ts +206 -0
- package/src/models/ConnectedAccounts.ts +735 -0
- package/src/models/ConnectionRequest.ts +150 -0
- package/src/models/CustomTool.ts +676 -0
- package/src/models/Experimental.ts +202 -0
- package/src/models/Files.node.ts +93 -0
- package/src/models/Files.workerd.ts +49 -0
- package/src/models/MCP.ts +478 -0
- package/src/models/RemoteFile.ts +172 -0
- package/src/models/SessionContext.ts +147 -0
- package/src/models/Sessions.ts +21 -0
- package/src/models/ToolRouter.ts +391 -0
- package/src/models/ToolRouterSession.ts +827 -0
- package/src/models/ToolRouterSessionFileMount.ts +389 -0
- package/src/models/Toolkits.ts +412 -0
- package/src/models/Tools.ts +1260 -0
- package/src/models/Triggers.ts +1381 -0
- package/src/models/customToolExecution.ts +118 -0
- package/src/models/inlineCustomToolsPayload.ts +17 -0
- package/src/models/proxyParamsTransform.ts +26 -0
- package/src/provider/BaseProvider.ts +138 -0
- package/src/provider/ComposioProvider.ts +29 -0
- package/src/provider/OpenAIProvider.ts +547 -0
- package/src/services/internal/InternalService.ts +50 -0
- package/src/services/internal/InternalService.types.ts +14 -0
- package/src/services/pusher/Pusher.ts +230 -0
- package/src/services/telemetry/TelemetryService.ts +48 -0
- package/src/services/telemetry/TelemetryService.types.ts +67 -0
- package/src/telemetry/BatchProcessor.ts +77 -0
- package/src/telemetry/README.md +123 -0
- package/src/telemetry/Telemetry.ts +356 -0
- package/src/types/ToolRouterSessionFilesMount.types.ts +96 -0
- package/src/types/authConfigs.types.ts +174 -0
- package/src/types/composio.types.ts +1 -0
- package/src/types/connectedAccountAuthStates.types.ts +852 -0
- package/src/types/connectedAccounts.types.ts +395 -0
- package/src/types/connectionRequest.types.ts +16 -0
- package/src/types/customTool.types.ts +261 -0
- package/{dist/files.types-lo4zZd87.d.cts → src/types/files.types.ts} +3 -5
- package/src/types/mcp.experimental.types.ts +163 -0
- package/src/types/mcp.types.ts +362 -0
- package/src/types/modifiers.types.ts +663 -0
- package/src/types/org.types.ts +0 -0
- package/src/types/provider.types.ts +41 -0
- package/src/types/pusher.types.ts +18 -0
- package/src/types/requestOptions.types.ts +62 -0
- package/src/types/telemetry.types.ts +89 -0
- package/src/types/tool.types.ts +408 -0
- package/src/types/toolRouter.types.ts +761 -0
- package/src/types/toolkit.types.ts +130 -0
- package/src/types/triggers.types.ts +401 -0
- package/src/types/webhookEvents.types.ts +219 -0
- package/src/utils/buffer.ts +30 -0
- package/src/utils/cancellation.ts +22 -0
- package/src/utils/config-defaults/ConfigDefaults.node.ts +7 -0
- package/src/utils/config-defaults/ConfigDefaults.workerd.ts +10 -0
- package/src/utils/config-defaults/index.ts +1 -0
- package/src/utils/config-defaults/types.ts +14 -0
- package/src/utils/constants.ts +22 -0
- package/src/utils/crypto.ts +34 -0
- package/src/utils/env.ts +34 -0
- package/src/utils/fileDirs.ts +81 -0
- package/src/utils/fileUtils.node.ts +458 -0
- package/src/utils/json-schema.ts +1 -0
- package/src/utils/jsonSchema.ts +355 -0
- package/src/utils/logger.ts +99 -0
- package/src/utils/mime.ts +75 -0
- package/src/utils/modifiers/FileToolModifier.node.ts +477 -0
- package/src/utils/modifiers/FileToolModifier.utils.neutral.ts +132 -0
- package/src/utils/modifiers/FileToolModifier.workerd.ts +51 -0
- package/src/utils/pagination.ts +73 -0
- package/src/utils/pusher.ts +286 -0
- package/src/utils/schemaPropertyKeys.ts +433 -0
- package/src/utils/sdk.ts +110 -0
- package/src/utils/sensitiveFileUploadPaths.node.ts +105 -0
- package/src/utils/session.ts +114 -0
- package/src/utils/toolArguments.ts +73 -0
- package/src/utils/toolkitVersion.ts +26 -0
- package/src/utils/transform.ts +42 -0
- package/src/utils/transformers/authConfigs.ts +107 -0
- package/src/utils/transformers/connectedAccounts.ts +119 -0
- package/src/utils/transformers/mcp.ts +164 -0
- package/src/utils/transformers/toolRouterResponseTransform.ts +160 -0
- package/src/utils/transformers/toolkits.ts +100 -0
- package/src/utils/transformers/triggers.ts +118 -0
- package/src/utils/uploadDirAllowlist.node.ts +178 -0
- package/src/utils/uuid.ts +7 -0
- package/src/utils/version.ts +58 -0
- package/src/utils/zodSchema.ts +90 -0
- package/dist/BaseProvider-BvHvJLXc.d.mts +0 -29378
- package/dist/CustomTool-D3-NreIm.cjs +0 -1341
- package/dist/FileModifierErrors-BYJBHiay.cjs +0 -554
- package/dist/FileToolModifier.utils.neutral-DSBQs9-i.cjs +0 -96
- package/dist/Telemetry-BQ_pl5AK.cjs +0 -360
- package/dist/buffer-BjWptbNH.cjs +0 -63
- package/dist/chunk-CQwRTUmo.cjs +0 -53
- package/dist/experimental/index.cjs +0 -5
- package/dist/experimental/index.d.cts +0 -3
- package/dist/fileUtils.node-DtnSRMWa.cjs +0 -462
- package/dist/index.cjs +0 -8523
- package/dist/index.d.cts +0 -6065
- package/dist/models/Files.node.cjs +0 -55
- package/dist/models/Files.node.d.cts +0 -56
- package/dist/models/Files.workerd.cjs +0 -29
- package/dist/models/Files.workerd.d.cts +0 -13
- package/dist/platform/node.cjs +0 -55
- package/dist/platform/node.d.cts +0 -11
- package/dist/platform/workerd.cjs +0 -42
- package/dist/platform/workerd.d.cts +0 -12
- package/dist/types-pDNm1lYs.d.cts +0 -69
- package/dist/utils/config-defaults/ConfigDefaults.node.cjs +0 -10
- package/dist/utils/config-defaults/ConfigDefaults.node.d.cts +0 -7
- package/dist/utils/config-defaults/ConfigDefaults.workerd.cjs +0 -10
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.cts +0 -7
- package/dist/utils/modifiers/FileToolModifier.node.cjs +0 -224
- package/dist/utils/modifiers/FileToolModifier.node.d.cts +0 -22
- package/dist/utils/modifiers/FileToolModifier.workerd.cjs +0 -27
- package/dist/utils/modifiers/FileToolModifier.workerd.d.cts +0 -20
- /package/dist/{FileToolModifier.utils.neutral-BpSceNK8.mjs → FileToolModifier.utils.neutral-B5rT711M.mjs} +0 -0
- /package/dist/{buffer-yOtEsT4J.mjs → buffer-PcbMMsgm.mjs} +0 -0
- /package/dist/{files.types-BXDWA_zS.d.mts → files.types-DeMC_mAW.d.mts} +0 -0
- /package/dist/{types-HpJQ8K9l.d.mts → types-DdoCRzLj.d.mts} +0 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { z } from 'zod/v3';
|
|
2
|
+
import { AuthSchemeTypes } from './authConfigs.types';
|
|
3
|
+
import { ConnectionStatuses } from './connectedAccountAuthStates.types';
|
|
4
|
+
|
|
5
|
+
// =============================================================================
|
|
6
|
+
// WEBHOOK EVENT TYPES
|
|
7
|
+
// =============================================================================
|
|
8
|
+
|
|
9
|
+
export const WebhookEventTypes = {
|
|
10
|
+
CONNECTION_EXPIRED: 'composio.connected_account.expired',
|
|
11
|
+
TRIGGER_MESSAGE: 'composio.trigger.message',
|
|
12
|
+
} as const;
|
|
13
|
+
|
|
14
|
+
export type WebhookEventType = (typeof WebhookEventTypes)[keyof typeof WebhookEventTypes];
|
|
15
|
+
|
|
16
|
+
// =============================================================================
|
|
17
|
+
// CONNECTED ACCOUNT DATA SCHEMA (matches GET /api/v3/connected_accounts/{id})
|
|
18
|
+
// =============================================================================
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Auth config schema for webhook payloads (raw API format, snake_case).
|
|
22
|
+
*
|
|
23
|
+
* This intentionally does NOT reuse ConnectedAccountAuthConfigSchema from
|
|
24
|
+
* connectedAccounts.types.ts because:
|
|
25
|
+
* - Webhook payloads arrive in raw snake_case (is_composio_managed, is_disabled)
|
|
26
|
+
* while the SDK schema uses camelCase (isComposioManaged, isDisabled)
|
|
27
|
+
* - Webhook payloads include additional fields (auth_scheme, deprecated)
|
|
28
|
+
* not present in the SDK schema
|
|
29
|
+
*
|
|
30
|
+
* Uses .passthrough() to accept unknown fields the API may add in the future.
|
|
31
|
+
*
|
|
32
|
+
* @see ConnectedAccountAuthConfigSchema in connectedAccounts.types.ts for the camelCase SDK version
|
|
33
|
+
*/
|
|
34
|
+
export const WebhookConnectedAccountAuthConfigSchema = z
|
|
35
|
+
.object({
|
|
36
|
+
/** The nano ID of the auth config */
|
|
37
|
+
id: z.string(),
|
|
38
|
+
/** @deprecated - use state.authScheme instead */
|
|
39
|
+
auth_scheme: z.nativeEnum(AuthSchemeTypes),
|
|
40
|
+
/** Whether this auth config is managed by Composio */
|
|
41
|
+
is_composio_managed: z.boolean(),
|
|
42
|
+
/** Whether the auth config is disabled */
|
|
43
|
+
is_disabled: z.boolean(),
|
|
44
|
+
/** @deprecated */
|
|
45
|
+
deprecated: z
|
|
46
|
+
.object({
|
|
47
|
+
uuid: z.string(),
|
|
48
|
+
})
|
|
49
|
+
.optional(),
|
|
50
|
+
})
|
|
51
|
+
.passthrough();
|
|
52
|
+
|
|
53
|
+
export type WebhookConnectedAccountAuthConfig = z.infer<
|
|
54
|
+
typeof WebhookConnectedAccountAuthConfigSchema
|
|
55
|
+
>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Simplified connection state schema for webhook payloads (raw API format).
|
|
59
|
+
*
|
|
60
|
+
* This intentionally does NOT reuse ConnectionDataSchema from
|
|
61
|
+
* connectedAccountAuthStates.types.ts because:
|
|
62
|
+
* - ConnectionDataSchema is a discriminated union requiring typed `val`
|
|
63
|
+
* per auth scheme (e.g., Oauth2ConnectionDataSchema)
|
|
64
|
+
* - Webhook payloads need loose validation (z.record(z.unknown()))
|
|
65
|
+
* since the connection state varies and isn't the focus of event handling
|
|
66
|
+
*
|
|
67
|
+
* Uses .passthrough() to accept unknown fields the API may add in the future.
|
|
68
|
+
*
|
|
69
|
+
* @see ConnectionDataSchema in connectedAccountAuthStates.types.ts for the full typed version
|
|
70
|
+
*/
|
|
71
|
+
export const WebhookConnectionStateSchema = z
|
|
72
|
+
.object({
|
|
73
|
+
/** The auth scheme type (e.g., 'OAUTH2', 'API_KEY') */
|
|
74
|
+
authScheme: z.nativeEnum(AuthSchemeTypes),
|
|
75
|
+
/** Connection state values - varies by auth scheme */
|
|
76
|
+
val: z.record(z.unknown()),
|
|
77
|
+
})
|
|
78
|
+
.passthrough();
|
|
79
|
+
|
|
80
|
+
export type WebhookConnectionState = z.infer<typeof WebhookConnectionStateSchema>;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Connected account data schema for webhook payloads (raw API format, snake_case).
|
|
84
|
+
*
|
|
85
|
+
* This is the snake_case equivalent of ConnectedAccountRetrieveResponseSchema
|
|
86
|
+
* from connectedAccounts.types.ts. It intentionally does NOT reuse that schema because:
|
|
87
|
+
* - Webhook payloads arrive in raw snake_case (auth_config, user_id, created_at, etc.)
|
|
88
|
+
* while the SDK schema uses camelCase (authConfig, createdAt, etc.)
|
|
89
|
+
* - The SDK applies a transformation layer (utils/transformers/connectedAccounts.ts)
|
|
90
|
+
* before validation; webhooks are validated directly by the user
|
|
91
|
+
* - Webhook payloads include user_id, which the SDK schema omits
|
|
92
|
+
*
|
|
93
|
+
* Uses .passthrough() to accept unknown fields the API may add in the future.
|
|
94
|
+
*
|
|
95
|
+
* @see ConnectedAccountRetrieveResponseSchema in connectedAccounts.types.ts for the camelCase SDK version
|
|
96
|
+
* @see utils/transformers/connectedAccounts.ts for the snake-to-camel transformation
|
|
97
|
+
*/
|
|
98
|
+
export const SingleConnectedAccountDetailedResponseSchema = z
|
|
99
|
+
.object({
|
|
100
|
+
/** Toolkit information */
|
|
101
|
+
toolkit: z
|
|
102
|
+
.object({
|
|
103
|
+
slug: z.string().describe('The slug of the toolkit'),
|
|
104
|
+
})
|
|
105
|
+
.passthrough(),
|
|
106
|
+
/** Auth config details */
|
|
107
|
+
auth_config: WebhookConnectedAccountAuthConfigSchema,
|
|
108
|
+
/** The nano ID of the connected account */
|
|
109
|
+
id: z.string(),
|
|
110
|
+
/** @deprecated - user ID of the connection owner */
|
|
111
|
+
user_id: z.string(),
|
|
112
|
+
/** Connection status */
|
|
113
|
+
status: z.nativeEnum(ConnectionStatuses),
|
|
114
|
+
/** ISO-8601 timestamp of creation */
|
|
115
|
+
created_at: z.string(),
|
|
116
|
+
/** ISO-8601 timestamp of last update */
|
|
117
|
+
updated_at: z.string(),
|
|
118
|
+
/** Connection state data (auth scheme + state values) */
|
|
119
|
+
state: WebhookConnectionStateSchema,
|
|
120
|
+
/** @deprecated - use state instead */
|
|
121
|
+
data: z.record(z.unknown()),
|
|
122
|
+
/** @deprecated - use state instead */
|
|
123
|
+
params: z.record(z.unknown()),
|
|
124
|
+
/** Reason for the current status (e.g., expiration reason) */
|
|
125
|
+
status_reason: z.string().nullable(),
|
|
126
|
+
/** Whether the connection is disabled */
|
|
127
|
+
is_disabled: z.boolean(),
|
|
128
|
+
/** Endpoint for making test requests */
|
|
129
|
+
test_request_endpoint: z.string().optional(),
|
|
130
|
+
/** @deprecated */
|
|
131
|
+
deprecated: z
|
|
132
|
+
.object({
|
|
133
|
+
labels: z.array(z.string()),
|
|
134
|
+
uuid: z.string(),
|
|
135
|
+
})
|
|
136
|
+
.optional(),
|
|
137
|
+
})
|
|
138
|
+
.passthrough();
|
|
139
|
+
|
|
140
|
+
export type SingleConnectedAccountDetailedResponse = z.infer<
|
|
141
|
+
typeof SingleConnectedAccountDetailedResponseSchema
|
|
142
|
+
>;
|
|
143
|
+
|
|
144
|
+
// =============================================================================
|
|
145
|
+
// CONNECTION EXPIRED WEBHOOK EVENT SCHEMA
|
|
146
|
+
// =============================================================================
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Webhook metadata for connection events.
|
|
150
|
+
* Note: This differs from the trigger webhook metadata in WebhookTriggerPayloadV3Schema.
|
|
151
|
+
*
|
|
152
|
+
* Uses .passthrough() to accept unknown fields the API may add in the future.
|
|
153
|
+
*/
|
|
154
|
+
export const WebhookConnectionMetadataSchema = z
|
|
155
|
+
.object({
|
|
156
|
+
/** Project nano ID */
|
|
157
|
+
project_id: z.string(),
|
|
158
|
+
/** Organization UUID */
|
|
159
|
+
org_id: z.string(),
|
|
160
|
+
})
|
|
161
|
+
.passthrough();
|
|
162
|
+
|
|
163
|
+
export type WebhookConnectionMetadata = z.infer<typeof WebhookConnectionMetadataSchema>;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Connection expired webhook event payload.
|
|
167
|
+
* Emitted when a connected account expires due to authentication refresh failure.
|
|
168
|
+
*
|
|
169
|
+
* Uses .passthrough() to accept unknown fields the API may add in the future.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* import { ConnectionExpiredEventSchema } from '@composio/core';
|
|
174
|
+
*
|
|
175
|
+
* // In your webhook handler
|
|
176
|
+
* const result = ConnectionExpiredEventSchema.safeParse(webhookPayload);
|
|
177
|
+
* if (result.success) {
|
|
178
|
+
* const { data, metadata } = result.data;
|
|
179
|
+
* console.log(`Connection ${data.id} expired for user ${data.user_id}`);
|
|
180
|
+
* console.log(`Toolkit: ${data.toolkit.slug}`);
|
|
181
|
+
* console.log(`Project: ${metadata.project_id}`);
|
|
182
|
+
* }
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
export const ConnectionExpiredEventSchema = z
|
|
186
|
+
.object({
|
|
187
|
+
/** Unique message ID (e.g., "msg_847cdfcd-d219-4f18-a6dd-91acd42ca94a") */
|
|
188
|
+
id: z.string(),
|
|
189
|
+
/** ISO-8601 timestamp of when the event was emitted */
|
|
190
|
+
timestamp: z.string(),
|
|
191
|
+
/** Event type identifier */
|
|
192
|
+
type: z.literal(WebhookEventTypes.CONNECTION_EXPIRED),
|
|
193
|
+
/** Connected account data (same as GET /api/v3/connected_accounts/{id}) */
|
|
194
|
+
data: SingleConnectedAccountDetailedResponseSchema,
|
|
195
|
+
/** Event metadata */
|
|
196
|
+
metadata: WebhookConnectionMetadataSchema,
|
|
197
|
+
})
|
|
198
|
+
.passthrough();
|
|
199
|
+
|
|
200
|
+
export type ConnectionExpiredEvent = z.infer<typeof ConnectionExpiredEventSchema>;
|
|
201
|
+
|
|
202
|
+
// =============================================================================
|
|
203
|
+
// UNION TYPE FOR ALL WEBHOOK EVENTS
|
|
204
|
+
// =============================================================================
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Union of all typed webhook event schemas.
|
|
208
|
+
* Extend this as new event types are added.
|
|
209
|
+
*
|
|
210
|
+
* Note: This covers specific known event types with strict validation.
|
|
211
|
+
* For unknown or new event types, use WebhookPayloadV3Schema from
|
|
212
|
+
* triggers.types.ts which accepts any composio.* event with loose validation.
|
|
213
|
+
*
|
|
214
|
+
* Trigger events (composio.trigger.message) are handled through the
|
|
215
|
+
* WebhookTriggerPayloadV3Schema in triggers.types.ts and the TriggerEvent type.
|
|
216
|
+
*/
|
|
217
|
+
export const WebhookEventSchema = z.discriminatedUnion('type', [ConnectionExpiredEventSchema]);
|
|
218
|
+
|
|
219
|
+
export type WebhookEvent = z.infer<typeof WebhookEventSchema>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert ArrayBuffer to base64.
|
|
3
|
+
*/
|
|
4
|
+
export function arrayBufferToBase64(buffer: ArrayBuffer) {
|
|
5
|
+
const bytes = new Uint8Array(buffer);
|
|
6
|
+
let binary = '';
|
|
7
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
8
|
+
binary += String.fromCharCode(bytes[i]);
|
|
9
|
+
}
|
|
10
|
+
return btoa(binary);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Helper function to convert base64 string to Uint8Array (cross-platform)
|
|
14
|
+
export const base64ToUint8Array = (base64: string): Uint8Array => {
|
|
15
|
+
const binary = atob(base64);
|
|
16
|
+
const bytes = new Uint8Array(binary.length);
|
|
17
|
+
for (let i = 0; i < binary.length; i++) {
|
|
18
|
+
bytes[i] = binary.charCodeAt(i);
|
|
19
|
+
}
|
|
20
|
+
return bytes;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// Helper function to convert Uint8Array to base64 string (cross-platform)
|
|
24
|
+
export const uint8ArrayToBase64 = (bytes: Uint8Array): string => {
|
|
25
|
+
let binary = '';
|
|
26
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
27
|
+
binary += String.fromCharCode(bytes[i]);
|
|
28
|
+
}
|
|
29
|
+
return btoa(binary);
|
|
30
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ComposioRequestCancelledError, isRequestAbortError } from '../errors/SDKErrors';
|
|
2
|
+
|
|
3
|
+
/** @internal */
|
|
4
|
+
export async function withCancellation<T>(
|
|
5
|
+
call: () => Promise<T>,
|
|
6
|
+
signal?: AbortSignal
|
|
7
|
+
): Promise<T> {
|
|
8
|
+
try {
|
|
9
|
+
return await call();
|
|
10
|
+
} catch (error) {
|
|
11
|
+
if (signal?.aborted && isRequestAbortError(error)) {
|
|
12
|
+
const underlyingMessage = error instanceof Error ? error.message : '';
|
|
13
|
+
const message = underlyingMessage
|
|
14
|
+
? `Request was cancelled by the caller: ${underlyingMessage}`
|
|
15
|
+
: 'Request was cancelled by the caller';
|
|
16
|
+
throw new ComposioRequestCancelledError(message, {
|
|
17
|
+
cause: error instanceof Error ? error : undefined,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ConfigDefaults } from './types';
|
|
2
|
+
|
|
3
|
+
export const CONFIG_DEFAULTS: ConfigDefaults = {
|
|
4
|
+
/**
|
|
5
|
+
* We don't support auto-uploading/download files in Cloudflare Workers yet.
|
|
6
|
+
*/
|
|
7
|
+
dangerouslyAllowAutoUploadDownloadFiles: false,
|
|
8
|
+
allowTracking: true,
|
|
9
|
+
toolkitVersions: 'latest',
|
|
10
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CONFIG_DEFAULTS } from '#config_defaults';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ComposioConfig } from '../../composio';
|
|
2
|
+
import type { BaseComposioProvider } from '../../provider/BaseProvider';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration defaults for Composio.
|
|
6
|
+
* These are the required fields that must have default values.
|
|
7
|
+
* The provider type is set to never since defaults don't include a provider instance.
|
|
8
|
+
*/
|
|
9
|
+
export type ConfigDefaults = Required<
|
|
10
|
+
Pick<
|
|
11
|
+
ComposioConfig<BaseComposioProvider<never, never, never>>,
|
|
12
|
+
'dangerouslyAllowAutoUploadDownloadFiles' | 'allowTracking' | 'toolkitVersions'
|
|
13
|
+
>
|
|
14
|
+
>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getEnvVariable } from './env';
|
|
2
|
+
|
|
3
|
+
// Constants
|
|
4
|
+
export const COMPOSIO_DIR = '.composio';
|
|
5
|
+
export const USER_DATA_FILE_NAME = 'user_data.json';
|
|
6
|
+
export const TEMP_FILES_DIRECTORY_NAME = 'files';
|
|
7
|
+
export const DEFAULT_BASE_URL = 'https://backend.composio.dev';
|
|
8
|
+
export const DEFAULT_WEB_URL = 'https://dashboard.composio.dev/';
|
|
9
|
+
|
|
10
|
+
export const TELEMETRY_URL = 'https://app.composio.dev';
|
|
11
|
+
export const CLIENT_PUSHER_KEY = getEnvVariable('CLIENT_PUSHER_KEY') || 'ff9f18c208855d77a152';
|
|
12
|
+
|
|
13
|
+
export const COMPOSIO_LOG_LEVEL = getEnvVariable('COMPOSIO_LOG_LEVEL') as
|
|
14
|
+
| 'debug'
|
|
15
|
+
| 'info'
|
|
16
|
+
| 'warn'
|
|
17
|
+
| 'error'
|
|
18
|
+
| undefined;
|
|
19
|
+
|
|
20
|
+
export const IS_DEVELOPMENT_OR_CI = getEnvVariable('DEVELOPMENT') || getEnvVariable('CI') || false;
|
|
21
|
+
|
|
22
|
+
export const DEFAULT_TOOL_ROUTER_SESSION_FILES_MOUNT_ID = 'files';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { arrayBufferToBase64 } from './buffer';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Computes HMAC-SHA256 using Web Crypto API
|
|
5
|
+
*/
|
|
6
|
+
export async function hmacSha256Base64(secret: string, message: string): Promise<string> {
|
|
7
|
+
const encoder = new TextEncoder();
|
|
8
|
+
const keyData = encoder.encode(secret);
|
|
9
|
+
const key = await globalThis.crypto.subtle.importKey(
|
|
10
|
+
'raw',
|
|
11
|
+
keyData,
|
|
12
|
+
{ name: 'HMAC', hash: 'SHA-256' },
|
|
13
|
+
false,
|
|
14
|
+
['sign']
|
|
15
|
+
);
|
|
16
|
+
const signatureData = encoder.encode(message);
|
|
17
|
+
const signatureBuffer = await globalThis.crypto.subtle.sign('HMAC', key, signatureData);
|
|
18
|
+
|
|
19
|
+
return arrayBufferToBase64(signatureBuffer);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Constant-time comparison of two strings to prevent timing attacks
|
|
24
|
+
*/
|
|
25
|
+
export function timingSafeEqual(a: string, b: string): boolean {
|
|
26
|
+
if (a.length !== b.length) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
let result = 0;
|
|
30
|
+
for (let i = 0; i < a.length; i++) {
|
|
31
|
+
result |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
32
|
+
}
|
|
33
|
+
return result === 0;
|
|
34
|
+
}
|
package/src/utils/env.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const getEnvVariable = (
|
|
2
|
+
name: string,
|
|
3
|
+
defaultValue: string | undefined = undefined
|
|
4
|
+
): string | undefined => {
|
|
5
|
+
try {
|
|
6
|
+
return process.env[name] || defaultValue;
|
|
7
|
+
} catch (_e) {
|
|
8
|
+
return defaultValue;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Method to return all the envs based on a specific prefix
|
|
14
|
+
* @param prefix
|
|
15
|
+
* @example
|
|
16
|
+
* COMPOSIO_TOOLKIT_VERSION_GITHUB=20250902_00
|
|
17
|
+
* COMPOSIO_TOOLKIT_VERSION_SLACK=20250902_00
|
|
18
|
+
* COMPOSIO_TOOLKIT_VERSION_GMAIL=latest
|
|
19
|
+
* @returns {Record<string, unknown>}
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
export const getEnvsWithPrefix = (prefix: string): Record<string, unknown> => {
|
|
23
|
+
try {
|
|
24
|
+
if (process && process.env) {
|
|
25
|
+
return Object.fromEntries(
|
|
26
|
+
Object.entries(process.env).filter(([key]) => key.startsWith(prefix))
|
|
27
|
+
);
|
|
28
|
+
} else {
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime-neutral helpers for normalizing user-provided filesystem paths.
|
|
3
|
+
*
|
|
4
|
+
* In filesystem-less runtimes (Cloudflare Workers, etc.) the platform
|
|
5
|
+
* abstraction reports `supportsFileSystem: false` and `homedir()` returns
|
|
6
|
+
* `null`. We use that as the signal to drop unresolvable entries from the
|
|
7
|
+
* allowlist (fail-closed) rather than silently passing `~/foo` through as
|
|
8
|
+
* a literal directory name.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { platform } from '#platform';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Expands a leading `~` to the user's home directory and resolves to an
|
|
15
|
+
* absolute path. Returns `undefined` when expansion is required but no
|
|
16
|
+
* home directory is available — that signals "unusable, drop me" to
|
|
17
|
+
* {@link expandHomeAndResolveMany}, which is safer than letting the literal
|
|
18
|
+
* `~/foo` survive as a CWD-relative path.
|
|
19
|
+
*/
|
|
20
|
+
export function expandHomeAndResolve(p: string | undefined): string | undefined {
|
|
21
|
+
if (!p) return p;
|
|
22
|
+
let expanded = p;
|
|
23
|
+
if (p === '~' || p.startsWith('~/') || p.startsWith('~\\')) {
|
|
24
|
+
const home = platform.homedir();
|
|
25
|
+
if (!home) return undefined;
|
|
26
|
+
expanded = p === '~' ? home : platform.joinPath(home, p.slice(2));
|
|
27
|
+
}
|
|
28
|
+
return platform.resolvePath(expanded);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Applies {@link expandHomeAndResolve} to each entry, dropping empty/invalid
|
|
33
|
+
* values. Preserves `undefined` and `false` (so downstream can distinguish
|
|
34
|
+
* "user did not configure" from "user explicitly disabled local uploads"
|
|
35
|
+
* from "user configured []").
|
|
36
|
+
*/
|
|
37
|
+
export function expandHomeAndResolveMany(
|
|
38
|
+
list: string[] | false | undefined
|
|
39
|
+
): string[] | false | undefined {
|
|
40
|
+
if (list === undefined) return undefined;
|
|
41
|
+
if (list === false) return false;
|
|
42
|
+
const out: string[] = [];
|
|
43
|
+
for (const raw of list) {
|
|
44
|
+
if (typeof raw !== 'string' || raw.trim() === '') continue;
|
|
45
|
+
const resolved = expandHomeAndResolve(raw);
|
|
46
|
+
if (resolved) out.push(resolved);
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Absolute path of the default upload staging directory
|
|
53
|
+
* (`<home>/.composio/temp`), or `null` when a home directory is unavailable
|
|
54
|
+
* (e.g. Cloudflare Workers).
|
|
55
|
+
*/
|
|
56
|
+
export function getDefaultUploadDir(): string | null {
|
|
57
|
+
const home = platform.homedir();
|
|
58
|
+
if (!home) return null;
|
|
59
|
+
return platform.resolvePath(platform.joinPath(home, '.composio', 'temp'));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Resolve the effective upload allowlist for a given user-provided value.
|
|
64
|
+
*
|
|
65
|
+
* - `undefined` → `[<default>]` when a home directory is available, else `[]`
|
|
66
|
+
* (fail-closed if we can't derive the default staging dir).
|
|
67
|
+
* - `false` → `[]` (explicit "reject all local paths"). URLs / File objects
|
|
68
|
+
* still work because they aren't path-checked.
|
|
69
|
+
* - `string[]` (including `[]`) replaces the default and is returned
|
|
70
|
+
* verbatim after `~` expansion / `path.resolve`. `[]` is treated as
|
|
71
|
+
* equivalent to `false`.
|
|
72
|
+
*/
|
|
73
|
+
export function resolveEffectiveUploadAllowlist(userDirs: string[] | false | undefined): string[] {
|
|
74
|
+
if (userDirs === undefined) {
|
|
75
|
+
const def = getDefaultUploadDir();
|
|
76
|
+
return def ? [def] : [];
|
|
77
|
+
}
|
|
78
|
+
if (userDirs === false) return [];
|
|
79
|
+
const resolved = expandHomeAndResolveMany(userDirs);
|
|
80
|
+
return Array.isArray(resolved) ? resolved : [];
|
|
81
|
+
}
|