@tma.js/bridge 2.1.3 → 2.2.1
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/env/isTMA.d.ts +2 -2
- package/dist/dts/errors.d.ts +6 -6
- package/dist/dts/index.d.ts +2 -1
- package/dist/dts/launch-params.d.ts +3 -3
- package/dist/dts/utils/invokeCustomMethod.d.ts +6 -6
- package/dist/dts/utils/request.d.ts +14 -2
- package/dist/dts/utils/request2.d.ts +62 -0
- 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 +374 -306
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/dts/env/isTMA.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BetterPromise, BetterPromiseOptions, TimeoutError } from 'better-promises';
|
|
2
|
-
import {
|
|
2
|
+
import { Request2Error } from '../utils/request2.js';
|
|
3
3
|
import * as TE from 'fp-ts/TaskEither';
|
|
4
|
-
export type isTMAError = Exclude<
|
|
4
|
+
export type isTMAError = Exclude<Request2Error, TimeoutError>;
|
|
5
5
|
/**
|
|
6
6
|
* @see isTMAFp
|
|
7
7
|
*/
|
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 {};
|
package/dist/dts/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ export { hasWebviewProxy } from './env/hasWebviewProxy.js';
|
|
|
2
2
|
export { isIframe } from './env/isIframe.js';
|
|
3
3
|
export { isTMA, isTMAFp, type isTMAError } from './env/isTMA.js';
|
|
4
4
|
export { mockTelegramEnv } from './env/mockTelegramEnv.js';
|
|
5
|
-
export { emitEvent } from './events/emitEvent.js';
|
|
6
5
|
export { off, offAll, on } from './events/emitter.js';
|
|
6
|
+
export { emitEvent } from './events/emitEvent.js';
|
|
7
7
|
export type { EventListener, SubscribeListener, Events, WriteAccessRequestedStatus, EmojiStatusAccessRequestedStatus, BiometryAuthRequestStatus, BiometryTokenUpdateStatus, BiometryType, EmojiStatusFailedError, EventName, EventPayload, EventWithoutPayload, EventWithPayload, PhoneRequestedStatus, FullScreenErrorStatus, HomeScreenStatus, InvoiceStatus, SafeAreaInsets, } from './events/types/index.js';
|
|
8
8
|
export { captureSameReq } from './methods/captureSameReq.js';
|
|
9
9
|
export { createPostEvent, type CreatePostEventMode, type OnUnsupportedFn, } from './methods/createPostEvent.js';
|
|
@@ -15,6 +15,7 @@ export type { AnyHapticFeedbackParams, AnyInvokeCustomMethodParams, CreateMethod
|
|
|
15
15
|
export { compareVersions } from './utils/compareVersions.js';
|
|
16
16
|
export { invokeCustomMethod, invokeCustomMethodFp, type InvokeCustomMethodFn, type InvokeCustomMethodOptions, type InvokeCustomMethodFpFn, type InvokeCustomMethodError, type InvokeCustomMethodFpOptions, } from './utils/invokeCustomMethod.js';
|
|
17
17
|
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';
|
|
18
|
+
export { request2, request2Fp, type Request2CaptureEventFn, type Request2CaptureEventsFn, type Request2CaptureFn, type Request2CaptureFnEventsPayload, type Request2Fn, type Request2Options, type Request2Result, type Request2Error, type Request2FpOptions, type Request2FpFn, } from './utils/request2.js';
|
|
18
19
|
export { applyPolyfills } from './applyPolyfills.js';
|
|
19
20
|
export { decodeBase64Url, encodeBase64Url, decodeBase64UrlFp, type DecodeBase64UrlError, } from './base64-url.js';
|
|
20
21
|
export { LaunchParamsRetrieveError, InvalidLaunchParamsError, InvokeCustomMethodFailedError, MethodParameterUnsupportedError, MethodUnsupportedError, UnknownEnvError, } from './errors.js';
|
|
@@ -9,7 +9,7 @@ export type RetrieveLaunchParamsResult = LaunchParamsGenType;
|
|
|
9
9
|
/**
|
|
10
10
|
* @returns Launch parameters from any known source.
|
|
11
11
|
*/
|
|
12
|
-
export declare
|
|
12
|
+
export declare function retrieveLaunchParamsFp(): E.Either<RetrieveLaunchParamsError, RetrieveLaunchParamsResult>;
|
|
13
13
|
/**
|
|
14
14
|
* @see retrieveLaunchParamsFp
|
|
15
15
|
*/
|
|
@@ -17,11 +17,11 @@ export declare const retrieveLaunchParams: () => RetrieveLaunchParamsResult;
|
|
|
17
17
|
/**
|
|
18
18
|
* @returns Raw init data from any known source.
|
|
19
19
|
*/
|
|
20
|
-
export declare
|
|
20
|
+
export declare function retrieveRawInitDataFp(): E.Either<RetrieveRawInitDataError, O.Option<string>>;
|
|
21
21
|
/**
|
|
22
22
|
* @see retrieveRawInitDataFp
|
|
23
23
|
*/
|
|
24
|
-
export declare
|
|
24
|
+
export declare function retrieveRawInitData(): string | undefined;
|
|
25
25
|
/**
|
|
26
26
|
* @returns Launch parameters in a raw format from any known source.
|
|
27
27
|
*/
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { BetterPromise } from 'better-promises';
|
|
2
|
-
import { CustomMethodName, CustomMethodParams } from '../methods/types/index.js';
|
|
3
2
|
import { InvokeCustomMethodFailedError } from '../errors.js';
|
|
4
|
-
import {
|
|
3
|
+
import { CustomMethodName, CustomMethodParams } from '../methods/types/index.js';
|
|
4
|
+
import { Request2Error, Request2FpOptions, Request2Options } from './request2.js';
|
|
5
5
|
import * as TE from 'fp-ts/TaskEither';
|
|
6
|
-
export type InvokeCustomMethodError =
|
|
7
|
-
export type InvokeCustomMethodOptions = Omit<
|
|
6
|
+
export type InvokeCustomMethodError = Request2Error | InvokeCustomMethodFailedError;
|
|
7
|
+
export type InvokeCustomMethodOptions = Omit<Request2Options<'custom_method_invoked'>, 'capture'>;
|
|
8
8
|
export type InvokeCustomMethodFn = typeof invokeCustomMethod;
|
|
9
|
-
export type InvokeCustomMethodFpOptions = Omit<
|
|
9
|
+
export type InvokeCustomMethodFpOptions = Omit<Request2FpOptions<'custom_method_invoked'>, 'capture'>;
|
|
10
10
|
export type InvokeCustomMethodFpFn = typeof invokeCustomMethodFp;
|
|
11
11
|
/**
|
|
12
12
|
* Invokes known custom method. Returns method execution result.
|
|
@@ -23,7 +23,7 @@ export declare function invokeCustomMethodFp<M extends CustomMethodName>(method:
|
|
|
23
23
|
* @param requestId - request identifier.
|
|
24
24
|
* @param options - additional options.
|
|
25
25
|
*/
|
|
26
|
-
export declare function invokeCustomMethodFp(method: string, params: object, requestId: string, options?: InvokeCustomMethodFpOptions): TE.TaskEither<
|
|
26
|
+
export declare function invokeCustomMethodFp(method: string, params: object, requestId: string, options?: InvokeCustomMethodFpOptions): TE.TaskEither<Request2Error, unknown>;
|
|
27
27
|
/**
|
|
28
28
|
* @see invokeCustomMethodFp
|
|
29
29
|
*/
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { BetterPromise, BetterPromiseOptions, TimeoutError } from 'better-promises';
|
|
2
1
|
import { If, IsNever } from '@tma.js/toolkit';
|
|
2
|
+
import { BetterPromise, BetterPromiseOptions, TimeoutError } from 'better-promises';
|
|
3
|
+
import { EventName, EventPayload } from '../events/types/index.js';
|
|
3
4
|
import { PostEventError, PostEventFn, PostEventFpFn } from '../methods/postEvent.js';
|
|
4
5
|
import { MethodNameWithOptionalParams, MethodNameWithoutParams, MethodNameWithRequiredParams, MethodParams } from '../methods/types/index.js';
|
|
5
|
-
import { EventName, EventPayload } from '../events/types/index.js';
|
|
6
6
|
import * as TE from 'fp-ts/TaskEither';
|
|
7
7
|
type AnyEventName = EventName | EventName[];
|
|
8
8
|
export type RequestError = PostEventError | TimeoutError;
|
|
@@ -51,6 +51,8 @@ export type RequestFpFn = typeof requestFp;
|
|
|
51
51
|
* @param method - method name.
|
|
52
52
|
* @param eventOrEvents - tracked event or events.
|
|
53
53
|
* @param options - additional options.
|
|
54
|
+
* @deprecated To be removed in the next major update. Use `request2fp` instead, it provides
|
|
55
|
+
* a proper way of handling multiple events.
|
|
54
56
|
*/
|
|
55
57
|
export declare function requestFp<M extends MethodNameWithRequiredParams, E extends AnyEventName, AbortError = never>(method: M, eventOrEvents: E, options: RequestFpOptions<E> & {
|
|
56
58
|
params: MethodParams<M>;
|
|
@@ -60,6 +62,8 @@ export declare function requestFp<M extends MethodNameWithRequiredParams, E exte
|
|
|
60
62
|
* @param method - method name.
|
|
61
63
|
* @param eventOrEvents - tracked event or events.
|
|
62
64
|
* @param options - additional options.
|
|
65
|
+
* @deprecated To be removed in the next major update. Use `request2fp` instead, it provides
|
|
66
|
+
* a proper way of handling multiple events.
|
|
63
67
|
*/
|
|
64
68
|
export declare function requestFp<M extends MethodNameWithOptionalParams, E extends AnyEventName, AbortError = never>(method: M, eventOrEvents: E, options?: RequestFpOptions<E> & {
|
|
65
69
|
params?: MethodParams<M>;
|
|
@@ -69,22 +73,30 @@ export declare function requestFp<M extends MethodNameWithOptionalParams, E exte
|
|
|
69
73
|
* @param method - method name.
|
|
70
74
|
* @param eventOrEvents - tracked event or events.
|
|
71
75
|
* @param options - additional options.
|
|
76
|
+
* @deprecated To be removed in the next major update. Use `request2fp` instead, it provides
|
|
77
|
+
* a proper way of handling multiple events.
|
|
72
78
|
*/
|
|
73
79
|
export declare function requestFp<M extends MethodNameWithoutParams, E extends AnyEventName, AbortError = never>(method: M, eventOrEvents: E, options?: RequestFpOptions<E>): TE.TaskEither<RequestError | AbortError, RequestResult<E>>;
|
|
74
80
|
/**
|
|
75
81
|
* @see requestFp
|
|
82
|
+
* @deprecated To be removed in the next major update. Use `request2` instead, it provides
|
|
83
|
+
* a proper way of handling multiple events.
|
|
76
84
|
*/
|
|
77
85
|
export declare function request<M extends MethodNameWithRequiredParams, E extends AnyEventName>(method: M, eventOrEvents: E, options: RequestOptions<E> & {
|
|
78
86
|
params: MethodParams<M>;
|
|
79
87
|
}): BetterPromise<RequestResult<E>>;
|
|
80
88
|
/**
|
|
81
89
|
* @see requestFp
|
|
90
|
+
* @deprecated To be removed in the next major update. Use `request2` instead, it provides
|
|
91
|
+
* a proper way of handling multiple events.
|
|
82
92
|
*/
|
|
83
93
|
export declare function request<M extends MethodNameWithOptionalParams, E extends AnyEventName>(method: M, eventOrEvents: E, options?: RequestOptions<E> & {
|
|
84
94
|
params?: MethodParams<M>;
|
|
85
95
|
}): BetterPromise<RequestResult<E>>;
|
|
86
96
|
/**
|
|
87
97
|
* @see requestFp
|
|
98
|
+
* @deprecated To be removed in the next major update. Use `request2` instead, it provides
|
|
99
|
+
* a proper way of handling multiple events.
|
|
88
100
|
*/
|
|
89
101
|
export declare function request<M extends MethodNameWithoutParams, E extends AnyEventName>(method: M, eventOrEvents: E, options?: RequestOptions<E>): BetterPromise<RequestResult<E>>;
|
|
90
102
|
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { If, IsNever } from '@tma.js/toolkit';
|
|
2
|
+
import { BetterPromise } from 'better-promises';
|
|
3
|
+
import { EventName, EventPayload } from '../events/types/index.js';
|
|
4
|
+
import { MethodNameWithOptionalParams, MethodNameWithRequiredParams, MethodNameWithoutParams, MethodParams } from '../methods/types/index.js';
|
|
5
|
+
import { RequestCaptureEventFn, RequestCaptureEventsFn, RequestCaptureFn, RequestError, RequestFpOptions, RequestOptions, RequestCaptureFnEventsPayload } from './request.js';
|
|
6
|
+
import * as TE from 'fp-ts/TaskEither';
|
|
7
|
+
type AnyEventName = EventName | EventName[];
|
|
8
|
+
export type Request2Error = RequestError;
|
|
9
|
+
export type Request2CaptureEventsFn<E extends EventName[]> = RequestCaptureEventsFn<E>;
|
|
10
|
+
export type Request2CaptureEventFn<E extends EventName> = RequestCaptureEventFn<E>;
|
|
11
|
+
export type Request2CaptureFn<E extends AnyEventName> = RequestCaptureFn<E>;
|
|
12
|
+
export type Request2Options<E extends AnyEventName> = RequestOptions<E>;
|
|
13
|
+
export type Request2FpOptions<E extends AnyEventName> = RequestFpOptions<E>;
|
|
14
|
+
export type Request2CaptureFnEventsPayload<E extends EventName[]> = RequestCaptureFnEventsPayload<E>;
|
|
15
|
+
export type Request2Result<E extends AnyEventName> = E extends (infer U extends EventName)[] ? U extends infer K extends EventName ? {
|
|
16
|
+
event: K;
|
|
17
|
+
payload: If<IsNever<EventPayload<K>>, undefined, EventPayload<K>>;
|
|
18
|
+
} : never : E extends EventName ? If<IsNever<EventPayload<E>>, undefined, EventPayload<E>> : never;
|
|
19
|
+
export type Request2Fn = typeof request2;
|
|
20
|
+
export type Request2FpFn = typeof request2Fp;
|
|
21
|
+
/**
|
|
22
|
+
* Calls a method waiting for the specified event(-s) to occur.
|
|
23
|
+
* @param method - method name.
|
|
24
|
+
* @param eventOrEvents - tracked event or events.
|
|
25
|
+
* @param options - additional options.
|
|
26
|
+
*/
|
|
27
|
+
export declare function request2Fp<M extends MethodNameWithRequiredParams, E extends AnyEventName, AbortError = never>(method: M, eventOrEvents: E, options: Request2FpOptions<E> & {
|
|
28
|
+
params: MethodParams<M>;
|
|
29
|
+
}): TE.TaskEither<Request2Error | AbortError, Request2Result<E>>;
|
|
30
|
+
/**
|
|
31
|
+
* Calls a method waiting for the specified event(-s) to occur.
|
|
32
|
+
* @param method - method name.
|
|
33
|
+
* @param eventOrEvents - tracked event or events.
|
|
34
|
+
* @param options - additional options.
|
|
35
|
+
*/
|
|
36
|
+
export declare function request2Fp<M extends MethodNameWithOptionalParams, E extends AnyEventName, AbortError = never>(method: M, eventOrEvents: E, options?: Request2FpOptions<E> & {
|
|
37
|
+
params?: MethodParams<M>;
|
|
38
|
+
}): TE.TaskEither<Request2Error | AbortError, Request2Result<E>>;
|
|
39
|
+
/**
|
|
40
|
+
* Calls a method waiting for the specified event(-s) to occur.
|
|
41
|
+
* @param method - method name.
|
|
42
|
+
* @param eventOrEvents - tracked event or events.
|
|
43
|
+
* @param options - additional options.
|
|
44
|
+
*/
|
|
45
|
+
export declare function request2Fp<M extends MethodNameWithoutParams, E extends AnyEventName, AbortError = never>(method: M, eventOrEvents: E, options?: Request2FpOptions<E>): TE.TaskEither<Request2Error | AbortError, Request2Result<E>>;
|
|
46
|
+
/**
|
|
47
|
+
* @see request2Fp
|
|
48
|
+
*/
|
|
49
|
+
export declare function request2<M extends MethodNameWithRequiredParams, E extends AnyEventName>(method: M, eventOrEvents: E, options: Request2Options<E> & {
|
|
50
|
+
params: MethodParams<M>;
|
|
51
|
+
}): BetterPromise<Request2Result<E>>;
|
|
52
|
+
/**
|
|
53
|
+
* @see request2Fp
|
|
54
|
+
*/
|
|
55
|
+
export declare function request2<M extends MethodNameWithOptionalParams, E extends AnyEventName>(method: M, eventOrEvents: E, options?: Request2Options<E> & {
|
|
56
|
+
params?: MethodParams<M>;
|
|
57
|
+
}): BetterPromise<Request2Result<E>>;
|
|
58
|
+
/**
|
|
59
|
+
* @see request2Fp
|
|
60
|
+
*/
|
|
61
|
+
export declare function request2<M extends MethodNameWithoutParams, E extends AnyEventName>(method: M, eventOrEvents: E, options?: Request2Options<E>): BetterPromise<Request2Result<E>>;
|
|
62
|
+
export {};
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("valibot"),_=require("@tma.js/toolkit"),
|
|
2
|
-
`)]){}class
|
|
3
|
-
`),r,s)}
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("valibot"),_=require("@tma.js/toolkit"),A=require("better-promises"),E=require("error-kid"),w=require("@tma.js/transformers"),b=require("@tma.js/signals"),Oe=require("mitt");function U(e){return i.is(i.looseObject({TelegramWebviewProxy:i.looseObject({postEvent:i.function()})}),e)}function W(){try{return window.self!==window.top}catch{return!0}}var Le=function(e,r,t){if(t||arguments.length===2)for(var n=0,o=r.length,a;n<o;n++)(a||!(n in r))&&(a||(a=Array.prototype.slice.call(r,0,n)),a[n]=r[n]);return e.concat(a||Array.prototype.slice.call(r))};function $e(e){return e}function re(e,r,t,n,o,a,s,u,p){switch(arguments.length){case 1:return e;case 2:return function(){return r(e.apply(this,arguments))};case 3:return function(){return t(r(e.apply(this,arguments)))};case 4:return function(){return n(t(r(e.apply(this,arguments))))};case 5:return function(){return o(n(t(r(e.apply(this,arguments)))))};case 6:return function(){return a(o(n(t(r(e.apply(this,arguments))))))};case 7:return function(){return s(a(o(n(t(r(e.apply(this,arguments)))))))};case 8:return function(){return u(s(a(o(n(t(r(e.apply(this,arguments))))))))};case 9:return function(){return p(u(s(a(o(n(t(r(e.apply(this,arguments)))))))))}}}function m(e,r,t,n,o,a,s,u,p){switch(arguments.length){case 1:return e;case 2:return r(e);case 3:return t(r(e));case 4:return n(t(r(e)));case 5:return o(n(t(r(e))));case 6:return a(o(n(t(r(e)))));case 7:return s(a(o(n(t(r(e))))));case 8:return u(s(a(o(n(t(r(e)))))));case 9:return p(u(s(a(o(n(t(r(e))))))));default:{for(var c=arguments[0],l=1;l<arguments.length;l++)c=arguments[l](c);return c}}}var C=function(e,r){var t=typeof e=="number"?function(n){return n.length>=e}:e;return function(){var n=Array.from(arguments);return t(arguments)?r.apply(this,n):function(o){return r.apply(void 0,Le([o],n,!1))}}},je={_tag:"None"},Re=function(e){return{_tag:"Some",value:e}},Ue=function(e){return e._tag==="Left"},We=function(e){return{_tag:"Left",left:e}},Ie=function(e){return{_tag:"Right",right:e}},g=We,f=Ie,te=C(2,function(e,r){return P(e)?e:r(e.right)}),Be=function(e){return function(r){return P(r)?r:f(e(r.right))}},Ve=function(e,r){return function(t){return P(t)?g(e(t.left)):f(r(t.right))}},ze=function(e){return function(r){return P(r)?g(e(r.left)):r}},P=Ue,ne=function(e,r){return function(t){return P(t)?e(t.left):r(t.right)}},De=ne,I=ne,Ge=I,B=function(e,r){try{return f(e())}catch(t){return g(r(t))}},Je=te,Ne=te,Qe=je,Ke=Re,He=function(e){return e._tag==="None"},Ye=function(e,r){return function(t){return He(t)?e():r(t.value)}},Xe=Ye;function Ze(e){return re(f,e.of)}function er(e){return re(g,e.of)}function rr(e){return function(r,t){return e.chain(r,function(n){return P(n)?e.of(n):t(n.right)})}}function tr(e){return function(r,t,n){return e.map(r,Ve(t,n))}}function nr(e){return function(r,t){return function(n){return e.map(n,I(r,t))}}}var ae=function(e,r){return m(e,or(r))},ar=function(e,r){return m(e,sr(r))},or=function(e){return function(r){return function(){return Promise.resolve().then(r).then(e)}}},sr=function(e){return function(r){return function(){return Promise.all([Promise.resolve().then(r),Promise.resolve().then(e)]).then(function(t){var n=t[0],o=t[1];return n(o)})}}},oe=function(e){return function(){return Promise.resolve(e)}},ir=C(2,function(e,r){return function(){return Promise.resolve().then(e).then(function(t){return r(t)()})}}),se="Task",ie={URI:se,map:ae},ue={of:oe},ur={URI:se,map:ae,of:oe,ap:ar,chain:ir},cr=er(ue),ce=Ze(ue),pe=nr(ie),le=C(3,tr(ie)),_e=C(2,rr(ur)),pr=_e,fe=_e;class me extends E.errorClass("MethodUnsupportedError",(r,t)=>[`Method "${r}" is unsupported in Mini Apps version ${t}`]){}class he extends E.errorClass("MethodParameterUnsupportedError",(r,t,n)=>[`Parameter "${t}" of "${r}" method is unsupported in Mini Apps version ${n}`]){}class ge extends E.errorClassWithData("LaunchParamsRetrieveError",r=>({errors:r}),r=>[["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:",...r.map(({source:t,error:n})=>`Source: ${t} / ${n instanceof Error?n.message:String(n)}`)].join(`
|
|
2
|
+
`)]){}class de extends E.errorClass("InvalidLaunchParamsError",(r,t)=>[`Invalid value for launch params: ${r}`,{cause:t}]){}class V extends E.errorClass("UnknownEnvError"){}class we extends E.errorClass("InvokeCustomMethodError",r=>[`Server returned error: ${r}`]){}const Q="launchParams";function K(e){return e.replace(/^[^?#]*[?#]/,"").replace(/[?#]/g,"&")}function be(){return m(x(),Je(w.parseLaunchParamsQueryFp))}const lr=_.throwifyFpFn(be);function ve(){return m(x(),Be(e=>{const r=new URLSearchParams(e).get("tgWebAppData");return r?Ke(r):Qe}))}function _r(){return m(ve(),Ge(e=>{throw e},e=>e),Xe(()=>{},e=>e))}function x(){const e=[];for(const[r,t]of[[()=>K(window.location.href),"window.location.href"],[()=>{const n=performance.getEntriesByType("navigation")[0];return n&&K(n.name)},"performance navigation entries"],[()=>_.getStorageValue(Q),"local storage"]]){const n=r();if(!n){e.push({source:t,error:new Error("Source is empty")});continue}const o=m(w.parseLaunchParamsQueryFp(n),De(a=>a,()=>!0));if(typeof o!="boolean"){e.push({source:t,error:o});continue}return _.setStorageValue(Q,n),f(n)}return g(new ge(e))}const fr=_.throwifyFpFn(x);function mr(e,r){const t=new Map,n=Oe(),o=(a,s,u=!1)=>{const p=t.get(a)||new Map;t.set(a,p);const c=p.get(s)||[];p.set(s,c);const l=c.findIndex(h=>h[1]===u);if(l>=0&&(n.off(a,c[l][0]),c.splice(l,1),!c.length&&(p.delete(s),!p.size))){const h=t.size;t.delete(a),h&&!t.size&&r()}};return{on(a,s,u){!t.size&&e();const p=()=>{o(a,s,u)},c=(...d)=>{u&&p(),a==="*"?s({name:d[0],payload:d[1]}):s(...d)};n.on(a,c);const l=t.get(a)||new Map;t.set(a,l);const h=l.get(s)||[];return l.set(s,h),h.push([c,u||!1]),p},off:o,emit:n.emit,clear(){const a=t.size;n.all.clear(),t.clear(),a&&r()}}}function F(e,r){window.dispatchEvent(new MessageEvent("message",{data:JSON.stringify({eventType:e,eventData:r}),source:window.parent}))}const M=b.signal(!1),z=b.signal("https://web.telegram.org"),hr=e=>{v().log("Event received:",e)},D=b.computed(M);function gr(e){e!==M()&&(M.set(e),(e?q:Ee)("*",hr))}const G=b.computed(z);function dr(e){z.set(e),v().log("New target origin set",e)}const y=b.signal((...e)=>{window.parent.postMessage(...e)}),v=b.signal(_.createLogger("Bridge",{bgColor:"#9147ff",textColor:"white",shouldLog:D}));function wr(){Pe(),[y,z,G,M,D,v].forEach(e=>{e.unsubAll(),"reset"in e&&e.reset()})}function $(e,r,t){const n=[t],o=e[r];typeof o=="function"&&n.push(o);const a=(...u)=>{n.forEach(p=>p(...u))},s=Object.assign((...u)=>{a(...u)},{unwrap(){const{length:u}=n;if(u===1){delete e[r];return}if(u===2){Y(e,r,n[1]);return}n.unshift(1),Y(e,r,a)}});ye(e,r,()=>s,u=>n.push(u))}function H(e,r){const t=e[r];ye(e,r,()=>t,n=>{Object.entries(n).forEach(([o,a])=>{t[o]=a})})}function ye(e,r,t,n){Object.defineProperty(e,r,{enumerable:!0,configurable:!0,get:t,set:n})}function Y(e,r,t){Object.defineProperty(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t})}const br={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:w.themeParams()})};function X(e){if(e.source!==window.parent)return;let r;try{r=i.parse(w.pipeJsonToSchema(w.miniAppsMessage()),e.data)}catch{return}const{eventType:t,eventData:n}=r,o=br[t];let a;try{a=o?i.parse(o,n):n}catch(s){return v().forceError([`An error occurred processing the "${t}" event from the Telegram application.`,"Please, file an issue here:","https://github.com/Telegram-Mini-Apps/tma.js/issues/new/choose"].join(`
|
|
3
|
+
`),r,s)}vr(t,a)}const{on:q,off:Ee,emit:vr,clear:Pe}=mr(()=>{const e=window;!e.TelegramGameProxy&&(e.TelegramGameProxy={}),$(e.TelegramGameProxy,"receiveEvent",F),H(e,"TelegramGameProxy"),!e.Telegram&&(e.Telegram={}),!e.Telegram.WebView&&(e.Telegram.WebView={}),$(e.Telegram.WebView,"receiveEvent",F),H(e.Telegram,"WebView"),$(e,"TelegramGameProxy_receiveEvent",F),window.addEventListener("message",X)},()=>{[["TelegramGameProxy_receiveEvent"],["TelegramGameProxy","receiveEvent"],["Telegram","WebView","receiveEvent"]].forEach(e=>{const r=window;let t=[void 0,r];for(const a of e)if(t=[t[1],t[1][a]],!t[1])return;const[n,o]=t;"unwrap"in o&&(o.unwrap(),n&&n!==r&&!Object.keys(n).length&&delete r[e[0]])}),window.removeEventListener("message",X)}),ke=(...e)=>y()(...e);function Se(e,r){m(k(e,r),ze(t=>{throw t}))}function k(e,r){v().log("Posting event:",r?{eventType:e,eventData:r}:{eventType:e});const t=window,n=JSON.stringify({eventType:e,eventData:r});return W()?(ke(n,G()),f(void 0)):U(t)?(t.TelegramWebviewProxy.postEvent(e,JSON.stringify(r)),f(void 0)):i.is(i.looseObject({external:i.looseObject({notify:i.function()})}),t)?(t.external.notify(n),f(void 0)):g(new V)}function O(e,r,t={}){const{capture:n=()=>!0,postEvent:o=k}=t,a=b.signal(),[s,u]=_.createCbCollector();(Array.isArray(r)?r:[r]).forEach(c=>{s(q(c,l=>{const h=Array.isArray(r);n(h?{event:c,payload:l}:l)&&a.set([h?{event:c,payload:l}:l])}))});const p=c=>(u(),c);return m(async()=>o(e,t.params),fe(()=>_.BetterTaskEither((c,l,h)=>{const d=a();if(d)return c(d[0]);const S=T=>{T&&c(T[0])},L=()=>{a.unsub(S)};a.sub(S),h.on("finalized",L)},t)),le(p,p))}function yr(e,r,t){const{postEvent:n}=t||{};return _.throwifyAnyEither(O(e,r,{...t,postEvent:n?(...o)=>{try{return n(...o),f(void 0)}catch(a){return g(a)}}:k}))}function Er(e,r){const t=Te(e,r);return typeof t=="function"?A.BetterPromise.fn(()=>_.throwifyAnyEither(t)):t}function Te(e,r){const t=U(window);if(!e)return t||m(x(),I(()=>!1,()=>!0));if(t)return ce(!0);const{timeout:n=100}=r||{};return m(O("web_app_request_theme","theme_changed",{...r,timeout:n}),pe(o=>A.TimeoutError.is(o)||V.is(o)?f(!1):g(o),()=>f(!0)))}function Pr({launchParams:e,onEvent:r,resetPostMessage:t}={}){if(e){const a=typeof e=="string"||e instanceof URLSearchParams?e.toString():w.serializeLaunchParamsQuery({...e,tgWebAppData:void 0})+(e.tgWebAppData?`&tgWebAppData=${encodeURIComponent(e.tgWebAppData.toString())}`:"");try{w.parseLaunchParamsQuery(a)}catch(s){throw new de(a,s)}_.setStorageValue("launchParams",a)}if(W()){if(!r)return;t&&y.reset();const a=y();y.set((...s)=>{const[u]=s,p=()=>{a(...s)};try{const c=i.parse(w.pipeJsonToSchema(w.miniAppsMessage()),u);r({name:c.eventType,params:c.eventData},p)}catch{p()}});return}const n=window.TelegramWebviewProxy||{},o=n.postEvent||(()=>{});window.TelegramWebviewProxy={...n,postEvent(a,s){const u=()=>{o(a,s)};r?r({name:a,params:s?JSON.parse(s):void 0},u):u()}},v().log("Environment was mocked by the mockTelegramEnv function")}function Ae(e){return({req_id:r})=>r===e}const Z={"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 j(e,r){return Object.keys(Z).find(n=>Z[n].some(o=>r?typeof o=="object"&&o.method===e&&o.param===r:o===e))||null}function ee(e){return e.split(".").map(Number)}function xe(e,r){const t=ee(e),n=ee(r),o=Math.max(t.length,n.length);for(let a=0;a<o;a+=1){const s=t[a]||0,u=n[a]||0;if(s!==u)return s>u?1:-1}return 0}function R(e,r,t){const n=t?j(e,r):j(e);return n?xe(n,t||r)<=0:!1}function kr(e,r="strict"){const t=typeof r=="function"?r:n=>{const{method:o,version:a}=n,s="param"in n?new he(o,n.param,a):new me(o,a);if(r==="strict")throw s;return v().forceWarn(s.message)};return(n,o)=>R(n,e)?n==="web_app_set_header_color"&&i.is(i.looseObject({color:i.any()}),o)&&!R(n,"color",e)?t({version:e,method:n,param:"color"}):Se(n,o):t({version:e,method:n})}function Fe(e,r,t,n){return m(O("web_app_invoke_custom_method","custom_method_invoked",{...n||{},params:{method:e,params:r,req_id:t},capture:Ae(t)}),pr(({result:o,error:a})=>a?cr(new we(a)):ce(o)))}function Sr(e,r,t,n){return A.BetterPromise.fn(()=>m(Fe(e,r,t,n),pe(o=>{throw o},o=>o))())}function Me(e,r,t={}){const{capture:n=()=>!0,postEvent:o=k}=t,a=b.signal(),[s,u]=_.createCbCollector();(Array.isArray(r)?r:[r]).forEach(c=>{s(q(c,l=>{(Array.isArray(r)?n({event:c,payload:l}):n(l))&&a.set([l])}))});const p=c=>(u(),c);return m(async()=>o(e,t.params),fe(()=>_.BetterTaskEither((c,l,h)=>{const d=a();if(d)return c(d[0]);const S=T=>{T&&c(T[0])},L=()=>{a.unsub(S)};a.sub(S),h.on("finalized",L)},t)),le(p,p))}function Tr(e,r,t){const{postEvent:n}=t||{};return _.throwifyAnyEither(Me(e,r,{...t,postEvent:n?(...o)=>{try{return n(...o),f(void 0)}catch(a){return g(a)}}:k}))}function Ar(){Object.hasOwn||(Object.hasOwn=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)})}function J(e){return B(()=>decodeURIComponent(atob(e.replace(/-/g,"+").replace(/_/g,"/")).split("").map(r=>"%"+("00"+r.charCodeAt(0).toString(16)).slice(-2)).join("")),r=>r)}const xr=_.throwifyFpFn(J);function N(e){return btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(r,t)=>String.fromCharCode(parseInt(`0x${t}`)))).replace(/\+/g,"-").replace(/\//g,"_")}var Fr=function(e){return B(function(){return JSON.parse(e)},$e)};function Ce(e){const r=N(typeof e=="string"?e:JSON.stringify(e));return r.length>512?g(new Error("Value is too long for start parameter")):f(r)}const Mr=_.throwifyFpFn(Ce);function Cr(e,r){return _.throwifyAnyEither(qe(e,typeof r=="function"?t=>B(()=>r(t),n=>n):r))}function qe(e,r){return m(J(e),Ne(t=>r?typeof r=="function"?r(t):Fr(t):f(t)))}function qr(e){return N(e).length<=512}Object.defineProperty(exports,"createLogger",{enumerable:!0,get:()=>_.createLogger});Object.defineProperty(exports,"deepSnakeToCamelObjKeys",{enumerable:!0,get:()=>_.deepSnakeToCamelObjKeys});Object.defineProperty(exports,"CancelledError",{enumerable:!0,get:()=>A.CancelledError});Object.defineProperty(exports,"TimeoutError",{enumerable:!0,get:()=>A.TimeoutError});exports.InvalidLaunchParamsError=de;exports.InvokeCustomMethodFailedError=we;exports.LaunchParamsRetrieveError=ge;exports.MethodParameterUnsupportedError=he;exports.MethodUnsupportedError=me;exports.UnknownEnvError=V;exports.applyPolyfills=Ar;exports.captureSameReq=Ae;exports.compareVersions=xe;exports.createPostEvent=kr;exports.createStartParam=Mr;exports.createStartParamFp=Ce;exports.debug=D;exports.decodeBase64Url=xr;exports.decodeBase64UrlFp=J;exports.decodeStartParam=Cr;exports.decodeStartParamFp=qe;exports.emitEvent=F;exports.encodeBase64Url=N;exports.getReleaseVersion=j;exports.hasWebviewProxy=U;exports.invokeCustomMethod=Sr;exports.invokeCustomMethodFp=Fe;exports.isIframe=W;exports.isSafeToCreateStartParam=qr;exports.isTMA=Er;exports.isTMAFp=Te;exports.logger=v;exports.mockTelegramEnv=Pr;exports.off=Ee;exports.offAll=Pe;exports.on=q;exports.postEvent=Se;exports.postEventFp=k;exports.postMessage=ke;exports.postMessageImpl=y;exports.request=Tr;exports.request2=yr;exports.request2Fp=O;exports.requestFp=Me;exports.resetGlobals=wr;exports.retrieveLaunchParams=lr;exports.retrieveLaunchParamsFp=be;exports.retrieveRawInitData=_r;exports.retrieveRawInitDataFp=ve;exports.retrieveRawLaunchParams=fr;exports.retrieveRawLaunchParamsFp=x;exports.setDebug=gr;exports.setTargetOrigin=dr;exports.supports=R;exports.targetOrigin=G;
|
|
4
4
|
//# sourceMappingURL=index.cjs.map
|