@sap-ux/preview-middleware 0.23.44 → 0.23.46

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
@@ -32,7 +32,7 @@ When this middleware is used together with the `reload-middleware`, then the ord
32
32
  | `editors.rta` | `array` | optional | `undefined` | Configuration allowing to add mount points for runtime adaptation |
33
33
  | `editors.rta.layer` | `string` | optional | `(calculated)` | Property for defining the runtime adaptation layer for changes (default is `CUSTOMER_BASE` or read from the project for adaptation projects) |
34
34
  | `editors.rta.endpoints` | `array` | optional | `undefined` | List of mount points for editing |
35
- | `editors.cardGenerator` | --- | optional | `undefined` | Configuration object to enable card generation for an application (only supported for non-CAP apps). |
35
+ | `editors.cardGenerator` | --- | optional | `undefined` | Configuration object that enables card generation for an application. The generated cards are only available when the application is deployed to an ABAP-based SAP Fiori launchpad, such as SAP Fiori launchpad in SAP S/4HANA Cloud Public Edition. |
36
36
  | `editors.cardGenerator.path` | `string` | optional | `test/flpGeneratorSandbox.html` | The mount point of the local SAP Fiori launchpad which will be considered for card generation. |
37
37
  | `test` | `array` | optional | `undefined` | List of configurations for automated testing. |
38
38
  | `debug` | `boolean` | optional | `false` | Enables the debug output |
package/dist/base/flp.js CHANGED
@@ -401,13 +401,7 @@ class FlpSandbox {
401
401
  const previewGeneratorPath = this.cardGenerator?.path ?? config_1.CARD_GENERATOR_DEFAULT.previewGeneratorSandbox;
402
402
  this.logger.debug(`Add route for ${previewGeneratorPath}`);
403
403
  this.router.get(previewGeneratorPath, async (req, res, next) => {
404
- if (this.projectType === 'EDMXBackend') {
405
- this.templateConfig.enableCardGenerator = !!this.cardGenerator?.path;
406
- }
407
- else {
408
- this.logger.warn(`The Card Generator is not available for CAP projects.`);
409
- this.templateConfig.enableCardGenerator = false;
410
- }
404
+ this.templateConfig.enableCardGenerator = !!this.cardGenerator?.path;
411
405
  await this.flpGetHandler(req, res, next);
412
406
  });
413
407
  }
@@ -829,9 +823,6 @@ class FlpSandbox {
829
823
  * @returns {Promise<void>} A promise that resolves when the route is added.
830
824
  */
831
825
  async addStoreCardManifestRoute() {
832
- if (this.projectType !== 'EDMXBackend') {
833
- return;
834
- }
835
826
  this.router.use(config_1.CARD_GENERATOR_DEFAULT.cardsStore, (0, express_1.json)());
836
827
  this.logger.debug(`Add route for ${config_1.CARD_GENERATOR_DEFAULT.cardsStore}`);
837
828
  this.router.post(config_1.CARD_GENERATOR_DEFAULT.cardsStore, async (req, res) => {
@@ -849,14 +840,32 @@ class FlpSandbox {
849
840
  try {
850
841
  this.fs = this.fs ?? (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
851
842
  const webappPath = await (0, project_access_1.getWebappPath)(node_path_1.default.resolve(), this.fs);
852
- const i18nPath = this.manifest['sap.app'].i18n;
853
- const filePath = i18nPath ? (0, node_path_1.join)(webappPath, i18nPath) : (0, node_path_1.join)(webappPath, 'i18n', 'i18n.properties');
854
- const entries = req.body || [];
855
- entries.forEach((entry) => {
856
- if (entry.comment) {
857
- entry.annotation = entry.comment;
858
- }
859
- });
843
+ const i18nConfig = this.manifest['sap.app'].i18n;
844
+ let i18nPath = 'i18n/i18n.properties';
845
+ let fallbackLocale;
846
+ let supportedLocales = [];
847
+ if (typeof i18nConfig === 'string') {
848
+ i18nPath = i18nConfig;
849
+ }
850
+ else if (typeof i18nConfig === 'object' && i18nConfig !== null && 'bundleUrl' in i18nConfig) {
851
+ const { bundleUrl: i18nPathFromConfig, supportedLocales: locales = [], fallbackLocale: fallback } = i18nConfig;
852
+ i18nPath = i18nPathFromConfig;
853
+ supportedLocales = locales;
854
+ fallbackLocale = fallback;
855
+ }
856
+ const requestedLocale = req.query.locale || fallbackLocale || '';
857
+ const baseFilePath = (0, node_path_1.join)(webappPath, i18nPath);
858
+ const filePath = requestedLocale
859
+ ? baseFilePath.replace('.properties', `_${requestedLocale}.properties`)
860
+ : baseFilePath;
861
+ if (requestedLocale && supportedLocales.length > 0 && !supportedLocales.includes(requestedLocale)) {
862
+ this.sendResponse(res, 'text/plain', 400, `Locale "${requestedLocale}" is not supported. Supported: ${supportedLocales.join(', ')}`);
863
+ return;
864
+ }
865
+ const entries = (req.body || []).map((entry) => ({
866
+ ...entry,
867
+ annotation: entry.comment ?? entry.annotation
868
+ }));
860
869
  await (0, i18n_1.createPropertiesI18nEntries)(filePath, entries);
861
870
  this.fs.commit(() => this.sendResponse(res, 'text/plain', 201, `i18n file updated.`));
862
871
  }
@@ -872,9 +881,6 @@ class FlpSandbox {
872
881
  * @returns {Promise<void>} A promise that resolves when the route is added.
873
882
  */
874
883
  async addStoreI18nKeysRoute() {
875
- if (this.projectType !== 'EDMXBackend') {
876
- return;
877
- }
878
884
  this.router.use(config_1.CARD_GENERATOR_DEFAULT.i18nStore, (0, express_1.json)());
879
885
  this.logger.debug(`Add route for ${config_1.CARD_GENERATOR_DEFAULT.i18nStore}`);
880
886
  this.router.post(config_1.CARD_GENERATOR_DEFAULT.i18nStore, async (req, res) => {
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.23.44",
12
+ "version": "0.23.46",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -28,10 +28,10 @@
28
28
  "qrcode": "1.5.4",
29
29
  "@sap/bas-sdk": "3.12.0",
30
30
  "@sap-ux/adp-tooling": "0.17.5",
31
- "@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.7.1",
32
31
  "@sap-ux/feature-toggle": "0.3.3",
33
- "@sap-ux/logger": "0.7.0",
34
32
  "@sap-ux/btp-utils": "1.1.4",
33
+ "@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.7.1",
34
+ "@sap-ux/logger": "0.7.0",
35
35
  "@sap-ux/project-access": "1.32.7",
36
36
  "@sap-ux/system-access": "0.6.27",
37
37
  "@sap-ux/i18n": "0.3.4"