@suprsend/web-sdk 4.0.1 → 4.0.3
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 +159 -140
- package/dist/es/index.js.map +1 -1
- package/package.json +1 -1
package/dist/es/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
var W = Object.defineProperty;
|
|
2
2
|
var H = (a, e, t) => e in a ? W(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
|
|
3
3
|
var f = (a, e, t) => H(a, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
-
import
|
|
5
|
-
import
|
|
4
|
+
import F from "mitt";
|
|
5
|
+
import M 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 || {}), w = /* @__PURE__ */ ((a) => (a.ALL = "all", a.REQUIRED = "required", a))(w || {}),
|
|
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
9
|
function C() {
|
|
10
10
|
let a = (/* @__PURE__ */ new Date()).getTime();
|
|
11
11
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
|
|
@@ -37,7 +37,7 @@ function J(a, e) {
|
|
|
37
37
|
t = setTimeout(() => r(a(...s)), e);
|
|
38
38
|
}));
|
|
39
39
|
}
|
|
40
|
-
function
|
|
40
|
+
function V(a, e) {
|
|
41
41
|
const t = {};
|
|
42
42
|
return (...s) => {
|
|
43
43
|
const [r] = s, i = s.slice(1);
|
|
@@ -54,7 +54,7 @@ function o(a) {
|
|
|
54
54
|
function A() {
|
|
55
55
|
return typeof window < "u";
|
|
56
56
|
}
|
|
57
|
-
function
|
|
57
|
+
function x(a, e) {
|
|
58
58
|
A() && (typeof e == "object" && (e = JSON.stringify(e)), localStorage.setItem(a, e));
|
|
59
59
|
}
|
|
60
60
|
function L(a) {
|
|
@@ -72,7 +72,7 @@ function Z(a) {
|
|
|
72
72
|
}
|
|
73
73
|
async function X(a) {
|
|
74
74
|
const t = new TextEncoder().encode(a), s = await crypto.subtle.digest("SHA-256", t);
|
|
75
|
-
return Array.from(new Uint8Array(s)).map((
|
|
75
|
+
return Array.from(new Uint8Array(s)).map((c) => c.toString(16).padStart(2, "0")).join("");
|
|
76
76
|
}
|
|
77
77
|
class N {
|
|
78
78
|
constructor(e) {
|
|
@@ -123,12 +123,12 @@ class N {
|
|
|
123
123
|
if (!this.config.distinctId)
|
|
124
124
|
return o({
|
|
125
125
|
status: n.ERROR,
|
|
126
|
-
errorType:
|
|
126
|
+
errorType: d.VALIDATION_ERROR,
|
|
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 =
|
|
131
|
-
if (
|
|
130
|
+
const i = M(this.config.userToken), c = (i.exp || 0) * 1e3, u = Date.now();
|
|
131
|
+
if (c <= u)
|
|
132
132
|
try {
|
|
133
133
|
const h = await this.config.authenticateOptions.refreshUserToken(
|
|
134
134
|
this.config.userToken,
|
|
@@ -143,20 +143,20 @@ class N {
|
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
try {
|
|
146
|
-
const i = await this.requestApiInstance(e),
|
|
146
|
+
const i = await this.requestApiInstance(e), c = await i.json(), u = (c == null ? void 0 : c.status) || (i.ok ? n.SUCCESS : n.ERROR);
|
|
147
147
|
return o({
|
|
148
148
|
status: u,
|
|
149
|
-
body:
|
|
149
|
+
body: c,
|
|
150
150
|
statusCode: i.status,
|
|
151
|
-
errorMessage: (s =
|
|
152
|
-
errorType: (r =
|
|
151
|
+
errorMessage: (s = c == null ? void 0 : c.error) == null ? void 0 : s.message,
|
|
152
|
+
errorType: (r = c == null ? void 0 : c.error) == null ? void 0 : r.type
|
|
153
153
|
});
|
|
154
154
|
} catch (i) {
|
|
155
155
|
return console.error(i), o({
|
|
156
156
|
status: n.ERROR,
|
|
157
157
|
statusCode: 500,
|
|
158
158
|
errorMessage: (i == null ? void 0 : i.message) || "network error",
|
|
159
|
-
errorType:
|
|
159
|
+
errorType: d.NETWORK_ERROR
|
|
160
160
|
});
|
|
161
161
|
}
|
|
162
162
|
}
|
|
@@ -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 = V(
|
|
173
173
|
this._updateCategoryPreferences.bind(this),
|
|
174
174
|
this.debounceTime
|
|
175
|
-
), this.debouncedUpdateChannelPreferences =
|
|
175
|
+
), this.debouncedUpdateChannelPreferences = V(
|
|
176
176
|
this._updateChannelPreferences.bind(this),
|
|
177
177
|
this.debounceTime
|
|
178
178
|
);
|
|
@@ -232,7 +232,7 @@ class Y {
|
|
|
232
232
|
if (!e)
|
|
233
233
|
return o({
|
|
234
234
|
status: n.ERROR,
|
|
235
|
-
errorType:
|
|
235
|
+
errorType: d.VALIDATION_ERROR,
|
|
236
236
|
errorMessage: "Category parameter is missing"
|
|
237
237
|
});
|
|
238
238
|
const s = {
|
|
@@ -249,16 +249,16 @@ class Y {
|
|
|
249
249
|
return await this.config.client().request({ type: "get", url: e });
|
|
250
250
|
}
|
|
251
251
|
async _updateCategoryPreferences(e, t, s, r) {
|
|
252
|
-
const i = this.getUrl(`category/${e}`, r),
|
|
252
|
+
const i = this.getUrl(`category/${e}`, r), c = await this.config.client().request({
|
|
253
253
|
type: "patch",
|
|
254
254
|
url: i,
|
|
255
255
|
payload: t
|
|
256
256
|
});
|
|
257
|
-
return
|
|
257
|
+
return c != null && c.error ? this.config.emitter.emit("preferences_error", c) : (Object.assign(s, c.body), this.config.emitter.emit("preferences_updated", {
|
|
258
258
|
status: n.SUCCESS,
|
|
259
259
|
statusCode: 200,
|
|
260
260
|
body: this.data
|
|
261
|
-
})),
|
|
261
|
+
})), c;
|
|
262
262
|
}
|
|
263
263
|
async _updateChannelPreferences(e) {
|
|
264
264
|
const t = this.getUrl("channel_preference"), s = await this.config.client().request({
|
|
@@ -282,45 +282,45 @@ class Y {
|
|
|
282
282
|
))
|
|
283
283
|
return o({
|
|
284
284
|
status: n.ERROR,
|
|
285
|
-
errorType:
|
|
285
|
+
errorType: d.VALIDATION_ERROR,
|
|
286
286
|
errorMessage: e ? "Preference parameter is invalid" : "Category parameter is missing"
|
|
287
287
|
});
|
|
288
288
|
if (!this.data)
|
|
289
289
|
return o({
|
|
290
290
|
status: n.ERROR,
|
|
291
|
-
errorType:
|
|
291
|
+
errorType: d.VALIDATION_ERROR,
|
|
292
292
|
errorMessage: "Call getPreferences method before performing action"
|
|
293
293
|
});
|
|
294
294
|
if (!this.data.sections)
|
|
295
295
|
return o({
|
|
296
296
|
status: n.ERROR,
|
|
297
|
-
errorType:
|
|
297
|
+
errorType: d.VALIDATION_ERROR,
|
|
298
298
|
errorMessage: "Sections doesn't exist"
|
|
299
299
|
});
|
|
300
300
|
let r = null, i = !1;
|
|
301
301
|
for (const R of this.data.sections) {
|
|
302
|
-
let
|
|
302
|
+
let O = !1;
|
|
303
303
|
if (R.subcategories) {
|
|
304
|
-
for (const
|
|
305
|
-
if (
|
|
306
|
-
if (r =
|
|
307
|
-
if (
|
|
308
|
-
|
|
304
|
+
for (const g of R.subcategories)
|
|
305
|
+
if (g.category === e)
|
|
306
|
+
if (r = g, g.is_editable) {
|
|
307
|
+
if (g.preference !== t) {
|
|
308
|
+
g.preference = t, i = !0, O = !0;
|
|
309
309
|
break;
|
|
310
310
|
}
|
|
311
311
|
} else
|
|
312
312
|
return o({
|
|
313
313
|
status: n.ERROR,
|
|
314
|
-
errorType:
|
|
314
|
+
errorType: d.VALIDATION_ERROR,
|
|
315
315
|
errorMessage: "Category preference is not editable"
|
|
316
316
|
});
|
|
317
|
-
if (
|
|
317
|
+
if (O) break;
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
320
|
if (!r)
|
|
321
321
|
return o({
|
|
322
322
|
status: n.ERROR,
|
|
323
|
-
errorType:
|
|
323
|
+
errorType: d.VALIDATION_ERROR,
|
|
324
324
|
errorMessage: "Category not found"
|
|
325
325
|
});
|
|
326
326
|
if (!i)
|
|
@@ -328,15 +328,15 @@ class Y {
|
|
|
328
328
|
status: n.SUCCESS,
|
|
329
329
|
body: this.data
|
|
330
330
|
});
|
|
331
|
-
const
|
|
331
|
+
const c = [];
|
|
332
332
|
(h = r == null ? void 0 : r.channels) == null || h.forEach((R) => {
|
|
333
|
-
R.preference === p.OPT_OUT &&
|
|
333
|
+
R.preference === p.OPT_OUT && c.push(R.channel);
|
|
334
334
|
});
|
|
335
335
|
let u = !0;
|
|
336
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);
|
|
337
337
|
const l = {
|
|
338
338
|
preference: r.preference,
|
|
339
|
-
opt_out_channels: u && t === p.OPT_IN ? null :
|
|
339
|
+
opt_out_channels: u && t === p.OPT_IN ? null : c
|
|
340
340
|
};
|
|
341
341
|
return this.debouncedUpdateCategoryPreferences(
|
|
342
342
|
e,
|
|
@@ -357,11 +357,11 @@ class Y {
|
|
|
357
357
|
* Used to update user's category level channel preference.
|
|
358
358
|
*/
|
|
359
359
|
async updateChannelPreferenceInCategory(e, t, s, r) {
|
|
360
|
-
var T, R,
|
|
360
|
+
var T, R, O, g;
|
|
361
361
|
if (!e || !s)
|
|
362
362
|
return o({
|
|
363
363
|
status: n.ERROR,
|
|
364
|
-
errorType:
|
|
364
|
+
errorType: d.VALIDATION_ERROR,
|
|
365
365
|
errorMessage: e ? "Category parameter is missing" : "Channel parameter is missing"
|
|
366
366
|
});
|
|
367
367
|
if (![p.OPT_IN, p.OPT_OUT].includes(
|
|
@@ -369,22 +369,22 @@ class Y {
|
|
|
369
369
|
))
|
|
370
370
|
return o({
|
|
371
371
|
status: n.ERROR,
|
|
372
|
-
errorType:
|
|
372
|
+
errorType: d.VALIDATION_ERROR,
|
|
373
373
|
errorMessage: "Preference parameter is invalid"
|
|
374
374
|
});
|
|
375
375
|
if (!this.data)
|
|
376
376
|
return o({
|
|
377
377
|
status: n.ERROR,
|
|
378
|
-
errorType:
|
|
378
|
+
errorType: d.VALIDATION_ERROR,
|
|
379
379
|
errorMessage: "Call getPreferences method before performing action"
|
|
380
380
|
});
|
|
381
381
|
if (!this.data.sections)
|
|
382
382
|
return o({
|
|
383
383
|
status: n.ERROR,
|
|
384
|
-
errorType:
|
|
384
|
+
errorType: d.VALIDATION_ERROR,
|
|
385
385
|
errorMessage: "Sections doesn't exist"
|
|
386
386
|
});
|
|
387
|
-
let i = null,
|
|
387
|
+
let i = null, c = null, u = !1;
|
|
388
388
|
for (const y of this.data.sections) {
|
|
389
389
|
let b = !1;
|
|
390
390
|
if (y.subcategories) {
|
|
@@ -393,7 +393,7 @@ class Y {
|
|
|
393
393
|
if (i = m, !m.channels) continue;
|
|
394
394
|
for (const E of m.channels)
|
|
395
395
|
if (E.channel === e)
|
|
396
|
-
if (
|
|
396
|
+
if (c = E, E.is_editable) {
|
|
397
397
|
if (E.preference !== t) {
|
|
398
398
|
E.preference = t, t === p.OPT_IN && (m.preference = p.OPT_IN), u = !0, b = !0;
|
|
399
399
|
break;
|
|
@@ -401,7 +401,7 @@ class Y {
|
|
|
401
401
|
} else
|
|
402
402
|
return o({
|
|
403
403
|
status: n.ERROR,
|
|
404
|
-
errorType:
|
|
404
|
+
errorType: d.VALIDATION_ERROR,
|
|
405
405
|
errorMessage: "Channel preference is not editable"
|
|
406
406
|
});
|
|
407
407
|
}
|
|
@@ -413,13 +413,13 @@ class Y {
|
|
|
413
413
|
if (!i)
|
|
414
414
|
return o({
|
|
415
415
|
status: n.ERROR,
|
|
416
|
-
errorType:
|
|
416
|
+
errorType: d.VALIDATION_ERROR,
|
|
417
417
|
errorMessage: "Category not found"
|
|
418
418
|
});
|
|
419
|
-
if (!
|
|
419
|
+
if (!c)
|
|
420
420
|
return o({
|
|
421
421
|
status: n.ERROR,
|
|
422
|
-
errorType:
|
|
422
|
+
errorType: d.VALIDATION_ERROR,
|
|
423
423
|
errorMessage: "Category's channel not found"
|
|
424
424
|
});
|
|
425
425
|
if (!u)
|
|
@@ -443,9 +443,9 @@ class Y {
|
|
|
443
443
|
v,
|
|
444
444
|
i,
|
|
445
445
|
{
|
|
446
|
-
tenant_id: (r == null ? void 0 : r.tenantId) || ((
|
|
446
|
+
tenant_id: (r == null ? void 0 : r.tenantId) || ((O = this.preferenceArgs) == null ? void 0 : O.tenantId),
|
|
447
447
|
show_opt_out_channels: h,
|
|
448
|
-
tags: (r == null ? void 0 : r.tags) || ((
|
|
448
|
+
tags: (r == null ? void 0 : r.tags) || ((g = this.preferenceArgs) == null ? void 0 : g.tags)
|
|
449
449
|
}
|
|
450
450
|
), o({
|
|
451
451
|
status: n.SUCCESS,
|
|
@@ -462,26 +462,26 @@ class Y {
|
|
|
462
462
|
].includes(t))
|
|
463
463
|
return o({
|
|
464
464
|
status: n.ERROR,
|
|
465
|
-
errorType:
|
|
465
|
+
errorType: d.VALIDATION_ERROR,
|
|
466
466
|
errorMessage: e ? "Preference parameter is invalid" : "Channel parameter is missing"
|
|
467
467
|
});
|
|
468
468
|
if (!this.data)
|
|
469
469
|
return o({
|
|
470
470
|
status: n.ERROR,
|
|
471
|
-
errorType:
|
|
471
|
+
errorType: d.VALIDATION_ERROR,
|
|
472
472
|
errorMessage: "Call getPreferences method before performing action"
|
|
473
473
|
});
|
|
474
474
|
if (!this.data.channel_preferences)
|
|
475
475
|
return o({
|
|
476
476
|
status: n.ERROR,
|
|
477
|
-
errorType:
|
|
477
|
+
errorType: d.VALIDATION_ERROR,
|
|
478
478
|
errorMessage: "Channel preferences doesn't exist"
|
|
479
479
|
});
|
|
480
480
|
let s = null, r = !1;
|
|
481
481
|
const i = t === w.REQUIRED;
|
|
482
|
-
for (const
|
|
483
|
-
if (
|
|
484
|
-
|
|
482
|
+
for (const c of this.data.channel_preferences)
|
|
483
|
+
if (c.channel === e && (s = c, c.is_restricted !== i)) {
|
|
484
|
+
c.is_restricted = i, r = !0;
|
|
485
485
|
break;
|
|
486
486
|
}
|
|
487
487
|
return s ? r ? (this.debouncedUpdateChannelPreferences(s.channel, {
|
|
@@ -494,12 +494,12 @@ class Y {
|
|
|
494
494
|
body: this.data
|
|
495
495
|
}) : o({
|
|
496
496
|
status: n.ERROR,
|
|
497
|
-
errorType:
|
|
497
|
+
errorType: d.VALIDATION_ERROR,
|
|
498
498
|
errorMessage: "Channel data not found"
|
|
499
499
|
});
|
|
500
500
|
}
|
|
501
501
|
}
|
|
502
|
-
const
|
|
502
|
+
const $ = "ss_device_id";
|
|
503
503
|
class q {
|
|
504
504
|
constructor(e) {
|
|
505
505
|
f(this, "config");
|
|
@@ -520,14 +520,14 @@ class q {
|
|
|
520
520
|
}
|
|
521
521
|
validateObjData(e, t) {
|
|
522
522
|
const s = {}, r = (t == null ? void 0 : t.allowReservedKeys) || !1, i = (t == null ? void 0 : t.valueType) || "";
|
|
523
|
-
for (const
|
|
524
|
-
let u = e[
|
|
525
|
-
if (!(
|
|
526
|
-
if (!r && this.isReservedKey(
|
|
523
|
+
for (const c in e) {
|
|
524
|
+
let u = e[c];
|
|
525
|
+
if (!(c && u === void 0)) {
|
|
526
|
+
if (!r && this.isReservedKey(c)) {
|
|
527
527
|
console.warn("[SuprSend]: key cannot start with $ or ss_");
|
|
528
528
|
continue;
|
|
529
529
|
}
|
|
530
|
-
i === "number" ? u = Number(u) : i === "boolean" && (u = !!u), s[
|
|
530
|
+
i === "number" ? u = Number(u) : i === "boolean" && (u = !!u), s[c] = u;
|
|
531
531
|
}
|
|
532
532
|
}
|
|
533
533
|
return s;
|
|
@@ -560,13 +560,13 @@ class q {
|
|
|
560
560
|
if (!s)
|
|
561
561
|
return o({
|
|
562
562
|
status: n.ERROR,
|
|
563
|
-
errorType:
|
|
563
|
+
errorType: d.VALIDATION_ERROR,
|
|
564
564
|
errorMessage: "data provided is empty"
|
|
565
565
|
});
|
|
566
566
|
const r = this.validateObjData(s);
|
|
567
567
|
return I(r) ? o({
|
|
568
568
|
status: n.ERROR,
|
|
569
|
-
errorType:
|
|
569
|
+
errorType: d.VALIDATION_ERROR,
|
|
570
570
|
errorMessage: "data provided is empty"
|
|
571
571
|
}) : this.triggerUserEvent({ $set: r });
|
|
572
572
|
}
|
|
@@ -579,13 +579,13 @@ class q {
|
|
|
579
579
|
if (!s)
|
|
580
580
|
return o({
|
|
581
581
|
status: n.ERROR,
|
|
582
|
-
errorType:
|
|
582
|
+
errorType: d.VALIDATION_ERROR,
|
|
583
583
|
errorMessage: "data provided is empty"
|
|
584
584
|
});
|
|
585
585
|
const r = this.validateObjData(s);
|
|
586
586
|
return I(r) ? o({
|
|
587
587
|
status: n.ERROR,
|
|
588
|
-
errorType:
|
|
588
|
+
errorType: d.VALIDATION_ERROR,
|
|
589
589
|
errorMessage: "data provided is empty"
|
|
590
590
|
}) : this.triggerUserEvent({ $set_once: r });
|
|
591
591
|
}
|
|
@@ -598,13 +598,13 @@ class q {
|
|
|
598
598
|
if (!s)
|
|
599
599
|
return o({
|
|
600
600
|
status: n.ERROR,
|
|
601
|
-
errorType:
|
|
601
|
+
errorType: d.VALIDATION_ERROR,
|
|
602
602
|
errorMessage: "data provided is empty"
|
|
603
603
|
});
|
|
604
604
|
const r = this.validateObjData(s, { valueType: "number" });
|
|
605
605
|
return I(r) ? o({
|
|
606
606
|
status: n.ERROR,
|
|
607
|
-
errorType:
|
|
607
|
+
errorType: d.VALIDATION_ERROR,
|
|
608
608
|
errorMessage: "data provided is empty"
|
|
609
609
|
}) : this.triggerUserEvent({ $add: r });
|
|
610
610
|
}
|
|
@@ -617,13 +617,13 @@ class q {
|
|
|
617
617
|
if (!s)
|
|
618
618
|
return o({
|
|
619
619
|
status: n.ERROR,
|
|
620
|
-
errorType:
|
|
620
|
+
errorType: d.VALIDATION_ERROR,
|
|
621
621
|
errorMessage: "data provided is empty"
|
|
622
622
|
});
|
|
623
623
|
const r = this.validateObjData(s);
|
|
624
624
|
return I(r) ? o({
|
|
625
625
|
status: n.ERROR,
|
|
626
|
-
errorType:
|
|
626
|
+
errorType: d.VALIDATION_ERROR,
|
|
627
627
|
errorMessage: "data provided is empty"
|
|
628
628
|
}) : this.triggerUserEvent({ $append: r });
|
|
629
629
|
}
|
|
@@ -636,13 +636,13 @@ class q {
|
|
|
636
636
|
if (!s)
|
|
637
637
|
return o({
|
|
638
638
|
status: n.ERROR,
|
|
639
|
-
errorType:
|
|
639
|
+
errorType: d.VALIDATION_ERROR,
|
|
640
640
|
errorMessage: "data provided is empty"
|
|
641
641
|
});
|
|
642
642
|
const r = this.validateObjData(s);
|
|
643
643
|
return I(r) ? o({
|
|
644
644
|
status: n.ERROR,
|
|
645
|
-
errorType:
|
|
645
|
+
errorType: d.VALIDATION_ERROR,
|
|
646
646
|
errorMessage: "data provided is empty"
|
|
647
647
|
}) : this.triggerUserEvent({ $remove: r });
|
|
648
648
|
}
|
|
@@ -654,13 +654,13 @@ class q {
|
|
|
654
654
|
if (!t)
|
|
655
655
|
return o({
|
|
656
656
|
status: n.ERROR,
|
|
657
|
-
errorType:
|
|
657
|
+
errorType: d.VALIDATION_ERROR,
|
|
658
658
|
errorMessage: "data provided is empty"
|
|
659
659
|
});
|
|
660
660
|
const s = this.validateArrayData(t);
|
|
661
661
|
return Q(s) ? o({
|
|
662
662
|
status: n.ERROR,
|
|
663
|
-
errorType:
|
|
663
|
+
errorType: d.VALIDATION_ERROR,
|
|
664
664
|
errorMessage: "data provided is empty"
|
|
665
665
|
}) : this.triggerUserEvent({ $unset: s });
|
|
666
666
|
}
|
|
@@ -670,7 +670,7 @@ class q {
|
|
|
670
670
|
if (!s)
|
|
671
671
|
return o({
|
|
672
672
|
status: n.ERROR,
|
|
673
|
-
errorType:
|
|
673
|
+
errorType: d.VALIDATION_ERROR,
|
|
674
674
|
errorMessage: "data provided is empty"
|
|
675
675
|
});
|
|
676
676
|
const r = this.validateObjData(s, {
|
|
@@ -678,7 +678,7 @@ class q {
|
|
|
678
678
|
});
|
|
679
679
|
return I(r) ? o({
|
|
680
680
|
status: n.ERROR,
|
|
681
|
-
errorType:
|
|
681
|
+
errorType: d.VALIDATION_ERROR,
|
|
682
682
|
errorMessage: "data provided is empty"
|
|
683
683
|
}) : this.triggerUserEvent({ $append: r });
|
|
684
684
|
}
|
|
@@ -688,7 +688,7 @@ class q {
|
|
|
688
688
|
if (!s)
|
|
689
689
|
return o({
|
|
690
690
|
status: n.ERROR,
|
|
691
|
-
errorType:
|
|
691
|
+
errorType: d.VALIDATION_ERROR,
|
|
692
692
|
errorMessage: "data provided is empty"
|
|
693
693
|
});
|
|
694
694
|
const r = this.validateObjData(s, {
|
|
@@ -696,7 +696,7 @@ class q {
|
|
|
696
696
|
});
|
|
697
697
|
return I(r) ? o({
|
|
698
698
|
status: n.ERROR,
|
|
699
|
-
errorType:
|
|
699
|
+
errorType: d.VALIDATION_ERROR,
|
|
700
700
|
errorMessage: "data provided is empty"
|
|
701
701
|
}) : this.triggerUserEvent({ $remove: r });
|
|
702
702
|
}
|
|
@@ -705,7 +705,7 @@ class q {
|
|
|
705
705
|
if (!s)
|
|
706
706
|
return o({
|
|
707
707
|
status: n.ERROR,
|
|
708
|
-
errorType:
|
|
708
|
+
errorType: d.VALIDATION_ERROR,
|
|
709
709
|
errorMessage: "data provided is empty"
|
|
710
710
|
});
|
|
711
711
|
const r = this.validateObjData(s, {
|
|
@@ -713,7 +713,7 @@ class q {
|
|
|
713
713
|
});
|
|
714
714
|
return I(r) ? o({
|
|
715
715
|
status: n.ERROR,
|
|
716
|
-
errorType:
|
|
716
|
+
errorType: d.VALIDATION_ERROR,
|
|
717
717
|
errorMessage: "data provided is empty"
|
|
718
718
|
}) : this.triggerUserEvent({ $set: r });
|
|
719
719
|
}
|
|
@@ -726,14 +726,14 @@ class q {
|
|
|
726
726
|
async addEmail(e) {
|
|
727
727
|
return this.validateEmail(e) ? this.appendInternal({ $email: e }) : o({
|
|
728
728
|
status: n.ERROR,
|
|
729
|
-
errorType:
|
|
729
|
+
errorType: d.VALIDATION_ERROR,
|
|
730
730
|
errorMessage: "provided email is invalid"
|
|
731
731
|
});
|
|
732
732
|
}
|
|
733
733
|
async removeEmail(e) {
|
|
734
734
|
return this.validateEmail(e) ? this.removeInternal({ $email: e }) : o({
|
|
735
735
|
status: n.ERROR,
|
|
736
|
-
errorType:
|
|
736
|
+
errorType: d.VALIDATION_ERROR,
|
|
737
737
|
errorMessage: "provided email is invalid"
|
|
738
738
|
});
|
|
739
739
|
}
|
|
@@ -743,7 +743,7 @@ class q {
|
|
|
743
743
|
async addSms(e) {
|
|
744
744
|
return this.validateMobile(e) ? this.appendInternal({ $sms: e }) : o({
|
|
745
745
|
status: n.ERROR,
|
|
746
|
-
errorType:
|
|
746
|
+
errorType: d.VALIDATION_ERROR,
|
|
747
747
|
errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
|
|
748
748
|
});
|
|
749
749
|
}
|
|
@@ -753,7 +753,7 @@ class q {
|
|
|
753
753
|
async removeSms(e) {
|
|
754
754
|
return this.validateMobile(e) ? this.removeInternal({ $sms: e }) : o({
|
|
755
755
|
status: n.ERROR,
|
|
756
|
-
errorType:
|
|
756
|
+
errorType: d.VALIDATION_ERROR,
|
|
757
757
|
errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
|
|
758
758
|
});
|
|
759
759
|
}
|
|
@@ -763,7 +763,7 @@ class q {
|
|
|
763
763
|
async addWhatsapp(e) {
|
|
764
764
|
return this.validateMobile(e) ? this.appendInternal({ $whatsapp: e }) : o({
|
|
765
765
|
status: n.ERROR,
|
|
766
|
-
errorType:
|
|
766
|
+
errorType: d.VALIDATION_ERROR,
|
|
767
767
|
errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
|
|
768
768
|
});
|
|
769
769
|
}
|
|
@@ -773,19 +773,19 @@ class q {
|
|
|
773
773
|
async removeWhatsapp(e) {
|
|
774
774
|
return this.validateMobile(e) ? this.removeInternal({ $whatsapp: e }) : o({
|
|
775
775
|
status: n.ERROR,
|
|
776
|
-
errorType:
|
|
776
|
+
errorType: d.VALIDATION_ERROR,
|
|
777
777
|
errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
|
|
778
778
|
});
|
|
779
779
|
}
|
|
780
780
|
getDeviceId() {
|
|
781
|
-
let e = L(
|
|
782
|
-
return e || (e = C(),
|
|
781
|
+
let e = L($);
|
|
782
|
+
return e || (e = C(), x($, e)), e;
|
|
783
783
|
}
|
|
784
784
|
async addWebPush(e) {
|
|
785
785
|
if (typeof e != "object")
|
|
786
786
|
return o({
|
|
787
787
|
status: n.ERROR,
|
|
788
|
-
errorType:
|
|
788
|
+
errorType: d.VALIDATION_ERROR,
|
|
789
789
|
errorMessage: "provided push subscription is invalid, must be an object"
|
|
790
790
|
});
|
|
791
791
|
const t = this.getDeviceId();
|
|
@@ -799,7 +799,7 @@ class q {
|
|
|
799
799
|
if (typeof e != "object")
|
|
800
800
|
return o({
|
|
801
801
|
status: n.ERROR,
|
|
802
|
-
errorType:
|
|
802
|
+
errorType: d.VALIDATION_ERROR,
|
|
803
803
|
errorMessage: "provided push subscription is invalid, must be an object"
|
|
804
804
|
});
|
|
805
805
|
const t = this.getDeviceId();
|
|
@@ -812,28 +812,28 @@ class q {
|
|
|
812
812
|
async addSlack(e) {
|
|
813
813
|
return typeof e != "object" ? o({
|
|
814
814
|
status: n.ERROR,
|
|
815
|
-
errorType:
|
|
815
|
+
errorType: d.VALIDATION_ERROR,
|
|
816
816
|
errorMessage: "provided slack data is invalid, must be an object"
|
|
817
817
|
}) : this.appendInternal({ $slack: e });
|
|
818
818
|
}
|
|
819
819
|
async removeSlack(e) {
|
|
820
820
|
return typeof e != "object" ? o({
|
|
821
821
|
status: n.ERROR,
|
|
822
|
-
errorType:
|
|
822
|
+
errorType: d.VALIDATION_ERROR,
|
|
823
823
|
errorMessage: "provided slack data is invalid, must be an object"
|
|
824
824
|
}) : this.removeInternal({ $slack: e });
|
|
825
825
|
}
|
|
826
826
|
async addMSTeams(e) {
|
|
827
827
|
return typeof e != "object" ? o({
|
|
828
828
|
status: n.ERROR,
|
|
829
|
-
errorType:
|
|
829
|
+
errorType: d.VALIDATION_ERROR,
|
|
830
830
|
errorMessage: "provided ms_teams data is invalid, must be object"
|
|
831
831
|
}) : this.appendInternal({ $ms_teams: e });
|
|
832
832
|
}
|
|
833
833
|
async removeMSTeams(e) {
|
|
834
834
|
return typeof e != "object" ? o({
|
|
835
835
|
status: n.ERROR,
|
|
836
|
-
errorType:
|
|
836
|
+
errorType: d.VALIDATION_ERROR,
|
|
837
837
|
errorMessage: "provided ms_teams data is invalid, must be object"
|
|
838
838
|
}) : this.removeInternal({ $ms_teams: e });
|
|
839
839
|
}
|
|
@@ -844,7 +844,7 @@ class q {
|
|
|
844
844
|
async setPreferredLanguage(e) {
|
|
845
845
|
return typeof e != "string" ? o({
|
|
846
846
|
status: n.ERROR,
|
|
847
|
-
errorType:
|
|
847
|
+
errorType: d.VALIDATION_ERROR,
|
|
848
848
|
errorMessage: "provided language is invalid, must be string"
|
|
849
849
|
}) : this.setInternal({ $preferred_language: e });
|
|
850
850
|
}
|
|
@@ -854,7 +854,7 @@ class q {
|
|
|
854
854
|
async setTimezone(e) {
|
|
855
855
|
return typeof e != "string" ? o({
|
|
856
856
|
status: n.ERROR,
|
|
857
|
-
errorType:
|
|
857
|
+
errorType: d.VALIDATION_ERROR,
|
|
858
858
|
errorMessage: "provided timezone is invalid, must be string"
|
|
859
859
|
}) : this.setInternal({ $timezone: e });
|
|
860
860
|
}
|
|
@@ -883,7 +883,7 @@ class ee {
|
|
|
883
883
|
if (s) {
|
|
884
884
|
if (s === L(k))
|
|
885
885
|
return o({ status: n.SUCCESS });
|
|
886
|
-
|
|
886
|
+
x(k, s);
|
|
887
887
|
}
|
|
888
888
|
return await this.config.user.addWebPush(e);
|
|
889
889
|
}
|
|
@@ -892,7 +892,7 @@ class ee {
|
|
|
892
892
|
if (await navigator.serviceWorker.register(`/${this.config.swFileName}`), await Notification.requestPermission() !== "granted")
|
|
893
893
|
return console.warn("[SuprSend]: Notification permission isnt granted"), o({
|
|
894
894
|
status: n.ERROR,
|
|
895
|
-
errorType:
|
|
895
|
+
errorType: d.PERMISSION_DENIED,
|
|
896
896
|
errorMessage: "Notification permission isn't granted"
|
|
897
897
|
});
|
|
898
898
|
const t = await navigator.serviceWorker.ready, s = await t.pushManager.getSubscription();
|
|
@@ -903,7 +903,7 @@ class ee {
|
|
|
903
903
|
"[SuprSend]: Vapid key is missing. Add it while creating SuprSend instance"
|
|
904
904
|
), o({
|
|
905
905
|
status: n.ERROR,
|
|
906
|
-
errorType:
|
|
906
|
+
errorType: d.VALIDATION_ERROR,
|
|
907
907
|
errorMessage: "Vapid key is missing. Add it while creating SuprSend instance"
|
|
908
908
|
});
|
|
909
909
|
const r = await t.pushManager.subscribe({
|
|
@@ -914,7 +914,7 @@ class ee {
|
|
|
914
914
|
} catch (e) {
|
|
915
915
|
return console.warn("SuprSend: Error getting push subscription", e), o({
|
|
916
916
|
status: n.ERROR,
|
|
917
|
-
errorType:
|
|
917
|
+
errorType: d.UNKNOWN_ERROR,
|
|
918
918
|
errorMessage: (e == null ? void 0 : e.message) || "Unknown error occured while registering for push"
|
|
919
919
|
});
|
|
920
920
|
}
|
|
@@ -928,7 +928,7 @@ class ee {
|
|
|
928
928
|
async registerPush() {
|
|
929
929
|
return A() && "serviceWorker" in navigator && "PushManager" in window ? this.handleRegisterPush() : (console.warn("[SuprSend]: Webpush isn't supported"), o({
|
|
930
930
|
status: n.ERROR,
|
|
931
|
-
errorType:
|
|
931
|
+
errorType: d.UNSUPPORTED_ACTION,
|
|
932
932
|
errorMessage: "Webpush isn't supported"
|
|
933
933
|
}));
|
|
934
934
|
}
|
|
@@ -1006,7 +1006,7 @@ class ne {
|
|
|
1006
1006
|
f(this, "store");
|
|
1007
1007
|
f(this, "socket");
|
|
1008
1008
|
f(this, "expiryTimerId");
|
|
1009
|
-
f(this, "emitter",
|
|
1009
|
+
f(this, "emitter", F());
|
|
1010
1010
|
this.config = e, this.setOptions(t), this.store = this.createFeedStore();
|
|
1011
1011
|
}
|
|
1012
1012
|
setOptions(e) {
|
|
@@ -1028,12 +1028,12 @@ class ne {
|
|
|
1028
1028
|
return;
|
|
1029
1029
|
}
|
|
1030
1030
|
const r = s == null ? void 0 : s.query;
|
|
1031
|
-
let i,
|
|
1032
|
-
typeof (r == null ? void 0 : r.read) == "boolean" && (i = r.read), typeof (r == null ? void 0 : r.archived) == "boolean" && (
|
|
1031
|
+
let i, c, u = [], l = [];
|
|
1032
|
+
typeof (r == null ? void 0 : r.read) == "boolean" && (i = r.read), typeof (r == null ? void 0 : r.archived) == "boolean" && (c = r.archived), typeof (r == null ? void 0 : r.tags) == "string" ? u = [r.tags] : Array.isArray(r == null ? void 0 : r.tags) && (u = r == null ? void 0 : r.tags.filter((h) => typeof h == "string")), typeof (r == null ? void 0 : r.categories) == "string" ? l = [r.categories] : Array.isArray(r == null ? void 0 : r.categories) && (l = r == null ? void 0 : r.categories.filter((h) => typeof h == "string")), t.push({
|
|
1033
1033
|
storeId: s.storeId,
|
|
1034
1034
|
label: s.label || s.storeId,
|
|
1035
1035
|
query: {
|
|
1036
|
-
archived:
|
|
1036
|
+
archived: c,
|
|
1037
1037
|
read: i,
|
|
1038
1038
|
tags: u,
|
|
1039
1039
|
categories: l
|
|
@@ -1051,7 +1051,27 @@ class ne {
|
|
|
1051
1051
|
});
|
|
1052
1052
|
}
|
|
1053
1053
|
initializeSocketEvents() {
|
|
1054
|
-
this.socket.on(
|
|
1054
|
+
this.socket.on("connect_error", async (e) => {
|
|
1055
|
+
var t;
|
|
1056
|
+
if (e.message === "Authentication Error: wrong auth token" && ((t = this.config.authenticateOptions) != null && t.refreshUserToken) && this.config.userToken) {
|
|
1057
|
+
const s = M(this.config.userToken), r = (s.exp || 0) * 1e3, i = Date.now();
|
|
1058
|
+
if (r <= i)
|
|
1059
|
+
try {
|
|
1060
|
+
const u = await this.config.authenticateOptions.refreshUserToken(
|
|
1061
|
+
this.config.userToken,
|
|
1062
|
+
s
|
|
1063
|
+
);
|
|
1064
|
+
u && typeof u == "string" && (await this.config.identify(
|
|
1065
|
+
this.config.distinctId,
|
|
1066
|
+
u,
|
|
1067
|
+
this.config.authenticateOptions
|
|
1068
|
+
), this.socket.auth["x-ss-signature"] = u, setTimeout(() => {
|
|
1069
|
+
this.socket.connect();
|
|
1070
|
+
}, 1e3));
|
|
1071
|
+
} catch {
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
}), this.socket.on(
|
|
1055
1075
|
"new_notification",
|
|
1056
1076
|
this.handleNewNotificationSocketEvent.bind(this)
|
|
1057
1077
|
), this.socket.on(
|
|
@@ -1075,18 +1095,18 @@ class ne {
|
|
|
1075
1095
|
return;
|
|
1076
1096
|
const s = t.body, r = this.store.getState();
|
|
1077
1097
|
let i = !1;
|
|
1078
|
-
const
|
|
1098
|
+
const c = { ...r.meta };
|
|
1079
1099
|
this.notificationBelongToStore(s, r.store) && (i = !0, this.store.setState({
|
|
1080
1100
|
notifications: this.orderNotificationsBasedOnPinFlag(
|
|
1081
1101
|
s,
|
|
1082
1102
|
r.notifications
|
|
1083
1103
|
)
|
|
1084
1104
|
})), (l = (u = this.feedOptions.stores) == null ? void 0 : u.map) == null || l.call(u, (h) => {
|
|
1085
|
-
this.notificationBelongToStore(s, h) && (i = !0,
|
|
1105
|
+
this.notificationBelongToStore(s, h) && (i = !0, c[h.storeId] = (r.meta[h.storeId] || 0) + 1);
|
|
1086
1106
|
}), this.store.setState({
|
|
1087
1107
|
meta: {
|
|
1088
|
-
...
|
|
1089
|
-
badge: i ?
|
|
1108
|
+
...c,
|
|
1109
|
+
badge: i ? c.badge + 1 : c.badge
|
|
1090
1110
|
}
|
|
1091
1111
|
}), i && this.emitter.emit("feed.new_notification", s), this.emitter.emit("feed.store_update", this.data);
|
|
1092
1112
|
}
|
|
@@ -1100,13 +1120,13 @@ class ne {
|
|
|
1100
1120
|
if (t[0].status !== "fulfilled") return;
|
|
1101
1121
|
const r = t[0].value;
|
|
1102
1122
|
if (r.status === n.ERROR) return;
|
|
1103
|
-
const i = r.body,
|
|
1123
|
+
const i = r.body, c = (l = s.notifications) == null ? void 0 : l.some(
|
|
1104
1124
|
(h) => h.n_id === i.n_id
|
|
1105
1125
|
);
|
|
1106
1126
|
this.notificationBelongToStore(
|
|
1107
1127
|
i,
|
|
1108
1128
|
s.store
|
|
1109
|
-
) ?
|
|
1129
|
+
) ? c ? this.store.setState({
|
|
1110
1130
|
notifications: s.notifications.map((h) => h.n_id === i.n_id ? i : h)
|
|
1111
1131
|
}) : this.store.setState({
|
|
1112
1132
|
notifications: this.orderNotificationsBasedOnPinFlag(
|
|
@@ -1134,12 +1154,12 @@ class ne {
|
|
|
1134
1154
|
}), this.emitter.emit("feed.store_update", this.data);
|
|
1135
1155
|
}
|
|
1136
1156
|
notificationBelongToStore(e, t) {
|
|
1137
|
-
var
|
|
1138
|
-
const s = !!e.read_on, r = e.archived, i = e.tags,
|
|
1139
|
-
let R = !1,
|
|
1157
|
+
var g, y, b, m;
|
|
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 = (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;
|
|
1159
|
+
let R = !1, O = !1;
|
|
1140
1160
|
return Array.isArray(h) && h.length > 0 ? h.forEach((E) => {
|
|
1141
1161
|
i != null && i.includes(E) && (R = !0);
|
|
1142
|
-
}) : R = !0, Array.isArray(S) && S.length > 0 ? S.includes(
|
|
1162
|
+
}) : R = !0, Array.isArray(S) && S.length > 0 ? S.includes(c) && (O = !0) : O = !0, v && R && O && T;
|
|
1143
1163
|
}
|
|
1144
1164
|
orderNotificationsBasedOnPinFlag(e, t) {
|
|
1145
1165
|
if (e.is_pinned)
|
|
@@ -1164,8 +1184,8 @@ class ne {
|
|
|
1164
1184
|
t && (this.store.setState({ notifications: s }), await this.fetchCount(), this.emitter.emit("feed.store_update", this.data));
|
|
1165
1185
|
}
|
|
1166
1186
|
getUrl(e, t) {
|
|
1167
|
-
var
|
|
1168
|
-
const s = `${(
|
|
1187
|
+
var c;
|
|
1188
|
+
const s = `${(c = this.feedOptions.host) == null ? void 0 : c.apiHost}/v1/feed/${e}`, r = this.validateQueryParams(t), i = new URLSearchParams(
|
|
1169
1189
|
r
|
|
1170
1190
|
).toString();
|
|
1171
1191
|
return i ? `${s}?${i}` : s;
|
|
@@ -1189,12 +1209,12 @@ class ne {
|
|
|
1189
1209
|
return e == null ? void 0 : e.map((s) => this.storeQueryParamObj(s));
|
|
1190
1210
|
}
|
|
1191
1211
|
storeQueryParamObj(e) {
|
|
1192
|
-
const t = e == null ? void 0 : e.query, s = (t == null ? void 0 : t.tags) || [], r = (t == null ? void 0 : t.categories) || [], i = t == null ? void 0 : t.read,
|
|
1212
|
+
const t = e == null ? void 0 : e.query, s = (t == null ? void 0 : t.tags) || [], r = (t == null ? void 0 : t.categories) || [], i = t == null ? void 0 : t.read, c = t == null ? void 0 : t.archived;
|
|
1193
1213
|
return {
|
|
1194
1214
|
store_id: e.storeId,
|
|
1195
1215
|
query: {
|
|
1196
1216
|
read: i,
|
|
1197
|
-
archived:
|
|
1217
|
+
archived: c,
|
|
1198
1218
|
tags: { or: s },
|
|
1199
1219
|
categories: { or: r }
|
|
1200
1220
|
}
|
|
@@ -1214,7 +1234,7 @@ class ne {
|
|
|
1214
1234
|
}), await this.fetch()) : {
|
|
1215
1235
|
status: n.ERROR,
|
|
1216
1236
|
error: {
|
|
1217
|
-
type:
|
|
1237
|
+
type: d.NOT_FOUND,
|
|
1218
1238
|
message: `store with storeId ${e} doesnt exist`
|
|
1219
1239
|
}
|
|
1220
1240
|
};
|
|
@@ -1240,8 +1260,7 @@ class ne {
|
|
|
1240
1260
|
tenant_id: this.feedOptions.tenantId,
|
|
1241
1261
|
schema: "1"
|
|
1242
1262
|
},
|
|
1243
|
-
|
|
1244
|
-
reconnectionDelay: 5e3,
|
|
1263
|
+
reconnectionDelay: 1e3,
|
|
1245
1264
|
reconnectionDelayMax: 1e4
|
|
1246
1265
|
}), this.initializeSocketEvents());
|
|
1247
1266
|
}
|
|
@@ -1269,24 +1288,24 @@ class ne {
|
|
|
1269
1288
|
];
|
|
1270
1289
|
} else
|
|
1271
1290
|
r.search_after = [];
|
|
1272
|
-
const i = this.getUrl("notifications", r),
|
|
1273
|
-
return
|
|
1291
|
+
const i = this.getUrl("notifications", r), c = await this.config.client().request({ type: "get", url: i });
|
|
1292
|
+
return c.status === n.ERROR ? (this.store.setState({ apiStatus: _.ERROR }), this.emitter.emit("feed.store_update", this.data), c) : (this.store.setState({
|
|
1274
1293
|
apiStatus: _.SUCCESS,
|
|
1275
|
-
notifications: t.isFirstFetch ?
|
|
1294
|
+
notifications: t.isFirstFetch ? c.body.results : [...t.notifications, ...c.body.results],
|
|
1276
1295
|
pageInfo: {
|
|
1277
1296
|
...t.pageInfo,
|
|
1278
|
-
total:
|
|
1279
|
-
hasMore:
|
|
1297
|
+
total: c.body.meta.total_count,
|
|
1298
|
+
hasMore: c.body.meta.has_more
|
|
1280
1299
|
},
|
|
1281
1300
|
isFirstFetch: !1
|
|
1282
|
-
}), this.emitter.emit("feed.store_update", this.data), this.startExpiryTimer(),
|
|
1301
|
+
}), this.emitter.emit("feed.store_update", this.data), this.startExpiryTimer(), c);
|
|
1283
1302
|
}
|
|
1284
1303
|
// TODO: support other stores
|
|
1285
1304
|
async fetchNextPage() {
|
|
1286
1305
|
return this.store.getState().pageInfo.hasMore === !1 ? {
|
|
1287
1306
|
status: n.ERROR,
|
|
1288
1307
|
error: {
|
|
1289
|
-
type:
|
|
1308
|
+
type: d.VALIDATION_ERROR,
|
|
1290
1309
|
message: "No more pages to fetch"
|
|
1291
1310
|
}
|
|
1292
1311
|
} : this.fetch();
|
|
@@ -1414,7 +1433,7 @@ class ne {
|
|
|
1414
1433
|
this.reset(), this.emitter.off("*"), (e = this.socket) == null || e.disconnect(), this.config.feeds.removeInstance(this);
|
|
1415
1434
|
}
|
|
1416
1435
|
}
|
|
1417
|
-
const ae = "https://hub.suprsend.com", oe = "serviceworker.js",
|
|
1436
|
+
const ae = "https://hub.suprsend.com", oe = "serviceworker.js", j = "ss_distinct_id";
|
|
1418
1437
|
class le {
|
|
1419
1438
|
constructor(e, t) {
|
|
1420
1439
|
f(this, "host");
|
|
@@ -1429,16 +1448,16 @@ class le {
|
|
|
1429
1448
|
f(this, "user", new q(this));
|
|
1430
1449
|
f(this, "webpush", new ee(this));
|
|
1431
1450
|
f(this, "feeds", new ie(this));
|
|
1432
|
-
f(this, "emitter",
|
|
1451
|
+
f(this, "emitter", F());
|
|
1433
1452
|
if (!e)
|
|
1434
1453
|
throw new Error("[SuprSend]: publicApiKey is missing");
|
|
1435
1454
|
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;
|
|
1436
1455
|
}
|
|
1437
1456
|
handleRefreshUserToken(e) {
|
|
1438
1457
|
if (!this.userToken || !A()) return;
|
|
1439
|
-
const t =
|
|
1458
|
+
const t = M(this.userToken), s = (t.exp || 0) * 1e3, r = Date.now(), i = 1e3 * 30;
|
|
1440
1459
|
if (s && s > r) {
|
|
1441
|
-
const
|
|
1460
|
+
const c = s - r - i;
|
|
1442
1461
|
this.userTokenExpirationTimer && clearTimeout(this.userTokenExpirationTimer), this.userTokenExpirationTimer = setTimeout(async () => {
|
|
1443
1462
|
let u = "";
|
|
1444
1463
|
try {
|
|
@@ -1457,7 +1476,7 @@ class le {
|
|
|
1457
1476
|
}
|
|
1458
1477
|
}
|
|
1459
1478
|
u && typeof u == "string" && this.identify(this.distinctId, u, this.authenticateOptions);
|
|
1460
|
-
},
|
|
1479
|
+
}, c);
|
|
1461
1480
|
}
|
|
1462
1481
|
}
|
|
1463
1482
|
client() {
|
|
@@ -1480,13 +1499,13 @@ class le {
|
|
|
1480
1499
|
if (!e)
|
|
1481
1500
|
return o({
|
|
1482
1501
|
status: n.ERROR,
|
|
1483
|
-
errorType:
|
|
1502
|
+
errorType: d.VALIDATION_ERROR,
|
|
1484
1503
|
errorMessage: "distinctId is missing"
|
|
1485
1504
|
});
|
|
1486
1505
|
if (this.apiClient && this.distinctId && this.distinctId !== e)
|
|
1487
1506
|
return o({
|
|
1488
1507
|
status: n.ERROR,
|
|
1489
|
-
errorType:
|
|
1508
|
+
errorType: d.VALIDATION_ERROR,
|
|
1490
1509
|
errorMessage: "User already loggedin, reset current user to login new user"
|
|
1491
1510
|
});
|
|
1492
1511
|
if (this.apiClient && this.distinctId === e && this.userToken !== t)
|
|
@@ -1495,7 +1514,7 @@ class le {
|
|
|
1495
1514
|
return o({ status: n.SUCCESS });
|
|
1496
1515
|
this.distinctId = e, this.userToken = t, this.apiClient = new N(this), this.authenticateOptions = s;
|
|
1497
1516
|
const r = L(
|
|
1498
|
-
|
|
1517
|
+
j
|
|
1499
1518
|
);
|
|
1500
1519
|
if (s != null && s.refreshUserToken && this.handleRefreshUserToken(s.refreshUserToken), r == this.distinctId)
|
|
1501
1520
|
return this.webpush.updatePushSubscription(), o({ status: n.SUCCESS });
|
|
@@ -1507,7 +1526,7 @@ class le {
|
|
|
1507
1526
|
$identified_id: e
|
|
1508
1527
|
}
|
|
1509
1528
|
});
|
|
1510
|
-
return i.status === n.SUCCESS ? (this.webpush.updatePushSubscription(),
|
|
1529
|
+
return i.status === n.SUCCESS ? (this.webpush.updatePushSubscription(), x(j, this.distinctId)) : this.reset({ unsubscribePush: !1 }), i;
|
|
1511
1530
|
}
|
|
1512
1531
|
/**
|
|
1513
1532
|
* Check's if SuprSend instance is authenticated. To check if userToken is also present pass true.
|
|
@@ -1528,7 +1547,7 @@ class le {
|
|
|
1528
1547
|
properties: s
|
|
1529
1548
|
})) : o({
|
|
1530
1549
|
status: n.ERROR,
|
|
1531
|
-
errorType:
|
|
1550
|
+
errorType: d.VALIDATION_ERROR,
|
|
1532
1551
|
errorMessage: "event name is missing"
|
|
1533
1552
|
});
|
|
1534
1553
|
}
|
|
@@ -1543,7 +1562,7 @@ class le {
|
|
|
1543
1562
|
export {
|
|
1544
1563
|
_ as ApiResponseStatus,
|
|
1545
1564
|
w as ChannelLevelPreferenceOptions,
|
|
1546
|
-
|
|
1565
|
+
d as ERROR_TYPE,
|
|
1547
1566
|
ne as Feed,
|
|
1548
1567
|
p as PreferenceOptions,
|
|
1549
1568
|
n as RESPONSE_STATUS,
|