@novu/js 3.11.0 → 3.11.2-nightly.20251224.eb609546a3

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.
Files changed (36) hide show
  1. package/dist/cjs/{chunk-QQNKEWGC.js → chunk-C6V4UPCA.js} +1338 -1241
  2. package/dist/cjs/chunk-CDGREQFE.js +799 -0
  3. package/dist/cjs/index.d.ts +4 -4
  4. package/dist/cjs/index.js +38 -26
  5. package/dist/cjs/internal/index.d.ts +14 -2
  6. package/dist/cjs/internal/index.js +12 -4
  7. package/dist/cjs/novu-DxuaDf-Z.d.ts +192 -0
  8. package/dist/{esm/novu-DY-mm8Og.d.mts → cjs/novu-event-emitter-BOA_6GfJ.d.ts} +413 -162
  9. package/dist/cjs/themes/index.d.ts +11 -5
  10. package/dist/cjs/themes/index.js +17 -1
  11. package/dist/cjs/types-Buzm23uF.d.ts +836 -0
  12. package/dist/cjs/ui/index.d.ts +74 -7
  13. package/dist/cjs/ui/index.js +1836 -261
  14. package/dist/esm/{chunk-UM35OVAD.mjs → chunk-NF4ANB6D.mjs} +1308 -1207
  15. package/dist/esm/chunk-SWKDFXVR.mjs +770 -0
  16. package/dist/esm/index.d.mts +4 -4
  17. package/dist/esm/index.mjs +2 -2
  18. package/dist/esm/internal/index.d.mts +14 -2
  19. package/dist/esm/internal/index.mjs +1 -1
  20. package/dist/esm/novu-DY8vwRGE.d.mts +192 -0
  21. package/dist/{cjs/novu-ThMWeiRt.d.ts → esm/novu-event-emitter-BOA_6GfJ.d.mts} +413 -162
  22. package/dist/esm/themes/index.d.mts +11 -5
  23. package/dist/esm/themes/index.mjs +16 -2
  24. package/dist/esm/types-xBjzv9ok.d.mts +836 -0
  25. package/dist/esm/ui/index.d.mts +74 -7
  26. package/dist/esm/ui/index.mjs +1833 -257
  27. package/dist/index.css +1 -1
  28. package/dist/novu.min.js +12 -12
  29. package/dist/novu.min.js.gz +0 -0
  30. package/package.json +18 -17
  31. package/dist/cjs/chunk-VWSQDNZX.js +0 -66
  32. package/dist/cjs/types-BM_9Xx5Z.d.ts +0 -220
  33. package/dist/cjs/types-BjANCN3c.d.ts +0 -537
  34. package/dist/esm/chunk-RZWQYM3H.mjs +0 -62
  35. package/dist/esm/types-BM_9Xx5Z.d.mts +0 -220
  36. package/dist/esm/types-C5eX1GmB.d.mts +0 -537
@@ -0,0 +1,799 @@
1
+ 'use strict';
2
+
3
+ var chunk7B52C2XE_js = require('./chunk-7B52C2XE.js');
4
+
5
+ // src/ui/internal/buildContextKey.ts
6
+ function buildContextKey(context) {
7
+ if (!context) {
8
+ return "";
9
+ }
10
+ const keys = [];
11
+ for (const [type, value] of Object.entries(context)) {
12
+ if (value) {
13
+ const id = typeof value === "string" ? value : value.id;
14
+ keys.push(`${type}:${id}`);
15
+ }
16
+ }
17
+ return keys.sort().join(",");
18
+ }
19
+
20
+ // src/ui/internal/buildSubscriber.ts
21
+ function buildSubscriber({
22
+ subscriberId,
23
+ subscriber
24
+ }) {
25
+ if (subscriber) {
26
+ return typeof subscriber === "string" ? { subscriberId: subscriber } : subscriber;
27
+ }
28
+ if (subscriberId) {
29
+ return { subscriberId };
30
+ }
31
+ return { subscriberId: "" };
32
+ }
33
+
34
+ // src/ui/internal/buildSubscriptionIdentifier.ts
35
+ function buildSubscriptionIdentifier({ topicKey, subscriberId }) {
36
+ return `tk_${topicKey}:si_${subscriberId}`;
37
+ }
38
+
39
+ // src/types.ts
40
+ var NotificationStatus = /* @__PURE__ */ ((NotificationStatus2) => {
41
+ NotificationStatus2["READ"] = "read";
42
+ NotificationStatus2["SEEN"] = "seen";
43
+ NotificationStatus2["SNOOZED"] = "snoozed";
44
+ NotificationStatus2["UNREAD"] = "unread";
45
+ NotificationStatus2["UNSEEN"] = "unseen";
46
+ NotificationStatus2["UNSNOOZED"] = "unsnoozed";
47
+ return NotificationStatus2;
48
+ })(NotificationStatus || {});
49
+ var PreferenceLevel = /* @__PURE__ */ ((PreferenceLevel2) => {
50
+ PreferenceLevel2["GLOBAL"] = "global";
51
+ PreferenceLevel2["TEMPLATE"] = "template";
52
+ return PreferenceLevel2;
53
+ })(PreferenceLevel || {});
54
+ var ChannelType = /* @__PURE__ */ ((ChannelType2) => {
55
+ ChannelType2["IN_APP"] = "in_app";
56
+ ChannelType2["EMAIL"] = "email";
57
+ ChannelType2["SMS"] = "sms";
58
+ ChannelType2["CHAT"] = "chat";
59
+ ChannelType2["PUSH"] = "push";
60
+ return ChannelType2;
61
+ })(ChannelType || {});
62
+ var WebSocketEvent = /* @__PURE__ */ ((WebSocketEvent2) => {
63
+ WebSocketEvent2["RECEIVED"] = "notification_received";
64
+ WebSocketEvent2["UNREAD"] = "unread_count_changed";
65
+ WebSocketEvent2["UNSEEN"] = "unseen_count_changed";
66
+ return WebSocketEvent2;
67
+ })(WebSocketEvent || {});
68
+ var SeverityLevelEnum = /* @__PURE__ */ ((SeverityLevelEnum2) => {
69
+ SeverityLevelEnum2["HIGH"] = "high";
70
+ SeverityLevelEnum2["MEDIUM"] = "medium";
71
+ SeverityLevelEnum2["LOW"] = "low";
72
+ SeverityLevelEnum2["NONE"] = "none";
73
+ return SeverityLevelEnum2;
74
+ })(SeverityLevelEnum || {});
75
+ var WorkflowCriticalityEnum = /* @__PURE__ */ ((WorkflowCriticalityEnum2) => {
76
+ WorkflowCriticalityEnum2["CRITICAL"] = "critical";
77
+ WorkflowCriticalityEnum2["NON_CRITICAL"] = "nonCritical";
78
+ WorkflowCriticalityEnum2["ALL"] = "all";
79
+ return WorkflowCriticalityEnum2;
80
+ })(WorkflowCriticalityEnum || {});
81
+
82
+ // src/utils/errors.ts
83
+ var NovuError = class extends Error {
84
+ constructor(message, originalError) {
85
+ super(message);
86
+ this.originalError = originalError;
87
+ }
88
+ };
89
+
90
+ // src/notifications/helpers.ts
91
+ var read = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
92
+ emitter,
93
+ apiService,
94
+ args
95
+ }) {
96
+ const { notificationId, optimisticValue } = getNotificationDetails(
97
+ args,
98
+ {
99
+ isRead: true,
100
+ readAt: (/* @__PURE__ */ new Date()).toISOString(),
101
+ isArchived: false,
102
+ archivedAt: void 0
103
+ },
104
+ {
105
+ emitter,
106
+ apiService
107
+ }
108
+ );
109
+ try {
110
+ emitter.emit("notification.read.pending", {
111
+ args,
112
+ data: optimisticValue
113
+ });
114
+ const response = yield apiService.read(notificationId);
115
+ const updatedNotification = new Notification(response, emitter, apiService);
116
+ emitter.emit("notification.read.resolved", { args, data: updatedNotification });
117
+ return { data: updatedNotification };
118
+ } catch (error) {
119
+ emitter.emit("notification.read.resolved", { args, error });
120
+ return { error: new NovuError("Failed to read notification", error) };
121
+ }
122
+ });
123
+ var unread = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
124
+ emitter,
125
+ apiService,
126
+ args
127
+ }) {
128
+ const { notificationId, optimisticValue } = getNotificationDetails(
129
+ args,
130
+ {
131
+ isRead: false,
132
+ readAt: null,
133
+ isArchived: false,
134
+ archivedAt: void 0
135
+ },
136
+ {
137
+ emitter,
138
+ apiService
139
+ }
140
+ );
141
+ try {
142
+ emitter.emit("notification.unread.pending", {
143
+ args,
144
+ data: optimisticValue
145
+ });
146
+ const response = yield apiService.unread(notificationId);
147
+ const updatedNotification = new Notification(response, emitter, apiService);
148
+ emitter.emit("notification.unread.resolved", { args, data: updatedNotification });
149
+ return { data: updatedNotification };
150
+ } catch (error) {
151
+ emitter.emit("notification.unread.resolved", { args, error });
152
+ return { error: new NovuError("Failed to unread notification", error) };
153
+ }
154
+ });
155
+ var seen = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
156
+ emitter,
157
+ apiService,
158
+ args
159
+ }) {
160
+ const { notificationId, optimisticValue } = getNotificationDetails(
161
+ args,
162
+ {
163
+ isSeen: true
164
+ },
165
+ {
166
+ emitter,
167
+ apiService
168
+ }
169
+ );
170
+ try {
171
+ emitter.emit("notification.seen.pending", {
172
+ args,
173
+ data: optimisticValue
174
+ });
175
+ yield apiService.seen(notificationId);
176
+ if (!optimisticValue) {
177
+ throw new Error("Failed to create optimistic value for notification");
178
+ }
179
+ const updatedNotification = new Notification(optimisticValue, emitter, apiService);
180
+ emitter.emit("notification.seen.resolved", { args, data: updatedNotification });
181
+ return { data: updatedNotification };
182
+ } catch (error) {
183
+ emitter.emit("notification.seen.resolved", { args, error });
184
+ return { error: new NovuError("Failed to mark notification as seen", error) };
185
+ }
186
+ });
187
+ var archive = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
188
+ emitter,
189
+ apiService,
190
+ args
191
+ }) {
192
+ const { notificationId, optimisticValue } = getNotificationDetails(
193
+ args,
194
+ {
195
+ isArchived: true,
196
+ archivedAt: (/* @__PURE__ */ new Date()).toISOString(),
197
+ isRead: true,
198
+ readAt: (/* @__PURE__ */ new Date()).toISOString()
199
+ },
200
+ {
201
+ emitter,
202
+ apiService
203
+ }
204
+ );
205
+ try {
206
+ emitter.emit("notification.archive.pending", {
207
+ args,
208
+ data: optimisticValue
209
+ });
210
+ const response = yield apiService.archive(notificationId);
211
+ const updatedNotification = new Notification(response, emitter, apiService);
212
+ emitter.emit("notification.archive.resolved", { args, data: updatedNotification });
213
+ return { data: updatedNotification };
214
+ } catch (error) {
215
+ emitter.emit("notification.archive.resolved", { args, error });
216
+ return { error: new NovuError("Failed to archive notification", error) };
217
+ }
218
+ });
219
+ var unarchive = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
220
+ emitter,
221
+ apiService,
222
+ args
223
+ }) {
224
+ const { notificationId, optimisticValue } = getNotificationDetails(
225
+ args,
226
+ {
227
+ isArchived: false,
228
+ archivedAt: null,
229
+ isRead: true,
230
+ readAt: (/* @__PURE__ */ new Date()).toISOString()
231
+ },
232
+ {
233
+ emitter,
234
+ apiService
235
+ }
236
+ );
237
+ try {
238
+ emitter.emit("notification.unarchive.pending", {
239
+ args,
240
+ data: optimisticValue
241
+ });
242
+ const response = yield apiService.unarchive(notificationId);
243
+ const updatedNotification = new Notification(response, emitter, apiService);
244
+ emitter.emit("notification.unarchive.resolved", { args, data: updatedNotification });
245
+ return { data: updatedNotification };
246
+ } catch (error) {
247
+ emitter.emit("notification.unarchive.resolved", { args, error });
248
+ return { error: new NovuError("Failed to unarchive notification", error) };
249
+ }
250
+ });
251
+ var snooze = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
252
+ emitter,
253
+ apiService,
254
+ args
255
+ }) {
256
+ const { notificationId, optimisticValue } = getNotificationDetails(
257
+ args,
258
+ {
259
+ isSnoozed: true,
260
+ snoozedUntil: args.snoozeUntil
261
+ },
262
+ {
263
+ emitter,
264
+ apiService
265
+ }
266
+ );
267
+ try {
268
+ emitter.emit("notification.snooze.pending", {
269
+ args,
270
+ data: optimisticValue
271
+ });
272
+ const response = yield apiService.snooze(notificationId, args.snoozeUntil);
273
+ const updatedNotification = new Notification(response, emitter, apiService);
274
+ emitter.emit("notification.snooze.resolved", { args, data: updatedNotification });
275
+ return { data: updatedNotification };
276
+ } catch (error) {
277
+ emitter.emit("notification.snooze.resolved", { args, error });
278
+ return { error: new NovuError("Failed to snooze notification", error) };
279
+ }
280
+ });
281
+ var unsnooze = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
282
+ emitter,
283
+ apiService,
284
+ args
285
+ }) {
286
+ const { notificationId, optimisticValue } = getNotificationDetails(
287
+ args,
288
+ {
289
+ isSnoozed: false,
290
+ snoozedUntil: null
291
+ },
292
+ {
293
+ emitter,
294
+ apiService
295
+ }
296
+ );
297
+ try {
298
+ emitter.emit("notification.unsnooze.pending", {
299
+ args,
300
+ data: optimisticValue
301
+ });
302
+ const response = yield apiService.unsnooze(notificationId);
303
+ const updatedNotification = new Notification(response, emitter, apiService);
304
+ emitter.emit("notification.unsnooze.resolved", { args, data: updatedNotification });
305
+ return { data: updatedNotification };
306
+ } catch (error) {
307
+ emitter.emit("notification.unsnooze.resolved", { args, error });
308
+ return { error: new NovuError("Failed to unsnooze notification", error) };
309
+ }
310
+ });
311
+ var completeAction = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
312
+ emitter,
313
+ apiService,
314
+ args,
315
+ actionType
316
+ }) {
317
+ const optimisticUpdate = actionType === "primary" /* PRIMARY */ ? {
318
+ primaryAction: chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, "notification" in args ? args.notification.primaryAction : {}), {
319
+ isCompleted: true
320
+ })
321
+ } : {
322
+ secondaryAction: chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, "notification" in args ? args.notification.secondaryAction : {}), {
323
+ isCompleted: true
324
+ })
325
+ };
326
+ const { notificationId, optimisticValue } = getNotificationDetails(args, optimisticUpdate, {
327
+ emitter,
328
+ apiService
329
+ });
330
+ try {
331
+ emitter.emit("notification.complete_action.pending", {
332
+ args,
333
+ data: optimisticValue
334
+ });
335
+ const response = yield apiService.completeAction({ actionType, notificationId });
336
+ const updatedNotification = new Notification(response, emitter, apiService);
337
+ emitter.emit("notification.complete_action.resolved", { args, data: updatedNotification });
338
+ return { data: updatedNotification };
339
+ } catch (error) {
340
+ emitter.emit("notification.complete_action.resolved", { args, error });
341
+ return { error: new NovuError(`Failed to complete ${actionType} action on the notification`, error) };
342
+ }
343
+ });
344
+ var revertAction = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
345
+ emitter,
346
+ apiService,
347
+ args,
348
+ actionType
349
+ }) {
350
+ const optimisticUpdate = actionType === "primary" /* PRIMARY */ ? {
351
+ primaryAction: chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, "notification" in args ? args.notification.primaryAction : {}), {
352
+ isCompleted: false
353
+ })
354
+ } : {
355
+ secondaryAction: chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, "notification" in args ? args.notification.secondaryAction : {}), {
356
+ isCompleted: false
357
+ })
358
+ };
359
+ const { notificationId, optimisticValue } = getNotificationDetails(args, optimisticUpdate, {
360
+ emitter,
361
+ apiService
362
+ });
363
+ try {
364
+ emitter.emit("notification.revert_action.pending", {
365
+ args,
366
+ data: optimisticValue
367
+ });
368
+ const response = yield apiService.revertAction({ actionType, notificationId });
369
+ const updatedNotification = new Notification(response, emitter, apiService);
370
+ emitter.emit("notification.revert_action.resolved", { args, data: updatedNotification });
371
+ return { data: updatedNotification };
372
+ } catch (error) {
373
+ emitter.emit("notification.revert_action.resolved", { args, error });
374
+ return { error: new NovuError("Failed to fetch notifications", error) };
375
+ }
376
+ });
377
+ var getNotificationDetails = (args, update, dependencies) => {
378
+ if ("notification" in args) {
379
+ return {
380
+ notificationId: args.notification.id,
381
+ optimisticValue: new Notification(
382
+ chunk7B52C2XE_js.__spreadValues(chunk7B52C2XE_js.__spreadValues({}, args.notification), update),
383
+ dependencies.emitter,
384
+ dependencies.apiService
385
+ )
386
+ };
387
+ } else {
388
+ return {
389
+ notificationId: args.notificationId
390
+ };
391
+ }
392
+ };
393
+ var readAll = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
394
+ emitter,
395
+ inboxService,
396
+ notificationsCache,
397
+ tags,
398
+ data
399
+ }) {
400
+ try {
401
+ const notifications = notificationsCache.getUniqueNotifications({ tags, data });
402
+ const optimisticNotifications = notifications.map(
403
+ (notification) => new Notification(
404
+ chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, notification), {
405
+ isRead: true,
406
+ readAt: (/* @__PURE__ */ new Date()).toISOString(),
407
+ isArchived: false,
408
+ archivedAt: void 0
409
+ }),
410
+ emitter,
411
+ inboxService
412
+ )
413
+ );
414
+ emitter.emit("notifications.read_all.pending", { args: { tags, data }, data: optimisticNotifications });
415
+ yield inboxService.readAll({ tags, data });
416
+ emitter.emit("notifications.read_all.resolved", { args: { tags, data }, data: optimisticNotifications });
417
+ return {};
418
+ } catch (error) {
419
+ emitter.emit("notifications.read_all.resolved", { args: { tags, data }, error });
420
+ return { error: new NovuError("Failed to read all notifications", error) };
421
+ }
422
+ });
423
+ var seenAll = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
424
+ emitter,
425
+ inboxService,
426
+ notificationsCache,
427
+ notificationIds,
428
+ tags,
429
+ data
430
+ }) {
431
+ try {
432
+ const notifications = notificationsCache.getUniqueNotifications({ tags, data });
433
+ const filteredNotifications = notificationIds && notificationIds.length > 0 ? notifications.filter((notification) => notificationIds.includes(notification.id)) : notifications;
434
+ const optimisticNotifications = filteredNotifications.map(
435
+ (notification) => new Notification(
436
+ chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, notification), {
437
+ isSeen: true,
438
+ firstSeenAt: notification.firstSeenAt || (/* @__PURE__ */ new Date()).toISOString()
439
+ }),
440
+ emitter,
441
+ inboxService
442
+ )
443
+ );
444
+ emitter.emit("notifications.seen_all.pending", {
445
+ args: { notificationIds, tags, data },
446
+ data: optimisticNotifications
447
+ });
448
+ yield inboxService.markAsSeen({ notificationIds, tags, data });
449
+ emitter.emit("notifications.seen_all.resolved", {
450
+ args: { notificationIds, tags, data },
451
+ data: optimisticNotifications
452
+ });
453
+ return {};
454
+ } catch (error) {
455
+ emitter.emit("notifications.seen_all.resolved", { args: { notificationIds, tags, data }, error });
456
+ return { error: new NovuError("Failed to mark all notifications as seen", error) };
457
+ }
458
+ });
459
+ var archiveAll = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
460
+ emitter,
461
+ inboxService,
462
+ notificationsCache,
463
+ tags,
464
+ data
465
+ }) {
466
+ try {
467
+ const notifications = notificationsCache.getUniqueNotifications({ tags, data });
468
+ const optimisticNotifications = notifications.map(
469
+ (notification) => new Notification(
470
+ chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, notification), {
471
+ isRead: true,
472
+ readAt: (/* @__PURE__ */ new Date()).toISOString(),
473
+ isArchived: true,
474
+ archivedAt: (/* @__PURE__ */ new Date()).toISOString()
475
+ }),
476
+ emitter,
477
+ inboxService
478
+ )
479
+ );
480
+ emitter.emit("notifications.archive_all.pending", { args: { tags, data }, data: optimisticNotifications });
481
+ yield inboxService.archiveAll({ tags, data });
482
+ emitter.emit("notifications.archive_all.resolved", { args: { tags, data }, data: optimisticNotifications });
483
+ return {};
484
+ } catch (error) {
485
+ emitter.emit("notifications.archive_all.resolved", { args: { tags, data }, error });
486
+ return { error: new NovuError("Failed to archive all notifications", error) };
487
+ }
488
+ });
489
+ var archiveAllRead = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
490
+ emitter,
491
+ inboxService,
492
+ notificationsCache,
493
+ tags,
494
+ data
495
+ }) {
496
+ try {
497
+ const notifications = notificationsCache.getUniqueNotifications({ tags, data, read: true });
498
+ const optimisticNotifications = notifications.map(
499
+ (notification) => new Notification(
500
+ chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, notification), { isArchived: true, archivedAt: (/* @__PURE__ */ new Date()).toISOString() }),
501
+ emitter,
502
+ inboxService
503
+ )
504
+ );
505
+ emitter.emit("notifications.archive_all_read.pending", { args: { tags, data }, data: optimisticNotifications });
506
+ yield inboxService.archiveAllRead({ tags, data });
507
+ emitter.emit("notifications.archive_all_read.resolved", { args: { tags, data }, data: optimisticNotifications });
508
+ return {};
509
+ } catch (error) {
510
+ emitter.emit("notifications.archive_all_read.resolved", { args: { tags, data }, error });
511
+ return { error: new NovuError("Failed to archive all read notifications", error) };
512
+ }
513
+ });
514
+ var deleteNotification = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
515
+ emitter,
516
+ apiService,
517
+ args
518
+ }) {
519
+ const { notificationId } = getNotificationDetails(
520
+ args,
521
+ {},
522
+ {
523
+ emitter,
524
+ apiService
525
+ }
526
+ );
527
+ try {
528
+ emitter.emit("notification.delete.pending", {
529
+ args
530
+ });
531
+ yield apiService.delete(notificationId);
532
+ emitter.emit("notification.delete.resolved", { args });
533
+ return {};
534
+ } catch (error) {
535
+ emitter.emit("notification.delete.resolved", { args, error });
536
+ return { error: new NovuError("Failed to delete notification", error) };
537
+ }
538
+ });
539
+ var deleteAll = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
540
+ emitter,
541
+ inboxService,
542
+ notificationsCache,
543
+ tags,
544
+ data
545
+ }) {
546
+ try {
547
+ const notifications = notificationsCache.getUniqueNotifications({ tags, data });
548
+ emitter.emit("notifications.delete_all.pending", { args: { tags, data }, data: notifications });
549
+ yield inboxService.deleteAll({ tags, data });
550
+ emitter.emit("notifications.delete_all.resolved", { args: { tags, data } });
551
+ return {};
552
+ } catch (error) {
553
+ emitter.emit("notifications.delete_all.resolved", { args: { tags, data }, error });
554
+ return { error: new NovuError("Failed to delete all notifications", error) };
555
+ }
556
+ });
557
+
558
+ // src/notifications/notification.ts
559
+ var _emitter, _inboxService;
560
+ var Notification = class {
561
+ constructor(notification, emitter, inboxService) {
562
+ chunk7B52C2XE_js.__privateAdd(this, _emitter);
563
+ chunk7B52C2XE_js.__privateAdd(this, _inboxService);
564
+ chunk7B52C2XE_js.__privateSet(this, _emitter, emitter);
565
+ chunk7B52C2XE_js.__privateSet(this, _inboxService, inboxService);
566
+ this.id = notification.id;
567
+ this.transactionId = notification.transactionId;
568
+ this.subject = notification.subject;
569
+ this.body = notification.body;
570
+ this.to = notification.to;
571
+ this.isRead = notification.isRead;
572
+ this.isSeen = notification.isSeen;
573
+ this.isArchived = notification.isArchived;
574
+ this.isSnoozed = notification.isSnoozed;
575
+ this.snoozedUntil = notification.snoozedUntil;
576
+ this.deliveredAt = notification.deliveredAt;
577
+ this.createdAt = notification.createdAt;
578
+ this.readAt = notification.readAt;
579
+ this.firstSeenAt = notification.firstSeenAt;
580
+ this.archivedAt = notification.archivedAt;
581
+ this.avatar = notification.avatar;
582
+ this.primaryAction = notification.primaryAction;
583
+ this.secondaryAction = notification.secondaryAction;
584
+ this.channelType = notification.channelType;
585
+ this.tags = notification.tags;
586
+ this.redirect = notification.redirect;
587
+ this.data = notification.data;
588
+ this.workflow = notification.workflow;
589
+ this.severity = notification.severity;
590
+ }
591
+ read() {
592
+ return read({
593
+ emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
594
+ apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
595
+ args: {
596
+ notification: this
597
+ }
598
+ });
599
+ }
600
+ unread() {
601
+ return unread({
602
+ emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
603
+ apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
604
+ args: {
605
+ notification: this
606
+ }
607
+ });
608
+ }
609
+ seen() {
610
+ return seen({
611
+ emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
612
+ apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
613
+ args: {
614
+ notification: this
615
+ }
616
+ });
617
+ }
618
+ archive() {
619
+ return archive({
620
+ emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
621
+ apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
622
+ args: {
623
+ notification: this
624
+ }
625
+ });
626
+ }
627
+ unarchive() {
628
+ return unarchive({
629
+ emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
630
+ apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
631
+ args: {
632
+ notification: this
633
+ }
634
+ });
635
+ }
636
+ delete() {
637
+ return deleteNotification({
638
+ emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
639
+ apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
640
+ args: {
641
+ notification: this
642
+ }
643
+ });
644
+ }
645
+ snooze(snoozeUntil) {
646
+ return snooze({
647
+ emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
648
+ apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
649
+ args: {
650
+ notification: this,
651
+ snoozeUntil
652
+ }
653
+ });
654
+ }
655
+ unsnooze() {
656
+ return unsnooze({
657
+ emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
658
+ apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
659
+ args: { notification: this }
660
+ });
661
+ }
662
+ completePrimary() {
663
+ if (!this.primaryAction) {
664
+ throw new Error("Primary action is not available");
665
+ }
666
+ return completeAction({
667
+ emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
668
+ apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
669
+ args: {
670
+ notification: this
671
+ },
672
+ actionType: "primary" /* PRIMARY */
673
+ });
674
+ }
675
+ completeSecondary() {
676
+ if (!this.primaryAction) {
677
+ throw new Error("Secondary action is not available");
678
+ }
679
+ return completeAction({
680
+ emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
681
+ apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
682
+ args: {
683
+ notification: this
684
+ },
685
+ actionType: "secondary" /* SECONDARY */
686
+ });
687
+ }
688
+ revertPrimary() {
689
+ if (!this.primaryAction) {
690
+ throw new Error("Primary action is not available");
691
+ }
692
+ return revertAction({
693
+ emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
694
+ apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
695
+ args: {
696
+ notification: this
697
+ },
698
+ actionType: "primary" /* PRIMARY */
699
+ });
700
+ }
701
+ revertSecondary() {
702
+ if (!this.primaryAction) {
703
+ throw new Error("Secondary action is not available");
704
+ }
705
+ return revertAction({
706
+ emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
707
+ apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
708
+ args: {
709
+ notification: this
710
+ },
711
+ actionType: "secondary" /* SECONDARY */
712
+ });
713
+ }
714
+ on(eventName, listener) {
715
+ const cleanup = chunk7B52C2XE_js.__privateGet(this, _emitter).on(eventName, listener);
716
+ return () => {
717
+ cleanup();
718
+ };
719
+ }
720
+ /**
721
+ * @deprecated
722
+ * Use the cleanup function returned by the "on" method instead.
723
+ */
724
+ off(eventName, listener) {
725
+ chunk7B52C2XE_js.__privateGet(this, _emitter).off(eventName, listener);
726
+ }
727
+ };
728
+ _emitter = new WeakMap();
729
+ _inboxService = new WeakMap();
730
+
731
+ // src/ui/internal/createNotification.ts
732
+ function createNotification({
733
+ emitter,
734
+ inboxService,
735
+ notification
736
+ }) {
737
+ return new Notification(notification, emitter, inboxService);
738
+ }
739
+
740
+ // src/ui/internal/parseMarkdown.tsx
741
+ var parseMarkdownIntoTokens = (text) => {
742
+ const tokens = [];
743
+ let buffer = "";
744
+ let inBold = false;
745
+ for (let i = 0; i < text.length; i += 1) {
746
+ if (text[i] === "\\" && text[i + 1] === "*") {
747
+ buffer += "*";
748
+ i += 1;
749
+ } else if (text[i] === "*" && text[i + 1] === "*") {
750
+ if (buffer) {
751
+ tokens.push({
752
+ type: inBold ? "bold" : "text",
753
+ content: buffer
754
+ });
755
+ buffer = "";
756
+ }
757
+ inBold = !inBold;
758
+ i += 1;
759
+ } else {
760
+ buffer += text[i];
761
+ }
762
+ }
763
+ if (buffer) {
764
+ tokens.push({
765
+ type: inBold ? "bold" : "text",
766
+ content: buffer
767
+ });
768
+ }
769
+ return tokens;
770
+ };
771
+
772
+ exports.ChannelType = ChannelType;
773
+ exports.Notification = Notification;
774
+ exports.NotificationStatus = NotificationStatus;
775
+ exports.NovuError = NovuError;
776
+ exports.PreferenceLevel = PreferenceLevel;
777
+ exports.SeverityLevelEnum = SeverityLevelEnum;
778
+ exports.WebSocketEvent = WebSocketEvent;
779
+ exports.WorkflowCriticalityEnum = WorkflowCriticalityEnum;
780
+ exports.archive = archive;
781
+ exports.archiveAll = archiveAll;
782
+ exports.archiveAllRead = archiveAllRead;
783
+ exports.buildContextKey = buildContextKey;
784
+ exports.buildSubscriber = buildSubscriber;
785
+ exports.buildSubscriptionIdentifier = buildSubscriptionIdentifier;
786
+ exports.completeAction = completeAction;
787
+ exports.createNotification = createNotification;
788
+ exports.deleteAll = deleteAll;
789
+ exports.deleteNotification = deleteNotification;
790
+ exports.parseMarkdownIntoTokens = parseMarkdownIntoTokens;
791
+ exports.read = read;
792
+ exports.readAll = readAll;
793
+ exports.revertAction = revertAction;
794
+ exports.seen = seen;
795
+ exports.seenAll = seenAll;
796
+ exports.snooze = snooze;
797
+ exports.unarchive = unarchive;
798
+ exports.unread = unread;
799
+ exports.unsnooze = unsnooze;