@novu/js 2.4.0 → 2.6.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.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkXKQCRZD6_js = require('../chunk-XKQCRZD6.js');
3
+ var chunkR7DABK4G_js = require('../chunk-R7DABK4G.js');
4
4
  var chunkERC62PGI_js = require('../chunk-ERC62PGI.js');
5
5
  var chunk7B52C2XE_js = require('../chunk-7B52C2XE.js');
6
6
  var web = require('solid-js/web');
@@ -526,9 +526,9 @@ var useNovuEvent = ({
526
526
  }) => {
527
527
  const novu = useNovu();
528
528
  solidJs.onMount(() => {
529
- novu.on(event, eventHandler);
529
+ const cleanup = novu.on(event, eventHandler);
530
530
  solidJs.onCleanup(() => {
531
- novu.off(event, eventHandler);
531
+ cleanup();
532
532
  });
533
533
  });
534
534
  };
@@ -585,11 +585,14 @@ var useWebSocketEvent = ({
585
585
  postMessage(data);
586
586
  };
587
587
  solidJs.onMount(() => {
588
+ let cleanup;
588
589
  const resolveLock = requestLock(`nv.${webSocketEvent}`, () => {
589
- novu.on(webSocketEvent, updateReadCount);
590
+ cleanup = novu.on(webSocketEvent, updateReadCount);
590
591
  });
591
592
  solidJs.onCleanup(() => {
592
- novu.off(webSocketEvent, updateReadCount);
593
+ if (cleanup) {
594
+ cleanup();
595
+ }
593
596
  resolveLock();
594
597
  });
595
598
  });
@@ -750,7 +753,7 @@ var useInboxContext = () => {
750
753
  };
751
754
  var NovuContext = solidJs.createContext(void 0);
752
755
  function NovuProvider(props) {
753
- const novu = solidJs.createMemo(() => props.novu || new chunkXKQCRZD6_js.Novu(props.options));
756
+ const novu = solidJs.createMemo(() => props.novu || new chunkR7DABK4G_js.Novu(props.options));
754
757
  return web.createComponent(NovuContext.Provider, {
755
758
  get value() {
756
759
  return novu();
@@ -2009,17 +2012,17 @@ var useNotificationsInfiniteScroll = (props) => {
2009
2012
  }));
2010
2013
  solidJs.onMount(() => {
2011
2014
  const listener = ({ data: data2 }) => {
2012
- if (!data2 || !chunkXKQCRZD6_js.isSameFilter(filter, data2.filter)) {
2015
+ if (!data2 || !chunkR7DABK4G_js.isSameFilter(filter, data2.filter)) {
2013
2016
  return;
2014
2017
  }
2015
2018
  mutate({ data: data2.notifications, hasMore: data2.hasMore });
2016
2019
  };
2017
- novu.on("notifications.list.updated", listener);
2018
- solidJs.onCleanup(() => novu.off("notifications.list.updated", listener));
2020
+ const cleanup = novu.on("notifications.list.updated", listener);
2021
+ solidJs.onCleanup(() => cleanup());
2019
2022
  });
2020
2023
  solidJs.createEffect(() => {
2021
2024
  const newFilter = chunk7B52C2XE_js.__spreadValues({}, props.options());
2022
- if (chunkXKQCRZD6_js.isSameFilter(filter, newFilter)) {
2025
+ if (chunkR7DABK4G_js.isSameFilter(filter, newFilter)) {
2023
2026
  return;
2024
2027
  }
2025
2028
  novu.notifications.clearCache();
@@ -2051,8 +2054,8 @@ var usePreferences = (options) => {
2051
2054
  }
2052
2055
  mutate(data);
2053
2056
  };
2054
- novu.on("preferences.list.updated", listener);
2055
- solidJs.onCleanup(() => novu.off("preferences.list.updated", listener));
2057
+ const cleanup = novu.on("preferences.list.updated", listener);
2058
+ solidJs.onCleanup(() => cleanup());
2056
2059
  });
2057
2060
  solidJs.createEffect(() => {
2058
2061
  setLoading(preferences.loading);
@@ -2069,7 +2072,7 @@ var useReadAll = (props) => {
2069
2072
  yield novu.notifications.readAll({ tags });
2070
2073
  (_a = props == null ? void 0 : props.onSuccess) == null ? void 0 : _a.call(props);
2071
2074
  } catch (error) {
2072
- (_b = props == null ? void 0 : props.onError) == null ? void 0 : _b.call(props, error);
2075
+ (_b = void 0 ) == null ? void 0 : _b.call(props, error);
2073
2076
  }
2074
2077
  });
2075
2078
  return { readAll };
@@ -2084,7 +2087,7 @@ var useArchiveAll = (props) => {
2084
2087
  yield novu.notifications.archiveAll({ tags });
2085
2088
  (_a = props == null ? void 0 : props.onSuccess) == null ? void 0 : _a.call(props);
2086
2089
  } catch (error) {
2087
- (_b = props == null ? void 0 : props.onError) == null ? void 0 : _b.call(props, error);
2090
+ (_b = void 0 ) == null ? void 0 : _b.call(props, error);
2088
2091
  }
2089
2092
  });
2090
2093
  return { archiveAll };
@@ -2099,7 +2102,7 @@ var useArchiveAllRead = (props) => {
2099
2102
  yield novu.notifications.archiveAllRead({ tags });
2100
2103
  (_a = props == null ? void 0 : props.onSuccess) == null ? void 0 : _a.call(props);
2101
2104
  } catch (error) {
2102
- (_b = props == null ? void 0 : props.onError) == null ? void 0 : _b.call(props, error);
2105
+ (_b = void 0 ) == null ? void 0 : _b.call(props, error);
2103
2106
  }
2104
2107
  });
2105
2108
  return { archiveAllRead };
@@ -3995,7 +3998,7 @@ var Renderer = (props) => {
3995
3998
  }
3996
3999
  });
3997
4000
  };
3998
- var version = "2.4.0";
4001
+ var version = "2.6.0";
3999
4002
  var cssHref = `https://cdn.jsdelivr.net/npm/@novu/js@${version}/dist/index.css`;
4000
4003
  var _dispose, _rootElement, _mountedElements, _setMountedElements, _appearance, _setAppearance, _localization, _setLocalization, _options, _setOptions, _tabs, _setTabs, _routerPush, _setRouterPush, _preferencesFilter, _setPreferencesFilter, _predefinedNovu, _NovuUI_instances, mountComponentRenderer_fn, updateComponentProps_fn;
4001
4004
  var NovuUI = class {
@@ -89,6 +89,9 @@ var NovuEventEmitter = class {
89
89
  }
90
90
  on(eventName, listener) {
91
91
  __privateGet(this, _mittEmitter).on(eventName, listener);
92
+ return () => {
93
+ this.off(eventName, listener);
94
+ };
92
95
  }
93
96
  off(eventName, listener) {
94
97
  __privateGet(this, _mittEmitter).off(eventName, listener);
@@ -272,8 +275,15 @@ var Notification = class {
272
275
  });
273
276
  }
274
277
  on(eventName, listener) {
275
- __privateGet(this, _emitter).on(eventName, listener);
278
+ const cleanup = __privateGet(this, _emitter).on(eventName, listener);
279
+ return () => {
280
+ cleanup();
281
+ };
276
282
  }
283
+ /**
284
+ * @deprecated
285
+ * Use the cleanup function returned by the "on" method instead.
286
+ */
277
287
  off(eventName, listener) {
278
288
  __privateGet(this, _emitter).off(eventName, listener);
279
289
  }
@@ -806,7 +816,8 @@ var Notifications = class extends BaseModule {
806
816
  return this.callWithSession(() => __async(this, null, function* () {
807
817
  const args = __spreadValues({ limit }, restOptions);
808
818
  try {
809
- let data = __privateGet(this, _useCache) ? this.cache.getAll(args) : void 0;
819
+ const shouldUseCache = "useCache" in args ? args.useCache : __privateGet(this, _useCache);
820
+ let data = shouldUseCache ? this.cache.getAll(args) : void 0;
810
821
  this._emitter.emit("notifications.list.pending", { args, data });
811
822
  if (!data) {
812
823
  const response = yield this._inboxService.fetchNotifications(__spreadValues({
@@ -817,7 +828,7 @@ var Notifications = class extends BaseModule {
817
828
  filter: response.filter,
818
829
  notifications: response.data.map((el) => new Notification(el, this._emitter, this._inboxService))
819
830
  };
820
- if (__privateGet(this, _useCache)) {
831
+ if (shouldUseCache) {
821
832
  this.cache.set(args, data);
822
833
  data = this.cache.getAll(args);
823
834
  }
@@ -1044,44 +1055,12 @@ _emitter3 = new WeakMap();
1044
1055
  _inboxService2 = new WeakMap();
1045
1056
  _options = new WeakMap();
1046
1057
 
1047
- // src/preferences/preference.ts
1048
- var _emitter4, _apiService;
1049
- var Preference = class {
1050
- constructor(preference, { emitterInstance, inboxServiceInstance }) {
1051
- __privateAdd(this, _emitter4);
1052
- __privateAdd(this, _apiService);
1053
- __privateSet(this, _emitter4, emitterInstance);
1054
- __privateSet(this, _apiService, inboxServiceInstance);
1055
- this.level = preference.level;
1056
- this.enabled = preference.enabled;
1057
- this.channels = preference.channels;
1058
- this.workflow = preference.workflow;
1059
- }
1060
- update({ channelPreferences }) {
1061
- var _a;
1062
- return updatePreference({
1063
- emitter: __privateGet(this, _emitter4),
1064
- apiService: __privateGet(this, _apiService),
1065
- args: {
1066
- workflowId: (_a = this.workflow) == null ? void 0 : _a.id,
1067
- channelPreferences,
1068
- preference: {
1069
- level: this.level,
1070
- enabled: this.enabled,
1071
- channels: this.channels,
1072
- workflow: this.workflow
1073
- }
1074
- }
1075
- });
1076
- }
1077
- };
1078
- _emitter4 = new WeakMap();
1079
- _apiService = new WeakMap();
1080
-
1081
1058
  // src/preferences/helpers.ts
1082
1059
  var updatePreference = (_0) => __async(void 0, [_0], function* ({
1083
1060
  emitter,
1084
1061
  apiService,
1062
+ cache,
1063
+ useCache,
1085
1064
  args
1086
1065
  }) {
1087
1066
  const { workflowId, channelPreferences } = args;
@@ -1094,7 +1073,9 @@ var updatePreference = (_0) => __async(void 0, [_0], function* ({
1094
1073
  }),
1095
1074
  {
1096
1075
  emitterInstance: emitter,
1097
- inboxServiceInstance: apiService
1076
+ inboxServiceInstance: apiService,
1077
+ cache,
1078
+ useCache
1098
1079
  }
1099
1080
  ) : void 0
1100
1081
  });
@@ -1102,11 +1083,14 @@ var updatePreference = (_0) => __async(void 0, [_0], function* ({
1102
1083
  if (workflowId) {
1103
1084
  response = yield apiService.updateWorkflowPreferences({ workflowId, channelPreferences });
1104
1085
  } else {
1086
+ optimisticUpdateWorkflowPreferences({ emitter, apiService, cache, useCache, args });
1105
1087
  response = yield apiService.updateGlobalPreferences(channelPreferences);
1106
1088
  }
1107
1089
  const preference = new Preference(response, {
1108
1090
  emitterInstance: emitter,
1109
- inboxServiceInstance: apiService
1091
+ inboxServiceInstance: apiService,
1092
+ cache,
1093
+ useCache
1110
1094
  });
1111
1095
  emitter.emit("preference.update.resolved", { args, data: preference });
1112
1096
  return { data: preference };
@@ -1115,6 +1099,90 @@ var updatePreference = (_0) => __async(void 0, [_0], function* ({
1115
1099
  return { error: new NovuError("Failed to fetch notifications", error) };
1116
1100
  }
1117
1101
  });
1102
+ var optimisticUpdateWorkflowPreferences = ({
1103
+ emitter,
1104
+ apiService,
1105
+ cache,
1106
+ useCache,
1107
+ args
1108
+ }) => {
1109
+ const allPreferences = useCache ? cache == null ? void 0 : cache.getAll({}) : void 0;
1110
+ allPreferences == null ? void 0 : allPreferences.forEach((el) => {
1111
+ var _a;
1112
+ if (el.level === "template" /* TEMPLATE */) {
1113
+ const mergedPreference = __spreadProps(__spreadValues({}, el), {
1114
+ channels: Object.entries(el.channels).reduce((acc, [key, value]) => {
1115
+ var _a2;
1116
+ const channelType = key;
1117
+ acc[channelType] = (_a2 = args.channelPreferences[channelType]) != null ? _a2 : value;
1118
+ return acc;
1119
+ }, {})
1120
+ });
1121
+ const updatedPreference = args.preference ? new Preference(mergedPreference, {
1122
+ emitterInstance: emitter,
1123
+ inboxServiceInstance: apiService,
1124
+ cache,
1125
+ useCache
1126
+ }) : void 0;
1127
+ if (updatedPreference) {
1128
+ emitter.emit("preference.update.pending", {
1129
+ args: {
1130
+ workflowId: (_a = el.workflow) == null ? void 0 : _a.id,
1131
+ channelPreferences: updatedPreference.channels
1132
+ },
1133
+ data: updatedPreference
1134
+ });
1135
+ }
1136
+ }
1137
+ });
1138
+ };
1139
+
1140
+ // src/preferences/preference.ts
1141
+ var _emitter4, _apiService, _cache3, _useCache2;
1142
+ var Preference = class {
1143
+ constructor(preference, {
1144
+ emitterInstance,
1145
+ inboxServiceInstance,
1146
+ cache,
1147
+ useCache
1148
+ }) {
1149
+ __privateAdd(this, _emitter4);
1150
+ __privateAdd(this, _apiService);
1151
+ __privateAdd(this, _cache3);
1152
+ __privateAdd(this, _useCache2);
1153
+ __privateSet(this, _emitter4, emitterInstance);
1154
+ __privateSet(this, _apiService, inboxServiceInstance);
1155
+ __privateSet(this, _cache3, cache);
1156
+ __privateSet(this, _useCache2, useCache);
1157
+ this.level = preference.level;
1158
+ this.enabled = preference.enabled;
1159
+ this.channels = preference.channels;
1160
+ this.workflow = preference.workflow;
1161
+ }
1162
+ update({ channelPreferences }) {
1163
+ var _a;
1164
+ return updatePreference({
1165
+ emitter: __privateGet(this, _emitter4),
1166
+ apiService: __privateGet(this, _apiService),
1167
+ cache: __privateGet(this, _cache3),
1168
+ useCache: __privateGet(this, _useCache2),
1169
+ args: {
1170
+ workflowId: (_a = this.workflow) == null ? void 0 : _a.id,
1171
+ channelPreferences,
1172
+ preference: {
1173
+ level: this.level,
1174
+ enabled: this.enabled,
1175
+ channels: this.channels,
1176
+ workflow: this.workflow
1177
+ }
1178
+ }
1179
+ });
1180
+ }
1181
+ };
1182
+ _emitter4 = new WeakMap();
1183
+ _apiService = new WeakMap();
1184
+ _cache3 = new WeakMap();
1185
+ _useCache2 = new WeakMap();
1118
1186
 
1119
1187
  // src/cache/preferences-cache.ts
1120
1188
  var updateEvents2 = ["preference.update.pending", "preference.update.resolved"];
@@ -1128,13 +1196,13 @@ var excludeEmpty2 = ({ tags }) => Object.entries({ tags }).reduce((acc, [key, va
1128
1196
  var getCacheKey2 = ({ tags }) => {
1129
1197
  return JSON.stringify(excludeEmpty2({ tags }));
1130
1198
  };
1131
- var _emitter5, _cache3;
1199
+ var _emitter5, _cache4;
1132
1200
  var PreferencesCache = class {
1133
1201
  constructor({ emitterInstance }) {
1134
1202
  __privateAdd(this, _emitter5);
1135
- __privateAdd(this, _cache3);
1203
+ __privateAdd(this, _cache4);
1136
1204
  this.updatePreference = (key, data) => {
1137
- const preferences = __privateGet(this, _cache3).get(key);
1205
+ const preferences = __privateGet(this, _cache4).get(key);
1138
1206
  if (!preferences) {
1139
1207
  return false;
1140
1208
  }
@@ -1149,16 +1217,16 @@ var PreferencesCache = class {
1149
1217
  }
1150
1218
  const updatedPreferences = [...preferences];
1151
1219
  updatedPreferences[index] = data;
1152
- __privateGet(this, _cache3).set(key, updatedPreferences);
1220
+ __privateGet(this, _cache4).set(key, updatedPreferences);
1153
1221
  return true;
1154
1222
  };
1155
1223
  this.handlePreferenceEvent = ({ data }) => {
1156
1224
  if (!data) {
1157
1225
  return;
1158
1226
  }
1159
- __privateGet(this, _cache3).keys().forEach((key) => {
1227
+ __privateGet(this, _cache4).keys().forEach((key) => {
1160
1228
  const hasUpdatedPreference = this.updatePreference(key, data);
1161
- const updatedPreference = __privateGet(this, _cache3).get(key);
1229
+ const updatedPreference = __privateGet(this, _cache4).get(key);
1162
1230
  if (!hasUpdatedPreference || !updatedPreference) {
1163
1231
  return;
1164
1232
  }
@@ -1171,28 +1239,28 @@ var PreferencesCache = class {
1171
1239
  updateEvents2.forEach((event) => {
1172
1240
  __privateGet(this, _emitter5).on(event, this.handlePreferenceEvent);
1173
1241
  });
1174
- __privateSet(this, _cache3, new InMemoryCache());
1242
+ __privateSet(this, _cache4, new InMemoryCache());
1175
1243
  }
1176
1244
  has(args) {
1177
- return __privateGet(this, _cache3).get(getCacheKey2(args)) !== void 0;
1245
+ return __privateGet(this, _cache4).get(getCacheKey2(args)) !== void 0;
1178
1246
  }
1179
1247
  set(args, data) {
1180
- __privateGet(this, _cache3).set(getCacheKey2(args), data);
1248
+ __privateGet(this, _cache4).set(getCacheKey2(args), data);
1181
1249
  }
1182
1250
  getAll(args) {
1183
1251
  if (this.has(args)) {
1184
- return __privateGet(this, _cache3).get(getCacheKey2(args));
1252
+ return __privateGet(this, _cache4).get(getCacheKey2(args));
1185
1253
  }
1186
1254
  }
1187
1255
  clearAll() {
1188
- __privateGet(this, _cache3).clear();
1256
+ __privateGet(this, _cache4).clear();
1189
1257
  }
1190
1258
  };
1191
1259
  _emitter5 = new WeakMap();
1192
- _cache3 = new WeakMap();
1260
+ _cache4 = new WeakMap();
1193
1261
 
1194
1262
  // src/preferences/preferences.ts
1195
- var _useCache2;
1263
+ var _useCache3;
1196
1264
  var Preferences = class extends BaseModule {
1197
1265
  constructor({
1198
1266
  useCache,
@@ -1203,27 +1271,29 @@ var Preferences = class extends BaseModule {
1203
1271
  eventEmitterInstance,
1204
1272
  inboxServiceInstance
1205
1273
  });
1206
- __privateAdd(this, _useCache2);
1274
+ __privateAdd(this, _useCache3);
1207
1275
  this.cache = new PreferencesCache({
1208
1276
  emitterInstance: this._emitter
1209
1277
  });
1210
- __privateSet(this, _useCache2, useCache);
1278
+ __privateSet(this, _useCache3, useCache);
1211
1279
  }
1212
1280
  list() {
1213
1281
  return __async(this, arguments, function* (args = {}) {
1214
1282
  return this.callWithSession(() => __async(this, null, function* () {
1215
1283
  try {
1216
- let data = __privateGet(this, _useCache2) ? this.cache.getAll(args) : void 0;
1284
+ let data = __privateGet(this, _useCache3) ? this.cache.getAll(args) : void 0;
1217
1285
  this._emitter.emit("preferences.list.pending", { args, data });
1218
1286
  if (!data) {
1219
1287
  const response = yield this._inboxService.fetchPreferences(args.tags);
1220
1288
  data = response.map(
1221
1289
  (el) => new Preference(el, {
1222
1290
  emitterInstance: this._emitter,
1223
- inboxServiceInstance: this._inboxService
1291
+ inboxServiceInstance: this._inboxService,
1292
+ cache: this.cache,
1293
+ useCache: __privateGet(this, _useCache3)
1224
1294
  })
1225
1295
  );
1226
- if (__privateGet(this, _useCache2)) {
1296
+ if (__privateGet(this, _useCache3)) {
1227
1297
  this.cache.set(args, data);
1228
1298
  data = this.cache.getAll(args);
1229
1299
  }
@@ -1237,17 +1307,8 @@ var Preferences = class extends BaseModule {
1237
1307
  }));
1238
1308
  });
1239
1309
  }
1240
- update(args) {
1241
- return __async(this, null, function* () {
1242
- return this.callWithSession(
1243
- () => __async(this, null, function* () {
1244
- return updatePreference({ emitter: this._emitter, apiService: this._inboxService, args });
1245
- })
1246
- );
1247
- });
1248
- }
1249
1310
  };
1250
- _useCache2 = new WeakMap();
1311
+ _useCache3 = new WeakMap();
1251
1312
  var PRODUCTION_SOCKET_URL = "https://ws.novu.co";
1252
1313
  var NOTIFICATION_RECEIVED = "notifications.notification_received";
1253
1314
  var UNSEEN_COUNT_CHANGED = "notifications.unseen_count_changed";
@@ -1525,7 +1586,7 @@ var InboxService = class {
1525
1586
  _httpClient = new WeakMap();
1526
1587
 
1527
1588
  // src/novu.ts
1528
- var version = "2.4.0";
1589
+ var version = "2.6.0";
1529
1590
  var name = "@novu/js";
1530
1591
  var userAgent = `${name}@${version}`;
1531
1592
  var _emitter7, _session, _socket, _inboxService3;
@@ -1570,7 +1631,10 @@ var Novu = class {
1570
1631
  if (__privateGet(this, _socket).isSocketEvent(eventName)) {
1571
1632
  __privateGet(this, _socket).initialize();
1572
1633
  }
1573
- __privateGet(this, _emitter7).on(eventName, listener);
1634
+ const cleanup = __privateGet(this, _emitter7).on(eventName, listener);
1635
+ return () => {
1636
+ cleanup();
1637
+ };
1574
1638
  };
1575
1639
  this.off = (eventName, listener) => {
1576
1640
  __privateGet(this, _emitter7).off(eventName, listener);
@@ -1,5 +1,5 @@
1
- import { N as NotificationFilter } from './novu-gS68EfJw.mjs';
2
- export { k as Action, A as ActionTypeEnum, m as ChannelPreference, f as ChannelType, C as CtaType, E as EventHandler, a as Events, F as FiltersCountResponse, q as IPreferenceOverride, I as InboxNotification, L as ListNotificationsResponse, i as MessageAction, M as MessageButton, t as Notification, e as NotificationActionStatus, d as NotificationButton, c as NotificationStatus, b as Novu, v as NovuError, s as NovuOptions, n as PaginatedResponse, u as Preference, P as PreferenceLevel, g as PreferenceOverrideSource, p as PreferenceOverrideSourceEnum, o as PreferencesResponse, R as Redirect, r as Result, h as Session, S as SocketEventNames, j as Subscriber, T as TODO, W as WebSocketEvent, l as Workflow } from './novu-gS68EfJw.mjs';
1
+ import { N as NotificationFilter } from './novu-C3OVXS9Q.mjs';
2
+ export { k as Action, A as ActionTypeEnum, m as ChannelPreference, f as ChannelType, C as CtaType, E as EventHandler, a as Events, F as FiltersCountResponse, q as IPreferenceOverride, I as InboxNotification, L as ListNotificationsResponse, i as MessageAction, M as MessageButton, t as Notification, e as NotificationActionStatus, d as NotificationButton, c as NotificationStatus, b as Novu, v as NovuError, s as NovuOptions, n as PaginatedResponse, u as Preference, P as PreferenceLevel, g as PreferenceOverrideSource, p as PreferenceOverrideSourceEnum, o as PreferencesResponse, R as Redirect, r as Result, h as Session, S as SocketEventNames, j as Subscriber, T as TODO, W as WebSocketEvent, l as Workflow } from './novu-C3OVXS9Q.mjs';
3
3
  import '@novu/client';
4
4
 
5
5
  declare const areTagsEqual: (tags1?: string[], tags2?: string[]) => boolean;
@@ -1,2 +1,2 @@
1
- export { ActionTypeEnum, ChannelType, CtaType, NotificationActionStatus, NotificationButton, NotificationStatus, Novu, PreferenceLevel, PreferenceOverrideSource, PreferenceOverrideSourceEnum, WebSocketEvent, areTagsEqual, isSameFilter } from './chunk-VCUP7D3X.mjs';
1
+ export { ActionTypeEnum, ChannelType, CtaType, NotificationActionStatus, NotificationButton, NotificationStatus, Novu, PreferenceLevel, PreferenceOverrideSource, PreferenceOverrideSourceEnum, WebSocketEvent, areTagsEqual, isSameFilter } from './chunk-BGMSCE2S.mjs';
2
2
  import './chunk-STZMOEWR.mjs';
@@ -5,6 +5,33 @@ declare class NovuError extends Error {
5
5
  constructor(message: string, originalError: unknown);
6
6
  }
7
7
 
8
+ type ListPreferencesArgs = {
9
+ tags?: string[];
10
+ };
11
+ type UpdatePreferencesArgs = {
12
+ workflowId?: string;
13
+ channelPreferences: ChannelPreference;
14
+ preference?: {
15
+ level: PreferenceLevel;
16
+ enabled: boolean;
17
+ channels: ChannelPreference;
18
+ workflow?: Workflow;
19
+ };
20
+ };
21
+
22
+ declare class PreferencesCache {
23
+ #private;
24
+ constructor({ emitterInstance }: {
25
+ emitterInstance: NovuEventEmitter;
26
+ });
27
+ private updatePreference;
28
+ private handlePreferenceEvent;
29
+ has(args: ListPreferencesArgs): boolean;
30
+ set(args: ListPreferencesArgs, data: Preference[]): void;
31
+ getAll(args: ListPreferencesArgs): Preference[] | undefined;
32
+ clearAll(): void;
33
+ }
34
+
8
35
  type PreferenceLike = Pick<Preference, 'level' | 'enabled' | 'channels' | 'workflow'>;
9
36
  declare class Preference {
10
37
  #private;
@@ -12,9 +39,11 @@ declare class Preference {
12
39
  readonly enabled: boolean;
13
40
  readonly channels: ChannelPreference;
14
41
  readonly workflow?: Workflow;
15
- constructor(preference: PreferenceLike, { emitterInstance, inboxServiceInstance }: {
42
+ constructor(preference: PreferenceLike, { emitterInstance, inboxServiceInstance, cache, useCache, }: {
16
43
  emitterInstance: NovuEventEmitter;
17
44
  inboxServiceInstance: InboxService;
45
+ cache: PreferencesCache;
46
+ useCache: boolean;
18
47
  });
19
48
  update({ channelPreferences }: {
20
49
  channelPreferences: ChannelPreference;
@@ -251,7 +280,7 @@ declare class BaseModule {
251
280
  callWithSession<T>(fn: () => Result<T>): Result<T>;
252
281
  }
253
282
 
254
- declare class Notification implements Pick<NovuEventEmitter, 'on' | 'off'>, InboxNotification {
283
+ declare class Notification implements Pick<NovuEventEmitter, 'on'>, InboxNotification {
255
284
  #private;
256
285
  readonly id: InboxNotification['id'];
257
286
  readonly subject?: InboxNotification['subject'];
@@ -278,7 +307,11 @@ declare class Notification implements Pick<NovuEventEmitter, 'on' | 'off'>, Inbo
278
307
  completeSecondary(): Result<Notification>;
279
308
  revertPrimary(): Result<Notification>;
280
309
  revertSecondary(): Result<Notification>;
281
- on<Key extends EventNames>(eventName: Key, listener: EventHandler<Events[Key]>): void;
310
+ on<Key extends EventNames>(eventName: Key, listener: EventHandler<Events[Key]>): () => void;
311
+ /**
312
+ * @deprecated
313
+ * Use the cleanup function returned by the "on" method instead.
314
+ */
282
315
  off<Key extends EventNames>(eventName: Key, listener: EventHandler<Events[Key]>): void;
283
316
  }
284
317
 
@@ -289,6 +322,7 @@ type ListNotificationsArgs = {
289
322
  limit?: number;
290
323
  after?: string;
291
324
  offset?: number;
325
+ useCache?: boolean;
292
326
  };
293
327
  type ListNotificationsResponse = {
294
328
  notifications: Notification[];
@@ -395,20 +429,6 @@ declare class Notifications extends BaseModule {
395
429
  }): void;
396
430
  }
397
431
 
398
- type ListPreferencesArgs = {
399
- tags?: string[];
400
- };
401
- type UpdatePreferencesArgs = {
402
- workflowId?: string;
403
- channelPreferences: ChannelPreference;
404
- preference?: {
405
- level: PreferenceLevel;
406
- enabled: boolean;
407
- channels: ChannelPreference;
408
- workflow?: Workflow;
409
- };
410
- };
411
-
412
432
  type InitializeSessionArgs = {
413
433
  applicationIdentifier: string;
414
434
  subscriberId: string;
@@ -495,24 +515,11 @@ type EventHandler<T = unknown> = (event: T) => void;
495
515
  declare class NovuEventEmitter {
496
516
  #private;
497
517
  constructor();
498
- on<Key extends EventNames>(eventName: Key, listener: EventHandler<Events[Key]>): void;
518
+ on<Key extends EventNames>(eventName: Key, listener: EventHandler<Events[Key]>): () => void;
499
519
  off<Key extends EventNames>(eventName: Key, listener: EventHandler<Events[Key]>): void;
500
520
  emit<Key extends EventNames>(type: Key, event?: Events[Key]): void;
501
521
  }
502
522
 
503
- declare class PreferencesCache {
504
- #private;
505
- constructor({ emitterInstance }: {
506
- emitterInstance: NovuEventEmitter;
507
- });
508
- private updatePreference;
509
- private handlePreferenceEvent;
510
- has(args: ListPreferencesArgs): boolean;
511
- set(args: ListPreferencesArgs, data: Preference[]): void;
512
- getAll(args: ListPreferencesArgs): Preference[] | undefined;
513
- clearAll(): void;
514
- }
515
-
516
523
  declare class Preferences extends BaseModule {
517
524
  #private;
518
525
  readonly cache: PreferencesCache;
@@ -522,14 +529,17 @@ declare class Preferences extends BaseModule {
522
529
  eventEmitterInstance: NovuEventEmitter;
523
530
  });
524
531
  list(args?: ListPreferencesArgs): Result<Preference[]>;
525
- update(args: UpdatePreferencesArgs): Result<Preference>;
526
532
  }
527
533
 
528
- declare class Novu implements Pick<NovuEventEmitter, 'on' | 'off'> {
534
+ declare class Novu implements Pick<NovuEventEmitter, 'on'> {
529
535
  #private;
530
536
  readonly notifications: Notifications;
531
537
  readonly preferences: Preferences;
532
- on: <Key extends EventNames>(eventName: Key, listener: EventHandler<Events[Key]>) => void;
538
+ on: <Key extends EventNames>(eventName: Key, listener: EventHandler<Events[Key]>) => () => void;
539
+ /**
540
+ * @deprecated
541
+ * Use the cleanup function returned by the "on" method instead.
542
+ */
533
543
  off: <Key extends EventNames>(eventName: Key, listener: EventHandler<Events[Key]>) => void;
534
544
  constructor(options: NovuOptions);
535
545
  }
@@ -1,5 +1,5 @@
1
- import { g as Theme } from '../types-MmHw9UXx.mjs';
2
- import '../novu-gS68EfJw.mjs';
1
+ import { g as Theme } from '../types-Cuys78dx.mjs';
2
+ import '../novu-C3OVXS9Q.mjs';
3
3
  import '@novu/client';
4
4
 
5
5
  declare const dark: Theme;
@@ -1,4 +1,4 @@
1
- import { t as Notification, N as NotificationFilter, s as NovuOptions, b as Novu } from './novu-gS68EfJw.mjs';
1
+ import { t as Notification, N as NotificationFilter, s as NovuOptions, b as Novu } from './novu-C3OVXS9Q.mjs';
2
2
 
3
3
  declare const defaultLocalization: {
4
4
  readonly locale: "en-US";
@@ -1,7 +1,7 @@
1
- import { s as NovuOptions } from '../novu-gS68EfJw.mjs';
2
- export { t as Notification } from '../novu-gS68EfJw.mjs';
3
- import { N as NotificationRenderer, B as BellRenderer, a as NotificationClickHandler, b as NotificationActionClickHandler, c as NovuProviderProps, d as BaseNovuProviderProps, A as Appearance, L as Localization, T as Tab, P as PreferencesFilter, R as RouterPush } from '../types-MmHw9UXx.mjs';
4
- export { e as AppearanceKey, C as CSSProperties, E as ElementStyles, f as Elements, i as LocalizationKey, h as NotificationStatus, g as Theme, V as Variables } from '../types-MmHw9UXx.mjs';
1
+ import { s as NovuOptions } from '../novu-C3OVXS9Q.mjs';
2
+ export { t as Notification } from '../novu-C3OVXS9Q.mjs';
3
+ import { N as NotificationRenderer, B as BellRenderer, a as NotificationClickHandler, b as NotificationActionClickHandler, c as NovuProviderProps, d as BaseNovuProviderProps, A as Appearance, L as Localization, T as Tab, P as PreferencesFilter, R as RouterPush } from '../types-Cuys78dx.mjs';
4
+ export { e as AppearanceKey, C as CSSProperties, E as ElementStyles, f as Elements, i as LocalizationKey, h as NotificationStatus, g as Theme, V as Variables } from '../types-Cuys78dx.mjs';
5
5
  import * as solid_js from 'solid-js';
6
6
  import { ComponentProps } from 'solid-js';
7
7
  import { MountableElement } from 'solid-js/web';