@sap-ux/preview-middleware 0.12.11 → 0.12.12
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 +22 -0
- package/dist/base/flp.d.ts +10 -1
- package/dist/base/flp.js +67 -4
- package/dist/base/test.d.ts +24 -0
- package/dist/base/test.js +59 -0
- package/dist/client/adp/api-handler.js +141 -141
- package/dist/client/adp/command-executor.js +54 -54
- package/dist/client/adp/control-utils.js +44 -44
- package/dist/client/adp/controllers/AddFragment.controller.js +206 -206
- package/dist/client/adp/controllers/BaseDialog.controller.js +57 -57
- package/dist/client/adp/controllers/ControllerExtension.controller.js +174 -174
- package/dist/client/adp/controllers/ExtensionPoint.controller.js +100 -100
- package/dist/client/adp/init-dialogs.js +74 -74
- package/dist/client/adp/ui5-version-utils.js +63 -63
- package/dist/client/adp/utils.js +33 -33
- package/dist/client/cpe/changes/flex-change.js +51 -51
- package/dist/client/cpe/changes/index.js +10 -10
- package/dist/client/cpe/changes/validator.js +35 -35
- package/dist/client/cpe/documentation.js +164 -164
- package/dist/client/cpe/logger.js +30 -30
- package/dist/client/cpe/outline/nodes.js +84 -84
- package/dist/client/cpe/outline/utils.js +37 -37
- package/dist/client/cpe/types.js +4 -4
- package/dist/client/cpe/ui5-utils.js +49 -49
- package/dist/client/cpe/utils.js +48 -48
- package/dist/client/flp/WorkspaceConnector.js +69 -69
- package/dist/client/flp/common.js +28 -28
- package/dist/client/flp/enableFakeConnector.js +77 -77
- package/dist/client/flp/init.js +220 -212
- package/dist/client/flp/init.ts +17 -2
- package/dist/client/flp/initConnectors.js +33 -33
- package/dist/client/flp/initRta.js +178 -178
- package/dist/index.d.ts +1 -1
- package/dist/types/index.d.ts +23 -0
- package/package.json +3 -3
- package/templates/flp/sandbox.html +5 -4
- package/templates/test/qunit.html +25 -0
- package/templates/test/qunit.js +6 -0
package/README.md
CHANGED
|
@@ -17,6 +17,7 @@ When this middleware is used together with the `reload-middleware`, then the ord
|
|
|
17
17
|
| ---------------------- | --------- | ---------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
18
18
|
| `flp` | | | Optional configuration object for the local Fiori launchpad |
|
|
19
19
|
| `flp.path` | `string` | `/test/flp.html` | The mount point of the local Fiori launchpad. |
|
|
20
|
+
| `flp.init` | `string` | `undefined` | Optional UI5 module/script to be executed after the standard initialization |
|
|
20
21
|
| `flp.intent` | | | Optional intent to be used for the application |
|
|
21
22
|
| `flp.intent.object` | `string` | `app` | Optional intent object |
|
|
22
23
|
| `flp.intent.action` | `string` | `preview` | Optional intent action |
|
|
@@ -28,6 +29,7 @@ When this middleware is used together with the `reload-middleware`, then the ord
|
|
|
28
29
|
| `rta` | | | Optional configuration allowing to add mount points for runtime adaptation |
|
|
29
30
|
| `rta.layer` | `string` | `(calculated)` | Optional property for defining the runtime adaptation layer for changes (default is `CUSTOMER_BASE` or read from the project for adaptation projects) |
|
|
30
31
|
| `rta.editors` | `array` | `undefined` | Optional list of mount points for editing |
|
|
32
|
+
| `test` | `array` | `undefined` | Optional list of configurations for automated testing |
|
|
31
33
|
| `debug` | `boolean` | `false` | Enables debug output |
|
|
32
34
|
|
|
33
35
|
### `flp.apps`
|
|
@@ -54,6 +56,14 @@ Array of additional application configurations:
|
|
|
54
56
|
| `path` | `string` mandatory | The mount point to be used for the editor. |
|
|
55
57
|
| `developerMode` | `boolean` optional | Enables/disables the runtime adaptation developer mode (only supported for adaptation projects) |
|
|
56
58
|
|
|
59
|
+
### `test`
|
|
60
|
+
| Option | Type | Description |
|
|
61
|
+
| --------------- | -------------------| -----------------------------------------------------------------------------------------------|
|
|
62
|
+
| `framework` | `string` mandatory | Currently `OPA5` and `QUnit` are supported |
|
|
63
|
+
| `path` | `string` optional | The mount point to be used for test suite |
|
|
64
|
+
| `init` | `string` optional | The mount point to be used for test runner script |
|
|
65
|
+
| `pattern` | `string` optional | Optional glob pattern to find the tests. By default `/test/**/*Journey.*` is used for `OPA5` and `/test/**/*Test.*` is used for `QUnit`|
|
|
66
|
+
|
|
57
67
|
|
|
58
68
|
## Usage
|
|
59
69
|
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`).
|
|
@@ -109,6 +119,18 @@ server:
|
|
|
109
119
|
- path: /test/variant-editor.html
|
|
110
120
|
```
|
|
111
121
|
|
|
122
|
+
### Test Suites
|
|
123
|
+
If you want to also generate generic test suites and test runners for QUnit or OPA5 tests then you can use the following minimum configurations
|
|
124
|
+
```Yaml
|
|
125
|
+
server:
|
|
126
|
+
customMiddleware:
|
|
127
|
+
- name: preview-middleware
|
|
128
|
+
afterMiddleware: compression
|
|
129
|
+
configuration:
|
|
130
|
+
test:
|
|
131
|
+
- framework: QUnit
|
|
132
|
+
- framework: OPA5
|
|
133
|
+
```
|
|
112
134
|
|
|
113
135
|
### Adaptation Project
|
|
114
136
|
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. For adaptation projects, it is also recommended to add the `rta` configuration allowing to edit the project.
|
package/dist/base/flp.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference path="../../../../types/ui5.d.ts" />
|
|
2
2
|
import type { ReaderCollection } from '@ui5/fs';
|
|
3
3
|
import type { Router } from 'express';
|
|
4
|
-
import type { App, FlpConfig, MiddlewareConfig, RtaConfig } from '../types';
|
|
4
|
+
import type { App, FlpConfig, MiddlewareConfig, RtaConfig, TestConfig } from '../types';
|
|
5
5
|
import type { Logger, ToolsLogger } from '@sap-ux/logger';
|
|
6
6
|
import type { MiddlewareUtils } from '@ui5/server';
|
|
7
7
|
import type { Manifest, UI5FlexLayer } from '@sap-ux/project-access';
|
|
@@ -44,6 +44,7 @@ export interface TemplateConfig {
|
|
|
44
44
|
bootstrapOptions: string;
|
|
45
45
|
resources: Record<string, string>;
|
|
46
46
|
};
|
|
47
|
+
init?: string;
|
|
47
48
|
flex?: {
|
|
48
49
|
[key: string]: unknown;
|
|
49
50
|
layer: UI5FlexLayer;
|
|
@@ -62,6 +63,7 @@ export declare class FlpSandbox {
|
|
|
62
63
|
protected templateConfig: TemplateConfig;
|
|
63
64
|
readonly config: FlpConfig;
|
|
64
65
|
readonly rta?: RtaConfig;
|
|
66
|
+
readonly test?: TestConfig[];
|
|
65
67
|
readonly router: EnhancedRouter;
|
|
66
68
|
/**
|
|
67
69
|
* Constructor setting defaults and keeping reference to workspace resources.
|
|
@@ -119,6 +121,13 @@ export declare class FlpSandbox {
|
|
|
119
121
|
* Create required routes for flex.
|
|
120
122
|
*/
|
|
121
123
|
private createFlexHandler;
|
|
124
|
+
/**
|
|
125
|
+
* Add routes for html and scripts required for a local test FLP.
|
|
126
|
+
*
|
|
127
|
+
* @param configs test configurations
|
|
128
|
+
* @param id application id from manifest
|
|
129
|
+
*/
|
|
130
|
+
private addTestRoutes;
|
|
122
131
|
/**
|
|
123
132
|
* Add an application to the local FLP preview.
|
|
124
133
|
*
|
package/dist/base/flp.js
CHANGED
|
@@ -16,6 +16,7 @@ const path_1 = require("path");
|
|
|
16
16
|
const express_1 = require("express");
|
|
17
17
|
const flex_1 = require("./flex");
|
|
18
18
|
const adp_tooling_1 = require("@sap-ux/adp-tooling");
|
|
19
|
+
const test_1 = require("./test");
|
|
19
20
|
const DEVELOPER_MODE_CONFIG = new Map([
|
|
20
21
|
// Run application in design time mode
|
|
21
22
|
// Adds bindingString to BindingInfo objects. Required to create and read PropertyBinding changes
|
|
@@ -91,7 +92,7 @@ class FlpSandbox {
|
|
|
91
92
|
* @param logger logger instance
|
|
92
93
|
*/
|
|
93
94
|
constructor(config, project, utils, logger) {
|
|
94
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
95
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
95
96
|
this.project = project;
|
|
96
97
|
this.utils = utils;
|
|
97
98
|
this.logger = logger;
|
|
@@ -100,13 +101,15 @@ class FlpSandbox {
|
|
|
100
101
|
intent: (_d = (_c = config.flp) === null || _c === void 0 ? void 0 : _c.intent) !== null && _d !== void 0 ? _d : DEFAULT_INTENT,
|
|
101
102
|
apps: (_f = (_e = config.flp) === null || _e === void 0 ? void 0 : _e.apps) !== null && _f !== void 0 ? _f : [],
|
|
102
103
|
libs: (_g = config.flp) === null || _g === void 0 ? void 0 : _g.libs,
|
|
103
|
-
theme: (_h = config.flp) === null || _h === void 0 ? void 0 : _h.theme
|
|
104
|
+
theme: (_h = config.flp) === null || _h === void 0 ? void 0 : _h.theme,
|
|
105
|
+
init: (_j = config.flp) === null || _j === void 0 ? void 0 : _j.init
|
|
104
106
|
};
|
|
105
107
|
if (!this.config.path.startsWith('/')) {
|
|
106
108
|
this.config.path = `/${this.config.path}`;
|
|
107
109
|
}
|
|
110
|
+
this.test = config.test;
|
|
108
111
|
this.rta = config.rta;
|
|
109
|
-
logger.debug(`Config: ${JSON.stringify({ flp: this.config, rta: this.rta })}`);
|
|
112
|
+
logger.debug(`Config: ${JSON.stringify({ flp: this.config, rta: this.rta, test: this.test })}`);
|
|
110
113
|
this.router = (0, express_1.Router)();
|
|
111
114
|
}
|
|
112
115
|
/**
|
|
@@ -124,9 +127,12 @@ class FlpSandbox {
|
|
|
124
127
|
const flex = this.getFlexSettings();
|
|
125
128
|
const supportedThemes = (_b = (_a = manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.supportedThemes) !== null && _b !== void 0 ? _b : [DEFAULT_THEME];
|
|
126
129
|
const ui5Theme = (_c = this.config.theme) !== null && _c !== void 0 ? _c : (supportedThemes.includes(DEFAULT_THEME) ? DEFAULT_THEME : supportedThemes[0]);
|
|
130
|
+
const id = manifest['sap.app'].id;
|
|
131
|
+
const ns = id.replace(/\./g, '/');
|
|
127
132
|
this.templateConfig = {
|
|
128
133
|
basePath: (_d = path_1.posix.relative(path_1.posix.dirname(this.config.path), '/')) !== null && _d !== void 0 ? _d : '.',
|
|
129
134
|
apps: {},
|
|
135
|
+
init: this.config.init ? ns + this.config.init : undefined,
|
|
130
136
|
ui5: {
|
|
131
137
|
libs: this.getUI5Libs(manifest),
|
|
132
138
|
theme: ui5Theme,
|
|
@@ -136,7 +142,6 @@ class FlpSandbox {
|
|
|
136
142
|
},
|
|
137
143
|
locateReuseLibsScript: (_e = this.config.libs) !== null && _e !== void 0 ? _e : (yield this.hasLocateReuseLibsScript())
|
|
138
144
|
};
|
|
139
|
-
const id = manifest['sap.app'].id;
|
|
140
145
|
this.addApp(manifest, {
|
|
141
146
|
componentId,
|
|
142
147
|
target: (_f = resources[componentId !== null && componentId !== void 0 ? componentId : id]) !== null && _f !== void 0 ? _f : this.templateConfig.basePath,
|
|
@@ -150,6 +155,9 @@ class FlpSandbox {
|
|
|
150
155
|
this.rta.options.appName = id;
|
|
151
156
|
this.addEditorRoutes(this.rta);
|
|
152
157
|
}
|
|
158
|
+
if (this.test) {
|
|
159
|
+
this.addTestRoutes(this.test, id);
|
|
160
|
+
}
|
|
153
161
|
this.addRoutesForAdditionalApps();
|
|
154
162
|
this.logger.info(`Initialized for app ${id}`);
|
|
155
163
|
this.logger.debug(`Configured apps: ${JSON.stringify(this.templateConfig.apps)}`);
|
|
@@ -325,6 +333,61 @@ class FlpSandbox {
|
|
|
325
333
|
}
|
|
326
334
|
})));
|
|
327
335
|
}
|
|
336
|
+
/**
|
|
337
|
+
* Add routes for html and scripts required for a local test FLP.
|
|
338
|
+
*
|
|
339
|
+
* @param configs test configurations
|
|
340
|
+
* @param id application id from manifest
|
|
341
|
+
*/
|
|
342
|
+
addTestRoutes(configs, id) {
|
|
343
|
+
const ns = id.replace(/\./g, '/');
|
|
344
|
+
const htmlTemplate = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../templates/test/qunit.html'), 'utf-8');
|
|
345
|
+
const initTemplate = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../templates/test/qunit.js'), 'utf-8');
|
|
346
|
+
for (const testConfig of configs) {
|
|
347
|
+
const config = (0, test_1.mergeTestConfigDefaults)(testConfig);
|
|
348
|
+
this.logger.debug(`Add route for ${config.path}`);
|
|
349
|
+
// add route for the *.qunit.html
|
|
350
|
+
this.router.get(config.path, ((_req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
351
|
+
var _a;
|
|
352
|
+
this.logger.debug(`Serving test route: ${config.path}`);
|
|
353
|
+
const file = yield this.project.byPath(config.path);
|
|
354
|
+
if (file) {
|
|
355
|
+
this.logger.warn(`HTML file returned at ${config.path} is loaded from the file system.`);
|
|
356
|
+
next();
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
const templateConfig = {
|
|
360
|
+
id,
|
|
361
|
+
framework: config.framework,
|
|
362
|
+
basePath: (_a = path_1.posix.relative(path_1.posix.dirname(config.path), '/')) !== null && _a !== void 0 ? _a : '.',
|
|
363
|
+
initPath: `${ns}${config.init.replace('.js', '')}`
|
|
364
|
+
};
|
|
365
|
+
const html = (0, ejs_1.render)(htmlTemplate, templateConfig);
|
|
366
|
+
res.status(200).contentType('html').send(html);
|
|
367
|
+
}
|
|
368
|
+
})));
|
|
369
|
+
if (testConfig.init !== undefined) {
|
|
370
|
+
this.logger.debug(`Skip serving test init script in favor of provided script: ${testConfig.init}`);
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
// add route for the init file
|
|
374
|
+
this.logger.debug(`Add route for ${config.init}`);
|
|
375
|
+
this.router.get(config.init, ((_req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
376
|
+
this.logger.debug(`Serving test init script: ${config.init}`);
|
|
377
|
+
const files = yield this.project.byGlob(config.init.replace('.js', '.*'));
|
|
378
|
+
if ((files === null || files === void 0 ? void 0 : files.length) > 0) {
|
|
379
|
+
this.logger.warn(`Script returned at ${config.path} is loaded from the file system.`);
|
|
380
|
+
next();
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
const testFiles = yield this.project.byGlob(config.pattern);
|
|
384
|
+
const templateConfig = { tests: (0, test_1.generateImportList)(ns, testFiles) };
|
|
385
|
+
const html = (0, ejs_1.render)(initTemplate, templateConfig);
|
|
386
|
+
res.status(200).contentType('application/javascript').send(html);
|
|
387
|
+
}
|
|
388
|
+
})));
|
|
389
|
+
}
|
|
390
|
+
}
|
|
328
391
|
/**
|
|
329
392
|
* Add an application to the local FLP preview.
|
|
330
393
|
*
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference path="../../../../types/ui5.d.ts" />
|
|
2
|
+
import type { Resource } from '@ui5/fs';
|
|
3
|
+
import type { TestConfig } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Merge the given test configuration with the default values.
|
|
6
|
+
*
|
|
7
|
+
* @param config test configuration
|
|
8
|
+
* @returns merged test configuration
|
|
9
|
+
*/
|
|
10
|
+
export declare function mergeTestConfigDefaults(config: TestConfig): {
|
|
11
|
+
framework: "OPA5" | "QUnit";
|
|
12
|
+
path: string;
|
|
13
|
+
init: string;
|
|
14
|
+
pattern: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Generate a list of imports from a list of resources.
|
|
18
|
+
*
|
|
19
|
+
* @param ns namespace of the test files
|
|
20
|
+
* @param resourceList list of resources representing test files
|
|
21
|
+
* @returns array of strings representing the tests
|
|
22
|
+
*/
|
|
23
|
+
export declare function generateImportList(ns: string, resourceList: Resource[]): string[];
|
|
24
|
+
//# sourceMappingURL=test.d.ts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateImportList = exports.mergeTestConfigDefaults = void 0;
|
|
4
|
+
const DEFAULTS = {
|
|
5
|
+
qunit: {
|
|
6
|
+
path: '/test/unitTests.qunit.html',
|
|
7
|
+
init: '/test/unitTests.qunit.js',
|
|
8
|
+
pattern: '/test/**/*Test.*',
|
|
9
|
+
framework: 'QUnit'
|
|
10
|
+
},
|
|
11
|
+
opa5: {
|
|
12
|
+
path: '/test/opaTests.qunit.html',
|
|
13
|
+
init: '/test/opaTests.qunit.js',
|
|
14
|
+
pattern: '/test/**/*Journey.*',
|
|
15
|
+
framework: 'OPA5'
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Merge the given test configuration with the default values.
|
|
20
|
+
*
|
|
21
|
+
* @param config test configuration
|
|
22
|
+
* @returns merged test configuration
|
|
23
|
+
*/
|
|
24
|
+
function mergeTestConfigDefaults(config) {
|
|
25
|
+
var _a, _b, _c, _d;
|
|
26
|
+
const key = config.framework.toLowerCase();
|
|
27
|
+
const defaults = (_a = DEFAULTS[key]) !== null && _a !== void 0 ? _a : {};
|
|
28
|
+
if (config.path && !config.path.startsWith('/')) {
|
|
29
|
+
config.path = `/${config.path}`;
|
|
30
|
+
}
|
|
31
|
+
if (config.init && !config.init.startsWith('/')) {
|
|
32
|
+
config.init = `/${config.init}`;
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
framework: config.framework,
|
|
36
|
+
path: (_b = config.path) !== null && _b !== void 0 ? _b : defaults.path,
|
|
37
|
+
init: (_c = config.init) !== null && _c !== void 0 ? _c : defaults.init,
|
|
38
|
+
pattern: (_d = config.pattern) !== null && _d !== void 0 ? _d : defaults.pattern
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
exports.mergeTestConfigDefaults = mergeTestConfigDefaults;
|
|
42
|
+
/**
|
|
43
|
+
* Generate a list of imports from a list of resources.
|
|
44
|
+
*
|
|
45
|
+
* @param ns namespace of the test files
|
|
46
|
+
* @param resourceList list of resources representing test files
|
|
47
|
+
* @returns array of strings representing the tests
|
|
48
|
+
*/
|
|
49
|
+
function generateImportList(ns, resourceList) {
|
|
50
|
+
return resourceList
|
|
51
|
+
? resourceList.map((file) => {
|
|
52
|
+
const path = file.getPath().split('.');
|
|
53
|
+
path.pop();
|
|
54
|
+
return `${ns}${path.join('.')}`;
|
|
55
|
+
})
|
|
56
|
+
: [];
|
|
57
|
+
}
|
|
58
|
+
exports.generateImportList = generateImportList;
|
|
59
|
+
//# sourceMappingURL=test.js.map
|
|
@@ -1,143 +1,143 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
sap.ui.define([], function () {
|
|
4
|
-
"use strict";
|
|
5
|
-
|
|
6
|
-
var ApiEndpoints = /*#__PURE__*/function (ApiEndpoints) {
|
|
7
|
-
ApiEndpoints["CHANGES"] = "/preview/api/changes";
|
|
8
|
-
ApiEndpoints["FRAGMENT"] = "/adp/api/fragment";
|
|
9
|
-
ApiEndpoints["CONTROLLER"] = "/adp/api/controller";
|
|
10
|
-
ApiEndpoints["CODE_EXT"] = "/adp/api/code_ext";
|
|
11
|
-
ApiEndpoints["MANIFEST_APP_DESCRIPTOR"] = "/manifest.appdescr_variant";
|
|
12
|
-
return ApiEndpoints;
|
|
13
|
-
}(ApiEndpoints || {});
|
|
14
|
-
var RequestMethod = /*#__PURE__*/function (RequestMethod) {
|
|
15
|
-
RequestMethod["GET"] = "GET";
|
|
16
|
-
RequestMethod["PUT"] = "PUT";
|
|
17
|
-
RequestMethod["POST"] = "POST";
|
|
18
|
-
RequestMethod["PATCH"] = "PATCH";
|
|
19
|
-
RequestMethod["DELETE"] = "DELETE";
|
|
20
|
-
return RequestMethod;
|
|
21
|
-
}(RequestMethod || {});
|
|
22
|
-
/**
|
|
23
|
-
* Requests a given endpoint
|
|
24
|
-
*
|
|
25
|
-
* @param endpoint API Endpoint
|
|
26
|
-
* @param method RequestMethod
|
|
27
|
-
* @param data Data to be sent to the server
|
|
28
|
-
* @returns Data from the server request
|
|
29
|
-
*/
|
|
30
|
-
async function request(endpoint, method, data) {
|
|
31
|
-
const config = {
|
|
32
|
-
method,
|
|
33
|
-
body: JSON.stringify(data),
|
|
34
|
-
headers: {
|
|
35
|
-
'content-type': 'application/json'
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
try {
|
|
39
|
-
const response = await fetch(endpoint, config);
|
|
40
|
-
if (!response.ok) {
|
|
41
|
-
const errorData = await response.json();
|
|
42
|
-
const message = errorData?.message ?? '';
|
|
43
|
-
throw new Error(`Request failed, status: ${response.status}. ${message}`.trim());
|
|
44
|
-
}
|
|
45
|
-
switch (method) {
|
|
46
|
-
case RequestMethod.GET:
|
|
47
|
-
return response.json();
|
|
48
|
-
case RequestMethod.POST:
|
|
49
|
-
/**
|
|
50
|
-
* Since POST usually creates something
|
|
51
|
-
* and returns nothing (or a message) we just parse the text from res.send(msg)
|
|
52
|
-
*/
|
|
53
|
-
return response.text();
|
|
54
|
-
default:
|
|
55
|
-
return response.json();
|
|
56
|
-
}
|
|
57
|
-
} catch (e) {
|
|
58
|
-
throw new Error(e.message);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Retrieves all XML fragments from the project's workspace
|
|
64
|
-
*
|
|
65
|
-
* @returns Generic Promise<T>
|
|
66
|
-
*/
|
|
67
|
-
async function getFragments() {
|
|
68
|
-
return request(ApiEndpoints.FRAGMENT, RequestMethod.GET);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Writes an XML fragment to the project's workspace
|
|
73
|
-
*
|
|
74
|
-
* @param data Data to be send to the server
|
|
75
|
-
* @returns Generic Promise<T>
|
|
76
|
-
*/
|
|
77
|
-
async function writeFragment(data) {
|
|
78
|
-
return request(ApiEndpoints.FRAGMENT, RequestMethod.POST, data);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Retrieves manifest.appdescr_variant from the project's workspace
|
|
83
|
-
*
|
|
84
|
-
* @returns Generic Promise<T>
|
|
85
|
-
*/
|
|
86
|
-
async function getManifestAppdescr() {
|
|
87
|
-
return request(ApiEndpoints.MANIFEST_APP_DESCRIPTOR, RequestMethod.GET);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Retrieves all controller extensions from the project's workspace
|
|
92
|
-
*
|
|
93
|
-
* @returns Generic Promise<T>
|
|
94
|
-
*/
|
|
95
|
-
async function readControllers() {
|
|
96
|
-
return request(ApiEndpoints.CONTROLLER, RequestMethod.GET);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Writes a Controller to the project's workspace
|
|
101
|
-
*
|
|
102
|
-
* @param data Data to be send to the server
|
|
103
|
-
* @returns Generic Promise<T>
|
|
104
|
-
*/
|
|
105
|
-
async function writeController(data) {
|
|
106
|
-
return request(ApiEndpoints.CONTROLLER, RequestMethod.POST, data);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Checks for existing controller in the project's workspace
|
|
111
|
-
*
|
|
112
|
-
* @param controllerName Name of the controller
|
|
113
|
-
* @returns {CodeExtResponse} Returns path to existing controller if found
|
|
114
|
-
*/
|
|
115
|
-
async function getExistingController(controllerName) {
|
|
116
|
-
return request(`${ApiEndpoints.CODE_EXT}/${controllerName}`, RequestMethod.GET);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Writes a change object to the project's workspace
|
|
121
|
-
*
|
|
122
|
-
* @param data Data to be send to the server
|
|
123
|
-
* @returns Generic Promise<T>
|
|
124
|
-
*/
|
|
125
|
-
async function writeChange(data) {
|
|
126
|
-
return request(ApiEndpoints.CHANGES, RequestMethod.POST, data);
|
|
127
|
-
}
|
|
128
|
-
var __exports = {
|
|
129
|
-
__esModule: true
|
|
130
|
-
};
|
|
131
|
-
__exports.ApiEndpoints = ApiEndpoints;
|
|
132
|
-
__exports.RequestMethod = RequestMethod;
|
|
133
|
-
__exports.request = request;
|
|
134
|
-
__exports.getFragments = getFragments;
|
|
135
|
-
__exports.writeFragment = writeFragment;
|
|
136
|
-
__exports.getManifestAppdescr = getManifestAppdescr;
|
|
137
|
-
__exports.readControllers = readControllers;
|
|
138
|
-
__exports.writeController = writeController;
|
|
139
|
-
__exports.getExistingController = getExistingController;
|
|
140
|
-
__exports.writeChange = writeChange;
|
|
141
|
-
return __exports;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
sap.ui.define([], function () {
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
var ApiEndpoints = /*#__PURE__*/function (ApiEndpoints) {
|
|
7
|
+
ApiEndpoints["CHANGES"] = "/preview/api/changes";
|
|
8
|
+
ApiEndpoints["FRAGMENT"] = "/adp/api/fragment";
|
|
9
|
+
ApiEndpoints["CONTROLLER"] = "/adp/api/controller";
|
|
10
|
+
ApiEndpoints["CODE_EXT"] = "/adp/api/code_ext";
|
|
11
|
+
ApiEndpoints["MANIFEST_APP_DESCRIPTOR"] = "/manifest.appdescr_variant";
|
|
12
|
+
return ApiEndpoints;
|
|
13
|
+
}(ApiEndpoints || {});
|
|
14
|
+
var RequestMethod = /*#__PURE__*/function (RequestMethod) {
|
|
15
|
+
RequestMethod["GET"] = "GET";
|
|
16
|
+
RequestMethod["PUT"] = "PUT";
|
|
17
|
+
RequestMethod["POST"] = "POST";
|
|
18
|
+
RequestMethod["PATCH"] = "PATCH";
|
|
19
|
+
RequestMethod["DELETE"] = "DELETE";
|
|
20
|
+
return RequestMethod;
|
|
21
|
+
}(RequestMethod || {});
|
|
22
|
+
/**
|
|
23
|
+
* Requests a given endpoint
|
|
24
|
+
*
|
|
25
|
+
* @param endpoint API Endpoint
|
|
26
|
+
* @param method RequestMethod
|
|
27
|
+
* @param data Data to be sent to the server
|
|
28
|
+
* @returns Data from the server request
|
|
29
|
+
*/
|
|
30
|
+
async function request(endpoint, method, data) {
|
|
31
|
+
const config = {
|
|
32
|
+
method,
|
|
33
|
+
body: JSON.stringify(data),
|
|
34
|
+
headers: {
|
|
35
|
+
'content-type': 'application/json'
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
try {
|
|
39
|
+
const response = await fetch(endpoint, config);
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
const errorData = await response.json();
|
|
42
|
+
const message = errorData?.message ?? '';
|
|
43
|
+
throw new Error(`Request failed, status: ${response.status}. ${message}`.trim());
|
|
44
|
+
}
|
|
45
|
+
switch (method) {
|
|
46
|
+
case RequestMethod.GET:
|
|
47
|
+
return response.json();
|
|
48
|
+
case RequestMethod.POST:
|
|
49
|
+
/**
|
|
50
|
+
* Since POST usually creates something
|
|
51
|
+
* and returns nothing (or a message) we just parse the text from res.send(msg)
|
|
52
|
+
*/
|
|
53
|
+
return response.text();
|
|
54
|
+
default:
|
|
55
|
+
return response.json();
|
|
56
|
+
}
|
|
57
|
+
} catch (e) {
|
|
58
|
+
throw new Error(e.message);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Retrieves all XML fragments from the project's workspace
|
|
64
|
+
*
|
|
65
|
+
* @returns Generic Promise<T>
|
|
66
|
+
*/
|
|
67
|
+
async function getFragments() {
|
|
68
|
+
return request(ApiEndpoints.FRAGMENT, RequestMethod.GET);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Writes an XML fragment to the project's workspace
|
|
73
|
+
*
|
|
74
|
+
* @param data Data to be send to the server
|
|
75
|
+
* @returns Generic Promise<T>
|
|
76
|
+
*/
|
|
77
|
+
async function writeFragment(data) {
|
|
78
|
+
return request(ApiEndpoints.FRAGMENT, RequestMethod.POST, data);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Retrieves manifest.appdescr_variant from the project's workspace
|
|
83
|
+
*
|
|
84
|
+
* @returns Generic Promise<T>
|
|
85
|
+
*/
|
|
86
|
+
async function getManifestAppdescr() {
|
|
87
|
+
return request(ApiEndpoints.MANIFEST_APP_DESCRIPTOR, RequestMethod.GET);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Retrieves all controller extensions from the project's workspace
|
|
92
|
+
*
|
|
93
|
+
* @returns Generic Promise<T>
|
|
94
|
+
*/
|
|
95
|
+
async function readControllers() {
|
|
96
|
+
return request(ApiEndpoints.CONTROLLER, RequestMethod.GET);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Writes a Controller to the project's workspace
|
|
101
|
+
*
|
|
102
|
+
* @param data Data to be send to the server
|
|
103
|
+
* @returns Generic Promise<T>
|
|
104
|
+
*/
|
|
105
|
+
async function writeController(data) {
|
|
106
|
+
return request(ApiEndpoints.CONTROLLER, RequestMethod.POST, data);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Checks for existing controller in the project's workspace
|
|
111
|
+
*
|
|
112
|
+
* @param controllerName Name of the controller
|
|
113
|
+
* @returns {CodeExtResponse} Returns path to existing controller if found
|
|
114
|
+
*/
|
|
115
|
+
async function getExistingController(controllerName) {
|
|
116
|
+
return request(`${ApiEndpoints.CODE_EXT}/${controllerName}`, RequestMethod.GET);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Writes a change object to the project's workspace
|
|
121
|
+
*
|
|
122
|
+
* @param data Data to be send to the server
|
|
123
|
+
* @returns Generic Promise<T>
|
|
124
|
+
*/
|
|
125
|
+
async function writeChange(data) {
|
|
126
|
+
return request(ApiEndpoints.CHANGES, RequestMethod.POST, data);
|
|
127
|
+
}
|
|
128
|
+
var __exports = {
|
|
129
|
+
__esModule: true
|
|
130
|
+
};
|
|
131
|
+
__exports.ApiEndpoints = ApiEndpoints;
|
|
132
|
+
__exports.RequestMethod = RequestMethod;
|
|
133
|
+
__exports.request = request;
|
|
134
|
+
__exports.getFragments = getFragments;
|
|
135
|
+
__exports.writeFragment = writeFragment;
|
|
136
|
+
__exports.getManifestAppdescr = getManifestAppdescr;
|
|
137
|
+
__exports.readControllers = readControllers;
|
|
138
|
+
__exports.writeController = writeController;
|
|
139
|
+
__exports.getExistingController = getExistingController;
|
|
140
|
+
__exports.writeChange = writeChange;
|
|
141
|
+
return __exports;
|
|
142
142
|
});
|
|
143
143
|
//# sourceMappingURL=api-handler.js.map
|