@braze/web-sdk 4.10.1 → 4.10.2
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 +9 -9
- package/package.json +1 -1
- package/shared-lib/braze-shared-lib.js +8 -1
- package/shared-lib/encoding-utils.js +12 -1
- package/shared-lib/event-types.js +34 -1
- package/shared-lib/guid.js +10 -1
- package/shared-lib/index.js +6 -0
- package/shared-lib/indexed-db-adapter.js +352 -1
- package/shared-lib/logger.js +38 -1
- package/shared-lib/supported-options.js +27 -1
- package/shared-lib/types.js +1 -1
- package/src/Card/card-manager-factory.js +14 -1
- package/src/Card/card-manager.js +78 -1
- package/src/Card/display/card-display.js +138 -1
- package/src/Card/index.js +6 -1
- package/src/Card/log-card-click.js +11 -1
- package/src/Card/log-card-dismissal.js +11 -1
- package/src/Card/log-card-impressions.js +13 -1
- package/src/Card/log-content-card-click.js +4 -1
- package/src/Card/log-content-card-impressions.js +4 -1
- package/src/Card/models/banner.js +31 -1
- package/src/Card/models/captioned-image.js +33 -1
- package/src/Card/models/card.js +196 -1
- package/src/Card/models/classic-card.js +32 -1
- package/src/Card/models/control-card.js +23 -1
- package/src/Card/models/image-only.js +32 -1
- package/src/Card/models/index.js +6 -1
- package/src/Card/types.js +1 -1
- package/src/Card/util/card-factory.js +104 -1
- package/src/ContentCards/content-cards-provider-factory.js +20 -1
- package/src/ContentCards/content-cards-provider.js +391 -1
- package/src/ContentCards/content-cards.js +24 -1
- package/src/ContentCards/get-cached-content-cards.js +5 -1
- package/src/ContentCards/index.js +8 -1
- package/src/ContentCards/log-content-cards-displayed.js +5 -1
- package/src/ContentCards/request-content-cards-refresh.js +5 -1
- package/src/ContentCards/subscribe-to-content-cards-updates.js +17 -1
- package/src/ContentCards/types.js +1 -1
- package/src/ContentCards/ui/hide-content-cards.js +8 -1
- package/src/ContentCards/ui/show-content-cards.js +77 -1
- package/src/ContentCards/ui/toggle-content-cards.js +8 -1
- package/src/Core/add-sdk-metadata.js +26 -1
- package/src/Core/braze-sdk-metadata.js +10 -1
- package/src/Core/change-user.js +17 -1
- package/src/Core/destroy.js +5 -1
- package/src/Core/device-properties.js +9 -1
- package/src/Core/disable-sdk.js +15 -1
- package/src/Core/enable-sdk.js +11 -1
- package/src/Core/get-device-id.js +13 -1
- package/src/Core/get-user.js +4 -1
- package/src/Core/handle-braze-action.js +87 -1
- package/src/Core/index.js +23 -1
- package/src/Core/initialize.js +4 -1
- package/src/Core/is-disabled.js +4 -1
- package/src/Core/log-custom-event.js +38 -1
- package/src/Core/log-purchase.js +245 -1
- package/src/Core/open-session.js +25 -1
- package/src/Core/remove-all-subscriptions.js +4 -1
- package/src/Core/remove-subscription.js +4 -1
- package/src/Core/request-immediate-data-flush.js +6 -1
- package/src/Core/set-logger.js +4 -1
- package/src/Core/set-sdk-authentication-signature.js +8 -1
- package/src/Core/subscribe-to-sdk-authentication-failures.js +6 -1
- package/src/Core/toggle-logging.js +4 -1
- package/src/Core/types.js +1 -1
- package/src/Core/wipe-data.js +16 -1
- package/src/FeatureFlags/feature-flag-factory.js +24 -1
- package/src/FeatureFlags/feature-flag.js +64 -1
- package/src/FeatureFlags/feature-flags-provider-factory.js +19 -1
- package/src/FeatureFlags/feature-flags-provider.js +145 -1
- package/src/FeatureFlags/get-all-feature-flags.js +12 -1
- package/src/FeatureFlags/get-feature-flag.js +12 -1
- package/src/FeatureFlags/index.js +6 -1
- package/src/FeatureFlags/log-feature-flag-impression.js +23 -1
- package/src/FeatureFlags/refresh-feature-flags.js +9 -1
- package/src/FeatureFlags/subscribe-to-feature-flags-updates.js +9 -1
- package/src/FeatureFlags/types.js +1 -1
- package/src/Feed/feed-provider-factory.js +18 -1
- package/src/Feed/feed-provider.js +90 -1
- package/src/Feed/feed.js +20 -1
- package/src/Feed/get-cached-feed.js +5 -1
- package/src/Feed/index.js +8 -1
- package/src/Feed/log-feed-displayed.js +7 -1
- package/src/Feed/request-feed-refresh.js +5 -1
- package/src/Feed/subscribe-to-feed-updates.js +5 -1
- package/src/Feed/types.js +1 -1
- package/src/Feed/ui/hide-feed.js +7 -1
- package/src/Feed/ui/show-feed.js +96 -1
- package/src/Feed/ui/toggle-feed.js +8 -1
- package/src/InAppMessage/defer-in-app-message.js +13 -1
- package/src/InAppMessage/display/get-animation-effect.js +19 -1
- package/src/InAppMessage/display/html-message-to-html.js +244 -1
- package/src/InAppMessage/display/in-app-message-to-html.js +188 -1
- package/src/InAppMessage/display/modal-utils.js +73 -1
- package/src/InAppMessage/get-deferred-in-app-message.js +5 -1
- package/src/InAppMessage/in-app-message-factory.js +166 -1
- package/src/InAppMessage/in-app-message-manager-factory.js +16 -1
- package/src/InAppMessage/in-app-message-manager.js +248 -1
- package/src/InAppMessage/index.js +16 -1
- package/src/InAppMessage/log-in-app-message-button-click.js +27 -1
- package/src/InAppMessage/log-in-app-message-click.js +19 -1
- package/src/InAppMessage/log-in-app-message-html-click.js +23 -1
- package/src/InAppMessage/log-in-app-message-impression.js +13 -1
- package/src/InAppMessage/models/control-message.js +11 -1
- package/src/InAppMessage/models/full-screen-message.js +105 -1
- package/src/InAppMessage/models/html-message.js +68 -1
- package/src/InAppMessage/models/in-app-message-button.js +47 -1
- package/src/InAppMessage/models/in-app-message.js +382 -1
- package/src/InAppMessage/models/modal-message.js +101 -1
- package/src/InAppMessage/models/slide-up-message.js +84 -1
- package/src/InAppMessage/models/templated-in-app-message.js +19 -1
- package/src/InAppMessage/subscribe-to-in-app-message.js +10 -1
- package/src/InAppMessage/types.js +1 -1
- package/src/InAppMessage/ui/automatically-show-in-app-messages.js +15 -1
- package/src/InAppMessage/ui/show-in-app-message.js +181 -1
- package/src/InAppMessage/utils/in-app-message-utils.js +1 -1
- package/src/Push/index.js +5 -1
- package/src/Push/is-push-blocked.js +5 -1
- package/src/Push/is-push-permission-granted.js +5 -1
- package/src/Push/is-push-supported.js +5 -1
- package/src/Push/push-manager-factory.js +30 -1
- package/src/Push/push-manager.js +387 -1
- package/src/Push/request-push-permission.js +9 -1
- package/src/Push/types.js +1 -1
- package/src/Push/unregister-push.js +5 -1
- package/src/Push/utils/push-utils.js +36 -1
- package/src/User/index.js +1 -1
- package/src/User/types.js +1 -1
- package/src/User/user-manager.js +73 -1
- package/src/User/user.js +302 -1
- package/src/common/base-feed.js +28 -1
- package/src/common/base-provider.js +6 -1
- package/src/common/constants.js +14 -1
- package/src/common/event-logger.js +31 -1
- package/src/common/feed-display.js +210 -1
- package/src/common/translations.js +148 -1
- package/src/common/types.js +1 -1
- package/src/index.js +9 -1
- package/src/l10n/l10n-manager-factory.js +22 -1
- package/src/l10n/l10n-manager.js +25 -1
- package/src/l10n/types.js +1 -1
- package/src/managers/auth-manager.js +51 -1
- package/src/managers/braze-instance.js +331 -1
- package/src/managers/device-manager.js +85 -1
- package/src/managers/network-manager.js +256 -1
- package/src/managers/server-config-manager.js +108 -1
- package/src/managers/session-manager.js +75 -1
- package/src/managers/storage-manager-factory.js +42 -1
- package/src/managers/storage-manager.js +419 -1
- package/src/managers/subscription-manager.js +28 -1
- package/src/managers/types.js +1 -1
- package/src/models/backend-errors.js +8 -1
- package/src/models/braze-event.js +47 -1
- package/src/models/braze-sdk-metadata.js +10 -1
- package/src/models/device.js +18 -1
- package/src/models/identifier.js +19 -1
- package/src/models/push-token.js +27 -1
- package/src/models/request-result.js +8 -1
- package/src/models/server-config.js +48 -1
- package/src/models/types.js +1 -1
- package/src/request-controller.js +311 -1
- package/src/triggers/models/custom-event-data.js +14 -1
- package/src/triggers/models/custom-event-property-data.js +21 -1
- package/src/triggers/models/filter-set.js +55 -1
- package/src/triggers/models/filter.js +102 -1
- package/src/triggers/models/in-app-message-click-data.js +25 -1
- package/src/triggers/models/purchase-data.js +14 -1
- package/src/triggers/models/purchase-property-data.js +21 -1
- package/src/triggers/models/push-click-data.js +15 -1
- package/src/triggers/models/trigger-condition.js +105 -1
- package/src/triggers/models/trigger-events.js +8 -1
- package/src/triggers/models/trigger.js +122 -1
- package/src/triggers/triggers-provider-factory.js +34 -1
- package/src/triggers/triggers-provider.js +326 -1
- package/src/triggers/types.js +1 -1
- package/src/types.js +1 -1
- package/src/ui/js/attach-css.js +13 -1
- package/src/ui/js/feed-css.js +12 -1
- package/src/ui/js/iam-css.js +12 -1
- package/src/ui/js/index.js +3 -1
- package/src/ui/js/load-font-awesome.js +13 -1
- package/src/util/base-device-parser.js +14 -1
- package/src/util/braze-actions.js +84 -1
- package/src/util/browser-detector.js +84 -1
- package/src/util/client-hints-parser.js +66 -1
- package/src/util/code-utils.js +100 -1
- package/src/util/color-utils.js +29 -1
- package/src/util/component-utils.js +26 -1
- package/src/util/date-utils.js +28 -1
- package/src/util/deprecation-utils.js +5 -1
- package/src/util/device-constants.js +14 -1
- package/src/util/dom-utils.js +91 -1
- package/src/util/error-utils.js +2 -1
- package/src/util/key-codes.js +1 -1
- package/src/util/math.js +5 -1
- package/src/util/net.js +71 -1
- package/src/util/request-header-utils.js +46 -1
- package/src/util/string-utils.js +22 -1
- package/src/util/types.js +1 -1
- package/src/util/url-utils.js +20 -1
- package/src/util/user-agent-parser.js +85 -1
- package/src/util/validation-utils.js +217 -1
- package/src/util/window-utils.js +34 -1
package/src/util/dom-utils.js
CHANGED
|
@@ -1 +1,91 @@
|
|
|
1
|
-
import r from"../../shared-lib/braze-shared-lib.js";
|
|
1
|
+
import r from "../../shared-lib/braze-shared-lib.js";
|
|
2
|
+
import { getErrorMessage as ei } from "./error-utils.js";
|
|
3
|
+
export function _isInView(t, n = !1, e = !1, s = !1) {
|
|
4
|
+
if (null == t) return !1;
|
|
5
|
+
(n = n || !1), (e = e || !1);
|
|
6
|
+
const i = t.getBoundingClientRect();
|
|
7
|
+
return (
|
|
8
|
+
null != i &&
|
|
9
|
+
((i.top >= 0 &&
|
|
10
|
+
i.top <= (window.innerHeight || document.documentElement.clientHeight)) ||
|
|
11
|
+
!n) &&
|
|
12
|
+
(i.left >= 0 || !s) &&
|
|
13
|
+
((i.bottom >= 0 &&
|
|
14
|
+
i.bottom <=
|
|
15
|
+
(window.innerHeight || document.documentElement.clientHeight)) ||
|
|
16
|
+
!e) &&
|
|
17
|
+
(i.right <= (window.innerWidth || document.documentElement.clientWidth) ||
|
|
18
|
+
!s)
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
export const DOMUtils = { lc: null, no: _isInView };
|
|
22
|
+
export const DIRECTIONS = { Oe: "up", Qe: "down", W: "left", X: "right" };
|
|
23
|
+
export function supportsPassive() {
|
|
24
|
+
if (null == DOMUtils.lc) {
|
|
25
|
+
DOMUtils.lc = !1;
|
|
26
|
+
try {
|
|
27
|
+
const t = Object.defineProperty({}, "passive", {
|
|
28
|
+
get: () => {
|
|
29
|
+
DOMUtils.lc = !0;
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
window.addEventListener("testPassive", () => {}, t),
|
|
33
|
+
window.removeEventListener("testPassive", () => {}, t);
|
|
34
|
+
} catch (t) {
|
|
35
|
+
r.j.error(ei(t));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return DOMUtils.lc;
|
|
39
|
+
}
|
|
40
|
+
export function addPassiveEventListener(t, n, e = () => {}) {
|
|
41
|
+
t.addEventListener(n, e, !!supportsPassive() && { passive: !0 });
|
|
42
|
+
}
|
|
43
|
+
export function topIsInView(t) {
|
|
44
|
+
return DOMUtils.no(t, !0, !1, !1);
|
|
45
|
+
}
|
|
46
|
+
export function bottomIsInView(t) {
|
|
47
|
+
return DOMUtils.no(t, !1, !0, !1);
|
|
48
|
+
}
|
|
49
|
+
export function clickElement(t) {
|
|
50
|
+
if (t.onclick) {
|
|
51
|
+
const n = document.createEvent("MouseEvents");
|
|
52
|
+
n.initEvent("click", !0, !0), t.onclick.apply(t, [n]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export function detectSwipe(t, n, e) {
|
|
56
|
+
let s = null,
|
|
57
|
+
i = null;
|
|
58
|
+
addPassiveEventListener(t, "touchstart", (t) => {
|
|
59
|
+
(s = t.touches[0].clientX), (i = t.touches[0].clientY);
|
|
60
|
+
}),
|
|
61
|
+
addPassiveEventListener(t, "touchmove", (o) => {
|
|
62
|
+
if (null == s || null == i) return;
|
|
63
|
+
const l = s - o.touches[0].clientX,
|
|
64
|
+
r = i - o.touches[0].clientY;
|
|
65
|
+
Math.abs(l) > Math.abs(r) && Math.abs(l) >= 25
|
|
66
|
+
? (((l > 0 && n === DIRECTIONS.W) || (l < 0 && n === DIRECTIONS.X)) &&
|
|
67
|
+
e(o),
|
|
68
|
+
(s = null),
|
|
69
|
+
(i = null))
|
|
70
|
+
: Math.abs(r) >= 25 &&
|
|
71
|
+
(((r > 0 &&
|
|
72
|
+
n === DIRECTIONS.Oe &&
|
|
73
|
+
t.scrollTop === t.scrollHeight - t.offsetHeight) ||
|
|
74
|
+
(r < 0 && n === DIRECTIONS.Qe && 0 === t.scrollTop)) &&
|
|
75
|
+
e(o),
|
|
76
|
+
(s = null),
|
|
77
|
+
(i = null));
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
export function buildSvg(t, n, e) {
|
|
81
|
+
const s = "http://www.w3.org/2000/svg",
|
|
82
|
+
i = document.createElementNS(s, "svg");
|
|
83
|
+
i.setAttribute("viewBox", t), i.setAttribute("xmlns", s);
|
|
84
|
+
const o = document.createElementNS(s, "path");
|
|
85
|
+
return (
|
|
86
|
+
o.setAttribute("d", n),
|
|
87
|
+
null != e && o.setAttribute("fill", e),
|
|
88
|
+
i.appendChild(o),
|
|
89
|
+
i
|
|
90
|
+
);
|
|
91
|
+
}
|
package/src/util/error-utils.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export const getErrorMessage=
|
|
1
|
+
export const getErrorMessage = (r) =>
|
|
2
|
+
r instanceof Error ? r.message : String(r);
|
package/src/util/key-codes.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const KeyCodes={Fo:32,oo:9,To:13,_h:27};
|
|
1
|
+
export const KeyCodes = { Fo: 32, oo: 9, To: 13, _h: 27 };
|
package/src/util/math.js
CHANGED
package/src/util/net.js
CHANGED
|
@@ -1 +1,71 @@
|
|
|
1
|
-
import r from"../../shared-lib/braze-shared-lib.js";
|
|
1
|
+
import r from "../../shared-lib/braze-shared-lib.js";
|
|
2
|
+
import qt from "../models/backend-errors.js";
|
|
3
|
+
import { getErrorMessage as ei } from "./error-utils.js";
|
|
4
|
+
const C = {
|
|
5
|
+
Xs: (t) => {
|
|
6
|
+
let e, o;
|
|
7
|
+
try {
|
|
8
|
+
const s = () => {
|
|
9
|
+
r.j.error("This browser does not have any supported ajax options!");
|
|
10
|
+
};
|
|
11
|
+
let n = !1;
|
|
12
|
+
if ((window.XMLHttpRequest && (n = !0), !n)) return void s();
|
|
13
|
+
e = new XMLHttpRequest();
|
|
14
|
+
const i = () => {
|
|
15
|
+
"function" == typeof t.error && t.error(e.status),
|
|
16
|
+
"function" == typeof t.ei && t.ei(!1);
|
|
17
|
+
};
|
|
18
|
+
(e.onload = () => {
|
|
19
|
+
let o = !1;
|
|
20
|
+
if (4 === e.readyState)
|
|
21
|
+
if (
|
|
22
|
+
((o = (e.status >= 200 && e.status < 300) || 304 === e.status), o)
|
|
23
|
+
) {
|
|
24
|
+
if ("function" == typeof t.O) {
|
|
25
|
+
let o, r;
|
|
26
|
+
try {
|
|
27
|
+
(o = JSON.parse(e.responseText)),
|
|
28
|
+
(r = e.getAllResponseHeaders());
|
|
29
|
+
} catch (o) {
|
|
30
|
+
const s = {
|
|
31
|
+
error: "" === e.responseText ? qt.Vh : qt.Zh,
|
|
32
|
+
response: e.responseText,
|
|
33
|
+
};
|
|
34
|
+
(0, t.O)(s, r);
|
|
35
|
+
}
|
|
36
|
+
o && t.O(o, r);
|
|
37
|
+
}
|
|
38
|
+
"function" == typeof t.ei && t.ei(!0);
|
|
39
|
+
} else i();
|
|
40
|
+
}),
|
|
41
|
+
(e.onerror = () => {
|
|
42
|
+
i();
|
|
43
|
+
}),
|
|
44
|
+
(e.ontimeout = () => {
|
|
45
|
+
i();
|
|
46
|
+
}),
|
|
47
|
+
(o = JSON.stringify(t.data)),
|
|
48
|
+
e.open("POST", t.url, !0),
|
|
49
|
+
e.setRequestHeader("Content-type", "application/json"),
|
|
50
|
+
e.setRequestHeader("X-Requested-With", "XMLHttpRequest");
|
|
51
|
+
const f = t.headers || [];
|
|
52
|
+
for (const t of f) e.setRequestHeader(t[0], t[1]);
|
|
53
|
+
e.send(o);
|
|
54
|
+
} catch (t) {
|
|
55
|
+
r.j.error(`Network request error: ${ei(t)}`);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
export const readResponseHeaders = (t) => {
|
|
60
|
+
const e = {},
|
|
61
|
+
o = t.toString().split("\r\n");
|
|
62
|
+
if (!o) return e;
|
|
63
|
+
let r, s;
|
|
64
|
+
for (const t of o)
|
|
65
|
+
t &&
|
|
66
|
+
((r = t.slice(0, t.indexOf(":")).toLowerCase().trim()),
|
|
67
|
+
(s = t.slice(t.indexOf(":") + 1).trim()),
|
|
68
|
+
(e[r] = s));
|
|
69
|
+
return e;
|
|
70
|
+
};
|
|
71
|
+
export default C;
|
|
@@ -1 +1,46 @@
|
|
|
1
|
-
import{REQUEST_ATTEMPT_DEFAULT as Ae}from"../common/constants.js";
|
|
1
|
+
import { REQUEST_ATTEMPT_DEFAULT as Ae } from "../common/constants.js";
|
|
2
|
+
import { STORAGE_KEYS as i } from "../managers/storage-manager.js";
|
|
3
|
+
const T = {
|
|
4
|
+
Os: { Na: "d", Ks: "cc", Si: "ff", Lr: "t" },
|
|
5
|
+
rm: (e) => {
|
|
6
|
+
if (e) return e.v(i.k.EE);
|
|
7
|
+
},
|
|
8
|
+
sm: (e) => {
|
|
9
|
+
if (e) return e.v(i.k.lE);
|
|
10
|
+
},
|
|
11
|
+
nm: (e, t) => {
|
|
12
|
+
e && e.D(i.k.EE, t);
|
|
13
|
+
},
|
|
14
|
+
um: (e, t) => {
|
|
15
|
+
e && e.D(i.k.lE, t);
|
|
16
|
+
},
|
|
17
|
+
La: (e, t) => {
|
|
18
|
+
if (!e || !t) return -1;
|
|
19
|
+
const r = T.rm(e);
|
|
20
|
+
if (null == r) return -1;
|
|
21
|
+
const s = r[t];
|
|
22
|
+
return null == s || isNaN(s) ? -1 : s;
|
|
23
|
+
},
|
|
24
|
+
Wa: (e, t) => {
|
|
25
|
+
let r = Ae;
|
|
26
|
+
if (!e || !t) return r;
|
|
27
|
+
const s = T.sm(e);
|
|
28
|
+
return null == s ? r : ((r = s[t]), null == r || isNaN(r) ? Ae : r);
|
|
29
|
+
},
|
|
30
|
+
Ws: (e, t, r) => {
|
|
31
|
+
if (!e || !t) return;
|
|
32
|
+
let s = T.rm(e);
|
|
33
|
+
null == s && (s = {}), (s[t] = r), T.nm(e, s);
|
|
34
|
+
},
|
|
35
|
+
si: (e, t, r) => {
|
|
36
|
+
if (!e || !t) return;
|
|
37
|
+
let s = T.sm(e);
|
|
38
|
+
null == s && (s = {}), (s[t] = r), T.um(e, s);
|
|
39
|
+
},
|
|
40
|
+
hi: (e, t) => {
|
|
41
|
+
if (!e || !t) return;
|
|
42
|
+
const r = T.Wa(e, t);
|
|
43
|
+
T.si(e, t, r + 1);
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
export default T;
|
package/src/util/string-utils.js
CHANGED
|
@@ -1 +1,22 @@
|
|
|
1
|
-
import r from"../../shared-lib/braze-shared-lib.js";
|
|
1
|
+
import r from "../../shared-lib/braze-shared-lib.js";
|
|
2
|
+
export function getByteLength(t) {
|
|
3
|
+
let e = t.length;
|
|
4
|
+
for (let r = t.length - 1; r >= 0; r--) {
|
|
5
|
+
const n = t.charCodeAt(r);
|
|
6
|
+
n > 127 && n <= 2047 ? e++ : n > 2047 && n <= 65535 && (e += 2),
|
|
7
|
+
n >= 56320 && n <= 57343 && r--;
|
|
8
|
+
}
|
|
9
|
+
return e;
|
|
10
|
+
}
|
|
11
|
+
export function decodeBrazeActions(t) {
|
|
12
|
+
try {
|
|
13
|
+
t = t.replace(/-/g, "+").replace(/_/g, "/");
|
|
14
|
+
const e = window.atob(t),
|
|
15
|
+
r = new Uint8Array(e.length);
|
|
16
|
+
for (let t = 0; t < e.length; t++) r[t] = e.charCodeAt(t);
|
|
17
|
+
const n = new Uint16Array(r.buffer);
|
|
18
|
+
return String.fromCharCode(...n);
|
|
19
|
+
} catch (t) {
|
|
20
|
+
return r.j.error("Unable to decode Base64: " + t), null;
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/util/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{};
|
|
1
|
+
export {};
|
package/src/util/url-utils.js
CHANGED
|
@@ -1 +1,20 @@
|
|
|
1
|
-
export function parseQueryStringKeyValues(t)
|
|
1
|
+
export function parseQueryStringKeyValues(t) {
|
|
2
|
+
null == t && (t = "");
|
|
3
|
+
const r = t.split("?").slice(1).join("?"),
|
|
4
|
+
n = {};
|
|
5
|
+
if (null != r) {
|
|
6
|
+
const t = r.split("&");
|
|
7
|
+
for (let r = 0; r < t.length; r++) {
|
|
8
|
+
const a = t[r].split("=");
|
|
9
|
+
"" !== a[0] && (n[a[0]] = a[1]);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return n;
|
|
13
|
+
}
|
|
14
|
+
export function isURIJavascriptOrData(t) {
|
|
15
|
+
return !(
|
|
16
|
+
!t ||
|
|
17
|
+
(0 !== (t = t.toString().toLowerCase()).lastIndexOf("javascript:", 0) &&
|
|
18
|
+
0 !== t.lastIndexOf("data:", 0))
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -1 +1,85 @@
|
|
|
1
|
-
import ge from"./base-device-parser.js";
|
|
1
|
+
import ge from "./base-device-parser.js";
|
|
2
|
+
import { Browsers as oi, OperatingSystems as W } from "./device-constants.js";
|
|
3
|
+
export default class ai extends ge {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(), (this.rd = ai.ic(navigator.userAgent || ""));
|
|
6
|
+
}
|
|
7
|
+
tf() {
|
|
8
|
+
return this.rd[0] || "Unknown Browser";
|
|
9
|
+
}
|
|
10
|
+
ef() {
|
|
11
|
+
return this.rd[1] || "Unknown Version";
|
|
12
|
+
}
|
|
13
|
+
Ta(r) {
|
|
14
|
+
for (let n = 0; n < r.length; n++) {
|
|
15
|
+
const e = r[n].string;
|
|
16
|
+
let i = ai.rf(e, r[n]);
|
|
17
|
+
if (i)
|
|
18
|
+
return (
|
|
19
|
+
i === W.kg && navigator.maxTouchPoints > 1 && (i = W.de),
|
|
20
|
+
Promise.resolve(i)
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
return Promise.resolve(navigator.platform);
|
|
24
|
+
}
|
|
25
|
+
static ic(r) {
|
|
26
|
+
let n,
|
|
27
|
+
e =
|
|
28
|
+
r.match(
|
|
29
|
+
/(samsungbrowser|tizen|roku|konqueror|icab|crios|opera|ucbrowser|chrome|safari|firefox|camino|msie|trident(?=\/))\/?\s*(\.?\d+(\.\d+)*)/i,
|
|
30
|
+
) || [];
|
|
31
|
+
if (e[1] && /trident/i.test(e[1]))
|
|
32
|
+
return (
|
|
33
|
+
(n = /\brv[ :]+(\.?\d+(\.\d+)*)/g.exec(r) || []), [oi.oc, n[1] || ""]
|
|
34
|
+
);
|
|
35
|
+
if (-1 !== r.indexOf("(Web0S; Linux/SmartTV)"))
|
|
36
|
+
return ["LG Smart TV", null];
|
|
37
|
+
if (-1 !== r.indexOf("CrKey")) return ["Chromecast", null];
|
|
38
|
+
if (
|
|
39
|
+
-1 !== r.indexOf("BRAVIA") ||
|
|
40
|
+
-1 !== r.indexOf("SonyCEBrowser") ||
|
|
41
|
+
-1 !== r.indexOf("SonyDTV")
|
|
42
|
+
)
|
|
43
|
+
return ["Sony Smart TV", null];
|
|
44
|
+
if (-1 !== r.indexOf("PhilipsTV")) return ["Philips Smart TV", null];
|
|
45
|
+
if (r.match(/\b(Roku)\b/)) return ["Roku", null];
|
|
46
|
+
if (r.match(/\bAFTM\b/)) return ["Amazon Fire Stick", null];
|
|
47
|
+
if (
|
|
48
|
+
e[1] === oi.pE &&
|
|
49
|
+
((n = r.match(/\b(OPR|Edge|EdgA|Edg|UCBrowser)\/(\.?\d+(\.\d+)*)/)),
|
|
50
|
+
null != n)
|
|
51
|
+
)
|
|
52
|
+
return (
|
|
53
|
+
(n = n.slice(1)),
|
|
54
|
+
(n[0] = n[0].replace("OPR", oi.FE)),
|
|
55
|
+
(n[0] = n[0].replace("EdgA", oi.xE)),
|
|
56
|
+
"Edg" === n[0] && (n[0] = oi.xE),
|
|
57
|
+
[n[0], n[1]]
|
|
58
|
+
);
|
|
59
|
+
if (
|
|
60
|
+
e[1] === oi.Bg &&
|
|
61
|
+
((n = r.match(/\b(EdgiOS)\/(\.?\d+(\.\d+)*)/)), null != n)
|
|
62
|
+
)
|
|
63
|
+
return (
|
|
64
|
+
(n = n.slice(1)), (n[0] = n[0].replace("EdgiOS", oi.xE)), [n[0], n[1]]
|
|
65
|
+
);
|
|
66
|
+
if (
|
|
67
|
+
((e = e[2] ? [e[1], e[2]] : [null, null]),
|
|
68
|
+
e[0] === oi.Bg &&
|
|
69
|
+
null != (n = r.match(/version\/(\.?\d+(\.\d+)*)/i)) &&
|
|
70
|
+
e.splice(1, 1, n[1]),
|
|
71
|
+
null != (n = r.match(/\b(UCBrowser)\/(\.?\d+(\.\d+)*)/)) &&
|
|
72
|
+
e.splice(1, 1, n[2]),
|
|
73
|
+
e[0] === oi.FE && null != (n = r.match(/mini\/(\.?\d+(\.\d+)*)/i)))
|
|
74
|
+
)
|
|
75
|
+
return ["Opera Mini", n[1] || ""];
|
|
76
|
+
if (e[0]) {
|
|
77
|
+
const r = e[0].toLowerCase();
|
|
78
|
+
"msie" === r && (e[0] = oi.oc),
|
|
79
|
+
"crios" === r && (e[0] = oi.pE),
|
|
80
|
+
"tizen" === r && ((e[0] = "Samsung Smart TV"), (e[1] = null)),
|
|
81
|
+
"samsungbrowser" === r && (e[0] = "Samsung Browser");
|
|
82
|
+
}
|
|
83
|
+
return e;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -1 +1,217 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
isArray as p,
|
|
3
|
+
isDate as yt,
|
|
4
|
+
isObject as Nt,
|
|
5
|
+
keys as oo,
|
|
6
|
+
} from "./code-utils.js";
|
|
7
|
+
import { getByteLength as U } from "./string-utils.js";
|
|
8
|
+
import r from "../../shared-lib/braze-shared-lib.js";
|
|
9
|
+
import { toValidBackendTimeString as $t } from "./date-utils.js";
|
|
10
|
+
import { BRAZE_ACTIONS as _ } from "./braze-actions.js";
|
|
11
|
+
import { SET_CUSTOM_USER_ATTRIBUTE_STRING as Ft } from "../common/constants.js";
|
|
12
|
+
export const CUSTOM_DATA_REGEX = /^[^\x00-\x1F\x22]+$/;
|
|
13
|
+
export const CUSTOM_ATTRIBUTE_SPECIAL_CHARS_REGEX = /[$.]/;
|
|
14
|
+
export const CUSTOM_ATTRIBUTE_RESERVED_OPERATORS = [
|
|
15
|
+
"$add",
|
|
16
|
+
"$update",
|
|
17
|
+
"$remove",
|
|
18
|
+
"$identifier_key",
|
|
19
|
+
"$identifier_value",
|
|
20
|
+
"$new_object",
|
|
21
|
+
"$time",
|
|
22
|
+
];
|
|
23
|
+
export const EMAIL_ADDRESS_REGEX = new RegExp(/^.+@.+\..+$/);
|
|
24
|
+
export const CUSTOM_PROPERTIES_MAX_SIZE_BYTES = 51200;
|
|
25
|
+
export const CUSTOM_PROPERTIES_MAX_SIZE_STRING = "50KB";
|
|
26
|
+
export const CUSTOM_ATTRIBUTES_MAX_SIZE_BYTES = 76800;
|
|
27
|
+
export const CUSTOM_ATTRIBUTES_MAX_SIZE_STRING = "75KB";
|
|
28
|
+
export const CUSTOM_ATTRIBUTE_MAX_DEPTH = 50;
|
|
29
|
+
export const BRAZE_ACTION_URI_REGEX = /^brazeActions:\/\/v\d+\//;
|
|
30
|
+
export function validateCustomString(t, e, n) {
|
|
31
|
+
const o =
|
|
32
|
+
null != t &&
|
|
33
|
+
"string" == typeof t &&
|
|
34
|
+
("" === t || null != t.match(CUSTOM_DATA_REGEX));
|
|
35
|
+
return o || r.j.error(`Cannot ${e} because ${n} "${t}" is invalid.`), o;
|
|
36
|
+
}
|
|
37
|
+
export function validateCustomAttributeKey(t) {
|
|
38
|
+
return (
|
|
39
|
+
null != t &&
|
|
40
|
+
t.match(CUSTOM_ATTRIBUTE_SPECIAL_CHARS_REGEX) &&
|
|
41
|
+
-1 === CUSTOM_ATTRIBUTE_RESERVED_OPERATORS.indexOf(t) &&
|
|
42
|
+
r.j.warn("Custom attribute keys cannot contain '$' or '.'"),
|
|
43
|
+
validateCustomString(t, "set custom user attribute", "the given key")
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
export function validatePropertyType(t) {
|
|
47
|
+
const e = typeof t;
|
|
48
|
+
return (
|
|
49
|
+
null == t || "number" === e || "boolean" === e || yt(t) || "string" === e
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
export function _validateNestedProperties(t, e, n) {
|
|
53
|
+
const o = -1 !== n;
|
|
54
|
+
if (o && n > 50)
|
|
55
|
+
return (
|
|
56
|
+
r.j.error("Nested attributes cannot be more than 50 levels deep."), !1
|
|
57
|
+
);
|
|
58
|
+
const i = o ? n + 1 : -1;
|
|
59
|
+
if (p(t) && p(e)) {
|
|
60
|
+
for (let r = 0; r < t.length && r < e.length; r++)
|
|
61
|
+
if (
|
|
62
|
+
(yt(t[r]) && (e[r] = $t(t[r])),
|
|
63
|
+
!_validateNestedProperties(t[r], e[r], i))
|
|
64
|
+
)
|
|
65
|
+
return !1;
|
|
66
|
+
} else {
|
|
67
|
+
if (!Nt(t)) return validatePropertyType(t);
|
|
68
|
+
for (const r of oo(t)) {
|
|
69
|
+
const n = t[r];
|
|
70
|
+
if (o && !validateCustomAttributeKey(r)) return !1;
|
|
71
|
+
if (yt(n)) {
|
|
72
|
+
e[r] = $t(n);
|
|
73
|
+
}
|
|
74
|
+
if (!_validateNestedProperties(n, e[r], i)) return !1;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return !0;
|
|
78
|
+
}
|
|
79
|
+
export function _validateEventPropertyValue(t, e, n, o, i) {
|
|
80
|
+
let a;
|
|
81
|
+
return (
|
|
82
|
+
(a =
|
|
83
|
+
Nt(t) || p(t)
|
|
84
|
+
? _validateNestedProperties(t, e, i ? 1 : -1)
|
|
85
|
+
: validatePropertyType(t)),
|
|
86
|
+
a || r.j.error(`Cannot ${n} because ${o} "${t}" is invalid.`),
|
|
87
|
+
a
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
export function validateStandardString(t, e, n, o = !1) {
|
|
91
|
+
const i = "string" == typeof t || (null === t && o);
|
|
92
|
+
return i || r.j.error(`Cannot ${e} because ${n} "${t}" is invalid.`), i;
|
|
93
|
+
}
|
|
94
|
+
export function validateCustomProperties(t, e, n, o, i) {
|
|
95
|
+
if ((null == t && (t = {}), "object" != typeof t || p(t)))
|
|
96
|
+
return (
|
|
97
|
+
r.j.error(`${e} requires that ${n} be an object. Ignoring ${i}.`),
|
|
98
|
+
[!1, null]
|
|
99
|
+
);
|
|
100
|
+
let a, s;
|
|
101
|
+
e === Ft ? ((a = 76800), (s = "75KB")) : ((a = 51200), (s = "50KB"));
|
|
102
|
+
const u = JSON.stringify(t);
|
|
103
|
+
if (U(u) > a)
|
|
104
|
+
return (
|
|
105
|
+
r.j.error(
|
|
106
|
+
`Could not ${o} because ${n} was greater than the max size of ${s}.`,
|
|
107
|
+
),
|
|
108
|
+
[!1, null]
|
|
109
|
+
);
|
|
110
|
+
let l;
|
|
111
|
+
try {
|
|
112
|
+
l = JSON.parse(u);
|
|
113
|
+
} catch (t) {
|
|
114
|
+
return (
|
|
115
|
+
r.j.error(`Could not ${o} because ${n} did not contain valid JSON.`),
|
|
116
|
+
[!1, null]
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
for (const r in t) {
|
|
120
|
+
if (e === Ft && !validateCustomAttributeKey(r)) return [!1, null];
|
|
121
|
+
if (!validateCustomString(r, o, `the ${i} property name`))
|
|
122
|
+
return [!1, null];
|
|
123
|
+
const n = t[r];
|
|
124
|
+
if (e !== Ft && null == n) {
|
|
125
|
+
delete t[r], delete l[r];
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
yt(n) && (l[r] = $t(n));
|
|
129
|
+
if (
|
|
130
|
+
!_validateEventPropertyValue(
|
|
131
|
+
n,
|
|
132
|
+
l[r],
|
|
133
|
+
o,
|
|
134
|
+
`the ${i} property "${r}"`,
|
|
135
|
+
e === Ft,
|
|
136
|
+
)
|
|
137
|
+
)
|
|
138
|
+
return [!1, null];
|
|
139
|
+
}
|
|
140
|
+
return [!0, l];
|
|
141
|
+
}
|
|
142
|
+
export function validateCustomAttributeArrayType(t, e) {
|
|
143
|
+
let n = !1,
|
|
144
|
+
o = !1;
|
|
145
|
+
const i = () => {
|
|
146
|
+
r.j.error(
|
|
147
|
+
"Custom attribute arrays must be either string arrays or object arrays.",
|
|
148
|
+
);
|
|
149
|
+
};
|
|
150
|
+
for (const r of e)
|
|
151
|
+
if ("string" == typeof r) {
|
|
152
|
+
if (o) return i(), [!1, !1];
|
|
153
|
+
if (
|
|
154
|
+
!validateCustomString(
|
|
155
|
+
r,
|
|
156
|
+
`set custom user attribute "${t}"`,
|
|
157
|
+
"the element in the given array",
|
|
158
|
+
)
|
|
159
|
+
)
|
|
160
|
+
return [!1, !1];
|
|
161
|
+
n = !0;
|
|
162
|
+
} else {
|
|
163
|
+
if (!Nt(r)) return i(), [!1, !1];
|
|
164
|
+
if (n) return i(), [!1, !1];
|
|
165
|
+
if (
|
|
166
|
+
!validateCustomProperties(
|
|
167
|
+
r,
|
|
168
|
+
Ft,
|
|
169
|
+
"attribute value",
|
|
170
|
+
`set custom user attribute "${t}"`,
|
|
171
|
+
"custom user attribute",
|
|
172
|
+
)
|
|
173
|
+
)
|
|
174
|
+
return [!1, !1];
|
|
175
|
+
o = !0;
|
|
176
|
+
}
|
|
177
|
+
return [n, o];
|
|
178
|
+
}
|
|
179
|
+
export function isValidEmail(t) {
|
|
180
|
+
return (
|
|
181
|
+
"string" == typeof t && null != t.toLowerCase().match(EMAIL_ADDRESS_REGEX)
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
export function isValidBrazeActionJson(t) {
|
|
185
|
+
if (!(_.properties.type in t)) return !1;
|
|
186
|
+
switch (t[_.properties.type]) {
|
|
187
|
+
case _.types.ue:
|
|
188
|
+
if (_.properties.me in t) return !0;
|
|
189
|
+
break;
|
|
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.pe:
|
|
199
|
+
case _.types.je:
|
|
200
|
+
if (_.properties.le in t) return !0;
|
|
201
|
+
break;
|
|
202
|
+
case _.types.requestPushPermission:
|
|
203
|
+
return !0;
|
|
204
|
+
default:
|
|
205
|
+
return !1;
|
|
206
|
+
}
|
|
207
|
+
return !1;
|
|
208
|
+
}
|
|
209
|
+
export function isValidBrazeActionType(t) {
|
|
210
|
+
let e = !1;
|
|
211
|
+
return (
|
|
212
|
+
Object.keys(_.types).forEach((r) => {
|
|
213
|
+
_.types[r] !== t.toString() || (e = !0);
|
|
214
|
+
}),
|
|
215
|
+
e
|
|
216
|
+
);
|
|
217
|
+
}
|
package/src/util/window-utils.js
CHANGED
|
@@ -1 +1,34 @@
|
|
|
1
|
-
export const ORIENTATION={PORTRAIT:0,
|
|
1
|
+
export const ORIENTATION = { PORTRAIT: 0, LANDSCAPE: 1 };
|
|
2
|
+
export function _isPhone() {
|
|
3
|
+
return screen.width <= 600;
|
|
4
|
+
}
|
|
5
|
+
export function _getOrientation() {
|
|
6
|
+
if ("orientation" in window)
|
|
7
|
+
return 90 === Math.abs(window.orientation) || 270 === window.orientation
|
|
8
|
+
? ORIENTATION.LANDSCAPE
|
|
9
|
+
: ORIENTATION.PORTRAIT;
|
|
10
|
+
const n = window;
|
|
11
|
+
if ("screen" in n) {
|
|
12
|
+
let e =
|
|
13
|
+
n.screen.orientation || screen.mozOrientation || screen.msOrientation;
|
|
14
|
+
return (
|
|
15
|
+
null != e && "object" == typeof e && (e = e.type),
|
|
16
|
+
"landscape-primary" === e || "landscape-secondary" === e
|
|
17
|
+
? ORIENTATION.LANDSCAPE
|
|
18
|
+
: ORIENTATION.PORTRAIT
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
return ORIENTATION.PORTRAIT;
|
|
22
|
+
}
|
|
23
|
+
export function _openUri(n, e, t) {
|
|
24
|
+
n && (e || (null != t && t.metaKey) ? window.open(n) : (window.location = n));
|
|
25
|
+
}
|
|
26
|
+
export function _getCurrentUrl() {
|
|
27
|
+
return window.location.href;
|
|
28
|
+
}
|
|
29
|
+
export const WindowUtils = {
|
|
30
|
+
openUri: _openUri,
|
|
31
|
+
ao: _isPhone,
|
|
32
|
+
mo: _getOrientation,
|
|
33
|
+
Cn: _getCurrentUrl,
|
|
34
|
+
};
|