@suprsend/web-sdk 3.0.3 → 3.1.0
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/README.md +3 -3
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/es/index.js +101 -86
- package/dist/es/index.js.map +1 -1
- package/dist/types/preferences.d.ts +4 -0
- package/package.json +1 -1
package/dist/es/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
var K = Object.defineProperty;
|
|
2
2
|
var W = (a, e, t) => e in a ? K(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
|
|
3
3
|
var f = (a, e, t) => W(a, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
-
import
|
|
5
|
-
import
|
|
4
|
+
import V from "mitt";
|
|
5
|
+
import x from "jwt-decode";
|
|
6
6
|
import { createStore as z } from "zustand/vanilla";
|
|
7
7
|
import { io as B } from "socket.io-client";
|
|
8
|
-
var p = /* @__PURE__ */ ((a) => (a.OPT_IN = "opt_in", a.OPT_OUT = "opt_out", a))(p || {}),
|
|
9
|
-
function
|
|
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 || {}), d = /* @__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))(d || {}), 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))(_ || {});
|
|
9
|
+
function C() {
|
|
10
10
|
let a = (/* @__PURE__ */ new Date()).getTime();
|
|
11
11
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
|
|
12
12
|
/[xy]/g,
|
|
@@ -16,7 +16,7 @@ function A() {
|
|
|
16
16
|
}
|
|
17
17
|
);
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function U() {
|
|
20
20
|
return Math.round(Date.now());
|
|
21
21
|
}
|
|
22
22
|
function I(a) {
|
|
@@ -37,7 +37,7 @@ function G(a, e) {
|
|
|
37
37
|
t = setTimeout(() => r(a(...s)), e);
|
|
38
38
|
}));
|
|
39
39
|
}
|
|
40
|
-
function
|
|
40
|
+
function k(a, e) {
|
|
41
41
|
const t = {};
|
|
42
42
|
return (...s) => {
|
|
43
43
|
const [r] = s, i = s.slice(1);
|
|
@@ -51,14 +51,14 @@ function o(a) {
|
|
|
51
51
|
message: a.errorMessage
|
|
52
52
|
}), e;
|
|
53
53
|
}
|
|
54
|
-
function
|
|
54
|
+
function A() {
|
|
55
55
|
return typeof window < "u";
|
|
56
56
|
}
|
|
57
|
-
function
|
|
58
|
-
|
|
57
|
+
function $(a, e) {
|
|
58
|
+
A() && (typeof e == "object" && (e = JSON.stringify(e)), localStorage.setItem(a, e));
|
|
59
59
|
}
|
|
60
|
-
function
|
|
61
|
-
if (!
|
|
60
|
+
function j(a) {
|
|
61
|
+
if (!A()) return;
|
|
62
62
|
const e = localStorage.getItem(a);
|
|
63
63
|
if (e)
|
|
64
64
|
try {
|
|
@@ -67,7 +67,7 @@ function $(a) {
|
|
|
67
67
|
return e;
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
class
|
|
70
|
+
class N {
|
|
71
71
|
constructor(e) {
|
|
72
72
|
f(this, "config");
|
|
73
73
|
this.config = e;
|
|
@@ -120,7 +120,7 @@ class D {
|
|
|
120
120
|
errorMessage: "User isn't authenticated. Call identify method before performing any action"
|
|
121
121
|
});
|
|
122
122
|
if ((t = this.config.authenticateOptions) != null && t.refreshUserToken && this.config.userToken) {
|
|
123
|
-
const i =
|
|
123
|
+
const i = x(this.config.userToken), c = (i.exp || 0) * 1e3, u = Date.now();
|
|
124
124
|
if (c <= u)
|
|
125
125
|
try {
|
|
126
126
|
const h = await this.config.authenticateOptions.refreshUserToken(
|
|
@@ -162,10 +162,10 @@ class J {
|
|
|
162
162
|
f(this, "debouncedUpdateCategoryPreferences");
|
|
163
163
|
f(this, "debouncedUpdateChannelPreferences");
|
|
164
164
|
f(this, "debounceTime", 1e3);
|
|
165
|
-
this.config = e, this.debouncedUpdateCategoryPreferences =
|
|
165
|
+
this.config = e, this.debouncedUpdateCategoryPreferences = k(
|
|
166
166
|
this._updateCategoryPreferences.bind(this),
|
|
167
167
|
this.debounceTime
|
|
168
|
-
), this.debouncedUpdateChannelPreferences =
|
|
168
|
+
), this.debouncedUpdateChannelPreferences = k(
|
|
169
169
|
this._updateChannelPreferences.bind(this),
|
|
170
170
|
this.debounceTime
|
|
171
171
|
);
|
|
@@ -173,7 +173,7 @@ class J {
|
|
|
173
173
|
validateQueryParams(e = {}) {
|
|
174
174
|
const t = {};
|
|
175
175
|
for (const s in e)
|
|
176
|
-
e[s] && (t[s] = String(e[s]));
|
|
176
|
+
e[s] && (typeof e[s] == "object" ? t[s] = JSON.stringify(e[s]) : t[s] = String(e[s]));
|
|
177
177
|
return t;
|
|
178
178
|
}
|
|
179
179
|
set data(e) {
|
|
@@ -194,11 +194,13 @@ class J {
|
|
|
194
194
|
async getPreferences(e) {
|
|
195
195
|
const t = {
|
|
196
196
|
tenant_id: e == null ? void 0 : e.tenantId,
|
|
197
|
-
show_opt_out_channels: (e == null ? void 0 : e.showOptOutChannels) !== !1
|
|
197
|
+
show_opt_out_channels: (e == null ? void 0 : e.showOptOutChannels) !== !1,
|
|
198
|
+
tags: e == null ? void 0 : e.tags
|
|
198
199
|
};
|
|
199
200
|
this.preferenceArgs = {
|
|
200
201
|
tenantId: t == null ? void 0 : t.tenant_id,
|
|
201
|
-
showOptOutChannels: t == null ? void 0 : t.show_opt_out_channels
|
|
202
|
+
showOptOutChannels: t == null ? void 0 : t.show_opt_out_channels,
|
|
203
|
+
tags: t == null ? void 0 : t.tags
|
|
202
204
|
};
|
|
203
205
|
const s = this.getUrl("full_preference", t), r = await this.config.client().request({ type: "get", url: s });
|
|
204
206
|
return r.error || (this.data = r.body), r;
|
|
@@ -211,7 +213,8 @@ class J {
|
|
|
211
213
|
tenant_id: e == null ? void 0 : e.tenantId,
|
|
212
214
|
show_opt_out_channels: (e == null ? void 0 : e.showOptOutChannels) !== !1,
|
|
213
215
|
limit: e == null ? void 0 : e.limit,
|
|
214
|
-
offset: e == null ? void 0 : e.offset
|
|
216
|
+
offset: e == null ? void 0 : e.offset,
|
|
217
|
+
tags: e == null ? void 0 : e.tags
|
|
215
218
|
}, s = this.getUrl("category", t);
|
|
216
219
|
return await this.config.client().request({ type: "get", url: s });
|
|
217
220
|
}
|
|
@@ -266,7 +269,7 @@ class J {
|
|
|
266
269
|
* Used to update user's category level preference.
|
|
267
270
|
*/
|
|
268
271
|
async updateCategoryPreference(e, t, s) {
|
|
269
|
-
var h;
|
|
272
|
+
var h, T, b, S;
|
|
270
273
|
if (!e || ![p.OPT_IN, p.OPT_OUT].includes(
|
|
271
274
|
t
|
|
272
275
|
))
|
|
@@ -289,13 +292,13 @@ class J {
|
|
|
289
292
|
});
|
|
290
293
|
let r = null, i = !1;
|
|
291
294
|
for (const R of this.data.sections) {
|
|
292
|
-
let
|
|
295
|
+
let O = !1;
|
|
293
296
|
if (R.subcategories) {
|
|
294
297
|
for (const g of R.subcategories)
|
|
295
298
|
if (g.category === e)
|
|
296
299
|
if (r = g, g.is_editable) {
|
|
297
300
|
if (g.preference !== t) {
|
|
298
|
-
g.preference = t, i = !0,
|
|
301
|
+
g.preference = t, i = !0, O = !0;
|
|
299
302
|
break;
|
|
300
303
|
}
|
|
301
304
|
} else
|
|
@@ -304,7 +307,7 @@ class J {
|
|
|
304
307
|
errorType: d.VALIDATION_ERROR,
|
|
305
308
|
errorMessage: "Category preference is not editable"
|
|
306
309
|
});
|
|
307
|
-
if (
|
|
310
|
+
if (O) break;
|
|
308
311
|
}
|
|
309
312
|
}
|
|
310
313
|
if (!r)
|
|
@@ -322,7 +325,9 @@ class J {
|
|
|
322
325
|
(h = r == null ? void 0 : r.channels) == null || h.forEach((R) => {
|
|
323
326
|
R.preference === p.OPT_OUT && c.push(R.channel);
|
|
324
327
|
});
|
|
325
|
-
|
|
328
|
+
let u = !0;
|
|
329
|
+
typeof (s == null ? void 0 : s.showOptOutChannels) == "boolean" ? u = s == null ? void 0 : s.showOptOutChannels : typeof ((T = this.preferenceArgs) == null ? void 0 : T.showOptOutChannels) == "boolean" && (u = this.preferenceArgs.showOptOutChannels);
|
|
330
|
+
const l = {
|
|
326
331
|
preference: r.preference,
|
|
327
332
|
opt_out_channels: u && t === p.OPT_IN ? null : c
|
|
328
333
|
};
|
|
@@ -331,7 +336,11 @@ class J {
|
|
|
331
336
|
e,
|
|
332
337
|
l,
|
|
333
338
|
r,
|
|
334
|
-
{
|
|
339
|
+
{
|
|
340
|
+
tenant_id: (s == null ? void 0 : s.tenantId) || ((b = this.preferenceArgs) == null ? void 0 : b.tenantId),
|
|
341
|
+
show_opt_out_channels: u,
|
|
342
|
+
tags: (s == null ? void 0 : s.tags) || ((S = this.preferenceArgs) == null ? void 0 : S.tags)
|
|
343
|
+
}
|
|
335
344
|
), o({
|
|
336
345
|
status: n.SUCCESS,
|
|
337
346
|
body: this.data
|
|
@@ -341,7 +350,7 @@ class J {
|
|
|
341
350
|
* Used to update user's category level channel preference.
|
|
342
351
|
*/
|
|
343
352
|
async updateChannelPreferenceInCategory(e, t, s, r) {
|
|
344
|
-
var g;
|
|
353
|
+
var S, R, O, g;
|
|
345
354
|
if (!e || !s)
|
|
346
355
|
return o({
|
|
347
356
|
status: n.ERROR,
|
|
@@ -370,16 +379,16 @@ class J {
|
|
|
370
379
|
});
|
|
371
380
|
let i = null, c = null, u = !1;
|
|
372
381
|
for (const m of this.data.sections) {
|
|
373
|
-
let
|
|
382
|
+
let v = !1;
|
|
374
383
|
if (m.subcategories) {
|
|
375
|
-
for (const
|
|
376
|
-
if (
|
|
377
|
-
if (i =
|
|
378
|
-
for (const
|
|
379
|
-
if (
|
|
380
|
-
if (c =
|
|
381
|
-
if (
|
|
382
|
-
|
|
384
|
+
for (const y of m.subcategories) {
|
|
385
|
+
if (y.category === s) {
|
|
386
|
+
if (i = y, !y.channels) continue;
|
|
387
|
+
for (const E of y.channels)
|
|
388
|
+
if (E.channel === e)
|
|
389
|
+
if (c = E, E.is_editable) {
|
|
390
|
+
if (E.preference !== t) {
|
|
391
|
+
E.preference = t, t === p.OPT_IN && (y.preference = p.OPT_IN), u = !0, v = !0;
|
|
383
392
|
break;
|
|
384
393
|
}
|
|
385
394
|
} else
|
|
@@ -389,9 +398,9 @@ class J {
|
|
|
389
398
|
errorMessage: "Channel preference is not editable"
|
|
390
399
|
});
|
|
391
400
|
}
|
|
392
|
-
if (
|
|
401
|
+
if (v) break;
|
|
393
402
|
}
|
|
394
|
-
if (
|
|
403
|
+
if (v) break;
|
|
395
404
|
}
|
|
396
405
|
}
|
|
397
406
|
if (!i)
|
|
@@ -412,19 +421,25 @@ class J {
|
|
|
412
421
|
body: this.data
|
|
413
422
|
});
|
|
414
423
|
const l = [];
|
|
415
|
-
(
|
|
424
|
+
(S = i == null ? void 0 : i.channels) == null || S.forEach((m) => {
|
|
416
425
|
m.preference === p.OPT_OUT && l.push(m.channel);
|
|
417
426
|
});
|
|
418
|
-
|
|
427
|
+
let h = !0;
|
|
428
|
+
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 b = {
|
|
419
430
|
preference: h && i.preference === p.OPT_OUT && t === p.OPT_IN ? p.OPT_IN : i.preference,
|
|
420
431
|
opt_out_channels: l
|
|
421
432
|
};
|
|
422
433
|
return this.debouncedUpdateCategoryPreferences(
|
|
423
434
|
s,
|
|
424
435
|
s,
|
|
425
|
-
|
|
436
|
+
b,
|
|
426
437
|
i,
|
|
427
|
-
{
|
|
438
|
+
{
|
|
439
|
+
tenant_id: (r == null ? void 0 : r.tenantId) || ((O = this.preferenceArgs) == null ? void 0 : O.tenantId),
|
|
440
|
+
show_opt_out_channels: h,
|
|
441
|
+
tags: (r == null ? void 0 : r.tags) || ((g = this.preferenceArgs) == null ? void 0 : g.tags)
|
|
442
|
+
}
|
|
428
443
|
), o({
|
|
429
444
|
status: n.SUCCESS,
|
|
430
445
|
body: this.data
|
|
@@ -435,8 +450,8 @@ class J {
|
|
|
435
450
|
*/
|
|
436
451
|
async updateOverallChannelPreference(e, t) {
|
|
437
452
|
if (!e || ![
|
|
438
|
-
|
|
439
|
-
|
|
453
|
+
w.ALL,
|
|
454
|
+
w.REQUIRED
|
|
440
455
|
].includes(t))
|
|
441
456
|
return o({
|
|
442
457
|
status: n.ERROR,
|
|
@@ -456,7 +471,7 @@ class J {
|
|
|
456
471
|
errorMessage: "Channel preferences doesn't exist"
|
|
457
472
|
});
|
|
458
473
|
let s = null, r = !1;
|
|
459
|
-
const i = t ===
|
|
474
|
+
const i = t === w.REQUIRED;
|
|
460
475
|
for (const c of this.data.channel_preferences)
|
|
461
476
|
if (c.channel === e && (s = c, c.is_restricted !== i)) {
|
|
462
477
|
c.is_restricted = i, r = !0;
|
|
@@ -477,7 +492,7 @@ class J {
|
|
|
477
492
|
});
|
|
478
493
|
}
|
|
479
494
|
}
|
|
480
|
-
const
|
|
495
|
+
const M = "ss_device_id";
|
|
481
496
|
class Z {
|
|
482
497
|
constructor(e) {
|
|
483
498
|
f(this, "config");
|
|
@@ -525,8 +540,8 @@ class Z {
|
|
|
525
540
|
async triggerUserEvent(e) {
|
|
526
541
|
return this.config.eventApi({
|
|
527
542
|
distinct_id: this.config.distinctId,
|
|
528
|
-
$insert_id:
|
|
529
|
-
$time:
|
|
543
|
+
$insert_id: C(),
|
|
544
|
+
$time: U(),
|
|
530
545
|
...e
|
|
531
546
|
});
|
|
532
547
|
}
|
|
@@ -756,8 +771,8 @@ class Z {
|
|
|
756
771
|
});
|
|
757
772
|
}
|
|
758
773
|
getDeviceId() {
|
|
759
|
-
let e =
|
|
760
|
-
return e || (e =
|
|
774
|
+
let e = j(M);
|
|
775
|
+
return e || (e = C(), $(M, e)), e;
|
|
761
776
|
}
|
|
762
777
|
async addWebPush(e) {
|
|
763
778
|
if (typeof e != "object")
|
|
@@ -843,7 +858,7 @@ class X {
|
|
|
843
858
|
this.config = e;
|
|
844
859
|
}
|
|
845
860
|
async getPushSubscription() {
|
|
846
|
-
if (!
|
|
861
|
+
if (!A()) return;
|
|
847
862
|
const e = await navigator.serviceWorker.getRegistration();
|
|
848
863
|
if (!e) return;
|
|
849
864
|
const t = e.pushManager.getSubscription();
|
|
@@ -889,7 +904,7 @@ class X {
|
|
|
889
904
|
* 3. Send webpush token to SuprSend.
|
|
890
905
|
*/
|
|
891
906
|
async registerPush() {
|
|
892
|
-
return
|
|
907
|
+
return A() && "serviceWorker" in navigator && "PushManager" in window ? this.handleRegisterPush() : (console.warn("[SuprSend]: Webpush isn't supported"), o({
|
|
893
908
|
status: n.ERROR,
|
|
894
909
|
errorType: d.UNSUPPORTED_ACTION,
|
|
895
910
|
errorMessage: "Webpush isn't supported"
|
|
@@ -918,25 +933,25 @@ class X {
|
|
|
918
933
|
return !!await this.getPushSubscription();
|
|
919
934
|
}
|
|
920
935
|
}
|
|
921
|
-
const
|
|
936
|
+
const F = 20, Y = "default", q = 100, D = {
|
|
922
937
|
storeId: "$suprsend_default_store",
|
|
923
938
|
label: ""
|
|
924
939
|
}, ee = {
|
|
925
|
-
tenantId:
|
|
926
|
-
pageSize:
|
|
940
|
+
tenantId: Y,
|
|
941
|
+
pageSize: F,
|
|
927
942
|
stores: null,
|
|
928
943
|
host: {
|
|
929
944
|
apiHost: "https://inboxs.live",
|
|
930
945
|
socketHost: "https://betainbox.suprsend.com"
|
|
931
946
|
}
|
|
932
|
-
},
|
|
947
|
+
}, P = {
|
|
933
948
|
notifications: [],
|
|
934
|
-
store:
|
|
949
|
+
store: D,
|
|
935
950
|
pageInfo: {
|
|
936
951
|
total: 0,
|
|
937
952
|
currentPage: 0,
|
|
938
953
|
totalPages: 0,
|
|
939
|
-
pageSize:
|
|
954
|
+
pageSize: F
|
|
940
955
|
},
|
|
941
956
|
meta: { badge: 0 },
|
|
942
957
|
apiStatus: _.INITIAL,
|
|
@@ -970,11 +985,11 @@ class se {
|
|
|
970
985
|
f(this, "store");
|
|
971
986
|
f(this, "socket");
|
|
972
987
|
f(this, "expiryTimerId");
|
|
973
|
-
f(this, "emitter",
|
|
988
|
+
f(this, "emitter", V());
|
|
974
989
|
this.config = e, this.setOptions(t), this.store = this.createFeedStore();
|
|
975
990
|
}
|
|
976
991
|
setOptions(e) {
|
|
977
|
-
this.feedOptions = { ...ee }, 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,
|
|
992
|
+
this.feedOptions = { ...ee }, 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, q)), e != null && e.stores && (this.feedOptions.stores = e.stores), this.validateStore();
|
|
978
993
|
}
|
|
979
994
|
validateStore() {
|
|
980
995
|
const e = this.feedOptions.stores;
|
|
@@ -1009,8 +1024,8 @@ class se {
|
|
|
1009
1024
|
return z()(() => {
|
|
1010
1025
|
var e;
|
|
1011
1026
|
return {
|
|
1012
|
-
...
|
|
1013
|
-
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) ||
|
|
1027
|
+
...P,
|
|
1028
|
+
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) || D
|
|
1014
1029
|
};
|
|
1015
1030
|
});
|
|
1016
1031
|
}
|
|
@@ -1098,12 +1113,12 @@ class se {
|
|
|
1098
1113
|
}), this.emitter.emit("feed.store_update", this.data);
|
|
1099
1114
|
}
|
|
1100
1115
|
notificationBelongToStore(e, t) {
|
|
1101
|
-
var
|
|
1102
|
-
const s = !!e.read_on, r = e.archived, i = e.tags, c = e.n_category, u = (
|
|
1103
|
-
let
|
|
1104
|
-
return Array.isArray(h) && h.length > 0 ? h.forEach((
|
|
1105
|
-
i != null && i.includes(
|
|
1106
|
-
}) :
|
|
1116
|
+
var g, m, v, y;
|
|
1117
|
+
const s = !!e.read_on, r = e.archived, i = e.tags, c = e.n_category, u = (g = t == null ? void 0 : t.query) == null ? void 0 : g.read, l = (m = t == null ? void 0 : t.query) == null ? void 0 : m.archived, h = (v = t == null ? void 0 : t.query) == null ? void 0 : v.tags, T = (y = t == null ? void 0 : t.query) == null ? void 0 : y.categories, b = u == null || s === u, S = !!r == !!l;
|
|
1118
|
+
let R = !1, O = !1;
|
|
1119
|
+
return Array.isArray(h) && h.length > 0 ? h.forEach((E) => {
|
|
1120
|
+
i != null && i.includes(E) && (R = !0);
|
|
1121
|
+
}) : R = !0, Array.isArray(T) && T.length > 0 ? T.includes(c) && (O = !0) : O = !0, b && R && O && S;
|
|
1107
1122
|
}
|
|
1108
1123
|
orderNotificationsBasedOnPinFlag(e, t) {
|
|
1109
1124
|
if (e.is_pinned)
|
|
@@ -1172,7 +1187,7 @@ class se {
|
|
|
1172
1187
|
(i) => i.storeId === e
|
|
1173
1188
|
);
|
|
1174
1189
|
return s ? (this.store.setState({
|
|
1175
|
-
...
|
|
1190
|
+
...P,
|
|
1176
1191
|
store: s,
|
|
1177
1192
|
meta: t.meta
|
|
1178
1193
|
}), await this.fetch()) : {
|
|
@@ -1225,7 +1240,7 @@ class se {
|
|
|
1225
1240
|
page_size: r,
|
|
1226
1241
|
page_no: s,
|
|
1227
1242
|
before: i,
|
|
1228
|
-
store: t.store.storeId !==
|
|
1243
|
+
store: t.store.storeId !== D.storeId ? this.storeQueryParamObj(t.store) : null
|
|
1229
1244
|
}, u = this.getUrl("notifications", c), l = await this.config.client().request({ type: "get", url: u });
|
|
1230
1245
|
if (l.status === n.ERROR)
|
|
1231
1246
|
return this.store.setState({ apiStatus: _.ERROR }), this.emitter.emit("feed.store_update", this.data), l;
|
|
@@ -1367,8 +1382,8 @@ class se {
|
|
|
1367
1382
|
reset() {
|
|
1368
1383
|
var e;
|
|
1369
1384
|
this.store.setState({
|
|
1370
|
-
...
|
|
1371
|
-
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) ||
|
|
1385
|
+
...P,
|
|
1386
|
+
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) || D
|
|
1372
1387
|
}), this.emitter.emit("feed.store_update", this.data), this.expiryTimerId && (clearInterval(this.expiryTimerId), this.expiryTimerId = void 0);
|
|
1373
1388
|
}
|
|
1374
1389
|
remove() {
|
|
@@ -1376,7 +1391,7 @@ class se {
|
|
|
1376
1391
|
this.reset(), this.emitter.off("*"), (e = this.socket) == null || e.disconnect(), this.config.feeds.removeInstance(this);
|
|
1377
1392
|
}
|
|
1378
1393
|
}
|
|
1379
|
-
const re = "https://hub.suprsend.com", ie = "serviceworker.js",
|
|
1394
|
+
const re = "https://hub.suprsend.com", ie = "serviceworker.js", L = "ss_distinct_id";
|
|
1380
1395
|
class ue {
|
|
1381
1396
|
constructor(e, t) {
|
|
1382
1397
|
f(this, "host");
|
|
@@ -1391,14 +1406,14 @@ class ue {
|
|
|
1391
1406
|
f(this, "user", new Z(this));
|
|
1392
1407
|
f(this, "webpush", new X(this));
|
|
1393
1408
|
f(this, "feeds", new te(this));
|
|
1394
|
-
f(this, "emitter",
|
|
1409
|
+
f(this, "emitter", V());
|
|
1395
1410
|
if (!e)
|
|
1396
1411
|
throw new Error("[SuprSend]: publicApiKey is missing");
|
|
1397
1412
|
this.publicApiKey = e, this.host = (t == null ? void 0 : t.host) || re, this.vapidKey = (t == null ? void 0 : t.vapidKey) || "", this.swFileName = (t == null ? void 0 : t.swFileName) || ie;
|
|
1398
1413
|
}
|
|
1399
1414
|
handleRefreshUserToken(e) {
|
|
1400
|
-
if (!this.userToken || !
|
|
1401
|
-
const t =
|
|
1415
|
+
if (!this.userToken || !A()) return;
|
|
1416
|
+
const t = x(this.userToken), s = (t.exp || 0) * 1e3, r = Date.now(), i = 1e3 * 30;
|
|
1402
1417
|
if (s && s > r) {
|
|
1403
1418
|
const c = s - r - i;
|
|
1404
1419
|
this.userTokenExpirationTimer && clearTimeout(this.userTokenExpirationTimer), this.userTokenExpirationTimer = setTimeout(async () => {
|
|
@@ -1425,7 +1440,7 @@ class ue {
|
|
|
1425
1440
|
client() {
|
|
1426
1441
|
return this.distinctId || console.warn(
|
|
1427
1442
|
"[SuprSend]: distinctId is missing. User should be authenticated"
|
|
1428
|
-
), this.apiClient || (this.apiClient = new
|
|
1443
|
+
), this.apiClient || (this.apiClient = new N(this)), this.apiClient;
|
|
1429
1444
|
}
|
|
1430
1445
|
eventApi(e) {
|
|
1431
1446
|
return this.client().request({
|
|
@@ -1452,24 +1467,24 @@ class ue {
|
|
|
1452
1467
|
errorMessage: "User already loggedin, reset current user to login new user"
|
|
1453
1468
|
});
|
|
1454
1469
|
if (this.apiClient && this.distinctId === e && this.userToken !== t)
|
|
1455
|
-
return this.userToken = t, this.apiClient = new
|
|
1470
|
+
return this.userToken = t, this.apiClient = new N(this), s != null && s.refreshUserToken && this.handleRefreshUserToken(s.refreshUserToken), o({ status: n.SUCCESS });
|
|
1456
1471
|
if (this.distinctId && this.apiClient)
|
|
1457
1472
|
return o({ status: n.SUCCESS });
|
|
1458
|
-
this.distinctId = e, this.userToken = t, this.apiClient = new
|
|
1459
|
-
const r =
|
|
1460
|
-
|
|
1473
|
+
this.distinctId = e, this.userToken = t, this.apiClient = new N(this), this.authenticateOptions = s;
|
|
1474
|
+
const r = j(
|
|
1475
|
+
L
|
|
1461
1476
|
);
|
|
1462
1477
|
if (s != null && s.refreshUserToken && this.handleRefreshUserToken(s.refreshUserToken), r == this.distinctId)
|
|
1463
1478
|
return this.webpush.updatePushSubscription(), o({ status: n.SUCCESS });
|
|
1464
1479
|
const i = await this.eventApi({
|
|
1465
1480
|
event: "$identify",
|
|
1466
|
-
$insert_id:
|
|
1467
|
-
$time:
|
|
1481
|
+
$insert_id: C(),
|
|
1482
|
+
$time: U(),
|
|
1468
1483
|
properties: {
|
|
1469
1484
|
$identified_id: e
|
|
1470
1485
|
}
|
|
1471
1486
|
});
|
|
1472
|
-
return i.status === n.SUCCESS ? (this.webpush.updatePushSubscription(),
|
|
1487
|
+
return i.status === n.SUCCESS ? (this.webpush.updatePushSubscription(), $(L, this.distinctId)) : this.reset({ unsubscribePush: !1 }), i;
|
|
1473
1488
|
}
|
|
1474
1489
|
/**
|
|
1475
1490
|
* Check's if SuprSend instance is authenticated. To check if userToken is also present pass true.
|
|
@@ -1484,8 +1499,8 @@ class ue {
|
|
|
1484
1499
|
let s = {};
|
|
1485
1500
|
return e ? (typeof t == "object" && (s = { ...s, ...t }), this.eventApi({
|
|
1486
1501
|
event: String(e),
|
|
1487
|
-
$insert_id:
|
|
1488
|
-
$time:
|
|
1502
|
+
$insert_id: C(),
|
|
1503
|
+
$time: U(),
|
|
1489
1504
|
distinct_id: this.distinctId,
|
|
1490
1505
|
properties: s
|
|
1491
1506
|
})) : o({
|
|
@@ -1504,7 +1519,7 @@ class ue {
|
|
|
1504
1519
|
}
|
|
1505
1520
|
export {
|
|
1506
1521
|
_ as ApiResponseStatus,
|
|
1507
|
-
|
|
1522
|
+
w as ChannelLevelPreferenceOptions,
|
|
1508
1523
|
d as ERROR_TYPE,
|
|
1509
1524
|
se as Feed,
|
|
1510
1525
|
p as PreferenceOptions,
|