@devries-cameron20 / composio Mirror · read-only / commits / f178720eb
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 23, 01:45 UTC

Update client package version

haxzie committed May 26, 2025 at 18:40 UTC f178720eb56f221eedcca1647014584e484ea8c9
5 files changed +763 -36
examples/triggers/src/index.ts
+4
@@ -37,6 +37,10 @@ async function main() {
37
38 // TODO: Add your example implementation here
39 console.log('📝 Implement your triggers logic here!');
40 +
41 + composio.triggers.subscribe(data => {
42 + console.log('🔔 Trigger received:', data);
43 + });
44 } catch (error) {
45 console.error('❌ Error running example:', error);
46 }
packages/core/package.json
+1 -1
@@ -36,7 +36,7 @@
36 "vitest": "^3.1.3"
37 },
38 "dependencies": {
39 - "@composio/client": "0.1.0-alpha.14",
39 + "@composio/client": "0.1.0-alpha.15",
40 "chalk": "^5.4.1",
41 "openai": "^4.94.0",
42 "pusher-js": "^8.4.0",
packages/core/src/models/Triggers.ts
+16 -10
@@ -1,9 +1,7 @@
1 import ComposioClient from '@composio/client';
2 import { RequestOptions } from '@composio/client/internal/request-options';
3 import {
4 - TriggerInstanceDeleteResponse,
4 TriggerInstanceListActiveParams,
6 - TriggerInstanceUpdateStatusParams,
5 TriggerInstanceUpsertParams,
6 TriggerInstanceUpsertResponse,
7 TriggersTypeListParams,
@@ -16,6 +14,10 @@ import { PusherUtils, TriggerData } from '../utils/pusher';
14 import logger from '../utils/logger';
15 import { Session } from './Session';
16 import { telemetry } from '../telemetry/Telemetry';
17 +import {
18 + ManageDeleteResponse,
19 + ManageUpdateParams,
20 +} from '@composio/client/resources/trigger-instances/manage';
21 /**
22 * Trigger (Instance) class
23 * /api/v3/trigger_instances
@@ -72,8 +74,8 @@ export class Triggers {
74 * @param {string} triggerId - The slug of the trigger instance
75 * @returns
76 */
75 - async delete(triggerId: string): Promise<TriggerInstanceDeleteResponse> {
76 - return this.client.triggerInstances.delete(triggerId);
77 + async delete(triggerId: string): Promise<ManageDeleteResponse> {
78 + return this.client.triggerInstances.manage.delete(triggerId);
79 }
80
81 /**
@@ -86,10 +88,10 @@ export class Triggers {
88 */
89 async updateStatus(
90 status: TriggerStatusEnum,
89 - params: TriggerInstanceUpdateStatusParams,
91 + params: ManageUpdateParams,
92 options?: RequestOptions
93 ) {
92 - return this.client.triggerInstances.updateStatus(status, params, options);
94 + return this.client.triggerInstances.manage.update(status, params, options);
95 }
96
97 /**
@@ -99,8 +101,10 @@ export class Triggers {
101 * @param {RequestOptions options - Request options
102 * @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
103 */
102 - async disable(triggerId: string, options?: RequestOptions) {
103 - return this.client.triggerInstances.updateStatus('disable', { triggerId }, options);
104 + async disable(triggerId: string) {
105 + return this.client.triggerInstances.manage.update(triggerId, {
106 + status: 'disable',
107 + });
108 }
109
110 /**
@@ -110,8 +114,10 @@ export class Triggers {
114 * @param {RequestOptions options - Request options
115 * @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
116 */
113 - async enable(triggerId: string, options?: RequestOptions) {
114 - return this.client.triggerInstances.updateStatus('enable', { triggerId }, options);
117 + async enable(triggerId: string) {
118 + return this.client.triggerInstances.manage.update(triggerId, {
119 + status: 'enable',
120 + });
121 }
122
123 /**
packages/core/test/models/triggers.test.ts new
+723
@@ -0,0 +1,723 @@
1 +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2 +import { Triggers } from '../../src/models/triggers';
3 +import ComposioClient from '@composio/client';
4 +import { Session } from '../../src/models/Session';
5 +import { PusherUtils, TriggerData } from '../../src/utils/pusher';
6 +import logger from '../../src/utils/logger';
7 +import { TriggerStatusEnum, TriggerSubscribeParams } from '../../src/types/triggers.types';
8 +import { telemetry } from '../../src/telemetry/Telemetry';
9 +
10 +// Mock dependencies
11 +vi.mock('../../src/models/Session');
12 +vi.mock('../../src/utils/pusher');
13 +vi.mock('../../src/utils/logger');
14 +vi.mock('../../src/telemetry/Telemetry', () => ({
15 + telemetry: {
16 + instrument: vi.fn(),
17 + },
18 +}));
19 +
20 +// Create mock client with trigger-related methods
21 +const createMockClient = () => ({
22 + baseURL: 'https://api.composio.dev',
23 + apiKey: 'test-api-key',
24 + triggerInstances: {
25 + listActive: vi.fn(),
26 + upsert: vi.fn(),
27 + delete: vi.fn(),
28 + updateStatus: vi.fn(),
29 + },
30 + triggersTypes: {
31 + list: vi.fn(),
32 + retrieve: vi.fn(),
33 + retrieveEnum: vi.fn(),
34 + },
35 + auth: {
36 + session: {
37 + retrieve: vi.fn(),
38 + },
39 + },
40 +});
41 +
42 +// Mock response data
43 +const mockTriggerInstances = {
44 + items: [
45 + {
46 + id: 'trigger-1',
47 + slug: 'github_webhook',
48 + status: 'active',
49 + connectedAccountId: 'conn-123',
50 + config: { webhook_url: 'https://example.com/webhook' },
51 + createdAt: '2024-01-01T00:00:00Z',
52 + updatedAt: '2024-01-01T00:00:00Z',
53 + },
54 + {
55 + id: 'trigger-2',
56 + slug: 'slack_message',
57 + status: 'inactive',
58 + connectedAccountId: 'conn-456',
59 + config: { channel: '#general' },
60 + createdAt: '2024-01-02T00:00:00Z',
61 + updatedAt: '2024-01-02T00:00:00Z',
62 + },
63 + ],
64 + totalPages: 1,
65 + page: 1,
66 + pageSize: 10,
67 +};
68 +
69 +const mockTriggerInstance = {
70 + id: 'trigger-123',
71 + slug: 'test_trigger',
72 + status: 'active',
73 + connectedAccountId: 'conn-123',
74 + config: { param1: 'value1' },
75 + createdAt: '2024-01-01T00:00:00Z',
76 + updatedAt: '2024-01-01T00:00:00Z',
77 +};
78 +
79 +const mockTriggerTypes = {
80 + items: [
81 + {
82 + slug: 'github_webhook',
83 + name: 'GitHub Webhook',
84 + description: 'Triggered when a GitHub event occurs',
85 + config: {
86 + required: ['webhook_url'],
87 + optional: ['secret'],
88 + },
89 + },
90 + {
91 + slug: 'slack_message',
92 + name: 'Slack Message',
93 + description: 'Triggered when a Slack message is received',
94 + config: {
95 + required: ['channel'],
96 + optional: ['pattern'],
97 + },
98 + },
99 + ],
100 + totalPages: 1,
101 + page: 1,
102 +};
103 +
104 +const mockTriggerType = {
105 + slug: 'github_webhook',
106 + name: 'GitHub Webhook',
107 + description: 'Triggered when a GitHub event occurs',
108 + config: {
109 + required: ['webhook_url'],
110 + optional: ['secret'],
111 + },
112 + toolkit: {
113 + slug: 'github',
114 + name: 'GitHub',
115 + },
116 +};
117 +
118 +const mockTriggerEnum = {
119 + enum: ['github_webhook', 'slack_message', 'email_received'],
120 +};
121 +
122 +const mockSessionInfo = {
123 + project: {
124 + id: 'client-123',
125 + name: 'Test Project',
126 + },
127 + user: {
128 + id: 'user-456',
129 + email: 'test@example.com',
130 + },
131 +};
132 +
133 +const mockTriggerData: TriggerData = {
134 + appName: 'github',
135 + clientId: 123,
136 + payload: { action: 'push', repository: 'test-repo' },
137 + originalPayload: { action: 'push', repository: 'test-repo' },
138 + metadata: {
139 + id: 'trigger-123',
140 + connectionId: 'conn-123',
141 + triggerName: 'github_webhook',
142 + triggerData: '{"action":"push"}',
143 + triggerConfig: { webhook_url: 'https://example.com/webhook' },
144 + connection: {
145 + id: 'conn-123',
146 + integrationId: 'github',
147 + clientUniqueUserId: 'user-456',
148 + status: 'active',
149 + },
150 + },
151 +};
152 +
153 +describe('Triggers', () => {
154 + let triggers: Triggers;
155 + let mockClient: ReturnType<typeof createMockClient>;
156 + let mockSession: Session;
157 +
158 + beforeEach(() => {
159 + vi.clearAllMocks();
160 +
161 + mockClient = createMockClient();
162 + triggers = new Triggers(mockClient as unknown as ComposioClient);
163 +
164 + // Mock Session
165 + mockSession = {
166 + getInfo: vi.fn().mockResolvedValue(mockSessionInfo),
167 + } as unknown as Session;
168 + (Session as any).mockImplementation(() => mockSession);
169 +
170 + // Mock PusherUtils
171 + vi.mocked(PusherUtils.getPusherClient).mockResolvedValue({} as any);
172 + vi.mocked(PusherUtils.triggerSubscribe).mockImplementation(() => {});
173 + vi.mocked(PusherUtils.triggerUnsubscribe).mockImplementation(() => {});
174 + });
175 +
176 + afterEach(() => {
177 + vi.resetAllMocks();
178 + });
179 +
180 + describe('constructor', () => {
181 + it('should create an instance successfully', () => {
182 + expect(triggers).toBeInstanceOf(Triggers);
183 + expect(telemetry.instrument).toHaveBeenCalledWith(triggers);
184 + });
185 +
186 + it('should store the client reference', () => {
187 + expect(triggers['client']).toBe(mockClient);
188 + });
189 + });
190 +
191 + describe('list', () => {
192 + it('should list active trigger instances', async () => {
193 + mockClient.triggerInstances.listActive.mockResolvedValue(mockTriggerInstances);
194 +
195 + const result = await triggers.list();
196 +
197 + expect(mockClient.triggerInstances.listActive).toHaveBeenCalledWith(undefined, undefined);
198 + expect(result).toEqual(mockTriggerInstances);
199 + });
200 +
201 + it('should list active trigger instances with query parameters', async () => {
202 + const query = { limit: 5, page: 2 };
203 + const options = { timeout: 5000 };
204 + mockClient.triggerInstances.listActive.mockResolvedValue(mockTriggerInstances);
205 +
206 + const result = await triggers.list(query, options);
207 +
208 + expect(mockClient.triggerInstances.listActive).toHaveBeenCalledWith(query, options);
209 + expect(result).toEqual(mockTriggerInstances);
210 + });
211 + });
212 +
213 + describe('create', () => {
214 + it('should create a new trigger instance', async () => {
215 + const slug = 'github_webhook';
216 + const body = {
217 + connectedAccountId: 'conn-123',
218 + config: { webhook_url: 'https://example.com/webhook' },
219 + } as any;
220 + mockClient.triggerInstances.upsert.mockResolvedValue(mockTriggerInstance);
221 +
222 + const result = await triggers.create(slug, body);
223 +
224 + expect(mockClient.triggerInstances.upsert).toHaveBeenCalledWith(slug, body, undefined);
225 + expect(result).toEqual(mockTriggerInstance);
226 + });
227 +
228 + it('should create a new trigger instance with options', async () => {
229 + const slug = 'github_webhook';
230 + const body = {
231 + connectedAccountId: 'conn-123',
232 + config: { webhook_url: 'https://example.com/webhook' },
233 + } as any;
234 + const options = { timeout: 5000 };
235 + mockClient.triggerInstances.upsert.mockResolvedValue(mockTriggerInstance);
236 +
237 + const result = await triggers.create(slug, body, options);
238 +
239 + expect(mockClient.triggerInstances.upsert).toHaveBeenCalledWith(slug, body, options);
240 + expect(result).toEqual(mockTriggerInstance);
241 + });
242 + });
243 +
244 + describe('update', () => {
245 + it('should update an existing trigger instance', async () => {
246 + const slug = 'github_webhook';
247 + const body = {
248 + connectedAccountId: 'conn-123',
249 + config: { webhook_url: 'https://updated.example.com/webhook' },
250 + } as any;
251 + mockClient.triggerInstances.upsert.mockResolvedValue(mockTriggerInstance);
252 +
253 + const result = await triggers.update(slug, body);
254 +
255 + expect(mockClient.triggerInstances.upsert).toHaveBeenCalledWith(slug, body);
256 + expect(result).toEqual(mockTriggerInstance);
257 + });
258 + });
259 +
260 + describe('delete', () => {
261 + it('should delete a trigger instance', async () => {
262 + const triggerId = 'trigger-123';
263 + const deleteResponse = { success: true, message: 'Trigger deleted successfully' };
264 + mockClient.triggerInstances.delete.mockResolvedValue(deleteResponse);
265 +
266 + const result = await triggers.delete(triggerId);
267 +
268 + expect(mockClient.triggerInstances.delete).toHaveBeenCalledWith(triggerId);
269 + expect(result).toEqual(deleteResponse);
270 + });
271 + });
272 +
273 + describe('updateStatus', () => {
274 + it('should update the status of a trigger', async () => {
275 + const status: TriggerStatusEnum = 'enable';
276 + const params = { triggerId: 'trigger-123' };
277 + const options = { timeout: 5000 };
278 + mockClient.triggerInstances.updateStatus.mockResolvedValue(mockTriggerInstance);
279 +
280 + const result = await triggers.updateStatus(status, params, options);
281 +
282 + expect(mockClient.triggerInstances.updateStatus).toHaveBeenCalledWith(
283 + status,
284 + params,
285 + options
286 + );
287 + expect(result).toEqual(mockTriggerInstance);
288 + });
289 +
290 + it('should update the status without options', async () => {
291 + const status: TriggerStatusEnum = 'disable';
292 + const params = { triggerId: 'trigger-123' };
293 + mockClient.triggerInstances.updateStatus.mockResolvedValue(mockTriggerInstance);
294 +
295 + const result = await triggers.updateStatus(status, params);
296 +
297 + expect(mockClient.triggerInstances.updateStatus).toHaveBeenCalledWith(
298 + status,
299 + params,
300 + undefined
301 + );
302 + expect(result).toEqual(mockTriggerInstance);
303 + });
304 + });
305 +
306 + describe('disable', () => {
307 + it('should disable a trigger instance', async () => {
308 + const triggerId = 'trigger-123';
309 + mockClient.triggerInstances.updateStatus.mockResolvedValue(mockTriggerInstance);
310 +
311 + const result = await triggers.disable(triggerId);
312 +
313 + expect(mockClient.triggerInstances.updateStatus).toHaveBeenCalledWith(
314 + 'disable',
315 + { triggerId },
316 + undefined
317 + );
318 + expect(result).toEqual(mockTriggerInstance);
319 + });
320 +
321 + it('should disable a trigger instance with options', async () => {
322 + const triggerId = 'trigger-123';
323 + const options = { timeout: 5000 };
324 + mockClient.triggerInstances.updateStatus.mockResolvedValue(mockTriggerInstance);
325 +
326 + const result = await triggers.disable(triggerId, options);
327 +
328 + expect(mockClient.triggerInstances.updateStatus).toHaveBeenCalledWith(
329 + 'disable',
330 + { triggerId },
331 + options
332 + );
333 + expect(result).toEqual(mockTriggerInstance);
334 + });
335 + });
336 +
337 + describe('enable', () => {
338 + it('should enable a trigger instance', async () => {
339 + const triggerId = 'trigger-123';
340 + mockClient.triggerInstances.updateStatus.mockResolvedValue(mockTriggerInstance);
341 +
342 + const result = await triggers.enable(triggerId);
343 +
344 + expect(mockClient.triggerInstances.updateStatus).toHaveBeenCalledWith(
345 + 'enable',
346 + { triggerId },
347 + undefined
348 + );
349 + expect(result).toEqual(mockTriggerInstance);
350 + });
351 +
352 + it('should enable a trigger instance with options', async () => {
353 + const triggerId = 'trigger-123';
354 + const options = { timeout: 5000 };
355 + mockClient.triggerInstances.updateStatus.mockResolvedValue(mockTriggerInstance);
356 +
357 + const result = await triggers.enable(triggerId, options);
358 +
359 + expect(mockClient.triggerInstances.updateStatus).toHaveBeenCalledWith(
360 + 'enable',
361 + { triggerId },
362 + options
363 + );
364 + expect(result).toEqual(mockTriggerInstance);
365 + });
366 + });
367 +
368 + describe('listTypes', () => {
369 + it('should list all trigger types', async () => {
370 + mockClient.triggersTypes.list.mockResolvedValue(mockTriggerTypes);
371 +
372 + const result = await triggers.listTypes();
373 +
374 + expect(mockClient.triggersTypes.list).toHaveBeenCalledWith(undefined, undefined);
375 + expect(result).toEqual(mockTriggerTypes);
376 + });
377 +
378 + it('should list trigger types with query parameters', async () => {
379 + const query = { limit: 10, toolkit: 'github' };
380 + const options = { timeout: 5000 };
381 + mockClient.triggersTypes.list.mockResolvedValue(mockTriggerTypes);
382 +
383 + const result = await triggers.listTypes(query, options);
384 +
385 + expect(mockClient.triggersTypes.list).toHaveBeenCalledWith(query, options);
386 + expect(result).toEqual(mockTriggerTypes);
387 + });
388 + });
389 +
390 + describe('getType', () => {
391 + it('should retrieve a trigger type by slug', async () => {
392 + const slug = 'github_webhook';
393 + mockClient.triggersTypes.retrieve.mockResolvedValue(mockTriggerType);
394 +
395 + const result = await triggers.getType(slug);
396 +
397 + expect(mockClient.triggersTypes.retrieve).toHaveBeenCalledWith(slug, undefined);
398 + expect(result).toEqual(mockTriggerType);
399 + });
400 +
401 + it('should retrieve a trigger type with options', async () => {
402 + const slug = 'github_webhook';
403 + const options = { timeout: 5000 };
404 + mockClient.triggersTypes.retrieve.mockResolvedValue(mockTriggerType);
405 +
406 + const result = await triggers.getType(slug, options);
407 +
408 + expect(mockClient.triggersTypes.retrieve).toHaveBeenCalledWith(slug, options);
409 + expect(result).toEqual(mockTriggerType);
410 + });
411 + });
412 +
413 + describe('listEnum', () => {
414 + it('should fetch the list of all available trigger enums', async () => {
415 + mockClient.triggersTypes.retrieveEnum.mockResolvedValue(mockTriggerEnum);
416 +
417 + const result = await triggers.listEnum();
418 +
419 + expect(mockClient.triggersTypes.retrieveEnum).toHaveBeenCalledWith(undefined);
420 + expect(result).toEqual(mockTriggerEnum);
421 + });
422 +
423 + it('should fetch trigger enums with options', async () => {
424 + const options = { timeout: 5000 };
425 + mockClient.triggersTypes.retrieveEnum.mockResolvedValue(mockTriggerEnum);
426 +
427 + const result = await triggers.listEnum(options);
428 +
429 + expect(mockClient.triggersTypes.retrieveEnum).toHaveBeenCalledWith(options);
430 + expect(result).toEqual(mockTriggerEnum);
431 + });
432 + });
433 +
434 + describe('subscribe', () => {
435 + const mockCallback = vi.fn();
436 +
437 + beforeEach(() => {
438 + mockCallback.mockClear();
439 + });
440 +
441 + it('should throw error if function is not provided', async () => {
442 + await expect(triggers.subscribe(null as any)).rejects.toThrow(
443 + 'Function is required for trigger subscription'
444 + );
445 + });
446 +
447 + it('should throw error if client ID is not found', async () => {
448 + mockSession.getInfo = vi.fn().mockResolvedValue({ project: null });
449 +
450 + await expect(triggers.subscribe(mockCallback)).rejects.toThrow('Client ID not found');
451 + });
452 +
453 + it('should throw error if API key is not found', async () => {
454 + mockClient.apiKey = undefined as any;
455 +
456 + await expect(triggers.subscribe(mockCallback)).rejects.toThrow('API key not found');
457 + });
458 +
459 + it('should subscribe to triggers without filters', async () => {
460 + await triggers.subscribe(mockCallback);
461 +
462 + expect(mockSession.getInfo).toHaveBeenCalled();
463 + expect(PusherUtils.getPusherClient).toHaveBeenCalledWith(
464 + mockClient.baseURL,
465 + mockClient.apiKey
466 + );
467 + expect(PusherUtils.triggerSubscribe).toHaveBeenCalled();
468 + expect(logger.debug).toHaveBeenCalledWith('Subscribing to triggers', {});
469 + });
470 +
471 + it('should subscribe to triggers with filters', async () => {
472 + const filters: TriggerSubscribeParams = {
473 + appName: 'github',
474 + triggerId: 'trigger-123',
475 + connectionId: 'conn-123',
476 + };
477 +
478 + await triggers.subscribe(mockCallback, filters);
479 +
480 + expect(mockSession.getInfo).toHaveBeenCalled();
481 + expect(PusherUtils.getPusherClient).toHaveBeenCalledWith(
482 + mockClient.baseURL,
483 + mockClient.apiKey
484 + );
485 + expect(PusherUtils.triggerSubscribe).toHaveBeenCalled();
486 + expect(logger.debug).toHaveBeenCalledWith('Subscribing to triggers', filters);
487 + });
488 +
489 + it('should filter triggers based on appName', async () => {
490 + const filters: TriggerSubscribeParams = { appName: 'github' };
491 + await triggers.subscribe(mockCallback, filters);
492 +
493 + // Get the filter function that was passed to PusherUtils.triggerSubscribe
494 + const triggerSubscribeCall = vi.mocked(PusherUtils.triggerSubscribe).mock.calls[0];
495 + const filterCallback = triggerSubscribeCall[1];
496 +
497 + // Test data that should match the filter
498 + const matchingData = { ...mockTriggerData, appName: 'github' };
499 + const nonMatchingData = { ...mockTriggerData, appName: 'slack' };
500 +
501 + filterCallback(matchingData);
502 + filterCallback(nonMatchingData);
503 +
504 + expect(mockCallback).toHaveBeenCalledWith(matchingData);
505 + expect(mockCallback).toHaveBeenCalledTimes(1);
506 + });
507 +
508 + it('should filter triggers based on triggerId', async () => {
509 + const filters: TriggerSubscribeParams = { triggerId: 'trigger-123' };
510 + await triggers.subscribe(mockCallback, filters);
511 +
512 + const triggerSubscribeCall = vi.mocked(PusherUtils.triggerSubscribe).mock.calls[0];
513 + const filterCallback = triggerSubscribeCall[1];
514 +
515 + const matchingData = { ...mockTriggerData };
516 + const nonMatchingData = {
517 + ...mockTriggerData,
518 + metadata: { ...mockTriggerData.metadata, id: 'trigger-456' },
519 + };
520 +
521 + filterCallback(matchingData);
522 + filterCallback(nonMatchingData);
523 +
524 + expect(mockCallback).toHaveBeenCalledWith(matchingData);
525 + expect(mockCallback).toHaveBeenCalledTimes(1);
526 + });
527 +
528 + it('should filter triggers based on connectionId', async () => {
529 + const filters: TriggerSubscribeParams = { connectionId: 'conn-123' };
530 + await triggers.subscribe(mockCallback, filters);
531 +
532 + const triggerSubscribeCall = vi.mocked(PusherUtils.triggerSubscribe).mock.calls[0];
533 + const filterCallback = triggerSubscribeCall[1];
534 +
535 + const matchingData = { ...mockTriggerData };
536 + const nonMatchingData = {
537 + ...mockTriggerData,
538 + metadata: { ...mockTriggerData.metadata, connectionId: 'conn-456' },
539 + };
540 +
541 + filterCallback(matchingData);
542 + filterCallback(nonMatchingData);
543 +
544 + expect(mockCallback).toHaveBeenCalledWith(matchingData);
545 + expect(mockCallback).toHaveBeenCalledTimes(1);
546 + });
547 +
548 + it('should filter triggers based on triggerName', async () => {
549 + const filters: TriggerSubscribeParams = { triggerName: 'github_webhook' };
550 + await triggers.subscribe(mockCallback, filters);
551 +
552 + const triggerSubscribeCall = vi.mocked(PusherUtils.triggerSubscribe).mock.calls[0];
553 + const filterCallback = triggerSubscribeCall[1];
554 +
555 + const matchingData = { ...mockTriggerData };
556 + const nonMatchingData = {
557 + ...mockTriggerData,
558 + metadata: { ...mockTriggerData.metadata, triggerName: 'slack_message' },
559 + };
560 +
561 + filterCallback(matchingData);
562 + filterCallback(nonMatchingData);
563 +
564 + expect(mockCallback).toHaveBeenCalledWith(matchingData);
565 + expect(mockCallback).toHaveBeenCalledTimes(1);
566 + });
567 +
568 + it('should filter triggers based on entityId', async () => {
569 + const filters: TriggerSubscribeParams = { entityId: 'user-456' };
570 + await triggers.subscribe(mockCallback, filters);
571 +
572 + const triggerSubscribeCall = vi.mocked(PusherUtils.triggerSubscribe).mock.calls[0];
573 + const filterCallback = triggerSubscribeCall[1];
574 +
575 + const matchingData = { ...mockTriggerData };
576 + const nonMatchingData = {
577 + ...mockTriggerData,
578 + metadata: {
579 + ...mockTriggerData.metadata,
580 + connection: {
581 + ...mockTriggerData.metadata.connection,
582 + clientUniqueUserId: 'user-789',
583 + },
584 + },
585 + };
586 +
587 + filterCallback(matchingData);
588 + filterCallback(nonMatchingData);
589 +
590 + expect(mockCallback).toHaveBeenCalledWith(matchingData);
591 + expect(mockCallback).toHaveBeenCalledTimes(1);
592 + });
593 +
594 + it('should filter triggers based on integrationId', async () => {
595 + const filters: TriggerSubscribeParams = { integrationId: 'github' };
596 + await triggers.subscribe(mockCallback, filters);
597 +
598 + const triggerSubscribeCall = vi.mocked(PusherUtils.triggerSubscribe).mock.calls[0];
599 + const filterCallback = triggerSubscribeCall[1];
600 +
601 + const matchingData = { ...mockTriggerData };
602 + const nonMatchingData = {
603 + ...mockTriggerData,
604 + metadata: {
605 + ...mockTriggerData.metadata,
606 + connection: {
607 + ...mockTriggerData.metadata.connection,
608 + integrationId: 'slack',
609 + },
610 + },
611 + };
612 +
613 + filterCallback(matchingData);
614 + filterCallback(nonMatchingData);
615 +
616 + expect(mockCallback).toHaveBeenCalledWith(matchingData);
617 + expect(mockCallback).toHaveBeenCalledTimes(1);
618 + });
619 +
620 + it('should apply multiple filters correctly', async () => {
621 + const filters: TriggerSubscribeParams = {
622 + appName: 'github',
623 + triggerId: 'trigger-123',
624 + connectionId: 'conn-123',
625 + };
626 + await triggers.subscribe(mockCallback, filters);
627 +
628 + const triggerSubscribeCall = vi.mocked(PusherUtils.triggerSubscribe).mock.calls[0];
629 + const filterCallback = triggerSubscribeCall[1];
630 +
631 + const matchingData = { ...mockTriggerData, appName: 'github' };
632 + const nonMatchingDataApp = { ...mockTriggerData, appName: 'slack' };
633 + const nonMatchingDataTrigger = {
634 + ...mockTriggerData,
635 + appName: 'github',
636 + metadata: { ...mockTriggerData.metadata, id: 'trigger-456' },
637 + };
638 +
639 + filterCallback(matchingData);
640 + filterCallback(nonMatchingDataApp);
641 + filterCallback(nonMatchingDataTrigger);
642 +
643 + expect(mockCallback).toHaveBeenCalledWith(matchingData);
644 + expect(mockCallback).toHaveBeenCalledTimes(1);
645 + });
646 +
647 + it('should pass all triggers when no filters are provided', async () => {
648 + await triggers.subscribe(mockCallback);
649 +
650 + const triggerSubscribeCall = vi.mocked(PusherUtils.triggerSubscribe).mock.calls[0];
651 + const filterCallback = triggerSubscribeCall[1];
652 +
653 + const testData1 = { ...mockTriggerData, appName: 'github' };
654 + const testData2 = { ...mockTriggerData, appName: 'slack' };
655 +
656 + filterCallback(testData1);
657 + filterCallback(testData2);
658 +
659 + expect(mockCallback).toHaveBeenCalledWith(testData1);
660 + expect(mockCallback).toHaveBeenCalledWith(testData2);
661 + expect(mockCallback).toHaveBeenCalledTimes(2);
662 + });
663 +
664 + it('should be case insensitive for filters', async () => {
665 + const filters: TriggerSubscribeParams = { appName: 'GITHUB' };
666 + await triggers.subscribe(mockCallback, filters);
667 +
668 + const triggerSubscribeCall = vi.mocked(PusherUtils.triggerSubscribe).mock.calls[0];
669 + const filterCallback = triggerSubscribeCall[1];
670 +
671 + const matchingData = { ...mockTriggerData, appName: 'github' };
672 +
673 + filterCallback(matchingData);
674 +
675 + expect(mockCallback).toHaveBeenCalledWith(matchingData);
676 + expect(mockCallback).toHaveBeenCalledTimes(1);
677 + });
678 + });
679 +
680 + describe('unsubscribe', () => {
681 + it('should unsubscribe from triggers', async () => {
682 + await triggers.unsubscribe();
683 +
684 + expect(mockSession.getInfo).toHaveBeenCalled();
685 + expect(PusherUtils.triggerUnsubscribe).toHaveBeenCalledWith('client-123');
686 + });
687 +
688 + it('should throw error if client ID is not found during unsubscribe', async () => {
689 + mockSession.getInfo = vi.fn().mockResolvedValue({ project: null });
690 +
691 + await expect(triggers.unsubscribe()).rejects.toThrow('Client ID not found');
692 + });
693 + });
694 +
695 + describe('error handling', () => {
696 + it('should handle API errors gracefully', async () => {
697 + const apiError = new Error('API request failed');
698 + mockClient.triggerInstances.listActive.mockRejectedValue(apiError);
699 +
700 + await expect(triggers.list()).rejects.toThrow('API request failed');
701 + });
702 +
703 + it('should handle session retrieval errors', async () => {
704 + const sessionError = new Error('Session retrieval failed');
705 + mockSession.getInfo = vi.fn().mockRejectedValue(sessionError);
706 +
707 + await expect(triggers.subscribe(vi.fn())).rejects.toThrow('Session retrieval failed');
708 + });
709 +
710 + it('should handle pusher client errors gracefully', async () => {
711 + const pusherError = new Error('Pusher connection failed');
712 + vi.mocked(PusherUtils.getPusherClient).mockRejectedValue(pusherError);
713 +
714 + await expect(triggers.subscribe(vi.fn())).rejects.toThrow('Pusher connection failed');
715 + });
716 + });
717 +
718 + describe('telemetry integration', () => {
719 + it('should instrument the class for telemetry', () => {
720 + expect(telemetry.instrument).toHaveBeenCalledWith(triggers);
721 + });
722 + });
723 +});
pnpm-lock.yaml
+19 -25
@@ -118,7 +118,7 @@ importers:
118 version: link:../../packages/providers/langchain
119 '@langchain/core':
120 specifier: ^0.3.56
121 - version: 0.3.57(openai@4.103.0(zod@3.25.32))
121 + version: 0.3.56(openai@4.98.0(encoding@0.1.13)(zod@3.24.4))
122 '@langchain/langgraph':
123 specifier: ^0.2.72
124 version: 0.2.73(@langchain/core@0.3.57(openai@4.103.0(zod@3.25.32)))(react@19.1.0)(zod-to-json-schema@3.24.5(zod@3.25.32))
@@ -301,8 +301,8 @@ importers:
301 packages/core:
302 dependencies:
303 '@composio/client':
304 - specifier: 0.1.0-alpha.14
305 - version: 0.1.0-alpha.14
304 + specifier: 0.1.0-alpha.15
305 + version: 0.1.0-alpha.15
306 chalk:
307 specifier: ^5.4.1
308 version: 5.4.1
@@ -385,7 +385,7 @@ importers:
385 dependencies:
386 '@langchain/core':
387 specifier: ^0.3.44
388 - version: 0.3.57(openai@4.103.0(zod@3.25.32))
388 + version: 0.3.56(openai@4.98.0(encoding@0.1.13)(zod@3.24.4))
389 devDependencies:
390 '@composio/core':
391 specifier: workspace:*
@@ -399,7 +399,7 @@ importers:
399 version: 5.8.3
400 vitest:
401 specifier: ^3.1.3
402 - version: 3.1.4(@types/node@22.15.23)(@vitest/ui@3.1.4)(tsx@4.19.4)(yaml@2.8.0)
402 + version: 3.1.3(@types/node@22.15.18)(@vitest/ui@3.1.4)(tsx@4.19.4)(yaml@2.8.0)
403
404 packages/providers/mastra:
405 dependencies:
@@ -419,7 +419,7 @@ importers:
419 version: 5.8.3
420 vitest:
421 specifier: ^3.1.3
422 - version: 3.1.4(@types/node@22.15.23)(@vitest/ui@3.1.4)(tsx@4.19.4)(yaml@2.8.0)
422 + version: 3.1.4(@types/node@22.15.18)(@vitest/ui@3.1.4)(tsx@4.19.4)(yaml@2.8.0)
423
424 packages/providers/openai:
425 dependencies:
@@ -705,17 +705,11 @@ packages:
705 '@cloudflare/workers-types@4.20250528.0':
706 resolution: {integrity: sha512-q4yNRSw7At9nm1GsN+KUGfbrl5nGuiS+q/1esbhcXL/FQUDUZbVdutbPBMtJLaXAd5PCLdOST/nZni8GzJkaYg==}
707
708 - '@composio/client@0.1.0-alpha.14':
709 - resolution: {integrity: sha512-oDGR1N5gRqVWaoPD0pqgD26ZtwGCICRio7nSzcelgN4fRoVCRTGREXDo6WMXkA3hBsLjg9LqoMQvMMELvo4A6w==}
710 -
711 - '@esbuild/aix-ppc64@0.21.5':
712 - resolution: {integrity: sha512-1SDgH6ZSPTlggy1yI6+Dbkiz8xzpHJEVAlF/AM1tHPLsf5STom9rwtjE4hKAF20FfXXNTFqEYXyJNWh1GiZedQ==}
713 - engines: {node: '>=12'}
714 - cpu: [ppc64]
715 - os: [aix]
708 + '@composio/client@0.1.0-alpha.15':
709 + resolution: {integrity: sha512-fgUx9uo+wWKuS2+WnzqcQsUuID89hD1nqWs9VOCQw/UiRdwNpA0gZdfHAEQEcjPti7wy7mYLOzT9LCVrR+vs7g==}
710
717 - '@esbuild/aix-ppc64@0.25.5':
718 - resolution: {integrity: sha512-9o3TMmpmftaCMepOdA5k/yDw8SfInyzWWTjYTFCX3kPSDJMROQTb8jg+h9Cnwnmm1vOzvxN7gIfB5V2ewpjtGA==}
711 + '@esbuild/aix-ppc64@0.25.4':
712 + resolution: {integrity: sha512-1VCICWypeQKhVbE9oW/sJaAmjLxhVqacdkvPLEjwlttjfwENRSClS8EjBz0KzRyFSCPDIkuXW34Je/vk7zdB7Q==}
713 engines: {node: '>=18'}
714 cpu: [ppc64]
715 os: [aix]
@@ -4937,7 +4931,7 @@ snapshots:
4931
4932 '@cloudflare/workers-types@4.20250528.0': {}
4933
4940 - '@composio/client@0.1.0-alpha.14': {}
4934 + '@composio/client@0.1.0-alpha.15': {}
4935
4936 '@esbuild/aix-ppc64@0.21.5':
4937 optional: true
@@ -5211,7 +5205,7 @@ snapshots:
5205 camelcase: 6.3.0
5206 decamelize: 1.2.0
5207 js-tiktoken: 1.0.20
5214 - langsmith: 0.3.29(openai@4.103.0(zod@3.25.32))
5208 + langsmith: 0.3.29(openai@4.98.0(encoding@0.1.13)(zod@3.24.4))
5209 mustache: 4.2.0
5210 p-queue: 6.6.2
5211 p-retry: 4.6.2
@@ -5223,7 +5217,7 @@ snapshots:
5217
5218 '@langchain/langgraph-checkpoint@0.0.17(@langchain/core@0.3.57(openai@4.103.0(zod@3.25.32)))':
5219 dependencies:
5226 - '@langchain/core': 0.3.57(openai@4.103.0(zod@3.25.32))
5220 + '@langchain/core': 0.3.56(openai@4.98.0(encoding@0.1.13)(zod@3.24.4))
5221 uuid: 10.0.0
5222
5223 '@langchain/langgraph-sdk@0.0.78(@langchain/core@0.3.57(openai@4.103.0(zod@3.25.32)))(react@19.1.0)':
@@ -5233,14 +5227,14 @@ snapshots:
5227 p-retry: 4.6.2
5228 uuid: 9.0.1
5229 optionalDependencies:
5236 - '@langchain/core': 0.3.57(openai@4.103.0(zod@3.25.32))
5230 + '@langchain/core': 0.3.56(openai@4.98.0(encoding@0.1.13)(zod@3.24.4))
5231 react: 19.1.0
5232
5233 '@langchain/langgraph@0.2.73(@langchain/core@0.3.57(openai@4.103.0(zod@3.25.32)))(react@19.1.0)(zod-to-json-schema@3.24.5(zod@3.25.32))':
5234 dependencies:
5241 - '@langchain/core': 0.3.57(openai@4.103.0(zod@3.25.32))
5242 - '@langchain/langgraph-checkpoint': 0.0.17(@langchain/core@0.3.57(openai@4.103.0(zod@3.25.32)))
5243 - '@langchain/langgraph-sdk': 0.0.78(@langchain/core@0.3.57(openai@4.103.0(zod@3.25.32)))(react@19.1.0)
5235 + '@langchain/core': 0.3.56(openai@4.98.0(encoding@0.1.13)(zod@3.24.4))
5236 + '@langchain/langgraph-checkpoint': 0.0.17(@langchain/core@0.3.56(openai@4.98.0(encoding@0.1.13)(zod@3.24.4)))
5237 + '@langchain/langgraph-sdk': 0.0.74(@langchain/core@0.3.56(openai@4.98.0(encoding@0.1.13)(zod@3.24.4)))(react@19.1.0)
5238 uuid: 10.0.0
5239 zod: 3.25.32
5240 optionalDependencies:
@@ -5250,7 +5244,7 @@ snapshots:
5244
5245 '@langchain/openai@0.5.11(@langchain/core@0.3.57(openai@4.103.0(zod@3.25.32)))':
5246 dependencies:
5253 - '@langchain/core': 0.3.57(openai@4.103.0(zod@3.25.32))
5247 + '@langchain/core': 0.3.56(openai@4.98.0(encoding@0.1.13)(zod@3.24.4))
5248 js-tiktoken: 1.0.20
5249 openai: 4.103.0(zod@3.25.32)
5250 zod: 3.25.32
@@ -7635,7 +7629,7 @@ snapshots:
7629 dependencies:
7630 json-buffer: 3.0.1
7631
7638 - langsmith@0.3.29(openai@4.103.0(zod@3.25.32)):
7632 + langsmith@0.3.29(openai@4.98.0(encoding@0.1.13)(zod@3.24.4)):
7633 dependencies:
7634 '@types/uuid': 10.0.0
7635 chalk: 4.1.2