@novu/js 3.3.1 → 3.5.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{chunk-DCLHIVKS.js → chunk-ME3JBJPI.js} +205 -62
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js +8 -8
- package/dist/{esm/novu-DJTVB7VN.d.mts → cjs/novu-q3jzGeyW.d.ts} +46 -25
- package/dist/cjs/themes/index.d.ts +2 -2
- package/dist/cjs/{types-BPv1rvbm.d.ts → types-DdImrpw7.d.ts} +25 -4
- package/dist/cjs/ui/index.d.ts +7 -5
- package/dist/cjs/ui/index.js +1383 -590
- package/dist/esm/{chunk-JKFCSXQM.mjs → chunk-P4YVABAC.mjs} +205 -62
- package/dist/esm/index.d.mts +2 -2
- package/dist/esm/index.mjs +1 -1
- package/dist/{cjs/novu-DJTVB7VN.d.ts → esm/novu-q3jzGeyW.d.mts} +46 -25
- package/dist/esm/themes/index.d.mts +2 -2
- package/dist/esm/{types-CYgpCW2I.d.mts → types-CTQLJWIf.d.mts} +25 -4
- package/dist/esm/ui/index.d.mts +7 -5
- package/dist/esm/ui/index.mjs +1382 -589
- package/dist/index.css +1 -1
- package/dist/novu.min.js +11 -11
- package/dist/novu.min.js.gz +0 -0
- package/package.json +16 -16
|
@@ -55,14 +55,27 @@ var arrayValuesEqual = (arr1, arr2) => {
|
|
|
55
55
|
var areTagsEqual = (tags1, tags2) => {
|
|
56
56
|
return arrayValuesEqual(tags1, tags2) || !tags1 && (tags2 == null ? void 0 : tags2.length) === 0 || (tags1 == null ? void 0 : tags1.length) === 0 && !tags2;
|
|
57
57
|
};
|
|
58
|
+
var areDataEqual = (data1, data2) => {
|
|
59
|
+
if (!data1 && !data2) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
if (!data1 || !data2) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
return JSON.stringify(data1) === JSON.stringify(data2);
|
|
67
|
+
} catch (e) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
58
71
|
var isSameFilter = (filter1, filter2) => {
|
|
59
|
-
return areTagsEqual(filter1.tags, filter2.tags) && filter1.read === filter2.read && filter1.archived === filter2.archived && filter1.snoozed === filter2.snoozed;
|
|
72
|
+
return areDataEqual(filter1.data, filter2.data) && areTagsEqual(filter1.tags, filter2.tags) && filter1.read === filter2.read && filter1.archived === filter2.archived && filter1.snoozed === filter2.snoozed;
|
|
60
73
|
};
|
|
61
74
|
|
|
62
75
|
// src/api/http-client.ts
|
|
63
76
|
var DEFAULT_API_VERSION = "v1";
|
|
64
77
|
var DEFAULT_BACKEND_URL = "https://api.novu.co";
|
|
65
|
-
var DEFAULT_USER_AGENT = `${"@novu/js"}@${"3.
|
|
78
|
+
var DEFAULT_USER_AGENT = `${"@novu/js"}@${"3.5.0-rc.1"}`;
|
|
66
79
|
var HttpClient = class {
|
|
67
80
|
constructor(options = {}) {
|
|
68
81
|
const {
|
|
@@ -197,7 +210,8 @@ var InboxService = class {
|
|
|
197
210
|
offset,
|
|
198
211
|
read: read2,
|
|
199
212
|
tags,
|
|
200
|
-
snoozed
|
|
213
|
+
snoozed,
|
|
214
|
+
data
|
|
201
215
|
}) {
|
|
202
216
|
const searchParams = new URLSearchParams(`limit=${limit}`);
|
|
203
217
|
if (after) {
|
|
@@ -218,9 +232,14 @@ var InboxService = class {
|
|
|
218
232
|
if (snoozed !== void 0) {
|
|
219
233
|
searchParams.append("snoozed", `${snoozed}`);
|
|
220
234
|
}
|
|
235
|
+
if (data !== void 0) {
|
|
236
|
+
searchParams.append("data", JSON.stringify(data));
|
|
237
|
+
}
|
|
221
238
|
return chunk7B52C2XE_js.__privateGet(this, _httpClient).get(INBOX_NOTIFICATIONS_ROUTE, searchParams, false);
|
|
222
239
|
}
|
|
223
|
-
count({
|
|
240
|
+
count({
|
|
241
|
+
filters
|
|
242
|
+
}) {
|
|
224
243
|
return chunk7B52C2XE_js.__privateGet(this, _httpClient).get(
|
|
225
244
|
`${INBOX_NOTIFICATIONS_ROUTE}/count`,
|
|
226
245
|
new URLSearchParams({
|
|
@@ -247,14 +266,23 @@ var InboxService = class {
|
|
|
247
266
|
unsnooze(notificationId) {
|
|
248
267
|
return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/unsnooze`);
|
|
249
268
|
}
|
|
250
|
-
readAll({ tags }) {
|
|
251
|
-
return chunk7B52C2XE_js.__privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read`, {
|
|
269
|
+
readAll({ tags, data }) {
|
|
270
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read`, {
|
|
271
|
+
tags,
|
|
272
|
+
data: data ? JSON.stringify(data) : void 0
|
|
273
|
+
});
|
|
252
274
|
}
|
|
253
|
-
archiveAll({ tags }) {
|
|
254
|
-
return chunk7B52C2XE_js.__privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/archive`, {
|
|
275
|
+
archiveAll({ tags, data }) {
|
|
276
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/archive`, {
|
|
277
|
+
tags,
|
|
278
|
+
data: data ? JSON.stringify(data) : void 0
|
|
279
|
+
});
|
|
255
280
|
}
|
|
256
|
-
archiveAllRead({ tags }) {
|
|
257
|
-
return chunk7B52C2XE_js.__privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read-archive`, {
|
|
281
|
+
archiveAllRead({ tags, data }) {
|
|
282
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read-archive`, {
|
|
283
|
+
tags,
|
|
284
|
+
data: data ? JSON.stringify(data) : void 0
|
|
285
|
+
});
|
|
258
286
|
}
|
|
259
287
|
completeAction({
|
|
260
288
|
actionType,
|
|
@@ -280,6 +308,9 @@ var InboxService = class {
|
|
|
280
308
|
const query = queryParams.size ? `?${queryParams.toString()}` : "";
|
|
281
309
|
return chunk7B52C2XE_js.__privateGet(this, _httpClient).get(`${INBOX_ROUTE}/preferences${query}`);
|
|
282
310
|
}
|
|
311
|
+
bulkUpdatePreferences(preferences) {
|
|
312
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/bulk`, { preferences });
|
|
313
|
+
}
|
|
283
314
|
updateGlobalPreferences(channels) {
|
|
284
315
|
return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences`, channels);
|
|
285
316
|
}
|
|
@@ -797,10 +828,11 @@ var readAll = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
|
|
|
797
828
|
emitter,
|
|
798
829
|
inboxService,
|
|
799
830
|
notificationsCache,
|
|
800
|
-
tags
|
|
831
|
+
tags,
|
|
832
|
+
data
|
|
801
833
|
}) {
|
|
802
834
|
try {
|
|
803
|
-
const notifications = notificationsCache.getUniqueNotifications({ tags });
|
|
835
|
+
const notifications = notificationsCache.getUniqueNotifications({ tags, data });
|
|
804
836
|
const optimisticNotifications = notifications.map(
|
|
805
837
|
(notification) => new Notification(
|
|
806
838
|
chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, notification), {
|
|
@@ -813,12 +845,12 @@ var readAll = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
|
|
|
813
845
|
inboxService
|
|
814
846
|
)
|
|
815
847
|
);
|
|
816
|
-
emitter.emit("notifications.read_all.pending", { args: { tags }, data: optimisticNotifications });
|
|
817
|
-
yield inboxService.readAll({ tags });
|
|
818
|
-
emitter.emit("notifications.read_all.resolved", { args: { tags }, data: optimisticNotifications });
|
|
848
|
+
emitter.emit("notifications.read_all.pending", { args: { tags, data }, data: optimisticNotifications });
|
|
849
|
+
yield inboxService.readAll({ tags, data });
|
|
850
|
+
emitter.emit("notifications.read_all.resolved", { args: { tags, data }, data: optimisticNotifications });
|
|
819
851
|
return {};
|
|
820
852
|
} catch (error) {
|
|
821
|
-
emitter.emit("notifications.read_all.resolved", { args: { tags }, error });
|
|
853
|
+
emitter.emit("notifications.read_all.resolved", { args: { tags, data }, error });
|
|
822
854
|
return { error: new NovuError("Failed to read all notifications", error) };
|
|
823
855
|
}
|
|
824
856
|
});
|
|
@@ -826,10 +858,11 @@ var archiveAll = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
|
|
|
826
858
|
emitter,
|
|
827
859
|
inboxService,
|
|
828
860
|
notificationsCache,
|
|
829
|
-
tags
|
|
861
|
+
tags,
|
|
862
|
+
data
|
|
830
863
|
}) {
|
|
831
864
|
try {
|
|
832
|
-
const notifications = notificationsCache.getUniqueNotifications({ tags });
|
|
865
|
+
const notifications = notificationsCache.getUniqueNotifications({ tags, data });
|
|
833
866
|
const optimisticNotifications = notifications.map(
|
|
834
867
|
(notification) => new Notification(
|
|
835
868
|
chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, notification), {
|
|
@@ -842,12 +875,12 @@ var archiveAll = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
|
|
|
842
875
|
inboxService
|
|
843
876
|
)
|
|
844
877
|
);
|
|
845
|
-
emitter.emit("notifications.archive_all.pending", { args: { tags }, data: optimisticNotifications });
|
|
846
|
-
yield inboxService.archiveAll({ tags });
|
|
847
|
-
emitter.emit("notifications.archive_all.resolved", { args: { tags }, data: optimisticNotifications });
|
|
878
|
+
emitter.emit("notifications.archive_all.pending", { args: { tags, data }, data: optimisticNotifications });
|
|
879
|
+
yield inboxService.archiveAll({ tags, data });
|
|
880
|
+
emitter.emit("notifications.archive_all.resolved", { args: { tags, data }, data: optimisticNotifications });
|
|
848
881
|
return {};
|
|
849
882
|
} catch (error) {
|
|
850
|
-
emitter.emit("notifications.archive_all.resolved", { args: { tags }, error });
|
|
883
|
+
emitter.emit("notifications.archive_all.resolved", { args: { tags, data }, error });
|
|
851
884
|
return { error: new NovuError("Failed to archive all notifications", error) };
|
|
852
885
|
}
|
|
853
886
|
});
|
|
@@ -855,10 +888,11 @@ var archiveAllRead = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
|
|
|
855
888
|
emitter,
|
|
856
889
|
inboxService,
|
|
857
890
|
notificationsCache,
|
|
858
|
-
tags
|
|
891
|
+
tags,
|
|
892
|
+
data
|
|
859
893
|
}) {
|
|
860
894
|
try {
|
|
861
|
-
const notifications = notificationsCache.getUniqueNotifications({ tags, read: true });
|
|
895
|
+
const notifications = notificationsCache.getUniqueNotifications({ tags, data, read: true });
|
|
862
896
|
const optimisticNotifications = notifications.map(
|
|
863
897
|
(notification) => new Notification(
|
|
864
898
|
chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, notification), { isArchived: true, archivedAt: (/* @__PURE__ */ new Date()).toISOString() }),
|
|
@@ -866,12 +900,12 @@ var archiveAllRead = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
|
|
|
866
900
|
inboxService
|
|
867
901
|
)
|
|
868
902
|
);
|
|
869
|
-
emitter.emit("notifications.archive_all_read.pending", { args: { tags }, data: optimisticNotifications });
|
|
870
|
-
yield inboxService.archiveAllRead({ tags });
|
|
871
|
-
emitter.emit("notifications.archive_all_read.resolved", { args: { tags }, data: optimisticNotifications });
|
|
903
|
+
emitter.emit("notifications.archive_all_read.pending", { args: { tags, data }, data: optimisticNotifications });
|
|
904
|
+
yield inboxService.archiveAllRead({ tags, data });
|
|
905
|
+
emitter.emit("notifications.archive_all_read.resolved", { args: { tags, data }, data: optimisticNotifications });
|
|
872
906
|
return {};
|
|
873
907
|
} catch (error) {
|
|
874
|
-
emitter.emit("notifications.archive_all_read.resolved", { args: { tags }, error });
|
|
908
|
+
emitter.emit("notifications.archive_all_read.resolved", { args: { tags, data }, error });
|
|
875
909
|
return { error: new NovuError("Failed to archive all read notifications", error) };
|
|
876
910
|
}
|
|
877
911
|
});
|
|
@@ -908,20 +942,21 @@ var InMemoryCache = class {
|
|
|
908
942
|
_cache = new WeakMap();
|
|
909
943
|
|
|
910
944
|
// src/cache/notifications-cache.ts
|
|
911
|
-
var excludeEmpty = ({ tags, read: read2, archived, snoozed, limit, offset, after }) => Object.entries({ tags, read: read2, archived, snoozed, limit, offset, after }).filter(([_, value]) => value !== null && value !== void 0 && !(Array.isArray(value) && value.length === 0)).reduce((acc, [key, value]) => {
|
|
945
|
+
var excludeEmpty = ({ tags, data, read: read2, archived, snoozed, limit, offset, after }) => Object.entries({ tags, data, read: read2, archived, snoozed, limit, offset, after }).filter(([_, value]) => value !== null && value !== void 0 && !(Array.isArray(value) && value.length === 0)).reduce((acc, [key, value]) => {
|
|
912
946
|
acc[key] = value;
|
|
913
947
|
return acc;
|
|
914
948
|
}, {});
|
|
915
|
-
var getCacheKey = ({ tags, read: read2, archived, snoozed, limit, offset, after }) => {
|
|
916
|
-
return JSON.stringify(excludeEmpty({ tags, read: read2, archived, snoozed, limit, offset, after }));
|
|
949
|
+
var getCacheKey = ({ tags, data, read: read2, archived, snoozed, limit, offset, after }) => {
|
|
950
|
+
return JSON.stringify(excludeEmpty({ tags, data, read: read2, archived, snoozed, limit, offset, after }));
|
|
917
951
|
};
|
|
918
952
|
var getFilterKey = ({
|
|
919
953
|
tags,
|
|
954
|
+
data,
|
|
920
955
|
read: read2,
|
|
921
956
|
archived,
|
|
922
957
|
snoozed
|
|
923
958
|
}) => {
|
|
924
|
-
return JSON.stringify(excludeEmpty({ tags, read: read2, archived, snoozed }));
|
|
959
|
+
return JSON.stringify(excludeEmpty({ tags, data, read: read2, archived, snoozed }));
|
|
925
960
|
};
|
|
926
961
|
var getFilter = (key) => {
|
|
927
962
|
return JSON.parse(key);
|
|
@@ -1053,19 +1088,29 @@ var NotificationsCache = class {
|
|
|
1053
1088
|
}
|
|
1054
1089
|
getAll(args) {
|
|
1055
1090
|
if (this.has(args)) {
|
|
1056
|
-
return this.getAggregated({
|
|
1091
|
+
return this.getAggregated({
|
|
1092
|
+
tags: args.tags,
|
|
1093
|
+
data: args.data,
|
|
1094
|
+
read: args.read,
|
|
1095
|
+
snoozed: args.snoozed,
|
|
1096
|
+
archived: args.archived
|
|
1097
|
+
});
|
|
1057
1098
|
}
|
|
1058
1099
|
}
|
|
1059
1100
|
/**
|
|
1060
1101
|
* Get unique notifications based on specified filter fields.
|
|
1061
|
-
* The same tags can be applied to multiple filters which means that the same notification can be duplicated.
|
|
1102
|
+
* The same tags and data can be applied to multiple filters which means that the same notification can be duplicated.
|
|
1062
1103
|
*/
|
|
1063
|
-
getUniqueNotifications({
|
|
1104
|
+
getUniqueNotifications({
|
|
1105
|
+
tags,
|
|
1106
|
+
read: read2,
|
|
1107
|
+
data
|
|
1108
|
+
}) {
|
|
1064
1109
|
const keys = chunk7B52C2XE_js.__privateGet(this, _cache2).keys();
|
|
1065
1110
|
const uniqueNotifications = /* @__PURE__ */ new Map();
|
|
1066
1111
|
keys.forEach((key) => {
|
|
1067
1112
|
const filter = getFilter(key);
|
|
1068
|
-
if (areTagsEqual(tags, filter.tags)) {
|
|
1113
|
+
if (areTagsEqual(tags, filter.tags) && areDataEqual(data, filter.data)) {
|
|
1069
1114
|
const value = chunk7B52C2XE_js.__privateGet(this, _cache2).get(key);
|
|
1070
1115
|
if (!value) {
|
|
1071
1116
|
return;
|
|
@@ -1297,42 +1342,54 @@ var Notifications = class extends BaseModule {
|
|
|
1297
1342
|
});
|
|
1298
1343
|
}
|
|
1299
1344
|
readAll() {
|
|
1300
|
-
return chunk7B52C2XE_js.__async(this, arguments, function* ({
|
|
1345
|
+
return chunk7B52C2XE_js.__async(this, arguments, function* ({
|
|
1346
|
+
tags,
|
|
1347
|
+
data
|
|
1348
|
+
} = {}) {
|
|
1301
1349
|
return this.callWithSession(
|
|
1302
1350
|
() => chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1303
1351
|
return readAll({
|
|
1304
1352
|
emitter: this._emitter,
|
|
1305
1353
|
inboxService: this._inboxService,
|
|
1306
1354
|
notificationsCache: this.cache,
|
|
1307
|
-
tags
|
|
1355
|
+
tags,
|
|
1356
|
+
data
|
|
1308
1357
|
});
|
|
1309
1358
|
})
|
|
1310
1359
|
);
|
|
1311
1360
|
});
|
|
1312
1361
|
}
|
|
1313
1362
|
archiveAll() {
|
|
1314
|
-
return chunk7B52C2XE_js.__async(this, arguments, function* ({
|
|
1363
|
+
return chunk7B52C2XE_js.__async(this, arguments, function* ({
|
|
1364
|
+
tags,
|
|
1365
|
+
data
|
|
1366
|
+
} = {}) {
|
|
1315
1367
|
return this.callWithSession(
|
|
1316
1368
|
() => chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1317
1369
|
return archiveAll({
|
|
1318
1370
|
emitter: this._emitter,
|
|
1319
1371
|
inboxService: this._inboxService,
|
|
1320
1372
|
notificationsCache: this.cache,
|
|
1321
|
-
tags
|
|
1373
|
+
tags,
|
|
1374
|
+
data
|
|
1322
1375
|
});
|
|
1323
1376
|
})
|
|
1324
1377
|
);
|
|
1325
1378
|
});
|
|
1326
1379
|
}
|
|
1327
1380
|
archiveAllRead() {
|
|
1328
|
-
return chunk7B52C2XE_js.__async(this, arguments, function* ({
|
|
1381
|
+
return chunk7B52C2XE_js.__async(this, arguments, function* ({
|
|
1382
|
+
tags,
|
|
1383
|
+
data
|
|
1384
|
+
} = {}) {
|
|
1329
1385
|
return this.callWithSession(
|
|
1330
1386
|
() => chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1331
1387
|
return archiveAllRead({
|
|
1332
1388
|
emitter: this._emitter,
|
|
1333
1389
|
inboxService: this._inboxService,
|
|
1334
1390
|
notificationsCache: this.cache,
|
|
1335
|
-
tags
|
|
1391
|
+
tags,
|
|
1392
|
+
data
|
|
1336
1393
|
});
|
|
1337
1394
|
})
|
|
1338
1395
|
);
|
|
@@ -1355,11 +1412,13 @@ var updatePreference = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function*
|
|
|
1355
1412
|
useCache,
|
|
1356
1413
|
args
|
|
1357
1414
|
}) {
|
|
1358
|
-
|
|
1415
|
+
var _a;
|
|
1416
|
+
const { channels } = args;
|
|
1417
|
+
const workflowId = "workflowId" in args ? args.workflowId : (_a = args.preference.workflow) == null ? void 0 : _a.id;
|
|
1359
1418
|
try {
|
|
1360
1419
|
emitter.emit("preference.update.pending", {
|
|
1361
1420
|
args,
|
|
1362
|
-
data:
|
|
1421
|
+
data: "preference" in args ? new Preference(
|
|
1363
1422
|
chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, args.preference), {
|
|
1364
1423
|
channels: chunk7B52C2XE_js.__spreadValues(chunk7B52C2XE_js.__spreadValues({}, args.preference.channels), channels)
|
|
1365
1424
|
}),
|
|
@@ -1388,7 +1447,58 @@ var updatePreference = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function*
|
|
|
1388
1447
|
return { data: preference };
|
|
1389
1448
|
} catch (error) {
|
|
1390
1449
|
emitter.emit("preference.update.resolved", { args, error });
|
|
1391
|
-
return { error: new NovuError("Failed to
|
|
1450
|
+
return { error: new NovuError("Failed to update preference", error) };
|
|
1451
|
+
}
|
|
1452
|
+
});
|
|
1453
|
+
var bulkUpdatePreference = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
|
|
1454
|
+
emitter,
|
|
1455
|
+
apiService,
|
|
1456
|
+
cache,
|
|
1457
|
+
useCache,
|
|
1458
|
+
args
|
|
1459
|
+
}) {
|
|
1460
|
+
const globalPreference = args.find((arg) => "preference" in arg && arg.preference.level === "global" /* GLOBAL */);
|
|
1461
|
+
if (globalPreference) {
|
|
1462
|
+
return { error: new NovuError("Global preference is not supported in bulk update", "") };
|
|
1463
|
+
}
|
|
1464
|
+
try {
|
|
1465
|
+
const optimisticallyUpdatedPreferences = args.map(
|
|
1466
|
+
(arg) => "preference" in arg ? new Preference(
|
|
1467
|
+
chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, arg.preference), {
|
|
1468
|
+
channels: chunk7B52C2XE_js.__spreadValues(chunk7B52C2XE_js.__spreadValues({}, arg.preference.channels), arg.channels)
|
|
1469
|
+
}),
|
|
1470
|
+
{
|
|
1471
|
+
emitterInstance: emitter,
|
|
1472
|
+
inboxServiceInstance: apiService,
|
|
1473
|
+
cache,
|
|
1474
|
+
useCache
|
|
1475
|
+
}
|
|
1476
|
+
) : void 0
|
|
1477
|
+
).filter((el) => el !== void 0);
|
|
1478
|
+
emitter.emit("preferences.bulk_update.pending", {
|
|
1479
|
+
args,
|
|
1480
|
+
data: optimisticallyUpdatedPreferences
|
|
1481
|
+
});
|
|
1482
|
+
const preferencesToUpdate = args.map((arg) => {
|
|
1483
|
+
var _a, _b, _c, _d;
|
|
1484
|
+
return chunk7B52C2XE_js.__spreadValues({
|
|
1485
|
+
workflowId: "workflowId" in arg ? arg.workflowId : (_d = (_c = (_a = arg.preference.workflow) == null ? void 0 : _a.id) != null ? _c : (_b = arg.preference.workflow) == null ? void 0 : _b.identifier) != null ? _d : ""
|
|
1486
|
+
}, arg.channels);
|
|
1487
|
+
});
|
|
1488
|
+
const response = yield apiService.bulkUpdatePreferences(preferencesToUpdate);
|
|
1489
|
+
const preferences = response.map(
|
|
1490
|
+
(el) => new Preference(el, {
|
|
1491
|
+
emitterInstance: emitter,
|
|
1492
|
+
inboxServiceInstance: apiService,
|
|
1493
|
+
cache,
|
|
1494
|
+
useCache
|
|
1495
|
+
})
|
|
1496
|
+
);
|
|
1497
|
+
emitter.emit("preferences.bulk_update.resolved", { args, data: preferences });
|
|
1498
|
+
return { data: preferences };
|
|
1499
|
+
} catch (error) {
|
|
1500
|
+
emitter.emit("preferences.bulk_update.resolved", { args, error });
|
|
1501
|
+
return { error: new NovuError("Failed to bulk update preferences", error) };
|
|
1392
1502
|
}
|
|
1393
1503
|
});
|
|
1394
1504
|
var optimisticUpdateWorkflowPreferences = ({
|
|
@@ -1400,7 +1510,7 @@ var optimisticUpdateWorkflowPreferences = ({
|
|
|
1400
1510
|
}) => {
|
|
1401
1511
|
const allPreferences = useCache ? cache == null ? void 0 : cache.getAll({}) : void 0;
|
|
1402
1512
|
allPreferences == null ? void 0 : allPreferences.forEach((el) => {
|
|
1403
|
-
var _a;
|
|
1513
|
+
var _a, _b;
|
|
1404
1514
|
if (el.level === "template" /* TEMPLATE */) {
|
|
1405
1515
|
const mergedPreference = chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, el), {
|
|
1406
1516
|
channels: Object.entries(el.channels).reduce((acc, [key, value]) => {
|
|
@@ -1410,7 +1520,7 @@ var optimisticUpdateWorkflowPreferences = ({
|
|
|
1410
1520
|
return acc;
|
|
1411
1521
|
}, {})
|
|
1412
1522
|
});
|
|
1413
|
-
const updatedPreference =
|
|
1523
|
+
const updatedPreference = "preference" in args ? new Preference(mergedPreference, {
|
|
1414
1524
|
emitterInstance: emitter,
|
|
1415
1525
|
inboxServiceInstance: apiService,
|
|
1416
1526
|
cache,
|
|
@@ -1419,7 +1529,7 @@ var optimisticUpdateWorkflowPreferences = ({
|
|
|
1419
1529
|
if (updatedPreference) {
|
|
1420
1530
|
emitter.emit("preference.update.pending", {
|
|
1421
1531
|
args: {
|
|
1422
|
-
workflowId: (_a = el.workflow) == null ? void 0 : _a.id,
|
|
1532
|
+
workflowId: (_b = (_a = el.workflow) == null ? void 0 : _a.id) != null ? _b : "",
|
|
1423
1533
|
channels: updatedPreference.channels
|
|
1424
1534
|
},
|
|
1425
1535
|
data: updatedPreference
|
|
@@ -1453,7 +1563,6 @@ var Preference = class {
|
|
|
1453
1563
|
}
|
|
1454
1564
|
update({
|
|
1455
1565
|
channels,
|
|
1456
|
-
/** @deprecated Use channels instead */
|
|
1457
1566
|
channelPreferences
|
|
1458
1567
|
}) {
|
|
1459
1568
|
var _a;
|
|
@@ -1465,12 +1574,7 @@ var Preference = class {
|
|
|
1465
1574
|
args: {
|
|
1466
1575
|
workflowId: (_a = this.workflow) == null ? void 0 : _a.id,
|
|
1467
1576
|
channels: channels || channelPreferences,
|
|
1468
|
-
preference:
|
|
1469
|
-
level: this.level,
|
|
1470
|
-
enabled: this.enabled,
|
|
1471
|
-
channels: this.channels,
|
|
1472
|
-
workflow: this.workflow
|
|
1473
|
-
}
|
|
1577
|
+
preference: this
|
|
1474
1578
|
}
|
|
1475
1579
|
});
|
|
1476
1580
|
}
|
|
@@ -1481,7 +1585,12 @@ _cache3 = new WeakMap();
|
|
|
1481
1585
|
_useCache2 = new WeakMap();
|
|
1482
1586
|
|
|
1483
1587
|
// src/cache/preferences-cache.ts
|
|
1484
|
-
var updateEvents2 = [
|
|
1588
|
+
var updateEvents2 = [
|
|
1589
|
+
"preference.update.pending",
|
|
1590
|
+
"preference.update.resolved",
|
|
1591
|
+
"preferences.bulk_update.pending",
|
|
1592
|
+
"preferences.bulk_update.resolved"
|
|
1593
|
+
];
|
|
1485
1594
|
var excludeEmpty2 = ({ tags }) => Object.entries({ tags }).reduce((acc, [key, value]) => {
|
|
1486
1595
|
if (value === null || value === void 0 || Array.isArray(value) && value.length === 0) {
|
|
1487
1596
|
return acc;
|
|
@@ -1520,14 +1629,22 @@ var PreferencesCache = class {
|
|
|
1520
1629
|
if (!data) {
|
|
1521
1630
|
return;
|
|
1522
1631
|
}
|
|
1632
|
+
const preferences = Array.isArray(data) ? data : [data];
|
|
1633
|
+
const uniqueFilterKeys = /* @__PURE__ */ new Set();
|
|
1523
1634
|
chunk7B52C2XE_js.__privateGet(this, _cache4).keys().forEach((key) => {
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1635
|
+
preferences.forEach((preference) => {
|
|
1636
|
+
const hasUpdatedPreference = this.updatePreference(key, preference);
|
|
1637
|
+
const updatedPreference = chunk7B52C2XE_js.__privateGet(this, _cache4).get(key);
|
|
1638
|
+
if (!hasUpdatedPreference || !updatedPreference) {
|
|
1639
|
+
return;
|
|
1640
|
+
}
|
|
1641
|
+
uniqueFilterKeys.add(key);
|
|
1642
|
+
});
|
|
1643
|
+
});
|
|
1644
|
+
uniqueFilterKeys.forEach((key) => {
|
|
1645
|
+
var _a;
|
|
1529
1646
|
chunk7B52C2XE_js.__privateGet(this, _emitter4).emit("preferences.list.updated", {
|
|
1530
|
-
data:
|
|
1647
|
+
data: (_a = chunk7B52C2XE_js.__privateGet(this, _cache4).get(key)) != null ? _a : []
|
|
1531
1648
|
});
|
|
1532
1649
|
});
|
|
1533
1650
|
};
|
|
@@ -1603,6 +1720,32 @@ var Preferences = class extends BaseModule {
|
|
|
1603
1720
|
}));
|
|
1604
1721
|
});
|
|
1605
1722
|
}
|
|
1723
|
+
update(args) {
|
|
1724
|
+
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1725
|
+
return this.callWithSession(
|
|
1726
|
+
() => updatePreference({
|
|
1727
|
+
emitter: this._emitter,
|
|
1728
|
+
apiService: this._inboxService,
|
|
1729
|
+
cache: this.cache,
|
|
1730
|
+
useCache: chunk7B52C2XE_js.__privateGet(this, _useCache3),
|
|
1731
|
+
args
|
|
1732
|
+
})
|
|
1733
|
+
);
|
|
1734
|
+
});
|
|
1735
|
+
}
|
|
1736
|
+
bulkUpdate(args) {
|
|
1737
|
+
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1738
|
+
return this.callWithSession(
|
|
1739
|
+
() => bulkUpdatePreference({
|
|
1740
|
+
emitter: this._emitter,
|
|
1741
|
+
apiService: this._inboxService,
|
|
1742
|
+
cache: this.cache,
|
|
1743
|
+
useCache: chunk7B52C2XE_js.__privateGet(this, _useCache3),
|
|
1744
|
+
args
|
|
1745
|
+
})
|
|
1746
|
+
);
|
|
1747
|
+
});
|
|
1748
|
+
}
|
|
1606
1749
|
};
|
|
1607
1750
|
_useCache3 = new WeakMap();
|
|
1608
1751
|
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { N as NotificationFilter } from './novu-
|
|
2
|
-
export { C as ChannelPreference, c as ChannelType, E as EventHandler, a as Events, F as FiltersCountResponse, I as InboxNotification, L as ListNotificationsResponse, d as Notification, e as NotificationStatus, b as Novu, f as NovuError, g as NovuOptions, P as Preference, h as PreferenceLevel, i as PreferencesResponse, S as SocketEventNames, j as Subscriber, W as WebSocketEvent } from './novu-
|
|
1
|
+
import { N as NotificationFilter } from './novu-q3jzGeyW.js';
|
|
2
|
+
export { C as ChannelPreference, c as ChannelType, E as EventHandler, a as Events, F as FiltersCountResponse, I as InboxNotification, L as ListNotificationsResponse, d as Notification, e as NotificationStatus, b as Novu, f as NovuError, g as NovuOptions, P as Preference, h as PreferenceLevel, i as PreferencesResponse, S as SocketEventNames, j as Subscriber, W as WebSocketEvent } from './novu-q3jzGeyW.js';
|
|
3
3
|
|
|
4
4
|
declare const areTagsEqual: (tags1?: string[], tags2?: string[]) => boolean;
|
|
5
5
|
declare const isSameFilter: (filter1: NotificationFilter, filter2: NotificationFilter) => boolean;
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkME3JBJPI_js = require('./chunk-ME3JBJPI.js');
|
|
4
4
|
require('./chunk-7B52C2XE.js');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "ChannelType", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunkME3JBJPI_js.ChannelType; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "NotificationStatus", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkME3JBJPI_js.NotificationStatus; }
|
|
15
15
|
});
|
|
16
16
|
Object.defineProperty(exports, "Novu", {
|
|
17
17
|
enumerable: true,
|
|
18
|
-
get: function () { return
|
|
18
|
+
get: function () { return chunkME3JBJPI_js.Novu; }
|
|
19
19
|
});
|
|
20
20
|
Object.defineProperty(exports, "PreferenceLevel", {
|
|
21
21
|
enumerable: true,
|
|
22
|
-
get: function () { return
|
|
22
|
+
get: function () { return chunkME3JBJPI_js.PreferenceLevel; }
|
|
23
23
|
});
|
|
24
24
|
Object.defineProperty(exports, "WebSocketEvent", {
|
|
25
25
|
enumerable: true,
|
|
26
|
-
get: function () { return
|
|
26
|
+
get: function () { return chunkME3JBJPI_js.WebSocketEvent; }
|
|
27
27
|
});
|
|
28
28
|
Object.defineProperty(exports, "areTagsEqual", {
|
|
29
29
|
enumerable: true,
|
|
30
|
-
get: function () { return
|
|
30
|
+
get: function () { return chunkME3JBJPI_js.areTagsEqual; }
|
|
31
31
|
});
|
|
32
32
|
Object.defineProperty(exports, "isSameFilter", {
|
|
33
33
|
enumerable: true,
|
|
34
|
-
get: function () { return
|
|
34
|
+
get: function () { return chunkME3JBJPI_js.isSameFilter; }
|
|
35
35
|
});
|