@sap-ux/preview-middleware 0.1.0 → 0.3.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
@@ -3,22 +3,35 @@
3
3
  The `@sap-ux/preview-middleware` is a [Custom UI5 Server Middleware](https://sap.github.io/ui5-tooling/pages/extensibility/CustomServerMiddleware) for previewing an application in a local Fiori launchpad . It can be used either with the `ui5 serve` or the `fiori run` commands.
4
4
 
5
5
  ## Configuration Options
6
- | Option | Type | Default Value | Description |
7
- | ------------ | ------| ------------- | ----------- |
8
- | `flp` | | |Optional configuration object for the local Fiori launchpad |
9
- | `flp.path` | `string` | `/test/flp.html` | The mount point of the local Fiori launchpad. |
10
- | `flp.apps` | `array` | `[]` | Optional additional local apps that are available in local Fiori launchpad |
11
- | `debug` | `boolean` | false | Enables debug output |
6
+ | Option | Type | Default Value | Description |
7
+ | ---------------------- | --------- | ---------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
8
+ | `flp` | | | Optional configuration object for the local Fiori launchpad |
9
+ | `flp.path` | `string` | `/test/flp.html` | The mount point of the local Fiori launchpad. |
10
+ | `flp.intent` | | | Optional intent to be used for the application |
11
+ | `flp.intent.object` | `string` | `app` | Optional intent object |
12
+ | `flp.intent.action` | `string` | `preview` | Optional intent action |
13
+ | `flp.apps` | `array` | `[]` | Optional additional local apps that are available in local Fiori launchpad |
14
+ | `adp.target` | | | Required configuration for adaptation projects defining the connected backend |
15
+ | `adp.ignoreCertErrors` | `boolean` | `false` | Optional setting to ignore certification validation errors when working with e.g. development systems with self signed certificates |
16
+ | `debug` | `boolean` | false | Enables debug output |
12
17
 
13
18
  ### `flp.apps`
14
19
  Array of additional application configurations:
15
- | Option | Type | Default Value | Description |
16
- | ------------ | ------| ------------- | ----------- |
17
- | `target` | `string` | | Target path of the additional application |
18
- | `local` | `string` | | Local path to the folder containing the application |
19
- | `intent` | | | Optional intent to be used for the application |
20
- | `intent.object` | `string` | `(calculated)`| Optional intent object, if it is not provided then it will be calculated based on the application id |
21
- | `intent.action` | `string` | `preview` | Optional intent action |
20
+ | Option | Type | Default Value | Description |
21
+ | --------------- | -------- | -------------- | ---------------------------------------------------------------------------------------------------- |
22
+ | `target` | `string` | | Target path of the additional application |
23
+ | `local` | `string` | | Local path to the folder containing the application |
24
+ | `intent` | | | Optional intent to be used for the application |
25
+ | `intent.object` | `string` | `(calculated)` | Optional intent object, if it is not provided then it will be calculated based on the application id |
26
+ | `intent.action` | `string` | `preview` | Optional intent action |
27
+
28
+ ### `adp.target`
29
+ | Option | Type | Description |
30
+ | ------------- | ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
31
+ | `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 |
32
+ | `destination` | `string` mandatory (if no url) | Required if the backend system is available as destination in SAP Business Application Studio. |
33
+ | `client` | `string` optional | sap-client parameter |
34
+ | `scp` | `boolean` optional | If set to true the proxy will execute the required OAuth routine for the ABAP environment on SAP BTP |
22
35
 
23
36
  ## Usage
24
37
  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`).
@@ -59,3 +72,32 @@ server:
59
72
  - local: ../local-folder
60
73
  target: /apps/other-app
61
74
  ```
75
+
76
+ ### Adaptation Project
77
+ 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.
78
+ ```Yaml
79
+ server:
80
+ customMiddleware:
81
+ - name: preview-middleware
82
+ afterMiddleware: compression
83
+ configuration:
84
+ adp:
85
+ target:
86
+ url: http://sap.example
87
+ ignoreCertErrors: true
88
+ ```
89
+ ### Programmatic Usage
90
+ Alternatively you can use the underlying middleware fuction programmatically, e.g. for the case when you want to incorporate the `preview-middleware` functionality in your own middleware.
91
+
92
+ ```
93
+ import { FlpSandbox } from '@sap-ux/preview-middleware';
94
+ const flp = new FlpSandbox(flpConfig, rootProject, middlewareUtil, logger);
95
+ const files = await resources.rootProject.byGlob('/manifest.json');
96
+ flp.init(JSON.parse(await files[0].getString()));
97
+
98
+ return flp.router
99
+ ```
100
+ - `flpConfig` - the FLP configuration
101
+ - `rootProject` - [Reader](https://sap.github.io/ui5-tooling/stable/api/@ui5_fs_AbstractReader.html) to access resources of the root project
102
+ - `middlewareUtil` - [MiddlewareUtil](https://sap.github.io/ui5-tooling/v3/api/@ui5_server_middleware_MiddlewareUtil.html) of the UI5 server
103
+ - `logger` - Logger instance for use in the middleware.
@@ -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
@@ -23,6 +23,13 @@ const DEFAULT_THEME = 'sap_horizon';
23
23
  * Default path for mounting the local FLP.
24
24
  */
25
25
  const DEFAULT_PATH = '/test/flp.html';
26
+ /**
27
+ * Default intent
28
+ */
29
+ const DEFAULT_INTENT = {
30
+ object: 'app',
31
+ action: 'preview'
32
+ };
26
33
  /**
27
34
  * Class handling preview of a sandbox FLP.
28
35
  */
@@ -36,13 +43,14 @@ class FlpSandbox {
36
43
  * @param logger logger instance
37
44
  */
38
45
  constructor(config, project, utils, logger) {
39
- var _a, _b;
46
+ var _a, _b, _c;
40
47
  this.project = project;
41
48
  this.utils = utils;
42
49
  this.logger = logger;
43
50
  this.config = {
44
51
  path: (_a = config.path) !== null && _a !== void 0 ? _a : DEFAULT_PATH,
45
- apps: (_b = config.apps) !== null && _b !== void 0 ? _b : [],
52
+ intent: (_b = config.intent) !== null && _b !== void 0 ? _b : DEFAULT_INTENT,
53
+ apps: (_c = config.apps) !== null && _c !== void 0 ? _c : [],
46
54
  rta: config.rta
47
55
  };
48
56
  logger.debug(`Config: ${JSON.stringify(this.config)}`);
@@ -52,9 +60,11 @@ class FlpSandbox {
52
60
  * Initialize the FLP sandbox router.
53
61
  *
54
62
  * @param manifest application manifest
63
+ * @param componentId optional componentId e.g. for adaptation projects
64
+ * @param resources optional additional resource mappings
55
65
  */
56
- init(manifest) {
57
- var _a, _b, _c, _d, _e;
66
+ init(manifest, componentId, resources = {}) {
67
+ var _a, _b, _c, _d, _e, _f;
58
68
  return __awaiter(this, void 0, void 0, function* () {
59
69
  const flex = this.createFlexHandler();
60
70
  const supportedThemes = (_b = (_a = manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.supportedThemes) !== null && _b !== void 0 ? _b : [DEFAULT_THEME];
@@ -64,27 +74,26 @@ class FlpSandbox {
64
74
  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
75
  theme: supportedThemes.includes(DEFAULT_THEME) ? DEFAULT_THEME : supportedThemes[0],
66
76
  flex,
67
- resources: {}
77
+ resources: Object.assign({}, resources)
68
78
  },
69
79
  locateReuseLibsScript: yield this.findLocateReuseLibsScript()
70
80
  };
71
81
  this.addApp(manifest, {
72
- target: '/',
82
+ componentId,
83
+ target: (_f = resources[componentId !== null && componentId !== void 0 ? componentId : manifest['sap.app'].id]) !== null && _f !== void 0 ? _f : '/',
73
84
  local: '.',
74
- intent: {
75
- object: 'app',
76
- action: 'preview'
77
- }
85
+ intent: this.config.intent
78
86
  });
79
87
  // add route for the sandbox.html
80
88
  this.router.get(this.config.path, (req, res) => {
81
89
  var _a, _b;
82
90
  const config = Object.assign({}, this.templateConfig);
83
- if (req.query['fiori-tools-rta-mode']) {
91
+ const fioriToolsRtaMode = req.query['fiori-tools-rta-mode'];
92
+ if (fioriToolsRtaMode) {
84
93
  if ((_a = this.config.rta) === null || _a === void 0 ? void 0 : _a.layer) {
85
94
  config.flex = {
86
95
  layer: (_b = this.config.rta) === null || _b === void 0 ? void 0 : _b.layer,
87
- developerMode: false
96
+ developerMode: fioriToolsRtaMode === 'forAdaptation'
88
97
  };
89
98
  }
90
99
  else {
@@ -195,7 +204,7 @@ class FlpSandbox {
195
204
  * @param app configuration for the preview
196
205
  */
197
206
  addApp(manifest, app) {
198
- var _a, _b, _c, _d, _e;
207
+ var _a, _b, _c, _d, _e, _f;
199
208
  const id = manifest['sap.app'].id;
200
209
  (_a = app.intent) !== null && _a !== void 0 ? _a : (app.intent = {
201
210
  object: id.replace(/\./g, ''),
@@ -205,7 +214,7 @@ class FlpSandbox {
205
214
  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
215
  title: (_d = manifest['sap.app'].title) !== null && _d !== void 0 ? _d : id,
207
216
  description: (_e = manifest['sap.app'].description) !== null && _e !== void 0 ? _e : '',
208
- additionalInformation: `SAPUI5.Component=${id}`,
217
+ additionalInformation: `SAPUI5.Component=${(_f = app.componentId) !== null && _f !== void 0 ? _f : id}`,
209
218
  applicationType: 'URL',
210
219
  url: app.target
211
220
  };
@@ -0,0 +1,2 @@
1
+ export { FlpSandbox } from './flp';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlpSandbox = void 0;
4
+ var flp_1 = require("./flp");
5
+ Object.defineProperty(exports, "FlpSandbox", { enumerable: true, get: function () { return flp_1.FlpSandbox; } });
6
+ //# sourceMappingURL=index.js.map
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './ui5/middleware';
2
+ export { FlpSandbox } from './base';
2
3
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -14,5 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.FlpSandbox = void 0;
17
18
  __exportStar(require("./ui5/middleware"), exports);
19
+ var base_1 = require("./base");
20
+ Object.defineProperty(exports, "FlpSandbox", { enumerable: true, get: function () { return base_1.FlpSandbox; } });
18
21
  //# sourceMappingURL=index.js.map
@@ -1,20 +1,27 @@
1
+ import type { AdpPreviewConfig } from '@sap-ux/adp-tooling';
1
2
  import type { UI5FlexLayer } from '@sap-ux/project-access';
3
+ interface Intent {
4
+ object: string;
5
+ action: string;
6
+ }
2
7
  /**
3
8
  * Configuration for additional applications
4
9
  */
5
10
  export interface App {
6
11
  target: string;
7
12
  local: string;
8
- intent?: {
9
- object: string;
10
- action: string;
11
- };
13
+ /**
14
+ * Optional component id if it differs from the manifest (e.g. for adaptation projects)
15
+ */
16
+ componentId?: string;
17
+ intent?: Intent;
12
18
  }
13
19
  /**
14
20
  * FLP preview configuration.
15
21
  */
16
22
  export interface FlpConfig {
17
23
  path: string;
24
+ intent?: Intent;
18
25
  rta?: {
19
26
  layer?: UI5FlexLayer;
20
27
  };
@@ -25,6 +32,8 @@ export interface FlpConfig {
25
32
  */
26
33
  export interface Config {
27
34
  flp?: Partial<FlpConfig>;
35
+ adp?: AdpPreviewConfig;
28
36
  debug?: boolean;
29
37
  }
38
+ export {};
30
39
  //# 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.3.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.11.0",
38
+ "@sap-ux/store": "0.3.12"
35
39
  },
36
40
  "peerDependencies": {
37
41
  "express": "4"