@vbotma/bridge 2.2.10 → 2.3.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/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 +52 -53
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { is as O, looseObject as w, function as ne, nullish as P, boolean as
|
|
2
|
-
import { throwifyFpFn as
|
|
1
|
+
import { is as O, looseObject as w, function as ne, nullish as P, boolean as J, number as G, string as x, optional as H, unknown as he, parse as B, any as ye } from "valibot";
|
|
2
|
+
import { throwifyFpFn as A, getStorageValue as ve, setStorageValue as R, createLogger as Ee, throwifyAnyEither as V, createCbCollector as oe, BetterTaskEither as ae } from "@vbotma/toolkit";
|
|
3
3
|
import { createLogger as St, deepSnakeToCamelObjKeys as kt } from "@vbotma/toolkit";
|
|
4
4
|
import { BetterPromise as se, TimeoutError as Pe } from "better-promises";
|
|
5
5
|
import { CancelledError as Bt, TimeoutError as Ct } from "better-promises";
|
|
@@ -61,20 +61,20 @@ class Ve extends (/* @__PURE__ */ S(
|
|
|
61
61
|
(t) => [`Server returned error: ${t}`]
|
|
62
62
|
)) {
|
|
63
63
|
}
|
|
64
|
-
const
|
|
64
|
+
const N = "launchParams";
|
|
65
65
|
function Q(e) {
|
|
66
66
|
return e.replace(/^[^?#]*[?#]/, "").replace(/[?#]/g, "&");
|
|
67
67
|
}
|
|
68
68
|
function Le() {
|
|
69
69
|
return l.pipe(
|
|
70
|
-
|
|
70
|
+
L(),
|
|
71
71
|
c.chainW(ie)
|
|
72
72
|
);
|
|
73
73
|
}
|
|
74
|
-
const rt =
|
|
74
|
+
const rt = A(Le);
|
|
75
75
|
function Me() {
|
|
76
76
|
return l.pipe(
|
|
77
|
-
|
|
77
|
+
L(),
|
|
78
78
|
c.map((e) => {
|
|
79
79
|
const t = new URLSearchParams(e).get("vbWebAppData");
|
|
80
80
|
return t ? F.some(t) : F.none;
|
|
@@ -91,7 +91,7 @@ function nt() {
|
|
|
91
91
|
}, (e) => e)
|
|
92
92
|
);
|
|
93
93
|
}
|
|
94
|
-
function
|
|
94
|
+
function L() {
|
|
95
95
|
const e = [];
|
|
96
96
|
for (const [t, r] of [
|
|
97
97
|
// Try to retrieve launch parameters from the current location. This method
|
|
@@ -104,7 +104,7 @@ function V() {
|
|
|
104
104
|
return n && Q(n.name);
|
|
105
105
|
}, "performance navigation entries"],
|
|
106
106
|
// Finally, try using the session storage.
|
|
107
|
-
[() => ve(
|
|
107
|
+
[() => ve(N), "local storage"]
|
|
108
108
|
]) {
|
|
109
109
|
const n = t();
|
|
110
110
|
if (!n) {
|
|
@@ -119,11 +119,11 @@ function V() {
|
|
|
119
119
|
e.push({ source: r, error: a });
|
|
120
120
|
continue;
|
|
121
121
|
}
|
|
122
|
-
return R(
|
|
122
|
+
return R(N, n), c.right(n);
|
|
123
123
|
}
|
|
124
124
|
return c.left(new Ae(e));
|
|
125
125
|
}
|
|
126
|
-
const ot =
|
|
126
|
+
const ot = A(L);
|
|
127
127
|
function I(e, t) {
|
|
128
128
|
const r = /* @__PURE__ */ new Map(), n = We(), a = (o, s, i = !1) => {
|
|
129
129
|
const _ = r.get(o) || /* @__PURE__ */ new Map();
|
|
@@ -159,7 +159,7 @@ function I(e, t) {
|
|
|
159
159
|
}
|
|
160
160
|
};
|
|
161
161
|
}
|
|
162
|
-
function
|
|
162
|
+
function W(e, t) {
|
|
163
163
|
window.dispatchEvent(new MessageEvent("message", {
|
|
164
164
|
data: JSON.stringify({ eventType: e, eventData: t }),
|
|
165
165
|
// We specify this kind of source here in order to allow the package's "on" function to
|
|
@@ -168,11 +168,11 @@ function M(e, t) {
|
|
|
168
168
|
source: window.parent
|
|
169
169
|
}));
|
|
170
170
|
}
|
|
171
|
-
const
|
|
171
|
+
const C = y(!1), $ = y("https://web.telegram.org"), qe = (e) => {
|
|
172
172
|
h().log("Event received:", e);
|
|
173
|
-
}, we = _e(
|
|
173
|
+
}, we = _e(C);
|
|
174
174
|
function at(e) {
|
|
175
|
-
e !==
|
|
175
|
+
e !== C() && (C.set(e), (e ? z : Oe)("*", qe));
|
|
176
176
|
}
|
|
177
177
|
const de = _e($);
|
|
178
178
|
function st(e) {
|
|
@@ -186,7 +186,7 @@ const b = y((...e) => {
|
|
|
186
186
|
shouldLog: we
|
|
187
187
|
}));
|
|
188
188
|
function it() {
|
|
189
|
-
Te(), [b, $, de,
|
|
189
|
+
Te(), [b, $, de, C, we, h].forEach((e) => {
|
|
190
190
|
e.unsubAll(), "reset" in e && e.reset();
|
|
191
191
|
});
|
|
192
192
|
}
|
|
@@ -250,8 +250,8 @@ const Fe = {
|
|
|
250
250
|
}),
|
|
251
251
|
custom_method_invoked: w({
|
|
252
252
|
req_id: x(),
|
|
253
|
-
result:
|
|
254
|
-
error:
|
|
253
|
+
result: H(he()),
|
|
254
|
+
error: H(x())
|
|
255
255
|
}),
|
|
256
256
|
popup_closed: P(
|
|
257
257
|
w({ button_id: P(x(), () => {
|
|
@@ -262,8 +262,8 @@ const Fe = {
|
|
|
262
262
|
w({
|
|
263
263
|
height: G(),
|
|
264
264
|
width: P(G(), () => window.innerWidth),
|
|
265
|
-
is_state_stable:
|
|
266
|
-
is_expanded:
|
|
265
|
+
is_state_stable: J(),
|
|
266
|
+
is_expanded: J()
|
|
267
267
|
}),
|
|
268
268
|
// TODO: At the moment, macOS has a bug with the invalid event payload - it is always equal to
|
|
269
269
|
// null. Leaving this default value until the bug is fixed.
|
|
@@ -282,14 +282,14 @@ function X(e) {
|
|
|
282
282
|
return;
|
|
283
283
|
let t;
|
|
284
284
|
try {
|
|
285
|
-
t =
|
|
285
|
+
t = B(T(U()), e.data);
|
|
286
286
|
} catch {
|
|
287
287
|
return;
|
|
288
288
|
}
|
|
289
289
|
const { eventType: r, eventData: n } = t, a = Fe[r];
|
|
290
290
|
let o;
|
|
291
291
|
try {
|
|
292
|
-
o = a ?
|
|
292
|
+
o = a ? B(a, n) : n;
|
|
293
293
|
} catch (s) {
|
|
294
294
|
return h().forceError(
|
|
295
295
|
[
|
|
@@ -312,7 +312,7 @@ const {
|
|
|
312
312
|
} = I(
|
|
313
313
|
() => {
|
|
314
314
|
const e = window;
|
|
315
|
-
!e.TelegramGameProxy && (e.TelegramGameProxy = {}), q(e.TelegramGameProxy, "receiveEvent",
|
|
315
|
+
!e.TelegramGameProxy && (e.TelegramGameProxy = {}), q(e.TelegramGameProxy, "receiveEvent", W), K(e, "TelegramGameProxy"), !e.VBot && (e.VBot = {}), !e.VBot.WebView && (e.VBot.WebView = {}), q(e.VBot.WebView, "receiveEvent", W), K(e.VBot, "WebView"), q(e, "TelegramGameProxy_receiveEvent", W), window.addEventListener("message", X);
|
|
316
316
|
},
|
|
317
317
|
() => {
|
|
318
318
|
[
|
|
@@ -347,7 +347,7 @@ function k(e, t) {
|
|
|
347
347
|
const r = window, n = JSON.stringify({ eventType: e, eventData: t });
|
|
348
348
|
return j() ? (Ue(n, de()), c.right(void 0)) : ue(r) ? (r.VBotWebviewProxy.postEvent(e, JSON.stringify(t)), c.right(void 0)) : O(w({ external: w({ notify: ne() }) }), r) ? (r.external.notify(n), c.right(void 0)) : c.left(new le());
|
|
349
349
|
}
|
|
350
|
-
function
|
|
350
|
+
function D(e, t, r = {}) {
|
|
351
351
|
const {
|
|
352
352
|
// If no capture function was passed, we capture the first compatible event.
|
|
353
353
|
capture: n = () => !0,
|
|
@@ -372,19 +372,19 @@ function J(e, t, r = {}) {
|
|
|
372
372
|
return p(m[0]);
|
|
373
373
|
const v = (E) => {
|
|
374
374
|
E && p(E[0]);
|
|
375
|
-
},
|
|
375
|
+
}, M = () => {
|
|
376
376
|
o.unsub(v);
|
|
377
377
|
};
|
|
378
|
-
o.sub(v), f.on("finalized",
|
|
378
|
+
o.sub(v), f.on("finalized", M);
|
|
379
379
|
}, r)),
|
|
380
380
|
d.mapBoth(_, _)
|
|
381
381
|
);
|
|
382
382
|
}
|
|
383
383
|
function pt(e, t, r) {
|
|
384
384
|
const { postEvent: n } = r || {};
|
|
385
|
-
return
|
|
385
|
+
return V(
|
|
386
386
|
// @ts-expect-error TypeScript will not be able to handle our overrides here.
|
|
387
|
-
|
|
387
|
+
D(e, t, {
|
|
388
388
|
...r,
|
|
389
389
|
postEvent: n ? (...a) => {
|
|
390
390
|
try {
|
|
@@ -402,17 +402,17 @@ function ct(e, t) {
|
|
|
402
402
|
e,
|
|
403
403
|
t
|
|
404
404
|
);
|
|
405
|
-
return typeof r == "function" ? se.fn(() =>
|
|
405
|
+
return typeof r == "function" ? se.fn(() => V(r)) : r;
|
|
406
406
|
}
|
|
407
407
|
function Ie(e, t) {
|
|
408
408
|
const r = ue(window);
|
|
409
409
|
if (!e)
|
|
410
|
-
return r || l.pipe(
|
|
410
|
+
return r || l.pipe(L(), c.match(() => !1, () => !0));
|
|
411
411
|
if (r)
|
|
412
412
|
return d.right(!0);
|
|
413
413
|
const { timeout: n = 100 } = t || {};
|
|
414
414
|
return l.pipe(
|
|
415
|
-
|
|
415
|
+
D("web_app_request_theme", "theme_changed", { ...t, timeout: n }),
|
|
416
416
|
d.match(
|
|
417
417
|
(a) => Pe.is(a) || le.is(a) ? c.right(!1) : c.left(a),
|
|
418
418
|
() => c.right(!0)
|
|
@@ -444,7 +444,7 @@ function _t({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
|
|
|
444
444
|
o(...s);
|
|
445
445
|
};
|
|
446
446
|
try {
|
|
447
|
-
const p =
|
|
447
|
+
const p = B(T(U()), i);
|
|
448
448
|
t({ name: p.eventType, params: p.eventData }, _);
|
|
449
449
|
} catch {
|
|
450
450
|
_();
|
|
@@ -492,7 +492,7 @@ function ut({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
|
|
|
492
492
|
o(...s);
|
|
493
493
|
};
|
|
494
494
|
try {
|
|
495
|
-
const p =
|
|
495
|
+
const p = B(T(U()), i);
|
|
496
496
|
t({ name: p.eventType, params: p.eventData }, _);
|
|
497
497
|
} catch {
|
|
498
498
|
_();
|
|
@@ -555,8 +555,7 @@ function lt() {
|
|
|
555
555
|
), t = {
|
|
556
556
|
...e,
|
|
557
557
|
send: (r, n) => {
|
|
558
|
-
|
|
559
|
-
window.postMessage(a, window.location.origin || "*");
|
|
558
|
+
W(r, n);
|
|
560
559
|
},
|
|
561
560
|
clear: () => {
|
|
562
561
|
var r;
|
|
@@ -708,9 +707,9 @@ function dt(e, t = "strict") {
|
|
|
708
707
|
};
|
|
709
708
|
return ((n, a) => re(n, e) ? n === "web_app_set_header_color" && O(w({ color: ye() }), a) && !re(n, "color", e) ? r({ version: e, method: n, param: "color" }) : je(n, a) : r({ version: e, method: n }));
|
|
710
709
|
}
|
|
711
|
-
function
|
|
710
|
+
function De(e, t, r, n) {
|
|
712
711
|
return l.pipe(
|
|
713
|
-
|
|
712
|
+
D("web_app_invoke_custom_method", "custom_method_invoked", {
|
|
714
713
|
...n || {},
|
|
715
714
|
params: { method: e, params: t, req_id: r },
|
|
716
715
|
capture: $e(r)
|
|
@@ -721,7 +720,7 @@ function Je(e, t, r, n) {
|
|
|
721
720
|
function mt(e, t, r, n) {
|
|
722
721
|
return se.fn(() => l.pipe(
|
|
723
722
|
// @ts-expect-error TypeScript is unable to determine required override.
|
|
724
|
-
|
|
723
|
+
De(e, t, r, n),
|
|
725
724
|
d.match(
|
|
726
725
|
(a) => {
|
|
727
726
|
throw a;
|
|
@@ -730,7 +729,7 @@ function mt(e, t, r, n) {
|
|
|
730
729
|
)
|
|
731
730
|
)());
|
|
732
731
|
}
|
|
733
|
-
function
|
|
732
|
+
function Je(e, t, r = {}) {
|
|
734
733
|
const {
|
|
735
734
|
// If no capture function was passed, we capture the first compatible event.
|
|
736
735
|
capture: n = () => !0,
|
|
@@ -752,19 +751,19 @@ function De(e, t, r = {}) {
|
|
|
752
751
|
return p(m[0]);
|
|
753
752
|
const v = (E) => {
|
|
754
753
|
E && p(E[0]);
|
|
755
|
-
},
|
|
754
|
+
}, M = () => {
|
|
756
755
|
o.unsub(v);
|
|
757
756
|
};
|
|
758
|
-
o.sub(v), f.on("finalized",
|
|
757
|
+
o.sub(v), f.on("finalized", M);
|
|
759
758
|
}, r)),
|
|
760
759
|
d.mapBoth(_, _)
|
|
761
760
|
);
|
|
762
761
|
}
|
|
763
762
|
function bt(e, t, r) {
|
|
764
763
|
const { postEvent: n } = r || {};
|
|
765
|
-
return
|
|
764
|
+
return V(
|
|
766
765
|
// @ts-expect-error TypeScript will not be able to handle our overrides here.
|
|
767
|
-
|
|
766
|
+
Je(e, t, {
|
|
768
767
|
...r,
|
|
769
768
|
postEvent: n ? (...a) => {
|
|
770
769
|
try {
|
|
@@ -788,7 +787,7 @@ function be(e) {
|
|
|
788
787
|
).split("").map((t) => "%" + ("00" + t.charCodeAt(0).toString(16)).slice(-2)).join("")
|
|
789
788
|
), (t) => t);
|
|
790
789
|
}
|
|
791
|
-
const ht =
|
|
790
|
+
const ht = A(be);
|
|
792
791
|
function ge(e) {
|
|
793
792
|
return btoa(
|
|
794
793
|
encodeURIComponent(e).replace(/%([0-9A-F]{2})/g, (t, r) => String.fromCharCode(parseInt(`0x${r}`)))
|
|
@@ -798,17 +797,17 @@ function Ge(e) {
|
|
|
798
797
|
const t = ge(typeof e == "string" ? e : JSON.stringify(e));
|
|
799
798
|
return t.length > 512 ? c.left(new Error("Value is too long for start parameter")) : c.right(t);
|
|
800
799
|
}
|
|
801
|
-
const yt =
|
|
800
|
+
const yt = A(Ge);
|
|
802
801
|
function vt(e, t) {
|
|
803
|
-
return
|
|
804
|
-
|
|
802
|
+
return V(
|
|
803
|
+
He(
|
|
805
804
|
e,
|
|
806
805
|
// @ts-expect-error TypeScript is unable to detect a correct override.
|
|
807
806
|
typeof t == "function" ? (r) => c.tryCatch(() => t(r), (n) => n) : t
|
|
808
807
|
)
|
|
809
808
|
);
|
|
810
809
|
}
|
|
811
|
-
function
|
|
810
|
+
function He(e, t) {
|
|
812
811
|
return l.pipe(
|
|
813
812
|
be(e),
|
|
814
813
|
c.chain((r) => t ? typeof t == "function" ? t(r) : xe.parse(r) : c.right(r))
|
|
@@ -837,17 +836,17 @@ export {
|
|
|
837
836
|
ht as decodeBase64Url,
|
|
838
837
|
be as decodeBase64UrlFp,
|
|
839
838
|
vt as decodeStartParam,
|
|
840
|
-
|
|
839
|
+
He as decodeStartParamFp,
|
|
841
840
|
kt as deepSnakeToCamelObjKeys,
|
|
842
841
|
ft as defineHostBridge,
|
|
843
842
|
lt as defineWebComponentBridge,
|
|
844
|
-
|
|
843
|
+
W as emitEvent,
|
|
845
844
|
ge as encodeBase64Url,
|
|
846
845
|
wt as getHostBridge,
|
|
847
846
|
ee as getReleaseVersion,
|
|
848
847
|
ue as hasWebviewProxy,
|
|
849
848
|
mt as invokeCustomMethod,
|
|
850
|
-
|
|
849
|
+
De as invokeCustomMethodFp,
|
|
851
850
|
j as isIframe,
|
|
852
851
|
Et as isSafeToCreateStartParam,
|
|
853
852
|
ct as isVBma,
|
|
@@ -863,15 +862,15 @@ export {
|
|
|
863
862
|
b as postMessageImpl,
|
|
864
863
|
bt as request,
|
|
865
864
|
pt as request2,
|
|
866
|
-
|
|
867
|
-
|
|
865
|
+
D as request2Fp,
|
|
866
|
+
Je as requestFp,
|
|
868
867
|
it as resetGlobals,
|
|
869
868
|
rt as retrieveLaunchParams,
|
|
870
869
|
Le as retrieveLaunchParamsFp,
|
|
871
870
|
nt as retrieveRawInitData,
|
|
872
871
|
Me as retrieveRawInitDataFp,
|
|
873
872
|
ot as retrieveRawLaunchParams,
|
|
874
|
-
|
|
873
|
+
L as retrieveRawLaunchParamsFp,
|
|
875
874
|
at as setDebug,
|
|
876
875
|
ut as setLaunchParams,
|
|
877
876
|
st as setTargetOrigin,
|