-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Gosha <[email protected]>
- Loading branch information
1 parent
f068ac9
commit 8f5cc6e
Showing
6 changed files
with
256 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,102 @@ | ||
import { JSONSchema } from 'json-schema-to-ts'; | ||
import { StepType } from '@novu/shared'; | ||
|
||
import { ActionStepEnum, ChannelStepEnum } from '@novu/framework/internal'; | ||
|
||
const chatProperties = { | ||
body: { type: 'chatBody' }, | ||
}; | ||
|
||
const emailProperties = { | ||
subject: { type: 'emailSubject' }, | ||
body: { type: 'emailBody' }, | ||
}; | ||
|
||
const inAppProperties = { | ||
subject: { type: 'inAppSubject' }, | ||
body: { type: 'inAppBody' }, | ||
avatar: { type: 'inAppAvatar' }, | ||
primaryAction: { type: 'inAppPrimaryAction' }, | ||
secondaryAction: { type: 'inAppSecondaryAction' }, | ||
data: { type: 'inAppData' }, | ||
redirect: { type: 'inAppRedirect' }, | ||
}; | ||
|
||
const pushProperties = { | ||
subject: { type: 'pushSubject' }, | ||
body: { type: 'pushBody' }, | ||
}; | ||
|
||
const smsProperties = { | ||
body: { type: 'smsBody' }, | ||
}; | ||
|
||
const delayProperties = { | ||
type: { type: 'delayType' }, | ||
amount: { type: 'delayAmount' }, | ||
unit: { type: 'delayUnit' }, | ||
}; | ||
|
||
const digestProperties = { | ||
amount: { type: 'digestAmount' }, | ||
unit: { type: 'digestUnit' }, | ||
digestKey: { type: 'digestKey' }, | ||
lookBackWindow: { type: 'digestLookBackWindow' }, | ||
}; | ||
|
||
const customProperties = {}; | ||
|
||
export type UiSchema = | ||
| { | ||
type: 'email'; | ||
properties: typeof emailProperties; | ||
} | ||
| { | ||
type: 'sms'; | ||
properties: typeof smsProperties; | ||
} | ||
| { | ||
type: 'push'; | ||
properties: typeof pushProperties; | ||
} | ||
| { | ||
type: 'chat'; | ||
properties: typeof chatProperties; | ||
} | ||
| { | ||
type: 'in_app'; | ||
properties: typeof inAppProperties; | ||
} | ||
| { | ||
type: 'delay'; | ||
properties: typeof delayProperties; | ||
} | ||
| { | ||
type: 'digest'; | ||
properties: typeof digestProperties; | ||
} | ||
| { | ||
type: 'custom'; | ||
properties: typeof customProperties; | ||
}; | ||
|
||
export const mapStepTypeToUiSchema = { | ||
[ChannelStepEnum.SMS]: { type: 'sms', properties: smsProperties }, | ||
[ChannelStepEnum.EMAIL]: { type: 'email', properties: emailProperties }, | ||
[ChannelStepEnum.PUSH]: { type: 'push', properties: pushProperties }, | ||
[ChannelStepEnum.CHAT]: { type: 'chat', properties: chatProperties }, | ||
[ChannelStepEnum.IN_APP]: { type: 'in_app', properties: inAppProperties }, | ||
[ActionStepEnum.DELAY]: { type: 'delay', properties: delayProperties }, | ||
[ActionStepEnum.DIGEST]: { type: 'digest', properties: digestProperties }, | ||
[ActionStepEnum.CUSTOM]: { type: 'custom', properties: customProperties }, | ||
} as const satisfies Record<ChannelStepEnum | ActionStepEnum, UiSchema>; | ||
|
||
export class ControlsDto { | ||
schema: JSONSchema; | ||
uiSchema: UiSchema; | ||
} | ||
|
||
export type StepSchemaDto = { | ||
controls: JSONSchema; | ||
controls: ControlsDto; | ||
variables: JSONSchema; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 41 additions & 8 deletions
49
apps/api/src/app/step-schemas/shared/mappers/map-step-type-to-output.mapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,45 @@ | ||
import { ActionStepEnum, actionStepSchemas, ChannelStepEnum, channelStepSchemas } from '@novu/framework/internal'; | ||
import { EmailStepControlSchema } from '@novu/shared'; | ||
import { ControlsDto, mapStepTypeToUiSchema } from '../../dtos/step-schema.dto'; | ||
|
||
export const mapStepTypeToOutput = { | ||
[ChannelStepEnum.SMS]: channelStepSchemas[ChannelStepEnum.SMS].output, | ||
[ChannelStepEnum.EMAIL]: EmailStepControlSchema, | ||
[ChannelStepEnum.PUSH]: channelStepSchemas[ChannelStepEnum.PUSH].output, | ||
[ChannelStepEnum.CHAT]: channelStepSchemas[ChannelStepEnum.CHAT].output, | ||
[ChannelStepEnum.IN_APP]: channelStepSchemas[ChannelStepEnum.IN_APP].output, | ||
[ActionStepEnum.DELAY]: actionStepSchemas[ActionStepEnum.DELAY].output, | ||
[ActionStepEnum.DIGEST]: actionStepSchemas[ActionStepEnum.DIGEST].output, | ||
export const PERMISSIVE_EMPTY_SCHEMA = { | ||
type: 'object', | ||
properties: {}, | ||
required: [], | ||
additionalProperties: true, | ||
} as const; | ||
|
||
export const mapStepTypeToControlSchema: Record<ChannelStepEnum | ActionStepEnum, ControlsDto> = { | ||
[ChannelStepEnum.SMS]: { | ||
schema: channelStepSchemas[ChannelStepEnum.SMS].output, | ||
uiSchema: mapStepTypeToUiSchema[ChannelStepEnum.SMS], | ||
}, | ||
[ChannelStepEnum.EMAIL]: { | ||
schema: EmailStepControlSchema, | ||
uiSchema: mapStepTypeToUiSchema[ChannelStepEnum.EMAIL], | ||
}, | ||
[ChannelStepEnum.PUSH]: { | ||
schema: channelStepSchemas[ChannelStepEnum.PUSH].output, | ||
uiSchema: mapStepTypeToUiSchema[ChannelStepEnum.PUSH], | ||
}, | ||
[ChannelStepEnum.CHAT]: { | ||
schema: channelStepSchemas[ChannelStepEnum.CHAT].output, | ||
uiSchema: mapStepTypeToUiSchema[ChannelStepEnum.CHAT], | ||
}, | ||
[ChannelStepEnum.IN_APP]: { | ||
schema: channelStepSchemas[ChannelStepEnum.IN_APP].output, | ||
uiSchema: mapStepTypeToUiSchema[ChannelStepEnum.IN_APP], | ||
}, | ||
[ActionStepEnum.DELAY]: { | ||
schema: actionStepSchemas[ActionStepEnum.DELAY].output, | ||
uiSchema: mapStepTypeToUiSchema[ActionStepEnum.DELAY], | ||
}, | ||
[ActionStepEnum.DIGEST]: { | ||
schema: actionStepSchemas[ActionStepEnum.DIGEST].output, | ||
uiSchema: mapStepTypeToUiSchema[ActionStepEnum.DIGEST], | ||
}, | ||
[ActionStepEnum.CUSTOM]: { | ||
schema: PERMISSIVE_EMPTY_SCHEMA, | ||
uiSchema: mapStepTypeToUiSchema[ActionStepEnum.CUSTOM], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.