@suprsend/web-sdk 4.0.0 → 4.0.2
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/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/es/index.js +89 -68
- package/dist/es/index.js.map +1 -1
- package/dist/types/utils.d.ts +1 -0
- package/dist/types/webpush.d.ts +2 -0
- package/package.json +1 -1
package/dist/es/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var f = (a, e, t) =>
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
var W = Object.defineProperty;
|
|
2
|
+
var H = (a, e, t) => e in a ? W(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
|
|
3
|
+
var f = (a, e, t) => H(a, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import j from "mitt";
|
|
5
|
+
import F from "jwt-decode";
|
|
6
6
|
import { createStore as z } from "zustand/vanilla";
|
|
7
7
|
import { io as B } from "socket.io-client";
|
|
8
8
|
var p = /* @__PURE__ */ ((a) => (a.OPT_IN = "opt_in", a.OPT_OUT = "opt_out", a))(p || {}), w = /* @__PURE__ */ ((a) => (a.ALL = "all", a.REQUIRED = "required", a))(w || {}), c = /* @__PURE__ */ ((a) => (a.VALIDATION_ERROR = "VALIDATION_ERROR", a.NETWORK_ERROR = "NETWORK_ERROR", a.UNKNOWN_ERROR = "UNKNOWN_ERROR", a.PERMISSION_DENIED = "PERMISSION_DENIED", a.UNSUPPORTED_ACTION = "UNSUPPORTED_ACTION", a.NOT_FOUND = "NOT_FOUND", a))(c || {}), n = /* @__PURE__ */ ((a) => (a.SUCCESS = "success", a.ERROR = "error", a))(n || {}), _ = /* @__PURE__ */ ((a) => (a.INITIAL = "INITIAL", a.LOADING = "LOADING", a.SUCCESS = "SUCCESS", a.ERROR = "ERROR", a.FETCHING_MORE = "FETCHING_MORE", a))(_ || {});
|
|
@@ -22,26 +22,26 @@ function P() {
|
|
|
22
22
|
function I(a) {
|
|
23
23
|
return Object.keys(a).length === 0;
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function Q(a) {
|
|
26
26
|
return (a == null ? void 0 : a.length) <= 0;
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function G(a) {
|
|
29
29
|
const e = "=".repeat((4 - a.length % 4) % 4), t = (a + e).replace(/-/g, "+").replace(/_/g, "/"), s = atob(t), r = new Uint8Array(s.length);
|
|
30
30
|
for (let i = 0; i < s.length; ++i)
|
|
31
31
|
r[i] = s.charCodeAt(i);
|
|
32
32
|
return r;
|
|
33
33
|
}
|
|
34
|
-
function
|
|
34
|
+
function J(a, e) {
|
|
35
35
|
let t;
|
|
36
36
|
return (...s) => (clearTimeout(t), new Promise((r) => {
|
|
37
37
|
t = setTimeout(() => r(a(...s)), e);
|
|
38
38
|
}));
|
|
39
39
|
}
|
|
40
|
-
function
|
|
40
|
+
function x(a, e) {
|
|
41
41
|
const t = {};
|
|
42
42
|
return (...s) => {
|
|
43
43
|
const [r] = s, i = s.slice(1);
|
|
44
|
-
return typeof t[r] == "function" ? t[r](...i) : (t[r] =
|
|
44
|
+
return typeof t[r] == "function" ? t[r](...i) : (t[r] = J(a, e), t[r](...i));
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
function o(a) {
|
|
@@ -54,10 +54,10 @@ function o(a) {
|
|
|
54
54
|
function A() {
|
|
55
55
|
return typeof window < "u";
|
|
56
56
|
}
|
|
57
|
-
function
|
|
57
|
+
function M(a, e) {
|
|
58
58
|
A() && (typeof e == "object" && (e = JSON.stringify(e)), localStorage.setItem(a, e));
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function L(a) {
|
|
61
61
|
if (!A()) return;
|
|
62
62
|
const e = localStorage.getItem(a);
|
|
63
63
|
if (e)
|
|
@@ -67,6 +67,13 @@ function j(a) {
|
|
|
67
67
|
return e;
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
+
function Z(a) {
|
|
71
|
+
A() && localStorage.removeItem(a);
|
|
72
|
+
}
|
|
73
|
+
async function X(a) {
|
|
74
|
+
const t = new TextEncoder().encode(a), s = await crypto.subtle.digest("SHA-256", t);
|
|
75
|
+
return Array.from(new Uint8Array(s)).map((d) => d.toString(16).padStart(2, "0")).join("");
|
|
76
|
+
}
|
|
70
77
|
class N {
|
|
71
78
|
constructor(e) {
|
|
72
79
|
f(this, "config");
|
|
@@ -120,7 +127,7 @@ class N {
|
|
|
120
127
|
errorMessage: "User isn't authenticated. Call identify method before performing any action"
|
|
121
128
|
});
|
|
122
129
|
if ((t = this.config.authenticateOptions) != null && t.refreshUserToken && this.config.userToken) {
|
|
123
|
-
const i =
|
|
130
|
+
const i = F(this.config.userToken), d = (i.exp || 0) * 1e3, u = Date.now();
|
|
124
131
|
if (d <= u)
|
|
125
132
|
try {
|
|
126
133
|
const h = await this.config.authenticateOptions.refreshUserToken(
|
|
@@ -154,7 +161,7 @@ class N {
|
|
|
154
161
|
}
|
|
155
162
|
}
|
|
156
163
|
}
|
|
157
|
-
class
|
|
164
|
+
class Y {
|
|
158
165
|
constructor(e) {
|
|
159
166
|
f(this, "config");
|
|
160
167
|
f(this, "preferenceData");
|
|
@@ -162,10 +169,10 @@ class J {
|
|
|
162
169
|
f(this, "debouncedUpdateCategoryPreferences");
|
|
163
170
|
f(this, "debouncedUpdateChannelPreferences");
|
|
164
171
|
f(this, "debounceTime", 1e3);
|
|
165
|
-
this.config = e, this.debouncedUpdateCategoryPreferences =
|
|
172
|
+
this.config = e, this.debouncedUpdateCategoryPreferences = x(
|
|
166
173
|
this._updateCategoryPreferences.bind(this),
|
|
167
174
|
this.debounceTime
|
|
168
|
-
), this.debouncedUpdateChannelPreferences =
|
|
175
|
+
), this.debouncedUpdateChannelPreferences = x(
|
|
169
176
|
this._updateChannelPreferences.bind(this),
|
|
170
177
|
this.debounceTime
|
|
171
178
|
);
|
|
@@ -269,7 +276,7 @@ class J {
|
|
|
269
276
|
* Used to update user's category level preference.
|
|
270
277
|
*/
|
|
271
278
|
async updateCategoryPreference(e, t, s) {
|
|
272
|
-
var h,
|
|
279
|
+
var h, S, v, T;
|
|
273
280
|
if (!e || ![p.OPT_IN, p.OPT_OUT].includes(
|
|
274
281
|
t
|
|
275
282
|
))
|
|
@@ -326,7 +333,7 @@ class J {
|
|
|
326
333
|
R.preference === p.OPT_OUT && d.push(R.channel);
|
|
327
334
|
});
|
|
328
335
|
let u = !0;
|
|
329
|
-
typeof (s == null ? void 0 : s.showOptOutChannels) == "boolean" ? u = s == null ? void 0 : s.showOptOutChannels : typeof ((
|
|
336
|
+
typeof (s == null ? void 0 : s.showOptOutChannels) == "boolean" ? u = s == null ? void 0 : s.showOptOutChannels : typeof ((S = this.preferenceArgs) == null ? void 0 : S.showOptOutChannels) == "boolean" && (u = this.preferenceArgs.showOptOutChannels);
|
|
330
337
|
const l = {
|
|
331
338
|
preference: r.preference,
|
|
332
339
|
opt_out_channels: u && t === p.OPT_IN ? null : d
|
|
@@ -337,9 +344,9 @@ class J {
|
|
|
337
344
|
l,
|
|
338
345
|
r,
|
|
339
346
|
{
|
|
340
|
-
tenant_id: (s == null ? void 0 : s.tenantId) || ((
|
|
347
|
+
tenant_id: (s == null ? void 0 : s.tenantId) || ((v = this.preferenceArgs) == null ? void 0 : v.tenantId),
|
|
341
348
|
show_opt_out_channels: u,
|
|
342
|
-
tags: (s == null ? void 0 : s.tags) || ((
|
|
349
|
+
tags: (s == null ? void 0 : s.tags) || ((T = this.preferenceArgs) == null ? void 0 : T.tags)
|
|
343
350
|
}
|
|
344
351
|
), o({
|
|
345
352
|
status: n.SUCCESS,
|
|
@@ -350,7 +357,7 @@ class J {
|
|
|
350
357
|
* Used to update user's category level channel preference.
|
|
351
358
|
*/
|
|
352
359
|
async updateChannelPreferenceInCategory(e, t, s, r) {
|
|
353
|
-
var
|
|
360
|
+
var T, R, g, O;
|
|
354
361
|
if (!e || !s)
|
|
355
362
|
return o({
|
|
356
363
|
status: n.ERROR,
|
|
@@ -379,7 +386,7 @@ class J {
|
|
|
379
386
|
});
|
|
380
387
|
let i = null, d = null, u = !1;
|
|
381
388
|
for (const y of this.data.sections) {
|
|
382
|
-
let
|
|
389
|
+
let b = !1;
|
|
383
390
|
if (y.subcategories) {
|
|
384
391
|
for (const m of y.subcategories) {
|
|
385
392
|
if (m.category === s) {
|
|
@@ -388,7 +395,7 @@ class J {
|
|
|
388
395
|
if (E.channel === e)
|
|
389
396
|
if (d = E, E.is_editable) {
|
|
390
397
|
if (E.preference !== t) {
|
|
391
|
-
E.preference = t, t === p.OPT_IN && (m.preference = p.OPT_IN), u = !0,
|
|
398
|
+
E.preference = t, t === p.OPT_IN && (m.preference = p.OPT_IN), u = !0, b = !0;
|
|
392
399
|
break;
|
|
393
400
|
}
|
|
394
401
|
} else
|
|
@@ -398,9 +405,9 @@ class J {
|
|
|
398
405
|
errorMessage: "Channel preference is not editable"
|
|
399
406
|
});
|
|
400
407
|
}
|
|
401
|
-
if (
|
|
408
|
+
if (b) break;
|
|
402
409
|
}
|
|
403
|
-
if (
|
|
410
|
+
if (b) break;
|
|
404
411
|
}
|
|
405
412
|
}
|
|
406
413
|
if (!i)
|
|
@@ -421,19 +428,19 @@ class J {
|
|
|
421
428
|
body: this.data
|
|
422
429
|
});
|
|
423
430
|
const l = [];
|
|
424
|
-
(
|
|
431
|
+
(T = i == null ? void 0 : i.channels) == null || T.forEach((y) => {
|
|
425
432
|
y.preference === p.OPT_OUT && l.push(y.channel);
|
|
426
433
|
});
|
|
427
434
|
let h = !0;
|
|
428
435
|
typeof (r == null ? void 0 : r.showOptOutChannels) == "boolean" ? h = r == null ? void 0 : r.showOptOutChannels : typeof ((R = this.preferenceArgs) == null ? void 0 : R.showOptOutChannels) == "boolean" && (h = this.preferenceArgs.showOptOutChannels);
|
|
429
|
-
const
|
|
436
|
+
const v = {
|
|
430
437
|
preference: h && i.preference === p.OPT_OUT && t === p.OPT_IN ? p.OPT_IN : i.preference,
|
|
431
438
|
opt_out_channels: l
|
|
432
439
|
};
|
|
433
440
|
return this.debouncedUpdateCategoryPreferences(
|
|
434
441
|
s,
|
|
435
442
|
s,
|
|
436
|
-
|
|
443
|
+
v,
|
|
437
444
|
i,
|
|
438
445
|
{
|
|
439
446
|
tenant_id: (r == null ? void 0 : r.tenantId) || ((g = this.preferenceArgs) == null ? void 0 : g.tenantId),
|
|
@@ -492,12 +499,12 @@ class J {
|
|
|
492
499
|
});
|
|
493
500
|
}
|
|
494
501
|
}
|
|
495
|
-
const
|
|
496
|
-
class
|
|
502
|
+
const V = "ss_device_id";
|
|
503
|
+
class q {
|
|
497
504
|
constructor(e) {
|
|
498
505
|
f(this, "config");
|
|
499
506
|
f(this, "preferences");
|
|
500
|
-
this.config = e, this.preferences = new
|
|
507
|
+
this.config = e, this.preferences = new Y(e);
|
|
501
508
|
}
|
|
502
509
|
isReservedKey(e) {
|
|
503
510
|
var t;
|
|
@@ -651,7 +658,7 @@ class Z {
|
|
|
651
658
|
errorMessage: "data provided is empty"
|
|
652
659
|
});
|
|
653
660
|
const s = this.validateArrayData(t);
|
|
654
|
-
return
|
|
661
|
+
return Q(s) ? o({
|
|
655
662
|
status: n.ERROR,
|
|
656
663
|
errorType: c.VALIDATION_ERROR,
|
|
657
664
|
errorMessage: "data provided is empty"
|
|
@@ -771,8 +778,8 @@ class Z {
|
|
|
771
778
|
});
|
|
772
779
|
}
|
|
773
780
|
getDeviceId() {
|
|
774
|
-
let e =
|
|
775
|
-
return e || (e = C(),
|
|
781
|
+
let e = L(V);
|
|
782
|
+
return e || (e = C(), M(V, e)), e;
|
|
776
783
|
}
|
|
777
784
|
async addWebPush(e) {
|
|
778
785
|
if (typeof e != "object")
|
|
@@ -852,7 +859,8 @@ class Z {
|
|
|
852
859
|
}) : this.setInternal({ $timezone: e });
|
|
853
860
|
}
|
|
854
861
|
}
|
|
855
|
-
|
|
862
|
+
const k = "ss_wp_hash";
|
|
863
|
+
class ee {
|
|
856
864
|
constructor(e) {
|
|
857
865
|
f(this, "config");
|
|
858
866
|
this.config = e;
|
|
@@ -865,6 +873,20 @@ class X {
|
|
|
865
873
|
if (t)
|
|
866
874
|
return t;
|
|
867
875
|
}
|
|
876
|
+
async checkAndUpdateOnServer(e) {
|
|
877
|
+
const t = e.endpoint;
|
|
878
|
+
let s = null;
|
|
879
|
+
try {
|
|
880
|
+
s = await X(t);
|
|
881
|
+
} catch {
|
|
882
|
+
}
|
|
883
|
+
if (s) {
|
|
884
|
+
if (s === L(k))
|
|
885
|
+
return o({ status: n.SUCCESS });
|
|
886
|
+
M(k, s);
|
|
887
|
+
}
|
|
888
|
+
return await this.config.user.addWebPush(e);
|
|
889
|
+
}
|
|
868
890
|
async handleRegisterPush() {
|
|
869
891
|
try {
|
|
870
892
|
if (await navigator.serviceWorker.register(`/${this.config.swFileName}`), await Notification.requestPermission() !== "granted")
|
|
@@ -875,7 +897,7 @@ class X {
|
|
|
875
897
|
});
|
|
876
898
|
const t = await navigator.serviceWorker.ready, s = await t.pushManager.getSubscription();
|
|
877
899
|
if (s)
|
|
878
|
-
return this.
|
|
900
|
+
return this.checkAndUpdateOnServer(s);
|
|
879
901
|
if (!this.config.vapidKey)
|
|
880
902
|
return console.warn(
|
|
881
903
|
"[SuprSend]: Vapid key is missing. Add it while creating SuprSend instance"
|
|
@@ -886,9 +908,9 @@ class X {
|
|
|
886
908
|
});
|
|
887
909
|
const r = await t.pushManager.subscribe({
|
|
888
910
|
userVisibleOnly: !0,
|
|
889
|
-
applicationServerKey:
|
|
911
|
+
applicationServerKey: G(this.config.vapidKey)
|
|
890
912
|
});
|
|
891
|
-
return this.
|
|
913
|
+
return this.checkAndUpdateOnServer(r);
|
|
892
914
|
} catch (e) {
|
|
893
915
|
return console.warn("SuprSend: Error getting push subscription", e), o({
|
|
894
916
|
status: n.ERROR,
|
|
@@ -913,7 +935,7 @@ class X {
|
|
|
913
935
|
async updatePushSubscription() {
|
|
914
936
|
const e = await this.getPushSubscription();
|
|
915
937
|
if (e)
|
|
916
|
-
return this.
|
|
938
|
+
return this.checkAndUpdateOnServer(e);
|
|
917
939
|
}
|
|
918
940
|
async removePushSubscription() {
|
|
919
941
|
const e = await this.getPushSubscription();
|
|
@@ -933,12 +955,12 @@ class X {
|
|
|
933
955
|
return !!await this.getPushSubscription();
|
|
934
956
|
}
|
|
935
957
|
}
|
|
936
|
-
const
|
|
958
|
+
const K = 20, te = "default", se = 100, D = {
|
|
937
959
|
storeId: "$suprsend_default_store",
|
|
938
960
|
label: ""
|
|
939
|
-
},
|
|
940
|
-
tenantId:
|
|
941
|
-
pageSize:
|
|
961
|
+
}, re = {
|
|
962
|
+
tenantId: te,
|
|
963
|
+
pageSize: K,
|
|
942
964
|
stores: null,
|
|
943
965
|
host: {
|
|
944
966
|
apiHost: "https://inboxs.live",
|
|
@@ -949,21 +971,21 @@ const F = 20, Y = "default", q = 100, D = {
|
|
|
949
971
|
store: D,
|
|
950
972
|
pageInfo: {
|
|
951
973
|
total: 0,
|
|
952
|
-
pageSize:
|
|
974
|
+
pageSize: K,
|
|
953
975
|
hasMore: !1
|
|
954
976
|
},
|
|
955
977
|
meta: { badge: 0 },
|
|
956
978
|
apiStatus: _.INITIAL,
|
|
957
979
|
isFirstFetch: !0
|
|
958
980
|
};
|
|
959
|
-
class
|
|
981
|
+
class ie {
|
|
960
982
|
constructor(e) {
|
|
961
983
|
f(this, "config");
|
|
962
984
|
f(this, "feedInstances", []);
|
|
963
985
|
this.config = e;
|
|
964
986
|
}
|
|
965
987
|
initialize(e = {}) {
|
|
966
|
-
const t = new
|
|
988
|
+
const t = new ne(this.config, e);
|
|
967
989
|
return this.feedInstances.push(t), t;
|
|
968
990
|
}
|
|
969
991
|
removeInstance(e) {
|
|
@@ -977,18 +999,18 @@ class te {
|
|
|
977
999
|
this.feedInstances = [];
|
|
978
1000
|
}
|
|
979
1001
|
}
|
|
980
|
-
class
|
|
1002
|
+
class ne {
|
|
981
1003
|
constructor(e, t) {
|
|
982
1004
|
f(this, "feedOptions");
|
|
983
1005
|
f(this, "config");
|
|
984
1006
|
f(this, "store");
|
|
985
1007
|
f(this, "socket");
|
|
986
1008
|
f(this, "expiryTimerId");
|
|
987
|
-
f(this, "emitter",
|
|
1009
|
+
f(this, "emitter", j());
|
|
988
1010
|
this.config = e, this.setOptions(t), this.store = this.createFeedStore();
|
|
989
1011
|
}
|
|
990
1012
|
setOptions(e) {
|
|
991
|
-
this.feedOptions = { ...
|
|
1013
|
+
this.feedOptions = { ...re }, e != null && e.tenantId && (this.feedOptions.tenantId = e.tenantId), e != null && e.host && (this.feedOptions.host = e.host), typeof (e == null ? void 0 : e.pageSize) == "number" && e.pageSize > 0 && (this.feedOptions.pageSize = Math.min(e.pageSize, se)), e != null && e.stores && (this.feedOptions.stores = e.stores), this.validateStore();
|
|
992
1014
|
}
|
|
993
1015
|
validateStore() {
|
|
994
1016
|
const e = this.feedOptions.stores;
|
|
@@ -1112,12 +1134,12 @@ class se {
|
|
|
1112
1134
|
}), this.emitter.emit("feed.store_update", this.data);
|
|
1113
1135
|
}
|
|
1114
1136
|
notificationBelongToStore(e, t) {
|
|
1115
|
-
var O, y,
|
|
1116
|
-
const s = !!e.read_on, r = e.archived, i = e.tags, d = e.n_category, u = (O = t == null ? void 0 : t.query) == null ? void 0 : O.read, l = (y = t == null ? void 0 : t.query) == null ? void 0 : y.archived, h = (
|
|
1137
|
+
var O, y, b, m;
|
|
1138
|
+
const s = !!e.read_on, r = e.archived, i = e.tags, d = e.n_category, u = (O = t == null ? void 0 : t.query) == null ? void 0 : O.read, l = (y = t == null ? void 0 : t.query) == null ? void 0 : y.archived, h = (b = t == null ? void 0 : t.query) == null ? void 0 : b.tags, S = (m = t == null ? void 0 : t.query) == null ? void 0 : m.categories, v = u == null || s === u, T = !!r == !!l;
|
|
1117
1139
|
let R = !1, g = !1;
|
|
1118
1140
|
return Array.isArray(h) && h.length > 0 ? h.forEach((E) => {
|
|
1119
1141
|
i != null && i.includes(E) && (R = !0);
|
|
1120
|
-
}) : R = !0, Array.isArray(
|
|
1142
|
+
}) : R = !0, Array.isArray(S) && S.length > 0 ? S.includes(d) && (g = !0) : g = !0, v && R && g && T;
|
|
1121
1143
|
}
|
|
1122
1144
|
orderNotificationsBasedOnPinFlag(e, t) {
|
|
1123
1145
|
if (e.is_pinned)
|
|
@@ -1218,8 +1240,7 @@ class se {
|
|
|
1218
1240
|
tenant_id: this.feedOptions.tenantId,
|
|
1219
1241
|
schema: "1"
|
|
1220
1242
|
},
|
|
1221
|
-
|
|
1222
|
-
reconnectionDelay: 5e3,
|
|
1243
|
+
reconnectionDelay: 1e3,
|
|
1223
1244
|
reconnectionDelayMax: 1e4
|
|
1224
1245
|
}), this.initializeSocketEvents());
|
|
1225
1246
|
}
|
|
@@ -1392,8 +1413,8 @@ class se {
|
|
|
1392
1413
|
this.reset(), this.emitter.off("*"), (e = this.socket) == null || e.disconnect(), this.config.feeds.removeInstance(this);
|
|
1393
1414
|
}
|
|
1394
1415
|
}
|
|
1395
|
-
const
|
|
1396
|
-
class
|
|
1416
|
+
const ae = "https://hub.suprsend.com", oe = "serviceworker.js", $ = "ss_distinct_id";
|
|
1417
|
+
class le {
|
|
1397
1418
|
constructor(e, t) {
|
|
1398
1419
|
f(this, "host");
|
|
1399
1420
|
f(this, "publicApiKey");
|
|
@@ -1404,17 +1425,17 @@ class ue {
|
|
|
1404
1425
|
f(this, "apiClient", null);
|
|
1405
1426
|
f(this, "userTokenExpirationTimer", null);
|
|
1406
1427
|
f(this, "authenticateOptions");
|
|
1407
|
-
f(this, "user", new
|
|
1408
|
-
f(this, "webpush", new
|
|
1409
|
-
f(this, "feeds", new
|
|
1410
|
-
f(this, "emitter",
|
|
1428
|
+
f(this, "user", new q(this));
|
|
1429
|
+
f(this, "webpush", new ee(this));
|
|
1430
|
+
f(this, "feeds", new ie(this));
|
|
1431
|
+
f(this, "emitter", j());
|
|
1411
1432
|
if (!e)
|
|
1412
1433
|
throw new Error("[SuprSend]: publicApiKey is missing");
|
|
1413
|
-
this.publicApiKey = e, this.host = (t == null ? void 0 : t.host) ||
|
|
1434
|
+
this.publicApiKey = e, this.host = (t == null ? void 0 : t.host) || ae, this.vapidKey = (t == null ? void 0 : t.vapidKey) || "", this.swFileName = (t == null ? void 0 : t.swFileName) || oe;
|
|
1414
1435
|
}
|
|
1415
1436
|
handleRefreshUserToken(e) {
|
|
1416
1437
|
if (!this.userToken || !A()) return;
|
|
1417
|
-
const t =
|
|
1438
|
+
const t = F(this.userToken), s = (t.exp || 0) * 1e3, r = Date.now(), i = 1e3 * 30;
|
|
1418
1439
|
if (s && s > r) {
|
|
1419
1440
|
const d = s - r - i;
|
|
1420
1441
|
this.userTokenExpirationTimer && clearTimeout(this.userTokenExpirationTimer), this.userTokenExpirationTimer = setTimeout(async () => {
|
|
@@ -1472,8 +1493,8 @@ class ue {
|
|
|
1472
1493
|
if (this.distinctId && this.apiClient)
|
|
1473
1494
|
return o({ status: n.SUCCESS });
|
|
1474
1495
|
this.distinctId = e, this.userToken = t, this.apiClient = new N(this), this.authenticateOptions = s;
|
|
1475
|
-
const r =
|
|
1476
|
-
|
|
1496
|
+
const r = L(
|
|
1497
|
+
$
|
|
1477
1498
|
);
|
|
1478
1499
|
if (s != null && s.refreshUserToken && this.handleRefreshUserToken(s.refreshUserToken), r == this.distinctId)
|
|
1479
1500
|
return this.webpush.updatePushSubscription(), o({ status: n.SUCCESS });
|
|
@@ -1485,7 +1506,7 @@ class ue {
|
|
|
1485
1506
|
$identified_id: e
|
|
1486
1507
|
}
|
|
1487
1508
|
});
|
|
1488
|
-
return i.status === n.SUCCESS ? (this.webpush.updatePushSubscription(),
|
|
1509
|
+
return i.status === n.SUCCESS ? (this.webpush.updatePushSubscription(), M($, this.distinctId)) : this.reset({ unsubscribePush: !1 }), i;
|
|
1489
1510
|
}
|
|
1490
1511
|
/**
|
|
1491
1512
|
* Check's if SuprSend instance is authenticated. To check if userToken is also present pass true.
|
|
@@ -1515,16 +1536,16 @@ class ue {
|
|
|
1515
1536
|
*/
|
|
1516
1537
|
async reset(e) {
|
|
1517
1538
|
var s, r;
|
|
1518
|
-
return (e == null ? void 0 : e.unsubscribePush) !== !1 && await ((s = this.webpush) == null ? void 0 : s.removePushSubscription()), this.apiClient = null, this.distinctId = null, this.userToken = "", this.userTokenExpirationTimer && clearTimeout(this.userTokenExpirationTimer), ((r = this.feeds.feedInstances) == null ? void 0 : r.length) > 0 && this.feeds.removeAll(), o({ status: n.SUCCESS });
|
|
1539
|
+
return (e == null ? void 0 : e.unsubscribePush) !== !1 && (await ((s = this.webpush) == null ? void 0 : s.removePushSubscription()), Z(k)), this.apiClient = null, this.distinctId = null, this.userToken = "", this.userTokenExpirationTimer && clearTimeout(this.userTokenExpirationTimer), ((r = this.feeds.feedInstances) == null ? void 0 : r.length) > 0 && this.feeds.removeAll(), o({ status: n.SUCCESS });
|
|
1519
1540
|
}
|
|
1520
1541
|
}
|
|
1521
1542
|
export {
|
|
1522
1543
|
_ as ApiResponseStatus,
|
|
1523
1544
|
w as ChannelLevelPreferenceOptions,
|
|
1524
1545
|
c as ERROR_TYPE,
|
|
1525
|
-
|
|
1546
|
+
ne as Feed,
|
|
1526
1547
|
p as PreferenceOptions,
|
|
1527
1548
|
n as RESPONSE_STATUS,
|
|
1528
|
-
|
|
1549
|
+
le as SuprSend
|
|
1529
1550
|
};
|
|
1530
1551
|
//# sourceMappingURL=index.js.map
|