@sap-ux/preview-middleware 0.13.8 → 0.13.10

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.
@@ -121,6 +121,17 @@ export declare class FlpSandbox {
121
121
  * Create required routes for flex.
122
122
  */
123
123
  private createFlexHandler;
124
+ /**
125
+ * Send a response with the given content type, status and body.
126
+ * Ensure compliance with common APIs in express and connect.
127
+ *
128
+ * @param res the response object
129
+ * @param contentType the content type
130
+ * @param status the response status
131
+ * @param body the response body
132
+ * @private
133
+ */
134
+ private sendResponse;
124
135
  /**
125
136
  * Add routes for html and scripts required for a local test FLP.
126
137
  *
package/dist/base/flp.js CHANGED
@@ -222,7 +222,7 @@ class FlpSandbox {
222
222
  scenario,
223
223
  livereloadPort
224
224
  });
225
- res.status(200).contentType('html').send(html);
225
+ this.sendResponse(res, 'text/html', 200, html);
226
226
  });
227
227
  let path = (0, path_1.dirname)(editor.path);
228
228
  if (!path.endsWith('/')) {
@@ -232,7 +232,7 @@ class FlpSandbox {
232
232
  }
233
233
  this.router.get(previewUrl, (_req, res) => {
234
234
  const html = this.generateSandboxForEditor(rta, editor).replace('</body>', `</body>\n<!-- livereload disabled for editor </body>-->`);
235
- res.status(200).contentType('html').send(html);
235
+ this.sendResponse(res, 'text/html', 200, html);
236
236
  });
237
237
  }
238
238
  }
@@ -251,7 +251,7 @@ class FlpSandbox {
251
251
  }
252
252
  const template = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../templates/flp/sandbox.html'), 'utf-8');
253
253
  const html = (0, ejs_1.render)(template, this.templateConfig);
254
- res.status(200).contentType('html').send(html);
254
+ this.sendResponse(res, 'text/html', 200, html);
255
255
  })));
256
256
  }
257
257
  /**
@@ -324,39 +324,54 @@ class FlpSandbox {
324
324
  const api = `${PREVIEW_URL.api}/changes`;
325
325
  this.router.use(api, (0, express_1.json)());
326
326
  this.router.get(api, ((_req, res) => __awaiter(this, void 0, void 0, function* () {
327
- res.status(200)
328
- .contentType('application/json')
329
- .send(yield (0, flex_1.readChanges)(this.project, this.logger));
327
+ this.sendResponse(res, 'application/json', 200, JSON.stringify(yield (0, flex_1.readChanges)(this.project, this.logger)));
330
328
  })));
331
329
  this.router.post(api, ((req, res) => __awaiter(this, void 0, void 0, function* () {
332
330
  try {
333
331
  const { success, message } = (0, flex_1.writeChange)(req.body, this.utils.getProject().getSourcePath(), this.logger);
334
332
  if (success) {
335
- res.status(200).send(message);
333
+ this.sendResponse(res, 'text/plain', 200, message !== null && message !== void 0 ? message : '');
336
334
  }
337
335
  else {
338
- res.status(400).send('INVALID_DATA');
336
+ this.sendResponse(res, 'text/plain', 400, 'INVALID_DATA');
339
337
  }
340
338
  }
341
339
  catch (error) {
342
- res.status(500).send(error.message);
340
+ this.sendResponse(res, 'text/plain', 500, error.message);
343
341
  }
344
342
  })));
345
343
  this.router.delete(api, ((req, res) => __awaiter(this, void 0, void 0, function* () {
346
344
  try {
347
345
  const { success, message } = (0, flex_1.deleteChange)(req.body, this.utils.getProject().getSourcePath(), this.logger);
348
346
  if (success) {
349
- res.status(200).send(message);
347
+ this.sendResponse(res, 'text/plain', 200, message !== null && message !== void 0 ? message : '');
350
348
  }
351
349
  else {
352
- res.status(400).send('INVALID_DATA');
350
+ this.sendResponse(res, 'text/plain', 400, 'INVALID_DATA');
353
351
  }
354
352
  }
355
353
  catch (error) {
356
- res.status(500).send(error.message);
354
+ this.sendResponse(res, 'text/plain', 500, error.message);
357
355
  }
358
356
  })));
359
357
  }
358
+ /**
359
+ * Send a response with the given content type, status and body.
360
+ * Ensure compliance with common APIs in express and connect.
361
+ *
362
+ * @param res the response object
363
+ * @param contentType the content type
364
+ * @param status the response status
365
+ * @param body the response body
366
+ * @private
367
+ */
368
+ sendResponse(res, contentType, status, body) {
369
+ res.writeHead(status, {
370
+ 'Content-Type': contentType
371
+ });
372
+ res.write(body);
373
+ res.end();
374
+ }
360
375
  /**
361
376
  * Add routes for html and scripts required for a local test FLP.
362
377
  *
@@ -387,7 +402,7 @@ class FlpSandbox {
387
402
  initPath: `${ns}${config.init.replace('.js', '')}`
388
403
  };
389
404
  const html = (0, ejs_1.render)(htmlTemplate, templateConfig);
390
- res.status(200).contentType('html').send(html);
405
+ this.sendResponse(res, 'text/html', 200, html);
391
406
  }
392
407
  })));
393
408
  if (testConfig.init !== undefined) {
@@ -406,8 +421,8 @@ class FlpSandbox {
406
421
  else {
407
422
  const testFiles = yield this.project.byGlob(config.pattern);
408
423
  const templateConfig = { tests: (0, test_1.generateImportList)(ns, testFiles) };
409
- const html = (0, ejs_1.render)(initTemplate, templateConfig);
410
- res.status(200).contentType('application/javascript').send(html);
424
+ const js = (0, ejs_1.render)(initTemplate, templateConfig);
425
+ this.sendResponse(res, 'application/javascript', 200, js);
411
426
  }
412
427
  })));
413
428
  }
@@ -75,7 +75,7 @@ export async function request<T>(endpoint: ApiEndpoints, method: RequestMethod,
75
75
 
76
76
  switch (method) {
77
77
  case RequestMethod.GET:
78
- return response.json();
78
+ return response.json() as T;
79
79
  case RequestMethod.POST:
80
80
  /**
81
81
  * Since POST usually creates something
@@ -83,7 +83,7 @@ export async function request<T>(endpoint: ApiEndpoints, method: RequestMethod,
83
83
  */
84
84
  return response.text() as T;
85
85
  default:
86
- return response.json();
86
+ return response.json() as T;
87
87
  }
88
88
  } catch (e) {
89
89
  throw new Error(e.message);
@@ -86,9 +86,9 @@ sap.ui.define(["sap/m/MessageToast", "sap/ui/model/json/JSONModel", "../api-hand
86
86
  MessageToast.show(e.message);
87
87
  throw new Error(e.message);
88
88
  }
89
- await this.createExtensionPointFragmentChange(fragmentName);
89
+ this.createExtensionPointFragmentChange(fragmentName);
90
90
  },
91
- createExtensionPointFragmentChange: async function _createExtensionPointFragmentChange(fragmentName) {
91
+ createExtensionPointFragmentChange: function _createExtensionPointFragmentChange(fragmentName) {
92
92
  const extensionPointName = this.model.getProperty('/extensionPointName');
93
93
  const modifiedValue = {
94
94
  fragmentPath: `fragments/${fragmentName}.fragment.xml`,
@@ -142,7 +142,7 @@ export default class ExtensionPoint extends BaseDialog {
142
142
  throw new Error(e.message);
143
143
  }
144
144
 
145
- await this.createExtensionPointFragmentChange(fragmentName);
145
+ this.createExtensionPointFragmentChange(fragmentName);
146
146
  }
147
147
 
148
148
  /**
@@ -150,7 +150,7 @@ export default class ExtensionPoint extends BaseDialog {
150
150
  *
151
151
  * @param fragmentName Fragment name
152
152
  */
153
- private async createExtensionPointFragmentChange(fragmentName: string): Promise<void> {
153
+ private createExtensionPointFragmentChange(fragmentName: string): void {
154
154
  const extensionPointName = this.model.getProperty('/extensionPointName');
155
155
  const modifiedValue = {
156
156
  fragmentPath: `fragments/${fragmentName}.fragment.xml`,
@@ -52,7 +52,7 @@ sap.ui.define([
52
52
  const extPointService = new ExtensionPointService(rta);
53
53
  extPointService.init(subscribe);
54
54
  }
55
- init(rta);
55
+ await init(rta);
56
56
  const ui5VersionValidationMsg = getUI5VersionValidationMessage(version);
57
57
  if (ui5VersionValidationMsg) {
58
58
  sendAction(showMessage(ui5VersionValidationMsg));
@@ -51,7 +51,7 @@ export default async function (rta: RuntimeAuthoring) {
51
51
  }
52
52
 
53
53
  // also initialize the editor
54
- init(rta);
54
+ await init(rta);
55
55
 
56
56
  const ui5VersionValidationMsg = getUI5VersionValidationMessage(version);
57
57
 
@@ -120,6 +120,7 @@ export class ChangeService {
120
120
  if (control) {
121
121
  name = control.getMetadata().getName();
122
122
  }
123
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
123
124
  const modifiedMessage = modifyRTAErrorMessage(exception?.toString(), id, name);
124
125
  const errorMessage =
125
126
  modifiedMessage || `RTA Exception applying expression "${action.payload.value}"`;
@@ -379,9 +380,10 @@ export class ChangeService {
379
380
  private getCommandSelectorId(command: FlexCommand): string | undefined {
380
381
  return this.retryOperations([
381
382
  () => command.getSelector().id,
383
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
382
384
  () => command.getElement().getProperty('persistencyKey'),
383
385
  () => command.getElement().getId(),
384
386
  () => command.getParent()?.getElement().getId()
385
- ]);
387
+ ]) as string | undefined;
386
388
  }
387
389
  }
@@ -102,6 +102,7 @@ function analyzePropertyType(property: ManagedObjectMetadataProperties): Analyze
102
102
  if (propertyDataType && !(propertyDataType instanceof DataType)) {
103
103
  return analyzedType;
104
104
  }
105
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
105
106
  const name = Object.getPrototypeOf(propertyDataType).getName();
106
107
  if (!name) {
107
108
  analyzedType.primitiveType = 'enum';
@@ -1,5 +1,5 @@
1
1
  import { getLibrary } from './utils';
2
- import type { SchemaForApiJsonFiles, Ui5Property } from './api-json';
2
+ import type { SchemaForApiJsonFiles, Ui5Metadata, Ui5Property } from './api-json';
3
3
  import type { Properties } from './utils';
4
4
  import Log from 'sap/base/Log';
5
5
  import { PropertiesInfo } from '@sap-ux-private/control-property-editor-common';
@@ -18,7 +18,7 @@ export interface ControlMetadata {
18
18
  */
19
19
  export async function getUi5ApiDtMetadata(libName: string): Promise<SchemaForApiJsonFiles> {
20
20
  const libUrl = '/test-resources/' + libName.split('.').join('/') + '/designtime/api.json';
21
- return fetch(libUrl).then((res) => res.json());
21
+ return fetch(libUrl).then((res) => res.json() as unknown as SchemaForApiJsonFiles);
22
22
  }
23
23
 
24
24
  /**
@@ -85,7 +85,9 @@ function parseControlMetaModel(controlLibMetadata: SchemaForApiJsonFiles, contro
85
85
  // base type info of control is available on property 'extends'
86
86
  controlInfo.baseType = selectedControlMetadata.extends;
87
87
  controlInfo.doc = selectedControlMetadata.description ?? '';
88
- const properties = selectedControlMetadata['ui5-metadata'].properties;
88
+ const properties: (Ui5Property & PropertiesInfo)[] | undefined = (
89
+ selectedControlMetadata['ui5-metadata'] as Ui5Metadata
90
+ ).properties as (Ui5Property & PropertiesInfo)[] | undefined;
89
91
  if (properties) {
90
92
  properties.forEach((prop: Ui5Property & PropertiesInfo) => {
91
93
  prop.description = formatHtmlText(prop.description || '');
@@ -5,7 +5,7 @@ sap.ui.define(["sap/base/Log"], function (Log) {
5
5
 
6
6
  function getString(message) {
7
7
  if (typeof message === 'object') {
8
- return message.toString();
8
+ return JSON.stringify(message).toString();
9
9
  }
10
10
  return message;
11
11
  }
@@ -4,7 +4,7 @@ import { Logger } from '@sap-ux-private/control-property-editor-common';
4
4
 
5
5
  function getString(message: string | object): string {
6
6
  if (typeof message === 'object') {
7
- return message.toString();
7
+ return JSON.stringify(message).toString();
8
8
  }
9
9
  return message;
10
10
  }
@@ -45,7 +45,7 @@ sap.ui.define(["./utils"], function (___utils) {
45
45
  const items = [];
46
46
  while (stack.length) {
47
47
  const current = stack.shift();
48
- const editable = await isEditable(current?.id);
48
+ const editable = isEditable(current?.id);
49
49
  if (current?.type === 'element') {
50
50
  const children = getChildren(current);
51
51
  const {
@@ -48,7 +48,7 @@ export async function transformNodes(input: OutlineViewNode[], scenario: Scenari
48
48
  const items: OutlineNode[] = [];
49
49
  while (stack.length) {
50
50
  const current = stack.shift();
51
- const editable = await isEditable(current?.id);
51
+ const editable = isEditable(current?.id);
52
52
  if (current?.type === 'element') {
53
53
  const children = getChildren(current);
54
54
  const { text } = getAdditionalData(current.id);
@@ -54,7 +54,7 @@ sap.ui.define([
54
54
  constructor(rta) {
55
55
  this.rta = rta;
56
56
  }
57
- async init(sendAction, subscribe) {
57
+ init(sendAction, subscribe) {
58
58
  const eventOrigin = new Set();
59
59
  const onselectionChange = this.createOnSelectionChangeHandler(sendAction, eventOrigin);
60
60
  this.rta.attachSelectionChange(event => {
@@ -101,7 +101,7 @@ export class SelectionService implements Service {
101
101
  * @param sendAction action sender function
102
102
  * @param subscribe subscriber function
103
103
  */
104
- public async init(sendAction: ActionSenderFunction, subscribe: SubscribeFunction): Promise<void> {
104
+ public init(sendAction: ActionSenderFunction, subscribe: SubscribeFunction): void {
105
105
  const eventOrigin: Set<string> = new Set();
106
106
  const onselectionChange = this.createOnSelectionChangeHandler(sendAction, eventOrigin);
107
107
  this.rta.attachSelectionChange((event) => {
@@ -185,8 +185,10 @@ export class SelectionService implements Service {
185
185
  const isOutline = eventOrigin.has('outline');
186
186
  const name = controlName.toLowerCase().startsWith('sap') ? controlName : 'Other Control Types';
187
187
  if (isOutline) {
188
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
188
189
  reportTelemetry({ category: 'Outline Selection', controlName: name });
189
190
  } else {
191
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
190
192
  reportTelemetry({ category: 'Overlay Selection', controlName: name });
191
193
  }
192
194
  } catch (error) {
@@ -18,7 +18,7 @@ const connector = merge({}, ObjectStorageConnector, {
18
18
 
19
19
  if (typeof this.fileChangeRequestNotifier === 'function' && change.fileName) {
20
20
  try {
21
- this.fileChangeRequestNotifier(change.fileName, 'create', change.changeType);
21
+ this.fileChangeRequestNotifier(change.fileName, 'create', change.changeType);
22
22
  } catch (e) {
23
23
  // exceptions in the listener call are ignored
24
24
  }
@@ -62,7 +62,7 @@ const connector = merge({}, ObjectStorageConnector, {
62
62
  'content-type': 'application/json'
63
63
  }
64
64
  });
65
- const changes = await response.json();
65
+ const changes = await response.json() as unknown as FlexChange[];
66
66
  return changes;
67
67
  }
68
68
  } as typeof ObjectStorageConnector.storage,
@@ -18,11 +18,11 @@ export const CHANGES_API_PATH = '/preview/api/changes';
18
18
  * @returns {FlexSettings | undefined} The parsed Flex settings if available, otherwise undefined.
19
19
  */
20
20
  export function getFlexSettings(): FlexSettings | undefined {
21
- let result;
21
+ let result: FlexSettings | undefined;
22
22
  const bootstrapConfig = document.getElementById('sap-ui-bootstrap');
23
23
  const flexSetting = bootstrapConfig?.getAttribute('data-open-ux-preview-flex-settings');
24
24
  if (flexSetting) {
25
- result = JSON.parse(flexSetting);
25
+ result = JSON.parse(flexSetting) as FlexSettings;
26
26
  }
27
27
  return result;
28
28
  }
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.13.8",
12
+ "version": "0.13.10",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -23,9 +23,9 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "ejs": "3.1.9",
26
- "@sap-ux/adp-tooling": "0.9.10",
27
- "@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.4.17",
28
26
  "@sap-ux/logger": "0.5.1",
27
+ "@sap-ux/adp-tooling": "0.9.11",
28
+ "@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.4.17",
29
29
  "@sap-ux/project-access": "1.19.6"
30
30
  },
31
31
  "devDependencies": {
@@ -40,8 +40,8 @@
40
40
  "supertest": "6.3.3",
41
41
  "@sap-ux-private/playwright": "0.0.3",
42
42
  "dotenv": "16.3.1",
43
- "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.9.4",
44
- "@sap-ux/axios-extension": "1.11.5",
43
+ "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.9.5",
44
+ "@sap-ux/axios-extension": "1.11.6",
45
45
  "@sap-ux/store": "0.5.0",
46
46
  "@sap-ux/i18n": "0.0.5"
47
47
  },