@suprsend/web-sdk 1.2.2 → 1.2.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suprsend/web-sdk",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "This is sdk used to integrate suprsend functionality in javascript applications",
5
5
  "main": "dist/cjs_bundle.js",
6
6
  "scripts": {
package/src/index.d.ts CHANGED
@@ -146,6 +146,7 @@ interface User {
146
146
 
147
147
  export interface WebPush {
148
148
  register_push(): void;
149
+ notification_permission(): NotificationPermission;
149
150
  }
150
151
 
151
152
  export interface SuprSend {
package/src/index.js CHANGED
@@ -160,7 +160,7 @@ class SuprSend {
160
160
  async reset(options = { unsubscribe_push: true }) {
161
161
  // unsubscribe push
162
162
  if (options?.unsubscribe_push) {
163
- const subscription = await this.web_push._get_subscription();
163
+ const subscription = await this.web_push._get_subscription_without_wait();
164
164
  if (subscription) {
165
165
  this.user.remove_webpush(subscription);
166
166
  }
package/src/web_push.js CHANGED
@@ -28,6 +28,18 @@ class WebPush {
28
28
  });
29
29
  };
30
30
 
31
+ _get_subscription_without_wait = async () => {
32
+ const registration = await navigator.serviceWorker.getRegistration();
33
+ if (!registration) return;
34
+
35
+ return registration.pushManager
36
+ .getSubscription()
37
+ .then(async (subscription) => {
38
+ if (!subscription) return;
39
+ return subscription;
40
+ });
41
+ };
42
+
31
43
  _get_subscription = () => {
32
44
  return navigator.serviceWorker.ready
33
45
  .then((registration) => {
@@ -102,10 +114,14 @@ class WebPush {
102
114
  };
103
115
 
104
116
  is_subscribed = async () => {
105
- const subscription = await this._get_subscription();
117
+ const subscription = await this._get_subscription_without_wait();
106
118
  return !!subscription;
107
119
  };
108
120
 
121
+ notification_permission() {
122
+ return Notification.permission;
123
+ }
124
+
109
125
  // unsubscribe_push = () => {
110
126
  // navigator.serviceWorker.ready
111
127
  // .then((registration) => {