import type { ReaderCollection } from '@ui5/fs'; import type { Editor as MemFsEditor } from 'mem-fs-editor'; import type { Request, Router } from 'express'; import type { Logger } from '@sap-ux/logger'; import type { MiddlewareUtils } from '@ui5/server'; import { type Manifest } from '@sap-ux/project-access'; import { AdpPreview, type AdpPreviewConfig, type CommonChangeProperties, type OperationType, type CommonAdditionalChangeInfoProperties } from '@sap-ux/adp-tooling'; import type { FlpConfig, MiddlewareConfig, RtaConfig, TestConfig } from '../types/index.js'; import { type TemplateConfig } from './config.js'; /** * Enhanced request handler that exposes a list of endpoints for the cds-plugin-ui5. */ export type EnhancedRouter = Router & { getAppPages?: () => string[]; }; /** * Enhanced request object that contains additional properties from cds-plugin-ui5. */ export type EnhancedRequest = Request & { 'ui5-patched-router'?: { baseUrl?: string; }; }; type OnChangeRequestHandler = (type: OperationType, change: CommonChangeProperties, fs: MemFsEditor, logger: Logger, extendedChange?: CommonAdditionalChangeInfoProperties) => Promise; /** * Class handling preview of a sandbox FLP. */ export declare class FlpSandbox { private adp?; private manifest; protected onChangeRequest: OnChangeRequestHandler | undefined; protected templateConfig: TemplateConfig; readonly flpConfig: FlpConfig; readonly rta?: RtaConfig; readonly test?: TestConfig[]; readonly router: EnhancedRouter; private readonly fs; private readonly logger; private readonly utils; private readonly project; private readonly cardGenerator?; private projectType; /** * Constructor setting defaults and keeping reference to workspace resources. * * @param config configuration from the ui5.yaml * @param project reference to the project provided by the UI5 CLI * @param utils middleware utilities provided by the UI5 CLI * @param logger logger instance */ constructor(config: Partial, project: ReaderCollection, utils: MiddlewareUtils, logger: Logger); /** * Registers a handler function to be called when a change request occurs. * * @param {OnChangeRequestHandler} handler - The function to be executed when a change request occurs. */ addOnChangeRequestHandler(handler: OnChangeRequestHandler): void; /** * Initialize the FLP sandbox router. * * @param manifest application manifest * @param componentId optional componentId e.g. for adaptation projects * @param resources optional additional resource mappings * @param adp optional reference to the ADP tooling */ init(manifest: Manifest, componentId?: string, resources?: Record, adp?: AdpPreview): Promise; /** * Get the configuration for the developer mode. * * @param ui5MajorVersion - the major version of UI5 * @returns the configuration for the developer mode * @private */ private getDeveloperModeConfig; /** * Deletes the Fiori Tools local connector (WorkspaceConnector) in case of a not supported UI5 versions. * As an alternative the Fiori Tools fake connector (FakeLrepConnector) will be used as defined in preview-middleware-client/src/flp/initConnectors.ts. * Also deletes the ABAP connector in case of a CAP project. * Deletes all connectors if UI5 version is < 1.84 and served from npmjs. * * @param config - the template config to mutate (must be a per-request clone, not the shared this.templateConfig) * @param ui5VersionMajor - the major version of UI5 * @param ui5VersionMinor - the minor version of UI5 * @param isCDN - whether the UI5 sources are served from CDN * @private */ private checkDeleteConnectors; /** * Generates the FLP sandbox for an editor. * * @param req the request * @param rta runtime authoring configuration * @param editor editor configuration * @returns FLP sandbox html */ private generateSandboxForEditor; /** * Sets application dependencies in the template configuration. * The descriptor is refreshed if the global flag is set. * * @returns Promise that resolves when the application dependencies are set */ private setApplicationDependencies; /** * Handler for the GET requests to the runtime adaptation editor in developer mode. * * @param req the request * @param res the response * @param rta runtime adaptation configuration * @param previewUrl the url of the preview * @private */ private editorGetHandlerDeveloperMode; /** * Handler for the GET requests to the runtime adaptation editor. * * @param req the request * @param res the response * @param rta runtime adaptation configuration * @param previewUrl the url of the preview * @param editor editor configuration * @private */ private editorGetHandler; /** * Add additional routes for configured editors. * * @param rta runtime authoring configuration */ private addEditorRoutes; /** * Handler for the GET requests to the FLP. * * @param req the request * @param res the response * @param next the next function * @private */ private flpGetHandler; /** * Handler for GET requests to fioriSandboxAppConfig.json (Sandbox 2.0). * Serves a virtual config, optionally merged with a user-provided file. * If a real HTML file exists at the FLP path, no virtual config is served. * * @param req incoming request * @param res server response * @param next next middleware function * @param configJsonPath project-relative path to fioriSandboxAppConfig.json */ private sandboxAppConfigGetHandler; /** * Add routes for html and scripts required for a local FLP. */ private addStandardRoutes; /** * Adds a middleware route for the Card Generator in the FLP sandbox. * * This route dynamically updates the `templateConfig` with the Card Generator application details * and serves the FLP sandbox HTML using the `flpGetHandler`. * * @private */ private addCardGeneratorMiddlewareRoute; /** * Extracts protocol and baseUrl from a request and calls getUi5Version. * Handles both express Request and connect IncomingMessage (karma test runner). * * @param req - the incoming request * @param baseUrl - the base path to include when fetching the UI5 version * @returns the parsed UI5 version * @private */ private getUi5VersionFromRequest; /** * Read the UI5 version. * In case of an error, the default UI5 version '1.121.0' is returned. * * @param protocol - the protocol that should be used to request the UI5 version ('http' or 'https') * @param host - the host that should be used to request the UI5 version * @param baseUrl - the base path of the request that should be added to the host * @returns the template for the sandbox HTML file * @private */ private getUi5Version; /** * Read the sandbox template file based on the given UI5 version. * Also checks for a legacy 'appconfig/fioriSandboxConfig.json' and falls back to Sandbox 1 if found. * * @param ui5Version - the UI5 version * @returns the template for the sandbox HTML file */ private getSandboxTemplate; /** * For UI5 version 1.71 and below, the asyncHints.requests need to be removed from the template configuration * to load the changes in an Adaptation project. */ private removeAsyncHintsRequests; /** * Checks if a legacy 'appconfig/fioriSandboxConfig.json' file is present when using the new FLP Sandbox. * If found, warns the user to migrate and returns true so the caller can fall back to the classic Sandbox * for this request. * * @param ui5Version - the resolved UI5 version * @param baseUrl - the base URL of the current request * @returns true if the legacy file is present and sandbox 2 should be suppressed * @private */ private hasLegacySandboxConfig; /** * For UI5 versions below 1.120, flexExtensionPointEnabled must be removed from the application * dependencies manifest. Older UI5 versions cannot handle this property at bootstrap time. */ private removeFlexExtensionPointEnabled; /** * Try finding a locate-reuse-libs script in the project. * * @returns the location of the locate-reuse-libs script or undefined. */ private hasLocateReuseLibsScript; /** * Add additional routes for apps also to be shown in the local FLP. */ private addRoutesForAdditionalApps; /** * Add routes for cdm.json required by FLP during bootstrapping via cdm. * */ private addCDMRoute; /** * Handler for flex changes GET requests. * * @param res the response * @private */ private flexGetHandler; /** * Handler for flex changes POST requests. * * @param req the request * @param res the response * @private */ private flexPostHandler; /** * Handler for flex changes DELETE requests. * * @param req the request * @param res the response * @private */ private flexDeleteHandler; /** * Create required routes for flex. */ private createFlexHandler; /** * Handler for the GET requests to the HTML of the test suite. * * @param res the response * @param testsuite the test suite template * @param config the test configuration * @private */ private testSuiteHtmlGetHandler; /** * Handler for the GET requests to the JS of the test suite. * * @param res the response * @param next the next function * @param config the test configuration * @param initTemplate the test runner template * @param testPaths the paths to the test files * @param opa5Path optional relative path from testsuite to OPA5 HTML page * @param journeyNamesForIsolation optional list of journey module paths for isolated runs * @private */ private testSuiteJsGetHandler; /** * If it is part of TestConfig, create a test suite for the test configurations. * * @param configs test configurations * @param id application id from manifest * @private */ private createTestSuite; /** * Send a response with the given content type, status and body. * Ensure compliance with common APIs in express and connect. * * @param res the response object * @param contentType the content type * @param status the response status * @param body the response body * @private */ private sendResponse; /** * Handler for the GET requests to the HTML of the test runner. * * @param res the response * @param next the next function * @param config test configuration * @param htmlTemplate the test runner template * @param id application id from manifest */ private testRunnerHtmlGetHandler; /** * Handler for the GET requests to the JS of the test runner. * * @param res the response * @param next the next function * @param config test configuration * @param initTemplate the test runner template * @param ns namespace for the test files * @private */ private testRunnerJsGetHandler; /** * Add routes for html and scripts required for a local test FLP. * * @param configs test configurations * @param id application id from manifest */ private addTestRoutes; /** * Stores the card manifest files in the webapp folder of the project and updates the application manifest. * * @param {Request} req - The HTTP request object containing the card manifest data in the body. * @param {Response} res - The HTTP response object used to send the response back to the client. * @returns {Promise} A promise that resolves when the operation is complete. */ private storeCardManifestHandler; /** * Adds a route to store card manifest files, the files are stored in the webapp folder of the project. * The application manifest.json file is updated with the new card manifests information within the sap.cards.ap.embeds. * * @returns {Promise} A promise that resolves when the route is added. */ addStoreCardManifestRoute(): Promise; /** * Handles the storage of i18n keys in the i18n file. * * @param {Request} req - The HTTP request object containing the i18n key-value pairs in the body. * @param {Response} res - The HTTP response object used to send the response back to the client. * @returns {Promise} A promise that resolves when the operation is complete. */ private storeI18nKeysHandler; /** * Parses i18n configuration from manifest and returns path and locale settings. * * @returns i18n path, supported locales, and fallback locale */ private parseI18nConfig; /** * Extracts i18n path from object configuration (bundleName or bundleUrl). * * @param i18nConfig - The i18n configuration object * @returns The resolved i18n path */ private getI18nPathFromConfig; /** * Adds a route to store i18n properties in the i18n file. * This function updates the i18n file with new properties provided in the request body. * * @returns {Promise} A promise that resolves when the route is added. */ addStoreI18nKeysRoute(): Promise; /** * Initialize the preview for an adaptation project. * * @param config configuration from the ui5.yaml * @throws Error in case no manifest.appdescr_variant found */ initAdp(config: AdpPreviewConfig): Promise; /** * Setup common ADP middleware and handlers. * * @param adp AdpPreview instance */ private setupAdpCommonHandlers; /** * Registers a middleware that intercepts LREP flex data responses to apply * local workspace overrides: stripping inlined modules for active local files, * removing the loadModules pre-fetch flag, injecting correct moduleNames, and * suppressing deployed changes for orphaned local files (change record deleted). * * The local module state is captured once at server startup by `readLocalModulePaths` * and is not refreshed during the preview session. If a developer adds, renames, or deletes * a local fragment, controller, or change file while the preview is running, the filter will * be stale until the server is restarted. This is an intentional trade-off — re-scanning the * VFS on every flex-data request would add latency to every preview round-trip. * * @param adp AdpPreview instance with access to the ABAP service provider * @param localModuleState pre-scanned local module state */ private registerLrepFlexDataFilter; /** * Handler for LREP flex data requests. Strips inlined modules that exist locally * so that UI5 fetches them via HTTP from the local workspace instead. * * @param req the request * @param res the response * @param next the next middleware * @param provider the ABAP service provider for backend calls * @param localModuleState pre-scanned local module state */ private lrepFlexDataFilterHandler; /** * Setup the CF build path mode for the ADP project. * * @param cfBuildPath path to the build output folder * @param adp AdpPreview instance for proxying manifest requests * @returns the manifest */ private setupCfBuildMode; } export {}; //# sourceMappingURL=flp.d.ts.map