@braze/web-sdk 4.7.2 → 4.8.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.
Files changed (164) hide show
  1. package/index.d.ts +32 -26
  2. package/package.json +1 -1
  3. package/shared-lib/braze-shared-lib.js +5 -5
  4. package/shared-lib/encoding-utils.js +1 -1
  5. package/shared-lib/event-types.js +25 -25
  6. package/shared-lib/guid.js +3 -3
  7. package/shared-lib/indexed-db-adapter.js +74 -74
  8. package/shared-lib/logger.js +18 -18
  9. package/shared-lib/supported-options.js +18 -18
  10. package/src/Card/card-manager-factory.js +2 -2
  11. package/src/Card/card-manager.js +48 -42
  12. package/src/Card/display/card-display.js +70 -67
  13. package/src/Card/log-card-click.js +1 -1
  14. package/src/Card/log-card-dismissal.js +1 -1
  15. package/src/Card/log-card-impressions.js +3 -3
  16. package/src/Card/models/banner.js +3 -2
  17. package/src/Card/models/captioned-image.js +6 -5
  18. package/src/Card/models/card.js +107 -87
  19. package/src/Card/models/classic-card.js +5 -5
  20. package/src/Card/models/control-card.js +5 -21
  21. package/src/Card/types.js +1 -0
  22. package/src/Card/util/card-factory.js +32 -32
  23. package/src/ContentCards/content-cards-provider-factory.js +3 -3
  24. package/src/ContentCards/content-cards-provider.js +283 -175
  25. package/src/ContentCards/content-cards.js +2 -2
  26. package/src/ContentCards/get-cached-content-cards.js +1 -1
  27. package/src/ContentCards/log-content-cards-displayed.js +2 -2
  28. package/src/ContentCards/request-content-cards-refresh.js +1 -1
  29. package/src/ContentCards/subscribe-to-content-cards-updates.js +9 -6
  30. package/src/ContentCards/types.js +1 -0
  31. package/src/ContentCards/ui/hide-content-cards.js +2 -2
  32. package/src/ContentCards/ui/show-content-cards.js +36 -34
  33. package/src/Core/add-sdk-metadata.js +17 -18
  34. package/src/Core/change-user.js +12 -14
  35. package/src/Core/destroy.js +1 -1
  36. package/src/Core/disable-sdk.js +8 -6
  37. package/src/Core/enable-sdk.js +4 -4
  38. package/src/Core/get-device-id.js +7 -6
  39. package/src/Core/get-user.js +1 -1
  40. package/src/Core/handle-braze-action.js +57 -40
  41. package/src/Core/is-disabled.js +2 -2
  42. package/src/Core/log-custom-event.js +22 -15
  43. package/src/Core/log-purchase.js +33 -33
  44. package/src/Core/open-session.js +17 -15
  45. package/src/Core/request-immediate-data-flush.js +4 -2
  46. package/src/Core/set-logger.js +1 -1
  47. package/src/Core/set-sdk-authentication-signature.js +5 -6
  48. package/src/Core/subscribe-to-sdk-authentication-failures.js +3 -1
  49. package/src/Core/toggle-logging.js +1 -1
  50. package/src/Core/types.js +1 -0
  51. package/src/Core/wipe-data.js +11 -10
  52. package/src/FeatureFlags/feature-flag-factory.js +6 -6
  53. package/src/FeatureFlags/feature-flag.js +17 -17
  54. package/src/FeatureFlags/feature-flags-provider-factory.js +2 -2
  55. package/src/FeatureFlags/feature-flags-provider.js +67 -65
  56. package/src/FeatureFlags/get-all-feature-flags.js +3 -3
  57. package/src/FeatureFlags/get-feature-flag.js +4 -4
  58. package/src/FeatureFlags/subscribe-to-feature-flags-updates.js +4 -1
  59. package/src/Feed/feed-provider-factory.js +8 -8
  60. package/src/Feed/feed-provider.js +57 -46
  61. package/src/Feed/feed.js +1 -1
  62. package/src/Feed/get-cached-feed.js +2 -2
  63. package/src/Feed/log-feed-displayed.js +3 -1
  64. package/src/Feed/request-feed-refresh.js +2 -2
  65. package/src/Feed/subscribe-to-feed-updates.js +2 -2
  66. package/src/Feed/types.js +1 -0
  67. package/src/Feed/ui/hide-feed.js +2 -2
  68. package/src/Feed/ui/show-feed.js +41 -37
  69. package/src/InAppMessage/display/html-message-to-html.js +125 -119
  70. package/src/InAppMessage/display/in-app-message-to-html.js +72 -69
  71. package/src/InAppMessage/display/modal-utils.js +18 -13
  72. package/src/InAppMessage/in-app-message-factory.js +9 -8
  73. package/src/InAppMessage/in-app-message-manager-factory.js +7 -7
  74. package/src/InAppMessage/in-app-message-manager.js +130 -110
  75. package/src/InAppMessage/log-in-app-message-button-click.js +10 -10
  76. package/src/InAppMessage/log-in-app-message-click.js +9 -9
  77. package/src/InAppMessage/log-in-app-message-html-click.js +10 -10
  78. package/src/InAppMessage/log-in-app-message-impression.js +5 -5
  79. package/src/InAppMessage/models/control-message.js +4 -1
  80. package/src/InAppMessage/models/full-screen-message.js +35 -37
  81. package/src/InAppMessage/models/html-message.js +34 -33
  82. package/src/InAppMessage/models/in-app-message-button.js +23 -16
  83. package/src/InAppMessage/models/in-app-message.js +147 -105
  84. package/src/InAppMessage/models/modal-message.js +34 -36
  85. package/src/InAppMessage/models/slide-up-message.js +25 -27
  86. package/src/InAppMessage/models/templated-in-app-message.js +12 -7
  87. package/src/InAppMessage/subscribe-to-in-app-message.js +2 -2
  88. package/src/InAppMessage/types.js +1 -0
  89. package/src/InAppMessage/ui/automatically-show-in-app-messages.js +4 -4
  90. package/src/InAppMessage/ui/show-in-app-message.js +95 -89
  91. package/src/InAppMessage/utils/in-app-message-utils.js +1 -0
  92. package/src/Push/is-push-blocked.js +2 -2
  93. package/src/Push/is-push-permission-granted.js +2 -2
  94. package/src/Push/is-push-supported.js +2 -2
  95. package/src/Push/push-manager-factory.js +20 -20
  96. package/src/Push/push-manager.js +193 -174
  97. package/src/Push/request-push-permission.js +4 -3
  98. package/src/Push/types.js +1 -0
  99. package/src/Push/unregister-push.js +2 -2
  100. package/src/Push/utils/push-utils.js +10 -10
  101. package/src/User/types.js +1 -0
  102. package/src/User/user-manager.js +24 -24
  103. package/src/User/user.js +117 -105
  104. package/src/common/base-feed.js +7 -7
  105. package/src/common/base-provider.js +2 -2
  106. package/src/common/constants.js +6 -0
  107. package/src/common/event-logger.js +6 -6
  108. package/src/common/feed-display.js +95 -85
  109. package/src/common/types.js +1 -0
  110. package/src/l10n/l10n-manager-factory.js +10 -10
  111. package/src/l10n/l10n-manager.js +1 -1
  112. package/src/managers/auth-manager.js +37 -34
  113. package/src/managers/braze-instance.js +209 -193
  114. package/src/managers/device-manager.js +43 -38
  115. package/src/managers/network-manager.js +119 -96
  116. package/src/managers/server-config-manager.js +68 -48
  117. package/src/managers/session-manager.js +52 -45
  118. package/src/managers/storage-manager-factory.js +29 -22
  119. package/src/managers/storage-manager.js +288 -273
  120. package/src/managers/subscription-manager.js +9 -6
  121. package/src/managers/types.js +1 -0
  122. package/src/models/backend-errors.js +5 -5
  123. package/src/models/braze-event.js +14 -8
  124. package/src/models/device.js +10 -18
  125. package/src/models/identifier.js +10 -11
  126. package/src/models/push-token.js +17 -12
  127. package/src/models/request-result.js +4 -4
  128. package/src/models/server-config.js +36 -20
  129. package/src/models/types.js +1 -0
  130. package/src/request-controller.js +176 -174
  131. package/src/triggers/models/custom-event-data.js +6 -6
  132. package/src/triggers/models/custom-event-property-data.js +9 -9
  133. package/src/triggers/models/filter-set.js +9 -9
  134. package/src/triggers/models/filter.js +64 -64
  135. package/src/triggers/models/in-app-message-click-data.js +12 -12
  136. package/src/triggers/models/purchase-data.js +3 -3
  137. package/src/triggers/models/purchase-property-data.js +9 -9
  138. package/src/triggers/models/push-click-data.js +7 -7
  139. package/src/triggers/models/trigger-condition.js +57 -57
  140. package/src/triggers/models/trigger-events.js +2 -2
  141. package/src/triggers/models/trigger.js +42 -42
  142. package/src/triggers/triggers-provider-factory.js +8 -8
  143. package/src/triggers/triggers-provider.js +173 -170
  144. package/src/types.js +1 -0
  145. package/src/ui/js/attach-css.js +3 -3
  146. package/src/ui/js/load-font-awesome.js +2 -2
  147. package/src/util/base-device-parser.js +2 -2
  148. package/src/util/braze-actions.js +20 -20
  149. package/src/util/browser-detector.js +22 -22
  150. package/src/util/client-hints-parser.js +7 -7
  151. package/src/util/code-utils.js +1 -1
  152. package/src/util/color-utils.js +2 -2
  153. package/src/util/component-utils.js +2 -2
  154. package/src/util/deprecation-utils.js +1 -1
  155. package/src/util/device-constants.js +3 -3
  156. package/src/util/dom-utils.js +7 -7
  157. package/src/util/error-utils.js +2 -0
  158. package/src/util/key-codes.js +1 -1
  159. package/src/util/net.js +11 -11
  160. package/src/util/request-header-utils.js +23 -0
  161. package/src/util/string-utils.js +1 -1
  162. package/src/util/user-agent-parser.js +21 -21
  163. package/src/util/validation-utils.js +44 -44
  164. package/src/util/window-utils.js +3 -3
@@ -1,59 +1,72 @@
1
1
  import qt from "../models/backend-errors.js";
2
2
  import ue from "../models/braze-event.js";
3
3
  import {
4
- convertMsToSeconds as l,
4
+ convertMsToSeconds as h,
5
5
  convertSecondsToMs as Xt
6
6
  } from "../util/date-utils.js";
7
7
  import s from "../common/event-logger.js";
8
8
  import { isArray as p, isEqual as ii } from "../util/code-utils.js";
9
9
  import r from "../../shared-lib/braze-shared-lib.js";
10
- import { STORAGE_KEYS as o } from "./storage-manager.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";
11
13
  export default class Pt {
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.Uo = a),
21
- (this.jo = u),
22
- (this.Vo = h),
23
- (this.$o = c),
24
- (this.sa = ["npm"]);
14
+ constructor(t, e, s, i, r, o, n, a, h, u, c) {
15
+ (this.Zr = t),
16
+ (this.u = e),
17
+ (this.jo = s),
18
+ (this.ft = i),
19
+ (this._e = r),
20
+ (this.wt = o),
21
+ (this.Xr = n),
22
+ (this.Do = a),
23
+ (this.Ro = h),
24
+ (this.Mo = u),
25
+ (this.appVersion = c),
26
+ (this.Zr = t),
27
+ (this.u = e),
28
+ (this.jo = s),
29
+ (this.ft = i),
30
+ (this._e = r),
31
+ (this.wt = o),
32
+ (this.Xr = n),
33
+ (this.Do = a),
34
+ (this.Ro = h),
35
+ (this.Mo = u),
36
+ (this.appVersion = c),
37
+ (this.ha = ["npm"]);
25
38
  }
26
- Ps(t, e) {
27
- const s = this.Ur.te(),
28
- i = s.Pi(),
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) || "";
39
+ Gs(t, e = !1) {
40
+ const s = this.Zr.te(),
41
+ r = s.Xi(),
42
+ o = this.u.v(i.k.la);
43
+ ii(o, r) || (t.device = r),
44
+ (t.api_key = this.Xr),
45
+ (t.time = h(new Date().valueOf(), !0));
46
+ const n = this.u.v(i.k.ua) || [],
47
+ a = this.u.v(i.k.ma) || "";
35
48
  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.jo),
40
- this.Vo && (t.sdk_flavor = this.Vo),
41
- (t.app_version = this.$o),
49
+ (this.ha.length > 0 &&
50
+ (!ii(n, this.ha) || a !== this._e.pa()) &&
51
+ (t.sdk_metadata = this.ha),
52
+ (t.sdk_version = this.Ro),
53
+ this.Mo && (t.sdk_flavor = this.Mo),
54
+ (t.app_version = this.appVersion),
42
55
  (t.device_id = s.id),
43
56
  e)
44
57
  ) {
45
- const e = this.v.getUserId();
58
+ const e = this.ft.getUserId();
46
59
  null != e && (t.user_id = e);
47
60
  }
48
61
  return t;
49
62
  }
50
- Os(t, e, i) {
63
+ ti(t, e, i) {
51
64
  const o = e.auth_error,
52
65
  n = e.error;
53
66
  if (!o && !n) return !0;
54
67
  if (o) {
55
68
  let e;
56
- this.Go.Vn();
69
+ this.jo.Ch();
57
70
  const s = { errorCode: o.error_code };
58
71
  for (const t of i)
59
72
  p(t) && "X-Braze-Auth-Signature" === t[0] && (s.signature = t[1]);
@@ -65,12 +78,12 @@ export default class Pt {
65
78
  n
66
79
  ? ((s.reason = n), (e = `due to ${n}`))
67
80
  : (e = `with error code ${o.error_code}.`),
68
- this.Go.Jn() ||
81
+ this.jo.Zn() ||
69
82
  (e +=
70
83
  ' 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.Qn(s),
84
+ r.j.error(`SDK Authentication failed ${e}`),
85
+ this.Ra(t.events || [], t.attributes || []),
86
+ this.jo.wh(s),
74
87
  !1
75
88
  );
76
89
  }
@@ -78,110 +91,119 @@ export default class Pt {
78
91
  let i,
79
92
  o = n;
80
93
  switch (o) {
81
- case qt.la:
94
+ case qt.ga:
82
95
  return (
83
96
  (i = "Received successful response with empty body."),
84
- s.G(r.A.qs, { e: i }),
85
- r.D.info(i),
97
+ s.N(r.q.Is, { e: i }),
98
+ r.j.info(i),
86
99
  !1
87
100
  );
88
- case qt.fa:
101
+ case qt.qa:
89
102
  return (
90
103
  (i = "Received successful response with invalid JSON"),
91
- s.G(r.A.qs, { e: i + ": " + e.response }),
92
- r.D.info(i),
104
+ s.N(r.q.Is, { e: i + ": " + e.response }),
105
+ r.j.info(i),
93
106
  !1
94
107
  );
95
- case qt.ma:
96
- o = `The API key "${t.api_key}" is invalid for the baseUrl ${this.Uo}`;
108
+ case qt.ba:
109
+ o = `The API key "${t.api_key}" is invalid for the baseUrl ${this.Do}`;
97
110
  break;
98
- case qt.pa:
111
+ case qt.Aa:
99
112
  o =
100
113
  "Sorry, we are not currently accepting your requests. If you think this is in error, please contact us.";
101
114
  break;
102
- case qt.Ra:
115
+ case qt.za:
103
116
  o = "No device identifier. Please contact support@braze.com";
104
117
  }
105
- r.D.error("Backend error: " + o);
118
+ r.j.error("Backend error: " + o);
106
119
  }
107
120
  return !1;
108
121
  }
109
- ba(t, e, s, i) {
122
+ Ba(t, e, s, i) {
110
123
  return !!((t && 0 !== t.length) || (e && 0 !== e.length) || s || i);
111
124
  }
112
- ga(t, e, s, i) {
125
+ Da(t, e, s, i) {
113
126
  const r = [],
114
127
  o = t => t || "",
115
- n = o(this.v.getUserId());
116
- let a,
117
- u,
118
- h,
119
- c,
120
- l = this.Oi(t, e);
128
+ n = o(this.ft.getUserId());
129
+ let a = this.Wi(t, e);
130
+ const h = [],
131
+ u = [];
132
+ let c,
133
+ l = null;
121
134
  if (s.length > 0) {
122
135
  const t = [];
123
136
  for (const e of s) {
124
- if (((a = e.Pi()), this.Go.Jn())) {
125
- if (n && !a.user_id) {
126
- c || ((c = {}), (c.events = [])), c.events.push(a);
137
+ if (((c = e.Xi()), this.jo.Zn())) {
138
+ if (n && !c.user_id) {
139
+ l || (l = {}), l.events || (l.events = []), l.events.push(c);
127
140
  continue;
128
141
  }
129
- if (o(a.user_id) !== n) {
130
- u || (u = []), u.push(a);
142
+ if (o(c.user_id) !== n) {
143
+ u.push(c);
131
144
  continue;
132
145
  }
133
146
  }
134
- t.push(a);
147
+ t.push(c);
135
148
  }
136
- t.length > 0 && (l.events = t);
149
+ t.length > 0 && (a.events = t);
137
150
  }
138
151
  if (i.length > 0) {
139
152
  const t = [];
140
153
  for (const e of i)
141
- this.Go.Jn() && o(e.user_id) !== n
142
- ? (h || (h = []), h.push(e))
143
- : t.push(e);
144
- t.length > 0 && (l.attributes = t);
154
+ this.jo.Zn() && o(e.user_id) !== n ? h.push(e) : t.push(e);
155
+ t.length > 0 && (a.attributes = t);
145
156
  }
146
- if ((this.ca(u, h), (l = this.Ps(l, !0)), c)) {
147
- c = this.Ps(c, !1);
148
- const t = { requestData: c, headers: this.Bs(c) };
157
+ if ((this.Ra(u, h), (a = this.Gs(a, !0)), l)) {
158
+ l = this.Gs(l, !1);
159
+ const t = { requestData: l, headers: this.Ks(l, T.Qs.Sa) };
149
160
  r.push(t);
150
161
  }
151
- if (l && !this.ba(l.events, l.attributes, t, e)) return c ? r : null;
152
- const f = { requestData: l, headers: this.Bs(l) };
162
+ if (a && !this.Ba(a.events, a.attributes, t, e)) return l ? r : null;
163
+ const f = { requestData: a, headers: this.Ks(a, T.Qs.Sa) };
153
164
  return r.push(f), r;
154
165
  }
155
- ca(t, e) {
166
+ Ra(t, e) {
156
167
  if (t) {
157
168
  const e = [];
158
169
  for (const s of t) {
159
170
  const t = ue.fromJson(s);
160
171
  (t.time = Xt(t.time)), e.push(t);
161
172
  }
162
- this.h.bo(e);
173
+ this.u.co(e);
163
174
  }
164
- if (e) for (const t of e) this.h.qa(t);
175
+ if (e) for (const t of e) this.u.va(t);
165
176
  }
166
- Vs(t, e) {
177
+ ii(t, e) {
167
178
  let s = "HTTP error ";
168
- null != t && (s += t + " "), (s += e), r.D.error(s);
179
+ null != t && (s += t + " "), (s += e), r.j.error(s);
169
180
  }
170
- Fr(t) {
171
- return s.G(r.A.Aa, { n: t });
181
+ qr(t) {
182
+ return s.N(r.q.ka, { n: t });
172
183
  }
173
- Oi(t, e, s) {
184
+ Wi(t, e, s) {
174
185
  const i = {};
175
186
  t && (i.feed = !0), e && (i.triggers = !0);
176
- const r = null != s ? s : this.v.getUserId();
187
+ const r = null != s ? s : this.ft.getUserId();
177
188
  return (
178
189
  r && (i.user_id = r),
179
- (i.config = { config_time: this.gt.Zs() }),
190
+ (i.config = { config_time: this.wt.oi() }),
180
191
  { respond_with: i }
181
192
  );
182
193
  }
183
- Bs(t, e, s, i) {
184
- const r = [["X-Braze-Api-Key", this._r]];
194
+ Ta(t) {
195
+ const e = new Date().valueOf();
196
+ let s = Ht.toString();
197
+ const i = T.Xa(this.u, t);
198
+ if (-1 !== i) {
199
+ s = (e - i).toString();
200
+ }
201
+ return s;
202
+ }
203
+ Ks(t, e, s = !1) {
204
+ const r = [["X-Braze-Api-Key", this.Xr]],
205
+ o = this.Ta(e);
206
+ r.push(["X-Braze-Last-Req-Ms-Ago", o]);
185
207
  let n = !1;
186
208
  if (
187
209
  (null != t.respond_with &&
@@ -190,25 +212,26 @@ export default class Pt {
190
212
  null != t.respond_with &&
191
213
  t.respond_with.feed &&
192
214
  (r.push(["X-Braze-FeedRequest", "true"]), (n = !0)),
193
- e)
215
+ e === T.Qs.Os)
194
216
  ) {
195
217
  r.push(["X-Braze-ContentCardsRequest", "true"]);
196
- let t = this.h.I(o.q.As);
197
- (t && i) || ((t = 0), this.h.B(o.q.As, t)),
218
+ let t = this.u.v(i.k.Fs);
219
+ (t && s) || ((t = 0), this.u.D(i.k.Fs, t)),
198
220
  r.push(["BRAZE-SYNC-RETRY-COUNT", t.toString()]),
199
221
  (n = !0);
200
222
  }
201
223
  if (
202
- (s && (r.push(["X-Braze-FeatureFlagsRequest", "true"]), (n = !0)),
224
+ (e === T.Qs.xi &&
225
+ (r.push(["X-Braze-FeatureFlagsRequest", "true"]), (n = !0)),
203
226
  n && r.push(["X-Braze-DataRequest", "true"]),
204
- this.Go.Jn())
227
+ this.jo.Zn())
205
228
  ) {
206
- const t = this.Go.Kn();
229
+ const t = this.jo.gh();
207
230
  null != t && r.push(["X-Braze-Auth-Signature", t]);
208
231
  }
209
232
  return r;
210
233
  }
211
- Gs(t, e) {
234
+ Vs(t, e) {
212
235
  const s = t.device;
213
236
  s && s.os_version instanceof Promise
214
237
  ? s.os_version.then(s => {
@@ -216,13 +239,13 @@ export default class Pt {
216
239
  })
217
240
  : e();
218
241
  }
219
- Qs() {
220
- this.Go.Qs();
242
+ si() {
243
+ this.jo.si();
221
244
  }
222
- Ks() {
223
- return this.Uo;
245
+ Zs() {
246
+ return this.Do;
224
247
  }
225
248
  addSdkMetadata(t) {
226
- for (const e of t) -1 === this.sa.indexOf(e) && this.sa.push(e);
249
+ for (const e of t) -1 === this.ha.indexOf(e) && this.ha.push(e);
227
250
  }
228
251
  }
@@ -1,30 +1,36 @@
1
- import { STORAGE_KEYS as o } from "./storage-manager.js";
2
- import u from "./subscription-manager.js";
1
+ import { STORAGE_KEYS as i } from "./storage-manager.js";
2
+ import E from "./subscription-manager.js";
3
3
  import Kt from "../models/server-config.js";
4
4
  import s from "../common/event-logger.js";
5
5
  import r from "../../shared-lib/braze-shared-lib.js";
6
+ import {
7
+ CONTENT_CARDS_RATE_LIMIT_CAPACITY_DEFAULT as Vt,
8
+ CONTENT_CARDS_RATE_LIMIT_REFILL_RATE_DEFAULT as Gt
9
+ } from "../common/constants.js";
6
10
  export default class Mt {
7
11
  constructor(t) {
8
- (this.h = t),
9
- (this.tl = new u()),
10
- (this.el = new u()),
11
- (this.sl = new u()),
12
- (this.il = null);
13
- }
14
- rl() {
15
- if (null == this.il) {
16
- const t = this.h.I(o.q.hl);
17
- this.il = null != t ? Kt.Pn(t) : new Kt();
12
+ (this.u = t),
13
+ (this.u = t),
14
+ (this.tl = new E()),
15
+ (this.el = new E()),
16
+ (this.sl = new E()),
17
+ (this.il = null),
18
+ (this.rl = null);
19
+ }
20
+ ll() {
21
+ if (null == this.rl) {
22
+ const t = this.u.v(i.k.hl);
23
+ this.rl = null != t ? Kt.zn(t) : new Kt();
18
24
  }
19
- return this.il;
25
+ return this.rl;
20
26
  }
21
- Zs() {
22
- return this.rl().ol;
27
+ oi() {
28
+ return this.ll().ol;
23
29
  }
24
- al(t) {
30
+ ul(t) {
25
31
  if (null != t && null != t.config) {
26
32
  const e = t.config;
27
- if (e.time > this.rl().ol) {
33
+ if (e.time > this.ll().ol) {
28
34
  const t = new Kt(
29
35
  e.time,
30
36
  e.events_blacklist,
@@ -36,53 +42,67 @@ export default class Mt {
36
42
  e.feature_flags
37
43
  );
38
44
  let s = !1;
39
- null != t.gl && this.mn() !== t.gl && (s = !0);
40
- let i = !1;
41
- null != t.ml.enabled && this.Ys() !== t.ml.enabled && (i = !0);
45
+ null != t.al && this.Un() !== t.al && (s = !0);
42
46
  let r = !1;
43
- null != t.hi.enabled && this.ci() !== t.hi.enabled && (r = !0),
44
- (this.il = t),
45
- this.h.B(o.q.hl, t.ss()),
46
- s && this.tl.St(),
47
- i && this.el.St(),
48
- r && this.sl.St();
47
+ null != t.ml.enabled && this.ni() !== t.ml.enabled && (r = !0);
48
+ let n = !1;
49
+ null != t.mi.enabled && this.bi() !== t.mi.enabled && (n = !0),
50
+ (this.rl = t),
51
+ this.u.D(i.k.hl, t.ss()),
52
+ s && this.tl.Et(),
53
+ r && this.el.Et(),
54
+ n && this.sl.Et();
49
55
  }
50
56
  }
51
57
  }
52
- gn(t) {
53
- let e = this.tl.ut(t);
54
- return this.cl && this.tl.removeSubscription(this.cl), (this.cl = e), e;
58
+ Wn(t) {
59
+ const e = this.tl.lt(t);
60
+ return this.il && this.tl.removeSubscription(this.il), (this.il = e), e;
55
61
  }
56
- Ms(t) {
57
- return this.el.ut(t);
62
+ $s(t) {
63
+ return this.el.lt(t);
58
64
  }
59
- Fi(t) {
60
- return this.sl.ut(t);
65
+ Ni(t) {
66
+ return this.sl.lt(t);
61
67
  }
62
68
  ge(t) {
63
- return -1 !== this.rl().fl.indexOf(t);
69
+ return -1 !== this.ll().cl.indexOf(t);
64
70
  }
65
71
  hu(t) {
66
- return -1 !== this.rl().bl.indexOf(t);
72
+ return -1 !== this.ll().gl.indexOf(t);
67
73
  }
68
74
  Dr(t) {
69
- return -1 !== this.rl().dl.indexOf(t);
75
+ return -1 !== this.ll().fl.indexOf(t);
76
+ }
77
+ dl() {
78
+ return this.ll().bl;
79
+ }
80
+ Un() {
81
+ return this.ll().al;
82
+ }
83
+ ni() {
84
+ return this.ll().ml.enabled || !1;
70
85
  }
71
- vl() {
72
- return this.rl().wl;
86
+ _s() {
87
+ const t = this.ll().ml.rate_limit;
88
+ return !(!t || null == t.enabled) && t.enabled;
73
89
  }
74
- mn() {
75
- return this.rl().gl;
90
+ fi() {
91
+ if (!this._s()) return -1;
92
+ const t = this.ll().ml.rate_limit;
93
+ return null == t.capacity ? Vt : t.capacity <= 0 ? -1 : t.capacity;
76
94
  }
77
- Ys() {
78
- return this.rl().ml.enabled || !1;
95
+ di() {
96
+ if (!this._s()) return -1;
97
+ const t = this.ll().ml.rate_limit;
98
+ return null == t.refill_rate ? Gt : t.refill_rate <= 0 ? -1 : t.refill_rate;
79
99
  }
80
- ci() {
81
- return this.rl().hi.enabled && null == this.ji()
82
- ? (s.G(r.A.qs, { e: "Missing feature flag refresh_rate_limit." }), !1)
83
- : this.rl().hi.enabled || !1;
100
+ bi() {
101
+ return this.ll().mi.enabled && null == this.Si()
102
+ ? (s.N(r.q.Is, { e: "Missing feature flag refresh_rate_limit." }), !1)
103
+ : this.ll().mi.enabled || !1;
84
104
  }
85
- ji() {
86
- return this.rl().hi.refresh_rate_limit;
105
+ Si() {
106
+ return this.ll().mi.refresh_rate_limit;
87
107
  }
88
108
  }
@@ -1,68 +1,75 @@
1
- import { STORAGE_KEYS as o } from "../managers/storage-manager.js";
1
+ import { STORAGE_KEYS as i } from "../managers/storage-manager.js";
2
2
  import ue from "../models/braze-event.js";
3
3
  import _t from "../models/identifier.js";
4
- import { convertMsToSeconds as l } from "../util/date-utils.js";
4
+ import { convertMsToSeconds as h } from "../util/date-utils.js";
5
5
  import r from "../../shared-lib/braze-shared-lib.js";
6
- export default class jt {
7
- constructor(s, t, e, i) {
8
- (this.h = s),
9
- (this.v = t),
10
- (this.gt = e),
11
- (this.fh = 1e3),
12
- (i = parseFloat(i)),
13
- isNaN(i) && (i = 1800),
14
- i < this.fh / 1e3 &&
15
- (r.D.info(
6
+ export default class Dt {
7
+ constructor(s, t, i, e) {
8
+ (this.u = s),
9
+ (this.ft = t),
10
+ (this.wt = i),
11
+ (this.wl = e),
12
+ (this.u = s),
13
+ (this.ft = t),
14
+ (this.wt = i),
15
+ (this.Sl = 1e3),
16
+ (null == e || isNaN(e)) && (e = 1800),
17
+ e < this.Sl / 1e3 &&
18
+ (r.j.info(
16
19
  "Specified session timeout of " +
17
- i +
20
+ e +
18
21
  "s is too small, using the minimum session timeout of " +
19
- this.fh / 1e3 +
22
+ this.Sl / 1e3 +
20
23
  "s instead."
21
24
  ),
22
- (i = this.fh / 1e3)),
23
- (this.ph = i);
25
+ (e = this.Sl / 1e3)),
26
+ (this.wl = e);
24
27
  }
25
- gh(s, t) {
26
- return new ue(this.v.getUserId(), r.A.wh, s, t.iu, { d: l(s - t.jh) });
28
+ jl(s, t) {
29
+ return new ue(this.ft.getUserId(), r.q.xl, s, t.iu, { d: h(s - t.vl) });
27
30
  }
28
- ha() {
29
- const s = this.h.tu(o.eu.xh);
31
+ pa() {
32
+ const s = this.u.tu(i.eu.Dl);
30
33
  return null == s ? null : s.iu;
31
34
  }
32
- Ch() {
35
+ El() {
33
36
  const s = new Date().valueOf(),
34
- t = this.gt.vl(),
35
- e = this.h.I(o.q.Gh);
37
+ t = this.wt.dl(),
38
+ e = this.u.v(i.k.zl);
36
39
  if (null != e && null == t) return !1;
37
- const i = null == e || s - e > 1e3 * t;
38
- return i && this.h.B(o.q.Gh, s), i;
40
+ let n = !1;
41
+ return (
42
+ null == e ? (n = !0) : null != t && (n = s - e > 1e3 * t),
43
+ n && this.u.D(i.k.zl, s),
44
+ n
45
+ );
39
46
  }
40
- Fh(s, t) {
41
- return null == t || (!(s - t.jh < this.fh) && t.Hh < s);
47
+ Cl(s, t) {
48
+ return null == t || null == t.Gl || (!(s - t.vl < this.Sl) && t.Gl < s);
42
49
  }
43
- mo() {
50
+ bo() {
44
51
  const s = new Date().valueOf(),
45
- t = s + 1e3 * this.ph,
46
- e = this.h.tu(o.eu.xh);
47
- if (this.Fh(s, e)) {
48
- let i = "Generating session start event with time " + s;
52
+ t = s + 1e3 * this.wl,
53
+ e = this.u.tu(i.eu.Dl);
54
+ if (this.Cl(s, e)) {
55
+ let n = "Generating session start event with time " + s;
49
56
  if (null != e) {
50
- let s = e.Wh;
51
- s - e.jh < this.fh && (s = e.jh + this.kh),
52
- this.h.qh(this.gh(s, e)),
53
- (i += " (old session ended " + s + ")");
57
+ let s = e.Nl;
58
+ s - e.vl < this.Sl && (s = e.vl + this.Sl),
59
+ this.u.Hl(this.jl(s, e)),
60
+ (n += " (old session ended " + s + ")");
54
61
  }
55
- (i += ". Will expire " + t.valueOf()), r.D.info(i);
56
- const n = new _t(r.it.nt(), t);
57
- this.h.qh(new ue(this.v.getUserId(), r.A.yh, s, n.iu)),
58
- this.h.uu(o.eu.xh, n);
59
- return null == this.h.I(o.q.Gh) && this.h.B(o.q.Gh, s), n.iu;
62
+ (n += ". Will expire " + t.valueOf()), r.j.info(n);
63
+ const l = new _t(r.Z.Y(), t);
64
+ this.u.Hl(new ue(this.ft.getUserId(), r.q.Wl, s, l.iu)),
65
+ this.u.uu(i.eu.Dl, l);
66
+ return null == this.u.v(i.k.zl) && this.u.D(i.k.zl, s), l.iu;
60
67
  }
61
- return (e.Wh = s), (e.Hh = t), this.h.uu(o.eu.xh, e), e.iu;
68
+ if (null != e) return (e.Nl = s), (e.Gl = t), this.u.uu(i.eu.Dl, e), e.iu;
62
69
  }
63
- Bh() {
64
- const s = this.h.tu(o.eu.xh);
70
+ kl() {
71
+ const s = this.u.tu(i.eu.Dl);
65
72
  null != s &&
66
- (this.h.Jh(o.eu.xh), this.h.qh(this.gh(new Date().valueOf(), s)));
73
+ (this.u.ql(i.eu.Dl), this.u.Hl(this.jl(new Date().valueOf(), s)));
67
74
  }
68
75
  }