@novu/js 3.15.0 → 3.17.0-rc.d0046861c6

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.
@@ -6,32 +6,6 @@ type HttpClientOptions = {
6
6
  headers?: Record<string, string>;
7
7
  };
8
8
 
9
- declare class SubscriptionsCache {
10
- #private;
11
- constructor({ emitterInstance, inboxServiceInstance, useCache, }: {
12
- emitterInstance: NovuEventEmitter;
13
- inboxServiceInstance: InboxService;
14
- useCache: boolean;
15
- });
16
- private handleCreate;
17
- private handleUpdate;
18
- private handlePreferenceUpdate;
19
- private handleBulkPreferenceUpdate;
20
- private updateSubscriptionPreferences;
21
- private createUpdatedSubscription;
22
- private handleDelete;
23
- private handleDeleteByIdentifier;
24
- has(args: ListSubscriptionsArgs): boolean;
25
- set(args: ListSubscriptionsArgs, data: TopicSubscription[]): void;
26
- setOne(args: GetSubscriptionArgs, data: TopicSubscription): void;
27
- getAll(args: ListSubscriptionsArgs): TopicSubscription[] | undefined;
28
- get(args: GetSubscriptionArgs): TopicSubscription | undefined;
29
- invalidate(args: {
30
- topicKey: string;
31
- }): void;
32
- clearAll(): void;
33
- }
34
-
35
9
  declare class NovuError extends Error {
36
10
  originalError: Error;
37
11
  constructor(message: string, originalError: unknown);
@@ -121,280 +95,117 @@ declare class Preference {
121
95
  }>): Result<Preference>;
122
96
  }
123
97
 
124
- declare global {
125
- /**
126
- * If you want to provide custom types for the notification.data object,
127
- * simply redeclare this rule in the global namespace.
128
- * Every notification object will use the provided type.
129
- */
130
- interface NotificationData {
131
- [k: string]: unknown;
132
- }
133
- }
134
- declare enum NotificationStatus {
135
- READ = "read",
136
- SEEN = "seen",
137
- SNOOZED = "snoozed",
138
- UNREAD = "unread",
139
- UNSEEN = "unseen",
140
- UNSNOOZED = "unsnoozed"
141
- }
142
- declare enum PreferenceLevel {
143
- GLOBAL = "global",
144
- TEMPLATE = "template"
145
- }
146
- declare enum ChannelType {
147
- IN_APP = "in_app",
148
- EMAIL = "email",
149
- SMS = "sms",
150
- CHAT = "chat",
151
- PUSH = "push"
152
- }
153
- declare enum WebSocketEvent {
154
- RECEIVED = "notification_received",
155
- UNREAD = "unread_count_changed",
156
- UNSEEN = "unseen_count_changed"
157
- }
158
- type SocketTypeOption = 'cloud' | 'self-hosted';
159
- type NovuSocketOptions = {
160
- socketType?: SocketTypeOption;
161
- [key: string]: unknown;
162
- };
163
- declare enum SeverityLevelEnum {
164
- HIGH = "high",
165
- MEDIUM = "medium",
166
- LOW = "low",
167
- NONE = "none"
168
- }
169
- declare enum WorkflowCriticalityEnum {
170
- CRITICAL = "critical",
171
- NON_CRITICAL = "nonCritical",
172
- ALL = "all"
173
- }
174
- type UnreadCount = {
175
- total: number;
176
- severity: Record<SeverityLevelEnum, number>;
98
+ type KeylessInitializeSessionArgs = {} & {
99
+ [K in string]?: never;
177
100
  };
178
- type Session = {
179
- token: string;
180
- /** @deprecated Use unreadCount.total instead */
181
- totalUnreadCount: number;
182
- unreadCount: UnreadCount;
183
- removeNovuBranding: boolean;
184
- isDevelopmentMode: boolean;
185
- maxSnoozeDurationHours: number;
186
- applicationIdentifier?: string;
187
- contextKeys?: string[];
101
+ type InitializeSessionArgs = KeylessInitializeSessionArgs | {
102
+ applicationIdentifier: string;
103
+ subscriber: Subscriber;
104
+ subscriberHash?: string;
105
+ contextHash?: string;
106
+ defaultSchedule?: DefaultSchedule;
107
+ context?: Context;
188
108
  };
189
- type Subscriber = {
190
- id?: string;
191
- subscriberId: string;
192
- firstName?: string;
193
- lastName?: string;
194
- email?: string;
195
- phone?: string;
196
- avatar?: string;
197
- locale?: string;
198
- data?: Record<string, unknown>;
199
- timezone?: string;
109
+
110
+ declare class SubscriptionPreference {
111
+ #private;
112
+ readonly subscriptionId: string;
113
+ readonly workflow: Workflow;
114
+ readonly enabled: boolean;
115
+ readonly condition?: RulesLogic;
116
+ constructor(preference: SubscriptionPreferenceResponse, emitter: NovuEventEmitter, inboxService: InboxService, cache: SubscriptionsCache, useCache?: boolean);
117
+ update(args: {
118
+ value: boolean | RulesLogic;
119
+ }): Result<SubscriptionPreference>;
120
+ }
121
+
122
+ type WorkflowIdentifierOrId = string;
123
+ type WorkflowFilter = {
124
+ workflowId: WorkflowIdentifierOrId;
125
+ enabled?: boolean;
126
+ condition?: RulesLogic;
127
+ filter?: never;
200
128
  };
201
- type Redirect = {
202
- url: string;
203
- target?: '_self' | '_blank' | '_parent' | '_top' | '_unfencedTop';
129
+ type WorkflowGroupFilter = {
130
+ filter: {
131
+ workflowIds?: Array<WorkflowIdentifierOrId>;
132
+ tags?: string[];
133
+ };
134
+ enabled?: boolean;
135
+ condition?: RulesLogic;
136
+ workflowId?: never;
204
137
  };
205
- declare enum ActionTypeEnum {
206
- PRIMARY = "primary",
207
- SECONDARY = "secondary"
208
- }
209
- type Action = {
210
- label: string;
211
- isCompleted: boolean;
212
- redirect?: Redirect;
138
+ type PreferenceFilter = WorkflowIdentifierOrId | WorkflowFilter | WorkflowGroupFilter;
139
+ type ListSubscriptionsArgs = {
140
+ topicKey: string;
213
141
  };
214
- type Workflow = {
215
- id: string;
216
- identifier: string;
217
- name: string;
218
- critical: boolean;
142
+ type GetSubscriptionArgs = {
143
+ topicKey: string;
144
+ identifier?: string;
145
+ workflowIds?: string[];
219
146
  tags?: string[];
220
- severity: SeverityLevelEnum;
221
147
  };
222
- type TagsFilterOrGroup = {
223
- or: string[];
148
+ type CreateSubscriptionArgs = {
149
+ topicKey: string;
150
+ topicName?: string;
151
+ identifier?: string;
152
+ name?: string;
153
+ preferences?: Array<PreferenceFilter> | undefined;
224
154
  };
225
- type TagsFilterAndForm = {
226
- and: TagsFilterOrGroup[];
155
+ type BaseUpdateSubscriptionArgs = {
156
+ topicKey: string;
157
+ identifier: string;
158
+ name?: string;
159
+ preferences?: Array<PreferenceFilter>;
227
160
  };
228
- /**
229
- * Inbox tag filter: a **single** OR-group as `string[]` or `{ or: string[] }`, or **multiple** OR-groups (AND of OR) as `{ and: [{ or: string[] }, ...] }`.
230
- *
231
- * @example Single OR-group — match notifications tagged `promo` **or** `sale`
232
- * ```ts
233
- * const tags: TagsFilter = ['promo', 'sale'];
234
- * ```
235
- *
236
- * @example AND of OR-groups — match (`urgent` **or** `critical`) **and** (`billing`)
237
- * ```ts
238
- * const tags: TagsFilter = {
239
- * and: [{ or: ['urgent', 'critical'] }, { or: ['billing'] }],
240
- * };
241
- * ```
242
- */
243
- type TagsFilter = string[] | TagsFilterOrGroup | TagsFilterAndForm;
244
- type InboxNotification = {
245
- id: string;
246
- transactionId: string;
247
- subject?: string;
248
- body: string;
249
- to: Subscriber;
250
- isRead: boolean;
251
- isSeen: boolean;
252
- isArchived: boolean;
253
- isSnoozed: boolean;
254
- snoozedUntil?: string | null;
255
- deliveredAt?: string[];
256
- createdAt: string;
257
- readAt?: string | null;
258
- firstSeenAt?: string | null;
259
- archivedAt?: string | null;
260
- avatar?: string;
261
- primaryAction?: Action;
262
- secondaryAction?: Action;
263
- channelType: ChannelType;
264
- tags?: string[];
265
- data?: NotificationData;
266
- redirect?: Redirect;
267
- workflow?: Workflow;
268
- severity: SeverityLevelEnum;
161
+ type InstanceUpdateSubscriptionArgs = {
162
+ subscription: TopicSubscription;
163
+ name?: string;
164
+ preferences?: Array<PreferenceFilter>;
269
165
  };
270
- type NotificationFilter = {
271
- tags?: TagsFilter;
272
- read?: boolean;
273
- archived?: boolean;
274
- snoozed?: boolean;
275
- seen?: boolean;
276
- data?: Record<string, unknown>;
277
- severity?: SeverityLevelEnum | SeverityLevelEnum[];
278
- createdGte?: number;
279
- createdLte?: number;
166
+ type UpdateSubscriptionArgs = BaseUpdateSubscriptionArgs | InstanceUpdateSubscriptionArgs;
167
+ type BaseSubscriptionPreferenceArgs = {
168
+ workflowId: string;
169
+ value: boolean | RulesLogic;
280
170
  };
281
- type ChannelPreference = {
282
- email?: boolean;
283
- sms?: boolean;
284
- in_app?: boolean;
285
- chat?: boolean;
286
- push?: boolean;
171
+ type InstanceSubscriptionPreferenceArgs = {
172
+ preference: SubscriptionPreference;
173
+ value: boolean | RulesLogic;
287
174
  };
288
- type TimeRange = {
289
- start: string;
290
- end: string;
175
+ type UpdateSubscriptionPreferenceArgs = BaseSubscriptionPreferenceArgs | InstanceSubscriptionPreferenceArgs;
176
+ type BaseDeleteSubscriptionArgs = {
177
+ identifier: string;
178
+ topicKey: string;
291
179
  };
292
- type DaySchedule = {
293
- isEnabled: boolean;
294
- hours?: Array<TimeRange>;
180
+ type InstanceDeleteSubscriptionArgs = {
181
+ subscription: TopicSubscription;
295
182
  };
296
- type WeeklySchedule = {
297
- monday?: DaySchedule;
298
- tuesday?: DaySchedule;
299
- wednesday?: DaySchedule;
300
- thursday?: DaySchedule;
301
- friday?: DaySchedule;
302
- saturday?: DaySchedule;
303
- sunday?: DaySchedule;
304
- };
305
- type DefaultSchedule = {
306
- isEnabled?: boolean;
307
- weeklySchedule?: WeeklySchedule;
308
- };
309
- type ContextValue = string | {
310
- id: string;
311
- data?: Record<string, unknown>;
312
- };
313
- type Context = Partial<Record<string, ContextValue>>;
314
- type PreferencesResponse = {
315
- level: PreferenceLevel;
316
- enabled: boolean;
317
- condition?: RulesLogic;
318
- subscriptionId?: string;
319
- channels: ChannelPreference;
320
- overrides?: IPreferenceOverride[];
321
- workflow?: Workflow;
322
- schedule?: {
323
- isEnabled: boolean;
324
- weeklySchedule?: WeeklySchedule;
325
- };
326
- };
327
- declare enum PreferenceOverrideSourceEnum {
328
- SUBSCRIBER = "subscriber",
329
- TEMPLATE = "template",
330
- WORKFLOW_OVERRIDE = "workflowOverride"
331
- }
332
- type IPreferenceOverride = {
333
- channel: ChannelType;
334
- source: PreferenceOverrideSourceEnum;
335
- };
336
- type SubscriptionPreferenceResponse = Omit<PreferencesResponse, 'subscriptionId' | 'workflow' | 'schedule' | 'level' | 'channels'> & {
337
- subscriptionId: string;
338
- workflow: Workflow;
339
- };
340
- type SubscriptionResponse = {
341
- id: string;
342
- identifier: string;
343
- name?: string;
344
- preferences?: Array<SubscriptionPreferenceResponse>;
345
- };
346
- type Options = {
347
- refetch?: boolean;
348
- useCache?: boolean;
349
- };
350
- type Result<D = undefined, E = NovuError> = Promise<{
351
- data?: D;
352
- error?: E;
353
- }>;
354
- type KeylessNovuOptions = {} & {
355
- [K in string]?: never;
356
- };
357
- type StandardNovuOptions = {
358
- /** @deprecated Use apiUrl instead */
359
- backendUrl?: string;
360
- applicationIdentifier: string;
361
- subscriberHash?: string;
362
- contextHash?: string;
363
- apiUrl?: string;
364
- socketUrl?: string;
365
- /**
366
- * Custom socket configuration options. These options will be merged with the default socket configuration.
367
- * Use `socketType` to explicitly select the socket implementation: `'cloud'` for PartySocket or `'self-hosted'` for socket.io.
368
- * For socket.io-client connections, supports all socket.io-client options (e.g., `path`, `reconnectionDelay`, `timeout`, etc.).
369
- * For PartySocket connections, options are applied to the WebSocket instance.
370
- */
371
- socketOptions?: NovuSocketOptions;
372
- useCache?: boolean;
373
- defaultSchedule?: DefaultSchedule;
374
- context?: Context;
375
- } & ({
376
- /** @deprecated Use subscriber prop instead */
377
- subscriberId: string;
378
- subscriber?: never;
379
- } | {
380
- subscriber: Subscriber | string;
381
- subscriberId?: never;
382
- });
383
- type NovuOptions = KeylessNovuOptions | StandardNovuOptions;
384
- type Prettify<T> = {
385
- [K in keyof T]: T[K];
386
- } & {};
183
+ type DeleteSubscriptionArgs = BaseDeleteSubscriptionArgs | InstanceDeleteSubscriptionArgs;
387
184
 
388
- declare class SubscriptionPreference {
185
+ declare class SubscriptionsCache {
389
186
  #private;
390
- readonly subscriptionId: string;
391
- readonly workflow: Workflow;
392
- readonly enabled: boolean;
393
- readonly condition?: RulesLogic;
394
- constructor(preference: SubscriptionPreferenceResponse, emitter: NovuEventEmitter, inboxService: InboxService, cache: SubscriptionsCache, useCache?: boolean);
395
- update(args: {
396
- value: boolean | RulesLogic;
397
- }): Result<SubscriptionPreference>;
187
+ constructor({ emitterInstance, inboxServiceInstance, useCache, }: {
188
+ emitterInstance: NovuEventEmitter;
189
+ inboxServiceInstance: InboxService;
190
+ useCache: boolean;
191
+ });
192
+ private handleCreate;
193
+ private handleUpdate;
194
+ private handlePreferenceUpdate;
195
+ private handleBulkPreferenceUpdate;
196
+ private updateSubscriptionPreferences;
197
+ private createUpdatedSubscription;
198
+ private handleDelete;
199
+ private handleDeleteByIdentifier;
200
+ has(args: ListSubscriptionsArgs): boolean;
201
+ set(args: ListSubscriptionsArgs, data: TopicSubscription[]): void;
202
+ setOne(args: GetSubscriptionArgs, data: TopicSubscription): void;
203
+ getAll(args: ListSubscriptionsArgs): TopicSubscription[] | undefined;
204
+ get(args: GetSubscriptionArgs): TopicSubscription | undefined;
205
+ invalidate(args: {
206
+ topicKey: string;
207
+ }): void;
208
+ clearAll(): void;
398
209
  }
399
210
 
400
211
  declare class TopicSubscription {
@@ -415,214 +226,145 @@ declare class TopicSubscription {
415
226
  delete(): Result<void>;
416
227
  }
417
228
 
418
- type WorkflowIdentifierOrId = string;
419
- type WorkflowFilter = {
420
- workflowId: WorkflowIdentifierOrId;
421
- enabled?: boolean;
422
- condition?: RulesLogic;
423
- filter?: never;
424
- };
425
- type WorkflowGroupFilter = {
426
- filter: {
427
- workflowIds?: Array<WorkflowIdentifierOrId>;
428
- tags?: string[];
429
- };
430
- enabled?: boolean;
431
- condition?: RulesLogic;
432
- workflowId?: never;
433
- };
434
- type PreferenceFilter = WorkflowIdentifierOrId | WorkflowFilter | WorkflowGroupFilter;
435
- type ListSubscriptionsArgs = {
436
- topicKey: string;
437
- };
438
- type GetSubscriptionArgs = {
439
- topicKey: string;
440
- identifier?: string;
441
- workflowIds?: string[];
442
- tags?: string[];
443
- };
444
- type CreateSubscriptionArgs = {
445
- topicKey: string;
446
- topicName?: string;
447
- identifier?: string;
448
- name?: string;
449
- preferences?: Array<PreferenceFilter> | undefined;
450
- };
451
- type BaseUpdateSubscriptionArgs = {
452
- topicKey: string;
453
- identifier: string;
454
- name?: string;
455
- preferences?: Array<PreferenceFilter>;
229
+ type NovuPendingEvent<A, D = undefined> = {
230
+ args: A;
231
+ data?: D;
456
232
  };
457
- type InstanceUpdateSubscriptionArgs = {
458
- subscription: TopicSubscription;
459
- name?: string;
460
- preferences?: Array<PreferenceFilter>;
233
+ type NovuResolvedEvent<A, D> = NovuPendingEvent<A, D> & {
234
+ error?: unknown;
461
235
  };
462
- type UpdateSubscriptionArgs = BaseUpdateSubscriptionArgs | InstanceUpdateSubscriptionArgs;
463
- type BaseSubscriptionPreferenceArgs = {
464
- workflowId: string;
465
- value: boolean | RulesLogic;
236
+ type EventName<T extends string> = `${T}.pending` | `${T}.resolved`;
237
+ type EventStatus<T extends string> = `${T extends `${infer _}.${infer __}.${infer V}` ? V : never}`;
238
+ type EventObject<K extends string, ARGS, DATA, EVENT_STATUS = EventStatus<K>> = EVENT_STATUS extends 'pending' ? NovuPendingEvent<ARGS, DATA> : NovuResolvedEvent<ARGS, DATA>;
239
+ type BaseEvents<T extends string, ARGS, DATA> = {
240
+ [key in `${EventName<T>}`]: EventObject<key, ARGS, DATA>;
466
241
  };
467
- type InstanceSubscriptionPreferenceArgs = {
468
- preference: SubscriptionPreference;
469
- value: boolean | RulesLogic;
242
+ type SessionInitializeEvents = BaseEvents<'session.initialize', InitializeSessionArgs, Session>;
243
+ type NotificationsFetchEvents = BaseEvents<'notifications.list', ListNotificationsArgs, ListNotificationsResponse>;
244
+ type NotificationsFetchCountEvents = BaseEvents<'notifications.count', CountArgs, CountResponse>;
245
+ type NotificationReadEvents = BaseEvents<'notification.read', ReadArgs, Notification>;
246
+ type NotificationUnreadEvents = BaseEvents<'notification.unread', UnreadArgs, Notification>;
247
+ type NotificationSeenEvents = BaseEvents<'notification.seen', SeenArgs, Notification>;
248
+ type NotificationArchiveEvents = BaseEvents<'notification.archive', ArchivedArgs, Notification>;
249
+ type NotificationUnarchiveEvents = BaseEvents<'notification.unarchive', UnarchivedArgs, Notification>;
250
+ type NotificationDeleteEvents = BaseEvents<'notification.delete', DeletedArgs, Notification>;
251
+ type NotificationSnoozeEvents = BaseEvents<'notification.snooze', SnoozeArgs, Notification>;
252
+ type NotificationUnsnoozeEvents = BaseEvents<'notification.unsnooze', UnsnoozeArgs, Notification>;
253
+ type NotificationCompleteActionEvents = BaseEvents<'notification.complete_action', CompleteArgs, Notification>;
254
+ type NotificationRevertActionEvents = BaseEvents<'notification.revert_action', RevertArgs, Notification>;
255
+ type NotificationsReadAllEvents = BaseEvents<'notifications.read_all', {
256
+ tags?: TagsFilter;
257
+ data?: Record<string, unknown>;
258
+ }, Notification[]>;
259
+ type NotificationsSeenAllEvents = BaseEvents<'notifications.seen_all', {
260
+ notificationIds: string[];
261
+ } | {
262
+ tags?: TagsFilter;
263
+ data?: Record<string, unknown>;
264
+ } | {}, Notification[]>;
265
+ type NotificationsArchivedAllEvents = BaseEvents<'notifications.archive_all', {
266
+ tags?: TagsFilter;
267
+ data?: Record<string, unknown>;
268
+ }, Notification[]>;
269
+ type NotificationsReadArchivedAllEvents = BaseEvents<'notifications.archive_all_read', {
270
+ tags?: TagsFilter;
271
+ data?: Record<string, unknown>;
272
+ }, Notification[]>;
273
+ type NotificationsDeletedAllEvents = BaseEvents<'notifications.delete_all', {
274
+ tags?: TagsFilter;
275
+ data?: Record<string, unknown>;
276
+ }, Notification[]>;
277
+ type PreferencesFetchEvents = BaseEvents<'preferences.list', ListPreferencesArgs, Preference[]>;
278
+ type PreferenceUpdateEvents = BaseEvents<'preference.update', UpdatePreferenceArgs, Preference>;
279
+ type PreferencesBulkUpdateEvents = BaseEvents<'preferences.bulk_update', Array<UpdatePreferenceArgs>, Preference[]>;
280
+ type PreferenceScheduleGetEvents = BaseEvents<'preference.schedule.get', undefined, Schedule>;
281
+ type PreferenceScheduleUpdateEvents = BaseEvents<'preference.schedule.update', UpdateScheduleArgs, Schedule>;
282
+ type SubscriptionsFetchEvents = BaseEvents<'subscriptions.list', ListSubscriptionsArgs, TopicSubscription[]>;
283
+ type SubscriptionGetEvents = BaseEvents<'subscription.get', GetSubscriptionArgs, TopicSubscription | null>;
284
+ type SubscriptionCreateEvents = BaseEvents<'subscription.create', CreateSubscriptionArgs, TopicSubscription>;
285
+ type SubscriptionUpdateEvents = BaseEvents<'subscription.update', UpdateSubscriptionArgs, TopicSubscription>;
286
+ type SubscriptionPreferenceUpdateEvents = BaseEvents<'subscription.preference.update', UpdateSubscriptionPreferenceArgs, SubscriptionPreference>;
287
+ type SubscriptionPreferencesBulkUpdateEvents = BaseEvents<'subscription.preferences.bulk_update', Array<UpdateSubscriptionPreferenceArgs & {
288
+ subscriptionId: string;
289
+ }>, SubscriptionPreference[]>;
290
+ type SubscriptionDeleteEvents = BaseEvents<'subscription.delete', DeleteSubscriptionArgs, void>;
291
+ type ChannelConnectionOAuthUrlEvents = BaseEvents<'channel-connection.oauth-url', GenerateChatOAuthUrlArgs, {
292
+ url: string;
293
+ }>;
294
+ type ChannelConnectionsFetchEvents = BaseEvents<'channel-connections.list', ListChannelConnectionsArgs, ChannelConnectionResponse[]>;
295
+ type ChannelConnectionGetEvents = BaseEvents<'channel-connection.get', GetChannelConnectionArgs, ChannelConnectionResponse | null>;
296
+ type ChannelConnectionDeleteEvents = BaseEvents<'channel-connection.delete', DeleteChannelConnectionArgs, void>;
297
+ type ChannelEndpointOAuthUrlEvents = BaseEvents<'channel-endpoint.oauth-url', GenerateLinkUserOAuthUrlArgs, {
298
+ url: string;
299
+ }>;
300
+ type ChannelEndpointsFetchEvents = BaseEvents<'channel-endpoints.list', ListChannelEndpointsArgs, ChannelEndpointResponse[]>;
301
+ type ChannelEndpointGetEvents = BaseEvents<'channel-endpoint.get', GetChannelEndpointArgs, ChannelEndpointResponse | null>;
302
+ type ChannelEndpointCreateEvents = BaseEvents<'channel-endpoint.create', CreateChannelEndpointArgs, ChannelEndpointResponse>;
303
+ type ChannelEndpointDeleteEvents = BaseEvents<'channel-endpoint.delete', DeleteChannelEndpointArgs, void>;
304
+ type SocketConnectEvents = BaseEvents<'socket.connect', {
305
+ socketUrl: string;
306
+ }, undefined>;
307
+ type NotificationReceivedEvent = `notifications.${WebSocketEvent.RECEIVED}`;
308
+ type NotificationUnseenEvent = `notifications.${WebSocketEvent.UNSEEN}`;
309
+ type NotificationUnreadEvent = `notifications.${WebSocketEvent.UNREAD}`;
310
+ type SocketEvents = {
311
+ [key in NotificationReceivedEvent]: {
312
+ result: Notification;
313
+ };
314
+ } & {
315
+ [key in NotificationUnseenEvent]: {
316
+ result: number;
317
+ };
318
+ } & {
319
+ [key in NotificationUnreadEvent]: {
320
+ result: {
321
+ total: number;
322
+ severity: Record<string, number>;
323
+ };
324
+ };
470
325
  };
471
- type UpdateSubscriptionPreferenceArgs = BaseSubscriptionPreferenceArgs | InstanceSubscriptionPreferenceArgs;
472
- type BaseDeleteSubscriptionArgs = {
473
- identifier: string;
474
- topicKey: string;
475
- };
476
- type InstanceDeleteSubscriptionArgs = {
477
- subscription: TopicSubscription;
478
- };
479
- type DeleteSubscriptionArgs = BaseDeleteSubscriptionArgs | InstanceDeleteSubscriptionArgs;
326
+ /**
327
+ * Events that are emitted by Novu Event Emitter.
328
+ *
329
+ * The event name consists of second pattern: module.action.status
330
+ * - module: the name of the module
331
+ * - action: the action that is being performed
332
+ * - status: the status of the action, could be pending or resolved
333
+ *
334
+ * Each event has a corresponding payload that is associated with the event:
335
+ * - pending: the args that are passed to the action and the optional optimistic value
336
+ * - resolved: the args that are passed to the action and the result of the action or the error that is thrown
337
+ */
338
+ type Events = SessionInitializeEvents & NotificationsFetchEvents & {
339
+ 'notifications.list.updated': {
340
+ data: ListNotificationsResponse;
341
+ };
342
+ } & NotificationsFetchCountEvents & PreferencesFetchEvents & {
343
+ 'preferences.list.updated': {
344
+ data: Preference[];
345
+ };
346
+ } & PreferenceUpdateEvents & PreferencesBulkUpdateEvents & PreferenceScheduleGetEvents & PreferenceScheduleUpdateEvents & {
347
+ 'preference.schedule.get.updated': {
348
+ data: Schedule;
349
+ };
350
+ } & SubscriptionsFetchEvents & SubscriptionGetEvents & SubscriptionCreateEvents & SubscriptionPreferenceUpdateEvents & SubscriptionUpdateEvents & SubscriptionPreferencesBulkUpdateEvents & SubscriptionDeleteEvents & {
351
+ 'subscriptions.list.updated': {
352
+ data: {
353
+ topicKey: string;
354
+ subscriptions: TopicSubscription[];
355
+ };
356
+ };
357
+ } & ChannelConnectionOAuthUrlEvents & ChannelConnectionsFetchEvents & ChannelConnectionGetEvents & ChannelConnectionDeleteEvents & ChannelEndpointOAuthUrlEvents & ChannelEndpointsFetchEvents & ChannelEndpointGetEvents & ChannelEndpointCreateEvents & ChannelEndpointDeleteEvents & SocketConnectEvents & SocketEvents & NotificationReadEvents & NotificationUnreadEvents & NotificationSeenEvents & NotificationArchiveEvents & NotificationUnarchiveEvents & NotificationDeleteEvents & NotificationSnoozeEvents & NotificationUnsnoozeEvents & NotificationCompleteActionEvents & NotificationRevertActionEvents & NotificationsReadAllEvents & NotificationsSeenAllEvents & NotificationsArchivedAllEvents & NotificationsReadArchivedAllEvents & NotificationsDeletedAllEvents;
358
+ type EventNames = keyof Events;
359
+ type SocketEventNames = keyof SocketEvents;
360
+ type EventHandler<T = unknown> = (event: T) => void;
480
361
 
481
- type InboxServiceOptions = HttpClientOptions;
482
- declare class InboxService {
362
+ declare class NovuEventEmitter {
483
363
  #private;
484
- isSessionInitialized: boolean;
485
- constructor(options?: InboxServiceOptions);
486
- initializeSession({ applicationIdentifier, subscriberHash, contextHash, subscriber, defaultSchedule, context, }: {
487
- applicationIdentifier?: string;
488
- subscriberHash?: string;
489
- contextHash?: string;
490
- subscriber?: Subscriber;
491
- defaultSchedule?: DefaultSchedule;
492
- context?: Context;
493
- }): Promise<Session>;
494
- fetchNotifications({ after, archived, limit, offset, read, tags, snoozed, seen, data, severity, createdGte, createdLte, }: {
495
- tags?: TagsFilter;
496
- read?: boolean;
497
- archived?: boolean;
498
- snoozed?: boolean;
499
- seen?: boolean;
500
- limit?: number;
501
- after?: string;
502
- offset?: number;
503
- data?: Record<string, unknown>;
504
- severity?: SeverityLevelEnum | SeverityLevelEnum[];
505
- createdGte?: number;
506
- createdLte?: number;
507
- }): Promise<{
508
- data: InboxNotification[];
509
- hasMore: boolean;
510
- filter: NotificationFilter;
511
- }>;
512
- count({ filters, }: {
513
- filters: Array<{
514
- tags?: TagsFilter;
515
- read?: boolean;
516
- archived?: boolean;
517
- snoozed?: boolean;
518
- seen?: boolean;
519
- data?: Record<string, unknown>;
520
- severity?: SeverityLevelEnum | SeverityLevelEnum[];
521
- }>;
522
- }): Promise<{
523
- data: Array<{
524
- count: number;
525
- filter: NotificationFilter;
526
- }>;
527
- }>;
528
- read(notificationId: string): Promise<InboxNotification>;
529
- unread(notificationId: string): Promise<InboxNotification>;
530
- archive(notificationId: string): Promise<InboxNotification>;
531
- unarchive(notificationId: string): Promise<InboxNotification>;
532
- snooze(notificationId: string, snoozeUntil: string): Promise<InboxNotification>;
533
- unsnooze(notificationId: string): Promise<InboxNotification>;
534
- readAll({ tags, data }: {
535
- tags?: TagsFilter;
536
- data?: Record<string, unknown>;
537
- }): Promise<void>;
538
- archiveAll({ tags, data }: {
539
- tags?: TagsFilter;
540
- data?: Record<string, unknown>;
541
- }): Promise<void>;
542
- archiveAllRead({ tags, data }: {
543
- tags?: TagsFilter;
544
- data?: Record<string, unknown>;
545
- }): Promise<void>;
546
- delete(notificationId: string): Promise<void>;
547
- deleteAll({ tags, data }: {
548
- tags?: TagsFilter;
549
- data?: Record<string, unknown>;
550
- }): Promise<void>;
551
- markAsSeen({ notificationIds, tags, data, }: {
552
- notificationIds?: string[];
553
- tags?: TagsFilter;
554
- data?: Record<string, unknown>;
555
- }): Promise<void>;
556
- seen(notificationId: string): Promise<void>;
557
- completeAction({ actionType, notificationId, }: {
558
- notificationId: string;
559
- actionType: ActionTypeEnum;
560
- }): Promise<InboxNotification>;
561
- revertAction({ actionType, notificationId, }: {
562
- notificationId: string;
563
- actionType: ActionTypeEnum;
564
- }): Promise<InboxNotification>;
565
- fetchPreferences({ tags, severity, criticality, }: {
566
- tags?: string[];
567
- severity?: SeverityLevelEnum | SeverityLevelEnum[];
568
- criticality: WorkflowCriticalityEnum;
569
- }): Promise<PreferencesResponse[]>;
570
- bulkUpdatePreferences(preferences: Array<{
571
- workflowId: string;
572
- } & ChannelPreference>): Promise<PreferencesResponse[]>;
573
- updateGlobalPreferences(preferences: ChannelPreference & {
574
- schedule?: {
575
- isEnabled?: boolean;
576
- weeklySchedule?: WeeklySchedule;
577
- };
578
- }): Promise<PreferencesResponse>;
579
- updateWorkflowPreferences({ workflowId, channels, }: {
580
- workflowId: string;
581
- channels: ChannelPreference;
582
- }): Promise<PreferencesResponse>;
583
- fetchGlobalPreferences(): Promise<PreferencesResponse>;
584
- triggerHelloWorldEvent(): Promise<unknown>;
585
- fetchSubscriptions(topicKey: string): Promise<SubscriptionResponse[]>;
586
- getSubscription(topicKey: string, identifier?: string, workflowIds?: string[], tags?: string[]): Promise<SubscriptionResponse | undefined>;
587
- createSubscription({ identifier, name, topicKey, topicName, preferences, }: {
588
- identifier?: string;
589
- name?: string;
590
- topicKey: string;
591
- topicName?: string;
592
- preferences?: Array<PreferenceFilter>;
593
- }): Promise<SubscriptionResponse>;
594
- updateSubscription({ topicKey, identifier, name, preferences, }: {
595
- topicKey: string;
596
- identifier: string;
597
- name?: string;
598
- preferences?: Array<PreferenceFilter>;
599
- }): Promise<SubscriptionResponse>;
600
- updateSubscriptionPreference({ subscriptionIdentifier, workflowId, enabled, condition, email, sms, in_app, chat, push, }: {
601
- subscriptionIdentifier: string;
602
- workflowId: string;
603
- enabled?: boolean;
604
- condition?: RulesLogic;
605
- email?: boolean;
606
- sms?: boolean;
607
- in_app?: boolean;
608
- chat?: boolean;
609
- push?: boolean;
610
- }): Promise<SubscriptionPreferenceResponse>;
611
- bulkUpdateSubscriptionPreferences(preferences: Array<{
612
- subscriptionIdentifier: string;
613
- workflowId: string;
614
- enabled?: boolean;
615
- condition?: RulesLogic;
616
- email?: boolean;
617
- sms?: boolean;
618
- in_app?: boolean;
619
- chat?: boolean;
620
- push?: boolean;
621
- }>): Promise<SubscriptionPreferenceResponse[]>;
622
- deleteSubscription({ topicKey, identifier }: {
623
- topicKey: string;
624
- identifier: string;
625
- }): Promise<void>;
364
+ constructor();
365
+ on<Key extends EventNames>(eventName: Key, listener: EventHandler<Events[Key]>): () => void;
366
+ off<Key extends EventNames>(eventName: Key, listener: EventHandler<Events[Key]>): void;
367
+ emit<Key extends EventNames>(type: Key, event?: Events[Key]): void;
626
368
  }
627
369
 
628
370
  declare class Notification implements Pick<NovuEventEmitter, 'on'>, InboxNotification {
@@ -747,144 +489,555 @@ type UnsnoozeArgs = BaseArgs | InstanceArgs;
747
489
  type CompleteArgs = BaseArgs | InstanceArgs;
748
490
  type RevertArgs = BaseArgs | InstanceArgs;
749
491
 
750
- type KeylessInitializeSessionArgs = {} & {
751
- [K in string]?: never;
492
+ declare global {
493
+ /**
494
+ * If you want to provide custom types for the notification.data object,
495
+ * simply redeclare this rule in the global namespace.
496
+ * Every notification object will use the provided type.
497
+ */
498
+ interface NotificationData {
499
+ [k: string]: unknown;
500
+ }
501
+ }
502
+ declare enum NotificationStatus {
503
+ READ = "read",
504
+ SEEN = "seen",
505
+ SNOOZED = "snoozed",
506
+ UNREAD = "unread",
507
+ UNSEEN = "unseen",
508
+ UNSNOOZED = "unsnoozed"
509
+ }
510
+ declare enum PreferenceLevel {
511
+ GLOBAL = "global",
512
+ TEMPLATE = "template"
513
+ }
514
+ declare enum ChannelType {
515
+ IN_APP = "in_app",
516
+ EMAIL = "email",
517
+ SMS = "sms",
518
+ CHAT = "chat",
519
+ PUSH = "push"
520
+ }
521
+ declare enum WebSocketEvent {
522
+ RECEIVED = "notification_received",
523
+ UNREAD = "unread_count_changed",
524
+ UNSEEN = "unseen_count_changed"
525
+ }
526
+ type SocketTypeOption = 'cloud' | 'self-hosted';
527
+ type NovuSocketOptions = {
528
+ socketType?: SocketTypeOption;
529
+ [key: string]: unknown;
752
530
  };
753
- type InitializeSessionArgs = KeylessInitializeSessionArgs | {
754
- applicationIdentifier: string;
755
- subscriber: Subscriber;
756
- subscriberHash?: string;
757
- contextHash?: string;
758
- defaultSchedule?: DefaultSchedule;
759
- context?: Context;
531
+ declare enum SeverityLevelEnum {
532
+ HIGH = "high",
533
+ MEDIUM = "medium",
534
+ LOW = "low",
535
+ NONE = "none"
536
+ }
537
+ declare enum WorkflowCriticalityEnum {
538
+ CRITICAL = "critical",
539
+ NON_CRITICAL = "nonCritical",
540
+ ALL = "all"
541
+ }
542
+ type UnreadCount = {
543
+ total: number;
544
+ severity: Record<SeverityLevelEnum, number>;
760
545
  };
761
-
762
- type NovuPendingEvent<A, D = undefined> = {
763
- args: A;
764
- data?: D;
546
+ type Session = {
547
+ token: string;
548
+ /** @deprecated Use unreadCount.total instead */
549
+ totalUnreadCount: number;
550
+ unreadCount: UnreadCount;
551
+ removeNovuBranding: boolean;
552
+ isDevelopmentMode: boolean;
553
+ maxSnoozeDurationHours: number;
554
+ applicationIdentifier?: string;
555
+ contextKeys?: string[];
765
556
  };
766
- type NovuResolvedEvent<A, D> = NovuPendingEvent<A, D> & {
767
- error?: unknown;
557
+ type Subscriber = {
558
+ id?: string;
559
+ subscriberId: string;
560
+ firstName?: string;
561
+ lastName?: string;
562
+ email?: string;
563
+ phone?: string;
564
+ avatar?: string;
565
+ locale?: string;
566
+ data?: Record<string, unknown>;
567
+ timezone?: string;
768
568
  };
769
- type EventName<T extends string> = `${T}.pending` | `${T}.resolved`;
770
- type EventStatus<T extends string> = `${T extends `${infer _}.${infer __}.${infer V}` ? V : never}`;
771
- type EventObject<K extends string, ARGS, DATA, EVENT_STATUS = EventStatus<K>> = EVENT_STATUS extends 'pending' ? NovuPendingEvent<ARGS, DATA> : NovuResolvedEvent<ARGS, DATA>;
772
- type BaseEvents<T extends string, ARGS, DATA> = {
773
- [key in `${EventName<T>}`]: EventObject<key, ARGS, DATA>;
569
+ type Redirect = {
570
+ url: string;
571
+ target?: '_self' | '_blank' | '_parent' | '_top' | '_unfencedTop';
774
572
  };
775
- type SessionInitializeEvents = BaseEvents<'session.initialize', InitializeSessionArgs, Session>;
776
- type NotificationsFetchEvents = BaseEvents<'notifications.list', ListNotificationsArgs, ListNotificationsResponse>;
777
- type NotificationsFetchCountEvents = BaseEvents<'notifications.count', CountArgs, CountResponse>;
778
- type NotificationReadEvents = BaseEvents<'notification.read', ReadArgs, Notification>;
779
- type NotificationUnreadEvents = BaseEvents<'notification.unread', UnreadArgs, Notification>;
780
- type NotificationSeenEvents = BaseEvents<'notification.seen', SeenArgs, Notification>;
781
- type NotificationArchiveEvents = BaseEvents<'notification.archive', ArchivedArgs, Notification>;
782
- type NotificationUnarchiveEvents = BaseEvents<'notification.unarchive', UnarchivedArgs, Notification>;
783
- type NotificationDeleteEvents = BaseEvents<'notification.delete', DeletedArgs, Notification>;
784
- type NotificationSnoozeEvents = BaseEvents<'notification.snooze', SnoozeArgs, Notification>;
785
- type NotificationUnsnoozeEvents = BaseEvents<'notification.unsnooze', UnsnoozeArgs, Notification>;
786
- type NotificationCompleteActionEvents = BaseEvents<'notification.complete_action', CompleteArgs, Notification>;
787
- type NotificationRevertActionEvents = BaseEvents<'notification.revert_action', RevertArgs, Notification>;
788
- type NotificationsReadAllEvents = BaseEvents<'notifications.read_all', {
789
- tags?: TagsFilter;
790
- data?: Record<string, unknown>;
791
- }, Notification[]>;
792
- type NotificationsSeenAllEvents = BaseEvents<'notifications.seen_all', {
793
- notificationIds: string[];
794
- } | {
795
- tags?: TagsFilter;
796
- data?: Record<string, unknown>;
797
- } | {}, Notification[]>;
798
- type NotificationsArchivedAllEvents = BaseEvents<'notifications.archive_all', {
799
- tags?: TagsFilter;
800
- data?: Record<string, unknown>;
801
- }, Notification[]>;
802
- type NotificationsReadArchivedAllEvents = BaseEvents<'notifications.archive_all_read', {
573
+ declare enum ActionTypeEnum {
574
+ PRIMARY = "primary",
575
+ SECONDARY = "secondary"
576
+ }
577
+ type Action = {
578
+ label: string;
579
+ isCompleted: boolean;
580
+ redirect?: Redirect;
581
+ };
582
+ type Workflow = {
583
+ id: string;
584
+ identifier: string;
585
+ name: string;
586
+ critical: boolean;
587
+ tags?: string[];
588
+ severity: SeverityLevelEnum;
589
+ };
590
+ type TagsFilterOrGroup = {
591
+ or: string[];
592
+ };
593
+ type TagsFilterAndForm = {
594
+ and: TagsFilterOrGroup[];
595
+ };
596
+ /**
597
+ * Inbox tag filter: a **single** OR-group as `string[]` or `{ or: string[] }`, or **multiple** OR-groups (AND of OR) as `{ and: [{ or: string[] }, ...] }`.
598
+ *
599
+ * @example Single OR-group — match notifications tagged `promo` **or** `sale`
600
+ * ```ts
601
+ * const tags: TagsFilter = ['promo', 'sale'];
602
+ * ```
603
+ *
604
+ * @example AND of OR-groups — match (`urgent` **or** `critical`) **and** (`billing`)
605
+ * ```ts
606
+ * const tags: TagsFilter = {
607
+ * and: [{ or: ['urgent', 'critical'] }, { or: ['billing'] }],
608
+ * };
609
+ * ```
610
+ */
611
+ type TagsFilter = string[] | TagsFilterOrGroup | TagsFilterAndForm;
612
+ type InboxNotification = {
613
+ id: string;
614
+ transactionId: string;
615
+ subject?: string;
616
+ body: string;
617
+ to: Subscriber;
618
+ isRead: boolean;
619
+ isSeen: boolean;
620
+ isArchived: boolean;
621
+ isSnoozed: boolean;
622
+ snoozedUntil?: string | null;
623
+ deliveredAt?: string[];
624
+ createdAt: string;
625
+ readAt?: string | null;
626
+ firstSeenAt?: string | null;
627
+ archivedAt?: string | null;
628
+ avatar?: string;
629
+ primaryAction?: Action;
630
+ secondaryAction?: Action;
631
+ channelType: ChannelType;
632
+ tags?: string[];
633
+ data?: NotificationData;
634
+ redirect?: Redirect;
635
+ workflow?: Workflow;
636
+ severity: SeverityLevelEnum;
637
+ };
638
+ type NotificationFilter = {
803
639
  tags?: TagsFilter;
640
+ read?: boolean;
641
+ archived?: boolean;
642
+ snoozed?: boolean;
643
+ seen?: boolean;
644
+ /**
645
+ * Filter notifications by keys in their `data` object.
646
+ *
647
+ * Each top-level key value can be:
648
+ * - a scalar (exact equality)
649
+ * - `Scalar[]` (OR — match any of the listed values)
650
+ * - `{ or: Scalar[] }` (explicit OR)
651
+ * - `{ and: [{ or: Scalar[] }, ...] }` (AND of OR-groups)
652
+ * - a 1-level nested object whose sub-keys follow the same rules
653
+ *
654
+ * Across keys clauses are AND-ed together.
655
+ */
804
656
  data?: Record<string, unknown>;
805
- }, Notification[]>;
806
- type NotificationsDeletedAllEvents = BaseEvents<'notifications.delete_all', {
807
- tags?: TagsFilter;
657
+ severity?: SeverityLevelEnum | SeverityLevelEnum[];
658
+ createdGte?: number;
659
+ createdLte?: number;
660
+ };
661
+ type ChannelPreference = {
662
+ email?: boolean;
663
+ sms?: boolean;
664
+ in_app?: boolean;
665
+ chat?: boolean;
666
+ push?: boolean;
667
+ };
668
+ type TimeRange = {
669
+ start: string;
670
+ end: string;
671
+ };
672
+ type DaySchedule = {
673
+ isEnabled: boolean;
674
+ hours?: Array<TimeRange>;
675
+ };
676
+ type WeeklySchedule = {
677
+ monday?: DaySchedule;
678
+ tuesday?: DaySchedule;
679
+ wednesday?: DaySchedule;
680
+ thursday?: DaySchedule;
681
+ friday?: DaySchedule;
682
+ saturday?: DaySchedule;
683
+ sunday?: DaySchedule;
684
+ };
685
+ type DefaultSchedule = {
686
+ isEnabled?: boolean;
687
+ weeklySchedule?: WeeklySchedule;
688
+ };
689
+ type ContextValue = string | {
690
+ id: string;
808
691
  data?: Record<string, unknown>;
809
- }, Notification[]>;
810
- type PreferencesFetchEvents = BaseEvents<'preferences.list', ListPreferencesArgs, Preference[]>;
811
- type PreferenceUpdateEvents = BaseEvents<'preference.update', UpdatePreferenceArgs, Preference>;
812
- type PreferencesBulkUpdateEvents = BaseEvents<'preferences.bulk_update', Array<UpdatePreferenceArgs>, Preference[]>;
813
- type PreferenceScheduleGetEvents = BaseEvents<'preference.schedule.get', undefined, Schedule>;
814
- type PreferenceScheduleUpdateEvents = BaseEvents<'preference.schedule.update', UpdateScheduleArgs, Schedule>;
815
- type SubscriptionsFetchEvents = BaseEvents<'subscriptions.list', ListSubscriptionsArgs, TopicSubscription[]>;
816
- type SubscriptionGetEvents = BaseEvents<'subscription.get', GetSubscriptionArgs, TopicSubscription | null>;
817
- type SubscriptionCreateEvents = BaseEvents<'subscription.create', CreateSubscriptionArgs, TopicSubscription>;
818
- type SubscriptionUpdateEvents = BaseEvents<'subscription.update', UpdateSubscriptionArgs, TopicSubscription>;
819
- type SubscriptionPreferenceUpdateEvents = BaseEvents<'subscription.preference.update', UpdateSubscriptionPreferenceArgs, SubscriptionPreference>;
820
- type SubscriptionPreferencesBulkUpdateEvents = BaseEvents<'subscription.preferences.bulk_update', Array<UpdateSubscriptionPreferenceArgs & {
821
- subscriptionId: string;
822
- }>, SubscriptionPreference[]>;
823
- type SubscriptionDeleteEvents = BaseEvents<'subscription.delete', DeleteSubscriptionArgs, void>;
824
- type SocketConnectEvents = BaseEvents<'socket.connect', {
825
- socketUrl: string;
826
- }, undefined>;
827
- type NotificationReceivedEvent = `notifications.${WebSocketEvent.RECEIVED}`;
828
- type NotificationUnseenEvent = `notifications.${WebSocketEvent.UNSEEN}`;
829
- type NotificationUnreadEvent = `notifications.${WebSocketEvent.UNREAD}`;
830
- type SocketEvents = {
831
- [key in NotificationReceivedEvent]: {
832
- result: Notification;
833
- };
834
- } & {
835
- [key in NotificationUnseenEvent]: {
836
- result: number;
837
- };
838
- } & {
839
- [key in NotificationUnreadEvent]: {
840
- result: {
841
- total: number;
842
- severity: Record<string, number>;
843
- };
692
+ };
693
+ type Context = Partial<Record<string, ContextValue>>;
694
+ type PreferencesResponse = {
695
+ level: PreferenceLevel;
696
+ enabled: boolean;
697
+ condition?: RulesLogic;
698
+ subscriptionId?: string;
699
+ channels: ChannelPreference;
700
+ overrides?: IPreferenceOverride[];
701
+ workflow?: Workflow;
702
+ schedule?: {
703
+ isEnabled: boolean;
704
+ weeklySchedule?: WeeklySchedule;
844
705
  };
845
706
  };
707
+ declare enum PreferenceOverrideSourceEnum {
708
+ SUBSCRIBER = "subscriber",
709
+ TEMPLATE = "template",
710
+ WORKFLOW_OVERRIDE = "workflowOverride"
711
+ }
712
+ type IPreferenceOverride = {
713
+ channel: ChannelType;
714
+ source: PreferenceOverrideSourceEnum;
715
+ };
716
+ type SubscriptionPreferenceResponse = Omit<PreferencesResponse, 'subscriptionId' | 'workflow' | 'schedule' | 'level' | 'channels'> & {
717
+ subscriptionId: string;
718
+ workflow: Workflow;
719
+ };
720
+ type SubscriptionResponse = {
721
+ id: string;
722
+ identifier: string;
723
+ name?: string;
724
+ preferences?: Array<SubscriptionPreferenceResponse>;
725
+ };
726
+ type Options = {
727
+ refetch?: boolean;
728
+ useCache?: boolean;
729
+ };
730
+ type Result<D = undefined, E = NovuError> = Promise<{
731
+ data?: D;
732
+ error?: E;
733
+ }>;
734
+ type KeylessNovuOptions = {} & {
735
+ [K in string]?: never;
736
+ };
737
+ type StandardNovuOptions = {
738
+ /** @deprecated Use apiUrl instead */
739
+ backendUrl?: string;
740
+ applicationIdentifier: string;
741
+ subscriberHash?: string;
742
+ contextHash?: string;
743
+ apiUrl?: string;
744
+ socketUrl?: string;
745
+ /**
746
+ * Custom socket configuration options. These options will be merged with the default socket configuration.
747
+ * Use `socketType` to explicitly select the socket implementation: `'cloud'` for PartySocket or `'self-hosted'` for socket.io.
748
+ * For socket.io-client connections, supports all socket.io-client options (e.g., `path`, `reconnectionDelay`, `timeout`, etc.).
749
+ * For PartySocket connections, options are applied to the WebSocket instance.
750
+ */
751
+ socketOptions?: NovuSocketOptions;
752
+ useCache?: boolean;
753
+ defaultSchedule?: DefaultSchedule;
754
+ context?: Context;
755
+ } & ({
756
+ /** @deprecated Use subscriber prop instead */
757
+ subscriberId: string;
758
+ subscriber?: never;
759
+ } | {
760
+ subscriber: Subscriber | string;
761
+ subscriberId?: never;
762
+ });
763
+ type NovuOptions = KeylessNovuOptions | StandardNovuOptions;
764
+ type Prettify<T> = {
765
+ [K in keyof T]: T[K];
766
+ } & {};
767
+
768
+ type ChannelConnectionResponse = {
769
+ identifier: string;
770
+ };
771
+ type ChannelEndpointResponse = {
772
+ identifier: string;
773
+ type: string;
774
+ };
775
+ type OAuthMode = 'connect' | 'link_user';
776
+ type ConnectionMode = 'subscriber' | 'shared';
846
777
  /**
847
- * Events that are emitted by Novu Event Emitter.
848
- *
849
- * The event name consists of second pattern: module.action.status
850
- * - module: the name of the module
851
- * - action: the action that is being performed
852
- * - status: the status of the action, could be pending or resolved
853
- *
854
- * Each event has a corresponding payload that is associated with the event:
855
- * - pending: the args that are passed to the action and the optional optimistic value
856
- * - resolved: the args that are passed to the action and the result of the action or the error that is thrown
778
+ * @deprecated Use GenerateConnectOAuthUrlArgs or GenerateLinkUserOAuthUrlArgs instead.
857
779
  */
858
- type Events = SessionInitializeEvents & NotificationsFetchEvents & {
859
- 'notifications.list.updated': {
860
- data: ListNotificationsResponse;
861
- };
862
- } & NotificationsFetchCountEvents & PreferencesFetchEvents & {
863
- 'preferences.list.updated': {
864
- data: Preference[];
865
- };
866
- } & PreferenceUpdateEvents & PreferencesBulkUpdateEvents & PreferenceScheduleGetEvents & PreferenceScheduleUpdateEvents & {
867
- 'preference.schedule.get.updated': {
868
- data: Schedule;
780
+ type GenerateChatOAuthUrlArgs = {
781
+ integrationIdentifier: string;
782
+ connectionIdentifier?: string;
783
+ subscriberId?: string;
784
+ context?: Context;
785
+ scope?: string[];
786
+ userScope?: string[];
787
+ mode?: OAuthMode;
788
+ connectionMode?: ConnectionMode;
789
+ autoLinkUser?: boolean;
790
+ };
791
+ /** Args for creating a workspace/tenant channel connection (Slack install or MS Teams admin consent). */
792
+ type GenerateConnectOAuthUrlArgs = {
793
+ integrationIdentifier: string;
794
+ connectionIdentifier?: string;
795
+ subscriberId?: string;
796
+ context?: Context;
797
+ /** Slack only: OAuth bot scopes to request. */
798
+ scope?: string[];
799
+ connectionMode?: ConnectionMode;
800
+ autoLinkUser?: boolean;
801
+ };
802
+ /** Args for linking a subscriber to their personal chat identity (Slack user or MS Teams user OID). */
803
+ type GenerateLinkUserOAuthUrlArgs = {
804
+ integrationIdentifier: string;
805
+ connectionIdentifier?: string;
806
+ /** Required — this operation always binds a specific subscriber to a user identity. */
807
+ subscriberId: string;
808
+ context?: Context;
809
+ /** Slack only: user-level OAuth scopes (e.g. identity.basic). */
810
+ userScope?: string[];
811
+ };
812
+ type ListChannelConnectionsArgs = {
813
+ subscriberId?: string;
814
+ integrationIdentifier?: string;
815
+ channel?: string;
816
+ providerId?: string;
817
+ contextKeys?: string[];
818
+ limit?: number;
819
+ after?: string;
820
+ before?: string;
821
+ };
822
+ type GetChannelConnectionArgs = {
823
+ identifier: string;
824
+ };
825
+ type CreateChannelConnectionArgs = {
826
+ identifier?: string;
827
+ integrationIdentifier: string;
828
+ subscriberId?: string;
829
+ context?: Context;
830
+ workspace: {
831
+ id: string;
832
+ name?: string;
869
833
  };
870
- } & SubscriptionsFetchEvents & SubscriptionGetEvents & SubscriptionCreateEvents & SubscriptionPreferenceUpdateEvents & SubscriptionUpdateEvents & SubscriptionPreferencesBulkUpdateEvents & SubscriptionDeleteEvents & {
871
- 'subscriptions.list.updated': {
872
- data: {
873
- topicKey: string;
874
- subscriptions: TopicSubscription[];
875
- };
834
+ auth: {
835
+ accessToken: string;
876
836
  };
877
- } & SocketConnectEvents & SocketEvents & NotificationReadEvents & NotificationUnreadEvents & NotificationSeenEvents & NotificationArchiveEvents & NotificationUnarchiveEvents & NotificationDeleteEvents & NotificationSnoozeEvents & NotificationUnsnoozeEvents & NotificationCompleteActionEvents & NotificationRevertActionEvents & NotificationsReadAllEvents & NotificationsSeenAllEvents & NotificationsArchivedAllEvents & NotificationsReadArchivedAllEvents & NotificationsDeletedAllEvents;
878
- type EventNames = keyof Events;
879
- type SocketEventNames = keyof SocketEvents;
880
- type EventHandler<T = unknown> = (event: T) => void;
837
+ };
838
+ type DeleteChannelConnectionArgs = {
839
+ identifier: string;
840
+ };
841
+ type ListChannelEndpointsArgs = {
842
+ subscriberId?: string;
843
+ integrationIdentifier?: string;
844
+ connectionIdentifier?: string;
845
+ channel?: string;
846
+ providerId?: string;
847
+ contextKeys?: string[];
848
+ limit?: number;
849
+ after?: string;
850
+ before?: string;
851
+ };
852
+ type GetChannelEndpointArgs = {
853
+ identifier: string;
854
+ };
855
+ type CreateChannelEndpointArgs = {
856
+ identifier?: string;
857
+ integrationIdentifier: string;
858
+ connectionIdentifier?: string;
859
+ subscriberId: string;
860
+ context?: Context;
861
+ type: string;
862
+ endpoint: Record<string, string>;
863
+ };
864
+ type DeleteChannelEndpointArgs = {
865
+ identifier: string;
866
+ };
881
867
 
882
- declare class NovuEventEmitter {
868
+ type InboxServiceOptions = HttpClientOptions;
869
+ declare class InboxService {
883
870
  #private;
884
- constructor();
885
- on<Key extends EventNames>(eventName: Key, listener: EventHandler<Events[Key]>): () => void;
886
- off<Key extends EventNames>(eventName: Key, listener: EventHandler<Events[Key]>): void;
887
- emit<Key extends EventNames>(type: Key, event?: Events[Key]): void;
871
+ isSessionInitialized: boolean;
872
+ constructor(options?: InboxServiceOptions);
873
+ initializeSession({ applicationIdentifier, subscriberHash, contextHash, subscriber, defaultSchedule, context, }: {
874
+ applicationIdentifier?: string;
875
+ subscriberHash?: string;
876
+ contextHash?: string;
877
+ subscriber?: Subscriber;
878
+ defaultSchedule?: DefaultSchedule;
879
+ context?: Context;
880
+ }): Promise<Session>;
881
+ fetchNotifications({ after, archived, limit, offset, read, tags, snoozed, seen, data, severity, createdGte, createdLte, }: {
882
+ tags?: TagsFilter;
883
+ read?: boolean;
884
+ archived?: boolean;
885
+ snoozed?: boolean;
886
+ seen?: boolean;
887
+ limit?: number;
888
+ after?: string;
889
+ offset?: number;
890
+ data?: Record<string, unknown>;
891
+ severity?: SeverityLevelEnum | SeverityLevelEnum[];
892
+ createdGte?: number;
893
+ createdLte?: number;
894
+ }): Promise<{
895
+ data: InboxNotification[];
896
+ hasMore: boolean;
897
+ filter: NotificationFilter;
898
+ }>;
899
+ count({ filters, }: {
900
+ filters: Array<{
901
+ tags?: TagsFilter;
902
+ read?: boolean;
903
+ archived?: boolean;
904
+ snoozed?: boolean;
905
+ seen?: boolean;
906
+ data?: Record<string, unknown>;
907
+ severity?: SeverityLevelEnum | SeverityLevelEnum[];
908
+ }>;
909
+ }): Promise<{
910
+ data: Array<{
911
+ count: number;
912
+ filter: NotificationFilter;
913
+ }>;
914
+ }>;
915
+ read(notificationId: string): Promise<InboxNotification>;
916
+ unread(notificationId: string): Promise<InboxNotification>;
917
+ archive(notificationId: string): Promise<InboxNotification>;
918
+ unarchive(notificationId: string): Promise<InboxNotification>;
919
+ snooze(notificationId: string, snoozeUntil: string): Promise<InboxNotification>;
920
+ unsnooze(notificationId: string): Promise<InboxNotification>;
921
+ readAll({ tags, data }: {
922
+ tags?: TagsFilter;
923
+ data?: Record<string, unknown>;
924
+ }): Promise<void>;
925
+ archiveAll({ tags, data }: {
926
+ tags?: TagsFilter;
927
+ data?: Record<string, unknown>;
928
+ }): Promise<void>;
929
+ archiveAllRead({ tags, data }: {
930
+ tags?: TagsFilter;
931
+ data?: Record<string, unknown>;
932
+ }): Promise<void>;
933
+ delete(notificationId: string): Promise<void>;
934
+ deleteAll({ tags, data }: {
935
+ tags?: TagsFilter;
936
+ data?: Record<string, unknown>;
937
+ }): Promise<void>;
938
+ markAsSeen({ notificationIds, tags, data, }: {
939
+ notificationIds?: string[];
940
+ tags?: TagsFilter;
941
+ data?: Record<string, unknown>;
942
+ }): Promise<void>;
943
+ seen(notificationId: string): Promise<void>;
944
+ completeAction({ actionType, notificationId, }: {
945
+ notificationId: string;
946
+ actionType: ActionTypeEnum;
947
+ }): Promise<InboxNotification>;
948
+ revertAction({ actionType, notificationId, }: {
949
+ notificationId: string;
950
+ actionType: ActionTypeEnum;
951
+ }): Promise<InboxNotification>;
952
+ fetchPreferences({ tags, severity, criticality, }: {
953
+ tags?: string[];
954
+ severity?: SeverityLevelEnum | SeverityLevelEnum[];
955
+ criticality: WorkflowCriticalityEnum;
956
+ }): Promise<PreferencesResponse[]>;
957
+ bulkUpdatePreferences(preferences: Array<{
958
+ workflowId: string;
959
+ } & ChannelPreference>): Promise<PreferencesResponse[]>;
960
+ updateGlobalPreferences(preferences: ChannelPreference & {
961
+ schedule?: {
962
+ isEnabled?: boolean;
963
+ weeklySchedule?: WeeklySchedule;
964
+ };
965
+ }): Promise<PreferencesResponse>;
966
+ updateWorkflowPreferences({ workflowId, channels, }: {
967
+ workflowId: string;
968
+ channels: ChannelPreference;
969
+ }): Promise<PreferencesResponse>;
970
+ fetchGlobalPreferences(): Promise<PreferencesResponse>;
971
+ triggerHelloWorldEvent(): Promise<unknown>;
972
+ fetchSubscriptions(topicKey: string): Promise<SubscriptionResponse[]>;
973
+ getSubscription(topicKey: string, identifier?: string, workflowIds?: string[], tags?: string[]): Promise<SubscriptionResponse | undefined>;
974
+ createSubscription({ identifier, name, topicKey, topicName, preferences, }: {
975
+ identifier?: string;
976
+ name?: string;
977
+ topicKey: string;
978
+ topicName?: string;
979
+ preferences?: Array<PreferenceFilter>;
980
+ }): Promise<SubscriptionResponse>;
981
+ updateSubscription({ topicKey, identifier, name, preferences, }: {
982
+ topicKey: string;
983
+ identifier: string;
984
+ name?: string;
985
+ preferences?: Array<PreferenceFilter>;
986
+ }): Promise<SubscriptionResponse>;
987
+ updateSubscriptionPreference({ subscriptionIdentifier, workflowId, enabled, condition, email, sms, in_app, chat, push, }: {
988
+ subscriptionIdentifier: string;
989
+ workflowId: string;
990
+ enabled?: boolean;
991
+ condition?: RulesLogic;
992
+ email?: boolean;
993
+ sms?: boolean;
994
+ in_app?: boolean;
995
+ chat?: boolean;
996
+ push?: boolean;
997
+ }): Promise<SubscriptionPreferenceResponse>;
998
+ bulkUpdateSubscriptionPreferences(preferences: Array<{
999
+ subscriptionIdentifier: string;
1000
+ workflowId: string;
1001
+ enabled?: boolean;
1002
+ condition?: RulesLogic;
1003
+ email?: boolean;
1004
+ sms?: boolean;
1005
+ in_app?: boolean;
1006
+ chat?: boolean;
1007
+ push?: boolean;
1008
+ }>): Promise<SubscriptionPreferenceResponse[]>;
1009
+ deleteSubscription({ topicKey, identifier }: {
1010
+ topicKey: string;
1011
+ identifier: string;
1012
+ }): Promise<void>;
1013
+ /**
1014
+ * @deprecated Use generateConnectOAuthUrl() or generateLinkUserOAuthUrl() instead.
1015
+ */
1016
+ generateChatOAuthUrl({ integrationIdentifier, connectionIdentifier, subscriberId, context, scope, userScope, mode, connectionMode, autoLinkUser, }: GenerateChatOAuthUrlArgs): Promise<{
1017
+ url: string;
1018
+ }>;
1019
+ generateConnectOAuthUrl({ integrationIdentifier, connectionIdentifier, subscriberId, context, scope, connectionMode, autoLinkUser, }: GenerateConnectOAuthUrlArgs): Promise<{
1020
+ url: string;
1021
+ }>;
1022
+ generateLinkUserOAuthUrl({ integrationIdentifier, connectionIdentifier, subscriberId, context, userScope, }: GenerateLinkUserOAuthUrlArgs): Promise<{
1023
+ url: string;
1024
+ }>;
1025
+ listChannelConnections(args?: ListChannelConnectionsArgs): Promise<{
1026
+ data: ChannelConnectionResponse[];
1027
+ next?: string;
1028
+ previous?: string;
1029
+ }>;
1030
+ getChannelConnection(identifier: string): Promise<ChannelConnectionResponse>;
1031
+ createChannelConnection({ identifier, integrationIdentifier, subscriberId, context, workspace, auth, }: CreateChannelConnectionArgs): Promise<ChannelConnectionResponse>;
1032
+ deleteChannelConnection(identifier: string): Promise<void>;
1033
+ listChannelEndpoints(args?: ListChannelEndpointsArgs): Promise<{
1034
+ data: ChannelEndpointResponse[];
1035
+ next?: string;
1036
+ previous?: string;
1037
+ }>;
1038
+ getChannelEndpoint(identifier: string): Promise<ChannelEndpointResponse>;
1039
+ createChannelEndpoint({ identifier, integrationIdentifier, connectionIdentifier, subscriberId, context, type, endpoint, }: CreateChannelEndpointArgs): Promise<ChannelEndpointResponse>;
1040
+ deleteChannelEndpoint(identifier: string): Promise<void>;
888
1041
  }
889
1042
 
890
- export { ScheduleCache as $, type TimeRange as A, type BaseDeleteSubscriptionArgs as B, type ChannelPreference as C, type DaySchedule as D, type EventHandler as E, type FiltersCountResponse as F, type GetSubscriptionArgs as G, TopicSubscription as H, type InboxNotification as I, type UpdateSubscriptionArgs as J, type UpdateSubscriptionPreferenceArgs as K, type ListNotificationsResponse as L, type WeeklySchedule as M, Notification as N, WorkflowCriticalityEnum as O, Preference as P, type WorkflowFilter as Q, type WorkflowGroupFilter as R, SeverityLevelEnum as S, type TagsFilter as T, type UnreadCount as U, type WorkflowIdentifierOrId as V, WebSocketEvent as W, InboxService as X, NovuEventEmitter as Y, type Session as Z, type Result as _, type NotificationFilter as a, type UpdateScheduleArgs as a0, PreferencesCache as a1, type ListPreferencesArgs as a2, type BasePreferenceArgs as a3, type InstancePreferenceArgs as a4, type ListNotificationsArgs as a5, type FilterCountArgs as a6, type FilterCountResponse as a7, type FiltersCountArgs as a8, type BaseArgs as a9, type InstanceArgs as aa, type SnoozeArgs as ab, SubscriptionsCache as ac, type Options as ad, type EventNames as ae, type ContextValue as af, type BaseUpdateSubscriptionArgs as b, ChannelType as c, type Context as d, type CreateSubscriptionArgs as e, type DefaultSchedule as f, type DeleteSubscriptionArgs as g, type Events as h, type InstanceDeleteSubscriptionArgs as i, type InstanceUpdateSubscriptionArgs as j, type ListSubscriptionsArgs as k, NotificationStatus as l, NovuError as m, type NovuOptions as n, type NovuSocketOptions as o, type PreferenceFilter as p, PreferenceLevel as q, type PreferencesResponse as r, Schedule as s, type SocketEventNames as t, type SocketTypeOption as u, type StandardNovuOptions as v, type Subscriber as w, SubscriptionPreference as x, type TagsFilterAndForm as y, type TagsFilterOrGroup as z };
1043
+ export { type UpdateSubscriptionPreferenceArgs as $, type PreferenceFilter as A, type BaseDeleteSubscriptionArgs as B, type ChannelConnectionResponse as C, type DaySchedule as D, type EventHandler as E, type FiltersCountResponse as F, type GenerateChatOAuthUrlArgs as G, PreferenceLevel as H, type InboxNotification as I, type PreferencesResponse as J, Schedule as K, type ListChannelConnectionsArgs as L, type SocketEventNames as M, Notification as N, type SocketTypeOption as O, Preference as P, type StandardNovuOptions as Q, type Subscriber as R, SeverityLevelEnum as S, type TagsFilter as T, SubscriptionPreference as U, type TagsFilterAndForm as V, type TagsFilterOrGroup as W, type TimeRange as X, TopicSubscription as Y, type UnreadCount as Z, type UpdateSubscriptionArgs as _, type NotificationFilter as a, WebSocketEvent as a0, type WeeklySchedule as a1, WorkflowCriticalityEnum as a2, type WorkflowFilter as a3, type WorkflowGroupFilter as a4, type WorkflowIdentifierOrId as a5, type ConnectionMode as a6, InboxService as a7, NovuEventEmitter as a8, type Session as a9, type Result as aa, ScheduleCache as ab, type UpdateScheduleArgs as ac, PreferencesCache as ad, type ListPreferencesArgs as ae, type BasePreferenceArgs as af, type InstancePreferenceArgs as ag, type ListNotificationsArgs as ah, type FilterCountArgs as ai, type FilterCountResponse as aj, type FiltersCountArgs as ak, type BaseArgs as al, type InstanceArgs as am, type SnoozeArgs as an, type GenerateConnectOAuthUrlArgs as ao, type GenerateLinkUserOAuthUrlArgs as ap, SubscriptionsCache as aq, type Options as ar, type EventNames as as, type ContextValue as at, type BaseUpdateSubscriptionArgs as b, type ChannelEndpointResponse as c, type ChannelPreference as d, ChannelType as e, type Context as f, type CreateChannelConnectionArgs as g, type CreateChannelEndpointArgs as h, type CreateSubscriptionArgs as i, type DefaultSchedule as j, type DeleteChannelConnectionArgs as k, type DeleteChannelEndpointArgs as l, type DeleteSubscriptionArgs as m, type Events as n, type GetChannelConnectionArgs as o, type GetChannelEndpointArgs as p, type GetSubscriptionArgs as q, type InstanceDeleteSubscriptionArgs as r, type InstanceUpdateSubscriptionArgs as s, type ListChannelEndpointsArgs as t, type ListNotificationsResponse as u, type ListSubscriptionsArgs as v, NotificationStatus as w, NovuError as x, type NovuOptions as y, type NovuSocketOptions as z };