@braze/web-sdk 4.2.1 → 4.4.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 +57 -6
- 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 +32 -1
- package/shared-lib/guid.js +10 -1
- package/shared-lib/indexed-db-adapter.js +315 -1
- package/shared-lib/logger.js +38 -1
- package/shared-lib/supported-options.js +26 -1
- package/src/Card/card-manager-factory.js +14 -1
- package/src/Card/card-manager.js +72 -1
- package/src/Card/display/card-display.js +134 -1
- package/src/Card/index.js +5 -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-impressions.js +4 -1
- package/src/Card/models/banner.js +30 -1
- package/src/Card/models/captioned-image.js +32 -1
- package/src/Card/models/card.js +174 -1
- package/src/Card/models/classic-card.js +32 -1
- package/src/Card/models/control-card.js +38 -1
- package/src/Card/models/index.js +5 -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 +283 -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 +14 -1
- package/src/ContentCards/ui/hide-content-cards.js +8 -1
- package/src/ContentCards/ui/show-content-cards.js +72 -1
- package/src/ContentCards/ui/toggle-content-cards.js +8 -1
- package/src/Core/add-sdk-metadata.js +27 -1
- package/src/Core/braze-sdk-metadata.js +10 -1
- package/src/Core/change-user.js +19 -1
- package/src/Core/destroy.js +5 -1
- package/src/Core/device-properties.js +9 -1
- package/src/Core/disable-sdk.js +10 -1
- package/src/Core/enable-sdk.js +8 -1
- package/src/Core/get-device-id.js +10 -1
- package/src/Core/get-user.js +4 -1
- package/src/Core/handle-braze-action.js +64 -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 +36 -1
- package/src/Core/log-purchase.js +245 -1
- package/src/Core/open-session.js +23 -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 +4 -1
- package/src/Core/set-logger.js +4 -1
- package/src/Core/set-sdk-authentication-signature.js +9 -1
- package/src/Core/subscribe-to-sdk-authentication-failures.js +4 -1
- package/src/Core/toggle-logging.js +4 -1
- package/src/Core/wipe-data.js +15 -1
- package/src/FeatureFlags/feature-flag-factory.js +14 -0
- package/src/FeatureFlags/feature-flag.js +16 -0
- package/src/FeatureFlags/feature-flags-provider-factory.js +19 -0
- package/src/FeatureFlags/feature-flags-provider.js +94 -0
- package/src/FeatureFlags/get-all-feature-flags.js +12 -0
- package/src/FeatureFlags/get-feature-flag.js +12 -0
- package/src/FeatureFlags/index.js +4 -0
- package/src/FeatureFlags/refresh-feature-flags.js +9 -0
- package/src/FeatureFlags/subscribe-to-feature-flags-updates.js +6 -0
- package/src/Feed/feed-provider-factory.js +18 -1
- package/src/Feed/feed-provider.js +79 -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 +5 -1
- package/src/Feed/request-feed-refresh.js +5 -1
- package/src/Feed/subscribe-to-feed-updates.js +5 -1
- package/src/Feed/ui/hide-feed.js +7 -1
- package/src/Feed/ui/show-feed.js +89 -1
- package/src/Feed/ui/toggle-feed.js +8 -1
- package/src/InAppMessage/display/get-animation-effect.js +19 -1
- package/src/InAppMessage/display/html-message-to-html.js +223 -1
- package/src/InAppMessage/display/in-app-message-to-html.js +152 -1
- package/src/InAppMessage/display/modal-utils.js +68 -1
- package/src/InAppMessage/in-app-message-factory.js +145 -1
- package/src/InAppMessage/in-app-message-manager-factory.js +16 -1
- package/src/InAppMessage/in-app-message-manager.js +189 -1
- package/src/InAppMessage/index.js +14 -1
- package/src/InAppMessage/log-in-app-message-button-click.js +19 -1
- package/src/InAppMessage/log-in-app-message-click.js +16 -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 +8 -1
- package/src/InAppMessage/models/full-screen-message.js +71 -1
- package/src/InAppMessage/models/html-message.js +54 -1
- package/src/InAppMessage/models/in-app-message-button.js +40 -1
- package/src/InAppMessage/models/in-app-message.js +267 -1
- package/src/InAppMessage/models/modal-message.js +68 -1
- package/src/InAppMessage/models/slide-up-message.js +58 -1
- package/src/InAppMessage/models/templated-in-app-message.js +14 -1
- package/src/InAppMessage/subscribe-to-in-app-message.js +10 -1
- package/src/InAppMessage/ui/automatically-show-in-app-messages.js +15 -1
- package/src/InAppMessage/ui/show-in-app-message.js +170 -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 +360 -1
- package/src/Push/request-push-permission.js +8 -1
- package/src/Push/unregister-push.js +5 -1
- package/src/Push/utils/push-utils.js +34 -1
- package/src/User/index.js +1 -1
- package/src/User/user-manager.js +70 -1
- package/src/User/user.js +278 -1
- package/src/common/base-feed.js +25 -1
- package/src/common/base-provider.js +6 -1
- package/src/common/constants.js +5 -1
- package/src/common/event-logger.js +24 -1
- package/src/common/feed-display.js +200 -1
- package/src/common/translations.js +148 -1
- package/src/index.js +9 -1
- package/src/l10n/l10n-manager-factory.js +22 -1
- package/src/l10n/l10n-manager.js +21 -1
- package/src/managers/auth-manager.js +48 -1
- package/src/managers/braze-instance.js +307 -1
- package/src/managers/device-manager.js +80 -1
- package/src/managers/network-manager.js +219 -1
- package/src/managers/server-config-manager.js +88 -1
- package/src/managers/session-manager.js +68 -1
- package/src/managers/storage-manager-factory.js +35 -1
- package/src/managers/storage-manager.js +394 -1
- package/src/managers/subscription-manager.js +25 -1
- package/src/models/backend-errors.js +8 -1
- package/src/models/braze-event.js +41 -1
- package/src/models/braze-sdk-metadata.js +10 -1
- package/src/models/device.js +26 -1
- package/src/models/identifier.js +20 -1
- package/src/models/push-token.js +22 -1
- package/src/models/request-result.js +8 -1
- package/src/models/server-config.js +32 -1
- package/src/request-controller.js +288 -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 +98 -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 +109 -1
- package/src/triggers/models/trigger-events.js +8 -1
- package/src/triggers/models/trigger.js +110 -1
- package/src/triggers/triggers-provider-factory.js +30 -1
- package/src/triggers/triggers-provider.js +307 -1
- package/src/ui/js/attach-css.js +12 -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 +79 -1
- package/src/util/browser-detector.js +85 -1
- package/src/util/client-hints-parser.js +60 -1
- package/src/util/code-utils.js +92 -1
- package/src/util/color-utils.js +23 -1
- package/src/util/component-utils.js +26 -1
- package/src/util/date-utils.js +27 -1
- package/src/util/deprecation-utils.js +5 -1
- package/src/util/device-constants.js +14 -1
- package/src/util/dom-utils.js +87 -1
- package/src/util/key-codes.js +1 -1
- package/src/util/math.js +5 -1
- package/src/util/net.js +75 -1
- package/src/util/string-utils.js +22 -1
- package/src/util/url-utils.js +23 -1
- package/src/util/user-agent-parser.js +85 -1
- package/src/util/validation-utils.js +136 -1
- package/src/util/window-utils.js +35 -1
|
@@ -1 +1,307 @@
|
|
|
1
|
-
import St from"./auth-manager.js";
|
|
1
|
+
import St from "./auth-manager.js";
|
|
2
|
+
import y from "../common/base-provider.js";
|
|
3
|
+
import ot from "../util/browser-detector.js";
|
|
4
|
+
import It from "./device-manager.js";
|
|
5
|
+
import DeviceProperties from "../Core/device-properties.js";
|
|
6
|
+
import {
|
|
7
|
+
isArray as p,
|
|
8
|
+
keys as rr,
|
|
9
|
+
validateValueIsFromEnum as F,
|
|
10
|
+
values as At
|
|
11
|
+
} from "../util/code-utils.js";
|
|
12
|
+
import { logDeprecationWarning as D } from "../util/deprecation-utils.js";
|
|
13
|
+
import Ot from "./network-manager.js";
|
|
14
|
+
import Lt from "../request-controller.js";
|
|
15
|
+
import Pt from "./server-config-manager.js";
|
|
16
|
+
import Rt from "./session-manager.js";
|
|
17
|
+
import r from "../../shared-lib/braze-shared-lib.js";
|
|
18
|
+
import G, { STORAGE_KEYS as o } from "./storage-manager.js";
|
|
19
|
+
import Mt from "./storage-manager-factory.js";
|
|
20
|
+
import u from "./subscription-manager.js";
|
|
21
|
+
import { TriggersProviderFactory as W } from "../triggers/triggers-provider-factory.js";
|
|
22
|
+
import bt from "../User/user-manager.js";
|
|
23
|
+
import { User } from "../User/index.js";
|
|
24
|
+
import { parseQueryStringKeyValues as it } from "../util/url-utils.js";
|
|
25
|
+
import { WindowUtils as H } from "../util/window-utils.js";
|
|
26
|
+
const T = {
|
|
27
|
+
Yn: "allowCrawlerActivity",
|
|
28
|
+
Zn: "baseUrl",
|
|
29
|
+
ho: "noCookies",
|
|
30
|
+
po: "devicePropertyAllowlist",
|
|
31
|
+
ta: "disablePushTokenMaintenance",
|
|
32
|
+
Eo: "enableLogging",
|
|
33
|
+
_o: "enableSdkAuthentication",
|
|
34
|
+
ia: "manageServiceWorkerExternally",
|
|
35
|
+
Io: "minimumIntervalBetweenTriggerActionsInSeconds",
|
|
36
|
+
Ao: "sessionTimeoutInSeconds",
|
|
37
|
+
So: "appVersion",
|
|
38
|
+
na: "serviceWorkerLocation",
|
|
39
|
+
ra: "safariWebsitePushId",
|
|
40
|
+
jn: "localization",
|
|
41
|
+
ao: "contentSecurityNonce",
|
|
42
|
+
No: "enableHtmlInAppMessages",
|
|
43
|
+
wo: "allowUserSuppliedJavascript",
|
|
44
|
+
no: "inAppMessageZIndex",
|
|
45
|
+
lo: "openInAppMessagesInNewTab",
|
|
46
|
+
tn: "openCardsInNewTab",
|
|
47
|
+
en: "openNewsFeedCardsInNewTab",
|
|
48
|
+
qi: "requireExplicitInAppMessageDismissal",
|
|
49
|
+
To: "doNotLoadFontAwesome",
|
|
50
|
+
Oo: "sdkFlavor"
|
|
51
|
+
};
|
|
52
|
+
class jt {
|
|
53
|
+
constructor() {
|
|
54
|
+
(this.vo = !1),
|
|
55
|
+
(this.Co = !1),
|
|
56
|
+
(this.Lo = new u()),
|
|
57
|
+
(this.Po = new u()),
|
|
58
|
+
(this.Ro = {}),
|
|
59
|
+
(this.Mo = []),
|
|
60
|
+
(this.jo = []),
|
|
61
|
+
(this.Pe = []),
|
|
62
|
+
(this.yo = "4.4.0");
|
|
63
|
+
}
|
|
64
|
+
Do(t) {
|
|
65
|
+
this.Lo.ut(t);
|
|
66
|
+
}
|
|
67
|
+
Zi(t) {
|
|
68
|
+
this.Po.ut(t);
|
|
69
|
+
}
|
|
70
|
+
initialize(t, i) {
|
|
71
|
+
if (this.Uo())
|
|
72
|
+
return (
|
|
73
|
+
r.D.info("Braze has already been initialized with an API key."), !0
|
|
74
|
+
);
|
|
75
|
+
this.Ro = i || {};
|
|
76
|
+
let s = this.nn(T.Eo);
|
|
77
|
+
const e = it(H.bn());
|
|
78
|
+
if (
|
|
79
|
+
(e && "true" === e.brazeLogging && (s = !0),
|
|
80
|
+
r.D.init(s),
|
|
81
|
+
r.D.info(`Initialization Options: ${JSON.stringify(this.Ro, null, 2)}`),
|
|
82
|
+
null == t || "" === t || "string" != typeof t)
|
|
83
|
+
)
|
|
84
|
+
return r.D.error("Braze requires a valid API key to be initialized."), !1;
|
|
85
|
+
this._r = t;
|
|
86
|
+
let n = this.nn(T.Zn);
|
|
87
|
+
if (null == n || "" === n || "string" != typeof n)
|
|
88
|
+
return r.D.error("Braze requires a valid baseUrl to be initialized."), !1;
|
|
89
|
+
!1 === /^https?:/.test(n) && (n = `https://${n}`);
|
|
90
|
+
let a = n;
|
|
91
|
+
if (
|
|
92
|
+
((n = document.createElement("a")),
|
|
93
|
+
(n.href = a),
|
|
94
|
+
"/" === n.pathname && (n = `${n}api/v3`),
|
|
95
|
+
(this.zo = n.toString()),
|
|
96
|
+
ot.Bo && !this.nn(T.Yn))
|
|
97
|
+
)
|
|
98
|
+
return (
|
|
99
|
+
r.D.info("Ignoring activity from crawler bot " + navigator.userAgent),
|
|
100
|
+
(this.Co = !0),
|
|
101
|
+
!1
|
|
102
|
+
);
|
|
103
|
+
const h = this.nn(jt.ho) || !1;
|
|
104
|
+
if (((this.h = Mt.Wo(t, h)), new G.ne(null, !0).lr(o.ae)))
|
|
105
|
+
return (
|
|
106
|
+
r.D.info("Ignoring all activity due to previous opt out"),
|
|
107
|
+
(this.Co = !0),
|
|
108
|
+
!1
|
|
109
|
+
);
|
|
110
|
+
for (const t of rr(this.Ro))
|
|
111
|
+
-1 === At(r.Fo).indexOf(t) &&
|
|
112
|
+
r.D.warn(`Ignoring unknown initialization option '${t}'.`);
|
|
113
|
+
const l = ["mparticle", "wordpress", "tealium"];
|
|
114
|
+
if (null != this.nn(T.Oo)) {
|
|
115
|
+
const t = this.nn(T.Oo);
|
|
116
|
+
-1 !== l.indexOf(t)
|
|
117
|
+
? (this.Vo = t)
|
|
118
|
+
: r.D.error("Invalid sdk flavor passed: " + t);
|
|
119
|
+
}
|
|
120
|
+
let f = this.nn(r.Fo.po);
|
|
121
|
+
if (null != f)
|
|
122
|
+
if (p(f)) {
|
|
123
|
+
const t = [];
|
|
124
|
+
for (let i = 0; i < f.length; i++)
|
|
125
|
+
F(
|
|
126
|
+
DeviceProperties,
|
|
127
|
+
f[i],
|
|
128
|
+
"devicePropertyAllowlist contained an invalid value.",
|
|
129
|
+
"DeviceProperties"
|
|
130
|
+
) && t.push(f[i]);
|
|
131
|
+
f = t;
|
|
132
|
+
} else
|
|
133
|
+
r.D.error(
|
|
134
|
+
"devicePropertyAllowlist must be an array. Defaulting to all properties."
|
|
135
|
+
),
|
|
136
|
+
(f = null);
|
|
137
|
+
(this.Ur = new It(this.h, f)),
|
|
138
|
+
(this.gt = new Pt(this.h)),
|
|
139
|
+
(this.v = new bt(this.gt, this.h)),
|
|
140
|
+
(this.j = new Rt(this.h, this.v, this.gt, this.nn(T.Ao)));
|
|
141
|
+
const m = new u();
|
|
142
|
+
return (
|
|
143
|
+
(this.Go = new St(this.h, this.nn(T._o), m)),
|
|
144
|
+
this.jt(m),
|
|
145
|
+
(this.vt = new Ot(
|
|
146
|
+
this.Ur,
|
|
147
|
+
this.h,
|
|
148
|
+
this.Go,
|
|
149
|
+
this.v,
|
|
150
|
+
this.j,
|
|
151
|
+
this.gt,
|
|
152
|
+
this._r,
|
|
153
|
+
this.zo,
|
|
154
|
+
this.yo,
|
|
155
|
+
this.Vo,
|
|
156
|
+
this.nn(T.So)
|
|
157
|
+
)),
|
|
158
|
+
(this.si = new Lt(
|
|
159
|
+
this._r,
|
|
160
|
+
this.zo,
|
|
161
|
+
this.j,
|
|
162
|
+
this.Ur,
|
|
163
|
+
this.v,
|
|
164
|
+
this.gt,
|
|
165
|
+
this.h,
|
|
166
|
+
t => {
|
|
167
|
+
if (this.Uo()) for (const i of this.re()) i.Rs(t);
|
|
168
|
+
},
|
|
169
|
+
this.Go,
|
|
170
|
+
this.vt
|
|
171
|
+
)),
|
|
172
|
+
this.si.initialize(),
|
|
173
|
+
r.D.info(
|
|
174
|
+
`Initialized for the Braze backend at "${this.nn(
|
|
175
|
+
T.Zn
|
|
176
|
+
)}" with API key "${this._r}".`
|
|
177
|
+
),
|
|
178
|
+
null != this.nn(T.No) &&
|
|
179
|
+
D(
|
|
180
|
+
"enableHtmlInAppMessages",
|
|
181
|
+
"initialization option",
|
|
182
|
+
"allowUserSuppliedJavascript"
|
|
183
|
+
),
|
|
184
|
+
W.init(),
|
|
185
|
+
this.gt.Te(() => {
|
|
186
|
+
this.gt.ye() &&
|
|
187
|
+
import("../FeatureFlags/refresh-feature-flags.js").then(t => {
|
|
188
|
+
(0, t.default)();
|
|
189
|
+
});
|
|
190
|
+
}),
|
|
191
|
+
this.si.cr(() => {
|
|
192
|
+
this.gt.ye() &&
|
|
193
|
+
import("../FeatureFlags/refresh-feature-flags.js").then(t => {
|
|
194
|
+
(0, t.default)(null, null, !0);
|
|
195
|
+
});
|
|
196
|
+
}),
|
|
197
|
+
this.Lo.St(this.Ro),
|
|
198
|
+
(this.vo = !0),
|
|
199
|
+
!0
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
destroy(t) {
|
|
203
|
+
if ((r.D.destroy(), this.Uo())) {
|
|
204
|
+
this.Po.St(), this.Po.removeAllSubscriptions();
|
|
205
|
+
for (const t of this.Mo) t.destroy();
|
|
206
|
+
this.Mo = [];
|
|
207
|
+
for (const t of this.jo) t.clearData(!1);
|
|
208
|
+
(this.jo = []),
|
|
209
|
+
this.removeAllSubscriptions(),
|
|
210
|
+
(this.Pe = []),
|
|
211
|
+
this.si.destroy(),
|
|
212
|
+
(this.si = null),
|
|
213
|
+
(this.Go = null),
|
|
214
|
+
(this.Ur = null),
|
|
215
|
+
(this.vt = null),
|
|
216
|
+
(this.gt = null),
|
|
217
|
+
(this.j = null),
|
|
218
|
+
(this.v = null),
|
|
219
|
+
(this.Ro = {}),
|
|
220
|
+
(this.Vo = void 0),
|
|
221
|
+
(this.vo = !1),
|
|
222
|
+
(this.Co = !1),
|
|
223
|
+
t && (this.h = null);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
rr() {
|
|
227
|
+
if (this.Ko()) return !1;
|
|
228
|
+
if (!this.Uo())
|
|
229
|
+
throw new Error("Braze must be initialized before calling methods.");
|
|
230
|
+
return !0;
|
|
231
|
+
}
|
|
232
|
+
ea() {
|
|
233
|
+
return this._r;
|
|
234
|
+
}
|
|
235
|
+
ii() {
|
|
236
|
+
return this.Go;
|
|
237
|
+
}
|
|
238
|
+
Ks() {
|
|
239
|
+
return this.zo;
|
|
240
|
+
}
|
|
241
|
+
ce() {
|
|
242
|
+
return this.Ur;
|
|
243
|
+
}
|
|
244
|
+
nr() {
|
|
245
|
+
return this.vt;
|
|
246
|
+
}
|
|
247
|
+
nn(t) {
|
|
248
|
+
return this.Ro[t];
|
|
249
|
+
}
|
|
250
|
+
re() {
|
|
251
|
+
return this.jo;
|
|
252
|
+
}
|
|
253
|
+
mr() {
|
|
254
|
+
return this.si;
|
|
255
|
+
}
|
|
256
|
+
ir() {
|
|
257
|
+
return this.gt;
|
|
258
|
+
}
|
|
259
|
+
g() {
|
|
260
|
+
return this.j;
|
|
261
|
+
}
|
|
262
|
+
l() {
|
|
263
|
+
return this.h;
|
|
264
|
+
}
|
|
265
|
+
gr() {
|
|
266
|
+
if (this.v && this.si) return new User(this.v, this.si);
|
|
267
|
+
}
|
|
268
|
+
p() {
|
|
269
|
+
return this.v;
|
|
270
|
+
}
|
|
271
|
+
tr() {
|
|
272
|
+
return !0 === this.nn(T.wo) || !0 === this.nn(T.No);
|
|
273
|
+
}
|
|
274
|
+
u(t) {
|
|
275
|
+
let i = !1;
|
|
276
|
+
for (const s of this.Mo) s === t && (i = !0);
|
|
277
|
+
i || this.Mo.push(t);
|
|
278
|
+
}
|
|
279
|
+
ar(t) {
|
|
280
|
+
let i = !1;
|
|
281
|
+
for (const s of this.jo) s.constructor === t.constructor && (i = !0);
|
|
282
|
+
t instanceof y && !i && this.jo.push(t);
|
|
283
|
+
}
|
|
284
|
+
jt(t) {
|
|
285
|
+
t instanceof u && this.Pe.push(t);
|
|
286
|
+
}
|
|
287
|
+
removeAllSubscriptions() {
|
|
288
|
+
if (this.rr()) for (const t of this.Pe) t.removeAllSubscriptions();
|
|
289
|
+
}
|
|
290
|
+
removeSubscription(t) {
|
|
291
|
+
if (this.rr()) for (const i of this.Pe) i.removeSubscription(t);
|
|
292
|
+
}
|
|
293
|
+
le(t) {
|
|
294
|
+
this.Co = t;
|
|
295
|
+
}
|
|
296
|
+
Uo() {
|
|
297
|
+
return this.vo;
|
|
298
|
+
}
|
|
299
|
+
Ko() {
|
|
300
|
+
return this.Co;
|
|
301
|
+
}
|
|
302
|
+
Ds() {
|
|
303
|
+
return this.yo;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
const e = new jt();
|
|
307
|
+
export { e as default, jt as BrazeSdkInstance, T as OPTIONS };
|
|
@@ -1 +1,80 @@
|
|
|
1
|
-
import
|
|
1
|
+
import ot from "../util/browser-detector.js";
|
|
2
|
+
import Ie from "../models/device.js";
|
|
3
|
+
import DeviceProperties from "../Core/device-properties.js";
|
|
4
|
+
import _t from "../models/identifier.js";
|
|
5
|
+
import r from "../../shared-lib/braze-shared-lib.js";
|
|
6
|
+
import { STORAGE_KEYS as o } from "../managers/storage-manager.js";
|
|
7
|
+
import { values as At } from "../util/code-utils.js";
|
|
8
|
+
export default class It {
|
|
9
|
+
constructor(e, t) {
|
|
10
|
+
(this.h = e), null == t && (t = At(DeviceProperties)), (this.xo = t);
|
|
11
|
+
}
|
|
12
|
+
te() {
|
|
13
|
+
let e = this.h.tu(o.eu.Jo);
|
|
14
|
+
null == e && ((e = new _t(r.it.nt())), this.h.ru(o.eu.Jo, e));
|
|
15
|
+
const t = new Ie(e.iu);
|
|
16
|
+
for (let e = 0; e < this.xo.length; e++) {
|
|
17
|
+
const r = this.xo[e];
|
|
18
|
+
switch (r) {
|
|
19
|
+
case DeviceProperties.BROWSER:
|
|
20
|
+
t[r] = ot.browser;
|
|
21
|
+
break;
|
|
22
|
+
case DeviceProperties.BROWSER_VERSION:
|
|
23
|
+
t[r] = ot.version;
|
|
24
|
+
break;
|
|
25
|
+
case DeviceProperties.OS:
|
|
26
|
+
t[r] = this.qo();
|
|
27
|
+
break;
|
|
28
|
+
case DeviceProperties.RESOLUTION:
|
|
29
|
+
t[r] = screen.width + "x" + screen.height;
|
|
30
|
+
break;
|
|
31
|
+
case DeviceProperties.LANGUAGE:
|
|
32
|
+
t[r] = ot.language;
|
|
33
|
+
break;
|
|
34
|
+
case DeviceProperties.TIME_ZONE:
|
|
35
|
+
t[r] = this.Ho(new Date());
|
|
36
|
+
break;
|
|
37
|
+
case DeviceProperties.USER_AGENT:
|
|
38
|
+
t[r] = ot.userAgent;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return t;
|
|
42
|
+
}
|
|
43
|
+
qo() {
|
|
44
|
+
if (ot.Qo()) return ot.Qo();
|
|
45
|
+
const e = this.h.I(o.q.Xo);
|
|
46
|
+
return e && e.os_version ? e.os_version : ot.Yo();
|
|
47
|
+
}
|
|
48
|
+
Ho(e) {
|
|
49
|
+
if ("undefined" != typeof Intl && "function" == typeof Intl.DateTimeFormat)
|
|
50
|
+
try {
|
|
51
|
+
if ("function" == typeof Intl.DateTimeFormat().resolvedOptions) {
|
|
52
|
+
const e = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
53
|
+
if (null != e && "" !== e) return e;
|
|
54
|
+
}
|
|
55
|
+
} catch (t) {
|
|
56
|
+
r.D.info(
|
|
57
|
+
"Intl.DateTimeFormat threw an error, cannot detect user's time zone:" +
|
|
58
|
+
t.message
|
|
59
|
+
),
|
|
60
|
+
(e = "");
|
|
61
|
+
}
|
|
62
|
+
if (!e) return e;
|
|
63
|
+
const t = e.getTimezoneOffset();
|
|
64
|
+
return this.Zo(t);
|
|
65
|
+
}
|
|
66
|
+
Zo(e) {
|
|
67
|
+
const t = parseInt(e / 60),
|
|
68
|
+
r = parseInt(e % 60);
|
|
69
|
+
let s = "GMT";
|
|
70
|
+
return (
|
|
71
|
+
0 !== e &&
|
|
72
|
+
((s += e < 0 ? "+" : "-"),
|
|
73
|
+
(s +=
|
|
74
|
+
("00" + Math.abs(t)).slice(-2) +
|
|
75
|
+
":" +
|
|
76
|
+
("00" + Math.abs(r)).slice(-2))),
|
|
77
|
+
s
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -1 +1,219 @@
|
|
|
1
|
-
import qt from"../models/backend-errors.js";
|
|
1
|
+
import qt from "../models/backend-errors.js";
|
|
2
|
+
import ue from "../models/braze-event.js";
|
|
3
|
+
import {
|
|
4
|
+
convertMsToSeconds as l,
|
|
5
|
+
convertSecondsToMs as Bt
|
|
6
|
+
} from "../util/date-utils.js";
|
|
7
|
+
import s from "../common/event-logger.js";
|
|
8
|
+
import { isArray as p, isEqual as ii } from "../util/code-utils.js";
|
|
9
|
+
import r from "../../shared-lib/braze-shared-lib.js";
|
|
10
|
+
import { STORAGE_KEYS as o } from "./storage-manager.js";
|
|
11
|
+
export default class Ot {
|
|
12
|
+
constructor(t, e, s, i, r, o, n, a, u, h, c) {
|
|
13
|
+
(this.Ur = t),
|
|
14
|
+
(this.h = e),
|
|
15
|
+
(this.Go = s),
|
|
16
|
+
(this.v = i),
|
|
17
|
+
(this.j = r),
|
|
18
|
+
(this.gt = o),
|
|
19
|
+
(this._r = n),
|
|
20
|
+
(this.zo = a),
|
|
21
|
+
(this.yo = u),
|
|
22
|
+
(this.Vo = h),
|
|
23
|
+
(this.$o = c),
|
|
24
|
+
(this.sa = ["npm"]);
|
|
25
|
+
}
|
|
26
|
+
Ps(t, e) {
|
|
27
|
+
const s = this.Ur.te(),
|
|
28
|
+
i = s.Mi(),
|
|
29
|
+
r = this.h.I(o.q.Xo);
|
|
30
|
+
ii(r, i) || (t.device = i),
|
|
31
|
+
(t.api_key = this._r),
|
|
32
|
+
(t.time = l(new Date().valueOf(), !0));
|
|
33
|
+
const n = this.h.I(o.q.oa) || [],
|
|
34
|
+
a = this.h.I(o.q.ua) || "";
|
|
35
|
+
if (
|
|
36
|
+
(this.sa.length > 0 &&
|
|
37
|
+
(!ii(n, this.sa) || a !== this.j.ha()) &&
|
|
38
|
+
(t.sdk_metadata = this.sa),
|
|
39
|
+
(t.sdk_version = this.yo),
|
|
40
|
+
this.Vo && (t.sdk_flavor = this.Vo),
|
|
41
|
+
(t.app_version = this.$o),
|
|
42
|
+
(t.device_id = s.id),
|
|
43
|
+
e)
|
|
44
|
+
) {
|
|
45
|
+
const e = this.v.getUserId();
|
|
46
|
+
null != e && (t.user_id = e);
|
|
47
|
+
}
|
|
48
|
+
return t;
|
|
49
|
+
}
|
|
50
|
+
Os(t, e, i) {
|
|
51
|
+
const o = e.auth_error,
|
|
52
|
+
n = e.error;
|
|
53
|
+
if (!o && !n) return !0;
|
|
54
|
+
if (o) {
|
|
55
|
+
let e;
|
|
56
|
+
this.Go.Wn();
|
|
57
|
+
const s = { errorCode: o.error_code };
|
|
58
|
+
for (const t of i)
|
|
59
|
+
p(t) && "X-Braze-Auth-Signature" === t[0] && (s.signature = t[1]);
|
|
60
|
+
t.respond_with && t.respond_with.user_id
|
|
61
|
+
? (s.userId = t.respond_with.user_id)
|
|
62
|
+
: t.user_id && (s.userId = t.user_id);
|
|
63
|
+
const n = o.reason;
|
|
64
|
+
return (
|
|
65
|
+
n
|
|
66
|
+
? ((s.reason = n), (e = `due to ${n}`))
|
|
67
|
+
: (e = `with error code ${o.error_code}.`),
|
|
68
|
+
this.Go.Jn() ||
|
|
69
|
+
(e +=
|
|
70
|
+
' Please use the "enableSdkAuthentication" initialization option to enable authentication.'),
|
|
71
|
+
r.D.error(`SDK Authentication failed ${e}`),
|
|
72
|
+
this.ca(t.events, t.attributes),
|
|
73
|
+
this.Go.Rn(s),
|
|
74
|
+
!1
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
if (n) {
|
|
78
|
+
let i = n;
|
|
79
|
+
switch (i) {
|
|
80
|
+
case qt.la:
|
|
81
|
+
const o = "Received successful response with empty body.";
|
|
82
|
+
return s.G(r.A.qs, { e: o }), r.D.info(o), !1;
|
|
83
|
+
case qt.fa:
|
|
84
|
+
const n = "Received successful response with invalid JSON";
|
|
85
|
+
return s.G(r.A.qs, { e: n + ": " + e.response }), r.D.info(n), !1;
|
|
86
|
+
case qt.ma:
|
|
87
|
+
i = `The API key "${t.api_key}" is invalid for the baseUrl ${this.zo}`;
|
|
88
|
+
break;
|
|
89
|
+
case qt.pa:
|
|
90
|
+
i =
|
|
91
|
+
"Sorry, we are not currently accepting your requests. If you think this is in error, please contact us.";
|
|
92
|
+
break;
|
|
93
|
+
case qt.Ra:
|
|
94
|
+
i = "No device identifier. Please contact support@braze.com";
|
|
95
|
+
}
|
|
96
|
+
r.D.error("Backend error: " + i);
|
|
97
|
+
}
|
|
98
|
+
return !1;
|
|
99
|
+
}
|
|
100
|
+
ba(t, e, s, i) {
|
|
101
|
+
return !!((t && 0 !== t.length) || (e && 0 !== e.length) || s || i);
|
|
102
|
+
}
|
|
103
|
+
ga(t, e, s, i) {
|
|
104
|
+
const r = [],
|
|
105
|
+
o = t => t || "",
|
|
106
|
+
n = o(this.v.getUserId());
|
|
107
|
+
let a,
|
|
108
|
+
u,
|
|
109
|
+
h,
|
|
110
|
+
c,
|
|
111
|
+
l = this.Ai(t, e);
|
|
112
|
+
if (s.length > 0) {
|
|
113
|
+
const t = [];
|
|
114
|
+
for (const e of s) {
|
|
115
|
+
if (((a = e.Mi()), this.Go.Jn())) {
|
|
116
|
+
if (n && !a.user_id) {
|
|
117
|
+
c || ((c = {}), (c.events = [])), c.events.push(a);
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (o(a.user_id) !== n) {
|
|
121
|
+
u || (u = []), u.push(a);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
t.push(a);
|
|
126
|
+
}
|
|
127
|
+
t.length > 0 && (l.events = t);
|
|
128
|
+
}
|
|
129
|
+
if (i.length > 0) {
|
|
130
|
+
const t = [];
|
|
131
|
+
for (const e of i)
|
|
132
|
+
this.Go.Jn() && o(e.user_id) !== n
|
|
133
|
+
? (h || (h = []), h.push(e))
|
|
134
|
+
: t.push(e);
|
|
135
|
+
t.length > 0 && (l.attributes = t);
|
|
136
|
+
}
|
|
137
|
+
if ((this.ca(u, h), (l = this.Ps(l, !0)), c)) {
|
|
138
|
+
c = this.Ps(c, !1);
|
|
139
|
+
const t = { requestData: c, headers: this.Bs(c) };
|
|
140
|
+
r.push(t);
|
|
141
|
+
}
|
|
142
|
+
if (l && !this.ba(l.events, l.attributes, t, e)) return c ? r : null;
|
|
143
|
+
const f = { requestData: l, headers: this.Bs(l) };
|
|
144
|
+
return r.push(f), r;
|
|
145
|
+
}
|
|
146
|
+
ca(t, e) {
|
|
147
|
+
if (t) {
|
|
148
|
+
const e = [];
|
|
149
|
+
for (const s of t) {
|
|
150
|
+
const t = ue.fromJson(s);
|
|
151
|
+
(t.time = Bt(t.time)), e.push(t);
|
|
152
|
+
}
|
|
153
|
+
this.h.bo(e);
|
|
154
|
+
}
|
|
155
|
+
if (e) for (const t of e) this.h.qa(t);
|
|
156
|
+
}
|
|
157
|
+
Vs(t, e) {
|
|
158
|
+
let s = "HTTP error ";
|
|
159
|
+
null != t && (s += t + " "), (s += e), r.D.error(s);
|
|
160
|
+
}
|
|
161
|
+
yr(t) {
|
|
162
|
+
return s.G(r.A.Aa, { n: t });
|
|
163
|
+
}
|
|
164
|
+
Ai(t, e, s) {
|
|
165
|
+
const i = {};
|
|
166
|
+
t && (i.feed = !0), e && (i.triggers = !0);
|
|
167
|
+
const r = null != s ? s : this.v.getUserId();
|
|
168
|
+
return (
|
|
169
|
+
r && (i.user_id = r),
|
|
170
|
+
(i.config = { config_time: this.gt.Zs() }),
|
|
171
|
+
{ respond_with: i }
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
Bs(t, e, s, i) {
|
|
175
|
+
const r = [["X-Braze-Api-Key", this._r]];
|
|
176
|
+
let n = !1;
|
|
177
|
+
if (
|
|
178
|
+
(null != t.respond_with &&
|
|
179
|
+
t.respond_with.triggers &&
|
|
180
|
+
(r.push(["X-Braze-TriggersRequest", "true"]), (n = !0)),
|
|
181
|
+
null != t.respond_with &&
|
|
182
|
+
t.respond_with.feed &&
|
|
183
|
+
(r.push(["X-Braze-FeedRequest", "true"]), (n = !0)),
|
|
184
|
+
e)
|
|
185
|
+
) {
|
|
186
|
+
r.push(["X-Braze-ContentCardsRequest", "true"]);
|
|
187
|
+
let t = this.h.I(o.q.As);
|
|
188
|
+
(t && i) || ((t = 0), this.h.B(o.q.As, t)),
|
|
189
|
+
r.push(["BRAZE-SYNC-RETRY-COUNT", t.toString()]),
|
|
190
|
+
(n = !0);
|
|
191
|
+
}
|
|
192
|
+
if (
|
|
193
|
+
(s && (r.push(["X-Braze-FeatureFlagsRequest", "true"]), (n = !0)),
|
|
194
|
+
n && r.push(["X-Braze-DataRequest", "true"]),
|
|
195
|
+
this.Go.Jn())
|
|
196
|
+
) {
|
|
197
|
+
const t = this.Go.Kn();
|
|
198
|
+
null != t && r.push(["X-Braze-Auth-Signature", t]);
|
|
199
|
+
}
|
|
200
|
+
return r;
|
|
201
|
+
}
|
|
202
|
+
Gs(t, e) {
|
|
203
|
+
const s = t.device;
|
|
204
|
+
s && s.os_version instanceof Promise
|
|
205
|
+
? s.os_version.then(s => {
|
|
206
|
+
(t.device.os_version = s), e();
|
|
207
|
+
})
|
|
208
|
+
: e();
|
|
209
|
+
}
|
|
210
|
+
Qs() {
|
|
211
|
+
this.Go.Qs();
|
|
212
|
+
}
|
|
213
|
+
Ks() {
|
|
214
|
+
return this.zo;
|
|
215
|
+
}
|
|
216
|
+
addSdkMetadata(t) {
|
|
217
|
+
for (const e of t) -1 === this.sa.indexOf(e) && this.sa.push(e);
|
|
218
|
+
}
|
|
219
|
+
}
|