@tma.js/bridge 2.3.3 → 4.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +156 -35
- package/dist/dts/env.d.ts +69 -0
- package/dist/dts/errors.d.ts +55 -9
- package/dist/dts/events.d.ts +64 -0
- package/dist/dts/index.d.ts +14 -26
- package/dist/dts/invokeCustomMethod.d.ts +33 -0
- package/dist/dts/launch-params.d.ts +101 -19
- package/dist/dts/logger.d.ts +29 -0
- package/dist/dts/mockTelegramEnv.d.ts +55 -0
- package/dist/dts/post-event.d.ts +40 -0
- package/dist/dts/request.d.ts +98 -0
- package/dist/dts/result.d.ts +45 -0
- package/dist/dts/start-param.d.ts +34 -40
- package/dist/dts/theme-params.d.ts +10 -0
- package/dist/dts/types/common.d.ts +61 -0
- package/dist/dts/{events/types → types}/events.d.ts +75 -56
- package/dist/dts/types/index.d.ts +5 -0
- package/dist/dts/{methods/types → types}/methods.d.ts +200 -116
- package/dist/dts/versions.d.ts +83 -0
- package/dist/dts/window-hooks.d.ts +27 -0
- package/dist/index.cjs +2 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.iife.js +2 -3
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +619 -601
- package/dist/index.js.map +1 -1
- package/package.json +11 -19
- package/dist/dts/applyPolyfills.d.ts +0 -5
- package/dist/dts/base64-url.d.ts +0 -24
- package/dist/dts/env/hasWebviewProxy.d.ts +0 -10
- package/dist/dts/env/isIframe.d.ts +0 -5
- package/dist/dts/env/isTMA.d.ts +0 -31
- package/dist/dts/env/mockTelegramEnv.d.ts +0 -60
- package/dist/dts/events/createEmitter.d.ts +0 -58
- package/dist/dts/events/emitEvent.d.ts +0 -33
- package/dist/dts/events/emitter.d.ts +0 -2
- package/dist/dts/events/types/index.d.ts +0 -3
- package/dist/dts/events/types/listening.d.ts +0 -5
- package/dist/dts/events/types/misc.d.ts +0 -16
- package/dist/dts/globals.d.ts +0 -53
- package/dist/dts/methods/captureSameReq.d.ts +0 -10
- package/dist/dts/methods/createPostEvent.d.ts +0 -30
- package/dist/dts/methods/getReleaseVersion.d.ts +0 -15
- package/dist/dts/methods/postEvent.d.ts +0 -35
- package/dist/dts/methods/postMessage.d.ts +0 -7
- package/dist/dts/methods/supports.d.ts +0 -15
- package/dist/dts/methods/types/custom-method.d.ts +0 -59
- package/dist/dts/methods/types/index.d.ts +0 -6
- package/dist/dts/methods/types/misc.d.ts +0 -27
- package/dist/dts/methods/types/utils.d.ts +0 -9
- package/dist/dts/obj-prop-helpers.d.ts +0 -39
- package/dist/dts/utils/compareVersions.d.ts +0 -10
- package/dist/dts/utils/invokeCustomMethod.d.ts +0 -34
- package/dist/dts/utils/request.d.ts +0 -102
- package/dist/dts/utils/request2.d.ts +0 -62
- /package/dist/dts/{methods/types → types}/haptic-feedback.d.ts +0 -0
- /package/dist/dts/{methods/types → types}/popup.d.ts +0 -0
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { LaunchParamsLike } from '@tma.js/transformers';
|
|
2
|
-
import { MethodName, MethodParams } from '../methods/types/index.js';
|
|
3
|
-
/**
|
|
4
|
-
* Mocks the environment and imitates Telegram Mini Apps behavior.
|
|
5
|
-
*
|
|
6
|
-
* We usually use this function in the following cases:
|
|
7
|
-
* 1. We are developing an application outside the Telegram environment and would like to imitate
|
|
8
|
-
* the Telegram client in order to re-create the same communication behavior.
|
|
9
|
-
* 2. We would like to intercept some Telegram Mini Apps methods' calls in order to enhance them
|
|
10
|
-
* or write a custom behavior. It is extremely useful in some Telegram clients improperly handling
|
|
11
|
-
* Mini Apps methods' calls and not even responding.
|
|
12
|
-
*
|
|
13
|
-
* Note that calling this function in Telegram web clients, the `postMessageImplementation` signal
|
|
14
|
-
* value will be updated with a new one, enhancing previously set signal value to allow wrapping
|
|
15
|
-
* the original `window.parent.postMessage` function. In other words, calling `mockTelegramEnv`
|
|
16
|
-
* function N times, you will effectively wrap previously set implementation N times, so be
|
|
17
|
-
* careful calling this function several times during a single lifecycle of the app. In case you
|
|
18
|
-
* would like to avoid such kind of behavior, use the `resetPostMessage` option.
|
|
19
|
-
*/
|
|
20
|
-
export declare function mockTelegramEnv({ launchParams, onEvent, resetPostMessage }?: {
|
|
21
|
-
/**
|
|
22
|
-
* Launch parameters to mock. They will be saved in the storage, so the SDK functions could
|
|
23
|
-
* retrieve them.
|
|
24
|
-
*
|
|
25
|
-
* Note that this value must have `tgWebAppData` presented in a raw format as long as you will
|
|
26
|
-
* need it when retrieving init data in this format. Otherwise, init data may be broken.
|
|
27
|
-
*/
|
|
28
|
-
launchParams?: (Omit<LaunchParamsLike, 'tgWebAppData'> & {
|
|
29
|
-
tgWebAppData?: string | URLSearchParams;
|
|
30
|
-
}) | string | URLSearchParams;
|
|
31
|
-
/**
|
|
32
|
-
* Function that will be called if a Mini Apps method call was requested by the mini app.
|
|
33
|
-
*
|
|
34
|
-
* It receives a Mini Apps method name along with the passed payload.
|
|
35
|
-
*
|
|
36
|
-
* Note that using the `next` function, in non-web environments it uses the
|
|
37
|
-
* `window.TelegramWebviewProxy.postEvent` method.
|
|
38
|
-
*
|
|
39
|
-
* Talking about the web versions of Telegram, the value of `next` is a bit more complex - it
|
|
40
|
-
* will be equal to the value stored in the `postMessageImpl` signal set previously. By default,
|
|
41
|
-
* this value contains a function utilizing the `window.parent.postMessage` method.
|
|
42
|
-
* @param event - event information.
|
|
43
|
-
* @param next - function to call the original method used to call a Mini Apps method.
|
|
44
|
-
*/
|
|
45
|
-
onEvent?: (event: {
|
|
46
|
-
[M in MethodName]: {
|
|
47
|
-
name: M;
|
|
48
|
-
params: MethodParams<M>;
|
|
49
|
-
};
|
|
50
|
-
}[MethodName] | {
|
|
51
|
-
name: string;
|
|
52
|
-
params: unknown;
|
|
53
|
-
}, next: () => void) => void;
|
|
54
|
-
/**
|
|
55
|
-
* Removes all previously set enhancements of the `window.parent.postMessage` function set
|
|
56
|
-
* by other `mockTelegramEnv` calls.
|
|
57
|
-
* @default false
|
|
58
|
-
*/
|
|
59
|
-
resetPostMessage?: boolean;
|
|
60
|
-
}): void;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { If, IsNever, IsUndefined, Or } from '@tma.js/toolkit';
|
|
2
|
-
import { Handler } from 'mitt';
|
|
3
|
-
export type WildcardHandler<E> = Handler<{
|
|
4
|
-
[K in keyof E]: {
|
|
5
|
-
name: K;
|
|
6
|
-
payload: If<Or<IsNever<E[K]>, IsUndefined<E[K]>>, never, E[K]>;
|
|
7
|
-
};
|
|
8
|
-
}[keyof E]>;
|
|
9
|
-
export interface OnFn<E> {
|
|
10
|
-
/**
|
|
11
|
-
* Adds a new listener for the specified event.
|
|
12
|
-
* @param type - event name.
|
|
13
|
-
* @param handler - event listener.
|
|
14
|
-
* @param once - should this listener be called only once.
|
|
15
|
-
* @returns Function to remove bound event listener.
|
|
16
|
-
*/
|
|
17
|
-
<K extends keyof E>(type: K, handler: Handler<E[K]>, once?: boolean): VoidFunction;
|
|
18
|
-
/**
|
|
19
|
-
* Adds a listener to the wildcard event.
|
|
20
|
-
* @param type - event name.
|
|
21
|
-
* @param handler - event listener.
|
|
22
|
-
* @param once - should this listener be called only once.
|
|
23
|
-
* @returns Function to remove bound event listener.
|
|
24
|
-
*/
|
|
25
|
-
(type: '*', handler: WildcardHandler<E>, once?: boolean): VoidFunction;
|
|
26
|
-
}
|
|
27
|
-
export interface OffFn<E> {
|
|
28
|
-
/**
|
|
29
|
-
* Removes a listener from the specified event.
|
|
30
|
-
* @param type - event to listen.
|
|
31
|
-
* @param handler - event listener to remove.
|
|
32
|
-
* @param once - had this listener to be called only once.
|
|
33
|
-
*/
|
|
34
|
-
<K extends keyof E>(type: K, handler: Handler<E[K]>, once?: boolean): void;
|
|
35
|
-
/**
|
|
36
|
-
* Removes a listener from the wildcard event.
|
|
37
|
-
* @param type - event to stop listening.
|
|
38
|
-
* @param handler - event listener to remove.
|
|
39
|
-
* @param once - should this listener be called only once.
|
|
40
|
-
*/
|
|
41
|
-
(type: '*', handler: WildcardHandler<E>, once?: boolean): void;
|
|
42
|
-
}
|
|
43
|
-
export interface EmitFn<E> {
|
|
44
|
-
<K extends keyof E>(type: K, event: E[K]): void;
|
|
45
|
-
<K extends keyof E>(type: undefined extends E[K] ? K : never): void;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Creates a new enhanced event emitter.
|
|
49
|
-
* @param onFirst - a function to call every time when the events map appeared to be empty during
|
|
50
|
-
* the event listener creation.
|
|
51
|
-
* @param onEmpty - a function to call every tume when the events map became empty.
|
|
52
|
-
*/
|
|
53
|
-
export declare function createEmitter<E extends object>(onFirst: VoidFunction, onEmpty: VoidFunction): {
|
|
54
|
-
on: OnFn<E>;
|
|
55
|
-
off: OffFn<E>;
|
|
56
|
-
emit: EmitFn<E>;
|
|
57
|
-
clear: VoidFunction;
|
|
58
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { EventPayload, EventWithoutPayload, EventWithPayload } from './types/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* Emits an event without payload sent from the Telegram native application like it was sent in
|
|
4
|
-
* a default web environment between two iframes.
|
|
5
|
-
*
|
|
6
|
-
* It dispatches a new MessageEvent and expects it to be handled via
|
|
7
|
-
* the `window.addEventListener('message', ...)` call, as a developer would do it to handle
|
|
8
|
-
* messages sent from the parent iframe.
|
|
9
|
-
* @param eventType - event name.
|
|
10
|
-
*/
|
|
11
|
-
export declare function emitEvent<E extends EventWithoutPayload>(eventType: E): void;
|
|
12
|
-
/**
|
|
13
|
-
* Emits an event with payload sent from the Telegram native application like it was sent in
|
|
14
|
-
* a default web environment between two iframes.
|
|
15
|
-
*
|
|
16
|
-
* It dispatches a new MessageEvent and expects it to be handled via
|
|
17
|
-
* the `window.addEventListener('message', ...)` call, as a developer would do it to handle
|
|
18
|
-
* messages sent from the parent iframe.
|
|
19
|
-
* @param eventType - event name.
|
|
20
|
-
* @param eventData - event payload.
|
|
21
|
-
*/
|
|
22
|
-
export declare function emitEvent<E extends EventWithPayload>(eventType: E, eventData: EventPayload<E>): void;
|
|
23
|
-
/**
|
|
24
|
-
* Emits an unknown event sent from the Telegram native application like it was sent in a default
|
|
25
|
-
* web environment between two iframes.
|
|
26
|
-
*
|
|
27
|
-
* It dispatches a new MessageEvent and expects it to be handled via
|
|
28
|
-
* the `window.addEventListener('message', ...)` call, as a developer would do it to handle
|
|
29
|
-
* messages sent from the parent iframe.
|
|
30
|
-
* @param eventType - event name.
|
|
31
|
-
* @param eventData - event payload.
|
|
32
|
-
*/
|
|
33
|
-
export declare function emitEvent<E extends string>(eventType: E, eventData: E extends EventWithoutPayload ? never : E extends EventWithPayload ? EventPayload<E> : unknown): void;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Handler } from 'mitt';
|
|
2
|
-
import { WildcardHandler } from '../createEmitter.js';
|
|
3
|
-
import { EventName, EventPayload, Events } from './index.js';
|
|
4
|
-
export type EventListener<E extends EventName> = Handler<EventPayload<E>>;
|
|
5
|
-
export type SubscribeListener = WildcardHandler<Events>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export type InvoiceStatus = 'paid' | 'failed' | 'pending' | 'cancelled' | string;
|
|
2
|
-
export type PhoneRequestedStatus = 'sent' | 'cancelled' | string;
|
|
3
|
-
export type EmojiStatusAccessRequestedStatus = 'allowed' | string;
|
|
4
|
-
export type EmojiStatusFailedError = 'SUGGESTED_EMOJI_INVALID' | 'USER_DECLINED' | string;
|
|
5
|
-
export type WriteAccessRequestedStatus = 'allowed' | string;
|
|
6
|
-
export type BiometryType = 'finger' | 'face' | string;
|
|
7
|
-
export type BiometryTokenUpdateStatus = 'updated' | 'removed' | 'failed' | string;
|
|
8
|
-
export type BiometryAuthRequestStatus = 'failed' | 'authorized' | string;
|
|
9
|
-
export type FullScreenErrorStatus = 'ALREADY_FULLSCREEN' | 'UNSUPPORTED' | string;
|
|
10
|
-
export interface SafeAreaInsets {
|
|
11
|
-
top: number;
|
|
12
|
-
bottom: number;
|
|
13
|
-
left: number;
|
|
14
|
-
right: number;
|
|
15
|
-
}
|
|
16
|
-
export type HomeScreenStatus = 'unsupported' | 'unknown' | 'added' | 'missed' | string;
|
package/dist/dts/globals.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@tma.js/toolkit';
|
|
2
|
-
/**
|
|
3
|
-
* The current debug mode state.
|
|
4
|
-
*
|
|
5
|
-
* To update the value, use the `setDebug` function.
|
|
6
|
-
* @see setDebug
|
|
7
|
-
*/
|
|
8
|
-
export declare const debug: import('@tma.js/signals').Computed<boolean>;
|
|
9
|
-
/**
|
|
10
|
-
* Sets the package debug mode.
|
|
11
|
-
*
|
|
12
|
-
* Enabling debug mode leads to printing additional messages in the console related to the
|
|
13
|
-
* processes inside the package.
|
|
14
|
-
* @param value - enable debug mode.
|
|
15
|
-
*/
|
|
16
|
-
export declare function setDebug(value: boolean): void;
|
|
17
|
-
/**
|
|
18
|
-
* The current target origin used by the `postEvent` method.
|
|
19
|
-
*
|
|
20
|
-
* You don't need to override this value until you know what you are doing.
|
|
21
|
-
* To update the value, use the `setTargetOrigin` function.
|
|
22
|
-
* @default 'https://web.telegram.org'
|
|
23
|
-
* @see setTargetOrigin
|
|
24
|
-
*/
|
|
25
|
-
export declare const targetOrigin: import('@tma.js/signals').Computed<string>;
|
|
26
|
-
/**
|
|
27
|
-
* Sets a new target origin that is being used when calling the `postEvent` function in Telegram
|
|
28
|
-
* web versions.
|
|
29
|
-
*
|
|
30
|
-
* You don't need to override this value until you know what you are doing.
|
|
31
|
-
* @param origin - allowed target origin value.
|
|
32
|
-
* @see _targetOrigin
|
|
33
|
-
*/
|
|
34
|
-
export declare function setTargetOrigin(origin: string): void;
|
|
35
|
-
/**
|
|
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 Telegram.
|
|
38
|
-
*
|
|
39
|
-
* @default A function behaving like the `window.parent.postMessage` method.
|
|
40
|
-
*/
|
|
41
|
-
export declare const postMessageImpl: import('@tma.js/signals').Signal<{
|
|
42
|
-
(message: any, targetOrigin: string, transfer?: Transferable[]): void;
|
|
43
|
-
(message: any, options?: WindowPostMessageOptions): void;
|
|
44
|
-
}>;
|
|
45
|
-
/**
|
|
46
|
-
* The package logger. You can override this value in order to use your own implementation.
|
|
47
|
-
*/
|
|
48
|
-
export declare const logger: import('@tma.js/signals').Signal<Logger>;
|
|
49
|
-
/**
|
|
50
|
-
* Resets the package global values. Normally, you don't use this function in your application.
|
|
51
|
-
* We are using it only for test purposes.
|
|
52
|
-
*/
|
|
53
|
-
export declare function resetGlobals(): void;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
type CaptureSameReqFn = (payload: {
|
|
2
|
-
req_id: string;
|
|
3
|
-
}) => boolean;
|
|
4
|
-
/**
|
|
5
|
-
* Returns a function which can be used in `request` function `capture` property to capture
|
|
6
|
-
* the event with the same request identifier.
|
|
7
|
-
* @param reqId - request identifier.
|
|
8
|
-
*/
|
|
9
|
-
export declare function captureSameReq(reqId: string): CaptureSameReqFn;
|
|
10
|
-
export {};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Version } from '@tma.js/types';
|
|
2
|
-
import { PostEventFn } from './postEvent.js';
|
|
3
|
-
import { MethodName, MethodNameWithVersionedParams, MethodVersionedParams } from './types/index.js';
|
|
4
|
-
export type OnUnsupportedFn = (data: {
|
|
5
|
-
version: Version;
|
|
6
|
-
} & ({
|
|
7
|
-
method: MethodName;
|
|
8
|
-
} | {
|
|
9
|
-
[M in MethodNameWithVersionedParams]: {
|
|
10
|
-
method: M;
|
|
11
|
-
param: MethodVersionedParams<M>;
|
|
12
|
-
};
|
|
13
|
-
}[MethodNameWithVersionedParams])) => void;
|
|
14
|
-
export type CreatePostEventMode = 'strict' | 'non-strict';
|
|
15
|
-
/**
|
|
16
|
-
* Creates a function that checks if the specified method and parameters are supported.
|
|
17
|
-
*
|
|
18
|
-
* If the method or parameters are unsupported, the `onUnsupported` function will be called.
|
|
19
|
-
*
|
|
20
|
-
* If `strict` or `non-strict` value was passed as the second argument, the function
|
|
21
|
-
* will create its own `onUnsupported` function with behavior depending on the value passed.
|
|
22
|
-
*
|
|
23
|
-
* - Passing `strict` will make the function to throw a `MethodParameterUnsupportedError`
|
|
24
|
-
* or a `MethodUnsupportedError` error.
|
|
25
|
-
* - Passing `non-strict` will just warn you about something being unsupported.
|
|
26
|
-
*
|
|
27
|
-
* @param version - Telegram Mini Apps version.
|
|
28
|
-
* @param onUnsupportedOrMode - function or strict mode. Default: `strict`
|
|
29
|
-
*/
|
|
30
|
-
export declare function createPostEvent(version: Version, onUnsupportedOrMode?: OnUnsupportedFn | CreatePostEventMode): PostEventFn;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Version } from '@tma.js/types';
|
|
2
|
-
import { MethodName, MethodNameWithVersionedParams, MethodVersionedParams } from './types/index.js';
|
|
3
|
-
/**
|
|
4
|
-
* @returns Version of the specified method parameter release. Returns `null`
|
|
5
|
-
* if passed method or parameter are unknown.
|
|
6
|
-
* @param method - method name
|
|
7
|
-
* @param param - method parameter
|
|
8
|
-
*/
|
|
9
|
-
export declare function getReleaseVersion<M extends MethodNameWithVersionedParams>(method: M, param: MethodVersionedParams<M>): Version | null;
|
|
10
|
-
/**
|
|
11
|
-
* @returns Version of the specified method release. Returns `null`
|
|
12
|
-
* if passed method is unknown.
|
|
13
|
-
* @param method - method name.
|
|
14
|
-
*/
|
|
15
|
-
export declare function getReleaseVersion(method: MethodName): Version | null;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { either as E } from 'fp-ts';
|
|
2
|
-
import { UnknownEnvError } from '../errors.js';
|
|
3
|
-
import { MethodNameWithOptionalParams, MethodNameWithoutParams, MethodNameWithRequiredParams, MethodParams } from './types/index.js';
|
|
4
|
-
export type PostEventError = UnknownEnvError;
|
|
5
|
-
export type PostEventFn = typeof postEvent;
|
|
6
|
-
export type PostEventFpFn = typeof postEventFp;
|
|
7
|
-
/**
|
|
8
|
-
* @see postEventFp
|
|
9
|
-
*/
|
|
10
|
-
export declare function postEvent<Method extends MethodNameWithRequiredParams>(method: Method, params: MethodParams<Method>): void;
|
|
11
|
-
/**
|
|
12
|
-
* @see postEventFp
|
|
13
|
-
*/
|
|
14
|
-
export declare function postEvent(method: MethodNameWithoutParams): void;
|
|
15
|
-
/**
|
|
16
|
-
* @see postEventFp
|
|
17
|
-
*/
|
|
18
|
-
export declare function postEvent<Method extends MethodNameWithOptionalParams>(method: Method, params?: MethodParams<Method>): void;
|
|
19
|
-
/**
|
|
20
|
-
* Calls Mini Apps methods requiring parameters.
|
|
21
|
-
* @param method - method name.
|
|
22
|
-
* @param params - options along with params.
|
|
23
|
-
*/
|
|
24
|
-
export declare function postEventFp<Method extends MethodNameWithRequiredParams>(method: Method, params: MethodParams<Method>): E.Either<PostEventError, void>;
|
|
25
|
-
/**
|
|
26
|
-
* Calls Mini Apps methods accepting no parameters at all.
|
|
27
|
-
* @param method - method name.
|
|
28
|
-
*/
|
|
29
|
-
export declare function postEventFp(method: MethodNameWithoutParams): E.Either<PostEventError, void>;
|
|
30
|
-
/**
|
|
31
|
-
* Calls Mini Apps methods accepting optional parameters.
|
|
32
|
-
* @param method - method name.
|
|
33
|
-
* @param params - options along with params.
|
|
34
|
-
*/
|
|
35
|
-
export declare function postEventFp<Method extends MethodNameWithOptionalParams>(method: Method, params?: MethodParams<Method>): E.Either<PostEventError, void>;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export type PostMessage = typeof window.parent.postMessage;
|
|
2
|
-
/**
|
|
3
|
-
* Posts a message to the parent window. We usually use it to send a message in web versions of
|
|
4
|
-
* Telegram.
|
|
5
|
-
* @param args - `window.parent.postMessage` arguments.
|
|
6
|
-
*/
|
|
7
|
-
export declare const postMessage: PostMessage;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Version } from '@tma.js/types';
|
|
2
|
-
import { MethodName, MethodNameWithVersionedParams, MethodVersionedParams } from './types/index.js';
|
|
3
|
-
/**
|
|
4
|
-
* Returns true in case, passed parameter in specified method is supported.
|
|
5
|
-
* @param method - method name
|
|
6
|
-
* @param param - method parameter
|
|
7
|
-
* @param inVersion - platform version.
|
|
8
|
-
*/
|
|
9
|
-
export declare function supports<M extends MethodNameWithVersionedParams>(method: M, param: MethodVersionedParams<M>, inVersion: Version): boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Returns true in case, specified method is supported in a passed version.
|
|
12
|
-
* @param method - method name.
|
|
13
|
-
* @param inVersion - platform version.
|
|
14
|
-
*/
|
|
15
|
-
export declare function supports(method: MethodName, inVersion: Version): boolean;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
interface CreateInvokeCustomMethodParams<M extends string, Params extends object> {
|
|
2
|
-
/**
|
|
3
|
-
* Unique request identifier.
|
|
4
|
-
*/
|
|
5
|
-
req_id: string;
|
|
6
|
-
/**
|
|
7
|
-
* Method name.
|
|
8
|
-
*/
|
|
9
|
-
method: M;
|
|
10
|
-
/**
|
|
11
|
-
* Method specific parameters.
|
|
12
|
-
*/
|
|
13
|
-
params: Params;
|
|
14
|
-
}
|
|
15
|
-
export interface CustomMethodsParams {
|
|
16
|
-
/**
|
|
17
|
-
* Deletes storage values using their keys.
|
|
18
|
-
*/
|
|
19
|
-
deleteStorageValues: {
|
|
20
|
-
keys: string | string[];
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Returns the current server time.
|
|
24
|
-
*/
|
|
25
|
-
getCurrentTime: {};
|
|
26
|
-
/**
|
|
27
|
-
* Gets the current user contact in case, the mini app has access to it.
|
|
28
|
-
*/
|
|
29
|
-
getRequestedContact: {};
|
|
30
|
-
/**
|
|
31
|
-
* Gets all registered storage keys.
|
|
32
|
-
*/
|
|
33
|
-
getStorageKeys: {};
|
|
34
|
-
/**
|
|
35
|
-
* Gets storage values using their keys.
|
|
36
|
-
*/
|
|
37
|
-
getStorageValues: {
|
|
38
|
-
keys: string | string[];
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Saves a value using specified key in the storage.
|
|
42
|
-
*/
|
|
43
|
-
saveStorageValue: {
|
|
44
|
-
key: string;
|
|
45
|
-
value: string;
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Known custom method name.
|
|
50
|
-
*/
|
|
51
|
-
export type CustomMethodName = keyof CustomMethodsParams;
|
|
52
|
-
/**
|
|
53
|
-
* Custom method parameters.
|
|
54
|
-
*/
|
|
55
|
-
export type CustomMethodParams<M extends CustomMethodName> = CustomMethodsParams[M];
|
|
56
|
-
export type AnyInvokeCustomMethodParams = CreateInvokeCustomMethodParams<string, any> | {
|
|
57
|
-
[M in CustomMethodName]: CreateInvokeCustomMethodParams<M, CustomMethodParams<M>>;
|
|
58
|
-
}[CustomMethodName];
|
|
59
|
-
export {};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { RGB } from '@tma.js/types';
|
|
2
|
-
type KnownColorKey = 'bg_color' | 'secondary_bg_color';
|
|
3
|
-
/**
|
|
4
|
-
* Color key which could be used to update header color.
|
|
5
|
-
*/
|
|
6
|
-
export type HeaderColorKey = KnownColorKey;
|
|
7
|
-
/**
|
|
8
|
-
* Color key which could be used to update Mini App background color.
|
|
9
|
-
*/
|
|
10
|
-
export type BackgroundColor = RGB;
|
|
11
|
-
/**
|
|
12
|
-
* Color key which could be used to update bottom bar background color.
|
|
13
|
-
*/
|
|
14
|
-
export type BottomBarColor = RGB;
|
|
15
|
-
/**
|
|
16
|
-
* Position of the secondary button related to the main one.
|
|
17
|
-
*/
|
|
18
|
-
export type SecondaryButtonPosition = 'left' | 'right' | 'top' | 'bottom';
|
|
19
|
-
/**
|
|
20
|
-
* Values expected by the `web_app_open_link.try_browser` option.
|
|
21
|
-
*/
|
|
22
|
-
export type OpenLinkBrowser = 'google-chrome' | 'chrome' | 'mozilla-firefox' | 'firefox' | 'microsoft-edge' | 'edge' | 'opera' | 'opera-mini' | 'brave' | 'brave-browser' | 'duckduckgo' | 'duckduckgo-browser' | 'samsung' | 'samsung-browser' | 'vivaldi' | 'vivaldi-browser' | 'kiwi' | 'kiwi-browser' | 'uc' | 'uc-browser' | 'tor' | 'tor-browser';
|
|
23
|
-
/**
|
|
24
|
-
* Chat type which could be used when calling `web_app_switch_inline_query` method.
|
|
25
|
-
*/
|
|
26
|
-
export type SwitchInlineQueryChatType = 'users' | 'bots' | 'groups' | 'channels';
|
|
27
|
-
export {};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
type UnionKeys<T> = T extends T ? keyof T : never;
|
|
2
|
-
/**
|
|
3
|
-
* Creates Mini Apps method parameters types.
|
|
4
|
-
*/
|
|
5
|
-
export interface CreateMethodParams<Params = never, VersionedParam extends UnionKeys<Params> = never> {
|
|
6
|
-
params: Params;
|
|
7
|
-
versionedParams: VersionedParam;
|
|
8
|
-
}
|
|
9
|
-
export {};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Defines a property, that is a functions compose. Trying to set a value in this property
|
|
3
|
-
* will lead to adding it to a function's pool. The property value will always be equal to a
|
|
4
|
-
* function, calling all collected functions in the pool.
|
|
5
|
-
*
|
|
6
|
-
* Returned function performs a cleanup. It does one of the following:
|
|
7
|
-
* 1. Removes the property if no functions were to the pool added other than the initial one.
|
|
8
|
-
* 2. Sets the value equal to the first added function to the pool after the initial one if
|
|
9
|
-
* the only one additional function was added at all. In other words, if the pool length is equal
|
|
10
|
-
* to 2, the second item will be selected as the property value.
|
|
11
|
-
* 3. Leaves the value equal to a function calling all pool functions, but removes the initially
|
|
12
|
-
* added one.
|
|
13
|
-
* @param obj - object.
|
|
14
|
-
* @param propertyName - object property.
|
|
15
|
-
* @param initialFn - an initial function to set.
|
|
16
|
-
*/
|
|
17
|
-
export declare function defineFnComposer(obj: any, propertyName: string, initialFn: (...args: any) => any): void;
|
|
18
|
-
/**
|
|
19
|
-
* Wires the specified property in the object preventing it from being overwritten. Instead, it
|
|
20
|
-
* enhances the previous value by merging the current one with the passed one.
|
|
21
|
-
* @param obj - object.
|
|
22
|
-
* @param prop - object property to rewire.
|
|
23
|
-
*/
|
|
24
|
-
export declare function defineMergeableProperty(obj: any, prop: string): void;
|
|
25
|
-
/**
|
|
26
|
-
* Defines an enumerable and configurable property with a getter and setter.
|
|
27
|
-
* @param obj - object.
|
|
28
|
-
* @param prop - object property name.
|
|
29
|
-
* @param get - getter to use.
|
|
30
|
-
* @param set - setter to use.
|
|
31
|
-
*/
|
|
32
|
-
export declare function defineProxiedProperty(obj: any, prop: string, get: () => unknown, set: (v: any) => void): void;
|
|
33
|
-
/**
|
|
34
|
-
* Defines an enumerable, configurable and writable property with the initial value.
|
|
35
|
-
* @param obj - object.
|
|
36
|
-
* @param prop - object property name.
|
|
37
|
-
* @param value - value to set.
|
|
38
|
-
*/
|
|
39
|
-
export declare function defineStaticProperty(obj: any, prop: string, value: any): void;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Version } from '@tma.js/types';
|
|
2
|
-
/**
|
|
3
|
-
* @param a - first version.
|
|
4
|
-
* @param b - second version.
|
|
5
|
-
* @returns
|
|
6
|
-
* - `1` if the version "a" is greater than "b".
|
|
7
|
-
* - `0` the version "a" is equal to "b".
|
|
8
|
-
* - `-1` the version "a" is lower than "b".
|
|
9
|
-
*/
|
|
10
|
-
export declare function compareVersions(a: Version, b: Version): number;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { BetterPromise } from 'better-promises';
|
|
2
|
-
import { taskEither as TE } from 'fp-ts';
|
|
3
|
-
import { InvokeCustomMethodFailedError } from '../errors.js';
|
|
4
|
-
import { CustomMethodName, CustomMethodParams } from '../methods/types/index.js';
|
|
5
|
-
import { Request2Error, Request2FpOptions, Request2Options } from './request2.js';
|
|
6
|
-
export type InvokeCustomMethodError = Request2Error | InvokeCustomMethodFailedError;
|
|
7
|
-
export type InvokeCustomMethodOptions = Omit<Request2Options<'custom_method_invoked'>, 'capture'>;
|
|
8
|
-
export type InvokeCustomMethodFn = typeof invokeCustomMethod;
|
|
9
|
-
export type InvokeCustomMethodFpOptions = Omit<Request2FpOptions<'custom_method_invoked'>, 'capture'>;
|
|
10
|
-
export type InvokeCustomMethodFpFn = typeof invokeCustomMethodFp;
|
|
11
|
-
/**
|
|
12
|
-
* Invokes known custom method. Returns method execution result.
|
|
13
|
-
* @param method - method name.
|
|
14
|
-
* @param params - method parameters.
|
|
15
|
-
* @param requestId - request identifier.
|
|
16
|
-
* @param options - additional options.
|
|
17
|
-
*/
|
|
18
|
-
export declare function invokeCustomMethodFp<M extends CustomMethodName>(method: M, params: CustomMethodParams<M>, requestId: string, options?: InvokeCustomMethodFpOptions): TE.TaskEither<InvokeCustomMethodError, unknown>;
|
|
19
|
-
/**
|
|
20
|
-
* Invokes unknown custom method. Returns method execution result.
|
|
21
|
-
* @param method - method name.
|
|
22
|
-
* @param params - method parameters.
|
|
23
|
-
* @param requestId - request identifier.
|
|
24
|
-
* @param options - additional options.
|
|
25
|
-
*/
|
|
26
|
-
export declare function invokeCustomMethodFp(method: string, params: object, requestId: string, options?: InvokeCustomMethodFpOptions): TE.TaskEither<Request2Error, unknown>;
|
|
27
|
-
/**
|
|
28
|
-
* @see invokeCustomMethodFp
|
|
29
|
-
*/
|
|
30
|
-
export declare function invokeCustomMethod<M extends CustomMethodName>(method: M, params: CustomMethodParams<M>, requestId: string, options?: InvokeCustomMethodOptions): BetterPromise<unknown>;
|
|
31
|
-
/**
|
|
32
|
-
* @see invokeCustomMethodFp
|
|
33
|
-
*/
|
|
34
|
-
export declare function invokeCustomMethod(method: string, params: object, requestId: string, options?: InvokeCustomMethodOptions): BetterPromise<unknown>;
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { If, IsNever } from '@tma.js/toolkit';
|
|
2
|
-
import { BetterPromise, BetterPromiseOptions, TimeoutError } from 'better-promises';
|
|
3
|
-
import { taskEither as TE } from 'fp-ts';
|
|
4
|
-
import { EventName, EventPayload } from '../events/types/index.js';
|
|
5
|
-
import { PostEventError, PostEventFn, PostEventFpFn } from '../methods/postEvent.js';
|
|
6
|
-
import { MethodNameWithOptionalParams, MethodNameWithoutParams, MethodNameWithRequiredParams, MethodParams } from '../methods/types/index.js';
|
|
7
|
-
type AnyEventName = EventName | EventName[];
|
|
8
|
-
export type RequestError = PostEventError | TimeoutError;
|
|
9
|
-
/**
|
|
10
|
-
* @example
|
|
11
|
-
* { event: 'scan_qr_closed' }
|
|
12
|
-
* @example
|
|
13
|
-
* {
|
|
14
|
-
* event: 'popup_closed',
|
|
15
|
-
* payload: { button_id: 'ok' }
|
|
16
|
-
* }
|
|
17
|
-
*/
|
|
18
|
-
export type RequestCaptureFnEventsPayload<E extends EventName[]> = E extends (infer U extends EventName)[] ? {
|
|
19
|
-
[K in U]: If<IsNever<EventPayload<K>>, {
|
|
20
|
-
event: K;
|
|
21
|
-
}, {
|
|
22
|
-
event: K;
|
|
23
|
-
payload: EventPayload<K>;
|
|
24
|
-
}>;
|
|
25
|
-
}[U] : never;
|
|
26
|
-
export type RequestCaptureEventsFn<E extends EventName[]> = (payload: RequestCaptureFnEventsPayload<E>) => boolean;
|
|
27
|
-
export type RequestCaptureEventFn<E extends EventName> = If<IsNever<EventPayload<E>>, () => boolean, (payload: EventPayload<E>) => boolean>;
|
|
28
|
-
export type RequestCaptureFn<E extends AnyEventName> = E extends EventName[] ? RequestCaptureEventsFn<E> : E extends EventName ? RequestCaptureEventFn<E> : never;
|
|
29
|
-
export interface RequestOptions<E extends AnyEventName> extends Omit<RequestFpOptions<E>, 'postEvent'> {
|
|
30
|
-
/**
|
|
31
|
-
* Custom function to call mini apps methods.
|
|
32
|
-
*/
|
|
33
|
-
postEvent?: PostEventFn;
|
|
34
|
-
}
|
|
35
|
-
export type RequestResult<E extends AnyEventName> = E extends (infer U extends EventName)[] ? U extends infer K extends EventName ? If<IsNever<EventPayload<K>>, undefined, EventPayload<K>> : never : E extends EventName ? If<IsNever<EventPayload<E>>, undefined, EventPayload<E>> : never;
|
|
36
|
-
export interface RequestFpOptions<E extends AnyEventName> extends Pick<BetterPromiseOptions, 'abortSignal' | 'timeout'> {
|
|
37
|
-
/**
|
|
38
|
-
* A function that should return true if the event should be captured.
|
|
39
|
-
* The first compatible request will be captured if this property is omitted.
|
|
40
|
-
*/
|
|
41
|
-
capture?: RequestCaptureFn<E>;
|
|
42
|
-
/**
|
|
43
|
-
* A custom function to call mini apps methods.
|
|
44
|
-
*/
|
|
45
|
-
postEvent?: PostEventFpFn;
|
|
46
|
-
}
|
|
47
|
-
export type RequestFn = typeof request;
|
|
48
|
-
export type RequestFpFn = typeof requestFp;
|
|
49
|
-
/**
|
|
50
|
-
* Calls a method waiting for the specified event(-s) to occur.
|
|
51
|
-
* @param method - method name.
|
|
52
|
-
* @param eventOrEvents - tracked event or events.
|
|
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.
|
|
56
|
-
*/
|
|
57
|
-
export declare function requestFp<M extends MethodNameWithRequiredParams, E extends AnyEventName, AbortError = never>(method: M, eventOrEvents: E, options: RequestFpOptions<E> & {
|
|
58
|
-
params: MethodParams<M>;
|
|
59
|
-
}): TE.TaskEither<RequestError | AbortError, RequestResult<E>>;
|
|
60
|
-
/**
|
|
61
|
-
* Calls a method waiting for the specified event(-s) to occur.
|
|
62
|
-
* @param method - method name.
|
|
63
|
-
* @param eventOrEvents - tracked event or events.
|
|
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.
|
|
67
|
-
*/
|
|
68
|
-
export declare function requestFp<M extends MethodNameWithOptionalParams, E extends AnyEventName, AbortError = never>(method: M, eventOrEvents: E, options?: RequestFpOptions<E> & {
|
|
69
|
-
params?: MethodParams<M>;
|
|
70
|
-
}): TE.TaskEither<RequestError | AbortError, RequestResult<E>>;
|
|
71
|
-
/**
|
|
72
|
-
* Calls a method waiting for the specified event(-s) to occur.
|
|
73
|
-
* @param method - method name.
|
|
74
|
-
* @param eventOrEvents - tracked event or events.
|
|
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.
|
|
78
|
-
*/
|
|
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>>;
|
|
80
|
-
/**
|
|
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.
|
|
84
|
-
*/
|
|
85
|
-
export declare function request<M extends MethodNameWithRequiredParams, E extends AnyEventName>(method: M, eventOrEvents: E, options: RequestOptions<E> & {
|
|
86
|
-
params: MethodParams<M>;
|
|
87
|
-
}): BetterPromise<RequestResult<E>>;
|
|
88
|
-
/**
|
|
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.
|
|
92
|
-
*/
|
|
93
|
-
export declare function request<M extends MethodNameWithOptionalParams, E extends AnyEventName>(method: M, eventOrEvents: E, options?: RequestOptions<E> & {
|
|
94
|
-
params?: MethodParams<M>;
|
|
95
|
-
}): BetterPromise<RequestResult<E>>;
|
|
96
|
-
/**
|
|
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.
|
|
100
|
-
*/
|
|
101
|
-
export declare function request<M extends MethodNameWithoutParams, E extends AnyEventName>(method: M, eventOrEvents: E, options?: RequestOptions<E>): BetterPromise<RequestResult<E>>;
|
|
102
|
-
export {};
|