@suprsend/web-sdk 3.1.0 → 4.0.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/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/es/index.js +165 -164
- package/dist/es/index.js.map +1 -1
- package/dist/types/interface.d.ts +2 -5
- package/package.json +1 -1
package/dist/es/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import V from "mitt";
|
|
|
5
5
|
import x from "jwt-decode";
|
|
6
6
|
import { createStore as z } from "zustand/vanilla";
|
|
7
7
|
import { io as B } from "socket.io-client";
|
|
8
|
-
var p = /* @__PURE__ */ ((a) => (a.OPT_IN = "opt_in", a.OPT_OUT = "opt_out", a))(p || {}), 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 || {}), c = /* @__PURE__ */ ((a) => (a.VALIDATION_ERROR = "VALIDATION_ERROR", a.NETWORK_ERROR = "NETWORK_ERROR", a.UNKNOWN_ERROR = "UNKNOWN_ERROR", a.PERMISSION_DENIED = "PERMISSION_DENIED", a.UNSUPPORTED_ACTION = "UNSUPPORTED_ACTION", a.NOT_FOUND = "NOT_FOUND", a))(c || {}), n = /* @__PURE__ */ ((a) => (a.SUCCESS = "success", a.ERROR = "error", a))(n || {}), _ = /* @__PURE__ */ ((a) => (a.INITIAL = "INITIAL", a.LOADING = "LOADING", a.SUCCESS = "SUCCESS", a.ERROR = "ERROR", a.FETCHING_MORE = "FETCHING_MORE", a))(_ || {});
|
|
9
9
|
function C() {
|
|
10
10
|
let a = (/* @__PURE__ */ new Date()).getTime();
|
|
11
11
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
|
|
@@ -16,7 +16,7 @@ function C() {
|
|
|
16
16
|
}
|
|
17
17
|
);
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function P() {
|
|
20
20
|
return Math.round(Date.now());
|
|
21
21
|
}
|
|
22
22
|
function I(a) {
|
|
@@ -37,7 +37,7 @@ function G(a, e) {
|
|
|
37
37
|
t = setTimeout(() => r(a(...s)), e);
|
|
38
38
|
}));
|
|
39
39
|
}
|
|
40
|
-
function
|
|
40
|
+
function M(a, e) {
|
|
41
41
|
const t = {};
|
|
42
42
|
return (...s) => {
|
|
43
43
|
const [r] = s, i = s.slice(1);
|
|
@@ -116,12 +116,12 @@ class N {
|
|
|
116
116
|
if (!this.config.distinctId)
|
|
117
117
|
return o({
|
|
118
118
|
status: n.ERROR,
|
|
119
|
-
errorType:
|
|
119
|
+
errorType: c.VALIDATION_ERROR,
|
|
120
120
|
errorMessage: "User isn't authenticated. Call identify method before performing any action"
|
|
121
121
|
});
|
|
122
122
|
if ((t = this.config.authenticateOptions) != null && t.refreshUserToken && this.config.userToken) {
|
|
123
|
-
const i = x(this.config.userToken),
|
|
124
|
-
if (
|
|
123
|
+
const i = x(this.config.userToken), d = (i.exp || 0) * 1e3, u = Date.now();
|
|
124
|
+
if (d <= u)
|
|
125
125
|
try {
|
|
126
126
|
const h = await this.config.authenticateOptions.refreshUserToken(
|
|
127
127
|
this.config.userToken,
|
|
@@ -136,20 +136,20 @@ class N {
|
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
try {
|
|
139
|
-
const i = await this.requestApiInstance(e),
|
|
139
|
+
const i = await this.requestApiInstance(e), d = await i.json(), u = (d == null ? void 0 : d.status) || (i.ok ? n.SUCCESS : n.ERROR);
|
|
140
140
|
return o({
|
|
141
141
|
status: u,
|
|
142
|
-
body:
|
|
142
|
+
body: d,
|
|
143
143
|
statusCode: i.status,
|
|
144
|
-
errorMessage: (s =
|
|
145
|
-
errorType: (r =
|
|
144
|
+
errorMessage: (s = d == null ? void 0 : d.error) == null ? void 0 : s.message,
|
|
145
|
+
errorType: (r = d == null ? void 0 : d.error) == null ? void 0 : r.type
|
|
146
146
|
});
|
|
147
147
|
} catch (i) {
|
|
148
148
|
return console.error(i), o({
|
|
149
149
|
status: n.ERROR,
|
|
150
150
|
statusCode: 500,
|
|
151
151
|
errorMessage: (i == null ? void 0 : i.message) || "network error",
|
|
152
|
-
errorType:
|
|
152
|
+
errorType: c.NETWORK_ERROR
|
|
153
153
|
});
|
|
154
154
|
}
|
|
155
155
|
}
|
|
@@ -162,10 +162,10 @@ class J {
|
|
|
162
162
|
f(this, "debouncedUpdateCategoryPreferences");
|
|
163
163
|
f(this, "debouncedUpdateChannelPreferences");
|
|
164
164
|
f(this, "debounceTime", 1e3);
|
|
165
|
-
this.config = e, this.debouncedUpdateCategoryPreferences =
|
|
165
|
+
this.config = e, this.debouncedUpdateCategoryPreferences = M(
|
|
166
166
|
this._updateCategoryPreferences.bind(this),
|
|
167
167
|
this.debounceTime
|
|
168
|
-
), this.debouncedUpdateChannelPreferences =
|
|
168
|
+
), this.debouncedUpdateChannelPreferences = M(
|
|
169
169
|
this._updateChannelPreferences.bind(this),
|
|
170
170
|
this.debounceTime
|
|
171
171
|
);
|
|
@@ -225,7 +225,7 @@ class J {
|
|
|
225
225
|
if (!e)
|
|
226
226
|
return o({
|
|
227
227
|
status: n.ERROR,
|
|
228
|
-
errorType:
|
|
228
|
+
errorType: c.VALIDATION_ERROR,
|
|
229
229
|
errorMessage: "Category parameter is missing"
|
|
230
230
|
});
|
|
231
231
|
const s = {
|
|
@@ -242,16 +242,16 @@ class J {
|
|
|
242
242
|
return await this.config.client().request({ type: "get", url: e });
|
|
243
243
|
}
|
|
244
244
|
async _updateCategoryPreferences(e, t, s, r) {
|
|
245
|
-
const i = this.getUrl(`category/${e}`, r),
|
|
245
|
+
const i = this.getUrl(`category/${e}`, r), d = await this.config.client().request({
|
|
246
246
|
type: "patch",
|
|
247
247
|
url: i,
|
|
248
248
|
payload: t
|
|
249
249
|
});
|
|
250
|
-
return
|
|
250
|
+
return d != null && d.error ? this.config.emitter.emit("preferences_error", d) : (Object.assign(s, d.body), this.config.emitter.emit("preferences_updated", {
|
|
251
251
|
status: n.SUCCESS,
|
|
252
252
|
statusCode: 200,
|
|
253
253
|
body: this.data
|
|
254
|
-
})),
|
|
254
|
+
})), d;
|
|
255
255
|
}
|
|
256
256
|
async _updateChannelPreferences(e) {
|
|
257
257
|
const t = this.getUrl("channel_preference"), s = await this.config.client().request({
|
|
@@ -275,45 +275,45 @@ class J {
|
|
|
275
275
|
))
|
|
276
276
|
return o({
|
|
277
277
|
status: n.ERROR,
|
|
278
|
-
errorType:
|
|
278
|
+
errorType: c.VALIDATION_ERROR,
|
|
279
279
|
errorMessage: e ? "Preference parameter is invalid" : "Category parameter is missing"
|
|
280
280
|
});
|
|
281
281
|
if (!this.data)
|
|
282
282
|
return o({
|
|
283
283
|
status: n.ERROR,
|
|
284
|
-
errorType:
|
|
284
|
+
errorType: c.VALIDATION_ERROR,
|
|
285
285
|
errorMessage: "Call getPreferences method before performing action"
|
|
286
286
|
});
|
|
287
287
|
if (!this.data.sections)
|
|
288
288
|
return o({
|
|
289
289
|
status: n.ERROR,
|
|
290
|
-
errorType:
|
|
290
|
+
errorType: c.VALIDATION_ERROR,
|
|
291
291
|
errorMessage: "Sections doesn't exist"
|
|
292
292
|
});
|
|
293
293
|
let r = null, i = !1;
|
|
294
294
|
for (const R of this.data.sections) {
|
|
295
|
-
let
|
|
295
|
+
let g = !1;
|
|
296
296
|
if (R.subcategories) {
|
|
297
|
-
for (const
|
|
298
|
-
if (
|
|
299
|
-
if (r =
|
|
300
|
-
if (
|
|
301
|
-
|
|
297
|
+
for (const O of R.subcategories)
|
|
298
|
+
if (O.category === e)
|
|
299
|
+
if (r = O, O.is_editable) {
|
|
300
|
+
if (O.preference !== t) {
|
|
301
|
+
O.preference = t, i = !0, g = !0;
|
|
302
302
|
break;
|
|
303
303
|
}
|
|
304
304
|
} else
|
|
305
305
|
return o({
|
|
306
306
|
status: n.ERROR,
|
|
307
|
-
errorType:
|
|
307
|
+
errorType: c.VALIDATION_ERROR,
|
|
308
308
|
errorMessage: "Category preference is not editable"
|
|
309
309
|
});
|
|
310
|
-
if (
|
|
310
|
+
if (g) break;
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
313
|
if (!r)
|
|
314
314
|
return o({
|
|
315
315
|
status: n.ERROR,
|
|
316
|
-
errorType:
|
|
316
|
+
errorType: c.VALIDATION_ERROR,
|
|
317
317
|
errorMessage: "Category not found"
|
|
318
318
|
});
|
|
319
319
|
if (!i)
|
|
@@ -321,15 +321,15 @@ class J {
|
|
|
321
321
|
status: n.SUCCESS,
|
|
322
322
|
body: this.data
|
|
323
323
|
});
|
|
324
|
-
const
|
|
324
|
+
const d = [];
|
|
325
325
|
(h = r == null ? void 0 : r.channels) == null || h.forEach((R) => {
|
|
326
|
-
R.preference === p.OPT_OUT &&
|
|
326
|
+
R.preference === p.OPT_OUT && d.push(R.channel);
|
|
327
327
|
});
|
|
328
328
|
let u = !0;
|
|
329
329
|
typeof (s == null ? void 0 : s.showOptOutChannels) == "boolean" ? u = s == null ? void 0 : s.showOptOutChannels : typeof ((T = this.preferenceArgs) == null ? void 0 : T.showOptOutChannels) == "boolean" && (u = this.preferenceArgs.showOptOutChannels);
|
|
330
330
|
const l = {
|
|
331
331
|
preference: r.preference,
|
|
332
|
-
opt_out_channels: u && t === p.OPT_IN ? null :
|
|
332
|
+
opt_out_channels: u && t === p.OPT_IN ? null : d
|
|
333
333
|
};
|
|
334
334
|
return this.debouncedUpdateCategoryPreferences(
|
|
335
335
|
e,
|
|
@@ -350,11 +350,11 @@ class J {
|
|
|
350
350
|
* Used to update user's category level channel preference.
|
|
351
351
|
*/
|
|
352
352
|
async updateChannelPreferenceInCategory(e, t, s, r) {
|
|
353
|
-
var S, R,
|
|
353
|
+
var S, R, g, O;
|
|
354
354
|
if (!e || !s)
|
|
355
355
|
return o({
|
|
356
356
|
status: n.ERROR,
|
|
357
|
-
errorType:
|
|
357
|
+
errorType: c.VALIDATION_ERROR,
|
|
358
358
|
errorMessage: e ? "Category parameter is missing" : "Channel parameter is missing"
|
|
359
359
|
});
|
|
360
360
|
if (![p.OPT_IN, p.OPT_OUT].includes(
|
|
@@ -362,39 +362,39 @@ class J {
|
|
|
362
362
|
))
|
|
363
363
|
return o({
|
|
364
364
|
status: n.ERROR,
|
|
365
|
-
errorType:
|
|
365
|
+
errorType: c.VALIDATION_ERROR,
|
|
366
366
|
errorMessage: "Preference parameter is invalid"
|
|
367
367
|
});
|
|
368
368
|
if (!this.data)
|
|
369
369
|
return o({
|
|
370
370
|
status: n.ERROR,
|
|
371
|
-
errorType:
|
|
371
|
+
errorType: c.VALIDATION_ERROR,
|
|
372
372
|
errorMessage: "Call getPreferences method before performing action"
|
|
373
373
|
});
|
|
374
374
|
if (!this.data.sections)
|
|
375
375
|
return o({
|
|
376
376
|
status: n.ERROR,
|
|
377
|
-
errorType:
|
|
377
|
+
errorType: c.VALIDATION_ERROR,
|
|
378
378
|
errorMessage: "Sections doesn't exist"
|
|
379
379
|
});
|
|
380
|
-
let i = null,
|
|
381
|
-
for (const
|
|
380
|
+
let i = null, d = null, u = !1;
|
|
381
|
+
for (const y of this.data.sections) {
|
|
382
382
|
let v = !1;
|
|
383
|
-
if (
|
|
384
|
-
for (const
|
|
385
|
-
if (
|
|
386
|
-
if (i =
|
|
387
|
-
for (const E of
|
|
383
|
+
if (y.subcategories) {
|
|
384
|
+
for (const m of y.subcategories) {
|
|
385
|
+
if (m.category === s) {
|
|
386
|
+
if (i = m, !m.channels) continue;
|
|
387
|
+
for (const E of m.channels)
|
|
388
388
|
if (E.channel === e)
|
|
389
|
-
if (
|
|
389
|
+
if (d = E, E.is_editable) {
|
|
390
390
|
if (E.preference !== t) {
|
|
391
|
-
E.preference = t, t === p.OPT_IN && (
|
|
391
|
+
E.preference = t, t === p.OPT_IN && (m.preference = p.OPT_IN), u = !0, v = !0;
|
|
392
392
|
break;
|
|
393
393
|
}
|
|
394
394
|
} else
|
|
395
395
|
return o({
|
|
396
396
|
status: n.ERROR,
|
|
397
|
-
errorType:
|
|
397
|
+
errorType: c.VALIDATION_ERROR,
|
|
398
398
|
errorMessage: "Channel preference is not editable"
|
|
399
399
|
});
|
|
400
400
|
}
|
|
@@ -406,13 +406,13 @@ class J {
|
|
|
406
406
|
if (!i)
|
|
407
407
|
return o({
|
|
408
408
|
status: n.ERROR,
|
|
409
|
-
errorType:
|
|
409
|
+
errorType: c.VALIDATION_ERROR,
|
|
410
410
|
errorMessage: "Category not found"
|
|
411
411
|
});
|
|
412
|
-
if (!
|
|
412
|
+
if (!d)
|
|
413
413
|
return o({
|
|
414
414
|
status: n.ERROR,
|
|
415
|
-
errorType:
|
|
415
|
+
errorType: c.VALIDATION_ERROR,
|
|
416
416
|
errorMessage: "Category's channel not found"
|
|
417
417
|
});
|
|
418
418
|
if (!u)
|
|
@@ -421,8 +421,8 @@ class J {
|
|
|
421
421
|
body: this.data
|
|
422
422
|
});
|
|
423
423
|
const l = [];
|
|
424
|
-
(S = i == null ? void 0 : i.channels) == null || S.forEach((
|
|
425
|
-
|
|
424
|
+
(S = i == null ? void 0 : i.channels) == null || S.forEach((y) => {
|
|
425
|
+
y.preference === p.OPT_OUT && l.push(y.channel);
|
|
426
426
|
});
|
|
427
427
|
let h = !0;
|
|
428
428
|
typeof (r == null ? void 0 : r.showOptOutChannels) == "boolean" ? h = r == null ? void 0 : r.showOptOutChannels : typeof ((R = this.preferenceArgs) == null ? void 0 : R.showOptOutChannels) == "boolean" && (h = this.preferenceArgs.showOptOutChannels);
|
|
@@ -436,9 +436,9 @@ class J {
|
|
|
436
436
|
b,
|
|
437
437
|
i,
|
|
438
438
|
{
|
|
439
|
-
tenant_id: (r == null ? void 0 : r.tenantId) || ((
|
|
439
|
+
tenant_id: (r == null ? void 0 : r.tenantId) || ((g = this.preferenceArgs) == null ? void 0 : g.tenantId),
|
|
440
440
|
show_opt_out_channels: h,
|
|
441
|
-
tags: (r == null ? void 0 : r.tags) || ((
|
|
441
|
+
tags: (r == null ? void 0 : r.tags) || ((O = this.preferenceArgs) == null ? void 0 : O.tags)
|
|
442
442
|
}
|
|
443
443
|
), o({
|
|
444
444
|
status: n.SUCCESS,
|
|
@@ -455,26 +455,26 @@ class J {
|
|
|
455
455
|
].includes(t))
|
|
456
456
|
return o({
|
|
457
457
|
status: n.ERROR,
|
|
458
|
-
errorType:
|
|
458
|
+
errorType: c.VALIDATION_ERROR,
|
|
459
459
|
errorMessage: e ? "Preference parameter is invalid" : "Channel parameter is missing"
|
|
460
460
|
});
|
|
461
461
|
if (!this.data)
|
|
462
462
|
return o({
|
|
463
463
|
status: n.ERROR,
|
|
464
|
-
errorType:
|
|
464
|
+
errorType: c.VALIDATION_ERROR,
|
|
465
465
|
errorMessage: "Call getPreferences method before performing action"
|
|
466
466
|
});
|
|
467
467
|
if (!this.data.channel_preferences)
|
|
468
468
|
return o({
|
|
469
469
|
status: n.ERROR,
|
|
470
|
-
errorType:
|
|
470
|
+
errorType: c.VALIDATION_ERROR,
|
|
471
471
|
errorMessage: "Channel preferences doesn't exist"
|
|
472
472
|
});
|
|
473
473
|
let s = null, r = !1;
|
|
474
474
|
const i = t === w.REQUIRED;
|
|
475
|
-
for (const
|
|
476
|
-
if (
|
|
477
|
-
|
|
475
|
+
for (const d of this.data.channel_preferences)
|
|
476
|
+
if (d.channel === e && (s = d, d.is_restricted !== i)) {
|
|
477
|
+
d.is_restricted = i, r = !0;
|
|
478
478
|
break;
|
|
479
479
|
}
|
|
480
480
|
return s ? r ? (this.debouncedUpdateChannelPreferences(s.channel, {
|
|
@@ -487,12 +487,12 @@ class J {
|
|
|
487
487
|
body: this.data
|
|
488
488
|
}) : o({
|
|
489
489
|
status: n.ERROR,
|
|
490
|
-
errorType:
|
|
490
|
+
errorType: c.VALIDATION_ERROR,
|
|
491
491
|
errorMessage: "Channel data not found"
|
|
492
492
|
});
|
|
493
493
|
}
|
|
494
494
|
}
|
|
495
|
-
const
|
|
495
|
+
const k = "ss_device_id";
|
|
496
496
|
class Z {
|
|
497
497
|
constructor(e) {
|
|
498
498
|
f(this, "config");
|
|
@@ -513,14 +513,14 @@ class Z {
|
|
|
513
513
|
}
|
|
514
514
|
validateObjData(e, t) {
|
|
515
515
|
const s = {}, r = (t == null ? void 0 : t.allowReservedKeys) || !1, i = (t == null ? void 0 : t.valueType) || "";
|
|
516
|
-
for (const
|
|
517
|
-
let u = e[
|
|
518
|
-
if (!(
|
|
519
|
-
if (!r && this.isReservedKey(
|
|
516
|
+
for (const d in e) {
|
|
517
|
+
let u = e[d];
|
|
518
|
+
if (!(d && u === void 0)) {
|
|
519
|
+
if (!r && this.isReservedKey(d)) {
|
|
520
520
|
console.warn("[SuprSend]: key cannot start with $ or ss_");
|
|
521
521
|
continue;
|
|
522
522
|
}
|
|
523
|
-
i === "number" ? u = Number(u) : i === "boolean" && (u = !!u), s[
|
|
523
|
+
i === "number" ? u = Number(u) : i === "boolean" && (u = !!u), s[d] = u;
|
|
524
524
|
}
|
|
525
525
|
}
|
|
526
526
|
return s;
|
|
@@ -541,7 +541,7 @@ class Z {
|
|
|
541
541
|
return this.config.eventApi({
|
|
542
542
|
distinct_id: this.config.distinctId,
|
|
543
543
|
$insert_id: C(),
|
|
544
|
-
$time:
|
|
544
|
+
$time: P(),
|
|
545
545
|
...e
|
|
546
546
|
});
|
|
547
547
|
}
|
|
@@ -553,13 +553,13 @@ class Z {
|
|
|
553
553
|
if (!s)
|
|
554
554
|
return o({
|
|
555
555
|
status: n.ERROR,
|
|
556
|
-
errorType:
|
|
556
|
+
errorType: c.VALIDATION_ERROR,
|
|
557
557
|
errorMessage: "data provided is empty"
|
|
558
558
|
});
|
|
559
559
|
const r = this.validateObjData(s);
|
|
560
560
|
return I(r) ? o({
|
|
561
561
|
status: n.ERROR,
|
|
562
|
-
errorType:
|
|
562
|
+
errorType: c.VALIDATION_ERROR,
|
|
563
563
|
errorMessage: "data provided is empty"
|
|
564
564
|
}) : this.triggerUserEvent({ $set: r });
|
|
565
565
|
}
|
|
@@ -572,13 +572,13 @@ class Z {
|
|
|
572
572
|
if (!s)
|
|
573
573
|
return o({
|
|
574
574
|
status: n.ERROR,
|
|
575
|
-
errorType:
|
|
575
|
+
errorType: c.VALIDATION_ERROR,
|
|
576
576
|
errorMessage: "data provided is empty"
|
|
577
577
|
});
|
|
578
578
|
const r = this.validateObjData(s);
|
|
579
579
|
return I(r) ? o({
|
|
580
580
|
status: n.ERROR,
|
|
581
|
-
errorType:
|
|
581
|
+
errorType: c.VALIDATION_ERROR,
|
|
582
582
|
errorMessage: "data provided is empty"
|
|
583
583
|
}) : this.triggerUserEvent({ $set_once: r });
|
|
584
584
|
}
|
|
@@ -591,13 +591,13 @@ class Z {
|
|
|
591
591
|
if (!s)
|
|
592
592
|
return o({
|
|
593
593
|
status: n.ERROR,
|
|
594
|
-
errorType:
|
|
594
|
+
errorType: c.VALIDATION_ERROR,
|
|
595
595
|
errorMessage: "data provided is empty"
|
|
596
596
|
});
|
|
597
597
|
const r = this.validateObjData(s, { valueType: "number" });
|
|
598
598
|
return I(r) ? o({
|
|
599
599
|
status: n.ERROR,
|
|
600
|
-
errorType:
|
|
600
|
+
errorType: c.VALIDATION_ERROR,
|
|
601
601
|
errorMessage: "data provided is empty"
|
|
602
602
|
}) : this.triggerUserEvent({ $add: r });
|
|
603
603
|
}
|
|
@@ -610,13 +610,13 @@ class Z {
|
|
|
610
610
|
if (!s)
|
|
611
611
|
return o({
|
|
612
612
|
status: n.ERROR,
|
|
613
|
-
errorType:
|
|
613
|
+
errorType: c.VALIDATION_ERROR,
|
|
614
614
|
errorMessage: "data provided is empty"
|
|
615
615
|
});
|
|
616
616
|
const r = this.validateObjData(s);
|
|
617
617
|
return I(r) ? o({
|
|
618
618
|
status: n.ERROR,
|
|
619
|
-
errorType:
|
|
619
|
+
errorType: c.VALIDATION_ERROR,
|
|
620
620
|
errorMessage: "data provided is empty"
|
|
621
621
|
}) : this.triggerUserEvent({ $append: r });
|
|
622
622
|
}
|
|
@@ -629,13 +629,13 @@ class Z {
|
|
|
629
629
|
if (!s)
|
|
630
630
|
return o({
|
|
631
631
|
status: n.ERROR,
|
|
632
|
-
errorType:
|
|
632
|
+
errorType: c.VALIDATION_ERROR,
|
|
633
633
|
errorMessage: "data provided is empty"
|
|
634
634
|
});
|
|
635
635
|
const r = this.validateObjData(s);
|
|
636
636
|
return I(r) ? o({
|
|
637
637
|
status: n.ERROR,
|
|
638
|
-
errorType:
|
|
638
|
+
errorType: c.VALIDATION_ERROR,
|
|
639
639
|
errorMessage: "data provided is empty"
|
|
640
640
|
}) : this.triggerUserEvent({ $remove: r });
|
|
641
641
|
}
|
|
@@ -647,13 +647,13 @@ class Z {
|
|
|
647
647
|
if (!t)
|
|
648
648
|
return o({
|
|
649
649
|
status: n.ERROR,
|
|
650
|
-
errorType:
|
|
650
|
+
errorType: c.VALIDATION_ERROR,
|
|
651
651
|
errorMessage: "data provided is empty"
|
|
652
652
|
});
|
|
653
653
|
const s = this.validateArrayData(t);
|
|
654
654
|
return H(s) ? o({
|
|
655
655
|
status: n.ERROR,
|
|
656
|
-
errorType:
|
|
656
|
+
errorType: c.VALIDATION_ERROR,
|
|
657
657
|
errorMessage: "data provided is empty"
|
|
658
658
|
}) : this.triggerUserEvent({ $unset: s });
|
|
659
659
|
}
|
|
@@ -663,7 +663,7 @@ class Z {
|
|
|
663
663
|
if (!s)
|
|
664
664
|
return o({
|
|
665
665
|
status: n.ERROR,
|
|
666
|
-
errorType:
|
|
666
|
+
errorType: c.VALIDATION_ERROR,
|
|
667
667
|
errorMessage: "data provided is empty"
|
|
668
668
|
});
|
|
669
669
|
const r = this.validateObjData(s, {
|
|
@@ -671,7 +671,7 @@ class Z {
|
|
|
671
671
|
});
|
|
672
672
|
return I(r) ? o({
|
|
673
673
|
status: n.ERROR,
|
|
674
|
-
errorType:
|
|
674
|
+
errorType: c.VALIDATION_ERROR,
|
|
675
675
|
errorMessage: "data provided is empty"
|
|
676
676
|
}) : this.triggerUserEvent({ $append: r });
|
|
677
677
|
}
|
|
@@ -681,7 +681,7 @@ class Z {
|
|
|
681
681
|
if (!s)
|
|
682
682
|
return o({
|
|
683
683
|
status: n.ERROR,
|
|
684
|
-
errorType:
|
|
684
|
+
errorType: c.VALIDATION_ERROR,
|
|
685
685
|
errorMessage: "data provided is empty"
|
|
686
686
|
});
|
|
687
687
|
const r = this.validateObjData(s, {
|
|
@@ -689,7 +689,7 @@ class Z {
|
|
|
689
689
|
});
|
|
690
690
|
return I(r) ? o({
|
|
691
691
|
status: n.ERROR,
|
|
692
|
-
errorType:
|
|
692
|
+
errorType: c.VALIDATION_ERROR,
|
|
693
693
|
errorMessage: "data provided is empty"
|
|
694
694
|
}) : this.triggerUserEvent({ $remove: r });
|
|
695
695
|
}
|
|
@@ -698,7 +698,7 @@ class Z {
|
|
|
698
698
|
if (!s)
|
|
699
699
|
return o({
|
|
700
700
|
status: n.ERROR,
|
|
701
|
-
errorType:
|
|
701
|
+
errorType: c.VALIDATION_ERROR,
|
|
702
702
|
errorMessage: "data provided is empty"
|
|
703
703
|
});
|
|
704
704
|
const r = this.validateObjData(s, {
|
|
@@ -706,7 +706,7 @@ class Z {
|
|
|
706
706
|
});
|
|
707
707
|
return I(r) ? o({
|
|
708
708
|
status: n.ERROR,
|
|
709
|
-
errorType:
|
|
709
|
+
errorType: c.VALIDATION_ERROR,
|
|
710
710
|
errorMessage: "data provided is empty"
|
|
711
711
|
}) : this.triggerUserEvent({ $set: r });
|
|
712
712
|
}
|
|
@@ -719,14 +719,14 @@ class Z {
|
|
|
719
719
|
async addEmail(e) {
|
|
720
720
|
return this.validateEmail(e) ? this.appendInternal({ $email: e }) : o({
|
|
721
721
|
status: n.ERROR,
|
|
722
|
-
errorType:
|
|
722
|
+
errorType: c.VALIDATION_ERROR,
|
|
723
723
|
errorMessage: "provided email is invalid"
|
|
724
724
|
});
|
|
725
725
|
}
|
|
726
726
|
async removeEmail(e) {
|
|
727
727
|
return this.validateEmail(e) ? this.removeInternal({ $email: e }) : o({
|
|
728
728
|
status: n.ERROR,
|
|
729
|
-
errorType:
|
|
729
|
+
errorType: c.VALIDATION_ERROR,
|
|
730
730
|
errorMessage: "provided email is invalid"
|
|
731
731
|
});
|
|
732
732
|
}
|
|
@@ -736,7 +736,7 @@ class Z {
|
|
|
736
736
|
async addSms(e) {
|
|
737
737
|
return this.validateMobile(e) ? this.appendInternal({ $sms: e }) : o({
|
|
738
738
|
status: n.ERROR,
|
|
739
|
-
errorType:
|
|
739
|
+
errorType: c.VALIDATION_ERROR,
|
|
740
740
|
errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
|
|
741
741
|
});
|
|
742
742
|
}
|
|
@@ -746,7 +746,7 @@ class Z {
|
|
|
746
746
|
async removeSms(e) {
|
|
747
747
|
return this.validateMobile(e) ? this.removeInternal({ $sms: e }) : o({
|
|
748
748
|
status: n.ERROR,
|
|
749
|
-
errorType:
|
|
749
|
+
errorType: c.VALIDATION_ERROR,
|
|
750
750
|
errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
|
|
751
751
|
});
|
|
752
752
|
}
|
|
@@ -756,7 +756,7 @@ class Z {
|
|
|
756
756
|
async addWhatsapp(e) {
|
|
757
757
|
return this.validateMobile(e) ? this.appendInternal({ $whatsapp: e }) : o({
|
|
758
758
|
status: n.ERROR,
|
|
759
|
-
errorType:
|
|
759
|
+
errorType: c.VALIDATION_ERROR,
|
|
760
760
|
errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
|
|
761
761
|
});
|
|
762
762
|
}
|
|
@@ -766,19 +766,19 @@ class Z {
|
|
|
766
766
|
async removeWhatsapp(e) {
|
|
767
767
|
return this.validateMobile(e) ? this.removeInternal({ $whatsapp: e }) : o({
|
|
768
768
|
status: n.ERROR,
|
|
769
|
-
errorType:
|
|
769
|
+
errorType: c.VALIDATION_ERROR,
|
|
770
770
|
errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
|
|
771
771
|
});
|
|
772
772
|
}
|
|
773
773
|
getDeviceId() {
|
|
774
|
-
let e = j(
|
|
775
|
-
return e || (e = C(), $(
|
|
774
|
+
let e = j(k);
|
|
775
|
+
return e || (e = C(), $(k, e)), e;
|
|
776
776
|
}
|
|
777
777
|
async addWebPush(e) {
|
|
778
778
|
if (typeof e != "object")
|
|
779
779
|
return o({
|
|
780
780
|
status: n.ERROR,
|
|
781
|
-
errorType:
|
|
781
|
+
errorType: c.VALIDATION_ERROR,
|
|
782
782
|
errorMessage: "provided push subscription is invalid, must be an object"
|
|
783
783
|
});
|
|
784
784
|
const t = this.getDeviceId();
|
|
@@ -792,7 +792,7 @@ class Z {
|
|
|
792
792
|
if (typeof e != "object")
|
|
793
793
|
return o({
|
|
794
794
|
status: n.ERROR,
|
|
795
|
-
errorType:
|
|
795
|
+
errorType: c.VALIDATION_ERROR,
|
|
796
796
|
errorMessage: "provided push subscription is invalid, must be an object"
|
|
797
797
|
});
|
|
798
798
|
const t = this.getDeviceId();
|
|
@@ -805,28 +805,28 @@ class Z {
|
|
|
805
805
|
async addSlack(e) {
|
|
806
806
|
return typeof e != "object" ? o({
|
|
807
807
|
status: n.ERROR,
|
|
808
|
-
errorType:
|
|
808
|
+
errorType: c.VALIDATION_ERROR,
|
|
809
809
|
errorMessage: "provided slack data is invalid, must be an object"
|
|
810
810
|
}) : this.appendInternal({ $slack: e });
|
|
811
811
|
}
|
|
812
812
|
async removeSlack(e) {
|
|
813
813
|
return typeof e != "object" ? o({
|
|
814
814
|
status: n.ERROR,
|
|
815
|
-
errorType:
|
|
815
|
+
errorType: c.VALIDATION_ERROR,
|
|
816
816
|
errorMessage: "provided slack data is invalid, must be an object"
|
|
817
817
|
}) : this.removeInternal({ $slack: e });
|
|
818
818
|
}
|
|
819
819
|
async addMSTeams(e) {
|
|
820
820
|
return typeof e != "object" ? o({
|
|
821
821
|
status: n.ERROR,
|
|
822
|
-
errorType:
|
|
822
|
+
errorType: c.VALIDATION_ERROR,
|
|
823
823
|
errorMessage: "provided ms_teams data is invalid, must be object"
|
|
824
824
|
}) : this.appendInternal({ $ms_teams: e });
|
|
825
825
|
}
|
|
826
826
|
async removeMSTeams(e) {
|
|
827
827
|
return typeof e != "object" ? o({
|
|
828
828
|
status: n.ERROR,
|
|
829
|
-
errorType:
|
|
829
|
+
errorType: c.VALIDATION_ERROR,
|
|
830
830
|
errorMessage: "provided ms_teams data is invalid, must be object"
|
|
831
831
|
}) : this.removeInternal({ $ms_teams: e });
|
|
832
832
|
}
|
|
@@ -837,7 +837,7 @@ class Z {
|
|
|
837
837
|
async setPreferredLanguage(e) {
|
|
838
838
|
return typeof e != "string" ? o({
|
|
839
839
|
status: n.ERROR,
|
|
840
|
-
errorType:
|
|
840
|
+
errorType: c.VALIDATION_ERROR,
|
|
841
841
|
errorMessage: "provided language is invalid, must be string"
|
|
842
842
|
}) : this.setInternal({ $preferred_language: e });
|
|
843
843
|
}
|
|
@@ -847,7 +847,7 @@ class Z {
|
|
|
847
847
|
async setTimezone(e) {
|
|
848
848
|
return typeof e != "string" ? o({
|
|
849
849
|
status: n.ERROR,
|
|
850
|
-
errorType:
|
|
850
|
+
errorType: c.VALIDATION_ERROR,
|
|
851
851
|
errorMessage: "provided timezone is invalid, must be string"
|
|
852
852
|
}) : this.setInternal({ $timezone: e });
|
|
853
853
|
}
|
|
@@ -870,7 +870,7 @@ class X {
|
|
|
870
870
|
if (await navigator.serviceWorker.register(`/${this.config.swFileName}`), await Notification.requestPermission() !== "granted")
|
|
871
871
|
return console.warn("[SuprSend]: Notification permission isnt granted"), o({
|
|
872
872
|
status: n.ERROR,
|
|
873
|
-
errorType:
|
|
873
|
+
errorType: c.PERMISSION_DENIED,
|
|
874
874
|
errorMessage: "Notification permission isn't granted"
|
|
875
875
|
});
|
|
876
876
|
const t = await navigator.serviceWorker.ready, s = await t.pushManager.getSubscription();
|
|
@@ -881,7 +881,7 @@ class X {
|
|
|
881
881
|
"[SuprSend]: Vapid key is missing. Add it while creating SuprSend instance"
|
|
882
882
|
), o({
|
|
883
883
|
status: n.ERROR,
|
|
884
|
-
errorType:
|
|
884
|
+
errorType: c.VALIDATION_ERROR,
|
|
885
885
|
errorMessage: "Vapid key is missing. Add it while creating SuprSend instance"
|
|
886
886
|
});
|
|
887
887
|
const r = await t.pushManager.subscribe({
|
|
@@ -892,7 +892,7 @@ class X {
|
|
|
892
892
|
} catch (e) {
|
|
893
893
|
return console.warn("SuprSend: Error getting push subscription", e), o({
|
|
894
894
|
status: n.ERROR,
|
|
895
|
-
errorType:
|
|
895
|
+
errorType: c.UNKNOWN_ERROR,
|
|
896
896
|
errorMessage: (e == null ? void 0 : e.message) || "Unknown error occured while registering for push"
|
|
897
897
|
});
|
|
898
898
|
}
|
|
@@ -906,7 +906,7 @@ class X {
|
|
|
906
906
|
async registerPush() {
|
|
907
907
|
return A() && "serviceWorker" in navigator && "PushManager" in window ? this.handleRegisterPush() : (console.warn("[SuprSend]: Webpush isn't supported"), o({
|
|
908
908
|
status: n.ERROR,
|
|
909
|
-
errorType:
|
|
909
|
+
errorType: c.UNSUPPORTED_ACTION,
|
|
910
910
|
errorMessage: "Webpush isn't supported"
|
|
911
911
|
}));
|
|
912
912
|
}
|
|
@@ -944,18 +944,17 @@ const F = 20, Y = "default", q = 100, D = {
|
|
|
944
944
|
apiHost: "https://inboxs.live",
|
|
945
945
|
socketHost: "https://betainbox.suprsend.com"
|
|
946
946
|
}
|
|
947
|
-
},
|
|
947
|
+
}, U = {
|
|
948
948
|
notifications: [],
|
|
949
949
|
store: D,
|
|
950
950
|
pageInfo: {
|
|
951
951
|
total: 0,
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
pageSize: F
|
|
952
|
+
pageSize: F,
|
|
953
|
+
hasMore: !1
|
|
955
954
|
},
|
|
956
955
|
meta: { badge: 0 },
|
|
957
956
|
apiStatus: _.INITIAL,
|
|
958
|
-
|
|
957
|
+
isFirstFetch: !0
|
|
959
958
|
};
|
|
960
959
|
class te {
|
|
961
960
|
constructor(e) {
|
|
@@ -1007,12 +1006,12 @@ class se {
|
|
|
1007
1006
|
return;
|
|
1008
1007
|
}
|
|
1009
1008
|
const r = s == null ? void 0 : s.query;
|
|
1010
|
-
let i,
|
|
1011
|
-
typeof (r == null ? void 0 : r.read) == "boolean" && (i = r.read), typeof (r == null ? void 0 : r.archived) == "boolean" && (
|
|
1009
|
+
let i, d, u = [], l = [];
|
|
1010
|
+
typeof (r == null ? void 0 : r.read) == "boolean" && (i = r.read), typeof (r == null ? void 0 : r.archived) == "boolean" && (d = 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({
|
|
1012
1011
|
storeId: s.storeId,
|
|
1013
1012
|
label: s.label || s.storeId,
|
|
1014
1013
|
query: {
|
|
1015
|
-
archived:
|
|
1014
|
+
archived: d,
|
|
1016
1015
|
read: i,
|
|
1017
1016
|
tags: u,
|
|
1018
1017
|
categories: l
|
|
@@ -1024,7 +1023,7 @@ class se {
|
|
|
1024
1023
|
return z()(() => {
|
|
1025
1024
|
var e;
|
|
1026
1025
|
return {
|
|
1027
|
-
...
|
|
1026
|
+
...U,
|
|
1028
1027
|
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) || D
|
|
1029
1028
|
};
|
|
1030
1029
|
});
|
|
@@ -1054,18 +1053,18 @@ class se {
|
|
|
1054
1053
|
return;
|
|
1055
1054
|
const s = t.body, r = this.store.getState();
|
|
1056
1055
|
let i = !1;
|
|
1057
|
-
const
|
|
1056
|
+
const d = { ...r.meta };
|
|
1058
1057
|
this.notificationBelongToStore(s, r.store) && (i = !0, this.store.setState({
|
|
1059
1058
|
notifications: this.orderNotificationsBasedOnPinFlag(
|
|
1060
1059
|
s,
|
|
1061
1060
|
r.notifications
|
|
1062
1061
|
)
|
|
1063
1062
|
})), (l = (u = this.feedOptions.stores) == null ? void 0 : u.map) == null || l.call(u, (h) => {
|
|
1064
|
-
this.notificationBelongToStore(s, h) && (i = !0,
|
|
1063
|
+
this.notificationBelongToStore(s, h) && (i = !0, d[h.storeId] = (r.meta[h.storeId] || 0) + 1);
|
|
1065
1064
|
}), this.store.setState({
|
|
1066
1065
|
meta: {
|
|
1067
|
-
...
|
|
1068
|
-
badge: i ?
|
|
1066
|
+
...d,
|
|
1067
|
+
badge: i ? d.badge + 1 : d.badge
|
|
1069
1068
|
}
|
|
1070
1069
|
}), i && this.emitter.emit("feed.new_notification", s), this.emitter.emit("feed.store_update", this.data);
|
|
1071
1070
|
}
|
|
@@ -1079,13 +1078,13 @@ class se {
|
|
|
1079
1078
|
if (t[0].status !== "fulfilled") return;
|
|
1080
1079
|
const r = t[0].value;
|
|
1081
1080
|
if (r.status === n.ERROR) return;
|
|
1082
|
-
const i = r.body,
|
|
1081
|
+
const i = r.body, d = (l = s.notifications) == null ? void 0 : l.some(
|
|
1083
1082
|
(h) => h.n_id === i.n_id
|
|
1084
1083
|
);
|
|
1085
1084
|
this.notificationBelongToStore(
|
|
1086
1085
|
i,
|
|
1087
1086
|
s.store
|
|
1088
|
-
) ?
|
|
1087
|
+
) ? d ? this.store.setState({
|
|
1089
1088
|
notifications: s.notifications.map((h) => h.n_id === i.n_id ? i : h)
|
|
1090
1089
|
}) : this.store.setState({
|
|
1091
1090
|
notifications: this.orderNotificationsBasedOnPinFlag(
|
|
@@ -1113,12 +1112,12 @@ class se {
|
|
|
1113
1112
|
}), this.emitter.emit("feed.store_update", this.data);
|
|
1114
1113
|
}
|
|
1115
1114
|
notificationBelongToStore(e, t) {
|
|
1116
|
-
var
|
|
1117
|
-
const s = !!e.read_on, r = e.archived, i = e.tags,
|
|
1118
|
-
let R = !1,
|
|
1115
|
+
var O, y, v, m;
|
|
1116
|
+
const s = !!e.read_on, r = e.archived, i = e.tags, d = e.n_category, u = (O = t == null ? void 0 : t.query) == null ? void 0 : O.read, l = (y = t == null ? void 0 : t.query) == null ? void 0 : y.archived, h = (v = t == null ? void 0 : t.query) == null ? void 0 : v.tags, T = (m = t == null ? void 0 : t.query) == null ? void 0 : m.categories, b = u == null || s === u, S = !!r == !!l;
|
|
1117
|
+
let R = !1, g = !1;
|
|
1119
1118
|
return Array.isArray(h) && h.length > 0 ? h.forEach((E) => {
|
|
1120
1119
|
i != null && i.includes(E) && (R = !0);
|
|
1121
|
-
}) : R = !0, Array.isArray(T) && T.length > 0 ? T.includes(
|
|
1120
|
+
}) : R = !0, Array.isArray(T) && T.length > 0 ? T.includes(d) && (g = !0) : g = !0, b && R && g && S;
|
|
1122
1121
|
}
|
|
1123
1122
|
orderNotificationsBasedOnPinFlag(e, t) {
|
|
1124
1123
|
if (e.is_pinned)
|
|
@@ -1143,8 +1142,8 @@ class se {
|
|
|
1143
1142
|
t && (this.store.setState({ notifications: s }), await this.fetchCount(), this.emitter.emit("feed.store_update", this.data));
|
|
1144
1143
|
}
|
|
1145
1144
|
getUrl(e, t) {
|
|
1146
|
-
var
|
|
1147
|
-
const s = `${(
|
|
1145
|
+
var d;
|
|
1146
|
+
const s = `${(d = this.feedOptions.host) == null ? void 0 : d.apiHost}/v1/feed/${e}`, r = this.validateQueryParams(t), i = new URLSearchParams(
|
|
1148
1147
|
r
|
|
1149
1148
|
).toString();
|
|
1150
1149
|
return i ? `${s}?${i}` : s;
|
|
@@ -1168,12 +1167,12 @@ class se {
|
|
|
1168
1167
|
return e == null ? void 0 : e.map((s) => this.storeQueryParamObj(s));
|
|
1169
1168
|
}
|
|
1170
1169
|
storeQueryParamObj(e) {
|
|
1171
|
-
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,
|
|
1170
|
+
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, d = t == null ? void 0 : t.archived;
|
|
1172
1171
|
return {
|
|
1173
1172
|
store_id: e.storeId,
|
|
1174
1173
|
query: {
|
|
1175
1174
|
read: i,
|
|
1176
|
-
archived:
|
|
1175
|
+
archived: d,
|
|
1177
1176
|
tags: { or: s },
|
|
1178
1177
|
categories: { or: r }
|
|
1179
1178
|
}
|
|
@@ -1187,13 +1186,13 @@ class se {
|
|
|
1187
1186
|
(i) => i.storeId === e
|
|
1188
1187
|
);
|
|
1189
1188
|
return s ? (this.store.setState({
|
|
1190
|
-
...
|
|
1189
|
+
...U,
|
|
1191
1190
|
store: s,
|
|
1192
1191
|
meta: t.meta
|
|
1193
1192
|
}), await this.fetch()) : {
|
|
1194
1193
|
status: n.ERROR,
|
|
1195
1194
|
error: {
|
|
1196
|
-
type:
|
|
1195
|
+
type: c.NOT_FOUND,
|
|
1197
1196
|
message: `store with storeId ${e} doesnt exist`
|
|
1198
1197
|
}
|
|
1199
1198
|
};
|
|
@@ -1228,45 +1227,47 @@ class se {
|
|
|
1228
1227
|
async fetch(e = {}) {
|
|
1229
1228
|
const t = this.store.getState();
|
|
1230
1229
|
if (this.requestInprogress()) return;
|
|
1231
|
-
const s = (e == null ? void 0 : e.
|
|
1232
|
-
|
|
1233
|
-
apiStatus: _.FETCHING_MORE
|
|
1234
|
-
}) : (this.store.setState({
|
|
1230
|
+
const s = (e == null ? void 0 : e.pageSize) || this.feedOptions.pageSize;
|
|
1231
|
+
t.isFirstFetch ? (this.store.setState({
|
|
1235
1232
|
apiStatus: _.LOADING
|
|
1236
|
-
}), this.fetchCount())
|
|
1237
|
-
|
|
1233
|
+
}), this.fetchCount()) : this.store.setState({
|
|
1234
|
+
apiStatus: _.FETCHING_MORE
|
|
1235
|
+
}), this.emitter.emit("feed.store_update", this.data);
|
|
1236
|
+
const r = {
|
|
1238
1237
|
distinct_id: this.config.distinctId,
|
|
1239
1238
|
tenant_id: this.feedOptions.tenantId,
|
|
1240
|
-
page_size:
|
|
1241
|
-
page_no: s,
|
|
1242
|
-
before: i,
|
|
1239
|
+
page_size: s,
|
|
1243
1240
|
store: t.store.storeId !== D.storeId ? this.storeQueryParamObj(t.store) : null
|
|
1244
|
-
}
|
|
1245
|
-
if (
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1241
|
+
};
|
|
1242
|
+
if (t.notifications.length > 0) {
|
|
1243
|
+
const u = t.notifications[t.notifications.length - 1];
|
|
1244
|
+
r.search_after = [
|
|
1245
|
+
u.is_pinned,
|
|
1246
|
+
u.created_on
|
|
1247
|
+
];
|
|
1248
|
+
} else
|
|
1249
|
+
r.search_after = [];
|
|
1250
|
+
const i = this.getUrl("notifications", r), d = await this.config.client().request({ type: "get", url: i });
|
|
1251
|
+
return d.status === n.ERROR ? (this.store.setState({ apiStatus: _.ERROR }), this.emitter.emit("feed.store_update", this.data), d) : (this.store.setState({
|
|
1249
1252
|
apiStatus: _.SUCCESS,
|
|
1250
|
-
notifications:
|
|
1253
|
+
notifications: t.isFirstFetch ? d.body.results : [...t.notifications, ...d.body.results],
|
|
1251
1254
|
pageInfo: {
|
|
1252
1255
|
...t.pageInfo,
|
|
1253
|
-
total:
|
|
1254
|
-
|
|
1255
|
-
totalPages: l.body.meta.total_pages
|
|
1256
|
+
total: d.body.meta.total_count,
|
|
1257
|
+
hasMore: d.body.meta.has_more
|
|
1256
1258
|
},
|
|
1257
|
-
|
|
1258
|
-
}), this.emitter.emit("feed.store_update", this.data), this.startExpiryTimer(),
|
|
1259
|
+
isFirstFetch: !1
|
|
1260
|
+
}), this.emitter.emit("feed.store_update", this.data), this.startExpiryTimer(), d);
|
|
1259
1261
|
}
|
|
1260
1262
|
// TODO: support other stores
|
|
1261
1263
|
async fetchNextPage() {
|
|
1262
|
-
|
|
1263
|
-
return e.pageInfo.currentPage >= e.pageInfo.totalPages ? {
|
|
1264
|
+
return this.store.getState().pageInfo.hasMore === !1 ? {
|
|
1264
1265
|
status: n.ERROR,
|
|
1265
1266
|
error: {
|
|
1266
|
-
type:
|
|
1267
|
+
type: c.VALIDATION_ERROR,
|
|
1267
1268
|
message: "No more pages to fetch"
|
|
1268
1269
|
}
|
|
1269
|
-
} : this.fetch(
|
|
1270
|
+
} : this.fetch();
|
|
1270
1271
|
}
|
|
1271
1272
|
async fetchCount() {
|
|
1272
1273
|
const e = {
|
|
@@ -1382,7 +1383,7 @@ class se {
|
|
|
1382
1383
|
reset() {
|
|
1383
1384
|
var e;
|
|
1384
1385
|
this.store.setState({
|
|
1385
|
-
...
|
|
1386
|
+
...U,
|
|
1386
1387
|
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) || D
|
|
1387
1388
|
}), this.emitter.emit("feed.store_update", this.data), this.expiryTimerId && (clearInterval(this.expiryTimerId), this.expiryTimerId = void 0);
|
|
1388
1389
|
}
|
|
@@ -1415,7 +1416,7 @@ class ue {
|
|
|
1415
1416
|
if (!this.userToken || !A()) return;
|
|
1416
1417
|
const t = x(this.userToken), s = (t.exp || 0) * 1e3, r = Date.now(), i = 1e3 * 30;
|
|
1417
1418
|
if (s && s > r) {
|
|
1418
|
-
const
|
|
1419
|
+
const d = s - r - i;
|
|
1419
1420
|
this.userTokenExpirationTimer && clearTimeout(this.userTokenExpirationTimer), this.userTokenExpirationTimer = setTimeout(async () => {
|
|
1420
1421
|
let u = "";
|
|
1421
1422
|
try {
|
|
@@ -1434,7 +1435,7 @@ class ue {
|
|
|
1434
1435
|
}
|
|
1435
1436
|
}
|
|
1436
1437
|
u && typeof u == "string" && this.identify(this.distinctId, u, this.authenticateOptions);
|
|
1437
|
-
},
|
|
1438
|
+
}, d);
|
|
1438
1439
|
}
|
|
1439
1440
|
}
|
|
1440
1441
|
client() {
|
|
@@ -1457,13 +1458,13 @@ class ue {
|
|
|
1457
1458
|
if (!e)
|
|
1458
1459
|
return o({
|
|
1459
1460
|
status: n.ERROR,
|
|
1460
|
-
errorType:
|
|
1461
|
+
errorType: c.VALIDATION_ERROR,
|
|
1461
1462
|
errorMessage: "distinctId is missing"
|
|
1462
1463
|
});
|
|
1463
1464
|
if (this.apiClient && this.distinctId && this.distinctId !== e)
|
|
1464
1465
|
return o({
|
|
1465
1466
|
status: n.ERROR,
|
|
1466
|
-
errorType:
|
|
1467
|
+
errorType: c.VALIDATION_ERROR,
|
|
1467
1468
|
errorMessage: "User already loggedin, reset current user to login new user"
|
|
1468
1469
|
});
|
|
1469
1470
|
if (this.apiClient && this.distinctId === e && this.userToken !== t)
|
|
@@ -1479,7 +1480,7 @@ class ue {
|
|
|
1479
1480
|
const i = await this.eventApi({
|
|
1480
1481
|
event: "$identify",
|
|
1481
1482
|
$insert_id: C(),
|
|
1482
|
-
$time:
|
|
1483
|
+
$time: P(),
|
|
1483
1484
|
properties: {
|
|
1484
1485
|
$identified_id: e
|
|
1485
1486
|
}
|
|
@@ -1500,12 +1501,12 @@ class ue {
|
|
|
1500
1501
|
return e ? (typeof t == "object" && (s = { ...s, ...t }), this.eventApi({
|
|
1501
1502
|
event: String(e),
|
|
1502
1503
|
$insert_id: C(),
|
|
1503
|
-
$time:
|
|
1504
|
+
$time: P(),
|
|
1504
1505
|
distinct_id: this.distinctId,
|
|
1505
1506
|
properties: s
|
|
1506
1507
|
})) : o({
|
|
1507
1508
|
status: n.ERROR,
|
|
1508
|
-
errorType:
|
|
1509
|
+
errorType: c.VALIDATION_ERROR,
|
|
1509
1510
|
errorMessage: "event name is missing"
|
|
1510
1511
|
});
|
|
1511
1512
|
}
|
|
@@ -1520,7 +1521,7 @@ class ue {
|
|
|
1520
1521
|
export {
|
|
1521
1522
|
_ as ApiResponseStatus,
|
|
1522
1523
|
w as ChannelLevelPreferenceOptions,
|
|
1523
|
-
|
|
1524
|
+
c as ERROR_TYPE,
|
|
1524
1525
|
se as Feed,
|
|
1525
1526
|
p as PreferenceOptions,
|
|
1526
1527
|
n as RESPONSE_STATUS,
|