@tma.js/sdk 1.5.2 → 2.0.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 (255) hide show
  1. package/dist/dts/bridge/events/event-emitter/createMiniAppsEventEmitter.d.ts +15 -0
  2. package/dist/dts/bridge/events/event-emitter/singleton.d.ts +8 -0
  3. package/dist/dts/bridge/events/event-handlers/cleanupEventHandlers.d.ts +4 -0
  4. package/dist/dts/bridge/events/event-handlers/defineEventHandlers.d.ts +6 -0
  5. package/dist/dts/bridge/events/event-handlers/emitMiniAppsEvent.d.ts +9 -0
  6. package/dist/dts/bridge/events/{off.d.ts → listening/off.d.ts} +3 -2
  7. package/dist/dts/bridge/events/listening/on.d.ts +12 -0
  8. package/dist/dts/bridge/events/listening/subscribe.d.ts +9 -0
  9. package/dist/dts/bridge/events/listening/unsubscribe.d.ts +7 -0
  10. package/dist/dts/bridge/events/types.d.ts +294 -2
  11. package/dist/dts/bridge/methods/createPostEvent.d.ts +7 -4
  12. package/dist/dts/bridge/methods/postEvent.d.ts +24 -15
  13. package/dist/dts/bridge/methods/{custom-methods.d.ts → types/custom-methods.d.ts} +2 -1
  14. package/dist/dts/bridge/methods/types/index.d.ts +4 -0
  15. package/dist/dts/bridge/methods/{methods.d.ts → types/methods.d.ts} +70 -17
  16. package/dist/dts/{globals.d.ts → bridge/target-origin.d.ts} +0 -9
  17. package/dist/dts/bridge/{invokeCustomMethod.d.ts → utils/invokeCustomMethod.d.ts} +7 -2
  18. package/dist/dts/bridge/utils/request.d.ts +35 -0
  19. package/dist/dts/classes/State/State.d.ts +46 -0
  20. package/dist/dts/classes/State/types.d.ts +29 -0
  21. package/dist/dts/classes/WithStateUtils.d.ts +18 -0
  22. package/dist/dts/classes/WithSupports.d.ts +19 -0
  23. package/dist/dts/classes/WithSupportsAndStateUtils.d.ts +24 -0
  24. package/dist/dts/classes/WithSupportsAndTrackableState.d.ts +16 -0
  25. package/dist/dts/classes/WithTrackableState.d.ts +16 -0
  26. package/dist/dts/classnames/mergeClassNames.d.ts +2 -1
  27. package/dist/dts/colors/isRGB.d.ts +2 -1
  28. package/dist/dts/colors/isRGBShort.d.ts +2 -1
  29. package/dist/dts/colors/toRGB.d.ts +2 -1
  30. package/dist/dts/components/BackButton/BackButton.d.ts +41 -0
  31. package/dist/dts/components/BackButton/initBackButton.d.ts +7 -0
  32. package/dist/dts/components/BackButton/types.d.ts +25 -0
  33. package/dist/dts/components/BiometryManager/BiometryManager.d.ts +61 -0
  34. package/dist/dts/components/BiometryManager/formatEvent.d.ts +34 -0
  35. package/dist/dts/components/BiometryManager/initBiometryManager.d.ts +7 -0
  36. package/dist/dts/components/BiometryManager/requestBiometryInfo.d.ts +8 -0
  37. package/dist/dts/components/BiometryManager/types.d.ts +40 -0
  38. package/dist/dts/components/ClosingBehavior/ClosingBehavior.d.ts +26 -0
  39. package/dist/dts/components/ClosingBehavior/initClosingBehavior.d.ts +7 -0
  40. package/dist/dts/components/{closing-behavior → ClosingBehavior}/types.d.ts +14 -1
  41. package/dist/dts/components/{cloud-storage → CloudStorage}/CloudStorage.d.ts +11 -11
  42. package/dist/dts/components/CloudStorage/initCloudStorage.d.ts +7 -0
  43. package/dist/dts/components/{haptic-feedback → HapticFeedback}/HapticFeedback.d.ts +9 -13
  44. package/dist/dts/components/HapticFeedback/initHapticFeedback.d.ts +7 -0
  45. package/dist/dts/components/{init-data → InitData}/InitData.d.ts +4 -2
  46. package/dist/dts/components/InitData/initInitData.d.ts +7 -0
  47. package/dist/dts/components/{init-data → InitData}/parseInitData.d.ts +2 -1
  48. package/dist/dts/components/InitData/parsers/chat.d.ts +3 -0
  49. package/dist/dts/components/InitData/parsers/initData.d.ts +7 -0
  50. package/dist/dts/components/InitData/parsers/user.d.ts +3 -0
  51. package/dist/dts/components/{init-data → InitData}/types.d.ts +2 -3
  52. package/dist/dts/components/Invoice/Invoice.d.ts +31 -0
  53. package/dist/dts/components/Invoice/initInvoice.d.ts +7 -0
  54. package/dist/dts/components/{invoice → Invoice}/types.d.ts +14 -1
  55. package/dist/dts/components/MainButton/MainButton.d.ts +106 -0
  56. package/dist/dts/components/MainButton/initMainButton.d.ts +7 -0
  57. package/dist/dts/components/MainButton/types.d.ts +40 -0
  58. package/dist/dts/components/{mini-app → MiniApp}/MiniApp.d.ts +29 -43
  59. package/dist/dts/components/MiniApp/initMiniApp.d.ts +7 -0
  60. package/dist/dts/components/MiniApp/parsing/contact.d.ts +7 -0
  61. package/dist/dts/components/MiniApp/types.d.ts +53 -0
  62. package/dist/dts/components/Popup/Popup.d.ts +30 -0
  63. package/dist/dts/components/Popup/initPopup.d.ts +7 -0
  64. package/dist/dts/components/{popup → Popup}/preparePopupParams.d.ts +3 -2
  65. package/dist/dts/components/{popup → Popup}/types.d.ts +2 -1
  66. package/dist/dts/components/QRScanner/QRScanner.d.ts +28 -0
  67. package/dist/dts/components/QRScanner/initQRScanner.d.ts +7 -0
  68. package/dist/dts/components/{qr-scanner → QRScanner}/types.d.ts +14 -1
  69. package/dist/dts/components/SettingsButton/SettingsButton.d.ts +37 -0
  70. package/dist/dts/components/SettingsButton/initSettingsButton.d.ts +7 -0
  71. package/dist/dts/components/{settings-button → SettingsButton}/types.d.ts +18 -3
  72. package/dist/dts/components/ThemeParams/ThemeParams.d.ts +53 -0
  73. package/dist/dts/components/ThemeParams/initThemeParams.d.ts +7 -0
  74. package/dist/dts/components/ThemeParams/keys.d.ts +11 -0
  75. package/dist/dts/components/{theme-params → ThemeParams/parsing}/parseThemeParams.d.ts +2 -1
  76. package/dist/dts/components/{theme-params → ThemeParams/parsing}/serializeThemeParams.d.ts +2 -1
  77. package/dist/dts/components/ThemeParams/parsing/themeParams.d.ts +4 -0
  78. package/dist/dts/components/ThemeParams/requestThemeParams.d.ts +8 -0
  79. package/dist/dts/components/ThemeParams/types.d.ts +29 -0
  80. package/dist/dts/components/{utils → Utils}/Utils.d.ts +10 -12
  81. package/dist/dts/components/Utils/initUtils.d.ts +7 -0
  82. package/dist/dts/components/Viewport/Viewport.d.ts +77 -0
  83. package/dist/dts/components/Viewport/initViewport.d.ts +8 -0
  84. package/dist/dts/components/Viewport/initViewportFromRequest.d.ts +10 -0
  85. package/dist/dts/components/{viewport → Viewport}/requestViewport.d.ts +3 -2
  86. package/dist/dts/components/Viewport/types.d.ts +35 -0
  87. package/dist/dts/css-vars/bindMiniAppCSSVars.d.ts +29 -0
  88. package/dist/dts/css-vars/bindThemeParamsCSSVars.d.ts +29 -0
  89. package/dist/dts/css-vars/bindViewportCSSVars.d.ts +32 -0
  90. package/dist/dts/{css → css-vars}/setCSSVar.d.ts +1 -1
  91. package/dist/dts/debug/debug.d.ts +14 -0
  92. package/dist/dts/{bridge/env → env}/hasExternalNotify.d.ts +5 -7
  93. package/dist/dts/{bridge/env → env}/hasWebviewProxy.d.ts +5 -7
  94. package/dist/dts/env/initWeb.d.ts +11 -0
  95. package/dist/dts/env/isSSR.d.ts +4 -0
  96. package/dist/dts/{misc → env}/isTMA.d.ts +1 -1
  97. package/dist/dts/errors/SDKError.d.ts +9 -0
  98. package/dist/dts/errors/createError.d.ts +10 -0
  99. package/dist/dts/errors/errors.d.ts +53 -0
  100. package/dist/dts/errors/isSDKError.d.ts +7 -0
  101. package/dist/dts/errors/isSDKErrorOfType.d.ts +8 -0
  102. package/dist/dts/{event-emitter → events/event-emitter}/EventEmitter.d.ts +20 -30
  103. package/dist/dts/{event-emitter → events/event-emitter}/types.d.ts +10 -9
  104. package/dist/dts/events/onWindow.d.ts +10 -0
  105. package/dist/dts/events/types.d.ts +6 -0
  106. package/dist/dts/index.d.ts +113 -92
  107. package/dist/dts/index.low-level.d.ts +41 -0
  108. package/dist/dts/launch-params/parseLaunchParams.d.ts +2 -1
  109. package/dist/dts/launch-params/retrieveFromLocation.d.ts +2 -1
  110. package/dist/dts/launch-params/retrieveFromPerformance.d.ts +3 -3
  111. package/dist/dts/launch-params/{storage.d.ts → retrieveFromStorage.d.ts} +2 -6
  112. package/dist/dts/launch-params/retrieveFromUrl.d.ts +2 -1
  113. package/dist/dts/launch-params/retrieveLaunchParams.d.ts +2 -1
  114. package/dist/dts/launch-params/saveToStorage.d.ts +7 -0
  115. package/dist/dts/launch-params/serializeLaunchParams.d.ts +2 -1
  116. package/dist/dts/launch-params/types.d.ts +12 -13
  117. package/dist/dts/logger/Logger.d.ts +9 -18
  118. package/dist/dts/misc/createComponentInitFn/createComponentInitFn.d.ts +15 -0
  119. package/dist/dts/misc/createComponentInitFn/types.d.ts +47 -0
  120. package/dist/dts/misc/createSingleton.d.ts +15 -0
  121. package/dist/dts/misc/objectFromKeys.d.ts +6 -0
  122. package/dist/dts/navigation/BasicNavigator/BasicNavigator.d.ts +118 -0
  123. package/dist/dts/navigation/BasicNavigator/prepareItem.d.ts +8 -0
  124. package/dist/dts/navigation/BasicNavigator/types.d.ts +37 -0
  125. package/dist/dts/navigation/BrowserNavigator/BrowserNavigator.d.ts +198 -0
  126. package/dist/dts/navigation/BrowserNavigator/basicItemToBrowser.d.ts +7 -0
  127. package/dist/dts/navigation/BrowserNavigator/createBrowserNavigatorFromLocation.d.ts +4 -0
  128. package/dist/dts/navigation/BrowserNavigator/prepareItem.d.ts +25 -0
  129. package/dist/dts/navigation/BrowserNavigator/types.d.ts +63 -0
  130. package/dist/dts/navigation/createSafeURL.d.ts +7 -0
  131. package/dist/dts/navigation/getHash.d.ts +2 -1
  132. package/dist/dts/navigation/getPathname.d.ts +7 -0
  133. package/dist/dts/navigation/initNavigator.d.ts +9 -0
  134. package/dist/dts/navigation/urlToPath.d.ts +7 -0
  135. package/dist/dts/parsing/ArrayParser/ArrayParser.d.ts +17 -0
  136. package/dist/dts/parsing/ArrayParser/types.d.ts +12 -0
  137. package/dist/dts/parsing/ValueParser/ValueParser.d.ts +17 -0
  138. package/dist/dts/parsing/{ValueParser.d.ts → ValueParser/types.d.ts} +6 -14
  139. package/dist/dts/parsing/createTypeError.d.ts +6 -0
  140. package/dist/dts/parsing/createValueParserGenerator.d.ts +3 -2
  141. package/dist/dts/parsing/parseBySchema.d.ts +2 -1
  142. package/dist/dts/parsing/parsers/array.d.ts +3 -2
  143. package/dist/dts/parsing/parsers/boolean.d.ts +2 -1
  144. package/dist/dts/parsing/parsers/date.d.ts +2 -1
  145. package/dist/dts/parsing/parsers/json.d.ts +3 -2
  146. package/dist/dts/parsing/parsers/number.d.ts +2 -1
  147. package/dist/dts/parsing/parsers/rgb.d.ts +3 -2
  148. package/dist/dts/parsing/parsers/searchParams.d.ts +3 -2
  149. package/dist/dts/parsing/parsers/string.d.ts +2 -1
  150. package/dist/dts/{init/creators → request-id}/createRequestIdGenerator.d.ts +3 -2
  151. package/dist/dts/{types/request-id.d.ts → request-id/types.d.ts} +1 -1
  152. package/dist/dts/storage/storage.d.ts +42 -0
  153. package/dist/dts/supports/createSupportsFn.d.ts +12 -0
  154. package/dist/dts/supports/{createSupportsParamFunc.d.ts → createSupportsParamFn.d.ts} +5 -4
  155. package/dist/dts/supports/supports.d.ts +3 -2
  156. package/dist/dts/supports/types.d.ts +1 -1
  157. package/dist/dts/timeout/createTimeoutError.d.ts +7 -0
  158. package/dist/dts/timeout/sleep.d.ts +1 -1
  159. package/dist/dts/timeout/withTimeout.d.ts +1 -2
  160. package/dist/dts/types/index.d.ts +6 -0
  161. package/dist/dts/types/methods.d.ts +2 -1
  162. package/dist/dts/types/misc.d.ts +12 -0
  163. package/dist/dts/types/utils.d.ts +16 -0
  164. package/dist/dts/version/compareVersions.d.ts +2 -1
  165. package/dist/index.cjs +2 -1
  166. package/dist/index.cjs.map +1 -0
  167. package/dist/index.iife.js +2 -1
  168. package/dist/index.iife.js.map +1 -0
  169. package/dist/index.js +2998 -0
  170. package/dist/index.js.map +1 -0
  171. package/dist/index.low-level.iife.js +2 -0
  172. package/dist/index.low-level.iife.js.map +1 -0
  173. package/package.json +7 -9
  174. package/dist/dts/bridge/errors/MethodUnsupportedError.d.ts +0 -8
  175. package/dist/dts/bridge/errors/ParameterUnsupportedError.d.ts +0 -8
  176. package/dist/dts/bridge/events/createEmitter.d.ts +0 -6
  177. package/dist/dts/bridge/events/events.d.ts +0 -140
  178. package/dist/dts/bridge/events/on.d.ts +0 -9
  179. package/dist/dts/bridge/events/onTelegramEvent.d.ts +0 -7
  180. package/dist/dts/bridge/events/once.d.ts +0 -8
  181. package/dist/dts/bridge/events/parsers/clipboardTextReceived.d.ts +0 -13
  182. package/dist/dts/bridge/events/parsers/customMethodInvoked.d.ts +0 -16
  183. package/dist/dts/bridge/events/parsers/invoiceClosed.d.ts +0 -12
  184. package/dist/dts/bridge/events/parsers/phoneRequested.d.ts +0 -8
  185. package/dist/dts/bridge/events/parsers/popupClosed.d.ts +0 -8
  186. package/dist/dts/bridge/events/parsers/qrTextReceived.d.ts +0 -7
  187. package/dist/dts/bridge/events/parsers/theme-changed.d.ts +0 -42
  188. package/dist/dts/bridge/events/parsers/viewportChanged.d.ts +0 -19
  189. package/dist/dts/bridge/events/parsers/writeAccessRequested.d.ts +0 -8
  190. package/dist/dts/bridge/events/singletonEmitter.d.ts +0 -6
  191. package/dist/dts/bridge/events/subscribe.d.ts +0 -8
  192. package/dist/dts/bridge/events/unsubscribe.d.ts +0 -6
  193. package/dist/dts/bridge/request.d.ts +0 -54
  194. package/dist/dts/components/back-button/BackButton.d.ts +0 -47
  195. package/dist/dts/components/back-button/types.d.ts +0 -10
  196. package/dist/dts/components/closing-behavior/ClosingBehavior.d.ts +0 -39
  197. package/dist/dts/components/init-data/chatParser.d.ts +0 -6
  198. package/dist/dts/components/init-data/initDataParser.d.ts +0 -6
  199. package/dist/dts/components/init-data/userParser.d.ts +0 -6
  200. package/dist/dts/components/invoice/Invoice.d.ts +0 -47
  201. package/dist/dts/components/main-button/MainButton.d.ts +0 -104
  202. package/dist/dts/components/main-button/types.d.ts +0 -20
  203. package/dist/dts/components/mini-app/contactParser.d.ts +0 -2
  204. package/dist/dts/components/mini-app/types.d.ts +0 -32
  205. package/dist/dts/components/popup/Popup.d.ts +0 -48
  206. package/dist/dts/components/qr-scanner/QRScanner.d.ts +0 -44
  207. package/dist/dts/components/settings-button/SettingsButton.d.ts +0 -42
  208. package/dist/dts/components/theme-params/ThemeParams.d.ts +0 -66
  209. package/dist/dts/components/theme-params/keys.d.ts +0 -11
  210. package/dist/dts/components/theme-params/requestThemeParams.d.ts +0 -7
  211. package/dist/dts/components/theme-params/themeParamsParser.d.ts +0 -3
  212. package/dist/dts/components/theme-params/types.d.ts +0 -14
  213. package/dist/dts/components/viewport/Viewport.d.ts +0 -90
  214. package/dist/dts/components/viewport/isStableViewportPlatform.d.ts +0 -7
  215. package/dist/dts/components/viewport/types.d.ts +0 -18
  216. package/dist/dts/components/viewport/utils.d.ts +0 -5
  217. package/dist/dts/css/bindMiniAppCSSVars.d.ts +0 -16
  218. package/dist/dts/css/bindThemeCSSVars.d.ts +0 -12
  219. package/dist/dts/css/bindViewportCSSVars.d.ts +0 -20
  220. package/dist/dts/init/catchCustomStyles.d.ts +0 -4
  221. package/dist/dts/init/creators/createBackButton.d.ts +0 -10
  222. package/dist/dts/init/creators/createClosingBehavior.d.ts +0 -9
  223. package/dist/dts/init/creators/createMainButton.d.ts +0 -12
  224. package/dist/dts/init/creators/createMiniApp.d.ts +0 -16
  225. package/dist/dts/init/creators/createSettingsButton.d.ts +0 -10
  226. package/dist/dts/init/creators/createThemeParams.d.ts +0 -7
  227. package/dist/dts/init/creators/createViewport.d.ts +0 -11
  228. package/dist/dts/init/css/processCSSVarsOption.d.ts +0 -12
  229. package/dist/dts/init/init.d.ts +0 -9
  230. package/dist/dts/init/types.d.ts +0 -85
  231. package/dist/dts/launch-params/launchParamsParser.d.ts +0 -6
  232. package/dist/dts/launch-params/retrieveLaunchData.d.ts +0 -7
  233. package/dist/dts/navigation/HashNavigator/HashNavigator.d.ts +0 -46
  234. package/dist/dts/navigation/HashNavigator/types.d.ts +0 -33
  235. package/dist/dts/navigation/Navigator/Navigator.d.ts +0 -104
  236. package/dist/dts/navigation/Navigator/types.d.ts +0 -44
  237. package/dist/dts/parsing/ArrayValueParser.d.ts +0 -18
  238. package/dist/dts/parsing/ParseError.d.ts +0 -22
  239. package/dist/dts/parsing/ParseSchemaFieldError.d.ts +0 -17
  240. package/dist/dts/parsing/unexpectedTypeError.d.ts +0 -4
  241. package/dist/dts/state/State.d.ts +0 -28
  242. package/dist/dts/state/types.d.ts +0 -27
  243. package/dist/dts/storage.d.ts +0 -50
  244. package/dist/dts/supports/createSupportsFunc.d.ts +0 -10
  245. package/dist/dts/timeout/TimeoutError.d.ts +0 -3
  246. package/dist/dts/timeout/isTimeoutError.d.ts +0 -6
  247. package/dist/index.mjs +0 -2813
  248. /package/dist/dts/bridge/methods/{haptic.d.ts → types/haptic.d.ts} +0 -0
  249. /package/dist/dts/bridge/methods/{popup.d.ts → types/popup.d.ts} +0 -0
  250. /package/dist/dts/bridge/{captureSameReq.d.ts → utils/captureSameReq.d.ts} +0 -0
  251. /package/dist/dts/{misc → env}/isIframe.d.ts +0 -0
  252. /package/dist/dts/navigation/{HashNavigator/drop.d.ts → drop.d.ts} +0 -0
  253. /package/dist/dts/{misc → navigation}/getFirstNavigationEntry.d.ts +0 -0
  254. /package/dist/dts/navigation/{HashNavigator/go.d.ts → go.d.ts} +0 -0
  255. /package/dist/dts/{misc → navigation}/isPageReload.d.ts +0 -0
@@ -0,0 +1,35 @@
1
+ import { ExecuteWithOptions, If, IsNever } from '../../types/index.js';
2
+ import { MiniAppsEventListener, MiniAppsEventName, MiniAppsEventPayload } from '../events/types.js';
3
+ import { MiniAppsMethodName, MiniAppsMethodParams } from '../methods/types/index.js';
4
+
5
+ interface BasicOptions<Method extends MiniAppsMethodName, Event extends MiniAppsEventName> extends ExecuteWithOptions {
6
+ /**
7
+ * Mini Apps method name.
8
+ */
9
+ method: Method;
10
+ /**
11
+ * One or many tracked Mini Apps events.
12
+ */
13
+ event: Event | Event[];
14
+ /**
15
+ * Should return true in case, this event should be captured. If not specified,
16
+ * request will be captured automatically.
17
+ */
18
+ capture?: If<IsNever<MiniAppsEventListener<Event>>, () => boolean, (payload: MiniAppsEventPayload<Event>) => boolean>;
19
+ }
20
+ /**
21
+ * `request` method options.
22
+ */
23
+ export type RequestOptions<Method extends MiniAppsMethodName, Event extends MiniAppsEventName> = BasicOptions<Method, Event> & If<IsNever<MiniAppsMethodParams<Method>>, {}, {
24
+ /**
25
+ * List of method parameters.
26
+ */
27
+ params: MiniAppsMethodParams<Method>;
28
+ }>;
29
+ /**
30
+ * Calls specified Mini Apps method and captures one of the specified events. Returns promise
31
+ * which will be resolved in case, specified event was captured.
32
+ * @param options - method options.
33
+ */
34
+ export declare function request<Method extends MiniAppsMethodName, Event extends MiniAppsEventName>(options: RequestOptions<Method, Event>): Promise<MiniAppsEventPayload<Event>>;
35
+ export {};
@@ -0,0 +1,46 @@
1
+ import { EventEmitter } from '../../events/event-emitter/EventEmitter.js';
2
+ import { StateEvents } from './types.js';
3
+ import { StringKeys } from '../../types/utils.js';
4
+
5
+ type Emitter<State extends object> = EventEmitter<StateEvents<State>>;
6
+ export declare class State<State extends object> {
7
+ /**
8
+ * Initial state.
9
+ */
10
+ private readonly state;
11
+ private readonly ee;
12
+ constructor(
13
+ /**
14
+ * Initial state.
15
+ */
16
+ state: State);
17
+ /**
18
+ * Clones current state and returns its copy.
19
+ */
20
+ clone(): State;
21
+ /**
22
+ * Sets value by key.
23
+ * @param key - state key.
24
+ * @param value - value to set.
25
+ */
26
+ set<K extends StringKeys<State>>(key: K, value: State[K]): void;
27
+ /**
28
+ * Sets several values simultaneously.
29
+ * @param state - partial state.
30
+ */
31
+ set(state: Partial<State>): void;
32
+ /**
33
+ * Returns value by specified key.
34
+ * @param key - state key.
35
+ */
36
+ get<K extends StringKeys<State>>(key: K): State[K];
37
+ /**
38
+ * Adds new event listener.
39
+ */
40
+ on: Emitter<State>['on'];
41
+ /**
42
+ * Removes event listener.
43
+ */
44
+ off: Emitter<State>['off'];
45
+ }
46
+ export {};
@@ -0,0 +1,29 @@
1
+ import { StringKeys } from '../../types/utils.js';
2
+
3
+ /**
4
+ * Creates a map with all events emitted by BaseComponent.
5
+ * @example
6
+ * ```ts
7
+ * type A = StateEvents<{
8
+ * name: string;
9
+ * age: number;
10
+ * isRegistered: boolean;
11
+ * }>;
12
+ *
13
+ * // Will be:
14
+ * {
15
+ * "change:name": (currentValue: string) => void;
16
+ * "change:age": (currentValue: number) => void;
17
+ * "change:isRegistered": (currentValue: boolean) => void;
18
+ * "change": () => void;
19
+ * }
20
+ * ```
21
+ */
22
+ export type StateEvents<State extends object> = {
23
+ [Event in `change:${StringKeys<State>}`]: (currentValue: Event extends `change:${infer T extends StringKeys<State>}` ? State[T] : never) => void;
24
+ } & {
25
+ /**
26
+ * Something has changed in the state.
27
+ */
28
+ change: (currentState: State) => void;
29
+ };
@@ -0,0 +1,18 @@
1
+ import { State } from './State/State.js';
2
+
3
+ export declare class WithStateUtils<Shape extends object> {
4
+ protected state: State<Shape>;
5
+ constructor(shape: Shape);
6
+ /**
7
+ * Gets the state value.
8
+ */
9
+ protected get: State<Shape>['get'];
10
+ /**
11
+ * Sets the state value.
12
+ */
13
+ protected set: State<Shape>['set'];
14
+ /**
15
+ * Clones the current state.
16
+ */
17
+ protected clone: State<Shape>['clone'];
18
+ }
@@ -0,0 +1,19 @@
1
+ import { MiniAppsMethodName } from '../bridge/methods/types/methods.js';
2
+ import { SupportsFn } from '../supports/types.js';
3
+ import { Version } from '../version/types.js';
4
+
5
+ export declare class WithSupports<SupportsMethod extends string> {
6
+ constructor(
7
+ /**
8
+ * Mini Apps version.
9
+ */
10
+ version: Version,
11
+ /**
12
+ * Supports method schema.
13
+ */
14
+ supportsSchema: Record<SupportsMethod, MiniAppsMethodName>);
15
+ /**
16
+ * @returns True, if specified method is supported by the current component.
17
+ */
18
+ supports: SupportsFn<SupportsMethod>;
19
+ }
@@ -0,0 +1,24 @@
1
+ import { WithStateUtils } from './WithStateUtils.js';
2
+ import { MiniAppsMethodName } from '../bridge/methods/types/methods.js';
3
+ import { SupportsFn } from '../supports/types.js';
4
+ import { Version } from '../version/types.js';
5
+
6
+ export declare class WithSupportsAndStateUtils<StateShape extends object, SupportsMethod extends string> extends WithStateUtils<StateShape> {
7
+ constructor(
8
+ /**
9
+ * Initial state.
10
+ */
11
+ stateShape: StateShape,
12
+ /**
13
+ * Mini Apps version.
14
+ */
15
+ version: Version,
16
+ /**
17
+ * Supports method schema.
18
+ */
19
+ supportsSchema: Record<SupportsMethod, MiniAppsMethodName>);
20
+ /**
21
+ * @returns True, if specified method is supported by the current component.
22
+ */
23
+ supports: SupportsFn<SupportsMethod>;
24
+ }
@@ -0,0 +1,16 @@
1
+ import { WithSupportsAndStateUtils } from './WithSupportsAndStateUtils.js';
2
+ import { StateEvents } from './State/types.js';
3
+ import { EventEmitter } from '../events/event-emitter/EventEmitter.js';
4
+
5
+ type Emitter<StateShape extends object> = EventEmitter<StateEvents<StateShape>>;
6
+ export declare class WithSupportsAndTrackableState<StateShape extends object, SupportsMethod extends string> extends WithSupportsAndStateUtils<StateShape, SupportsMethod> {
7
+ /**
8
+ * Adds a new event listener.
9
+ */
10
+ on: Emitter<StateShape>['on'];
11
+ /**
12
+ * Removes the event listener.
13
+ */
14
+ off: Emitter<StateShape>['off'];
15
+ }
16
+ export {};
@@ -0,0 +1,16 @@
1
+ import { WithStateUtils } from './WithStateUtils.js';
2
+ import { StateEvents } from './State/types.js';
3
+ import { EventEmitter } from '../events/event-emitter/EventEmitter.js';
4
+
5
+ type Emitter<StateShape extends object> = EventEmitter<StateEvents<StateShape>>;
6
+ export declare class WithTrackableState<StateShape extends object> extends WithStateUtils<StateShape> {
7
+ /**
8
+ * Adds a new event listener.
9
+ */
10
+ on: Emitter<StateShape>['on'];
11
+ /**
12
+ * Removes the event listener.
13
+ */
14
+ off: Emitter<StateShape>['off'];
15
+ }
16
+ export {};
@@ -1,4 +1,5 @@
1
- import type { UnionOptionalKeys, UnionRequiredKeys } from '../types/unions.js';
1
+ import { UnionOptionalKeys, UnionRequiredKeys } from '../types/unions.js';
2
+
2
3
  export type MergeClassNames<Tuple extends any[]> = Exclude<Tuple[number], number | string | null | undefined | any[] | boolean> extends infer Union ? {
3
4
  [K in UnionRequiredKeys<Union>]: string;
4
5
  } & {
@@ -1,4 +1,5 @@
1
- import type { RGB } from './types.js';
1
+ import { RGB } from './types.js';
2
+
2
3
  /**
3
4
  * Returns true in case, passed value has #RRGGBB format.
4
5
  * @param value - value to check.
@@ -1,4 +1,5 @@
1
- import type { RGBShort } from './types.js';
1
+ import { RGBShort } from './types.js';
2
+
2
3
  /**
3
4
  * Returns true in case, passed value has #RGB format.
4
5
  * @param value - value to check.
@@ -1,4 +1,5 @@
1
- import type { RGB } from './types.js';
1
+ import { RGB } from './types.js';
2
+
2
3
  /**
3
4
  * Converts passed value to #RRGGBB format. Accepts following color formats:
4
5
  * - `#RGB`
@@ -0,0 +1,41 @@
1
+ import { WithSupportsAndStateUtils } from '../../classes/WithSupportsAndStateUtils.js';
2
+ import { PostEvent } from '../../bridge/methods/postEvent.js';
3
+ import { BackButtonEvents, BackButtonState } from './types.js';
4
+ import { EventEmitter } from '../../events/event-emitter/EventEmitter.js';
5
+ import { Version } from '../../version/types.js';
6
+
7
+ type Emitter = EventEmitter<BackButtonEvents>;
8
+ /**
9
+ * @see Usage: https://docs.telegram-mini-apps.com/platform/back-button
10
+ * @see API: https://docs.telegram-mini-apps.com/packages/tma-js-sdk/components/back-button
11
+ */
12
+ export declare class BackButton extends WithSupportsAndStateUtils<BackButtonState, 'show' | 'hide'> {
13
+ private readonly postEvent;
14
+ constructor(isVisible: boolean, version: Version, postEvent: PostEvent);
15
+ private set isVisible(value);
16
+ /**
17
+ * True if BackButton is currently visible.
18
+ */
19
+ get isVisible(): boolean;
20
+ /**
21
+ * Hides the BackButton.
22
+ */
23
+ hide(): void;
24
+ /**
25
+ * Adds a new event listener.
26
+ * @param event - event to listen.
27
+ * @param listener - listener to add.
28
+ */
29
+ on: Emitter['on'];
30
+ /**
31
+ * Removes the event listener.
32
+ * @param event - event to listen.
33
+ * @param listener - listener to remove.
34
+ */
35
+ off: Emitter['off'];
36
+ /**
37
+ * Shows the BackButton.
38
+ */
39
+ show(): void;
40
+ }
41
+ export {};
@@ -0,0 +1,7 @@
1
+ import { BackButton } from './BackButton.js';
2
+
3
+ /**
4
+ * @returns A new initialized instance of the `BackButton` class.
5
+ * @see BackButton
6
+ */
7
+ export declare const initBackButton: import('../../index.js').InitComponentFn<"version", BackButton, import('./types.js').BackButtonState>;
@@ -0,0 +1,25 @@
1
+ import { StateEvents } from '../../classes/State/types.js';
2
+
3
+ /**
4
+ * BackButton internal state.
5
+ */
6
+ export interface BackButtonState {
7
+ isVisible: boolean;
8
+ }
9
+ /**
10
+ * BackButton trackable events.
11
+ */
12
+ export interface BackButtonEvents extends StateEvents<BackButtonState> {
13
+ /**
14
+ * The BackButton was clicked.
15
+ */
16
+ click: () => void;
17
+ }
18
+ /**
19
+ * BackButton event name.
20
+ */
21
+ export type BackButtonEventName = keyof BackButtonEvents;
22
+ /**
23
+ * BackButton event listener.
24
+ */
25
+ export type BackButtonEventListener<E extends BackButtonEventName> = BackButtonEvents[E];
@@ -0,0 +1,61 @@
1
+ import { WithSupportsAndTrackableState } from '../../classes/WithSupportsAndTrackableState.js';
2
+ import { BiometryType } from '../../bridge/events/types.js';
3
+ import { BiometryManagerAuthenticateOptions, BiometryManagerProps, BiometryManagerRequestAccessOptions, BiometryManagerState, BiometryManagerUpdateTokenOptions } from './types.js';
4
+
5
+ export declare class BiometryManager extends WithSupportsAndTrackableState<BiometryManagerState, 'auth' | 'openSettings' | 'requestAccess' | 'updateToken'> {
6
+ private readonly postEvent;
7
+ private authPromise?;
8
+ private accessPromise?;
9
+ constructor({ postEvent, version, ...rest }: BiometryManagerProps);
10
+ /**
11
+ * Shows whether biometry is available.
12
+ */
13
+ get available(): boolean;
14
+ /**
15
+ * Shows whether permission to use biometrics has been granted.
16
+ */
17
+ get accessGranted(): boolean;
18
+ /**
19
+ * Shows whether if permission to use biometrics has been requested.
20
+ */
21
+ get accessRequested(): boolean;
22
+ /**
23
+ * Authenticates the user using biometrics.
24
+ * @param options - method options.
25
+ * @since 7.2
26
+ * @returns Token from the local secure storage, if authentication was successful.
27
+ */
28
+ authenticate({ reason, ...rest }: BiometryManagerAuthenticateOptions): Promise<string | undefined>;
29
+ /**
30
+ * A unique device identifier that can be used to match the token to the device.
31
+ */
32
+ get deviceId(): string;
33
+ /**
34
+ * Opens the biometric access settings for bots. Useful when you need to request biometrics
35
+ * access to users who haven't granted it yet.
36
+ *
37
+ * _Note that this method can be called only in response to user interaction with the Mini App
38
+ * interface (e.g. a click inside the Mini App or on the main button)_.
39
+ * @since 7.2
40
+ */
41
+ openSettings(): void;
42
+ /**
43
+ * Requests permission to use biometrics.
44
+ * @since 7.2
45
+ * @returns Promise with true, if access was granted.
46
+ */
47
+ requestAccess({ reason, ...rest }?: BiometryManagerRequestAccessOptions): Promise<boolean>;
48
+ /**
49
+ * The type of biometrics currently available on the device.
50
+ */
51
+ get biometryType(): BiometryType | undefined;
52
+ /**
53
+ * Shows whether token was saved previously in the local secure storage.
54
+ */
55
+ get tokenSaved(): boolean;
56
+ /**
57
+ * Updates the biometric token in a secure storage on the device.
58
+ * @returns Promise with `true`, if token was updated.
59
+ */
60
+ updateToken({ token, ...rest }?: BiometryManagerUpdateTokenOptions): Promise<boolean>;
61
+ }
@@ -0,0 +1,34 @@
1
+ import { BiometryType, MiniAppsEventPayload } from '../../bridge/events/types.js';
2
+
3
+ export interface FormatBiometryInfoResult {
4
+ /**
5
+ * Shows whether biometry is available.
6
+ */
7
+ available: boolean;
8
+ /**
9
+ * Shows whether permission to use biometrics has been requested.
10
+ */
11
+ accessRequested: boolean;
12
+ /**
13
+ * Shows whether permission to use biometrics has been granted.
14
+ */
15
+ accessGranted: boolean;
16
+ /**
17
+ * A unique device identifier that can be used to match the token to the device.
18
+ */
19
+ deviceId: string;
20
+ /**
21
+ * Show whether local storage contains previously saved token.
22
+ */
23
+ tokenSaved: boolean;
24
+ /**
25
+ * The type of biometrics currently available on the device.
26
+ */
27
+ type: BiometryType;
28
+ }
29
+ /**
30
+ * Converts `biometry_info_received` to some common shape.
31
+ * @param event - event payload.
32
+ * @see biometry_info_received
33
+ */
34
+ export declare function formatEvent(event: MiniAppsEventPayload<'biometry_info_received'>): FormatBiometryInfoResult;
@@ -0,0 +1,7 @@
1
+ import { BiometryManager } from './BiometryManager.js';
2
+
3
+ /**
4
+ * @returns A promise with a new initialized instance of the `BiometryManager` class.
5
+ * @see BiometryManager
6
+ */
7
+ export declare const initBiometryManager: import('../../index.js').InitComponentFn<"version", Promise<BiometryManager>, import('./types.js').BiometryManagerState>;
@@ -0,0 +1,8 @@
1
+ import { ExecuteWithOptions } from '../../types/index.js';
2
+ import { FormatBiometryInfoResult } from './formatEvent.js';
3
+
4
+ /**
5
+ * Requests biometry information.
6
+ * @param options - additional execution options.
7
+ */
8
+ export declare function requestBiometryInfo(options?: ExecuteWithOptions): Promise<FormatBiometryInfoResult>;
@@ -0,0 +1,40 @@
1
+ import { BiometryType } from '../../bridge/events/types.js';
2
+ import { PostEvent } from '../../bridge/methods/postEvent.js';
3
+ import { ExecuteWithTimeout, Maybe } from '../../types/index.js';
4
+ import { Version } from '../../version/types.js';
5
+
6
+ export interface BiometryManagerState {
7
+ accessGranted: boolean;
8
+ accessRequested: boolean;
9
+ available: boolean;
10
+ deviceId: string;
11
+ tokenSaved: boolean;
12
+ token?: string;
13
+ biometryType?: BiometryType;
14
+ }
15
+ export interface BiometryManagerProps extends BiometryManagerState {
16
+ postEvent: PostEvent;
17
+ version: Version;
18
+ }
19
+ export interface BiometryManagerAuthenticateOptions extends ExecuteWithTimeout {
20
+ /**
21
+ * The text to be displayed to a user in the popup describing why you are
22
+ * asking them to authenticate and what action you will be taking based on that
23
+ * authentication, 0-128 characters.
24
+ */
25
+ reason?: Maybe<string>;
26
+ }
27
+ export interface BiometryManagerUpdateTokenOptions extends ExecuteWithTimeout {
28
+ /**
29
+ * Token to save in the local device secure storage. Passing `null`, `undefined` or empty string
30
+ * removes it from the storage.
31
+ */
32
+ token?: Maybe<string>;
33
+ }
34
+ export interface BiometryManagerRequestAccessOptions extends ExecuteWithTimeout {
35
+ /**
36
+ * The text to be displayed to a user in the popup describing why the bot needs access to
37
+ * biometrics, 0-128 characters.
38
+ */
39
+ reason?: Maybe<string>;
40
+ }
@@ -0,0 +1,26 @@
1
+ import { WithTrackableState } from '../../classes/WithTrackableState.js';
2
+ import { PostEvent } from '../../bridge/methods/postEvent.js';
3
+ import { ClosingBehaviorState } from './types.js';
4
+
5
+ /**
6
+ * @see Usage: https://docs.telegram-mini-apps.com/platform/closing-behavior
7
+ * @see API: https://docs.telegram-mini-apps.com/packages/tma-js-sdk/components/closing-behavior
8
+ */
9
+ export declare class ClosingBehavior extends WithTrackableState<ClosingBehaviorState> {
10
+ private readonly postEvent;
11
+ constructor(isConfirmationNeeded: boolean, postEvent: PostEvent);
12
+ private set isConfirmationNeeded(value);
13
+ /**
14
+ * True, if the confirmation dialog should be shown while the user is trying to close
15
+ * the Mini App.
16
+ */
17
+ get isConfirmationNeeded(): boolean;
18
+ /**
19
+ * Disables the confirmation dialog when closing the Mini App.
20
+ */
21
+ disableConfirmation(): void;
22
+ /**
23
+ * Enables the confirmation dialog when closing the Mini App.
24
+ */
25
+ enableConfirmation(): void;
26
+ }
@@ -0,0 +1,7 @@
1
+ import { ClosingBehavior } from './ClosingBehavior.js';
2
+
3
+ /**
4
+ * @returns A new initialized instance of the `ClosingBehavior` class.
5
+ * @see ClosingBehavior
6
+ */
7
+ export declare const initClosingBehavior: import('../../index.js').InitComponentFn<never, ClosingBehavior, import('./types.js').ClosingBehaviorState>;
@@ -1,7 +1,20 @@
1
- import type { StateEvents } from '../../state/types.js';
1
+ import { StateEvents } from '../../classes/State/types.js';
2
+
3
+ /**
4
+ * ClosingBehavior internal state.
5
+ */
2
6
  export interface ClosingBehaviorState {
3
7
  isConfirmationNeeded: boolean;
4
8
  }
9
+ /**
10
+ * ClosingBehavior trackable events.
11
+ */
5
12
  export type ClosingBehaviorEvents = StateEvents<ClosingBehaviorState>;
13
+ /**
14
+ * ClosingBehavior event name.
15
+ */
6
16
  export type ClosingBehaviorEventName = keyof ClosingBehaviorEvents;
17
+ /**
18
+ * ClosingBehavior event listener.
19
+ */
7
20
  export type ClosingBehaviorEventListener<E extends ClosingBehaviorEventName> = ClosingBehaviorEvents[E];
@@ -1,12 +1,16 @@
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';
6
- export declare class CloudStorage {
1
+ import { WithSupports } from '../../classes/WithSupports.js';
2
+ import { PostEvent } from '../../bridge/methods/postEvent.js';
3
+ import { CreateRequestIdFn } from '../../request-id/types.js';
4
+ import { ExecuteWithTimeout } from '../../types/methods.js';
5
+ import { Version } from '../../version/types.js';
6
+
7
+ /**
8
+ * @see API: https://docs.telegram-mini-apps.com/packages/tma-js-sdk/components/cloud-storage
9
+ */
10
+ export declare class CloudStorage extends WithSupports<'delete' | 'get' | 'getKeys' | 'set'> {
7
11
  private readonly createRequestId;
8
12
  private readonly postEvent;
9
- constructor(version: Version, createRequestId: CreateRequestIdFunc, postEvent?: typeof defaultPostEvent);
13
+ constructor(version: Version, createRequestId: CreateRequestIdFn, postEvent: PostEvent);
10
14
  /**
11
15
  * Deletes specified key or keys from the cloud storage.
12
16
  * @param keyOrKeys - key or keys to delete.
@@ -40,8 +44,4 @@ export declare class CloudStorage {
40
44
  * @param options - request execution options.
41
45
  */
42
46
  set(key: string, value: string, options?: ExecuteWithTimeout): Promise<void>;
43
- /**
44
- * Checks if specified method is supported by current component.
45
- */
46
- supports: SupportsFunc<'delete' | 'get' | 'getKeys' | 'set'>;
47
47
  }
@@ -0,0 +1,7 @@
1
+ import { CloudStorage } from './CloudStorage.js';
2
+
3
+ /**
4
+ * @returns A new initialized instance of the `CloudStorage` class.
5
+ * @see CloudStorage
6
+ */
7
+ export declare const initCloudStorage: import('../../index.js').InitComponentFn<"version", CloudStorage, never>;
@@ -1,15 +1,15 @@
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';
1
+ import { WithSupports } from '../../classes/WithSupports.js';
2
+ import { PostEvent } from '../../bridge/methods/postEvent.js';
3
+ import { ImpactHapticFeedbackStyle, NotificationHapticFeedbackType } from '../../bridge/methods/types/haptic.js';
4
+ import { Version } from '../../version/types.js';
5
+
5
6
  /**
6
- * Class which controls haptic feedback. It allows calling different types of
7
- * haptic notifications which usually occur after user interaction with
8
- * application.
7
+ * @see Usage: https://docs.telegram-mini-apps.com/platform/haptic-feedback
8
+ * @see API: https://docs.telegram-mini-apps.com/packages/tma-js-sdk/components/haptic-feedback
9
9
  */
10
- export declare class HapticFeedback {
10
+ export declare class HapticFeedback extends WithSupports<'impactOccurred' | 'notificationOccurred' | 'selectionChanged'> {
11
11
  private readonly postEvent;
12
- constructor(version: Version, postEvent?: PostEvent);
12
+ constructor(version: Version, postEvent: PostEvent);
13
13
  /**
14
14
  * A method tells that an impact occurred. The Telegram app may play the
15
15
  * appropriate haptics based on style value passed.
@@ -31,8 +31,4 @@ export declare class HapticFeedback {
31
31
  * use it only when the selection changes.
32
32
  */
33
33
  selectionChanged(): void;
34
- /**
35
- * Checks if specified method is supported by current component.
36
- */
37
- supports: SupportsFunc<'impactOccurred' | 'notificationOccurred' | 'selectionChanged'>;
38
34
  }
@@ -0,0 +1,7 @@
1
+ import { HapticFeedback } from './HapticFeedback.js';
2
+
3
+ /**
4
+ * @returns A new initialized instance of the `HapticFeedback` class.
5
+ * @see HapticFeedback
6
+ */
7
+ export declare const initHapticFeedback: import('../../index.js').InitComponentFn<"version", HapticFeedback, never>;
@@ -1,6 +1,8 @@
1
- import type { Chat, ChatType, InitDataParsed, User } from './types.js';
1
+ import { Chat, ChatType, InitDataParsed, User } from './types.js';
2
+
2
3
  /**
3
- * Class which is responsible for displaying Mini Apps init data.
4
+ * @see Usage: https://docs.telegram-mini-apps.com/platform/init-data
5
+ * @see API: https://docs.telegram-mini-apps.com/packages/tma-js-sdk/init-data
4
6
  */
5
7
  export declare class InitData {
6
8
  private readonly initData;
@@ -0,0 +1,7 @@
1
+ import { InitData } from './InitData.js';
2
+
3
+ /**
4
+ * @returns A new initialized instance of the `InitData` class or undefined.
5
+ * @see InitData
6
+ */
7
+ export declare const initInitData: import('../../index.js').InitComponentFn<"initData", InitData | undefined, never>;
@@ -1,4 +1,5 @@
1
- import type { InitDataParsed } from './types.js';
1
+ import { InitDataParsed } from './types.js';
2
+
2
3
  /**
3
4
  * Parses incoming value as init data.
4
5
  * @param value - value to parse.