Skip to content

Commit

Permalink
Merge branch 'next' into feat-new-integrations-page-table
Browse files Browse the repository at this point in the history
  • Loading branch information
scopsy committed Dec 18, 2024
2 parents b17543a + 32ef340 commit baa0df3
Show file tree
Hide file tree
Showing 62 changed files with 1,521 additions and 384 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Instrument, InstrumentUsecase } from '@novu/application-generic';
import isEmpty from 'lodash/isEmpty';
import { FullPayloadForRender, RenderCommand } from './render-command';
import { ExpandEmailEditorSchemaUsecase } from './expand-email-editor-schema.usecase';
import { EmailStepControlZodSchema } from '../../../workflows-v2/shared';
import { emailStepControlZodSchema } from '../../../workflows-v2/shared';

export class RenderEmailOutputCommand extends RenderCommand {}

Expand All @@ -15,7 +15,7 @@ export class RenderEmailOutputUsecase {

@InstrumentUsecase()
async execute(renderCommand: RenderEmailOutputCommand): Promise<EmailRenderOutput> {
const { body, subject } = EmailStepControlZodSchema.parse(renderCommand.controlValues);
const { body, subject } = emailStepControlZodSchema.parse(renderCommand.controlValues);

if (isEmpty(body)) {
return { subject, body: '' };
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/app/workflows-v2/e2e/generate-preview.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('Workflow Step Preview - POST /:workflowId/step/:stepId/preview', () =>
preview: {
subject: 'Welcome {{subscriber.firstName}}',
// cspell:disable-next-line
body: 'Hello {{subscriber.firstName}} {{subscriber.lastName}}, Welcome to {{PAYLOAD.ORGANIZATIONNAME | UPCASE}}!',
body: 'Hello {{subscriber.firstName}} {{subscriber.lastName}}, Welcome to {{PAYLOAD.ORGANIZATIONNAME}}!',
},
type: 'in_app',
},
Expand All @@ -69,7 +69,7 @@ describe('Workflow Step Preview - POST /:workflowId/step/:stepId/preview', () =>
lastName: '{{subscriber.lastName}}',
},
payload: {
organizationName: '{{payload.organizationName | upcase}}',
organizationName: '{{payload.organizationName}}',
},
},
},
Expand Down
27 changes: 3 additions & 24 deletions apps/api/src/app/workflows-v2/generate-preview.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,9 @@ describe('Generate Preview', () => {
if (previewResponseDto.result!.type !== 'sms') {
throw new Error('Expected sms');
}
expect(previewResponseDto.result!.preview.body).to.contain('{{PAYLOAD.VARIABLENAME | UPCASE}}');
expect(previewResponseDto.result!.preview.body).to.contain('{{PAYLOAD.VARIABLENAME}}');
expect(previewResponseDto.previewPayloadExample).to.exist;
expect(previewResponseDto?.previewPayloadExample?.payload?.variableName).to.equal(
'{{payload.variableName | upcase}}'
);
expect(previewResponseDto?.previewPayloadExample?.payload?.variableName).to.equal('{{payload.variableName}}');
});

it('Should not fail if inApp is providing partial URL in redirect', async () => {
Expand Down Expand Up @@ -413,26 +411,7 @@ describe('Generate Preview', () => {
);

if (generatePreviewResponseDto.result?.type === ChannelTypeEnum.IN_APP) {
expect(generatePreviewResponseDto.result.preview.body).to.equal(
{
subject: `{{subscriber.firstName}} Hello, World! ${PLACEHOLDER_SUBJECT_INAPP}`,
body: `Hello, World! {{payload.placeholder.body}}`,
avatar: 'https://www.example.com/avatar.png',
primaryAction: {
label: '{{payload.secondaryUrl}}',
redirect: {
target: RedirectTargetEnum.BLANK,
},
},
secondaryAction: null,
redirect: {
target: RedirectTargetEnum.BLANK,
url: ' ',
},
}.body
);
expect(generatePreviewResponseDto.result.preview.primaryAction?.redirect?.url).to.be.ok;
expect(generatePreviewResponseDto.result.preview.primaryAction?.redirect?.url).to.contain('https');
expect(generatePreviewResponseDto.result.preview.body).to.equal('Hello, World! {{payload.placeholder.body}}');
}
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { JSONSchemaDto, UiComponentEnum, UiSchema, UiSchemaGroupEnum } from '@novu/shared';

import { z } from 'zod';
import { zodToJsonSchema } from 'zod-to-json-schema';
import { skipControl } from './skip-control.schema';
import { TipTapSchema } from '../../../environments-v1/usecases/output-renderers';

export const EmailStepControlZodSchema = z
export const emailStepControlZodSchema = z
.object({
skip: skipControl.schema,
/*
* todo: we need to validate the email editor (body) by type and not string,
* updating it to TipTapSchema will break the existing upsert issues generation
*/
body: z.string().optional().default(''),
subject: z.string().optional().default(''),
})
.strict();

export const emailStepControlSchema = zodToJsonSchema(EmailStepControlZodSchema) as JSONSchemaDto;

export type EmailStepControlType = z.infer<typeof EmailStepControlZodSchema>;
export const emailStepControlSchema = zodToJsonSchema(emailStepControlZodSchema) as JSONSchemaDto;
export type EmailStepControlType = z.infer<typeof emailStepControlZodSchema>;

export const emailStepUiSchema: UiSchema = {
group: UiSchemaGroupEnum.EMAIL,
Expand All @@ -28,3 +31,8 @@ export const emailStepUiSchema: UiSchema = {
skip: skipControl.uiSchema.properties.skip,
},
};

export const emailStepControl = {
uiSchema: emailStepUiSchema,
schema: emailStepControlSchema,
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ActionStepEnum, ChannelStepEnum, channelStepSchemas } from '@novu/framework/internal';
import { ActionStepEnum, ChannelStepEnum } from '@novu/framework/internal';
import { ControlSchemas, JSONSchemaDto } from '@novu/shared';
import { emailStepControlSchema, emailStepUiSchema, inAppControlSchema, inAppUiSchema } from './schemas';
import { emailStepControl, inAppControlSchema, inAppUiSchema } from './schemas';
import { DelayTimeControlSchema, delayUiSchema } from './schemas/delay-control.schema';
import { DigestOutputJsonSchema, digestUiSchema } from './schemas/digest-control.schema';
import { smsStepControl } from './schemas/sms-control.schema';
Expand All @@ -20,8 +20,8 @@ export const stepTypeToControlSchema: Record<ChannelStepEnum | ActionStepEnum, C
uiSchema: inAppUiSchema,
},
[ChannelStepEnum.EMAIL]: {
schema: emailStepControlSchema,
uiSchema: emailStepUiSchema,
schema: emailStepControl.schema,
uiSchema: emailStepControl.uiSchema,
},
[ChannelStepEnum.SMS]: {
schema: smsStepControl.schema,
Expand Down
Loading

0 comments on commit baa0df3

Please sign in to comment.