@sap/generator-fiori
Version:
Create an SAPUI5 application using SAP Fiori elements or a freestyle approach
1 lines • 49.1 kB
JavaScript
"use strict";exports.id=3688,exports.ids=[3688],exports.modules={1425(e,a,i){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(a,"__esModule",{value:!0}),a.generateAppConfig=async function generateAppConfig(e,a,i){a??=(0,s.create)((0,r.create)()),i&&(g.default.logger=i);return(0,m.doesMTABinaryExist)(),await async function generateDeployConfig(e,a){g.default?.logger?.debug(`Generate HTML5 app deployment configuration with: \n ${JSON.stringify(e)}`);const i=await async function getUpdatedConfig(e,a){const i=e.lcapMode??!1,{rootPath:n,isCap:r,mtaId:s,mtaPath:c,hasRoot:u,capRoot:M}=await async function getProjectProperties(e){let a,i,n,r=!1;const s=await(0,p.getMtaPath)(e.appPath);s&&(i=(0,o.dirname)(s.mtaPath),n=await(0,m.getMtaId)(i));const d=s?.hasRoot??!1,c=await(0,p.findCapProjectRoot)(e.appPath)??void 0;c?((0,m.doesCDSBinaryExist)(),r=!0,a=c):a=i??e.appPath;return{rootPath:a,isCap:r,mtaId:n,mtaPath:i,hasRoot:d,capRoot:c}}(e),{serviceHost:f,destination:A,firstServicePathSegmentUI5Config:P}=await async function processUI5Config(e,a){let i,n,o;try{const r=(await(0,p.readUi5Yaml)(e,p.FileName.Ui5Yaml,a)).findCustomMiddleware(d.fioriToolsProxy);1===r?.configuration?.backend?.length&&(i=r?.configuration?.backend[0].destination,n=r?.configuration?.backend[0].url,o=r?.configuration?.backend[0].path)}catch(e){g.default.logger?.debug((0,h.t)("debug.ui5YamlDoesNotExist",{error:e.message}))}return{destination:i,serviceHost:n,firstServicePathSegmentUI5Config:o}}(e.appPath,a),{servicePath:T,firstServicePathSegment:y,appId:_}=await async function processManifest(e,a){const i=await(0,p.getWebappPath)(e),n=(0,l.readManifest)((0,o.join)(i,p.FileName.Manifest),a),r=n?.["sap.app"]?.id?(0,m.toMtaModuleName)(n["sap.app"].id):void 0,s=n?.["sap.app"]?.dataSources?.mainService?.uri,d=s?.substring(0,s.indexOf("/",1));return{servicePath:s,firstServicePathSegment:d,appId:r}}(e.appPath,a);if(!_)throw new Error((0,h.t)("error.noUI5AppFound"));const{destinationIsFullUrl:S,destinationAuthentication:R}=await(0,l.getDestinationProperties)(e.destinationName??A);(0,l.enforceValidRouterConfig)(e);const v={appPath:e.appPath.replace(/\/$/,""),destinationName:e.destinationName??A,addManagedAppRouter:e.addManagedAppRouter,addAppFrontendRouter:e.addAppFrontendRouter,addMtaDestination:e.addMtaDestination??!1,cloudServiceName:e.cloudServiceName,lcapMode:!!r&&i,isMtaRoot:u??!1,serviceHost:e.serviceHost??f,rootPath:n.replace(/\/$/,""),destinationAuthentication:e.destinationAuthentication??R,isDestinationFullUrl:e.isDestinationFullUrl??S,apiHubConfig:e.apiHubConfig,firstServicePathSegment:P??y??"<apply-service-segment-path>",mtaId:s,mtaPath:c,isCap:r,servicePath:T,appId:_,capRoot:M};return v}(e,a);g.default?.logger?.debug(`Deployment configuration updated: \n ${JSON.stringify(i)}`),i.lcapMode||await generateMTAFile(i,a);await async function appendCloudFoundryConfigurations(e,a){const i=e.addAppFrontendRouter?"ias":"xsuaa",n={service:e.addAppFrontendRouter?"app-front":"html5-apps-repo-rt",authenticationType:i,addAppFrontendRoutes:e.addAppFrontendRouter??!1,...e.destinationName&&e.destinationName!==u.EmptyDestination?{destination:e.destinationName,servicePathSegment:`${e.firstServicePathSegment}${e.isDestinationFullUrl?"/.*":""}`,targetPath:`${e.isDestinationFullUrl?"":e.firstServicePathSegment}/$1`,authentication:e.destinationAuthentication===c.Authentication.NO_AUTHENTICATION?"none":i}:{}};a.copyTpl((0,l.getTemplatePath)("app/xs-app-destination.json"),(0,o.join)(e.appPath,p.FileName.XSAppJson),n),await generateUI5DeployConfig(e,a)}(i,a),await async function updateManifest(e,a){const i=await(0,p.getWebappPath)(e.appPath,a),n=(0,l.readManifest)((0,o.join)(i,p.FileName.Manifest),a);if(n&&e.cloudServiceName){const r={...n["sap.cloud"],public:!0,service:e.cloudServiceName};a.extendJSON((0,o.join)(i,p.FileName.Manifest),{"sap.cloud":r})}}(i,a),await async function updateHTML5AppPackage(e,a){let i=[];(0,l.fileExists)(a,(0,o.join)(e.appPath,p.FileName.MtaExtYaml))&&(i=["-e",p.FileName.MtaExtYaml]);await(0,p.updatePackageScript)(e.appPath,"build:cf",u.UI5DeployBuildScript,a),await(0,l.addCommonPackageDependencies)(e.appPath,a),e.isCap&&await(0,p.updatePackageScript)(e.appPath,"build",u.UI5DeployBuildScriptForCap,a);e.mtaPath&&!e.isMtaRoot&&(await(0,p.updatePackageScript)(e.appPath,"build:mta",u.MTABuildScript,a),await(0,p.updatePackageScript)(e.appPath,"deploy",(0,u.appDeployMTAScript)(i),a),await(0,p.updatePackageScript)(e.appPath,"undeploy",(0,u.undeployMTAScript)(e.mtaId??e.appId),a),await(0,p.addPackageDevDependency)(e.appPath,u.Rimraf,u.RimrafVersion,a),await(0,p.addPackageDevDependency)(e.appPath,u.MbtPackage,u.MbtPackageVersion,a))}(i,a),i.isMtaRoot&&await(0,l.updateRootPackage)({mtaId:i.mtaId??i.appId,rootPath:i.rootPath},a)}(e,a),a},a.generateMTAFile=generateMTAFile,a.generateUI5DeployConfig=generateUI5DeployConfig;const o=i(76760),r=i(64812),s=i(90718),d=i(8231),p=i(20787),c=i(75199),u=i(54036),l=i(37736),m=i(79875),g=n(i(57470)),h=i(97649);async function generateMTAFile(e,a){e.mtaId||(e.isCap?await(0,m.generateCAPMTA)({...e,mtaPath:e.rootPath},a):(0,m.createMTA)({mtaId:e.appId,mtaPath:e.mtaPath??e.rootPath}),e.mtaId=e.appId,e.mtaPath=e.rootPath),await async function appendAppRouter(e,a){const i=await(0,m.getMtaConfig)(e.rootPath);if(i){await i.addRoutingModules({isManagedApp:e.addManagedAppRouter,isAppFrontApp:e.addAppFrontendRouter,addMissingModules:!e.addAppFrontendRouter});const n=e.appId,r=(0,l.toPosixPath)((0,o.relative)(e.rootPath,e.appPath));await i.addApp(n,r??"."),(e.addMtaDestination&&e.isCap||e.destinationName===u.DefaultMTADestination)&&(e.destinationName=e.destinationName===u.DefaultMTADestination?u.SRV_API:e.destinationName,await i.addDestinationToAppRouter(e.destinationName),i.hasManagedXsuaaResource()||(e.destinationAuthentication=c.Authentication.NO_AUTHENTICATION)),function cleanupStandaloneRoutes({rootPath:e,appId:a},i,n){const r=i.standaloneRouterPath;if(r)try{const i=(0,o.join)(r,p.FileName.XSAppJson),s=n.readJSON((0,o.join)(e,i));(s&&!s?.[u.WelcomeFile]||"/"===s?.[u.WelcomeFile])&&(s[u.WelcomeFile]=`/${a}`,n.writeJSON((0,o.join)(e,i),s))}catch(e){g.default.logger?.error((0,h.t)("error.cannotUpdateRouterXSApp",{error:e}))}}(e,i,a),await async function saveMta(e,a){try{await a.save(),g.default.logger?.debug((0,h.t)("debug.mtaSaved"))}catch(e){g.default.logger?.debug((0,h.t)("debug.mtaSavedFailed",{error:e}))}if("API_HUB_ENTERPRISE"===e.apiHubConfig?.apiHubType)try{await a.addMtaExtensionConfig(e.destinationName,e.serviceHost,{key:"ApiKey",value:e.apiHubConfig.apiHubKey})}catch(e){g.default.logger?.error((0,h.t)("error.mtaExtensionFailed",{error:e}))}}(e,i),e.cloudServiceName=i.cloudServiceName,e.addAppFrontendRouter=i.hasAppFrontendRouter()}}(e,a),await(0,l.generateSupportingConfig)(e,a)}async function generateUI5DeployConfig(e,a){const i=await(0,p.readUi5Yaml)(e.appPath,p.FileName.Ui5Yaml,a),n=!!i.findCustomMiddleware("ui5-tooling-transpile-task"),r=!!i.findCustomMiddleware("ui5-tooling-modules-task"),s=i.removeConfig("server"),c=await d.UI5Config.newInstance(s.toString());c.addComment({comment:" yaml-language-server: $schema=https://sap.github.io/ui5-tooling/schema/ui5.yaml.json",location:"beginning"}),c.setConfiguration({propertiesFileSourceEncoding:"UTF-8"}),c.addCloudFoundryDeployTask(e.appId,r,n),a.write((0,o.join)(e.appPath,p.FileName.UI5DeployYaml),c.toString())}},9291(e,a,i){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(a,"__esModule",{value:!0}),a.generateBaseConfig=async function generateBaseConfig(e,a,i){a??=(0,s.create)((0,r.create)()),i&&(p.default.logger=i);if(i?.debug(`Generate base configuration using: \n ${JSON.stringify(e)}`),(0,c.validateMtaConfig)(e),(0,d.fileExists)(a,(0,o.join)(e.mtaPath,e.mtaId)))throw new Error((0,u.t)("error.mtaAlreadyExists"));return(0,c.createMTA)(e),await(0,c.addRoutingConfig)(e,a),await(0,d.generateSupportingConfig)(e,a),p.default.logger?.debug(`CF Config ${JSON.stringify(e,null,2)}`),a};const o=i(76760),r=i(64812),s=i(90718),d=i(37736),p=n(i(57470)),c=i(79875),u=i(97649)},89416(e,a,i){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(a,"__esModule",{value:!0}),a.generateCAPConfig=async function generateCAPConfig(e,a,i){a??=(0,r.create)((0,o.create)()),i&&(c.default.logger=i);return i?.debug(`Generate CAP configuration using: \n ${JSON.stringify(e)}`),await async function validateConfig(e){if((0,d.validateMtaConfig)(e),"CAPNodejs"!==await(0,l.getCapProjectType)(e.mtaPath))throw new Error((0,u.t)("error.doesNotContainACapApp"));if((0,d.isMTAFound)(e.mtaPath))throw new Error((0,u.t)("error.mtaAlreadyExists"))}(e),await(0,d.generateCAPMTA)(e,a),await(0,p.waitForMtaFile)(e.mtaPath),await(0,d.addRoutingConfig)(e,a),await(0,s.updateRootPackage)({mtaId:e.mtaId,rootPath:e.mtaPath},a),c.default.logger?.debug((0,u.t)("debug.capGenerationCompleted")),a};const o=i(64812),r=i(90718),s=i(37736),d=i(79875),p=i(85929),c=n(i(57470)),u=i(97649),l=i(20787)},58445(e,a,i){Object.defineProperty(a,"__esModule",{value:!0}),a.generateCAPConfig=a.generateBaseConfig=a.generateAppConfig=void 0;var n=i(1425);Object.defineProperty(a,"generateAppConfig",{enumerable:!0,get:function(){return n.generateAppConfig}});var o=i(9291);Object.defineProperty(a,"generateBaseConfig",{enumerable:!0,get:function(){return o.generateBaseConfig}});var r=i(89416);Object.defineProperty(a,"generateCAPConfig",{enumerable:!0,get:function(){return r.generateCAPConfig}})},54036(e,a,i){Object.defineProperty(a,"__esModule",{value:!0}),a.CDSBinNotFound=a.undeployMTAScript=a.rootDeployMTAScript=a.appDeployMTAScript=a.MTABuildScript=a.UI5DeployBuildScript=a.UI5DeployBuildScriptForCap=a.HTMLAppBuildParams=a.ServiceAPIRequires=a.DestinationServiceConfig=a.UI5StandaloneModuleDestination=a.UI5ResourceDestination=a.CAPAppfrontDestination=a.UI5AppfrontDestinationParameter=a.UI5Destination=a.MTAAPIDestination=a.CDSDestinationService=a.CDSHTML5RepoService=a.CDSXSUAAService=a.CDSAddMtaParams=a.UI5PackageVersion=a.UI5Package=a.UI5TaskZipperPackageVersion=a.UI5TaskZipperPackage=a.MbtPackageVersion=a.MbtPackage=a.Rimraf=a.RimrafVersion=a.MTAVersion=a.MTAPackage=a.MTAExecutable=a.CDSPackage=a.CDSDKPackage=a.CDSExecutable=a.enableParallelDeployments=a.deployMode=a.CloudFoundry=a.RouterModule=a.MTADescription=a.EmptyDestination=a.DefaultMTADestination=a.SRV_API=a.HTML5RepoHost=a.ManagedDestination=a.ManagedAppFront=a.ManagedXSUAA=a.DefaultServiceURL=a.MTABuildParams=a.MTABuildResult=a.WelcomeFile=void 0,a.MTA_FILE_OPERATION_DELAY_MS=a.MAX_ABAP_SERVICE_NAME_LENGTH=a.MAX_ABAP_SERVICE_PREFIX_LENGTH=a.MAX_MTA_PREFIX_SHORTER_LENGTH=a.MAX_MTA_PREFIX_SHORT_LENGTH=a.MAX_MTA_PREFIX_LENGTH=a.MAX_MTA_ID_LENGTH=a.MTABinNotFound=void 0;const n=i(97649);a.WelcomeFile="welcomeFile",a.MTABuildResult="build-result",a.MTABuildParams="build-parameters",a.DefaultServiceURL="${default-url}",a.ManagedXSUAA="managed:xsuaa",a.ManagedAppFront="managed:app-front",a.ManagedDestination="destination",a.HTML5RepoHost="html5-apps-repo:app-host",a.SRV_API="srv-api",a.DefaultMTADestination="fiori-default-srv-api",a.EmptyDestination="NONE",a.MTADescription="Generated by Fiori Tools",a.RouterModule="router",a.CloudFoundry="cf",a.deployMode="deploy_mode",a.enableParallelDeployments="enable-parallel-deployments",a.CDSExecutable="cds",a.CDSDKPackage="@sap/cds-dk",a.CDSPackage="@sap/cds",a.MTAExecutable="mta",a.MTAPackage="mta",a.MTAVersion="0.0.1",a.RimrafVersion="^5.0.5",a.Rimraf="rimraf",a.MbtPackage="mbt",a.MbtPackageVersion="^1.2.49",a.UI5TaskZipperPackage="ui5-task-zipper",a.UI5TaskZipperPackageVersion="^3.4.x",a.UI5Package="@ui5/cli",a.UI5PackageVersion="^4.0.33",a.CDSAddMtaParams=["add","mta"],a.CDSXSUAAService="xsuaa",a.CDSHTML5RepoService="html5-repo",a.CDSDestinationService="destination",a.MTAAPIDestination={Name:a.SRV_API,Type:"HTTP",URL:"~{srv-api/srv-url}",ProxyType:"Internet",Authentication:"NoAuthentication","HTML5.DynamicDestination":!0,"HTML5.ForwardAuthToken":!0},a.UI5Destination={Name:"ui5",Type:"HTTP",URL:"https://ui5.sap.com",ProxyType:"Internet",Authentication:"NoAuthentication"},a.UI5AppfrontDestinationParameter={name:"ui5",url:"https://ui5.sap.com"},a.CAPAppfrontDestination={name:a.SRV_API,url:"~{srv-api/srv-url}",forwardAuthToken:!0},a.UI5ResourceDestination={init_data:{instance:{existing_destinations_policy:"update",destinations:[{Name:"ui5",Type:"HTTP",URL:"https://ui5.sap.com",ProxyType:"Internet",Authentication:"NoAuthentication"}]}}},a.UI5StandaloneModuleDestination={group:"destinations",properties:{forwardAuthToken:!1,name:"ui5",url:"https://ui5.sap.com"}},a.DestinationServiceConfig={config:{HTML5Runtime_enabled:!0,version:"1.0.0",...a.UI5ResourceDestination}},a.ServiceAPIRequires={name:a.SRV_API,properties:{"srv-url":a.DefaultServiceURL}},a.HTMLAppBuildParams={builder:"custom","build-result":"dist",commands:["npm install","npm run build:cf"],"supported-platforms":[]},a.UI5DeployBuildScriptForCap="npm run build:cf",a.UI5DeployBuildScript="ui5 build preload --clean-dest --config ui5-deploy.yaml --include-task=generateCachebusterInfo",a.MTABuildScript="rimraf resources mta_archives && mbt build";a.appDeployMTAScript=e=>`fiori cfDeploy${e.length>0?` ${e.join(" ")}`:""}`;a.rootDeployMTAScript=e=>`cf deploy mta_archives/archive.mtar ${e.length>0?`${e.join(" ")} `:""}--retries 1`;a.undeployMTAScript=e=>`cf undeploy ${e} --delete-services --delete-service-keys --delete-service-brokers`;const cannotFindBinary=(e,a)=>(0,n.t)("error.cannotFindBinary",{bin:e,pkg:a});a.CDSBinNotFound=cannotFindBinary(a.CDSExecutable,a.CDSDKPackage),a.MTABinNotFound=cannotFindBinary(a.MTAExecutable,a.MTAPackage),a.MAX_MTA_ID_LENGTH=128,a.MAX_MTA_PREFIX_LENGTH=100,a.MAX_MTA_PREFIX_SHORT_LENGTH=94,a.MAX_MTA_PREFIX_SHORTER_LENGTH=96,a.MAX_ABAP_SERVICE_PREFIX_LENGTH=24,a.MAX_ABAP_SERVICE_NAME_LENGTH=20,a.MTA_FILE_OPERATION_DELAY_MS=1e3},97649(e,a,i){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(a,"__esModule",{value:!0}),a.i18n=void 0,a.initI18n=initI18n,a.t=function t(e,i){return a.i18n.t(e,i)};const o=n(i(68801)),r=n(i(54417)),s="cf-deploy-config-writer";async function initI18n(){await a.i18n.init({resources:{en:{[s]:r.default}},lng:"en",fallbackLng:"en",defaultNS:s,ns:[s],showSupportNotice:!1})}a.i18n=o.default.createInstance(),initI18n().catch(()=>{})},13149(e,a,i){var n=this&&this.__createBinding||(Object.create?function(e,a,i,n){void 0===n&&(n=i);var o=Object.getOwnPropertyDescriptor(a,i);o&&!("get"in o?!a.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return a[i]}}),Object.defineProperty(e,n,o)}:function(e,a,i,n){void 0===n&&(n=i),e[n]=a[i]}),o=this&&this.__exportStar||function(e,a){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(a,i)||n(a,e,i)};Object.defineProperty(a,"__esModule",{value:!0}),a.RouterModuleType=a.MTA_FILE_OPERATION_DELAY_MS=a.MAX_ABAP_SERVICE_NAME_LENGTH=a.MAX_ABAP_SERVICE_PREFIX_LENGTH=a.MAX_MTA_PREFIX_SHORTER_LENGTH=a.MAX_MTA_PREFIX_SHORT_LENGTH=a.MAX_MTA_PREFIX_LENGTH=a.MAX_MTA_ID_LENGTH=a.DefaultMTADestination=void 0,o(i(79875),a),o(i(58445),a);var r=i(54036);Object.defineProperty(a,"DefaultMTADestination",{enumerable:!0,get:function(){return r.DefaultMTADestination}}),Object.defineProperty(a,"MAX_MTA_ID_LENGTH",{enumerable:!0,get:function(){return r.MAX_MTA_ID_LENGTH}}),Object.defineProperty(a,"MAX_MTA_PREFIX_LENGTH",{enumerable:!0,get:function(){return r.MAX_MTA_PREFIX_LENGTH}}),Object.defineProperty(a,"MAX_MTA_PREFIX_SHORT_LENGTH",{enumerable:!0,get:function(){return r.MAX_MTA_PREFIX_SHORT_LENGTH}}),Object.defineProperty(a,"MAX_MTA_PREFIX_SHORTER_LENGTH",{enumerable:!0,get:function(){return r.MAX_MTA_PREFIX_SHORTER_LENGTH}}),Object.defineProperty(a,"MAX_ABAP_SERVICE_PREFIX_LENGTH",{enumerable:!0,get:function(){return r.MAX_ABAP_SERVICE_PREFIX_LENGTH}}),Object.defineProperty(a,"MAX_ABAP_SERVICE_NAME_LENGTH",{enumerable:!0,get:function(){return r.MAX_ABAP_SERVICE_NAME_LENGTH}}),Object.defineProperty(a,"MTA_FILE_OPERATION_DELAY_MS",{enumerable:!0,get:function(){return r.MTA_FILE_OPERATION_DELAY_MS}});var s=i(26011);Object.defineProperty(a,"RouterModuleType",{enumerable:!0,get:function(){return s.RouterModuleType}})},57470(e,a,i){Object.defineProperty(a,"__esModule",{value:!0});const n=i(76277);class LoggerHelper{static _logger=new n.ToolsLogger({logPrefix:"@sap-ux/cf-deploy-config-writer"});static get logger(){return LoggerHelper._logger}static set logger(e){LoggerHelper._logger=e}}a.default=LoggerHelper},79875(e,a,i){var n=this&&this.__createBinding||(Object.create?function(e,a,i,n){void 0===n&&(n=i);var o=Object.getOwnPropertyDescriptor(a,i);o&&!("get"in o?!a.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return a[i]}}),Object.defineProperty(e,n,o)}:function(e,a,i,n){void 0===n&&(n=i),e[n]=a[i]}),o=this&&this.__exportStar||function(e,a){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(a,i)||n(a,e,i)},r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(a,"__esModule",{value:!0}),a.getMtaId=async function getMtaId(e){return(await getMtaConfig(e))?.prefix},a.getMtaConfig=getMtaConfig,a.toMtaModuleName=function toMtaModuleName(e){return(0,c.toMtaModuleName)(e).slice(0,u.MAX_MTA_ID_LENGTH)},a.createMTA=function createMTA(e){const a=`${e.mtaId.slice(0,u.MAX_MTA_ID_LENGTH)}`;e.mtaId=a,(0,p.renderTemplateToDisk)(`app/${A.FileName.MtaYaml}`,(0,s.join)(e.mtaPath,A.FileName.MtaYaml),{id:a,mtaDescription:e.mtaDescription??u.MTADescription,mtaVersion:e.mtaVersion??u.MTAVersion}),g.default.logger?.debug((0,M.t)("debug.mtaCreated",{mtaPath:e.mtaPath}))},a.doesMTABinaryExist=doesMTABinaryExist,a.doesCDSBinaryExist=function doesCDSBinaryExist(){if(!(0,h.sync)(u.CDSExecutable))throw new Error(u.CDSBinNotFound)},a.validateMtaConfig=function validateMtaConfig(e){if(doesMTABinaryExist(),!e.routerType||!e.mtaId||!e.mtaPath)throw new Error((0,M.t)("error.missingMtaParameters"));if(e.mtaId.length>u.MAX_MTA_ID_LENGTH||!/^[a-zA-Z_]/.test(e.mtaId))throw new Error((0,M.t)("error.invalidMtaId"));if(!/^[\w\-.]*$/.test(e.mtaId))throw new Error((0,M.t)("error.invalidMtaIdWithChars"));if((0,c.validateVersion)(e.mtaVersion),e.abapServiceProvider&&(!e.abapServiceProvider.abapService||!e.abapServiceProvider.abapServiceName))throw new Error((0,M.t)("error.missingABAPServiceBindingDetails"));(0,c.setMtaDefaults)(e)},a.addRoutingConfig=async function addRoutingConfig(e,a){const i=await getMtaConfig(e.mtaPath);i&&(e.routerType===m.RouterModuleType.Standard?await async function addStandaloneRouter(e,a,i){await a.addStandaloneRouter(!0),e.addConnectivityService&&await a.addConnectivityResource();const{abapServiceName:n,abapService:o}=e.abapServiceProvider??{};n&&o&&await a.addAbapService(n,o);if(i.copyTpl((0,c.getTemplatePath)("router/package.json"),(0,s.join)(e.mtaPath,`${u.RouterModule}/${A.FileName.Package}`)),n){let a;try{const e=await(0,f.apiGetInstanceCredentials)(n);a=e?.credentials}catch{g.default.logger?.error((0,M.t)("error.serviceKeyFailed"))}const o=a?.endpoints?Object.keys(a.endpoints):[""],r=a?a["sap.cloud.service"]:"";i.copyTpl((0,c.getTemplatePath)("router/xs-app-abapservice.json"),(0,s.join)(e.mtaPath,`${u.RouterModule}/${A.FileName.XSAppJson}`),{servicekeyService:r,servicekeyEndpoint:o[0]})}else i.copyTpl((0,c.getTemplatePath)("router/xs-app-server.json"),(0,s.join)(e.mtaPath,`${u.RouterModule}/${A.FileName.XSAppJson}`))}(e,i,a):await i.addRouterType({routerType:e.routerType,addMissingModules:!1}),await i.save(),g.default.logger?.debug((0,M.t)("debug.capMtaUpdated")))},a.generateCAPMTA=async function generateCAPMTA(e,a){if(e.routerType===m.RouterModuleType.AppFront)await async function createCAPMTAAppFrontend(e,a){(0,p.renderTemplateToDisk)(`frontend/${A.FileName.MtaYaml}`,(0,s.join)(e.mtaPath,A.FileName.MtaYaml),{id:`${e.mtaId.slice(0,u.MAX_MTA_ID_LENGTH)}`,mtaDescription:e.mtaDescription??u.MTADescription,mtaVersion:e.mtaVersion??u.MTAVersion}),(0,c.addXSSecurityConfig)(e,a,!1),g.default.logger?.debug((0,M.t)("debug.mtaCreated",{mtaPath:e.mtaPath}))}(e,a);else{const a=[u.CDSXSUAAService,u.CDSDestinationService,u.CDSHTML5RepoService],i=[...u.CDSAddMtaParams,...a];g.default.logger?.debug((0,M.t)("debug.creatingMta",{cdsParams:i.toString()})),await(0,c.runCommand)(e.mtaPath,u.CDSExecutable,i,(0,M.t)("error.errorGeneratingMtaYaml")),g.default.logger?.debug((0,M.t)("debug.capMtaCreated"))}};const s=i(76760),d=i(22495),p=i(44385),c=i(37736),u=i(54036),l=i(85929),m=i(26011),g=r(i(57470)),h=i(44425),M=i(97649),f=i(14501),A=i(20787);async function getMtaConfig(e){try{await(0,l.waitForMtaFile)(e)}catch{return void g.default.logger?.debug((0,M.t)("debug.mtaReadWithPrefix",{prefix:void 0}))}const a=await d.MtaConfig.newInstance(e,g.default.logger);return g.default.logger?.debug((0,M.t)("debug.mtaReadWithPrefix",{prefix:a?.prefix})),a}function doesMTABinaryExist(){if(!(0,h.sync)(u.MTAExecutable))throw new Error(u.MTABinNotFound)}o(i(22495),a)},22495(e,a,i){Object.defineProperty(a,"__esModule",{value:!0}),a.MtaConfig=void 0,a.isMTAFound=function isMTAFound(e){return(0,r.existsSync)((0,o.join)(e,c.FileName.MtaYaml))},a.useAbapDirectServiceBinding=async function useAbapDirectServiceBinding(e,a,i="",n){try{let r;if(a){const a=await(0,c.getMtaPath)(e);a&&(r=(0,o.dirname)(a.mtaPath))}else i&&(r=(0,o.dirname)(i));if(r){return(await MtaConfig.newInstance(r,n)).isABAPServiceFound}return!1}catch(e){return n?.debug((0,l.t)("debug.logError",{error:e,method:"useAbapDirectServiceBinding"})),!1}};const n=i(57975),o=i(76760),r=i(73024),s=i(87827),d=i(75199),p=i(55968),c=i(20787),u=i(54036),l=i(97649),m=i(26011),g=i(44385);class MtaConfig{mta;apps=new Map;modules=new Map;resources=new Map;log;mtaDir;dirty=!1;mtaId;static async newInstance(e,a){return new MtaConfig(e,a).init()}constructor(e,a){this.mta=new s.Mta(e,!1),this.log=a,this.mtaDir=e}async init(){try{await this.loadMTAResources(),await this.loadMTAModules(),this.mtaId=await(this.mta?.getMtaID())}catch(e){this.log?.error((0,l.t)("error.unableToLoadMTA",{error:e,mtaDir:this.mtaDir}))}return this}targetExists(e,a){return e&&-1!==e.findIndex(e=>!0===e.parameters?.["content-target"]&&this.resources.get(a)?.name===e.name)}async loadMTAResources(){(await this.mta.getResources()||[]).forEach(e=>{e.parameters?.service&&("html5-apps-repo"===e.parameters?.service?this.resources.set("app-host"===e.parameters["service-plan"]?u.HTML5RepoHost:"html5-apps-repo:app-runtime",e):"xsuaa"===e.parameters?.service?this.resources.set(u.ManagedXSUAA,e):"app-front"===e.parameters?.service?this.resources.set(u.ManagedAppFront,e):e.type===m.CloudFoundryServiceType.Existing?this.resources.set(e.name,e):this.resources.set(e.parameters.service,e))}),this.log?.debug((0,l.t)("debug.mtaLoaded",{type:"resources",size:this.resources.size}))}async loadMTAModules(){(await(this.mta?.getModules())||[]).forEach(e=>{e.type&&("html5"===e.type?this.apps.set(e.name,e):this.targetExists(e.requires??[],"destination")?this.modules.set("com.sap.application.content:destination",e):this.targetExists(e.requires??[],u.HTML5RepoHost)?this.modules.set("com.sap.application.content:resource",e):this.targetExists(e.requires??[],u.ManagedAppFront)?this.modules.set("com.sap.application.content:appfront",e):this.modules.set(e.type,e))}),this.log?.debug((0,l.t)("debug.mtaLoaded",{type:"modules",size:this.modules.size}))}async addAppContent(){this.resources.has(u.HTML5RepoHost)||await this.addHtml5Host();const e=this.resources.get(u.HTML5RepoHost)?.name;if(e){const a={name:`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_LENGTH)}-app-content`,type:"com.sap.application.content",path:".",requires:[{name:e,parameters:{"content-target":!0}}],"build-parameters":{"build-result":"resources",requires:[]}};await(this.mta?.addModule(a)),this.modules.set("com.sap.application.content:resource",a),this.dirty=!0}}async addUaa(){const e={name:`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_LENGTH)}-uaa`,type:"org.cloudfoundry.managed-service",parameters:{service:"xsuaa","service-plan":"application",path:"./xs-security.json","service-name":`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_LENGTH)}-xsuaa-service`,config:{xsappname:`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_LENGTH)}-\${space-guid}`,"tenant-mode":"dedicated"}}};await(this.mta?.addResource(e)),this.resources.set("xsuaa",e),this.dirty=!0}async addHtml5Runtime(){const e={name:`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_LENGTH)}-html5-repo-runtime`,type:"org.cloudfoundry.managed-service",parameters:{"service-plan":"app-runtime",service:"html5-apps-repo"}};await(this.mta?.addResource(e)),this.resources.set("html5-apps-repo:app-runtime",e),this.dirty=!0}async updateServiceName(e,a){const i=this.resources.get(a);i&&!i.parameters?.["service-name"]&&(i.parameters={...i.parameters??{},"service-name":`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_LENGTH)}-${e}-service`},await(this.mta?.updateResource(i)),this.resources.set(a,i),this.dirty=!0)}getServiceInstanceName(e){const a=this.resources.get(e),i=a?.parameters?.["service-name"];return i||a?.name}async addAppFrontResource(){const e={name:`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_SHORT_LENGTH)}-app-front`,type:"org.cloudfoundry.managed-service",parameters:{service:"app-front","service-name":`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_SHORTER_LENGTH)}-app-front-service`,"service-plan":"developer"}};await(this.mta?.addResource(e)),this.resources.set(u.ManagedAppFront,e),this.dirty=!0}async addHtml5Host(){const e={name:`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_LENGTH)}-repo-host`,type:"org.cloudfoundry.managed-service",parameters:{"service-name":`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_LENGTH)}-html5-service`,"service-plan":"app-host",service:"html5-apps-repo"}};await(this.mta?.addResource(e)),this.resources.set(u.HTML5RepoHost,e),this.dirty=!0}async addDestinationResource(e=!1){const a=`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_LENGTH)}-destination-service`,i={name:a,type:"org.cloudfoundry.managed-service",parameters:{service:"destination","service-name":a,"service-plan":"lite",config:{...u.DestinationServiceConfig.config,HTML5Runtime_enabled:e}}};await(this.mta?.addResource(i)),this.resources.set("destination",i),this.dirty=!0}async updateDestinationResource(e=!1){const a=this.resources.get("destination");a&&(a.parameters={...a.parameters??{},config:{...a.parameters?.config??{},HTML5Runtime_enabled:e}},a.parameters?.config?.init_data?.instance?.destinations||(a.parameters.config={...a.parameters.config,...u.UI5ResourceDestination}),a.parameters?.config?.init_data?.instance?.destinations?.some(e=>e.Name===u.UI5Destination.Name)||a.parameters.config.init_data.instance.destinations.push(u.UI5Destination),await(this.mta?.updateResource(a)),this.resources.set("destination",a),this.dirty=!0)}async updateServerModule(e,a=u.ManagedXSUAA,i=!0){const n=this.resources.get(a),o=this.modules.get(e);o&&(i&&!o.provides?.some(e=>e.name===u.SRV_API)&&(o.provides=[...o.provides??[],u.ServiceAPIRequires]),n&&!o.requires?.some(e=>e.name===n.name)&&(o.requires=[...o.requires??[],{name:n.name}]),await(this.mta?.updateModule(o)),this.modules.set(e,o),this.dirty=!0)}async addManagedUAAWithSecurity(){this.log?.debug((0,l.t)("debug.addXsuaaService"));const e={name:`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_LENGTH)}-uaa`,type:"org.cloudfoundry.managed-service",parameters:{path:"./xs-security.json",service:"xsuaa","service-name":`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_LENGTH)}-xsuaa-service`,"service-plan":"application",...this.modules.has("nodejs")&&this.modules.has("com.sap.application.content:appfront")?{config:{xsappname:`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_LENGTH)}-\${org}-\${space}`,"tenant-mode":"dedicated"}}:{}}};await(this.mta?.addResource(e)),this.resources.set(u.ManagedXSUAA,e),this.dirty=!0}isODataDestination(e){return(0,d.isGenericODataDestination)(e)||(0,d.isAbapEnvironmentOnBtp)(e)}async cleanupMissingResources(){this.log?.debug((0,l.t)("debug.addMissingModules")),this.modules.has("com.sap.application.content:appfront")||(this.modules.has("com.sap.application.content:resource")||await this.addAppContent(),this.resources.get("destination")?await this.updateDestinationResource(this.modules.has("com.sap.application.content:destination")):await this.addDestinationResource(this.modules.has("com.sap.application.content:destination")))}async cleanupModules(){this.log?.debug((0,l.t)("debug.cleanupModules"));for(const e of[this.modules.get("com.sap.application.content:destination"),this.modules.get("approuter.nodejs")].filter(e=>void 0!==e)){const a=this.resources.get("destination")?.name??`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_LENGTH)}-destination-service`;-1===e?.requires?.findIndex(e=>e.name===a)&&("approuter.nodejs"===e.type&&e.requires.push({name:a,...u.UI5StandaloneModuleDestination}),"com.sap.application.content"===e.type&&e.requires.push({name:a,parameters:{"content-target":!0}}),await(this.mta?.updateModule(e)),this.dirty=!0)}}get prefix(){return this.mtaId}get standaloneRouterPath(){return this.modules.get("approuter.nodejs")?.path}get cloudServiceName(){let e;return this.modules.forEach(a=>{const i=a.parameters?.content?.instance?.destinations??[];"com.sap.application.content"===a.type&&i.length&&i.some(a=>(e=a["sap.cloud.service"],!!e))}),e}hasAppFrontendRouter(){return this.modules.has("com.sap.application.content:appfront")}async getParameters(){return this.mta.getParameters()}async getBuildParameters(){return this.mta.getBuildParameters()}async updateParameters(e){await(this.mta?.updateParameters(e)),this.dirty=!0}async updateBuildParams(e){await(this.mta?.updateBuildParameters(e)),this.dirty=!0}async addApp(e,a){const i=this.getAppContentModule();let n=!1;if(i){i[u.MTABuildParams]=i[u.MTABuildParams]??{},i[u.MTABuildParams][u.MTABuildResult]=i[u.MTABuildParams]?.[u.MTABuildResult]??"resources",i[u.MTABuildParams].requires=i[u.MTABuildParams].requires??[];const a=`${e}.zip`;-1!==i[u.MTABuildParams].requires?.findIndex(e=>e.artifacts?.includes?.(a))?(this.log?.debug((0,l.t)("debug.html5AlreadyExists",{appName:e})),n=!0):i[u.MTABuildParams].requires.push({name:e.slice(0,u.MAX_MTA_ID_LENGTH),artifacts:[a],"target-path":`${i[u.MTABuildParams][u.MTABuildResult]}/`.replace(/\/{2,}/g,"/")}),await(this.mta?.updateModule(i)),this.dirty=!0}if(!n&&!this.apps.get(e)){const i={name:e.slice(0,u.MAX_MTA_ID_LENGTH),type:"html5",path:a,"build-parameters":u.HTMLAppBuildParams};await(this.mta?.addModule(i)),this.apps.set(e,i),this.dirty=!0,this.log?.debug((0,l.t)("debug.html5AppAdded",{appName:e}))}await this.syncHtml5Apps(),await this.addMtaDeployParameters()}async syncHtml5Apps(){for(const[e,a]of this.apps.entries())if("html5"===a.type&&a.path&&a["build-parameters"]){this.log?.debug((0,l.t)("debug.processHTML5App",{appName:e}));try{const e=JSON.parse((0,r.readFileSync)((0,o.join)(this.mtaDir,a.path,c.FileName.Package),"utf8"));e&&(0,c.hasDependency)(e,"@sap/ux-ui5-tooling")&&(a["build-parameters"].commands=["npm install","npm run build:cf"],await(this.mta?.updateModule(a)),this.dirty=!0)}catch(e){this.log?.debug((0,l.t)("debug.unableToReadPackageJson",{error:e}))}}}async addConnectivityResource(){const e="connectivity",a=m.CloudFoundryServiceType.Managed,i=`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_LENGTH)}-connectivity`,n=this.modules.get("approuter.nodejs");n&&-1===n.requires?.findIndex(e=>e.name===i)&&(n.requires.push({name:i}),await(this.mta?.updateModule(n)));const o={name:i,type:a,parameters:{service:e,"service-plan":"lite"}};this.resources.has(e)||(await(this.mta?.addResource(o)),this.resources.set(e,o)),this.dirty=!0}async addRouterType({routerType:e,addMissingModules:a=!0}={}){e===m.RouterModuleType.Standard&&await this.addStandaloneRouter(!0),e===m.RouterModuleType.Managed&&await this.addManagedAppRouter(),e===m.RouterModuleType.AppFront&&await this.addAppFrontAppRouter(),e!==m.RouterModuleType.AppFront&&(a&&await this.cleanupMissingResources(),await this.cleanupModules()),await this.addMtaDeployParameters()}async addRoutingModules({isManagedApp:e=!1,isAppFrontApp:a=!1,addMissingModules:i=!0}={}){e&&await this.addManagedAppRouter(),a&&await this.addAppFrontAppRouter(),i&&await this.cleanupMissingResources(),await this.cleanupModules()}async addAbapService(e,a){const i=`${this.prefix?.slice(0,u.MAX_ABAP_SERVICE_PREFIX_LENGTH)}-abap-${e.slice(0,u.MAX_ABAP_SERVICE_NAME_LENGTH)}`,n=this.modules.get("approuter.nodejs");n&&-1===n.requires?.findIndex(e=>e.name===i)&&(n.requires.push({name:i}),await(this.mta?.updateModule(n)));const o={name:i,type:m.CloudFoundryServiceType.Existing,parameters:{"service-name":e,protocol:["ODataV2"],service:a,"service-plan":"16_abap_64_db"}};this.resources.has(i)||(await(this.mta?.addResource(o)),this.resources.set(i,o)),this.dirty=!0}get isABAPServiceFound(){let e=!1;const a=Array.from(this.resources.keys());for(const i of a)if(i.includes(`${this.prefix}-abap-`)){e=!0;break}return e}async addStandaloneRouter(e=!1){this.log?.debug((0,l.t)("debug.addingRouter",{routerType:m.RouterModuleType.Standard})),this.resources.has("xsuaa")||await this.addUaa(),this.resources.has("html5-apps-repo:app-runtime")||await this.addHtml5Runtime(),this.resources.has("destination")||await this.addDestinationResource();const a=this.resources.get("html5-apps-repo:app-runtime")?.name,i=this.resources.get("xsuaa")?.name,n=this.resources.get("destination")?.name;if(n&&i&&a){const o={name:`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_LENGTH)}-router`,type:"approuter.nodejs",path:e?`${u.RouterModule}`:`${u.CloudFoundry}/${u.RouterModule}`,parameters:{"disk-quota":"256M",memory:"256M"},requires:[{name:a},{name:i},{name:n,group:"destinations",properties:{name:"ui5",url:"https://ui5.sap.com",forwardAuthToken:!1}}]};await(this.mta?.addModule(o)),this.modules.set("approuter.nodejs",o),this.dirty=!0}}hasManagedXsuaaResource(){return this.resources.has(u.ManagedXSUAA)}async addMtaExtensionConfig(e,a,i){let n=this.resources.get("destination")?.name;n||(this.log?.info((0,l.t)("info.existingDestinationNotFound")),n=`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_LENGTH)}-destination-service`);const s=this.mtaId,d=(0,o.join)(this.mta.mtaDirPath,c.FileName.MtaExtYaml);let m;try{const e=(0,r.readFileSync)(d,"utf-8");m=await p.YamlDocument.newInstance(e)}catch(e){this.log?.info((0,l.t)("info.existingMTAExtensionNotFound",{error:e.message}))}if(m){const o=m.getSequence({path:"resources"}).items.findIndex(e=>e.get("name")===n);if(o>-1){const n={Authentication:"NoAuthentication",Name:e,ProxyType:"Internet",Type:"HTTP",URL:a,[`URL.headers.${i.key}`]:i.value};m.appendTo({path:`resources.${o}.parameters.config.init_data.instance.destinations`,value:n}),(0,r.writeFileSync)(d,m.toString()),this.log?.info((0,l.t)("info.mtaExtensionUpdated",{mtaExtFile:c.FileName.MtaExtYaml}))}else this.log?.error((0,l.t)("error.updatingMTAExtensionFailed",{mtaExtFilePath:d}))}else{const o={appMtaId:s,mtaExtensionId:`${s}-ext`,destinationName:e,destinationUrl:a,headerKey:i.key,headerValue:i.value,destinationServiceName:n,mtaVersion:"1.0.0"};(0,g.renderTemplateToDisk)(`app/${c.FileName.MtaExtYaml}`,d,o),this.log?.info((0,l.t)("info.mtaExtensionCreated",{appMtaId:s,mtaExtFile:c.FileName.MtaExtYaml}))}}async addDestinationToAppRouter(e){this.hasAppFrontendRouter()?await this.appendAppfrontCAPDestination(e):await this.appendInstanceBasedDestination(e)}async appendAppfrontCAPDestination(e){const a=this.modules.get("com.sap.application.content:appfront");if(a){const i=e===u.DefaultMTADestination?u.SRV_API:e;if(!a.parameters?.config?.destinations?.some(e=>e.Name===i)){const e={...u.CAPAppfrontDestination,name:i};a.parameters?.config?.destinations.push(e),await(this.mta?.updateModule(a))}}}async appendInstanceBasedDestination(e){const a=this.resources.get("destination"),i=e===u.DefaultMTADestination?u.SRV_API:e;if(a){a.requires?.some(e=>e.name===u.SRV_API)||(a.requires=[...a.requires??[],{name:u.SRV_API}]);e===u.SRV_API&&a.parameters?.config?.init_data?.instance?.destinations?.some(e=>e.Name===u.SRV_API)||a.parameters?.config?.init_data?.instance?.destinations?.some(e=>e.Name===i)||a.parameters?.config?.init_data?.instance?.destinations?.push({...u.MTAAPIDestination,Name:i}),await(this.mta?.updateResource(a)),this.resources.set("destination",a),await this.updateServerModule(this.modules.has("nodejs")?"nodejs":"java"),this.dirty=!0}}async save(){return this.dirty&&await(this.mta?.save()),this.dirty}async addAppFrontAppRouter(){if(this.resources.has(u.ManagedXSUAA)||await this.addManagedUAAWithSecurity(),await this.updateServiceName("xsuaa",u.ManagedXSUAA),this.resources.has(u.ManagedAppFront)||await this.addAppFrontResource(),!this.modules.has("com.sap.application.content:appfront")){this.log?.debug((0,l.t)("debug.addingRouter",{routerType:m.RouterModuleType.AppFront}));const e=this.resources.get(u.ManagedAppFront)?.name;if(e){const a={name:`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_LENGTH)}-app-content`,type:"com.sap.application.content",path:".",requires:[{name:e,parameters:{"content-target":!0}}],parameters:{config:{destinations:[u.UI5AppfrontDestinationParameter]}}};this.modules.has("nodejs")&&a.requires?.push({name:u.SRV_API}),await(this.mta?.addModule(a)),this.modules.set("com.sap.application.content:appfront",a),this.dirty=!0}}await this.updateServerModule("com.sap.application.content:appfront",u.ManagedXSUAA,!1),await this.updateServerModule("nodejs",u.ManagedXSUAA,!1)}async addManagedAppRouter(){if(this.resources.has("destination")||await this.addDestinationResource(!0),this.resources.has(u.ManagedXSUAA)||await this.addManagedUAAWithSecurity(),this.resources.has(u.HTML5RepoHost)||await this.addHtml5Host(),!this.modules.has("com.sap.application.content:destination")){this.log?.debug((0,l.t)("debug.addingRouter",{routerType:m.RouterModuleType.Managed}));const e=this.resources.get("destination")?.name,a=this.resources.get(u.HTML5RepoHost)?.name,i=this.resources.get(u.ManagedXSUAA)?.name;if(e&&a&&i){await this.updateServiceName("html5",u.HTML5RepoHost),await this.updateServiceName("xsuaa",u.ManagedXSUAA);const n=this.getServiceInstanceName(u.HTML5RepoHost),o=this.getServiceInstanceName(u.ManagedXSUAA),r={name:`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_LENGTH)}-destination-content`,type:"com.sap.application.content",requires:[{name:e,parameters:{"content-target":!0}},{name:a,parameters:{"service-key":{name:`${a}-key`}}},{name:i,parameters:{"service-key":{name:`${i}-key`}}}],parameters:{content:{instance:{destinations:[{Name:`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_LENGTH)}_html_repo_host`,ServiceInstanceName:n,ServiceKeyName:`${a}-key`,"sap.cloud.service":`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_LENGTH)}`},{Authentication:"OAuth2UserTokenExchange",Name:`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_LENGTH)}_uaa`,ServiceInstanceName:o,ServiceKeyName:`${i}-key`,"sap.cloud.service":`${this.prefix?.slice(0,u.MAX_MTA_PREFIX_LENGTH)}`}],existing_destinations_policy:"update"}}},"build-parameters":{"no-source":!0}};await(this.mta?.addModule(r)),this.modules.set("com.sap.application.content:destination",r),this.dirty=!0}}}getExposedDestinations(e=!1){const a=[],i=this.resources.get("destination");i&&(i.parameters?.config?.init_data?.instance?.destinations?.forEach(i=>(!e||this.isODataDestination(i))&&a.push(i.Name)),i.parameters?.config?.init_data?.subaccount?.destinations?.forEach(i=>(!e||this.isODataDestination(i))&&a.push(i.Name)));const n=this.modules.get("com.sap.application.content:destination");return n&&n.parameters?.content?.instance?.destinations?.map(i=>(!e||this.isODataDestination(i))&&a.push(i.Name)),a}getFormattedPrefix(e){return(0,n.format)(e,this.prefix).replace(/[^\w-]/g,"_")}getAppContentModule(){return this.modules.get("com.sap.application.content:resource")??this.modules.get("com.sap.application.content:appfront")}async addMtaBuildParameters(){const e=await this.getBuildParameters()??{};e["before-all"]??=[],e["before-all"].push({builder:"custom",commands:["npm install"]}),await this.updateBuildParams(e)}async addMtaDeployParameters(){let e=await this.getParameters();e={...e??{}},e[u.deployMode]="html5-repo",e[u.enableParallelDeployments]=!0,await this.updateParameters(e)}}a.MtaConfig=MtaConfig},44385(e,a,i){Object.defineProperty(a,"__esModule",{value:!0}),a.renderTemplateToDisk=function renderTemplateToDisk(e,a,i){const s=(0,n.readFileSync)((0,r.getTemplatePath)(e),"utf-8");(0,n.writeFileSync)(a,(0,o.render)(s,i))};const n=i(73024),o=i(29473),r=i(37736)},85929(e,a,i){Object.defineProperty(a,"__esModule",{value:!0}),a.waitForMtaFile=async function waitForMtaFile(e,a={}){const{maxWaitMs:i=5e3,pollIntervalMs:p=100}=a,c=(0,o.join)(e,s.FileName.MtaYaml),u=Date.now()+i;for(;Date.now()<u;){if((0,n.existsSync)(c))try{const a=new r.Mta(e,!1);if(await a.getMtaID())return}catch{}await new Promise(e=>setTimeout(e,p))}throw new Error((0,d.t)("error.mtaFileNotReady",{mtaPath:e}))};const n=i(73024),o=i(76760),r=i(87827),s=i(20787),d=i(97649)},26011(e,a){var i;Object.defineProperty(a,"__esModule",{value:!0}),a.RouterModuleType=a.CloudFoundryServiceType=void 0,function(e){e.Existing="org.cloudfoundry.existing-service",e.Managed="org.cloudfoundry.managed-service"}(i||(a.CloudFoundryServiceType=i={})),a.RouterModuleType={Standard:"standard",Managed:"managed",AppFront:"appFront"}},37736(e,a,i){Object.defineProperty(a,"__esModule",{value:!0}),a.readManifest=function readManifest(e,a){return a.readJSON(e)},a.getTemplatePath=getTemplatePath,a.toMtaModuleName=toMtaModuleName,a.toPosixPath=function toPosixPath(e){return(0,n.normalize)(e).split(/[\\/]/g).join(n.posix.sep)},a.getDestinationProperties=async function getDestinationProperties(e,a={}){let i,n=!1;if((0,s.isAppStudio)()&&e){const o=await getBTPDestinations(a);o[e]&&(n=(0,s.isFullUrlDestination)(o[e]),i=o[e].Authentication)}return{destinationIsFullUrl:n,destinationAuthentication:i}},a.getBTPDestinations=getBTPDestinations,a.validateVersion=function validateVersion(e){const a=(0,o.coerce)(e);if(e&&!a||a&&!(0,o.satisfies)(a,`>=${p.MTAVersion}`))throw new Error("Invalid MTA version specified. Please use version 0.0.1 or higher.");return!0},a.addXSSecurityConfig=addXSSecurityConfig,a.addGitIgnore=addGitIgnore,a.addRootPackage=addRootPackage,a.addCommonPackageDependencies=async function addCommonPackageDependencies(e,a){await(0,d.addPackageDevDependency)(e,p.UI5TaskZipperPackage,p.UI5TaskZipperPackageVersion,a),await(0,d.addPackageDevDependency)(e,p.UI5Package,p.UI5PackageVersion,a)},a.generateSupportingConfig=async function generateSupportingConfig(e,a,i=!0){e.mtaId&&!a.exists((0,n.join)(e.mtaPath,"package.json"))&&addRootPackage(e,a);e.mtaId&&!a.exists((0,n.join)(e.mtaPath,d.FileName.XSSecurityJson))&&addXSSecurityConfig(e,a,i);a.exists((0,n.join)(e.mtaPath,".gitignore"))||addGitIgnore(e.mtaPath,a)},a.setMtaDefaults=function setMtaDefaults(e){e.mtaPath=e.mtaPath.replace(/\/$/,""),e.addConnectivityService??=!1,e.mtaId=toMtaModuleName(e.mtaId)},a.updateRootPackage=async function updateRootPackage({mtaId:e,rootPath:a},i){if(fileExists(i,(0,n.join)(a,d.FileName.Package))){await alignCdsVersions(a,i),await(0,d.addPackageDevDependency)(a,p.Rimraf,p.RimrafVersion,i),await(0,d.addPackageDevDependency)(a,p.MbtPackage,p.MbtPackageVersion,i);let o=[];i?.exists((0,n.join)(a,d.FileName.MtaExtYaml))&&(o=["-e",d.FileName.MtaExtYaml]);for(const n of[{name:"undeploy",run:(0,p.undeployMTAScript)(e)},{name:"build",run:`${p.MTABuildScript} --mtar archive`},{name:"deploy",run:(0,p.rootDeployMTAScript)(o)}])await(0,d.updatePackageScript)(a,n.name,n.run,i)}},a.enforceValidRouterConfig=function enforceValidRouterConfig(e){const{addManagedAppRouter:a,addAppFrontendRouter:i}=e;a?e.addAppFrontendRouter=!1:i?e.addManagedAppRouter=!1:(e.addManagedAppRouter??=!0,e.addAppFrontendRouter??=!1)},a.alignCdsVersions=alignCdsVersions,a.runCommand=async function runCommand(e,a,i,n){const o=new r.CommandRunner;try{await o.run(a,i,{cwd:e})}catch(e){const a=e instanceof Error?e.message:String(e);throw new Error(`${n}: ${a}`)}},a.fileExists=fileExists;const n=i(76760),o=i(85263),r=i(35752),s=i(75199),d=i(20787),p=i(54036);function getTemplatePath(e){return(0,n.join)(__dirname,"../templates",e)}function toMtaModuleName(e){return e.replaceAll(/[`~!@#$%^&*£()|+=?;:'",.<>]/gi,"")}async function getBTPDestinations(e={}){return e.list??=await(0,s.listDestinations)({stripS4HCApiHosts:!0}),e.list}function addXSSecurityConfig({mtaPath:e,mtaId:a},i,o=!0){i.copyTpl(getTemplatePath(`common/${d.FileName.XSSecurityJson}`),(0,n.join)(e,d.FileName.XSSecurityJson),{id:a.slice(0,p.MAX_MTA_PREFIX_LENGTH),addTenant:o})}function addGitIgnore(e,a){a.copyTpl(getTemplatePath("gitignore.tmpl"),(0,n.join)(e,d.FileName.DotGitIgnore),{})}function addRootPackage({mtaPath:e,mtaId:a},i){i.copyTpl(getTemplatePath(d.FileName.Package),(0,n.join)(e,d.FileName.Package),{mtaId:a})}async function alignCdsVersions(e,a){const i=(0,n.join)(e,d.FileName.Package),r=a.readJSON(i)??{},s=(0,o.coerce)(r?.devDependencies?.[p.CDSDKPackage]),c=r?.dependencies?.[p.CDSPackage];!s&&c&&await(0,d.addPackageDevDependency)(e,p.CDSDKPackage,c,a)}function fileExists(e,a){return e.exists(a)}},54417(e){e.exports=JSON.parse('{"debug":{"logError":"{{method}} error found: {{ error }}","mtaLoaded":"MTA {{ type }} loaded. The size is: {{ size }}.","ui5YamlDoesNotExist":"The `ui5.yaml` file does not exist in the project. Create one. Returned error: {{- error }}","capMtaCreated":"CAP MTA configuration created.","capMtaUpdated":"CAP MTA configuration updated.","capGenerationCompleted":"CAP generation completed.","mtaCreated":"The MTA configuration has been created: {{- mtaPath}}.","mtaSaved":"The MTA configuration has been saved.","mtaSavedFailed":"Saving the MTA configuration failed with the error: {{- error }}.","addingRouter":"Adding {{routerType}} app router...","addMissingModules":"Adding missing modules to MTA configuration...","cleanupModules":"Cleanup modules.","creatingMta":"Creating MTA using {{- cdsParams }}...","html5AppAdded":"HTML5 application added to MTA configuration: {{- appName}}","html5AlreadyExists":"HTML5 application {{- appName}} already exists in the MTA configuration.","addXsuaaService":"Adding XSUAA service to MTA configuration.","mtaReadWithPrefix":"Read `mta.yaml` with prefix {{- prefix }}.","errorReadingMta":"An error occurred when reading the `mta.yaml` file: {{- error }}. Please check the file.","unableToReadPackageJson":"Unable to read the `package.json` file: {{- error }}.","processHTML5App":"Processing HTML5 app: {{- appName }}."},"error":{"unableToLoadMTA":"Unable to load the `mta.yaml` configuration: {{- mtaDir }}. Returned error: {{- error }}.","updatingMTAExtensionFailed":"Unable to add the MTA extension configuration to the file: {{mtaExtFilePath}}.","cannotFindBinary":"Cannot find the \\"{{bin}}\\" executable. Please add it to the path or use \\"npm i -g {{- pkg}}\\" to install it.","mtaExtensionFailed":"Unable to create or update the MTA extension file for the API Hub Enterprise destination configuration: {{error}}.","serviceKeyFailed":"Failed to fetch the service key.","missingMtaParameters":"Missing required parameters, MTA Path, MTA ID, or the Router type is missing.","invalidMtaIdWithChars":"The MTA ID can only contain letters, numbers, dashes, periods, and underscores.","invalidMtaId":"The MTA ID must start with a letter or underscore and be less than 128 characters.","missingABAPServiceBindingDetails":"Missing ABAP service details for direct service binding.","mtaFolderAlreadyExists":"A folder with same name already exists in the target directory.","mtaAlreadyExists":"An `mta.yaml` file already exists in the target directory.","cannotUpdateRouterXSApp":"Unable to update the router `xs-app.json` welcome location.","targetFolderDoesNotExist":"The target folder does not exist: {{targetFolder}}. Check the folder has the correct permissions.","doesNotContainACapApp":"The target folder does not contain a Node.js CAP project. Please ensure the folder contains a Node.js CAP project.","errorInstallingNodeModules":"An error occurred when installing node modules. Please check the logs.","errorGeneratingMtaYaml":"An error occurred when creating the mta.yaml file. For more information, check the logs.","noUI5AppFound":"No SAPUI5 application found. Please ensure the manifest.json file contains a valid \'sap.app.id\'.","mtaFileNotReady":"The `mta.yaml` file in \'{{- mtaPath}}\' was not ready within the allowed time. Please check the file system and retry."},"info":{"existingMTAExtensionNotFound":"Cannot find a valid existing MTA extension file. A new one will be created. Error: {{- error}}.","existingDestinationNotFound":"A destination service resource cannot be found in the `mta.yaml` file. An MTA extension destination instance cannot be added.","mtaExtensionCreated":"Created file: {{mtaExtFile}} to extend the MTA module: {{appMtaId}} with the destination configuration.","mtaExtensionUpdated":"Updated file: {{mtaExtFile}} with the module destination configuration."}}')}};