@sap-ux/preview-middleware 0.1.0 → 0.2.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.
package/README.md CHANGED
@@ -8,6 +8,8 @@ The `@sap-ux/preview-middleware` is a [Custom UI5 Server Middleware](https://sap
8
8
  | `flp` | | |Optional configuration object for the local Fiori launchpad |
9
9
  | `flp.path` | `string` | `/test/flp.html` | The mount point of the local Fiori launchpad. |
10
10
  | `flp.apps` | `array` | `[]` | Optional additional local apps that are available in local Fiori launchpad |
11
+ | `adp.target` | | | Required configuration for adaptation projects defining the connected backend
12
+ | `adp.ignoreCertErrors` | `boolean` | `false` | Optional setting to ignore certification validation errors when working with e.g. development systems with self signed certificates |
11
13
  | `debug` | `boolean` | false | Enables debug output |
12
14
 
13
15
  ### `flp.apps`
@@ -20,6 +22,14 @@ Array of additional application configurations:
20
22
  | `intent.object` | `string` | `(calculated)`| Optional intent object, if it is not provided then it will be calculated based on the application id |
21
23
  | `intent.action` | `string` | `preview` | Optional intent action |
22
24
 
25
+ ### `adp.target`
26
+ | Option | Type | Description |
27
+ | ------------- | ------------- | ----------- |
28
+ | `url` | `string` mandatory (local) | Mandatory URL pointing to the backend system. *Not required if destination is provided and the proxy is running SAP Business Application Studio |
29
+ | `destination` | `string` mandatory (if no url) | Required if the backend system is available as destination in SAP Business Application Studio. |
30
+ | `client` | `string` optional | sap-client parameter |
31
+ | `scp` | `boolean` optional | If set to true the proxy will execute the required OAuth routine for the ABAP environment on SAP BTP |
32
+
23
33
  ## Usage
24
34
  The middleware can be used without configuration. However, since the middleware intercepts a few requests that might otherwise be handled by a different middleware, it is strongly recommended to run other file serving middlewares after the `preview-middleware` e.g. `backend-proxy-middleware` and `ui5-proxy-middleware` (and the corresponding middlewares in the `@sap/ux-ui5-tooling`).
25
35
  Example: [./test/fixtures/simple-app/ui5.yaml](./test/fixtures/simple-app/ui5.yaml)
@@ -59,3 +69,17 @@ server:
59
69
  - local: ../local-folder
60
70
  target: /apps/other-app
61
71
  ```
72
+
73
+ ### Adaptation Project
74
+ If you want to use the middleware in an adaption project, the additional `adp` object needs to be configured. This example would preview a local adaptation project merged with its reference application from the target system at `http://sap.example` and it will ignore certification validation errors.
75
+ ```Yaml
76
+ server:
77
+ customMiddleware:
78
+ - name: preview-middleware
79
+ afterMiddleware: compression
80
+ configuration:
81
+ adp:
82
+ target:
83
+ url: http://sap.example
84
+ ignoreCertErrors: true
85
+ ```
@@ -38,7 +38,7 @@ export declare class FlpSandbox {
38
38
  private readonly utils;
39
39
  private readonly logger;
40
40
  protected templateConfig: TemplateConfig;
41
- protected readonly config: FlpConfig;
41
+ readonly config: FlpConfig;
42
42
  readonly router: any;
43
43
  /**
44
44
  * Constructor setting defaults and keeping reference to workspace resources.
@@ -53,8 +53,10 @@ export declare class FlpSandbox {
53
53
  * Initialize the FLP sandbox router.
54
54
  *
55
55
  * @param manifest application manifest
56
+ * @param componentId optional componentId e.g. for adaptation projects
57
+ * @param resources optional additional resource mappings
56
58
  */
57
- init(manifest: Manifest): Promise<void>;
59
+ init(manifest: Manifest, componentId?: string, resources?: Record<string, string>): Promise<void>;
58
60
  /**
59
61
  * Try finding the locate-reuse-libs script.
60
62
  *
package/dist/base/flp.js CHANGED
@@ -52,9 +52,11 @@ class FlpSandbox {
52
52
  * Initialize the FLP sandbox router.
53
53
  *
54
54
  * @param manifest application manifest
55
+ * @param componentId optional componentId e.g. for adaptation projects
56
+ * @param resources optional additional resource mappings
55
57
  */
56
- init(manifest) {
57
- var _a, _b, _c, _d, _e;
58
+ init(manifest, componentId, resources = {}) {
59
+ var _a, _b, _c, _d, _e, _f;
58
60
  return __awaiter(this, void 0, void 0, function* () {
59
61
  const flex = this.createFlexHandler();
60
62
  const supportedThemes = (_b = (_a = manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.supportedThemes) !== null && _b !== void 0 ? _b : [DEFAULT_THEME];
@@ -64,12 +66,13 @@ class FlpSandbox {
64
66
  libs: Object.keys((_e = (_d = (_c = manifest['sap.ui5']) === null || _c === void 0 ? void 0 : _c.dependencies) === null || _d === void 0 ? void 0 : _d.libs) !== null && _e !== void 0 ? _e : {}).join(','),
65
67
  theme: supportedThemes.includes(DEFAULT_THEME) ? DEFAULT_THEME : supportedThemes[0],
66
68
  flex,
67
- resources: {}
69
+ resources: Object.assign({}, resources)
68
70
  },
69
71
  locateReuseLibsScript: yield this.findLocateReuseLibsScript()
70
72
  };
71
73
  this.addApp(manifest, {
72
- target: '/',
74
+ componentId,
75
+ target: (_f = resources[componentId !== null && componentId !== void 0 ? componentId : manifest['sap.app'].id]) !== null && _f !== void 0 ? _f : '/',
73
76
  local: '.',
74
77
  intent: {
75
78
  object: 'app',
@@ -80,11 +83,12 @@ class FlpSandbox {
80
83
  this.router.get(this.config.path, (req, res) => {
81
84
  var _a, _b;
82
85
  const config = Object.assign({}, this.templateConfig);
83
- if (req.query['fiori-tools-rta-mode']) {
86
+ const fioriToolsRtaMode = req.query['fiori-tools-rta-mode'];
87
+ if (fioriToolsRtaMode) {
84
88
  if ((_a = this.config.rta) === null || _a === void 0 ? void 0 : _a.layer) {
85
89
  config.flex = {
86
90
  layer: (_b = this.config.rta) === null || _b === void 0 ? void 0 : _b.layer,
87
- developerMode: false
91
+ developerMode: fioriToolsRtaMode === 'forAdaptation'
88
92
  };
89
93
  }
90
94
  else {
@@ -195,7 +199,7 @@ class FlpSandbox {
195
199
  * @param app configuration for the preview
196
200
  */
197
201
  addApp(manifest, app) {
198
- var _a, _b, _c, _d, _e;
202
+ var _a, _b, _c, _d, _e, _f;
199
203
  const id = manifest['sap.app'].id;
200
204
  (_a = app.intent) !== null && _a !== void 0 ? _a : (app.intent = {
201
205
  object: id.replace(/\./g, ''),
@@ -205,7 +209,7 @@ class FlpSandbox {
205
209
  this.templateConfig.apps[`${(_b = app.intent) === null || _b === void 0 ? void 0 : _b.object}-${(_c = app.intent) === null || _c === void 0 ? void 0 : _c.action}`] = {
206
210
  title: (_d = manifest['sap.app'].title) !== null && _d !== void 0 ? _d : id,
207
211
  description: (_e = manifest['sap.app'].description) !== null && _e !== void 0 ? _e : '',
208
- additionalInformation: `SAPUI5.Component=${id}`,
212
+ additionalInformation: `SAPUI5.Component=${(_f = app.componentId) !== null && _f !== void 0 ? _f : id}`,
209
213
  applicationType: 'URL',
210
214
  url: app.target
211
215
  };
@@ -1,3 +1,4 @@
1
+ import type { AdpPreviewConfig } from '@sap-ux/adp-tooling';
1
2
  import type { UI5FlexLayer } from '@sap-ux/project-access';
2
3
  /**
3
4
  * Configuration for additional applications
@@ -5,6 +6,10 @@ import type { UI5FlexLayer } from '@sap-ux/project-access';
5
6
  export interface App {
6
7
  target: string;
7
8
  local: string;
9
+ /**
10
+ * Optional component id if it differs from the manifest (e.g. for adaptation projects)
11
+ */
12
+ componentId?: string;
8
13
  intent?: {
9
14
  object: string;
10
15
  action: string;
@@ -25,6 +30,7 @@ export interface FlpConfig {
25
30
  */
26
31
  export interface Config {
27
32
  flp?: Partial<FlpConfig>;
33
+ adp?: AdpPreviewConfig;
28
34
  debug?: boolean;
29
35
  }
30
36
  //# sourceMappingURL=index.d.ts.map
@@ -11,6 +11,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const logger_1 = require("@sap-ux/logger");
13
13
  const flp_1 = require("../base/flp");
14
+ const adp_tooling_1 = require("@sap-ux/adp-tooling");
15
+ /**
16
+ * Initialize the preview for an adaptation project.
17
+ *
18
+ * @param rootProject reference to the project
19
+ * @param config configuration from the ui5.yaml
20
+ * @param flp FlpSandbox instance
21
+ * @param logger logger instance
22
+ */
23
+ function initAdp(rootProject, config, flp, logger) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const files = yield rootProject.byGlob('/manifest.appdescr_variant');
26
+ if (files.length === 1) {
27
+ const adp = new adp_tooling_1.AdpPreview(config, logger);
28
+ const layer = yield adp.init(JSON.parse(yield files[0].getString()), yield rootProject.byGlob('**/*.*'));
29
+ flp.config.rta = { layer };
30
+ yield flp.init(adp.descriptor.manifest, adp.descriptor.name, adp.resources);
31
+ flp.router.use(adp.descriptor.url, adp.proxy.bind(adp));
32
+ }
33
+ else {
34
+ throw new Error('ADP configured but no manifest.appdescr_variant found.');
35
+ }
36
+ });
37
+ }
14
38
  /**
15
39
  * Create the router that is to be exposed as UI5 middleware.
16
40
  *
@@ -29,12 +53,17 @@ function createRouter({ resources, options, middlewareUtil }, logger) {
29
53
  (_b = config.flp) !== null && _b !== void 0 ? _b : (config.flp = {});
30
54
  // configure the FLP sandbox based on information from the manifest
31
55
  const flp = new flp_1.FlpSandbox(config.flp, resources.rootProject, middlewareUtil, logger);
32
- const files = yield resources.rootProject.byGlob('/manifest.json');
33
- if (files.length === 1) {
34
- yield flp.init(JSON.parse(yield files[0].getString()));
56
+ if (config.adp) {
57
+ yield initAdp(resources.rootProject, config.adp, flp, logger);
35
58
  }
36
59
  else {
37
- throw new Error('No manifest.json found.');
60
+ const files = yield resources.rootProject.byGlob('/manifest.json');
61
+ if (files.length === 1) {
62
+ yield flp.init(JSON.parse(yield files[0].getString()));
63
+ }
64
+ else {
65
+ throw new Error('No manifest.json found.');
66
+ }
38
67
  }
39
68
  return flp.router;
40
69
  });
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.1.0",
12
+ "version": "0.2.0",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -23,15 +23,19 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "ejs": "3.1.7",
26
- "@sap-ux/logger": "0.3.7"
26
+ "@sap-ux/logger": "0.3.7",
27
+ "@sap-ux/adp-tooling": "0.1.0"
27
28
  },
28
29
  "devDependencies": {
29
30
  "@types/ejs": "3.1.0",
30
31
  "@types/express": "4.17.13",
32
+ "@types/prompts": "2.0.14",
31
33
  "@types/supertest": "2.0.12",
32
34
  "express": "4.18.2",
35
+ "nock": "13.2.1",
33
36
  "supertest": "6.3.2",
34
- "@sap-ux/project-access": "1.10.0"
37
+ "@sap-ux/project-access": "1.10.1",
38
+ "@sap-ux/store": "0.3.12"
35
39
  },
36
40
  "peerDependencies": {
37
41
  "express": "4"