@vbotma/bridge 2.3.0 → 2.3.2
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/README.md +1 -2
- package/dist/dts/env/mockVBotEnv.d.ts +2 -2
- package/dist/dts/env/setLaunchParams.d.ts +2 -2
- package/dist/dts/events/emitEvent.d.ts +3 -3
- package/dist/dts/events/types/events.d.ts +2 -2
- package/dist/dts/globals.d.ts +3 -3
- package/dist/dts/index.d.ts +1 -1
- package/dist/dts/methods/postMessage.d.ts +1 -1
- package/dist/dts/methods/types/methods.d.ts +13 -17
- 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 +184 -185
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
[docs-badge]: https://img.shields.io/badge/documentation-blue?logo=gitbook&logoColor=white
|
|
6
6
|
|
|
7
|
-
[link]: https://github.com/Telegram-Mini-Apps/tma.js/tree/master/tma.js/bridge
|
|
8
7
|
|
|
9
8
|
[docs-link]: https://docs.vbot-mini-apps.com/packages/tma-js-bridge
|
|
10
9
|
|
|
@@ -21,7 +20,7 @@
|
|
|
21
20
|
|
|
22
21
|
The lowest level communication layer with VBot Mini Apps.
|
|
23
22
|
|
|
24
|
-
This package provides fundamental utilities and types for developing applications on the
|
|
23
|
+
This package provides fundamental utilities and types for developing applications on the VBot
|
|
25
24
|
Mini Apps platform.
|
|
26
25
|
|
|
27
26
|
While a developer can use this package alone, it's recommended to use a higher-level package
|
|
@@ -10,7 +10,7 @@ import { MethodName, MethodParams } from '../methods/types/index.js';
|
|
|
10
10
|
* or write a custom behavior. It is extremely useful in some VBot clients improperly handling
|
|
11
11
|
* Mini Apps methods' calls and not even responding.
|
|
12
12
|
*
|
|
13
|
-
* Note that calling this function in
|
|
13
|
+
* Note that calling this function in VBot web clients, the `postMessageImplementation` signal
|
|
14
14
|
* value will be updated with a new one, enhancing previously set signal value to allow wrapping
|
|
15
15
|
* the original `window.parent.postMessage` function. In other words, calling `mockVBotEnv`
|
|
16
16
|
* function N times, you will effectively wrap previously set implementation N times, so be
|
|
@@ -36,7 +36,7 @@ export declare function mockVBotEnv({ launchParams, onEvent, resetPostMessage }?
|
|
|
36
36
|
* Note that using the `next` function, in non-web environments it uses the
|
|
37
37
|
* `window.VBotWebviewProxy.postEvent` method.
|
|
38
38
|
*
|
|
39
|
-
* Talking about the web versions of
|
|
39
|
+
* Talking about the web versions of VBot, the value of `next` is a bit more complex - it
|
|
40
40
|
* will be equal to the value stored in the `postMessageImpl` signal set previously. By default,
|
|
41
41
|
* this value contains a function utilizing the `window.parent.postMessage` method.
|
|
42
42
|
* @param event - event information.
|
|
@@ -13,7 +13,7 @@ import { MethodName, MethodParams } from '../methods/types/index.js';
|
|
|
13
13
|
* This function acts identically to `mockVBotEnv` but provides a more semantic name when the primary
|
|
14
14
|
* goal is to inject launch parameters into the simulated environment.
|
|
15
15
|
*
|
|
16
|
-
* Note that calling this function in
|
|
16
|
+
* Note that calling this function in VBot web clients, the `postMessageImplementation` signal
|
|
17
17
|
* value will be updated with a new one, enhancing previously set signal value to allow wrapping
|
|
18
18
|
* the original `window.parent.postMessage` function. In other words, calling `setLaunchParams`
|
|
19
19
|
* function N times, you will effectively wrap previously set implementation N times, so be
|
|
@@ -39,7 +39,7 @@ export declare function setLaunchParams({ launchParams, onEvent, resetPostMessag
|
|
|
39
39
|
* Note that using the `next` function, in non-web environments it uses the
|
|
40
40
|
* `window.VBotWebviewProxy.postEvent` method.
|
|
41
41
|
*
|
|
42
|
-
* Talking about the web versions of
|
|
42
|
+
* Talking about the web versions of VBot, the value of `next` is a bit more complex - it
|
|
43
43
|
* will be equal to the value stored in the `postMessageImpl` signal set previously. By default,
|
|
44
44
|
* this value contains a function utilizing the `window.parent.postMessage` method.
|
|
45
45
|
* @param event - event information.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventPayload, EventWithoutPayload, EventWithPayload } from './types/index.js';
|
|
2
2
|
/**
|
|
3
|
-
* Emits an event without payload sent from the
|
|
3
|
+
* Emits an event without payload sent from the VBot native application like it was sent in
|
|
4
4
|
* a default web environment between two iframes.
|
|
5
5
|
*
|
|
6
6
|
* It dispatches a new MessageEvent and expects it to be handled via
|
|
@@ -10,7 +10,7 @@ import { EventPayload, EventWithoutPayload, EventWithPayload } from './types/ind
|
|
|
10
10
|
*/
|
|
11
11
|
export declare function emitEvent<E extends EventWithoutPayload>(eventType: E): void;
|
|
12
12
|
/**
|
|
13
|
-
* Emits an event with payload sent from the
|
|
13
|
+
* Emits an event with payload sent from the VBot native application like it was sent in
|
|
14
14
|
* a default web environment between two iframes.
|
|
15
15
|
*
|
|
16
16
|
* It dispatches a new MessageEvent and expects it to be handled via
|
|
@@ -21,7 +21,7 @@ export declare function emitEvent<E extends EventWithoutPayload>(eventType: E):
|
|
|
21
21
|
*/
|
|
22
22
|
export declare function emitEvent<E extends EventWithPayload>(eventType: E, eventData: EventPayload<E>): void;
|
|
23
23
|
/**
|
|
24
|
-
* Emits an unknown event sent from the
|
|
24
|
+
* Emits an unknown event sent from the VBot native application like it was sent in a default
|
|
25
25
|
* web environment between two iframes.
|
|
26
26
|
*
|
|
27
27
|
* It dispatches a new MessageEvent and expects it to be handled via
|
|
@@ -647,7 +647,7 @@ export interface Events {
|
|
|
647
647
|
*/
|
|
648
648
|
secure_storage_key_saved: WithReqId;
|
|
649
649
|
/**
|
|
650
|
-
* The event which is usually sent by the
|
|
650
|
+
* The event which is usually sent by the VBot web application. Its
|
|
651
651
|
* payload represents
|
|
652
652
|
* `<style/>` tag html content, a developer could use. The stylesheet
|
|
653
653
|
* described in the payload will help the developer to stylize the app
|
|
@@ -662,7 +662,7 @@ export interface Events {
|
|
|
662
662
|
*/
|
|
663
663
|
settings_button_pressed: never;
|
|
664
664
|
/**
|
|
665
|
-
* Occurs whenever theme settings are changed in the user's
|
|
665
|
+
* Occurs whenever theme settings are changed in the user's VBot app
|
|
666
666
|
* (including switching to night mode).
|
|
667
667
|
* @see https://docs.vbot-mini-apps.com/platform/events#theme-changed
|
|
668
668
|
*/
|
package/dist/dts/globals.d.ts
CHANGED
|
@@ -19,12 +19,12 @@ export declare function setDebug(value: boolean): void;
|
|
|
19
19
|
*
|
|
20
20
|
* You don't need to override this value until you know what you are doing.
|
|
21
21
|
* To update the value, use the `setTargetOrigin` function.
|
|
22
|
-
* @default 'https://web.
|
|
22
|
+
* @default 'https://web.vbot.org'
|
|
23
23
|
* @see setTargetOrigin
|
|
24
24
|
*/
|
|
25
25
|
export declare const targetOrigin: import('@vbotma/signals').Computed<string>;
|
|
26
26
|
/**
|
|
27
|
-
* Sets a new target origin that is being used when calling the `postEvent` function in
|
|
27
|
+
* Sets a new target origin that is being used when calling the `postEvent` function in VBot
|
|
28
28
|
* web versions.
|
|
29
29
|
*
|
|
30
30
|
* You don't need to override this value until you know what you are doing.
|
|
@@ -34,7 +34,7 @@ export declare const targetOrigin: import('@vbotma/signals').Computed<string>;
|
|
|
34
34
|
export declare function setTargetOrigin(origin: string): void;
|
|
35
35
|
/**
|
|
36
36
|
* Signal containing a custom implementation of the method to post a message to the parent
|
|
37
|
-
* window. We usually use it to send a message in web versions of
|
|
37
|
+
* window. We usually use it to send a message in web versions of VBot.
|
|
38
38
|
*
|
|
39
39
|
* @default A function behaving like the `window.parent.postMessage` method.
|
|
40
40
|
*/
|
package/dist/dts/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export { getReleaseVersion } from './methods/getReleaseVersion.js';
|
|
|
13
13
|
export { postEvent, postEventFp, type PostEventFn, type PostEventFpFn, type PostEventError, } from './methods/postEvent.js';
|
|
14
14
|
export { postMessage, type PostMessage } from './methods/postMessage.js';
|
|
15
15
|
export { supports } from './methods/supports.js';
|
|
16
|
-
export type { AnyHapticFeedbackParams, AnyInvokeCustomMethodParams, CreateMethodParams, CustomMethodName, ImpactHapticFeedbackParams, ImpactHapticFeedbackStyle, CustomMethodsParams, CustomMethodParams, MethodName, MethodVersionedParams, NotificationHapticFeedbackParams, NotificationHapticFeedbackType, Methods, SelectionHapticFeedbackParams, MethodNameWithOptionalParams, MethodNameWithoutParams, MethodNameWithRequiredParams, MethodNameWithVersionedParams, MethodParams, PopupParams, BackgroundColor, BottomBarColor, HeaderColorKey, PopupButton, OpenLinkBrowser, SecondaryButtonPosition, SwitchInlineQueryChatType, } from './methods/types/index.js';
|
|
16
|
+
export type { AnyHapticFeedbackParams, AnyInvokeCustomMethodParams, CreateMethodParams, CustomMethodName, ImpactHapticFeedbackParams, ImpactHapticFeedbackStyle, CustomMethodsParams, CustomMethodParams, MethodName, MethodVersionedParams, NotificationHapticFeedbackParams, NotificationHapticFeedbackType, Methods, SelectionHapticFeedbackParams, MethodNameWithOptionalParams, MethodNameWithoutParams, MethodNameWithRequiredParams, MethodNameWithVersionedParams, MethodParams, PopupParams, BackgroundColor, BottomBarColor, HeaderColorKey, PopupButton, OpenLinkBrowser, SecondaryButtonPosition, SwitchInlineQueryChatType, NotificationParams, } from './methods/types/index.js';
|
|
17
17
|
export { compareVersions } from './utils/compareVersions.js';
|
|
18
18
|
export { invokeCustomMethod, invokeCustomMethodFp, type InvokeCustomMethodFn, type InvokeCustomMethodOptions, type InvokeCustomMethodFpFn, type InvokeCustomMethodError, type InvokeCustomMethodFpOptions, } from './utils/invokeCustomMethod.js';
|
|
19
19
|
export { request, requestFp, type RequestCaptureEventFn, type RequestCaptureEventsFn, type RequestCaptureFn, type RequestCaptureFnEventsPayload, type RequestFn, type RequestOptions, type RequestResult, type RequestError, type RequestFpOptions, type RequestFpFn, } from './utils/request.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type PostMessage = typeof window.parent.postMessage;
|
|
2
2
|
/**
|
|
3
3
|
* Posts a message to the parent window. We usually use it to send a message in web versions of
|
|
4
|
-
*
|
|
4
|
+
* VBot.
|
|
5
5
|
* @param args - `window.parent.postMessage` arguments.
|
|
6
6
|
*/
|
|
7
7
|
export declare const postMessage: PostMessage;
|
|
@@ -52,7 +52,7 @@ interface ButtonParams {
|
|
|
52
52
|
export interface Methods {
|
|
53
53
|
/**
|
|
54
54
|
* Notifies parent iframe about the current frame is ready. This method is only used in the Web
|
|
55
|
-
* version of
|
|
55
|
+
* version of VBot. As a result, Mini App will receive `set_custom_style` event.
|
|
56
56
|
* @see https://docs.vbot-mini-apps.com/platform/methods#iframe-ready
|
|
57
57
|
*/
|
|
58
58
|
iframe_ready: CreateMethodParams<{
|
|
@@ -190,7 +190,6 @@ export interface Methods {
|
|
|
190
190
|
* containing the data of the length up to 4096 bytes. Then, Mini App will be closed.
|
|
191
191
|
*
|
|
192
192
|
* To get more information, take a look at `web_app_data` field in the
|
|
193
|
-
* class [Message](https://core.telegram.org/bots/api#message).
|
|
194
193
|
*
|
|
195
194
|
* @see https://docs.vbot-mini-apps.com/platform/methods#web-app-data-send
|
|
196
195
|
*/
|
|
@@ -264,7 +263,6 @@ export interface Methods {
|
|
|
264
263
|
web_app_invoke_custom_method: CreateMethodParams<AnyInvokeCustomMethodParams>;
|
|
265
264
|
/**
|
|
266
265
|
* Opens an invoice by its specified slug. More information about invoices in
|
|
267
|
-
* this [documentation](https://core.telegram.org/bots/payments).
|
|
268
266
|
* @since v6.1
|
|
269
267
|
* @see https://docs.vbot-mini-apps.com/platform/methods#web-app-open-invoice
|
|
270
268
|
*/
|
|
@@ -286,7 +284,7 @@ export interface Methods {
|
|
|
286
284
|
/**
|
|
287
285
|
* Link will be opened in Instant View mode if possible.
|
|
288
286
|
* @since v6.4
|
|
289
|
-
* @see https://instantview.
|
|
287
|
+
* @see https://instantview.vbot.org/
|
|
290
288
|
*/
|
|
291
289
|
try_instant_view?: boolean;
|
|
292
290
|
/**
|
|
@@ -306,14 +304,14 @@ export interface Methods {
|
|
|
306
304
|
*/
|
|
307
305
|
web_app_open_location_settings: CreateMethodParams;
|
|
308
306
|
/**
|
|
309
|
-
* Opens a new popup. When a user closes the popup,
|
|
307
|
+
* Opens a new popup. When a user closes the popup, VBot creates the `popup_closed` event.
|
|
310
308
|
* @since v6.2
|
|
311
309
|
* @see https://docs.vbot-mini-apps.com/platform/methods#web-app-open-popup
|
|
312
310
|
*/
|
|
313
311
|
web_app_open_popup: CreateMethodParams<PopupParams>;
|
|
314
312
|
/**
|
|
315
313
|
* Opens a QR scanner. When the scanner was closed, the VBot application creates
|
|
316
|
-
* the `scan_qr_popup_closed` event. When the scanner reads QR,
|
|
314
|
+
* the `scan_qr_popup_closed` event. When the scanner reads QR, VBot creates the
|
|
317
315
|
* `qr_text_received` event.
|
|
318
316
|
* @since v6.4
|
|
319
317
|
* @see https://docs.vbot-mini-apps.com/platform/methods#web-app-open-scan-qr-popup
|
|
@@ -325,14 +323,14 @@ export interface Methods {
|
|
|
325
323
|
text?: string;
|
|
326
324
|
}>;
|
|
327
325
|
/**
|
|
328
|
-
* Opens the
|
|
329
|
-
*
|
|
326
|
+
* Opens the VBot link by its pathname and query parameters. The link will be opened in the
|
|
327
|
+
* VBot app, Mini App will be closed.
|
|
330
328
|
* @since v6.1
|
|
331
329
|
* @see https://docs.vbot-mini-apps.com/platform/methods#web-app-open-tg-link
|
|
332
330
|
*/
|
|
333
331
|
web_app_open_tg_link: CreateMethodParams<{
|
|
334
332
|
/**
|
|
335
|
-
* Should be a value taken from the link of this format: `https://
|
|
333
|
+
* Should be a value taken from the link of this format: `https://vbot.vn/{path_full}`. Can
|
|
336
334
|
* additionally contain query parameters.
|
|
337
335
|
*/
|
|
338
336
|
path_full: string;
|
|
@@ -345,8 +343,8 @@ export interface Methods {
|
|
|
345
343
|
*/
|
|
346
344
|
web_app_read_text_from_clipboard: CreateMethodParams<WithReqId>;
|
|
347
345
|
/**
|
|
348
|
-
* Notifies
|
|
349
|
-
*
|
|
346
|
+
* Notifies VBot about current application is ready to be shown. This method will make
|
|
347
|
+
* VBot to remove application loader and display Mini App.
|
|
350
348
|
* @see https://docs.vbot-mini-apps.com/platform/methods#web-app-ready
|
|
351
349
|
*/
|
|
352
350
|
web_app_ready: CreateMethodParams;
|
|
@@ -440,12 +438,12 @@ export interface Methods {
|
|
|
440
438
|
read_content?: boolean;
|
|
441
439
|
}>;
|
|
442
440
|
/**
|
|
443
|
-
* Requests current theme from
|
|
441
|
+
* Requests current theme from VBot. As a result, VBot will create `theme_changed` event.
|
|
444
442
|
* @see https://docs.vbot-mini-apps.com/platform/methods#web-app-request-theme
|
|
445
443
|
*/
|
|
446
444
|
web_app_request_theme: CreateMethodParams;
|
|
447
445
|
/**
|
|
448
|
-
* Requests current viewport information from
|
|
446
|
+
* Requests current viewport information from VBot. As a result, VBot will create
|
|
449
447
|
* `viewport_changed` event.
|
|
450
448
|
* @see https://docs.vbot-mini-apps.com/platform/methods#web-app-request-viewport
|
|
451
449
|
*/
|
|
@@ -514,9 +512,7 @@ export interface Methods {
|
|
|
514
512
|
web_app_send_prepared_message: CreateMethodParams<{
|
|
515
513
|
/**
|
|
516
514
|
* Identifier of the message
|
|
517
|
-
* ([PreparedInlineMessage](https://core.telegram.org/bots/api#preparedinlinemessage))
|
|
518
515
|
* previously obtained via the Bot API method
|
|
519
|
-
* [savePreparedInlineMessage](https://core.telegram.org/bots/api#savepreparedinlinemessage).
|
|
520
516
|
*/
|
|
521
517
|
id: string;
|
|
522
518
|
}>;
|
|
@@ -649,13 +645,13 @@ export interface Methods {
|
|
|
649
645
|
/**
|
|
650
646
|
* The caption to be added to the media.
|
|
651
647
|
* 0-200 characters for regular users and 0-2048 characters for premium subscribers.
|
|
652
|
-
* @see https://
|
|
648
|
+
* @see https://vbot.org/faq_premium#vbot-premium
|
|
653
649
|
*/
|
|
654
650
|
text?: string;
|
|
655
651
|
/**
|
|
656
652
|
* An object that describes a widget link to be included in the story.
|
|
657
653
|
* Note that only premium subscribers can post stories with links.
|
|
658
|
-
* @see https://
|
|
654
|
+
* @see https://vbot.org/faq_premium#vbot-premium
|
|
659
655
|
*/
|
|
660
656
|
widget_link?: {
|
|
661
657
|
/**
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("valibot"),l=require("@vbotma/toolkit"),
|
|
2
|
-
`)]){}class j extends v.errorClass("InvalidLaunchParamsError",(t,r)=>[`Invalid value for launch params: ${t}`,{cause:r}]){}class
|
|
3
|
-
`),t,i)}Se(r,o)}const{on:W,off:ae,emit:Se,clear:se}=R(()=>{const e=window;!e.TelegramGameProxy&&(e.TelegramGameProxy={}),V(e.TelegramGameProxy,"receiveEvent",S),H(e,"TelegramGameProxy"),!e.VBot&&(e.VBot={}),!e.VBot.WebView&&(e.VBot.WebView={}),V(e.VBot.WebView,"receiveEvent",S),H(e.VBot,"WebView"),V(e,"TelegramGameProxy_receiveEvent",S),window.addEventListener("message",Q)},()=>{[["TelegramGameProxy_receiveEvent"],["TelegramGameProxy","receiveEvent"],["VBot","WebView","receiveEvent"]].forEach(e=>{const t=window;let r=[void 0,t];for(const o of e)if(r=[r[1],r[1][o]],!r[1])return;const[n,a]=r;"unwrap"in a&&(a.unwrap(),n&&n!==t&&!Object.keys(n).length&&delete t[e[0]])}),window.removeEventListener("message",Q)}),ie=(...e)=>w()(...e);function ce(e,t){s.function.pipe(E(e,t),s.either.mapLeft(r=>{throw r}))}function E(e,t){b().log("Posting event:",t?{eventType:e,eventData:t}:{eventType:e});const r=window,n=JSON.stringify({eventType:e,eventData:t});return F()?(ie(n,$()),s.either.right(void 0)):M(r)?(r.VBotWebviewProxy.postEvent(e,JSON.stringify(t)),s.either.right(void 0)):c.is(c.looseObject({external:c.looseObject({notify:c.function()})}),r)?(r.external.notify(n),s.either.right(void 0)):s.either.left(new T)}function A(e,t,r={}){const{capture:n=()=>!0,postEvent:a=E}=r,o=y.signal(),[i,p]=l.createCbCollector();(Array.isArray(t)?t:[t]).forEach(u=>{i(W(u,f=>{const d=Array.isArray(t);n(d?{event:u,payload:f}:f)&&o.set([d?{event:u,payload:f}:f])}))});const _=u=>(p(),u);return s.function.pipe(async()=>a(e,r.params),s.taskEither.chainW(()=>l.BetterTaskEither((u,f,d)=>{const m=o();if(m)return u(m[0]);const P=k=>{k&&u(k[0])},L=()=>{o.unsub(P)};o.sub(P),d.on("finalized",L)},r)),s.taskEither.mapBoth(_,_))}function Be(e,t,r){const{postEvent:n}=r||{};return l.throwifyAnyEither(A(e,t,{...r,postEvent:n?(...a)=>{try{return n(...a),s.either.right(void 0)}catch(o){return s.either.left(o)}}:E}))}function xe(e,t){const r=pe(e,t);return typeof r=="function"?B.BetterPromise.fn(()=>l.throwifyAnyEither(r)):r}function pe(e,t){const r=M(window);if(!e)return r||s.function.pipe(x(),s.either.match(()=>!1,()=>!0));if(r)return s.taskEither.right(!0);const{timeout:n=100}=t||{};return s.function.pipe(A("web_app_request_theme","theme_changed",{...t,timeout:n}),s.taskEither.match(a=>B.TimeoutError.is(a)||T.is(a)?s.either.right(!1):s.either.left(a),()=>s.either.right(!0)))}function Ce({launchParams:e,onEvent:t,resetPostMessage:r}={}){if(e){const o=typeof e=="string"||e instanceof URLSearchParams?e.toString():h.serializeLaunchParamsQuery({...e,vbWebAppData:void 0})+(e.vbWebAppData?`&vbWebAppData=${encodeURIComponent(e.vbWebAppData.toString())}`:"");try{h.parseLaunchParamsQuery(o)}catch(i){throw new j(o,i)}l.setStorageValue("launchParams",o)}if(F()){if(!t)return;r&&w.reset();const o=w();w.set((...i)=>{const[p]=i,_=()=>{o(...i)};try{const u=c.parse(h.pipeJsonToSchema(h.miniAppsMessage()),p);t({name:u.eventType,params:u.eventData},_)}catch{_()}});return}const n=window.VBotWebviewProxy||{},a=n.postEvent||(()=>{});window.VBotWebviewProxy={...n,postEvent(o,i){const p=()=>{a(o,i)};t?t({name:o,params:i?JSON.parse(i):void 0},p):p()}},b().log("Environment was mocked by the mockVBotEnv function")}function Fe({launchParams:e,onEvent:t,resetPostMessage:r}={}){if(e){const o=typeof e=="string"||e instanceof URLSearchParams?e.toString():h.serializeLaunchParamsQuery({...e,vbWebAppData:void 0})+(e.vbWebAppData?`&vbWebAppData=${encodeURIComponent(e.vbWebAppData.toString())}`:"");try{h.parseLaunchParamsQuery(o)}catch(i){throw new j(o,i)}l.setStorageValue("launchParams",o)}if(F()){if(!t)return;r&&w.reset();const o=w();w.set((...i)=>{const[p]=i,_=()=>{o(...i)};try{const u=c.parse(h.pipeJsonToSchema(h.miniAppsMessage()),p);t({name:u.eventType,params:u.eventData},_)}catch{_()}});return}const n=window.VBotWebviewProxy||{},a=n.postEvent||(()=>{});window.VBotWebviewProxy={...n,postEvent(o,i){const p=()=>{a(o,i)};t?t({name:o,params:i?JSON.parse(i):void 0},p):p()}},b().log("Launch params are injected by the setLaunchParams function")}function We(e,t="*"){const r=o=>{if(o.source===e.contentWindow)try{const i=JSON.parse(o.data),{eventType:p,eventData:_}=i;n.emit(p,_)}catch{}},n=R(()=>{window.addEventListener("message",r)},()=>{window.removeEventListener("message",r)}),a={...n,send:(o,i)=>{if(e.contentWindow){const p=JSON.stringify({eventType:o,eventData:i});e.contentWindow.postMessage(p,t)}},clear:()=>{n.clear(),g===a&&(g=void 0)}};return g=a,a}function Ae(){const e=R(()=>{},()=>{}),t={...e,send:(r,n)=>{S(r,n)},clear:()=>{var r;e.clear(),g===t&&(g=void 0),(r=window.VBotWebviewProxy)!=null&&r.__isWebComponentProxy&&delete window.VBotWebviewProxy}};return window.VBotWebviewProxy={__isWebComponentProxy:!0,postEvent(r,n){let a;try{a=n?JSON.parse(n):void 0}catch{a=n}e.emit(r,a)}},g=t,t}let g;function Le(){if(!g)throw new Error("HostBridge not initialized. Call defineHostBridge() or defineWebComponentBridge() first.");return g}function ue(e){return({req_id:t})=>t===e}const K={"6.0":["iframe_ready","iframe_will_reload","web_app_close","web_app_data_send","web_app_expand","web_app_open_link","web_app_ready","web_app_request_theme","web_app_request_viewport","web_app_setup_main_button","web_app_setup_closing_behavior"],6.1:["web_app_open_tg_link","web_app_open_invoice","web_app_setup_back_button","web_app_set_background_color","web_app_set_header_color","web_app_trigger_haptic_feedback"],6.2:["web_app_open_popup"],6.4:["web_app_close_scan_qr_popup","web_app_open_scan_qr_popup","web_app_read_text_from_clipboard",{method:"web_app_open_link",param:"try_instant_view"}],6.7:["web_app_switch_inline_query"],6.9:["web_app_invoke_custom_method","web_app_request_write_access","web_app_request_phone",{method:"web_app_set_header_color",param:"color"}],"6.10":["web_app_setup_settings_button"],7.2:["web_app_biometry_get_info","web_app_biometry_open_settings","web_app_biometry_request_access","web_app_biometry_request_auth","web_app_biometry_update_token"],7.6:[{method:"web_app_open_link",param:"try_browser"},{method:"web_app_close",param:"return_back"}],7.7:["web_app_setup_swipe_behavior"],7.8:["web_app_share_to_story"],"7.10":["web_app_setup_secondary_button","web_app_set_bottom_bar_color",{method:"web_app_setup_main_button",param:"has_shine_effect"}],"8.0":["web_app_request_safe_area","web_app_request_content_safe_area","web_app_request_fullscreen","web_app_exit_fullscreen","web_app_set_emoji_status","web_app_add_to_home_screen","web_app_check_home_screen","web_app_request_emoji_status_access","web_app_check_location","web_app_open_location_settings","web_app_request_file_download","web_app_request_location","web_app_send_prepared_message","web_app_start_accelerometer","web_app_start_device_orientation","web_app_start_gyroscope","web_app_stop_accelerometer","web_app_stop_device_orientation","web_app_stop_gyroscope","web_app_toggle_orientation_lock"],"9.0":["web_app_device_storage_clear","web_app_device_storage_get_key","web_app_device_storage_save_key","web_app_secure_storage_clear","web_app_secure_storage_get_key","web_app_secure_storage_restore_key","web_app_secure_storage_save_key"],9.1:["web_app_hide_keyboard"],9.2:["web_app_send_notification","web_app_finish_refresh"]};function O(e,t){return Object.keys(K).find(n=>K[n].some(a=>t?typeof a=="object"&&a.method===e&&a.param===t:a===e))||null}function Y(e){return e.split(".").map(Number)}function _e(e,t){const r=Y(e),n=Y(t),a=Math.max(r.length,n.length);for(let o=0;o<a;o+=1){const i=r[o]||0,p=n[o]||0;if(i!==p)return i>p?1:-1}return 0}function q(e,t,r){const n=r?O(e,t):O(e);return n?_e(n,r||t)<=0:!1}function Ve(e,t="strict"){const r=typeof t=="function"?t:n=>{const{method:a,version:o}=n,i="param"in n?new Z(a,n.param,o):new X(a,o);if(t==="strict")throw i;return b().forceWarn(i.message)};return((n,a)=>q(n,e)?n==="web_app_set_header_color"&&c.is(c.looseObject({color:c.any()}),a)&&!q(n,"color",e)?r({version:e,method:n,param:"color"}):ce(n,a):r({version:e,method:n}))}function le(e,t,r,n){return s.function.pipe(A("web_app_invoke_custom_method","custom_method_invoked",{...n||{},params:{method:e,params:t,req_id:r},capture:ue(r)}),s.taskEither.chain(({result:a,error:o})=>o?s.taskEither.left(new te(o)):s.taskEither.right(a)))}function Oe(e,t,r,n){return B.BetterPromise.fn(()=>s.function.pipe(le(e,t,r,n),s.taskEither.match(a=>{throw a},a=>a))())}function fe(e,t,r={}){const{capture:n=()=>!0,postEvent:a=E}=r,o=y.signal(),[i,p]=l.createCbCollector();(Array.isArray(t)?t:[t]).forEach(u=>{i(W(u,f=>{(Array.isArray(t)?n({event:u,payload:f}):n(f))&&o.set([f])}))});const _=u=>(p(),u);return s.function.pipe(async()=>a(e,r.params),s.taskEither.chainW(()=>l.BetterTaskEither((u,f,d)=>{const m=o();if(m)return u(m[0]);const P=k=>{k&&u(k[0])},L=()=>{o.unsub(P)};o.sub(P),d.on("finalized",L)},r)),s.taskEither.mapBoth(_,_))}function qe(e,t,r){const{postEvent:n}=r||{};return l.throwifyAnyEither(fe(e,t,{...r,postEvent:n?(...a)=>{try{return n(...a),s.either.right(void 0)}catch(o){return s.either.left(o)}}:E}))}function Me(){Object.hasOwn||(Object.hasOwn=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)})}function z(e){return s.either.tryCatch(()=>decodeURIComponent(atob(e.replace(/-/g,"+").replace(/_/g,"/")).split("").map(t=>"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2)).join("")),t=>t)}const je=l.throwifyFpFn(z);function D(e){return btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,r)=>String.fromCharCode(parseInt(`0x${r}`)))).replace(/\+/g,"-").replace(/\//g,"_")}function de(e){const t=D(typeof e=="string"?e:JSON.stringify(e));return t.length>512?s.either.left(new Error("Value is too long for start parameter")):s.either.right(t)}const Te=l.throwifyFpFn(de);function Re(e,t){return l.throwifyAnyEither(he(e,typeof t=="function"?r=>s.either.tryCatch(()=>t(r),n=>n):t))}function he(e,t){return s.function.pipe(z(e),s.either.chain(r=>t?typeof t=="function"?t(r):s.json.parse(r):s.either.right(r)))}function Ue(e){return D(e).length<=512}Object.defineProperty(exports,"createLogger",{enumerable:!0,get:()=>l.createLogger});Object.defineProperty(exports,"deepSnakeToCamelObjKeys",{enumerable:!0,get:()=>l.deepSnakeToCamelObjKeys});Object.defineProperty(exports,"CancelledError",{enumerable:!0,get:()=>B.CancelledError});Object.defineProperty(exports,"TimeoutError",{enumerable:!0,get:()=>B.TimeoutError});exports.InvalidLaunchParamsError=j;exports.InvokeCustomMethodFailedError=te;exports.LaunchParamsRetrieveError=ee;exports.MethodParameterUnsupportedError=Z;exports.MethodUnsupportedError=X;exports.UnknownEnvError=T;exports.applyPolyfills=Me;exports.captureSameReq=ue;exports.compareVersions=_e;exports.createPostEvent=Ve;exports.createStartParam=Te;exports.createStartParamFp=de;exports.debug=I;exports.decodeBase64Url=je;exports.decodeBase64UrlFp=z;exports.decodeStartParam=Re;exports.decodeStartParamFp=he;exports.defineHostBridge=We;exports.defineWebComponentBridge=Ae;exports.emitEvent=S;exports.encodeBase64Url=D;exports.getHostBridge=Le;exports.getReleaseVersion=O;exports.hasWebviewProxy=M;exports.invokeCustomMethod=Oe;exports.invokeCustomMethodFp=le;exports.isIframe=F;exports.isSafeToCreateStartParam=Ue;exports.isVBma=xe;exports.isVBmaFp=pe;exports.logger=b;exports.mockVBotEnv=Ce;exports.off=ae;exports.offAll=se;exports.on=W;exports.postEvent=ce;exports.postEventFp=E;exports.postMessage=ie;exports.postMessageImpl=w;exports.request=qe;exports.request2=Be;exports.request2Fp=A;exports.requestFp=fe;exports.resetGlobals=Pe;exports.retrieveLaunchParams=we;exports.retrieveLaunchParamsFp=re;exports.retrieveRawInitData=be;exports.retrieveRawInitDataFp=ne;exports.retrieveRawLaunchParams=ge;exports.retrieveRawLaunchParamsFp=x;exports.setDebug=ve;exports.setLaunchParams=Fe;exports.setTargetOrigin=Ee;exports.supports=q;exports.targetOrigin=$;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("valibot"),l=require("@vbotma/toolkit"),S=require("better-promises"),s=require("fp-ts"),v=require("error-kid"),h=require("@vbotma/transformers"),y=require("@vbotma/signals"),we=require("mitt");function M(e){return c.is(c.looseObject({VBotWebviewProxy:c.looseObject({postEvent:c.function()})}),e)}function V(){try{return window.self!==window.top}catch{return!0}}class X extends v.errorClass("MethodUnsupportedError",(t,r)=>[`Method "${t}" is unsupported in Mini Apps version ${r}`]){}class Z extends v.errorClass("MethodParameterUnsupportedError",(t,r,n)=>[`Parameter "${r}" of "${t}" method is unsupported in Mini Apps version ${n}`]){}class ee extends v.errorClassWithData("LaunchParamsRetrieveError",t=>({errors:t}),t=>[["Unable to retrieve launch parameters from any known source. You should pass correct parameters to Mini App","","Collected errors:",...t.map(({source:r,error:n})=>`Source: ${r} / ${n instanceof Error?n.message:String(n)}`)].join(`
|
|
2
|
+
`)]){}class j extends v.errorClass("InvalidLaunchParamsError",(t,r)=>[`Invalid value for launch params: ${t}`,{cause:r}]){}class R extends v.errorClass("UnknownEnvError"){}class te extends v.errorClass("InvokeCustomMethodError",t=>[`Server returned error: ${t}`]){}const J="launchParams";function G(e){return e.replace(/^[^?#]*[?#]/,"").replace(/[?#]/g,"&")}function re(){return s.function.pipe(x(),s.either.chainW(h.parseLaunchParamsQueryFp))}const be=l.throwifyFpFn(re);function ne(){return s.function.pipe(x(),s.either.map(e=>{const t=new URLSearchParams(e).get("vbWebAppData");return t?s.option.some(t):s.option.none}))}function me(){return s.function.pipe(ne(),s.either.fold(e=>{throw e},e=>e),s.option.match(()=>{},e=>e))}function x(){const e=[];for(const[t,r]of[[()=>G(window.location.href),"window.location.href"],[()=>{const n=performance.getEntriesByType("navigation")[0];return n&&G(n.name)},"performance navigation entries"],[()=>l.getStorageValue(J),"local storage"]]){const n=t();if(!n){e.push({source:r,error:new Error("Source is empty")});continue}const a=s.function.pipe(h.parseLaunchParamsQueryFp(n),s.either.foldW(o=>o,()=>!0));if(typeof a!="boolean"){e.push({source:r,error:a});continue}return l.setStorageValue(J,n),s.either.right(n)}return s.either.left(new ee(e))}const ge=l.throwifyFpFn(x);function U(e,t){const r=new Map,n=we(),a=(o,i,p=!1)=>{const _=r.get(o)||new Map;r.set(o,_);const u=_.get(i)||[];_.set(i,u);const f=u.findIndex(d=>d[1]===p);if(f>=0&&(n.off(o,u[f][0]),u.splice(f,1),!u.length&&(_.delete(i),!_.size))){const d=r.size;r.delete(o),d&&!r.size&&t()}};return{on(o,i,p){!r.size&&e();const _=()=>{a(o,i,p)},u=(...w)=>{p&&_(),o==="*"?i({name:w[0],payload:w[1]}):i(...w)};n.on(o,u);const f=r.get(o)||new Map;r.set(o,f);const d=f.get(i)||[];return f.set(i,d),d.push([u,p||!1]),_},off:a,emit:n.emit,clear(){const o=r.size;n.all.clear(),r.clear(),o&&t()}}}function B(e,t){window.dispatchEvent(new MessageEvent("message",{data:JSON.stringify({eventType:e,eventData:t}),source:window.parent}))}const C=y.signal(!1),I=y.signal("https://web.vbot.org"),ye=e=>{m().log("Event received:",e)},T=y.computed(C);function ve(e){e!==C()&&(C.set(e),(e?F:ae)("*",ye))}const $=y.computed(I);function Ee(e){I.set(e),m().log("New target origin set",e)}const b=y.signal((...e)=>{window.parent.postMessage(...e)}),m=y.signal(l.createLogger("Bridge",{bgColor:"#9147ff",textColor:"white",shouldLog:T}));function Pe(){se(),[b,I,$,C,T,m].forEach(e=>{e.unsubAll(),"reset"in e&&e.reset()})}function A(e,t,r){const n=[r],a=e[t];typeof a=="function"&&n.push(a);const o=(...p)=>{n.forEach(_=>_(...p))},i=Object.assign((...p)=>{o(...p)},{unwrap(){const{length:p}=n;if(p===1){delete e[t];return}if(p===2){N(e,t,n[1]);return}n.unshift(1),N(e,t,o)}});oe(e,t,()=>i,p=>n.push(p))}function H(e,t){const r=e[t];oe(e,t,()=>r,n=>{Object.entries(n).forEach(([a,o])=>{r[a]=o})})}function oe(e,t,r,n){Object.defineProperty(e,t,{enumerable:!0,configurable:!0,get:r,set:n})}function N(e,t,r){Object.defineProperty(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r})}const ke={clipboard_text_received:c.looseObject({req_id:c.string(),data:c.nullish(c.string())}),custom_method_invoked:c.looseObject({req_id:c.string(),result:c.optional(c.unknown()),error:c.optional(c.string())}),popup_closed:c.nullish(c.looseObject({button_id:c.nullish(c.string(),()=>{})}),{}),viewport_changed:c.nullish(c.looseObject({height:c.number(),width:c.nullish(c.number(),()=>window.innerWidth),is_state_stable:c.boolean(),is_expanded:c.boolean()}),()=>({height:window.innerHeight,is_state_stable:!0,is_expanded:!0})),theme_changed:c.looseObject({theme_params:h.themeParams()})};function Q(e){if(e.source!==window.parent)return;let t;try{t=c.parse(h.pipeJsonToSchema(h.miniAppsMessage()),e.data)}catch{return}const{eventType:r,eventData:n}=t,a=ke[r];let o;try{o=a?c.parse(a,n):n}catch(i){return m().forceError([`An error occurred processing the "${r}" event from the VBot application.`,"Please, file an issue here:"].join(`
|
|
3
|
+
`),t,i)}Be(r,o)}const{on:F,off:ae,emit:Be,clear:se}=U(()=>{const e=window;!e.VBotGameProxy&&(e.VBotGameProxy={}),A(e.VBotGameProxy,"receiveEvent",B),H(e,"VBotGameProxy"),!e.VBot&&(e.VBot={}),!e.VBot.WebView&&(e.VBot.WebView={}),A(e.VBot.WebView,"receiveEvent",B),H(e.VBot,"WebView"),A(e,"VBotGameProxy_receiveEvent",B),window.addEventListener("message",Q)},()=>{[["VBotGameProxy_receiveEvent"],["VBotGameProxy","receiveEvent"],["VBot","WebView","receiveEvent"]].forEach(e=>{const t=window;let r=[void 0,t];for(const o of e)if(r=[r[1],r[1][o]],!r[1])return;const[n,a]=r;"unwrap"in a&&(a.unwrap(),n&&n!==t&&!Object.keys(n).length&&delete t[e[0]])}),window.removeEventListener("message",Q)}),ie=(...e)=>b()(...e);function ce(e,t){s.function.pipe(E(e,t),s.either.mapLeft(r=>{throw r}))}function E(e,t){m().log("Posting event:",t?{eventType:e,eventData:t}:{eventType:e});const r=window,n=JSON.stringify({eventType:e,eventData:t});return V()?(ie(n,$()),s.either.right(void 0)):M(r)?(r.VBotWebviewProxy.postEvent(e,JSON.stringify(t)),s.either.right(void 0)):c.is(c.looseObject({external:c.looseObject({notify:c.function()})}),r)?(r.external.notify(n),s.either.right(void 0)):s.either.left(new R)}function W(e,t,r={}){const{capture:n=()=>!0,postEvent:a=E}=r,o=y.signal(),[i,p]=l.createCbCollector();(Array.isArray(t)?t:[t]).forEach(u=>{i(F(u,f=>{const d=Array.isArray(t);n(d?{event:u,payload:f}:f)&&o.set([d?{event:u,payload:f}:f])}))});const _=u=>(p(),u);return s.function.pipe(async()=>a(e,r.params),s.taskEither.chainW(()=>l.BetterTaskEither((u,f,d)=>{const w=o();if(w)return u(w[0]);const P=k=>{k&&u(k[0])},L=()=>{o.unsub(P)};o.sub(P),d.on("finalized",L)},r)),s.taskEither.mapBoth(_,_))}function Se(e,t,r){const{postEvent:n}=r||{};return l.throwifyAnyEither(W(e,t,{...r,postEvent:n?(...a)=>{try{return n(...a),s.either.right(void 0)}catch(o){return s.either.left(o)}}:E}))}function xe(e,t){const r=pe(e,t);return typeof r=="function"?S.BetterPromise.fn(()=>l.throwifyAnyEither(r)):r}function pe(e,t){const r=M(window);if(!e)return r||s.function.pipe(x(),s.either.match(()=>!1,()=>!0));if(r)return s.taskEither.right(!0);const{timeout:n=100}=t||{};return s.function.pipe(W("web_app_request_theme","theme_changed",{...t,timeout:n}),s.taskEither.match(a=>S.TimeoutError.is(a)||R.is(a)?s.either.right(!1):s.either.left(a),()=>s.either.right(!0)))}function Ce({launchParams:e,onEvent:t,resetPostMessage:r}={}){if(e){const o=typeof e=="string"||e instanceof URLSearchParams?e.toString():h.serializeLaunchParamsQuery({...e,vbWebAppData:void 0})+(e.vbWebAppData?`&vbWebAppData=${encodeURIComponent(e.vbWebAppData.toString())}`:"");try{h.parseLaunchParamsQuery(o)}catch(i){throw new j(o,i)}l.setStorageValue("launchParams",o)}if(V()){if(!t)return;r&&b.reset();const o=b();b.set((...i)=>{const[p]=i,_=()=>{o(...i)};try{const u=c.parse(h.pipeJsonToSchema(h.miniAppsMessage()),p);t({name:u.eventType,params:u.eventData},_)}catch{_()}});return}const n=window.VBotWebviewProxy||{},a=n.postEvent||(()=>{});window.VBotWebviewProxy={...n,postEvent(o,i){const p=()=>{a(o,i)};t?t({name:o,params:i?JSON.parse(i):void 0},p):p()}},m().log("Environment was mocked by the mockVBotEnv function")}function Ve({launchParams:e,onEvent:t,resetPostMessage:r}={}){if(e){const o=typeof e=="string"||e instanceof URLSearchParams?e.toString():h.serializeLaunchParamsQuery({...e,vbWebAppData:void 0})+(e.vbWebAppData?`&vbWebAppData=${encodeURIComponent(e.vbWebAppData.toString())}`:"");try{h.parseLaunchParamsQuery(o)}catch(i){throw new j(o,i)}l.setStorageValue("launchParams",o)}if(V()){if(!t)return;r&&b.reset();const o=b();b.set((...i)=>{const[p]=i,_=()=>{o(...i)};try{const u=c.parse(h.pipeJsonToSchema(h.miniAppsMessage()),p);t({name:u.eventType,params:u.eventData},_)}catch{_()}});return}const n=window.VBotWebviewProxy||{},a=n.postEvent||(()=>{});window.VBotWebviewProxy={...n,postEvent(o,i){const p=()=>{a(o,i)};t?t({name:o,params:i?JSON.parse(i):void 0},p):p()}},m().log("Launch params are injected by the setLaunchParams function")}function Fe(e,t="*"){const r=o=>{if(o.source===e.contentWindow)try{const i=JSON.parse(o.data),{eventType:p,eventData:_}=i;n.emit(p,_)}catch{}},n=U(()=>{window.addEventListener("message",r)},()=>{window.removeEventListener("message",r)}),a={...n,send:(o,i)=>{if(e.contentWindow){const p=JSON.stringify({eventType:o,eventData:i});e.contentWindow.postMessage(p,t)}},clear:()=>{n.clear(),g===a&&(g=void 0)}};return g=a,a}function We(){const e=U(()=>{},()=>{}),t={...e,send:(r,n)=>{B(r,n)},clear:()=>{var r;e.clear(),g===t&&(g=void 0),(r=window.VBotWebviewProxy)!=null&&r.__isWebComponentProxy&&delete window.VBotWebviewProxy}};return window.VBotWebviewProxy={__isWebComponentProxy:!0,postEvent(r,n){let a;try{a=n?JSON.parse(n):void 0}catch{a=n}e.emit(r,a)}},g=t,t}let g;function Le(){if(!g)throw new Error("HostBridge not initialized. Call defineHostBridge() or defineWebComponentBridge() first.");return g}function ue(e){return({req_id:t})=>t===e}const K={"6.0":["iframe_ready","iframe_will_reload","web_app_close","web_app_data_send","web_app_expand","web_app_open_link","web_app_ready","web_app_request_theme","web_app_request_viewport","web_app_setup_main_button","web_app_setup_closing_behavior"],6.1:["web_app_open_tg_link","web_app_open_invoice","web_app_setup_back_button","web_app_set_background_color","web_app_set_header_color","web_app_trigger_haptic_feedback"],6.2:["web_app_open_popup"],6.4:["web_app_close_scan_qr_popup","web_app_open_scan_qr_popup","web_app_read_text_from_clipboard",{method:"web_app_open_link",param:"try_instant_view"}],6.7:["web_app_switch_inline_query"],6.9:["web_app_invoke_custom_method","web_app_request_write_access","web_app_request_phone",{method:"web_app_set_header_color",param:"color"}],"6.10":["web_app_setup_settings_button"],7.2:["web_app_biometry_get_info","web_app_biometry_open_settings","web_app_biometry_request_access","web_app_biometry_request_auth","web_app_biometry_update_token"],7.6:[{method:"web_app_open_link",param:"try_browser"},{method:"web_app_close",param:"return_back"}],7.7:["web_app_setup_swipe_behavior"],7.8:["web_app_share_to_story"],"7.10":["web_app_setup_secondary_button","web_app_set_bottom_bar_color",{method:"web_app_setup_main_button",param:"has_shine_effect"}],"8.0":["web_app_request_safe_area","web_app_request_content_safe_area","web_app_request_fullscreen","web_app_exit_fullscreen","web_app_set_emoji_status","web_app_add_to_home_screen","web_app_check_home_screen","web_app_request_emoji_status_access","web_app_check_location","web_app_open_location_settings","web_app_request_file_download","web_app_request_location","web_app_send_prepared_message","web_app_start_accelerometer","web_app_start_device_orientation","web_app_start_gyroscope","web_app_stop_accelerometer","web_app_stop_device_orientation","web_app_stop_gyroscope","web_app_toggle_orientation_lock"],"9.0":["web_app_device_storage_clear","web_app_device_storage_get_key","web_app_device_storage_save_key","web_app_secure_storage_clear","web_app_secure_storage_get_key","web_app_secure_storage_restore_key","web_app_secure_storage_save_key"],9.1:["web_app_hide_keyboard"],9.2:["web_app_send_notification","web_app_finish_refresh"]};function O(e,t){return Object.keys(K).find(n=>K[n].some(a=>t?typeof a=="object"&&a.method===e&&a.param===t:a===e))||null}function Y(e){return e.split(".").map(Number)}function _e(e,t){const r=Y(e),n=Y(t),a=Math.max(r.length,n.length);for(let o=0;o<a;o+=1){const i=r[o]||0,p=n[o]||0;if(i!==p)return i>p?1:-1}return 0}function q(e,t,r){const n=r?O(e,t):O(e);return n?_e(n,r||t)<=0:!1}function Ae(e,t="strict"){const r=typeof t=="function"?t:n=>{const{method:a,version:o}=n,i="param"in n?new Z(a,n.param,o):new X(a,o);if(t==="strict")throw i;return m().forceWarn(i.message)};return((n,a)=>q(n,e)?n==="web_app_set_header_color"&&c.is(c.looseObject({color:c.any()}),a)&&!q(n,"color",e)?r({version:e,method:n,param:"color"}):ce(n,a):r({version:e,method:n}))}function le(e,t,r,n){return s.function.pipe(W("web_app_invoke_custom_method","custom_method_invoked",{...n||{},params:{method:e,params:t,req_id:r},capture:ue(r)}),s.taskEither.chain(({result:a,error:o})=>o?s.taskEither.left(new te(o)):s.taskEither.right(a)))}function Oe(e,t,r,n){return S.BetterPromise.fn(()=>s.function.pipe(le(e,t,r,n),s.taskEither.match(a=>{throw a},a=>a))())}function fe(e,t,r={}){const{capture:n=()=>!0,postEvent:a=E}=r,o=y.signal(),[i,p]=l.createCbCollector();(Array.isArray(t)?t:[t]).forEach(u=>{i(F(u,f=>{(Array.isArray(t)?n({event:u,payload:f}):n(f))&&o.set([f])}))});const _=u=>(p(),u);return s.function.pipe(async()=>a(e,r.params),s.taskEither.chainW(()=>l.BetterTaskEither((u,f,d)=>{const w=o();if(w)return u(w[0]);const P=k=>{k&&u(k[0])},L=()=>{o.unsub(P)};o.sub(P),d.on("finalized",L)},r)),s.taskEither.mapBoth(_,_))}function qe(e,t,r){const{postEvent:n}=r||{};return l.throwifyAnyEither(fe(e,t,{...r,postEvent:n?(...a)=>{try{return n(...a),s.either.right(void 0)}catch(o){return s.either.left(o)}}:E}))}function Me(){Object.hasOwn||(Object.hasOwn=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)})}function z(e){return s.either.tryCatch(()=>decodeURIComponent(atob(e.replace(/-/g,"+").replace(/_/g,"/")).split("").map(t=>"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2)).join("")),t=>t)}const je=l.throwifyFpFn(z);function D(e){return btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,r)=>String.fromCharCode(parseInt(`0x${r}`)))).replace(/\+/g,"-").replace(/\//g,"_")}function de(e){const t=D(typeof e=="string"?e:JSON.stringify(e));return t.length>512?s.either.left(new Error("Value is too long for start parameter")):s.either.right(t)}const Re=l.throwifyFpFn(de);function Ue(e,t){return l.throwifyAnyEither(he(e,typeof t=="function"?r=>s.either.tryCatch(()=>t(r),n=>n):t))}function he(e,t){return s.function.pipe(z(e),s.either.chain(r=>t?typeof t=="function"?t(r):s.json.parse(r):s.either.right(r)))}function Ie(e){return D(e).length<=512}Object.defineProperty(exports,"createLogger",{enumerable:!0,get:()=>l.createLogger});Object.defineProperty(exports,"deepSnakeToCamelObjKeys",{enumerable:!0,get:()=>l.deepSnakeToCamelObjKeys});Object.defineProperty(exports,"CancelledError",{enumerable:!0,get:()=>S.CancelledError});Object.defineProperty(exports,"TimeoutError",{enumerable:!0,get:()=>S.TimeoutError});exports.InvalidLaunchParamsError=j;exports.InvokeCustomMethodFailedError=te;exports.LaunchParamsRetrieveError=ee;exports.MethodParameterUnsupportedError=Z;exports.MethodUnsupportedError=X;exports.UnknownEnvError=R;exports.applyPolyfills=Me;exports.captureSameReq=ue;exports.compareVersions=_e;exports.createPostEvent=Ae;exports.createStartParam=Re;exports.createStartParamFp=de;exports.debug=T;exports.decodeBase64Url=je;exports.decodeBase64UrlFp=z;exports.decodeStartParam=Ue;exports.decodeStartParamFp=he;exports.defineHostBridge=Fe;exports.defineWebComponentBridge=We;exports.emitEvent=B;exports.encodeBase64Url=D;exports.getHostBridge=Le;exports.getReleaseVersion=O;exports.hasWebviewProxy=M;exports.invokeCustomMethod=Oe;exports.invokeCustomMethodFp=le;exports.isIframe=V;exports.isSafeToCreateStartParam=Ie;exports.isVBma=xe;exports.isVBmaFp=pe;exports.logger=m;exports.mockVBotEnv=Ce;exports.off=ae;exports.offAll=se;exports.on=F;exports.postEvent=ce;exports.postEventFp=E;exports.postMessage=ie;exports.postMessageImpl=b;exports.request=qe;exports.request2=Se;exports.request2Fp=W;exports.requestFp=fe;exports.resetGlobals=Pe;exports.retrieveLaunchParams=be;exports.retrieveLaunchParamsFp=re;exports.retrieveRawInitData=me;exports.retrieveRawInitDataFp=ne;exports.retrieveRawLaunchParams=ge;exports.retrieveRawLaunchParamsFp=x;exports.setDebug=ve;exports.setLaunchParams=Ve;exports.setTargetOrigin=Ee;exports.supports=q;exports.targetOrigin=$;
|
|
4
4
|
//# sourceMappingURL=index.cjs.map
|