@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
|
@@ -48,14 +48,27 @@ var arrayValuesEqual = (arr1, arr2) => {
|
|
|
48
48
|
var areTagsEqual = (tags1, tags2) => {
|
|
49
49
|
return arrayValuesEqual(tags1, tags2) || !tags1 && (tags2 == null ? void 0 : tags2.length) === 0 || (tags1 == null ? void 0 : tags1.length) === 0 && !tags2;
|
|
50
50
|
};
|
|
51
|
+
var areDataEqual = (data1, data2) => {
|
|
52
|
+
if (!data1 && !data2) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
if (!data1 || !data2) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
return JSON.stringify(data1) === JSON.stringify(data2);
|
|
60
|
+
} catch (e) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
51
64
|
var isSameFilter = (filter1, filter2) => {
|
|
52
|
-
return areTagsEqual(filter1.tags, filter2.tags) && filter1.read === filter2.read && filter1.archived === filter2.archived && filter1.snoozed === filter2.snoozed;
|
|
65
|
+
return areDataEqual(filter1.data, filter2.data) && areTagsEqual(filter1.tags, filter2.tags) && filter1.read === filter2.read && filter1.archived === filter2.archived && filter1.snoozed === filter2.snoozed;
|
|
53
66
|
};
|
|
54
67
|
|
|
55
68
|
// src/api/http-client.ts
|
|
56
69
|
var DEFAULT_API_VERSION = "v1";
|
|
57
70
|
var DEFAULT_BACKEND_URL = "https://api.novu.co";
|
|
58
|
-
var DEFAULT_USER_AGENT = `${"@novu/js"}@${"3.
|
|
71
|
+
var DEFAULT_USER_AGENT = `${"@novu/js"}@${"3.5.0-rc.1"}`;
|
|
59
72
|
var HttpClient = class {
|
|
60
73
|
constructor(options = {}) {
|
|
61
74
|
const {
|
|
@@ -190,7 +203,8 @@ var InboxService = class {
|
|
|
190
203
|
offset,
|
|
191
204
|
read: read2,
|
|
192
205
|
tags,
|
|
193
|
-
snoozed
|
|
206
|
+
snoozed,
|
|
207
|
+
data
|
|
194
208
|
}) {
|
|
195
209
|
const searchParams = new URLSearchParams(`limit=${limit}`);
|
|
196
210
|
if (after) {
|
|
@@ -211,9 +225,14 @@ var InboxService = class {
|
|
|
211
225
|
if (snoozed !== void 0) {
|
|
212
226
|
searchParams.append("snoozed", `${snoozed}`);
|
|
213
227
|
}
|
|
228
|
+
if (data !== void 0) {
|
|
229
|
+
searchParams.append("data", JSON.stringify(data));
|
|
230
|
+
}
|
|
214
231
|
return __privateGet(this, _httpClient).get(INBOX_NOTIFICATIONS_ROUTE, searchParams, false);
|
|
215
232
|
}
|
|
216
|
-
count({
|
|
233
|
+
count({
|
|
234
|
+
filters
|
|
235
|
+
}) {
|
|
217
236
|
return __privateGet(this, _httpClient).get(
|
|
218
237
|
`${INBOX_NOTIFICATIONS_ROUTE}/count`,
|
|
219
238
|
new URLSearchParams({
|
|
@@ -240,14 +259,23 @@ var InboxService = class {
|
|
|
240
259
|
unsnooze(notificationId) {
|
|
241
260
|
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/unsnooze`);
|
|
242
261
|
}
|
|
243
|
-
readAll({ tags }) {
|
|
244
|
-
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read`, {
|
|
262
|
+
readAll({ tags, data }) {
|
|
263
|
+
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read`, {
|
|
264
|
+
tags,
|
|
265
|
+
data: data ? JSON.stringify(data) : void 0
|
|
266
|
+
});
|
|
245
267
|
}
|
|
246
|
-
archiveAll({ tags }) {
|
|
247
|
-
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/archive`, {
|
|
268
|
+
archiveAll({ tags, data }) {
|
|
269
|
+
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/archive`, {
|
|
270
|
+
tags,
|
|
271
|
+
data: data ? JSON.stringify(data) : void 0
|
|
272
|
+
});
|
|
248
273
|
}
|
|
249
|
-
archiveAllRead({ tags }) {
|
|
250
|
-
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read-archive`, {
|
|
274
|
+
archiveAllRead({ tags, data }) {
|
|
275
|
+
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read-archive`, {
|
|
276
|
+
tags,
|
|
277
|
+
data: data ? JSON.stringify(data) : void 0
|
|
278
|
+
});
|
|
251
279
|
}
|
|
252
280
|
completeAction({
|
|
253
281
|
actionType,
|
|
@@ -273,6 +301,9 @@ var InboxService = class {
|
|
|
273
301
|
const query = queryParams.size ? `?${queryParams.toString()}` : "";
|
|
274
302
|
return __privateGet(this, _httpClient).get(`${INBOX_ROUTE}/preferences${query}`);
|
|
275
303
|
}
|
|
304
|
+
bulkUpdatePreferences(preferences) {
|
|
305
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/bulk`, { preferences });
|
|
306
|
+
}
|
|
276
307
|
updateGlobalPreferences(channels) {
|
|
277
308
|
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences`, channels);
|
|
278
309
|
}
|
|
@@ -790,10 +821,11 @@ var readAll = (_0) => __async(void 0, [_0], function* ({
|
|
|
790
821
|
emitter,
|
|
791
822
|
inboxService,
|
|
792
823
|
notificationsCache,
|
|
793
|
-
tags
|
|
824
|
+
tags,
|
|
825
|
+
data
|
|
794
826
|
}) {
|
|
795
827
|
try {
|
|
796
|
-
const notifications = notificationsCache.getUniqueNotifications({ tags });
|
|
828
|
+
const notifications = notificationsCache.getUniqueNotifications({ tags, data });
|
|
797
829
|
const optimisticNotifications = notifications.map(
|
|
798
830
|
(notification) => new Notification(
|
|
799
831
|
__spreadProps(__spreadValues({}, notification), {
|
|
@@ -806,12 +838,12 @@ var readAll = (_0) => __async(void 0, [_0], function* ({
|
|
|
806
838
|
inboxService
|
|
807
839
|
)
|
|
808
840
|
);
|
|
809
|
-
emitter.emit("notifications.read_all.pending", { args: { tags }, data: optimisticNotifications });
|
|
810
|
-
yield inboxService.readAll({ tags });
|
|
811
|
-
emitter.emit("notifications.read_all.resolved", { args: { tags }, data: optimisticNotifications });
|
|
841
|
+
emitter.emit("notifications.read_all.pending", { args: { tags, data }, data: optimisticNotifications });
|
|
842
|
+
yield inboxService.readAll({ tags, data });
|
|
843
|
+
emitter.emit("notifications.read_all.resolved", { args: { tags, data }, data: optimisticNotifications });
|
|
812
844
|
return {};
|
|
813
845
|
} catch (error) {
|
|
814
|
-
emitter.emit("notifications.read_all.resolved", { args: { tags }, error });
|
|
846
|
+
emitter.emit("notifications.read_all.resolved", { args: { tags, data }, error });
|
|
815
847
|
return { error: new NovuError("Failed to read all notifications", error) };
|
|
816
848
|
}
|
|
817
849
|
});
|
|
@@ -819,10 +851,11 @@ var archiveAll = (_0) => __async(void 0, [_0], function* ({
|
|
|
819
851
|
emitter,
|
|
820
852
|
inboxService,
|
|
821
853
|
notificationsCache,
|
|
822
|
-
tags
|
|
854
|
+
tags,
|
|
855
|
+
data
|
|
823
856
|
}) {
|
|
824
857
|
try {
|
|
825
|
-
const notifications = notificationsCache.getUniqueNotifications({ tags });
|
|
858
|
+
const notifications = notificationsCache.getUniqueNotifications({ tags, data });
|
|
826
859
|
const optimisticNotifications = notifications.map(
|
|
827
860
|
(notification) => new Notification(
|
|
828
861
|
__spreadProps(__spreadValues({}, notification), {
|
|
@@ -835,12 +868,12 @@ var archiveAll = (_0) => __async(void 0, [_0], function* ({
|
|
|
835
868
|
inboxService
|
|
836
869
|
)
|
|
837
870
|
);
|
|
838
|
-
emitter.emit("notifications.archive_all.pending", { args: { tags }, data: optimisticNotifications });
|
|
839
|
-
yield inboxService.archiveAll({ tags });
|
|
840
|
-
emitter.emit("notifications.archive_all.resolved", { args: { tags }, data: optimisticNotifications });
|
|
871
|
+
emitter.emit("notifications.archive_all.pending", { args: { tags, data }, data: optimisticNotifications });
|
|
872
|
+
yield inboxService.archiveAll({ tags, data });
|
|
873
|
+
emitter.emit("notifications.archive_all.resolved", { args: { tags, data }, data: optimisticNotifications });
|
|
841
874
|
return {};
|
|
842
875
|
} catch (error) {
|
|
843
|
-
emitter.emit("notifications.archive_all.resolved", { args: { tags }, error });
|
|
876
|
+
emitter.emit("notifications.archive_all.resolved", { args: { tags, data }, error });
|
|
844
877
|
return { error: new NovuError("Failed to archive all notifications", error) };
|
|
845
878
|
}
|
|
846
879
|
});
|
|
@@ -848,10 +881,11 @@ var archiveAllRead = (_0) => __async(void 0, [_0], function* ({
|
|
|
848
881
|
emitter,
|
|
849
882
|
inboxService,
|
|
850
883
|
notificationsCache,
|
|
851
|
-
tags
|
|
884
|
+
tags,
|
|
885
|
+
data
|
|
852
886
|
}) {
|
|
853
887
|
try {
|
|
854
|
-
const notifications = notificationsCache.getUniqueNotifications({ tags, read: true });
|
|
888
|
+
const notifications = notificationsCache.getUniqueNotifications({ tags, data, read: true });
|
|
855
889
|
const optimisticNotifications = notifications.map(
|
|
856
890
|
(notification) => new Notification(
|
|
857
891
|
__spreadProps(__spreadValues({}, notification), { isArchived: true, archivedAt: (/* @__PURE__ */ new Date()).toISOString() }),
|
|
@@ -859,12 +893,12 @@ var archiveAllRead = (_0) => __async(void 0, [_0], function* ({
|
|
|
859
893
|
inboxService
|
|
860
894
|
)
|
|
861
895
|
);
|
|
862
|
-
emitter.emit("notifications.archive_all_read.pending", { args: { tags }, data: optimisticNotifications });
|
|
863
|
-
yield inboxService.archiveAllRead({ tags });
|
|
864
|
-
emitter.emit("notifications.archive_all_read.resolved", { args: { tags }, data: optimisticNotifications });
|
|
896
|
+
emitter.emit("notifications.archive_all_read.pending", { args: { tags, data }, data: optimisticNotifications });
|
|
897
|
+
yield inboxService.archiveAllRead({ tags, data });
|
|
898
|
+
emitter.emit("notifications.archive_all_read.resolved", { args: { tags, data }, data: optimisticNotifications });
|
|
865
899
|
return {};
|
|
866
900
|
} catch (error) {
|
|
867
|
-
emitter.emit("notifications.archive_all_read.resolved", { args: { tags }, error });
|
|
901
|
+
emitter.emit("notifications.archive_all_read.resolved", { args: { tags, data }, error });
|
|
868
902
|
return { error: new NovuError("Failed to archive all read notifications", error) };
|
|
869
903
|
}
|
|
870
904
|
});
|
|
@@ -901,20 +935,21 @@ var InMemoryCache = class {
|
|
|
901
935
|
_cache = new WeakMap();
|
|
902
936
|
|
|
903
937
|
// src/cache/notifications-cache.ts
|
|
904
|
-
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]) => {
|
|
938
|
+
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]) => {
|
|
905
939
|
acc[key] = value;
|
|
906
940
|
return acc;
|
|
907
941
|
}, {});
|
|
908
|
-
var getCacheKey = ({ tags, read: read2, archived, snoozed, limit, offset, after }) => {
|
|
909
|
-
return JSON.stringify(excludeEmpty({ tags, read: read2, archived, snoozed, limit, offset, after }));
|
|
942
|
+
var getCacheKey = ({ tags, data, read: read2, archived, snoozed, limit, offset, after }) => {
|
|
943
|
+
return JSON.stringify(excludeEmpty({ tags, data, read: read2, archived, snoozed, limit, offset, after }));
|
|
910
944
|
};
|
|
911
945
|
var getFilterKey = ({
|
|
912
946
|
tags,
|
|
947
|
+
data,
|
|
913
948
|
read: read2,
|
|
914
949
|
archived,
|
|
915
950
|
snoozed
|
|
916
951
|
}) => {
|
|
917
|
-
return JSON.stringify(excludeEmpty({ tags, read: read2, archived, snoozed }));
|
|
952
|
+
return JSON.stringify(excludeEmpty({ tags, data, read: read2, archived, snoozed }));
|
|
918
953
|
};
|
|
919
954
|
var getFilter = (key) => {
|
|
920
955
|
return JSON.parse(key);
|
|
@@ -1046,19 +1081,29 @@ var NotificationsCache = class {
|
|
|
1046
1081
|
}
|
|
1047
1082
|
getAll(args) {
|
|
1048
1083
|
if (this.has(args)) {
|
|
1049
|
-
return this.getAggregated({
|
|
1084
|
+
return this.getAggregated({
|
|
1085
|
+
tags: args.tags,
|
|
1086
|
+
data: args.data,
|
|
1087
|
+
read: args.read,
|
|
1088
|
+
snoozed: args.snoozed,
|
|
1089
|
+
archived: args.archived
|
|
1090
|
+
});
|
|
1050
1091
|
}
|
|
1051
1092
|
}
|
|
1052
1093
|
/**
|
|
1053
1094
|
* Get unique notifications based on specified filter fields.
|
|
1054
|
-
* The same tags can be applied to multiple filters which means that the same notification can be duplicated.
|
|
1095
|
+
* The same tags and data can be applied to multiple filters which means that the same notification can be duplicated.
|
|
1055
1096
|
*/
|
|
1056
|
-
getUniqueNotifications({
|
|
1097
|
+
getUniqueNotifications({
|
|
1098
|
+
tags,
|
|
1099
|
+
read: read2,
|
|
1100
|
+
data
|
|
1101
|
+
}) {
|
|
1057
1102
|
const keys = __privateGet(this, _cache2).keys();
|
|
1058
1103
|
const uniqueNotifications = /* @__PURE__ */ new Map();
|
|
1059
1104
|
keys.forEach((key) => {
|
|
1060
1105
|
const filter = getFilter(key);
|
|
1061
|
-
if (areTagsEqual(tags, filter.tags)) {
|
|
1106
|
+
if (areTagsEqual(tags, filter.tags) && areDataEqual(data, filter.data)) {
|
|
1062
1107
|
const value = __privateGet(this, _cache2).get(key);
|
|
1063
1108
|
if (!value) {
|
|
1064
1109
|
return;
|
|
@@ -1290,42 +1335,54 @@ var Notifications = class extends BaseModule {
|
|
|
1290
1335
|
});
|
|
1291
1336
|
}
|
|
1292
1337
|
readAll() {
|
|
1293
|
-
return __async(this, arguments, function* ({
|
|
1338
|
+
return __async(this, arguments, function* ({
|
|
1339
|
+
tags,
|
|
1340
|
+
data
|
|
1341
|
+
} = {}) {
|
|
1294
1342
|
return this.callWithSession(
|
|
1295
1343
|
() => __async(this, null, function* () {
|
|
1296
1344
|
return readAll({
|
|
1297
1345
|
emitter: this._emitter,
|
|
1298
1346
|
inboxService: this._inboxService,
|
|
1299
1347
|
notificationsCache: this.cache,
|
|
1300
|
-
tags
|
|
1348
|
+
tags,
|
|
1349
|
+
data
|
|
1301
1350
|
});
|
|
1302
1351
|
})
|
|
1303
1352
|
);
|
|
1304
1353
|
});
|
|
1305
1354
|
}
|
|
1306
1355
|
archiveAll() {
|
|
1307
|
-
return __async(this, arguments, function* ({
|
|
1356
|
+
return __async(this, arguments, function* ({
|
|
1357
|
+
tags,
|
|
1358
|
+
data
|
|
1359
|
+
} = {}) {
|
|
1308
1360
|
return this.callWithSession(
|
|
1309
1361
|
() => __async(this, null, function* () {
|
|
1310
1362
|
return archiveAll({
|
|
1311
1363
|
emitter: this._emitter,
|
|
1312
1364
|
inboxService: this._inboxService,
|
|
1313
1365
|
notificationsCache: this.cache,
|
|
1314
|
-
tags
|
|
1366
|
+
tags,
|
|
1367
|
+
data
|
|
1315
1368
|
});
|
|
1316
1369
|
})
|
|
1317
1370
|
);
|
|
1318
1371
|
});
|
|
1319
1372
|
}
|
|
1320
1373
|
archiveAllRead() {
|
|
1321
|
-
return __async(this, arguments, function* ({
|
|
1374
|
+
return __async(this, arguments, function* ({
|
|
1375
|
+
tags,
|
|
1376
|
+
data
|
|
1377
|
+
} = {}) {
|
|
1322
1378
|
return this.callWithSession(
|
|
1323
1379
|
() => __async(this, null, function* () {
|
|
1324
1380
|
return archiveAllRead({
|
|
1325
1381
|
emitter: this._emitter,
|
|
1326
1382
|
inboxService: this._inboxService,
|
|
1327
1383
|
notificationsCache: this.cache,
|
|
1328
|
-
tags
|
|
1384
|
+
tags,
|
|
1385
|
+
data
|
|
1329
1386
|
});
|
|
1330
1387
|
})
|
|
1331
1388
|
);
|
|
@@ -1348,11 +1405,13 @@ var updatePreference = (_0) => __async(void 0, [_0], function* ({
|
|
|
1348
1405
|
useCache,
|
|
1349
1406
|
args
|
|
1350
1407
|
}) {
|
|
1351
|
-
|
|
1408
|
+
var _a;
|
|
1409
|
+
const { channels } = args;
|
|
1410
|
+
const workflowId = "workflowId" in args ? args.workflowId : (_a = args.preference.workflow) == null ? void 0 : _a.id;
|
|
1352
1411
|
try {
|
|
1353
1412
|
emitter.emit("preference.update.pending", {
|
|
1354
1413
|
args,
|
|
1355
|
-
data:
|
|
1414
|
+
data: "preference" in args ? new Preference(
|
|
1356
1415
|
__spreadProps(__spreadValues({}, args.preference), {
|
|
1357
1416
|
channels: __spreadValues(__spreadValues({}, args.preference.channels), channels)
|
|
1358
1417
|
}),
|
|
@@ -1381,7 +1440,58 @@ var updatePreference = (_0) => __async(void 0, [_0], function* ({
|
|
|
1381
1440
|
return { data: preference };
|
|
1382
1441
|
} catch (error) {
|
|
1383
1442
|
emitter.emit("preference.update.resolved", { args, error });
|
|
1384
|
-
return { error: new NovuError("Failed to
|
|
1443
|
+
return { error: new NovuError("Failed to update preference", error) };
|
|
1444
|
+
}
|
|
1445
|
+
});
|
|
1446
|
+
var bulkUpdatePreference = (_0) => __async(void 0, [_0], function* ({
|
|
1447
|
+
emitter,
|
|
1448
|
+
apiService,
|
|
1449
|
+
cache,
|
|
1450
|
+
useCache,
|
|
1451
|
+
args
|
|
1452
|
+
}) {
|
|
1453
|
+
const globalPreference = args.find((arg) => "preference" in arg && arg.preference.level === "global" /* GLOBAL */);
|
|
1454
|
+
if (globalPreference) {
|
|
1455
|
+
return { error: new NovuError("Global preference is not supported in bulk update", "") };
|
|
1456
|
+
}
|
|
1457
|
+
try {
|
|
1458
|
+
const optimisticallyUpdatedPreferences = args.map(
|
|
1459
|
+
(arg) => "preference" in arg ? new Preference(
|
|
1460
|
+
__spreadProps(__spreadValues({}, arg.preference), {
|
|
1461
|
+
channels: __spreadValues(__spreadValues({}, arg.preference.channels), arg.channels)
|
|
1462
|
+
}),
|
|
1463
|
+
{
|
|
1464
|
+
emitterInstance: emitter,
|
|
1465
|
+
inboxServiceInstance: apiService,
|
|
1466
|
+
cache,
|
|
1467
|
+
useCache
|
|
1468
|
+
}
|
|
1469
|
+
) : void 0
|
|
1470
|
+
).filter((el) => el !== void 0);
|
|
1471
|
+
emitter.emit("preferences.bulk_update.pending", {
|
|
1472
|
+
args,
|
|
1473
|
+
data: optimisticallyUpdatedPreferences
|
|
1474
|
+
});
|
|
1475
|
+
const preferencesToUpdate = args.map((arg) => {
|
|
1476
|
+
var _a, _b, _c, _d;
|
|
1477
|
+
return __spreadValues({
|
|
1478
|
+
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 : ""
|
|
1479
|
+
}, arg.channels);
|
|
1480
|
+
});
|
|
1481
|
+
const response = yield apiService.bulkUpdatePreferences(preferencesToUpdate);
|
|
1482
|
+
const preferences = response.map(
|
|
1483
|
+
(el) => new Preference(el, {
|
|
1484
|
+
emitterInstance: emitter,
|
|
1485
|
+
inboxServiceInstance: apiService,
|
|
1486
|
+
cache,
|
|
1487
|
+
useCache
|
|
1488
|
+
})
|
|
1489
|
+
);
|
|
1490
|
+
emitter.emit("preferences.bulk_update.resolved", { args, data: preferences });
|
|
1491
|
+
return { data: preferences };
|
|
1492
|
+
} catch (error) {
|
|
1493
|
+
emitter.emit("preferences.bulk_update.resolved", { args, error });
|
|
1494
|
+
return { error: new NovuError("Failed to bulk update preferences", error) };
|
|
1385
1495
|
}
|
|
1386
1496
|
});
|
|
1387
1497
|
var optimisticUpdateWorkflowPreferences = ({
|
|
@@ -1393,7 +1503,7 @@ var optimisticUpdateWorkflowPreferences = ({
|
|
|
1393
1503
|
}) => {
|
|
1394
1504
|
const allPreferences = useCache ? cache == null ? void 0 : cache.getAll({}) : void 0;
|
|
1395
1505
|
allPreferences == null ? void 0 : allPreferences.forEach((el) => {
|
|
1396
|
-
var _a;
|
|
1506
|
+
var _a, _b;
|
|
1397
1507
|
if (el.level === "template" /* TEMPLATE */) {
|
|
1398
1508
|
const mergedPreference = __spreadProps(__spreadValues({}, el), {
|
|
1399
1509
|
channels: Object.entries(el.channels).reduce((acc, [key, value]) => {
|
|
@@ -1403,7 +1513,7 @@ var optimisticUpdateWorkflowPreferences = ({
|
|
|
1403
1513
|
return acc;
|
|
1404
1514
|
}, {})
|
|
1405
1515
|
});
|
|
1406
|
-
const updatedPreference =
|
|
1516
|
+
const updatedPreference = "preference" in args ? new Preference(mergedPreference, {
|
|
1407
1517
|
emitterInstance: emitter,
|
|
1408
1518
|
inboxServiceInstance: apiService,
|
|
1409
1519
|
cache,
|
|
@@ -1412,7 +1522,7 @@ var optimisticUpdateWorkflowPreferences = ({
|
|
|
1412
1522
|
if (updatedPreference) {
|
|
1413
1523
|
emitter.emit("preference.update.pending", {
|
|
1414
1524
|
args: {
|
|
1415
|
-
workflowId: (_a = el.workflow) == null ? void 0 : _a.id,
|
|
1525
|
+
workflowId: (_b = (_a = el.workflow) == null ? void 0 : _a.id) != null ? _b : "",
|
|
1416
1526
|
channels: updatedPreference.channels
|
|
1417
1527
|
},
|
|
1418
1528
|
data: updatedPreference
|
|
@@ -1446,7 +1556,6 @@ var Preference = class {
|
|
|
1446
1556
|
}
|
|
1447
1557
|
update({
|
|
1448
1558
|
channels,
|
|
1449
|
-
/** @deprecated Use channels instead */
|
|
1450
1559
|
channelPreferences
|
|
1451
1560
|
}) {
|
|
1452
1561
|
var _a;
|
|
@@ -1458,12 +1567,7 @@ var Preference = class {
|
|
|
1458
1567
|
args: {
|
|
1459
1568
|
workflowId: (_a = this.workflow) == null ? void 0 : _a.id,
|
|
1460
1569
|
channels: channels || channelPreferences,
|
|
1461
|
-
preference:
|
|
1462
|
-
level: this.level,
|
|
1463
|
-
enabled: this.enabled,
|
|
1464
|
-
channels: this.channels,
|
|
1465
|
-
workflow: this.workflow
|
|
1466
|
-
}
|
|
1570
|
+
preference: this
|
|
1467
1571
|
}
|
|
1468
1572
|
});
|
|
1469
1573
|
}
|
|
@@ -1474,7 +1578,12 @@ _cache3 = new WeakMap();
|
|
|
1474
1578
|
_useCache2 = new WeakMap();
|
|
1475
1579
|
|
|
1476
1580
|
// src/cache/preferences-cache.ts
|
|
1477
|
-
var updateEvents2 = [
|
|
1581
|
+
var updateEvents2 = [
|
|
1582
|
+
"preference.update.pending",
|
|
1583
|
+
"preference.update.resolved",
|
|
1584
|
+
"preferences.bulk_update.pending",
|
|
1585
|
+
"preferences.bulk_update.resolved"
|
|
1586
|
+
];
|
|
1478
1587
|
var excludeEmpty2 = ({ tags }) => Object.entries({ tags }).reduce((acc, [key, value]) => {
|
|
1479
1588
|
if (value === null || value === void 0 || Array.isArray(value) && value.length === 0) {
|
|
1480
1589
|
return acc;
|
|
@@ -1513,14 +1622,22 @@ var PreferencesCache = class {
|
|
|
1513
1622
|
if (!data) {
|
|
1514
1623
|
return;
|
|
1515
1624
|
}
|
|
1625
|
+
const preferences = Array.isArray(data) ? data : [data];
|
|
1626
|
+
const uniqueFilterKeys = /* @__PURE__ */ new Set();
|
|
1516
1627
|
__privateGet(this, _cache4).keys().forEach((key) => {
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1628
|
+
preferences.forEach((preference) => {
|
|
1629
|
+
const hasUpdatedPreference = this.updatePreference(key, preference);
|
|
1630
|
+
const updatedPreference = __privateGet(this, _cache4).get(key);
|
|
1631
|
+
if (!hasUpdatedPreference || !updatedPreference) {
|
|
1632
|
+
return;
|
|
1633
|
+
}
|
|
1634
|
+
uniqueFilterKeys.add(key);
|
|
1635
|
+
});
|
|
1636
|
+
});
|
|
1637
|
+
uniqueFilterKeys.forEach((key) => {
|
|
1638
|
+
var _a;
|
|
1522
1639
|
__privateGet(this, _emitter4).emit("preferences.list.updated", {
|
|
1523
|
-
data:
|
|
1640
|
+
data: (_a = __privateGet(this, _cache4).get(key)) != null ? _a : []
|
|
1524
1641
|
});
|
|
1525
1642
|
});
|
|
1526
1643
|
};
|
|
@@ -1596,6 +1713,32 @@ var Preferences = class extends BaseModule {
|
|
|
1596
1713
|
}));
|
|
1597
1714
|
});
|
|
1598
1715
|
}
|
|
1716
|
+
update(args) {
|
|
1717
|
+
return __async(this, null, function* () {
|
|
1718
|
+
return this.callWithSession(
|
|
1719
|
+
() => updatePreference({
|
|
1720
|
+
emitter: this._emitter,
|
|
1721
|
+
apiService: this._inboxService,
|
|
1722
|
+
cache: this.cache,
|
|
1723
|
+
useCache: __privateGet(this, _useCache3),
|
|
1724
|
+
args
|
|
1725
|
+
})
|
|
1726
|
+
);
|
|
1727
|
+
});
|
|
1728
|
+
}
|
|
1729
|
+
bulkUpdate(args) {
|
|
1730
|
+
return __async(this, null, function* () {
|
|
1731
|
+
return this.callWithSession(
|
|
1732
|
+
() => bulkUpdatePreference({
|
|
1733
|
+
emitter: this._emitter,
|
|
1734
|
+
apiService: this._inboxService,
|
|
1735
|
+
cache: this.cache,
|
|
1736
|
+
useCache: __privateGet(this, _useCache3),
|
|
1737
|
+
args
|
|
1738
|
+
})
|
|
1739
|
+
);
|
|
1740
|
+
});
|
|
1741
|
+
}
|
|
1599
1742
|
};
|
|
1600
1743
|
_useCache3 = new WeakMap();
|
|
1601
1744
|
|
package/dist/esm/index.d.mts
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.mjs';
|
|
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.mjs';
|
|
3
3
|
|
|
4
4
|
declare const areTagsEqual: (tags1?: string[], tags2?: string[]) => boolean;
|
|
5
5
|
declare const isSameFilter: (filter1: NotificationFilter, filter2: NotificationFilter) => boolean;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { ChannelType, NotificationStatus, Novu, PreferenceLevel, WebSocketEvent, areTagsEqual, isSameFilter } from './chunk-
|
|
1
|
+
export { ChannelType, NotificationStatus, Novu, PreferenceLevel, WebSocketEvent, areTagsEqual, isSameFilter } from './chunk-P4YVABAC.mjs';
|
|
2
2
|
import './chunk-STZMOEWR.mjs';
|