@suprsend/web-sdk 1.2.3 → 1.2.5
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/dist/cdn_bundle.js +1 -1
- package/dist/cjs_bundle.js +1 -1
- package/package.json +1 -1
- package/src/index.d.ts +5 -5
- package/src/index.js +1 -1
- package/src/preferences.js +5 -5
- package/src/web_push.js +13 -1
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -72,17 +72,17 @@ interface GetOverAllChannelPreferencesResponse extends PreferenceErrorData {
|
|
|
72
72
|
interface Preferences {
|
|
73
73
|
data: PreferenceData;
|
|
74
74
|
|
|
75
|
-
get_preferences(args?: {
|
|
75
|
+
get_preferences(args?: { tenant_id?: string }): Promise<PreferencesResponse>;
|
|
76
76
|
|
|
77
77
|
get_categories(args?: {
|
|
78
|
-
|
|
78
|
+
tenant_id?: string;
|
|
79
79
|
limit?: number;
|
|
80
80
|
offset?: number;
|
|
81
81
|
}): Promise<GetCategoriesResponse>;
|
|
82
82
|
|
|
83
83
|
get_category(
|
|
84
84
|
category: string,
|
|
85
|
-
args?: {
|
|
85
|
+
args?: { tenant_id?: string }
|
|
86
86
|
): Promise<Category>;
|
|
87
87
|
|
|
88
88
|
get_overall_channel_preferences(): Promise<GetOverAllChannelPreferencesResponse>;
|
|
@@ -91,7 +91,7 @@ interface Preferences {
|
|
|
91
91
|
category: string,
|
|
92
92
|
preference: PreferenceOptions,
|
|
93
93
|
args?: {
|
|
94
|
-
|
|
94
|
+
tenant_id?: string;
|
|
95
95
|
}
|
|
96
96
|
): PreferencesResponse;
|
|
97
97
|
|
|
@@ -100,7 +100,7 @@ interface Preferences {
|
|
|
100
100
|
preference: PreferenceOptions,
|
|
101
101
|
category: string,
|
|
102
102
|
args?: {
|
|
103
|
-
|
|
103
|
+
tenant_id?: string;
|
|
104
104
|
}
|
|
105
105
|
): PreferencesResponse;
|
|
106
106
|
|
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.
|
|
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/preferences.js
CHANGED
|
@@ -181,7 +181,7 @@ class Preferences {
|
|
|
181
181
|
|
|
182
182
|
async get_preferences(args = {}) {
|
|
183
183
|
let url_path = "full_preference";
|
|
184
|
-
let query_params = {
|
|
184
|
+
let query_params = { tenant_id: args?.tenant_id };
|
|
185
185
|
|
|
186
186
|
const response = await this._get_request(url_path, query_params);
|
|
187
187
|
if (!response?.error) {
|
|
@@ -193,7 +193,7 @@ class Preferences {
|
|
|
193
193
|
async get_categories(args = {}) {
|
|
194
194
|
let url_path = "category";
|
|
195
195
|
const query_params = {
|
|
196
|
-
|
|
196
|
+
tenant_id: args?.tenant_id,
|
|
197
197
|
limit: args?.limit,
|
|
198
198
|
offset: args?.offset,
|
|
199
199
|
};
|
|
@@ -211,7 +211,7 @@ class Preferences {
|
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
let url_path = `category/${category}`;
|
|
214
|
-
let query_params = {
|
|
214
|
+
let query_params = { tenant_id: args?.tenant_id };
|
|
215
215
|
|
|
216
216
|
const response = await this._get_request(url_path, query_params);
|
|
217
217
|
return response;
|
|
@@ -302,7 +302,7 @@ class Preferences {
|
|
|
302
302
|
category,
|
|
303
303
|
request_payload,
|
|
304
304
|
category_data,
|
|
305
|
-
{
|
|
305
|
+
{ tenant_id: args?.tenant_id }
|
|
306
306
|
);
|
|
307
307
|
|
|
308
308
|
return this.data;
|
|
@@ -413,7 +413,7 @@ class Preferences {
|
|
|
413
413
|
category,
|
|
414
414
|
request_payload,
|
|
415
415
|
category_data,
|
|
416
|
-
{
|
|
416
|
+
{ tenant_id: args?.tenant_id }
|
|
417
417
|
);
|
|
418
418
|
|
|
419
419
|
return this.data;
|
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,7 +114,7 @@ class WebPush {
|
|
|
102
114
|
};
|
|
103
115
|
|
|
104
116
|
is_subscribed = async () => {
|
|
105
|
-
const subscription = await this.
|
|
117
|
+
const subscription = await this._get_subscription_without_wait();
|
|
106
118
|
return !!subscription;
|
|
107
119
|
};
|
|
108
120
|
|