@alfalab/bridge-to-native 0.0.13-beta-00a10e9 → 0.0.13-beta-024d5c2
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/client/index.d.ts +3 -0
- package/client/index.js +7 -0
- package/{types.d.ts → client/types.d.ts} +2 -8
- package/{utils.d.ts → client/utils.d.ts} +4 -0
- package/{utils.js → client/utils.js} +7 -1
- package/index.d.ts +2 -2
- package/index.js +12 -3
- package/package.json +2 -2
- package/server/constants.d.ts +7 -0
- package/server/constants.js +10 -0
- package/server/extract-and-join-original-webview-params.d.ts +9 -0
- package/server/extract-and-join-original-webview-params.js +40 -0
- package/server/extract-native-params.d.ts +7 -0
- package/server/extract-native-params.js +54 -0
- package/server/index.d.ts +4 -0
- package/server/index.js +16 -0
- package/server/is-webview-environment.d.ts +4 -0
- package/server/is-webview-environment.js +21 -0
- package/server/reg-exp-patterns.d.ts +3 -0
- package/server/reg-exp-patterns.js +7 -0
- package/server/set-native-params-cookie.d.ts +1 -0
- package/server/set-native-params-cookie.js +8 -0
- package/server/types.d.ts +9 -0
- package/server/types.js +2 -0
- package/server/utils.d.ts +13 -0
- package/server/utils.js +29 -0
- package/shared/types.d.ts +8 -0
- package/shared/types.js +2 -0
- package/shared/utils.d.ts +4 -0
- package/shared/utils.js +24 -0
- /package/{bridge-to-native.d.ts → client/bridge-to-native.d.ts} +0 -0
- /package/{bridge-to-native.js → client/bridge-to-native.js} +0 -0
- /package/{constants.d.ts → client/constants.d.ts} +0 -0
- /package/{constants.js → client/constants.js} +0 -0
- /package/{native-fallbacks.d.ts → client/native-fallbacks.d.ts} +0 -0
- /package/{native-fallbacks.js → client/native-fallbacks.js} +0 -0
- /package/{native-navigation-and-title.d.ts → client/native-navigation-and-title.d.ts} +0 -0
- /package/{native-navigation-and-title.js → client/native-navigation-and-title.js} +0 -0
- /package/{types.js → client/types.js} +0 -0
package/client/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNativeParamsFromCookies = exports.BridgeToNative = void 0;
|
|
4
|
+
var bridge_to_native_1 = require("./bridge-to-native");
|
|
5
|
+
Object.defineProperty(exports, "BridgeToNative", { enumerable: true, get: function () { return bridge_to_native_1.BridgeToNative; } });
|
|
6
|
+
var utils_1 = require("./utils");
|
|
7
|
+
Object.defineProperty(exports, "getNativeParamsFromCookies", { enumerable: true, get: function () { return utils_1.getNativeParamsFromCookies; } });
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
title?: string;
|
|
4
|
-
iosAppId?: string;
|
|
5
|
-
theme: string;
|
|
6
|
-
nextPageId: number | null;
|
|
7
|
-
originalWebviewParams: string;
|
|
8
|
-
};
|
|
1
|
+
import { NativeParamsType } from "../shared/types";
|
|
2
|
+
export declare type NativeParams = NativeParamsType;
|
|
9
3
|
export declare type NativeFeatureKey = 'geolocation' | 'linksInBrowser';
|
|
10
4
|
declare type NativeFeaturesParams = Readonly<Record<NativeFeatureKey, {
|
|
11
5
|
fromVersion: string;
|
|
@@ -21,3 +21,7 @@ export declare const getUrlInstance: (link: string) => URL;
|
|
|
21
21
|
*/
|
|
22
22
|
export declare const isValidVersionFormat: (version?: string | undefined) => boolean;
|
|
23
23
|
export declare const getAppId: (environment: Environment, iosAppId?: string | undefined) => string | null;
|
|
24
|
+
/**
|
|
25
|
+
* Возвращает объект с `webview-параметрами` из cookies
|
|
26
|
+
*/
|
|
27
|
+
export declare const getNativeParamsFromCookies: () => Record<string, unknown> | null;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAppId = exports.isValidVersionFormat = exports.getUrlInstance = exports.extractAppNameRouteAndQuery = void 0;
|
|
3
|
+
exports.getNativeParamsFromCookies = exports.getAppId = exports.isValidVersionFormat = exports.getUrlInstance = exports.extractAppNameRouteAndQuery = void 0;
|
|
4
4
|
const constants_1 = require("./constants");
|
|
5
|
+
const utils_1 = require("../shared/utils");
|
|
5
6
|
/**
|
|
6
7
|
* Разделяет веб ссылку на компоненты
|
|
7
8
|
* @param route внутренний путь для навигации
|
|
@@ -68,3 +69,8 @@ const getAppId = (environment, iosAppId) => {
|
|
|
68
69
|
return null;
|
|
69
70
|
};
|
|
70
71
|
exports.getAppId = getAppId;
|
|
72
|
+
/**
|
|
73
|
+
* Возвращает объект с `webview-параметрами` из cookies
|
|
74
|
+
*/
|
|
75
|
+
const getNativeParamsFromCookies = () => (0, utils_1.extractNativeParamsFromCookies)(document.cookie);
|
|
76
|
+
exports.getNativeParamsFromCookies = getNativeParamsFromCookies;
|
package/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export * from './client';
|
|
2
|
+
export * from './server';
|
package/index.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
2
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "BridgeToNative", { enumerable: true, get: function () { return bridge_to_native_1.BridgeToNative; } });
|
|
13
|
+
__exportStar(require("./client"), exports);
|
|
14
|
+
__exportStar(require("./server"), exports);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"license": "UNLICENSED",
|
|
3
3
|
"name": "@alfalab/bridge-to-native",
|
|
4
|
-
"version": "0.0.13-beta-
|
|
4
|
+
"version": "0.0.13-beta-024d5c2",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/core-ds/bridge-to-native.git"
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
],
|
|
76
76
|
"testPathIgnorePatterns": [
|
|
77
77
|
"/node_modules/",
|
|
78
|
-
"/test/
|
|
78
|
+
"/test/.*/mock/"
|
|
79
79
|
],
|
|
80
80
|
"reporters": [
|
|
81
81
|
"jest-junit",
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const THEME_QUERY = "theme";
|
|
2
|
+
export declare const TITLE = "title";
|
|
3
|
+
export declare const WEBVIEW_IOS_APP_ID_QUERY = "applicationId";
|
|
4
|
+
export declare const WEBVIEW_IOS_APP_VERSION_QUERY = "device_app_version";
|
|
5
|
+
export declare const WEBVIEW_WITHOUT_LAYOUT_QUERY = "without_layout";
|
|
6
|
+
export declare const WEBVIEW_NEXT_PAGE_ID_QUERY = "nextPageId";
|
|
7
|
+
export declare const NATIVE_PARAMS_COOKIE_NAME = "app_native_params";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NATIVE_PARAMS_COOKIE_NAME = exports.WEBVIEW_NEXT_PAGE_ID_QUERY = exports.WEBVIEW_WITHOUT_LAYOUT_QUERY = exports.WEBVIEW_IOS_APP_VERSION_QUERY = exports.WEBVIEW_IOS_APP_ID_QUERY = exports.TITLE = exports.THEME_QUERY = void 0;
|
|
4
|
+
exports.THEME_QUERY = 'theme';
|
|
5
|
+
exports.TITLE = 'title';
|
|
6
|
+
exports.WEBVIEW_IOS_APP_ID_QUERY = 'applicationId';
|
|
7
|
+
exports.WEBVIEW_IOS_APP_VERSION_QUERY = 'device_app_version';
|
|
8
|
+
exports.WEBVIEW_WITHOUT_LAYOUT_QUERY = 'without_layout';
|
|
9
|
+
exports.WEBVIEW_NEXT_PAGE_ID_QUERY = 'nextPageId';
|
|
10
|
+
exports.NATIVE_PARAMS_COOKIE_NAME = 'app_native_params';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Данная утилита извлекает из запроса все известные
|
|
3
|
+
* сервисные query параметры которые добавляются к url внутри
|
|
4
|
+
* webview при первой инициализации и собирает их в query строку.
|
|
5
|
+
*
|
|
6
|
+
* @param query - Query в формате объекта
|
|
7
|
+
* @return строка query параметров в формате: "title=Title&theme=dark..."
|
|
8
|
+
* */
|
|
9
|
+
export declare const extractAndJoinOriginalWebviewParams: (query: Record<string, string>) => string;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractAndJoinOriginalWebviewParams = void 0;
|
|
4
|
+
// Словарь всех известных на данный момент сервисных query параметров в webview
|
|
5
|
+
const webviewInitParamsDictionary = [
|
|
6
|
+
'device_app_version',
|
|
7
|
+
'device_os_version',
|
|
8
|
+
'device_boot_time',
|
|
9
|
+
'device_timezone',
|
|
10
|
+
'applicationId',
|
|
11
|
+
'device_app_id',
|
|
12
|
+
'device_locale',
|
|
13
|
+
'paySupported',
|
|
14
|
+
'device_model',
|
|
15
|
+
'device_uuid',
|
|
16
|
+
'device_name',
|
|
17
|
+
'device_id',
|
|
18
|
+
'client_id',
|
|
19
|
+
'theme',
|
|
20
|
+
'scope',
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* Данная утилита извлекает из запроса все известные
|
|
24
|
+
* сервисные query параметры которые добавляются к url внутри
|
|
25
|
+
* webview при первой инициализации и собирает их в query строку.
|
|
26
|
+
*
|
|
27
|
+
* @param query - Query в формате объекта
|
|
28
|
+
* @return строка query параметров в формате: "title=Title&theme=dark..."
|
|
29
|
+
* */
|
|
30
|
+
const extractAndJoinOriginalWebviewParams = (query) => {
|
|
31
|
+
const params = new URLSearchParams();
|
|
32
|
+
webviewInitParamsDictionary.forEach((key) => {
|
|
33
|
+
const value = query[key];
|
|
34
|
+
if (value) {
|
|
35
|
+
params.set(key, value);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return params.toString();
|
|
39
|
+
};
|
|
40
|
+
exports.extractAndJoinOriginalWebviewParams = extractAndJoinOriginalWebviewParams;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { WebViewParams, RequestHeaderType } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Вытаскивает из query и headers все детали для вебвью.
|
|
4
|
+
*
|
|
5
|
+
* @returns Примечание по `appVersion`: В вебвью окружении версия всегда имеет формат `x.x.x`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const extractNativeParams: (request: RequestHeaderType) => WebViewParams | null;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractNativeParams = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
const extract_and_join_original_webview_params_1 = require("./extract-and-join-original-webview-params");
|
|
7
|
+
const reg_exp_patterns_1 = require("./reg-exp-patterns");
|
|
8
|
+
const is_webview_environment_1 = require("./is-webview-environment");
|
|
9
|
+
/**
|
|
10
|
+
* Вытаскивает из query и headers все детали для вебвью.
|
|
11
|
+
*
|
|
12
|
+
* @returns Примечание по `appVersion`: В вебвью окружении версия всегда имеет формат `x.x.x`.
|
|
13
|
+
*/
|
|
14
|
+
const extractNativeParams = (request) => {
|
|
15
|
+
if (!(0, is_webview_environment_1.isWebviewEnvironment)(request)) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const { [constants_1.THEME_QUERY]: themeQuery,
|
|
19
|
+
// При желании через диплинк на вебвью можно передать желаемый заголовок
|
|
20
|
+
// По умолчанию нужна именно пустая строка.
|
|
21
|
+
[constants_1.TITLE]: title = '',
|
|
22
|
+
// Говорят, этого может и не быть в урле. Формат `com.xxxxxxxxx.app`.
|
|
23
|
+
[constants_1.WEBVIEW_IOS_APP_ID_QUERY]: iosAppIdQuery, [constants_1.WEBVIEW_IOS_APP_VERSION_QUERY]: iosAppVersionQuery, [constants_1.WEBVIEW_WITHOUT_LAYOUT_QUERY]: withoutLayoutQuery, [constants_1.WEBVIEW_NEXT_PAGE_ID_QUERY]: nextPageId, } = request.query;
|
|
24
|
+
const originalWebviewParams = (0, extract_and_join_original_webview_params_1.extractAndJoinOriginalWebviewParams)(request.query);
|
|
25
|
+
// Пробуем вытащить схему iOS приложения из query, если есть.
|
|
26
|
+
let iosAppId;
|
|
27
|
+
if (reg_exp_patterns_1.iosAppIdPattern.test(iosAppIdQuery)) {
|
|
28
|
+
const [, appIdSubsting] = iosAppIdQuery.match(reg_exp_patterns_1.iosAppIdPattern);
|
|
29
|
+
iosAppId = appIdSubsting;
|
|
30
|
+
}
|
|
31
|
+
// Определяем версию приложения из query или заголовка.
|
|
32
|
+
let appVersion = '0.0.0';
|
|
33
|
+
const appVersionFromHeaders = (0, utils_1.extractAppVersion)(request);
|
|
34
|
+
if (typeof iosAppVersionQuery === 'string' && reg_exp_patterns_1.versionPattern.test(iosAppVersionQuery)) {
|
|
35
|
+
appVersion = iosAppVersionQuery;
|
|
36
|
+
}
|
|
37
|
+
else if (typeof appVersionFromHeaders === 'string' &&
|
|
38
|
+
reg_exp_patterns_1.versionPattern.test(appVersionFromHeaders)) {
|
|
39
|
+
const [, versionSubstring] = appVersionFromHeaders.match(reg_exp_patterns_1.versionPattern) || [];
|
|
40
|
+
appVersion = versionSubstring;
|
|
41
|
+
}
|
|
42
|
+
const nativeParams = {
|
|
43
|
+
appVersion,
|
|
44
|
+
iosAppId,
|
|
45
|
+
isWebview: true,
|
|
46
|
+
theme: themeQuery === 'dark' ? 'dark' : 'light',
|
|
47
|
+
title,
|
|
48
|
+
withoutLayout: withoutLayoutQuery === 'true',
|
|
49
|
+
originalWebviewParams,
|
|
50
|
+
nextPageId: nextPageId ? Number(nextPageId) : null,
|
|
51
|
+
};
|
|
52
|
+
return nativeParams;
|
|
53
|
+
};
|
|
54
|
+
exports.extractNativeParams = extractNativeParams;
|
package/server/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./is-webview-environment"), exports);
|
|
14
|
+
__exportStar(require("./extract-native-params"), exports);
|
|
15
|
+
__exportStar(require("./set-native-params-cookie"), exports);
|
|
16
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { RequestHeaderType } from './types';
|
|
2
|
+
export declare const isWebviewByUserAgent: (userAgent: string, appVersion: string | undefined) => boolean;
|
|
3
|
+
export declare const isWebviewByCookies: (nativeParamsFromCookies: Record<string, any> | null) => boolean;
|
|
4
|
+
export declare const isWebviewEnvironment: (request: RequestHeaderType) => boolean;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isWebviewEnvironment = exports.isWebviewByCookies = exports.isWebviewByUserAgent = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
const reg_exp_patterns_1 = require("./reg-exp-patterns");
|
|
6
|
+
const isWebviewByUserAgent = (userAgent, appVersion) => {
|
|
7
|
+
return ((appVersion && reg_exp_patterns_1.versionPattern.test(appVersion)) || !!(userAgent === null || userAgent === void 0 ? void 0 : userAgent.match(reg_exp_patterns_1.webviewUaIOSPattern)));
|
|
8
|
+
};
|
|
9
|
+
exports.isWebviewByUserAgent = isWebviewByUserAgent;
|
|
10
|
+
const isWebviewByCookies = (nativeParamsFromCookies) => {
|
|
11
|
+
return !!(nativeParamsFromCookies && nativeParamsFromCookies.isWebview);
|
|
12
|
+
};
|
|
13
|
+
exports.isWebviewByCookies = isWebviewByCookies;
|
|
14
|
+
const isWebviewEnvironment = (request) => {
|
|
15
|
+
const userAgent = (0, utils_1.extractUserAgent)(request);
|
|
16
|
+
// `app-version` в заголовках – индикатор вебвью. В iOS есть только в первом запросе от webview
|
|
17
|
+
const appVersion = (0, utils_1.extractAppVersion)(request);
|
|
18
|
+
const nativeParams = (0, utils_1.extractNativeParamsFromCookieHeader)(request);
|
|
19
|
+
return (0, exports.isWebviewByCookies)(nativeParams) || (0, exports.isWebviewByUserAgent)(userAgent, appVersion);
|
|
20
|
+
};
|
|
21
|
+
exports.isWebviewEnvironment = isWebviewEnvironment;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.webviewUaIOSPattern = exports.versionPattern = exports.iosAppIdPattern = void 0;
|
|
4
|
+
exports.iosAppIdPattern = /^com\.([a-z]+)\.app$/;
|
|
5
|
+
// Android приписывает после версии тип билда, например `feature`. Нам эта инфа не нужна.
|
|
6
|
+
exports.versionPattern = /^(\d+\.\d+\.\d+)(\s.+)?$/;
|
|
7
|
+
exports.webviewUaIOSPattern = new RegExp(['WebView', '(iPhone|iPod|iPad)(?!.*Safari)'].join('|'), 'ig');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const setNativeParamsCookie: (params: Record<string, string>, setCookie: (name: string, value: string) => void) => void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setNativeParamsCookie = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const setNativeParamsCookie = (params, setCookie) => {
|
|
6
|
+
setCookie(constants_1.NATIVE_PARAMS_COOKIE_NAME, encodeURIComponent(JSON.stringify(params)));
|
|
7
|
+
};
|
|
8
|
+
exports.setNativeParamsCookie = setNativeParamsCookie;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { NativeParamsType } from '../shared/types';
|
|
2
|
+
export declare type RequestHeaderType = Record<string, any>;
|
|
3
|
+
export declare type EmptyWebViewParams = {
|
|
4
|
+
isWebview: false;
|
|
5
|
+
};
|
|
6
|
+
export declare type WebViewParams = NativeParamsType & {
|
|
7
|
+
isWebview: true;
|
|
8
|
+
withoutLayout: boolean;
|
|
9
|
+
};
|
package/server/types.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RequestHeaderType } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Возвращает `app-version` из заголовков запроса
|
|
4
|
+
*/
|
|
5
|
+
export declare function extractAppVersion(request: RequestHeaderType): string | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* Возвращает `User-agent` из заголовков запроса
|
|
8
|
+
*/
|
|
9
|
+
export declare function extractUserAgent(request: RequestHeaderType): string;
|
|
10
|
+
/**
|
|
11
|
+
* Возвращает объект с `webview-параметрами` из cookies
|
|
12
|
+
*/
|
|
13
|
+
export declare function extractNativeParamsFromCookieHeader(request: RequestHeaderType): Record<string, unknown> | null;
|
package/server/utils.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractNativeParamsFromCookieHeader = exports.extractUserAgent = exports.extractAppVersion = void 0;
|
|
4
|
+
const utils_1 = require("../shared/utils");
|
|
5
|
+
/**
|
|
6
|
+
* Заголовок с версией приложения, который посылает вебвью из AM Android
|
|
7
|
+
*/
|
|
8
|
+
const AppVersion = 'app-version';
|
|
9
|
+
/**
|
|
10
|
+
* Возвращает `app-version` из заголовков запроса
|
|
11
|
+
*/
|
|
12
|
+
function extractAppVersion(request) {
|
|
13
|
+
return request.headers[AppVersion];
|
|
14
|
+
}
|
|
15
|
+
exports.extractAppVersion = extractAppVersion;
|
|
16
|
+
/**
|
|
17
|
+
* Возвращает `User-agent` из заголовков запроса
|
|
18
|
+
*/
|
|
19
|
+
function extractUserAgent(request) {
|
|
20
|
+
return request.headers['user-agent'];
|
|
21
|
+
}
|
|
22
|
+
exports.extractUserAgent = extractUserAgent;
|
|
23
|
+
/**
|
|
24
|
+
* Возвращает объект с `webview-параметрами` из cookies
|
|
25
|
+
*/
|
|
26
|
+
function extractNativeParamsFromCookieHeader(request) {
|
|
27
|
+
return (0, utils_1.extractNativeParamsFromCookies)(request.headers['cookie']);
|
|
28
|
+
}
|
|
29
|
+
exports.extractNativeParamsFromCookieHeader = extractNativeParamsFromCookieHeader;
|
package/shared/types.js
ADDED
package/shared/utils.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractNativeParamsFromCookies = void 0;
|
|
4
|
+
const constants_1 = require("../server/constants");
|
|
5
|
+
/**
|
|
6
|
+
* Возвращает объект с `webview-параметрами` из cookies
|
|
7
|
+
*/
|
|
8
|
+
function extractNativeParamsFromCookies(cookies) {
|
|
9
|
+
if (!cookies) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const cookiesArray = cookies.split('; ');
|
|
13
|
+
const cookieString = cookiesArray.find((cookie) => cookie.startsWith(`${constants_1.NATIVE_PARAMS_COOKIE_NAME}=`));
|
|
14
|
+
if (!cookieString)
|
|
15
|
+
return null;
|
|
16
|
+
const [, value] = cookieString.split('=');
|
|
17
|
+
try {
|
|
18
|
+
return JSON.parse(decodeURIComponent(value));
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.extractNativeParamsFromCookies = extractNativeParamsFromCookies;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|