From aeae66dd2896253fe594a0a0bff585279cffc608 Mon Sep 17 00:00:00 2001 From: Richard Fontein <32132657+rifont@users.noreply.github.com> Date: Thu, 7 Nov 2024 00:51:32 +0100 Subject: [PATCH 01/12] refactor(client): make addWorkflows async --- packages/framework/src/client.test.ts | 76 ++++----- packages/framework/src/client.ts | 9 +- .../framework/src/client.validation.test.ts | 8 +- packages/framework/src/handler.ts | 4 +- .../workflow/discover-action-step-factory.ts | 12 +- .../workflow/discover-channel-step-factory.ts | 12 +- .../workflow/discover-custom-step-factory.ts | 13 +- .../resources/workflow/discover-providers.ts | 8 +- .../src/resources/workflow/discover-step.ts | 6 +- .../resources/workflow/workflow.resource.ts | 146 +++++++++--------- .../src/resources/workflow/workflow.test.ts | 12 +- .../framework/src/types/discover.types.ts | 2 +- .../framework/src/types/validator.types.ts | 2 +- .../src/validators/base.validator.ts | 2 +- .../src/validators/json-schema.validator.ts | 2 +- .../src/validators/validator.test.ts | 8 +- .../framework/src/validators/zod.validator.ts | 5 +- 17 files changed, 173 insertions(+), 154 deletions(-) diff --git a/packages/framework/src/client.test.ts b/packages/framework/src/client.test.ts index cb7a7fa78e4..45c380b0d16 100644 --- a/packages/framework/src/client.test.ts +++ b/packages/framework/src/client.test.ts @@ -25,7 +25,7 @@ describe('Novu Client', () => { }); client = new Client({ secretKey: 'some-secret-key' }); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); }); describe('client constructor', () => { @@ -184,7 +184,7 @@ describe('Novu Client', () => { })); }); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); // wait for discovery to finish await new Promise((resolve) => { @@ -300,7 +300,7 @@ describe('Novu Client', () => { ); }); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const discovery = client.discover(); expect(discovery.workflows).toHaveLength(2); @@ -354,7 +354,7 @@ describe('Novu Client', () => { } ); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const emailEvent: Event = { action: PostActionEnum.PREVIEW, @@ -380,7 +380,7 @@ describe('Novu Client', () => { it('should sanitize the step result of all delivery channel step types', async () => { const script = ``; - client.addWorkflows([ + await client.addWorkflows([ workflow('test-workflow', async ({ step }) => { await step.email('send-email', async () => ({ body: `Start of body. ${script}`, @@ -408,7 +408,7 @@ describe('Novu Client', () => { it('should not sanitize the step result of custom step type', async () => { const script = ``; - client.addWorkflows([ + await client.addWorkflows([ workflow('test-workflow', async ({ step }) => { await step.custom( 'send-email', @@ -467,7 +467,7 @@ describe('Novu Client', () => { controls: {}, }; - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const emailExecutionResult = await client.executeWorkflow(emailEvent); @@ -563,7 +563,7 @@ describe('Novu Client', () => { } ); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const emailEvent: Event = { action: PostActionEnum.EXECUTE, @@ -632,7 +632,7 @@ describe('Novu Client', () => { } ); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const event: Event = { action: PostActionEnum.EXECUTE, @@ -698,7 +698,7 @@ describe('Novu Client', () => { } ); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const event: Event = { action: PostActionEnum.EXECUTE, @@ -761,7 +761,7 @@ describe('Novu Client', () => { } ); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const event: Event = { action: PostActionEnum.EXECUTE, @@ -824,7 +824,7 @@ describe('Novu Client', () => { } ); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const event: Event = { action: PostActionEnum.EXECUTE, @@ -887,7 +887,7 @@ describe('Novu Client', () => { } ); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const event: Event = { action: PostActionEnum.EXECUTE, @@ -934,7 +934,7 @@ describe('Novu Client', () => { ); }); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const event: Event = { action: PostActionEnum.EXECUTE, @@ -980,7 +980,7 @@ describe('Novu Client', () => { ); }); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const emailEvent: Event = { action: PostActionEnum.EXECUTE, @@ -1029,7 +1029,7 @@ describe('Novu Client', () => { ); }); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const emailEvent: Event = { action: PostActionEnum.EXECUTE, @@ -1060,7 +1060,7 @@ describe('Novu Client', () => { await step.email('send-email', async () => ({ body: 'Test Body', subject: 'Subject' })); }); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const event: Event = { action: PostActionEnum.EXECUTE, @@ -1099,7 +1099,7 @@ describe('Novu Client', () => { }); }); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const event: Event = { action: PostActionEnum.EXECUTE, @@ -1152,7 +1152,7 @@ describe('Novu Client', () => { }); }); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const event: Event = { action: PostActionEnum.EXECUTE, @@ -1206,7 +1206,7 @@ describe('Novu Client', () => { }); }); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const event: Event = { action: PostActionEnum.EXECUTE, @@ -1248,7 +1248,7 @@ describe('Novu Client', () => { await step.email('inactive-step-id', async () => ({ body: 'Test Body', subject: 'Subject' })); }); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const event: Event = { action: PostActionEnum.EXECUTE, @@ -1276,7 +1276,7 @@ describe('Novu Client', () => { }); }); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const event: Event = { action: PostActionEnum.EXECUTE, @@ -1305,7 +1305,7 @@ describe('Novu Client', () => { }); }); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const event: Event = { action: PostActionEnum.EXECUTE, @@ -1343,7 +1343,7 @@ describe('Novu Client', () => { }); }); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const event: Event = { action: PostActionEnum.EXECUTE, @@ -1377,7 +1377,7 @@ describe('Novu Client', () => { } ); - client.addWorkflows([workflowMock]); + await client.addWorkflows([workflowMock]); const event: Event = { action: PostActionEnum.PREVIEW, @@ -1401,7 +1401,7 @@ describe('Novu Client', () => { await step.email('send-email', async () => ({ body: 'Test Body', subject: 'Subject' })); }); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const event: Event = { action: PostActionEnum.PREVIEW, @@ -1440,7 +1440,7 @@ describe('Novu Client', () => { }); }); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const event: Event = { action: PostActionEnum.PREVIEW, @@ -1490,7 +1490,7 @@ describe('Novu Client', () => { await step.email('send-email', async () => ({ body: 'Test Body', subject: 'Subject' })); }); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); // @ts-expect-error - no workflow id const event2: Event = { @@ -1507,7 +1507,7 @@ describe('Novu Client', () => { await step.email('send-email', async () => ({ body: 'Test Body', subject: 'Subject' })); }); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const event: Event = { action: PostActionEnum.EXECUTE, @@ -1527,7 +1527,7 @@ describe('Novu Client', () => { await step.email('send-email', async () => ({ body: 'Test Body', subject: 'Subject' })); }); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); // @ts-expect-error - no action const event: Event = { @@ -1548,7 +1548,7 @@ describe('Novu Client', () => { }); }); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const event: Event = { action: PostActionEnum.EXECUTE, @@ -1585,7 +1585,7 @@ describe('Novu Client', () => { ); }); - client.addWorkflows([newWorkflow]); + await client.addWorkflows([newWorkflow]); const event: Event = { action: PostActionEnum.EXECUTE, @@ -1605,7 +1605,7 @@ describe('Novu Client', () => { it('should sanitize the step output of all channel step types by default', async () => { const script = ``; - client.addWorkflows([ + await client.addWorkflows([ workflow('test-workflow', async ({ step }) => { await step.email('send-email', async () => ({ body: `Start of body. ${script}`, @@ -1633,7 +1633,7 @@ describe('Novu Client', () => { it('should sanitize the step output of channel step types when `disableOutputSanitization: false`', async () => { const script = ``; - client.addWorkflows([ + await client.addWorkflows([ workflow('test-workflow', async ({ step }) => { await step.email( 'send-email', @@ -1668,7 +1668,7 @@ describe('Novu Client', () => { const link = '/pipeline/Oee4d54-ca52-4d70-86b3-cd10a67b6810/requirements?requirementId=dc25a578-ecf1-4835-9310-2236f8244bd&commentId=e259b16b-68f9-43af-b252-fce68bc7cb2f'; - client.addWorkflows([ + await client.addWorkflows([ workflow('test-workflow', async ({ step }) => { await step.inApp( 'send-inapp', @@ -1704,7 +1704,7 @@ describe('Novu Client', () => { it('should not sanitize the step result of custom step type', async () => { const script = `