@novu/js 3.11.0 → 3.11.1

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