From c03058a52193df7fd34638fc217344b45bcb6144 Mon Sep 17 00:00:00 2001 From: Ilya Pishchulin <45998835+ilyapishchulin@users.noreply.github.com> Date: Fri, 15 Jul 2022 12:34:34 +0800 Subject: [PATCH] Fixed types for UpdateConfig and add ScrollTop events (#308) --- package.json | 18 +----------- src/bridge.ts | 3 ++ src/types/data.ts | 70 ++++++++++++++++++++++++++++++----------------- 3 files changed, 49 insertions(+), 42 deletions(-) diff --git a/package.json b/package.json index e3bc736..340e1dc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@vkontakte/vk-bridge", - "version": "2.6.4", + "version": "2.7.0", "description": "Connects a Mini App with VK client", "license": "MIT", "main": "dist/index.js", @@ -19,22 +19,6 @@ "name": "VK", "url": "https://vk.com" }, - "contributors": [ - { - "name": "Tim Chaptykov", - "email": "tim.chaptykov@gmail.com", - "url": "https://vk.com/tc" - }, - { - "name": "Gleb Vorontsov", - "email": "vorontsov.gleb@gmail.com", - "url": "https://vk.com/boy" - }, - { - "name": "Danakt Frost", - "url": "https://danakt.com" - } - ], "repository": { "type": "git", "url": "git+https://github.com/VKCOM/vk-bridge.git" diff --git a/src/bridge.ts b/src/bridge.ts index 7cd72fb..c2fc525 100644 --- a/src/bridge.ts +++ b/src/bridge.ts @@ -87,6 +87,9 @@ export const DESKTOP_METHODS = [ 'VKWebAppShowSubscriptionBox', 'VKWebAppCheckSurvey', 'VKWebAppShowSurvey', + 'VKWebAppScrollTop', + 'VKWebAppScrollTopStart', + 'VKWebAppScrollTopStop', // Desktop web specific events ...(IS_DESKTOP_VK ? ['VKWebAppResizeWindow', 'VKWebAppAddToMenu', 'VKWebAppShowInstallPushBox', 'VKWebAppGetFriends'] : ['VKWebAppShowImages']), diff --git a/src/types/data.ts b/src/types/data.ts index 93e5b59..3e1e42e 100644 --- a/src/types/data.ts +++ b/src/types/data.ts @@ -223,7 +223,7 @@ export type AppearanceType = 'light' | 'dark'; /** * Application color scheme type */ -export type AppearanceSchemeType = 'vkcom_light' | 'vkcom_dark' | 'client_light' | 'client_dark' | 'space_gray' | 'bright_light'; +export type AppearanceSchemeType = 'vkcom_light' | 'vkcom_dark' | 'space_gray' | 'bright_light'; /** * Vibration type for Taptic Engine @@ -303,40 +303,46 @@ export type Insets = { bottom: number; }; -/** - * Update config type for mvk (mobile browser). - */ -export type MVKUpdateConfigData = { - /** Server API host for direct requests. */ +/** Default fields for config response on all platforms */ +export type DefaultUpdateConfigData = { api_host: string; + /** App_id of opened app */ + app_id: string; + /** Native app appearance */ + appearance: AppearanceType; + /** Native app scheme */ scheme: AppearanceSchemeType; }; -export type VKUpdateConfigData = { - /** Server API host for direct requests. */ - api_host: string; +/** Config response for native platforms */ +export type MobileUpdateConfigData = DefaultUpdateConfigData & { + /** Client type */ + app: 'vkclient' | 'vkme'; + /** Safe area insets. iOS only */ + insets?: Insets; +}; + +/** Config response for m.vk.com and vk.com */ +export type SharedUpdateConfigData = DefaultUpdateConfigData & { /** window.innerWidth of the parent window */ viewport_width: number; /** window.innerHeight of the parent window */ viewport_height: number; - scheme: AppearanceSchemeType; -}; + /** Server API host for direct requests. */ + api_host: string; +} -/** - * Update config type data for mobile clients and desktop. - */ -export type DefaultUpdateConfigData = { - app: 'vkclient' | 'vkme'; - app_id: string; - appearance: AppearanceType; - scheme: AppearanceSchemeType; - insets: Insets; +/** Config response for m.vk.com (mobile browser) */ +export type MVKUpdateConfigData = SharedUpdateConfigData; + +/** Config response for vk.com (full web) */ +export type VKUpdateConfigData = SharedUpdateConfigData & { + /** Is app opened in layer */ + is_layer: boolean; }; -/** - * Update config data - */ -export type ParentConfigData = DefaultUpdateConfigData | MVKUpdateConfigData | VKUpdateConfigData; +/** Update config data */ +export type ParentConfigData = MobileUpdateConfigData | MVKUpdateConfigData | VKUpdateConfigData; export type WidgetPreviewRequestOptions = { /** Widget type */ @@ -926,6 +932,10 @@ export type VKWebAppShowOrderBoxResponse = { order_id: string; }; +export type ScrollTopResponse = { + scrollTop: number; +}; + /** * Map of types of request props of VK Bridge methods */ @@ -1016,6 +1026,9 @@ export type RequestPropsMap = { VKWebAppConversionHit: ConversionHitRequest; VKWebAppCheckSurvey: {}; VKWebAppShowSurvey: {}; + VKWebAppScrollTop: {}, + VKWebAppScrollTopStart: {}, + VKWebAppScrollTopStop: {}, }; /** @@ -1117,6 +1130,9 @@ export type ReceiveDataMap = { VKWebAppConversionHit: ConversionHitResponse; VKWebAppCheckSurvey: { result: boolean }; VKWebAppShowSurvey: { result: boolean }; + VKWebAppScrollTop: ScrollTopResponse, + VKWebAppScrollTopStart: { result: true }, + VKWebAppScrollTopStop: { result: true }, }; type EventReceiveNames = Record< @@ -1237,4 +1253,8 @@ export type ReceiveEventMap = EventReceiveNames<'VKWebAppInit', 'VKWebAppInitRes EventReceiveNames<'VKWebAppCheckAllowedScopes', 'VKWebAppCheckAllowedScopesResult', 'VKWebAppCheckAllowedScopesFailed'> & EventReceiveNames<'VKWebAppCheckSurvey', 'VKWebAppCheckSurveyResult', 'VKWebAppCheckSurveyFailed'> & EventReceiveNames<'VKWebAppShowSurvey', 'VKWebAppShowSurveyResult', 'VKWebAppShowSurveyFailed'> & - EventReceiveNames<'VKWebAppConversionHit', 'VKWebAppConversionHitResult', 'VKWebAppConversionHitFailed'>; + EventReceiveNames<'VKWebAppConversionHit', 'VKWebAppConversionHitResult', 'VKWebAppConversionHitFailed'> & + EventReceiveNames<'VKWebAppScrollTop', 'VKWebAppScrollTopResult', 'VKWebAppScrollTopFailed'> & + EventReceiveNames<'VKWebAppScrollTopStart', 'VKWebAppScrollTopStartResult', 'VKWebAppScrollTopStop'> & + EventReceiveNames<'VKWebAppScrollTopStop', 'VKWebAppScrollTopStopResult', 'VKWebAppScrollTopStopFailed'> +;