@tma.js/sdk 0.13.2 → 1.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.
- package/dist/dts/{components/BackButton → back-button}/BackButton.d.ts +12 -9
- package/dist/dts/back-button/index.d.ts +2 -0
- package/dist/dts/{components/BackButton → back-button}/types.d.ts +3 -2
- package/dist/dts/bridge/env/hasExternalNotify.d.ts +12 -0
- package/dist/dts/bridge/env/hasWebviewProxy.d.ts +12 -0
- package/dist/dts/bridge/env/index.d.ts +3 -0
- package/dist/dts/bridge/env/isIframe.d.ts +5 -0
- package/dist/dts/bridge/errors/MethodUnsupportedError.d.ts +8 -0
- package/dist/dts/bridge/errors/ParameterUnsupportedError.d.ts +8 -0
- package/dist/dts/bridge/errors/index.d.ts +2 -0
- package/dist/dts/bridge/events/createEmitter.d.ts +6 -0
- package/dist/dts/bridge/events/events.d.ts +130 -0
- package/dist/dts/bridge/events/index.d.ts +9 -0
- package/dist/dts/bridge/events/off.d.ts +7 -0
- package/dist/dts/bridge/events/on.d.ts +10 -0
- package/dist/dts/bridge/events/onTelegramEvent.d.ts +7 -0
- package/dist/dts/bridge/events/once.d.ts +9 -0
- package/dist/dts/bridge/events/parsers/clipboardTextReceived.d.ts +13 -0
- package/dist/dts/bridge/events/parsers/customMethodInvoked.d.ts +16 -0
- package/dist/dts/bridge/events/parsers/index.d.ts +9 -0
- package/dist/dts/bridge/events/parsers/invoiceClosed.d.ts +12 -0
- package/dist/dts/bridge/events/parsers/phoneRequested.d.ts +8 -0
- package/dist/dts/bridge/events/parsers/popupClosed.d.ts +8 -0
- package/dist/dts/bridge/events/parsers/qrTextReceived.d.ts +7 -0
- package/dist/dts/bridge/events/parsers/theme-changed.d.ts +42 -0
- package/dist/dts/bridge/events/parsers/viewportChanged.d.ts +19 -0
- package/dist/dts/bridge/events/parsers/writeAccessRequested.d.ts +8 -0
- package/dist/dts/bridge/events/singletonEmitter.d.ts +6 -0
- package/dist/dts/bridge/events/subscribe.d.ts +9 -0
- package/dist/dts/bridge/events/unsubscribe.d.ts +6 -0
- package/dist/dts/bridge/index.d.ts +5 -0
- package/dist/dts/bridge/methods/createPostEvent.d.ts +10 -0
- package/dist/dts/bridge/methods/haptic.d.ts +40 -0
- package/dist/dts/bridge/methods/index.d.ts +6 -0
- package/dist/dts/bridge/methods/invoke-custom-method.d.ts +24 -0
- package/dist/dts/bridge/methods/methods.d.ts +329 -0
- package/dist/dts/bridge/methods/popup.d.ts +49 -0
- package/dist/dts/bridge/methods/postEvent.d.ts +29 -0
- package/dist/dts/bridge/request.d.ts +65 -0
- package/dist/dts/classnames/classNames.d.ts +10 -0
- package/dist/dts/classnames/index.d.ts +2 -0
- package/dist/dts/classnames/mergeClassNames.d.ts +32 -0
- package/dist/dts/{components/ClosingBehaviour/ClosingBehaviour.d.ts → closing-behavior/ClosingBehavior.d.ts} +5 -4
- package/dist/dts/closing-behavior/index.d.ts +2 -0
- package/dist/dts/closing-behavior/types.d.ts +7 -0
- package/dist/dts/{components/CloudStorage → cloud-storage}/CloudStorage.d.ts +19 -11
- package/dist/dts/colors/index.d.ts +5 -0
- package/dist/dts/colors/isColorDark.d.ts +6 -0
- package/dist/dts/colors/isRGB.d.ts +6 -0
- package/dist/dts/colors/isRGBShort.d.ts +6 -0
- package/dist/dts/colors/toRGB.d.ts +11 -0
- package/dist/dts/colors/types.d.ts +8 -0
- package/dist/dts/event-emitter/EventEmitter.d.ts +64 -0
- package/dist/dts/event-emitter/index.d.ts +2 -0
- package/dist/dts/event-emitter/types.d.ts +44 -0
- package/dist/dts/globals.d.ts +22 -0
- package/dist/dts/{components/HapticFeedback → haptic-feedback}/HapticFeedback.d.ts +3 -3
- package/dist/dts/index.d.ts +24 -6
- package/dist/dts/init/catchCustomStyles.d.ts +4 -0
- package/dist/dts/init/creators/createBackButton.d.ts +2 -2
- package/dist/dts/init/creators/createClosingBehavior.d.ts +3 -3
- package/dist/dts/init/creators/createMainButton.d.ts +3 -3
- package/dist/dts/init/creators/createMiniApp.d.ts +14 -0
- package/dist/dts/init/creators/createRequestIdGenerator.d.ts +1 -1
- package/dist/dts/init/creators/createThemeParams.d.ts +2 -3
- package/dist/dts/init/creators/createViewport.d.ts +16 -9
- package/dist/dts/init/creators/index.d.ts +1 -1
- package/dist/dts/init/css/bindMiniAppCSSVars.d.ts +16 -0
- package/dist/dts/init/css/bindThemeCSSVars.d.ts +12 -0
- package/dist/dts/init/css/bindViewportCSSVars.d.ts +20 -0
- package/dist/dts/init/css/index.d.ts +1 -0
- package/dist/dts/init/css/processCSSVarsOption.d.ts +12 -0
- package/dist/dts/init/css/setCSSVar.d.ts +6 -0
- package/dist/dts/init/init.d.ts +5 -5
- package/dist/dts/init/types.d.ts +42 -69
- package/dist/dts/init-data/InitData.d.ts +53 -0
- package/dist/dts/init-data/chatParser.d.ts +5 -0
- package/dist/dts/init-data/index.d.ts +6 -0
- package/dist/dts/init-data/initDataParser.d.ts +5 -0
- package/dist/dts/init-data/parseInitData.d.ts +6 -0
- package/dist/dts/init-data/types.d.ts +133 -0
- package/dist/dts/init-data/userParser.d.ts +5 -0
- package/dist/dts/invoice/Invoice.d.ts +43 -0
- package/dist/dts/invoice/index.d.ts +2 -0
- package/dist/dts/invoice/types.d.ts +7 -0
- package/dist/dts/launch-params/computeLaunchData.d.ts +6 -0
- package/dist/dts/launch-params/computePageReload.d.ts +6 -0
- package/dist/dts/launch-params/getFirstNavigationEntry.d.ts +6 -0
- package/dist/dts/launch-params/index.d.ts +12 -0
- package/dist/dts/launch-params/launchParamsParser.d.ts +5 -0
- package/dist/dts/launch-params/parseLaunchParams.d.ts +6 -0
- package/dist/dts/launch-params/retrieveCurrent.d.ts +5 -0
- package/dist/dts/launch-params/retrieveFromLocation.d.ts +6 -0
- package/dist/dts/launch-params/retrieveFromPerformance.d.ts +8 -0
- package/dist/dts/launch-params/retrieveLaunchData.d.ts +6 -0
- package/dist/dts/launch-params/serializeLaunchParams.d.ts +6 -0
- package/dist/dts/launch-params/storage.d.ts +13 -0
- package/dist/dts/launch-params/types.d.ts +48 -0
- package/dist/dts/logger/Logger.d.ts +38 -0
- package/dist/dts/logger/index.d.ts +1 -0
- package/dist/dts/main-button/MainButton.d.ts +104 -0
- package/dist/dts/main-button/index.d.ts +2 -0
- package/dist/dts/main-button/types.d.ts +20 -0
- package/dist/dts/mini-app/MiniApp.d.ts +99 -0
- package/dist/dts/mini-app/index.d.ts +2 -0
- package/dist/dts/mini-app/types.d.ts +19 -0
- package/dist/dts/misc/index.d.ts +2 -0
- package/dist/dts/misc/isRecord.d.ts +5 -0
- package/dist/dts/misc/isTMA.d.ts +4 -0
- package/dist/dts/navigation/HashNavigator/HashNavigator.d.ts +43 -0
- package/dist/dts/navigation/HashNavigator/drop.d.ts +4 -0
- package/dist/dts/navigation/HashNavigator/go.d.ts +5 -0
- package/dist/dts/navigation/HashNavigator/index.d.ts +2 -0
- package/dist/dts/navigation/HashNavigator/types.d.ts +34 -0
- package/dist/dts/navigation/Navigator/Navigator.d.ts +104 -0
- package/dist/dts/navigation/Navigator/index.d.ts +2 -0
- package/dist/dts/navigation/Navigator/types.d.ts +44 -0
- package/dist/dts/navigation/ensurePrefix.d.ts +7 -0
- package/dist/dts/navigation/getHash.d.ts +14 -0
- package/dist/dts/navigation/index.d.ts +4 -0
- package/dist/dts/parsing/ArrayValueParser.d.ts +18 -0
- package/dist/dts/parsing/ParseError.d.ts +22 -0
- package/dist/dts/parsing/ParseSchemaFieldError.d.ts +17 -0
- package/dist/dts/parsing/ValueParser.d.ts +36 -0
- package/dist/dts/parsing/createValueParserGenerator.d.ts +9 -0
- package/dist/dts/parsing/index.d.ts +10 -0
- package/dist/dts/parsing/parseBySchema.d.ts +8 -0
- package/dist/dts/parsing/parsers/array.d.ts +6 -0
- package/dist/dts/parsing/parsers/boolean.d.ts +4 -0
- package/dist/dts/parsing/parsers/date.d.ts +4 -0
- package/dist/dts/parsing/parsers/index.d.ts +8 -0
- package/dist/dts/parsing/parsers/json.d.ts +8 -0
- package/dist/dts/parsing/parsers/number.d.ts +4 -0
- package/dist/dts/parsing/parsers/rgb.d.ts +4 -0
- package/dist/dts/parsing/parsers/searchParams.d.ts +8 -0
- package/dist/dts/parsing/parsers/string.d.ts +4 -0
- package/dist/dts/parsing/toRecord.d.ts +7 -0
- package/dist/dts/parsing/types.d.ts +30 -0
- package/dist/dts/parsing/unexpectedTypeError.d.ts +4 -0
- package/dist/dts/{components/Popup → popup}/Popup.d.ts +10 -9
- package/dist/dts/popup/index.d.ts +2 -0
- package/dist/dts/popup/preparePopupParams.d.ts +7 -0
- package/dist/dts/{components/Popup → popup}/types.d.ts +4 -4
- package/dist/dts/{components/QRScanner → qr-scanner}/QRScanner.d.ts +6 -5
- package/dist/dts/qr-scanner/index.d.ts +2 -0
- package/dist/dts/{components/QRScanner → qr-scanner}/types.d.ts +1 -1
- package/dist/dts/state/State.d.ts +19 -6
- package/dist/dts/state/types.d.ts +4 -7
- package/dist/dts/storage.d.ts +4 -4
- package/dist/dts/supports/createSupportsFunc.d.ts +10 -0
- package/dist/dts/supports/createSupportsParamFunc.d.ts +15 -0
- package/dist/dts/supports/index.d.ts +4 -0
- package/dist/dts/supports/supports.d.ts +15 -0
- package/dist/dts/supports/types.d.ts +1 -0
- package/dist/dts/theme-params/ThemeParams.d.ts +62 -0
- package/dist/dts/theme-params/index.d.ts +6 -0
- package/dist/dts/theme-params/keys.d.ts +11 -0
- package/dist/dts/theme-params/parseThemeParams.d.ts +6 -0
- package/dist/dts/theme-params/requestThemeParams.d.ts +7 -0
- package/dist/dts/theme-params/serializeThemeParams.d.ts +5 -0
- package/dist/dts/theme-params/themeParamsParser.d.ts +2 -0
- package/dist/dts/theme-params/types.d.ts +14 -0
- package/dist/dts/timeout/TimeoutError.d.ts +3 -0
- package/dist/dts/timeout/index.d.ts +3 -0
- package/dist/dts/timeout/isTimeoutError.d.ts +6 -0
- package/dist/dts/timeout/withTimeout.d.ts +14 -0
- package/dist/dts/types/index.d.ts +3 -0
- package/dist/dts/types/platform.d.ts +4 -0
- package/dist/dts/types/request-id.d.ts +9 -0
- package/dist/dts/types/utils.d.ts +36 -0
- package/dist/dts/utils/Utils.d.ts +45 -0
- package/dist/dts/utils/index.d.ts +1 -0
- package/dist/dts/version/compareVersions.d.ts +8 -0
- package/dist/dts/version/index.d.ts +2 -0
- package/dist/dts/version/types.d.ts +4 -0
- package/dist/dts/{components/Viewport → viewport}/Viewport.d.ts +16 -38
- package/dist/dts/viewport/index.d.ts +3 -0
- package/dist/dts/viewport/requestViewport.d.ts +12 -0
- package/dist/dts/{components/Viewport → viewport}/types.d.ts +9 -1
- package/dist/dts/viewport/utils.d.ts +5 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.iife.js +1 -1
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +2249 -1036
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -16
- package/src/{components/BackButton → back-button}/BackButton.ts +23 -21
- package/src/back-button/index.ts +2 -0
- package/src/{components/BackButton → back-button}/types.ts +3 -2
- package/src/bridge/env/hasExternalNotify.ts +19 -0
- package/src/bridge/env/hasWebviewProxy.ts +19 -0
- package/src/bridge/env/index.ts +3 -0
- package/src/bridge/env/isIframe.ts +11 -0
- package/src/bridge/errors/MethodUnsupportedError.ts +13 -0
- package/src/bridge/errors/ParameterUnsupportedError.ts +13 -0
- package/src/bridge/errors/index.ts +2 -0
- package/src/bridge/events/createEmitter.ts +108 -0
- package/src/bridge/events/events.ts +170 -0
- package/src/bridge/events/index.ts +9 -0
- package/src/bridge/events/off.ts +14 -0
- package/src/bridge/events/on.ts +19 -0
- package/src/bridge/events/onTelegramEvent.ts +83 -0
- package/src/bridge/events/once.ts +18 -0
- package/src/bridge/events/parsers/clipboardTextReceived.ts +26 -0
- package/src/bridge/events/parsers/customMethodInvoked.ts +25 -0
- package/src/bridge/events/parsers/index.ts +9 -0
- package/src/bridge/events/parsers/invoiceClosed.ts +26 -0
- package/src/bridge/events/parsers/phoneRequested.ts +14 -0
- package/src/bridge/events/parsers/popupClosed.ts +19 -0
- package/src/bridge/events/parsers/qrTextReceived.ts +14 -0
- package/src/bridge/events/parsers/theme-changed.ts +58 -0
- package/src/bridge/events/parsers/viewportChanged.ts +33 -0
- package/src/bridge/events/parsers/writeAccessRequested.ts +14 -0
- package/src/bridge/events/singletonEmitter.ts +19 -0
- package/src/bridge/events/subscribe.ts +15 -0
- package/src/bridge/events/unsubscribe.ts +10 -0
- package/src/bridge/index.ts +5 -0
- package/src/bridge/methods/createPostEvent.ts +40 -0
- package/src/bridge/methods/haptic.ts +52 -0
- package/src/bridge/methods/index.ts +6 -0
- package/src/bridge/methods/invoke-custom-method.ts +25 -0
- package/src/bridge/methods/methods.ts +372 -0
- package/src/bridge/methods/popup.ts +53 -0
- package/src/bridge/methods/postEvent.ts +101 -0
- package/src/bridge/request.ts +185 -0
- package/src/classnames/classNames.ts +34 -0
- package/src/classnames/index.ts +2 -0
- package/src/classnames/mergeClassNames.ts +68 -0
- package/src/{components/ClosingBehaviour/ClosingBehaviour.ts → closing-behavior/ClosingBehavior.ts} +12 -10
- package/src/closing-behavior/index.ts +2 -0
- package/src/closing-behavior/types.ts +12 -0
- package/src/{components/CloudStorage → cloud-storage}/CloudStorage.ts +50 -28
- package/src/colors/index.ts +5 -0
- package/src/colors/isColorDark.ts +22 -0
- package/src/colors/isRGB.ts +9 -0
- package/src/colors/isRGBShort.ts +9 -0
- package/src/colors/toRGB.ts +49 -0
- package/src/colors/types.ts +9 -0
- package/src/event-emitter/EventEmitter.ts +146 -0
- package/src/event-emitter/index.ts +2 -0
- package/src/event-emitter/types.ts +60 -0
- package/src/globals.ts +38 -0
- package/src/{components/HapticFeedback → haptic-feedback}/HapticFeedback.ts +16 -8
- package/src/index.ts +171 -6
- package/src/init/catchCustomStyles.ts +17 -0
- package/src/init/creators/createBackButton.ts +4 -6
- package/src/init/creators/createClosingBehavior.ts +6 -8
- package/src/init/creators/createMainButton.ts +13 -20
- package/src/init/creators/createMiniApp.ts +44 -0
- package/src/init/creators/createRequestIdGenerator.ts +1 -1
- package/src/init/creators/createThemeParams.ts +3 -6
- package/src/init/creators/createViewport.ts +92 -42
- package/src/init/creators/index.ts +1 -1
- package/src/init/css/bindMiniAppCSSVars.ts +48 -0
- package/src/init/css/bindThemeCSSVars.ts +31 -0
- package/src/init/css/bindViewportCSSVars.ts +36 -0
- package/src/init/css/index.ts +1 -0
- package/src/init/css/processCSSVarsOption.ts +57 -0
- package/src/init/css/setCSSVar.ts +8 -0
- package/src/init/init.ts +96 -138
- package/src/init/types.ts +42 -87
- package/src/init-data/InitData.ts +96 -0
- package/src/init-data/chatParser.ts +19 -0
- package/src/init-data/index.ts +6 -0
- package/src/init-data/initDataParser.ts +41 -0
- package/src/init-data/parseInitData.ts +10 -0
- package/src/init-data/types.ts +164 -0
- package/src/init-data/userParser.ts +45 -0
- package/src/invoice/Invoice.ts +123 -0
- package/src/invoice/index.ts +2 -0
- package/src/invoice/types.ts +11 -0
- package/src/launch-params/computeLaunchData.ts +81 -0
- package/src/launch-params/computePageReload.ts +13 -0
- package/src/launch-params/getFirstNavigationEntry.ts +10 -0
- package/src/launch-params/index.ts +12 -0
- package/src/launch-params/launchParamsParser.ts +41 -0
- package/src/launch-params/parseLaunchParams.ts +10 -0
- package/src/launch-params/retrieveCurrent.ts +27 -0
- package/src/launch-params/retrieveFromLocation.ts +10 -0
- package/src/launch-params/retrieveFromPerformance.ts +23 -0
- package/src/launch-params/retrieveLaunchData.ts +30 -0
- package/src/launch-params/serializeLaunchParams.ts +37 -0
- package/src/launch-params/storage.ts +33 -0
- package/src/launch-params/types.ts +57 -0
- package/src/logger/Logger.ts +72 -0
- package/src/logger/index.ts +1 -0
- package/src/main-button/MainButton.ts +239 -0
- package/src/main-button/index.ts +2 -0
- package/src/main-button/types.ts +26 -0
- package/src/mini-app/MiniApp.ts +237 -0
- package/src/mini-app/index.ts +2 -0
- package/src/mini-app/types.ts +25 -0
- package/src/misc/index.ts +2 -0
- package/src/misc/isRecord.ts +7 -0
- package/src/misc/isTMA.ts +13 -0
- package/src/navigation/HashNavigator/HashNavigator.ts +220 -0
- package/src/navigation/HashNavigator/drop.ts +36 -0
- package/src/navigation/HashNavigator/go.ts +28 -0
- package/src/navigation/HashNavigator/index.ts +2 -0
- package/src/navigation/HashNavigator/types.ts +41 -0
- package/src/navigation/Navigator/Navigator.ts +282 -0
- package/src/navigation/Navigator/index.ts +2 -0
- package/src/navigation/Navigator/types.ts +55 -0
- package/src/navigation/ensurePrefix.ts +9 -0
- package/src/navigation/getHash.ts +17 -0
- package/src/navigation/index.ts +4 -0
- package/src/parsing/ArrayValueParser.ts +79 -0
- package/src/parsing/ParseError.ts +27 -0
- package/src/parsing/ParseSchemaFieldError.ts +21 -0
- package/src/parsing/ValueParser.ts +71 -0
- package/src/parsing/createValueParserGenerator.ts +16 -0
- package/src/parsing/index.ts +10 -0
- package/src/parsing/parseBySchema.ts +65 -0
- package/src/parsing/parsers/array.ts +9 -0
- package/src/parsing/parsers/boolean.ts +22 -0
- package/src/parsing/parsers/date.ts +13 -0
- package/src/parsing/parsers/index.ts +8 -0
- package/src/parsing/parsers/json.ts +17 -0
- package/src/parsing/parsers/number.ts +21 -0
- package/src/parsing/parsers/rgb.ts +12 -0
- package/src/parsing/parsers/searchParams.ts +24 -0
- package/src/parsing/parsers/string.ts +12 -0
- package/src/parsing/toRecord.ts +27 -0
- package/src/parsing/types.ts +32 -0
- package/src/parsing/unexpectedTypeError.ts +6 -0
- package/src/{components/Popup → popup}/Popup.ts +38 -28
- package/src/popup/index.ts +2 -0
- package/src/{components/Popup/utils.ts → popup/preparePopupParams.ts} +3 -3
- package/src/{components/Popup → popup}/types.ts +4 -4
- package/src/{components/QRScanner → qr-scanner}/QRScanner.ts +18 -10
- package/src/qr-scanner/index.ts +2 -0
- package/src/{components/QRScanner → qr-scanner}/types.ts +1 -1
- package/src/state/State.ts +30 -16
- package/src/state/types.ts +5 -8
- package/src/storage.ts +6 -4
- package/src/supports/createSupportsFunc.ts +18 -0
- package/src/supports/createSupportsParamFunc.ts +27 -0
- package/src/supports/index.ts +4 -0
- package/src/supports/supports.ts +84 -0
- package/src/supports/types.ts +1 -0
- package/src/theme-params/ThemeParams.ts +131 -0
- package/src/theme-params/index.ts +6 -0
- package/src/theme-params/keys.ts +24 -0
- package/src/theme-params/parseThemeParams.ts +10 -0
- package/src/theme-params/requestThemeParams.ts +13 -0
- package/src/theme-params/serializeThemeParams.ts +20 -0
- package/src/theme-params/themeParamsParser.ts +20 -0
- package/src/theme-params/types.ts +33 -0
- package/src/timeout/TimeoutError.ts +6 -0
- package/src/timeout/index.ts +3 -0
- package/src/timeout/isTimeoutError.ts +9 -0
- package/src/timeout/withTimeout.ts +36 -0
- package/src/types/index.ts +3 -0
- package/src/types/platform.ts +14 -0
- package/src/types/request-id.ts +10 -0
- package/src/types/utils.ts +50 -0
- package/src/utils/Utils.ts +107 -0
- package/src/utils/index.ts +1 -0
- package/src/version/compareVersions.ts +28 -0
- package/src/version/index.ts +2 -0
- package/src/version/types.ts +4 -0
- package/src/{components/Viewport → viewport}/Viewport.ts +72 -98
- package/src/viewport/index.ts +3 -0
- package/src/viewport/requestViewport.ts +23 -0
- package/src/{components/Viewport → viewport}/types.ts +10 -1
- package/src/viewport/utils.ts +7 -0
- package/dist/dts/components/BackButton/index.d.ts +0 -2
- package/dist/dts/components/ClosingBehaviour/index.d.ts +0 -2
- package/dist/dts/components/ClosingBehaviour/types.d.ts +0 -7
- package/dist/dts/components/InitData/InitData.d.ts +0 -60
- package/dist/dts/components/InitData/index.d.ts +0 -1
- package/dist/dts/components/MainButton/MainButton.d.ts +0 -114
- package/dist/dts/components/MainButton/index.d.ts +0 -2
- package/dist/dts/components/MainButton/types.d.ts +0 -15
- package/dist/dts/components/Popup/index.d.ts +0 -2
- package/dist/dts/components/Popup/utils.d.ts +0 -7
- package/dist/dts/components/QRScanner/index.d.ts +0 -2
- package/dist/dts/components/ThemeParams/ThemeParams.d.ts +0 -73
- package/dist/dts/components/ThemeParams/index.d.ts +0 -2
- package/dist/dts/components/ThemeParams/types.d.ts +0 -9
- package/dist/dts/components/Viewport/index.d.ts +0 -2
- package/dist/dts/components/WebApp/WebApp.d.ts +0 -146
- package/dist/dts/components/WebApp/index.d.ts +0 -2
- package/dist/dts/components/WebApp/types.d.ts +0 -11
- package/dist/dts/components/index.d.ts +0 -11
- package/dist/dts/env.d.ts +0 -10
- package/dist/dts/errors/MethodNotSupportedError.d.ts +0 -6
- package/dist/dts/errors/ParameterNotSupportedError.d.ts +0 -6
- package/dist/dts/errors/index.d.ts +0 -2
- package/dist/dts/init/creators/createWebApp.d.ts +0 -16
- package/dist/dts/init/css.d.ts +0 -57
- package/dist/dts/supports.d.ts +0 -22
- package/dist/dts/types.d.ts +0 -10
- package/dist/dts/url.d.ts +0 -7
- package/src/components/BackButton/index.ts +0 -2
- package/src/components/ClosingBehaviour/index.ts +0 -6
- package/src/components/ClosingBehaviour/types.ts +0 -12
- package/src/components/InitData/InitData.ts +0 -139
- package/src/components/InitData/index.ts +0 -1
- package/src/components/MainButton/MainButton.ts +0 -242
- package/src/components/MainButton/index.ts +0 -2
- package/src/components/MainButton/types.ts +0 -20
- package/src/components/Popup/index.ts +0 -8
- package/src/components/QRScanner/index.ts +0 -2
- package/src/components/ThemeParams/ThemeParams.ts +0 -166
- package/src/components/ThemeParams/index.ts +0 -2
- package/src/components/ThemeParams/types.ts +0 -18
- package/src/components/Viewport/index.ts +0 -2
- package/src/components/WebApp/WebApp.ts +0 -311
- package/src/components/WebApp/index.ts +0 -2
- package/src/components/WebApp/types.ts +0 -17
- package/src/components/index.ts +0 -11
- package/src/env.ts +0 -22
- package/src/errors/MethodNotSupportedError.ts +0 -9
- package/src/errors/ParameterNotSupportedError.ts +0 -9
- package/src/errors/index.ts +0 -2
- package/src/init/creators/createWebApp.ts +0 -52
- package/src/init/css.ts +0 -166
- package/src/supports.ts +0 -44
- package/src/types.ts +0 -13
- package/src/url.ts +0 -23
- /package/dist/dts/{components/CloudStorage → cloud-storage}/index.d.ts +0 -0
- /package/dist/dts/{components/HapticFeedback → haptic-feedback}/index.d.ts +0 -0
- /package/src/{components/CloudStorage → cloud-storage}/index.ts +0 -0
- /package/src/{components/HapticFeedback → haptic-feedback}/index.ts +0 -0
package/src/init/types.ts
CHANGED
|
@@ -1,99 +1,81 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} from '../components/index.js';
|
|
1
|
+
import type { BackButton } from '~/back-button/index.js';
|
|
2
|
+
import type { PostEvent } from '~/bridge/index.js';
|
|
3
|
+
import type { ClosingBehavior } from '~/closing-behavior/index.js';
|
|
4
|
+
import type { CloudStorage } from '~/cloud-storage/index.js';
|
|
5
|
+
import type { HapticFeedback } from '~/haptic-feedback/index.js';
|
|
6
|
+
import type { InitData } from '~/init-data/index.js';
|
|
7
|
+
import type { Invoice } from '~/invoice/index.js';
|
|
8
|
+
import type { MainButton } from '~/main-button/index.js';
|
|
9
|
+
import type { MiniApp } from '~/mini-app/index.js';
|
|
10
|
+
import type { Popup } from '~/popup/index.js';
|
|
11
|
+
import type { QRScanner } from '~/qr-scanner/index.js';
|
|
12
|
+
import type { ThemeParams } from '~/theme-params/index.js';
|
|
13
|
+
import type { CreateRequestIdFunc } from '~/types/index.js';
|
|
14
|
+
import type { Utils } from '~/utils/index.js';
|
|
15
|
+
import type { Viewport } from '~/viewport/index.js';
|
|
17
16
|
|
|
18
17
|
export interface InitResult {
|
|
19
18
|
backButton: BackButton;
|
|
20
|
-
closingBehavior:
|
|
19
|
+
closingBehavior: ClosingBehavior;
|
|
21
20
|
cloudStorage: CloudStorage;
|
|
22
|
-
|
|
21
|
+
createRequestId: CreateRequestIdFunc;
|
|
22
|
+
hapticFeedback: HapticFeedback;
|
|
23
23
|
initData?: InitData;
|
|
24
24
|
initDataRaw?: string;
|
|
25
|
+
invoice: Invoice;
|
|
25
26
|
mainButton: MainButton;
|
|
27
|
+
miniApp: MiniApp;
|
|
26
28
|
popup: Popup;
|
|
27
29
|
postEvent: PostEvent;
|
|
28
30
|
qrScanner: QRScanner;
|
|
29
31
|
themeParams: ThemeParams;
|
|
32
|
+
utils: Utils;
|
|
30
33
|
viewport: Viewport;
|
|
31
|
-
webApp: WebApp;
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
export interface InitCSSVarsSpecificOption {
|
|
35
37
|
/**
|
|
36
|
-
* Enables theme parameters CSS variables
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* - `--tg-theme-button-text-color`
|
|
40
|
-
* - `--tg-theme-hint-color`
|
|
41
|
-
* - `--tg-theme-link-color`
|
|
42
|
-
* - `--tg-theme-secondary-bg-color`
|
|
43
|
-
* - `--tg-theme-text-color`
|
|
44
|
-
*
|
|
45
|
-
* @see bindThemeCSSVariables
|
|
38
|
+
* Enables theme parameters CSS variables.
|
|
39
|
+
* @see bindThemeCSSVars
|
|
40
|
+
* @default false
|
|
46
41
|
*/
|
|
47
|
-
themeParams?:
|
|
42
|
+
themeParams?: boolean;
|
|
48
43
|
|
|
49
44
|
/**
|
|
50
|
-
* Enables viewport CSS variables
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* @see bindViewportCSSVariables
|
|
45
|
+
* Enables viewport CSS variables.
|
|
46
|
+
* @see bindViewportCSSVars
|
|
47
|
+
* @default false
|
|
55
48
|
*/
|
|
56
|
-
viewport?:
|
|
49
|
+
viewport?: boolean;
|
|
57
50
|
|
|
58
51
|
/**
|
|
59
|
-
* Enables
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* @see bindWebAppVariables
|
|
52
|
+
* Enables mini app CSS variables.
|
|
53
|
+
* @see bindMiniAppCSSVars
|
|
54
|
+
* @default false
|
|
64
55
|
*/
|
|
65
|
-
|
|
56
|
+
miniApp?: boolean;
|
|
66
57
|
}
|
|
67
58
|
|
|
68
59
|
export type InitCSSVarsOption = boolean | InitCSSVarsSpecificOption;
|
|
69
60
|
|
|
70
61
|
export interface InitOptions {
|
|
71
62
|
/**
|
|
72
|
-
*
|
|
63
|
+
* True if synchronization must be performed asynchronously. This allows init function to
|
|
64
|
+
* perform async operations. One of them is the actual viewport state retrieving from the
|
|
65
|
+
* Telegram application. Otherwise, viewport state will be retrieved later.
|
|
66
|
+
* @default false
|
|
73
67
|
*/
|
|
74
|
-
|
|
68
|
+
async?: boolean;
|
|
75
69
|
|
|
76
70
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* @default true
|
|
71
|
+
* True if SDK should accept styles sent from the Telegram web application. This option is only
|
|
72
|
+
* used in web versions of Telegram.
|
|
73
|
+
* @default false
|
|
81
74
|
*/
|
|
82
75
|
acceptCustomStyles?: boolean;
|
|
83
76
|
|
|
84
77
|
/**
|
|
85
|
-
* Should SDK
|
|
86
|
-
* Mini App method was called. It is highly recommended not to disable this
|
|
87
|
-
* feature as long as it helps developer to find issues related to usage
|
|
88
|
-
* of unsupported methods.
|
|
89
|
-
*
|
|
90
|
-
* @default true
|
|
91
|
-
*/
|
|
92
|
-
checkCompat?: boolean;
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Should SDK create global CSS variables related to current Telegram
|
|
96
|
-
* application colors.
|
|
78
|
+
* Should SDK create global CSS variables related to current Telegram application colors.
|
|
97
79
|
*
|
|
98
80
|
* Possible values:
|
|
99
81
|
* - `false` - no CSS variables will be created.
|
|
@@ -103,31 +85,4 @@ export interface InitOptions {
|
|
|
103
85
|
* @default false
|
|
104
86
|
*/
|
|
105
87
|
cssVars?: InitCSSVarsOption;
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Enable debug mode.
|
|
109
|
-
*
|
|
110
|
-
* @default false
|
|
111
|
-
*/
|
|
112
|
-
debug?: boolean;
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Launch parameters presented as query parameters or already parsed
|
|
116
|
-
* object. In case, this value is not specified, init
|
|
117
|
-
* function will try to retrieve launch parameters from window.location.hash
|
|
118
|
-
* via retrieveLaunchParams function.
|
|
119
|
-
*/
|
|
120
|
-
launchParams?: string | URLSearchParams | LaunchParams;
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Sets new targetOrigin, used by bridge's `postEvent` function.
|
|
124
|
-
* @see setTargetOrigin
|
|
125
|
-
*/
|
|
126
|
-
targetOrigin?: string;
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Initialization process timeout.
|
|
130
|
-
* @default 1000
|
|
131
|
-
*/
|
|
132
|
-
timeout?: number;
|
|
133
88
|
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Chat,
|
|
3
|
+
ChatType,
|
|
4
|
+
InitDataParsed,
|
|
5
|
+
User,
|
|
6
|
+
} from './types.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Class which is responsible for displaying Mini Apps init data.
|
|
10
|
+
*/
|
|
11
|
+
export class InitData {
|
|
12
|
+
constructor(private readonly initData: InitDataParsed) {
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @see InitDataParsed.authDate
|
|
17
|
+
*/
|
|
18
|
+
get authDate(): Date {
|
|
19
|
+
return this.initData.authDate;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @see InitDataParsed.canSendAfter
|
|
24
|
+
*/
|
|
25
|
+
get canSendAfter(): number | undefined {
|
|
26
|
+
return this.initData.canSendAfter;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Date after which it is allowed to call
|
|
31
|
+
* the [answerWebAppQuery](https://core.telegram.org/bots/api#answerwebappquery) method.
|
|
32
|
+
*/
|
|
33
|
+
get canSendAfterDate(): Date | undefined {
|
|
34
|
+
const { canSendAfter } = this;
|
|
35
|
+
|
|
36
|
+
return canSendAfter === undefined
|
|
37
|
+
? undefined
|
|
38
|
+
: new Date(this.authDate.getTime() + canSendAfter * 1000);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @see InitDataParsed.chat
|
|
43
|
+
*/
|
|
44
|
+
get chat(): Chat | undefined {
|
|
45
|
+
return this.initData.chat;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @see InitDataParsed.chatType
|
|
50
|
+
*/
|
|
51
|
+
get chatType(): ChatType | undefined {
|
|
52
|
+
return this.initData.chatType;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @see InitDataParsed.chatInstance
|
|
57
|
+
*/
|
|
58
|
+
get chatInstance(): string | undefined {
|
|
59
|
+
return this.initData.chatInstance;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @see InitDataParsed.hash
|
|
64
|
+
*/
|
|
65
|
+
get hash(): string {
|
|
66
|
+
return this.initData.hash;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @see InitDataParsed.queryId
|
|
71
|
+
*/
|
|
72
|
+
get queryId(): string | undefined {
|
|
73
|
+
return this.initData.queryId;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @see InitDataParsed.receiver
|
|
78
|
+
*/
|
|
79
|
+
get receiver(): User | undefined {
|
|
80
|
+
return this.initData.receiver;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @see InitDataParsed.startParam
|
|
85
|
+
*/
|
|
86
|
+
get startParam(): string | undefined {
|
|
87
|
+
return this.initData.startParam;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @see InitDataParsed.user
|
|
92
|
+
*/
|
|
93
|
+
get user(): User | undefined {
|
|
94
|
+
return this.initData.user;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { json, number, string } from '~/parsing/index.js';
|
|
2
|
+
|
|
3
|
+
import type { Chat } from './types.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns parser used to parse chat data.
|
|
7
|
+
*/
|
|
8
|
+
export function chatParser() {
|
|
9
|
+
return json<Chat>({
|
|
10
|
+
id: number(),
|
|
11
|
+
type: string(),
|
|
12
|
+
title: string(),
|
|
13
|
+
photoUrl: {
|
|
14
|
+
type: string().optional(),
|
|
15
|
+
from: 'photo_url',
|
|
16
|
+
},
|
|
17
|
+
username: string().optional(),
|
|
18
|
+
}, 'Chat');
|
|
19
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { date, number, searchParams, string } from '~/parsing/index.js';
|
|
2
|
+
|
|
3
|
+
import { chatParser } from './chatParser.js';
|
|
4
|
+
import type { InitDataParsed } from './types.js';
|
|
5
|
+
import { userParser } from './userParser.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns parser used to parse init data, presented as search params.
|
|
9
|
+
*/
|
|
10
|
+
export function initDataParser() {
|
|
11
|
+
return searchParams<InitDataParsed>({
|
|
12
|
+
authDate: {
|
|
13
|
+
type: date(),
|
|
14
|
+
from: 'auth_date',
|
|
15
|
+
},
|
|
16
|
+
canSendAfter: {
|
|
17
|
+
type: number().optional(),
|
|
18
|
+
from: 'can_send_after',
|
|
19
|
+
},
|
|
20
|
+
chat: chatParser().optional(),
|
|
21
|
+
chatInstance: {
|
|
22
|
+
type: string().optional(),
|
|
23
|
+
from: 'chat_instance',
|
|
24
|
+
},
|
|
25
|
+
chatType: {
|
|
26
|
+
type: string().optional(),
|
|
27
|
+
from: 'chat_type',
|
|
28
|
+
},
|
|
29
|
+
hash: string(),
|
|
30
|
+
queryId: {
|
|
31
|
+
type: string().optional(),
|
|
32
|
+
from: 'query_id',
|
|
33
|
+
},
|
|
34
|
+
receiver: userParser().optional(),
|
|
35
|
+
startParam: {
|
|
36
|
+
type: string().optional(),
|
|
37
|
+
from: 'start_param',
|
|
38
|
+
},
|
|
39
|
+
user: userParser().optional(),
|
|
40
|
+
}, 'InitData');
|
|
41
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { initDataParser } from './initDataParser.js';
|
|
2
|
+
import type { InitDataParsed } from './types.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Parses incoming value as init data.
|
|
6
|
+
* @param value - value to parse.
|
|
7
|
+
*/
|
|
8
|
+
export function parseInitData(value: unknown): InitDataParsed {
|
|
9
|
+
return initDataParser().parse(value);
|
|
10
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Known type of chat.
|
|
3
|
+
*/
|
|
4
|
+
export type ChatType =
|
|
5
|
+
| 'sender'
|
|
6
|
+
| 'private'
|
|
7
|
+
| 'group'
|
|
8
|
+
| 'supergroup'
|
|
9
|
+
| 'channel'
|
|
10
|
+
| string;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Describes Telegram Mini Apps [User](https://docs.telegram-mini-apps.com/platform/launch-parameters/init-data#user) type.
|
|
14
|
+
*/
|
|
15
|
+
export interface User {
|
|
16
|
+
/**
|
|
17
|
+
* True, if this user added the bot to the attachment menu.
|
|
18
|
+
*/
|
|
19
|
+
addedToAttachmentMenu?: boolean;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* True, if this user allowed the bot to message them.
|
|
23
|
+
*/
|
|
24
|
+
allowsWriteToPm?: boolean;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* First name of the user or bot.
|
|
28
|
+
*/
|
|
29
|
+
firstName: string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A unique identifier for the user or bot.
|
|
33
|
+
*/
|
|
34
|
+
id: number;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* True, if this user is a bot. Returned in the `receiver` field only.
|
|
38
|
+
* @see InitDataParsed.receiver
|
|
39
|
+
*/
|
|
40
|
+
isBot?: boolean;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* True, if this user is a Telegram Premium user.
|
|
44
|
+
*/
|
|
45
|
+
isPremium?: boolean;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Last name of the user or bot.
|
|
49
|
+
*/
|
|
50
|
+
lastName?: string;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* [IETF language tag](https://en.wikipedia.org/wiki/IETF_language_tag) of the user's language.
|
|
54
|
+
* Returns in user field only.
|
|
55
|
+
*/
|
|
56
|
+
languageCode?: string;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* URL of the user’s profile photo. The photo can be in .jpeg or .svg
|
|
60
|
+
* formats. Only returned for Mini Apps launched from the attachment menu.
|
|
61
|
+
*/
|
|
62
|
+
photoUrl?: string;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Username of the user or bot.
|
|
66
|
+
*/
|
|
67
|
+
username?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Describes Telegram Mini Apps [Chat](https://docs.telegram-mini-apps.com/platform/launch-parameters/init-data#chat) type.
|
|
72
|
+
*/
|
|
73
|
+
export interface Chat {
|
|
74
|
+
/**
|
|
75
|
+
* Unique identifier for this chat.
|
|
76
|
+
*/
|
|
77
|
+
id: number;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* URL of the chat’s photo. The photo can be in .jpeg or .svg formats.
|
|
81
|
+
* Only returned for Mini Apps launched from the attachment menu.
|
|
82
|
+
*/
|
|
83
|
+
photoUrl?: string;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Type of chat.
|
|
87
|
+
*/
|
|
88
|
+
type: 'group' | 'supergroup' | 'channel' | string;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Title of the chat.
|
|
92
|
+
*/
|
|
93
|
+
title: string;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Username of the chat.
|
|
97
|
+
*/
|
|
98
|
+
username?: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Describes Telegram Mini Apps [InitData](https://docs.telegram-mini-apps.com/platform/launch-parameters/init-data#parameters-list)
|
|
103
|
+
* type.
|
|
104
|
+
*/
|
|
105
|
+
export interface InitDataParsed {
|
|
106
|
+
/**
|
|
107
|
+
* Init data generation date.
|
|
108
|
+
*/
|
|
109
|
+
authDate: Date;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* The number of seconds after which a message can be sent via the method [answerWebAppQuery](https://core.telegram.org/bots/api#answerwebappquery).
|
|
113
|
+
*/
|
|
114
|
+
canSendAfter?: number;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* An object containing data about the chat where the bot was launched via
|
|
118
|
+
* the attachment menu. Returned for supergroups, channels and group
|
|
119
|
+
* chats – only for Mini Apps launched via the attachment menu.
|
|
120
|
+
*/
|
|
121
|
+
chat?: Chat;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The type of chat from which Mini App was opened.
|
|
125
|
+
*/
|
|
126
|
+
chatType?: ChatType;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* A global identifier indicating the chat from which Mini App was opened. Returned only for
|
|
130
|
+
* applications opened by direct link.
|
|
131
|
+
*/
|
|
132
|
+
chatInstance?: string;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* A hash of all passed parameters, which the bot server can use to
|
|
136
|
+
* check their [validity](https://core.telegram.org/bots/webapps#validating-data-received-via-the-web-app).
|
|
137
|
+
*/
|
|
138
|
+
hash: string;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* A unique identifier for the Mini App session, required for sending
|
|
142
|
+
* messages via the [answerWebAppQuery](https://core.telegram.org/bots/api#answerwebappquery) method.
|
|
143
|
+
*/
|
|
144
|
+
queryId?: string;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* An object containing data about the chat partner of the current user in
|
|
148
|
+
* the chat where the bot was launched via the attachment menu.
|
|
149
|
+
* Returned only for private chats and only for Mini Apps launched
|
|
150
|
+
* via the attachment menu.
|
|
151
|
+
*/
|
|
152
|
+
receiver?: User;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* The value of the `startattach` parameter, passed via link. Only returned for
|
|
156
|
+
* Mini Apps when launched from the attachment menu via link.
|
|
157
|
+
*/
|
|
158
|
+
startParam?: string;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* An object containing data about the current user.
|
|
162
|
+
*/
|
|
163
|
+
user?: User;
|
|
164
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { boolean, json, number, string } from '~/parsing/index.js';
|
|
2
|
+
|
|
3
|
+
import type { User } from './types.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns parser used to parse user data.
|
|
7
|
+
*/
|
|
8
|
+
export function userParser() {
|
|
9
|
+
return json<User>({
|
|
10
|
+
addedToAttachmentMenu: {
|
|
11
|
+
type: boolean().optional(),
|
|
12
|
+
from: 'added_to_attachment_menu',
|
|
13
|
+
},
|
|
14
|
+
allowsWriteToPm: {
|
|
15
|
+
type: boolean().optional(),
|
|
16
|
+
from: 'allows_write_to_pm',
|
|
17
|
+
},
|
|
18
|
+
firstName: {
|
|
19
|
+
type: string(),
|
|
20
|
+
from: 'first_name',
|
|
21
|
+
},
|
|
22
|
+
id: number(),
|
|
23
|
+
isBot: {
|
|
24
|
+
type: boolean().optional(),
|
|
25
|
+
from: 'is_bot',
|
|
26
|
+
},
|
|
27
|
+
isPremium: {
|
|
28
|
+
type: boolean().optional(),
|
|
29
|
+
from: 'is_premium',
|
|
30
|
+
},
|
|
31
|
+
languageCode: {
|
|
32
|
+
type: string().optional(),
|
|
33
|
+
from: 'language_code',
|
|
34
|
+
},
|
|
35
|
+
lastName: {
|
|
36
|
+
type: string().optional(),
|
|
37
|
+
from: 'last_name',
|
|
38
|
+
},
|
|
39
|
+
photoUrl: {
|
|
40
|
+
type: string().optional(),
|
|
41
|
+
from: 'photo_url',
|
|
42
|
+
},
|
|
43
|
+
username: string().optional(),
|
|
44
|
+
}, 'User');
|
|
45
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type InvoiceStatus,
|
|
3
|
+
type PostEvent,
|
|
4
|
+
postEvent as defaultPostEvent,
|
|
5
|
+
request,
|
|
6
|
+
} from '~/bridge/index.js';
|
|
7
|
+
import { EventEmitter } from '~/event-emitter/index.js';
|
|
8
|
+
import { State } from '~/state/index.js';
|
|
9
|
+
import {
|
|
10
|
+
createSupportsFunc,
|
|
11
|
+
type SupportsFunc,
|
|
12
|
+
} from '~/supports/index.js';
|
|
13
|
+
import type { Version } from '~/version/index.js';
|
|
14
|
+
|
|
15
|
+
import type { InvoiceEvents, InvoiceState } from './types.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Extracts invoice slug from URL.
|
|
19
|
+
* @param url - url to extract slug from.
|
|
20
|
+
*/
|
|
21
|
+
function slugFromUrl(url: string): string {
|
|
22
|
+
const { hostname, pathname } = new URL(url, window.location.href);
|
|
23
|
+
if (hostname !== 't.me') {
|
|
24
|
+
throw new Error(`Incorrect hostname: ${hostname}`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Valid examples:
|
|
28
|
+
// "/invoice/my-slug"
|
|
29
|
+
// "/$my-slug"
|
|
30
|
+
const match = pathname.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);
|
|
31
|
+
|
|
32
|
+
if (match === null) {
|
|
33
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
34
|
+
throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');
|
|
35
|
+
}
|
|
36
|
+
return match[2];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Controls currently displayed invoice.
|
|
41
|
+
*/
|
|
42
|
+
export class Invoice {
|
|
43
|
+
private readonly ee = new EventEmitter<InvoiceEvents>();
|
|
44
|
+
|
|
45
|
+
private readonly state: State<InvoiceState>;
|
|
46
|
+
|
|
47
|
+
constructor(
|
|
48
|
+
version: Version,
|
|
49
|
+
private readonly postEvent: PostEvent = defaultPostEvent,
|
|
50
|
+
) {
|
|
51
|
+
this.state = new State({ isOpened: false }, this.ee);
|
|
52
|
+
this.supports = createSupportsFunc(version, { open: 'web_app_open_invoice' });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private set isOpened(value) {
|
|
56
|
+
this.state.set('isOpened', value);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* True if invoice is currently opened.
|
|
61
|
+
*/
|
|
62
|
+
get isOpened(): boolean {
|
|
63
|
+
return this.state.get('isOpened');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Adds new event listener.
|
|
68
|
+
*/
|
|
69
|
+
on = this.ee.on.bind(this.ee);
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Removes event listener.
|
|
73
|
+
*/
|
|
74
|
+
off = this.ee.off.bind(this.ee);
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Opens an invoice using its slug.
|
|
78
|
+
* @param slug - invoice slug.
|
|
79
|
+
* @throws {Error} Invoice is already opened.
|
|
80
|
+
*/
|
|
81
|
+
open(slug: string): Promise<InvoiceStatus>;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Opens an invoice using its url. It expects passing link in full format, with hostname "t.me".
|
|
85
|
+
* @param url - invoice URL.
|
|
86
|
+
* @param type - value type.
|
|
87
|
+
* @throws {Error} Invoice is already opened.
|
|
88
|
+
*/
|
|
89
|
+
open(url: string, type: 'url'): Promise<InvoiceStatus>;
|
|
90
|
+
|
|
91
|
+
async open(urlOrSlug: string, type?: 'url'): Promise<InvoiceStatus> {
|
|
92
|
+
if (this.isOpened) {
|
|
93
|
+
throw new Error('Invoice is already opened');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const slug = type ? slugFromUrl(urlOrSlug) : urlOrSlug;
|
|
97
|
+
|
|
98
|
+
this.isOpened = true;
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
const result = await request(
|
|
102
|
+
'web_app_open_invoice',
|
|
103
|
+
{ slug },
|
|
104
|
+
'invoice_closed',
|
|
105
|
+
{
|
|
106
|
+
postEvent: this.postEvent,
|
|
107
|
+
capture(data) {
|
|
108
|
+
return slug === data.slug;
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
return result.status;
|
|
114
|
+
} finally {
|
|
115
|
+
this.isOpened = false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Checks if specified method is supported by current component.
|
|
121
|
+
*/
|
|
122
|
+
supports: SupportsFunc<'open'>;
|
|
123
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { StateEvents } from '~/state/index.js';
|
|
2
|
+
|
|
3
|
+
export interface InvoiceState {
|
|
4
|
+
isOpened: boolean;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export type InvoiceEvents = StateEvents<InvoiceState>;
|
|
8
|
+
|
|
9
|
+
export type InvoiceEventName = keyof InvoiceEvents;
|
|
10
|
+
|
|
11
|
+
export type InvoiceEventListener<E extends InvoiceEventName> = InvoiceEvents[E];
|