@novu/framework 2.0.2 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { ChannelTypeEnum, TriggerEventStatusEnum, ITriggerPayload, TriggerRecipientSubscriber, TriggerRecipientsPayload } from '@novu/shared';
1
+ import { TriggerEventStatusEnum, ITriggerPayload, TriggerRecipientSubscriber, TriggerRecipientsPayload, WorkflowPreferencesPartial } from '@novu/shared';
2
2
  import { JSONSchema, FromSchema as FromSchema$1 } from 'json-schema-to-ts';
3
3
  import zod from 'zod';
4
4
 
@@ -55,6 +55,19 @@ declare enum ActionStepEnum {
55
55
  CUSTOM = "custom"
56
56
  }
57
57
 
58
+ /**
59
+ * A developer-friendly variant of ChannelTypeEnum, utilizing camelCase instead of snake_case
60
+ * to use consistent casing throughout the Framework.
61
+ */
62
+ declare enum WorkflowChannelEnum {
63
+ EMAIL = "email",
64
+ SMS = "sms",
65
+ PUSH = "push",
66
+ CHAT = "chat",
67
+ /** Differs from ChannelTypeEnum in capitalization / snake_case */
68
+ IN_APP = "inApp"
69
+ }
70
+
58
71
  type JsonSchema = JSONSchema;
59
72
  /**
60
73
  * A schema used to validate a JSON object.
@@ -4049,6 +4062,12 @@ type PickRequiredKeys<T, DEEP extends boolean = true> = keyof PickRequired<T, DE
4049
4062
  * Optionally, recurses through nested objects if `DEEP` is true.
4050
4063
  */
4051
4064
  type PickOptionalKeys<T, DEEP extends boolean = true> = keyof PickOptional<T, DEEP>;
4065
+ /**
4066
+ * Recursively make all properties of type `T` optional.
4067
+ */
4068
+ type DeepPartial<T> = T extends object ? {
4069
+ [P in keyof T]?: DeepPartial<T[P]>;
4070
+ } : T;
4052
4071
 
4053
4072
  type Passthrough = {
4054
4073
  body?: Record<string, unknown>;
@@ -4256,15 +4275,15 @@ type DigestResult = FromSchema<(typeof actionStepSchemas)[ActionStepEnum.DIGEST]
4256
4275
  */
4257
4276
  type Step = {
4258
4277
  /** Send an email. */
4259
- email: ChannelStep<ChannelStepEnum.EMAIL, EmailOutputUnvalidated, EmailResult>;
4278
+ [WorkflowChannelEnum.EMAIL]: ChannelStep<ChannelStepEnum.EMAIL, EmailOutputUnvalidated, EmailResult>;
4260
4279
  /** Send an SMS. */
4261
- sms: ChannelStep<ChannelStepEnum.SMS, SmsOutputUnvalidated, SmsResult>;
4280
+ [WorkflowChannelEnum.SMS]: ChannelStep<ChannelStepEnum.SMS, SmsOutputUnvalidated, SmsResult>;
4262
4281
  /** Send a push notification. */
4263
- push: ChannelStep<ChannelStepEnum.PUSH, PushOutputUnvalidated, PushResult>;
4282
+ [WorkflowChannelEnum.PUSH]: ChannelStep<ChannelStepEnum.PUSH, PushOutputUnvalidated, PushResult>;
4264
4283
  /** Send a chat message. */
4265
- chat: ChannelStep<ChannelStepEnum.CHAT, ChatOutputUnvalidated, ChatResult>;
4284
+ [WorkflowChannelEnum.CHAT]: ChannelStep<ChannelStepEnum.CHAT, ChatOutputUnvalidated, ChatResult>;
4266
4285
  /** Send an in-app notification. */
4267
- inApp: ChannelStep<ChannelStepEnum.IN_APP, InAppOutputUnvalidated, InAppResult>;
4286
+ [WorkflowChannelEnum.IN_APP]: ChannelStep<ChannelStepEnum.IN_APP, InAppOutputUnvalidated, InAppResult>;
4268
4287
  /** Aggregate events for a period of time. */
4269
4288
  digest: ActionStep<DigestOutputUnvalidated, DigestResult>;
4270
4289
  /** Delay the workflow for a period of time. */
@@ -4308,16 +4327,42 @@ type ExecuteInput<T_Payload extends Record<string, unknown>, T_Controls extends
4308
4327
  * The function to execute the workflow.
4309
4328
  */
4310
4329
  type Execute<T_Payload extends Record<string, unknown>, T_Controls extends Record<string, unknown>> = (event: ExecuteInput<T_Payload, T_Controls>) => Promise<void>;
4311
- type WorkflowOptionChannelPreference = {
4312
- defaultValue?: boolean;
4313
- readOnly?: boolean;
4314
- };
4315
- type WorkflowOptionsPreferences = {
4316
- workflow?: WorkflowOptionChannelPreference;
4317
- channels?: {
4318
- [key in (typeof ChannelTypeEnum)[keyof typeof ChannelTypeEnum]]?: WorkflowOptionChannelPreference;
4319
- };
4330
+ /** A preference for a notification delivery channel. */
4331
+ type ChannelPreference = {
4332
+ /**
4333
+ * A flag specifying if notification delivery is enabled for the channel.
4334
+ *
4335
+ * If `true`, notification delivery is enabled.
4336
+ *
4337
+ * @default true
4338
+ */
4339
+ enabled: boolean;
4340
+ /**
4341
+ * A flag specifying if the preference is read-only.
4342
+ *
4343
+ * If `true`, the preference cannot be changed by the Subscriber.
4344
+ *
4345
+ * @default false
4346
+ */
4347
+ readOnly: boolean;
4320
4348
  };
4349
+ /**
4350
+ * A partial set of workflow preferences.
4351
+ */
4352
+ type WorkflowPreferences = DeepPartial<{
4353
+ /**
4354
+ * A preference for the workflow.
4355
+ *
4356
+ * The values specified here will be used if no preference is specified for a channel.
4357
+ */
4358
+ workflow: ChannelPreference;
4359
+ /**
4360
+ * A preference for each notification delivery channel.
4361
+ *
4362
+ * If no preference is specified for a channel, the `workflow` preference will be used.
4363
+ */
4364
+ channels: Record<WorkflowChannelEnum, ChannelPreference>;
4365
+ }>;
4321
4366
  /**
4322
4367
  * The options for the workflow.
4323
4368
  */
@@ -4330,8 +4375,63 @@ type WorkflowOptions<T_PayloadSchema extends Schema, T_ControlSchema extends Sch
4330
4375
  * @deprecated Use `controlSchema` instead
4331
4376
  */
4332
4377
  inputSchema?: T_ControlSchema;
4378
+ /** The schema for the controls. */
4333
4379
  controlSchema?: T_ControlSchema;
4334
- preferences?: WorkflowOptionsPreferences;
4380
+ /**
4381
+ * The preferences for the notification workflow.
4382
+ *
4383
+ * If no preference is specified for a channel, the `workflow` preference will be used.
4384
+ *
4385
+ * @example
4386
+ * ```ts
4387
+ * // Enable notification delivery for only the in-app channel by default.
4388
+ * {
4389
+ * workflow: { enabled: false },
4390
+ * channels: {
4391
+ * inApp: { enabled: true },
4392
+ * },
4393
+ * }
4394
+ * ```
4395
+ *
4396
+ * @example
4397
+ * ```ts
4398
+ * // Enable notification delivery for all channels by default.
4399
+ * {
4400
+ * workflow: { enabled: true }
4401
+ * }
4402
+ * ```
4403
+ *
4404
+ * @example
4405
+ * ```ts
4406
+ * // Enable notification delivery for all channels by default,
4407
+ * // disallowing the Subscriber to change the preference.
4408
+ * {
4409
+ * workflow: { enabled: true, readOnly: true },
4410
+ * }
4411
+ * ```
4412
+ *
4413
+ * @example
4414
+ * ```ts
4415
+ * // Disable notification delivery for all channels by default,
4416
+ * // allowing the Subscriber to change the preference.
4417
+ * {
4418
+ * workflow: { enabled: false, readOnly: false },
4419
+ * }
4420
+ * ```
4421
+ *
4422
+ * @example
4423
+ * ```ts
4424
+ * // Disable notification delivery for only the in-app channel by default,
4425
+ * // allowing the Subscriber to change the preference.
4426
+ * {
4427
+ * channels: {
4428
+ * inApp: { enabled: false, readOnly: false },
4429
+ * },
4430
+ * }
4431
+ * ```
4432
+ */
4433
+ preferences?: WorkflowPreferences;
4434
+ /** The tags for the workflow. */
4335
4435
  tags?: string[];
4336
4436
  };
4337
4437
 
@@ -4449,16 +4549,6 @@ type DiscoverStepOutput = {
4449
4549
  providers: Array<DiscoverProviderOutput>;
4450
4550
  options: StepOptions;
4451
4551
  };
4452
- type ChannelPreference = {
4453
- defaultValue: boolean;
4454
- readOnly: boolean;
4455
- };
4456
- type DiscoverWorkflowOutputPreferences = {
4457
- workflow: ChannelPreference;
4458
- channels: {
4459
- [key in (typeof ChannelTypeEnum)[keyof typeof ChannelTypeEnum]]: ChannelPreference;
4460
- };
4461
- };
4462
4552
  type DiscoverWorkflowOutput = {
4463
4553
  workflowId: string;
4464
4554
  execute: Execute<Record<string, unknown>, Record<string, unknown>>;
@@ -4483,7 +4573,7 @@ type DiscoverWorkflowOutput = {
4483
4573
  schema: JsonSchema;
4484
4574
  unknownSchema: Schema;
4485
4575
  };
4486
- preferences: DiscoverWorkflowOutputPreferences;
4576
+ preferences: WorkflowPreferencesPartial;
4487
4577
  tags: string[];
4488
4578
  };
4489
4579
  type Workflow<T_Payload = any> = {
@@ -4644,4 +4734,4 @@ declare class NovuRequestHandler<Input extends any[] = any[], Output = any> {
4644
4734
  private hashHmac;
4645
4735
  }
4646
4736
 
4647
- export { type ChatResult as $, ActionStepEnum as A, type StepOutput as B, Client as C, type DiscoverProviderOutput as D, type Execute as E, type FromSchemaUnvalidated as F, GetActionEnum as G, type HealthCheck as H, type ActionStep as I, type JsonSchema as J, type CustomStep as K, type ChannelStep as L, type EmailOutput as M, NovuRequestHandler as N, type EmailOutputUnvalidated as O, PostActionEnum as P, type EmailResult as Q, type SmsOutput as R, type Schema as S, type SmsOutputUnvalidated as T, type SmsResult as U, type PushOutput as V, type WorkflowOptions as W, type PushOutputUnvalidated as X, type PushResult as Y, type ChatOutput as Z, type ChatOutputUnvalidated as _, type FromSchema as a, type InAppOutput as a0, type InAppOutputUnvalidated as a1, type InAppResult as a2, type DelayOutput as a3, type DelayOutputUnvalidated as a4, type DelayResult as a5, type DigestRegularOutput as a6, type DigestRegularOutputUnvalidated as a7, type DigestTimedOutput as a8, type DigestTimedOutputUnvalidated as a9, type DigestOutput as aa, type DigestOutputUnvalidated as ab, type DigestResult as ac, type Step as ad, type Subscriber as ae, type Either as af, type Awaitable as ag, type Prettify as ah, type ConditionalPartial as ai, type Indexable as aj, type PickOptional as ak, type PickRequired as al, type PickRequiredKeys as am, type PickOptionalKeys as an, type ExecuteInput as ao, type WorkflowOptionChannelPreference as ap, type WorkflowOptionsPreferences as aq, type Workflow as b, type ServeHandlerOptions as c, ChannelStepEnum as d, type CodeResult as e, type ClientOptions as f, type StepType as g, type DiscoverStepOutput as h, type ChannelPreference as i, type DiscoverWorkflowOutputPreferences as j, type DiscoverWorkflowOutput as k, type DiscoverOutput as l, type EventTriggerResult as m, type EventTriggerParams as n, type EventTriggerResponse as o, type CancelEventTriggerResponse as p, type Event as q, type State as r, type ExecuteOutputMetadata as s, type ExecuteOutputOptions as t, type ExecuteOutput as u, type SupportedFrameworkName as v, type Skip as w, type StepOptions as x, JobStatusEnum as y, type StepContext as z };
4737
+ export { type InAppOutput as $, ActionStepEnum as A, type ActionStep as B, Client as C, type DiscoverProviderOutput as D, type Execute as E, type FromSchemaUnvalidated as F, GetActionEnum as G, type HealthCheck as H, type CustomStep as I, type JsonSchema as J, type ChannelStep as K, type EmailOutput as L, type EmailOutputUnvalidated as M, NovuRequestHandler as N, type EmailResult as O, PostActionEnum as P, type SmsOutput as Q, type SmsOutputUnvalidated as R, type Schema as S, type SmsResult as T, type PushOutput as U, type PushOutputUnvalidated as V, type WorkflowOptions as W, type PushResult as X, type ChatOutput as Y, type ChatOutputUnvalidated as Z, type ChatResult as _, type FromSchema as a, type InAppOutputUnvalidated as a0, type InAppResult as a1, type DelayOutput as a2, type DelayOutputUnvalidated as a3, type DelayResult as a4, type DigestRegularOutput as a5, type DigestRegularOutputUnvalidated as a6, type DigestTimedOutput as a7, type DigestTimedOutputUnvalidated as a8, type DigestOutput as a9, type DigestOutputUnvalidated as aa, type DigestResult as ab, type Step as ac, type Subscriber as ad, type Either as ae, type Awaitable as af, type Prettify as ag, type ConditionalPartial as ah, type Indexable as ai, type PickOptional as aj, type PickRequired as ak, type PickRequiredKeys as al, type PickOptionalKeys as am, type DeepPartial as an, type ExecuteInput as ao, type ChannelPreference as ap, type WorkflowPreferences as aq, type Workflow as b, type ServeHandlerOptions as c, ChannelStepEnum as d, WorkflowChannelEnum as e, type CodeResult as f, type ClientOptions as g, type StepType as h, type DiscoverStepOutput as i, type DiscoverWorkflowOutput as j, type DiscoverOutput as k, type EventTriggerResult as l, type EventTriggerParams as m, type EventTriggerResponse as n, type CancelEventTriggerResponse as o, type Event as p, type State as q, type ExecuteOutputMetadata as r, type ExecuteOutputOptions as s, type ExecuteOutput as t, type SupportedFrameworkName as u, type Skip as v, type StepOptions as w, JobStatusEnum as x, type StepContext as y, type StepOutput as z };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as Schema, F as FromSchemaUnvalidated, a as FromSchema, J as JsonSchema, E as Execute, W as WorkflowOptions, b as Workflow } from './handler-xDdUZXcL.js';
2
- export { I as ActionStep, A as ActionStepEnum, ag as Awaitable, p as CancelEventTriggerResponse, i as ChannelPreference, L as ChannelStep, d as ChannelStepEnum, Z as ChatOutput, _ as ChatOutputUnvalidated, $ as ChatResult, C as Client, f as ClientOptions, e as CodeResult, ai as ConditionalPartial, K as CustomStep, a3 as DelayOutput, a4 as DelayOutputUnvalidated, a5 as DelayResult, aa as DigestOutput, ab as DigestOutputUnvalidated, a6 as DigestRegularOutput, a7 as DigestRegularOutputUnvalidated, ac as DigestResult, a8 as DigestTimedOutput, a9 as DigestTimedOutputUnvalidated, l as DiscoverOutput, D as DiscoverProviderOutput, h as DiscoverStepOutput, k as DiscoverWorkflowOutput, j as DiscoverWorkflowOutputPreferences, af as Either, M as EmailOutput, O as EmailOutputUnvalidated, Q as EmailResult, q as Event, n as EventTriggerParams, o as EventTriggerResponse, m as EventTriggerResult, ao as ExecuteInput, u as ExecuteOutput, s as ExecuteOutputMetadata, t as ExecuteOutputOptions, G as GetActionEnum, H as HealthCheck, a0 as InAppOutput, a1 as InAppOutputUnvalidated, a2 as InAppResult, aj as Indexable, y as JobStatusEnum, N as NovuRequestHandler, ak as PickOptional, an as PickOptionalKeys, al as PickRequired, am as PickRequiredKeys, P as PostActionEnum, ah as Prettify, V as PushOutput, X as PushOutputUnvalidated, Y as PushResult, c as ServeHandlerOptions, w as Skip, R as SmsOutput, T as SmsOutputUnvalidated, U as SmsResult, r as State, ad as Step, z as StepContext, x as StepOptions, B as StepOutput, g as StepType, ae as Subscriber, v as SupportedFrameworkName, ap as WorkflowOptionChannelPreference, aq as WorkflowOptionsPreferences } from './handler-xDdUZXcL.js';
1
+ import { S as Schema, F as FromSchemaUnvalidated, a as FromSchema, J as JsonSchema, E as Execute, W as WorkflowOptions, b as Workflow } from './handler-8vDLpUDh.js';
2
+ export { B as ActionStep, A as ActionStepEnum, af as Awaitable, o as CancelEventTriggerResponse, ap as ChannelPreference, K as ChannelStep, d as ChannelStepEnum, Y as ChatOutput, Z as ChatOutputUnvalidated, _ as ChatResult, C as Client, g as ClientOptions, f as CodeResult, ah as ConditionalPartial, I as CustomStep, an as DeepPartial, a2 as DelayOutput, a3 as DelayOutputUnvalidated, a4 as DelayResult, a9 as DigestOutput, aa as DigestOutputUnvalidated, a5 as DigestRegularOutput, a6 as DigestRegularOutputUnvalidated, ab as DigestResult, a7 as DigestTimedOutput, a8 as DigestTimedOutputUnvalidated, k as DiscoverOutput, D as DiscoverProviderOutput, i as DiscoverStepOutput, j as DiscoverWorkflowOutput, ae as Either, L as EmailOutput, M as EmailOutputUnvalidated, O as EmailResult, p as Event, m as EventTriggerParams, n as EventTriggerResponse, l as EventTriggerResult, ao as ExecuteInput, t as ExecuteOutput, r as ExecuteOutputMetadata, s as ExecuteOutputOptions, G as GetActionEnum, H as HealthCheck, $ as InAppOutput, a0 as InAppOutputUnvalidated, a1 as InAppResult, ai as Indexable, x as JobStatusEnum, N as NovuRequestHandler, aj as PickOptional, am as PickOptionalKeys, ak as PickRequired, al as PickRequiredKeys, P as PostActionEnum, ag as Prettify, U as PushOutput, V as PushOutputUnvalidated, X as PushResult, c as ServeHandlerOptions, v as Skip, Q as SmsOutput, R as SmsOutputUnvalidated, T as SmsResult, q as State, ac as Step, y as StepContext, w as StepOptions, z as StepOutput, h as StepType, ad as Subscriber, u as SupportedFrameworkName, e as WorkflowChannelEnum, aq as WorkflowPreferences } from './handler-8vDLpUDh.js';
3
3
  import { ValidateFunction as ValidateFunction$1 } from 'ajv';
4
4
  import { ParseReturnType } from 'zod';
5
5
  import '@novu/shared';