@tma.js/bridge 2.2.0 → 2.2.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/dist/dts/base64-url.d.ts +1 -1
- package/dist/dts/env/isTMA.d.ts +1 -1
- package/dist/dts/errors.d.ts +6 -6
- package/dist/dts/launch-params.d.ts +4 -5
- package/dist/dts/methods/postEvent.d.ts +1 -1
- package/dist/dts/start-param.d.ts +1 -2
- package/dist/dts/utils/invokeCustomMethod.d.ts +1 -1
- package/dist/dts/utils/request.d.ts +1 -1
- package/dist/dts/utils/request2.d.ts +1 -1
- 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 +322 -499
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/dts/base64-url.d.ts
CHANGED
package/dist/dts/env/isTMA.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BetterPromise, BetterPromiseOptions, TimeoutError } from 'better-promises';
|
|
2
|
+
import { taskEither as TE } from 'fp-ts';
|
|
2
3
|
import { Request2Error } from '../utils/request2.js';
|
|
3
|
-
import * as TE from 'fp-ts/TaskEither';
|
|
4
4
|
export type isTMAError = Exclude<Request2Error, TimeoutError>;
|
|
5
5
|
/**
|
|
6
6
|
* @see isTMAFp
|
package/dist/dts/errors.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
declare const MethodUnsupportedError_base: import('error-kid').ErrorClass<[method: string, version: string]>;
|
|
2
|
-
export declare class MethodUnsupportedError extends MethodUnsupportedError_base {
|
|
2
|
+
export declare class MethodUnsupportedError extends /* @__PURE__ */ MethodUnsupportedError_base {
|
|
3
3
|
}
|
|
4
4
|
declare const MethodParameterUnsupportedError_base: import('error-kid').ErrorClass<[method: string, param: string, version: string]>;
|
|
5
|
-
export declare class MethodParameterUnsupportedError extends MethodParameterUnsupportedError_base {
|
|
5
|
+
export declare class MethodParameterUnsupportedError extends /* @__PURE__ */ MethodParameterUnsupportedError_base {
|
|
6
6
|
}
|
|
7
7
|
declare const LaunchParamsRetrieveError_base: import('error-kid').ErrorClassWithData<[{
|
|
8
8
|
source: string;
|
|
@@ -13,15 +13,15 @@ declare const LaunchParamsRetrieveError_base: import('error-kid').ErrorClassWith
|
|
|
13
13
|
error: unknown;
|
|
14
14
|
}[];
|
|
15
15
|
}>;
|
|
16
|
-
export declare class LaunchParamsRetrieveError extends LaunchParamsRetrieveError_base {
|
|
16
|
+
export declare class LaunchParamsRetrieveError extends /* @__PURE__ */ LaunchParamsRetrieveError_base {
|
|
17
17
|
}
|
|
18
18
|
declare const InvalidLaunchParamsError_base: import('error-kid').ErrorClass<[launchParams: string, cause: unknown]>;
|
|
19
|
-
export declare class InvalidLaunchParamsError extends InvalidLaunchParamsError_base {
|
|
19
|
+
export declare class InvalidLaunchParamsError extends /* @__PURE__ */ InvalidLaunchParamsError_base {
|
|
20
20
|
}
|
|
21
21
|
declare const UnknownEnvError_base: import('error-kid').ErrorClass<[]>;
|
|
22
|
-
export declare class UnknownEnvError extends UnknownEnvError_base {
|
|
22
|
+
export declare class UnknownEnvError extends /* @__PURE__ */ UnknownEnvError_base {
|
|
23
23
|
}
|
|
24
24
|
declare const InvokeCustomMethodFailedError_base: import('error-kid').ErrorClass<[error: string]>;
|
|
25
|
-
export declare class InvokeCustomMethodFailedError extends InvokeCustomMethodFailedError_base {
|
|
25
|
+
export declare class InvokeCustomMethodFailedError extends /* @__PURE__ */ InvokeCustomMethodFailedError_base {
|
|
26
26
|
}
|
|
27
27
|
export {};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { LaunchParamsGenType, ParseLaunchParamsQueryError } from '@tma.js/transformers';
|
|
2
|
+
import { either as E, option as O } from 'fp-ts';
|
|
2
3
|
import { LaunchParamsRetrieveError } from './errors.js';
|
|
3
|
-
import * as E from 'fp-ts/Either';
|
|
4
|
-
import * as O from 'fp-ts/Option';
|
|
5
4
|
export type RetrieveRawInitDataError = RetrieveRawLaunchParamsError;
|
|
6
5
|
export type RetrieveRawLaunchParamsError = LaunchParamsRetrieveError;
|
|
7
6
|
export type RetrieveLaunchParamsError = RetrieveRawLaunchParamsError | ParseLaunchParamsQueryError;
|
|
@@ -9,7 +8,7 @@ export type RetrieveLaunchParamsResult = LaunchParamsGenType;
|
|
|
9
8
|
/**
|
|
10
9
|
* @returns Launch parameters from any known source.
|
|
11
10
|
*/
|
|
12
|
-
export declare
|
|
11
|
+
export declare function retrieveLaunchParamsFp(): E.Either<RetrieveLaunchParamsError, RetrieveLaunchParamsResult>;
|
|
13
12
|
/**
|
|
14
13
|
* @see retrieveLaunchParamsFp
|
|
15
14
|
*/
|
|
@@ -17,11 +16,11 @@ export declare const retrieveLaunchParams: () => RetrieveLaunchParamsResult;
|
|
|
17
16
|
/**
|
|
18
17
|
* @returns Raw init data from any known source.
|
|
19
18
|
*/
|
|
20
|
-
export declare
|
|
19
|
+
export declare function retrieveRawInitDataFp(): E.Either<RetrieveRawInitDataError, O.Option<string>>;
|
|
21
20
|
/**
|
|
22
21
|
* @see retrieveRawInitDataFp
|
|
23
22
|
*/
|
|
24
|
-
export declare
|
|
23
|
+
export declare function retrieveRawInitData(): string | undefined;
|
|
25
24
|
/**
|
|
26
25
|
* @returns Launch parameters in a raw format from any known source.
|
|
27
26
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { either as E } from 'fp-ts';
|
|
1
2
|
import { UnknownEnvError } from '../errors.js';
|
|
2
3
|
import { MethodNameWithOptionalParams, MethodNameWithoutParams, MethodNameWithRequiredParams, MethodParams } from './types/index.js';
|
|
3
|
-
import * as E from 'fp-ts/Either';
|
|
4
4
|
export type PostEventError = UnknownEnvError;
|
|
5
5
|
export type PostEventFn = typeof postEvent;
|
|
6
6
|
export type PostEventFpFn = typeof postEventFp;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
+
import { either as E, json as J } from 'fp-ts';
|
|
1
2
|
import { DecodeBase64UrlError } from './base64-url.js';
|
|
2
|
-
import * as E from 'fp-ts/Either';
|
|
3
|
-
import * as J from 'fp-ts/Json';
|
|
4
3
|
/**
|
|
5
4
|
* Creates a safe start parameter value. If the value is not a string, the
|
|
6
5
|
* function applies JSON.stringify to it, so make sure you are not passing an
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BetterPromise } from 'better-promises';
|
|
2
|
+
import { taskEither as TE } from 'fp-ts';
|
|
2
3
|
import { InvokeCustomMethodFailedError } from '../errors.js';
|
|
3
4
|
import { CustomMethodName, CustomMethodParams } from '../methods/types/index.js';
|
|
4
5
|
import { Request2Error, Request2FpOptions, Request2Options } from './request2.js';
|
|
5
|
-
import * as TE from 'fp-ts/TaskEither';
|
|
6
6
|
export type InvokeCustomMethodError = Request2Error | InvokeCustomMethodFailedError;
|
|
7
7
|
export type InvokeCustomMethodOptions = Omit<Request2Options<'custom_method_invoked'>, 'capture'>;
|
|
8
8
|
export type InvokeCustomMethodFn = typeof invokeCustomMethod;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { If, IsNever } from '@tma.js/toolkit';
|
|
2
2
|
import { BetterPromise, BetterPromiseOptions, TimeoutError } from 'better-promises';
|
|
3
|
+
import { taskEither as TE } from 'fp-ts';
|
|
3
4
|
import { EventName, EventPayload } from '../events/types/index.js';
|
|
4
5
|
import { PostEventError, PostEventFn, PostEventFpFn } from '../methods/postEvent.js';
|
|
5
6
|
import { MethodNameWithOptionalParams, MethodNameWithoutParams, MethodNameWithRequiredParams, MethodParams } from '../methods/types/index.js';
|
|
6
|
-
import * as TE from 'fp-ts/TaskEither';
|
|
7
7
|
type AnyEventName = EventName | EventName[];
|
|
8
8
|
export type RequestError = PostEventError | TimeoutError;
|
|
9
9
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { If, IsNever } from '@tma.js/toolkit';
|
|
2
2
|
import { BetterPromise } from 'better-promises';
|
|
3
|
+
import { taskEither as TE } from 'fp-ts';
|
|
3
4
|
import { EventName, EventPayload } from '../events/types/index.js';
|
|
4
5
|
import { MethodNameWithOptionalParams, MethodNameWithRequiredParams, MethodNameWithoutParams, MethodParams } from '../methods/types/index.js';
|
|
5
6
|
import { RequestCaptureEventFn, RequestCaptureEventsFn, RequestCaptureFn, RequestError, RequestFpOptions, RequestOptions, RequestCaptureFnEventsPayload } from './request.js';
|
|
6
|
-
import * as TE from 'fp-ts/TaskEither';
|
|
7
7
|
type AnyEventName = EventName | EventName[];
|
|
8
8
|
export type Request2Error = RequestError;
|
|
9
9
|
export type Request2CaptureEventsFn<E extends EventName[]> = RequestCaptureEventsFn<E>;
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("valibot"),
|
|
2
|
-
`)]){}class
|
|
3
|
-
`),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("valibot"),f=require("@tma.js/toolkit"),k=require("better-promises"),a=require("fp-ts"),y=require("error-kid"),d=require("@tma.js/transformers"),g=require("@tma.js/signals"),me=require("mitt");function j(e){return i.is(i.looseObject({TelegramWebviewProxy:i.looseObject({postEvent:i.function()})}),e)}function L(){try{return window.self!==window.top}catch{return!0}}class N extends y.errorClass("MethodUnsupportedError",(t,r)=>[`Method "${t}" is unsupported in Mini Apps version ${r}`]){}class H extends y.errorClass("MethodParameterUnsupportedError",(t,r,n)=>[`Parameter "${r}" of "${t}" method is unsupported in Mini Apps version ${n}`]){}class Y extends y.errorClassWithData("LaunchParamsRetrieveError",t=>({errors:t}),t=>[["Unable to retrieve launch parameters from any known source. Perhaps, you have opened your app outside Telegram?","📖 Refer to docs for more information:","https://docs.telegram-mini-apps.com/packages/tma-js-bridge/environment","","Collected errors:",...t.map(({source:r,error:n})=>`Source: ${r} / ${n instanceof Error?n.message:String(n)}`)].join(`
|
|
2
|
+
`)]){}class X extends y.errorClass("InvalidLaunchParamsError",(t,r)=>[`Invalid value for launch params: ${t}`,{cause:r}]){}class R extends y.errorClass("UnknownEnvError"){}class Z extends y.errorClass("InvokeCustomMethodError",t=>[`Server returned error: ${t}`]){}const $="launchParams";function z(e){return e.replace(/^[^?#]*[?#]/,"").replace(/[?#]/g,"&")}function ee(){return a.function.pipe(S(),a.either.chainW(d.parseLaunchParamsQueryFp))}const he=f.throwifyFpFn(ee);function te(){return a.function.pipe(S(),a.either.map(e=>{const t=new URLSearchParams(e).get("tgWebAppData");return t?a.option.some(t):a.option.none}))}function de(){return a.function.pipe(te(),a.either.fold(e=>{throw e},e=>e),a.option.match(()=>{},e=>e))}function S(){const e=[];for(const[t,r]of[[()=>z(window.location.href),"window.location.href"],[()=>{const n=performance.getEntriesByType("navigation")[0];return n&&z(n.name)},"performance navigation entries"],[()=>f.getStorageValue($),"local storage"]]){const n=t();if(!n){e.push({source:r,error:new Error("Source is empty")});continue}const s=a.function.pipe(d.parseLaunchParamsQueryFp(n),a.either.foldW(o=>o,()=>!0));if(typeof s!="boolean"){e.push({source:r,error:s});continue}return f.setStorageValue($,n),a.either.right(n)}return a.either.left(new Y(e))}const ge=f.throwifyFpFn(S);function we(e,t){const r=new Map,n=me(),s=(o,c,u=!1)=>{const _=r.get(o)||new Map;r.set(o,_);const p=_.get(c)||[];_.set(c,p);const l=p.findIndex(m=>m[1]===u);if(l>=0&&(n.off(o,p[l][0]),p.splice(l,1),!p.length&&(_.delete(c),!_.size))){const m=r.size;r.delete(o),m&&!r.size&&t()}};return{on(o,c,u){!r.size&&e();const _=()=>{s(o,c,u)},p=(...h)=>{u&&_(),o==="*"?c({name:h[0],payload:h[1]}):c(...h)};n.on(o,p);const l=r.get(o)||new Map;r.set(o,l);const m=l.get(c)||[];return l.set(c,m),m.push([p,u||!1]),_},off:s,emit:n.emit,clear(){const o=r.size;n.all.clear(),r.clear(),o&&t()}}}function T(e,t){window.dispatchEvent(new MessageEvent("message",{data:JSON.stringify({eventType:e,eventData:t}),source:window.parent}))}const C=g.signal(!1),W=g.signal("https://web.telegram.org"),be=e=>{w().log("Event received:",e)},U=g.computed(C);function ye(e){e!==C()&&(C.set(e),(e?F:ne)("*",be))}const I=g.computed(W);function ve(e){W.set(e),w().log("New target origin set",e)}const b=g.signal((...e)=>{window.parent.postMessage(...e)}),w=g.signal(f.createLogger("Bridge",{bgColor:"#9147ff",textColor:"white",shouldLog:U}));function Ee(){oe(),[b,W,I,C,U,w].forEach(e=>{e.unsubAll(),"reset"in e&&e.reset()})}function q(e,t,r){const n=[r],s=e[t];typeof s=="function"&&n.push(s);const o=(...u)=>{n.forEach(_=>_(...u))},c=Object.assign((...u)=>{o(...u)},{unwrap(){const{length:u}=n;if(u===1){delete e[t];return}if(u===2){G(e,t,n[1]);return}n.unshift(1),G(e,t,o)}});re(e,t,()=>c,u=>n.push(u))}function D(e,t){const r=e[t];re(e,t,()=>r,n=>{Object.entries(n).forEach(([s,o])=>{r[s]=o})})}function re(e,t,r,n){Object.defineProperty(e,t,{enumerable:!0,configurable:!0,get:r,set:n})}function G(e,t,r){Object.defineProperty(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r})}const Pe={clipboard_text_received:i.looseObject({req_id:i.string(),data:i.nullish(i.string())}),custom_method_invoked:i.looseObject({req_id:i.string(),result:i.optional(i.unknown()),error:i.optional(i.string())}),popup_closed:i.nullish(i.looseObject({button_id:i.nullish(i.string(),()=>{})}),{}),viewport_changed:i.nullish(i.looseObject({height:i.number(),width:i.nullish(i.number(),()=>window.innerWidth),is_state_stable:i.boolean(),is_expanded:i.boolean()}),()=>({height:window.innerHeight,is_state_stable:!0,is_expanded:!0})),theme_changed:i.looseObject({theme_params:d.themeParams()})};function J(e){if(e.source!==window.parent)return;let t;try{t=i.parse(d.pipeJsonToSchema(d.miniAppsMessage()),e.data)}catch{return}const{eventType:r,eventData:n}=t,s=Pe[r];let o;try{o=s?i.parse(s,n):n}catch(c){return w().forceError([`An error occurred processing the "${r}" event from the Telegram application.`,"Please, file an issue here:","https://github.com/Telegram-Mini-Apps/tma.js/issues/new/choose"].join(`
|
|
3
|
+
`),t,c)}ke(r,o)}const{on:F,off:ne,emit:ke,clear:oe}=we(()=>{const e=window;!e.TelegramGameProxy&&(e.TelegramGameProxy={}),q(e.TelegramGameProxy,"receiveEvent",T),D(e,"TelegramGameProxy"),!e.Telegram&&(e.Telegram={}),!e.Telegram.WebView&&(e.Telegram.WebView={}),q(e.Telegram.WebView,"receiveEvent",T),D(e.Telegram,"WebView"),q(e,"TelegramGameProxy_receiveEvent",T),window.addEventListener("message",J)},()=>{[["TelegramGameProxy_receiveEvent"],["TelegramGameProxy","receiveEvent"],["Telegram","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,s]=r;"unwrap"in s&&(s.unwrap(),n&&n!==t&&!Object.keys(n).length&&delete t[e[0]])}),window.removeEventListener("message",J)}),ae=(...e)=>b()(...e);function se(e,t){a.function.pipe(v(e,t),a.either.mapLeft(r=>{throw r}))}function v(e,t){w().log("Posting event:",t?{eventType:e,eventData:t}:{eventType:e});const r=window,n=JSON.stringify({eventType:e,eventData:t});return L()?(ae(n,I()),a.either.right(void 0)):j(r)?(r.TelegramWebviewProxy.postEvent(e,JSON.stringify(t)),a.either.right(void 0)):i.is(i.looseObject({external:i.looseObject({notify:i.function()})}),r)?(r.external.notify(n),a.either.right(void 0)):a.either.left(new R)}function x(e,t,r={}){const{capture:n=()=>!0,postEvent:s=v}=r,o=g.signal(),[c,u]=f.createCbCollector();(Array.isArray(t)?t:[t]).forEach(p=>{c(F(p,l=>{const m=Array.isArray(t);n(m?{event:p,payload:l}:l)&&o.set([m?{event:p,payload:l}:l])}))});const _=p=>(u(),p);return a.function.pipe(async()=>s(e,r.params),a.taskEither.chainW(()=>f.BetterTaskEither((p,l,m)=>{const h=o();if(h)return p(h[0]);const E=P=>{P&&p(P[0])},M=()=>{o.unsub(E)};o.sub(E),m.on("finalized",M)},r)),a.taskEither.mapBoth(_,_))}function Se(e,t,r){const{postEvent:n}=r||{};return f.throwifyAnyEither(x(e,t,{...r,postEvent:n?(...s)=>{try{return n(...s),a.either.right(void 0)}catch(o){return a.either.left(o)}}:v}))}function Te(e,t){const r=ie(e,t);return typeof r=="function"?k.BetterPromise.fn(()=>f.throwifyAnyEither(r)):r}function ie(e,t){const r=j(window);if(!e)return r||a.function.pipe(S(),a.either.match(()=>!1,()=>!0));if(r)return a.taskEither.right(!0);const{timeout:n=100}=t||{};return a.function.pipe(x("web_app_request_theme","theme_changed",{...t,timeout:n}),a.taskEither.match(s=>k.TimeoutError.is(s)||R.is(s)?a.either.right(!1):a.either.left(s),()=>a.either.right(!0)))}function Ce({launchParams:e,onEvent:t,resetPostMessage:r}={}){if(e){const o=typeof e=="string"||e instanceof URLSearchParams?e.toString():d.serializeLaunchParamsQuery({...e,tgWebAppData:void 0})+(e.tgWebAppData?`&tgWebAppData=${encodeURIComponent(e.tgWebAppData.toString())}`:"");try{d.parseLaunchParamsQuery(o)}catch(c){throw new X(o,c)}f.setStorageValue("launchParams",o)}if(L()){if(!t)return;r&&b.reset();const o=b();b.set((...c)=>{const[u]=c,_=()=>{o(...c)};try{const p=i.parse(d.pipeJsonToSchema(d.miniAppsMessage()),u);t({name:p.eventType,params:p.eventData},_)}catch{_()}});return}const n=window.TelegramWebviewProxy||{},s=n.postEvent||(()=>{});window.TelegramWebviewProxy={...n,postEvent(o,c){const u=()=>{s(o,c)};t?t({name:o,params:c?JSON.parse(c):void 0},u):u()}},w().log("Environment was mocked by the mockTelegramEnv function")}function ce(e){return({req_id:t})=>t===e}const Q={"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"]};function A(e,t){return Object.keys(Q).find(n=>Q[n].some(s=>t?typeof s=="object"&&s.method===e&&s.param===t:s===e))||null}function K(e){return e.split(".").map(Number)}function pe(e,t){const r=K(e),n=K(t),s=Math.max(r.length,n.length);for(let o=0;o<s;o+=1){const c=r[o]||0,u=n[o]||0;if(c!==u)return c>u?1:-1}return 0}function O(e,t,r){const n=r?A(e,t):A(e);return n?pe(n,r||t)<=0:!1}function Fe(e,t="strict"){const r=typeof t=="function"?t:n=>{const{method:s,version:o}=n,c="param"in n?new H(s,n.param,o):new N(s,o);if(t==="strict")throw c;return w().forceWarn(c.message)};return(n,s)=>O(n,e)?n==="web_app_set_header_color"&&i.is(i.looseObject({color:i.any()}),s)&&!O(n,"color",e)?r({version:e,method:n,param:"color"}):se(n,s):r({version:e,method:n})}function ue(e,t,r,n){return a.function.pipe(x("web_app_invoke_custom_method","custom_method_invoked",{...n||{},params:{method:e,params:t,req_id:r},capture:ce(r)}),a.taskEither.chain(({result:s,error:o})=>o?a.taskEither.left(new Z(o)):a.taskEither.right(s)))}function xe(e,t,r,n){return k.BetterPromise.fn(()=>a.function.pipe(ue(e,t,r,n),a.taskEither.match(s=>{throw s},s=>s))())}function _e(e,t,r={}){const{capture:n=()=>!0,postEvent:s=v}=r,o=g.signal(),[c,u]=f.createCbCollector();(Array.isArray(t)?t:[t]).forEach(p=>{c(F(p,l=>{(Array.isArray(t)?n({event:p,payload:l}):n(l))&&o.set([l])}))});const _=p=>(u(),p);return a.function.pipe(async()=>s(e,r.params),a.taskEither.chainW(()=>f.BetterTaskEither((p,l,m)=>{const h=o();if(h)return p(h[0]);const E=P=>{P&&p(P[0])},M=()=>{o.unsub(E)};o.sub(E),m.on("finalized",M)},r)),a.taskEither.mapBoth(_,_))}function Me(e,t,r){const{postEvent:n}=r||{};return f.throwifyAnyEither(_e(e,t,{...r,postEvent:n?(...s)=>{try{return n(...s),a.either.right(void 0)}catch(o){return a.either.left(o)}}:v}))}function qe(){Object.hasOwn||(Object.hasOwn=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)})}function B(e){return a.either.tryCatch(()=>decodeURIComponent(atob(e.replace(/-/g,"+").replace(/_/g,"/")).split("").map(t=>"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2)).join("")),t=>t)}const Ae=f.throwifyFpFn(B);function V(e){return btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(t,r)=>String.fromCharCode(parseInt(`0x${r}`)))).replace(/\+/g,"-").replace(/\//g,"_")}function le(e){const t=V(typeof e=="string"?e:JSON.stringify(e));return t.length>512?a.either.left(new Error("Value is too long for start parameter")):a.either.right(t)}const Oe=f.throwifyFpFn(le);function je(e,t){return f.throwifyAnyEither(fe(e,typeof t=="function"?r=>a.either.tryCatch(()=>t(r),n=>n):t))}function fe(e,t){return a.function.pipe(B(e),a.either.chain(r=>t?typeof t=="function"?t(r):a.json.parse(r):a.either.right(r)))}function Le(e){return V(e).length<=512}Object.defineProperty(exports,"createLogger",{enumerable:!0,get:()=>f.createLogger});Object.defineProperty(exports,"deepSnakeToCamelObjKeys",{enumerable:!0,get:()=>f.deepSnakeToCamelObjKeys});Object.defineProperty(exports,"CancelledError",{enumerable:!0,get:()=>k.CancelledError});Object.defineProperty(exports,"TimeoutError",{enumerable:!0,get:()=>k.TimeoutError});exports.InvalidLaunchParamsError=X;exports.InvokeCustomMethodFailedError=Z;exports.LaunchParamsRetrieveError=Y;exports.MethodParameterUnsupportedError=H;exports.MethodUnsupportedError=N;exports.UnknownEnvError=R;exports.applyPolyfills=qe;exports.captureSameReq=ce;exports.compareVersions=pe;exports.createPostEvent=Fe;exports.createStartParam=Oe;exports.createStartParamFp=le;exports.debug=U;exports.decodeBase64Url=Ae;exports.decodeBase64UrlFp=B;exports.decodeStartParam=je;exports.decodeStartParamFp=fe;exports.emitEvent=T;exports.encodeBase64Url=V;exports.getReleaseVersion=A;exports.hasWebviewProxy=j;exports.invokeCustomMethod=xe;exports.invokeCustomMethodFp=ue;exports.isIframe=L;exports.isSafeToCreateStartParam=Le;exports.isTMA=Te;exports.isTMAFp=ie;exports.logger=w;exports.mockTelegramEnv=Ce;exports.off=ne;exports.offAll=oe;exports.on=F;exports.postEvent=se;exports.postEventFp=v;exports.postMessage=ae;exports.postMessageImpl=b;exports.request=Me;exports.request2=Se;exports.request2Fp=x;exports.requestFp=_e;exports.resetGlobals=Ee;exports.retrieveLaunchParams=he;exports.retrieveLaunchParamsFp=ee;exports.retrieveRawInitData=de;exports.retrieveRawInitDataFp=te;exports.retrieveRawLaunchParams=ge;exports.retrieveRawLaunchParamsFp=S;exports.setDebug=ye;exports.setTargetOrigin=ve;exports.supports=O;exports.targetOrigin=I;
|
|
4
4
|
//# sourceMappingURL=index.cjs.map
|