Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move create workflow to app gen package #5396

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .source
28 changes: 12 additions & 16 deletions apps/api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,19 @@ import { ProductFeatureInterceptor } from './app/shared/interceptors/product-fea

const enterpriseImports = (): Array<Type | DynamicModule | Promise<DynamicModule> | ForwardReference> => {
const modules: Array<Type | DynamicModule | Promise<DynamicModule> | ForwardReference> = [];
try {
if (process.env.NOVU_ENTERPRISE === 'true' || process.env.CI_EE_TEST === 'true') {
if (require('@novu/ee-auth')?.EEAuthModule) {
modules.push(require('@novu/ee-auth')?.EEAuthModule);
}
if (require('@novu/ee-chimera')?.ChimeraModule) {
modules.push(require('@novu/ee-chimera')?.ChimeraModule);
}
if (require('@novu/ee-translation')?.EnterpriseTranslationModule) {
modules.push(require('@novu/ee-translation')?.EnterpriseTranslationModule);
}
if (require('@novu/ee-billing')?.BillingModule) {
modules.push(require('@novu/ee-billing')?.BillingModule.forRoot());
}
if (process.env.NOVU_ENTERPRISE === 'true' || process.env.CI_EE_TEST === 'true') {
if (require('@novu/ee-auth')?.EEAuthModule) {
modules.push(require('@novu/ee-auth')?.EEAuthModule);
}
if (require('@novu/ee-chimera')?.ChimeraModule) {
modules.push(require('@novu/ee-chimera')?.ChimeraModule);
}
if (require('@novu/ee-translation')?.EnterpriseTranslationModule) {
modules.push(require('@novu/ee-translation')?.EnterpriseTranslationModule);
}
if (require('@novu/ee-billing')?.BillingModule) {
modules.push(require('@novu/ee-billing')?.BillingModule.forRoot());
}
} catch (e) {
Logger.error(e, `Unexpected error while importing enterprise modules`, 'EnterpriseImport');
}

return modules;
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/app/change/usecases/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { CreateChange, UpdateChange } from '@novu/application-generic';

import { PromoteMessageTemplateChange } from './promote-message-template-change/promote-message-template-change';
import { PromoteNotificationTemplateChange } from './promote-notification-template-change/promote-notification-template-change.usecase';
import { PromoteChangeToEnvironment } from './promote-change-to-environment/promote-change-to-environment.usecase';
Expand All @@ -6,10 +8,8 @@ import { GetChanges } from './get-changes/get-changes.usecase';
import { BulkApplyChange } from './bulk-apply-change/bulk-apply-change.usecase';
import { CountChanges } from './count-changes/count-changes.usecase';
import { PromoteNotificationGroupChange } from './promote-notification-group-change/promote-notification-group-change';
import { UpdateChange } from './update-change/update-change';
import { PromoteFeedChange } from './promote-feed-change/promote-feed-change';
import { PromoteLayoutChange } from './promote-layout-change/promote-layout-change.use-case';
import { CreateChange } from '@novu/application-generic';
import { PromoteTranslationChange } from './promote-translation-change';
import { PromoteTranslationGroupChange } from './promote-translation-group-change';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Injectable, ConflictException } from '@nestjs/common';

import { LayoutEntity, LayoutRepository } from '@novu/dal';
import { Injectable, Inject, ConflictException } from '@nestjs/common';
import { isReservedVariableName } from '@novu/shared';
import { AnalyticsService } from '@novu/application-generic';
import { CreateLayoutCommand } from './create-layout.command';
import { AnalyticsService, ContentService } from '@novu/application-generic';

import { CreateLayoutCommand } from './create-layout.command';
import { CreateLayoutChangeCommand, CreateLayoutChangeUseCase } from '../create-layout-change';
import { SetDefaultLayoutCommand, SetDefaultLayoutUseCase } from '../set-default-layout';
import { LayoutDto } from '../../dtos';
import { ChannelTypeEnum, ITemplateVariable, LayoutId } from '../../types';
import { ApiException } from '../../../shared/exceptions/api.exception';
import { ContentService } from '../../../shared/helpers/content.service';

@Injectable()
export class CreateLayoutUseCase {
Expand Down
5 changes: 3 additions & 2 deletions apps/api/src/app/message-template/usecases/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { CreateMessageTemplate } from '@novu/application-generic';

import { DeleteMessageTemplate } from './delete-message-template/delete-message-template.usecase';
import { CreateMessageTemplate } from './create-message-template/create-message-template.usecase';
import { FindMessageTemplatesByLayoutUseCase } from './find-message-templates-by-layout/find-message-templates-by-layout.use-case';
import { UpdateMessageTemplate } from './update-message-template/update-message-template.usecase';

export * from './create-message-template';
export { CreateMessageTemplate };
export * from './find-message-templates-by-layout';
export * from './update-message-template';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsDefined, IsEnum, IsMongoId, IsOptional, ValidateNested } from 'class-validator';
import { IsDefined, IsEnum, IsMongoId, IsOptional, IsString, ValidateNested } from 'class-validator';
import {
StepTypeEnum,
IEmailBlock,
Expand All @@ -19,19 +19,22 @@ export class UpdateMessageTemplateCommand extends EnvironmentWithUserCommand {
type: StepTypeEnum;

@IsOptional()
@IsString()
name?: string;

@IsOptional()
@IsString()
subject?: string;

@IsOptional()
@IsString()
title?: string;

@IsOptional()
variables?: ITemplateVariable[];

@IsOptional()
content: string | IEmailBlock[];
content?: string | IEmailBlock[];

@IsOptional()
contentType?: MessageTemplateContentType;
Expand All @@ -47,12 +50,15 @@ export class UpdateMessageTemplateCommand extends EnvironmentWithUserCommand {
layoutId?: string | null;

@IsMongoId()
parentChangeId: string;
@IsOptional()
parentChangeId?: string;

@IsOptional()
@IsString()
preheader?: string;

@IsOptional()
@IsString()
senderName?: string;

@IsOptional()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';

import { ChangeRepository, MessageTemplateEntity, MessageTemplateRepository, MessageRepository } from '@novu/dal';
import { ChangeEntityTypeEnum, ITemplateVariable } from '@novu/shared';
import {
CreateChange,
CreateChangeCommand,
normalizeVariantDefault,
sanitizeMessageContent,
UpdateChange,
UpdateChangeCommand,
} from '@novu/application-generic';

import { UpdateMessageTemplateCommand } from './update-message-template.command';
import { sanitizeMessageContent } from '../../shared/sanitizer.service';
import { UpdateChangeCommand } from '../../../change/usecases/update-change/update-change.command';
import { UpdateChange } from '../../../change/usecases/update-change/update-change';
import { CreateChange, CreateChangeCommand } from '@novu/application-generic';

@Injectable()
export class UpdateMessageTemplate {
Expand Down Expand Up @@ -35,11 +40,11 @@ export class UpdateMessageTemplate {

if (command.content !== null || command.content !== undefined) {
updatePayload.content =
command.contentType === 'editor' ? sanitizeMessageContent(command.content) : command.content;
command.content && command.contentType === 'editor' ? sanitizeMessageContent(command.content) : command.content;
}

if (command.variables) {
updatePayload.variables = UpdateMessageTemplate.mapVariables(command.variables);
updatePayload.variables = normalizeVariantDefault(command.variables);
}

if (command.contentType) {
Expand Down Expand Up @@ -137,7 +142,7 @@ export class UpdateMessageTemplate {
);
}

if (command.feedId) {
if (command.feedId && command.parentChangeId) {
await this.updateChange.execute(
UpdateChangeCommand.create({
_entityId: command.feedId,
Expand All @@ -150,7 +155,7 @@ export class UpdateMessageTemplate {
);
}

if (command.layoutId) {
if (command.layoutId && command.parentChangeId) {
await this.updateChange.execute(
UpdateChangeCommand.create({
_entityId: command.layoutId,
Expand All @@ -165,14 +170,4 @@ export class UpdateMessageTemplate {

return item;
}

public static mapVariables(items: ITemplateVariable[]) {
return items.map((item) => {
if (item.defaultValue === '') {
item.defaultValue = undefined;
}

return item;
});
}
}
6 changes: 2 additions & 4 deletions apps/api/src/app/shared/dtos/message-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IMessageCTA,
ActorTypeEnum,
MessageTemplateContentType,
IActor,
} from '@novu/shared';

export class MessageTemplate {
Expand Down Expand Up @@ -54,10 +55,7 @@ export class MessageTemplate {
senderName?: string;

@IsOptional()
actor?: {
type: ActorTypeEnum;
data: string | null;
};
actor?: IActor;

@IsOptional()
_creatorId?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Injectable, Logger, NotFoundException } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import slugify from 'slugify';
import * as shortid from 'shortid';

Expand All @@ -16,18 +17,23 @@ import {
TriggerTypeEnum,
IStepVariant,
} from '@novu/shared';
import { AnalyticsService, CreateChange, CreateChangeCommand, PlatformException } from '@novu/application-generic';
import {
AnalyticsService,
ContentService,
CreateChange,
CreateChangeCommand,
CreateMessageTemplate,
CreateMessageTemplateCommand,
isVariantEmpty,
PlatformException,
} from '@novu/application-generic';

import {
CreateNotificationTemplateCommand,
NotificationStep,
NotificationStepVariant,
} from './create-notification-template.command';
import { ContentService } from '../../../shared/helpers/content.service';
import { CreateMessageTemplate, CreateMessageTemplateCommand } from '../../../message-template/usecases';
import { ApiException } from '../../../shared/exceptions/api.exception';
import { ModuleRef } from '@nestjs/core';
import { checkIsVariantEmpty } from '../../utils';

/**
* DEPRECATED:
Expand Down Expand Up @@ -86,7 +92,7 @@ export class CreateNotificationTemplate {
const variants = command.steps ? command.steps?.flatMap((step) => step.variants || []) : [];

for (const variant of variants) {
if (checkIsVariantEmpty(variant)) {
if (isVariantEmpty(variant)) {
throw new ApiException(`Variant conditions are required, variant name ${variant.name} id ${variant._id}`);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
NotificationTemplateRepository,
StepVariantEntity,
} from '@novu/dal';
import { ChangeEntityTypeEnum, StepTypeEnum } from '@novu/shared';
import { ChangeEntityTypeEnum } from '@novu/shared';
import {
AnalyticsService,
buildNotificationTemplateIdentifierKey,
Expand All @@ -18,22 +18,19 @@ import {
CacheService,
InvalidateCacheService,
PlatformException,
ContentService,
CreateMessageTemplate,
CreateMessageTemplateCommand,
isVariantEmpty,
} from '@novu/application-generic';

import { UpdateNotificationTemplateCommand } from './update-notification-template.command';
import { ContentService } from '../../../shared/helpers/content.service';
import {
CreateMessageTemplate,
CreateMessageTemplateCommand,
UpdateMessageTemplate,
UpdateMessageTemplateCommand,
} from '../../../message-template/usecases';
import { UpdateMessageTemplate, UpdateMessageTemplateCommand } from '../../../message-template/usecases';
import { ApiException } from '../../../shared/exceptions/api.exception';
import { NotificationStep, NotificationStepVariant } from '../create-notification-template';
import { DeleteMessageTemplate } from '../../../message-template/usecases/delete-message-template/delete-message-template.usecase';
import { DeleteMessageTemplateCommand } from '../../../message-template/usecases/delete-message-template/delete-message-template.command';
import { ModuleRef } from '@nestjs/core';
import { checkIsVariantEmpty } from '../../utils';

/**
* DEPRECATED:
Expand Down Expand Up @@ -220,7 +217,7 @@ export class UpdateNotificationTemplate {
const variants = command.steps ? command.steps?.flatMap((step) => step.variants || []) : [];

for (const variant of variants) {
if (checkIsVariantEmpty(variant)) {
if (isVariantEmpty(variant)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The replacement of checkIsVariantEmpty with isVariantEmpty in the main application code has been successfully verified. However, the function checkIsVariantEmpty is still referenced in a test file (packages/application-generic/src/utils/variants/isVariantEmpty.spec.ts). It is recommended to update this test file to use isVariantEmpty to maintain consistency and ensure all tests are aligned with the current implementation.

Analysis chain

Ensure the replacement of checkIsVariantEmpty with isVariantEmpty maintains the intended functionality.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for usages of the old function `checkIsVariantEmpty` to ensure it's fully replaced.
rg --type ts "checkIsVariantEmpty"

Length of output: 145

throw new ApiException(`Variant filters are required, variant name ${variant.name} id ${variant._id}`);
}
}
Expand Down
53 changes: 0 additions & 53 deletions apps/api/src/app/workflows/utils/checkIsVariantEmpty.spec.ts

This file was deleted.

6 changes: 0 additions & 6 deletions apps/api/src/app/workflows/utils/checkIsVariantEmpty.ts

This file was deleted.

1 change: 0 additions & 1 deletion apps/api/src/app/workflows/utils/index.ts

This file was deleted.

Loading
Loading