@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,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var mitt = require('mitt');
|
|
4
|
-
var client = require('@novu/client');
|
|
5
4
|
var io = require('socket.io-client');
|
|
5
|
+
var client = require('@novu/client');
|
|
6
6
|
|
|
7
7
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
8
|
|
|
@@ -147,18 +147,12 @@ var areTagsEqual = (tags1, tags2) => {
|
|
|
147
147
|
var isSameFilter = (filter1, filter2) => {
|
|
148
148
|
return areTagsEqual(filter1.tags, filter2.tags) && filter1.read === filter2.read && filter1.archived === filter2.archived;
|
|
149
149
|
};
|
|
150
|
-
var
|
|
151
|
-
var
|
|
150
|
+
var _mittEmitter;
|
|
151
|
+
var NovuEventEmitter = class {
|
|
152
152
|
constructor() {
|
|
153
153
|
__privateAdd(this, _mittEmitter);
|
|
154
154
|
__privateSet(this, _mittEmitter, mitt__default.default());
|
|
155
155
|
}
|
|
156
|
-
static getInstance(options) {
|
|
157
|
-
if (options == null ? void 0 : options.recreate) {
|
|
158
|
-
__privateSet(_NovuEventEmitter, _instance, new _NovuEventEmitter());
|
|
159
|
-
}
|
|
160
|
-
return __privateGet(_NovuEventEmitter, _instance);
|
|
161
|
-
}
|
|
162
156
|
on(eventName, listener) {
|
|
163
157
|
__privateGet(this, _mittEmitter).on(eventName, listener);
|
|
164
158
|
}
|
|
@@ -169,10 +163,7 @@ var _NovuEventEmitter = class _NovuEventEmitter {
|
|
|
169
163
|
__privateGet(this, _mittEmitter).emit(type, event);
|
|
170
164
|
}
|
|
171
165
|
};
|
|
172
|
-
_instance = new WeakMap();
|
|
173
166
|
_mittEmitter = new WeakMap();
|
|
174
|
-
__privateAdd(_NovuEventEmitter, _instance);
|
|
175
|
-
var NovuEventEmitter = _NovuEventEmitter;
|
|
176
167
|
|
|
177
168
|
// src/utils/errors.ts
|
|
178
169
|
var NovuError = class extends Error {
|
|
@@ -181,139 +172,18 @@ var NovuError = class extends Error {
|
|
|
181
172
|
this.originalError = originalError;
|
|
182
173
|
}
|
|
183
174
|
};
|
|
184
|
-
var NOVU_API_VERSION = "2024-06-26";
|
|
185
|
-
var INBOX_ROUTE = "/inbox";
|
|
186
|
-
var INBOX_NOTIFICATIONS_ROUTE = `${INBOX_ROUTE}/notifications`;
|
|
187
|
-
var _httpClient;
|
|
188
|
-
var InboxService = class {
|
|
189
|
-
constructor(options = {}) {
|
|
190
|
-
this.isSessionInitialized = false;
|
|
191
|
-
__privateAdd(this, _httpClient);
|
|
192
|
-
__privateSet(this, _httpClient, new client.HttpClient(options));
|
|
193
|
-
__privateGet(this, _httpClient).updateHeaders({
|
|
194
|
-
"Novu-API-Version": NOVU_API_VERSION
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
initializeSession(_0) {
|
|
198
|
-
return __async(this, arguments, function* ({
|
|
199
|
-
applicationIdentifier,
|
|
200
|
-
subscriberId,
|
|
201
|
-
subscriberHash
|
|
202
|
-
}) {
|
|
203
|
-
const response = yield __privateGet(this, _httpClient).post(`${INBOX_ROUTE}/session`, {
|
|
204
|
-
applicationIdentifier,
|
|
205
|
-
subscriberId,
|
|
206
|
-
subscriberHash
|
|
207
|
-
});
|
|
208
|
-
__privateGet(this, _httpClient).setAuthorizationToken(response.token);
|
|
209
|
-
this.isSessionInitialized = true;
|
|
210
|
-
return response;
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
fetchNotifications({
|
|
214
|
-
after,
|
|
215
|
-
archived,
|
|
216
|
-
limit = 10,
|
|
217
|
-
offset,
|
|
218
|
-
read: read2,
|
|
219
|
-
tags
|
|
220
|
-
}) {
|
|
221
|
-
const queryParams = new URLSearchParams(`limit=${limit}`);
|
|
222
|
-
if (after) {
|
|
223
|
-
queryParams.append("after", after);
|
|
224
|
-
}
|
|
225
|
-
if (offset) {
|
|
226
|
-
queryParams.append("offset", `${offset}`);
|
|
227
|
-
}
|
|
228
|
-
if (tags) {
|
|
229
|
-
tags.forEach((tag) => queryParams.append("tags[]", tag));
|
|
230
|
-
}
|
|
231
|
-
if (read2 !== void 0) {
|
|
232
|
-
queryParams.append("read", `${read2}`);
|
|
233
|
-
}
|
|
234
|
-
if (archived !== void 0) {
|
|
235
|
-
queryParams.append("archived", `${archived}`);
|
|
236
|
-
}
|
|
237
|
-
return __privateGet(this, _httpClient).getFullResponse(`${INBOX_NOTIFICATIONS_ROUTE}?${queryParams.toString()}`);
|
|
238
|
-
}
|
|
239
|
-
count({ filters }) {
|
|
240
|
-
return __privateGet(this, _httpClient).getFullResponse(`${INBOX_NOTIFICATIONS_ROUTE}/count?filters=${JSON.stringify(filters)}`);
|
|
241
|
-
}
|
|
242
|
-
read(notificationId) {
|
|
243
|
-
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/read`);
|
|
244
|
-
}
|
|
245
|
-
unread(notificationId) {
|
|
246
|
-
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/unread`);
|
|
247
|
-
}
|
|
248
|
-
archive(notificationId) {
|
|
249
|
-
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/archive`);
|
|
250
|
-
}
|
|
251
|
-
unarchive(notificationId) {
|
|
252
|
-
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/unarchive`);
|
|
253
|
-
}
|
|
254
|
-
readAll({ tags }) {
|
|
255
|
-
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read`, { tags });
|
|
256
|
-
}
|
|
257
|
-
archiveAll({ tags }) {
|
|
258
|
-
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/archive`, { tags });
|
|
259
|
-
}
|
|
260
|
-
archiveAllRead({ tags }) {
|
|
261
|
-
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read-archive`, { tags });
|
|
262
|
-
}
|
|
263
|
-
completeAction({
|
|
264
|
-
actionType,
|
|
265
|
-
notificationId
|
|
266
|
-
}) {
|
|
267
|
-
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/complete`, {
|
|
268
|
-
actionType
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
revertAction({
|
|
272
|
-
actionType,
|
|
273
|
-
notificationId
|
|
274
|
-
}) {
|
|
275
|
-
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/revert`, {
|
|
276
|
-
actionType
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
fetchPreferences() {
|
|
280
|
-
return __privateGet(this, _httpClient).get(`${INBOX_ROUTE}/preferences`);
|
|
281
|
-
}
|
|
282
|
-
updateGlobalPreferences(channelPreferences) {
|
|
283
|
-
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences`, channelPreferences);
|
|
284
|
-
}
|
|
285
|
-
updateWorkflowPreferences({
|
|
286
|
-
workflowId,
|
|
287
|
-
channelPreferences
|
|
288
|
-
}) {
|
|
289
|
-
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/${workflowId}`, channelPreferences);
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
_httpClient = new WeakMap();
|
|
293
|
-
|
|
294
|
-
// src/utils/inbox-service-singleton.ts
|
|
295
|
-
var _instance2;
|
|
296
|
-
var _InboxServiceSingleton = class _InboxServiceSingleton {
|
|
297
|
-
static getInstance(options) {
|
|
298
|
-
const isNeedsToRecreate = !!options;
|
|
299
|
-
if (isNeedsToRecreate) {
|
|
300
|
-
__privateSet(_InboxServiceSingleton, _instance2, new InboxService(options));
|
|
301
|
-
}
|
|
302
|
-
return __privateGet(_InboxServiceSingleton, _instance2);
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
_instance2 = new WeakMap();
|
|
306
|
-
__privateAdd(_InboxServiceSingleton, _instance2);
|
|
307
|
-
var InboxServiceSingleton = _InboxServiceSingleton;
|
|
308
175
|
|
|
309
176
|
// src/base-module.ts
|
|
310
177
|
var _callsQueue, _sessionError;
|
|
311
178
|
var BaseModule = class {
|
|
312
|
-
constructor(
|
|
179
|
+
constructor({
|
|
180
|
+
inboxServiceInstance,
|
|
181
|
+
eventEmitterInstance
|
|
182
|
+
}) {
|
|
313
183
|
__privateAdd(this, _callsQueue, []);
|
|
314
184
|
__privateAdd(this, _sessionError);
|
|
315
|
-
this._emitter =
|
|
316
|
-
this._inboxService =
|
|
185
|
+
this._emitter = eventEmitterInstance;
|
|
186
|
+
this._inboxService = inboxServiceInstance;
|
|
317
187
|
this._emitter.on("session.initialize.resolved", ({ error, data }) => {
|
|
318
188
|
if (data) {
|
|
319
189
|
this.onSessionSuccess(data);
|
|
@@ -357,11 +227,11 @@ _sessionError = new WeakMap();
|
|
|
357
227
|
// src/notifications/notification.ts
|
|
358
228
|
var _emitter, _inboxService;
|
|
359
229
|
var Notification = class {
|
|
360
|
-
constructor(notification) {
|
|
230
|
+
constructor(notification, emitter, inboxService) {
|
|
361
231
|
__privateAdd(this, _emitter);
|
|
362
232
|
__privateAdd(this, _inboxService);
|
|
363
|
-
__privateSet(this, _emitter,
|
|
364
|
-
__privateSet(this, _inboxService,
|
|
233
|
+
__privateSet(this, _emitter, emitter);
|
|
234
|
+
__privateSet(this, _inboxService, inboxService);
|
|
365
235
|
this.id = notification.id;
|
|
366
236
|
this.subject = notification.subject;
|
|
367
237
|
this.body = notification.body;
|
|
@@ -483,19 +353,26 @@ var read = (_0) => __async(void 0, [_0], function* ({
|
|
|
483
353
|
apiService,
|
|
484
354
|
args
|
|
485
355
|
}) {
|
|
486
|
-
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
356
|
+
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
357
|
+
args,
|
|
358
|
+
{
|
|
359
|
+
isRead: true,
|
|
360
|
+
readAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
361
|
+
isArchived: false,
|
|
362
|
+
archivedAt: void 0
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
emitter,
|
|
366
|
+
apiService
|
|
367
|
+
}
|
|
368
|
+
);
|
|
492
369
|
try {
|
|
493
370
|
emitter.emit("notification.read.pending", {
|
|
494
371
|
args,
|
|
495
372
|
data: optimisticValue
|
|
496
373
|
});
|
|
497
374
|
const response = yield apiService.read(notificationId);
|
|
498
|
-
const updatedNotification = new Notification(response);
|
|
375
|
+
const updatedNotification = new Notification(response, emitter, apiService);
|
|
499
376
|
emitter.emit("notification.read.resolved", { args, data: updatedNotification });
|
|
500
377
|
return { data: updatedNotification };
|
|
501
378
|
} catch (error) {
|
|
@@ -508,19 +385,26 @@ var unread = (_0) => __async(void 0, [_0], function* ({
|
|
|
508
385
|
apiService,
|
|
509
386
|
args
|
|
510
387
|
}) {
|
|
511
|
-
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
388
|
+
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
389
|
+
args,
|
|
390
|
+
{
|
|
391
|
+
isRead: false,
|
|
392
|
+
readAt: null,
|
|
393
|
+
isArchived: false,
|
|
394
|
+
archivedAt: void 0
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
emitter,
|
|
398
|
+
apiService
|
|
399
|
+
}
|
|
400
|
+
);
|
|
517
401
|
try {
|
|
518
402
|
emitter.emit("notification.unread.pending", {
|
|
519
403
|
args,
|
|
520
404
|
data: optimisticValue
|
|
521
405
|
});
|
|
522
406
|
const response = yield apiService.unread(notificationId);
|
|
523
|
-
const updatedNotification = new Notification(response);
|
|
407
|
+
const updatedNotification = new Notification(response, emitter, apiService);
|
|
524
408
|
emitter.emit("notification.unread.resolved", { args, data: updatedNotification });
|
|
525
409
|
return { data: updatedNotification };
|
|
526
410
|
} catch (error) {
|
|
@@ -533,19 +417,26 @@ var archive = (_0) => __async(void 0, [_0], function* ({
|
|
|
533
417
|
apiService,
|
|
534
418
|
args
|
|
535
419
|
}) {
|
|
536
|
-
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
420
|
+
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
421
|
+
args,
|
|
422
|
+
{
|
|
423
|
+
isArchived: true,
|
|
424
|
+
archivedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
425
|
+
isRead: true,
|
|
426
|
+
readAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
emitter,
|
|
430
|
+
apiService
|
|
431
|
+
}
|
|
432
|
+
);
|
|
542
433
|
try {
|
|
543
434
|
emitter.emit("notification.archive.pending", {
|
|
544
435
|
args,
|
|
545
436
|
data: optimisticValue
|
|
546
437
|
});
|
|
547
438
|
const response = yield apiService.archive(notificationId);
|
|
548
|
-
const updatedNotification = new Notification(response);
|
|
439
|
+
const updatedNotification = new Notification(response, emitter, apiService);
|
|
549
440
|
emitter.emit("notification.archive.resolved", { args, data: updatedNotification });
|
|
550
441
|
return { data: updatedNotification };
|
|
551
442
|
} catch (error) {
|
|
@@ -558,19 +449,26 @@ var unarchive = (_0) => __async(void 0, [_0], function* ({
|
|
|
558
449
|
apiService,
|
|
559
450
|
args
|
|
560
451
|
}) {
|
|
561
|
-
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
452
|
+
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
453
|
+
args,
|
|
454
|
+
{
|
|
455
|
+
isArchived: false,
|
|
456
|
+
archivedAt: null,
|
|
457
|
+
isRead: true,
|
|
458
|
+
readAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
emitter,
|
|
462
|
+
apiService
|
|
463
|
+
}
|
|
464
|
+
);
|
|
567
465
|
try {
|
|
568
466
|
emitter.emit("notification.unarchive.pending", {
|
|
569
467
|
args,
|
|
570
468
|
data: optimisticValue
|
|
571
469
|
});
|
|
572
470
|
const response = yield apiService.unarchive(notificationId);
|
|
573
|
-
const updatedNotification = new Notification(response);
|
|
471
|
+
const updatedNotification = new Notification(response, emitter, apiService);
|
|
574
472
|
emitter.emit("notification.unarchive.resolved", { args, data: updatedNotification });
|
|
575
473
|
return { data: updatedNotification };
|
|
576
474
|
} catch (error) {
|
|
@@ -593,14 +491,17 @@ var completeAction = (_0) => __async(void 0, [_0], function* ({
|
|
|
593
491
|
isCompleted: true
|
|
594
492
|
})
|
|
595
493
|
};
|
|
596
|
-
const { notificationId, optimisticValue } = getNotificationDetails(args, optimisticUpdate
|
|
494
|
+
const { notificationId, optimisticValue } = getNotificationDetails(args, optimisticUpdate, {
|
|
495
|
+
emitter,
|
|
496
|
+
apiService
|
|
497
|
+
});
|
|
597
498
|
try {
|
|
598
499
|
emitter.emit("notification.complete_action.pending", {
|
|
599
500
|
args,
|
|
600
501
|
data: optimisticValue
|
|
601
502
|
});
|
|
602
503
|
const response = yield apiService.completeAction({ actionType, notificationId });
|
|
603
|
-
const updatedNotification = new Notification(response);
|
|
504
|
+
const updatedNotification = new Notification(response, emitter, apiService);
|
|
604
505
|
emitter.emit("notification.complete_action.resolved", { args, data: updatedNotification });
|
|
605
506
|
return { data: updatedNotification };
|
|
606
507
|
} catch (error) {
|
|
@@ -623,14 +524,17 @@ var revertAction = (_0) => __async(void 0, [_0], function* ({
|
|
|
623
524
|
isCompleted: false
|
|
624
525
|
})
|
|
625
526
|
};
|
|
626
|
-
const { notificationId, optimisticValue } = getNotificationDetails(args, optimisticUpdate
|
|
527
|
+
const { notificationId, optimisticValue } = getNotificationDetails(args, optimisticUpdate, {
|
|
528
|
+
emitter,
|
|
529
|
+
apiService
|
|
530
|
+
});
|
|
627
531
|
try {
|
|
628
532
|
emitter.emit("notification.revert_action.pending", {
|
|
629
533
|
args,
|
|
630
534
|
data: optimisticValue
|
|
631
535
|
});
|
|
632
536
|
const response = yield apiService.revertAction({ actionType, notificationId });
|
|
633
|
-
const updatedNotification = new Notification(response);
|
|
537
|
+
const updatedNotification = new Notification(response, emitter, apiService);
|
|
634
538
|
emitter.emit("notification.revert_action.resolved", { args, data: updatedNotification });
|
|
635
539
|
return { data: updatedNotification };
|
|
636
540
|
} catch (error) {
|
|
@@ -638,11 +542,15 @@ var revertAction = (_0) => __async(void 0, [_0], function* ({
|
|
|
638
542
|
return { error: new NovuError("Failed to fetch notifications", error) };
|
|
639
543
|
}
|
|
640
544
|
});
|
|
641
|
-
var getNotificationDetails = (args, update) => {
|
|
545
|
+
var getNotificationDetails = (args, update, dependencies) => {
|
|
642
546
|
if ("notification" in args) {
|
|
643
547
|
return {
|
|
644
548
|
notificationId: args.notification.id,
|
|
645
|
-
optimisticValue: new Notification(
|
|
549
|
+
optimisticValue: new Notification(
|
|
550
|
+
__spreadValues(__spreadValues({}, args.notification), update),
|
|
551
|
+
dependencies.emitter,
|
|
552
|
+
dependencies.apiService
|
|
553
|
+
)
|
|
646
554
|
};
|
|
647
555
|
} else {
|
|
648
556
|
return {
|
|
@@ -659,12 +567,16 @@ var readAll = (_0) => __async(void 0, [_0], function* ({
|
|
|
659
567
|
try {
|
|
660
568
|
const notifications = notificationsCache.getUniqueNotifications({ tags });
|
|
661
569
|
const optimisticNotifications = notifications.map(
|
|
662
|
-
(notification) => new Notification(
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
570
|
+
(notification) => new Notification(
|
|
571
|
+
__spreadProps(__spreadValues({}, notification), {
|
|
572
|
+
isRead: true,
|
|
573
|
+
readAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
574
|
+
isArchived: false,
|
|
575
|
+
archivedAt: void 0
|
|
576
|
+
}),
|
|
577
|
+
emitter,
|
|
578
|
+
inboxService
|
|
579
|
+
)
|
|
668
580
|
);
|
|
669
581
|
emitter.emit("notifications.read_all.pending", { args: { tags }, data: optimisticNotifications });
|
|
670
582
|
yield inboxService.readAll({ tags });
|
|
@@ -684,12 +596,16 @@ var archiveAll = (_0) => __async(void 0, [_0], function* ({
|
|
|
684
596
|
try {
|
|
685
597
|
const notifications = notificationsCache.getUniqueNotifications({ tags });
|
|
686
598
|
const optimisticNotifications = notifications.map(
|
|
687
|
-
(notification) => new Notification(
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
599
|
+
(notification) => new Notification(
|
|
600
|
+
__spreadProps(__spreadValues({}, notification), {
|
|
601
|
+
isRead: true,
|
|
602
|
+
readAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
603
|
+
isArchived: true,
|
|
604
|
+
archivedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
605
|
+
}),
|
|
606
|
+
emitter,
|
|
607
|
+
inboxService
|
|
608
|
+
)
|
|
693
609
|
);
|
|
694
610
|
emitter.emit("notifications.archive_all.pending", { args: { tags }, data: optimisticNotifications });
|
|
695
611
|
yield inboxService.archiveAll({ tags });
|
|
@@ -709,7 +625,11 @@ var archiveAllRead = (_0) => __async(void 0, [_0], function* ({
|
|
|
709
625
|
try {
|
|
710
626
|
const notifications = notificationsCache.getUniqueNotifications({ tags, read: true });
|
|
711
627
|
const optimisticNotifications = notifications.map(
|
|
712
|
-
(notification) => new Notification(
|
|
628
|
+
(notification) => new Notification(
|
|
629
|
+
__spreadProps(__spreadValues({}, notification), { isArchived: true, archivedAt: (/* @__PURE__ */ new Date()).toISOString() }),
|
|
630
|
+
emitter,
|
|
631
|
+
inboxService
|
|
632
|
+
)
|
|
713
633
|
);
|
|
714
634
|
emitter.emit("notifications.archive_all_read.pending", { args: { tags }, data: optimisticNotifications });
|
|
715
635
|
yield inboxService.archiveAllRead({ tags });
|
|
@@ -786,7 +706,7 @@ var removeEvents = [
|
|
|
786
706
|
];
|
|
787
707
|
var _emitter2, _cache2;
|
|
788
708
|
var NotificationsCache = class {
|
|
789
|
-
constructor() {
|
|
709
|
+
constructor({ emitter }) {
|
|
790
710
|
__privateAdd(this, _emitter2);
|
|
791
711
|
/**
|
|
792
712
|
* The key is the stringified notifications filter, the values are the paginated notifications.
|
|
@@ -848,7 +768,7 @@ var NotificationsCache = class {
|
|
|
848
768
|
});
|
|
849
769
|
});
|
|
850
770
|
};
|
|
851
|
-
__privateSet(this, _emitter2,
|
|
771
|
+
__privateSet(this, _emitter2, emitter);
|
|
852
772
|
updateEvents.forEach((event) => {
|
|
853
773
|
__privateGet(this, _emitter2).on(event, this.handleNotificationEvent());
|
|
854
774
|
});
|
|
@@ -931,10 +851,19 @@ _cache2 = new WeakMap();
|
|
|
931
851
|
// src/notifications/notifications.ts
|
|
932
852
|
var _useCache;
|
|
933
853
|
var Notifications = class extends BaseModule {
|
|
934
|
-
constructor({
|
|
935
|
-
|
|
854
|
+
constructor({
|
|
855
|
+
useCache,
|
|
856
|
+
inboxServiceInstance,
|
|
857
|
+
eventEmitterInstance
|
|
858
|
+
}) {
|
|
859
|
+
super({
|
|
860
|
+
eventEmitterInstance,
|
|
861
|
+
inboxServiceInstance
|
|
862
|
+
});
|
|
936
863
|
__privateAdd(this, _useCache);
|
|
937
|
-
this.cache = new NotificationsCache(
|
|
864
|
+
this.cache = new NotificationsCache({
|
|
865
|
+
emitter: eventEmitterInstance
|
|
866
|
+
});
|
|
938
867
|
__privateSet(this, _useCache, useCache);
|
|
939
868
|
}
|
|
940
869
|
list() {
|
|
@@ -952,7 +881,7 @@ var Notifications = class extends BaseModule {
|
|
|
952
881
|
data = {
|
|
953
882
|
hasMore: response.hasMore,
|
|
954
883
|
filter: response.filter,
|
|
955
|
-
notifications: response.data.map((el) => new Notification(el))
|
|
884
|
+
notifications: response.data.map((el) => new Notification(el, this._emitter, this._inboxService))
|
|
956
885
|
};
|
|
957
886
|
if (__privateGet(this, _useCache)) {
|
|
958
887
|
this.cache.set(args, data);
|
|
@@ -1149,14 +1078,46 @@ var Notifications = class extends BaseModule {
|
|
|
1149
1078
|
};
|
|
1150
1079
|
_useCache = new WeakMap();
|
|
1151
1080
|
|
|
1081
|
+
// src/session/session.ts
|
|
1082
|
+
var _emitter3, _inboxService2, _options;
|
|
1083
|
+
var Session = class {
|
|
1084
|
+
constructor(options, inboxServiceInstance, eventEmitterInstance) {
|
|
1085
|
+
__privateAdd(this, _emitter3);
|
|
1086
|
+
__privateAdd(this, _inboxService2);
|
|
1087
|
+
__privateAdd(this, _options);
|
|
1088
|
+
__privateSet(this, _emitter3, eventEmitterInstance);
|
|
1089
|
+
__privateSet(this, _inboxService2, inboxServiceInstance);
|
|
1090
|
+
__privateSet(this, _options, options);
|
|
1091
|
+
}
|
|
1092
|
+
initialize() {
|
|
1093
|
+
return __async(this, null, function* () {
|
|
1094
|
+
try {
|
|
1095
|
+
const { applicationIdentifier, subscriberId, subscriberHash } = __privateGet(this, _options);
|
|
1096
|
+
__privateGet(this, _emitter3).emit("session.initialize.pending", { args: __privateGet(this, _options) });
|
|
1097
|
+
const response = yield __privateGet(this, _inboxService2).initializeSession({
|
|
1098
|
+
applicationIdentifier,
|
|
1099
|
+
subscriberId,
|
|
1100
|
+
subscriberHash
|
|
1101
|
+
});
|
|
1102
|
+
__privateGet(this, _emitter3).emit("session.initialize.resolved", { args: __privateGet(this, _options), data: response });
|
|
1103
|
+
} catch (error) {
|
|
1104
|
+
__privateGet(this, _emitter3).emit("session.initialize.resolved", { args: __privateGet(this, _options), error });
|
|
1105
|
+
}
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
_emitter3 = new WeakMap();
|
|
1110
|
+
_inboxService2 = new WeakMap();
|
|
1111
|
+
_options = new WeakMap();
|
|
1112
|
+
|
|
1152
1113
|
// src/preferences/preference.ts
|
|
1153
|
-
var
|
|
1114
|
+
var _emitter4, _apiService;
|
|
1154
1115
|
var Preference = class {
|
|
1155
|
-
constructor(preference) {
|
|
1156
|
-
__privateAdd(this,
|
|
1116
|
+
constructor(preference, { emitterInstance, inboxServiceInstance }) {
|
|
1117
|
+
__privateAdd(this, _emitter4);
|
|
1157
1118
|
__privateAdd(this, _apiService);
|
|
1158
|
-
__privateSet(this,
|
|
1159
|
-
__privateSet(this, _apiService,
|
|
1119
|
+
__privateSet(this, _emitter4, emitterInstance);
|
|
1120
|
+
__privateSet(this, _apiService, inboxServiceInstance);
|
|
1160
1121
|
this.level = preference.level;
|
|
1161
1122
|
this.enabled = preference.enabled;
|
|
1162
1123
|
this.channels = preference.channels;
|
|
@@ -1165,7 +1126,7 @@ var Preference = class {
|
|
|
1165
1126
|
update({ channelPreferences }) {
|
|
1166
1127
|
var _a;
|
|
1167
1128
|
return updatePreference({
|
|
1168
|
-
emitter: __privateGet(this,
|
|
1129
|
+
emitter: __privateGet(this, _emitter4),
|
|
1169
1130
|
apiService: __privateGet(this, _apiService),
|
|
1170
1131
|
args: {
|
|
1171
1132
|
workflowId: (_a = this.workflow) == null ? void 0 : _a.id,
|
|
@@ -1180,7 +1141,7 @@ var Preference = class {
|
|
|
1180
1141
|
});
|
|
1181
1142
|
}
|
|
1182
1143
|
};
|
|
1183
|
-
|
|
1144
|
+
_emitter4 = new WeakMap();
|
|
1184
1145
|
_apiService = new WeakMap();
|
|
1185
1146
|
|
|
1186
1147
|
// src/preferences/helpers.ts
|
|
@@ -1193,9 +1154,15 @@ var updatePreference = (_0) => __async(void 0, [_0], function* ({
|
|
|
1193
1154
|
try {
|
|
1194
1155
|
emitter.emit("preference.update.pending", {
|
|
1195
1156
|
args,
|
|
1196
|
-
data: args.preference ? new Preference(
|
|
1197
|
-
|
|
1198
|
-
|
|
1157
|
+
data: args.preference ? new Preference(
|
|
1158
|
+
__spreadProps(__spreadValues({}, args.preference), {
|
|
1159
|
+
channels: __spreadValues(__spreadValues({}, args.preference.channels), channelPreferences)
|
|
1160
|
+
}),
|
|
1161
|
+
{
|
|
1162
|
+
emitterInstance: emitter,
|
|
1163
|
+
inboxServiceInstance: apiService
|
|
1164
|
+
}
|
|
1165
|
+
) : void 0
|
|
1199
1166
|
});
|
|
1200
1167
|
let response;
|
|
1201
1168
|
if (workflowId) {
|
|
@@ -1203,7 +1170,10 @@ var updatePreference = (_0) => __async(void 0, [_0], function* ({
|
|
|
1203
1170
|
} else {
|
|
1204
1171
|
response = yield apiService.updateGlobalPreferences(channelPreferences);
|
|
1205
1172
|
}
|
|
1206
|
-
const preference = new Preference(response
|
|
1173
|
+
const preference = new Preference(response, {
|
|
1174
|
+
emitterInstance: emitter,
|
|
1175
|
+
inboxServiceInstance: apiService
|
|
1176
|
+
});
|
|
1207
1177
|
emitter.emit("preference.update.resolved", { args, data: preference });
|
|
1208
1178
|
return { data: preference };
|
|
1209
1179
|
} catch (error) {
|
|
@@ -1215,10 +1185,10 @@ var updatePreference = (_0) => __async(void 0, [_0], function* ({
|
|
|
1215
1185
|
// src/cache/preferences-cache.ts
|
|
1216
1186
|
var updateEvents2 = ["preference.update.pending", "preference.update.resolved"];
|
|
1217
1187
|
var DEFAULT_KEY = "default";
|
|
1218
|
-
var
|
|
1188
|
+
var _emitter5, _cache3;
|
|
1219
1189
|
var PreferencesCache = class {
|
|
1220
|
-
constructor() {
|
|
1221
|
-
__privateAdd(this,
|
|
1190
|
+
constructor({ emitterInstance }) {
|
|
1191
|
+
__privateAdd(this, _emitter5);
|
|
1222
1192
|
__privateAdd(this, _cache3);
|
|
1223
1193
|
this.updatePreference = (key, data) => {
|
|
1224
1194
|
const preferences = __privateGet(this, _cache3).get(key);
|
|
@@ -1249,14 +1219,14 @@ var PreferencesCache = class {
|
|
|
1249
1219
|
if (!hasUpdatedPreference || !updatedPreference) {
|
|
1250
1220
|
return;
|
|
1251
1221
|
}
|
|
1252
|
-
__privateGet(this,
|
|
1222
|
+
__privateGet(this, _emitter5).emit("preferences.list.updated", {
|
|
1253
1223
|
data: updatedPreference
|
|
1254
1224
|
});
|
|
1255
1225
|
});
|
|
1256
1226
|
};
|
|
1257
|
-
__privateSet(this,
|
|
1227
|
+
__privateSet(this, _emitter5, emitterInstance);
|
|
1258
1228
|
updateEvents2.forEach((event) => {
|
|
1259
|
-
__privateGet(this,
|
|
1229
|
+
__privateGet(this, _emitter5).on(event, this.handlePreferenceEvent);
|
|
1260
1230
|
});
|
|
1261
1231
|
__privateSet(this, _cache3, new InMemoryCache());
|
|
1262
1232
|
}
|
|
@@ -1270,16 +1240,25 @@ var PreferencesCache = class {
|
|
|
1270
1240
|
__privateGet(this, _cache3).clear();
|
|
1271
1241
|
}
|
|
1272
1242
|
};
|
|
1273
|
-
|
|
1243
|
+
_emitter5 = new WeakMap();
|
|
1274
1244
|
_cache3 = new WeakMap();
|
|
1275
1245
|
|
|
1276
1246
|
// src/preferences/preferences.ts
|
|
1277
1247
|
var _useCache2;
|
|
1278
1248
|
var Preferences = class extends BaseModule {
|
|
1279
|
-
constructor({
|
|
1280
|
-
|
|
1249
|
+
constructor({
|
|
1250
|
+
useCache,
|
|
1251
|
+
inboxServiceInstance,
|
|
1252
|
+
eventEmitterInstance
|
|
1253
|
+
}) {
|
|
1254
|
+
super({
|
|
1255
|
+
eventEmitterInstance,
|
|
1256
|
+
inboxServiceInstance
|
|
1257
|
+
});
|
|
1281
1258
|
__privateAdd(this, _useCache2);
|
|
1282
|
-
this.cache = new PreferencesCache(
|
|
1259
|
+
this.cache = new PreferencesCache({
|
|
1260
|
+
emitterInstance: this._emitter
|
|
1261
|
+
});
|
|
1283
1262
|
__privateSet(this, _useCache2, useCache);
|
|
1284
1263
|
}
|
|
1285
1264
|
list() {
|
|
@@ -1290,7 +1269,12 @@ var Preferences = class extends BaseModule {
|
|
|
1290
1269
|
this._emitter.emit("preferences.list.pending", { args: void 0, data });
|
|
1291
1270
|
if (!data) {
|
|
1292
1271
|
const response = yield this._inboxService.fetchPreferences();
|
|
1293
|
-
data = response.map(
|
|
1272
|
+
data = response.map(
|
|
1273
|
+
(el) => new Preference(el, {
|
|
1274
|
+
emitterInstance: this._emitter,
|
|
1275
|
+
inboxServiceInstance: this._inboxService
|
|
1276
|
+
})
|
|
1277
|
+
);
|
|
1294
1278
|
if (__privateGet(this, _useCache2)) {
|
|
1295
1279
|
this.cache.set(data);
|
|
1296
1280
|
}
|
|
@@ -1315,41 +1299,6 @@ var Preferences = class extends BaseModule {
|
|
|
1315
1299
|
}
|
|
1316
1300
|
};
|
|
1317
1301
|
_useCache2 = new WeakMap();
|
|
1318
|
-
|
|
1319
|
-
// src/session/session.ts
|
|
1320
|
-
var _emitter5, _inboxService2, _options;
|
|
1321
|
-
var Session = class {
|
|
1322
|
-
constructor(options) {
|
|
1323
|
-
__privateAdd(this, _emitter5);
|
|
1324
|
-
__privateAdd(this, _inboxService2);
|
|
1325
|
-
__privateAdd(this, _options);
|
|
1326
|
-
__privateSet(this, _emitter5, NovuEventEmitter.getInstance());
|
|
1327
|
-
__privateSet(this, _inboxService2, InboxServiceSingleton.getInstance());
|
|
1328
|
-
__privateSet(this, _options, options);
|
|
1329
|
-
}
|
|
1330
|
-
initialize() {
|
|
1331
|
-
return __async(this, null, function* () {
|
|
1332
|
-
try {
|
|
1333
|
-
const { applicationIdentifier, subscriberId, subscriberHash } = __privateGet(this, _options);
|
|
1334
|
-
__privateGet(this, _emitter5).emit("session.initialize.pending", { args: __privateGet(this, _options) });
|
|
1335
|
-
const response = yield __privateGet(this, _inboxService2).initializeSession({
|
|
1336
|
-
applicationIdentifier,
|
|
1337
|
-
subscriberId,
|
|
1338
|
-
subscriberHash
|
|
1339
|
-
});
|
|
1340
|
-
__privateGet(this, _emitter5).emit("session.initialize.resolved", { args: __privateGet(this, _options), data: response });
|
|
1341
|
-
} catch (error) {
|
|
1342
|
-
__privateGet(this, _emitter5).emit("session.initialize.resolved", { args: __privateGet(this, _options), error });
|
|
1343
|
-
}
|
|
1344
|
-
});
|
|
1345
|
-
}
|
|
1346
|
-
};
|
|
1347
|
-
_emitter5 = new WeakMap();
|
|
1348
|
-
_inboxService2 = new WeakMap();
|
|
1349
|
-
_options = new WeakMap();
|
|
1350
|
-
|
|
1351
|
-
// src/utils/config.ts
|
|
1352
|
-
var PRODUCTION_BACKEND_URL = "https://api.novu.co";
|
|
1353
1302
|
var PRODUCTION_SOCKET_URL = "https://ws.novu.co";
|
|
1354
1303
|
var NOTIFICATION_RECEIVED = "notifications.notification_received";
|
|
1355
1304
|
var UNSEEN_COUNT_CHANGED = "notifications.unseen_count_changed";
|
|
@@ -1420,8 +1369,15 @@ var mapToNotification = ({
|
|
|
1420
1369
|
};
|
|
1421
1370
|
var _token, _emitter6, _socketIo, _socketUrl, _notificationReceived, _unseenCountChanged, _unreadCountChanged, _Socket_instances, initializeSocket_fn;
|
|
1422
1371
|
var Socket = class extends BaseModule {
|
|
1423
|
-
constructor({
|
|
1424
|
-
|
|
1372
|
+
constructor({
|
|
1373
|
+
socketUrl,
|
|
1374
|
+
inboxServiceInstance,
|
|
1375
|
+
eventEmitterInstance
|
|
1376
|
+
}) {
|
|
1377
|
+
super({
|
|
1378
|
+
eventEmitterInstance,
|
|
1379
|
+
inboxServiceInstance
|
|
1380
|
+
});
|
|
1425
1381
|
__privateAdd(this, _Socket_instances);
|
|
1426
1382
|
__privateAdd(this, _token);
|
|
1427
1383
|
__privateAdd(this, _emitter6);
|
|
@@ -1429,7 +1385,7 @@ var Socket = class extends BaseModule {
|
|
|
1429
1385
|
__privateAdd(this, _socketUrl);
|
|
1430
1386
|
__privateAdd(this, _notificationReceived, ({ message }) => {
|
|
1431
1387
|
__privateGet(this, _emitter6).emit(NOTIFICATION_RECEIVED, {
|
|
1432
|
-
result: new Notification(mapToNotification(message))
|
|
1388
|
+
result: new Notification(mapToNotification(message), __privateGet(this, _emitter6), this._inboxService)
|
|
1433
1389
|
});
|
|
1434
1390
|
});
|
|
1435
1391
|
__privateAdd(this, _unseenCountChanged, ({ unseenCount }) => {
|
|
@@ -1442,7 +1398,7 @@ var Socket = class extends BaseModule {
|
|
|
1442
1398
|
result: unreadCount
|
|
1443
1399
|
});
|
|
1444
1400
|
});
|
|
1445
|
-
__privateSet(this, _emitter6,
|
|
1401
|
+
__privateSet(this, _emitter6, eventEmitterInstance);
|
|
1446
1402
|
__privateSet(this, _socketUrl, socketUrl != null ? socketUrl : PRODUCTION_SOCKET_URL);
|
|
1447
1403
|
}
|
|
1448
1404
|
onSessionSuccess({ token }) {
|
|
@@ -1501,35 +1457,169 @@ initializeSocket_fn = function() {
|
|
|
1501
1457
|
});
|
|
1502
1458
|
};
|
|
1503
1459
|
|
|
1460
|
+
// src/utils/config.ts
|
|
1461
|
+
var PRODUCTION_BACKEND_URL = "https://api.novu.co";
|
|
1462
|
+
var NOVU_API_VERSION = "2024-06-26";
|
|
1463
|
+
var INBOX_ROUTE = "/inbox";
|
|
1464
|
+
var INBOX_NOTIFICATIONS_ROUTE = `${INBOX_ROUTE}/notifications`;
|
|
1465
|
+
var _httpClient;
|
|
1466
|
+
var InboxService = class {
|
|
1467
|
+
constructor(options = {}) {
|
|
1468
|
+
this.isSessionInitialized = false;
|
|
1469
|
+
__privateAdd(this, _httpClient);
|
|
1470
|
+
__privateSet(this, _httpClient, new client.HttpClient(options));
|
|
1471
|
+
__privateGet(this, _httpClient).updateHeaders({
|
|
1472
|
+
"Novu-API-Version": NOVU_API_VERSION
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
initializeSession(_0) {
|
|
1476
|
+
return __async(this, arguments, function* ({
|
|
1477
|
+
applicationIdentifier,
|
|
1478
|
+
subscriberId,
|
|
1479
|
+
subscriberHash
|
|
1480
|
+
}) {
|
|
1481
|
+
const response = yield __privateGet(this, _httpClient).post(`${INBOX_ROUTE}/session`, {
|
|
1482
|
+
applicationIdentifier,
|
|
1483
|
+
subscriberId,
|
|
1484
|
+
subscriberHash
|
|
1485
|
+
});
|
|
1486
|
+
__privateGet(this, _httpClient).setAuthorizationToken(response.token);
|
|
1487
|
+
this.isSessionInitialized = true;
|
|
1488
|
+
return response;
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
fetchNotifications({
|
|
1492
|
+
after,
|
|
1493
|
+
archived,
|
|
1494
|
+
limit = 10,
|
|
1495
|
+
offset,
|
|
1496
|
+
read: read2,
|
|
1497
|
+
tags
|
|
1498
|
+
}) {
|
|
1499
|
+
const queryParams = new URLSearchParams(`limit=${limit}`);
|
|
1500
|
+
if (after) {
|
|
1501
|
+
queryParams.append("after", after);
|
|
1502
|
+
}
|
|
1503
|
+
if (offset) {
|
|
1504
|
+
queryParams.append("offset", `${offset}`);
|
|
1505
|
+
}
|
|
1506
|
+
if (tags) {
|
|
1507
|
+
tags.forEach((tag) => queryParams.append("tags[]", tag));
|
|
1508
|
+
}
|
|
1509
|
+
if (read2 !== void 0) {
|
|
1510
|
+
queryParams.append("read", `${read2}`);
|
|
1511
|
+
}
|
|
1512
|
+
if (archived !== void 0) {
|
|
1513
|
+
queryParams.append("archived", `${archived}`);
|
|
1514
|
+
}
|
|
1515
|
+
return __privateGet(this, _httpClient).getFullResponse(`${INBOX_NOTIFICATIONS_ROUTE}?${queryParams.toString()}`);
|
|
1516
|
+
}
|
|
1517
|
+
count({ filters }) {
|
|
1518
|
+
return __privateGet(this, _httpClient).getFullResponse(`${INBOX_NOTIFICATIONS_ROUTE}/count?filters=${JSON.stringify(filters)}`);
|
|
1519
|
+
}
|
|
1520
|
+
read(notificationId) {
|
|
1521
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/read`);
|
|
1522
|
+
}
|
|
1523
|
+
unread(notificationId) {
|
|
1524
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/unread`);
|
|
1525
|
+
}
|
|
1526
|
+
archive(notificationId) {
|
|
1527
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/archive`);
|
|
1528
|
+
}
|
|
1529
|
+
unarchive(notificationId) {
|
|
1530
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/unarchive`);
|
|
1531
|
+
}
|
|
1532
|
+
readAll({ tags }) {
|
|
1533
|
+
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read`, { tags });
|
|
1534
|
+
}
|
|
1535
|
+
archiveAll({ tags }) {
|
|
1536
|
+
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/archive`, { tags });
|
|
1537
|
+
}
|
|
1538
|
+
archiveAllRead({ tags }) {
|
|
1539
|
+
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read-archive`, { tags });
|
|
1540
|
+
}
|
|
1541
|
+
completeAction({
|
|
1542
|
+
actionType,
|
|
1543
|
+
notificationId
|
|
1544
|
+
}) {
|
|
1545
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/complete`, {
|
|
1546
|
+
actionType
|
|
1547
|
+
});
|
|
1548
|
+
}
|
|
1549
|
+
revertAction({
|
|
1550
|
+
actionType,
|
|
1551
|
+
notificationId
|
|
1552
|
+
}) {
|
|
1553
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/revert`, {
|
|
1554
|
+
actionType
|
|
1555
|
+
});
|
|
1556
|
+
}
|
|
1557
|
+
fetchPreferences() {
|
|
1558
|
+
return __privateGet(this, _httpClient).get(`${INBOX_ROUTE}/preferences`);
|
|
1559
|
+
}
|
|
1560
|
+
updateGlobalPreferences(channelPreferences) {
|
|
1561
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences`, channelPreferences);
|
|
1562
|
+
}
|
|
1563
|
+
updateWorkflowPreferences({
|
|
1564
|
+
workflowId,
|
|
1565
|
+
channelPreferences
|
|
1566
|
+
}) {
|
|
1567
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/${workflowId}`, channelPreferences);
|
|
1568
|
+
}
|
|
1569
|
+
};
|
|
1570
|
+
_httpClient = new WeakMap();
|
|
1571
|
+
|
|
1504
1572
|
// src/novu.ts
|
|
1505
|
-
var _session;
|
|
1573
|
+
var _emitter7, _session, _socket, _inboxService3;
|
|
1506
1574
|
var Novu = class {
|
|
1507
1575
|
constructor(options) {
|
|
1576
|
+
__privateAdd(this, _emitter7);
|
|
1508
1577
|
__privateAdd(this, _session);
|
|
1578
|
+
__privateAdd(this, _socket);
|
|
1579
|
+
__privateAdd(this, _inboxService3);
|
|
1509
1580
|
var _a, _b, _c;
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
__privateSet(this, _session, new Session(
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1581
|
+
__privateSet(this, _inboxService3, new InboxService({ backendUrl: (_a = options.backendUrl) != null ? _a : PRODUCTION_BACKEND_URL }));
|
|
1582
|
+
__privateSet(this, _emitter7, new NovuEventEmitter());
|
|
1583
|
+
__privateSet(this, _session, new Session(
|
|
1584
|
+
{
|
|
1585
|
+
applicationIdentifier: options.applicationIdentifier,
|
|
1586
|
+
subscriberId: options.subscriberId,
|
|
1587
|
+
subscriberHash: options.subscriberHash
|
|
1588
|
+
},
|
|
1589
|
+
__privateGet(this, _inboxService3),
|
|
1590
|
+
__privateGet(this, _emitter7)
|
|
1591
|
+
));
|
|
1517
1592
|
__privateGet(this, _session).initialize();
|
|
1518
|
-
this.notifications = new Notifications({
|
|
1519
|
-
|
|
1520
|
-
|
|
1593
|
+
this.notifications = new Notifications({
|
|
1594
|
+
useCache: (_b = options.useCache) != null ? _b : true,
|
|
1595
|
+
inboxServiceInstance: __privateGet(this, _inboxService3),
|
|
1596
|
+
eventEmitterInstance: __privateGet(this, _emitter7)
|
|
1597
|
+
});
|
|
1598
|
+
this.preferences = new Preferences({
|
|
1599
|
+
useCache: (_c = options.useCache) != null ? _c : true,
|
|
1600
|
+
inboxServiceInstance: __privateGet(this, _inboxService3),
|
|
1601
|
+
eventEmitterInstance: __privateGet(this, _emitter7)
|
|
1602
|
+
});
|
|
1603
|
+
__privateSet(this, _socket, new Socket({
|
|
1604
|
+
socketUrl: options.socketUrl,
|
|
1605
|
+
eventEmitterInstance: __privateGet(this, _emitter7),
|
|
1606
|
+
inboxServiceInstance: __privateGet(this, _inboxService3)
|
|
1607
|
+
}));
|
|
1521
1608
|
this.on = (eventName, listener) => {
|
|
1522
|
-
if (
|
|
1523
|
-
|
|
1609
|
+
if (__privateGet(this, _socket).isSocketEvent(eventName)) {
|
|
1610
|
+
__privateGet(this, _socket).initialize();
|
|
1524
1611
|
}
|
|
1525
|
-
|
|
1612
|
+
__privateGet(this, _emitter7).on(eventName, listener);
|
|
1526
1613
|
};
|
|
1527
1614
|
this.off = (eventName, listener) => {
|
|
1528
|
-
|
|
1615
|
+
__privateGet(this, _emitter7).off(eventName, listener);
|
|
1529
1616
|
};
|
|
1530
1617
|
}
|
|
1531
1618
|
};
|
|
1619
|
+
_emitter7 = new WeakMap();
|
|
1532
1620
|
_session = new WeakMap();
|
|
1621
|
+
_socket = new WeakMap();
|
|
1622
|
+
_inboxService3 = new WeakMap();
|
|
1533
1623
|
|
|
1534
1624
|
exports.ActionTypeEnum = ActionTypeEnum;
|
|
1535
1625
|
exports.ChannelType = ChannelType;
|