@suprsend/web-sdk 4.1.2 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/es/index.js +479 -416
- package/dist/es/index.js.map +1 -1
- package/dist/types/interface.d.ts +20 -0
- package/dist/types/main.d.ts +7 -5
- package/dist/types/utils.d.ts +13 -1
- package/package.json +1 -1
package/dist/es/index.js
CHANGED
|
@@ -1,65 +1,69 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { createStore as
|
|
7
|
-
import { io as
|
|
8
|
-
var p = /* @__PURE__ */ ((
|
|
9
|
-
|
|
10
|
-
|
|
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.2.0";
|
|
10
|
+
function D() {
|
|
11
|
+
let i = (/* @__PURE__ */ new Date()).getTime();
|
|
11
12
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
|
|
12
13
|
/[xy]/g,
|
|
13
14
|
function(t) {
|
|
14
|
-
const s = (
|
|
15
|
-
return
|
|
15
|
+
const s = (i + Math.random() * 16) % 16 | 0;
|
|
16
|
+
return i = Math.floor(i / 16), (t == "x" ? s : s & 3 | 8).toString(16);
|
|
16
17
|
}
|
|
17
18
|
);
|
|
18
19
|
}
|
|
19
|
-
function
|
|
20
|
+
function M() {
|
|
20
21
|
return Math.round(Date.now());
|
|
21
22
|
}
|
|
22
|
-
function I(
|
|
23
|
-
return Object.keys(
|
|
23
|
+
function I(i) {
|
|
24
|
+
return Object.keys(i).length === 0;
|
|
24
25
|
}
|
|
25
|
-
function
|
|
26
|
-
return (
|
|
26
|
+
function Y(i) {
|
|
27
|
+
return (i == null ? void 0 : i.length) <= 0;
|
|
27
28
|
}
|
|
28
|
-
function
|
|
29
|
-
const e = "=".repeat((4 -
|
|
30
|
-
for (let
|
|
31
|
-
r[
|
|
29
|
+
function q(i) {
|
|
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
|
+
for (let n = 0; n < s.length; ++n)
|
|
32
|
+
r[n] = s.charCodeAt(n);
|
|
32
33
|
return r;
|
|
33
34
|
}
|
|
34
|
-
function
|
|
35
|
+
function ee(i, e) {
|
|
35
36
|
let t;
|
|
36
37
|
return (...s) => (clearTimeout(t), new Promise((r) => {
|
|
37
|
-
t = setTimeout(() => r(
|
|
38
|
+
t = setTimeout(() => r(i(...s)), e);
|
|
38
39
|
}));
|
|
39
40
|
}
|
|
40
|
-
function
|
|
41
|
+
function F(i, e) {
|
|
41
42
|
const t = {};
|
|
42
43
|
return (...s) => {
|
|
43
|
-
const [r] = s,
|
|
44
|
-
return typeof t[r] == "function" ? t[r](...
|
|
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
46
|
};
|
|
46
47
|
}
|
|
47
|
-
function o(
|
|
48
|
-
const e = { status:
|
|
49
|
-
return
|
|
50
|
-
type:
|
|
51
|
-
message:
|
|
48
|
+
function o(i) {
|
|
49
|
+
const e = { status: i.status };
|
|
50
|
+
return i.statusCode && (e.statusCode = i.statusCode), i.body && (e.body = i.body), i.status === a.ERROR && (e.error = {
|
|
51
|
+
type: i.errorType,
|
|
52
|
+
message: i.errorMessage
|
|
52
53
|
}), e;
|
|
53
54
|
}
|
|
54
|
-
function
|
|
55
|
+
function N() {
|
|
55
56
|
return typeof window < "u";
|
|
56
57
|
}
|
|
57
|
-
function
|
|
58
|
-
|
|
58
|
+
function V() {
|
|
59
|
+
return !(!N() || !(window != null && window.localStorage));
|
|
60
|
+
}
|
|
61
|
+
function $(i, e) {
|
|
62
|
+
V() && (typeof e == "object" && (e = JSON.stringify(e)), localStorage.setItem(i, e));
|
|
59
63
|
}
|
|
60
|
-
function
|
|
61
|
-
if (!
|
|
62
|
-
const e = localStorage.getItem(
|
|
64
|
+
function j(i) {
|
|
65
|
+
if (!V()) return;
|
|
66
|
+
const e = localStorage.getItem(i);
|
|
63
67
|
if (e)
|
|
64
68
|
try {
|
|
65
69
|
return JSON.parse(e);
|
|
@@ -67,22 +71,76 @@ function V(a) {
|
|
|
67
71
|
return e;
|
|
68
72
|
}
|
|
69
73
|
}
|
|
70
|
-
function
|
|
71
|
-
|
|
74
|
+
function te(i) {
|
|
75
|
+
V() && localStorage.removeItem(i);
|
|
76
|
+
}
|
|
77
|
+
function U() {
|
|
78
|
+
return typeof navigator < "u" && navigator.userAgent || "";
|
|
79
|
+
}
|
|
80
|
+
function se(i = U()) {
|
|
81
|
+
let e;
|
|
82
|
+
return (e = i.match(/Windows NT (\d+(?:\.\d+)*)/i)) ? { os: "windows", os_version: e[1] } : (e = i.match(
|
|
83
|
+
/(?:iPhone|iPad|iPod)[^;]*;\s*CPU[^)]*OS (\d+[_.]\d+(?:[_.]\d+)?)/i
|
|
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
|
+
}
|
|
86
|
+
function re(i = U()) {
|
|
87
|
+
let e;
|
|
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: "" };
|
|
72
89
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return Array.from(new Uint8Array(s)).map((d) => d.toString(16).padStart(2, "0")).join("");
|
|
90
|
+
function ie(i = U()) {
|
|
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" : "";
|
|
76
92
|
}
|
|
77
|
-
|
|
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(),
|
|
97
|
+
lang: "javascript",
|
|
98
|
+
platform: "browser",
|
|
99
|
+
environment: ie(t),
|
|
100
|
+
os: s,
|
|
101
|
+
os_version: r,
|
|
102
|
+
browser: n,
|
|
103
|
+
browser_version: c
|
|
104
|
+
};
|
|
105
|
+
if (i != null && i.name && (u.app_info = {
|
|
106
|
+
name: i.name,
|
|
107
|
+
version: i.version || ""
|
|
108
|
+
}), !e) return u;
|
|
109
|
+
const f = { ...u };
|
|
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);
|
|
113
|
+
}
|
|
114
|
+
return f;
|
|
115
|
+
}
|
|
116
|
+
function ae(i) {
|
|
117
|
+
return i != null && i.name ? i.version ? `${i.name}/${i.version}` : i.name : "";
|
|
118
|
+
}
|
|
119
|
+
function oe(i) {
|
|
120
|
+
const e = i.sdk || "", t = i.sdk_version || "";
|
|
121
|
+
let s = t ? `${e}/${t}` : e;
|
|
122
|
+
const r = i.browser ? `${i.browser}${i.browser_version ? `/${i.browser_version}` : ""}` : i.lang || "", n = [];
|
|
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;
|
|
126
|
+
}
|
|
127
|
+
async function ce(i) {
|
|
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("");
|
|
130
|
+
}
|
|
131
|
+
class P {
|
|
78
132
|
constructor(e) {
|
|
79
|
-
|
|
133
|
+
l(this, "config");
|
|
80
134
|
this.config = e;
|
|
81
135
|
}
|
|
82
136
|
getHeaders() {
|
|
83
137
|
const e = {
|
|
84
138
|
"Content-Type": "application/json",
|
|
85
|
-
Authorization: this.config.publicApiKey
|
|
139
|
+
Authorization: this.config.publicApiKey,
|
|
140
|
+
"X-Suprsend-Client-User-Agent": JSON.stringify(
|
|
141
|
+
this.config.clientUserAgent
|
|
142
|
+
),
|
|
143
|
+
"X-Suprsend-User-Agent": this.config.userAgent
|
|
86
144
|
};
|
|
87
145
|
return this.config.userToken && (e["x-ss-signature"] = this.config.userToken), e;
|
|
88
146
|
}
|
|
@@ -125,17 +183,17 @@ class U {
|
|
|
125
183
|
var t, s, r;
|
|
126
184
|
if (!this.config.distinctId)
|
|
127
185
|
return o({
|
|
128
|
-
status:
|
|
129
|
-
errorType:
|
|
186
|
+
status: a.ERROR,
|
|
187
|
+
errorType: d.VALIDATION_ERROR,
|
|
130
188
|
errorMessage: "User isn't authenticated. Call identify method before performing any action"
|
|
131
189
|
});
|
|
132
190
|
if ((t = this.config.authenticateOptions) != null && t.refreshUserToken && this.config.userToken) {
|
|
133
|
-
const
|
|
134
|
-
if (
|
|
191
|
+
const n = L(this.config.userToken), c = (n.exp || 0) * 1e3, u = Date.now();
|
|
192
|
+
if (c <= u)
|
|
135
193
|
try {
|
|
136
194
|
const h = await this.config.authenticateOptions.refreshUserToken(
|
|
137
195
|
this.config.userToken,
|
|
138
|
-
|
|
196
|
+
n
|
|
139
197
|
);
|
|
140
198
|
h && typeof h == "string" && this.config.identify(
|
|
141
199
|
this.config.distinctId,
|
|
@@ -146,36 +204,36 @@ class U {
|
|
|
146
204
|
}
|
|
147
205
|
}
|
|
148
206
|
try {
|
|
149
|
-
const
|
|
207
|
+
const n = await this.requestApiInstance(e), c = await n.json(), u = (c == null ? void 0 : c.status) || (n.ok ? a.SUCCESS : a.ERROR);
|
|
150
208
|
return o({
|
|
151
209
|
status: u,
|
|
152
|
-
body:
|
|
153
|
-
statusCode:
|
|
154
|
-
errorMessage: (s =
|
|
155
|
-
errorType: (r =
|
|
210
|
+
body: c,
|
|
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
|
|
156
214
|
});
|
|
157
|
-
} catch (
|
|
158
|
-
return console.error(
|
|
159
|
-
status:
|
|
215
|
+
} catch (n) {
|
|
216
|
+
return console.error(n), o({
|
|
217
|
+
status: a.ERROR,
|
|
160
218
|
statusCode: 500,
|
|
161
|
-
errorMessage: (
|
|
162
|
-
errorType:
|
|
219
|
+
errorMessage: (n == null ? void 0 : n.message) || "network error",
|
|
220
|
+
errorType: d.NETWORK_ERROR
|
|
163
221
|
});
|
|
164
222
|
}
|
|
165
223
|
}
|
|
166
224
|
}
|
|
167
|
-
class
|
|
225
|
+
class de {
|
|
168
226
|
constructor(e) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
this.config = e, this.debouncedUpdateCategoryPreferences =
|
|
227
|
+
l(this, "config");
|
|
228
|
+
l(this, "preferenceData");
|
|
229
|
+
l(this, "preferenceArgs");
|
|
230
|
+
l(this, "debouncedUpdateCategoryPreferences");
|
|
231
|
+
l(this, "debouncedUpdateChannelPreferences");
|
|
232
|
+
l(this, "debounceTime", 1e3);
|
|
233
|
+
this.config = e, this.debouncedUpdateCategoryPreferences = F(
|
|
176
234
|
this._updateCategoryPreferences.bind(this),
|
|
177
235
|
this.debounceTime
|
|
178
|
-
), this.debouncedUpdateChannelPreferences =
|
|
236
|
+
), this.debouncedUpdateChannelPreferences = F(
|
|
179
237
|
this._updateChannelPreferences.bind(this),
|
|
180
238
|
this.debounceTime
|
|
181
239
|
);
|
|
@@ -193,10 +251,10 @@ class q {
|
|
|
193
251
|
return this.preferenceData;
|
|
194
252
|
}
|
|
195
253
|
getUrl(e, t) {
|
|
196
|
-
const s = `${this.config.host}/v2/subscriber/${this.config.distinctId}/${e}`, r = this.validateQueryParams(t),
|
|
254
|
+
const s = `${this.config.host}/v2/subscriber/${this.config.distinctId}/${e}`, r = this.validateQueryParams(t), n = new URLSearchParams(
|
|
197
255
|
r
|
|
198
256
|
).toString();
|
|
199
|
-
return
|
|
257
|
+
return n ? `${s}/?${n}` : s;
|
|
200
258
|
}
|
|
201
259
|
/**
|
|
202
260
|
* Used to get user's whole preferences data.
|
|
@@ -237,8 +295,8 @@ class q {
|
|
|
237
295
|
async getCategory(e, t) {
|
|
238
296
|
if (!e)
|
|
239
297
|
return o({
|
|
240
|
-
status:
|
|
241
|
-
errorType:
|
|
298
|
+
status: a.ERROR,
|
|
299
|
+
errorType: d.VALIDATION_ERROR,
|
|
242
300
|
errorMessage: "Category parameter is missing"
|
|
243
301
|
});
|
|
244
302
|
const s = {
|
|
@@ -256,16 +314,16 @@ class q {
|
|
|
256
314
|
return await this.config.client().request({ type: "get", url: s });
|
|
257
315
|
}
|
|
258
316
|
async _updateCategoryPreferences(e, t, s, r) {
|
|
259
|
-
const
|
|
317
|
+
const n = this.getUrl(`category/${e}`, r), c = await this.config.client().request({
|
|
260
318
|
type: "patch",
|
|
261
|
-
url:
|
|
319
|
+
url: n,
|
|
262
320
|
payload: t
|
|
263
321
|
});
|
|
264
|
-
return
|
|
265
|
-
status:
|
|
322
|
+
return c != null && c.error ? this.config.emitter.emit("preferences_error", c) : (Object.assign(s, c.body), this.config.emitter.emit("preferences_updated", {
|
|
323
|
+
status: a.SUCCESS,
|
|
266
324
|
statusCode: 200,
|
|
267
325
|
body: this.data
|
|
268
|
-
})),
|
|
326
|
+
})), c;
|
|
269
327
|
}
|
|
270
328
|
async _updateChannelPreferences(e, t) {
|
|
271
329
|
const s = this.getUrl("channel_preference", t), r = await this.config.client().request({
|
|
@@ -274,7 +332,7 @@ class q {
|
|
|
274
332
|
payload: e
|
|
275
333
|
});
|
|
276
334
|
return r != null && r.error ? this.config.emitter.emit("preferences_error", r) : (await this.getPreferences(this.preferenceArgs), this.config.emitter.emit("preferences_updated", {
|
|
277
|
-
status:
|
|
335
|
+
status: a.SUCCESS,
|
|
278
336
|
statusCode: 200,
|
|
279
337
|
body: this.data
|
|
280
338
|
})), r;
|
|
@@ -283,81 +341,81 @@ class q {
|
|
|
283
341
|
* Used to update user's category level preference.
|
|
284
342
|
*/
|
|
285
343
|
async updateCategoryPreference(e, t, s) {
|
|
286
|
-
var h,
|
|
344
|
+
var h, O, v, T, g;
|
|
287
345
|
if (!e || ![p.OPT_IN, p.OPT_OUT].includes(
|
|
288
346
|
t
|
|
289
347
|
))
|
|
290
348
|
return o({
|
|
291
|
-
status:
|
|
292
|
-
errorType:
|
|
349
|
+
status: a.ERROR,
|
|
350
|
+
errorType: d.VALIDATION_ERROR,
|
|
293
351
|
errorMessage: e ? "Preference parameter is invalid" : "Category parameter is missing"
|
|
294
352
|
});
|
|
295
353
|
if (!this.data)
|
|
296
354
|
return o({
|
|
297
|
-
status:
|
|
298
|
-
errorType:
|
|
355
|
+
status: a.ERROR,
|
|
356
|
+
errorType: d.VALIDATION_ERROR,
|
|
299
357
|
errorMessage: "Call getPreferences method before performing action"
|
|
300
358
|
});
|
|
301
359
|
if (!this.data.sections)
|
|
302
360
|
return o({
|
|
303
|
-
status:
|
|
304
|
-
errorType:
|
|
361
|
+
status: a.ERROR,
|
|
362
|
+
errorType: d.VALIDATION_ERROR,
|
|
305
363
|
errorMessage: "Sections doesn't exist"
|
|
306
364
|
});
|
|
307
|
-
let r = null,
|
|
365
|
+
let r = null, n = !1;
|
|
308
366
|
for (const R of this.data.sections) {
|
|
309
|
-
let
|
|
367
|
+
let y = !1;
|
|
310
368
|
if (R.subcategories) {
|
|
311
|
-
for (const
|
|
312
|
-
if (
|
|
313
|
-
if (r =
|
|
314
|
-
if (
|
|
315
|
-
|
|
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;
|
|
316
374
|
break;
|
|
317
375
|
}
|
|
318
376
|
} else
|
|
319
377
|
return o({
|
|
320
|
-
status:
|
|
321
|
-
errorType:
|
|
378
|
+
status: a.ERROR,
|
|
379
|
+
errorType: d.VALIDATION_ERROR,
|
|
322
380
|
errorMessage: "Category preference is not editable"
|
|
323
381
|
});
|
|
324
|
-
if (
|
|
382
|
+
if (y) break;
|
|
325
383
|
}
|
|
326
384
|
}
|
|
327
385
|
if (!r)
|
|
328
386
|
return o({
|
|
329
|
-
status:
|
|
330
|
-
errorType:
|
|
387
|
+
status: a.ERROR,
|
|
388
|
+
errorType: d.VALIDATION_ERROR,
|
|
331
389
|
errorMessage: "Category not found"
|
|
332
390
|
});
|
|
333
|
-
if (!
|
|
391
|
+
if (!n)
|
|
334
392
|
return o({
|
|
335
|
-
status:
|
|
393
|
+
status: a.SUCCESS,
|
|
336
394
|
body: this.data
|
|
337
395
|
});
|
|
338
|
-
const
|
|
396
|
+
const c = [];
|
|
339
397
|
(h = r == null ? void 0 : r.channels) == null || h.forEach((R) => {
|
|
340
|
-
R.preference === p.OPT_OUT &&
|
|
398
|
+
R.preference === p.OPT_OUT && c.push(R.channel);
|
|
341
399
|
});
|
|
342
400
|
let u = !0;
|
|
343
|
-
typeof (s == null ? void 0 : s.showOptOutChannels) == "boolean" ? u = s == null ? void 0 : s.showOptOutChannels : typeof ((
|
|
344
|
-
const
|
|
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);
|
|
402
|
+
const f = {
|
|
345
403
|
preference: r.preference,
|
|
346
|
-
opt_out_channels: u && t === p.OPT_IN ? null :
|
|
404
|
+
opt_out_channels: u && t === p.OPT_IN ? null : c
|
|
347
405
|
};
|
|
348
406
|
return this.debouncedUpdateCategoryPreferences(
|
|
349
407
|
e,
|
|
350
408
|
e,
|
|
351
|
-
|
|
409
|
+
f,
|
|
352
410
|
r,
|
|
353
411
|
{
|
|
354
|
-
tenant_id: (s == null ? void 0 : s.tenantId) || ((
|
|
412
|
+
tenant_id: (s == null ? void 0 : s.tenantId) || ((v = this.preferenceArgs) == null ? void 0 : v.tenantId),
|
|
355
413
|
show_opt_out_channels: u,
|
|
356
414
|
tags: (s == null ? void 0 : s.tags) || ((T = this.preferenceArgs) == null ? void 0 : T.tags),
|
|
357
|
-
locale: (s == null ? void 0 : s.locale) || ((
|
|
415
|
+
locale: (s == null ? void 0 : s.locale) || ((g = this.preferenceArgs) == null ? void 0 : g.locale)
|
|
358
416
|
}
|
|
359
417
|
), o({
|
|
360
|
-
status:
|
|
418
|
+
status: a.SUCCESS,
|
|
361
419
|
body: this.data
|
|
362
420
|
});
|
|
363
421
|
}
|
|
@@ -365,99 +423,99 @@ class q {
|
|
|
365
423
|
* Used to update user's category level channel preference.
|
|
366
424
|
*/
|
|
367
425
|
async updateChannelPreferenceInCategory(e, t, s, r) {
|
|
368
|
-
var T,
|
|
426
|
+
var T, g, R, y, m;
|
|
369
427
|
if (!e || !s)
|
|
370
428
|
return o({
|
|
371
|
-
status:
|
|
372
|
-
errorType:
|
|
429
|
+
status: a.ERROR,
|
|
430
|
+
errorType: d.VALIDATION_ERROR,
|
|
373
431
|
errorMessage: e ? "Category parameter is missing" : "Channel parameter is missing"
|
|
374
432
|
});
|
|
375
433
|
if (![p.OPT_IN, p.OPT_OUT].includes(
|
|
376
434
|
t
|
|
377
435
|
))
|
|
378
436
|
return o({
|
|
379
|
-
status:
|
|
380
|
-
errorType:
|
|
437
|
+
status: a.ERROR,
|
|
438
|
+
errorType: d.VALIDATION_ERROR,
|
|
381
439
|
errorMessage: "Preference parameter is invalid"
|
|
382
440
|
});
|
|
383
441
|
if (!this.data)
|
|
384
442
|
return o({
|
|
385
|
-
status:
|
|
386
|
-
errorType:
|
|
443
|
+
status: a.ERROR,
|
|
444
|
+
errorType: d.VALIDATION_ERROR,
|
|
387
445
|
errorMessage: "Call getPreferences method before performing action"
|
|
388
446
|
});
|
|
389
447
|
if (!this.data.sections)
|
|
390
448
|
return o({
|
|
391
|
-
status:
|
|
392
|
-
errorType:
|
|
449
|
+
status: a.ERROR,
|
|
450
|
+
errorType: d.VALIDATION_ERROR,
|
|
393
451
|
errorMessage: "Sections doesn't exist"
|
|
394
452
|
});
|
|
395
|
-
let
|
|
396
|
-
for (const
|
|
397
|
-
let
|
|
398
|
-
if (
|
|
399
|
-
for (const
|
|
400
|
-
if (
|
|
401
|
-
if (
|
|
402
|
-
for (const
|
|
403
|
-
if (
|
|
404
|
-
if (
|
|
405
|
-
if (
|
|
406
|
-
|
|
453
|
+
let n = null, c = null, u = !1;
|
|
454
|
+
for (const _ of this.data.sections) {
|
|
455
|
+
let E = !1;
|
|
456
|
+
if (_.subcategories) {
|
|
457
|
+
for (const b of _.subcategories) {
|
|
458
|
+
if (b.category === s) {
|
|
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;
|
|
407
465
|
break;
|
|
408
466
|
}
|
|
409
467
|
} else
|
|
410
468
|
return o({
|
|
411
|
-
status:
|
|
412
|
-
errorType:
|
|
469
|
+
status: a.ERROR,
|
|
470
|
+
errorType: d.VALIDATION_ERROR,
|
|
413
471
|
errorMessage: "Channel preference is not editable"
|
|
414
472
|
});
|
|
415
473
|
}
|
|
416
|
-
if (
|
|
474
|
+
if (E) break;
|
|
417
475
|
}
|
|
418
|
-
if (
|
|
476
|
+
if (E) break;
|
|
419
477
|
}
|
|
420
478
|
}
|
|
421
|
-
if (!
|
|
479
|
+
if (!n)
|
|
422
480
|
return o({
|
|
423
|
-
status:
|
|
424
|
-
errorType:
|
|
481
|
+
status: a.ERROR,
|
|
482
|
+
errorType: d.VALIDATION_ERROR,
|
|
425
483
|
errorMessage: "Category not found"
|
|
426
484
|
});
|
|
427
|
-
if (!
|
|
485
|
+
if (!c)
|
|
428
486
|
return o({
|
|
429
|
-
status:
|
|
430
|
-
errorType:
|
|
487
|
+
status: a.ERROR,
|
|
488
|
+
errorType: d.VALIDATION_ERROR,
|
|
431
489
|
errorMessage: "Category's channel not found"
|
|
432
490
|
});
|
|
433
491
|
if (!u)
|
|
434
492
|
return o({
|
|
435
|
-
status:
|
|
493
|
+
status: a.SUCCESS,
|
|
436
494
|
body: this.data
|
|
437
495
|
});
|
|
438
|
-
const
|
|
439
|
-
(T =
|
|
440
|
-
|
|
496
|
+
const f = [];
|
|
497
|
+
(T = n == null ? void 0 : n.channels) == null || T.forEach((_) => {
|
|
498
|
+
_.preference === p.OPT_OUT && f.push(_.channel);
|
|
441
499
|
});
|
|
442
500
|
let h = !0;
|
|
443
|
-
typeof (r == null ? void 0 : r.showOptOutChannels) == "boolean" ? h = r == null ? void 0 : r.showOptOutChannels : typeof ((
|
|
444
|
-
const
|
|
445
|
-
preference: h &&
|
|
446
|
-
opt_out_channels:
|
|
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,
|
|
504
|
+
opt_out_channels: f
|
|
447
505
|
};
|
|
448
506
|
return this.debouncedUpdateCategoryPreferences(
|
|
449
507
|
s,
|
|
450
508
|
s,
|
|
451
|
-
|
|
452
|
-
|
|
509
|
+
v,
|
|
510
|
+
n,
|
|
453
511
|
{
|
|
454
512
|
tenant_id: (r == null ? void 0 : r.tenantId) || ((R = this.preferenceArgs) == null ? void 0 : R.tenantId),
|
|
455
513
|
show_opt_out_channels: h,
|
|
456
|
-
tags: (r == null ? void 0 : r.tags) || ((
|
|
457
|
-
locale: (r == null ? void 0 : r.locale) || ((
|
|
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)
|
|
458
516
|
}
|
|
459
517
|
), o({
|
|
460
|
-
status:
|
|
518
|
+
status: a.SUCCESS,
|
|
461
519
|
body: this.data
|
|
462
520
|
});
|
|
463
521
|
}
|
|
@@ -467,56 +525,56 @@ class q {
|
|
|
467
525
|
async updateOverallChannelPreference(e, t, s) {
|
|
468
526
|
var u;
|
|
469
527
|
if (!e || ![
|
|
470
|
-
|
|
471
|
-
|
|
528
|
+
w.ALL,
|
|
529
|
+
w.REQUIRED
|
|
472
530
|
].includes(t))
|
|
473
531
|
return o({
|
|
474
|
-
status:
|
|
475
|
-
errorType:
|
|
532
|
+
status: a.ERROR,
|
|
533
|
+
errorType: d.VALIDATION_ERROR,
|
|
476
534
|
errorMessage: e ? "Preference parameter is invalid" : "Channel parameter is missing"
|
|
477
535
|
});
|
|
478
536
|
if (!this.data)
|
|
479
537
|
return o({
|
|
480
|
-
status:
|
|
481
|
-
errorType:
|
|
538
|
+
status: a.ERROR,
|
|
539
|
+
errorType: d.VALIDATION_ERROR,
|
|
482
540
|
errorMessage: "Call getPreferences method before performing action"
|
|
483
541
|
});
|
|
484
542
|
if (!this.data.channel_preferences)
|
|
485
543
|
return o({
|
|
486
|
-
status:
|
|
487
|
-
errorType:
|
|
544
|
+
status: a.ERROR,
|
|
545
|
+
errorType: d.VALIDATION_ERROR,
|
|
488
546
|
errorMessage: "Channel preferences doesn't exist"
|
|
489
547
|
});
|
|
490
|
-
let r = null,
|
|
491
|
-
const
|
|
492
|
-
for (const
|
|
493
|
-
if (
|
|
494
|
-
|
|
548
|
+
let r = null, n = !1;
|
|
549
|
+
const c = t === w.REQUIRED;
|
|
550
|
+
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;
|
|
495
553
|
break;
|
|
496
554
|
}
|
|
497
|
-
return r ?
|
|
555
|
+
return r ? n ? (this.debouncedUpdateChannelPreferences(
|
|
498
556
|
r.channel,
|
|
499
557
|
{ channel_preferences: [r] },
|
|
500
558
|
{ tenant_id: (s == null ? void 0 : s.tenantId) || ((u = this.preferenceArgs) == null ? void 0 : u.tenantId) }
|
|
501
559
|
), o({
|
|
502
|
-
status:
|
|
560
|
+
status: a.SUCCESS,
|
|
503
561
|
body: this.data
|
|
504
562
|
})) : o({
|
|
505
|
-
status:
|
|
563
|
+
status: a.SUCCESS,
|
|
506
564
|
body: this.data
|
|
507
565
|
}) : o({
|
|
508
|
-
status:
|
|
509
|
-
errorType:
|
|
566
|
+
status: a.ERROR,
|
|
567
|
+
errorType: d.VALIDATION_ERROR,
|
|
510
568
|
errorMessage: "Channel data not found"
|
|
511
569
|
});
|
|
512
570
|
}
|
|
513
571
|
}
|
|
514
|
-
const
|
|
515
|
-
class
|
|
572
|
+
const K = "ss_device_id";
|
|
573
|
+
class ue {
|
|
516
574
|
constructor(e) {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
this.config = e, this.preferences = new
|
|
575
|
+
l(this, "config");
|
|
576
|
+
l(this, "preferences");
|
|
577
|
+
this.config = e, this.preferences = new de(e);
|
|
520
578
|
}
|
|
521
579
|
isReservedKey(e) {
|
|
522
580
|
var t;
|
|
@@ -531,15 +589,15 @@ class ee {
|
|
|
531
589
|
return Array.isArray(e) ? e : [e];
|
|
532
590
|
}
|
|
533
591
|
validateObjData(e, t) {
|
|
534
|
-
const s = {}, r = (t == null ? void 0 : t.allowReservedKeys) || !1,
|
|
535
|
-
for (const
|
|
536
|
-
let u = e[
|
|
537
|
-
if (!(
|
|
538
|
-
if (!r && this.isReservedKey(
|
|
592
|
+
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)) {
|
|
539
597
|
console.warn("[SuprSend]: key cannot start with $ or ss_");
|
|
540
598
|
continue;
|
|
541
599
|
}
|
|
542
|
-
|
|
600
|
+
n === "number" ? u = Number(u) : n === "boolean" && (u = !!u), s[c] = u;
|
|
543
601
|
}
|
|
544
602
|
}
|
|
545
603
|
return s;
|
|
@@ -559,8 +617,8 @@ class ee {
|
|
|
559
617
|
async triggerUserEvent(e) {
|
|
560
618
|
return this.config.eventApi({
|
|
561
619
|
distinct_id: this.config.distinctId,
|
|
562
|
-
$insert_id:
|
|
563
|
-
$time:
|
|
620
|
+
$insert_id: D(),
|
|
621
|
+
$time: M(),
|
|
564
622
|
...e
|
|
565
623
|
});
|
|
566
624
|
}
|
|
@@ -571,14 +629,14 @@ class ee {
|
|
|
571
629
|
const s = this.formatParamsToObj(e, t);
|
|
572
630
|
if (!s)
|
|
573
631
|
return o({
|
|
574
|
-
status:
|
|
575
|
-
errorType:
|
|
632
|
+
status: a.ERROR,
|
|
633
|
+
errorType: d.VALIDATION_ERROR,
|
|
576
634
|
errorMessage: "data provided is empty"
|
|
577
635
|
});
|
|
578
636
|
const r = this.validateObjData(s);
|
|
579
637
|
return I(r) ? o({
|
|
580
|
-
status:
|
|
581
|
-
errorType:
|
|
638
|
+
status: a.ERROR,
|
|
639
|
+
errorType: d.VALIDATION_ERROR,
|
|
582
640
|
errorMessage: "data provided is empty"
|
|
583
641
|
}) : this.triggerUserEvent({ $set: r });
|
|
584
642
|
}
|
|
@@ -590,14 +648,14 @@ class ee {
|
|
|
590
648
|
const s = this.formatParamsToObj(e, t);
|
|
591
649
|
if (!s)
|
|
592
650
|
return o({
|
|
593
|
-
status:
|
|
594
|
-
errorType:
|
|
651
|
+
status: a.ERROR,
|
|
652
|
+
errorType: d.VALIDATION_ERROR,
|
|
595
653
|
errorMessage: "data provided is empty"
|
|
596
654
|
});
|
|
597
655
|
const r = this.validateObjData(s);
|
|
598
656
|
return I(r) ? o({
|
|
599
|
-
status:
|
|
600
|
-
errorType:
|
|
657
|
+
status: a.ERROR,
|
|
658
|
+
errorType: d.VALIDATION_ERROR,
|
|
601
659
|
errorMessage: "data provided is empty"
|
|
602
660
|
}) : this.triggerUserEvent({ $set_once: r });
|
|
603
661
|
}
|
|
@@ -609,14 +667,14 @@ class ee {
|
|
|
609
667
|
const s = this.formatParamsToObj(e, t);
|
|
610
668
|
if (!s)
|
|
611
669
|
return o({
|
|
612
|
-
status:
|
|
613
|
-
errorType:
|
|
670
|
+
status: a.ERROR,
|
|
671
|
+
errorType: d.VALIDATION_ERROR,
|
|
614
672
|
errorMessage: "data provided is empty"
|
|
615
673
|
});
|
|
616
674
|
const r = this.validateObjData(s, { valueType: "number" });
|
|
617
675
|
return I(r) ? o({
|
|
618
|
-
status:
|
|
619
|
-
errorType:
|
|
676
|
+
status: a.ERROR,
|
|
677
|
+
errorType: d.VALIDATION_ERROR,
|
|
620
678
|
errorMessage: "data provided is empty"
|
|
621
679
|
}) : this.triggerUserEvent({ $add: r });
|
|
622
680
|
}
|
|
@@ -628,14 +686,14 @@ class ee {
|
|
|
628
686
|
const s = this.formatParamsToObj(e, t);
|
|
629
687
|
if (!s)
|
|
630
688
|
return o({
|
|
631
|
-
status:
|
|
632
|
-
errorType:
|
|
689
|
+
status: a.ERROR,
|
|
690
|
+
errorType: d.VALIDATION_ERROR,
|
|
633
691
|
errorMessage: "data provided is empty"
|
|
634
692
|
});
|
|
635
693
|
const r = this.validateObjData(s);
|
|
636
694
|
return I(r) ? o({
|
|
637
|
-
status:
|
|
638
|
-
errorType:
|
|
695
|
+
status: a.ERROR,
|
|
696
|
+
errorType: d.VALIDATION_ERROR,
|
|
639
697
|
errorMessage: "data provided is empty"
|
|
640
698
|
}) : this.triggerUserEvent({ $append: r });
|
|
641
699
|
}
|
|
@@ -647,14 +705,14 @@ class ee {
|
|
|
647
705
|
const s = this.formatParamsToObj(e, t);
|
|
648
706
|
if (!s)
|
|
649
707
|
return o({
|
|
650
|
-
status:
|
|
651
|
-
errorType:
|
|
708
|
+
status: a.ERROR,
|
|
709
|
+
errorType: d.VALIDATION_ERROR,
|
|
652
710
|
errorMessage: "data provided is empty"
|
|
653
711
|
});
|
|
654
712
|
const r = this.validateObjData(s);
|
|
655
713
|
return I(r) ? o({
|
|
656
|
-
status:
|
|
657
|
-
errorType:
|
|
714
|
+
status: a.ERROR,
|
|
715
|
+
errorType: d.VALIDATION_ERROR,
|
|
658
716
|
errorMessage: "data provided is empty"
|
|
659
717
|
}) : this.triggerUserEvent({ $remove: r });
|
|
660
718
|
}
|
|
@@ -665,14 +723,14 @@ class ee {
|
|
|
665
723
|
const t = this.formatParamsToArray(e);
|
|
666
724
|
if (!t)
|
|
667
725
|
return o({
|
|
668
|
-
status:
|
|
669
|
-
errorType:
|
|
726
|
+
status: a.ERROR,
|
|
727
|
+
errorType: d.VALIDATION_ERROR,
|
|
670
728
|
errorMessage: "data provided is empty"
|
|
671
729
|
});
|
|
672
730
|
const s = this.validateArrayData(t);
|
|
673
|
-
return
|
|
674
|
-
status:
|
|
675
|
-
errorType:
|
|
731
|
+
return Y(s) ? o({
|
|
732
|
+
status: a.ERROR,
|
|
733
|
+
errorType: d.VALIDATION_ERROR,
|
|
676
734
|
errorMessage: "data provided is empty"
|
|
677
735
|
}) : this.triggerUserEvent({ $unset: s });
|
|
678
736
|
}
|
|
@@ -681,16 +739,16 @@ class ee {
|
|
|
681
739
|
const s = this.formatParamsToObj(e, t);
|
|
682
740
|
if (!s)
|
|
683
741
|
return o({
|
|
684
|
-
status:
|
|
685
|
-
errorType:
|
|
742
|
+
status: a.ERROR,
|
|
743
|
+
errorType: d.VALIDATION_ERROR,
|
|
686
744
|
errorMessage: "data provided is empty"
|
|
687
745
|
});
|
|
688
746
|
const r = this.validateObjData(s, {
|
|
689
747
|
allowReservedKeys: !0
|
|
690
748
|
});
|
|
691
749
|
return I(r) ? o({
|
|
692
|
-
status:
|
|
693
|
-
errorType:
|
|
750
|
+
status: a.ERROR,
|
|
751
|
+
errorType: d.VALIDATION_ERROR,
|
|
694
752
|
errorMessage: "data provided is empty"
|
|
695
753
|
}) : this.triggerUserEvent({ $append: r });
|
|
696
754
|
}
|
|
@@ -699,16 +757,16 @@ class ee {
|
|
|
699
757
|
const s = this.formatParamsToObj(e, t);
|
|
700
758
|
if (!s)
|
|
701
759
|
return o({
|
|
702
|
-
status:
|
|
703
|
-
errorType:
|
|
760
|
+
status: a.ERROR,
|
|
761
|
+
errorType: d.VALIDATION_ERROR,
|
|
704
762
|
errorMessage: "data provided is empty"
|
|
705
763
|
});
|
|
706
764
|
const r = this.validateObjData(s, {
|
|
707
765
|
allowReservedKeys: !0
|
|
708
766
|
});
|
|
709
767
|
return I(r) ? o({
|
|
710
|
-
status:
|
|
711
|
-
errorType:
|
|
768
|
+
status: a.ERROR,
|
|
769
|
+
errorType: d.VALIDATION_ERROR,
|
|
712
770
|
errorMessage: "data provided is empty"
|
|
713
771
|
}) : this.triggerUserEvent({ $remove: r });
|
|
714
772
|
}
|
|
@@ -716,16 +774,16 @@ class ee {
|
|
|
716
774
|
const s = this.formatParamsToObj(e, t);
|
|
717
775
|
if (!s)
|
|
718
776
|
return o({
|
|
719
|
-
status:
|
|
720
|
-
errorType:
|
|
777
|
+
status: a.ERROR,
|
|
778
|
+
errorType: d.VALIDATION_ERROR,
|
|
721
779
|
errorMessage: "data provided is empty"
|
|
722
780
|
});
|
|
723
781
|
const r = this.validateObjData(s, {
|
|
724
782
|
allowReservedKeys: !0
|
|
725
783
|
});
|
|
726
784
|
return I(r) ? o({
|
|
727
|
-
status:
|
|
728
|
-
errorType:
|
|
785
|
+
status: a.ERROR,
|
|
786
|
+
errorType: d.VALIDATION_ERROR,
|
|
729
787
|
errorMessage: "data provided is empty"
|
|
730
788
|
}) : this.triggerUserEvent({ $set: r });
|
|
731
789
|
}
|
|
@@ -737,15 +795,15 @@ class ee {
|
|
|
737
795
|
}
|
|
738
796
|
async addEmail(e) {
|
|
739
797
|
return this.validateEmail(e) ? this.appendInternal({ $email: e }) : o({
|
|
740
|
-
status:
|
|
741
|
-
errorType:
|
|
798
|
+
status: a.ERROR,
|
|
799
|
+
errorType: d.VALIDATION_ERROR,
|
|
742
800
|
errorMessage: "provided email is invalid"
|
|
743
801
|
});
|
|
744
802
|
}
|
|
745
803
|
async removeEmail(e) {
|
|
746
804
|
return this.validateEmail(e) ? this.removeInternal({ $email: e }) : o({
|
|
747
|
-
status:
|
|
748
|
-
errorType:
|
|
805
|
+
status: a.ERROR,
|
|
806
|
+
errorType: d.VALIDATION_ERROR,
|
|
749
807
|
errorMessage: "provided email is invalid"
|
|
750
808
|
});
|
|
751
809
|
}
|
|
@@ -754,8 +812,8 @@ class ee {
|
|
|
754
812
|
*/
|
|
755
813
|
async addSms(e) {
|
|
756
814
|
return this.validateMobile(e) ? this.appendInternal({ $sms: e }) : o({
|
|
757
|
-
status:
|
|
758
|
-
errorType:
|
|
815
|
+
status: a.ERROR,
|
|
816
|
+
errorType: d.VALIDATION_ERROR,
|
|
759
817
|
errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
|
|
760
818
|
});
|
|
761
819
|
}
|
|
@@ -764,8 +822,8 @@ class ee {
|
|
|
764
822
|
*/
|
|
765
823
|
async removeSms(e) {
|
|
766
824
|
return this.validateMobile(e) ? this.removeInternal({ $sms: e }) : o({
|
|
767
|
-
status:
|
|
768
|
-
errorType:
|
|
825
|
+
status: a.ERROR,
|
|
826
|
+
errorType: d.VALIDATION_ERROR,
|
|
769
827
|
errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
|
|
770
828
|
});
|
|
771
829
|
}
|
|
@@ -774,8 +832,8 @@ class ee {
|
|
|
774
832
|
*/
|
|
775
833
|
async addWhatsapp(e) {
|
|
776
834
|
return this.validateMobile(e) ? this.appendInternal({ $whatsapp: e }) : o({
|
|
777
|
-
status:
|
|
778
|
-
errorType:
|
|
835
|
+
status: a.ERROR,
|
|
836
|
+
errorType: d.VALIDATION_ERROR,
|
|
779
837
|
errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
|
|
780
838
|
});
|
|
781
839
|
}
|
|
@@ -784,20 +842,20 @@ class ee {
|
|
|
784
842
|
*/
|
|
785
843
|
async removeWhatsapp(e) {
|
|
786
844
|
return this.validateMobile(e) ? this.removeInternal({ $whatsapp: e }) : o({
|
|
787
|
-
status:
|
|
788
|
-
errorType:
|
|
845
|
+
status: a.ERROR,
|
|
846
|
+
errorType: d.VALIDATION_ERROR,
|
|
789
847
|
errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
|
|
790
848
|
});
|
|
791
849
|
}
|
|
792
850
|
getDeviceId() {
|
|
793
|
-
let e =
|
|
794
|
-
return e || (e =
|
|
851
|
+
let e = j(K);
|
|
852
|
+
return e || (e = D(), $(K, e)), e;
|
|
795
853
|
}
|
|
796
854
|
async addWebPush(e) {
|
|
797
855
|
if (typeof e != "object")
|
|
798
856
|
return o({
|
|
799
|
-
status:
|
|
800
|
-
errorType:
|
|
857
|
+
status: a.ERROR,
|
|
858
|
+
errorType: d.VALIDATION_ERROR,
|
|
801
859
|
errorMessage: "provided push subscription is invalid, must be an object"
|
|
802
860
|
});
|
|
803
861
|
const t = this.getDeviceId();
|
|
@@ -810,8 +868,8 @@ class ee {
|
|
|
810
868
|
async removeWebPush(e) {
|
|
811
869
|
if (typeof e != "object")
|
|
812
870
|
return o({
|
|
813
|
-
status:
|
|
814
|
-
errorType:
|
|
871
|
+
status: a.ERROR,
|
|
872
|
+
errorType: d.VALIDATION_ERROR,
|
|
815
873
|
errorMessage: "provided push subscription is invalid, must be an object"
|
|
816
874
|
});
|
|
817
875
|
const t = this.getDeviceId();
|
|
@@ -823,29 +881,29 @@ class ee {
|
|
|
823
881
|
}
|
|
824
882
|
async addSlack(e) {
|
|
825
883
|
return typeof e != "object" ? o({
|
|
826
|
-
status:
|
|
827
|
-
errorType:
|
|
884
|
+
status: a.ERROR,
|
|
885
|
+
errorType: d.VALIDATION_ERROR,
|
|
828
886
|
errorMessage: "provided slack data is invalid, must be an object"
|
|
829
887
|
}) : this.appendInternal({ $slack: e });
|
|
830
888
|
}
|
|
831
889
|
async removeSlack(e) {
|
|
832
890
|
return typeof e != "object" ? o({
|
|
833
|
-
status:
|
|
834
|
-
errorType:
|
|
891
|
+
status: a.ERROR,
|
|
892
|
+
errorType: d.VALIDATION_ERROR,
|
|
835
893
|
errorMessage: "provided slack data is invalid, must be an object"
|
|
836
894
|
}) : this.removeInternal({ $slack: e });
|
|
837
895
|
}
|
|
838
896
|
async addMSTeams(e) {
|
|
839
897
|
return typeof e != "object" ? o({
|
|
840
|
-
status:
|
|
841
|
-
errorType:
|
|
898
|
+
status: a.ERROR,
|
|
899
|
+
errorType: d.VALIDATION_ERROR,
|
|
842
900
|
errorMessage: "provided ms_teams data is invalid, must be object"
|
|
843
901
|
}) : this.appendInternal({ $ms_teams: e });
|
|
844
902
|
}
|
|
845
903
|
async removeMSTeams(e) {
|
|
846
904
|
return typeof e != "object" ? o({
|
|
847
|
-
status:
|
|
848
|
-
errorType:
|
|
905
|
+
status: a.ERROR,
|
|
906
|
+
errorType: d.VALIDATION_ERROR,
|
|
849
907
|
errorMessage: "provided ms_teams data is invalid, must be object"
|
|
850
908
|
}) : this.removeInternal({ $ms_teams: e });
|
|
851
909
|
}
|
|
@@ -855,8 +913,8 @@ class ee {
|
|
|
855
913
|
*/
|
|
856
914
|
async setPreferredLanguage(e) {
|
|
857
915
|
return typeof e != "string" ? o({
|
|
858
|
-
status:
|
|
859
|
-
errorType:
|
|
916
|
+
status: a.ERROR,
|
|
917
|
+
errorType: d.VALIDATION_ERROR,
|
|
860
918
|
errorMessage: "provided language is invalid, must be string"
|
|
861
919
|
}) : this.setInternal({ $preferred_language: e });
|
|
862
920
|
}
|
|
@@ -865,20 +923,20 @@ class ee {
|
|
|
865
923
|
*/
|
|
866
924
|
async setTimezone(e) {
|
|
867
925
|
return typeof e != "string" ? o({
|
|
868
|
-
status:
|
|
869
|
-
errorType:
|
|
926
|
+
status: a.ERROR,
|
|
927
|
+
errorType: d.VALIDATION_ERROR,
|
|
870
928
|
errorMessage: "provided timezone is invalid, must be string"
|
|
871
929
|
}) : this.setInternal({ $timezone: e });
|
|
872
930
|
}
|
|
873
931
|
}
|
|
874
|
-
const
|
|
875
|
-
class
|
|
932
|
+
const x = "ss_wp_hash";
|
|
933
|
+
class he {
|
|
876
934
|
constructor(e) {
|
|
877
|
-
|
|
935
|
+
l(this, "config");
|
|
878
936
|
this.config = e;
|
|
879
937
|
}
|
|
880
938
|
async getPushSubscription() {
|
|
881
|
-
if (!
|
|
939
|
+
if (!N()) return;
|
|
882
940
|
const e = await navigator.serviceWorker.getRegistration();
|
|
883
941
|
if (!e) return;
|
|
884
942
|
const t = e.pushManager.getSubscription();
|
|
@@ -889,13 +947,13 @@ class te {
|
|
|
889
947
|
const t = e.endpoint;
|
|
890
948
|
let s = null;
|
|
891
949
|
try {
|
|
892
|
-
s = await
|
|
950
|
+
s = await ce(t);
|
|
893
951
|
} catch {
|
|
894
952
|
}
|
|
895
953
|
if (s) {
|
|
896
|
-
if (s ===
|
|
897
|
-
return o({ status:
|
|
898
|
-
|
|
954
|
+
if (s === j(x))
|
|
955
|
+
return o({ status: a.SUCCESS });
|
|
956
|
+
$(x, s);
|
|
899
957
|
}
|
|
900
958
|
return await this.config.user.addWebPush(e);
|
|
901
959
|
}
|
|
@@ -903,8 +961,8 @@ class te {
|
|
|
903
961
|
try {
|
|
904
962
|
if (await navigator.serviceWorker.register(`/${this.config.swFileName}`), await Notification.requestPermission() !== "granted")
|
|
905
963
|
return console.warn("[SuprSend]: Notification permission isnt granted"), o({
|
|
906
|
-
status:
|
|
907
|
-
errorType:
|
|
964
|
+
status: a.ERROR,
|
|
965
|
+
errorType: d.PERMISSION_DENIED,
|
|
908
966
|
errorMessage: "Notification permission isn't granted"
|
|
909
967
|
});
|
|
910
968
|
const t = await navigator.serviceWorker.ready, s = await t.pushManager.getSubscription();
|
|
@@ -914,19 +972,19 @@ class te {
|
|
|
914
972
|
return console.warn(
|
|
915
973
|
"[SuprSend]: Vapid key is missing. Add it while creating SuprSend instance"
|
|
916
974
|
), o({
|
|
917
|
-
status:
|
|
918
|
-
errorType:
|
|
975
|
+
status: a.ERROR,
|
|
976
|
+
errorType: d.VALIDATION_ERROR,
|
|
919
977
|
errorMessage: "Vapid key is missing. Add it while creating SuprSend instance"
|
|
920
978
|
});
|
|
921
979
|
const r = await t.pushManager.subscribe({
|
|
922
980
|
userVisibleOnly: !0,
|
|
923
|
-
applicationServerKey:
|
|
981
|
+
applicationServerKey: q(this.config.vapidKey)
|
|
924
982
|
});
|
|
925
983
|
return this.checkAndUpdateOnServer(r);
|
|
926
984
|
} catch (e) {
|
|
927
985
|
return console.warn("SuprSend: Error getting push subscription", e), o({
|
|
928
|
-
status:
|
|
929
|
-
errorType:
|
|
986
|
+
status: a.ERROR,
|
|
987
|
+
errorType: d.UNKNOWN_ERROR,
|
|
930
988
|
errorMessage: (e == null ? void 0 : e.message) || "Unknown error occured while registering for push"
|
|
931
989
|
});
|
|
932
990
|
}
|
|
@@ -938,9 +996,9 @@ class te {
|
|
|
938
996
|
* 3. Send webpush token to SuprSend.
|
|
939
997
|
*/
|
|
940
998
|
async registerPush() {
|
|
941
|
-
return
|
|
942
|
-
status:
|
|
943
|
-
errorType:
|
|
999
|
+
return N() && "serviceWorker" in navigator && "PushManager" in window ? this.handleRegisterPush() : (console.warn("[SuprSend]: Webpush isn't supported"), o({
|
|
1000
|
+
status: a.ERROR,
|
|
1001
|
+
errorType: d.UNSUPPORTED_ACTION,
|
|
944
1002
|
errorMessage: "Webpush isn't supported"
|
|
945
1003
|
}));
|
|
946
1004
|
}
|
|
@@ -967,37 +1025,37 @@ class te {
|
|
|
967
1025
|
return !!await this.getPushSubscription();
|
|
968
1026
|
}
|
|
969
1027
|
}
|
|
970
|
-
const
|
|
1028
|
+
const z = 20, fe = "default", le = 100, C = {
|
|
971
1029
|
storeId: "$suprsend_default_store",
|
|
972
1030
|
label: ""
|
|
973
|
-
},
|
|
974
|
-
tenantId:
|
|
975
|
-
pageSize:
|
|
1031
|
+
}, pe = {
|
|
1032
|
+
tenantId: fe,
|
|
1033
|
+
pageSize: z,
|
|
976
1034
|
stores: null,
|
|
977
1035
|
host: {
|
|
978
1036
|
apiHost: "https://inboxs.live",
|
|
979
1037
|
socketHost: "https://betainbox.suprsend.com"
|
|
980
1038
|
}
|
|
981
|
-
},
|
|
1039
|
+
}, k = {
|
|
982
1040
|
notifications: [],
|
|
983
|
-
store:
|
|
1041
|
+
store: C,
|
|
984
1042
|
pageInfo: {
|
|
985
1043
|
total: 0,
|
|
986
|
-
pageSize:
|
|
1044
|
+
pageSize: z,
|
|
987
1045
|
hasMore: !1
|
|
988
1046
|
},
|
|
989
1047
|
meta: { badge: 0 },
|
|
990
|
-
apiStatus:
|
|
1048
|
+
apiStatus: S.INITIAL,
|
|
991
1049
|
isFirstFetch: !0
|
|
992
1050
|
};
|
|
993
|
-
class
|
|
1051
|
+
class Re {
|
|
994
1052
|
constructor(e) {
|
|
995
|
-
|
|
996
|
-
|
|
1053
|
+
l(this, "config");
|
|
1054
|
+
l(this, "feedInstances", []);
|
|
997
1055
|
this.config = e;
|
|
998
1056
|
}
|
|
999
1057
|
initialize(e = {}) {
|
|
1000
|
-
const t = new
|
|
1058
|
+
const t = new Oe(this.config, e);
|
|
1001
1059
|
return this.feedInstances.push(t), t;
|
|
1002
1060
|
}
|
|
1003
1061
|
removeInstance(e) {
|
|
@@ -1011,19 +1069,19 @@ class ne {
|
|
|
1011
1069
|
this.feedInstances = [];
|
|
1012
1070
|
}
|
|
1013
1071
|
}
|
|
1014
|
-
class
|
|
1072
|
+
class Oe {
|
|
1015
1073
|
constructor(e, t) {
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1074
|
+
l(this, "feedOptions");
|
|
1075
|
+
l(this, "config");
|
|
1076
|
+
l(this, "store");
|
|
1077
|
+
l(this, "socket");
|
|
1078
|
+
l(this, "expiryTimerId");
|
|
1079
|
+
l(this, "fetchAbortController");
|
|
1080
|
+
l(this, "emitter", H());
|
|
1023
1081
|
this.config = e, this.setOptions(t), this.store = this.createFeedStore();
|
|
1024
1082
|
}
|
|
1025
1083
|
setOptions(e) {
|
|
1026
|
-
this.feedOptions = { ...
|
|
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();
|
|
1027
1085
|
}
|
|
1028
1086
|
validateStore() {
|
|
1029
1087
|
const e = this.feedOptions.stores;
|
|
@@ -1041,25 +1099,25 @@ class ae {
|
|
|
1041
1099
|
return;
|
|
1042
1100
|
}
|
|
1043
1101
|
const r = s == null ? void 0 : s.query;
|
|
1044
|
-
let
|
|
1045
|
-
typeof (r == null ? void 0 : r.read) == "boolean" && (
|
|
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({
|
|
1046
1104
|
storeId: s.storeId,
|
|
1047
1105
|
label: s.label || s.storeId,
|
|
1048
1106
|
query: {
|
|
1049
|
-
archived:
|
|
1050
|
-
read:
|
|
1107
|
+
archived: c,
|
|
1108
|
+
read: n,
|
|
1051
1109
|
tags: u,
|
|
1052
|
-
categories:
|
|
1110
|
+
categories: f
|
|
1053
1111
|
}
|
|
1054
1112
|
});
|
|
1055
1113
|
}), this.feedOptions.stores = t;
|
|
1056
1114
|
}
|
|
1057
1115
|
createFeedStore() {
|
|
1058
|
-
return
|
|
1116
|
+
return G()(() => {
|
|
1059
1117
|
var e;
|
|
1060
1118
|
return {
|
|
1061
|
-
...
|
|
1062
|
-
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) ||
|
|
1119
|
+
...k,
|
|
1120
|
+
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) || C
|
|
1063
1121
|
};
|
|
1064
1122
|
});
|
|
1065
1123
|
}
|
|
@@ -1067,18 +1125,18 @@ class ae {
|
|
|
1067
1125
|
this.socket.on("connect_error", async (e) => {
|
|
1068
1126
|
var t;
|
|
1069
1127
|
if (e.message === "Authentication Error: wrong auth token" && ((t = this.config.authenticateOptions) != null && t.refreshUserToken) && this.config.userToken) {
|
|
1070
|
-
const s = this.socket.auth["x-ss-signature"], r =
|
|
1071
|
-
if (
|
|
1128
|
+
const s = this.socket.auth["x-ss-signature"], r = L(s), n = (r.exp || 0) * 1e3, c = Date.now();
|
|
1129
|
+
if (n <= c)
|
|
1072
1130
|
try {
|
|
1073
|
-
const
|
|
1131
|
+
const f = await this.config.authenticateOptions.refreshUserToken(
|
|
1074
1132
|
this.config.userToken,
|
|
1075
1133
|
r
|
|
1076
1134
|
);
|
|
1077
|
-
|
|
1135
|
+
f && typeof f == "string" && (await this.config.identify(
|
|
1078
1136
|
this.config.distinctId,
|
|
1079
|
-
|
|
1137
|
+
f,
|
|
1080
1138
|
this.config.authenticateOptions
|
|
1081
|
-
), this.socket.auth["x-ss-signature"] =
|
|
1139
|
+
), this.socket.auth["x-ss-signature"] = f, setTimeout(() => {
|
|
1082
1140
|
this.socket.connect();
|
|
1083
1141
|
}, 1e3));
|
|
1084
1142
|
} catch {
|
|
@@ -1101,30 +1159,30 @@ class ae {
|
|
|
1101
1159
|
});
|
|
1102
1160
|
}
|
|
1103
1161
|
async handleNewNotificationSocketEvent(e) {
|
|
1104
|
-
var u,
|
|
1162
|
+
var u, f;
|
|
1105
1163
|
if (!e.n_id) return;
|
|
1106
1164
|
const t = await this.fetchDetails(e.n_id);
|
|
1107
|
-
if (t.status ===
|
|
1165
|
+
if (t.status === a.ERROR)
|
|
1108
1166
|
return;
|
|
1109
1167
|
const s = t.body, r = this.store.getState();
|
|
1110
|
-
let
|
|
1111
|
-
const
|
|
1112
|
-
this.notificationBelongToStore(s, r.store) && (
|
|
1168
|
+
let n = !1;
|
|
1169
|
+
const c = { ...r.meta };
|
|
1170
|
+
this.notificationBelongToStore(s, r.store) && (n = !0, this.store.setState({
|
|
1113
1171
|
notifications: this.orderNotificationsBasedOnPinFlag(
|
|
1114
1172
|
s,
|
|
1115
1173
|
r.notifications
|
|
1116
1174
|
)
|
|
1117
|
-
})), (
|
|
1118
|
-
this.notificationBelongToStore(s, h) && (
|
|
1175
|
+
})), (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);
|
|
1119
1177
|
}), this.store.setState({
|
|
1120
1178
|
meta: {
|
|
1121
|
-
...
|
|
1122
|
-
badge:
|
|
1179
|
+
...c,
|
|
1180
|
+
badge: n ? c.badge + 1 : c.badge
|
|
1123
1181
|
}
|
|
1124
|
-
}),
|
|
1182
|
+
}), n && this.emitter.emit("feed.new_notification", s), this.emitter.emit("feed.store_update", this.data);
|
|
1125
1183
|
}
|
|
1126
1184
|
async handleNoticationUpdateSocketEvent(e) {
|
|
1127
|
-
var
|
|
1185
|
+
var f;
|
|
1128
1186
|
if (!e.n_id) return;
|
|
1129
1187
|
const t = await Promise.allSettled([
|
|
1130
1188
|
this.fetchDetails(e.n_id),
|
|
@@ -1132,23 +1190,23 @@ class ae {
|
|
|
1132
1190
|
]), s = this.store.getState();
|
|
1133
1191
|
if (t[0].status !== "fulfilled") return;
|
|
1134
1192
|
const r = t[0].value;
|
|
1135
|
-
if (r.status ===
|
|
1136
|
-
const
|
|
1137
|
-
(h) => h.n_id ===
|
|
1193
|
+
if (r.status === a.ERROR) return;
|
|
1194
|
+
const n = r.body, c = (f = s.notifications) == null ? void 0 : f.some(
|
|
1195
|
+
(h) => h.n_id === n.n_id
|
|
1138
1196
|
);
|
|
1139
1197
|
this.notificationBelongToStore(
|
|
1140
|
-
|
|
1198
|
+
n,
|
|
1141
1199
|
s.store
|
|
1142
|
-
) ?
|
|
1143
|
-
notifications: s.notifications.map((h) => h.n_id ===
|
|
1200
|
+
) ? c ? this.store.setState({
|
|
1201
|
+
notifications: s.notifications.map((h) => h.n_id === n.n_id ? n : h)
|
|
1144
1202
|
}) : this.store.setState({
|
|
1145
1203
|
notifications: this.orderNotificationsBasedOnPinFlag(
|
|
1146
|
-
|
|
1204
|
+
n,
|
|
1147
1205
|
s.notifications
|
|
1148
1206
|
)
|
|
1149
1207
|
}) : this.store.setState({
|
|
1150
1208
|
notifications: s.notifications.filter(
|
|
1151
|
-
(h) => h.n_id !==
|
|
1209
|
+
(h) => h.n_id !== n.n_id
|
|
1152
1210
|
)
|
|
1153
1211
|
}), this.emitter.emit("feed.store_update", this.data);
|
|
1154
1212
|
}
|
|
@@ -1167,12 +1225,12 @@ class ae {
|
|
|
1167
1225
|
}), this.emitter.emit("feed.store_update", this.data);
|
|
1168
1226
|
}
|
|
1169
1227
|
notificationBelongToStore(e, t) {
|
|
1170
|
-
var
|
|
1171
|
-
const s = !!e.read_on, r = e.archived,
|
|
1172
|
-
let
|
|
1173
|
-
return Array.isArray(h) && h.length > 0 ? h.forEach((
|
|
1174
|
-
|
|
1175
|
-
}) :
|
|
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;
|
|
1231
|
+
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;
|
|
1176
1234
|
}
|
|
1177
1235
|
orderNotificationsBasedOnPinFlag(e, t) {
|
|
1178
1236
|
if (e.is_pinned)
|
|
@@ -1180,8 +1238,8 @@ class ae {
|
|
|
1180
1238
|
{
|
|
1181
1239
|
let s = !1;
|
|
1182
1240
|
const r = [];
|
|
1183
|
-
return t.forEach((
|
|
1184
|
-
|
|
1241
|
+
return t.forEach((n) => {
|
|
1242
|
+
n.is_pinned || s ? r.push(n) : (r.push(e), r.push(n), s = !0);
|
|
1185
1243
|
}), s ? r : [...t, e];
|
|
1186
1244
|
}
|
|
1187
1245
|
}
|
|
@@ -1197,11 +1255,11 @@ class ae {
|
|
|
1197
1255
|
t && (this.store.setState({ notifications: s }), await this.fetchCount(), this.emitter.emit("feed.store_update", this.data));
|
|
1198
1256
|
}
|
|
1199
1257
|
getUrl(e, t) {
|
|
1200
|
-
var
|
|
1201
|
-
const s = `${(
|
|
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(
|
|
1202
1260
|
r
|
|
1203
1261
|
).toString();
|
|
1204
|
-
return
|
|
1262
|
+
return n ? `${s}?${n}` : s;
|
|
1205
1263
|
}
|
|
1206
1264
|
validateQueryParams(e = {}) {
|
|
1207
1265
|
const t = {};
|
|
@@ -1214,20 +1272,20 @@ class ae {
|
|
|
1214
1272
|
requestInprogress() {
|
|
1215
1273
|
const e = this.store.getState();
|
|
1216
1274
|
return [
|
|
1217
|
-
|
|
1218
|
-
|
|
1275
|
+
S.LOADING,
|
|
1276
|
+
S.FETCHING_MORE
|
|
1219
1277
|
].includes(e.apiStatus);
|
|
1220
1278
|
}
|
|
1221
1279
|
storesQueryParamObj(e) {
|
|
1222
1280
|
return e == null ? void 0 : e.map((s) => this.storeQueryParamObj(s));
|
|
1223
1281
|
}
|
|
1224
1282
|
storeQueryParamObj(e) {
|
|
1225
|
-
const t = e == null ? void 0 : e.query, s = (t == null ? void 0 : t.tags) || [], r = (t == null ? void 0 : t.categories) || [],
|
|
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;
|
|
1226
1284
|
return {
|
|
1227
1285
|
store_id: e.storeId,
|
|
1228
1286
|
query: {
|
|
1229
|
-
read:
|
|
1230
|
-
archived:
|
|
1287
|
+
read: n,
|
|
1288
|
+
archived: c,
|
|
1231
1289
|
tags: { or: s },
|
|
1232
1290
|
categories: { or: r }
|
|
1233
1291
|
}
|
|
@@ -1238,16 +1296,16 @@ class ae {
|
|
|
1238
1296
|
const t = this.store.getState();
|
|
1239
1297
|
if (t.store.storeId === e) return;
|
|
1240
1298
|
const s = (r = this.feedOptions.stores) == null ? void 0 : r.find(
|
|
1241
|
-
(
|
|
1299
|
+
(n) => n.storeId === e
|
|
1242
1300
|
);
|
|
1243
1301
|
return s ? (this.fetchAbortController && (this.fetchAbortController.abort(), this.fetchAbortController = void 0), this.store.setState({
|
|
1244
|
-
...
|
|
1302
|
+
...k,
|
|
1245
1303
|
store: s,
|
|
1246
1304
|
meta: t.meta
|
|
1247
1305
|
}), await this.fetch()) : {
|
|
1248
|
-
status:
|
|
1306
|
+
status: a.ERROR,
|
|
1249
1307
|
error: {
|
|
1250
|
-
type:
|
|
1308
|
+
type: d.NOT_FOUND,
|
|
1251
1309
|
message: `store with storeId ${e} doesnt exist`
|
|
1252
1310
|
}
|
|
1253
1311
|
};
|
|
@@ -1264,7 +1322,7 @@ class ae {
|
|
|
1264
1322
|
}
|
|
1265
1323
|
initializeSocketConnection() {
|
|
1266
1324
|
var e;
|
|
1267
|
-
this.socket || (this.socket =
|
|
1325
|
+
this.socket || (this.socket = J((e = this.feedOptions.host) == null ? void 0 : e.socketHost, {
|
|
1268
1326
|
transports: ["websocket"],
|
|
1269
1327
|
auth: {
|
|
1270
1328
|
authorization: this.config.publicApiKey,
|
|
@@ -1283,30 +1341,30 @@ class ae {
|
|
|
1283
1341
|
if (this.requestInprogress()) return;
|
|
1284
1342
|
const s = (e == null ? void 0 : e.pageSize) || this.feedOptions.pageSize;
|
|
1285
1343
|
t.isFirstFetch ? (this.store.setState({
|
|
1286
|
-
apiStatus:
|
|
1344
|
+
apiStatus: S.LOADING
|
|
1287
1345
|
}), this.fetchCount()) : this.store.setState({
|
|
1288
|
-
apiStatus:
|
|
1346
|
+
apiStatus: S.FETCHING_MORE
|
|
1289
1347
|
}), this.emitter.emit("feed.store_update", this.data);
|
|
1290
1348
|
const r = {
|
|
1291
1349
|
distinct_id: this.config.distinctId,
|
|
1292
1350
|
tenant_id: this.feedOptions.tenantId,
|
|
1293
1351
|
page_size: s,
|
|
1294
|
-
store: t.store.storeId !==
|
|
1352
|
+
store: t.store.storeId !== C.storeId ? this.storeQueryParamObj(t.store) : null
|
|
1295
1353
|
};
|
|
1296
1354
|
if (t.notifications.length > 0) {
|
|
1297
|
-
const
|
|
1355
|
+
const f = t.notifications[t.notifications.length - 1];
|
|
1298
1356
|
r.search_after = [
|
|
1299
|
-
|
|
1300
|
-
|
|
1357
|
+
f.is_pinned,
|
|
1358
|
+
f.created_on
|
|
1301
1359
|
];
|
|
1302
1360
|
} else
|
|
1303
1361
|
r.search_after = [];
|
|
1304
|
-
const
|
|
1305
|
-
this.fetchAbortController =
|
|
1306
|
-
const u = await this.config.client().request({ type: "get", url:
|
|
1307
|
-
if (!
|
|
1308
|
-
return u.status ===
|
|
1309
|
-
apiStatus:
|
|
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,
|
|
1310
1368
|
notifications: t.isFirstFetch ? u.body.results : [...t.notifications, ...u.body.results],
|
|
1311
1369
|
pageInfo: {
|
|
1312
1370
|
...t.pageInfo,
|
|
@@ -1319,9 +1377,9 @@ class ae {
|
|
|
1319
1377
|
// TODO: support other stores
|
|
1320
1378
|
async fetchNextPage() {
|
|
1321
1379
|
return this.store.getState().pageInfo.hasMore === !1 ? {
|
|
1322
|
-
status:
|
|
1380
|
+
status: a.ERROR,
|
|
1323
1381
|
error: {
|
|
1324
|
-
type:
|
|
1382
|
+
type: d.VALIDATION_ERROR,
|
|
1325
1383
|
message: "No more pages to fetch"
|
|
1326
1384
|
}
|
|
1327
1385
|
} : this.fetch();
|
|
@@ -1332,7 +1390,7 @@ class ae {
|
|
|
1332
1390
|
tenant_id: this.feedOptions.tenantId,
|
|
1333
1391
|
stores: this.feedOptions.stores ? this.storesQueryParamObj(this.feedOptions.stores) : null
|
|
1334
1392
|
}, t = this.getUrl("notifications_count", e), s = await this.config.client().request({ type: "get", url: t });
|
|
1335
|
-
return s.status ===
|
|
1393
|
+
return s.status === a.SUCCESS && this.store.setState({ meta: s.body }), this.emitter.emit("feed.store_update", this.data), s;
|
|
1336
1394
|
}
|
|
1337
1395
|
async fetchDetails(e) {
|
|
1338
1396
|
const t = this.getUrl(`notifications/${e}`, {
|
|
@@ -1345,8 +1403,8 @@ class ae {
|
|
|
1345
1403
|
const t = this.store.getState();
|
|
1346
1404
|
let s = !1;
|
|
1347
1405
|
if (this.store.setState({
|
|
1348
|
-
notifications: t.notifications.map((
|
|
1349
|
-
}), s) return { status:
|
|
1406
|
+
notifications: t.notifications.map((n) => (n.n_id === e && (n.seen_on ? s = !0 : n.seen_on = Date.now()), n))
|
|
1407
|
+
}), s) return { status: a.SUCCESS };
|
|
1350
1408
|
const r = this.getUrl(`notifications/${e}/seen`, {
|
|
1351
1409
|
tenant_id: this.feedOptions.tenantId,
|
|
1352
1410
|
distinct_id: this.config.distinctId
|
|
@@ -1357,8 +1415,8 @@ class ae {
|
|
|
1357
1415
|
const t = this.store.getState();
|
|
1358
1416
|
let s = !1;
|
|
1359
1417
|
if (this.store.setState({
|
|
1360
|
-
notifications: t.notifications.map((
|
|
1361
|
-
}), s) return { status:
|
|
1418
|
+
notifications: t.notifications.map((n) => (n.n_id === e && (n.read_on ? s = !0 : (n.read_on = Date.now(), n.seen_on = Date.now())), n))
|
|
1419
|
+
}), s) return { status: a.SUCCESS };
|
|
1362
1420
|
const r = this.getUrl(`notifications/${e}/read`, {
|
|
1363
1421
|
tenant_id: this.feedOptions.tenantId,
|
|
1364
1422
|
distinct_id: this.config.distinctId
|
|
@@ -1369,8 +1427,8 @@ class ae {
|
|
|
1369
1427
|
const t = this.store.getState();
|
|
1370
1428
|
let s = !1;
|
|
1371
1429
|
if (this.store.setState({
|
|
1372
|
-
notifications: t.notifications.map((
|
|
1373
|
-
}), s) return { status:
|
|
1430
|
+
notifications: t.notifications.map((n) => (n.n_id === e && (n.read_on ? n.read_on = null : s = !0), n))
|
|
1431
|
+
}), s) return { status: a.SUCCESS };
|
|
1374
1432
|
const r = this.getUrl(`notifications/${e}/unread`, {
|
|
1375
1433
|
tenant_id: this.feedOptions.tenantId,
|
|
1376
1434
|
distinct_id: this.config.distinctId
|
|
@@ -1393,8 +1451,8 @@ class ae {
|
|
|
1393
1451
|
const t = this.store.getState();
|
|
1394
1452
|
let s = !1;
|
|
1395
1453
|
if (this.store.setState({
|
|
1396
|
-
notifications: t.notifications.filter((
|
|
1397
|
-
}), s) return { status:
|
|
1454
|
+
notifications: t.notifications.filter((n) => n.n_id === e ? (s = !!n.archived, !1) : !0)
|
|
1455
|
+
}), s) return { status: a.SUCCESS };
|
|
1398
1456
|
const r = this.getUrl(`notifications/${e}/archive`, {
|
|
1399
1457
|
tenant_id: this.feedOptions.tenantId,
|
|
1400
1458
|
distinct_id: this.config.distinctId
|
|
@@ -1440,8 +1498,8 @@ class ae {
|
|
|
1440
1498
|
reset() {
|
|
1441
1499
|
var e;
|
|
1442
1500
|
this.store.setState({
|
|
1443
|
-
...
|
|
1444
|
-
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) ||
|
|
1501
|
+
...k,
|
|
1502
|
+
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) || C
|
|
1445
1503
|
}), this.emitter.emit("feed.store_update", this.data), this.expiryTimerId && (clearInterval(this.expiryTimerId), this.expiryTimerId = void 0);
|
|
1446
1504
|
}
|
|
1447
1505
|
remove() {
|
|
@@ -1449,31 +1507,36 @@ class ae {
|
|
|
1449
1507
|
this.reset(), this.emitter.off("*"), (e = this.socket) == null || e.disconnect(), this.config.feeds.removeInstance(this);
|
|
1450
1508
|
}
|
|
1451
1509
|
}
|
|
1452
|
-
const
|
|
1453
|
-
class
|
|
1510
|
+
const me = "https://hub.suprsend.com", ge = "serviceworker.js", W = "ss_distinct_id";
|
|
1511
|
+
class be {
|
|
1454
1512
|
constructor(e, t) {
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1513
|
+
l(this, "host");
|
|
1514
|
+
l(this, "publicApiKey");
|
|
1515
|
+
l(this, "distinctId");
|
|
1516
|
+
l(this, "userToken");
|
|
1517
|
+
l(this, "vapidKey");
|
|
1518
|
+
l(this, "swFileName");
|
|
1519
|
+
l(this, "clientUserAgent");
|
|
1520
|
+
l(this, "userAgent");
|
|
1521
|
+
l(this, "apiClient", null);
|
|
1522
|
+
l(this, "userTokenExpirationTimer", null);
|
|
1523
|
+
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());
|
|
1468
1528
|
if (!e)
|
|
1469
1529
|
throw new Error("[SuprSend]: publicApiKey is missing");
|
|
1470
|
-
this.publicApiKey = e, this.host = (t == null ? void 0 : t.host) ||
|
|
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(
|
|
1531
|
+
t == null ? void 0 : t.appInfo,
|
|
1532
|
+
t == null ? void 0 : t.clientUserAgent
|
|
1533
|
+
), this.userAgent = oe(this.clientUserAgent);
|
|
1471
1534
|
}
|
|
1472
1535
|
handleRefreshUserToken(e) {
|
|
1473
|
-
if (!this.userToken || !
|
|
1474
|
-
const t =
|
|
1536
|
+
if (!this.userToken || !N()) return;
|
|
1537
|
+
const t = L(this.userToken), s = (t.exp || 0) * 1e3, r = Date.now(), n = 1e3 * 30;
|
|
1475
1538
|
if (s && s > r) {
|
|
1476
|
-
const
|
|
1539
|
+
const c = s - r - n;
|
|
1477
1540
|
this.userTokenExpirationTimer && clearTimeout(this.userTokenExpirationTimer), this.userTokenExpirationTimer = setTimeout(async () => {
|
|
1478
1541
|
let u = "";
|
|
1479
1542
|
try {
|
|
@@ -1492,13 +1555,13 @@ class pe {
|
|
|
1492
1555
|
}
|
|
1493
1556
|
}
|
|
1494
1557
|
u && typeof u == "string" && this.identify(this.distinctId, u, this.authenticateOptions);
|
|
1495
|
-
},
|
|
1558
|
+
}, c);
|
|
1496
1559
|
}
|
|
1497
1560
|
}
|
|
1498
1561
|
client() {
|
|
1499
1562
|
return this.distinctId || console.warn(
|
|
1500
1563
|
"[SuprSend]: distinctId is missing. User should be authenticated"
|
|
1501
|
-
), this.apiClient || (this.apiClient = new
|
|
1564
|
+
), this.apiClient || (this.apiClient = new P(this)), this.apiClient;
|
|
1502
1565
|
}
|
|
1503
1566
|
eventApi(e) {
|
|
1504
1567
|
return this.client().request({
|
|
@@ -1514,35 +1577,35 @@ class pe {
|
|
|
1514
1577
|
async identify(e, t, s) {
|
|
1515
1578
|
if (!e)
|
|
1516
1579
|
return o({
|
|
1517
|
-
status:
|
|
1518
|
-
errorType:
|
|
1580
|
+
status: a.ERROR,
|
|
1581
|
+
errorType: d.VALIDATION_ERROR,
|
|
1519
1582
|
errorMessage: "distinctId is missing"
|
|
1520
1583
|
});
|
|
1521
1584
|
if (this.apiClient && this.distinctId && this.distinctId !== e)
|
|
1522
1585
|
return o({
|
|
1523
|
-
status:
|
|
1524
|
-
errorType:
|
|
1586
|
+
status: a.ERROR,
|
|
1587
|
+
errorType: d.VALIDATION_ERROR,
|
|
1525
1588
|
errorMessage: "User already loggedin, reset current user to login new user"
|
|
1526
1589
|
});
|
|
1527
1590
|
if (this.apiClient && this.distinctId === e && this.userToken !== t)
|
|
1528
|
-
return this.userToken = t, this.apiClient = new
|
|
1591
|
+
return this.userToken = t, this.apiClient = new P(this), s != null && s.refreshUserToken && this.handleRefreshUserToken(s.refreshUserToken), o({ status: a.SUCCESS });
|
|
1529
1592
|
if (this.distinctId && this.apiClient)
|
|
1530
|
-
return o({ status:
|
|
1531
|
-
this.distinctId = e, this.userToken = t, this.apiClient = new
|
|
1532
|
-
const r =
|
|
1533
|
-
|
|
1593
|
+
return o({ status: a.SUCCESS });
|
|
1594
|
+
this.distinctId = e, this.userToken = t, this.apiClient = new P(this), this.authenticateOptions = s;
|
|
1595
|
+
const r = j(
|
|
1596
|
+
W
|
|
1534
1597
|
);
|
|
1535
1598
|
if (s != null && s.refreshUserToken && this.handleRefreshUserToken(s.refreshUserToken), r == this.distinctId)
|
|
1536
|
-
return this.webpush.updatePushSubscription(), o({ status:
|
|
1537
|
-
|
|
1599
|
+
return this.webpush.updatePushSubscription(), o({ status: a.SUCCESS });
|
|
1600
|
+
let n;
|
|
1601
|
+
return (s == null ? void 0 : s.createUser) !== !1 ? n = await this.eventApi({
|
|
1538
1602
|
event: "$identify",
|
|
1539
|
-
$insert_id:
|
|
1540
|
-
$time:
|
|
1603
|
+
$insert_id: D(),
|
|
1604
|
+
$time: M(),
|
|
1541
1605
|
properties: {
|
|
1542
1606
|
$identified_id: e
|
|
1543
1607
|
}
|
|
1544
|
-
});
|
|
1545
|
-
return i.status === n.SUCCESS ? (this.webpush.updatePushSubscription(), L(F, this.distinctId)) : this.reset({ unsubscribePush: !1 }), i;
|
|
1608
|
+
}) : n = { status: a.SUCCESS }, n.status === a.SUCCESS ? (this.webpush.updatePushSubscription(), $(W, this.distinctId)) : this.reset({ unsubscribePush: !1 }), n;
|
|
1546
1609
|
}
|
|
1547
1610
|
/**
|
|
1548
1611
|
* Check's if SuprSend instance is authenticated. To check if userToken is also present pass true.
|
|
@@ -1557,13 +1620,13 @@ class pe {
|
|
|
1557
1620
|
let s = {};
|
|
1558
1621
|
return e ? (typeof t == "object" && (s = { ...s, ...t }), this.eventApi({
|
|
1559
1622
|
event: String(e),
|
|
1560
|
-
$insert_id:
|
|
1561
|
-
$time:
|
|
1623
|
+
$insert_id: D(),
|
|
1624
|
+
$time: M(),
|
|
1562
1625
|
distinct_id: this.distinctId,
|
|
1563
1626
|
properties: s
|
|
1564
1627
|
})) : o({
|
|
1565
|
-
status:
|
|
1566
|
-
errorType:
|
|
1628
|
+
status: a.ERROR,
|
|
1629
|
+
errorType: d.VALIDATION_ERROR,
|
|
1567
1630
|
errorMessage: "event name is missing"
|
|
1568
1631
|
});
|
|
1569
1632
|
}
|
|
@@ -1572,16 +1635,16 @@ class pe {
|
|
|
1572
1635
|
*/
|
|
1573
1636
|
async reset(e) {
|
|
1574
1637
|
var s, r;
|
|
1575
|
-
return (e == null ? void 0 : e.unsubscribePush) !== !1 && (await ((s = this.webpush) == null ? void 0 : s.removePushSubscription()),
|
|
1638
|
+
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 });
|
|
1576
1639
|
}
|
|
1577
1640
|
}
|
|
1578
1641
|
export {
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1642
|
+
S as ApiResponseStatus,
|
|
1643
|
+
w as ChannelLevelPreferenceOptions,
|
|
1644
|
+
d as ERROR_TYPE,
|
|
1645
|
+
Oe as Feed,
|
|
1583
1646
|
p as PreferenceOptions,
|
|
1584
|
-
|
|
1585
|
-
|
|
1647
|
+
a as RESPONSE_STATUS,
|
|
1648
|
+
be as SuprSend
|
|
1586
1649
|
};
|
|
1587
1650
|
//# sourceMappingURL=index.js.map
|