@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.
- package/index.d.ts +165 -38
- package/package.json +1 -1
- package/shared-lib/encoding-utils.js +2 -2
- package/shared-lib/event-types.js +16 -16
- package/shared-lib/indexed-db-adapter.js +65 -65
- package/shared-lib/logger.js +18 -18
- package/shared-lib/supported-options.js +1 -1
- package/src/Banner/banner-provider.js +67 -59
- package/src/Banner/banner.js +40 -19
- package/src/Banner/dismiss-banner.js +4 -0
- package/src/Banner/display/banner-to-html.js +10 -10
- package/src/Banner/display/destroy-banner-html.js +2 -2
- package/src/Banner/get-all-banners.js +6 -6
- package/src/Banner/get-banner.js +6 -6
- package/src/Banner/index.js +1 -0
- package/src/Banner/log-banner-click.js +7 -7
- package/src/Banner/log-banner-dismissal.js +7 -7
- package/src/Banner/log-banner-impressions.js +27 -18
- package/src/Banner/request-banners-refresh.js +8 -8
- package/src/Banner/subscribe-to-banners-updates.js +5 -5
- package/src/Banner/ui/insert-banner.js +8 -8
- package/src/Card/card-manager.js +31 -31
- package/src/Card/log-card-dismissal.js +2 -2
- package/src/Card/log-content-card-click.js +2 -2
- package/src/Card/log-content-card-impressions.js +4 -4
- package/src/Card/models/captioned-image.js +15 -15
- package/src/Card/models/card.js +89 -89
- package/src/Card/models/classic-card.js +16 -16
- package/src/Card/models/control-card.js +7 -7
- package/src/Card/models/image-only.js +13 -13
- package/src/Card/util/card-factory.js +32 -32
- package/src/ContentCards/content-cards-provider-factory.js +13 -11
- package/src/ContentCards/content-cards-provider.js +105 -105
- package/src/ContentCards/get-cached-content-cards.js +2 -2
- package/src/ContentCards/request-content-cards-refresh.js +2 -2
- package/src/ContentCards/subscribe-to-content-cards-updates.js +10 -10
- package/src/ContentCards/ui/show-content-cards.js +7 -7
- package/src/Core/add-sdk-metadata.js +2 -2
- package/src/Core/change-user.js +5 -5
- package/src/Core/destroy.js +2 -2
- package/src/Core/disable-sdk.js +4 -4
- package/src/Core/enable-sdk.js +4 -4
- package/src/Core/get-device-id.js +2 -2
- package/src/Core/handle-braze-action.js +5 -5
- package/src/Core/index.js +1 -0
- package/src/Core/log-custom-event.js +5 -5
- package/src/Core/log-ecommerce-event.js +29 -0
- package/src/Core/log-purchase.js +23 -198
- package/src/Core/open-session.js +10 -10
- package/src/Core/set-logger.js +2 -2
- package/src/Core/set-sdk-authentication-signature.js +1 -1
- package/src/Core/subscribe-to-sdk-authentication-failures.js +1 -1
- package/src/Core/toggle-logging.js +2 -2
- package/src/Core/wipe-data.js +6 -6
- package/src/DUST/dust-connection-core.js +1 -0
- package/src/DUST/dust-provider-factory.js +10 -10
- package/src/DUST/dust-provider.js +258 -226
- package/src/DUST/dust-shared-worker-code.js +1 -1
- package/src/DUST/dust-shared-worker-impl.js +97 -103
- package/src/DUST/dust-worker-bridge.js +55 -40
- package/src/DUST/subscribe-to-dust.js +7 -7
- package/src/FeatureFlags/feature-flag-factory.js +8 -8
- package/src/FeatureFlags/feature-flag.js +3 -3
- package/src/FeatureFlags/feature-flags-provider.js +21 -21
- package/src/FeatureFlags/log-feature-flag-impression.js +5 -5
- package/src/FeatureFlags/subscribe-to-feature-flags-updates.js +1 -1
- package/src/InAppMessage/constants.js +3 -3
- package/src/InAppMessage/defer-in-app-message.js +3 -3
- package/src/InAppMessage/display/html-message-to-html.js +4 -4
- package/src/InAppMessage/display/in-app-message-to-html.js +32 -32
- package/src/InAppMessage/display/modal-utils.js +2 -2
- package/src/InAppMessage/in-app-message-factory.js +36 -36
- package/src/InAppMessage/in-app-message-manager.js +35 -35
- package/src/InAppMessage/log-in-app-message-button-click.js +3 -3
- package/src/InAppMessage/log-in-app-message-click.js +3 -3
- package/src/InAppMessage/log-in-app-message-html-click.js +3 -3
- package/src/InAppMessage/log-in-app-message-impression.js +3 -3
- package/src/InAppMessage/models/control-message.js +4 -4
- package/src/InAppMessage/models/full-screen-message.js +9 -9
- package/src/InAppMessage/models/html-message.js +2 -2
- package/src/InAppMessage/models/in-app-message-button.js +4 -4
- package/src/InAppMessage/models/in-app-message.js +34 -34
- package/src/InAppMessage/models/modal-message.js +7 -7
- package/src/InAppMessage/models/slide-up-message.js +8 -8
- package/src/InAppMessage/ui/show-in-app-message.js +20 -20
- package/src/Push/push-manager.js +44 -44
- package/src/User/user-manager.js +19 -19
- package/src/User/user.js +17 -17
- package/src/common/base-provider.js +1 -1
- package/src/common/constants.js +1 -0
- package/src/common/content-cards-display.js +6 -6
- package/src/common/event-logger.js +3 -3
- package/src/common/properties-base.js +3 -3
- package/src/l10n/l10n-manager.js +2 -2
- package/src/managers/auth-manager.js +11 -11
- package/src/managers/braze-instance.js +59 -59
- package/src/managers/device-manager.js +9 -9
- package/src/managers/network-manager.js +65 -63
- package/src/managers/server-config-manager.js +110 -93
- package/src/managers/session-manager.js +20 -20
- package/src/managers/storage-manager-factory.js +9 -9
- package/src/managers/storage-manager.js +137 -137
- package/src/managers/subscription-manager.js +2 -2
- package/src/managers/utils.js +1 -1
- package/src/models/braze-event.js +2 -2
- package/src/models/identifier.js +5 -5
- package/src/models/push-token.js +8 -8
- package/src/models/request-result.js +1 -1
- package/src/models/server-config.js +46 -28
- package/src/request-controller.js +124 -124
- package/src/triggers/models/custom-event-data.js +4 -4
- package/src/triggers/models/custom-event-property-data.js +5 -5
- package/src/triggers/models/filter-set.js +2 -2
- package/src/triggers/models/filter.js +1 -1
- package/src/triggers/models/in-app-message-click-data.js +5 -5
- package/src/triggers/models/purchase-data.js +1 -1
- package/src/triggers/models/purchase-property-data.js +2 -2
- package/src/triggers/models/push-click-data.js +5 -5
- package/src/triggers/models/trigger-condition.js +45 -45
- package/src/triggers/models/trigger-events.js +3 -3
- package/src/triggers/models/trigger.js +30 -30
- package/src/triggers/triggers-provider.js +63 -63
- package/src/types.js +5 -1
- package/src/ui/js/attach-css.js +1 -1
- package/src/util/braze-actions.js +6 -6
- package/src/util/browser-detector.js +13 -13
- package/src/util/client-hints-parser.js +5 -5
- package/src/util/code-utils.js +2 -2
- package/src/util/deprecation-utils.js +2 -2
- package/src/util/dom-utils.js +8 -8
- package/src/util/ecommerce-event-validation.js +343 -0
- package/src/util/html-display-utils.js +11 -11
- package/src/util/iso-4217-currency-codes.js +176 -0
- package/src/util/net.js +4 -4
- package/src/util/request-header-utils.js +10 -10
- package/src/util/string-utils.js +2 -2
- package/src/util/user-agent-parser.js +15 -15
- 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
|
|
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
|
-
|
|
16
|
-
|
|
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
|
|
20
|
-
isSharedWorkerSupported as
|
|
20
|
+
DustWorkerBridge as ei,
|
|
21
|
+
isSharedWorkerSupported as ni,
|
|
21
22
|
} from "./dust-worker-bridge.js";
|
|
22
|
-
export default class
|
|
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.
|
|
27
|
+
(this.j = t),
|
|
27
28
|
(this.h = s),
|
|
28
29
|
(this.B = i),
|
|
29
|
-
(this.
|
|
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.
|
|
38
|
+
(this.Vi = null),
|
|
38
39
|
(this.T = null),
|
|
39
|
-
(this.
|
|
40
|
-
(this.
|
|
40
|
+
(this._i = 0),
|
|
41
|
+
(this.Qi = ti),
|
|
41
42
|
(this.Yi = null),
|
|
42
43
|
(this.Zi = null),
|
|
43
|
-
(this.
|
|
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 =
|
|
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 =
|
|
54
|
-
(this.
|
|
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
|
-
|
|
60
|
+
Ne(i) {
|
|
59
61
|
return i
|
|
60
|
-
?
|
|
62
|
+
? ni()
|
|
61
63
|
? "sharedworker"
|
|
62
|
-
: (
|
|
64
|
+
: (b.info(
|
|
63
65
|
"SharedWorker not supported, using direct EventSource (multi-tab will gracefully degrade)",
|
|
64
66
|
),
|
|
65
67
|
"direct")
|
|
66
|
-
: (
|
|
68
|
+
: (b.info("Shared connection disabled, using direct EventSource"),
|
|
67
69
|
"direct");
|
|
68
70
|
}
|
|
69
|
-
|
|
70
|
-
this.
|
|
71
|
-
|
|
72
|
-
this.
|
|
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
|
-
|
|
75
|
-
this.
|
|
79
|
+
Le: () => {
|
|
80
|
+
this.ze = null;
|
|
76
81
|
},
|
|
77
|
-
|
|
78
|
-
|
|
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.
|
|
83
|
-
(
|
|
86
|
+
this.Fe.initialize() ||
|
|
87
|
+
(b.info(
|
|
84
88
|
"SharedWorker initialization failed, falling back to direct EventSource",
|
|
85
89
|
),
|
|
86
|
-
(this.
|
|
87
|
-
(this.
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
(this.
|
|
91
|
-
(this.
|
|
92
|
-
(this.
|
|
93
|
-
(this.
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
if (
|
|
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
|
-
|
|
107
|
-
} catch (
|
|
108
|
-
|
|
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
|
|
125
|
+
else b.info(`No subscribers for real-time message type '${t}'`);
|
|
113
126
|
}
|
|
114
|
-
|
|
115
|
-
return "sharedworker" === this.
|
|
127
|
+
_e() {
|
|
128
|
+
return "sharedworker" === this.Ue;
|
|
116
129
|
}
|
|
117
|
-
|
|
118
|
-
return this.
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (this.
|
|
122
|
-
const i = this.
|
|
123
|
-
t = this.
|
|
124
|
-
e = this.
|
|
125
|
-
n = this.
|
|
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
|
-
|
|
144
|
+
b.info("Restored real-time messaging configuration from storage"))
|
|
132
145
|
: (i || t) &&
|
|
133
|
-
(
|
|
146
|
+
(b.warn(
|
|
134
147
|
"Incomplete real-time messaging configuration in storage, clearing",
|
|
135
148
|
),
|
|
136
|
-
this.
|
|
149
|
+
this.en());
|
|
137
150
|
}
|
|
138
151
|
}
|
|
139
152
|
Hr() {
|
|
140
153
|
this.xe ||
|
|
141
|
-
this.
|
|
142
|
-
((this.xe = this.
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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.
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
166
|
-
this.
|
|
167
|
-
this.
|
|
168
|
-
((this.
|
|
169
|
-
(this.
|
|
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.
|
|
172
|
-
(this.
|
|
201
|
+
window.addEventListener("beforeunload", this.Re),
|
|
202
|
+
(this.ke = () => {
|
|
173
203
|
var i;
|
|
174
|
-
this.
|
|
175
|
-
(this.
|
|
176
|
-
(null === (i = this.
|
|
177
|
-
(
|
|
178
|
-
(this.
|
|
179
|
-
this.
|
|
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.
|
|
182
|
-
(this.
|
|
211
|
+
window.addEventListener("pagehide", this.ke),
|
|
212
|
+
(this.ye = (i) => {
|
|
183
213
|
var t;
|
|
184
214
|
const s =
|
|
185
|
-
this.
|
|
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
|
-
(
|
|
190
|
-
(this.
|
|
191
|
-
this.
|
|
192
|
-
this.
|
|
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.
|
|
224
|
+
window.addEventListener("pageshow", this.ye));
|
|
195
225
|
}
|
|
196
|
-
|
|
226
|
+
Et() {
|
|
197
227
|
return this.T;
|
|
198
228
|
}
|
|
199
|
-
|
|
229
|
+
Lt(i) {
|
|
200
230
|
this.T = i;
|
|
201
231
|
}
|
|
202
|
-
|
|
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.
|
|
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
|
-
|
|
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.
|
|
225
|
-
(this.
|
|
226
|
-
this.
|
|
227
|
-
this.
|
|
228
|
-
this.
|
|
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.
|
|
265
|
+
r = this.j;
|
|
236
266
|
if (!n || !r)
|
|
237
267
|
return (
|
|
238
|
-
|
|
268
|
+
b.error("NetworkManager or StorageManager not available"), void e()
|
|
239
269
|
);
|
|
240
270
|
if (!this.h || !this.h.fn())
|
|
241
271
|
return (
|
|
242
|
-
|
|
272
|
+
b.info("Real-time messaging is not enabled, skipping refresh"), void e()
|
|
243
273
|
);
|
|
244
274
|
this.un()
|
|
245
|
-
?
|
|
246
|
-
:
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
299
|
+
b.info(
|
|
270
300
|
"Received real-time messaging configuration from server",
|
|
271
301
|
),
|
|
272
|
-
r.
|
|
273
|
-
r.
|
|
274
|
-
t.auth ? r.
|
|
275
|
-
t.expiration ? r.
|
|
276
|
-
this.
|
|
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
|
-
: (
|
|
308
|
+
: (b.info(
|
|
279
309
|
"Real-time messaging configuration not available - this SDK version may not be supported",
|
|
280
310
|
),
|
|
281
|
-
this.
|
|
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
|
-
|
|
319
|
+
an() {
|
|
290
320
|
if (!this.h || !this.h.fn()) return;
|
|
291
321
|
if (!this.un())
|
|
292
|
-
return void
|
|
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
|
-
|
|
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.
|
|
332
|
+
this.an();
|
|
303
333
|
},
|
|
304
334
|
() => {
|
|
305
|
-
|
|
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.
|
|
344
|
+
switch (this.Ue) {
|
|
315
345
|
case "sharedworker":
|
|
316
346
|
this.vn(i, t);
|
|
317
347
|
break;
|
|
318
348
|
case "direct":
|
|
319
|
-
this.
|
|
320
|
-
(
|
|
349
|
+
this.Vi &&
|
|
350
|
+
(b.info(
|
|
321
351
|
"Real-time connection already exists, closing before starting new subscription",
|
|
322
352
|
),
|
|
323
|
-
this.
|
|
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
|
-
?
|
|
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.
|
|
366
|
+
if ((this.Fe || this.Ge(), !this.Fe))
|
|
337
367
|
return (
|
|
338
|
-
|
|
368
|
+
b.info(
|
|
339
369
|
"SharedWorker initialization failed, falling back to direct EventSource",
|
|
340
370
|
),
|
|
341
|
-
(this.
|
|
371
|
+
(this.Ue = "direct"),
|
|
342
372
|
void this.Sn()
|
|
343
373
|
);
|
|
344
|
-
this.Oi &&
|
|
345
|
-
|
|
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.
|
|
379
|
+
this.Fe.connect({
|
|
350
380
|
mite: i,
|
|
351
|
-
|
|
381
|
+
dustHost: t,
|
|
352
382
|
auth: this.Gi || void 0,
|
|
353
|
-
|
|
383
|
+
backoff: { minSleepMs: r, maxSleepMs: o, scaleFactor: h },
|
|
354
384
|
});
|
|
355
385
|
}
|
|
356
386
|
Sn() {
|
|
357
|
-
this.
|
|
358
|
-
(
|
|
387
|
+
this.Vi &&
|
|
388
|
+
(b.info(
|
|
359
389
|
"Real-time connection already exists, closing before starting new subscription",
|
|
360
390
|
),
|
|
361
|
-
this.
|
|
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 &&
|
|
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
|
-
? (
|
|
402
|
+
? (b.info(
|
|
373
403
|
"Gapless reconnection: new connection established, closing old connection",
|
|
374
404
|
),
|
|
375
405
|
i.close())
|
|
376
|
-
:
|
|
377
|
-
(this.
|
|
378
|
-
(this.
|
|
379
|
-
(this.
|
|
380
|
-
(this.
|
|
381
|
-
(this.
|
|
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.
|
|
415
|
+
this.yn(i.data);
|
|
385
416
|
}),
|
|
386
417
|
(s.onerror = () => {
|
|
387
418
|
const t = s.readyState;
|
|
388
419
|
return (
|
|
389
|
-
this.
|
|
420
|
+
this.De ||
|
|
390
421
|
(0 === t
|
|
391
|
-
?
|
|
392
|
-
:
|
|
393
|
-
i && this.
|
|
394
|
-
? (
|
|
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.
|
|
399
|
-
: (this.
|
|
400
|
-
this.
|
|
401
|
-
? (
|
|
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.
|
|
405
|
-
: void (this.
|
|
406
|
-
? this
|
|
407
|
-
: (this.
|
|
408
|
-
|
|
409
|
-
`Max retry attempts (${this.
|
|
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.
|
|
442
|
+
(this.we = !1))))
|
|
412
443
|
);
|
|
413
444
|
});
|
|
414
445
|
} catch (i) {
|
|
415
|
-
|
|
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
|
-
|
|
454
|
+
$n() {
|
|
424
455
|
var i, t, s;
|
|
425
|
-
this.
|
|
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.
|
|
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.
|
|
433
|
-
|
|
434
|
-
`Retrying real-time messaging connection in ${h}ms (attempt ${this.
|
|
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.
|
|
468
|
+
(this.Yi = null), this.an();
|
|
438
469
|
}, h));
|
|
439
470
|
}
|
|
440
|
-
|
|
471
|
+
ln() {
|
|
441
472
|
if (this.un()) {
|
|
442
473
|
if (this.gn())
|
|
443
474
|
return (
|
|
444
|
-
|
|
475
|
+
b.info(
|
|
445
476
|
"Auth token expired during gapless reconnection, falling back to regular reconnection",
|
|
446
477
|
),
|
|
447
|
-
this.
|
|
448
|
-
void this.
|
|
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.
|
|
452
|
-
} else
|
|
482
|
+
this.wn(this.Vi || void 0);
|
|
483
|
+
} else b.error("Cannot perform gapless reconnection without configuration");
|
|
453
484
|
}
|
|
454
|
-
|
|
485
|
+
hn() {
|
|
455
486
|
var i;
|
|
456
|
-
switch (this.
|
|
487
|
+
switch (((this.ze = null), this.Ue)) {
|
|
457
488
|
case "sharedworker":
|
|
458
|
-
null === (i = this.
|
|
489
|
+
null === (i = this.Fe) || void 0 === i || i.disconnect();
|
|
459
490
|
break;
|
|
460
491
|
case "direct":
|
|
461
|
-
this.
|
|
492
|
+
this.kn();
|
|
462
493
|
}
|
|
463
494
|
}
|
|
464
|
-
|
|
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.
|
|
468
|
-
|
|
469
|
-
(this.
|
|
470
|
-
|
|
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
|
-
|
|
504
|
+
yn(i) {
|
|
473
505
|
try {
|
|
474
506
|
const t = JSON.parse(i);
|
|
475
|
-
this.
|
|
507
|
+
this.qe(t);
|
|
476
508
|
} catch (i) {
|
|
477
|
-
|
|
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.
|
|
517
|
+
this.hn(),
|
|
486
518
|
i ||
|
|
487
519
|
(this.un() &&
|
|
488
|
-
|
|
520
|
+
b.info(
|
|
489
521
|
"Clearing cached real-time messaging configuration for user change",
|
|
490
522
|
),
|
|
491
|
-
this.
|
|
492
|
-
this.
|
|
523
|
+
this.en()),
|
|
524
|
+
this.Je();
|
|
493
525
|
}
|
|
494
526
|
clearData(i = !1) {
|
|
495
|
-
(this.
|
|
496
|
-
this.
|
|
527
|
+
(this.we = !1),
|
|
528
|
+
this.hn(),
|
|
497
529
|
i &&
|
|
498
530
|
(this.un() &&
|
|
499
|
-
|
|
531
|
+
b.info(
|
|
500
532
|
"Clearing cached real-time messaging configuration (wipeData)",
|
|
501
533
|
),
|
|
502
|
-
this.
|
|
503
|
-
this.
|
|
534
|
+
this.en()),
|
|
535
|
+
this.Je();
|
|
504
536
|
}
|
|
505
537
|
destroy() {
|
|
506
|
-
(this.
|
|
507
|
-
this.
|
|
508
|
-
this.
|
|
509
|
-
this.
|
|
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.
|
|
512
|
-
this.
|
|
513
|
-
(window.removeEventListener("beforeunload", this.
|
|
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("
|
|
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
|
}
|