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