@vbotma/bridge 2.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -0
  3. package/dist/dts/applyPolyfills.d.ts +5 -0
  4. package/dist/dts/base64-url.d.ts +24 -0
  5. package/dist/dts/env/hasWebviewProxy.d.ts +10 -0
  6. package/dist/dts/env/isIframe.d.ts +5 -0
  7. package/dist/dts/env/isVBMA.d.ts +31 -0
  8. package/dist/dts/env/mockVBotEnv.d.ts +60 -0
  9. package/dist/dts/errors.d.ts +27 -0
  10. package/dist/dts/events/createEmitter.d.ts +58 -0
  11. package/dist/dts/events/emitEvent.d.ts +33 -0
  12. package/dist/dts/events/emitter.d.ts +2 -0
  13. package/dist/dts/events/types/events.d.ts +780 -0
  14. package/dist/dts/events/types/index.d.ts +3 -0
  15. package/dist/dts/events/types/listening.d.ts +5 -0
  16. package/dist/dts/events/types/misc.d.ts +16 -0
  17. package/dist/dts/globals.d.ts +53 -0
  18. package/dist/dts/index.d.ts +26 -0
  19. package/dist/dts/launch-params.d.ts +31 -0
  20. package/dist/dts/methods/captureSameReq.d.ts +10 -0
  21. package/dist/dts/methods/createPostEvent.d.ts +30 -0
  22. package/dist/dts/methods/getReleaseVersion.d.ts +15 -0
  23. package/dist/dts/methods/postEvent.d.ts +35 -0
  24. package/dist/dts/methods/postMessage.d.ts +7 -0
  25. package/dist/dts/methods/supports.d.ts +15 -0
  26. package/dist/dts/methods/types/custom-method.d.ts +59 -0
  27. package/dist/dts/methods/types/haptic-feedback.d.ts +40 -0
  28. package/dist/dts/methods/types/index.d.ts +7 -0
  29. package/dist/dts/methods/types/methods.d.ts +807 -0
  30. package/dist/dts/methods/types/misc.d.ts +27 -0
  31. package/dist/dts/methods/types/notification.d.ts +20 -0
  32. package/dist/dts/methods/types/popup.d.ts +49 -0
  33. package/dist/dts/methods/types/utils.d.ts +9 -0
  34. package/dist/dts/obj-prop-helpers.d.ts +39 -0
  35. package/dist/dts/start-param.d.ts +52 -0
  36. package/dist/dts/utils/compareVersions.d.ts +10 -0
  37. package/dist/dts/utils/invokeCustomMethod.d.ts +34 -0
  38. package/dist/dts/utils/request.d.ts +102 -0
  39. package/dist/dts/utils/request2.d.ts +62 -0
  40. package/dist/index.cjs +4 -0
  41. package/dist/index.cjs.map +1 -0
  42. package/dist/index.iife.js +4 -0
  43. package/dist/index.iife.js.map +1 -0
  44. package/dist/index.js +758 -0
  45. package/dist/index.js.map +1 -0
  46. package/package.json +54 -0
package/dist/index.js ADDED
@@ -0,0 +1,758 @@
1
+ import { is as L, looseObject as m, function as Y, nullish as v, boolean as j, number as U, string as E, optional as I, unknown as me, parse as B, any as we } from "valibot";
2
+ import { throwifyFpFn as A, getStorageValue as de, setStorageValue as X, createLogger as be, throwifyAnyEither as C, createCbCollector as Z, BetterTaskEither as ee } from "@vbotma/toolkit";
3
+ import { createLogger as yt, deepSnakeToCamelObjKeys as vt } from "@vbotma/toolkit";
4
+ import { BetterPromise as te, TimeoutError as he } from "better-promises";
5
+ import { CancelledError as Pt, TimeoutError as kt } from "better-promises";
6
+ import { function as l, either as c, option as F, taskEither as w, json as ge } from "fp-ts";
7
+ import { errorClassWithData as ye, errorClass as k } from "error-kid";
8
+ import { parseLaunchParamsQueryFp as re, themeParams as ve, pipeJsonToSchema as ne, miniAppsMessage as oe, serializeLaunchParamsQuery as Ee, parseLaunchParamsQuery as Pe } from "@vbotma/transformers";
9
+ import { signal as h, computed as ae } from "@vbotma/signals";
10
+ import ke from "mitt";
11
+ function se(e) {
12
+ return L(
13
+ m({ VBotWebviewProxy: m({ postEvent: Y() }) }),
14
+ e
15
+ );
16
+ }
17
+ function ie() {
18
+ try {
19
+ return window.self !== window.top;
20
+ } catch {
21
+ return !0;
22
+ }
23
+ }
24
+ class xe extends (/* @__PURE__ */ k("MethodUnsupportedError", (t, r) => [
25
+ `Method "${t}" is unsupported in Mini Apps version ${r}`
26
+ ])) {
27
+ }
28
+ class Se extends (/* @__PURE__ */ k("MethodParameterUnsupportedError", (t, r, n) => [
29
+ `Parameter "${r}" of "${t}" method is unsupported in Mini Apps version ${n}`
30
+ ])) {
31
+ }
32
+ class Ae extends (/* @__PURE__ */ ye(
33
+ "LaunchParamsRetrieveError",
34
+ (t) => ({ errors: t }),
35
+ (t) => [
36
+ [
37
+ "Unable to retrieve launch parameters from any known source. Perhaps, you have opened your app outside Telegram?",
38
+ "📖 Refer to docs for more information:",
39
+ "https://docs.vbot-mini-apps.com/packages/tma-js-bridge/environment",
40
+ "",
41
+ "Collected errors:",
42
+ ...t.map(({ source: r, error: n }) => `Source: ${r} / ${n instanceof Error ? n.message : String(n)}`)
43
+ ].join(`
44
+ `)
45
+ ]
46
+ )) {
47
+ }
48
+ class Ce extends (/* @__PURE__ */ k("InvalidLaunchParamsError", (t, r) => [
49
+ `Invalid value for launch params: ${t}`,
50
+ { cause: r }
51
+ ])) {
52
+ }
53
+ class pe extends (/* @__PURE__ */ k("UnknownEnvError")) {
54
+ }
55
+ class Me extends (/* @__PURE__ */ k(
56
+ "InvokeCustomMethodError",
57
+ (t) => [`Server returned error: ${t}`]
58
+ )) {
59
+ }
60
+ const $ = "launchParams";
61
+ function z(e) {
62
+ return e.replace(/^[^?#]*[?#]/, "").replace(/[?#]/g, "&");
63
+ }
64
+ function qe() {
65
+ return l.pipe(
66
+ M(),
67
+ c.chainW(re)
68
+ );
69
+ }
70
+ const tt = A(qe);
71
+ function Ve() {
72
+ return l.pipe(
73
+ M(),
74
+ c.map((e) => {
75
+ const t = new URLSearchParams(e).get("vbWebAppData");
76
+ return t ? F.some(t) : F.none;
77
+ })
78
+ );
79
+ }
80
+ function rt() {
81
+ return l.pipe(
82
+ Ve(),
83
+ c.fold((e) => {
84
+ throw e;
85
+ }, (e) => e),
86
+ F.match(() => {
87
+ }, (e) => e)
88
+ );
89
+ }
90
+ function M() {
91
+ const e = [];
92
+ for (const [t, r] of [
93
+ // Try to retrieve launch parameters from the current location. This method
94
+ // can return nothing in case, location was changed, and then the page was
95
+ // reloaded.
96
+ [() => z(window.location.href), "window.location.href"],
97
+ // Then, try using the lower level API - window.performance.
98
+ [() => {
99
+ const n = performance.getEntriesByType("navigation")[0];
100
+ return n && z(n.name);
101
+ }, "performance navigation entries"],
102
+ // Finally, try using the session storage.
103
+ [() => de($), "local storage"]
104
+ ]) {
105
+ const n = t();
106
+ if (!n) {
107
+ e.push({ source: r, error: new Error("Source is empty") });
108
+ continue;
109
+ }
110
+ const a = l.pipe(
111
+ re(n),
112
+ c.foldW((o) => o, () => !0)
113
+ );
114
+ if (typeof a != "boolean") {
115
+ e.push({ source: r, error: a });
116
+ continue;
117
+ }
118
+ return X($, n), c.right(n);
119
+ }
120
+ return c.left(new Ae(e));
121
+ }
122
+ const nt = A(M);
123
+ function We(e, t) {
124
+ const r = /* @__PURE__ */ new Map(), n = ke(), a = (o, s, p = !1) => {
125
+ const _ = r.get(o) || /* @__PURE__ */ new Map();
126
+ r.set(o, _);
127
+ const i = _.get(s) || [];
128
+ _.set(s, i);
129
+ const u = i.findIndex((f) => f[1] === p);
130
+ if (u >= 0 && (n.off(o, i[u][0]), i.splice(u, 1), !i.length && (_.delete(s), !_.size))) {
131
+ const f = r.size;
132
+ r.delete(o), f && !r.size && t();
133
+ }
134
+ };
135
+ return {
136
+ on(o, s, p) {
137
+ !r.size && e();
138
+ const _ = () => {
139
+ a(o, s, p);
140
+ }, i = (...d) => {
141
+ p && _(), o === "*" ? s({ name: d[0], payload: d[1] }) : s(...d);
142
+ };
143
+ n.on(o, i);
144
+ const u = r.get(o) || /* @__PURE__ */ new Map();
145
+ r.set(o, u);
146
+ const f = u.get(s) || [];
147
+ return u.set(s, f), f.push([i, p || !1]), _;
148
+ },
149
+ off: a,
150
+ // eslint-disable-next-line @typescript-eslint/unbound-method
151
+ emit: n.emit,
152
+ clear() {
153
+ const o = r.size;
154
+ n.all.clear(), r.clear(), o && t();
155
+ }
156
+ };
157
+ }
158
+ function V(e, t) {
159
+ window.dispatchEvent(new MessageEvent("message", {
160
+ data: JSON.stringify({ eventType: e, eventData: t }),
161
+ // We specify this kind of source here in order to allow the package's "on" function to
162
+ // capture it. The reason is this function always checks the event source and relies on
163
+ // it to be the parent window.
164
+ source: window.parent
165
+ }));
166
+ }
167
+ const S = h(!1), T = h("https://web.telegram.org"), Be = (e) => {
168
+ b().log("Event received:", e);
169
+ }, ce = ae(S);
170
+ function ot(e) {
171
+ e !== S() && (S.set(e), (e ? O : Le)("*", Be));
172
+ }
173
+ const _e = ae(T);
174
+ function at(e) {
175
+ T.set(e), b().log("New target origin set", e);
176
+ }
177
+ const P = h((...e) => {
178
+ window.parent.postMessage(...e);
179
+ }), b = h(be("Bridge", {
180
+ bgColor: "#9147ff",
181
+ textColor: "white",
182
+ shouldLog: ce
183
+ }));
184
+ function st() {
185
+ Oe(), [P, T, _e, S, ce, b].forEach((e) => {
186
+ e.unsubAll(), "reset" in e && e.reset();
187
+ });
188
+ }
189
+ function W(e, t, r) {
190
+ const n = [r], a = e[t];
191
+ typeof a == "function" && n.push(a);
192
+ const o = (...p) => {
193
+ n.forEach((_) => _(...p));
194
+ }, s = Object.assign((...p) => {
195
+ o(...p);
196
+ }, {
197
+ // Unwraps the composer.
198
+ unwrap() {
199
+ const { length: p } = n;
200
+ if (p === 1) {
201
+ delete e[t];
202
+ return;
203
+ }
204
+ if (p === 2) {
205
+ D(e, t, n[1]);
206
+ return;
207
+ }
208
+ n.unshift(1), D(e, t, o);
209
+ }
210
+ });
211
+ ue(
212
+ e,
213
+ t,
214
+ () => s,
215
+ (p) => n.push(p)
216
+ );
217
+ }
218
+ function G(e, t) {
219
+ const r = e[t];
220
+ ue(e, t, () => r, (n) => {
221
+ Object.entries(n).forEach(([a, o]) => {
222
+ r[a] = o;
223
+ });
224
+ });
225
+ }
226
+ function ue(e, t, r, n) {
227
+ Object.defineProperty(e, t, {
228
+ enumerable: !0,
229
+ configurable: !0,
230
+ get: r,
231
+ set: n
232
+ });
233
+ }
234
+ function D(e, t, r) {
235
+ Object.defineProperty(e, t, {
236
+ enumerable: !0,
237
+ configurable: !0,
238
+ writable: !0,
239
+ value: r
240
+ });
241
+ }
242
+ const Fe = {
243
+ clipboard_text_received: m({
244
+ req_id: E(),
245
+ data: v(E())
246
+ }),
247
+ custom_method_invoked: m({
248
+ req_id: E(),
249
+ result: I(me()),
250
+ error: I(E())
251
+ }),
252
+ popup_closed: v(
253
+ m({ button_id: v(E(), () => {
254
+ }) }),
255
+ {}
256
+ ),
257
+ viewport_changed: v(
258
+ m({
259
+ height: U(),
260
+ width: v(U(), () => window.innerWidth),
261
+ is_state_stable: j(),
262
+ is_expanded: j()
263
+ }),
264
+ // TODO: At the moment, macOS has a bug with the invalid event payload - it is always equal to
265
+ // null. Leaving this default value until the bug is fixed.
266
+ () => ({
267
+ height: window.innerHeight,
268
+ is_state_stable: !0,
269
+ is_expanded: !0
270
+ })
271
+ ),
272
+ theme_changed: m({
273
+ theme_params: ve()
274
+ })
275
+ };
276
+ function J(e) {
277
+ if (e.source !== window.parent)
278
+ return;
279
+ let t;
280
+ try {
281
+ t = B(ne(oe()), e.data);
282
+ } catch {
283
+ return;
284
+ }
285
+ const { eventType: r, eventData: n } = t, a = Fe[r];
286
+ let o;
287
+ try {
288
+ o = a ? B(a, n) : n;
289
+ } catch (s) {
290
+ return b().forceError(
291
+ [
292
+ `An error occurred processing the "${r}" event from the VBot application.`,
293
+ "Please, file an issue here:",
294
+ "https://github.com/Telegram-Mini-Apps/tma.js/issues/new/choose"
295
+ ].join(`
296
+ `),
297
+ t,
298
+ s
299
+ );
300
+ }
301
+ Te(r, o);
302
+ }
303
+ const {
304
+ on: O,
305
+ off: Le,
306
+ emit: Te,
307
+ clear: Oe
308
+ } = We(
309
+ () => {
310
+ const e = window;
311
+ !e.TelegramGameProxy && (e.TelegramGameProxy = {}), W(e.TelegramGameProxy, "receiveEvent", V), G(e, "TelegramGameProxy"), !e.Telegram && (e.Telegram = {}), !e.VBot.WebView && (e.VBot.WebView = {}), W(e.VBot.WebView, "receiveEvent", V), G(e.Telegram, "WebView"), W(e, "TelegramGameProxy_receiveEvent", V), window.addEventListener("message", J);
312
+ },
313
+ () => {
314
+ [
315
+ ["TelegramGameProxy_receiveEvent"],
316
+ ["TelegramGameProxy", "receiveEvent"],
317
+ ["Telegram", "WebView", "receiveEvent"]
318
+ ].forEach((e) => {
319
+ const t = window;
320
+ let r = [void 0, t];
321
+ for (const o of e)
322
+ if (r = [r[1], r[1][o]], !r[1])
323
+ return;
324
+ const [n, a] = r;
325
+ "unwrap" in a && (a.unwrap(), n && n !== t && !Object.keys(n).length && delete t[e[0]]);
326
+ }), window.removeEventListener("message", J);
327
+ }
328
+ ), Re = (...e) => P()(...e);
329
+ function je(e, t) {
330
+ l.pipe(
331
+ x(
332
+ // @ts-expect-error It's ok, TS can't determine a specific override.
333
+ e,
334
+ t
335
+ ),
336
+ c.mapLeft((r) => {
337
+ throw r;
338
+ })
339
+ );
340
+ }
341
+ function x(e, t) {
342
+ b().log("Posting event:", t ? { eventType: e, eventData: t } : { eventType: e });
343
+ const r = window, n = JSON.stringify({ eventType: e, eventData: t });
344
+ return ie() ? (Re(n, _e()), c.right(void 0)) : se(r) ? (r.VBotWebviewProxy.postEvent(e, JSON.stringify(t)), c.right(void 0)) : L(m({ external: m({ notify: Y() }) }), r) ? (r.external.notify(n), c.right(void 0)) : c.left(new pe());
345
+ }
346
+ function R(e, t, r = {}) {
347
+ const {
348
+ // If no capture function was passed, we capture the first compatible event.
349
+ capture: n = () => !0,
350
+ postEvent: a = x
351
+ } = r, o = h(), [s, p] = Z();
352
+ (Array.isArray(t) ? t : [t]).forEach((i) => {
353
+ s(
354
+ O(i, (u) => {
355
+ const f = Array.isArray(t);
356
+ n(f ? { event: i, payload: u } : u) && o.set([
357
+ f ? { event: i, payload: u } : u
358
+ ]);
359
+ })
360
+ );
361
+ });
362
+ const _ = (i) => (p(), i);
363
+ return l.pipe(
364
+ async () => a(e, r.params),
365
+ w.chainW(() => ee((i, u, f) => {
366
+ const d = o();
367
+ if (d)
368
+ return i(d[0]);
369
+ const g = (y) => {
370
+ y && i(y[0]);
371
+ }, q = () => {
372
+ o.unsub(g);
373
+ };
374
+ o.sub(g), f.on("finalized", q);
375
+ }, r)),
376
+ w.mapBoth(_, _)
377
+ );
378
+ }
379
+ function it(e, t, r) {
380
+ const { postEvent: n } = r || {};
381
+ return C(
382
+ // @ts-expect-error TypeScript will not be able to handle our overrides here.
383
+ R(e, t, {
384
+ ...r,
385
+ postEvent: n ? (...a) => {
386
+ try {
387
+ return n(...a), c.right(void 0);
388
+ } catch (o) {
389
+ return c.left(o);
390
+ }
391
+ } : x
392
+ })
393
+ );
394
+ }
395
+ function pt(e, t) {
396
+ const r = Ue(
397
+ // @ts-expect-error TS doesn't get what override we are going to use.
398
+ e,
399
+ t
400
+ );
401
+ return typeof r == "function" ? te.fn(() => C(r)) : r;
402
+ }
403
+ function Ue(e, t) {
404
+ const r = se(window);
405
+ if (!e)
406
+ return r || l.pipe(M(), c.match(() => !1, () => !0));
407
+ if (r)
408
+ return w.right(!0);
409
+ const { timeout: n = 100 } = t || {};
410
+ return l.pipe(
411
+ R("web_app_request_theme", "theme_changed", { ...t, timeout: n }),
412
+ w.match(
413
+ (a) => he.is(a) || pe.is(a) ? c.right(!1) : c.left(a),
414
+ () => c.right(!0)
415
+ )
416
+ );
417
+ }
418
+ function ct({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
419
+ if (e) {
420
+ const o = typeof e == "string" || e instanceof URLSearchParams ? e.toString() : (
421
+ // Here we have to trick serializeLaunchParamsQuery into thinking, it serializes a valid
422
+ // value. We are doing it because we are working with vbWebAppData presented as a
423
+ // string, not an object as serializeLaunchParamsQuery requires.
424
+ Ee({ ...e, vbWebAppData: void 0 }) + (e.vbWebAppData ? `&vbWebAppData=${encodeURIComponent(e.vbWebAppData.toString())}` : "")
425
+ );
426
+ try {
427
+ Pe(o);
428
+ } catch (s) {
429
+ throw new Ce(o, s);
430
+ }
431
+ X("launchParams", o);
432
+ }
433
+ if (ie()) {
434
+ if (!t)
435
+ return;
436
+ r && P.reset();
437
+ const o = P();
438
+ P.set((...s) => {
439
+ const [p] = s, _ = () => {
440
+ o(...s);
441
+ };
442
+ try {
443
+ const i = B(ne(oe()), p);
444
+ t({ name: i.eventType, params: i.eventData }, _);
445
+ } catch {
446
+ _();
447
+ }
448
+ });
449
+ return;
450
+ }
451
+ const n = window.VBotWebviewProxy || {}, a = n.postEvent || (() => {
452
+ });
453
+ window.VBotWebviewProxy = {
454
+ ...n,
455
+ postEvent(o, s) {
456
+ const p = () => {
457
+ a(o, s);
458
+ };
459
+ t ? t({
460
+ name: o,
461
+ params: s ? JSON.parse(s) : void 0
462
+ }, p) : p();
463
+ }
464
+ }, b().log("Environment was mocked by the mockVBotEnv function");
465
+ }
466
+ function Ie(e) {
467
+ return ({ req_id: t }) => t === e;
468
+ }
469
+ const N = {
470
+ "6.0": [
471
+ "iframe_ready",
472
+ "iframe_will_reload",
473
+ "web_app_close",
474
+ "web_app_data_send",
475
+ "web_app_expand",
476
+ "web_app_open_link",
477
+ "web_app_ready",
478
+ "web_app_request_theme",
479
+ "web_app_request_viewport",
480
+ "web_app_setup_main_button",
481
+ "web_app_setup_closing_behavior"
482
+ ],
483
+ 6.1: [
484
+ "web_app_open_tg_link",
485
+ "web_app_open_invoice",
486
+ "web_app_setup_back_button",
487
+ "web_app_set_background_color",
488
+ "web_app_set_header_color",
489
+ "web_app_trigger_haptic_feedback"
490
+ ],
491
+ 6.2: ["web_app_open_popup"],
492
+ 6.4: [
493
+ "web_app_close_scan_qr_popup",
494
+ "web_app_open_scan_qr_popup",
495
+ "web_app_read_text_from_clipboard",
496
+ { method: "web_app_open_link", param: "try_instant_view" }
497
+ ],
498
+ 6.7: ["web_app_switch_inline_query"],
499
+ 6.9: [
500
+ "web_app_invoke_custom_method",
501
+ "web_app_request_write_access",
502
+ "web_app_request_phone",
503
+ { method: "web_app_set_header_color", param: "color" }
504
+ ],
505
+ "6.10": ["web_app_setup_settings_button"],
506
+ 7.2: [
507
+ "web_app_biometry_get_info",
508
+ "web_app_biometry_open_settings",
509
+ "web_app_biometry_request_access",
510
+ "web_app_biometry_request_auth",
511
+ "web_app_biometry_update_token"
512
+ ],
513
+ 7.6: [
514
+ { method: "web_app_open_link", param: "try_browser" },
515
+ { method: "web_app_close", param: "return_back" }
516
+ ],
517
+ 7.7: ["web_app_setup_swipe_behavior"],
518
+ 7.8: ["web_app_share_to_story"],
519
+ "7.10": [
520
+ "web_app_setup_secondary_button",
521
+ "web_app_set_bottom_bar_color",
522
+ { method: "web_app_setup_main_button", param: "has_shine_effect" }
523
+ ],
524
+ "8.0": [
525
+ "web_app_request_safe_area",
526
+ "web_app_request_content_safe_area",
527
+ "web_app_request_fullscreen",
528
+ "web_app_exit_fullscreen",
529
+ "web_app_set_emoji_status",
530
+ "web_app_add_to_home_screen",
531
+ "web_app_check_home_screen",
532
+ "web_app_request_emoji_status_access",
533
+ "web_app_check_location",
534
+ "web_app_open_location_settings",
535
+ "web_app_request_file_download",
536
+ "web_app_request_location",
537
+ "web_app_send_prepared_message",
538
+ "web_app_start_accelerometer",
539
+ "web_app_start_device_orientation",
540
+ "web_app_start_gyroscope",
541
+ "web_app_stop_accelerometer",
542
+ "web_app_stop_device_orientation",
543
+ "web_app_stop_gyroscope",
544
+ "web_app_toggle_orientation_lock"
545
+ ],
546
+ "9.0": [
547
+ "web_app_device_storage_clear",
548
+ "web_app_device_storage_get_key",
549
+ "web_app_device_storage_save_key",
550
+ "web_app_secure_storage_clear",
551
+ "web_app_secure_storage_get_key",
552
+ "web_app_secure_storage_restore_key",
553
+ "web_app_secure_storage_save_key"
554
+ ],
555
+ 9.1: ["web_app_hide_keyboard"],
556
+ 9.2: [
557
+ "web_app_send_notification",
558
+ "web_app_finish_refresh"
559
+ ]
560
+ };
561
+ function Q(e, t) {
562
+ return Object.keys(N).find((n) => N[n].some((a) => t ? typeof a == "object" && a.method === e && a.param === t : a === e)) || null;
563
+ }
564
+ function H(e) {
565
+ return e.split(".").map(Number);
566
+ }
567
+ function $e(e, t) {
568
+ const r = H(e), n = H(t), a = Math.max(r.length, n.length);
569
+ for (let o = 0; o < a; o += 1) {
570
+ const s = r[o] || 0, p = n[o] || 0;
571
+ if (s !== p)
572
+ return s > p ? 1 : -1;
573
+ }
574
+ return 0;
575
+ }
576
+ function K(e, t, r) {
577
+ const n = r ? Q(
578
+ e,
579
+ t
580
+ ) : Q(e);
581
+ return n ? $e(n, r || t) <= 0 : !1;
582
+ }
583
+ function _t(e, t = "strict") {
584
+ const r = typeof t == "function" ? t : (n) => {
585
+ const { method: a, version: o } = n, s = "param" in n ? new Se(a, n.param, o) : new xe(a, o);
586
+ if (t === "strict")
587
+ throw s;
588
+ return b().forceWarn(s.message);
589
+ };
590
+ return ((n, a) => K(n, e) ? n === "web_app_set_header_color" && L(m({ color: we() }), a) && !K(n, "color", e) ? r({ version: e, method: n, param: "color" }) : je(n, a) : r({ version: e, method: n }));
591
+ }
592
+ function ze(e, t, r, n) {
593
+ return l.pipe(
594
+ R("web_app_invoke_custom_method", "custom_method_invoked", {
595
+ ...n || {},
596
+ params: { method: e, params: t, req_id: r },
597
+ capture: Ie(r)
598
+ }),
599
+ w.chain(({ result: a, error: o }) => o ? w.left(new Me(o)) : w.right(a))
600
+ );
601
+ }
602
+ function ut(e, t, r, n) {
603
+ return te.fn(() => l.pipe(
604
+ // @ts-expect-error TypeScript is unable to determine required override.
605
+ ze(e, t, r, n),
606
+ w.match(
607
+ (a) => {
608
+ throw a;
609
+ },
610
+ (a) => a
611
+ )
612
+ )());
613
+ }
614
+ function Ge(e, t, r = {}) {
615
+ const {
616
+ // If no capture function was passed, we capture the first compatible event.
617
+ capture: n = () => !0,
618
+ postEvent: a = x
619
+ } = r, o = h(), [s, p] = Z();
620
+ (Array.isArray(t) ? t : [t]).forEach((i) => {
621
+ s(
622
+ O(i, (u) => {
623
+ (Array.isArray(t) ? n({ event: i, payload: u }) : n(u)) && o.set([u]);
624
+ })
625
+ );
626
+ });
627
+ const _ = (i) => (p(), i);
628
+ return l.pipe(
629
+ async () => a(e, r.params),
630
+ w.chainW(() => ee((i, u, f) => {
631
+ const d = o();
632
+ if (d)
633
+ return i(d[0]);
634
+ const g = (y) => {
635
+ y && i(y[0]);
636
+ }, q = () => {
637
+ o.unsub(g);
638
+ };
639
+ o.sub(g), f.on("finalized", q);
640
+ }, r)),
641
+ w.mapBoth(_, _)
642
+ );
643
+ }
644
+ function ft(e, t, r) {
645
+ const { postEvent: n } = r || {};
646
+ return C(
647
+ // @ts-expect-error TypeScript will not be able to handle our overrides here.
648
+ Ge(e, t, {
649
+ ...r,
650
+ postEvent: n ? (...a) => {
651
+ try {
652
+ return n(...a), c.right(void 0);
653
+ } catch (o) {
654
+ return c.left(o);
655
+ }
656
+ } : x
657
+ })
658
+ );
659
+ }
660
+ function lt() {
661
+ Object.hasOwn || (Object.hasOwn = function(e, t) {
662
+ return Object.prototype.hasOwnProperty.call(e, t);
663
+ });
664
+ }
665
+ function fe(e) {
666
+ return c.tryCatch(() => decodeURIComponent(
667
+ atob(
668
+ e.replace(/-/g, "+").replace(/_/g, "/")
669
+ ).split("").map((t) => "%" + ("00" + t.charCodeAt(0).toString(16)).slice(-2)).join("")
670
+ ), (t) => t);
671
+ }
672
+ const mt = A(fe);
673
+ function le(e) {
674
+ return btoa(
675
+ encodeURIComponent(e).replace(/%([0-9A-F]{2})/g, (t, r) => String.fromCharCode(parseInt(`0x${r}`)))
676
+ ).replace(/\+/g, "-").replace(/\//g, "_");
677
+ }
678
+ function De(e) {
679
+ const t = le(typeof e == "string" ? e : JSON.stringify(e));
680
+ return t.length > 512 ? c.left(new Error("Value is too long for start parameter")) : c.right(t);
681
+ }
682
+ const wt = A(De);
683
+ function dt(e, t) {
684
+ return C(
685
+ Je(
686
+ e,
687
+ // @ts-expect-error TypeScript is unable to detect a correct override.
688
+ typeof t == "function" ? (r) => c.tryCatch(() => t(r), (n) => n) : t
689
+ )
690
+ );
691
+ }
692
+ function Je(e, t) {
693
+ return l.pipe(
694
+ fe(e),
695
+ c.chain((r) => t ? typeof t == "function" ? t(r) : ge.parse(r) : c.right(r))
696
+ );
697
+ }
698
+ function bt(e) {
699
+ return le(e).length <= 512;
700
+ }
701
+ export {
702
+ Pt as CancelledError,
703
+ Ce as InvalidLaunchParamsError,
704
+ Me as InvokeCustomMethodFailedError,
705
+ Ae as LaunchParamsRetrieveError,
706
+ Se as MethodParameterUnsupportedError,
707
+ xe as MethodUnsupportedError,
708
+ kt as TimeoutError,
709
+ pe as UnknownEnvError,
710
+ lt as applyPolyfills,
711
+ Ie as captureSameReq,
712
+ $e as compareVersions,
713
+ yt as createLogger,
714
+ _t as createPostEvent,
715
+ wt as createStartParam,
716
+ De as createStartParamFp,
717
+ ce as debug,
718
+ mt as decodeBase64Url,
719
+ fe as decodeBase64UrlFp,
720
+ dt as decodeStartParam,
721
+ Je as decodeStartParamFp,
722
+ vt as deepSnakeToCamelObjKeys,
723
+ V as emitEvent,
724
+ le as encodeBase64Url,
725
+ Q as getReleaseVersion,
726
+ se as hasWebviewProxy,
727
+ ut as invokeCustomMethod,
728
+ ze as invokeCustomMethodFp,
729
+ ie as isIframe,
730
+ bt as isSafeToCreateStartParam,
731
+ pt as isVBMA,
732
+ Ue as isVBMAFp,
733
+ b as logger,
734
+ ct as mockVBotEnv,
735
+ Le as off,
736
+ Oe as offAll,
737
+ O as on,
738
+ je as postEvent,
739
+ x as postEventFp,
740
+ Re as postMessage,
741
+ P as postMessageImpl,
742
+ ft as request,
743
+ it as request2,
744
+ R as request2Fp,
745
+ Ge as requestFp,
746
+ st as resetGlobals,
747
+ tt as retrieveLaunchParams,
748
+ qe as retrieveLaunchParamsFp,
749
+ rt as retrieveRawInitData,
750
+ Ve as retrieveRawInitDataFp,
751
+ nt as retrieveRawLaunchParams,
752
+ M as retrieveRawLaunchParamsFp,
753
+ ot as setDebug,
754
+ at as setTargetOrigin,
755
+ K as supports,
756
+ _e as targetOrigin
757
+ };
758
+ //# sourceMappingURL=index.js.map