@novu/framework 2.0.3 → 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 { TriggerEventStatusEnum, ITriggerPayload, TriggerRecipientSubscriber, TriggerRecipientsPayload, ChannelTypeEnum } 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,10 @@ 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
+ */
58
62
  declare enum WorkflowChannelEnum {
59
63
  EMAIL = "email",
60
64
  SMS = "sms",
@@ -4058,6 +4062,12 @@ type PickRequiredKeys<T, DEEP extends boolean = true> = keyof PickRequired<T, DE
4058
4062
  * Optionally, recurses through nested objects if `DEEP` is true.
4059
4063
  */
4060
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;
4061
4071
 
4062
4072
  type Passthrough = {
4063
4073
  body?: Record<string, unknown>;
@@ -4317,14 +4327,42 @@ type ExecuteInput<T_Payload extends Record<string, unknown>, T_Controls extends
4317
4327
  * The function to execute the workflow.
4318
4328
  */
4319
4329
  type Execute<T_Payload extends Record<string, unknown>, T_Controls extends Record<string, unknown>> = (event: ExecuteInput<T_Payload, T_Controls>) => Promise<void>;
4320
- type WorkflowOptionChannelPreference = {
4321
- defaultValue?: boolean;
4322
- readOnly?: boolean;
4323
- };
4324
- type WorkflowOptionsPreferences = {
4325
- workflow?: WorkflowOptionChannelPreference;
4326
- channels?: Partial<Record<WorkflowChannelEnum, WorkflowOptionChannelPreference>>;
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;
4327
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
+ }>;
4328
4366
  /**
4329
4367
  * The options for the workflow.
4330
4368
  */
@@ -4337,8 +4375,63 @@ type WorkflowOptions<T_PayloadSchema extends Schema, T_ControlSchema extends Sch
4337
4375
  * @deprecated Use `controlSchema` instead
4338
4376
  */
4339
4377
  inputSchema?: T_ControlSchema;
4378
+ /** The schema for the controls. */
4340
4379
  controlSchema?: T_ControlSchema;
4341
- 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. */
4342
4435
  tags?: string[];
4343
4436
  };
4344
4437
 
@@ -4456,16 +4549,6 @@ type DiscoverStepOutput = {
4456
4549
  providers: Array<DiscoverProviderOutput>;
4457
4550
  options: StepOptions;
4458
4551
  };
4459
- type ChannelPreference = {
4460
- defaultValue: boolean;
4461
- readOnly: boolean;
4462
- };
4463
- type DiscoverWorkflowOutputPreferences = {
4464
- workflow: ChannelPreference;
4465
- channels: {
4466
- [key in (typeof ChannelTypeEnum)[keyof typeof ChannelTypeEnum]]: ChannelPreference;
4467
- };
4468
- };
4469
4552
  type DiscoverWorkflowOutput = {
4470
4553
  workflowId: string;
4471
4554
  execute: Execute<Record<string, unknown>, Record<string, unknown>>;
@@ -4490,7 +4573,7 @@ type DiscoverWorkflowOutput = {
4490
4573
  schema: JsonSchema;
4491
4574
  unknownSchema: Schema;
4492
4575
  };
4493
- preferences: DiscoverWorkflowOutputPreferences;
4576
+ preferences: WorkflowPreferencesPartial;
4494
4577
  tags: string[];
4495
4578
  };
4496
4579
  type Workflow<T_Payload = any> = {
@@ -4651,4 +4734,4 @@ declare class NovuRequestHandler<Input extends any[] = any[], Output = any> {
4651
4734
  private hashHmac;
4652
4735
  }
4653
4736
 
4654
- export { type ChatOutputUnvalidated as $, ActionStepEnum as A, type StepContext 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 StepOutput as I, type JsonSchema as J, type ActionStep as K, type CustomStep as L, type ChannelStep as M, NovuRequestHandler as N, type EmailOutput as O, PostActionEnum as P, type EmailOutputUnvalidated as Q, type EmailResult as R, type Schema as S, type SmsOutput as T, type SmsOutputUnvalidated as U, type SmsResult as V, type WorkflowOptions as W, type PushOutput as X, type PushOutputUnvalidated as Y, type PushResult as Z, type ChatOutput as _, type FromSchema as a, type ChatResult as a0, type InAppOutput as a1, type InAppOutputUnvalidated as a2, type InAppResult as a3, type DelayOutput as a4, type DelayOutputUnvalidated as a5, type DelayResult as a6, type DigestRegularOutput as a7, type DigestRegularOutputUnvalidated as a8, type DigestTimedOutput as a9, type DigestTimedOutputUnvalidated as aa, type DigestOutput as ab, type DigestOutputUnvalidated as ac, type DigestResult as ad, type Step as ae, type Subscriber as af, type Either as ag, type Awaitable as ah, type Prettify as ai, type ConditionalPartial as aj, type Indexable as ak, type PickOptional as al, type PickRequired as am, type PickRequiredKeys as an, type PickOptionalKeys as ao, type ExecuteInput as ap, type WorkflowOptionChannelPreference as aq, type WorkflowOptionsPreferences as ar, 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 ChannelPreference as j, type DiscoverWorkflowOutputPreferences as k, type DiscoverWorkflowOutput as l, type DiscoverOutput as m, type EventTriggerResult as n, type EventTriggerParams as o, type EventTriggerResponse as p, type CancelEventTriggerResponse as q, type Event as r, type State as s, type ExecuteOutputMetadata as t, type ExecuteOutputOptions as u, type ExecuteOutput as v, type SupportedFrameworkName as w, type Skip as x, type StepOptions as y, JobStatusEnum 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-WKKD7ESp.js';
2
- export { K as ActionStep, A as ActionStepEnum, ah as Awaitable, q as CancelEventTriggerResponse, j as ChannelPreference, M as ChannelStep, d as ChannelStepEnum, _ as ChatOutput, $ as ChatOutputUnvalidated, a0 as ChatResult, C as Client, g as ClientOptions, f as CodeResult, aj as ConditionalPartial, L as CustomStep, a4 as DelayOutput, a5 as DelayOutputUnvalidated, a6 as DelayResult, ab as DigestOutput, ac as DigestOutputUnvalidated, a7 as DigestRegularOutput, a8 as DigestRegularOutputUnvalidated, ad as DigestResult, a9 as DigestTimedOutput, aa as DigestTimedOutputUnvalidated, m as DiscoverOutput, D as DiscoverProviderOutput, i as DiscoverStepOutput, l as DiscoverWorkflowOutput, k as DiscoverWorkflowOutputPreferences, ag as Either, O as EmailOutput, Q as EmailOutputUnvalidated, R as EmailResult, r as Event, o as EventTriggerParams, p as EventTriggerResponse, n as EventTriggerResult, ap as ExecuteInput, v as ExecuteOutput, t as ExecuteOutputMetadata, u as ExecuteOutputOptions, G as GetActionEnum, H as HealthCheck, a1 as InAppOutput, a2 as InAppOutputUnvalidated, a3 as InAppResult, ak as Indexable, z as JobStatusEnum, N as NovuRequestHandler, al as PickOptional, ao as PickOptionalKeys, am as PickRequired, an as PickRequiredKeys, P as PostActionEnum, ai as Prettify, X as PushOutput, Y as PushOutputUnvalidated, Z as PushResult, c as ServeHandlerOptions, x as Skip, T as SmsOutput, U as SmsOutputUnvalidated, V as SmsResult, s as State, ae as Step, B as StepContext, y as StepOptions, I as StepOutput, h as StepType, af as Subscriber, w as SupportedFrameworkName, e as WorkflowChannelEnum, aq as WorkflowOptionChannelPreference, ar as WorkflowOptionsPreferences } from './handler-WKKD7ESp.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';