@braze/web-sdk 6.7.1 → 6.9.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 (138) hide show
  1. package/index.d.ts +165 -38
  2. package/package.json +1 -1
  3. package/shared-lib/encoding-utils.js +2 -2
  4. package/shared-lib/event-types.js +16 -16
  5. package/shared-lib/indexed-db-adapter.js +65 -65
  6. package/shared-lib/logger.js +18 -18
  7. package/shared-lib/supported-options.js +1 -1
  8. package/src/Banner/banner-provider.js +67 -59
  9. package/src/Banner/banner.js +40 -19
  10. package/src/Banner/dismiss-banner.js +4 -0
  11. package/src/Banner/display/banner-to-html.js +10 -10
  12. package/src/Banner/display/destroy-banner-html.js +2 -2
  13. package/src/Banner/get-all-banners.js +6 -6
  14. package/src/Banner/get-banner.js +6 -6
  15. package/src/Banner/index.js +1 -0
  16. package/src/Banner/log-banner-click.js +7 -7
  17. package/src/Banner/log-banner-dismissal.js +7 -7
  18. package/src/Banner/log-banner-impressions.js +27 -18
  19. package/src/Banner/request-banners-refresh.js +8 -8
  20. package/src/Banner/subscribe-to-banners-updates.js +5 -5
  21. package/src/Banner/ui/insert-banner.js +8 -8
  22. package/src/Card/card-manager.js +31 -31
  23. package/src/Card/log-card-dismissal.js +2 -2
  24. package/src/Card/log-content-card-click.js +2 -2
  25. package/src/Card/log-content-card-impressions.js +4 -4
  26. package/src/Card/models/captioned-image.js +15 -15
  27. package/src/Card/models/card.js +89 -89
  28. package/src/Card/models/classic-card.js +16 -16
  29. package/src/Card/models/control-card.js +7 -7
  30. package/src/Card/models/image-only.js +13 -13
  31. package/src/Card/util/card-factory.js +32 -32
  32. package/src/ContentCards/content-cards-provider-factory.js +13 -11
  33. package/src/ContentCards/content-cards-provider.js +105 -105
  34. package/src/ContentCards/get-cached-content-cards.js +2 -2
  35. package/src/ContentCards/request-content-cards-refresh.js +2 -2
  36. package/src/ContentCards/subscribe-to-content-cards-updates.js +10 -10
  37. package/src/ContentCards/ui/show-content-cards.js +7 -7
  38. package/src/Core/add-sdk-metadata.js +2 -2
  39. package/src/Core/change-user.js +5 -5
  40. package/src/Core/destroy.js +2 -2
  41. package/src/Core/disable-sdk.js +4 -4
  42. package/src/Core/enable-sdk.js +4 -4
  43. package/src/Core/get-device-id.js +2 -2
  44. package/src/Core/handle-braze-action.js +5 -5
  45. package/src/Core/index.js +1 -0
  46. package/src/Core/log-custom-event.js +5 -5
  47. package/src/Core/log-ecommerce-event.js +29 -0
  48. package/src/Core/log-purchase.js +23 -198
  49. package/src/Core/open-session.js +10 -10
  50. package/src/Core/set-logger.js +2 -2
  51. package/src/Core/set-sdk-authentication-signature.js +1 -1
  52. package/src/Core/subscribe-to-sdk-authentication-failures.js +1 -1
  53. package/src/Core/toggle-logging.js +2 -2
  54. package/src/Core/wipe-data.js +6 -6
  55. package/src/DUST/dust-connection-core.js +1 -0
  56. package/src/DUST/dust-provider-factory.js +10 -10
  57. package/src/DUST/dust-provider.js +258 -226
  58. package/src/DUST/dust-shared-worker-code.js +1 -1
  59. package/src/DUST/dust-shared-worker-impl.js +97 -103
  60. package/src/DUST/dust-worker-bridge.js +55 -40
  61. package/src/DUST/subscribe-to-dust.js +7 -7
  62. package/src/FeatureFlags/feature-flag-factory.js +8 -8
  63. package/src/FeatureFlags/feature-flag.js +3 -3
  64. package/src/FeatureFlags/feature-flags-provider.js +21 -21
  65. package/src/FeatureFlags/log-feature-flag-impression.js +5 -5
  66. package/src/FeatureFlags/subscribe-to-feature-flags-updates.js +1 -1
  67. package/src/InAppMessage/constants.js +3 -3
  68. package/src/InAppMessage/defer-in-app-message.js +3 -3
  69. package/src/InAppMessage/display/html-message-to-html.js +4 -4
  70. package/src/InAppMessage/display/in-app-message-to-html.js +32 -32
  71. package/src/InAppMessage/display/modal-utils.js +2 -2
  72. package/src/InAppMessage/in-app-message-factory.js +36 -36
  73. package/src/InAppMessage/in-app-message-manager.js +35 -35
  74. package/src/InAppMessage/log-in-app-message-button-click.js +3 -3
  75. package/src/InAppMessage/log-in-app-message-click.js +3 -3
  76. package/src/InAppMessage/log-in-app-message-html-click.js +3 -3
  77. package/src/InAppMessage/log-in-app-message-impression.js +3 -3
  78. package/src/InAppMessage/models/control-message.js +4 -4
  79. package/src/InAppMessage/models/full-screen-message.js +9 -9
  80. package/src/InAppMessage/models/html-message.js +2 -2
  81. package/src/InAppMessage/models/in-app-message-button.js +4 -4
  82. package/src/InAppMessage/models/in-app-message.js +34 -34
  83. package/src/InAppMessage/models/modal-message.js +7 -7
  84. package/src/InAppMessage/models/slide-up-message.js +8 -8
  85. package/src/InAppMessage/ui/show-in-app-message.js +20 -20
  86. package/src/Push/push-manager.js +44 -44
  87. package/src/User/user-manager.js +19 -19
  88. package/src/User/user.js +17 -17
  89. package/src/common/base-provider.js +1 -1
  90. package/src/common/constants.js +1 -0
  91. package/src/common/content-cards-display.js +6 -6
  92. package/src/common/event-logger.js +3 -3
  93. package/src/common/properties-base.js +3 -3
  94. package/src/l10n/l10n-manager.js +2 -2
  95. package/src/managers/auth-manager.js +11 -11
  96. package/src/managers/braze-instance.js +59 -59
  97. package/src/managers/device-manager.js +9 -9
  98. package/src/managers/network-manager.js +65 -63
  99. package/src/managers/server-config-manager.js +110 -93
  100. package/src/managers/session-manager.js +20 -20
  101. package/src/managers/storage-manager-factory.js +9 -9
  102. package/src/managers/storage-manager.js +137 -137
  103. package/src/managers/subscription-manager.js +2 -2
  104. package/src/managers/utils.js +1 -1
  105. package/src/models/braze-event.js +2 -2
  106. package/src/models/identifier.js +5 -5
  107. package/src/models/push-token.js +8 -8
  108. package/src/models/request-result.js +1 -1
  109. package/src/models/server-config.js +46 -28
  110. package/src/request-controller.js +124 -124
  111. package/src/triggers/models/custom-event-data.js +4 -4
  112. package/src/triggers/models/custom-event-property-data.js +5 -5
  113. package/src/triggers/models/filter-set.js +2 -2
  114. package/src/triggers/models/filter.js +1 -1
  115. package/src/triggers/models/in-app-message-click-data.js +5 -5
  116. package/src/triggers/models/purchase-data.js +1 -1
  117. package/src/triggers/models/purchase-property-data.js +2 -2
  118. package/src/triggers/models/push-click-data.js +5 -5
  119. package/src/triggers/models/trigger-condition.js +45 -45
  120. package/src/triggers/models/trigger-events.js +3 -3
  121. package/src/triggers/models/trigger.js +30 -30
  122. package/src/triggers/triggers-provider.js +63 -63
  123. package/src/types.js +5 -1
  124. package/src/ui/js/attach-css.js +1 -1
  125. package/src/util/braze-actions.js +6 -6
  126. package/src/util/browser-detector.js +13 -13
  127. package/src/util/client-hints-parser.js +5 -5
  128. package/src/util/code-utils.js +2 -2
  129. package/src/util/deprecation-utils.js +2 -2
  130. package/src/util/dom-utils.js +8 -8
  131. package/src/util/ecommerce-event-validation.js +343 -0
  132. package/src/util/html-display-utils.js +11 -11
  133. package/src/util/iso-4217-currency-codes.js +176 -0
  134. package/src/util/net.js +4 -4
  135. package/src/util/request-header-utils.js +10 -10
  136. package/src/util/string-utils.js +2 -2
  137. package/src/util/user-agent-parser.js +15 -15
  138. package/src/util/validation-utils.js +14 -14
@@ -4,7 +4,7 @@ import { STORAGE_KEYS as s } from "../managers/storage-manager.js";
4
4
  import f from "../managers/subscription-manager.js";
5
5
  import l from "../util/net.js";
6
6
  import h from "../util/request-header-utils.js";
7
- import { logger as E } from "../../shared-lib/index.js";
7
+ import { logger as b } from "../../shared-lib/index.js";
8
8
  import {
9
9
  REQUEST_BACKOFF_MAX_SLEEP_MS_DEFAULT as c,
10
10
  REQUEST_BACKOFF_MIN_SLEEP_MS_DEFAULT as d,
@@ -12,21 +12,22 @@ import {
12
12
  } from "../common/constants.js";
13
13
  import { randomInclusive as a } from "../util/math.js";
14
14
  import {
15
- MAX_RETRIES as ii,
16
- buildSseUrl as ti,
15
+ CONNECTION_VALID_THRESHOLD_MS as ii,
16
+ MAX_RETRIES as ti,
17
+ buildSseUrl as si,
17
18
  } from "./dust-connection-core.js";
18
19
  import {
19
- DustWorkerBridge as si,
20
- isSharedWorkerSupported as ei,
20
+ DustWorkerBridge as ei,
21
+ isSharedWorkerSupported as ni,
21
22
  } from "./dust-worker-bridge.js";
22
- export default class nr extends t {
23
+ export default class sr extends t {
23
24
  constructor(i, t, s, e, n = !0) {
24
25
  super(),
25
26
  (this.B = i),
26
- (this.C = t),
27
+ (this.j = t),
27
28
  (this.h = s),
28
29
  (this.B = i),
29
- (this.C = t),
30
+ (this.j = t),
30
31
  (this.h = s),
31
32
  (this.mite = null),
32
33
  (this.Wi = null),
@@ -34,175 +35,204 @@ export default class nr extends t {
34
35
  (this.Hi = null),
35
36
  (this.Oi = e || null),
36
37
  (this.Ki = null),
37
- (this.Qi = null),
38
+ (this.Vi = null),
38
39
  (this.T = null),
39
- (this.Vi = 0),
40
- (this.Xi = ii),
40
+ (this._i = 0),
41
+ (this.Qi = ti),
41
42
  (this.Yi = null),
42
43
  (this.Zi = null),
43
- (this._i = !0),
44
- (this.we = null),
44
+ (this.we = !0),
45
45
  (this.Se = null),
46
46
  (this.ke = null),
47
47
  (this.ye = null),
48
- (this.Re = !1),
48
+ (this.Re = null),
49
+ (this.De = !1),
49
50
  (this.Me = new Map()),
50
51
  (this.xe = null),
51
- (this.De = null),
52
52
  (this.We = null),
53
- (this.Fe = this.Ue(n)),
54
- (this.Ne = !1),
53
+ (this.Fe = null),
54
+ (this.Ue = this.Ne(n)),
55
+ (this.Be = !1),
55
56
  (this.Te = 0),
56
- this.ze();
57
+ (this.ze = null),
58
+ this.Ae();
57
59
  }
58
- Ue(i) {
60
+ Ne(i) {
59
61
  return i
60
- ? ei()
62
+ ? ni()
61
63
  ? "sharedworker"
62
- : (E.info(
64
+ : (b.info(
63
65
  "SharedWorker not supported, using direct EventSource (multi-tab will gracefully degrade)",
64
66
  ),
65
67
  "direct")
66
- : (E.info("Shared connection disabled, using direct EventSource"),
68
+ : (b.info("Shared connection disabled, using direct EventSource"),
67
69
  "direct");
68
70
  }
69
- Ae() {
70
- this.We = new si({
71
- Be: (i) => {
72
- this.Ge(i);
71
+ Ge() {
72
+ this.Fe = new ei({
73
+ Pe: (i) => {
74
+ this.qe(i);
75
+ },
76
+ He: () => {
77
+ this.Je(), (this.ze = new Date().valueOf());
73
78
  },
74
- Pe: () => {
75
- this.qe();
79
+ Le: () => {
80
+ this.ze = null;
76
81
  },
77
- He: () => {},
78
- Je: (i) => {
79
- E.error(`Real-time messaging SharedWorker error: ${i}`);
82
+ Oe: (i) => {
83
+ b.error(`Real-time messaging SharedWorker error: ${i}`);
80
84
  },
81
85
  });
82
- this.We.initialize() ||
83
- (E.info(
86
+ this.Fe.initialize() ||
87
+ (b.info(
84
88
  "SharedWorker initialization failed, falling back to direct EventSource",
85
89
  ),
86
- (this.Fe = "direct"),
87
- (this.We = null));
88
- }
89
- qe() {
90
- (this.Vi = 0),
91
- (this.we = null),
92
- (this._i = !0),
93
- (this.Ne = !1),
90
+ (this.Ue = "direct"),
91
+ (this.Fe = null));
92
+ }
93
+ Je() {
94
+ (this._i = 0),
95
+ (this.Se = null),
96
+ (this.we = !0),
97
+ (this.Be = !1),
94
98
  (this.Te = 0);
95
99
  }
96
- Ge(i) {
97
- if (!i.type)
98
- return void E.warn(
100
+ Ie() {
101
+ var i;
102
+ return (
103
+ !(
104
+ !("sharedworker" === this.Ue
105
+ ? Boolean(null === (i = this.Fe) || void 0 === i ? void 0 : i.Ke())
106
+ : Boolean(this.Vi)) || null === this.ze
107
+ ) && new Date().valueOf() - this.ze >= ii
108
+ );
109
+ }
110
+ qe(i) {
111
+ const t = i.type;
112
+ if (!t)
113
+ return void b.warn(
99
114
  `Received real-time message without type: ${JSON.stringify(i)}`,
100
115
  );
101
- const t = "sharedworker" === this.Fe ? "SharedWorker" : "Direct";
102
- E.info(`Received real-time message of type '${i.type}' via ${t}`);
103
- const s = this.Me.get(i.type);
104
- if (s && s.Le() > 0)
116
+ const s = "sharedworker" === this.Ue ? "SharedWorker" : "Direct";
117
+ b.info(`Received real-time message of type '${t}' via ${s}`);
118
+ const e = this.Me.get(t);
119
+ if (e && e.Ve() > 0)
105
120
  try {
106
- s.A(i);
107
- } catch (t) {
108
- E.error(
109
- `Error invoking subscription for message type '${i.type}': ${t}`,
110
- );
121
+ e.A(i);
122
+ } catch (i) {
123
+ b.error(`Error invoking subscription for message type '${t}': ${i}`);
111
124
  }
112
- else E.info(`No subscribers for real-time message type '${i.type}'`);
125
+ else b.info(`No subscribers for real-time message type '${t}'`);
113
126
  }
114
- Oe() {
115
- return "sharedworker" === this.Fe;
127
+ _e() {
128
+ return "sharedworker" === this.Ue;
116
129
  }
117
- Ie() {
118
- return this.Fe;
119
- }
120
- ze() {
121
- if (this.C) {
122
- const i = this.C.Rt(s.Tt.Ke),
123
- t = this.C.Rt(s.Tt.Qe),
124
- e = this.C.Rt(s.Tt.Ve),
125
- n = this.C.Rt(s.Tt.Xe);
130
+ Qe() {
131
+ return this.Ue;
132
+ }
133
+ Ae() {
134
+ if (this.j) {
135
+ const i = this.j.St(s.It.Xe),
136
+ t = this.j.St(s.It.Ye),
137
+ e = this.j.St(s.It.Ze),
138
+ n = this.j.St(s.It.sn);
126
139
  i && t
127
140
  ? ((this.mite = i),
128
141
  (this.Wi = t),
129
142
  (this.Gi = e),
130
143
  (this.Hi = n),
131
- E.info("Restored real-time messaging configuration from storage"))
144
+ b.info("Restored real-time messaging configuration from storage"))
132
145
  : (i || t) &&
133
- (E.warn(
146
+ (b.warn(
134
147
  "Incomplete real-time messaging configuration in storage, clearing",
135
148
  ),
136
- this.Ye());
149
+ this.en());
137
150
  }
138
151
  }
139
152
  Hr() {
140
153
  this.xe ||
141
- this.De ||
142
- ((this.xe = this.Ze("ddr", (i) => {
143
- if (!i.body || "number" != typeof i.body._e) return;
144
- const t = Math.random() * i.body._e * 0.3,
145
- s = Math.round(i.body._e + t),
146
- e = i.body.e ? ` (${i.body.e})` : "";
147
- E.info(`Admin requested disconnect${e}, reconnecting in ${s}ms`),
148
- this.sn(),
149
- setTimeout(() => this.en(), s);
154
+ this.We ||
155
+ ((this.xe = this.on("ddr", (i) => {
156
+ var t, s, e;
157
+ const n = i.body;
158
+ if (!n) return;
159
+ const r = n.r_ms;
160
+ if ("number" != typeof r) return;
161
+ const o = n.e,
162
+ h = (null === (t = this.h) || void 0 === t ? void 0 : t.vt()) || d,
163
+ l = (null === (s = this.h) || void 0 === s ? void 0 : s.gt()) || m,
164
+ u = (null === (e = this.h) || void 0 === e ? void 0 : e.bt()) || c,
165
+ g = Math.min(u, a(h, h * l)),
166
+ f = Math.round(r + g),
167
+ p = o ? ` (${o})` : "";
168
+ b.info(
169
+ `Admin requested disconnect${p}, reconnecting in ${f}ms (r_ms=${r} + backoff=${g})`,
170
+ ),
171
+ this.hn(),
172
+ setTimeout(() => this.an(), f);
150
173
  })),
151
- (this.De = this.Ze("ttl", (i) => {
152
- if (!i.body || "number" != typeof i.body.on) return;
153
- const t = i.body.on;
154
- E.info(`Time to live set to ${t}ms, will reconnect when expired`),
155
- "sharedworker" !== this.Fe &&
156
- ("string" == typeof i.body.hn && (this.Ki = i.body.hn),
157
- null !== this.Zi && window.clearTimeout(this.Zi),
158
- (this.Zi = window.setTimeout(() => {
159
- (this.Zi = null),
160
- E.info("Time to live expired, performing gapless reconnection"),
161
- this.an();
162
- }, t)));
174
+ (this.We = this.on("ttl", (i) => {
175
+ const t = i.body;
176
+ if (!t) return;
177
+ const s = t.t_ms;
178
+ if ("number" != typeof s) return;
179
+ const e = s;
180
+ if (
181
+ (b.info(`Time to live set to ${e}ms, will reconnect when expired`),
182
+ "sharedworker" === this.Ue)
183
+ )
184
+ return;
185
+ const n = t.rcs;
186
+ "string" == typeof n && (this.Ki = n),
187
+ null !== this.Zi && window.clearTimeout(this.Zi),
188
+ (this.Zi = window.setTimeout(() => {
189
+ (this.Zi = null),
190
+ b.info("Time to live expired, performing gapless reconnection"),
191
+ this.ln();
192
+ }, e));
163
193
  })));
164
194
  }
165
- ln() {
166
- this.Se ||
167
- this.ke ||
168
- ((this.ye = () => {
169
- (this.Re = !0), (this._i = !1);
195
+ cn() {
196
+ this.ke ||
197
+ this.ye ||
198
+ ((this.Re = () => {
199
+ (this.De = !0), (this.we = !1);
170
200
  }),
171
- window.addEventListener("beforeunload", this.ye),
172
- (this.Se = () => {
201
+ window.addEventListener("beforeunload", this.Re),
202
+ (this.ke = () => {
173
203
  var i;
174
- this.Re = !0;
175
- (this.Qi ||
176
- (null === (i = this.We) || void 0 === i ? void 0 : i.cn())) &&
177
- (E.info("Page unloading, closing real-time connection gracefully"),
178
- (this._i = !1),
179
- this.sn());
204
+ this.De = !0;
205
+ (this.Vi ||
206
+ (null === (i = this.Fe) || void 0 === i ? void 0 : i.Ke())) &&
207
+ (b.info("Page unloading, closing real-time connection gracefully"),
208
+ (this.we = !1),
209
+ this.hn());
180
210
  }),
181
- window.addEventListener("pagehide", this.Se),
182
- (this.ke = (i) => {
211
+ window.addEventListener("pagehide", this.ke),
212
+ (this.ye = (i) => {
183
213
  var t;
184
214
  const s =
185
- this.Qi || (null === (t = this.We) || void 0 === t ? void 0 : t.cn());
215
+ this.Vi || (null === (t = this.Fe) || void 0 === t ? void 0 : t.Ke());
186
216
  i.persisted &&
187
217
  this.un() &&
188
218
  !s &&
189
- (E.info("Page restored from bfcache, reconnecting"),
190
- (this.Re = !1),
191
- this.qe(),
192
- this.en());
219
+ (b.info("Page restored from bfcache, reconnecting"),
220
+ (this.De = !1),
221
+ this.Je(),
222
+ this.an());
193
223
  }),
194
- window.addEventListener("pageshow", this.ke));
224
+ window.addEventListener("pageshow", this.ye));
195
225
  }
196
- Lt() {
226
+ Et() {
197
227
  return this.T;
198
228
  }
199
- $t(i) {
229
+ Lt(i) {
200
230
  this.T = i;
201
231
  }
202
- Ze(i, t) {
232
+ on(i, t) {
203
233
  if ("function" != typeof t) return null;
204
234
  let s = this.Me.get(i);
205
- return s || ((s = new f()), this.Me.set(i, s), r.S(s)), s.Kt(t);
235
+ return s || ((s = new f()), this.Me.set(i, s), r.S(s)), s.Ut(t);
206
236
  }
207
237
  dn(i, t) {
208
238
  const s = this.Me.get(i);
@@ -215,37 +245,37 @@ export default class nr extends t {
215
245
  if (!this.Hi) return !1;
216
246
  return Math.floor(new Date().valueOf() / 1e3) >= this.Hi;
217
247
  }
218
- Ye() {
248
+ en() {
219
249
  (this.mite = null),
220
250
  (this.Wi = null),
221
251
  (this.Gi = null),
222
252
  (this.Hi = null),
223
253
  (this.Ki = null),
224
- this.C &&
225
- (this.C.Qt(s.Tt.Ke),
226
- this.C.Qt(s.Tt.Qe),
227
- this.C.Qt(s.Tt.Ve),
228
- this.C.Qt(s.Tt.Xe));
254
+ this.j &&
255
+ (this.j.Vt(s.It.Xe),
256
+ this.j.Vt(s.It.Ye),
257
+ this.j.Vt(s.It.Ze),
258
+ this.j.Vt(s.It.sn));
229
259
  }
230
260
  mn(i, t) {
231
261
  const e = () => {
232
262
  "function" == typeof t && t();
233
263
  },
234
264
  n = this.B,
235
- r = this.C;
265
+ r = this.j;
236
266
  if (!n || !r)
237
267
  return (
238
- E.error("NetworkManager or StorageManager not available"), void e()
268
+ b.error("NetworkManager or StorageManager not available"), void e()
239
269
  );
240
270
  if (!this.h || !this.h.fn())
241
271
  return (
242
- E.info("Real-time messaging is not enabled, skipping refresh"), void e()
272
+ b.info("Real-time messaging is not enabled, skipping refresh"), void e()
243
273
  );
244
274
  this.un()
245
- ? E.info("Refreshing real-time messaging configuration")
246
- : E.info("Fetching initial real-time messaging configuration");
275
+ ? b.info("Refreshing real-time messaging configuration")
276
+ : b.info("Fetching initial real-time messaging configuration");
247
277
  const o = n.Z({}, !0),
248
- a = n.tt(o, h.it.pn, !1),
278
+ a = n.tt(o, h.it.pn),
249
279
  c = new Date().valueOf();
250
280
  h.nt(r, h.it.pn, c),
251
281
  l.ot({
@@ -255,7 +285,7 @@ export default class nr extends t {
255
285
  lt: (t) => {
256
286
  if (!n.ut(o, t, a))
257
287
  return (
258
- E.error(
288
+ b.error(
259
289
  "Failed to validate server response for real-time messaging configuration",
260
290
  ),
261
291
  void e()
@@ -266,19 +296,19 @@ export default class nr extends t {
266
296
  (this.Wi = t.host),
267
297
  (this.Gi = t.auth || null),
268
298
  (this.Hi = t.expiration || null),
269
- E.info(
299
+ b.info(
270
300
  "Received real-time messaging configuration from server",
271
301
  ),
272
- r.It(s.Tt.Ke, t.mite),
273
- r.It(s.Tt.Qe, t.host),
274
- t.auth ? r.It(s.Tt.Ve, t.auth) : r.Qt(s.Tt.Ve),
275
- t.expiration ? r.It(s.Tt.Xe, t.expiration) : r.Qt(s.Tt.Xe),
276
- this.en(),
302
+ r.Pt(s.It.Xe, t.mite),
303
+ r.Pt(s.It.Ye, t.host),
304
+ t.auth ? r.Pt(s.It.Ze, t.auth) : r.Vt(s.It.Ze),
305
+ t.expiration ? r.Pt(s.It.sn, t.expiration) : r.Vt(s.It.sn),
306
+ this.an(),
277
307
  "function" == typeof i && i())
278
- : (E.info(
308
+ : (b.info(
279
309
  "Real-time messaging configuration not available - this SDK version may not be supported",
280
310
  ),
281
- this.Ye(),
311
+ this.en(),
282
312
  e());
283
313
  },
284
314
  error: (i) => {
@@ -286,23 +316,23 @@ export default class nr extends t {
286
316
  },
287
317
  });
288
318
  }
289
- en() {
319
+ an() {
290
320
  if (!this.h || !this.h.fn()) return;
291
321
  if (!this.un())
292
- return void E.error(
322
+ return void b.error(
293
323
  "Cannot start real-time subscription without configuration",
294
324
  );
295
325
  if (this.gn())
296
326
  return (
297
- E.info(
327
+ b.info(
298
328
  "Real-time messaging auth token has expired, refreshing configuration",
299
329
  ),
300
330
  void this.mn(
301
331
  () => {
302
- this.en();
332
+ this.an();
303
333
  },
304
334
  () => {
305
- E.error(
335
+ b.error(
306
336
  "Failed to refresh expired real-time messaging configuration",
307
337
  );
308
338
  },
@@ -311,16 +341,16 @@ export default class nr extends t {
311
341
  const i = this.mite,
312
342
  t = this.Oi || this.Wi;
313
343
  if (i && t)
314
- switch (this.Fe) {
344
+ switch (this.Ue) {
315
345
  case "sharedworker":
316
346
  this.vn(i, t);
317
347
  break;
318
348
  case "direct":
319
- this.Qi &&
320
- (E.info(
349
+ this.Vi &&
350
+ (b.info(
321
351
  "Real-time connection already exists, closing before starting new subscription",
322
352
  ),
323
- this.sn()),
353
+ this.hn()),
324
354
  this.wn();
325
355
  }
326
356
  }
@@ -328,91 +358,92 @@ export default class nr extends t {
328
358
  const i = this.mite,
329
359
  t = this.Oi || this.Wi;
330
360
  return i && t
331
- ? ti(t, i, this.Vi, this.Gi || void 0, this.Ki || void 0)
361
+ ? si(t, i, this._i, this.Gi || void 0, this.Ki || void 0)
332
362
  : null;
333
363
  }
334
364
  vn(i, t) {
335
365
  var s, e, n;
336
- if ((this.We || this.Ae(), !this.We))
366
+ if ((this.Fe || this.Ge(), !this.Fe))
337
367
  return (
338
- E.info(
368
+ b.info(
339
369
  "SharedWorker initialization failed, falling back to direct EventSource",
340
370
  ),
341
- (this.Fe = "direct"),
371
+ (this.Ue = "direct"),
342
372
  void this.Sn()
343
373
  );
344
- this.Oi && E.info(`Using custom real-time messaging host: ${this.Oi}`),
345
- E.info("Starting real-time subscription via SharedWorker");
374
+ this.Oi && b.info(`Using custom real-time messaging host: ${this.Oi}`),
375
+ b.info("Starting real-time subscription via SharedWorker");
346
376
  const r = (null === (s = this.h) || void 0 === s ? void 0 : s.vt()) || d,
347
377
  o = (null === (e = this.h) || void 0 === e ? void 0 : e.bt()) || c,
348
378
  h = (null === (n = this.h) || void 0 === n ? void 0 : n.gt()) || m;
349
- this.We.connect({
379
+ this.Fe.connect({
350
380
  mite: i,
351
- Wi: t,
381
+ dustHost: t,
352
382
  auth: this.Gi || void 0,
353
- kn: { yn: r, $n: o, Rn: h },
383
+ backoff: { minSleepMs: r, maxSleepMs: o, scaleFactor: h },
354
384
  });
355
385
  }
356
386
  Sn() {
357
- this.Qi &&
358
- (E.info(
387
+ this.Vi &&
388
+ (b.info(
359
389
  "Real-time connection already exists, closing before starting new subscription",
360
390
  ),
361
- this.Cn()),
391
+ this.kn()),
362
392
  this.wn();
363
393
  }
364
394
  wn(i) {
365
395
  const t = this.bn();
366
396
  if (t) {
367
- this.Oi && E.info(`Using custom real-time messaging host: ${this.Oi}`);
397
+ this.Oi && b.info(`Using custom real-time messaging host: ${this.Oi}`);
368
398
  try {
369
399
  const s = new EventSource(t);
370
400
  (s.onopen = () => {
371
401
  i
372
- ? (E.info(
402
+ ? (b.info(
373
403
  "Gapless reconnection: new connection established, closing old connection",
374
404
  ),
375
405
  i.close())
376
- : E.info("Real-time messaging connection established"),
377
- (this.Qi = s),
378
- (this.Vi = 0),
379
- (this.we = null),
380
- (this._i = !0),
381
- (this.Ne = !0);
406
+ : b.info("Real-time messaging connection established"),
407
+ (this.Vi = s),
408
+ (this._i = 0),
409
+ (this.Se = null),
410
+ (this.we = !0),
411
+ (this.Be = !0),
412
+ (this.ze = new Date().valueOf());
382
413
  }),
383
414
  s.addEventListener("msg", (i) => {
384
- this.Mn(i.data);
415
+ this.yn(i.data);
385
416
  }),
386
417
  (s.onerror = () => {
387
418
  const t = s.readyState;
388
419
  return (
389
- this.Re ||
420
+ this.De ||
390
421
  (0 === t
391
- ? E.info("Real-time messaging failed to connect")
392
- : E.info("Real-time messaging connection lost")),
393
- i && this.Qi !== s
394
- ? (E.info(
422
+ ? b.info("Real-time messaging failed to connect")
423
+ : b.info("Real-time messaging connection lost")),
424
+ i && this.Vi !== s
425
+ ? (b.info(
395
426
  "Gapless reconnection failed, keeping old connection",
396
427
  ),
397
428
  s.close(),
398
- void (this._i && this.Vi < this.Xi && this.xn()))
399
- : (this.Cn(),
400
- this.Ne && (this.Te++, this.Te > 1)
401
- ? (E.info(
429
+ void (this.we && this._i < this.Qi && this.$n()))
430
+ : (this.kn(),
431
+ this.Be && (this.Te++, this.Te > 1)
432
+ ? (b.info(
402
433
  "Real-time messaging connection lost twice after successful connect (likely multi-tab conflict), yielding to other tab",
403
434
  ),
404
- void (this._i = !1))
405
- : void (this._i && this.Vi < this.Xi
406
- ? this.xn()
407
- : (this.Vi >= this.Xi &&
408
- E.error(
409
- `Max retry attempts (${this.Xi}) reached for real-time messaging, giving up for current session`,
435
+ void (this.we = !1))
436
+ : void (this.we && this._i < this.Qi
437
+ ? this.$n()
438
+ : (this._i >= this.Qi &&
439
+ b.error(
440
+ `Max retry attempts (${this.Qi}) reached for real-time messaging, giving up for current session`,
410
441
  ),
411
- (this._i = !1))))
442
+ (this.we = !1))))
412
443
  );
413
444
  });
414
445
  } catch (i) {
415
- E.error(
446
+ b.error(
416
447
  `Failed to create real-time messaging connection: ${
417
448
  i instanceof Error ? i.message : String(i)
418
449
  }`,
@@ -420,61 +451,62 @@ export default class nr extends t {
420
451
  }
421
452
  }
422
453
  }
423
- xn() {
454
+ $n() {
424
455
  var i, t, s;
425
- this.Vi++;
456
+ this._i++;
426
457
  const e = (null === (i = this.h) || void 0 === i ? void 0 : i.vt()) || d,
427
458
  n = (null === (t = this.h) || void 0 === t ? void 0 : t.gt()) || m,
428
459
  r = (null === (s = this.h) || void 0 === s ? void 0 : s.bt()) || c;
429
- let o = this.we;
460
+ let o = this.Se;
430
461
  (null == o || o < e) && (o = e);
431
462
  const h = Math.min(r, a(e, o * n));
432
- (this.we = h),
433
- E.info(
434
- `Retrying real-time messaging connection in ${h}ms (attempt ${this.Vi}/${this.Xi})`,
463
+ (this.Se = h),
464
+ b.info(
465
+ `Retrying real-time messaging connection in ${h}ms (attempt ${this._i}/${this.Qi})`,
435
466
  ),
436
467
  (this.Yi = window.setTimeout(() => {
437
- (this.Yi = null), this.en();
468
+ (this.Yi = null), this.an();
438
469
  }, h));
439
470
  }
440
- an() {
471
+ ln() {
441
472
  if (this.un()) {
442
473
  if (this.gn())
443
474
  return (
444
- E.info(
475
+ b.info(
445
476
  "Auth token expired during gapless reconnection, falling back to regular reconnection",
446
477
  ),
447
- this.sn(),
448
- void this.en()
478
+ this.hn(),
479
+ void this.an()
449
480
  );
450
481
  null !== this.Zi && (window.clearTimeout(this.Zi), (this.Zi = null)),
451
- this.wn(this.Qi || void 0);
452
- } else E.error("Cannot perform gapless reconnection without configuration");
482
+ this.wn(this.Vi || void 0);
483
+ } else b.error("Cannot perform gapless reconnection without configuration");
453
484
  }
454
- sn() {
485
+ hn() {
455
486
  var i;
456
- switch (this.Fe) {
487
+ switch (((this.ze = null), this.Ue)) {
457
488
  case "sharedworker":
458
- null === (i = this.We) || void 0 === i || i.disconnect();
489
+ null === (i = this.Fe) || void 0 === i || i.disconnect();
459
490
  break;
460
491
  case "direct":
461
- this.Cn();
492
+ this.kn();
462
493
  }
463
494
  }
464
- Cn() {
495
+ kn() {
465
496
  null !== this.Yi && (window.clearTimeout(this.Yi), (this.Yi = null)),
466
497
  null !== this.Zi && (window.clearTimeout(this.Zi), (this.Zi = null)),
467
- this.Qi &&
468
- (this.Qi.close(),
469
- (this.Qi = null),
470
- E.info("Real-time messaging connection closed"));
498
+ (this.ze = null),
499
+ this.Vi &&
500
+ (this.Vi.close(),
501
+ (this.Vi = null),
502
+ b.info("Real-time messaging connection closed"));
471
503
  }
472
- Mn(i) {
504
+ yn(i) {
473
505
  try {
474
506
  const t = JSON.parse(i);
475
- this.Ge(t);
507
+ this.qe(t);
476
508
  } catch (i) {
477
- E.warn(
509
+ b.warn(
478
510
  `Failed to parse real-time message: ${
479
511
  i instanceof Error ? i.message : String(i)
480
512
  }`,
@@ -482,39 +514,39 @@ export default class nr extends t {
482
514
  }
483
515
  }
484
516
  changeUser(i = !1) {
485
- this.sn(),
517
+ this.hn(),
486
518
  i ||
487
519
  (this.un() &&
488
- E.info(
520
+ b.info(
489
521
  "Clearing cached real-time messaging configuration for user change",
490
522
  ),
491
- this.Ye()),
492
- this.qe();
523
+ this.en()),
524
+ this.Je();
493
525
  }
494
526
  clearData(i = !1) {
495
- (this._i = !1),
496
- this.sn(),
527
+ (this.we = !1),
528
+ this.hn(),
497
529
  i &&
498
530
  (this.un() &&
499
- E.info(
531
+ b.info(
500
532
  "Clearing cached real-time messaging configuration (wipeData)",
501
533
  ),
502
- this.Ye()),
503
- this.qe();
534
+ this.en()),
535
+ this.Je();
504
536
  }
505
537
  destroy() {
506
- (this._i = !1),
507
- this.sn(),
508
- this.Ye(),
509
- this.We && (this.We.destroy(), (this.We = null)),
538
+ (this.we = !1),
539
+ this.hn(),
540
+ this.en(),
541
+ this.Fe && (this.Fe.destroy(), (this.Fe = null)),
510
542
  this.xe && (this.dn("ddr", this.xe), (this.xe = null)),
511
- this.De && (this.dn("ttl", this.De), (this.De = null)),
512
- this.ye &&
513
- (window.removeEventListener("beforeunload", this.ye), (this.ye = null)),
514
- this.Se &&
515
- (window.removeEventListener("pagehide", this.Se), (this.Se = null)),
543
+ this.We && (this.dn("ttl", this.We), (this.We = null)),
544
+ this.Re &&
545
+ (window.removeEventListener("beforeunload", this.Re), (this.Re = null)),
516
546
  this.ke &&
517
- (window.removeEventListener("pageshow", this.ke), (this.ke = null)),
547
+ (window.removeEventListener("pagehide", this.ke), (this.ke = null)),
548
+ this.ye &&
549
+ (window.removeEventListener("pageshow", this.ye), (this.ye = null)),
518
550
  this.T && (r.removeSubscription(this.T), (this.T = null));
519
551
  }
520
552
  }