@sap-ux/preview-middleware 0.5.6 → 0.6.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.
@@ -3,38 +3,6 @@
3
3
  sap.ui.define(["sap/base/Log", "sap/ui/core/IconPool", "sap/base/i18n/ResourceBundle", "sap/base/util/UriParameters"], function (Log, IconPool, ResourceBundle, UriParameters) {
4
4
  "use strict";
5
5
 
6
- /**
7
- * Fetch the manifest from the given application urls, then parse them for custom libs, and finally request their urls.
8
- *
9
- * @param appUrls application urls
10
- * @returns returns a promise when the registration is completed.
11
- */
12
- const registerComponentDependencyPaths = function (appUrls) {
13
- try {
14
- return Promise.resolve(getManifestLibs(appUrls)).then(function (libs) {
15
- const _temp = function () {
16
- if (libs && libs.length > 0) {
17
- let url = '/sap/bc/ui2/app_index/ui5_app_info?id=' + libs;
18
- const sapClient = UriParameters.fromQuery(window.location.search).get('sap-client');
19
- if (sapClient && sapClient.length === 3) {
20
- url = url + '&sap-client=' + sapClient;
21
- }
22
- return Promise.resolve(fetch(url)).then(function (response) {
23
- return Promise.resolve(response.json()).then(function (_response$json) {
24
- registerModules(_response$json);
25
- });
26
- });
27
- }
28
- }();
29
- if (_temp && _temp.then) return _temp.then(function () {});
30
- });
31
- } catch (e) {
32
- return Promise.reject(e);
33
- }
34
- };
35
- /**
36
- * Register SAP fonts that are also registered in a productive Fiori launchpad.
37
- */
38
6
  /**
39
7
  * SAPUI5 delivered namespaces from https://ui5.sap.com/#/api/sap
40
8
  */
@@ -67,25 +35,20 @@ sap.ui.define(["sap/base/Log", "sap/ui/core/IconPool", "sap/base/i18n/ResourceBu
67
35
  const result = {};
68
36
  const promises = [];
69
37
  for (const url of appUrls) {
70
- promises.push(fetch(`${url}/manifest.json`).then(function (resp) {
71
- try {
72
- return Promise.resolve(resp.json()).then(function (manifest) {
73
- if (manifest) {
74
- if (manifest['sap.ui5'] && manifest['sap.ui5'].dependencies) {
75
- if (manifest['sap.ui5'].dependencies.libs) {
76
- addKeys(manifest['sap.ui5'].dependencies.libs, result);
77
- }
78
- if (manifest['sap.ui5'].dependencies.components) {
79
- addKeys(manifest['sap.ui5'].dependencies.components, result);
80
- }
81
- }
82
- if (manifest['sap.ui5'] && manifest['sap.ui5'].componentUsages) {
83
- addKeys(manifest['sap.ui5'].componentUsages, result);
84
- }
38
+ promises.push(fetch(`${url}/manifest.json`).then(async resp => {
39
+ const manifest = await resp.json();
40
+ if (manifest) {
41
+ if (manifest['sap.ui5'] && manifest['sap.ui5'].dependencies) {
42
+ if (manifest['sap.ui5'].dependencies.libs) {
43
+ addKeys(manifest['sap.ui5'].dependencies.libs, result);
85
44
  }
86
- });
87
- } catch (e) {
88
- return Promise.reject(e);
45
+ if (manifest['sap.ui5'].dependencies.components) {
46
+ addKeys(manifest['sap.ui5'].dependencies.components, result);
47
+ }
48
+ }
49
+ if (manifest['sap.ui5'] && manifest['sap.ui5'].componentUsages) {
50
+ addKeys(manifest['sap.ui5'].componentUsages, result);
51
+ }
89
52
  }
90
53
  }));
91
54
  }
@@ -115,6 +78,29 @@ sap.ui.define(["sap/base/Log", "sap/ui/core/IconPool", "sap/base/i18n/ResourceBu
115
78
  }
116
79
  });
117
80
  }
81
+
82
+ /**
83
+ * Fetch the manifest from the given application urls, then parse them for custom libs, and finally request their urls.
84
+ *
85
+ * @param appUrls application urls
86
+ * @returns returns a promise when the registration is completed.
87
+ */
88
+ async function registerComponentDependencyPaths(appUrls) {
89
+ const libs = await getManifestLibs(appUrls);
90
+ if (libs && libs.length > 0) {
91
+ let url = '/sap/bc/ui2/app_index/ui5_app_info?id=' + libs;
92
+ const sapClient = UriParameters.fromQuery(window.location.search).get('sap-client');
93
+ if (sapClient && sapClient.length === 3) {
94
+ url = url + '&sap-client=' + sapClient;
95
+ }
96
+ const response = await fetch(url);
97
+ registerModules(await response.json());
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Register SAP fonts that are also registered in a productive Fiori launchpad.
103
+ */
118
104
  function registerSAPFonts() {
119
105
  //Fiori Theme font family and URI
120
106
  const fioriTheme = {
@@ -159,30 +145,25 @@ sap.ui.define(["sap/base/Log", "sap/ui/core/IconPool", "sap/base/i18n/ResourceBu
159
145
  } = _ref;
160
146
  // Register RTA if configured
161
147
  if (flex) {
162
- sap.ushell.Container.attachRendererCreatedEvent(function () {
163
- try {
164
- return Promise.resolve(sap.ushell.Container.getServiceAsync('AppLifeCycle')).then(function (serviceInstance) {
165
- serviceInstance.attachAppLoaded(event => {
166
- const oView = event.getParameter('componentInstance');
167
- const requiredLibs = ['sap/ui/rta/api/startAdaptation'];
168
- const flexSettings = JSON.parse(flex);
169
- if (flexSettings.pluginScript) {
170
- requiredLibs.push(flexSettings.pluginScript);
171
- delete flexSettings.pluginScript;
172
- }
173
- sap.ui.require(requiredLibs, function (startAdaptation, pluginScript) {
174
- const options = {
175
- rootControl: oView,
176
- validateAppVersion: false,
177
- flexSettings
178
- };
179
- startAdaptation(options, pluginScript);
180
- });
181
- });
148
+ sap.ushell.Container.attachRendererCreatedEvent(async function () {
149
+ const serviceInstance = await sap.ushell.Container.getServiceAsync('AppLifeCycle');
150
+ serviceInstance.attachAppLoaded(event => {
151
+ const oView = event.getParameter('componentInstance');
152
+ const requiredLibs = ['sap/ui/rta/api/startAdaptation'];
153
+ const flexSettings = JSON.parse(flex);
154
+ if (flexSettings.pluginScript) {
155
+ requiredLibs.push(flexSettings.pluginScript);
156
+ delete flexSettings.pluginScript;
157
+ }
158
+ sap.ui.require(requiredLibs, function (startAdaptation, pluginScript) {
159
+ const options = {
160
+ rootControl: oView,
161
+ validateAppVersion: false,
162
+ flexSettings
163
+ };
164
+ startAdaptation(options, pluginScript);
182
165
  });
183
- } catch (e) {
184
- return Promise.reject(e);
185
- }
166
+ });
186
167
  });
187
168
  }
188
169
 
@@ -18,17 +18,17 @@ const adp_tooling_1 = require("@sap-ux/adp-tooling");
18
18
  * @param rootProject reference to the project
19
19
  * @param config configuration from the ui5.yaml
20
20
  * @param flp FlpSandbox instance
21
+ * @param util middleware utilities provided by the UI5 CLI
21
22
  * @param logger logger instance
22
23
  */
23
- function initAdp(rootProject, config, flp, logger) {
24
+ function initAdp(rootProject, config, flp, util, logger) {
24
25
  var _a;
25
26
  return __awaiter(this, void 0, void 0, function* () {
26
27
  const appVariant = yield rootProject.byPath('/manifest.appdescr_variant');
27
28
  if (appVariant) {
28
- const adp = new adp_tooling_1.AdpPreview(config, rootProject, logger);
29
+ const adp = new adp_tooling_1.AdpPreview(config, rootProject, util, logger);
29
30
  const variant = JSON.parse(yield appVariant.getString());
30
31
  const layer = yield adp.init(variant);
31
- logger.warn(variant);
32
32
  if (flp.rta) {
33
33
  flp.rta.layer = layer;
34
34
  flp.rta.options = {
@@ -40,6 +40,7 @@ function initAdp(rootProject, config, flp, logger) {
40
40
  }
41
41
  yield flp.init(adp.descriptor.manifest, adp.descriptor.name, adp.resources);
42
42
  flp.router.use(adp.descriptor.url, adp.proxy.bind(adp));
43
+ adp.addApis(flp.router);
43
44
  }
44
45
  else {
45
46
  throw new Error('ADP configured but no manifest.appdescr_variant found.');
@@ -65,7 +66,7 @@ function createRouter({ resources, options, middlewareUtil }, logger) {
65
66
  // configure the FLP sandbox based on information from the manifest
66
67
  const flp = new flp_1.FlpSandbox(config, resources.rootProject, middlewareUtil, logger);
67
68
  if (config.adp) {
68
- yield initAdp(resources.rootProject, config.adp, flp, logger);
69
+ yield initAdp(resources.rootProject, config.adp, flp, middlewareUtil, logger);
69
70
  }
70
71
  else {
71
72
  const manifest = yield resources.rootProject.byPath('/manifest.json');
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%3Apreview-middleware"
11
11
  },
12
- "version": "0.5.6",
12
+ "version": "0.6.0",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -23,8 +23,8 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "ejs": "3.1.9",
26
- "@sap-ux/logger": "0.3.7",
27
- "@sap-ux/adp-tooling": "0.2.4"
26
+ "@sap-ux/logger": "0.3.8",
27
+ "@sap-ux/adp-tooling": "0.3.0"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/ejs": "3.1.2",
@@ -36,9 +36,9 @@
36
36
  "express": "4.18.2",
37
37
  "nock": "13.2.1",
38
38
  "supertest": "6.3.3",
39
- "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.1.1",
40
- "@sap-ux/project-access": "1.13.5",
41
- "@sap-ux/store": "0.3.13"
39
+ "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.2.0",
40
+ "@sap-ux/project-access": "1.13.6",
41
+ "@sap-ux/store": "0.3.14"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "express": "4"
@@ -53,7 +53,7 @@
53
53
  "build:middleware": "tsc --build",
54
54
  "build:client": "pnpm -C ../preview-middleware-client run build && copyfiles --exclude **/*-dbg.js --up 4 \"./node_modules/@private/preview-middleware-client/dist/**/*\" \"./dist/client\"",
55
55
  "watch": "tsc --watch",
56
- "clean": "rimraf dist test/test-output coverage *.tsbuildinfo",
56
+ "clean": "rimraf --glob dist test/test-output coverage *.tsbuildinfo",
57
57
  "format": "prettier --write '**/*.{js,json,ts,yaml,yml}' --ignore-path ../../.prettierignore",
58
58
  "lint": "eslint . --ext .ts",
59
59
  "lint:fix": "eslint . --ext .ts --fix",