@braze/web-sdk 4.7.2 → 4.8.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 +27 -24
- package/package.json +1 -1
- package/shared-lib/braze-shared-lib.js +5 -5
- package/shared-lib/encoding-utils.js +1 -1
- package/shared-lib/event-types.js +24 -24
- package/shared-lib/guid.js +3 -3
- package/shared-lib/indexed-db-adapter.js +17 -17
- package/shared-lib/logger.js +18 -18
- package/shared-lib/supported-options.js +18 -18
- package/src/Card/card-manager-factory.js +2 -2
- package/src/Card/card-manager.js +47 -41
- package/src/Card/display/card-display.js +70 -67
- package/src/Card/log-card-click.js +1 -1
- package/src/Card/log-card-dismissal.js +1 -1
- package/src/Card/log-card-impressions.js +3 -3
- package/src/Card/models/banner.js +3 -2
- package/src/Card/models/captioned-image.js +6 -5
- package/src/Card/models/card.js +107 -87
- package/src/Card/models/classic-card.js +5 -5
- package/src/Card/models/control-card.js +5 -21
- package/src/Card/types.js +1 -0
- package/src/Card/util/card-factory.js +32 -32
- package/src/ContentCards/content-cards-provider-factory.js +3 -3
- package/src/ContentCards/content-cards-provider.js +283 -175
- package/src/ContentCards/content-cards.js +2 -2
- package/src/ContentCards/get-cached-content-cards.js +1 -1
- package/src/ContentCards/log-content-cards-displayed.js +2 -2
- package/src/ContentCards/request-content-cards-refresh.js +1 -1
- package/src/ContentCards/subscribe-to-content-cards-updates.js +9 -6
- package/src/ContentCards/types.js +1 -0
- package/src/ContentCards/ui/hide-content-cards.js +2 -2
- package/src/ContentCards/ui/show-content-cards.js +35 -33
- package/src/Core/add-sdk-metadata.js +17 -18
- package/src/Core/change-user.js +12 -14
- package/src/Core/destroy.js +1 -1
- package/src/Core/disable-sdk.js +7 -6
- package/src/Core/enable-sdk.js +4 -4
- package/src/Core/get-device-id.js +7 -6
- package/src/Core/get-user.js +1 -1
- package/src/Core/handle-braze-action.js +57 -40
- package/src/Core/is-disabled.js +2 -2
- package/src/Core/log-custom-event.js +22 -15
- package/src/Core/log-purchase.js +33 -33
- package/src/Core/open-session.js +17 -15
- package/src/Core/request-immediate-data-flush.js +4 -2
- package/src/Core/set-logger.js +1 -1
- package/src/Core/set-sdk-authentication-signature.js +5 -6
- package/src/Core/subscribe-to-sdk-authentication-failures.js +3 -1
- package/src/Core/toggle-logging.js +1 -1
- package/src/Core/types.js +1 -0
- package/src/Core/wipe-data.js +11 -10
- package/src/FeatureFlags/feature-flag-factory.js +6 -6
- package/src/FeatureFlags/feature-flag.js +17 -17
- package/src/FeatureFlags/feature-flags-provider-factory.js +2 -2
- package/src/FeatureFlags/feature-flags-provider.js +67 -65
- package/src/FeatureFlags/get-all-feature-flags.js +3 -3
- package/src/FeatureFlags/get-feature-flag.js +4 -4
- package/src/FeatureFlags/subscribe-to-feature-flags-updates.js +4 -1
- package/src/Feed/feed-provider-factory.js +8 -8
- package/src/Feed/feed-provider.js +57 -46
- package/src/Feed/feed.js +1 -1
- package/src/Feed/get-cached-feed.js +2 -2
- package/src/Feed/log-feed-displayed.js +3 -1
- package/src/Feed/request-feed-refresh.js +2 -2
- package/src/Feed/subscribe-to-feed-updates.js +2 -2
- package/src/Feed/types.js +1 -0
- package/src/Feed/ui/hide-feed.js +2 -2
- package/src/Feed/ui/show-feed.js +40 -36
- package/src/InAppMessage/display/html-message-to-html.js +125 -119
- package/src/InAppMessage/display/in-app-message-to-html.js +72 -69
- package/src/InAppMessage/display/modal-utils.js +18 -13
- package/src/InAppMessage/in-app-message-factory.js +9 -8
- package/src/InAppMessage/in-app-message-manager-factory.js +7 -7
- package/src/InAppMessage/in-app-message-manager.js +122 -108
- package/src/InAppMessage/log-in-app-message-button-click.js +10 -10
- package/src/InAppMessage/log-in-app-message-click.js +9 -9
- package/src/InAppMessage/log-in-app-message-html-click.js +10 -10
- package/src/InAppMessage/log-in-app-message-impression.js +5 -5
- package/src/InAppMessage/models/control-message.js +4 -1
- package/src/InAppMessage/models/full-screen-message.js +35 -37
- package/src/InAppMessage/models/html-message.js +34 -33
- package/src/InAppMessage/models/in-app-message-button.js +23 -16
- package/src/InAppMessage/models/in-app-message.js +147 -105
- package/src/InAppMessage/models/modal-message.js +34 -36
- package/src/InAppMessage/models/slide-up-message.js +25 -27
- package/src/InAppMessage/models/templated-in-app-message.js +12 -7
- package/src/InAppMessage/subscribe-to-in-app-message.js +2 -2
- package/src/InAppMessage/types.js +1 -0
- package/src/InAppMessage/ui/automatically-show-in-app-messages.js +4 -4
- package/src/InAppMessage/ui/show-in-app-message.js +95 -89
- package/src/InAppMessage/utils/in-app-message-utils.js +1 -0
- 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 +20 -20
- package/src/Push/push-manager.js +192 -174
- package/src/Push/request-push-permission.js +4 -3
- package/src/Push/types.js +1 -0
- package/src/Push/unregister-push.js +2 -2
- package/src/Push/utils/push-utils.js +10 -10
- package/src/User/types.js +1 -0
- package/src/User/user-manager.js +24 -24
- package/src/User/user.js +117 -105
- package/src/common/base-feed.js +7 -7
- package/src/common/base-provider.js +2 -2
- package/src/common/constants.js +6 -0
- package/src/common/event-logger.js +6 -6
- package/src/common/feed-display.js +18 -18
- package/src/common/types.js +1 -0
- package/src/l10n/l10n-manager-factory.js +5 -5
- package/src/l10n/l10n-manager.js +1 -1
- package/src/managers/auth-manager.js +32 -32
- package/src/managers/braze-instance.js +202 -202
- package/src/managers/device-manager.js +23 -23
- package/src/managers/network-manager.js +96 -82
- package/src/managers/server-config-manager.js +60 -42
- package/src/managers/session-manager.js +41 -41
- package/src/managers/storage-manager-factory.js +15 -15
- package/src/managers/storage-manager.js +163 -160
- package/src/managers/subscription-manager.js +11 -11
- package/src/models/backend-errors.js +5 -5
- package/src/models/braze-event.js +7 -7
- package/src/models/device.js +2 -2
- package/src/models/identifier.js +7 -7
- package/src/models/push-token.js +7 -7
- package/src/models/request-result.js +3 -3
- package/src/models/server-config.js +20 -20
- package/src/request-controller.js +176 -174
- package/src/triggers/models/custom-event-data.js +6 -6
- package/src/triggers/models/custom-event-property-data.js +9 -9
- package/src/triggers/models/filter-set.js +9 -9
- package/src/triggers/models/filter.js +64 -64
- package/src/triggers/models/in-app-message-click-data.js +12 -12
- package/src/triggers/models/purchase-data.js +3 -3
- package/src/triggers/models/purchase-property-data.js +9 -9
- package/src/triggers/models/push-click-data.js +5 -5
- package/src/triggers/models/trigger-condition.js +52 -52
- package/src/triggers/models/trigger-events.js +2 -2
- package/src/triggers/models/trigger.js +36 -36
- package/src/triggers/triggers-provider-factory.js +8 -8
- package/src/triggers/triggers-provider.js +165 -162
- package/src/types.js +1 -0
- package/src/ui/js/attach-css.js +3 -3
- package/src/ui/js/load-font-awesome.js +2 -2
- package/src/util/base-device-parser.js +1 -1
- package/src/util/braze-actions.js +20 -20
- package/src/util/browser-detector.js +22 -22
- package/src/util/client-hints-parser.js +6 -6
- package/src/util/code-utils.js +1 -1
- package/src/util/color-utils.js +2 -2
- package/src/util/component-utils.js +2 -2
- package/src/util/deprecation-utils.js +1 -1
- package/src/util/device-constants.js +5 -5
- package/src/util/dom-utils.js +2 -2
- package/src/util/key-codes.js +1 -1
- package/src/util/net.js +11 -11
- package/src/util/request-header-utils.js +23 -0
- package/src/util/string-utils.js +1 -1
- package/src/util/user-agent-parser.js +20 -20
- package/src/util/validation-utils.js +44 -44
- package/src/util/window-utils.js +3 -3
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { Browsers as
|
|
4
|
-
class
|
|
1
|
+
import ni from "./client-hints-parser.js";
|
|
2
|
+
import ei from "./user-agent-parser.js";
|
|
3
|
+
import { Browsers as ai, OperatingSystems as W } from "./device-constants.js";
|
|
4
|
+
class gi {
|
|
5
5
|
constructor() {
|
|
6
|
-
const t = navigator.userAgentData ?
|
|
6
|
+
const t = navigator.userAgentData ? ni : ei;
|
|
7
7
|
(this.Sg = new t()),
|
|
8
8
|
(this.userAgent = navigator.userAgent),
|
|
9
9
|
(this.browser = this.Sg.tf()),
|
|
10
10
|
(this.version = this.Sg.ef()),
|
|
11
|
-
this.
|
|
11
|
+
this.ua().then(t => (this.OS = t)),
|
|
12
12
|
(this.language = (
|
|
13
13
|
navigator.userLanguage ||
|
|
14
14
|
navigator.language ||
|
|
@@ -16,21 +16,21 @@ class si {
|
|
|
16
16
|
navigator.systemLanguage ||
|
|
17
17
|
""
|
|
18
18
|
).toLowerCase()),
|
|
19
|
-
(this
|
|
19
|
+
(this.$o = gi.Bg(this.userAgent));
|
|
20
20
|
}
|
|
21
21
|
Og() {
|
|
22
|
-
return this.browser !==
|
|
22
|
+
return this.browser !== ai.Pg || this.version > 8;
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
return this.browser ===
|
|
24
|
+
rE() {
|
|
25
|
+
return this.browser === ai.kg;
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
la() {
|
|
28
28
|
return this.OS || null;
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
ua() {
|
|
31
31
|
return this.OS
|
|
32
32
|
? Promise.resolve(this.OS)
|
|
33
|
-
: this.Sg.
|
|
33
|
+
: this.Sg.ua(gi.xg).then(t => ((this.OS = t), t));
|
|
34
34
|
}
|
|
35
35
|
static Bg(t) {
|
|
36
36
|
t = t.toLowerCase();
|
|
@@ -56,9 +56,9 @@ class si {
|
|
|
56
56
|
return !1;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
{ string: navigator.platform, if: "Win", identity:
|
|
61
|
-
{ string: navigator.platform, if: "Mac", identity:
|
|
59
|
+
gi.xg = [
|
|
60
|
+
{ string: navigator.platform, if: "Win", identity: W.Dg },
|
|
61
|
+
{ string: navigator.platform, if: "Mac", identity: W.jg },
|
|
62
62
|
{ string: navigator.platform, if: "BlackBerry", identity: "BlackBerry" },
|
|
63
63
|
{ string: navigator.platform, if: "FreeBSD", identity: "FreeBSD" },
|
|
64
64
|
{ string: navigator.platform, if: "OpenBSD", identity: "OpenBSD" },
|
|
@@ -69,17 +69,17 @@ si.xg = [
|
|
|
69
69
|
{
|
|
70
70
|
string: navigator.userAgent,
|
|
71
71
|
if: ["iPhone", "iPad", "iPod"],
|
|
72
|
-
identity:
|
|
72
|
+
identity: W.fe
|
|
73
73
|
},
|
|
74
|
-
{ string: navigator.platform, if: "Pike v", identity:
|
|
74
|
+
{ string: navigator.platform, if: "Pike v", identity: W.fe },
|
|
75
75
|
{ string: navigator.userAgent, if: ["Web0S"], identity: "WebOS" },
|
|
76
76
|
{
|
|
77
77
|
string: navigator.platform,
|
|
78
78
|
if: ["Linux armv7l", "Android"],
|
|
79
|
-
identity:
|
|
79
|
+
identity: W.Fg
|
|
80
80
|
},
|
|
81
|
-
{ string: navigator.userAgent, if: ["Android"], identity:
|
|
81
|
+
{ string: navigator.userAgent, if: ["Android"], identity: W.Fg },
|
|
82
82
|
{ string: navigator.platform, if: "Linux", identity: "Linux" }
|
|
83
83
|
];
|
|
84
|
-
const
|
|
85
|
-
export {
|
|
84
|
+
const V = new gi();
|
|
85
|
+
export { V as default, gi as BrowserDetector };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Oe from "./base-device-parser.js";
|
|
2
|
-
import { Browsers as
|
|
3
|
-
export default class
|
|
2
|
+
import { Browsers as ai } from "./device-constants.js";
|
|
3
|
+
export default class ni extends Oe {
|
|
4
4
|
constructor() {
|
|
5
5
|
if (
|
|
6
6
|
(super(),
|
|
@@ -18,11 +18,11 @@ export default class ti extends Oe {
|
|
|
18
18
|
ef() {
|
|
19
19
|
return this.version;
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
ua(t) {
|
|
22
22
|
if (this.OS) return Promise.resolve(this.OS);
|
|
23
23
|
const r = r => {
|
|
24
24
|
for (let s = 0; s < t.length; s++) {
|
|
25
|
-
const e =
|
|
25
|
+
const e = ni.rf(r, t[s]);
|
|
26
26
|
if (e) return (this.OS = e), this.OS;
|
|
27
27
|
}
|
|
28
28
|
return r;
|
|
@@ -38,7 +38,7 @@ export default class ti extends Oe {
|
|
|
38
38
|
r = this.userAgentData.brands;
|
|
39
39
|
if (r && r.length)
|
|
40
40
|
for (const s of r) {
|
|
41
|
-
const r = this.oc(
|
|
41
|
+
const r = this.oc(ai),
|
|
42
42
|
e = s.brand.match(r);
|
|
43
43
|
if (e && e.length > 0) {
|
|
44
44
|
(t.browser = e[0]), (t.version = s.version);
|
|
@@ -49,7 +49,7 @@ export default class ti extends Oe {
|
|
|
49
49
|
}
|
|
50
50
|
oc(t) {
|
|
51
51
|
const r = [];
|
|
52
|
-
for (const s in t) t[s] !==
|
|
52
|
+
for (const s in t) t[s] !== ai.Pg && r.push(t[s]);
|
|
53
53
|
return new RegExp("(" + r.join("|") + ")", "i");
|
|
54
54
|
}
|
|
55
55
|
nc() {
|
package/src/util/code-utils.js
CHANGED
|
@@ -11,7 +11,7 @@ export function validateValueIsFromEnum(t, e, n, o) {
|
|
|
11
11
|
const c = values(t);
|
|
12
12
|
return (
|
|
13
13
|
-1 !== c.indexOf(e) ||
|
|
14
|
-
(r.
|
|
14
|
+
(r.j.error(`${n} Valid values from ${o} are "${c.join('"/"')}".`), !1)
|
|
15
15
|
);
|
|
16
16
|
}
|
|
17
17
|
export function isArray(t) {
|
package/src/util/color-utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import V from "./browser-detector.js";
|
|
2
2
|
export function isTransparent(r) {
|
|
3
3
|
return (r = parseInt(r)), !isNaN(r) && (4278190080 & r) >>> 24 == 0;
|
|
4
4
|
}
|
|
@@ -9,7 +9,7 @@ export function toRgba(r, t) {
|
|
|
9
9
|
e = (65280 & r) >>> 8,
|
|
10
10
|
o = (16711680 & r) >>> 16,
|
|
11
11
|
a = ((4278190080 & r) >>> 24) / 255;
|
|
12
|
-
return
|
|
12
|
+
return V.Og()
|
|
13
13
|
? "rgba(" + [o, e, n, a * t].join(",") + ")"
|
|
14
14
|
: "rgb(" + [o, e, n].join(",") + ")";
|
|
15
15
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { addPassiveEventListener as oe, buildSvg as ae } from "./dom-utils.js";
|
|
2
|
-
import { KeyCodes as
|
|
2
|
+
import { KeyCodes as lt } from "./key-codes.js";
|
|
3
3
|
export function createCloseButton(t, o, e) {
|
|
4
4
|
const n = document.createElement("button");
|
|
5
5
|
n.setAttribute("aria-label", t),
|
|
@@ -15,7 +15,7 @@ export function createCloseButton(t, o, e) {
|
|
|
15
15
|
return (
|
|
16
16
|
n.appendChild(r),
|
|
17
17
|
n.addEventListener("keydown", t => {
|
|
18
|
-
(t.keyCode !==
|
|
18
|
+
(t.keyCode !== lt.yo && t.keyCode !== lt.Fo) ||
|
|
19
19
|
(e(), t.stopPropagation());
|
|
20
20
|
}),
|
|
21
21
|
(n.onclick = t => {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export const Browsers = {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
OE: "Chrome",
|
|
3
|
+
RE: "Edge",
|
|
4
4
|
Pg: "Internet Explorer",
|
|
5
|
-
|
|
5
|
+
IE: "Opera",
|
|
6
6
|
kg: "Safari",
|
|
7
|
-
|
|
7
|
+
AE: "Firefox"
|
|
8
8
|
};
|
|
9
9
|
export const OperatingSystems = {
|
|
10
10
|
Fg: "Android",
|
|
11
|
-
|
|
11
|
+
fe: "iOS",
|
|
12
12
|
jg: "Mac",
|
|
13
13
|
Dg: "Windows"
|
|
14
14
|
};
|
package/src/util/dom-utils.js
CHANGED
|
@@ -17,7 +17,7 @@ export function _isInView(t, n, e, s) {
|
|
|
17
17
|
);
|
|
18
18
|
}
|
|
19
19
|
export const DOMUtils = { Ou: null, eo: _isInView };
|
|
20
|
-
export const DIRECTIONS = { Je: "up", Ke: "down",
|
|
20
|
+
export const DIRECTIONS = { Je: "up", Ke: "down", W: "left", X: "right" };
|
|
21
21
|
export function supportsPassive() {
|
|
22
22
|
if (null == DOMUtils.Ou) {
|
|
23
23
|
DOMUtils.Ou = !1;
|
|
@@ -59,7 +59,7 @@ export function detectSwipe(t, n, e) {
|
|
|
59
59
|
const l = s - o.touches[0].clientX,
|
|
60
60
|
u = i - o.touches[0].clientY;
|
|
61
61
|
Math.abs(l) > Math.abs(u) && Math.abs(l) >= 25
|
|
62
|
-
? (((l > 0 && n === DIRECTIONS.
|
|
62
|
+
? (((l > 0 && n === DIRECTIONS.W) || (l < 0 && n === DIRECTIONS.X)) &&
|
|
63
63
|
e(o),
|
|
64
64
|
(s = null),
|
|
65
65
|
(i = null))
|
package/src/util/key-codes.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const KeyCodes = {
|
|
1
|
+
export const KeyCodes = { yo: 32, oo: 9, Fo: 13, Ih: 27 };
|
package/src/util/net.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import r from "../../shared-lib/braze-shared-lib.js";
|
|
2
2
|
import qt from "../models/backend-errors.js";
|
|
3
|
-
const
|
|
4
|
-
|
|
3
|
+
const C = {
|
|
4
|
+
Ys: t => {
|
|
5
5
|
let e, o;
|
|
6
6
|
try {
|
|
7
7
|
const n = () => {
|
|
8
|
-
r.
|
|
8
|
+
r.j.error("This browser does not have any supported ajax options!");
|
|
9
9
|
};
|
|
10
10
|
if (
|
|
11
11
|
(window.XMLHttpRequest ? ((e = new XMLHttpRequest()), e || n()) : n(),
|
|
@@ -13,7 +13,7 @@ const b = {
|
|
|
13
13
|
) {
|
|
14
14
|
const r = () => {
|
|
15
15
|
"function" == typeof t.error && t.error(e.status),
|
|
16
|
-
"function" == typeof t.
|
|
16
|
+
"function" == typeof t.ei && t.ei(!1);
|
|
17
17
|
};
|
|
18
18
|
(e.onload = () => {
|
|
19
19
|
let o = !1;
|
|
@@ -21,21 +21,21 @@ const b = {
|
|
|
21
21
|
if (
|
|
22
22
|
((o = (e.status >= 200 && e.status < 300) || 304 === e.status), o)
|
|
23
23
|
) {
|
|
24
|
-
if ("function" == typeof t.
|
|
24
|
+
if ("function" == typeof t.O) {
|
|
25
25
|
let o, r;
|
|
26
26
|
try {
|
|
27
27
|
(o = JSON.parse(e.responseText)),
|
|
28
28
|
(r = e.getAllResponseHeaders());
|
|
29
29
|
} catch (o) {
|
|
30
30
|
const n = {
|
|
31
|
-
error: "" === e.responseText ? qt.
|
|
31
|
+
error: "" === e.responseText ? qt.za : qt.Ba,
|
|
32
32
|
response: e.responseText
|
|
33
33
|
};
|
|
34
|
-
t.
|
|
34
|
+
t.O(n, r);
|
|
35
35
|
}
|
|
36
|
-
o && t.
|
|
36
|
+
o && t.O(o, r);
|
|
37
37
|
}
|
|
38
|
-
"function" == typeof t.
|
|
38
|
+
"function" == typeof t.ei && t.ei(!0);
|
|
39
39
|
} else r();
|
|
40
40
|
}),
|
|
41
41
|
(e.onerror = () => {
|
|
@@ -53,7 +53,7 @@ const b = {
|
|
|
53
53
|
e.send(o);
|
|
54
54
|
}
|
|
55
55
|
} catch (t) {
|
|
56
|
-
r.
|
|
56
|
+
r.j.error(`Network request error: ${t.message}`);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
};
|
|
@@ -72,4 +72,4 @@ export const readResponseHeaders = t => {
|
|
|
72
72
|
(e[r] = n));
|
|
73
73
|
return e;
|
|
74
74
|
};
|
|
75
|
-
export default
|
|
75
|
+
export default C;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { STORAGE_KEYS as i } from "../managers/storage-manager.js";
|
|
2
|
+
const T = {
|
|
3
|
+
Qs: { Xa: "d", Os: "cc", xi: "ff", Xi: "t" },
|
|
4
|
+
Lu: e => {
|
|
5
|
+
if (e) return e.v(i.k.Pa);
|
|
6
|
+
},
|
|
7
|
+
qu: (e, t) => {
|
|
8
|
+
e && e.D(i.k.Pa, t);
|
|
9
|
+
},
|
|
10
|
+
Ea: (e, t) => {
|
|
11
|
+
if (!e || !t) return -1;
|
|
12
|
+
const r = T.Lu(e);
|
|
13
|
+
if (null == r) return -1;
|
|
14
|
+
const s = r[t];
|
|
15
|
+
return null == s || isNaN(s) ? -1 : s;
|
|
16
|
+
},
|
|
17
|
+
Xs: (e, t, r) => {
|
|
18
|
+
if (!e || !t) return;
|
|
19
|
+
let s = T.Lu(e);
|
|
20
|
+
null == s && (s = {}), (s[t] = r), T.qu(e, s);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
export default T;
|
package/src/util/string-utils.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import Oe from "./base-device-parser.js";
|
|
2
|
-
import { Browsers as
|
|
3
|
-
export default class
|
|
2
|
+
import { Browsers as ai, OperatingSystems as W } from "./device-constants.js";
|
|
3
|
+
export default class ei extends Oe {
|
|
4
4
|
constructor() {
|
|
5
|
-
super(), (this.
|
|
5
|
+
super(), (this.Vu = ei.Uu(navigator.userAgent || ""));
|
|
6
6
|
}
|
|
7
7
|
tf() {
|
|
8
|
-
return this.
|
|
8
|
+
return this.Vu[0] || "Unknown Browser";
|
|
9
9
|
}
|
|
10
10
|
ef() {
|
|
11
|
-
return this.
|
|
11
|
+
return this.Vu[1] || "Unknown Version";
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
ua(r) {
|
|
14
14
|
for (let e = 0; e < r.length; e++) {
|
|
15
15
|
let n = r[e].string,
|
|
16
|
-
i =
|
|
16
|
+
i = ei.rf(n, r[e]);
|
|
17
17
|
if (i)
|
|
18
18
|
return (
|
|
19
|
-
i ===
|
|
19
|
+
i === W.jg && navigator.maxTouchPoints > 1 && (i = W.fe),
|
|
20
20
|
Promise.resolve(i)
|
|
21
21
|
);
|
|
22
22
|
}
|
|
23
23
|
return Promise.resolve(navigator.platform);
|
|
24
24
|
}
|
|
25
|
-
static
|
|
25
|
+
static Uu(r) {
|
|
26
26
|
let e,
|
|
27
27
|
n =
|
|
28
28
|
r.match(
|
|
@@ -30,7 +30,7 @@ export default class ni extends Oe {
|
|
|
30
30
|
) || [];
|
|
31
31
|
if (/trident/i.test(n[1]))
|
|
32
32
|
return (
|
|
33
|
-
(e = /\brv[ :]+(\.?\d+(\.\d+)*)/g.exec(r) || []), [
|
|
33
|
+
(e = /\brv[ :]+(\.?\d+(\.\d+)*)/g.exec(r) || []), [ai.Pg, e[1] || ""]
|
|
34
34
|
);
|
|
35
35
|
if (-1 !== r.indexOf("(Web0S; Linux/SmartTV)"))
|
|
36
36
|
return ["LG Smart TV", null];
|
|
@@ -45,38 +45,38 @@ export default class ni extends Oe {
|
|
|
45
45
|
if (r.match(/\b(Roku)\b/)) return ["Roku", null];
|
|
46
46
|
if (r.match(/\bAFTM\b/)) return ["Amazon Fire Stick", null];
|
|
47
47
|
if (
|
|
48
|
-
n[1] ===
|
|
48
|
+
n[1] === ai.OE &&
|
|
49
49
|
((e = r.match(/\b(OPR|Edge|EdgA|Edg|UCBrowser)\/(\.?\d+(\.\d+)*)/)),
|
|
50
50
|
null != e)
|
|
51
51
|
)
|
|
52
52
|
return (
|
|
53
53
|
(e = e.slice(1)),
|
|
54
|
-
(e[0] = e[0].replace("OPR",
|
|
55
|
-
(e[0] = e[0].replace("EdgA",
|
|
56
|
-
"Edg" === e[0] && (e[0] =
|
|
54
|
+
(e[0] = e[0].replace("OPR", ai.IE)),
|
|
55
|
+
(e[0] = e[0].replace("EdgA", ai.RE)),
|
|
56
|
+
"Edg" === e[0] && (e[0] = ai.RE),
|
|
57
57
|
[e[0], e[1]]
|
|
58
58
|
);
|
|
59
59
|
if (
|
|
60
|
-
n[1] ===
|
|
60
|
+
n[1] === ai.kg &&
|
|
61
61
|
((e = r.match(/\b(EdgiOS)\/(\.?\d+(\.\d+)*)/)), null != e)
|
|
62
62
|
)
|
|
63
63
|
return (
|
|
64
|
-
(e = e.slice(1)), (e[0] = e[0].replace("EdgiOS",
|
|
64
|
+
(e = e.slice(1)), (e[0] = e[0].replace("EdgiOS", ai.RE)), [e[0], e[1]]
|
|
65
65
|
);
|
|
66
66
|
if (
|
|
67
67
|
((n = n[2] ? [n[1], n[2]] : [null, null]),
|
|
68
|
-
n[0] ===
|
|
68
|
+
n[0] === ai.kg &&
|
|
69
69
|
null != (e = r.match(/version\/(\.?\d+(\.\d+)*)/i)) &&
|
|
70
70
|
n.splice(1, 1, e[1]),
|
|
71
71
|
null != (e = r.match(/\b(UCBrowser)\/(\.?\d+(\.\d+)*)/)) &&
|
|
72
72
|
n.splice(1, 1, e[2]),
|
|
73
|
-
n[0] ===
|
|
73
|
+
n[0] === ai.IE && null != (e = r.match(/mini\/(\.?\d+(\.\d+)*)/i)))
|
|
74
74
|
)
|
|
75
75
|
return ["Opera Mini", e[1] || ""];
|
|
76
76
|
if (n[0]) {
|
|
77
77
|
const r = n[0].toLowerCase();
|
|
78
|
-
"msie" === r && (n[0] =
|
|
79
|
-
"crios" === r && (n[0] =
|
|
78
|
+
"msie" === r && (n[0] = ai.Pg),
|
|
79
|
+
"crios" === r && (n[0] = ai.OE),
|
|
80
80
|
"tizen" === r && ((n[0] = "Samsung Smart TV"), (n[1] = null)),
|
|
81
81
|
"samsungbrowser" === r && (n[0] = "Samsung Browser");
|
|
82
82
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isArray as p,
|
|
3
3
|
isDate as Nt,
|
|
4
|
-
isObject as
|
|
5
|
-
keys as
|
|
4
|
+
isObject as Ct,
|
|
5
|
+
keys as oo
|
|
6
6
|
} from "./code-utils.js";
|
|
7
7
|
import { getByteLength as U } from "./string-utils.js";
|
|
8
8
|
import r from "../../shared-lib/braze-shared-lib.js";
|
|
9
|
-
import { toValidBackendTimeString as
|
|
10
|
-
import { BRAZE_ACTIONS as
|
|
11
|
-
import { SET_CUSTOM_USER_ATTRIBUTE_STRING as
|
|
9
|
+
import { toValidBackendTimeString as kt } from "./date-utils.js";
|
|
10
|
+
import { BRAZE_ACTIONS as _ } from "./braze-actions.js";
|
|
11
|
+
import { SET_CUSTOM_USER_ATTRIBUTE_STRING as $t } from "../common/constants.js";
|
|
12
12
|
export const CUSTOM_DATA_REGEX = /^[^\x00-\x1F\x22]+$/;
|
|
13
13
|
export const CUSTOM_ATTRIBUTE_SPECIAL_CHARS_REGEX = /[$.]/;
|
|
14
14
|
export const CUSTOM_ATTRIBUTE_RESERVED_OPERATORS = [
|
|
@@ -32,14 +32,14 @@ export function validateCustomString(t, e, n) {
|
|
|
32
32
|
null != t &&
|
|
33
33
|
"string" == typeof t &&
|
|
34
34
|
("" === t || t.match(CUSTOM_DATA_REGEX));
|
|
35
|
-
return o || r.
|
|
35
|
+
return o || r.j.error(`Cannot ${e} because ${n} "${t}" is invalid.`), o;
|
|
36
36
|
}
|
|
37
37
|
export function validateCustomAttributeKey(t) {
|
|
38
38
|
return (
|
|
39
39
|
null != t &&
|
|
40
40
|
t.match(CUSTOM_ATTRIBUTE_SPECIAL_CHARS_REGEX) &&
|
|
41
41
|
-1 === CUSTOM_ATTRIBUTE_RESERVED_OPERATORS.indexOf(t) &&
|
|
42
|
-
r.
|
|
42
|
+
r.j.warn("Custom attribute keys cannot contain '$' or '.'"),
|
|
43
43
|
validateCustomString(t, "set custom user attribute", "the given key")
|
|
44
44
|
);
|
|
45
45
|
}
|
|
@@ -53,22 +53,22 @@ export function _validateNestedProperties(t, e, n) {
|
|
|
53
53
|
const o = -1 !== n;
|
|
54
54
|
if (o && n > 50)
|
|
55
55
|
return (
|
|
56
|
-
r.
|
|
56
|
+
r.j.error("Nested attributes cannot be more than 50 levels deep."), !1
|
|
57
57
|
);
|
|
58
58
|
const i = o ? n + 1 : -1;
|
|
59
59
|
if (p(t) && p(e)) {
|
|
60
60
|
for (let r = 0; r < t.length && r < e.length; r++)
|
|
61
61
|
if (
|
|
62
|
-
(Nt(t[r]) && (e[r] =
|
|
62
|
+
(Nt(t[r]) && (e[r] = kt(t[r])),
|
|
63
63
|
!_validateNestedProperties(t[r], e[r], i))
|
|
64
64
|
)
|
|
65
65
|
return !1;
|
|
66
66
|
} else {
|
|
67
|
-
if (!
|
|
68
|
-
for (const r of
|
|
67
|
+
if (!Ct(t)) return validatePropertyType(t);
|
|
68
|
+
for (const r of oo(t)) {
|
|
69
69
|
if (o && !validateCustomAttributeKey(r)) return !1;
|
|
70
70
|
if (
|
|
71
|
-
(Nt(t[r]) && (e[r] =
|
|
71
|
+
(Nt(t[r]) && (e[r] = kt(t[r])),
|
|
72
72
|
!_validateNestedProperties(t[r], e[r], i))
|
|
73
73
|
)
|
|
74
74
|
return !1;
|
|
@@ -80,29 +80,29 @@ export function _validateEventPropertyValue(t, e, n, o, i) {
|
|
|
80
80
|
let a;
|
|
81
81
|
return (
|
|
82
82
|
(a =
|
|
83
|
-
|
|
83
|
+
Ct(t) || p(t)
|
|
84
84
|
? _validateNestedProperties(t, e, i ? 1 : -1)
|
|
85
85
|
: validatePropertyType(t)),
|
|
86
|
-
a || r.
|
|
86
|
+
a || r.j.error(`Cannot ${n} because ${o} "${t}" is invalid.`),
|
|
87
87
|
a
|
|
88
88
|
);
|
|
89
89
|
}
|
|
90
90
|
export function validateStandardString(t, e, n, o) {
|
|
91
91
|
const i = "string" == typeof t || (null === t && o);
|
|
92
|
-
return i || r.
|
|
92
|
+
return i || r.j.error(`Cannot ${e} because ${n} "${t}" is invalid.`), i;
|
|
93
93
|
}
|
|
94
94
|
export function validateCustomProperties(t, e, n, o, i) {
|
|
95
95
|
if ((null == t && (t = {}), "object" != typeof t || p(t)))
|
|
96
96
|
return (
|
|
97
|
-
r.
|
|
97
|
+
r.j.error(`${e} requires that ${n} be an object. Ignoring ${i}.`),
|
|
98
98
|
[!1, null]
|
|
99
99
|
);
|
|
100
100
|
let a, s;
|
|
101
|
-
e ===
|
|
101
|
+
e === $t ? ((a = 76800), (s = "75KB")) : ((a = 51200), (s = "50KB"));
|
|
102
102
|
const u = JSON.stringify(t);
|
|
103
103
|
if (U(u) > a)
|
|
104
104
|
return (
|
|
105
|
-
r.
|
|
105
|
+
r.j.error(
|
|
106
106
|
`Could not ${o} because ${n} was greater than the max size of ${s}.`
|
|
107
107
|
),
|
|
108
108
|
[!1, null]
|
|
@@ -112,27 +112,27 @@ export function validateCustomProperties(t, e, n, o, i) {
|
|
|
112
112
|
l = JSON.parse(u);
|
|
113
113
|
} catch (t) {
|
|
114
114
|
return (
|
|
115
|
-
r.
|
|
115
|
+
r.j.error(`Could not ${o} because ${n} did not contain valid JSON.`),
|
|
116
116
|
[!1, null]
|
|
117
117
|
);
|
|
118
118
|
}
|
|
119
119
|
for (let r in t) {
|
|
120
|
-
if (e ===
|
|
120
|
+
if (e === $t && !validateCustomAttributeKey(r)) return [!1, null];
|
|
121
121
|
if (!validateCustomString(r, o, `the ${i} property name`))
|
|
122
122
|
return [!1, null];
|
|
123
123
|
const n = t[r];
|
|
124
|
-
if (e !==
|
|
124
|
+
if (e !== $t && null == n) {
|
|
125
125
|
delete t[r], delete l[r];
|
|
126
126
|
continue;
|
|
127
127
|
}
|
|
128
|
-
Nt(n) && (l[r] =
|
|
128
|
+
Nt(n) && (l[r] = kt(n));
|
|
129
129
|
if (
|
|
130
130
|
!_validateEventPropertyValue(
|
|
131
131
|
n,
|
|
132
132
|
l[r],
|
|
133
133
|
o,
|
|
134
134
|
`the ${i} property "${r}"`,
|
|
135
|
-
e ===
|
|
135
|
+
e === $t
|
|
136
136
|
)
|
|
137
137
|
)
|
|
138
138
|
return [!1, null];
|
|
@@ -143,7 +143,7 @@ export function validateCustomAttributeArrayType(t, e) {
|
|
|
143
143
|
let n = !1,
|
|
144
144
|
o = !1;
|
|
145
145
|
const i = () => {
|
|
146
|
-
r.
|
|
146
|
+
r.j.error(
|
|
147
147
|
"Custom attribute arrays must be either string arrays or object arrays."
|
|
148
148
|
);
|
|
149
149
|
};
|
|
@@ -160,12 +160,12 @@ export function validateCustomAttributeArrayType(t, e) {
|
|
|
160
160
|
return [!1, !1];
|
|
161
161
|
n = !0;
|
|
162
162
|
} else {
|
|
163
|
-
if (!
|
|
163
|
+
if (!Ct(r)) return i(), [!1, !1];
|
|
164
164
|
if (n) return i(), [!1, !1];
|
|
165
165
|
if (
|
|
166
166
|
!validateCustomProperties(
|
|
167
167
|
r,
|
|
168
|
-
|
|
168
|
+
$t,
|
|
169
169
|
"attribute value",
|
|
170
170
|
`set custom user attribute "${t}"`,
|
|
171
171
|
"custom user attribute"
|
|
@@ -182,24 +182,24 @@ export function isValidEmail(t) {
|
|
|
182
182
|
);
|
|
183
183
|
}
|
|
184
184
|
export function isValidBrazeActionJson(t) {
|
|
185
|
-
if (!(
|
|
186
|
-
switch (t[
|
|
187
|
-
case
|
|
188
|
-
if (
|
|
185
|
+
if (!(_.properties.type in t)) return !1;
|
|
186
|
+
switch (t[_.properties.type]) {
|
|
187
|
+
case _.types.le:
|
|
188
|
+
if (_.properties.ce in t) return !0;
|
|
189
189
|
break;
|
|
190
|
-
case
|
|
191
|
-
case
|
|
192
|
-
case
|
|
193
|
-
case
|
|
194
|
-
case
|
|
195
|
-
case
|
|
196
|
-
case
|
|
197
|
-
case
|
|
198
|
-
case
|
|
199
|
-
case
|
|
200
|
-
if (
|
|
190
|
+
case _.types.logCustomEvent:
|
|
191
|
+
case _.types.setEmailNotificationSubscriptionType:
|
|
192
|
+
case _.types.setPushNotificationSubscriptionType:
|
|
193
|
+
case _.types.setCustomUserAttribute:
|
|
194
|
+
case _.types.addToSubscriptionGroup:
|
|
195
|
+
case _.types.removeFromSubscriptionGroup:
|
|
196
|
+
case _.types.addToCustomAttributeArray:
|
|
197
|
+
case _.types.removeFromCustomAttributeArray:
|
|
198
|
+
case _.types.de:
|
|
199
|
+
case _.types.pe:
|
|
200
|
+
if (_.properties.me in t) return !0;
|
|
201
201
|
break;
|
|
202
|
-
case
|
|
202
|
+
case _.types.requestPushPermission:
|
|
203
203
|
return !0;
|
|
204
204
|
default:
|
|
205
205
|
return !1;
|
|
@@ -209,8 +209,8 @@ export function isValidBrazeActionJson(t) {
|
|
|
209
209
|
export function isValidBrazeActionType(t) {
|
|
210
210
|
let e = !1;
|
|
211
211
|
return (
|
|
212
|
-
Object.keys(
|
|
213
|
-
|
|
212
|
+
Object.keys(_.types).forEach(r => {
|
|
213
|
+
_.types[r] !== t.toString() || (e = !0);
|
|
214
214
|
}),
|
|
215
215
|
e
|
|
216
216
|
);
|
package/src/util/window-utils.js
CHANGED