@sap/generator-fiori
Version:
Create an SAPUI5 application using SAP Fiori elements or a freestyle approach
3 lines (2 loc) • 6.34 kB
JavaScript
const __esmImportMetaUrl = require('node:url').pathToFileURL(__filename).href;
var D=Object.create;var p=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var B=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var o=(e,t)=>p(e,"name",{value:t,configurable:!0});var K=(e,t)=>{for(var r in t)p(e,r,{get:t[r],enumerable:!0})},R=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of U(t))!q.call(e,n)&&n!==r&&p(e,n,{get:()=>t[n],enumerable:!(i=L(t,n))||i.enumerable});return e};var x=(e,t,r)=>(r=e!=null?D(B(e)):{},R(t||!e||!e.__esModule?p(r,"default",{value:e,enumerable:!0}):r,e)),W=e=>R(p({},"__esModule",{value:!0}),e);var g={};K(g,{createAbapServiceProvider:()=>Y,default:()=>Z,getCredentialsFromEnvVariables:()=>T,getCredentialsFromStore:()=>l,getCredentialsWithPrompts:()=>y,inquirer:()=>C,isBasicAuth:()=>O,isDestinationTarget:()=>E,isServiceAuth:()=>f,isUrlTarget:()=>k,questions:()=>c,storeCredentials:()=>G});module.exports=W(g);var a=require("../../open-ux-shared/axios-extension/index.js");var u=require("../../open-ux-shared/store/index.js"),b=require("../../open-ux-shared/btp-utils/index.js"),F=x(require("../../commonlibs/prompts/index.js"),1);var w=require("../../open-ux-shared/store/index.js"),_=require("node:fs");var N={type:"autocomplete",name:"authType",message:"Type of authentication:",choices:[{title:"Basic authentication",value:w.AuthenticationType.Basic},{title:"SAP reentrance tickets",value:w.AuthenticationType.ReentranceTicket}]},$={type:"text",name:"username",message:"Username:"},V={type:"password",name:"password",message:"Password:"},j={type:"text",name:"path",message:"Please provide the service keys as file:",validate:o(e=>(0,_.existsSync)(e),"validate")},z={type:"confirm",name:"store",message:"Do you want to store your credentials in the secure storage?",initial:!0},J={type:"text",name:"name",message:"System name:",validate:o(e=>!!e,"validate")},c={authType:N,username:$,password:V,serviceKeysPath:j,storeCredentials:z,systemName:J},C={};for(let e in c){let t=c[e];C[e]={type:t.type==="text"?"input":t.type,name:t.name,message:t.message,validate:t.validate,default:t.initial}}function O(e){return!!e&&e.password!==void 0}o(O,"isBasicAuth");function f(e){return!!e&&e.serviceKeys!==void 0}o(f,"isServiceAuth");async function l(e,t){try{if(!(0,b.isAppStudio)()){let r=await(0,u.getService)({entityName:"system"}),i=e.url;if(e.connectPath){let s=e.connectPath.startsWith("/")?e.connectPath:`/${e.connectPath}`;i=new URL(s,e.url).href}let n=await r.read(new u.BackendSystemKey({url:i,client:e.client}));return!n&&e.client&&(n=await r.read(new u.BackendSystemKey({url:i}))),n}}catch(r){t.warn("Reading credentials from store failed"),t.debug(r.message)}}o(l,"getCredentialsFromStore");async function G(e,t,r,i){try{let n=await(0,u.getService)({entityName:"system"}),s=new u.BackendSystem({name:e,...t,...r});return await n.write(s),!0}catch(n){return i.error("Could not store credentials."),i.debug(n),!1}}o(G,"storeCredentials");function T(){if(process.env.FIORI_TOOLS_USER&&process.env.FIORI_TOOLS_PASSWORD)return{username:process.env.FIORI_TOOLS_USER,password:process.env.FIORI_TOOLS_PASSWORD}}o(T,"getCredentialsFromEnvVariables");async function y(e){return await(0,F.default)([{...c.username,initial:e},c.password])}o(y,"getCredentialsWithPrompts");var v=require("../../open-ux-shared/btp-utils/index.js");var A=x(require("../../commonlibs/prompts/index.js"),1),I=require("node:fs"),d=require("../../open-ux-shared/store/index.js");function k(e){return e.url!==void 0}o(k,"isUrlTarget");function E(e){return e.destination!==void 0}o(E,"isDestinationTarget");async function H(e,t,r,i){let n={...e,environment:a.AbapCloudEnvironment.Standalone,service:t.serviceKey};if(!n.service){let s=await l(t,i);if(f(s)&&(n.service=s.serviceKeys,n.refreshToken=s.refreshToken,i.info(`Using system [${s.name}] from System store`)),!n.service&&r){let{path:m}=await(0,A.default)(c.serviceKeysPath);n.service=JSON.parse((0,I.readFileSync)(m,"utf-8"))}}if(n.service)return(0,a.createForAbapOnCloud)(n);throw new Error("Service keys required for ABAP Cloud environment.")}o(H,"createAbapCloudServiceProvider");async function M(e,t,r,i){let n=await l(t,i);if(O(n)){e.auth={username:n.username,password:n.password};return}if(f(n))throw new Error("This is an ABAP Cloud system, please correct your configuration.");if(e.auth??=T(),!e.auth&&r){let{authType:s}=await(0,A.default)([c.authType]);if(s===d.AuthenticationType.ReentranceTicket)t.authenticationType=d.AuthenticationType.ReentranceTicket;else{let m=await y(n?.username);e.auth=m,process.env.FIORI_TOOLS_USER=m.username,process.env.FIORI_TOOLS_PASSWORD=m.password}}}o(M,"resolveOnPremCredentials");async function Q(e,t,r,i){return e.auth||await M(e,t,r,i),t.authenticationType===d.AuthenticationType.ReentranceTicket?(0,a.createForAbapOnCloud)({...e,...t,environment:a.AbapCloudEnvironment.EmbeddedSteampunk}):(0,a.createForAbap)(e)}o(Q,"createAbapOnPremServiceProvider");async function X(e,t,r){let n=(await(0,v.listDestinations)())?.[t.destination];if(!n)throw new Error(`Destination ${t.destination} not found on subaccount`);let s=(0,a.createForDestination)(e,n);if(r){let m=s.interceptors.response.use(void 0,async h=>{if(s.interceptors.response.eject(m),h.response?.status===401){let S=await y();return s.defaults.auth=S,process.env.FIORI_TOOLS_USER=S.username,process.env.FIORI_TOOLS_PASSWORD=S.password,s.request(h.config)}else throw h})}return s}o(X,"createAbapDestinationServiceProvider");async function Y(e,t,r,i){let n,s={params:e.params??{},...t};if((0,v.isAppStudio)()&&E(e))n=await X(s,e,r);else if(k(e))e.scp||e.serviceKey?n=await H(s,e,r,i):e.authenticationType===d.AuthenticationType.ReentranceTicket?n=(0,a.createForAbapOnCloud)({ignoreCertErrors:s.ignoreCertErrors,environment:a.AbapCloudEnvironment.EmbeddedSteampunk,...e}):(s.baseURL=e.url,e.client&&(s.params["sap-client"]=e.client),n=await Q(s,e,r,i));else throw new Error("Unable to handle the configuration in the current environment.");return n}o(Y,"createAbapServiceProvider");var Z=void 0;0&&(module.exports={createAbapServiceProvider,getCredentialsFromEnvVariables,getCredentialsFromStore,getCredentialsWithPrompts,inquirer,isBasicAuth,isDestinationTarget,isServiceAuth,isUrlTarget,questions,storeCredentials});