@suprsend/web-sdk 4.0.4 → 4.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 +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/es/index.js +124 -118
- package/dist/es/index.js.map +1 -1
- package/dist/types/interface.d.ts +6 -0
- package/dist/types/preferences.d.ts +6 -16
- package/package.json +1 -1
package/dist/es/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var f = (a, e, t) =>
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { createStore as
|
|
7
|
-
import { io as
|
|
8
|
-
var p = /* @__PURE__ */ ((a) => (a.OPT_IN = "opt_in", a.OPT_OUT = "opt_out", a))(p || {}),
|
|
9
|
-
function
|
|
1
|
+
var H = Object.defineProperty;
|
|
2
|
+
var z = (a, e, t) => e in a ? H(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
|
|
3
|
+
var f = (a, e, t) => z(a, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import K from "mitt";
|
|
5
|
+
import x from "jwt-decode";
|
|
6
|
+
import { createStore as B } from "zustand/vanilla";
|
|
7
|
+
import { io as Q } from "socket.io-client";
|
|
8
|
+
var p = /* @__PURE__ */ ((a) => (a.OPT_IN = "opt_in", a.OPT_OUT = "opt_out", a))(p || {}), D = /* @__PURE__ */ ((a) => (a.ALL = "all", a.REQUIRED = "required", a))(D || {}), 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 N() {
|
|
10
10
|
let a = (/* @__PURE__ */ new Date()).getTime();
|
|
11
11
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
|
|
12
12
|
/[xy]/g,
|
|
@@ -16,32 +16,32 @@ function C() {
|
|
|
16
16
|
}
|
|
17
17
|
);
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function k() {
|
|
20
20
|
return Math.round(Date.now());
|
|
21
21
|
}
|
|
22
22
|
function I(a) {
|
|
23
23
|
return Object.keys(a).length === 0;
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function G(a) {
|
|
26
26
|
return (a == null ? void 0 : a.length) <= 0;
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function J(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 Z(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 $(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] = Z(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 L(a, e) {
|
|
58
58
|
A() && (typeof e == "object" && (e = JSON.stringify(e)), localStorage.setItem(a, e));
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function V(a) {
|
|
61
61
|
if (!A()) return;
|
|
62
62
|
const e = localStorage.getItem(a);
|
|
63
63
|
if (e)
|
|
@@ -67,14 +67,14 @@ function L(a) {
|
|
|
67
67
|
return e;
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
function
|
|
70
|
+
function X(a) {
|
|
71
71
|
A() && localStorage.removeItem(a);
|
|
72
72
|
}
|
|
73
|
-
async function
|
|
73
|
+
async function Y(a) {
|
|
74
74
|
const t = new TextEncoder().encode(a), s = await crypto.subtle.digest("SHA-256", t);
|
|
75
75
|
return Array.from(new Uint8Array(s)).map((c) => c.toString(16).padStart(2, "0")).join("");
|
|
76
76
|
}
|
|
77
|
-
class
|
|
77
|
+
class U {
|
|
78
78
|
constructor(e) {
|
|
79
79
|
f(this, "config");
|
|
80
80
|
this.config = e;
|
|
@@ -127,7 +127,7 @@ class N {
|
|
|
127
127
|
errorMessage: "User isn't authenticated. Call identify method before performing any action"
|
|
128
128
|
});
|
|
129
129
|
if ((t = this.config.authenticateOptions) != null && t.refreshUserToken && this.config.userToken) {
|
|
130
|
-
const i =
|
|
130
|
+
const i = x(this.config.userToken), c = (i.exp || 0) * 1e3, u = Date.now();
|
|
131
131
|
if (c <= u)
|
|
132
132
|
try {
|
|
133
133
|
const h = await this.config.authenticateOptions.refreshUserToken(
|
|
@@ -161,7 +161,7 @@ class N {
|
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
-
class
|
|
164
|
+
class q {
|
|
165
165
|
constructor(e) {
|
|
166
166
|
f(this, "config");
|
|
167
167
|
f(this, "preferenceData");
|
|
@@ -169,10 +169,10 @@ class Y {
|
|
|
169
169
|
f(this, "debouncedUpdateCategoryPreferences");
|
|
170
170
|
f(this, "debouncedUpdateChannelPreferences");
|
|
171
171
|
f(this, "debounceTime", 1e3);
|
|
172
|
-
this.config = e, this.debouncedUpdateCategoryPreferences =
|
|
172
|
+
this.config = e, this.debouncedUpdateCategoryPreferences = $(
|
|
173
173
|
this._updateCategoryPreferences.bind(this),
|
|
174
174
|
this.debounceTime
|
|
175
|
-
), this.debouncedUpdateChannelPreferences =
|
|
175
|
+
), this.debouncedUpdateChannelPreferences = $(
|
|
176
176
|
this._updateChannelPreferences.bind(this),
|
|
177
177
|
this.debounceTime
|
|
178
178
|
);
|
|
@@ -202,12 +202,14 @@ class Y {
|
|
|
202
202
|
const t = {
|
|
203
203
|
tenant_id: e == null ? void 0 : e.tenantId,
|
|
204
204
|
show_opt_out_channels: (e == null ? void 0 : e.showOptOutChannels) !== !1,
|
|
205
|
-
tags: e == null ? void 0 : e.tags
|
|
205
|
+
tags: e == null ? void 0 : e.tags,
|
|
206
|
+
locale: e == null ? void 0 : e.locale
|
|
206
207
|
};
|
|
207
208
|
this.preferenceArgs = {
|
|
208
209
|
tenantId: t == null ? void 0 : t.tenant_id,
|
|
209
210
|
showOptOutChannels: t == null ? void 0 : t.show_opt_out_channels,
|
|
210
|
-
tags: t == null ? void 0 : t.tags
|
|
211
|
+
tags: t == null ? void 0 : t.tags,
|
|
212
|
+
locale: t == null ? void 0 : t.locale
|
|
211
213
|
};
|
|
212
214
|
const s = this.getUrl("full_preference", t), r = await this.config.client().request({ type: "get", url: s });
|
|
213
215
|
return r.error || (this.data = r.body), r;
|
|
@@ -221,7 +223,8 @@ class Y {
|
|
|
221
223
|
show_opt_out_channels: (e == null ? void 0 : e.showOptOutChannels) !== !1,
|
|
222
224
|
limit: e == null ? void 0 : e.limit,
|
|
223
225
|
offset: e == null ? void 0 : e.offset,
|
|
224
|
-
tags: e == null ? void 0 : e.tags
|
|
226
|
+
tags: e == null ? void 0 : e.tags,
|
|
227
|
+
locale: e == null ? void 0 : e.locale
|
|
225
228
|
}, s = this.getUrl("category", t);
|
|
226
229
|
return await this.config.client().request({ type: "get", url: s });
|
|
227
230
|
}
|
|
@@ -237,7 +240,8 @@ class Y {
|
|
|
237
240
|
});
|
|
238
241
|
const s = {
|
|
239
242
|
tenant_id: t == null ? void 0 : t.tenantId,
|
|
240
|
-
show_opt_out_channels: (t == null ? void 0 : t.showOptOutChannels) !== !1
|
|
243
|
+
show_opt_out_channels: (t == null ? void 0 : t.showOptOutChannels) !== !1,
|
|
244
|
+
locale: t == null ? void 0 : t.locale
|
|
241
245
|
}, r = this.getUrl(`category/${e}`, s);
|
|
242
246
|
return await this.config.client().request({ type: "get", url: r });
|
|
243
247
|
}
|
|
@@ -276,7 +280,7 @@ class Y {
|
|
|
276
280
|
* Used to update user's category level preference.
|
|
277
281
|
*/
|
|
278
282
|
async updateCategoryPreference(e, t, s) {
|
|
279
|
-
var h, S, v, T;
|
|
283
|
+
var h, S, v, T, y;
|
|
280
284
|
if (!e || ![p.OPT_IN, p.OPT_OUT].includes(
|
|
281
285
|
t
|
|
282
286
|
))
|
|
@@ -299,13 +303,13 @@ class Y {
|
|
|
299
303
|
});
|
|
300
304
|
let r = null, i = !1;
|
|
301
305
|
for (const R of this.data.sections) {
|
|
302
|
-
let
|
|
306
|
+
let g = !1;
|
|
303
307
|
if (R.subcategories) {
|
|
304
|
-
for (const
|
|
305
|
-
if (
|
|
306
|
-
if (r =
|
|
307
|
-
if (
|
|
308
|
-
|
|
308
|
+
for (const O of R.subcategories)
|
|
309
|
+
if (O.category === e)
|
|
310
|
+
if (r = O, O.is_editable) {
|
|
311
|
+
if (O.preference !== t) {
|
|
312
|
+
O.preference = t, i = !0, g = !0;
|
|
309
313
|
break;
|
|
310
314
|
}
|
|
311
315
|
} else
|
|
@@ -314,7 +318,7 @@ class Y {
|
|
|
314
318
|
errorType: d.VALIDATION_ERROR,
|
|
315
319
|
errorMessage: "Category preference is not editable"
|
|
316
320
|
});
|
|
317
|
-
if (
|
|
321
|
+
if (g) break;
|
|
318
322
|
}
|
|
319
323
|
}
|
|
320
324
|
if (!r)
|
|
@@ -346,7 +350,8 @@ class Y {
|
|
|
346
350
|
{
|
|
347
351
|
tenant_id: (s == null ? void 0 : s.tenantId) || ((v = this.preferenceArgs) == null ? void 0 : v.tenantId),
|
|
348
352
|
show_opt_out_channels: u,
|
|
349
|
-
tags: (s == null ? void 0 : s.tags) || ((T = this.preferenceArgs) == null ? void 0 : T.tags)
|
|
353
|
+
tags: (s == null ? void 0 : s.tags) || ((T = this.preferenceArgs) == null ? void 0 : T.tags),
|
|
354
|
+
locale: (s == null ? void 0 : s.locale) || ((y = this.preferenceArgs) == null ? void 0 : y.locale)
|
|
350
355
|
}
|
|
351
356
|
), o({
|
|
352
357
|
status: n.SUCCESS,
|
|
@@ -357,7 +362,7 @@ class Y {
|
|
|
357
362
|
* Used to update user's category level channel preference.
|
|
358
363
|
*/
|
|
359
364
|
async updateChannelPreferenceInCategory(e, t, s, r) {
|
|
360
|
-
var T, R,
|
|
365
|
+
var T, y, R, g, O;
|
|
361
366
|
if (!e || !s)
|
|
362
367
|
return o({
|
|
363
368
|
status: n.ERROR,
|
|
@@ -385,17 +390,17 @@ class Y {
|
|
|
385
390
|
errorMessage: "Sections doesn't exist"
|
|
386
391
|
});
|
|
387
392
|
let i = null, c = null, u = !1;
|
|
388
|
-
for (const
|
|
393
|
+
for (const m of this.data.sections) {
|
|
389
394
|
let b = !1;
|
|
390
|
-
if (
|
|
391
|
-
for (const
|
|
392
|
-
if (
|
|
393
|
-
if (i =
|
|
394
|
-
for (const
|
|
395
|
-
if (
|
|
396
|
-
if (c =
|
|
397
|
-
if (
|
|
398
|
-
|
|
395
|
+
if (m.subcategories) {
|
|
396
|
+
for (const E of m.subcategories) {
|
|
397
|
+
if (E.category === s) {
|
|
398
|
+
if (i = E, !E.channels) continue;
|
|
399
|
+
for (const w of E.channels)
|
|
400
|
+
if (w.channel === e)
|
|
401
|
+
if (c = w, w.is_editable) {
|
|
402
|
+
if (w.preference !== t) {
|
|
403
|
+
w.preference = t, t === p.OPT_IN && (E.preference = p.OPT_IN), u = !0, b = !0;
|
|
399
404
|
break;
|
|
400
405
|
}
|
|
401
406
|
} else
|
|
@@ -428,11 +433,11 @@ class Y {
|
|
|
428
433
|
body: this.data
|
|
429
434
|
});
|
|
430
435
|
const l = [];
|
|
431
|
-
(T = i == null ? void 0 : i.channels) == null || T.forEach((
|
|
432
|
-
|
|
436
|
+
(T = i == null ? void 0 : i.channels) == null || T.forEach((m) => {
|
|
437
|
+
m.preference === p.OPT_OUT && l.push(m.channel);
|
|
433
438
|
});
|
|
434
439
|
let h = !0;
|
|
435
|
-
typeof (r == null ? void 0 : r.showOptOutChannels) == "boolean" ? h = r == null ? void 0 : r.showOptOutChannels : typeof ((
|
|
440
|
+
typeof (r == null ? void 0 : r.showOptOutChannels) == "boolean" ? h = r == null ? void 0 : r.showOptOutChannels : typeof ((y = this.preferenceArgs) == null ? void 0 : y.showOptOutChannels) == "boolean" && (h = this.preferenceArgs.showOptOutChannels);
|
|
436
441
|
const v = {
|
|
437
442
|
preference: h && i.preference === p.OPT_OUT && t === p.OPT_IN ? p.OPT_IN : i.preference,
|
|
438
443
|
opt_out_channels: l
|
|
@@ -443,9 +448,10 @@ class Y {
|
|
|
443
448
|
v,
|
|
444
449
|
i,
|
|
445
450
|
{
|
|
446
|
-
tenant_id: (r == null ? void 0 : r.tenantId) || ((
|
|
451
|
+
tenant_id: (r == null ? void 0 : r.tenantId) || ((R = this.preferenceArgs) == null ? void 0 : R.tenantId),
|
|
447
452
|
show_opt_out_channels: h,
|
|
448
|
-
tags: (r == null ? void 0 : r.tags) || ((g = this.preferenceArgs) == null ? void 0 : g.tags)
|
|
453
|
+
tags: (r == null ? void 0 : r.tags) || ((g = this.preferenceArgs) == null ? void 0 : g.tags),
|
|
454
|
+
locale: (r == null ? void 0 : r.locale) || ((O = this.preferenceArgs) == null ? void 0 : O.locale)
|
|
449
455
|
}
|
|
450
456
|
), o({
|
|
451
457
|
status: n.SUCCESS,
|
|
@@ -457,8 +463,8 @@ class Y {
|
|
|
457
463
|
*/
|
|
458
464
|
async updateOverallChannelPreference(e, t) {
|
|
459
465
|
if (!e || ![
|
|
460
|
-
|
|
461
|
-
|
|
466
|
+
D.ALL,
|
|
467
|
+
D.REQUIRED
|
|
462
468
|
].includes(t))
|
|
463
469
|
return o({
|
|
464
470
|
status: n.ERROR,
|
|
@@ -478,7 +484,7 @@ class Y {
|
|
|
478
484
|
errorMessage: "Channel preferences doesn't exist"
|
|
479
485
|
});
|
|
480
486
|
let s = null, r = !1;
|
|
481
|
-
const i = t ===
|
|
487
|
+
const i = t === D.REQUIRED;
|
|
482
488
|
for (const c of this.data.channel_preferences)
|
|
483
489
|
if (c.channel === e && (s = c, c.is_restricted !== i)) {
|
|
484
490
|
c.is_restricted = i, r = !0;
|
|
@@ -499,12 +505,12 @@ class Y {
|
|
|
499
505
|
});
|
|
500
506
|
}
|
|
501
507
|
}
|
|
502
|
-
const
|
|
503
|
-
class
|
|
508
|
+
const j = "ss_device_id";
|
|
509
|
+
class ee {
|
|
504
510
|
constructor(e) {
|
|
505
511
|
f(this, "config");
|
|
506
512
|
f(this, "preferences");
|
|
507
|
-
this.config = e, this.preferences = new
|
|
513
|
+
this.config = e, this.preferences = new q(e);
|
|
508
514
|
}
|
|
509
515
|
isReservedKey(e) {
|
|
510
516
|
var t;
|
|
@@ -547,8 +553,8 @@ class q {
|
|
|
547
553
|
async triggerUserEvent(e) {
|
|
548
554
|
return this.config.eventApi({
|
|
549
555
|
distinct_id: this.config.distinctId,
|
|
550
|
-
$insert_id:
|
|
551
|
-
$time:
|
|
556
|
+
$insert_id: N(),
|
|
557
|
+
$time: k(),
|
|
552
558
|
...e
|
|
553
559
|
});
|
|
554
560
|
}
|
|
@@ -658,7 +664,7 @@ class q {
|
|
|
658
664
|
errorMessage: "data provided is empty"
|
|
659
665
|
});
|
|
660
666
|
const s = this.validateArrayData(t);
|
|
661
|
-
return
|
|
667
|
+
return G(s) ? o({
|
|
662
668
|
status: n.ERROR,
|
|
663
669
|
errorType: d.VALIDATION_ERROR,
|
|
664
670
|
errorMessage: "data provided is empty"
|
|
@@ -778,8 +784,8 @@ class q {
|
|
|
778
784
|
});
|
|
779
785
|
}
|
|
780
786
|
getDeviceId() {
|
|
781
|
-
let e =
|
|
782
|
-
return e || (e =
|
|
787
|
+
let e = V(j);
|
|
788
|
+
return e || (e = N(), L(j, e)), e;
|
|
783
789
|
}
|
|
784
790
|
async addWebPush(e) {
|
|
785
791
|
if (typeof e != "object")
|
|
@@ -859,8 +865,8 @@ class q {
|
|
|
859
865
|
}) : this.setInternal({ $timezone: e });
|
|
860
866
|
}
|
|
861
867
|
}
|
|
862
|
-
const
|
|
863
|
-
class
|
|
868
|
+
const M = "ss_wp_hash";
|
|
869
|
+
class te {
|
|
864
870
|
constructor(e) {
|
|
865
871
|
f(this, "config");
|
|
866
872
|
this.config = e;
|
|
@@ -877,13 +883,13 @@ class ee {
|
|
|
877
883
|
const t = e.endpoint;
|
|
878
884
|
let s = null;
|
|
879
885
|
try {
|
|
880
|
-
s = await
|
|
886
|
+
s = await Y(t);
|
|
881
887
|
} catch {
|
|
882
888
|
}
|
|
883
889
|
if (s) {
|
|
884
|
-
if (s ===
|
|
890
|
+
if (s === V(M))
|
|
885
891
|
return o({ status: n.SUCCESS });
|
|
886
|
-
|
|
892
|
+
L(M, s);
|
|
887
893
|
}
|
|
888
894
|
return await this.config.user.addWebPush(e);
|
|
889
895
|
}
|
|
@@ -908,7 +914,7 @@ class ee {
|
|
|
908
914
|
});
|
|
909
915
|
const r = await t.pushManager.subscribe({
|
|
910
916
|
userVisibleOnly: !0,
|
|
911
|
-
applicationServerKey:
|
|
917
|
+
applicationServerKey: J(this.config.vapidKey)
|
|
912
918
|
});
|
|
913
919
|
return this.checkAndUpdateOnServer(r);
|
|
914
920
|
} catch (e) {
|
|
@@ -955,37 +961,37 @@ class ee {
|
|
|
955
961
|
return !!await this.getPushSubscription();
|
|
956
962
|
}
|
|
957
963
|
}
|
|
958
|
-
const
|
|
964
|
+
const W = 20, se = "default", re = 100, C = {
|
|
959
965
|
storeId: "$suprsend_default_store",
|
|
960
966
|
label: ""
|
|
961
|
-
},
|
|
962
|
-
tenantId:
|
|
963
|
-
pageSize:
|
|
967
|
+
}, ie = {
|
|
968
|
+
tenantId: se,
|
|
969
|
+
pageSize: W,
|
|
964
970
|
stores: null,
|
|
965
971
|
host: {
|
|
966
972
|
apiHost: "https://inboxs.live",
|
|
967
973
|
socketHost: "https://betainbox.suprsend.com"
|
|
968
974
|
}
|
|
969
|
-
},
|
|
975
|
+
}, P = {
|
|
970
976
|
notifications: [],
|
|
971
|
-
store:
|
|
977
|
+
store: C,
|
|
972
978
|
pageInfo: {
|
|
973
979
|
total: 0,
|
|
974
|
-
pageSize:
|
|
980
|
+
pageSize: W,
|
|
975
981
|
hasMore: !1
|
|
976
982
|
},
|
|
977
983
|
meta: { badge: 0 },
|
|
978
984
|
apiStatus: _.INITIAL,
|
|
979
985
|
isFirstFetch: !0
|
|
980
986
|
};
|
|
981
|
-
class
|
|
987
|
+
class ne {
|
|
982
988
|
constructor(e) {
|
|
983
989
|
f(this, "config");
|
|
984
990
|
f(this, "feedInstances", []);
|
|
985
991
|
this.config = e;
|
|
986
992
|
}
|
|
987
993
|
initialize(e = {}) {
|
|
988
|
-
const t = new
|
|
994
|
+
const t = new ae(this.config, e);
|
|
989
995
|
return this.feedInstances.push(t), t;
|
|
990
996
|
}
|
|
991
997
|
removeInstance(e) {
|
|
@@ -999,18 +1005,18 @@ class ie {
|
|
|
999
1005
|
this.feedInstances = [];
|
|
1000
1006
|
}
|
|
1001
1007
|
}
|
|
1002
|
-
class
|
|
1008
|
+
class ae {
|
|
1003
1009
|
constructor(e, t) {
|
|
1004
1010
|
f(this, "feedOptions");
|
|
1005
1011
|
f(this, "config");
|
|
1006
1012
|
f(this, "store");
|
|
1007
1013
|
f(this, "socket");
|
|
1008
1014
|
f(this, "expiryTimerId");
|
|
1009
|
-
f(this, "emitter",
|
|
1015
|
+
f(this, "emitter", K());
|
|
1010
1016
|
this.config = e, this.setOptions(t), this.store = this.createFeedStore();
|
|
1011
1017
|
}
|
|
1012
1018
|
setOptions(e) {
|
|
1013
|
-
this.feedOptions = { ...
|
|
1019
|
+
this.feedOptions = { ...ie }, 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, re)), e != null && e.stores && (this.feedOptions.stores = e.stores), this.validateStore();
|
|
1014
1020
|
}
|
|
1015
1021
|
validateStore() {
|
|
1016
1022
|
const e = this.feedOptions.stores;
|
|
@@ -1042,11 +1048,11 @@ class ne {
|
|
|
1042
1048
|
}), this.feedOptions.stores = t;
|
|
1043
1049
|
}
|
|
1044
1050
|
createFeedStore() {
|
|
1045
|
-
return
|
|
1051
|
+
return B()(() => {
|
|
1046
1052
|
var e;
|
|
1047
1053
|
return {
|
|
1048
|
-
...
|
|
1049
|
-
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) ||
|
|
1054
|
+
...P,
|
|
1055
|
+
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) || C
|
|
1050
1056
|
};
|
|
1051
1057
|
});
|
|
1052
1058
|
}
|
|
@@ -1054,7 +1060,7 @@ class ne {
|
|
|
1054
1060
|
this.socket.on("connect_error", async (e) => {
|
|
1055
1061
|
var t;
|
|
1056
1062
|
if (e.message === "Authentication Error: wrong auth token" && ((t = this.config.authenticateOptions) != null && t.refreshUserToken) && this.config.userToken) {
|
|
1057
|
-
const s = this.socket.auth["x-ss-signature"], r =
|
|
1063
|
+
const s = this.socket.auth["x-ss-signature"], r = x(s), i = (r.exp || 0) * 1e3, c = Date.now();
|
|
1058
1064
|
if (i <= c)
|
|
1059
1065
|
try {
|
|
1060
1066
|
const l = await this.config.authenticateOptions.refreshUserToken(
|
|
@@ -1154,12 +1160,12 @@ class ne {
|
|
|
1154
1160
|
}), this.emitter.emit("feed.store_update", this.data);
|
|
1155
1161
|
}
|
|
1156
1162
|
notificationBelongToStore(e, t) {
|
|
1157
|
-
var g,
|
|
1158
|
-
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 = (
|
|
1159
|
-
let
|
|
1163
|
+
var g, O, m, b;
|
|
1164
|
+
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 = (O = t == null ? void 0 : t.query) == null ? void 0 : O.archived, h = (m = t == null ? void 0 : t.query) == null ? void 0 : m.tags, S = (b = t == null ? void 0 : t.query) == null ? void 0 : b.categories, v = u == null || s === u, T = !!r == !!l;
|
|
1165
|
+
let y = !1, R = !1;
|
|
1160
1166
|
return Array.isArray(h) && h.length > 0 ? h.forEach((E) => {
|
|
1161
|
-
i != null && i.includes(E) && (
|
|
1162
|
-
}) :
|
|
1167
|
+
i != null && i.includes(E) && (y = !0);
|
|
1168
|
+
}) : y = !0, Array.isArray(S) && S.length > 0 ? S.includes(c) && (R = !0) : R = !0, v && y && R && T;
|
|
1163
1169
|
}
|
|
1164
1170
|
orderNotificationsBasedOnPinFlag(e, t) {
|
|
1165
1171
|
if (e.is_pinned)
|
|
@@ -1228,7 +1234,7 @@ class ne {
|
|
|
1228
1234
|
(i) => i.storeId === e
|
|
1229
1235
|
);
|
|
1230
1236
|
return s ? (this.store.setState({
|
|
1231
|
-
...
|
|
1237
|
+
...P,
|
|
1232
1238
|
store: s,
|
|
1233
1239
|
meta: t.meta
|
|
1234
1240
|
}), await this.fetch()) : {
|
|
@@ -1251,7 +1257,7 @@ class ne {
|
|
|
1251
1257
|
}
|
|
1252
1258
|
initializeSocketConnection() {
|
|
1253
1259
|
var e;
|
|
1254
|
-
this.socket || (this.socket =
|
|
1260
|
+
this.socket || (this.socket = Q((e = this.feedOptions.host) == null ? void 0 : e.socketHost, {
|
|
1255
1261
|
transports: ["websocket"],
|
|
1256
1262
|
auth: {
|
|
1257
1263
|
authorization: this.config.publicApiKey,
|
|
@@ -1278,7 +1284,7 @@ class ne {
|
|
|
1278
1284
|
distinct_id: this.config.distinctId,
|
|
1279
1285
|
tenant_id: this.feedOptions.tenantId,
|
|
1280
1286
|
page_size: s,
|
|
1281
|
-
store: t.store.storeId !==
|
|
1287
|
+
store: t.store.storeId !== C.storeId ? this.storeQueryParamObj(t.store) : null
|
|
1282
1288
|
};
|
|
1283
1289
|
if (t.notifications.length > 0) {
|
|
1284
1290
|
const u = t.notifications[t.notifications.length - 1];
|
|
@@ -1424,8 +1430,8 @@ class ne {
|
|
|
1424
1430
|
reset() {
|
|
1425
1431
|
var e;
|
|
1426
1432
|
this.store.setState({
|
|
1427
|
-
...
|
|
1428
|
-
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) ||
|
|
1433
|
+
...P,
|
|
1434
|
+
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) || C
|
|
1429
1435
|
}), this.emitter.emit("feed.store_update", this.data), this.expiryTimerId && (clearInterval(this.expiryTimerId), this.expiryTimerId = void 0);
|
|
1430
1436
|
}
|
|
1431
1437
|
remove() {
|
|
@@ -1433,8 +1439,8 @@ class ne {
|
|
|
1433
1439
|
this.reset(), this.emitter.off("*"), (e = this.socket) == null || e.disconnect(), this.config.feeds.removeInstance(this);
|
|
1434
1440
|
}
|
|
1435
1441
|
}
|
|
1436
|
-
const
|
|
1437
|
-
class
|
|
1442
|
+
const oe = "https://hub.suprsend.com", ce = "serviceworker.js", F = "ss_distinct_id";
|
|
1443
|
+
class pe {
|
|
1438
1444
|
constructor(e, t) {
|
|
1439
1445
|
f(this, "host");
|
|
1440
1446
|
f(this, "publicApiKey");
|
|
@@ -1445,17 +1451,17 @@ class le {
|
|
|
1445
1451
|
f(this, "apiClient", null);
|
|
1446
1452
|
f(this, "userTokenExpirationTimer", null);
|
|
1447
1453
|
f(this, "authenticateOptions");
|
|
1448
|
-
f(this, "user", new
|
|
1449
|
-
f(this, "webpush", new
|
|
1450
|
-
f(this, "feeds", new
|
|
1451
|
-
f(this, "emitter",
|
|
1454
|
+
f(this, "user", new ee(this));
|
|
1455
|
+
f(this, "webpush", new te(this));
|
|
1456
|
+
f(this, "feeds", new ne(this));
|
|
1457
|
+
f(this, "emitter", K());
|
|
1452
1458
|
if (!e)
|
|
1453
1459
|
throw new Error("[SuprSend]: publicApiKey is missing");
|
|
1454
|
-
this.publicApiKey = e, this.host = (t == null ? void 0 : t.host) ||
|
|
1460
|
+
this.publicApiKey = e, this.host = (t == null ? void 0 : t.host) || oe, this.vapidKey = (t == null ? void 0 : t.vapidKey) || "", this.swFileName = (t == null ? void 0 : t.swFileName) || ce;
|
|
1455
1461
|
}
|
|
1456
1462
|
handleRefreshUserToken(e) {
|
|
1457
1463
|
if (!this.userToken || !A()) return;
|
|
1458
|
-
const t =
|
|
1464
|
+
const t = x(this.userToken), s = (t.exp || 0) * 1e3, r = Date.now(), i = 1e3 * 30;
|
|
1459
1465
|
if (s && s > r) {
|
|
1460
1466
|
const c = s - r - i;
|
|
1461
1467
|
this.userTokenExpirationTimer && clearTimeout(this.userTokenExpirationTimer), this.userTokenExpirationTimer = setTimeout(async () => {
|
|
@@ -1482,7 +1488,7 @@ class le {
|
|
|
1482
1488
|
client() {
|
|
1483
1489
|
return this.distinctId || console.warn(
|
|
1484
1490
|
"[SuprSend]: distinctId is missing. User should be authenticated"
|
|
1485
|
-
), this.apiClient || (this.apiClient = new
|
|
1491
|
+
), this.apiClient || (this.apiClient = new U(this)), this.apiClient;
|
|
1486
1492
|
}
|
|
1487
1493
|
eventApi(e) {
|
|
1488
1494
|
return this.client().request({
|
|
@@ -1509,24 +1515,24 @@ class le {
|
|
|
1509
1515
|
errorMessage: "User already loggedin, reset current user to login new user"
|
|
1510
1516
|
});
|
|
1511
1517
|
if (this.apiClient && this.distinctId === e && this.userToken !== t)
|
|
1512
|
-
return this.userToken = t, this.apiClient = new
|
|
1518
|
+
return this.userToken = t, this.apiClient = new U(this), s != null && s.refreshUserToken && this.handleRefreshUserToken(s.refreshUserToken), o({ status: n.SUCCESS });
|
|
1513
1519
|
if (this.distinctId && this.apiClient)
|
|
1514
1520
|
return o({ status: n.SUCCESS });
|
|
1515
|
-
this.distinctId = e, this.userToken = t, this.apiClient = new
|
|
1516
|
-
const r =
|
|
1517
|
-
|
|
1521
|
+
this.distinctId = e, this.userToken = t, this.apiClient = new U(this), this.authenticateOptions = s;
|
|
1522
|
+
const r = V(
|
|
1523
|
+
F
|
|
1518
1524
|
);
|
|
1519
1525
|
if (s != null && s.refreshUserToken && this.handleRefreshUserToken(s.refreshUserToken), r == this.distinctId)
|
|
1520
1526
|
return this.webpush.updatePushSubscription(), o({ status: n.SUCCESS });
|
|
1521
1527
|
const i = await this.eventApi({
|
|
1522
1528
|
event: "$identify",
|
|
1523
|
-
$insert_id:
|
|
1524
|
-
$time:
|
|
1529
|
+
$insert_id: N(),
|
|
1530
|
+
$time: k(),
|
|
1525
1531
|
properties: {
|
|
1526
1532
|
$identified_id: e
|
|
1527
1533
|
}
|
|
1528
1534
|
});
|
|
1529
|
-
return i.status === n.SUCCESS ? (this.webpush.updatePushSubscription(),
|
|
1535
|
+
return i.status === n.SUCCESS ? (this.webpush.updatePushSubscription(), L(F, this.distinctId)) : this.reset({ unsubscribePush: !1 }), i;
|
|
1530
1536
|
}
|
|
1531
1537
|
/**
|
|
1532
1538
|
* Check's if SuprSend instance is authenticated. To check if userToken is also present pass true.
|
|
@@ -1541,8 +1547,8 @@ class le {
|
|
|
1541
1547
|
let s = {};
|
|
1542
1548
|
return e ? (typeof t == "object" && (s = { ...s, ...t }), this.eventApi({
|
|
1543
1549
|
event: String(e),
|
|
1544
|
-
$insert_id:
|
|
1545
|
-
$time:
|
|
1550
|
+
$insert_id: N(),
|
|
1551
|
+
$time: k(),
|
|
1546
1552
|
distinct_id: this.distinctId,
|
|
1547
1553
|
properties: s
|
|
1548
1554
|
})) : o({
|
|
@@ -1556,16 +1562,16 @@ class le {
|
|
|
1556
1562
|
*/
|
|
1557
1563
|
async reset(e) {
|
|
1558
1564
|
var s, r;
|
|
1559
|
-
return (e == null ? void 0 : e.unsubscribePush) !== !1 && (await ((s = this.webpush) == null ? void 0 : s.removePushSubscription()),
|
|
1565
|
+
return (e == null ? void 0 : e.unsubscribePush) !== !1 && (await ((s = this.webpush) == null ? void 0 : s.removePushSubscription()), X(M)), 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 });
|
|
1560
1566
|
}
|
|
1561
1567
|
}
|
|
1562
1568
|
export {
|
|
1563
1569
|
_ as ApiResponseStatus,
|
|
1564
|
-
|
|
1570
|
+
D as ChannelLevelPreferenceOptions,
|
|
1565
1571
|
d as ERROR_TYPE,
|
|
1566
|
-
|
|
1572
|
+
ae as Feed,
|
|
1567
1573
|
p as PreferenceOptions,
|
|
1568
1574
|
n as RESPONSE_STATUS,
|
|
1569
|
-
|
|
1575
|
+
pe as SuprSend
|
|
1570
1576
|
};
|
|
1571
1577
|
//# sourceMappingURL=index.js.map
|