@suprsend/web-sdk 4.1.1 → 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 +402 -336
- 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/preferences.d.ts +6 -2
- 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));
|
|
59
60
|
}
|
|
60
|
-
function
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
function $(i, e) {
|
|
62
|
+
V() && (typeof e == "object" && (e = JSON.stringify(e)), localStorage.setItem(i, e));
|
|
63
|
+
}
|
|
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 || "";
|
|
72
79
|
}
|
|
73
|
-
|
|
74
|
-
|
|
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: "" };
|
|
89
|
+
}
|
|
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" : "";
|
|
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(),
|
|
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);
|
|
75
129
|
return Array.from(new Uint8Array(s)).map((c) => c.toString(16).padStart(2, "0")).join("");
|
|
76
130
|
}
|
|
77
|
-
class
|
|
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:
|
|
186
|
+
status: a.ERROR,
|
|
129
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
|
|
191
|
+
const n = L(this.config.userToken), c = (n.exp || 0) * 1e3, u = Date.now();
|
|
134
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
210
|
body: c,
|
|
153
|
-
statusCode:
|
|
211
|
+
statusCode: n.status,
|
|
154
212
|
errorMessage: (s = c == null ? void 0 : c.error) == null ? void 0 : s.message,
|
|
155
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: (
|
|
219
|
+
errorMessage: (n == null ? void 0 : n.message) || "network error",
|
|
162
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,7 +295,7 @@ class q {
|
|
|
237
295
|
async getCategory(e, t) {
|
|
238
296
|
if (!e)
|
|
239
297
|
return o({
|
|
240
|
-
status:
|
|
298
|
+
status: a.ERROR,
|
|
241
299
|
errorType: d.VALIDATION_ERROR,
|
|
242
300
|
errorMessage: "Category parameter is missing"
|
|
243
301
|
});
|
|
@@ -251,73 +309,73 @@ class q {
|
|
|
251
309
|
/**
|
|
252
310
|
* Used to get user's all channel level preference.
|
|
253
311
|
*/
|
|
254
|
-
async getOverallChannelPreferences() {
|
|
255
|
-
const e = this.getUrl("channel_preference");
|
|
256
|
-
return await this.config.client().request({ type: "get", url:
|
|
312
|
+
async getOverallChannelPreferences(e) {
|
|
313
|
+
const t = { tenant_id: e == null ? void 0 : e.tenantId }, s = this.getUrl("channel_preference", t);
|
|
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
322
|
return c != null && c.error ? this.config.emitter.emit("preferences_error", c) : (Object.assign(s, c.body), this.config.emitter.emit("preferences_updated", {
|
|
265
|
-
status:
|
|
323
|
+
status: a.SUCCESS,
|
|
266
324
|
statusCode: 200,
|
|
267
325
|
body: this.data
|
|
268
326
|
})), c;
|
|
269
327
|
}
|
|
270
|
-
async _updateChannelPreferences(e) {
|
|
271
|
-
const
|
|
328
|
+
async _updateChannelPreferences(e, t) {
|
|
329
|
+
const s = this.getUrl("channel_preference", t), r = await this.config.client().request({
|
|
272
330
|
type: "patch",
|
|
273
|
-
url:
|
|
331
|
+
url: s,
|
|
274
332
|
payload: e
|
|
275
333
|
});
|
|
276
|
-
return
|
|
277
|
-
status:
|
|
334
|
+
return r != null && r.error ? this.config.emitter.emit("preferences_error", r) : (await this.getPreferences(this.preferenceArgs), this.config.emitter.emit("preferences_updated", {
|
|
335
|
+
status: a.SUCCESS,
|
|
278
336
|
statusCode: 200,
|
|
279
337
|
body: this.data
|
|
280
|
-
})),
|
|
338
|
+
})), r;
|
|
281
339
|
}
|
|
282
340
|
/**
|
|
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:
|
|
349
|
+
status: a.ERROR,
|
|
292
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:
|
|
355
|
+
status: a.ERROR,
|
|
298
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:
|
|
361
|
+
status: a.ERROR,
|
|
304
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
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:
|
|
378
|
+
status: a.ERROR,
|
|
321
379
|
errorType: d.VALIDATION_ERROR,
|
|
322
380
|
errorMessage: "Category preference is not editable"
|
|
323
381
|
});
|
|
@@ -326,13 +384,13 @@ class q {
|
|
|
326
384
|
}
|
|
327
385
|
if (!r)
|
|
328
386
|
return o({
|
|
329
|
-
status:
|
|
387
|
+
status: a.ERROR,
|
|
330
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
396
|
const c = [];
|
|
@@ -340,24 +398,24 @@ class q {
|
|
|
340
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
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
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,10 +423,10 @@ 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, g, R, y,
|
|
426
|
+
var T, g, R, y, m;
|
|
369
427
|
if (!e || !s)
|
|
370
428
|
return o({
|
|
371
|
-
status:
|
|
429
|
+
status: a.ERROR,
|
|
372
430
|
errorType: d.VALIDATION_ERROR,
|
|
373
431
|
errorMessage: e ? "Category parameter is missing" : "Channel parameter is missing"
|
|
374
432
|
});
|
|
@@ -376,144 +434,147 @@ class q {
|
|
|
376
434
|
t
|
|
377
435
|
))
|
|
378
436
|
return o({
|
|
379
|
-
status:
|
|
437
|
+
status: a.ERROR,
|
|
380
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:
|
|
443
|
+
status: a.ERROR,
|
|
386
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:
|
|
449
|
+
status: a.ERROR,
|
|
392
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 (c =
|
|
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:
|
|
469
|
+
status: a.ERROR,
|
|
412
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:
|
|
481
|
+
status: a.ERROR,
|
|
424
482
|
errorType: d.VALIDATION_ERROR,
|
|
425
483
|
errorMessage: "Category not found"
|
|
426
484
|
});
|
|
427
485
|
if (!c)
|
|
428
486
|
return o({
|
|
429
|
-
status:
|
|
487
|
+
status: a.ERROR,
|
|
430
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
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);
|
|
444
|
-
const
|
|
445
|
-
preference: h &&
|
|
446
|
-
opt_out_channels:
|
|
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
514
|
tags: (r == null ? void 0 : r.tags) || ((y = this.preferenceArgs) == null ? void 0 : y.tags),
|
|
457
|
-
locale: (r == null ? void 0 : r.locale) || ((
|
|
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
|
}
|
|
464
522
|
/**
|
|
465
523
|
* Used to update user's channel level preference.
|
|
466
524
|
*/
|
|
467
|
-
async updateOverallChannelPreference(e, t) {
|
|
525
|
+
async updateOverallChannelPreference(e, t, s) {
|
|
526
|
+
var u;
|
|
468
527
|
if (!e || ![
|
|
469
|
-
|
|
470
|
-
|
|
528
|
+
w.ALL,
|
|
529
|
+
w.REQUIRED
|
|
471
530
|
].includes(t))
|
|
472
531
|
return o({
|
|
473
|
-
status:
|
|
532
|
+
status: a.ERROR,
|
|
474
533
|
errorType: d.VALIDATION_ERROR,
|
|
475
534
|
errorMessage: e ? "Preference parameter is invalid" : "Channel parameter is missing"
|
|
476
535
|
});
|
|
477
536
|
if (!this.data)
|
|
478
537
|
return o({
|
|
479
|
-
status:
|
|
538
|
+
status: a.ERROR,
|
|
480
539
|
errorType: d.VALIDATION_ERROR,
|
|
481
540
|
errorMessage: "Call getPreferences method before performing action"
|
|
482
541
|
});
|
|
483
542
|
if (!this.data.channel_preferences)
|
|
484
543
|
return o({
|
|
485
|
-
status:
|
|
544
|
+
status: a.ERROR,
|
|
486
545
|
errorType: d.VALIDATION_ERROR,
|
|
487
546
|
errorMessage: "Channel preferences doesn't exist"
|
|
488
547
|
});
|
|
489
|
-
let
|
|
490
|
-
const
|
|
491
|
-
for (const
|
|
492
|
-
if (
|
|
493
|
-
|
|
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;
|
|
494
553
|
break;
|
|
495
554
|
}
|
|
496
|
-
return
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
555
|
+
return r ? n ? (this.debouncedUpdateChannelPreferences(
|
|
556
|
+
r.channel,
|
|
557
|
+
{ channel_preferences: [r] },
|
|
558
|
+
{ tenant_id: (s == null ? void 0 : s.tenantId) || ((u = this.preferenceArgs) == null ? void 0 : u.tenantId) }
|
|
559
|
+
), o({
|
|
560
|
+
status: a.SUCCESS,
|
|
500
561
|
body: this.data
|
|
501
562
|
})) : o({
|
|
502
|
-
status:
|
|
563
|
+
status: a.SUCCESS,
|
|
503
564
|
body: this.data
|
|
504
565
|
}) : o({
|
|
505
|
-
status:
|
|
566
|
+
status: a.ERROR,
|
|
506
567
|
errorType: d.VALIDATION_ERROR,
|
|
507
568
|
errorMessage: "Channel data not found"
|
|
508
569
|
});
|
|
509
570
|
}
|
|
510
571
|
}
|
|
511
|
-
const
|
|
512
|
-
class
|
|
572
|
+
const K = "ss_device_id";
|
|
573
|
+
class ue {
|
|
513
574
|
constructor(e) {
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
this.config = e, this.preferences = new
|
|
575
|
+
l(this, "config");
|
|
576
|
+
l(this, "preferences");
|
|
577
|
+
this.config = e, this.preferences = new de(e);
|
|
517
578
|
}
|
|
518
579
|
isReservedKey(e) {
|
|
519
580
|
var t;
|
|
@@ -528,7 +589,7 @@ class ee {
|
|
|
528
589
|
return Array.isArray(e) ? e : [e];
|
|
529
590
|
}
|
|
530
591
|
validateObjData(e, t) {
|
|
531
|
-
const s = {}, r = (t == null ? void 0 : t.allowReservedKeys) || !1,
|
|
592
|
+
const s = {}, r = (t == null ? void 0 : t.allowReservedKeys) || !1, n = (t == null ? void 0 : t.valueType) || "";
|
|
532
593
|
for (const c in e) {
|
|
533
594
|
let u = e[c];
|
|
534
595
|
if (!(c && u === void 0)) {
|
|
@@ -536,7 +597,7 @@ class ee {
|
|
|
536
597
|
console.warn("[SuprSend]: key cannot start with $ or ss_");
|
|
537
598
|
continue;
|
|
538
599
|
}
|
|
539
|
-
|
|
600
|
+
n === "number" ? u = Number(u) : n === "boolean" && (u = !!u), s[c] = u;
|
|
540
601
|
}
|
|
541
602
|
}
|
|
542
603
|
return s;
|
|
@@ -556,8 +617,8 @@ class ee {
|
|
|
556
617
|
async triggerUserEvent(e) {
|
|
557
618
|
return this.config.eventApi({
|
|
558
619
|
distinct_id: this.config.distinctId,
|
|
559
|
-
$insert_id:
|
|
560
|
-
$time:
|
|
620
|
+
$insert_id: D(),
|
|
621
|
+
$time: M(),
|
|
561
622
|
...e
|
|
562
623
|
});
|
|
563
624
|
}
|
|
@@ -568,13 +629,13 @@ class ee {
|
|
|
568
629
|
const s = this.formatParamsToObj(e, t);
|
|
569
630
|
if (!s)
|
|
570
631
|
return o({
|
|
571
|
-
status:
|
|
632
|
+
status: a.ERROR,
|
|
572
633
|
errorType: d.VALIDATION_ERROR,
|
|
573
634
|
errorMessage: "data provided is empty"
|
|
574
635
|
});
|
|
575
636
|
const r = this.validateObjData(s);
|
|
576
637
|
return I(r) ? o({
|
|
577
|
-
status:
|
|
638
|
+
status: a.ERROR,
|
|
578
639
|
errorType: d.VALIDATION_ERROR,
|
|
579
640
|
errorMessage: "data provided is empty"
|
|
580
641
|
}) : this.triggerUserEvent({ $set: r });
|
|
@@ -587,13 +648,13 @@ class ee {
|
|
|
587
648
|
const s = this.formatParamsToObj(e, t);
|
|
588
649
|
if (!s)
|
|
589
650
|
return o({
|
|
590
|
-
status:
|
|
651
|
+
status: a.ERROR,
|
|
591
652
|
errorType: d.VALIDATION_ERROR,
|
|
592
653
|
errorMessage: "data provided is empty"
|
|
593
654
|
});
|
|
594
655
|
const r = this.validateObjData(s);
|
|
595
656
|
return I(r) ? o({
|
|
596
|
-
status:
|
|
657
|
+
status: a.ERROR,
|
|
597
658
|
errorType: d.VALIDATION_ERROR,
|
|
598
659
|
errorMessage: "data provided is empty"
|
|
599
660
|
}) : this.triggerUserEvent({ $set_once: r });
|
|
@@ -606,13 +667,13 @@ class ee {
|
|
|
606
667
|
const s = this.formatParamsToObj(e, t);
|
|
607
668
|
if (!s)
|
|
608
669
|
return o({
|
|
609
|
-
status:
|
|
670
|
+
status: a.ERROR,
|
|
610
671
|
errorType: d.VALIDATION_ERROR,
|
|
611
672
|
errorMessage: "data provided is empty"
|
|
612
673
|
});
|
|
613
674
|
const r = this.validateObjData(s, { valueType: "number" });
|
|
614
675
|
return I(r) ? o({
|
|
615
|
-
status:
|
|
676
|
+
status: a.ERROR,
|
|
616
677
|
errorType: d.VALIDATION_ERROR,
|
|
617
678
|
errorMessage: "data provided is empty"
|
|
618
679
|
}) : this.triggerUserEvent({ $add: r });
|
|
@@ -625,13 +686,13 @@ class ee {
|
|
|
625
686
|
const s = this.formatParamsToObj(e, t);
|
|
626
687
|
if (!s)
|
|
627
688
|
return o({
|
|
628
|
-
status:
|
|
689
|
+
status: a.ERROR,
|
|
629
690
|
errorType: d.VALIDATION_ERROR,
|
|
630
691
|
errorMessage: "data provided is empty"
|
|
631
692
|
});
|
|
632
693
|
const r = this.validateObjData(s);
|
|
633
694
|
return I(r) ? o({
|
|
634
|
-
status:
|
|
695
|
+
status: a.ERROR,
|
|
635
696
|
errorType: d.VALIDATION_ERROR,
|
|
636
697
|
errorMessage: "data provided is empty"
|
|
637
698
|
}) : this.triggerUserEvent({ $append: r });
|
|
@@ -644,13 +705,13 @@ class ee {
|
|
|
644
705
|
const s = this.formatParamsToObj(e, t);
|
|
645
706
|
if (!s)
|
|
646
707
|
return o({
|
|
647
|
-
status:
|
|
708
|
+
status: a.ERROR,
|
|
648
709
|
errorType: d.VALIDATION_ERROR,
|
|
649
710
|
errorMessage: "data provided is empty"
|
|
650
711
|
});
|
|
651
712
|
const r = this.validateObjData(s);
|
|
652
713
|
return I(r) ? o({
|
|
653
|
-
status:
|
|
714
|
+
status: a.ERROR,
|
|
654
715
|
errorType: d.VALIDATION_ERROR,
|
|
655
716
|
errorMessage: "data provided is empty"
|
|
656
717
|
}) : this.triggerUserEvent({ $remove: r });
|
|
@@ -662,13 +723,13 @@ class ee {
|
|
|
662
723
|
const t = this.formatParamsToArray(e);
|
|
663
724
|
if (!t)
|
|
664
725
|
return o({
|
|
665
|
-
status:
|
|
726
|
+
status: a.ERROR,
|
|
666
727
|
errorType: d.VALIDATION_ERROR,
|
|
667
728
|
errorMessage: "data provided is empty"
|
|
668
729
|
});
|
|
669
730
|
const s = this.validateArrayData(t);
|
|
670
|
-
return
|
|
671
|
-
status:
|
|
731
|
+
return Y(s) ? o({
|
|
732
|
+
status: a.ERROR,
|
|
672
733
|
errorType: d.VALIDATION_ERROR,
|
|
673
734
|
errorMessage: "data provided is empty"
|
|
674
735
|
}) : this.triggerUserEvent({ $unset: s });
|
|
@@ -678,7 +739,7 @@ class ee {
|
|
|
678
739
|
const s = this.formatParamsToObj(e, t);
|
|
679
740
|
if (!s)
|
|
680
741
|
return o({
|
|
681
|
-
status:
|
|
742
|
+
status: a.ERROR,
|
|
682
743
|
errorType: d.VALIDATION_ERROR,
|
|
683
744
|
errorMessage: "data provided is empty"
|
|
684
745
|
});
|
|
@@ -686,7 +747,7 @@ class ee {
|
|
|
686
747
|
allowReservedKeys: !0
|
|
687
748
|
});
|
|
688
749
|
return I(r) ? o({
|
|
689
|
-
status:
|
|
750
|
+
status: a.ERROR,
|
|
690
751
|
errorType: d.VALIDATION_ERROR,
|
|
691
752
|
errorMessage: "data provided is empty"
|
|
692
753
|
}) : this.triggerUserEvent({ $append: r });
|
|
@@ -696,7 +757,7 @@ class ee {
|
|
|
696
757
|
const s = this.formatParamsToObj(e, t);
|
|
697
758
|
if (!s)
|
|
698
759
|
return o({
|
|
699
|
-
status:
|
|
760
|
+
status: a.ERROR,
|
|
700
761
|
errorType: d.VALIDATION_ERROR,
|
|
701
762
|
errorMessage: "data provided is empty"
|
|
702
763
|
});
|
|
@@ -704,7 +765,7 @@ class ee {
|
|
|
704
765
|
allowReservedKeys: !0
|
|
705
766
|
});
|
|
706
767
|
return I(r) ? o({
|
|
707
|
-
status:
|
|
768
|
+
status: a.ERROR,
|
|
708
769
|
errorType: d.VALIDATION_ERROR,
|
|
709
770
|
errorMessage: "data provided is empty"
|
|
710
771
|
}) : this.triggerUserEvent({ $remove: r });
|
|
@@ -713,7 +774,7 @@ class ee {
|
|
|
713
774
|
const s = this.formatParamsToObj(e, t);
|
|
714
775
|
if (!s)
|
|
715
776
|
return o({
|
|
716
|
-
status:
|
|
777
|
+
status: a.ERROR,
|
|
717
778
|
errorType: d.VALIDATION_ERROR,
|
|
718
779
|
errorMessage: "data provided is empty"
|
|
719
780
|
});
|
|
@@ -721,7 +782,7 @@ class ee {
|
|
|
721
782
|
allowReservedKeys: !0
|
|
722
783
|
});
|
|
723
784
|
return I(r) ? o({
|
|
724
|
-
status:
|
|
785
|
+
status: a.ERROR,
|
|
725
786
|
errorType: d.VALIDATION_ERROR,
|
|
726
787
|
errorMessage: "data provided is empty"
|
|
727
788
|
}) : this.triggerUserEvent({ $set: r });
|
|
@@ -734,14 +795,14 @@ class ee {
|
|
|
734
795
|
}
|
|
735
796
|
async addEmail(e) {
|
|
736
797
|
return this.validateEmail(e) ? this.appendInternal({ $email: e }) : o({
|
|
737
|
-
status:
|
|
798
|
+
status: a.ERROR,
|
|
738
799
|
errorType: d.VALIDATION_ERROR,
|
|
739
800
|
errorMessage: "provided email is invalid"
|
|
740
801
|
});
|
|
741
802
|
}
|
|
742
803
|
async removeEmail(e) {
|
|
743
804
|
return this.validateEmail(e) ? this.removeInternal({ $email: e }) : o({
|
|
744
|
-
status:
|
|
805
|
+
status: a.ERROR,
|
|
745
806
|
errorType: d.VALIDATION_ERROR,
|
|
746
807
|
errorMessage: "provided email is invalid"
|
|
747
808
|
});
|
|
@@ -751,7 +812,7 @@ class ee {
|
|
|
751
812
|
*/
|
|
752
813
|
async addSms(e) {
|
|
753
814
|
return this.validateMobile(e) ? this.appendInternal({ $sms: e }) : o({
|
|
754
|
-
status:
|
|
815
|
+
status: a.ERROR,
|
|
755
816
|
errorType: d.VALIDATION_ERROR,
|
|
756
817
|
errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
|
|
757
818
|
});
|
|
@@ -761,7 +822,7 @@ class ee {
|
|
|
761
822
|
*/
|
|
762
823
|
async removeSms(e) {
|
|
763
824
|
return this.validateMobile(e) ? this.removeInternal({ $sms: e }) : o({
|
|
764
|
-
status:
|
|
825
|
+
status: a.ERROR,
|
|
765
826
|
errorType: d.VALIDATION_ERROR,
|
|
766
827
|
errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
|
|
767
828
|
});
|
|
@@ -771,7 +832,7 @@ class ee {
|
|
|
771
832
|
*/
|
|
772
833
|
async addWhatsapp(e) {
|
|
773
834
|
return this.validateMobile(e) ? this.appendInternal({ $whatsapp: e }) : o({
|
|
774
|
-
status:
|
|
835
|
+
status: a.ERROR,
|
|
775
836
|
errorType: d.VALIDATION_ERROR,
|
|
776
837
|
errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
|
|
777
838
|
});
|
|
@@ -781,19 +842,19 @@ class ee {
|
|
|
781
842
|
*/
|
|
782
843
|
async removeWhatsapp(e) {
|
|
783
844
|
return this.validateMobile(e) ? this.removeInternal({ $whatsapp: e }) : o({
|
|
784
|
-
status:
|
|
845
|
+
status: a.ERROR,
|
|
785
846
|
errorType: d.VALIDATION_ERROR,
|
|
786
847
|
errorMessage: "provided mobile number is invalid, must be as per E.164 standard"
|
|
787
848
|
});
|
|
788
849
|
}
|
|
789
850
|
getDeviceId() {
|
|
790
|
-
let e =
|
|
791
|
-
return e || (e =
|
|
851
|
+
let e = j(K);
|
|
852
|
+
return e || (e = D(), $(K, e)), e;
|
|
792
853
|
}
|
|
793
854
|
async addWebPush(e) {
|
|
794
855
|
if (typeof e != "object")
|
|
795
856
|
return o({
|
|
796
|
-
status:
|
|
857
|
+
status: a.ERROR,
|
|
797
858
|
errorType: d.VALIDATION_ERROR,
|
|
798
859
|
errorMessage: "provided push subscription is invalid, must be an object"
|
|
799
860
|
});
|
|
@@ -807,7 +868,7 @@ class ee {
|
|
|
807
868
|
async removeWebPush(e) {
|
|
808
869
|
if (typeof e != "object")
|
|
809
870
|
return o({
|
|
810
|
-
status:
|
|
871
|
+
status: a.ERROR,
|
|
811
872
|
errorType: d.VALIDATION_ERROR,
|
|
812
873
|
errorMessage: "provided push subscription is invalid, must be an object"
|
|
813
874
|
});
|
|
@@ -820,28 +881,28 @@ class ee {
|
|
|
820
881
|
}
|
|
821
882
|
async addSlack(e) {
|
|
822
883
|
return typeof e != "object" ? o({
|
|
823
|
-
status:
|
|
884
|
+
status: a.ERROR,
|
|
824
885
|
errorType: d.VALIDATION_ERROR,
|
|
825
886
|
errorMessage: "provided slack data is invalid, must be an object"
|
|
826
887
|
}) : this.appendInternal({ $slack: e });
|
|
827
888
|
}
|
|
828
889
|
async removeSlack(e) {
|
|
829
890
|
return typeof e != "object" ? o({
|
|
830
|
-
status:
|
|
891
|
+
status: a.ERROR,
|
|
831
892
|
errorType: d.VALIDATION_ERROR,
|
|
832
893
|
errorMessage: "provided slack data is invalid, must be an object"
|
|
833
894
|
}) : this.removeInternal({ $slack: e });
|
|
834
895
|
}
|
|
835
896
|
async addMSTeams(e) {
|
|
836
897
|
return typeof e != "object" ? o({
|
|
837
|
-
status:
|
|
898
|
+
status: a.ERROR,
|
|
838
899
|
errorType: d.VALIDATION_ERROR,
|
|
839
900
|
errorMessage: "provided ms_teams data is invalid, must be object"
|
|
840
901
|
}) : this.appendInternal({ $ms_teams: e });
|
|
841
902
|
}
|
|
842
903
|
async removeMSTeams(e) {
|
|
843
904
|
return typeof e != "object" ? o({
|
|
844
|
-
status:
|
|
905
|
+
status: a.ERROR,
|
|
845
906
|
errorType: d.VALIDATION_ERROR,
|
|
846
907
|
errorMessage: "provided ms_teams data is invalid, must be object"
|
|
847
908
|
}) : this.removeInternal({ $ms_teams: e });
|
|
@@ -852,7 +913,7 @@ class ee {
|
|
|
852
913
|
*/
|
|
853
914
|
async setPreferredLanguage(e) {
|
|
854
915
|
return typeof e != "string" ? o({
|
|
855
|
-
status:
|
|
916
|
+
status: a.ERROR,
|
|
856
917
|
errorType: d.VALIDATION_ERROR,
|
|
857
918
|
errorMessage: "provided language is invalid, must be string"
|
|
858
919
|
}) : this.setInternal({ $preferred_language: e });
|
|
@@ -862,20 +923,20 @@ class ee {
|
|
|
862
923
|
*/
|
|
863
924
|
async setTimezone(e) {
|
|
864
925
|
return typeof e != "string" ? o({
|
|
865
|
-
status:
|
|
926
|
+
status: a.ERROR,
|
|
866
927
|
errorType: d.VALIDATION_ERROR,
|
|
867
928
|
errorMessage: "provided timezone is invalid, must be string"
|
|
868
929
|
}) : this.setInternal({ $timezone: e });
|
|
869
930
|
}
|
|
870
931
|
}
|
|
871
|
-
const
|
|
872
|
-
class
|
|
932
|
+
const x = "ss_wp_hash";
|
|
933
|
+
class he {
|
|
873
934
|
constructor(e) {
|
|
874
|
-
|
|
935
|
+
l(this, "config");
|
|
875
936
|
this.config = e;
|
|
876
937
|
}
|
|
877
938
|
async getPushSubscription() {
|
|
878
|
-
if (!
|
|
939
|
+
if (!N()) return;
|
|
879
940
|
const e = await navigator.serviceWorker.getRegistration();
|
|
880
941
|
if (!e) return;
|
|
881
942
|
const t = e.pushManager.getSubscription();
|
|
@@ -886,13 +947,13 @@ class te {
|
|
|
886
947
|
const t = e.endpoint;
|
|
887
948
|
let s = null;
|
|
888
949
|
try {
|
|
889
|
-
s = await
|
|
950
|
+
s = await ce(t);
|
|
890
951
|
} catch {
|
|
891
952
|
}
|
|
892
953
|
if (s) {
|
|
893
|
-
if (s ===
|
|
894
|
-
return o({ status:
|
|
895
|
-
|
|
954
|
+
if (s === j(x))
|
|
955
|
+
return o({ status: a.SUCCESS });
|
|
956
|
+
$(x, s);
|
|
896
957
|
}
|
|
897
958
|
return await this.config.user.addWebPush(e);
|
|
898
959
|
}
|
|
@@ -900,7 +961,7 @@ class te {
|
|
|
900
961
|
try {
|
|
901
962
|
if (await navigator.serviceWorker.register(`/${this.config.swFileName}`), await Notification.requestPermission() !== "granted")
|
|
902
963
|
return console.warn("[SuprSend]: Notification permission isnt granted"), o({
|
|
903
|
-
status:
|
|
964
|
+
status: a.ERROR,
|
|
904
965
|
errorType: d.PERMISSION_DENIED,
|
|
905
966
|
errorMessage: "Notification permission isn't granted"
|
|
906
967
|
});
|
|
@@ -911,18 +972,18 @@ class te {
|
|
|
911
972
|
return console.warn(
|
|
912
973
|
"[SuprSend]: Vapid key is missing. Add it while creating SuprSend instance"
|
|
913
974
|
), o({
|
|
914
|
-
status:
|
|
975
|
+
status: a.ERROR,
|
|
915
976
|
errorType: d.VALIDATION_ERROR,
|
|
916
977
|
errorMessage: "Vapid key is missing. Add it while creating SuprSend instance"
|
|
917
978
|
});
|
|
918
979
|
const r = await t.pushManager.subscribe({
|
|
919
980
|
userVisibleOnly: !0,
|
|
920
|
-
applicationServerKey:
|
|
981
|
+
applicationServerKey: q(this.config.vapidKey)
|
|
921
982
|
});
|
|
922
983
|
return this.checkAndUpdateOnServer(r);
|
|
923
984
|
} catch (e) {
|
|
924
985
|
return console.warn("SuprSend: Error getting push subscription", e), o({
|
|
925
|
-
status:
|
|
986
|
+
status: a.ERROR,
|
|
926
987
|
errorType: d.UNKNOWN_ERROR,
|
|
927
988
|
errorMessage: (e == null ? void 0 : e.message) || "Unknown error occured while registering for push"
|
|
928
989
|
});
|
|
@@ -935,8 +996,8 @@ class te {
|
|
|
935
996
|
* 3. Send webpush token to SuprSend.
|
|
936
997
|
*/
|
|
937
998
|
async registerPush() {
|
|
938
|
-
return
|
|
939
|
-
status:
|
|
999
|
+
return N() && "serviceWorker" in navigator && "PushManager" in window ? this.handleRegisterPush() : (console.warn("[SuprSend]: Webpush isn't supported"), o({
|
|
1000
|
+
status: a.ERROR,
|
|
940
1001
|
errorType: d.UNSUPPORTED_ACTION,
|
|
941
1002
|
errorMessage: "Webpush isn't supported"
|
|
942
1003
|
}));
|
|
@@ -964,37 +1025,37 @@ class te {
|
|
|
964
1025
|
return !!await this.getPushSubscription();
|
|
965
1026
|
}
|
|
966
1027
|
}
|
|
967
|
-
const
|
|
1028
|
+
const z = 20, fe = "default", le = 100, C = {
|
|
968
1029
|
storeId: "$suprsend_default_store",
|
|
969
1030
|
label: ""
|
|
970
|
-
},
|
|
971
|
-
tenantId:
|
|
972
|
-
pageSize:
|
|
1031
|
+
}, pe = {
|
|
1032
|
+
tenantId: fe,
|
|
1033
|
+
pageSize: z,
|
|
973
1034
|
stores: null,
|
|
974
1035
|
host: {
|
|
975
1036
|
apiHost: "https://inboxs.live",
|
|
976
1037
|
socketHost: "https://betainbox.suprsend.com"
|
|
977
1038
|
}
|
|
978
|
-
},
|
|
1039
|
+
}, k = {
|
|
979
1040
|
notifications: [],
|
|
980
|
-
store:
|
|
1041
|
+
store: C,
|
|
981
1042
|
pageInfo: {
|
|
982
1043
|
total: 0,
|
|
983
|
-
pageSize:
|
|
1044
|
+
pageSize: z,
|
|
984
1045
|
hasMore: !1
|
|
985
1046
|
},
|
|
986
1047
|
meta: { badge: 0 },
|
|
987
|
-
apiStatus:
|
|
1048
|
+
apiStatus: S.INITIAL,
|
|
988
1049
|
isFirstFetch: !0
|
|
989
1050
|
};
|
|
990
|
-
class
|
|
1051
|
+
class Re {
|
|
991
1052
|
constructor(e) {
|
|
992
|
-
|
|
993
|
-
|
|
1053
|
+
l(this, "config");
|
|
1054
|
+
l(this, "feedInstances", []);
|
|
994
1055
|
this.config = e;
|
|
995
1056
|
}
|
|
996
1057
|
initialize(e = {}) {
|
|
997
|
-
const t = new
|
|
1058
|
+
const t = new Oe(this.config, e);
|
|
998
1059
|
return this.feedInstances.push(t), t;
|
|
999
1060
|
}
|
|
1000
1061
|
removeInstance(e) {
|
|
@@ -1008,19 +1069,19 @@ class ne {
|
|
|
1008
1069
|
this.feedInstances = [];
|
|
1009
1070
|
}
|
|
1010
1071
|
}
|
|
1011
|
-
class
|
|
1072
|
+
class Oe {
|
|
1012
1073
|
constructor(e, t) {
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
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());
|
|
1020
1081
|
this.config = e, this.setOptions(t), this.store = this.createFeedStore();
|
|
1021
1082
|
}
|
|
1022
1083
|
setOptions(e) {
|
|
1023
|
-
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();
|
|
1024
1085
|
}
|
|
1025
1086
|
validateStore() {
|
|
1026
1087
|
const e = this.feedOptions.stores;
|
|
@@ -1038,25 +1099,25 @@ class ae {
|
|
|
1038
1099
|
return;
|
|
1039
1100
|
}
|
|
1040
1101
|
const r = s == null ? void 0 : s.query;
|
|
1041
|
-
let
|
|
1042
|
-
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({
|
|
1043
1104
|
storeId: s.storeId,
|
|
1044
1105
|
label: s.label || s.storeId,
|
|
1045
1106
|
query: {
|
|
1046
1107
|
archived: c,
|
|
1047
|
-
read:
|
|
1108
|
+
read: n,
|
|
1048
1109
|
tags: u,
|
|
1049
|
-
categories:
|
|
1110
|
+
categories: f
|
|
1050
1111
|
}
|
|
1051
1112
|
});
|
|
1052
1113
|
}), this.feedOptions.stores = t;
|
|
1053
1114
|
}
|
|
1054
1115
|
createFeedStore() {
|
|
1055
|
-
return
|
|
1116
|
+
return G()(() => {
|
|
1056
1117
|
var e;
|
|
1057
1118
|
return {
|
|
1058
|
-
...
|
|
1059
|
-
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) ||
|
|
1119
|
+
...k,
|
|
1120
|
+
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) || C
|
|
1060
1121
|
};
|
|
1061
1122
|
});
|
|
1062
1123
|
}
|
|
@@ -1064,18 +1125,18 @@ class ae {
|
|
|
1064
1125
|
this.socket.on("connect_error", async (e) => {
|
|
1065
1126
|
var t;
|
|
1066
1127
|
if (e.message === "Authentication Error: wrong auth token" && ((t = this.config.authenticateOptions) != null && t.refreshUserToken) && this.config.userToken) {
|
|
1067
|
-
const s = this.socket.auth["x-ss-signature"], r =
|
|
1068
|
-
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)
|
|
1069
1130
|
try {
|
|
1070
|
-
const
|
|
1131
|
+
const f = await this.config.authenticateOptions.refreshUserToken(
|
|
1071
1132
|
this.config.userToken,
|
|
1072
1133
|
r
|
|
1073
1134
|
);
|
|
1074
|
-
|
|
1135
|
+
f && typeof f == "string" && (await this.config.identify(
|
|
1075
1136
|
this.config.distinctId,
|
|
1076
|
-
|
|
1137
|
+
f,
|
|
1077
1138
|
this.config.authenticateOptions
|
|
1078
|
-
), this.socket.auth["x-ss-signature"] =
|
|
1139
|
+
), this.socket.auth["x-ss-signature"] = f, setTimeout(() => {
|
|
1079
1140
|
this.socket.connect();
|
|
1080
1141
|
}, 1e3));
|
|
1081
1142
|
} catch {
|
|
@@ -1098,30 +1159,30 @@ class ae {
|
|
|
1098
1159
|
});
|
|
1099
1160
|
}
|
|
1100
1161
|
async handleNewNotificationSocketEvent(e) {
|
|
1101
|
-
var u,
|
|
1162
|
+
var u, f;
|
|
1102
1163
|
if (!e.n_id) return;
|
|
1103
1164
|
const t = await this.fetchDetails(e.n_id);
|
|
1104
|
-
if (t.status ===
|
|
1165
|
+
if (t.status === a.ERROR)
|
|
1105
1166
|
return;
|
|
1106
1167
|
const s = t.body, r = this.store.getState();
|
|
1107
|
-
let
|
|
1168
|
+
let n = !1;
|
|
1108
1169
|
const c = { ...r.meta };
|
|
1109
|
-
this.notificationBelongToStore(s, r.store) && (
|
|
1170
|
+
this.notificationBelongToStore(s, r.store) && (n = !0, this.store.setState({
|
|
1110
1171
|
notifications: this.orderNotificationsBasedOnPinFlag(
|
|
1111
1172
|
s,
|
|
1112
1173
|
r.notifications
|
|
1113
1174
|
)
|
|
1114
|
-
})), (
|
|
1115
|
-
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);
|
|
1116
1177
|
}), this.store.setState({
|
|
1117
1178
|
meta: {
|
|
1118
1179
|
...c,
|
|
1119
|
-
badge:
|
|
1180
|
+
badge: n ? c.badge + 1 : c.badge
|
|
1120
1181
|
}
|
|
1121
|
-
}),
|
|
1182
|
+
}), n && this.emitter.emit("feed.new_notification", s), this.emitter.emit("feed.store_update", this.data);
|
|
1122
1183
|
}
|
|
1123
1184
|
async handleNoticationUpdateSocketEvent(e) {
|
|
1124
|
-
var
|
|
1185
|
+
var f;
|
|
1125
1186
|
if (!e.n_id) return;
|
|
1126
1187
|
const t = await Promise.allSettled([
|
|
1127
1188
|
this.fetchDetails(e.n_id),
|
|
@@ -1129,23 +1190,23 @@ class ae {
|
|
|
1129
1190
|
]), s = this.store.getState();
|
|
1130
1191
|
if (t[0].status !== "fulfilled") return;
|
|
1131
1192
|
const r = t[0].value;
|
|
1132
|
-
if (r.status ===
|
|
1133
|
-
const
|
|
1134
|
-
(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
|
|
1135
1196
|
);
|
|
1136
1197
|
this.notificationBelongToStore(
|
|
1137
|
-
|
|
1198
|
+
n,
|
|
1138
1199
|
s.store
|
|
1139
1200
|
) ? c ? this.store.setState({
|
|
1140
|
-
notifications: s.notifications.map((h) => h.n_id ===
|
|
1201
|
+
notifications: s.notifications.map((h) => h.n_id === n.n_id ? n : h)
|
|
1141
1202
|
}) : this.store.setState({
|
|
1142
1203
|
notifications: this.orderNotificationsBasedOnPinFlag(
|
|
1143
|
-
|
|
1204
|
+
n,
|
|
1144
1205
|
s.notifications
|
|
1145
1206
|
)
|
|
1146
1207
|
}) : this.store.setState({
|
|
1147
1208
|
notifications: s.notifications.filter(
|
|
1148
|
-
(h) => h.n_id !==
|
|
1209
|
+
(h) => h.n_id !== n.n_id
|
|
1149
1210
|
)
|
|
1150
1211
|
}), this.emitter.emit("feed.store_update", this.data);
|
|
1151
1212
|
}
|
|
@@ -1164,12 +1225,12 @@ class ae {
|
|
|
1164
1225
|
}), this.emitter.emit("feed.store_update", this.data);
|
|
1165
1226
|
}
|
|
1166
1227
|
notificationBelongToStore(e, t) {
|
|
1167
|
-
var y,
|
|
1168
|
-
const s = !!e.read_on, r = e.archived,
|
|
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;
|
|
1169
1230
|
let g = !1, R = !1;
|
|
1170
|
-
return Array.isArray(h) && h.length > 0 ? h.forEach((
|
|
1171
|
-
|
|
1172
|
-
}) : g = !0, Array.isArray(
|
|
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;
|
|
1173
1234
|
}
|
|
1174
1235
|
orderNotificationsBasedOnPinFlag(e, t) {
|
|
1175
1236
|
if (e.is_pinned)
|
|
@@ -1177,8 +1238,8 @@ class ae {
|
|
|
1177
1238
|
{
|
|
1178
1239
|
let s = !1;
|
|
1179
1240
|
const r = [];
|
|
1180
|
-
return t.forEach((
|
|
1181
|
-
|
|
1241
|
+
return t.forEach((n) => {
|
|
1242
|
+
n.is_pinned || s ? r.push(n) : (r.push(e), r.push(n), s = !0);
|
|
1182
1243
|
}), s ? r : [...t, e];
|
|
1183
1244
|
}
|
|
1184
1245
|
}
|
|
@@ -1195,10 +1256,10 @@ class ae {
|
|
|
1195
1256
|
}
|
|
1196
1257
|
getUrl(e, t) {
|
|
1197
1258
|
var c;
|
|
1198
|
-
const s = `${(c = this.feedOptions.host) == null ? void 0 : c.apiHost}/v1/feed/${e}`, r = this.validateQueryParams(t),
|
|
1259
|
+
const s = `${(c = this.feedOptions.host) == null ? void 0 : c.apiHost}/v1/feed/${e}`, r = this.validateQueryParams(t), n = new URLSearchParams(
|
|
1199
1260
|
r
|
|
1200
1261
|
).toString();
|
|
1201
|
-
return
|
|
1262
|
+
return n ? `${s}?${n}` : s;
|
|
1202
1263
|
}
|
|
1203
1264
|
validateQueryParams(e = {}) {
|
|
1204
1265
|
const t = {};
|
|
@@ -1211,19 +1272,19 @@ class ae {
|
|
|
1211
1272
|
requestInprogress() {
|
|
1212
1273
|
const e = this.store.getState();
|
|
1213
1274
|
return [
|
|
1214
|
-
|
|
1215
|
-
|
|
1275
|
+
S.LOADING,
|
|
1276
|
+
S.FETCHING_MORE
|
|
1216
1277
|
].includes(e.apiStatus);
|
|
1217
1278
|
}
|
|
1218
1279
|
storesQueryParamObj(e) {
|
|
1219
1280
|
return e == null ? void 0 : e.map((s) => this.storeQueryParamObj(s));
|
|
1220
1281
|
}
|
|
1221
1282
|
storeQueryParamObj(e) {
|
|
1222
|
-
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;
|
|
1223
1284
|
return {
|
|
1224
1285
|
store_id: e.storeId,
|
|
1225
1286
|
query: {
|
|
1226
|
-
read:
|
|
1287
|
+
read: n,
|
|
1227
1288
|
archived: c,
|
|
1228
1289
|
tags: { or: s },
|
|
1229
1290
|
categories: { or: r }
|
|
@@ -1235,14 +1296,14 @@ class ae {
|
|
|
1235
1296
|
const t = this.store.getState();
|
|
1236
1297
|
if (t.store.storeId === e) return;
|
|
1237
1298
|
const s = (r = this.feedOptions.stores) == null ? void 0 : r.find(
|
|
1238
|
-
(
|
|
1299
|
+
(n) => n.storeId === e
|
|
1239
1300
|
);
|
|
1240
1301
|
return s ? (this.fetchAbortController && (this.fetchAbortController.abort(), this.fetchAbortController = void 0), this.store.setState({
|
|
1241
|
-
...
|
|
1302
|
+
...k,
|
|
1242
1303
|
store: s,
|
|
1243
1304
|
meta: t.meta
|
|
1244
1305
|
}), await this.fetch()) : {
|
|
1245
|
-
status:
|
|
1306
|
+
status: a.ERROR,
|
|
1246
1307
|
error: {
|
|
1247
1308
|
type: d.NOT_FOUND,
|
|
1248
1309
|
message: `store with storeId ${e} doesnt exist`
|
|
@@ -1261,7 +1322,7 @@ class ae {
|
|
|
1261
1322
|
}
|
|
1262
1323
|
initializeSocketConnection() {
|
|
1263
1324
|
var e;
|
|
1264
|
-
this.socket || (this.socket =
|
|
1325
|
+
this.socket || (this.socket = J((e = this.feedOptions.host) == null ? void 0 : e.socketHost, {
|
|
1265
1326
|
transports: ["websocket"],
|
|
1266
1327
|
auth: {
|
|
1267
1328
|
authorization: this.config.publicApiKey,
|
|
@@ -1280,30 +1341,30 @@ class ae {
|
|
|
1280
1341
|
if (this.requestInprogress()) return;
|
|
1281
1342
|
const s = (e == null ? void 0 : e.pageSize) || this.feedOptions.pageSize;
|
|
1282
1343
|
t.isFirstFetch ? (this.store.setState({
|
|
1283
|
-
apiStatus:
|
|
1344
|
+
apiStatus: S.LOADING
|
|
1284
1345
|
}), this.fetchCount()) : this.store.setState({
|
|
1285
|
-
apiStatus:
|
|
1346
|
+
apiStatus: S.FETCHING_MORE
|
|
1286
1347
|
}), this.emitter.emit("feed.store_update", this.data);
|
|
1287
1348
|
const r = {
|
|
1288
1349
|
distinct_id: this.config.distinctId,
|
|
1289
1350
|
tenant_id: this.feedOptions.tenantId,
|
|
1290
1351
|
page_size: s,
|
|
1291
|
-
store: t.store.storeId !==
|
|
1352
|
+
store: t.store.storeId !== C.storeId ? this.storeQueryParamObj(t.store) : null
|
|
1292
1353
|
};
|
|
1293
1354
|
if (t.notifications.length > 0) {
|
|
1294
|
-
const
|
|
1355
|
+
const f = t.notifications[t.notifications.length - 1];
|
|
1295
1356
|
r.search_after = [
|
|
1296
|
-
|
|
1297
|
-
|
|
1357
|
+
f.is_pinned,
|
|
1358
|
+
f.created_on
|
|
1298
1359
|
];
|
|
1299
1360
|
} else
|
|
1300
1361
|
r.search_after = [];
|
|
1301
|
-
const
|
|
1362
|
+
const n = this.getUrl("notifications", r), c = new AbortController();
|
|
1302
1363
|
this.fetchAbortController = c;
|
|
1303
|
-
const u = await this.config.client().request({ type: "get", url:
|
|
1364
|
+
const u = await this.config.client().request({ type: "get", url: n, signal: c.signal });
|
|
1304
1365
|
if (!c.signal.aborted)
|
|
1305
|
-
return u.status ===
|
|
1306
|
-
apiStatus:
|
|
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,
|
|
1307
1368
|
notifications: t.isFirstFetch ? u.body.results : [...t.notifications, ...u.body.results],
|
|
1308
1369
|
pageInfo: {
|
|
1309
1370
|
...t.pageInfo,
|
|
@@ -1316,7 +1377,7 @@ class ae {
|
|
|
1316
1377
|
// TODO: support other stores
|
|
1317
1378
|
async fetchNextPage() {
|
|
1318
1379
|
return this.store.getState().pageInfo.hasMore === !1 ? {
|
|
1319
|
-
status:
|
|
1380
|
+
status: a.ERROR,
|
|
1320
1381
|
error: {
|
|
1321
1382
|
type: d.VALIDATION_ERROR,
|
|
1322
1383
|
message: "No more pages to fetch"
|
|
@@ -1329,7 +1390,7 @@ class ae {
|
|
|
1329
1390
|
tenant_id: this.feedOptions.tenantId,
|
|
1330
1391
|
stores: this.feedOptions.stores ? this.storesQueryParamObj(this.feedOptions.stores) : null
|
|
1331
1392
|
}, t = this.getUrl("notifications_count", e), s = await this.config.client().request({ type: "get", url: t });
|
|
1332
|
-
return s.status ===
|
|
1393
|
+
return s.status === a.SUCCESS && this.store.setState({ meta: s.body }), this.emitter.emit("feed.store_update", this.data), s;
|
|
1333
1394
|
}
|
|
1334
1395
|
async fetchDetails(e) {
|
|
1335
1396
|
const t = this.getUrl(`notifications/${e}`, {
|
|
@@ -1342,8 +1403,8 @@ class ae {
|
|
|
1342
1403
|
const t = this.store.getState();
|
|
1343
1404
|
let s = !1;
|
|
1344
1405
|
if (this.store.setState({
|
|
1345
|
-
notifications: t.notifications.map((
|
|
1346
|
-
}), 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 };
|
|
1347
1408
|
const r = this.getUrl(`notifications/${e}/seen`, {
|
|
1348
1409
|
tenant_id: this.feedOptions.tenantId,
|
|
1349
1410
|
distinct_id: this.config.distinctId
|
|
@@ -1354,8 +1415,8 @@ class ae {
|
|
|
1354
1415
|
const t = this.store.getState();
|
|
1355
1416
|
let s = !1;
|
|
1356
1417
|
if (this.store.setState({
|
|
1357
|
-
notifications: t.notifications.map((
|
|
1358
|
-
}), 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 };
|
|
1359
1420
|
const r = this.getUrl(`notifications/${e}/read`, {
|
|
1360
1421
|
tenant_id: this.feedOptions.tenantId,
|
|
1361
1422
|
distinct_id: this.config.distinctId
|
|
@@ -1366,8 +1427,8 @@ class ae {
|
|
|
1366
1427
|
const t = this.store.getState();
|
|
1367
1428
|
let s = !1;
|
|
1368
1429
|
if (this.store.setState({
|
|
1369
|
-
notifications: t.notifications.map((
|
|
1370
|
-
}), 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 };
|
|
1371
1432
|
const r = this.getUrl(`notifications/${e}/unread`, {
|
|
1372
1433
|
tenant_id: this.feedOptions.tenantId,
|
|
1373
1434
|
distinct_id: this.config.distinctId
|
|
@@ -1390,8 +1451,8 @@ class ae {
|
|
|
1390
1451
|
const t = this.store.getState();
|
|
1391
1452
|
let s = !1;
|
|
1392
1453
|
if (this.store.setState({
|
|
1393
|
-
notifications: t.notifications.filter((
|
|
1394
|
-
}), s) return { status:
|
|
1454
|
+
notifications: t.notifications.filter((n) => n.n_id === e ? (s = !!n.archived, !1) : !0)
|
|
1455
|
+
}), s) return { status: a.SUCCESS };
|
|
1395
1456
|
const r = this.getUrl(`notifications/${e}/archive`, {
|
|
1396
1457
|
tenant_id: this.feedOptions.tenantId,
|
|
1397
1458
|
distinct_id: this.config.distinctId
|
|
@@ -1437,8 +1498,8 @@ class ae {
|
|
|
1437
1498
|
reset() {
|
|
1438
1499
|
var e;
|
|
1439
1500
|
this.store.setState({
|
|
1440
|
-
...
|
|
1441
|
-
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) ||
|
|
1501
|
+
...k,
|
|
1502
|
+
store: ((e = this.feedOptions.stores) == null ? void 0 : e[0]) || C
|
|
1442
1503
|
}), this.emitter.emit("feed.store_update", this.data), this.expiryTimerId && (clearInterval(this.expiryTimerId), this.expiryTimerId = void 0);
|
|
1443
1504
|
}
|
|
1444
1505
|
remove() {
|
|
@@ -1446,31 +1507,36 @@ class ae {
|
|
|
1446
1507
|
this.reset(), this.emitter.off("*"), (e = this.socket) == null || e.disconnect(), this.config.feeds.removeInstance(this);
|
|
1447
1508
|
}
|
|
1448
1509
|
}
|
|
1449
|
-
const
|
|
1450
|
-
class
|
|
1510
|
+
const me = "https://hub.suprsend.com", ge = "serviceworker.js", W = "ss_distinct_id";
|
|
1511
|
+
class be {
|
|
1451
1512
|
constructor(e, t) {
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
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());
|
|
1465
1528
|
if (!e)
|
|
1466
1529
|
throw new Error("[SuprSend]: publicApiKey is missing");
|
|
1467
|
-
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);
|
|
1468
1534
|
}
|
|
1469
1535
|
handleRefreshUserToken(e) {
|
|
1470
|
-
if (!this.userToken || !
|
|
1471
|
-
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;
|
|
1472
1538
|
if (s && s > r) {
|
|
1473
|
-
const c = s - r -
|
|
1539
|
+
const c = s - r - n;
|
|
1474
1540
|
this.userTokenExpirationTimer && clearTimeout(this.userTokenExpirationTimer), this.userTokenExpirationTimer = setTimeout(async () => {
|
|
1475
1541
|
let u = "";
|
|
1476
1542
|
try {
|
|
@@ -1495,7 +1561,7 @@ class pe {
|
|
|
1495
1561
|
client() {
|
|
1496
1562
|
return this.distinctId || console.warn(
|
|
1497
1563
|
"[SuprSend]: distinctId is missing. User should be authenticated"
|
|
1498
|
-
), this.apiClient || (this.apiClient = new
|
|
1564
|
+
), this.apiClient || (this.apiClient = new P(this)), this.apiClient;
|
|
1499
1565
|
}
|
|
1500
1566
|
eventApi(e) {
|
|
1501
1567
|
return this.client().request({
|
|
@@ -1511,35 +1577,35 @@ class pe {
|
|
|
1511
1577
|
async identify(e, t, s) {
|
|
1512
1578
|
if (!e)
|
|
1513
1579
|
return o({
|
|
1514
|
-
status:
|
|
1580
|
+
status: a.ERROR,
|
|
1515
1581
|
errorType: d.VALIDATION_ERROR,
|
|
1516
1582
|
errorMessage: "distinctId is missing"
|
|
1517
1583
|
});
|
|
1518
1584
|
if (this.apiClient && this.distinctId && this.distinctId !== e)
|
|
1519
1585
|
return o({
|
|
1520
|
-
status:
|
|
1586
|
+
status: a.ERROR,
|
|
1521
1587
|
errorType: d.VALIDATION_ERROR,
|
|
1522
1588
|
errorMessage: "User already loggedin, reset current user to login new user"
|
|
1523
1589
|
});
|
|
1524
1590
|
if (this.apiClient && this.distinctId === e && this.userToken !== t)
|
|
1525
|
-
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 });
|
|
1526
1592
|
if (this.distinctId && this.apiClient)
|
|
1527
|
-
return o({ status:
|
|
1528
|
-
this.distinctId = e, this.userToken = t, this.apiClient = new
|
|
1529
|
-
const r =
|
|
1530
|
-
|
|
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
|
|
1531
1597
|
);
|
|
1532
1598
|
if (s != null && s.refreshUserToken && this.handleRefreshUserToken(s.refreshUserToken), r == this.distinctId)
|
|
1533
|
-
return this.webpush.updatePushSubscription(), o({ status:
|
|
1534
|
-
|
|
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({
|
|
1535
1602
|
event: "$identify",
|
|
1536
|
-
$insert_id:
|
|
1537
|
-
$time:
|
|
1603
|
+
$insert_id: D(),
|
|
1604
|
+
$time: M(),
|
|
1538
1605
|
properties: {
|
|
1539
1606
|
$identified_id: e
|
|
1540
1607
|
}
|
|
1541
|
-
});
|
|
1542
|
-
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;
|
|
1543
1609
|
}
|
|
1544
1610
|
/**
|
|
1545
1611
|
* Check's if SuprSend instance is authenticated. To check if userToken is also present pass true.
|
|
@@ -1554,12 +1620,12 @@ class pe {
|
|
|
1554
1620
|
let s = {};
|
|
1555
1621
|
return e ? (typeof t == "object" && (s = { ...s, ...t }), this.eventApi({
|
|
1556
1622
|
event: String(e),
|
|
1557
|
-
$insert_id:
|
|
1558
|
-
$time:
|
|
1623
|
+
$insert_id: D(),
|
|
1624
|
+
$time: M(),
|
|
1559
1625
|
distinct_id: this.distinctId,
|
|
1560
1626
|
properties: s
|
|
1561
1627
|
})) : o({
|
|
1562
|
-
status:
|
|
1628
|
+
status: a.ERROR,
|
|
1563
1629
|
errorType: d.VALIDATION_ERROR,
|
|
1564
1630
|
errorMessage: "event name is missing"
|
|
1565
1631
|
});
|
|
@@ -1569,16 +1635,16 @@ class pe {
|
|
|
1569
1635
|
*/
|
|
1570
1636
|
async reset(e) {
|
|
1571
1637
|
var s, r;
|
|
1572
|
-
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 });
|
|
1573
1639
|
}
|
|
1574
1640
|
}
|
|
1575
1641
|
export {
|
|
1576
|
-
|
|
1577
|
-
|
|
1642
|
+
S as ApiResponseStatus,
|
|
1643
|
+
w as ChannelLevelPreferenceOptions,
|
|
1578
1644
|
d as ERROR_TYPE,
|
|
1579
|
-
|
|
1645
|
+
Oe as Feed,
|
|
1580
1646
|
p as PreferenceOptions,
|
|
1581
|
-
|
|
1582
|
-
|
|
1647
|
+
a as RESPONSE_STATUS,
|
|
1648
|
+
be as SuprSend
|
|
1583
1649
|
};
|
|
1584
1650
|
//# sourceMappingURL=index.js.map
|