@sap-ux/ui5-proxy-middleware 1.1.26 → 1.1.28

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.
@@ -1,20 +1,12 @@
1
1
  /// <reference types="node" />
2
2
  import type { NextFunction } from 'express';
3
3
  import type { IncomingMessage } from 'http';
4
- import type { UI5ProxyConfig } from '@sap-ux/ui5-config';
5
- export type Ui5MiddlewareConfig = UI5ProxyConfig;
6
4
  export interface ProxyConfig {
7
5
  path: string;
8
6
  url: string;
9
7
  version?: string;
10
8
  proxy?: string;
11
9
  }
12
- export interface MiddlewareParameters<T> {
13
- resources: object;
14
- options: {
15
- configuration: T;
16
- };
17
- }
18
10
  export interface UI5ProxyRequest {
19
11
  next?: NextFunction;
20
12
  }
@@ -73,28 +73,15 @@ export declare const getWebAppFolderFromYaml: (ui5YamlPath: string) => Promise<s
73
73
  * @param html - The HTML content
74
74
  */
75
75
  export declare const setHtmlResponse: (res: any, html: string) => void;
76
- /**
77
- * Gets the manifest.json for a given application.
78
- *
79
- * @param args list of runtime arguments
80
- * @returns The content of the manifest.json
81
- */
82
- export declare const getManifest: (args: string[]) => Promise<Manifest>;
83
- /**
84
- * Gets the minUI5Version from the manifest.json.
85
- *
86
- * @param args list of runtime args
87
- * @returns The minUI5Version from manifest.json or undefined otherwise
88
- */
89
- export declare function getUI5VersionFromManifest(args: string[]): Promise<string | undefined>;
90
76
  /**
91
77
  * Determines which UI5 version to use when previewing the application.
92
78
  *
93
79
  * @param version ui5 version as defined in the yaml or via cli argument
94
80
  * @param log logger for outputing information from where ui5 version config is coming
81
+ * @param manifest optional already loaded manifest.json
95
82
  * @returns The UI5 version with which the application will be started
96
83
  */
97
- export declare function resolveUI5Version(version?: string, log?: ToolsLogger): Promise<string>;
84
+ export declare function resolveUI5Version(version?: string, log?: ToolsLogger, manifest?: Manifest): Promise<string>;
98
85
  /**
99
86
  * Injects the absolute UI5 urls into the html file, which is used to preview the application.
100
87
  *
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.proxyErrorHandler = exports.filterCompressedHtmlFiles = exports.injectScripts = exports.injectUI5Url = exports.resolveUI5Version = exports.getUI5VersionFromManifest = exports.getManifest = exports.setHtmlResponse = exports.getWebAppFolderFromYaml = exports.getYamlFile = exports.getHtmlFile = exports.updateProxyEnv = exports.hideProxyCredentials = exports.getCorporateProxyServer = exports.proxyRequestHandler = exports.proxyResponseHandler = void 0;
12
+ exports.proxyErrorHandler = exports.filterCompressedHtmlFiles = exports.injectScripts = exports.injectUI5Url = exports.resolveUI5Version = exports.setHtmlResponse = exports.getWebAppFolderFromYaml = exports.getYamlFile = exports.getHtmlFile = exports.updateProxyEnv = exports.hideProxyCredentials = exports.getCorporateProxyServer = exports.proxyRequestHandler = exports.proxyResponseHandler = void 0;
13
13
  const ui5_config_1 = require("@sap-ux/ui5-config");
14
14
  const fs_1 = require("fs");
15
15
  const path_1 = require("path");
@@ -99,8 +99,8 @@ function updateProxyEnv(proxyFromConfig) {
99
99
  }
100
100
  });
101
101
  if (proxyFromArgs || process.env.FIORI_TOOLS_PROXY) {
102
- process.env.npm_config_proxy = proxyFromArgs || process.env.FIORI_TOOLS_PROXY;
103
- process.env.npm_config_https_proxy = proxyFromArgs || process.env.FIORI_TOOLS_PROXY;
102
+ process.env['npm_config_proxy'] = proxyFromArgs || process.env.FIORI_TOOLS_PROXY;
103
+ process.env['npm_config_https_proxy'] = proxyFromArgs || process.env.FIORI_TOOLS_PROXY;
104
104
  }
105
105
  else {
106
106
  const proxyFromEnv = process.env.npm_config_proxy ||
@@ -110,8 +110,8 @@ function updateProxyEnv(proxyFromConfig) {
110
110
  process.env.https_proxy ||
111
111
  process.env.HTTPS_PROXY;
112
112
  if (!proxyFromEnv && proxyFromConfig) {
113
- process.env.npm_config_proxy = proxyFromConfig;
114
- process.env.npm_config_https_proxy = proxyFromConfig;
113
+ process.env['npm_config_proxy'] = proxyFromConfig;
114
+ process.env['npm_config_https_proxy'] = proxyFromConfig;
115
115
  }
116
116
  }
117
117
  }
@@ -184,44 +184,16 @@ const setHtmlResponse = (res, html) => {
184
184
  }
185
185
  };
186
186
  exports.setHtmlResponse = setHtmlResponse;
187
- /**
188
- * Gets the manifest.json for a given application.
189
- *
190
- * @param args list of runtime arguments
191
- * @returns The content of the manifest.json
192
- */
193
- const getManifest = (args) => __awaiter(void 0, void 0, void 0, function* () {
194
- const projectRoot = process.cwd();
195
- const yamlFileName = (0, exports.getYamlFile)(args);
196
- const ui5YamlPath = (0, path_1.join)(projectRoot, yamlFileName);
197
- const webAppFolder = yield (0, exports.getWebAppFolderFromYaml)(ui5YamlPath);
198
- const manifestPath = (0, path_1.join)(projectRoot, webAppFolder, 'manifest.json');
199
- const manifest = JSON.parse((0, fs_1.readFileSync)(manifestPath, { encoding: 'utf8' }));
200
- return manifest;
201
- });
202
- exports.getManifest = getManifest;
203
- /**
204
- * Gets the minUI5Version from the manifest.json.
205
- *
206
- * @param args list of runtime args
207
- * @returns The minUI5Version from manifest.json or undefined otherwise
208
- */
209
- function getUI5VersionFromManifest(args) {
210
- var _a, _b;
211
- return __awaiter(this, void 0, void 0, function* () {
212
- const manifest = yield (0, exports.getManifest)(args);
213
- return (_b = (_a = manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.dependencies) === null || _b === void 0 ? void 0 : _b.minUI5Version;
214
- });
215
- }
216
- exports.getUI5VersionFromManifest = getUI5VersionFromManifest;
217
187
  /**
218
188
  * Determines which UI5 version to use when previewing the application.
219
189
  *
220
190
  * @param version ui5 version as defined in the yaml or via cli argument
221
191
  * @param log logger for outputing information from where ui5 version config is coming
192
+ * @param manifest optional already loaded manifest.json
222
193
  * @returns The UI5 version with which the application will be started
223
194
  */
224
- function resolveUI5Version(version, log) {
195
+ function resolveUI5Version(version, log, manifest) {
196
+ var _a, _b;
225
197
  return __awaiter(this, void 0, void 0, function* () {
226
198
  let ui5Version;
227
199
  let ui5VersionInfo;
@@ -235,7 +207,7 @@ function resolveUI5Version(version, log) {
235
207
  ui5VersionLocation = (0, exports.getYamlFile)(process.argv);
236
208
  }
237
209
  else {
238
- const minUI5Version = yield getUI5VersionFromManifest(process.argv);
210
+ const minUI5Version = (_b = (_a = manifest === null || manifest === void 0 ? void 0 : manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.dependencies) === null || _b === void 0 ? void 0 : _b.minUI5Version;
239
211
  ui5Version = minUI5Version && !isNaN(parseFloat(minUI5Version)) ? minUI5Version : '';
240
212
  ui5VersionLocation = 'manifest.json';
241
213
  }
package/dist/i18n.js CHANGED
@@ -46,5 +46,7 @@ function t(key, options) {
46
46
  return i18next_1.default.t(key, options);
47
47
  }
48
48
  exports.t = t;
49
- initI18n();
49
+ initI18n().catch(() => {
50
+ // Ignore any errors since the middleware will still work
51
+ });
50
52
  //# sourceMappingURL=i18n.js.map
@@ -46,13 +46,43 @@ function createRequestHandler(routes) {
46
46
  next();
47
47
  };
48
48
  }
49
- module.exports = ({ options }) => __awaiter(void 0, void 0, void 0, function* () {
49
+ /**
50
+ * Search the project for the manifest.json.
51
+ *
52
+ * @param rootProject @ui5/fs reader collection with access to the project files
53
+ * @returns manifest.json as object or undefined if not found
54
+ */
55
+ function loadManifest(rootProject) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ const files = yield rootProject.byGlob('**/manifest.json');
58
+ if ((files === null || files === void 0 ? void 0 : files.length) > 0) {
59
+ return JSON.parse(yield files[0].getString());
60
+ }
61
+ else {
62
+ return undefined;
63
+ }
64
+ });
65
+ }
66
+ module.exports = ({ resources, options }) => __awaiter(void 0, void 0, void 0, function* () {
67
+ var _a;
50
68
  const logger = new logger_1.ToolsLogger({
51
69
  transports: [new logger_1.UI5ToolingTransport({ moduleName: 'ui5-proxy-middleware' })]
52
70
  });
71
+ if (!((_a = options.configuration) === null || _a === void 0 ? void 0 : _a.ui5)) {
72
+ logger.error('Configuration missing, no proxy created.');
73
+ return (_req, _res, next) => next();
74
+ }
53
75
  dotenv_1.default.config();
54
76
  const config = options.configuration;
55
- const ui5Version = yield (0, base_1.resolveUI5Version)(config.version, logger);
77
+ let ui5Version = '';
78
+ try {
79
+ const manifest = yield loadManifest(resources.rootProject);
80
+ ui5Version = yield (0, base_1.resolveUI5Version)(config.version, logger, manifest);
81
+ }
82
+ catch (error) {
83
+ logger.warn('Retrieving UI5 version failed, using latest version instead.');
84
+ logger.debug(error);
85
+ }
56
86
  const envUI5Url = process.env.FIORI_TOOLS_UI5_URI;
57
87
  const directLoad = !!config.directLoad;
58
88
  const corporateProxyServer = (0, base_1.getCorporateProxyServer)(config.proxy);
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "bugs": {
10
10
  "url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Aui5-proxy-middleware"
11
11
  },
12
- "version": "1.1.26",
12
+ "version": "1.1.28",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -26,8 +26,8 @@
26
26
  "https-proxy-agent": "5.0.0",
27
27
  "i18next": "20.3.2",
28
28
  "proxy-from-env": "1.1.0",
29
- "@sap-ux/logger": "0.3.5",
30
- "@sap-ux/ui5-config": "0.17.0"
29
+ "@sap-ux/logger": "0.3.6",
30
+ "@sap-ux/ui5-config": "0.17.1"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/express": "4.17.13",
@@ -37,7 +37,7 @@
37
37
  "nock": "13.2.4",
38
38
  "supertest": "6.3.2",
39
39
  "yaml": "2.2.2",
40
- "@sap-ux/project-access": "1.7.0"
40
+ "@sap-ux/project-access": "1.8.1"
41
41
  },
42
42
  "ui5": {
43
43
  "dependencies": []