@sap-ux/preview-middleware 0.2.0 → 0.3.1

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,32 +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
- | `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 |
13
- | `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 |
14
17
 
15
18
  ### `flp.apps`
16
19
  Array of additional application configurations:
17
- | Option | Type | Default Value | Description |
18
- | ------------ | ------| ------------- | ----------- |
19
- | `target` | `string` | | Target path of the additional application |
20
- | `local` | `string` | | Local path to the folder containing the application |
21
- | `intent` | | | Optional intent to be used for the application |
22
- | `intent.object` | `string` | `(calculated)`| Optional intent object, if it is not provided then it will be calculated based on the application id |
23
- | `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 |
24
27
 
25
28
  ### `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 |
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 |
32
35
 
33
36
  ## Usage
34
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`).
@@ -83,3 +86,18 @@ server:
83
86
  url: http://sap.example
84
87
  ignoreCertErrors: true
85
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.
@@ -1,5 +1,18 @@
1
1
  import type { Logger } from '@sap-ux/logger';
2
2
  import type { ReaderCollection } from '@ui5/fs';
3
+ /**
4
+ * Structure of a flex change.
5
+ */
6
+ export interface FlexChange {
7
+ [key: string]: string | object | undefined;
8
+ changeType: string;
9
+ reference: string;
10
+ moduleName?: string;
11
+ content?: {
12
+ codeRef?: string;
13
+ fragmentPath?: string;
14
+ };
15
+ }
3
16
  /**
4
17
  * Read changes from the file system and return them.
5
18
  *
@@ -7,7 +20,7 @@ import type { ReaderCollection } from '@ui5/fs';
7
20
  * @param logger logger instance
8
21
  * @returns object with the file name as key and the file content as value
9
22
  */
10
- export declare function readChanges(project: ReaderCollection, logger: Logger): Promise<Record<string, unknown>>;
23
+ export declare function readChanges(project: ReaderCollection, logger: Logger): Promise<Record<string, FlexChange>>;
11
24
  /**
12
25
  * Writes flex changes to the user's workspace.
13
26
  *
package/dist/base/flex.js CHANGED
@@ -12,6 +12,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.deleteChange = exports.writeChange = exports.readChanges = void 0;
13
13
  const fs_1 = require("fs");
14
14
  const path_1 = require("path");
15
+ /**
16
+ * Map of change type specific correction functions.
17
+ */
18
+ const moduleNameContentMap = {
19
+ codeExt: (change) => { var _a, _b; return ((_b = (_a = change.content) === null || _a === void 0 ? void 0 : _a.codeRef) !== null && _b !== void 0 ? _b : '').replace('.js', ''); },
20
+ addXML: (change) => { var _a, _b; return (_b = (_a = change.content) === null || _a === void 0 ? void 0 : _a.fragmentPath) !== null && _b !== void 0 ? _b : ''; }
21
+ };
22
+ /**
23
+ * Sets the moduleName property of the provided change to also support old changes with newer UI5 versions.
24
+ *
25
+ * @param change change to be fixed
26
+ * @param logger logger instance
27
+ */
28
+ function tryFixChange(change, logger) {
29
+ try {
30
+ const prefix = change.reference.replace(/\./g, '/');
31
+ change.moduleName = `${prefix}/changes/${moduleNameContentMap[change.changeType](change)}`;
32
+ }
33
+ catch (error) {
34
+ logger.warn('Could not fix missing module name.');
35
+ }
36
+ }
15
37
  /**
16
38
  * Read changes from the file system and return them.
17
39
  *
@@ -25,7 +47,11 @@ function readChanges(project, logger) {
25
47
  const files = yield project.byGlob('/**/changes/*.*');
26
48
  for (const file of files) {
27
49
  try {
28
- changes[`sap.ui.fl.${(0, path_1.parse)(file.getName()).name}`] = JSON.parse(yield file.getString());
50
+ const change = JSON.parse(yield file.getString());
51
+ if (moduleNameContentMap[change.changeType] && !change.moduleName) {
52
+ tryFixChange(change, logger);
53
+ }
54
+ changes[`sap.ui.fl.${(0, path_1.parse)(file.getName()).name}`] = change;
29
55
  logger.debug(`Read change from ${file.getPath()}`);
30
56
  }
31
57
  catch (error) {
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)}`);
@@ -74,10 +82,7 @@ class FlpSandbox {
74
82
  componentId,
75
83
  target: (_f = resources[componentId !== null && componentId !== void 0 ? componentId : manifest['sap.app'].id]) !== null && _f !== void 0 ? _f : '/',
76
84
  local: '.',
77
- intent: {
78
- object: 'app',
79
- action: 'preview'
80
- }
85
+ intent: this.config.intent
81
86
  });
82
87
  // add route for the sandbox.html
83
88
  this.router.get(this.config.path, (req, res) => {
@@ -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,5 +1,12 @@
1
1
  import type { AdpPreviewConfig } from '@sap-ux/adp-tooling';
2
2
  import type { UI5FlexLayer } from '@sap-ux/project-access';
3
+ /**
4
+ * Intent object consisting of an object and an action.
5
+ */
6
+ interface Intent {
7
+ object: string;
8
+ action: string;
9
+ }
3
10
  /**
4
11
  * Configuration for additional applications
5
12
  */
@@ -10,16 +17,14 @@ export interface App {
10
17
  * Optional component id if it differs from the manifest (e.g. for adaptation projects)
11
18
  */
12
19
  componentId?: string;
13
- intent?: {
14
- object: string;
15
- action: string;
16
- };
20
+ intent?: Intent;
17
21
  }
18
22
  /**
19
23
  * FLP preview configuration.
20
24
  */
21
25
  export interface FlpConfig {
22
26
  path: string;
27
+ intent?: Intent;
23
28
  rta?: {
24
29
  layer?: UI5FlexLayer;
25
30
  };
@@ -33,4 +38,5 @@ export interface Config {
33
38
  adp?: AdpPreviewConfig;
34
39
  debug?: boolean;
35
40
  }
41
+ export {};
36
42
  //# sourceMappingURL=index.d.ts.map
@@ -24,8 +24,8 @@ function initAdp(rootProject, config, flp, logger) {
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
25
  const files = yield rootProject.byGlob('/manifest.appdescr_variant');
26
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('**/*.*'));
27
+ const adp = new adp_tooling_1.AdpPreview(config, rootProject, logger);
28
+ const layer = yield adp.init(JSON.parse(yield files[0].getString()));
29
29
  flp.config.rta = { layer };
30
30
  yield flp.init(adp.descriptor.manifest, adp.descriptor.name, adp.resources);
31
31
  flp.router.use(adp.descriptor.url, adp.proxy.bind(adp));
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.2.0",
12
+ "version": "0.3.1",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -24,7 +24,7 @@
24
24
  "dependencies": {
25
25
  "ejs": "3.1.7",
26
26
  "@sap-ux/logger": "0.3.7",
27
- "@sap-ux/adp-tooling": "0.1.0"
27
+ "@sap-ux/adp-tooling": "0.1.1"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/ejs": "3.1.0",
@@ -34,7 +34,7 @@
34
34
  "express": "4.18.2",
35
35
  "nock": "13.2.1",
36
36
  "supertest": "6.3.2",
37
- "@sap-ux/project-access": "1.10.1",
37
+ "@sap-ux/project-access": "1.11.0",
38
38
  "@sap-ux/store": "0.3.12"
39
39
  },
40
40
  "peerDependencies": {