@alfalab/bridge-to-native 1.4.1 → 1.4.2

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.
@@ -19,11 +19,11 @@ class BridgeToNative {
19
19
  * если не передать, B2N не будет логировать ошибки.
20
20
  */
21
21
  constructor(options) {
22
- var _a, _b, _c;
22
+ var _a, _b, _c, _d;
23
23
  this.options = options;
24
24
  this.nativeParamsService = new native_params_service_1.NativeParamsService((_a = this.options) === null || _a === void 0 ? void 0 : _a.logError);
25
- this.externalLinksService = new external_links_service_1.ExternalLinksService(this.nativeParamsService);
26
- this.nativeNavigationAndTitleService = new native_navigation_and_title_service_1.NativeNavigationAndTitleService(this.nativeParamsService, (_b = this.options) === null || _b === void 0 ? void 0 : _b.browserHistoryApiWrappers, (_c = this.options) === null || _c === void 0 ? void 0 : _c.logError);
25
+ this.externalLinksService = new external_links_service_1.ExternalLinksService(this.nativeParamsService, (_b = this.options) === null || _b === void 0 ? void 0 : _b.logError);
26
+ this.nativeNavigationAndTitleService = new native_navigation_and_title_service_1.NativeNavigationAndTitleService(this.nativeParamsService, (_c = this.options) === null || _c === void 0 ? void 0 : _c.browserHistoryApiWrappers, (_d = this.options) === null || _d === void 0 ? void 0 : _d.logError);
27
27
  }
28
28
  /**
29
29
  * Схема NA.
@@ -1,4 +1,4 @@
1
- import { type PdfType } from '../types';
1
+ import { type LogError, type PdfType } from '../types';
2
2
  import { type NativeParamsService } from './native-params-service';
3
3
  /**
4
4
  * Сервис, предоставляющий методы для открытия внешних для текущего WA экранов
@@ -6,8 +6,9 @@ import { type NativeParamsService } from './native-params-service';
6
6
  */
7
7
  export declare class ExternalLinksService {
8
8
  private nativeParamsService;
9
+ private logError?;
9
10
  private navigationByNativeAppInProgress;
10
- constructor(nativeParamsService: NativeParamsService);
11
+ constructor(nativeParamsService: NativeParamsService, logError?: LogError | undefined);
11
12
  handleNativeDeeplink(deeplink: string, closeWebviewBeforeCallNativeDeeplinkHandler?: boolean): void;
12
13
  getHrefToOpenInBrowser(link: string): string;
13
14
  openInBrowser(link: string): void;
@@ -12,8 +12,9 @@ const QUERY_OPEN_IN_BROWSER_VALUE = 'true';
12
12
  * и связанных с этим действий.
13
13
  */
14
14
  class ExternalLinksService {
15
- constructor(nativeParamsService) {
15
+ constructor(nativeParamsService, logError) {
16
16
  this.nativeParamsService = nativeParamsService;
17
+ this.logError = logError;
17
18
  this.navigationByNativeAppInProgress = false;
18
19
  }
19
20
  handleNativeDeeplink(deeplink, closeWebviewBeforeCallNativeDeeplinkHandler = false) {
@@ -39,7 +40,10 @@ class ExternalLinksService {
39
40
  if (!this.nativeParamsService.canUseNativeFeature('linksInBrowser')) {
40
41
  return `${this.nativeParamsService.appId}://webFeature?type=recommendation&url=${encodeURIComponent(link)}`;
41
42
  }
42
- const url = new URL(link);
43
+ const url = (0, utils_1.validateUrl)(link, this.logError);
44
+ if (!url) {
45
+ throw new Error(`invalid url: ${link}`);
46
+ }
43
47
  url.searchParams.append(QUERY_OPEN_IN_BROWSER_KEY, QUERY_OPEN_IN_BROWSER_VALUE);
44
48
  return url.href;
45
49
  }
@@ -51,12 +55,18 @@ class ExternalLinksService {
51
55
  this.openInNewWebview(link);
52
56
  return;
53
57
  }
54
- const url = new URL(link);
58
+ const url = (0, utils_1.validateUrl)(link, this.logError);
59
+ if (!url) {
60
+ throw new Error(`invalid url: ${link}`);
61
+ }
55
62
  url.searchParams.append(QUERY_OPEN_IN_BROWSER_KEY, QUERY_OPEN_IN_BROWSER_VALUE);
56
63
  this.navigateByNativeApp(url.href);
57
64
  }
58
65
  openInNewWebview(link, nativeTitle = '', closeCurrentWebview = false) {
59
- const url = new URL(link);
66
+ const url = (0, utils_1.validateUrl)(link, this.logError);
67
+ if (!url) {
68
+ throw new Error(`invalid url: ${link}`);
69
+ }
60
70
  if (nativeTitle) {
61
71
  url.searchParams.set(query_and_headers_keys_1.QUERY_B2N_TITLE, nativeTitle);
62
72
  }
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- /* eslint max-lines: ["error", {"max": 350, "skipComments": true}] */
2
+ /* eslint max-lines: ["error", {"max": 360, "skipComments": true}] */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.NativeNavigationAndTitleService = void 0;
5
5
  const query_and_headers_keys_1 = require("../../query-and-headers-keys");
@@ -88,11 +88,22 @@ class NativeNavigationAndTitleService {
88
88
  this.syncHistoryWithNative();
89
89
  }
90
90
  navigateServerSide(link, nativeTitle = '') {
91
+ var _a;
91
92
  if (this.isNavigateServerSideLocked) {
92
93
  return;
93
94
  }
94
95
  this.isNavigateServerSideLocked = true;
95
- const url = link instanceof URL ? link : new URL(link);
96
+ let url;
97
+ try {
98
+ url = link instanceof URL ? link : new URL(link);
99
+ }
100
+ catch (error) {
101
+ (_a = this.logError) === null || _a === void 0 ? void 0 : _a.call(this, 'navigateServerSide: URL creating error', {
102
+ link,
103
+ error,
104
+ });
105
+ throw error;
106
+ }
96
107
  this.nativeHistoryStack.push(nativeTitle || '');
97
108
  if (nativeTitle) {
98
109
  url.searchParams.set(query_and_headers_keys_1.QUERY_B2N_TITLE, nativeTitle);
@@ -1,2 +1,4 @@
1
+ import { type LogError } from '../types';
1
2
  export declare function appendFromCurrentQueryParamForIos(nativeUrl: string): string;
2
3
  export declare const closeWebviewUtil: () => void;
4
+ export declare const validateUrl: (link: URL | string, logError?: LogError) => URL | null;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.closeWebviewUtil = void 0;
3
+ exports.validateUrl = exports.closeWebviewUtil = void 0;
4
4
  exports.appendFromCurrentQueryParamForIos = appendFromCurrentQueryParamForIos;
5
5
  const QUERY_CLOSE_WEBVIEW_KEY = 'closeWebView';
6
6
  const QUERY_CLOSE_WEBVIEW_VALUE = 'true';
@@ -23,3 +23,18 @@ const closeWebviewUtil = () => {
23
23
  window.location.href = originalPageUrl.toString();
24
24
  };
25
25
  exports.closeWebviewUtil = closeWebviewUtil;
26
+ const validateUrl = (link, logError) => {
27
+ let url;
28
+ try {
29
+ url = link instanceof URL ? link : new URL(link);
30
+ }
31
+ catch (error) {
32
+ logError === null || logError === void 0 ? void 0 : logError('validateUrl: URL parsing error', {
33
+ error,
34
+ link,
35
+ });
36
+ return null;
37
+ }
38
+ return url;
39
+ };
40
+ exports.validateUrl = validateUrl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alfalab/bridge-to-native",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "license": "MIT",
5
5
  "description": "Утилита для удобной работы веб приложения внутри нативного приложения и коммуникации с ним.",
6
6
  "engines": {