@composio/core 0.30.0 → 0.32.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.
Files changed (88) hide show
  1. package/dist/{CustomTool-9Vlb4XaS.mjs → CustomTool-B4dQn2M5.mjs} +1 -1
  2. package/dist/{CustomTool-Dzk3iqfP.d.mts → CustomTool-CBx9kzea.d.mts} +1 -1
  3. package/dist/{FileModifierErrors-WrqokuIF.mjs → FileModifierErrors-D-AKc3ds.mjs} +1 -1
  4. package/dist/{SsrfErrors-BSVMW915.mjs → SsrfErrors-BekZPeWY.mjs} +59 -12
  5. package/dist/{Telemetry-a7SOQXcg.mjs → Telemetry-BWKZmDxM.mjs} +2 -2
  6. package/dist/composio-CPf6NHnB.d.mts +20334 -0
  7. package/dist/{customTool.types-CpJbzxT6.d.mts → customTool.types-BSbIG1OG.d.mts} +306 -83
  8. package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +28 -11
  9. package/dist/docs/reference/sdk-reference/typescript/composio.mdx +28 -10
  10. package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +44 -32
  11. package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +8 -6
  12. package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +4 -3
  13. package/dist/docs/reference/sdk-reference/typescript/index.mdx +4 -2
  14. package/dist/docs/reference/sdk-reference/typescript/keyring.mdx +6 -3
  15. package/dist/docs/reference/sdk-reference/typescript/logs.mdx +5 -3
  16. package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +54 -43
  17. package/dist/docs/reference/sdk-reference/typescript/meta.json +1 -0
  18. package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +5 -14
  19. package/dist/docs/reference/sdk-reference/typescript/session-configs.mdx +5 -3
  20. package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +7 -5
  21. package/dist/docs/reference/sdk-reference/typescript/session-webhooks.mdx +64 -0
  22. package/dist/docs/reference/sdk-reference/typescript/session.mdx +16 -16
  23. package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +36 -8
  24. package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +14 -11
  25. package/dist/docs/reference/sdk-reference/typescript/tools.mdx +18 -20
  26. package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +42 -30
  27. package/dist/docs/reference/sdk-reference/typescript/usage.mdx +6 -4
  28. package/dist/docs/reference/sdk-reference/typescript/webhook-endpoints.mdx +9 -7
  29. package/dist/docs/reference/sdk-reference/typescript/webhook-subscriptions.mdx +13 -9
  30. package/dist/docs/reference/sdk-reference/typescript/webhooks.mdx +3 -1
  31. package/dist/{errors-xC13uvaA.mjs → errors-CtIKA9BH.mjs} +2 -2
  32. package/dist/experimental/index.d.mts +2 -2
  33. package/dist/experimental/index.mjs +1 -1
  34. package/dist/{fileUtils.node-CAwIbWYH.mjs → fileUtils.node-BJUYMEph.mjs} +7 -7
  35. package/dist/index.d.mts +10 -15
  36. package/dist/index.mjs +582 -242
  37. package/dist/{jsonSchema-Cc4EtHRw.mjs → jsonSchema-BZoXGUCr.mjs} +2 -2
  38. package/dist/models/Files.node.mjs +3 -3
  39. package/dist/{sensitiveFileUploadPaths-CSyJ3Ku8.mjs → sensitiveFileUploadPaths-CcbMAYCC.mjs} +21 -15
  40. package/dist/{ssrfGuard.node-CdIkwqVu.mjs → ssrfGuard.node-B749ae5Q.mjs} +1 -1
  41. package/dist/{types-DQdUb7OG.d.mts → types-ns3Q_WrP.d.mts} +2 -2
  42. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
  43. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
  44. package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
  45. package/dist/utils/modifiers/FileToolModifier.node.mjs +5 -5
  46. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
  47. package/dist/utils/ssrfGuard.node.mjs +1 -1
  48. package/dist/utils/ssrfGuard.workerd.mjs +1 -1
  49. package/package.json +4 -4
  50. package/src/composio.ts +26 -7
  51. package/src/errors/ComposioError.ts +3 -2
  52. package/src/index.ts +19 -0
  53. package/src/lib/toolRouterParams.ts +38 -14
  54. package/src/models/AuthConfigs.ts +18 -2
  55. package/src/models/ConnectedAccounts.ts +30 -17
  56. package/src/models/CustomTool.ts +0 -10
  57. package/src/models/Keyring.ts +2 -1
  58. package/src/models/MCP.ts +44 -36
  59. package/src/models/SessionWebhooks.ts +136 -0
  60. package/src/models/ToolRouter.ts +39 -4
  61. package/src/models/ToolRouterSession.ts +2 -2
  62. package/src/models/ToolRouterSessionFileMount.ts +3 -1
  63. package/src/models/Toolkits.ts +1 -0
  64. package/src/models/Tools.ts +6 -10
  65. package/src/models/Triggers.ts +48 -213
  66. package/src/models/Webhooks.ts +2 -0
  67. package/src/provider/ComposioProvider.ts +0 -1
  68. package/src/telemetry/BatchProcessor.ts +1 -1
  69. package/src/telemetry/Telemetry.ts +1 -1
  70. package/src/types/authConfigs.types.ts +14 -0
  71. package/src/types/connectedAccountAuthStates.types.ts +0 -1
  72. package/src/types/provider.types.ts +0 -1
  73. package/src/types/sessionWebhooks.types.ts +292 -0
  74. package/src/types/tool.types.ts +1 -1
  75. package/src/types/toolRouter.types.ts +33 -4
  76. package/src/types/toolkit.types.ts +21 -0
  77. package/src/types/triggers.types.ts +4 -0
  78. package/src/utils/crypto.ts +6 -5
  79. package/src/utils/env.ts +2 -5
  80. package/src/utils/fileUtils.node.ts +4 -3
  81. package/src/utils/logger.ts +19 -9
  82. package/src/utils/pusher.ts +5 -2
  83. package/src/utils/readResponseBody.ts +30 -17
  84. package/src/utils/transformers/authConfigs.ts +6 -3
  85. package/src/utils/transformers/toolkits.ts +7 -0
  86. package/src/utils/userCallback.ts +3 -1
  87. package/src/utils/webhookVerification.ts +211 -0
  88. package/dist/composio-DaokW5sV.d.mts +0 -9593
@@ -1,4 +1,3 @@
1
- import { logger } from '../..';
2
1
  import {
3
2
  AuthConfigRetrieveResponse,
4
3
  AuthConfigRetrieveResponseSchema,
@@ -15,19 +14,21 @@ import {
15
14
  } from '@composio/client/resources/auth-configs';
16
15
  import { transform } from '../transform';
17
16
 
17
+ type RawAuthConfig = RawAuthConfigRetrieveResponse | RawAuthConfigListResponse['items'][number];
18
+
18
19
  /**
19
20
  * Transforms an auth config response from API format to SDK format.
20
21
  *
21
22
  * This method converts property names from snake_case to camelCase and reorganizes
22
23
  * the data structure to match the SDK's standardized format for auth configurations.
23
24
  *
24
- * @param {RawAuthConfigRetrieveResponse} authConfig - The raw API response to transform
25
+ * @param {RawAuthConfig} authConfig - The raw retrieve response or list item to transform
25
26
  * @returns {AuthConfigRetrieveResponse} The transformed auth config data
26
27
  *
27
28
  * @private
28
29
  */
29
30
  export function transformAuthConfigRetrieveResponse(
30
- authConfig: RawAuthConfigRetrieveResponse
31
+ authConfig: RawAuthConfig
31
32
  ): AuthConfigRetrieveResponse {
32
33
  return transform(authConfig)
33
34
  .with(AuthConfigRetrieveResponseSchema)
@@ -56,6 +57,7 @@ export function transformAuthConfigRetrieveResponse(
56
57
  authConfig.tool_access_config.tools_for_connected_account_creation,
57
58
  }
58
59
  : undefined,
60
+ managedAppId: authConfig.managed_app_id,
59
61
  }));
60
62
  }
61
63
 
@@ -103,5 +105,6 @@ export function transformCreateAuthConfigResponse(
103
105
  authScheme: response.auth_config.auth_scheme,
104
106
  isComposioManaged: response.auth_config.is_composio_managed,
105
107
  toolkit: response.toolkit.slug,
108
+ managedAppId: response.auth_config.managed_app_id,
106
109
  }));
107
110
  }
@@ -156,6 +156,13 @@ export const transformToolkitRetrieveResponse = (
156
156
  },
157
157
  isLocalToolkit: response.is_local_toolkit,
158
158
  composioManagedAuthSchemes: response.composio_managed_auth_schemes,
159
+ composioManagedAuth: response.composio_managed_auth?.map(app => ({
160
+ managedAppId: app.managed_app_id,
161
+ isDefault: app.is_default,
162
+ mode: app.mode,
163
+ scopes: app.scopes,
164
+ ...(app.user_scopes != null && { userScopes: app.user_scopes }),
165
+ })),
159
166
  authConfigDetails: response.auth_config_details?.map(authConfig => ({
160
167
  name: authConfig.name,
161
168
  mode: authConfig.mode,
@@ -11,7 +11,9 @@ import logger from './logger';
11
11
  export function describeThrown(value: unknown): string {
12
12
  try {
13
13
  if (value instanceof Error) return value.message;
14
- if (typeof value === 'object' && value !== null) return JSON.stringify(value) ?? String(value);
14
+ if (typeof value === 'object' && value !== null) {
15
+ return JSON.stringify(value) ?? Object.prototype.toString.call(value);
16
+ }
15
17
  return String(value);
16
18
  } catch {
17
19
  try {
@@ -0,0 +1,211 @@
1
+ import {
2
+ ComposioWebhookPayloadError,
3
+ ComposioWebhookSignatureVerificationError,
4
+ } from '../errors/TriggerErrors';
5
+ import type { WebhookRequestLike } from '../types/triggers.types';
6
+ import { hmacSha256Base64, timingSafeEqual } from './crypto';
7
+ import { assertValidBodyLimit, readBodyWithLimit } from './readResponseBody';
8
+ import { describeThrown } from './userCallback';
9
+
10
+ const DEFAULT_WEBHOOK_BODY_LIMIT_BYTES = 10 * 1024 * 1024;
11
+
12
+ /**
13
+ * The signature header names Composio sends with every webhook request.
14
+ */
15
+ export const WEBHOOK_HEADERS = {
16
+ id: 'webhook-id',
17
+ timestamp: 'webhook-timestamp',
18
+ signature: 'webhook-signature',
19
+ } as const;
20
+
21
+ const isFetchRequest = (request: WebhookRequestLike): request is Request =>
22
+ typeof Request !== 'undefined' && request instanceof Request;
23
+
24
+ /**
25
+ * Coerces an already-buffered request body into the string expected by
26
+ * signature verification.
27
+ */
28
+ const bodyToString = (body: unknown): string => {
29
+ if (typeof body === 'string') {
30
+ return body;
31
+ }
32
+ if (body === null || body === undefined) {
33
+ return '';
34
+ }
35
+ // Already-parsed object (e.g. Next.js Pages Router with the JSON body parser).
36
+ // Note: re-stringifying cannot reproduce the exact bytes Composio signed, so
37
+ // signature verification on a pre-parsed body is best-effort only.
38
+ if (typeof body === 'object') {
39
+ return JSON.stringify(body);
40
+ }
41
+ return describeThrown(body);
42
+ };
43
+
44
+ const webhookBodyLimitError = (maxBytes: number): ComposioWebhookPayloadError =>
45
+ new ComposioWebhookPayloadError(`Webhook payload exceeds the ${maxBytes}-byte limit`);
46
+
47
+ export const assertWebhookBodySize = (body: string | Uint8Array, maxBytes: number): void => {
48
+ assertValidBodyLimit(maxBytes);
49
+ if (
50
+ body.length > maxBytes ||
51
+ (typeof body === 'string' && new TextEncoder().encode(body).byteLength > maxBytes)
52
+ ) {
53
+ throw webhookBodyLimitError(maxBytes);
54
+ }
55
+ };
56
+
57
+ /**
58
+ * Reads the raw body and the headers from either request shape: a Fetch API
59
+ * `Request`, or a plain `{ body, headers }` object.
60
+ */
61
+ export const readWebhookRequest = async (
62
+ request: WebhookRequestLike,
63
+ maxBytes = DEFAULT_WEBHOOK_BODY_LIMIT_BYTES
64
+ ): Promise<{ body: string; headers: unknown }> => {
65
+ if (isFetchRequest(request)) {
66
+ if (request.bodyUsed) {
67
+ throw new TypeError('Webhook request body has already been read');
68
+ }
69
+ const bytes = await readBodyWithLimit(request, maxBytes, () => webhookBodyLimitError(maxBytes));
70
+ return { body: new TextDecoder().decode(bytes), headers: request.headers };
71
+ }
72
+ const body = request.body instanceof Uint8Array ? request.body : bodyToString(request.body);
73
+ assertWebhookBodySize(body, maxBytes);
74
+ return {
75
+ body: typeof body === 'string' ? body : new TextDecoder().decode(body),
76
+ headers: request.headers,
77
+ };
78
+ };
79
+
80
+ /**
81
+ * Reads a single header value case-insensitively from either a `Headers`
82
+ * instance or a plain record (where values may be `string | string[]`).
83
+ * Returns `undefined` when the header is missing.
84
+ */
85
+ export const getHeader = (headers: unknown, name: string): string | undefined => {
86
+ if (typeof Headers !== 'undefined' && headers instanceof Headers) {
87
+ return headers.get(name) ?? undefined;
88
+ }
89
+
90
+ if (headers === null || typeof headers !== 'object') {
91
+ return undefined;
92
+ }
93
+
94
+ // Plain record: match the header name case-insensitively.
95
+ const target = name.toLowerCase();
96
+ for (const [key, value] of Object.entries(headers as Record<string, unknown>)) {
97
+ if (key.toLowerCase() !== target) {
98
+ continue;
99
+ }
100
+ if (Array.isArray(value)) {
101
+ const first = value.find((item): item is string => typeof item === 'string');
102
+ return first;
103
+ }
104
+ return typeof value === 'string' ? value : undefined;
105
+ }
106
+ return undefined;
107
+ };
108
+
109
+ /**
110
+ * Verifies the HMAC-SHA256 signature of a webhook payload.
111
+ * The signature format used by Composio is: `v1,base64EncodedSignature`
112
+ * The signing input is the UTF-8 prefix `${msgId}.${timestamp}.` followed by
113
+ * the original payload bytes.
114
+ */
115
+ export async function verifyWebhookSignature(
116
+ webhookId: string,
117
+ webhookTimestamp: string,
118
+ payload: string | Uint8Array,
119
+ signature: string,
120
+ secret: string
121
+ ): Promise<void> {
122
+ if (payload.length === 0) {
123
+ throw new ComposioWebhookSignatureVerificationError('No webhook payload was provided.');
124
+ }
125
+
126
+ if (signature.length === 0) {
127
+ throw new ComposioWebhookSignatureVerificationError(
128
+ "No signature header value was provided. Please pass the value of the 'webhook-signature' header."
129
+ );
130
+ }
131
+
132
+ if (secret.length === 0) {
133
+ throw new ComposioWebhookSignatureVerificationError(
134
+ 'No webhook secret was provided. You can find your webhook secret in your Composio dashboard.'
135
+ );
136
+ }
137
+
138
+ if (webhookId.length === 0) {
139
+ throw new ComposioWebhookSignatureVerificationError(
140
+ "No webhook ID was provided. Please pass the value of the 'webhook-id' header."
141
+ );
142
+ }
143
+
144
+ if (webhookTimestamp.length === 0) {
145
+ throw new ComposioWebhookSignatureVerificationError(
146
+ "No webhook timestamp was provided. Please pass the value of the 'webhook-timestamp' header."
147
+ );
148
+ }
149
+
150
+ // Parse signature - may have multiple signatures prefixed with version (e.g., "v1,base64sig")
151
+ const signatures = signature.split(' ');
152
+ const v1Signatures: string[] = [];
153
+
154
+ for (const sig of signatures) {
155
+ const [version, value] = sig.split(',');
156
+ if (version === 'v1' && value) {
157
+ v1Signatures.push(value);
158
+ }
159
+ }
160
+
161
+ if (v1Signatures.length === 0) {
162
+ throw new ComposioWebhookSignatureVerificationError(
163
+ 'No valid v1 signature found in the webhook-signature header. ' +
164
+ "Expected format: 'v1,base64EncodedSignature'"
165
+ );
166
+ }
167
+
168
+ const encoder = new TextEncoder();
169
+ const prefix = `${webhookId}.${webhookTimestamp}.`;
170
+ let toSign: Uint8Array<ArrayBuffer>;
171
+ if (typeof payload === 'string') {
172
+ toSign = encoder.encode(prefix + payload);
173
+ } else {
174
+ const prefixBytes = encoder.encode(prefix);
175
+ toSign = new Uint8Array(prefixBytes.length + payload.length);
176
+ toSign.set(prefixBytes);
177
+ toSign.set(payload, prefixBytes.length);
178
+ }
179
+ const expectedSignature = await hmacSha256Base64(secret, toSign);
180
+
181
+ if (!v1Signatures.some(candidate => timingSafeEqual(candidate, expectedSignature))) {
182
+ throw new ComposioWebhookSignatureVerificationError(
183
+ 'The signature provided is invalid. Please ensure you are using the correct webhook secret.'
184
+ );
185
+ }
186
+ }
187
+
188
+ /**
189
+ * Validates that the webhook timestamp is within the allowed tolerance
190
+ */
191
+ export function validateWebhookTimestamp(webhookTimestamp: string, tolerance: number): void {
192
+ const timestampSeconds = parseInt(webhookTimestamp, 10);
193
+
194
+ if (Number.isNaN(timestampSeconds)) {
195
+ throw new ComposioWebhookPayloadError(
196
+ `Invalid webhook timestamp: ${webhookTimestamp}. Expected Unix timestamp in seconds.`
197
+ );
198
+ }
199
+
200
+ const webhookTimeMs = timestampSeconds * 1000;
201
+ const currentTime = Date.now();
202
+ const timeDifference = Math.abs(currentTime - webhookTimeMs);
203
+
204
+ if (timeDifference > tolerance * 1000) {
205
+ throw new ComposioWebhookSignatureVerificationError(
206
+ `The webhook timestamp is outside the allowed tolerance. ` +
207
+ `The webhook was sent ${Math.round(timeDifference / 1000)} seconds ago, ` +
208
+ `but the maximum allowed age is ${tolerance} seconds.`
209
+ );
210
+ }
211
+ }