@novu/js 2.1.0 → 2.1.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.
- package/dist/cjs/{chunk-UUYKXZBW.js → chunk-D7P7KCZI.js} +361 -271
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js +14 -14
- package/dist/cjs/{novu-PgupDkfH.d.ts → novu-04KlkBy4.d.ts} +24 -14
- package/dist/cjs/ui/index.d.ts +2 -2
- package/dist/cjs/ui/index.js +209 -116
- package/dist/esm/{chunk-PCEUODSO.mjs → chunk-APRCCICD.mjs} +361 -271
- package/dist/esm/index.d.mts +2 -2
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/{novu-PgupDkfH.d.mts → novu-04KlkBy4.d.mts} +24 -14
- package/dist/esm/ui/index.d.mts +2 -2
- package/dist/esm/ui/index.mjs +118 -25
- package/dist/novu.min.js +10 -10
- package/dist/novu.min.js.gz +0 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import mitt from 'mitt';
|
|
2
|
-
import { HttpClient } from '@novu/client';
|
|
3
2
|
import io from 'socket.io-client';
|
|
3
|
+
import { HttpClient } from '@novu/client';
|
|
4
4
|
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
6
6
|
var __defProps = Object.defineProperties;
|
|
@@ -140,18 +140,12 @@ var areTagsEqual = (tags1, tags2) => {
|
|
|
140
140
|
var isSameFilter = (filter1, filter2) => {
|
|
141
141
|
return areTagsEqual(filter1.tags, filter2.tags) && filter1.read === filter2.read && filter1.archived === filter2.archived;
|
|
142
142
|
};
|
|
143
|
-
var
|
|
144
|
-
var
|
|
143
|
+
var _mittEmitter;
|
|
144
|
+
var NovuEventEmitter = class {
|
|
145
145
|
constructor() {
|
|
146
146
|
__privateAdd(this, _mittEmitter);
|
|
147
147
|
__privateSet(this, _mittEmitter, mitt());
|
|
148
148
|
}
|
|
149
|
-
static getInstance(options) {
|
|
150
|
-
if (options == null ? void 0 : options.recreate) {
|
|
151
|
-
__privateSet(_NovuEventEmitter, _instance, new _NovuEventEmitter());
|
|
152
|
-
}
|
|
153
|
-
return __privateGet(_NovuEventEmitter, _instance);
|
|
154
|
-
}
|
|
155
149
|
on(eventName, listener) {
|
|
156
150
|
__privateGet(this, _mittEmitter).on(eventName, listener);
|
|
157
151
|
}
|
|
@@ -162,10 +156,7 @@ var _NovuEventEmitter = class _NovuEventEmitter {
|
|
|
162
156
|
__privateGet(this, _mittEmitter).emit(type, event);
|
|
163
157
|
}
|
|
164
158
|
};
|
|
165
|
-
_instance = new WeakMap();
|
|
166
159
|
_mittEmitter = new WeakMap();
|
|
167
|
-
__privateAdd(_NovuEventEmitter, _instance);
|
|
168
|
-
var NovuEventEmitter = _NovuEventEmitter;
|
|
169
160
|
|
|
170
161
|
// src/utils/errors.ts
|
|
171
162
|
var NovuError = class extends Error {
|
|
@@ -174,139 +165,18 @@ var NovuError = class extends Error {
|
|
|
174
165
|
this.originalError = originalError;
|
|
175
166
|
}
|
|
176
167
|
};
|
|
177
|
-
var NOVU_API_VERSION = "2024-06-26";
|
|
178
|
-
var INBOX_ROUTE = "/inbox";
|
|
179
|
-
var INBOX_NOTIFICATIONS_ROUTE = `${INBOX_ROUTE}/notifications`;
|
|
180
|
-
var _httpClient;
|
|
181
|
-
var InboxService = class {
|
|
182
|
-
constructor(options = {}) {
|
|
183
|
-
this.isSessionInitialized = false;
|
|
184
|
-
__privateAdd(this, _httpClient);
|
|
185
|
-
__privateSet(this, _httpClient, new HttpClient(options));
|
|
186
|
-
__privateGet(this, _httpClient).updateHeaders({
|
|
187
|
-
"Novu-API-Version": NOVU_API_VERSION
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
initializeSession(_0) {
|
|
191
|
-
return __async(this, arguments, function* ({
|
|
192
|
-
applicationIdentifier,
|
|
193
|
-
subscriberId,
|
|
194
|
-
subscriberHash
|
|
195
|
-
}) {
|
|
196
|
-
const response = yield __privateGet(this, _httpClient).post(`${INBOX_ROUTE}/session`, {
|
|
197
|
-
applicationIdentifier,
|
|
198
|
-
subscriberId,
|
|
199
|
-
subscriberHash
|
|
200
|
-
});
|
|
201
|
-
__privateGet(this, _httpClient).setAuthorizationToken(response.token);
|
|
202
|
-
this.isSessionInitialized = true;
|
|
203
|
-
return response;
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
fetchNotifications({
|
|
207
|
-
after,
|
|
208
|
-
archived,
|
|
209
|
-
limit = 10,
|
|
210
|
-
offset,
|
|
211
|
-
read: read2,
|
|
212
|
-
tags
|
|
213
|
-
}) {
|
|
214
|
-
const queryParams = new URLSearchParams(`limit=${limit}`);
|
|
215
|
-
if (after) {
|
|
216
|
-
queryParams.append("after", after);
|
|
217
|
-
}
|
|
218
|
-
if (offset) {
|
|
219
|
-
queryParams.append("offset", `${offset}`);
|
|
220
|
-
}
|
|
221
|
-
if (tags) {
|
|
222
|
-
tags.forEach((tag) => queryParams.append("tags[]", tag));
|
|
223
|
-
}
|
|
224
|
-
if (read2 !== void 0) {
|
|
225
|
-
queryParams.append("read", `${read2}`);
|
|
226
|
-
}
|
|
227
|
-
if (archived !== void 0) {
|
|
228
|
-
queryParams.append("archived", `${archived}`);
|
|
229
|
-
}
|
|
230
|
-
return __privateGet(this, _httpClient).getFullResponse(`${INBOX_NOTIFICATIONS_ROUTE}?${queryParams.toString()}`);
|
|
231
|
-
}
|
|
232
|
-
count({ filters }) {
|
|
233
|
-
return __privateGet(this, _httpClient).getFullResponse(`${INBOX_NOTIFICATIONS_ROUTE}/count?filters=${JSON.stringify(filters)}`);
|
|
234
|
-
}
|
|
235
|
-
read(notificationId) {
|
|
236
|
-
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/read`);
|
|
237
|
-
}
|
|
238
|
-
unread(notificationId) {
|
|
239
|
-
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/unread`);
|
|
240
|
-
}
|
|
241
|
-
archive(notificationId) {
|
|
242
|
-
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/archive`);
|
|
243
|
-
}
|
|
244
|
-
unarchive(notificationId) {
|
|
245
|
-
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/unarchive`);
|
|
246
|
-
}
|
|
247
|
-
readAll({ tags }) {
|
|
248
|
-
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read`, { tags });
|
|
249
|
-
}
|
|
250
|
-
archiveAll({ tags }) {
|
|
251
|
-
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/archive`, { tags });
|
|
252
|
-
}
|
|
253
|
-
archiveAllRead({ tags }) {
|
|
254
|
-
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read-archive`, { tags });
|
|
255
|
-
}
|
|
256
|
-
completeAction({
|
|
257
|
-
actionType,
|
|
258
|
-
notificationId
|
|
259
|
-
}) {
|
|
260
|
-
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/complete`, {
|
|
261
|
-
actionType
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
revertAction({
|
|
265
|
-
actionType,
|
|
266
|
-
notificationId
|
|
267
|
-
}) {
|
|
268
|
-
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/revert`, {
|
|
269
|
-
actionType
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
fetchPreferences() {
|
|
273
|
-
return __privateGet(this, _httpClient).get(`${INBOX_ROUTE}/preferences`);
|
|
274
|
-
}
|
|
275
|
-
updateGlobalPreferences(channelPreferences) {
|
|
276
|
-
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences`, channelPreferences);
|
|
277
|
-
}
|
|
278
|
-
updateWorkflowPreferences({
|
|
279
|
-
workflowId,
|
|
280
|
-
channelPreferences
|
|
281
|
-
}) {
|
|
282
|
-
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/${workflowId}`, channelPreferences);
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
_httpClient = new WeakMap();
|
|
286
|
-
|
|
287
|
-
// src/utils/inbox-service-singleton.ts
|
|
288
|
-
var _instance2;
|
|
289
|
-
var _InboxServiceSingleton = class _InboxServiceSingleton {
|
|
290
|
-
static getInstance(options) {
|
|
291
|
-
const isNeedsToRecreate = !!options;
|
|
292
|
-
if (isNeedsToRecreate) {
|
|
293
|
-
__privateSet(_InboxServiceSingleton, _instance2, new InboxService(options));
|
|
294
|
-
}
|
|
295
|
-
return __privateGet(_InboxServiceSingleton, _instance2);
|
|
296
|
-
}
|
|
297
|
-
};
|
|
298
|
-
_instance2 = new WeakMap();
|
|
299
|
-
__privateAdd(_InboxServiceSingleton, _instance2);
|
|
300
|
-
var InboxServiceSingleton = _InboxServiceSingleton;
|
|
301
168
|
|
|
302
169
|
// src/base-module.ts
|
|
303
170
|
var _callsQueue, _sessionError;
|
|
304
171
|
var BaseModule = class {
|
|
305
|
-
constructor(
|
|
172
|
+
constructor({
|
|
173
|
+
inboxServiceInstance,
|
|
174
|
+
eventEmitterInstance
|
|
175
|
+
}) {
|
|
306
176
|
__privateAdd(this, _callsQueue, []);
|
|
307
177
|
__privateAdd(this, _sessionError);
|
|
308
|
-
this._emitter =
|
|
309
|
-
this._inboxService =
|
|
178
|
+
this._emitter = eventEmitterInstance;
|
|
179
|
+
this._inboxService = inboxServiceInstance;
|
|
310
180
|
this._emitter.on("session.initialize.resolved", ({ error, data }) => {
|
|
311
181
|
if (data) {
|
|
312
182
|
this.onSessionSuccess(data);
|
|
@@ -350,11 +220,11 @@ _sessionError = new WeakMap();
|
|
|
350
220
|
// src/notifications/notification.ts
|
|
351
221
|
var _emitter, _inboxService;
|
|
352
222
|
var Notification = class {
|
|
353
|
-
constructor(notification) {
|
|
223
|
+
constructor(notification, emitter, inboxService) {
|
|
354
224
|
__privateAdd(this, _emitter);
|
|
355
225
|
__privateAdd(this, _inboxService);
|
|
356
|
-
__privateSet(this, _emitter,
|
|
357
|
-
__privateSet(this, _inboxService,
|
|
226
|
+
__privateSet(this, _emitter, emitter);
|
|
227
|
+
__privateSet(this, _inboxService, inboxService);
|
|
358
228
|
this.id = notification.id;
|
|
359
229
|
this.subject = notification.subject;
|
|
360
230
|
this.body = notification.body;
|
|
@@ -476,19 +346,26 @@ var read = (_0) => __async(void 0, [_0], function* ({
|
|
|
476
346
|
apiService,
|
|
477
347
|
args
|
|
478
348
|
}) {
|
|
479
|
-
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
349
|
+
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
350
|
+
args,
|
|
351
|
+
{
|
|
352
|
+
isRead: true,
|
|
353
|
+
readAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
354
|
+
isArchived: false,
|
|
355
|
+
archivedAt: void 0
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
emitter,
|
|
359
|
+
apiService
|
|
360
|
+
}
|
|
361
|
+
);
|
|
485
362
|
try {
|
|
486
363
|
emitter.emit("notification.read.pending", {
|
|
487
364
|
args,
|
|
488
365
|
data: optimisticValue
|
|
489
366
|
});
|
|
490
367
|
const response = yield apiService.read(notificationId);
|
|
491
|
-
const updatedNotification = new Notification(response);
|
|
368
|
+
const updatedNotification = new Notification(response, emitter, apiService);
|
|
492
369
|
emitter.emit("notification.read.resolved", { args, data: updatedNotification });
|
|
493
370
|
return { data: updatedNotification };
|
|
494
371
|
} catch (error) {
|
|
@@ -501,19 +378,26 @@ var unread = (_0) => __async(void 0, [_0], function* ({
|
|
|
501
378
|
apiService,
|
|
502
379
|
args
|
|
503
380
|
}) {
|
|
504
|
-
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
381
|
+
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
382
|
+
args,
|
|
383
|
+
{
|
|
384
|
+
isRead: false,
|
|
385
|
+
readAt: null,
|
|
386
|
+
isArchived: false,
|
|
387
|
+
archivedAt: void 0
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
emitter,
|
|
391
|
+
apiService
|
|
392
|
+
}
|
|
393
|
+
);
|
|
510
394
|
try {
|
|
511
395
|
emitter.emit("notification.unread.pending", {
|
|
512
396
|
args,
|
|
513
397
|
data: optimisticValue
|
|
514
398
|
});
|
|
515
399
|
const response = yield apiService.unread(notificationId);
|
|
516
|
-
const updatedNotification = new Notification(response);
|
|
400
|
+
const updatedNotification = new Notification(response, emitter, apiService);
|
|
517
401
|
emitter.emit("notification.unread.resolved", { args, data: updatedNotification });
|
|
518
402
|
return { data: updatedNotification };
|
|
519
403
|
} catch (error) {
|
|
@@ -526,19 +410,26 @@ var archive = (_0) => __async(void 0, [_0], function* ({
|
|
|
526
410
|
apiService,
|
|
527
411
|
args
|
|
528
412
|
}) {
|
|
529
|
-
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
413
|
+
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
414
|
+
args,
|
|
415
|
+
{
|
|
416
|
+
isArchived: true,
|
|
417
|
+
archivedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
418
|
+
isRead: true,
|
|
419
|
+
readAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
emitter,
|
|
423
|
+
apiService
|
|
424
|
+
}
|
|
425
|
+
);
|
|
535
426
|
try {
|
|
536
427
|
emitter.emit("notification.archive.pending", {
|
|
537
428
|
args,
|
|
538
429
|
data: optimisticValue
|
|
539
430
|
});
|
|
540
431
|
const response = yield apiService.archive(notificationId);
|
|
541
|
-
const updatedNotification = new Notification(response);
|
|
432
|
+
const updatedNotification = new Notification(response, emitter, apiService);
|
|
542
433
|
emitter.emit("notification.archive.resolved", { args, data: updatedNotification });
|
|
543
434
|
return { data: updatedNotification };
|
|
544
435
|
} catch (error) {
|
|
@@ -551,19 +442,26 @@ var unarchive = (_0) => __async(void 0, [_0], function* ({
|
|
|
551
442
|
apiService,
|
|
552
443
|
args
|
|
553
444
|
}) {
|
|
554
|
-
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
445
|
+
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
446
|
+
args,
|
|
447
|
+
{
|
|
448
|
+
isArchived: false,
|
|
449
|
+
archivedAt: null,
|
|
450
|
+
isRead: true,
|
|
451
|
+
readAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
emitter,
|
|
455
|
+
apiService
|
|
456
|
+
}
|
|
457
|
+
);
|
|
560
458
|
try {
|
|
561
459
|
emitter.emit("notification.unarchive.pending", {
|
|
562
460
|
args,
|
|
563
461
|
data: optimisticValue
|
|
564
462
|
});
|
|
565
463
|
const response = yield apiService.unarchive(notificationId);
|
|
566
|
-
const updatedNotification = new Notification(response);
|
|
464
|
+
const updatedNotification = new Notification(response, emitter, apiService);
|
|
567
465
|
emitter.emit("notification.unarchive.resolved", { args, data: updatedNotification });
|
|
568
466
|
return { data: updatedNotification };
|
|
569
467
|
} catch (error) {
|
|
@@ -586,14 +484,17 @@ var completeAction = (_0) => __async(void 0, [_0], function* ({
|
|
|
586
484
|
isCompleted: true
|
|
587
485
|
})
|
|
588
486
|
};
|
|
589
|
-
const { notificationId, optimisticValue } = getNotificationDetails(args, optimisticUpdate
|
|
487
|
+
const { notificationId, optimisticValue } = getNotificationDetails(args, optimisticUpdate, {
|
|
488
|
+
emitter,
|
|
489
|
+
apiService
|
|
490
|
+
});
|
|
590
491
|
try {
|
|
591
492
|
emitter.emit("notification.complete_action.pending", {
|
|
592
493
|
args,
|
|
593
494
|
data: optimisticValue
|
|
594
495
|
});
|
|
595
496
|
const response = yield apiService.completeAction({ actionType, notificationId });
|
|
596
|
-
const updatedNotification = new Notification(response);
|
|
497
|
+
const updatedNotification = new Notification(response, emitter, apiService);
|
|
597
498
|
emitter.emit("notification.complete_action.resolved", { args, data: updatedNotification });
|
|
598
499
|
return { data: updatedNotification };
|
|
599
500
|
} catch (error) {
|
|
@@ -616,14 +517,17 @@ var revertAction = (_0) => __async(void 0, [_0], function* ({
|
|
|
616
517
|
isCompleted: false
|
|
617
518
|
})
|
|
618
519
|
};
|
|
619
|
-
const { notificationId, optimisticValue } = getNotificationDetails(args, optimisticUpdate
|
|
520
|
+
const { notificationId, optimisticValue } = getNotificationDetails(args, optimisticUpdate, {
|
|
521
|
+
emitter,
|
|
522
|
+
apiService
|
|
523
|
+
});
|
|
620
524
|
try {
|
|
621
525
|
emitter.emit("notification.revert_action.pending", {
|
|
622
526
|
args,
|
|
623
527
|
data: optimisticValue
|
|
624
528
|
});
|
|
625
529
|
const response = yield apiService.revertAction({ actionType, notificationId });
|
|
626
|
-
const updatedNotification = new Notification(response);
|
|
530
|
+
const updatedNotification = new Notification(response, emitter, apiService);
|
|
627
531
|
emitter.emit("notification.revert_action.resolved", { args, data: updatedNotification });
|
|
628
532
|
return { data: updatedNotification };
|
|
629
533
|
} catch (error) {
|
|
@@ -631,11 +535,15 @@ var revertAction = (_0) => __async(void 0, [_0], function* ({
|
|
|
631
535
|
return { error: new NovuError("Failed to fetch notifications", error) };
|
|
632
536
|
}
|
|
633
537
|
});
|
|
634
|
-
var getNotificationDetails = (args, update) => {
|
|
538
|
+
var getNotificationDetails = (args, update, dependencies) => {
|
|
635
539
|
if ("notification" in args) {
|
|
636
540
|
return {
|
|
637
541
|
notificationId: args.notification.id,
|
|
638
|
-
optimisticValue: new Notification(
|
|
542
|
+
optimisticValue: new Notification(
|
|
543
|
+
__spreadValues(__spreadValues({}, args.notification), update),
|
|
544
|
+
dependencies.emitter,
|
|
545
|
+
dependencies.apiService
|
|
546
|
+
)
|
|
639
547
|
};
|
|
640
548
|
} else {
|
|
641
549
|
return {
|
|
@@ -652,12 +560,16 @@ var readAll = (_0) => __async(void 0, [_0], function* ({
|
|
|
652
560
|
try {
|
|
653
561
|
const notifications = notificationsCache.getUniqueNotifications({ tags });
|
|
654
562
|
const optimisticNotifications = notifications.map(
|
|
655
|
-
(notification) => new Notification(
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
563
|
+
(notification) => new Notification(
|
|
564
|
+
__spreadProps(__spreadValues({}, notification), {
|
|
565
|
+
isRead: true,
|
|
566
|
+
readAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
567
|
+
isArchived: false,
|
|
568
|
+
archivedAt: void 0
|
|
569
|
+
}),
|
|
570
|
+
emitter,
|
|
571
|
+
inboxService
|
|
572
|
+
)
|
|
661
573
|
);
|
|
662
574
|
emitter.emit("notifications.read_all.pending", { args: { tags }, data: optimisticNotifications });
|
|
663
575
|
yield inboxService.readAll({ tags });
|
|
@@ -677,12 +589,16 @@ var archiveAll = (_0) => __async(void 0, [_0], function* ({
|
|
|
677
589
|
try {
|
|
678
590
|
const notifications = notificationsCache.getUniqueNotifications({ tags });
|
|
679
591
|
const optimisticNotifications = notifications.map(
|
|
680
|
-
(notification) => new Notification(
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
592
|
+
(notification) => new Notification(
|
|
593
|
+
__spreadProps(__spreadValues({}, notification), {
|
|
594
|
+
isRead: true,
|
|
595
|
+
readAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
596
|
+
isArchived: true,
|
|
597
|
+
archivedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
598
|
+
}),
|
|
599
|
+
emitter,
|
|
600
|
+
inboxService
|
|
601
|
+
)
|
|
686
602
|
);
|
|
687
603
|
emitter.emit("notifications.archive_all.pending", { args: { tags }, data: optimisticNotifications });
|
|
688
604
|
yield inboxService.archiveAll({ tags });
|
|
@@ -702,7 +618,11 @@ var archiveAllRead = (_0) => __async(void 0, [_0], function* ({
|
|
|
702
618
|
try {
|
|
703
619
|
const notifications = notificationsCache.getUniqueNotifications({ tags, read: true });
|
|
704
620
|
const optimisticNotifications = notifications.map(
|
|
705
|
-
(notification) => new Notification(
|
|
621
|
+
(notification) => new Notification(
|
|
622
|
+
__spreadProps(__spreadValues({}, notification), { isArchived: true, archivedAt: (/* @__PURE__ */ new Date()).toISOString() }),
|
|
623
|
+
emitter,
|
|
624
|
+
inboxService
|
|
625
|
+
)
|
|
706
626
|
);
|
|
707
627
|
emitter.emit("notifications.archive_all_read.pending", { args: { tags }, data: optimisticNotifications });
|
|
708
628
|
yield inboxService.archiveAllRead({ tags });
|
|
@@ -779,7 +699,7 @@ var removeEvents = [
|
|
|
779
699
|
];
|
|
780
700
|
var _emitter2, _cache2;
|
|
781
701
|
var NotificationsCache = class {
|
|
782
|
-
constructor() {
|
|
702
|
+
constructor({ emitter }) {
|
|
783
703
|
__privateAdd(this, _emitter2);
|
|
784
704
|
/**
|
|
785
705
|
* The key is the stringified notifications filter, the values are the paginated notifications.
|
|
@@ -841,7 +761,7 @@ var NotificationsCache = class {
|
|
|
841
761
|
});
|
|
842
762
|
});
|
|
843
763
|
};
|
|
844
|
-
__privateSet(this, _emitter2,
|
|
764
|
+
__privateSet(this, _emitter2, emitter);
|
|
845
765
|
updateEvents.forEach((event) => {
|
|
846
766
|
__privateGet(this, _emitter2).on(event, this.handleNotificationEvent());
|
|
847
767
|
});
|
|
@@ -924,10 +844,19 @@ _cache2 = new WeakMap();
|
|
|
924
844
|
// src/notifications/notifications.ts
|
|
925
845
|
var _useCache;
|
|
926
846
|
var Notifications = class extends BaseModule {
|
|
927
|
-
constructor({
|
|
928
|
-
|
|
847
|
+
constructor({
|
|
848
|
+
useCache,
|
|
849
|
+
inboxServiceInstance,
|
|
850
|
+
eventEmitterInstance
|
|
851
|
+
}) {
|
|
852
|
+
super({
|
|
853
|
+
eventEmitterInstance,
|
|
854
|
+
inboxServiceInstance
|
|
855
|
+
});
|
|
929
856
|
__privateAdd(this, _useCache);
|
|
930
|
-
this.cache = new NotificationsCache(
|
|
857
|
+
this.cache = new NotificationsCache({
|
|
858
|
+
emitter: eventEmitterInstance
|
|
859
|
+
});
|
|
931
860
|
__privateSet(this, _useCache, useCache);
|
|
932
861
|
}
|
|
933
862
|
list() {
|
|
@@ -945,7 +874,7 @@ var Notifications = class extends BaseModule {
|
|
|
945
874
|
data = {
|
|
946
875
|
hasMore: response.hasMore,
|
|
947
876
|
filter: response.filter,
|
|
948
|
-
notifications: response.data.map((el) => new Notification(el))
|
|
877
|
+
notifications: response.data.map((el) => new Notification(el, this._emitter, this._inboxService))
|
|
949
878
|
};
|
|
950
879
|
if (__privateGet(this, _useCache)) {
|
|
951
880
|
this.cache.set(args, data);
|
|
@@ -1142,14 +1071,46 @@ var Notifications = class extends BaseModule {
|
|
|
1142
1071
|
};
|
|
1143
1072
|
_useCache = new WeakMap();
|
|
1144
1073
|
|
|
1074
|
+
// src/session/session.ts
|
|
1075
|
+
var _emitter3, _inboxService2, _options;
|
|
1076
|
+
var Session = class {
|
|
1077
|
+
constructor(options, inboxServiceInstance, eventEmitterInstance) {
|
|
1078
|
+
__privateAdd(this, _emitter3);
|
|
1079
|
+
__privateAdd(this, _inboxService2);
|
|
1080
|
+
__privateAdd(this, _options);
|
|
1081
|
+
__privateSet(this, _emitter3, eventEmitterInstance);
|
|
1082
|
+
__privateSet(this, _inboxService2, inboxServiceInstance);
|
|
1083
|
+
__privateSet(this, _options, options);
|
|
1084
|
+
}
|
|
1085
|
+
initialize() {
|
|
1086
|
+
return __async(this, null, function* () {
|
|
1087
|
+
try {
|
|
1088
|
+
const { applicationIdentifier, subscriberId, subscriberHash } = __privateGet(this, _options);
|
|
1089
|
+
__privateGet(this, _emitter3).emit("session.initialize.pending", { args: __privateGet(this, _options) });
|
|
1090
|
+
const response = yield __privateGet(this, _inboxService2).initializeSession({
|
|
1091
|
+
applicationIdentifier,
|
|
1092
|
+
subscriberId,
|
|
1093
|
+
subscriberHash
|
|
1094
|
+
});
|
|
1095
|
+
__privateGet(this, _emitter3).emit("session.initialize.resolved", { args: __privateGet(this, _options), data: response });
|
|
1096
|
+
} catch (error) {
|
|
1097
|
+
__privateGet(this, _emitter3).emit("session.initialize.resolved", { args: __privateGet(this, _options), error });
|
|
1098
|
+
}
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
};
|
|
1102
|
+
_emitter3 = new WeakMap();
|
|
1103
|
+
_inboxService2 = new WeakMap();
|
|
1104
|
+
_options = new WeakMap();
|
|
1105
|
+
|
|
1145
1106
|
// src/preferences/preference.ts
|
|
1146
|
-
var
|
|
1107
|
+
var _emitter4, _apiService;
|
|
1147
1108
|
var Preference = class {
|
|
1148
|
-
constructor(preference) {
|
|
1149
|
-
__privateAdd(this,
|
|
1109
|
+
constructor(preference, { emitterInstance, inboxServiceInstance }) {
|
|
1110
|
+
__privateAdd(this, _emitter4);
|
|
1150
1111
|
__privateAdd(this, _apiService);
|
|
1151
|
-
__privateSet(this,
|
|
1152
|
-
__privateSet(this, _apiService,
|
|
1112
|
+
__privateSet(this, _emitter4, emitterInstance);
|
|
1113
|
+
__privateSet(this, _apiService, inboxServiceInstance);
|
|
1153
1114
|
this.level = preference.level;
|
|
1154
1115
|
this.enabled = preference.enabled;
|
|
1155
1116
|
this.channels = preference.channels;
|
|
@@ -1158,7 +1119,7 @@ var Preference = class {
|
|
|
1158
1119
|
update({ channelPreferences }) {
|
|
1159
1120
|
var _a;
|
|
1160
1121
|
return updatePreference({
|
|
1161
|
-
emitter: __privateGet(this,
|
|
1122
|
+
emitter: __privateGet(this, _emitter4),
|
|
1162
1123
|
apiService: __privateGet(this, _apiService),
|
|
1163
1124
|
args: {
|
|
1164
1125
|
workflowId: (_a = this.workflow) == null ? void 0 : _a.id,
|
|
@@ -1173,7 +1134,7 @@ var Preference = class {
|
|
|
1173
1134
|
});
|
|
1174
1135
|
}
|
|
1175
1136
|
};
|
|
1176
|
-
|
|
1137
|
+
_emitter4 = new WeakMap();
|
|
1177
1138
|
_apiService = new WeakMap();
|
|
1178
1139
|
|
|
1179
1140
|
// src/preferences/helpers.ts
|
|
@@ -1186,9 +1147,15 @@ var updatePreference = (_0) => __async(void 0, [_0], function* ({
|
|
|
1186
1147
|
try {
|
|
1187
1148
|
emitter.emit("preference.update.pending", {
|
|
1188
1149
|
args,
|
|
1189
|
-
data: args.preference ? new Preference(
|
|
1190
|
-
|
|
1191
|
-
|
|
1150
|
+
data: args.preference ? new Preference(
|
|
1151
|
+
__spreadProps(__spreadValues({}, args.preference), {
|
|
1152
|
+
channels: __spreadValues(__spreadValues({}, args.preference.channels), channelPreferences)
|
|
1153
|
+
}),
|
|
1154
|
+
{
|
|
1155
|
+
emitterInstance: emitter,
|
|
1156
|
+
inboxServiceInstance: apiService
|
|
1157
|
+
}
|
|
1158
|
+
) : void 0
|
|
1192
1159
|
});
|
|
1193
1160
|
let response;
|
|
1194
1161
|
if (workflowId) {
|
|
@@ -1196,7 +1163,10 @@ var updatePreference = (_0) => __async(void 0, [_0], function* ({
|
|
|
1196
1163
|
} else {
|
|
1197
1164
|
response = yield apiService.updateGlobalPreferences(channelPreferences);
|
|
1198
1165
|
}
|
|
1199
|
-
const preference = new Preference(response
|
|
1166
|
+
const preference = new Preference(response, {
|
|
1167
|
+
emitterInstance: emitter,
|
|
1168
|
+
inboxServiceInstance: apiService
|
|
1169
|
+
});
|
|
1200
1170
|
emitter.emit("preference.update.resolved", { args, data: preference });
|
|
1201
1171
|
return { data: preference };
|
|
1202
1172
|
} catch (error) {
|
|
@@ -1208,10 +1178,10 @@ var updatePreference = (_0) => __async(void 0, [_0], function* ({
|
|
|
1208
1178
|
// src/cache/preferences-cache.ts
|
|
1209
1179
|
var updateEvents2 = ["preference.update.pending", "preference.update.resolved"];
|
|
1210
1180
|
var DEFAULT_KEY = "default";
|
|
1211
|
-
var
|
|
1181
|
+
var _emitter5, _cache3;
|
|
1212
1182
|
var PreferencesCache = class {
|
|
1213
|
-
constructor() {
|
|
1214
|
-
__privateAdd(this,
|
|
1183
|
+
constructor({ emitterInstance }) {
|
|
1184
|
+
__privateAdd(this, _emitter5);
|
|
1215
1185
|
__privateAdd(this, _cache3);
|
|
1216
1186
|
this.updatePreference = (key, data) => {
|
|
1217
1187
|
const preferences = __privateGet(this, _cache3).get(key);
|
|
@@ -1242,14 +1212,14 @@ var PreferencesCache = class {
|
|
|
1242
1212
|
if (!hasUpdatedPreference || !updatedPreference) {
|
|
1243
1213
|
return;
|
|
1244
1214
|
}
|
|
1245
|
-
__privateGet(this,
|
|
1215
|
+
__privateGet(this, _emitter5).emit("preferences.list.updated", {
|
|
1246
1216
|
data: updatedPreference
|
|
1247
1217
|
});
|
|
1248
1218
|
});
|
|
1249
1219
|
};
|
|
1250
|
-
__privateSet(this,
|
|
1220
|
+
__privateSet(this, _emitter5, emitterInstance);
|
|
1251
1221
|
updateEvents2.forEach((event) => {
|
|
1252
|
-
__privateGet(this,
|
|
1222
|
+
__privateGet(this, _emitter5).on(event, this.handlePreferenceEvent);
|
|
1253
1223
|
});
|
|
1254
1224
|
__privateSet(this, _cache3, new InMemoryCache());
|
|
1255
1225
|
}
|
|
@@ -1263,16 +1233,25 @@ var PreferencesCache = class {
|
|
|
1263
1233
|
__privateGet(this, _cache3).clear();
|
|
1264
1234
|
}
|
|
1265
1235
|
};
|
|
1266
|
-
|
|
1236
|
+
_emitter5 = new WeakMap();
|
|
1267
1237
|
_cache3 = new WeakMap();
|
|
1268
1238
|
|
|
1269
1239
|
// src/preferences/preferences.ts
|
|
1270
1240
|
var _useCache2;
|
|
1271
1241
|
var Preferences = class extends BaseModule {
|
|
1272
|
-
constructor({
|
|
1273
|
-
|
|
1242
|
+
constructor({
|
|
1243
|
+
useCache,
|
|
1244
|
+
inboxServiceInstance,
|
|
1245
|
+
eventEmitterInstance
|
|
1246
|
+
}) {
|
|
1247
|
+
super({
|
|
1248
|
+
eventEmitterInstance,
|
|
1249
|
+
inboxServiceInstance
|
|
1250
|
+
});
|
|
1274
1251
|
__privateAdd(this, _useCache2);
|
|
1275
|
-
this.cache = new PreferencesCache(
|
|
1252
|
+
this.cache = new PreferencesCache({
|
|
1253
|
+
emitterInstance: this._emitter
|
|
1254
|
+
});
|
|
1276
1255
|
__privateSet(this, _useCache2, useCache);
|
|
1277
1256
|
}
|
|
1278
1257
|
list() {
|
|
@@ -1283,7 +1262,12 @@ var Preferences = class extends BaseModule {
|
|
|
1283
1262
|
this._emitter.emit("preferences.list.pending", { args: void 0, data });
|
|
1284
1263
|
if (!data) {
|
|
1285
1264
|
const response = yield this._inboxService.fetchPreferences();
|
|
1286
|
-
data = response.map(
|
|
1265
|
+
data = response.map(
|
|
1266
|
+
(el) => new Preference(el, {
|
|
1267
|
+
emitterInstance: this._emitter,
|
|
1268
|
+
inboxServiceInstance: this._inboxService
|
|
1269
|
+
})
|
|
1270
|
+
);
|
|
1287
1271
|
if (__privateGet(this, _useCache2)) {
|
|
1288
1272
|
this.cache.set(data);
|
|
1289
1273
|
}
|
|
@@ -1308,41 +1292,6 @@ var Preferences = class extends BaseModule {
|
|
|
1308
1292
|
}
|
|
1309
1293
|
};
|
|
1310
1294
|
_useCache2 = new WeakMap();
|
|
1311
|
-
|
|
1312
|
-
// src/session/session.ts
|
|
1313
|
-
var _emitter5, _inboxService2, _options;
|
|
1314
|
-
var Session = class {
|
|
1315
|
-
constructor(options) {
|
|
1316
|
-
__privateAdd(this, _emitter5);
|
|
1317
|
-
__privateAdd(this, _inboxService2);
|
|
1318
|
-
__privateAdd(this, _options);
|
|
1319
|
-
__privateSet(this, _emitter5, NovuEventEmitter.getInstance());
|
|
1320
|
-
__privateSet(this, _inboxService2, InboxServiceSingleton.getInstance());
|
|
1321
|
-
__privateSet(this, _options, options);
|
|
1322
|
-
}
|
|
1323
|
-
initialize() {
|
|
1324
|
-
return __async(this, null, function* () {
|
|
1325
|
-
try {
|
|
1326
|
-
const { applicationIdentifier, subscriberId, subscriberHash } = __privateGet(this, _options);
|
|
1327
|
-
__privateGet(this, _emitter5).emit("session.initialize.pending", { args: __privateGet(this, _options) });
|
|
1328
|
-
const response = yield __privateGet(this, _inboxService2).initializeSession({
|
|
1329
|
-
applicationIdentifier,
|
|
1330
|
-
subscriberId,
|
|
1331
|
-
subscriberHash
|
|
1332
|
-
});
|
|
1333
|
-
__privateGet(this, _emitter5).emit("session.initialize.resolved", { args: __privateGet(this, _options), data: response });
|
|
1334
|
-
} catch (error) {
|
|
1335
|
-
__privateGet(this, _emitter5).emit("session.initialize.resolved", { args: __privateGet(this, _options), error });
|
|
1336
|
-
}
|
|
1337
|
-
});
|
|
1338
|
-
}
|
|
1339
|
-
};
|
|
1340
|
-
_emitter5 = new WeakMap();
|
|
1341
|
-
_inboxService2 = new WeakMap();
|
|
1342
|
-
_options = new WeakMap();
|
|
1343
|
-
|
|
1344
|
-
// src/utils/config.ts
|
|
1345
|
-
var PRODUCTION_BACKEND_URL = "https://api.novu.co";
|
|
1346
1295
|
var PRODUCTION_SOCKET_URL = "https://ws.novu.co";
|
|
1347
1296
|
var NOTIFICATION_RECEIVED = "notifications.notification_received";
|
|
1348
1297
|
var UNSEEN_COUNT_CHANGED = "notifications.unseen_count_changed";
|
|
@@ -1413,8 +1362,15 @@ var mapToNotification = ({
|
|
|
1413
1362
|
};
|
|
1414
1363
|
var _token, _emitter6, _socketIo, _socketUrl, _notificationReceived, _unseenCountChanged, _unreadCountChanged, _Socket_instances, initializeSocket_fn;
|
|
1415
1364
|
var Socket = class extends BaseModule {
|
|
1416
|
-
constructor({
|
|
1417
|
-
|
|
1365
|
+
constructor({
|
|
1366
|
+
socketUrl,
|
|
1367
|
+
inboxServiceInstance,
|
|
1368
|
+
eventEmitterInstance
|
|
1369
|
+
}) {
|
|
1370
|
+
super({
|
|
1371
|
+
eventEmitterInstance,
|
|
1372
|
+
inboxServiceInstance
|
|
1373
|
+
});
|
|
1418
1374
|
__privateAdd(this, _Socket_instances);
|
|
1419
1375
|
__privateAdd(this, _token);
|
|
1420
1376
|
__privateAdd(this, _emitter6);
|
|
@@ -1422,7 +1378,7 @@ var Socket = class extends BaseModule {
|
|
|
1422
1378
|
__privateAdd(this, _socketUrl);
|
|
1423
1379
|
__privateAdd(this, _notificationReceived, ({ message }) => {
|
|
1424
1380
|
__privateGet(this, _emitter6).emit(NOTIFICATION_RECEIVED, {
|
|
1425
|
-
result: new Notification(mapToNotification(message))
|
|
1381
|
+
result: new Notification(mapToNotification(message), __privateGet(this, _emitter6), this._inboxService)
|
|
1426
1382
|
});
|
|
1427
1383
|
});
|
|
1428
1384
|
__privateAdd(this, _unseenCountChanged, ({ unseenCount }) => {
|
|
@@ -1435,7 +1391,7 @@ var Socket = class extends BaseModule {
|
|
|
1435
1391
|
result: unreadCount
|
|
1436
1392
|
});
|
|
1437
1393
|
});
|
|
1438
|
-
__privateSet(this, _emitter6,
|
|
1394
|
+
__privateSet(this, _emitter6, eventEmitterInstance);
|
|
1439
1395
|
__privateSet(this, _socketUrl, socketUrl != null ? socketUrl : PRODUCTION_SOCKET_URL);
|
|
1440
1396
|
}
|
|
1441
1397
|
onSessionSuccess({ token }) {
|
|
@@ -1494,34 +1450,168 @@ initializeSocket_fn = function() {
|
|
|
1494
1450
|
});
|
|
1495
1451
|
};
|
|
1496
1452
|
|
|
1453
|
+
// src/utils/config.ts
|
|
1454
|
+
var PRODUCTION_BACKEND_URL = "https://api.novu.co";
|
|
1455
|
+
var NOVU_API_VERSION = "2024-06-26";
|
|
1456
|
+
var INBOX_ROUTE = "/inbox";
|
|
1457
|
+
var INBOX_NOTIFICATIONS_ROUTE = `${INBOX_ROUTE}/notifications`;
|
|
1458
|
+
var _httpClient;
|
|
1459
|
+
var InboxService = class {
|
|
1460
|
+
constructor(options = {}) {
|
|
1461
|
+
this.isSessionInitialized = false;
|
|
1462
|
+
__privateAdd(this, _httpClient);
|
|
1463
|
+
__privateSet(this, _httpClient, new HttpClient(options));
|
|
1464
|
+
__privateGet(this, _httpClient).updateHeaders({
|
|
1465
|
+
"Novu-API-Version": NOVU_API_VERSION
|
|
1466
|
+
});
|
|
1467
|
+
}
|
|
1468
|
+
initializeSession(_0) {
|
|
1469
|
+
return __async(this, arguments, function* ({
|
|
1470
|
+
applicationIdentifier,
|
|
1471
|
+
subscriberId,
|
|
1472
|
+
subscriberHash
|
|
1473
|
+
}) {
|
|
1474
|
+
const response = yield __privateGet(this, _httpClient).post(`${INBOX_ROUTE}/session`, {
|
|
1475
|
+
applicationIdentifier,
|
|
1476
|
+
subscriberId,
|
|
1477
|
+
subscriberHash
|
|
1478
|
+
});
|
|
1479
|
+
__privateGet(this, _httpClient).setAuthorizationToken(response.token);
|
|
1480
|
+
this.isSessionInitialized = true;
|
|
1481
|
+
return response;
|
|
1482
|
+
});
|
|
1483
|
+
}
|
|
1484
|
+
fetchNotifications({
|
|
1485
|
+
after,
|
|
1486
|
+
archived,
|
|
1487
|
+
limit = 10,
|
|
1488
|
+
offset,
|
|
1489
|
+
read: read2,
|
|
1490
|
+
tags
|
|
1491
|
+
}) {
|
|
1492
|
+
const queryParams = new URLSearchParams(`limit=${limit}`);
|
|
1493
|
+
if (after) {
|
|
1494
|
+
queryParams.append("after", after);
|
|
1495
|
+
}
|
|
1496
|
+
if (offset) {
|
|
1497
|
+
queryParams.append("offset", `${offset}`);
|
|
1498
|
+
}
|
|
1499
|
+
if (tags) {
|
|
1500
|
+
tags.forEach((tag) => queryParams.append("tags[]", tag));
|
|
1501
|
+
}
|
|
1502
|
+
if (read2 !== void 0) {
|
|
1503
|
+
queryParams.append("read", `${read2}`);
|
|
1504
|
+
}
|
|
1505
|
+
if (archived !== void 0) {
|
|
1506
|
+
queryParams.append("archived", `${archived}`);
|
|
1507
|
+
}
|
|
1508
|
+
return __privateGet(this, _httpClient).getFullResponse(`${INBOX_NOTIFICATIONS_ROUTE}?${queryParams.toString()}`);
|
|
1509
|
+
}
|
|
1510
|
+
count({ filters }) {
|
|
1511
|
+
return __privateGet(this, _httpClient).getFullResponse(`${INBOX_NOTIFICATIONS_ROUTE}/count?filters=${JSON.stringify(filters)}`);
|
|
1512
|
+
}
|
|
1513
|
+
read(notificationId) {
|
|
1514
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/read`);
|
|
1515
|
+
}
|
|
1516
|
+
unread(notificationId) {
|
|
1517
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/unread`);
|
|
1518
|
+
}
|
|
1519
|
+
archive(notificationId) {
|
|
1520
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/archive`);
|
|
1521
|
+
}
|
|
1522
|
+
unarchive(notificationId) {
|
|
1523
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/unarchive`);
|
|
1524
|
+
}
|
|
1525
|
+
readAll({ tags }) {
|
|
1526
|
+
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read`, { tags });
|
|
1527
|
+
}
|
|
1528
|
+
archiveAll({ tags }) {
|
|
1529
|
+
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/archive`, { tags });
|
|
1530
|
+
}
|
|
1531
|
+
archiveAllRead({ tags }) {
|
|
1532
|
+
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read-archive`, { tags });
|
|
1533
|
+
}
|
|
1534
|
+
completeAction({
|
|
1535
|
+
actionType,
|
|
1536
|
+
notificationId
|
|
1537
|
+
}) {
|
|
1538
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/complete`, {
|
|
1539
|
+
actionType
|
|
1540
|
+
});
|
|
1541
|
+
}
|
|
1542
|
+
revertAction({
|
|
1543
|
+
actionType,
|
|
1544
|
+
notificationId
|
|
1545
|
+
}) {
|
|
1546
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/revert`, {
|
|
1547
|
+
actionType
|
|
1548
|
+
});
|
|
1549
|
+
}
|
|
1550
|
+
fetchPreferences() {
|
|
1551
|
+
return __privateGet(this, _httpClient).get(`${INBOX_ROUTE}/preferences`);
|
|
1552
|
+
}
|
|
1553
|
+
updateGlobalPreferences(channelPreferences) {
|
|
1554
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences`, channelPreferences);
|
|
1555
|
+
}
|
|
1556
|
+
updateWorkflowPreferences({
|
|
1557
|
+
workflowId,
|
|
1558
|
+
channelPreferences
|
|
1559
|
+
}) {
|
|
1560
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/${workflowId}`, channelPreferences);
|
|
1561
|
+
}
|
|
1562
|
+
};
|
|
1563
|
+
_httpClient = new WeakMap();
|
|
1564
|
+
|
|
1497
1565
|
// src/novu.ts
|
|
1498
|
-
var _session;
|
|
1566
|
+
var _emitter7, _session, _socket, _inboxService3;
|
|
1499
1567
|
var Novu = class {
|
|
1500
1568
|
constructor(options) {
|
|
1569
|
+
__privateAdd(this, _emitter7);
|
|
1501
1570
|
__privateAdd(this, _session);
|
|
1571
|
+
__privateAdd(this, _socket);
|
|
1572
|
+
__privateAdd(this, _inboxService3);
|
|
1502
1573
|
var _a, _b, _c;
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
__privateSet(this, _session, new Session(
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1574
|
+
__privateSet(this, _inboxService3, new InboxService({ backendUrl: (_a = options.backendUrl) != null ? _a : PRODUCTION_BACKEND_URL }));
|
|
1575
|
+
__privateSet(this, _emitter7, new NovuEventEmitter());
|
|
1576
|
+
__privateSet(this, _session, new Session(
|
|
1577
|
+
{
|
|
1578
|
+
applicationIdentifier: options.applicationIdentifier,
|
|
1579
|
+
subscriberId: options.subscriberId,
|
|
1580
|
+
subscriberHash: options.subscriberHash
|
|
1581
|
+
},
|
|
1582
|
+
__privateGet(this, _inboxService3),
|
|
1583
|
+
__privateGet(this, _emitter7)
|
|
1584
|
+
));
|
|
1510
1585
|
__privateGet(this, _session).initialize();
|
|
1511
|
-
this.notifications = new Notifications({
|
|
1512
|
-
|
|
1513
|
-
|
|
1586
|
+
this.notifications = new Notifications({
|
|
1587
|
+
useCache: (_b = options.useCache) != null ? _b : true,
|
|
1588
|
+
inboxServiceInstance: __privateGet(this, _inboxService3),
|
|
1589
|
+
eventEmitterInstance: __privateGet(this, _emitter7)
|
|
1590
|
+
});
|
|
1591
|
+
this.preferences = new Preferences({
|
|
1592
|
+
useCache: (_c = options.useCache) != null ? _c : true,
|
|
1593
|
+
inboxServiceInstance: __privateGet(this, _inboxService3),
|
|
1594
|
+
eventEmitterInstance: __privateGet(this, _emitter7)
|
|
1595
|
+
});
|
|
1596
|
+
__privateSet(this, _socket, new Socket({
|
|
1597
|
+
socketUrl: options.socketUrl,
|
|
1598
|
+
eventEmitterInstance: __privateGet(this, _emitter7),
|
|
1599
|
+
inboxServiceInstance: __privateGet(this, _inboxService3)
|
|
1600
|
+
}));
|
|
1514
1601
|
this.on = (eventName, listener) => {
|
|
1515
|
-
if (
|
|
1516
|
-
|
|
1602
|
+
if (__privateGet(this, _socket).isSocketEvent(eventName)) {
|
|
1603
|
+
__privateGet(this, _socket).initialize();
|
|
1517
1604
|
}
|
|
1518
|
-
|
|
1605
|
+
__privateGet(this, _emitter7).on(eventName, listener);
|
|
1519
1606
|
};
|
|
1520
1607
|
this.off = (eventName, listener) => {
|
|
1521
|
-
|
|
1608
|
+
__privateGet(this, _emitter7).off(eventName, listener);
|
|
1522
1609
|
};
|
|
1523
1610
|
}
|
|
1524
1611
|
};
|
|
1612
|
+
_emitter7 = new WeakMap();
|
|
1525
1613
|
_session = new WeakMap();
|
|
1614
|
+
_socket = new WeakMap();
|
|
1615
|
+
_inboxService3 = new WeakMap();
|
|
1526
1616
|
|
|
1527
1617
|
export { ActionTypeEnum, ChannelType, CtaType, NotificationActionStatus, NotificationButton, NotificationStatus, Novu, PreferenceLevel, PreferenceOverrideSource, PreferenceOverrideSourceEnum, WebSocketEvent, __async, __objRest, __privateAdd, __privateGet, __privateMethod, __privateSet, __spreadProps, __spreadValues, areTagsEqual, isSameFilter };
|