@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.
@@ -1,3 +1,323 @@
1
+ // src/hooks/NovuProvider.tsx
2
+ import { Novu } from "@novu/js";
3
+ import { createContext, useContext, useMemo } from "react";
4
+ import { jsx } from "react/jsx-runtime";
5
+ var NovuContext = createContext(void 0);
6
+ var NovuProvider = ({
7
+ children,
8
+ applicationIdentifier,
9
+ subscriberId,
10
+ subscriberHash,
11
+ backendUrl,
12
+ socketUrl,
13
+ useCache
14
+ }) => {
15
+ const novu = useMemo(
16
+ () => new Novu({ applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl, useCache }),
17
+ [applicationIdentifier, subscriberId, subscriberHash, backendUrl, socketUrl, useCache]
18
+ );
19
+ return /* @__PURE__ */ jsx(NovuContext.Provider, { value: novu, children });
20
+ };
21
+ var useNovu = () => {
22
+ const context = useContext(NovuContext);
23
+ if (!context) {
24
+ throw new Error("useNovu must be used within a <NovuProvider />");
25
+ }
26
+ return context;
27
+ };
28
+
29
+ // src/hooks/useNotifications.ts
30
+ import { useState, useEffect, useRef } from "react";
31
+ import { isSameFilter } from "@novu/js";
32
+ var useNotifications = (props) => {
33
+ const { tags, read, archived = false, limit, onSuccess, onError } = props || {};
34
+ const filterRef = useRef(void 0);
35
+ const { notifications, on, off } = useNovu();
36
+ const [data, setData] = useState();
37
+ const [error, setError] = useState();
38
+ const [isLoading, setIsLoading] = useState(true);
39
+ const [isFetching, setIsFetching] = useState(false);
40
+ const [hasMore, setHasMore] = useState(false);
41
+ const length = data == null ? void 0 : data.length;
42
+ const after = length ? data[length - 1].id : void 0;
43
+ const sync = (event) => {
44
+ if (!event.data || filterRef.current && !isSameFilter(filterRef.current, event.data.filter)) {
45
+ return;
46
+ }
47
+ setData(event.data.notifications);
48
+ setHasMore(event.data.hasMore);
49
+ };
50
+ useEffect(() => {
51
+ on("notifications.list.updated", sync);
52
+ return () => {
53
+ off("notifications.list.updated", sync);
54
+ };
55
+ }, []);
56
+ useEffect(() => {
57
+ const newFilter = { tags, read, archived };
58
+ if (filterRef.current && isSameFilter(filterRef.current, newFilter)) {
59
+ return;
60
+ }
61
+ notifications.clearCache({ filter: filterRef.current });
62
+ filterRef.current = newFilter;
63
+ fetchNotifications({ refetch: true });
64
+ }, [tags, read, archived]);
65
+ const fetchNotifications = async (options) => {
66
+ if (options == null ? void 0 : options.refetch) {
67
+ setError(void 0);
68
+ setIsLoading(true);
69
+ setIsFetching(false);
70
+ }
71
+ setIsFetching(true);
72
+ const response = await notifications.list({
73
+ tags,
74
+ read,
75
+ archived,
76
+ limit,
77
+ after: (options == null ? void 0 : options.refetch) ? void 0 : after
78
+ });
79
+ if (response.error) {
80
+ setError(response.error);
81
+ onError == null ? void 0 : onError(response.error);
82
+ } else {
83
+ onSuccess == null ? void 0 : onSuccess(response.data.notifications);
84
+ setData(response.data.notifications);
85
+ setHasMore(response.data.hasMore);
86
+ }
87
+ setIsLoading(false);
88
+ setIsFetching(false);
89
+ };
90
+ const refetch = () => {
91
+ notifications.clearCache({ filter: { tags, read, archived } });
92
+ return fetchNotifications({ refetch: true });
93
+ };
94
+ const fetchMore = async () => {
95
+ if (!hasMore || isFetching) return;
96
+ return fetchNotifications();
97
+ };
98
+ const readAll = async () => {
99
+ return await notifications.readAll({ tags });
100
+ };
101
+ const archiveAll = async () => {
102
+ return await notifications.archiveAll({ tags });
103
+ };
104
+ const archiveAllRead = async () => {
105
+ return await notifications.archiveAllRead({ tags });
106
+ };
107
+ return {
108
+ readAll,
109
+ archiveAll,
110
+ archiveAllRead,
111
+ notifications: data,
112
+ error,
113
+ isLoading,
114
+ isFetching,
115
+ refetch,
116
+ fetchMore,
117
+ hasMore
118
+ };
119
+ };
120
+
121
+ // src/hooks/usePreferences.ts
122
+ import { useEffect as useEffect2, useState as useState2 } from "react";
123
+ var usePreferences = (props) => {
124
+ const { onSuccess, onError } = props || {};
125
+ const [data, setData] = useState2();
126
+ const { preferences, on, off } = useNovu();
127
+ const [error, setError] = useState2();
128
+ const [isLoading, setIsLoading] = useState2(true);
129
+ const [isFetching, setIsFetching] = useState2(false);
130
+ const sync = (event) => {
131
+ if (!event.data) {
132
+ return;
133
+ }
134
+ setData(event.data);
135
+ };
136
+ useEffect2(() => {
137
+ fetchPreferences();
138
+ on("preferences.list.updated", sync);
139
+ on("preferences.list.pending", sync);
140
+ on("preferences.list.resolved", sync);
141
+ return () => {
142
+ off("preferences.list.updated", sync);
143
+ off("preferences.list.pending", sync);
144
+ off("preferences.list.resolved", sync);
145
+ };
146
+ }, []);
147
+ const fetchPreferences = async () => {
148
+ setIsFetching(true);
149
+ const response = await preferences.list();
150
+ if (response.error) {
151
+ setError(response.error);
152
+ onError == null ? void 0 : onError(response.error);
153
+ } else {
154
+ onSuccess == null ? void 0 : onSuccess(response.data);
155
+ }
156
+ setIsLoading(false);
157
+ setIsFetching(false);
158
+ };
159
+ const refetch = () => {
160
+ preferences.cache.clearAll();
161
+ return fetchPreferences();
162
+ };
163
+ return {
164
+ preferences: data,
165
+ error,
166
+ isLoading,
167
+ isFetching,
168
+ refetch
169
+ };
170
+ };
171
+
172
+ // src/hooks/useCounts.ts
173
+ import { useEffect as useEffect5, useState as useState4 } from "react";
174
+ import { areTagsEqual } from "@novu/js";
175
+
176
+ // src/hooks/internal/useWebsocketEvent.ts
177
+ import { useEffect as useEffect4 } from "react";
178
+
179
+ // src/utils/requestLock.ts
180
+ function requestLock(id, cb) {
181
+ if (!("locks" in navigator)) {
182
+ cb(id);
183
+ return () => {
184
+ };
185
+ }
186
+ let isFulfilled = false;
187
+ let promiseResolve;
188
+ const promise = new Promise((resolve) => {
189
+ promiseResolve = resolve;
190
+ });
191
+ navigator.locks.request(id, () => {
192
+ if (!isFulfilled) {
193
+ cb(id);
194
+ }
195
+ return promise;
196
+ });
197
+ return () => {
198
+ isFulfilled = true;
199
+ promiseResolve();
200
+ };
201
+ }
202
+
203
+ // src/hooks/internal/useBrowserTabsChannel.ts
204
+ import { useEffect as useEffect3, useState as useState3 } from "react";
205
+ var useBrowserTabsChannel = ({
206
+ channelName,
207
+ onMessage
208
+ }) => {
209
+ const [tabsChannel] = useState3(
210
+ typeof BroadcastChannel !== "undefined" ? new BroadcastChannel(channelName) : void 0
211
+ );
212
+ const postMessage = (data) => {
213
+ tabsChannel == null ? void 0 : tabsChannel.postMessage(data);
214
+ };
215
+ useEffect3(() => {
216
+ const listener = (event) => {
217
+ onMessage(event.data);
218
+ };
219
+ tabsChannel == null ? void 0 : tabsChannel.addEventListener("message", listener);
220
+ return () => {
221
+ tabsChannel == null ? void 0 : tabsChannel.removeEventListener("message", listener);
222
+ };
223
+ }, []);
224
+ return { postMessage };
225
+ };
226
+
227
+ // src/hooks/internal/useWebsocketEvent.ts
228
+ var useWebSocketEvent = ({
229
+ event: webSocketEvent,
230
+ eventHandler: onMessage
231
+ }) => {
232
+ const novu = useNovu();
233
+ const { postMessage } = useBrowserTabsChannel({ channelName: `nv.${webSocketEvent}`, onMessage });
234
+ const updateReadCount = (data) => {
235
+ onMessage(data);
236
+ postMessage(data);
237
+ };
238
+ useEffect4(() => {
239
+ const resolveLock = requestLock(`nv.${webSocketEvent}`, () => {
240
+ novu.on(webSocketEvent, updateReadCount);
241
+ });
242
+ return () => {
243
+ novu.off(webSocketEvent, updateReadCount);
244
+ resolveLock();
245
+ };
246
+ }, []);
247
+ };
248
+
249
+ // src/hooks/useCounts.ts
250
+ var useCounts = (props) => {
251
+ const { filters, onSuccess, onError } = props;
252
+ const { notifications } = useNovu();
253
+ const [error, setError] = useState4();
254
+ const [counts, setCounts] = useState4();
255
+ const [isLoading, setIsLoading] = useState4(true);
256
+ const [isFetching, setIsFetching] = useState4(false);
257
+ const sync = async (notification) => {
258
+ const existingCounts = counts ?? new Array(filters.length).fill(void 0);
259
+ let countFiltersToFetch = [];
260
+ if (notification) {
261
+ for (let i = 0; i < existingCounts.length; i++) {
262
+ const filter = filters[i];
263
+ if (areTagsEqual(filter.tags, notification.tags)) {
264
+ countFiltersToFetch.push(filter);
265
+ }
266
+ }
267
+ } else {
268
+ countFiltersToFetch = filters;
269
+ }
270
+ if (countFiltersToFetch.length === 0) {
271
+ return;
272
+ }
273
+ setIsFetching(true);
274
+ const countsRes = await notifications.count({ filters: countFiltersToFetch });
275
+ setIsFetching(false);
276
+ setIsLoading(false);
277
+ if (countsRes.error) {
278
+ setError(countsRes.error);
279
+ onError == null ? void 0 : onError(countsRes.error);
280
+ return;
281
+ }
282
+ const data = countsRes.data;
283
+ onSuccess == null ? void 0 : onSuccess(data.counts);
284
+ setCounts((oldCounts) => {
285
+ const newCounts = [];
286
+ const countsReceived = data.counts;
287
+ for (let i = 0; i < existingCounts.length; i++) {
288
+ const countReceived = countsReceived.find((c) => {
289
+ var _a;
290
+ return areTagsEqual(c.filter.tags, (_a = existingCounts[i]) == null ? void 0 : _a.filter.tags);
291
+ });
292
+ newCounts.push(countReceived || oldCounts[i]);
293
+ }
294
+ return newCounts;
295
+ });
296
+ };
297
+ useWebSocketEvent({
298
+ event: "notifications.notification_received",
299
+ eventHandler: (data) => {
300
+ sync(data.result);
301
+ }
302
+ });
303
+ useWebSocketEvent({
304
+ event: "notifications.unread_count_changed",
305
+ eventHandler: () => {
306
+ sync();
307
+ }
308
+ });
309
+ useEffect5(() => {
310
+ setError(void 0);
311
+ setIsLoading(true);
312
+ setIsFetching(false);
313
+ sync();
314
+ }, [JSON.stringify(filters)]);
315
+ const refetch = async () => {
316
+ await sync();
317
+ };
318
+ return { counts, error, refetch, isLoading, isFetching };
319
+ };
320
+
1
321
  // src/server.ts
2
322
  function Inbox() {
3
323
  }
@@ -11,6 +331,11 @@ export {
11
331
  Bell,
12
332
  Inbox,
13
333
  Notifications,
14
- Preferences
334
+ NovuProvider,
335
+ Preferences,
336
+ useCounts,
337
+ useNotifications,
338
+ useNovu,
339
+ usePreferences
15
340
  };
16
341
  //# sourceMappingURL=server.mjs.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":";AAOO,SAAS,QAAQ;AAAC;AAClB,SAAS,gBAAgB;AAAC;AAC1B,SAAS,cAAc;AAAC;AACxB,SAAS,OAAO;AAAC;","names":[]}
1
+ {"version":3,"sources":["../../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","../../src/server.ts"],"sourcesContent":["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","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"],"mappings":";AAAA,SAAS,YAAyB;AAClC,SAAoB,eAAe,YAAY,eAAe;AAsBrD;AAhBT,IAAM,cAAc,cAAgC,MAAS;AAEtD,IAAM,eAAe,CAAC;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAyB;AACvB,QAAM,OAAO;AAAA,IACX,MAAM,IAAI,KAAK,EAAE,uBAAuB,cAAc,gBAAgB,YAAY,WAAW,SAAS,CAAC;AAAA,IACvG,CAAC,uBAAuB,cAAc,gBAAgB,YAAY,WAAW,QAAQ;AAAA,EACvF;AAEA,SAAO,oBAAC,YAAY,UAAZ,EAAqB,OAAO,MAAO,UAAS;AACtD;AAEO,IAAM,UAAU,MAAM;AAC3B,QAAM,UAAU,WAAW,WAAW;AACtC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,gDAAgD;AAAA,EAClE;AAEA,SAAO;AACT;;;ACjCA,SAAS,UAAU,WAAW,cAAc;AAC5C,SAA6D,oBAAwC;AAY9F,IAAM,mBAAmB,CAAC,UAAkC;AACjE,QAAM,EAAE,MAAM,MAAM,WAAW,OAAO,OAAO,WAAW,QAAQ,IAAI,SAAS,CAAC;AAC9E,QAAM,YAAY,OAAuC,MAAS;AAClE,QAAM,EAAE,eAAe,IAAI,IAAI,IAAI,QAAQ;AAC3C,QAAM,CAAC,MAAM,OAAO,IAAI,SAA8B;AACtD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAoB;AAC9C,QAAM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A,IAChB,OAAO;AAAA,IACP,cAAc,MAAM;AAClB,WAAK;AAAA,IACP;AAAA,EACF,CAAC;AAED,EAAAC,WAAU,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;;;AIlGO,SAAS,QAAQ;AAAC;AAClB,SAAS,gBAAgB;AAAC;AAC1B,SAAS,cAAc;AAAC;AACxB,SAAS,OAAO;AAAC;","names":["useEffect","useState","useState","useEffect","useEffect","useState","useEffect","useEffect","useState","useEffect","useState","useEffect"]}
@@ -0,0 +1,5 @@
1
+ {
2
+ "main": "../dist/hooks/index.js",
3
+ "module": "../dist/hooks/index.mjs",
4
+ "types": "../dist/hooks/index.d.ts"
5
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@novu/react",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "repository": "https://github.com/novuhq/novu",
5
5
  "description": "Novu's React SDK for building custom inbox notification experiences",
6
6
  "author": "",
@@ -15,19 +15,31 @@
15
15
  "exports": {
16
16
  ".": {
17
17
  "import": {
18
- "types": "./dist/client/index.d.ts",
18
+ "types": "./dist/client/index.d.mts",
19
19
  "default": "./dist/server/server.mjs"
20
20
  },
21
21
  "require": {
22
22
  "types": "./dist/server/server.d.ts",
23
23
  "default": "./dist/server/server.js"
24
24
  }
25
+ },
26
+ "./hooks": {
27
+ "import": {
28
+ "types": "./dist/hooks/index.d.mts",
29
+ "default": "./dist/hooks/index.mjs"
30
+ },
31
+ "require": {
32
+ "types": "./dist/hooks/index.d.ts",
33
+ "default": "./dist/hooks/index.js"
34
+ }
25
35
  }
26
36
  },
27
37
  "files": [
28
38
  "dist",
29
39
  "dist/client/**/*",
30
- "dist/server/**/*"
40
+ "dist/server/**/*",
41
+ "dist/hooks/**/*",
42
+ "hooks/**/*"
31
43
  ],
32
44
  "sideEffects": false,
33
45
  "private": false,
@@ -36,8 +48,9 @@
36
48
  },
37
49
  "scripts": {
38
50
  "build:watch": "tsup --watch",
39
- "build": "tsup",
40
- "lint": "eslint src"
51
+ "build": "tsup && pnpm run check-exports",
52
+ "lint": "eslint src",
53
+ "check-exports": "attw --pack ."
41
54
  },
42
55
  "browserslist": {
43
56
  "production": [
@@ -52,11 +65,10 @@
52
65
  ]
53
66
  },
54
67
  "devDependencies": {
68
+ "@arethetypeswrong/cli": "^0.15.4",
55
69
  "@types/node": "^20.14.12",
56
- "@types/react": "^18.3.3",
57
- "@types/react-dom": "^18.3.0",
58
- "react": "^18.3.1",
59
- "react-dom": "^18.3.1",
70
+ "@types/react": "*",
71
+ "@types/react-dom": "*",
60
72
  "tsup": "^8.2.1",
61
73
  "typescript": "4.9.5"
62
74
  },
@@ -64,7 +76,12 @@
64
76
  "react": ">=17",
65
77
  "react-dom": ">=17"
66
78
  },
79
+ "peerDependenciesMeta": {
80
+ "react-dom": {
81
+ "optional": true
82
+ }
83
+ },
67
84
  "dependencies": {
68
- "@novu/js": "^2.0.0"
85
+ "@novu/js": "^2.1.0"
69
86
  }
70
87
  }