@bodhveda/react 0.0.3 → 0.0.5
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/LICENSE +21 -0
- package/README.md +93 -0
- package/dist/hooks.d.ts +61 -0
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +66 -11
- package/dist/hooks.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/provider.d.ts +49 -0
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +6 -0
- package/dist/provider.js.map +1 -1
- package/package.json +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Mudgal Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1 +1,94 @@
|
|
|
1
1
|
# React SDK for Bodhveda
|
|
2
|
+
|
|
3
|
+
Official React SDK for Bodhveda.
|
|
4
|
+
|
|
5
|
+
It extends the core `bodhveda` SDK to provide you with hooks to make it easy to build custom notification UX with React.
|
|
6
|
+
|
|
7
|
+
> This SDK uses [TanStack Query](https://tanstack.com/query/v5/docs/framework/react/overview) to manage Bodhveda API state for you - including caching and invalidation as well. You will need to add `@tanstack/react-query` and wrap your React app with `QueryClientProvider` and then put `BodhvedaProvider` inside it so that `@bodhveda/react` can use the ReactQuery's `QueryClient`.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @bodhveda/react @tanstack/react-query
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
19
|
+
import { BodhvedaProvider } from "@bodhveda/react";
|
|
20
|
+
|
|
21
|
+
const queryClient = new QueryClient();
|
|
22
|
+
|
|
23
|
+
<QueryClientProvider client={queryClient}>
|
|
24
|
+
<BodhvedaProvider apiKey="your-api-key" recipientID="user-123">
|
|
25
|
+
<NotificationInbox />
|
|
26
|
+
</BodhvedaProvider>
|
|
27
|
+
</QueryClientProvider>;
|
|
28
|
+
|
|
29
|
+
// src/components/NotificationInbox.tsx
|
|
30
|
+
import { Notification } from "./Notification";
|
|
31
|
+
import { useNotifications } from "@bodhveda/react";
|
|
32
|
+
|
|
33
|
+
function NotificationInbox() {
|
|
34
|
+
// Fetch recipient's notifications.
|
|
35
|
+
const { data } = useNotifications();
|
|
36
|
+
|
|
37
|
+
// ...
|
|
38
|
+
// Handle loading and error states.
|
|
39
|
+
// ...
|
|
40
|
+
|
|
41
|
+
// Render the notifications however you want.
|
|
42
|
+
return (
|
|
43
|
+
<ul>
|
|
44
|
+
{data.notifications.map((notification) => (
|
|
45
|
+
<li key={notification.id}>
|
|
46
|
+
<Notification notification={notification} />
|
|
47
|
+
</li>
|
|
48
|
+
))}
|
|
49
|
+
</ul>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Hooks
|
|
55
|
+
|
|
56
|
+
### `useBodhveda()`
|
|
57
|
+
|
|
58
|
+
Returns the Bodhveda client instance.
|
|
59
|
+
|
|
60
|
+
### `useRecipientID()`
|
|
61
|
+
|
|
62
|
+
Returns the current recipient ID.
|
|
63
|
+
|
|
64
|
+
### `useNotifications(options?)`
|
|
65
|
+
|
|
66
|
+
Fetches the list of notifications for the current recipient.
|
|
67
|
+
|
|
68
|
+
### `useNotificationsUnreadCount(options?)`
|
|
69
|
+
|
|
70
|
+
Fetches the unread notifications count for the current recipient.
|
|
71
|
+
|
|
72
|
+
### `useUpdateNotificationsState(options?)`
|
|
73
|
+
|
|
74
|
+
Returns a mutation hook to update notification state (e.g., mark as read).
|
|
75
|
+
|
|
76
|
+
### `useDeleteNotifications(options?)`
|
|
77
|
+
|
|
78
|
+
Returns a mutation hook to delete notifications for the current recipient.
|
|
79
|
+
|
|
80
|
+
### `usePreferences(options?)`
|
|
81
|
+
|
|
82
|
+
Fetches the notification preferences for the current recipient.
|
|
83
|
+
|
|
84
|
+
### `useUpdatePreference(options?)`
|
|
85
|
+
|
|
86
|
+
Returns a mutation hook to update a notification preference.
|
|
87
|
+
|
|
88
|
+
### `useCheckPreference(target, options?)`
|
|
89
|
+
|
|
90
|
+
Checks a specific notification preference for the current recipient.
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
MIT
|
package/dist/hooks.d.ts
CHANGED
|
@@ -2,16 +2,77 @@ import { AnyUseMutationOptions, AnyUseQueryOptions, UseQueryResult } from "@tans
|
|
|
2
2
|
import { ListNotificationsResponse, ListPreferencesResponse, UpdateNotificationsStateRequest, UpdateNotificationsStateResponse, SetPreferenceRequest, SetPreferenceResponse, DeleteNotificationsResponse, DeleteNotificationsRequest, Target, CheckPreferenceResponse } from "bodhveda";
|
|
3
3
|
type QueryOptions = Omit<AnyUseQueryOptions, "queryKey">;
|
|
4
4
|
type MutationOptions = AnyUseMutationOptions;
|
|
5
|
+
export declare const QueryKeys: {
|
|
6
|
+
useNotifications: string[];
|
|
7
|
+
useNotificationsUnreadCount: string[];
|
|
8
|
+
useCheckPreference: string[];
|
|
9
|
+
usePreferences: string[];
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Returns the Bodhveda client instance.
|
|
13
|
+
*
|
|
14
|
+
* @throws If used outside a {@link BodhvedaProvider}.
|
|
15
|
+
* @returns {Bodhveda} The Bodhveda client instance.
|
|
16
|
+
*/
|
|
5
17
|
export declare function useBodhveda(): import("bodhveda").Bodhveda;
|
|
18
|
+
/**
|
|
19
|
+
* Returns the current recipient ID.
|
|
20
|
+
*
|
|
21
|
+
* @throws If used outside a {@link BodhvedaProvider}.
|
|
22
|
+
* @returns {string} The recipient ID.
|
|
23
|
+
*/
|
|
6
24
|
export declare function useRecipientID(): string;
|
|
25
|
+
/**
|
|
26
|
+
* Fetches the list of notifications for the current recipient.
|
|
27
|
+
*
|
|
28
|
+
* @param options - Optional react-query options.
|
|
29
|
+
* @returns {UseQueryResult<ListNotificationsResponse>} Query result.
|
|
30
|
+
*/
|
|
7
31
|
export declare function useNotifications(options?: QueryOptions): UseQueryResult<ListNotificationsResponse>;
|
|
32
|
+
/**
|
|
33
|
+
* Fetches the unread notifications count for the current recipient.
|
|
34
|
+
*
|
|
35
|
+
* @param options - Optional react-query options.
|
|
36
|
+
* @returns {UseQueryResult<{ unread_count: number }>} Query result.
|
|
37
|
+
*/
|
|
8
38
|
export declare function useNotificationsUnreadCount(options?: QueryOptions): UseQueryResult<{
|
|
9
39
|
unread_count: number;
|
|
10
40
|
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Returns a mutation hook to update notification state (e.g., mark as read).
|
|
43
|
+
*
|
|
44
|
+
* @param options - Optional mutation options.
|
|
45
|
+
* @returns Mutation hook.
|
|
46
|
+
*/
|
|
11
47
|
export declare function useUpdateNotificationsState(options?: MutationOptions): import("@tanstack/react-query").UseMutationResult<UpdateNotificationsStateResponse, unknown, UpdateNotificationsStateRequest, unknown>;
|
|
48
|
+
/**
|
|
49
|
+
* Returns a mutation hook to delete notifications for the current recipient.
|
|
50
|
+
*
|
|
51
|
+
* @param options - Optional mutation options.
|
|
52
|
+
* @returns Mutation hook.
|
|
53
|
+
*/
|
|
12
54
|
export declare function useDeleteNotifications(options?: MutationOptions): import("@tanstack/react-query").UseMutationResult<DeleteNotificationsResponse, unknown, DeleteNotificationsRequest, unknown>;
|
|
55
|
+
/**
|
|
56
|
+
* Fetches the notification preferences for the current recipient.
|
|
57
|
+
*
|
|
58
|
+
* @param options - Optional react-query options.
|
|
59
|
+
* @returns {UseQueryResult<ListPreferencesResponse>} Query result.
|
|
60
|
+
*/
|
|
13
61
|
export declare function usePreferences(options?: QueryOptions): UseQueryResult<ListPreferencesResponse>;
|
|
62
|
+
/**
|
|
63
|
+
* Returns a mutation hook to update a notification preference for the current recipient.
|
|
64
|
+
*
|
|
65
|
+
* @param options - Optional mutation options.
|
|
66
|
+
* @returns Mutation hook.
|
|
67
|
+
*/
|
|
14
68
|
export declare function useUpdatePreference(options?: MutationOptions): import("@tanstack/react-query").UseMutationResult<SetPreferenceResponse, unknown, SetPreferenceRequest, unknown>;
|
|
69
|
+
/**
|
|
70
|
+
* Checks a specific notification preference for the current recipient.
|
|
71
|
+
*
|
|
72
|
+
* @param target - The notification target/channel to check.
|
|
73
|
+
* @param options - Optional react-query options.
|
|
74
|
+
* @returns {UseQueryResult<CheckPreferenceResponse>} Query result.
|
|
75
|
+
*/
|
|
15
76
|
export declare function useCheckPreference(target: Target, options?: QueryOptions): UseQueryResult<CheckPreferenceResponse>;
|
|
16
77
|
export {};
|
|
17
78
|
//# sourceMappingURL=hooks.d.ts.map
|
package/dist/hooks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.tsx"],"names":[],"mappings":"AACA,OAAO,EACH,qBAAqB,EACrB,kBAAkB,EAIlB,cAAc,EACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACH,yBAAyB,EACzB,uBAAuB,EACvB,+BAA+B,EAC/B,gCAAgC,EAChC,oBAAoB,EACpB,qBAAqB,EACrB,2BAA2B,EAC3B,0BAA0B,EAC1B,MAAM,EACN,uBAAuB,EAC1B,MAAM,UAAU,CAAC;AAIlB,KAAK,YAAY,GAAG,IAAI,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC;AACzD,KAAK,eAAe,GAAG,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.tsx"],"names":[],"mappings":"AACA,OAAO,EACH,qBAAqB,EACrB,kBAAkB,EAIlB,cAAc,EACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACH,yBAAyB,EACzB,uBAAuB,EACvB,+BAA+B,EAC/B,gCAAgC,EAChC,oBAAoB,EACpB,qBAAqB,EACrB,2BAA2B,EAC3B,0BAA0B,EAC1B,MAAM,EACN,uBAAuB,EAC1B,MAAM,UAAU,CAAC;AAIlB,KAAK,YAAY,GAAG,IAAI,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC;AACzD,KAAK,eAAe,GAAG,qBAAqB,CAAC;AAE7C,eAAO,MAAM,SAAS;;;;;CAKrB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,WAAW,gCAQ1B;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,WAQ7B;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC5B,OAAO,GAAE,YAAiB,GAC3B,cAAc,CAAC,yBAAyB,CAAC,CAS3C;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACvC,OAAO,GAAE,YAAiB,GAC3B,cAAc,CAAC;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC,CAU1C;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,GAAE,eAAoB,0IA6BxE;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,GAAE,eAAoB,gIA0BnE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC1B,OAAO,GAAE,YAAiB,GAC3B,cAAc,CAAC,uBAAuB,CAAC,CASzC;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,eAAoB,oHA0BhE;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAC9B,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,YAAiB,GAC3B,cAAc,CAAC,uBAAuB,CAAC,CAUzC"}
|
package/dist/hooks.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { useContext } from "react";
|
|
2
2
|
import { useMutation, useQuery, useQueryClient, } from "@tanstack/react-query";
|
|
3
3
|
import { BodhvedaContext } from "./context";
|
|
4
|
-
const
|
|
4
|
+
export const QueryKeys = {
|
|
5
5
|
useNotifications: ["useNotifications"],
|
|
6
6
|
useNotificationsUnreadCount: ["useNotificationsUnreadCount"],
|
|
7
7
|
useCheckPreference: ["useCheckPreference"],
|
|
8
8
|
usePreferences: ["usePreferences"],
|
|
9
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Returns the Bodhveda client instance.
|
|
12
|
+
*
|
|
13
|
+
* @throws If used outside a {@link BodhvedaProvider}.
|
|
14
|
+
* @returns {Bodhveda} The Bodhveda client instance.
|
|
15
|
+
*/
|
|
10
16
|
export function useBodhveda() {
|
|
11
17
|
const context = useContext(BodhvedaContext);
|
|
12
18
|
if (!context) {
|
|
@@ -14,6 +20,12 @@ export function useBodhveda() {
|
|
|
14
20
|
}
|
|
15
21
|
return context.bodhveda;
|
|
16
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Returns the current recipient ID.
|
|
25
|
+
*
|
|
26
|
+
* @throws If used outside a {@link BodhvedaProvider}.
|
|
27
|
+
* @returns {string} The recipient ID.
|
|
28
|
+
*/
|
|
17
29
|
export function useRecipientID() {
|
|
18
30
|
const context = useContext(BodhvedaContext);
|
|
19
31
|
if (!context) {
|
|
@@ -21,24 +33,42 @@ export function useRecipientID() {
|
|
|
21
33
|
}
|
|
22
34
|
return context.recipientID;
|
|
23
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Fetches the list of notifications for the current recipient.
|
|
38
|
+
*
|
|
39
|
+
* @param options - Optional react-query options.
|
|
40
|
+
* @returns {UseQueryResult<ListNotificationsResponse>} Query result.
|
|
41
|
+
*/
|
|
24
42
|
export function useNotifications(options = {}) {
|
|
25
43
|
const bodhveda = useBodhveda();
|
|
26
44
|
const recipientID = useRecipientID();
|
|
27
45
|
return useQuery({
|
|
28
|
-
queryKey: [
|
|
46
|
+
queryKey: [QueryKeys.useNotifications],
|
|
29
47
|
queryFn: () => bodhveda.recipients.notifications.list(recipientID),
|
|
30
48
|
...options,
|
|
31
49
|
});
|
|
32
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Fetches the unread notifications count for the current recipient.
|
|
53
|
+
*
|
|
54
|
+
* @param options - Optional react-query options.
|
|
55
|
+
* @returns {UseQueryResult<{ unread_count: number }>} Query result.
|
|
56
|
+
*/
|
|
33
57
|
export function useNotificationsUnreadCount(options = {}) {
|
|
34
58
|
const bodhveda = useBodhveda();
|
|
35
59
|
const recipientID = useRecipientID();
|
|
36
60
|
return useQuery({
|
|
37
|
-
queryKey: [
|
|
61
|
+
queryKey: [QueryKeys.useNotificationsUnreadCount],
|
|
38
62
|
queryFn: () => bodhveda.recipients.notifications.unreadCount(recipientID),
|
|
39
63
|
...options,
|
|
40
64
|
});
|
|
41
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Returns a mutation hook to update notification state (e.g., mark as read).
|
|
68
|
+
*
|
|
69
|
+
* @param options - Optional mutation options.
|
|
70
|
+
* @returns Mutation hook.
|
|
71
|
+
*/
|
|
42
72
|
export function useUpdateNotificationsState(options = {}) {
|
|
43
73
|
const bodhveda = useBodhveda();
|
|
44
74
|
const recipientID = useRecipientID();
|
|
@@ -50,16 +80,22 @@ export function useUpdateNotificationsState(options = {}) {
|
|
|
50
80
|
},
|
|
51
81
|
onSuccess: (...args) => {
|
|
52
82
|
queryClient.invalidateQueries({
|
|
53
|
-
queryKey: [
|
|
83
|
+
queryKey: [QueryKeys.useNotifications],
|
|
54
84
|
});
|
|
55
85
|
queryClient.invalidateQueries({
|
|
56
|
-
queryKey: [
|
|
86
|
+
queryKey: [QueryKeys.useNotificationsUnreadCount],
|
|
57
87
|
});
|
|
58
88
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(...args);
|
|
59
89
|
},
|
|
60
90
|
...rest,
|
|
61
91
|
});
|
|
62
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Returns a mutation hook to delete notifications for the current recipient.
|
|
95
|
+
*
|
|
96
|
+
* @param options - Optional mutation options.
|
|
97
|
+
* @returns Mutation hook.
|
|
98
|
+
*/
|
|
63
99
|
export function useDeleteNotifications(options = {}) {
|
|
64
100
|
const bodhveda = useBodhveda();
|
|
65
101
|
const recipientID = useRecipientID();
|
|
@@ -71,25 +107,37 @@ export function useDeleteNotifications(options = {}) {
|
|
|
71
107
|
},
|
|
72
108
|
onSuccess: (...args) => {
|
|
73
109
|
queryClient.invalidateQueries({
|
|
74
|
-
queryKey: [
|
|
110
|
+
queryKey: [QueryKeys.useNotifications],
|
|
75
111
|
});
|
|
76
112
|
queryClient.invalidateQueries({
|
|
77
|
-
queryKey: [
|
|
113
|
+
queryKey: [QueryKeys.useNotificationsUnreadCount],
|
|
78
114
|
});
|
|
79
115
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(...args);
|
|
80
116
|
},
|
|
81
117
|
...rest,
|
|
82
118
|
});
|
|
83
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Fetches the notification preferences for the current recipient.
|
|
122
|
+
*
|
|
123
|
+
* @param options - Optional react-query options.
|
|
124
|
+
* @returns {UseQueryResult<ListPreferencesResponse>} Query result.
|
|
125
|
+
*/
|
|
84
126
|
export function usePreferences(options = {}) {
|
|
85
127
|
const bodhveda = useBodhveda();
|
|
86
128
|
const recipientID = useRecipientID();
|
|
87
129
|
return useQuery({
|
|
88
|
-
queryKey: [
|
|
130
|
+
queryKey: [QueryKeys.usePreferences],
|
|
89
131
|
queryFn: () => bodhveda.recipients.preferences.list(recipientID),
|
|
90
132
|
...options,
|
|
91
133
|
});
|
|
92
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Returns a mutation hook to update a notification preference for the current recipient.
|
|
137
|
+
*
|
|
138
|
+
* @param options - Optional mutation options.
|
|
139
|
+
* @returns Mutation hook.
|
|
140
|
+
*/
|
|
93
141
|
export function useUpdatePreference(options = {}) {
|
|
94
142
|
const bodhveda = useBodhveda();
|
|
95
143
|
const recipientID = useRecipientID();
|
|
@@ -101,21 +149,28 @@ export function useUpdatePreference(options = {}) {
|
|
|
101
149
|
},
|
|
102
150
|
onSuccess: (...args) => {
|
|
103
151
|
queryClient.invalidateQueries({
|
|
104
|
-
queryKey: [
|
|
152
|
+
queryKey: [QueryKeys.usePreferences],
|
|
105
153
|
});
|
|
106
154
|
queryClient.invalidateQueries({
|
|
107
|
-
queryKey: [
|
|
155
|
+
queryKey: [QueryKeys.useCheckPreference, args[0].target],
|
|
108
156
|
});
|
|
109
157
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(...args);
|
|
110
158
|
},
|
|
111
159
|
...rest,
|
|
112
160
|
});
|
|
113
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Checks a specific notification preference for the current recipient.
|
|
164
|
+
*
|
|
165
|
+
* @param target - The notification target/channel to check.
|
|
166
|
+
* @param options - Optional react-query options.
|
|
167
|
+
* @returns {UseQueryResult<CheckPreferenceResponse>} Query result.
|
|
168
|
+
*/
|
|
114
169
|
export function useCheckPreference(target, options = {}) {
|
|
115
170
|
const bodhveda = useBodhveda();
|
|
116
171
|
const recipientID = useRecipientID();
|
|
117
172
|
return useQuery({
|
|
118
|
-
queryKey: [
|
|
173
|
+
queryKey: [QueryKeys.useCheckPreference, target],
|
|
119
174
|
queryFn: () => bodhveda.recipients.preferences.check(recipientID, { target }),
|
|
120
175
|
...options,
|
|
121
176
|
});
|
package/dist/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAGH,WAAW,EACX,QAAQ,EACR,cAAc,GAEjB,MAAM,uBAAuB,CAAC;AAc/B,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAK5C,MAAM,
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAGH,WAAW,EACX,QAAQ,EACR,cAAc,GAEjB,MAAM,uBAAuB,CAAC;AAc/B,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAK5C,MAAM,CAAC,MAAM,SAAS,GAAG;IACrB,gBAAgB,EAAE,CAAC,kBAAkB,CAAC;IACtC,2BAA2B,EAAE,CAAC,6BAA6B,CAAC;IAC5D,kBAAkB,EAAE,CAAC,oBAAoB,CAAC;IAC1C,cAAc,EAAE,CAAC,gBAAgB,CAAC;CACrC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,WAAW;IACvB,MAAM,OAAO,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IAE5C,IAAI,CAAC,OAAO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,EAAE,CAAC,SAAS,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;aAC3D,CAAC,CAAC;YACH,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAG,GAAG,IAAI,CAAC,CAAC;QACzB,CAAC;QACD,GAAG,IAAI;KACV,CAAC,CAAC;AACP,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAC9B,MAAc,EACd,UAAwB,EAAE;IAE1B,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IAErC,OAAO,QAAQ,CAAC;QACZ,QAAQ,EAAE,CAAC,SAAS,CAAC,kBAAkB,EAAE,MAAM,CAAC;QAChD,OAAO,EAAE,GAAG,EAAE,CACV,QAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,MAAM,EAAE,CAAC;QAClE,GAAG,OAAO;KACb,CAAC,CAAC;AACP,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AAGxB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AAGxB,cAAc,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AAExB,qEAAqE;AACrE,cAAc,UAAU,CAAC"}
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,16 +1,65 @@
|
|
|
1
1
|
import { Bodhveda } from "bodhveda";
|
|
2
|
+
/**
|
|
3
|
+
* Props for {@link BodhvedaProvider}.
|
|
4
|
+
*
|
|
5
|
+
* You must provide `recipientID` along with either a `bodhveda` client instance, or an `apiKey` (with optional `options`).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* <BodhvedaProvider bodhveda={bodhvedaClient} recipientID="user-123">
|
|
10
|
+
* <App />
|
|
11
|
+
* </BodhvedaProvider>
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* <BodhvedaProvider apiKey="your-api-key" recipientID="user-123">
|
|
17
|
+
* <App />
|
|
18
|
+
* </BodhvedaProvider>
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
2
21
|
type BodhvedaProviderProps = {
|
|
22
|
+
/**
|
|
23
|
+
* An existing Bodhveda client instance.
|
|
24
|
+
*/
|
|
3
25
|
bodhveda: Bodhveda;
|
|
26
|
+
/**
|
|
27
|
+
* The recipient's ID.
|
|
28
|
+
*/
|
|
4
29
|
recipientID: string;
|
|
30
|
+
/**
|
|
31
|
+
* React children.
|
|
32
|
+
*/
|
|
5
33
|
children: React.ReactNode;
|
|
6
34
|
} | {
|
|
35
|
+
/**
|
|
36
|
+
* API key for Bodhveda.
|
|
37
|
+
*/
|
|
7
38
|
apiKey: string;
|
|
39
|
+
/**
|
|
40
|
+
* The recipient's ID.
|
|
41
|
+
*/
|
|
8
42
|
recipientID: string;
|
|
43
|
+
/**
|
|
44
|
+
* Optional configuration.
|
|
45
|
+
*/
|
|
9
46
|
options?: {
|
|
47
|
+
/**
|
|
48
|
+
* Override the API URL.
|
|
49
|
+
*/
|
|
10
50
|
apiURL?: string;
|
|
11
51
|
};
|
|
52
|
+
/**
|
|
53
|
+
* React children.
|
|
54
|
+
*/
|
|
12
55
|
children: React.ReactNode;
|
|
13
56
|
};
|
|
57
|
+
/**
|
|
58
|
+
* Use this at the root of your React app to be able to use the hooks provided.
|
|
59
|
+
*
|
|
60
|
+
* @param props - {@link BodhvedaProviderProps}
|
|
61
|
+
* @returns React provider component.
|
|
62
|
+
*/
|
|
14
63
|
export declare function BodhvedaProvider(props: BodhvedaProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
15
64
|
export {};
|
|
16
65
|
//# sourceMappingURL=provider.d.ts.map
|
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAIpC,KAAK,qBAAqB,GACpB;IACI,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC7B,GACD;IACI,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE;QACN,MAAM,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC7B,CAAC;AAER,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,2CAsC5D"}
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAIpC;;;;;;;;;;;;;;;;;;GAkBG;AACH,KAAK,qBAAqB,GACpB;IACI;;OAEG;IACH,QAAQ,EAAE,QAAQ,CAAC;IACnB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC7B,GACD;IACI;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,OAAO,CAAC,EAAE;QACN;;WAEG;QACH,MAAM,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;IACF;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC7B,CAAC;AAER;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,2CAsC5D"}
|
package/dist/provider.js
CHANGED
|
@@ -2,6 +2,12 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
import { Bodhveda } from "bodhveda";
|
|
4
4
|
import { BodhvedaContext } from "./context";
|
|
5
|
+
/**
|
|
6
|
+
* Use this at the root of your React app to be able to use the hooks provided.
|
|
7
|
+
*
|
|
8
|
+
* @param props - {@link BodhvedaProviderProps}
|
|
9
|
+
* @returns React provider component.
|
|
10
|
+
*/
|
|
5
11
|
export function BodhvedaProvider(props) {
|
|
6
12
|
const hasClient = "bodhveda" in props;
|
|
7
13
|
const hasApiKey = "apiKey" in props;
|
package/dist/provider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC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"name": "@bodhveda/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "React SDK for Bodhveda",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -50,6 +50,6 @@
|
|
|
50
50
|
"typescript": "^5.9.2"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"bodhveda": "^0.0.
|
|
53
|
+
"bodhveda": "^0.0.5"
|
|
54
54
|
}
|
|
55
55
|
}
|