@vbotma/sdk 3.1.8

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 (145) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +64 -0
  3. package/dist/dts/composables/AsyncMountable.d.ts +44 -0
  4. package/dist/dts/composables/Button.d.ts +140 -0
  5. package/dist/dts/composables/Mountable.d.ts +43 -0
  6. package/dist/dts/composables/Stateful.d.ts +35 -0
  7. package/dist/dts/errors.d.ts +51 -0
  8. package/dist/dts/features/BackButton/BackButton.d.ts +96 -0
  9. package/dist/dts/features/BackButton/exports.d.ts +2 -0
  10. package/dist/dts/features/BackButton/instance.d.ts +2 -0
  11. package/dist/dts/features/Biometry/Biometry.d.ts +121 -0
  12. package/dist/dts/features/Biometry/exports.d.ts +3 -0
  13. package/dist/dts/features/Biometry/instance.d.ts +2 -0
  14. package/dist/dts/features/Biometry/types.d.ts +84 -0
  15. package/dist/dts/features/ClosingBehavior/ClosingBehavior.d.ts +51 -0
  16. package/dist/dts/features/ClosingBehavior/exports.d.ts +2 -0
  17. package/dist/dts/features/ClosingBehavior/instance.d.ts +2 -0
  18. package/dist/dts/features/CloudStorage/CloudStorage.d.ts +90 -0
  19. package/dist/dts/features/CloudStorage/exports.d.ts +2 -0
  20. package/dist/dts/features/CloudStorage/instance.d.ts +2 -0
  21. package/dist/dts/features/DeviceStorage/DeviceStorage.d.ts +53 -0
  22. package/dist/dts/features/DeviceStorage/exports.d.ts +2 -0
  23. package/dist/dts/features/DeviceStorage/instance.d.ts +2 -0
  24. package/dist/dts/features/HapticFeedback/HapticFeedback.d.ts +57 -0
  25. package/dist/dts/features/HapticFeedback/exports.d.ts +2 -0
  26. package/dist/dts/features/HapticFeedback/instance.d.ts +2 -0
  27. package/dist/dts/features/InitData/InitData.d.ts +87 -0
  28. package/dist/dts/features/InitData/exports.d.ts +2 -0
  29. package/dist/dts/features/InitData/instance.d.ts +2 -0
  30. package/dist/dts/features/Invoice/Invoice.d.ts +54 -0
  31. package/dist/dts/features/Invoice/exports.d.ts +2 -0
  32. package/dist/dts/features/Invoice/instance.d.ts +2 -0
  33. package/dist/dts/features/LocationManager/LocationManager.d.ts +73 -0
  34. package/dist/dts/features/LocationManager/exports.d.ts +3 -0
  35. package/dist/dts/features/LocationManager/instance.d.ts +2 -0
  36. package/dist/dts/features/LocationManager/types.d.ts +65 -0
  37. package/dist/dts/features/MainButton/MainButton.d.ts +214 -0
  38. package/dist/dts/features/MainButton/exports.d.ts +2 -0
  39. package/dist/dts/features/MainButton/instance.d.ts +2 -0
  40. package/dist/dts/features/MiniApp/MiniApp.d.ts +192 -0
  41. package/dist/dts/features/MiniApp/exports.d.ts +2 -0
  42. package/dist/dts/features/MiniApp/instance.d.ts +2 -0
  43. package/dist/dts/features/Notification/Notification.d.ts +21 -0
  44. package/dist/dts/features/Notification/exports.d.ts +3 -0
  45. package/dist/dts/features/Notification/instance.d.ts +2 -0
  46. package/dist/dts/features/Notification/types.d.ts +19 -0
  47. package/dist/dts/features/Popup/Popup.d.ts +56 -0
  48. package/dist/dts/features/Popup/exports.d.ts +3 -0
  49. package/dist/dts/features/Popup/instance.d.ts +2 -0
  50. package/dist/dts/features/Popup/prepareParams.d.ts +9 -0
  51. package/dist/dts/features/Popup/types.d.ts +54 -0
  52. package/dist/dts/features/QrScanner/QrScanner.d.ts +131 -0
  53. package/dist/dts/features/QrScanner/exports.d.ts +2 -0
  54. package/dist/dts/features/QrScanner/instance.d.ts +2 -0
  55. package/dist/dts/features/Refresh/Refresh.d.ts +39 -0
  56. package/dist/dts/features/Refresh/exports.d.ts +3 -0
  57. package/dist/dts/features/Refresh/instance.d.ts +2 -0
  58. package/dist/dts/features/Refresh/types.d.ts +7 -0
  59. package/dist/dts/features/SecondaryButton/SecondaryButton.d.ts +253 -0
  60. package/dist/dts/features/SecondaryButton/exports.d.ts +2 -0
  61. package/dist/dts/features/SecondaryButton/instance.d.ts +2 -0
  62. package/dist/dts/features/SecureStorage/SecureStorage.d.ts +68 -0
  63. package/dist/dts/features/SecureStorage/exports.d.ts +2 -0
  64. package/dist/dts/features/SecureStorage/instance.d.ts +2 -0
  65. package/dist/dts/features/SettingsButton/SettingsButton.d.ts +96 -0
  66. package/dist/dts/features/SettingsButton/exports.d.ts +2 -0
  67. package/dist/dts/features/SettingsButton/instance.d.ts +2 -0
  68. package/dist/dts/features/StoragePermission/StoragePermission.d.ts +45 -0
  69. package/dist/dts/features/StoragePermission/exports.d.ts +3 -0
  70. package/dist/dts/features/StoragePermission/instance.d.ts +2 -0
  71. package/dist/dts/features/StoragePermission/types.d.ts +51 -0
  72. package/dist/dts/features/SwipeBehavior/SwipeBehavior.d.ts +62 -0
  73. package/dist/dts/features/SwipeBehavior/exports.d.ts +2 -0
  74. package/dist/dts/features/SwipeBehavior/instance.d.ts +2 -0
  75. package/dist/dts/features/ThemeParams/ThemeParams.d.ts +127 -0
  76. package/dist/dts/features/ThemeParams/exports.d.ts +2 -0
  77. package/dist/dts/features/ThemeParams/instance.d.ts +2 -0
  78. package/dist/dts/features/Viewport/Viewport.d.ts +219 -0
  79. package/dist/dts/features/Viewport/exports.d.ts +2 -0
  80. package/dist/dts/features/Viewport/instance.d.ts +2 -0
  81. package/dist/dts/features/emoji-status/exports.d.ts +2 -0
  82. package/dist/dts/features/emoji-status/requestEmojiStatusAccess.d.ts +16 -0
  83. package/dist/dts/features/emoji-status/setEmojiStatus.d.ts +28 -0
  84. package/dist/dts/features/home-screen/addToHomeScreen.d.ts +11 -0
  85. package/dist/dts/features/home-screen/checkHomeScreenStatus.d.ts +14 -0
  86. package/dist/dts/features/home-screen/exports.d.ts +2 -0
  87. package/dist/dts/features/links/exports.d.ts +3 -0
  88. package/dist/dts/features/links/openLink.d.ts +31 -0
  89. package/dist/dts/features/links/openTelegramLink.d.ts +18 -0
  90. package/dist/dts/features/links/shareURL.d.ts +18 -0
  91. package/dist/dts/features/privacy/exports.d.ts +3 -0
  92. package/dist/dts/features/privacy/requestContact.d.ts +59 -0
  93. package/dist/dts/features/privacy/requestPhoneAccess.d.ts +19 -0
  94. package/dist/dts/features/privacy/requestWriteAccess.d.ts +14 -0
  95. package/dist/dts/features/uncategorized/copyTextToClipboard.d.ts +5 -0
  96. package/dist/dts/features/uncategorized/downloadFile.d.ts +21 -0
  97. package/dist/dts/features/uncategorized/exports.d.ts +11 -0
  98. package/dist/dts/features/uncategorized/getCurrentTime.d.ts +15 -0
  99. package/dist/dts/features/uncategorized/hideKeyboard.d.ts +13 -0
  100. package/dist/dts/features/uncategorized/readTextFromClipboard.d.ts +13 -0
  101. package/dist/dts/features/uncategorized/retrieveAndroidDeviceData.d.ts +6 -0
  102. package/dist/dts/features/uncategorized/retrieveAndroidDeviceDataFrom.d.ts +14 -0
  103. package/dist/dts/features/uncategorized/sendData.d.ts +20 -0
  104. package/dist/dts/features/uncategorized/shareMessage.d.ts +14 -0
  105. package/dist/dts/features/uncategorized/shareStory.d.ts +50 -0
  106. package/dist/dts/features/uncategorized/switchInlineQuery.d.ts +28 -0
  107. package/dist/dts/fn-options/bottomButtonOptions.d.ts +11 -0
  108. package/dist/dts/fn-options/buttonOptions.d.ts +10 -0
  109. package/dist/dts/fn-options/createFnOption.d.ts +2 -0
  110. package/dist/dts/fn-options/sharedFeatureOptions.d.ts +8 -0
  111. package/dist/dts/fn-options/withCreateRequestId.d.ts +7 -0
  112. package/dist/dts/fn-options/withInvokeCustomMethod.d.ts +11 -0
  113. package/dist/dts/fn-options/withPostEvent.d.ts +8 -0
  114. package/dist/dts/fn-options/withRequest.d.ts +8 -0
  115. package/dist/dts/fn-options/withStateRestore.d.ts +13 -0
  116. package/dist/dts/fn-options/withVersion.d.ts +9 -0
  117. package/dist/dts/globals/createRequestId.d.ts +4 -0
  118. package/dist/dts/globals/invokeCustomMethod.d.ts +16 -0
  119. package/dist/dts/globals/isInlineMode.d.ts +4 -0
  120. package/dist/dts/globals/postEvent.d.ts +4 -0
  121. package/dist/dts/globals/request.d.ts +13 -0
  122. package/dist/dts/globals/resetGlobals.d.ts +4 -0
  123. package/dist/dts/globals/signals-registry.d.ts +39 -0
  124. package/dist/dts/globals/themeParams.d.ts +4 -0
  125. package/dist/dts/globals/version.d.ts +4 -0
  126. package/dist/dts/helpers/access.d.ts +2 -0
  127. package/dist/dts/helpers/component-storage.d.ts +9 -0
  128. package/dist/dts/helpers/createIsSupportedSignal.d.ts +5 -0
  129. package/dist/dts/helpers/css-vars.d.ts +11 -0
  130. package/dist/dts/helpers/isColorDark.d.ts +11 -0
  131. package/dist/dts/helpers/navigation.d.ts +5 -0
  132. package/dist/dts/helpers/removeUndefined.d.ts +10 -0
  133. package/dist/dts/helpers/shallowEqual.d.ts +1 -0
  134. package/dist/dts/index.d.ts +38 -0
  135. package/dist/dts/init.d.ts +42 -0
  136. package/dist/dts/types.d.ts +6 -0
  137. package/dist/dts/with-checks/throwifyWithChecksFp.d.ts +3 -0
  138. package/dist/dts/with-checks/withChecksFp.d.ts +170 -0
  139. package/dist/index.cjs +2 -0
  140. package/dist/index.cjs.map +1 -0
  141. package/dist/index.iife.js +4 -0
  142. package/dist/index.iife.js.map +1 -0
  143. package/dist/index.js +4088 -0
  144. package/dist/index.js.map +1 -0
  145. package/package.json +54 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Vladislav Kibenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # @vbotma/sdk
2
+
3
+ [code-badge]: https://img.shields.io/badge/source-black?logo=github
4
+
5
+ [docs-badge]: https://img.shields.io/badge/documentation-blue?logo=gitbook&logoColor=white
6
+
7
+ [link]: https://github.com/Telegram-Mini-Apps/tma.js/tree/master/tma.js/sdk
8
+
9
+ [docs-link]: https://docs.vbot-mini-apps.com/packages/tma-js-sdk
10
+
11
+ [npm-link]: https://npmjs.com/package/@vbotma/sdk
12
+
13
+ [npm-badge]: https://img.shields.io/npm/v/@vbotma/sdk?logo=npm
14
+
15
+ [size-badge]: https://img.shields.io/bundlephobia/minzip/@vbotma/sdk
16
+
17
+ [![NPM][npm-badge]][npm-link]
18
+ ![Size][size-badge]
19
+ [![docs-badge]][docs-link]
20
+ [![code-badge]][link]
21
+
22
+ Made from scratch TypeScript library for seamless communication with VBot Mini Apps
23
+ functionality.
24
+
25
+ The code of this library is designed to simplify the process of developers interacting with Telegram
26
+ Mini Apps. It consists of several individual components, each responsible for a specific aspect of
27
+ the VBot Mini Apps ecosystem.
28
+
29
+ Before you begin using the SDK, we highly recommend familiarizing yourself with the Telegram Mini
30
+ Apps [documentation](https://docs.vbot-mini-apps.com/platform/about)
31
+ to grasp the fundamental concepts of the platform.
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ # pnpm
37
+ pnpm i @vbotma/sdk
38
+
39
+ # yarn
40
+ yarn add @vbotma/sdk
41
+
42
+ # npm
43
+ npm i @vbotma/sdk
44
+ ```
45
+
46
+ ## Usage Example
47
+
48
+ ```typescript
49
+ import { init, backButton } from '@vbotma/sdk';
50
+
51
+ // Initialize all library dependencies.
52
+ init();
53
+
54
+ // Mount all required components used across the application.
55
+ // This will lead to components' state restoration.
56
+ backButton.mount();
57
+ backButton.onClick(() => {
58
+ window.history.back();
59
+ });
60
+ ```
61
+
62
+ ## Documentation
63
+
64
+ You can find complete documentation over the library [here](https://docs.vbot-mini-apps.com/packages/tma-js-sdk).
@@ -0,0 +1,44 @@
1
+ import { taskEither as TE } from 'fp-ts';
2
+ import { AsyncOptions, MaybeAccessor } from '../types.js';
3
+ export interface AsyncMountableOptions<S, E> {
4
+ /**
5
+ * A function to retrieve the initial state.
6
+ * @param options - additional options.
7
+ */
8
+ initialState: (options?: AsyncOptions) => TE.TaskEither<E, S>;
9
+ /**
10
+ * @returns True if the current page was reloaded.
11
+ */
12
+ isPageReload: MaybeAccessor<boolean>;
13
+ /**
14
+ * A function to call whenever the component was mounted.
15
+ * @param state - restored state.
16
+ */
17
+ onMounted?: (state: S) => void;
18
+ /**
19
+ * A function to call whenever the component was unmounted.
20
+ */
21
+ onUnmounted?: VoidFunction;
22
+ /**
23
+ * Attempts to restore previously saved component state. This function
24
+ * will only be called if the current page was reloaded.
25
+ */
26
+ restoreState: () => (S | undefined);
27
+ }
28
+ export declare class AsyncMountable<S extends object, E> {
29
+ constructor({ initialState, onMounted, restoreState, onUnmounted, isPageReload, }: AsyncMountableOptions<S, E>);
30
+ private readonly _isMounted;
31
+ /**
32
+ * Signal indicating if the component is mounted.
33
+ */
34
+ readonly isMounted: import('@vbotma/signals').Computed<boolean>;
35
+ /**
36
+ * Mounts the component restoring its state and calling required side effects.
37
+ * @param options - additional execution options.
38
+ */
39
+ readonly mount: (options?: AsyncOptions) => TE.TaskEither<E, void>;
40
+ /**
41
+ * Unmounts the component.
42
+ */
43
+ readonly unmount: () => void;
44
+ }
@@ -0,0 +1,140 @@
1
+ import { PostEventError, MethodName, MethodParams } from '@vbotma/bridge';
2
+ import { Computed } from '@vbotma/signals';
3
+ import { either as E } from 'fp-ts';
4
+ import { SharedFeatureOptions } from '../fn-options/sharedFeatureOptions.js';
5
+ import { WithPostEvent } from '../fn-options/withPostEvent.js';
6
+ import { WithStateRestore } from '../fn-options/withStateRestore.js';
7
+ import { WithVersion } from '../fn-options/withVersion.js';
8
+ import { WithChecksFp, WithChecks } from '../with-checks/withChecksFp.js';
9
+ type ButtonEither = E.Either<PostEventError, void>;
10
+ type BoolFields<S> = {
11
+ [K in keyof S]-?: S[K] extends boolean ? K : never;
12
+ }[keyof S];
13
+ export interface ButtonOptions<S, M extends MethodName> extends SharedFeatureOptions, WithStateRestore<S>, WithPostEvent, WithVersion {
14
+ /**
15
+ * The initial button state.
16
+ */
17
+ initialState: S;
18
+ /**
19
+ * Removes a component click listener.
20
+ * @param listener - a listener to remove.
21
+ * @param once - should the listener be called only once.
22
+ */
23
+ offClick: (listener: VoidFunction, once?: boolean) => void;
24
+ /**
25
+ * Adds a component click listener.
26
+ * @returns A function to remove listener.
27
+ * @param listener - a listener to add.
28
+ * @param once - should the listener be called only once.
29
+ */
30
+ onClick: (listener: VoidFunction, once?: boolean) => VoidFunction;
31
+ /**
32
+ * A Mini Apps method to commit changes.
33
+ */
34
+ method: M;
35
+ /**
36
+ * A function to create method payload.
37
+ * @param state
38
+ */
39
+ payload: (state: S) => MethodParams<M>;
40
+ }
41
+ export declare class Button<S extends object, M extends MethodName> {
42
+ constructor({ isTma, storage, onClick, offClick, initialState, isPageReload, postEvent, payload, method, version, }: ButtonOptions<S, M>);
43
+ /**
44
+ * Signal indicating if the component is currently mounted.
45
+ */
46
+ readonly isMounted: Computed<boolean>;
47
+ /**
48
+ * Signal indicating if the component is supported.
49
+ */
50
+ readonly isSupported: Computed<boolean>;
51
+ /**
52
+ * Complete button state.
53
+ */
54
+ readonly state: Computed<S>;
55
+ /**
56
+ * @returns A computed based on the specified state and its related key.
57
+ * @param key - a key to use.
58
+ */
59
+ stateGetter<K extends keyof S>(key: K): Computed<S[K]>;
60
+ /**
61
+ * @returns A setter with checks for the specified key.
62
+ * @param key
63
+ */
64
+ readonly stateSetters: <K extends keyof S>(key: K) => [
65
+ throwing: WithChecks<(value: S[K]) => void, true>,
66
+ fp: WithChecksFp<(value: S[K]) => ButtonEither, true>
67
+ ];
68
+ /**
69
+ * @returns Setters with checks to set a specified boolean key.
70
+ * @param key
71
+ */
72
+ readonly stateBoolSetters: <K extends BoolFields<S>>(key: K) => [
73
+ setFalse: [
74
+ throwing: WithChecks<() => void, true>,
75
+ fp: WithChecksFp<() => ButtonEither, true>
76
+ ],
77
+ setTrue: [
78
+ throwing: WithChecks<() => void, true>,
79
+ fp: WithChecksFp<() => ButtonEither, true>
80
+ ]
81
+ ];
82
+ /**
83
+ * Updates the button state.
84
+ */
85
+ readonly setStateFp: WithChecksFp<(state: Partial<S>) => ButtonEither, true>;
86
+ /**
87
+ * @see setStateFp
88
+ */
89
+ readonly setState: WithChecks<(state: Partial<S>) => void, true>;
90
+ /**
91
+ * Adds a new button listener.
92
+ * @param listener - event listener.
93
+ * @param once - should the listener be called only once.
94
+ * @returns A function to remove bound listener.
95
+ * @example
96
+ * const off = button.onClick(() => {
97
+ * console.log('User clicked the button');
98
+ * off();
99
+ * });
100
+ */
101
+ readonly onClickFp: WithChecksFp<(listener: VoidFunction, once?: boolean) => VoidFunction, true>;
102
+ /**
103
+ * @see onClickFp
104
+ */
105
+ readonly onClick: WithChecks<(listener: VoidFunction, once?: boolean) => VoidFunction, true>;
106
+ /**
107
+ * Removes the button click listener.
108
+ * @param listener - event listener.
109
+ * @param once - should the listener be called only once.
110
+ * @example
111
+ * function listener() {
112
+ * console.log('User clicked the button');
113
+ * button.offClick(listener);
114
+ * }
115
+ * button.onClick(listener);
116
+ */
117
+ readonly offClickFp: WithChecksFp<(listener: VoidFunction, once?: boolean) => void, true>;
118
+ /**
119
+ * @see offClickFp
120
+ */
121
+ readonly offClick: WithChecks<(listener: VoidFunction, once?: boolean) => void, true>;
122
+ /**
123
+ * Mounts the component restoring its state.
124
+ * @since Mini Apps v6.1
125
+ */
126
+ readonly mountFp: WithChecksFp<() => void, true>;
127
+ /**
128
+ * @see mountFp
129
+ */
130
+ readonly mount: WithChecks<() => void, true>;
131
+ /**
132
+ * Unmounts the component.
133
+ *
134
+ * Note that this function does not remove listeners added via the `onClick`
135
+ * function, so you have to remove them on your own.
136
+ * @see onClick
137
+ */
138
+ readonly unmount: () => void;
139
+ }
140
+ export {};
@@ -0,0 +1,43 @@
1
+ import { either as E } from 'fp-ts';
2
+ import { MaybeAccessor } from '../types.js';
3
+ export interface MountableOptions<S, Err> {
4
+ /**
5
+ * A state to use if the `restoreState` function returned falsy value or
6
+ * `isPageReload` returned false.
7
+ */
8
+ initialState: S | (() => E.Either<Err, S>);
9
+ /**
10
+ * @returns True if the current page was reloaded.
11
+ */
12
+ isPageReload: MaybeAccessor<boolean>;
13
+ /**
14
+ * A function to call whenever the component was mounted.
15
+ * @param state - restored state.
16
+ */
17
+ onMounted?: (state: S) => void;
18
+ /**
19
+ * A function to call whenever the component was unmounted.
20
+ */
21
+ onUnmounted?: VoidFunction;
22
+ /**
23
+ * Attempts to restore previously saved component state. This function
24
+ * will only be called if the current page was reloaded.
25
+ */
26
+ restoreState: () => (S | undefined);
27
+ }
28
+ export declare class Mountable<S extends object, Err = never> {
29
+ constructor({ onMounted, restoreState, initialState, onUnmounted, isPageReload, }: MountableOptions<S, Err>);
30
+ private readonly _isMounted;
31
+ /**
32
+ * Signal indicating if the component is mounted.
33
+ */
34
+ readonly isMounted: import('@vbotma/signals').Computed<boolean>;
35
+ /**
36
+ * Mounts the component restoring its state and calling required side effects.
37
+ */
38
+ readonly mount: () => E.Either<Err, void>;
39
+ /**
40
+ * Unmounts the component.
41
+ */
42
+ readonly unmount: () => void;
43
+ }
@@ -0,0 +1,35 @@
1
+ import { Computed, Signal } from '@vbotma/signals';
2
+ export interface StatefulOptions<S> {
3
+ /**
4
+ * The initial state.
5
+ */
6
+ initialState: S;
7
+ /**
8
+ * A function to call whenever the state changes.
9
+ * @param state - updated state.
10
+ */
11
+ onChange: (state: S) => void;
12
+ }
13
+ export declare class Stateful<S extends object> {
14
+ constructor({ initialState, onChange }: StatefulOptions<S>);
15
+ protected readonly _state: Signal<S>;
16
+ /**
17
+ * The current state.
18
+ */
19
+ readonly state: Computed<S>;
20
+ /**
21
+ * Creates a computed signal based on the state.
22
+ * @param key - a state key to use as a source.
23
+ */
24
+ getter<K extends keyof S>(key: K): Computed<S[K]>;
25
+ /**
26
+ * Updates the state.
27
+ * @param state - updates to apply.
28
+ */
29
+ readonly setState: (state: Partial<S>) => void;
30
+ /**
31
+ * @returns True if specified payload will update the state.
32
+ * @param state
33
+ */
34
+ hasDiff(state: Partial<S>): boolean;
35
+ }
@@ -0,0 +1,51 @@
1
+ import { BaseIssue } from 'valibot';
2
+ declare const ValidationError_base: import('error-kid').ErrorClassWithData<[input: unknown, issues: BaseIssue<any>[]], {
3
+ input: unknown;
4
+ issues: BaseIssue<any>[];
5
+ }>;
6
+ export declare class ValidationError extends /* #__PURE__ */ ValidationError_base {
7
+ }
8
+ declare const CSSVarsBoundError_base: import('error-kid').ErrorClass<[]>;
9
+ export declare class CSSVarsBoundError extends /* #__PURE__ */ CSSVarsBoundError_base {
10
+ }
11
+ declare const DeviceStorageMethodError_base: import('error-kid').ErrorClassWithData<[error: string], {
12
+ error: string;
13
+ }>;
14
+ export declare class DeviceStorageMethodError extends /* #__PURE__ */ DeviceStorageMethodError_base {
15
+ }
16
+ declare const SecureStorageMethodError_base: import('error-kid').ErrorClassWithData<[error: string], {
17
+ error: string;
18
+ }>;
19
+ export declare class SecureStorageMethodError extends /* #__PURE__ */ SecureStorageMethodError_base {
20
+ }
21
+ declare const NotAvailableError_base: import('error-kid').ErrorClass<[message: string]>;
22
+ export declare class NotAvailableError extends /* #__PURE__ */ NotAvailableError_base {
23
+ }
24
+ declare const InvalidEnvError_base: import('error-kid').ErrorClass<[message?: string | undefined]>;
25
+ export declare class InvalidEnvError extends /* #__PURE__ */ InvalidEnvError_base {
26
+ }
27
+ declare const FunctionUnavailableError_base: import('error-kid').ErrorClass<[message?: string | undefined]>;
28
+ export declare class FunctionUnavailableError extends /* #__PURE__ */ FunctionUnavailableError_base {
29
+ }
30
+ declare const InvalidArgumentsError_base: import('error-kid').ErrorClass<[message: string, cause?: unknown]>;
31
+ export declare class InvalidArgumentsError extends /* #__PURE__ */ InvalidArgumentsError_base {
32
+ }
33
+ declare const ConcurrentCallError_base: import('error-kid').ErrorClass<[message: string]>;
34
+ export declare class ConcurrentCallError extends /* #__PURE__ */ ConcurrentCallError_base {
35
+ }
36
+ declare const SetEmojiStatusError_base: import('error-kid').ErrorClass<[error: string]>;
37
+ export declare class SetEmojiStatusError extends /* #__PURE__ */ SetEmojiStatusError_base {
38
+ }
39
+ declare const AccessDeniedError_base: import('error-kid').ErrorClass<[message: string]>;
40
+ export declare class AccessDeniedError extends /* #__PURE__ */ AccessDeniedError_base {
41
+ }
42
+ declare const FullscreenFailedError_base: import('error-kid').ErrorClass<[message: string]>;
43
+ export declare class FullscreenFailedError extends /* #__PURE__ */ FullscreenFailedError_base {
44
+ }
45
+ declare const ShareMessageError_base: import('error-kid').ErrorClass<[error: string]>;
46
+ export declare class ShareMessageError extends /* #__PURE__ */ ShareMessageError_base {
47
+ }
48
+ declare const UnknownThemeParamsKeyError_base: import('error-kid').ErrorClass<[key: string]>;
49
+ export declare class UnknownThemeParamsKeyError extends /* #__PURE__ */ UnknownThemeParamsKeyError_base {
50
+ }
51
+ export {};
@@ -0,0 +1,96 @@
1
+ import { PostEventError } from '@vbotma/bridge';
2
+ import { Computed } from '@vbotma/signals';
3
+ import { either as E } from 'fp-ts';
4
+ import { ButtonOptions } from '../../composables/Button.js';
5
+ import { WithChecksFp, WithChecks } from '../../with-checks/withChecksFp.js';
6
+ export interface BackButtonState {
7
+ isVisible: boolean;
8
+ }
9
+ export type BackButtonOptions = Omit<ButtonOptions<BackButtonState, 'web_app_setup_back_button'>, 'method' | 'payload' | 'initialState'>;
10
+ /**
11
+ * @since Mini Apps v6.1
12
+ */
13
+ export declare class BackButton {
14
+ constructor(options: BackButtonOptions);
15
+ /**
16
+ * Signal indicating if the component is currently visible.
17
+ */
18
+ readonly isVisible: Computed<boolean>;
19
+ /**
20
+ * Signal indicating if the component is currently mounted.
21
+ */
22
+ readonly isMounted: Computed<boolean>;
23
+ /**
24
+ * Signal indicating if the component is supported.
25
+ */
26
+ readonly isSupported: Computed<boolean>;
27
+ /**
28
+ * Hides the button.
29
+ * @since Mini Apps v6.1
30
+ */
31
+ readonly hideFp: WithChecksFp<() => E.Either<PostEventError, void>, true>;
32
+ /**
33
+ * @see hideFp
34
+ */
35
+ readonly hide: WithChecks<() => void, true>;
36
+ /**
37
+ * Shows the button.
38
+ * @since Mini Apps v6.1
39
+ */
40
+ readonly showFp: WithChecksFp<() => E.Either<PostEventError, void>, true>;
41
+ /**
42
+ * @see showFp
43
+ */
44
+ readonly show: WithChecks<() => void, true>;
45
+ /**
46
+ * Adds a new button listener.
47
+ * @param listener - event listener.
48
+ * @param once - should the listener be called only once.
49
+ * @returns A function to remove bound listener.
50
+ * @since Mini Apps v6.1
51
+ * @example
52
+ * const off = button.onClick(() => {
53
+ * console.log('User clicked the button');
54
+ * off();
55
+ * });
56
+ */
57
+ readonly onClickFp: WithChecksFp<(listener: VoidFunction, once?: boolean) => VoidFunction, true>;
58
+ /**
59
+ * @see onClickFp
60
+ */
61
+ readonly onClick: WithChecks<(listener: VoidFunction, once?: boolean) => VoidFunction, true>;
62
+ /**
63
+ * Removes the button click listener.
64
+ * @param listener - event listener.
65
+ * @param once - should the listener be called only once.
66
+ * @since Mini Apps v6.1
67
+ * @example
68
+ * function listener() {
69
+ * console.log('User clicked the button');
70
+ * button.offClick(listener);
71
+ * }
72
+ * button.onClick(listener);
73
+ */
74
+ readonly offClickFp: WithChecksFp<(listener: VoidFunction, once?: boolean) => void, true>;
75
+ /**
76
+ * @see offClickFp
77
+ */
78
+ readonly offClick: WithChecks<(listener: VoidFunction, once?: boolean) => void, true>;
79
+ /**
80
+ * Mounts the component restoring its state.
81
+ * @since Mini Apps v6.1
82
+ */
83
+ readonly mountFp: WithChecksFp<() => void, true>;
84
+ /**
85
+ * @see mountFp
86
+ */
87
+ readonly mount: WithChecks<() => void, true>;
88
+ /**
89
+ * Unmounts the component.
90
+ *
91
+ * Note that this function does not remove listeners added via the `onClick`
92
+ * function, so you have to remove them on your own.
93
+ * @see onClick
94
+ */
95
+ readonly unmount: () => void;
96
+ }
@@ -0,0 +1,2 @@
1
+ export { BackButton, type BackButtonState, type BackButtonOptions } from './BackButton.js';
2
+ export { backButton } from './instance.js';
@@ -0,0 +1,2 @@
1
+ import { BackButton } from './BackButton.js';
2
+ export declare const backButton: BackButton;
@@ -0,0 +1,121 @@
1
+ import { RequestError, PostEventError, BiometryAuthRequestStatus, BiometryTokenUpdateStatus } from '@vbotma/bridge';
2
+ import { Computed } from '@vbotma/signals';
3
+ import { BetterPromise } from 'better-promises';
4
+ import { either as E, taskEither as TE } from 'fp-ts';
5
+ import { BiometryAuthenticateOptions, BiometryOptions, BiometryRequestAccessOptions, BiometryState, BiometryUpdateTokenOptions } from './types.js';
6
+ import { AsyncOptions } from '../../types.js';
7
+ import { WithChecks, WithChecksFp } from '../../with-checks/withChecksFp.js';
8
+ type BiometryTask<T> = TE.TaskEither<RequestError, T>;
9
+ interface AuthenticateResult {
10
+ /**
11
+ * Authentication status.
12
+ */
13
+ status: BiometryAuthRequestStatus;
14
+ /**
15
+ * Token from the local secure storage saved previously.
16
+ */
17
+ token?: string;
18
+ }
19
+ /**
20
+ * @since Mini Apps v7.2
21
+ */
22
+ export declare class Biometry {
23
+ constructor({ version, request, postEvent, storage, onInfoReceived, offInfoReceived, isTma, isPageReload, }: BiometryOptions);
24
+ /**
25
+ * Signal indicating if biometry is available.
26
+ */
27
+ readonly isAvailable: Computed<boolean>;
28
+ /**
29
+ * Signal indicating if the component is supported.
30
+ */
31
+ readonly isSupported: Computed<boolean>;
32
+ /**
33
+ * Signal indicating if the component is mounted.
34
+ */
35
+ readonly isMounted: Computed<boolean>;
36
+ /**
37
+ * Complete component state.
38
+ */
39
+ readonly state: Computed<BiometryState>;
40
+ /**
41
+ * Attempts to authenticate a user using biometrics and fetch a previously stored secure token.
42
+ * @param options - method options.
43
+ * @since Mini Apps v7.2
44
+ * @returns Token from the local secure storage saved previously or undefined.
45
+ * @example
46
+ * const { status, token } = await biometry.authenticate({
47
+ * reason: 'Authenticate to open wallet',
48
+ * });
49
+ */
50
+ readonly authenticateFp: WithChecksFp<(options?: BiometryAuthenticateOptions) => BiometryTask<{
51
+ /**
52
+ * Authentication status.
53
+ */
54
+ status: BiometryAuthRequestStatus;
55
+ /**
56
+ * Token from the local secure storage saved previously.
57
+ */
58
+ token?: string;
59
+ }>, true>;
60
+ /**
61
+ * @see authenticateFp
62
+ */
63
+ readonly authenticate: WithChecks<(options?: BiometryAuthenticateOptions) => BetterPromise<AuthenticateResult>, true>;
64
+ /**
65
+ * Opens the biometric access settings for bots. Useful when you need to request biometrics
66
+ * access to users who haven't granted it yet.
67
+ *
68
+ * _Note that this method can be called only in response to user interaction with the Mini App
69
+ * interface (e.g. a click inside the Mini App or on the main button)_.
70
+ * @since Mini Apps v7.2
71
+ */
72
+ readonly openSettingsFp: WithChecksFp<() => E.Either<PostEventError, void>, true>;
73
+ /**
74
+ * @see openSettingsFp
75
+ */
76
+ readonly openSettings: WithChecks<() => void, true>;
77
+ /**
78
+ * Requests permission to use biometrics.
79
+ * @since Mini Apps v7.2
80
+ * @returns Promise with true, if access was granted.
81
+ * @example
82
+ * const accessGranted = await biometry.requestAccess({
83
+ * reason: 'Authenticate to open wallet',
84
+ * });
85
+ */
86
+ readonly requestAccessFp: WithChecksFp<(options?: BiometryRequestAccessOptions) => BiometryTask<boolean>, true>;
87
+ /**
88
+ * @see requestAccessFp
89
+ */
90
+ readonly requestAccess: WithChecks<(options?: BiometryRequestAccessOptions) => BetterPromise<boolean>, true>;
91
+ /**
92
+ * Updates the biometric token in a secure storage on the device.
93
+ * @since Mini Apps v7.2
94
+ * @returns Promise with `true`, if token was updated.
95
+ * @example Setting a new token
96
+ * biometry.updateToken({
97
+ * token: 'abcdef',
98
+ * })
99
+ * @example Deleting the token
100
+ * biometry.updateToken();
101
+ */
102
+ readonly updateTokenFp: WithChecksFp<(options?: BiometryUpdateTokenOptions) => BiometryTask<BiometryTokenUpdateStatus>, true>;
103
+ /**
104
+ * @see updateTokenFp
105
+ */
106
+ readonly updateToken: WithChecks<(options?: BiometryUpdateTokenOptions) => BetterPromise<BiometryTokenUpdateStatus>, true>;
107
+ /**
108
+ * Mounts the component restoring its state.
109
+ * @since Mini Apps v7.2
110
+ */
111
+ readonly mountFp: WithChecksFp<(options?: AsyncOptions) => BiometryTask<void>, true>;
112
+ /**
113
+ * @see mountFp
114
+ */
115
+ readonly mount: WithChecks<(options?: AsyncOptions) => BetterPromise<void>, true>;
116
+ /**
117
+ * Unmounts the component.
118
+ */
119
+ readonly unmount: () => void;
120
+ }
121
+ export {};
@@ -0,0 +1,3 @@
1
+ export { Biometry } from './Biometry.js';
2
+ export { biometry } from './instance.js';
3
+ export type { BiometryState, BiometryUpdateTokenOptions, BiometryAuthenticateOptions, BiometryRequestAccessOptions, } from './types.js';
@@ -0,0 +1,2 @@
1
+ import { Biometry } from './Biometry.js';
2
+ export declare const biometry: Biometry;