@vbotma/bridge 2.2.8 → 2.2.9
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/dist/dts/env/setLaunchParams.d.ts +63 -0
- package/dist/dts/index.d.ts +1 -0
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.iife.js +3 -3
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +274 -221
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,42 +1,43 @@
|
|
|
1
|
-
import { is as O, looseObject as w, function as
|
|
2
|
-
import { throwifyFpFn as
|
|
3
|
-
import { createLogger as
|
|
4
|
-
import { BetterPromise as
|
|
5
|
-
import { CancelledError as
|
|
6
|
-
import { function as l, either as c, option as F, taskEither as
|
|
7
|
-
import { errorClassWithData as
|
|
8
|
-
import { parseLaunchParamsQueryFp as
|
|
9
|
-
import { signal as
|
|
10
|
-
import
|
|
11
|
-
function
|
|
1
|
+
import { is as O, looseObject as w, function as re, nullish as E, boolean as D, number as G, string as P, optional as J, unknown as ge, parse as A, any as ye } from "valibot";
|
|
2
|
+
import { throwifyFpFn as W, getStorageValue as ve, setStorageValue as R, createLogger as Ee, throwifyAnyEither as C, createCbCollector as ne, BetterTaskEither as oe } from "@vbotma/toolkit";
|
|
3
|
+
import { createLogger as xt, deepSnakeToCamelObjKeys as St } from "@vbotma/toolkit";
|
|
4
|
+
import { BetterPromise as ae, TimeoutError as Pe } from "better-promises";
|
|
5
|
+
import { CancelledError as At, TimeoutError as Bt } from "better-promises";
|
|
6
|
+
import { function as l, either as c, option as F, taskEither as d, json as xe } from "fp-ts";
|
|
7
|
+
import { errorClassWithData as Se, errorClass as S } from "error-kid";
|
|
8
|
+
import { parseLaunchParamsQueryFp as se, themeParams as ke, pipeJsonToSchema as T, miniAppsMessage as U, serializeLaunchParamsQuery as ie, parseLaunchParamsQuery as pe } from "@vbotma/transformers";
|
|
9
|
+
import { signal as g, computed as ce } from "@vbotma/signals";
|
|
10
|
+
import Ae from "mitt";
|
|
11
|
+
function _e(e) {
|
|
12
12
|
return O(
|
|
13
|
-
w({ VBotWebviewProxy: w({ postEvent:
|
|
13
|
+
w({ VBotWebviewProxy: w({ postEvent: re() }) }),
|
|
14
14
|
e
|
|
15
15
|
);
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function j() {
|
|
18
18
|
try {
|
|
19
19
|
return window.self !== window.top;
|
|
20
20
|
} catch {
|
|
21
21
|
return !0;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
class Be extends (/* @__PURE__ */
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
class Be extends (/* @__PURE__ */ S(
|
|
25
|
+
"MethodUnsupportedError",
|
|
26
|
+
(t, r) => [
|
|
27
|
+
`Method "${t}" is unsupported in Mini Apps version ${r}`
|
|
28
|
+
]
|
|
29
|
+
)) {
|
|
27
30
|
}
|
|
28
|
-
class
|
|
31
|
+
class We extends (/* @__PURE__ */ S("MethodParameterUnsupportedError", (t, r, n) => [
|
|
29
32
|
`Parameter "${r}" of "${t}" method is unsupported in Mini Apps version ${n}`
|
|
30
33
|
])) {
|
|
31
34
|
}
|
|
32
|
-
class
|
|
35
|
+
class Ce extends (/* @__PURE__ */ Se(
|
|
33
36
|
"LaunchParamsRetrieveError",
|
|
34
37
|
(t) => ({ errors: t }),
|
|
35
38
|
(t) => [
|
|
36
39
|
[
|
|
37
|
-
"Unable to retrieve launch parameters from any known source.
|
|
38
|
-
"📖 Refer to docs for more information:",
|
|
39
|
-
"https://docs.vbot-mini-apps.com/packages/tma-js-bridge/environment",
|
|
40
|
+
"Unable to retrieve launch parameters from any known source. You should pass correct parameters to Mini App",
|
|
40
41
|
"",
|
|
41
42
|
"Collected errors:",
|
|
42
43
|
...t.map(({ source: r, error: n }) => `Source: ${r} / ${n instanceof Error ? n.message : String(n)}`)
|
|
@@ -45,30 +46,33 @@ class Ae extends (/* @__PURE__ */ Ee(
|
|
|
45
46
|
]
|
|
46
47
|
)) {
|
|
47
48
|
}
|
|
48
|
-
class
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
class ue extends (/* @__PURE__ */ S(
|
|
50
|
+
"InvalidLaunchParamsError",
|
|
51
|
+
(t, r) => [
|
|
52
|
+
`Invalid value for launch params: ${t}`,
|
|
53
|
+
{ cause: r }
|
|
54
|
+
]
|
|
55
|
+
)) {
|
|
52
56
|
}
|
|
53
|
-
class
|
|
57
|
+
class fe extends (/* @__PURE__ */ S("UnknownEnvError")) {
|
|
54
58
|
}
|
|
55
|
-
class
|
|
59
|
+
class Ve extends (/* @__PURE__ */ S(
|
|
56
60
|
"InvokeCustomMethodError",
|
|
57
61
|
(t) => [`Server returned error: ${t}`]
|
|
58
62
|
)) {
|
|
59
63
|
}
|
|
60
|
-
const
|
|
61
|
-
function
|
|
64
|
+
const H = "launchParams";
|
|
65
|
+
function N(e) {
|
|
62
66
|
return e.replace(/^[^?#]*[?#]/, "").replace(/[?#]/g, "&");
|
|
63
67
|
}
|
|
64
|
-
function
|
|
68
|
+
function Le() {
|
|
65
69
|
return l.pipe(
|
|
66
70
|
V(),
|
|
67
|
-
c.chainW(
|
|
71
|
+
c.chainW(se)
|
|
68
72
|
);
|
|
69
73
|
}
|
|
70
|
-
const rt =
|
|
71
|
-
function
|
|
74
|
+
const rt = W(Le);
|
|
75
|
+
function Me() {
|
|
72
76
|
return l.pipe(
|
|
73
77
|
V(),
|
|
74
78
|
c.map((e) => {
|
|
@@ -79,7 +83,7 @@ function qe() {
|
|
|
79
83
|
}
|
|
80
84
|
function nt() {
|
|
81
85
|
return l.pipe(
|
|
82
|
-
|
|
86
|
+
Me(),
|
|
83
87
|
c.fold((e) => {
|
|
84
88
|
throw e;
|
|
85
89
|
}, (e) => e),
|
|
@@ -93,14 +97,14 @@ function V() {
|
|
|
93
97
|
// Try to retrieve launch parameters from the current location. This method
|
|
94
98
|
// can return nothing in case, location was changed, and then the page was
|
|
95
99
|
// reloaded.
|
|
96
|
-
[() =>
|
|
100
|
+
[() => N(window.location.href), "window.location.href"],
|
|
97
101
|
// Then, try using the lower level API - window.performance.
|
|
98
102
|
[() => {
|
|
99
103
|
const n = performance.getEntriesByType("navigation")[0];
|
|
100
|
-
return n &&
|
|
104
|
+
return n && N(n.name);
|
|
101
105
|
}, "performance navigation entries"],
|
|
102
106
|
// Finally, try using the session storage.
|
|
103
|
-
[() =>
|
|
107
|
+
[() => ve(H), "local storage"]
|
|
104
108
|
]) {
|
|
105
109
|
const n = t();
|
|
106
110
|
if (!n) {
|
|
@@ -108,20 +112,20 @@ function V() {
|
|
|
108
112
|
continue;
|
|
109
113
|
}
|
|
110
114
|
const a = l.pipe(
|
|
111
|
-
|
|
115
|
+
se(n),
|
|
112
116
|
c.foldW((o) => o, () => !0)
|
|
113
117
|
);
|
|
114
118
|
if (typeof a != "boolean") {
|
|
115
119
|
e.push({ source: r, error: a });
|
|
116
120
|
continue;
|
|
117
121
|
}
|
|
118
|
-
return
|
|
122
|
+
return R(H, n), c.right(n);
|
|
119
123
|
}
|
|
120
|
-
return c.left(new
|
|
124
|
+
return c.left(new Ce(e));
|
|
121
125
|
}
|
|
122
|
-
const ot =
|
|
123
|
-
function
|
|
124
|
-
const r = /* @__PURE__ */ new Map(), n =
|
|
126
|
+
const ot = W(V);
|
|
127
|
+
function le(e, t) {
|
|
128
|
+
const r = /* @__PURE__ */ new Map(), n = Ae(), a = (o, s, i = !1) => {
|
|
125
129
|
const _ = r.get(o) || /* @__PURE__ */ new Map();
|
|
126
130
|
r.set(o, _);
|
|
127
131
|
const p = _.get(s) || [];
|
|
@@ -137,8 +141,8 @@ function _e(e, t) {
|
|
|
137
141
|
!r.size && e();
|
|
138
142
|
const _ = () => {
|
|
139
143
|
a(o, s, i);
|
|
140
|
-
}, p = (...
|
|
141
|
-
i && _(), o === "*" ? s({ name:
|
|
144
|
+
}, p = (...m) => {
|
|
145
|
+
i && _(), o === "*" ? s({ name: m[0], payload: m[1] }) : s(...m);
|
|
142
146
|
};
|
|
143
147
|
n.on(o, p);
|
|
144
148
|
const u = r.get(o) || /* @__PURE__ */ new Map();
|
|
@@ -155,7 +159,7 @@ function _e(e, t) {
|
|
|
155
159
|
}
|
|
156
160
|
};
|
|
157
161
|
}
|
|
158
|
-
function
|
|
162
|
+
function M(e, t) {
|
|
159
163
|
window.dispatchEvent(new MessageEvent("message", {
|
|
160
164
|
data: JSON.stringify({ eventType: e, eventData: t }),
|
|
161
165
|
// We specify this kind of source here in order to allow the package's "on" function to
|
|
@@ -164,25 +168,25 @@ function W(e, t) {
|
|
|
164
168
|
source: window.parent
|
|
165
169
|
}));
|
|
166
170
|
}
|
|
167
|
-
const B =
|
|
168
|
-
|
|
169
|
-
},
|
|
171
|
+
const B = g(!1), I = g("https://web.telegram.org"), qe = (e) => {
|
|
172
|
+
h().log("Event received:", e);
|
|
173
|
+
}, we = ce(B);
|
|
170
174
|
function at(e) {
|
|
171
|
-
e !== B() && (B.set(e), (e ?
|
|
175
|
+
e !== B() && (B.set(e), (e ? $ : Oe)("*", qe));
|
|
172
176
|
}
|
|
173
|
-
const
|
|
177
|
+
const de = ce(I);
|
|
174
178
|
function st(e) {
|
|
175
|
-
|
|
179
|
+
I.set(e), h().log("New target origin set", e);
|
|
176
180
|
}
|
|
177
|
-
const
|
|
181
|
+
const b = g((...e) => {
|
|
178
182
|
window.parent.postMessage(...e);
|
|
179
|
-
}),
|
|
183
|
+
}), h = g(Ee("Bridge", {
|
|
180
184
|
bgColor: "#9147ff",
|
|
181
185
|
textColor: "white",
|
|
182
|
-
shouldLog:
|
|
186
|
+
shouldLog: we
|
|
183
187
|
}));
|
|
184
188
|
function it() {
|
|
185
|
-
|
|
189
|
+
Te(), [b, I, de, B, we, h].forEach((e) => {
|
|
186
190
|
e.unsubAll(), "reset" in e && e.reset();
|
|
187
191
|
});
|
|
188
192
|
}
|
|
@@ -202,28 +206,28 @@ function q(e, t, r) {
|
|
|
202
206
|
return;
|
|
203
207
|
}
|
|
204
208
|
if (i === 2) {
|
|
205
|
-
|
|
209
|
+
K(e, t, n[1]);
|
|
206
210
|
return;
|
|
207
211
|
}
|
|
208
|
-
n.unshift(1),
|
|
212
|
+
n.unshift(1), K(e, t, o);
|
|
209
213
|
}
|
|
210
214
|
});
|
|
211
|
-
|
|
215
|
+
me(
|
|
212
216
|
e,
|
|
213
217
|
t,
|
|
214
218
|
() => s,
|
|
215
219
|
(i) => n.push(i)
|
|
216
220
|
);
|
|
217
221
|
}
|
|
218
|
-
function
|
|
222
|
+
function Q(e, t) {
|
|
219
223
|
const r = e[t];
|
|
220
|
-
|
|
224
|
+
me(e, t, () => r, (n) => {
|
|
221
225
|
Object.entries(n).forEach(([a, o]) => {
|
|
222
226
|
r[a] = o;
|
|
223
227
|
});
|
|
224
228
|
});
|
|
225
229
|
}
|
|
226
|
-
function
|
|
230
|
+
function me(e, t, r, n) {
|
|
227
231
|
Object.defineProperty(e, t, {
|
|
228
232
|
enumerable: !0,
|
|
229
233
|
configurable: !0,
|
|
@@ -231,7 +235,7 @@ function le(e, t, r, n) {
|
|
|
231
235
|
set: n
|
|
232
236
|
});
|
|
233
237
|
}
|
|
234
|
-
function
|
|
238
|
+
function K(e, t, r) {
|
|
235
239
|
Object.defineProperty(e, t, {
|
|
236
240
|
enumerable: !0,
|
|
237
241
|
configurable: !0,
|
|
@@ -241,25 +245,25 @@ function H(e, t, r) {
|
|
|
241
245
|
}
|
|
242
246
|
const Fe = {
|
|
243
247
|
clipboard_text_received: w({
|
|
244
|
-
req_id:
|
|
245
|
-
data:
|
|
248
|
+
req_id: P(),
|
|
249
|
+
data: E(P())
|
|
246
250
|
}),
|
|
247
251
|
custom_method_invoked: w({
|
|
248
|
-
req_id:
|
|
249
|
-
result:
|
|
250
|
-
error:
|
|
252
|
+
req_id: P(),
|
|
253
|
+
result: J(ge()),
|
|
254
|
+
error: J(P())
|
|
251
255
|
}),
|
|
252
|
-
popup_closed:
|
|
253
|
-
w({ button_id:
|
|
256
|
+
popup_closed: E(
|
|
257
|
+
w({ button_id: E(P(), () => {
|
|
254
258
|
}) }),
|
|
255
259
|
{}
|
|
256
260
|
),
|
|
257
|
-
viewport_changed:
|
|
261
|
+
viewport_changed: E(
|
|
258
262
|
w({
|
|
259
|
-
height:
|
|
260
|
-
width:
|
|
261
|
-
is_state_stable:
|
|
262
|
-
is_expanded:
|
|
263
|
+
height: G(),
|
|
264
|
+
width: E(G(), () => window.innerWidth),
|
|
265
|
+
is_state_stable: D(),
|
|
266
|
+
is_expanded: D()
|
|
263
267
|
}),
|
|
264
268
|
// TODO: At the moment, macOS has a bug with the invalid event payload - it is always equal to
|
|
265
269
|
// null. Leaving this default value until the bug is fixed.
|
|
@@ -270,24 +274,24 @@ const Fe = {
|
|
|
270
274
|
})
|
|
271
275
|
),
|
|
272
276
|
theme_changed: w({
|
|
273
|
-
theme_params:
|
|
277
|
+
theme_params: ke()
|
|
274
278
|
})
|
|
275
279
|
};
|
|
276
|
-
function
|
|
280
|
+
function Y(e) {
|
|
277
281
|
if (e.source !== window.parent)
|
|
278
282
|
return;
|
|
279
283
|
let t;
|
|
280
284
|
try {
|
|
281
|
-
t =
|
|
285
|
+
t = A(T(U()), e.data);
|
|
282
286
|
} catch {
|
|
283
287
|
return;
|
|
284
288
|
}
|
|
285
289
|
const { eventType: r, eventData: n } = t, a = Fe[r];
|
|
286
290
|
let o;
|
|
287
291
|
try {
|
|
288
|
-
o = a ?
|
|
292
|
+
o = a ? A(a, n) : n;
|
|
289
293
|
} catch (s) {
|
|
290
|
-
return
|
|
294
|
+
return h().forceError(
|
|
291
295
|
[
|
|
292
296
|
`An error occurred processing the "${r}" event from the VBot application.`,
|
|
293
297
|
"Please, file an issue here:",
|
|
@@ -298,17 +302,17 @@ function J(e) {
|
|
|
298
302
|
s
|
|
299
303
|
);
|
|
300
304
|
}
|
|
301
|
-
|
|
305
|
+
Re(r, o);
|
|
302
306
|
}
|
|
303
307
|
const {
|
|
304
|
-
on:
|
|
308
|
+
on: $,
|
|
305
309
|
off: Oe,
|
|
306
|
-
emit:
|
|
307
|
-
clear:
|
|
308
|
-
} =
|
|
310
|
+
emit: Re,
|
|
311
|
+
clear: Te
|
|
312
|
+
} = le(
|
|
309
313
|
() => {
|
|
310
314
|
const e = window;
|
|
311
|
-
!e.TelegramGameProxy && (e.TelegramGameProxy = {}), q(e.TelegramGameProxy, "receiveEvent",
|
|
315
|
+
!e.TelegramGameProxy && (e.TelegramGameProxy = {}), q(e.TelegramGameProxy, "receiveEvent", M), Q(e, "TelegramGameProxy"), !e.VBot && (e.VBot = {}), !e.VBot.WebView && (e.VBot.WebView = {}), q(e.VBot.WebView, "receiveEvent", M), Q(e.VBot, "WebView"), q(e, "TelegramGameProxy_receiveEvent", M), window.addEventListener("message", Y);
|
|
312
316
|
},
|
|
313
317
|
() => {
|
|
314
318
|
[
|
|
@@ -323,12 +327,12 @@ const {
|
|
|
323
327
|
return;
|
|
324
328
|
const [n, a] = r;
|
|
325
329
|
"unwrap" in a && (a.unwrap(), n && n !== t && !Object.keys(n).length && delete t[e[0]]);
|
|
326
|
-
}), window.removeEventListener("message",
|
|
330
|
+
}), window.removeEventListener("message", Y);
|
|
327
331
|
}
|
|
328
|
-
),
|
|
329
|
-
function
|
|
332
|
+
), Ue = (...e) => b()(...e);
|
|
333
|
+
function je(e, t) {
|
|
330
334
|
l.pipe(
|
|
331
|
-
|
|
335
|
+
k(
|
|
332
336
|
// @ts-expect-error It's ok, TS can't determine a specific override.
|
|
333
337
|
e,
|
|
334
338
|
t
|
|
@@ -338,20 +342,20 @@ function Ue(e, t) {
|
|
|
338
342
|
})
|
|
339
343
|
);
|
|
340
344
|
}
|
|
341
|
-
function
|
|
342
|
-
|
|
345
|
+
function k(e, t) {
|
|
346
|
+
h().log("Posting event:", t ? { eventType: e, eventData: t } : { eventType: e });
|
|
343
347
|
const r = window, n = JSON.stringify({ eventType: e, eventData: t });
|
|
344
|
-
return
|
|
348
|
+
return j() ? (Ue(n, de()), c.right(void 0)) : _e(r) ? (r.VBotWebviewProxy.postEvent(e, JSON.stringify(t)), c.right(void 0)) : O(w({ external: w({ notify: re() }) }), r) ? (r.external.notify(n), c.right(void 0)) : c.left(new fe());
|
|
345
349
|
}
|
|
346
|
-
function
|
|
350
|
+
function z(e, t, r = {}) {
|
|
347
351
|
const {
|
|
348
352
|
// If no capture function was passed, we capture the first compatible event.
|
|
349
353
|
capture: n = () => !0,
|
|
350
|
-
postEvent: a =
|
|
351
|
-
} = r, o =
|
|
354
|
+
postEvent: a = k
|
|
355
|
+
} = r, o = g(), [s, i] = ne();
|
|
352
356
|
(Array.isArray(t) ? t : [t]).forEach((p) => {
|
|
353
357
|
s(
|
|
354
|
-
|
|
358
|
+
$(p, (u) => {
|
|
355
359
|
const f = Array.isArray(t);
|
|
356
360
|
n(f ? { event: p, payload: u } : u) && o.set([
|
|
357
361
|
f ? { event: p, payload: u } : u
|
|
@@ -362,25 +366,25 @@ function j(e, t, r = {}) {
|
|
|
362
366
|
const _ = (p) => (i(), p);
|
|
363
367
|
return l.pipe(
|
|
364
368
|
async () => a(e, r.params),
|
|
365
|
-
|
|
366
|
-
const
|
|
367
|
-
if (
|
|
368
|
-
return p(
|
|
369
|
-
const
|
|
369
|
+
d.chainW(() => oe((p, u, f) => {
|
|
370
|
+
const m = o();
|
|
371
|
+
if (m)
|
|
372
|
+
return p(m[0]);
|
|
373
|
+
const y = (v) => {
|
|
370
374
|
v && p(v[0]);
|
|
371
|
-
},
|
|
372
|
-
o.unsub(
|
|
375
|
+
}, L = () => {
|
|
376
|
+
o.unsub(y);
|
|
373
377
|
};
|
|
374
|
-
o.sub(
|
|
378
|
+
o.sub(y), f.on("finalized", L);
|
|
375
379
|
}, r)),
|
|
376
|
-
|
|
380
|
+
d.mapBoth(_, _)
|
|
377
381
|
);
|
|
378
382
|
}
|
|
379
383
|
function pt(e, t, r) {
|
|
380
384
|
const { postEvent: n } = r || {};
|
|
381
|
-
return
|
|
385
|
+
return C(
|
|
382
386
|
// @ts-expect-error TypeScript will not be able to handle our overrides here.
|
|
383
|
-
|
|
387
|
+
z(e, t, {
|
|
384
388
|
...r,
|
|
385
389
|
postEvent: n ? (...a) => {
|
|
386
390
|
try {
|
|
@@ -388,7 +392,7 @@ function pt(e, t, r) {
|
|
|
388
392
|
} catch (o) {
|
|
389
393
|
return c.left(o);
|
|
390
394
|
}
|
|
391
|
-
} :
|
|
395
|
+
} : k
|
|
392
396
|
})
|
|
393
397
|
);
|
|
394
398
|
}
|
|
@@ -398,19 +402,19 @@ function ct(e, t) {
|
|
|
398
402
|
e,
|
|
399
403
|
t
|
|
400
404
|
);
|
|
401
|
-
return typeof r == "function" ?
|
|
405
|
+
return typeof r == "function" ? ae.fn(() => C(r)) : r;
|
|
402
406
|
}
|
|
403
407
|
function Ie(e, t) {
|
|
404
|
-
const r =
|
|
408
|
+
const r = _e(window);
|
|
405
409
|
if (!e)
|
|
406
410
|
return r || l.pipe(V(), c.match(() => !1, () => !0));
|
|
407
411
|
if (r)
|
|
408
|
-
return
|
|
412
|
+
return d.right(!0);
|
|
409
413
|
const { timeout: n = 100 } = t || {};
|
|
410
414
|
return l.pipe(
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
(a) =>
|
|
415
|
+
z("web_app_request_theme", "theme_changed", { ...t, timeout: n }),
|
|
416
|
+
d.match(
|
|
417
|
+
(a) => Pe.is(a) || fe.is(a) ? c.right(!1) : c.left(a),
|
|
414
418
|
() => c.right(!0)
|
|
415
419
|
)
|
|
416
420
|
);
|
|
@@ -421,26 +425,26 @@ function _t({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
|
|
|
421
425
|
// Here we have to trick serializeLaunchParamsQuery into thinking, it serializes a valid
|
|
422
426
|
// value. We are doing it because we are working with vbWebAppData presented as a
|
|
423
427
|
// string, not an object as serializeLaunchParamsQuery requires.
|
|
424
|
-
|
|
428
|
+
ie({ ...e, vbWebAppData: void 0 }) + (e.vbWebAppData ? `&vbWebAppData=${encodeURIComponent(e.vbWebAppData.toString())}` : "")
|
|
425
429
|
);
|
|
426
430
|
try {
|
|
427
|
-
|
|
431
|
+
pe(o);
|
|
428
432
|
} catch (s) {
|
|
429
|
-
throw new
|
|
433
|
+
throw new ue(o, s);
|
|
430
434
|
}
|
|
431
|
-
|
|
435
|
+
R("launchParams", o);
|
|
432
436
|
}
|
|
433
|
-
if (
|
|
437
|
+
if (j()) {
|
|
434
438
|
if (!t)
|
|
435
439
|
return;
|
|
436
|
-
r &&
|
|
437
|
-
const o =
|
|
438
|
-
|
|
440
|
+
r && b.reset();
|
|
441
|
+
const o = b();
|
|
442
|
+
b.set((...s) => {
|
|
439
443
|
const [i] = s, _ = () => {
|
|
440
444
|
o(...s);
|
|
441
445
|
};
|
|
442
446
|
try {
|
|
443
|
-
const p =
|
|
447
|
+
const p = A(T(U()), i);
|
|
444
448
|
t({ name: p.eventType, params: p.eventData }, _);
|
|
445
449
|
} catch {
|
|
446
450
|
_();
|
|
@@ -461,9 +465,57 @@ function _t({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
|
|
|
461
465
|
params: s ? JSON.parse(s) : void 0
|
|
462
466
|
}, i) : i();
|
|
463
467
|
}
|
|
464
|
-
},
|
|
468
|
+
}, h().log("Environment was mocked by the mockVBotEnv function");
|
|
465
469
|
}
|
|
466
|
-
function ut(e, t =
|
|
470
|
+
function ut({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
|
|
471
|
+
if (e) {
|
|
472
|
+
const o = typeof e == "string" || e instanceof URLSearchParams ? e.toString() : (
|
|
473
|
+
// Here we have to trick serializeLaunchParamsQuery into thinking, it serializes a valid
|
|
474
|
+
// value. We are doing it because we are working with vbWebAppData presented as a
|
|
475
|
+
// string, not an object as serializeLaunchParamsQuery requires.
|
|
476
|
+
ie({ ...e, vbWebAppData: void 0 }) + (e.vbWebAppData ? `&vbWebAppData=${encodeURIComponent(e.vbWebAppData.toString())}` : "")
|
|
477
|
+
);
|
|
478
|
+
try {
|
|
479
|
+
pe(o);
|
|
480
|
+
} catch (s) {
|
|
481
|
+
throw new ue(o, s);
|
|
482
|
+
}
|
|
483
|
+
R("launchParams", o);
|
|
484
|
+
}
|
|
485
|
+
if (j()) {
|
|
486
|
+
if (!t)
|
|
487
|
+
return;
|
|
488
|
+
r && b.reset();
|
|
489
|
+
const o = b();
|
|
490
|
+
b.set((...s) => {
|
|
491
|
+
const [i] = s, _ = () => {
|
|
492
|
+
o(...s);
|
|
493
|
+
};
|
|
494
|
+
try {
|
|
495
|
+
const p = A(T(U()), i);
|
|
496
|
+
t({ name: p.eventType, params: p.eventData }, _);
|
|
497
|
+
} catch {
|
|
498
|
+
_();
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
const n = window.VBotWebviewProxy || {}, a = n.postEvent || (() => {
|
|
504
|
+
});
|
|
505
|
+
window.VBotWebviewProxy = {
|
|
506
|
+
...n,
|
|
507
|
+
postEvent(o, s) {
|
|
508
|
+
const i = () => {
|
|
509
|
+
a(o, s);
|
|
510
|
+
};
|
|
511
|
+
t ? t({
|
|
512
|
+
name: o,
|
|
513
|
+
params: s ? JSON.parse(s) : void 0
|
|
514
|
+
}, i) : i();
|
|
515
|
+
}
|
|
516
|
+
}, h().log("Launch params are injected by the setLaunchParams function");
|
|
517
|
+
}
|
|
518
|
+
function ft(e, t = "*") {
|
|
467
519
|
const r = (o) => {
|
|
468
520
|
if (o.source === e.contentWindow)
|
|
469
521
|
try {
|
|
@@ -471,7 +523,7 @@ function ut(e, t = "*") {
|
|
|
471
523
|
n.emit(i, _);
|
|
472
524
|
} catch {
|
|
473
525
|
}
|
|
474
|
-
}, n =
|
|
526
|
+
}, n = le(
|
|
475
527
|
() => {
|
|
476
528
|
window.addEventListener("message", r);
|
|
477
529
|
},
|
|
@@ -489,21 +541,21 @@ function ut(e, t = "*") {
|
|
|
489
541
|
},
|
|
490
542
|
// We need to override clear to also remove the window listener
|
|
491
543
|
clear: () => {
|
|
492
|
-
n.clear(),
|
|
544
|
+
n.clear(), x === a && (x = void 0);
|
|
493
545
|
}
|
|
494
546
|
};
|
|
495
|
-
return
|
|
547
|
+
return x = a, a;
|
|
496
548
|
}
|
|
497
|
-
let
|
|
498
|
-
function
|
|
499
|
-
if (!
|
|
549
|
+
let x;
|
|
550
|
+
function lt() {
|
|
551
|
+
if (!x)
|
|
500
552
|
throw new Error("HostBridge not initialized. Call defineHostBridge() first.");
|
|
501
|
-
return
|
|
553
|
+
return x;
|
|
502
554
|
}
|
|
503
555
|
function $e(e) {
|
|
504
556
|
return ({ req_id: t }) => t === e;
|
|
505
557
|
}
|
|
506
|
-
const
|
|
558
|
+
const X = {
|
|
507
559
|
"6.0": [
|
|
508
560
|
"iframe_ready",
|
|
509
561
|
"iframe_will_reload",
|
|
@@ -595,14 +647,14 @@ const N = {
|
|
|
595
647
|
"web_app_finish_refresh"
|
|
596
648
|
]
|
|
597
649
|
};
|
|
598
|
-
function
|
|
599
|
-
return Object.keys(
|
|
650
|
+
function Z(e, t) {
|
|
651
|
+
return Object.keys(X).find((n) => X[n].some((a) => t ? typeof a == "object" && a.method === e && a.param === t : a === e)) || null;
|
|
600
652
|
}
|
|
601
|
-
function
|
|
653
|
+
function ee(e) {
|
|
602
654
|
return e.split(".").map(Number);
|
|
603
655
|
}
|
|
604
656
|
function ze(e, t) {
|
|
605
|
-
const r =
|
|
657
|
+
const r = ee(e), n = ee(t), a = Math.max(r.length, n.length);
|
|
606
658
|
for (let o = 0; o < a; o += 1) {
|
|
607
659
|
const s = r[o] || 0, i = n[o] || 0;
|
|
608
660
|
if (s !== i)
|
|
@@ -610,37 +662,37 @@ function ze(e, t) {
|
|
|
610
662
|
}
|
|
611
663
|
return 0;
|
|
612
664
|
}
|
|
613
|
-
function
|
|
614
|
-
const n = r ?
|
|
665
|
+
function te(e, t, r) {
|
|
666
|
+
const n = r ? Z(
|
|
615
667
|
e,
|
|
616
668
|
t
|
|
617
|
-
) :
|
|
669
|
+
) : Z(e);
|
|
618
670
|
return n ? ze(n, r || t) <= 0 : !1;
|
|
619
671
|
}
|
|
620
|
-
function
|
|
672
|
+
function wt(e, t = "strict") {
|
|
621
673
|
const r = typeof t == "function" ? t : (n) => {
|
|
622
|
-
const { method: a, version: o } = n, s = "param" in n ? new
|
|
674
|
+
const { method: a, version: o } = n, s = "param" in n ? new We(a, n.param, o) : new Be(a, o);
|
|
623
675
|
if (t === "strict")
|
|
624
676
|
throw s;
|
|
625
|
-
return
|
|
677
|
+
return h().forceWarn(s.message);
|
|
626
678
|
};
|
|
627
|
-
return ((n, a) =>
|
|
679
|
+
return ((n, a) => te(n, e) ? n === "web_app_set_header_color" && O(w({ color: ye() }), a) && !te(n, "color", e) ? r({ version: e, method: n, param: "color" }) : je(n, a) : r({ version: e, method: n }));
|
|
628
680
|
}
|
|
629
|
-
function
|
|
681
|
+
function De(e, t, r, n) {
|
|
630
682
|
return l.pipe(
|
|
631
|
-
|
|
683
|
+
z("web_app_invoke_custom_method", "custom_method_invoked", {
|
|
632
684
|
...n || {},
|
|
633
685
|
params: { method: e, params: t, req_id: r },
|
|
634
686
|
capture: $e(r)
|
|
635
687
|
}),
|
|
636
|
-
|
|
688
|
+
d.chain(({ result: a, error: o }) => o ? d.left(new Ve(o)) : d.right(a))
|
|
637
689
|
);
|
|
638
690
|
}
|
|
639
|
-
function
|
|
640
|
-
return
|
|
691
|
+
function dt(e, t, r, n) {
|
|
692
|
+
return ae.fn(() => l.pipe(
|
|
641
693
|
// @ts-expect-error TypeScript is unable to determine required override.
|
|
642
|
-
|
|
643
|
-
|
|
694
|
+
De(e, t, r, n),
|
|
695
|
+
d.match(
|
|
644
696
|
(a) => {
|
|
645
697
|
throw a;
|
|
646
698
|
},
|
|
@@ -648,15 +700,15 @@ function wt(e, t, r, n) {
|
|
|
648
700
|
)
|
|
649
701
|
)());
|
|
650
702
|
}
|
|
651
|
-
function
|
|
703
|
+
function Ge(e, t, r = {}) {
|
|
652
704
|
const {
|
|
653
705
|
// If no capture function was passed, we capture the first compatible event.
|
|
654
706
|
capture: n = () => !0,
|
|
655
|
-
postEvent: a =
|
|
656
|
-
} = r, o =
|
|
707
|
+
postEvent: a = k
|
|
708
|
+
} = r, o = g(), [s, i] = ne();
|
|
657
709
|
(Array.isArray(t) ? t : [t]).forEach((p) => {
|
|
658
710
|
s(
|
|
659
|
-
|
|
711
|
+
$(p, (u) => {
|
|
660
712
|
(Array.isArray(t) ? n({ event: p, payload: u }) : n(u)) && o.set([u]);
|
|
661
713
|
})
|
|
662
714
|
);
|
|
@@ -664,25 +716,25 @@ function De(e, t, r = {}) {
|
|
|
664
716
|
const _ = (p) => (i(), p);
|
|
665
717
|
return l.pipe(
|
|
666
718
|
async () => a(e, r.params),
|
|
667
|
-
|
|
668
|
-
const
|
|
669
|
-
if (
|
|
670
|
-
return p(
|
|
671
|
-
const
|
|
719
|
+
d.chainW(() => oe((p, u, f) => {
|
|
720
|
+
const m = o();
|
|
721
|
+
if (m)
|
|
722
|
+
return p(m[0]);
|
|
723
|
+
const y = (v) => {
|
|
672
724
|
v && p(v[0]);
|
|
673
|
-
},
|
|
674
|
-
o.unsub(
|
|
725
|
+
}, L = () => {
|
|
726
|
+
o.unsub(y);
|
|
675
727
|
};
|
|
676
|
-
o.sub(
|
|
728
|
+
o.sub(y), f.on("finalized", L);
|
|
677
729
|
}, r)),
|
|
678
|
-
|
|
730
|
+
d.mapBoth(_, _)
|
|
679
731
|
);
|
|
680
732
|
}
|
|
681
733
|
function mt(e, t, r) {
|
|
682
734
|
const { postEvent: n } = r || {};
|
|
683
|
-
return
|
|
735
|
+
return C(
|
|
684
736
|
// @ts-expect-error TypeScript will not be able to handle our overrides here.
|
|
685
|
-
|
|
737
|
+
Ge(e, t, {
|
|
686
738
|
...r,
|
|
687
739
|
postEvent: n ? (...a) => {
|
|
688
740
|
try {
|
|
@@ -690,108 +742,109 @@ function mt(e, t, r) {
|
|
|
690
742
|
} catch (o) {
|
|
691
743
|
return c.left(o);
|
|
692
744
|
}
|
|
693
|
-
} :
|
|
745
|
+
} : k
|
|
694
746
|
})
|
|
695
747
|
);
|
|
696
748
|
}
|
|
697
|
-
function
|
|
749
|
+
function bt() {
|
|
698
750
|
Object.hasOwn || (Object.hasOwn = function(e, t) {
|
|
699
751
|
return Object.prototype.hasOwnProperty.call(e, t);
|
|
700
752
|
});
|
|
701
753
|
}
|
|
702
|
-
function
|
|
754
|
+
function be(e) {
|
|
703
755
|
return c.tryCatch(() => decodeURIComponent(
|
|
704
756
|
atob(
|
|
705
757
|
e.replace(/-/g, "+").replace(/_/g, "/")
|
|
706
758
|
).split("").map((t) => "%" + ("00" + t.charCodeAt(0).toString(16)).slice(-2)).join("")
|
|
707
759
|
), (t) => t);
|
|
708
760
|
}
|
|
709
|
-
const
|
|
710
|
-
function
|
|
761
|
+
const ht = W(be);
|
|
762
|
+
function he(e) {
|
|
711
763
|
return btoa(
|
|
712
764
|
encodeURIComponent(e).replace(/%([0-9A-F]{2})/g, (t, r) => String.fromCharCode(parseInt(`0x${r}`)))
|
|
713
765
|
).replace(/\+/g, "-").replace(/\//g, "_");
|
|
714
766
|
}
|
|
715
|
-
function
|
|
716
|
-
const t =
|
|
767
|
+
function Je(e) {
|
|
768
|
+
const t = he(typeof e == "string" ? e : JSON.stringify(e));
|
|
717
769
|
return t.length > 512 ? c.left(new Error("Value is too long for start parameter")) : c.right(t);
|
|
718
770
|
}
|
|
719
|
-
const
|
|
720
|
-
function
|
|
721
|
-
return
|
|
722
|
-
|
|
771
|
+
const gt = W(Je);
|
|
772
|
+
function yt(e, t) {
|
|
773
|
+
return C(
|
|
774
|
+
He(
|
|
723
775
|
e,
|
|
724
776
|
// @ts-expect-error TypeScript is unable to detect a correct override.
|
|
725
777
|
typeof t == "function" ? (r) => c.tryCatch(() => t(r), (n) => n) : t
|
|
726
778
|
)
|
|
727
779
|
);
|
|
728
780
|
}
|
|
729
|
-
function
|
|
781
|
+
function He(e, t) {
|
|
730
782
|
return l.pipe(
|
|
731
|
-
|
|
732
|
-
c.chain((r) => t ? typeof t == "function" ? t(r) :
|
|
783
|
+
be(e),
|
|
784
|
+
c.chain((r) => t ? typeof t == "function" ? t(r) : xe.parse(r) : c.right(r))
|
|
733
785
|
);
|
|
734
786
|
}
|
|
735
787
|
function vt(e) {
|
|
736
|
-
return
|
|
788
|
+
return he(e).length <= 512;
|
|
737
789
|
}
|
|
738
790
|
export {
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
791
|
+
At as CancelledError,
|
|
792
|
+
ue as InvalidLaunchParamsError,
|
|
793
|
+
Ve as InvokeCustomMethodFailedError,
|
|
794
|
+
Ce as LaunchParamsRetrieveError,
|
|
795
|
+
We as MethodParameterUnsupportedError,
|
|
744
796
|
Be as MethodUnsupportedError,
|
|
745
797
|
Bt as TimeoutError,
|
|
746
|
-
|
|
747
|
-
|
|
798
|
+
fe as UnknownEnvError,
|
|
799
|
+
bt as applyPolyfills,
|
|
748
800
|
$e as captureSameReq,
|
|
749
801
|
ze as compareVersions,
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
802
|
+
xt as createLogger,
|
|
803
|
+
wt as createPostEvent,
|
|
804
|
+
gt as createStartParam,
|
|
805
|
+
Je as createStartParamFp,
|
|
806
|
+
we as debug,
|
|
807
|
+
ht as decodeBase64Url,
|
|
808
|
+
be as decodeBase64UrlFp,
|
|
809
|
+
yt as decodeStartParam,
|
|
810
|
+
He as decodeStartParamFp,
|
|
811
|
+
St as deepSnakeToCamelObjKeys,
|
|
812
|
+
ft as defineHostBridge,
|
|
813
|
+
M as emitEvent,
|
|
814
|
+
he as encodeBase64Url,
|
|
815
|
+
lt as getHostBridge,
|
|
816
|
+
Z as getReleaseVersion,
|
|
817
|
+
_e as hasWebviewProxy,
|
|
818
|
+
dt as invokeCustomMethod,
|
|
819
|
+
De as invokeCustomMethodFp,
|
|
820
|
+
j as isIframe,
|
|
769
821
|
vt as isSafeToCreateStartParam,
|
|
770
822
|
ct as isVBma,
|
|
771
823
|
Ie as isVBmaFp,
|
|
772
|
-
|
|
824
|
+
h as logger,
|
|
773
825
|
_t as mockVBotEnv,
|
|
774
826
|
Oe as off,
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
827
|
+
Te as offAll,
|
|
828
|
+
$ as on,
|
|
829
|
+
je as postEvent,
|
|
830
|
+
k as postEventFp,
|
|
831
|
+
Ue as postMessage,
|
|
832
|
+
b as postMessageImpl,
|
|
781
833
|
mt as request,
|
|
782
834
|
pt as request2,
|
|
783
|
-
|
|
784
|
-
|
|
835
|
+
z as request2Fp,
|
|
836
|
+
Ge as requestFp,
|
|
785
837
|
it as resetGlobals,
|
|
786
838
|
rt as retrieveLaunchParams,
|
|
787
|
-
|
|
839
|
+
Le as retrieveLaunchParamsFp,
|
|
788
840
|
nt as retrieveRawInitData,
|
|
789
|
-
|
|
841
|
+
Me as retrieveRawInitDataFp,
|
|
790
842
|
ot as retrieveRawLaunchParams,
|
|
791
843
|
V as retrieveRawLaunchParamsFp,
|
|
792
844
|
at as setDebug,
|
|
845
|
+
ut as setLaunchParams,
|
|
793
846
|
st as setTargetOrigin,
|
|
794
|
-
|
|
795
|
-
|
|
847
|
+
te as supports,
|
|
848
|
+
de as targetOrigin
|
|
796
849
|
};
|
|
797
850
|
//# sourceMappingURL=index.js.map
|