From 20fc0f076d4290cf433f06d8918922c958d53e52 Mon Sep 17 00:00:00 2001 From: Richard Fontein <32132657+rifont@users.noreply.github.com> Date: Tue, 20 Aug 2024 15:12:16 +0100 Subject: [PATCH] fix(api, shared, application-generic): Replace branded types with `string` type (#6354) --- .../events/dtos/trigger-event-request.dto.ts | 3 +- .../update-all-notifications-request.dto.ts | 4 +-- .../src/app/layouts/dtos/create-layout.dto.ts | 18 +++++----- apps/api/src/app/layouts/dtos/layout.dto.ts | 26 +++++--------- .../src/app/layouts/dtos/update-layout.dto.ts | 8 ++--- .../tenant/dtos/create-tenant-response.dto.ts | 6 ++-- .../app/topics/dtos/add-subscribers.dto.ts | 2 +- .../src/app/topics/dtos/create-topic.dto.ts | 19 ++++++---- .../src/app/topics/dtos/filter-topics.dto.ts | 4 +-- .../app/topics/dtos/remove-subscribers.dto.ts | 2 +- .../src/app/topics/dtos/rename-topic.dto.ts | 4 +-- .../app/topics/dtos/topic-subscriber.dto.ts | 14 ++++---- apps/api/src/app/topics/dtos/topic.dto.ts | 13 ++++--- .../src/usecases/get-layout/layout.dto.ts | 26 +++++--------- libs/shared/src/dto/layout/layout.dto.ts | 29 +++++---------- .../src/dto/subscriber/subscriber.dto.ts | 14 +++----- libs/shared/src/dto/topic/topic.dto.ts | 35 +++++++------------ 17 files changed, 88 insertions(+), 139 deletions(-) diff --git a/apps/api/src/app/events/dtos/trigger-event-request.dto.ts b/apps/api/src/app/events/dtos/trigger-event-request.dto.ts index 023b46820ee..c405ad086d0 100644 --- a/apps/api/src/app/events/dtos/trigger-event-request.dto.ts +++ b/apps/api/src/app/events/dtos/trigger-event-request.dto.ts @@ -13,7 +13,6 @@ import { Type } from 'class-transformer'; import { ApiExtraModels, ApiProperty, ApiPropertyOptional, getSchemaPath } from '@nestjs/swagger'; import { ControlsDto, - TopicKey, TriggerRecipients, TriggerRecipientsTypeEnum, TriggerRecipientSubscriber, @@ -27,7 +26,7 @@ export class TenantPayloadDto extends UpdateTenantRequestDto {} export class TopicPayloadDto { @ApiProperty() - topicKey: TopicKey; + topicKey: string; @ApiProperty({ example: 'Topic', enum: TriggerRecipientsTypeEnum }) type: TriggerRecipientsTypeEnum; diff --git a/apps/api/src/app/inbox/dtos/update-all-notifications-request.dto.ts b/apps/api/src/app/inbox/dtos/update-all-notifications-request.dto.ts index e55e5362c3d..ccccc3f5cf7 100644 --- a/apps/api/src/app/inbox/dtos/update-all-notifications-request.dto.ts +++ b/apps/api/src/app/inbox/dtos/update-all-notifications-request.dto.ts @@ -1,8 +1,6 @@ import { IsArray, IsOptional, IsString } from 'class-validator'; -import type { NotificationFilter } from '../utils/types'; - -export class UpdateAllNotificationsRequestDto implements Pick { +export class UpdateAllNotificationsRequestDto { @IsOptional() @IsArray() @IsString({ each: true }) diff --git a/apps/api/src/app/layouts/dtos/create-layout.dto.ts b/apps/api/src/app/layouts/dtos/create-layout.dto.ts index 41d5d2ec850..d2bf0d97088 100644 --- a/apps/api/src/app/layouts/dtos/create-layout.dto.ts +++ b/apps/api/src/app/layouts/dtos/create-layout.dto.ts @@ -1,13 +1,13 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { IsBoolean, IsDefined, IsOptional, IsString } from 'class-validator'; -import { LayoutDto } from './layout.dto'; +import { LayoutVariables } from '../types'; -import { LayoutDescription, LayoutId, LayoutIdentifier, LayoutName, LayoutVariables } from '../types'; - -export class CreateLayoutResponseDto implements Pick { - @ApiProperty() - _id: LayoutId; +export class CreateLayoutResponseDto { + @ApiProperty({ + description: 'The unique identifier for the Layout created.', + }) + _id: string; } export class CreateLayoutRequestDto { @@ -16,21 +16,21 @@ export class CreateLayoutRequestDto { }) @IsString() @IsDefined() - name: LayoutName; + name: string; @ApiProperty({ description: 'User defined custom key that will be a unique identifier for the Layout created.', }) @IsString() @IsDefined() - identifier: LayoutIdentifier; + identifier: string; @ApiPropertyOptional({ description: 'User description of the layout', }) @IsString() @IsOptional() - description: LayoutDescription; + description: string; @ApiProperty({ description: 'User defined content for the layout.', diff --git a/apps/api/src/app/layouts/dtos/layout.dto.ts b/apps/api/src/app/layouts/dtos/layout.dto.ts index bad8564758b..863eb18dfc5 100644 --- a/apps/api/src/app/layouts/dtos/layout.dto.ts +++ b/apps/api/src/app/layouts/dtos/layout.dto.ts @@ -1,37 +1,27 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; -import { - ChannelTypeEnum, - EnvironmentId, - ITemplateVariable, - OrganizationId, - LayoutDescription, - LayoutId, - LayoutName, - LayoutIdentifier, - UserId, -} from '../types'; +import { ChannelTypeEnum, ITemplateVariable } from '../types'; export class LayoutDto { @ApiPropertyOptional() - _id?: LayoutId; + _id?: string; @ApiProperty() - _organizationId: OrganizationId; + _organizationId: string; @ApiProperty() - _environmentId: EnvironmentId; + _environmentId: string; @ApiProperty() - _creatorId: UserId; + _creatorId: string; @ApiProperty() - name: LayoutName; + name: string; @ApiProperty() - identifier: LayoutIdentifier; + identifier: string; @ApiProperty() - description?: LayoutDescription; + description?: string; @ApiProperty({ enum: ChannelTypeEnum, diff --git a/apps/api/src/app/layouts/dtos/update-layout.dto.ts b/apps/api/src/app/layouts/dtos/update-layout.dto.ts index b957aec0561..fc7f5a9d7d6 100644 --- a/apps/api/src/app/layouts/dtos/update-layout.dto.ts +++ b/apps/api/src/app/layouts/dtos/update-layout.dto.ts @@ -3,7 +3,7 @@ import { IsBoolean, IsOptional, IsString } from 'class-validator'; import { LayoutDto } from './layout.dto'; -import { LayoutDescription, LayoutIdentifier, LayoutName, LayoutVariables } from '../types'; +import { LayoutVariables } from '../types'; export class UpdateLayoutResponseDto extends LayoutDto {} @@ -13,21 +13,21 @@ export class UpdateLayoutRequestDto { }) @IsString() @IsOptional() - name?: LayoutName; + name?: string; @ApiProperty({ description: 'User defined custom key that will be a unique identifier for the Layout updated.', }) @IsString() @IsOptional() - identifier: LayoutIdentifier; + identifier: string; @ApiPropertyOptional({ description: 'User defined description of the layout', }) @IsString() @IsOptional() - description?: LayoutDescription; + description?: string; @ApiPropertyOptional({ description: 'User defined content for the layout.', diff --git a/apps/api/src/app/tenant/dtos/create-tenant-response.dto.ts b/apps/api/src/app/tenant/dtos/create-tenant-response.dto.ts index 53ef1068e95..6f78e64f5d6 100644 --- a/apps/api/src/app/tenant/dtos/create-tenant-response.dto.ts +++ b/apps/api/src/app/tenant/dtos/create-tenant-response.dto.ts @@ -1,11 +1,11 @@ import { ApiProperty } from '@nestjs/swagger'; -import { EnvironmentId, TenantCustomData } from '@novu/shared'; +import { TenantCustomData } from '@novu/shared'; import { TenantId } from '@novu/dal'; export class CreateTenantResponseDto { @ApiProperty() - _id: TenantId; + _id: string; @ApiProperty() identifier: string; @@ -17,7 +17,7 @@ export class CreateTenantResponseDto { data?: TenantCustomData; @ApiProperty() - _environmentId: EnvironmentId; + _environmentId: string; @ApiProperty() createdAt: string; diff --git a/apps/api/src/app/topics/dtos/add-subscribers.dto.ts b/apps/api/src/app/topics/dtos/add-subscribers.dto.ts index 9e26cd254b5..d5223cb2f85 100644 --- a/apps/api/src/app/topics/dtos/add-subscribers.dto.ts +++ b/apps/api/src/app/topics/dtos/add-subscribers.dto.ts @@ -9,5 +9,5 @@ export class AddSubscribersRequestDto { }) @IsArray() @IsDefined() - subscribers: ExternalSubscriberId[]; + subscribers: string[]; } diff --git a/apps/api/src/app/topics/dtos/create-topic.dto.ts b/apps/api/src/app/topics/dtos/create-topic.dto.ts index 96d2f85fdfe..ef7a9e33c75 100644 --- a/apps/api/src/app/topics/dtos/create-topic.dto.ts +++ b/apps/api/src/app/topics/dtos/create-topic.dto.ts @@ -1,11 +1,18 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { IsDefined, IsString } from 'class-validator'; -import { TopicDto } from './topic.dto'; - -import { TopicKey, TopicName } from '../types'; +export class CreateTopicResponseDto { + @ApiPropertyOptional({ + description: 'The unique identifier for the Topic created.', + }) + _id: string; -export class CreateTopicResponseDto implements Pick {} + @ApiProperty({ + description: + 'User defined custom key and provided by the user that will be an unique identifier for the Topic created.', + }) + key: string; +} export class CreateTopicRequestDto { @ApiProperty({ @@ -14,12 +21,12 @@ export class CreateTopicRequestDto { }) @IsString() @IsDefined() - key: TopicKey; + key: string; @ApiProperty({ description: 'User defined custom name and provided by the user that will name the Topic created.', }) @IsString() @IsDefined() - name: TopicName; + name: string; } diff --git a/apps/api/src/app/topics/dtos/filter-topics.dto.ts b/apps/api/src/app/topics/dtos/filter-topics.dto.ts index ef9b51e1998..c45291177d4 100644 --- a/apps/api/src/app/topics/dtos/filter-topics.dto.ts +++ b/apps/api/src/app/topics/dtos/filter-topics.dto.ts @@ -4,8 +4,6 @@ import { Transform } from 'class-transformer'; import { TopicDto } from './topic.dto'; -import { TopicKey } from '../types'; - export class FilterTopicsRequestDto { @Transform(({ value }) => Number(value)) @IsOptional() @@ -24,7 +22,7 @@ export class FilterTopicsRequestDto { @IsString() @IsOptional() @ApiPropertyOptional({ type: String }) - public key?: TopicKey; + public key?: string; } export class FilterTopicsResponseDto { diff --git a/apps/api/src/app/topics/dtos/remove-subscribers.dto.ts b/apps/api/src/app/topics/dtos/remove-subscribers.dto.ts index 60bf61f8678..267481f1169 100644 --- a/apps/api/src/app/topics/dtos/remove-subscribers.dto.ts +++ b/apps/api/src/app/topics/dtos/remove-subscribers.dto.ts @@ -9,5 +9,5 @@ export class RemoveSubscribersRequestDto { }) @IsArray() @IsDefined() - subscribers: ExternalSubscriberId[]; + subscribers: string[]; } diff --git a/apps/api/src/app/topics/dtos/rename-topic.dto.ts b/apps/api/src/app/topics/dtos/rename-topic.dto.ts index ffa5f598709..bfb31d9a453 100644 --- a/apps/api/src/app/topics/dtos/rename-topic.dto.ts +++ b/apps/api/src/app/topics/dtos/rename-topic.dto.ts @@ -3,8 +3,6 @@ import { IsDefined, IsString } from 'class-validator'; import { TopicDto } from './topic.dto'; -import { TopicName } from '../types'; - export class RenameTopicResponseDto extends TopicDto {} export class RenameTopicRequestDto { @@ -13,5 +11,5 @@ export class RenameTopicRequestDto { }) @IsString() @IsDefined() - name: TopicName; + name: string; } diff --git a/apps/api/src/app/topics/dtos/topic-subscriber.dto.ts b/apps/api/src/app/topics/dtos/topic-subscriber.dto.ts index e52550ffad2..b96aa8c5a7f 100644 --- a/apps/api/src/app/topics/dtos/topic-subscriber.dto.ts +++ b/apps/api/src/app/topics/dtos/topic-subscriber.dto.ts @@ -2,24 +2,22 @@ import { ApiProperty } from '@nestjs/swagger'; import { ITopicSubscriber } from '@novu/shared'; -import { EnvironmentId, ExternalSubscriberId, OrganizationId, SubscriberId, TopicId, TopicKey } from '../types'; - export class TopicSubscriberDto implements ITopicSubscriber { @ApiProperty() - _organizationId: OrganizationId; + _organizationId: string; @ApiProperty() - _environmentId: EnvironmentId; + _environmentId: string; @ApiProperty() - _subscriberId: SubscriberId; + _subscriberId: string; @ApiProperty() - _topicId: TopicId; + _topicId: string; @ApiProperty() - topicKey: TopicKey; + topicKey: string; @ApiProperty() - externalSubscriberId: ExternalSubscriberId; + externalSubscriberId: string; } diff --git a/apps/api/src/app/topics/dtos/topic.dto.ts b/apps/api/src/app/topics/dtos/topic.dto.ts index a2fa0223d2c..494eb521c3e 100644 --- a/apps/api/src/app/topics/dtos/topic.dto.ts +++ b/apps/api/src/app/topics/dtos/topic.dto.ts @@ -1,22 +1,21 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; -import { EnvironmentId, ExternalSubscriberId, OrganizationId, TopicId, TopicKey, TopicName } from '../types'; export class TopicDto { @ApiPropertyOptional() - _id: TopicId; + _id: string; @ApiProperty() - _organizationId: OrganizationId; + _organizationId: string; @ApiProperty() - _environmentId: EnvironmentId; + _environmentId: string; @ApiProperty() - key: TopicKey; + key: string; @ApiProperty() - name: TopicName; + name: string; @ApiProperty() - subscribers: ExternalSubscriberId[]; + subscribers: string[]; } diff --git a/libs/application-generic/src/usecases/get-layout/layout.dto.ts b/libs/application-generic/src/usecases/get-layout/layout.dto.ts index 6398556fef6..391fa652b6d 100644 --- a/libs/application-generic/src/usecases/get-layout/layout.dto.ts +++ b/libs/application-generic/src/usecases/get-layout/layout.dto.ts @@ -1,37 +1,27 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; -import { - EnvironmentId, - OrganizationId, - ChannelTypeEnum, - ITemplateVariable, - LayoutDescription, - LayoutId, - LayoutName, - LayoutIdentifier, - UserId, -} from '@novu/dal'; +import { ChannelTypeEnum, ITemplateVariable } from '@novu/dal'; export class LayoutDto { @ApiPropertyOptional() - _id?: LayoutId; + _id?: string; @ApiProperty() - _organizationId: OrganizationId; + _organizationId: string; @ApiProperty() - _environmentId: EnvironmentId; + _environmentId: string; @ApiProperty() - _creatorId: UserId; + _creatorId: string; @ApiProperty() - name: LayoutName; + name: string; @ApiProperty() - identifier: LayoutIdentifier; + identifier: string; @ApiProperty() - description?: LayoutDescription; + description?: string; @ApiProperty() channel: ChannelTypeEnum; diff --git a/libs/shared/src/dto/layout/layout.dto.ts b/libs/shared/src/dto/layout/layout.dto.ts index b1d464069a1..0747917fef5 100644 --- a/libs/shared/src/dto/layout/layout.dto.ts +++ b/libs/shared/src/dto/layout/layout.dto.ts @@ -1,25 +1,14 @@ -import { - ChannelTypeEnum, - EnvironmentId, - IEmailBlock, - ITemplateVariable, - OrganizationId, - LayoutDescription, - LayoutId, - LayoutName, - LayoutIdentifier, - UserId, -} from '../../types'; +import { ChannelTypeEnum, IEmailBlock, ITemplateVariable } from '../../types'; export class LayoutDto { - _id?: LayoutId; - _organizationId: OrganizationId; - _environmentId: EnvironmentId; - _creatorId: UserId; - _parentId?: LayoutId; - name: LayoutName; - identifier: LayoutIdentifier; - description?: LayoutDescription; + _id?: string; + _organizationId: string; + _environmentId: string; + _creatorId: string; + _parentId?: string; + name: string; + identifier: string; + description?: string; channel: ChannelTypeEnum; content: IEmailBlock[]; contentType: string; diff --git a/libs/shared/src/dto/subscriber/subscriber.dto.ts b/libs/shared/src/dto/subscriber/subscriber.dto.ts index a090334a3c8..32538d11714 100644 --- a/libs/shared/src/dto/subscriber/subscriber.dto.ts +++ b/libs/shared/src/dto/subscriber/subscriber.dto.ts @@ -1,11 +1,5 @@ import { ChatProviderIdEnum, PushProviderIdEnum } from '../../consts'; -import { - EnvironmentId, - ExternalSubscriberId, - ISubscriberChannel, - OrganizationId, - SubscriberCustomData, -} from '../../types'; +import { ISubscriberChannel } from '../../types'; interface IChannelCredentials { webhookUrl?: string; @@ -20,15 +14,15 @@ interface IChannelSettings { export class SubscriberDto { _id: string; - _organizationId: OrganizationId; - _environmentId: EnvironmentId; + _organizationId: string; + _environmentId: string; firstName: string; lastName: string; email: string; phone?: string; avatar?: string; locale?: string; - subscriberId: ExternalSubscriberId; + subscriberId: string; channels?: IChannelSettings[]; deleted: boolean; } diff --git a/libs/shared/src/dto/topic/topic.dto.ts b/libs/shared/src/dto/topic/topic.dto.ts index 92b3f7cc42b..bbcbbe5cce7 100644 --- a/libs/shared/src/dto/topic/topic.dto.ts +++ b/libs/shared/src/dto/topic/topic.dto.ts @@ -1,28 +1,17 @@ -import { - EnvironmentId, - ExternalSubscriberId, - OrganizationId, - SubscriberId, - TopicId, - TopicKey, - TopicName, - UserId, -} from '../../types'; - export class TopicDto { - _id: TopicId; - _organizationId: OrganizationId; - _environmentId: EnvironmentId; - key: TopicKey; - name: TopicName; - subscribers: ExternalSubscriberId[]; + _id: string; + _organizationId: string; + _environmentId: string; + key: string; + name: string; + subscribers: string[]; } export class TopicSubscribersDto { - _organizationId: OrganizationId; - _environmentId: EnvironmentId; - _subscriberId: SubscriberId; - _topicId: TopicId; - topicKey: TopicKey; - externalSubscriberId: ExternalSubscriberId; + _organizationId: string; + _environmentId: string; + _subscriberId: string; + _topicId: string; + topicKey: string; + externalSubscriberId: string; }