Skip to content

Commit 49e158d

Browse files
docs: Update README doc
2 parents 0ab81c2 + 8a26f31 commit 49e158d

File tree

1 file changed

+47
-66
lines changed

1 file changed

+47
-66
lines changed

README.md

Lines changed: 47 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The JavaScript JS SDK empowers you to streamline backend interaction and efficie
44

55
## Installation
66

7-
The easiest way to use js sdk is to install it from npm
7+
You can install the js sdk from npm
88

99
```bash
1010
npm install @siren/js-sdk
@@ -16,7 +16,7 @@ yarn add @siren/js-sdk
1616

1717
## Usage
1818

19-
You can access the exposed methods by creating an instance of siren
19+
Initialize the SDK by creating a class instance as follows
2020

2121
```bash
2222
import Siren from "@siren/js-sdk"
@@ -27,15 +27,21 @@ const sirenInstance = new Siren({
2727
onError: (error) => {
2828
# error callback function
2929
});
30+
actionCallbacks:{
31+
onNotificationReceived?: (response: NotificationsApiResponse) => {
32+
# callback function on getting notifications
33+
};
34+
onUnViewedCountReceived?: (response: UnviewedCountApiResponse) => {
35+
# callback function on getting unviewed count
36+
};
37+
}
3038
```
31-
All the exposed functions can be accessed using sirenInstance object.
39+
All the exposed methods can be accessed using sirenInstance object.
3240
For example,to fetch all notifications,
3341
```bash
34-
const response = await sirenInstance.fetchAllNotifications({ page: 0, size: 10, isRead: false })
42+
const response = await sirenInstance.fetchAllNotifications({ page: 0, size: 10 })
3543
```
3644

37-
## constructor
38-
3945
Siren constructor accepts the following arguments
4046

4147
<table>
@@ -75,50 +81,28 @@ Siren constructor accepts the following arguments
7581
</tbody>
7682
</table>
7783

78-
```bash
79-
const sirenInstance = new Siren({
80-
token: "your-user-token",
81-
recipientId: "your-recipient-id",
82-
onError: (error) => {
83-
# error callback function
84-
});
85-
actionCallbacks:{
86-
onNotificationReceived: (response) => {
87-
# handle the notification list
88-
},
89-
onUnViewedCountReceived:(response) => {
90-
# handle the unviewed count response
91-
},
92-
},
93-
```
94-
To generate the token and recipientId, follow the below steps
95-
1. Create a new in_app provider account or use an existing one. From the in_app provider account use the `providerIntegrationId`.
96-
2. Create a new API_KEY or use an existing one.
97-
3. Utilize the `providerIntegrationId` and `API_KEY` to make a POST request to the /api/v1/in-app/recipients API. This will generate the user_token and recipient_id.
98-
4. Include the API_KEY as the bearer token in the authorization header of the request.
99-
100-
Api Body
101-
```bash
102-
{ "referenceId": "user-unique-id", "providerIntegrationId": "provider-integration-id-from-siren" }
103-
```
10484

10585
## Siren Methods
10686

10787
### 1. verifyToken
108-
Method to verify validity of the passed tokens. Access to the remaining exposed functions is only granted after invoking this function. Upon successful verification, it returns a 'SUCCESS' string as data.
88+
This method verifies the validity of the given tokens (recipientId and userToken).This method is called automatically while creating the instance . Once the verification is successful, the remaining exposed methods can be accessed.
10989
```bash
11090
await sirenInstance.verifyToken();
11191
```
11292

11393
### 2. fetchUnviewedNotificationsCount
114-
The method to retrieve the count of unviewed notifications
94+
This method retrieves the count of unviewed notifications.
11595
```bash
11696
const { unviewedCount } = await sirenInstance.fetchUnviewedNotificationsCount()
11797
```
11898
11999
120100
### 3. fetchAllNotifications
121-
Method to fetch the paginated list of notifications
101+
This method retrieves list of notifications in a paginated manner.
102+
```bash
103+
const notifications = await sirenInstance.fetchAllNotifications({ page: 0, size: 15, start: '', end: '', isRead: false });
104+
```
105+
122106
<table>
123107
<thead>
124108
<tr>
@@ -132,48 +116,45 @@ Method to fetch the paginated list of notifications
132116
<tbody>
133117
<tr>
134118
<td>page</td>
135-
<td>Represents current page</td>
119+
<td>Current page</td>
136120
<td>number</td>
137121
<td>false</td>
138122
<td>0</td>
139123
</tr>
140124
<tr>
141125
<td>size</td>
142-
<td>Number of items to be fetched in a single call</td>
126+
<td>Number of items fetched </td>
143127
<td>number</td>
144128
<td>false</td>
145129
<td>10</td>
146130
</tr>
147131
<tr>
148132
<td>start</td>
149-
<td>Accepts a date string and serves as a filter to fetch notifications created after the specified date. If no value is provided, it defaults to retrieving the first 10 notifications<br />
133+
<td>Accepts an ISO date string to filter notifications created after the specified date. By default, only the first 20 notifications will be fetched <br />
150134
eg: 2024-02-19T06:37:33.792+00:00</td>
151135
<td>string</td>
152136
<td>false</td>
153137
<td>null</td>
154138
</tr>
155139
<tr>
156140
<td>end</td>
157-
<td>Accepts a date string and serves as a filter to fetch notifications created before the specified date. If no value is provided, it defaults to retrieving the first 10 notifications<br />
141+
<td>Accepts an ISO date string to filter notifications created before the specified date. By default, only the first 20 notifications will be fetched <br />
158142
eg: 2024-02-19T06:37:33.792+00:00</td>
159143
<td>string</td>
160144
<td>false</td>
161145
<td>null</td>
162146
</tr>
163147
<tr>
164148
<td>isRead</td>
165-
<td>This filter is used to fetch only read or unread notifications. If not specified, it retrieves both read and unread notifications</td>
166-
<td>number</td>
149+
<td>Filter to fetch read or unread notifications. If not specified, it retrieves both read and unread notifications</td>
150+
<td>boolean</td>
167151
<td>false</td>
168152
<td>null</td>
169153
</tr>
170154
</tbody>
171155
</table>
172156
173-
```bash
174-
const notifications = await sirenInstance.fetchAllNotifications({ page: 0, size: 15, start: '', end: '', isRead: false});
175-
```
176-
type of return value is given below
157+
#### Response
177158
```bash
178159
interface Notifications = {
179160
id: string;
@@ -195,7 +176,12 @@ type of return value is given below
195176
}[]
196177
```
197178
### 4. startRealTimeNotificationFetch
198-
Method to initiate the real-time fetching of notifications
179+
This method initiates the real-time fetching of notifications
180+
```bash
181+
await sirenInstance.startRealTimeNotificationFetch({ page: 0, size: 15, start: '', end: '', isRead: false });
182+
```
183+
The notifications received can be subscribed using the `onNotificationReceived` actionCallback.
184+
199185
<table>
200186
<thead>
201187
<tr>
@@ -223,82 +209,77 @@ Method to initiate the real-time fetching of notifications
223209
</tr>
224210
<tr>
225211
<td>start</td>
226-
<td>Accepts a date string and serves as a filter to fetch notifications created before the specified date. If no value is provided, it defaults to retrieving the first 10 notifications</td>
212+
<td>Accepts an ISO date string to filter notifications created after the specified date. By default, only the first 20 notifications will be fetched </td>
227213
<td>string</td>
228214
<td>false</td>
229215
<td>null</td>
230216
</tr>
231217
<tr>
232218
<td>end</td>
233-
<td>Accepts a date string and serves as a filter to fetch notifications created before the specified date. If no value is provided, it defaults to retrieving the first 10 notifications</td>
219+
<td>Accepts an ISO date string to filter notifications created before the specified date. By default, only the first 20 notifications will be fetched</td>
234220
<td>string</td>
235221
<td>false</td>
236222
<td>null</td>
237223
</tr>
238224
<tr>
239225
<td>isRead</td>
240-
<td>This filter is used to fetch only read or unread notifications. If not specified, it retrieves both read and unread notifications</td>
226+
<td>Filter to fetch read or unread notifications. If not specified, it retrieves both read and unread notifications</td>
241227
<td>number</td>
242228
<td>false</td>
243229
<td>null</td>
244230
</tr>
245231
</tbody>
246232
</table>
247233
248-
```bash
249-
const notifications = await sirenInstance.startRealTimeNotificationFetch({ page: 0, size: 15, start: '', end: '', isRead: false});
250-
```
251-
These new notifications can be subscribed using the `onNotificationReceived` actionCallback.
252-
253234
### 5. startRealTimeUnviewedCountFetch
254-
Method to initiate real-time tracking of unviewed notification count. It returns the count value after the last markNotificationsAsViewed function call. The count can be subscribed using the onUnViewedCountReceived actionCallback.
235+
This method initiates the real-time fetching of unviewed notification count.The count can be subscribed using the onUnViewedCountReceived actionCallback. It returns the count after the last markNotificationsAsViewed function call.
255236
```bash
256237
await sirenInstance.startRealTimeUnviewedCountFetch();
257238
```
258239
259240
### 6. stopRealTimeNotificationFetch
260-
Method to stop the realtime notification fetch
241+
This method stops the fetching of realtime notifications
261242
```bash
262243
await sirenInstance.stopRealTimeNotificationFetch();
263244
```
264245
265246
### 7. stopRealTimeUnviewedCountFetch
266-
Method to stop the realtime unviewed count fetch
247+
This method stops the fetching of realtime unviewed count
267248
```bash
268249
await sirenInstance.stopRealTimeUnviewedCountFetch();
269250
```
270251
271252
### 8. markAsReadById
272-
Method to mark a notification as read. Accepts the notification id as an argument
253+
This method marks the notification as read. It accepts a notification id as an argument.
273254
```bash
274255
await sirenInstance.markAsReadById("your-notification-id");
275256
```
276257
277258
### 9. markNotificationsAsReadByDate
278-
Method to mark the notifications as read till the passed date.<br />
279-
Accepts an ISO date string as a parameter
259+
This method marks the notifications as read till the given date.<br />
260+
It accepts an ISO date string as an argument.
280261
```bash
281262
await sirenInstance.markNotificationsAsReadByDate("2011-10-05T14:48:00.000Z");
282263
```
283264
284265
### 10. deleteNotificationById
285-
Method to delete a notification. Accepts the notification id as an argument
266+
This method deletes a notification. It accepts a notification id as an argument.
286267
```bash
287268
await sirenInstance.deleteNotificationById("your-notification-id");
288269
```
289270
290271
### 11. deleteNotificationsByDate
291-
Method to delete the notifications till the passed date.<br />
292-
Accepts an ISO date string as a parameter
272+
This method deletes the notifications till the given date.<br />
273+
It accepts an ISO date string as an argument
293274
294275
```bash
295276
await sirenInstance.deleteNotificationsByDate("2011-10-05T14:48:00.000Z");
296277
```
297278
298279
### 12. markNotificationsAsViewed
299-
Method to mark the notifications as viewed till the passed date. Once this is called the unviewed count will get reset to 0 <br />
300-
Accepts an ISO date string as a parameter
280+
This method marks the notifications as viewed till the given date. This sets the unviewed count as 0 <br />
281+
It accepts an ISO date string as an argument
301282
302283
```bash
303-
await sirenInstance.markNotificationsAsViewed(""2011-10-05T14:48:00.000Z"");
284+
await sirenInstance.markNotificationsAsViewed("2011-10-05T14:48:00.000Z");
304285
```

0 commit comments

Comments
 (0)