@suprsend/web-sdk 4.3.1 → 4.4.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
- var B = Object.defineProperty;
2
- var Q = (i, e, t) => e in i ? B(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
- var l = (i, e, t) => Q(i, typeof e != "symbol" ? e + "" : e, t);
4
- import H from "mitt";
5
- import L from "jwt-decode";
6
- import { createStore as G } from "zustand/vanilla";
7
- import { io as J } from "socket.io-client";
8
- var p = /* @__PURE__ */ ((i) => (i.OPT_IN = "opt_in", i.OPT_OUT = "opt_out", i))(p || {}), w = /* @__PURE__ */ ((i) => (i.ALL = "all", i.REQUIRED = "required", i))(w || {}), d = /* @__PURE__ */ ((i) => (i.VALIDATION_ERROR = "VALIDATION_ERROR", i.NETWORK_ERROR = "NETWORK_ERROR", i.UNKNOWN_ERROR = "UNKNOWN_ERROR", i.PERMISSION_DENIED = "PERMISSION_DENIED", i.UNSUPPORTED_ACTION = "UNSUPPORTED_ACTION", i.NOT_FOUND = "NOT_FOUND", i))(d || {}), a = /* @__PURE__ */ ((i) => (i.SUCCESS = "success", i.ERROR = "error", i))(a || {}), S = /* @__PURE__ */ ((i) => (i.INITIAL = "INITIAL", i.LOADING = "LOADING", i.SUCCESS = "SUCCESS", i.ERROR = "ERROR", i.FETCHING_MORE = "FETCHING_MORE", i))(S || {});
9
- const X = "@suprsend/web-sdk", Z = "4.3.1";
1
+ var z = Object.defineProperty;
2
+ var G = (i, e, t) => e in i ? z(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
+ var l = (i, e, t) => G(i, typeof e != "symbol" ? e + "" : e, t);
4
+ import W from "mitt";
5
+ import x from "jwt-decode";
6
+ import { createStore as Q } from "zustand/vanilla";
7
+ import { io as Y } from "socket.io-client";
8
+ var y = /* @__PURE__ */ ((i) => (i.OPT_IN = "opt_in", i.OPT_OUT = "opt_out", i))(y || {}), w = /* @__PURE__ */ ((i) => (i.ALL = "all", i.REQUIRED = "required", i))(w || {}), J = /* @__PURE__ */ ((i) => (i.INSTANTLY = "instantly", i.MINUTELY = "minutely", i.HOURLY = "hourly", i.DAILY = "daily", i.WEEKLY = "weekly", i.WEEKLY_MO2FR = "weekly_mo2fr", i.MONTHLY = "monthly", i))(J || {}), X = /* @__PURE__ */ ((i) => (i.INTEGER = "integer", i.STRING = "string", i.STRING_CHOICE = "string_choice", i.LIST_CHOICE = "list_choice", i.STRING_DYNAMIC = "string_dynamic", i.LIST_DYNAMIC = "list_dynamic", i))(X || {}), Z = /* @__PURE__ */ ((i) => (i.LOCKED = "locked", i.EDITABLE = "editable", i))(Z || {}), q = /* @__PURE__ */ ((i) => (i.SUNDAY = "su", i.MONDAY = "mo", i.TUESDAY = "tu", i.WEDNESDAY = "we", i.THURSDAY = "th", i.FRIDAY = "fr", i.SATURDAY = "sa", i))(q || {}), c = /* @__PURE__ */ ((i) => (i.VALIDATION_ERROR = "VALIDATION_ERROR", i.NETWORK_ERROR = "NETWORK_ERROR", i.UNKNOWN_ERROR = "UNKNOWN_ERROR", i.PERMISSION_DENIED = "PERMISSION_DENIED", i.UNSUPPORTED_ACTION = "UNSUPPORTED_ACTION", i.NOT_FOUND = "NOT_FOUND", i))(c || {}), a = /* @__PURE__ */ ((i) => (i.SUCCESS = "success", i.ERROR = "error", i))(a || {}), A = /* @__PURE__ */ ((i) => (i.INITIAL = "INITIAL", i.LOADING = "LOADING", i.SUCCESS = "SUCCESS", i.ERROR = "ERROR", i.FETCHING_MORE = "FETCHING_MORE", i))(A || {});
9
+ const ee = "@suprsend/web-sdk", te = "4.4.0";
10
10
  function D() {
11
11
  let i = (/* @__PURE__ */ new Date()).getTime();
12
12
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
@@ -20,19 +20,19 @@ function D() {
20
20
  function M() {
21
21
  return Math.round(Date.now());
22
22
  }
23
- function I(i) {
23
+ function S(i) {
24
24
  return Object.keys(i).length === 0;
25
25
  }
26
- function Y(i) {
26
+ function se(i) {
27
27
  return (i == null ? void 0 : i.length) <= 0;
28
28
  }
29
- function q(i) {
29
+ function re(i) {
30
30
  const e = "=".repeat((4 - i.length % 4) % 4), t = (i + e).replace(/-/g, "+").replace(/_/g, "/"), s = atob(t), r = new Uint8Array(s.length);
31
31
  for (let n = 0; n < s.length; ++n)
32
32
  r[n] = s.charCodeAt(n);
33
33
  return r;
34
34
  }
35
- function ee(i, e) {
35
+ function ie(i, e) {
36
36
  let t;
37
37
  return (...s) => (clearTimeout(t), new Promise((r) => {
38
38
  t = setTimeout(() => r(i(...s)), e);
@@ -42,7 +42,7 @@ function F(i, e) {
42
42
  const t = {};
43
43
  return (...s) => {
44
44
  const [r] = s, n = s.slice(1);
45
- return typeof t[r] == "function" ? t[r](...n) : (t[r] = ee(i, e), t[r](...n));
45
+ return typeof t[r] == "function" ? t[r](...n) : (t[r] = ie(i, e), t[r](...n));
46
46
  };
47
47
  }
48
48
  function o(i) {
@@ -71,36 +71,36 @@ function j(i) {
71
71
  return e;
72
72
  }
73
73
  }
74
- function te(i) {
74
+ function ne(i) {
75
75
  V() && localStorage.removeItem(i);
76
76
  }
77
77
  function U() {
78
78
  return typeof navigator < "u" && navigator.userAgent || "";
79
79
  }
80
- function se(i = U()) {
80
+ function ae(i = U()) {
81
81
  let e;
82
82
  return (e = i.match(/Windows NT (\d+(?:\.\d+)*)/i)) ? { os: "windows", os_version: e[1] } : (e = i.match(
83
83
  /(?:iPhone|iPad|iPod)[^;]*;\s*CPU[^)]*OS (\d+[_.]\d+(?:[_.]\d+)?)/i
84
84
  )) ? { os: "ios", os_version: e[1].replace(/_/g, ".") } : (e = i.match(/Android (\d+(?:\.\d+)*)/i)) ? { os: "android", os_version: e[1] } : (e = i.match(/Mac OS X (\d+[_.]\d+(?:[_.]\d+)?)/i)) ? { os: "mac os", os_version: e[1].replace(/_/g, ".") } : /Linux/i.test(i) ? { os: "linux", os_version: "" } : { os: "", os_version: "" };
85
85
  }
86
- function re(i = U()) {
86
+ function oe(i = U()) {
87
87
  let e;
88
88
  return (e = i.match(/Edg(?:e|A|iOS)?\/(\d+(?:\.\d+)*)/i)) ? { browser: "edge", browser_version: e[1] } : (e = i.match(/OPR\/(\d+(?:\.\d+)*)/i)) ? { browser: "opera", browser_version: e[1] } : (e = i.match(/Firefox\/(\d+(?:\.\d+)*)/i)) ? { browser: "firefox", browser_version: e[1] } : (e = i.match(/Chrome\/(\d+(?:\.\d+)*)/i)) ? { browser: "chrome", browser_version: e[1] } : (e = i.match(/Version\/(\d+(?:\.\d+)*)[^)]*Safari/i)) ? { browser: "safari", browser_version: e[1] } : /Safari/i.test(i) ? { browser: "safari", browser_version: "" } : { browser: "", browser_version: "" };
89
89
  }
90
- function ie(i = U()) {
90
+ function ce(i = U()) {
91
91
  return i ? /iPad|Tablet/i.test(i) || /Android/i.test(i) && !/Mobile/i.test(i) ? "tablet" : /Mobi|Android|iPhone|iPod/i.test(i) ? "mobile" : "desktop" : "";
92
92
  }
93
- function ne(i, e) {
94
- const t = U(), { os: s, os_version: r } = se(t), { browser: n, browser_version: c } = re(t), u = {
95
- sdk: X.toLowerCase(),
96
- sdk_version: Z.toLowerCase(),
93
+ function de(i, e) {
94
+ const t = U(), { os: s, os_version: r } = ae(t), { browser: n, browser_version: d } = oe(t), u = {
95
+ sdk: ee.toLowerCase(),
96
+ sdk_version: te.toLowerCase(),
97
97
  lang: "javascript",
98
98
  platform: "browser",
99
- environment: ie(t),
99
+ environment: ce(t),
100
100
  os: s,
101
101
  os_version: r,
102
102
  browser: n,
103
- browser_version: c
103
+ browser_version: d
104
104
  };
105
105
  if (i != null && i.name && (u.app_info = {
106
106
  name: i.name,
@@ -108,25 +108,25 @@ function ne(i, e) {
108
108
  }), !e) return u;
109
109
  const f = { ...u };
110
110
  for (const h of Object.keys(e)) {
111
- const O = e[h];
112
- O !== void 0 && (h === "app_info" ? f.app_info = { ...u.app_info, ...O } : f[h] = O);
111
+ const p = e[h];
112
+ p !== void 0 && (h === "app_info" ? f.app_info = { ...u.app_info, ...p } : f[h] = p);
113
113
  }
114
114
  return f;
115
115
  }
116
- function ae(i) {
116
+ function ue(i) {
117
117
  return i != null && i.name ? i.version ? `${i.name}/${i.version}` : i.name : "";
118
118
  }
119
- function oe(i) {
119
+ function he(i) {
120
120
  const e = i.sdk || "", t = i.sdk_version || "";
121
121
  let s = t ? `${e}/${t}` : e;
122
122
  const r = i.browser ? `${i.browser}${i.browser_version ? `/${i.browser_version}` : ""}` : i.lang || "", n = [];
123
123
  r && n.push(r), i.os && n.push(i.os), n.length && (s += ` (${n.join("; ")})`);
124
- const c = ae(i.app_info);
125
- return c && (s += ` (${c})`), s;
124
+ const d = ue(i.app_info);
125
+ return d && (s += ` (${d})`), s;
126
126
  }
127
- async function ce(i) {
127
+ async function fe(i) {
128
128
  const t = new TextEncoder().encode(i), s = await crypto.subtle.digest("SHA-256", t);
129
- return Array.from(new Uint8Array(s)).map((c) => c.toString(16).padStart(2, "0")).join("");
129
+ return Array.from(new Uint8Array(s)).map((d) => d.toString(16).padStart(2, "0")).join("");
130
130
  }
131
131
  class P {
132
132
  constructor(e) {
@@ -184,12 +184,12 @@ class P {
184
184
  if (!this.config.distinctId)
185
185
  return o({
186
186
  status: a.ERROR,
187
- errorType: d.VALIDATION_ERROR,
187
+ errorType: c.VALIDATION_ERROR,
188
188
  errorMessage: "User isn't authenticated. Call identify method before performing any action"
189
189
  });
190
190
  if ((t = this.config.authenticateOptions) != null && t.refreshUserToken && this.config.userToken) {
191
- const n = L(this.config.userToken), c = (n.exp || 0) * 1e3, u = Date.now();
192
- if (c <= u)
191
+ const n = x(this.config.userToken), d = (n.exp || 0) * 1e3, u = Date.now();
192
+ if (d <= u)
193
193
  try {
194
194
  const h = await this.config.authenticateOptions.refreshUserToken(
195
195
  this.config.userToken,
@@ -204,25 +204,25 @@ class P {
204
204
  }
205
205
  }
206
206
  try {
207
- const n = await this.requestApiInstance(e), c = await n.json(), u = (c == null ? void 0 : c.status) || (n.ok ? a.SUCCESS : a.ERROR);
207
+ const n = await this.requestApiInstance(e), d = await n.json(), u = (d == null ? void 0 : d.status) || (n.ok ? a.SUCCESS : a.ERROR);
208
208
  return o({
209
209
  status: u,
210
- body: c,
210
+ body: d,
211
211
  statusCode: n.status,
212
- errorMessage: (s = c == null ? void 0 : c.error) == null ? void 0 : s.message,
213
- errorType: (r = c == null ? void 0 : c.error) == null ? void 0 : r.type
212
+ errorMessage: (s = d == null ? void 0 : d.error) == null ? void 0 : s.message,
213
+ errorType: (r = d == null ? void 0 : d.error) == null ? void 0 : r.type
214
214
  });
215
215
  } catch (n) {
216
216
  return console.error(n), o({
217
217
  status: a.ERROR,
218
218
  statusCode: 500,
219
219
  errorMessage: (n == null ? void 0 : n.message) || "network error",
220
- errorType: d.NETWORK_ERROR
220
+ errorType: c.NETWORK_ERROR
221
221
  });
222
222
  }
223
223
  }
224
224
  }
225
- class de {
225
+ class le {
226
226
  constructor(e) {
227
227
  l(this, "config");
228
228
  l(this, "preferenceData");
@@ -296,7 +296,7 @@ class de {
296
296
  if (!e)
297
297
  return o({
298
298
  status: a.ERROR,
299
- errorType: d.VALIDATION_ERROR,
299
+ errorType: c.VALIDATION_ERROR,
300
300
  errorMessage: "Category parameter is missing"
301
301
  });
302
302
  const s = {
@@ -314,16 +314,16 @@ class de {
314
314
  return await this.config.client().request({ type: "get", url: s });
315
315
  }
316
316
  async _updateCategoryPreferences(e, t, s, r) {
317
- const n = this.getUrl(`category/${e}`, r), c = await this.config.client().request({
317
+ const n = this.getUrl(`category/${e}`, r), d = await this.config.client().request({
318
318
  type: "patch",
319
319
  url: n,
320
320
  payload: t
321
321
  });
322
- return c != null && c.error ? this.config.emitter.emit("preferences_error", c) : (Object.assign(s, c.body), this.config.emitter.emit("preferences_updated", {
322
+ return d != null && d.error ? this.config.emitter.emit("preferences_error", d) : (Object.assign(s, d.body), this.config.emitter.emit("preferences_updated", {
323
323
  status: a.SUCCESS,
324
324
  statusCode: 200,
325
325
  body: this.data
326
- })), c;
326
+ })), d;
327
327
  }
328
328
  async _updateChannelPreferences(e, t) {
329
329
  const s = this.getUrl("channel_preference", t), r = await this.config.client().request({
@@ -341,51 +341,51 @@ class de {
341
341
  * Used to update user's category level preference.
342
342
  */
343
343
  async updateCategoryPreference(e, t, s) {
344
- var h, O, v, T, g;
345
- if (!e || ![p.OPT_IN, p.OPT_OUT].includes(
344
+ var h, p, m, O, R;
345
+ if (!e || ![y.OPT_IN, y.OPT_OUT].includes(
346
346
  t
347
347
  ))
348
348
  return o({
349
349
  status: a.ERROR,
350
- errorType: d.VALIDATION_ERROR,
350
+ errorType: c.VALIDATION_ERROR,
351
351
  errorMessage: e ? "Preference parameter is invalid" : "Category parameter is missing"
352
352
  });
353
353
  if (!this.data)
354
354
  return o({
355
355
  status: a.ERROR,
356
- errorType: d.VALIDATION_ERROR,
356
+ errorType: c.VALIDATION_ERROR,
357
357
  errorMessage: "Call getPreferences method before performing action"
358
358
  });
359
359
  if (!this.data.sections)
360
360
  return o({
361
361
  status: a.ERROR,
362
- errorType: d.VALIDATION_ERROR,
362
+ errorType: c.VALIDATION_ERROR,
363
363
  errorMessage: "Sections doesn't exist"
364
364
  });
365
365
  let r = null, n = !1;
366
- for (const R of this.data.sections) {
367
- let y = !1;
368
- if (R.subcategories) {
369
- for (const m of R.subcategories)
370
- if (m.category === e)
371
- if (r = m, m.is_editable) {
372
- if (m.preference !== t) {
373
- m.preference = t, n = !0, y = !0;
366
+ for (const g of this.data.sections) {
367
+ let I = !1;
368
+ if (g.subcategories) {
369
+ for (const _ of g.subcategories)
370
+ if (_.category === e)
371
+ if (r = _, _.is_editable) {
372
+ if (_.preference !== t) {
373
+ _.preference = t, n = !0, I = !0;
374
374
  break;
375
375
  }
376
376
  } else
377
377
  return o({
378
378
  status: a.ERROR,
379
- errorType: d.VALIDATION_ERROR,
379
+ errorType: c.VALIDATION_ERROR,
380
380
  errorMessage: "Category preference is not editable"
381
381
  });
382
- if (y) break;
382
+ if (I) break;
383
383
  }
384
384
  }
385
385
  if (!r)
386
386
  return o({
387
387
  status: a.ERROR,
388
- errorType: d.VALIDATION_ERROR,
388
+ errorType: c.VALIDATION_ERROR,
389
389
  errorMessage: "Category not found"
390
390
  });
391
391
  if (!n)
@@ -393,15 +393,15 @@ class de {
393
393
  status: a.SUCCESS,
394
394
  body: this.data
395
395
  });
396
- const c = [];
397
- (h = r == null ? void 0 : r.channels) == null || h.forEach((R) => {
398
- R.preference === p.OPT_OUT && c.push(R.channel);
396
+ const d = [];
397
+ (h = r == null ? void 0 : r.channels) == null || h.forEach((g) => {
398
+ g.preference === y.OPT_OUT && d.push(g.channel);
399
399
  });
400
400
  let u = !0;
401
- typeof (s == null ? void 0 : s.showOptOutChannels) == "boolean" ? u = s == null ? void 0 : s.showOptOutChannels : typeof ((O = this.preferenceArgs) == null ? void 0 : O.showOptOutChannels) == "boolean" && (u = this.preferenceArgs.showOptOutChannels);
401
+ typeof (s == null ? void 0 : s.showOptOutChannels) == "boolean" ? u = s == null ? void 0 : s.showOptOutChannels : typeof ((p = this.preferenceArgs) == null ? void 0 : p.showOptOutChannels) == "boolean" && (u = this.preferenceArgs.showOptOutChannels);
402
402
  const f = {
403
403
  preference: r.preference,
404
- opt_out_channels: u && t === p.OPT_IN ? null : c
404
+ opt_out_channels: u && t === y.OPT_IN ? null : d
405
405
  };
406
406
  return this.debouncedUpdateCategoryPreferences(
407
407
  e,
@@ -409,10 +409,10 @@ class de {
409
409
  f,
410
410
  r,
411
411
  {
412
- tenant_id: (s == null ? void 0 : s.tenantId) || ((v = this.preferenceArgs) == null ? void 0 : v.tenantId),
412
+ tenant_id: (s == null ? void 0 : s.tenantId) || ((m = this.preferenceArgs) == null ? void 0 : m.tenantId),
413
413
  show_opt_out_channels: u,
414
- tags: (s == null ? void 0 : s.tags) || ((T = this.preferenceArgs) == null ? void 0 : T.tags),
415
- locale: (s == null ? void 0 : s.locale) || ((g = this.preferenceArgs) == null ? void 0 : g.locale)
414
+ tags: (s == null ? void 0 : s.tags) || ((O = this.preferenceArgs) == null ? void 0 : O.tags),
415
+ locale: (s == null ? void 0 : s.locale) || ((R = this.preferenceArgs) == null ? void 0 : R.locale)
416
416
  }
417
417
  ), o({
418
418
  status: a.SUCCESS,
@@ -423,51 +423,51 @@ class de {
423
423
  * Used to update user's category level channel preference.
424
424
  */
425
425
  async updateChannelPreferenceInCategory(e, t, s, r) {
426
- var T, g, R, y, m;
426
+ var O, R, g, I, _;
427
427
  if (!e || !s)
428
428
  return o({
429
429
  status: a.ERROR,
430
- errorType: d.VALIDATION_ERROR,
430
+ errorType: c.VALIDATION_ERROR,
431
431
  errorMessage: e ? "Category parameter is missing" : "Channel parameter is missing"
432
432
  });
433
- if (![p.OPT_IN, p.OPT_OUT].includes(
433
+ if (![y.OPT_IN, y.OPT_OUT].includes(
434
434
  t
435
435
  ))
436
436
  return o({
437
437
  status: a.ERROR,
438
- errorType: d.VALIDATION_ERROR,
438
+ errorType: c.VALIDATION_ERROR,
439
439
  errorMessage: "Preference parameter is invalid"
440
440
  });
441
441
  if (!this.data)
442
442
  return o({
443
443
  status: a.ERROR,
444
- errorType: d.VALIDATION_ERROR,
444
+ errorType: c.VALIDATION_ERROR,
445
445
  errorMessage: "Call getPreferences method before performing action"
446
446
  });
447
447
  if (!this.data.sections)
448
448
  return o({
449
449
  status: a.ERROR,
450
- errorType: d.VALIDATION_ERROR,
450
+ errorType: c.VALIDATION_ERROR,
451
451
  errorMessage: "Sections doesn't exist"
452
452
  });
453
- let n = null, c = null, u = !1;
454
- for (const _ of this.data.sections) {
453
+ let n = null, d = null, u = !1;
454
+ for (const T of this.data.sections) {
455
455
  let E = !1;
456
- if (_.subcategories) {
457
- for (const b of _.subcategories) {
456
+ if (T.subcategories) {
457
+ for (const b of T.subcategories) {
458
458
  if (b.category === s) {
459
459
  if (n = b, !b.channels) continue;
460
- for (const A of b.channels)
461
- if (A.channel === e)
462
- if (c = A, A.is_editable) {
463
- if (A.preference !== t) {
464
- A.preference = t, t === p.OPT_IN && (b.preference = p.OPT_IN), u = !0, E = !0;
460
+ for (const v of b.channels)
461
+ if (v.channel === e)
462
+ if (d = v, v.is_editable) {
463
+ if (v.preference !== t) {
464
+ v.preference = t, t === y.OPT_IN && (b.preference = y.OPT_IN), u = !0, E = !0;
465
465
  break;
466
466
  }
467
467
  } else
468
468
  return o({
469
469
  status: a.ERROR,
470
- errorType: d.VALIDATION_ERROR,
470
+ errorType: c.VALIDATION_ERROR,
471
471
  errorMessage: "Channel preference is not editable"
472
472
  });
473
473
  }
@@ -479,13 +479,13 @@ class de {
479
479
  if (!n)
480
480
  return o({
481
481
  status: a.ERROR,
482
- errorType: d.VALIDATION_ERROR,
482
+ errorType: c.VALIDATION_ERROR,
483
483
  errorMessage: "Category not found"
484
484
  });
485
- if (!c)
485
+ if (!d)
486
486
  return o({
487
487
  status: a.ERROR,
488
- errorType: d.VALIDATION_ERROR,
488
+ errorType: c.VALIDATION_ERROR,
489
489
  errorMessage: "Category's channel not found"
490
490
  });
491
491
  if (!u)
@@ -494,31 +494,161 @@ class de {
494
494
  body: this.data
495
495
  });
496
496
  const f = [];
497
- (T = n == null ? void 0 : n.channels) == null || T.forEach((_) => {
498
- _.preference === p.OPT_OUT && f.push(_.channel);
497
+ (O = n == null ? void 0 : n.channels) == null || O.forEach((T) => {
498
+ T.preference === y.OPT_OUT && f.push(T.channel);
499
499
  });
500
500
  let h = !0;
501
- typeof (r == null ? void 0 : r.showOptOutChannels) == "boolean" ? h = r == null ? void 0 : r.showOptOutChannels : typeof ((g = this.preferenceArgs) == null ? void 0 : g.showOptOutChannels) == "boolean" && (h = this.preferenceArgs.showOptOutChannels);
502
- const v = {
503
- preference: h && n.preference === p.OPT_OUT && t === p.OPT_IN ? p.OPT_IN : n.preference,
501
+ 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);
502
+ const m = {
503
+ preference: h && n.preference === y.OPT_OUT && t === y.OPT_IN ? y.OPT_IN : n.preference,
504
504
  opt_out_channels: f
505
505
  };
506
506
  return this.debouncedUpdateCategoryPreferences(
507
507
  s,
508
508
  s,
509
- v,
509
+ m,
510
510
  n,
511
511
  {
512
- tenant_id: (r == null ? void 0 : r.tenantId) || ((R = this.preferenceArgs) == null ? void 0 : R.tenantId),
512
+ tenant_id: (r == null ? void 0 : r.tenantId) || ((g = this.preferenceArgs) == null ? void 0 : g.tenantId),
513
513
  show_opt_out_channels: h,
514
- tags: (r == null ? void 0 : r.tags) || ((y = this.preferenceArgs) == null ? void 0 : y.tags),
515
- locale: (r == null ? void 0 : r.locale) || ((m = this.preferenceArgs) == null ? void 0 : m.locale)
514
+ tags: (r == null ? void 0 : r.tags) || ((I = this.preferenceArgs) == null ? void 0 : I.tags),
515
+ locale: (r == null ? void 0 : r.locale) || ((_ = this.preferenceArgs) == null ? void 0 : _.locale)
516
516
  }
517
517
  ), o({
518
518
  status: a.SUCCESS,
519
519
  body: this.data
520
520
  });
521
521
  }
522
+ /**
523
+ * Used to update user's category level digest configuration.
524
+ */
525
+ async updateDigestScheduleInCategory(e, t, s) {
526
+ var u, f, h, p;
527
+ if (!e)
528
+ return o({
529
+ status: a.ERROR,
530
+ errorType: c.VALIDATION_ERROR,
531
+ errorMessage: "Category parameter is missing"
532
+ });
533
+ if (!t || typeof t != "object")
534
+ return o({
535
+ status: a.ERROR,
536
+ errorType: c.VALIDATION_ERROR,
537
+ errorMessage: "Digest schedule parameter is invalid"
538
+ });
539
+ if (!this.data)
540
+ return o({
541
+ status: a.ERROR,
542
+ errorType: c.VALIDATION_ERROR,
543
+ errorMessage: "Call getPreferences method before performing action"
544
+ });
545
+ if (!this.data.sections)
546
+ return o({
547
+ status: a.ERROR,
548
+ errorType: c.VALIDATION_ERROR,
549
+ errorMessage: "Sections doesn't exist"
550
+ });
551
+ let r = null;
552
+ for (const m of this.data.sections) {
553
+ let O = !1;
554
+ if (m.subcategories) {
555
+ for (const R of m.subcategories)
556
+ if (R.category === e) {
557
+ r = R, O = !0;
558
+ break;
559
+ }
560
+ if (O) break;
561
+ }
562
+ }
563
+ if (!r)
564
+ return o({
565
+ status: a.ERROR,
566
+ errorType: c.VALIDATION_ERROR,
567
+ errorMessage: "Category not found"
568
+ });
569
+ let n = !0;
570
+ typeof (s == null ? void 0 : s.showOptOutChannels) == "boolean" ? n = s == null ? void 0 : s.showOptOutChannels : typeof ((u = this.preferenceArgs) == null ? void 0 : u.showOptOutChannels) == "boolean" && (n = this.preferenceArgs.showOptOutChannels);
571
+ const d = {
572
+ digest_schedule: t,
573
+ preference: r.preference
574
+ };
575
+ return this._updateCategoryPreferences(
576
+ e,
577
+ d,
578
+ r,
579
+ {
580
+ tenant_id: (s == null ? void 0 : s.tenantId) || ((f = this.preferenceArgs) == null ? void 0 : f.tenantId),
581
+ show_opt_out_channels: n,
582
+ tags: (s == null ? void 0 : s.tags) || ((h = this.preferenceArgs) == null ? void 0 : h.tags),
583
+ locale: (s == null ? void 0 : s.locale) || ((p = this.preferenceArgs) == null ? void 0 : p.locale)
584
+ }
585
+ );
586
+ }
587
+ /**
588
+ * Used to update user's category level condition configuration.
589
+ */
590
+ async updatePropertiesInCategory(e, t, s) {
591
+ var u, f, h, p;
592
+ if (!e)
593
+ return o({
594
+ status: a.ERROR,
595
+ errorType: c.VALIDATION_ERROR,
596
+ errorMessage: "Category parameter is missing"
597
+ });
598
+ if (!t || !Array.isArray(t))
599
+ return o({
600
+ status: a.ERROR,
601
+ errorType: c.VALIDATION_ERROR,
602
+ errorMessage: "Properties parameter is invalid"
603
+ });
604
+ if (!this.data)
605
+ return o({
606
+ status: a.ERROR,
607
+ errorType: c.VALIDATION_ERROR,
608
+ errorMessage: "Call getPreferences method before performing action"
609
+ });
610
+ if (!this.data.sections)
611
+ return o({
612
+ status: a.ERROR,
613
+ errorType: c.VALIDATION_ERROR,
614
+ errorMessage: "Sections doesn't exist"
615
+ });
616
+ let r = null;
617
+ for (const m of this.data.sections) {
618
+ let O = !1;
619
+ if (m.subcategories) {
620
+ for (const R of m.subcategories)
621
+ if (R.category === e) {
622
+ r = R, O = !0;
623
+ break;
624
+ }
625
+ if (O) break;
626
+ }
627
+ }
628
+ if (!r)
629
+ return o({
630
+ status: a.ERROR,
631
+ errorType: c.VALIDATION_ERROR,
632
+ errorMessage: "Category not found"
633
+ });
634
+ let n = !0;
635
+ typeof (s == null ? void 0 : s.showOptOutChannels) == "boolean" ? n = s == null ? void 0 : s.showOptOutChannels : typeof ((u = this.preferenceArgs) == null ? void 0 : u.showOptOutChannels) == "boolean" && (n = this.preferenceArgs.showOptOutChannels);
636
+ const d = {
637
+ properties: t,
638
+ preference: r.preference
639
+ };
640
+ return this._updateCategoryPreferences(
641
+ e,
642
+ d,
643
+ r,
644
+ {
645
+ tenant_id: (s == null ? void 0 : s.tenantId) || ((f = this.preferenceArgs) == null ? void 0 : f.tenantId),
646
+ show_opt_out_channels: n,
647
+ tags: (s == null ? void 0 : s.tags) || ((h = this.preferenceArgs) == null ? void 0 : h.tags),
648
+ locale: (s == null ? void 0 : s.locale) || ((p = this.preferenceArgs) == null ? void 0 : p.locale)
649
+ }
650
+ );
651
+ }
522
652
  /**
523
653
  * Used to update user's channel level preference.
524
654
  */
@@ -530,26 +660,26 @@ class de {
530
660
  ].includes(t))
531
661
  return o({
532
662
  status: a.ERROR,
533
- errorType: d.VALIDATION_ERROR,
663
+ errorType: c.VALIDATION_ERROR,
534
664
  errorMessage: e ? "Preference parameter is invalid" : "Channel parameter is missing"
535
665
  });
536
666
  if (!this.data)
537
667
  return o({
538
668
  status: a.ERROR,
539
- errorType: d.VALIDATION_ERROR,
669
+ errorType: c.VALIDATION_ERROR,
540
670
  errorMessage: "Call getPreferences method before performing action"
541
671
  });
542
672
  if (!this.data.channel_preferences)
543
673
  return o({
544
674
  status: a.ERROR,
545
- errorType: d.VALIDATION_ERROR,
675
+ errorType: c.VALIDATION_ERROR,
546
676
  errorMessage: "Channel preferences doesn't exist"
547
677
  });
548
678
  let r = null, n = !1;
549
- const c = t === w.REQUIRED;
679
+ const d = t === w.REQUIRED;
550
680
  for (const f of this.data.channel_preferences)
551
- if (f.channel === e && (r = f, f.is_restricted !== c)) {
552
- f.is_restricted = c, n = !0;
681
+ if (f.channel === e && (r = f, f.is_restricted !== d)) {
682
+ f.is_restricted = d, n = !0;
553
683
  break;
554
684
  }
555
685
  return r ? n ? (this.debouncedUpdateChannelPreferences(
@@ -564,17 +694,17 @@ class de {
564
694
  body: this.data
565
695
  }) : o({
566
696
  status: a.ERROR,
567
- errorType: d.VALIDATION_ERROR,
697
+ errorType: c.VALIDATION_ERROR,
568
698
  errorMessage: "Channel data not found"
569
699
  });
570
700
  }
571
701
  }
572
702
  const K = "ss_device_id";
573
- class ue {
703
+ class pe {
574
704
  constructor(e) {
575
705
  l(this, "config");
576
706
  l(this, "preferences");
577
- this.config = e, this.preferences = new de(e);
707
+ this.config = e, this.preferences = new le(e);
578
708
  }
579
709
  isReservedKey(e) {
580
710
  var t;
@@ -590,14 +720,14 @@ class ue {
590
720
  }
591
721
  validateObjData(e, t) {
592
722
  const s = {}, r = (t == null ? void 0 : t.allowReservedKeys) || !1, n = (t == null ? void 0 : t.valueType) || "";
593
- for (const c in e) {
594
- let u = e[c];
595
- if (!(c && u === void 0)) {
596
- if (!r && this.isReservedKey(c)) {
723
+ for (const d in e) {
724
+ let u = e[d];
725
+ if (!(d && u === void 0)) {
726
+ if (!r && this.isReservedKey(d)) {
597
727
  console.warn("[SuprSend]: key cannot start with $ or ss_");
598
728
  continue;
599
729
  }
600
- n === "number" ? u = Number(u) : n === "boolean" && (u = !!u), s[c] = u;
730
+ n === "number" ? u = Number(u) : n === "boolean" && (u = !!u), s[d] = u;
601
731
  }
602
732
  }
603
733
  return s;
@@ -630,13 +760,13 @@ class ue {
630
760
  if (!s)
631
761
  return o({
632
762
  status: a.ERROR,
633
- errorType: d.VALIDATION_ERROR,
763
+ errorType: c.VALIDATION_ERROR,
634
764
  errorMessage: "data provided is empty"
635
765
  });
636
766
  const r = this.validateObjData(s);
637
- return I(r) ? o({
767
+ return S(r) ? o({
638
768
  status: a.ERROR,
639
- errorType: d.VALIDATION_ERROR,
769
+ errorType: c.VALIDATION_ERROR,
640
770
  errorMessage: "data provided is empty"
641
771
  }) : this.triggerUserEvent({ $set: r });
642
772
  }
@@ -649,13 +779,13 @@ class ue {
649
779
  if (!s)
650
780
  return o({
651
781
  status: a.ERROR,
652
- errorType: d.VALIDATION_ERROR,
782
+ errorType: c.VALIDATION_ERROR,
653
783
  errorMessage: "data provided is empty"
654
784
  });
655
785
  const r = this.validateObjData(s);
656
- return I(r) ? o({
786
+ return S(r) ? o({
657
787
  status: a.ERROR,
658
- errorType: d.VALIDATION_ERROR,
788
+ errorType: c.VALIDATION_ERROR,
659
789
  errorMessage: "data provided is empty"
660
790
  }) : this.triggerUserEvent({ $set_once: r });
661
791
  }
@@ -668,13 +798,13 @@ class ue {
668
798
  if (!s)
669
799
  return o({
670
800
  status: a.ERROR,
671
- errorType: d.VALIDATION_ERROR,
801
+ errorType: c.VALIDATION_ERROR,
672
802
  errorMessage: "data provided is empty"
673
803
  });
674
804
  const r = this.validateObjData(s, { valueType: "number" });
675
- return I(r) ? o({
805
+ return S(r) ? o({
676
806
  status: a.ERROR,
677
- errorType: d.VALIDATION_ERROR,
807
+ errorType: c.VALIDATION_ERROR,
678
808
  errorMessage: "data provided is empty"
679
809
  }) : this.triggerUserEvent({ $add: r });
680
810
  }
@@ -687,13 +817,13 @@ class ue {
687
817
  if (!s)
688
818
  return o({
689
819
  status: a.ERROR,
690
- errorType: d.VALIDATION_ERROR,
820
+ errorType: c.VALIDATION_ERROR,
691
821
  errorMessage: "data provided is empty"
692
822
  });
693
823
  const r = this.validateObjData(s);
694
- return I(r) ? o({
824
+ return S(r) ? o({
695
825
  status: a.ERROR,
696
- errorType: d.VALIDATION_ERROR,
826
+ errorType: c.VALIDATION_ERROR,
697
827
  errorMessage: "data provided is empty"
698
828
  }) : this.triggerUserEvent({ $append: r });
699
829
  }
@@ -706,13 +836,13 @@ class ue {
706
836
  if (!s)
707
837
  return o({
708
838
  status: a.ERROR,
709
- errorType: d.VALIDATION_ERROR,
839
+ errorType: c.VALIDATION_ERROR,
710
840
  errorMessage: "data provided is empty"
711
841
  });
712
842
  const r = this.validateObjData(s);
713
- return I(r) ? o({
843
+ return S(r) ? o({
714
844
  status: a.ERROR,
715
- errorType: d.VALIDATION_ERROR,
845
+ errorType: c.VALIDATION_ERROR,
716
846
  errorMessage: "data provided is empty"
717
847
  }) : this.triggerUserEvent({ $remove: r });
718
848
  }
@@ -724,13 +854,13 @@ class ue {
724
854
  if (!t)
725
855
  return o({
726
856
  status: a.ERROR,
727
- errorType: d.VALIDATION_ERROR,
857
+ errorType: c.VALIDATION_ERROR,
728
858
  errorMessage: "data provided is empty"
729
859
  });
730
860
  const s = this.validateArrayData(t);
731
- return Y(s) ? o({
861
+ return se(s) ? o({
732
862
  status: a.ERROR,
733
- errorType: d.VALIDATION_ERROR,
863
+ errorType: c.VALIDATION_ERROR,
734
864
  errorMessage: "data provided is empty"
735
865
  }) : this.triggerUserEvent({ $unset: s });
736
866
  }
@@ -740,15 +870,15 @@ class ue {
740
870
  if (!s)
741
871
  return o({
742
872
  status: a.ERROR,
743
- errorType: d.VALIDATION_ERROR,
873
+ errorType: c.VALIDATION_ERROR,
744
874
  errorMessage: "data provided is empty"
745
875
  });
746
876
  const r = this.validateObjData(s, {
747
877
  allowReservedKeys: !0
748
878
  });
749
- return I(r) ? o({
879
+ return S(r) ? o({
750
880
  status: a.ERROR,
751
- errorType: d.VALIDATION_ERROR,
881
+ errorType: c.VALIDATION_ERROR,
752
882
  errorMessage: "data provided is empty"
753
883
  }) : this.triggerUserEvent({ $append: r });
754
884
  }
@@ -758,15 +888,15 @@ class ue {
758
888
  if (!s)
759
889
  return o({
760
890
  status: a.ERROR,
761
- errorType: d.VALIDATION_ERROR,
891
+ errorType: c.VALIDATION_ERROR,
762
892
  errorMessage: "data provided is empty"
763
893
  });
764
894
  const r = this.validateObjData(s, {
765
895
  allowReservedKeys: !0
766
896
  });
767
- return I(r) ? o({
897
+ return S(r) ? o({
768
898
  status: a.ERROR,
769
- errorType: d.VALIDATION_ERROR,
899
+ errorType: c.VALIDATION_ERROR,
770
900
  errorMessage: "data provided is empty"
771
901
  }) : this.triggerUserEvent({ $remove: r });
772
902
  }
@@ -775,15 +905,15 @@ class ue {
775
905
  if (!s)
776
906
  return o({
777
907
  status: a.ERROR,
778
- errorType: d.VALIDATION_ERROR,
908
+ errorType: c.VALIDATION_ERROR,
779
909
  errorMessage: "data provided is empty"
780
910
  });
781
911
  const r = this.validateObjData(s, {
782
912
  allowReservedKeys: !0
783
913
  });
784
- return I(r) ? o({
914
+ return S(r) ? o({
785
915
  status: a.ERROR,
786
- errorType: d.VALIDATION_ERROR,
916
+ errorType: c.VALIDATION_ERROR,
787
917
  errorMessage: "data provided is empty"
788
918
  }) : this.triggerUserEvent({ $set: r });
789
919
  }
@@ -796,14 +926,14 @@ class ue {
796
926
  async addEmail(e) {
797
927
  return this.validateEmail(e) ? this.appendInternal({ $email: e }) : o({
798
928
  status: a.ERROR,
799
- errorType: d.VALIDATION_ERROR,
929
+ errorType: c.VALIDATION_ERROR,
800
930
  errorMessage: "provided email is invalid"
801
931
  });
802
932
  }
803
933
  async removeEmail(e) {
804
934
  return this.validateEmail(e) ? this.removeInternal({ $email: e }) : o({
805
935
  status: a.ERROR,
806
- errorType: d.VALIDATION_ERROR,
936
+ errorType: c.VALIDATION_ERROR,
807
937
  errorMessage: "provided email is invalid"
808
938
  });
809
939
  }
@@ -813,7 +943,7 @@ class ue {
813
943
  async addSms(e) {
814
944
  return this.validateMobile(e) ? this.appendInternal({ $sms: e }) : o({
815
945
  status: a.ERROR,
816
- errorType: d.VALIDATION_ERROR,
946
+ errorType: c.VALIDATION_ERROR,
817
947
  errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
818
948
  });
819
949
  }
@@ -823,7 +953,7 @@ class ue {
823
953
  async removeSms(e) {
824
954
  return this.validateMobile(e) ? this.removeInternal({ $sms: e }) : o({
825
955
  status: a.ERROR,
826
- errorType: d.VALIDATION_ERROR,
956
+ errorType: c.VALIDATION_ERROR,
827
957
  errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
828
958
  });
829
959
  }
@@ -833,7 +963,7 @@ class ue {
833
963
  async addWhatsapp(e) {
834
964
  return this.validateMobile(e) ? this.appendInternal({ $whatsapp: e }) : o({
835
965
  status: a.ERROR,
836
- errorType: d.VALIDATION_ERROR,
966
+ errorType: c.VALIDATION_ERROR,
837
967
  errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
838
968
  });
839
969
  }
@@ -843,7 +973,7 @@ class ue {
843
973
  async removeWhatsapp(e) {
844
974
  return this.validateMobile(e) ? this.removeInternal({ $whatsapp: e }) : o({
845
975
  status: a.ERROR,
846
- errorType: d.VALIDATION_ERROR,
976
+ errorType: c.VALIDATION_ERROR,
847
977
  errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
848
978
  });
849
979
  }
@@ -855,7 +985,7 @@ class ue {
855
985
  if (typeof e != "object")
856
986
  return o({
857
987
  status: a.ERROR,
858
- errorType: d.VALIDATION_ERROR,
988
+ errorType: c.VALIDATION_ERROR,
859
989
  errorMessage: "provided push subscription is invalid, must be an object"
860
990
  });
861
991
  const t = this.getDeviceId();
@@ -869,7 +999,7 @@ class ue {
869
999
  if (typeof e != "object")
870
1000
  return o({
871
1001
  status: a.ERROR,
872
- errorType: d.VALIDATION_ERROR,
1002
+ errorType: c.VALIDATION_ERROR,
873
1003
  errorMessage: "provided push subscription is invalid, must be an object"
874
1004
  });
875
1005
  const t = this.getDeviceId();
@@ -882,28 +1012,28 @@ class ue {
882
1012
  async addSlack(e) {
883
1013
  return typeof e != "object" ? o({
884
1014
  status: a.ERROR,
885
- errorType: d.VALIDATION_ERROR,
1015
+ errorType: c.VALIDATION_ERROR,
886
1016
  errorMessage: "provided slack data is invalid, must be an object"
887
1017
  }) : this.appendInternal({ $slack: e });
888
1018
  }
889
1019
  async removeSlack(e) {
890
1020
  return typeof e != "object" ? o({
891
1021
  status: a.ERROR,
892
- errorType: d.VALIDATION_ERROR,
1022
+ errorType: c.VALIDATION_ERROR,
893
1023
  errorMessage: "provided slack data is invalid, must be an object"
894
1024
  }) : this.removeInternal({ $slack: e });
895
1025
  }
896
1026
  async addMSTeams(e) {
897
1027
  return typeof e != "object" ? o({
898
1028
  status: a.ERROR,
899
- errorType: d.VALIDATION_ERROR,
1029
+ errorType: c.VALIDATION_ERROR,
900
1030
  errorMessage: "provided ms_teams data is invalid, must be object"
901
1031
  }) : this.appendInternal({ $ms_teams: e });
902
1032
  }
903
1033
  async removeMSTeams(e) {
904
1034
  return typeof e != "object" ? o({
905
1035
  status: a.ERROR,
906
- errorType: d.VALIDATION_ERROR,
1036
+ errorType: c.VALIDATION_ERROR,
907
1037
  errorMessage: "provided ms_teams data is invalid, must be object"
908
1038
  }) : this.removeInternal({ $ms_teams: e });
909
1039
  }
@@ -914,7 +1044,7 @@ class ue {
914
1044
  async setPreferredLanguage(e) {
915
1045
  return typeof e != "string" ? o({
916
1046
  status: a.ERROR,
917
- errorType: d.VALIDATION_ERROR,
1047
+ errorType: c.VALIDATION_ERROR,
918
1048
  errorMessage: "provided language is invalid, must be string"
919
1049
  }) : this.setInternal({ $preferred_language: e });
920
1050
  }
@@ -924,13 +1054,13 @@ class ue {
924
1054
  async setTimezone(e) {
925
1055
  return typeof e != "string" ? o({
926
1056
  status: a.ERROR,
927
- errorType: d.VALIDATION_ERROR,
1057
+ errorType: c.VALIDATION_ERROR,
928
1058
  errorMessage: "provided timezone is invalid, must be string"
929
1059
  }) : this.setInternal({ $timezone: e });
930
1060
  }
931
1061
  }
932
- const x = "ss_wp_hash";
933
- class he {
1062
+ const L = "ss_wp_hash";
1063
+ class Re {
934
1064
  constructor(e) {
935
1065
  l(this, "config");
936
1066
  this.config = e;
@@ -947,13 +1077,13 @@ class he {
947
1077
  const t = e.endpoint;
948
1078
  let s = null;
949
1079
  try {
950
- s = await ce(t);
1080
+ s = await fe(t);
951
1081
  } catch {
952
1082
  }
953
1083
  if (s) {
954
- if (s === j(x))
1084
+ if (s === j(L))
955
1085
  return o({ status: a.SUCCESS });
956
- $(x, s);
1086
+ $(L, s);
957
1087
  }
958
1088
  return await this.config.user.addWebPush(e);
959
1089
  }
@@ -962,7 +1092,7 @@ class he {
962
1092
  if (await navigator.serviceWorker.register(`/${this.config.swFileName}`), await Notification.requestPermission() !== "granted")
963
1093
  return console.warn("[SuprSend]: Notification permission isnt granted"), o({
964
1094
  status: a.ERROR,
965
- errorType: d.PERMISSION_DENIED,
1095
+ errorType: c.PERMISSION_DENIED,
966
1096
  errorMessage: "Notification permission isn't granted"
967
1097
  });
968
1098
  const t = await navigator.serviceWorker.ready, s = await t.pushManager.getSubscription();
@@ -973,18 +1103,18 @@ class he {
973
1103
  "[SuprSend]: Vapid key is missing. Add it while creating SuprSend instance"
974
1104
  ), o({
975
1105
  status: a.ERROR,
976
- errorType: d.VALIDATION_ERROR,
1106
+ errorType: c.VALIDATION_ERROR,
977
1107
  errorMessage: "Vapid key is missing. Add it while creating SuprSend instance"
978
1108
  });
979
1109
  const r = await t.pushManager.subscribe({
980
1110
  userVisibleOnly: !0,
981
- applicationServerKey: q(this.config.vapidKey)
1111
+ applicationServerKey: re(this.config.vapidKey)
982
1112
  });
983
1113
  return this.checkAndUpdateOnServer(r);
984
1114
  } catch (e) {
985
1115
  return console.warn("SuprSend: Error getting push subscription", e), o({
986
1116
  status: a.ERROR,
987
- errorType: d.UNKNOWN_ERROR,
1117
+ errorType: c.UNKNOWN_ERROR,
988
1118
  errorMessage: (e == null ? void 0 : e.message) || "Unknown error occured while registering for push"
989
1119
  });
990
1120
  }
@@ -998,7 +1128,7 @@ class he {
998
1128
  async registerPush() {
999
1129
  return N() && "serviceWorker" in navigator && "PushManager" in window ? this.handleRegisterPush() : (console.warn("[SuprSend]: Webpush isn't supported"), o({
1000
1130
  status: a.ERROR,
1001
- errorType: d.UNSUPPORTED_ACTION,
1131
+ errorType: c.UNSUPPORTED_ACTION,
1002
1132
  errorMessage: "Webpush isn't supported"
1003
1133
  }));
1004
1134
  }
@@ -1025,12 +1155,12 @@ class he {
1025
1155
  return !!await this.getPushSubscription();
1026
1156
  }
1027
1157
  }
1028
- const z = 20, fe = "default", le = 100, C = {
1158
+ const B = 20, Oe = "default", ye = 100, C = {
1029
1159
  storeId: "$suprsend_default_store",
1030
1160
  label: ""
1031
- }, pe = {
1032
- tenantId: fe,
1033
- pageSize: z,
1161
+ }, me = {
1162
+ tenantId: Oe,
1163
+ pageSize: B,
1034
1164
  stores: null,
1035
1165
  host: {
1036
1166
  apiHost: "https://inboxs.live",
@@ -1041,21 +1171,21 @@ const z = 20, fe = "default", le = 100, C = {
1041
1171
  store: C,
1042
1172
  pageInfo: {
1043
1173
  total: 0,
1044
- pageSize: z,
1174
+ pageSize: B,
1045
1175
  hasMore: !1
1046
1176
  },
1047
1177
  meta: { badge: 0 },
1048
- apiStatus: S.INITIAL,
1178
+ apiStatus: A.INITIAL,
1049
1179
  isFirstFetch: !0
1050
1180
  };
1051
- class Re {
1181
+ class ge {
1052
1182
  constructor(e) {
1053
1183
  l(this, "config");
1054
1184
  l(this, "feedInstances", []);
1055
1185
  this.config = e;
1056
1186
  }
1057
1187
  initialize(e = {}) {
1058
- const t = new Oe(this.config, e);
1188
+ const t = new _e(this.config, e);
1059
1189
  return this.feedInstances.push(t), t;
1060
1190
  }
1061
1191
  removeInstance(e) {
@@ -1069,7 +1199,7 @@ class Re {
1069
1199
  this.feedInstances = [];
1070
1200
  }
1071
1201
  }
1072
- class Oe {
1202
+ class _e {
1073
1203
  constructor(e, t) {
1074
1204
  l(this, "feedOptions");
1075
1205
  l(this, "config");
@@ -1077,11 +1207,11 @@ class Oe {
1077
1207
  l(this, "socket");
1078
1208
  l(this, "expiryTimerId");
1079
1209
  l(this, "fetchAbortController");
1080
- l(this, "emitter", H());
1210
+ l(this, "emitter", W());
1081
1211
  this.config = e, this.setOptions(t), this.store = this.createFeedStore();
1082
1212
  }
1083
1213
  setOptions(e) {
1084
- this.feedOptions = { ...pe }, 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, le)), e != null && e.stores && (this.feedOptions.stores = e.stores), this.validateStore();
1214
+ this.feedOptions = { ...me }, 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, ye)), e != null && e.stores && (this.feedOptions.stores = e.stores), this.validateStore();
1085
1215
  }
1086
1216
  validateStore() {
1087
1217
  const e = this.feedOptions.stores;
@@ -1099,12 +1229,12 @@ class Oe {
1099
1229
  return;
1100
1230
  }
1101
1231
  const r = s == null ? void 0 : s.query;
1102
- let n, c, u = [], f = [];
1103
- typeof (r == null ? void 0 : r.read) == "boolean" && (n = 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" ? f = [r.categories] : Array.isArray(r == null ? void 0 : r.categories) && (f = r == null ? void 0 : r.categories.filter((h) => typeof h == "string")), t.push({
1232
+ let n, d, u = [], f = [];
1233
+ typeof (r == null ? void 0 : r.read) == "boolean" && (n = 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" ? f = [r.categories] : Array.isArray(r == null ? void 0 : r.categories) && (f = r == null ? void 0 : r.categories.filter((h) => typeof h == "string")), t.push({
1104
1234
  storeId: s.storeId,
1105
1235
  label: s.label || s.storeId,
1106
1236
  query: {
1107
- archived: c,
1237
+ archived: d,
1108
1238
  read: n,
1109
1239
  tags: u,
1110
1240
  categories: f
@@ -1113,7 +1243,7 @@ class Oe {
1113
1243
  }), this.feedOptions.stores = t;
1114
1244
  }
1115
1245
  createFeedStore() {
1116
- return G()(() => {
1246
+ return Q()(() => {
1117
1247
  var e;
1118
1248
  return {
1119
1249
  ...k,
@@ -1125,8 +1255,8 @@ class Oe {
1125
1255
  this.socket.on("connect_error", async (e) => {
1126
1256
  var t;
1127
1257
  if (e.message === "Authentication Error: wrong auth token" && ((t = this.config.authenticateOptions) != null && t.refreshUserToken) && this.config.userToken) {
1128
- const s = this.socket.auth["x-ss-signature"], r = L(s), n = (r.exp || 0) * 1e3, c = Date.now();
1129
- if (n <= c)
1258
+ const s = this.socket.auth["x-ss-signature"], r = x(s), n = (r.exp || 0) * 1e3, d = Date.now();
1259
+ if (n <= d)
1130
1260
  try {
1131
1261
  const f = await this.config.authenticateOptions.refreshUserToken(
1132
1262
  this.config.userToken,
@@ -1166,18 +1296,18 @@ class Oe {
1166
1296
  return;
1167
1297
  const s = t.body, r = this.store.getState();
1168
1298
  let n = !1;
1169
- const c = { ...r.meta };
1299
+ const d = { ...r.meta };
1170
1300
  this.notificationBelongToStore(s, r.store) && (n = !0, this.store.setState({
1171
1301
  notifications: this.orderNotificationsBasedOnPinFlag(
1172
1302
  s,
1173
1303
  r.notifications
1174
1304
  )
1175
1305
  })), (f = (u = this.feedOptions.stores) == null ? void 0 : u.map) == null || f.call(u, (h) => {
1176
- this.notificationBelongToStore(s, h) && (n = !0, c[h.storeId] = (r.meta[h.storeId] || 0) + 1);
1306
+ this.notificationBelongToStore(s, h) && (n = !0, d[h.storeId] = (r.meta[h.storeId] || 0) + 1);
1177
1307
  }), this.store.setState({
1178
1308
  meta: {
1179
- ...c,
1180
- badge: n ? c.badge + 1 : c.badge
1309
+ ...d,
1310
+ badge: n ? d.badge + 1 : d.badge
1181
1311
  }
1182
1312
  }), n && this.emitter.emit("feed.new_notification", s), this.emitter.emit("feed.store_update", this.data);
1183
1313
  }
@@ -1191,13 +1321,13 @@ class Oe {
1191
1321
  if (t[0].status !== "fulfilled") return;
1192
1322
  const r = t[0].value;
1193
1323
  if (r.status === a.ERROR) return;
1194
- const n = r.body, c = (f = s.notifications) == null ? void 0 : f.some(
1324
+ const n = r.body, d = (f = s.notifications) == null ? void 0 : f.some(
1195
1325
  (h) => h.n_id === n.n_id
1196
1326
  );
1197
1327
  this.notificationBelongToStore(
1198
1328
  n,
1199
1329
  s.store
1200
- ) ? c ? this.store.setState({
1330
+ ) ? d ? this.store.setState({
1201
1331
  notifications: s.notifications.map((h) => h.n_id === n.n_id ? n : h)
1202
1332
  }) : this.store.setState({
1203
1333
  notifications: this.orderNotificationsBasedOnPinFlag(
@@ -1225,12 +1355,12 @@ class Oe {
1225
1355
  }), this.emitter.emit("feed.store_update", this.data);
1226
1356
  }
1227
1357
  notificationBelongToStore(e, t) {
1228
- var y, m, _, E;
1229
- const s = !!e.read_on, r = e.archived, n = e.tags, c = e.n_category, u = (y = t == null ? void 0 : t.query) == null ? void 0 : y.read, f = (m = t == null ? void 0 : t.query) == null ? void 0 : m.archived, h = (_ = t == null ? void 0 : t.query) == null ? void 0 : _.tags, O = (E = t == null ? void 0 : t.query) == null ? void 0 : E.categories, v = u == null || s === u, T = !!r == !!f;
1230
- let g = !1, R = !1;
1358
+ var I, _, T, E;
1359
+ const s = !!e.read_on, r = e.archived, n = e.tags, d = e.n_category, u = (I = t == null ? void 0 : t.query) == null ? void 0 : I.read, f = (_ = t == null ? void 0 : t.query) == null ? void 0 : _.archived, h = (T = t == null ? void 0 : t.query) == null ? void 0 : T.tags, p = (E = t == null ? void 0 : t.query) == null ? void 0 : E.categories, m = u == null || s === u, O = !!r == !!f;
1360
+ let R = !1, g = !1;
1231
1361
  return Array.isArray(h) && h.length > 0 ? h.forEach((b) => {
1232
- n != null && n.includes(b) && (g = !0);
1233
- }) : g = !0, Array.isArray(O) && O.length > 0 ? O.includes(c) && (R = !0) : R = !0, v && g && R && T;
1362
+ n != null && n.includes(b) && (R = !0);
1363
+ }) : R = !0, Array.isArray(p) && p.length > 0 ? p.includes(d) && (g = !0) : g = !0, m && R && g && O;
1234
1364
  }
1235
1365
  orderNotificationsBasedOnPinFlag(e, t) {
1236
1366
  if (e.is_pinned)
@@ -1255,8 +1385,8 @@ class Oe {
1255
1385
  t && (this.store.setState({ notifications: s }), await this.fetchCount(), this.emitter.emit("feed.store_update", this.data));
1256
1386
  }
1257
1387
  getUrl(e, t) {
1258
- var c;
1259
- const s = `${(c = this.feedOptions.host) == null ? void 0 : c.apiHost}/v1/feed/${e}`, r = this.validateQueryParams(t), n = new URLSearchParams(
1388
+ var d;
1389
+ const s = `${(d = this.feedOptions.host) == null ? void 0 : d.apiHost}/v1/feed/${e}`, r = this.validateQueryParams(t), n = new URLSearchParams(
1260
1390
  r
1261
1391
  ).toString();
1262
1392
  return n ? `${s}?${n}` : s;
@@ -1272,20 +1402,20 @@ class Oe {
1272
1402
  requestInprogress() {
1273
1403
  const e = this.store.getState();
1274
1404
  return [
1275
- S.LOADING,
1276
- S.FETCHING_MORE
1405
+ A.LOADING,
1406
+ A.FETCHING_MORE
1277
1407
  ].includes(e.apiStatus);
1278
1408
  }
1279
1409
  storesQueryParamObj(e) {
1280
1410
  return e == null ? void 0 : e.map((s) => this.storeQueryParamObj(s));
1281
1411
  }
1282
1412
  storeQueryParamObj(e) {
1283
- const t = e == null ? void 0 : e.query, s = (t == null ? void 0 : t.tags) || [], r = (t == null ? void 0 : t.categories) || [], n = t == null ? void 0 : t.read, c = t == null ? void 0 : t.archived;
1413
+ const t = e == null ? void 0 : e.query, s = (t == null ? void 0 : t.tags) || [], r = (t == null ? void 0 : t.categories) || [], n = t == null ? void 0 : t.read, d = t == null ? void 0 : t.archived;
1284
1414
  return {
1285
1415
  store_id: e.storeId,
1286
1416
  query: {
1287
1417
  read: n,
1288
- archived: c,
1418
+ archived: d,
1289
1419
  tags: { or: s },
1290
1420
  categories: { or: r }
1291
1421
  }
@@ -1305,7 +1435,7 @@ class Oe {
1305
1435
  }), await this.fetch()) : {
1306
1436
  status: a.ERROR,
1307
1437
  error: {
1308
- type: d.NOT_FOUND,
1438
+ type: c.NOT_FOUND,
1309
1439
  message: `store with storeId ${e} doesnt exist`
1310
1440
  }
1311
1441
  };
@@ -1322,7 +1452,7 @@ class Oe {
1322
1452
  }
1323
1453
  initializeSocketConnection() {
1324
1454
  var e;
1325
- this.socket || (this.socket = J((e = this.feedOptions.host) == null ? void 0 : e.socketHost, {
1455
+ this.socket || (this.socket = Y((e = this.feedOptions.host) == null ? void 0 : e.socketHost, {
1326
1456
  transports: ["websocket"],
1327
1457
  auth: {
1328
1458
  authorization: this.config.publicApiKey,
@@ -1341,9 +1471,9 @@ class Oe {
1341
1471
  if (this.requestInprogress()) return;
1342
1472
  const s = (e == null ? void 0 : e.pageSize) || this.feedOptions.pageSize;
1343
1473
  t.isFirstFetch ? (this.store.setState({
1344
- apiStatus: S.LOADING
1474
+ apiStatus: A.LOADING
1345
1475
  }), this.fetchCount()) : this.store.setState({
1346
- apiStatus: S.FETCHING_MORE
1476
+ apiStatus: A.FETCHING_MORE
1347
1477
  }), this.emitter.emit("feed.store_update", this.data);
1348
1478
  const r = {
1349
1479
  distinct_id: this.config.distinctId,
@@ -1359,12 +1489,12 @@ class Oe {
1359
1489
  ];
1360
1490
  } else
1361
1491
  r.search_after = [];
1362
- const n = this.getUrl("notifications", r), c = new AbortController();
1363
- this.fetchAbortController = c;
1364
- const u = await this.config.client().request({ type: "get", url: n, signal: c.signal });
1365
- if (!c.signal.aborted)
1366
- return u.status === a.ERROR ? (this.store.setState({ apiStatus: S.ERROR }), this.emitter.emit("feed.store_update", this.data), u) : (this.store.setState({
1367
- apiStatus: S.SUCCESS,
1492
+ const n = this.getUrl("notifications", r), d = new AbortController();
1493
+ this.fetchAbortController = d;
1494
+ const u = await this.config.client().request({ type: "get", url: n, signal: d.signal });
1495
+ if (!d.signal.aborted)
1496
+ return u.status === a.ERROR ? (this.store.setState({ apiStatus: A.ERROR }), this.emitter.emit("feed.store_update", this.data), u) : (this.store.setState({
1497
+ apiStatus: A.SUCCESS,
1368
1498
  notifications: t.isFirstFetch ? u.body.results : [...t.notifications, ...u.body.results],
1369
1499
  pageInfo: {
1370
1500
  ...t.pageInfo,
@@ -1379,7 +1509,7 @@ class Oe {
1379
1509
  return this.store.getState().pageInfo.hasMore === !1 ? {
1380
1510
  status: a.ERROR,
1381
1511
  error: {
1382
- type: d.VALIDATION_ERROR,
1512
+ type: c.VALIDATION_ERROR,
1383
1513
  message: "No more pages to fetch"
1384
1514
  }
1385
1515
  } : this.fetch();
@@ -1507,8 +1637,8 @@ class Oe {
1507
1637
  this.reset(), this.emitter.off("*"), (e = this.socket) == null || e.disconnect(), this.config.feeds.removeInstance(this);
1508
1638
  }
1509
1639
  }
1510
- const me = "https://hub.suprsend.com", ge = "serviceworker.js", W = "ss_distinct_id";
1511
- class be {
1640
+ const Ie = "https://hub.suprsend.com", Te = "serviceworker.js", H = "ss_distinct_id";
1641
+ class we {
1512
1642
  constructor(e, t) {
1513
1643
  l(this, "host");
1514
1644
  l(this, "publicApiKey");
@@ -1521,22 +1651,22 @@ class be {
1521
1651
  l(this, "apiClient", null);
1522
1652
  l(this, "userTokenExpirationTimer", null);
1523
1653
  l(this, "authenticateOptions");
1524
- l(this, "user", new ue(this));
1525
- l(this, "webpush", new he(this));
1526
- l(this, "feeds", new Re(this));
1527
- l(this, "emitter", H());
1654
+ l(this, "user", new pe(this));
1655
+ l(this, "webpush", new Re(this));
1656
+ l(this, "feeds", new ge(this));
1657
+ l(this, "emitter", W());
1528
1658
  if (!e)
1529
1659
  throw new Error("[SuprSend]: publicApiKey is missing");
1530
- this.publicApiKey = e, this.host = (t == null ? void 0 : t.host) || me, this.vapidKey = (t == null ? void 0 : t.vapidKey) || "", this.swFileName = (t == null ? void 0 : t.swFileName) || ge, this.clientUserAgent = ne(
1660
+ this.publicApiKey = e, this.host = (t == null ? void 0 : t.host) || Ie, this.vapidKey = (t == null ? void 0 : t.vapidKey) || "", this.swFileName = (t == null ? void 0 : t.swFileName) || Te, this.clientUserAgent = de(
1531
1661
  t == null ? void 0 : t.appInfo,
1532
1662
  t == null ? void 0 : t.clientUserAgent
1533
- ), this.userAgent = oe(this.clientUserAgent);
1663
+ ), this.userAgent = he(this.clientUserAgent);
1534
1664
  }
1535
1665
  handleRefreshUserToken(e) {
1536
1666
  if (!this.userToken || !N()) return;
1537
- const t = L(this.userToken), s = (t.exp || 0) * 1e3, r = Date.now(), n = 1e3 * 30;
1667
+ const t = x(this.userToken), s = (t.exp || 0) * 1e3, r = Date.now(), n = 1e3 * 30;
1538
1668
  if (s && s > r) {
1539
- const c = s - r - n;
1669
+ const d = s - r - n;
1540
1670
  this.userTokenExpirationTimer && clearTimeout(this.userTokenExpirationTimer), this.userTokenExpirationTimer = setTimeout(async () => {
1541
1671
  let u = "";
1542
1672
  try {
@@ -1555,7 +1685,7 @@ class be {
1555
1685
  }
1556
1686
  }
1557
1687
  u && typeof u == "string" && this.identify(this.distinctId, u, this.authenticateOptions);
1558
- }, c);
1688
+ }, d);
1559
1689
  }
1560
1690
  }
1561
1691
  client() {
@@ -1578,13 +1708,13 @@ class be {
1578
1708
  if (!e)
1579
1709
  return o({
1580
1710
  status: a.ERROR,
1581
- errorType: d.VALIDATION_ERROR,
1711
+ errorType: c.VALIDATION_ERROR,
1582
1712
  errorMessage: "distinctId is missing"
1583
1713
  });
1584
1714
  if (this.apiClient && this.distinctId && this.distinctId !== e)
1585
1715
  return o({
1586
1716
  status: a.ERROR,
1587
- errorType: d.VALIDATION_ERROR,
1717
+ errorType: c.VALIDATION_ERROR,
1588
1718
  errorMessage: "User already loggedin, reset current user to login new user"
1589
1719
  });
1590
1720
  if (this.apiClient && this.distinctId === e && this.userToken !== t)
@@ -1593,7 +1723,7 @@ class be {
1593
1723
  return o({ status: a.SUCCESS });
1594
1724
  this.distinctId = e, this.userToken = t, this.apiClient = new P(this), this.authenticateOptions = s;
1595
1725
  const r = j(
1596
- W
1726
+ H
1597
1727
  );
1598
1728
  if (s != null && s.refreshUserToken && this.handleRefreshUserToken(s.refreshUserToken), r == this.distinctId)
1599
1729
  return this.webpush.updatePushSubscription().catch(() => {
@@ -1607,7 +1737,7 @@ class be {
1607
1737
  $identified_id: e
1608
1738
  }
1609
1739
  }) : n = { status: a.SUCCESS }, n.status === a.SUCCESS ? (this.webpush.updatePushSubscription().catch(() => {
1610
- }), $(W, this.distinctId)) : this.reset({ unsubscribePush: !1 }), n;
1740
+ }), $(H, this.distinctId)) : this.reset({ unsubscribePush: !1 }), n;
1611
1741
  }
1612
1742
  /**
1613
1743
  * Check's if SuprSend instance is authenticated. To check if userToken is also present pass true.
@@ -1628,7 +1758,7 @@ class be {
1628
1758
  properties: s
1629
1759
  })) : o({
1630
1760
  status: a.ERROR,
1631
- errorType: d.VALIDATION_ERROR,
1761
+ errorType: c.VALIDATION_ERROR,
1632
1762
  errorMessage: "event name is missing"
1633
1763
  });
1634
1764
  }
@@ -1637,16 +1767,20 @@ class be {
1637
1767
  */
1638
1768
  async reset(e) {
1639
1769
  var s, r;
1640
- return (e == null ? void 0 : e.unsubscribePush) !== !1 && (await ((s = this.webpush) == null ? void 0 : s.removePushSubscription()), te(x)), this.apiClient = null, this.distinctId = null, this.userToken = "", this.userTokenExpirationTimer && clearTimeout(this.userTokenExpirationTimer), ((r = this.feeds.feedInstances) == null ? void 0 : r.length) > 0 && this.feeds.removeAll(), o({ status: a.SUCCESS });
1770
+ return (e == null ? void 0 : e.unsubscribePush) !== !1 && (await ((s = this.webpush) == null ? void 0 : s.removePushSubscription()), ne(L)), this.apiClient = null, this.distinctId = null, this.userToken = "", this.userTokenExpirationTimer && clearTimeout(this.userTokenExpirationTimer), ((r = this.feeds.feedInstances) == null ? void 0 : r.length) > 0 && this.feeds.removeAll(), o({ status: a.SUCCESS });
1641
1771
  }
1642
1772
  }
1643
1773
  export {
1644
- S as ApiResponseStatus,
1774
+ A as ApiResponseStatus,
1645
1775
  w as ChannelLevelPreferenceOptions,
1646
- d as ERROR_TYPE,
1647
- Oe as Feed,
1648
- p as PreferenceOptions,
1776
+ c as ERROR_TYPE,
1777
+ Z as EditPolicy,
1778
+ _e as Feed,
1779
+ J as FrequencyEnum,
1780
+ y as PreferenceOptions,
1781
+ X as PropertyValueTypeEnum,
1649
1782
  a as RESPONSE_STATUS,
1650
- be as SuprSend
1783
+ we as SuprSend,
1784
+ q as WeekDaysEnum
1651
1785
  };
1652
1786
  //# sourceMappingURL=index.js.map