Socket
Socket
Sign inDemoInstall

@sap-ux/ui5-config

Package Overview
Dependencies
Maintainers
3
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sap-ux/ui5-config - npm Package Compare versions

Comparing version 0.9.3 to 0.10.0

11

CHANGELOG.md
# @sap-ux/ui5-config
## 0.10.0
### Minor Changes
- d37c8bd: Added support for selecting a custom view name for Fiori freestyle - Basic template
### Patch Changes
- Updated dependencies [d37c8bd]
- @sap-ux/yaml@0.10.0
## 0.9.3

@@ -4,0 +15,0 @@

2

dist/index.d.ts
export { UI5Config } from './ui5-config';
export * from './middlewares';
export { CustomMiddleware, FioriAppReloadConfig, FioriToolsProxyConfig, ProxyBackend, ProxyUIConfig } from './types';
//# sourceMappingURL=index.d.ts.map
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -16,3 +6,2 @@ exports.UI5Config = void 0;

Object.defineProperty(exports, "UI5Config", { enumerable: true, get: function () { return ui5_config_1.UI5Config; } });
__exportStar(require("./middlewares"), exports);
//# sourceMappingURL=index.js.map

@@ -1,21 +0,17 @@

import type { MiddlewareConfig } from './types';
import type { ProxyBackend, CustomMiddleware, FioriAppReloadConfig, FioriToolsProxyConfig, MockserverConfig, ProxyUIConfig } from './types';
import type { NodeComment } from '@sap-ux/yaml';
import type { Editor } from 'mem-fs-editor';
export declare const getAppReloadMiddlewareConfig: () => MiddlewareConfig[];
export declare const getFioriToolsProxyMiddlewareConfig: ({ url, path, destination, client }: {
url?: string | undefined;
path?: string | undefined;
destination?: {
name?: string | undefined;
instance?: string | undefined;
} | undefined;
client?: string | undefined;
}, useUi5Cdn?: boolean, ui5CdnUrl?: string, ui5Version?: string) => {
config: MiddlewareConfig[];
comments: NodeComment<MiddlewareConfig>[];
/**
* @returns {FioriAppReloadConfig}
*/
export declare function getAppReloadMiddlewareConfig(): CustomMiddleware<FioriAppReloadConfig>;
/**
* @param backends
* @param ui5
* @returns {{config, comments}}
*/
export declare function getFioriToolsProxyMiddlewareConfig(backends?: ProxyBackend[], ui5?: ProxyUIConfig): {
config: CustomMiddleware<FioriToolsProxyConfig>;
comments: NodeComment<CustomMiddleware<FioriToolsProxyConfig>>[];
};
export declare const getMockServerMiddlewareConfig: ({ path }: {
path?: string | undefined;
}) => MiddlewareConfig[];
export declare const addMiddlewareConfig: (fs: Editor, basePath: string, filename: string, middlewares: MiddlewareConfig[], comments?: NodeComment<MiddlewareConfig>[] | undefined) => Promise<void>;
export declare const getMockServerMiddlewareConfig: (path?: string | undefined) => CustomMiddleware<MockserverConfig>;
//# sourceMappingURL=middlewares.d.ts.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.addMiddlewareConfig = exports.getMockServerMiddlewareConfig = exports.getFioriToolsProxyMiddlewareConfig = exports.getAppReloadMiddlewareConfig = void 0;
const path_1 = require("path");
const ui5_config_1 = require("./ui5-config");
const constants_1 = require("./constants");
const getAppReloadMiddlewareConfig = () => {
return [
{
name: 'fiori-tools-appreload',
afterMiddleware: 'compression',
configuration: {
port: 35729,
path: 'webapp'
}
exports.getMockServerMiddlewareConfig = exports.getFioriToolsProxyMiddlewareConfig = exports.getAppReloadMiddlewareConfig = void 0;
/**
* @returns {FioriAppReloadConfig}
*/
function getAppReloadMiddlewareConfig() {
return {
name: 'fiori-tools-appreload',
afterMiddleware: 'compression',
configuration: {
port: 35729,
path: 'webapp'
}
];
};
};
}
exports.getAppReloadMiddlewareConfig = getAppReloadMiddlewareConfig;
const getFioriToolsProxyMiddlewareConfig = ({ url, path, destination, client }, useUi5Cdn = true, ui5CdnUrl = 'https://ui5.sap.com', ui5Version = '') => {
/**
* @param backends
* @param ui5
* @returns {{config, comments}}
*/
function getFioriToolsProxyMiddlewareConfig(backends, ui5) {
const fioriToolsProxy = {

@@ -37,34 +31,23 @@ name: 'fiori-tools-proxy',

};
if (url || path || (destination === null || destination === void 0 ? void 0 : destination.name) || (destination === null || destination === void 0 ? void 0 : destination.instance)) {
const rootSegment = path === null || path === void 0 ? void 0 : path.split('/').filter((s) => s !== '')[0];
const backend = {
path: `/${rootSegment || ''}`,
url: url !== null && url !== void 0 ? url : constants_1.DEFAULT_HOST
};
if (client) {
Object.assign(backend, { client: client });
const comments = [
{
path: 'configuration.ignoreCertError',
comment: ' If set to true, certificate errors will be ignored. E.g. self-signed certificates will be accepted'
}
if (destination === null || destination === void 0 ? void 0 : destination.name) {
Object.assign(backend, { destination: destination.name });
}
if (destination === null || destination === void 0 ? void 0 : destination.instance) {
Object.assign(backend, { destinationInstance: destination.instance });
}
fioriToolsProxy.configuration.backend = [backend];
];
if (backends && backends.length > 0) {
backends.forEach((element) => {
element.path = element.path || '/';
});
fioriToolsProxy.configuration.backend = backends;
}
if (useUi5Cdn === true) {
if (ui5 !== undefined) {
fioriToolsProxy.configuration['ui5'] = {
path: ['/resources', '/test-resources'],
url: ui5CdnUrl,
version: ui5Version !== null && ui5Version !== void 0 ? ui5Version : ''
url: ui5.url || 'https://ui5.sap.com',
version: ui5.version || ''
};
}
const config = [fioriToolsProxy];
const comments = [
{
path: 'configuration.ignoreCertError',
comment: ' If set to true, certificate errors will be ignored. E.g. self-signed certificates will be accepted'
if (ui5.directLoad) {
fioriToolsProxy.configuration['ui5'].directLoad = true;
}
];
if (useUi5Cdn === true) {
comments.push({

@@ -75,33 +58,22 @@ path: 'configuration.ui5.version',

}
return { config, comments };
};
return { config: fioriToolsProxy, comments };
}
exports.getFioriToolsProxyMiddlewareConfig = getFioriToolsProxyMiddlewareConfig;
const getMockServerMiddlewareConfig = ({ path }) => {
const getMockServerMiddlewareConfig = (path) => {
const pathSegments = (path === null || path === void 0 ? void 0 : path.split('/')) || [];
return [
{
name: 'sap-fe-mockserver',
beforeMiddleware: 'fiori-tools-proxy',
configuration: {
service: {
urlBasePath: pathSegments.slice(0, -1).join('/'),
name: pathSegments[pathSegments.length - 1],
metadataXmlPath: './webapp/localService/metadata.xml',
mockdataRootPath: './webapp/localService/data',
generateMockData: true
}
return {
name: 'sap-fe-mockserver',
beforeMiddleware: 'fiori-tools-proxy',
configuration: {
service: {
urlBasePath: pathSegments.slice(0, -1).join('/'),
name: pathSegments[pathSegments.length - 1],
metadataXmlPath: './webapp/localService/metadata.xml',
mockdataRootPath: './webapp/localService/data',
generateMockData: true
}
}
];
};
};
exports.getMockServerMiddlewareConfig = getMockServerMiddlewareConfig;
const addMiddlewareConfig = (fs, basePath, filename, middlewares, comments) => __awaiter(void 0, void 0, void 0, function* () {
// update filename e.g. ui5.yaml
const ui5ConfigPath = path_1.join(basePath, filename);
const existingUI5Config = fs.read(ui5ConfigPath);
const ui5Config = yield ui5_config_1.UI5Config.newInstance(existingUI5Config);
ui5Config.addCustomMiddleware(middlewares, comments);
fs.write(ui5ConfigPath, ui5Config.toString());
});
exports.addMiddlewareConfig = addMiddlewareConfig;
//# sourceMappingURL=middlewares.js.map

@@ -1,10 +0,21 @@

export interface Destination {
destination: string;
export interface ProxyBackend {
path?: string;
url: string;
client?: string;
destination?: string;
destinationInstance?: string;
pathPrefix?: string;
scp?: boolean;
apiHub?: boolean;
ws?: boolean;
xfwd?: boolean;
}
export declare type Backend = Partial<Destination> & {
path: string;
url: string;
};
export interface MiddlewareConfig {
export interface ProxyUIConfig {
[key: string]: unknown | undefined;
path?: string[];
url?: string;
version?: string;
directLoad?: boolean;
}
export interface CustomMiddleware<C extends any> {
name: string;

@@ -14,25 +25,26 @@ beforeMiddleware?: string;

mountPath?: string;
configuration: {
port?: number;
path?: string;
annotations?: {
localPath?: string;
urlPath: string;
};
service?: {
urlBasePath: string;
name: string;
metadataXmlPath: string;
mockdataRootPath?: string;
generateMockData?: boolean;
};
backend?: Backend[];
ui5?: {
path: string[];
url: string;
version: string | null;
};
ignoreCertError?: boolean;
configuration: C;
}
export interface FioriAppReloadConfig {
port: number;
path: string;
}
export interface FioriToolsProxyConfig {
backend?: ProxyBackend[];
ui5?: ProxyUIConfig;
ignoreCertError?: boolean;
}
export interface MockserverConfig {
annotations?: {
localPath?: string;
urlPath: string;
};
service?: {
urlBasePath: string;
name: string;
metadataXmlPath: string;
mockdataRootPath?: string;
generateMockData?: boolean;
};
}
//# sourceMappingURL=types.d.ts.map

@@ -1,3 +0,4 @@

import { MiddlewareConfig } from './types';
import { FioriToolsProxyConfig, ProxyBackend } from './types';
import { NodeComment } from '@sap-ux/yaml';
import { CustomMiddleware } from 'index';
/**

@@ -22,13 +23,14 @@ * Represents a UI5 config file in yaml format (ui5(-*).yaml) with utility functions to manipulate the yaml document.

*
* @param {string} ui5Framework - whether to user SAPUI5 or OpenUI5
* @param {string} ui5Version - ui5 version
* @param {string[]} libraries - a list of libraries
* @param ui5Theme - ui5 theme
* @param {string[]} ui5Libraries - a list of libraries
* @param {string} ui5Theme - optional ui5 theme
* @returns {UI5Config} the UI5Config instance
* @memberof UI5Config
*/
addUI5Framework(ui5Version: string, libraries: string[], ui5Theme?: string): UI5Config;
addUI5Framework(ui5Framework: string, ui5Version: string, ui5Libraries: string[], ui5Theme?: string): UI5Config;
/**
* Adds a list of custom middlewares to the config.
*
* @param {MiddlewareConfig[]} middlewares - the list of custom middlewares
* @param {CustomMiddleware<any>[]} middlewares - the list of custom middlewares
* @param {NodeComment<MiddlewareConfig>[]} [comments] - a list of comments

@@ -38,4 +40,35 @@ * @returns {UI5Config} the UI5Config instance

*/
addCustomMiddleware(middlewares: MiddlewareConfig[], comments?: NodeComment<MiddlewareConfig>[]): UI5Config;
addCustomMiddleware(middlewares: CustomMiddleware<any>[], comments?: NodeComment<CustomMiddleware<any>>[]): UI5Config;
/**
* Adds a instance of the Fiori tools app-reload middleware to the config.
*
* @returns {UI5Config} the UI5Config instance
* @memberof UI5Config
*/
addFioriToolsAppReloadMiddleware(): UI5Config;
/**
* Adds a instance of the Fiori tools proxy middleware to the config.
*
* @param proxyConfig proxy configuration containing an optional array of backend and an option UI5 host configuration
* @returns {UI5Config} the UI5Config instance
* @memberof UI5Config
*/
addFioriToolsProxydMiddleware(proxyConfig: FioriToolsProxyConfig): UI5Config;
/**
* Adds a backend configuration to an existing fiori-tools-proxy middleware. If the config does not contain a fiori-tools-proxy middleware, an error is thrown.
*
* @param backend config of backend that is to be proxied
* @returns {UI5Config} the UI5Config instance
* @memberof UI5Config
*/
addBackendToFioriToolsProxydMiddleware(backend: ProxyBackend): UI5Config;
/**
* Adds a instance of the mockserver middleware to the config.
*
* @param path option path that is to be mocked
* @returns {UI5Config} the UI5Config instance
* @memberof UI5Config
*/
addMockServerMiddleware(path?: string): UI5Config;
/**
* Returns a string representation of the config.

@@ -42,0 +75,0 @@ *

@@ -14,2 +14,3 @@ "use strict";

const yaml_1 = require("@sap-ux/yaml");
const middlewares_1 = require("./middlewares");
/**

@@ -39,19 +40,19 @@ * Represents a UI5 config file in yaml format (ui5(-*).yaml) with utility functions to manipulate the yaml document.

*
* @param {string} ui5Framework - whether to user SAPUI5 or OpenUI5
* @param {string} ui5Version - ui5 version
* @param {string[]} libraries - a list of libraries
* @param ui5Theme - ui5 theme
* @param {string[]} ui5Libraries - a list of libraries
* @param {string} ui5Theme - optional ui5 theme
* @returns {UI5Config} the UI5Config instance
* @memberof UI5Config
*/
addUI5Framework(ui5Version, libraries, ui5Theme = 'sap_fiori_3') {
addUI5Framework(ui5Framework, ui5Version, ui5Libraries, ui5Theme = 'sap_fiori_3') {
const libraryObjs = [];
for (const library of libraries) {
for (const library of ui5Libraries) {
libraryObjs.push({ name: library });
}
// Add theme lib
ui5Theme = ui5Theme.replace(/_dark$/, ''); // Dark theme versions are provided by base theme lib
libraryObjs.push({ name: `themelib_${ui5Theme}` });
// Add theme lib (dark theme versions are provided by base theme lib)
libraryObjs.push({ name: `themelib_${ui5Theme.replace(/_dark$/, '')}` });
this.document.setIn({
path: 'framework',
value: { name: 'SAPUI5', version: ui5Version, libraries: libraryObjs }
value: { name: ui5Framework, version: ui5Version, libraries: libraryObjs }
});

@@ -63,3 +64,3 @@ return this;

*
* @param {MiddlewareConfig[]} middlewares - the list of custom middlewares
* @param {CustomMiddleware<any>[]} middlewares - the list of custom middlewares
* @param {NodeComment<MiddlewareConfig>[]} [comments] - a list of comments

@@ -76,2 +77,61 @@ * @returns {UI5Config} the UI5Config instance

/**
* Adds a instance of the Fiori tools app-reload middleware to the config.
*
* @returns {UI5Config} the UI5Config instance
* @memberof UI5Config
*/
addFioriToolsAppReloadMiddleware() {
this.document.appendTo({
path: 'server.customMiddleware',
value: middlewares_1.getAppReloadMiddlewareConfig()
});
return this;
}
/**
* Adds a instance of the Fiori tools proxy middleware to the config.
*
* @param proxyConfig proxy configuration containing an optional array of backend and an option UI5 host configuration
* @returns {UI5Config} the UI5Config instance
* @memberof UI5Config
*/
addFioriToolsProxydMiddleware(proxyConfig) {
const { config, comments } = middlewares_1.getFioriToolsProxyMiddlewareConfig(proxyConfig.backend, proxyConfig.ui5);
this.document.appendTo({
path: 'server.customMiddleware',
value: config,
comments: comments
});
return this;
}
/**
* Adds a backend configuration to an existing fiori-tools-proxy middleware. If the config does not contain a fiori-tools-proxy middleware, an error is thrown.
*
* @param backend config of backend that is to be proxied
* @returns {UI5Config} the UI5Config instance
* @memberof UI5Config
*/
addBackendToFioriToolsProxydMiddleware(backend) {
const middlewareList = this.document.getSequence({ path: 'server.customMiddleware' });
const proxyMiddleware = this.document.findItem(middlewareList, (item) => item.name === 'fiori-tools-proxy');
if (!proxyMiddleware) {
throw new Error('Could not find fiori-tools-proxy');
}
this.document.getMap({ start: proxyMiddleware, path: 'configuration' }).set('backend', [backend]);
return this;
}
/**
* Adds a instance of the mockserver middleware to the config.
*
* @param path option path that is to be mocked
* @returns {UI5Config} the UI5Config instance
* @memberof UI5Config
*/
addMockServerMiddleware(path) {
this.document.appendTo({
path: 'server.customMiddleware',
value: middlewares_1.getMockServerMiddlewareConfig(path)
});
return this;
}
/**
* Returns a string representation of the config.

@@ -78,0 +138,0 @@ *

{
"name": "@sap-ux/ui5-config",
"description": "Library to UI5 configuration artifacts",
"version": "0.9.3",
"version": "0.10.0",
"license": "Apache-2.0",

@@ -12,3 +12,3 @@ "main": "dist/index.js",

"dependencies": {
"@sap-ux/yaml": "0.9.2",
"@sap-ux/yaml": "0.10.0",
"typescript": "4.2.4"

@@ -15,0 +15,0 @@ },

# @sap-ux/ui5-config
Utility module to create and update [UI5 tooling configuration](https://sap.github.io/ui5-tooling/pages/Configuration/) files (`ui5*.yaml`) with helper methods specifically for Fiori tools middlewares.
Utilities functions to generate middleware sections in ui*.yaml files
## Installation

@@ -18,5 +15,30 @@ Npm

## Usage
See example in `/test/index.test.ts`
Create a new config file
```javascript
// generate an empty instance
const ui5Config = await UI5Config.newInstance('');
// set the UI5 framework with a specific version
ui5Config.addUI5Framework('SAPUI5', '1.64.0', []);
// create the file
fs.write('./ui5.yaml', ui5Config.toString());
```
Add a middleware to an existing file
```javascript
// load a config from the filesytem
const ui5Config = await UI5Config.newInstance(fs.read('./ui5.yaml'));
// add a middlewre
ui5Config.addFioriToolsAppReloadMiddleware();
// write the changes back to the filestystem
fs.write('./ui5.yaml', ui5Config.toString());
```
See more example in [`/test/index.test.ts`](./test/index.test.ts)
## Keywords
SAP Fiori Freestyle
SAP Fiori freestyle

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc