@suprsend/web-sdk 4.0.4 → 4.1.1
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 +158 -145
- package/dist/es/index.js.map +1 -1
- package/dist/types/feed.d.ts +1 -0
- package/dist/types/interface.d.ts +7 -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 || {}), C = /* @__PURE__ */ ((a) => (a.ALL = "all", a.REQUIRED = "required", a))(C || {}), 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;
|
|
@@ -89,33 +89,36 @@ class N {
|
|
|
89
89
|
requestApiInstance(e) {
|
|
90
90
|
switch (e.type) {
|
|
91
91
|
case "get":
|
|
92
|
-
return this.get(e.url);
|
|
92
|
+
return this.get(e.url, e.signal);
|
|
93
93
|
case "post":
|
|
94
|
-
return this.post(e.url, (e == null ? void 0 : e.payload) || {});
|
|
94
|
+
return this.post(e.url, (e == null ? void 0 : e.payload) || {}, e.signal);
|
|
95
95
|
case "patch":
|
|
96
|
-
return this.patch(e.url, (e == null ? void 0 : e.payload) || {});
|
|
96
|
+
return this.patch(e.url, (e == null ? void 0 : e.payload) || {}, e.signal);
|
|
97
97
|
default:
|
|
98
|
-
return this.get(e.url);
|
|
98
|
+
return this.get(e.url, e.signal);
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
-
get(e) {
|
|
101
|
+
get(e, t) {
|
|
102
102
|
return fetch(e, {
|
|
103
103
|
method: "GET",
|
|
104
|
-
headers: this.getHeaders()
|
|
104
|
+
headers: this.getHeaders(),
|
|
105
|
+
signal: t
|
|
105
106
|
});
|
|
106
107
|
}
|
|
107
|
-
post(e, t) {
|
|
108
|
+
post(e, t, s) {
|
|
108
109
|
return fetch(e, {
|
|
109
110
|
method: "POST",
|
|
110
111
|
body: JSON.stringify(t),
|
|
111
|
-
headers: this.getHeaders()
|
|
112
|
+
headers: this.getHeaders(),
|
|
113
|
+
signal: s
|
|
112
114
|
});
|
|
113
115
|
}
|
|
114
|
-
patch(e, t) {
|
|
116
|
+
patch(e, t, s) {
|
|
115
117
|
return fetch(e, {
|
|
116
118
|
method: "PATCH",
|
|
117
119
|
body: JSON.stringify(t),
|
|
118
|
-
headers: this.getHeaders()
|
|
120
|
+
headers: this.getHeaders(),
|
|
121
|
+
signal: s
|
|
119
122
|
});
|
|
120
123
|
}
|
|
121
124
|
async request(e) {
|
|
@@ -127,7 +130,7 @@ class N {
|
|
|
127
130
|
errorMessage: "User isn't authenticated. Call identify method before performing any action"
|
|
128
131
|
});
|
|
129
132
|
if ((t = this.config.authenticateOptions) != null && t.refreshUserToken && this.config.userToken) {
|
|
130
|
-
const i =
|
|
133
|
+
const i = x(this.config.userToken), c = (i.exp || 0) * 1e3, u = Date.now();
|
|
131
134
|
if (c <= u)
|
|
132
135
|
try {
|
|
133
136
|
const h = await this.config.authenticateOptions.refreshUserToken(
|
|
@@ -161,7 +164,7 @@ class N {
|
|
|
161
164
|
}
|
|
162
165
|
}
|
|
163
166
|
}
|
|
164
|
-
class
|
|
167
|
+
class q {
|
|
165
168
|
constructor(e) {
|
|
166
169
|
f(this, "config");
|
|
167
170
|
f(this, "preferenceData");
|
|
@@ -169,10 +172,10 @@ class Y {
|
|
|
169
172
|
f(this, "debouncedUpdateCategoryPreferences");
|
|
170
173
|
f(this, "debouncedUpdateChannelPreferences");
|
|
171
174
|
f(this, "debounceTime", 1e3);
|
|
172
|
-
this.config = e, this.debouncedUpdateCategoryPreferences =
|
|
175
|
+
this.config = e, this.debouncedUpdateCategoryPreferences = $(
|
|
173
176
|
this._updateCategoryPreferences.bind(this),
|
|
174
177
|
this.debounceTime
|
|
175
|
-
), this.debouncedUpdateChannelPreferences =
|
|
178
|
+
), this.debouncedUpdateChannelPreferences = $(
|
|
176
179
|
this._updateChannelPreferences.bind(this),
|
|
177
180
|
this.debounceTime
|
|
178
181
|
);
|
|
@@ -202,12 +205,14 @@ class Y {
|
|
|
202
205
|
const t = {
|
|
203
206
|
tenant_id: e == null ? void 0 : e.tenantId,
|
|
204
207
|
show_opt_out_channels: (e == null ? void 0 : e.showOptOutChannels) !== !1,
|
|
205
|
-
tags: e == null ? void 0 : e.tags
|
|
208
|
+
tags: e == null ? void 0 : e.tags,
|
|
209
|
+
locale: e == null ? void 0 : e.locale
|
|
206
210
|
};
|
|
207
211
|
this.preferenceArgs = {
|
|
208
212
|
tenantId: t == null ? void 0 : t.tenant_id,
|
|
209
213
|
showOptOutChannels: t == null ? void 0 : t.show_opt_out_channels,
|
|
210
|
-
tags: t == null ? void 0 : t.tags
|
|
214
|
+
tags: t == null ? void 0 : t.tags,
|
|
215
|
+
locale: t == null ? void 0 : t.locale
|
|
211
216
|
};
|
|
212
217
|
const s = this.getUrl("full_preference", t), r = await this.config.client().request({ type: "get", url: s });
|
|
213
218
|
return r.error || (this.data = r.body), r;
|
|
@@ -221,7 +226,8 @@ class Y {
|
|
|
221
226
|
show_opt_out_channels: (e == null ? void 0 : e.showOptOutChannels) !== !1,
|
|
222
227
|
limit: e == null ? void 0 : e.limit,
|
|
223
228
|
offset: e == null ? void 0 : e.offset,
|
|
224
|
-
tags: e == null ? void 0 : e.tags
|
|
229
|
+
tags: e == null ? void 0 : e.tags,
|
|
230
|
+
locale: e == null ? void 0 : e.locale
|
|
225
231
|
}, s = this.getUrl("category", t);
|
|
226
232
|
return await this.config.client().request({ type: "get", url: s });
|
|
227
233
|
}
|
|
@@ -237,7 +243,8 @@ class Y {
|
|
|
237
243
|
});
|
|
238
244
|
const s = {
|
|
239
245
|
tenant_id: t == null ? void 0 : t.tenantId,
|
|
240
|
-
show_opt_out_channels: (t == null ? void 0 : t.showOptOutChannels) !== !1
|
|
246
|
+
show_opt_out_channels: (t == null ? void 0 : t.showOptOutChannels) !== !1,
|
|
247
|
+
locale: t == null ? void 0 : t.locale
|
|
241
248
|
}, r = this.getUrl(`category/${e}`, s);
|
|
242
249
|
return await this.config.client().request({ type: "get", url: r });
|
|
243
250
|
}
|
|
@@ -276,7 +283,7 @@ class Y {
|
|
|
276
283
|
* Used to update user's category level preference.
|
|
277
284
|
*/
|
|
278
285
|
async updateCategoryPreference(e, t, s) {
|
|
279
|
-
var h, S,
|
|
286
|
+
var h, S, b, T, g;
|
|
280
287
|
if (!e || ![p.OPT_IN, p.OPT_OUT].includes(
|
|
281
288
|
t
|
|
282
289
|
))
|
|
@@ -299,13 +306,13 @@ class Y {
|
|
|
299
306
|
});
|
|
300
307
|
let r = null, i = !1;
|
|
301
308
|
for (const R of this.data.sections) {
|
|
302
|
-
let
|
|
309
|
+
let y = !1;
|
|
303
310
|
if (R.subcategories) {
|
|
304
|
-
for (const
|
|
305
|
-
if (
|
|
306
|
-
if (r =
|
|
307
|
-
if (
|
|
308
|
-
|
|
311
|
+
for (const O of R.subcategories)
|
|
312
|
+
if (O.category === e)
|
|
313
|
+
if (r = O, O.is_editable) {
|
|
314
|
+
if (O.preference !== t) {
|
|
315
|
+
O.preference = t, i = !0, y = !0;
|
|
309
316
|
break;
|
|
310
317
|
}
|
|
311
318
|
} else
|
|
@@ -314,7 +321,7 @@ class Y {
|
|
|
314
321
|
errorType: d.VALIDATION_ERROR,
|
|
315
322
|
errorMessage: "Category preference is not editable"
|
|
316
323
|
});
|
|
317
|
-
if (
|
|
324
|
+
if (y) break;
|
|
318
325
|
}
|
|
319
326
|
}
|
|
320
327
|
if (!r)
|
|
@@ -344,9 +351,10 @@ class Y {
|
|
|
344
351
|
l,
|
|
345
352
|
r,
|
|
346
353
|
{
|
|
347
|
-
tenant_id: (s == null ? void 0 : s.tenantId) || ((
|
|
354
|
+
tenant_id: (s == null ? void 0 : s.tenantId) || ((b = this.preferenceArgs) == null ? void 0 : b.tenantId),
|
|
348
355
|
show_opt_out_channels: u,
|
|
349
|
-
tags: (s == null ? void 0 : s.tags) || ((T = this.preferenceArgs) == null ? void 0 : T.tags)
|
|
356
|
+
tags: (s == null ? void 0 : s.tags) || ((T = this.preferenceArgs) == null ? void 0 : T.tags),
|
|
357
|
+
locale: (s == null ? void 0 : s.locale) || ((g = this.preferenceArgs) == null ? void 0 : g.locale)
|
|
350
358
|
}
|
|
351
359
|
), o({
|
|
352
360
|
status: n.SUCCESS,
|
|
@@ -357,7 +365,7 @@ class Y {
|
|
|
357
365
|
* Used to update user's category level channel preference.
|
|
358
366
|
*/
|
|
359
367
|
async updateChannelPreferenceInCategory(e, t, s, r) {
|
|
360
|
-
var T, R,
|
|
368
|
+
var T, g, R, y, O;
|
|
361
369
|
if (!e || !s)
|
|
362
370
|
return o({
|
|
363
371
|
status: n.ERROR,
|
|
@@ -385,17 +393,17 @@ class Y {
|
|
|
385
393
|
errorMessage: "Sections doesn't exist"
|
|
386
394
|
});
|
|
387
395
|
let i = null, c = null, u = !1;
|
|
388
|
-
for (const
|
|
389
|
-
let
|
|
390
|
-
if (
|
|
391
|
-
for (const
|
|
392
|
-
if (
|
|
393
|
-
if (i =
|
|
394
|
-
for (const
|
|
395
|
-
if (
|
|
396
|
-
if (c =
|
|
397
|
-
if (
|
|
398
|
-
|
|
396
|
+
for (const m of this.data.sections) {
|
|
397
|
+
let v = !1;
|
|
398
|
+
if (m.subcategories) {
|
|
399
|
+
for (const E of m.subcategories) {
|
|
400
|
+
if (E.category === s) {
|
|
401
|
+
if (i = E, !E.channels) continue;
|
|
402
|
+
for (const w of E.channels)
|
|
403
|
+
if (w.channel === e)
|
|
404
|
+
if (c = w, w.is_editable) {
|
|
405
|
+
if (w.preference !== t) {
|
|
406
|
+
w.preference = t, t === p.OPT_IN && (E.preference = p.OPT_IN), u = !0, v = !0;
|
|
399
407
|
break;
|
|
400
408
|
}
|
|
401
409
|
} else
|
|
@@ -405,9 +413,9 @@ class Y {
|
|
|
405
413
|
errorMessage: "Channel preference is not editable"
|
|
406
414
|
});
|
|
407
415
|
}
|
|
408
|
-
if (
|
|
416
|
+
if (v) break;
|
|
409
417
|
}
|
|
410
|
-
if (
|
|
418
|
+
if (v) break;
|
|
411
419
|
}
|
|
412
420
|
}
|
|
413
421
|
if (!i)
|
|
@@ -428,24 +436,25 @@ class Y {
|
|
|
428
436
|
body: this.data
|
|
429
437
|
});
|
|
430
438
|
const l = [];
|
|
431
|
-
(T = i == null ? void 0 : i.channels) == null || T.forEach((
|
|
432
|
-
|
|
439
|
+
(T = i == null ? void 0 : i.channels) == null || T.forEach((m) => {
|
|
440
|
+
m.preference === p.OPT_OUT && l.push(m.channel);
|
|
433
441
|
});
|
|
434
442
|
let h = !0;
|
|
435
|
-
typeof (r == null ? void 0 : r.showOptOutChannels) == "boolean" ? h = r == null ? void 0 : r.showOptOutChannels : typeof ((
|
|
436
|
-
const
|
|
443
|
+
typeof (r == null ? void 0 : r.showOptOutChannels) == "boolean" ? h = r == null ? void 0 : r.showOptOutChannels : typeof ((g = this.preferenceArgs) == null ? void 0 : g.showOptOutChannels) == "boolean" && (h = this.preferenceArgs.showOptOutChannels);
|
|
444
|
+
const b = {
|
|
437
445
|
preference: h && i.preference === p.OPT_OUT && t === p.OPT_IN ? p.OPT_IN : i.preference,
|
|
438
446
|
opt_out_channels: l
|
|
439
447
|
};
|
|
440
448
|
return this.debouncedUpdateCategoryPreferences(
|
|
441
449
|
s,
|
|
442
450
|
s,
|
|
443
|
-
|
|
451
|
+
b,
|
|
444
452
|
i,
|
|
445
453
|
{
|
|
446
|
-
tenant_id: (r == null ? void 0 : r.tenantId) || ((
|
|
454
|
+
tenant_id: (r == null ? void 0 : r.tenantId) || ((R = this.preferenceArgs) == null ? void 0 : R.tenantId),
|
|
447
455
|
show_opt_out_channels: h,
|
|
448
|
-
tags: (r == null ? void 0 : r.tags) || ((
|
|
456
|
+
tags: (r == null ? void 0 : r.tags) || ((y = this.preferenceArgs) == null ? void 0 : y.tags),
|
|
457
|
+
locale: (r == null ? void 0 : r.locale) || ((O = this.preferenceArgs) == null ? void 0 : O.locale)
|
|
449
458
|
}
|
|
450
459
|
), o({
|
|
451
460
|
status: n.SUCCESS,
|
|
@@ -457,8 +466,8 @@ class Y {
|
|
|
457
466
|
*/
|
|
458
467
|
async updateOverallChannelPreference(e, t) {
|
|
459
468
|
if (!e || ![
|
|
460
|
-
|
|
461
|
-
|
|
469
|
+
C.ALL,
|
|
470
|
+
C.REQUIRED
|
|
462
471
|
].includes(t))
|
|
463
472
|
return o({
|
|
464
473
|
status: n.ERROR,
|
|
@@ -478,7 +487,7 @@ class Y {
|
|
|
478
487
|
errorMessage: "Channel preferences doesn't exist"
|
|
479
488
|
});
|
|
480
489
|
let s = null, r = !1;
|
|
481
|
-
const i = t ===
|
|
490
|
+
const i = t === C.REQUIRED;
|
|
482
491
|
for (const c of this.data.channel_preferences)
|
|
483
492
|
if (c.channel === e && (s = c, c.is_restricted !== i)) {
|
|
484
493
|
c.is_restricted = i, r = !0;
|
|
@@ -499,12 +508,12 @@ class Y {
|
|
|
499
508
|
});
|
|
500
509
|
}
|
|
501
510
|
}
|
|
502
|
-
const
|
|
503
|
-
class
|
|
511
|
+
const j = "ss_device_id";
|
|
512
|
+
class ee {
|
|
504
513
|
constructor(e) {
|
|
505
514
|
f(this, "config");
|
|
506
515
|
f(this, "preferences");
|
|
507
|
-
this.config = e, this.preferences = new
|
|
516
|
+
this.config = e, this.preferences = new q(e);
|
|
508
517
|
}
|
|
509
518
|
isReservedKey(e) {
|
|
510
519
|
var t;
|
|
@@ -547,8 +556,8 @@ class q {
|
|
|
547
556
|
async triggerUserEvent(e) {
|
|
548
557
|
return this.config.eventApi({
|
|
549
558
|
distinct_id: this.config.distinctId,
|
|
550
|
-
$insert_id:
|
|
551
|
-
$time:
|
|
559
|
+
$insert_id: N(),
|
|
560
|
+
$time: k(),
|
|
552
561
|
...e
|
|
553
562
|
});
|
|
554
563
|
}
|
|
@@ -658,7 +667,7 @@ class q {
|
|
|
658
667
|
errorMessage: "data provided is empty"
|
|
659
668
|
});
|
|
660
669
|
const s = this.validateArrayData(t);
|
|
661
|
-
return
|
|
670
|
+
return G(s) ? o({
|
|
662
671
|
status: n.ERROR,
|
|
663
672
|
errorType: d.VALIDATION_ERROR,
|
|
664
673
|
errorMessage: "data provided is empty"
|
|
@@ -778,8 +787,8 @@ class q {
|
|
|
778
787
|
});
|
|
779
788
|
}
|
|
780
789
|
getDeviceId() {
|
|
781
|
-
let e =
|
|
782
|
-
return e || (e =
|
|
790
|
+
let e = V(j);
|
|
791
|
+
return e || (e = N(), L(j, e)), e;
|
|
783
792
|
}
|
|
784
793
|
async addWebPush(e) {
|
|
785
794
|
if (typeof e != "object")
|
|
@@ -859,8 +868,8 @@ class q {
|
|
|
859
868
|
}) : this.setInternal({ $timezone: e });
|
|
860
869
|
}
|
|
861
870
|
}
|
|
862
|
-
const
|
|
863
|
-
class
|
|
871
|
+
const M = "ss_wp_hash";
|
|
872
|
+
class te {
|
|
864
873
|
constructor(e) {
|
|
865
874
|
f(this, "config");
|
|
866
875
|
this.config = e;
|
|
@@ -877,13 +886,13 @@ class ee {
|
|
|
877
886
|
const t = e.endpoint;
|
|
878
887
|
let s = null;
|
|
879
888
|
try {
|
|
880
|
-
s = await
|
|
889
|
+
s = await Y(t);
|
|
881
890
|
} catch {
|
|
882
891
|
}
|
|
883
892
|
if (s) {
|
|
884
|
-
if (s ===
|
|
893
|
+
if (s === V(M))
|
|
885
894
|
return o({ status: n.SUCCESS });
|
|
886
|
-
|
|
895
|
+
L(M, s);
|
|
887
896
|
}
|
|
888
897
|
return await this.config.user.addWebPush(e);
|
|
889
898
|
}
|
|
@@ -908,7 +917,7 @@ class ee {
|
|
|
908
917
|
});
|
|
909
918
|
const r = await t.pushManager.subscribe({
|
|
910
919
|
userVisibleOnly: !0,
|
|
911
|
-
applicationServerKey:
|
|
920
|
+
applicationServerKey: J(this.config.vapidKey)
|
|
912
921
|
});
|
|
913
922
|
return this.checkAndUpdateOnServer(r);
|
|
914
923
|
} catch (e) {
|
|
@@ -955,37 +964,37 @@ class ee {
|
|
|
955
964
|
return !!await this.getPushSubscription();
|
|
956
965
|
}
|
|
957
966
|
}
|
|
958
|
-
const
|
|
967
|
+
const W = 20, se = "default", re = 100, D = {
|
|
959
968
|
storeId: "$suprsend_default_store",
|
|
960
969
|
label: ""
|
|
961
|
-
},
|
|
962
|
-
tenantId:
|
|
963
|
-
pageSize:
|
|
970
|
+
}, ie = {
|
|
971
|
+
tenantId: se,
|
|
972
|
+
pageSize: W,
|
|
964
973
|
stores: null,
|
|
965
974
|
host: {
|
|
966
975
|
apiHost: "https://inboxs.live",
|
|
967
976
|
socketHost: "https://betainbox.suprsend.com"
|
|
968
977
|
}
|
|
969
|
-
},
|
|
978
|
+
}, P = {
|
|
970
979
|
notifications: [],
|
|
971
980
|
store: D,
|
|
972
981
|
pageInfo: {
|
|
973
982
|
total: 0,
|
|
974
|
-
pageSize:
|
|
983
|
+
pageSize: W,
|
|
975
984
|
hasMore: !1
|
|
976
985
|
},
|
|
977
986
|
meta: { badge: 0 },
|
|
978
987
|
apiStatus: _.INITIAL,
|
|
979
988
|
isFirstFetch: !0
|
|
980
989
|
};
|
|
981
|
-
class
|
|
990
|
+
class ne {
|
|
982
991
|
constructor(e) {
|
|
983
992
|
f(this, "config");
|
|
984
993
|
f(this, "feedInstances", []);
|
|
985
994
|
this.config = e;
|
|
986
995
|
}
|
|
987
996
|
initialize(e = {}) {
|
|
988
|
-
const t = new
|
|
997
|
+
const t = new ae(this.config, e);
|
|
989
998
|
return this.feedInstances.push(t), t;
|
|
990
999
|
}
|
|
991
1000
|
removeInstance(e) {
|
|
@@ -999,18 +1008,19 @@ class ie {
|
|
|
999
1008
|
this.feedInstances = [];
|
|
1000
1009
|
}
|
|
1001
1010
|
}
|
|
1002
|
-
class
|
|
1011
|
+
class ae {
|
|
1003
1012
|
constructor(e, t) {
|
|
1004
1013
|
f(this, "feedOptions");
|
|
1005
1014
|
f(this, "config");
|
|
1006
1015
|
f(this, "store");
|
|
1007
1016
|
f(this, "socket");
|
|
1008
1017
|
f(this, "expiryTimerId");
|
|
1009
|
-
f(this, "
|
|
1018
|
+
f(this, "fetchAbortController");
|
|
1019
|
+
f(this, "emitter", K());
|
|
1010
1020
|
this.config = e, this.setOptions(t), this.store = this.createFeedStore();
|
|
1011
1021
|
}
|
|
1012
1022
|
setOptions(e) {
|
|
1013
|
-
this.feedOptions = { ...
|
|
1023
|
+
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
1024
|
}
|
|
1015
1025
|
validateStore() {
|
|
1016
1026
|
const e = this.feedOptions.stores;
|
|
@@ -1042,10 +1052,10 @@ class ne {
|
|
|
1042
1052
|
}), this.feedOptions.stores = t;
|
|
1043
1053
|
}
|
|
1044
1054
|
createFeedStore() {
|
|
1045
|
-
return
|
|
1055
|
+
return B()(() => {
|
|
1046
1056
|
var e;
|
|
1047
1057
|
return {
|
|
1048
|
-
...
|
|
1058
|
+
...P,
|
|
1049
1059
|
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) || D
|
|
1050
1060
|
};
|
|
1051
1061
|
});
|
|
@@ -1054,7 +1064,7 @@ class ne {
|
|
|
1054
1064
|
this.socket.on("connect_error", async (e) => {
|
|
1055
1065
|
var t;
|
|
1056
1066
|
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 =
|
|
1067
|
+
const s = this.socket.auth["x-ss-signature"], r = x(s), i = (r.exp || 0) * 1e3, c = Date.now();
|
|
1058
1068
|
if (i <= c)
|
|
1059
1069
|
try {
|
|
1060
1070
|
const l = await this.config.authenticateOptions.refreshUserToken(
|
|
@@ -1154,12 +1164,12 @@ class ne {
|
|
|
1154
1164
|
}), this.emitter.emit("feed.store_update", this.data);
|
|
1155
1165
|
}
|
|
1156
1166
|
notificationBelongToStore(e, t) {
|
|
1157
|
-
var
|
|
1158
|
-
const s = !!e.read_on, r = e.archived, i = e.tags, c = e.n_category, u = (
|
|
1159
|
-
let
|
|
1167
|
+
var y, O, m, v;
|
|
1168
|
+
const s = !!e.read_on, r = e.archived, i = e.tags, c = e.n_category, u = (y = t == null ? void 0 : t.query) == null ? void 0 : y.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 = (v = t == null ? void 0 : t.query) == null ? void 0 : v.categories, b = u == null || s === u, T = !!r == !!l;
|
|
1169
|
+
let g = !1, R = !1;
|
|
1160
1170
|
return Array.isArray(h) && h.length > 0 ? h.forEach((E) => {
|
|
1161
|
-
i != null && i.includes(E) && (
|
|
1162
|
-
}) :
|
|
1171
|
+
i != null && i.includes(E) && (g = !0);
|
|
1172
|
+
}) : g = !0, Array.isArray(S) && S.length > 0 ? S.includes(c) && (R = !0) : R = !0, b && g && R && T;
|
|
1163
1173
|
}
|
|
1164
1174
|
orderNotificationsBasedOnPinFlag(e, t) {
|
|
1165
1175
|
if (e.is_pinned)
|
|
@@ -1227,8 +1237,8 @@ class ne {
|
|
|
1227
1237
|
const s = (r = this.feedOptions.stores) == null ? void 0 : r.find(
|
|
1228
1238
|
(i) => i.storeId === e
|
|
1229
1239
|
);
|
|
1230
|
-
return s ? (this.store.setState({
|
|
1231
|
-
...
|
|
1240
|
+
return s ? (this.fetchAbortController && (this.fetchAbortController.abort(), this.fetchAbortController = void 0), this.store.setState({
|
|
1241
|
+
...P,
|
|
1232
1242
|
store: s,
|
|
1233
1243
|
meta: t.meta
|
|
1234
1244
|
}), await this.fetch()) : {
|
|
@@ -1251,7 +1261,7 @@ class ne {
|
|
|
1251
1261
|
}
|
|
1252
1262
|
initializeSocketConnection() {
|
|
1253
1263
|
var e;
|
|
1254
|
-
this.socket || (this.socket =
|
|
1264
|
+
this.socket || (this.socket = Q((e = this.feedOptions.host) == null ? void 0 : e.socketHost, {
|
|
1255
1265
|
transports: ["websocket"],
|
|
1256
1266
|
auth: {
|
|
1257
1267
|
authorization: this.config.publicApiKey,
|
|
@@ -1281,24 +1291,27 @@ class ne {
|
|
|
1281
1291
|
store: t.store.storeId !== D.storeId ? this.storeQueryParamObj(t.store) : null
|
|
1282
1292
|
};
|
|
1283
1293
|
if (t.notifications.length > 0) {
|
|
1284
|
-
const
|
|
1294
|
+
const l = t.notifications[t.notifications.length - 1];
|
|
1285
1295
|
r.search_after = [
|
|
1286
|
-
|
|
1287
|
-
|
|
1296
|
+
l.is_pinned,
|
|
1297
|
+
l.created_on
|
|
1288
1298
|
];
|
|
1289
1299
|
} else
|
|
1290
1300
|
r.search_after = [];
|
|
1291
|
-
const i = this.getUrl("notifications", r), c =
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1301
|
+
const i = this.getUrl("notifications", r), c = new AbortController();
|
|
1302
|
+
this.fetchAbortController = c;
|
|
1303
|
+
const u = await this.config.client().request({ type: "get", url: i, signal: c.signal });
|
|
1304
|
+
if (!c.signal.aborted)
|
|
1305
|
+
return u.status === n.ERROR ? (this.store.setState({ apiStatus: _.ERROR }), this.emitter.emit("feed.store_update", this.data), u) : (this.store.setState({
|
|
1306
|
+
apiStatus: _.SUCCESS,
|
|
1307
|
+
notifications: t.isFirstFetch ? u.body.results : [...t.notifications, ...u.body.results],
|
|
1308
|
+
pageInfo: {
|
|
1309
|
+
...t.pageInfo,
|
|
1310
|
+
total: u.body.meta.total_count,
|
|
1311
|
+
hasMore: u.body.meta.has_more
|
|
1312
|
+
},
|
|
1313
|
+
isFirstFetch: !1
|
|
1314
|
+
}), this.emitter.emit("feed.store_update", this.data), this.startExpiryTimer(), u);
|
|
1302
1315
|
}
|
|
1303
1316
|
// TODO: support other stores
|
|
1304
1317
|
async fetchNextPage() {
|
|
@@ -1424,7 +1437,7 @@ class ne {
|
|
|
1424
1437
|
reset() {
|
|
1425
1438
|
var e;
|
|
1426
1439
|
this.store.setState({
|
|
1427
|
-
...
|
|
1440
|
+
...P,
|
|
1428
1441
|
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) || D
|
|
1429
1442
|
}), this.emitter.emit("feed.store_update", this.data), this.expiryTimerId && (clearInterval(this.expiryTimerId), this.expiryTimerId = void 0);
|
|
1430
1443
|
}
|
|
@@ -1433,8 +1446,8 @@ class ne {
|
|
|
1433
1446
|
this.reset(), this.emitter.off("*"), (e = this.socket) == null || e.disconnect(), this.config.feeds.removeInstance(this);
|
|
1434
1447
|
}
|
|
1435
1448
|
}
|
|
1436
|
-
const
|
|
1437
|
-
class
|
|
1449
|
+
const oe = "https://hub.suprsend.com", ce = "serviceworker.js", F = "ss_distinct_id";
|
|
1450
|
+
class pe {
|
|
1438
1451
|
constructor(e, t) {
|
|
1439
1452
|
f(this, "host");
|
|
1440
1453
|
f(this, "publicApiKey");
|
|
@@ -1445,17 +1458,17 @@ class le {
|
|
|
1445
1458
|
f(this, "apiClient", null);
|
|
1446
1459
|
f(this, "userTokenExpirationTimer", null);
|
|
1447
1460
|
f(this, "authenticateOptions");
|
|
1448
|
-
f(this, "user", new
|
|
1449
|
-
f(this, "webpush", new
|
|
1450
|
-
f(this, "feeds", new
|
|
1451
|
-
f(this, "emitter",
|
|
1461
|
+
f(this, "user", new ee(this));
|
|
1462
|
+
f(this, "webpush", new te(this));
|
|
1463
|
+
f(this, "feeds", new ne(this));
|
|
1464
|
+
f(this, "emitter", K());
|
|
1452
1465
|
if (!e)
|
|
1453
1466
|
throw new Error("[SuprSend]: publicApiKey is missing");
|
|
1454
|
-
this.publicApiKey = e, this.host = (t == null ? void 0 : t.host) ||
|
|
1467
|
+
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
1468
|
}
|
|
1456
1469
|
handleRefreshUserToken(e) {
|
|
1457
1470
|
if (!this.userToken || !A()) return;
|
|
1458
|
-
const t =
|
|
1471
|
+
const t = x(this.userToken), s = (t.exp || 0) * 1e3, r = Date.now(), i = 1e3 * 30;
|
|
1459
1472
|
if (s && s > r) {
|
|
1460
1473
|
const c = s - r - i;
|
|
1461
1474
|
this.userTokenExpirationTimer && clearTimeout(this.userTokenExpirationTimer), this.userTokenExpirationTimer = setTimeout(async () => {
|
|
@@ -1482,7 +1495,7 @@ class le {
|
|
|
1482
1495
|
client() {
|
|
1483
1496
|
return this.distinctId || console.warn(
|
|
1484
1497
|
"[SuprSend]: distinctId is missing. User should be authenticated"
|
|
1485
|
-
), this.apiClient || (this.apiClient = new
|
|
1498
|
+
), this.apiClient || (this.apiClient = new U(this)), this.apiClient;
|
|
1486
1499
|
}
|
|
1487
1500
|
eventApi(e) {
|
|
1488
1501
|
return this.client().request({
|
|
@@ -1509,24 +1522,24 @@ class le {
|
|
|
1509
1522
|
errorMessage: "User already loggedin, reset current user to login new user"
|
|
1510
1523
|
});
|
|
1511
1524
|
if (this.apiClient && this.distinctId === e && this.userToken !== t)
|
|
1512
|
-
return this.userToken = t, this.apiClient = new
|
|
1525
|
+
return this.userToken = t, this.apiClient = new U(this), s != null && s.refreshUserToken && this.handleRefreshUserToken(s.refreshUserToken), o({ status: n.SUCCESS });
|
|
1513
1526
|
if (this.distinctId && this.apiClient)
|
|
1514
1527
|
return o({ status: n.SUCCESS });
|
|
1515
|
-
this.distinctId = e, this.userToken = t, this.apiClient = new
|
|
1516
|
-
const r =
|
|
1517
|
-
|
|
1528
|
+
this.distinctId = e, this.userToken = t, this.apiClient = new U(this), this.authenticateOptions = s;
|
|
1529
|
+
const r = V(
|
|
1530
|
+
F
|
|
1518
1531
|
);
|
|
1519
1532
|
if (s != null && s.refreshUserToken && this.handleRefreshUserToken(s.refreshUserToken), r == this.distinctId)
|
|
1520
1533
|
return this.webpush.updatePushSubscription(), o({ status: n.SUCCESS });
|
|
1521
1534
|
const i = await this.eventApi({
|
|
1522
1535
|
event: "$identify",
|
|
1523
|
-
$insert_id:
|
|
1524
|
-
$time:
|
|
1536
|
+
$insert_id: N(),
|
|
1537
|
+
$time: k(),
|
|
1525
1538
|
properties: {
|
|
1526
1539
|
$identified_id: e
|
|
1527
1540
|
}
|
|
1528
1541
|
});
|
|
1529
|
-
return i.status === n.SUCCESS ? (this.webpush.updatePushSubscription(),
|
|
1542
|
+
return i.status === n.SUCCESS ? (this.webpush.updatePushSubscription(), L(F, this.distinctId)) : this.reset({ unsubscribePush: !1 }), i;
|
|
1530
1543
|
}
|
|
1531
1544
|
/**
|
|
1532
1545
|
* Check's if SuprSend instance is authenticated. To check if userToken is also present pass true.
|
|
@@ -1541,8 +1554,8 @@ class le {
|
|
|
1541
1554
|
let s = {};
|
|
1542
1555
|
return e ? (typeof t == "object" && (s = { ...s, ...t }), this.eventApi({
|
|
1543
1556
|
event: String(e),
|
|
1544
|
-
$insert_id:
|
|
1545
|
-
$time:
|
|
1557
|
+
$insert_id: N(),
|
|
1558
|
+
$time: k(),
|
|
1546
1559
|
distinct_id: this.distinctId,
|
|
1547
1560
|
properties: s
|
|
1548
1561
|
})) : o({
|
|
@@ -1556,16 +1569,16 @@ class le {
|
|
|
1556
1569
|
*/
|
|
1557
1570
|
async reset(e) {
|
|
1558
1571
|
var s, r;
|
|
1559
|
-
return (e == null ? void 0 : e.unsubscribePush) !== !1 && (await ((s = this.webpush) == null ? void 0 : s.removePushSubscription()),
|
|
1572
|
+
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
1573
|
}
|
|
1561
1574
|
}
|
|
1562
1575
|
export {
|
|
1563
1576
|
_ as ApiResponseStatus,
|
|
1564
|
-
|
|
1577
|
+
C as ChannelLevelPreferenceOptions,
|
|
1565
1578
|
d as ERROR_TYPE,
|
|
1566
|
-
|
|
1579
|
+
ae as Feed,
|
|
1567
1580
|
p as PreferenceOptions,
|
|
1568
1581
|
n as RESPONSE_STATUS,
|
|
1569
|
-
|
|
1582
|
+
pe as SuprSend
|
|
1570
1583
|
};
|
|
1571
1584
|
//# sourceMappingURL=index.js.map
|