@bodhveda/js 0.3.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/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 ADDED
@@ -0,0 +1,260 @@
1
+ # JavaScript/TypeScript SDK for Bodhveda
2
+
3
+ Official JavaScript/TypeScript SDK for Bodhveda.
4
+
5
+ It offers a simpler way to work with Bodhveda APIs in both browser and server environments.
6
+
7
+ ## Index
8
+
9
+ - [Installation](#installation)
10
+ - [Quick Start](#quick-start)
11
+ - [Notifications](#notifications)
12
+ - [Recipients](#recipients)
13
+ - [Recipient Notifications](#recipient-notifications)
14
+ - [Recipient Preferences](#recipient-preferences)
15
+ - [Recipient Contacts](#recipient-contacts)
16
+ - [License](#license)
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install @bodhveda/js
22
+ ```
23
+
24
+ > Previously published as `bodhveda`. That package is deprecated — install `@bodhveda/js` instead.
25
+
26
+ ## Quick Start
27
+
28
+ ```typescript
29
+ import { Bodhveda } from "@bodhveda/js";
30
+
31
+ const bodhveda = new Bodhveda("YOUR_API_KEY");
32
+
33
+ // Send a notification to a recipient.
34
+ // Note: Bodhveda will create the recipient if it does not already exist.
35
+ await bodhveda.notifications.send({
36
+ recipient_id: "user-123",
37
+ payload: { message: "Hello, world!" },
38
+ });
39
+
40
+ // List all notifications for a recipient.
41
+ const notifications = await bodhveda.recipients.notifications.list("user-123");
42
+ ```
43
+
44
+ ## Notifications
45
+
46
+ ### Send a notification
47
+
48
+ Send a notification to a recipient or broadcast to a target.
49
+
50
+ ```typescript
51
+ await bodhveda.notifications.send({
52
+ recipient_id: "user-123",
53
+ payload: { message: "Hello, world!" },
54
+ });
55
+ ```
56
+
57
+ ### Send with email
58
+
59
+ Include the optional `email` block to also send an email. Its presence makes email
60
+ eligible (**direct sends only** — an email block on a broadcast returns `400`).
61
+ Bodhveda does no templating: you render the subject/HTML/text yourself (e.g. with
62
+ `@react-email`) and pass the result. `text` is optional and derived from `html`.
63
+
64
+ Email fires only when the `(target, email)` pair is cataloged, the recipient's email
65
+ preference is enabled, and the recipient has a primary email
66
+ [contact](#recipient-contacts). Per-medium outcomes are returned in `deliveries`.
67
+
68
+ ```typescript
69
+ const res = await bodhveda.notifications.send({
70
+ recipient_id: "user-123",
71
+ target: { channel: "digest", topic: "none", event: "sent" },
72
+ payload: { title: "Your daily digest is ready." },
73
+ email: {
74
+ subject: "Your daily digest",
75
+ html: "<h1>Your daily digest</h1><p>3 new follow-ups today.</p>",
76
+ },
77
+ });
78
+ // res.notification (in-app) and res.deliveries (per-medium email outcome)
79
+ ```
80
+
81
+ ---
82
+
83
+ ## Recipients
84
+
85
+ ### Create a recipient
86
+
87
+ Create a new recipient.
88
+
89
+ ```typescript
90
+ await bodhveda.recipients.create({
91
+ id: "user-123",
92
+ name: "Alice",
93
+ });
94
+ ```
95
+
96
+ ### Create multiple recipients (batch)
97
+
98
+ Create multiple recipients in a single request.
99
+
100
+ ```typescript
101
+ await bodhveda.recipients.createBatch({
102
+ recipients: [
103
+ { id: "user-1", name: "Alice" },
104
+ { id: "user-2", name: "Bob" },
105
+ ],
106
+ });
107
+ ```
108
+
109
+ ### Get a recipient
110
+
111
+ Retrieve details of a recipient by ID.
112
+
113
+ ```typescript
114
+ const recipient = await bodhveda.recipients.get("user-123");
115
+ ```
116
+
117
+ ### Update a recipient
118
+
119
+ Update recipient details.
120
+
121
+ ```typescript
122
+ await bodhveda.recipients.update("user-123", { name: "Alice Updated" });
123
+ ```
124
+
125
+ ### Delete a recipient
126
+
127
+ Delete a recipient by ID.
128
+
129
+ ```typescript
130
+ await bodhveda.recipients.delete("user-123");
131
+ ```
132
+
133
+ ---
134
+
135
+ ## Recipient Notifications
136
+
137
+ ### List notifications
138
+
139
+ List notifications for a recipient.
140
+
141
+ ```typescript
142
+ const notifications = await bodhveda.recipients.notifications.list("user-123");
143
+ ```
144
+
145
+ ### Get unread notification count
146
+
147
+ Get the count of unread notifications for a recipient.
148
+
149
+ ```typescript
150
+ const { unread_count } = await bodhveda.recipients.notifications.unreadCount(
151
+ "user-123"
152
+ );
153
+ ```
154
+
155
+ ### Update notification state
156
+
157
+ Update the state (e.g., mark as read) of notifications for a recipient.
158
+
159
+ ```typescript
160
+ await bodhveda.recipients.notifications.updateState("user-123", {
161
+ ids: [1, 2, 3],
162
+ state: { read: true },
163
+ });
164
+ ```
165
+
166
+ ### Delete notifications
167
+
168
+ Delete notifications for a recipient.
169
+
170
+ ```typescript
171
+ await bodhveda.recipients.notifications.delete("user-123", {
172
+ ids: [1, 2, 3],
173
+ });
174
+ ```
175
+
176
+ ---
177
+
178
+ ## Recipient Preferences
179
+
180
+ ### List preferences
181
+
182
+ List all preferences for a recipient.
183
+
184
+ ```typescript
185
+ const preferences = await bodhveda.recipients.preferences.list("user-123");
186
+ ```
187
+
188
+ ### Set a preference
189
+
190
+ Set a notification preference for a recipient. Pass an optional `medium`
191
+ (`"in_app"` or `"email"`) to toggle in-app and email independently for the same
192
+ target. It defaults to `"in_app"` when omitted.
193
+
194
+ ```typescript
195
+ await bodhveda.recipients.preferences.set("user-123", {
196
+ target: { channel: "digest", topic: "none", event: "sent" },
197
+ medium: "email",
198
+ state: { enabled: true },
199
+ });
200
+ ```
201
+
202
+ ### Check a preference
203
+
204
+ Check the state of a specific preference for a recipient.
205
+
206
+ ```typescript
207
+ const result = await bodhveda.recipients.preferences.check("user-123", {
208
+ target: { channel: "digest", topic: "none", event: "sent" },
209
+ medium: "email",
210
+ });
211
+ ```
212
+
213
+ ---
214
+
215
+ ## Recipient Contacts
216
+
217
+ Contacts are per-medium addresses for a recipient. To send **email** to a recipient,
218
+ add an `email` contact and mark it primary. Sync this **server-side** (e.g. on your
219
+ `/me` endpoint) so the address never rides a browser request.
220
+
221
+ `create`, `list`, and `update` work with a `Full access` or `Recipient access` API
222
+ key; `delete` requires `Full access`.
223
+
224
+ ### Add a contact
225
+
226
+ ```typescript
227
+ await bodhveda.recipients.contacts.create("user-123", {
228
+ medium: "email",
229
+ address: "alice@example.com",
230
+ is_primary: true,
231
+ });
232
+ ```
233
+
234
+ ### List contacts
235
+
236
+ ```typescript
237
+ const { contacts } = await bodhveda.recipients.contacts.list("user-123");
238
+ ```
239
+
240
+ ### Update a contact
241
+
242
+ ```typescript
243
+ await bodhveda.recipients.contacts.update("user-123", 1, {
244
+ address: "alice.new@example.com",
245
+ });
246
+ ```
247
+
248
+ ### Delete a contact
249
+
250
+ Requires a `Full access` API key.
251
+
252
+ ```typescript
253
+ await bodhveda.recipients.contacts.delete("user-123", 1);
254
+ ```
255
+
256
+ ---
257
+
258
+ ## License
259
+
260
+ MIT
@@ -0,0 +1,184 @@
1
+ import { ListNotificationsResponse, ListNotificationsRequest, ListPreferencesResponse, SetPreferenceRequest, SetPreferenceResponse, UnreadCountResponse, UpdateNotificationsStateResponse, UpdateNotificationsStateRequest, DeleteNotificationsRequest, DeleteNotificationsResponse, CheckPreferenceRequest, CheckPreferenceResponse, SendNotificationRequest, SendNotificationResponse, CreateRecipientRequest, CreateRecipientResponse, CreateRecipientsBatchRequest, CreateRecipientsBatchResponse, GetRecipientResponse, UpdateRecipientRequest, UpdateRecipientResponse, CreateRecipientContactRequest, CreateRecipientContactResponse, ListRecipientContactsResponse, UpdateRecipientContactRequest, UpdateRecipientContactResponse } from "./types";
2
+ /**
3
+ * Options for configuring the Bodhveda SDK.
4
+ */
5
+ interface BodhvedaOptions {
6
+ apiURL?: string;
7
+ }
8
+ /**
9
+ * Main interface for interacting with Bodhveda services.
10
+ */
11
+ interface BodhvedaClient {
12
+ /**
13
+ * Provides access to notification-related methods.
14
+ */
15
+ notifications: NotificationsClient;
16
+ /**
17
+ * Provides access to recipient-related methods.
18
+ */
19
+ recipients: RecipientsClient;
20
+ }
21
+ /**
22
+ * Main class for initializing and interacting with the Bodhveda SDK.
23
+ */
24
+ export declare class Bodhveda implements BodhvedaClient {
25
+ notifications: NotificationsClient;
26
+ recipients: RecipientsClient;
27
+ /**
28
+ * Creates an instance of the Bodhveda SDK.
29
+ * @param apiKey - The API key for authentication.
30
+ * @param options - Optional configuration options.
31
+ */
32
+ constructor(apiKey: string, options?: BodhvedaOptions);
33
+ }
34
+ /**
35
+ * Interface for interacting with notifications.
36
+ */
37
+ interface NotificationsClient {
38
+ /**
39
+ * Sends a notification.
40
+ * @param req - The request object containing notification details.
41
+ * @returns The response from the API.
42
+ */
43
+ send(req: SendNotificationRequest): Promise<SendNotificationResponse>;
44
+ }
45
+ /**
46
+ * Interface for interacting with recipients.
47
+ */
48
+ interface RecipientsClient {
49
+ /**
50
+ * Creates a new recipient.
51
+ * @param req - The request object containing recipient details.
52
+ * @returns The response after creating the recipient.
53
+ */
54
+ create(req: CreateRecipientRequest): Promise<CreateRecipientResponse>;
55
+ /**
56
+ * Creates multiple recipients in a batch.
57
+ * @param req - The request object containing an array of recipients.
58
+ * @returns The response after creating recipients in batch.
59
+ */
60
+ createBatch(req: CreateRecipientsBatchRequest): Promise<CreateRecipientsBatchResponse>;
61
+ /**
62
+ * Retrieves a recipient by ID.
63
+ * @param recipientID - The unique identifier of the recipient.
64
+ * @returns The recipient details.
65
+ */
66
+ get(recipientID: string): Promise<GetRecipientResponse>;
67
+ /**
68
+ * Updates a recipient by ID.
69
+ * @param recipientID - The unique identifier of the recipient.
70
+ * @param req - The request object containing updated recipient details.
71
+ * @returns The updated recipient details.
72
+ */
73
+ update(recipientID: string, req: UpdateRecipientRequest): Promise<UpdateRecipientResponse>;
74
+ /**
75
+ * Deletes a recipient by ID.
76
+ * @param recipientID - The unique identifier of the recipient.
77
+ * @returns A promise that resolves when the recipient is deleted.
78
+ */
79
+ delete(recipientID: string): Promise<void>;
80
+ /**
81
+ * Provides access to recipient preferences methods.
82
+ */
83
+ preferences: RecipientsPreferencesClient;
84
+ /**
85
+ * Provides access to recipient notifications methods.
86
+ */
87
+ notifications: RecipientsNotificationsClient;
88
+ /**
89
+ * Provides access to recipient contacts methods.
90
+ */
91
+ contacts: RecipientsContactsClient;
92
+ }
93
+ /**
94
+ * Interface for managing recipient notifications.
95
+ */
96
+ interface RecipientsNotificationsClient {
97
+ /**
98
+ * Lists notifications for a recipient.
99
+ * @param recipientID - The unique identifier of the recipient.
100
+ * @param req - Optional request parameters for listing notifications.
101
+ * @returns The response containing the list of notifications.
102
+ */
103
+ list(recipientID: string, req?: ListNotificationsRequest): Promise<ListNotificationsResponse>;
104
+ /**
105
+ * Gets the count of unread notifications for a recipient.
106
+ * @param recipientID - The unique identifier of the recipient.
107
+ * @returns The response containing the unread count.
108
+ */
109
+ unreadCount(recipientID: string): Promise<UnreadCountResponse>;
110
+ /**
111
+ * Updates the state of notifications for a recipient.
112
+ * @param recipientID - The unique identifier of the recipient.
113
+ * @param req - The request object containing state updates.
114
+ * @returns The response after updating notification states.
115
+ */
116
+ updateState(recipientID: string, req: UpdateNotificationsStateRequest): Promise<UpdateNotificationsStateResponse>;
117
+ /**
118
+ * Deletes notifications for a recipient.
119
+ * @param recipientID - The unique identifier of the recipient.
120
+ * @param req - The request object containing IDs of notifications to delete.
121
+ * @returns The response after deleting notifications.
122
+ */
123
+ delete(recipientID: string, req: DeleteNotificationsRequest): Promise<DeleteNotificationsResponse>;
124
+ }
125
+ /**
126
+ * Interface for managing recipient preferences.
127
+ */
128
+ interface RecipientsPreferencesClient {
129
+ /**
130
+ * Lists preferences for a recipient.
131
+ * @param recipientID - The unique identifier of the recipient.
132
+ * @returns The response containing the list of preferences.
133
+ */
134
+ list(recipientID: string): Promise<ListPreferencesResponse>;
135
+ /**
136
+ * Sets a preference for a recipient.
137
+ * @param recipientID - The unique identifier of the recipient.
138
+ * @param req - The request object containing the preference to set.
139
+ * @returns The response after setting the preference.
140
+ */
141
+ set(recipientID: string, req: SetPreferenceRequest): Promise<SetPreferenceResponse>;
142
+ /**
143
+ * Checks a preference for a recipient.
144
+ * @param recipientID - The unique identifier of the recipient.
145
+ * @param req - The request object specifying the preference to check.
146
+ * @returns The response after checking the preference.
147
+ */
148
+ check(recipientID: string, req: CheckPreferenceRequest): Promise<CheckPreferenceResponse>;
149
+ }
150
+ /**
151
+ * Interface for managing recipient contacts.
152
+ */
153
+ interface RecipientsContactsClient {
154
+ /**
155
+ * Lists a recipient's contacts.
156
+ * @param recipientID - The unique identifier of the recipient.
157
+ * @returns The response containing the list of contacts.
158
+ */
159
+ list(recipientID: string): Promise<ListRecipientContactsResponse>;
160
+ /**
161
+ * Adds a contact to a recipient.
162
+ * @param recipientID - The unique identifier of the recipient.
163
+ * @param req - The request object containing the contact to add.
164
+ * @returns The response after creating the contact.
165
+ */
166
+ create(recipientID: string, req: CreateRecipientContactRequest): Promise<CreateRecipientContactResponse>;
167
+ /**
168
+ * Updates a recipient's contact by contact ID.
169
+ * @param recipientID - The unique identifier of the recipient.
170
+ * @param contactID - The unique identifier of the contact.
171
+ * @param req - The request object containing the fields to update.
172
+ * @returns The response after updating the contact.
173
+ */
174
+ update(recipientID: string, contactID: number, req: UpdateRecipientContactRequest): Promise<UpdateRecipientContactResponse>;
175
+ /**
176
+ * Deletes a recipient's contact by contact ID. Requires a full-scope API key.
177
+ * @param recipientID - The unique identifier of the recipient.
178
+ * @param contactID - The unique identifier of the contact.
179
+ * @returns A promise that resolves when the contact is deleted.
180
+ */
181
+ delete(recipientID: string, contactID: number): Promise<void>;
182
+ }
183
+ export {};
184
+ //# sourceMappingURL=bodhveda.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bodhveda.d.ts","sourceRoot":"","sources":["../../src/bodhveda.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,yBAAyB,EACzB,wBAAwB,EACxB,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,gCAAgC,EAChC,+BAA+B,EAC/B,0BAA0B,EAC1B,2BAA2B,EAC3B,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,wBAAwB,EACxB,sBAAsB,EACtB,uBAAuB,EACvB,4BAA4B,EAC5B,6BAA6B,EAC7B,oBAAoB,EACpB,sBAAsB,EACtB,uBAAuB,EACvB,6BAA6B,EAC7B,8BAA8B,EAC9B,6BAA6B,EAC7B,6BAA6B,EAC7B,8BAA8B,EACjC,MAAM,SAAS,CAAC;AAGjB;;GAEG;AACH,UAAU,eAAe;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,UAAU,cAAc;IACpB;;OAEG;IACH,aAAa,EAAE,mBAAmB,CAAC;IACnC;;OAEG;IACH,UAAU,EAAE,gBAAgB,CAAC;CAChC;AAED;;GAEG;AACH,qBAAa,QAAS,YAAW,cAAc;IAC3C,aAAa,EAAE,mBAAmB,CAAC;IACnC,UAAU,EAAE,gBAAgB,CAAC;IAE7B;;;;OAIG;gBACS,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB;CAyB5D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,OAAO,CAAC,2BAA2B,CAAC,CAAC;CAC3C;AA6DD;;GAEG;AACH,UAAU,2BAA2B;IACjC;;;;OAIG;IACH,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAE5D;;;;;OAKG;IACH,GAAG,CACC,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,oBAAoB,GAC1B,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAElC;;;;;OAKG;IACH,KAAK,CACD,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,sBAAsB,GAC5B,OAAO,CAAC,uBAAuB,CAAC,CAAC;CACvC;AAoDD;;GAEG;AACH,UAAU,wBAAwB;IAC9B;;;;OAIG;IACH,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;IAElE;;;;;OAKG;IACH,MAAM,CACF,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,6BAA6B,GACnC,OAAO,CAAC,8BAA8B,CAAC,CAAC;IAE3C;;;;;;OAMG;IACH,MAAM,CACF,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,6BAA6B,GACnC,OAAO,CAAC,8BAA8B,CAAC,CAAC;IAE3C;;;;;OAKG;IACH,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjE"}
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Bodhveda = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const routes_1 = require("./routes");
9
+ /**
10
+ * Main class for initializing and interacting with the Bodhveda SDK.
11
+ */
12
+ class Bodhveda {
13
+ /**
14
+ * Creates an instance of the Bodhveda SDK.
15
+ * @param apiKey - The API key for authentication.
16
+ * @param options - Optional configuration options.
17
+ */
18
+ constructor(apiKey, options = {}) {
19
+ const { apiURL = "https://api.bodhveda.com" } = options;
20
+ const client = axios_1.default.create({
21
+ baseURL: apiURL,
22
+ headers: {
23
+ "Content-Type": "application/json",
24
+ Authorization: `Bearer ${apiKey}`,
25
+ },
26
+ });
27
+ client.interceptors.response.use((response) => response.data, // Unwrap the main data object from the response.
28
+ (error) => {
29
+ var _a, _b;
30
+ if (axios_1.default.isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data)) {
31
+ throw (_b = error.response) === null || _b === void 0 ? void 0 : _b.data; // Throw the API's error response directly.
32
+ }
33
+ else {
34
+ throw error;
35
+ }
36
+ });
37
+ this.notifications = new Notifications(client);
38
+ this.recipients = new Recipients(client);
39
+ }
40
+ }
41
+ exports.Bodhveda = Bodhveda;
42
+ /**
43
+ * Class for managing notifications.
44
+ */
45
+ class Notifications {
46
+ /**
47
+ * Creates an instance of the Notifications class.
48
+ * @param client - The Axios client instance.
49
+ */
50
+ constructor(client) {
51
+ this.client = client;
52
+ }
53
+ async send(req) {
54
+ const response = await this.client.post(routes_1.ROUTES.notifications.send, req);
55
+ return response.data;
56
+ }
57
+ }
58
+ /**
59
+ * Class for managing recipients.
60
+ */
61
+ class Recipients {
62
+ /**
63
+ * Creates an instance of the Recipients class.
64
+ * @param client - The Axios client instance.
65
+ */
66
+ constructor(client) {
67
+ this.client = client;
68
+ this.notifications = new RecipientsNotifications(client);
69
+ this.preferences = new RecipientsPreferences(client);
70
+ this.contacts = new RecipientsContacts(client);
71
+ }
72
+ async create(req) {
73
+ const response = await this.client.post(routes_1.ROUTES.recipients.create, req);
74
+ return response.data;
75
+ }
76
+ async createBatch(req) {
77
+ const response = await this.client.post(routes_1.ROUTES.recipients.createBatch, req);
78
+ return response.data;
79
+ }
80
+ async get(recipientID) {
81
+ const response = await this.client.get(routes_1.ROUTES.recipients.get(recipientID));
82
+ return response.data;
83
+ }
84
+ async update(recipientID, req) {
85
+ const response = await this.client.patch(routes_1.ROUTES.recipients.update(recipientID), req);
86
+ return response.data;
87
+ }
88
+ async delete(recipientID) {
89
+ await this.client.delete(routes_1.ROUTES.recipients.delete(recipientID));
90
+ }
91
+ }
92
+ /**
93
+ * Class for managing recipient notifications.
94
+ */
95
+ class RecipientsNotifications {
96
+ /**
97
+ * Creates an instance of the RecipientsNotifications class.
98
+ * @param client - The Axios client instance.
99
+ */
100
+ constructor(client) {
101
+ this.client = client;
102
+ }
103
+ async list(recipientID, req) {
104
+ const response = await this.client.get(routes_1.ROUTES.recipients.notifications.list(recipientID), {
105
+ params: req,
106
+ });
107
+ return response.data;
108
+ }
109
+ async unreadCount(recipientID) {
110
+ const response = await this.client.get(routes_1.ROUTES.recipients.notifications.unreadCount(recipientID));
111
+ return response.data;
112
+ }
113
+ async updateState(recipientID, req) {
114
+ const response = await this.client.patch(routes_1.ROUTES.recipients.notifications.udpateState(recipientID), req);
115
+ return response.data;
116
+ }
117
+ async delete(recipientID, req) {
118
+ const response = await this.client.delete(routes_1.ROUTES.recipients.notifications.delete(recipientID), {
119
+ data: req,
120
+ });
121
+ return response.data;
122
+ }
123
+ }
124
+ /**
125
+ * Class for managing recipient preferences.
126
+ */
127
+ class RecipientsPreferences {
128
+ /**
129
+ * Creates an instance of the RecipientsPreferences class.
130
+ * @param client - The Axios client instance.
131
+ */
132
+ constructor(client) {
133
+ this.client = client;
134
+ }
135
+ async list(recipientID) {
136
+ const response = await this.client.get(routes_1.ROUTES.recipients.preferences.list(recipientID));
137
+ return response.data;
138
+ }
139
+ async set(recipientID, req) {
140
+ const response = await this.client.patch(routes_1.ROUTES.recipients.preferences.set(recipientID), {
141
+ target: req.target,
142
+ medium: req.medium,
143
+ state: req.state,
144
+ });
145
+ return response.data;
146
+ }
147
+ async check(recipientID, req) {
148
+ const response = await this.client.get(routes_1.ROUTES.recipients.preferences.check(recipientID), {
149
+ params: { ...req.target, medium: req.medium },
150
+ });
151
+ return response.data;
152
+ }
153
+ }
154
+ /**
155
+ * Class for managing recipient contacts.
156
+ */
157
+ class RecipientsContacts {
158
+ /**
159
+ * Creates an instance of the RecipientsContacts class.
160
+ * @param client - The Axios client instance.
161
+ */
162
+ constructor(client) {
163
+ this.client = client;
164
+ }
165
+ async list(recipientID) {
166
+ const response = await this.client.get(routes_1.ROUTES.recipients.contacts.list(recipientID));
167
+ return response.data;
168
+ }
169
+ async create(recipientID, req) {
170
+ const response = await this.client.post(routes_1.ROUTES.recipients.contacts.create(recipientID), req);
171
+ return response.data;
172
+ }
173
+ async update(recipientID, contactID, req) {
174
+ const response = await this.client.patch(routes_1.ROUTES.recipients.contacts.update(recipientID, contactID), req);
175
+ return response.data;
176
+ }
177
+ async delete(recipientID, contactID) {
178
+ await this.client.delete(routes_1.ROUTES.recipients.contacts.delete(recipientID, contactID));
179
+ }
180
+ }
181
+ //# sourceMappingURL=bodhveda.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bodhveda.js","sourceRoot":"","sources":["../../src/bodhveda.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyD;AA8BzD,qCAAkC;AAuBlC;;GAEG;AACH,MAAa,QAAQ;IAIjB;;;;OAIG;IACH,YAAY,MAAc,EAAE,UAA2B,EAAE;QACrD,MAAM,EAAE,MAAM,GAAG,0BAA0B,EAAE,GAAG,OAAO,CAAC;QAExD,MAAM,MAAM,GAAG,eAAK,CAAC,MAAM,CAAC;YACxB,OAAO,EAAE,MAAM;YACf,OAAO,EAAE;gBACL,cAAc,EAAE,kBAAkB;gBAClC,aAAa,EAAE,UAAU,MAAM,EAAE;aACpC;SACJ,CAAC,CAAC;QAEH,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAC5B,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,iDAAiD;QAC9E,CAAC,KAAiB,EAAE,EAAE;;YAClB,IAAI,eAAK,CAAC,YAAY,CAAC,KAAK,CAAC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SAAiB,EACjB,GAAkC;QAElC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CACpC,eAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,EACzD,GAAG,CACN,CAAC;QACF,OAAO,QAAQ,CAAC,IAAsC,CAAC;IAC3D,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,WAAmB,EAAE,SAAiB;QAC/C,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CACpB,eAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,CAC5D,CAAC;IACN,CAAC;CACJ"}
@@ -0,0 +1,3 @@
1
+ export * from "./bodhveda";
2
+ export * from "./types";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./bodhveda"), exports);
18
+ __exportStar(require("./types"), exports);
19
+ //# sourceMappingURL=index.js.map