@novu/js 3.11.0 → 3.12.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/cjs/{chunk-VWSQDNZX.js → chunk-OZV3TKWX.js} +6 -0
  2. package/dist/cjs/{chunk-QQNKEWGC.js → chunk-SZEUW4CB.js} +1070 -309
  3. package/dist/cjs/index.d.ts +5 -4
  4. package/dist/cjs/index.js +26 -14
  5. package/dist/cjs/internal/index.d.ts +8 -2
  6. package/dist/cjs/internal/index.js +8 -4
  7. package/dist/{esm/novu-DY-mm8Og.d.mts → cjs/novu-BVtCFUxa.d.ts} +398 -203
  8. package/dist/cjs/themes/index.d.ts +11 -5
  9. package/dist/cjs/themes/index.js +17 -1
  10. package/dist/{esm/types-BM_9Xx5Z.d.mts → cjs/types-D-9ozWeQ.d.ts} +20 -1
  11. package/dist/cjs/types-Rjzg7eo3.d.ts +836 -0
  12. package/dist/cjs/ui/index.d.ts +74 -7
  13. package/dist/cjs/ui/index.js +1785 -260
  14. package/dist/esm/{chunk-UM35OVAD.mjs → chunk-IA6ISHOP.mjs} +1068 -310
  15. package/dist/esm/{chunk-RZWQYM3H.mjs → chunk-RO3GDYAG.mjs} +6 -1
  16. package/dist/esm/index.d.mts +5 -4
  17. package/dist/esm/index.mjs +2 -2
  18. package/dist/esm/internal/index.d.mts +8 -2
  19. package/dist/esm/internal/index.mjs +1 -1
  20. package/dist/{cjs/novu-ThMWeiRt.d.ts → esm/novu-YP3PwsQR.d.mts} +398 -203
  21. package/dist/esm/themes/index.d.mts +11 -5
  22. package/dist/esm/themes/index.mjs +16 -2
  23. package/dist/{cjs/types-BM_9Xx5Z.d.ts → esm/types-D-9ozWeQ.d.mts} +20 -1
  24. package/dist/esm/types-DmMJ1GiR.d.mts +836 -0
  25. package/dist/esm/ui/index.d.mts +74 -7
  26. package/dist/esm/ui/index.mjs +1782 -256
  27. package/dist/index.css +1 -1
  28. package/dist/novu.min.js +12 -12
  29. package/dist/novu.min.js.gz +0 -0
  30. package/package.json +18 -17
  31. package/dist/cjs/types-BjANCN3c.d.ts +0 -537
  32. package/dist/esm/types-C5eX1GmB.d.mts +0 -537
@@ -1,5 +1,5 @@
1
- import { buildSubscriber, buildContextKey } from './chunk-RZWQYM3H.mjs';
2
- import { __privateAdd, __privateSet, __privateGet, __async, __objRest, __spreadValues, __spreadProps, __privateMethod } from './chunk-STZMOEWR.mjs';
1
+ import { buildSubscriber, buildContextKey, buildSubscriptionIdentifier } from './chunk-RO3GDYAG.mjs';
2
+ import { __privateAdd, __privateSet, __spreadValues, __privateGet, __async, __spreadProps, __objRest, __privateMethod } from './chunk-STZMOEWR.mjs';
3
3
  import mitt from 'mitt';
4
4
  import 'event-target-polyfill';
5
5
  import { WebSocket } from 'partysocket';
@@ -48,6 +48,14 @@ var WorkflowCriticalityEnum = /* @__PURE__ */ ((WorkflowCriticalityEnum2) => {
48
48
  return WorkflowCriticalityEnum2;
49
49
  })(WorkflowCriticalityEnum || {});
50
50
 
51
+ // src/utils/errors.ts
52
+ var NovuError = class extends Error {
53
+ constructor(message, originalError) {
54
+ super(message);
55
+ this.originalError = originalError;
56
+ }
57
+ };
58
+
51
59
  // src/utils/arrays.ts
52
60
  var arrayValuesEqual = (arr1, arr2) => {
53
61
  if (arr1 === arr2) {
@@ -124,24 +132,788 @@ function checkBasicFilters(notification, filter) {
124
132
  if (filter.read !== void 0 && notification.isRead !== filter.read) {
125
133
  return false;
126
134
  }
127
- if (filter.seen !== void 0 && notification.isSeen !== filter.seen) {
128
- return false;
135
+ if (filter.seen !== void 0 && notification.isSeen !== filter.seen) {
136
+ return false;
137
+ }
138
+ if (filter.archived !== void 0 && notification.isArchived !== filter.archived) {
139
+ return false;
140
+ }
141
+ if (filter.snoozed !== void 0 && notification.isSnoozed !== filter.snoozed) {
142
+ return false;
143
+ }
144
+ return true;
145
+ }
146
+ function checkNotificationMatchesFilter(notification, filter) {
147
+ return checkBasicFilters(notification, filter) && checkNotificationTagFilter(notification.tags, filter.tags) && checkNotificationDataFilter(notification.data, filter.data);
148
+ }
149
+
150
+ // src/subscriptions/subscription.ts
151
+ var _emitter, _inboxService, _cache, _useCache, _isStale;
152
+ var TopicSubscription = class {
153
+ constructor(subscription, emitter, inboxService, cache, useCache) {
154
+ __privateAdd(this, _emitter);
155
+ __privateAdd(this, _inboxService);
156
+ __privateAdd(this, _cache);
157
+ __privateAdd(this, _useCache);
158
+ __privateAdd(this, _isStale, false);
159
+ __privateSet(this, _emitter, emitter);
160
+ __privateSet(this, _inboxService, inboxService);
161
+ __privateSet(this, _cache, cache);
162
+ __privateSet(this, _useCache, useCache);
163
+ this.id = subscription.id;
164
+ this.identifier = subscription.identifier;
165
+ this.topicKey = subscription.topicKey;
166
+ this.preferences = subscription.preferences.map(
167
+ (pref) => new SubscriptionPreference(__spreadValues({}, pref), __privateGet(this, _emitter), __privateGet(this, _inboxService), __privateGet(this, _cache), __privateGet(this, _useCache))
168
+ );
169
+ }
170
+ update(args) {
171
+ return __async(this, null, function* () {
172
+ return updateSubscription({
173
+ emitter: __privateGet(this, _emitter),
174
+ apiService: __privateGet(this, _inboxService),
175
+ cache: __privateGet(this, _cache),
176
+ useCache: __privateGet(this, _useCache),
177
+ args: __spreadProps(__spreadValues({}, args), { subscription: this })
178
+ });
179
+ });
180
+ }
181
+ updatePreference(args) {
182
+ return __async(this, null, function* () {
183
+ if (__privateGet(this, _isStale)) {
184
+ return {
185
+ error: new NovuError("Cannot update a deleted subscription", new Error("Subscription is stale"))
186
+ };
187
+ }
188
+ return updateSubscriptionPreference({
189
+ emitter: __privateGet(this, _emitter),
190
+ apiService: __privateGet(this, _inboxService),
191
+ cache: __privateGet(this, _cache),
192
+ useCache: __privateGet(this, _useCache),
193
+ args: __spreadProps(__spreadValues({}, args), { subscriptionId: this.id })
194
+ });
195
+ });
196
+ }
197
+ bulkUpdatePreferences(args) {
198
+ return __async(this, null, function* () {
199
+ if (__privateGet(this, _isStale)) {
200
+ return {
201
+ error: new NovuError("Cannot bulk update a deleted subscription", new Error("Subscription is stale"))
202
+ };
203
+ }
204
+ return bulkUpdateSubscriptionPreference({
205
+ emitter: __privateGet(this, _emitter),
206
+ apiService: __privateGet(this, _inboxService),
207
+ cache: __privateGet(this, _cache),
208
+ useCache: __privateGet(this, _useCache),
209
+ args: args.map((arg) => __spreadProps(__spreadValues({}, arg), { subscriptionId: this.id }))
210
+ });
211
+ });
212
+ }
213
+ delete() {
214
+ return __async(this, null, function* () {
215
+ if (__privateGet(this, _isStale)) {
216
+ return {
217
+ error: new NovuError("Cannot delete an already deleted subscription", new Error("Subscription is stale"))
218
+ };
219
+ }
220
+ return deleteSubscription({
221
+ emitter: __privateGet(this, _emitter),
222
+ apiService: __privateGet(this, _inboxService),
223
+ args: { subscription: this }
224
+ });
225
+ });
226
+ }
227
+ };
228
+ _emitter = new WeakMap();
229
+ _inboxService = new WeakMap();
230
+ _cache = new WeakMap();
231
+ _useCache = new WeakMap();
232
+ _isStale = new WeakMap();
233
+
234
+ // src/subscriptions/helpers.ts
235
+ var listSubscriptions = (_0) => __async(void 0, [_0], function* ({
236
+ emitter,
237
+ apiService,
238
+ cache,
239
+ options,
240
+ args
241
+ }) {
242
+ try {
243
+ const { useCache, refetch } = options;
244
+ let data = useCache && !refetch ? cache.getAll(args) : void 0;
245
+ emitter.emit("subscriptions.list.pending", { args, data });
246
+ if (!data || refetch) {
247
+ const response = yield apiService.fetchSubscriptions(args.topicKey);
248
+ data = response.map((el) => {
249
+ return new TopicSubscription(__spreadProps(__spreadValues({}, el), { topicKey: args.topicKey }), emitter, apiService, cache, useCache);
250
+ });
251
+ if (useCache) {
252
+ cache.set(args, data);
253
+ data = cache.getAll(args);
254
+ }
255
+ }
256
+ emitter.emit("subscriptions.list.resolved", { args, data });
257
+ return { data };
258
+ } catch (error) {
259
+ emitter.emit("subscriptions.list.resolved", { args, error });
260
+ return { error: new NovuError("Failed to fetch subscriptions", error) };
261
+ }
262
+ });
263
+ var getSubscription = (_0) => __async(void 0, [_0], function* ({
264
+ emitter,
265
+ apiService,
266
+ cache,
267
+ options,
268
+ args
269
+ }) {
270
+ try {
271
+ const { useCache, refetch } = options;
272
+ let data = useCache && !refetch ? cache.get(args) : void 0;
273
+ emitter.emit("subscription.get.pending", { args, data });
274
+ if (!data || refetch) {
275
+ const response = yield apiService.getSubscription({
276
+ topicKey: args.topicKey,
277
+ identifier: args.identifier
278
+ });
279
+ if (!response) {
280
+ emitter.emit("subscription.get.resolved", { args, data: null });
281
+ return { data: null };
282
+ }
283
+ data = new TopicSubscription(__spreadProps(__spreadValues({}, response), { topicKey: args.topicKey }), emitter, apiService, cache, useCache);
284
+ if (useCache) {
285
+ cache.setOne(args, data);
286
+ data = cache.get(args);
287
+ }
288
+ }
289
+ emitter.emit("subscription.get.resolved", { args, data });
290
+ return { data };
291
+ } catch (error) {
292
+ emitter.emit("subscription.get.resolved", { args, error });
293
+ return { error: new NovuError("Failed to fetch subscription", error) };
294
+ }
295
+ });
296
+ var createSubscription = (_0) => __async(void 0, [_0], function* ({
297
+ emitter,
298
+ apiService,
299
+ cache,
300
+ useCache,
301
+ args
302
+ }) {
303
+ var _a;
304
+ try {
305
+ emitter.emit("subscription.create.pending", { args });
306
+ const response = yield apiService.createSubscription({
307
+ identifier: (_a = args.identifier) != null ? _a : "",
308
+ name: args.name,
309
+ topicKey: args.topicKey,
310
+ topicName: args.topicName,
311
+ preferences: args.preferences
312
+ });
313
+ const subscription = new TopicSubscription(
314
+ __spreadProps(__spreadValues({}, response), { topicKey: args.topicKey }),
315
+ emitter,
316
+ apiService,
317
+ cache,
318
+ useCache
319
+ );
320
+ emitter.emit("subscription.create.resolved", { args, data: subscription });
321
+ return { data: subscription };
322
+ } catch (error) {
323
+ emitter.emit("subscription.create.resolved", { args, error });
324
+ return { error: new NovuError("Failed to create subscription", error) };
325
+ }
326
+ });
327
+ var updateSubscription = (_0) => __async(void 0, [_0], function* ({
328
+ emitter,
329
+ apiService,
330
+ cache,
331
+ useCache,
332
+ args
333
+ }) {
334
+ const subscriptionId = "subscriptionId" in args ? args.subscriptionId : args.subscription.id;
335
+ const topicKey = "topicKey" in args ? args.topicKey : args.subscription.topicKey;
336
+ try {
337
+ emitter.emit("subscription.update.pending", {
338
+ args
339
+ });
340
+ const response = yield apiService.updateSubscription({
341
+ topicKey,
342
+ subscriptionId,
343
+ name: args.name,
344
+ preferences: args.preferences
345
+ });
346
+ const updatedSubscription = new TopicSubscription(__spreadProps(__spreadValues({}, response), { topicKey }), emitter, apiService, cache, useCache);
347
+ emitter.emit("subscription.update.resolved", { args, data: updatedSubscription });
348
+ return { data: updatedSubscription };
349
+ } catch (error) {
350
+ emitter.emit("subscription.update.resolved", { args, error });
351
+ return { error: new NovuError("Failed to update subscription", error) };
352
+ }
353
+ });
354
+ var updateSubscriptionPreference = (_0) => __async(void 0, [_0], function* ({
355
+ emitter,
356
+ apiService,
357
+ cache,
358
+ useCache,
359
+ args
360
+ }) {
361
+ var _a, _b;
362
+ const workflowId = "workflowId" in args ? args.workflowId : (_b = (_a = args.preference) == null ? void 0 : _a.workflow) == null ? void 0 : _b.id;
363
+ try {
364
+ emitter.emit("subscription.preference.update.pending", {
365
+ args,
366
+ data: "preference" in args ? new SubscriptionPreference(
367
+ __spreadValues(__spreadValues({}, args.preference), typeof args.value === "boolean" ? { enabled: args.value } : { condition: args.value }),
368
+ emitter,
369
+ apiService,
370
+ cache,
371
+ useCache
372
+ ) : void 0
373
+ });
374
+ const response = yield apiService.updateSubscriptionPreference(__spreadValues({
375
+ subscriptionId: args.subscriptionId,
376
+ workflowId
377
+ }, typeof args.value === "boolean" ? { enabled: args.value } : { condition: args.value }));
378
+ const updatedSubscription = new SubscriptionPreference(__spreadValues({}, response), emitter, apiService, cache, useCache);
379
+ emitter.emit("subscription.preference.update.resolved", { args, data: updatedSubscription });
380
+ return { data: updatedSubscription };
381
+ } catch (error) {
382
+ emitter.emit("subscription.preference.update.resolved", { args, error });
383
+ return { error: new NovuError("Failed to update subscription", error) };
384
+ }
385
+ });
386
+ var bulkUpdateSubscriptionPreference = (_0) => __async(void 0, [_0], function* ({
387
+ emitter,
388
+ apiService,
389
+ cache,
390
+ useCache,
391
+ args
392
+ }) {
393
+ try {
394
+ const optimisticallyUpdatedPreferences = args.map(
395
+ (arg) => "preference" in arg ? new SubscriptionPreference(
396
+ __spreadValues(__spreadValues({}, arg.preference), typeof arg.value === "boolean" ? { enabled: arg.value } : { condition: arg.value }),
397
+ emitter,
398
+ apiService,
399
+ cache,
400
+ useCache
401
+ ) : void 0
402
+ ).filter((el) => el !== void 0);
403
+ emitter.emit("subscription.preferences.bulk_update.pending", {
404
+ args,
405
+ data: optimisticallyUpdatedPreferences
406
+ });
407
+ const preferencesToUpdate = args.map((arg) => {
408
+ var _a, _b, _c, _d, _e, _f;
409
+ return __spreadValues({
410
+ subscriptionIdOrIdentifier: arg.subscriptionId,
411
+ workflowId: "workflowId" in arg ? arg.workflowId : (_f = (_e = (_b = (_a = arg.preference) == null ? void 0 : _a.workflow) == null ? void 0 : _b.id) != null ? _e : (_d = (_c = arg.preference) == null ? void 0 : _c.workflow) == null ? void 0 : _d.identifier) != null ? _f : ""
412
+ }, typeof arg.value === "boolean" ? { enabled: arg.value } : { condition: arg.value });
413
+ });
414
+ const response = yield apiService.bulkUpdateSubscriptionPreferences(preferencesToUpdate);
415
+ const preferences = response.map((el) => new SubscriptionPreference(el, emitter, apiService, cache, useCache));
416
+ emitter.emit("subscription.preferences.bulk_update.resolved", { args, data: preferences });
417
+ return { data: preferences };
418
+ } catch (error) {
419
+ emitter.emit("subscription.preferences.bulk_update.resolved", { args, error });
420
+ return { error: new NovuError("Failed to bulk update subscription preferences", error) };
421
+ }
422
+ });
423
+ var deleteSubscription = (_0) => __async(void 0, [_0], function* ({
424
+ emitter,
425
+ apiService,
426
+ args
427
+ }) {
428
+ const subscriptionId = "subscriptionId" in args ? args.subscriptionId : args.subscription.id;
429
+ const topicKey = "topicKey" in args ? args.topicKey : args.subscription.topicKey;
430
+ try {
431
+ emitter.emit("subscription.delete.pending", { args });
432
+ yield apiService.deleteSubscription({ topicKey, subscriptionId });
433
+ emitter.emit("subscription.delete.resolved", { args });
434
+ return { data: void 0 };
435
+ } catch (error) {
436
+ emitter.emit("subscription.delete.resolved", { args, error });
437
+ return { error: new NovuError("Failed to delete subscription", error) };
438
+ }
439
+ });
440
+
441
+ // src/subscriptions/subscription-preference.ts
442
+ var _emitter2, _inboxService2, _cache2, _useCache2;
443
+ var SubscriptionPreference = class {
444
+ constructor(preference, emitter, inboxService, cache, useCache) {
445
+ __privateAdd(this, _emitter2);
446
+ __privateAdd(this, _inboxService2);
447
+ __privateAdd(this, _cache2);
448
+ __privateAdd(this, _useCache2);
449
+ var _a;
450
+ __privateSet(this, _emitter2, emitter);
451
+ __privateSet(this, _inboxService2, inboxService);
452
+ __privateSet(this, _cache2, cache);
453
+ __privateSet(this, _useCache2, useCache);
454
+ this.enabled = preference.enabled;
455
+ this.condition = (_a = preference.condition) != null ? _a : void 0;
456
+ this.workflow = preference.workflow;
457
+ this.subscriptionId = preference.subscriptionId;
458
+ }
459
+ update(args) {
460
+ return __async(this, null, function* () {
461
+ var _a;
462
+ return updateSubscriptionPreference({
463
+ emitter: __privateGet(this, _emitter2),
464
+ apiService: __privateGet(this, _inboxService2),
465
+ cache: __privateGet(this, _cache2),
466
+ useCache: __privateGet(this, _useCache2),
467
+ args: {
468
+ subscriptionId: this.subscriptionId,
469
+ workflowId: (_a = this.workflow) == null ? void 0 : _a.id,
470
+ value: args.value,
471
+ preference: this
472
+ }
473
+ });
474
+ });
475
+ }
476
+ };
477
+ _emitter2 = new WeakMap();
478
+ _inboxService2 = new WeakMap();
479
+ _cache2 = new WeakMap();
480
+ _useCache2 = new WeakMap();
481
+
482
+ // src/base-module.ts
483
+ var _callsQueue, _sessionError;
484
+ var BaseModule = class {
485
+ constructor({
486
+ inboxServiceInstance,
487
+ eventEmitterInstance
488
+ }) {
489
+ __privateAdd(this, _callsQueue, []);
490
+ __privateAdd(this, _sessionError);
491
+ this._emitter = eventEmitterInstance;
492
+ this._inboxService = inboxServiceInstance;
493
+ this._emitter.on("session.initialize.resolved", ({ error, data }) => {
494
+ if (data) {
495
+ this.onSessionSuccess(data);
496
+ __privateGet(this, _callsQueue).forEach((_0) => __async(this, [_0], function* ({ fn, resolve }) {
497
+ resolve(yield fn());
498
+ }));
499
+ __privateSet(this, _callsQueue, []);
500
+ } else if (error) {
501
+ this.onSessionError(error);
502
+ __privateSet(this, _sessionError, error);
503
+ __privateGet(this, _callsQueue).forEach(({ resolve }) => {
504
+ resolve({ error: new NovuError("Failed to initialize session, please contact the support", error) });
505
+ });
506
+ __privateSet(this, _callsQueue, []);
507
+ }
508
+ });
509
+ }
510
+ onSessionSuccess(_) {
511
+ }
512
+ onSessionError(_) {
513
+ }
514
+ callWithSession(fn) {
515
+ return __async(this, null, function* () {
516
+ if (this._inboxService.isSessionInitialized) {
517
+ return fn();
518
+ }
519
+ if (__privateGet(this, _sessionError)) {
520
+ return Promise.resolve({
521
+ error: new NovuError("Failed to initialize session, please contact the support", __privateGet(this, _sessionError))
522
+ });
523
+ }
524
+ return new Promise((resolve, reject) => {
525
+ __privateGet(this, _callsQueue).push({ fn, resolve, reject });
526
+ });
527
+ });
528
+ }
529
+ };
530
+ _callsQueue = new WeakMap();
531
+ _sessionError = new WeakMap();
532
+
533
+ // src/cache/in-memory-cache.ts
534
+ var _cache3;
535
+ var InMemoryCache = class {
536
+ constructor() {
537
+ __privateAdd(this, _cache3);
538
+ __privateSet(this, _cache3, /* @__PURE__ */ new Map());
539
+ }
540
+ get(key) {
541
+ return __privateGet(this, _cache3).get(key);
542
+ }
543
+ getValues() {
544
+ return Array.from(__privateGet(this, _cache3).values());
545
+ }
546
+ entries() {
547
+ return Array.from(__privateGet(this, _cache3).entries());
548
+ }
549
+ keys() {
550
+ return Array.from(__privateGet(this, _cache3).keys());
551
+ }
552
+ set(key, value) {
553
+ __privateGet(this, _cache3).set(key, value);
554
+ }
555
+ remove(key) {
556
+ __privateGet(this, _cache3).delete(key);
557
+ }
558
+ clear() {
559
+ __privateGet(this, _cache3).clear();
560
+ }
561
+ };
562
+ _cache3 = new WeakMap();
563
+
564
+ // src/cache/subscriptions-cache.ts
565
+ var getListCacheKey = (args) => {
566
+ return `list:${args.topicKey}`;
567
+ };
568
+ var getTopicKeyFromListCacheKey = (key) => {
569
+ return key.split(":")[1];
570
+ };
571
+ var getItemCacheKey = (args) => {
572
+ return `item:${args.topicKey}:${args.identifier}`;
573
+ };
574
+ var _emitter3, _cache4, _useCache3, _itemCache, _inboxService3;
575
+ var SubscriptionsCache = class {
576
+ constructor({
577
+ emitterInstance,
578
+ inboxServiceInstance,
579
+ useCache
580
+ }) {
581
+ __privateAdd(this, _emitter3);
582
+ __privateAdd(this, _cache4);
583
+ __privateAdd(this, _useCache3);
584
+ __privateAdd(this, _itemCache);
585
+ __privateAdd(this, _inboxService3);
586
+ this.handleCreate = (subscription) => {
587
+ const listKey = getListCacheKey({ topicKey: subscription.topicKey });
588
+ const subscriptions = __privateGet(this, _cache4).get(listKey);
589
+ if (subscriptions) {
590
+ const updatedSubscriptions = [...subscriptions, subscription];
591
+ __privateGet(this, _cache4).set(listKey, updatedSubscriptions);
592
+ __privateGet(this, _emitter3).emit("subscriptions.list.updated", {
593
+ data: { topicKey: subscription.topicKey, subscriptions: updatedSubscriptions }
594
+ });
595
+ }
596
+ __privateGet(this, _itemCache).set(
597
+ getItemCacheKey({ topicKey: subscription.topicKey, identifier: subscription.identifier }),
598
+ subscription
599
+ );
600
+ };
601
+ this.handleUpdate = (subscription) => {
602
+ const listKey = getListCacheKey({ topicKey: subscription.topicKey });
603
+ const subscriptions = __privateGet(this, _cache4).get(listKey);
604
+ if (subscriptions) {
605
+ const updatedSubscriptions = subscriptions.map((el) => el.id === subscription.id ? subscription : el);
606
+ __privateGet(this, _cache4).set(listKey, updatedSubscriptions);
607
+ __privateGet(this, _emitter3).emit("subscriptions.list.updated", {
608
+ data: { topicKey: subscription.topicKey, subscriptions: updatedSubscriptions }
609
+ });
610
+ }
611
+ __privateGet(this, _itemCache).set(
612
+ getItemCacheKey({ topicKey: subscription.topicKey, identifier: subscription.identifier }),
613
+ subscription
614
+ );
615
+ };
616
+ this.handlePreferenceUpdate = (preference) => {
617
+ this.updateSubscriptionPreferences([preference]);
618
+ };
619
+ this.handleBulkPreferenceUpdate = (preferences) => {
620
+ this.updateSubscriptionPreferences(preferences);
621
+ };
622
+ this.updateSubscriptionPreferences = (updatedPreferences) => {
623
+ var _a;
624
+ const preferencesBySubscription = /* @__PURE__ */ new Map();
625
+ for (const pref of updatedPreferences) {
626
+ const existing = (_a = preferencesBySubscription.get(pref.subscriptionId)) != null ? _a : [];
627
+ existing.push(pref);
628
+ preferencesBySubscription.set(pref.subscriptionId, existing);
629
+ }
630
+ const allListKeys = __privateGet(this, _cache4).keys();
631
+ for (const listKey of allListKeys) {
632
+ const subscriptions = __privateGet(this, _cache4).get(listKey);
633
+ if (!subscriptions) continue;
634
+ let hasUpdates = false;
635
+ const updatedSubscriptions = subscriptions.map((subscription) => {
636
+ const subscriptionPreferences = preferencesBySubscription.get(subscription.id);
637
+ if (subscriptionPreferences) {
638
+ hasUpdates = true;
639
+ return this.createUpdatedSubscription(subscription, subscriptionPreferences);
640
+ }
641
+ return subscription;
642
+ });
643
+ if (hasUpdates) {
644
+ __privateGet(this, _cache4).set(listKey, updatedSubscriptions);
645
+ __privateGet(this, _emitter3).emit("subscriptions.list.updated", {
646
+ data: { topicKey: getTopicKeyFromListCacheKey(listKey), subscriptions: updatedSubscriptions }
647
+ });
648
+ }
649
+ }
650
+ const allItemKeys = __privateGet(this, _itemCache).keys();
651
+ for (const key of allItemKeys) {
652
+ const subscription = __privateGet(this, _itemCache).get(key);
653
+ if (!subscription) continue;
654
+ const subscriptionPreferences = preferencesBySubscription.get(subscription.id);
655
+ if (subscriptionPreferences) {
656
+ const updatedSubscription = this.createUpdatedSubscription(subscription, subscriptionPreferences);
657
+ __privateGet(this, _itemCache).set(key, updatedSubscription);
658
+ __privateGet(this, _emitter3).emit("subscription.update.resolved", {
659
+ args: { subscription },
660
+ data: updatedSubscription
661
+ });
662
+ }
663
+ }
664
+ };
665
+ this.createUpdatedSubscription = (subscription, subscriptionPreferences) => {
666
+ const updatedPreferences = subscription.preferences.map((pref) => {
667
+ const newPreference = subscriptionPreferences.find((el) => el.workflow.id === pref.workflow.id);
668
+ if (newPreference) {
669
+ return newPreference;
670
+ }
671
+ return pref;
672
+ });
673
+ return new TopicSubscription(
674
+ {
675
+ id: subscription.id,
676
+ identifier: subscription.identifier,
677
+ topicKey: subscription.topicKey,
678
+ preferences: updatedPreferences
679
+ },
680
+ __privateGet(this, _emitter3),
681
+ __privateGet(this, _inboxService3),
682
+ this,
683
+ __privateGet(this, _useCache3)
684
+ );
685
+ };
686
+ this.handleDelete = (subscription) => {
687
+ const listKey = getListCacheKey({ topicKey: subscription.topicKey });
688
+ const subscriptions = __privateGet(this, _cache4).get(listKey);
689
+ if (subscriptions) {
690
+ const updatedSubscriptions = subscriptions.filter((el) => el.id !== subscription.id);
691
+ __privateGet(this, _cache4).set(listKey, updatedSubscriptions);
692
+ __privateGet(this, _emitter3).emit("subscriptions.list.updated", {
693
+ data: { topicKey: subscription.topicKey, subscriptions: updatedSubscriptions }
694
+ });
695
+ }
696
+ __privateGet(this, _itemCache).remove(getItemCacheKey({ topicKey: subscription.topicKey, identifier: subscription.identifier }));
697
+ };
698
+ this.handleDeleteById = (subscriptionId) => {
699
+ const allListKeys = __privateGet(this, _cache4).keys();
700
+ for (const listKey of allListKeys) {
701
+ const subscriptions = __privateGet(this, _cache4).get(listKey);
702
+ if (subscriptions) {
703
+ const subscription = subscriptions.find((el) => el.id === subscriptionId || el.identifier === subscriptionId);
704
+ if (subscription) {
705
+ const updatedSubscriptions = subscriptions.filter((el) => el.id !== subscription.id);
706
+ __privateGet(this, _cache4).set(listKey, updatedSubscriptions);
707
+ __privateGet(this, _emitter3).emit("subscriptions.list.updated", {
708
+ data: { topicKey: getTopicKeyFromListCacheKey(listKey), subscriptions: updatedSubscriptions }
709
+ });
710
+ __privateGet(this, _itemCache).remove(
711
+ getItemCacheKey({ topicKey: subscription.topicKey, identifier: subscription.identifier })
712
+ );
713
+ return;
714
+ }
715
+ }
716
+ }
717
+ const allItemKeys = __privateGet(this, _itemCache).keys();
718
+ for (const key of allItemKeys) {
719
+ const subscription = __privateGet(this, _itemCache).get(key);
720
+ if (subscription && (subscription.id === subscriptionId || subscription.identifier === subscriptionId)) {
721
+ __privateGet(this, _itemCache).remove(key);
722
+ return;
723
+ }
724
+ }
725
+ };
726
+ __privateSet(this, _emitter3, emitterInstance);
727
+ __privateSet(this, _cache4, new InMemoryCache());
728
+ __privateSet(this, _itemCache, new InMemoryCache());
729
+ __privateSet(this, _inboxService3, inboxServiceInstance);
730
+ __privateSet(this, _useCache3, useCache);
731
+ __privateGet(this, _emitter3).on("subscription.create.resolved", ({ data }) => {
732
+ if (data) {
733
+ this.handleCreate(data);
734
+ }
735
+ });
736
+ __privateGet(this, _emitter3).on("subscription.update.resolved", ({ data }) => {
737
+ if (data) {
738
+ this.handleUpdate(data);
739
+ }
740
+ });
741
+ __privateGet(this, _emitter3).on("subscription.delete.resolved", ({ args }) => {
742
+ if ("subscription" in args) {
743
+ this.handleDelete(args.subscription);
744
+ } else if ("subscriptionId" in args) {
745
+ this.handleDeleteById(args.subscriptionId);
746
+ }
747
+ });
748
+ __privateGet(this, _emitter3).on("subscription.preference.update.pending", ({ data }) => {
749
+ if (data) {
750
+ this.handlePreferenceUpdate(data);
751
+ }
752
+ });
753
+ __privateGet(this, _emitter3).on("subscription.preference.update.resolved", ({ data }) => {
754
+ if (data) {
755
+ this.handlePreferenceUpdate(data);
756
+ }
757
+ });
758
+ __privateGet(this, _emitter3).on("subscription.preferences.bulk_update.resolved", ({ data }) => {
759
+ if (data && data.length > 0) {
760
+ this.handleBulkPreferenceUpdate(data);
761
+ }
762
+ });
763
+ }
764
+ has(args) {
765
+ return __privateGet(this, _cache4).get(getListCacheKey(args)) !== void 0;
766
+ }
767
+ set(args, data) {
768
+ __privateGet(this, _cache4).set(getListCacheKey(args), data);
769
+ for (const subscription of data) {
770
+ __privateGet(this, _itemCache).set(
771
+ getItemCacheKey({ topicKey: args.topicKey, identifier: subscription.identifier }),
772
+ subscription
773
+ );
774
+ }
775
+ }
776
+ setOne(args, data) {
777
+ __privateGet(this, _itemCache).set(getItemCacheKey(args), data);
778
+ }
779
+ getAll(args) {
780
+ return __privateGet(this, _cache4).get(getListCacheKey(args));
781
+ }
782
+ get(args) {
783
+ return __privateGet(this, _itemCache).get(getItemCacheKey(args));
784
+ }
785
+ invalidate(args) {
786
+ const listKey = getListCacheKey({ topicKey: args.topicKey });
787
+ const subscriptions = __privateGet(this, _cache4).get(listKey);
788
+ if (subscriptions) {
789
+ for (const subscription of subscriptions) {
790
+ __privateGet(this, _itemCache).remove(getItemCacheKey({ topicKey: args.topicKey, identifier: subscription.identifier }));
791
+ }
792
+ }
793
+ __privateGet(this, _cache4).remove(listKey);
794
+ const allItemKeys = __privateGet(this, _itemCache).keys();
795
+ for (const key of allItemKeys) {
796
+ if (key.startsWith(`item:${args.topicKey}:`)) {
797
+ __privateGet(this, _itemCache).remove(key);
798
+ }
799
+ }
800
+ }
801
+ clearAll() {
802
+ __privateGet(this, _cache4).clear();
803
+ __privateGet(this, _itemCache).clear();
804
+ }
805
+ };
806
+ _emitter3 = new WeakMap();
807
+ _cache4 = new WeakMap();
808
+ _useCache3 = new WeakMap();
809
+ _itemCache = new WeakMap();
810
+ _inboxService3 = new WeakMap();
811
+
812
+ // src/subscriptions/subscriptions.ts
813
+ var _useCache4, _subscriber;
814
+ var Subscriptions = class extends BaseModule {
815
+ constructor({
816
+ useCache,
817
+ inboxServiceInstance,
818
+ eventEmitterInstance,
819
+ subscriber
820
+ }) {
821
+ super({
822
+ eventEmitterInstance,
823
+ inboxServiceInstance
824
+ });
825
+ __privateAdd(this, _useCache4);
826
+ __privateAdd(this, _subscriber);
827
+ this.cache = new SubscriptionsCache({
828
+ emitterInstance: this._emitter,
829
+ inboxServiceInstance: this._inboxService,
830
+ useCache
831
+ });
832
+ __privateSet(this, _useCache4, useCache);
833
+ __privateSet(this, _subscriber, subscriber);
834
+ }
835
+ list(args, options) {
836
+ return __async(this, null, function* () {
837
+ return this.callWithSession(
838
+ () => {
839
+ var _a;
840
+ return listSubscriptions({
841
+ emitter: this._emitter,
842
+ apiService: this._inboxService,
843
+ cache: this.cache,
844
+ options: __spreadProps(__spreadValues({}, options), {
845
+ useCache: (_a = options == null ? void 0 : options.useCache) != null ? _a : __privateGet(this, _useCache4)
846
+ }),
847
+ args
848
+ });
849
+ }
850
+ );
851
+ });
852
+ }
853
+ get(args, options) {
854
+ return __async(this, null, function* () {
855
+ return this.callWithSession(
856
+ () => {
857
+ var _a, _b;
858
+ return getSubscription({
859
+ emitter: this._emitter,
860
+ apiService: this._inboxService,
861
+ cache: this.cache,
862
+ options: __spreadProps(__spreadValues({}, options), {
863
+ useCache: (_a = options == null ? void 0 : options.useCache) != null ? _a : __privateGet(this, _useCache4)
864
+ }),
865
+ args: __spreadProps(__spreadValues({}, args), {
866
+ identifier: (_b = args.identifier) != null ? _b : buildSubscriptionIdentifier({ topicKey: args.topicKey, subscriberId: __privateGet(this, _subscriber).subscriberId })
867
+ })
868
+ });
869
+ }
870
+ );
871
+ });
872
+ }
873
+ create(args) {
874
+ return __async(this, null, function* () {
875
+ return this.callWithSession(
876
+ () => createSubscription({
877
+ emitter: this._emitter,
878
+ apiService: this._inboxService,
879
+ cache: this.cache,
880
+ useCache: __privateGet(this, _useCache4),
881
+ args
882
+ })
883
+ );
884
+ });
129
885
  }
130
- if (filter.archived !== void 0 && notification.isArchived !== filter.archived) {
131
- return false;
886
+ update(args) {
887
+ return __async(this, null, function* () {
888
+ return this.callWithSession(
889
+ () => updateSubscription({
890
+ emitter: this._emitter,
891
+ apiService: this._inboxService,
892
+ cache: this.cache,
893
+ useCache: __privateGet(this, _useCache4),
894
+ args
895
+ })
896
+ );
897
+ });
132
898
  }
133
- if (filter.snoozed !== void 0 && notification.isSnoozed !== filter.snoozed) {
134
- return false;
899
+ delete(args) {
900
+ return __async(this, null, function* () {
901
+ return this.callWithSession(
902
+ () => deleteSubscription({
903
+ emitter: this._emitter,
904
+ apiService: this._inboxService,
905
+ args
906
+ })
907
+ );
908
+ });
135
909
  }
136
- return true;
137
- }
138
- function checkNotificationMatchesFilter(notification, filter) {
139
- return checkBasicFilters(notification, filter) && checkNotificationTagFilter(notification.tags, filter.tags) && checkNotificationDataFilter(notification.data, filter.data);
140
- }
910
+ };
911
+ _useCache4 = new WeakMap();
912
+ _subscriber = new WeakMap();
141
913
 
142
914
  // src/api/http-client.ts
143
915
  var DEFAULT_API_VERSION = "v1";
144
- var DEFAULT_USER_AGENT = `${"@novu/js"}@${"3.11.0"}`;
916
+ var DEFAULT_USER_AGENT = `${"@novu/js"}@${"3.12.0-rc.1"}`;
145
917
  var HttpClient = class {
146
918
  constructor(options = {}) {
147
919
  // Environment variable for local development that overrides the default API endpoint without affecting the Inbox DX
@@ -478,6 +1250,57 @@ var InboxService = class {
478
1250
  };
479
1251
  return __privateGet(this, _httpClient).post("/inbox/events", payload);
480
1252
  }
1253
+ fetchSubscriptions(topicKey) {
1254
+ return __privateGet(this, _httpClient).get(`${INBOX_ROUTE}/topics/${topicKey}/subscriptions`);
1255
+ }
1256
+ getSubscription({
1257
+ topicKey,
1258
+ identifier
1259
+ }) {
1260
+ return __privateGet(this, _httpClient).get(`${INBOX_ROUTE}/topics/${topicKey}/subscriptions/${identifier}`);
1261
+ }
1262
+ createSubscription({
1263
+ identifier,
1264
+ name,
1265
+ topicKey,
1266
+ topicName,
1267
+ preferences
1268
+ }) {
1269
+ return __privateGet(this, _httpClient).post(`${INBOX_ROUTE}/topics/${topicKey}/subscriptions`, __spreadProps(__spreadValues({
1270
+ identifier,
1271
+ name
1272
+ }, topicName && { topic: { name: topicName } }), {
1273
+ preferences
1274
+ }));
1275
+ }
1276
+ updateSubscription({
1277
+ topicKey,
1278
+ subscriptionId,
1279
+ name,
1280
+ preferences
1281
+ }) {
1282
+ return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/topics/${topicKey}/subscriptions/${subscriptionId}`, {
1283
+ name,
1284
+ preferences
1285
+ });
1286
+ }
1287
+ updateSubscriptionPreference({
1288
+ subscriptionId,
1289
+ workflowId,
1290
+ enabled,
1291
+ condition
1292
+ }) {
1293
+ return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/subscriptions/${subscriptionId}/preferences/${workflowId}`, {
1294
+ enabled,
1295
+ condition
1296
+ });
1297
+ }
1298
+ bulkUpdateSubscriptionPreferences(preferences) {
1299
+ return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/bulk`, { preferences });
1300
+ }
1301
+ deleteSubscription({ topicKey, subscriptionId }) {
1302
+ return __privateGet(this, _httpClient).delete(`${INBOX_ROUTE}/topics/${topicKey}/subscriptions/${subscriptionId}`);
1303
+ }
481
1304
  };
482
1305
  _httpClient = new WeakMap();
483
1306
  var _mittEmitter;
@@ -501,14 +1324,6 @@ var NovuEventEmitter = class {
501
1324
  };
502
1325
  _mittEmitter = new WeakMap();
503
1326
 
504
- // src/utils/errors.ts
505
- var NovuError = class extends Error {
506
- constructor(message, originalError) {
507
- super(message);
508
- this.originalError = originalError;
509
- }
510
- };
511
-
512
1327
  // src/notifications/helpers.ts
513
1328
  var read = (_0) => __async(void 0, [_0], function* ({
514
1329
  emitter,
@@ -978,13 +1793,13 @@ var deleteAll = (_0) => __async(void 0, [_0], function* ({
978
1793
  });
979
1794
 
980
1795
  // src/notifications/notification.ts
981
- var _emitter, _inboxService;
1796
+ var _emitter4, _inboxService4;
982
1797
  var Notification = class {
983
1798
  constructor(notification, emitter, inboxService) {
984
- __privateAdd(this, _emitter);
985
- __privateAdd(this, _inboxService);
986
- __privateSet(this, _emitter, emitter);
987
- __privateSet(this, _inboxService, inboxService);
1799
+ __privateAdd(this, _emitter4);
1800
+ __privateAdd(this, _inboxService4);
1801
+ __privateSet(this, _emitter4, emitter);
1802
+ __privateSet(this, _inboxService4, inboxService);
988
1803
  this.id = notification.id;
989
1804
  this.transactionId = notification.transactionId;
990
1805
  this.subject = notification.subject;
@@ -1012,8 +1827,8 @@ var Notification = class {
1012
1827
  }
1013
1828
  read() {
1014
1829
  return read({
1015
- emitter: __privateGet(this, _emitter),
1016
- apiService: __privateGet(this, _inboxService),
1830
+ emitter: __privateGet(this, _emitter4),
1831
+ apiService: __privateGet(this, _inboxService4),
1017
1832
  args: {
1018
1833
  notification: this
1019
1834
  }
@@ -1021,8 +1836,8 @@ var Notification = class {
1021
1836
  }
1022
1837
  unread() {
1023
1838
  return unread({
1024
- emitter: __privateGet(this, _emitter),
1025
- apiService: __privateGet(this, _inboxService),
1839
+ emitter: __privateGet(this, _emitter4),
1840
+ apiService: __privateGet(this, _inboxService4),
1026
1841
  args: {
1027
1842
  notification: this
1028
1843
  }
@@ -1030,8 +1845,8 @@ var Notification = class {
1030
1845
  }
1031
1846
  seen() {
1032
1847
  return seen({
1033
- emitter: __privateGet(this, _emitter),
1034
- apiService: __privateGet(this, _inboxService),
1848
+ emitter: __privateGet(this, _emitter4),
1849
+ apiService: __privateGet(this, _inboxService4),
1035
1850
  args: {
1036
1851
  notification: this
1037
1852
  }
@@ -1039,8 +1854,8 @@ var Notification = class {
1039
1854
  }
1040
1855
  archive() {
1041
1856
  return archive({
1042
- emitter: __privateGet(this, _emitter),
1043
- apiService: __privateGet(this, _inboxService),
1857
+ emitter: __privateGet(this, _emitter4),
1858
+ apiService: __privateGet(this, _inboxService4),
1044
1859
  args: {
1045
1860
  notification: this
1046
1861
  }
@@ -1048,8 +1863,8 @@ var Notification = class {
1048
1863
  }
1049
1864
  unarchive() {
1050
1865
  return unarchive({
1051
- emitter: __privateGet(this, _emitter),
1052
- apiService: __privateGet(this, _inboxService),
1866
+ emitter: __privateGet(this, _emitter4),
1867
+ apiService: __privateGet(this, _inboxService4),
1053
1868
  args: {
1054
1869
  notification: this
1055
1870
  }
@@ -1057,8 +1872,8 @@ var Notification = class {
1057
1872
  }
1058
1873
  delete() {
1059
1874
  return deleteNotification({
1060
- emitter: __privateGet(this, _emitter),
1061
- apiService: __privateGet(this, _inboxService),
1875
+ emitter: __privateGet(this, _emitter4),
1876
+ apiService: __privateGet(this, _inboxService4),
1062
1877
  args: {
1063
1878
  notification: this
1064
1879
  }
@@ -1066,8 +1881,8 @@ var Notification = class {
1066
1881
  }
1067
1882
  snooze(snoozeUntil) {
1068
1883
  return snooze({
1069
- emitter: __privateGet(this, _emitter),
1070
- apiService: __privateGet(this, _inboxService),
1884
+ emitter: __privateGet(this, _emitter4),
1885
+ apiService: __privateGet(this, _inboxService4),
1071
1886
  args: {
1072
1887
  notification: this,
1073
1888
  snoozeUntil
@@ -1076,8 +1891,8 @@ var Notification = class {
1076
1891
  }
1077
1892
  unsnooze() {
1078
1893
  return unsnooze({
1079
- emitter: __privateGet(this, _emitter),
1080
- apiService: __privateGet(this, _inboxService),
1894
+ emitter: __privateGet(this, _emitter4),
1895
+ apiService: __privateGet(this, _inboxService4),
1081
1896
  args: { notification: this }
1082
1897
  });
1083
1898
  }
@@ -1086,8 +1901,8 @@ var Notification = class {
1086
1901
  throw new Error("Primary action is not available");
1087
1902
  }
1088
1903
  return completeAction({
1089
- emitter: __privateGet(this, _emitter),
1090
- apiService: __privateGet(this, _inboxService),
1904
+ emitter: __privateGet(this, _emitter4),
1905
+ apiService: __privateGet(this, _inboxService4),
1091
1906
  args: {
1092
1907
  notification: this
1093
1908
  },
@@ -1099,8 +1914,8 @@ var Notification = class {
1099
1914
  throw new Error("Secondary action is not available");
1100
1915
  }
1101
1916
  return completeAction({
1102
- emitter: __privateGet(this, _emitter),
1103
- apiService: __privateGet(this, _inboxService),
1917
+ emitter: __privateGet(this, _emitter4),
1918
+ apiService: __privateGet(this, _inboxService4),
1104
1919
  args: {
1105
1920
  notification: this
1106
1921
  },
@@ -1112,8 +1927,8 @@ var Notification = class {
1112
1927
  throw new Error("Primary action is not available");
1113
1928
  }
1114
1929
  return revertAction({
1115
- emitter: __privateGet(this, _emitter),
1116
- apiService: __privateGet(this, _inboxService),
1930
+ emitter: __privateGet(this, _emitter4),
1931
+ apiService: __privateGet(this, _inboxService4),
1117
1932
  args: {
1118
1933
  notification: this
1119
1934
  },
@@ -1125,8 +1940,8 @@ var Notification = class {
1125
1940
  throw new Error("Secondary action is not available");
1126
1941
  }
1127
1942
  return revertAction({
1128
- emitter: __privateGet(this, _emitter),
1129
- apiService: __privateGet(this, _inboxService),
1943
+ emitter: __privateGet(this, _emitter4),
1944
+ apiService: __privateGet(this, _inboxService4),
1130
1945
  args: {
1131
1946
  notification: this
1132
1947
  },
@@ -1134,7 +1949,7 @@ var Notification = class {
1134
1949
  });
1135
1950
  }
1136
1951
  on(eventName, listener) {
1137
- const cleanup = __privateGet(this, _emitter).on(eventName, listener);
1952
+ const cleanup = __privateGet(this, _emitter4).on(eventName, listener);
1138
1953
  return () => {
1139
1954
  cleanup();
1140
1955
  };
@@ -1144,93 +1959,11 @@ var Notification = class {
1144
1959
  * Use the cleanup function returned by the "on" method instead.
1145
1960
  */
1146
1961
  off(eventName, listener) {
1147
- __privateGet(this, _emitter).off(eventName, listener);
1148
- }
1149
- };
1150
- _emitter = new WeakMap();
1151
- _inboxService = new WeakMap();
1152
-
1153
- // src/base-module.ts
1154
- var _callsQueue, _sessionError;
1155
- var BaseModule = class {
1156
- constructor({
1157
- inboxServiceInstance,
1158
- eventEmitterInstance
1159
- }) {
1160
- __privateAdd(this, _callsQueue, []);
1161
- __privateAdd(this, _sessionError);
1162
- this._emitter = eventEmitterInstance;
1163
- this._inboxService = inboxServiceInstance;
1164
- this._emitter.on("session.initialize.resolved", ({ error, data }) => {
1165
- if (data) {
1166
- this.onSessionSuccess(data);
1167
- __privateGet(this, _callsQueue).forEach((_0) => __async(this, [_0], function* ({ fn, resolve }) {
1168
- resolve(yield fn());
1169
- }));
1170
- __privateSet(this, _callsQueue, []);
1171
- } else if (error) {
1172
- this.onSessionError(error);
1173
- __privateSet(this, _sessionError, error);
1174
- __privateGet(this, _callsQueue).forEach(({ resolve }) => {
1175
- resolve({ error: new NovuError("Failed to initialize session, please contact the support", error) });
1176
- });
1177
- __privateSet(this, _callsQueue, []);
1178
- }
1179
- });
1180
- }
1181
- onSessionSuccess(_) {
1182
- }
1183
- onSessionError(_) {
1184
- }
1185
- callWithSession(fn) {
1186
- return __async(this, null, function* () {
1187
- if (this._inboxService.isSessionInitialized) {
1188
- return fn();
1189
- }
1190
- if (__privateGet(this, _sessionError)) {
1191
- return Promise.resolve({
1192
- error: new NovuError("Failed to initialize session, please contact the support", __privateGet(this, _sessionError))
1193
- });
1194
- }
1195
- return new Promise((resolve, reject) => {
1196
- __privateGet(this, _callsQueue).push({ fn, resolve, reject });
1197
- });
1198
- });
1199
- }
1200
- };
1201
- _callsQueue = new WeakMap();
1202
- _sessionError = new WeakMap();
1203
-
1204
- // src/cache/in-memory-cache.ts
1205
- var _cache;
1206
- var InMemoryCache = class {
1207
- constructor() {
1208
- __privateAdd(this, _cache);
1209
- __privateSet(this, _cache, /* @__PURE__ */ new Map());
1210
- }
1211
- get(key) {
1212
- return __privateGet(this, _cache).get(key);
1213
- }
1214
- getValues() {
1215
- return Array.from(__privateGet(this, _cache).values());
1216
- }
1217
- entries() {
1218
- return Array.from(__privateGet(this, _cache).entries());
1219
- }
1220
- keys() {
1221
- return Array.from(__privateGet(this, _cache).keys());
1222
- }
1223
- set(key, value) {
1224
- __privateGet(this, _cache).set(key, value);
1225
- }
1226
- remove(key) {
1227
- __privateGet(this, _cache).delete(key);
1228
- }
1229
- clear() {
1230
- __privateGet(this, _cache).clear();
1962
+ __privateGet(this, _emitter4).off(eventName, listener);
1231
1963
  }
1232
1964
  };
1233
- _cache = new WeakMap();
1965
+ _emitter4 = new WeakMap();
1966
+ _inboxService4 = new WeakMap();
1234
1967
 
1235
1968
  // src/cache/notifications-cache.ts
1236
1969
  var excludeEmpty = ({
@@ -1298,16 +2031,16 @@ var removeEvents = [
1298
2031
  "notifications.archive_all_read.pending",
1299
2032
  "notifications.delete_all.pending"
1300
2033
  ];
1301
- var _emitter2, _cache2;
2034
+ var _emitter5, _cache5;
1302
2035
  var NotificationsCache = class {
1303
2036
  constructor({ emitter }) {
1304
- __privateAdd(this, _emitter2);
2037
+ __privateAdd(this, _emitter5);
1305
2038
  /**
1306
2039
  * The key is the stringified notifications filter, the values are the paginated notifications.
1307
2040
  */
1308
- __privateAdd(this, _cache2);
2041
+ __privateAdd(this, _cache5);
1309
2042
  this.updateNotification = (key, data) => {
1310
- const notificationsResponse = __privateGet(this, _cache2).get(key);
2043
+ const notificationsResponse = __privateGet(this, _cache5).get(key);
1311
2044
  if (!notificationsResponse) {
1312
2045
  return false;
1313
2046
  }
@@ -1317,11 +2050,11 @@ var NotificationsCache = class {
1317
2050
  }
1318
2051
  const updatedNotifications = [...notificationsResponse.notifications];
1319
2052
  updatedNotifications[index] = data;
1320
- __privateGet(this, _cache2).set(key, __spreadProps(__spreadValues({}, notificationsResponse), { notifications: updatedNotifications }));
2053
+ __privateGet(this, _cache5).set(key, __spreadProps(__spreadValues({}, notificationsResponse), { notifications: updatedNotifications }));
1321
2054
  return true;
1322
2055
  };
1323
2056
  this.removeNotification = (key, data) => {
1324
- const notificationsResponse = __privateGet(this, _cache2).get(key);
2057
+ const notificationsResponse = __privateGet(this, _cache5).get(key);
1325
2058
  if (!notificationsResponse) {
1326
2059
  return false;
1327
2060
  }
@@ -1331,7 +2064,7 @@ var NotificationsCache = class {
1331
2064
  }
1332
2065
  const newNotifications = [...notificationsResponse.notifications];
1333
2066
  newNotifications.splice(index, 1);
1334
- __privateGet(this, _cache2).set(key, __spreadProps(__spreadValues({}, notificationsResponse), {
2067
+ __privateGet(this, _cache5).set(key, __spreadProps(__spreadValues({}, notificationsResponse), {
1335
2068
  notifications: newNotifications
1336
2069
  }));
1337
2070
  return true;
@@ -1350,8 +2083,8 @@ var NotificationsCache = class {
1350
2083
  notifications = [args.notification];
1351
2084
  } else if ("notificationId" in args && args.notificationId) {
1352
2085
  const foundNotifications = [];
1353
- __privateGet(this, _cache2).keys().forEach((key) => {
1354
- const cachedResponse = __privateGet(this, _cache2).get(key);
2086
+ __privateGet(this, _cache5).keys().forEach((key) => {
2087
+ const cachedResponse = __privateGet(this, _cache5).get(key);
1355
2088
  if (cachedResponse) {
1356
2089
  const found = cachedResponse.notifications.find((n) => n.id === args.notificationId);
1357
2090
  if (found) {
@@ -1366,7 +2099,7 @@ var NotificationsCache = class {
1366
2099
  return;
1367
2100
  }
1368
2101
  const uniqueFilterKeys = /* @__PURE__ */ new Set();
1369
- __privateGet(this, _cache2).keys().forEach((key) => {
2102
+ __privateGet(this, _cache5).keys().forEach((key) => {
1370
2103
  notifications.forEach((notification) => {
1371
2104
  let isNotificationFound = false;
1372
2105
  if (remove) {
@@ -1381,26 +2114,26 @@ var NotificationsCache = class {
1381
2114
  });
1382
2115
  uniqueFilterKeys.forEach((key) => {
1383
2116
  const notificationsResponse = this.getAggregated(getFilter(key));
1384
- __privateGet(this, _emitter2).emit("notifications.list.updated", {
2117
+ __privateGet(this, _emitter5).emit("notifications.list.updated", {
1385
2118
  data: notificationsResponse
1386
2119
  });
1387
2120
  });
1388
2121
  };
1389
- __privateSet(this, _emitter2, emitter);
2122
+ __privateSet(this, _emitter5, emitter);
1390
2123
  updateEvents.forEach((event) => {
1391
- __privateGet(this, _emitter2).on(event, this.handleNotificationEvent());
2124
+ __privateGet(this, _emitter5).on(event, this.handleNotificationEvent());
1392
2125
  });
1393
2126
  removeEvents.forEach((event) => {
1394
- __privateGet(this, _emitter2).on(event, this.handleNotificationEvent({ remove: true }));
2127
+ __privateGet(this, _emitter5).on(event, this.handleNotificationEvent({ remove: true }));
1395
2128
  });
1396
- __privateSet(this, _cache2, new InMemoryCache());
2129
+ __privateSet(this, _cache5, new InMemoryCache());
1397
2130
  }
1398
2131
  getAggregated(filter) {
1399
- const cacheKeys = __privateGet(this, _cache2).keys().filter((key) => {
2132
+ const cacheKeys = __privateGet(this, _cache5).keys().filter((key) => {
1400
2133
  const parsedFilter = getFilter(key);
1401
2134
  return isSameFilter(parsedFilter, filter);
1402
2135
  });
1403
- return cacheKeys.map((key) => __privateGet(this, _cache2).get(key)).reduce(
2136
+ return cacheKeys.map((key) => __privateGet(this, _cache5).get(key)).reduce(
1404
2137
  (acc, el) => {
1405
2138
  if (!el) {
1406
2139
  return acc;
@@ -1415,15 +2148,15 @@ var NotificationsCache = class {
1415
2148
  );
1416
2149
  }
1417
2150
  has(args) {
1418
- return __privateGet(this, _cache2).get(getCacheKey(args)) !== void 0;
2151
+ return __privateGet(this, _cache5).get(getCacheKey(args)) !== void 0;
1419
2152
  }
1420
2153
  set(args, data) {
1421
- __privateGet(this, _cache2).set(getCacheKey(args), data);
2154
+ __privateGet(this, _cache5).set(getCacheKey(args), data);
1422
2155
  }
1423
2156
  update(args, data) {
1424
2157
  this.set(args, data);
1425
2158
  const notificationsResponse = this.getAggregated(getFilter(getCacheKey(args)));
1426
- __privateGet(this, _emitter2).emit("notifications.list.updated", {
2159
+ __privateGet(this, _emitter5).emit("notifications.list.updated", {
1427
2160
  data: notificationsResponse
1428
2161
  });
1429
2162
  }
@@ -1449,12 +2182,12 @@ var NotificationsCache = class {
1449
2182
  read: read2,
1450
2183
  data
1451
2184
  }) {
1452
- const keys = __privateGet(this, _cache2).keys();
2185
+ const keys = __privateGet(this, _cache5).keys();
1453
2186
  const uniqueNotifications = /* @__PURE__ */ new Map();
1454
2187
  keys.forEach((key) => {
1455
2188
  const filter = getFilter(key);
1456
2189
  if (areTagsEqual(tags, filter.tags) && areDataEqual(data, filter.data)) {
1457
- const value = __privateGet(this, _cache2).get(key);
2190
+ const value = __privateGet(this, _cache5).get(key);
1458
2191
  if (!value) {
1459
2192
  return;
1460
2193
  }
@@ -1466,22 +2199,22 @@ var NotificationsCache = class {
1466
2199
  return Array.from(uniqueNotifications.values());
1467
2200
  }
1468
2201
  clear(filter) {
1469
- const keys = __privateGet(this, _cache2).keys();
2202
+ const keys = __privateGet(this, _cache5).keys();
1470
2203
  keys.forEach((key) => {
1471
2204
  if (isSameFilter(getFilter(key), filter)) {
1472
- __privateGet(this, _cache2).remove(key);
2205
+ __privateGet(this, _cache5).remove(key);
1473
2206
  }
1474
2207
  });
1475
2208
  }
1476
2209
  clearAll() {
1477
- __privateGet(this, _cache2).clear();
2210
+ __privateGet(this, _cache5).clear();
1478
2211
  }
1479
2212
  };
1480
- _emitter2 = new WeakMap();
1481
- _cache2 = new WeakMap();
2213
+ _emitter5 = new WeakMap();
2214
+ _cache5 = new WeakMap();
1482
2215
 
1483
2216
  // src/notifications/notifications.ts
1484
- var _useCache;
2217
+ var _useCache5;
1485
2218
  var Notifications = class extends BaseModule {
1486
2219
  constructor({
1487
2220
  useCache,
@@ -1492,11 +2225,11 @@ var Notifications = class extends BaseModule {
1492
2225
  eventEmitterInstance,
1493
2226
  inboxServiceInstance
1494
2227
  });
1495
- __privateAdd(this, _useCache);
2228
+ __privateAdd(this, _useCache5);
1496
2229
  this.cache = new NotificationsCache({
1497
2230
  emitter: eventEmitterInstance
1498
2231
  });
1499
- __privateSet(this, _useCache, useCache);
2232
+ __privateSet(this, _useCache5, useCache);
1500
2233
  }
1501
2234
  get inboxService() {
1502
2235
  return this._inboxService;
@@ -1507,7 +2240,7 @@ var Notifications = class extends BaseModule {
1507
2240
  return this.callWithSession(() => __async(this, null, function* () {
1508
2241
  const args = __spreadValues({ limit }, restOptions);
1509
2242
  try {
1510
- const shouldUseCache = "useCache" in args ? args.useCache : __privateGet(this, _useCache);
2243
+ const shouldUseCache = "useCache" in args ? args.useCache : __privateGet(this, _useCache5);
1511
2244
  let data = shouldUseCache ? this.cache.getAll(args) : void 0;
1512
2245
  this._emitter.emit("notifications.list.pending", { args, data });
1513
2246
  if (!data) {
@@ -1819,10 +2552,10 @@ var Notifications = class extends BaseModule {
1819
2552
  });
1820
2553
  }
1821
2554
  };
1822
- _useCache = new WeakMap();
2555
+ _useCache5 = new WeakMap();
1823
2556
 
1824
2557
  // src/preferences/schedule.ts
1825
- var _emitter3, _apiService, _cache3, _useCache2;
2558
+ var _emitter6, _apiService, _cache6, _useCache6;
1826
2559
  var Schedule = class {
1827
2560
  constructor(schedule, {
1828
2561
  emitterInstance,
@@ -1830,14 +2563,14 @@ var Schedule = class {
1830
2563
  cache,
1831
2564
  useCache
1832
2565
  }) {
1833
- __privateAdd(this, _emitter3);
2566
+ __privateAdd(this, _emitter6);
1834
2567
  __privateAdd(this, _apiService);
1835
- __privateAdd(this, _cache3);
1836
- __privateAdd(this, _useCache2);
1837
- __privateSet(this, _emitter3, emitterInstance);
2568
+ __privateAdd(this, _cache6);
2569
+ __privateAdd(this, _useCache6);
2570
+ __privateSet(this, _emitter6, emitterInstance);
1838
2571
  __privateSet(this, _apiService, inboxServiceInstance);
1839
- __privateSet(this, _cache3, cache);
1840
- __privateSet(this, _useCache2, useCache);
2572
+ __privateSet(this, _cache6, cache);
2573
+ __privateSet(this, _useCache6, useCache);
1841
2574
  this.isEnabled = schedule.isEnabled;
1842
2575
  this.weeklySchedule = schedule.weeklySchedule;
1843
2576
  }
@@ -1846,10 +2579,10 @@ var Schedule = class {
1846
2579
  var _a;
1847
2580
  const hasWeeklySchedule = !!args.weeklySchedule || !!this.weeklySchedule;
1848
2581
  return updateSchedule({
1849
- emitter: __privateGet(this, _emitter3),
2582
+ emitter: __privateGet(this, _emitter6),
1850
2583
  apiService: __privateGet(this, _apiService),
1851
- cache: __privateGet(this, _cache3),
1852
- useCache: __privateGet(this, _useCache2),
2584
+ cache: __privateGet(this, _cache6),
2585
+ useCache: __privateGet(this, _useCache6),
1853
2586
  args: __spreadValues({
1854
2587
  isEnabled: (_a = args.isEnabled) != null ? _a : this.isEnabled
1855
2588
  }, hasWeeklySchedule && {
@@ -1859,13 +2592,13 @@ var Schedule = class {
1859
2592
  });
1860
2593
  }
1861
2594
  };
1862
- _emitter3 = new WeakMap();
2595
+ _emitter6 = new WeakMap();
1863
2596
  _apiService = new WeakMap();
1864
- _cache3 = new WeakMap();
1865
- _useCache2 = new WeakMap();
2597
+ _cache6 = new WeakMap();
2598
+ _useCache6 = new WeakMap();
1866
2599
 
1867
2600
  // src/preferences/preference.ts
1868
- var _emitter4, _apiService2, _cache4, _scheduleCache, _useCache3;
2601
+ var _emitter7, _apiService2, _cache7, _scheduleCache, _useCache7;
1869
2602
  var Preference = class {
1870
2603
  constructor(preference, {
1871
2604
  emitterInstance,
@@ -1874,16 +2607,16 @@ var Preference = class {
1874
2607
  scheduleCache,
1875
2608
  useCache
1876
2609
  }) {
1877
- __privateAdd(this, _emitter4);
2610
+ __privateAdd(this, _emitter7);
1878
2611
  __privateAdd(this, _apiService2);
1879
- __privateAdd(this, _cache4);
2612
+ __privateAdd(this, _cache7);
1880
2613
  __privateAdd(this, _scheduleCache);
1881
- __privateAdd(this, _useCache3);
1882
- __privateSet(this, _emitter4, emitterInstance);
2614
+ __privateAdd(this, _useCache7);
2615
+ __privateSet(this, _emitter7, emitterInstance);
1883
2616
  __privateSet(this, _apiService2, inboxServiceInstance);
1884
- __privateSet(this, _cache4, cache);
2617
+ __privateSet(this, _cache7, cache);
1885
2618
  __privateSet(this, _scheduleCache, scheduleCache);
1886
- __privateSet(this, _useCache3, useCache);
2619
+ __privateSet(this, _useCache7, useCache);
1887
2620
  this.level = preference.level;
1888
2621
  this.enabled = preference.enabled;
1889
2622
  this.channels = preference.channels;
@@ -1899,11 +2632,11 @@ var Preference = class {
1899
2632
  }) {
1900
2633
  var _a;
1901
2634
  return updatePreference({
1902
- emitter: __privateGet(this, _emitter4),
2635
+ emitter: __privateGet(this, _emitter7),
1903
2636
  apiService: __privateGet(this, _apiService2),
1904
- cache: __privateGet(this, _cache4),
2637
+ cache: __privateGet(this, _cache7),
1905
2638
  scheduleCache: __privateGet(this, _scheduleCache),
1906
- useCache: __privateGet(this, _useCache3),
2639
+ useCache: __privateGet(this, _useCache7),
1907
2640
  args: {
1908
2641
  workflowId: (_a = this.workflow) == null ? void 0 : _a.id,
1909
2642
  channels: channels || channelPreferences,
@@ -1912,11 +2645,11 @@ var Preference = class {
1912
2645
  });
1913
2646
  }
1914
2647
  };
1915
- _emitter4 = new WeakMap();
2648
+ _emitter7 = new WeakMap();
1916
2649
  _apiService2 = new WeakMap();
1917
- _cache4 = new WeakMap();
2650
+ _cache7 = new WeakMap();
1918
2651
  _scheduleCache = new WeakMap();
1919
- _useCache3 = new WeakMap();
2652
+ _useCache7 = new WeakMap();
1920
2653
 
1921
2654
  // src/preferences/helpers.ts
1922
2655
  var updatePreference = (_0) => __async(void 0, [_0], function* ({
@@ -2113,7 +2846,7 @@ var updateSchedule = (_0) => __async(void 0, [_0], function* ({
2113
2846
  });
2114
2847
 
2115
2848
  // src/preferences/preference-schedule.ts
2116
- var _useCache4;
2849
+ var _useCache8;
2117
2850
  var PreferenceSchedule = class extends BaseModule {
2118
2851
  constructor({
2119
2852
  cache,
@@ -2125,16 +2858,16 @@ var PreferenceSchedule = class extends BaseModule {
2125
2858
  eventEmitterInstance,
2126
2859
  inboxServiceInstance
2127
2860
  });
2128
- __privateAdd(this, _useCache4);
2861
+ __privateAdd(this, _useCache8);
2129
2862
  this.cache = cache;
2130
- __privateSet(this, _useCache4, useCache);
2863
+ __privateSet(this, _useCache8, useCache);
2131
2864
  }
2132
2865
  get() {
2133
2866
  return __async(this, null, function* () {
2134
2867
  return this.callWithSession(() => __async(this, null, function* () {
2135
2868
  var _a, _b;
2136
2869
  try {
2137
- let data = __privateGet(this, _useCache4) ? this.cache.getAll() : void 0;
2870
+ let data = __privateGet(this, _useCache8) ? this.cache.getAll() : void 0;
2138
2871
  this._emitter.emit("preference.schedule.get.pending", { args: void 0, data });
2139
2872
  if (!data) {
2140
2873
  const globalPreference = yield this._inboxService.fetchGlobalPreferences();
@@ -2147,10 +2880,10 @@ var PreferenceSchedule = class extends BaseModule {
2147
2880
  emitterInstance: this._emitter,
2148
2881
  inboxServiceInstance: this._inboxService,
2149
2882
  cache: this.cache,
2150
- useCache: __privateGet(this, _useCache4)
2883
+ useCache: __privateGet(this, _useCache8)
2151
2884
  }
2152
2885
  );
2153
- if (__privateGet(this, _useCache4)) {
2886
+ if (__privateGet(this, _useCache8)) {
2154
2887
  this.cache.set(data);
2155
2888
  data = this.cache.getAll();
2156
2889
  }
@@ -2174,14 +2907,14 @@ var PreferenceSchedule = class extends BaseModule {
2174
2907
  emitter: this._emitter,
2175
2908
  apiService: this._inboxService,
2176
2909
  cache: this.cache,
2177
- useCache: __privateGet(this, _useCache4),
2910
+ useCache: __privateGet(this, _useCache8),
2178
2911
  args
2179
2912
  })
2180
2913
  );
2181
2914
  });
2182
2915
  }
2183
2916
  };
2184
- _useCache4 = new WeakMap();
2917
+ _useCache8 = new WeakMap();
2185
2918
 
2186
2919
  // src/cache/preferences-cache.ts
2187
2920
  var updateEvents2 = [
@@ -2204,13 +2937,13 @@ var excludeEmpty2 = ({ tags, severity }) => Object.entries({ tags, severity }).r
2204
2937
  var getCacheKey2 = ({ tags, severity }) => {
2205
2938
  return JSON.stringify(excludeEmpty2({ tags, severity }));
2206
2939
  };
2207
- var _emitter5, _cache5;
2940
+ var _emitter8, _cache8;
2208
2941
  var PreferencesCache = class {
2209
2942
  constructor({ emitterInstance }) {
2210
- __privateAdd(this, _emitter5);
2211
- __privateAdd(this, _cache5);
2943
+ __privateAdd(this, _emitter8);
2944
+ __privateAdd(this, _cache8);
2212
2945
  this.updatePreference = (key, data) => {
2213
- const preferences = __privateGet(this, _cache5).get(key);
2946
+ const preferences = __privateGet(this, _cache8).get(key);
2214
2947
  if (!preferences) {
2215
2948
  return false;
2216
2949
  }
@@ -2225,11 +2958,11 @@ var PreferencesCache = class {
2225
2958
  }
2226
2959
  const updatedPreferences = [...preferences];
2227
2960
  updatedPreferences[index] = data;
2228
- __privateGet(this, _cache5).set(key, updatedPreferences);
2961
+ __privateGet(this, _cache8).set(key, updatedPreferences);
2229
2962
  return true;
2230
2963
  };
2231
2964
  this.updatePreferenceSchedule = (key, data) => {
2232
- const preferences = __privateGet(this, _cache5).get(key);
2965
+ const preferences = __privateGet(this, _cache8).get(key);
2233
2966
  if (!preferences) {
2234
2967
  return false;
2235
2968
  }
@@ -2239,7 +2972,7 @@ var PreferencesCache = class {
2239
2972
  }
2240
2973
  const updatedPreferences = [...preferences];
2241
2974
  updatedPreferences[index].schedule = data;
2242
- __privateGet(this, _cache5).set(key, updatedPreferences);
2975
+ __privateGet(this, _cache8).set(key, updatedPreferences);
2243
2976
  return true;
2244
2977
  };
2245
2978
  this.handleScheduleEvent = ({ data }) => {
@@ -2247,19 +2980,19 @@ var PreferencesCache = class {
2247
2980
  if (!data) {
2248
2981
  return;
2249
2982
  }
2250
- const cacheKeys = __privateGet(this, _cache5).keys();
2983
+ const cacheKeys = __privateGet(this, _cache8).keys();
2251
2984
  const uniqueFilterKeys = /* @__PURE__ */ new Set();
2252
2985
  for (const key of cacheKeys) {
2253
2986
  const hasUpdatedPreference = this.updatePreferenceSchedule(key, data);
2254
- const updatedPreference = __privateGet(this, _cache5).get(key);
2987
+ const updatedPreference = __privateGet(this, _cache8).get(key);
2255
2988
  if (!hasUpdatedPreference || !updatedPreference) {
2256
2989
  continue;
2257
2990
  }
2258
2991
  uniqueFilterKeys.add(key);
2259
2992
  }
2260
2993
  for (const key of uniqueFilterKeys) {
2261
- __privateGet(this, _emitter5).emit("preferences.list.updated", {
2262
- data: (_a = __privateGet(this, _cache5).get(key)) != null ? _a : []
2994
+ __privateGet(this, _emitter8).emit("preferences.list.updated", {
2995
+ data: (_a = __privateGet(this, _cache8).get(key)) != null ? _a : []
2263
2996
  });
2264
2997
  }
2265
2998
  };
@@ -2269,10 +3002,10 @@ var PreferencesCache = class {
2269
3002
  }
2270
3003
  const preferences = Array.isArray(data) ? data : [data];
2271
3004
  const uniqueFilterKeys = /* @__PURE__ */ new Set();
2272
- __privateGet(this, _cache5).keys().forEach((key) => {
3005
+ __privateGet(this, _cache8).keys().forEach((key) => {
2273
3006
  preferences.forEach((preference) => {
2274
3007
  const hasUpdatedPreference = this.updatePreference(key, preference);
2275
- const updatedPreference = __privateGet(this, _cache5).get(key);
3008
+ const updatedPreference = __privateGet(this, _cache8).get(key);
2276
3009
  if (!hasUpdatedPreference || !updatedPreference) {
2277
3010
  return;
2278
3011
  }
@@ -2281,37 +3014,37 @@ var PreferencesCache = class {
2281
3014
  });
2282
3015
  uniqueFilterKeys.forEach((key) => {
2283
3016
  var _a;
2284
- __privateGet(this, _emitter5).emit("preferences.list.updated", {
2285
- data: (_a = __privateGet(this, _cache5).get(key)) != null ? _a : []
3017
+ __privateGet(this, _emitter8).emit("preferences.list.updated", {
3018
+ data: (_a = __privateGet(this, _cache8).get(key)) != null ? _a : []
2286
3019
  });
2287
3020
  });
2288
3021
  };
2289
- __privateSet(this, _emitter5, emitterInstance);
3022
+ __privateSet(this, _emitter8, emitterInstance);
2290
3023
  for (const event of updateEvents2) {
2291
- __privateGet(this, _emitter5).on(event, this.handlePreferenceEvent);
3024
+ __privateGet(this, _emitter8).on(event, this.handlePreferenceEvent);
2292
3025
  }
2293
3026
  for (const event of scheduleUpdateEvents) {
2294
- __privateGet(this, _emitter5).on(event, this.handleScheduleEvent);
3027
+ __privateGet(this, _emitter8).on(event, this.handleScheduleEvent);
2295
3028
  }
2296
- __privateSet(this, _cache5, new InMemoryCache());
3029
+ __privateSet(this, _cache8, new InMemoryCache());
2297
3030
  }
2298
3031
  has(args) {
2299
- return __privateGet(this, _cache5).get(getCacheKey2(args)) !== void 0;
3032
+ return __privateGet(this, _cache8).get(getCacheKey2(args)) !== void 0;
2300
3033
  }
2301
3034
  set(args, data) {
2302
- __privateGet(this, _cache5).set(getCacheKey2(args), data);
3035
+ __privateGet(this, _cache8).set(getCacheKey2(args), data);
2303
3036
  }
2304
3037
  getAll(args) {
2305
3038
  if (this.has(args)) {
2306
- return __privateGet(this, _cache5).get(getCacheKey2(args));
3039
+ return __privateGet(this, _cache8).get(getCacheKey2(args));
2307
3040
  }
2308
3041
  }
2309
3042
  clearAll() {
2310
- __privateGet(this, _cache5).clear();
3043
+ __privateGet(this, _cache8).clear();
2311
3044
  }
2312
3045
  };
2313
- _emitter5 = new WeakMap();
2314
- _cache5 = new WeakMap();
3046
+ _emitter8 = new WeakMap();
3047
+ _cache8 = new WeakMap();
2315
3048
 
2316
3049
  // src/cache/schedule-cache.ts
2317
3050
  var updateEvents3 = [
@@ -2321,17 +3054,17 @@ var updateEvents3 = [
2321
3054
  var getCacheKey3 = () => {
2322
3055
  return "schedule";
2323
3056
  };
2324
- var _emitter6, _cache6;
3057
+ var _emitter9, _cache9;
2325
3058
  var ScheduleCache = class {
2326
3059
  constructor({ emitterInstance }) {
2327
- __privateAdd(this, _emitter6);
2328
- __privateAdd(this, _cache6);
3060
+ __privateAdd(this, _emitter9);
3061
+ __privateAdd(this, _cache9);
2329
3062
  this.updateScheduleInCache = (key, data) => {
2330
- const schedule = __privateGet(this, _cache6).get(key);
3063
+ const schedule = __privateGet(this, _cache9).get(key);
2331
3064
  if (!schedule) {
2332
3065
  return false;
2333
3066
  }
2334
- __privateGet(this, _cache6).set(key, data);
3067
+ __privateGet(this, _cache9).set(key, data);
2335
3068
  return true;
2336
3069
  };
2337
3070
  this.handleScheduleEvent = ({ data }) => {
@@ -2339,47 +3072,47 @@ var ScheduleCache = class {
2339
3072
  return;
2340
3073
  }
2341
3074
  const uniqueFilterKeys = /* @__PURE__ */ new Set();
2342
- const keys = __privateGet(this, _cache6).keys();
3075
+ const keys = __privateGet(this, _cache9).keys();
2343
3076
  for (const key of keys) {
2344
3077
  const hasUpdatedSchedule = this.updateScheduleInCache(key, data);
2345
- const updatedSchedule = __privateGet(this, _cache6).get(key);
3078
+ const updatedSchedule = __privateGet(this, _cache9).get(key);
2346
3079
  if (!hasUpdatedSchedule || !updatedSchedule) {
2347
3080
  continue;
2348
3081
  }
2349
3082
  uniqueFilterKeys.add(key);
2350
3083
  }
2351
3084
  for (const key of uniqueFilterKeys) {
2352
- __privateGet(this, _emitter6).emit("preference.schedule.get.updated", {
2353
- data: __privateGet(this, _cache6).get(key)
3085
+ __privateGet(this, _emitter9).emit("preference.schedule.get.updated", {
3086
+ data: __privateGet(this, _cache9).get(key)
2354
3087
  });
2355
3088
  }
2356
3089
  };
2357
- __privateSet(this, _emitter6, emitterInstance);
3090
+ __privateSet(this, _emitter9, emitterInstance);
2358
3091
  for (const event of updateEvents3) {
2359
- __privateGet(this, _emitter6).on(event, this.handleScheduleEvent);
3092
+ __privateGet(this, _emitter9).on(event, this.handleScheduleEvent);
2360
3093
  }
2361
- __privateSet(this, _cache6, new InMemoryCache());
3094
+ __privateSet(this, _cache9, new InMemoryCache());
2362
3095
  }
2363
3096
  has() {
2364
- return __privateGet(this, _cache6).get(getCacheKey3()) !== void 0;
3097
+ return __privateGet(this, _cache9).get(getCacheKey3()) !== void 0;
2365
3098
  }
2366
3099
  set(data) {
2367
- __privateGet(this, _cache6).set(getCacheKey3(), data);
3100
+ __privateGet(this, _cache9).set(getCacheKey3(), data);
2368
3101
  }
2369
3102
  getAll() {
2370
3103
  if (this.has()) {
2371
- return __privateGet(this, _cache6).get(getCacheKey3());
3104
+ return __privateGet(this, _cache9).get(getCacheKey3());
2372
3105
  }
2373
3106
  }
2374
3107
  clearAll() {
2375
- __privateGet(this, _cache6).clear();
3108
+ __privateGet(this, _cache9).clear();
2376
3109
  }
2377
3110
  };
2378
- _emitter6 = new WeakMap();
2379
- _cache6 = new WeakMap();
3111
+ _emitter9 = new WeakMap();
3112
+ _cache9 = new WeakMap();
2380
3113
 
2381
3114
  // src/preferences/preferences.ts
2382
- var _useCache5;
3115
+ var _useCache9;
2383
3116
  var Preferences = class extends BaseModule {
2384
3117
  constructor({
2385
3118
  useCache,
@@ -2390,14 +3123,14 @@ var Preferences = class extends BaseModule {
2390
3123
  eventEmitterInstance,
2391
3124
  inboxServiceInstance
2392
3125
  });
2393
- __privateAdd(this, _useCache5);
3126
+ __privateAdd(this, _useCache9);
2394
3127
  this.cache = new PreferencesCache({
2395
3128
  emitterInstance: this._emitter
2396
3129
  });
2397
3130
  this.scheduleCache = new ScheduleCache({
2398
3131
  emitterInstance: this._emitter
2399
3132
  });
2400
- __privateSet(this, _useCache5, useCache);
3133
+ __privateSet(this, _useCache9, useCache);
2401
3134
  this.schedule = new PreferenceSchedule({
2402
3135
  cache: this.scheduleCache,
2403
3136
  useCache,
@@ -2410,7 +3143,7 @@ var Preferences = class extends BaseModule {
2410
3143
  return this.callWithSession(() => __async(this, null, function* () {
2411
3144
  var _a;
2412
3145
  try {
2413
- let data = __privateGet(this, _useCache5) ? this.cache.getAll(args) : void 0;
3146
+ let data = __privateGet(this, _useCache9) ? this.cache.getAll(args) : void 0;
2414
3147
  this._emitter.emit("preferences.list.pending", { args, data });
2415
3148
  if (!data) {
2416
3149
  const response = yield this._inboxService.fetchPreferences({
@@ -2424,10 +3157,10 @@ var Preferences = class extends BaseModule {
2424
3157
  inboxServiceInstance: this._inboxService,
2425
3158
  cache: this.cache,
2426
3159
  scheduleCache: this.scheduleCache,
2427
- useCache: __privateGet(this, _useCache5)
3160
+ useCache: __privateGet(this, _useCache9)
2428
3161
  })
2429
3162
  );
2430
- if (__privateGet(this, _useCache5)) {
3163
+ if (__privateGet(this, _useCache9)) {
2431
3164
  this.cache.set(args, data);
2432
3165
  data = this.cache.getAll(args);
2433
3166
  }
@@ -2449,7 +3182,7 @@ var Preferences = class extends BaseModule {
2449
3182
  apiService: this._inboxService,
2450
3183
  cache: this.cache,
2451
3184
  scheduleCache: this.scheduleCache,
2452
- useCache: __privateGet(this, _useCache5),
3185
+ useCache: __privateGet(this, _useCache9),
2453
3186
  args
2454
3187
  })
2455
3188
  );
@@ -2463,14 +3196,14 @@ var Preferences = class extends BaseModule {
2463
3196
  apiService: this._inboxService,
2464
3197
  cache: this.cache,
2465
3198
  scheduleCache: this.scheduleCache,
2466
- useCache: __privateGet(this, _useCache5),
3199
+ useCache: __privateGet(this, _useCache9),
2467
3200
  args
2468
3201
  })
2469
3202
  );
2470
3203
  });
2471
3204
  }
2472
3205
  };
2473
- _useCache5 = new WeakMap();
3206
+ _useCache9 = new WeakMap();
2474
3207
 
2475
3208
  // src/utils/is-browser.ts
2476
3209
  function isBrowser() {
@@ -2478,14 +3211,14 @@ function isBrowser() {
2478
3211
  }
2479
3212
 
2480
3213
  // src/session/session.ts
2481
- var _emitter7, _inboxService2, _options;
3214
+ var _emitter10, _inboxService5, _options;
2482
3215
  var Session = class {
2483
3216
  constructor(options, inboxServiceInstance, eventEmitterInstance) {
2484
- __privateAdd(this, _emitter7);
2485
- __privateAdd(this, _inboxService2);
3217
+ __privateAdd(this, _emitter10);
3218
+ __privateAdd(this, _inboxService5);
2486
3219
  __privateAdd(this, _options);
2487
- __privateSet(this, _emitter7, eventEmitterInstance);
2488
- __privateSet(this, _inboxService2, inboxServiceInstance);
3220
+ __privateSet(this, _emitter10, eventEmitterInstance);
3221
+ __privateSet(this, _inboxService5, inboxServiceInstance);
2489
3222
  __privateSet(this, _options, options);
2490
3223
  }
2491
3224
  get applicationIdentifier() {
@@ -2556,8 +3289,8 @@ var Session = class {
2556
3289
  } else {
2557
3290
  this.handleApplicationIdentifier("delete");
2558
3291
  }
2559
- __privateGet(this, _emitter7).emit("session.initialize.pending", { args: __privateGet(this, _options) });
2560
- const response = yield __privateGet(this, _inboxService2).initializeSession({
3292
+ __privateGet(this, _emitter10).emit("session.initialize.pending", { args: __privateGet(this, _options) });
3293
+ const response = yield __privateGet(this, _inboxService5).initializeSession({
2561
3294
  applicationIdentifier: finalApplicationIdentifier,
2562
3295
  subscriberHash,
2563
3296
  contextHash,
@@ -2574,15 +3307,15 @@ var Session = class {
2574
3307
  if (!((_f = response == null ? void 0 : response.applicationIdentifier) == null ? void 0 : _f.startsWith("pk_keyless_"))) {
2575
3308
  this.handleApplicationIdentifier("delete");
2576
3309
  }
2577
- __privateGet(this, _emitter7).emit("session.initialize.resolved", { args: __privateGet(this, _options), data: response });
3310
+ __privateGet(this, _emitter10).emit("session.initialize.resolved", { args: __privateGet(this, _options), data: response });
2578
3311
  } catch (error) {
2579
- __privateGet(this, _emitter7).emit("session.initialize.resolved", { args: __privateGet(this, _options), error });
3312
+ __privateGet(this, _emitter10).emit("session.initialize.resolved", { args: __privateGet(this, _options), error });
2580
3313
  }
2581
3314
  });
2582
3315
  }
2583
3316
  };
2584
- _emitter7 = new WeakMap();
2585
- _inboxService2 = new WeakMap();
3317
+ _emitter10 = new WeakMap();
3318
+ _inboxService5 = new WeakMap();
2586
3319
  _options = new WeakMap();
2587
3320
  var PRODUCTION_SOCKET_URL = "wss://socket.novu.co";
2588
3321
  var NOTIFICATION_RECEIVED = "notifications.notification_received";
@@ -2675,7 +3408,7 @@ var mapToNotification = ({
2675
3408
  severity
2676
3409
  });
2677
3410
  };
2678
- var _token, _emitter8, _partySocket, _socketUrl, _notificationReceived, _unseenCountChanged, _unreadCountChanged, _handleMessage, _PartySocketClient_instances, initializeSocket_fn, handleConnectSocket_fn, handleDisconnectSocket_fn;
3411
+ var _token, _emitter11, _partySocket, _socketUrl, _notificationReceived, _unseenCountChanged, _unreadCountChanged, _handleMessage, _PartySocketClient_instances, initializeSocket_fn, handleConnectSocket_fn, handleDisconnectSocket_fn;
2679
3412
  var PartySocketClient = class extends BaseModule {
2680
3413
  constructor({
2681
3414
  socketUrl,
@@ -2688,15 +3421,15 @@ var PartySocketClient = class extends BaseModule {
2688
3421
  });
2689
3422
  __privateAdd(this, _PartySocketClient_instances);
2690
3423
  __privateAdd(this, _token);
2691
- __privateAdd(this, _emitter8);
3424
+ __privateAdd(this, _emitter11);
2692
3425
  __privateAdd(this, _partySocket);
2693
3426
  __privateAdd(this, _socketUrl);
2694
3427
  __privateAdd(this, _notificationReceived, (event) => {
2695
3428
  try {
2696
3429
  const data = JSON.parse(event.data);
2697
3430
  if (data.event === "notification_received" /* RECEIVED */) {
2698
- __privateGet(this, _emitter8).emit(NOTIFICATION_RECEIVED, {
2699
- result: new Notification(mapToNotification(data.data.message), __privateGet(this, _emitter8), this._inboxService)
3431
+ __privateGet(this, _emitter11).emit(NOTIFICATION_RECEIVED, {
3432
+ result: new Notification(mapToNotification(data.data.message), __privateGet(this, _emitter11), this._inboxService)
2700
3433
  });
2701
3434
  }
2702
3435
  } catch (error) {
@@ -2707,7 +3440,7 @@ var PartySocketClient = class extends BaseModule {
2707
3440
  try {
2708
3441
  const data = JSON.parse(event.data);
2709
3442
  if (data.event === "unseen_count_changed" /* UNSEEN */) {
2710
- __privateGet(this, _emitter8).emit(UNSEEN_COUNT_CHANGED, {
3443
+ __privateGet(this, _emitter11).emit(UNSEEN_COUNT_CHANGED, {
2711
3444
  result: data.data.unseenCount
2712
3445
  });
2713
3446
  }
@@ -2718,7 +3451,7 @@ var PartySocketClient = class extends BaseModule {
2718
3451
  try {
2719
3452
  const data = JSON.parse(event.data);
2720
3453
  if (data.event === "unread_count_changed" /* UNREAD */) {
2721
- __privateGet(this, _emitter8).emit(UNREAD_COUNT_CHANGED, {
3454
+ __privateGet(this, _emitter11).emit(UNREAD_COUNT_CHANGED, {
2722
3455
  result: data.data.counts
2723
3456
  });
2724
3457
  }
@@ -2743,7 +3476,7 @@ var PartySocketClient = class extends BaseModule {
2743
3476
  } catch (error) {
2744
3477
  }
2745
3478
  });
2746
- __privateSet(this, _emitter8, eventEmitterInstance);
3479
+ __privateSet(this, _emitter11, eventEmitterInstance);
2747
3480
  __privateSet(this, _socketUrl, socketUrl != null ? socketUrl : PRODUCTION_SOCKET_URL);
2748
3481
  }
2749
3482
  onSessionSuccess({ token }) {
@@ -2770,7 +3503,7 @@ var PartySocketClient = class extends BaseModule {
2770
3503
  }
2771
3504
  };
2772
3505
  _token = new WeakMap();
2773
- _emitter8 = new WeakMap();
3506
+ _emitter11 = new WeakMap();
2774
3507
  _partySocket = new WeakMap();
2775
3508
  _socketUrl = new WeakMap();
2776
3509
  _notificationReceived = new WeakMap();
@@ -2784,15 +3517,15 @@ initializeSocket_fn = function() {
2784
3517
  return;
2785
3518
  }
2786
3519
  const args = { socketUrl: __privateGet(this, _socketUrl) };
2787
- __privateGet(this, _emitter8).emit("socket.connect.pending", { args });
3520
+ __privateGet(this, _emitter11).emit("socket.connect.pending", { args });
2788
3521
  const url = new URL(__privateGet(this, _socketUrl));
2789
3522
  url.searchParams.set("token", __privateGet(this, _token));
2790
3523
  __privateSet(this, _partySocket, new WebSocket(url.toString()));
2791
3524
  __privateGet(this, _partySocket).addEventListener("open", () => {
2792
- __privateGet(this, _emitter8).emit("socket.connect.resolved", { args });
3525
+ __privateGet(this, _emitter11).emit("socket.connect.resolved", { args });
2793
3526
  });
2794
3527
  __privateGet(this, _partySocket).addEventListener("error", (error) => {
2795
- __privateGet(this, _emitter8).emit("socket.connect.resolved", { args, error });
3528
+ __privateGet(this, _emitter11).emit("socket.connect.resolved", { args, error });
2796
3529
  });
2797
3530
  __privateGet(this, _partySocket).addEventListener("message", __privateGet(this, _handleMessage));
2798
3531
  });
@@ -2910,7 +3643,7 @@ var mapToNotification2 = ({
2910
3643
  severity
2911
3644
  });
2912
3645
  };
2913
- var _token2, _emitter9, _socketIo, _socketUrl2, _notificationReceived2, _unseenCountChanged2, _unreadCountChanged2, _Socket_instances, initializeSocket_fn2, handleConnectSocket_fn2, handleDisconnectSocket_fn2;
3646
+ var _token2, _emitter12, _socketIo, _socketUrl2, _notificationReceived2, _unseenCountChanged2, _unreadCountChanged2, _Socket_instances, initializeSocket_fn2, handleConnectSocket_fn2, handleDisconnectSocket_fn2;
2914
3647
  var Socket = class extends BaseModule {
2915
3648
  constructor({
2916
3649
  socketUrl,
@@ -2923,25 +3656,25 @@ var Socket = class extends BaseModule {
2923
3656
  });
2924
3657
  __privateAdd(this, _Socket_instances);
2925
3658
  __privateAdd(this, _token2);
2926
- __privateAdd(this, _emitter9);
3659
+ __privateAdd(this, _emitter12);
2927
3660
  __privateAdd(this, _socketIo);
2928
3661
  __privateAdd(this, _socketUrl2);
2929
3662
  __privateAdd(this, _notificationReceived2, ({ message }) => {
2930
- __privateGet(this, _emitter9).emit(NOTIFICATION_RECEIVED2, {
2931
- result: new Notification(mapToNotification2(message), __privateGet(this, _emitter9), this._inboxService)
3663
+ __privateGet(this, _emitter12).emit(NOTIFICATION_RECEIVED2, {
3664
+ result: new Notification(mapToNotification2(message), __privateGet(this, _emitter12), this._inboxService)
2932
3665
  });
2933
3666
  });
2934
3667
  __privateAdd(this, _unseenCountChanged2, ({ unseenCount }) => {
2935
- __privateGet(this, _emitter9).emit(UNSEEN_COUNT_CHANGED2, {
3668
+ __privateGet(this, _emitter12).emit(UNSEEN_COUNT_CHANGED2, {
2936
3669
  result: unseenCount
2937
3670
  });
2938
3671
  });
2939
3672
  __privateAdd(this, _unreadCountChanged2, ({ counts }) => {
2940
- __privateGet(this, _emitter9).emit(UNREAD_COUNT_CHANGED2, {
3673
+ __privateGet(this, _emitter12).emit(UNREAD_COUNT_CHANGED2, {
2941
3674
  result: counts
2942
3675
  });
2943
3676
  });
2944
- __privateSet(this, _emitter9, eventEmitterInstance);
3677
+ __privateSet(this, _emitter12, eventEmitterInstance);
2945
3678
  __privateSet(this, _socketUrl2, socketUrl != null ? socketUrl : PRODUCTION_SOCKET_URL2);
2946
3679
  }
2947
3680
  onSessionSuccess({ token }) {
@@ -2968,7 +3701,7 @@ var Socket = class extends BaseModule {
2968
3701
  }
2969
3702
  };
2970
3703
  _token2 = new WeakMap();
2971
- _emitter9 = new WeakMap();
3704
+ _emitter12 = new WeakMap();
2972
3705
  _socketIo = new WeakMap();
2973
3706
  _socketUrl2 = new WeakMap();
2974
3707
  _notificationReceived2 = new WeakMap();
@@ -2982,7 +3715,7 @@ initializeSocket_fn2 = function() {
2982
3715
  return;
2983
3716
  }
2984
3717
  const args = { socketUrl: __privateGet(this, _socketUrl2) };
2985
- __privateGet(this, _emitter9).emit("socket.connect.pending", { args });
3718
+ __privateGet(this, _emitter12).emit("socket.connect.pending", { args });
2986
3719
  __privateSet(this, _socketIo, io(__privateGet(this, _socketUrl2), {
2987
3720
  reconnectionDelayMax: 1e4,
2988
3721
  transports: ["websocket"],
@@ -2991,10 +3724,10 @@ initializeSocket_fn2 = function() {
2991
3724
  }
2992
3725
  }));
2993
3726
  __privateGet(this, _socketIo).on("connect", () => {
2994
- __privateGet(this, _emitter9).emit("socket.connect.resolved", { args });
3727
+ __privateGet(this, _emitter12).emit("socket.connect.resolved", { args });
2995
3728
  });
2996
3729
  __privateGet(this, _socketIo).on("connect_error", (error) => {
2997
- __privateGet(this, _emitter9).emit("socket.connect.resolved", { args, error });
3730
+ __privateGet(this, _emitter12).emit("socket.connect.resolved", { args, error });
2998
3731
  });
2999
3732
  (_a = __privateGet(this, _socketIo)) == null ? void 0 : _a.on("notification_received" /* RECEIVED */, __privateGet(this, _notificationReceived2));
3000
3733
  (_b = __privateGet(this, _socketIo)) == null ? void 0 : _b.on("unseen_count_changed" /* UNSEEN */, __privateGet(this, _unseenCountChanged2));
@@ -3068,57 +3801,66 @@ function createSocket({
3068
3801
  }
3069
3802
 
3070
3803
  // src/novu.ts
3071
- var _emitter10, _session, _inboxService3;
3804
+ var _emitter13, _session, _inboxService6, _options2;
3072
3805
  var Novu = class {
3073
3806
  constructor(options) {
3074
- __privateAdd(this, _emitter10);
3807
+ __privateAdd(this, _emitter13);
3075
3808
  __privateAdd(this, _session);
3076
- __privateAdd(this, _inboxService3);
3077
- var _a, _b;
3078
- __privateSet(this, _inboxService3, new InboxService({
3809
+ __privateAdd(this, _inboxService6);
3810
+ __privateAdd(this, _options2);
3811
+ var _a, _b, _c;
3812
+ __privateSet(this, _options2, options);
3813
+ __privateSet(this, _inboxService6, new InboxService({
3079
3814
  apiUrl: options.apiUrl || options.backendUrl,
3080
3815
  userAgent: options.__userAgent
3081
3816
  }));
3082
- __privateSet(this, _emitter10, new NovuEventEmitter());
3817
+ __privateSet(this, _emitter13, new NovuEventEmitter());
3818
+ const subscriber = buildSubscriber({ subscriberId: options.subscriberId, subscriber: options.subscriber });
3083
3819
  __privateSet(this, _session, new Session(
3084
3820
  {
3085
3821
  applicationIdentifier: options.applicationIdentifier || "",
3086
3822
  subscriberHash: options.subscriberHash,
3087
- subscriber: buildSubscriber({ subscriberId: options.subscriberId, subscriber: options.subscriber }),
3823
+ subscriber,
3088
3824
  defaultSchedule: options.defaultSchedule,
3089
3825
  context: options.context,
3090
3826
  contextHash: options.contextHash
3091
3827
  },
3092
- __privateGet(this, _inboxService3),
3093
- __privateGet(this, _emitter10)
3828
+ __privateGet(this, _inboxService6),
3829
+ __privateGet(this, _emitter13)
3094
3830
  ));
3095
3831
  __privateGet(this, _session).initialize();
3096
3832
  this.notifications = new Notifications({
3097
3833
  useCache: (_a = options.useCache) != null ? _a : true,
3098
- inboxServiceInstance: __privateGet(this, _inboxService3),
3099
- eventEmitterInstance: __privateGet(this, _emitter10)
3834
+ inboxServiceInstance: __privateGet(this, _inboxService6),
3835
+ eventEmitterInstance: __privateGet(this, _emitter13)
3100
3836
  });
3101
3837
  this.preferences = new Preferences({
3102
3838
  useCache: (_b = options.useCache) != null ? _b : true,
3103
- inboxServiceInstance: __privateGet(this, _inboxService3),
3104
- eventEmitterInstance: __privateGet(this, _emitter10)
3839
+ inboxServiceInstance: __privateGet(this, _inboxService6),
3840
+ eventEmitterInstance: __privateGet(this, _emitter13)
3841
+ });
3842
+ this.subscriptions = new Subscriptions({
3843
+ subscriber,
3844
+ useCache: (_c = options.useCache) != null ? _c : true,
3845
+ inboxServiceInstance: __privateGet(this, _inboxService6),
3846
+ eventEmitterInstance: __privateGet(this, _emitter13)
3105
3847
  });
3106
3848
  this.socket = createSocket({
3107
3849
  socketUrl: options.socketUrl,
3108
- eventEmitterInstance: __privateGet(this, _emitter10),
3109
- inboxServiceInstance: __privateGet(this, _inboxService3)
3850
+ eventEmitterInstance: __privateGet(this, _emitter13),
3851
+ inboxServiceInstance: __privateGet(this, _inboxService6)
3110
3852
  });
3111
3853
  this.on = (eventName, listener) => {
3112
3854
  if (this.socket.isSocketEvent(eventName)) {
3113
3855
  this.socket.connect();
3114
3856
  }
3115
- const cleanup = __privateGet(this, _emitter10).on(eventName, listener);
3857
+ const cleanup = __privateGet(this, _emitter13).on(eventName, listener);
3116
3858
  return () => {
3117
3859
  cleanup();
3118
3860
  };
3119
3861
  };
3120
3862
  this.off = (eventName, listener) => {
3121
- __privateGet(this, _emitter10).off(eventName, listener);
3863
+ __privateGet(this, _emitter13).off(eventName, listener);
3122
3864
  };
3123
3865
  }
3124
3866
  get applicationIdentifier() {
@@ -3130,9 +3872,21 @@ var Novu = class {
3130
3872
  get context() {
3131
3873
  return __privateGet(this, _session).context;
3132
3874
  }
3875
+ get options() {
3876
+ return __privateGet(this, _options2);
3877
+ }
3133
3878
  get contextKey() {
3134
3879
  return buildContextKey(__privateGet(this, _session).context);
3135
3880
  }
3881
+ clearCache() {
3882
+ this.notifications.cache.clearAll();
3883
+ this.preferences.cache.clearAll();
3884
+ this.preferences.scheduleCache.clearAll();
3885
+ this.subscriptions.cache.clearAll();
3886
+ }
3887
+ /**
3888
+ * @deprecated
3889
+ */
3136
3890
  changeSubscriber(options) {
3137
3891
  return __async(this, null, function* () {
3138
3892
  yield __privateGet(this, _session).initialize({
@@ -3143,13 +3897,16 @@ var Novu = class {
3143
3897
  context: __privateGet(this, _session).context,
3144
3898
  contextHash: __privateGet(this, _session).contextHash
3145
3899
  });
3146
- this.notifications.cache.clearAll();
3900
+ this.clearCache();
3147
3901
  const disconnectResult = yield this.socket.disconnect();
3148
3902
  if (!disconnectResult.error) {
3149
3903
  yield this.socket.connect();
3150
3904
  }
3151
3905
  });
3152
3906
  }
3907
+ /**
3908
+ * @deprecated
3909
+ */
3153
3910
  changeContext(options) {
3154
3911
  return __async(this, null, function* () {
3155
3912
  const currentSubscriber = __privateGet(this, _session).subscriber;
@@ -3164,7 +3921,7 @@ var Novu = class {
3164
3921
  context: options.context,
3165
3922
  contextHash: options.contextHash
3166
3923
  });
3167
- this.notifications.cache.clearAll();
3924
+ this.clearCache();
3168
3925
  const disconnectResult = yield this.socket.disconnect();
3169
3926
  if (!disconnectResult.error) {
3170
3927
  yield this.socket.connect();
@@ -3172,8 +3929,9 @@ var Novu = class {
3172
3929
  });
3173
3930
  }
3174
3931
  };
3175
- _emitter10 = new WeakMap();
3932
+ _emitter13 = new WeakMap();
3176
3933
  _session = new WeakMap();
3177
- _inboxService3 = new WeakMap();
3934
+ _inboxService6 = new WeakMap();
3935
+ _options2 = new WeakMap();
3178
3936
 
3179
- export { ChannelType, DEFAULT_API_VERSION, NotificationStatus, Novu, PreferenceLevel, SeverityLevelEnum, WebSocketEvent, WorkflowCriticalityEnum, areSeveritiesEqual, areTagsEqual, checkNotificationDataFilter, checkNotificationMatchesFilter, checkNotificationTagFilter, isBrowser, isSameFilter };
3937
+ export { ChannelType, DEFAULT_API_VERSION, NotificationStatus, Novu, NovuError, PreferenceLevel, SeverityLevelEnum, SubscriptionPreference, TopicSubscription, WebSocketEvent, WorkflowCriticalityEnum, areSeveritiesEqual, areTagsEqual, checkNotificationDataFilter, checkNotificationMatchesFilter, checkNotificationTagFilter, isBrowser, isSameFilter };