@suprsend/web-sdk 3.0.3 → 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/es/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  var K = Object.defineProperty;
2
2
  var W = (a, e, t) => e in a ? K(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
3
3
  var f = (a, e, t) => W(a, typeof e != "symbol" ? e + "" : e, t);
4
- import L from "mitt";
5
- import V from "jwt-decode";
4
+ import V from "mitt";
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 || {}), b = /* @__PURE__ */ ((a) => (a.ALL = "all", a.REQUIRED = "required", a))(b || {}), d = /* @__PURE__ */ ((a) => (a.VALIDATION_ERROR = "VALIDATION_ERROR", a.NETWORK_ERROR = "NETWORK_ERROR", a.UNKNOWN_ERROR = "UNKNOWN_ERROR", a.PERMISSION_DENIED = "PERMISSION_DENIED", a.UNSUPPORTED_ACTION = "UNSUPPORTED_ACTION", a.NOT_FOUND = "NOT_FOUND", a))(d || {}), n = /* @__PURE__ */ ((a) => (a.SUCCESS = "success", a.ERROR = "error", a))(n || {}), _ = /* @__PURE__ */ ((a) => (a.INITIAL = "INITIAL", a.LOADING = "LOADING", a.SUCCESS = "SUCCESS", a.ERROR = "ERROR", a.FETCHING_MORE = "FETCHING_MORE", a))(_ || {});
9
- function A() {
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
+ function C() {
10
10
  let a = (/* @__PURE__ */ new Date()).getTime();
11
11
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
12
12
  /[xy]/g,
@@ -16,7 +16,7 @@ function A() {
16
16
  }
17
17
  );
18
18
  }
19
- function N() {
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 U(a, e) {
40
+ function M(a, e) {
41
41
  const t = {};
42
42
  return (...s) => {
43
43
  const [r] = s, i = s.slice(1);
@@ -51,14 +51,14 @@ function o(a) {
51
51
  message: a.errorMessage
52
52
  }), e;
53
53
  }
54
- function E() {
54
+ function A() {
55
55
  return typeof window < "u";
56
56
  }
57
- function x(a, e) {
58
- E() && (typeof e == "object" && (e = JSON.stringify(e)), localStorage.setItem(a, e));
57
+ function $(a, e) {
58
+ A() && (typeof e == "object" && (e = JSON.stringify(e)), localStorage.setItem(a, e));
59
59
  }
60
- function $(a) {
61
- if (!E()) return;
60
+ function j(a) {
61
+ if (!A()) return;
62
62
  const e = localStorage.getItem(a);
63
63
  if (e)
64
64
  try {
@@ -67,7 +67,7 @@ function $(a) {
67
67
  return e;
68
68
  }
69
69
  }
70
- class D {
70
+ class N {
71
71
  constructor(e) {
72
72
  f(this, "config");
73
73
  this.config = e;
@@ -116,12 +116,12 @@ class D {
116
116
  if (!this.config.distinctId)
117
117
  return o({
118
118
  status: n.ERROR,
119
- errorType: d.VALIDATION_ERROR,
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 = V(this.config.userToken), c = (i.exp || 0) * 1e3, u = Date.now();
124
- if (c <= u)
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 D {
136
136
  }
137
137
  }
138
138
  try {
139
- const i = await this.requestApiInstance(e), c = await i.json(), u = (c == null ? void 0 : c.status) || (i.ok ? n.SUCCESS : n.ERROR);
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: c,
142
+ body: d,
143
143
  statusCode: i.status,
144
- errorMessage: (s = c == null ? void 0 : c.error) == null ? void 0 : s.message,
145
- errorType: (r = c == null ? void 0 : c.error) == null ? void 0 : r.type
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: d.NETWORK_ERROR
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 = U(
165
+ this.config = e, this.debouncedUpdateCategoryPreferences = M(
166
166
  this._updateCategoryPreferences.bind(this),
167
167
  this.debounceTime
168
- ), this.debouncedUpdateChannelPreferences = U(
168
+ ), this.debouncedUpdateChannelPreferences = M(
169
169
  this._updateChannelPreferences.bind(this),
170
170
  this.debounceTime
171
171
  );
@@ -173,7 +173,7 @@ class J {
173
173
  validateQueryParams(e = {}) {
174
174
  const t = {};
175
175
  for (const s in e)
176
- e[s] && (t[s] = String(e[s]));
176
+ e[s] && (typeof e[s] == "object" ? t[s] = JSON.stringify(e[s]) : t[s] = String(e[s]));
177
177
  return t;
178
178
  }
179
179
  set data(e) {
@@ -194,11 +194,13 @@ class J {
194
194
  async getPreferences(e) {
195
195
  const t = {
196
196
  tenant_id: e == null ? void 0 : e.tenantId,
197
- show_opt_out_channels: (e == null ? void 0 : e.showOptOutChannels) !== !1
197
+ show_opt_out_channels: (e == null ? void 0 : e.showOptOutChannels) !== !1,
198
+ tags: e == null ? void 0 : e.tags
198
199
  };
199
200
  this.preferenceArgs = {
200
201
  tenantId: t == null ? void 0 : t.tenant_id,
201
- showOptOutChannels: t == null ? void 0 : t.show_opt_out_channels
202
+ showOptOutChannels: t == null ? void 0 : t.show_opt_out_channels,
203
+ tags: t == null ? void 0 : t.tags
202
204
  };
203
205
  const s = this.getUrl("full_preference", t), r = await this.config.client().request({ type: "get", url: s });
204
206
  return r.error || (this.data = r.body), r;
@@ -211,7 +213,8 @@ class J {
211
213
  tenant_id: e == null ? void 0 : e.tenantId,
212
214
  show_opt_out_channels: (e == null ? void 0 : e.showOptOutChannels) !== !1,
213
215
  limit: e == null ? void 0 : e.limit,
214
- offset: e == null ? void 0 : e.offset
216
+ offset: e == null ? void 0 : e.offset,
217
+ tags: e == null ? void 0 : e.tags
215
218
  }, s = this.getUrl("category", t);
216
219
  return await this.config.client().request({ type: "get", url: s });
217
220
  }
@@ -222,7 +225,7 @@ class J {
222
225
  if (!e)
223
226
  return o({
224
227
  status: n.ERROR,
225
- errorType: d.VALIDATION_ERROR,
228
+ errorType: c.VALIDATION_ERROR,
226
229
  errorMessage: "Category parameter is missing"
227
230
  });
228
231
  const s = {
@@ -239,16 +242,16 @@ class J {
239
242
  return await this.config.client().request({ type: "get", url: e });
240
243
  }
241
244
  async _updateCategoryPreferences(e, t, s, r) {
242
- const i = this.getUrl(`category/${e}`, r), c = await this.config.client().request({
245
+ const i = this.getUrl(`category/${e}`, r), d = await this.config.client().request({
243
246
  type: "patch",
244
247
  url: i,
245
248
  payload: t
246
249
  });
247
- return c != null && c.error ? this.config.emitter.emit("preferences_error", c) : (Object.assign(s, c.body), this.config.emitter.emit("preferences_updated", {
250
+ return d != null && d.error ? this.config.emitter.emit("preferences_error", d) : (Object.assign(s, d.body), this.config.emitter.emit("preferences_updated", {
248
251
  status: n.SUCCESS,
249
252
  statusCode: 200,
250
253
  body: this.data
251
- })), c;
254
+ })), d;
252
255
  }
253
256
  async _updateChannelPreferences(e) {
254
257
  const t = this.getUrl("channel_preference"), s = await this.config.client().request({
@@ -266,51 +269,51 @@ class J {
266
269
  * Used to update user's category level preference.
267
270
  */
268
271
  async updateCategoryPreference(e, t, s) {
269
- var h;
272
+ var h, T, b, S;
270
273
  if (!e || ![p.OPT_IN, p.OPT_OUT].includes(
271
274
  t
272
275
  ))
273
276
  return o({
274
277
  status: n.ERROR,
275
- errorType: d.VALIDATION_ERROR,
278
+ errorType: c.VALIDATION_ERROR,
276
279
  errorMessage: e ? "Preference parameter is invalid" : "Category parameter is missing"
277
280
  });
278
281
  if (!this.data)
279
282
  return o({
280
283
  status: n.ERROR,
281
- errorType: d.VALIDATION_ERROR,
284
+ errorType: c.VALIDATION_ERROR,
282
285
  errorMessage: "Call getPreferences method before performing action"
283
286
  });
284
287
  if (!this.data.sections)
285
288
  return o({
286
289
  status: n.ERROR,
287
- errorType: d.VALIDATION_ERROR,
290
+ errorType: c.VALIDATION_ERROR,
288
291
  errorMessage: "Sections doesn't exist"
289
292
  });
290
293
  let r = null, i = !1;
291
294
  for (const R of this.data.sections) {
292
- let S = !1;
295
+ let g = !1;
293
296
  if (R.subcategories) {
294
- for (const g of R.subcategories)
295
- if (g.category === e)
296
- if (r = g, g.is_editable) {
297
- if (g.preference !== t) {
298
- g.preference = t, i = !0, S = !0;
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;
299
302
  break;
300
303
  }
301
304
  } else
302
305
  return o({
303
306
  status: n.ERROR,
304
- errorType: d.VALIDATION_ERROR,
307
+ errorType: c.VALIDATION_ERROR,
305
308
  errorMessage: "Category preference is not editable"
306
309
  });
307
- if (S) break;
310
+ if (g) break;
308
311
  }
309
312
  }
310
313
  if (!r)
311
314
  return o({
312
315
  status: n.ERROR,
313
- errorType: d.VALIDATION_ERROR,
316
+ errorType: c.VALIDATION_ERROR,
314
317
  errorMessage: "Category not found"
315
318
  });
316
319
  if (!i)
@@ -318,20 +321,26 @@ class J {
318
321
  status: n.SUCCESS,
319
322
  body: this.data
320
323
  });
321
- const c = [];
324
+ const d = [];
322
325
  (h = r == null ? void 0 : r.channels) == null || h.forEach((R) => {
323
- R.preference === p.OPT_OUT && c.push(R.channel);
326
+ R.preference === p.OPT_OUT && d.push(R.channel);
324
327
  });
325
- const u = (s == null ? void 0 : s.showOptOutChannels) !== !1, l = {
328
+ let u = !0;
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
+ const l = {
326
331
  preference: r.preference,
327
- opt_out_channels: u && t === p.OPT_IN ? null : c
332
+ opt_out_channels: u && t === p.OPT_IN ? null : d
328
333
  };
329
334
  return this.debouncedUpdateCategoryPreferences(
330
335
  e,
331
336
  e,
332
337
  l,
333
338
  r,
334
- { tenant_id: s == null ? void 0 : s.tenantId, show_opt_out_channels: u }
339
+ {
340
+ tenant_id: (s == null ? void 0 : s.tenantId) || ((b = this.preferenceArgs) == null ? void 0 : b.tenantId),
341
+ show_opt_out_channels: u,
342
+ tags: (s == null ? void 0 : s.tags) || ((S = this.preferenceArgs) == null ? void 0 : S.tags)
343
+ }
335
344
  ), o({
336
345
  status: n.SUCCESS,
337
346
  body: this.data
@@ -341,11 +350,11 @@ class J {
341
350
  * Used to update user's category level channel preference.
342
351
  */
343
352
  async updateChannelPreferenceInCategory(e, t, s, r) {
344
- var g;
353
+ var S, R, g, O;
345
354
  if (!e || !s)
346
355
  return o({
347
356
  status: n.ERROR,
348
- errorType: d.VALIDATION_ERROR,
357
+ errorType: c.VALIDATION_ERROR,
349
358
  errorMessage: e ? "Category parameter is missing" : "Channel parameter is missing"
350
359
  });
351
360
  if (![p.OPT_IN, p.OPT_OUT].includes(
@@ -353,57 +362,57 @@ class J {
353
362
  ))
354
363
  return o({
355
364
  status: n.ERROR,
356
- errorType: d.VALIDATION_ERROR,
365
+ errorType: c.VALIDATION_ERROR,
357
366
  errorMessage: "Preference parameter is invalid"
358
367
  });
359
368
  if (!this.data)
360
369
  return o({
361
370
  status: n.ERROR,
362
- errorType: d.VALIDATION_ERROR,
371
+ errorType: c.VALIDATION_ERROR,
363
372
  errorMessage: "Call getPreferences method before performing action"
364
373
  });
365
374
  if (!this.data.sections)
366
375
  return o({
367
376
  status: n.ERROR,
368
- errorType: d.VALIDATION_ERROR,
377
+ errorType: c.VALIDATION_ERROR,
369
378
  errorMessage: "Sections doesn't exist"
370
379
  });
371
- let i = null, c = null, u = !1;
372
- for (const m of this.data.sections) {
373
- let T = !1;
374
- if (m.subcategories) {
375
- for (const O of m.subcategories) {
376
- if (O.category === s) {
377
- if (i = O, !O.channels) continue;
378
- for (const y of O.channels)
379
- if (y.channel === e)
380
- if (c = y, y.is_editable) {
381
- if (y.preference !== t) {
382
- y.preference = t, t === p.OPT_IN && (O.preference = p.OPT_IN), u = !0, T = !0;
380
+ let i = null, d = null, u = !1;
381
+ for (const y of this.data.sections) {
382
+ let v = !1;
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
+ if (E.channel === e)
389
+ if (d = E, E.is_editable) {
390
+ if (E.preference !== t) {
391
+ E.preference = t, t === p.OPT_IN && (m.preference = p.OPT_IN), u = !0, v = !0;
383
392
  break;
384
393
  }
385
394
  } else
386
395
  return o({
387
396
  status: n.ERROR,
388
- errorType: d.VALIDATION_ERROR,
397
+ errorType: c.VALIDATION_ERROR,
389
398
  errorMessage: "Channel preference is not editable"
390
399
  });
391
400
  }
392
- if (T) break;
401
+ if (v) break;
393
402
  }
394
- if (T) break;
403
+ if (v) break;
395
404
  }
396
405
  }
397
406
  if (!i)
398
407
  return o({
399
408
  status: n.ERROR,
400
- errorType: d.VALIDATION_ERROR,
409
+ errorType: c.VALIDATION_ERROR,
401
410
  errorMessage: "Category not found"
402
411
  });
403
- if (!c)
412
+ if (!d)
404
413
  return o({
405
414
  status: n.ERROR,
406
- errorType: d.VALIDATION_ERROR,
415
+ errorType: c.VALIDATION_ERROR,
407
416
  errorMessage: "Category's channel not found"
408
417
  });
409
418
  if (!u)
@@ -412,19 +421,25 @@ class J {
412
421
  body: this.data
413
422
  });
414
423
  const l = [];
415
- (g = i == null ? void 0 : i.channels) == null || g.forEach((m) => {
416
- m.preference === p.OPT_OUT && l.push(m.channel);
424
+ (S = i == null ? void 0 : i.channels) == null || S.forEach((y) => {
425
+ y.preference === p.OPT_OUT && l.push(y.channel);
417
426
  });
418
- const h = (r == null ? void 0 : r.showOptOutChannels) !== !1, S = {
427
+ let h = !0;
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);
429
+ const b = {
419
430
  preference: h && i.preference === p.OPT_OUT && t === p.OPT_IN ? p.OPT_IN : i.preference,
420
431
  opt_out_channels: l
421
432
  };
422
433
  return this.debouncedUpdateCategoryPreferences(
423
434
  s,
424
435
  s,
425
- S,
436
+ b,
426
437
  i,
427
- { tenant_id: r == null ? void 0 : r.tenantId, show_opt_out_channels: h }
438
+ {
439
+ tenant_id: (r == null ? void 0 : r.tenantId) || ((g = this.preferenceArgs) == null ? void 0 : g.tenantId),
440
+ show_opt_out_channels: h,
441
+ tags: (r == null ? void 0 : r.tags) || ((O = this.preferenceArgs) == null ? void 0 : O.tags)
442
+ }
428
443
  ), o({
429
444
  status: n.SUCCESS,
430
445
  body: this.data
@@ -435,31 +450,31 @@ class J {
435
450
  */
436
451
  async updateOverallChannelPreference(e, t) {
437
452
  if (!e || ![
438
- b.ALL,
439
- b.REQUIRED
453
+ w.ALL,
454
+ w.REQUIRED
440
455
  ].includes(t))
441
456
  return o({
442
457
  status: n.ERROR,
443
- errorType: d.VALIDATION_ERROR,
458
+ errorType: c.VALIDATION_ERROR,
444
459
  errorMessage: e ? "Preference parameter is invalid" : "Channel parameter is missing"
445
460
  });
446
461
  if (!this.data)
447
462
  return o({
448
463
  status: n.ERROR,
449
- errorType: d.VALIDATION_ERROR,
464
+ errorType: c.VALIDATION_ERROR,
450
465
  errorMessage: "Call getPreferences method before performing action"
451
466
  });
452
467
  if (!this.data.channel_preferences)
453
468
  return o({
454
469
  status: n.ERROR,
455
- errorType: d.VALIDATION_ERROR,
470
+ errorType: c.VALIDATION_ERROR,
456
471
  errorMessage: "Channel preferences doesn't exist"
457
472
  });
458
473
  let s = null, r = !1;
459
- const i = t === b.REQUIRED;
460
- for (const c of this.data.channel_preferences)
461
- if (c.channel === e && (s = c, c.is_restricted !== i)) {
462
- c.is_restricted = i, r = !0;
474
+ const i = t === w.REQUIRED;
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;
463
478
  break;
464
479
  }
465
480
  return s ? r ? (this.debouncedUpdateChannelPreferences(s.channel, {
@@ -472,7 +487,7 @@ class J {
472
487
  body: this.data
473
488
  }) : o({
474
489
  status: n.ERROR,
475
- errorType: d.VALIDATION_ERROR,
490
+ errorType: c.VALIDATION_ERROR,
476
491
  errorMessage: "Channel data not found"
477
492
  });
478
493
  }
@@ -498,14 +513,14 @@ class Z {
498
513
  }
499
514
  validateObjData(e, t) {
500
515
  const s = {}, r = (t == null ? void 0 : t.allowReservedKeys) || !1, i = (t == null ? void 0 : t.valueType) || "";
501
- for (const c in e) {
502
- let u = e[c];
503
- if (!(c && u === void 0)) {
504
- if (!r && this.isReservedKey(c)) {
516
+ for (const d in e) {
517
+ let u = e[d];
518
+ if (!(d && u === void 0)) {
519
+ if (!r && this.isReservedKey(d)) {
505
520
  console.warn("[SuprSend]: key cannot start with $ or ss_");
506
521
  continue;
507
522
  }
508
- i === "number" ? u = Number(u) : i === "boolean" && (u = !!u), s[c] = u;
523
+ i === "number" ? u = Number(u) : i === "boolean" && (u = !!u), s[d] = u;
509
524
  }
510
525
  }
511
526
  return s;
@@ -525,8 +540,8 @@ class Z {
525
540
  async triggerUserEvent(e) {
526
541
  return this.config.eventApi({
527
542
  distinct_id: this.config.distinctId,
528
- $insert_id: A(),
529
- $time: N(),
543
+ $insert_id: C(),
544
+ $time: P(),
530
545
  ...e
531
546
  });
532
547
  }
@@ -538,13 +553,13 @@ class Z {
538
553
  if (!s)
539
554
  return o({
540
555
  status: n.ERROR,
541
- errorType: d.VALIDATION_ERROR,
556
+ errorType: c.VALIDATION_ERROR,
542
557
  errorMessage: "data provided is empty"
543
558
  });
544
559
  const r = this.validateObjData(s);
545
560
  return I(r) ? o({
546
561
  status: n.ERROR,
547
- errorType: d.VALIDATION_ERROR,
562
+ errorType: c.VALIDATION_ERROR,
548
563
  errorMessage: "data provided is empty"
549
564
  }) : this.triggerUserEvent({ $set: r });
550
565
  }
@@ -557,13 +572,13 @@ class Z {
557
572
  if (!s)
558
573
  return o({
559
574
  status: n.ERROR,
560
- errorType: d.VALIDATION_ERROR,
575
+ errorType: c.VALIDATION_ERROR,
561
576
  errorMessage: "data provided is empty"
562
577
  });
563
578
  const r = this.validateObjData(s);
564
579
  return I(r) ? o({
565
580
  status: n.ERROR,
566
- errorType: d.VALIDATION_ERROR,
581
+ errorType: c.VALIDATION_ERROR,
567
582
  errorMessage: "data provided is empty"
568
583
  }) : this.triggerUserEvent({ $set_once: r });
569
584
  }
@@ -576,13 +591,13 @@ class Z {
576
591
  if (!s)
577
592
  return o({
578
593
  status: n.ERROR,
579
- errorType: d.VALIDATION_ERROR,
594
+ errorType: c.VALIDATION_ERROR,
580
595
  errorMessage: "data provided is empty"
581
596
  });
582
597
  const r = this.validateObjData(s, { valueType: "number" });
583
598
  return I(r) ? o({
584
599
  status: n.ERROR,
585
- errorType: d.VALIDATION_ERROR,
600
+ errorType: c.VALIDATION_ERROR,
586
601
  errorMessage: "data provided is empty"
587
602
  }) : this.triggerUserEvent({ $add: r });
588
603
  }
@@ -595,13 +610,13 @@ class Z {
595
610
  if (!s)
596
611
  return o({
597
612
  status: n.ERROR,
598
- errorType: d.VALIDATION_ERROR,
613
+ errorType: c.VALIDATION_ERROR,
599
614
  errorMessage: "data provided is empty"
600
615
  });
601
616
  const r = this.validateObjData(s);
602
617
  return I(r) ? o({
603
618
  status: n.ERROR,
604
- errorType: d.VALIDATION_ERROR,
619
+ errorType: c.VALIDATION_ERROR,
605
620
  errorMessage: "data provided is empty"
606
621
  }) : this.triggerUserEvent({ $append: r });
607
622
  }
@@ -614,13 +629,13 @@ class Z {
614
629
  if (!s)
615
630
  return o({
616
631
  status: n.ERROR,
617
- errorType: d.VALIDATION_ERROR,
632
+ errorType: c.VALIDATION_ERROR,
618
633
  errorMessage: "data provided is empty"
619
634
  });
620
635
  const r = this.validateObjData(s);
621
636
  return I(r) ? o({
622
637
  status: n.ERROR,
623
- errorType: d.VALIDATION_ERROR,
638
+ errorType: c.VALIDATION_ERROR,
624
639
  errorMessage: "data provided is empty"
625
640
  }) : this.triggerUserEvent({ $remove: r });
626
641
  }
@@ -632,13 +647,13 @@ class Z {
632
647
  if (!t)
633
648
  return o({
634
649
  status: n.ERROR,
635
- errorType: d.VALIDATION_ERROR,
650
+ errorType: c.VALIDATION_ERROR,
636
651
  errorMessage: "data provided is empty"
637
652
  });
638
653
  const s = this.validateArrayData(t);
639
654
  return H(s) ? o({
640
655
  status: n.ERROR,
641
- errorType: d.VALIDATION_ERROR,
656
+ errorType: c.VALIDATION_ERROR,
642
657
  errorMessage: "data provided is empty"
643
658
  }) : this.triggerUserEvent({ $unset: s });
644
659
  }
@@ -648,7 +663,7 @@ class Z {
648
663
  if (!s)
649
664
  return o({
650
665
  status: n.ERROR,
651
- errorType: d.VALIDATION_ERROR,
666
+ errorType: c.VALIDATION_ERROR,
652
667
  errorMessage: "data provided is empty"
653
668
  });
654
669
  const r = this.validateObjData(s, {
@@ -656,7 +671,7 @@ class Z {
656
671
  });
657
672
  return I(r) ? o({
658
673
  status: n.ERROR,
659
- errorType: d.VALIDATION_ERROR,
674
+ errorType: c.VALIDATION_ERROR,
660
675
  errorMessage: "data provided is empty"
661
676
  }) : this.triggerUserEvent({ $append: r });
662
677
  }
@@ -666,7 +681,7 @@ class Z {
666
681
  if (!s)
667
682
  return o({
668
683
  status: n.ERROR,
669
- errorType: d.VALIDATION_ERROR,
684
+ errorType: c.VALIDATION_ERROR,
670
685
  errorMessage: "data provided is empty"
671
686
  });
672
687
  const r = this.validateObjData(s, {
@@ -674,7 +689,7 @@ class Z {
674
689
  });
675
690
  return I(r) ? o({
676
691
  status: n.ERROR,
677
- errorType: d.VALIDATION_ERROR,
692
+ errorType: c.VALIDATION_ERROR,
678
693
  errorMessage: "data provided is empty"
679
694
  }) : this.triggerUserEvent({ $remove: r });
680
695
  }
@@ -683,7 +698,7 @@ class Z {
683
698
  if (!s)
684
699
  return o({
685
700
  status: n.ERROR,
686
- errorType: d.VALIDATION_ERROR,
701
+ errorType: c.VALIDATION_ERROR,
687
702
  errorMessage: "data provided is empty"
688
703
  });
689
704
  const r = this.validateObjData(s, {
@@ -691,7 +706,7 @@ class Z {
691
706
  });
692
707
  return I(r) ? o({
693
708
  status: n.ERROR,
694
- errorType: d.VALIDATION_ERROR,
709
+ errorType: c.VALIDATION_ERROR,
695
710
  errorMessage: "data provided is empty"
696
711
  }) : this.triggerUserEvent({ $set: r });
697
712
  }
@@ -704,14 +719,14 @@ class Z {
704
719
  async addEmail(e) {
705
720
  return this.validateEmail(e) ? this.appendInternal({ $email: e }) : o({
706
721
  status: n.ERROR,
707
- errorType: d.VALIDATION_ERROR,
722
+ errorType: c.VALIDATION_ERROR,
708
723
  errorMessage: "provided email is invalid"
709
724
  });
710
725
  }
711
726
  async removeEmail(e) {
712
727
  return this.validateEmail(e) ? this.removeInternal({ $email: e }) : o({
713
728
  status: n.ERROR,
714
- errorType: d.VALIDATION_ERROR,
729
+ errorType: c.VALIDATION_ERROR,
715
730
  errorMessage: "provided email is invalid"
716
731
  });
717
732
  }
@@ -721,7 +736,7 @@ class Z {
721
736
  async addSms(e) {
722
737
  return this.validateMobile(e) ? this.appendInternal({ $sms: e }) : o({
723
738
  status: n.ERROR,
724
- errorType: d.VALIDATION_ERROR,
739
+ errorType: c.VALIDATION_ERROR,
725
740
  errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
726
741
  });
727
742
  }
@@ -731,7 +746,7 @@ class Z {
731
746
  async removeSms(e) {
732
747
  return this.validateMobile(e) ? this.removeInternal({ $sms: e }) : o({
733
748
  status: n.ERROR,
734
- errorType: d.VALIDATION_ERROR,
749
+ errorType: c.VALIDATION_ERROR,
735
750
  errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
736
751
  });
737
752
  }
@@ -741,7 +756,7 @@ class Z {
741
756
  async addWhatsapp(e) {
742
757
  return this.validateMobile(e) ? this.appendInternal({ $whatsapp: e }) : o({
743
758
  status: n.ERROR,
744
- errorType: d.VALIDATION_ERROR,
759
+ errorType: c.VALIDATION_ERROR,
745
760
  errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
746
761
  });
747
762
  }
@@ -751,19 +766,19 @@ class Z {
751
766
  async removeWhatsapp(e) {
752
767
  return this.validateMobile(e) ? this.removeInternal({ $whatsapp: e }) : o({
753
768
  status: n.ERROR,
754
- errorType: d.VALIDATION_ERROR,
769
+ errorType: c.VALIDATION_ERROR,
755
770
  errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
756
771
  });
757
772
  }
758
773
  getDeviceId() {
759
- let e = $(k);
760
- return e || (e = A(), x(k, e)), e;
774
+ let e = j(k);
775
+ return e || (e = C(), $(k, e)), e;
761
776
  }
762
777
  async addWebPush(e) {
763
778
  if (typeof e != "object")
764
779
  return o({
765
780
  status: n.ERROR,
766
- errorType: d.VALIDATION_ERROR,
781
+ errorType: c.VALIDATION_ERROR,
767
782
  errorMessage: "provided push subscription is invalid, must be an object"
768
783
  });
769
784
  const t = this.getDeviceId();
@@ -777,7 +792,7 @@ class Z {
777
792
  if (typeof e != "object")
778
793
  return o({
779
794
  status: n.ERROR,
780
- errorType: d.VALIDATION_ERROR,
795
+ errorType: c.VALIDATION_ERROR,
781
796
  errorMessage: "provided push subscription is invalid, must be an object"
782
797
  });
783
798
  const t = this.getDeviceId();
@@ -790,28 +805,28 @@ class Z {
790
805
  async addSlack(e) {
791
806
  return typeof e != "object" ? o({
792
807
  status: n.ERROR,
793
- errorType: d.VALIDATION_ERROR,
808
+ errorType: c.VALIDATION_ERROR,
794
809
  errorMessage: "provided slack data is invalid, must be an object"
795
810
  }) : this.appendInternal({ $slack: e });
796
811
  }
797
812
  async removeSlack(e) {
798
813
  return typeof e != "object" ? o({
799
814
  status: n.ERROR,
800
- errorType: d.VALIDATION_ERROR,
815
+ errorType: c.VALIDATION_ERROR,
801
816
  errorMessage: "provided slack data is invalid, must be an object"
802
817
  }) : this.removeInternal({ $slack: e });
803
818
  }
804
819
  async addMSTeams(e) {
805
820
  return typeof e != "object" ? o({
806
821
  status: n.ERROR,
807
- errorType: d.VALIDATION_ERROR,
822
+ errorType: c.VALIDATION_ERROR,
808
823
  errorMessage: "provided ms_teams data is invalid, must be object"
809
824
  }) : this.appendInternal({ $ms_teams: e });
810
825
  }
811
826
  async removeMSTeams(e) {
812
827
  return typeof e != "object" ? o({
813
828
  status: n.ERROR,
814
- errorType: d.VALIDATION_ERROR,
829
+ errorType: c.VALIDATION_ERROR,
815
830
  errorMessage: "provided ms_teams data is invalid, must be object"
816
831
  }) : this.removeInternal({ $ms_teams: e });
817
832
  }
@@ -822,7 +837,7 @@ class Z {
822
837
  async setPreferredLanguage(e) {
823
838
  return typeof e != "string" ? o({
824
839
  status: n.ERROR,
825
- errorType: d.VALIDATION_ERROR,
840
+ errorType: c.VALIDATION_ERROR,
826
841
  errorMessage: "provided language is invalid, must be string"
827
842
  }) : this.setInternal({ $preferred_language: e });
828
843
  }
@@ -832,7 +847,7 @@ class Z {
832
847
  async setTimezone(e) {
833
848
  return typeof e != "string" ? o({
834
849
  status: n.ERROR,
835
- errorType: d.VALIDATION_ERROR,
850
+ errorType: c.VALIDATION_ERROR,
836
851
  errorMessage: "provided timezone is invalid, must be string"
837
852
  }) : this.setInternal({ $timezone: e });
838
853
  }
@@ -843,7 +858,7 @@ class X {
843
858
  this.config = e;
844
859
  }
845
860
  async getPushSubscription() {
846
- if (!E()) return;
861
+ if (!A()) return;
847
862
  const e = await navigator.serviceWorker.getRegistration();
848
863
  if (!e) return;
849
864
  const t = e.pushManager.getSubscription();
@@ -855,7 +870,7 @@ class X {
855
870
  if (await navigator.serviceWorker.register(`/${this.config.swFileName}`), await Notification.requestPermission() !== "granted")
856
871
  return console.warn("[SuprSend]: Notification permission isnt granted"), o({
857
872
  status: n.ERROR,
858
- errorType: d.PERMISSION_DENIED,
873
+ errorType: c.PERMISSION_DENIED,
859
874
  errorMessage: "Notification permission isn't granted"
860
875
  });
861
876
  const t = await navigator.serviceWorker.ready, s = await t.pushManager.getSubscription();
@@ -866,7 +881,7 @@ class X {
866
881
  "[SuprSend]: Vapid key is missing. Add it while creating SuprSend instance"
867
882
  ), o({
868
883
  status: n.ERROR,
869
- errorType: d.VALIDATION_ERROR,
884
+ errorType: c.VALIDATION_ERROR,
870
885
  errorMessage: "Vapid key is missing. Add it while creating SuprSend instance"
871
886
  });
872
887
  const r = await t.pushManager.subscribe({
@@ -877,7 +892,7 @@ class X {
877
892
  } catch (e) {
878
893
  return console.warn("SuprSend: Error getting push subscription", e), o({
879
894
  status: n.ERROR,
880
- errorType: d.UNKNOWN_ERROR,
895
+ errorType: c.UNKNOWN_ERROR,
881
896
  errorMessage: (e == null ? void 0 : e.message) || "Unknown error occured while registering for push"
882
897
  });
883
898
  }
@@ -889,9 +904,9 @@ class X {
889
904
  * 3. Send webpush token to SuprSend.
890
905
  */
891
906
  async registerPush() {
892
- return E() && "serviceWorker" in navigator && "PushManager" in window ? this.handleRegisterPush() : (console.warn("[SuprSend]: Webpush isn't supported"), o({
907
+ return A() && "serviceWorker" in navigator && "PushManager" in window ? this.handleRegisterPush() : (console.warn("[SuprSend]: Webpush isn't supported"), o({
893
908
  status: n.ERROR,
894
- errorType: d.UNSUPPORTED_ACTION,
909
+ errorType: c.UNSUPPORTED_ACTION,
895
910
  errorMessage: "Webpush isn't supported"
896
911
  }));
897
912
  }
@@ -918,29 +933,28 @@ class X {
918
933
  return !!await this.getPushSubscription();
919
934
  }
920
935
  }
921
- const j = 20, q = "default", Y = 100, v = {
936
+ const F = 20, Y = "default", q = 100, D = {
922
937
  storeId: "$suprsend_default_store",
923
938
  label: ""
924
939
  }, ee = {
925
- tenantId: q,
926
- pageSize: j,
940
+ tenantId: Y,
941
+ pageSize: F,
927
942
  stores: null,
928
943
  host: {
929
944
  apiHost: "https://inboxs.live",
930
945
  socketHost: "https://betainbox.suprsend.com"
931
946
  }
932
- }, w = {
947
+ }, U = {
933
948
  notifications: [],
934
- store: v,
949
+ store: D,
935
950
  pageInfo: {
936
951
  total: 0,
937
- currentPage: 0,
938
- totalPages: 0,
939
- pageSize: j
952
+ pageSize: F,
953
+ hasMore: !1
940
954
  },
941
955
  meta: { badge: 0 },
942
956
  apiStatus: _.INITIAL,
943
- _firstFetchedTimeStamp: null
957
+ isFirstFetch: !0
944
958
  };
945
959
  class te {
946
960
  constructor(e) {
@@ -970,11 +984,11 @@ class se {
970
984
  f(this, "store");
971
985
  f(this, "socket");
972
986
  f(this, "expiryTimerId");
973
- f(this, "emitter", L());
987
+ f(this, "emitter", V());
974
988
  this.config = e, this.setOptions(t), this.store = this.createFeedStore();
975
989
  }
976
990
  setOptions(e) {
977
- this.feedOptions = { ...ee }, e != null && e.tenantId && (this.feedOptions.tenantId = e.tenantId), e != null && e.host && (this.feedOptions.host = e.host), typeof (e == null ? void 0 : e.pageSize) == "number" && e.pageSize > 0 && (this.feedOptions.pageSize = Math.min(e.pageSize, Y)), e != null && e.stores && (this.feedOptions.stores = e.stores), this.validateStore();
991
+ this.feedOptions = { ...ee }, e != null && e.tenantId && (this.feedOptions.tenantId = e.tenantId), e != null && e.host && (this.feedOptions.host = e.host), typeof (e == null ? void 0 : e.pageSize) == "number" && e.pageSize > 0 && (this.feedOptions.pageSize = Math.min(e.pageSize, q)), e != null && e.stores && (this.feedOptions.stores = e.stores), this.validateStore();
978
992
  }
979
993
  validateStore() {
980
994
  const e = this.feedOptions.stores;
@@ -992,12 +1006,12 @@ class se {
992
1006
  return;
993
1007
  }
994
1008
  const r = s == null ? void 0 : s.query;
995
- let i, c, u = [], l = [];
996
- 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({
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({
997
1011
  storeId: s.storeId,
998
1012
  label: s.label || s.storeId,
999
1013
  query: {
1000
- archived: c,
1014
+ archived: d,
1001
1015
  read: i,
1002
1016
  tags: u,
1003
1017
  categories: l
@@ -1009,8 +1023,8 @@ class se {
1009
1023
  return z()(() => {
1010
1024
  var e;
1011
1025
  return {
1012
- ...w,
1013
- store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) || v
1026
+ ...U,
1027
+ store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) || D
1014
1028
  };
1015
1029
  });
1016
1030
  }
@@ -1039,18 +1053,18 @@ class se {
1039
1053
  return;
1040
1054
  const s = t.body, r = this.store.getState();
1041
1055
  let i = !1;
1042
- const c = { ...r.meta };
1056
+ const d = { ...r.meta };
1043
1057
  this.notificationBelongToStore(s, r.store) && (i = !0, this.store.setState({
1044
1058
  notifications: this.orderNotificationsBasedOnPinFlag(
1045
1059
  s,
1046
1060
  r.notifications
1047
1061
  )
1048
1062
  })), (l = (u = this.feedOptions.stores) == null ? void 0 : u.map) == null || l.call(u, (h) => {
1049
- this.notificationBelongToStore(s, h) && (i = !0, c[h.storeId] = (r.meta[h.storeId] || 0) + 1);
1063
+ this.notificationBelongToStore(s, h) && (i = !0, d[h.storeId] = (r.meta[h.storeId] || 0) + 1);
1050
1064
  }), this.store.setState({
1051
1065
  meta: {
1052
- ...c,
1053
- badge: i ? c.badge + 1 : c.badge
1066
+ ...d,
1067
+ badge: i ? d.badge + 1 : d.badge
1054
1068
  }
1055
1069
  }), i && this.emitter.emit("feed.new_notification", s), this.emitter.emit("feed.store_update", this.data);
1056
1070
  }
@@ -1064,13 +1078,13 @@ class se {
1064
1078
  if (t[0].status !== "fulfilled") return;
1065
1079
  const r = t[0].value;
1066
1080
  if (r.status === n.ERROR) return;
1067
- const i = r.body, c = (l = s.notifications) == null ? void 0 : l.some(
1081
+ const i = r.body, d = (l = s.notifications) == null ? void 0 : l.some(
1068
1082
  (h) => h.n_id === i.n_id
1069
1083
  );
1070
1084
  this.notificationBelongToStore(
1071
1085
  i,
1072
1086
  s.store
1073
- ) ? c ? this.store.setState({
1087
+ ) ? d ? this.store.setState({
1074
1088
  notifications: s.notifications.map((h) => h.n_id === i.n_id ? i : h)
1075
1089
  }) : this.store.setState({
1076
1090
  notifications: this.orderNotificationsBasedOnPinFlag(
@@ -1098,12 +1112,12 @@ class se {
1098
1112
  }), this.emitter.emit("feed.store_update", this.data);
1099
1113
  }
1100
1114
  notificationBelongToStore(e, t) {
1101
- var O, y, C, P;
1102
- const s = !!e.read_on, r = e.archived, i = e.tags, c = 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 = (C = t == null ? void 0 : t.query) == null ? void 0 : C.tags, R = (P = t == null ? void 0 : t.query) == null ? void 0 : P.categories, S = u == null || s === u, g = !!r == !!l;
1103
- let m = !1, T = !1;
1104
- return Array.isArray(h) && h.length > 0 ? h.forEach((F) => {
1105
- i != null && i.includes(F) && (m = !0);
1106
- }) : m = !0, Array.isArray(R) && R.length > 0 ? R.includes(c) && (T = !0) : T = !0, S && m && T && g;
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;
1118
+ return Array.isArray(h) && h.length > 0 ? h.forEach((E) => {
1119
+ i != null && i.includes(E) && (R = !0);
1120
+ }) : R = !0, Array.isArray(T) && T.length > 0 ? T.includes(d) && (g = !0) : g = !0, b && R && g && S;
1107
1121
  }
1108
1122
  orderNotificationsBasedOnPinFlag(e, t) {
1109
1123
  if (e.is_pinned)
@@ -1128,8 +1142,8 @@ class se {
1128
1142
  t && (this.store.setState({ notifications: s }), await this.fetchCount(), this.emitter.emit("feed.store_update", this.data));
1129
1143
  }
1130
1144
  getUrl(e, t) {
1131
- var c;
1132
- const s = `${(c = this.feedOptions.host) == null ? void 0 : c.apiHost}/v1/feed/${e}`, r = this.validateQueryParams(t), i = new URLSearchParams(
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(
1133
1147
  r
1134
1148
  ).toString();
1135
1149
  return i ? `${s}?${i}` : s;
@@ -1153,12 +1167,12 @@ class se {
1153
1167
  return e == null ? void 0 : e.map((s) => this.storeQueryParamObj(s));
1154
1168
  }
1155
1169
  storeQueryParamObj(e) {
1156
- 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;
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;
1157
1171
  return {
1158
1172
  store_id: e.storeId,
1159
1173
  query: {
1160
1174
  read: i,
1161
- archived: c,
1175
+ archived: d,
1162
1176
  tags: { or: s },
1163
1177
  categories: { or: r }
1164
1178
  }
@@ -1172,13 +1186,13 @@ class se {
1172
1186
  (i) => i.storeId === e
1173
1187
  );
1174
1188
  return s ? (this.store.setState({
1175
- ...w,
1189
+ ...U,
1176
1190
  store: s,
1177
1191
  meta: t.meta
1178
1192
  }), await this.fetch()) : {
1179
1193
  status: n.ERROR,
1180
1194
  error: {
1181
- type: d.NOT_FOUND,
1195
+ type: c.NOT_FOUND,
1182
1196
  message: `store with storeId ${e} doesnt exist`
1183
1197
  }
1184
1198
  };
@@ -1213,45 +1227,47 @@ class se {
1213
1227
  async fetch(e = {}) {
1214
1228
  const t = this.store.getState();
1215
1229
  if (this.requestInprogress()) return;
1216
- const s = (e == null ? void 0 : e.page) || 1, r = (e == null ? void 0 : e.pageSize) || this.feedOptions.pageSize, i = t._firstFetchedTimeStamp || Date.now();
1217
- s > 1 ? this.store.setState({
1218
- apiStatus: _.FETCHING_MORE
1219
- }) : (this.store.setState({
1230
+ const s = (e == null ? void 0 : e.pageSize) || this.feedOptions.pageSize;
1231
+ t.isFirstFetch ? (this.store.setState({
1220
1232
  apiStatus: _.LOADING
1221
- }), this.fetchCount()), this.emitter.emit("feed.store_update", this.data);
1222
- const c = {
1233
+ }), this.fetchCount()) : this.store.setState({
1234
+ apiStatus: _.FETCHING_MORE
1235
+ }), this.emitter.emit("feed.store_update", this.data);
1236
+ const r = {
1223
1237
  distinct_id: this.config.distinctId,
1224
1238
  tenant_id: this.feedOptions.tenantId,
1225
- page_size: r,
1226
- page_no: s,
1227
- before: i,
1228
- store: t.store.storeId !== v.storeId ? this.storeQueryParamObj(t.store) : null
1229
- }, u = this.getUrl("notifications", c), l = await this.config.client().request({ type: "get", url: u });
1230
- if (l.status === n.ERROR)
1231
- return this.store.setState({ apiStatus: _.ERROR }), this.emitter.emit("feed.store_update", this.data), l;
1232
- const h = l.body.meta.current_page === 1;
1233
- return this.store.setState({
1239
+ page_size: s,
1240
+ store: t.store.storeId !== D.storeId ? this.storeQueryParamObj(t.store) : null
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({
1234
1252
  apiStatus: _.SUCCESS,
1235
- notifications: h ? l.body.results : [...t.notifications, ...l.body.results],
1253
+ notifications: t.isFirstFetch ? d.body.results : [...t.notifications, ...d.body.results],
1236
1254
  pageInfo: {
1237
1255
  ...t.pageInfo,
1238
- total: l.body.meta.total_count,
1239
- currentPage: l.body.meta.current_page,
1240
- totalPages: l.body.meta.total_pages
1256
+ total: d.body.meta.total_count,
1257
+ hasMore: d.body.meta.has_more
1241
1258
  },
1242
- _firstFetchedTimeStamp: i
1243
- }), this.emitter.emit("feed.store_update", this.data), this.startExpiryTimer(), l;
1259
+ isFirstFetch: !1
1260
+ }), this.emitter.emit("feed.store_update", this.data), this.startExpiryTimer(), d);
1244
1261
  }
1245
1262
  // TODO: support other stores
1246
1263
  async fetchNextPage() {
1247
- const e = this.store.getState();
1248
- return e.pageInfo.currentPage >= e.pageInfo.totalPages ? {
1264
+ return this.store.getState().pageInfo.hasMore === !1 ? {
1249
1265
  status: n.ERROR,
1250
1266
  error: {
1251
- type: d.VALIDATION_ERROR,
1267
+ type: c.VALIDATION_ERROR,
1252
1268
  message: "No more pages to fetch"
1253
1269
  }
1254
- } : this.fetch({ page: e.pageInfo.currentPage + 1 });
1270
+ } : this.fetch();
1255
1271
  }
1256
1272
  async fetchCount() {
1257
1273
  const e = {
@@ -1367,8 +1383,8 @@ class se {
1367
1383
  reset() {
1368
1384
  var e;
1369
1385
  this.store.setState({
1370
- ...w,
1371
- store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) || v
1386
+ ...U,
1387
+ store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) || D
1372
1388
  }), this.emitter.emit("feed.store_update", this.data), this.expiryTimerId && (clearInterval(this.expiryTimerId), this.expiryTimerId = void 0);
1373
1389
  }
1374
1390
  remove() {
@@ -1376,7 +1392,7 @@ class se {
1376
1392
  this.reset(), this.emitter.off("*"), (e = this.socket) == null || e.disconnect(), this.config.feeds.removeInstance(this);
1377
1393
  }
1378
1394
  }
1379
- const re = "https://hub.suprsend.com", ie = "serviceworker.js", M = "ss_distinct_id";
1395
+ const re = "https://hub.suprsend.com", ie = "serviceworker.js", L = "ss_distinct_id";
1380
1396
  class ue {
1381
1397
  constructor(e, t) {
1382
1398
  f(this, "host");
@@ -1391,16 +1407,16 @@ class ue {
1391
1407
  f(this, "user", new Z(this));
1392
1408
  f(this, "webpush", new X(this));
1393
1409
  f(this, "feeds", new te(this));
1394
- f(this, "emitter", L());
1410
+ f(this, "emitter", V());
1395
1411
  if (!e)
1396
1412
  throw new Error("[SuprSend]: publicApiKey is missing");
1397
1413
  this.publicApiKey = e, this.host = (t == null ? void 0 : t.host) || re, this.vapidKey = (t == null ? void 0 : t.vapidKey) || "", this.swFileName = (t == null ? void 0 : t.swFileName) || ie;
1398
1414
  }
1399
1415
  handleRefreshUserToken(e) {
1400
- if (!this.userToken || !E()) return;
1401
- const t = V(this.userToken), s = (t.exp || 0) * 1e3, r = Date.now(), i = 1e3 * 30;
1416
+ if (!this.userToken || !A()) return;
1417
+ const t = x(this.userToken), s = (t.exp || 0) * 1e3, r = Date.now(), i = 1e3 * 30;
1402
1418
  if (s && s > r) {
1403
- const c = s - r - i;
1419
+ const d = s - r - i;
1404
1420
  this.userTokenExpirationTimer && clearTimeout(this.userTokenExpirationTimer), this.userTokenExpirationTimer = setTimeout(async () => {
1405
1421
  let u = "";
1406
1422
  try {
@@ -1419,13 +1435,13 @@ class ue {
1419
1435
  }
1420
1436
  }
1421
1437
  u && typeof u == "string" && this.identify(this.distinctId, u, this.authenticateOptions);
1422
- }, c);
1438
+ }, d);
1423
1439
  }
1424
1440
  }
1425
1441
  client() {
1426
1442
  return this.distinctId || console.warn(
1427
1443
  "[SuprSend]: distinctId is missing. User should be authenticated"
1428
- ), this.apiClient || (this.apiClient = new D(this)), this.apiClient;
1444
+ ), this.apiClient || (this.apiClient = new N(this)), this.apiClient;
1429
1445
  }
1430
1446
  eventApi(e) {
1431
1447
  return this.client().request({
@@ -1442,34 +1458,34 @@ class ue {
1442
1458
  if (!e)
1443
1459
  return o({
1444
1460
  status: n.ERROR,
1445
- errorType: d.VALIDATION_ERROR,
1461
+ errorType: c.VALIDATION_ERROR,
1446
1462
  errorMessage: "distinctId is missing"
1447
1463
  });
1448
1464
  if (this.apiClient && this.distinctId && this.distinctId !== e)
1449
1465
  return o({
1450
1466
  status: n.ERROR,
1451
- errorType: d.VALIDATION_ERROR,
1467
+ errorType: c.VALIDATION_ERROR,
1452
1468
  errorMessage: "User already loggedin, reset current user to login new user"
1453
1469
  });
1454
1470
  if (this.apiClient && this.distinctId === e && this.userToken !== t)
1455
- return this.userToken = t, this.apiClient = new D(this), s != null && s.refreshUserToken && this.handleRefreshUserToken(s.refreshUserToken), o({ status: n.SUCCESS });
1471
+ return this.userToken = t, this.apiClient = new N(this), s != null && s.refreshUserToken && this.handleRefreshUserToken(s.refreshUserToken), o({ status: n.SUCCESS });
1456
1472
  if (this.distinctId && this.apiClient)
1457
1473
  return o({ status: n.SUCCESS });
1458
- this.distinctId = e, this.userToken = t, this.apiClient = new D(this), this.authenticateOptions = s;
1459
- const r = $(
1460
- M
1474
+ this.distinctId = e, this.userToken = t, this.apiClient = new N(this), this.authenticateOptions = s;
1475
+ const r = j(
1476
+ L
1461
1477
  );
1462
1478
  if (s != null && s.refreshUserToken && this.handleRefreshUserToken(s.refreshUserToken), r == this.distinctId)
1463
1479
  return this.webpush.updatePushSubscription(), o({ status: n.SUCCESS });
1464
1480
  const i = await this.eventApi({
1465
1481
  event: "$identify",
1466
- $insert_id: A(),
1467
- $time: N(),
1482
+ $insert_id: C(),
1483
+ $time: P(),
1468
1484
  properties: {
1469
1485
  $identified_id: e
1470
1486
  }
1471
1487
  });
1472
- return i.status === n.SUCCESS ? (this.webpush.updatePushSubscription(), x(M, this.distinctId)) : this.reset({ unsubscribePush: !1 }), i;
1488
+ return i.status === n.SUCCESS ? (this.webpush.updatePushSubscription(), $(L, this.distinctId)) : this.reset({ unsubscribePush: !1 }), i;
1473
1489
  }
1474
1490
  /**
1475
1491
  * Check's if SuprSend instance is authenticated. To check if userToken is also present pass true.
@@ -1484,13 +1500,13 @@ class ue {
1484
1500
  let s = {};
1485
1501
  return e ? (typeof t == "object" && (s = { ...s, ...t }), this.eventApi({
1486
1502
  event: String(e),
1487
- $insert_id: A(),
1488
- $time: N(),
1503
+ $insert_id: C(),
1504
+ $time: P(),
1489
1505
  distinct_id: this.distinctId,
1490
1506
  properties: s
1491
1507
  })) : o({
1492
1508
  status: n.ERROR,
1493
- errorType: d.VALIDATION_ERROR,
1509
+ errorType: c.VALIDATION_ERROR,
1494
1510
  errorMessage: "event name is missing"
1495
1511
  });
1496
1512
  }
@@ -1504,8 +1520,8 @@ class ue {
1504
1520
  }
1505
1521
  export {
1506
1522
  _ as ApiResponseStatus,
1507
- b as ChannelLevelPreferenceOptions,
1508
- d as ERROR_TYPE,
1523
+ w as ChannelLevelPreferenceOptions,
1524
+ c as ERROR_TYPE,
1509
1525
  se as Feed,
1510
1526
  p as PreferenceOptions,
1511
1527
  n as RESPONSE_STATUS,