@tma.js/bridge 2.3.2 → 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
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface Logger {
|
|
2
|
+
log: (...args: unknown[]) => void;
|
|
3
|
+
warn: (...args: unknown[]) => void;
|
|
4
|
+
error: (...args: unknown[]) => void;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Enables or disables debug mode. In debug mode, the package logs every outgoing method call
|
|
8
|
+
* and every incoming event.
|
|
9
|
+
* @param value - should the debug mode be enabled.
|
|
10
|
+
*/
|
|
11
|
+
export declare function setDebug(value: boolean): void;
|
|
12
|
+
/**
|
|
13
|
+
* @returns True if the debug mode is enabled.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isDebug(): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Replaces the package logger. Pass nothing to restore the default one.
|
|
18
|
+
* @param value - logger to use.
|
|
19
|
+
*/
|
|
20
|
+
export declare function setLogger(value?: Logger): void;
|
|
21
|
+
/**
|
|
22
|
+
* @returns The current package logger.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getLogger(): Logger;
|
|
25
|
+
/**
|
|
26
|
+
* Logs a message only in debug mode.
|
|
27
|
+
* @param args - values to log.
|
|
28
|
+
*/
|
|
29
|
+
export declare function debugLog(...args: unknown[]): void;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { LaunchParams } from './launch-params.js';
|
|
2
|
+
import { MethodName, MethodParams } from './types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Mini Apps method call intercepted by `mockTelegramEnv`.
|
|
5
|
+
*/
|
|
6
|
+
export type MockedMethodCall = {
|
|
7
|
+
[M in MethodName]: {
|
|
8
|
+
name: M;
|
|
9
|
+
params: [MethodParams<M>] extends [never] ? undefined : MethodParams<M>;
|
|
10
|
+
};
|
|
11
|
+
}[MethodName] | {
|
|
12
|
+
name: string & {};
|
|
13
|
+
params: unknown;
|
|
14
|
+
};
|
|
15
|
+
export interface MockTelegramEnvOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Launch parameters to mock. They are saved in the session storage, so the launch parameters
|
|
18
|
+
* retrieving functions return them.
|
|
19
|
+
*/
|
|
20
|
+
launchParams?: string | URLSearchParams | LaunchParams;
|
|
21
|
+
/**
|
|
22
|
+
* Function called whenever the mini app calls a Mini Apps method. Use `emitEvent` to respond
|
|
23
|
+
* to the call as the Telegram client would do.
|
|
24
|
+
* @param call - called method name and its parameters.
|
|
25
|
+
* @param next - function passing the call to the original transport, if there is one.
|
|
26
|
+
*/
|
|
27
|
+
onMethod?: (call: MockedMethodCall, next: VoidFunction) => void;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Mocks the environment to imitate the Telegram client.
|
|
31
|
+
*
|
|
32
|
+
* Use it to develop the app outside Telegram, or to intercept method calls in Telegram, for
|
|
33
|
+
* example, to fix a client not responding to some method.
|
|
34
|
+
*
|
|
35
|
+
* Outside iframes, calls are intercepted by defining `window.TelegramWebviewProxy`, so method
|
|
36
|
+
* calls performed by other libraries (e.g. the official SDK) are intercepted too. In Telegram Web
|
|
37
|
+
* (iframe), only calls performed by this package are intercepted.
|
|
38
|
+
* @param options - mock options.
|
|
39
|
+
* @returns Function reverting the mocked method calls handling. Launch parameters stay saved.
|
|
40
|
+
* When mocking several times, revert in the reverse order.
|
|
41
|
+
* @example
|
|
42
|
+
* mockTelegramEnv({
|
|
43
|
+
* launchParams: {
|
|
44
|
+
* tgWebAppPlatform: 'tdesktop',
|
|
45
|
+
* tgWebAppVersion: '9.0',
|
|
46
|
+
* tgWebAppThemeParams: { bg_color: '#ffffff' },
|
|
47
|
+
* },
|
|
48
|
+
* onMethod({ name }) {
|
|
49
|
+
* if (name === 'web_app_request_theme') {
|
|
50
|
+
* emitEvent('theme_changed', { theme_params: { bg_color: '#ffffff' } });
|
|
51
|
+
* }
|
|
52
|
+
* },
|
|
53
|
+
* });
|
|
54
|
+
*/
|
|
55
|
+
export declare function mockTelegramEnv({ launchParams, onMethod }?: MockTelegramEnvOptions): VoidFunction;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { MethodArgs, MethodName } from './types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Sets the target origin used to post messages to the parent window in Telegram Web clients.
|
|
4
|
+
*
|
|
5
|
+
* You don't need to change it until you know what you are doing.
|
|
6
|
+
* @param origin - target origin. Default: `https://web.telegram.org`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function setTargetOrigin(origin: string): void;
|
|
9
|
+
/**
|
|
10
|
+
* @returns The target origin used to post messages to the parent window.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getTargetOrigin(): string;
|
|
13
|
+
export type PostMessageFn = (message: string, targetOrigin: string) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Replaces the function posting messages to the parent window in Telegram Web clients.
|
|
16
|
+
* @param fn - function to use.
|
|
17
|
+
* @returns Function restoring the previous implementation.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export declare function setPostMessage(fn: PostMessageFn): VoidFunction;
|
|
21
|
+
/**
|
|
22
|
+
* @returns The current function posting messages to the parent window.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export declare function getPostMessage(): PostMessageFn;
|
|
26
|
+
export type PostEventFn = <M extends MethodName>(method: M, ...args: MethodArgs<M>) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Calls a Mini Apps method.
|
|
29
|
+
*
|
|
30
|
+
* Depending on the environment, the method is sent:
|
|
31
|
+
* - via `window.parent.postMessage` in Telegram Web clients;
|
|
32
|
+
* - via `window.TelegramWebviewProxy.postEvent` in Telegram for iOS, macOS, Android and Desktop;
|
|
33
|
+
* - via `window.external.notify` in Telegram for Windows Phone.
|
|
34
|
+
*
|
|
35
|
+
* @param method - method name.
|
|
36
|
+
* @param args - method parameters.
|
|
37
|
+
* @throws {UnknownEnvError} The current environment is not a Telegram Mini App.
|
|
38
|
+
* @see https://docs.telegram-mini-apps.com/platform/methods
|
|
39
|
+
*/
|
|
40
|
+
export declare const postEvent: PostEventFn;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { TimeoutError } from './errors.js';
|
|
2
|
+
import { PostEventFn } from './post-event.js';
|
|
3
|
+
import { Result } from './result.js';
|
|
4
|
+
import { EventListenerPayload, EventName, MethodName, MethodNameWithRequiredParams, MethodParams } from './types/index.js';
|
|
5
|
+
type AnyEventName = EventName | EventName[];
|
|
6
|
+
/**
|
|
7
|
+
* Value captured by the `request` function. For a list of tracked events, it also contains
|
|
8
|
+
* the event name.
|
|
9
|
+
*/
|
|
10
|
+
export type RequestResult<E extends AnyEventName> = E extends (infer U extends EventName)[] ? {
|
|
11
|
+
[K in U]: {
|
|
12
|
+
event: K;
|
|
13
|
+
payload: EventListenerPayload<K>;
|
|
14
|
+
};
|
|
15
|
+
}[U] : E extends EventName ? EventListenerPayload<E> : never;
|
|
16
|
+
export interface RequestOptions<E extends AnyEventName> {
|
|
17
|
+
/**
|
|
18
|
+
* Function returning true if the received event should be captured. If omitted, the first
|
|
19
|
+
* tracked event is captured.
|
|
20
|
+
*/
|
|
21
|
+
capture?: (value: RequestResult<E>) => boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Time in milliseconds to wait for the event. When reached, the request fails with
|
|
24
|
+
* `TimeoutError`.
|
|
25
|
+
*/
|
|
26
|
+
timeout?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Signal to abort the request. When aborted, the request is rejected with `signal.reason`.
|
|
29
|
+
*/
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
/**
|
|
32
|
+
* Custom function to call the method.
|
|
33
|
+
*/
|
|
34
|
+
postEvent?: PostEventFn;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Options of the `request` function. The `params` option is required only if the method
|
|
38
|
+
* requires parameters.
|
|
39
|
+
*/
|
|
40
|
+
export type RequestFnOptions<M extends MethodName, E extends AnyEventName> = RequestOptions<E> & ([MethodParams<M>] extends [never] ? {
|
|
41
|
+
params?: never;
|
|
42
|
+
} : M extends MethodNameWithRequiredParams ? {
|
|
43
|
+
params: MethodParams<M>;
|
|
44
|
+
} : {
|
|
45
|
+
params?: MethodParams<M>;
|
|
46
|
+
});
|
|
47
|
+
export type RequestFnArgs<M extends MethodName, E extends AnyEventName> = M extends MethodNameWithRequiredParams ? [options: RequestFnOptions<M, E>] : [options?: RequestFnOptions<M, E>];
|
|
48
|
+
/**
|
|
49
|
+
* Calls a Mini Apps method and waits for the specified event (or one of the events) to occur.
|
|
50
|
+
*
|
|
51
|
+
* Listeners are added before the method is called, so events emitted synchronously are
|
|
52
|
+
* captured too.
|
|
53
|
+
*
|
|
54
|
+
* The request is rejected with `signal.reason` if it was aborted, and with the error thrown by
|
|
55
|
+
* `postEvent` or the `capture` option.
|
|
56
|
+
* @param method - method name.
|
|
57
|
+
* @param events - event or events to wait for.
|
|
58
|
+
* @param args - additional options.
|
|
59
|
+
* @returns For a single event, its payload. For a list of events, an object with the captured
|
|
60
|
+
* event name and payload. If the timeout was reached, `TimeoutError`.
|
|
61
|
+
* @example
|
|
62
|
+
* const result = await safeRequest('web_app_request_phone', 'phone_requested', { timeout: 5000 });
|
|
63
|
+
* if (!result.ok) {
|
|
64
|
+
* console.log('The user didn\'t respond in time');
|
|
65
|
+
* }
|
|
66
|
+
*/
|
|
67
|
+
export declare function safeRequest<M extends MethodName, E extends AnyEventName>(method: M, events: E, ...args: RequestFnArgs<M, E>): Promise<Result<TimeoutError, RequestResult<E>>>;
|
|
68
|
+
/**
|
|
69
|
+
* Calls a Mini Apps method and waits for the specified event (or one of the events) to occur.
|
|
70
|
+
*
|
|
71
|
+
* Throwing version of `safeRequest`.
|
|
72
|
+
* @param method - method name.
|
|
73
|
+
* @param events - event or events to wait for.
|
|
74
|
+
* @param args - additional options.
|
|
75
|
+
* @returns For a single event, its payload. For a list of events, an object with the captured
|
|
76
|
+
* event name and payload.
|
|
77
|
+
* @throws {TimeoutError} The timeout was reached.
|
|
78
|
+
* @example
|
|
79
|
+
* const { button_id } = await request('web_app_open_popup', 'popup_closed', {
|
|
80
|
+
* params: { title: 'Hello', message: 'World', buttons: [{ id: 'ok', type: 'ok' }] },
|
|
81
|
+
* });
|
|
82
|
+
* @example
|
|
83
|
+
* const result = await request('web_app_request_phone', ['phone_requested'], { timeout: 5000 });
|
|
84
|
+
*/
|
|
85
|
+
export declare function request<M extends MethodName, E extends AnyEventName>(method: M, events: E, ...args: RequestFnArgs<M, E>): Promise<RequestResult<E>>;
|
|
86
|
+
/**
|
|
87
|
+
* @returns A new unique request identifier. Use it for methods requiring the `req_id` parameter.
|
|
88
|
+
*/
|
|
89
|
+
export declare function createRequestId(): string;
|
|
90
|
+
/**
|
|
91
|
+
* @returns Function to use in the `request` function `capture` option to capture the event
|
|
92
|
+
* with the specified request identifier.
|
|
93
|
+
* @param reqId - request identifier.
|
|
94
|
+
*/
|
|
95
|
+
export declare function captureSameReq(reqId: string): (payload: {
|
|
96
|
+
req_id: string;
|
|
97
|
+
}) => boolean;
|
|
98
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result of an operation which can fail with one of the known errors. Unlike a thrown error,
|
|
3
|
+
* the error type here is checked by the compiler.
|
|
4
|
+
*/
|
|
5
|
+
export type Result<E, T> = {
|
|
6
|
+
ok: false;
|
|
7
|
+
error: E;
|
|
8
|
+
} | {
|
|
9
|
+
ok: true;
|
|
10
|
+
data: T;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* @returns A successful result.
|
|
14
|
+
* @param data - result data.
|
|
15
|
+
*/
|
|
16
|
+
export declare function ok<T>(data: T): {
|
|
17
|
+
ok: true;
|
|
18
|
+
data: T;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* @returns A failed result.
|
|
22
|
+
* @param error - result error.
|
|
23
|
+
*/
|
|
24
|
+
export declare function err<E>(error: E): {
|
|
25
|
+
ok: false;
|
|
26
|
+
error: E;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* @returns Result data.
|
|
30
|
+
* @param result - result to unwrap.
|
|
31
|
+
* @throws The result error, if the result is failed.
|
|
32
|
+
*/
|
|
33
|
+
export declare function unwrap<E extends Error, T>(result: Result<E, T>): T;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a throwing version of a function returning a result. The created function accepts
|
|
36
|
+
* the same arguments and returns the result data, or throws the result error.
|
|
37
|
+
*
|
|
38
|
+
* Generic functions lose their type parameters when wrapped, so write their throwing versions
|
|
39
|
+
* manually using `unwrap`.
|
|
40
|
+
* @param fn - function returning a result, or a promise of it.
|
|
41
|
+
* @example
|
|
42
|
+
* export const createStartParam = throwing(safeCreateStartParam);
|
|
43
|
+
*/
|
|
44
|
+
export declare function throwing<A extends unknown[], E extends Error, T>(fn: (...args: A) => Promise<Result<E, T>>): (...args: A) => Promise<T>;
|
|
45
|
+
export declare function throwing<A extends unknown[], E extends Error, T>(fn: (...args: A) => Result<E, T>): (...args: A) => T;
|
|
@@ -1,52 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { StartParamTooLongError } from './errors.js';
|
|
2
|
+
import { Result } from './result.js';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @param value - value to create start parameter from.
|
|
9
|
-
* @see Learn more about start parameter:
|
|
10
|
-
* https://docs.telegram-mini-apps.com/platform/start-parameter
|
|
11
|
-
*/
|
|
12
|
-
export declare function createStartParamFp(value: unknown): E.Either<Error, string>;
|
|
13
|
-
/**
|
|
14
|
-
* @see createStartParamFp
|
|
15
|
-
*/
|
|
16
|
-
export declare const createStartParam: ((value: unknown) => string) & {};
|
|
17
|
-
/**
|
|
18
|
-
* @see decodeStartParamFp
|
|
19
|
-
*/
|
|
20
|
-
export declare function decodeStartParam<T>(value: string, parse: (value: string) => T): T;
|
|
21
|
-
/**
|
|
22
|
-
* @see decodeStartParamFp
|
|
4
|
+
* Encodes a string to base64url.
|
|
5
|
+
* @param value - value to encode.
|
|
6
|
+
* @see https://datatracker.ietf.org/doc/html/rfc4648#section-5
|
|
23
7
|
*/
|
|
24
|
-
export declare function
|
|
8
|
+
export declare function encodeBase64Url(value: string): string;
|
|
25
9
|
/**
|
|
26
|
-
*
|
|
10
|
+
* Decodes a base64url string.
|
|
11
|
+
* @param value - value to decode.
|
|
12
|
+
* @throws {DOMException} The value is not a valid base64url string.
|
|
13
|
+
* @throws {TypeError} The decoded value is not a valid UTF-8 string.
|
|
27
14
|
*/
|
|
28
|
-
export declare function
|
|
15
|
+
export declare function decodeBase64Url(value: string): string;
|
|
29
16
|
/**
|
|
30
|
-
*
|
|
31
|
-
* @param value -
|
|
32
|
-
* @param parse - a custom value parser.
|
|
17
|
+
* @returns True if the value can be used to create a start parameter.
|
|
18
|
+
* @param value - value to check.
|
|
33
19
|
*/
|
|
34
|
-
export declare function
|
|
20
|
+
export declare function isSafeToCreateStartParam(value: string): boolean;
|
|
35
21
|
/**
|
|
36
|
-
*
|
|
37
|
-
* @param value -
|
|
38
|
-
* @
|
|
22
|
+
* Creates a start parameter from the value. Non-string values are converted to JSON.
|
|
23
|
+
* @param value - value to encode.
|
|
24
|
+
* @returns Start parameter, or `StartParamTooLongError` if the encoded value exceeds 512
|
|
25
|
+
* characters.
|
|
26
|
+
* @see https://docs.telegram-mini-apps.com/platform/start-parameter
|
|
39
27
|
*/
|
|
40
|
-
export declare function
|
|
28
|
+
export declare function safeCreateStartParam(value: unknown): Result<StartParamTooLongError, string>;
|
|
41
29
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
30
|
+
* Creates a start parameter from the value. Non-string values are converted to JSON.
|
|
31
|
+
*
|
|
32
|
+
* Throwing version of `safeCreateStartParam`.
|
|
33
|
+
* @param value - value to encode.
|
|
34
|
+
* @throws {StartParamTooLongError} The encoded value exceeds 512 characters.
|
|
35
|
+
* @see https://docs.telegram-mini-apps.com/platform/start-parameter
|
|
44
36
|
*/
|
|
45
|
-
export declare
|
|
37
|
+
export declare const createStartParam: (value: unknown) => string;
|
|
46
38
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* @param
|
|
50
|
-
* @
|
|
39
|
+
* Decodes a start parameter created with `createStartParam`.
|
|
40
|
+
* @param value - start parameter.
|
|
41
|
+
* @param parse - `json` to parse the decoded value as JSON, or a custom parser.
|
|
42
|
+
* @throws {DOMException} The value is not a valid base64url string.
|
|
51
43
|
*/
|
|
52
|
-
export declare function
|
|
44
|
+
export declare function decodeStartParam(value: string): string;
|
|
45
|
+
export declare function decodeStartParam(value: string, parse: 'json'): unknown;
|
|
46
|
+
export declare function decodeStartParam<T>(value: string, parse: (value: string) => T): T;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { GenericSchema } from 'valibot';
|
|
2
|
+
import { ThemeParams } from './types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Schema of a raw theme parameters object.
|
|
5
|
+
*/
|
|
6
|
+
export declare const ThemeParamsSchema: GenericSchema<unknown, ThemeParams>;
|
|
7
|
+
/**
|
|
8
|
+
* Schema of theme parameters in the JSON format.
|
|
9
|
+
*/
|
|
10
|
+
export declare const ThemeParamsJsonSchema: GenericSchema<unknown, ThemeParams>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Color in the `#RRGGBB` format.
|
|
3
|
+
*/
|
|
4
|
+
export type RGB = `#${string}`;
|
|
5
|
+
/**
|
|
6
|
+
* Telegram Mini Apps platform version, e.g. `6.10` or `9.1`.
|
|
7
|
+
*/
|
|
8
|
+
export type Version = string;
|
|
9
|
+
/**
|
|
10
|
+
* Telegram application platform identifier.
|
|
11
|
+
*/
|
|
12
|
+
export type Platform = 'android' | 'android_x' | 'ios' | 'macos' | 'tdesktop' | 'weba' | 'webk' | 'unigram' | 'unknown' | string;
|
|
13
|
+
/**
|
|
14
|
+
* Theme parameters. Keys are snake-cased color names, values are colors in the `#RRGGBB` format.
|
|
15
|
+
* @see https://docs.telegram-mini-apps.com/platform/theming
|
|
16
|
+
*/
|
|
17
|
+
export interface ThemeParams {
|
|
18
|
+
/**
|
|
19
|
+
* @since v6.10
|
|
20
|
+
*/
|
|
21
|
+
accent_text_color?: RGB;
|
|
22
|
+
bg_color?: RGB;
|
|
23
|
+
/**
|
|
24
|
+
* @since v7.10
|
|
25
|
+
*/
|
|
26
|
+
bottom_bar_bg_color?: RGB;
|
|
27
|
+
button_color?: RGB;
|
|
28
|
+
button_text_color?: RGB;
|
|
29
|
+
/**
|
|
30
|
+
* @since v6.10
|
|
31
|
+
*/
|
|
32
|
+
destructive_text_color?: RGB;
|
|
33
|
+
/**
|
|
34
|
+
* @since v6.10
|
|
35
|
+
*/
|
|
36
|
+
header_bg_color?: RGB;
|
|
37
|
+
hint_color?: RGB;
|
|
38
|
+
link_color?: RGB;
|
|
39
|
+
secondary_bg_color?: RGB;
|
|
40
|
+
/**
|
|
41
|
+
* @since v6.10
|
|
42
|
+
*/
|
|
43
|
+
section_bg_color?: RGB;
|
|
44
|
+
/**
|
|
45
|
+
* @since v6.10
|
|
46
|
+
*/
|
|
47
|
+
section_header_text_color?: RGB;
|
|
48
|
+
/**
|
|
49
|
+
* @since v7.6
|
|
50
|
+
*/
|
|
51
|
+
section_separator_color?: RGB;
|
|
52
|
+
/**
|
|
53
|
+
* @since v6.10
|
|
54
|
+
*/
|
|
55
|
+
subtitle_text_color?: RGB;
|
|
56
|
+
text_color?: RGB;
|
|
57
|
+
/**
|
|
58
|
+
* Keys unknown at the moment of the package release.
|
|
59
|
+
*/
|
|
60
|
+
[key: string]: RGB | undefined;
|
|
61
|
+
}
|
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ThemeParams } from './common.js';
|
|
2
|
+
export type InvoiceStatus = 'paid' | 'failed' | 'pending' | 'cancelled' | string;
|
|
3
|
+
export type PhoneRequestedStatus = 'sent' | 'cancelled' | string;
|
|
4
|
+
export type EmojiStatusAccessRequestedStatus = 'allowed' | string;
|
|
5
|
+
export type EmojiStatusFailedError = 'SUGGESTED_EMOJI_INVALID' | 'USER_DECLINED' | string;
|
|
6
|
+
export type WriteAccessRequestedStatus = 'allowed' | string;
|
|
7
|
+
export type BiometryType = 'finger' | 'face' | string;
|
|
8
|
+
export type BiometryTokenUpdateStatus = 'updated' | 'removed' | 'failed' | string;
|
|
9
|
+
export type BiometryAuthRequestStatus = 'failed' | 'authorized' | string;
|
|
10
|
+
export type FullScreenErrorStatus = 'ALREADY_FULLSCREEN' | 'UNSUPPORTED' | string;
|
|
11
|
+
export interface SafeAreaInsets {
|
|
12
|
+
top: number;
|
|
13
|
+
bottom: number;
|
|
14
|
+
left: number;
|
|
15
|
+
right: number;
|
|
16
|
+
}
|
|
17
|
+
export type HomeScreenStatus = 'unsupported' | 'unknown' | 'added' | 'missed' | string;
|
|
4
18
|
type WithReqId<T = {}> = T & {
|
|
5
19
|
/**
|
|
6
20
|
* Unique request identifier.
|
|
@@ -187,7 +201,7 @@ export interface Events {
|
|
|
187
201
|
* A boolean that indicates whether the device is providing orientation data in
|
|
188
202
|
* absolute values.
|
|
189
203
|
*/
|
|
190
|
-
absolute?:
|
|
204
|
+
absolute?: boolean | null;
|
|
191
205
|
/**
|
|
192
206
|
* The rotation around the Z-axis, measured in radians.
|
|
193
207
|
*/
|
|
@@ -289,7 +303,7 @@ export interface Events {
|
|
|
289
303
|
* @see https://docs.telegram-mini-apps.com/platform/events#file-download-requested
|
|
290
304
|
*/
|
|
291
305
|
file_download_requested: {
|
|
292
|
-
status?:
|
|
306
|
+
status?: 'downloading' | string | null;
|
|
293
307
|
};
|
|
294
308
|
/**
|
|
295
309
|
* App entered or exited fullscreen mode.
|
|
@@ -409,8 +423,8 @@ export interface Events {
|
|
|
409
423
|
available: false;
|
|
410
424
|
} | {
|
|
411
425
|
available: true;
|
|
412
|
-
access_requested?:
|
|
413
|
-
access_granted?:
|
|
426
|
+
access_requested?: boolean | null;
|
|
427
|
+
access_granted?: boolean | null;
|
|
414
428
|
};
|
|
415
429
|
/**
|
|
416
430
|
* Location-related functionality availability status was retrieved.
|
|
@@ -432,31 +446,31 @@ export interface Events {
|
|
|
432
446
|
/**
|
|
433
447
|
* Altitude above sea level in meters.
|
|
434
448
|
*/
|
|
435
|
-
altitude?:
|
|
449
|
+
altitude?: number | null;
|
|
436
450
|
/**
|
|
437
451
|
* The direction the device is moving in degrees.
|
|
438
452
|
*/
|
|
439
|
-
course?:
|
|
453
|
+
course?: number | null;
|
|
440
454
|
/**
|
|
441
455
|
* The speed of the device in m/s.
|
|
442
456
|
*/
|
|
443
|
-
speed?:
|
|
457
|
+
speed?: number | null;
|
|
444
458
|
/**
|
|
445
459
|
* Accuracy of the latitude and longitude values in meters.
|
|
446
460
|
*/
|
|
447
|
-
horizontal_accuracy?:
|
|
461
|
+
horizontal_accuracy?: number | null;
|
|
448
462
|
/**
|
|
449
463
|
* Accuracy of the altitude value in meters.
|
|
450
464
|
*/
|
|
451
|
-
vertical_accuracy?:
|
|
465
|
+
vertical_accuracy?: number | null;
|
|
452
466
|
/**
|
|
453
467
|
* Accuracy of the course value in degrees.
|
|
454
468
|
*/
|
|
455
|
-
course_accuracy?:
|
|
469
|
+
course_accuracy?: number | null;
|
|
456
470
|
/**
|
|
457
471
|
* Accuracy of the speed value in m/s.
|
|
458
472
|
*/
|
|
459
|
-
speed_accuracy?:
|
|
473
|
+
speed_accuracy?: number | null;
|
|
460
474
|
};
|
|
461
475
|
/**
|
|
462
476
|
* A user clicked the Main Button.
|
|
@@ -519,6 +533,23 @@ export interface Events {
|
|
|
519
533
|
* @see https://docs.telegram-mini-apps.com/platform/events#reload-iframe
|
|
520
534
|
*/
|
|
521
535
|
reload_iframe: never;
|
|
536
|
+
/**
|
|
537
|
+
* Failed to share a chat requested via the `web_app_request_chat` method.
|
|
538
|
+
* @since v9.6
|
|
539
|
+
* @see https://docs.telegram-mini-apps.com/platform/events#requested-chat-failed
|
|
540
|
+
*/
|
|
541
|
+
requested_chat_failed: {
|
|
542
|
+
/**
|
|
543
|
+
* Occurred error.
|
|
544
|
+
*/
|
|
545
|
+
error: string;
|
|
546
|
+
};
|
|
547
|
+
/**
|
|
548
|
+
* A chat requested via the `web_app_request_chat` method was shared.
|
|
549
|
+
* @since v9.6
|
|
550
|
+
* @see https://docs.telegram-mini-apps.com/platform/events#requested-chat-sent
|
|
551
|
+
*/
|
|
552
|
+
requested_chat_sent: never;
|
|
522
553
|
/**
|
|
523
554
|
* Occurs whenever the device's safe area insets change
|
|
524
555
|
* (e.g., due to orientation change or screen adjustments).
|
|
@@ -613,44 +644,7 @@ export interface Events {
|
|
|
613
644
|
* corresponding color in
|
|
614
645
|
* `#RRGGBB` format.
|
|
615
646
|
*/
|
|
616
|
-
theme_params:
|
|
617
|
-
/**
|
|
618
|
-
* @since v6.10
|
|
619
|
-
*/
|
|
620
|
-
accent_text_color?: RGB;
|
|
621
|
-
/**
|
|
622
|
-
* @since 7.10
|
|
623
|
-
*/
|
|
624
|
-
bottom_bar_bg_color?: RGB;
|
|
625
|
-
bg_color?: RGB;
|
|
626
|
-
button_color?: RGB;
|
|
627
|
-
button_text_color?: RGB;
|
|
628
|
-
/**
|
|
629
|
-
* @since v6.10
|
|
630
|
-
*/
|
|
631
|
-
destructive_text_color?: RGB;
|
|
632
|
-
/**
|
|
633
|
-
* @since v6.10
|
|
634
|
-
*/
|
|
635
|
-
header_bg_color?: RGB;
|
|
636
|
-
hint_color?: RGB;
|
|
637
|
-
link_color?: RGB;
|
|
638
|
-
secondary_bg_color?: RGB;
|
|
639
|
-
/**
|
|
640
|
-
* @since v6.10
|
|
641
|
-
*/
|
|
642
|
-
section_bg_color?: RGB;
|
|
643
|
-
/**
|
|
644
|
-
* @since v6.10
|
|
645
|
-
*/
|
|
646
|
-
section_header_text_color?: RGB;
|
|
647
|
-
/**
|
|
648
|
-
* @since v6.10
|
|
649
|
-
*/
|
|
650
|
-
subtitle_text_color?: RGB;
|
|
651
|
-
text_color?: RGB;
|
|
652
|
-
[key: string]: RGB | undefined;
|
|
653
|
-
};
|
|
647
|
+
theme_params: ThemeParams;
|
|
654
648
|
};
|
|
655
649
|
/**
|
|
656
650
|
* Occurs whenever the viewport has been changed. For example, when the user
|
|
@@ -712,10 +706,35 @@ export type EventName = keyof Events;
|
|
|
712
706
|
* Payload of the specified Mini Apps event.
|
|
713
707
|
*/
|
|
714
708
|
export type EventPayload<E extends EventName> = Events[E];
|
|
715
|
-
|
|
716
|
-
|
|
709
|
+
/**
|
|
710
|
+
* Events having no payload.
|
|
711
|
+
*/
|
|
712
|
+
export type EventNameWithoutPayload = {
|
|
713
|
+
[E in EventName]: [EventPayload<E>] extends [never] ? E : never;
|
|
717
714
|
}[EventName];
|
|
718
|
-
|
|
719
|
-
|
|
715
|
+
/**
|
|
716
|
+
* Events having payload.
|
|
717
|
+
*/
|
|
718
|
+
export type EventNameWithPayload = Exclude<EventName, EventNameWithoutPayload>;
|
|
719
|
+
/**
|
|
720
|
+
* Value passed to event listeners. Events without payload produce `undefined`.
|
|
721
|
+
*/
|
|
722
|
+
export type EventListenerPayload<E extends EventName> = [EventPayload<E>] extends [never] ? undefined : EventPayload<E>;
|
|
723
|
+
/**
|
|
724
|
+
* Listener of the specified Mini Apps event.
|
|
725
|
+
*/
|
|
726
|
+
export type EventListener<E extends EventName> = (payload: EventListenerPayload<E>) => void;
|
|
727
|
+
/**
|
|
728
|
+
* Any Mini Apps event with its payload.
|
|
729
|
+
*/
|
|
730
|
+
export type AnyEvent = {
|
|
731
|
+
[E in EventName]: {
|
|
732
|
+
name: E;
|
|
733
|
+
payload: EventListenerPayload<E>;
|
|
734
|
+
};
|
|
720
735
|
}[EventName];
|
|
736
|
+
/**
|
|
737
|
+
* Listener of all Mini Apps events.
|
|
738
|
+
*/
|
|
739
|
+
export type AnyEventListener = (event: AnyEvent) => void;
|
|
721
740
|
export {};
|