@sap-ux/ui5-proxy-middleware 1.3.15 → 1.4.0

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,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  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
4
  const ui5_config_1 = require("@sap-ux/ui5-config");
@@ -157,16 +148,15 @@ exports.getYamlFile = getYamlFile;
157
148
  * @param ui5YamlPath - path to the yaml file
158
149
  * @returns Path to the webapp folder
159
150
  */
160
- const getWebAppFolderFromYaml = (ui5YamlPath) => __awaiter(void 0, void 0, void 0, function* () {
161
- var _a, _b;
151
+ const getWebAppFolderFromYaml = async (ui5YamlPath) => {
162
152
  if ((0, fs_1.existsSync)(ui5YamlPath)) {
163
- const ui5Config = yield ui5_config_1.UI5Config.newInstance((0, fs_1.readFileSync)(ui5YamlPath, { encoding: 'utf8' }));
164
- return (_b = (_a = ui5Config.getConfiguration().paths) === null || _a === void 0 ? void 0 : _a.webapp) !== null && _b !== void 0 ? _b : 'webapp';
153
+ const ui5Config = await ui5_config_1.UI5Config.newInstance((0, fs_1.readFileSync)(ui5YamlPath, { encoding: 'utf8' }));
154
+ return ui5Config.getConfiguration().paths?.webapp ?? 'webapp';
165
155
  }
166
156
  else {
167
157
  return 'webapp';
168
158
  }
169
- });
159
+ };
170
160
  exports.getWebAppFolderFromYaml = getWebAppFolderFromYaml;
171
161
  /**
172
162
  * Sends HTML content as a response.
@@ -196,31 +186,28 @@ exports.setHtmlResponse = setHtmlResponse;
196
186
  * @param manifest optional already loaded manifest.json
197
187
  * @returns The UI5 version with which the application will be started
198
188
  */
199
- function resolveUI5Version(version, log, manifest) {
200
- var _a, _b;
201
- return __awaiter(this, void 0, void 0, function* () {
202
- let ui5Version;
203
- let ui5VersionInfo;
204
- let ui5VersionLocation;
205
- if (process.env.FIORI_TOOLS_UI5_VERSION || process.env.FIORI_TOOLS_UI5_VERSION === '') {
206
- ui5Version = process.env.FIORI_TOOLS_UI5_VERSION;
207
- ui5VersionLocation = 'CLI arguments / Run configuration';
208
- }
209
- else if (version !== undefined) {
210
- ui5Version = version ? version : '';
211
- ui5VersionLocation = (0, exports.getYamlFile)(process.argv);
212
- }
213
- else {
214
- 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;
215
- ui5Version = minUI5Version && !isNaN(parseFloat(minUI5Version)) ? minUI5Version : '';
216
- ui5VersionLocation = 'manifest.json';
217
- }
218
- if (log) {
219
- ui5VersionInfo = ui5Version ? ui5Version : 'latest';
220
- log.info((0, i18n_1.t)('info.ui5VersionSource', { version: ui5VersionInfo, source: ui5VersionLocation }));
221
- }
222
- return ui5Version;
223
- });
189
+ async function resolveUI5Version(version, log, manifest) {
190
+ let ui5Version;
191
+ let ui5VersionInfo;
192
+ let ui5VersionLocation;
193
+ if (process.env.FIORI_TOOLS_UI5_VERSION || process.env.FIORI_TOOLS_UI5_VERSION === '') {
194
+ ui5Version = process.env.FIORI_TOOLS_UI5_VERSION;
195
+ ui5VersionLocation = 'CLI arguments / Run configuration';
196
+ }
197
+ else if (version !== undefined) {
198
+ ui5Version = version ? version : '';
199
+ ui5VersionLocation = (0, exports.getYamlFile)(process.argv);
200
+ }
201
+ else {
202
+ const minUI5Version = manifest?.['sap.ui5']?.dependencies?.minUI5Version;
203
+ ui5Version = minUI5Version && !isNaN(parseFloat(minUI5Version)) ? minUI5Version : '';
204
+ ui5VersionLocation = 'manifest.json';
205
+ }
206
+ if (log) {
207
+ ui5VersionInfo = ui5Version ? ui5Version : 'latest';
208
+ log.info((0, i18n_1.t)('info.ui5VersionSource', { version: ui5VersionInfo, source: ui5VersionLocation }));
209
+ }
210
+ return ui5Version;
224
211
  }
225
212
  exports.resolveUI5Version = resolveUI5Version;
226
213
  /**
@@ -260,14 +247,14 @@ exports.injectUI5Url = injectUI5Url;
260
247
  * @param next - the next function, used to forward the request to the next available handler
261
248
  * @param ui5Configs - the UI5 configuration of the ui5-proxy-middleware
262
249
  */
263
- const injectScripts = (req, res, next, ui5Configs) => __awaiter(void 0, void 0, void 0, function* () {
250
+ const injectScripts = async (req, res, next, ui5Configs) => {
264
251
  try {
265
252
  const projectRoot = process.cwd();
266
253
  const args = process.argv;
267
254
  const htmlFileName = (0, exports.getHtmlFile)(req.baseUrl);
268
255
  const yamlFileName = (0, exports.getYamlFile)(args);
269
256
  const ui5YamlPath = (0, path_1.join)(projectRoot, yamlFileName);
270
- const webAppFolder = yield (0, exports.getWebAppFolderFromYaml)(ui5YamlPath);
257
+ const webAppFolder = await (0, exports.getWebAppFolderFromYaml)(ui5YamlPath);
271
258
  const htmlFilePath = (0, path_1.join)(projectRoot, webAppFolder, htmlFileName);
272
259
  const html = injectUI5Url(htmlFilePath, ui5Configs);
273
260
  if (html) {
@@ -280,7 +267,7 @@ const injectScripts = (req, res, next, ui5Configs) => __awaiter(void 0, void 0,
280
267
  catch (error) {
281
268
  next(error);
282
269
  }
283
- });
270
+ };
284
271
  exports.injectScripts = injectScripts;
285
272
  /**
286
273
  * Filters comressed html files from UI5 CDN.
@@ -310,8 +297,7 @@ exports.filterCompressedHtmlFiles = filterCompressedHtmlFiles;
310
297
  * @param _target (not used)
311
298
  */
312
299
  function proxyErrorHandler(err, req, logger, _res, _target) {
313
- var _a;
314
- if (err && ((_a = err.stack) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== 'error') {
300
+ if (err && err.stack?.toLowerCase() !== 'error') {
315
301
  if (typeof req.next === 'function') {
316
302
  req.next(err);
317
303
  }
package/dist/i18n.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -19,19 +10,17 @@ const NS = 'ui5-proxy-middleware';
19
10
  /**
20
11
  * Initialize i18next with the translations for this module.
21
12
  */
22
- function initI18n() {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- yield i18next_1.default.init({
25
- resources: {
26
- en: {
27
- [NS]: ui5_proxy_middleware_i18n_json_1.default
28
- }
29
- },
30
- lng: 'en',
31
- fallbackLng: 'en',
32
- defaultNS: NS,
33
- ns: [NS]
34
- });
13
+ async function initI18n() {
14
+ await i18next_1.default.init({
15
+ resources: {
16
+ en: {
17
+ [NS]: ui5_proxy_middleware_i18n_json_1.default
18
+ }
19
+ },
20
+ lng: 'en',
21
+ fallbackLng: 'en',
22
+ defaultNS: NS,
23
+ ns: [NS]
35
24
  });
36
25
  }
37
26
  exports.initI18n = initI18n;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -49,30 +40,31 @@ function createRequestHandler(routes) {
49
40
  * @param rootProject @ui5/fs reader collection with access to the project files
50
41
  * @returns manifest.json as object or undefined if not found
51
42
  */
52
- function loadManifest(rootProject) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- const files = yield rootProject.byGlob('**/manifest.json');
55
- if ((files === null || files === void 0 ? void 0 : files.length) > 0) {
56
- return JSON.parse(yield files[0].getString());
57
- }
58
- else {
59
- return undefined;
60
- }
61
- });
43
+ async function loadManifest(rootProject) {
44
+ const files = await rootProject.byGlob('**/manifest.json');
45
+ if (files?.length > 0) {
46
+ return JSON.parse(await files[0].getString());
47
+ }
48
+ else {
49
+ return undefined;
50
+ }
62
51
  }
63
- module.exports = ({ resources, options }) => __awaiter(void 0, void 0, void 0, function* () {
52
+ module.exports = async ({ resources, options }) => {
64
53
  const logger = new logger_1.ToolsLogger({
65
54
  transports: [new logger_1.UI5ToolingTransport({ moduleName: 'ui5-proxy-middleware' })]
66
55
  });
67
56
  dotenv_1.default.config();
68
- const config = Object.assign({ ui5: {
57
+ const config = {
58
+ ui5: {
69
59
  path: ['/resources', '/test-resources'],
70
60
  url: 'https://ui5.sap.com'
71
- } }, options.configuration);
61
+ },
62
+ ...options.configuration
63
+ };
72
64
  let ui5Version = '';
73
65
  try {
74
- const manifest = yield loadManifest(resources.rootProject);
75
- ui5Version = yield (0, base_1.resolveUI5Version)(config.version, logger, manifest);
66
+ const manifest = await loadManifest(resources.rootProject);
67
+ ui5Version = await (0, base_1.resolveUI5Version)(config.version, logger, manifest);
76
68
  }
77
69
  catch (error) {
78
70
  logger.warn('Retrieving UI5 version failed, using latest version instead.');
@@ -102,19 +94,19 @@ module.exports = ({ resources, options }) => __awaiter(void 0, void 0, void 0, f
102
94
  }
103
95
  }
104
96
  if (directLoad) {
105
- const directLoadProxy = ((req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
97
+ const directLoadProxy = (async (req, res, next) => {
106
98
  try {
107
- yield (0, base_1.injectScripts)(req, res, next, ui5Configs);
99
+ await (0, base_1.injectScripts)(req, res, next, ui5Configs);
108
100
  }
109
101
  catch (error) {
110
102
  logger.error(error);
111
103
  next(error);
112
104
  }
113
- }));
105
+ });
114
106
  base_1.HTML_MOUNT_PATHS.forEach((path) => {
115
107
  routes.push({ route: path, handler: directLoadProxy });
116
108
  });
117
109
  }
118
110
  return createRequestHandler(routes);
119
- });
111
+ };
120
112
  //# sourceMappingURL=middleware.js.map
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.3.15",
12
+ "version": "1.4.0",
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.1",
27
27
  "i18next": "20.6.1",
28
28
  "proxy-from-env": "1.1.0",
29
- "@sap-ux/logger": "0.5.1",
30
- "@sap-ux/ui5-config": "0.22.9"
29
+ "@sap-ux/logger": "0.6.0",
30
+ "@sap-ux/ui5-config": "0.23.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/express": "4.17.21",
@@ -37,7 +37,7 @@
37
37
  "nock": "13.4.0",
38
38
  "supertest": "6.3.3",
39
39
  "yaml": "2.2.2",
40
- "@sap-ux/project-access": "1.22.2"
40
+ "@sap-ux/project-access": "1.23.0"
41
41
  },
42
42
  "ui5": {
43
43
  "dependencies": []