@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.
- package/dist/{CustomTool-9Vlb4XaS.mjs → CustomTool-B4dQn2M5.mjs} +1 -1
- package/dist/{CustomTool-Dzk3iqfP.d.mts → CustomTool-CBx9kzea.d.mts} +1 -1
- package/dist/{FileModifierErrors-WrqokuIF.mjs → FileModifierErrors-D-AKc3ds.mjs} +1 -1
- package/dist/{SsrfErrors-BSVMW915.mjs → SsrfErrors-BekZPeWY.mjs} +59 -12
- package/dist/{Telemetry-a7SOQXcg.mjs → Telemetry-BWKZmDxM.mjs} +2 -2
- package/dist/composio-CPf6NHnB.d.mts +20334 -0
- package/dist/{customTool.types-CpJbzxT6.d.mts → customTool.types-BSbIG1OG.d.mts} +306 -83
- package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +28 -11
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +28 -10
- package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +44 -32
- package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +8 -6
- package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +4 -3
- package/dist/docs/reference/sdk-reference/typescript/index.mdx +4 -2
- package/dist/docs/reference/sdk-reference/typescript/keyring.mdx +6 -3
- package/dist/docs/reference/sdk-reference/typescript/logs.mdx +5 -3
- package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +54 -43
- package/dist/docs/reference/sdk-reference/typescript/meta.json +1 -0
- package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +5 -14
- package/dist/docs/reference/sdk-reference/typescript/session-configs.mdx +5 -3
- package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +7 -5
- package/dist/docs/reference/sdk-reference/typescript/session-webhooks.mdx +64 -0
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +16 -16
- package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +36 -8
- package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +14 -11
- package/dist/docs/reference/sdk-reference/typescript/tools.mdx +18 -20
- package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +42 -30
- package/dist/docs/reference/sdk-reference/typescript/usage.mdx +6 -4
- package/dist/docs/reference/sdk-reference/typescript/webhook-endpoints.mdx +9 -7
- package/dist/docs/reference/sdk-reference/typescript/webhook-subscriptions.mdx +13 -9
- package/dist/docs/reference/sdk-reference/typescript/webhooks.mdx +3 -1
- package/dist/{errors-xC13uvaA.mjs → errors-CtIKA9BH.mjs} +2 -2
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-CAwIbWYH.mjs → fileUtils.node-BJUYMEph.mjs} +7 -7
- package/dist/index.d.mts +10 -15
- package/dist/index.mjs +582 -242
- package/dist/{jsonSchema-Cc4EtHRw.mjs → jsonSchema-BZoXGUCr.mjs} +2 -2
- package/dist/models/Files.node.mjs +3 -3
- package/dist/{sensitiveFileUploadPaths-CSyJ3Ku8.mjs → sensitiveFileUploadPaths-CcbMAYCC.mjs} +21 -15
- package/dist/{ssrfGuard.node-CdIkwqVu.mjs → ssrfGuard.node-B749ae5Q.mjs} +1 -1
- package/dist/{types-DQdUb7OG.d.mts → types-ns3Q_WrP.d.mts} +2 -2
- 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 +5 -5
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
- package/dist/utils/ssrfGuard.node.mjs +1 -1
- package/dist/utils/ssrfGuard.workerd.mjs +1 -1
- package/package.json +4 -4
- package/src/composio.ts +26 -7
- package/src/errors/ComposioError.ts +3 -2
- package/src/index.ts +19 -0
- package/src/lib/toolRouterParams.ts +38 -14
- package/src/models/AuthConfigs.ts +18 -2
- package/src/models/ConnectedAccounts.ts +30 -17
- package/src/models/CustomTool.ts +0 -10
- package/src/models/Keyring.ts +2 -1
- package/src/models/MCP.ts +44 -36
- package/src/models/SessionWebhooks.ts +136 -0
- package/src/models/ToolRouter.ts +39 -4
- package/src/models/ToolRouterSession.ts +2 -2
- package/src/models/ToolRouterSessionFileMount.ts +3 -1
- package/src/models/Toolkits.ts +1 -0
- package/src/models/Tools.ts +6 -10
- package/src/models/Triggers.ts +48 -213
- package/src/models/Webhooks.ts +2 -0
- package/src/provider/ComposioProvider.ts +0 -1
- package/src/telemetry/BatchProcessor.ts +1 -1
- package/src/telemetry/Telemetry.ts +1 -1
- package/src/types/authConfigs.types.ts +14 -0
- package/src/types/connectedAccountAuthStates.types.ts +0 -1
- package/src/types/provider.types.ts +0 -1
- package/src/types/sessionWebhooks.types.ts +292 -0
- package/src/types/tool.types.ts +1 -1
- package/src/types/toolRouter.types.ts +33 -4
- package/src/types/toolkit.types.ts +21 -0
- package/src/types/triggers.types.ts +4 -0
- package/src/utils/crypto.ts +6 -5
- package/src/utils/env.ts +2 -5
- package/src/utils/fileUtils.node.ts +4 -3
- package/src/utils/logger.ts +19 -9
- package/src/utils/pusher.ts +5 -2
- package/src/utils/readResponseBody.ts +30 -17
- package/src/utils/transformers/authConfigs.ts +6 -3
- package/src/utils/transformers/toolkits.ts +7 -0
- package/src/utils/userCallback.ts +3 -1
- package/src/utils/webhookVerification.ts +211 -0
- package/dist/composio-DaokW5sV.d.mts +0 -9593
package/src/models/Triggers.ts
CHANGED
|
@@ -42,7 +42,6 @@ import { PusherService } from '../services/pusher/Pusher';
|
|
|
42
42
|
import {
|
|
43
43
|
ComposioTriggerTypeNotFoundError,
|
|
44
44
|
ComposioWebhookPayloadError,
|
|
45
|
-
ComposioWebhookSignatureVerificationError,
|
|
46
45
|
} from '../errors/TriggerErrors';
|
|
47
46
|
import { transform } from '../utils/transform';
|
|
48
47
|
import {
|
|
@@ -54,96 +53,28 @@ import {
|
|
|
54
53
|
import { ToolkitVersionParam } from '../types/tool.types';
|
|
55
54
|
import type { ComposioConfig } from '../composio';
|
|
56
55
|
import type { BaseComposioProvider } from '../provider/BaseProvider';
|
|
57
|
-
import {
|
|
56
|
+
import {
|
|
57
|
+
WEBHOOK_HEADERS,
|
|
58
|
+
getHeader,
|
|
59
|
+
assertWebhookBodySize,
|
|
60
|
+
readWebhookRequest,
|
|
61
|
+
validateWebhookTimestamp,
|
|
62
|
+
verifyWebhookSignature,
|
|
63
|
+
} from '../utils/webhookVerification';
|
|
58
64
|
import { CONFIG_DEFAULTS } from '../utils/config-defaults';
|
|
59
65
|
import { ComposioRequestOptions } from '../types/requestOptions.types';
|
|
60
66
|
import { withCancellation } from '../utils/cancellation';
|
|
61
67
|
import { invokeUserCallback } from '../utils/userCallback';
|
|
62
68
|
|
|
63
69
|
/**
|
|
64
|
-
*
|
|
65
|
-
* This prevents runtime crashes when calling string methods like `.toLowerCase()` on non-string values.
|
|
70
|
+
* Normalizes string and numeric identifiers, falling back for empty or malformed values.
|
|
66
71
|
* @private
|
|
67
72
|
*/
|
|
68
73
|
const toStringOrDefault = (value: unknown, defaultValue: string): string => {
|
|
69
|
-
|
|
70
|
-
return defaultValue;
|
|
71
|
-
}
|
|
72
|
-
const str = String(value);
|
|
74
|
+
const str = typeof value === 'string' || typeof value === 'number' ? String(value) : '';
|
|
73
75
|
return str.length > 0 ? str : defaultValue;
|
|
74
76
|
};
|
|
75
77
|
|
|
76
|
-
/**
|
|
77
|
-
* The signature header names Composio sends with every webhook delivery.
|
|
78
|
-
* @private
|
|
79
|
-
*/
|
|
80
|
-
const WEBHOOK_HEADERS = {
|
|
81
|
-
id: 'webhook-id',
|
|
82
|
-
timestamp: 'webhook-timestamp',
|
|
83
|
-
signature: 'webhook-signature',
|
|
84
|
-
} as const;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Returns true if the value is a Fetch API `Request`.
|
|
88
|
-
* @private
|
|
89
|
-
*/
|
|
90
|
-
const isFetchRequest = (request: WebhookRequestLike): request is Request =>
|
|
91
|
-
typeof Request !== 'undefined' && request instanceof Request;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Reads a single header value case-insensitively from either a `Headers`
|
|
95
|
-
* instance or a plain record (where values may be `string | string[]`).
|
|
96
|
-
* Returns `undefined` when the header is missing.
|
|
97
|
-
* @private
|
|
98
|
-
*/
|
|
99
|
-
const getHeader = (headers: unknown, name: string): string | undefined => {
|
|
100
|
-
if (typeof Headers !== 'undefined' && headers instanceof Headers) {
|
|
101
|
-
return headers.get(name) ?? undefined;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (headers === null || typeof headers !== 'object') {
|
|
105
|
-
return undefined;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Plain record: match the header name case-insensitively.
|
|
109
|
-
const target = name.toLowerCase();
|
|
110
|
-
for (const [key, value] of Object.entries(headers as Record<string, unknown>)) {
|
|
111
|
-
if (key.toLowerCase() !== target) {
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
if (Array.isArray(value)) {
|
|
115
|
-
const first = value.find((item): item is string => typeof item === 'string');
|
|
116
|
-
return first;
|
|
117
|
-
}
|
|
118
|
-
return typeof value === 'string' ? value : undefined;
|
|
119
|
-
}
|
|
120
|
-
return undefined;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Coerces an object request body (string, Buffer/Uint8Array, or already-parsed
|
|
125
|
-
* value) into the raw string form expected by signature verification.
|
|
126
|
-
* @private
|
|
127
|
-
*/
|
|
128
|
-
const bodyToString = (body: unknown): string => {
|
|
129
|
-
if (typeof body === 'string') {
|
|
130
|
-
return body;
|
|
131
|
-
}
|
|
132
|
-
if (body instanceof Uint8Array) {
|
|
133
|
-
return new TextDecoder().decode(body);
|
|
134
|
-
}
|
|
135
|
-
if (body === null || body === undefined) {
|
|
136
|
-
return '';
|
|
137
|
-
}
|
|
138
|
-
// Already-parsed object (e.g. Next.js Pages Router with the JSON body parser).
|
|
139
|
-
// Note: re-stringifying cannot reproduce the exact bytes Composio signed, so
|
|
140
|
-
// signature verification on a pre-parsed body is best-effort only.
|
|
141
|
-
if (typeof body === 'object') {
|
|
142
|
-
return JSON.stringify(body);
|
|
143
|
-
}
|
|
144
|
-
return String(body);
|
|
145
|
-
};
|
|
146
|
-
|
|
147
78
|
/**
|
|
148
79
|
* Trigger (Instance) class
|
|
149
80
|
* /api/v3/trigger_instances
|
|
@@ -174,6 +105,8 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
174
105
|
*
|
|
175
106
|
* @example
|
|
176
107
|
* ```ts
|
|
108
|
+
* const APP_URL = 'https://your-app.com';
|
|
109
|
+
*
|
|
177
110
|
* await composio.triggers.setWebhookSubscription({
|
|
178
111
|
* webhookUrl: `${APP_URL}/webhooks/composio`,
|
|
179
112
|
* });
|
|
@@ -194,7 +127,7 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
194
127
|
*
|
|
195
128
|
* @example
|
|
196
129
|
* ```ts
|
|
197
|
-
* const
|
|
130
|
+
* const activeTriggers = await composio.triggers.listActive({
|
|
198
131
|
* authConfigIds: ['123'],
|
|
199
132
|
* connectedAccountIds: ['456'],
|
|
200
133
|
* });
|
|
@@ -554,10 +487,9 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
554
487
|
*
|
|
555
488
|
* @example
|
|
556
489
|
* ```ts
|
|
557
|
-
*
|
|
558
|
-
* triggers.subscribe((data) => {
|
|
490
|
+
* await composio.triggers.subscribe((data) => {
|
|
559
491
|
* console.log(data);
|
|
560
|
-
* }
|
|
492
|
+
* });
|
|
561
493
|
* ```
|
|
562
494
|
*/
|
|
563
495
|
async subscribe(
|
|
@@ -724,11 +656,11 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
724
656
|
*
|
|
725
657
|
* @example
|
|
726
658
|
* ```ts
|
|
727
|
-
* composio.
|
|
659
|
+
* await composio.triggers.subscribe((data) => {
|
|
728
660
|
* console.log(data);
|
|
729
661
|
* });
|
|
730
662
|
*
|
|
731
|
-
* await triggers.unsubscribe();
|
|
663
|
+
* await composio.triggers.unsubscribe();
|
|
732
664
|
* ```
|
|
733
665
|
*/
|
|
734
666
|
async unsubscribe() {
|
|
@@ -748,18 +680,22 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
748
680
|
* Next.js Pages Router `req`). The signature headers (`webhook-id`,
|
|
749
681
|
* `webhook-timestamp`, `webhook-signature`) are read case-insensitively.
|
|
750
682
|
*
|
|
683
|
+
* Configure a request body limit in your server or framework as well,
|
|
684
|
+
* especially if it buffers the body before calling this method.
|
|
685
|
+
*
|
|
751
686
|
* @param {WebhookRequestLike} request - The incoming webhook HTTP request
|
|
752
687
|
* @param {ParseWebhookOptions} [options] - Parse options
|
|
753
688
|
* @param {string} [options.verifySecret] - Webhook secret; when set, the signature is verified
|
|
754
689
|
* @param {number} [options.tolerance=300] - Max webhook age in seconds (only used when verifying)
|
|
690
|
+
* @param {number} [options.maxBodyBytes=10485760] - Max request body size in bytes (10 MiB)
|
|
755
691
|
* @returns {Promise<VerifyWebhookResult>} The parsed (and optionally verified) webhook payload
|
|
756
692
|
*
|
|
757
693
|
* @throws {ValidationError} If `verifySecret` is set but the signature headers are missing
|
|
758
694
|
* @throws {ComposioWebhookSignatureVerificationError} If signature verification fails
|
|
759
|
-
* @throws {ComposioWebhookPayloadError} If the payload cannot be parsed
|
|
695
|
+
* @throws {ComposioWebhookPayloadError} If the payload exceeds the limit or cannot be parsed
|
|
760
696
|
*
|
|
761
697
|
* @example
|
|
762
|
-
* ```ts
|
|
698
|
+
* ```ts nocheck="Express route handler; the checker has no express types"
|
|
763
699
|
* // Express with express.raw (verify the signature)
|
|
764
700
|
* app.post('/webhooks/composio', express.raw({ type: 'application/json' }), async (req, res) => {
|
|
765
701
|
* try {
|
|
@@ -797,7 +733,10 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
797
733
|
* return new Response('Unauthorized', { status: 401 });
|
|
798
734
|
* }
|
|
799
735
|
* }
|
|
736
|
+
* ```
|
|
800
737
|
*
|
|
738
|
+
* @example
|
|
739
|
+
* ```ts
|
|
801
740
|
* // Next.js App Router — parse only (no verification)
|
|
802
741
|
* export async function POST(request: Request) {
|
|
803
742
|
* const result = await composio.triggers.parse(request);
|
|
@@ -811,15 +750,7 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
811
750
|
options?: ParseWebhookOptions
|
|
812
751
|
): Promise<VerifyWebhookResult> {
|
|
813
752
|
// Extract the raw body and signature headers from either request shape.
|
|
814
|
-
|
|
815
|
-
let headers: unknown;
|
|
816
|
-
if (isFetchRequest(request)) {
|
|
817
|
-
body = await request.text();
|
|
818
|
-
headers = request.headers;
|
|
819
|
-
} else {
|
|
820
|
-
body = bodyToString(request.body);
|
|
821
|
-
headers = request.headers;
|
|
822
|
-
}
|
|
753
|
+
const { body, headers } = await readWebhookRequest(request, options?.maxBodyBytes);
|
|
823
754
|
|
|
824
755
|
const verifySecret = options?.verifySecret;
|
|
825
756
|
|
|
@@ -887,6 +818,9 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
887
818
|
* The signature is computed as: `HMAC-SHA256(${webhookId}.${webhookTimestamp}.${payload}, secret)`
|
|
888
819
|
* and is expected in the format: `v1,base64EncodedSignature`
|
|
889
820
|
*
|
|
821
|
+
* For a Fetch API `Request`, use {@link parse} to enforce a limit while reading
|
|
822
|
+
* the body. Set a server request limit if you buffer the payload yourself.
|
|
823
|
+
*
|
|
890
824
|
* @param {VerifyWebhookParams} params - The verification parameters
|
|
891
825
|
* @param {string} params.payload - The raw webhook payload as a string (request body)
|
|
892
826
|
* @param {string} params.signature - The signature from the 'webhook-signature' header
|
|
@@ -894,6 +828,7 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
894
828
|
* @param {string} params.webhookId - The webhook ID from the 'webhook-id' header
|
|
895
829
|
* @param {string} params.webhookTimestamp - The timestamp from the 'webhook-timestamp' header (Unix seconds)
|
|
896
830
|
* @param {number} [params.tolerance=300] - Maximum allowed age of the webhook in seconds (default: 5 minutes). Set to 0 to disable timestamp validation.
|
|
831
|
+
* @param {number} [params.maxBodyBytes] - Max UTF-8 size of the supplied payload
|
|
897
832
|
* @returns {VerifyWebhookResult} The verified and parsed webhook payload with version information
|
|
898
833
|
*
|
|
899
834
|
* @throws {ValidationError} If the parameters are invalid
|
|
@@ -902,26 +837,26 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
902
837
|
*
|
|
903
838
|
* @example
|
|
904
839
|
* ```ts
|
|
905
|
-
* // In
|
|
906
|
-
*
|
|
840
|
+
* // In a webhook route that receives a Fetch API Request (Next.js App Router, Hono, Remix)
|
|
841
|
+
* export async function POST(request: Request) {
|
|
907
842
|
* try {
|
|
908
843
|
* const result = await composio.triggers.verifyWebhook({
|
|
909
|
-
* payload:
|
|
910
|
-
* signature:
|
|
911
|
-
*
|
|
912
|
-
*
|
|
844
|
+
* payload: await request.text(),
|
|
845
|
+
* signature: request.headers.get('webhook-signature') ?? '',
|
|
846
|
+
* id: request.headers.get('webhook-id') ?? '',
|
|
847
|
+
* timestamp: request.headers.get('webhook-timestamp') ?? '',
|
|
913
848
|
* secret: process.env.COMPOSIO_WEBHOOK_SECRET!,
|
|
914
849
|
* });
|
|
915
850
|
*
|
|
916
851
|
* // Process the verified payload
|
|
917
852
|
* console.log('Webhook version:', result.version);
|
|
918
853
|
* console.log('Received trigger:', result.payload.triggerSlug);
|
|
919
|
-
*
|
|
854
|
+
* return new Response('OK', { status: 200 });
|
|
920
855
|
* } catch (error) {
|
|
921
856
|
* console.error('Webhook verification failed:', error);
|
|
922
|
-
*
|
|
857
|
+
* return new Response('Unauthorized', { status: 401 });
|
|
923
858
|
* }
|
|
924
|
-
* }
|
|
859
|
+
* }
|
|
925
860
|
* ```
|
|
926
861
|
*/
|
|
927
862
|
async verifyWebhook(params: VerifyWebhookParams): Promise<VerifyWebhookResult> {
|
|
@@ -962,15 +897,20 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
962
897
|
id: webhookId,
|
|
963
898
|
timestamp: webhookTimestamp,
|
|
964
899
|
tolerance,
|
|
900
|
+
maxBodyBytes,
|
|
965
901
|
} = parsedParams.data;
|
|
966
902
|
|
|
903
|
+
if (maxBodyBytes !== undefined) {
|
|
904
|
+
assertWebhookBodySize(payload, maxBodyBytes);
|
|
905
|
+
}
|
|
906
|
+
|
|
967
907
|
// Validate timestamp if tolerance is set
|
|
968
908
|
if (tolerance > 0) {
|
|
969
|
-
|
|
909
|
+
validateWebhookTimestamp(webhookTimestamp, tolerance);
|
|
970
910
|
}
|
|
971
911
|
|
|
972
912
|
// Verify signature using the correct format: msgId.timestamp.payload
|
|
973
|
-
await
|
|
913
|
+
await verifyWebhookSignature(webhookId, webhookTimestamp, payload, signature, secret);
|
|
974
914
|
|
|
975
915
|
// Parse the payload and detect version
|
|
976
916
|
const { version, rawPayload, normalizedPayload } = this.parseWebhookPayload(payload);
|
|
@@ -1003,7 +943,7 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
1003
943
|
// Try V1/V2/V3 formats using shared parsing logic
|
|
1004
944
|
const result = this.tryParseVersionedPayload(jsonPayload);
|
|
1005
945
|
if (result.ok) {
|
|
1006
|
-
const { ok, ...rest } = result;
|
|
946
|
+
const { ok: _ok, ...rest } = result;
|
|
1007
947
|
return rest;
|
|
1008
948
|
}
|
|
1009
949
|
|
|
@@ -1168,109 +1108,4 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
1168
1108
|
},
|
|
1169
1109
|
};
|
|
1170
1110
|
}
|
|
1171
|
-
|
|
1172
|
-
/**
|
|
1173
|
-
* Verifies the HMAC-SHA256 signature of a webhook payload.
|
|
1174
|
-
* The signature format used by Composio is: `v1,base64EncodedSignature`
|
|
1175
|
-
* The signing input is: `${msgId}.${timestamp}.${payload}`
|
|
1176
|
-
* @private
|
|
1177
|
-
*/
|
|
1178
|
-
private async verifyWebhookSignature(
|
|
1179
|
-
webhookId: string,
|
|
1180
|
-
webhookTimestamp: string,
|
|
1181
|
-
payload: string,
|
|
1182
|
-
signature: string,
|
|
1183
|
-
secret: string
|
|
1184
|
-
): Promise<void> {
|
|
1185
|
-
if (payload.length === 0) {
|
|
1186
|
-
throw new ComposioWebhookSignatureVerificationError('No webhook payload was provided.');
|
|
1187
|
-
}
|
|
1188
|
-
|
|
1189
|
-
if (signature.length === 0) {
|
|
1190
|
-
throw new ComposioWebhookSignatureVerificationError(
|
|
1191
|
-
"No signature header value was provided. Please pass the value of the 'webhook-signature' header."
|
|
1192
|
-
);
|
|
1193
|
-
}
|
|
1194
|
-
|
|
1195
|
-
if (secret.length === 0) {
|
|
1196
|
-
throw new ComposioWebhookSignatureVerificationError(
|
|
1197
|
-
'No webhook secret was provided. You can find your webhook secret in your Composio dashboard.'
|
|
1198
|
-
);
|
|
1199
|
-
}
|
|
1200
|
-
|
|
1201
|
-
if (webhookId.length === 0) {
|
|
1202
|
-
throw new ComposioWebhookSignatureVerificationError(
|
|
1203
|
-
"No webhook ID was provided. Please pass the value of the 'webhook-id' header."
|
|
1204
|
-
);
|
|
1205
|
-
}
|
|
1206
|
-
|
|
1207
|
-
if (webhookTimestamp.length === 0) {
|
|
1208
|
-
throw new ComposioWebhookSignatureVerificationError(
|
|
1209
|
-
"No webhook timestamp was provided. Please pass the value of the 'webhook-timestamp' header."
|
|
1210
|
-
);
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1213
|
-
// Parse signature - may have multiple signatures prefixed with version (e.g., "v1,base64sig")
|
|
1214
|
-
const signatures = signature.split(' ');
|
|
1215
|
-
const v1Signatures: string[] = [];
|
|
1216
|
-
|
|
1217
|
-
for (const sig of signatures) {
|
|
1218
|
-
const [version, value] = sig.split(',');
|
|
1219
|
-
if (version === 'v1' && value) {
|
|
1220
|
-
v1Signatures.push(value);
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
if (v1Signatures.length === 0) {
|
|
1225
|
-
throw new ComposioWebhookSignatureVerificationError(
|
|
1226
|
-
'No valid v1 signature found in the webhook-signature header. ' +
|
|
1227
|
-
"Expected format: 'v1,base64EncodedSignature'"
|
|
1228
|
-
);
|
|
1229
|
-
}
|
|
1230
|
-
|
|
1231
|
-
// Compute expected signature: HMAC-SHA256(msgId.timestamp.payload, secret) -> base64
|
|
1232
|
-
const toSign = `${webhookId}.${webhookTimestamp}.${payload}`;
|
|
1233
|
-
const expectedSignature = await hmacSha256Base64(secret, toSign);
|
|
1234
|
-
|
|
1235
|
-
// Check if any of the provided signatures match
|
|
1236
|
-
let isValid = false;
|
|
1237
|
-
for (const providedSignature of v1Signatures) {
|
|
1238
|
-
if (timingSafeEqual(providedSignature, expectedSignature)) {
|
|
1239
|
-
isValid = true;
|
|
1240
|
-
break;
|
|
1241
|
-
}
|
|
1242
|
-
}
|
|
1243
|
-
|
|
1244
|
-
if (!isValid) {
|
|
1245
|
-
throw new ComposioWebhookSignatureVerificationError(
|
|
1246
|
-
'The signature provided is invalid. Please ensure you are using the correct webhook secret.'
|
|
1247
|
-
);
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
/**
|
|
1252
|
-
* Validates that the webhook timestamp is within the allowed tolerance
|
|
1253
|
-
* @private
|
|
1254
|
-
*/
|
|
1255
|
-
private validateWebhookTimestamp(webhookTimestamp: string, tolerance: number): void {
|
|
1256
|
-
const timestampSeconds = parseInt(webhookTimestamp, 10);
|
|
1257
|
-
|
|
1258
|
-
if (Number.isNaN(timestampSeconds)) {
|
|
1259
|
-
throw new ComposioWebhookPayloadError(
|
|
1260
|
-
`Invalid webhook timestamp: ${webhookTimestamp}. Expected Unix timestamp in seconds.`
|
|
1261
|
-
);
|
|
1262
|
-
}
|
|
1263
|
-
|
|
1264
|
-
const webhookTimeMs = timestampSeconds * 1000;
|
|
1265
|
-
const currentTime = Date.now();
|
|
1266
|
-
const timeDifference = Math.abs(currentTime - webhookTimeMs);
|
|
1267
|
-
|
|
1268
|
-
if (timeDifference > tolerance * 1000) {
|
|
1269
|
-
throw new ComposioWebhookSignatureVerificationError(
|
|
1270
|
-
`The webhook timestamp is outside the allowed tolerance. ` +
|
|
1271
|
-
`The webhook was sent ${Math.round(timeDifference / 1000)} seconds ago, ` +
|
|
1272
|
-
`but the maximum allowed age is ${tolerance} seconds.`
|
|
1273
|
-
);
|
|
1274
|
-
}
|
|
1275
|
-
}
|
|
1276
1111
|
}
|
package/src/models/Webhooks.ts
CHANGED
|
@@ -193,6 +193,8 @@ export class WebhookSubscriptions {
|
|
|
193
193
|
*
|
|
194
194
|
* @example
|
|
195
195
|
* ```typescript
|
|
196
|
+
* const APP_URL = 'https://your-app.com';
|
|
197
|
+
*
|
|
196
198
|
* const subscription = await composio.webhooks.subscriptions.set({
|
|
197
199
|
* webhookUrl: `${APP_URL}/webhooks/composio`,
|
|
198
200
|
* enabledEvents: ['composio.trigger.message', 'composio.connected_account.expired'],
|
|
@@ -78,6 +78,11 @@ export const CreateComposioManagedAuthConfigParamsSchema = z.object({
|
|
|
78
78
|
.optional(),
|
|
79
79
|
toolAccessConfig: AuthConfigCreationToolAccessConfigSchema.optional(),
|
|
80
80
|
isEnabledForToolRouter: z.boolean().optional(),
|
|
81
|
+
/**
|
|
82
|
+
* The Composio-managed app to use, as `composioManagedAuth[].managedAppId`
|
|
83
|
+
* from `composio.toolkits.get(slug)`. Omit to use the toolkit's default app.
|
|
84
|
+
*/
|
|
85
|
+
managedAppId: z.string().optional(),
|
|
81
86
|
});
|
|
82
87
|
|
|
83
88
|
/**
|
|
@@ -90,11 +95,19 @@ export const CreateAuthConfigParamsSchema = z.discriminatedUnion('type', [
|
|
|
90
95
|
|
|
91
96
|
export type CreateAuthConfigParams = z.infer<typeof CreateAuthConfigParamsSchema>;
|
|
92
97
|
|
|
98
|
+
/**
|
|
99
|
+
* The Composio-managed app an auth config uses, as
|
|
100
|
+
* `composioManagedAuth[].managedAppId` from `composio.toolkits.get(slug)`.
|
|
101
|
+
* `null` when the auth config is not linked to a managed app.
|
|
102
|
+
*/
|
|
103
|
+
const AuthConfigManagedAppIdSchema = z.string().nullable();
|
|
104
|
+
|
|
93
105
|
export const CreateAuthConfigResponseSchema = z.object({
|
|
94
106
|
id: z.string(),
|
|
95
107
|
authScheme: z.string(),
|
|
96
108
|
isComposioManaged: z.boolean(),
|
|
97
109
|
toolkit: z.string(),
|
|
110
|
+
managedAppId: AuthConfigManagedAppIdSchema,
|
|
98
111
|
});
|
|
99
112
|
export type CreateAuthConfigResponse = z.infer<typeof CreateAuthConfigResponseSchema>;
|
|
100
113
|
|
|
@@ -120,6 +133,7 @@ export const AuthConfigRetrieveResponseSchema = z.object({
|
|
|
120
133
|
createdAt: z.string().optional(),
|
|
121
134
|
lastUpdatedAt: z.string().optional(),
|
|
122
135
|
toolAccessConfig: AuthConfigToolAccessConfigSchema.optional(),
|
|
136
|
+
managedAppId: AuthConfigManagedAppIdSchema,
|
|
123
137
|
});
|
|
124
138
|
export type AuthConfigRetrieveResponse = z.infer<typeof AuthConfigRetrieveResponseSchema>;
|
|
125
139
|
|
|
@@ -624,7 +624,6 @@ const SamlConnectionDataSchema = z.discriminatedUnion('status', [
|
|
|
624
624
|
expired_at: z.string().optional(),
|
|
625
625
|
}).catchall(z.unknown()),
|
|
626
626
|
]);
|
|
627
|
-
const CustomSamlConnectionDataSchema = BaseSchemeRaw.catchall(z.unknown());
|
|
628
627
|
|
|
629
628
|
// DCR_OAUTH
|
|
630
629
|
const DcrOauthInitiatingSchema = BaseSchemeRaw.extend({
|