Skip to content

Commit 6675b4c

Browse files
Version 1.1.0
Merge pull request #32 from KeyValueSoftwareSystems/dev
2 parents 7784aab + c8f8019 commit 6675b4c

25 files changed

+384
-243
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [1.1.0] - 2024-05-07
6+
7+
### Changed
8+
9+
- actionCallbacks object structure to handle generic use cases
10+
- Improved API error handling
11+
- Improved exposed function names
12+
513
## [1.0.0] - 2024-03-26
614

715
### Added
8-
- JavaScript middleware designed to streamline interaction for managing and displaying in-app notifications
916

17+
- JavaScript middleware designed to streamline interaction for managing and displaying in-app notifications

README.md

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ The Siren JS SDK for In-App Notifications enhances Siren's capabilities by provi
44

55
## Installation
66

7-
You can install the js sdk from npm
7+
You can install the js sdk from npm
88

99
```bash
1010
npm install @sirenapp/js-sdk
1111
```
12+
1213
or from yarn
14+
1315
```bash
1416
yarn add @sirenapp/js-sdk
1517
```
18+
1619
or from cdn
20+
1721
```bash
1822
<script src="https://siren-js.sirenapp.io/siren-js-umd-sdk.js"></script>
1923
```
@@ -32,19 +36,18 @@ const sirenInstance = new Siren({
3236
# error callback function
3337
});
3438
actionCallbacks:{
35-
onNotificationReceived?: (response: NotificationsApiResponse) => {
36-
# callback function on getting notifications
37-
};
38-
onUnViewedCountReceived?: (response: UnviewedCountApiResponse) => {
39-
# callback function on getting unviewed count
39+
onEventReceive?: (response: NotificationsApiResponse, eventType: 'NOTIFICATIONS'| 'UNVIEWED_COUNT') => {
40+
# callback function to receive data
4041
};
4142
onStatusChange?: (status: 'SUCCESS' | 'FAILED' | 'PENDING') =>{
4243
# callback function triggered when token verification status changes
4344
}
4445
}
4546
```
47+
4648
All the exposed methods can be accessed using sirenInstance object.
4749
For example,to fetch all notifications,
50+
4851
```bash
4952
const response = await sirenInstance.fetchAllNotifications({ page: 0, size: 10 })
5053
```
@@ -88,24 +91,28 @@ Siren constructor accepts the following arguments
8891
</tbody>
8992
</table>
9093

91-
9294
## Siren Methods
9395

9496
### 1. verifyToken
97+
9598
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.
99+
96100
```bash
97101
await sirenInstance.verifyToken();
98102
```
99103

100104
### 2. fetchUnviewedNotificationsCount
105+
101106
This method retrieves the count of unviewed notifications.
107+
102108
```bash
103109
const { unviewedCount } = await sirenInstance.fetchUnviewedNotificationsCount()
104110
```
105111
106-
107112
### 3. fetchAllNotifications
113+
108114
This method retrieves list of notifications in a paginated manner.
115+
109116
```bash
110117
const notifications = await sirenInstance.fetchAllNotifications({ page: 0, size: 15, start: '', end: '', isRead: false });
111118
```
@@ -116,7 +123,7 @@ const notifications = await sirenInstance.fetchAllNotifications({ page: 0, size:
116123
<th>Argument</th>
117124
<th>Description</th>
118125
<th>Type</th>
119-
<th>Optional</th>
126+
<th>Mandatory</th>
120127
<th>Default</th>
121128
</tr>
122129
</thead>
@@ -162,6 +169,7 @@ const notifications = await sirenInstance.fetchAllNotifications({ page: 0, size:
162169
</table>
163170
164171
#### Response
172+
165173
```bash
166174
interface Notifications = {
167175
id: string;
@@ -182,20 +190,25 @@ const notifications = await sirenInstance.fetchAllNotifications({ page: 0, size:
182190
isRead: boolean;
183191
}[]
184192
```
185-
### 4. startRealTimeNotificationFetch
186-
This method initiates the real-time fetching of notifications
193+
194+
### 4. startRealTimeFetch
195+
196+
By specifying the parameter eventType as either `NOTIFICATIONS` or `UNVIEWED_COUNT`, this method triggers the real-time retrieval of notifications or the count of unviewed notifications. If `NOTIFICATIONS` is selected, further parameters (`params`) can be provided for additional customization or filtering
197+
187198
```bash
188-
await sirenInstance.startRealTimeNotificationFetch({ page: 0, size: 15, start: '', end: '', isRead: false });
199+
sirenInstance.startRealTimeFetch({ eventType: NOTIFICATIONS, params:{ page: 0, size: 15, start: '', end: '', isRead: false }});
200+
201+
sirenInstance.startRealTimeFetch({ eventType: UNVIEWED_COUNT });
189202
```
190-
The notifications received can be subscribed using the `onNotificationReceived` actionCallback.
191203
204+
Below are the accepted filters for notifications
192205
<table>
193206
<thead>
194207
<tr>
195208
<th>Argument</th>
196209
<th>Description</th>
197210
<th>Type</th>
198-
<th>Optional</th>
211+
<th>Mandatory</th>
199212
<th>Default</th>
200213
</tr>
201214
</thead>
@@ -238,55 +251,56 @@ The notifications received can be subscribed using the `onNotificationReceived`
238251
</tbody>
239252
</table>
240253
241-
### 5. startRealTimeUnviewedCountFetch
242-
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.
243-
```bash
244-
await sirenInstance.startRealTimeUnviewedCountFetch();
245-
```
254+
### 5. stopRealTimeFetch
246255
247-
### 6. stopRealTimeNotificationFetch
248-
This method stops the fetching of realtime notifications
249-
```bash
250-
await sirenInstance.stopRealTimeNotificationFetch();
251-
```
256+
By specifying the parameter eventType as either `NOTIFICATIONS` or `UNVIEWED_COUNT`, this method stops the real-time retrieval of notifications or the count of unviewed notifications.
252257
253-
### 7. stopRealTimeUnviewedCountFetch
254-
This method stops the fetching of realtime unviewed count
255258
```bash
256-
await sirenInstance.stopRealTimeUnviewedCountFetch();
259+
sirenInstance.stopRealTimeFetch(NOTIFICATIONS);
260+
261+
262+
sirenInstance.stopRealTimeFetch(UNVIEWED_COUNT);
257263
```
258264
259-
### 8. markAsReadById
265+
### 6. markAsReadById
266+
260267
This method marks the notification as read. It accepts a notification id as an argument.
268+
261269
```bash
262270
await sirenInstance.markAsReadById("your-notification-id");
263271
```
264272
265-
### 9. markNotificationsAsReadByDate
273+
### 7. markAsReadByDate
274+
266275
This method marks the notifications as read till the given date.<br />
267276
It accepts an ISO date string as an argument.
277+
268278
```bash
269-
await sirenInstance.markNotificationsAsReadByDate("2011-10-05T14:48:00.000Z");
279+
await sirenInstance.markAsReadByDate("2011-10-05T14:48:00.000Z");
270280
```
271281
272-
### 10. deleteNotificationById
282+
### 8. deleteById
283+
273284
This method deletes a notification. It accepts a notification id as an argument.
285+
274286
```bash
275-
await sirenInstance.deleteNotificationById("your-notification-id");
287+
await sirenInstance.deleteById("your-notification-id");
276288
```
277289
278-
### 11. deleteNotificationsByDate
290+
### 9. deleteByDate
291+
279292
This method deletes the notifications till the given date.<br />
280293
It accepts an ISO date string as an argument
281294
282295
```bash
283-
await sirenInstance.deleteNotificationsByDate("2011-10-05T14:48:00.000Z");
296+
await sirenInstance.deleteByDate("2011-10-05T14:48:00.000Z");
284297
```
285298
286-
### 12. markNotificationsAsViewed
299+
### 10. markAllAsViewed
300+
287301
This method marks the notifications as viewed till the given date. This sets the unviewed count as 0 <br />
288302
It accepts an ISO date string as an argument
289303
290304
```bash
291-
await sirenInstance.markNotificationsAsViewed("2011-10-05T14:48:00.000Z");
305+
await sirenInstance.markAllAsViewed("2011-10-05T14:48:00.000Z");
292306
```

examples/index.html

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,16 @@ <h1>Logs</h1>
5757
onError: (error) => {
5858
console.log('Error callback:', error);
5959
},
60-
actionCallbacks:{
61-
onNotificationReceived: (response) => {
62-
if(response.data.length > 0)
60+
actionCallbacks: {
61+
onEventReceive: (response, eventType) => {
62+
console.log(eventType)
63+
if(eventType === 'NOTIFICATIONS' && response.data.length > 0)
6364
document.getElementById("output").innerHTML = 'New Notifications ' + JSON.stringify(response, null, 2);
64-
},
65-
onUnViewedCountReceived:(response) => {
66-
if(response.data)
65+
else if(eventType === 'UNVIEWED_COUNT' && response.data)
6766
document.getElementById("output").innerHTML = 'Latest unviewed count ' + JSON.stringify(response, null, 2);
68-
},
69-
},
70-
dataFetchIntervalsInMilliSeconds:{
71-
notificationFetch: 2000,
72-
unViewedCountFetch: 2000
7367
}
74-
7568
}
76-
);
69+
});
7770
}
7871

7972
async function getUnviewedCount() {
@@ -95,67 +88,67 @@ <h1>Logs</h1>
9588
function startNotificationsRealTimeFetch() {
9689
document.getElementById("output").innerHTML = '';
9790
if (sirenWeb) {
98-
sirenWeb.startRealTimeNotificationFetch({ page: 0, size: 10 });
91+
sirenWeb.startRealTimeFetch({eventType: 'NOTIFICATIONS', params: { page: 0, size: 10 }});
9992
}
10093
}
10194

10295
function stopNotificationsRealTimeFetch() {
10396
if (sirenWeb) {
104-
sirenWeb.stopRealTimeNotificationFetch();
97+
sirenWeb.stopRealTimeFetch('NOTIFICATIONS');
10598
document.getElementById("output").innerHTML = 'Fetch disabled';
10699
}
107100
}
108101

109102
function startUnviewedCountRealTimeFetch() {
110103
document.getElementById("output").innerHTML = '';
111104
if (sirenWeb) {
112-
sirenWeb.startRealTimeUnviewedCountFetch({ page: 0, size: 10 });
105+
sirenWeb.startRealTimeFetch({eventType: 'UNVIEWED_COUNT'})
113106
}
114107
}
115108

116109
function stopUnviewedCountRealTimeFetch() {
117110
if (sirenWeb) {
118-
sirenWeb.stopRealTimeUnviewedCountFetch();
111+
sirenWeb.stopRealTimeFetch('UNVIEWED_COUNT');
119112
document.getElementById("output").innerHTML = 'Fetch disabled';
120113
}
121114
}
122115

123116

124117
async function markAsReadById() {
125118
if (sirenWeb) {
126-
const res = await sirenWeb.markNotificationAsReadById(notificationId);
119+
const res = await sirenWeb.markAsReadById(notificationId);
127120
document.getElementById("output").innerHTML = 'Mark Notification as Read ' + JSON.stringify(res, null, 2);
128121
console.log('markNotificationAsReadById', res);
129122
}
130123
}
131124

132125
async function markAllAsRead() {
133126
if (sirenWeb) {
134-
const res= await sirenWeb.markNotificationsAsReadByDate(new Date().toISOString());
127+
const res= await sirenWeb.markAsReadByDate(new Date().toISOString());
135128
document.getElementById("output").innerHTML = 'Mark All as Read ' + JSON.stringify(res, null, 2);
136129
console.log('markAllNotificationsAsRead', res);
137130
}
138131
}
139132

140133
async function deleteById() {
141134
if (sirenWeb) {
142-
const res= await sirenWeb.deleteNotificationById(notificationId);
135+
const res= await sirenWeb.deleteById(notificationId);
143136
document.getElementById("output").innerHTML = 'Delete Notification ' + JSON.stringify(res, null, 2);
144137
console.log('deleteNotificationById', res);
145138
}
146139
}
147140

148141
async function clearAll() {
149142
if (sirenWeb) {
150-
const res = await sirenWeb.deleteNotificationsByDate(new Date().toISOString());
143+
const res = await sirenWeb.deleteByDate(new Date().toISOString());
151144
document.getElementById("output").innerHTML = 'Delete All Notification ' + JSON.stringify(res, null, 2);
152145
console.log('clearAllNotifications', res);
153146
}
154147
}
155148

156149
async function markAsViewed() {
157150
if (sirenWeb) {
158-
const res = await sirenWeb.markNotificationsAsViewed(new Date().toISOString());
151+
const res = await sirenWeb.markAllAsViewed(new Date().toISOString());
159152
document.getElementById("output").innerHTML = 'Mark Notifications as viewed ' + JSON.stringify(res, null, 2);
160153
console.log('markAllNotificationsAsRead', res);
161154
}

0 commit comments

Comments
 (0)