Skip to content

Commit

Permalink
feat(api): add push schema
Browse files Browse the repository at this point in the history
  • Loading branch information
djabarovgeorge committed Dec 9, 2024
1 parent 6ec90ed commit 62fea98
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { z } from 'zod';
import { zodToJsonSchema } from 'zod-to-json-schema';

import { JSONSchemaDto, UiComponentEnum, UiSchema, UiSchemaGroupEnum } from '@novu/shared';

export const PushStepControlZodSchema = z
.object({
subject: z.string(),
body: z.string(),
})
.strict();

export type PushStepControlType = z.infer<typeof PushStepControlZodSchema>;

export const pushStepControlSchema = zodToJsonSchema(PushStepControlZodSchema) as JSONSchemaDto;
export const pushStepUiSchema: UiSchema = {
group: UiSchemaGroupEnum.PUSH,
properties: {
subject: {
component: UiComponentEnum.PUSH_SUBJECT,
},
body: {
component: UiComponentEnum.PUSH_BODY,
},
},
};

export const pushStepControl = {
uiSchema: pushStepUiSchema,
schema: pushStepControlSchema,
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { emailStepControlSchema, emailStepUiSchema, inAppControlSchema, inAppUiS
import { DelayTimeControlSchema, delayUiSchema } from './schemas/delay-control.schema';
import { DigestOutputJsonSchema, digestUiSchema } from './schemas/digest-control.schema';
import { smsStepControl } from './schemas/sms-control.schema';
import { pushStepControl } from './schemas/push-control.schema';

export const PERMISSIVE_EMPTY_SCHEMA = {
type: 'object',
Expand All @@ -29,7 +30,8 @@ export const stepTypeToControlSchema: Record<ChannelStepEnum | ActionStepEnum, C
schema: channelStepSchemas[ChannelStepEnum.PUSH].output as unknown as JSONSchemaDto,
},
[ChannelStepEnum.CHAT]: {
schema: channelStepSchemas[ChannelStepEnum.CHAT].output as unknown as JSONSchemaDto,
schema: pushStepControl.schema,
uiSchema: pushStepControl.uiSchema,
},
[ActionStepEnum.DELAY]: {
schema: DelayTimeControlSchema,
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/src/dto/workflows/step-data.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export enum UiSchemaGroupEnum {
DIGEST = 'DIGEST',
DELAY = 'DELAY',
SMS = 'SMS',
PUSH = 'PUSH',
}

export enum UiComponentEnum {
Expand All @@ -40,6 +41,8 @@ export enum UiComponentEnum {
DELAY_AMOUNT = 'DELAY_AMOUNT',
DELAY_UNIT = 'DELAY_UNIT',
SMS_BODY = 'SMS_BODY',
PUSH_BODY = 'PUSH_BODY',
PUSH_SUBJECT = 'PUSH_SUBJECT',
}

export class UiSchemaProperty {
Expand Down

0 comments on commit 62fea98

Please sign in to comment.