@braze/web-sdk 6.11.0 → 6.12.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/index.d.ts +36 -5
- package/package.json +1 -1
- package/shared-lib/event-types.js +4 -4
- package/shared-lib/indexed-db-adapter.js +51 -51
- package/shared-lib/logger.js +7 -7
- package/shared-lib/supported-options.js +9 -9
- package/src/DUST/dust-config-store.js +89 -0
- package/src/DUST/dust-connection-core.js +7 -21
- package/src/DUST/dust-message-dedup.js +33 -0
- package/src/DUST/dust-provider.js +367 -397
- package/src/DUST/dust-tab-identity.js +30 -0
- package/src/DUST/index.js +7 -9
- package/src/DUST/subscribe-to-dust.js +5 -5
- package/src/FeatureFlags/feature-flag-factory.js +4 -4
- package/src/FeatureFlags/feature-flag.js +5 -5
- package/src/FeatureFlags/feature-flags-provider-factory.js +8 -1
- package/src/FeatureFlags/feature-flags-provider.js +74 -74
- package/src/FeatureFlags/get-all-feature-flags.js +2 -2
- package/src/FeatureFlags/get-feature-flag.js +2 -2
- package/src/FeatureFlags/log-feature-flag-impression.js +3 -3
- package/src/FeatureFlags/subscribe-to-feature-flags-updates.js +1 -1
- package/src/InAppMessage/defer-in-app-message.js +2 -2
- package/src/InAppMessage/display/get-animation-effect.js +1 -1
- package/src/InAppMessage/display/html-message-display-utils.js +4 -4
- package/src/InAppMessage/display/html-message-to-html.js +10 -10
- package/src/InAppMessage/display/in-app-message-to-html.js +42 -42
- package/src/InAppMessage/display/modal-utils.js +14 -14
- package/src/InAppMessage/get-deferred-in-app-message.js +2 -2
- package/src/InAppMessage/in-app-message-factory.js +6 -6
- package/src/InAppMessage/in-app-message-manager-factory.js +5 -5
- package/src/InAppMessage/in-app-message-manager.js +73 -73
- package/src/InAppMessage/log-in-app-message-button-click.js +2 -2
- package/src/InAppMessage/log-in-app-message-click.js +2 -2
- package/src/InAppMessage/log-in-app-message-html-click.js +2 -2
- package/src/InAppMessage/log-in-app-message-impression.js +2 -2
- package/src/InAppMessage/models/full-screen-message.js +9 -9
- package/src/InAppMessage/models/html-message.js +4 -4
- package/src/InAppMessage/models/in-app-message-button.js +2 -2
- package/src/InAppMessage/models/in-app-message.js +52 -52
- package/src/InAppMessage/models/modal-message.js +7 -7
- package/src/InAppMessage/models/slide-up-message.js +11 -11
- package/src/InAppMessage/models/templated-in-app-message.js +8 -8
- package/src/InAppMessage/subscribe-to-in-app-message.js +2 -2
- package/src/InAppMessage/ui/automatically-show-in-app-messages.js +5 -5
- package/src/InAppMessage/ui/show-in-app-message.js +36 -36
- package/src/Push/is-push-blocked.js +2 -2
- package/src/Push/is-push-permission-granted.js +2 -2
- package/src/Push/is-push-supported.js +2 -2
- package/src/Push/push-manager-factory.js +6 -6
- package/src/Push/push-manager.js +14 -14
- package/src/Push/unregister-push-token-on-server.js +3 -3
- package/src/Push/utils/push-utils.js +10 -10
- package/src/User/user.js +19 -19
- package/src/common/content-cards-display.js +21 -21
- package/src/common/event-logger.js +2 -2
- package/src/l10n/l10n-manager-factory.js +7 -7
- package/src/l10n/l10n-manager.js +5 -5
- package/src/managers/auth-manager.js +1 -1
- package/src/managers/braze-instance.js +41 -41
- package/src/managers/device-manager.js +22 -22
- package/src/managers/network-manager.js +108 -108
- package/src/managers/server-config-manager.js +83 -83
- package/src/managers/session-manager.js +6 -6
- package/src/managers/storage-manager-factory.js +4 -4
- package/src/managers/storage-manager.js +127 -125
- package/src/managers/subscription-manager.js +1 -1
- package/src/managers/utils.js +1 -1
- package/src/models/backend-errors.js +5 -5
- package/src/models/braze-event.js +7 -7
- package/src/models/device.js +3 -3
- package/src/models/identifier.js +3 -3
- package/src/models/push-token.js +3 -3
- package/src/models/server-config.js +31 -31
- package/src/request-controller.js +39 -39
- package/src/triggers/models/filter.js +58 -58
- package/src/triggers/models/in-app-message-click-data.js +4 -4
- package/src/triggers/models/push-click-data.js +2 -2
- package/src/triggers/models/trigger-condition.js +35 -35
- package/src/triggers/models/trigger.js +37 -37
- package/src/triggers/triggers-provider-factory.js +3 -3
- package/src/triggers/triggers-provider.js +50 -50
- package/src/types.js +2 -2
- package/src/ui/js/attach-css.js +1 -1
- package/src/ui/js/feed-css.js +2 -2
- package/src/ui/js/iam-css.js +2 -2
- package/src/util/base-device-parser.js +2 -2
- package/src/util/braze-actions.js +2 -2
- package/src/util/browser-detector.js +15 -15
- package/src/util/client-hints-parser.js +5 -5
- package/src/util/component-utils.js +4 -4
- package/src/util/dom-utils.js +5 -5
- package/src/util/ecommerce-event-validation.js +77 -48
- package/src/util/key-codes.js +1 -1
- package/src/util/net.js +4 -4
- package/src/util/request-header-utils.js +20 -20
- package/src/util/string-utils.js +5 -0
- package/src/util/user-agent-parser.js +18 -18
- package/src/util/validation-utils.js +4 -4
- package/src/util/window-utils.js +2 -2
- package/src/DUST/dust-shared-worker-code.js +0 -2
- package/src/DUST/dust-shared-worker-impl.js +0 -234
- package/src/DUST/dust-worker-bridge.js +0 -151
package/src/util/dom-utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { logger as b } from "../../shared-lib/index.js";
|
|
2
|
-
import { getErrorMessage as
|
|
2
|
+
import { getErrorMessage as ci } from "./error-utils.js";
|
|
3
3
|
export function _isInView(t, n = !1, e = !1, s = !1) {
|
|
4
4
|
if (null == t) return !1;
|
|
5
5
|
(n = n || !1), (e = e || !1);
|
|
@@ -19,7 +19,7 @@ export function _isInView(t, n = !1, e = !1, s = !1) {
|
|
|
19
19
|
);
|
|
20
20
|
}
|
|
21
21
|
export const DOMUtils = { Ic: null, td: _isInView };
|
|
22
|
-
export const DIRECTIONS = {
|
|
22
|
+
export const DIRECTIONS = { Jo: "up", Ko: "down", ie: "left", ne: "right" };
|
|
23
23
|
export function supportsPassive() {
|
|
24
24
|
if (null == DOMUtils.Ic) {
|
|
25
25
|
DOMUtils.Ic = !1;
|
|
@@ -32,7 +32,7 @@ export function supportsPassive() {
|
|
|
32
32
|
window.addEventListener("testPassive", () => {}, t),
|
|
33
33
|
window.removeEventListener("testPassive", () => {}, t);
|
|
34
34
|
} catch (t) {
|
|
35
|
-
b.error(
|
|
35
|
+
b.error(ci(t));
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
return DOMUtils.Ic;
|
|
@@ -69,9 +69,9 @@ export function detectSwipe(t, n, e) {
|
|
|
69
69
|
(i = null))
|
|
70
70
|
: Math.abs(u) >= 25 &&
|
|
71
71
|
(((u > 0 &&
|
|
72
|
-
n === DIRECTIONS.
|
|
72
|
+
n === DIRECTIONS.Jo &&
|
|
73
73
|
t.scrollTop === t.scrollHeight - t.offsetHeight) ||
|
|
74
|
-
(u < 0 && n === DIRECTIONS.
|
|
74
|
+
(u < 0 && n === DIRECTIONS.Ko && 0 === t.scrollTop)) &&
|
|
75
75
|
e(o),
|
|
76
76
|
(s = null),
|
|
77
77
|
(i = null));
|
|
@@ -55,7 +55,7 @@ function _n(n, t) {
|
|
|
55
55
|
),
|
|
56
56
|
!1);
|
|
57
57
|
}
|
|
58
|
-
function
|
|
58
|
+
function yn(n, t, e) {
|
|
59
59
|
if (e > 50)
|
|
60
60
|
return b.error(`Cannot ${ln} because ${t} is nested too deeply.`), !1;
|
|
61
61
|
if (null == n || "object" != typeof n) return !0;
|
|
@@ -71,7 +71,7 @@ function $n(n, t, e) {
|
|
|
71
71
|
),
|
|
72
72
|
!1
|
|
73
73
|
);
|
|
74
|
-
} else if (
|
|
74
|
+
} else if (!yn(u, t, e + 1)) return !1;
|
|
75
75
|
}
|
|
76
76
|
return !0;
|
|
77
77
|
}
|
|
@@ -89,11 +89,11 @@ function $n(n, t, e) {
|
|
|
89
89
|
),
|
|
90
90
|
!1
|
|
91
91
|
);
|
|
92
|
-
} else if (null != u && "object" == typeof u &&
|
|
92
|
+
} else if (null != u && "object" == typeof u && !yn(u, t, e + 1)) return !1;
|
|
93
93
|
}
|
|
94
94
|
return !0;
|
|
95
95
|
}
|
|
96
|
-
function
|
|
96
|
+
function $n(n, t) {
|
|
97
97
|
if (!g(n))
|
|
98
98
|
return (
|
|
99
99
|
b.error(`Cannot ${ln} because ${t} must be an array of strings.`), !1
|
|
@@ -101,10 +101,10 @@ function vn(n, t) {
|
|
|
101
101
|
for (const e of n) if (!1 === dn(e, t, !0)) return !1;
|
|
102
102
|
return !0;
|
|
103
103
|
}
|
|
104
|
-
function
|
|
105
|
-
if (
|
|
106
|
-
const [e, r] = nt(
|
|
107
|
-
return !!e && !(null != r &&
|
|
104
|
+
function vn(n, t) {
|
|
105
|
+
if (null == n) return;
|
|
106
|
+
const [e, r] = nt(n, R.QE, "metadata", ln, t);
|
|
107
|
+
return !!e && !(null != r && !yn(r, t, 0)) && r;
|
|
108
108
|
}
|
|
109
109
|
function gn(n) {
|
|
110
110
|
if (null == n || "object" != typeof n || g(n))
|
|
@@ -130,10 +130,10 @@ function gn(n) {
|
|
|
130
130
|
})(t.quantity),
|
|
131
131
|
c = pn(t.price, "product price");
|
|
132
132
|
if (!1 === e || !1 === r || !1 === u || !1 === o || !1 === c) return null;
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
if (!1 ===
|
|
136
|
-
const s =
|
|
133
|
+
const a = dn(t.image_url, "image_url", !1),
|
|
134
|
+
i = dn(t.product_url, "product_url", !1);
|
|
135
|
+
if (!1 === a || !1 === i) return null;
|
|
136
|
+
const s = vn(t.metadata, "eCommerce product metadata");
|
|
137
137
|
if (!1 === s) return null;
|
|
138
138
|
const l = {
|
|
139
139
|
product_id: e,
|
|
@@ -143,8 +143,8 @@ function gn(n) {
|
|
|
143
143
|
price: c,
|
|
144
144
|
};
|
|
145
145
|
return (
|
|
146
|
-
null !=
|
|
147
|
-
null !=
|
|
146
|
+
null != a && (l.image_url = a),
|
|
147
|
+
null != i && (l.product_url = i),
|
|
148
148
|
null != s && (l.metadata = s),
|
|
149
149
|
l
|
|
150
150
|
);
|
|
@@ -161,7 +161,7 @@ function Cn(n) {
|
|
|
161
161
|
}
|
|
162
162
|
return t;
|
|
163
163
|
}
|
|
164
|
-
function
|
|
164
|
+
function jn(n) {
|
|
165
165
|
const t = (function (n) {
|
|
166
166
|
if (null == n || "string" != typeof n || n.length <= 0)
|
|
167
167
|
return (
|
|
@@ -179,7 +179,7 @@ function hn(n) {
|
|
|
179
179
|
e = dn(n.source, "source", !0);
|
|
180
180
|
return !1 === t || !1 === e ? null : { currency: t, source: e };
|
|
181
181
|
}
|
|
182
|
-
function
|
|
182
|
+
function hn(n, t) {
|
|
183
183
|
const e = ["subtotal_value", "tax", "shipping"];
|
|
184
184
|
for (const r of e)
|
|
185
185
|
if (null != t[r]) {
|
|
@@ -189,14 +189,43 @@ function jn(n, t) {
|
|
|
189
189
|
}
|
|
190
190
|
return !0;
|
|
191
191
|
}
|
|
192
|
-
function
|
|
193
|
-
const e =
|
|
192
|
+
function kn(n, t) {
|
|
193
|
+
const e = vn(t, "eCommerce event metadata");
|
|
194
194
|
return !1 !== e && (null != e && (n.metadata = e), !0);
|
|
195
195
|
}
|
|
196
|
-
function
|
|
196
|
+
function wn(n, t) {
|
|
197
|
+
return null == n || !1 !== dn(n, t, !1);
|
|
198
|
+
}
|
|
199
|
+
function qn(n) {
|
|
200
|
+
if (null == n || "object" != typeof n || g(n)) return !0;
|
|
201
|
+
const t = n;
|
|
202
|
+
if (!wn(t.country, "metadata.country")) return !1;
|
|
203
|
+
if (!wn(t.market_handle, "metadata.market_handle")) return !1;
|
|
204
|
+
if (null == t.presentment_currency) return !0;
|
|
205
|
+
if ("object" != typeof t.presentment_currency || g(t.presentment_currency))
|
|
206
|
+
return (
|
|
207
|
+
b.error(
|
|
208
|
+
`Cannot ${ln} because metadata.presentment_currency must be an object.`,
|
|
209
|
+
),
|
|
210
|
+
!1
|
|
211
|
+
);
|
|
212
|
+
const e = t.presentment_currency;
|
|
213
|
+
if (!wn(e.price, "metadata.presentment_currency.price")) return !1;
|
|
214
|
+
if (null == e.code) return !0;
|
|
215
|
+
const r = dn(e.code, "metadata.presentment_currency.code", !1);
|
|
216
|
+
if ("string" != typeof r) return !1;
|
|
217
|
+
const u = r.toUpperCase();
|
|
218
|
+
return or(u)
|
|
219
|
+
? ((e.code = u), !0)
|
|
220
|
+
: (b.error(
|
|
221
|
+
`${R.QE} requires a valid ISO 4217 currency code, got "${r}". Ignoring event.`,
|
|
222
|
+
),
|
|
223
|
+
!1);
|
|
224
|
+
}
|
|
225
|
+
function En(n, t) {
|
|
197
226
|
const e = dn(n.cart_id, "cart_id", !0),
|
|
198
227
|
r =
|
|
199
|
-
|
|
228
|
+
null == n.action
|
|
200
229
|
? un.REPLACE
|
|
201
230
|
: ((u = n.action),
|
|
202
231
|
!!ta(
|
|
@@ -208,11 +237,10 @@ function kn(n, t) {
|
|
|
208
237
|
var u;
|
|
209
238
|
const o = Cn(n.products);
|
|
210
239
|
if (!1 === e || !1 === r || null == o) return null;
|
|
211
|
-
const c = r === un.
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const a = {
|
|
240
|
+
const c = r === un.Ld || r === un.Md,
|
|
241
|
+
a = null == n.total_value && c ? void 0 : pn(n.total_value, "total_value");
|
|
242
|
+
if (!1 === a) return null;
|
|
243
|
+
const i = {
|
|
216
244
|
cart_id: e,
|
|
217
245
|
action: r,
|
|
218
246
|
currency: t.currency,
|
|
@@ -220,8 +248,8 @@ function kn(n, t) {
|
|
|
220
248
|
source: t.source,
|
|
221
249
|
};
|
|
222
250
|
return (
|
|
223
|
-
void 0 !==
|
|
224
|
-
|
|
251
|
+
void 0 !== a && (i.total_value = a),
|
|
252
|
+
hn(i, n) && kn(i, n.metadata) ? i : null
|
|
225
253
|
);
|
|
226
254
|
}
|
|
227
255
|
export function sanitizeEcommerceEvent(n) {
|
|
@@ -229,26 +257,26 @@ export function sanitizeEcommerceEvent(n) {
|
|
|
229
257
|
if (null == t || "object" != typeof t || g(t))
|
|
230
258
|
return b.error(`${R.QE} requires a properties object.`), null;
|
|
231
259
|
const e = t,
|
|
232
|
-
r =
|
|
260
|
+
r = jn(e);
|
|
233
261
|
if (null == r) return null;
|
|
234
262
|
switch (n.name) {
|
|
235
263
|
case "ecommerce.product_viewed":
|
|
236
264
|
return (function (n, t) {
|
|
237
265
|
const e = n.metadata;
|
|
238
|
-
if (
|
|
266
|
+
if (null != n.type && !$n(n.type, "type")) return null;
|
|
239
267
|
const r = dn(n.product_id, "product_id", !0),
|
|
240
268
|
u = dn(n.product_name, "product_name", !0),
|
|
241
269
|
o = dn(n.variant_id, "variant_id", !0),
|
|
242
270
|
c = pn(n.price, "price"),
|
|
243
|
-
|
|
244
|
-
|
|
271
|
+
a = dn(n.image_url, "image_url", !1),
|
|
272
|
+
i = dn(n.product_url, "product_url", !1);
|
|
245
273
|
if (
|
|
246
274
|
!1 === r ||
|
|
247
275
|
!1 === u ||
|
|
248
276
|
!1 === o ||
|
|
249
277
|
!1 === c ||
|
|
250
|
-
!1 ===
|
|
251
|
-
!1 ===
|
|
278
|
+
!1 === a ||
|
|
279
|
+
!1 === i
|
|
252
280
|
)
|
|
253
281
|
return null;
|
|
254
282
|
const s = {
|
|
@@ -260,14 +288,14 @@ export function sanitizeEcommerceEvent(n) {
|
|
|
260
288
|
source: t.source,
|
|
261
289
|
};
|
|
262
290
|
return (
|
|
263
|
-
null !=
|
|
264
|
-
null !=
|
|
265
|
-
|
|
266
|
-
|
|
291
|
+
null != a && (s.image_url = a),
|
|
292
|
+
null != i && (s.product_url = i),
|
|
293
|
+
null != n.type && (s.type = n.type),
|
|
294
|
+
kn(s, e) ? s : null
|
|
267
295
|
);
|
|
268
296
|
})(e, r);
|
|
269
297
|
case "ecommerce.cart_updated":
|
|
270
|
-
return
|
|
298
|
+
return En(e, r);
|
|
271
299
|
case "ecommerce.checkout_started":
|
|
272
300
|
return (function (n, t) {
|
|
273
301
|
const e = dn(n.checkout_id, "checkout_id", !0),
|
|
@@ -283,7 +311,8 @@ export function sanitizeEcommerceEvent(n) {
|
|
|
283
311
|
source: t.source,
|
|
284
312
|
};
|
|
285
313
|
return (
|
|
286
|
-
null != o && (c.cart_id = o),
|
|
314
|
+
null != o && (c.cart_id = o),
|
|
315
|
+
hn(c, n) && qn(n.metadata) && kn(c, n.metadata) ? c : null
|
|
287
316
|
);
|
|
288
317
|
})(e, r);
|
|
289
318
|
case "ecommerce.order_placed":
|
|
@@ -291,10 +320,10 @@ export function sanitizeEcommerceEvent(n) {
|
|
|
291
320
|
const e = n.metadata;
|
|
292
321
|
if (null != e && "object" == typeof e && !g(e)) {
|
|
293
322
|
const n = e;
|
|
294
|
-
if (
|
|
323
|
+
if (null != n.tags && !$n(n.tags, "metadata.tags")) return null;
|
|
295
324
|
if (
|
|
296
|
-
|
|
297
|
-
|
|
325
|
+
null != n.payment_gateway_names &&
|
|
326
|
+
!$n(n.payment_gateway_names, "metadata.payment_gateway_names")
|
|
298
327
|
)
|
|
299
328
|
return null;
|
|
300
329
|
}
|
|
@@ -303,19 +332,19 @@ export function sanitizeEcommerceEvent(n) {
|
|
|
303
332
|
o = Cn(n.products),
|
|
304
333
|
c = dn(n.cart_id, "cart_id", !1);
|
|
305
334
|
if (!1 === r || !1 === u || null == o || !1 === c) return null;
|
|
306
|
-
const
|
|
335
|
+
const a = {
|
|
307
336
|
order_id: r,
|
|
308
337
|
total_value: u,
|
|
309
338
|
currency: t.currency,
|
|
310
339
|
products: o,
|
|
311
340
|
source: t.source,
|
|
312
341
|
};
|
|
313
|
-
if ((null != c && (
|
|
342
|
+
if ((null != c && (a.cart_id = c), null != n.total_discounts)) {
|
|
314
343
|
const t = pn(n.total_discounts, "total_discounts");
|
|
315
344
|
if (!1 === t) return null;
|
|
316
|
-
|
|
345
|
+
a.total_discounts = t;
|
|
317
346
|
}
|
|
318
|
-
if (
|
|
347
|
+
if (null != n.discounts) {
|
|
319
348
|
if (!g(n.discounts))
|
|
320
349
|
return (
|
|
321
350
|
b.error(`Cannot ${ln} because discounts must be an array.`), null
|
|
@@ -328,9 +357,9 @@ export function sanitizeEcommerceEvent(n) {
|
|
|
328
357
|
"eCommerce order discounts",
|
|
329
358
|
);
|
|
330
359
|
if (!t || null == e) return null;
|
|
331
|
-
|
|
360
|
+
a.discounts = e.discounts;
|
|
332
361
|
}
|
|
333
|
-
return
|
|
362
|
+
return hn(a, n) && qn(n.metadata) && kn(a, n.metadata) ? a : null;
|
|
334
363
|
})(e, r);
|
|
335
364
|
default:
|
|
336
365
|
return (
|
package/src/util/key-codes.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const KeyCodes = {
|
|
1
|
+
export const KeyCodes = { To: 32, No: 9, Lo: 13, oh: 27 };
|
package/src/util/net.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { logger as b } from "../../shared-lib/index.js";
|
|
2
|
-
import
|
|
3
|
-
import { getErrorMessage as
|
|
2
|
+
import Re from "../models/backend-errors.js";
|
|
3
|
+
import { getErrorMessage as ci } from "./error-utils.js";
|
|
4
4
|
const l = {
|
|
5
5
|
ot: (t) => {
|
|
6
6
|
let e, o;
|
|
@@ -27,7 +27,7 @@ const l = {
|
|
|
27
27
|
o = JSON.parse(e.responseText);
|
|
28
28
|
} catch (o) {
|
|
29
29
|
const n = {
|
|
30
|
-
error: "" === e.responseText ?
|
|
30
|
+
error: "" === e.responseText ? Re.Ha : Re.Wa,
|
|
31
31
|
response: e.responseText,
|
|
32
32
|
};
|
|
33
33
|
(0, t.lt)(n, r);
|
|
@@ -51,7 +51,7 @@ const l = {
|
|
|
51
51
|
for (const t of i) e.setRequestHeader(t[0], t[1]);
|
|
52
52
|
e.send(o);
|
|
53
53
|
} catch (t) {
|
|
54
|
-
b.error(`Network request error: ${
|
|
54
|
+
b.error(`Network request error: ${ci(t)}`);
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
57
|
};
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import { REQUEST_ATTEMPT_DEFAULT as
|
|
1
|
+
import { REQUEST_ATTEMPT_DEFAULT as Ne } from "../common/constants.js";
|
|
2
2
|
import { STORAGE_KEYS as s } from "../managers/storage-manager.js";
|
|
3
3
|
const h = {
|
|
4
4
|
it: {
|
|
5
|
-
|
|
5
|
+
Cn: "data",
|
|
6
6
|
Mi: "content_cards/sync",
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
vo: "feature_flags/sync",
|
|
8
|
+
Xo: "template",
|
|
9
9
|
st: "banners/sync",
|
|
10
|
-
|
|
10
|
+
ka: "push/unregister",
|
|
11
11
|
},
|
|
12
|
-
|
|
13
|
-
Rm: (e) => (null == e ? void 0 : e.St(s.It.
|
|
12
|
+
Il: (e) => (null == e ? void 0 : e.St(s.It.lS)),
|
|
13
|
+
Rm: (e) => (null == e ? void 0 : e.St(s.It._S)),
|
|
14
14
|
Am: (e, t) => {
|
|
15
|
-
null == e || e.Pt(s.It.
|
|
15
|
+
null == e || e.Pt(s.It.lS, t);
|
|
16
16
|
},
|
|
17
17
|
qm: (e, t) => {
|
|
18
|
-
null == e || e.Pt(s.It.
|
|
18
|
+
null == e || e.Pt(s.It._S, t);
|
|
19
19
|
},
|
|
20
|
-
|
|
20
|
+
gl: (e, t) => {
|
|
21
21
|
if (!e || !t) return -1;
|
|
22
|
-
const s = h.
|
|
22
|
+
const s = h.Il(e);
|
|
23
23
|
if (null == s) return -1;
|
|
24
24
|
const n = s[t];
|
|
25
25
|
return null == n || isNaN(n) ? -1 : n;
|
|
26
26
|
},
|
|
27
|
-
|
|
28
|
-
let s =
|
|
27
|
+
bl: (e, t) => {
|
|
28
|
+
let s = Ne;
|
|
29
29
|
if (!e || !t) return s;
|
|
30
30
|
const n = h.Rm(e);
|
|
31
|
-
return null == n ? s : ((s = n[t]), null == s || isNaN(s) ?
|
|
31
|
+
return null == n ? s : ((s = n[t]), null == s || isNaN(s) ? Ne : s);
|
|
32
32
|
},
|
|
33
33
|
nt: (e, t, s) => {
|
|
34
34
|
if (!e || !t) return;
|
|
35
|
-
let n = h.
|
|
35
|
+
let n = h.Il(e);
|
|
36
36
|
null == n && (n = {}), (n[t] = s), h.Am(e, n);
|
|
37
37
|
},
|
|
38
|
-
|
|
38
|
+
ql: (e, t, s) => {
|
|
39
39
|
if (!e || !t) return;
|
|
40
40
|
let n = h.Rm(e);
|
|
41
41
|
null == n && (n = {}), (n[t] = s), h.qm(e, n);
|
|
42
42
|
},
|
|
43
43
|
Ji: (e, t) => {
|
|
44
|
-
e && t && h.
|
|
44
|
+
e && t && h.ql(e, t, Ne);
|
|
45
45
|
},
|
|
46
|
-
|
|
46
|
+
Sl: (e, t) => {
|
|
47
47
|
if (!e || !t) return;
|
|
48
|
-
const s = h.
|
|
49
|
-
h.
|
|
48
|
+
const s = h.bl(e, t);
|
|
49
|
+
h.ql(e, t, s + 1);
|
|
50
50
|
},
|
|
51
51
|
};
|
|
52
52
|
export default h;
|
package/src/util/string-utils.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { logger as b } from "../../shared-lib/index.js";
|
|
2
|
+
export function isAlphanumericChar(t) {
|
|
3
|
+
return (
|
|
4
|
+
(t >= "a" && t <= "z") || (t >= "A" && t <= "Z") || (t >= "0" && t <= "9")
|
|
5
|
+
);
|
|
6
|
+
}
|
|
2
7
|
export function getByteLength(t) {
|
|
3
8
|
let e = t.length;
|
|
4
9
|
for (let n = t.length - 1; n >= 0; n--) {
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Browsers as
|
|
3
|
-
export default class
|
|
1
|
+
import Oe from "./base-device-parser.js";
|
|
2
|
+
import { Browsers as xi, OperatingSystems as so } from "./device-constants.js";
|
|
3
|
+
export default class yi extends Oe {
|
|
4
4
|
constructor() {
|
|
5
|
-
super(), (this.
|
|
5
|
+
super(), (this.Sd = yi.Bc(navigator.userAgent || ""));
|
|
6
6
|
}
|
|
7
7
|
ef() {
|
|
8
|
-
return this.
|
|
8
|
+
return this.Sd[0] || "Unknown Browser";
|
|
9
9
|
}
|
|
10
10
|
ff() {
|
|
11
|
-
return this.
|
|
11
|
+
return this.Sd[1] || "Unknown Version";
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
Fa(r) {
|
|
14
14
|
for (let n = 0; n < r.length; n++) {
|
|
15
15
|
const e = r[n].string;
|
|
16
|
-
let i =
|
|
16
|
+
let i = yi.nf(e, r[n]);
|
|
17
17
|
if (i)
|
|
18
18
|
return (
|
|
19
19
|
i === so.Pg && navigator.maxTouchPoints > 1 && (i = so.co),
|
|
@@ -40,40 +40,40 @@ export default class vi extends Ve {
|
|
|
40
40
|
if (-1 !== r.indexOf("PhilipsTV")) return ["Philips Smart TV", null];
|
|
41
41
|
if (r.match(/\b(Roku)\b/)) return ["Roku", null];
|
|
42
42
|
if (r.match(/\bAFTM\b/)) return ["Amazon Fire Stick", null];
|
|
43
|
-
if (e[1] ===
|
|
44
|
-
if (r.includes(
|
|
43
|
+
if (e[1] === xi.rO) {
|
|
44
|
+
if (r.includes(xi.Sg)) return [xi.Sg, e[2]];
|
|
45
45
|
if (
|
|
46
46
|
((n = r.match(/\b(OPR|Edge|EdgA|Edg|UCBrowser)\/(\.?\d+(\.\d+)*)/)),
|
|
47
47
|
null != n)
|
|
48
48
|
)
|
|
49
49
|
return (
|
|
50
50
|
(n = n.slice(1)),
|
|
51
|
-
(n[0] = n[0].replace("OPR",
|
|
52
|
-
(n[0] = n[0].replace("EdgA",
|
|
53
|
-
"Edg" === n[0] && (n[0] =
|
|
51
|
+
(n[0] = n[0].replace("OPR", xi.oO)),
|
|
52
|
+
(n[0] = n[0].replace("EdgA", xi.eO)),
|
|
53
|
+
"Edg" === n[0] && (n[0] = xi.eO),
|
|
54
54
|
[n[0], n[1]]
|
|
55
55
|
);
|
|
56
56
|
}
|
|
57
57
|
if (
|
|
58
|
-
e[1] ===
|
|
58
|
+
e[1] === xi.Bg &&
|
|
59
59
|
((n = r.match(/\b(EdgiOS)\/(\.?\d+(\.\d+)*)/)), null != n)
|
|
60
60
|
)
|
|
61
61
|
return (
|
|
62
|
-
(n = n.slice(1)), (n[0] = n[0].replace("EdgiOS",
|
|
62
|
+
(n = n.slice(1)), (n[0] = n[0].replace("EdgiOS", xi.eO)), [n[0], n[1]]
|
|
63
63
|
);
|
|
64
64
|
if (
|
|
65
65
|
((e = e[2] ? [e[1], e[2]] : [null, null]),
|
|
66
|
-
e[0] ===
|
|
66
|
+
e[0] === xi.Bg &&
|
|
67
67
|
null != (n = r.match(/version\/(\.?\d+(\.\d+)*)/i)) &&
|
|
68
68
|
e.splice(1, 1, n[1]),
|
|
69
69
|
null != (n = r.match(/\b(UCBrowser)\/(\.?\d+(\.\d+)*)/)) &&
|
|
70
70
|
e.splice(1, 1, n[2]),
|
|
71
|
-
e[0] ===
|
|
71
|
+
e[0] === xi.oO && null != (n = r.match(/mini\/(\.?\d+(\.\d+)*)/i)))
|
|
72
72
|
)
|
|
73
73
|
return ["Opera Mini", n[1] || ""];
|
|
74
74
|
if (e[0]) {
|
|
75
75
|
const r = e[0].toLowerCase();
|
|
76
|
-
"crios" === r && (e[0] =
|
|
76
|
+
"crios" === r && (e[0] = xi.rO),
|
|
77
77
|
"tizen" === r && ((e[0] = "Samsung Smart TV"), (e[1] = null)),
|
|
78
78
|
"samsungbrowser" === r && (e[0] = "Samsung Browser");
|
|
79
79
|
}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "./code-utils.js";
|
|
7
7
|
import { getByteLength as er } from "./string-utils.js";
|
|
8
8
|
import { logger as b } from "../../shared-lib/index.js";
|
|
9
|
-
import { toValidBackendTimeString as
|
|
9
|
+
import { toValidBackendTimeString as Rt } from "./date-utils.js";
|
|
10
10
|
import { BRAZE_ACTIONS as oo } from "./braze-actions.js";
|
|
11
11
|
import { CoreStrings as R } from "../common/constants.js";
|
|
12
12
|
export const CUSTOM_DATA_REGEX = /^[^\x00-\x1F\x22]+$/;
|
|
@@ -61,7 +61,7 @@ export function _validateNestedProperties(t, e, r) {
|
|
|
61
61
|
if (g(t) && g(e)) {
|
|
62
62
|
for (let r = 0; r < t.length && r < e.length; r++)
|
|
63
63
|
if (
|
|
64
|
-
(Nt(t[r]) && (e[r] =
|
|
64
|
+
(Nt(t[r]) && (e[r] = Rt(t[r])),
|
|
65
65
|
!_validateNestedProperties(t[r], e[r], o))
|
|
66
66
|
)
|
|
67
67
|
return !1;
|
|
@@ -71,7 +71,7 @@ export function _validateNestedProperties(t, e, r) {
|
|
|
71
71
|
const i = t[r];
|
|
72
72
|
if (n && !validateCustomAttributeKey(r)) return !1;
|
|
73
73
|
if (Nt(i)) {
|
|
74
|
-
e[r] =
|
|
74
|
+
e[r] = Rt(i);
|
|
75
75
|
}
|
|
76
76
|
if (!_validateNestedProperties(i, e[r], o)) return !1;
|
|
77
77
|
}
|
|
@@ -127,7 +127,7 @@ export function validateCustomProperties(t, e, r, n, o) {
|
|
|
127
127
|
delete t[r], delete u[r];
|
|
128
128
|
continue;
|
|
129
129
|
}
|
|
130
|
-
Nt(i) && (u[r] =
|
|
130
|
+
Nt(i) && (u[r] = Rt(i));
|
|
131
131
|
if (
|
|
132
132
|
!_validateEventPropertyValue(
|
|
133
133
|
i,
|
package/src/util/window-utils.js
CHANGED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export const DUST_SHARED_WORKER_CODE =
|
|
2
|
-
'\n"use strict";\nconst workerSelf = self;\nlet eventSource = null;\nlet currentConfig = null;\nlet retryCount = 0;\nlet retryTimeoutId = null;\nlet connectionInProgress = false;\nconst maxRetries = 5;\nconst connectedPorts = new Map();\nlet lastSleepMs = null;\nlet currentRcs = null;\nlet ttlTimeoutId = null;\nlet leaderPortId = null;\nlet ddrTimeoutId = null;\nconst fn = {\n startConnection: null,\n handleMessage: null,\n};\nfunction broadcast(message) {\n connectedPorts.forEach((portInfo, portId) => {\n try {\n portInfo.port.postMessage(message);\n }\n catch (_a) {\n connectedPorts.delete(portId);\n }\n });\n}\nfunction randomInclusive(min, max) {\n return Math.floor(Math.random() * (max - min + 1)) + min;\n}\nfunction electLeader() {\n if (leaderPortId && connectedPorts.has(leaderPortId)) {\n return;\n }\n const firstPortId = connectedPorts.keys().next().value;\n leaderPortId = firstPortId || null;\n if (leaderPortId) {\n console.log("[Braze Real-Time] Elected leader port:", leaderPortId);\n }\n}\nfunction promoteToLeader(portId) {\n if (connectedPorts.has(portId) && leaderPortId !== portId) {\n leaderPortId = portId;\n console.log("[Braze Real-Time] Promoted to leader (tab became active):", portId);\n }\n}\nfunction sendToLeader(message) {\n electLeader();\n if (!leaderPortId) {\n console.warn("[Braze Real-Time] No leader to send message to");\n return;\n }\n const leader = connectedPorts.get(leaderPortId);\n if (leader) {\n try {\n leader.port.postMessage(message);\n }\n catch (_a) {\n connectedPorts.delete(leaderPortId);\n leaderPortId = null;\n sendToLeader(message);\n }\n }\n}\nfunction closeConnection() {\n connectionInProgress = false;\n if (retryTimeoutId !== null) {\n clearTimeout(retryTimeoutId);\n retryTimeoutId = null;\n }\n if (ttlTimeoutId !== null) {\n clearTimeout(ttlTimeoutId);\n ttlTimeoutId = null;\n }\n if (ddrTimeoutId !== null) {\n clearTimeout(ddrTimeoutId);\n ddrTimeoutId = null;\n }\n if (eventSource) {\n eventSource.close();\n eventSource = null;\n broadcast({ type: "disconnected" });\n }\n}\nfunction retryWithBackoff() {\n if (!currentConfig) {\n return;\n }\n retryCount++;\n const { minSleepMs, maxSleepMs, scaleFactor } = currentConfig.backoff;\n let previousSleepMs = lastSleepMs;\n if (previousSleepMs == null || previousSleepMs < minSleepMs) {\n previousSleepMs = minSleepMs;\n }\n const backoffMs = Math.min(maxSleepMs, randomInclusive(minSleepMs, previousSleepMs * scaleFactor));\n lastSleepMs = backoffMs;\n console.log(`[Braze Real-Time] Retrying in ${backoffMs}ms (attempt ${retryCount}/${maxRetries})`);\n retryTimeoutId = setTimeout(function () {\n retryTimeoutId = null;\n fn.startConnection();\n }, backoffMs);\n}\nfunction startConnection(oldEventSourceToClose) {\n if (!currentConfig) {\n return;\n }\n if (eventSource && !oldEventSourceToClose) {\n console.warn("[Braze Real-Time] Connection already exists");\n return;\n }\n if (connectionInProgress && !oldEventSourceToClose) {\n console.warn("[Braze Real-Time] Connection attempt already in progress");\n return;\n }\n connectionInProgress = true;\n const { dustHost, mite, auth } = currentConfig;\n const dustHostWithScheme = /^https?:\\/\\//i.test(dustHost) ? dustHost : `https://${dustHost}`;\n let queryString = `mite=${encodeURIComponent(mite)}&attempts=${retryCount}`;\n if (auth) {\n queryString += `&auth=${encodeURIComponent(auth)}`;\n }\n if (currentRcs) {\n queryString += `&rcs=${encodeURIComponent(currentRcs)}`;\n }\n const subscribeUrl = `${dustHostWithScheme}/sse?${queryString}`;\n try {\n const newEventSource = new EventSource(subscribeUrl);\n newEventSource.onopen = function () {\n if (oldEventSourceToClose) {\n console.log("[Braze Real-Time] Gapless reconnection: new connection established, closing old connection");\n oldEventSourceToClose.close();\n }\n else {\n console.log("[Braze Real-Time] Connection established");\n }\n eventSource = newEventSource;\n connectionInProgress = false;\n retryCount = 0;\n lastSleepMs = null;\n broadcast({ type: "connected" });\n };\n newEventSource.addEventListener("msg", function (event) {\n fn.handleMessage(event.data);\n });\n newEventSource.onerror = function () {\n const readyState = newEventSource ? newEventSource.readyState : -1;\n if (readyState === 0) {\n console.log("[Braze Real-Time] Failed to connect");\n }\n else {\n console.log("[Braze Real-Time] Connection lost");\n }\n if (oldEventSourceToClose && eventSource !== newEventSource) {\n console.log("[Braze Real-Time] Gapless reconnection failed, keeping old connection");\n newEventSource.close();\n connectionInProgress = false;\n if (retryCount < maxRetries) {\n retryWithBackoff();\n }\n return;\n }\n closeConnection();\n if (retryCount < maxRetries) {\n retryWithBackoff();\n }\n else {\n console.error("[Braze Real-Time] Max retries reached");\n broadcast({ type: "error", error: "Max retry attempts reached" });\n }\n };\n }\n catch (error) {\n connectionInProgress = false;\n console.error("[Braze Real-Time] Failed to create EventSource:", error);\n broadcast({ type: "error", error: String(error) });\n }\n}\nfunction handleTtlMessage(tMs, rcs) {\n if (typeof tMs !== "number") {\n return;\n }\n if (typeof rcs === "string") {\n currentRcs = rcs;\n }\n console.log(`[Braze Real-Time] TTL set to ${tMs}ms, will perform gapless reconnection when expired`);\n if (ttlTimeoutId !== null) {\n clearTimeout(ttlTimeoutId);\n }\n ttlTimeoutId = setTimeout(function () {\n ttlTimeoutId = null;\n console.log("[Braze Real-Time] TTL expired, performing gapless reconnection");\n startConnection(eventSource || undefined);\n }, tMs);\n}\nfunction handleDdrMessage(rMs, reason) {\n if (typeof rMs !== "number") {\n return;\n }\n const backoffConfig = currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig.backoff;\n const minSleepMs = (backoffConfig === null || backoffConfig === void 0 ? void 0 : backoffConfig.minSleepMs) || 10000;\n const scaleFactor = (backoffConfig === null || backoffConfig === void 0 ? void 0 : backoffConfig.scaleFactor) || 3;\n const maxSleepMs = (backoffConfig === null || backoffConfig === void 0 ? void 0 : backoffConfig.maxSleepMs) || 300000;\n const backoffMs = Math.min(maxSleepMs, randomInclusive(minSleepMs, minSleepMs * scaleFactor));\n const waitMs = Math.round(rMs + backoffMs);\n const reasonStr = reason ? ` (${reason})` : "";\n console.log(`[Braze Real-Time] Admin requested disconnect${reasonStr}, reconnecting in ${waitMs}ms (r_ms=${rMs} + backoff=${backoffMs})`);\n if (ddrTimeoutId !== null) {\n clearTimeout(ddrTimeoutId);\n }\n closeConnection();\n ddrTimeoutId = setTimeout(function () {\n ddrTimeoutId = null;\n fn.startConnection();\n }, waitMs);\n}\nfunction handleMessage(data) {\n try {\n const message = JSON.parse(data);\n if (!message.type) {\n console.warn("[Braze Real-Time] Message without type:", message);\n return;\n }\n if (message.type === "ttl" && message.body) {\n handleTtlMessage(message.body.t_ms, message.body.rcs);\n return;\n }\n if (message.type === "ddr" && message.body) {\n handleDdrMessage(message.body.r_ms, message.body.e);\n return;\n }\n console.log(`[Braze Real-Time] Routing \'${message.type}\' message to leader`);\n sendToLeader({ type: "message", data: message });\n }\n catch (error) {\n console.warn("[Braze Real-Time] Failed to parse message:", error);\n }\n}\nfn.startConnection = startConnection;\nfn.handleMessage = handleMessage;\nfunction handlePortMessage(port, portId, message) {\n switch (message.type) {\n case "connect":\n if (currentConfig &&\n (currentConfig.mite !== message.config.mite || currentConfig.dustHost !== message.config.dustHost)) {\n console.log("[Braze Real-Time] Config changed, reconnecting");\n closeConnection();\n retryCount = 0;\n lastSleepMs = null;\n currentRcs = null;\n }\n currentConfig = message.config;\n if (!connectedPorts.has(portId)) {\n connectedPorts.set(portId, { port: port });\n }\n electLeader();\n if (!eventSource && !connectionInProgress) {\n startConnection();\n }\n else if (eventSource) {\n port.postMessage({ type: "connected" });\n }\n break;\n case "disconnect":\n connectedPorts.delete(portId);\n if (portId === leaderPortId) {\n leaderPortId = null;\n electLeader();\n }\n if (connectedPorts.size === 0) {\n console.log("[Braze Real-Time] No more ports, closing connection");\n closeConnection();\n currentConfig = null;\n currentRcs = null;\n leaderPortId = null;\n }\n break;\n case "tab_active":\n promoteToLeader(portId);\n break;\n case "ping":\n port.postMessage({ type: "pong" });\n break;\n default:\n console.warn("[Braze Real-Time] Unknown message type:", message.type);\n }\n}\nworkerSelf.onconnect = function (event) {\n const port = event.ports[0];\n const portId = `port-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;\n connectedPorts.set(portId, { port: port });\n port.onmessage = function (messageEvent) {\n try {\n handlePortMessage(port, portId, messageEvent.data);\n }\n catch (error) {\n console.error("[Braze Real-Time] Error handling message:", error);\n }\n };\n port.onmessageerror = function () {\n console.warn("[Braze Real-Time] Message error from port:", portId);\n connectedPorts.delete(portId);\n };\n port.start();\n};\n';
|