@novu/js 3.9.3 → 3.10.0

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.
@@ -148,7 +148,7 @@ function checkNotificationMatchesFilter(notification, filter) {
148
148
 
149
149
  // src/api/http-client.ts
150
150
  var DEFAULT_API_VERSION = "v1";
151
- var DEFAULT_USER_AGENT = `${"@novu/js"}@${"3.9.3"}`;
151
+ var DEFAULT_USER_AGENT = `${"@novu/js"}@${"3.10.0"}`;
152
152
  var HttpClient = class {
153
153
  constructor(options = {}) {
154
154
  // Environment variable for local development that overrides the default API endpoint without affecting the Inbox DX
@@ -276,12 +276,14 @@ var InboxService = class {
276
276
  return chunk7B52C2XE_js.__async(this, arguments, function* ({
277
277
  applicationIdentifier,
278
278
  subscriberHash,
279
- subscriber
279
+ subscriber,
280
+ defaultSchedule
280
281
  }) {
281
282
  const response = yield chunk7B52C2XE_js.__privateGet(this, _httpClient).post(`${INBOX_ROUTE}/session`, {
282
283
  applicationIdentifier,
283
284
  subscriberHash,
284
- subscriber
285
+ subscriber,
286
+ defaultSchedule
285
287
  });
286
288
  chunk7B52C2XE_js.__privateGet(this, _httpClient).setAuthorizationToken(response.token);
287
289
  chunk7B52C2XE_js.__privateGet(this, _httpClient).setKeylessHeader(response.applicationIdentifier);
@@ -384,6 +386,15 @@ var InboxService = class {
384
386
  data: data ? JSON.stringify(data) : void 0
385
387
  });
386
388
  }
389
+ delete(notificationId) {
390
+ return chunk7B52C2XE_js.__privateGet(this, _httpClient).delete(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/delete`);
391
+ }
392
+ deleteAll({ tags, data }) {
393
+ return chunk7B52C2XE_js.__privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/delete`, {
394
+ tags,
395
+ data: data ? JSON.stringify(data) : void 0
396
+ });
397
+ }
387
398
  markAsSeen({
388
399
  notificationIds,
389
400
  tags,
@@ -441,8 +452,8 @@ var InboxService = class {
441
452
  bulkUpdatePreferences(preferences) {
442
453
  return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/bulk`, { preferences });
443
454
  }
444
- updateGlobalPreferences(channels) {
445
- return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences`, channels);
455
+ updateGlobalPreferences(preferences) {
456
+ return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences`, preferences);
446
457
  }
447
458
  updateWorkflowPreferences({
448
459
  workflowId,
@@ -450,6 +461,9 @@ var InboxService = class {
450
461
  }) {
451
462
  return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/${workflowId}`, channels);
452
463
  }
464
+ fetchGlobalPreferences() {
465
+ return chunk7B52C2XE_js.__privateGet(this, _httpClient).get(`${INBOX_ROUTE}/preferences/global`);
466
+ }
453
467
  triggerHelloWorldEvent() {
454
468
  const payload = {
455
469
  name: "hello-world",
@@ -922,6 +936,49 @@ var archiveAllRead = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
922
936
  return { error: new NovuError("Failed to archive all read notifications", error) };
923
937
  }
924
938
  });
939
+ var deleteNotification = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
940
+ emitter,
941
+ apiService,
942
+ args
943
+ }) {
944
+ const { notificationId } = getNotificationDetails(
945
+ args,
946
+ {},
947
+ {
948
+ emitter,
949
+ apiService
950
+ }
951
+ );
952
+ try {
953
+ emitter.emit("notification.delete.pending", {
954
+ args
955
+ });
956
+ yield apiService.delete(notificationId);
957
+ emitter.emit("notification.delete.resolved", { args });
958
+ return {};
959
+ } catch (error) {
960
+ emitter.emit("notification.delete.resolved", { args, error });
961
+ return { error: new NovuError("Failed to delete notification", error) };
962
+ }
963
+ });
964
+ var deleteAll = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
965
+ emitter,
966
+ inboxService,
967
+ notificationsCache,
968
+ tags,
969
+ data
970
+ }) {
971
+ try {
972
+ const notifications = notificationsCache.getUniqueNotifications({ tags, data });
973
+ emitter.emit("notifications.delete_all.pending", { args: { tags, data }, data: notifications });
974
+ yield inboxService.deleteAll({ tags, data });
975
+ emitter.emit("notifications.delete_all.resolved", { args: { tags, data } });
976
+ return {};
977
+ } catch (error) {
978
+ emitter.emit("notifications.delete_all.resolved", { args: { tags, data }, error });
979
+ return { error: new NovuError("Failed to delete all notifications", error) };
980
+ }
981
+ });
925
982
 
926
983
  // src/notifications/notification.ts
927
984
  var _emitter, _inboxService;
@@ -1001,6 +1058,15 @@ var Notification = class {
1001
1058
  }
1002
1059
  });
1003
1060
  }
1061
+ delete() {
1062
+ return deleteNotification({
1063
+ emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
1064
+ apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
1065
+ args: {
1066
+ notification: this
1067
+ }
1068
+ });
1069
+ }
1004
1070
  snooze(snoozeUntil) {
1005
1071
  return snooze({
1006
1072
  emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
@@ -1230,8 +1296,10 @@ var removeEvents = [
1230
1296
  "notification.unarchive.pending",
1231
1297
  "notification.snooze.pending",
1232
1298
  "notification.unsnooze.pending",
1299
+ "notification.delete.pending",
1233
1300
  "notifications.archive_all.pending",
1234
- "notifications.archive_all_read.pending"
1301
+ "notifications.archive_all_read.pending",
1302
+ "notifications.delete_all.pending"
1235
1303
  ];
1236
1304
  var _emitter2, _cache2;
1237
1305
  var NotificationsCache = class {
@@ -1271,11 +1339,35 @@ var NotificationsCache = class {
1271
1339
  }));
1272
1340
  return true;
1273
1341
  };
1274
- this.handleNotificationEvent = ({ remove } = { remove: false }) => ({ data }) => {
1275
- if (!data) {
1342
+ this.handleNotificationEvent = ({ remove } = { remove: false }) => (event) => {
1343
+ const { data, args } = event;
1344
+ let notifications = [];
1345
+ if (data !== void 0 && data !== null) {
1346
+ if (Array.isArray(data) && data.every((item) => typeof item === "object" && "id" in item)) {
1347
+ notifications = data;
1348
+ } else if (typeof data === "object" && "id" in data) {
1349
+ notifications = [data];
1350
+ }
1351
+ } else if (remove && args) {
1352
+ if ("notification" in args && args.notification) {
1353
+ notifications = [args.notification];
1354
+ } else if ("notificationId" in args && args.notificationId) {
1355
+ const foundNotifications = [];
1356
+ chunk7B52C2XE_js.__privateGet(this, _cache2).keys().forEach((key) => {
1357
+ const cachedResponse = chunk7B52C2XE_js.__privateGet(this, _cache2).get(key);
1358
+ if (cachedResponse) {
1359
+ const found = cachedResponse.notifications.find((n) => n.id === args.notificationId);
1360
+ if (found) {
1361
+ foundNotifications.push(found);
1362
+ }
1363
+ }
1364
+ });
1365
+ notifications = foundNotifications;
1366
+ }
1367
+ }
1368
+ if (notifications.length === 0) {
1276
1369
  return;
1277
1370
  }
1278
- const notifications = Array.isArray(data) ? data : [data];
1279
1371
  const uniqueFilterKeys = /* @__PURE__ */ new Set();
1280
1372
  chunk7B52C2XE_js.__privateGet(this, _cache2).keys().forEach((key) => {
1281
1373
  notifications.forEach((notification) => {
@@ -1531,6 +1623,19 @@ var Notifications = class extends BaseModule {
1531
1623
  );
1532
1624
  });
1533
1625
  }
1626
+ delete(args) {
1627
+ return chunk7B52C2XE_js.__async(this, null, function* () {
1628
+ return this.callWithSession(
1629
+ () => chunk7B52C2XE_js.__async(this, null, function* () {
1630
+ return deleteNotification({
1631
+ emitter: this._emitter,
1632
+ apiService: this._inboxService,
1633
+ args
1634
+ });
1635
+ })
1636
+ );
1637
+ });
1638
+ }
1534
1639
  snooze(args) {
1535
1640
  return chunk7B52C2XE_js.__async(this, null, function* () {
1536
1641
  return this.callWithSession(
@@ -1686,11 +1791,30 @@ var Notifications = class extends BaseModule {
1686
1791
  );
1687
1792
  });
1688
1793
  }
1794
+ deleteAll() {
1795
+ return chunk7B52C2XE_js.__async(this, arguments, function* ({
1796
+ tags,
1797
+ data
1798
+ } = {}) {
1799
+ return this.callWithSession(
1800
+ () => chunk7B52C2XE_js.__async(this, null, function* () {
1801
+ return deleteAll({
1802
+ emitter: this._emitter,
1803
+ inboxService: this._inboxService,
1804
+ notificationsCache: this.cache,
1805
+ tags,
1806
+ data
1807
+ });
1808
+ })
1809
+ );
1810
+ });
1811
+ }
1689
1812
  clearCache({ filter } = {}) {
1690
1813
  if (filter) {
1691
- return this.cache.clear(filter != null ? filter : {});
1814
+ this.cache.clear(filter != null ? filter : {});
1815
+ return;
1692
1816
  }
1693
- return this.cache.clearAll();
1817
+ this.cache.clearAll();
1694
1818
  }
1695
1819
  triggerHelloWorldEvent() {
1696
1820
  return chunk7B52C2XE_js.__async(this, null, function* () {
@@ -1700,115 +1824,77 @@ var Notifications = class extends BaseModule {
1700
1824
  };
1701
1825
  _useCache = new WeakMap();
1702
1826
 
1703
- // src/cache/preferences-cache.ts
1704
- var updateEvents2 = [
1705
- "preference.update.pending",
1706
- "preference.update.resolved",
1707
- "preferences.bulk_update.pending",
1708
- "preferences.bulk_update.resolved"
1709
- ];
1710
- var excludeEmpty2 = ({ tags, severity }) => Object.entries({ tags, severity }).reduce((acc, [key, value]) => {
1711
- if (value === null || value === void 0 || Array.isArray(value) && value.length === 0) {
1712
- return acc;
1713
- }
1714
- acc[key] = value;
1715
- return acc;
1716
- }, {});
1717
- var getCacheKey2 = ({ tags, severity }) => {
1718
- return JSON.stringify(excludeEmpty2({ tags, severity }));
1719
- };
1720
- var _emitter3, _cache3;
1721
- var PreferencesCache = class {
1722
- constructor({ emitterInstance }) {
1827
+ // src/preferences/schedule.ts
1828
+ var _emitter3, _apiService, _cache3, _useCache2;
1829
+ var Schedule = class {
1830
+ constructor(schedule, {
1831
+ emitterInstance,
1832
+ inboxServiceInstance,
1833
+ cache,
1834
+ useCache
1835
+ }) {
1723
1836
  chunk7B52C2XE_js.__privateAdd(this, _emitter3);
1837
+ chunk7B52C2XE_js.__privateAdd(this, _apiService);
1724
1838
  chunk7B52C2XE_js.__privateAdd(this, _cache3);
1725
- this.updatePreference = (key, data) => {
1726
- const preferences = chunk7B52C2XE_js.__privateGet(this, _cache3).get(key);
1727
- if (!preferences) {
1728
- return false;
1729
- }
1730
- const index = preferences.findIndex(
1731
- (el) => {
1732
- var _a, _b;
1733
- return ((_a = el.workflow) == null ? void 0 : _a.id) === ((_b = data.workflow) == null ? void 0 : _b.id) || el.level === data.level && data.level === "global" /* GLOBAL */;
1734
- }
1735
- );
1736
- if (index === -1) {
1737
- return false;
1738
- }
1739
- const updatedPreferences = [...preferences];
1740
- updatedPreferences[index] = data;
1741
- chunk7B52C2XE_js.__privateGet(this, _cache3).set(key, updatedPreferences);
1742
- return true;
1743
- };
1744
- this.handlePreferenceEvent = ({ data }) => {
1745
- if (!data) {
1746
- return;
1747
- }
1748
- const preferences = Array.isArray(data) ? data : [data];
1749
- const uniqueFilterKeys = /* @__PURE__ */ new Set();
1750
- chunk7B52C2XE_js.__privateGet(this, _cache3).keys().forEach((key) => {
1751
- preferences.forEach((preference) => {
1752
- const hasUpdatedPreference = this.updatePreference(key, preference);
1753
- const updatedPreference = chunk7B52C2XE_js.__privateGet(this, _cache3).get(key);
1754
- if (!hasUpdatedPreference || !updatedPreference) {
1755
- return;
1756
- }
1757
- uniqueFilterKeys.add(key);
1758
- });
1759
- });
1760
- uniqueFilterKeys.forEach((key) => {
1761
- var _a;
1762
- chunk7B52C2XE_js.__privateGet(this, _emitter3).emit("preferences.list.updated", {
1763
- data: (_a = chunk7B52C2XE_js.__privateGet(this, _cache3).get(key)) != null ? _a : []
1764
- });
1765
- });
1766
- };
1839
+ chunk7B52C2XE_js.__privateAdd(this, _useCache2);
1767
1840
  chunk7B52C2XE_js.__privateSet(this, _emitter3, emitterInstance);
1768
- updateEvents2.forEach((event) => {
1769
- chunk7B52C2XE_js.__privateGet(this, _emitter3).on(event, this.handlePreferenceEvent);
1770
- });
1771
- chunk7B52C2XE_js.__privateSet(this, _cache3, new InMemoryCache());
1772
- }
1773
- has(args) {
1774
- return chunk7B52C2XE_js.__privateGet(this, _cache3).get(getCacheKey2(args)) !== void 0;
1775
- }
1776
- set(args, data) {
1777
- chunk7B52C2XE_js.__privateGet(this, _cache3).set(getCacheKey2(args), data);
1778
- }
1779
- getAll(args) {
1780
- if (this.has(args)) {
1781
- return chunk7B52C2XE_js.__privateGet(this, _cache3).get(getCacheKey2(args));
1782
- }
1841
+ chunk7B52C2XE_js.__privateSet(this, _apiService, inboxServiceInstance);
1842
+ chunk7B52C2XE_js.__privateSet(this, _cache3, cache);
1843
+ chunk7B52C2XE_js.__privateSet(this, _useCache2, useCache);
1844
+ this.isEnabled = schedule.isEnabled;
1845
+ this.weeklySchedule = schedule.weeklySchedule;
1783
1846
  }
1784
- clearAll() {
1785
- chunk7B52C2XE_js.__privateGet(this, _cache3).clear();
1847
+ update(args) {
1848
+ return chunk7B52C2XE_js.__async(this, null, function* () {
1849
+ var _a;
1850
+ const hasWeeklySchedule = !!args.weeklySchedule || !!this.weeklySchedule;
1851
+ return updateSchedule({
1852
+ emitter: chunk7B52C2XE_js.__privateGet(this, _emitter3),
1853
+ apiService: chunk7B52C2XE_js.__privateGet(this, _apiService),
1854
+ cache: chunk7B52C2XE_js.__privateGet(this, _cache3),
1855
+ useCache: chunk7B52C2XE_js.__privateGet(this, _useCache2),
1856
+ args: chunk7B52C2XE_js.__spreadValues({
1857
+ isEnabled: (_a = args.isEnabled) != null ? _a : this.isEnabled
1858
+ }, hasWeeklySchedule && {
1859
+ weeklySchedule: chunk7B52C2XE_js.__spreadValues(chunk7B52C2XE_js.__spreadValues({}, this.weeklySchedule), args.weeklySchedule)
1860
+ })
1861
+ });
1862
+ });
1786
1863
  }
1787
1864
  };
1788
1865
  _emitter3 = new WeakMap();
1866
+ _apiService = new WeakMap();
1789
1867
  _cache3 = new WeakMap();
1868
+ _useCache2 = new WeakMap();
1790
1869
 
1791
1870
  // src/preferences/preference.ts
1792
- var _emitter4, _apiService, _cache4, _useCache2;
1871
+ var _emitter4, _apiService2, _cache4, _scheduleCache, _useCache3;
1793
1872
  var Preference = class {
1794
1873
  constructor(preference, {
1795
1874
  emitterInstance,
1796
1875
  inboxServiceInstance,
1797
1876
  cache,
1877
+ scheduleCache,
1798
1878
  useCache
1799
1879
  }) {
1800
1880
  chunk7B52C2XE_js.__privateAdd(this, _emitter4);
1801
- chunk7B52C2XE_js.__privateAdd(this, _apiService);
1881
+ chunk7B52C2XE_js.__privateAdd(this, _apiService2);
1802
1882
  chunk7B52C2XE_js.__privateAdd(this, _cache4);
1803
- chunk7B52C2XE_js.__privateAdd(this, _useCache2);
1883
+ chunk7B52C2XE_js.__privateAdd(this, _scheduleCache);
1884
+ chunk7B52C2XE_js.__privateAdd(this, _useCache3);
1804
1885
  chunk7B52C2XE_js.__privateSet(this, _emitter4, emitterInstance);
1805
- chunk7B52C2XE_js.__privateSet(this, _apiService, inboxServiceInstance);
1886
+ chunk7B52C2XE_js.__privateSet(this, _apiService2, inboxServiceInstance);
1806
1887
  chunk7B52C2XE_js.__privateSet(this, _cache4, cache);
1807
- chunk7B52C2XE_js.__privateSet(this, _useCache2, useCache);
1888
+ chunk7B52C2XE_js.__privateSet(this, _scheduleCache, scheduleCache);
1889
+ chunk7B52C2XE_js.__privateSet(this, _useCache3, useCache);
1808
1890
  this.level = preference.level;
1809
1891
  this.enabled = preference.enabled;
1810
1892
  this.channels = preference.channels;
1811
1893
  this.workflow = preference.workflow;
1894
+ this.schedule = new Schedule(
1895
+ chunk7B52C2XE_js.__spreadValues({}, preference.schedule),
1896
+ { emitterInstance, inboxServiceInstance, cache: scheduleCache, useCache }
1897
+ );
1812
1898
  }
1813
1899
  update({
1814
1900
  channels,
@@ -1817,9 +1903,10 @@ var Preference = class {
1817
1903
  var _a;
1818
1904
  return updatePreference({
1819
1905
  emitter: chunk7B52C2XE_js.__privateGet(this, _emitter4),
1820
- apiService: chunk7B52C2XE_js.__privateGet(this, _apiService),
1906
+ apiService: chunk7B52C2XE_js.__privateGet(this, _apiService2),
1821
1907
  cache: chunk7B52C2XE_js.__privateGet(this, _cache4),
1822
- useCache: chunk7B52C2XE_js.__privateGet(this, _useCache2),
1908
+ scheduleCache: chunk7B52C2XE_js.__privateGet(this, _scheduleCache),
1909
+ useCache: chunk7B52C2XE_js.__privateGet(this, _useCache3),
1823
1910
  args: {
1824
1911
  workflowId: (_a = this.workflow) == null ? void 0 : _a.id,
1825
1912
  channels: channels || channelPreferences,
@@ -1829,15 +1916,17 @@ var Preference = class {
1829
1916
  }
1830
1917
  };
1831
1918
  _emitter4 = new WeakMap();
1832
- _apiService = new WeakMap();
1919
+ _apiService2 = new WeakMap();
1833
1920
  _cache4 = new WeakMap();
1834
- _useCache2 = new WeakMap();
1921
+ _scheduleCache = new WeakMap();
1922
+ _useCache3 = new WeakMap();
1835
1923
 
1836
1924
  // src/preferences/helpers.ts
1837
1925
  var updatePreference = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
1838
1926
  emitter,
1839
1927
  apiService,
1840
1928
  cache,
1929
+ scheduleCache,
1841
1930
  useCache,
1842
1931
  args
1843
1932
  }) {
@@ -1855,6 +1944,7 @@ var updatePreference = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function*
1855
1944
  emitterInstance: emitter,
1856
1945
  inboxServiceInstance: apiService,
1857
1946
  cache,
1947
+ scheduleCache,
1858
1948
  useCache
1859
1949
  }
1860
1950
  ) : void 0
@@ -1863,13 +1953,14 @@ var updatePreference = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function*
1863
1953
  if (workflowId) {
1864
1954
  response = yield apiService.updateWorkflowPreferences({ workflowId, channels });
1865
1955
  } else {
1866
- optimisticUpdateWorkflowPreferences({ emitter, apiService, cache, useCache, args });
1956
+ optimisticUpdateWorkflowPreferences({ emitter, apiService, cache, scheduleCache, useCache, args });
1867
1957
  response = yield apiService.updateGlobalPreferences(channels);
1868
1958
  }
1869
1959
  const preference = new Preference(response, {
1870
1960
  emitterInstance: emitter,
1871
1961
  inboxServiceInstance: apiService,
1872
1962
  cache,
1963
+ scheduleCache,
1873
1964
  useCache
1874
1965
  });
1875
1966
  emitter.emit("preference.update.resolved", { args, data: preference });
@@ -1883,6 +1974,7 @@ var bulkUpdatePreference = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], functi
1883
1974
  emitter,
1884
1975
  apiService,
1885
1976
  cache,
1977
+ scheduleCache,
1886
1978
  useCache,
1887
1979
  args
1888
1980
  }) {
@@ -1900,6 +1992,7 @@ var bulkUpdatePreference = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], functi
1900
1992
  emitterInstance: emitter,
1901
1993
  inboxServiceInstance: apiService,
1902
1994
  cache,
1995
+ scheduleCache,
1903
1996
  useCache
1904
1997
  }
1905
1998
  ) : void 0
@@ -1920,6 +2013,7 @@ var bulkUpdatePreference = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], functi
1920
2013
  emitterInstance: emitter,
1921
2014
  inboxServiceInstance: apiService,
1922
2015
  cache,
2016
+ scheduleCache,
1923
2017
  useCache
1924
2018
  })
1925
2019
  );
@@ -1934,6 +2028,7 @@ var optimisticUpdateWorkflowPreferences = ({
1934
2028
  emitter,
1935
2029
  apiService,
1936
2030
  cache,
2031
+ scheduleCache,
1937
2032
  useCache,
1938
2033
  args
1939
2034
  }) => {
@@ -1953,6 +2048,7 @@ var optimisticUpdateWorkflowPreferences = ({
1953
2048
  emitterInstance: emitter,
1954
2049
  inboxServiceInstance: apiService,
1955
2050
  cache,
2051
+ scheduleCache,
1956
2052
  useCache
1957
2053
  }) : void 0;
1958
2054
  if (updatedPreference) {
@@ -1967,9 +2063,326 @@ var optimisticUpdateWorkflowPreferences = ({
1967
2063
  }
1968
2064
  });
1969
2065
  };
2066
+ var updateSchedule = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
2067
+ emitter,
2068
+ apiService,
2069
+ cache,
2070
+ useCache,
2071
+ args
2072
+ }) {
2073
+ var _a, _b;
2074
+ try {
2075
+ const { isEnabled, weeklySchedule } = args;
2076
+ const optimisticallyUpdatedSchedule = new Schedule(
2077
+ {
2078
+ isEnabled,
2079
+ weeklySchedule
2080
+ },
2081
+ {
2082
+ emitterInstance: emitter,
2083
+ inboxServiceInstance: apiService,
2084
+ cache,
2085
+ useCache
2086
+ }
2087
+ );
2088
+ emitter.emit("preference.schedule.update.pending", { args, data: optimisticallyUpdatedSchedule });
2089
+ const response = yield apiService.updateGlobalPreferences({
2090
+ schedule: {
2091
+ isEnabled,
2092
+ weeklySchedule
2093
+ }
2094
+ });
2095
+ const updatedSchedule = new Schedule(
2096
+ {
2097
+ isEnabled: (_a = response.schedule) == null ? void 0 : _a.isEnabled,
2098
+ weeklySchedule: (_b = response.schedule) == null ? void 0 : _b.weeklySchedule
2099
+ },
2100
+ {
2101
+ emitterInstance: emitter,
2102
+ inboxServiceInstance: apiService,
2103
+ cache,
2104
+ useCache
2105
+ }
2106
+ );
2107
+ emitter.emit("preference.schedule.update.resolved", {
2108
+ args,
2109
+ data: updatedSchedule
2110
+ });
2111
+ return { data: updatedSchedule };
2112
+ } catch (error) {
2113
+ emitter.emit("preference.schedule.update.resolved", { args, error });
2114
+ return { error: new NovuError("Failed to update preference", error) };
2115
+ }
2116
+ });
2117
+
2118
+ // src/preferences/preference-schedule.ts
2119
+ var _useCache4;
2120
+ var PreferenceSchedule = class extends BaseModule {
2121
+ constructor({
2122
+ cache,
2123
+ useCache,
2124
+ inboxServiceInstance,
2125
+ eventEmitterInstance
2126
+ }) {
2127
+ super({
2128
+ eventEmitterInstance,
2129
+ inboxServiceInstance
2130
+ });
2131
+ chunk7B52C2XE_js.__privateAdd(this, _useCache4);
2132
+ this.cache = cache;
2133
+ chunk7B52C2XE_js.__privateSet(this, _useCache4, useCache);
2134
+ }
2135
+ get() {
2136
+ return chunk7B52C2XE_js.__async(this, null, function* () {
2137
+ return this.callWithSession(() => chunk7B52C2XE_js.__async(this, null, function* () {
2138
+ var _a, _b;
2139
+ try {
2140
+ let data = chunk7B52C2XE_js.__privateGet(this, _useCache4) ? this.cache.getAll() : void 0;
2141
+ this._emitter.emit("preference.schedule.get.pending", { args: void 0, data });
2142
+ if (!data) {
2143
+ const globalPreference = yield this._inboxService.fetchGlobalPreferences();
2144
+ data = new Schedule(
2145
+ {
2146
+ isEnabled: (_a = globalPreference == null ? void 0 : globalPreference.schedule) == null ? void 0 : _a.isEnabled,
2147
+ weeklySchedule: (_b = globalPreference == null ? void 0 : globalPreference.schedule) == null ? void 0 : _b.weeklySchedule
2148
+ },
2149
+ {
2150
+ emitterInstance: this._emitter,
2151
+ inboxServiceInstance: this._inboxService,
2152
+ cache: this.cache,
2153
+ useCache: chunk7B52C2XE_js.__privateGet(this, _useCache4)
2154
+ }
2155
+ );
2156
+ if (chunk7B52C2XE_js.__privateGet(this, _useCache4)) {
2157
+ this.cache.set(data);
2158
+ data = this.cache.getAll();
2159
+ }
2160
+ }
2161
+ this._emitter.emit("preference.schedule.get.resolved", {
2162
+ args: void 0,
2163
+ data
2164
+ });
2165
+ return { data };
2166
+ } catch (error) {
2167
+ this._emitter.emit("preference.schedule.get.resolved", { args: void 0, error });
2168
+ throw error;
2169
+ }
2170
+ }));
2171
+ });
2172
+ }
2173
+ update(args) {
2174
+ return chunk7B52C2XE_js.__async(this, null, function* () {
2175
+ return this.callWithSession(
2176
+ () => updateSchedule({
2177
+ emitter: this._emitter,
2178
+ apiService: this._inboxService,
2179
+ cache: this.cache,
2180
+ useCache: chunk7B52C2XE_js.__privateGet(this, _useCache4),
2181
+ args
2182
+ })
2183
+ );
2184
+ });
2185
+ }
2186
+ };
2187
+ _useCache4 = new WeakMap();
2188
+
2189
+ // src/cache/preferences-cache.ts
2190
+ var updateEvents2 = [
2191
+ "preference.update.pending",
2192
+ "preference.update.resolved",
2193
+ "preferences.bulk_update.pending",
2194
+ "preferences.bulk_update.resolved"
2195
+ ];
2196
+ var scheduleUpdateEvents = [
2197
+ "preference.schedule.update.pending",
2198
+ "preference.schedule.update.resolved"
2199
+ ];
2200
+ var excludeEmpty2 = ({ tags, severity }) => Object.entries({ tags, severity }).reduce((acc, [key, value]) => {
2201
+ if (value === null || value === void 0 || Array.isArray(value) && value.length === 0) {
2202
+ return acc;
2203
+ }
2204
+ acc[key] = value;
2205
+ return acc;
2206
+ }, {});
2207
+ var getCacheKey2 = ({ tags, severity }) => {
2208
+ return JSON.stringify(excludeEmpty2({ tags, severity }));
2209
+ };
2210
+ var _emitter5, _cache5;
2211
+ var PreferencesCache = class {
2212
+ constructor({ emitterInstance }) {
2213
+ chunk7B52C2XE_js.__privateAdd(this, _emitter5);
2214
+ chunk7B52C2XE_js.__privateAdd(this, _cache5);
2215
+ this.updatePreference = (key, data) => {
2216
+ const preferences = chunk7B52C2XE_js.__privateGet(this, _cache5).get(key);
2217
+ if (!preferences) {
2218
+ return false;
2219
+ }
2220
+ const index = preferences.findIndex(
2221
+ (el) => {
2222
+ var _a, _b;
2223
+ return ((_a = el.workflow) == null ? void 0 : _a.id) === ((_b = data.workflow) == null ? void 0 : _b.id) || el.level === data.level && data.level === "global" /* GLOBAL */;
2224
+ }
2225
+ );
2226
+ if (index === -1) {
2227
+ return false;
2228
+ }
2229
+ const updatedPreferences = [...preferences];
2230
+ updatedPreferences[index] = data;
2231
+ chunk7B52C2XE_js.__privateGet(this, _cache5).set(key, updatedPreferences);
2232
+ return true;
2233
+ };
2234
+ this.updatePreferenceSchedule = (key, data) => {
2235
+ const preferences = chunk7B52C2XE_js.__privateGet(this, _cache5).get(key);
2236
+ if (!preferences) {
2237
+ return false;
2238
+ }
2239
+ const index = preferences.findIndex((el) => el.level === "global" /* GLOBAL */);
2240
+ if (index === -1) {
2241
+ return false;
2242
+ }
2243
+ const updatedPreferences = [...preferences];
2244
+ updatedPreferences[index].schedule = data;
2245
+ chunk7B52C2XE_js.__privateGet(this, _cache5).set(key, updatedPreferences);
2246
+ return true;
2247
+ };
2248
+ this.handleScheduleEvent = ({ data }) => {
2249
+ var _a;
2250
+ if (!data) {
2251
+ return;
2252
+ }
2253
+ const cacheKeys = chunk7B52C2XE_js.__privateGet(this, _cache5).keys();
2254
+ const uniqueFilterKeys = /* @__PURE__ */ new Set();
2255
+ for (const key of cacheKeys) {
2256
+ const hasUpdatedPreference = this.updatePreferenceSchedule(key, data);
2257
+ const updatedPreference = chunk7B52C2XE_js.__privateGet(this, _cache5).get(key);
2258
+ if (!hasUpdatedPreference || !updatedPreference) {
2259
+ continue;
2260
+ }
2261
+ uniqueFilterKeys.add(key);
2262
+ }
2263
+ for (const key of uniqueFilterKeys) {
2264
+ chunk7B52C2XE_js.__privateGet(this, _emitter5).emit("preferences.list.updated", {
2265
+ data: (_a = chunk7B52C2XE_js.__privateGet(this, _cache5).get(key)) != null ? _a : []
2266
+ });
2267
+ }
2268
+ };
2269
+ this.handlePreferenceEvent = ({ data }) => {
2270
+ if (!data) {
2271
+ return;
2272
+ }
2273
+ const preferences = Array.isArray(data) ? data : [data];
2274
+ const uniqueFilterKeys = /* @__PURE__ */ new Set();
2275
+ chunk7B52C2XE_js.__privateGet(this, _cache5).keys().forEach((key) => {
2276
+ preferences.forEach((preference) => {
2277
+ const hasUpdatedPreference = this.updatePreference(key, preference);
2278
+ const updatedPreference = chunk7B52C2XE_js.__privateGet(this, _cache5).get(key);
2279
+ if (!hasUpdatedPreference || !updatedPreference) {
2280
+ return;
2281
+ }
2282
+ uniqueFilterKeys.add(key);
2283
+ });
2284
+ });
2285
+ uniqueFilterKeys.forEach((key) => {
2286
+ var _a;
2287
+ chunk7B52C2XE_js.__privateGet(this, _emitter5).emit("preferences.list.updated", {
2288
+ data: (_a = chunk7B52C2XE_js.__privateGet(this, _cache5).get(key)) != null ? _a : []
2289
+ });
2290
+ });
2291
+ };
2292
+ chunk7B52C2XE_js.__privateSet(this, _emitter5, emitterInstance);
2293
+ for (const event of updateEvents2) {
2294
+ chunk7B52C2XE_js.__privateGet(this, _emitter5).on(event, this.handlePreferenceEvent);
2295
+ }
2296
+ for (const event of scheduleUpdateEvents) {
2297
+ chunk7B52C2XE_js.__privateGet(this, _emitter5).on(event, this.handleScheduleEvent);
2298
+ }
2299
+ chunk7B52C2XE_js.__privateSet(this, _cache5, new InMemoryCache());
2300
+ }
2301
+ has(args) {
2302
+ return chunk7B52C2XE_js.__privateGet(this, _cache5).get(getCacheKey2(args)) !== void 0;
2303
+ }
2304
+ set(args, data) {
2305
+ chunk7B52C2XE_js.__privateGet(this, _cache5).set(getCacheKey2(args), data);
2306
+ }
2307
+ getAll(args) {
2308
+ if (this.has(args)) {
2309
+ return chunk7B52C2XE_js.__privateGet(this, _cache5).get(getCacheKey2(args));
2310
+ }
2311
+ }
2312
+ clearAll() {
2313
+ chunk7B52C2XE_js.__privateGet(this, _cache5).clear();
2314
+ }
2315
+ };
2316
+ _emitter5 = new WeakMap();
2317
+ _cache5 = new WeakMap();
2318
+
2319
+ // src/cache/schedule-cache.ts
2320
+ var updateEvents3 = [
2321
+ "preference.schedule.update.pending",
2322
+ "preference.schedule.update.resolved"
2323
+ ];
2324
+ var getCacheKey3 = () => {
2325
+ return "schedule";
2326
+ };
2327
+ var _emitter6, _cache6;
2328
+ var ScheduleCache = class {
2329
+ constructor({ emitterInstance }) {
2330
+ chunk7B52C2XE_js.__privateAdd(this, _emitter6);
2331
+ chunk7B52C2XE_js.__privateAdd(this, _cache6);
2332
+ this.updateScheduleInCache = (key, data) => {
2333
+ const schedule = chunk7B52C2XE_js.__privateGet(this, _cache6).get(key);
2334
+ if (!schedule) {
2335
+ return false;
2336
+ }
2337
+ chunk7B52C2XE_js.__privateGet(this, _cache6).set(key, data);
2338
+ return true;
2339
+ };
2340
+ this.handleScheduleEvent = ({ data }) => {
2341
+ if (!data) {
2342
+ return;
2343
+ }
2344
+ const uniqueFilterKeys = /* @__PURE__ */ new Set();
2345
+ const keys = chunk7B52C2XE_js.__privateGet(this, _cache6).keys();
2346
+ for (const key of keys) {
2347
+ const hasUpdatedSchedule = this.updateScheduleInCache(key, data);
2348
+ const updatedSchedule = chunk7B52C2XE_js.__privateGet(this, _cache6).get(key);
2349
+ if (!hasUpdatedSchedule || !updatedSchedule) {
2350
+ continue;
2351
+ }
2352
+ uniqueFilterKeys.add(key);
2353
+ }
2354
+ for (const key of uniqueFilterKeys) {
2355
+ chunk7B52C2XE_js.__privateGet(this, _emitter6).emit("preference.schedule.get.updated", {
2356
+ data: chunk7B52C2XE_js.__privateGet(this, _cache6).get(key)
2357
+ });
2358
+ }
2359
+ };
2360
+ chunk7B52C2XE_js.__privateSet(this, _emitter6, emitterInstance);
2361
+ for (const event of updateEvents3) {
2362
+ chunk7B52C2XE_js.__privateGet(this, _emitter6).on(event, this.handleScheduleEvent);
2363
+ }
2364
+ chunk7B52C2XE_js.__privateSet(this, _cache6, new InMemoryCache());
2365
+ }
2366
+ has() {
2367
+ return chunk7B52C2XE_js.__privateGet(this, _cache6).get(getCacheKey3()) !== void 0;
2368
+ }
2369
+ set(data) {
2370
+ chunk7B52C2XE_js.__privateGet(this, _cache6).set(getCacheKey3(), data);
2371
+ }
2372
+ getAll() {
2373
+ if (this.has()) {
2374
+ return chunk7B52C2XE_js.__privateGet(this, _cache6).get(getCacheKey3());
2375
+ }
2376
+ }
2377
+ clearAll() {
2378
+ chunk7B52C2XE_js.__privateGet(this, _cache6).clear();
2379
+ }
2380
+ };
2381
+ _emitter6 = new WeakMap();
2382
+ _cache6 = new WeakMap();
1970
2383
 
1971
2384
  // src/preferences/preferences.ts
1972
- var _useCache3;
2385
+ var _useCache5;
1973
2386
  var Preferences = class extends BaseModule {
1974
2387
  constructor({
1975
2388
  useCache,
@@ -1980,18 +2393,27 @@ var Preferences = class extends BaseModule {
1980
2393
  eventEmitterInstance,
1981
2394
  inboxServiceInstance
1982
2395
  });
1983
- chunk7B52C2XE_js.__privateAdd(this, _useCache3);
2396
+ chunk7B52C2XE_js.__privateAdd(this, _useCache5);
1984
2397
  this.cache = new PreferencesCache({
1985
2398
  emitterInstance: this._emitter
1986
2399
  });
1987
- chunk7B52C2XE_js.__privateSet(this, _useCache3, useCache);
2400
+ this.scheduleCache = new ScheduleCache({
2401
+ emitterInstance: this._emitter
2402
+ });
2403
+ chunk7B52C2XE_js.__privateSet(this, _useCache5, useCache);
2404
+ this.schedule = new PreferenceSchedule({
2405
+ cache: this.scheduleCache,
2406
+ useCache,
2407
+ inboxServiceInstance,
2408
+ eventEmitterInstance
2409
+ });
1988
2410
  }
1989
2411
  list() {
1990
2412
  return chunk7B52C2XE_js.__async(this, arguments, function* (args = {}) {
1991
2413
  return this.callWithSession(() => chunk7B52C2XE_js.__async(this, null, function* () {
1992
2414
  var _a;
1993
2415
  try {
1994
- let data = chunk7B52C2XE_js.__privateGet(this, _useCache3) ? this.cache.getAll(args) : void 0;
2416
+ let data = chunk7B52C2XE_js.__privateGet(this, _useCache5) ? this.cache.getAll(args) : void 0;
1995
2417
  this._emitter.emit("preferences.list.pending", { args, data });
1996
2418
  if (!data) {
1997
2419
  const response = yield this._inboxService.fetchPreferences({
@@ -2004,10 +2426,11 @@ var Preferences = class extends BaseModule {
2004
2426
  emitterInstance: this._emitter,
2005
2427
  inboxServiceInstance: this._inboxService,
2006
2428
  cache: this.cache,
2007
- useCache: chunk7B52C2XE_js.__privateGet(this, _useCache3)
2429
+ scheduleCache: this.scheduleCache,
2430
+ useCache: chunk7B52C2XE_js.__privateGet(this, _useCache5)
2008
2431
  })
2009
2432
  );
2010
- if (chunk7B52C2XE_js.__privateGet(this, _useCache3)) {
2433
+ if (chunk7B52C2XE_js.__privateGet(this, _useCache5)) {
2011
2434
  this.cache.set(args, data);
2012
2435
  data = this.cache.getAll(args);
2013
2436
  }
@@ -2028,7 +2451,8 @@ var Preferences = class extends BaseModule {
2028
2451
  emitter: this._emitter,
2029
2452
  apiService: this._inboxService,
2030
2453
  cache: this.cache,
2031
- useCache: chunk7B52C2XE_js.__privateGet(this, _useCache3),
2454
+ scheduleCache: this.scheduleCache,
2455
+ useCache: chunk7B52C2XE_js.__privateGet(this, _useCache5),
2032
2456
  args
2033
2457
  })
2034
2458
  );
@@ -2041,14 +2465,15 @@ var Preferences = class extends BaseModule {
2041
2465
  emitter: this._emitter,
2042
2466
  apiService: this._inboxService,
2043
2467
  cache: this.cache,
2044
- useCache: chunk7B52C2XE_js.__privateGet(this, _useCache3),
2468
+ scheduleCache: this.scheduleCache,
2469
+ useCache: chunk7B52C2XE_js.__privateGet(this, _useCache5),
2045
2470
  args
2046
2471
  })
2047
2472
  );
2048
2473
  });
2049
2474
  }
2050
2475
  };
2051
- _useCache3 = new WeakMap();
2476
+ _useCache5 = new WeakMap();
2052
2477
 
2053
2478
  // src/utils/is-browser.ts
2054
2479
  function isBrowser() {
@@ -2056,13 +2481,13 @@ function isBrowser() {
2056
2481
  }
2057
2482
 
2058
2483
  // src/session/session.ts
2059
- var _emitter5, _inboxService2, _options;
2484
+ var _emitter7, _inboxService2, _options;
2060
2485
  var Session = class {
2061
2486
  constructor(options, inboxServiceInstance, eventEmitterInstance) {
2062
- chunk7B52C2XE_js.__privateAdd(this, _emitter5);
2487
+ chunk7B52C2XE_js.__privateAdd(this, _emitter7);
2063
2488
  chunk7B52C2XE_js.__privateAdd(this, _inboxService2);
2064
2489
  chunk7B52C2XE_js.__privateAdd(this, _options);
2065
- chunk7B52C2XE_js.__privateSet(this, _emitter5, eventEmitterInstance);
2490
+ chunk7B52C2XE_js.__privateSet(this, _emitter7, eventEmitterInstance);
2066
2491
  chunk7B52C2XE_js.__privateSet(this, _inboxService2, inboxServiceInstance);
2067
2492
  chunk7B52C2XE_js.__privateSet(this, _options, options);
2068
2493
  }
@@ -2106,7 +2531,7 @@ var Session = class {
2106
2531
  if (options) {
2107
2532
  chunk7B52C2XE_js.__privateSet(this, _options, options);
2108
2533
  }
2109
- const { subscriber, subscriberHash, applicationIdentifier } = chunk7B52C2XE_js.__privateGet(this, _options);
2534
+ const { subscriber, subscriberHash, applicationIdentifier, defaultSchedule } = chunk7B52C2XE_js.__privateGet(this, _options);
2110
2535
  let currentTimezone;
2111
2536
  if (isBrowser()) {
2112
2537
  currentTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
@@ -2120,14 +2545,15 @@ var Session = class {
2120
2545
  } else {
2121
2546
  this.handleApplicationIdentifier("delete");
2122
2547
  }
2123
- chunk7B52C2XE_js.__privateGet(this, _emitter5).emit("session.initialize.pending", { args: chunk7B52C2XE_js.__privateGet(this, _options) });
2548
+ chunk7B52C2XE_js.__privateGet(this, _emitter7).emit("session.initialize.pending", { args: chunk7B52C2XE_js.__privateGet(this, _options) });
2124
2549
  const response = yield chunk7B52C2XE_js.__privateGet(this, _inboxService2).initializeSession({
2125
2550
  applicationIdentifier: finalApplicationIdentifier,
2126
2551
  subscriberHash,
2127
2552
  subscriber: chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, subscriber), {
2128
2553
  subscriberId: (_c = subscriber == null ? void 0 : subscriber.subscriberId) != null ? _c : "",
2129
2554
  timezone: (_d = subscriber == null ? void 0 : subscriber.timezone) != null ? _d : currentTimezone
2130
- })
2555
+ }),
2556
+ defaultSchedule
2131
2557
  });
2132
2558
  if ((_e = response == null ? void 0 : response.applicationIdentifier) == null ? void 0 : _e.startsWith("pk_keyless_")) {
2133
2559
  this.handleApplicationIdentifier("store", response.applicationIdentifier);
@@ -2135,14 +2561,14 @@ var Session = class {
2135
2561
  if (!((_f = response == null ? void 0 : response.applicationIdentifier) == null ? void 0 : _f.startsWith("pk_keyless_"))) {
2136
2562
  this.handleApplicationIdentifier("delete");
2137
2563
  }
2138
- chunk7B52C2XE_js.__privateGet(this, _emitter5).emit("session.initialize.resolved", { args: chunk7B52C2XE_js.__privateGet(this, _options), data: response });
2564
+ chunk7B52C2XE_js.__privateGet(this, _emitter7).emit("session.initialize.resolved", { args: chunk7B52C2XE_js.__privateGet(this, _options), data: response });
2139
2565
  } catch (error) {
2140
- chunk7B52C2XE_js.__privateGet(this, _emitter5).emit("session.initialize.resolved", { args: chunk7B52C2XE_js.__privateGet(this, _options), error });
2566
+ chunk7B52C2XE_js.__privateGet(this, _emitter7).emit("session.initialize.resolved", { args: chunk7B52C2XE_js.__privateGet(this, _options), error });
2141
2567
  }
2142
2568
  });
2143
2569
  }
2144
2570
  };
2145
- _emitter5 = new WeakMap();
2571
+ _emitter7 = new WeakMap();
2146
2572
  _inboxService2 = new WeakMap();
2147
2573
  _options = new WeakMap();
2148
2574
  var PRODUCTION_SOCKET_URL = "wss://socket.novu.co";
@@ -2236,7 +2662,7 @@ var mapToNotification = ({
2236
2662
  severity
2237
2663
  });
2238
2664
  };
2239
- var _token, _emitter6, _partySocket, _socketUrl, _notificationReceived, _unseenCountChanged, _unreadCountChanged, _handleMessage, _PartySocketClient_instances, initializeSocket_fn, handleConnectSocket_fn, handleDisconnectSocket_fn;
2665
+ var _token, _emitter8, _partySocket, _socketUrl, _notificationReceived, _unseenCountChanged, _unreadCountChanged, _handleMessage, _PartySocketClient_instances, initializeSocket_fn, handleConnectSocket_fn, handleDisconnectSocket_fn;
2240
2666
  var PartySocketClient = class extends BaseModule {
2241
2667
  constructor({
2242
2668
  socketUrl,
@@ -2249,15 +2675,15 @@ var PartySocketClient = class extends BaseModule {
2249
2675
  });
2250
2676
  chunk7B52C2XE_js.__privateAdd(this, _PartySocketClient_instances);
2251
2677
  chunk7B52C2XE_js.__privateAdd(this, _token);
2252
- chunk7B52C2XE_js.__privateAdd(this, _emitter6);
2678
+ chunk7B52C2XE_js.__privateAdd(this, _emitter8);
2253
2679
  chunk7B52C2XE_js.__privateAdd(this, _partySocket);
2254
2680
  chunk7B52C2XE_js.__privateAdd(this, _socketUrl);
2255
2681
  chunk7B52C2XE_js.__privateAdd(this, _notificationReceived, (event) => {
2256
2682
  try {
2257
2683
  const data = JSON.parse(event.data);
2258
2684
  if (data.event === "notification_received" /* RECEIVED */) {
2259
- chunk7B52C2XE_js.__privateGet(this, _emitter6).emit(NOTIFICATION_RECEIVED, {
2260
- result: new Notification(mapToNotification(data.data.message), chunk7B52C2XE_js.__privateGet(this, _emitter6), this._inboxService)
2685
+ chunk7B52C2XE_js.__privateGet(this, _emitter8).emit(NOTIFICATION_RECEIVED, {
2686
+ result: new Notification(mapToNotification(data.data.message), chunk7B52C2XE_js.__privateGet(this, _emitter8), this._inboxService)
2261
2687
  });
2262
2688
  }
2263
2689
  } catch (error) {
@@ -2268,7 +2694,7 @@ var PartySocketClient = class extends BaseModule {
2268
2694
  try {
2269
2695
  const data = JSON.parse(event.data);
2270
2696
  if (data.event === "unseen_count_changed" /* UNSEEN */) {
2271
- chunk7B52C2XE_js.__privateGet(this, _emitter6).emit(UNSEEN_COUNT_CHANGED, {
2697
+ chunk7B52C2XE_js.__privateGet(this, _emitter8).emit(UNSEEN_COUNT_CHANGED, {
2272
2698
  result: data.data.unseenCount
2273
2699
  });
2274
2700
  }
@@ -2279,7 +2705,7 @@ var PartySocketClient = class extends BaseModule {
2279
2705
  try {
2280
2706
  const data = JSON.parse(event.data);
2281
2707
  if (data.event === "unread_count_changed" /* UNREAD */) {
2282
- chunk7B52C2XE_js.__privateGet(this, _emitter6).emit(UNREAD_COUNT_CHANGED, {
2708
+ chunk7B52C2XE_js.__privateGet(this, _emitter8).emit(UNREAD_COUNT_CHANGED, {
2283
2709
  result: data.data.counts
2284
2710
  });
2285
2711
  }
@@ -2304,7 +2730,7 @@ var PartySocketClient = class extends BaseModule {
2304
2730
  } catch (error) {
2305
2731
  }
2306
2732
  });
2307
- chunk7B52C2XE_js.__privateSet(this, _emitter6, eventEmitterInstance);
2733
+ chunk7B52C2XE_js.__privateSet(this, _emitter8, eventEmitterInstance);
2308
2734
  chunk7B52C2XE_js.__privateSet(this, _socketUrl, socketUrl != null ? socketUrl : PRODUCTION_SOCKET_URL);
2309
2735
  }
2310
2736
  onSessionSuccess({ token }) {
@@ -2331,7 +2757,7 @@ var PartySocketClient = class extends BaseModule {
2331
2757
  }
2332
2758
  };
2333
2759
  _token = new WeakMap();
2334
- _emitter6 = new WeakMap();
2760
+ _emitter8 = new WeakMap();
2335
2761
  _partySocket = new WeakMap();
2336
2762
  _socketUrl = new WeakMap();
2337
2763
  _notificationReceived = new WeakMap();
@@ -2345,15 +2771,15 @@ initializeSocket_fn = function() {
2345
2771
  return;
2346
2772
  }
2347
2773
  const args = { socketUrl: chunk7B52C2XE_js.__privateGet(this, _socketUrl) };
2348
- chunk7B52C2XE_js.__privateGet(this, _emitter6).emit("socket.connect.pending", { args });
2774
+ chunk7B52C2XE_js.__privateGet(this, _emitter8).emit("socket.connect.pending", { args });
2349
2775
  const url = new URL(chunk7B52C2XE_js.__privateGet(this, _socketUrl));
2350
2776
  url.searchParams.set("token", chunk7B52C2XE_js.__privateGet(this, _token));
2351
2777
  chunk7B52C2XE_js.__privateSet(this, _partySocket, new partysocket.WebSocket(url.toString()));
2352
2778
  chunk7B52C2XE_js.__privateGet(this, _partySocket).addEventListener("open", () => {
2353
- chunk7B52C2XE_js.__privateGet(this, _emitter6).emit("socket.connect.resolved", { args });
2779
+ chunk7B52C2XE_js.__privateGet(this, _emitter8).emit("socket.connect.resolved", { args });
2354
2780
  });
2355
2781
  chunk7B52C2XE_js.__privateGet(this, _partySocket).addEventListener("error", (error) => {
2356
- chunk7B52C2XE_js.__privateGet(this, _emitter6).emit("socket.connect.resolved", { args, error });
2782
+ chunk7B52C2XE_js.__privateGet(this, _emitter8).emit("socket.connect.resolved", { args, error });
2357
2783
  });
2358
2784
  chunk7B52C2XE_js.__privateGet(this, _partySocket).addEventListener("message", chunk7B52C2XE_js.__privateGet(this, _handleMessage));
2359
2785
  });
@@ -2471,7 +2897,7 @@ var mapToNotification2 = ({
2471
2897
  severity
2472
2898
  });
2473
2899
  };
2474
- var _token2, _emitter7, _socketIo, _socketUrl2, _notificationReceived2, _unseenCountChanged2, _unreadCountChanged2, _Socket_instances, initializeSocket_fn2, handleConnectSocket_fn2, handleDisconnectSocket_fn2;
2900
+ var _token2, _emitter9, _socketIo, _socketUrl2, _notificationReceived2, _unseenCountChanged2, _unreadCountChanged2, _Socket_instances, initializeSocket_fn2, handleConnectSocket_fn2, handleDisconnectSocket_fn2;
2475
2901
  var Socket = class extends BaseModule {
2476
2902
  constructor({
2477
2903
  socketUrl,
@@ -2484,25 +2910,25 @@ var Socket = class extends BaseModule {
2484
2910
  });
2485
2911
  chunk7B52C2XE_js.__privateAdd(this, _Socket_instances);
2486
2912
  chunk7B52C2XE_js.__privateAdd(this, _token2);
2487
- chunk7B52C2XE_js.__privateAdd(this, _emitter7);
2913
+ chunk7B52C2XE_js.__privateAdd(this, _emitter9);
2488
2914
  chunk7B52C2XE_js.__privateAdd(this, _socketIo);
2489
2915
  chunk7B52C2XE_js.__privateAdd(this, _socketUrl2);
2490
2916
  chunk7B52C2XE_js.__privateAdd(this, _notificationReceived2, ({ message }) => {
2491
- chunk7B52C2XE_js.__privateGet(this, _emitter7).emit(NOTIFICATION_RECEIVED2, {
2492
- result: new Notification(mapToNotification2(message), chunk7B52C2XE_js.__privateGet(this, _emitter7), this._inboxService)
2917
+ chunk7B52C2XE_js.__privateGet(this, _emitter9).emit(NOTIFICATION_RECEIVED2, {
2918
+ result: new Notification(mapToNotification2(message), chunk7B52C2XE_js.__privateGet(this, _emitter9), this._inboxService)
2493
2919
  });
2494
2920
  });
2495
2921
  chunk7B52C2XE_js.__privateAdd(this, _unseenCountChanged2, ({ unseenCount }) => {
2496
- chunk7B52C2XE_js.__privateGet(this, _emitter7).emit(UNSEEN_COUNT_CHANGED2, {
2922
+ chunk7B52C2XE_js.__privateGet(this, _emitter9).emit(UNSEEN_COUNT_CHANGED2, {
2497
2923
  result: unseenCount
2498
2924
  });
2499
2925
  });
2500
2926
  chunk7B52C2XE_js.__privateAdd(this, _unreadCountChanged2, ({ counts }) => {
2501
- chunk7B52C2XE_js.__privateGet(this, _emitter7).emit(UNREAD_COUNT_CHANGED2, {
2927
+ chunk7B52C2XE_js.__privateGet(this, _emitter9).emit(UNREAD_COUNT_CHANGED2, {
2502
2928
  result: counts
2503
2929
  });
2504
2930
  });
2505
- chunk7B52C2XE_js.__privateSet(this, _emitter7, eventEmitterInstance);
2931
+ chunk7B52C2XE_js.__privateSet(this, _emitter9, eventEmitterInstance);
2506
2932
  chunk7B52C2XE_js.__privateSet(this, _socketUrl2, socketUrl != null ? socketUrl : PRODUCTION_SOCKET_URL2);
2507
2933
  }
2508
2934
  onSessionSuccess({ token }) {
@@ -2529,7 +2955,7 @@ var Socket = class extends BaseModule {
2529
2955
  }
2530
2956
  };
2531
2957
  _token2 = new WeakMap();
2532
- _emitter7 = new WeakMap();
2958
+ _emitter9 = new WeakMap();
2533
2959
  _socketIo = new WeakMap();
2534
2960
  _socketUrl2 = new WeakMap();
2535
2961
  _notificationReceived2 = new WeakMap();
@@ -2543,7 +2969,7 @@ initializeSocket_fn2 = function() {
2543
2969
  return;
2544
2970
  }
2545
2971
  const args = { socketUrl: chunk7B52C2XE_js.__privateGet(this, _socketUrl2) };
2546
- chunk7B52C2XE_js.__privateGet(this, _emitter7).emit("socket.connect.pending", { args });
2972
+ chunk7B52C2XE_js.__privateGet(this, _emitter9).emit("socket.connect.pending", { args });
2547
2973
  chunk7B52C2XE_js.__privateSet(this, _socketIo, io__default.default(chunk7B52C2XE_js.__privateGet(this, _socketUrl2), {
2548
2974
  reconnectionDelayMax: 1e4,
2549
2975
  transports: ["websocket"],
@@ -2552,10 +2978,10 @@ initializeSocket_fn2 = function() {
2552
2978
  }
2553
2979
  }));
2554
2980
  chunk7B52C2XE_js.__privateGet(this, _socketIo).on("connect", () => {
2555
- chunk7B52C2XE_js.__privateGet(this, _emitter7).emit("socket.connect.resolved", { args });
2981
+ chunk7B52C2XE_js.__privateGet(this, _emitter9).emit("socket.connect.resolved", { args });
2556
2982
  });
2557
2983
  chunk7B52C2XE_js.__privateGet(this, _socketIo).on("connect_error", (error) => {
2558
- chunk7B52C2XE_js.__privateGet(this, _emitter7).emit("socket.connect.resolved", { args, error });
2984
+ chunk7B52C2XE_js.__privateGet(this, _emitter9).emit("socket.connect.resolved", { args, error });
2559
2985
  });
2560
2986
  (_a = chunk7B52C2XE_js.__privateGet(this, _socketIo)) == null ? void 0 : _a.on("notification_received" /* RECEIVED */, chunk7B52C2XE_js.__privateGet(this, _notificationReceived2));
2561
2987
  (_b = chunk7B52C2XE_js.__privateGet(this, _socketIo)) == null ? void 0 : _b.on("unseen_count_changed" /* UNSEEN */, chunk7B52C2XE_js.__privateGet(this, _unseenCountChanged2));
@@ -2629,10 +3055,10 @@ function createSocket({
2629
3055
  }
2630
3056
 
2631
3057
  // src/novu.ts
2632
- var _emitter8, _session, _inboxService3;
3058
+ var _emitter10, _session, _inboxService3;
2633
3059
  var Novu = class {
2634
3060
  constructor(options) {
2635
- chunk7B52C2XE_js.__privateAdd(this, _emitter8);
3061
+ chunk7B52C2XE_js.__privateAdd(this, _emitter10);
2636
3062
  chunk7B52C2XE_js.__privateAdd(this, _session);
2637
3063
  chunk7B52C2XE_js.__privateAdd(this, _inboxService3);
2638
3064
  var _a, _b;
@@ -2640,43 +3066,44 @@ var Novu = class {
2640
3066
  apiUrl: options.apiUrl || options.backendUrl,
2641
3067
  userAgent: options.__userAgent
2642
3068
  }));
2643
- chunk7B52C2XE_js.__privateSet(this, _emitter8, new NovuEventEmitter());
3069
+ chunk7B52C2XE_js.__privateSet(this, _emitter10, new NovuEventEmitter());
2644
3070
  chunk7B52C2XE_js.__privateSet(this, _session, new Session(
2645
3071
  {
2646
3072
  applicationIdentifier: options.applicationIdentifier || "",
2647
3073
  subscriberHash: options.subscriberHash,
2648
- subscriber: chunkZB7IPCHY_js.buildSubscriber({ subscriberId: options.subscriberId, subscriber: options.subscriber })
3074
+ subscriber: chunkZB7IPCHY_js.buildSubscriber({ subscriberId: options.subscriberId, subscriber: options.subscriber }),
3075
+ defaultSchedule: options.defaultSchedule
2649
3076
  },
2650
3077
  chunk7B52C2XE_js.__privateGet(this, _inboxService3),
2651
- chunk7B52C2XE_js.__privateGet(this, _emitter8)
3078
+ chunk7B52C2XE_js.__privateGet(this, _emitter10)
2652
3079
  ));
2653
3080
  chunk7B52C2XE_js.__privateGet(this, _session).initialize();
2654
3081
  this.notifications = new Notifications({
2655
3082
  useCache: (_a = options.useCache) != null ? _a : true,
2656
3083
  inboxServiceInstance: chunk7B52C2XE_js.__privateGet(this, _inboxService3),
2657
- eventEmitterInstance: chunk7B52C2XE_js.__privateGet(this, _emitter8)
3084
+ eventEmitterInstance: chunk7B52C2XE_js.__privateGet(this, _emitter10)
2658
3085
  });
2659
3086
  this.preferences = new Preferences({
2660
3087
  useCache: (_b = options.useCache) != null ? _b : true,
2661
3088
  inboxServiceInstance: chunk7B52C2XE_js.__privateGet(this, _inboxService3),
2662
- eventEmitterInstance: chunk7B52C2XE_js.__privateGet(this, _emitter8)
3089
+ eventEmitterInstance: chunk7B52C2XE_js.__privateGet(this, _emitter10)
2663
3090
  });
2664
3091
  this.socket = createSocket({
2665
3092
  socketUrl: options.socketUrl,
2666
- eventEmitterInstance: chunk7B52C2XE_js.__privateGet(this, _emitter8),
3093
+ eventEmitterInstance: chunk7B52C2XE_js.__privateGet(this, _emitter10),
2667
3094
  inboxServiceInstance: chunk7B52C2XE_js.__privateGet(this, _inboxService3)
2668
3095
  });
2669
3096
  this.on = (eventName, listener) => {
2670
3097
  if (this.socket.isSocketEvent(eventName)) {
2671
3098
  this.socket.connect();
2672
3099
  }
2673
- const cleanup = chunk7B52C2XE_js.__privateGet(this, _emitter8).on(eventName, listener);
3100
+ const cleanup = chunk7B52C2XE_js.__privateGet(this, _emitter10).on(eventName, listener);
2674
3101
  return () => {
2675
3102
  cleanup();
2676
3103
  };
2677
3104
  };
2678
3105
  this.off = (eventName, listener) => {
2679
- chunk7B52C2XE_js.__privateGet(this, _emitter8).off(eventName, listener);
3106
+ chunk7B52C2XE_js.__privateGet(this, _emitter10).off(eventName, listener);
2680
3107
  };
2681
3108
  }
2682
3109
  get applicationIdentifier() {
@@ -2695,7 +3122,7 @@ var Novu = class {
2695
3122
  });
2696
3123
  }
2697
3124
  };
2698
- _emitter8 = new WeakMap();
3125
+ _emitter10 = new WeakMap();
2699
3126
  _session = new WeakMap();
2700
3127
  _inboxService3 = new WeakMap();
2701
3128