@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.
- package/README.md +10 -18
- package/dist/cjs/components/Inbox.cjs +5 -1
- package/dist/cjs/components/Inbox.cjs.map +1 -1
- package/dist/cjs/components/NovuUI.cjs +3 -1
- package/dist/cjs/components/NovuUI.cjs.map +1 -1
- package/dist/cjs/components/NovuUI.d.cts +9 -9
- package/dist/cjs/components/index.cjs +7 -1
- package/dist/cjs/components/index.cjs.map +1 -1
- package/dist/cjs/components/index.d.cts +5 -0
- package/dist/cjs/components/subscription/DefaultSubscription.cjs +59 -0
- package/dist/cjs/components/subscription/DefaultSubscription.cjs.map +1 -0
- package/dist/cjs/components/subscription/DefaultSubscription.d.cts +11 -0
- package/dist/cjs/components/subscription/Subscription.cjs +80 -0
- package/dist/cjs/components/subscription/Subscription.cjs.map +1 -0
- package/dist/cjs/components/subscription/Subscription.d.cts +22 -0
- package/dist/cjs/components/subscription/SubscriptionButton.cjs +91 -0
- package/dist/cjs/components/subscription/SubscriptionButton.cjs.map +1 -0
- package/dist/cjs/components/subscription/SubscriptionButton.d.cts +8 -0
- package/dist/cjs/components/subscription/SubscriptionPreferences.cjs +91 -0
- package/dist/cjs/components/subscription/SubscriptionPreferences.cjs.map +1 -0
- package/dist/cjs/components/subscription/SubscriptionPreferences.d.cts +8 -0
- package/dist/cjs/hooks/NovuProvider.cjs +21 -18
- package/dist/cjs/hooks/NovuProvider.cjs.map +1 -1
- package/dist/cjs/hooks/index.cjs +11 -1
- package/dist/cjs/hooks/index.cjs.map +1 -1
- package/dist/cjs/hooks/index.d.cts +7 -1
- package/dist/cjs/hooks/useCounts.cjs +2 -2
- package/dist/cjs/hooks/useCounts.cjs.map +1 -1
- package/dist/cjs/hooks/useCreateSubscription.cjs +61 -0
- package/dist/cjs/hooks/useCreateSubscription.cjs.map +1 -0
- package/dist/cjs/hooks/useCreateSubscription.d.cts +17 -0
- package/dist/cjs/hooks/useNotifications.cjs +57 -60
- package/dist/cjs/hooks/useNotifications.cjs.map +1 -1
- package/dist/cjs/hooks/useRemoveSubscription.cjs +61 -0
- package/dist/cjs/hooks/useRemoveSubscription.cjs.map +1 -0
- package/dist/cjs/hooks/useRemoveSubscription.d.cts +17 -0
- package/dist/cjs/hooks/useSubscription.cjs +156 -0
- package/dist/cjs/hooks/useSubscription.cjs.map +1 -0
- package/dist/cjs/hooks/useSubscription.d.cts +21 -0
- package/dist/cjs/hooks/useSubscriptions.cjs +121 -0
- package/dist/cjs/hooks/useSubscriptions.cjs.map +1 -0
- package/dist/cjs/hooks/useSubscriptions.d.cts +36 -0
- package/dist/cjs/hooks/useUpdateSubscription.cjs +61 -0
- package/dist/cjs/hooks/useUpdateSubscription.cjs.map +1 -0
- package/dist/cjs/hooks/useUpdateSubscription.d.cts +18 -0
- package/dist/cjs/index.cjs +18 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +14 -3
- package/dist/cjs/server/index.cjs +61 -2
- package/dist/cjs/server/index.cjs.map +1 -1
- package/dist/cjs/server/index.d.cts +18 -4
- package/dist/cjs/utils/appearance.cjs.map +1 -1
- package/dist/cjs/utils/appearance.d.cts +3 -3
- package/dist/cjs/utils/types.cjs.map +1 -1
- package/dist/cjs/utils/types.d.cts +32 -11
- package/dist/esm/components/Inbox.js +5 -1
- package/dist/esm/components/Inbox.js.map +1 -1
- package/dist/esm/components/NovuUI.d.ts +9 -9
- package/dist/esm/components/NovuUI.js +3 -1
- package/dist/esm/components/NovuUI.js.map +1 -1
- package/dist/esm/components/index.d.ts +5 -0
- package/dist/esm/components/index.js +3 -0
- package/dist/esm/components/index.js.map +1 -1
- package/dist/esm/components/subscription/DefaultSubscription.d.ts +11 -0
- package/dist/esm/components/subscription/DefaultSubscription.js +34 -0
- package/dist/esm/components/subscription/DefaultSubscription.js.map +1 -0
- package/dist/esm/components/subscription/Subscription.d.ts +22 -0
- package/dist/esm/components/subscription/Subscription.js +45 -0
- package/dist/esm/components/subscription/Subscription.js.map +1 -0
- package/dist/esm/components/subscription/SubscriptionButton.d.ts +8 -0
- package/dist/esm/components/subscription/SubscriptionButton.js +56 -0
- package/dist/esm/components/subscription/SubscriptionButton.js.map +1 -0
- package/dist/esm/components/subscription/SubscriptionPreferences.d.ts +8 -0
- package/dist/esm/components/subscription/SubscriptionPreferences.js +56 -0
- package/dist/esm/components/subscription/SubscriptionPreferences.js.map +1 -0
- package/dist/esm/hooks/NovuProvider.js +22 -19
- package/dist/esm/hooks/NovuProvider.js.map +1 -1
- package/dist/esm/hooks/index.d.ts +7 -1
- package/dist/esm/hooks/index.js +5 -0
- package/dist/esm/hooks/index.js.map +1 -1
- package/dist/esm/hooks/useCounts.js +3 -3
- package/dist/esm/hooks/useCounts.js.map +1 -1
- package/dist/esm/hooks/useCreateSubscription.d.ts +17 -0
- package/dist/esm/hooks/useCreateSubscription.js +36 -0
- package/dist/esm/hooks/useCreateSubscription.js.map +1 -0
- package/dist/esm/hooks/useNotifications.js +58 -61
- package/dist/esm/hooks/useNotifications.js.map +1 -1
- package/dist/esm/hooks/useRemoveSubscription.d.ts +17 -0
- package/dist/esm/hooks/useRemoveSubscription.js +36 -0
- package/dist/esm/hooks/useRemoveSubscription.js.map +1 -0
- package/dist/esm/hooks/useSubscription.d.ts +21 -0
- package/dist/esm/hooks/useSubscription.js +129 -0
- package/dist/esm/hooks/useSubscription.js.map +1 -0
- package/dist/esm/hooks/useSubscriptions.d.ts +36 -0
- package/dist/esm/hooks/useSubscriptions.js +96 -0
- package/dist/esm/hooks/useSubscriptions.js.map +1 -0
- package/dist/esm/hooks/useUpdateSubscription.d.ts +18 -0
- package/dist/esm/hooks/useUpdateSubscription.js +36 -0
- package/dist/esm/hooks/useUpdateSubscription.js.map +1 -0
- package/dist/esm/index.d.ts +14 -3
- package/dist/esm/index.js +32 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/server/index.d.ts +18 -4
- package/dist/esm/server/index.js +53 -2
- package/dist/esm/server/index.js.map +1 -1
- package/dist/esm/utils/appearance.d.ts +3 -3
- package/dist/esm/utils/appearance.js.map +1 -1
- package/dist/esm/utils/types.d.ts +32 -11
- 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.
|
|
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,
|
|
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,
|
|
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
|
-
[
|
|
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,
|
|
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,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T;","names":[]}
|
package/dist/cjs/hooks/index.cjs
CHANGED
|
@@ -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("./
|
|
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
|
|
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
|
|
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,
|
|
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,
|
|
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,EAAE,SAAS,WAAW,QAAQ,IAAI;AACxC,QAAM,EAAE,cAAc,QAAI,6BAAQ;AAClC,QAAM,iBAAa,8BAAiC,OAAO;AAC3D,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,aAA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,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
|
|
44
|
-
const
|
|
45
|
-
const
|
|
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,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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 =
|
|
73
|
+
const currentFilter = filterRef.current;
|
|
72
74
|
const matches = (0, import_js.checkNotificationMatchesFilter)(notification, currentFilter);
|
|
73
|
-
if (matches)
|
|
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
|
|
85
|
-
|
|
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 :
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
[
|
|
108
|
+
[novu, filterRef, afterRef, limit, onError, onSuccess]
|
|
102
109
|
);
|
|
103
110
|
(0, import_react.useEffect)(() => {
|
|
104
|
-
|
|
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
|
-
}, [
|
|
112
|
-
const refetch = () => {
|
|
113
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return await notifications.
|
|
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,
|
|
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 archive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.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 };
|