Skip to content

Commit

Permalink
Fixed types for UpdateConfig and add ScrollTop events (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
mainsmirnov authored Jul 15, 2022
1 parent 9fa8a63 commit c03058a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 42 deletions.
18 changes: 1 addition & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -19,22 +19,6 @@
"name": "VK",
"url": "https://vk.com"
},
"contributors": [
{
"name": "Tim Chaptykov",
"email": "[email protected]",
"url": "https://vk.com/tc"
},
{
"name": "Gleb Vorontsov",
"email": "[email protected]",
"url": "https://vk.com/boy"
},
{
"name": "Danakt Frost",
"url": "https://danakt.com"
}
],
"repository": {
"type": "git",
"url": "git+https://github.com/VKCOM/vk-bridge.git"
Expand Down
3 changes: 3 additions & 0 deletions src/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
Expand Down
70 changes: 45 additions & 25 deletions src/types/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -1016,6 +1026,9 @@ export type RequestPropsMap = {
VKWebAppConversionHit: ConversionHitRequest;
VKWebAppCheckSurvey: {};
VKWebAppShowSurvey: {};
VKWebAppScrollTop: {},
VKWebAppScrollTopStart: {},
VKWebAppScrollTopStop: {},
};

/**
Expand Down Expand Up @@ -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<T extends keyof RequestPropsMap, R extends string, F extends string> = Record<
Expand Down Expand Up @@ -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'>
;

0 comments on commit c03058a

Please sign in to comment.