@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/index.js CHANGED
@@ -1,42 +1,43 @@
1
- import { is as O, looseObject as w, function as X, nullish as y, boolean as U, number as I, string as E, optional as $, unknown as de, parse as L, any as be } from "valibot";
2
- import { throwifyFpFn as C, getStorageValue as he, setStorageValue as Z, createLogger as ge, throwifyAnyEither as A, createCbCollector as ee, BetterTaskEither as te } from "@vbotma/toolkit";
3
- import { createLogger as Pt, deepSnakeToCamelObjKeys as kt } from "@vbotma/toolkit";
4
- import { BetterPromise as re, TimeoutError as ve } from "better-promises";
5
- import { CancelledError as St, TimeoutError as Bt } from "better-promises";
6
- import { function as l, either as c, option as F, taskEither as m, json as ye } from "fp-ts";
7
- import { errorClassWithData as Ee, errorClass as x } from "error-kid";
8
- import { parseLaunchParamsQueryFp as ne, themeParams as Pe, pipeJsonToSchema as oe, miniAppsMessage as ae, serializeLaunchParamsQuery as ke, parseLaunchParamsQuery as xe } from "@vbotma/transformers";
9
- import { signal as h, computed as se } from "@vbotma/signals";
10
- import Se from "mitt";
11
- function ie(e) {
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: X() }) }),
13
+ w({ VBotWebviewProxy: w({ postEvent: re() }) }),
14
14
  e
15
15
  );
16
16
  }
17
- function pe() {
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__ */ x("MethodUnsupportedError", (t, r) => [
25
- `Method "${t}" is unsupported in Mini Apps version ${r}`
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 Ce extends (/* @__PURE__ */ x("MethodParameterUnsupportedError", (t, r, n) => [
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 Ae extends (/* @__PURE__ */ Ee(
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. 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
+ "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 Ve extends (/* @__PURE__ */ x("InvalidLaunchParamsError", (t, r) => [
49
- `Invalid value for launch params: ${t}`,
50
- { cause: r }
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 ce extends (/* @__PURE__ */ x("UnknownEnvError")) {
57
+ class fe extends (/* @__PURE__ */ S("UnknownEnvError")) {
54
58
  }
55
- class Me extends (/* @__PURE__ */ x(
59
+ class Ve extends (/* @__PURE__ */ S(
56
60
  "InvokeCustomMethodError",
57
61
  (t) => [`Server returned error: ${t}`]
58
62
  )) {
59
63
  }
60
- const z = "launchParams";
61
- function G(e) {
64
+ const H = "launchParams";
65
+ function N(e) {
62
66
  return e.replace(/^[^?#]*[?#]/, "").replace(/[?#]/g, "&");
63
67
  }
64
- function We() {
68
+ function Le() {
65
69
  return l.pipe(
66
70
  V(),
67
- c.chainW(ne)
71
+ c.chainW(se)
68
72
  );
69
73
  }
70
- const rt = C(We);
71
- function qe() {
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
- qe(),
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
- [() => G(window.location.href), "window.location.href"],
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 && G(n.name);
104
+ return n && N(n.name);
101
105
  }, "performance navigation entries"],
102
106
  // Finally, try using the session storage.
103
- [() => he(z), "local storage"]
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
- ne(n),
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 Z(z, n), c.right(n);
122
+ return R(H, n), c.right(n);
119
123
  }
120
- return c.left(new Ae(e));
124
+ return c.left(new Ce(e));
121
125
  }
122
- const ot = C(V);
123
- function _e(e, t) {
124
- const r = /* @__PURE__ */ new Map(), n = Se(), a = (o, s, i = !1) => {
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 = (...d) => {
141
- i && _(), o === "*" ? s({ name: d[0], payload: d[1] }) : s(...d);
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 W(e, t) {
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 = h(!1), T = h("https://web.telegram.org"), Le = (e) => {
168
- b().log("Event received:", e);
169
- }, ue = se(B);
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 ? R : Oe)("*", Le));
175
+ e !== B() && (B.set(e), (e ? $ : Oe)("*", qe));
172
176
  }
173
- const fe = se(T);
177
+ const de = ce(I);
174
178
  function st(e) {
175
- T.set(e), b().log("New target origin set", e);
179
+ I.set(e), h().log("New target origin set", e);
176
180
  }
177
- const P = h((...e) => {
181
+ const b = g((...e) => {
178
182
  window.parent.postMessage(...e);
179
- }), b = h(ge("Bridge", {
183
+ }), h = g(Ee("Bridge", {
180
184
  bgColor: "#9147ff",
181
185
  textColor: "white",
182
- shouldLog: ue
186
+ shouldLog: we
183
187
  }));
184
188
  function it() {
185
- Re(), [P, T, fe, B, ue, b].forEach((e) => {
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
- H(e, t, n[1]);
209
+ K(e, t, n[1]);
206
210
  return;
207
211
  }
208
- n.unshift(1), H(e, t, o);
212
+ n.unshift(1), K(e, t, o);
209
213
  }
210
214
  });
211
- le(
215
+ me(
212
216
  e,
213
217
  t,
214
218
  () => s,
215
219
  (i) => n.push(i)
216
220
  );
217
221
  }
218
- function D(e, t) {
222
+ function Q(e, t) {
219
223
  const r = e[t];
220
- le(e, t, () => r, (n) => {
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 le(e, t, r, n) {
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 H(e, t, r) {
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: E(),
245
- data: y(E())
248
+ req_id: P(),
249
+ data: E(P())
246
250
  }),
247
251
  custom_method_invoked: w({
248
- req_id: E(),
249
- result: $(de()),
250
- error: $(E())
252
+ req_id: P(),
253
+ result: J(ge()),
254
+ error: J(P())
251
255
  }),
252
- popup_closed: y(
253
- w({ button_id: y(E(), () => {
256
+ popup_closed: E(
257
+ w({ button_id: E(P(), () => {
254
258
  }) }),
255
259
  {}
256
260
  ),
257
- viewport_changed: y(
261
+ viewport_changed: E(
258
262
  w({
259
- height: I(),
260
- width: y(I(), () => window.innerWidth),
261
- is_state_stable: U(),
262
- is_expanded: U()
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: Pe()
277
+ theme_params: ke()
274
278
  })
275
279
  };
276
- function J(e) {
280
+ function Y(e) {
277
281
  if (e.source !== window.parent)
278
282
  return;
279
283
  let t;
280
284
  try {
281
- t = L(oe(ae()), e.data);
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 ? L(a, n) : n;
292
+ o = a ? A(a, n) : n;
289
293
  } catch (s) {
290
- return b().forceError(
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
- Te(r, o);
305
+ Re(r, o);
302
306
  }
303
307
  const {
304
- on: R,
308
+ on: $,
305
309
  off: Oe,
306
- emit: Te,
307
- clear: Re
308
- } = _e(
310
+ emit: Re,
311
+ clear: Te
312
+ } = le(
309
313
  () => {
310
314
  const e = window;
311
- !e.TelegramGameProxy && (e.TelegramGameProxy = {}), q(e.TelegramGameProxy, "receiveEvent", W), D(e, "TelegramGameProxy"), !e.VBot && (e.VBot = {}), !e.VBot.WebView && (e.VBot.WebView = {}), q(e.VBot.WebView, "receiveEvent", W), D(e.VBot, "WebView"), q(e, "TelegramGameProxy_receiveEvent", W), window.addEventListener("message", J);
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", J);
330
+ }), window.removeEventListener("message", Y);
327
331
  }
328
- ), je = (...e) => P()(...e);
329
- function Ue(e, t) {
332
+ ), Ue = (...e) => b()(...e);
333
+ function je(e, t) {
330
334
  l.pipe(
331
- S(
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 S(e, t) {
342
- b().log("Posting event:", t ? { eventType: e, eventData: t } : { eventType: e });
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 pe() ? (je(n, fe()), c.right(void 0)) : ie(r) ? (r.VBotWebviewProxy.postEvent(e, JSON.stringify(t)), c.right(void 0)) : O(w({ external: w({ notify: X() }) }), r) ? (r.external.notify(n), c.right(void 0)) : c.left(new ce());
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 j(e, t, r = {}) {
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 = S
351
- } = r, o = h(), [s, i] = ee();
354
+ postEvent: a = k
355
+ } = r, o = g(), [s, i] = ne();
352
356
  (Array.isArray(t) ? t : [t]).forEach((p) => {
353
357
  s(
354
- R(p, (u) => {
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
- m.chainW(() => te((p, u, f) => {
366
- const d = o();
367
- if (d)
368
- return p(d[0]);
369
- const g = (v) => {
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
- }, M = () => {
372
- o.unsub(g);
375
+ }, L = () => {
376
+ o.unsub(y);
373
377
  };
374
- o.sub(g), f.on("finalized", M);
378
+ o.sub(y), f.on("finalized", L);
375
379
  }, r)),
376
- m.mapBoth(_, _)
380
+ d.mapBoth(_, _)
377
381
  );
378
382
  }
379
383
  function pt(e, t, r) {
380
384
  const { postEvent: n } = r || {};
381
- return A(
385
+ return C(
382
386
  // @ts-expect-error TypeScript will not be able to handle our overrides here.
383
- j(e, t, {
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
- } : S
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" ? re.fn(() => A(r)) : r;
405
+ return typeof r == "function" ? ae.fn(() => C(r)) : r;
402
406
  }
403
407
  function Ie(e, t) {
404
- const r = ie(window);
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 m.right(!0);
412
+ return d.right(!0);
409
413
  const { timeout: n = 100 } = t || {};
410
414
  return l.pipe(
411
- j("web_app_request_theme", "theme_changed", { ...t, timeout: n }),
412
- m.match(
413
- (a) => ve.is(a) || ce.is(a) ? c.right(!1) : c.left(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
- ke({ ...e, vbWebAppData: void 0 }) + (e.vbWebAppData ? `&vbWebAppData=${encodeURIComponent(e.vbWebAppData.toString())}` : "")
428
+ ie({ ...e, vbWebAppData: void 0 }) + (e.vbWebAppData ? `&vbWebAppData=${encodeURIComponent(e.vbWebAppData.toString())}` : "")
425
429
  );
426
430
  try {
427
- xe(o);
431
+ pe(o);
428
432
  } catch (s) {
429
- throw new Ve(o, s);
433
+ throw new ue(o, s);
430
434
  }
431
- Z("launchParams", o);
435
+ R("launchParams", o);
432
436
  }
433
- if (pe()) {
437
+ if (j()) {
434
438
  if (!t)
435
439
  return;
436
- r && P.reset();
437
- const o = P();
438
- P.set((...s) => {
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 = L(oe(ae()), i);
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
- }, b().log("Environment was mocked by the mockVBotEnv function");
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 = _e(
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(), k === a && (k = void 0);
544
+ n.clear(), x === a && (x = void 0);
493
545
  }
494
546
  };
495
- return k = a, a;
547
+ return x = a, a;
496
548
  }
497
- let k;
498
- function ft() {
499
- if (!k)
549
+ let x;
550
+ function lt() {
551
+ if (!x)
500
552
  throw new Error("HostBridge not initialized. Call defineHostBridge() first.");
501
- return k;
553
+ return x;
502
554
  }
503
555
  function $e(e) {
504
556
  return ({ req_id: t }) => t === e;
505
557
  }
506
- const N = {
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 Q(e, t) {
599
- return Object.keys(N).find((n) => N[n].some((a) => t ? typeof a == "object" && a.method === e && a.param === t : a === e)) || null;
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 K(e) {
653
+ function ee(e) {
602
654
  return e.split(".").map(Number);
603
655
  }
604
656
  function ze(e, t) {
605
- const r = K(e), n = K(t), a = Math.max(r.length, n.length);
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 Y(e, t, r) {
614
- const n = r ? Q(
665
+ function te(e, t, r) {
666
+ const n = r ? Z(
615
667
  e,
616
668
  t
617
- ) : Q(e);
669
+ ) : Z(e);
618
670
  return n ? ze(n, r || t) <= 0 : !1;
619
671
  }
620
- function lt(e, t = "strict") {
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 Ce(a, n.param, o) : new Be(a, o);
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 b().forceWarn(s.message);
677
+ return h().forceWarn(s.message);
626
678
  };
627
- return ((n, a) => Y(n, e) ? n === "web_app_set_header_color" && O(w({ color: be() }), a) && !Y(n, "color", e) ? r({ version: e, method: n, param: "color" }) : Ue(n, a) : r({ version: e, method: n }));
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 Ge(e, t, r, n) {
681
+ function De(e, t, r, n) {
630
682
  return l.pipe(
631
- j("web_app_invoke_custom_method", "custom_method_invoked", {
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
- m.chain(({ result: a, error: o }) => o ? m.left(new Me(o)) : m.right(a))
688
+ d.chain(({ result: a, error: o }) => o ? d.left(new Ve(o)) : d.right(a))
637
689
  );
638
690
  }
639
- function wt(e, t, r, n) {
640
- return re.fn(() => l.pipe(
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
- Ge(e, t, r, n),
643
- m.match(
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 De(e, t, r = {}) {
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 = S
656
- } = r, o = h(), [s, i] = ee();
707
+ postEvent: a = k
708
+ } = r, o = g(), [s, i] = ne();
657
709
  (Array.isArray(t) ? t : [t]).forEach((p) => {
658
710
  s(
659
- R(p, (u) => {
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
- m.chainW(() => te((p, u, f) => {
668
- const d = o();
669
- if (d)
670
- return p(d[0]);
671
- const g = (v) => {
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
- }, M = () => {
674
- o.unsub(g);
725
+ }, L = () => {
726
+ o.unsub(y);
675
727
  };
676
- o.sub(g), f.on("finalized", M);
728
+ o.sub(y), f.on("finalized", L);
677
729
  }, r)),
678
- m.mapBoth(_, _)
730
+ d.mapBoth(_, _)
679
731
  );
680
732
  }
681
733
  function mt(e, t, r) {
682
734
  const { postEvent: n } = r || {};
683
- return A(
735
+ return C(
684
736
  // @ts-expect-error TypeScript will not be able to handle our overrides here.
685
- De(e, t, {
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
- } : S
745
+ } : k
694
746
  })
695
747
  );
696
748
  }
697
- function dt() {
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 we(e) {
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 bt = C(we);
710
- function me(e) {
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 He(e) {
716
- const t = me(typeof e == "string" ? e : JSON.stringify(e));
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 ht = C(He);
720
- function gt(e, t) {
721
- return A(
722
- Je(
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 Je(e, t) {
781
+ function He(e, t) {
730
782
  return l.pipe(
731
- we(e),
732
- c.chain((r) => t ? typeof t == "function" ? t(r) : ye.parse(r) : c.right(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 me(e).length <= 512;
788
+ return he(e).length <= 512;
737
789
  }
738
790
  export {
739
- St as CancelledError,
740
- Ve as InvalidLaunchParamsError,
741
- Me as InvokeCustomMethodFailedError,
742
- Ae as LaunchParamsRetrieveError,
743
- Ce as MethodParameterUnsupportedError,
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
- ce as UnknownEnvError,
747
- dt as applyPolyfills,
798
+ fe as UnknownEnvError,
799
+ bt as applyPolyfills,
748
800
  $e as captureSameReq,
749
801
  ze as compareVersions,
750
- Pt as createLogger,
751
- lt as createPostEvent,
752
- ht as createStartParam,
753
- He as createStartParamFp,
754
- ue as debug,
755
- bt as decodeBase64Url,
756
- we as decodeBase64UrlFp,
757
- gt as decodeStartParam,
758
- Je as decodeStartParamFp,
759
- kt as deepSnakeToCamelObjKeys,
760
- ut as defineHostBridge,
761
- W as emitEvent,
762
- me as encodeBase64Url,
763
- ft as getHostBridge,
764
- Q as getReleaseVersion,
765
- ie as hasWebviewProxy,
766
- wt as invokeCustomMethod,
767
- Ge as invokeCustomMethodFp,
768
- pe as isIframe,
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
- b as logger,
824
+ h as logger,
773
825
  _t as mockVBotEnv,
774
826
  Oe as off,
775
- Re as offAll,
776
- R as on,
777
- Ue as postEvent,
778
- S as postEventFp,
779
- je as postMessage,
780
- P as postMessageImpl,
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
- j as request2Fp,
784
- De as requestFp,
835
+ z as request2Fp,
836
+ Ge as requestFp,
785
837
  it as resetGlobals,
786
838
  rt as retrieveLaunchParams,
787
- We as retrieveLaunchParamsFp,
839
+ Le as retrieveLaunchParamsFp,
788
840
  nt as retrieveRawInitData,
789
- qe as retrieveRawInitDataFp,
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
- Y as supports,
795
- fe as targetOrigin
847
+ te as supports,
848
+ de as targetOrigin
796
849
  };
797
850
  //# sourceMappingURL=index.js.map