@novu/react 2.1.2 → 2.3.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.
@@ -32,7 +32,7 @@ var src_exports = {};
32
32
  __export(src_exports, {
33
33
  Bell: () => Bell,
34
34
  Inbox: () => Inbox,
35
- InboxChild: () => InboxChild,
35
+ InboxContent: () => InboxContent,
36
36
  Notifications: () => Notifications,
37
37
  NovuProvider: () => NovuProvider,
38
38
  Preferences: () => Preferences,
@@ -45,10 +45,36 @@ __export(src_exports, {
45
45
  module.exports = __toCommonJS(src_exports);
46
46
 
47
47
  // src/components/Bell.tsx
48
- var import_react3 = __toESM(require("react"));
48
+ var import_react4 = __toESM(require("react"));
49
+
50
+ // src/components/Mounter.tsx
51
+ var import_react = require("react");
52
+ var import_jsx_runtime = require("react/jsx-runtime");
53
+ function Mounter({ mount }) {
54
+ const ref = (0, import_react.useRef)(null);
55
+ (0, import_react.useEffect)(() => {
56
+ let unmount;
57
+ const element = ref.current;
58
+ if (element && mount) {
59
+ const possibleUnmount = mount(element);
60
+ if (possibleUnmount) {
61
+ unmount = possibleUnmount;
62
+ }
63
+ }
64
+ return () => {
65
+ if (element && unmount) {
66
+ unmount(element);
67
+ }
68
+ };
69
+ }, [ref, mount]);
70
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref });
71
+ }
72
+
73
+ // src/components/Renderer.tsx
74
+ var import_react3 = require("react");
49
75
 
50
76
  // src/utils/createContextAndHook.ts
51
- var import_react = __toESM(require("react"));
77
+ var import_react2 = __toESM(require("react"));
52
78
  function assertContextExists(contextVal, msgOrCtx) {
53
79
  if (!contextVal) {
54
80
  throw typeof msgOrCtx === "string" ? new Error(msgOrCtx) : new Error(`${msgOrCtx.displayName} not found`);
@@ -56,56 +82,79 @@ function assertContextExists(contextVal, msgOrCtx) {
56
82
  }
57
83
  var createContextAndHook = (displayName, options) => {
58
84
  const { assertCtxFn = assertContextExists } = options || {};
59
- const Ctx = import_react.default.createContext(void 0);
85
+ const Ctx = import_react2.default.createContext(void 0);
60
86
  Ctx.displayName = displayName;
61
87
  const useCtx = () => {
62
- const ctx = import_react.default.useContext(Ctx);
63
- assertCtxFn(ctx, `Component must be wrapped with the <Inbox /> Component`);
88
+ const ctx = import_react2.default.useContext(Ctx);
89
+ assertCtxFn(ctx, `Component must be wrapped with ${Ctx.displayName}`);
64
90
  return ctx.value;
65
91
  };
66
92
  const useCtxWithoutGuarantee = () => {
67
- const ctx = import_react.default.useContext(Ctx);
93
+ const ctx = import_react2.default.useContext(Ctx);
68
94
  return ctx ? ctx.value : {};
69
95
  };
70
96
  return [Ctx, useCtx, useCtxWithoutGuarantee];
71
97
  };
72
98
 
73
- // src/context/RenderContext.tsx
74
- var import_jsx_runtime = require("react/jsx-runtime");
75
- var [RendererContext, useRendererContext] = createContextAndHook("RendererContext");
99
+ // src/context/RendererContext.tsx
100
+ var import_jsx_runtime2 = require("react/jsx-runtime");
101
+ var [RendererContext, useRendererContext, useUnsafeRendererContext] = createContextAndHook("RendererContext");
76
102
  var RendererProvider = (props) => {
77
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RendererContext.Provider, { value: { value: props.value }, children: props.children });
103
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RendererContext.Provider, { value: { value: props.value }, children: props.children });
78
104
  };
79
105
 
80
- // src/components/Mounter.tsx
81
- var import_react2 = __toESM(require("react"));
82
- var import_jsx_runtime2 = require("react/jsx-runtime");
83
- function Mounter({ mount }) {
84
- const ref = import_react2.default.useRef(null);
85
- import_react2.default.useEffect(() => {
86
- let unmount;
87
- const element = ref.current;
88
- if (element && mount) {
89
- const possibleUnmount = mount(element);
90
- if (possibleUnmount) {
91
- unmount = possibleUnmount;
92
- }
93
- }
94
- return () => {
95
- if (element && unmount) {
96
- unmount(element);
97
- }
98
- };
99
- }, [ref, mount]);
100
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ref });
101
- }
106
+ // src/components/Renderer.tsx
107
+ var import_react_dom = require("react-dom");
108
+ var import_jsx_runtime3 = require("react/jsx-runtime");
109
+ var Renderer = (props) => {
110
+ const { children } = props;
111
+ const [mountedElements, setMountedElements] = (0, import_react3.useState)(/* @__PURE__ */ new Map());
112
+ const mountElement = (0, import_react3.useCallback)(
113
+ (el, mountedElement) => {
114
+ setMountedElements((prev) => {
115
+ const newMountedElements = new Map(prev);
116
+ newMountedElements.set(el, mountedElement);
117
+ return newMountedElements;
118
+ });
119
+ return () => {
120
+ setMountedElements((prev) => {
121
+ const newMountedElements = new Map(prev);
122
+ newMountedElements.delete(el);
123
+ return newMountedElements;
124
+ });
125
+ };
126
+ },
127
+ [setMountedElements]
128
+ );
129
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(RendererProvider, { value: { mountElement }, children: [
130
+ [...mountedElements].map(([element, mountedElement]) => {
131
+ return (0, import_react_dom.createPortal)(mountedElement, element);
132
+ }),
133
+ children
134
+ ] });
135
+ };
136
+ var withRenderer = (WrappedComponent) => {
137
+ const HOC = (props) => {
138
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Renderer, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(WrappedComponent, { ...props }) });
139
+ };
140
+ HOC.displayName = `WithRenderer(${WrappedComponent.displayName || WrappedComponent.name || "Component"})`;
141
+ return HOC;
142
+ };
143
+
144
+ // src/context/NovuUIContext.tsx
145
+ var import_jsx_runtime4 = require("react/jsx-runtime");
146
+ var [NovuUIContext, useNovuUIContext, useUnsafeNovuUIContext] = createContextAndHook("NovuUIContext");
147
+ var NovuUIProvider = (props) => {
148
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(NovuUIContext.Provider, { value: { value: props.value }, children: props.children });
149
+ };
102
150
 
103
151
  // src/components/Bell.tsx
104
- var import_jsx_runtime3 = require("react/jsx-runtime");
105
- var Bell = import_react3.default.memo((props) => {
152
+ var import_jsx_runtime5 = require("react/jsx-runtime");
153
+ var _Bell = import_react4.default.memo((props) => {
106
154
  const { renderBell } = props;
107
- const { novuUI, mountElement } = useRendererContext();
108
- const mount = import_react3.default.useCallback(
155
+ const { novuUI } = useNovuUIContext();
156
+ const { mountElement } = useRendererContext();
157
+ const mount = import_react4.default.useCallback(
109
158
  (element) => {
110
159
  return novuUI.mountComponent({
111
160
  name: "Bell",
@@ -115,56 +164,70 @@ var Bell = import_react3.default.memo((props) => {
115
164
  },
116
165
  [renderBell]
117
166
  );
118
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Mounter, { mount });
167
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Mounter, { mount });
119
168
  });
169
+ var Bell = withRenderer(_Bell);
120
170
 
121
171
  // src/components/Inbox.tsx
122
- var import_react6 = __toESM(require("react"));
172
+ var import_react8 = __toESM(require("react"));
123
173
 
124
- // src/components/Renderer.tsx
174
+ // src/hooks/NovuProvider.tsx
175
+ var import_js = require("@novu/js");
125
176
  var import_react5 = require("react");
126
- var import_react_dom = __toESM(require("react-dom"));
177
+ var import_jsx_runtime6 = require("react/jsx-runtime");
178
+ var NovuContext = (0, import_react5.createContext)(void 0);
179
+ var NovuProvider = ({
180
+ children,
181
+ applicationIdentifier,
182
+ subscriberId,
183
+ subscriberHash,
184
+ backendUrl,
185
+ socketUrl,
186
+ useCache
187
+ }) => {
188
+ const novu = (0, import_react5.useMemo)(
189
+ () => new import_js.Novu({ applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl, useCache }),
190
+ [applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl, useCache]
191
+ );
192
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(NovuContext.Provider, { value: novu, children });
193
+ };
194
+ var useNovu = () => {
195
+ const context = (0, import_react5.useContext)(NovuContext);
196
+ if (!context) {
197
+ throw new Error("useNovu must be used within a <NovuProvider />");
198
+ }
199
+ return context;
200
+ };
201
+ var useUnsafeNovu = () => {
202
+ const context = (0, import_react5.useContext)(NovuContext);
203
+ return context;
204
+ };
205
+
206
+ // src/components/NovuUI.tsx
127
207
  var import_ui = require("@novu/js/ui");
208
+ var import_react7 = require("react");
128
209
 
129
210
  // src/hooks/internal/useDataRef.ts
130
- var import_react4 = require("react");
211
+ var import_react6 = require("react");
131
212
  var useDataRef = (data) => {
132
- const ref = (0, import_react4.useRef)(data);
213
+ const ref = (0, import_react6.useRef)(data);
133
214
  ref.current = data;
134
215
  return ref;
135
216
  };
136
217
 
137
- // src/components/Renderer.tsx
138
- var import_jsx_runtime4 = require("react/jsx-runtime");
139
- var Renderer = ({ options, novu, children }) => {
218
+ // src/components/NovuUI.tsx
219
+ var import_jsx_runtime7 = require("react/jsx-runtime");
220
+ var NovuUI = ({ options, novu, children }) => {
140
221
  const optionsRef = useDataRef({ ...options, novu });
141
- const [novuUI, setNovuUI] = (0, import_react5.useState)();
142
- const [mountedElements, setMountedElements] = (0, import_react5.useState)(/* @__PURE__ */ new Map());
143
- const mountElement = (0, import_react5.useCallback)(
144
- (el, mountedElement) => {
145
- setMountedElements((prev) => {
146
- const newMountedElements = new Map(prev);
147
- newMountedElements.set(el, mountedElement);
148
- return newMountedElements;
149
- });
150
- return () => {
151
- setMountedElements((prev) => {
152
- const newMountedElements = new Map(prev);
153
- newMountedElements.delete(el);
154
- return newMountedElements;
155
- });
156
- };
157
- },
158
- [setMountedElements]
159
- );
160
- (0, import_react5.useEffect)(() => {
222
+ const [novuUI, setNovuUI] = (0, import_react7.useState)();
223
+ (0, import_react7.useEffect)(() => {
161
224
  const novu2 = new import_ui.NovuUI(optionsRef.current);
162
225
  setNovuUI(novu2);
163
226
  return () => {
164
227
  novu2.unmount();
165
228
  };
166
229
  }, []);
167
- (0, import_react5.useEffect)(() => {
230
+ (0, import_react7.useEffect)(() => {
168
231
  if (!novuUI) {
169
232
  return;
170
233
  }
@@ -177,20 +240,16 @@ var Renderer = ({ options, novu, children }) => {
177
240
  if (!novuUI) {
178
241
  return null;
179
242
  }
180
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(RendererProvider, { value: { mountElement, novuUI }, children: [
181
- [...mountedElements].map(([element, mountedElement]) => {
182
- return import_react_dom.default.createPortal(mountedElement, element);
183
- }),
184
- children
185
- ] });
243
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(NovuUIProvider, { value: { novuUI }, children });
186
244
  };
187
245
 
188
246
  // src/components/Inbox.tsx
189
- var import_jsx_runtime5 = require("react/jsx-runtime");
190
- var DefaultInbox = (props) => {
247
+ var import_jsx_runtime8 = require("react/jsx-runtime");
248
+ var _DefaultInbox = (props) => {
191
249
  const { open, renderNotification, renderBell, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick } = props;
192
- const { novuUI, mountElement } = useRendererContext();
193
- const mount = import_react6.default.useCallback(
250
+ const { novuUI } = useNovuUIContext();
251
+ const { mountElement } = useRendererContext();
252
+ const mount = import_react8.default.useCallback(
194
253
  (element) => {
195
254
  return novuUI.mountComponent({
196
255
  name: "Inbox",
@@ -207,15 +266,16 @@ var DefaultInbox = (props) => {
207
266
  },
208
267
  [open, renderNotification, renderBell, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick]
209
268
  );
210
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Mounter, { mount });
269
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Mounter, { mount });
211
270
  };
212
- var Inbox = import_react6.default.memo((props) => {
271
+ var DefaultInbox = withRenderer(_DefaultInbox);
272
+ var Inbox = import_react8.default.memo((props) => {
213
273
  const { applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl } = props;
214
274
  const novu = useUnsafeNovu();
215
275
  if (novu) {
216
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(InboxChild, { ...props });
276
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(InboxChild, { ...props });
217
277
  }
218
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
278
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
219
279
  NovuProvider,
220
280
  {
221
281
  applicationIdentifier,
@@ -223,15 +283,16 @@ var Inbox = import_react6.default.memo((props) => {
223
283
  subscriberHash,
224
284
  backendUrl,
225
285
  socketUrl,
226
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(InboxChild, { ...props })
286
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(InboxChild, { ...props })
227
287
  }
228
288
  );
229
289
  });
230
- var InboxChild = import_react6.default.memo((props) => {
290
+ var InboxChild = import_react8.default.memo((props) => {
231
291
  const {
232
292
  localization,
233
293
  appearance,
234
294
  tabs,
295
+ preferencesFilter,
235
296
  routerPush,
236
297
  applicationIdentifier,
237
298
  subscriberId,
@@ -240,20 +301,31 @@ var InboxChild = import_react6.default.memo((props) => {
240
301
  socketUrl
241
302
  } = props;
242
303
  const novu = useNovu();
243
- const options = (0, import_react6.useMemo)(() => {
304
+ const options = (0, import_react8.useMemo)(() => {
244
305
  return {
245
306
  localization,
246
307
  appearance,
247
308
  tabs,
309
+ preferencesFilter,
248
310
  routerPush,
249
311
  options: { applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl }
250
312
  };
251
- }, [localization, appearance, tabs, applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl]);
313
+ }, [
314
+ localization,
315
+ appearance,
316
+ tabs,
317
+ preferencesFilter,
318
+ applicationIdentifier,
319
+ subscriberId,
320
+ subscriberHash,
321
+ backendUrl,
322
+ socketUrl
323
+ ]);
252
324
  if (isWithChildrenProps(props)) {
253
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Renderer, { options, novu, children: props.children });
325
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(NovuUI, { options, novu, children: props.children });
254
326
  }
255
327
  const { open, renderNotification, renderBell, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick } = props;
256
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Renderer, { options, novu, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
328
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(NovuUI, { options, novu, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
257
329
  DefaultInbox,
258
330
  {
259
331
  open,
@@ -270,26 +342,27 @@ function isWithChildrenProps(props) {
270
342
  }
271
343
 
272
344
  // src/components/Preferences.tsx
273
- var import_react7 = __toESM(require("react"));
274
- var import_jsx_runtime6 = require("react/jsx-runtime");
345
+ var import_react9 = __toESM(require("react"));
346
+ var import_jsx_runtime9 = require("react/jsx-runtime");
275
347
  var Preferences = () => {
276
- const { novuUI } = useRendererContext();
277
- const mount = import_react7.default.useCallback((element) => {
348
+ const { novuUI } = useNovuUIContext();
349
+ const mount = import_react9.default.useCallback((element) => {
278
350
  return novuUI.mountComponent({
279
351
  name: "Preferences",
280
352
  element
281
353
  });
282
354
  }, []);
283
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Mounter, { mount });
355
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Mounter, { mount });
284
356
  };
285
357
 
286
358
  // src/components/Notifications.tsx
287
- var import_react8 = __toESM(require("react"));
288
- var import_jsx_runtime7 = require("react/jsx-runtime");
289
- var Notifications = import_react8.default.memo((props) => {
359
+ var import_react10 = __toESM(require("react"));
360
+ var import_jsx_runtime10 = require("react/jsx-runtime");
361
+ var _Notifications = import_react10.default.memo((props) => {
290
362
  const { onNotificationClick, onPrimaryActionClick, renderNotification, onSecondaryActionClick } = props;
291
- const { novuUI, mountElement } = useRendererContext();
292
- const mount = import_react8.default.useCallback(
363
+ const { novuUI } = useNovuUIContext();
364
+ const { mountElement } = useRendererContext();
365
+ const mount = import_react10.default.useCallback(
293
366
  (element) => {
294
367
  return novuUI.mountComponent({
295
368
  name: "Notifications",
@@ -304,53 +377,57 @@ var Notifications = import_react8.default.memo((props) => {
304
377
  },
305
378
  [renderNotification, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick]
306
379
  );
307
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Mounter, { mount });
380
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Mounter, { mount });
308
381
  });
382
+ var Notifications = withRenderer(_Notifications);
309
383
 
310
- // src/hooks/NovuProvider.tsx
311
- var import_js = require("@novu/js");
312
- var import_react9 = require("react");
313
- var import_jsx_runtime8 = require("react/jsx-runtime");
314
- var NovuContext = (0, import_react9.createContext)(void 0);
315
- var NovuProvider = ({
316
- children,
317
- applicationIdentifier,
318
- subscriberId,
319
- subscriberHash,
320
- backendUrl,
321
- socketUrl,
322
- useCache
323
- }) => {
324
- const novu = (0, import_react9.useMemo)(
325
- () => new import_js.Novu({ applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl, useCache }),
326
- [applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl, useCache]
384
+ // src/components/InboxContent.tsx
385
+ var import_react11 = __toESM(require("react"));
386
+ var import_jsx_runtime11 = require("react/jsx-runtime");
387
+ var _InboxContent = import_react11.default.memo((props) => {
388
+ const {
389
+ onNotificationClick,
390
+ onPrimaryActionClick,
391
+ renderNotification,
392
+ onSecondaryActionClick,
393
+ initialPage,
394
+ hideNav
395
+ } = props;
396
+ const { novuUI } = useNovuUIContext();
397
+ const { mountElement } = useRendererContext();
398
+ const mount = import_react11.default.useCallback(
399
+ (element) => {
400
+ return novuUI.mountComponent({
401
+ name: "InboxContent",
402
+ element,
403
+ props: {
404
+ renderNotification: renderNotification ? (el, notification) => mountElement(el, renderNotification(notification)) : void 0,
405
+ onNotificationClick,
406
+ onPrimaryActionClick,
407
+ onSecondaryActionClick,
408
+ initialPage,
409
+ hideNav
410
+ }
411
+ });
412
+ },
413
+ [renderNotification, onNotificationClick, onPrimaryActionClick, onSecondaryActionClick]
327
414
  );
328
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(NovuContext.Provider, { value: novu, children });
329
- };
330
- var useNovu = () => {
331
- const context = (0, import_react9.useContext)(NovuContext);
332
- if (!context) {
333
- throw new Error("useNovu must be used within a <NovuProvider />");
334
- }
335
- return context;
336
- };
337
- var useUnsafeNovu = () => {
338
- const context = (0, import_react9.useContext)(NovuContext);
339
- return context;
340
- };
415
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Mounter, { mount });
416
+ });
417
+ var InboxContent = withRenderer(_InboxContent);
341
418
 
342
419
  // src/hooks/useNotifications.ts
343
- var import_react10 = require("react");
420
+ var import_react12 = require("react");
344
421
  var import_js2 = require("@novu/js");
345
422
  var useNotifications = (props) => {
346
423
  const { tags, read, archived = false, limit, onSuccess, onError } = props || {};
347
- const filterRef = (0, import_react10.useRef)(void 0);
424
+ const filterRef = (0, import_react12.useRef)(void 0);
348
425
  const { notifications, on, off } = useNovu();
349
- const [data, setData] = (0, import_react10.useState)();
350
- const [error, setError] = (0, import_react10.useState)();
351
- const [isLoading, setIsLoading] = (0, import_react10.useState)(true);
352
- const [isFetching, setIsFetching] = (0, import_react10.useState)(false);
353
- const [hasMore, setHasMore] = (0, import_react10.useState)(false);
426
+ const [data, setData] = (0, import_react12.useState)();
427
+ const [error, setError] = (0, import_react12.useState)();
428
+ const [isLoading, setIsLoading] = (0, import_react12.useState)(true);
429
+ const [isFetching, setIsFetching] = (0, import_react12.useState)(false);
430
+ const [hasMore, setHasMore] = (0, import_react12.useState)(false);
354
431
  const length = data?.length;
355
432
  const after = length ? data[length - 1].id : void 0;
356
433
  const sync = (event) => {
@@ -360,13 +437,13 @@ var useNotifications = (props) => {
360
437
  setData(event.data.notifications);
361
438
  setHasMore(event.data.hasMore);
362
439
  };
363
- (0, import_react10.useEffect)(() => {
440
+ (0, import_react12.useEffect)(() => {
364
441
  on("notifications.list.updated", sync);
365
442
  return () => {
366
443
  off("notifications.list.updated", sync);
367
444
  };
368
445
  }, []);
369
- (0, import_react10.useEffect)(() => {
446
+ (0, import_react12.useEffect)(() => {
370
447
  const newFilter = { tags, read, archived };
371
448
  if (filterRef.current && (0, import_js2.isSameFilter)(filterRef.current, newFilter)) {
372
449
  return;
@@ -432,21 +509,21 @@ var useNotifications = (props) => {
432
509
  };
433
510
 
434
511
  // src/hooks/usePreferences.ts
435
- var import_react11 = require("react");
512
+ var import_react13 = require("react");
436
513
  var usePreferences = (props) => {
437
514
  const { onSuccess, onError } = props || {};
438
- const [data, setData] = (0, import_react11.useState)();
515
+ const [data, setData] = (0, import_react13.useState)();
439
516
  const { preferences, on, off } = useNovu();
440
- const [error, setError] = (0, import_react11.useState)();
441
- const [isLoading, setIsLoading] = (0, import_react11.useState)(true);
442
- const [isFetching, setIsFetching] = (0, import_react11.useState)(false);
517
+ const [error, setError] = (0, import_react13.useState)();
518
+ const [isLoading, setIsLoading] = (0, import_react13.useState)(true);
519
+ const [isFetching, setIsFetching] = (0, import_react13.useState)(false);
443
520
  const sync = (event) => {
444
521
  if (!event.data) {
445
522
  return;
446
523
  }
447
524
  setData(event.data);
448
525
  };
449
- (0, import_react11.useEffect)(() => {
526
+ (0, import_react13.useEffect)(() => {
450
527
  fetchPreferences();
451
528
  on("preferences.list.updated", sync);
452
529
  on("preferences.list.pending", sync);
@@ -459,7 +536,7 @@ var usePreferences = (props) => {
459
536
  }, []);
460
537
  const fetchPreferences = async () => {
461
538
  setIsFetching(true);
462
- const response = await preferences.list();
539
+ const response = await preferences.list(props?.filter);
463
540
  if (response.error) {
464
541
  setError(response.error);
465
542
  onError?.(response.error);
@@ -483,11 +560,11 @@ var usePreferences = (props) => {
483
560
  };
484
561
 
485
562
  // src/hooks/useCounts.ts
486
- var import_react14 = require("react");
563
+ var import_react16 = require("react");
487
564
  var import_js3 = require("@novu/js");
488
565
 
489
566
  // src/hooks/internal/useWebsocketEvent.ts
490
- var import_react13 = require("react");
567
+ var import_react15 = require("react");
491
568
 
492
569
  // src/utils/requestLock.ts
493
570
  function requestLock(id, cb) {
@@ -514,18 +591,18 @@ function requestLock(id, cb) {
514
591
  }
515
592
 
516
593
  // src/hooks/internal/useBrowserTabsChannel.ts
517
- var import_react12 = require("react");
594
+ var import_react14 = require("react");
518
595
  var useBrowserTabsChannel = ({
519
596
  channelName,
520
597
  onMessage
521
598
  }) => {
522
- const [tabsChannel] = (0, import_react12.useState)(
599
+ const [tabsChannel] = (0, import_react14.useState)(
523
600
  typeof BroadcastChannel !== "undefined" ? new BroadcastChannel(channelName) : void 0
524
601
  );
525
602
  const postMessage = (data) => {
526
603
  tabsChannel?.postMessage(data);
527
604
  };
528
- (0, import_react12.useEffect)(() => {
605
+ (0, import_react14.useEffect)(() => {
529
606
  const listener = (event) => {
530
607
  onMessage(event.data);
531
608
  };
@@ -548,7 +625,7 @@ var useWebSocketEvent = ({
548
625
  onMessage(data);
549
626
  postMessage(data);
550
627
  };
551
- (0, import_react13.useEffect)(() => {
628
+ (0, import_react15.useEffect)(() => {
552
629
  const resolveLock = requestLock(`nv.${webSocketEvent}`, () => {
553
630
  novu.on(webSocketEvent, updateReadCount);
554
631
  });
@@ -563,10 +640,10 @@ var useWebSocketEvent = ({
563
640
  var useCounts = (props) => {
564
641
  const { filters, onSuccess, onError } = props;
565
642
  const { notifications } = useNovu();
566
- const [error, setError] = (0, import_react14.useState)();
567
- const [counts, setCounts] = (0, import_react14.useState)();
568
- const [isLoading, setIsLoading] = (0, import_react14.useState)(true);
569
- const [isFetching, setIsFetching] = (0, import_react14.useState)(false);
643
+ const [error, setError] = (0, import_react16.useState)();
644
+ const [counts, setCounts] = (0, import_react16.useState)();
645
+ const [isLoading, setIsLoading] = (0, import_react16.useState)(true);
646
+ const [isFetching, setIsFetching] = (0, import_react16.useState)(false);
570
647
  const sync = async (notification) => {
571
648
  const existingCounts = counts ?? new Array(filters.length).fill(void 0);
572
649
  let countFiltersToFetch = [];
@@ -616,7 +693,7 @@ var useCounts = (props) => {
616
693
  sync();
617
694
  }
618
695
  });
619
- (0, import_react14.useEffect)(() => {
696
+ (0, import_react16.useEffect)(() => {
620
697
  setError(void 0);
621
698
  setIsLoading(true);
622
699
  setIsFetching(false);