@novu/react 3.12.0-rc.1 → 3.12.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.
Files changed (47) hide show
  1. package/dist/cjs/components/subscription/SubscriptionButton.cjs +1 -1
  2. package/dist/cjs/components/subscription/SubscriptionButton.cjs.map +1 -1
  3. package/dist/cjs/components/subscription/SubscriptionPreferences.cjs +1 -1
  4. package/dist/cjs/components/subscription/SubscriptionPreferences.cjs.map +1 -1
  5. package/dist/cjs/hooks/NovuProvider.cjs +1 -1
  6. package/dist/cjs/hooks/index.cjs +2 -2
  7. package/dist/cjs/hooks/index.cjs.map +1 -1
  8. package/dist/cjs/hooks/index.d.cts +1 -1
  9. package/dist/cjs/hooks/useCounts.cjs +2 -2
  10. package/dist/cjs/hooks/useCounts.cjs.map +1 -1
  11. package/dist/cjs/hooks/useNotifications.cjs +57 -60
  12. package/dist/cjs/hooks/useNotifications.cjs.map +1 -1
  13. package/dist/cjs/hooks/{useDeleteSubscription.cjs → useRemoveSubscription.cjs} +14 -14
  14. package/dist/cjs/hooks/useRemoveSubscription.cjs.map +1 -0
  15. package/dist/cjs/hooks/useRemoveSubscription.d.cts +17 -0
  16. package/dist/cjs/index.cjs +2 -2
  17. package/dist/cjs/index.cjs.map +1 -1
  18. package/dist/cjs/index.d.cts +1 -1
  19. package/dist/cjs/server/index.cjs +5 -5
  20. package/dist/cjs/server/index.cjs.map +1 -1
  21. package/dist/cjs/server/index.d.cts +3 -3
  22. package/dist/esm/components/subscription/SubscriptionButton.js +1 -1
  23. package/dist/esm/components/subscription/SubscriptionButton.js.map +1 -1
  24. package/dist/esm/components/subscription/SubscriptionPreferences.js +1 -1
  25. package/dist/esm/components/subscription/SubscriptionPreferences.js.map +1 -1
  26. package/dist/esm/hooks/NovuProvider.js +1 -1
  27. package/dist/esm/hooks/index.d.ts +1 -1
  28. package/dist/esm/hooks/index.js +1 -1
  29. package/dist/esm/hooks/index.js.map +1 -1
  30. package/dist/esm/hooks/useCounts.js +3 -3
  31. package/dist/esm/hooks/useCounts.js.map +1 -1
  32. package/dist/esm/hooks/useNotifications.js +58 -61
  33. package/dist/esm/hooks/useNotifications.js.map +1 -1
  34. package/dist/esm/hooks/useRemoveSubscription.d.ts +17 -0
  35. package/dist/esm/hooks/{useDeleteSubscription.js → useRemoveSubscription.js} +10 -10
  36. package/dist/esm/hooks/useRemoveSubscription.js.map +1 -0
  37. package/dist/esm/index.d.ts +1 -1
  38. package/dist/esm/index.js +2 -2
  39. package/dist/esm/index.js.map +1 -1
  40. package/dist/esm/server/index.d.ts +3 -3
  41. package/dist/esm/server/index.js +4 -4
  42. package/dist/esm/server/index.js.map +1 -1
  43. package/package.json +11 -11
  44. package/dist/cjs/hooks/useDeleteSubscription.cjs.map +0 -1
  45. package/dist/cjs/hooks/useDeleteSubscription.d.cts +0 -17
  46. package/dist/esm/hooks/useDeleteSubscription.d.ts +0 -17
  47. package/dist/esm/hooks/useDeleteSubscription.js.map +0 -1
@@ -17,7 +17,7 @@ var SubscriptionButton = React.memo(
17
17
  const { novuUI } = useNovuUI();
18
18
  const mount = React.useCallback(
19
19
  (element) => {
20
- if (!topicKey || !preferences) {
20
+ if (!topicKey) {
21
21
  return;
22
22
  }
23
23
  return novuUI.mountComponent({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/subscription/SubscriptionButton.tsx"],"sourcesContent":["import type { SubscriptionButtonWrapperProps } from '@novu/js/ui';\nimport React from 'react';\nimport { useNovuUI } from '../../context/NovuUIContext';\nimport { Mounter } from '../Mounter';\n\nexport type SubscriptionButtonProps = Partial<SubscriptionButtonWrapperProps>;\n\nexport const SubscriptionButton = React.memo(\n ({\n topicKey,\n identifier,\n preferences,\n onClick,\n onDeleteError,\n onDeleteSuccess,\n onCreateError,\n onCreateSuccess,\n }: SubscriptionButtonProps) => {\n const { novuUI } = useNovuUI();\n\n const mount = React.useCallback(\n (element: HTMLElement) => {\n if (!topicKey || !preferences) {\n return;\n }\n\n return novuUI.mountComponent({\n name: 'SubscriptionButton',\n element,\n props: {\n topicKey,\n identifier,\n preferences,\n onClick,\n onDeleteError,\n onDeleteSuccess,\n onCreateError,\n onCreateSuccess,\n },\n });\n },\n [\n novuUI,\n topicKey,\n identifier,\n preferences,\n onClick,\n onDeleteError,\n onDeleteSuccess,\n onCreateError,\n onCreateSuccess,\n ]\n );\n\n return <Mounter mount={mount} />;\n }\n);\n"],"mappings":";AACA,OAAO,WAAW;AAClB,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AAmDb;AA/CJ,IAAM,qBAAqB,MAAM;AAAA,EACtC,CAAC;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,MAA+B;AAC7B,UAAM,EAAE,OAAO,IAAI,UAAU;AAE7B,UAAM,QAAQ,MAAM;AAAA,MAClB,CAAC,YAAyB;AACxB,YAAI,CAAC,YAAY,CAAC,aAAa;AAC7B;AAAA,QACF;AAEA,eAAO,OAAO,eAAe;AAAA,UAC3B,MAAM;AAAA,UACN;AAAA,UACA,OAAO;AAAA,YACL;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH;AAAA,MACA;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,oBAAC,WAAQ,OAAc;AAAA,EAChC;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/components/subscription/SubscriptionButton.tsx"],"sourcesContent":["import type { SubscriptionButtonWrapperProps } from '@novu/js/ui';\nimport React from 'react';\nimport { useNovuUI } from '../../context/NovuUIContext';\nimport { Mounter } from '../Mounter';\n\nexport type SubscriptionButtonProps = Partial<SubscriptionButtonWrapperProps>;\n\nexport const SubscriptionButton = React.memo(\n ({\n topicKey,\n identifier,\n preferences,\n onClick,\n onDeleteError,\n onDeleteSuccess,\n onCreateError,\n onCreateSuccess,\n }: SubscriptionButtonProps) => {\n const { novuUI } = useNovuUI();\n\n const mount = React.useCallback(\n (element: HTMLElement) => {\n if (!topicKey) {\n return;\n }\n\n return novuUI.mountComponent({\n name: 'SubscriptionButton',\n element,\n props: {\n topicKey,\n identifier,\n preferences,\n onClick,\n onDeleteError,\n onDeleteSuccess,\n onCreateError,\n onCreateSuccess,\n },\n });\n },\n [\n novuUI,\n topicKey,\n identifier,\n preferences,\n onClick,\n onDeleteError,\n onDeleteSuccess,\n onCreateError,\n onCreateSuccess,\n ]\n );\n\n return <Mounter mount={mount} />;\n }\n);\n"],"mappings":";AACA,OAAO,WAAW;AAClB,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AAmDb;AA/CJ,IAAM,qBAAqB,MAAM;AAAA,EACtC,CAAC;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,MAA+B;AAC7B,UAAM,EAAE,OAAO,IAAI,UAAU;AAE7B,UAAM,QAAQ,MAAM;AAAA,MAClB,CAAC,YAAyB;AACxB,YAAI,CAAC,UAAU;AACb;AAAA,QACF;AAEA,eAAO,OAAO,eAAe;AAAA,UAC3B,MAAM;AAAA,UACN;AAAA,UACA,OAAO;AAAA,YACL;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH;AAAA,MACA;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,oBAAC,WAAQ,OAAc;AAAA,EAChC;AACF;","names":[]}
@@ -17,7 +17,7 @@ var SubscriptionPreferences = React.memo(
17
17
  const { novuUI } = useNovuUI();
18
18
  const mount = React.useCallback(
19
19
  (element) => {
20
- if (!topicKey || !preferences) {
20
+ if (!topicKey) {
21
21
  return;
22
22
  }
23
23
  return novuUI.mountComponent({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/subscription/SubscriptionPreferences.tsx"],"sourcesContent":["import type { SubscriptionPreferencesWrapperProps } from '@novu/js/ui';\nimport React from 'react';\nimport { useNovuUI } from '../../context/NovuUIContext';\nimport { Mounter } from '../Mounter';\n\nexport type SubscriptionPreferencesProps = Partial<SubscriptionPreferencesWrapperProps>;\n\nexport const SubscriptionPreferences = React.memo(\n ({\n topicKey,\n identifier,\n preferences,\n onClick,\n onDeleteError,\n onDeleteSuccess,\n onCreateError,\n onCreateSuccess,\n }: SubscriptionPreferencesProps) => {\n const { novuUI } = useNovuUI();\n\n const mount = React.useCallback(\n (element: HTMLElement) => {\n if (!topicKey || !preferences) {\n return;\n }\n\n return novuUI.mountComponent({\n name: 'SubscriptionPreferences',\n element,\n props: {\n topicKey,\n identifier,\n preferences,\n onClick,\n onDeleteError,\n onDeleteSuccess,\n onCreateError,\n onCreateSuccess,\n },\n });\n },\n [\n novuUI,\n topicKey,\n identifier,\n preferences,\n onClick,\n onDeleteError,\n onDeleteSuccess,\n onCreateError,\n onCreateSuccess,\n ]\n );\n\n return <Mounter mount={mount} />;\n }\n);\n"],"mappings":";AACA,OAAO,WAAW;AAClB,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AAmDb;AA/CJ,IAAM,0BAA0B,MAAM;AAAA,EAC3C,CAAC;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,MAAoC;AAClC,UAAM,EAAE,OAAO,IAAI,UAAU;AAE7B,UAAM,QAAQ,MAAM;AAAA,MAClB,CAAC,YAAyB;AACxB,YAAI,CAAC,YAAY,CAAC,aAAa;AAC7B;AAAA,QACF;AAEA,eAAO,OAAO,eAAe;AAAA,UAC3B,MAAM;AAAA,UACN;AAAA,UACA,OAAO;AAAA,YACL;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH;AAAA,MACA;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,oBAAC,WAAQ,OAAc;AAAA,EAChC;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/components/subscription/SubscriptionPreferences.tsx"],"sourcesContent":["import type { SubscriptionPreferencesWrapperProps } from '@novu/js/ui';\nimport React from 'react';\nimport { useNovuUI } from '../../context/NovuUIContext';\nimport { Mounter } from '../Mounter';\n\nexport type SubscriptionPreferencesProps = Partial<SubscriptionPreferencesWrapperProps>;\n\nexport const SubscriptionPreferences = React.memo(\n ({\n topicKey,\n identifier,\n preferences,\n onClick,\n onDeleteError,\n onDeleteSuccess,\n onCreateError,\n onCreateSuccess,\n }: SubscriptionPreferencesProps) => {\n const { novuUI } = useNovuUI();\n\n const mount = React.useCallback(\n (element: HTMLElement) => {\n if (!topicKey) {\n return;\n }\n\n return novuUI.mountComponent({\n name: 'SubscriptionPreferences',\n element,\n props: {\n topicKey,\n identifier,\n preferences,\n onClick,\n onDeleteError,\n onDeleteSuccess,\n onCreateError,\n onCreateSuccess,\n },\n });\n },\n [\n novuUI,\n topicKey,\n identifier,\n preferences,\n onClick,\n onDeleteError,\n onDeleteSuccess,\n onCreateError,\n onCreateSuccess,\n ]\n );\n\n return <Mounter mount={mount} />;\n }\n);\n"],"mappings":";AACA,OAAO,WAAW;AAClB,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AAmDb;AA/CJ,IAAM,0BAA0B,MAAM;AAAA,EAC3C,CAAC;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,MAAoC;AAClC,UAAM,EAAE,OAAO,IAAI,UAAU;AAE7B,UAAM,QAAQ,MAAM;AAAA,MAClB,CAAC,YAAyB;AACxB,YAAI,CAAC,UAAU;AACb;AAAA,QACF;AAEA,eAAO,OAAO,eAAe;AAAA,UAC3B,MAAM;AAAA,UACN;AAAA,UACA,OAAO;AAAA,YACL;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH;AAAA,MACA;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,oBAAC,WAAQ,OAAc;AAAA,EAChC;AACF;","names":[]}
@@ -3,7 +3,7 @@ import { Novu } from "@novu/js";
3
3
  import { buildSubscriber } from "@novu/js/internal";
4
4
  import { createContext, useContext, useMemo } from "react";
5
5
  import { jsx } from "react/jsx-runtime";
6
- var version = "3.12.0-rc.1";
6
+ var version = "3.12.0";
7
7
  var name = "@novu/react";
8
8
  var baseUserAgent = `${name}@${version}`;
9
9
  var NovuContext = createContext(void 0);
@@ -3,9 +3,9 @@ export { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from '@no
3
3
  export { NovuProvider, useNovu } from './NovuProvider.js';
4
4
  export { UseCountsProps, UseCountsResult, useCounts } from './useCounts.js';
5
5
  export { UseCreateSubscriptionProps, UseCreateSubscriptionResult, useCreateSubscription } from './useCreateSubscription.js';
6
- export { UseDeleteSubscriptionProps, UseDeleteSubscriptionResult, useDeleteSubscription } from './useDeleteSubscription.js';
7
6
  export { UseNotificationsProps, UseNotificationsResult, useNotifications } from './useNotifications.js';
8
7
  export { UsePreferencesProps, UsePreferencesResult, usePreferences } from './usePreferences.js';
8
+ export { UseRemoveSubscriptionProps, UseRemoveSubscriptionResult, useRemoveSubscription } from './useRemoveSubscription.js';
9
9
  export { UseScheduleProps, UseScheduleResult, useSchedule } from './useSchedule.js';
10
10
  export { UseSubscriptionProps, UseSubscriptionResult, useSubscription } from './useSubscription.js';
11
11
  export { UseSubscriptionsProps, UseSubscriptionsResult, useSubscriptions } from './useSubscriptions.js';
@@ -3,9 +3,9 @@ import { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from "@no
3
3
  import { NovuProvider, useNovu } from "./NovuProvider.js";
4
4
  export * from "./useCounts.js";
5
5
  export * from "./useCreateSubscription.js";
6
- export * from "./useDeleteSubscription.js";
7
6
  export * from "./useNotifications.js";
8
7
  export * from "./usePreferences.js";
8
+ export * from "./useRemoveSubscription.js";
9
9
  export * from "./useSchedule.js";
10
10
  export * from "./useSubscription.js";
11
11
  export * from "./useSubscriptions.js";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/hooks/index.ts"],"sourcesContent":["export type * from '@novu/js';\nexport { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from '@novu/js';\nexport { NovuProvider, useNovu } from './NovuProvider';\nexport * from './useCounts';\nexport * from './useCreateSubscription';\nexport * from './useDeleteSubscription';\nexport * from './useNotifications';\nexport * from './usePreferences';\nexport * from './useSchedule';\nexport * from './useSubscription';\nexport * from './useSubscriptions';\nexport * from './useUpdateSubscription';\n"],"mappings":";AACA,SAAS,iBAAiB,mBAAmB,+BAA+B;AAC5E,SAAS,cAAc,eAAe;AACtC,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../../src/hooks/index.ts"],"sourcesContent":["export type * from '@novu/js';\nexport { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from '@novu/js';\nexport { NovuProvider, useNovu } from './NovuProvider';\nexport * from './useCounts';\nexport * from './useCreateSubscription';\nexport * from './useNotifications';\nexport * from './usePreferences';\nexport * from './useRemoveSubscription';\nexport * from './useSchedule';\nexport * from './useSubscription';\nexport * from './useSubscriptions';\nexport * from './useUpdateSubscription';\n"],"mappings":";AACA,SAAS,iBAAiB,mBAAmB,+BAA+B;AAC5E,SAAS,cAAc,eAAe;AACtC,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
@@ -1,17 +1,17 @@
1
1
  // src/hooks/useCounts.ts
2
2
  import { areTagsEqual, isSameFilter } from "@novu/js";
3
- import { useEffect, useRef, useState } from "react";
3
+ import { useEffect, useState } from "react";
4
+ import { useDataRef } from "./internal/useDataRef.js";
4
5
  import { useWebSocketEvent } from "./internal/useWebsocketEvent.js";
5
6
  import { useNovu } from "./NovuProvider.js";
6
7
  var useCounts = (props) => {
7
8
  const { filters, onSuccess, onError } = props;
8
9
  const { notifications } = useNovu();
9
- const filtersRef = useRef(filters);
10
+ const filtersRef = useDataRef(filters);
10
11
  const [error, setError] = useState();
11
12
  const [counts, setCounts] = useState();
12
13
  const [isLoading, setIsLoading] = useState(true);
13
14
  const [isFetching, setIsFetching] = useState(false);
14
- filtersRef.current = filters;
15
15
  const sync = async (notification, overrideFilters) => {
16
16
  const currentFilters = overrideFilters || filtersRef.current;
17
17
  const existingCounts = currentFilters.map((filter) => ({ count: 0, filter }));
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/hooks/useCounts.ts"],"sourcesContent":["import { areTagsEqual, isSameFilter, Notification, NotificationFilter, NovuError } from '@novu/js';\nimport { useEffect, useRef, useState } from 'react';\nimport { useWebSocketEvent } from './internal/useWebsocketEvent';\nimport { useNovu } from './NovuProvider';\n\ntype Count = {\n count: number;\n filter: NotificationFilter;\n};\n\n/**\n * Props for the useCounts hook.\n *\n * @example\n * ```tsx\n * // Count unread notifications\n * const { counts } = useCounts({\n * filters: [{ read: false }]\n * });\n *\n * // Count unseen notifications with specific tags\n * const { counts } = useCounts({\n * filters: [{ seen: false, tags: ['important'] }]\n * });\n *\n * // Count seen but unread notifications\n * const { counts } = useCounts({\n * filters: [{ seen: true, read: false }]\n * });\n * ```\n */\nexport type UseCountsProps = {\n filters: NotificationFilter[];\n onSuccess?: (data: Count[]) => void;\n onError?: (error: NovuError) => void;\n};\n\nexport type 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 filtersRef = useRef<NotificationFilter[]>(filters);\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 // Keep ref up to date\n filtersRef.current = filters;\n\n const sync = async (notification?: Notification, overrideFilters?: NotificationFilter[]) => {\n const currentFilters = overrideFilters || filtersRef.current;\n const existingCounts = currentFilters.map((filter) => ({ count: 0, filter }));\n let countFiltersToFetch: NotificationFilter[] = [];\n if (notification) {\n for (let i = 0; i < existingCounts.length; i++) {\n const filter = currentFilters[i];\n const isSeverityMatches =\n !filter.severity ||\n (Array.isArray(filter.severity) && filter.severity.length === 0) ||\n (Array.isArray(filter.severity) && filter.severity.includes(notification.severity)) ||\n (!Array.isArray(filter.severity) && filter.severity === notification.severity);\n\n if (areTagsEqual(filter.tags, notification.tags) && isSeverityMatches) {\n countFiltersToFetch.push(filter);\n }\n }\n } else {\n countFiltersToFetch = currentFilters;\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 for (let i = 0; i < existingCounts.length; i++) {\n const existingFilter = existingCounts[i].filter;\n const countReceived = countsReceived.find((c) => isSameFilter(c.filter, existingFilter));\n const count = countReceived || oldCounts?.[i];\n if (count) {\n newCounts.push(count);\n }\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(undefined, filters);\n }, [JSON.stringify(filters)]);\n\n const refetch = async () => {\n await sync();\n };\n\n return { counts, error, refetch, isLoading, isFetching };\n};\n"],"mappings":";AAAA,SAAS,cAAc,oBAAiE;AACxF,SAAS,WAAW,QAAQ,gBAAgB;AAC5C,SAAS,yBAAyB;AAClC,SAAS,eAAe;AA0CjB,IAAM,YAAY,CAAC,UAA2C;AACnE,QAAM,EAAE,SAAS,WAAW,QAAQ,IAAI;AACxC,QAAM,EAAE,cAAc,IAAI,QAAQ;AAClC,QAAM,aAAa,OAA6B,OAAO;AACvD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAoB;AAC9C,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAkB;AAC9C,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,IAAI;AAC/C,QAAM,CAAC,YAAY,aAAa,IAAI,SAAS,KAAK;AAGlD,aAAW,UAAU;AAErB,QAAM,OAAO,OAAO,cAA6B,oBAA2C;AAC1F,UAAM,iBAAiB,mBAAmB,WAAW;AACrD,UAAM,iBAAiB,eAAe,IAAI,CAAC,YAAY,EAAE,OAAO,GAAG,OAAO,EAAE;AAC5E,QAAI,sBAA4C,CAAC;AACjD,QAAI,cAAc;AAChB,eAAS,IAAI,GAAG,IAAI,eAAe,QAAQ,KAAK;AAC9C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ChB,OAAO;AAAA,IACP,cAAc,MAAM;AAClB,WAAK;AAAA,IACP;AAAA,EACF,CAAC;AAED,YAAU,MAAM;AACd,aAAS,MAAS;AAClB,iBAAa,IAAI;AACjB,kBAAc,KAAK;AACnB,SAAK,QAAW,OAAO;AAAA,EACzB,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;","names":[]}
1
+ {"version":3,"sources":["../../../src/hooks/useCounts.ts"],"sourcesContent":["import { areTagsEqual, isSameFilter, Notification, NotificationFilter, NovuError } from '@novu/js';\nimport { useEffect, useState } from 'react';\nimport { useDataRef } from './internal/useDataRef';\nimport { useWebSocketEvent } from './internal/useWebsocketEvent';\nimport { useNovu } from './NovuProvider';\n\ntype Count = {\n count: number;\n filter: NotificationFilter;\n};\n\n/**\n * Props for the useCounts hook.\n *\n * @example\n * ```tsx\n * // Count unread notifications\n * const { counts } = useCounts({\n * filters: [{ read: false }]\n * });\n *\n * // Count unseen notifications with specific tags\n * const { counts } = useCounts({\n * filters: [{ seen: false, tags: ['important'] }]\n * });\n *\n * // Count seen but unread notifications\n * const { counts } = useCounts({\n * filters: [{ seen: true, read: false }]\n * });\n * ```\n */\nexport type UseCountsProps = {\n filters: NotificationFilter[];\n onSuccess?: (data: Count[]) => void;\n onError?: (error: NovuError) => void;\n};\n\nexport type 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 filtersRef = useDataRef<NotificationFilter[]>(filters);\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, overrideFilters?: NotificationFilter[]) => {\n const currentFilters = overrideFilters || filtersRef.current;\n const existingCounts = currentFilters.map((filter) => ({ count: 0, filter }));\n let countFiltersToFetch: NotificationFilter[] = [];\n if (notification) {\n for (let i = 0; i < existingCounts.length; i++) {\n const filter = currentFilters[i];\n const isSeverityMatches =\n !filter.severity ||\n (Array.isArray(filter.severity) && filter.severity.length === 0) ||\n (Array.isArray(filter.severity) && filter.severity.includes(notification.severity)) ||\n (!Array.isArray(filter.severity) && filter.severity === notification.severity);\n\n if (areTagsEqual(filter.tags, notification.tags) && isSeverityMatches) {\n countFiltersToFetch.push(filter);\n }\n }\n } else {\n countFiltersToFetch = currentFilters;\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 for (let i = 0; i < existingCounts.length; i++) {\n const existingFilter = existingCounts[i].filter;\n const countReceived = countsReceived.find((c) => isSameFilter(c.filter, existingFilter));\n const count = countReceived || oldCounts?.[i];\n if (count) {\n newCounts.push(count);\n }\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(undefined, filters);\n }, [JSON.stringify(filters)]);\n\n const refetch = async () => {\n await sync();\n };\n\n return { counts, error, refetch, isLoading, isFetching };\n};\n"],"mappings":";AAAA,SAAS,cAAc,oBAAiE;AACxF,SAAS,WAAW,gBAAgB;AACpC,SA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nB,eAAS,UAAU,KAAK;AACxB,gBAAU,UAAU,KAAK;AAEzB;AAAA,IACF;AACA,UAAM,OAAO,UAAU;AACvB,gBAAY,KAAK,MAAM;AAEvB,cAAU,CAAC,cAAc;AACvB,YAAM,YAAqB,CAAC;AAC5B,YAAM,iBAAiB,KAAK;AAE5B,eAAS,IAAI,GAAG,IAAI,eAAe,QAAQ,KAAK;AAC9C,cAAM,iBAAiB,eAAe,CAAC,EAAE;AACzC,cAAM,gBAAgB,eAAe,KAAK,CAAC,MAAM,aAAa,EAAE,QAAQ,cAAc,CAAC;AACvF,cAAM,QAAQ,iBAAiB,YAAY,CAAC;AAC5C,YAAI,OAAO;AACT,oBAAU,KAAK,KAAK;AAAA,QACtB;AAAA,MACF;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,YAAU,MAAM;AACd,aAAS,MAAS;AAClB,iBAAa,IAAI;AACjB,kBAAc,KAAK;AACnB,SAAK,QAAW,OAAO;AAAA,EACzB,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;","names":[]}
@@ -1,6 +1,7 @@
1
1
  // src/hooks/useNotifications.ts
2
2
  import { checkNotificationMatchesFilter, isSameFilter } from "@novu/js";
3
- import { useCallback, useEffect, useRef, useState } from "react";
3
+ import { useCallback, useEffect, useState } from "react";
4
+ import { useDataRef } from "./internal/useDataRef.js";
4
5
  import { useWebSocketEvent } from "./internal/useWebsocketEvent.js";
5
6
  import { useNovu } from "./NovuProvider.js";
6
7
  var useNotifications = (props) => {
@@ -12,16 +13,13 @@ var useNotifications = (props) => {
12
13
  snoozed = false,
13
14
  seen,
14
15
  severity,
15
- limit,
16
+ limit = 10,
16
17
  onSuccess,
17
18
  onError
18
19
  } = props || {};
19
- const filterRef = useRef(void 0);
20
- const { notifications } = useNovu();
21
- const getCurrentFilter = useCallback(
22
- () => filterRef.current || { tags, data: dataFilter, severity },
23
- [tags, dataFilter, severity]
24
- );
20
+ const limitRef = useDataRef(limit);
21
+ const filterRef = useDataRef({ tags, data: dataFilter, read, archived, snoozed, seen, severity });
22
+ const novu = useNovu();
25
23
  const [data, setData] = useState();
26
24
  const [error, setError] = useState();
27
25
  const [isLoading, setIsLoading] = useState(true);
@@ -29,24 +27,31 @@ var useNotifications = (props) => {
29
27
  const [hasMore, setHasMore] = useState(false);
30
28
  const length = data?.length;
31
29
  const after = length ? data[length - 1].id : void 0;
32
- useWebSocketEvent({
33
- event: "notifications.unread_count_changed",
34
- eventHandler: () => {
35
- void refetch();
36
- }
37
- });
38
- useWebSocketEvent({
39
- event: "notifications.unseen_count_changed",
40
- eventHandler: () => {
41
- void refetch();
42
- }
43
- });
30
+ const afterRef = useDataRef(after);
31
+ useEffect(() => {
32
+ const listener = ({
33
+ data: data2
34
+ }) => {
35
+ if (!data2 || !isSameFilter(filterRef.current, data2.filter)) {
36
+ return;
37
+ }
38
+ setData(data2.notifications);
39
+ setHasMore(data2.hasMore);
40
+ };
41
+ const cleanup = novu.on("notifications.list.updated", listener);
42
+ return () => {
43
+ cleanup();
44
+ };
45
+ }, [filterRef, novu]);
44
46
  useWebSocketEvent({
45
47
  event: "notifications.notification_received",
46
48
  eventHandler: ({ result: notification }) => {
47
- const currentFilter = getCurrentFilter();
49
+ const currentFilter = filterRef.current;
48
50
  const matches = checkNotificationMatchesFilter(notification, currentFilter);
49
- if (matches) void refetch();
51
+ if (matches) {
52
+ const cacheKey = { ...currentFilter, limit: limitRef.current };
53
+ novu.notifications.cache.unshift(cacheKey, notification);
54
+ }
50
55
  }
51
56
  });
52
57
  const fetchNotifications = useCallback(
@@ -57,59 +62,51 @@ var useNotifications = (props) => {
57
62
  setIsFetching(false);
58
63
  }
59
64
  setIsFetching(true);
60
- const currentFilter = getCurrentFilter();
61
- const response = await notifications.list({
62
- ...currentFilter,
65
+ const response = await novu.notifications.list({
66
+ ...filterRef.current,
63
67
  limit,
64
- after: options?.refetch ? void 0 : after
68
+ after: options?.refetch ? void 0 : afterRef.current
65
69
  });
66
70
  if (response.error) {
67
71
  setError(response.error);
68
72
  onError?.(response.error);
73
+ setIsLoading(false);
74
+ setIsFetching(false);
69
75
  } else if (response.data) {
70
- onSuccess?.(response.data.notifications);
71
- setData(response.data.notifications);
72
- setHasMore(response.data.hasMore);
76
+ const responseData = response.data;
77
+ onSuccess?.(responseData.notifications);
78
+ setData(responseData.notifications);
79
+ setHasMore(responseData.hasMore);
80
+ setIsLoading(false);
81
+ setIsFetching(false);
73
82
  }
74
- setIsLoading(false);
75
- setIsFetching(false);
76
83
  },
77
- [notifications, getCurrentFilter, limit, after, onError, onSuccess]
84
+ [novu, filterRef, afterRef, limit, onError, onSuccess]
78
85
  );
79
86
  useEffect(() => {
80
- const newFilter = { tags, data: dataFilter, read, archived, snoozed, seen, severity };
81
- if (filterRef.current && isSameFilter(filterRef.current, newFilter)) {
82
- return;
83
- }
84
- notifications.clearCache({ filter: filterRef.current });
85
- filterRef.current = newFilter;
87
+ novu.notifications.clearCache({ filter: filterRef.current });
86
88
  fetchNotifications({ refetch: true });
87
- }, [tags, dataFilter, read, archived, snoozed, seen, notifications, fetchNotifications]);
88
- const refetch = () => {
89
- const filter = getCurrentFilter();
90
- notifications.clearCache({ filter });
89
+ }, [filterRef, novu, JSON.stringify(filterRef.current), fetchNotifications]);
90
+ const refetch = useCallback(() => {
91
+ novu.notifications.clearCache({ filter: filterRef.current });
91
92
  return fetchNotifications({ refetch: true });
92
- };
93
- const fetchMore = async () => {
93
+ }, [filterRef, novu, fetchNotifications]);
94
+ const fetchMore = useCallback(async () => {
94
95
  if (!hasMore || isFetching) return;
95
96
  return fetchNotifications();
96
- };
97
- const readAll = async () => {
98
- const { tags: tags2, data: data2 } = getCurrentFilter();
99
- return await notifications.readAll({ tags: tags2, data: data2 });
100
- };
101
- const seenAll = async () => {
102
- const { tags: tags2, data: data2 } = getCurrentFilter();
103
- return await notifications.seenAll({ tags: tags2, data: data2 });
104
- };
105
- const archiveAll = async () => {
106
- const { tags: tags2, data: data2 } = getCurrentFilter();
107
- return await notifications.archiveAll({ tags: tags2, data: data2 });
108
- };
109
- const archiveAllRead = async () => {
110
- const { tags: tags2, data: data2 } = getCurrentFilter();
111
- return await notifications.archiveAllRead({ tags: tags2, data: data2 });
112
- };
97
+ }, [hasMore, isFetching, fetchNotifications]);
98
+ const readAll = useCallback(async () => {
99
+ return await novu.notifications.readAll({ tags: filterRef.current.tags, data: filterRef.current.data });
100
+ }, [filterRef, novu]);
101
+ const seenAll = useCallback(async () => {
102
+ return await novu.notifications.seenAll({ tags: filterRef.current.tags, data: filterRef.current.data });
103
+ }, [filterRef, novu]);
104
+ const archiveAll = useCallback(async () => {
105
+ return await novu.notifications.archiveAll({ tags: filterRef.current.tags, data: filterRef.current.data });
106
+ }, [filterRef, novu]);
107
+ const archiveAllRead = useCallback(async () => {
108
+ return await novu.notifications.archiveAllRead({ tags: filterRef.current.tags, data: filterRef.current.data });
109
+ }, [filterRef, novu]);
113
110
  return {
114
111
  readAll,
115
112
  seenAll,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/hooks/useNotifications.ts"],"sourcesContent":["import { checkNotificationMatchesFilter, isSameFilter, Notification, NotificationFilter, NovuError } from '@novu/js';\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { useWebSocketEvent } from './internal/useWebsocketEvent';\nimport { useNovu } from './NovuProvider';\n\n/**\n * Props for the useNotifications hook.\n *\n * @example\n * ```tsx\n * // Get unread notifications\n * const { notifications } = useNotifications({\n * read: false\n * });\n *\n * // Get unseen notifications with specific tags\n * const { notifications } = useNotifications({\n * seen: false,\n * tags: ['important']\n * });\n *\n * // Get notifications (auto-updates in real time when new notifications arrive)\n * const { notifications } = useNotifications({\n * read: false\n * });\n * ```\n */\nexport type UseNotificationsProps = {\n tags?: NotificationFilter['tags'];\n data?: NotificationFilter['data'];\n read?: NotificationFilter['read'];\n archived?: NotificationFilter['archived'];\n snoozed?: NotificationFilter['snoozed'];\n seen?: NotificationFilter['seen'];\n severity?: NotificationFilter['severity'];\n limit?: number;\n onSuccess?: (data: Notification[]) => void;\n onError?: (error: NovuError) => void;\n};\n\nexport type UseNotificationsResult = {\n notifications?: Notification[];\n error?: NovuError;\n isLoading: boolean;\n isFetching: boolean;\n hasMore: boolean;\n readAll: () => Promise<{\n data?: void | undefined;\n error?: NovuError | undefined;\n }>;\n seenAll: () => Promise<{\n data?: void | undefined;\n error?: NovuError | undefined;\n }>;\n archiveAll: () => Promise<{\n data?: void | undefined;\n error?: NovuError | undefined;\n }>;\n archiveAllRead: () => Promise<{\n data?: void | undefined;\n error?: NovuError | undefined;\n }>;\n refetch: () => Promise<void>;\n fetchMore: () => Promise<void>;\n};\n\nexport const useNotifications = (props?: UseNotificationsProps): UseNotificationsResult => {\n const {\n tags,\n data: dataFilter,\n read,\n archived = false,\n snoozed = false,\n seen,\n severity,\n limit,\n onSuccess,\n onError,\n } = props || {};\n const filterRef = useRef<NotificationFilter | undefined>(undefined);\n const { notifications } = useNovu();\n\n const getCurrentFilter = useCallback(\n () => filterRef.current || { tags, data: dataFilter, severity },\n [tags, dataFilter, severity]\n );\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 useWebSocketEvent({\n event: 'notifications.unread_count_changed',\n eventHandler: () => {\n void refetch();\n },\n });\n\n useWebSocketEvent({\n event: 'notifications.unseen_count_changed',\n eventHandler: () => {\n void refetch();\n },\n });\n\n useWebSocketEvent({\n event: 'notifications.notification_received',\n eventHandler: ({ result: notification }) => {\n const currentFilter = getCurrentFilter();\n const matches = checkNotificationMatchesFilter(notification, currentFilter);\n if (matches) void refetch();\n },\n });\n\n const fetchNotifications = useCallback(\n async (options?: { refetch: boolean }) => {\n if (options?.refetch) {\n setError(undefined);\n setIsLoading(true);\n setIsFetching(false);\n }\n setIsFetching(true);\n\n const currentFilter = getCurrentFilter();\n\n const response = await notifications.list({\n ...currentFilter,\n limit,\n after: options?.refetch ? undefined : after,\n });\n\n if (response.error) {\n setError(response.error);\n onError?.(response.error);\n } else if (response.data) {\n onSuccess?.(response.data.notifications);\n setData(response.data.notifications);\n setHasMore(response.data.hasMore);\n }\n setIsLoading(false);\n setIsFetching(false);\n },\n [notifications, getCurrentFilter, limit, after, onError, onSuccess]\n );\n\n useEffect(() => {\n const newFilter = { tags, data: dataFilter, read, archived, snoozed, seen, severity };\n if (filterRef.current && isSameFilter(filterRef.current, newFilter)) {\n return;\n }\n notifications.clearCache({ filter: filterRef.current });\n filterRef.current = newFilter;\n\n fetchNotifications({ refetch: true });\n }, [tags, dataFilter, read, archived, snoozed, seen, notifications, fetchNotifications]);\n\n const refetch = () => {\n const filter = getCurrentFilter();\n notifications.clearCache({ filter });\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 const { tags, data } = getCurrentFilter();\n return await notifications.readAll({ tags, data });\n };\n\n const seenAll = async () => {\n const { tags, data } = getCurrentFilter();\n return await notifications.seenAll({ tags, data });\n };\n\n const archiveAll = async () => {\n const { tags, data } = getCurrentFilter();\n return await notifications.archiveAll({ tags, data });\n };\n\n const archiveAllRead = async () => {\n const { tags, data } = getCurrentFilter();\n return await notifications.archiveAllRead({ tags, data });\n };\n\n return {\n readAll,\n seenAll,\n archiveAll,\n archiveAllRead,\n not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Y;AAC5B,QAAI,CAAC,WAAW,WAAY;AAE5B,WAAO,mBAAmB;AAAA,EAC5B;AAEA,QAAM,UAAU,YAAY;AAC1B,UAAM,EAAE,MAAAA,OAAM,MAAAC,MAAK,IAAI,iBAAiB;AACxC,WAAO,MAAM,cAAc,QAAQ,EAAE,MAAAD,OAAM,MAAAC,MAAK,CAAC;AAAA,EACnD;AAEA,QAAM,UAAU,YAAY;AAC1B,UAAM,EAAE,MAAAD,OAAM,MAAAC,MAAK,IAAI,iBAAiB;AACxC,WAAO,MAAM,cAAc,QAAQ,EAAE,MAAAD,OAAM,MAAAC,MAAK,CAAC;AAAA,EACnD;AAEA,QAAM,aAAa,YAAY;AAC7B,UAAM,EAAE,MAAAD,OAAM,MAAAC,MAAK,IAAI,iBAAiB;AACxC,WAAO,MAAM,cAAc,WAAW,EAAE,MAAAD,OAAM,MAAAC,MAAK,CAAC;AAAA,EACtD;AAEA,QAAM,iBAAiB,YAAY;AACjC,UAAM,EAAE,MAAAD,OAAM,MAAAC,MAAK,IAAI,iBAAiB;AACxC,WAAO,MAAM,cAAc,eAAe,EAAE,MAAAD,OAAM,MAAAC,MAAK,CAAC;AAAA,EAC1D;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["tags","data"]}
1
+ {"version":3,"sources":["../../../src/hooks/useNotifications.ts"],"sourcesContent":["import { checkNotificationMatchesFilter, isSameFilter, Notification, NotificationFilter, NovuError } from '@novu/js';\nimport { useCallback, useEffect, useState } from 'react';\nimport { useDataRef } from './internal/useDataRef';\nimport { useWebSocketEvent } from './internal/useWebsocketEvent';\nimport { useNovu } from './NovuProvider';\n\n/**\n * Props for the useNotifications hook.\n *\n * @example\n * ```tsx\n * // Get unread notifications\n * const { notifications } = useNotifications({\n * read: false\n * });\n *\n * // Get unseen notifications with specific tags\n * const { notifications } = useNotifications({\n * seen: false,\n * tags: ['important']\n * });\n *\n * // Get notifications (auto-updates in real time when new notifications arrive)\n * const { notifications } = useNotifications({\n * read: false\n * });\n * ```\n */\nexport type UseNotificationsProps = {\n tags?: NotificationFilter['tags'];\n data?: NotificationFilter['data'];\n read?: NotificationFilter['read'];\n archived?: NotificationFilter['archived'];\n snoozed?: NotificationFilter['snoozed'];\n seen?: NotificationFilter['seen'];\n severity?: NotificationFilter['severity'];\n limit?: number;\n onSuccess?: (data: Notification[]) => void;\n onError?: (error: NovuError) => void;\n};\n\nexport type UseNotificationsResult = {\n notifications?: Notification[];\n error?: NovuError;\n isLoading: boolean;\n isFetching: boolean;\n hasMore: boolean;\n readAll: () => Promise<{\n data?: void | undefined;\n error?: NovuError | undefined;\n }>;\n seenAll: () => Promise<{\n data?: void | undefined;\n error?: NovuError | undefined;\n }>;\n archiveAll: () => Promise<{\n data?: void | undefined;\n error?: NovuError | undefined;\n }>;\n archiveAllRead: () => Promise<{\n data?: void | undefined;\n error?: NovuError | undefined;\n }>;\n refetch: () => Promise<void>;\n fetchMore: () => Promise<void>;\n};\n\nexport const useNotifications = (props?: UseNotificationsProps): UseNotificationsResult => {\n const {\n tags,\n data: dataFilter,\n read,\n archived = false,\n snoozed = false,\n seen,\n severity,\n limit = 10,\n onSuccess,\n onError,\n } = props || {};\n const limitRef = useDataRef<number | undefined>(limit);\n const filterRef = useDataRef<NotificationFilter>({ tags, data: dataFilter, read, archived, snoozed, seen, severity });\n const novu = 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 const afterRef = useDataRef<string | undefined>(after);\n\n useEffect(() => {\n const listener = ({\n data,\n }: {\n data: { notifications: Notification[]; hasMore: boolean; filter: NotificationFilter };\n }) => {\n if (!data || !isSameFilter(filterRef.current, data.filter)) {\n return;\n }\n\n // the event is called with the list of all notifications cached matching the current filter\n setData(data.notifications);\n setHasMore(data.hasMore);\n };\n\n const cleanup = novu.on('notifications.list.updated', listener);\n\n return () => {\n cleanup();\n };\n }, [filterRef, novu]);\n\n useWebSocketEvent({\n event: 'notifications.notification_received',\n eventHandler: ({ result: notification }) => {\n const currentFilter = filterRef.current;\n const matches = checkNotificationMatchesFilter(notification, currentFilter);\n if (matches) {\n // the limit and after props are used to create a cache key\n // the first batch of notifications in the cache doesn't include the after prop and we want to push to the first batch\n const cacheKey = { ...currentFilter, limit: limitRef.current };\n novu.notifications.cache.unshift(cacheKey, notification);\n }\n },\n });\n\n const fetchNotifications = useCallback(\n async (options?: { refetch: boolean }) => {\n if (options?.refetch) {\n setError(undefined);\n setIsLoading(true);\n setIsFetching(false);\n }\n setIsFetching(true);\n\n const response = await novu.notifications.list({\n ...filterRef.current,\n limit,\n after: options?.refetch ? undefined : afterRef.current,\n });\n\n if (response.error) {\n setError(response.error);\n onError?.(response.error);\n setIsLoading(false);\n setIsFetching(false);\n } else if (response.data) {\n const responseData = response.data;\n onSuccess?.(responseData.notifications);\n setData(responseData.notifications);\n setHasMore(responseData.hasMore);\n setIsLoading(false);\n setIsFetching(false);\n }\n },\n [novu, filterRef, afterRef, limit, onError, onSuccess]\n );\n\n useEffect(() => {\n novu.notifications.clearCache({ filter: filterRef.current });\n fetchNotifications({ refetch: true });\n }, [filterRef, novu, JSON.stringify(filterRef.current), fetchNotifications]);\n\n const refetch = useCallback(() => {\n novu.notifications.clearCache({ filter: filterRef.current });\n return fetchNotifications({ refetch: true });\n }, [filterRef, novu, fetchNotifications]);\n\n const fetchMore = useCallback(async () => {\n if (!hasMore || isFetching) return;\n\n return fetchNotifications();\n }, [hasMore, isFetching, fetchNotifications]);\n\n const readAll = useCallback(async () => {\n return await novu.notifications.readAll({ tags: filterRef.current.tags, data: filterRef.current.data });\n }, [filterRef, novu]);\n\n const seenAll = useCallback(async () => {\n return await novu.notifications.seenAll({ tags: filterRef.current.tags, data: filterRef.current.data });\n }, [filterRef, novu]);\n\n const archiveAll = useCallback(async () => {\n return await novu.notifications.archiveAll({ tags: filterRef.current.tags, data: filterRef.current.data });\n }, [filterRef, novu]);\n\n const archiveAllRead = useCallback(async () => {\n return await novu.notifications.archiveAllRead({ tags: filterRef.current.tags, data: filterRef.current.data });\n }, [filterRef, novu]);\n\n return {\n readAll,\n seenAll,\n archiveAll,\n archiveAllRead,\n notifications: data,\n error,\n isLoading,\n isFetching,\n refetch,\n fetchMore,\n hasMore,\n };\n};\n"],"mappings":";AAAA,SAAS,gCAAgC,oBAAiE;AAC1G,SAAS,aAAa,WAAW,gBAAgB;AACjD,SAAS,kBAAkB;AAC3B,SAAS,yBAAyB;AAClC,SAAS,eAAe;AA+DjB,IAAM,mBAAmB,CAAC,UAA0D;AACzF,QAAM;AAAA,IACJ;AAAA,IACA,MAAM;AAAA,IACN;AAAA,IACA,WAAW;AAAA,IACX,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,EACF,IAAI,SAAS,CAAC;AACd,QAAM,WAAW,WAA+B,KAAK;AACrD,QAAM,YAAY,WAA+B,EAAE,MAAM,MAAM,YAAY,MAAM,UAAU,SAAS,MAAM,SAAS,CAAC;AACpH,QAAM,OAAO,QAAQ;AACrB,QAAM,CAAC,MAAM,OAAO,IAAI,SAA8B;AACtD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAoB;AAC9C,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,IAAI;AAC/C,QAAM,CAAC,YAAY,aAAa,IAAI,SAAS,KAAK;AAClD,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,KAAK;AAC5C,QAAM,SAAS,MAAM;AACrB,QAAM,QAAQ,SAAS,KAAK,SAAS,CAAC,EAAE,KAAK;AAC7C,QAAM,WAAW,WAA+B,KAAK;AAErD,YAAU,MAAM;AACd,UAAM,WA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AAA,EAC/G,GAAG,CAAC,WAAW,IAAI,CAAC;AAEpB,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["data"]}
@@ -0,0 +1,17 @@
1
+ import { NovuError, DeleteSubscriptionArgs } from '@novu/js';
2
+
3
+ type UseRemoveSubscriptionProps = {
4
+ onSuccess?: () => void;
5
+ onError?: (error: NovuError) => void;
6
+ };
7
+ type RemoveResult = Promise<{
8
+ error?: NovuError;
9
+ }>;
10
+ type UseRemoveSubscriptionResult = {
11
+ isRemoving: boolean;
12
+ error?: NovuError;
13
+ remove: (args: DeleteSubscriptionArgs) => RemoveResult;
14
+ };
15
+ declare const useRemoveSubscription: (props?: UseRemoveSubscriptionProps) => UseRemoveSubscriptionResult;
16
+
17
+ export { type UseRemoveSubscriptionProps, type UseRemoveSubscriptionResult, useRemoveSubscription };
@@ -1,19 +1,19 @@
1
- // src/hooks/useDeleteSubscription.ts
1
+ // src/hooks/useRemoveSubscription.ts
2
2
  import { useCallback, useRef, useState } from "react";
3
3
  import { useNovu } from "./NovuProvider.js";
4
- var useDeleteSubscription = (props = {}) => {
4
+ var useRemoveSubscription = (props = {}) => {
5
5
  const propsRef = useRef(props);
6
6
  propsRef.current = props;
7
7
  const novu = useNovu();
8
- const [isDeleting, setIsDeleting] = useState(false);
8
+ const [isRemoving, setIsRemoving] = useState(false);
9
9
  const [error, setError] = useState();
10
- const deleteCallback = useCallback(
10
+ const removeCallback = useCallback(
11
11
  async (args) => {
12
12
  const { onSuccess, onError } = propsRef.current;
13
13
  setError(void 0);
14
- setIsDeleting(true);
14
+ setIsRemoving(true);
15
15
  const response = await novu.subscriptions.delete(args);
16
- setIsDeleting(false);
16
+ setIsRemoving(false);
17
17
  if (response.error) {
18
18
  setError(response.error);
19
19
  onError?.(response.error);
@@ -25,12 +25,12 @@ var useDeleteSubscription = (props = {}) => {
25
25
  [novu]
26
26
  );
27
27
  return {
28
- delete: deleteCallback,
29
- isDeleting,
28
+ remove: removeCallback,
29
+ isRemoving,
30
30
  error
31
31
  };
32
32
  };
33
33
  export {
34
- useDeleteSubscription
34
+ useRemoveSubscription
35
35
  };
36
- //# sourceMappingURL=useDeleteSubscription.js.map
36
+ //# sourceMappingURL=useRemoveSubscription.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/hooks/useRemoveSubscription.ts"],"sourcesContent":["import { BaseDeleteSubscriptionArgs, NovuError, DeleteSubscriptionArgs as RemoveSubscriptionArgs } from '@novu/js';\nimport { useCallback, useRef, useState } from 'react';\nimport { useNovu } from './NovuProvider';\n\nexport type UseRemoveSubscriptionProps = {\n onSuccess?: () => void;\n onError?: (error: NovuError) => void;\n};\n\ntype RemoveResult = Promise<{\n error?: NovuError;\n}>;\n\nexport type UseRemoveSubscriptionResult = {\n isRemoving: boolean;\n error?: NovuError;\n remove: (args: RemoveSubscriptionArgs) => RemoveResult;\n};\n\nexport const useRemoveSubscription = (props: UseRemoveSubscriptionProps = {}): UseRemoveSubscriptionResult => {\n const propsRef = useRef<UseRemoveSubscriptionProps>(props);\n propsRef.current = props;\n const novu = useNovu();\n const [isRemoving, setIsRemoving] = useState(false);\n const [error, setError] = useState<NovuError>();\n\n const removeCallback = useCallback(\n async (args: RemoveSubscriptionArgs): RemoveResult => {\n const { onSuccess, onError } = propsRef.current;\n setError(undefined);\n setIsRemoving(true);\n\n const response = await novu.subscriptions.delete(args as BaseDeleteSubscriptionArgs);\n\n setIsRemoving(false);\n\n if (response.error) {\n setError(response.error);\n onError?.(response.error);\n } else if (response.data) {\n onSuccess?.();\n }\n\n return response;\n },\n [novu]\n );\n\n return {\n remove: removeCallback,\n isRemoving,\n error,\n };\n};\n"],"mappings":";AACA,SAAS,aAAa,QAAQ,gBAAgB;AAC9C,SAAS,eAAe;AAiBjB,IAAM,wBAAwB,CAAC,QAAoC,CAAC,MAAmC;AAC5G,QAAM,WAAW,OAAmC,KAAK;AACzD,WAAS,UAAU;AACnB,QAAM,OAAO,QAAQ;AACrB,QAAM,CAAC,YAAY,aAAa,IAAI,SAAS,KAAK;AAClD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAoB;AAE9C,QAAM,iBAAiB;AAAA,IACrB,OAAO,SAA+C;AACpD,YAAM,EAAE,WAAW,QAAQ,IAAI,SAAS;AACxC,eAAS,MAAS;AAClB,oBAAc,IAAI;AAElB,YAAM,WAAW,MAAM,KAAK,cAAc,OAAO,IAAkC;AAEnF,oBAAc,KAAK;AAEnB,UAAI,SAAS,OAAO;AAClB,iBAAS,SAAS,KAAK;AACvB,kBAAU,SAAS,KAAK;AAAA,MAC1B,WAAW,SAAS,MAAM;AACxB,oBAAY;AAAA,MACd;AAEA,aAAO;AAAA,IACT;AAAA,IACA,CAAC,IAAI;AAAA,EACP;AAEA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -12,9 +12,9 @@ export { SubscriptionButton, SubscriptionButtonProps } from './components/subscr
12
12
  export { SubscriptionPreferences, SubscriptionPreferencesProps } from './components/subscription/SubscriptionPreferences.js';
13
13
  export { UseCountsProps, UseCountsResult, useCounts } from './hooks/useCounts.js';
14
14
  export { useCreateSubscription } from './hooks/useCreateSubscription.js';
15
- export { useDeleteSubscription } from './hooks/useDeleteSubscription.js';
16
15
  export { UseNotificationsProps, UseNotificationsResult, useNotifications } from './hooks/useNotifications.js';
17
16
  export { UsePreferencesResult, usePreferences } from './hooks/usePreferences.js';
17
+ export { useRemoveSubscription } from './hooks/useRemoveSubscription.js';
18
18
  export { UseScheduleProps as UsePreferencesProps, useSchedule } from './hooks/useSchedule.js';
19
19
  export { useSubscription } from './hooks/useSubscription.js';
20
20
  export { useSubscriptions } from './hooks/useSubscriptions.js';
package/dist/esm/index.js CHANGED
@@ -14,10 +14,10 @@ import {
14
14
  import {
15
15
  useCounts,
16
16
  useCreateSubscription,
17
- useDeleteSubscription,
18
17
  useNotifications,
19
18
  useNovu,
20
19
  usePreferences,
20
+ useRemoveSubscription,
21
21
  useSchedule,
22
22
  useSubscription,
23
23
  useSubscriptions,
@@ -38,10 +38,10 @@ export {
38
38
  WorkflowCriticalityEnum,
39
39
  useCounts,
40
40
  useCreateSubscription,
41
- useDeleteSubscription,
42
41
  useNotifications,
43
42
  useNovu,
44
43
  usePreferences,
44
+ useRemoveSubscription,
45
45
  useSchedule,
46
46
  useSubscription,
47
47
  useSubscriptions,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export type * from '@novu/js';\nexport { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from '@novu/js';\n\nexport type {\n AllLocalization,\n AllLocalizationKey,\n ElementStyles,\n InboxAppearance,\n InboxAppearanceCallback,\n InboxAppearanceCallbackFunction,\n InboxAppearanceCallbackKeys,\n InboxAppearanceKey,\n InboxElements,\n InboxLocalization,\n InboxLocalizationKey,\n InboxTheme,\n NotificationActionClickHandler,\n NotificationClickHandler,\n NotificationRenderer,\n PreferenceGroups,\n PreferencesFilter,\n RouterPush,\n SubscriptionAppearance,\n SubscriptionAppearanceCallback,\n SubscriptionAppearanceCallbackFunction,\n SubscriptionAppearanceCallbackKeys,\n SubscriptionAppearanceKey,\n SubscriptionElements,\n SubscriptionLocalization,\n SubscriptionLocalizationKey,\n SubscriptionTheme,\n Tab,\n Variables,\n} from '@novu/js/ui';\nexport type {\n BellProps,\n InboxContentProps,\n InboxProps,\n NotificationProps,\n NovuProviderProps,\n SubscriptionButtonProps,\n SubscriptionPreferencesProps,\n SubscriptionProps,\n} from './components';\nexport {\n Bell,\n Inbox,\n InboxContent,\n Notifications,\n NovuProvider,\n Preferences,\n Subscription,\n SubscriptionButton,\n SubscriptionPreferences,\n} from './components';\nexport type {\n UseCountsProps,\n UseCountsResult,\n UseNotificationsProps,\n UseNotificationsResult,\n UsePreferencesResult,\n UseScheduleProps as UsePreferencesProps,\n} from './hooks';\nexport {\n useCounts,\n useCreateSubscription,\n useDeleteSubscription,\n useNotifications,\n useNovu,\n usePreferences,\n useSchedule,\n useSubscription,\n useSubscriptions,\n useUpdateSubscription,\n} from './hooks';\n\nexport type {\n BaseProps,\n BellRenderer,\n BodyRenderer,\n DefaultInboxProps,\n DefaultProps,\n NoRendererProps,\n NotificationRendererProps,\n NotificationsRenderer,\n ReactInboxAppearance,\n ReactInboxTheme,\n ReactSubscriptionAppearance,\n ReactSubscriptionTheme,\n SubjectBodyRendererProps,\n SubjectRenderer,\n WithChildrenProps,\n} from './utils/types';\n"],"mappings":";AACA,SAAS,iBAAiB,mBAAmB,+BAA+B;AA2C5E;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AASP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export type * from '@novu/js';\nexport { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from '@novu/js';\n\nexport type {\n AllLocalization,\n AllLocalizationKey,\n ElementStyles,\n InboxAppearance,\n InboxAppearanceCallback,\n InboxAppearanceCallbackFunction,\n InboxAppearanceCallbackKeys,\n InboxAppearanceKey,\n InboxElements,\n InboxLocalization,\n InboxLocalizationKey,\n InboxTheme,\n NotificationActionClickHandler,\n NotificationClickHandler,\n NotificationRenderer,\n PreferenceGroups,\n PreferencesFilter,\n RouterPush,\n SubscriptionAppearance,\n SubscriptionAppearanceCallback,\n SubscriptionAppearanceCallbackFunction,\n SubscriptionAppearanceCallbackKeys,\n SubscriptionAppearanceKey,\n SubscriptionElements,\n SubscriptionLocalization,\n SubscriptionLocalizationKey,\n SubscriptionTheme,\n Tab,\n Variables,\n} from '@novu/js/ui';\nexport type {\n BellProps,\n InboxContentProps,\n InboxProps,\n NotificationProps,\n NovuProviderProps,\n SubscriptionButtonProps,\n SubscriptionPreferencesProps,\n SubscriptionProps,\n} from './components';\nexport {\n Bell,\n Inbox,\n InboxContent,\n Notifications,\n NovuProvider,\n Preferences,\n Subscription,\n SubscriptionButton,\n SubscriptionPreferences,\n} from './components';\nexport type {\n UseCountsProps,\n UseCountsResult,\n UseNotificationsProps,\n UseNotificationsResult,\n UsePreferencesResult,\n UseScheduleProps as UsePreferencesProps,\n} from './hooks';\nexport {\n useCounts,\n useCreateSubscription,\n useNotifications,\n useNovu,\n usePreferences,\n useRemoveSubscription,\n useSchedule,\n useSubscription,\n useSubscriptions,\n useUpdateSubscription,\n} from './hooks';\n\nexport type {\n BaseProps,\n BellRenderer,\n BodyRenderer,\n DefaultInboxProps,\n DefaultProps,\n NoRendererProps,\n NotificationRendererProps,\n NotificationsRenderer,\n ReactInboxAppearance,\n ReactInboxTheme,\n ReactSubscriptionAppearance,\n ReactSubscriptionTheme,\n SubjectBodyRendererProps,\n SubjectRenderer,\n WithChildrenProps,\n} from './utils/types';\n"],"mappings":";AACA,SAAS,iBAAiB,mBAAmB,+BAA+B;AA2C5E;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AASP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
@@ -5,9 +5,9 @@ export { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from '@no
5
5
  import { NovuProviderProps } from '../hooks/NovuProvider.js';
6
6
  import { UseCountsProps, UseCountsResult } from '../hooks/useCounts.js';
7
7
  import { UseCreateSubscriptionProps, UseCreateSubscriptionResult } from '../hooks/useCreateSubscription.js';
8
- import { UseDeleteSubscriptionProps, UseDeleteSubscriptionResult } from '../hooks/useDeleteSubscription.js';
9
8
  import { UseNotificationsProps, UseNotificationsResult } from '../hooks/useNotifications.js';
10
9
  import { UsePreferencesProps, UsePreferencesResult } from '../hooks/usePreferences.js';
10
+ import { UseRemoveSubscriptionProps, UseRemoveSubscriptionResult } from '../hooks/useRemoveSubscription.js';
11
11
  import { UseScheduleProps, UseScheduleResult } from '../hooks/useSchedule.js';
12
12
  import { UseSubscriptionProps, UseSubscriptionResult } from '../hooks/useSubscription.js';
13
13
  import { UseSubscriptionsProps, UseSubscriptionsResult } from '../hooks/useSubscriptions.js';
@@ -42,7 +42,7 @@ declare function useSchedule(_: UseScheduleProps): UseScheduleResult;
42
42
  declare function useSubscription(_: UseSubscriptionProps): UseSubscriptionResult;
43
43
  declare function useCreateSubscription(_?: UseCreateSubscriptionProps): UseCreateSubscriptionResult;
44
44
  declare function useUpdateSubscription(_?: UseUpdateSubscriptionProps): UseUpdateSubscriptionResult;
45
- declare function useDeleteSubscription(_?: UseDeleteSubscriptionProps): UseDeleteSubscriptionResult;
45
+ declare function useRemoveSubscription(_?: UseRemoveSubscriptionProps): UseRemoveSubscriptionResult;
46
46
  declare function useSubscriptions(_: UseSubscriptionsProps): UseSubscriptionsResult;
47
47
 
48
- export { Bell, Inbox, InboxContent, InboxProps, Notifications, NovuProvider, NovuProviderProps, Preferences, Subscription, SubscriptionButton, SubscriptionPreferences, UseCountsProps, UseCountsResult, UseNotificationsProps, UseNotificationsResult, UseScheduleProps as UsePreferencesProps, UsePreferencesResult, useCounts, useCreateSubscription, useDeleteSubscription, useNotifications, useNovu, usePreferences, useSchedule, useSubscription, useSubscriptions, useUpdateSubscription };
48
+ export { Bell, Inbox, InboxContent, InboxProps, Notifications, NovuProvider, NovuProviderProps, Preferences, Subscription, SubscriptionButton, SubscriptionPreferences, UseCountsProps, UseCountsResult, UseNotificationsProps, UseNotificationsResult, UseScheduleProps as UsePreferencesProps, UsePreferencesResult, useCounts, useCreateSubscription, useNotifications, useNovu, usePreferences, useRemoveSubscription, useSchedule, useSubscription, useSubscriptions, useUpdateSubscription };
@@ -81,11 +81,11 @@ function useUpdateSubscription(_ = {}) {
81
81
  update: () => Promise.resolve({ data: void 0, error: void 0 })
82
82
  };
83
83
  }
84
- function useDeleteSubscription(_ = {}) {
84
+ function useRemoveSubscription(_ = {}) {
85
85
  return {
86
- isDeleting: false,
86
+ isRemoving: false,
87
87
  error: void 0,
88
- delete: () => Promise.resolve({ data: void 0, error: void 0 })
88
+ remove: () => Promise.resolve({ data: void 0, error: void 0 })
89
89
  };
90
90
  }
91
91
  function useSubscriptions(_) {
@@ -110,10 +110,10 @@ export {
110
110
  WorkflowCriticalityEnum,
111
111
  useCounts,
112
112
  useCreateSubscription,
113
- useDeleteSubscription,
114
113
  useNotifications,
115
114
  useNovu,
116
115
  usePreferences,
116
+ useRemoveSubscription,
117
117
  useSchedule,
118
118
  useSubscription,
119
119
  useSubscriptions,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/index.tsx"],"sourcesContent":["import type { InboxProps } from '../components/Inbox';\nimport { ShadowRootDetector } from '../components/ShadowRootDetector';\nimport type {\n UseCreateSubscriptionProps,\n UseCreateSubscriptionResult,\n UseDeleteSubscriptionProps,\n UseDeleteSubscriptionResult,\n UseNotificationsProps,\n UseNotificationsResult,\n UsePreferencesProps,\n UsePreferencesResult,\n UseScheduleProps,\n UseScheduleResult,\n UseSubscriptionProps,\n UseSubscriptionResult,\n UseSubscriptionsProps,\n UseSubscriptionsResult,\n UseUpdateSubscriptionProps,\n UseUpdateSubscriptionResult,\n} from '../hooks';\nimport type { NovuProviderProps } from '../hooks/NovuProvider';\nimport type { UseCountsProps, UseCountsResult } from '../hooks/useCounts';\n\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(props: InboxProps) {\n return <ShadowRootDetector />;\n}\n\nexport function InboxContent() {}\n\nexport function Notifications() {}\n\nexport function Preferences() {}\n\nexport function Bell() {}\n\nexport function NovuProvider(props: NovuProviderProps) {\n return <>{props.children}</>;\n}\n\nexport function Subscription() {\n return <ShadowRootDetector />;\n}\n\nexport function SubscriptionButton() {}\n\nexport function SubscriptionPreferences() {}\n\nexport function useNovu() {\n return null;\n}\n\nexport function useCounts(_: UseCountsProps): UseCountsResult {\n return {\n isLoading: false,\n isFetching: false,\n refetch: () => Promise.resolve(),\n };\n}\n\nexport function useNotifications(_: UseNotificationsProps): UseNotificationsResult {\n return {\n isLoading: false,\n isFetching: false,\n hasMore: false,\n readAll: () => Promise.resolve({ data: undefined, error: undefined }),\n seenAll: () => Promise.resolve({ data: undefined, error: undefined }),\n archiveAll: () => Promise.resolve({ data: undefined, error: undefined }),\n archiveAllRead: () => Promise.resolve({ data: undefined, error: undefined }),\n refetch: () => Promise.resolve(),\n fetchMore: () => Promise.resolve(),\n };\n}\n\nexport function usePreferences(_: UsePreferencesProps): UsePreferencesResult {\n return {\n isLoading: false,\n isFetching: false,\n refetch: () => Promise.resolve(),\n };\n}\n\nexport function useSchedule(_: UseScheduleProps): UseScheduleResult {\n return {\n isLoading: false,\n isFetching: false,\n refetch: () => Promise.resolve(),\n };\n}\n\nexport function useSubscription(_: UseSubscriptionProps): UseSubscriptionResult {\n return {\n isLoading: false,\n isFetching: false,\n refetch: () => Promise.resolve(),\n };\n}\n\nexport function useCreateSubscription(_: UseCreateSubscriptionProps = {}): UseCreateSubscriptionResult {\n return {\n isCreating: false,\n error: undefined,\n create: () => Promise.resolve({ data: undefined, error: undefined }),\n };\n}\n\nexport function useUpdateSubscription(_: UseUpdateSubscriptionProps = {}): UseUpdateSubscriptionResult {\n return {\n isUpdating: false,\n error: undefined,\n update: () => Promise.resolve({ data: undefined, error: undefined }),\n };\n}\n\nexport function useDeleteSubscription(_: UseDeleteSubscriptionProps = {}): UseDeleteSubscriptionResult {\n return {\n isDeleting: false,\n error: undefined,\n delete: () => Promise.resolve({ data: undefined, error: undefined }),\n };\n}\n\nexport function useSubscriptions(_: UseSubscriptionsProps): UseSubscriptionsResult {\n return {\n isLoading: false,\n isFetching: false,\n refetch: () => Promise.resolve(),\n };\n}\n\nexport type * from '@novu/js';\nexport { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from '@novu/js';\n\nexport type {\n AllLocalization,\n AllLocalizationKey,\n ElementStyles,\n InboxAppearance,\n InboxAppearanceCallback,\n InboxAppearanceCallbackFunction,\n InboxAppearanceCallbackKeys,\n InboxAppearanceKey,\n InboxElements,\n InboxLocalization,\n InboxLocalizationKey,\n InboxTheme,\n NotificationActionClickHandler,\n NotificationClickHandler,\n NotificationRenderer,\n PreferenceGroups,\n PreferencesFilter,\n RouterPush,\n SubscriptionAppearance,\n SubscriptionAppearanceCallback,\n SubscriptionAppearanceCallbackFunction,\n SubscriptionAppearanceCallbackKeys,\n SubscriptionAppearanceKey,\n SubscriptionElements,\n SubscriptionLocalization,\n SubscriptionLocalizationKey,\n SubscriptionTheme,\n Tab,\n Variables,\n} from '@novu/js/ui';\n\nexport type { BellProps, InboxContentProps, InboxProps, NotificationProps, NovuProviderProps } from '../components';\n\nexport type {\n UseCountsProps,\n UseCountsResult,\n UseNotificationsProps,\n UseNotificationsResult,\n UsePreferencesResult,\n UseScheduleProps as UsePreferencesProps,\n} from '../hooks';\n\nexport type {\n BaseProps,\n BellRenderer,\n BodyRenderer,\n DefaultInboxProps,\n DefaultProps,\n NoRendererProps,\n NotificationRendererProps,\n NotificationsRenderer,\n SubjectBodyRendererProps,\n SubjectRenderer,\n WithChildrenProps,\n} from '../utils/types';\n"],"mappings":";AACA,SAAS,0BAA0B;AAuInC,SAAS,iBAAiB,mBAAmB,+BAA+B;AA1GnE,SAYA,UAZA;AADF,SAAS,MAAM,OAAmB;AACvC,SAAO,oBAAC,sBAAmB;AAC7B;AAEO,SAAS,eAAe;AAAC;AAEzB,SAAS,gBAAgB;AAAC;AAE1B,S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;AAAA,EACjC;AACF;AAEO,SAAS,sBAAsB,IAAgC,CAAC,GAAgC;AACrG,SAAO;AAAA,IACL,YAAY;AAAA,IACZ,OAAO;AAAA,IACP,QAAQ,MAAM,QAAQ,QAAQ,EAAE,MAAM,QAAW,OAAO,OAAU,CAAC;AAAA,EACrE;AACF;AAEO,SAAS,sBAAsB,IAAgC,CAAC,GAAgC;AACrG,SAAO;AAAA,IACL,YAAY;AAAA,IACZ,OAAO;AAAA,IACP,QAAQ,MAAM,QAAQ,QAAQ,EAAE,MAAM,QAAW,OAAO,OAAU,CAAC;AAAA,EACrE;AACF;AAEO,SAAS,sBAAsB,IAAgC,CAAC,GAAgC;AACrG,SAAO;AAAA,IACL,YAAY;AAAA,IACZ,OAAO;AAAA,IACP,QAAQ,MAAM,QAAQ,QAAQ,EAAE,MAAM,QAAW,OAAO,OAAU,CAAC;AAAA,EACrE;AACF;AAEO,SAAS,iBAAiB,GAAkD;AACjF,SAAO;AAAA,IACL,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,SAAS,MAAM,QAAQ,QAAQ;AAAA,EACjC;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/server/index.tsx"],"sourcesContent":["import type { InboxProps } from '../components/Inbox';\nimport { ShadowRootDetector } from '../components/ShadowRootDetector';\nimport type {\n UseCreateSubscriptionProps,\n UseCreateSubscriptionResult,\n UseNotificationsProps,\n UseNotificationsResult,\n UsePreferencesProps,\n UsePreferencesResult,\n UseRemoveSubscriptionProps,\n UseRemoveSubscriptionResult,\n UseScheduleProps,\n UseScheduleResult,\n UseSubscriptionProps,\n UseSubscriptionResult,\n UseSubscriptionsProps,\n UseSubscriptionsResult,\n UseUpdateSubscriptionProps,\n UseUpdateSubscriptionResult,\n} from '../hooks';\nimport type { NovuProviderProps } from '../hooks/NovuProvider';\nimport type { UseCountsProps, UseCountsResult } from '../hooks/useCounts';\n\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(props: InboxProps) {\n return <ShadowRootDetector />;\n}\n\nexport function InboxContent() {}\n\nexport function Notifications() {}\n\nexport function Preferences() {}\n\nexport function Bell() {}\n\nexport function NovuProvider(props: NovuProviderProps) {\n return <>{props.children}</>;\n}\n\nexport function Subscription() {\n return <ShadowRootDetector />;\n}\n\nexport function SubscriptionButton() {}\n\nexport function SubscriptionPreferences() {}\n\nexport function useNovu() {\n return null;\n}\n\nexport function useCounts(_: UseCountsProps): UseCountsResult {\n return {\n isLoading: false,\n isFetching: false,\n refetch: () => Promise.resolve(),\n };\n}\n\nexport function useNotifications(_: UseNotificationsProps): UseNotificationsResult {\n return {\n isLoading: false,\n isFetching: false,\n hasMore: false,\n readAll: () => Promise.resolve({ data: undefined, error: undefined }),\n seenAll: () => Promise.resolve({ data: undefined, error: undefined }),\n archiveAll: () => Promise.resolve({ data: undefined, error: undefined }),\n archiveAllRead: () => Promise.resolve({ data: undefined, error: undefined }),\n refetch: () => Promise.resolve(),\n fetchMore: () => Promise.resolve(),\n };\n}\n\nexport function usePreferences(_: UsePreferencesProps): UsePreferencesResult {\n return {\n isLoading: false,\n isFetching: false,\n refetch: () => Promise.resolve(),\n };\n}\n\nexport function useSchedule(_: UseScheduleProps): UseScheduleResult {\n return {\n isLoading: false,\n isFetching: false,\n refetch: () => Promise.resolve(),\n };\n}\n\nexport function useSubscription(_: UseSubscriptionProps): UseSubscriptionResult {\n return {\n isLoading: false,\n isFetching: false,\n refetch: () => Promise.resolve(),\n };\n}\n\nexport function useCreateSubscription(_: UseCreateSubscriptionProps = {}): UseCreateSubscriptionResult {\n return {\n isCreating: false,\n error: undefined,\n create: () => Promise.resolve({ data: undefined, error: undefined }),\n };\n}\n\nexport function useUpdateSubscription(_: UseUpdateSubscriptionProps = {}): UseUpdateSubscriptionResult {\n return {\n isUpdating: false,\n error: undefined,\n update: () => Promise.resolve({ data: undefined, error: undefined }),\n };\n}\n\nexport function useRemoveSubscription(_: UseRemoveSubscriptionProps = {}): UseRemoveSubscriptionResult {\n return {\n isRemoving: false,\n error: undefined,\n remove: () => Promise.resolve({ data: undefined, error: undefined }),\n };\n}\n\nexport function useSubscriptions(_: UseSubscriptionsProps): UseSubscriptionsResult {\n return {\n isLoading: false,\n isFetching: false,\n refetch: () => Promise.resolve(),\n };\n}\n\nexport type * from '@novu/js';\nexport { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from '@novu/js';\n\nexport type {\n AllLocalization,\n AllLocalizationKey,\n ElementStyles,\n InboxAppearance,\n InboxAppearanceCallback,\n InboxAppearanceCallbackFunction,\n InboxAppearanceCallbackKeys,\n InboxAppearanceKey,\n InboxElements,\n InboxLocalization,\n InboxLocalizationKey,\n InboxTheme,\n NotificationActionClickHandler,\n NotificationClickHandler,\n NotificationRenderer,\n PreferenceGroups,\n PreferencesFilter,\n RouterPush,\n SubscriptionAppearance,\n SubscriptionAppearanceCallback,\n SubscriptionAppearanceCallbackFunction,\n SubscriptionAppearanceCallbackKeys,\n SubscriptionAppearanceKey,\n SubscriptionElements,\n SubscriptionLocalization,\n SubscriptionLocalizationKey,\n SubscriptionTheme,\n Tab,\n Variables,\n} from '@novu/js/ui';\n\nexport type { BellProps, InboxContentProps, InboxProps, NotificationProps, NovuProviderProps } from '../components';\n\nexport type {\n UseCountsProps,\n UseCountsResult,\n UseNotificationsProps,\n UseNotificationsResult,\n UsePreferencesResult,\n UseScheduleProps as UsePreferencesProps,\n} from '../hooks';\n\nexport type {\n BaseProps,\n BellRenderer,\n BodyRenderer,\n DefaultInboxProps,\n DefaultProps,\n NoRendererProps,\n NotificationRendererProps,\n NotificationsRenderer,\n SubjectBodyRendererProps,\n SubjectRenderer,\n WithChildrenProps,\n} from '../utils/types';\n"],"mappings":";AACA,SAAS,0BAA0B;AAuInC,SAAS,iBAAiB,mBAAmB,+BAA+B;AA1GnE,SAYA,UAZA;AADF,SAAS,MAAM,OAAmB;AACvC,SAAO,oBAAC,sBAAmB;AAC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