@braze/web-sdk 5.0.0 → 5.1.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 (158) hide show
  1. package/README.md +1 -1
  2. package/index.d.ts +12 -5
  3. package/package.json +1 -1
  4. package/shared-lib/encoding-utils.js +3 -3
  5. package/shared-lib/event-types.js +29 -29
  6. package/shared-lib/guid.js +3 -3
  7. package/shared-lib/index.js +6 -0
  8. package/shared-lib/indexed-db-adapter.js +70 -70
  9. package/shared-lib/logger.js +18 -18
  10. package/shared-lib/supported-options.js +21 -21
  11. package/src/Card/card-manager.js +43 -45
  12. package/src/Card/display/card-display.js +60 -60
  13. package/src/Card/log-card-click.js +4 -4
  14. package/src/Card/log-card-dismissal.js +2 -3
  15. package/src/Card/log-card-impressions.js +7 -7
  16. package/src/Card/models/captioned-image.js +21 -21
  17. package/src/Card/models/card.js +73 -73
  18. package/src/Card/models/classic-card.js +21 -21
  19. package/src/Card/models/control-card.js +11 -11
  20. package/src/Card/models/image-only.js +19 -19
  21. package/src/Card/util/card-factory.js +68 -68
  22. package/src/ContentCards/content-cards-provider-factory.js +3 -3
  23. package/src/ContentCards/content-cards-provider.js +255 -245
  24. package/src/ContentCards/content-cards.js +2 -2
  25. package/src/ContentCards/get-cached-content-cards.js +1 -1
  26. package/src/ContentCards/request-content-cards-refresh.js +1 -1
  27. package/src/ContentCards/subscribe-to-content-cards-updates.js +6 -6
  28. package/src/ContentCards/ui/hide-content-cards.js +1 -1
  29. package/src/ContentCards/ui/show-content-cards.js +24 -24
  30. package/src/ContentCards/ui/toggle-content-cards.js +1 -1
  31. package/src/Core/add-sdk-metadata.js +21 -19
  32. package/src/Core/change-user.js +10 -10
  33. package/src/Core/destroy.js +2 -2
  34. package/src/Core/disable-sdk.js +11 -11
  35. package/src/Core/enable-sdk.js +7 -7
  36. package/src/Core/get-device-id.js +6 -6
  37. package/src/Core/get-user.js +1 -1
  38. package/src/Core/handle-braze-action.js +41 -41
  39. package/src/Core/is-disabled.js +2 -2
  40. package/src/Core/log-custom-event.js +15 -15
  41. package/src/Core/log-purchase.js +31 -37
  42. package/src/Core/open-session.js +12 -12
  43. package/src/Core/remove-all-subscriptions.js +1 -1
  44. package/src/Core/remove-subscription.js +1 -1
  45. package/src/Core/request-immediate-data-flush.js +1 -1
  46. package/src/Core/set-logger.js +2 -2
  47. package/src/Core/set-sdk-authentication-signature.js +3 -3
  48. package/src/Core/subscribe-to-sdk-authentication-failures.js +6 -4
  49. package/src/Core/toggle-logging.js +2 -2
  50. package/src/Core/wipe-data.js +9 -9
  51. package/src/FeatureFlags/feature-flag-factory.js +12 -12
  52. package/src/FeatureFlags/feature-flag.js +10 -10
  53. package/src/FeatureFlags/feature-flags-provider-factory.js +3 -2
  54. package/src/FeatureFlags/feature-flags-provider.js +108 -80
  55. package/src/FeatureFlags/get-all-feature-flags.js +5 -5
  56. package/src/FeatureFlags/get-feature-flag.js +6 -6
  57. package/src/FeatureFlags/log-feature-flag-impression.js +15 -13
  58. package/src/FeatureFlags/refresh-feature-flags.js +1 -1
  59. package/src/FeatureFlags/subscribe-to-feature-flags-updates.js +7 -4
  60. package/src/Feed/feed-provider-factory.js +2 -2
  61. package/src/Feed/feed-provider.js +44 -44
  62. package/src/Feed/feed.js +1 -1
  63. package/src/Feed/get-cached-feed.js +1 -1
  64. package/src/Feed/log-feed-displayed.js +4 -4
  65. package/src/Feed/request-feed-refresh.js +1 -1
  66. package/src/Feed/subscribe-to-feed-updates.js +1 -1
  67. package/src/Feed/ui/hide-feed.js +1 -1
  68. package/src/Feed/ui/show-feed.js +28 -28
  69. package/src/Feed/ui/toggle-feed.js +1 -1
  70. package/src/InAppMessage/defer-in-app-message.js +5 -5
  71. package/src/InAppMessage/display/html-message-to-html.js +54 -54
  72. package/src/InAppMessage/display/in-app-message-to-html.js +79 -79
  73. package/src/InAppMessage/display/modal-utils.js +8 -8
  74. package/src/InAppMessage/get-deferred-in-app-message.js +1 -1
  75. package/src/InAppMessage/in-app-message-factory.js +49 -49
  76. package/src/InAppMessage/in-app-message-manager-factory.js +1 -1
  77. package/src/InAppMessage/in-app-message-manager.js +143 -138
  78. package/src/InAppMessage/log-in-app-message-button-click.js +12 -12
  79. package/src/InAppMessage/log-in-app-message-click.js +9 -9
  80. package/src/InAppMessage/log-in-app-message-html-click.js +12 -12
  81. package/src/InAppMessage/log-in-app-message-impression.js +6 -6
  82. package/src/InAppMessage/models/full-screen-message.js +33 -33
  83. package/src/InAppMessage/models/html-message.js +20 -20
  84. package/src/InAppMessage/models/in-app-message-button.js +6 -6
  85. package/src/InAppMessage/models/in-app-message.js +99 -99
  86. package/src/InAppMessage/models/modal-message.js +32 -32
  87. package/src/InAppMessage/models/slide-up-message.js +28 -28
  88. package/src/InAppMessage/models/templated-in-app-message.js +8 -8
  89. package/src/InAppMessage/subscribe-to-in-app-message.js +2 -2
  90. package/src/InAppMessage/ui/automatically-show-in-app-messages.js +4 -4
  91. package/src/InAppMessage/ui/show-in-app-message.js +81 -81
  92. package/src/Push/is-push-blocked.js +1 -1
  93. package/src/Push/is-push-permission-granted.js +1 -1
  94. package/src/Push/is-push-supported.js +1 -1
  95. package/src/Push/push-manager-factory.js +5 -5
  96. package/src/Push/push-manager.js +176 -173
  97. package/src/Push/request-push-permission.js +1 -1
  98. package/src/Push/unregister-push.js +1 -1
  99. package/src/Push/utils/push-utils.js +4 -4
  100. package/src/User/user-manager.js +29 -29
  101. package/src/User/user.js +72 -74
  102. package/src/common/base-feed.js +7 -7
  103. package/src/common/base-provider.js +1 -1
  104. package/src/common/constants.js +2 -0
  105. package/src/common/event-logger.js +21 -18
  106. package/src/common/feed-display.js +44 -44
  107. package/src/l10n/l10n-manager-factory.js +3 -3
  108. package/src/l10n/l10n-manager.js +7 -7
  109. package/src/managers/auth-manager.js +32 -32
  110. package/src/managers/braze-instance.js +188 -189
  111. package/src/managers/device-manager.js +28 -28
  112. package/src/managers/network-manager.js +189 -138
  113. package/src/managers/server-config-manager.js +69 -53
  114. package/src/managers/session-manager.js +34 -30
  115. package/src/managers/storage-manager-factory.js +16 -16
  116. package/src/managers/storage-manager.js +210 -188
  117. package/src/managers/subscription-manager.js +12 -12
  118. package/src/models/backend-errors.js +5 -5
  119. package/src/models/braze-event.js +3 -3
  120. package/src/models/device.js +2 -2
  121. package/src/models/identifier.js +34 -14
  122. package/src/models/push-token.js +8 -8
  123. package/src/models/request-result.js +3 -3
  124. package/src/models/server-config.js +32 -23
  125. package/src/request-controller.js +187 -180
  126. package/src/triggers/models/custom-event-data.js +7 -7
  127. package/src/triggers/models/custom-event-property-data.js +10 -10
  128. package/src/triggers/models/filter-set.js +13 -13
  129. package/src/triggers/models/filter.js +45 -45
  130. package/src/triggers/models/in-app-message-click-data.js +12 -12
  131. package/src/triggers/models/purchase-data.js +2 -2
  132. package/src/triggers/models/purchase-property-data.js +10 -10
  133. package/src/triggers/models/push-click-data.js +7 -7
  134. package/src/triggers/models/trigger-condition.js +57 -59
  135. package/src/triggers/models/trigger-events.js +4 -4
  136. package/src/triggers/models/trigger.js +38 -38
  137. package/src/triggers/triggers-provider-factory.js +4 -4
  138. package/src/triggers/triggers-provider.js +127 -130
  139. package/src/ui/js/attach-css.js +2 -2
  140. package/src/ui/js/iam-css.js +1 -1
  141. package/src/ui/js/load-font-awesome.js +1 -1
  142. package/src/util/base-device-parser.js +3 -3
  143. package/src/util/braze-actions.js +35 -35
  144. package/src/util/browser-detector.js +21 -21
  145. package/src/util/client-hints-parser.js +8 -8
  146. package/src/util/code-utils.js +2 -2
  147. package/src/util/component-utils.js +1 -1
  148. package/src/util/deprecation-utils.js +4 -4
  149. package/src/util/device-constants.js +1 -1
  150. package/src/util/dom-utils.js +18 -18
  151. package/src/util/key-codes.js +1 -1
  152. package/src/util/net.js +18 -18
  153. package/src/util/request-header-utils.js +39 -37
  154. package/src/util/string-utils.js +10 -10
  155. package/src/util/user-agent-parser.js +18 -18
  156. package/src/util/validation-utils.js +37 -39
  157. package/src/util/window-utils.js +3 -3
  158. 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 p, isEqual as ii } from "../util/code-utils.js";
9
- import r from "../../shared-lib/braze-shared-lib.js";
10
- import { STORAGE_KEYS as i } from "./storage-manager.js";
11
- import T from "../util/request-header-utils.js";
12
- import { LAST_REQUEST_TO_ENDPOINT_MS_AGO_DEFAULT as Ht } from "../common/constants.js";
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, n, h, a, u, c, l) {
15
- (this.fn = t),
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.Mo = s),
17
+ (this.Go = s),
18
18
  (this.wt = i),
19
- (this._e = r),
20
- (this.yt = o),
21
- (this.cn = n),
22
- (this.Uo = h),
23
- (this.jo = a),
24
- (this.Do = u),
25
- (this.appVersion = c),
26
- (this.Xh = l),
27
- (this.fn = t),
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.Mo = s),
30
+ (this.Go = s),
30
31
  (this.wt = i),
31
- (this._e = r),
32
- (this.yt = o),
33
- (this.cn = n),
34
- (this.Uo = h),
35
- (this.jo = a),
36
- (this.Do = u),
37
- (this.appVersion = c),
38
- (this.Xh = l),
39
- (this.$h = ["npm"]);
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
- Bs(t, e = !1, s = !1) {
42
- const r = this.fn.ce(!s),
43
- o = r.Kr(),
44
- n = this.u.v(i.k.Ca);
45
- ii(n, o) || (t.device = o),
46
- (t.api_key = this.cn),
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.v(i.k.Kh) || [],
49
- u = this.u.v(i.k.Wh) || "";
49
+ const a = this.u.j(o.C.Na) || [],
50
+ u = this.u.j(o.C.$a) || "";
50
51
  if (
51
- (this.$h.length > 0 &&
52
- (!ii(a, this.$h) || u !== this._e.Yh()) &&
53
- (t.sdk_metadata = this.$h),
54
- (t.sdk_version = this.jo),
55
- this.Do && (t.sdk_flavor = this.Do),
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.Xh),
58
- (t.device_id = r.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
- Zs(t, e, i) {
67
+ Ws(t, e, n) {
67
68
  const o = e.auth_error,
68
- n = e.error;
69
- if (!o && !n) return !0;
69
+ a = e.error;
70
+ if (!o && !a) return !0;
70
71
  if (o) {
71
72
  let e;
72
- this.Mo.Hh();
73
+ this.Go.Gh();
73
74
  const s = { errorCode: o.error_code };
74
- for (const t of i)
75
- p(t) && "X-Braze-Auth-Signature" === t[0] && (s.signature = t[1]);
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 n = o.reason;
80
+ const i = o.reason;
80
81
  return (
81
- n
82
- ? ((s.reason = n), (e = `due to ${n}`))
82
+ i
83
+ ? ((s.reason = i), (e = `due to ${i}`))
83
84
  : (e = `with error code ${o.error_code}.`),
84
- this.Mo.wh() ||
85
+ this.Go.fh() ||
85
86
  (e +=
86
87
  ' Please use the "enableSdkAuthentication" initialization option to enable authentication.'),
87
- r.j.error(`SDK Authentication failed ${e}`),
88
- this.Qh(t.events || [], t.attributes || []),
89
- this.Mo.Bh(s),
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 (n) {
94
- let i,
95
- o = n;
94
+ if (a) {
95
+ let n,
96
+ o = a;
96
97
  switch (o) {
97
- case qt.Vh:
98
+ case qt.Ka:
98
99
  return (
99
- (i = "Received successful response with empty body."),
100
- s.N(r.q.qs, { e: i }),
101
- r.j.info(i),
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.Zh:
105
+ case qt.La:
105
106
  return (
106
- (i = "Received successful response with invalid JSON"),
107
- s.N(r.q.qs, { e: i + ": " + e.response }),
108
- r.j.info(i),
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.Ra:
112
- o = `The API key "${t.api_key}" is invalid for the baseUrl ${this.Uo}`;
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.Xa:
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.Ea:
119
+ case qt.Ha:
119
120
  o = "No device identifier. Please contact support@braze.com";
120
121
  }
121
- r.j.error("Backend error: " + o);
122
+ r.error("Backend error: " + o);
122
123
  }
123
124
  return !1;
124
125
  }
125
- Pa(t, e, s, i) {
126
+ Wa(t, e, s, i) {
126
127
  return !!((t && 0 !== t.length) || (e && 0 !== e.length) || s || i);
127
128
  }
128
- $a(t, e, s, i, r = !1) {
129
- const o = [],
130
- n = (t) => t || "",
131
- h = n(this.wt.getUserId());
132
- let a = this.Jr(t, e);
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
- c = [];
135
- let l,
136
- f = null;
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 (((l = e.Kr()), this.Mo.wh())) {
141
- if (h && !l.user_id) {
142
- f || (f = {}), f.events || (f.events = []), f.events.push(l);
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 (n(l.user_id) !== h) {
146
- c.push(l);
146
+ if (o(c.user_id) !== a) {
147
+ l.push(c);
147
148
  continue;
148
149
  }
149
150
  }
150
- t.push(l);
151
+ t.push(c);
151
152
  }
152
- t.length > 0 && (a.events = t);
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.Mo.wh() && n(e.user_id) !== h ? u.push(e) : t.push(e));
158
- t.length > 0 && (a.attributes = t);
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.Qh(c, u), (a = this.Bs(a, !0, r)), f)) {
161
- f = this.Bs(f, !1, r);
162
- const t = { requestData: f, headers: this.Hs(f, T.Os.Na) };
163
- o.push(t);
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 (a && !this.Pa(a.events, a.attributes, t, e)) return f ? o : null;
166
- const d = { requestData: a, headers: this.Hs(a, T.Os.Na) };
167
- return o.push(d), o;
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
- Qh(t, e) {
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.bo(e);
177
+ this.u.zo(e);
177
178
  }
178
- if (e) for (const t of e) this.u.Ha(t);
179
+ if (e) for (const t of e) this.u.Va(t);
179
180
  }
180
- ii(t, e) {
181
+ Zs(t, e) {
181
182
  let s = "HTTP error ";
182
- null != t && (s += t + " "), (s += e), r.j.error(s);
183
+ null != t && (s += t + " "), (s += e), r.error(s);
183
184
  }
184
185
  qr(t) {
185
- return s.N(r.q.Ka, { n: t });
186
+ return s.q(i.Za, { n: t });
186
187
  }
187
- Jr(t, e, s) {
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.li() }),
194
+ (i.config = { config_time: this.yt.ni() }),
194
195
  { respond_with: i }
195
196
  );
196
197
  }
197
- Ua(t) {
198
+ Xh(t) {
198
199
  const e = new Date().valueOf();
199
- let s = Ht.toString();
200
- const i = T.La(this.u, t);
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
- Hs(t, e, s = !1) {
207
- const r = [["X-Braze-Api-Key", this.cn]],
208
- o = this.Ua(e);
209
- r.push(["X-Braze-Last-Req-Ms-Ago", o]);
210
- const n = T.Wa(this.u, e).toString();
211
- r.push(["X-Braze-Req-Attempt", n]);
212
- let h = !1;
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
- (r.push(["X-Braze-TriggersRequest", "true"]), (h = !0)),
217
+ (i.push(["X-Braze-TriggersRequest", "true"]), (a = !0)),
217
218
  null != t.respond_with &&
218
219
  t.respond_with.feed &&
219
- (r.push(["X-Braze-FeedRequest", "true"]), (h = !0)),
220
- e === T.Os.Ks)
220
+ (i.push(["X-Braze-FeedRequest", "true"]), (a = !0)),
221
+ e === S.Gs.Bs)
221
222
  ) {
222
- r.push(["X-Braze-ContentCardsRequest", "true"]);
223
- let t = this.u.v(i.k.zs);
224
- (t && s) || ((t = 0), this.u.D(i.k.zs, t)),
225
- r.push(["BRAZE-SYNC-RETRY-COUNT", t.toString()]),
226
- (h = !0);
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 === T.Os.Si &&
230
- (r.push(["X-Braze-FeatureFlagsRequest", "true"]), (h = !0)),
231
- h && r.push(["X-Braze-DataRequest", "true"]),
232
- this.Mo.wh())
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.Mo.jh();
235
- null != t && r.push(["X-Braze-Auth-Signature", t]);
235
+ const t = this.Go.wh();
236
+ null != t && i.push(["X-Braze-Auth-Signature", t]);
236
237
  }
237
- return r;
238
+ return i;
238
239
  }
239
- Qs(t, e) {
240
- const s = t.device;
241
- s && s.os_version instanceof Promise
242
- ? s.os_version.then((s) => {
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
- ti() {
248
- this.Mo.ti();
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
- Ys() {
251
- return this.Uo;
301
+ Vs() {
302
+ return this.Ko;
252
303
  }
253
304
  addSdkMetadata(t) {
254
- for (const e of t) -1 === this.$h.indexOf(e) && this.$h.push(e);
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 i } from "./storage-manager.js";
2
- import E from "./subscription-manager.js";
3
- import Kt from "../models/server-config.js";
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 r from "../../shared-lib/braze-shared-lib.js";
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 Gt,
8
+ CONTENT_CARDS_RATE_LIMIT_REFILL_RATE_DEFAULT as Ht,
9
9
  } from "../common/constants.js";
10
- export default class jt {
10
+ export default class Dt {
11
11
  constructor(t) {
12
12
  (this.u = t),
13
13
  (this.u = t),
14
- (this.tl = new E()),
15
- (this.el = new E()),
16
- (this.sl = new E()),
17
- (this.il = null),
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.v(i.k.hl);
23
- this.rl = null != t ? Kt.Yn(t) : new Kt();
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
- li() {
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 = new Kt(
35
- e.time,
36
- e.events_blacklist,
37
- e.attributes_blacklist,
38
- e.purchases_blacklist,
39
- e.messaging_session_timeout,
40
- e.vapid_public_key,
41
- e.content_cards,
42
- e.feature_flags,
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 != t.al && this.En() !== t.al && (s = !0);
47
+ null != i.cl && this.In() !== i.cl && (s = !0);
46
48
  let r = !1;
47
- null != t.ml.enabled && this.oi() !== t.ml.enabled && (r = !0);
49
+ null != i.ml.enabled && this.ri() !== i.ml.enabled && (r = !0);
48
50
  let n = !1;
49
- null != t.gi.enabled && this.yi() !== t.gi.enabled && (n = !0),
50
- (this.rl = t),
51
- this.u.D(i.k.hl, t.tt()),
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.sl.Dt();
56
+ n && this.il.Dt();
55
57
  }
56
58
  }
57
59
  }
58
- Rn(t) {
60
+ Vn(t) {
59
61
  const e = this.tl.It(t);
60
- return this.il && this.tl.removeSubscription(this.il), (this.il = e), e;
62
+ return this.sl && this.tl.removeSubscription(this.sl), (this.sl = e), e;
61
63
  }
62
- Ps(t) {
64
+ qs(t) {
63
65
  return this.el.It(t);
64
66
  }
65
- Ci(t) {
66
- return this.sl.It(t);
67
+ xi(t) {
68
+ return this.il.It(t);
67
69
  }
68
- ge(t) {
69
- return -1 !== this.ll().cl.indexOf(t);
70
+ me(t) {
71
+ return -1 !== this.ll().gl.indexOf(t);
70
72
  }
71
73
  hu(t) {
72
- return -1 !== this.ll().gl.indexOf(t);
74
+ return -1 !== this.ll().fl.indexOf(t);
73
75
  }
74
76
  Dr(t) {
75
- return -1 !== this.ll().fl.indexOf(t);
77
+ return -1 !== this.ll().bl.indexOf(t);
76
78
  }
77
79
  dl() {
78
- return this.ll().bl;
80
+ return this.ll().Cl;
79
81
  }
80
- En() {
81
- return this.ll().al;
82
+ In() {
83
+ return this.ll().cl;
82
84
  }
83
- oi() {
85
+ ri() {
84
86
  return this.ll().ml.enabled || !1;
85
87
  }
86
- $s() {
88
+ Is() {
87
89
  const t = this.ll().ml.rate_limit;
88
90
  return !(!t || null == t.enabled) && t.enabled;
89
91
  }
90
- di() {
91
- if (!this.$s()) return -1;
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
- mi() {
96
- if (!this.$s()) return -1;
97
+ fi() {
98
+ if (!this.Is()) return -1;
97
99
  const t = this.ll().ml.rate_limit;
98
- return null == t.refill_rate ? Gt : t.refill_rate <= 0 ? -1 : 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().gi.enabled && null == this.Mi()
102
- ? (s.N(r.q.qs, { e: "Missing feature flag refresh_rate_limit." }), !1)
103
- : this.ll().gi.enabled || !1;
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
- Mi() {
106
- return this.ll().gi.refresh_rate_limit;
121
+ zi() {
122
+ return this.ll().mi.refresh_rate_limit;
107
123
  }
108
124
  }