diff --git a/packages/cli/src/services/hooks.service.ts b/packages/cli/src/services/hooks.service.ts index 16ccb6b354..53be3e244e 100644 --- a/packages/cli/src/services/hooks.service.ts +++ b/packages/cli/src/services/hooks.service.ts @@ -18,6 +18,7 @@ import type { Settings } from '@db/entities/Settings'; import { UserService } from '@/services/user.service'; import type { AuthenticatedRequest } from '@/requests'; import type { Invitation } from '@/Interfaces'; +import RudderStack, { type constructorOptions } from '@rudderstack/rudder-sdk-node'; /** * Exposes functionality to be used by the cloud BE hooks. @@ -106,6 +107,10 @@ export class HooksService { return await this.authService.authMiddleware(req, res, next); } + getRudderStackClient(key: string, options: constructorOptions): RudderStack { + return new RudderStack(key, options); + } + /** * Return repositories to be used in the hooks * 1. Some self-hosted users rely in the repositories to interact with the DB directly diff --git a/packages/cli/test/unit/services/hooks.service.test.ts b/packages/cli/test/unit/services/hooks.service.test.ts index 406ede0374..061d087b85 100644 --- a/packages/cli/test/unit/services/hooks.service.test.ts +++ b/packages/cli/test/unit/services/hooks.service.test.ts @@ -12,6 +12,9 @@ import { HooksService } from '@/services/hooks.service'; import type { Invitation } from '@/Interfaces'; import type { AuthenticatedRequest } from '@/requests'; import type { AuthUserRepository } from '@/databases/repositories/authUser.repository'; +import RudderStack from '@rudderstack/rudder-sdk-node'; + +jest.mock('@rudderstack/rudder-sdk-node'); describe('HooksService', () => { const mockedUser = mock(); @@ -148,4 +151,14 @@ describe('HooksService', () => { expect(collections).toHaveProperty('Credentials'); expect(collections).toHaveProperty('Workflow'); }); + + it('hooksService.getRudderStackClient', async () => { + // ACT + const key = 'TEST'; + const opts = { dataPlaneUrl: 'test.com' }; + const client = hooksService.getRudderStackClient(key, opts); + + expect(client instanceof RudderStack).toBeTruthy(); + expect(RudderStack).toHaveBeenCalledWith(key, opts); + }); });