@novu/react 3.11.0 → 3.11.2-nightly.20251224.eb609546a3

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 (109) hide show
  1. package/README.md +10 -18
  2. package/dist/cjs/components/Inbox.cjs +5 -1
  3. package/dist/cjs/components/Inbox.cjs.map +1 -1
  4. package/dist/cjs/components/NovuUI.cjs +3 -1
  5. package/dist/cjs/components/NovuUI.cjs.map +1 -1
  6. package/dist/cjs/components/NovuUI.d.cts +9 -9
  7. package/dist/cjs/components/index.cjs +7 -1
  8. package/dist/cjs/components/index.cjs.map +1 -1
  9. package/dist/cjs/components/index.d.cts +5 -0
  10. package/dist/cjs/components/subscription/DefaultSubscription.cjs +59 -0
  11. package/dist/cjs/components/subscription/DefaultSubscription.cjs.map +1 -0
  12. package/dist/cjs/components/subscription/DefaultSubscription.d.cts +11 -0
  13. package/dist/cjs/components/subscription/Subscription.cjs +80 -0
  14. package/dist/cjs/components/subscription/Subscription.cjs.map +1 -0
  15. package/dist/cjs/components/subscription/Subscription.d.cts +22 -0
  16. package/dist/cjs/components/subscription/SubscriptionButton.cjs +91 -0
  17. package/dist/cjs/components/subscription/SubscriptionButton.cjs.map +1 -0
  18. package/dist/cjs/components/subscription/SubscriptionButton.d.cts +8 -0
  19. package/dist/cjs/components/subscription/SubscriptionPreferences.cjs +91 -0
  20. package/dist/cjs/components/subscription/SubscriptionPreferences.cjs.map +1 -0
  21. package/dist/cjs/components/subscription/SubscriptionPreferences.d.cts +8 -0
  22. package/dist/cjs/hooks/NovuProvider.cjs +21 -18
  23. package/dist/cjs/hooks/NovuProvider.cjs.map +1 -1
  24. package/dist/cjs/hooks/index.cjs +11 -1
  25. package/dist/cjs/hooks/index.cjs.map +1 -1
  26. package/dist/cjs/hooks/index.d.cts +7 -1
  27. package/dist/cjs/hooks/useCounts.cjs +2 -2
  28. package/dist/cjs/hooks/useCounts.cjs.map +1 -1
  29. package/dist/cjs/hooks/useCreateSubscription.cjs +61 -0
  30. package/dist/cjs/hooks/useCreateSubscription.cjs.map +1 -0
  31. package/dist/cjs/hooks/useCreateSubscription.d.cts +17 -0
  32. package/dist/cjs/hooks/useNotifications.cjs +57 -60
  33. package/dist/cjs/hooks/useNotifications.cjs.map +1 -1
  34. package/dist/cjs/hooks/useRemoveSubscription.cjs +61 -0
  35. package/dist/cjs/hooks/useRemoveSubscription.cjs.map +1 -0
  36. package/dist/cjs/hooks/useRemoveSubscription.d.cts +17 -0
  37. package/dist/cjs/hooks/useSubscription.cjs +156 -0
  38. package/dist/cjs/hooks/useSubscription.cjs.map +1 -0
  39. package/dist/cjs/hooks/useSubscription.d.cts +21 -0
  40. package/dist/cjs/hooks/useSubscriptions.cjs +121 -0
  41. package/dist/cjs/hooks/useSubscriptions.cjs.map +1 -0
  42. package/dist/cjs/hooks/useSubscriptions.d.cts +36 -0
  43. package/dist/cjs/hooks/useUpdateSubscription.cjs +61 -0
  44. package/dist/cjs/hooks/useUpdateSubscription.cjs.map +1 -0
  45. package/dist/cjs/hooks/useUpdateSubscription.d.cts +18 -0
  46. package/dist/cjs/index.cjs +18 -2
  47. package/dist/cjs/index.cjs.map +1 -1
  48. package/dist/cjs/index.d.cts +14 -3
  49. package/dist/cjs/server/index.cjs +61 -2
  50. package/dist/cjs/server/index.cjs.map +1 -1
  51. package/dist/cjs/server/index.d.cts +18 -4
  52. package/dist/cjs/utils/appearance.cjs.map +1 -1
  53. package/dist/cjs/utils/appearance.d.cts +3 -3
  54. package/dist/cjs/utils/types.cjs.map +1 -1
  55. package/dist/cjs/utils/types.d.cts +32 -11
  56. package/dist/esm/components/Inbox.js +5 -1
  57. package/dist/esm/components/Inbox.js.map +1 -1
  58. package/dist/esm/components/NovuUI.d.ts +9 -9
  59. package/dist/esm/components/NovuUI.js +3 -1
  60. package/dist/esm/components/NovuUI.js.map +1 -1
  61. package/dist/esm/components/index.d.ts +5 -0
  62. package/dist/esm/components/index.js +3 -0
  63. package/dist/esm/components/index.js.map +1 -1
  64. package/dist/esm/components/subscription/DefaultSubscription.d.ts +11 -0
  65. package/dist/esm/components/subscription/DefaultSubscription.js +34 -0
  66. package/dist/esm/components/subscription/DefaultSubscription.js.map +1 -0
  67. package/dist/esm/components/subscription/Subscription.d.ts +22 -0
  68. package/dist/esm/components/subscription/Subscription.js +45 -0
  69. package/dist/esm/components/subscription/Subscription.js.map +1 -0
  70. package/dist/esm/components/subscription/SubscriptionButton.d.ts +8 -0
  71. package/dist/esm/components/subscription/SubscriptionButton.js +56 -0
  72. package/dist/esm/components/subscription/SubscriptionButton.js.map +1 -0
  73. package/dist/esm/components/subscription/SubscriptionPreferences.d.ts +8 -0
  74. package/dist/esm/components/subscription/SubscriptionPreferences.js +56 -0
  75. package/dist/esm/components/subscription/SubscriptionPreferences.js.map +1 -0
  76. package/dist/esm/hooks/NovuProvider.js +22 -19
  77. package/dist/esm/hooks/NovuProvider.js.map +1 -1
  78. package/dist/esm/hooks/index.d.ts +7 -1
  79. package/dist/esm/hooks/index.js +5 -0
  80. package/dist/esm/hooks/index.js.map +1 -1
  81. package/dist/esm/hooks/useCounts.js +3 -3
  82. package/dist/esm/hooks/useCounts.js.map +1 -1
  83. package/dist/esm/hooks/useCreateSubscription.d.ts +17 -0
  84. package/dist/esm/hooks/useCreateSubscription.js +36 -0
  85. package/dist/esm/hooks/useCreateSubscription.js.map +1 -0
  86. package/dist/esm/hooks/useNotifications.js +58 -61
  87. package/dist/esm/hooks/useNotifications.js.map +1 -1
  88. package/dist/esm/hooks/useRemoveSubscription.d.ts +17 -0
  89. package/dist/esm/hooks/useRemoveSubscription.js +36 -0
  90. package/dist/esm/hooks/useRemoveSubscription.js.map +1 -0
  91. package/dist/esm/hooks/useSubscription.d.ts +21 -0
  92. package/dist/esm/hooks/useSubscription.js +129 -0
  93. package/dist/esm/hooks/useSubscription.js.map +1 -0
  94. package/dist/esm/hooks/useSubscriptions.d.ts +36 -0
  95. package/dist/esm/hooks/useSubscriptions.js +96 -0
  96. package/dist/esm/hooks/useSubscriptions.js.map +1 -0
  97. package/dist/esm/hooks/useUpdateSubscription.d.ts +18 -0
  98. package/dist/esm/hooks/useUpdateSubscription.js +36 -0
  99. package/dist/esm/hooks/useUpdateSubscription.js.map +1 -0
  100. package/dist/esm/index.d.ts +14 -3
  101. package/dist/esm/index.js +32 -3
  102. package/dist/esm/index.js.map +1 -1
  103. package/dist/esm/server/index.d.ts +18 -4
  104. package/dist/esm/server/index.js +53 -2
  105. package/dist/esm/server/index.js.map +1 -1
  106. package/dist/esm/utils/appearance.d.ts +3 -3
  107. package/dist/esm/utils/appearance.js.map +1 -1
  108. package/dist/esm/utils/types.d.ts +32 -11
  109. package/package.json +11 -11
@@ -0,0 +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) {\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAClB,2BAA0B;AAC1B,qBAAwB;AAmDb;AA/CJ,IAAM,0BAA0B,aAAAA,QAAM;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,QAAI,gCAAU;AAE7B,UAAM,QAAQ,aAAAA,QAAM;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,4CAAC,0BAAQ,OAAc;AAAA,EAChC;AACF;","names":["React"]}
@@ -0,0 +1,8 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { SubscriptionPreferencesWrapperProps } from '@novu/js/ui';
3
+ import React__default from 'react';
4
+
5
+ type SubscriptionPreferencesProps = Partial<SubscriptionPreferencesWrapperProps>;
6
+ declare const SubscriptionPreferences: React__default.MemoExoticComponent<({ topicKey, identifier, preferences, onClick, onDeleteError, onDeleteSuccess, onCreateError, onCreateSuccess, }: SubscriptionPreferencesProps) => react_jsx_runtime.JSX.Element>;
7
+
8
+ export { SubscriptionPreferences, type SubscriptionPreferencesProps };
@@ -30,13 +30,16 @@ var import_js = require("@novu/js");
30
30
  var import_internal = require("@novu/js/internal");
31
31
  var import_react = require("react");
32
32
  var import_jsx_runtime = require("react/jsx-runtime");
33
- var version = "3.11.0";
33
+ var version = "3.11.2-nightly.20251224.eb609546a3";
34
34
  var name = "@novu/react";
35
35
  var baseUserAgent = `${name}@${version}`;
36
36
  var NovuContext = (0, import_react.createContext)(void 0);
37
37
  var NovuProvider = (props) => {
38
38
  const { subscriberId, ...propsWithoutSubscriberId } = props;
39
- const subscriberObj = (0, import_internal.buildSubscriber)({ subscriberId, subscriber: props.subscriber });
39
+ const subscriberObj = (0, import_react.useMemo)(
40
+ () => (0, import_internal.buildSubscriber)({ subscriberId, subscriber: props.subscriber }),
41
+ [subscriberId, props.subscriber]
42
+ );
40
43
  const applicationIdentifier = propsWithoutSubscriberId.applicationIdentifier ? propsWithoutSubscriberId.applicationIdentifier : "";
41
44
  const providerProps = {
42
45
  ...propsWithoutSubscriberId,
@@ -47,7 +50,10 @@ var NovuProvider = (props) => {
47
50
  };
48
51
  var InternalNovuProvider = (props) => {
49
52
  const applicationIdentifier = props.applicationIdentifier || "";
50
- const subscriberObj = (0, import_internal.buildSubscriber)({ subscriberId: props.subscriberId, subscriber: props.subscriber });
53
+ const subscriberObj = (0, import_react.useMemo)(
54
+ () => (0, import_internal.buildSubscriber)({ subscriberId: props.subscriberId, subscriber: props.subscriber }),
55
+ [props.subscriberId, props.subscriber]
56
+ );
51
57
  const {
52
58
  children,
53
59
  subscriberHash,
@@ -74,22 +80,19 @@ var InternalNovuProvider = (props) => {
74
80
  defaultSchedule,
75
81
  context
76
82
  }),
77
- [applicationIdentifier, backendUrl, apiUrl, socketUrl, useCache, userAgentType]
83
+ [
84
+ applicationIdentifier,
85
+ subscriberHash,
86
+ subscriberObj,
87
+ context,
88
+ contextHash,
89
+ backendUrl,
90
+ apiUrl,
91
+ socketUrl,
92
+ useCache,
93
+ userAgentType
94
+ ]
78
95
  );
79
- (0, import_react.useEffect)(() => {
80
- novu.changeSubscriber({
81
- subscriber: subscriberObj,
82
- subscriberHash: props.subscriberHash
83
- });
84
- }, [subscriberObj.subscriberId, props.subscriberHash, novu]);
85
- (0, import_react.useEffect)(() => {
86
- if (context && contextHash) {
87
- novu.changeContext({
88
- context,
89
- contextHash
90
- });
91
- }
92
- }, [context, contextHash, novu]);
93
96
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NovuContext.Provider, { value: novu, children });
94
97
  };
95
98
  var useNovu = () => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/hooks/NovuProvider.tsx"],"sourcesContent":["import { Novu, NovuOptions } from '@novu/js';\nimport { buildSubscriber } from '@novu/js/internal';\nimport { createContext, ReactNode, useContext, useEffect, useMemo } from 'react';\n\n// @ts-expect-error\nconst version = PACKAGE_VERSION;\n// @ts-expect-error\nconst name = PACKAGE_NAME;\nconst baseUserAgent = `${name}@${version}`;\n\nexport type NovuProviderProps = NovuOptions & {\n children: ReactNode;\n};\n\nconst NovuContext = createContext<Novu | undefined>(undefined);\n\nexport const NovuProvider = (props: NovuProviderProps) => {\n const { subscriberId, ...propsWithoutSubscriberId } = props;\n const subscriberObj = buildSubscriber({ subscriberId, subscriber: props.subscriber });\n const applicationIdentifier = propsWithoutSubscriberId.applicationIdentifier\n ? propsWithoutSubscriberId.applicationIdentifier\n : '';\n\n const providerProps: NovuProviderProps = {\n ...propsWithoutSubscriberId,\n applicationIdentifier,\n subscriber: subscriberObj,\n };\n\n return (\n <InternalNovuProvider {...providerProps} applicationIdentifier={applicationIdentifier} userAgentType=\"hooks\">\n {props.children}\n </InternalNovuProvider>\n );\n};\n\n/**\n * @internal Should be used internally not to be exposed outside of the library\n * This is needed to differentiate between the hooks and components user agents\n * Better to use this internally to avoid confusion.\n */\nexport const InternalNovuProvider = (props: NovuProviderProps & { userAgentType: 'components' | 'hooks' }) => {\n const applicationIdentifier = props.applicationIdentifier || '';\n const subscriberObj = buildSubscriber({ subscriberId: props.subscriberId, subscriber: props.subscriber });\n\n const {\n children,\n subscriberHash,\n contextHash,\n backendUrl,\n apiUrl,\n socketUrl,\n useCache,\n userAgentType,\n defaultSchedule,\n context,\n } = props;\n\n const novu = useMemo(\n () =>\n new Novu({\n applicationIdentifier,\n subscriberHash,\n contextHash,\n backendUrl,\n apiUrl,\n socketUrl,\n useCache,\n __userAgent: `${baseUserAgent} ${userAgentType}`,\n subscriber: subscriberObj,\n defaultSchedule,\n context,\n }),\n [applicationIdentifier, backendUrl, apiUrl, socketUrl, useCache, userAgentType]\n );\n\n useEffect(() => {\n novu.changeSubscriber({\n subscriber: subscriberObj,\n subscriberHash: props.subscriberHash,\n });\n }, [subscriberObj.subscriberId, props.subscriberHash, novu]);\n\n useEffect(() => {\n if (context && contextHash) {\n novu.changeContext({\n context,\n contextHash,\n });\n }\n }, [context, contextHash, novu]);\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAkC;AAClC,sBAAgC;AAChC,mBAAyE;AA4BrE;AAzBJ,IAAM,UAAU;AAEhB,IAAM,OAAO;AACb,IAAM,gBAAgB,GAAG,IAAI,IAAI,OAAO;AAMxC,IAAM,kBAAc,4BAAgC,MAAS;AAEtD,IAAM,eAAe,CAAC,UAA6B;AACxD,QAAM,EAAE,cAAc,GAAG,yBAAyB,IAAI;AACtD,QAAM,oBAAgB,iCAAgB,EAAE,cAAc,YAAY,MAAM,WAAW,CAAC;AACpF,QAAM,wBAAwB,yBAAyB,wBACnD,yBAAyB,wBACzB;AAEJ,QAAM,gBAAmC;AAAA,IACvC,GAAG;AAAA,IACH;AAAA,IACA,YAAY;AAAA,EACd;AAEA,SACE,4CAAC,wBAAsB,GAAG,eAAe,uBAA8C,eAAc,SAClG,gBAAM,UACT;AAEJ;AAOO,IAAM,uBAAuB,CAAC,UAAyE;AAC5G,QAAM,wBAAwB,MAAM,yBAAyB;AAC7D,QAAM,oBAAgB,iCAAgB,EAAE,cAAc,MAAM,cAAc,YAAY,MAAM,WAAW,CAAC;AAExG,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,QAAM,WAAO;AAAA,IACX,MACE,IAAI,eAAK;AAAA,MACP;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,aAAa,GAAG,aAAa,IAAI,aAAa;AAAA,MAC9C,YAAY;AAAA,MACZ;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,CAAC,uBAAuB,YAAY,QAAQ,WAAW,UAAU,aAAa;AAAA,EAChF;AAEA,8BAAU,MAAM;AACd,SAAK,iBAAiB;AAAA,MACpB,YAAY;AAAA,MACZ,gBAAgB,MAAM;AAAA,IACxB,CAAC;AAAA,EACH,GAAG,CAAC,cAAc,cAAc,MAAM,gBAAgB,IAAI,CAAC;AAE3D,8BAAU,MAAM;AACd,QAAI,WAAW,aAAa;AAC1B,WAAK,cAAc;AAAA,QACjB;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,GAAG,CAAC,SAAS,aAAa,IAAI,CAAC;AAE/B,SAAO,4CAAC,YAAY,UAAZ,EAAqB,OAAO,MAAO,UAAS;AACtD;AAEO,IAAM,UAAU,MAAM;AAC3B,QAAM,cAAU,yBAAW,WAAW;AACtC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,gDAAgD;AAAA,EAClE;AAEA,SAAO;AACT;AAEO,IAAM,gBAAgB,MAAM;AACjC,QAAM,cAAU,yBAAW,WAAW;AAEtC,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/hooks/NovuProvider.tsx"],"sourcesContent":["import { Novu, NovuOptions } from '@novu/js';\nimport { buildSubscriber } from '@novu/js/internal';\nimport { createContext, ReactNode, useContext, useMemo } from 'react';\n\n// @ts-expect-error\nconst version = PACKAGE_VERSION;\n// @ts-expect-error\nconst name = PACKAGE_NAME;\nconst baseUserAgent = `${name}@${version}`;\n\nexport type NovuProviderProps = NovuOptions & {\n children: ReactNode;\n};\n\nconst NovuContext = createContext<Novu | undefined>(undefined);\n\nexport const NovuProvider = (props: NovuProviderProps) => {\n const { subscriberId, ...propsWithoutSubscriberId } = props;\n const subscriberObj = useMemo(\n () => buildSubscriber({ subscriberId, subscriber: props.subscriber }),\n [subscriberId, props.subscriber]\n );\n const applicationIdentifier = propsWithoutSubscriberId.applicationIdentifier\n ? propsWithoutSubscriberId.applicationIdentifier\n : '';\n\n const providerProps: NovuProviderProps = {\n ...propsWithoutSubscriberId,\n applicationIdentifier,\n subscriber: subscriberObj,\n };\n\n return (\n <InternalNovuProvider {...providerProps} applicationIdentifier={applicationIdentifier} userAgentType=\"hooks\">\n {props.children}\n </InternalNovuProvider>\n );\n};\n\n/**\n * @internal Should be used internally not to be exposed outside of the library\n * This is needed to differentiate between the hooks and components user agents\n * Better to use this internally to avoid confusion.\n */\nexport const InternalNovuProvider = (props: NovuProviderProps & { userAgentType: 'components' | 'hooks' }) => {\n const applicationIdentifier = props.applicationIdentifier || '';\n const subscriberObj = useMemo(\n () => buildSubscriber({ subscriberId: props.subscriberId, subscriber: props.subscriber }),\n [props.subscriberId, props.subscriber]\n );\n\n const {\n children,\n subscriberHash,\n contextHash,\n backendUrl,\n apiUrl,\n socketUrl,\n useCache,\n userAgentType,\n defaultSchedule,\n context,\n } = props;\n\n const novu = useMemo(\n () =>\n new Novu({\n applicationIdentifier,\n subscriberHash,\n contextHash,\n backendUrl,\n apiUrl,\n socketUrl,\n useCache,\n __userAgent: `${baseUserAgent} ${userAgentType}`,\n subscriber: subscriberObj,\n defaultSchedule,\n context,\n }),\n [\n applicationIdentifier,\n subscriberHash,\n subscriberObj,\n context,\n contextHash,\n backendUrl,\n apiUrl,\n socketUrl,\n useCache,\n userAgentType,\n ]\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAkC;AAClC,sBAAgC;AAChC,mBAA8D;AA+B1D;AA5BJ,IAAM,UAAU;AAEhB,IAAM,OAAO;AACb,IAAM,gBAAgB,GAAG,IAAI,IAAI,OAAO;AAMxC,IAAM,kBAAc,4BAAgC,MAAS;AAEtD,IAAM,eAAe,CAAC,UAA6B;AACxD,QAAM,EAAE,cAAc,GAAG,yBAAyB,IAAI;AACtD,QAAM,oBAAgB;AAAA,IACpB,UAAM,iCAAgB,EAAE,cAAc,YAAY,MAAM,WAAW,CAAC;AAAA,IACpE,CAAC,cAAc,MAAM,UAAU;AAAA,EACjC;AACA,QAAM,wBAAwB,yBAAyB,wBACnD,yBAAyB,wBACzB;AAEJ,QAAM,gBAAmC;AAAA,IACvC,GAAG;AAAA,IACH;AAAA,IACA,YAAY;AAAA,EACd;AAEA,SACE,4CAAC,wBAAsB,GAAG,eAAe,uBAA8C,eAAc,SAClG,gBAAM,UACT;AAEJ;AAOO,IAAM,uBAAuB,CAAC,UAAyE;AAC5G,QAAM,wBAAwB,MAAM,yBAAyB;AAC7D,QAAM,oBAAgB;AAAA,IACpB,UAAM,iCAAgB,EAAE,cAAc,MAAM,cAAc,YAAY,MAAM,WAAW,CAAC;AAAA,IACxF,CAAC,MAAM,cAAc,MAAM,UAAU;AAAA,EACvC;AAEA,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,QAAM,WAAO;AAAA,IACX,MACE,IAAI,eAAK;AAAA,MACP;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,aAAa,GAAG,aAAa,IAAI,aAAa;AAAA,MAC9C,YAAY;AAAA,MACZ;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO,4CAAC,YAAY,UAAZ,EAAqB,OAAO,MAAO,UAAS;AACtD;AAEO,IAAM,UAAU,MAAM;AAC3B,QAAM,cAAU,yBAAW,WAAW;AACtC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,gDAAgD;AAAA,EAClE;AAEA,SAAO;AACT;AAEO,IAAM,gBAAgB,MAAM;AACjC,QAAM,cAAU,yBAAW,WAAW;AAEtC,SAAO;AACT;","names":[]}
@@ -31,9 +31,14 @@ module.exports = __toCommonJS(hooks_exports);
31
31
  var import_js = require("@novu/js");
32
32
  var import_NovuProvider = require("./NovuProvider.cjs");
33
33
  __reExport(hooks_exports, require("./useCounts.cjs"), module.exports);
34
+ __reExport(hooks_exports, require("./useCreateSubscription.cjs"), module.exports);
34
35
  __reExport(hooks_exports, require("./useNotifications.cjs"), module.exports);
35
36
  __reExport(hooks_exports, require("./usePreferences.cjs"), module.exports);
37
+ __reExport(hooks_exports, require("./useRemoveSubscription.cjs"), module.exports);
36
38
  __reExport(hooks_exports, require("./useSchedule.cjs"), module.exports);
39
+ __reExport(hooks_exports, require("./useSubscription.cjs"), module.exports);
40
+ __reExport(hooks_exports, require("./useSubscriptions.cjs"), module.exports);
41
+ __reExport(hooks_exports, require("./useUpdateSubscription.cjs"), module.exports);
37
42
  // Annotate the CommonJS export names for ESM import in node:
38
43
  0 && (module.exports = {
39
44
  NovuProvider,
@@ -42,8 +47,13 @@ __reExport(hooks_exports, require("./useSchedule.cjs"), module.exports);
42
47
  WorkflowCriticalityEnum,
43
48
  useNovu,
44
49
  ...require("./useCounts.cjs"),
50
+ ...require("./useCreateSubscription.cjs"),
45
51
  ...require("./useNotifications.cjs"),
46
52
  ...require("./usePreferences.cjs"),
47
- ...require("./useSchedule.cjs")
53
+ ...require("./useRemoveSubscription.cjs"),
54
+ ...require("./useSchedule.cjs"),
55
+ ...require("./useSubscription.cjs"),
56
+ ...require("./useSubscriptions.cjs"),
57
+ ...require("./useUpdateSubscription.cjs")
48
58
  });
49
59
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/hooks/index.ts"],"sourcesContent":["export type {\n ChannelPreference,\n ChannelType,\n EventHandler,\n Events,\n FiltersCountResponse,\n InboxNotification,\n ListNotificationsResponse,\n Notification,\n NotificationFilter,\n NotificationStatus,\n NovuError,\n NovuOptions,\n Preference,\n PreferencesResponse,\n SocketEventNames,\n UnreadCount,\n WebSocketEvent,\n} from '@novu/js';\nexport { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from '@novu/js';\nexport { NovuProvider, useNovu } from './NovuProvider';\nexport * from './useCounts';\nexport * from './useNotifications';\nexport * from './usePreferences';\nexport * from './useSchedule';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmBA,gBAA4E;AAC5E,0BAAsC;AACtC,0BAAc,4BArBd;AAsBA,0BAAc,mCAtBd;AAuBA,0BAAc,iCAvBd;AAwBA,0BAAc,8BAxBd;","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":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,gBAA4E;AAC5E,0BAAsC;AACtC,0BAAc,4BAHd;AAIA,0BAAc,wCAJd;AAKA,0BAAc,mCALd;AAMA,0BAAc,iCANd;AAOA,0BAAc,wCAPd;AAQA,0BAAc,8BARd;AASA,0BAAc,kCATd;AAUA,0BAAc,mCAVd;AAWA,0BAAc,wCAXd;","names":[]}
@@ -1,8 +1,14 @@
1
- export { ChannelPreference, ChannelType, EventHandler, Events, FiltersCountResponse, InboxNotification, ListNotificationsResponse, Notification, NotificationFilter, NotificationStatus, NovuError, NovuOptions, Preference, PreferenceLevel, PreferencesResponse, SeverityLevelEnum, SocketEventNames, UnreadCount, WebSocketEvent, WorkflowCriticalityEnum } from '@novu/js';
1
+ export * from '@novu/js';
2
+ export { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from '@novu/js';
2
3
  export { NovuProvider, useNovu } from './NovuProvider.cjs';
3
4
  export { UseCountsProps, UseCountsResult, useCounts } from './useCounts.cjs';
5
+ export { UseCreateSubscriptionProps, UseCreateSubscriptionResult, useCreateSubscription } from './useCreateSubscription.cjs';
4
6
  export { UseNotificationsProps, UseNotificationsResult, useNotifications } from './useNotifications.cjs';
5
7
  export { UsePreferencesProps, UsePreferencesResult, usePreferences } from './usePreferences.cjs';
8
+ export { UseRemoveSubscriptionProps, UseRemoveSubscriptionResult, useRemoveSubscription } from './useRemoveSubscription.cjs';
6
9
  export { UseScheduleProps, UseScheduleResult, useSchedule } from './useSchedule.cjs';
10
+ export { UseSubscriptionProps, UseSubscriptionResult, useSubscription } from './useSubscription.cjs';
11
+ export { UseSubscriptionsProps, UseSubscriptionsResult, useSubscriptions } from './useSubscriptions.cjs';
12
+ export { UseUpdateSubscriptionProps, UseUpdateSubscriptionResult, useUpdateSubscription } from './useUpdateSubscription.cjs';
7
13
  import 'react/jsx-runtime';
8
14
  import 'react';
@@ -25,17 +25,17 @@ __export(useCounts_exports, {
25
25
  module.exports = __toCommonJS(useCounts_exports);
26
26
  var import_js = require("@novu/js");
27
27
  var import_react = require("react");
28
+ var import_useDataRef = require("./internal/useDataRef.cjs");
28
29
  var import_useWebsocketEvent = require("./internal/useWebsocketEvent.cjs");
29
30
  var import_NovuProvider = require("./NovuProvider.cjs");
30
31
  var useCounts = (props) => {
31
32
  const { filters, onSuccess, onError } = props;
32
33
  const { notifications } = (0, import_NovuProvider.useNovu)();
33
- const filtersRef = (0, import_react.useRef)(filters);
34
+ const filtersRef = (0, import_useDataRef.useDataRef)(filters);
34
35
  const [error, setError] = (0, import_react.useState)();
35
36
  const [counts, setCounts] = (0, import_react.useState)();
36
37
  const [isLoading, setIsLoading] = (0, import_react.useState)(true);
37
38
  const [isFetching, setIsFetching] = (0, import_react.useState)(false);
38
- filtersRef.current = filters;
39
39
  const sync = async (notification, overrideFilters) => {
40
40
  const currentFilters = overrideFilters || filtersRef.current;
41
41
  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;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAwF;AACxF,mBAA4C;AAC5C,+BAAkC;AAClC,0BAAwB;AA0CjB,IAAM,YAAY,CAAC,UAA2C;AACnE,QAAM,EAAE,SAAS,WAAW,QAAQ,IAAI;AACxC,QAAM,EAAE,cAAc,QAAI,6BAAQ;AAClC,QAAM,iBAAa,qBAA6B,OAAO;AACvD,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAoB;AAC9C,QAAM,CAAC,QAAQ,SAAS,QAAI,uBAAkB;AAC9C,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,IAAI;AAC/C,QAAM,CAAC,YAAY,aAAa,QAAI,uBAAS,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,cAAM,SAAS,eAAe,CAAC;AAC/B,cAAM,oBACJ,CAAC,OAAO,YACP,MAAM,QAAQ,OAAO,QAAQ,KAAK,OAAO,S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AAa,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;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAwF;AACxF,mBAAoC;AACpC,wBAA2B;AAC3B,+BAAkC;AAClC,0BAAwB;AA0CjB,IAAM,YAAY,CAAC,UAA2C;AACnE,QAAM,EAA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AAY,KAAK;AAEjB,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,UAAM,wBAAa,EAAE,QAAQ,cAAc,CAAC;AACvF,cAAM,QAAQ,kBAAiB,uCAAY;AAC3C,YAAI,OAAO;AACT,oBAAU,KAAK,KAAK;AAAA,QACtB;AAAA,MACF;AAEA,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,kDAAkB;AAAA,IAChB,OAAO;AAAA,IACP,cAAc,CAAC,SAAS;AACtB,WAAK,KAAK,MAAM;AAAA,IAClB;AAAA,EACF,CAAC;AAED,kDAAkB;AAAA,IAChB,OAAO;AAAA,IACP,cAAc,MAAM;AAClB,WAAK;AAAA,IACP;AAAA,EACF,CAAC;AAED,8BAAU,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":[]}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/hooks/useCreateSubscription.ts
21
+ var useCreateSubscription_exports = {};
22
+ __export(useCreateSubscription_exports, {
23
+ useCreateSubscription: () => useCreateSubscription
24
+ });
25
+ module.exports = __toCommonJS(useCreateSubscription_exports);
26
+ var import_react = require("react");
27
+ var import_NovuProvider = require("./NovuProvider.cjs");
28
+ var useCreateSubscription = (props = {}) => {
29
+ const propsRef = (0, import_react.useRef)(props);
30
+ propsRef.current = props;
31
+ const novu = (0, import_NovuProvider.useNovu)();
32
+ const [isCreating, setIsCreating] = (0, import_react.useState)(false);
33
+ const [error, setError] = (0, import_react.useState)();
34
+ const create = (0, import_react.useCallback)(
35
+ async (args) => {
36
+ const { onSuccess, onError } = propsRef.current;
37
+ setError(void 0);
38
+ setIsCreating(true);
39
+ const response = await novu.subscriptions.create(args);
40
+ setIsCreating(false);
41
+ if (response.error) {
42
+ setError(response.error);
43
+ onError == null ? void 0 : onError(response.error);
44
+ } else if (response.data) {
45
+ onSuccess == null ? void 0 : onSuccess(response.data);
46
+ }
47
+ return response;
48
+ },
49
+ [novu]
50
+ );
51
+ return {
52
+ create,
53
+ isCreating,
54
+ error
55
+ };
56
+ };
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ useCreateSubscription
60
+ });
61
+ //# sourceMappingURL=useCreateSubscription.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/hooks/useCreateSubscription.ts"],"sourcesContent":["import { CreateSubscriptionArgs, NovuError, TopicSubscription } from '@novu/js';\nimport { useCallback, useRef, useState } from 'react';\nimport { useNovu } from './NovuProvider';\n\nexport type UseCreateSubscriptionProps = {\n onSuccess?: (data: TopicSubscription) => void;\n onError?: (error: NovuError) => void;\n};\n\nexport type UseCreateSubscriptionResult = {\n isCreating: boolean;\n error?: NovuError;\n create: (args: CreateSubscriptionArgs) => Promise<{\n data?: TopicSubscription | undefined;\n error?: NovuError | undefined;\n }>;\n};\n\nexport const useCreateSubscription = (props: UseCreateSubscriptionProps = {}): UseCreateSubscriptionResult => {\n const propsRef = useRef<UseCreateSubscriptionProps>(props);\n propsRef.current = props;\n const novu = useNovu();\n const [isCreating, setIsCreating] = useState(false);\n const [error, setError] = useState<NovuError>();\n\n const create = useCallback(\n async (args: CreateSubscriptionArgs) => {\n const { onSuccess, onError } = propsRef.current;\n setError(undefined);\n setIsCreating(true);\n\n const response = await novu.subscriptions.create(args);\n\n setIsCreating(false);\n\n if (response.error) {\n setError(response.error);\n onError?.(response.error);\n } else if (response.data) {\n onSuccess?.(response.data);\n }\n\n return response;\n },\n [novu]\n );\n\n return {\n create,\n isCreating,\n error,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA8C;AAC9C,0BAAwB;AAgBjB,IAAM,wBAAwB,CAAC,QAAoC,CAAC,MAAmC;AAC5G,QAAM,eAAW,qBAAmC,KAAK;AACzD,WAAS,UAAU;AACnB,QAAM,WAAO,6BAAQ;AACrB,QAAM,CAAC,YAAY,aAAa,QAAI,uBAAS,KAAK;AAClD,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAoB;AAE9C,QAAM,aAAS;AAAA,IACb,OAAO,SAAiC;AACtC,YAAM,EAAE,WAAW,QAAQ,IAAI,SAAS;AACxC,eAAS,MAAS;AAClB,oBAAc,IAAI;AAElB,YAAM,WAAW,MAAM,KAAK,cAAc,OAAO,IAAI;AAErD,oBAAc,KAAK;AAEnB,UAAI,SAAS,OAAO;AAClB,iBAAS,SAAS,KAAK;AACvB,2CAAU,SAAS;AAAA,MACrB,WAAW,SAAS,MAAM;AACxB,+CAAY,SAAS;AAAA,MACvB;AAEA,aAAO;AAAA,IACT;AAAA,IACA,CAAC,IAAI;AAAA,EACP;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,17 @@
1
+ import { TopicSubscription, NovuError, CreateSubscriptionArgs } from '@novu/js';
2
+
3
+ type UseCreateSubscriptionProps = {
4
+ onSuccess?: (data: TopicSubscription) => void;
5
+ onError?: (error: NovuError) => void;
6
+ };
7
+ type UseCreateSubscriptionResult = {
8
+ isCreating: boolean;
9
+ error?: NovuError;
10
+ create: (args: CreateSubscriptionArgs) => Promise<{
11
+ data?: TopicSubscription | undefined;
12
+ error?: NovuError | undefined;
13
+ }>;
14
+ };
15
+ declare const useCreateSubscription: (props?: UseCreateSubscriptionProps) => UseCreateSubscriptionResult;
16
+
17
+ export { type UseCreateSubscriptionProps, type UseCreateSubscriptionResult, useCreateSubscription };
@@ -25,6 +25,7 @@ __export(useNotifications_exports, {
25
25
  module.exports = __toCommonJS(useNotifications_exports);
26
26
  var import_js = require("@novu/js");
27
27
  var import_react = require("react");
28
+ var import_useDataRef = require("./internal/useDataRef.cjs");
28
29
  var import_useWebsocketEvent = require("./internal/useWebsocketEvent.cjs");
29
30
  var import_NovuProvider = require("./NovuProvider.cjs");
30
31
  var useNotifications = (props) => {
@@ -36,16 +37,13 @@ var useNotifications = (props) => {
36
37
  snoozed = false,
37
38
  seen,
38
39
  severity,
39
- limit,
40
+ limit = 10,
40
41
  onSuccess,
41
42
  onError
42
43
  } = props || {};
43
- const filterRef = (0, import_react.useRef)(void 0);
44
- const { notifications } = (0, import_NovuProvider.useNovu)();
45
- const getCurrentFilter = (0, import_react.useCallback)(
46
- () => filterRef.current || { tags, data: dataFilter, severity },
47
- [tags, dataFilter, severity]
48
- );
44
+ const limitRef = (0, import_useDataRef.useDataRef)(limit);
45
+ const filterRef = (0, import_useDataRef.useDataRef)({ tags, data: dataFilter, read, archived, snoozed, seen, severity });
46
+ const novu = (0, import_NovuProvider.useNovu)();
49
47
  const [data, setData] = (0, import_react.useState)();
50
48
  const [error, setError] = (0, import_react.useState)();
51
49
  const [isLoading, setIsLoading] = (0, import_react.useState)(true);
@@ -53,24 +51,31 @@ var useNotifications = (props) => {
53
51
  const [hasMore, setHasMore] = (0, import_react.useState)(false);
54
52
  const length = data == null ? void 0 : data.length;
55
53
  const after = length ? data[length - 1].id : void 0;
56
- (0, import_useWebsocketEvent.useWebSocketEvent)({
57
- event: "notifications.unread_count_changed",
58
- eventHandler: () => {
59
- void refetch();
60
- }
61
- });
62
- (0, import_useWebsocketEvent.useWebSocketEvent)({
63
- event: "notifications.unseen_count_changed",
64
- eventHandler: () => {
65
- void refetch();
66
- }
67
- });
54
+ const afterRef = (0, import_useDataRef.useDataRef)(after);
55
+ (0, import_react.useEffect)(() => {
56
+ const listener = ({
57
+ data: data2
58
+ }) => {
59
+ if (!data2 || !(0, import_js.isSameFilter)(filterRef.current, data2.filter)) {
60
+ return;
61
+ }
62
+ setData(data2.notifications);
63
+ setHasMore(data2.hasMore);
64
+ };
65
+ const cleanup = novu.on("notifications.list.updated", listener);
66
+ return () => {
67
+ cleanup();
68
+ };
69
+ }, [filterRef, novu]);
68
70
  (0, import_useWebsocketEvent.useWebSocketEvent)({
69
71
  event: "notifications.notification_received",
70
72
  eventHandler: ({ result: notification }) => {
71
- const currentFilter = getCurrentFilter();
73
+ const currentFilter = filterRef.current;
72
74
  const matches = (0, import_js.checkNotificationMatchesFilter)(notification, currentFilter);
73
- if (matches) void refetch();
75
+ if (matches) {
76
+ const cacheKey = { ...currentFilter, limit: limitRef.current };
77
+ novu.notifications.cache.unshift(cacheKey, notification);
78
+ }
74
79
  }
75
80
  });
76
81
  const fetchNotifications = (0, import_react.useCallback)(
@@ -81,59 +86,51 @@ var useNotifications = (props) => {
81
86
  setIsFetching(false);
82
87
  }
83
88
  setIsFetching(true);
84
- const currentFilter = getCurrentFilter();
85
- const response = await notifications.list({
86
- ...currentFilter,
89
+ const response = await novu.notifications.list({
90
+ ...filterRef.current,
87
91
  limit,
88
- after: (options == null ? void 0 : options.refetch) ? void 0 : after
92
+ after: (options == null ? void 0 : options.refetch) ? void 0 : afterRef.current
89
93
  });
90
94
  if (response.error) {
91
95
  setError(response.error);
92
96
  onError == null ? void 0 : onError(response.error);
97
+ setIsLoading(false);
98
+ setIsFetching(false);
93
99
  } else if (response.data) {
94
- onSuccess == null ? void 0 : onSuccess(response.data.notifications);
95
- setData(response.data.notifications);
96
- setHasMore(response.data.hasMore);
100
+ const responseData = response.data;
101
+ onSuccess == null ? void 0 : onSuccess(responseData.notifications);
102
+ setData(responseData.notifications);
103
+ setHasMore(responseData.hasMore);
104
+ setIsLoading(false);
105
+ setIsFetching(false);
97
106
  }
98
- setIsLoading(false);
99
- setIsFetching(false);
100
107
  },
101
- [notifications, getCurrentFilter, limit, after, onError, onSuccess]
108
+ [novu, filterRef, afterRef, limit, onError, onSuccess]
102
109
  );
103
110
  (0, import_react.useEffect)(() => {
104
- const newFilter = { tags, data: dataFilter, read, archived, snoozed, seen, severity };
105
- if (filterRef.current && (0, import_js.isSameFilter)(filterRef.current, newFilter)) {
106
- return;
107
- }
108
- notifications.clearCache({ filter: filterRef.current });
109
- filterRef.current = newFilter;
111
+ novu.notifications.clearCache({ filter: filterRef.current });
110
112
  fetchNotifications({ refetch: true });
111
- }, [tags, dataFilter, read, archived, snoozed, seen, notifications, fetchNotifications]);
112
- const refetch = () => {
113
- const filter = getCurrentFilter();
114
- notifications.clearCache({ filter });
113
+ }, [filterRef, novu, JSON.stringify(filterRef.current), fetchNotifications]);
114
+ const refetch = (0, import_react.useCallback)(() => {
115
+ novu.notifications.clearCache({ filter: filterRef.current });
115
116
  return fetchNotifications({ refetch: true });
116
- };
117
- const fetchMore = async () => {
117
+ }, [filterRef, novu, fetchNotifications]);
118
+ const fetchMore = (0, import_react.useCallback)(async () => {
118
119
  if (!hasMore || isFetching) return;
119
120
  return fetchNotifications();
120
- };
121
- const readAll = async () => {
122
- const { tags: tags2, data: data2 } = getCurrentFilter();
123
- return await notifications.readAll({ tags: tags2, data: data2 });
124
- };
125
- const seenAll = async () => {
126
- const { tags: tags2, data: data2 } = getCurrentFilter();
127
- return await notifications.seenAll({ tags: tags2, data: data2 });
128
- };
129
- const archiveAll = async () => {
130
- const { tags: tags2, data: data2 } = getCurrentFilter();
131
- return await notifications.archiveAll({ tags: tags2, data: data2 });
132
- };
133
- const archiveAllRead = async () => {
134
- const { tags: tags2, data: data2 } = getCurrentFilter();
135
- return await notifications.archiveAllRead({ tags: tags2, data: data2 });
136
- };
121
+ }, [hasMore, isFetching, fetchNotifications]);
122
+ const readAll = (0, import_react.useCallback)(async () => {
123
+ return await novu.notifications.readAll({ tags: filterRef.current.tags, data: filterRef.current.data });
124
+ }, [filterRef, novu]);
125
+ const seenAll = (0, import_react.useCallback)(async () => {
126
+ return await novu.notifications.seenAll({ tags: filterRef.current.tags, data: filterRef.current.data });
127
+ }, [filterRef, novu]);
128
+ const archiveAll = (0, import_react.useCallback)(async () => {
129
+ return await novu.notifications.archiveAll({ tags: filterRef.current.tags, data: filterRef.current.data });
130
+ }, [filterRef, novu]);
131
+ const archiveAllRead = (0, import_react.useCallback)(async () => {
132
+ return await novu.notifications.archiveAllRead({ tags: filterRef.current.tags, data: filterRef.current.data });
133
+ }, [filterRef, novu]);
137
134
  return {
138
135
  readAll,
139
136
  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 notifications: data,\n error,\n isLoading,\n isFetching,\n refetch,\n fetchMore,\n hasMore,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;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,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;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA0G;AAC1G,mBAAiD;AACjD,wBAA2B;AAC3B,+BAAkC;AAClC,0BAAwB;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,eAAW,8BAA+B,KAAK;AACrD,QAAM,gBAAY,8BAA+B,EAAE,MAAM,MAAM,YAAY,MAAM,UAAU,SAAS,MAAM,SAAS,CAAC;AACpH,QAAM,WAAO,6BAAQ;AACrB,QAAM,CAAC,MAAM,OAAO,QAAI,uBAA8B;AACtD,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAoB;AAC9C,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,IAAI;AAC/C,QAAM,CAAC,YAAY,aAAa,QAAI,uBAAS,KAAK;AAClD,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAS,KAAK;AAC5C,QAAM,SAAS,6BAAM;AACrB,QAAM,QAAQ,SAAS,KAAK,SAAS,CAAC,EAAE,KAAK;AAC7C,QAAM,eAAW,8BAA+B,KAAK;AAErD,8BAAU,MAAM;AACd,UAAM,WAAW,CAAC;AAAA,MAChB,MAAAA;AAAA,IACF,MAEM;AACJ,UAAI,CAACA,SA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L;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,61 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/hooks/useRemoveSubscription.ts
21
+ var useRemoveSubscription_exports = {};
22
+ __export(useRemoveSubscription_exports, {
23
+ useRemoveSubscription: () => useRemoveSubscription
24
+ });
25
+ module.exports = __toCommonJS(useRemoveSubscription_exports);
26
+ var import_react = require("react");
27
+ var import_NovuProvider = require("./NovuProvider.cjs");
28
+ var useRemoveSubscription = (props = {}) => {
29
+ const propsRef = (0, import_react.useRef)(props);
30
+ propsRef.current = props;
31
+ const novu = (0, import_NovuProvider.useNovu)();
32
+ const [isRemoving, setIsRemoving] = (0, import_react.useState)(false);
33
+ const [error, setError] = (0, import_react.useState)();
34
+ const removeCallback = (0, import_react.useCallback)(
35
+ async (args) => {
36
+ const { onSuccess, onError } = propsRef.current;
37
+ setError(void 0);
38
+ setIsRemoving(true);
39
+ const response = await novu.subscriptions.delete(args);
40
+ setIsRemoving(false);
41
+ if (response.error) {
42
+ setError(response.error);
43
+ onError == null ? void 0 : onError(response.error);
44
+ } else if (response.data) {
45
+ onSuccess == null ? void 0 : onSuccess();
46
+ }
47
+ return response;
48
+ },
49
+ [novu]
50
+ );
51
+ return {
52
+ remove: removeCallback,
53
+ isRemoving,
54
+ error
55
+ };
56
+ };
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ useRemoveSubscription
60
+ });
61
+ //# sourceMappingURL=useRemoveSubscription.cjs.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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA8C;AAC9C,0BAAwB;AAiBjB,IAAM,wBAAwB,CAAC,QAAoC,CAAC,MAAmC;AAC5G,QAAM,eAAW,qBAAmC,KAAK;AACzD,WAAS,UAAU;AACnB,QAAM,WAAO,6BAAQ;AACrB,QAAM,CAAC,YAAY,aAAa,QAAI,uBAAS,KAAK;AAClD,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAoB;AAE9C,QAAM,qBAAiB;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,2CAAU,SAAS;AAAA,MACrB,WAAW,SAAS,MAAM;AACxB;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,IACA,CAAC,IAAI;AAAA,EACP;AAEA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -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 };