@composio/core 0.12.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{BaseProvider-BBnsv9kS.d.mts → BaseProvider-Brb3o86-.d.mts} +80 -80
- package/dist/{CustomTool-DEB4BQPl.mjs → CustomTool-D9qwyMrv.mjs} +1 -1
- package/dist/{CustomTool-DH18rVQu.d.mts → CustomTool-DLf7JeKt.d.mts} +1 -1
- package/dist/CustomTool-NpHpqdnU.d.mts +74 -0
- package/dist/{composio-CHnEggnv.d.mts → composio-BHSQwOUz.d.mts} +503 -319
- package/dist/composio-DfPD7BAi.d.mts +5666 -0
- package/dist/{customTool.types-DpIdOJjL.d.mts → customTool.types-9yFqPjdw.d.mts} +448 -76
- package/dist/customTool.types-D-6YqFdW.d.mts +2826 -0
- 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 +252 -0
- package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +155 -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/{errors-D5f4pfvI.mjs → errors-DSIlYfl5.mjs} +2 -2
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/index.d.mts +36 -6
- package/dist/index.mjs +455 -123
- package/dist/{jsonSchema-daqF3S3d.mjs → jsonSchema-CFKdONpP.mjs} +1 -1
- package/dist/{types-CaI5Z4PA.d.mts → types-BJLCRj9q.d.mts} +2 -2
- package/dist/types-CCh8qvui.d.mts +12 -0
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.node.mjs +2 -2
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
- package/docs/error-consistency.md +97 -0
- package/package.json +4 -3
- 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/lib/toolRouterSessionDelete.ts +30 -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 +406 -0
- package/src/models/ToolRouterSession.ts +839 -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/src/types/files.types.ts +15 -0
- 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 +774 -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
|
@@ -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
|
+
};
|