@novu/js 3.9.2 → 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.
- package/dist/cjs/{chunk-VEX66SK3.js → chunk-TWUFZL5G.js} +578 -151
- package/dist/cjs/index.d.ts +4 -4
- package/dist/cjs/index.js +13 -13
- package/dist/cjs/internal/index.d.ts +1 -1
- package/dist/{esm/novu-BOlS1PMv.d.mts → cjs/novu--9_BeIj6.d.ts} +120 -36
- package/dist/cjs/themes/index.d.ts +3 -3
- package/dist/{esm/types-C9c_ID-G.d.mts → cjs/types-CvebLpsG.d.ts} +97 -5
- package/dist/{esm/types-CbmZeAf8.d.mts → cjs/types-DKMAoSfo.d.ts} +27 -1
- package/dist/cjs/ui/index.d.ts +6 -5
- package/dist/cjs/ui/index.js +1468 -312
- package/dist/esm/{chunk-3CKXF2I4.mjs → chunk-OMH4MVCZ.mjs} +578 -151
- package/dist/esm/index.d.mts +4 -4
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/internal/index.d.mts +1 -1
- package/dist/{cjs/novu-Db46nHZP.d.ts → esm/novu-C2DJGZ4P.d.mts} +120 -36
- package/dist/esm/themes/index.d.mts +3 -3
- package/dist/{cjs/types-B-VuVpSW.d.ts → esm/types-Ba0J3oyA.d.mts} +97 -5
- package/dist/{cjs/types-CbmZeAf8.d.ts → esm/types-DKMAoSfo.d.mts} +27 -1
- package/dist/esm/ui/index.d.mts +6 -5
- package/dist/esm/ui/index.mjs +1450 -313
- package/dist/index.css +1 -1
- package/dist/novu.min.js +12 -12
- package/dist/novu.min.js.gz +0 -0
- package/package.json +1 -1
|
@@ -141,7 +141,7 @@ function checkNotificationMatchesFilter(notification, filter) {
|
|
|
141
141
|
|
|
142
142
|
// src/api/http-client.ts
|
|
143
143
|
var DEFAULT_API_VERSION = "v1";
|
|
144
|
-
var DEFAULT_USER_AGENT = `${"@novu/js"}@${"3.
|
|
144
|
+
var DEFAULT_USER_AGENT = `${"@novu/js"}@${"3.10.0"}`;
|
|
145
145
|
var HttpClient = class {
|
|
146
146
|
constructor(options = {}) {
|
|
147
147
|
// Environment variable for local development that overrides the default API endpoint without affecting the Inbox DX
|
|
@@ -269,12 +269,14 @@ var InboxService = class {
|
|
|
269
269
|
return __async(this, arguments, function* ({
|
|
270
270
|
applicationIdentifier,
|
|
271
271
|
subscriberHash,
|
|
272
|
-
subscriber
|
|
272
|
+
subscriber,
|
|
273
|
+
defaultSchedule
|
|
273
274
|
}) {
|
|
274
275
|
const response = yield __privateGet(this, _httpClient).post(`${INBOX_ROUTE}/session`, {
|
|
275
276
|
applicationIdentifier,
|
|
276
277
|
subscriberHash,
|
|
277
|
-
subscriber
|
|
278
|
+
subscriber,
|
|
279
|
+
defaultSchedule
|
|
278
280
|
});
|
|
279
281
|
__privateGet(this, _httpClient).setAuthorizationToken(response.token);
|
|
280
282
|
__privateGet(this, _httpClient).setKeylessHeader(response.applicationIdentifier);
|
|
@@ -377,6 +379,15 @@ var InboxService = class {
|
|
|
377
379
|
data: data ? JSON.stringify(data) : void 0
|
|
378
380
|
});
|
|
379
381
|
}
|
|
382
|
+
delete(notificationId) {
|
|
383
|
+
return __privateGet(this, _httpClient).delete(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/delete`);
|
|
384
|
+
}
|
|
385
|
+
deleteAll({ tags, data }) {
|
|
386
|
+
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/delete`, {
|
|
387
|
+
tags,
|
|
388
|
+
data: data ? JSON.stringify(data) : void 0
|
|
389
|
+
});
|
|
390
|
+
}
|
|
380
391
|
markAsSeen({
|
|
381
392
|
notificationIds,
|
|
382
393
|
tags,
|
|
@@ -434,8 +445,8 @@ var InboxService = class {
|
|
|
434
445
|
bulkUpdatePreferences(preferences) {
|
|
435
446
|
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/bulk`, { preferences });
|
|
436
447
|
}
|
|
437
|
-
updateGlobalPreferences(
|
|
438
|
-
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences`,
|
|
448
|
+
updateGlobalPreferences(preferences) {
|
|
449
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences`, preferences);
|
|
439
450
|
}
|
|
440
451
|
updateWorkflowPreferences({
|
|
441
452
|
workflowId,
|
|
@@ -443,6 +454,9 @@ var InboxService = class {
|
|
|
443
454
|
}) {
|
|
444
455
|
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/${workflowId}`, channels);
|
|
445
456
|
}
|
|
457
|
+
fetchGlobalPreferences() {
|
|
458
|
+
return __privateGet(this, _httpClient).get(`${INBOX_ROUTE}/preferences/global`);
|
|
459
|
+
}
|
|
446
460
|
triggerHelloWorldEvent() {
|
|
447
461
|
const payload = {
|
|
448
462
|
name: "hello-world",
|
|
@@ -915,6 +929,49 @@ var archiveAllRead = (_0) => __async(void 0, [_0], function* ({
|
|
|
915
929
|
return { error: new NovuError("Failed to archive all read notifications", error) };
|
|
916
930
|
}
|
|
917
931
|
});
|
|
932
|
+
var deleteNotification = (_0) => __async(void 0, [_0], function* ({
|
|
933
|
+
emitter,
|
|
934
|
+
apiService,
|
|
935
|
+
args
|
|
936
|
+
}) {
|
|
937
|
+
const { notificationId } = getNotificationDetails(
|
|
938
|
+
args,
|
|
939
|
+
{},
|
|
940
|
+
{
|
|
941
|
+
emitter,
|
|
942
|
+
apiService
|
|
943
|
+
}
|
|
944
|
+
);
|
|
945
|
+
try {
|
|
946
|
+
emitter.emit("notification.delete.pending", {
|
|
947
|
+
args
|
|
948
|
+
});
|
|
949
|
+
yield apiService.delete(notificationId);
|
|
950
|
+
emitter.emit("notification.delete.resolved", { args });
|
|
951
|
+
return {};
|
|
952
|
+
} catch (error) {
|
|
953
|
+
emitter.emit("notification.delete.resolved", { args, error });
|
|
954
|
+
return { error: new NovuError("Failed to delete notification", error) };
|
|
955
|
+
}
|
|
956
|
+
});
|
|
957
|
+
var deleteAll = (_0) => __async(void 0, [_0], function* ({
|
|
958
|
+
emitter,
|
|
959
|
+
inboxService,
|
|
960
|
+
notificationsCache,
|
|
961
|
+
tags,
|
|
962
|
+
data
|
|
963
|
+
}) {
|
|
964
|
+
try {
|
|
965
|
+
const notifications = notificationsCache.getUniqueNotifications({ tags, data });
|
|
966
|
+
emitter.emit("notifications.delete_all.pending", { args: { tags, data }, data: notifications });
|
|
967
|
+
yield inboxService.deleteAll({ tags, data });
|
|
968
|
+
emitter.emit("notifications.delete_all.resolved", { args: { tags, data } });
|
|
969
|
+
return {};
|
|
970
|
+
} catch (error) {
|
|
971
|
+
emitter.emit("notifications.delete_all.resolved", { args: { tags, data }, error });
|
|
972
|
+
return { error: new NovuError("Failed to delete all notifications", error) };
|
|
973
|
+
}
|
|
974
|
+
});
|
|
918
975
|
|
|
919
976
|
// src/notifications/notification.ts
|
|
920
977
|
var _emitter, _inboxService;
|
|
@@ -994,6 +1051,15 @@ var Notification = class {
|
|
|
994
1051
|
}
|
|
995
1052
|
});
|
|
996
1053
|
}
|
|
1054
|
+
delete() {
|
|
1055
|
+
return deleteNotification({
|
|
1056
|
+
emitter: __privateGet(this, _emitter),
|
|
1057
|
+
apiService: __privateGet(this, _inboxService),
|
|
1058
|
+
args: {
|
|
1059
|
+
notification: this
|
|
1060
|
+
}
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
997
1063
|
snooze(snoozeUntil) {
|
|
998
1064
|
return snooze({
|
|
999
1065
|
emitter: __privateGet(this, _emitter),
|
|
@@ -1223,8 +1289,10 @@ var removeEvents = [
|
|
|
1223
1289
|
"notification.unarchive.pending",
|
|
1224
1290
|
"notification.snooze.pending",
|
|
1225
1291
|
"notification.unsnooze.pending",
|
|
1292
|
+
"notification.delete.pending",
|
|
1226
1293
|
"notifications.archive_all.pending",
|
|
1227
|
-
"notifications.archive_all_read.pending"
|
|
1294
|
+
"notifications.archive_all_read.pending",
|
|
1295
|
+
"notifications.delete_all.pending"
|
|
1228
1296
|
];
|
|
1229
1297
|
var _emitter2, _cache2;
|
|
1230
1298
|
var NotificationsCache = class {
|
|
@@ -1264,11 +1332,35 @@ var NotificationsCache = class {
|
|
|
1264
1332
|
}));
|
|
1265
1333
|
return true;
|
|
1266
1334
|
};
|
|
1267
|
-
this.handleNotificationEvent = ({ remove } = { remove: false }) => (
|
|
1268
|
-
|
|
1335
|
+
this.handleNotificationEvent = ({ remove } = { remove: false }) => (event) => {
|
|
1336
|
+
const { data, args } = event;
|
|
1337
|
+
let notifications = [];
|
|
1338
|
+
if (data !== void 0 && data !== null) {
|
|
1339
|
+
if (Array.isArray(data) && data.every((item) => typeof item === "object" && "id" in item)) {
|
|
1340
|
+
notifications = data;
|
|
1341
|
+
} else if (typeof data === "object" && "id" in data) {
|
|
1342
|
+
notifications = [data];
|
|
1343
|
+
}
|
|
1344
|
+
} else if (remove && args) {
|
|
1345
|
+
if ("notification" in args && args.notification) {
|
|
1346
|
+
notifications = [args.notification];
|
|
1347
|
+
} else if ("notificationId" in args && args.notificationId) {
|
|
1348
|
+
const foundNotifications = [];
|
|
1349
|
+
__privateGet(this, _cache2).keys().forEach((key) => {
|
|
1350
|
+
const cachedResponse = __privateGet(this, _cache2).get(key);
|
|
1351
|
+
if (cachedResponse) {
|
|
1352
|
+
const found = cachedResponse.notifications.find((n) => n.id === args.notificationId);
|
|
1353
|
+
if (found) {
|
|
1354
|
+
foundNotifications.push(found);
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
});
|
|
1358
|
+
notifications = foundNotifications;
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
if (notifications.length === 0) {
|
|
1269
1362
|
return;
|
|
1270
1363
|
}
|
|
1271
|
-
const notifications = Array.isArray(data) ? data : [data];
|
|
1272
1364
|
const uniqueFilterKeys = /* @__PURE__ */ new Set();
|
|
1273
1365
|
__privateGet(this, _cache2).keys().forEach((key) => {
|
|
1274
1366
|
notifications.forEach((notification) => {
|
|
@@ -1524,6 +1616,19 @@ var Notifications = class extends BaseModule {
|
|
|
1524
1616
|
);
|
|
1525
1617
|
});
|
|
1526
1618
|
}
|
|
1619
|
+
delete(args) {
|
|
1620
|
+
return __async(this, null, function* () {
|
|
1621
|
+
return this.callWithSession(
|
|
1622
|
+
() => __async(this, null, function* () {
|
|
1623
|
+
return deleteNotification({
|
|
1624
|
+
emitter: this._emitter,
|
|
1625
|
+
apiService: this._inboxService,
|
|
1626
|
+
args
|
|
1627
|
+
});
|
|
1628
|
+
})
|
|
1629
|
+
);
|
|
1630
|
+
});
|
|
1631
|
+
}
|
|
1527
1632
|
snooze(args) {
|
|
1528
1633
|
return __async(this, null, function* () {
|
|
1529
1634
|
return this.callWithSession(
|
|
@@ -1679,11 +1784,30 @@ var Notifications = class extends BaseModule {
|
|
|
1679
1784
|
);
|
|
1680
1785
|
});
|
|
1681
1786
|
}
|
|
1787
|
+
deleteAll() {
|
|
1788
|
+
return __async(this, arguments, function* ({
|
|
1789
|
+
tags,
|
|
1790
|
+
data
|
|
1791
|
+
} = {}) {
|
|
1792
|
+
return this.callWithSession(
|
|
1793
|
+
() => __async(this, null, function* () {
|
|
1794
|
+
return deleteAll({
|
|
1795
|
+
emitter: this._emitter,
|
|
1796
|
+
inboxService: this._inboxService,
|
|
1797
|
+
notificationsCache: this.cache,
|
|
1798
|
+
tags,
|
|
1799
|
+
data
|
|
1800
|
+
});
|
|
1801
|
+
})
|
|
1802
|
+
);
|
|
1803
|
+
});
|
|
1804
|
+
}
|
|
1682
1805
|
clearCache({ filter } = {}) {
|
|
1683
1806
|
if (filter) {
|
|
1684
|
-
|
|
1807
|
+
this.cache.clear(filter != null ? filter : {});
|
|
1808
|
+
return;
|
|
1685
1809
|
}
|
|
1686
|
-
|
|
1810
|
+
this.cache.clearAll();
|
|
1687
1811
|
}
|
|
1688
1812
|
triggerHelloWorldEvent() {
|
|
1689
1813
|
return __async(this, null, function* () {
|
|
@@ -1693,115 +1817,77 @@ var Notifications = class extends BaseModule {
|
|
|
1693
1817
|
};
|
|
1694
1818
|
_useCache = new WeakMap();
|
|
1695
1819
|
|
|
1696
|
-
// src/
|
|
1697
|
-
var
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
return acc;
|
|
1706
|
-
}
|
|
1707
|
-
acc[key] = value;
|
|
1708
|
-
return acc;
|
|
1709
|
-
}, {});
|
|
1710
|
-
var getCacheKey2 = ({ tags, severity }) => {
|
|
1711
|
-
return JSON.stringify(excludeEmpty2({ tags, severity }));
|
|
1712
|
-
};
|
|
1713
|
-
var _emitter3, _cache3;
|
|
1714
|
-
var PreferencesCache = class {
|
|
1715
|
-
constructor({ emitterInstance }) {
|
|
1820
|
+
// src/preferences/schedule.ts
|
|
1821
|
+
var _emitter3, _apiService, _cache3, _useCache2;
|
|
1822
|
+
var Schedule = class {
|
|
1823
|
+
constructor(schedule, {
|
|
1824
|
+
emitterInstance,
|
|
1825
|
+
inboxServiceInstance,
|
|
1826
|
+
cache,
|
|
1827
|
+
useCache
|
|
1828
|
+
}) {
|
|
1716
1829
|
__privateAdd(this, _emitter3);
|
|
1830
|
+
__privateAdd(this, _apiService);
|
|
1717
1831
|
__privateAdd(this, _cache3);
|
|
1718
|
-
this
|
|
1719
|
-
const preferences = __privateGet(this, _cache3).get(key);
|
|
1720
|
-
if (!preferences) {
|
|
1721
|
-
return false;
|
|
1722
|
-
}
|
|
1723
|
-
const index = preferences.findIndex(
|
|
1724
|
-
(el) => {
|
|
1725
|
-
var _a, _b;
|
|
1726
|
-
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 */;
|
|
1727
|
-
}
|
|
1728
|
-
);
|
|
1729
|
-
if (index === -1) {
|
|
1730
|
-
return false;
|
|
1731
|
-
}
|
|
1732
|
-
const updatedPreferences = [...preferences];
|
|
1733
|
-
updatedPreferences[index] = data;
|
|
1734
|
-
__privateGet(this, _cache3).set(key, updatedPreferences);
|
|
1735
|
-
return true;
|
|
1736
|
-
};
|
|
1737
|
-
this.handlePreferenceEvent = ({ data }) => {
|
|
1738
|
-
if (!data) {
|
|
1739
|
-
return;
|
|
1740
|
-
}
|
|
1741
|
-
const preferences = Array.isArray(data) ? data : [data];
|
|
1742
|
-
const uniqueFilterKeys = /* @__PURE__ */ new Set();
|
|
1743
|
-
__privateGet(this, _cache3).keys().forEach((key) => {
|
|
1744
|
-
preferences.forEach((preference) => {
|
|
1745
|
-
const hasUpdatedPreference = this.updatePreference(key, preference);
|
|
1746
|
-
const updatedPreference = __privateGet(this, _cache3).get(key);
|
|
1747
|
-
if (!hasUpdatedPreference || !updatedPreference) {
|
|
1748
|
-
return;
|
|
1749
|
-
}
|
|
1750
|
-
uniqueFilterKeys.add(key);
|
|
1751
|
-
});
|
|
1752
|
-
});
|
|
1753
|
-
uniqueFilterKeys.forEach((key) => {
|
|
1754
|
-
var _a;
|
|
1755
|
-
__privateGet(this, _emitter3).emit("preferences.list.updated", {
|
|
1756
|
-
data: (_a = __privateGet(this, _cache3).get(key)) != null ? _a : []
|
|
1757
|
-
});
|
|
1758
|
-
});
|
|
1759
|
-
};
|
|
1832
|
+
__privateAdd(this, _useCache2);
|
|
1760
1833
|
__privateSet(this, _emitter3, emitterInstance);
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
has(args) {
|
|
1767
|
-
return __privateGet(this, _cache3).get(getCacheKey2(args)) !== void 0;
|
|
1768
|
-
}
|
|
1769
|
-
set(args, data) {
|
|
1770
|
-
__privateGet(this, _cache3).set(getCacheKey2(args), data);
|
|
1771
|
-
}
|
|
1772
|
-
getAll(args) {
|
|
1773
|
-
if (this.has(args)) {
|
|
1774
|
-
return __privateGet(this, _cache3).get(getCacheKey2(args));
|
|
1775
|
-
}
|
|
1834
|
+
__privateSet(this, _apiService, inboxServiceInstance);
|
|
1835
|
+
__privateSet(this, _cache3, cache);
|
|
1836
|
+
__privateSet(this, _useCache2, useCache);
|
|
1837
|
+
this.isEnabled = schedule.isEnabled;
|
|
1838
|
+
this.weeklySchedule = schedule.weeklySchedule;
|
|
1776
1839
|
}
|
|
1777
|
-
|
|
1778
|
-
|
|
1840
|
+
update(args) {
|
|
1841
|
+
return __async(this, null, function* () {
|
|
1842
|
+
var _a;
|
|
1843
|
+
const hasWeeklySchedule = !!args.weeklySchedule || !!this.weeklySchedule;
|
|
1844
|
+
return updateSchedule({
|
|
1845
|
+
emitter: __privateGet(this, _emitter3),
|
|
1846
|
+
apiService: __privateGet(this, _apiService),
|
|
1847
|
+
cache: __privateGet(this, _cache3),
|
|
1848
|
+
useCache: __privateGet(this, _useCache2),
|
|
1849
|
+
args: __spreadValues({
|
|
1850
|
+
isEnabled: (_a = args.isEnabled) != null ? _a : this.isEnabled
|
|
1851
|
+
}, hasWeeklySchedule && {
|
|
1852
|
+
weeklySchedule: __spreadValues(__spreadValues({}, this.weeklySchedule), args.weeklySchedule)
|
|
1853
|
+
})
|
|
1854
|
+
});
|
|
1855
|
+
});
|
|
1779
1856
|
}
|
|
1780
1857
|
};
|
|
1781
1858
|
_emitter3 = new WeakMap();
|
|
1859
|
+
_apiService = new WeakMap();
|
|
1782
1860
|
_cache3 = new WeakMap();
|
|
1861
|
+
_useCache2 = new WeakMap();
|
|
1783
1862
|
|
|
1784
1863
|
// src/preferences/preference.ts
|
|
1785
|
-
var _emitter4,
|
|
1864
|
+
var _emitter4, _apiService2, _cache4, _scheduleCache, _useCache3;
|
|
1786
1865
|
var Preference = class {
|
|
1787
1866
|
constructor(preference, {
|
|
1788
1867
|
emitterInstance,
|
|
1789
1868
|
inboxServiceInstance,
|
|
1790
1869
|
cache,
|
|
1870
|
+
scheduleCache,
|
|
1791
1871
|
useCache
|
|
1792
1872
|
}) {
|
|
1793
1873
|
__privateAdd(this, _emitter4);
|
|
1794
|
-
__privateAdd(this,
|
|
1874
|
+
__privateAdd(this, _apiService2);
|
|
1795
1875
|
__privateAdd(this, _cache4);
|
|
1796
|
-
__privateAdd(this,
|
|
1876
|
+
__privateAdd(this, _scheduleCache);
|
|
1877
|
+
__privateAdd(this, _useCache3);
|
|
1797
1878
|
__privateSet(this, _emitter4, emitterInstance);
|
|
1798
|
-
__privateSet(this,
|
|
1879
|
+
__privateSet(this, _apiService2, inboxServiceInstance);
|
|
1799
1880
|
__privateSet(this, _cache4, cache);
|
|
1800
|
-
__privateSet(this,
|
|
1881
|
+
__privateSet(this, _scheduleCache, scheduleCache);
|
|
1882
|
+
__privateSet(this, _useCache3, useCache);
|
|
1801
1883
|
this.level = preference.level;
|
|
1802
1884
|
this.enabled = preference.enabled;
|
|
1803
1885
|
this.channels = preference.channels;
|
|
1804
1886
|
this.workflow = preference.workflow;
|
|
1887
|
+
this.schedule = new Schedule(
|
|
1888
|
+
__spreadValues({}, preference.schedule),
|
|
1889
|
+
{ emitterInstance, inboxServiceInstance, cache: scheduleCache, useCache }
|
|
1890
|
+
);
|
|
1805
1891
|
}
|
|
1806
1892
|
update({
|
|
1807
1893
|
channels,
|
|
@@ -1810,9 +1896,10 @@ var Preference = class {
|
|
|
1810
1896
|
var _a;
|
|
1811
1897
|
return updatePreference({
|
|
1812
1898
|
emitter: __privateGet(this, _emitter4),
|
|
1813
|
-
apiService: __privateGet(this,
|
|
1899
|
+
apiService: __privateGet(this, _apiService2),
|
|
1814
1900
|
cache: __privateGet(this, _cache4),
|
|
1815
|
-
|
|
1901
|
+
scheduleCache: __privateGet(this, _scheduleCache),
|
|
1902
|
+
useCache: __privateGet(this, _useCache3),
|
|
1816
1903
|
args: {
|
|
1817
1904
|
workflowId: (_a = this.workflow) == null ? void 0 : _a.id,
|
|
1818
1905
|
channels: channels || channelPreferences,
|
|
@@ -1822,15 +1909,17 @@ var Preference = class {
|
|
|
1822
1909
|
}
|
|
1823
1910
|
};
|
|
1824
1911
|
_emitter4 = new WeakMap();
|
|
1825
|
-
|
|
1912
|
+
_apiService2 = new WeakMap();
|
|
1826
1913
|
_cache4 = new WeakMap();
|
|
1827
|
-
|
|
1914
|
+
_scheduleCache = new WeakMap();
|
|
1915
|
+
_useCache3 = new WeakMap();
|
|
1828
1916
|
|
|
1829
1917
|
// src/preferences/helpers.ts
|
|
1830
1918
|
var updatePreference = (_0) => __async(void 0, [_0], function* ({
|
|
1831
1919
|
emitter,
|
|
1832
1920
|
apiService,
|
|
1833
1921
|
cache,
|
|
1922
|
+
scheduleCache,
|
|
1834
1923
|
useCache,
|
|
1835
1924
|
args
|
|
1836
1925
|
}) {
|
|
@@ -1848,6 +1937,7 @@ var updatePreference = (_0) => __async(void 0, [_0], function* ({
|
|
|
1848
1937
|
emitterInstance: emitter,
|
|
1849
1938
|
inboxServiceInstance: apiService,
|
|
1850
1939
|
cache,
|
|
1940
|
+
scheduleCache,
|
|
1851
1941
|
useCache
|
|
1852
1942
|
}
|
|
1853
1943
|
) : void 0
|
|
@@ -1856,13 +1946,14 @@ var updatePreference = (_0) => __async(void 0, [_0], function* ({
|
|
|
1856
1946
|
if (workflowId) {
|
|
1857
1947
|
response = yield apiService.updateWorkflowPreferences({ workflowId, channels });
|
|
1858
1948
|
} else {
|
|
1859
|
-
optimisticUpdateWorkflowPreferences({ emitter, apiService, cache, useCache, args });
|
|
1949
|
+
optimisticUpdateWorkflowPreferences({ emitter, apiService, cache, scheduleCache, useCache, args });
|
|
1860
1950
|
response = yield apiService.updateGlobalPreferences(channels);
|
|
1861
1951
|
}
|
|
1862
1952
|
const preference = new Preference(response, {
|
|
1863
1953
|
emitterInstance: emitter,
|
|
1864
1954
|
inboxServiceInstance: apiService,
|
|
1865
1955
|
cache,
|
|
1956
|
+
scheduleCache,
|
|
1866
1957
|
useCache
|
|
1867
1958
|
});
|
|
1868
1959
|
emitter.emit("preference.update.resolved", { args, data: preference });
|
|
@@ -1876,6 +1967,7 @@ var bulkUpdatePreference = (_0) => __async(void 0, [_0], function* ({
|
|
|
1876
1967
|
emitter,
|
|
1877
1968
|
apiService,
|
|
1878
1969
|
cache,
|
|
1970
|
+
scheduleCache,
|
|
1879
1971
|
useCache,
|
|
1880
1972
|
args
|
|
1881
1973
|
}) {
|
|
@@ -1893,6 +1985,7 @@ var bulkUpdatePreference = (_0) => __async(void 0, [_0], function* ({
|
|
|
1893
1985
|
emitterInstance: emitter,
|
|
1894
1986
|
inboxServiceInstance: apiService,
|
|
1895
1987
|
cache,
|
|
1988
|
+
scheduleCache,
|
|
1896
1989
|
useCache
|
|
1897
1990
|
}
|
|
1898
1991
|
) : void 0
|
|
@@ -1913,6 +2006,7 @@ var bulkUpdatePreference = (_0) => __async(void 0, [_0], function* ({
|
|
|
1913
2006
|
emitterInstance: emitter,
|
|
1914
2007
|
inboxServiceInstance: apiService,
|
|
1915
2008
|
cache,
|
|
2009
|
+
scheduleCache,
|
|
1916
2010
|
useCache
|
|
1917
2011
|
})
|
|
1918
2012
|
);
|
|
@@ -1927,6 +2021,7 @@ var optimisticUpdateWorkflowPreferences = ({
|
|
|
1927
2021
|
emitter,
|
|
1928
2022
|
apiService,
|
|
1929
2023
|
cache,
|
|
2024
|
+
scheduleCache,
|
|
1930
2025
|
useCache,
|
|
1931
2026
|
args
|
|
1932
2027
|
}) => {
|
|
@@ -1946,6 +2041,7 @@ var optimisticUpdateWorkflowPreferences = ({
|
|
|
1946
2041
|
emitterInstance: emitter,
|
|
1947
2042
|
inboxServiceInstance: apiService,
|
|
1948
2043
|
cache,
|
|
2044
|
+
scheduleCache,
|
|
1949
2045
|
useCache
|
|
1950
2046
|
}) : void 0;
|
|
1951
2047
|
if (updatedPreference) {
|
|
@@ -1960,9 +2056,326 @@ var optimisticUpdateWorkflowPreferences = ({
|
|
|
1960
2056
|
}
|
|
1961
2057
|
});
|
|
1962
2058
|
};
|
|
2059
|
+
var updateSchedule = (_0) => __async(void 0, [_0], function* ({
|
|
2060
|
+
emitter,
|
|
2061
|
+
apiService,
|
|
2062
|
+
cache,
|
|
2063
|
+
useCache,
|
|
2064
|
+
args
|
|
2065
|
+
}) {
|
|
2066
|
+
var _a, _b;
|
|
2067
|
+
try {
|
|
2068
|
+
const { isEnabled, weeklySchedule } = args;
|
|
2069
|
+
const optimisticallyUpdatedSchedule = new Schedule(
|
|
2070
|
+
{
|
|
2071
|
+
isEnabled,
|
|
2072
|
+
weeklySchedule
|
|
2073
|
+
},
|
|
2074
|
+
{
|
|
2075
|
+
emitterInstance: emitter,
|
|
2076
|
+
inboxServiceInstance: apiService,
|
|
2077
|
+
cache,
|
|
2078
|
+
useCache
|
|
2079
|
+
}
|
|
2080
|
+
);
|
|
2081
|
+
emitter.emit("preference.schedule.update.pending", { args, data: optimisticallyUpdatedSchedule });
|
|
2082
|
+
const response = yield apiService.updateGlobalPreferences({
|
|
2083
|
+
schedule: {
|
|
2084
|
+
isEnabled,
|
|
2085
|
+
weeklySchedule
|
|
2086
|
+
}
|
|
2087
|
+
});
|
|
2088
|
+
const updatedSchedule = new Schedule(
|
|
2089
|
+
{
|
|
2090
|
+
isEnabled: (_a = response.schedule) == null ? void 0 : _a.isEnabled,
|
|
2091
|
+
weeklySchedule: (_b = response.schedule) == null ? void 0 : _b.weeklySchedule
|
|
2092
|
+
},
|
|
2093
|
+
{
|
|
2094
|
+
emitterInstance: emitter,
|
|
2095
|
+
inboxServiceInstance: apiService,
|
|
2096
|
+
cache,
|
|
2097
|
+
useCache
|
|
2098
|
+
}
|
|
2099
|
+
);
|
|
2100
|
+
emitter.emit("preference.schedule.update.resolved", {
|
|
2101
|
+
args,
|
|
2102
|
+
data: updatedSchedule
|
|
2103
|
+
});
|
|
2104
|
+
return { data: updatedSchedule };
|
|
2105
|
+
} catch (error) {
|
|
2106
|
+
emitter.emit("preference.schedule.update.resolved", { args, error });
|
|
2107
|
+
return { error: new NovuError("Failed to update preference", error) };
|
|
2108
|
+
}
|
|
2109
|
+
});
|
|
2110
|
+
|
|
2111
|
+
// src/preferences/preference-schedule.ts
|
|
2112
|
+
var _useCache4;
|
|
2113
|
+
var PreferenceSchedule = class extends BaseModule {
|
|
2114
|
+
constructor({
|
|
2115
|
+
cache,
|
|
2116
|
+
useCache,
|
|
2117
|
+
inboxServiceInstance,
|
|
2118
|
+
eventEmitterInstance
|
|
2119
|
+
}) {
|
|
2120
|
+
super({
|
|
2121
|
+
eventEmitterInstance,
|
|
2122
|
+
inboxServiceInstance
|
|
2123
|
+
});
|
|
2124
|
+
__privateAdd(this, _useCache4);
|
|
2125
|
+
this.cache = cache;
|
|
2126
|
+
__privateSet(this, _useCache4, useCache);
|
|
2127
|
+
}
|
|
2128
|
+
get() {
|
|
2129
|
+
return __async(this, null, function* () {
|
|
2130
|
+
return this.callWithSession(() => __async(this, null, function* () {
|
|
2131
|
+
var _a, _b;
|
|
2132
|
+
try {
|
|
2133
|
+
let data = __privateGet(this, _useCache4) ? this.cache.getAll() : void 0;
|
|
2134
|
+
this._emitter.emit("preference.schedule.get.pending", { args: void 0, data });
|
|
2135
|
+
if (!data) {
|
|
2136
|
+
const globalPreference = yield this._inboxService.fetchGlobalPreferences();
|
|
2137
|
+
data = new Schedule(
|
|
2138
|
+
{
|
|
2139
|
+
isEnabled: (_a = globalPreference == null ? void 0 : globalPreference.schedule) == null ? void 0 : _a.isEnabled,
|
|
2140
|
+
weeklySchedule: (_b = globalPreference == null ? void 0 : globalPreference.schedule) == null ? void 0 : _b.weeklySchedule
|
|
2141
|
+
},
|
|
2142
|
+
{
|
|
2143
|
+
emitterInstance: this._emitter,
|
|
2144
|
+
inboxServiceInstance: this._inboxService,
|
|
2145
|
+
cache: this.cache,
|
|
2146
|
+
useCache: __privateGet(this, _useCache4)
|
|
2147
|
+
}
|
|
2148
|
+
);
|
|
2149
|
+
if (__privateGet(this, _useCache4)) {
|
|
2150
|
+
this.cache.set(data);
|
|
2151
|
+
data = this.cache.getAll();
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
this._emitter.emit("preference.schedule.get.resolved", {
|
|
2155
|
+
args: void 0,
|
|
2156
|
+
data
|
|
2157
|
+
});
|
|
2158
|
+
return { data };
|
|
2159
|
+
} catch (error) {
|
|
2160
|
+
this._emitter.emit("preference.schedule.get.resolved", { args: void 0, error });
|
|
2161
|
+
throw error;
|
|
2162
|
+
}
|
|
2163
|
+
}));
|
|
2164
|
+
});
|
|
2165
|
+
}
|
|
2166
|
+
update(args) {
|
|
2167
|
+
return __async(this, null, function* () {
|
|
2168
|
+
return this.callWithSession(
|
|
2169
|
+
() => updateSchedule({
|
|
2170
|
+
emitter: this._emitter,
|
|
2171
|
+
apiService: this._inboxService,
|
|
2172
|
+
cache: this.cache,
|
|
2173
|
+
useCache: __privateGet(this, _useCache4),
|
|
2174
|
+
args
|
|
2175
|
+
})
|
|
2176
|
+
);
|
|
2177
|
+
});
|
|
2178
|
+
}
|
|
2179
|
+
};
|
|
2180
|
+
_useCache4 = new WeakMap();
|
|
2181
|
+
|
|
2182
|
+
// src/cache/preferences-cache.ts
|
|
2183
|
+
var updateEvents2 = [
|
|
2184
|
+
"preference.update.pending",
|
|
2185
|
+
"preference.update.resolved",
|
|
2186
|
+
"preferences.bulk_update.pending",
|
|
2187
|
+
"preferences.bulk_update.resolved"
|
|
2188
|
+
];
|
|
2189
|
+
var scheduleUpdateEvents = [
|
|
2190
|
+
"preference.schedule.update.pending",
|
|
2191
|
+
"preference.schedule.update.resolved"
|
|
2192
|
+
];
|
|
2193
|
+
var excludeEmpty2 = ({ tags, severity }) => Object.entries({ tags, severity }).reduce((acc, [key, value]) => {
|
|
2194
|
+
if (value === null || value === void 0 || Array.isArray(value) && value.length === 0) {
|
|
2195
|
+
return acc;
|
|
2196
|
+
}
|
|
2197
|
+
acc[key] = value;
|
|
2198
|
+
return acc;
|
|
2199
|
+
}, {});
|
|
2200
|
+
var getCacheKey2 = ({ tags, severity }) => {
|
|
2201
|
+
return JSON.stringify(excludeEmpty2({ tags, severity }));
|
|
2202
|
+
};
|
|
2203
|
+
var _emitter5, _cache5;
|
|
2204
|
+
var PreferencesCache = class {
|
|
2205
|
+
constructor({ emitterInstance }) {
|
|
2206
|
+
__privateAdd(this, _emitter5);
|
|
2207
|
+
__privateAdd(this, _cache5);
|
|
2208
|
+
this.updatePreference = (key, data) => {
|
|
2209
|
+
const preferences = __privateGet(this, _cache5).get(key);
|
|
2210
|
+
if (!preferences) {
|
|
2211
|
+
return false;
|
|
2212
|
+
}
|
|
2213
|
+
const index = preferences.findIndex(
|
|
2214
|
+
(el) => {
|
|
2215
|
+
var _a, _b;
|
|
2216
|
+
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 */;
|
|
2217
|
+
}
|
|
2218
|
+
);
|
|
2219
|
+
if (index === -1) {
|
|
2220
|
+
return false;
|
|
2221
|
+
}
|
|
2222
|
+
const updatedPreferences = [...preferences];
|
|
2223
|
+
updatedPreferences[index] = data;
|
|
2224
|
+
__privateGet(this, _cache5).set(key, updatedPreferences);
|
|
2225
|
+
return true;
|
|
2226
|
+
};
|
|
2227
|
+
this.updatePreferenceSchedule = (key, data) => {
|
|
2228
|
+
const preferences = __privateGet(this, _cache5).get(key);
|
|
2229
|
+
if (!preferences) {
|
|
2230
|
+
return false;
|
|
2231
|
+
}
|
|
2232
|
+
const index = preferences.findIndex((el) => el.level === "global" /* GLOBAL */);
|
|
2233
|
+
if (index === -1) {
|
|
2234
|
+
return false;
|
|
2235
|
+
}
|
|
2236
|
+
const updatedPreferences = [...preferences];
|
|
2237
|
+
updatedPreferences[index].schedule = data;
|
|
2238
|
+
__privateGet(this, _cache5).set(key, updatedPreferences);
|
|
2239
|
+
return true;
|
|
2240
|
+
};
|
|
2241
|
+
this.handleScheduleEvent = ({ data }) => {
|
|
2242
|
+
var _a;
|
|
2243
|
+
if (!data) {
|
|
2244
|
+
return;
|
|
2245
|
+
}
|
|
2246
|
+
const cacheKeys = __privateGet(this, _cache5).keys();
|
|
2247
|
+
const uniqueFilterKeys = /* @__PURE__ */ new Set();
|
|
2248
|
+
for (const key of cacheKeys) {
|
|
2249
|
+
const hasUpdatedPreference = this.updatePreferenceSchedule(key, data);
|
|
2250
|
+
const updatedPreference = __privateGet(this, _cache5).get(key);
|
|
2251
|
+
if (!hasUpdatedPreference || !updatedPreference) {
|
|
2252
|
+
continue;
|
|
2253
|
+
}
|
|
2254
|
+
uniqueFilterKeys.add(key);
|
|
2255
|
+
}
|
|
2256
|
+
for (const key of uniqueFilterKeys) {
|
|
2257
|
+
__privateGet(this, _emitter5).emit("preferences.list.updated", {
|
|
2258
|
+
data: (_a = __privateGet(this, _cache5).get(key)) != null ? _a : []
|
|
2259
|
+
});
|
|
2260
|
+
}
|
|
2261
|
+
};
|
|
2262
|
+
this.handlePreferenceEvent = ({ data }) => {
|
|
2263
|
+
if (!data) {
|
|
2264
|
+
return;
|
|
2265
|
+
}
|
|
2266
|
+
const preferences = Array.isArray(data) ? data : [data];
|
|
2267
|
+
const uniqueFilterKeys = /* @__PURE__ */ new Set();
|
|
2268
|
+
__privateGet(this, _cache5).keys().forEach((key) => {
|
|
2269
|
+
preferences.forEach((preference) => {
|
|
2270
|
+
const hasUpdatedPreference = this.updatePreference(key, preference);
|
|
2271
|
+
const updatedPreference = __privateGet(this, _cache5).get(key);
|
|
2272
|
+
if (!hasUpdatedPreference || !updatedPreference) {
|
|
2273
|
+
return;
|
|
2274
|
+
}
|
|
2275
|
+
uniqueFilterKeys.add(key);
|
|
2276
|
+
});
|
|
2277
|
+
});
|
|
2278
|
+
uniqueFilterKeys.forEach((key) => {
|
|
2279
|
+
var _a;
|
|
2280
|
+
__privateGet(this, _emitter5).emit("preferences.list.updated", {
|
|
2281
|
+
data: (_a = __privateGet(this, _cache5).get(key)) != null ? _a : []
|
|
2282
|
+
});
|
|
2283
|
+
});
|
|
2284
|
+
};
|
|
2285
|
+
__privateSet(this, _emitter5, emitterInstance);
|
|
2286
|
+
for (const event of updateEvents2) {
|
|
2287
|
+
__privateGet(this, _emitter5).on(event, this.handlePreferenceEvent);
|
|
2288
|
+
}
|
|
2289
|
+
for (const event of scheduleUpdateEvents) {
|
|
2290
|
+
__privateGet(this, _emitter5).on(event, this.handleScheduleEvent);
|
|
2291
|
+
}
|
|
2292
|
+
__privateSet(this, _cache5, new InMemoryCache());
|
|
2293
|
+
}
|
|
2294
|
+
has(args) {
|
|
2295
|
+
return __privateGet(this, _cache5).get(getCacheKey2(args)) !== void 0;
|
|
2296
|
+
}
|
|
2297
|
+
set(args, data) {
|
|
2298
|
+
__privateGet(this, _cache5).set(getCacheKey2(args), data);
|
|
2299
|
+
}
|
|
2300
|
+
getAll(args) {
|
|
2301
|
+
if (this.has(args)) {
|
|
2302
|
+
return __privateGet(this, _cache5).get(getCacheKey2(args));
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
clearAll() {
|
|
2306
|
+
__privateGet(this, _cache5).clear();
|
|
2307
|
+
}
|
|
2308
|
+
};
|
|
2309
|
+
_emitter5 = new WeakMap();
|
|
2310
|
+
_cache5 = new WeakMap();
|
|
2311
|
+
|
|
2312
|
+
// src/cache/schedule-cache.ts
|
|
2313
|
+
var updateEvents3 = [
|
|
2314
|
+
"preference.schedule.update.pending",
|
|
2315
|
+
"preference.schedule.update.resolved"
|
|
2316
|
+
];
|
|
2317
|
+
var getCacheKey3 = () => {
|
|
2318
|
+
return "schedule";
|
|
2319
|
+
};
|
|
2320
|
+
var _emitter6, _cache6;
|
|
2321
|
+
var ScheduleCache = class {
|
|
2322
|
+
constructor({ emitterInstance }) {
|
|
2323
|
+
__privateAdd(this, _emitter6);
|
|
2324
|
+
__privateAdd(this, _cache6);
|
|
2325
|
+
this.updateScheduleInCache = (key, data) => {
|
|
2326
|
+
const schedule = __privateGet(this, _cache6).get(key);
|
|
2327
|
+
if (!schedule) {
|
|
2328
|
+
return false;
|
|
2329
|
+
}
|
|
2330
|
+
__privateGet(this, _cache6).set(key, data);
|
|
2331
|
+
return true;
|
|
2332
|
+
};
|
|
2333
|
+
this.handleScheduleEvent = ({ data }) => {
|
|
2334
|
+
if (!data) {
|
|
2335
|
+
return;
|
|
2336
|
+
}
|
|
2337
|
+
const uniqueFilterKeys = /* @__PURE__ */ new Set();
|
|
2338
|
+
const keys = __privateGet(this, _cache6).keys();
|
|
2339
|
+
for (const key of keys) {
|
|
2340
|
+
const hasUpdatedSchedule = this.updateScheduleInCache(key, data);
|
|
2341
|
+
const updatedSchedule = __privateGet(this, _cache6).get(key);
|
|
2342
|
+
if (!hasUpdatedSchedule || !updatedSchedule) {
|
|
2343
|
+
continue;
|
|
2344
|
+
}
|
|
2345
|
+
uniqueFilterKeys.add(key);
|
|
2346
|
+
}
|
|
2347
|
+
for (const key of uniqueFilterKeys) {
|
|
2348
|
+
__privateGet(this, _emitter6).emit("preference.schedule.get.updated", {
|
|
2349
|
+
data: __privateGet(this, _cache6).get(key)
|
|
2350
|
+
});
|
|
2351
|
+
}
|
|
2352
|
+
};
|
|
2353
|
+
__privateSet(this, _emitter6, emitterInstance);
|
|
2354
|
+
for (const event of updateEvents3) {
|
|
2355
|
+
__privateGet(this, _emitter6).on(event, this.handleScheduleEvent);
|
|
2356
|
+
}
|
|
2357
|
+
__privateSet(this, _cache6, new InMemoryCache());
|
|
2358
|
+
}
|
|
2359
|
+
has() {
|
|
2360
|
+
return __privateGet(this, _cache6).get(getCacheKey3()) !== void 0;
|
|
2361
|
+
}
|
|
2362
|
+
set(data) {
|
|
2363
|
+
__privateGet(this, _cache6).set(getCacheKey3(), data);
|
|
2364
|
+
}
|
|
2365
|
+
getAll() {
|
|
2366
|
+
if (this.has()) {
|
|
2367
|
+
return __privateGet(this, _cache6).get(getCacheKey3());
|
|
2368
|
+
}
|
|
2369
|
+
}
|
|
2370
|
+
clearAll() {
|
|
2371
|
+
__privateGet(this, _cache6).clear();
|
|
2372
|
+
}
|
|
2373
|
+
};
|
|
2374
|
+
_emitter6 = new WeakMap();
|
|
2375
|
+
_cache6 = new WeakMap();
|
|
1963
2376
|
|
|
1964
2377
|
// src/preferences/preferences.ts
|
|
1965
|
-
var
|
|
2378
|
+
var _useCache5;
|
|
1966
2379
|
var Preferences = class extends BaseModule {
|
|
1967
2380
|
constructor({
|
|
1968
2381
|
useCache,
|
|
@@ -1973,18 +2386,27 @@ var Preferences = class extends BaseModule {
|
|
|
1973
2386
|
eventEmitterInstance,
|
|
1974
2387
|
inboxServiceInstance
|
|
1975
2388
|
});
|
|
1976
|
-
__privateAdd(this,
|
|
2389
|
+
__privateAdd(this, _useCache5);
|
|
1977
2390
|
this.cache = new PreferencesCache({
|
|
1978
2391
|
emitterInstance: this._emitter
|
|
1979
2392
|
});
|
|
1980
|
-
|
|
2393
|
+
this.scheduleCache = new ScheduleCache({
|
|
2394
|
+
emitterInstance: this._emitter
|
|
2395
|
+
});
|
|
2396
|
+
__privateSet(this, _useCache5, useCache);
|
|
2397
|
+
this.schedule = new PreferenceSchedule({
|
|
2398
|
+
cache: this.scheduleCache,
|
|
2399
|
+
useCache,
|
|
2400
|
+
inboxServiceInstance,
|
|
2401
|
+
eventEmitterInstance
|
|
2402
|
+
});
|
|
1981
2403
|
}
|
|
1982
2404
|
list() {
|
|
1983
2405
|
return __async(this, arguments, function* (args = {}) {
|
|
1984
2406
|
return this.callWithSession(() => __async(this, null, function* () {
|
|
1985
2407
|
var _a;
|
|
1986
2408
|
try {
|
|
1987
|
-
let data = __privateGet(this,
|
|
2409
|
+
let data = __privateGet(this, _useCache5) ? this.cache.getAll(args) : void 0;
|
|
1988
2410
|
this._emitter.emit("preferences.list.pending", { args, data });
|
|
1989
2411
|
if (!data) {
|
|
1990
2412
|
const response = yield this._inboxService.fetchPreferences({
|
|
@@ -1997,10 +2419,11 @@ var Preferences = class extends BaseModule {
|
|
|
1997
2419
|
emitterInstance: this._emitter,
|
|
1998
2420
|
inboxServiceInstance: this._inboxService,
|
|
1999
2421
|
cache: this.cache,
|
|
2000
|
-
|
|
2422
|
+
scheduleCache: this.scheduleCache,
|
|
2423
|
+
useCache: __privateGet(this, _useCache5)
|
|
2001
2424
|
})
|
|
2002
2425
|
);
|
|
2003
|
-
if (__privateGet(this,
|
|
2426
|
+
if (__privateGet(this, _useCache5)) {
|
|
2004
2427
|
this.cache.set(args, data);
|
|
2005
2428
|
data = this.cache.getAll(args);
|
|
2006
2429
|
}
|
|
@@ -2021,7 +2444,8 @@ var Preferences = class extends BaseModule {
|
|
|
2021
2444
|
emitter: this._emitter,
|
|
2022
2445
|
apiService: this._inboxService,
|
|
2023
2446
|
cache: this.cache,
|
|
2024
|
-
|
|
2447
|
+
scheduleCache: this.scheduleCache,
|
|
2448
|
+
useCache: __privateGet(this, _useCache5),
|
|
2025
2449
|
args
|
|
2026
2450
|
})
|
|
2027
2451
|
);
|
|
@@ -2034,14 +2458,15 @@ var Preferences = class extends BaseModule {
|
|
|
2034
2458
|
emitter: this._emitter,
|
|
2035
2459
|
apiService: this._inboxService,
|
|
2036
2460
|
cache: this.cache,
|
|
2037
|
-
|
|
2461
|
+
scheduleCache: this.scheduleCache,
|
|
2462
|
+
useCache: __privateGet(this, _useCache5),
|
|
2038
2463
|
args
|
|
2039
2464
|
})
|
|
2040
2465
|
);
|
|
2041
2466
|
});
|
|
2042
2467
|
}
|
|
2043
2468
|
};
|
|
2044
|
-
|
|
2469
|
+
_useCache5 = new WeakMap();
|
|
2045
2470
|
|
|
2046
2471
|
// src/utils/is-browser.ts
|
|
2047
2472
|
function isBrowser() {
|
|
@@ -2049,13 +2474,13 @@ function isBrowser() {
|
|
|
2049
2474
|
}
|
|
2050
2475
|
|
|
2051
2476
|
// src/session/session.ts
|
|
2052
|
-
var
|
|
2477
|
+
var _emitter7, _inboxService2, _options;
|
|
2053
2478
|
var Session = class {
|
|
2054
2479
|
constructor(options, inboxServiceInstance, eventEmitterInstance) {
|
|
2055
|
-
__privateAdd(this,
|
|
2480
|
+
__privateAdd(this, _emitter7);
|
|
2056
2481
|
__privateAdd(this, _inboxService2);
|
|
2057
2482
|
__privateAdd(this, _options);
|
|
2058
|
-
__privateSet(this,
|
|
2483
|
+
__privateSet(this, _emitter7, eventEmitterInstance);
|
|
2059
2484
|
__privateSet(this, _inboxService2, inboxServiceInstance);
|
|
2060
2485
|
__privateSet(this, _options, options);
|
|
2061
2486
|
}
|
|
@@ -2099,7 +2524,7 @@ var Session = class {
|
|
|
2099
2524
|
if (options) {
|
|
2100
2525
|
__privateSet(this, _options, options);
|
|
2101
2526
|
}
|
|
2102
|
-
const { subscriber, subscriberHash, applicationIdentifier } = __privateGet(this, _options);
|
|
2527
|
+
const { subscriber, subscriberHash, applicationIdentifier, defaultSchedule } = __privateGet(this, _options);
|
|
2103
2528
|
let currentTimezone;
|
|
2104
2529
|
if (isBrowser()) {
|
|
2105
2530
|
currentTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
@@ -2113,14 +2538,15 @@ var Session = class {
|
|
|
2113
2538
|
} else {
|
|
2114
2539
|
this.handleApplicationIdentifier("delete");
|
|
2115
2540
|
}
|
|
2116
|
-
__privateGet(this,
|
|
2541
|
+
__privateGet(this, _emitter7).emit("session.initialize.pending", { args: __privateGet(this, _options) });
|
|
2117
2542
|
const response = yield __privateGet(this, _inboxService2).initializeSession({
|
|
2118
2543
|
applicationIdentifier: finalApplicationIdentifier,
|
|
2119
2544
|
subscriberHash,
|
|
2120
2545
|
subscriber: __spreadProps(__spreadValues({}, subscriber), {
|
|
2121
2546
|
subscriberId: (_c = subscriber == null ? void 0 : subscriber.subscriberId) != null ? _c : "",
|
|
2122
2547
|
timezone: (_d = subscriber == null ? void 0 : subscriber.timezone) != null ? _d : currentTimezone
|
|
2123
|
-
})
|
|
2548
|
+
}),
|
|
2549
|
+
defaultSchedule
|
|
2124
2550
|
});
|
|
2125
2551
|
if ((_e = response == null ? void 0 : response.applicationIdentifier) == null ? void 0 : _e.startsWith("pk_keyless_")) {
|
|
2126
2552
|
this.handleApplicationIdentifier("store", response.applicationIdentifier);
|
|
@@ -2128,14 +2554,14 @@ var Session = class {
|
|
|
2128
2554
|
if (!((_f = response == null ? void 0 : response.applicationIdentifier) == null ? void 0 : _f.startsWith("pk_keyless_"))) {
|
|
2129
2555
|
this.handleApplicationIdentifier("delete");
|
|
2130
2556
|
}
|
|
2131
|
-
__privateGet(this,
|
|
2557
|
+
__privateGet(this, _emitter7).emit("session.initialize.resolved", { args: __privateGet(this, _options), data: response });
|
|
2132
2558
|
} catch (error) {
|
|
2133
|
-
__privateGet(this,
|
|
2559
|
+
__privateGet(this, _emitter7).emit("session.initialize.resolved", { args: __privateGet(this, _options), error });
|
|
2134
2560
|
}
|
|
2135
2561
|
});
|
|
2136
2562
|
}
|
|
2137
2563
|
};
|
|
2138
|
-
|
|
2564
|
+
_emitter7 = new WeakMap();
|
|
2139
2565
|
_inboxService2 = new WeakMap();
|
|
2140
2566
|
_options = new WeakMap();
|
|
2141
2567
|
var PRODUCTION_SOCKET_URL = "wss://socket.novu.co";
|
|
@@ -2229,7 +2655,7 @@ var mapToNotification = ({
|
|
|
2229
2655
|
severity
|
|
2230
2656
|
});
|
|
2231
2657
|
};
|
|
2232
|
-
var _token,
|
|
2658
|
+
var _token, _emitter8, _partySocket, _socketUrl, _notificationReceived, _unseenCountChanged, _unreadCountChanged, _handleMessage, _PartySocketClient_instances, initializeSocket_fn, handleConnectSocket_fn, handleDisconnectSocket_fn;
|
|
2233
2659
|
var PartySocketClient = class extends BaseModule {
|
|
2234
2660
|
constructor({
|
|
2235
2661
|
socketUrl,
|
|
@@ -2242,15 +2668,15 @@ var PartySocketClient = class extends BaseModule {
|
|
|
2242
2668
|
});
|
|
2243
2669
|
__privateAdd(this, _PartySocketClient_instances);
|
|
2244
2670
|
__privateAdd(this, _token);
|
|
2245
|
-
__privateAdd(this,
|
|
2671
|
+
__privateAdd(this, _emitter8);
|
|
2246
2672
|
__privateAdd(this, _partySocket);
|
|
2247
2673
|
__privateAdd(this, _socketUrl);
|
|
2248
2674
|
__privateAdd(this, _notificationReceived, (event) => {
|
|
2249
2675
|
try {
|
|
2250
2676
|
const data = JSON.parse(event.data);
|
|
2251
2677
|
if (data.event === "notification_received" /* RECEIVED */) {
|
|
2252
|
-
__privateGet(this,
|
|
2253
|
-
result: new Notification(mapToNotification(data.data.message), __privateGet(this,
|
|
2678
|
+
__privateGet(this, _emitter8).emit(NOTIFICATION_RECEIVED, {
|
|
2679
|
+
result: new Notification(mapToNotification(data.data.message), __privateGet(this, _emitter8), this._inboxService)
|
|
2254
2680
|
});
|
|
2255
2681
|
}
|
|
2256
2682
|
} catch (error) {
|
|
@@ -2261,7 +2687,7 @@ var PartySocketClient = class extends BaseModule {
|
|
|
2261
2687
|
try {
|
|
2262
2688
|
const data = JSON.parse(event.data);
|
|
2263
2689
|
if (data.event === "unseen_count_changed" /* UNSEEN */) {
|
|
2264
|
-
__privateGet(this,
|
|
2690
|
+
__privateGet(this, _emitter8).emit(UNSEEN_COUNT_CHANGED, {
|
|
2265
2691
|
result: data.data.unseenCount
|
|
2266
2692
|
});
|
|
2267
2693
|
}
|
|
@@ -2272,7 +2698,7 @@ var PartySocketClient = class extends BaseModule {
|
|
|
2272
2698
|
try {
|
|
2273
2699
|
const data = JSON.parse(event.data);
|
|
2274
2700
|
if (data.event === "unread_count_changed" /* UNREAD */) {
|
|
2275
|
-
__privateGet(this,
|
|
2701
|
+
__privateGet(this, _emitter8).emit(UNREAD_COUNT_CHANGED, {
|
|
2276
2702
|
result: data.data.counts
|
|
2277
2703
|
});
|
|
2278
2704
|
}
|
|
@@ -2297,7 +2723,7 @@ var PartySocketClient = class extends BaseModule {
|
|
|
2297
2723
|
} catch (error) {
|
|
2298
2724
|
}
|
|
2299
2725
|
});
|
|
2300
|
-
__privateSet(this,
|
|
2726
|
+
__privateSet(this, _emitter8, eventEmitterInstance);
|
|
2301
2727
|
__privateSet(this, _socketUrl, socketUrl != null ? socketUrl : PRODUCTION_SOCKET_URL);
|
|
2302
2728
|
}
|
|
2303
2729
|
onSessionSuccess({ token }) {
|
|
@@ -2324,7 +2750,7 @@ var PartySocketClient = class extends BaseModule {
|
|
|
2324
2750
|
}
|
|
2325
2751
|
};
|
|
2326
2752
|
_token = new WeakMap();
|
|
2327
|
-
|
|
2753
|
+
_emitter8 = new WeakMap();
|
|
2328
2754
|
_partySocket = new WeakMap();
|
|
2329
2755
|
_socketUrl = new WeakMap();
|
|
2330
2756
|
_notificationReceived = new WeakMap();
|
|
@@ -2338,15 +2764,15 @@ initializeSocket_fn = function() {
|
|
|
2338
2764
|
return;
|
|
2339
2765
|
}
|
|
2340
2766
|
const args = { socketUrl: __privateGet(this, _socketUrl) };
|
|
2341
|
-
__privateGet(this,
|
|
2767
|
+
__privateGet(this, _emitter8).emit("socket.connect.pending", { args });
|
|
2342
2768
|
const url = new URL(__privateGet(this, _socketUrl));
|
|
2343
2769
|
url.searchParams.set("token", __privateGet(this, _token));
|
|
2344
2770
|
__privateSet(this, _partySocket, new WebSocket(url.toString()));
|
|
2345
2771
|
__privateGet(this, _partySocket).addEventListener("open", () => {
|
|
2346
|
-
__privateGet(this,
|
|
2772
|
+
__privateGet(this, _emitter8).emit("socket.connect.resolved", { args });
|
|
2347
2773
|
});
|
|
2348
2774
|
__privateGet(this, _partySocket).addEventListener("error", (error) => {
|
|
2349
|
-
__privateGet(this,
|
|
2775
|
+
__privateGet(this, _emitter8).emit("socket.connect.resolved", { args, error });
|
|
2350
2776
|
});
|
|
2351
2777
|
__privateGet(this, _partySocket).addEventListener("message", __privateGet(this, _handleMessage));
|
|
2352
2778
|
});
|
|
@@ -2464,7 +2890,7 @@ var mapToNotification2 = ({
|
|
|
2464
2890
|
severity
|
|
2465
2891
|
});
|
|
2466
2892
|
};
|
|
2467
|
-
var _token2,
|
|
2893
|
+
var _token2, _emitter9, _socketIo, _socketUrl2, _notificationReceived2, _unseenCountChanged2, _unreadCountChanged2, _Socket_instances, initializeSocket_fn2, handleConnectSocket_fn2, handleDisconnectSocket_fn2;
|
|
2468
2894
|
var Socket = class extends BaseModule {
|
|
2469
2895
|
constructor({
|
|
2470
2896
|
socketUrl,
|
|
@@ -2477,25 +2903,25 @@ var Socket = class extends BaseModule {
|
|
|
2477
2903
|
});
|
|
2478
2904
|
__privateAdd(this, _Socket_instances);
|
|
2479
2905
|
__privateAdd(this, _token2);
|
|
2480
|
-
__privateAdd(this,
|
|
2906
|
+
__privateAdd(this, _emitter9);
|
|
2481
2907
|
__privateAdd(this, _socketIo);
|
|
2482
2908
|
__privateAdd(this, _socketUrl2);
|
|
2483
2909
|
__privateAdd(this, _notificationReceived2, ({ message }) => {
|
|
2484
|
-
__privateGet(this,
|
|
2485
|
-
result: new Notification(mapToNotification2(message), __privateGet(this,
|
|
2910
|
+
__privateGet(this, _emitter9).emit(NOTIFICATION_RECEIVED2, {
|
|
2911
|
+
result: new Notification(mapToNotification2(message), __privateGet(this, _emitter9), this._inboxService)
|
|
2486
2912
|
});
|
|
2487
2913
|
});
|
|
2488
2914
|
__privateAdd(this, _unseenCountChanged2, ({ unseenCount }) => {
|
|
2489
|
-
__privateGet(this,
|
|
2915
|
+
__privateGet(this, _emitter9).emit(UNSEEN_COUNT_CHANGED2, {
|
|
2490
2916
|
result: unseenCount
|
|
2491
2917
|
});
|
|
2492
2918
|
});
|
|
2493
2919
|
__privateAdd(this, _unreadCountChanged2, ({ counts }) => {
|
|
2494
|
-
__privateGet(this,
|
|
2920
|
+
__privateGet(this, _emitter9).emit(UNREAD_COUNT_CHANGED2, {
|
|
2495
2921
|
result: counts
|
|
2496
2922
|
});
|
|
2497
2923
|
});
|
|
2498
|
-
__privateSet(this,
|
|
2924
|
+
__privateSet(this, _emitter9, eventEmitterInstance);
|
|
2499
2925
|
__privateSet(this, _socketUrl2, socketUrl != null ? socketUrl : PRODUCTION_SOCKET_URL2);
|
|
2500
2926
|
}
|
|
2501
2927
|
onSessionSuccess({ token }) {
|
|
@@ -2522,7 +2948,7 @@ var Socket = class extends BaseModule {
|
|
|
2522
2948
|
}
|
|
2523
2949
|
};
|
|
2524
2950
|
_token2 = new WeakMap();
|
|
2525
|
-
|
|
2951
|
+
_emitter9 = new WeakMap();
|
|
2526
2952
|
_socketIo = new WeakMap();
|
|
2527
2953
|
_socketUrl2 = new WeakMap();
|
|
2528
2954
|
_notificationReceived2 = new WeakMap();
|
|
@@ -2536,7 +2962,7 @@ initializeSocket_fn2 = function() {
|
|
|
2536
2962
|
return;
|
|
2537
2963
|
}
|
|
2538
2964
|
const args = { socketUrl: __privateGet(this, _socketUrl2) };
|
|
2539
|
-
__privateGet(this,
|
|
2965
|
+
__privateGet(this, _emitter9).emit("socket.connect.pending", { args });
|
|
2540
2966
|
__privateSet(this, _socketIo, io(__privateGet(this, _socketUrl2), {
|
|
2541
2967
|
reconnectionDelayMax: 1e4,
|
|
2542
2968
|
transports: ["websocket"],
|
|
@@ -2545,10 +2971,10 @@ initializeSocket_fn2 = function() {
|
|
|
2545
2971
|
}
|
|
2546
2972
|
}));
|
|
2547
2973
|
__privateGet(this, _socketIo).on("connect", () => {
|
|
2548
|
-
__privateGet(this,
|
|
2974
|
+
__privateGet(this, _emitter9).emit("socket.connect.resolved", { args });
|
|
2549
2975
|
});
|
|
2550
2976
|
__privateGet(this, _socketIo).on("connect_error", (error) => {
|
|
2551
|
-
__privateGet(this,
|
|
2977
|
+
__privateGet(this, _emitter9).emit("socket.connect.resolved", { args, error });
|
|
2552
2978
|
});
|
|
2553
2979
|
(_a = __privateGet(this, _socketIo)) == null ? void 0 : _a.on("notification_received" /* RECEIVED */, __privateGet(this, _notificationReceived2));
|
|
2554
2980
|
(_b = __privateGet(this, _socketIo)) == null ? void 0 : _b.on("unseen_count_changed" /* UNSEEN */, __privateGet(this, _unseenCountChanged2));
|
|
@@ -2622,10 +3048,10 @@ function createSocket({
|
|
|
2622
3048
|
}
|
|
2623
3049
|
|
|
2624
3050
|
// src/novu.ts
|
|
2625
|
-
var
|
|
3051
|
+
var _emitter10, _session, _inboxService3;
|
|
2626
3052
|
var Novu = class {
|
|
2627
3053
|
constructor(options) {
|
|
2628
|
-
__privateAdd(this,
|
|
3054
|
+
__privateAdd(this, _emitter10);
|
|
2629
3055
|
__privateAdd(this, _session);
|
|
2630
3056
|
__privateAdd(this, _inboxService3);
|
|
2631
3057
|
var _a, _b;
|
|
@@ -2633,43 +3059,44 @@ var Novu = class {
|
|
|
2633
3059
|
apiUrl: options.apiUrl || options.backendUrl,
|
|
2634
3060
|
userAgent: options.__userAgent
|
|
2635
3061
|
}));
|
|
2636
|
-
__privateSet(this,
|
|
3062
|
+
__privateSet(this, _emitter10, new NovuEventEmitter());
|
|
2637
3063
|
__privateSet(this, _session, new Session(
|
|
2638
3064
|
{
|
|
2639
3065
|
applicationIdentifier: options.applicationIdentifier || "",
|
|
2640
3066
|
subscriberHash: options.subscriberHash,
|
|
2641
|
-
subscriber: buildSubscriber({ subscriberId: options.subscriberId, subscriber: options.subscriber })
|
|
3067
|
+
subscriber: buildSubscriber({ subscriberId: options.subscriberId, subscriber: options.subscriber }),
|
|
3068
|
+
defaultSchedule: options.defaultSchedule
|
|
2642
3069
|
},
|
|
2643
3070
|
__privateGet(this, _inboxService3),
|
|
2644
|
-
__privateGet(this,
|
|
3071
|
+
__privateGet(this, _emitter10)
|
|
2645
3072
|
));
|
|
2646
3073
|
__privateGet(this, _session).initialize();
|
|
2647
3074
|
this.notifications = new Notifications({
|
|
2648
3075
|
useCache: (_a = options.useCache) != null ? _a : true,
|
|
2649
3076
|
inboxServiceInstance: __privateGet(this, _inboxService3),
|
|
2650
|
-
eventEmitterInstance: __privateGet(this,
|
|
3077
|
+
eventEmitterInstance: __privateGet(this, _emitter10)
|
|
2651
3078
|
});
|
|
2652
3079
|
this.preferences = new Preferences({
|
|
2653
3080
|
useCache: (_b = options.useCache) != null ? _b : true,
|
|
2654
3081
|
inboxServiceInstance: __privateGet(this, _inboxService3),
|
|
2655
|
-
eventEmitterInstance: __privateGet(this,
|
|
3082
|
+
eventEmitterInstance: __privateGet(this, _emitter10)
|
|
2656
3083
|
});
|
|
2657
3084
|
this.socket = createSocket({
|
|
2658
3085
|
socketUrl: options.socketUrl,
|
|
2659
|
-
eventEmitterInstance: __privateGet(this,
|
|
3086
|
+
eventEmitterInstance: __privateGet(this, _emitter10),
|
|
2660
3087
|
inboxServiceInstance: __privateGet(this, _inboxService3)
|
|
2661
3088
|
});
|
|
2662
3089
|
this.on = (eventName, listener) => {
|
|
2663
3090
|
if (this.socket.isSocketEvent(eventName)) {
|
|
2664
3091
|
this.socket.connect();
|
|
2665
3092
|
}
|
|
2666
|
-
const cleanup = __privateGet(this,
|
|
3093
|
+
const cleanup = __privateGet(this, _emitter10).on(eventName, listener);
|
|
2667
3094
|
return () => {
|
|
2668
3095
|
cleanup();
|
|
2669
3096
|
};
|
|
2670
3097
|
};
|
|
2671
3098
|
this.off = (eventName, listener) => {
|
|
2672
|
-
__privateGet(this,
|
|
3099
|
+
__privateGet(this, _emitter10).off(eventName, listener);
|
|
2673
3100
|
};
|
|
2674
3101
|
}
|
|
2675
3102
|
get applicationIdentifier() {
|
|
@@ -2688,7 +3115,7 @@ var Novu = class {
|
|
|
2688
3115
|
});
|
|
2689
3116
|
}
|
|
2690
3117
|
};
|
|
2691
|
-
|
|
3118
|
+
_emitter10 = new WeakMap();
|
|
2692
3119
|
_session = new WeakMap();
|
|
2693
3120
|
_inboxService3 = new WeakMap();
|
|
2694
3121
|
|