@novu/react 3.15.0 → 3.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/NovuUI.cjs.map +1 -1
- package/dist/cjs/components/NovuUI.d.cts +2 -2
- package/dist/cjs/components/connect-chat/ConnectChat.cjs +63 -0
- package/dist/cjs/components/connect-chat/ConnectChat.cjs.map +1 -0
- package/dist/cjs/components/connect-chat/ConnectChat.d.cts +12 -0
- package/dist/cjs/components/connect-chat/DefaultConnectChat.cjs +83 -0
- package/dist/cjs/components/connect-chat/DefaultConnectChat.cjs.map +1 -0
- package/dist/cjs/components/connect-chat/DefaultConnectChat.d.cts +7 -0
- package/dist/cjs/components/index.cjs +4 -0
- package/dist/cjs/components/index.cjs.map +1 -1
- package/dist/cjs/components/index.d.cts +5 -1
- package/dist/cjs/components/slack-connect-button/DefaultSlackConnectButton.cjs +89 -0
- package/dist/cjs/components/slack-connect-button/DefaultSlackConnectButton.cjs.map +1 -0
- package/dist/cjs/components/slack-connect-button/DefaultSlackConnectButton.d.cts +7 -0
- package/dist/cjs/components/slack-connect-button/SlackConnectButton.cjs +63 -0
- package/dist/cjs/components/slack-connect-button/SlackConnectButton.cjs.map +1 -0
- package/dist/cjs/components/slack-connect-button/SlackConnectButton.d.cts +12 -0
- package/dist/cjs/components/slack-link-user/DefaultSlackLinkUser.cjs +80 -0
- package/dist/cjs/components/slack-link-user/DefaultSlackLinkUser.cjs.map +1 -0
- package/dist/cjs/components/slack-link-user/DefaultSlackLinkUser.d.cts +7 -0
- package/dist/cjs/components/slack-link-user/SlackLinkUser.cjs +63 -0
- package/dist/cjs/components/slack-link-user/SlackLinkUser.cjs.map +1 -0
- package/dist/cjs/components/slack-link-user/SlackLinkUser.d.cts +12 -0
- package/dist/cjs/hooks/NovuProvider.cjs +34 -22
- package/dist/cjs/hooks/NovuProvider.cjs.map +1 -1
- package/dist/cjs/hooks/NovuProvider.d.cts +13 -2
- package/dist/cjs/hooks/index.cjs +10 -0
- package/dist/cjs/hooks/index.cjs.map +1 -1
- package/dist/cjs/hooks/index.d.cts +5 -0
- package/dist/cjs/hooks/internal/useBrowserTabsChannel.cjs +5 -2
- package/dist/cjs/hooks/internal/useBrowserTabsChannel.cjs.map +1 -1
- package/dist/cjs/hooks/internal/useBrowserTabsChannel.d.cts +2 -1
- package/dist/cjs/hooks/internal/useWebsocketEvent.cjs +6 -3
- package/dist/cjs/hooks/internal/useWebsocketEvent.cjs.map +1 -1
- package/dist/cjs/hooks/internal/useWebsocketEvent.d.cts +2 -1
- package/dist/cjs/hooks/useChannelConnection.cjs +107 -0
- package/dist/cjs/hooks/useChannelConnection.cjs.map +1 -0
- package/dist/cjs/hooks/useChannelConnection.d.cts +20 -0
- package/dist/cjs/hooks/useChannelConnections.cjs +85 -0
- package/dist/cjs/hooks/useChannelConnections.cjs.map +1 -0
- package/dist/cjs/hooks/useChannelConnections.d.cts +24 -0
- package/dist/cjs/hooks/useChannelEndpoint.cjs +110 -0
- package/dist/cjs/hooks/useChannelEndpoint.cjs.map +1 -0
- package/dist/cjs/hooks/useChannelEndpoint.d.cts +20 -0
- package/dist/cjs/hooks/useCounts.cjs +5 -1
- package/dist/cjs/hooks/useCounts.cjs.map +1 -1
- package/dist/cjs/hooks/useCounts.d.cts +18 -0
- package/dist/cjs/hooks/useCreateChannelEndpoint.cjs +61 -0
- package/dist/cjs/hooks/useCreateChannelEndpoint.cjs.map +1 -0
- package/dist/cjs/hooks/useCreateChannelEndpoint.d.cts +17 -0
- package/dist/cjs/hooks/useDeleteChannelEndpoint.cjs +69 -0
- package/dist/cjs/hooks/useDeleteChannelEndpoint.cjs.map +1 -0
- package/dist/cjs/hooks/useDeleteChannelEndpoint.d.cts +17 -0
- package/dist/cjs/hooks/useNotifications.cjs +4 -0
- package/dist/cjs/hooks/useNotifications.cjs.map +1 -1
- package/dist/cjs/hooks/useNotifications.d.cts +18 -0
- package/dist/cjs/index.cjs +14 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +11 -2
- package/dist/cjs/internal/index.d.cts +1 -0
- package/dist/cjs/themes/index.d.cts +0 -1
- package/dist/cjs/utils/appearance.cjs.map +1 -1
- package/dist/cjs/utils/appearance.d.cts +2 -2
- package/dist/cjs/utils/types.d.cts +1 -1
- package/dist/esm/components/NovuUI.d.ts +2 -2
- package/dist/esm/components/NovuUI.js.map +1 -1
- package/dist/esm/components/connect-chat/ConnectChat.d.ts +12 -0
- package/dist/esm/components/connect-chat/ConnectChat.js +28 -0
- package/dist/esm/components/connect-chat/ConnectChat.js.map +1 -0
- package/dist/esm/components/connect-chat/DefaultConnectChat.d.ts +7 -0
- package/dist/esm/components/connect-chat/DefaultConnectChat.js +58 -0
- package/dist/esm/components/connect-chat/DefaultConnectChat.js.map +1 -0
- package/dist/esm/components/index.d.ts +5 -1
- package/dist/esm/components/index.js +2 -0
- package/dist/esm/components/index.js.map +1 -1
- package/dist/esm/components/slack-connect-button/DefaultSlackConnectButton.d.ts +7 -0
- package/dist/esm/components/slack-connect-button/DefaultSlackConnectButton.js +64 -0
- package/dist/esm/components/slack-connect-button/DefaultSlackConnectButton.js.map +1 -0
- package/dist/esm/components/slack-connect-button/SlackConnectButton.d.ts +12 -0
- package/dist/esm/components/slack-connect-button/SlackConnectButton.js +28 -0
- package/dist/esm/components/slack-connect-button/SlackConnectButton.js.map +1 -0
- package/dist/esm/components/slack-link-user/DefaultSlackLinkUser.d.ts +7 -0
- package/dist/esm/components/slack-link-user/DefaultSlackLinkUser.js +55 -0
- package/dist/esm/components/slack-link-user/DefaultSlackLinkUser.js.map +1 -0
- package/dist/esm/components/slack-link-user/SlackLinkUser.d.ts +12 -0
- package/dist/esm/components/slack-link-user/SlackLinkUser.js +28 -0
- package/dist/esm/components/slack-link-user/SlackLinkUser.js.map +1 -0
- package/dist/esm/hooks/NovuProvider.d.ts +13 -2
- package/dist/esm/hooks/NovuProvider.js +33 -22
- package/dist/esm/hooks/NovuProvider.js.map +1 -1
- package/dist/esm/hooks/index.d.ts +5 -0
- package/dist/esm/hooks/index.js +5 -0
- package/dist/esm/hooks/index.js.map +1 -1
- package/dist/esm/hooks/internal/useBrowserTabsChannel.d.ts +2 -1
- package/dist/esm/hooks/internal/useBrowserTabsChannel.js +5 -2
- package/dist/esm/hooks/internal/useBrowserTabsChannel.js.map +1 -1
- package/dist/esm/hooks/internal/useWebsocketEvent.d.ts +2 -1
- package/dist/esm/hooks/internal/useWebsocketEvent.js +6 -3
- package/dist/esm/hooks/internal/useWebsocketEvent.js.map +1 -1
- package/dist/esm/hooks/useChannelConnection.d.ts +20 -0
- package/dist/esm/hooks/useChannelConnection.js +81 -0
- package/dist/esm/hooks/useChannelConnection.js.map +1 -0
- package/dist/esm/hooks/useChannelConnections.d.ts +24 -0
- package/dist/esm/hooks/useChannelConnections.js +60 -0
- package/dist/esm/hooks/useChannelConnections.js.map +1 -0
- package/dist/esm/hooks/useChannelEndpoint.d.ts +20 -0
- package/dist/esm/hooks/useChannelEndpoint.js +83 -0
- package/dist/esm/hooks/useChannelEndpoint.js.map +1 -0
- package/dist/esm/hooks/useCounts.d.ts +18 -0
- package/dist/esm/hooks/useCounts.js +6 -2
- package/dist/esm/hooks/useCounts.js.map +1 -1
- package/dist/esm/hooks/useCreateChannelEndpoint.d.ts +17 -0
- package/dist/esm/hooks/useCreateChannelEndpoint.js +36 -0
- package/dist/esm/hooks/useCreateChannelEndpoint.js.map +1 -0
- package/dist/esm/hooks/useDeleteChannelEndpoint.d.ts +17 -0
- package/dist/esm/hooks/useDeleteChannelEndpoint.js +43 -0
- package/dist/esm/hooks/useDeleteChannelEndpoint.js.map +1 -0
- package/dist/esm/hooks/useNotifications.d.ts +18 -0
- package/dist/esm/hooks/useNotifications.js +5 -1
- package/dist/esm/hooks/useNotifications.js.map +1 -1
- package/dist/esm/index.d.ts +11 -2
- package/dist/esm/index.js +14 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/appearance.d.ts +2 -2
- package/dist/esm/utils/appearance.js.map +1 -1
- package/dist/esm/utils/types.d.ts +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,110 @@
|
|
|
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/useChannelEndpoint.ts
|
|
21
|
+
var useChannelEndpoint_exports = {};
|
|
22
|
+
__export(useChannelEndpoint_exports, {
|
|
23
|
+
useChannelEndpoint: () => useChannelEndpoint
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(useChannelEndpoint_exports);
|
|
26
|
+
var import_react = require("react");
|
|
27
|
+
var import_NovuProvider = require("./NovuProvider.cjs");
|
|
28
|
+
var useChannelEndpoint = (props) => {
|
|
29
|
+
const novu = (0, import_NovuProvider.useNovu)();
|
|
30
|
+
const propsRef = (0, import_react.useRef)(props);
|
|
31
|
+
propsRef.current = props;
|
|
32
|
+
const [endpoint, setEndpoint] = (0, import_react.useState)();
|
|
33
|
+
const [error, setError] = (0, import_react.useState)();
|
|
34
|
+
const [isLoading, setIsLoading] = (0, import_react.useState)(true);
|
|
35
|
+
const [isFetching, setIsFetching] = (0, import_react.useState)(false);
|
|
36
|
+
const fetchEndpoint = (0, import_react.useCallback)(
|
|
37
|
+
async (options) => {
|
|
38
|
+
const { identifier, onSuccess, onError } = propsRef.current;
|
|
39
|
+
if (options == null ? void 0 : options.refetch) {
|
|
40
|
+
setError(void 0);
|
|
41
|
+
setIsLoading(true);
|
|
42
|
+
}
|
|
43
|
+
setIsFetching(true);
|
|
44
|
+
const response = await novu.channelEndpoints.get({ identifier });
|
|
45
|
+
if (response.error) {
|
|
46
|
+
setError(response.error);
|
|
47
|
+
onError == null ? void 0 : onError(response.error);
|
|
48
|
+
} else if (response.data !== void 0) {
|
|
49
|
+
onSuccess == null ? void 0 : onSuccess(response.data);
|
|
50
|
+
setEndpoint(response.data);
|
|
51
|
+
}
|
|
52
|
+
setIsLoading(false);
|
|
53
|
+
setIsFetching(false);
|
|
54
|
+
},
|
|
55
|
+
[novu]
|
|
56
|
+
);
|
|
57
|
+
(0, import_react.useEffect)(() => {
|
|
58
|
+
const cleanupGetPending = novu.on("channel-endpoint.get.pending", () => {
|
|
59
|
+
setIsFetching(true);
|
|
60
|
+
});
|
|
61
|
+
const cleanupGetResolved = novu.on("channel-endpoint.get.resolved", ({ data, error: resolvedError }) => {
|
|
62
|
+
const { onSuccess, onError } = propsRef.current;
|
|
63
|
+
if (resolvedError) {
|
|
64
|
+
setError(resolvedError);
|
|
65
|
+
onError == null ? void 0 : onError(resolvedError);
|
|
66
|
+
} else {
|
|
67
|
+
setEndpoint(data ?? null);
|
|
68
|
+
onSuccess == null ? void 0 : onSuccess(data ?? null);
|
|
69
|
+
}
|
|
70
|
+
setIsFetching(false);
|
|
71
|
+
});
|
|
72
|
+
const cleanupCreateResolved = novu.on("channel-endpoint.create.resolved", ({ data }) => {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
if (data) {
|
|
75
|
+
setEndpoint(data);
|
|
76
|
+
(_b = (_a = propsRef.current).onSuccess) == null ? void 0 : _b.call(_a, data);
|
|
77
|
+
}
|
|
78
|
+
setIsFetching(false);
|
|
79
|
+
});
|
|
80
|
+
const cleanupDeleteResolved = novu.on("channel-endpoint.delete.resolved", ({ args }) => {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
if (!args || args.identifier !== propsRef.current.identifier) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
setEndpoint(null);
|
|
86
|
+
(_b = (_a = propsRef.current).onSuccess) == null ? void 0 : _b.call(_a, null);
|
|
87
|
+
setIsFetching(false);
|
|
88
|
+
});
|
|
89
|
+
void fetchEndpoint({ refetch: true });
|
|
90
|
+
return () => {
|
|
91
|
+
cleanupGetPending();
|
|
92
|
+
cleanupGetResolved();
|
|
93
|
+
cleanupCreateResolved();
|
|
94
|
+
cleanupDeleteResolved();
|
|
95
|
+
};
|
|
96
|
+
}, [novu, fetchEndpoint, props.identifier]);
|
|
97
|
+
const refetch = (0, import_react.useCallback)(() => fetchEndpoint({ refetch: true }), [fetchEndpoint]);
|
|
98
|
+
return {
|
|
99
|
+
endpoint,
|
|
100
|
+
error,
|
|
101
|
+
isLoading,
|
|
102
|
+
isFetching,
|
|
103
|
+
refetch
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
107
|
+
0 && (module.exports = {
|
|
108
|
+
useChannelEndpoint
|
|
109
|
+
});
|
|
110
|
+
//# sourceMappingURL=useChannelEndpoint.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/useChannelEndpoint.ts"],"sourcesContent":["import type { ChannelEndpointResponse, NovuError } from '@novu/js';\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { useNovu } from './NovuProvider';\n\nexport type UseChannelEndpointProps = {\n identifier: string;\n onSuccess?: (data: ChannelEndpointResponse | null) => void;\n onError?: (error: NovuError) => void;\n};\n\nexport type UseChannelEndpointResult = {\n endpoint?: ChannelEndpointResponse | null;\n error?: NovuError;\n isLoading: boolean;\n isFetching: boolean;\n refetch: () => Promise<void>;\n};\n\n/**\n * Get a channel endpoint by identifier.\n */\nexport const useChannelEndpoint = (props: UseChannelEndpointProps): UseChannelEndpointResult => {\n const novu = useNovu();\n const propsRef = useRef<UseChannelEndpointProps>(props);\n propsRef.current = props;\n\n const [endpoint, setEndpoint] = useState<ChannelEndpointResponse | null>();\n const [error, setError] = useState<NovuError>();\n const [isLoading, setIsLoading] = useState(true);\n const [isFetching, setIsFetching] = useState(false);\n\n const fetchEndpoint = useCallback(\n async (options?: { refetch: boolean }) => {\n const { identifier, onSuccess, onError } = propsRef.current;\n if (options?.refetch) {\n setError(undefined);\n setIsLoading(true);\n }\n\n setIsFetching(true);\n\n const response = await novu.channelEndpoints.get({ identifier });\n\n if (response.error) {\n setError(response.error as NovuError);\n onError?.(response.error as NovuError);\n } else if (response.data !== undefined) {\n onSuccess?.(response.data);\n setEndpoint(response.data);\n }\n setIsLoading(false);\n setIsFetching(false);\n },\n [novu]\n );\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: props.identifier is needed to re-run the effect and initial fetch when the identifier changes\n useEffect(() => {\n const cleanupGetPending = novu.on('channel-endpoint.get.pending', () => {\n setIsFetching(true);\n });\n\n const cleanupGetResolved = novu.on('channel-endpoint.get.resolved', ({ data, error: resolvedError }) => {\n const { onSuccess, onError } = propsRef.current;\n if (resolvedError) {\n setError(resolvedError as NovuError);\n onError?.(resolvedError as NovuError);\n } else {\n setEndpoint((data as ChannelEndpointResponse) ?? null);\n onSuccess?.((data as ChannelEndpointResponse) ?? null);\n }\n setIsFetching(false);\n });\n\n const cleanupCreateResolved = novu.on('channel-endpoint.create.resolved', ({ data }) => {\n if (data) {\n setEndpoint(data as ChannelEndpointResponse);\n propsRef.current.onSuccess?.(data as ChannelEndpointResponse);\n }\n setIsFetching(false);\n });\n\n const cleanupDeleteResolved = novu.on('channel-endpoint.delete.resolved', ({ args }) => {\n if (!args || args.identifier !== propsRef.current.identifier) {\n return;\n }\n setEndpoint(null);\n propsRef.current.onSuccess?.(null);\n setIsFetching(false);\n });\n\n void fetchEndpoint({ refetch: true });\n\n return () => {\n cleanupGetPending();\n cleanupGetResolved();\n cleanupCreateResolved();\n cleanupDeleteResolved();\n };\n }, [novu, fetchEndpoint, props.identifier]);\n\n const refetch = useCallback(() => fetchEndpoint({ refetch: true }), [fetchEndpoint]);\n\n return {\n endpoint,\n error,\n isLoading,\n isFetching,\n refetch,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAyD;AACzD,0BAAwB;AAmBjB,IAAM,qBAAqB,CAAC,UAA6D;AAC9F,QAAM,WAAO,6BAAQ;AACrB,QAAM,eAAW,qBAAgC,KAAK;AACtD,WAAS,UAAU;AAEnB,QAAM,CAAC,UAAU,WAAW,QAAI,uBAAyC;AACzE,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAoB;AAC9C,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,IAAI;AAC/C,QAAM,CAAC,YAAY,aAAa,QAAI,uBAAS,KAAK;AAElD,QAAM,oBAAgB;AAAA,IACpB,OAAO,YAAmC;AACxC,YAAM,EAAE,YAAY,WAAW,QAAQ,IAAI,SAAS;AACpD,UAAI,mCAAS,SAAS;AACpB,iBAAS,MAAS;AAClB,qBAAa,IAAI;AAAA,MACnB;AAEA,oBAAc,IAAI;AAElB,YAAM,WAAW,MAAM,KAAK,iBAAiB,IAAI,EAAE,WAAW,CAAC;AAE/D,UAAI,SAAS,OAAO;AAClB,iBAAS,SAAS,KAAkB;AACpC,2CAAU,SAAS;AAAA,MACrB,WAAW,SAAS,SAAS,QAAW;AACtC,+CAAY,SAAS;AACrB,oBAAY,SAAS,IAAI;AAAA,MAC3B;AACA,mBAAa,KAAK;AAClB,oBAAc,KAAK;AAAA,IACrB;AAAA,IACA,CAAC,IAAI;AAAA,EACP;AAGA,8BAA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} from '@novu/js';
|
|
2
|
+
|
|
3
|
+
type UseChannelEndpointProps = {
|
|
4
|
+
identifier: string;
|
|
5
|
+
onSuccess?: (data: ChannelEndpointResponse | null) => void;
|
|
6
|
+
onError?: (error: NovuError) => void;
|
|
7
|
+
};
|
|
8
|
+
type UseChannelEndpointResult = {
|
|
9
|
+
endpoint?: ChannelEndpointResponse | null;
|
|
10
|
+
error?: NovuError;
|
|
11
|
+
isLoading: boolean;
|
|
12
|
+
isFetching: boolean;
|
|
13
|
+
refetch: () => Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Get a channel endpoint by identifier.
|
|
17
|
+
*/
|
|
18
|
+
declare const useChannelEndpoint: (props: UseChannelEndpointProps) => UseChannelEndpointResult;
|
|
19
|
+
|
|
20
|
+
export { type UseChannelEndpointProps, type UseChannelEndpointResult, useChannelEndpoint };
|
|
@@ -29,8 +29,10 @@ var import_useDataRef = require("./internal/useDataRef.cjs");
|
|
|
29
29
|
var import_useWebsocketEvent = require("./internal/useWebsocketEvent.cjs");
|
|
30
30
|
var import_NovuProvider = require("./NovuProvider.cjs");
|
|
31
31
|
var useCounts = (props) => {
|
|
32
|
-
const { filters, onSuccess, onError } = props;
|
|
32
|
+
const { filters, realtime: propsRealtime, onSuccess, onError } = props;
|
|
33
33
|
const { notifications } = (0, import_NovuProvider.useNovu)();
|
|
34
|
+
const providerRealtime = (0, import_NovuProvider.useRealtime)();
|
|
35
|
+
const realtime = propsRealtime ?? providerRealtime;
|
|
34
36
|
const filtersRef = (0, import_useDataRef.useDataRef)(filters);
|
|
35
37
|
const [error, setError] = (0, import_react.useState)();
|
|
36
38
|
const [counts, setCounts] = (0, import_react.useState)();
|
|
@@ -81,12 +83,14 @@ var useCounts = (props) => {
|
|
|
81
83
|
};
|
|
82
84
|
(0, import_useWebsocketEvent.useWebSocketEvent)({
|
|
83
85
|
event: "notifications.notification_received",
|
|
86
|
+
enabled: realtime,
|
|
84
87
|
eventHandler: (data) => {
|
|
85
88
|
sync(data.result);
|
|
86
89
|
}
|
|
87
90
|
});
|
|
88
91
|
(0, import_useWebsocketEvent.useWebSocketEvent)({
|
|
89
92
|
event: "notifications.unread_count_changed",
|
|
93
|
+
enabled: realtime,
|
|
90
94
|
eventHandler: () => {
|
|
91
95
|
sync();
|
|
92
96
|
}
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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, useRealtime } 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 * // Opt out of the built-in realtime count updates and drive them yourself\n * const { counts, refetch } = useCounts({\n * filters: [{ read: false }],\n * realtime: false,\n * });\n * ```\n */\nexport type UseCountsProps = {\n filters: NotificationFilter[];\n /**\n * When `false`, disables the WebSocket subscriptions that auto-resync\n * counts on `notifications.notification_received` and\n * `notifications.unread_count_changed`. The filter-driven fetch and\n * `refetch()` keep working. Use alongside\n * `useNotifications({ realtime: false })` when you drive live updates\n * yourself.\n *\n * When set, this prop takes precedence over the `realtime` config on\n * `<NovuProvider />`. When omitted, the provider value (default `true`) is used.\n */\n realtime?: boolean;\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, realtime: propsRealtime, onSuccess, onError } = props;\n const { notifications } = useNovu();\n const providerRealtime = useRealtime();\n const realtime = propsRealtime ?? providerRealtime;\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 enabled: realtime,\n eventHandler: (data) => {\n sync(data.result);\n },\n });\n\n useWebSocketEvent({\n event: 'notifications.unread_count_changed',\n enabled: realtime,\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;A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AAM,YAAY,MAAM,cAAc,MAAM,EAAE,SAAS,oBAAoB,CAAC;AAC5E,kBAAc,KAAK;AACnB,iBAAa,KAAK;AAClB,QAAI,UAAU,OAAO;AACnB,eAAS,UAAU,KAAK;AACxB,yCAAU,UAAU;AAEpB;AAAA,IACF;AACA,UAAM,OAAO,UAAU;AACvB,2CAAY,KAAK;AAEjB,cAAU,CAAC,cAAc;AACvB,YAAM,YAAqB,CAAC;AAC5B,YAAM,iBAAiB,KAAK;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,SAAS;AAAA,IACT,cAAc,CAAC,SAAS;AACtB,WAAK,KAAK,MAAM;AAAA,IAClB;AAAA,EACF,CAAC;AAED,kDAAkB;AAAA,IAChB,OAAO;AAAA,IACP,SAAS;AAAA,IACT,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":[]}
|
|
@@ -23,10 +23,28 @@ type Count = {
|
|
|
23
23
|
* const { counts } = useCounts({
|
|
24
24
|
* filters: [{ seen: true, read: false }]
|
|
25
25
|
* });
|
|
26
|
+
*
|
|
27
|
+
* // Opt out of the built-in realtime count updates and drive them yourself
|
|
28
|
+
* const { counts, refetch } = useCounts({
|
|
29
|
+
* filters: [{ read: false }],
|
|
30
|
+
* realtime: false,
|
|
31
|
+
* });
|
|
26
32
|
* ```
|
|
27
33
|
*/
|
|
28
34
|
type UseCountsProps = {
|
|
29
35
|
filters: NotificationFilter[];
|
|
36
|
+
/**
|
|
37
|
+
* When `false`, disables the WebSocket subscriptions that auto-resync
|
|
38
|
+
* counts on `notifications.notification_received` and
|
|
39
|
+
* `notifications.unread_count_changed`. The filter-driven fetch and
|
|
40
|
+
* `refetch()` keep working. Use alongside
|
|
41
|
+
* `useNotifications({ realtime: false })` when you drive live updates
|
|
42
|
+
* yourself.
|
|
43
|
+
*
|
|
44
|
+
* When set, this prop takes precedence over the `realtime` config on
|
|
45
|
+
* `<NovuProvider />`. When omitted, the provider value (default `true`) is used.
|
|
46
|
+
*/
|
|
47
|
+
realtime?: boolean;
|
|
30
48
|
onSuccess?: (data: Count[]) => void;
|
|
31
49
|
onError?: (error: NovuError) => void;
|
|
32
50
|
};
|
|
@@ -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/useCreateChannelEndpoint.ts
|
|
21
|
+
var useCreateChannelEndpoint_exports = {};
|
|
22
|
+
__export(useCreateChannelEndpoint_exports, {
|
|
23
|
+
useCreateChannelEndpoint: () => useCreateChannelEndpoint
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(useCreateChannelEndpoint_exports);
|
|
26
|
+
var import_react = require("react");
|
|
27
|
+
var import_NovuProvider = require("./NovuProvider.cjs");
|
|
28
|
+
var useCreateChannelEndpoint = (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.channelEndpoints.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
|
+
useCreateChannelEndpoint
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=useCreateChannelEndpoint.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/useCreateChannelEndpoint.ts"],"sourcesContent":["import type { ChannelEndpointResponse, CreateChannelEndpointArgs, NovuError } from '@novu/js';\nimport { useCallback, useRef, useState } from 'react';\nimport { useNovu } from './NovuProvider';\n\nexport type UseCreateChannelEndpointProps = {\n onSuccess?: (data: ChannelEndpointResponse) => void;\n onError?: (error: NovuError) => void;\n};\n\nexport type UseCreateChannelEndpointResult = {\n isCreating: boolean;\n error?: NovuError;\n create: (args: CreateChannelEndpointArgs) => Promise<{\n data?: ChannelEndpointResponse | undefined;\n error?: NovuError | undefined;\n }>;\n};\n\nexport const useCreateChannelEndpoint = (props: UseCreateChannelEndpointProps = {}): UseCreateChannelEndpointResult => {\n const propsRef = useRef<UseCreateChannelEndpointProps>(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: CreateChannelEndpointArgs) => {\n const { onSuccess, onError } = propsRef.current;\n setError(undefined);\n setIsCreating(true);\n\n const response = await novu.channelEndpoints.create(args);\n\n setIsCreating(false);\n\n if (response.error) {\n setError(response.error as NovuError);\n onError?.(response.error as NovuError);\n } else if (response.data) {\n onSuccess?.(response.data as ChannelEndpointResponse);\n }\n\n return response as { data?: ChannelEndpointResponse; error?: NovuError };\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,2BAA2B,CAAC,QAAuC,CAAC,MAAsC;AACrH,QAAM,eAAW,qBAAsC,KAAK;AAC5D,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,SAAoC;AACzC,YAAM,EAAE,WAAW,QAAQ,IAAI,SAAS;AACxC,eAAS,MAAS;AAClB,oBAAc,IAAI;AAElB,YAAM,WAAW,MAAM,KAAK,iBAAiB,OAAO,IAAI;AAExD,oBAAc,KAAK;AAEnB,UAAI,SAAS,OAAO;AAClB,iBAAS,SAAS,KAAkB;AACpC,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 { ChannelEndpointResponse, NovuError, CreateChannelEndpointArgs } from '@novu/js';
|
|
2
|
+
|
|
3
|
+
type UseCreateChannelEndpointProps = {
|
|
4
|
+
onSuccess?: (data: ChannelEndpointResponse) => void;
|
|
5
|
+
onError?: (error: NovuError) => void;
|
|
6
|
+
};
|
|
7
|
+
type UseCreateChannelEndpointResult = {
|
|
8
|
+
isCreating: boolean;
|
|
9
|
+
error?: NovuError;
|
|
10
|
+
create: (args: CreateChannelEndpointArgs) => Promise<{
|
|
11
|
+
data?: ChannelEndpointResponse | undefined;
|
|
12
|
+
error?: NovuError | undefined;
|
|
13
|
+
}>;
|
|
14
|
+
};
|
|
15
|
+
declare const useCreateChannelEndpoint: (props?: UseCreateChannelEndpointProps) => UseCreateChannelEndpointResult;
|
|
16
|
+
|
|
17
|
+
export { type UseCreateChannelEndpointProps, type UseCreateChannelEndpointResult, useCreateChannelEndpoint };
|
|
@@ -0,0 +1,69 @@
|
|
|
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/useDeleteChannelEndpoint.ts
|
|
21
|
+
var useDeleteChannelEndpoint_exports = {};
|
|
22
|
+
__export(useDeleteChannelEndpoint_exports, {
|
|
23
|
+
useDeleteChannelEndpoint: () => useDeleteChannelEndpoint
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(useDeleteChannelEndpoint_exports);
|
|
26
|
+
var import_react = require("react");
|
|
27
|
+
var import_NovuProvider = require("./NovuProvider.cjs");
|
|
28
|
+
var useDeleteChannelEndpoint = (props = {}) => {
|
|
29
|
+
const propsRef = (0, import_react.useRef)(props);
|
|
30
|
+
propsRef.current = props;
|
|
31
|
+
const novu = (0, import_NovuProvider.useNovu)();
|
|
32
|
+
const [isDeleting, setIsDeleting] = (0, import_react.useState)(false);
|
|
33
|
+
const [error, setError] = (0, import_react.useState)();
|
|
34
|
+
const remove = (0, import_react.useCallback)(
|
|
35
|
+
async (identifier) => {
|
|
36
|
+
var _a, _b, _c, _d, _e, _f;
|
|
37
|
+
setError(void 0);
|
|
38
|
+
setIsDeleting(true);
|
|
39
|
+
try {
|
|
40
|
+
const response = await novu.channelEndpoints.delete({ identifier });
|
|
41
|
+
if (response.error) {
|
|
42
|
+
setError(response.error);
|
|
43
|
+
(_b = (_a = propsRef.current).onError) == null ? void 0 : _b.call(_a, response.error);
|
|
44
|
+
} else {
|
|
45
|
+
(_d = (_c = propsRef.current).onSuccess) == null ? void 0 : _d.call(_c);
|
|
46
|
+
}
|
|
47
|
+
return response;
|
|
48
|
+
} catch (err) {
|
|
49
|
+
const novuError = err;
|
|
50
|
+
setError(novuError);
|
|
51
|
+
(_f = (_e = propsRef.current).onError) == null ? void 0 : _f.call(_e, novuError);
|
|
52
|
+
return { error: novuError };
|
|
53
|
+
} finally {
|
|
54
|
+
setIsDeleting(false);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
[novu]
|
|
58
|
+
);
|
|
59
|
+
return {
|
|
60
|
+
remove,
|
|
61
|
+
isDeleting,
|
|
62
|
+
error
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
useDeleteChannelEndpoint
|
|
68
|
+
});
|
|
69
|
+
//# sourceMappingURL=useDeleteChannelEndpoint.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/useDeleteChannelEndpoint.ts"],"sourcesContent":["import type { NovuError } from '@novu/js';\nimport { useCallback, useRef, useState } from 'react';\nimport { useNovu } from './NovuProvider';\n\nexport type UseDeleteChannelEndpointProps = {\n onSuccess?: () => void;\n onError?: (error: NovuError) => void;\n};\n\nexport type UseDeleteChannelEndpointResult = {\n isDeleting: boolean;\n error?: NovuError;\n remove: (identifier: string) => Promise<{\n data?: undefined;\n error?: NovuError | undefined;\n }>;\n};\n\nexport const useDeleteChannelEndpoint = (props: UseDeleteChannelEndpointProps = {}): UseDeleteChannelEndpointResult => {\n const propsRef = useRef<UseDeleteChannelEndpointProps>(props);\n propsRef.current = props;\n const novu = useNovu();\n const [isDeleting, setIsDeleting] = useState(false);\n const [error, setError] = useState<NovuError>();\n\n const remove = useCallback(\n async (identifier: string) => {\n setError(undefined);\n setIsDeleting(true);\n\n try {\n const response = await novu.channelEndpoints.delete({ identifier });\n\n if (response.error) {\n setError(response.error as NovuError);\n propsRef.current.onError?.(response.error as NovuError);\n } else {\n propsRef.current.onSuccess?.();\n }\n\n return response as { data?: undefined; error?: NovuError };\n } catch (err) {\n const novuError = err as NovuError;\n setError(novuError);\n propsRef.current.onError?.(novuError);\n\n return { error: novuError };\n } finally {\n setIsDeleting(false);\n }\n },\n [novu]\n );\n\n return {\n remove,\n isDeleting,\n error,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA8C;AAC9C,0BAAwB;AAgBjB,IAAM,2BAA2B,CAAC,QAAuC,CAAC,MAAsC;AACrH,QAAM,eAAW,qBAAsC,KAAK;AAC5D,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,eAAuB;AA1BlC;AA2BM,eAAS,MAAS;AAClB,oBAAc,IAAI;AAElB,UAAI;AACF,cAAM,WAAW,MAAM,KAAK,iBAAiB,OAAO,EAAE,WAAW,CAAC;AAElE,YAAI,SAAS,OAAO;AAClB,mBAAS,SAAS,KAAkB;AACpC,+BAAS,SAAQ,YAAjB,4BAA2B,SAAS;AAAA,QACtC,OAAO;AACL,+BAAS,SAAQ,cAAjB;AAAA,QACF;AAEA,eAAO;AAAA,MACT,SAAS,KAAK;AACZ,cAAM,YAAY;AAClB,iBAAS,SAAS;AAClB,6BAAS,SAAQ,YAAjB,4BAA2B;AAE3B,eAAO,EAAE,OAAO,UAAU;AAAA,MAC5B,UAAE;AACA,sBAAc,KAAK;AAAA,MACrB;AAAA,IACF;AAAA,IACA,CAAC,IAAI;AAAA,EACP;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { NovuError } from '@novu/js';
|
|
2
|
+
|
|
3
|
+
type UseDeleteChannelEndpointProps = {
|
|
4
|
+
onSuccess?: () => void;
|
|
5
|
+
onError?: (error: NovuError) => void;
|
|
6
|
+
};
|
|
7
|
+
type UseDeleteChannelEndpointResult = {
|
|
8
|
+
isDeleting: boolean;
|
|
9
|
+
error?: NovuError;
|
|
10
|
+
remove: (identifier: string) => Promise<{
|
|
11
|
+
data?: undefined;
|
|
12
|
+
error?: NovuError | undefined;
|
|
13
|
+
}>;
|
|
14
|
+
};
|
|
15
|
+
declare const useDeleteChannelEndpoint: (props?: UseDeleteChannelEndpointProps) => UseDeleteChannelEndpointResult;
|
|
16
|
+
|
|
17
|
+
export { type UseDeleteChannelEndpointProps, type UseDeleteChannelEndpointResult, useDeleteChannelEndpoint };
|
|
@@ -40,6 +40,7 @@ var useNotifications = (props) => {
|
|
|
40
40
|
createdGte,
|
|
41
41
|
createdLte,
|
|
42
42
|
limit = 10,
|
|
43
|
+
realtime: propsRealtime,
|
|
43
44
|
onSuccess,
|
|
44
45
|
onError
|
|
45
46
|
} = props || {};
|
|
@@ -56,6 +57,8 @@ var useNotifications = (props) => {
|
|
|
56
57
|
createdLte
|
|
57
58
|
});
|
|
58
59
|
const novu = (0, import_NovuProvider.useNovu)();
|
|
60
|
+
const providerRealtime = (0, import_NovuProvider.useRealtime)();
|
|
61
|
+
const realtime = propsRealtime ?? providerRealtime;
|
|
59
62
|
const [data, setData] = (0, import_react.useState)();
|
|
60
63
|
const [error, setError] = (0, import_react.useState)();
|
|
61
64
|
const [isLoading, setIsLoading] = (0, import_react.useState)(true);
|
|
@@ -81,6 +84,7 @@ var useNotifications = (props) => {
|
|
|
81
84
|
}, [filterRef, novu]);
|
|
82
85
|
(0, import_useWebsocketEvent.useWebSocketEvent)({
|
|
83
86
|
event: "notifications.notification_received",
|
|
87
|
+
enabled: realtime,
|
|
84
88
|
eventHandler: ({ result: notification }) => {
|
|
85
89
|
const currentFilter = filterRef.current;
|
|
86
90
|
const matches = (0, import_js.checkNotificationMatchesFilter)(notification, currentFilter);
|
|
@@ -1 +1 @@
|
|
|
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 * // Get notifications from a specific time period\n * const { notifications } = useNotifications({\n * createdGte: 1704067200000,\n * createdLte: 1735689599999\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 createdGte?: NotificationFilter['createdGte'];\n createdLte?: NotificationFilter['createdLte'];\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 createdGte,\n createdLte,\n limit = 10,\n onSuccess,\n onError,\n } = props || {};\n const limitRef = useDataRef<number | undefined>(limit);\n const filterRef = useDataRef<NotificationFilter>({\n tags,\n data: dataFilter,\n read,\n archived,\n snoozed,\n seen,\n severity,\n createdGte,\n createdLte,\n });\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;A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A,EAC7C,GAAG,CAAC,WAAW,MAAM,kBAAkB,CAAC;AAExC,QAAM,gBAAY,0BAAY,YAAY;AACxC,QAAI,CAAC,WAAW,WAAY;AAE5B,WAAO,mBAAmB;AAAA,EAC5B,GAAG,CAAC,SAAS,YAAY,kBAAkB,CAAC;AAE5C,QAAM,cAAU,0BAAY,YAAY;AACtC,WAAO,MAAM,KAAK,cAAc,QAAQ,EAAE,MAAM,UAAU,QAAQ,MAAM,MAAM,UAAU,QAAQ,KAAK,CAAC;AAAA,EACxG,GAAG,CAAC,WAAW,IAAI,CAAC;AAEpB,QAAM,cAAU,0BAAY,YAAY;AACtC,WAAO,MAAM,KAAK,cAAc,QAAQ,EAAE,MAAM,UAAU,QAAQ,MAAM,MAAM,UAAU,QAAQ,KAAK,CAAC;AAAA,EACxG,GAAG,CAAC,WAAW,IAAI,CAAC;AAEpB,QAAM,iBAAa,0BAAY,YAAY;AACzC,WAAO,MAAM,KAAK,cAAc,WAAW,EAAE,MAAM,UAAU,QAAQ,MAAM,MAAM,UAAU,QAAQ,KAAK,CAAC;AAAA,EAC3G,GAAG,CAAC,WAAW,IAAI,CAAC;AAEpB,QAAM,qBAAiB,0BAAY,YAAY;AAC7C,WAAO,MAAM,KAAK,cAAc,eAAe,EAAE,MAAM,UAAU,QAAQ,MAAM,MAAM,UAAU,QAAQ,KAAK,CAAC;AAAA,EAC/G,GAAG,CAAC,WAAW,IAAI,CAAC;AAEpB,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["data"]}
|
|
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, useRealtime } 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 * // Get notifications from a specific time period\n * const { notifications } = useNotifications({\n * createdGte: 1704067200000,\n * createdLte: 1735689599999\n * });\n *\n * // Opt out of the built-in realtime updates and drive them yourself\n * const { notifications, refetch } = useNotifications({\n * read: false,\n * realtime: 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 createdGte?: NotificationFilter['createdGte'];\n createdLte?: NotificationFilter['createdLte'];\n limit?: number;\n /**\n * When `false`, disables the WebSocket subscription that auto-injects\n * newly received notifications into the list. Built-in mutations like\n * `readAll`, `seenAll`, `archiveAll`, and `archiveAllRead` continue to\n * update local state. Use this when you want to drive new-notification updates yourself (e.g.\n * via your own `novu.on('notifications.notification_received', ...)`\n * handler combined with `refetch()`).\n *\n * When set, this prop takes precedence over the `realtime` config on\n * `<NovuProvider />`. When omitted, the provider value (default `true`) is used.\n */\n realtime?: boolean;\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 createdGte,\n createdLte,\n limit = 10,\n realtime: propsRealtime,\n onSuccess,\n onError,\n } = props || {};\n const limitRef = useDataRef<number | undefined>(limit);\n const filterRef = useDataRef<NotificationFilter>({\n tags,\n data: dataFilter,\n read,\n archived,\n snoozed,\n seen,\n severity,\n createdGte,\n createdLte,\n });\n const novu = useNovu();\n const providerRealtime = useRealtime();\n const realtime = propsRealtime ?? providerRealtime;\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 enabled: realtime,\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;AA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'@novu/js';
|
|
|
26
26
|
* createdGte: 1704067200000,
|
|
27
27
|
* createdLte: 1735689599999
|
|
28
28
|
* });
|
|
29
|
+
*
|
|
30
|
+
* // Opt out of the built-in realtime updates and drive them yourself
|
|
31
|
+
* const { notifications, refetch } = useNotifications({
|
|
32
|
+
* read: false,
|
|
33
|
+
* realtime: false,
|
|
34
|
+
* });
|
|
29
35
|
* ```
|
|
30
36
|
*/
|
|
31
37
|
type UseNotificationsProps = {
|
|
@@ -39,6 +45,18 @@ type UseNotificationsProps = {
|
|
|
39
45
|
createdGte?: NotificationFilter['createdGte'];
|
|
40
46
|
createdLte?: NotificationFilter['createdLte'];
|
|
41
47
|
limit?: number;
|
|
48
|
+
/**
|
|
49
|
+
* When `false`, disables the WebSocket subscription that auto-injects
|
|
50
|
+
* newly received notifications into the list. Built-in mutations like
|
|
51
|
+
* `readAll`, `seenAll`, `archiveAll`, and `archiveAllRead` continue to
|
|
52
|
+
* update local state. Use this when you want to drive new-notification updates yourself (e.g.
|
|
53
|
+
* via your own `novu.on('notifications.notification_received', ...)`
|
|
54
|
+
* handler combined with `refetch()`).
|
|
55
|
+
*
|
|
56
|
+
* When set, this prop takes precedence over the `realtime` config on
|
|
57
|
+
* `<NovuProvider />`. When omitted, the provider value (default `true`) is used.
|
|
58
|
+
*/
|
|
59
|
+
realtime?: boolean;
|
|
42
60
|
onSuccess?: (data: Notification[]) => void;
|
|
43
61
|
onError?: (error: NovuError) => void;
|
|
44
62
|
};
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -28,12 +28,19 @@ __export(index_exports, {
|
|
|
28
28
|
PreferenceLevel: () => import_js.PreferenceLevel,
|
|
29
29
|
Preferences: () => import_components.Preferences,
|
|
30
30
|
SeverityLevelEnum: () => import_js.SeverityLevelEnum,
|
|
31
|
+
SlackConnectButton: () => import_components.SlackConnectButton,
|
|
32
|
+
SlackLinkUser: () => import_components.SlackLinkUser,
|
|
31
33
|
Subscription: () => import_components.Subscription,
|
|
32
34
|
SubscriptionButton: () => import_components.SubscriptionButton,
|
|
33
35
|
SubscriptionPreferences: () => import_components.SubscriptionPreferences,
|
|
34
36
|
WorkflowCriticalityEnum: () => import_js.WorkflowCriticalityEnum,
|
|
37
|
+
useChannelConnection: () => import_hooks.useChannelConnection,
|
|
38
|
+
useChannelConnections: () => import_hooks.useChannelConnections,
|
|
39
|
+
useChannelEndpoint: () => import_hooks.useChannelEndpoint,
|
|
35
40
|
useCounts: () => import_hooks.useCounts,
|
|
41
|
+
useCreateChannelEndpoint: () => import_hooks.useCreateChannelEndpoint,
|
|
36
42
|
useCreateSubscription: () => import_hooks.useCreateSubscription,
|
|
43
|
+
useDeleteChannelEndpoint: () => import_hooks.useDeleteChannelEndpoint,
|
|
37
44
|
useNotifications: () => import_hooks.useNotifications,
|
|
38
45
|
useNovu: () => import_hooks.useNovu,
|
|
39
46
|
usePreferences: () => import_hooks.usePreferences,
|
|
@@ -57,12 +64,19 @@ var import_hooks = require("./hooks/index.cjs");
|
|
|
57
64
|
PreferenceLevel,
|
|
58
65
|
Preferences,
|
|
59
66
|
SeverityLevelEnum,
|
|
67
|
+
SlackConnectButton,
|
|
68
|
+
SlackLinkUser,
|
|
60
69
|
Subscription,
|
|
61
70
|
SubscriptionButton,
|
|
62
71
|
SubscriptionPreferences,
|
|
63
72
|
WorkflowCriticalityEnum,
|
|
73
|
+
useChannelConnection,
|
|
74
|
+
useChannelConnections,
|
|
75
|
+
useChannelEndpoint,
|
|
64
76
|
useCounts,
|
|
77
|
+
useCreateChannelEndpoint,
|
|
65
78
|
useCreateSubscription,
|
|
79
|
+
useDeleteChannelEndpoint,
|
|
66
80
|
useNotifications,
|
|
67
81
|
useNovu,
|
|
68
82
|
usePreferences,
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export type * from '@novu/js';\nexport { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from '@novu/js';\n\nexport type {\n AllLocalization,\n AllLocalizationKey,\n ElementStyles,\n InboxAppearance,\n InboxAppearanceCallback,\n InboxAppearanceCallbackFunction,\n InboxAppearanceCallbackKeys,\n InboxAppearanceKey,\n InboxElements,\n InboxLocalization,\n InboxLocalizationKey,\n InboxTheme,\n NotificationActionClickHandler,\n NotificationClickHandler,\n NotificationRenderer,\n PreferenceGroups,\n PreferencesFilter,\n RouterPush,\n SubscriptionAppearance,\n SubscriptionAppearanceCallback,\n SubscriptionAppearanceCallbackFunction,\n SubscriptionAppearanceCallbackKeys,\n SubscriptionAppearanceKey,\n SubscriptionElements,\n SubscriptionLocalization,\n SubscriptionLocalizationKey,\n SubscriptionTheme,\n Tab,\n Variables,\n} from '@novu/js/ui';\nexport type {\n BellProps,\n InboxContentProps,\n InboxProps,\n NotificationProps,\n NovuProviderProps,\n SubscriptionButtonProps,\n SubscriptionPreferencesProps,\n SubscriptionProps,\n} from './components';\nexport {\n Bell,\n Inbox,\n InboxContent,\n Notifications,\n NovuProvider,\n Preferences,\n Subscription,\n SubscriptionButton,\n SubscriptionPreferences,\n} from './components';\nexport type {\n UseCountsProps,\n UseCountsResult,\n UseNotificationsProps,\n UseNotificationsResult,\n UsePreferencesResult,\n UseScheduleProps as UsePreferencesProps,\n} from './hooks';\nexport {\n useCounts,\n useCreateSubscription,\n useNotifications,\n useNovu,\n usePreferences,\n useRemoveSubscription,\n useSchedule,\n useSubscription,\n useSubscriptions,\n useUpdateSubscription,\n} from './hooks';\n\nexport type {\n BaseProps,\n BellRenderer,\n BodyRenderer,\n DefaultInboxProps,\n DefaultProps,\n NoRendererProps,\n NotificationRendererProps,\n NotificationsRenderer,\n ReactInboxAppearance,\n ReactInboxTheme,\n ReactSubscriptionAppearance,\n ReactSubscriptionTheme,\n SubjectBodyRendererProps,\n SubjectRenderer,\n WithChildrenProps,\n} from './utils/types';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,gBAA4E;
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export type * from '@novu/js';\nexport { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from '@novu/js';\n\nexport type {\n AllLocalization,\n AllLocalizationKey,\n ChannelConnectButtonIconKey,\n ElementStyles,\n InboxAppearance,\n InboxAppearanceCallback,\n InboxAppearanceCallbackFunction,\n InboxAppearanceCallbackKeys,\n InboxAppearanceKey,\n InboxElements,\n InboxLocalization,\n InboxLocalizationKey,\n InboxTheme,\n NotificationActionClickHandler,\n NotificationClickHandler,\n NotificationRenderer,\n PreferenceGroups,\n PreferencesFilter,\n RouterPush,\n SubscriptionAppearance,\n SubscriptionAppearanceCallback,\n SubscriptionAppearanceCallbackFunction,\n SubscriptionAppearanceCallbackKeys,\n SubscriptionAppearanceKey,\n SubscriptionElements,\n SubscriptionLocalization,\n SubscriptionLocalizationKey,\n SubscriptionTheme,\n Tab,\n Variables,\n} from '@novu/js/ui';\nexport type {\n BellProps,\n InboxContentProps,\n InboxProps,\n NotificationProps,\n NovuProviderProps,\n SlackConnectButtonProps,\n SlackLinkUserProps,\n SubscriptionButtonProps,\n SubscriptionPreferencesProps,\n SubscriptionProps,\n} from './components';\nexport {\n Bell,\n Inbox,\n InboxContent,\n Notifications,\n NovuProvider,\n Preferences,\n SlackConnectButton,\n SlackLinkUser,\n Subscription,\n SubscriptionButton,\n SubscriptionPreferences,\n} from './components';\nexport type {\n UseChannelConnectionProps,\n UseChannelConnectionResult,\n UseChannelConnectionsProps,\n UseChannelConnectionsResult,\n UseChannelEndpointProps,\n UseChannelEndpointResult,\n UseCountsProps,\n UseCountsResult,\n UseCreateChannelEndpointProps,\n UseCreateChannelEndpointResult,\n UseDeleteChannelEndpointProps,\n UseDeleteChannelEndpointResult,\n UseNotificationsProps,\n UseNotificationsResult,\n UsePreferencesResult,\n UseScheduleProps as UsePreferencesProps,\n} from './hooks';\nexport {\n useChannelConnection,\n useChannelConnections,\n useChannelEndpoint,\n useCounts,\n useCreateChannelEndpoint,\n useCreateSubscription,\n useDeleteChannelEndpoint,\n useNotifications,\n useNovu,\n usePreferences,\n useRemoveSubscription,\n useSchedule,\n useSubscription,\n useSubscriptions,\n useUpdateSubscription,\n} from './hooks';\n\nexport type {\n BaseProps,\n BellRenderer,\n BodyRenderer,\n DefaultInboxProps,\n DefaultProps,\n NoRendererProps,\n NotificationRendererProps,\n NotificationsRenderer,\n ReactAllAppearance,\n ReactInboxAppearance,\n ReactInboxTheme,\n ReactSubscriptionAppearance,\n ReactSubscriptionTheme,\n SubjectBodyRendererProps,\n SubjectRenderer,\n WithChildrenProps,\n} from './utils/types';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,gBAA4E;AA8C5E,wBAYO;AAmBP,mBAgBO;","names":[]}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
export * from '@novu/js';
|
|
2
2
|
export { PreferenceLevel, SeverityLevelEnum, WorkflowCriticalityEnum } from '@novu/js';
|
|
3
|
-
export { AllLocalization, AllLocalizationKey, ElementStyles, InboxAppearance, InboxAppearanceCallback, InboxAppearanceCallbackFunction, InboxAppearanceCallbackKeys, InboxAppearanceKey, InboxElements, InboxLocalization, InboxLocalizationKey, InboxTheme, NotificationActionClickHandler, NotificationClickHandler, NotificationRenderer, PreferenceGroups, PreferencesFilter, RouterPush, SubscriptionAppearance, SubscriptionAppearanceCallback, SubscriptionAppearanceCallbackFunction, SubscriptionAppearanceCallbackKeys, SubscriptionAppearanceKey, SubscriptionElements, SubscriptionLocalization, SubscriptionLocalizationKey, SubscriptionTheme, Tab, Variables } from '@novu/js/ui';
|
|
3
|
+
export { AllLocalization, AllLocalizationKey, ChannelConnectButtonIconKey, ElementStyles, InboxAppearance, InboxAppearanceCallback, InboxAppearanceCallbackFunction, InboxAppearanceCallbackKeys, InboxAppearanceKey, InboxElements, InboxLocalization, InboxLocalizationKey, InboxTheme, NotificationActionClickHandler, NotificationClickHandler, NotificationRenderer, PreferenceGroups, PreferencesFilter, RouterPush, SubscriptionAppearance, SubscriptionAppearanceCallback, SubscriptionAppearanceCallbackFunction, SubscriptionAppearanceCallbackKeys, SubscriptionAppearanceKey, SubscriptionElements, SubscriptionLocalization, SubscriptionLocalizationKey, SubscriptionTheme, Tab, Variables } from '@novu/js/ui';
|
|
4
4
|
export { NovuProvider, NovuProviderProps, useNovu } from './hooks/NovuProvider.cjs';
|
|
5
5
|
export { Bell, BellProps } from './components/Bell.cjs';
|
|
6
6
|
export { Inbox, InboxProps } from './components/Inbox.cjs';
|
|
7
7
|
export { InboxContent, InboxContentProps } from './components/InboxContent.cjs';
|
|
8
8
|
export { NotificationProps, Notifications } from './components/Notifications.cjs';
|
|
9
9
|
export { Preferences } from './components/Preferences.cjs';
|
|
10
|
+
export { SlackConnectButton, SlackConnectButtonProps } from './components/slack-connect-button/SlackConnectButton.cjs';
|
|
11
|
+
export { SlackLinkUser, SlackLinkUserProps } from './components/slack-link-user/SlackLinkUser.cjs';
|
|
10
12
|
export { Subscription, SubscriptionProps } from './components/subscription/Subscription.cjs';
|
|
11
13
|
export { SubscriptionButton, SubscriptionButtonProps } from './components/subscription/SubscriptionButton.cjs';
|
|
12
14
|
export { SubscriptionPreferences, SubscriptionPreferencesProps } from './components/subscription/SubscriptionPreferences.cjs';
|
|
15
|
+
export { UseChannelConnectionProps, UseChannelConnectionResult, useChannelConnection } from './hooks/useChannelConnection.cjs';
|
|
16
|
+
export { UseChannelConnectionsProps, UseChannelConnectionsResult, useChannelConnections } from './hooks/useChannelConnections.cjs';
|
|
17
|
+
export { UseChannelEndpointProps, UseChannelEndpointResult, useChannelEndpoint } from './hooks/useChannelEndpoint.cjs';
|
|
13
18
|
export { UseCountsProps, UseCountsResult, useCounts } from './hooks/useCounts.cjs';
|
|
19
|
+
export { UseCreateChannelEndpointProps, UseCreateChannelEndpointResult, useCreateChannelEndpoint } from './hooks/useCreateChannelEndpoint.cjs';
|
|
14
20
|
export { useCreateSubscription } from './hooks/useCreateSubscription.cjs';
|
|
21
|
+
export { UseDeleteChannelEndpointProps, UseDeleteChannelEndpointResult, useDeleteChannelEndpoint } from './hooks/useDeleteChannelEndpoint.cjs';
|
|
15
22
|
export { UseNotificationsProps, UseNotificationsResult, useNotifications } from './hooks/useNotifications.cjs';
|
|
16
23
|
export { UsePreferencesResult, usePreferences } from './hooks/usePreferences.cjs';
|
|
17
24
|
export { useRemoveSubscription } from './hooks/useRemoveSubscription.cjs';
|
|
@@ -19,8 +26,10 @@ export { UseScheduleProps as UsePreferencesProps, useSchedule } from './hooks/us
|
|
|
19
26
|
export { useSubscription } from './hooks/useSubscription.cjs';
|
|
20
27
|
export { useSubscriptions } from './hooks/useSubscriptions.cjs';
|
|
21
28
|
export { useUpdateSubscription } from './hooks/useUpdateSubscription.cjs';
|
|
22
|
-
export { BaseProps, BellRenderer, BodyRenderer, DefaultInboxProps, DefaultProps, NoRendererProps, NotificationRendererProps, NotificationsRenderer, ReactInboxAppearance, ReactInboxTheme, ReactSubscriptionAppearance, ReactSubscriptionTheme, SubjectBodyRendererProps, SubjectRenderer, WithChildrenProps } from './utils/types.cjs';
|
|
29
|
+
export { BaseProps, BellRenderer, BodyRenderer, DefaultInboxProps, DefaultProps, NoRendererProps, NotificationRendererProps, NotificationsRenderer, ReactAllAppearance, ReactInboxAppearance, ReactInboxTheme, ReactSubscriptionAppearance, ReactSubscriptionTheme, SubjectBodyRendererProps, SubjectRenderer, WithChildrenProps } from './utils/types.cjs';
|
|
23
30
|
import 'react/jsx-runtime';
|
|
24
31
|
import 'react';
|
|
25
32
|
import './components/NovuUI.cjs';
|
|
33
|
+
import './components/slack-connect-button/DefaultSlackConnectButton.cjs';
|
|
34
|
+
import './components/slack-link-user/DefaultSlackLinkUser.cjs';
|
|
26
35
|
import './components/subscription/DefaultSubscription.cjs';
|