@novu/react 2.0.0 → 2.1.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.
@@ -23,9 +23,336 @@ __export(server_exports, {
23
23
  Bell: () => Bell,
24
24
  Inbox: () => Inbox,
25
25
  Notifications: () => Notifications,
26
- Preferences: () => Preferences
26
+ NovuProvider: () => NovuProvider,
27
+ Preferences: () => Preferences,
28
+ useCounts: () => useCounts,
29
+ useNotifications: () => useNotifications,
30
+ useNovu: () => useNovu,
31
+ usePreferences: () => usePreferences
27
32
  });
28
33
  module.exports = __toCommonJS(server_exports);
34
+
35
+ // src/hooks/NovuProvider.tsx
36
+ var import_js = require("@novu/js");
37
+ var import_react = require("react");
38
+ var import_jsx_runtime = require("react/jsx-runtime");
39
+ var NovuContext = (0, import_react.createContext)(void 0);
40
+ var NovuProvider = ({
41
+ children,
42
+ applicationIdentifier,
43
+ subscriberId,
44
+ subscriberHash,
45
+ backendUrl,
46
+ socketUrl,
47
+ useCache
48
+ }) => {
49
+ const novu = (0, import_react.useMemo)(
50
+ () => new import_js.Novu({ applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl, useCache }),
51
+ [applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl, useCache]
52
+ );
53
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NovuContext.Provider, { value: novu, children });
54
+ };
55
+ var useNovu = () => {
56
+ const context = (0, import_react.useContext)(NovuContext);
57
+ if (!context) {
58
+ throw new Error("useNovu must be used within a <NovuProvider />");
59
+ }
60
+ return context;
61
+ };
62
+
63
+ // src/hooks/useNotifications.ts
64
+ var import_react2 = require("react");
65
+ var import_js2 = require("@novu/js");
66
+ var useNotifications = (props) => {
67
+ const { tags, read, archived = false, limit, onSuccess, onError } = props || {};
68
+ const filterRef = (0, import_react2.useRef)(void 0);
69
+ const { notifications, on, off } = useNovu();
70
+ const [data, setData] = (0, import_react2.useState)();
71
+ const [error, setError] = (0, import_react2.useState)();
72
+ const [isLoading, setIsLoading] = (0, import_react2.useState)(true);
73
+ const [isFetching, setIsFetching] = (0, import_react2.useState)(false);
74
+ const [hasMore, setHasMore] = (0, import_react2.useState)(false);
75
+ const length = data == null ? void 0 : data.length;
76
+ const after = length ? data[length - 1].id : void 0;
77
+ const sync = (event) => {
78
+ if (!event.data || filterRef.current && !(0, import_js2.isSameFilter)(filterRef.current, event.data.filter)) {
79
+ return;
80
+ }
81
+ setData(event.data.notifications);
82
+ setHasMore(event.data.hasMore);
83
+ };
84
+ (0, import_react2.useEffect)(() => {
85
+ on("notifications.list.updated", sync);
86
+ return () => {
87
+ off("notifications.list.updated", sync);
88
+ };
89
+ }, []);
90
+ (0, import_react2.useEffect)(() => {
91
+ const newFilter = { tags, read, archived };
92
+ if (filterRef.current && (0, import_js2.isSameFilter)(filterRef.current, newFilter)) {
93
+ return;
94
+ }
95
+ notifications.clearCache({ filter: filterRef.current });
96
+ filterRef.current = newFilter;
97
+ fetchNotifications({ refetch: true });
98
+ }, [tags, read, archived]);
99
+ const fetchNotifications = async (options) => {
100
+ if (options == null ? void 0 : options.refetch) {
101
+ setError(void 0);
102
+ setIsLoading(true);
103
+ setIsFetching(false);
104
+ }
105
+ setIsFetching(true);
106
+ const response = await notifications.list({
107
+ tags,
108
+ read,
109
+ archived,
110
+ limit,
111
+ after: (options == null ? void 0 : options.refetch) ? void 0 : after
112
+ });
113
+ if (response.error) {
114
+ setError(response.error);
115
+ onError == null ? void 0 : onError(response.error);
116
+ } else {
117
+ onSuccess == null ? void 0 : onSuccess(response.data.notifications);
118
+ setData(response.data.notifications);
119
+ setHasMore(response.data.hasMore);
120
+ }
121
+ setIsLoading(false);
122
+ setIsFetching(false);
123
+ };
124
+ const refetch = () => {
125
+ notifications.clearCache({ filter: { tags, read, archived } });
126
+ return fetchNotifications({ refetch: true });
127
+ };
128
+ const fetchMore = async () => {
129
+ if (!hasMore || isFetching) return;
130
+ return fetchNotifications();
131
+ };
132
+ const readAll = async () => {
133
+ return await notifications.readAll({ tags });
134
+ };
135
+ const archiveAll = async () => {
136
+ return await notifications.archiveAll({ tags });
137
+ };
138
+ const archiveAllRead = async () => {
139
+ return await notifications.archiveAllRead({ tags });
140
+ };
141
+ return {
142
+ readAll,
143
+ archiveAll,
144
+ archiveAllRead,
145
+ notifications: data,
146
+ error,
147
+ isLoading,
148
+ isFetching,
149
+ refetch,
150
+ fetchMore,
151
+ hasMore
152
+ };
153
+ };
154
+
155
+ // src/hooks/usePreferences.ts
156
+ var import_react3 = require("react");
157
+ var usePreferences = (props) => {
158
+ const { onSuccess, onError } = props || {};
159
+ const [data, setData] = (0, import_react3.useState)();
160
+ const { preferences, on, off } = useNovu();
161
+ const [error, setError] = (0, import_react3.useState)();
162
+ const [isLoading, setIsLoading] = (0, import_react3.useState)(true);
163
+ const [isFetching, setIsFetching] = (0, import_react3.useState)(false);
164
+ const sync = (event) => {
165
+ if (!event.data) {
166
+ return;
167
+ }
168
+ setData(event.data);
169
+ };
170
+ (0, import_react3.useEffect)(() => {
171
+ fetchPreferences();
172
+ on("preferences.list.updated", sync);
173
+ on("preferences.list.pending", sync);
174
+ on("preferences.list.resolved", sync);
175
+ return () => {
176
+ off("preferences.list.updated", sync);
177
+ off("preferences.list.pending", sync);
178
+ off("preferences.list.resolved", sync);
179
+ };
180
+ }, []);
181
+ const fetchPreferences = async () => {
182
+ setIsFetching(true);
183
+ const response = await preferences.list();
184
+ if (response.error) {
185
+ setError(response.error);
186
+ onError == null ? void 0 : onError(response.error);
187
+ } else {
188
+ onSuccess == null ? void 0 : onSuccess(response.data);
189
+ }
190
+ setIsLoading(false);
191
+ setIsFetching(false);
192
+ };
193
+ const refetch = () => {
194
+ preferences.cache.clearAll();
195
+ return fetchPreferences();
196
+ };
197
+ return {
198
+ preferences: data,
199
+ error,
200
+ isLoading,
201
+ isFetching,
202
+ refetch
203
+ };
204
+ };
205
+
206
+ // src/hooks/useCounts.ts
207
+ var import_react6 = require("react");
208
+ var import_js3 = require("@novu/js");
209
+
210
+ // src/hooks/internal/useWebsocketEvent.ts
211
+ var import_react5 = require("react");
212
+
213
+ // src/utils/requestLock.ts
214
+ function requestLock(id, cb) {
215
+ if (!("locks" in navigator)) {
216
+ cb(id);
217
+ return () => {
218
+ };
219
+ }
220
+ let isFulfilled = false;
221
+ let promiseResolve;
222
+ const promise = new Promise((resolve) => {
223
+ promiseResolve = resolve;
224
+ });
225
+ navigator.locks.request(id, () => {
226
+ if (!isFulfilled) {
227
+ cb(id);
228
+ }
229
+ return promise;
230
+ });
231
+ return () => {
232
+ isFulfilled = true;
233
+ promiseResolve();
234
+ };
235
+ }
236
+
237
+ // src/hooks/internal/useBrowserTabsChannel.ts
238
+ var import_react4 = require("react");
239
+ var useBrowserTabsChannel = ({
240
+ channelName,
241
+ onMessage
242
+ }) => {
243
+ const [tabsChannel] = (0, import_react4.useState)(
244
+ typeof BroadcastChannel !== "undefined" ? new BroadcastChannel(channelName) : void 0
245
+ );
246
+ const postMessage = (data) => {
247
+ tabsChannel == null ? void 0 : tabsChannel.postMessage(data);
248
+ };
249
+ (0, import_react4.useEffect)(() => {
250
+ const listener = (event) => {
251
+ onMessage(event.data);
252
+ };
253
+ tabsChannel == null ? void 0 : tabsChannel.addEventListener("message", listener);
254
+ return () => {
255
+ tabsChannel == null ? void 0 : tabsChannel.removeEventListener("message", listener);
256
+ };
257
+ }, []);
258
+ return { postMessage };
259
+ };
260
+
261
+ // src/hooks/internal/useWebsocketEvent.ts
262
+ var useWebSocketEvent = ({
263
+ event: webSocketEvent,
264
+ eventHandler: onMessage
265
+ }) => {
266
+ const novu = useNovu();
267
+ const { postMessage } = useBrowserTabsChannel({ channelName: `nv.${webSocketEvent}`, onMessage });
268
+ const updateReadCount = (data) => {
269
+ onMessage(data);
270
+ postMessage(data);
271
+ };
272
+ (0, import_react5.useEffect)(() => {
273
+ const resolveLock = requestLock(`nv.${webSocketEvent}`, () => {
274
+ novu.on(webSocketEvent, updateReadCount);
275
+ });
276
+ return () => {
277
+ novu.off(webSocketEvent, updateReadCount);
278
+ resolveLock();
279
+ };
280
+ }, []);
281
+ };
282
+
283
+ // src/hooks/useCounts.ts
284
+ var useCounts = (props) => {
285
+ const { filters, onSuccess, onError } = props;
286
+ const { notifications } = useNovu();
287
+ const [error, setError] = (0, import_react6.useState)();
288
+ const [counts, setCounts] = (0, import_react6.useState)();
289
+ const [isLoading, setIsLoading] = (0, import_react6.useState)(true);
290
+ const [isFetching, setIsFetching] = (0, import_react6.useState)(false);
291
+ const sync = async (notification) => {
292
+ const existingCounts = counts ?? new Array(filters.length).fill(void 0);
293
+ let countFiltersToFetch = [];
294
+ if (notification) {
295
+ for (let i = 0; i < existingCounts.length; i++) {
296
+ const filter = filters[i];
297
+ if ((0, import_js3.areTagsEqual)(filter.tags, notification.tags)) {
298
+ countFiltersToFetch.push(filter);
299
+ }
300
+ }
301
+ } else {
302
+ countFiltersToFetch = filters;
303
+ }
304
+ if (countFiltersToFetch.length === 0) {
305
+ return;
306
+ }
307
+ setIsFetching(true);
308
+ const countsRes = await notifications.count({ filters: countFiltersToFetch });
309
+ setIsFetching(false);
310
+ setIsLoading(false);
311
+ if (countsRes.error) {
312
+ setError(countsRes.error);
313
+ onError == null ? void 0 : onError(countsRes.error);
314
+ return;
315
+ }
316
+ const data = countsRes.data;
317
+ onSuccess == null ? void 0 : onSuccess(data.counts);
318
+ setCounts((oldCounts) => {
319
+ const newCounts = [];
320
+ const countsReceived = data.counts;
321
+ for (let i = 0; i < existingCounts.length; i++) {
322
+ const countReceived = countsReceived.find((c) => {
323
+ var _a;
324
+ return (0, import_js3.areTagsEqual)(c.filter.tags, (_a = existingCounts[i]) == null ? void 0 : _a.filter.tags);
325
+ });
326
+ newCounts.push(countReceived || oldCounts[i]);
327
+ }
328
+ return newCounts;
329
+ });
330
+ };
331
+ useWebSocketEvent({
332
+ event: "notifications.notification_received",
333
+ eventHandler: (data) => {
334
+ sync(data.result);
335
+ }
336
+ });
337
+ useWebSocketEvent({
338
+ event: "notifications.unread_count_changed",
339
+ eventHandler: () => {
340
+ sync();
341
+ }
342
+ });
343
+ (0, import_react6.useEffect)(() => {
344
+ setError(void 0);
345
+ setIsLoading(true);
346
+ setIsFetching(false);
347
+ sync();
348
+ }, [JSON.stringify(filters)]);
349
+ const refetch = async () => {
350
+ await sync();
351
+ };
352
+ return { counts, error, refetch, isLoading, isFetching };
353
+ };
354
+
355
+ // src/server.ts
29
356
  function Inbox() {
30
357
  }
31
358
  function Notifications() {
@@ -39,6 +366,11 @@ function Bell() {
39
366
  Bell,
40
367
  Inbox,
41
368
  Notifications,
42
- Preferences
369
+ NovuProvider,
370
+ Preferences,
371
+ useCounts,
372
+ useNotifications,
373
+ useNovu,
374
+ usePreferences
43
375
  });
44
376
  //# sourceMappingURL=server.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/server.ts"],"sourcesContent":["export * from './utils/types';\n/**\n * Exporting all components from the components folder\n * as empty functions to fix build errors in SSR\n * This will be replaced with actual components\n * when we implement the SSR components in @novu/js/ui\n */\nexport function Inbox() {}\nexport function Notifications() {}\nexport function Preferences() {}\nexport function Bell() {}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,SAAS,QAAQ;AAAC;AAClB,SAAS,gBAAgB;AAAC;AAC1B,SAAS,cAAc;AAAC;AACxB,SAAS,OAAO;AAAC;","names":[]}
1
+ {"version":3,"sources":["../../src/server.ts","../../src/hooks/NovuProvider.tsx","../../src/hooks/useNotifications.ts","../../src/hooks/usePreferences.ts","../../src/hooks/useCounts.ts","../../src/hooks/internal/useWebsocketEvent.ts","../../src/utils/requestLock.ts","../../src/hooks/internal/useBrowserTabsChannel.ts"],"sourcesContent":["export * from './utils/types';\n/**\n * Exporting all components from the components folder\n * as empty functions to fix build errors in SSR\n * This will be replaced with actual components\n * when we implement the SSR components in @novu/js/ui\n */\nexport function Inbox() {}\nexport function Notifications() {}\nexport function Preferences() {}\nexport function Bell() {}\n\n//Hooks\nexport { NovuProvider } from './index';\nexport * from './hooks';\n","import { Novu, NovuOptions } from '@novu/js';\nimport { ReactNode, createContext, useContext, useMemo } from 'react';\n\ntype NovuProviderProps = NovuOptions & {\n children: ReactNode;\n};\n\nconst NovuContext = createContext<Novu | undefined>(undefined);\n\nexport const NovuProvider = ({\n children,\n applicationIdentifier,\n subscriberId,\n subscriberHash,\n backendUrl,\n socketUrl,\n useCache,\n}: NovuProviderProps) => {\n const novu = useMemo(\n () => new Novu({ applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl, useCache }),\n [applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl, useCache]\n );\n\n return <NovuContext.Provider value={novu}>{children}</NovuContext.Provider>;\n};\n\nexport const useNovu = () => {\n const context = useContext(NovuContext);\n if (!context) {\n throw new Error('useNovu must be used within a <NovuProvider />');\n }\n\n return context;\n};\n\nexport const useUnsafeNovu = () => {\n const context = useContext(NovuContext);\n\n return context;\n};\n","import { useState, useEffect, useRef } from 'react';\nimport { ListNotificationsResponse, Notification, NovuError, isSameFilter, NotificationFilter } from '@novu/js';\nimport { useNovu } from './NovuProvider';\n\nexport type UseNotificationsProps = {\n tags?: string[];\n read?: boolean;\n archived?: boolean;\n limit?: number;\n onSuccess?: (data: Notification[]) => void;\n onError?: (error: NovuError) => void;\n};\n\nexport const useNotifications = (props?: UseNotificationsProps) => {\n const { tags, read, archived = false, limit, onSuccess, onError } = props || {};\n const filterRef = useRef<NotificationFilter | undefined>(undefined);\n const { notifications, on, off } = useNovu();\n const [data, setData] = useState<Array<Notification>>();\n const [error, setError] = useState<NovuError>();\n const [isLoading, setIsLoading] = useState(true);\n const [isFetching, setIsFetching] = useState(false);\n const [hasMore, setHasMore] = useState(false);\n const length = data?.length;\n const after = length ? data[length - 1].id : undefined;\n\n const sync = (event: { data?: ListNotificationsResponse }) => {\n if (!event.data || (filterRef.current && !isSameFilter(filterRef.current, event.data.filter))) {\n return;\n }\n setData(event.data.notifications);\n setHasMore(event.data.hasMore);\n };\n\n useEffect(() => {\n on('notifications.list.updated', sync);\n\n return () => {\n off('notifications.list.updated', sync);\n };\n }, []);\n\n useEffect(() => {\n const newFilter = { tags, read, archived };\n if (filterRef.current && isSameFilter(filterRef.current, newFilter)) {\n return;\n }\n\n notifications.clearCache({ filter: filterRef.current });\n filterRef.current = newFilter;\n\n fetchNotifications({ refetch: true });\n }, [tags, read, archived]);\n\n const fetchNotifications = async (options?: { refetch: boolean }) => {\n if (options?.refetch) {\n setError(undefined);\n setIsLoading(true);\n setIsFetching(false);\n }\n setIsFetching(true);\n const response = await notifications.list({\n tags,\n read,\n archived,\n limit,\n after: options?.refetch ? undefined : after,\n });\n if (response.error) {\n setError(response.error);\n onError?.(response.error);\n } else {\n onSuccess?.(response.data!.notifications);\n setData(response.data!.notifications);\n setHasMore(response.data!.hasMore);\n }\n setIsLoading(false);\n setIsFetching(false);\n };\n\n const refetch = () => {\n notifications.clearCache({ filter: { tags, read, archived } });\n\n return fetchNotifications({ refetch: true });\n };\n\n const fetchMore = async () => {\n if (!hasMore || isFetching) return;\n\n return fetchNotifications();\n };\n\n const readAll = async () => {\n return await notifications.readAll({ tags });\n };\n\n const archiveAll = async () => {\n return await notifications.archiveAll({ tags });\n };\n\n const archiveAllRead = async () => {\n return await notifications.archiveAllRead({ tags });\n };\n\n return {\n readAll,\n archiveAll,\n archiveAllRead,\n notifications: data,\n error,\n isLoading,\n isFetching,\n refetch,\n fetchMore,\n hasMore,\n };\n};\n","import { NovuError, Preference } from '@novu/js';\nimport { useEffect, useState } from 'react';\nimport { useNovu } from './NovuProvider';\n\ntype UsePreferencesProps = {\n onSuccess?: (data: Preference[]) => void;\n onError?: (error: NovuError) => void;\n};\n\ntype UsePreferencesResult = {\n preferences?: Preference[];\n error?: NovuError;\n isLoading: boolean; // initial loading\n isFetching: boolean; // the request is in flight\n refetch: () => Promise<void>;\n};\n\nexport const usePreferences = (props?: UsePreferencesProps): UsePreferencesResult => {\n const { onSuccess, onError } = props || {};\n const [data, setData] = useState<Preference[]>();\n const { preferences, on, off } = useNovu();\n const [error, setError] = useState<NovuError>();\n const [isLoading, setIsLoading] = useState(true);\n const [isFetching, setIsFetching] = useState(false);\n\n const sync = (event: { data?: Preference[] }) => {\n if (!event.data) {\n return;\n }\n setData(event.data);\n };\n\n useEffect(() => {\n fetchPreferences();\n\n on('preferences.list.updated', sync);\n on('preferences.list.pending', sync);\n on('preferences.list.resolved', sync);\n\n return () => {\n off('preferences.list.updated', sync);\n off('preferences.list.pending', sync);\n off('preferences.list.resolved', sync);\n };\n }, []);\n\n const fetchPreferences = async () => {\n setIsFetching(true);\n const response = await preferences.list();\n if (response.error) {\n setError(response.error);\n onError?.(response.error);\n } else {\n onSuccess?.(response.data!);\n }\n setIsLoading(false);\n setIsFetching(false);\n };\n\n const refetch = () => {\n preferences.cache.clearAll();\n return fetchPreferences();\n };\n\n return {\n preferences: data,\n error,\n isLoading,\n isFetching,\n refetch,\n };\n};\n","import { useEffect, useState } from 'react';\nimport { Notification, NotificationFilter, NovuError, areTagsEqual } from '@novu/js';\nimport { useNovu } from './NovuProvider';\nimport { useWebSocketEvent } from './internal/useWebsocketEvent';\n\ntype Count = {\n count: number;\n filter: NotificationFilter;\n};\n\ntype UseCountsProps = {\n filters: NotificationFilter[];\n onSuccess?: (data: Count[]) => void;\n onError?: (error: NovuError) => void;\n};\n\ntype UseCountsResult = {\n counts?: Count[];\n error?: NovuError;\n isLoading: boolean; // initial loading\n isFetching: boolean; // the request is in flight\n refetch: () => Promise<void>;\n};\n\nexport const useCounts = (props: UseCountsProps): UseCountsResult => {\n const { filters, onSuccess, onError } = props;\n const { notifications } = useNovu();\n const [error, setError] = useState<NovuError>();\n const [counts, setCounts] = useState<Count[]>();\n const [isLoading, setIsLoading] = useState(true);\n const [isFetching, setIsFetching] = useState(false);\n\n const sync = async (notification?: Notification) => {\n const existingCounts = counts ?? (new Array(filters.length).fill(undefined) as (Count | undefined)[]);\n let countFiltersToFetch: NotificationFilter[] = [];\n if (notification) {\n // eslint-disable-next-line no-plusplus\n for (let i = 0; i < existingCounts.length; i++) {\n const filter = filters[i];\n if (areTagsEqual(filter.tags, notification.tags)) {\n countFiltersToFetch.push(filter);\n }\n }\n } else {\n countFiltersToFetch = filters;\n }\n\n if (countFiltersToFetch.length === 0) {\n return;\n }\n\n setIsFetching(true);\n const countsRes = await notifications.count({ filters: countFiltersToFetch });\n setIsFetching(false);\n setIsLoading(false);\n if (countsRes.error) {\n setError(countsRes.error);\n onError?.(countsRes.error);\n\n return;\n }\n const data = countsRes.data!;\n onSuccess?.(data.counts);\n\n setCounts((oldCounts) => {\n const newCounts: Count[] = [];\n const countsReceived = data.counts;\n\n // eslint-disable-next-line no-plusplus\n for (let i = 0; i < existingCounts.length; i++) {\n const countReceived = countsReceived.find((c) => areTagsEqual(c.filter.tags, existingCounts[i]?.filter.tags));\n\n newCounts.push(countReceived || oldCounts![i]);\n }\n\n return newCounts;\n });\n };\n\n useWebSocketEvent({\n event: 'notifications.notification_received',\n eventHandler: (data) => {\n sync(data.result);\n },\n });\n\n useWebSocketEvent({\n event: 'notifications.unread_count_changed',\n eventHandler: () => {\n sync();\n },\n });\n\n useEffect(() => {\n setError(undefined);\n setIsLoading(true);\n setIsFetching(false);\n sync();\n }, [JSON.stringify(filters)]);\n\n const refetch = async () => {\n await sync();\n };\n\n return { counts, error, refetch, isLoading, isFetching };\n};\n","import { EventHandler, Events, SocketEventNames } from '@novu/js';\nimport { useEffect } from 'react';\nimport { useNovu } from '../NovuProvider';\nimport { requestLock } from '../../utils/requestLock';\nimport { useBrowserTabsChannel } from './useBrowserTabsChannel';\n\nexport const useWebSocketEvent = <E extends SocketEventNames>({\n event: webSocketEvent,\n eventHandler: onMessage,\n}: {\n event: E;\n eventHandler: (args: Events[E]) => void;\n}) => {\n const novu = useNovu();\n const { postMessage } = useBrowserTabsChannel({ channelName: `nv.${webSocketEvent}`, onMessage });\n\n const updateReadCount: EventHandler<Events[E]> = (data) => {\n onMessage(data);\n postMessage(data);\n };\n\n useEffect(() => {\n const resolveLock = requestLock(`nv.${webSocketEvent}`, () => {\n novu.on(webSocketEvent, updateReadCount);\n });\n\n return () => {\n novu.off(webSocketEvent, updateReadCount);\n resolveLock();\n };\n }, []);\n};\n","export function requestLock(id: string, cb: (id: string) => void) {\n // Check if the Lock API is available\n if (!('locks' in navigator)) {\n // If Lock API is not available, immediately invoke the callback and return a no-op function\n cb(id);\n return () => {};\n }\n\n let isFulfilled = false;\n let promiseResolve: () => void;\n\n const promise = new Promise<void>((resolve) => {\n promiseResolve = resolve;\n });\n\n navigator.locks.request(id, () => {\n if (!isFulfilled) {\n cb(id);\n }\n\n return promise;\n });\n\n return () => {\n isFulfilled = true;\n promiseResolve();\n };\n}\n","import { useEffect, useState } from 'react';\n\nexport const useBrowserTabsChannel = <T = unknown>({\n channelName,\n onMessage,\n}: {\n channelName: string;\n onMessage: (args: T) => void;\n}) => {\n const [tabsChannel] = useState(\n typeof BroadcastChannel !== 'undefined' ? new BroadcastChannel(channelName) : undefined\n );\n\n const postMessage = (data: T) => {\n tabsChannel?.postMessage(data);\n };\n\n useEffect(() => {\n const listener = (event: MessageEvent<T>) => {\n onMessage(event.data);\n };\n\n tabsChannel?.addEventListener('message', listener);\n\n return () => {\n tabsChannel?.removeEventListener('message', listener);\n };\n }, []);\n\n return { postMessage };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,gBAAkC;AAClC,mBAA8D;AAsBrD;AAhBT,IAAM,kBAAc,4BAAgC,MAAS;AAEtD,IAAM,eAAe,CAAC;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAyB;AACvB,QAAM,WAAO;AAAA,IACX,MAAM,IAAI,eAAK,EAAE,uBAAuB,cAAc,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KAAK;AACxB,yCAAU,UAAU;AAEpB;AAAA,IACF;AACA,UAAM,OAAO,UAAU;AACvB,2CAAY,KAAK;AAEjB,cAAU,CAAC,cAAc;AACvB,YAAM,YAAqB,CAAC;AAC5B,YAAM,iBAAiB,KAAK;AAG5B,eAAS,IAAI,GAAG,IAAI,eAAe,QAAQ,KAAK;AAC9C,cAAM,gBAAgB,eAAe,KAAK,CAAC,MAAG;AAtEtD;AAsEyD,8CAAa,EAAE,OAAO,OAAM,oBAAe,CAAC,MAAhB,mBAAmB,OAAO,IAAI;AAAA,SAAC;AAE5G,kBAAU,KAAK,iBAAiB,UAAW,CAAC,CAAC;AAAA,MAC/C;AAEA,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,oBAAkB;AAAA,IAChB,OAAO;AAAA,IACP,cAAc,CAAC,SAAS;AACtB,WAAK,KAAK,MAAM;AAAA,IAClB;AAAA,EACF,CAAC;AAED,oBAAkB;AAAA,IAChB,OAAO;AAAA,IACP,cAAc,MAAM;AAClB,WAAK;AAAA,IACP;AAAA,EACF,CAAC;AAED,+BAAU,MAAM;AACd,aAAS,MAAS;AAClB,iBAAa,IAAI;AACjB,kBAAc,KAAK;AACnB,SAAK;AAAA,EACP,GAAG,CAAC,KAAK,UAAU,OAAO,CAAC,CAAC;AAE5B,QAAM,UAAU,YAAY;AAC1B,UAAM,KAAK;AAAA,EACb;AAEA,SAAO,EAAE,QAAQ,OAAO,SAAS,WAAW,WAAW;AACzD;;;AJlGO,SAAS,QAAQ;AAAC;AAClB,SAAS,gBAAgB;AAAC;AAC1B,SAAS,cAAc;AAAC;AACxB,SAAS,OAAO;AAAC;","names":["import_react","import_js","import_react","import_react","import_js","import_react","import_react"]}