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