@suprsend/web-sdk 4.1.0 → 4.1.2
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 +171 -161
- package/dist/es/index.js.map +1 -1
- package/dist/types/feed.d.ts +1 -0
- package/dist/types/interface.d.ts +1 -0
- package/dist/types/preferences.d.ts +6 -2
- package/package.json +1 -1
package/dist/es/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import K from "mitt";
|
|
|
5
5
|
import x from "jwt-decode";
|
|
6
6
|
import { createStore as B } from "zustand/vanilla";
|
|
7
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 || {}),
|
|
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 || {}), 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 N() {
|
|
10
10
|
let a = (/* @__PURE__ */ new Date()).getTime();
|
|
11
11
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
|
|
@@ -72,7 +72,7 @@ function X(a) {
|
|
|
72
72
|
}
|
|
73
73
|
async function Y(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((d) => d.toString(16).padStart(2, "0")).join("");
|
|
76
76
|
}
|
|
77
77
|
class U {
|
|
78
78
|
constructor(e) {
|
|
@@ -89,33 +89,36 @@ class U {
|
|
|
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) {
|
|
@@ -123,12 +126,12 @@ class U {
|
|
|
123
126
|
if (!this.config.distinctId)
|
|
124
127
|
return o({
|
|
125
128
|
status: n.ERROR,
|
|
126
|
-
errorType:
|
|
129
|
+
errorType: c.VALIDATION_ERROR,
|
|
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 = x(this.config.userToken),
|
|
131
|
-
if (
|
|
133
|
+
const i = x(this.config.userToken), d = (i.exp || 0) * 1e3, u = Date.now();
|
|
134
|
+
if (d <= u)
|
|
132
135
|
try {
|
|
133
136
|
const h = await this.config.authenticateOptions.refreshUserToken(
|
|
134
137
|
this.config.userToken,
|
|
@@ -143,20 +146,20 @@ class U {
|
|
|
143
146
|
}
|
|
144
147
|
}
|
|
145
148
|
try {
|
|
146
|
-
const i = await this.requestApiInstance(e),
|
|
149
|
+
const i = await this.requestApiInstance(e), d = await i.json(), u = (d == null ? void 0 : d.status) || (i.ok ? n.SUCCESS : n.ERROR);
|
|
147
150
|
return o({
|
|
148
151
|
status: u,
|
|
149
|
-
body:
|
|
152
|
+
body: d,
|
|
150
153
|
statusCode: i.status,
|
|
151
|
-
errorMessage: (s =
|
|
152
|
-
errorType: (r =
|
|
154
|
+
errorMessage: (s = d == null ? void 0 : d.error) == null ? void 0 : s.message,
|
|
155
|
+
errorType: (r = d == null ? void 0 : d.error) == null ? void 0 : r.type
|
|
153
156
|
});
|
|
154
157
|
} catch (i) {
|
|
155
158
|
return console.error(i), o({
|
|
156
159
|
status: n.ERROR,
|
|
157
160
|
statusCode: 500,
|
|
158
161
|
errorMessage: (i == null ? void 0 : i.message) || "network error",
|
|
159
|
-
errorType:
|
|
162
|
+
errorType: c.NETWORK_ERROR
|
|
160
163
|
});
|
|
161
164
|
}
|
|
162
165
|
}
|
|
@@ -235,7 +238,7 @@ class q {
|
|
|
235
238
|
if (!e)
|
|
236
239
|
return o({
|
|
237
240
|
status: n.ERROR,
|
|
238
|
-
errorType:
|
|
241
|
+
errorType: c.VALIDATION_ERROR,
|
|
239
242
|
errorMessage: "Category parameter is missing"
|
|
240
243
|
});
|
|
241
244
|
const s = {
|
|
@@ -248,57 +251,57 @@ class q {
|
|
|
248
251
|
/**
|
|
249
252
|
* Used to get user's all channel level preference.
|
|
250
253
|
*/
|
|
251
|
-
async getOverallChannelPreferences() {
|
|
252
|
-
const e = this.getUrl("channel_preference");
|
|
253
|
-
return await this.config.client().request({ type: "get", url:
|
|
254
|
+
async getOverallChannelPreferences(e) {
|
|
255
|
+
const t = { tenant_id: e == null ? void 0 : e.tenantId }, s = this.getUrl("channel_preference", t);
|
|
256
|
+
return await this.config.client().request({ type: "get", url: s });
|
|
254
257
|
}
|
|
255
258
|
async _updateCategoryPreferences(e, t, s, r) {
|
|
256
|
-
const i = this.getUrl(`category/${e}`, r),
|
|
259
|
+
const i = this.getUrl(`category/${e}`, r), d = await this.config.client().request({
|
|
257
260
|
type: "patch",
|
|
258
261
|
url: i,
|
|
259
262
|
payload: t
|
|
260
263
|
});
|
|
261
|
-
return
|
|
264
|
+
return d != null && d.error ? this.config.emitter.emit("preferences_error", d) : (Object.assign(s, d.body), this.config.emitter.emit("preferences_updated", {
|
|
262
265
|
status: n.SUCCESS,
|
|
263
266
|
statusCode: 200,
|
|
264
267
|
body: this.data
|
|
265
|
-
})),
|
|
268
|
+
})), d;
|
|
266
269
|
}
|
|
267
|
-
async _updateChannelPreferences(e) {
|
|
268
|
-
const
|
|
270
|
+
async _updateChannelPreferences(e, t) {
|
|
271
|
+
const s = this.getUrl("channel_preference", t), r = await this.config.client().request({
|
|
269
272
|
type: "patch",
|
|
270
|
-
url:
|
|
273
|
+
url: s,
|
|
271
274
|
payload: e
|
|
272
275
|
});
|
|
273
|
-
return
|
|
276
|
+
return r != null && r.error ? this.config.emitter.emit("preferences_error", r) : (await this.getPreferences(this.preferenceArgs), this.config.emitter.emit("preferences_updated", {
|
|
274
277
|
status: n.SUCCESS,
|
|
275
278
|
statusCode: 200,
|
|
276
279
|
body: this.data
|
|
277
|
-
})),
|
|
280
|
+
})), r;
|
|
278
281
|
}
|
|
279
282
|
/**
|
|
280
283
|
* Used to update user's category level preference.
|
|
281
284
|
*/
|
|
282
285
|
async updateCategoryPreference(e, t, s) {
|
|
283
|
-
var h, S,
|
|
286
|
+
var h, S, b, T, y;
|
|
284
287
|
if (!e || ![p.OPT_IN, p.OPT_OUT].includes(
|
|
285
288
|
t
|
|
286
289
|
))
|
|
287
290
|
return o({
|
|
288
291
|
status: n.ERROR,
|
|
289
|
-
errorType:
|
|
292
|
+
errorType: c.VALIDATION_ERROR,
|
|
290
293
|
errorMessage: e ? "Preference parameter is invalid" : "Category parameter is missing"
|
|
291
294
|
});
|
|
292
295
|
if (!this.data)
|
|
293
296
|
return o({
|
|
294
297
|
status: n.ERROR,
|
|
295
|
-
errorType:
|
|
298
|
+
errorType: c.VALIDATION_ERROR,
|
|
296
299
|
errorMessage: "Call getPreferences method before performing action"
|
|
297
300
|
});
|
|
298
301
|
if (!this.data.sections)
|
|
299
302
|
return o({
|
|
300
303
|
status: n.ERROR,
|
|
301
|
-
errorType:
|
|
304
|
+
errorType: c.VALIDATION_ERROR,
|
|
302
305
|
errorMessage: "Sections doesn't exist"
|
|
303
306
|
});
|
|
304
307
|
let r = null, i = !1;
|
|
@@ -315,7 +318,7 @@ class q {
|
|
|
315
318
|
} else
|
|
316
319
|
return o({
|
|
317
320
|
status: n.ERROR,
|
|
318
|
-
errorType:
|
|
321
|
+
errorType: c.VALIDATION_ERROR,
|
|
319
322
|
errorMessage: "Category preference is not editable"
|
|
320
323
|
});
|
|
321
324
|
if (g) break;
|
|
@@ -324,7 +327,7 @@ class q {
|
|
|
324
327
|
if (!r)
|
|
325
328
|
return o({
|
|
326
329
|
status: n.ERROR,
|
|
327
|
-
errorType:
|
|
330
|
+
errorType: c.VALIDATION_ERROR,
|
|
328
331
|
errorMessage: "Category not found"
|
|
329
332
|
});
|
|
330
333
|
if (!i)
|
|
@@ -332,15 +335,15 @@ class q {
|
|
|
332
335
|
status: n.SUCCESS,
|
|
333
336
|
body: this.data
|
|
334
337
|
});
|
|
335
|
-
const
|
|
338
|
+
const d = [];
|
|
336
339
|
(h = r == null ? void 0 : r.channels) == null || h.forEach((R) => {
|
|
337
|
-
R.preference === p.OPT_OUT &&
|
|
340
|
+
R.preference === p.OPT_OUT && d.push(R.channel);
|
|
338
341
|
});
|
|
339
342
|
let u = !0;
|
|
340
343
|
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);
|
|
341
344
|
const l = {
|
|
342
345
|
preference: r.preference,
|
|
343
|
-
opt_out_channels: u && t === p.OPT_IN ? null :
|
|
346
|
+
opt_out_channels: u && t === p.OPT_IN ? null : d
|
|
344
347
|
};
|
|
345
348
|
return this.debouncedUpdateCategoryPreferences(
|
|
346
349
|
e,
|
|
@@ -348,7 +351,7 @@ class q {
|
|
|
348
351
|
l,
|
|
349
352
|
r,
|
|
350
353
|
{
|
|
351
|
-
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),
|
|
352
355
|
show_opt_out_channels: u,
|
|
353
356
|
tags: (s == null ? void 0 : s.tags) || ((T = this.preferenceArgs) == null ? void 0 : T.tags),
|
|
354
357
|
locale: (s == null ? void 0 : s.locale) || ((y = this.preferenceArgs) == null ? void 0 : y.locale)
|
|
@@ -366,7 +369,7 @@ class q {
|
|
|
366
369
|
if (!e || !s)
|
|
367
370
|
return o({
|
|
368
371
|
status: n.ERROR,
|
|
369
|
-
errorType:
|
|
372
|
+
errorType: c.VALIDATION_ERROR,
|
|
370
373
|
errorMessage: e ? "Category parameter is missing" : "Channel parameter is missing"
|
|
371
374
|
});
|
|
372
375
|
if (![p.OPT_IN, p.OPT_OUT].includes(
|
|
@@ -374,57 +377,57 @@ class q {
|
|
|
374
377
|
))
|
|
375
378
|
return o({
|
|
376
379
|
status: n.ERROR,
|
|
377
|
-
errorType:
|
|
380
|
+
errorType: c.VALIDATION_ERROR,
|
|
378
381
|
errorMessage: "Preference parameter is invalid"
|
|
379
382
|
});
|
|
380
383
|
if (!this.data)
|
|
381
384
|
return o({
|
|
382
385
|
status: n.ERROR,
|
|
383
|
-
errorType:
|
|
386
|
+
errorType: c.VALIDATION_ERROR,
|
|
384
387
|
errorMessage: "Call getPreferences method before performing action"
|
|
385
388
|
});
|
|
386
389
|
if (!this.data.sections)
|
|
387
390
|
return o({
|
|
388
391
|
status: n.ERROR,
|
|
389
|
-
errorType:
|
|
392
|
+
errorType: c.VALIDATION_ERROR,
|
|
390
393
|
errorMessage: "Sections doesn't exist"
|
|
391
394
|
});
|
|
392
|
-
let i = null,
|
|
395
|
+
let i = null, d = null, u = !1;
|
|
393
396
|
for (const m of this.data.sections) {
|
|
394
|
-
let
|
|
397
|
+
let v = !1;
|
|
395
398
|
if (m.subcategories) {
|
|
396
399
|
for (const E of m.subcategories) {
|
|
397
400
|
if (E.category === s) {
|
|
398
401
|
if (i = E, !E.channels) continue;
|
|
399
402
|
for (const w of E.channels)
|
|
400
403
|
if (w.channel === e)
|
|
401
|
-
if (
|
|
404
|
+
if (d = w, w.is_editable) {
|
|
402
405
|
if (w.preference !== t) {
|
|
403
|
-
w.preference = t, t === p.OPT_IN && (E.preference = p.OPT_IN), u = !0,
|
|
406
|
+
w.preference = t, t === p.OPT_IN && (E.preference = p.OPT_IN), u = !0, v = !0;
|
|
404
407
|
break;
|
|
405
408
|
}
|
|
406
409
|
} else
|
|
407
410
|
return o({
|
|
408
411
|
status: n.ERROR,
|
|
409
|
-
errorType:
|
|
412
|
+
errorType: c.VALIDATION_ERROR,
|
|
410
413
|
errorMessage: "Channel preference is not editable"
|
|
411
414
|
});
|
|
412
415
|
}
|
|
413
|
-
if (
|
|
416
|
+
if (v) break;
|
|
414
417
|
}
|
|
415
|
-
if (
|
|
418
|
+
if (v) break;
|
|
416
419
|
}
|
|
417
420
|
}
|
|
418
421
|
if (!i)
|
|
419
422
|
return o({
|
|
420
423
|
status: n.ERROR,
|
|
421
|
-
errorType:
|
|
424
|
+
errorType: c.VALIDATION_ERROR,
|
|
422
425
|
errorMessage: "Category not found"
|
|
423
426
|
});
|
|
424
|
-
if (!
|
|
427
|
+
if (!d)
|
|
425
428
|
return o({
|
|
426
429
|
status: n.ERROR,
|
|
427
|
-
errorType:
|
|
430
|
+
errorType: c.VALIDATION_ERROR,
|
|
428
431
|
errorMessage: "Category's channel not found"
|
|
429
432
|
});
|
|
430
433
|
if (!u)
|
|
@@ -438,14 +441,14 @@ class q {
|
|
|
438
441
|
});
|
|
439
442
|
let h = !0;
|
|
440
443
|
typeof (r == null ? void 0 : r.showOptOutChannels) == "boolean" ? h = r == null ? void 0 : r.showOptOutChannels : typeof ((y = this.preferenceArgs) == null ? void 0 : y.showOptOutChannels) == "boolean" && (h = this.preferenceArgs.showOptOutChannels);
|
|
441
|
-
const
|
|
444
|
+
const b = {
|
|
442
445
|
preference: h && i.preference === p.OPT_OUT && t === p.OPT_IN ? p.OPT_IN : i.preference,
|
|
443
446
|
opt_out_channels: l
|
|
444
447
|
};
|
|
445
448
|
return this.debouncedUpdateCategoryPreferences(
|
|
446
449
|
s,
|
|
447
450
|
s,
|
|
448
|
-
|
|
451
|
+
b,
|
|
449
452
|
i,
|
|
450
453
|
{
|
|
451
454
|
tenant_id: (r == null ? void 0 : r.tenantId) || ((R = this.preferenceArgs) == null ? void 0 : R.tenantId),
|
|
@@ -461,38 +464,41 @@ class q {
|
|
|
461
464
|
/**
|
|
462
465
|
* Used to update user's channel level preference.
|
|
463
466
|
*/
|
|
464
|
-
async updateOverallChannelPreference(e, t) {
|
|
467
|
+
async updateOverallChannelPreference(e, t, s) {
|
|
468
|
+
var u;
|
|
465
469
|
if (!e || ![
|
|
466
|
-
|
|
467
|
-
|
|
470
|
+
C.ALL,
|
|
471
|
+
C.REQUIRED
|
|
468
472
|
].includes(t))
|
|
469
473
|
return o({
|
|
470
474
|
status: n.ERROR,
|
|
471
|
-
errorType:
|
|
475
|
+
errorType: c.VALIDATION_ERROR,
|
|
472
476
|
errorMessage: e ? "Preference parameter is invalid" : "Channel parameter is missing"
|
|
473
477
|
});
|
|
474
478
|
if (!this.data)
|
|
475
479
|
return o({
|
|
476
480
|
status: n.ERROR,
|
|
477
|
-
errorType:
|
|
481
|
+
errorType: c.VALIDATION_ERROR,
|
|
478
482
|
errorMessage: "Call getPreferences method before performing action"
|
|
479
483
|
});
|
|
480
484
|
if (!this.data.channel_preferences)
|
|
481
485
|
return o({
|
|
482
486
|
status: n.ERROR,
|
|
483
|
-
errorType:
|
|
487
|
+
errorType: c.VALIDATION_ERROR,
|
|
484
488
|
errorMessage: "Channel preferences doesn't exist"
|
|
485
489
|
});
|
|
486
|
-
let
|
|
487
|
-
const
|
|
488
|
-
for (const
|
|
489
|
-
if (
|
|
490
|
-
|
|
490
|
+
let r = null, i = !1;
|
|
491
|
+
const d = t === C.REQUIRED;
|
|
492
|
+
for (const l of this.data.channel_preferences)
|
|
493
|
+
if (l.channel === e && (r = l, l.is_restricted !== d)) {
|
|
494
|
+
l.is_restricted = d, i = !0;
|
|
491
495
|
break;
|
|
492
496
|
}
|
|
493
|
-
return
|
|
494
|
-
|
|
495
|
-
|
|
497
|
+
return r ? i ? (this.debouncedUpdateChannelPreferences(
|
|
498
|
+
r.channel,
|
|
499
|
+
{ channel_preferences: [r] },
|
|
500
|
+
{ tenant_id: (s == null ? void 0 : s.tenantId) || ((u = this.preferenceArgs) == null ? void 0 : u.tenantId) }
|
|
501
|
+
), o({
|
|
496
502
|
status: n.SUCCESS,
|
|
497
503
|
body: this.data
|
|
498
504
|
})) : o({
|
|
@@ -500,7 +506,7 @@ class q {
|
|
|
500
506
|
body: this.data
|
|
501
507
|
}) : o({
|
|
502
508
|
status: n.ERROR,
|
|
503
|
-
errorType:
|
|
509
|
+
errorType: c.VALIDATION_ERROR,
|
|
504
510
|
errorMessage: "Channel data not found"
|
|
505
511
|
});
|
|
506
512
|
}
|
|
@@ -526,14 +532,14 @@ class ee {
|
|
|
526
532
|
}
|
|
527
533
|
validateObjData(e, t) {
|
|
528
534
|
const s = {}, r = (t == null ? void 0 : t.allowReservedKeys) || !1, i = (t == null ? void 0 : t.valueType) || "";
|
|
529
|
-
for (const
|
|
530
|
-
let u = e[
|
|
531
|
-
if (!(
|
|
532
|
-
if (!r && this.isReservedKey(
|
|
535
|
+
for (const d in e) {
|
|
536
|
+
let u = e[d];
|
|
537
|
+
if (!(d && u === void 0)) {
|
|
538
|
+
if (!r && this.isReservedKey(d)) {
|
|
533
539
|
console.warn("[SuprSend]: key cannot start with $ or ss_");
|
|
534
540
|
continue;
|
|
535
541
|
}
|
|
536
|
-
i === "number" ? u = Number(u) : i === "boolean" && (u = !!u), s[
|
|
542
|
+
i === "number" ? u = Number(u) : i === "boolean" && (u = !!u), s[d] = u;
|
|
537
543
|
}
|
|
538
544
|
}
|
|
539
545
|
return s;
|
|
@@ -566,13 +572,13 @@ class ee {
|
|
|
566
572
|
if (!s)
|
|
567
573
|
return o({
|
|
568
574
|
status: n.ERROR,
|
|
569
|
-
errorType:
|
|
575
|
+
errorType: c.VALIDATION_ERROR,
|
|
570
576
|
errorMessage: "data provided is empty"
|
|
571
577
|
});
|
|
572
578
|
const r = this.validateObjData(s);
|
|
573
579
|
return I(r) ? o({
|
|
574
580
|
status: n.ERROR,
|
|
575
|
-
errorType:
|
|
581
|
+
errorType: c.VALIDATION_ERROR,
|
|
576
582
|
errorMessage: "data provided is empty"
|
|
577
583
|
}) : this.triggerUserEvent({ $set: r });
|
|
578
584
|
}
|
|
@@ -585,13 +591,13 @@ class ee {
|
|
|
585
591
|
if (!s)
|
|
586
592
|
return o({
|
|
587
593
|
status: n.ERROR,
|
|
588
|
-
errorType:
|
|
594
|
+
errorType: c.VALIDATION_ERROR,
|
|
589
595
|
errorMessage: "data provided is empty"
|
|
590
596
|
});
|
|
591
597
|
const r = this.validateObjData(s);
|
|
592
598
|
return I(r) ? o({
|
|
593
599
|
status: n.ERROR,
|
|
594
|
-
errorType:
|
|
600
|
+
errorType: c.VALIDATION_ERROR,
|
|
595
601
|
errorMessage: "data provided is empty"
|
|
596
602
|
}) : this.triggerUserEvent({ $set_once: r });
|
|
597
603
|
}
|
|
@@ -604,13 +610,13 @@ class ee {
|
|
|
604
610
|
if (!s)
|
|
605
611
|
return o({
|
|
606
612
|
status: n.ERROR,
|
|
607
|
-
errorType:
|
|
613
|
+
errorType: c.VALIDATION_ERROR,
|
|
608
614
|
errorMessage: "data provided is empty"
|
|
609
615
|
});
|
|
610
616
|
const r = this.validateObjData(s, { valueType: "number" });
|
|
611
617
|
return I(r) ? o({
|
|
612
618
|
status: n.ERROR,
|
|
613
|
-
errorType:
|
|
619
|
+
errorType: c.VALIDATION_ERROR,
|
|
614
620
|
errorMessage: "data provided is empty"
|
|
615
621
|
}) : this.triggerUserEvent({ $add: r });
|
|
616
622
|
}
|
|
@@ -623,13 +629,13 @@ class ee {
|
|
|
623
629
|
if (!s)
|
|
624
630
|
return o({
|
|
625
631
|
status: n.ERROR,
|
|
626
|
-
errorType:
|
|
632
|
+
errorType: c.VALIDATION_ERROR,
|
|
627
633
|
errorMessage: "data provided is empty"
|
|
628
634
|
});
|
|
629
635
|
const r = this.validateObjData(s);
|
|
630
636
|
return I(r) ? o({
|
|
631
637
|
status: n.ERROR,
|
|
632
|
-
errorType:
|
|
638
|
+
errorType: c.VALIDATION_ERROR,
|
|
633
639
|
errorMessage: "data provided is empty"
|
|
634
640
|
}) : this.triggerUserEvent({ $append: r });
|
|
635
641
|
}
|
|
@@ -642,13 +648,13 @@ class ee {
|
|
|
642
648
|
if (!s)
|
|
643
649
|
return o({
|
|
644
650
|
status: n.ERROR,
|
|
645
|
-
errorType:
|
|
651
|
+
errorType: c.VALIDATION_ERROR,
|
|
646
652
|
errorMessage: "data provided is empty"
|
|
647
653
|
});
|
|
648
654
|
const r = this.validateObjData(s);
|
|
649
655
|
return I(r) ? o({
|
|
650
656
|
status: n.ERROR,
|
|
651
|
-
errorType:
|
|
657
|
+
errorType: c.VALIDATION_ERROR,
|
|
652
658
|
errorMessage: "data provided is empty"
|
|
653
659
|
}) : this.triggerUserEvent({ $remove: r });
|
|
654
660
|
}
|
|
@@ -660,13 +666,13 @@ class ee {
|
|
|
660
666
|
if (!t)
|
|
661
667
|
return o({
|
|
662
668
|
status: n.ERROR,
|
|
663
|
-
errorType:
|
|
669
|
+
errorType: c.VALIDATION_ERROR,
|
|
664
670
|
errorMessage: "data provided is empty"
|
|
665
671
|
});
|
|
666
672
|
const s = this.validateArrayData(t);
|
|
667
673
|
return G(s) ? o({
|
|
668
674
|
status: n.ERROR,
|
|
669
|
-
errorType:
|
|
675
|
+
errorType: c.VALIDATION_ERROR,
|
|
670
676
|
errorMessage: "data provided is empty"
|
|
671
677
|
}) : this.triggerUserEvent({ $unset: s });
|
|
672
678
|
}
|
|
@@ -676,7 +682,7 @@ class ee {
|
|
|
676
682
|
if (!s)
|
|
677
683
|
return o({
|
|
678
684
|
status: n.ERROR,
|
|
679
|
-
errorType:
|
|
685
|
+
errorType: c.VALIDATION_ERROR,
|
|
680
686
|
errorMessage: "data provided is empty"
|
|
681
687
|
});
|
|
682
688
|
const r = this.validateObjData(s, {
|
|
@@ -684,7 +690,7 @@ class ee {
|
|
|
684
690
|
});
|
|
685
691
|
return I(r) ? o({
|
|
686
692
|
status: n.ERROR,
|
|
687
|
-
errorType:
|
|
693
|
+
errorType: c.VALIDATION_ERROR,
|
|
688
694
|
errorMessage: "data provided is empty"
|
|
689
695
|
}) : this.triggerUserEvent({ $append: r });
|
|
690
696
|
}
|
|
@@ -694,7 +700,7 @@ class ee {
|
|
|
694
700
|
if (!s)
|
|
695
701
|
return o({
|
|
696
702
|
status: n.ERROR,
|
|
697
|
-
errorType:
|
|
703
|
+
errorType: c.VALIDATION_ERROR,
|
|
698
704
|
errorMessage: "data provided is empty"
|
|
699
705
|
});
|
|
700
706
|
const r = this.validateObjData(s, {
|
|
@@ -702,7 +708,7 @@ class ee {
|
|
|
702
708
|
});
|
|
703
709
|
return I(r) ? o({
|
|
704
710
|
status: n.ERROR,
|
|
705
|
-
errorType:
|
|
711
|
+
errorType: c.VALIDATION_ERROR,
|
|
706
712
|
errorMessage: "data provided is empty"
|
|
707
713
|
}) : this.triggerUserEvent({ $remove: r });
|
|
708
714
|
}
|
|
@@ -711,7 +717,7 @@ class ee {
|
|
|
711
717
|
if (!s)
|
|
712
718
|
return o({
|
|
713
719
|
status: n.ERROR,
|
|
714
|
-
errorType:
|
|
720
|
+
errorType: c.VALIDATION_ERROR,
|
|
715
721
|
errorMessage: "data provided is empty"
|
|
716
722
|
});
|
|
717
723
|
const r = this.validateObjData(s, {
|
|
@@ -719,7 +725,7 @@ class ee {
|
|
|
719
725
|
});
|
|
720
726
|
return I(r) ? o({
|
|
721
727
|
status: n.ERROR,
|
|
722
|
-
errorType:
|
|
728
|
+
errorType: c.VALIDATION_ERROR,
|
|
723
729
|
errorMessage: "data provided is empty"
|
|
724
730
|
}) : this.triggerUserEvent({ $set: r });
|
|
725
731
|
}
|
|
@@ -732,14 +738,14 @@ class ee {
|
|
|
732
738
|
async addEmail(e) {
|
|
733
739
|
return this.validateEmail(e) ? this.appendInternal({ $email: e }) : o({
|
|
734
740
|
status: n.ERROR,
|
|
735
|
-
errorType:
|
|
741
|
+
errorType: c.VALIDATION_ERROR,
|
|
736
742
|
errorMessage: "provided email is invalid"
|
|
737
743
|
});
|
|
738
744
|
}
|
|
739
745
|
async removeEmail(e) {
|
|
740
746
|
return this.validateEmail(e) ? this.removeInternal({ $email: e }) : o({
|
|
741
747
|
status: n.ERROR,
|
|
742
|
-
errorType:
|
|
748
|
+
errorType: c.VALIDATION_ERROR,
|
|
743
749
|
errorMessage: "provided email is invalid"
|
|
744
750
|
});
|
|
745
751
|
}
|
|
@@ -749,7 +755,7 @@ class ee {
|
|
|
749
755
|
async addSms(e) {
|
|
750
756
|
return this.validateMobile(e) ? this.appendInternal({ $sms: e }) : o({
|
|
751
757
|
status: n.ERROR,
|
|
752
|
-
errorType:
|
|
758
|
+
errorType: c.VALIDATION_ERROR,
|
|
753
759
|
errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
|
|
754
760
|
});
|
|
755
761
|
}
|
|
@@ -759,7 +765,7 @@ class ee {
|
|
|
759
765
|
async removeSms(e) {
|
|
760
766
|
return this.validateMobile(e) ? this.removeInternal({ $sms: e }) : o({
|
|
761
767
|
status: n.ERROR,
|
|
762
|
-
errorType:
|
|
768
|
+
errorType: c.VALIDATION_ERROR,
|
|
763
769
|
errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
|
|
764
770
|
});
|
|
765
771
|
}
|
|
@@ -769,7 +775,7 @@ class ee {
|
|
|
769
775
|
async addWhatsapp(e) {
|
|
770
776
|
return this.validateMobile(e) ? this.appendInternal({ $whatsapp: e }) : o({
|
|
771
777
|
status: n.ERROR,
|
|
772
|
-
errorType:
|
|
778
|
+
errorType: c.VALIDATION_ERROR,
|
|
773
779
|
errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
|
|
774
780
|
});
|
|
775
781
|
}
|
|
@@ -779,7 +785,7 @@ class ee {
|
|
|
779
785
|
async removeWhatsapp(e) {
|
|
780
786
|
return this.validateMobile(e) ? this.removeInternal({ $whatsapp: e }) : o({
|
|
781
787
|
status: n.ERROR,
|
|
782
|
-
errorType:
|
|
788
|
+
errorType: c.VALIDATION_ERROR,
|
|
783
789
|
errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
|
|
784
790
|
});
|
|
785
791
|
}
|
|
@@ -791,7 +797,7 @@ class ee {
|
|
|
791
797
|
if (typeof e != "object")
|
|
792
798
|
return o({
|
|
793
799
|
status: n.ERROR,
|
|
794
|
-
errorType:
|
|
800
|
+
errorType: c.VALIDATION_ERROR,
|
|
795
801
|
errorMessage: "provided push subscription is invalid, must be an object"
|
|
796
802
|
});
|
|
797
803
|
const t = this.getDeviceId();
|
|
@@ -805,7 +811,7 @@ class ee {
|
|
|
805
811
|
if (typeof e != "object")
|
|
806
812
|
return o({
|
|
807
813
|
status: n.ERROR,
|
|
808
|
-
errorType:
|
|
814
|
+
errorType: c.VALIDATION_ERROR,
|
|
809
815
|
errorMessage: "provided push subscription is invalid, must be an object"
|
|
810
816
|
});
|
|
811
817
|
const t = this.getDeviceId();
|
|
@@ -818,28 +824,28 @@ class ee {
|
|
|
818
824
|
async addSlack(e) {
|
|
819
825
|
return typeof e != "object" ? o({
|
|
820
826
|
status: n.ERROR,
|
|
821
|
-
errorType:
|
|
827
|
+
errorType: c.VALIDATION_ERROR,
|
|
822
828
|
errorMessage: "provided slack data is invalid, must be an object"
|
|
823
829
|
}) : this.appendInternal({ $slack: e });
|
|
824
830
|
}
|
|
825
831
|
async removeSlack(e) {
|
|
826
832
|
return typeof e != "object" ? o({
|
|
827
833
|
status: n.ERROR,
|
|
828
|
-
errorType:
|
|
834
|
+
errorType: c.VALIDATION_ERROR,
|
|
829
835
|
errorMessage: "provided slack data is invalid, must be an object"
|
|
830
836
|
}) : this.removeInternal({ $slack: e });
|
|
831
837
|
}
|
|
832
838
|
async addMSTeams(e) {
|
|
833
839
|
return typeof e != "object" ? o({
|
|
834
840
|
status: n.ERROR,
|
|
835
|
-
errorType:
|
|
841
|
+
errorType: c.VALIDATION_ERROR,
|
|
836
842
|
errorMessage: "provided ms_teams data is invalid, must be object"
|
|
837
843
|
}) : this.appendInternal({ $ms_teams: e });
|
|
838
844
|
}
|
|
839
845
|
async removeMSTeams(e) {
|
|
840
846
|
return typeof e != "object" ? o({
|
|
841
847
|
status: n.ERROR,
|
|
842
|
-
errorType:
|
|
848
|
+
errorType: c.VALIDATION_ERROR,
|
|
843
849
|
errorMessage: "provided ms_teams data is invalid, must be object"
|
|
844
850
|
}) : this.removeInternal({ $ms_teams: e });
|
|
845
851
|
}
|
|
@@ -850,7 +856,7 @@ class ee {
|
|
|
850
856
|
async setPreferredLanguage(e) {
|
|
851
857
|
return typeof e != "string" ? o({
|
|
852
858
|
status: n.ERROR,
|
|
853
|
-
errorType:
|
|
859
|
+
errorType: c.VALIDATION_ERROR,
|
|
854
860
|
errorMessage: "provided language is invalid, must be string"
|
|
855
861
|
}) : this.setInternal({ $preferred_language: e });
|
|
856
862
|
}
|
|
@@ -860,7 +866,7 @@ class ee {
|
|
|
860
866
|
async setTimezone(e) {
|
|
861
867
|
return typeof e != "string" ? o({
|
|
862
868
|
status: n.ERROR,
|
|
863
|
-
errorType:
|
|
869
|
+
errorType: c.VALIDATION_ERROR,
|
|
864
870
|
errorMessage: "provided timezone is invalid, must be string"
|
|
865
871
|
}) : this.setInternal({ $timezone: e });
|
|
866
872
|
}
|
|
@@ -898,7 +904,7 @@ class te {
|
|
|
898
904
|
if (await navigator.serviceWorker.register(`/${this.config.swFileName}`), await Notification.requestPermission() !== "granted")
|
|
899
905
|
return console.warn("[SuprSend]: Notification permission isnt granted"), o({
|
|
900
906
|
status: n.ERROR,
|
|
901
|
-
errorType:
|
|
907
|
+
errorType: c.PERMISSION_DENIED,
|
|
902
908
|
errorMessage: "Notification permission isn't granted"
|
|
903
909
|
});
|
|
904
910
|
const t = await navigator.serviceWorker.ready, s = await t.pushManager.getSubscription();
|
|
@@ -909,7 +915,7 @@ class te {
|
|
|
909
915
|
"[SuprSend]: Vapid key is missing. Add it while creating SuprSend instance"
|
|
910
916
|
), o({
|
|
911
917
|
status: n.ERROR,
|
|
912
|
-
errorType:
|
|
918
|
+
errorType: c.VALIDATION_ERROR,
|
|
913
919
|
errorMessage: "Vapid key is missing. Add it while creating SuprSend instance"
|
|
914
920
|
});
|
|
915
921
|
const r = await t.pushManager.subscribe({
|
|
@@ -920,7 +926,7 @@ class te {
|
|
|
920
926
|
} catch (e) {
|
|
921
927
|
return console.warn("SuprSend: Error getting push subscription", e), o({
|
|
922
928
|
status: n.ERROR,
|
|
923
|
-
errorType:
|
|
929
|
+
errorType: c.UNKNOWN_ERROR,
|
|
924
930
|
errorMessage: (e == null ? void 0 : e.message) || "Unknown error occured while registering for push"
|
|
925
931
|
});
|
|
926
932
|
}
|
|
@@ -934,7 +940,7 @@ class te {
|
|
|
934
940
|
async registerPush() {
|
|
935
941
|
return A() && "serviceWorker" in navigator && "PushManager" in window ? this.handleRegisterPush() : (console.warn("[SuprSend]: Webpush isn't supported"), o({
|
|
936
942
|
status: n.ERROR,
|
|
937
|
-
errorType:
|
|
943
|
+
errorType: c.UNSUPPORTED_ACTION,
|
|
938
944
|
errorMessage: "Webpush isn't supported"
|
|
939
945
|
}));
|
|
940
946
|
}
|
|
@@ -961,7 +967,7 @@ class te {
|
|
|
961
967
|
return !!await this.getPushSubscription();
|
|
962
968
|
}
|
|
963
969
|
}
|
|
964
|
-
const W = 20, se = "default", re = 100,
|
|
970
|
+
const W = 20, se = "default", re = 100, D = {
|
|
965
971
|
storeId: "$suprsend_default_store",
|
|
966
972
|
label: ""
|
|
967
973
|
}, ie = {
|
|
@@ -974,7 +980,7 @@ const W = 20, se = "default", re = 100, C = {
|
|
|
974
980
|
}
|
|
975
981
|
}, P = {
|
|
976
982
|
notifications: [],
|
|
977
|
-
store:
|
|
983
|
+
store: D,
|
|
978
984
|
pageInfo: {
|
|
979
985
|
total: 0,
|
|
980
986
|
pageSize: W,
|
|
@@ -1012,6 +1018,7 @@ class ae {
|
|
|
1012
1018
|
f(this, "store");
|
|
1013
1019
|
f(this, "socket");
|
|
1014
1020
|
f(this, "expiryTimerId");
|
|
1021
|
+
f(this, "fetchAbortController");
|
|
1015
1022
|
f(this, "emitter", K());
|
|
1016
1023
|
this.config = e, this.setOptions(t), this.store = this.createFeedStore();
|
|
1017
1024
|
}
|
|
@@ -1034,12 +1041,12 @@ class ae {
|
|
|
1034
1041
|
return;
|
|
1035
1042
|
}
|
|
1036
1043
|
const r = s == null ? void 0 : s.query;
|
|
1037
|
-
let i,
|
|
1038
|
-
typeof (r == null ? void 0 : r.read) == "boolean" && (i = r.read), typeof (r == null ? void 0 : r.archived) == "boolean" && (
|
|
1044
|
+
let i, d, u = [], l = [];
|
|
1045
|
+
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({
|
|
1039
1046
|
storeId: s.storeId,
|
|
1040
1047
|
label: s.label || s.storeId,
|
|
1041
1048
|
query: {
|
|
1042
|
-
archived:
|
|
1049
|
+
archived: d,
|
|
1043
1050
|
read: i,
|
|
1044
1051
|
tags: u,
|
|
1045
1052
|
categories: l
|
|
@@ -1052,7 +1059,7 @@ class ae {
|
|
|
1052
1059
|
var e;
|
|
1053
1060
|
return {
|
|
1054
1061
|
...P,
|
|
1055
|
-
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) ||
|
|
1062
|
+
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) || D
|
|
1056
1063
|
};
|
|
1057
1064
|
});
|
|
1058
1065
|
}
|
|
@@ -1060,8 +1067,8 @@ class ae {
|
|
|
1060
1067
|
this.socket.on("connect_error", async (e) => {
|
|
1061
1068
|
var t;
|
|
1062
1069
|
if (e.message === "Authentication Error: wrong auth token" && ((t = this.config.authenticateOptions) != null && t.refreshUserToken) && this.config.userToken) {
|
|
1063
|
-
const s = this.socket.auth["x-ss-signature"], r = x(s), i = (r.exp || 0) * 1e3,
|
|
1064
|
-
if (i <=
|
|
1070
|
+
const s = this.socket.auth["x-ss-signature"], r = x(s), i = (r.exp || 0) * 1e3, d = Date.now();
|
|
1071
|
+
if (i <= d)
|
|
1065
1072
|
try {
|
|
1066
1073
|
const l = await this.config.authenticateOptions.refreshUserToken(
|
|
1067
1074
|
this.config.userToken,
|
|
@@ -1101,18 +1108,18 @@ class ae {
|
|
|
1101
1108
|
return;
|
|
1102
1109
|
const s = t.body, r = this.store.getState();
|
|
1103
1110
|
let i = !1;
|
|
1104
|
-
const
|
|
1111
|
+
const d = { ...r.meta };
|
|
1105
1112
|
this.notificationBelongToStore(s, r.store) && (i = !0, this.store.setState({
|
|
1106
1113
|
notifications: this.orderNotificationsBasedOnPinFlag(
|
|
1107
1114
|
s,
|
|
1108
1115
|
r.notifications
|
|
1109
1116
|
)
|
|
1110
1117
|
})), (l = (u = this.feedOptions.stores) == null ? void 0 : u.map) == null || l.call(u, (h) => {
|
|
1111
|
-
this.notificationBelongToStore(s, h) && (i = !0,
|
|
1118
|
+
this.notificationBelongToStore(s, h) && (i = !0, d[h.storeId] = (r.meta[h.storeId] || 0) + 1);
|
|
1112
1119
|
}), this.store.setState({
|
|
1113
1120
|
meta: {
|
|
1114
|
-
...
|
|
1115
|
-
badge: i ?
|
|
1121
|
+
...d,
|
|
1122
|
+
badge: i ? d.badge + 1 : d.badge
|
|
1116
1123
|
}
|
|
1117
1124
|
}), i && this.emitter.emit("feed.new_notification", s), this.emitter.emit("feed.store_update", this.data);
|
|
1118
1125
|
}
|
|
@@ -1126,13 +1133,13 @@ class ae {
|
|
|
1126
1133
|
if (t[0].status !== "fulfilled") return;
|
|
1127
1134
|
const r = t[0].value;
|
|
1128
1135
|
if (r.status === n.ERROR) return;
|
|
1129
|
-
const i = r.body,
|
|
1136
|
+
const i = r.body, d = (l = s.notifications) == null ? void 0 : l.some(
|
|
1130
1137
|
(h) => h.n_id === i.n_id
|
|
1131
1138
|
);
|
|
1132
1139
|
this.notificationBelongToStore(
|
|
1133
1140
|
i,
|
|
1134
1141
|
s.store
|
|
1135
|
-
) ?
|
|
1142
|
+
) ? d ? this.store.setState({
|
|
1136
1143
|
notifications: s.notifications.map((h) => h.n_id === i.n_id ? i : h)
|
|
1137
1144
|
}) : this.store.setState({
|
|
1138
1145
|
notifications: this.orderNotificationsBasedOnPinFlag(
|
|
@@ -1160,12 +1167,12 @@ class ae {
|
|
|
1160
1167
|
}), this.emitter.emit("feed.store_update", this.data);
|
|
1161
1168
|
}
|
|
1162
1169
|
notificationBelongToStore(e, t) {
|
|
1163
|
-
var g, O, m,
|
|
1164
|
-
const s = !!e.read_on, r = e.archived, i = e.tags,
|
|
1170
|
+
var g, O, m, v;
|
|
1171
|
+
const s = !!e.read_on, r = e.archived, i = e.tags, d = e.n_category, u = (g = t == null ? void 0 : t.query) == null ? void 0 : g.read, l = (O = t == null ? void 0 : t.query) == null ? void 0 : O.archived, h = (m = t == null ? void 0 : t.query) == null ? void 0 : m.tags, S = (v = t == null ? void 0 : t.query) == null ? void 0 : v.categories, b = u == null || s === u, T = !!r == !!l;
|
|
1165
1172
|
let y = !1, R = !1;
|
|
1166
1173
|
return Array.isArray(h) && h.length > 0 ? h.forEach((E) => {
|
|
1167
1174
|
i != null && i.includes(E) && (y = !0);
|
|
1168
|
-
}) : y = !0, Array.isArray(S) && S.length > 0 ? S.includes(
|
|
1175
|
+
}) : y = !0, Array.isArray(S) && S.length > 0 ? S.includes(d) && (R = !0) : R = !0, b && y && R && T;
|
|
1169
1176
|
}
|
|
1170
1177
|
orderNotificationsBasedOnPinFlag(e, t) {
|
|
1171
1178
|
if (e.is_pinned)
|
|
@@ -1190,8 +1197,8 @@ class ae {
|
|
|
1190
1197
|
t && (this.store.setState({ notifications: s }), await this.fetchCount(), this.emitter.emit("feed.store_update", this.data));
|
|
1191
1198
|
}
|
|
1192
1199
|
getUrl(e, t) {
|
|
1193
|
-
var
|
|
1194
|
-
const s = `${(
|
|
1200
|
+
var d;
|
|
1201
|
+
const s = `${(d = this.feedOptions.host) == null ? void 0 : d.apiHost}/v1/feed/${e}`, r = this.validateQueryParams(t), i = new URLSearchParams(
|
|
1195
1202
|
r
|
|
1196
1203
|
).toString();
|
|
1197
1204
|
return i ? `${s}?${i}` : s;
|
|
@@ -1215,12 +1222,12 @@ class ae {
|
|
|
1215
1222
|
return e == null ? void 0 : e.map((s) => this.storeQueryParamObj(s));
|
|
1216
1223
|
}
|
|
1217
1224
|
storeQueryParamObj(e) {
|
|
1218
|
-
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,
|
|
1225
|
+
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;
|
|
1219
1226
|
return {
|
|
1220
1227
|
store_id: e.storeId,
|
|
1221
1228
|
query: {
|
|
1222
1229
|
read: i,
|
|
1223
|
-
archived:
|
|
1230
|
+
archived: d,
|
|
1224
1231
|
tags: { or: s },
|
|
1225
1232
|
categories: { or: r }
|
|
1226
1233
|
}
|
|
@@ -1233,14 +1240,14 @@ class ae {
|
|
|
1233
1240
|
const s = (r = this.feedOptions.stores) == null ? void 0 : r.find(
|
|
1234
1241
|
(i) => i.storeId === e
|
|
1235
1242
|
);
|
|
1236
|
-
return s ? (this.store.setState({
|
|
1243
|
+
return s ? (this.fetchAbortController && (this.fetchAbortController.abort(), this.fetchAbortController = void 0), this.store.setState({
|
|
1237
1244
|
...P,
|
|
1238
1245
|
store: s,
|
|
1239
1246
|
meta: t.meta
|
|
1240
1247
|
}), await this.fetch()) : {
|
|
1241
1248
|
status: n.ERROR,
|
|
1242
1249
|
error: {
|
|
1243
|
-
type:
|
|
1250
|
+
type: c.NOT_FOUND,
|
|
1244
1251
|
message: `store with storeId ${e} doesnt exist`
|
|
1245
1252
|
}
|
|
1246
1253
|
};
|
|
@@ -1284,34 +1291,37 @@ class ae {
|
|
|
1284
1291
|
distinct_id: this.config.distinctId,
|
|
1285
1292
|
tenant_id: this.feedOptions.tenantId,
|
|
1286
1293
|
page_size: s,
|
|
1287
|
-
store: t.store.storeId !==
|
|
1294
|
+
store: t.store.storeId !== D.storeId ? this.storeQueryParamObj(t.store) : null
|
|
1288
1295
|
};
|
|
1289
1296
|
if (t.notifications.length > 0) {
|
|
1290
|
-
const
|
|
1297
|
+
const l = t.notifications[t.notifications.length - 1];
|
|
1291
1298
|
r.search_after = [
|
|
1292
|
-
|
|
1293
|
-
|
|
1299
|
+
l.is_pinned,
|
|
1300
|
+
l.created_on
|
|
1294
1301
|
];
|
|
1295
1302
|
} else
|
|
1296
1303
|
r.search_after = [];
|
|
1297
|
-
const i = this.getUrl("notifications", r),
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1304
|
+
const i = this.getUrl("notifications", r), d = new AbortController();
|
|
1305
|
+
this.fetchAbortController = d;
|
|
1306
|
+
const u = await this.config.client().request({ type: "get", url: i, signal: d.signal });
|
|
1307
|
+
if (!d.signal.aborted)
|
|
1308
|
+
return u.status === n.ERROR ? (this.store.setState({ apiStatus: _.ERROR }), this.emitter.emit("feed.store_update", this.data), u) : (this.store.setState({
|
|
1309
|
+
apiStatus: _.SUCCESS,
|
|
1310
|
+
notifications: t.isFirstFetch ? u.body.results : [...t.notifications, ...u.body.results],
|
|
1311
|
+
pageInfo: {
|
|
1312
|
+
...t.pageInfo,
|
|
1313
|
+
total: u.body.meta.total_count,
|
|
1314
|
+
hasMore: u.body.meta.has_more
|
|
1315
|
+
},
|
|
1316
|
+
isFirstFetch: !1
|
|
1317
|
+
}), this.emitter.emit("feed.store_update", this.data), this.startExpiryTimer(), u);
|
|
1308
1318
|
}
|
|
1309
1319
|
// TODO: support other stores
|
|
1310
1320
|
async fetchNextPage() {
|
|
1311
1321
|
return this.store.getState().pageInfo.hasMore === !1 ? {
|
|
1312
1322
|
status: n.ERROR,
|
|
1313
1323
|
error: {
|
|
1314
|
-
type:
|
|
1324
|
+
type: c.VALIDATION_ERROR,
|
|
1315
1325
|
message: "No more pages to fetch"
|
|
1316
1326
|
}
|
|
1317
1327
|
} : this.fetch();
|
|
@@ -1431,7 +1441,7 @@ class ae {
|
|
|
1431
1441
|
var e;
|
|
1432
1442
|
this.store.setState({
|
|
1433
1443
|
...P,
|
|
1434
|
-
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) ||
|
|
1444
|
+
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) || D
|
|
1435
1445
|
}), this.emitter.emit("feed.store_update", this.data), this.expiryTimerId && (clearInterval(this.expiryTimerId), this.expiryTimerId = void 0);
|
|
1436
1446
|
}
|
|
1437
1447
|
remove() {
|
|
@@ -1463,7 +1473,7 @@ class pe {
|
|
|
1463
1473
|
if (!this.userToken || !A()) return;
|
|
1464
1474
|
const t = x(this.userToken), s = (t.exp || 0) * 1e3, r = Date.now(), i = 1e3 * 30;
|
|
1465
1475
|
if (s && s > r) {
|
|
1466
|
-
const
|
|
1476
|
+
const d = s - r - i;
|
|
1467
1477
|
this.userTokenExpirationTimer && clearTimeout(this.userTokenExpirationTimer), this.userTokenExpirationTimer = setTimeout(async () => {
|
|
1468
1478
|
let u = "";
|
|
1469
1479
|
try {
|
|
@@ -1482,7 +1492,7 @@ class pe {
|
|
|
1482
1492
|
}
|
|
1483
1493
|
}
|
|
1484
1494
|
u && typeof u == "string" && this.identify(this.distinctId, u, this.authenticateOptions);
|
|
1485
|
-
},
|
|
1495
|
+
}, d);
|
|
1486
1496
|
}
|
|
1487
1497
|
}
|
|
1488
1498
|
client() {
|
|
@@ -1505,13 +1515,13 @@ class pe {
|
|
|
1505
1515
|
if (!e)
|
|
1506
1516
|
return o({
|
|
1507
1517
|
status: n.ERROR,
|
|
1508
|
-
errorType:
|
|
1518
|
+
errorType: c.VALIDATION_ERROR,
|
|
1509
1519
|
errorMessage: "distinctId is missing"
|
|
1510
1520
|
});
|
|
1511
1521
|
if (this.apiClient && this.distinctId && this.distinctId !== e)
|
|
1512
1522
|
return o({
|
|
1513
1523
|
status: n.ERROR,
|
|
1514
|
-
errorType:
|
|
1524
|
+
errorType: c.VALIDATION_ERROR,
|
|
1515
1525
|
errorMessage: "User already loggedin, reset current user to login new user"
|
|
1516
1526
|
});
|
|
1517
1527
|
if (this.apiClient && this.distinctId === e && this.userToken !== t)
|
|
@@ -1553,7 +1563,7 @@ class pe {
|
|
|
1553
1563
|
properties: s
|
|
1554
1564
|
})) : o({
|
|
1555
1565
|
status: n.ERROR,
|
|
1556
|
-
errorType:
|
|
1566
|
+
errorType: c.VALIDATION_ERROR,
|
|
1557
1567
|
errorMessage: "event name is missing"
|
|
1558
1568
|
});
|
|
1559
1569
|
}
|
|
@@ -1567,8 +1577,8 @@ class pe {
|
|
|
1567
1577
|
}
|
|
1568
1578
|
export {
|
|
1569
1579
|
_ as ApiResponseStatus,
|
|
1570
|
-
|
|
1571
|
-
|
|
1580
|
+
C as ChannelLevelPreferenceOptions,
|
|
1581
|
+
c as ERROR_TYPE,
|
|
1572
1582
|
ae as Feed,
|
|
1573
1583
|
p as PreferenceOptions,
|
|
1574
1584
|
n as RESPONSE_STATUS,
|