-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Expand file tree
/
Copy pathtrigger-event-request.dto.ts
More file actions
357 lines (328 loc) · 9.5 KB
/
trigger-event-request.dto.ts
File metadata and controls
357 lines (328 loc) · 9.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
import { ApiExtraModels, ApiHideProperty, ApiProperty, ApiPropertyOptional, getSchemaPath } from '@nestjs/swagger';
import { ApiContextPayload, IsValidContextPayload } from '@novu/application-generic';
import {
ContextPayload,
ProvidersIdEnum,
SeverityLevelEnum,
TriggerRecipientSubscriber,
TriggerRecipientsPayload,
TriggerRecipientsTypeEnum,
TriggerTenantContext,
} from '@novu/shared';
import { Type } from 'class-transformer';
import {
ArrayMaxSize,
IsArray,
IsDefined,
IsObject,
IsOptional,
IsString,
ValidateIf,
ValidateNested,
} from 'class-validator';
import { SdkApiProperty } from '../../shared/framework/swagger/sdk.decorators';
import { CreateSubscriberRequestDto } from '../../subscribers/dtos';
import { UpdateTenantRequestDto } from '../../tenant/dtos';
export class WorkflowToStepControlValuesDto {
/**
* A mapping of step IDs to their corresponding data.
* Built for stateless triggering by the local studio, those values will not be persisted outside of the job scope
* First key is step id, second is controlId, value is the control value
* @type {Record<stepId, Data>}
* @optional
*/
@ApiPropertyOptional({
description: 'A mapping of step IDs to their corresponding data.',
type: Object,
additionalProperties: {
type: 'object',
additionalProperties: true,
},
})
steps?: Record<string, Record<string, unknown>>;
}
export class SubscriberPayloadDto extends CreateSubscriberRequestDto {}
export class TenantPayloadDto extends UpdateTenantRequestDto {}
export class TopicPayloadDto {
@ApiProperty()
topicKey: string;
@ApiProperty({
enum: [...Object.values(TriggerRecipientsTypeEnum)],
enumName: 'TriggerRecipientsTypeEnum',
})
type: TriggerRecipientsTypeEnum;
@ApiPropertyOptional({
description: 'Optional array of subscriber IDs to exclude from the topic trigger',
type: [String],
})
@IsArray()
@ArrayMaxSize(100)
@IsString({ each: true })
@IsOptional()
exclude?: string[];
}
export class StepsOverrides {
@ApiPropertyOptional({
description: 'Passing the provider id and the provider specific configurations',
example: {
sendgrid: {
templateId: '1234567890',
},
},
type: 'object',
additionalProperties: {
type: 'object',
additionalProperties: true,
},
})
providers?: Record<ProvidersIdEnum, Record<string, unknown>>;
@ApiPropertyOptional({
description: 'Override the or remove the layout for this specific step',
example: 'welcome-email-layout',
nullable: true,
type: 'string',
})
@IsOptional()
@IsString()
layoutId?: string | null;
}
export class EmailChannelOverrides {
@ApiPropertyOptional({
description: 'Override or remove the layout for all email steps in the workflow',
example: 'promotional-layout-2024',
nullable: true,
type: 'string',
})
@IsOptional()
@IsString()
layoutId?: string | null;
}
export class ChannelOverrides {
@ApiPropertyOptional({
description: 'Email channel specific overrides',
type: () => EmailChannelOverrides,
})
email?: EmailChannelOverrides;
}
export class TriggerOverrides {
@ApiPropertyOptional({
description: 'This could be used to override provider specific configurations or layout at the step level',
example: {
'email-step': {
providers: {
sendgrid: {
templateId: '1234567890',
},
},
layoutId: 'step-specific-layout',
},
},
type: 'object',
additionalProperties: {
$ref: getSchemaPath(StepsOverrides),
},
})
steps?: Record<string, StepsOverrides>;
@ApiPropertyOptional({
description:
'Channel-specific overrides that apply to all steps of a particular channel type. Step-level overrides take precedence over channel-level overrides.',
example: {
email: {
layoutId: 'promotional-layout-2024',
},
},
type: () => ChannelOverrides,
})
channels?: ChannelOverrides;
@ApiPropertyOptional({
description: 'Overrides the provider configuration for the entire workflow and all steps',
example: {
sendgrid: {
templateId: '1234567890',
},
},
type: 'object',
additionalProperties: {
type: 'object',
additionalProperties: true,
},
})
providers?: Record<ProvidersIdEnum, Record<string, unknown>>;
@ApiPropertyOptional({
description: 'Override the email provider specific configurations for the entire workflow',
deprecated: true,
type: 'object',
additionalProperties: true,
})
email?: Record<string, any>;
@ApiPropertyOptional({
description: 'Override the push provider specific configurations for the entire workflow',
deprecated: true,
type: 'object',
additionalProperties: true,
})
push?: Record<string, any>;
@ApiPropertyOptional({
description: 'Override the sms provider specific configurations for the entire workflow',
deprecated: true,
type: 'object',
additionalProperties: true,
})
sms?: Record<string, any>;
@ApiPropertyOptional({
description: 'Override the chat provider specific configurations for the entire workflow',
deprecated: true,
type: 'object',
additionalProperties: true,
})
chat?: Record<string, any>;
@ApiPropertyOptional({
description: 'Override the layout identifier for the entire workflow',
deprecated: true,
})
layoutIdentifier?: string;
@ApiPropertyOptional({
description: 'Override the severity of the workflow',
enum: [...Object.values(SeverityLevelEnum)],
enumName: 'SeverityLevelEnum',
})
severity?: SeverityLevelEnum;
}
@ApiExtraModels(
SubscriberPayloadDto,
TenantPayloadDto,
TopicPayloadDto,
StepsOverrides,
EmailChannelOverrides,
ChannelOverrides
)
export class TriggerEventRequestDto {
@SdkApiProperty(
{
description:
'The trigger identifier of the workflow you wish to send. This identifier can be found on the workflow page.',
example: 'workflow_identifier',
},
{ nameOverride: 'workflowId' }
)
@IsString()
@IsDefined()
name: string;
@ApiPropertyOptional({
description: `The payload object is used to pass additional custom information that could be
used to render the workflow, or perform routing rules based on it.
This data will also be available when fetching the notifications feed from the API to display certain parts of the UI.`,
type: Object,
additionalProperties: true,
example: {
comment_id: 'string',
post: {
text: 'string',
},
},
})
@IsObject()
@IsOptional()
payload?: Record<string, unknown>;
@ApiHideProperty()
@IsString()
@IsOptional()
bridgeUrl?: string;
@ApiPropertyOptional({
description: 'This could be used to override provider specific configurations',
example: {
fcm: {
data: {
key: 'value',
},
},
},
type: TriggerOverrides,
})
@IsObject()
@IsOptional()
overrides?: TriggerOverrides;
@ApiProperty({
description:
'The recipients list of people who will receive the notification. Maximum number of recipients can be 100.',
oneOf: [
{
type: 'array',
items: {
oneOf: [
{
$ref: getSchemaPath(SubscriberPayloadDto),
},
{
$ref: getSchemaPath(TopicPayloadDto),
},
{
type: 'string',
description: 'Unique identifier of a subscriber in your systems',
example: 'SUBSCRIBER_ID',
},
],
},
},
{
type: 'string',
description: 'Unique identifier of a subscriber in your systems',
example: 'SUBSCRIBER_ID',
},
{
$ref: getSchemaPath(SubscriberPayloadDto),
},
{
$ref: getSchemaPath(TopicPayloadDto),
},
],
})
@IsDefined()
to: TriggerRecipientsPayload;
@ApiPropertyOptional({
description: `A unique identifier for deduplication. If the same **transactionId** is sent again,
the trigger is ignored. Useful to prevent duplicate notifications. The retention period depends on your billing tier.`,
})
@IsString()
@IsOptional()
transactionId?: string;
@ApiPropertyOptional({
description: `It is used to display the Avatar of the provided actor's subscriber id or actor object.
If a new actor object is provided, we will create a new subscriber in our system`,
oneOf: [
{ type: 'string', description: 'Unique identifier of a subscriber in your systems' },
{ $ref: getSchemaPath(SubscriberPayloadDto) },
],
})
@IsOptional()
@ValidateIf((_, value) => typeof value !== 'string')
@ValidateNested()
@Type(() => SubscriberPayloadDto)
actor?: TriggerRecipientSubscriber;
@ApiPropertyOptional({
description: `It is used to specify a tenant context during trigger event.
Existing tenants will be updated with the provided details.`,
oneOf: [
{ type: 'string', description: 'Unique identifier of a tenant in your system' },
{ $ref: getSchemaPath(TenantPayloadDto) },
],
})
@IsOptional()
@ValidateIf((_, value) => typeof value !== 'string')
@ValidateNested()
@Type(() => TenantPayloadDto)
tenant?: TriggerTenantContext;
@ApiHideProperty()
controls?: WorkflowToStepControlValuesDto;
@ApiContextPayload()
@IsOptional()
@IsValidContextPayload({ maxCount: 5 })
context?: ContextPayload;
}
export class BulkTriggerEventDto {
@ApiProperty({
isArray: true,
type: TriggerEventRequestDto,
})
events: TriggerEventRequestDto[];
}