Skip to content

Commit ddb8aa6

Browse files
Fix: Remove verification token validation
* fix: Remove verify token call * fix: Eslint error * fix: Eslint error * 1.2.3-rc.0 * docs: Update change log * docs: Update read me * tests: Update test cases
1 parent 23fa077 commit ddb8aa6

File tree

8 files changed

+19
-169
lines changed

8 files changed

+19
-169
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

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

5+
### Fixed
6+
7+
## [1.2.4] - 2025-02-13
8+
9+
- Remove verify token api call
10+
511
## [1.2.1] - 2024-06-24
612

713
### Fixed

README.md

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ const sirenInstance = new Siren({
3939
onEventReceive?: (response: NotificationsApiResponse, eventType: 'NOTIFICATIONS'| 'UNVIEWED_COUNT') => {
4040
# callback function to receive data
4141
};
42-
onStatusChange?: (status: 'SUCCESS' | 'FAILED' | 'PENDING') =>{
43-
# callback function triggered when token verification status changes
44-
}
4542
}
4643
```
4744

@@ -93,23 +90,15 @@ Siren constructor accepts the following arguments
9390

9491
## Siren Methods
9592

96-
### 1. verifyToken
97-
98-
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-
100-
```bash
101-
await sirenInstance.verifyToken();
102-
```
103-
104-
### 2. fetchUnviewedNotificationsCount
93+
### 1. fetchUnviewedNotificationsCount
10594

10695
This method retrieves the count of unviewed notifications.
10796

10897
```bash
10998
const { unviewedCount } = await sirenInstance.fetchUnviewedNotificationsCount()
11099
```
111100
112-
### 3. fetchAllNotifications
101+
### 2. fetchAllNotifications
113102
114103
This method retrieves list of notifications in a paginated manner.
115104
@@ -192,7 +181,7 @@ Below are the accepted optional filters
192181
}[]
193182
```
194183
195-
### 4. startRealTimeFetch
184+
### 3. startRealTimeFetch
196185
197186
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
198187
@@ -253,7 +242,7 @@ Below are the accepted optional filters for `NOTIFICATIONS` event type
253242
</tbody>
254243
</table>
255244
256-
### 5. stopRealTimeFetch
245+
### 4. stopRealTimeFetch
257246
258247
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.
259248
@@ -264,15 +253,15 @@ sirenInstance.stopRealTimeFetch(NOTIFICATIONS);
264253
sirenInstance.stopRealTimeFetch(UNVIEWED_COUNT);
265254
```
266255
267-
### 6. markAsReadById
256+
### 5. markAsReadById
268257
269258
This method marks the notification as read. It accepts a notification id as an argument.
270259
271260
```bash
272261
await sirenInstance.markAsReadById("your-notification-id");
273262
```
274263
275-
### 7. markAsReadByDate
264+
### 6. markAsReadByDate
276265
277266
This method marks the notifications as read till the given date.<br />
278267
It accepts a param object as an argument with keys startDate (ISO date string) and category(string).
@@ -281,15 +270,15 @@ It accepts a param object as an argument with keys startDate (ISO date string) a
281270
await sirenInstance.markAsReadByDate({startDate: "2011-10-05T14:48:00.000Z"});
282271
```
283272
284-
### 8. deleteById
273+
### 7. deleteById
285274
286275
This method deletes a notification. It accepts a notification id as an argument.
287276
288277
```bash
289278
await sirenInstance.deleteById("your-notification-id");
290279
```
291280
292-
### 9. deleteByDate
281+
### 8. deleteByDate
293282
294283
This method deletes the notifications till the given date.<br />
295284
It accepts a param object as an argument with keys startDate (ISO date string), isRead(boolean) and category(string).
@@ -298,7 +287,7 @@ It accepts a param object as an argument with keys startDate (ISO date string),
298287
await sirenInstance.deleteByDate({startDate: "2011-10-05T14:48:00.000Z"});
299288
```
300289
301-
### 10. markAllAsViewed
290+
### 9. markAllAsViewed
302291
303292
This method marks the notifications as viewed till the given date. This sets the unviewed count as 0 <br />
304293
It accepts an ISO date string as an argument

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sirenapp/js-sdk",
3-
"version": "1.2.2",
3+
"version": "1.2.3-rc.0",
44
"description": "JavaScript middleware designed to streamline interaction for managing and displaying in-app notifications seamlessly",
55
"main": "dist/umd/siren-js-umd-sdk.js",
66
"module": "dist/esm/siren-js-esm-sdk.js",

src/Siren.ts

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import SirenError from './error';
22
import {
3-
verifyToken,
43
fetchUnviewedNotificationsCount,
54
fetchAllNotifications,
65
markAsReadById,
@@ -10,22 +9,18 @@ import {
109
} from './api';
1110
import {
1211
BulkUpdateType,
13-
VerificationStatus,
1412
ErrorMap,
1513
SirenErrorTypes,
1614
DATA_FETCH_INTERVAL,
17-
ErrorLevelType,
1815
EventType
1916
} from './constants/generic';
2017
import { getStartDate, sanitizeSession, emitSirenError } from './utils';
2118

2219
import type {
23-
ErrorCallbackType,
2420
FetchNotificationsParamsType,
2521
InitConfigType,
2622
ActionCallbackType,
2723
NotificationsApiResponse,
28-
VerifyTokenResponse,
2924
NotificationDataType,
3025
SirenErrorType,
3126
NotificationDataResponse,
@@ -39,19 +34,16 @@ import type {
3934
export class Siren {
4035
private token: string;
4136
private recipientId: string;
42-
private onError: ErrorCallbackType;
4337
private notificationFetchIntervalId: number | undefined;
4438
private unViewedCountFetchIntervalId: number | undefined;
4539
private latestNotification: NotificationDataType | null = null;
4640
private actionCallbacks: ActionCallbackType | undefined;
47-
private tokenValidationStatus: VerificationStatus = VerificationStatus.PENDING;
4841
/**
4942
* Binds specific class methods to ensure the correct `this` context when called.
5043
* This is necessary for methods that are used asynchronously or passed as callbacks.
5144
* @private
5245
*/
5346
private bindMethods() {
54-
this.verifyToken = this.verifyToken.bind(this);
5547
this.fetchUnviewedNotificationsCount = this.fetchUnviewedNotificationsCount.bind(this);
5648
this.fetchAllNotifications = this.fetchAllNotifications.bind(this);
5749
this.startRealTimeFetch = this.startRealTimeFetch.bind(this);
@@ -81,35 +73,11 @@ export class Siren {
8173

8274
this.token = session.data?.token || '';
8375
this.recipientId = session.data?.recipientId || '';
84-
this.onError = session.data?.onError;
8576
this.actionCallbacks = actionCallbacks;
8677

87-
if (session.data) this.verifyToken();
8878
this.bindMethods();
8979
}
9080

91-
/**
92-
* Verifies the validity of the user's recipient and token.
93-
*
94-
* @returns {Promise<VerifyTokenResponse | null>}
95-
* - `VerifyTokenResponse` object containing status as SUCCESS.
96-
* - `null` if the API fails to return a valid response.
97-
*/
98-
async verifyToken(): Promise<VerifyTokenResponse | null> {
99-
this.tokenValidationStatus = VerificationStatus.PENDING;
100-
const res = await verifyToken(this.token, this.recipientId, this.onError);
101-
102-
if (res)
103-
this.tokenValidationStatus =
104-
res && res.data?.status === VerificationStatus.SUCCESS
105-
? VerificationStatus.SUCCESS
106-
: VerificationStatus.FAILED; // api returns null in failed scenarios
107-
if(this.actionCallbacks?.onStatusChange)
108-
this.actionCallbacks.onStatusChange(this.tokenValidationStatus);
109-
110-
return res;
111-
}
112-
11381
/**
11482
* Retrieves the number of unviewed notifications count for the user.
11583
*
@@ -118,9 +86,6 @@ export class Siren {
11886
*
11987
*/
12088
async fetchUnviewedNotificationsCount(): Promise<UnviewedCountReturnResponse | null> {
121-
const hasPermission = this.authorizeUserAction();
122-
123-
if (!hasPermission) return this.getErrorForUnauthorizedAction();
12489

12590
const response = await fetchUnviewedNotificationsCount(this.token, this.recipientId);
12691

@@ -146,9 +111,6 @@ export class Siren {
146111
async fetchAllNotifications(
147112
params: FetchNotificationsParamsType
148113
): Promise<NotificationsApiResponse | null> {
149-
const hasPermission = this.authorizeUserAction();
150-
151-
if (!hasPermission) return this.getErrorForUnauthorizedAction();
152114
const response = await fetchAllNotifications(this.token, this.recipientId, params);
153115

154116
if (response && response?.data?.length && response?.data?.length > 0)
@@ -170,7 +132,6 @@ export class Siren {
170132
eventType: EventType;
171133
params?: FetchNotificationsParamsType;
172134
}): void {
173-
this.authorizeUserAction();
174135
switch (eventType) {
175136
case EventType.NOTIFICATION:
176137
this.startRealTimeNotificationFetch(params ?? {});
@@ -208,9 +169,7 @@ export class Siren {
208169
*/
209170

210171
async markAsReadById(id: string): Promise<NotificationDataResponse | null> {
211-
const hasPermission = this.authorizeUserAction();
212172

213-
if (!hasPermission) return this.getErrorForUnauthorizedAction();
214173
let response;
215174

216175
if (id) response = await markAsReadById(this.token, this.recipientId, id);
@@ -230,9 +189,6 @@ export class Siren {
230189

231190
async markAsReadByDate(params: BulkUpdateParamsType): Promise<ActionResponse | null> {
232191
const { startDate, category } = params || {};
233-
const hasPermission = this.authorizeUserAction();
234-
235-
if (!hasPermission) return this.getErrorForUnauthorizedAction();
236192
let response;
237193

238194
if (startDate) {
@@ -265,9 +221,6 @@ export class Siren {
265221
*/
266222

267223
async deleteById(id: string): Promise<ActionResponse | null> {
268-
const hasPermission = this.authorizeUserAction();
269-
270-
if (!hasPermission) return this.getErrorForUnauthorizedAction();
271224
let response;
272225

273226
if (id) response = await deleteNotificationById(this.token, this.recipientId, id);
@@ -286,9 +239,7 @@ export class Siren {
286239
*/
287240
async deleteByDate(params: BulkUpdateParamsType): Promise<ActionResponse | null> {
288241
const { startDate, isRead, category } = params || {};
289-
const hasPermission = this.authorizeUserAction();
290242

291-
if (!hasPermission) return this.getErrorForUnauthorizedAction();
292243
let response;
293244

294245
if (startDate) {
@@ -322,9 +273,6 @@ export class Siren {
322273
*
323274
*/
324275
async markAllAsViewed(startDate: string): Promise<MarkAsViewedResponse | null> {
325-
const hasPermission = this.authorizeUserAction();
326-
327-
if (!hasPermission) return this.getErrorForUnauthorizedAction();
328276
let response;
329277

330278
if (startDate)
@@ -349,7 +297,6 @@ export class Siren {
349297
params.start ?? this.latestNotification?.createdAt ?? new Date().toISOString();
350298

351299
this.notificationFetchIntervalId = window.setInterval(async () => {
352-
if (this.tokenValidationStatus !== VerificationStatus.SUCCESS) return null;
353300
const response = await fetchAllNotifications(this.token, this.recipientId, {
354301
...params,
355302
...(lastFetchedCreatedAt && {
@@ -380,7 +327,6 @@ export class Siren {
380327
*/
381328
private startRealTimeUnviewedCountFetch(): void {
382329
this.unViewedCountFetchIntervalId = window.setInterval(async () => {
383-
if (this.tokenValidationStatus !== VerificationStatus.SUCCESS) return;
384330
const response = await fetchUnviewedNotificationsCount(this.token, this.recipientId);
385331

386332
if (this.actionCallbacks?.onEventReceive)
@@ -404,44 +350,6 @@ export class Siren {
404350

405351
return { data: null, error };
406352
}
407-
408-
private authorizeUserAction(): boolean {
409-
if (this?.tokenValidationStatus === VerificationStatus.FAILED) {
410-
const errorObj = new SirenError(
411-
SirenErrorTypes.ERROR,
412-
ErrorMap.UNAUTHORIZED_OPERATION.message,
413-
ErrorMap.UNAUTHORIZED_OPERATION.code
414-
);
415-
416-
if (this.onError) this.onError(errorObj.getError());
417-
418-
return false;
419-
}
420-
if (this?.tokenValidationStatus === VerificationStatus.PENDING) return false;
421-
422-
return true;
423-
}
424-
425-
private getErrorForUnauthorizedAction() {
426-
if (this?.tokenValidationStatus === VerificationStatus.PENDING)
427-
return {
428-
data: null,
429-
error: {
430-
Type: ErrorLevelType.ERROR,
431-
Message: ErrorMap.AUTHENTICATION_PENDING.message,
432-
Code: ErrorMap.AUTHENTICATION_PENDING.code
433-
}
434-
};
435-
436-
return {
437-
data: null,
438-
error: {
439-
Type: ErrorLevelType.ERROR,
440-
Message: ErrorMap.UNAUTHORIZED_OPERATION.message,
441-
Code: ErrorMap.UNAUTHORIZED_OPERATION.code
442-
}
443-
};
444-
}
445353
}
446354

447355
if (window) window.Siren = Siren;

src/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import "promise-polyfill/src/polyfill";
22
import type {
3-
VerificationStatus,
43
EventType,
54
ApiOperationType,
65
BulkUpdateType
@@ -158,7 +157,6 @@ export type ActionCallbackType = {
158157
response: NotificationsApiResponse | UnviewedCountApiResponse,
159158
eventType: EventType
160159
) => void;
161-
onStatusChange?: (status: VerificationStatus) => void;
162160
};
163161

164162
/**

src/utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ export function sanitizeSession(
5656
code: ErrorMap.INVALID_CREDENTIALS.code
5757
};
5858
} else if (
59-
(actionCallbacks?.onEventReceive && typeof actionCallbacks.onEventReceive !== 'function') ||
60-
(actionCallbacks?.onStatusChange && typeof actionCallbacks.onStatusChange !== 'function')
59+
(actionCallbacks?.onEventReceive && typeof actionCallbacks.onEventReceive !== 'function')
6160
) {
6261
emitSirenError(
6362
SirenErrorTypes.CONFIG_ERROR,

0 commit comments

Comments
 (0)