@composio/core 0.18.1 → 0.20.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 (100) hide show
  1. package/dist/{CustomTool-VRfWzMix.d.mts → CustomTool-B3m-188G.d.mts} +1 -1
  2. package/dist/{CustomTool-Bz0f52QR.mjs → CustomTool-fYEFjSLM.mjs} +1 -1
  3. package/dist/{FileModifierErrors-CwB-Inm9.mjs → FileModifierErrors-CdGSABoq.mjs} +1 -1
  4. package/dist/{FileToolModifier.utils.neutral-D_YkHwZP.mjs → FileToolModifier.utils.neutral-DWFpnsj2.mjs} +4 -2
  5. package/dist/{SsrfErrors-xhdVE4yw.mjs → SsrfErrors-DiQldIdC.mjs} +32 -17
  6. package/dist/{Telemetry-Dw9W5RSp.mjs → Telemetry-JRJJYS4I.mjs} +2 -2
  7. package/dist/{cancellation-P5YUlcfz.mjs → cancellation-Dwa9lGHA.mjs} +7 -5
  8. package/dist/{composio-Cb3d1jFe.d.mts → composio-B36OXii1.d.mts} +3017 -144
  9. package/dist/{customTool.types-B6ej_8XZ.d.mts → customTool.types-C436M_D0.d.mts} +525 -101
  10. package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +10 -10
  11. package/dist/docs/reference/sdk-reference/typescript/composio.mdx +8 -15
  12. package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +101 -18
  13. package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +123 -0
  14. package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +9 -2
  15. package/dist/docs/reference/sdk-reference/typescript/index.mdx +7 -0
  16. package/dist/docs/reference/sdk-reference/typescript/keyring.mdx +56 -0
  17. package/dist/docs/reference/sdk-reference/typescript/logs.mdx +78 -0
  18. package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +15 -15
  19. package/dist/docs/reference/sdk-reference/typescript/meta.json +8 -1
  20. package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +10 -10
  21. package/dist/docs/reference/sdk-reference/typescript/session.mdx +117 -24
  22. package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +24 -10
  23. package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +151 -14
  24. package/dist/docs/reference/sdk-reference/typescript/tools.mdx +50 -40
  25. package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +26 -25
  26. package/dist/docs/reference/sdk-reference/typescript/usage.mdx +78 -0
  27. package/dist/docs/reference/sdk-reference/typescript/webhook-endpoints.mdx +162 -0
  28. package/dist/docs/reference/sdk-reference/typescript/webhook-subscriptions.mdx +218 -0
  29. package/dist/docs/reference/sdk-reference/typescript/webhooks.mdx +20 -0
  30. package/dist/{errors-Ue9wMrPK.mjs → errors-D_A4b2c2.mjs} +143 -4
  31. package/dist/experimental/index.d.mts +2 -2
  32. package/dist/experimental/index.mjs +1 -1
  33. package/dist/{fileUtils.node-KE5Fa-af.mjs → fileUtils.node-DNLhLg0W.mjs} +8 -6
  34. package/dist/index.d.mts +418 -146
  35. package/dist/index.mjs +2728 -349
  36. package/dist/models/Files.node.d.mts +2 -3
  37. package/dist/models/Files.node.mjs +2 -2
  38. package/dist/models/Files.workerd.d.mts +2 -3
  39. package/dist/platform/node.d.mts +2 -3
  40. package/dist/platform/workerd.d.mts +2 -3
  41. package/dist/{sensitiveFileUploadPaths-QN7w4n8v.mjs → sensitiveFileUploadPaths-BlLp-Yo2.mjs} +10 -7
  42. package/dist/{ssrfGuard.node-BLX6b-Rf.mjs → ssrfGuard.node-BZ270bcu.mjs} +104 -14
  43. package/dist/{types-CGdgK442.d.mts → types-Br3GBya5.d.mts} +2 -2
  44. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +3 -4
  45. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +3 -4
  46. package/dist/utils/modifiers/FileToolModifier.node.d.mts +3 -4
  47. package/dist/utils/modifiers/FileToolModifier.node.mjs +6 -6
  48. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +3 -4
  49. package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
  50. package/dist/utils/ssrfGuard.node.d.mts +19 -10
  51. package/dist/utils/ssrfGuard.node.mjs +1 -1
  52. package/dist/utils/ssrfGuard.workerd.d.mts +12 -4
  53. package/dist/utils/ssrfGuard.workerd.mjs +2 -2
  54. package/package.json +9 -9
  55. package/src/composio.ts +207 -10
  56. package/src/errors/ConnectedAccountsErrors.ts +47 -0
  57. package/src/errors/SDKErrors.ts +52 -0
  58. package/src/errors/ToolErrors.ts +24 -0
  59. package/src/errors/ToolRouterErrors.ts +57 -0
  60. package/src/errors/index.ts +3 -0
  61. package/src/index.ts +15 -0
  62. package/src/lib/toolRouterMcp.ts +132 -0
  63. package/src/lib/toolRouterParams.ts +116 -29
  64. package/src/models/ConnectedAccounts.ts +118 -2
  65. package/src/models/CustomToolkits.ts +169 -0
  66. package/src/models/Experimental.ts +27 -0
  67. package/src/models/Keyring.ts +65 -0
  68. package/src/models/Logs.ts +101 -0
  69. package/src/models/MCP.ts +29 -15
  70. package/src/models/ToolRouter.ts +43 -14
  71. package/src/models/ToolRouterSession.ts +224 -16
  72. package/src/models/Toolkits.ts +181 -2
  73. package/src/models/Tools.ts +58 -26
  74. package/src/models/Triggers.ts +10 -90
  75. package/src/models/Usage.ts +119 -0
  76. package/src/models/Webhooks.ts +520 -0
  77. package/src/services/pusher/Pusher.ts +46 -16
  78. package/src/types/authConfigs.types.ts +2 -0
  79. package/src/types/connectedAccounts.types.ts +54 -0
  80. package/src/types/customToolkits.types.ts +102 -0
  81. package/src/types/keyring.types.ts +32 -0
  82. package/src/types/logs.types.ts +108 -0
  83. package/src/types/toolRouter.types.ts +259 -14
  84. package/src/types/toolkit.types.ts +161 -0
  85. package/src/types/usage.types.ts +81 -0
  86. package/src/types/webhooks.types.ts +143 -0
  87. package/src/utils/constants.ts +1 -5
  88. package/src/utils/jsonSchema.ts +4 -1
  89. package/src/utils/logger.ts +39 -7
  90. package/src/utils/sdk.ts +385 -22
  91. package/src/utils/ssrfGuard.node.ts +127 -13
  92. package/src/utils/ssrfGuard.workerd.ts +11 -1
  93. package/src/utils/transformers/connectedAccounts.ts +37 -2
  94. package/src/utils/transformers/customToolkits.ts +98 -0
  95. package/src/utils/transformers/keyring.ts +24 -0
  96. package/src/utils/transformers/logs.ts +85 -0
  97. package/src/utils/transformers/toolkits.ts +183 -3
  98. package/src/utils/transformers/triggers.ts +2 -2
  99. package/src/utils/transformers/usage.ts +77 -0
  100. package/src/utils/transformers/webhooks.ts +139 -0
@@ -18,6 +18,14 @@ export type ToolkitMangedByEnum = z.infer<typeof ToolkitMangedByEnumSchema>;
18
18
  export type ToolkitSortByEnum = z.infer<typeof ToolkitSortByEnumSchema>;
19
19
  export type ToolkitListParams = z.infer<typeof ToolkitsListParamsSchema>;
20
20
 
21
+ /**
22
+ * Toolkit getMany params — the slugs to fetch plus the same filters `list`
23
+ * accepts.
24
+ */
25
+ export const ToolkitGetManySlugsSchema = z.array(z.string().min(1)).min(1);
26
+ export const ToolkitsGetManyParamsSchema = ToolkitsListParamsSchema;
27
+ export type ToolkitGetManyParams = z.infer<typeof ToolkitsGetManyParamsSchema>;
28
+
21
29
  /**
22
30
  * Toolkits response
23
31
  */
@@ -66,10 +74,40 @@ export const ToolkitAuthFieldSchema = z.object({
66
74
  name: z.string(),
67
75
  type: z.string(),
68
76
  default: z.string().nullable().optional(),
77
+ /**
78
+ * Whether this field holds a secret/credential value. Clients use it to
79
+ * decide whether to mask the input when collecting the value in their own
80
+ * UI. The property is absent when the API omits the flag for the field.
81
+ */
82
+ isSecret: z.boolean().optional(),
83
+ /**
84
+ * The legacy template name the API reports for this field, mapped from
85
+ * `legacy_template_name`. The API declares it as an optional string without
86
+ * further documenting its semantics.
87
+ */
88
+ legacyTemplateName: z.string().optional(),
89
+ /**
90
+ * Whether the hosted connect flow shows this field to the end user, mapped
91
+ * from `user_visible`. A field with `false` is never required: its `default`
92
+ * applies unless the auth config supplies a value. Absent when the API omits
93
+ * the flag.
94
+ */
95
+ userVisible: z.boolean().optional(),
69
96
  });
70
97
  export const ToolkitAuthConfigDetailsSchema = z.object({
71
98
  name: z.string(),
72
99
  mode: z.string(),
100
+ /**
101
+ * URL to a page where users can obtain or configure credentials for this
102
+ * authentication method, e.g. `https://github.com/settings/tokens`.
103
+ */
104
+ authHintUrl: z.string().nullable().optional(),
105
+ /**
106
+ * OAuth scopes always requested for this auth method regardless of the
107
+ * tool-specific scopes, such as token refresh (`offline_access`) and identity
108
+ * scopes. Mapped from `required_scopes`; absent when the API omits it.
109
+ */
110
+ requiredScopes: z.array(z.string()).optional(),
73
111
  fields: z.object({
74
112
  authConfigCreation: z.object({
75
113
  optional: z.array(ToolkitAuthFieldSchema),
@@ -121,6 +159,129 @@ export type ToolkitRetrieveCategoriesResponse = z.infer<
121
159
  typeof ToolkitRetrieveCategoriesResponseSchema
122
160
  >;
123
161
 
162
+ /**
163
+ * Toolkit changelog response
164
+ */
165
+ export const ToolkitVersionChangelogSchema = z.object({
166
+ version: z.string(),
167
+ changelog: z.string(),
168
+ });
169
+ export const ToolkitChangelogItemSchema = z.object({
170
+ slug: z.string(),
171
+ name: z.string(),
172
+ displayName: z.string(),
173
+ /** Most recent versions first; the API returns up to the last 10 per toolkit. */
174
+ versions: z.array(ToolkitVersionChangelogSchema),
175
+ });
176
+ export const ToolkitChangelogResponseSchema = z.object({
177
+ items: z.array(ToolkitChangelogItemSchema),
178
+ });
179
+
180
+ export type ToolkitVersionChangelog = z.infer<typeof ToolkitVersionChangelogSchema>;
181
+ export type ToolkitChangelogItem = z.infer<typeof ToolkitChangelogItemSchema>;
182
+ export type ToolkitChangelogResponse = z.infer<typeof ToolkitChangelogResponseSchema>;
183
+
184
+ /**
185
+ * Params for `composio.toolkits.recommendScopes()`.
186
+ * **Experimental — shape may change in future releases.**
187
+ */
188
+ export const ToolkitRecommendScopesParamsSchema = z.object({
189
+ /** Tool slugs to cover. Pass `[]` to cover every tool in the toolkit. */
190
+ tools: z.array(z.string()),
191
+ /** Auth scheme the connection will use. The API defaults to `OAUTH2`. */
192
+ authScheme: AuthSchemeEnum.optional(),
193
+ /** Toolkit version to compute from. The API defaults to the latest published version. */
194
+ toolkitVersion: z.string().min(1).optional(),
195
+ /**
196
+ * Context the scopes will be granted in, as dimension → selected value,
197
+ * for example `{ account_type: 'Google Workspace' }`. Discover the
198
+ * dimensions with `composio.toolkits.listGrantContexts()`.
199
+ */
200
+ grantContext: z.record(z.string(), z.string()).optional(),
201
+ /** Scopes the recommendation must include, whether or not the tools need them. */
202
+ include: z.array(z.string()).optional(),
203
+ /** Scopes the recommendation must not include; the API picks documented alternatives or fails. */
204
+ exclude: z.array(z.string()).optional(),
205
+ /** Scopes your OAuth app can request. The recommendation never goes outside this list. */
206
+ availableScopes: z.array(z.string()).optional(),
207
+ });
208
+ export type ToolkitRecommendScopesParams = z.infer<typeof ToolkitRecommendScopesParamsSchema>;
209
+
210
+ export const ToolkitConditionalScopeSchema = z.object({
211
+ /** The scope needed only when the `when` guard matches. */
212
+ scope: z.string(),
213
+ /** Input field name → qualifying values. Any value matches within a field; all fields must match. */
214
+ when: z.record(z.string(), z.array(z.string())),
215
+ /** Tool slugs that need this scope under the guard. */
216
+ for: z.array(z.string()),
217
+ });
218
+ export type ToolkitConditionalScope = z.infer<typeof ToolkitConditionalScopeSchema>;
219
+
220
+ /**
221
+ * Response of `composio.toolkits.recommendScopes()`.
222
+ * **Experimental — shape may change in future releases.**
223
+ */
224
+ export const ToolkitRecommendScopesResponseSchema = z.object({
225
+ /** Auth scheme the recommendation was computed under. */
226
+ authScheme: z.string(),
227
+ /** Concrete toolkit version the answer was computed from; pass it back as `toolkitVersion` to pin. */
228
+ toolkitVersion: z.string(),
229
+ /** The effective grant context: the toolkit default overlaid with your overrides. */
230
+ grantContext: z.record(z.string(), z.string()),
231
+ scopes: z.object({
232
+ /** Narrowest documented option per requirement. */
233
+ leastPrivilege: z.array(z.string()),
234
+ /** Smallest scope set covering all requirements. */
235
+ fewest: z.array(z.string()),
236
+ /**
237
+ * Scopes needed only for particular call-time inputs. Both lists above
238
+ * already include them, so a caller that knows its inputs may drop the rest.
239
+ */
240
+ conditional: z.array(ToolkitConditionalScopeSchema),
241
+ }),
242
+ });
243
+ export type ToolkitRecommendScopesResponse = z.infer<typeof ToolkitRecommendScopesResponseSchema>;
244
+
245
+ /**
246
+ * Params for `composio.toolkits.listGrantContexts()`.
247
+ * **Experimental — shape may change in future releases.**
248
+ */
249
+ export const ToolkitListGrantContextsParamsSchema = z.object({
250
+ /** Auth scheme the connection will use. The API defaults to `OAUTH2`. */
251
+ authScheme: AuthSchemeEnum.optional(),
252
+ /** Toolkit version to read the scope catalog from. The API defaults to the latest published version. */
253
+ toolkitVersion: z.string().min(1).optional(),
254
+ });
255
+ export type ToolkitListGrantContextsParams = z.infer<typeof ToolkitListGrantContextsParamsSchema>;
256
+
257
+ export const ToolkitGrantContextDimensionSchema = z.object({
258
+ /** Dimension name to use as a `grantContext` key. */
259
+ dimension: z.string(),
260
+ /** What the dimension means and when to pass it. */
261
+ description: z.string(),
262
+ /** Values the dimension can take. */
263
+ values: z.array(z.string()),
264
+ });
265
+ export type ToolkitGrantContextDimension = z.infer<typeof ToolkitGrantContextDimensionSchema>;
266
+
267
+ /**
268
+ * Response of `composio.toolkits.listGrantContexts()`.
269
+ * **Experimental — shape may change in future releases.**
270
+ */
271
+ export const ToolkitListGrantContextsResponseSchema = z.object({
272
+ /** Auth scheme whose scope catalog the dimensions were read from. */
273
+ authScheme: z.string(),
274
+ /** Concrete toolkit version the answer was computed from. */
275
+ toolkitVersion: z.string(),
276
+ /** Dimensions the toolkit accepts in `grantContext`; empty when no scope depends on one. */
277
+ grantContextDimensions: z.array(ToolkitGrantContextDimensionSchema),
278
+ /** The grant context assumed when you pass none. */
279
+ defaultGrantContext: z.record(z.string(), z.string()),
280
+ });
281
+ export type ToolkitListGrantContextsResponse = z.infer<
282
+ typeof ToolkitListGrantContextsResponseSchema
283
+ >;
284
+
124
285
  export const ToolkitAuthFieldsResponseSchema = z.array(
125
286
  ToolkitAuthFieldSchema.extend({
126
287
  required: z.boolean().optional(),
@@ -0,0 +1,81 @@
1
+ import { z } from 'zod/v3';
2
+
3
+ /**
4
+ * Filters shared by the usage summary and breakdown queries.
5
+ * **Experimental — shape may change in future releases.**
6
+ */
7
+ export const UsageFiltersSchema = z.object({
8
+ /** Only count events for these external end-user IDs (OR logic). */
9
+ userId: z.array(z.string()).nullable().optional(),
10
+ /** Only count events for these session IDs (OR logic). */
11
+ sessionId: z.array(z.string()).nullable().optional(),
12
+ });
13
+ export type UsageFilters = z.infer<typeof UsageFiltersSchema>;
14
+
15
+ /**
16
+ * Params for `composio.experimental.usage.summary()`.
17
+ * **Experimental — shape may change in future releases.**
18
+ */
19
+ export const UsageSummaryParamsSchema = z.object({
20
+ /** Inclusive range start (Unix epoch milliseconds). Defaults to 30 days before `to`. */
21
+ from: z.number().optional(),
22
+ /** Exclusive range end (Unix epoch milliseconds). Defaults to now. */
23
+ to: z.number().optional(),
24
+ /** Restrict to these metering entity types. Omit for all types. */
25
+ entityTypes: z.array(z.string()).optional(),
26
+ filters: UsageFiltersSchema.optional(),
27
+ });
28
+ export type UsageSummaryParams = z.infer<typeof UsageSummaryParamsSchema>;
29
+
30
+ export const UsageOrderBySchema = z.enum(['key', 'total_quantity', 'event_count']);
31
+ export const UsageOrderDirectionSchema = z.enum(['asc', 'desc']);
32
+
33
+ /**
34
+ * Params for `composio.experimental.usage.breakdown()`.
35
+ * **Experimental — shape may change in future releases.**
36
+ */
37
+ export const UsageBreakdownParamsSchema = z.object({
38
+ /** Inclusive range start (Unix epoch milliseconds). Defaults to 30 days before `to`. */
39
+ from: z.number().optional(),
40
+ /** Exclusive range end (Unix epoch milliseconds). Defaults to now. */
41
+ to: z.number().optional(),
42
+ /** Dimension to group by. Defaults to `tool_slug` for tool_calls and `user_id` for sessions. */
43
+ groupBy: z.string().optional(),
44
+ /** Field to order groups by. Defaults to `total_quantity`. */
45
+ orderBy: UsageOrderBySchema.optional(),
46
+ /** Sort direction. Defaults to `desc`. */
47
+ orderDirection: UsageOrderDirectionSchema.optional(),
48
+ /** Maximum number of groups to return. Defaults to 100, max 1000. */
49
+ limit: z.number().optional(),
50
+ filters: UsageFiltersSchema.optional(),
51
+ });
52
+ export type UsageBreakdownParams = z.infer<typeof UsageBreakdownParamsSchema>;
53
+
54
+ export const UsageEntitySummarySchema = z.object({
55
+ unit: z.string(),
56
+ totalQuantity: z.string(),
57
+ eventCount: z.number(),
58
+ });
59
+ export type UsageEntitySummary = z.infer<typeof UsageEntitySummarySchema>;
60
+
61
+ export const UsageSummaryResponseSchema = z.object({
62
+ /** Aggregates keyed by metering entity type (e.g. `tool_calls`, `sessions`). */
63
+ entities: z.record(z.string(), UsageEntitySummarySchema),
64
+ });
65
+ export type UsageSummaryResponse = z.infer<typeof UsageSummaryResponseSchema>;
66
+
67
+ export const UsageBreakdownGroupSchema = z.object({
68
+ key: z.string(),
69
+ totalQuantity: z.string(),
70
+ eventCount: z.number(),
71
+ });
72
+ export type UsageBreakdownGroup = z.infer<typeof UsageBreakdownGroupSchema>;
73
+
74
+ export const UsageBreakdownResponseSchema = z.object({
75
+ entityType: z.string(),
76
+ unit: z.string(),
77
+ totalQuantity: z.string(),
78
+ eventCount: z.number(),
79
+ groups: z.array(UsageBreakdownGroupSchema),
80
+ });
81
+ export type UsageBreakdownResponse = z.infer<typeof UsageBreakdownResponseSchema>;
@@ -0,0 +1,143 @@
1
+ import { z } from 'zod/v3';
2
+ import { SetWebhookSubscriptionParamsSchema } from './triggers.types';
3
+
4
+ /**
5
+ * Webhook payload versions accepted by the webhook subscription endpoints.
6
+ */
7
+ export const WebhookVersionSchema = z.enum(['V1', 'V2', 'V3']);
8
+
9
+ // ---------------------------------------------------------------------------
10
+ // Webhook subscriptions
11
+ // ---------------------------------------------------------------------------
12
+
13
+ /**
14
+ * A project webhook subscription in the SDK's camelCase shape. The signing
15
+ * `secret` is returned by the API on every subscription read/write.
16
+ */
17
+ export const WebhookSubscriptionSchema = z.object({
18
+ id: z.string(),
19
+ webhookUrl: z.string(),
20
+ version: WebhookVersionSchema,
21
+ enabledEvents: z.array(z.string()),
22
+ secret: z.string().optional(),
23
+ createdAt: z.string().optional(),
24
+ updatedAt: z.string().optional(),
25
+ });
26
+
27
+ export const WebhookSubscriptionListParamsSchema = z.object({
28
+ /** Number of items per page, max allowed is 50. */
29
+ limit: z.number().optional(),
30
+ /** Cursor for pagination, taken from a previous response's `nextCursor`. */
31
+ cursor: z.string().optional(),
32
+ });
33
+ export type WebhookSubscriptionListParams = z.infer<typeof WebhookSubscriptionListParamsSchema>;
34
+
35
+ export const WebhookSubscriptionListResponseSchema = z.object({
36
+ items: z.array(WebhookSubscriptionSchema),
37
+ nextCursor: z.string().nullable(),
38
+ totalPages: z.number(),
39
+ currentPage: z.number(),
40
+ totalItems: z.number(),
41
+ });
42
+ export type WebhookSubscriptionListResponse = z.infer<typeof WebhookSubscriptionListResponseSchema>;
43
+
44
+ /**
45
+ * Params for `composio.webhooks.subscriptions.set()`. Identical to the
46
+ * params accepted by `composio.triggers.setWebhookSubscription()`.
47
+ */
48
+ export const WebhookSubscriptionSetParamsSchema = SetWebhookSubscriptionParamsSchema;
49
+ export type WebhookSubscriptionSetParams = z.infer<typeof WebhookSubscriptionSetParamsSchema>;
50
+
51
+ export const WebhookSubscriptionUpdateParamsSchema = z.object({
52
+ /** HTTPS URL to receive webhook events. */
53
+ webhookUrl: z.string().min(1).optional(),
54
+ /** Event types to subscribe to. */
55
+ enabledEvents: z.array(z.string()).min(1).optional(),
56
+ /** Webhook payload version. */
57
+ version: WebhookVersionSchema.optional(),
58
+ });
59
+ export type WebhookSubscriptionUpdateParams = z.infer<typeof WebhookSubscriptionUpdateParamsSchema>;
60
+
61
+ export const WebhookSubscriptionDeleteResponseSchema = z.object({
62
+ success: z.boolean(),
63
+ });
64
+ export type WebhookSubscriptionDeleteResponse = z.infer<
65
+ typeof WebhookSubscriptionDeleteResponseSchema
66
+ >;
67
+
68
+ export const WebhookSubscriptionRotateSecretResponseSchema = z.object({
69
+ id: z.string(),
70
+ /** The new signing secret. Store it — the previous secret stops validating. */
71
+ secret: z.string(),
72
+ });
73
+ export type WebhookSubscriptionRotateSecretResponse = z.infer<
74
+ typeof WebhookSubscriptionRotateSecretResponseSchema
75
+ >;
76
+
77
+ export const WebhookSubscriptionEventTypeSchema = z.object({
78
+ eventType: z.string(),
79
+ description: z.string(),
80
+ supportedVersions: z.array(WebhookVersionSchema),
81
+ });
82
+ export type WebhookSubscriptionEventType = z.infer<typeof WebhookSubscriptionEventTypeSchema>;
83
+
84
+ export const WebhookSubscriptionEventTypesResponseSchema = z.object({
85
+ items: z.array(WebhookSubscriptionEventTypeSchema),
86
+ });
87
+ export type WebhookSubscriptionEventTypesResponse = z.infer<
88
+ typeof WebhookSubscriptionEventTypesResponseSchema
89
+ >;
90
+
91
+ // ---------------------------------------------------------------------------
92
+ // Webhook endpoints (per toolkit + OAuth app inbound ingress URLs)
93
+ // ---------------------------------------------------------------------------
94
+
95
+ export const WebhookEndpointListParamsSchema = z.object({
96
+ /** Only return endpoints for this toolkit slug. */
97
+ toolkitSlug: z.string().optional(),
98
+ });
99
+ export type WebhookEndpointListParams = z.infer<typeof WebhookEndpointListParamsSchema>;
100
+
101
+ export const WebhookEndpointListItemSchema = z.object({
102
+ id: z.string(),
103
+ toolkitSlug: z.string(),
104
+ clientId: z.string().nullable(),
105
+ });
106
+ export type WebhookEndpointListItem = z.infer<typeof WebhookEndpointListItemSchema>;
107
+
108
+ export const WebhookEndpointListResponseSchema = z.object({
109
+ items: z.array(WebhookEndpointListItemSchema),
110
+ });
111
+ export type WebhookEndpointListResponse = z.infer<typeof WebhookEndpointListResponseSchema>;
112
+
113
+ export const WebhookEndpointSchema = z.object({
114
+ id: z.string(),
115
+ toolkitSlug: z.string(),
116
+ clientId: z.string().nullable(),
117
+ /** The inbound URL to register with the third-party provider. */
118
+ webhookUrl: z.string(),
119
+ /** Configured setup fields with secret values masked. */
120
+ data: z.record(z.string(), z.string()).nullable(),
121
+ createdAt: z.string(),
122
+ });
123
+ export type WebhookEndpoint = z.infer<typeof WebhookEndpointSchema>;
124
+
125
+ export const WebhookEndpointCreateParamsSchema = z.object({
126
+ /** Toolkit identifier (e.g. `slack`, `discord`). */
127
+ toolkitSlug: z.string().min(1),
128
+ /** OAuth app client ID — identifies which app this endpoint is for. */
129
+ clientId: z.string().min(1),
130
+ });
131
+ export type WebhookEndpointCreateParams = z.infer<typeof WebhookEndpointCreateParamsSchema>;
132
+
133
+ export const WebhookEndpointReplaceParamsSchema = z.object({
134
+ /** Key-value pairs for ALL required setup fields of the toolkit. */
135
+ data: z.record(z.string(), z.string()),
136
+ });
137
+ export type WebhookEndpointReplaceParams = z.infer<typeof WebhookEndpointReplaceParamsSchema>;
138
+
139
+ export const WebhookEndpointUpdateParamsSchema = z.object({
140
+ /** Key-value pairs to merge into the setup fields. Omitted fields are preserved. */
141
+ data: z.record(z.string(), z.string()),
142
+ });
143
+ export type WebhookEndpointUpdateParams = z.infer<typeof WebhookEndpointUpdateParamsSchema>;
@@ -11,11 +11,7 @@ export const TELEMETRY_URL = 'https://app.composio.dev';
11
11
  export const CLIENT_PUSHER_KEY = getEnvVariable('CLIENT_PUSHER_KEY') || 'ff9f18c208855d77a152';
12
12
 
13
13
  export const COMPOSIO_LOG_LEVEL = getEnvVariable('COMPOSIO_LOG_LEVEL') as
14
- | 'debug'
15
- | 'info'
16
- | 'warn'
17
- | 'error'
18
- | undefined;
14
+ 'silent' | 'debug' | 'info' | 'warn' | 'error' | undefined;
19
15
 
20
16
  export const IS_DEVELOPMENT_OR_CI = getEnvVariable('DEVELOPMENT') || getEnvVariable('CI') || false;
21
17
 
@@ -495,7 +495,10 @@ export function jsonSchemaToZodSchema<T extends z.ZodTypeAny>(
495
495
  const zodSchema = jsonSchemaToZod(schema) as T;
496
496
  return zodSchema;
497
497
  } catch (error) {
498
- throw new JsonSchemaToZodError('Failed to convert JSON Schema to Zod Schema', {
498
+ // The cause names the offending property path; surface it in the message
499
+ // so a single malformed property is identifiable without unwrapping.
500
+ const detail = error instanceof Error ? `: ${error.message}` : '';
501
+ throw new JsonSchemaToZodError(`Failed to convert JSON Schema to Zod Schema${detail}`, {
499
502
  cause: error,
500
503
  });
501
504
  }
@@ -23,20 +23,52 @@ export const getLogLevel = (): LogLevel => {
23
23
  return envLevel && envLevel in LOG_LEVELS ? (envLevel as LogLevel) : 'info';
24
24
  };
25
25
 
26
+ /**
27
+ * Destination for SDK log output. Each method receives the already
28
+ * formatted and redacted message as its single argument. `console` satisfies
29
+ * this interface, and so do most structured loggers (pino, winston, ...).
30
+ */
31
+ export interface ComposioLogger {
32
+ error: (...args: unknown[]) => void;
33
+ warn: (...args: unknown[]) => void;
34
+ info: (...args: unknown[]) => void;
35
+ debug: (...args: unknown[]) => void;
36
+ }
37
+
26
38
  interface LoggerOptions {
27
39
  level?: LogLevel;
28
40
  includeTimestamp?: boolean;
41
+ /** Where formatted output is written. Defaults to `console`. */
42
+ sink?: ComposioLogger;
43
+ }
44
+
45
+ export interface LoggerConfigureOptions {
46
+ level?: LogLevel;
47
+ sink?: ComposioLogger;
29
48
  }
30
49
 
31
50
  export class Logger {
32
- private readonly level: LogLevel;
51
+ private level: LogLevel;
33
52
  private readonly includeTimestamp: boolean;
34
- private readonly console: Console;
53
+ private sink: ComposioLogger;
35
54
 
36
55
  constructor(options: LoggerOptions = {}) {
37
56
  this.level = options.level ?? getLogLevel();
38
57
  this.includeTimestamp = options.includeTimestamp ?? true;
39
- this.console = console;
58
+ this.sink = options.sink ?? console;
59
+ }
60
+
61
+ /**
62
+ * Reconfigure the level and/or sink in place. Omitted fields are left
63
+ * unchanged, so `configure({ level: 'debug' })` keeps the current sink.
64
+ */
65
+ configure(options: LoggerConfigureOptions): void {
66
+ if (options.level !== undefined) this.level = options.level;
67
+ if (options.sink !== undefined) this.sink = options.sink;
68
+ }
69
+
70
+ getLevel(): LogLevel {
71
+ return this.level;
40
72
  }
41
73
 
42
74
  private formatMessage(args: unknown[]): string {
@@ -71,25 +103,25 @@ export class Logger {
71
103
 
72
104
  error(...args: unknown[]): void {
73
105
  if (this.shouldLog('error')) {
74
- this.console.error(this.formatMessage(args));
106
+ this.sink.error(this.formatMessage(args));
75
107
  }
76
108
  }
77
109
 
78
110
  warn(...args: unknown[]): void {
79
111
  if (this.shouldLog('warn')) {
80
- this.console.warn(this.formatMessage(args));
112
+ this.sink.warn(this.formatMessage(args));
81
113
  }
82
114
  }
83
115
 
84
116
  info(...args: unknown[]): void {
85
117
  if (this.shouldLog('info')) {
86
- this.console.info(this.formatMessage(args));
118
+ this.sink.info(this.formatMessage(args));
87
119
  }
88
120
  }
89
121
 
90
122
  debug(...args: unknown[]): void {
91
123
  if (this.shouldLog('debug')) {
92
- this.console.debug(this.formatMessage(args));
124
+ this.sink.debug(this.formatMessage(args));
93
125
  }
94
126
  }
95
127
  }