-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrei Takarski
committed
Nov 28, 2024
1 parent
7e9f88e
commit aaffe4d
Showing
20 changed files
with
523 additions
and
655 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { BridgeToNative } from './bridge-to-native'; | ||
export { NativeParams, Theme, Environment, NativeFeatureKey, PdfType } from './types'; | ||
export { getNativeParamsFromCookies } from './utils'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { BridgeToNative } from './client/bridge-to-native'; | ||
export { NativeParams, Theme, Environment, NativeFeatureKey, PdfType } from './client/types'; | ||
export * from './client' | ||
export * from './server'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,7 @@ | ||
export const THEME_QUERY = 'theme'; | ||
export const TITLE = 'title'; | ||
|
||
export const WEBVIEW_IOS_APP_ID_QUERY = 'applicationId'; | ||
export const WEBVIEW_IOS_APP_VERSION_QUERY = 'device_app_version'; | ||
export const WEBVIEW_WITHOUT_LAYOUT_QUERY = 'without_layout'; | ||
export const WEBVIEW_NEXT_PAGE_ID_QUERY = 'nextPageId'; | ||
|
||
export const CAPSULE_UA_SUBSTR = 'Capsule'; | ||
export const AKEY_UA_SUBSTR = 'AKEY'; | ||
export const VOSKHOD_UA_SUBSTR = 'VOSKHOD'; | ||
|
||
export const NATIVE_PARAMS_COOKIE_NAME = 'app_native_params'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
export * from './detect-and-extract-native-params'; | ||
export * from './check-is-webview'; | ||
export * from './is-webview-environment'; | ||
export * from './extract-native-params'; | ||
export * from './set-native-params-cookie'; | ||
export * from './types'; | ||
export * from './reg-exp-patterns'; | ||
export * from './extract-and-join-original-webview-params'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {NATIVE_PARAMS_COOKIE_NAME} from "./constants"; | ||
|
||
export const setNativeParamsCookie = (params: Record<string, string>, setCookie: (name: string, value: string) => void): void => { | ||
setCookie(NATIVE_PARAMS_COOKIE_NAME, encodeURIComponent(JSON.stringify(params))) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,11 @@ | ||
import type { NativeParamsType } from '../shared/types'; | ||
export type RequestHeaderType = Record<string, any>; | ||
|
||
export type EmptyNativeParams = { | ||
isWebview: false; | ||
}; | ||
|
||
export type NativeParams = { | ||
appVersion: string; | ||
iosAppId?: string; | ||
export type NativeParams = NativeParamsType & { | ||
isWebview: true; | ||
theme: 'dark' | 'light'; | ||
title: string; | ||
withoutLayout: boolean; | ||
originalWebviewParams: string; | ||
nextPageId: number | null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export type NativeParamsType = { | ||
appVersion: string; | ||
title?: string; | ||
// В ранних версиях iOS приложение не пробрасывет схему приложения в URL в прод окружении. | ||
// Для таких версий есть мэппинг `./constants` → `versionToIosAppId`. | ||
iosAppId?: string; | ||
theme: string; | ||
nextPageId: number | null; | ||
originalWebviewParams: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { NATIVE_PARAMS_COOKIE_NAME } from "../server/constants"; | ||
|
||
/** | ||
* Возвращает объект с `webview-параметрами` из cookies | ||
*/ | ||
export function extractNativeParamsFromCookies(cookies?: string): Record<string, unknown> | null { | ||
|
||
if (!cookies) { | ||
return null; | ||
} | ||
|
||
const cookiesArray = cookies.split('; '); | ||
const cookieString = cookiesArray.find((cookie: string) => cookie.startsWith(`${NATIVE_PARAMS_COOKIE_NAME}=`)); | ||
|
||
if (!cookieString) return null; | ||
|
||
const [, value] = cookieString.split('='); | ||
|
||
try { | ||
return JSON.parse(decodeURIComponent(value)); | ||
} catch { | ||
return null; | ||
} | ||
} |
Oops, something went wrong.