@tma.js/sdk 1.4.8 → 1.5.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.
Files changed (155) hide show
  1. package/dist/dts/bridge/captureSameReq.d.ts +10 -0
  2. package/dist/dts/bridge/errors/MethodUnsupportedError.d.ts +2 -2
  3. package/dist/dts/bridge/errors/ParameterUnsupportedError.d.ts +2 -2
  4. package/dist/dts/bridge/events/events.d.ts +13 -3
  5. package/dist/dts/bridge/events/on.d.ts +2 -3
  6. package/dist/dts/bridge/events/once.d.ts +2 -3
  7. package/dist/dts/bridge/events/parsers/clipboardTextReceived.d.ts +2 -2
  8. package/dist/dts/bridge/events/parsers/customMethodInvoked.d.ts +2 -2
  9. package/dist/dts/bridge/events/parsers/invoiceClosed.d.ts +1 -1
  10. package/dist/dts/bridge/events/parsers/phoneRequested.d.ts +1 -1
  11. package/dist/dts/bridge/events/parsers/popupClosed.d.ts +1 -1
  12. package/dist/dts/bridge/events/parsers/qrTextReceived.d.ts +1 -1
  13. package/dist/dts/bridge/events/parsers/theme-changed.d.ts +2 -2
  14. package/dist/dts/bridge/events/parsers/viewportChanged.d.ts +1 -1
  15. package/dist/dts/bridge/events/parsers/writeAccessRequested.d.ts +1 -1
  16. package/dist/dts/bridge/events/singletonEmitter.d.ts +1 -1
  17. package/dist/dts/bridge/events/subscribe.d.ts +2 -3
  18. package/dist/dts/bridge/events/types.d.ts +4 -0
  19. package/dist/dts/bridge/invokeCustomMethod.d.ts +2 -2
  20. package/dist/dts/bridge/methods/createPostEvent.d.ts +1 -1
  21. package/dist/dts/bridge/methods/custom-methods.d.ts +1 -1
  22. package/dist/dts/bridge/methods/methods.d.ts +9 -8
  23. package/dist/dts/bridge/request.d.ts +38 -40
  24. package/dist/dts/classnames/mergeClassNames.d.ts +2 -18
  25. package/dist/dts/{back-button → components/back-button}/BackButton.d.ts +4 -4
  26. package/dist/dts/{back-button → components/back-button}/types.d.ts +2 -2
  27. package/dist/dts/{closing-behavior → components/closing-behavior}/ClosingBehavior.d.ts +6 -3
  28. package/dist/dts/{closing-behavior → components/closing-behavior}/types.d.ts +1 -1
  29. package/dist/dts/{cloud-storage → components/cloud-storage}/CloudStorage.d.ts +5 -4
  30. package/dist/dts/{haptic-feedback → components/haptic-feedback}/HapticFeedback.d.ts +4 -3
  31. package/dist/dts/components/init-data/chatParser.d.ts +6 -0
  32. package/dist/dts/components/init-data/initDataParser.d.ts +6 -0
  33. package/dist/dts/components/init-data/userParser.d.ts +6 -0
  34. package/dist/dts/{invoice → components/invoice}/Invoice.d.ts +9 -5
  35. package/dist/dts/{invoice → components/invoice}/types.d.ts +1 -1
  36. package/dist/dts/{main-button → components/main-button}/MainButton.d.ts +2 -2
  37. package/dist/dts/{main-button → components/main-button}/types.d.ts +3 -3
  38. package/dist/dts/{mini-app → components/mini-app}/MiniApp.d.ts +11 -6
  39. package/dist/dts/components/mini-app/contactParser.d.ts +2 -0
  40. package/dist/dts/{mini-app → components/mini-app}/types.d.ts +6 -5
  41. package/dist/dts/{popup → components/popup}/Popup.d.ts +8 -5
  42. package/dist/dts/{popup → components/popup}/preparePopupParams.d.ts +1 -1
  43. package/dist/dts/{popup → components/popup}/types.d.ts +1 -1
  44. package/dist/dts/{qr-scanner → components/qr-scanner}/QRScanner.d.ts +8 -5
  45. package/dist/dts/{qr-scanner → components/qr-scanner}/types.d.ts +1 -1
  46. package/dist/dts/{settings-button → components/settings-button}/SettingsButton.d.ts +4 -4
  47. package/dist/dts/{settings-button → components/settings-button}/types.d.ts +2 -2
  48. package/dist/dts/{theme-params → components/theme-params}/ThemeParams.d.ts +8 -4
  49. package/dist/dts/components/theme-params/requestThemeParams.d.ts +7 -0
  50. package/dist/dts/components/theme-params/themeParamsParser.d.ts +3 -0
  51. package/dist/dts/{theme-params → components/theme-params}/types.d.ts +2 -2
  52. package/dist/dts/{utils → components/utils}/Utils.d.ts +4 -4
  53. package/dist/dts/{viewport → components/viewport}/Viewport.d.ts +9 -5
  54. package/dist/dts/{viewport → components/viewport}/isStableViewportPlatform.d.ts +1 -1
  55. package/dist/dts/{viewport → components/viewport}/requestViewport.d.ts +2 -2
  56. package/dist/dts/{viewport → components/viewport}/types.d.ts +2 -2
  57. package/dist/dts/css/bindMiniAppCSSVars.d.ts +2 -2
  58. package/dist/dts/css/bindThemeCSSVars.d.ts +1 -1
  59. package/dist/dts/css/bindViewportCSSVars.d.ts +1 -1
  60. package/dist/dts/event-emitter/types.d.ts +1 -1
  61. package/dist/dts/globals.d.ts +1 -1
  62. package/dist/dts/index.d.ts +144 -27
  63. package/dist/dts/init/creators/createBackButton.d.ts +2 -2
  64. package/dist/dts/init/creators/createClosingBehavior.d.ts +2 -2
  65. package/dist/dts/init/creators/createMainButton.d.ts +3 -3
  66. package/dist/dts/init/creators/createMiniApp.d.ts +5 -5
  67. package/dist/dts/init/creators/createRequestIdGenerator.d.ts +1 -1
  68. package/dist/dts/init/creators/createSettingsButton.d.ts +2 -2
  69. package/dist/dts/init/creators/createThemeParams.d.ts +2 -1
  70. package/dist/dts/init/creators/createViewport.d.ts +3 -3
  71. package/dist/dts/init/css/processCSSVarsOption.d.ts +3 -3
  72. package/dist/dts/init/types.d.ts +16 -16
  73. package/dist/dts/launch-params/launchParamsParser.d.ts +2 -1
  74. package/dist/dts/launch-params/types.d.ts +3 -3
  75. package/dist/dts/navigation/HashNavigator/HashNavigator.d.ts +6 -3
  76. package/dist/dts/navigation/HashNavigator/types.d.ts +1 -2
  77. package/dist/dts/navigation/Navigator/Navigator.d.ts +1 -1
  78. package/dist/dts/parsing/ValueParser.d.ts +1 -1
  79. package/dist/dts/parsing/parsers/array.d.ts +2 -2
  80. package/dist/dts/parsing/parsers/boolean.d.ts +2 -1
  81. package/dist/dts/parsing/parsers/date.d.ts +2 -1
  82. package/dist/dts/parsing/parsers/number.d.ts +2 -1
  83. package/dist/dts/parsing/parsers/rgb.d.ts +3 -1
  84. package/dist/dts/parsing/parsers/string.d.ts +2 -1
  85. package/dist/dts/state/State.d.ts +2 -2
  86. package/dist/dts/state/types.d.ts +1 -1
  87. package/dist/dts/storage.d.ts +2 -2
  88. package/dist/dts/supports/createSupportsFunc.d.ts +2 -2
  89. package/dist/dts/supports/createSupportsParamFunc.d.ts +2 -2
  90. package/dist/dts/supports/supports.d.ts +2 -2
  91. package/dist/dts/supports/types.d.ts +3 -0
  92. package/dist/dts/timeout/withTimeout.d.ts +2 -2
  93. package/dist/dts/types/logical.d.ts +16 -0
  94. package/dist/dts/types/methods.d.ts +1 -1
  95. package/dist/dts/types/unions.d.ts +20 -0
  96. package/dist/dts/types/utils.d.ts +0 -28
  97. package/dist/dts/version/compareVersions.d.ts +2 -1
  98. package/dist/dts/version/types.d.ts +1 -0
  99. package/dist/index.cjs +1 -1
  100. package/dist/index.iife.js +1 -1
  101. package/dist/index.mjs +1714 -1702
  102. package/package.json +1 -1
  103. package/dist/dts/back-button/index.d.ts +0 -2
  104. package/dist/dts/bridge/env/index.d.ts +0 -2
  105. package/dist/dts/bridge/errors/index.d.ts +0 -2
  106. package/dist/dts/bridge/events/index.d.ts +0 -9
  107. package/dist/dts/bridge/events/parsers/index.d.ts +0 -9
  108. package/dist/dts/bridge/index.d.ts +0 -7
  109. package/dist/dts/bridge/methods/index.d.ts +0 -6
  110. package/dist/dts/classnames/index.d.ts +0 -2
  111. package/dist/dts/closing-behavior/index.d.ts +0 -2
  112. package/dist/dts/cloud-storage/index.d.ts +0 -1
  113. package/dist/dts/colors/index.d.ts +0 -5
  114. package/dist/dts/css/index.d.ts +0 -4
  115. package/dist/dts/event-emitter/index.d.ts +0 -2
  116. package/dist/dts/haptic-feedback/index.d.ts +0 -1
  117. package/dist/dts/init/creators/index.d.ts +0 -8
  118. package/dist/dts/init/css/index.d.ts +0 -1
  119. package/dist/dts/init/index.d.ts +0 -2
  120. package/dist/dts/init-data/chatParser.d.ts +0 -5
  121. package/dist/dts/init-data/index.d.ts +0 -6
  122. package/dist/dts/init-data/initDataParser.d.ts +0 -5
  123. package/dist/dts/init-data/userParser.d.ts +0 -5
  124. package/dist/dts/invoice/index.d.ts +0 -2
  125. package/dist/dts/launch-params/index.d.ts +0 -10
  126. package/dist/dts/logger/index.d.ts +0 -1
  127. package/dist/dts/main-button/index.d.ts +0 -2
  128. package/dist/dts/mini-app/contactParser.d.ts +0 -2
  129. package/dist/dts/mini-app/index.d.ts +0 -2
  130. package/dist/dts/misc/index.d.ts +0 -5
  131. package/dist/dts/navigation/HashNavigator/index.d.ts +0 -2
  132. package/dist/dts/navigation/Navigator/index.d.ts +0 -2
  133. package/dist/dts/navigation/index.d.ts +0 -4
  134. package/dist/dts/parsing/index.d.ts +0 -10
  135. package/dist/dts/parsing/parsers/index.d.ts +0 -8
  136. package/dist/dts/popup/index.d.ts +0 -2
  137. package/dist/dts/qr-scanner/index.d.ts +0 -2
  138. package/dist/dts/settings-button/index.d.ts +0 -2
  139. package/dist/dts/state/index.d.ts +0 -2
  140. package/dist/dts/supports/index.d.ts +0 -4
  141. package/dist/dts/theme-params/index.d.ts +0 -6
  142. package/dist/dts/theme-params/requestThemeParams.d.ts +0 -7
  143. package/dist/dts/theme-params/themeParamsParser.d.ts +0 -2
  144. package/dist/dts/timeout/index.d.ts +0 -4
  145. package/dist/dts/types/index.d.ts +0 -4
  146. package/dist/dts/utils/index.d.ts +0 -1
  147. package/dist/dts/version/index.d.ts +0 -2
  148. package/dist/dts/viewport/index.d.ts +0 -4
  149. /package/dist/dts/{init-data → components/init-data}/InitData.d.ts +0 -0
  150. /package/dist/dts/{init-data → components/init-data}/parseInitData.d.ts +0 -0
  151. /package/dist/dts/{init-data → components/init-data}/types.d.ts +0 -0
  152. /package/dist/dts/{theme-params → components/theme-params}/keys.d.ts +0 -0
  153. /package/dist/dts/{theme-params → components/theme-params}/parseThemeParams.d.ts +0 -0
  154. /package/dist/dts/{theme-params → components/theme-params}/serializeThemeParams.d.ts +0 -0
  155. /package/dist/dts/{viewport → components/viewport}/utils.d.ts +0 -0
@@ -0,0 +1,10 @@
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,5 +1,5 @@
1
- import type { Version } from '../../version/index.js';
2
- import type { MiniAppsMethodName } from '../methods/index.js';
1
+ import type { Version } from '../../version/types.js';
2
+ import type { MiniAppsMethodName } from '../methods/methods.js';
3
3
  /**
4
4
  * Error thrown in case, unsupported method was called.
5
5
  */
@@ -1,5 +1,5 @@
1
- import type { Version } from '../../version/index.js';
2
- import type { MiniAppsMethodName } from '../methods/index.js';
1
+ import type { Version } from '../../version/types.js';
2
+ import type { MiniAppsMethodName } from '../methods/methods.js';
3
3
  /**
4
4
  * Error thrown in case, unsupported parameter was used.
5
5
  */
@@ -1,6 +1,16 @@
1
- import type { AnySubscribeListener, EventEmitter, EventListener, EventParams } from '../../event-emitter/index.js';
2
- import type { IsNever, Not } from '../../types/index.js';
3
- import type { ClipboardTextReceivedPayload, CustomMethodInvokedPayload, InvoiceClosedPayload, PhoneRequestedPayload, PopupClosedPayload, QrTextReceivedPayload, ThemeChangedPayload, ViewportChangedPayload, WriteAccessRequestedPayload } from './parsers/index.js';
1
+ import type { ClipboardTextReceivedPayload } from './parsers/clipboardTextReceived.js';
2
+ import type { CustomMethodInvokedPayload } from './parsers/customMethodInvoked.js';
3
+ import type { InvoiceClosedPayload } from './parsers/invoiceClosed.js';
4
+ import type { PhoneRequestedPayload } from './parsers/phoneRequested.js';
5
+ import type { PopupClosedPayload } from './parsers/popupClosed.js';
6
+ import type { QrTextReceivedPayload } from './parsers/qrTextReceived.js';
7
+ import type { ThemeChangedPayload } from './parsers/theme-changed.js';
8
+ import type { ViewportChangedPayload } from './parsers/viewportChanged.js';
9
+ import type { WriteAccessRequestedPayload } from './parsers/writeAccessRequested.js';
10
+ import type { EventEmitter } from '../../event-emitter/EventEmitter.js';
11
+ import type { AnySubscribeListener, EventListener, EventParams } from '../../event-emitter/types.js';
12
+ import type { Not } from '../../types/logical.js';
13
+ import type { IsNever } from '../../types/utils.js';
4
14
  /**
5
15
  * Map where key is known event name, and value is its listener.
6
16
  * @see https://docs.telegram-mini-apps.com/platform/events
@@ -1,10 +1,9 @@
1
1
  import type { MiniAppsEventListener, MiniAppsEventName } from './events.js';
2
- type StopListening = () => void;
2
+ import type { RemoveListenerFn } from './types.js';
3
3
  /**
4
4
  * Adds new listener to the specified event. Returns handler
5
5
  * which allows to stop listening to event.
6
6
  * @param event - event name.
7
7
  * @param listener - event listener.
8
8
  */
9
- export declare function on<E extends MiniAppsEventName>(event: E, listener: MiniAppsEventListener<E>): StopListening;
10
- export {};
9
+ export declare function on<E extends MiniAppsEventName>(event: E, listener: MiniAppsEventListener<E>): RemoveListenerFn;
@@ -1,9 +1,8 @@
1
1
  import type { MiniAppsEventListener, MiniAppsEventName } from './events.js';
2
- type StopListening = () => void;
2
+ import type { RemoveListenerFn } from './types.js';
3
3
  /**
4
4
  * Works the same as "on" method, but after catching the event, will remove event listener.
5
5
  * @param event - event name.
6
6
  * @param listener - event listener.
7
7
  */
8
- export declare function once<E extends MiniAppsEventName>(event: E, listener: MiniAppsEventListener<E>): StopListening;
9
- export {};
8
+ export declare function once<E extends MiniAppsEventName>(event: E, listener: MiniAppsEventListener<E>): RemoveListenerFn;
@@ -1,4 +1,4 @@
1
- import type { RequestId } from '../../../types/index.js';
1
+ import type { RequestId } from '../../../types/request-id.js';
2
2
  export interface ClipboardTextReceivedPayload {
3
3
  /**
4
4
  * Passed during the `web_app_read_text_from_clipboard` method invocation `req_id` value.
@@ -10,4 +10,4 @@ export interface ClipboardTextReceivedPayload {
10
10
  */
11
11
  data?: string | null;
12
12
  }
13
- export declare function clipboardTextReceived(): import('../../../parsing/index.js').ValueParser<ClipboardTextReceivedPayload, false>;
13
+ export declare function clipboardTextReceived(): import("../../../parsing/ValueParser.js").ValueParser<ClipboardTextReceivedPayload, false>;
@@ -1,4 +1,4 @@
1
- import type { RequestId } from '../../../types/index.js';
1
+ import type { RequestId } from '../../../types/request-id.js';
2
2
  export interface CustomMethodInvokedPayload<R = unknown> {
3
3
  /**
4
4
  * Unique identifier of this invocation.
@@ -13,4 +13,4 @@ export interface CustomMethodInvokedPayload<R = unknown> {
13
13
  */
14
14
  error?: string;
15
15
  }
16
- export declare function customMethodInvoked(): import('../../../parsing/index.js').ValueParser<CustomMethodInvokedPayload<unknown>, false>;
16
+ export declare function customMethodInvoked(): import("../../../parsing/ValueParser.js").ValueParser<CustomMethodInvokedPayload<unknown>, false>;
@@ -9,4 +9,4 @@ export interface InvoiceClosedPayload {
9
9
  */
10
10
  status: InvoiceStatus;
11
11
  }
12
- export declare function invoiceClosed(): import('../../../parsing/index.js').ValueParser<InvoiceClosedPayload, false>;
12
+ export declare function invoiceClosed(): import("../../../parsing/ValueParser.js").ValueParser<InvoiceClosedPayload, false>;
@@ -5,4 +5,4 @@ export interface PhoneRequestedPayload {
5
5
  */
6
6
  status: PhoneRequestedStatus;
7
7
  }
8
- export declare function phoneRequested(): import('../../../parsing/index.js').ValueParser<PhoneRequestedPayload, false>;
8
+ export declare function phoneRequested(): import("../../../parsing/ValueParser.js").ValueParser<PhoneRequestedPayload, false>;
@@ -5,4 +5,4 @@ export interface PopupClosedPayload {
5
5
  */
6
6
  button_id?: string;
7
7
  }
8
- export declare function popupClosed(): import('../../../parsing/index.js').ValueParser<PopupClosedPayload, false>;
8
+ export declare function popupClosed(): import("../../../parsing/ValueParser.js").ValueParser<PopupClosedPayload, false>;
@@ -4,4 +4,4 @@ export interface QrTextReceivedPayload {
4
4
  */
5
5
  data?: string;
6
6
  }
7
- export declare function qrTextReceived(): import('../../../parsing/index.js').ValueParser<QrTextReceivedPayload, false>;
7
+ export declare function qrTextReceived(): import("../../../parsing/ValueParser.js").ValueParser<QrTextReceivedPayload, false>;
@@ -1,4 +1,4 @@
1
- import type { RGB } from '../../../colors/index.js';
1
+ import type { RGB } from '../../../colors/types.js';
2
2
  export interface ThemeChangedPayload {
3
3
  /**
4
4
  * Map where the key is a theme stylesheet key and value is the corresponding color in
@@ -39,4 +39,4 @@ export interface ThemeChangedPayload {
39
39
  [key: string]: RGB | undefined;
40
40
  };
41
41
  }
42
- export declare function themeChanged(): import('../../../parsing/index.js').ValueParser<ThemeChangedPayload, false>;
42
+ export declare function themeChanged(): import("../../../parsing/ValueParser.js").ValueParser<ThemeChangedPayload, false>;
@@ -16,4 +16,4 @@ export interface ViewportChangedPayload {
16
16
  */
17
17
  is_state_stable: boolean;
18
18
  }
19
- export declare function viewportChanged(): import('../../../parsing/index.js').ValueParser<ViewportChangedPayload, false>;
19
+ export declare function viewportChanged(): import("../../../parsing/ValueParser.js").ValueParser<ViewportChangedPayload, false>;
@@ -5,4 +5,4 @@ export interface WriteAccessRequestedPayload {
5
5
  */
6
6
  status: WriteAccessRequestedStatus;
7
7
  }
8
- export declare function writeAccessRequested(): import('../../../parsing/index.js').ValueParser<WriteAccessRequestedPayload, false>;
8
+ export declare function writeAccessRequested(): import("../../../parsing/ValueParser.js").ValueParser<WriteAccessRequestedPayload, false>;
@@ -1,4 +1,4 @@
1
- import type { MiniAppsEventEmitter } from '../../bridge/index.js';
1
+ import type { MiniAppsEventEmitter } from './events.js';
2
2
  /**
3
3
  * Returns singleton instance of bridge EventEmitter. Also, defines
4
4
  * Telegram event handlers.
@@ -1,9 +1,8 @@
1
1
  import type { MiniAppsGlobalEventListener } from './events.js';
2
- type StopListening = () => void;
2
+ import type { RemoveListenerFn } from './types.js';
3
3
  /**
4
4
  * Subscribes to all events sent from the native Telegram application.
5
5
  * Returns function used to remove added event listener.
6
6
  * @param listener - event listener.
7
7
  */
8
- export declare function subscribe(listener: MiniAppsGlobalEventListener): StopListening;
9
- export {};
8
+ export declare function subscribe(listener: MiniAppsGlobalEventListener): RemoveListenerFn;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Removes event listener.
3
+ */
4
+ export type RemoveListenerFn = () => void;
@@ -1,5 +1,5 @@
1
- import type { ExecuteWithOptions } from '../types/index.js';
2
- import type { CustomMethodName, CustomMethodParams } from './methods/index.js';
1
+ import type { CustomMethodName, CustomMethodParams } from './methods/custom-methods.js';
2
+ import type { ExecuteWithOptions } from '../types/methods.js';
3
3
  /**
4
4
  * Invokes known custom method. Returns method execution result.
5
5
  * @param method - method name.
@@ -1,5 +1,5 @@
1
- import type { Version } from '../../version/index.js';
2
1
  import { type PostEvent } from './postEvent.js';
2
+ import type { Version } from '../../version/types.js';
3
3
  /**
4
4
  * Creates function which checks if specified method and parameters are supported. In case,
5
5
  * method or parameters are unsupported, an error will be thrown.
@@ -1,4 +1,4 @@
1
- import type { RequestId } from '../../types/index.js';
1
+ import type { RequestId } from '../../types/request-id.js';
2
2
  interface CreateInvokeCustomMethodParams<M extends string, Params extends object> {
3
3
  /**
4
4
  * Unique request identifier.
@@ -1,8 +1,11 @@
1
- import type { RGB } from '../../colors/index.js';
2
- import type { IsNever, Not, RequestId, UnionKeys } from '../../types/index.js';
3
1
  import type { AnyInvokeCustomMethodParams } from './custom-methods.js';
4
2
  import type { AnyHapticFeedbackParams } from './haptic.js';
5
3
  import type { PopupParams } from './popup.js';
4
+ import type { RGB } from '../../colors/types.js';
5
+ import type { If, Not } from '../../types/logical.js';
6
+ import type { RequestId } from '../../types/request-id.js';
7
+ import type { UnionKeys } from '../../types/unions.js';
8
+ import type { IsNever } from '../../types/utils.js';
6
9
  /**
7
10
  * Color key which could be used to update header color.
8
11
  */
@@ -11,7 +14,7 @@ export type HeaderColorKey = 'bg_color' | 'secondary_bg_color';
11
14
  * Chat type which could be used when calling `web_app_switch_inline_query` method.
12
15
  */
13
16
  export type SwitchInlineQueryChatType = 'users' | 'bots' | 'groups' | 'channels';
14
- interface CreateParams<Params = undefined, VersionedParam extends UnionKeys<Params> = never> {
17
+ interface CreateParams<Params = never, VersionedParam extends UnionKeys<Params> = never> {
15
18
  params: Params;
16
19
  versionedParams: VersionedParam;
17
20
  }
@@ -303,19 +306,17 @@ export type MiniAppsMethodParams<M extends MiniAppsMethodName> = MiniAppsMethods
303
306
  /**
304
307
  * True if specified method accepts parameters.
305
308
  */
306
- export type MiniAppsMethodAcceptParams<M extends MiniAppsMethodName> = Not<IsNever<Exclude<MiniAppsMethodParams<M>, undefined>>>;
309
+ export type MiniAppsMethodAcceptParams<M extends MiniAppsMethodName> = Not<IsNever<MiniAppsMethodParams<M>>>;
307
310
  /**
308
311
  * Any post-available event name which does not require arguments.
309
312
  */
310
313
  export type MiniAppsEmptyMethodName = {
311
- [M in MiniAppsMethodName]: undefined extends MiniAppsMethodParams<M> ? M : never;
314
+ [Method in MiniAppsMethodName]: If<MiniAppsMethodAcceptParams<Method>, never, Method>;
312
315
  }[MiniAppsMethodName];
313
316
  /**
314
317
  * Any post-available event name which require arguments.
315
318
  */
316
- export type MiniAppsNonEmptyMethodName = {
317
- [M in MiniAppsMethodName]: MiniAppsMethodAcceptParams<M> extends true ? M : never;
318
- }[MiniAppsMethodName];
319
+ export type MiniAppsNonEmptyMethodName = Exclude<MiniAppsMethodName, MiniAppsEmptyMethodName>;
319
320
  /**
320
321
  * Method names which have versioned params.
321
322
  */
@@ -1,56 +1,54 @@
1
- import type { And, ExecuteWithOptions, If, IsNever } from '../types/index.js';
2
- import { type MiniAppsEventHasParams, type MiniAppsEventName, type MiniAppsEventParams } from './events/index.js';
3
- import { type MiniAppsEmptyMethodName, type MiniAppsMethodAcceptParams, type MiniAppsMethodName, type MiniAppsMethodParams, type MiniAppsNonEmptyMethodName } from './methods/index.js';
1
+ import type { MiniAppsEventName, MiniAppsEventParams } from './events/events.js';
2
+ import type { MiniAppsEmptyMethodName, MiniAppsMethodName, MiniAppsMethodParams, MiniAppsNonEmptyMethodName } from './methods/methods.js';
3
+ import type { If } from '../types/logical.js';
4
+ import type { ExecuteWithOptions } from '../types/methods.js';
5
+ import type { IsNever } from '../types/utils.js';
4
6
  /**
5
- * Names of methods, which require passing "req_id" parameter.
7
+ * Simple `request` method options.
6
8
  */
7
- type MethodWithRequestId = {
8
- [M in MiniAppsMethodName]: If<And<MiniAppsMethodAcceptParams<M>, MiniAppsMethodParams<M> extends {
9
- req_id: string;
10
- } ? true : false>, M, never>;
11
- }[MiniAppsMethodName];
9
+ export type RequestSimpleOptions<Method extends MiniAppsMethodName> = Omit<RequestCompleteOptions<Method, any>, 'method' | 'event'>;
12
10
  /**
13
- * Names of events, which contain "req_id" parameter.
11
+ * Complete `request` method options.
14
12
  */
15
- type EventWithRequestId = {
16
- [E in MiniAppsEventName]: If<And<MiniAppsEventHasParams<E>, MiniAppsEventParams<E> extends {
17
- req_id: string;
18
- } ? true : false>, E, never>;
19
- }[MiniAppsEventName];
20
- export interface RequestOptions extends ExecuteWithOptions {
21
- }
22
- export interface RequestOptionsAdvanced<EventPayload> extends RequestOptions {
13
+ export type RequestCompleteOptions<Method extends MiniAppsMethodName, Event extends MiniAppsEventName> = {
14
+ /**
15
+ * Mini Apps method name.
16
+ */
17
+ method: Method;
18
+ /**
19
+ * One or many tracked Mini Apps events.
20
+ */
21
+ event: Event | Event[];
23
22
  /**
24
23
  * Should return true in case, this event should be captured. If not specified,
25
24
  * request is not skipping captured events.
26
25
  */
27
- capture?: If<IsNever<EventPayload>, () => boolean, (payload: EventPayload) => boolean>;
28
- }
26
+ capture?: If<IsNever<MiniAppsEventParams<Event>>, () => boolean, (payload: MiniAppsEventParams<Event>) => boolean>;
27
+ } & ExecuteWithOptions & If<IsNever<MiniAppsMethodParams<Method>>, {}, {
28
+ /**
29
+ * List of method parameters.
30
+ */
31
+ params: MiniAppsMethodParams<Method>;
32
+ }>;
29
33
  /**
30
- * Calls specified TWA method and captures one of the specified events. Returns promise
31
- * which will be resolved in case, event with specified in method request identifier
32
- * was captured.
33
- * @param method - method to execute.
34
- * @param params - method parameters.
35
- * @param event - event or events to listen.
36
- * @param options - additional execution options.
34
+ * Calls specified Mini Apps method and captures one of the specified events. Returns promise
35
+ * which will be resolved in case, specified event was captured.
36
+ * @param options - method options.
37
37
  */
38
- export declare function request<M extends MethodWithRequestId, E extends EventWithRequestId>(method: M, params: MiniAppsMethodParams<M>, event: E | E[], options?: RequestOptions): Promise<MiniAppsEventParams<E>>;
38
+ export declare function request<Method extends MiniAppsEmptyMethodName, Event extends MiniAppsEventName>(options: RequestCompleteOptions<Method, Event>): Promise<MiniAppsEventParams<Event>>;
39
39
  /**
40
- * Calls specified TWA method and captures one of the specified events. Returns promise
40
+ * Calls specified Mini Apps method and captures one of the specified events. Returns promise
41
41
  * which will be resolved in case, specified event was captured.
42
- * @param method - method to execute.
43
- * @param event - event or events to listen.
44
- * @param options - additional execution options.
42
+ * @param method - method name.
43
+ * @param eventOrEvents - tracked event or events.
44
+ * @param options - method options.
45
45
  */
46
- export declare function request<M extends MiniAppsEmptyMethodName, E extends MiniAppsEventName>(method: M, event: E | E[], options?: RequestOptionsAdvanced<MiniAppsEventParams<E>>): Promise<MiniAppsEventParams<E>>;
46
+ export declare function request<Method extends MiniAppsNonEmptyMethodName, Event extends MiniAppsEventName>(method: Method, eventOrEvents: Event | Event[], options: RequestSimpleOptions<Method>): Promise<MiniAppsEventParams<Event>>;
47
47
  /**
48
- * Calls specified TWA method and captures one of the specified events. Returns promise
48
+ * Calls specified Mini Apps method and captures one of the specified events. Returns promise
49
49
  * which will be resolved in case, specified event was captured.
50
- * @param method - method to execute
51
- * @param params - method parameters.
52
- * @param event - event or events to listen
53
- * @param options - additional execution options.
50
+ * @param method - method name.
51
+ * @param eventOrEvents - tracked event or events.
52
+ * @param options - method options.
54
53
  */
55
- export declare function request<M extends MiniAppsNonEmptyMethodName, E extends MiniAppsEventName>(method: M, params: MiniAppsMethodParams<M>, event: E | E[], options?: RequestOptionsAdvanced<MiniAppsEventParams<E>>): Promise<MiniAppsEventParams<E>>;
56
- export {};
54
+ export declare function request<Method extends MiniAppsEmptyMethodName, Event extends MiniAppsEventName>(method: Method, eventOrEvents: Event | Event[], options?: RequestSimpleOptions<Method>): Promise<MiniAppsEventParams<Event>>;
@@ -1,20 +1,5 @@
1
- /**
2
- * Returns union keys removing those, which values are not strings.
3
- */
4
- type UnionStringKeys<U> = U extends U ? {
5
- [K in keyof U]-?: U[K] extends string | undefined ? K : never;
6
- }[keyof U] : never;
7
- /**
8
- * Returns union required keys.
9
- */
10
- type UnionRequiredKeys<U> = U extends U ? {
11
- [K in UnionStringKeys<U>]: ({} extends Pick<U, K> ? never : K);
12
- }[UnionStringKeys<U>] : never;
13
- /**
14
- * Returns union optional keys.
15
- */
16
- type UnionOptionalKeys<U> = Exclude<UnionStringKeys<U>, UnionRequiredKeys<U>>;
17
- type MergeClassNames<Tuple extends any[]> = Exclude<Tuple[number], number | string | null | undefined | any[] | boolean> extends infer Union ? {
1
+ import type { UnionOptionalKeys, UnionRequiredKeys } from '../types/unions.js';
2
+ export type MergeClassNames<Tuple extends any[]> = Exclude<Tuple[number], number | string | null | undefined | any[] | boolean> extends infer Union ? {
18
3
  [K in UnionRequiredKeys<Union>]: string;
19
4
  } & {
20
5
  [K in UnionOptionalKeys<Union>]?: string;
@@ -26,4 +11,3 @@ type MergeClassNames<Tuple extends any[]> = Exclude<Tuple[number], number | stri
26
11
  * @see classNames
27
12
  */
28
13
  export declare function mergeClassNames<T extends any[]>(...partials: T): MergeClassNames<T>;
29
- export {};
@@ -1,8 +1,8 @@
1
- import { type PostEvent } from '../bridge/index.js';
2
- import { EventEmitter } from '../event-emitter/index.js';
3
- import { type SupportsFunc } from '../supports/index.js';
4
- import type { Version } from '../version/index.js';
5
1
  import type { BackButtonEvents } from './types.js';
2
+ import type { PostEvent } from '../../bridge/methods/postEvent.js';
3
+ import { EventEmitter } from '../../event-emitter/EventEmitter.js';
4
+ import type { SupportsFunc } from '../../supports/types.js';
5
+ import type { Version } from '../../version/types.js';
6
6
  type Emitter = EventEmitter<BackButtonEvents>;
7
7
  /**
8
8
  * Class which controls the back button displayed in the header of the Mini App in the Telegram
@@ -1,5 +1,5 @@
1
- import type { MiniAppsEventListener } from '../bridge/index.js';
2
- import type { StateEvents } from '../state/index.js';
1
+ import type { MiniAppsEventListener } from '../../bridge/events/events.js';
2
+ import type { StateEvents } from '../../state/types.js';
3
3
  export interface BackButtonState {
4
4
  isVisible: boolean;
5
5
  }
@@ -1,5 +1,7 @@
1
- import { type PostEvent } from '../bridge/index.js';
2
1
  import type { ClosingBehaviorEvents } from './types.js';
2
+ import type { PostEvent } from '../../bridge/methods/postEvent.js';
3
+ import { EventEmitter } from '../../event-emitter/EventEmitter.js';
4
+ type Emitter = EventEmitter<ClosingBehaviorEvents>;
3
5
  /**
4
6
  * Component responsible for controlling current closing confirmation
5
7
  * status.
@@ -28,9 +30,10 @@ export declare class ClosingBehavior {
28
30
  /**
29
31
  * Adds new event listener.
30
32
  */
31
- on: <E extends "change" | "change:isConfirmationNeeded">(event: E, listener: import('../event-emitter/index.js').EventListener<ClosingBehaviorEvents[E]>) => import('../event-emitter/index.js').RemoveEventListener;
33
+ on: Emitter['on'];
32
34
  /**
33
35
  * Removes event listener.
34
36
  */
35
- off: <E extends "change" | "change:isConfirmationNeeded">(event: E, listener: import('../event-emitter/index.js').EventListener<ClosingBehaviorEvents[E]>) => void;
37
+ off: Emitter['off'];
36
38
  }
39
+ export {};
@@ -1,4 +1,4 @@
1
- import type { StateEvents } from '../state/index.js';
1
+ import type { StateEvents } from '../../state/types.js';
2
2
  export interface ClosingBehaviorState {
3
3
  isConfirmationNeeded: boolean;
4
4
  }
@@ -1,7 +1,8 @@
1
- import { postEvent as defaultPostEvent } from '../bridge/index.js';
2
- import { type SupportsFunc } from '../supports/index.js';
3
- import type { CreateRequestIdFunc, ExecuteWithTimeout } from '../types/index.js';
4
- import type { Version } from '../version/index.js';
1
+ import { postEvent as defaultPostEvent } from '../../bridge/methods/postEvent.js';
2
+ import type { SupportsFunc } from '../../supports/types.js';
3
+ import type { ExecuteWithTimeout } from '../../types/methods.js';
4
+ import type { CreateRequestIdFunc } from '../../types/request-id.js';
5
+ import type { Version } from '../../version/types.js';
5
6
  export declare class CloudStorage {
6
7
  private readonly createRequestId;
7
8
  private readonly postEvent;
@@ -1,6 +1,7 @@
1
- import { type ImpactHapticFeedbackStyle, type NotificationHapticFeedbackType, type PostEvent } from '../bridge/index.js';
2
- import { type SupportsFunc } from '../supports/index.js';
3
- import type { Version } from '../version/index.js';
1
+ import type { ImpactHapticFeedbackStyle, NotificationHapticFeedbackType } from '../../bridge/methods/haptic.js';
2
+ import type { PostEvent } from '../../bridge/methods/postEvent.js';
3
+ import type { SupportsFunc } from '../../supports/types.js';
4
+ import type { Version } from '../../version/types.js';
4
5
  /**
5
6
  * Class which controls haptic feedback. It allows calling different types of
6
7
  * haptic notifications which usually occur after user interaction with
@@ -0,0 +1,6 @@
1
+ import type { Chat } from './types.js';
2
+ import type { ValueParser } from '../../parsing/ValueParser.js';
3
+ /**
4
+ * Returns parser used to parse chat data.
5
+ */
6
+ export declare function chatParser(): ValueParser<Chat, false>;
@@ -0,0 +1,6 @@
1
+ import type { InitDataParsed } from './types.js';
2
+ import type { ValueParser } from '../../parsing/ValueParser.js';
3
+ /**
4
+ * Returns parser used to parse init data, presented as search params.
5
+ */
6
+ export declare function initDataParser(): ValueParser<InitDataParsed, false>;
@@ -0,0 +1,6 @@
1
+ import type { User } from './types.js';
2
+ import type { ValueParser } from '../../parsing/ValueParser.js';
3
+ /**
4
+ * Returns parser used to parse user data.
5
+ */
6
+ export declare function userParser(): ValueParser<User, false>;
@@ -1,7 +1,10 @@
1
- import { type InvoiceStatus, type PostEvent } from '../bridge/index.js';
2
- import { type SupportsFunc } from '../supports/index.js';
3
- import type { Version } from '../version/index.js';
4
1
  import type { InvoiceEvents } from './types.js';
2
+ import type { InvoiceStatus } from '../../bridge/events/parsers/invoiceClosed.js';
3
+ import type { PostEvent } from '../../bridge/methods/postEvent.js';
4
+ import { EventEmitter } from '../../event-emitter/EventEmitter.js';
5
+ import type { SupportsFunc } from '../../supports/types.js';
6
+ import type { Version } from '../../version/types.js';
7
+ type Emitter = EventEmitter<InvoiceEvents>;
5
8
  /**
6
9
  * Controls currently displayed invoice.
7
10
  */
@@ -18,11 +21,11 @@ export declare class Invoice {
18
21
  /**
19
22
  * Adds new event listener.
20
23
  */
21
- on: <E extends "change" | "change:isOpened">(event: E, listener: import('../event-emitter/index.js').EventListener<InvoiceEvents[E]>) => import('../event-emitter/index.js').RemoveEventListener;
24
+ on: Emitter['on'];
22
25
  /**
23
26
  * Removes event listener.
24
27
  */
25
- off: <E extends "change" | "change:isOpened">(event: E, listener: import('../event-emitter/index.js').EventListener<InvoiceEvents[E]>) => void;
28
+ off: Emitter['off'];
26
29
  /**
27
30
  * Opens an invoice using its slug.
28
31
  * @param slug - invoice slug.
@@ -41,3 +44,4 @@ export declare class Invoice {
41
44
  */
42
45
  supports: SupportsFunc<'open'>;
43
46
  }
47
+ export {};
@@ -1,4 +1,4 @@
1
- import type { StateEvents } from '../state/index.js';
1
+ import type { StateEvents } from '../../state/types.js';
2
2
  export interface InvoiceState {
3
3
  isOpened: boolean;
4
4
  }
@@ -1,6 +1,6 @@
1
- import { EventEmitter } from '../event-emitter/index.js';
2
- import type { RGB } from '../colors/index.js';
3
1
  import type { MainButtonEvents, MainButtonParams, MainButtonProps } from './types.js';
2
+ import type { RGB } from '../../colors/types.js';
3
+ import { EventEmitter } from '../../event-emitter/EventEmitter.js';
4
4
  type Emitter = EventEmitter<MainButtonEvents>;
5
5
  /**
6
6
  * Controls the main button, which is displayed at the bottom
@@ -1,6 +1,6 @@
1
- import type { PostEvent } from '../bridge/index.js';
2
- import type { RGB } from '../colors/index.js';
3
- import type { StateEvents } from '../state/index.js';
1
+ import type { PostEvent } from '../../bridge/methods/postEvent.js';
2
+ import type { RGB } from '../../colors/types.js';
3
+ import type { StateEvents } from '../../state/types.js';
4
4
  export interface MainButtonParams {
5
5
  backgroundColor?: RGB;
6
6
  isEnabled?: boolean;
@@ -1,8 +1,12 @@
1
- import { type PhoneRequestedStatus, type SwitchInlineQueryChatType, type WriteAccessRequestedStatus } from '../bridge/index.js';
2
- import { type RGB } from '../colors/index.js';
3
- import { type SupportsFunc } from '../supports/index.js';
4
- import type { ExecuteWithTimeout } from '../types/index.js';
5
1
  import type { MiniAppEvents, MiniAppHeaderColor, MiniAppProps, RequestedContact } from './types.js';
2
+ import type { PhoneRequestedStatus } from '../../bridge/events/parsers/phoneRequested.js';
3
+ import type { WriteAccessRequestedStatus } from '../../bridge/events/parsers/writeAccessRequested.js';
4
+ import type { SwitchInlineQueryChatType } from '../../bridge/methods/methods.js';
5
+ import type { RGB } from '../../colors/types.js';
6
+ import { EventEmitter } from '../../event-emitter/EventEmitter.js';
7
+ import type { SupportsFunc } from '../../supports/types.js';
8
+ import type { ExecuteWithTimeout } from '../../types/methods.js';
9
+ type Emitter = EventEmitter<MiniAppEvents>;
6
10
  /**
7
11
  * Provides common Mini Apps functionality not covered by other system components.
8
12
  */
@@ -50,11 +54,11 @@ export declare class MiniApp {
50
54
  /**
51
55
  * Adds new event listener.
52
56
  */
53
- on: <E extends "change" | "change:backgroundColor" | "change:headerColor">(event: E, listener: import('../event-emitter/index.js').EventListener<MiniAppEvents[E]>) => import('../event-emitter/index.js').RemoveEventListener;
57
+ on: Emitter['on'];
54
58
  /**
55
59
  * Removes event listener.
56
60
  */
57
- off: <E extends "change" | "change:backgroundColor" | "change:headerColor">(event: E, listener: import('../event-emitter/index.js').EventListener<MiniAppEvents[E]>) => void;
61
+ off: Emitter['off'];
58
62
  /**
59
63
  * Informs the Telegram app that the Mini App is ready to be displayed.
60
64
  *
@@ -127,3 +131,4 @@ export declare class MiniApp {
127
131
  */
128
132
  switchInlineQuery(text: string, chatTypes?: SwitchInlineQueryChatType[]): void;
129
133
  }
134
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { RequestedContact } from './types.js';
2
+ export declare const contactParser: import("../../parsing/ValueParser.js").ValueParser<RequestedContact, false>;
@@ -1,8 +1,9 @@
1
- import type { HeaderColorKey, PostEvent } from '../bridge/index.js';
2
- import type { RGB } from '../colors/index.js';
3
- import type { StateEvents } from '../state/index.js';
4
- import type { CreateRequestIdFunc } from '../types/index.js';
5
- import type { Version } from '../version/index.js';
1
+ import type { HeaderColorKey } from '../../bridge/methods/methods.js';
2
+ import type { PostEvent } from '../../bridge/methods/postEvent.js';
3
+ import type { RGB } from '../../colors/types.js';
4
+ import type { StateEvents } from '../../state/types.js';
5
+ import type { CreateRequestIdFunc } from '../../types/request-id.js';
6
+ import type { Version } from '../../version/types.js';
6
7
  export interface MiniAppProps {
7
8
  headerColor: MiniAppHeaderColor;
8
9
  backgroundColor: RGB;