@braze/web-sdk 5.0.1 → 5.1.1
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/README.md +1 -1
- package/index.d.ts +10 -5
- package/package.json +1 -1
- package/shared-lib/encoding-utils.js +3 -3
- package/shared-lib/event-types.js +29 -29
- package/shared-lib/guid.js +3 -3
- package/shared-lib/index.js +6 -0
- package/shared-lib/indexed-db-adapter.js +70 -70
- package/shared-lib/logger.js +18 -18
- package/shared-lib/supported-options.js +21 -21
- package/src/Card/card-manager.js +43 -45
- package/src/Card/display/card-display.js +60 -60
- package/src/Card/log-card-click.js +4 -4
- package/src/Card/log-card-dismissal.js +2 -3
- package/src/Card/log-card-impressions.js +7 -7
- package/src/Card/models/captioned-image.js +21 -21
- package/src/Card/models/card.js +73 -73
- package/src/Card/models/classic-card.js +21 -21
- package/src/Card/models/control-card.js +11 -11
- package/src/Card/models/image-only.js +19 -19
- package/src/Card/util/card-factory.js +68 -68
- package/src/ContentCards/content-cards-provider-factory.js +3 -3
- package/src/ContentCards/content-cards-provider.js +255 -245
- package/src/ContentCards/content-cards.js +2 -2
- package/src/ContentCards/get-cached-content-cards.js +1 -1
- package/src/ContentCards/request-content-cards-refresh.js +1 -1
- package/src/ContentCards/subscribe-to-content-cards-updates.js +6 -6
- package/src/ContentCards/ui/hide-content-cards.js +1 -1
- package/src/ContentCards/ui/show-content-cards.js +24 -24
- package/src/ContentCards/ui/toggle-content-cards.js +1 -1
- package/src/Core/add-sdk-metadata.js +21 -19
- package/src/Core/change-user.js +10 -10
- package/src/Core/destroy.js +2 -2
- package/src/Core/disable-sdk.js +11 -11
- package/src/Core/enable-sdk.js +7 -7
- package/src/Core/get-device-id.js +6 -6
- package/src/Core/get-user.js +1 -1
- package/src/Core/handle-braze-action.js +41 -41
- package/src/Core/is-disabled.js +2 -2
- package/src/Core/log-custom-event.js +15 -15
- package/src/Core/log-purchase.js +31 -37
- package/src/Core/open-session.js +12 -12
- package/src/Core/remove-all-subscriptions.js +1 -1
- package/src/Core/remove-subscription.js +1 -1
- package/src/Core/request-immediate-data-flush.js +1 -1
- package/src/Core/set-logger.js +2 -2
- package/src/Core/set-sdk-authentication-signature.js +3 -3
- package/src/Core/subscribe-to-sdk-authentication-failures.js +6 -4
- package/src/Core/toggle-logging.js +2 -2
- package/src/Core/wipe-data.js +9 -9
- package/src/FeatureFlags/feature-flag-factory.js +12 -12
- package/src/FeatureFlags/feature-flag.js +10 -10
- package/src/FeatureFlags/feature-flags-provider-factory.js +3 -2
- package/src/FeatureFlags/feature-flags-provider.js +108 -80
- package/src/FeatureFlags/get-all-feature-flags.js +5 -5
- package/src/FeatureFlags/get-feature-flag.js +6 -6
- package/src/FeatureFlags/log-feature-flag-impression.js +15 -13
- package/src/FeatureFlags/refresh-feature-flags.js +1 -1
- package/src/FeatureFlags/subscribe-to-feature-flags-updates.js +7 -4
- package/src/Feed/feed-provider-factory.js +2 -2
- package/src/Feed/feed-provider.js +44 -44
- package/src/Feed/feed.js +1 -1
- package/src/Feed/get-cached-feed.js +1 -1
- package/src/Feed/log-feed-displayed.js +4 -4
- package/src/Feed/request-feed-refresh.js +1 -1
- package/src/Feed/subscribe-to-feed-updates.js +1 -1
- package/src/Feed/ui/hide-feed.js +1 -1
- package/src/Feed/ui/show-feed.js +28 -28
- package/src/Feed/ui/toggle-feed.js +1 -1
- package/src/InAppMessage/defer-in-app-message.js +5 -5
- package/src/InAppMessage/display/html-message-to-html.js +54 -54
- package/src/InAppMessage/display/in-app-message-to-html.js +79 -79
- package/src/InAppMessage/display/modal-utils.js +8 -8
- package/src/InAppMessage/get-deferred-in-app-message.js +1 -1
- package/src/InAppMessage/in-app-message-factory.js +49 -49
- package/src/InAppMessage/in-app-message-manager-factory.js +1 -1
- package/src/InAppMessage/in-app-message-manager.js +143 -138
- package/src/InAppMessage/log-in-app-message-button-click.js +12 -12
- package/src/InAppMessage/log-in-app-message-click.js +9 -9
- package/src/InAppMessage/log-in-app-message-html-click.js +12 -12
- package/src/InAppMessage/log-in-app-message-impression.js +6 -6
- package/src/InAppMessage/models/full-screen-message.js +33 -33
- package/src/InAppMessage/models/html-message.js +20 -20
- package/src/InAppMessage/models/in-app-message-button.js +6 -6
- package/src/InAppMessage/models/in-app-message.js +99 -99
- package/src/InAppMessage/models/modal-message.js +32 -32
- package/src/InAppMessage/models/slide-up-message.js +28 -28
- package/src/InAppMessage/models/templated-in-app-message.js +8 -8
- package/src/InAppMessage/subscribe-to-in-app-message.js +2 -2
- package/src/InAppMessage/ui/automatically-show-in-app-messages.js +4 -4
- package/src/InAppMessage/ui/show-in-app-message.js +81 -81
- package/src/Push/is-push-blocked.js +1 -1
- package/src/Push/is-push-permission-granted.js +1 -1
- package/src/Push/is-push-supported.js +1 -1
- package/src/Push/push-manager-factory.js +5 -5
- package/src/Push/push-manager.js +176 -173
- package/src/Push/request-push-permission.js +1 -1
- package/src/Push/unregister-push.js +1 -1
- package/src/Push/utils/push-utils.js +4 -4
- package/src/User/user-manager.js +29 -29
- package/src/User/user.js +72 -74
- package/src/common/base-feed.js +7 -7
- package/src/common/base-provider.js +1 -1
- package/src/common/constants.js +2 -0
- package/src/common/event-logger.js +21 -18
- package/src/common/feed-display.js +44 -44
- package/src/l10n/l10n-manager-factory.js +3 -3
- package/src/l10n/l10n-manager.js +7 -7
- package/src/managers/auth-manager.js +32 -32
- package/src/managers/braze-instance.js +188 -190
- package/src/managers/device-manager.js +28 -28
- package/src/managers/network-manager.js +189 -138
- package/src/managers/server-config-manager.js +69 -53
- package/src/managers/session-manager.js +34 -30
- package/src/managers/storage-manager-factory.js +16 -16
- package/src/managers/storage-manager.js +178 -163
- package/src/managers/subscription-manager.js +12 -12
- package/src/models/backend-errors.js +5 -5
- package/src/models/braze-event.js +4 -4
- package/src/models/device.js +2 -2
- package/src/models/identifier.js +34 -14
- package/src/models/push-token.js +8 -8
- package/src/models/request-result.js +3 -3
- package/src/models/server-config.js +32 -23
- package/src/request-controller.js +187 -179
- package/src/triggers/models/custom-event-data.js +7 -7
- package/src/triggers/models/custom-event-property-data.js +10 -10
- package/src/triggers/models/filter-set.js +13 -13
- package/src/triggers/models/filter.js +45 -45
- package/src/triggers/models/in-app-message-click-data.js +12 -12
- package/src/triggers/models/purchase-data.js +2 -2
- package/src/triggers/models/purchase-property-data.js +10 -10
- package/src/triggers/models/push-click-data.js +7 -7
- package/src/triggers/models/trigger-condition.js +57 -59
- package/src/triggers/models/trigger-events.js +4 -4
- package/src/triggers/models/trigger.js +38 -38
- package/src/triggers/triggers-provider-factory.js +4 -4
- package/src/triggers/triggers-provider.js +127 -130
- package/src/ui/js/attach-css.js +2 -2
- package/src/ui/js/iam-css.js +1 -1
- package/src/ui/js/load-font-awesome.js +1 -1
- package/src/util/base-device-parser.js +3 -3
- package/src/util/braze-actions.js +35 -35
- package/src/util/browser-detector.js +21 -21
- package/src/util/client-hints-parser.js +8 -8
- package/src/util/code-utils.js +2 -2
- package/src/util/component-utils.js +1 -1
- package/src/util/deprecation-utils.js +4 -4
- package/src/util/device-constants.js +1 -1
- package/src/util/dom-utils.js +18 -18
- package/src/util/key-codes.js +1 -1
- package/src/util/net.js +18 -18
- package/src/util/request-header-utils.js +39 -37
- package/src/util/string-utils.js +10 -10
- package/src/util/user-agent-parser.js +18 -18
- package/src/util/validation-utils.js +37 -39
- package/src/util/window-utils.js +3 -3
- package/shared-lib/braze-shared-lib.js +0 -8
|
@@ -5,57 +5,58 @@ import {
|
|
|
5
5
|
convertSecondsToMs as Xt,
|
|
6
6
|
} from "../util/date-utils.js";
|
|
7
7
|
import s from "../common/event-logger.js";
|
|
8
|
-
import { isArray as
|
|
9
|
-
import r from "../../shared-lib/
|
|
10
|
-
import { STORAGE_KEYS as
|
|
11
|
-
import
|
|
12
|
-
import { LAST_REQUEST_TO_ENDPOINT_MS_AGO_DEFAULT as
|
|
8
|
+
import { isArray as j, isEqual as ii } from "../util/code-utils.js";
|
|
9
|
+
import { logger as r, EventTypes as i } from "../../shared-lib/index.js";
|
|
10
|
+
import { STORAGE_KEYS as o } from "./storage-manager.js";
|
|
11
|
+
import S from "../util/request-header-utils.js";
|
|
12
|
+
import { LAST_REQUEST_TO_ENDPOINT_MS_AGO_DEFAULT as Kt } from "../common/constants.js";
|
|
13
13
|
export default class Rt {
|
|
14
|
-
constructor(t, e, s, i, r, o,
|
|
15
|
-
(this.
|
|
14
|
+
constructor(t, e, s, i, r, n, o, a, h, u, l, c) {
|
|
15
|
+
(this.hn = t),
|
|
16
16
|
(this.u = e),
|
|
17
|
-
(this.
|
|
17
|
+
(this.Go = s),
|
|
18
18
|
(this.wt = i),
|
|
19
|
-
(this.
|
|
20
|
-
(this.yt =
|
|
21
|
-
(this.
|
|
22
|
-
(this.
|
|
23
|
-
(this.
|
|
24
|
-
(this.
|
|
25
|
-
(this.appVersion =
|
|
26
|
-
(this.
|
|
27
|
-
(this.
|
|
19
|
+
(this.di = r),
|
|
20
|
+
(this.yt = n),
|
|
21
|
+
(this.an = o),
|
|
22
|
+
(this.Ko = a),
|
|
23
|
+
(this.Wo = h),
|
|
24
|
+
(this.Vo = u),
|
|
25
|
+
(this.appVersion = l),
|
|
26
|
+
(this.Ra = c),
|
|
27
|
+
(this.Ba = (t) => (null == t ? "" : `${t} `)),
|
|
28
|
+
(this.hn = t),
|
|
28
29
|
(this.u = e),
|
|
29
|
-
(this.
|
|
30
|
+
(this.Go = s),
|
|
30
31
|
(this.wt = i),
|
|
31
|
-
(this.
|
|
32
|
-
(this.yt =
|
|
33
|
-
(this.
|
|
34
|
-
(this.
|
|
35
|
-
(this.
|
|
36
|
-
(this.
|
|
37
|
-
(this.appVersion =
|
|
38
|
-
(this.
|
|
39
|
-
(this
|
|
32
|
+
(this.di = r),
|
|
33
|
+
(this.yt = n),
|
|
34
|
+
(this.an = o),
|
|
35
|
+
(this.Ko = a),
|
|
36
|
+
(this.Wo = h),
|
|
37
|
+
(this.Vo = u),
|
|
38
|
+
(this.appVersion = l),
|
|
39
|
+
(this.Ra = c),
|
|
40
|
+
(this.Xa = ["npm"]);
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
n = this.u.
|
|
45
|
-
ii(n,
|
|
46
|
-
(t.api_key = this.
|
|
42
|
+
Ps(t, e = !1, s = !1) {
|
|
43
|
+
const i = this.hn.ce(!s),
|
|
44
|
+
r = i.Gr(),
|
|
45
|
+
n = this.u.j(o.C.Ja);
|
|
46
|
+
ii(n, r) || (t.device = r),
|
|
47
|
+
(t.api_key = this.an),
|
|
47
48
|
(t.time = h(new Date().valueOf(), !0));
|
|
48
|
-
const a = this.u.
|
|
49
|
-
u = this.u.
|
|
49
|
+
const a = this.u.j(o.C.Na) || [],
|
|
50
|
+
u = this.u.j(o.C.$a) || "";
|
|
50
51
|
if (
|
|
51
|
-
(this
|
|
52
|
-
(!ii(a, this
|
|
53
|
-
(t.sdk_metadata = this
|
|
54
|
-
(t.sdk_version = this.
|
|
55
|
-
this.
|
|
52
|
+
(this.Xa.length > 0 &&
|
|
53
|
+
(!ii(a, this.Xa) || u !== this.di.ki()) &&
|
|
54
|
+
(t.sdk_metadata = this.Xa),
|
|
55
|
+
(t.sdk_version = this.Wo),
|
|
56
|
+
this.Vo && (t.sdk_flavor = this.Vo),
|
|
56
57
|
(t.app_version = this.appVersion),
|
|
57
|
-
(t.app_version_code = this.
|
|
58
|
-
(t.device_id =
|
|
58
|
+
(t.app_version_code = this.Ra),
|
|
59
|
+
(t.device_id = i.id),
|
|
59
60
|
e)
|
|
60
61
|
) {
|
|
61
62
|
const e = this.wt.getUserId();
|
|
@@ -63,194 +64,244 @@ export default class Rt {
|
|
|
63
64
|
}
|
|
64
65
|
return t;
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
+
Ws(t, e, n) {
|
|
67
68
|
const o = e.auth_error,
|
|
68
|
-
|
|
69
|
-
if (!o && !
|
|
69
|
+
a = e.error;
|
|
70
|
+
if (!o && !a) return !0;
|
|
70
71
|
if (o) {
|
|
71
72
|
let e;
|
|
72
|
-
this.
|
|
73
|
+
this.Go.Gh();
|
|
73
74
|
const s = { errorCode: o.error_code };
|
|
74
|
-
for (const t of
|
|
75
|
-
|
|
75
|
+
for (const t of n)
|
|
76
|
+
j(t) && "X-Braze-Auth-Signature" === t[0] && (s.signature = t[1]);
|
|
76
77
|
t.respond_with && t.respond_with.user_id
|
|
77
78
|
? (s.userId = t.respond_with.user_id)
|
|
78
79
|
: t.user_id && (s.userId = t.user_id);
|
|
79
|
-
const
|
|
80
|
+
const i = o.reason;
|
|
80
81
|
return (
|
|
81
|
-
|
|
82
|
-
? ((s.reason =
|
|
82
|
+
i
|
|
83
|
+
? ((s.reason = i), (e = `due to ${i}`))
|
|
83
84
|
: (e = `with error code ${o.error_code}.`),
|
|
84
|
-
this.
|
|
85
|
+
this.Go.fh() ||
|
|
85
86
|
(e +=
|
|
86
87
|
' Please use the "enableSdkAuthentication" initialization option to enable authentication.'),
|
|
87
|
-
r.
|
|
88
|
-
this.
|
|
89
|
-
this.
|
|
88
|
+
r.error(`SDK Authentication failed ${e}`),
|
|
89
|
+
this.Ea(t.events || [], t.attributes || []),
|
|
90
|
+
this.Go.yh(s),
|
|
90
91
|
!1
|
|
91
92
|
);
|
|
92
93
|
}
|
|
93
|
-
if (
|
|
94
|
-
let
|
|
95
|
-
o =
|
|
94
|
+
if (a) {
|
|
95
|
+
let n,
|
|
96
|
+
o = a;
|
|
96
97
|
switch (o) {
|
|
97
|
-
case qt.
|
|
98
|
+
case qt.Ka:
|
|
98
99
|
return (
|
|
99
|
-
(
|
|
100
|
-
s.
|
|
101
|
-
r.
|
|
100
|
+
(n = "Received successful response with empty body."),
|
|
101
|
+
s.q(i.Ms, { e: n }),
|
|
102
|
+
r.info(n),
|
|
102
103
|
!1
|
|
103
104
|
);
|
|
104
|
-
case qt.
|
|
105
|
+
case qt.La:
|
|
105
106
|
return (
|
|
106
|
-
(
|
|
107
|
-
s.
|
|
108
|
-
r.
|
|
107
|
+
(n = "Received successful response with invalid JSON"),
|
|
108
|
+
s.q(i.Ms, { e: n + ": " + e.response }),
|
|
109
|
+
r.info(n),
|
|
109
110
|
!1
|
|
110
111
|
);
|
|
111
|
-
case qt.
|
|
112
|
-
o = `The API key "${t.api_key}" is invalid for the baseUrl ${this.
|
|
112
|
+
case qt.Pa:
|
|
113
|
+
o = `The API key "${t.api_key}" is invalid for the baseUrl ${this.Ko}`;
|
|
113
114
|
break;
|
|
114
|
-
case qt.
|
|
115
|
+
case qt.Ua:
|
|
115
116
|
o =
|
|
116
117
|
"Sorry, we are not currently accepting your requests. If you think this is in error, please contact us.";
|
|
117
118
|
break;
|
|
118
|
-
case qt.
|
|
119
|
+
case qt.Ha:
|
|
119
120
|
o = "No device identifier. Please contact support@braze.com";
|
|
120
121
|
}
|
|
121
|
-
r.
|
|
122
|
+
r.error("Backend error: " + o);
|
|
122
123
|
}
|
|
123
124
|
return !1;
|
|
124
125
|
}
|
|
125
|
-
|
|
126
|
+
Wa(t, e, s, i) {
|
|
126
127
|
return !!((t && 0 !== t.length) || (e && 0 !== e.length) || s || i);
|
|
127
128
|
}
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
let
|
|
129
|
+
Ya(t, e, s, i, r = !1) {
|
|
130
|
+
const n = [],
|
|
131
|
+
o = (t) => t || "",
|
|
132
|
+
a = o(this.wt.getUserId());
|
|
133
|
+
let h = this._r(t, e);
|
|
133
134
|
const u = [],
|
|
134
|
-
|
|
135
|
-
let
|
|
136
|
-
|
|
135
|
+
l = [];
|
|
136
|
+
let c,
|
|
137
|
+
d = null;
|
|
137
138
|
if (s.length > 0) {
|
|
138
139
|
const t = [];
|
|
139
140
|
for (const e of s) {
|
|
140
|
-
if (((
|
|
141
|
-
if (
|
|
142
|
-
|
|
141
|
+
if (((c = e.Gr()), this.Go.fh())) {
|
|
142
|
+
if (a && !c.user_id) {
|
|
143
|
+
d || (d = {}), d.events || (d.events = []), d.events.push(c);
|
|
143
144
|
continue;
|
|
144
145
|
}
|
|
145
|
-
if (
|
|
146
|
-
|
|
146
|
+
if (o(c.user_id) !== a) {
|
|
147
|
+
l.push(c);
|
|
147
148
|
continue;
|
|
148
149
|
}
|
|
149
150
|
}
|
|
150
|
-
t.push(
|
|
151
|
+
t.push(c);
|
|
151
152
|
}
|
|
152
|
-
t.length > 0 && (
|
|
153
|
+
t.length > 0 && (h.events = t);
|
|
153
154
|
}
|
|
154
155
|
if (i.length > 0) {
|
|
155
156
|
const t = [];
|
|
156
157
|
for (const e of i)
|
|
157
|
-
e && (this.
|
|
158
|
-
t.length > 0 && (
|
|
158
|
+
e && (this.Go.fh() && o(e.user_id) !== a ? u.push(e) : t.push(e));
|
|
159
|
+
t.length > 0 && (h.attributes = t);
|
|
159
160
|
}
|
|
160
|
-
if ((this.
|
|
161
|
-
|
|
162
|
-
const t = { requestData:
|
|
163
|
-
|
|
161
|
+
if ((this.Ea(l, u), (h = this.Ps(h, !0, r)), d)) {
|
|
162
|
+
d = this.Ps(d, !1, r);
|
|
163
|
+
const t = { requestData: d, headers: this._s(d, S.Gs.Qa) };
|
|
164
|
+
n.push(t);
|
|
164
165
|
}
|
|
165
|
-
if (
|
|
166
|
-
const
|
|
167
|
-
return
|
|
166
|
+
if (h && !this.Wa(h.events, h.attributes, t, e)) return d ? n : null;
|
|
167
|
+
const f = { requestData: h, headers: this._s(h, S.Gs.Qa) };
|
|
168
|
+
return n.push(f), n;
|
|
168
169
|
}
|
|
169
|
-
|
|
170
|
+
Ea(t, e) {
|
|
170
171
|
if (t) {
|
|
171
172
|
const e = [];
|
|
172
173
|
for (const s of t) {
|
|
173
174
|
const t = ue.fromJson(s);
|
|
174
175
|
(t.time = Xt(t.time)), e.push(t);
|
|
175
176
|
}
|
|
176
|
-
this.u.
|
|
177
|
+
this.u.zo(e);
|
|
177
178
|
}
|
|
178
|
-
if (e) for (const t of e) this.u.
|
|
179
|
+
if (e) for (const t of e) this.u.Va(t);
|
|
179
180
|
}
|
|
180
|
-
|
|
181
|
+
Zs(t, e) {
|
|
181
182
|
let s = "HTTP error ";
|
|
182
|
-
null != t && (s += t + " "), (s += e), r.
|
|
183
|
+
null != t && (s += t + " "), (s += e), r.error(s);
|
|
183
184
|
}
|
|
184
185
|
qr(t) {
|
|
185
|
-
return s.
|
|
186
|
+
return s.q(i.Za, { n: t });
|
|
186
187
|
}
|
|
187
|
-
|
|
188
|
+
_r(t, e, s) {
|
|
188
189
|
const i = {};
|
|
189
190
|
t && (i.feed = !0), e && (i.triggers = !0);
|
|
190
191
|
const r = null != s ? s : this.wt.getUserId();
|
|
191
192
|
return (
|
|
192
193
|
r && (i.user_id = r),
|
|
193
|
-
(i.config = { config_time: this.yt.
|
|
194
|
+
(i.config = { config_time: this.yt.ni() }),
|
|
194
195
|
{ respond_with: i }
|
|
195
196
|
);
|
|
196
197
|
}
|
|
197
|
-
|
|
198
|
+
Xh(t) {
|
|
198
199
|
const e = new Date().valueOf();
|
|
199
|
-
let s =
|
|
200
|
-
const i =
|
|
200
|
+
let s = Kt.toString();
|
|
201
|
+
const i = S.Yh(this.u, t);
|
|
201
202
|
if (-1 !== i) {
|
|
202
203
|
s = (e - i).toString();
|
|
203
204
|
}
|
|
204
205
|
return s;
|
|
205
206
|
}
|
|
206
|
-
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const n =
|
|
211
|
-
|
|
212
|
-
let
|
|
207
|
+
_s(t, e, s = !1) {
|
|
208
|
+
const i = [["X-Braze-Api-Key", this.an]],
|
|
209
|
+
r = this.Xh(e);
|
|
210
|
+
i.push(["X-Braze-Last-Req-Ms-Ago", r]);
|
|
211
|
+
const n = S.Jh(this.u, e).toString();
|
|
212
|
+
i.push(["X-Braze-Req-Attempt", n]);
|
|
213
|
+
let a = !1;
|
|
213
214
|
if (
|
|
214
215
|
(null != t.respond_with &&
|
|
215
216
|
t.respond_with.triggers &&
|
|
216
|
-
(
|
|
217
|
+
(i.push(["X-Braze-TriggersRequest", "true"]), (a = !0)),
|
|
217
218
|
null != t.respond_with &&
|
|
218
219
|
t.respond_with.feed &&
|
|
219
|
-
(
|
|
220
|
-
e ===
|
|
220
|
+
(i.push(["X-Braze-FeedRequest", "true"]), (a = !0)),
|
|
221
|
+
e === S.Gs.Bs)
|
|
221
222
|
) {
|
|
222
|
-
|
|
223
|
-
let t = this.u.
|
|
224
|
-
(t && s) || ((t = 0), this.u.
|
|
225
|
-
|
|
226
|
-
(
|
|
223
|
+
i.push(["X-Braze-ContentCardsRequest", "true"]);
|
|
224
|
+
let t = this.u.j(o.C.As);
|
|
225
|
+
(t && s) || ((t = 0), this.u.k(o.C.As, t)),
|
|
226
|
+
i.push(["BRAZE-SYNC-RETRY-COUNT", t.toString()]),
|
|
227
|
+
(a = !0);
|
|
227
228
|
}
|
|
228
229
|
if (
|
|
229
|
-
(e ===
|
|
230
|
-
(
|
|
231
|
-
|
|
232
|
-
this.
|
|
230
|
+
(e === S.Gs.qi &&
|
|
231
|
+
(i.push(["X-Braze-FeatureFlagsRequest", "true"]), (a = !0)),
|
|
232
|
+
a && i.push(["X-Braze-DataRequest", "true"]),
|
|
233
|
+
this.Go.fh())
|
|
233
234
|
) {
|
|
234
|
-
const t = this.
|
|
235
|
-
null != t &&
|
|
235
|
+
const t = this.Go.wh();
|
|
236
|
+
null != t && i.push(["X-Braze-Auth-Signature", t]);
|
|
236
237
|
}
|
|
237
|
-
return
|
|
238
|
+
return i;
|
|
238
239
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
240
|
+
Qh(t, e, s, i) {
|
|
241
|
+
window.setTimeout(() => {
|
|
242
|
+
r.info(`Retrying rate limited ${this.Ba(i)}SDK request.`),
|
|
243
|
+
this.Hs(e, s, i);
|
|
244
|
+
}, t);
|
|
245
|
+
}
|
|
246
|
+
Hs(t, e, s) {
|
|
247
|
+
const i = this.Zh();
|
|
248
|
+
if (!i.au)
|
|
249
|
+
return (
|
|
250
|
+
r.info(
|
|
251
|
+
`${this.Ba(
|
|
252
|
+
s,
|
|
253
|
+
)}SDK request being rate limited. Request will be retried in ${Math.trunc(
|
|
254
|
+
i.du / 1e3,
|
|
255
|
+
)} seconds.`,
|
|
256
|
+
),
|
|
257
|
+
void this.Qh(i.du, t, e, s)
|
|
258
|
+
);
|
|
259
|
+
this.u.k(o.C.fu, new Date().valueOf());
|
|
260
|
+
const n = t.device;
|
|
261
|
+
n && n.os_version instanceof Promise
|
|
262
|
+
? n.os_version.then((s) => {
|
|
243
263
|
(t.device.os_version = s), e();
|
|
244
264
|
})
|
|
245
265
|
: e();
|
|
246
266
|
}
|
|
247
|
-
|
|
248
|
-
|
|
267
|
+
li(t) {
|
|
268
|
+
var e;
|
|
269
|
+
null === (e = this.u) || void 0 === e || e.k(o.C.Ru, t);
|
|
270
|
+
}
|
|
271
|
+
ui() {
|
|
272
|
+
var t;
|
|
273
|
+
return null === (t = this.u) || void 0 === t ? void 0 : t.j(o.C.Ru);
|
|
274
|
+
}
|
|
275
|
+
vu(t, e, s, i) {
|
|
276
|
+
let r = this.ui();
|
|
277
|
+
(null == r || isNaN(r)) && (r = e);
|
|
278
|
+
const n = (t - i) / 1e3;
|
|
279
|
+
return (r = Math.min(r + n / s, e)), r;
|
|
280
|
+
}
|
|
281
|
+
gu(t, e) {
|
|
282
|
+
return Math.max(0, (1 - t) * e * 1e3);
|
|
283
|
+
}
|
|
284
|
+
Zh() {
|
|
285
|
+
var t, e, s;
|
|
286
|
+
const i = { au: !0, du: 0 },
|
|
287
|
+
r = null === (t = this.u) || void 0 === t ? void 0 : t.j(o.C.fu);
|
|
288
|
+
if (null == r || isNaN(r)) return i;
|
|
289
|
+
const n = (null === (e = this.yt) || void 0 === e ? void 0 : e.pu()) || -1,
|
|
290
|
+
a = (null === (s = this.yt) || void 0 === s ? void 0 : s.qu()) || -1;
|
|
291
|
+
if (-1 === n || -1 === a) return i;
|
|
292
|
+
const h = new Date().valueOf();
|
|
293
|
+
let u = this.vu(h, n, a, r);
|
|
294
|
+
return u < 1
|
|
295
|
+
? ((i.au = !1), (i.du = this.gu(u, a)), i)
|
|
296
|
+
: ((u = Math.trunc(u) - 1), this.li(u), i);
|
|
297
|
+
}
|
|
298
|
+
Xs() {
|
|
299
|
+
this.Go.Xs();
|
|
249
300
|
}
|
|
250
|
-
|
|
251
|
-
return this.
|
|
301
|
+
Vs() {
|
|
302
|
+
return this.Ko;
|
|
252
303
|
}
|
|
253
304
|
addSdkMetadata(t) {
|
|
254
|
-
for (const e of t) -1 === this
|
|
305
|
+
for (const e of t) -1 === this.Xa.indexOf(e) && this.Xa.push(e);
|
|
255
306
|
}
|
|
256
307
|
}
|
|
@@ -1,108 +1,124 @@
|
|
|
1
|
-
import { STORAGE_KEYS as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { STORAGE_KEYS as o } from "./storage-manager.js";
|
|
2
|
+
import T from "./subscription-manager.js";
|
|
3
|
+
import Gt from "../models/server-config.js";
|
|
4
4
|
import s from "../common/event-logger.js";
|
|
5
|
-
import
|
|
5
|
+
import { EventTypes as i } from "../../shared-lib/index.js";
|
|
6
6
|
import {
|
|
7
7
|
CONTENT_CARDS_RATE_LIMIT_CAPACITY_DEFAULT as Vt,
|
|
8
|
-
CONTENT_CARDS_RATE_LIMIT_REFILL_RATE_DEFAULT as
|
|
8
|
+
CONTENT_CARDS_RATE_LIMIT_REFILL_RATE_DEFAULT as Ht,
|
|
9
9
|
} from "../common/constants.js";
|
|
10
|
-
export default class
|
|
10
|
+
export default class Dt {
|
|
11
11
|
constructor(t) {
|
|
12
12
|
(this.u = t),
|
|
13
13
|
(this.u = t),
|
|
14
|
-
(this.tl = new
|
|
15
|
-
(this.el = new
|
|
16
|
-
(this.
|
|
17
|
-
(this.
|
|
14
|
+
(this.tl = new T()),
|
|
15
|
+
(this.el = new T()),
|
|
16
|
+
(this.il = new T()),
|
|
17
|
+
(this.sl = null),
|
|
18
18
|
(this.rl = null);
|
|
19
19
|
}
|
|
20
20
|
ll() {
|
|
21
21
|
if (null == this.rl) {
|
|
22
|
-
const t = this.u.
|
|
23
|
-
this.rl = null != t ?
|
|
22
|
+
const t = this.u.j(o.C.hl);
|
|
23
|
+
this.rl = null != t ? Gt.En(t) : new Gt();
|
|
24
24
|
}
|
|
25
25
|
return this.rl;
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
ni() {
|
|
28
28
|
return this.ll().ol;
|
|
29
29
|
}
|
|
30
30
|
ul(t) {
|
|
31
31
|
if (null != t && null != t.config) {
|
|
32
32
|
const e = t.config;
|
|
33
33
|
if (e.time > this.ll().ol) {
|
|
34
|
-
const t =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
const t = (t) => (null == t ? this.ll().al : t),
|
|
35
|
+
i = new Gt(
|
|
36
|
+
e.time,
|
|
37
|
+
e.events_blacklist,
|
|
38
|
+
e.attributes_blacklist,
|
|
39
|
+
e.purchases_blacklist,
|
|
40
|
+
e.messaging_session_timeout,
|
|
41
|
+
e.vapid_public_key,
|
|
42
|
+
e.content_cards,
|
|
43
|
+
e.feature_flags,
|
|
44
|
+
t(e.global_request_rate_limit),
|
|
45
|
+
);
|
|
44
46
|
let s = !1;
|
|
45
|
-
null !=
|
|
47
|
+
null != i.cl && this.In() !== i.cl && (s = !0);
|
|
46
48
|
let r = !1;
|
|
47
|
-
null !=
|
|
49
|
+
null != i.ml.enabled && this.ri() !== i.ml.enabled && (r = !0);
|
|
48
50
|
let n = !1;
|
|
49
|
-
null !=
|
|
50
|
-
(this.rl =
|
|
51
|
-
this.u.
|
|
51
|
+
null != i.mi.enabled && this.yi() !== i.mi.enabled && (n = !0),
|
|
52
|
+
(this.rl = i),
|
|
53
|
+
this.u.k(o.C.hl, i.Y()),
|
|
52
54
|
s && this.tl.Dt(),
|
|
53
55
|
r && this.el.Dt(),
|
|
54
|
-
n && this.
|
|
56
|
+
n && this.il.Dt();
|
|
55
57
|
}
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
|
-
|
|
60
|
+
Vn(t) {
|
|
59
61
|
const e = this.tl.It(t);
|
|
60
|
-
return this.
|
|
62
|
+
return this.sl && this.tl.removeSubscription(this.sl), (this.sl = e), e;
|
|
61
63
|
}
|
|
62
|
-
|
|
64
|
+
qs(t) {
|
|
63
65
|
return this.el.It(t);
|
|
64
66
|
}
|
|
65
|
-
|
|
66
|
-
return this.
|
|
67
|
+
xi(t) {
|
|
68
|
+
return this.il.It(t);
|
|
67
69
|
}
|
|
68
|
-
|
|
69
|
-
return -1 !== this.ll().
|
|
70
|
+
me(t) {
|
|
71
|
+
return -1 !== this.ll().gl.indexOf(t);
|
|
70
72
|
}
|
|
71
73
|
hu(t) {
|
|
72
|
-
return -1 !== this.ll().
|
|
74
|
+
return -1 !== this.ll().fl.indexOf(t);
|
|
73
75
|
}
|
|
74
76
|
Dr(t) {
|
|
75
|
-
return -1 !== this.ll().
|
|
77
|
+
return -1 !== this.ll().bl.indexOf(t);
|
|
76
78
|
}
|
|
77
79
|
dl() {
|
|
78
|
-
return this.ll().
|
|
80
|
+
return this.ll().Cl;
|
|
79
81
|
}
|
|
80
|
-
|
|
81
|
-
return this.ll().
|
|
82
|
+
In() {
|
|
83
|
+
return this.ll().cl;
|
|
82
84
|
}
|
|
83
|
-
|
|
85
|
+
ri() {
|
|
84
86
|
return this.ll().ml.enabled || !1;
|
|
85
87
|
}
|
|
86
|
-
|
|
88
|
+
Is() {
|
|
87
89
|
const t = this.ll().ml.rate_limit;
|
|
88
90
|
return !(!t || null == t.enabled) && t.enabled;
|
|
89
91
|
}
|
|
90
|
-
|
|
91
|
-
if (!this
|
|
92
|
+
ci() {
|
|
93
|
+
if (!this.Is()) return -1;
|
|
92
94
|
const t = this.ll().ml.rate_limit;
|
|
93
95
|
return null == t.capacity ? Vt : t.capacity <= 0 ? -1 : t.capacity;
|
|
94
96
|
}
|
|
95
|
-
|
|
96
|
-
if (!this
|
|
97
|
+
fi() {
|
|
98
|
+
if (!this.Is()) return -1;
|
|
97
99
|
const t = this.ll().ml.rate_limit;
|
|
98
|
-
return null == t.refill_rate ?
|
|
100
|
+
return null == t.refill_rate ? Ht : t.refill_rate <= 0 ? -1 : t.refill_rate;
|
|
101
|
+
}
|
|
102
|
+
Rl() {
|
|
103
|
+
const t = this.ll().al;
|
|
104
|
+
return !(!t || null == t.enabled) && t.enabled;
|
|
105
|
+
}
|
|
106
|
+
pu() {
|
|
107
|
+
if (!this.Rl()) return -1;
|
|
108
|
+
const t = this.ll().al;
|
|
109
|
+
return null == t.capacity || t.capacity < 10 ? -1 : t.capacity;
|
|
110
|
+
}
|
|
111
|
+
qu() {
|
|
112
|
+
if (!this.Rl()) return -1;
|
|
113
|
+
const t = this.ll().al;
|
|
114
|
+
return null == t.refill_rate || t.refill_rate <= 0 ? -1 : t.refill_rate;
|
|
99
115
|
}
|
|
100
116
|
yi() {
|
|
101
|
-
return this.ll().
|
|
102
|
-
? (s.
|
|
103
|
-
: this.ll().
|
|
117
|
+
return this.ll().mi.enabled && null == this.zi()
|
|
118
|
+
? (s.q(i.Ms, { e: "Missing feature flag refresh_rate_limit." }), !1)
|
|
119
|
+
: this.ll().mi.enabled || !1;
|
|
104
120
|
}
|
|
105
|
-
|
|
106
|
-
return this.ll().
|
|
121
|
+
zi() {
|
|
122
|
+
return this.ll().mi.refresh_rate_limit;
|
|
107
123
|
}
|
|
108
124
|
}
|