Skip to content

Commit

Permalink
chore: used workflow shared interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
djabarovgeorge committed Sep 12, 2023
1 parent e8131d5 commit c1f0ee4
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 32 deletions.
3 changes: 3 additions & 0 deletions apps/api/src/app/shared/dtos/message-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@ export class MessageTemplate {
type: ActorTypeEnum;
data: string | null;
};

@IsOptional()
_creatorId: string;
}
9 changes: 5 additions & 4 deletions apps/api/src/app/shared/helpers/content.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '@novu/shared';
import Handlebars from 'handlebars';
import { ApiException } from '../exceptions/api.exception';
import { NotificationStep } from '../../workflows/usecases/create-notification-template';

export class ContentService {
replaceVariables(content: string, variables: { [key: string]: string }) {
Expand All @@ -41,7 +42,7 @@ export class ContentService {
}
}

extractMessageVariables(messages: INotificationTemplateStep[]): {
extractMessageVariables(messages: NotificationStep[]): {
variables: IMustacheVariable[];
reservedVariables: ITriggerReservedVariable[];
} {
Expand All @@ -68,7 +69,7 @@ export class ContentService {
};
}

extractStepVariables(messages: INotificationTemplateStep[]): IMustacheVariable[] {
extractStepVariables(messages: NotificationStep[]): IMustacheVariable[] {
const variables: IMustacheVariable[] = [];

for (const message of messages) {
Expand Down Expand Up @@ -116,7 +117,7 @@ export class ContentService {
return reservedVariables;
}

extractSubscriberMessageVariables(messages: INotificationTemplateStep[]): string[] {
extractSubscriberMessageVariables(messages: NotificationStep[]): string[] {
const variables: string[] = [];

const hasSmsMessage = !!messages.find((i) => i.template?.type === StepTypeEnum.SMS);
Expand All @@ -132,7 +133,7 @@ export class ContentService {
return Array.from(new Set(variables));
}

private *messagesTextIterator(messages: INotificationTemplateStep[]): Generator<string> {
private *messagesTextIterator(messages: NotificationStep[]): Generator<string> {
for (const message of messages) {
if (!message.template) continue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export class ChannelCTACommand {
}

export class NotificationStep {
@IsString()
@IsOptional()
_templateId?: string;

@ValidateNested()
@IsOptional()
template?: MessageTemplate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class UpdateNotificationTemplateCommand extends EnvironmentWithUserComman
@IsArray()
@ValidateNested()
@IsOptional()
steps?: Array<NotificationStep & { _templateId?: string }>;
steps?: NotificationStep[];

@ValidateNested()
@IsOptional()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export class UpdateNotificationTemplate {
return notificationTemplate;
}

private getRemovedSteps(existingSteps: NotificationStepEntity[], newSteps: INotificationTemplateStep[]) {
private getRemovedSteps(existingSteps: NotificationStepEntity[], newSteps: NotificationStep[]) {
const existingStepsIds = existingSteps.map((i) => i._templateId);
const newStepsIds = newSteps.map((i) => i._templateId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useEffect, useState } from 'react';
import { EmailCustomCodeEditor } from '../email-editor/EmailCustomCodeEditor';
import { When } from '../../../../components/utils/When';
import Handlebars from 'handlebars/dist/handlebars';
import { IMessageAction } from '@novu/shared';

export function InAppEditorBlock({
control,
Expand All @@ -28,7 +29,7 @@ export function InAppEditorBlock({
return (
<Controller
name={`steps.${index}.template.cta.action`}
defaultValue=""
defaultValue={{} as IMessageAction}
data-test-id="in-app-content-form-item"
control={control}
render={({ field }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function ActionBlockContainer({
onRemoveTemplate: () => void;
isButtonsTemplateSelected: boolean;
onChange: (data: any) => void;
value: IMessageAction;
value: IMessageAction | undefined;
readonly: boolean;
}) {
return (
Expand All @@ -45,7 +45,7 @@ export function ActionBlockContainer({
}

interface ISelectedButtonTemplateProps {
value: IMessageAction;
value?: IMessageAction;
onRemoveTemplate: () => void;
onChange: (actions: any) => void;
readonly: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function InAppWidgetPreview({
readonly: boolean;
preview?: boolean;
children: JSX.Element;
value: IMessageAction;
value: IMessageAction | undefined;
onChange: (data: any) => void;
index: number;
enableAvatar: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const mapToInAppFormStep = (item: INotificationTemplateStep): IFormStep => ({
cta: {
data: item?.template?.cta?.data ?? { url: '' },
type: ChannelCTATypeEnum.REDIRECT,
action: item?.template?.cta?.action ?? '',
...(item?.template?.cta?.action ? { action: item?.template?.cta?.action } : {}),
},
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { StepTypeEnum, IMessageCTA, IActor } from '@novu/shared';
import {
StepTypeEnum,
IMessageCTA,
IActor,
EnvironmentId,
OrganizationId,
MessageTemplateContentType,
} from '@novu/shared';

import { IEmailBlock, ITemplateVariable } from './types';
import type { OrganizationId } from '../organization';
import type { EnvironmentId } from '../environment';
import type { ChangePropsValueType } from '../../types/helpers';

export class MessageTemplateEntity {
Expand All @@ -15,15 +20,15 @@ export class MessageTemplateEntity {
_creatorId: string;

// TODO: Due a circular dependency I can't import LayoutId from Layout.
_layoutId: string | null;
_layoutId?: string;

type: StepTypeEnum;

variables?: ITemplateVariable[];

content: string | IEmailBlock[];

contentType?: 'editor' | 'customHtml';
contentType?: MessageTemplateContentType;

active?: boolean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import {
TemplateVariableTypeEnum,
NotificationTemplateCustomData,
TriggerContextTypeEnum,
INotificationTemplate,
INotificationTemplateStep,
IStepVariant,
INotificationTrigger,
TriggerTypeEnum,
} from '@novu/shared';

import { MessageTemplateEntity } from '../message-template';
Expand All @@ -16,7 +21,7 @@ import type { OrganizationId } from '../organization';
import type { EnvironmentId } from '../environment';
import type { ChangePropsValueType } from '../../types';

export class NotificationTemplateEntity {
export class NotificationTemplateEntity implements INotificationTemplate {
_id: string;

name: string;
Expand Down Expand Up @@ -73,8 +78,8 @@ export type NotificationTemplateDBModel = ChangePropsValueType<
_parentId?: Types.ObjectId;
};

export class NotificationTriggerEntity {
type: 'event';
export class NotificationTriggerEntity implements INotificationTrigger {
type: TriggerTypeEnum;

identifier: string;

Expand All @@ -85,7 +90,7 @@ export class NotificationTriggerEntity {
reservedVariables?: ITriggerReservedVariable[];
}

export class StepVariantEntity {
export class StepVariantEntity implements IStepVariant {
_id?: string;

uuid?: string;
Expand All @@ -112,7 +117,7 @@ export class StepVariantEntity {
shouldStopOnFail?: boolean;
}

export class NotificationStepEntity extends StepVariantEntity {
export class NotificationStepEntity extends StepVariantEntity implements INotificationTemplateStep {
variants?: StepVariantEntity[];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import {
ActorTypeEnum,
ChannelCTATypeEnum,
EnvironmentId,
IEmailBlock,
ITemplateVariable,
OrganizationId,
StepTypeEnum,
TemplateVariableTypeEnum,
} from '../../types';
import { TriggerContextTypeEnum } from '../notification-template';
import { IActor } from '../messages';

export type MessageTemplateContentType = 'editor' | 'customHtml';

export interface IMessageTemplate {
_id?: string;
_environmentId?: EnvironmentId;
_organizationId?: OrganizationId;
_creatorId?: string;
_feedId?: string;
_layoutId?: string;
_parentId?: string;
subject?: string;
name?: string;
title?: string;
Expand All @@ -21,20 +29,16 @@ export interface IMessageTemplate {
variables?: ITemplateVariable[];
cta?: {
type: ChannelCTATypeEnum;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data: any;
data: {
url?: string;
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
action?: any;
};
_feedId?: string;
_layoutId?: string;
active?: boolean;
preheader?: string;
senderName?: string;
actor?: {
type: ActorTypeEnum;
data: string | null;
};
actor?: IActor;
}

// eslint-disable-next-line @typescript-eslint/naming-convention
Expand Down
2 changes: 1 addition & 1 deletion libs/shared/src/entities/messages/messages.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface IMessage {
lastSeenDate: string;
lastReadDate: string;
createdAt: string;
cta: IMessageCTA;
cta?: IMessageCTA;
_feedId: string;
_layoutId?: string;
payload: Record<string, unknown>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export interface INotificationTriggerVariable {
type?: TemplateVariableTypeEnum;
}

export interface INotificationTemplateStep {
export interface IStepVariant {
_id?: string;
uuid?: string;
name?: string;
Expand All @@ -71,6 +71,10 @@ export interface INotificationTemplateStep {
metadata?: IWorkflowStepMetadata;
}

export interface INotificationTemplateStep extends IStepVariant {
variants?: IStepVariant[];
}

export interface IMessageFilter {
isNegated?: boolean;
type?: BuilderFieldType;
Expand Down

0 comments on commit c1f0ee4

Please sign in to comment.