@vbotma/bridge 2.2.7 → 2.2.8

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,9 +1,9 @@
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 me, parse as L, any as be } from "valibot";
2
- import { throwifyFpFn as A, getStorageValue as he, setStorageValue as Z, createLogger as ge, throwifyAnyEither as C, createCbCollector as ee, BetterTaskEither as te } from "@vbotma/toolkit";
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
3
  import { createLogger as Pt, deepSnakeToCamelObjKeys as kt } from "@vbotma/toolkit";
4
4
  import { BetterPromise as re, TimeoutError as ve } from "better-promises";
5
5
  import { CancelledError as St, TimeoutError as Bt } from "better-promises";
6
- import { function as l, either as c, option as F, taskEither as d, json as ye } from "fp-ts";
6
+ import { function as l, either as c, option as F, taskEither as m, json as ye } from "fp-ts";
7
7
  import { errorClassWithData as Ee, errorClass as x } from "error-kid";
8
8
  import { parseLaunchParamsQueryFp as ne, themeParams as Pe, pipeJsonToSchema as oe, miniAppsMessage as ae, serializeLaunchParamsQuery as ke, parseLaunchParamsQuery as xe } from "@vbotma/transformers";
9
9
  import { signal as h, computed as se } from "@vbotma/signals";
@@ -25,11 +25,11 @@ class Be extends (/* @__PURE__ */ x("MethodUnsupportedError", (t, r) => [
25
25
  `Method "${t}" is unsupported in Mini Apps version ${r}`
26
26
  ])) {
27
27
  }
28
- class Ae extends (/* @__PURE__ */ x("MethodParameterUnsupportedError", (t, r, n) => [
28
+ class Ce extends (/* @__PURE__ */ x("MethodParameterUnsupportedError", (t, r, n) => [
29
29
  `Parameter "${r}" of "${t}" method is unsupported in Mini Apps version ${n}`
30
30
  ])) {
31
31
  }
32
- class Ce extends (/* @__PURE__ */ Ee(
32
+ class Ae extends (/* @__PURE__ */ Ee(
33
33
  "LaunchParamsRetrieveError",
34
34
  (t) => ({ errors: t }),
35
35
  (t) => [
@@ -45,14 +45,14 @@ class Ce extends (/* @__PURE__ */ Ee(
45
45
  ]
46
46
  )) {
47
47
  }
48
- class Me extends (/* @__PURE__ */ x("InvalidLaunchParamsError", (t, r) => [
48
+ class Ve extends (/* @__PURE__ */ x("InvalidLaunchParamsError", (t, r) => [
49
49
  `Invalid value for launch params: ${t}`,
50
50
  { cause: r }
51
51
  ])) {
52
52
  }
53
53
  class ce extends (/* @__PURE__ */ x("UnknownEnvError")) {
54
54
  }
55
- class Ve extends (/* @__PURE__ */ x(
55
+ class Me extends (/* @__PURE__ */ x(
56
56
  "InvokeCustomMethodError",
57
57
  (t) => [`Server returned error: ${t}`]
58
58
  )) {
@@ -63,14 +63,14 @@ function G(e) {
63
63
  }
64
64
  function We() {
65
65
  return l.pipe(
66
- M(),
66
+ V(),
67
67
  c.chainW(ne)
68
68
  );
69
69
  }
70
- const rt = A(We);
70
+ const rt = C(We);
71
71
  function qe() {
72
72
  return l.pipe(
73
- M(),
73
+ V(),
74
74
  c.map((e) => {
75
75
  const t = new URLSearchParams(e).get("vbWebAppData");
76
76
  return t ? F.some(t) : F.none;
@@ -87,7 +87,7 @@ function nt() {
87
87
  }, (e) => e)
88
88
  );
89
89
  }
90
- function M() {
90
+ function V() {
91
91
  const e = [];
92
92
  for (const [t, r] of [
93
93
  // Try to retrieve launch parameters from the current location. This method
@@ -117,9 +117,9 @@ function M() {
117
117
  }
118
118
  return Z(z, n), c.right(n);
119
119
  }
120
- return c.left(new Ce(e));
120
+ return c.left(new Ae(e));
121
121
  }
122
- const ot = A(M);
122
+ const ot = C(V);
123
123
  function _e(e, t) {
124
124
  const r = /* @__PURE__ */ new Map(), n = Se(), a = (o, s, i = !1) => {
125
125
  const _ = r.get(o) || /* @__PURE__ */ new Map();
@@ -137,8 +137,8 @@ function _e(e, t) {
137
137
  !r.size && e();
138
138
  const _ = () => {
139
139
  a(o, s, i);
140
- }, p = (...m) => {
141
- i && _(), o === "*" ? s({ name: m[0], payload: m[1] }) : s(...m);
140
+ }, p = (...d) => {
141
+ i && _(), o === "*" ? s({ name: d[0], payload: d[1] }) : s(...d);
142
142
  };
143
143
  n.on(o, p);
144
144
  const u = r.get(o) || /* @__PURE__ */ new Map();
@@ -246,7 +246,7 @@ const Fe = {
246
246
  }),
247
247
  custom_method_invoked: w({
248
248
  req_id: E(),
249
- result: $(me()),
249
+ result: $(de()),
250
250
  error: $(E())
251
251
  }),
252
252
  popup_closed: y(
@@ -362,23 +362,23 @@ function j(e, t, r = {}) {
362
362
  const _ = (p) => (i(), p);
363
363
  return l.pipe(
364
364
  async () => a(e, r.params),
365
- d.chainW(() => te((p, u, f) => {
366
- const m = o();
367
- if (m)
368
- return p(m[0]);
365
+ m.chainW(() => te((p, u, f) => {
366
+ const d = o();
367
+ if (d)
368
+ return p(d[0]);
369
369
  const g = (v) => {
370
370
  v && p(v[0]);
371
- }, V = () => {
371
+ }, M = () => {
372
372
  o.unsub(g);
373
373
  };
374
- o.sub(g), f.on("finalized", V);
374
+ o.sub(g), f.on("finalized", M);
375
375
  }, r)),
376
- d.mapBoth(_, _)
376
+ m.mapBoth(_, _)
377
377
  );
378
378
  }
379
379
  function pt(e, t, r) {
380
380
  const { postEvent: n } = r || {};
381
- return C(
381
+ return A(
382
382
  // @ts-expect-error TypeScript will not be able to handle our overrides here.
383
383
  j(e, t, {
384
384
  ...r,
@@ -398,18 +398,18 @@ function ct(e, t) {
398
398
  e,
399
399
  t
400
400
  );
401
- return typeof r == "function" ? re.fn(() => C(r)) : r;
401
+ return typeof r == "function" ? re.fn(() => A(r)) : r;
402
402
  }
403
403
  function Ie(e, t) {
404
404
  const r = ie(window);
405
405
  if (!e)
406
- return r || l.pipe(M(), c.match(() => !1, () => !0));
406
+ return r || l.pipe(V(), c.match(() => !1, () => !0));
407
407
  if (r)
408
- return d.right(!0);
408
+ return m.right(!0);
409
409
  const { timeout: n = 100 } = t || {};
410
410
  return l.pipe(
411
411
  j("web_app_request_theme", "theme_changed", { ...t, timeout: n }),
412
- d.match(
412
+ m.match(
413
413
  (a) => ve.is(a) || ce.is(a) ? c.right(!1) : c.left(a),
414
414
  () => c.right(!0)
415
415
  )
@@ -426,7 +426,7 @@ function _t({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
426
426
  try {
427
427
  xe(o);
428
428
  } catch (s) {
429
- throw new Me(o, s);
429
+ throw new Ve(o, s);
430
430
  }
431
431
  Z("launchParams", o);
432
432
  }
@@ -619,7 +619,7 @@ function Y(e, t, r) {
619
619
  }
620
620
  function lt(e, t = "strict") {
621
621
  const r = typeof t == "function" ? t : (n) => {
622
- const { method: a, version: o } = n, s = "param" in n ? new Ae(a, n.param, o) : new Be(a, o);
622
+ const { method: a, version: o } = n, s = "param" in n ? new Ce(a, n.param, o) : new Be(a, o);
623
623
  if (t === "strict")
624
624
  throw s;
625
625
  return b().forceWarn(s.message);
@@ -633,14 +633,14 @@ function Ge(e, t, r, n) {
633
633
  params: { method: e, params: t, req_id: r },
634
634
  capture: $e(r)
635
635
  }),
636
- d.chain(({ result: a, error: o }) => o ? d.left(new Ve(o)) : d.right(a))
636
+ m.chain(({ result: a, error: o }) => o ? m.left(new Me(o)) : m.right(a))
637
637
  );
638
638
  }
639
639
  function wt(e, t, r, n) {
640
640
  return re.fn(() => l.pipe(
641
641
  // @ts-expect-error TypeScript is unable to determine required override.
642
642
  Ge(e, t, r, n),
643
- d.match(
643
+ m.match(
644
644
  (a) => {
645
645
  throw a;
646
646
  },
@@ -664,23 +664,23 @@ function De(e, t, r = {}) {
664
664
  const _ = (p) => (i(), p);
665
665
  return l.pipe(
666
666
  async () => a(e, r.params),
667
- d.chainW(() => te((p, u, f) => {
668
- const m = o();
669
- if (m)
670
- return p(m[0]);
667
+ m.chainW(() => te((p, u, f) => {
668
+ const d = o();
669
+ if (d)
670
+ return p(d[0]);
671
671
  const g = (v) => {
672
672
  v && p(v[0]);
673
- }, V = () => {
673
+ }, M = () => {
674
674
  o.unsub(g);
675
675
  };
676
- o.sub(g), f.on("finalized", V);
676
+ o.sub(g), f.on("finalized", M);
677
677
  }, r)),
678
- d.mapBoth(_, _)
678
+ m.mapBoth(_, _)
679
679
  );
680
680
  }
681
- function dt(e, t, r) {
681
+ function mt(e, t, r) {
682
682
  const { postEvent: n } = r || {};
683
- return C(
683
+ return A(
684
684
  // @ts-expect-error TypeScript will not be able to handle our overrides here.
685
685
  De(e, t, {
686
686
  ...r,
@@ -694,7 +694,7 @@ function dt(e, t, r) {
694
694
  })
695
695
  );
696
696
  }
697
- function mt() {
697
+ function dt() {
698
698
  Object.hasOwn || (Object.hasOwn = function(e, t) {
699
699
  return Object.prototype.hasOwnProperty.call(e, t);
700
700
  });
@@ -706,19 +706,19 @@ function we(e) {
706
706
  ).split("").map((t) => "%" + ("00" + t.charCodeAt(0).toString(16)).slice(-2)).join("")
707
707
  ), (t) => t);
708
708
  }
709
- const bt = A(we);
710
- function de(e) {
709
+ const bt = C(we);
710
+ function me(e) {
711
711
  return btoa(
712
712
  encodeURIComponent(e).replace(/%([0-9A-F]{2})/g, (t, r) => String.fromCharCode(parseInt(`0x${r}`)))
713
713
  ).replace(/\+/g, "-").replace(/\//g, "_");
714
714
  }
715
715
  function He(e) {
716
- const t = de(typeof e == "string" ? e : JSON.stringify(e));
716
+ const t = me(typeof e == "string" ? e : JSON.stringify(e));
717
717
  return t.length > 512 ? c.left(new Error("Value is too long for start parameter")) : c.right(t);
718
718
  }
719
- const ht = A(He);
719
+ const ht = C(He);
720
720
  function gt(e, t) {
721
- return C(
721
+ return A(
722
722
  Je(
723
723
  e,
724
724
  // @ts-expect-error TypeScript is unable to detect a correct override.
@@ -733,18 +733,18 @@ function Je(e, t) {
733
733
  );
734
734
  }
735
735
  function vt(e) {
736
- return de(e).length <= 512;
736
+ return me(e).length <= 512;
737
737
  }
738
738
  export {
739
739
  St as CancelledError,
740
- Me as InvalidLaunchParamsError,
741
- Ve as InvokeCustomMethodFailedError,
742
- Ce as LaunchParamsRetrieveError,
743
- Ae as MethodParameterUnsupportedError,
740
+ Ve as InvalidLaunchParamsError,
741
+ Me as InvokeCustomMethodFailedError,
742
+ Ae as LaunchParamsRetrieveError,
743
+ Ce as MethodParameterUnsupportedError,
744
744
  Be as MethodUnsupportedError,
745
745
  Bt as TimeoutError,
746
746
  ce as UnknownEnvError,
747
- mt as applyPolyfills,
747
+ dt as applyPolyfills,
748
748
  $e as captureSameReq,
749
749
  ze as compareVersions,
750
750
  Pt as createLogger,
@@ -759,7 +759,7 @@ export {
759
759
  kt as deepSnakeToCamelObjKeys,
760
760
  ut as defineHostBridge,
761
761
  W as emitEvent,
762
- de as encodeBase64Url,
762
+ me as encodeBase64Url,
763
763
  ft as getHostBridge,
764
764
  Q as getReleaseVersion,
765
765
  ie as hasWebviewProxy,
@@ -767,8 +767,8 @@ export {
767
767
  Ge as invokeCustomMethodFp,
768
768
  pe as isIframe,
769
769
  vt as isSafeToCreateStartParam,
770
- ct as isVBMA,
771
- Ie as isVBMAFp,
770
+ ct as isVBma,
771
+ Ie as isVBmaFp,
772
772
  b as logger,
773
773
  _t as mockVBotEnv,
774
774
  Oe as off,
@@ -778,7 +778,7 @@ export {
778
778
  S as postEventFp,
779
779
  je as postMessage,
780
780
  P as postMessageImpl,
781
- dt as request,
781
+ mt as request,
782
782
  pt as request2,
783
783
  j as request2Fp,
784
784
  De as requestFp,
@@ -788,7 +788,7 @@ export {
788
788
  nt as retrieveRawInitData,
789
789
  qe as retrieveRawInitDataFp,
790
790
  ot as retrieveRawLaunchParams,
791
- M as retrieveRawLaunchParamsFp,
791
+ V as retrieveRawLaunchParamsFp,
792
792
  at as setDebug,
793
793
  st as setTargetOrigin,
794
794
  Y as supports,