@tma.js/bridge 2.2.4 → 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/dts/methods/types/methods.d.ts +7 -2
- 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 +240 -235
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,41 +1,42 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { createLogger as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
1
|
+
import * as T from "valibot";
|
|
2
|
+
import { looseObject as d, nullish as v, boolean as z, number as V, string as E, optional as B, unknown as we, parse as L, is as O, function as de, any as G } from "valibot";
|
|
3
|
+
import { throwifyFpFn as A, getStorageValue as be, setStorageValue as Z, createLogger as ge, throwifyAnyEither as C, createCbCollector as ee, BetterTaskEither as te } from "@tma.js/toolkit";
|
|
4
|
+
import { createLogger as vt, deepSnakeToCamelObjKeys as Et } from "@tma.js/toolkit";
|
|
5
|
+
import { BetterPromise as re, TimeoutError as he } from "better-promises";
|
|
6
|
+
import { CancelledError as xt, TimeoutError as kt } from "better-promises";
|
|
7
|
+
import { function as l, either as c, option as R, taskEither as f, json as ye } from "fp-ts";
|
|
8
|
+
import { errorClassWithData as ve, errorClass as x } from "error-kid";
|
|
9
|
+
import { parseLaunchParamsQueryFp as ne, themeParams as Ee, pipeJsonToSchema as oe, miniAppsMessage as ae, serializeLaunchParamsQuery as Pe, parseLaunchParamsQuery as xe } from "@tma.js/transformers";
|
|
10
|
+
import { signal as g, computed as se } from "@tma.js/signals";
|
|
10
11
|
import ke from "mitt";
|
|
11
|
-
function
|
|
12
|
-
return
|
|
13
|
-
|
|
14
|
-
e
|
|
12
|
+
function ie(e) {
|
|
13
|
+
return typeof e == "object" && !!e && !Array.isArray(e) && T.is(
|
|
14
|
+
T.looseObject({ TelegramWebviewProxy: T.looseObject({ postEvent: T.function() }) }),
|
|
15
|
+
{ TelegramWebviewProxy: e.TelegramWebviewProxy }
|
|
15
16
|
);
|
|
16
17
|
}
|
|
17
|
-
function
|
|
18
|
+
function pe() {
|
|
18
19
|
try {
|
|
19
20
|
return window.self !== window.top;
|
|
20
21
|
} catch {
|
|
21
22
|
return !0;
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
|
-
class
|
|
25
|
+
class Te extends (/* @__PURE__ */ x({
|
|
25
26
|
name: "MethodUnsupportedError",
|
|
26
27
|
super: (t, r) => [
|
|
27
28
|
`Method "${t}" is unsupported in Mini Apps version ${r}`
|
|
28
29
|
]
|
|
29
30
|
})) {
|
|
30
31
|
}
|
|
31
|
-
class Se extends (/* @__PURE__ */
|
|
32
|
+
class Se extends (/* @__PURE__ */ x({
|
|
32
33
|
name: "MethodParameterUnsupportedError",
|
|
33
34
|
super: (t, r, n) => [
|
|
34
35
|
`Parameter "${r}" of "${t}" method is unsupported in Mini Apps version ${n}`
|
|
35
36
|
]
|
|
36
37
|
})) {
|
|
37
38
|
}
|
|
38
|
-
class
|
|
39
|
+
class Ae extends (/* @__PURE__ */ ve({
|
|
39
40
|
name: "LaunchParamsRetrieveError",
|
|
40
41
|
data: (t) => ({ errors: t }),
|
|
41
42
|
super: (t) => [
|
|
@@ -51,7 +52,7 @@ class Te extends (/* @__PURE__ */ ye({
|
|
|
51
52
|
]
|
|
52
53
|
})) {
|
|
53
54
|
}
|
|
54
|
-
class
|
|
55
|
+
class Ce extends (/* @__PURE__ */ x({
|
|
55
56
|
name: "InvalidLaunchParamsError",
|
|
56
57
|
super: (t, r) => [
|
|
57
58
|
`Invalid value for launch params: ${t}`,
|
|
@@ -59,86 +60,86 @@ class Ae extends (/* @__PURE__ */ k({
|
|
|
59
60
|
]
|
|
60
61
|
})) {
|
|
61
62
|
}
|
|
62
|
-
class
|
|
63
|
+
class ce extends (/* @__PURE__ */ x({ name: "UnknownEnvError" })) {
|
|
63
64
|
}
|
|
64
|
-
class
|
|
65
|
+
class Me extends (/* @__PURE__ */ x({
|
|
65
66
|
name: "InvokeCustomMethodError",
|
|
66
67
|
super: (t) => [`Server returned error: ${t}`]
|
|
67
68
|
})) {
|
|
68
69
|
}
|
|
69
|
-
const
|
|
70
|
-
function
|
|
70
|
+
const D = "launchParams";
|
|
71
|
+
function J(e) {
|
|
71
72
|
return e.replace(/^[^?#]*[?#]/, "").replace(/[?#]/g, "&");
|
|
72
73
|
}
|
|
73
|
-
function
|
|
74
|
-
return
|
|
75
|
-
|
|
76
|
-
c.chainW(
|
|
74
|
+
function We() {
|
|
75
|
+
return l.pipe(
|
|
76
|
+
M(),
|
|
77
|
+
c.chainW(ne)
|
|
77
78
|
);
|
|
78
79
|
}
|
|
79
|
-
const
|
|
80
|
-
function
|
|
81
|
-
return
|
|
82
|
-
|
|
80
|
+
const rt = A(We);
|
|
81
|
+
function je() {
|
|
82
|
+
return l.pipe(
|
|
83
|
+
M(),
|
|
83
84
|
c.map((e) => {
|
|
84
85
|
const t = new URLSearchParams(e).get("tgWebAppData");
|
|
85
|
-
return t ?
|
|
86
|
+
return t ? R.some(t) : R.none;
|
|
86
87
|
})
|
|
87
88
|
);
|
|
88
89
|
}
|
|
89
|
-
function
|
|
90
|
-
return
|
|
91
|
-
|
|
90
|
+
function nt() {
|
|
91
|
+
return l.pipe(
|
|
92
|
+
je(),
|
|
92
93
|
c.fold((e) => {
|
|
93
94
|
throw e;
|
|
94
95
|
}, (e) => e),
|
|
95
|
-
|
|
96
|
+
R.match(() => {
|
|
96
97
|
}, (e) => e)
|
|
97
98
|
);
|
|
98
99
|
}
|
|
99
|
-
function
|
|
100
|
+
function M() {
|
|
100
101
|
const e = [];
|
|
101
102
|
for (const [t, r] of [
|
|
102
103
|
// Try to retrieve launch parameters from the current location. This method
|
|
103
104
|
// can return nothing in case, location was changed, and then the page was
|
|
104
105
|
// reloaded.
|
|
105
|
-
[() =>
|
|
106
|
+
[() => J(window.location.href), "window.location.href"],
|
|
106
107
|
// Then, try using the lower level API - window.performance.
|
|
107
108
|
[() => {
|
|
108
109
|
const n = performance.getEntriesByType("navigation")[0];
|
|
109
|
-
return n &&
|
|
110
|
+
return n && J(n.name);
|
|
110
111
|
}, "performance navigation entries"],
|
|
111
112
|
// Finally, try using the session storage.
|
|
112
|
-
[() =>
|
|
113
|
+
[() => be(D), "local storage"]
|
|
113
114
|
]) {
|
|
114
115
|
const n = t();
|
|
115
116
|
if (!n) {
|
|
116
117
|
e.push({ source: r, error: new Error("Source is empty") });
|
|
117
118
|
continue;
|
|
118
119
|
}
|
|
119
|
-
const a =
|
|
120
|
-
|
|
120
|
+
const a = l.pipe(
|
|
121
|
+
ne(n),
|
|
121
122
|
c.foldW((o) => o, () => !0)
|
|
122
123
|
);
|
|
123
124
|
if (typeof a != "boolean") {
|
|
124
125
|
e.push({ source: r, error: a });
|
|
125
126
|
continue;
|
|
126
127
|
}
|
|
127
|
-
return
|
|
128
|
+
return Z(D, n), c.right(n);
|
|
128
129
|
}
|
|
129
|
-
return c.left(new
|
|
130
|
+
return c.left(new Ae(e));
|
|
130
131
|
}
|
|
131
|
-
const
|
|
132
|
-
function
|
|
132
|
+
const ot = A(M);
|
|
133
|
+
function qe(e, t) {
|
|
133
134
|
const r = /* @__PURE__ */ new Map(), n = ke(), a = (o, s, p = !1) => {
|
|
134
135
|
const _ = r.get(o) || /* @__PURE__ */ new Map();
|
|
135
136
|
r.set(o, _);
|
|
136
137
|
const i = _.get(s) || [];
|
|
137
138
|
_.set(s, i);
|
|
138
|
-
const u = i.findIndex((
|
|
139
|
+
const u = i.findIndex((m) => m[1] === p);
|
|
139
140
|
if (u >= 0 && (n.off(o, i[u][0]), i.splice(u, 1), !i.length && (_.delete(s), !_.size))) {
|
|
140
|
-
const
|
|
141
|
-
r.delete(o),
|
|
141
|
+
const m = r.size;
|
|
142
|
+
r.delete(o), m && !r.size && t();
|
|
142
143
|
}
|
|
143
144
|
};
|
|
144
145
|
return {
|
|
@@ -146,14 +147,14 @@ function We(e, t) {
|
|
|
146
147
|
!r.size && e();
|
|
147
148
|
const _ = () => {
|
|
148
149
|
a(o, s, p);
|
|
149
|
-
}, i = (...
|
|
150
|
-
p && _(), o === "*" ? s({ name:
|
|
150
|
+
}, i = (...w) => {
|
|
151
|
+
p && _(), o === "*" ? s({ name: w[0], payload: w[1] }) : s(...w);
|
|
151
152
|
};
|
|
152
153
|
n.on(o, i);
|
|
153
154
|
const u = r.get(o) || /* @__PURE__ */ new Map();
|
|
154
155
|
r.set(o, u);
|
|
155
|
-
const
|
|
156
|
-
return u.set(s,
|
|
156
|
+
const m = u.get(s) || [];
|
|
157
|
+
return u.set(s, m), m.push([i, p || !1]), _;
|
|
157
158
|
},
|
|
158
159
|
off: a,
|
|
159
160
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
@@ -164,7 +165,7 @@ function We(e, t) {
|
|
|
164
165
|
}
|
|
165
166
|
};
|
|
166
167
|
}
|
|
167
|
-
function
|
|
168
|
+
function j(e, t) {
|
|
168
169
|
window.dispatchEvent(new MessageEvent("message", {
|
|
169
170
|
data: JSON.stringify({ eventType: e, eventData: t }),
|
|
170
171
|
// We specify this kind of source here in order to allow the package's "on" function to
|
|
@@ -173,29 +174,29 @@ function q(e, t) {
|
|
|
173
174
|
source: window.parent
|
|
174
175
|
}));
|
|
175
176
|
}
|
|
176
|
-
const S =
|
|
177
|
-
|
|
178
|
-
},
|
|
179
|
-
function ot(e) {
|
|
180
|
-
e !== S() && (S.set(e), (e ? j : Oe)("*", Fe));
|
|
181
|
-
}
|
|
182
|
-
const _e = ae(R);
|
|
177
|
+
const S = g(!1), U = g("https://web.telegram.org"), Fe = (e) => {
|
|
178
|
+
b().log("Event received:", e);
|
|
179
|
+
}, _e = se(S);
|
|
183
180
|
function at(e) {
|
|
184
|
-
|
|
181
|
+
e !== S() && (S.set(e), (e ? I : Oe)("*", Fe));
|
|
182
|
+
}
|
|
183
|
+
const ue = se(U);
|
|
184
|
+
function st(e) {
|
|
185
|
+
U.set(e), b().log("New target origin set", e);
|
|
185
186
|
}
|
|
186
|
-
const P =
|
|
187
|
+
const P = g((...e) => {
|
|
187
188
|
window.parent.postMessage(...e);
|
|
188
|
-
}),
|
|
189
|
+
}), b = g(ge("Bridge", {
|
|
189
190
|
bgColor: "#9147ff",
|
|
190
191
|
textColor: "white",
|
|
191
|
-
shouldLog:
|
|
192
|
+
shouldLog: _e
|
|
192
193
|
}));
|
|
193
|
-
function
|
|
194
|
-
|
|
194
|
+
function it() {
|
|
195
|
+
Ue(), [P, U, ue, S, _e, b].forEach((e) => {
|
|
195
196
|
e.unsubAll(), "reset" in e && e.reset();
|
|
196
197
|
});
|
|
197
198
|
}
|
|
198
|
-
function
|
|
199
|
+
function q(e, t, r) {
|
|
199
200
|
const n = [r], a = e[t];
|
|
200
201
|
typeof a == "function" && n.push(a);
|
|
201
202
|
const o = (...p) => {
|
|
@@ -211,28 +212,28 @@ function W(e, t, r) {
|
|
|
211
212
|
return;
|
|
212
213
|
}
|
|
213
214
|
if (p === 2) {
|
|
214
|
-
|
|
215
|
+
Q(e, t, n[1]);
|
|
215
216
|
return;
|
|
216
217
|
}
|
|
217
|
-
n.unshift(1),
|
|
218
|
+
n.unshift(1), Q(e, t, o);
|
|
218
219
|
}
|
|
219
220
|
});
|
|
220
|
-
|
|
221
|
+
me(
|
|
221
222
|
e,
|
|
222
223
|
t,
|
|
223
224
|
() => s,
|
|
224
225
|
(p) => n.push(p)
|
|
225
226
|
);
|
|
226
227
|
}
|
|
227
|
-
function
|
|
228
|
+
function N(e, t) {
|
|
228
229
|
const r = e[t];
|
|
229
|
-
|
|
230
|
+
me(e, t, () => r, (n) => {
|
|
230
231
|
Object.entries(n).forEach(([a, o]) => {
|
|
231
232
|
r[a] = o;
|
|
232
233
|
});
|
|
233
234
|
});
|
|
234
235
|
}
|
|
235
|
-
function
|
|
236
|
+
function me(e, t, r, n) {
|
|
236
237
|
Object.defineProperty(e, t, {
|
|
237
238
|
enumerable: !0,
|
|
238
239
|
configurable: !0,
|
|
@@ -240,7 +241,7 @@ function ue(e, t, r, n) {
|
|
|
240
241
|
set: n
|
|
241
242
|
});
|
|
242
243
|
}
|
|
243
|
-
function
|
|
244
|
+
function Q(e, t, r) {
|
|
244
245
|
Object.defineProperty(e, t, {
|
|
245
246
|
enumerable: !0,
|
|
246
247
|
configurable: !0,
|
|
@@ -249,26 +250,26 @@ function D(e, t, r) {
|
|
|
249
250
|
});
|
|
250
251
|
}
|
|
251
252
|
const Le = {
|
|
252
|
-
clipboard_text_received:
|
|
253
|
+
clipboard_text_received: d({
|
|
253
254
|
req_id: E(),
|
|
254
255
|
data: v(E())
|
|
255
256
|
}),
|
|
256
|
-
custom_method_invoked:
|
|
257
|
+
custom_method_invoked: d({
|
|
257
258
|
req_id: E(),
|
|
258
|
-
result:
|
|
259
|
-
error:
|
|
259
|
+
result: B(we()),
|
|
260
|
+
error: B(E())
|
|
260
261
|
}),
|
|
261
262
|
popup_closed: v(
|
|
262
|
-
|
|
263
|
+
d({ button_id: v(E(), () => {
|
|
263
264
|
}) }),
|
|
264
265
|
{}
|
|
265
266
|
),
|
|
266
267
|
viewport_changed: v(
|
|
267
|
-
|
|
268
|
-
height:
|
|
269
|
-
width: v(
|
|
270
|
-
is_state_stable:
|
|
271
|
-
is_expanded:
|
|
268
|
+
d({
|
|
269
|
+
height: V(),
|
|
270
|
+
width: v(V(), () => window.innerWidth),
|
|
271
|
+
is_state_stable: z(),
|
|
272
|
+
is_expanded: z()
|
|
272
273
|
}),
|
|
273
274
|
// TODO: At the moment, macOS has a bug with the invalid event payload - it is always equal to
|
|
274
275
|
// null. Leaving this default value until the bug is fixed.
|
|
@@ -278,25 +279,25 @@ const Le = {
|
|
|
278
279
|
is_expanded: !0
|
|
279
280
|
})
|
|
280
281
|
),
|
|
281
|
-
theme_changed:
|
|
282
|
-
theme_params:
|
|
282
|
+
theme_changed: d({
|
|
283
|
+
theme_params: Ee()
|
|
283
284
|
})
|
|
284
285
|
};
|
|
285
|
-
function
|
|
286
|
+
function H(e) {
|
|
286
287
|
if (e.source !== window.parent)
|
|
287
288
|
return;
|
|
288
289
|
let t;
|
|
289
290
|
try {
|
|
290
|
-
t =
|
|
291
|
+
t = L(oe(ae()), e.data);
|
|
291
292
|
} catch {
|
|
292
293
|
return;
|
|
293
294
|
}
|
|
294
295
|
const { eventType: r, eventData: n } = t, a = Le[r];
|
|
295
296
|
let o;
|
|
296
297
|
try {
|
|
297
|
-
o = a ?
|
|
298
|
+
o = a ? L(a, n) : n;
|
|
298
299
|
} catch (s) {
|
|
299
|
-
return
|
|
300
|
+
return b().forceError(
|
|
300
301
|
[
|
|
301
302
|
`An error occurred processing the "${r}" event from the Telegram application.`,
|
|
302
303
|
"Please, file an issue here:",
|
|
@@ -310,14 +311,14 @@ function J(e) {
|
|
|
310
311
|
Re(r, o);
|
|
311
312
|
}
|
|
312
313
|
const {
|
|
313
|
-
on:
|
|
314
|
+
on: I,
|
|
314
315
|
off: Oe,
|
|
315
316
|
emit: Re,
|
|
316
|
-
clear:
|
|
317
|
-
} =
|
|
317
|
+
clear: Ue
|
|
318
|
+
} = qe(
|
|
318
319
|
() => {
|
|
319
320
|
const e = window;
|
|
320
|
-
!e.TelegramGameProxy && (e.TelegramGameProxy = {}),
|
|
321
|
+
!e.TelegramGameProxy && (e.TelegramGameProxy = {}), q(e.TelegramGameProxy, "receiveEvent", j), N(e, "TelegramGameProxy"), !e.Telegram && (e.Telegram = {}), !e.Telegram.WebView && (e.Telegram.WebView = {}), q(e.Telegram.WebView, "receiveEvent", j), N(e.Telegram, "WebView"), q(e, "TelegramGameProxy_receiveEvent", j), window.addEventListener("message", H);
|
|
321
322
|
},
|
|
322
323
|
() => {
|
|
323
324
|
[
|
|
@@ -332,12 +333,12 @@ const {
|
|
|
332
333
|
return;
|
|
333
334
|
const [n, a] = r;
|
|
334
335
|
"unwrap" in a && (a.unwrap(), n && n !== t && !Object.keys(n).length && delete t[e[0]]);
|
|
335
|
-
}), window.removeEventListener("message",
|
|
336
|
+
}), window.removeEventListener("message", H);
|
|
336
337
|
}
|
|
337
|
-
),
|
|
338
|
-
function
|
|
339
|
-
|
|
340
|
-
|
|
338
|
+
), Ie = (...e) => P()(...e);
|
|
339
|
+
function $e(e, t) {
|
|
340
|
+
l.pipe(
|
|
341
|
+
k(
|
|
341
342
|
// @ts-expect-error It's ok, TS can't determine a specific override.
|
|
342
343
|
e,
|
|
343
344
|
t
|
|
@@ -347,49 +348,49 @@ function Ie(e, t) {
|
|
|
347
348
|
})
|
|
348
349
|
);
|
|
349
350
|
}
|
|
350
|
-
function
|
|
351
|
-
|
|
351
|
+
function k(e, t) {
|
|
352
|
+
b().log("Posting event:", t ? { eventType: e, eventData: t } : { eventType: e });
|
|
352
353
|
const r = window, n = JSON.stringify({ eventType: e, eventData: t });
|
|
353
|
-
return
|
|
354
|
+
return pe() ? (Ie(n, ue()), c.right(void 0)) : ie(r) ? (r.TelegramWebviewProxy.postEvent(e, JSON.stringify(t)), c.right(void 0)) : O(d({ external: d({ notify: de() }) }), r) ? (r.external.notify(n), c.right(void 0)) : c.left(new ce());
|
|
354
355
|
}
|
|
355
|
-
function
|
|
356
|
+
function $(e, t, r = {}) {
|
|
356
357
|
const {
|
|
357
358
|
// If no capture function was passed, we capture the first compatible event.
|
|
358
359
|
capture: n = () => !0,
|
|
359
|
-
postEvent: a =
|
|
360
|
-
} = r, o =
|
|
360
|
+
postEvent: a = k
|
|
361
|
+
} = r, o = g(), [s, p] = ee();
|
|
361
362
|
(Array.isArray(t) ? t : [t]).forEach((i) => {
|
|
362
363
|
s(
|
|
363
|
-
|
|
364
|
-
const
|
|
365
|
-
n(
|
|
366
|
-
|
|
364
|
+
I(i, (u) => {
|
|
365
|
+
const m = Array.isArray(t);
|
|
366
|
+
n(m ? { event: i, payload: u } : u) && o.set([
|
|
367
|
+
m ? { event: i, payload: u } : u
|
|
367
368
|
]);
|
|
368
369
|
})
|
|
369
370
|
);
|
|
370
371
|
});
|
|
371
372
|
const _ = (i) => (p(), i);
|
|
372
|
-
return
|
|
373
|
+
return l.pipe(
|
|
373
374
|
async () => a(e, r.params),
|
|
374
|
-
|
|
375
|
-
const
|
|
376
|
-
if (
|
|
377
|
-
return i(
|
|
375
|
+
f.chainW(() => te((i, u, m) => {
|
|
376
|
+
const w = o();
|
|
377
|
+
if (w)
|
|
378
|
+
return i(w[0]);
|
|
378
379
|
const h = (y) => {
|
|
379
380
|
y && i(y[0]);
|
|
380
|
-
},
|
|
381
|
+
}, W = () => {
|
|
381
382
|
o.unsub(h);
|
|
382
383
|
};
|
|
383
|
-
o.sub(h),
|
|
384
|
+
o.sub(h), m.on("finalized", W);
|
|
384
385
|
}, r)),
|
|
385
|
-
|
|
386
|
+
f.mapBoth(_, _)
|
|
386
387
|
);
|
|
387
388
|
}
|
|
388
|
-
function
|
|
389
|
+
function pt(e, t, r) {
|
|
389
390
|
const { postEvent: n } = r || {};
|
|
390
|
-
return
|
|
391
|
+
return C(
|
|
391
392
|
// @ts-expect-error TypeScript will not be able to handle our overrides here.
|
|
392
|
-
|
|
393
|
+
$(e, t, {
|
|
393
394
|
...r,
|
|
394
395
|
postEvent: n ? (...a) => {
|
|
395
396
|
try {
|
|
@@ -397,49 +398,49 @@ function it(e, t, r) {
|
|
|
397
398
|
} catch (o) {
|
|
398
399
|
return c.left(o);
|
|
399
400
|
}
|
|
400
|
-
} :
|
|
401
|
+
} : k
|
|
401
402
|
})
|
|
402
403
|
);
|
|
403
404
|
}
|
|
404
|
-
function
|
|
405
|
-
const r =
|
|
405
|
+
function ct(e, t) {
|
|
406
|
+
const r = ze(
|
|
406
407
|
// @ts-expect-error TS doesn't get what override we are going to use.
|
|
407
408
|
e,
|
|
408
409
|
t
|
|
409
410
|
);
|
|
410
|
-
return typeof r == "function" ?
|
|
411
|
+
return typeof r == "function" ? re.fn(() => C(r)) : r;
|
|
411
412
|
}
|
|
412
|
-
function
|
|
413
|
-
const r =
|
|
413
|
+
function ze(e, t) {
|
|
414
|
+
const r = ie(window);
|
|
414
415
|
if (!e)
|
|
415
|
-
return r ||
|
|
416
|
+
return r || l.pipe(M(), c.match(() => !1, () => !0));
|
|
416
417
|
if (r)
|
|
417
|
-
return
|
|
418
|
+
return f.right(!0);
|
|
418
419
|
const { timeout: n = 100 } = t || {};
|
|
419
|
-
return
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
(a) =>
|
|
420
|
+
return l.pipe(
|
|
421
|
+
$("web_app_request_theme", "theme_changed", { ...t, timeout: n }),
|
|
422
|
+
f.match(
|
|
423
|
+
(a) => he.is(a) || ce.is(a) ? c.right(!1) : c.left(a),
|
|
423
424
|
() => c.right(!0)
|
|
424
425
|
)
|
|
425
426
|
);
|
|
426
427
|
}
|
|
427
|
-
function
|
|
428
|
+
function _t({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
|
|
428
429
|
if (e) {
|
|
429
430
|
const o = typeof e == "string" || e instanceof URLSearchParams ? e.toString() : (
|
|
430
431
|
// Here we have to trick serializeLaunchParamsQuery into thinking, it serializes a valid
|
|
431
432
|
// value. We are doing it because we are working with tgWebAppData presented as a
|
|
432
433
|
// string, not an object as serializeLaunchParamsQuery requires.
|
|
433
|
-
|
|
434
|
+
Pe({ ...e, tgWebAppData: void 0 }) + (e.tgWebAppData ? `&tgWebAppData=${encodeURIComponent(e.tgWebAppData.toString())}` : "")
|
|
434
435
|
);
|
|
435
436
|
try {
|
|
436
|
-
|
|
437
|
+
xe(o);
|
|
437
438
|
} catch (s) {
|
|
438
|
-
throw new
|
|
439
|
+
throw new Ce(o, s);
|
|
439
440
|
}
|
|
440
|
-
|
|
441
|
+
Z("launchParams", o);
|
|
441
442
|
}
|
|
442
|
-
if (
|
|
443
|
+
if (pe()) {
|
|
443
444
|
if (!t)
|
|
444
445
|
return;
|
|
445
446
|
r && P.reset();
|
|
@@ -449,7 +450,7 @@ function ct({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
|
|
|
449
450
|
o(...s);
|
|
450
451
|
};
|
|
451
452
|
try {
|
|
452
|
-
const i =
|
|
453
|
+
const i = L(oe(ae()), p);
|
|
453
454
|
t({ name: i.eventType, params: i.eventData }, _);
|
|
454
455
|
} catch {
|
|
455
456
|
_();
|
|
@@ -470,12 +471,12 @@ function ct({ launchParams: e, onEvent: t, resetPostMessage: r } = {}) {
|
|
|
470
471
|
params: s ? JSON.parse(s) : void 0
|
|
471
472
|
}, p) : p();
|
|
472
473
|
}
|
|
473
|
-
},
|
|
474
|
+
}, b().log("Environment was mocked by the mockTelegramEnv function");
|
|
474
475
|
}
|
|
475
|
-
function
|
|
476
|
+
function Ve(e) {
|
|
476
477
|
return ({ req_id: t }) => t === e;
|
|
477
478
|
}
|
|
478
|
-
const
|
|
479
|
+
const K = {
|
|
479
480
|
"6.0": [
|
|
480
481
|
"iframe_ready",
|
|
481
482
|
"iframe_will_reload",
|
|
@@ -561,16 +562,20 @@ const N = {
|
|
|
561
562
|
"web_app_secure_storage_restore_key",
|
|
562
563
|
"web_app_secure_storage_save_key"
|
|
563
564
|
],
|
|
564
|
-
9.1: ["web_app_hide_keyboard"]
|
|
565
|
+
9.1: ["web_app_hide_keyboard"],
|
|
566
|
+
9.5: [
|
|
567
|
+
{ method: "web_app_setup_main_button", param: "icon_custom_emoji_id" },
|
|
568
|
+
{ method: "web_app_setup_secondary_button", param: "icon_custom_emoji_id" }
|
|
569
|
+
]
|
|
565
570
|
};
|
|
566
|
-
function
|
|
567
|
-
return Object.keys(
|
|
571
|
+
function Y(e, t) {
|
|
572
|
+
return Object.keys(K).find((n) => K[n].some((a) => t ? typeof a == "object" && a.method === e && a.param === t : a === e)) || null;
|
|
568
573
|
}
|
|
569
|
-
function
|
|
574
|
+
function X(e) {
|
|
570
575
|
return e.split(".").map(Number);
|
|
571
576
|
}
|
|
572
|
-
function
|
|
573
|
-
const r =
|
|
577
|
+
function Be(e, t) {
|
|
578
|
+
const r = X(e), n = X(t), a = Math.max(r.length, n.length);
|
|
574
579
|
for (let o = 0; o < a; o += 1) {
|
|
575
580
|
const s = r[o] || 0, p = n[o] || 0;
|
|
576
581
|
if (s !== p)
|
|
@@ -578,37 +583,37 @@ function Ve(e, t) {
|
|
|
578
583
|
}
|
|
579
584
|
return 0;
|
|
580
585
|
}
|
|
581
|
-
function
|
|
582
|
-
const n = r ?
|
|
586
|
+
function F(e, t, r) {
|
|
587
|
+
const n = r ? Y(
|
|
583
588
|
e,
|
|
584
589
|
t
|
|
585
|
-
) :
|
|
586
|
-
return n ?
|
|
590
|
+
) : Y(e);
|
|
591
|
+
return n ? Be(n, r || t) <= 0 : !1;
|
|
587
592
|
}
|
|
588
|
-
function
|
|
593
|
+
function ut(e, t = "strict") {
|
|
589
594
|
const r = typeof t == "function" ? t : (n) => {
|
|
590
|
-
const { method: a, version: o } = n, s = "param" in n ? new Se(a, n.param, o) : new
|
|
595
|
+
const { method: a, version: o } = n, s = "param" in n ? new Se(a, n.param, o) : new Te(a, o);
|
|
591
596
|
if (t === "strict")
|
|
592
597
|
throw s;
|
|
593
|
-
return
|
|
598
|
+
return b().forceWarn(s.message);
|
|
594
599
|
};
|
|
595
|
-
return (n, a) =>
|
|
600
|
+
return (n, a) => F(n, e) ? n === "web_app_set_header_color" && O(d({ color: G() }), a) && !F(n, "color", e) ? r({ version: e, method: n, param: "color" }) : (n === "web_app_setup_main_button" || n === "web_app_setup_secondary_button") && O(d({ icon_custom_emoji_id: G() }), a) && !F(n, "icon_custom_emoji_id", e) ? r({ version: e, method: n, param: "icon_custom_emoji_id" }) : $e(n, a) : r({ version: e, method: n });
|
|
596
601
|
}
|
|
597
|
-
function
|
|
598
|
-
return
|
|
599
|
-
|
|
602
|
+
function Ge(e, t, r, n) {
|
|
603
|
+
return l.pipe(
|
|
604
|
+
$("web_app_invoke_custom_method", "custom_method_invoked", {
|
|
600
605
|
...n || {},
|
|
601
606
|
params: { method: e, params: t, req_id: r },
|
|
602
|
-
capture:
|
|
607
|
+
capture: Ve(r)
|
|
603
608
|
}),
|
|
604
|
-
|
|
609
|
+
f.chain(({ result: a, error: o }) => o ? f.left(new Me(o)) : f.right(a))
|
|
605
610
|
);
|
|
606
611
|
}
|
|
607
|
-
function
|
|
608
|
-
return
|
|
612
|
+
function mt(e, t, r, n) {
|
|
613
|
+
return re.fn(() => l.pipe(
|
|
609
614
|
// @ts-expect-error TypeScript is unable to determine required override.
|
|
610
|
-
|
|
611
|
-
|
|
615
|
+
Ge(e, t, r, n),
|
|
616
|
+
f.match(
|
|
612
617
|
(a) => {
|
|
613
618
|
throw a;
|
|
614
619
|
},
|
|
@@ -616,41 +621,41 @@ function ut(e, t, r, n) {
|
|
|
616
621
|
)
|
|
617
622
|
)());
|
|
618
623
|
}
|
|
619
|
-
function
|
|
624
|
+
function De(e, t, r = {}) {
|
|
620
625
|
const {
|
|
621
626
|
// If no capture function was passed, we capture the first compatible event.
|
|
622
627
|
capture: n = () => !0,
|
|
623
|
-
postEvent: a =
|
|
624
|
-
} = r, o =
|
|
628
|
+
postEvent: a = k
|
|
629
|
+
} = r, o = g(), [s, p] = ee();
|
|
625
630
|
(Array.isArray(t) ? t : [t]).forEach((i) => {
|
|
626
631
|
s(
|
|
627
|
-
|
|
632
|
+
I(i, (u) => {
|
|
628
633
|
(Array.isArray(t) ? n({ event: i, payload: u }) : n(u)) && o.set([u]);
|
|
629
634
|
})
|
|
630
635
|
);
|
|
631
636
|
});
|
|
632
637
|
const _ = (i) => (p(), i);
|
|
633
|
-
return
|
|
638
|
+
return l.pipe(
|
|
634
639
|
async () => a(e, r.params),
|
|
635
|
-
|
|
636
|
-
const
|
|
637
|
-
if (
|
|
638
|
-
return i(
|
|
640
|
+
f.chainW(() => te((i, u, m) => {
|
|
641
|
+
const w = o();
|
|
642
|
+
if (w)
|
|
643
|
+
return i(w[0]);
|
|
639
644
|
const h = (y) => {
|
|
640
645
|
y && i(y[0]);
|
|
641
|
-
},
|
|
646
|
+
}, W = () => {
|
|
642
647
|
o.unsub(h);
|
|
643
648
|
};
|
|
644
|
-
o.sub(h),
|
|
649
|
+
o.sub(h), m.on("finalized", W);
|
|
645
650
|
}, r)),
|
|
646
|
-
|
|
651
|
+
f.mapBoth(_, _)
|
|
647
652
|
);
|
|
648
653
|
}
|
|
649
654
|
function lt(e, t, r) {
|
|
650
655
|
const { postEvent: n } = r || {};
|
|
651
|
-
return
|
|
656
|
+
return C(
|
|
652
657
|
// @ts-expect-error TypeScript will not be able to handle our overrides here.
|
|
653
|
-
|
|
658
|
+
De(e, t, {
|
|
654
659
|
...r,
|
|
655
660
|
postEvent: n ? (...a) => {
|
|
656
661
|
try {
|
|
@@ -658,7 +663,7 @@ function lt(e, t, r) {
|
|
|
658
663
|
} catch (o) {
|
|
659
664
|
return c.left(o);
|
|
660
665
|
}
|
|
661
|
-
} :
|
|
666
|
+
} : k
|
|
662
667
|
})
|
|
663
668
|
);
|
|
664
669
|
}
|
|
@@ -674,90 +679,90 @@ function le(e) {
|
|
|
674
679
|
).split("").map((t) => "%" + ("00" + t.charCodeAt(0).toString(16)).slice(-2)).join("")
|
|
675
680
|
), (t) => t);
|
|
676
681
|
}
|
|
677
|
-
const
|
|
682
|
+
const wt = A(le);
|
|
678
683
|
function fe(e) {
|
|
679
684
|
return btoa(
|
|
680
685
|
encodeURIComponent(e).replace(/%([0-9A-F]{2})/g, (t, r) => String.fromCharCode(parseInt(`0x${r}`)))
|
|
681
686
|
).replace(/\+/g, "-").replace(/\//g, "_");
|
|
682
687
|
}
|
|
683
|
-
function
|
|
688
|
+
function Je(e) {
|
|
684
689
|
const t = fe(typeof e == "string" ? e : JSON.stringify(e));
|
|
685
690
|
return t.length > 512 ? c.left(new Error("Value is too long for start parameter")) : c.right(t);
|
|
686
691
|
}
|
|
687
|
-
const
|
|
688
|
-
function
|
|
689
|
-
return
|
|
690
|
-
|
|
692
|
+
const dt = A(Je);
|
|
693
|
+
function bt(e, t) {
|
|
694
|
+
return C(
|
|
695
|
+
Ne(
|
|
691
696
|
e,
|
|
692
697
|
// @ts-expect-error TypeScript is unable to detect a correct override.
|
|
693
698
|
typeof t == "function" ? (r) => c.tryCatch(() => t(r), (n) => n) : t
|
|
694
699
|
)
|
|
695
700
|
);
|
|
696
701
|
}
|
|
697
|
-
function
|
|
698
|
-
return
|
|
702
|
+
function Ne(e, t) {
|
|
703
|
+
return l.pipe(
|
|
699
704
|
le(e),
|
|
700
|
-
c.chain((r) => t ? typeof t == "function" ? t(r) :
|
|
705
|
+
c.chain((r) => t ? typeof t == "function" ? t(r) : ye.parse(r) : c.right(r))
|
|
701
706
|
);
|
|
702
707
|
}
|
|
703
708
|
function gt(e) {
|
|
704
709
|
return fe(e).length <= 512;
|
|
705
710
|
}
|
|
706
711
|
export {
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
712
|
+
xt as CancelledError,
|
|
713
|
+
Ce as InvalidLaunchParamsError,
|
|
714
|
+
Me as InvokeCustomMethodFailedError,
|
|
715
|
+
Ae as LaunchParamsRetrieveError,
|
|
711
716
|
Se as MethodParameterUnsupportedError,
|
|
712
|
-
|
|
717
|
+
Te as MethodUnsupportedError,
|
|
713
718
|
kt as TimeoutError,
|
|
714
|
-
|
|
719
|
+
ce as UnknownEnvError,
|
|
715
720
|
ft as applyPolyfills,
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
721
|
+
Ve as captureSameReq,
|
|
722
|
+
Be as compareVersions,
|
|
723
|
+
vt as createLogger,
|
|
724
|
+
ut as createPostEvent,
|
|
725
|
+
dt as createStartParam,
|
|
726
|
+
Je as createStartParamFp,
|
|
727
|
+
_e as debug,
|
|
728
|
+
wt as decodeBase64Url,
|
|
724
729
|
le as decodeBase64UrlFp,
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
730
|
+
bt as decodeStartParam,
|
|
731
|
+
Ne as decodeStartParamFp,
|
|
732
|
+
Et as deepSnakeToCamelObjKeys,
|
|
733
|
+
j as emitEvent,
|
|
729
734
|
fe as encodeBase64Url,
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
+
Y as getReleaseVersion,
|
|
736
|
+
ie as hasWebviewProxy,
|
|
737
|
+
mt as invokeCustomMethod,
|
|
738
|
+
Ge as invokeCustomMethodFp,
|
|
739
|
+
pe as isIframe,
|
|
735
740
|
gt as isSafeToCreateStartParam,
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
741
|
+
ct as isTMA,
|
|
742
|
+
ze as isTMAFp,
|
|
743
|
+
b as logger,
|
|
744
|
+
_t as mockTelegramEnv,
|
|
740
745
|
Oe as off,
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
+
Ue as offAll,
|
|
747
|
+
I as on,
|
|
748
|
+
$e as postEvent,
|
|
749
|
+
k as postEventFp,
|
|
750
|
+
Ie as postMessage,
|
|
746
751
|
P as postMessageImpl,
|
|
747
752
|
lt as request,
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
753
|
+
pt as request2,
|
|
754
|
+
$ as request2Fp,
|
|
755
|
+
De as requestFp,
|
|
756
|
+
it as resetGlobals,
|
|
757
|
+
rt as retrieveLaunchParams,
|
|
758
|
+
We as retrieveLaunchParamsFp,
|
|
759
|
+
nt as retrieveRawInitData,
|
|
760
|
+
je as retrieveRawInitDataFp,
|
|
761
|
+
ot as retrieveRawLaunchParams,
|
|
762
|
+
M as retrieveRawLaunchParamsFp,
|
|
763
|
+
at as setDebug,
|
|
764
|
+
st as setTargetOrigin,
|
|
765
|
+
F as supports,
|
|
766
|
+
ue as targetOrigin
|
|
762
767
|
};
|
|
763
768
|
//# sourceMappingURL=index.js.map
|