Skip to content

Commit 3841e10

Browse files
feat: Add token verification status change callback and trigger call back based on api status (#19)
1 parent 49e158d commit 3841e10

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ const sirenInstance = new Siren({
2828
# error callback function
2929
});
3030
actionCallbacks:{
31-
onNotificationReceived?: (response: NotificationsApiResponse) => {
31+
onNotificationReceived?: (response: NotificationsApiResponse) => {
3232
# callback function on getting notifications
33-
};
33+
};
3434
onUnViewedCountReceived?: (response: UnviewedCountApiResponse) => {
3535
# callback function on getting unviewed count
36-
};
36+
};
37+
onStatusChange?: (status: 'SUCCESS' | 'FAILED' | 'PENDING') =>{
38+
# callback function triggered when token verification status changes
39+
}
3740
}
3841
```
3942
All the exposed methods can be accessed using sirenInstance object.

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": "test_notification",
3-
"version": "1.0.21",
3+
"version": "1.0.25",
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ export class Siren {
120120
res && res.data?.status === VerificationStatus.SUCCESS
121121
? VerificationStatus.SUCCESS
122122
: VerificationStatus.FAILED; // api returns null in failed scenarios
123-
123+
if(this.actionCallbacks?.onStatusChange)
124+
this.actionCallbacks.onStatusChange(this.tokenValidationStatus);
125+
124126
return res;
125127
}
126128

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import "promise-polyfill/src/polyfill";
2+
import type { VerificationStatus } from "./constants/generic";
23

34
/**
45
* An interface representing the response structure of the Notifications API.
@@ -143,6 +144,7 @@ export type InitConfigType = {
143144
export type ActionCallbackType = {
144145
onNotificationReceived?: (response: NotificationsApiResponse) => void;
145146
onUnViewedCountReceived?: (response: UnviewedCountApiResponse) => void;
147+
onStatusChange?: (status: VerificationStatus) => void
146148
};
147149

148150
/**

0 commit comments

Comments
 (0)