@composio/core 0.12.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.
Files changed (144) hide show
  1. package/dist/BaseProvider-Brb3o86-.d.mts +29425 -0
  2. package/dist/{CustomTool-DEB4BQPl.mjs → CustomTool-D9qwyMrv.mjs} +1 -1
  3. package/dist/{CustomTool-DH18rVQu.d.mts → CustomTool-Dmi6ti3I.d.mts} +1 -1
  4. package/dist/CustomTool-DrJpOhY2.d.mts +74 -0
  5. package/dist/{composio-CHnEggnv.d.mts → composio-DHIKRdeG.d.mts} +253 -37
  6. package/dist/composio-vMwhASRc.d.mts +5698 -0
  7. package/dist/{customTool.types-DpIdOJjL.d.mts → customTool.types-CKH2R2ia.d.mts} +344 -25
  8. package/dist/customTool.types-DXin7Cfc.d.mts +2773 -0
  9. package/dist/docs/error-consistency.md +97 -0
  10. package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +306 -0
  11. package/dist/docs/reference/sdk-reference/typescript/composio.mdx +205 -0
  12. package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +488 -0
  13. package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +94 -0
  14. package/dist/docs/reference/sdk-reference/typescript/index.mdx +67 -0
  15. package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +304 -0
  16. package/dist/docs/reference/sdk-reference/typescript/meta.json +17 -0
  17. package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +107 -0
  18. package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +163 -0
  19. package/dist/docs/reference/sdk-reference/typescript/session.mdx +229 -0
  20. package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +131 -0
  21. package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +169 -0
  22. package/dist/docs/reference/sdk-reference/typescript/tools.mdx +453 -0
  23. package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +434 -0
  24. package/dist/{errors-D5f4pfvI.mjs → errors-DSIlYfl5.mjs} +2 -2
  25. package/dist/experimental/index.d.mts +2 -2
  26. package/dist/experimental/index.mjs +1 -1
  27. package/dist/index.d.mts +27 -4
  28. package/dist/index.mjs +423 -123
  29. package/dist/{jsonSchema-daqF3S3d.mjs → jsonSchema-CFKdONpP.mjs} +1 -1
  30. package/dist/{types-CaI5Z4PA.d.mts → types-D4Id3wXA.d.mts} +1 -1
  31. package/dist/types-qTbYYBJw.d.mts +12 -0
  32. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
  33. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
  34. package/dist/utils/modifiers/FileToolModifier.node.mjs +2 -2
  35. package/docs/error-consistency.md +97 -0
  36. package/package.json +4 -3
  37. package/src/composio.ts +509 -0
  38. package/src/errors/AuthConfigErrors.ts +23 -0
  39. package/src/errors/ComposioError.ts +408 -0
  40. package/src/errors/ConnectedAccountsErrors.ts +158 -0
  41. package/src/errors/ConnectionRequestErrors.ts +32 -0
  42. package/src/errors/FileModifierErrors.ts +100 -0
  43. package/src/errors/PusherErrors.ts +28 -0
  44. package/src/errors/RemoteFileErrors.ts +62 -0
  45. package/src/errors/SDKErrors.ts +92 -0
  46. package/src/errors/ToolErrors.ts +244 -0
  47. package/src/errors/ToolkitErrors.ts +39 -0
  48. package/src/errors/TriggerErrors.ts +120 -0
  49. package/src/errors/ValidationErrors.ts +99 -0
  50. package/src/errors/index.ts +41 -0
  51. package/src/experimental/index.ts +28 -0
  52. package/src/index.ts +64 -0
  53. package/src/lib/toolRouterConstants.ts +1 -0
  54. package/src/lib/toolRouterParams.ts +306 -0
  55. package/src/models/AuthConfigs.ts +398 -0
  56. package/src/models/AuthScheme.ts +206 -0
  57. package/src/models/ConnectedAccounts.ts +735 -0
  58. package/src/models/ConnectionRequest.ts +150 -0
  59. package/src/models/CustomTool.ts +676 -0
  60. package/src/models/Experimental.ts +202 -0
  61. package/src/models/Files.node.ts +93 -0
  62. package/src/models/Files.workerd.ts +49 -0
  63. package/src/models/MCP.ts +478 -0
  64. package/src/models/RemoteFile.ts +172 -0
  65. package/src/models/SessionContext.ts +147 -0
  66. package/src/models/Sessions.ts +21 -0
  67. package/src/models/ToolRouter.ts +391 -0
  68. package/src/models/ToolRouterSession.ts +827 -0
  69. package/src/models/ToolRouterSessionFileMount.ts +389 -0
  70. package/src/models/Toolkits.ts +412 -0
  71. package/src/models/Tools.ts +1260 -0
  72. package/src/models/Triggers.ts +1381 -0
  73. package/src/models/customToolExecution.ts +118 -0
  74. package/src/models/inlineCustomToolsPayload.ts +17 -0
  75. package/src/models/proxyParamsTransform.ts +26 -0
  76. package/src/provider/BaseProvider.ts +138 -0
  77. package/src/provider/ComposioProvider.ts +29 -0
  78. package/src/provider/OpenAIProvider.ts +547 -0
  79. package/src/services/internal/InternalService.ts +50 -0
  80. package/src/services/internal/InternalService.types.ts +14 -0
  81. package/src/services/pusher/Pusher.ts +230 -0
  82. package/src/services/telemetry/TelemetryService.ts +48 -0
  83. package/src/services/telemetry/TelemetryService.types.ts +67 -0
  84. package/src/telemetry/BatchProcessor.ts +77 -0
  85. package/src/telemetry/README.md +123 -0
  86. package/src/telemetry/Telemetry.ts +356 -0
  87. package/src/types/ToolRouterSessionFilesMount.types.ts +96 -0
  88. package/src/types/authConfigs.types.ts +174 -0
  89. package/src/types/composio.types.ts +1 -0
  90. package/src/types/connectedAccountAuthStates.types.ts +852 -0
  91. package/src/types/connectedAccounts.types.ts +395 -0
  92. package/src/types/connectionRequest.types.ts +16 -0
  93. package/src/types/customTool.types.ts +261 -0
  94. package/src/types/files.types.ts +15 -0
  95. package/src/types/mcp.experimental.types.ts +163 -0
  96. package/src/types/mcp.types.ts +362 -0
  97. package/src/types/modifiers.types.ts +663 -0
  98. package/src/types/org.types.ts +0 -0
  99. package/src/types/provider.types.ts +41 -0
  100. package/src/types/pusher.types.ts +18 -0
  101. package/src/types/requestOptions.types.ts +62 -0
  102. package/src/types/telemetry.types.ts +89 -0
  103. package/src/types/tool.types.ts +408 -0
  104. package/src/types/toolRouter.types.ts +761 -0
  105. package/src/types/toolkit.types.ts +130 -0
  106. package/src/types/triggers.types.ts +401 -0
  107. package/src/types/webhookEvents.types.ts +219 -0
  108. package/src/utils/buffer.ts +30 -0
  109. package/src/utils/cancellation.ts +22 -0
  110. package/src/utils/config-defaults/ConfigDefaults.node.ts +7 -0
  111. package/src/utils/config-defaults/ConfigDefaults.workerd.ts +10 -0
  112. package/src/utils/config-defaults/index.ts +1 -0
  113. package/src/utils/config-defaults/types.ts +14 -0
  114. package/src/utils/constants.ts +22 -0
  115. package/src/utils/crypto.ts +34 -0
  116. package/src/utils/env.ts +34 -0
  117. package/src/utils/fileDirs.ts +81 -0
  118. package/src/utils/fileUtils.node.ts +458 -0
  119. package/src/utils/json-schema.ts +1 -0
  120. package/src/utils/jsonSchema.ts +355 -0
  121. package/src/utils/logger.ts +99 -0
  122. package/src/utils/mime.ts +75 -0
  123. package/src/utils/modifiers/FileToolModifier.node.ts +477 -0
  124. package/src/utils/modifiers/FileToolModifier.utils.neutral.ts +132 -0
  125. package/src/utils/modifiers/FileToolModifier.workerd.ts +51 -0
  126. package/src/utils/pagination.ts +73 -0
  127. package/src/utils/pusher.ts +286 -0
  128. package/src/utils/schemaPropertyKeys.ts +433 -0
  129. package/src/utils/sdk.ts +110 -0
  130. package/src/utils/sensitiveFileUploadPaths.node.ts +105 -0
  131. package/src/utils/session.ts +114 -0
  132. package/src/utils/toolArguments.ts +73 -0
  133. package/src/utils/toolkitVersion.ts +26 -0
  134. package/src/utils/transform.ts +42 -0
  135. package/src/utils/transformers/authConfigs.ts +107 -0
  136. package/src/utils/transformers/connectedAccounts.ts +119 -0
  137. package/src/utils/transformers/mcp.ts +164 -0
  138. package/src/utils/transformers/toolRouterResponseTransform.ts +160 -0
  139. package/src/utils/transformers/toolkits.ts +100 -0
  140. package/src/utils/transformers/triggers.ts +118 -0
  141. package/src/utils/uploadDirAllowlist.node.ts +178 -0
  142. package/src/utils/uuid.ts +7 -0
  143. package/src/utils/version.ts +58 -0
  144. package/src/utils/zodSchema.ts +90 -0
@@ -0,0 +1,130 @@
1
+ import { z } from 'zod/v3';
2
+ import { AuthSchemeEnum } from './authConfigs.types';
3
+
4
+ /**
5
+ * Toolkit list params
6
+ */
7
+ export const ToolkitMangedByEnumSchema = z.enum(['all', 'composio', 'project']);
8
+ export const ToolkitSortByEnumSchema = z.enum(['usage', 'alphabetically']);
9
+ export const ToolkitsListParamsSchema = z.object({
10
+ category: z.string().optional(),
11
+ managedBy: ToolkitMangedByEnumSchema.optional(),
12
+ sortBy: ToolkitSortByEnumSchema.optional(),
13
+ cursor: z.string().optional(),
14
+ limit: z.number().optional(),
15
+ });
16
+
17
+ export type ToolkitMangedByEnum = z.infer<typeof ToolkitMangedByEnumSchema>;
18
+ export type ToolkitSortByEnum = z.infer<typeof ToolkitSortByEnumSchema>;
19
+ export type ToolkitListParams = z.infer<typeof ToolkitsListParamsSchema>;
20
+
21
+ /**
22
+ * Toolkits response
23
+ */
24
+ export const ToolKitMetaSchema = z.object({
25
+ categories: z
26
+ .array(
27
+ z.object({
28
+ slug: z.string(),
29
+ name: z.string(),
30
+ })
31
+ )
32
+ .optional(),
33
+ appUrl: z.string().optional(),
34
+ createdAt: z.string().optional(),
35
+ description: z.string().optional(),
36
+ logo: z.string().optional(),
37
+ toolsCount: z.number().optional(),
38
+ triggersCount: z.number().optional(),
39
+ updatedAt: z.string().optional(),
40
+ availableVersions: z.array(z.string()).optional(),
41
+ });
42
+
43
+ export const ToolKitItemSchema = z.object({
44
+ name: z.string(),
45
+ slug: z.string(),
46
+ meta: ToolKitMetaSchema,
47
+ isLocalToolkit: z.boolean(),
48
+ authSchemes: z.array(z.string()).optional(),
49
+ composioManagedAuthSchemes: z.array(z.string()).optional(),
50
+ noAuth: z.boolean().optional(),
51
+ });
52
+
53
+ export const ToolKitListResponseSchema = z.array(ToolKitItemSchema);
54
+
55
+ export type ToolKitMeta = z.infer<typeof ToolKitMetaSchema>;
56
+ export type ToolKitItem = z.infer<typeof ToolKitItemSchema>;
57
+ export type ToolKitListResponse = z.infer<typeof ToolKitListResponseSchema>;
58
+
59
+ /**
60
+ * Toolkit retrieve response
61
+ */
62
+ export const ToolkitAuthFieldSchema = z.object({
63
+ description: z.string(),
64
+ displayName: z.string(),
65
+ required: z.boolean(),
66
+ name: z.string(),
67
+ type: z.string(),
68
+ default: z.string().nullable().optional(),
69
+ });
70
+ export const ToolkitAuthConfigDetailsSchema = z.object({
71
+ name: z.string(),
72
+ mode: z.string(),
73
+ fields: z.object({
74
+ authConfigCreation: z.object({
75
+ optional: z.array(ToolkitAuthFieldSchema),
76
+ required: z.array(ToolkitAuthFieldSchema),
77
+ }),
78
+ connectedAccountInitiation: z.object({
79
+ optional: z.array(ToolkitAuthFieldSchema),
80
+ required: z.array(ToolkitAuthFieldSchema),
81
+ }),
82
+ }),
83
+ proxy: z
84
+ .object({
85
+ baseUrl: z.string().optional(),
86
+ })
87
+ .optional(),
88
+ });
89
+
90
+ export const ToolkitRetrieveResponseSchema = z.object({
91
+ name: z.string(),
92
+ slug: z.string(),
93
+ meta: ToolKitMetaSchema,
94
+ isLocalToolkit: z.boolean(),
95
+ composioManagedAuthSchemes: z.array(z.string()).optional(),
96
+ authConfigDetails: z.array(ToolkitAuthConfigDetailsSchema).optional(),
97
+ baseUrl: z.string().optional(),
98
+ getCurrentUserEndpoint: z.string().optional(),
99
+ getCurrentUserEndpointMethod: z.string().optional(),
100
+ });
101
+
102
+ export type ToolkitAuthField = z.infer<typeof ToolkitAuthFieldSchema>;
103
+ export type ToolkitAuthConfigDetails = z.infer<typeof ToolkitAuthConfigDetailsSchema>;
104
+ export type ToolkitRetrieveResponse = z.infer<typeof ToolkitRetrieveResponseSchema>;
105
+
106
+ /**
107
+ * Toolkit categories response
108
+ */
109
+ export const ToolkitCategorySchema = z.object({
110
+ id: z.string(),
111
+ name: z.string(),
112
+ });
113
+ export const ToolkitRetrieveCategoriesResponseSchema = z.object({
114
+ items: z.array(ToolkitCategorySchema),
115
+ nextCursor: z.string().nullable(),
116
+ totalPages: z.number(),
117
+ });
118
+
119
+ export type ToolkitCategory = z.infer<typeof ToolkitCategorySchema>;
120
+ export type ToolkitRetrieveCategoriesResponse = z.infer<
121
+ typeof ToolkitRetrieveCategoriesResponseSchema
122
+ >;
123
+
124
+ export const ToolkitAuthFieldsResponseSchema = z.array(
125
+ ToolkitAuthFieldSchema.extend({
126
+ required: z.boolean().optional(),
127
+ })
128
+ );
129
+
130
+ export type ToolkitAuthFieldsResponse = z.infer<typeof ToolkitAuthFieldsResponseSchema>;
@@ -0,0 +1,401 @@
1
+ import { z } from 'zod/v3';
2
+
3
+ export const TriggerStatuses = {
4
+ ENABLE: 'enable',
5
+ DISABLE: 'disable',
6
+ } as const;
7
+ export type TriggerStatusType = (typeof TriggerStatuses)[keyof typeof TriggerStatuses];
8
+ export const TriggerStatusEnum = z.enum(['enable', 'disable']);
9
+
10
+ export const TriggerSubscribeParamSchema = z.object({
11
+ toolkits: z.array(z.string()).optional(),
12
+ triggerId: z.string().optional(),
13
+ connectedAccountId: z.string().optional(),
14
+ authConfigId: z.string().optional(),
15
+ triggerSlug: z.array(z.string()).optional(),
16
+ triggerData: z.string().optional(),
17
+ userId: z.string().optional(),
18
+ });
19
+ export type TriggerSubscribeParams = z.infer<typeof TriggerSubscribeParamSchema>;
20
+
21
+ export const TriggerInstanceListActiveParamsSchema = z.object({
22
+ authConfigIds: z.array(z.string()).nullable().optional(),
23
+ connectedAccountIds: z.array(z.string()).nullable().optional(),
24
+ limit: z.number().optional(),
25
+ cursor: z.string().optional(),
26
+ showDisabled: z.boolean().nullable().optional(),
27
+ triggerIds: z.array(z.string()).nullable().optional(),
28
+ triggerNames: z.array(z.string()).nullable().optional(),
29
+ });
30
+
31
+ export type TriggerInstanceListActiveParams = z.infer<typeof TriggerInstanceListActiveParamsSchema>;
32
+
33
+ export const TriggerInstanceListActiveResponseItemSchema = z.object({
34
+ id: z.string(),
35
+ connectedAccountId: z.string(),
36
+ disabledAt: z.string().nullable(),
37
+ state: z.record(z.unknown()),
38
+ triggerConfig: z.record(z.unknown()),
39
+ triggerName: z.string(),
40
+ updatedAt: z.string(),
41
+ triggerData: z.string().optional(),
42
+ uuid: z.string().optional(),
43
+ });
44
+
45
+ export const TriggerInstanceListActiveResponseSchema = z.object({
46
+ items: z.array(TriggerInstanceListActiveResponseItemSchema),
47
+ nextCursor: z.string().nullable(),
48
+ totalPages: z.number(),
49
+ });
50
+
51
+ export type TriggerInstanceListActiveResponse = z.infer<
52
+ typeof TriggerInstanceListActiveResponseSchema
53
+ >;
54
+ export type TriggerInstanceListActiveResponseItem = z.infer<
55
+ typeof TriggerInstanceListActiveResponseItemSchema
56
+ >;
57
+
58
+ export const TriggerInstanceUpsertParamsSchema = z.object({
59
+ connectedAccountId: z.string().optional(),
60
+ triggerConfig: z.record(z.unknown()).optional(),
61
+ });
62
+
63
+ export type TriggerInstanceUpsertParams = z.infer<typeof TriggerInstanceUpsertParamsSchema>;
64
+
65
+ export const TriggerInstanceUpsertResponseSchema = z.object({
66
+ triggerId: z.string(),
67
+ });
68
+
69
+ export type TriggerInstanceUpsertResponse = z.infer<typeof TriggerInstanceUpsertResponseSchema>;
70
+
71
+ export const TriggerInstanceManageUpdateParamsSchema = z.object({
72
+ status: z.enum(['enable', 'disable']),
73
+ });
74
+
75
+ export type TriggerInstanceManageUpdateParams = z.infer<
76
+ typeof TriggerInstanceManageUpdateParamsSchema
77
+ >;
78
+
79
+ export const TriggerInstanceManageUpdateResponseSchema = z.object({
80
+ status: z.enum(['success']),
81
+ });
82
+
83
+ export type TriggerInstanceManageUpdateResponse = z.infer<
84
+ typeof TriggerInstanceManageUpdateResponseSchema
85
+ >;
86
+
87
+ export const TriggerInstanceManageDeleteResponseSchema = z.object({
88
+ triggerId: z.string(),
89
+ });
90
+
91
+ export type TriggerInstanceManageDeleteResponse = z.infer<
92
+ typeof TriggerInstanceManageDeleteResponseSchema
93
+ >;
94
+
95
+ export const IncomingTriggerPayloadSchema = z.object({
96
+ id: z.string().describe('The ID of the trigger'),
97
+ uuid: z.string().describe('The UUID of the trigger'),
98
+ triggerSlug: z.string().describe('The slug of the trigger that triggered the event'),
99
+ toolkitSlug: z.string().describe('The slug of the toolkit that triggered the event'),
100
+ userId: z.string().describe('The ID of the user that triggered the event'),
101
+ payload: z.record(z.unknown()).describe('The payload of the trigger').optional(),
102
+ originalPayload: z.record(z.unknown()).describe('The original payload of the trigger').optional(),
103
+ metadata: z.object({
104
+ id: z.string(),
105
+ uuid: z.string(),
106
+ toolkitSlug: z.string(),
107
+ triggerSlug: z.string(),
108
+ triggerData: z.string().optional(),
109
+ triggerConfig: z.record(z.unknown()),
110
+ connectedAccount: z.object({
111
+ id: z.string(),
112
+ uuid: z.string(),
113
+ authConfigId: z.string(),
114
+ authConfigUUID: z.string(),
115
+ userId: z.string(),
116
+ status: z.enum(['ACTIVE', 'INACTIVE']),
117
+ }),
118
+ }),
119
+ });
120
+
121
+ export type IncomingTriggerPayload = z.infer<typeof IncomingTriggerPayloadSchema>;
122
+
123
+ export type TriggerData = {
124
+ appName: string;
125
+ clientId: number;
126
+ payload: Record<string, unknown>;
127
+ originalPayload: Record<string, unknown>;
128
+ metadata: {
129
+ id: string;
130
+ nanoId: string;
131
+ triggerName: string;
132
+ triggerData: string;
133
+ triggerConfig: Record<string, unknown>;
134
+ connection: {
135
+ id: string;
136
+ connectedAccountNanoId: string;
137
+ integrationId: string;
138
+ authConfigNanoId: string;
139
+ clientUniqueUserId: string;
140
+ status: string;
141
+ };
142
+ };
143
+ };
144
+
145
+ export const TriggersTypeListParamsSchema = z.object({
146
+ cursor: z.string().optional(),
147
+ limit: z.number().nullish(),
148
+ toolkits: z.array(z.string()).nullish(),
149
+ });
150
+ export type TriggersTypeListParams = z.infer<typeof TriggersTypeListParamsSchema>;
151
+
152
+ export const TriggerTypeSchema = z.object({
153
+ slug: z.string(),
154
+ name: z.string(),
155
+ description: z.string(),
156
+ instructions: z.string().optional(),
157
+ toolkit: z.object({
158
+ logo: z.string(),
159
+ slug: z.string(),
160
+ name: z.string(),
161
+ }),
162
+ payload: z.record(z.unknown()),
163
+ config: z.record(z.unknown()),
164
+ version: z.string().optional(),
165
+ });
166
+
167
+ export type TriggerType = z.infer<typeof TriggerTypeSchema>;
168
+
169
+ export const TriggersTypeListResponseSchema = z.object({
170
+ items: z.array(TriggerTypeSchema),
171
+ nextCursor: z.string().nullish(),
172
+ totalPages: z.number(),
173
+ });
174
+
175
+ export type TriggersTypeListResponse = z.infer<typeof TriggersTypeListResponseSchema>;
176
+ export type TriggersTypeRetrieveResponse = z.infer<typeof TriggerTypeSchema>;
177
+
178
+ /**
179
+ * Generic trigger event type that can be used with generated trigger payload types
180
+ * @template TPayload - The specific trigger payload type (e.g., GITHUB_COMMIT_EVENT_PAYLOAD)
181
+ */
182
+ export interface TriggerEvent<TPayload = unknown> {
183
+ type: string;
184
+ timestamp: string;
185
+ data: TriggerEventData<TPayload>;
186
+ }
187
+
188
+ /**
189
+ * Generic trigger event data type that contains the payload and metadata
190
+ * @template TPayload - The specific trigger payload type
191
+ */
192
+ export type TriggerEventData<TPayload = unknown> = TPayload & {
193
+ connection_nano_id: string;
194
+ trigger_nano_id: string;
195
+ user_id: string;
196
+ };
197
+
198
+ /**
199
+ * Webhook payload schemas for V1, V2, V3 versions
200
+ * These schemas represent the raw payload structure sent by Composio's webhook system
201
+ */
202
+
203
+ /** V1 webhook payload - legacy format */
204
+ export const WebhookPayloadV1Schema = z.object({
205
+ trigger_name: z.string(),
206
+ connection_id: z.string(),
207
+ trigger_id: z.string(),
208
+ payload: z.record(z.unknown()),
209
+ log_id: z.string(),
210
+ });
211
+ export type WebhookPayloadV1 = z.infer<typeof WebhookPayloadV1Schema>;
212
+
213
+ /** V2 webhook payload - includes timestamp and nested data */
214
+ export const WebhookPayloadV2Schema = z.object({
215
+ type: z.string(),
216
+ timestamp: z.string(),
217
+ log_id: z.string(),
218
+ data: z
219
+ .object({
220
+ connection_id: z.string(),
221
+ connection_nano_id: z.string(),
222
+ trigger_nano_id: z.string(),
223
+ trigger_id: z.string(),
224
+ user_id: z.string(),
225
+ })
226
+ .passthrough(),
227
+ });
228
+ export type WebhookPayloadV2 = z.infer<typeof WebhookPayloadV2Schema>;
229
+
230
+ /** V3 webhook payload - generic envelope for all composio.* events */
231
+ export const WebhookPayloadV3Schema = z.object({
232
+ id: z.string(),
233
+ timestamp: z.string(),
234
+ type: z.string().refine(val => val.startsWith('composio.'), {
235
+ message: "V3 event type must start with 'composio.'",
236
+ }),
237
+ metadata: z.record(z.unknown()),
238
+ data: z.record(z.unknown()),
239
+ });
240
+ export type WebhookPayloadV3 = z.infer<typeof WebhookPayloadV3Schema>;
241
+
242
+ /** V3 trigger-specific payload - has trigger metadata fields */
243
+ export const WebhookTriggerPayloadV3Schema = z.object({
244
+ id: z.string(),
245
+ timestamp: z.string(),
246
+ type: z.string(),
247
+ metadata: z
248
+ .object({
249
+ log_id: z.string(),
250
+ trigger_slug: z.string(),
251
+ trigger_id: z.string(),
252
+ connected_account_id: z.string(),
253
+ auth_config_id: z.string(),
254
+ user_id: z.string(),
255
+ })
256
+ .passthrough(),
257
+ data: z.record(z.unknown()),
258
+ });
259
+ export type WebhookTriggerPayloadV3 = z.infer<typeof WebhookTriggerPayloadV3Schema>;
260
+
261
+ /** Union of all webhook payload versions */
262
+ export const WebhookPayloadSchema = z.union([
263
+ WebhookPayloadV3Schema,
264
+ WebhookPayloadV2Schema,
265
+ WebhookPayloadV1Schema,
266
+ ]);
267
+ export type WebhookPayload = z.infer<typeof WebhookPayloadSchema>;
268
+
269
+ /** Webhook version enum */
270
+ export const WebhookVersions = {
271
+ V1: 'V1',
272
+ V2: 'V2',
273
+ V3: 'V3',
274
+ } as const;
275
+ export type WebhookVersion = (typeof WebhookVersions)[keyof typeof WebhookVersions];
276
+
277
+ export const DefaultWebhookSubscriptionEvents = ['composio.trigger.message'] as const;
278
+
279
+ export const SetWebhookSubscriptionParamsSchema = z.object({
280
+ /** HTTPS URL to receive webhook events. */
281
+ webhookUrl: z.string().min(1),
282
+ /** Event types to subscribe to. Defaults to trigger messages. */
283
+ enabledEvents: z.array(z.string()).min(1).optional(),
284
+ /** Webhook payload version. Defaults to V3. */
285
+ version: z.enum(['V1', 'V2', 'V3']).optional(),
286
+ });
287
+
288
+ export type SetWebhookSubscriptionParams = z.infer<typeof SetWebhookSubscriptionParamsSchema>;
289
+
290
+ export type WebhookSubscription = {
291
+ id: string;
292
+ webhookUrl: string;
293
+ version: WebhookVersion;
294
+ enabledEvents: string[];
295
+ secret?: string;
296
+ createdAt?: string;
297
+ updatedAt?: string;
298
+ };
299
+
300
+ /**
301
+ * Parameters for verifying a webhook signature
302
+ */
303
+ export const VerifyWebhookParamsSchema = z.object({
304
+ /**
305
+ * The webhook message ID from the 'webhook-id' header.
306
+ * Format: 'msg_xxx'
307
+ */
308
+ id: z.string({
309
+ required_error: "Missing 'id' parameter. Pass the value of the 'webhook-id' HTTP header.",
310
+ invalid_type_error: "Invalid 'id' parameter. Expected string from 'webhook-id' HTTP header.",
311
+ }),
312
+ /** The raw webhook payload as a string (request body) */
313
+ payload: z.string({
314
+ required_error:
315
+ "Missing 'payload' parameter. Pass the raw request body as a string (do not parse it).",
316
+ invalid_type_error: "Invalid 'payload' parameter. Expected string (raw request body).",
317
+ }),
318
+ /** The webhook secret used to sign the payload (from Composio dashboard) */
319
+ secret: z.string({
320
+ required_error:
321
+ "Missing 'secret' parameter. Get your webhook secret from the Composio dashboard.",
322
+ invalid_type_error: "Invalid 'secret' parameter. Expected string.",
323
+ }),
324
+ /**
325
+ * The signature from the 'webhook-signature' header.
326
+ * Format: 'v1,base64EncodedSignature'
327
+ */
328
+ signature: z.string({
329
+ required_error:
330
+ "Missing 'signature' parameter. Pass the value of the 'webhook-signature' HTTP header.",
331
+ invalid_type_error:
332
+ "Invalid 'signature' parameter. Expected string from 'webhook-signature' HTTP header.",
333
+ }),
334
+ /**
335
+ * The webhook timestamp from the 'webhook-timestamp' header.
336
+ * This is the Unix timestamp in seconds when the webhook was sent.
337
+ */
338
+ timestamp: z.string({
339
+ required_error:
340
+ "Missing 'timestamp' parameter. Pass the value of the 'webhook-timestamp' HTTP header.",
341
+ invalid_type_error:
342
+ "Invalid 'timestamp' parameter. Expected string from 'webhook-timestamp' HTTP header.",
343
+ }),
344
+ /**
345
+ * Maximum allowed age of the webhook in seconds.
346
+ * If the webhook timestamp is older than this, verification will fail.
347
+ * Set to 0 to disable timestamp validation.
348
+ * @default 300 (5 minutes)
349
+ */
350
+ tolerance: z.number().optional().default(300),
351
+ });
352
+
353
+ export type VerifyWebhookParams = z.input<typeof VerifyWebhookParamsSchema>;
354
+
355
+ /**
356
+ * An incoming HTTP request that carries a Composio webhook.
357
+ *
358
+ * Accepts either:
359
+ * - A Fetch API `Request` (Next.js App Router, Hono, Remix, Cloudflare Workers).
360
+ * - A plain object `{ body, headers }` (Express with `express.raw`, Next.js
361
+ * Pages Router `req`). `body` may be a string, a Buffer/Uint8Array, or an
362
+ * already-parsed object; `headers` may be a `Headers` instance or a plain
363
+ * record of `string | string[] | undefined`.
364
+ */
365
+ export type WebhookRequestLike =
366
+ | Request
367
+ | {
368
+ body: unknown;
369
+ headers: unknown;
370
+ };
371
+
372
+ /**
373
+ * Options for {@link Triggers.parse}.
374
+ */
375
+ export type ParseWebhookOptions = {
376
+ /**
377
+ * The webhook secret used to sign the payload (from the Composio dashboard).
378
+ * When provided, the request signature is verified before the payload is
379
+ * returned. When omitted, the payload is parsed without verification.
380
+ */
381
+ verifySecret?: string;
382
+ /**
383
+ * Maximum allowed age of the webhook in seconds (default: 300 = 5 minutes).
384
+ * Only used when `verifySecret` is provided. Set to 0 to disable timestamp
385
+ * validation.
386
+ */
387
+ tolerance?: number;
388
+ };
389
+
390
+ /**
391
+ * Result of a successful webhook verification.
392
+ * Contains the parsed payload along with version information.
393
+ */
394
+ export type VerifyWebhookResult = {
395
+ /** The webhook version (V1, V2, or V3), from 'x-composio-webhook-version' */
396
+ version: WebhookVersion;
397
+ /** The parsed and normalized webhook payload */
398
+ payload: IncomingTriggerPayload;
399
+ /** The raw parsed payload before normalization */
400
+ rawPayload: WebhookPayload;
401
+ };