@zuplo/core 6.18.16 → 6.18.18

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.
@@ -591,7 +591,7 @@ globstar while`,s,Z,l,Re,Ae),this.matchOne(s.slice(Z),l.slice(Re),_))return this
591
591
  export default devPortal;`}t(Ghr,"generateSource");function nht(a){return{name:"dev-portal-config",setup(s){s.onResolve({filter:/dev-portal.json$/},l=>({namespace:"dev-portal-json",path:sfe.isAbsolute(l.path)?l.path:sfe.join(l.resolveDir,l.path),pluginName:"dev-portal"})),s.onLoad({filter:/.*/,namespace:"dev-portal-json"},async l=>hf.timeFn("Generating dev-portal.json data",async()=>{let _,m,b=[];if(await yl.fileExists(l.path)){m=await Vhr.readFile(l.path,"utf-8");try{_=JSON.parse(m)}catch{b.push({id:"dev-portal-build-error",text:"Could not parse dev-portal.json. Ensure that the file is valid JSON.",location:{file:"dev-portal.json",namespace:"dev-portal-json",line:1,column:0,length:0,lineText:"",suggestion:""},detail:"DevPortalValidationError",pluginName:"dev-portal",notes:[{text:"Could not parse dev-portal.json. Ensure that the file is valid JSON.",location:null}]})}}if(b&&b.length>0)throw b;let D;try{if(D=Ghr(_),ph.DEBUG_BUILD_MODE&&D){let A=sfe.join(a.sourceDirectory,".zuplo","dev-portal.js");await ak(A,D)}if(b&&b.length>0)throw b}catch(A){A.length>0?A.forEach(M=>{let U={id:"dev-portal-build-error",text:M.message,location:{file:"dev-portal.json",namespace:"dev-portal-json",line:1,column:0,length:0,lineText:"issue",suggestion:""},detail:"DevPortalValidationError",pluginName:"dev-portal",notes:[{text:M.message,location:null}]};b.push(U)}):b.push({id:"dev-portal-build-error",text:A.message,location:{file:"dev-portal.json",namespace:"dev-portal-json",line:1,column:0,length:0,lineText:"issue",suggestion:""},detail:"DevPortalValidationError",pluginName:"dev-portal",notes:[{text:A.message,location:null}]})}return{contents:D,errors:b,pluginName:"dev-portal",loader:"js",resolveDir:sfe.dirname(l.path),watchFiles:[l.path]}}))}}}t(nht,"devPortalConfigPlugin");import iht from"path";var sht="legacy-environment",aht="legacy-environment",Khr=`import { environment } from "@zuplo/runtime";
592
592
  export default environment;`;function oht(a){return{name:"environment",setup(s){s.onResolve({filter:/@app\/environment$/},()=>({namespace:aht,pluginName:sht,path:iht.join(a.sourceDirectory,Z4,"environment.js")})),s.onLoad({filter:/.*/,namespace:aht},async l=>({contents:Khr,loader:"ts",resolveDir:iht.dirname(l.path),pluginName:sht}))}}}t(oht,"environmentPlugin");var yyt=up(mFe(),1),vyt=up(U0t(),1),byt=up(UFe(),1),Syt=up($Fe(),1);import G2r from"fs/promises";import q2 from"path";var pk="schemas",$fe="json-schema";function Tyt(a){return{name:pk,async setup(s){let l=new byt.Ajv2020({code:{source:!0},allErrors:!0,strict:!1,verbose:!0,meta:!0});(0,vyt.default)(l,{mode:"fast"}),l.opts.code.formats=yyt._`require("ajv-formats/dist/formats").fastFormats`;let _=q2.join(a.sourceDirectory,uH),m,b=[],D=[];if(await yl.dirExists(_)&&(l.addKeyword("faker"),m=await yl.listFolderContents(_,uH),await Promise.all(m.map(async A=>{try{let M=yl.safePath(a.sourceDirectory).resolve(_,A);if(!M.startsWith(_))throw new Error("All schemas must be in the schemas directory");let U=await G2r.readFile(M,"utf-8");if(U===""||U===void 0)throw new Error(`Schema 'schemas/${A}' is empty and will be ignored.`);let ne=JSON.parse(U);if(ne.$schema&&ne.$schema!=="https://json-schema.org/draft/2020-12/schema")throw new Error(`Error in ${A}: All JSON schemas must use version 2020-12. See release notes for changes: https://json-schema.org/draft/2020-12/release-notes.html`);if(l.$dataMetaSchema,l.addSchema(ne,A),l.errors?.length){let se=l.errors[0];b.push({id:"json-schema-validation-error",pluginName:pk,text:`Error: ${se.message}`,location:{file:q2.join(uH,A)},detail:{params:se.params,propertyName:se.propertyName,schemaPath:se.schemaPath,data:se.data}})}}catch(M){if(M.message.endsWith("is empty and will be ignored.")){D.push({id:"empty-json-schema-file",pluginName:pk,text:`Schema 'schemas/${A}' is empty and will be ignored.`,location:{file:`schemas/${A}`,suggestion:"Add schema details or remove the file from the project."},detail:"EmptyJSONSchemaFile",notes:[{text:`Schema 'schemas/${A}' is empty and will be ignored.`,location:{file:`schemas/${A}`,suggestion:"Add schema details or remove the file from the project."}}]});return}let U=await S8e(A,a.sourceDirectory,M.message);b.push({id:"json-schema-add-error",pluginName:pk,text:`Error: ${M.message}`,location:U,detail:"InvalidAddSchemaError",notes:[{text:M.message}]})}})),await Promise.all(m.map(async A=>{try{let M=l.getSchema(A);M&&l.compile(M.schema).errors?.forEach(ne=>{b.push({text:`Failed to compile ${A}: ${ne.message}`})})}catch(M){let U=await S8e(A,a.sourceDirectory,M.message);b.push({id:"json-schema-compile-error",pluginName:pk,text:`The schema file '${A}' is not valid. Error: ${M.message}`,location:U,detail:"InvalidSchemaError",notes:[{text:M.message}]})}})),ph.DEBUG_BUILD_MODE)){let A=q2.resolve(a.outputDirectory,uH);await yl.mkdirIfNotExists(A)}s.onStart(async()=>{if(m)return{errors:b,warnings:D}}),s.onResolve({filter:/schemas\/.*\.json$/},async A=>{let M=q2.isAbsolute(A.path)?A.path:q2.join(A.resolveDir,A.path);if(A.importer&&A.importer!==q2.join(a.sourceDirectory,"config/routes.json"))return{path:M};if(!await yl.fileExists(M)){let U="policies.json";return{errors:[{id:"json-schema-build-error",text:`Unable to resolve reference to '${A.path}' from ${U}`,location:{file:q2.join(A.resolveDir,U),namespace:$fe,line:1,column:0,length:0,lineText:`Invalid JSON schema reference in ${U}`,suggestion:""},detail:"RouteReferenceError",pluginName:pk,notes:[{text:`Unable to resolve reference to '${A.path}' from ${U}`,location:null}]}],namespace:$fe,path:M,pluginName:pk}}return{path:M,namespace:$fe,pluginName:pk}}),s.onLoad({filter:/.*/,namespace:$fe},async A=>hf.timeFn(`Generating json schema data: ${q2.basename(A.path)}`,async()=>{let M=[],U;try{let ne=q2.relative(_,A.path),se=l.getSchema(ne);if(!se)throw new Error(`Could not load schema at ${A.path}`);U=se.source?.validateCode;let Z=l.compile(se.schema);U=(0,Syt.default)(l,Z)}catch(ne){M.push({pluginName:pk,text:`Cannot parse project's schemas/${q2.basename(A.path)} file. Error: ${ne.message}`,location:null,notes:[{text:ne.message,location:null}],detail:ne})}if(ph.DEBUG_BUILD_MODE&&U){let ne=q2.relative(_,A.path),se=q2.join(a.sourceDirectory,".zuplo",`${ne}.js`);await ak(se,U)}return{contents:U,errors:M,pluginName:pk,resolveDir:q2.dirname(A.path),watchFiles:[A.path]}}))}}}t(Tyt,"jsonSchemaPlugin");import{relative as K2r}from"path";var xyt=["node:assert","node:async_hooks","node:buffer","node:crypto","node:diagnostics_channel","node:events","node:path","node:process","node:stream","node:string_decoder","node:util"],Y2r="nodejs-compat-plugin";function Cyt({sourceDirectory:a}){return{name:Y2r,setup(s){let l=new Set;s.onStart(()=>{l.clear()}),s.onResolve({filter:/node:.*/},async({path:_,kind:m,resolveDir:b,...D})=>{let A=`${_}:${m}:${b}:${D.importer}`;if(l.has(A))return;l.add(A);let M=await s.resolve(_,{kind:m,resolveDir:b,importer:D.importer});return M.errors.length>0?xyt.includes(_)||_.includes("/")&&xyt.includes(_.split("/")[0])?{external:!0}:{external:!0,warnings:M.errors.map(ne=>({...ne,location:{file:K2r(a,D.importer),line:0,column:0,namespace:"",length:0,lineText:"",suggestion:"Remove the imported node module"},detail:`The package "${_}" wasn't found on the file system but is built into node. If this code is executed it will fail.`}))}:M})}}}t(Cyt,"nodejsCompatPlugin");import Eyt from"fs/promises";import eE from"path";var Cj="open-api-routes-plugin",Jfe="open-api-routes-json";function Dyt(a){return{name:"open-api-routes-plugin",setup(s){s.onResolve({filter:/routes.json$/},l=>({watchFiles:[...JFe(eE.join(a.sourceDirectory,M1),[".oas.json"],!0),eE.join(a.sourceDirectory,M1,yce)],namespace:Jfe,path:eE.isAbsolute(l.path)?l.path:eE.join(l.resolveDir,l.path),pluginName:Cj})),s.onResolve({filter:/^\.\.\/modules\/.*/,namespace:Jfe},async l=>{let _=eE.join(l.resolveDir,`${l.path}.ts`);if(!await yl.fileExists(_)){let m=`$import(.${l.path.replace(/^../,"")})`,b=eE.resolve(a.sourceDirectory,"config"),D=await xO(b),A=await got(D,m,"Update your route configuration to use code from the 'modules' folder");return{errors:[{id:"route-build-error",text:`Invalid handler reference in routes.json. Unable to resolve reference to '${m}' from routes.json`,location:A,detail:"RouteReferenceError",pluginName:Cj}],namespace:Jfe,path:l.path,pluginName:Cj}}}),s.onLoad({filter:/.*/,namespace:Jfe},async l=>hf.timeFn("Generating route.json data",async()=>{let _=eE.resolve(a.sourceDirectory,"config"),m=await xO(_),b=await Promise.all(m.map(async U=>({content:await Eyt.readFile(U,"utf-8"),fileName:U}))),D=eE.resolve(_,"policies.json");if(!await yl.fileExists(D))return{errors:[{text:"The project must include a policies file ('/config/policies.json')",detail:"OASPoliciesFileMissing",pluginName:Cj,location:{line:0,column:0,file:"/config/policies.json"}}],pluginName:Cj};let A={content:await Eyt.readFile(D,"utf-8"),fileName:D},M;try{M=await g8e({sourceDirectory:a.sourceDirectory,oasContent:b,policiesContent:A})}catch(U){throw new Error("Error compiling routes: "+U.message)}if(ph.DEBUG_BUILD_MODE&&M.content){let U=eE.join(a.sourceDirectory,".zuplo"),ne=eE.resolve(U,"routes.js");await ak(ne,M.content)}return{contents:M.content,errors:M.errors,pluginName:Cj,resolveDir:eE.dirname(l.path),watchFiles:[l.path]}}))}}}t(Dyt,"openApiRoutesPlugin");import zfe from"path";var zFe="raw-route-plugin",kyt="raw-route";function wyt(a){return{name:"raw-route-plugin",setup(s){s.onResolve({filter:/raw.json$/},l=>({namespace:kyt,path:l.path,pluginName:zFe})),s.onLoad({filter:/.*/,namespace:kyt},async l=>{let _=zfe.resolve(a.sourceDirectory,M1);if(!await yl.dirExists(_))return{loader:"js",resolveDir:zfe.dirname(l.path),pluginName:zFe};let m=await xO(_),b=await b8e({oasFiles:m,sourceDirectory:a.sourceDirectory,logger:a.logger});if(ph.DEBUG_BUILD_MODE&&b){let D=zfe.join(a.sourceDirectory,".zuplo","raw-routes.js");await ak(D,b)}return{contents:b,loader:"js",resolveDir:zfe.dirname(l.path),pluginName:zFe}})}}}t(wyt,"rawRoutePlugin");import X2r from"fs/promises";import qFe from"path";var qfe="runtime-config",Pyt="runtime-config-plugin";function Ayt(){return{name:qfe,setup(a){a.onResolve({filter:/^\.\.\/modules\/zuplo.runtime.ts$/},s=>({namespace:Pyt,path:qFe.isAbsolute(s.path)?s.path:qFe.join(s.resolveDir,s.path),pluginName:qfe})),a.onLoad({filter:/.*/,namespace:Pyt},async s=>hf.timeFn("Generating zuplo.runtime.ts data",async()=>{let l="export const runtimeInit = undefined;",_=[];return await yl.fileExists(s.path)?(l=await X2r.readFile(s.path,"utf-8"),{contents:l,loader:"ts",resolveDir:qFe.dirname(s.path),errors:_,pluginName:qfe,watchFiles:[s.path]}):{contents:l,loader:"ts",errors:_,pluginName:qfe}}))}}}t(Ayt,"runtimeConfigPlugin");var Iyt=up(UFe(),1),Oyt=up($Fe(),1);import HFe from"fs/promises";import cF from"path";var VFe="schema-validation-plugin",Nyt="schema-validation",Q2r="module.exports = {}";function Fyt(a){return{name:"schema-validation-plugin",setup(s){s.onResolve({filter:/ajv-schema.json$/},l=>({namespace:Nyt,path:l.path,pluginName:VFe})),s.onLoad({filter:/.*/,namespace:Nyt},async l=>{let _=cF.resolve(a.sourceDirectory,M1,"policies.json");if(!await yl.fileExists(_))return{contents:Q2r,loader:"js",resolveDir:cF.dirname(l.path),pluginName:VFe};let m=await eSr(a.sourceDirectory),b=cF.resolve(a.sourceDirectory,M1),D=await xO(b),A=await iSr(D,m),M=await Z2r({oasFiles:D,routesWithSchemaValidation:A,sourceDirectory:a.sourceDirectory,logger:a.logger});if(ph.DEBUG_BUILD_MODE&&M){let U=cF.join(a.sourceDirectory,".zuplo","schema-validation.js");await ak(U,M)}return{contents:M,loader:"js",resolveDir:cF.dirname(l.path),pluginName:VFe}})}}}t(Fyt,"schemaValidationPlugin");async function Z2r({oasFiles:a,routesWithSchemaValidation:s,sourceDirectory:l,logger:_}){let m="",b=new _3(l,_);if(s.length===0)return m;let D=new Iyt.Ajv2020({code:{source:!0},allErrors:!0,strict:!1,verbose:!0,meta:!0});for(let A of a){let M=await HFe.readFile(A,"utf-8"),U=cF.basename(A,".oas.json"),ne=s.filter(ke=>ke.fileName===U),se=await b.resolve(A),Z=JSON.parse(M),Re=[],Ae=new Map;ne.forEach(ke=>{let Ot=Z.paths[ke.path][ke.method];if(Ot.requestBody){let kt;if(Ot.requestBody.$ref){let br=Ot.requestBody.$ref;kt=se.get(br)?.content}else Ot.requestBody.content&&(kt=Ot.requestBody.content);if(kt)for(let br in kt){let Kr=kt[br].schema,on=e3e(ke.path,ke.method,br);Kr.$id=on,D.addSchema(Kr),WFe(Kr,A,U,D,se,Re,Ae)}}if(Ot.parameters)for(let kt of Ot.parameters){let br=kt.$ref?se.get(kt.$ref):kt,Kr=br.schema.$ref?se.get(br.schema.$ref):br.schema,on=Z4e(ke.path,ke.method,br.in,br.name);Kr.$id=on,D.addSchema(Kr),WFe(br,A,U,D,se,Re,Ae)}});for(let ke of Re){let Ot=se.get(ke),kt=tG(U,ke);D.addSchema(Ot,kt)}}return m=(0,Oyt.default)(D),m}t(Z2r,"schemaValidationSource");function WFe(a,s,l,_,m,b,D){for(let A in a){let M=a[A];if(A==="$ref"){let U=tG(l,n3(s,M));a[A]=U,RH(s,l,n3(s,M),m,b,D,(ne,se)=>tG(ne,n3(s,se)))}else typeof M=="object"&&WFe(M,s,l,_,m,b,D)}}t(WFe,"addRefsToSchema");async function eSr(a){let s=new Set(["RequestValidationInboundPolicy"]),l=await HFe.readFile(`${a}/config/policies.json`,"utf-8"),_=JSON.parse(l);return tSr(_,s)}t(eSr,"getPolicyNamesUsingSchemaValidationPolicies");function tSr(a,s){let l=new Set;a.policies?.forEach(m=>{m.handler?.export&&s.has(m.handler.export)&&m.handler.module==="$import(@zuplo/runtime)"&&l.add(m.name)});let _=rSr(a,l);return new Set([...l,..._])}t(tSr,"getPolicyNamesReferencingPolicyHandlers");function rSr(a,s){let l=new Set;return a.policies?.forEach(_=>{_.handler?.export==="CompositeInboundPolicy"&&_.handler?.options?.policies?.forEach(m=>{s.has(m)&&l.add(_.name)})}),l}t(rSr,"getCompositePoliciesContainingPolicy");function nSr(a,s){if(!a["x-zuplo-route"]||!a["x-zuplo-route"].policies)return!1;let l=a["x-zuplo-route"].policies.inbound;if(l){for(let m of l)if(s.has(m))return!0}let _=a["x-zuplo-route"].policies.outbound;if(_){for(let m of _)if(s.has(m))return!0}return!1}t(nSr,"isPolicyPresentInOperation");async function iSr(a,s){let l=[];for(let _ of a){let m=await HFe.readFile(_,"utf-8"),D=JSON.parse(m).paths;for(let A in D){let M=D[A];for(let U in M){let ne=M[U];nSr(ne,s)&&l.push({fileName:cF.basename(_,".oas.json"),path:A,method:U})}}}return l}t(iSr,"getRoutesContainingPolicies");import{mkdirSync as sSr,writeFileSync as aSr}from"fs";import oSr from"path";import Lyt from"path";function Ej(a,s){let l=Lyt.relative(process.cwd(),Lyt.join(a,GR));return Object.keys(s?.outputs??{}).map(m=>`.${m.replace(l,"")}`)}t(Ej,"getBuildModules");function Ryt(a){return{name:"write-modules-plugin",setup(s){s.onEnd(async l=>{if(l){let _=Ej(a.sourceDirectory,l.metafile);sSr(a.outputDirectory,{recursive:!0}),aSr(oSr.join(a.outputDirectory,"modules.json"),JSON.stringify(_,null,2))}})}}}t(Ryt,"writeModulesPlugin");var cSr=eht("zuplo:core:build"),lSr=["workerd","worker","browser"],Byt=[...process.env.GLOBAL_MODULE_LOCATION?[process.env.GLOBAL_MODULE_LOCATION]:[],GFe.resolve(Myt(jyt(import.meta.url)),"..","..","..","node_modules"),GFe.resolve(Myt(jyt(import.meta.url)),"..","..","..","..","..","node_modules")];async function OK({systemDirectory:a,outputDirectory:s,sourceDirectory:l,cacheDirectory:_,logger:m,minify:b=!0,command:D,flags:A}){let M=GFe.join(a,Sce);cSr(`Building with node paths: ${Byt.join(", ")}`);let U=b&&D!=="dev"&&!process.env.DEBUG_BUILD_DISABLE_MINIFY?{minify:!0,chunkNames:"[hash]"}:{minify:!1,keepNames:!0,chunkNames:"[name]-[hash]"},ne={sourceDirectory:l,outputDirectory:s,cacheDirectory:_,logger:m,debugMode:ph.DEBUG_BUILD_MODE,flags:A};return{platform:"browser",target:"es2022",outdir:s,splitting:!0,metafile:!0,format:"esm",nodePaths:Byt,entryPoints:[M],sourcemap:"linked",legalComments:"none",treeShaking:!0,bundle:!0,...U,external:[],logLevel:"silent",conditions:lSr,plugins:[oht(ne),tht(ne),Dyt(ne),wyt(ne),Fyt(ne),Ayt(),nht(ne),Tyt(ne),Cyt(ne),Ryt(ne)]}}t(OK,"getBaseESBuildConfig");var lF="run-esbuild",$yt=t(async function({systemDirectory:a,outputDirectory:s,sourceDirectory:l,cacheDirectory:_,buildId:m,logger:b,config:D,command:A,minify:M},U){return hf.timeFn("Running esbuild",async()=>{b.info(`Running build_id: ${m}`);let ne=await OK({command:A,minify:M,systemDirectory:a,outputDirectory:s,cacheDirectory:_,sourceDirectory:l,logger:b,flags:D.flags}),se;try{if(!await oM(l))throw new Error("Failed to build project because no open-api file was found on the 'config' folder");se=await Uyt.build(ne),U.set("metafile",se.metafile)}catch(Ae){if(b.error(Ae),Ae.errors||Ae.warnings)se=Ae;else if(Ae.message.includes("Failed to build project because no open-api file was found on the 'config' folder"))se={warnings:[],errors:[{id:"missing-open-api-file",text:"Failed to build project because no open-api file was found on the 'config' folder",pluginName:lF,location:null,notes:[],detail:"Failed to build project because no open-api file was found on the 'config' folder"}],outputFiles:void 0,metafile:void 0,mangleCache:void 0};else throw Ae}se.errors.length>0&&se.errors.length>1&&(se.errors.length=1);let{errors:Z,warnings:Re}=KFe({buildId:m,result:se});return{errors:Z,warnings:Re}})},"runEsbuild");function KFe({buildId:a,result:s}){return{status:s.errors.length>0?"Failed":s.warnings.length>0?"Warnings":"Good",runtimeVersion:"0.0.0",buildTime:"",buildTimeMs:0,buildId:a,warnings:s.warnings.map(_=>_.text==="Using direct eval with a bundler is not recommended and may cause problems"?{location:_.location,detail:_.detail,id:_.id,notes:_.notes,message:"We do not support the use of 'eval' or 'new Function(...)'",severity:dce,pluginName:_.pluginName||lF}:{location:_.location,detail:_.detail,id:_.id,notes:_.notes,message:_.text,severity:dce,pluginName:_.pluginName||lF}),errors:s.errors.map(_=>({location:_.location,detail:_.detail,id:_.id,notes:_.notes,message:_.text,severity:qAe,pluginName:_.pluginName||lF})),metafile:s.metafile}}t(KFe,"esbuildResultToBuildResult");var uSr=t((a,s)=>{let l=s;if(s.includes(a)){let _=new RegExp(`.*(${a})`,"g");l=s.replace(_,"")}return l.match(/^(\/)?(\.\.(\/)?)+/)&&(l=l.replace(/^(\/)?(\.\.(\/)?)+/,"/")),l},"removePrefixFromString"),fSr=t((a,s)=>{let l=s;if(l.includes(a)){let _=new RegExp(`[a-zA-Z0-9-_.\\/]+(${a})`,"g");l=l.replace(_,"")}return l},"cleanFilePathsInMessage"),Jyt=t((a,s,l)=>{if(!a||a.length<=0)return a;let _=a.filter(m=>m.message!=='Could not resolve "@zuplo/runtime"');return _&&_.length>0&&_.forEach(m=>{try{m.location&&m.location.file&&(m.location.file=uSr(s,m.location.file)),m.location&&m.location.lineText&&m.location.lineText.includes("@zuplo/core/index.minified.js")&&(m.location.lineText=m.location.lineText.substring(0,200)+"...<Truncated>"),m.message=fSr(s,m.message),m.notes&&m.notes.length>0&&delete m.notes,m.text&&delete m.text,m.pluginName===""&&(m.pluginName=l)}catch{}}),_},"cleanDataOnBuildIssue");function zyt(a,s){let l=YFe.basename(s);a.errors&&(a.errors=Jyt(a.errors,l,lF)),a.warnings&&(a.warnings=Jyt(a.warnings,l,lF))}t(zyt,"formatBuildResult");var _Sr=t(a=>YFe.basename(a).startsWith("."),"isHiddenOnUnix"),pSr=t((a,s=[])=>s.map(l=>l.startsWith(".")?l:`.${l}`).some(l=>a.endsWith(l)),"hasMatchingExtname");function JFe(a,s=[],l=!1){let _=[],m;if(!Vfe.existsSync(a)){let b;if(IH.hasMagic(a))b=a;else{let D=s.map(A=>A.startsWith(".")?A:`.${A}`).join("|");b=`${a}+(${D})`}if(_.push(...IH.sync(b,{nodir:!0})),!_.length)throw Error(`Cannot find any files matching pattern "${a}"`);return _}try{if(m=Vfe.statSync(a),m.isFile())return[a]}catch{return[]}return Vfe.readdirSync(a).forEach(b=>{let D=YFe.join(a,b),A;try{if(A=Vfe.statSync(D),A.isDirectory()){l&&_.push(...JFe(D,s,l));return}}catch{return}if(!s.length)throw Error(`Argument '${s}' required when argument '${a}' is a directory`);!A.isFile()||!pSr(D,s)||_Sr(D)||_.push(D)}),_}t(JFe,"lookupFiles");var Dj=new Dce({level:process.env.FORCE_BUILD_COLORS?2:void 0}),uF=` ${Dj.gray("|")} `;function XFe({output:a,buildId:s,runtimeVersion:l,compatibilityDate:_}){let m=["Building Zuplo API...",`${uF}Build ID: ${s}`,`${uF}Runtime Version: ${l}`];_&&m.push(`${uF}Compatibility Date: ${_}`),a.info(m.join(`
593
593
  `))}t(XFe,"outputBuildStart");async function Wfe(a,s,l){zyt(l,a),await Promise.all(l.warnings.map(_=>qyt(a,s,_))),await Promise.all(l.errors.map(_=>qyt(a,s,_))),l.status==="Good"?s.info(Dj.green("Build succeeded"),{status:"success"}):l.status==="Warnings"?s.warn(Dj.yellow("Build succeeded with warnings"),{status:"success"}):l.status==="Failed"&&s.error(Dj.red("Failed to build API"),{status:"failed"})}t(Wfe,"outputBuildResult");async function qyt(a,s,l){let _=[],m=l.severity==="error"?Dj.red:Dj.yellow,b=m(`${l.severity.toUpperCase()}: ${l.message}${l.detail?`
594
- ${uF}${l.detail.split(`
594
+ ${uF}${l.detail.toString().split(`
595
595
  `).join(`
596
596
  ${uF}`)}`:""}`);_.push(b);let D=hSr(l.location??void 0);if(D&&_.push(`${uF}${m(`The error was found in the file: ${D}`)}`),l.location&&l.location.column!==0&&l.location.line!==0){let A=mSr.join(a,l.location.file),M=await dSr(A,"utf-8"),U=(0,Vyt.codeFrameColumns)(M,{start:{line:l.location.line,column:l.location.column}},{highlightCode:!0,message:l.message,linesAbove:3,linesBelow:3});_.push(uF),_.push(U)}_.push(""),l.severity==="warning"?s.warn(_.join(`
597
597
  `)):s.error(_.join(`
package/index.minified.js CHANGED
@@ -589,14 +589,15 @@ globstar while`,s,Z,l,Re,Ae),this.matchOne(s.slice(Z),l.slice(Re),_))return this
589
589
  `?(A=0,M++):A++;this.column=A,this.line=M;return}}let{length:_}=s,{lineEnd:m}=this;_>0&&(this.lineEndSize>0&&(m.length===1?s[_-1]===m:s.endsWith(m))?(this.line+=this.lineEndSize,this.column=0):this.column+=_)}toString(){return this.output}};function Kmt(a,s){let l=new E8e(s);return l.generator[a.type](a,l),l.output}t(Kmt,"generate");import Yhr from"fs/promises";import Xhr from"path";async function D8e({oasFiles:a,sourceDirectory:s,logger:l}){let _=await Qhr({oasFiles:a,sourceDirectory:s,logger:l});return Kmt(_)}t(D8e,"generateRawRouteSource");async function Qhr({oasFiles:a,sourceDirectory:s,logger:l}){let _=new p3(s,l),m=[];for(let D of a){let A=Xhr.basename(D,".oas.json"),M=await _.resolve(D),U=[],ne=new Map,se=await Yhr.readFile(D,"utf-8"),Z=JSON.parse(se);for(let Re in Z.paths){let Ae=Z.paths[Re];for(let ke in Ae){if(ke.startsWith("x-"))continue;let{description:Ot,...kt}=Ae[ke],br=eG(A,Re,ke),Kr=nfe(D,A,kt,M,U,ne);m.unshift(Xmt(br,Kr))}}m.unshift(...Zhr(A,M,U,ne).reverse())}return{type:"Program",body:m,sourceType:"module"}}t(Qhr,"generateAst");function nfe(a,s,l,_,m,b){let D=[];for(let A in l){let M=l[A];if(A==="$ref")return RH(a,s,i3(a,M),_,m,b),{type:"Identifier",name:Qmt(s,b.get(i3(a,M)))};let U;switch(typeof M){case"string":case"number":case"boolean":U={type:"Literal",value:M};break;default:Array.isArray(M)?U=Ymt(M,a,s,_,m,b):typeof M=="object"&&M!==null&&(U={type:"ObjectExpression",properties:nfe(a,s,M,_,m,b).properties||[]});break}if(U){let ne=/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(A),se=ne?{type:"Identifier",name:A}:{type:"Literal",value:A};D.push({type:"Property",key:se,value:U,kind:"init",method:!1,shorthand:!1,computed:!ne})}}return{type:"ObjectExpression",properties:D}}t(nfe,"processNode");function Ymt(a,s,l,_,m,b){return{type:"ArrayExpression",elements:a.map(D=>{if(Array.isArray(D))return Ymt(D,s,l,_,m,b);if(typeof D=="object"&&D!==null){let A=nfe(s,l,D,_,m,b);return A.type==="Identifier"?A:{type:"ObjectExpression",properties:A.properties||[]}}else return{type:"Literal",value:D}})}}t(Ymt,"processArray");function Xmt(a,s){return{type:"ExportNamedDeclaration",declaration:{type:"VariableDeclaration",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:a},init:s}],kind:"var"},specifiers:[],source:null}}t(Xmt,"createExportedConstAssignment");function Zhr(a,s,l,_){let m=[];for(let b=0;b<l.length;b++){let D=Qmt(a,b),A=s.get(l[b]),M=nfe(B6e(l[b]),a,A,s,l,_);m.push(Xmt(D,M))}return m}t(Zhr,"generateRefs");function Qmt(a,s){return`${nA(a)}__ref__${s}`}t(Qmt,"getRefIdentifierName");import Zmt from"path";var eht=t(a=>{let s=null;if(a.value.type==="Object"&&a.value.members.length>0)for(let l of a.value.members){let _=eht(l);if(_!==null&&(s=_),l.name.value==="enum"&&l.value.type==="Array"&&l.value.elements.length===0){let m=l.value,b=m.loc.start.line,D=m.loc.start.column,A=m.loc.end.column;s={line:b,column:D,length:A-D,lineText:""}}}return s},"findEmptyEnums"),egr=t(a=>{if(a.startsWith("schema with key or id")&&a.endsWith("already exists"))return"Update your schema's '$id' to be unique across your project.";if(a.includes("All JSON schemas must use version 2020-12"))return"All JSON schemas must use version 2020-12. See release notes for changes: https://json-schema.org/draft/2020-12/release-notes.html";if(a==='"nullable" cannot be used without "type"')return'Property "nullable" can only be used when property "type" value is "object".';if(a==='NOT SUPPORTED: keyword "id", use "$id" for schema ID')return'Replace keyword "id" with "$id" when defining a schema Id.';if(a.startsWith("can't resolve reference http"))return"Cannot resolve remote references, try adding them directly to the schema file or as a schema file in the project.";if(a.startsWith("can't resolve reference"))return"Make sure all references are defined in the schema.";if(a.includes("oneOf must NOT have fewer than 1 items"))return'Property "oneOf" must have at least 1 item configured.';if(a.includes("enum must have non-empty array"))return'Property "enum" must be configured with at least one value.';if(a.includes("Unexpected")&&a.includes("in JSON at position"))return"Update your schema to only use valid properties."},"getSuggestions"),k8e=t(async(a,s,l)=>{if(!a)return null;let _={file:Zmt.join(R6e,a),suggestion:egr(l)},m=Zmt.join(s,R6e),b=yl.safePath(s).resolve(m,a),D=await Xce(b);if(l.includes("enum must have non-empty array")){if(D){let A=await LH(D);if(A&&A.body.members!==null)for(let M of A.body.members){let U=eht(M);U&&U!==null&&(_=Object.assign(_??{},U))}if(_){let M=_.line?_.line:0;_.lineText=FH(D,M)}}}else if(l.includes("Unexpected")&&l.includes("in JSON at position")&&D){let A=await LH(D);A&&"lineText"in A&&(_=Object.assign(_??{},A))}return _},"getLocation");import*as Vyt from"esbuild";import{performance as ife,PerformanceObserver as tgr}from"perf_hooks";var w8e=[];async function rgr(a,s){let l=ife.timerify(s),_=new tgr(m=>{let b=m.getEntries()[0];w8e.push({name:a,duration:b.duration}),_.disconnect()});return _.observe({entryTypes:["function"]}),l()}t(rgr,"timeFn");var ngr={mark:t(a=>{ife.mark(a)},"mark"),measure:t((a,s,l)=>{ife.measure(a,s,l)},"measure"),timeFn:rgr,report:t(()=>{w8e.length>0&&console.table(w8e)},"report"),getDuration:t(a=>{let s=ife.getEntriesByName(a);return s.length===0?0:s[0].duration},"getDuration")},hf=ngr;var igr=!1;function nj(a,s){return{open:`\x1B[${a.join(";")}m`,close:`\x1B[${s}m`,regexp:new RegExp(`\\x1b\\[${s}m`,"g")}}t(nj,"code");function ij(a,s){return igr?`${s.open}${a.replace(s.regexp,s.open)}${s.close}`:a}t(ij,"run");function sgr(a){return ij(a,nj([31],39))}t(sgr,"red");function agr(a){return ij(a,nj([32],39))}t(agr,"green");function ogr(a){return ij(a,nj([33],39))}t(ogr,"yellow");function cgr(a){return ij(a,nj([34],39))}t(cgr,"blue");function lgr(a){return ij(a,nj([35],39))}t(lgr,"magenta");function ugr(a){return ij(a,nj([36],39))}t(ugr,"cyan");var _Lr=new RegExp(["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|"),"g");var tht=[sgr,agr,ogr,cgr,lgr,ugr];function fgr(a){let s=0,l=a.length,_=0;if(l>0)for(;_<l;)s=(s<<5)-s+a.charCodeAt(_++)|0;return s}t(fgr,"hashCode");function rht(a){let s=Math.abs(fgr(a));return tht[s%tht.length]}t(rht,"generateColor");import{inspect as _gr}from"util";function nht(a,s,...l){let _=0,m=l.length,b=String(s).replace(/%[sdjoO%]/g,D=>{if(D==="%%")return"%";if(_>=m)return D;switch(D){case"%s":return String(l[_++]);case"%d":return Number(l[_++]).toString();case"%o":return a(l[_++]).split(`
590
590
  `).map(A=>A.trim()).join(" ");case"%O":return a(l[_++]);case"%j":try{return JSON.stringify(l[_++])}catch{return"[Circular]"}default:return D}});for(let D of l.splice(_))D===null||!(typeof D=="object"&&D!==null)?b+=" "+D:b+=" "+a(D);return b}t(nht,"format");var iht=t((a,...s)=>nht(_gr,a,s),"format");var P8e=class{static{t(this,"Debugger")}manager;ns;color;last;enabled;constructor(s,l){this.manager=s,this.ns=l,this.color=rht(l),this.last=0,this.enabled=s.enabled.some(_=>_.test(l))}log(...s){if(!this.enabled)return;let l,_=s[0];typeof _=="function"?l=_():l=String(_);let m=Date.now()-(this.last||Date.now());l=iht(l,...s);let b=`${this.color(this.ns)} ${l} ${this.color(`+${m}ms`)}`;console.log(b),this.last=Date.now()}},A8e=class{static{t(this,"DebugManager")}debuggers;enabled;constructor(s){this.debuggers=new Map,this.enabled=s??[]}};function pgr(a){return!a||a.length===0?[]:(a=a.replace(/\s/g,"").replace(/\*/g,".+"),a.split(",").map(s=>new RegExp(`^${s}$`)))}t(pgr,"extract");var sfe;function sht(a){sfe||(sfe=new A8e(pgr(process.env.DEBUG)));let s=new P8e(sfe,a);return sfe.debuggers.set(a,s),Object.assign(s.log.bind(s),{self:s})}t(sht,"debug");import e7e,{dirname as Jyt}from"path";import{fileURLToPath as zyt}from"url";var N8e=class{static{t(this,"Environment")}get DEV_SERVER_PORT(){return process.env.DEV_SERVER_PORT?parseInt(process.env.DEV_SERVER_PORT):3e3}get DEBUG_BUILD_MODE(){return!!process.env.DEBUG_BUILD_MODE}get USE_MONOREPO_PACKAGES(){return process.env.USE_MONOREPO_PACKAGES==="true"}get EXPERIMENTAL_CODEGEN(){return!!process.env.EXPERIMENTAL_CODEGEN}get NODE_ENV(){return process.env.NODE_ENV}isProduction(){return this.NODE_ENV==="production"}isLocalDevelopment(){return process.env.ZUPLO_IS_LOCAL_DEVELOPMENT==="true"}},dgr=new N8e,Ym=dgr;var I8e="no-remote-module";function aht({logger:a}){return{name:I8e,async setup(s){s.onResolve({filter:/^https?:\/\//},l=>(a.error(l,"User attempted to load a remote module"),{errors:[{text:`Remote modules are not supported. Attempted to load module ${l.path}`,detail:"InvalidRemoteModule",pluginName:I8e,location:{line:0,column:0,file:""}}],pluginName:I8e}))}}}t(aht,"blockRemoteModulePlugin");import hgr from"fs/promises";import afe from"path";import{writeFile as mgr}from"fs/promises";async function ok(a,s){await yl.mkdirForFilePathIfNotExits(a);let l=await import("prettier"),_=s;try{_=await l.format(s,{parser:"babel"})}catch{}await mgr(a,_,"utf-8")}t(ok,"writeDebugSourceFile");var oht="/docs",ggr="/__zuplo/dev-portal";function ygr(a){let s=a.trim().toLowerCase();return s.endsWith("/")&&(s=s.slice(0,-1)),s}t(ygr,"normalizePathname");function vgr(a){let s={sitePathname:a?.sitePathname===ggr?oht:a?.sitePathname?ygr(a.sitePathname):oht,enabled:a?a.enabled??!0:!1};return`const devPortal = ${JSON.stringify(s)};
591
591
  export default devPortal;`}t(vgr,"generateSource");function cht(a){return{name:"dev-portal-config",setup(s){s.onResolve({filter:/dev-portal.json$/},l=>({namespace:"dev-portal-json",path:afe.isAbsolute(l.path)?l.path:afe.join(l.resolveDir,l.path),pluginName:"dev-portal"})),s.onLoad({filter:/.*/,namespace:"dev-portal-json"},async l=>hf.timeFn("Generating dev-portal.json data",async()=>{let _,m,b=[];if(await yl.fileExists(l.path)){m=await hgr.readFile(l.path,"utf-8");try{_=JSON.parse(m)}catch{b.push({id:"dev-portal-build-error",text:"Could not parse dev-portal.json. Ensure that the file is valid JSON.",location:{file:"dev-portal.json",namespace:"dev-portal-json",line:1,column:0,length:0,lineText:"",suggestion:""},detail:"DevPortalValidationError",pluginName:"dev-portal",notes:[{text:"Could not parse dev-portal.json. Ensure that the file is valid JSON.",location:null}]})}}if(b&&b.length>0)throw b;let D;try{if(D=vgr(_),Ym.DEBUG_BUILD_MODE&&D){let A=afe.join(a.sourceDirectory,".zuplo","dev-portal.js");await ok(A,D)}if(b&&b.length>0)throw b}catch(A){A.length>0?A.forEach(M=>{let U={id:"dev-portal-build-error",text:M.message,location:{file:"dev-portal.json",namespace:"dev-portal-json",line:1,column:0,length:0,lineText:"issue",suggestion:""},detail:"DevPortalValidationError",pluginName:"dev-portal",notes:[{text:M.message,location:null}]};b.push(U)}):b.push({id:"dev-portal-build-error",text:A.message,location:{file:"dev-portal.json",namespace:"dev-portal-json",line:1,column:0,length:0,lineText:"issue",suggestion:""},detail:"DevPortalValidationError",pluginName:"dev-portal",notes:[{text:A.message,location:null}]})}return{contents:D,errors:b,pluginName:"dev-portal",loader:"js",resolveDir:afe.dirname(l.path),watchFiles:[l.path]}}))}}}t(cht,"devPortalConfigPlugin");import lht from"path";var uht="legacy-environment",fht="legacy-environment",bgr=`import { environment } from "@zuplo/runtime";
592
- export default environment;`;function _ht(a){return{name:"environment",setup(s){s.onResolve({filter:/@app\/environment$/},()=>({namespace:fht,pluginName:uht,path:lht.join(a.sourceDirectory,e3,"environment.js")})),s.onLoad({filter:/.*/,namespace:fht},async l=>({contents:bgr,loader:"ts",resolveDir:lht.dirname(l.path),pluginName:uht}))}}}t(_ht,"environmentPlugin");var xyt=S_(SFe(),1),Cyt=S_(V0t(),1),Eyt=S_(WFe(),1),Dyt=S_(HFe(),1);import vSr from"fs/promises";import q2 from"path";var dk="schemas",Jfe="json-schema";function kyt(a){return{name:dk,async setup(s){let l=new Eyt.Ajv2020({code:{source:!0},allErrors:!0,strict:!1,verbose:!0,meta:!0});(0,Cyt.default)(l,{mode:"fast"}),l.opts.code.formats=xyt._`require("ajv-formats/dist/formats").fastFormats`;let _=q2.join(a.sourceDirectory,uH),m,b=[],D=[];if(await yl.dirExists(_)&&(l.addKeyword("faker"),m=await yl.listFolderContents(_,uH),await Promise.all(m.map(async A=>{try{let M=yl.safePath(a.sourceDirectory).resolve(_,A);if(!M.startsWith(_))throw new Error("All schemas must be in the schemas directory");let U=await vSr.readFile(M,"utf-8");if(U===""||U===void 0)throw new Error(`Schema 'schemas/${A}' is empty and will be ignored.`);let ne=JSON.parse(U);if(ne.$schema&&ne.$schema!=="https://json-schema.org/draft/2020-12/schema")throw new Error(`Error in ${A}: All JSON schemas must use version 2020-12. See release notes for changes: https://json-schema.org/draft/2020-12/release-notes.html`);if(l.$dataMetaSchema,l.addSchema(ne,A),l.errors?.length){let se=l.errors[0];b.push({id:"json-schema-validation-error",pluginName:dk,text:`Error: ${se.message}`,location:{file:q2.join(uH,A)},detail:{params:se.params,propertyName:se.propertyName,schemaPath:se.schemaPath,data:se.data}})}}catch(M){if(M.message.endsWith("is empty and will be ignored.")){D.push({id:"empty-json-schema-file",pluginName:dk,text:`Schema 'schemas/${A}' is empty and will be ignored.`,location:{file:`schemas/${A}`,suggestion:"Add schema details or remove the file from the project."},detail:"EmptyJSONSchemaFile",notes:[{text:`Schema 'schemas/${A}' is empty and will be ignored.`,location:{file:`schemas/${A}`,suggestion:"Add schema details or remove the file from the project."}}]});return}let U=await k8e(A,a.sourceDirectory,M.message);b.push({id:"json-schema-add-error",pluginName:dk,text:`Error: ${M.message}`,location:U,detail:"InvalidAddSchemaError",notes:[{text:M.message}]})}})),await Promise.all(m.map(async A=>{try{let M=l.getSchema(A);M&&l.compile(M.schema).errors?.forEach(ne=>{b.push({text:`Failed to compile ${A}: ${ne.message}`})})}catch(M){let U=await k8e(A,a.sourceDirectory,M.message);b.push({id:"json-schema-compile-error",pluginName:dk,text:`The schema file '${A}' is not valid. Error: ${M.message}`,location:U,detail:"InvalidSchemaError",notes:[{text:M.message}]})}})),Ym.DEBUG_BUILD_MODE)){let A=q2.resolve(a.outputDirectory,uH);await yl.mkdirIfNotExists(A)}s.onStart(async()=>{if(m)return{errors:b,warnings:D}}),s.onResolve({filter:/schemas\/.*\.json$/},async A=>{let M=q2.isAbsolute(A.path)?A.path:q2.join(A.resolveDir,A.path);if(A.importer&&A.importer!==q2.join(a.sourceDirectory,"config/routes.json"))return{path:M};if(!await yl.fileExists(M)){let U="policies.json";return{errors:[{id:"json-schema-build-error",text:`Unable to resolve reference to '${A.path}' from ${U}`,location:{file:q2.join(A.resolveDir,U),namespace:Jfe,line:1,column:0,length:0,lineText:`Invalid JSON schema reference in ${U}`,suggestion:""},detail:"RouteReferenceError",pluginName:dk,notes:[{text:`Unable to resolve reference to '${A.path}' from ${U}`,location:null}]}],namespace:Jfe,path:M,pluginName:dk}}return{path:M,namespace:Jfe,pluginName:dk}}),s.onLoad({filter:/.*/,namespace:Jfe},async A=>hf.timeFn(`Generating json schema data: ${q2.basename(A.path)}`,async()=>{let M=[],U;try{let ne=q2.relative(_,A.path),se=l.getSchema(ne);if(!se)throw new Error(`Could not load schema at ${A.path}`);U=se.source?.validateCode;let Z=l.compile(se.schema);U=(0,Dyt.default)(l,Z)}catch(ne){M.push({pluginName:dk,text:`Cannot parse project's schemas/${q2.basename(A.path)} file. Error: ${ne.message}`,location:null,notes:[{text:ne.message,location:null}],detail:ne})}if(Ym.DEBUG_BUILD_MODE&&U){let ne=q2.relative(_,A.path),se=q2.join(a.sourceDirectory,".zuplo",`${ne}.js`);await ok(se,U)}return{contents:U,errors:M,pluginName:dk,resolveDir:q2.dirname(A.path),watchFiles:[A.path]}}))}}}t(kyt,"jsonSchemaPlugin");import{relative as bSr}from"path";var wyt=["node:assert","node:async_hooks","node:buffer","node:crypto","node:diagnostics_channel","node:events","node:path","node:process","node:stream","node:string_decoder","node:util"],SSr="nodejs-compat-plugin";function Pyt({sourceDirectory:a}){return{name:SSr,setup(s){let l=new Set;s.onStart(()=>{l.clear()}),s.onResolve({filter:/node:.*/},async({path:_,kind:m,resolveDir:b,...D})=>{let A=`${_}:${m}:${b}:${D.importer}`;if(l.has(A))return;l.add(A);let M=await s.resolve(_,{kind:m,resolveDir:b,importer:D.importer});return M.errors.length>0?wyt.includes(_)||_.includes("/")&&wyt.includes(_.split("/")[0])?{external:!0}:{external:!0,warnings:M.errors.map(ne=>({...ne,location:{file:bSr(a,D.importer),line:0,column:0,namespace:"",length:0,lineText:"",suggestion:"Remove the imported node module"},detail:`The package "${_}" wasn't found on the file system but is built into node. If this code is executed it will fail.`}))}:M})}}}t(Pyt,"nodejsCompatPlugin");import Ayt from"fs/promises";import eE from"path";var Dj="open-api-routes-plugin",zfe="open-api-routes-json";function Nyt(a){return{name:"open-api-routes-plugin",setup(s){s.onResolve({filter:/routes.json$/},l=>({watchFiles:[...GFe(eE.join(a.sourceDirectory,Ny),[".oas.json"],!0),eE.join(a.sourceDirectory,Ny,vce)],namespace:zfe,path:eE.isAbsolute(l.path)?l.path:eE.join(l.resolveDir,l.path),pluginName:Dj})),s.onResolve({filter:/^\.\.\/modules\/.*/,namespace:zfe},async l=>{let _=eE.join(l.resolveDir,`${l.path}.ts`);if(!await yl.fileExists(_)){let m=`$import(.${l.path.replace(/^../,"")})`,b=eE.resolve(a.sourceDirectory,"config"),D=await EO(b),A=await Tot(D,m,"Update your route configuration to use code from the 'modules' folder");return{errors:[{id:"route-build-error",text:`Invalid handler reference in routes.json. Unable to resolve reference to '${m}' from routes.json`,location:A,detail:"RouteReferenceError",pluginName:Dj}],namespace:zfe,path:l.path,pluginName:Dj}}}),s.onLoad({filter:/.*/,namespace:zfe},async l=>hf.timeFn("Generating route.json data",async()=>{let _=eE.resolve(a.sourceDirectory,"config"),m=await EO(_),b=await Promise.all(m.map(async U=>({content:await Ayt.readFile(U,"utf-8"),fileName:U}))),D=eE.resolve(_,"policies.json");if(!await yl.fileExists(D))return{errors:[{text:"The project must include a policies file ('/config/policies.json')",detail:"OASPoliciesFileMissing",pluginName:Dj,location:{line:0,column:0,file:"/config/policies.json"}}],pluginName:Dj};let A={content:await Ayt.readFile(D,"utf-8"),fileName:D},M;try{M=await x8e({sourceDirectory:a.sourceDirectory,oasContent:b,policiesContent:A})}catch(U){throw new Error("Error compiling routes: "+U.message)}if(Ym.DEBUG_BUILD_MODE&&M.content){let U=eE.join(a.sourceDirectory,".zuplo"),ne=eE.resolve(U,"routes.js");await ok(ne,M.content)}return{contents:M.content,errors:M.errors,pluginName:Dj,resolveDir:eE.dirname(l.path),watchFiles:[l.path]}}))}}}t(Nyt,"openApiRoutesPlugin");import qfe from"path";var KFe="raw-route-plugin",Iyt="raw-route";function Oyt(a){return{name:"raw-route-plugin",setup(s){s.onResolve({filter:/raw.json$/},l=>({namespace:Iyt,path:l.path,pluginName:KFe})),s.onLoad({filter:/.*/,namespace:Iyt},async l=>{let _=qfe.resolve(a.sourceDirectory,Ny);if(!await yl.dirExists(_))return{loader:"js",resolveDir:qfe.dirname(l.path),pluginName:KFe};let m=await EO(_),b=await D8e({oasFiles:m,sourceDirectory:a.sourceDirectory,logger:a.logger});if(Ym.DEBUG_BUILD_MODE&&b){let D=qfe.join(a.sourceDirectory,".zuplo","raw-routes.js");await ok(D,b)}return{contents:b,loader:"js",resolveDir:qfe.dirname(l.path),pluginName:KFe}})}}}t(Oyt,"rawRoutePlugin");import TSr from"fs/promises";import YFe from"path";var Vfe="runtime-config",Fyt="runtime-config-plugin";function Lyt(){return{name:Vfe,setup(a){a.onResolve({filter:/^\.\.\/modules\/zuplo.runtime.ts$/},s=>({namespace:Fyt,path:YFe.isAbsolute(s.path)?s.path:YFe.join(s.resolveDir,s.path),pluginName:Vfe})),a.onLoad({filter:/.*/,namespace:Fyt},async s=>hf.timeFn("Generating zuplo.runtime.ts data",async()=>{let l="export const runtimeInit = undefined;",_=[];return await yl.fileExists(s.path)?(l=await TSr.readFile(s.path,"utf-8"),{contents:l,loader:"ts",resolveDir:YFe.dirname(s.path),errors:_,pluginName:Vfe,watchFiles:[s.path]}):{contents:l,loader:"ts",errors:_,pluginName:Vfe}}))}}}t(Lyt,"runtimeConfigPlugin");var Myt=S_(WFe(),1),jyt=S_(HFe(),1);import ZFe from"fs/promises";import uF from"path";var XFe="schema-validation-plugin",Ryt="schema-validation",xSr="module.exports = {}";function Byt(a){return{name:"schema-validation-plugin",setup(s){s.onResolve({filter:/ajv-schema.json$/},l=>({namespace:Ryt,path:l.path,pluginName:XFe})),s.onLoad({filter:/.*/,namespace:Ryt},async l=>{let _=uF.resolve(a.sourceDirectory,Ny,"policies.json");if(!await yl.fileExists(_))return{contents:xSr,loader:"js",resolveDir:uF.dirname(l.path),pluginName:XFe};let m=await ESr(a.sourceDirectory),b=uF.resolve(a.sourceDirectory,Ny),D=await EO(b),A=await PSr(D,m),M=await CSr({oasFiles:D,routesWithSchemaValidation:A,sourceDirectory:a.sourceDirectory,logger:a.logger});if(Ym.DEBUG_BUILD_MODE&&M){let U=uF.join(a.sourceDirectory,".zuplo","schema-validation.js");await ok(U,M)}return{contents:M,loader:"js",resolveDir:uF.dirname(l.path),pluginName:XFe}})}}}t(Byt,"schemaValidationPlugin");async function CSr({oasFiles:a,routesWithSchemaValidation:s,sourceDirectory:l,logger:_}){let m="",b=new p3(l,_);if(s.length===0)return m;let D=new Myt.Ajv2020({code:{source:!0},allErrors:!0,strict:!1,verbose:!0,meta:!0});for(let A of a){let M=await ZFe.readFile(A,"utf-8"),U=uF.basename(A,".oas.json"),ne=s.filter(ke=>ke.fileName===U),se=await b.resolve(A),Z=JSON.parse(M),Re=[],Ae=new Map;ne.forEach(ke=>{let Ot=Z.paths[ke.path][ke.method];if(Ot.requestBody){let kt;if(Ot.requestBody.$ref){let br=Ot.requestBody.$ref;kt=se.get(br)?.content}else Ot.requestBody.content&&(kt=Ot.requestBody.content);if(kt)for(let br in kt){let Kr=kt[br].schema,on=a3e(ke.path,ke.method,br);Kr.$id=on,D.addSchema(Kr),QFe(Kr,A,U,D,se,Re,Ae)}}if(Ot.parameters)for(let kt of Ot.parameters){let br=kt.$ref?se.get(kt.$ref):kt,Kr=br.schema.$ref?se.get(br.schema.$ref):br.schema,on=s3e(ke.path,ke.method,br.in,br.name);Kr.$id=on,D.addSchema(Kr),QFe(br,A,U,D,se,Re,Ae)}});for(let ke of Re){let Ot=se.get(ke),kt=tG(U,ke);D.addSchema(Ot,kt)}}return m=(0,jyt.default)(D),m}t(CSr,"schemaValidationSource");function QFe(a,s,l,_,m,b,D){for(let A in a){let M=a[A];if(A==="$ref"){let U=tG(l,i3(s,M));a[A]=U,RH(s,l,i3(s,M),m,b,D,(ne,se)=>tG(ne,i3(s,se)))}else typeof M=="object"&&QFe(M,s,l,_,m,b,D)}}t(QFe,"addRefsToSchema");async function ESr(a){let s=new Set(["RequestValidationInboundPolicy"]),l=await ZFe.readFile(`${a}/config/policies.json`,"utf-8"),_=JSON.parse(l);return DSr(_,s)}t(ESr,"getPolicyNamesUsingSchemaValidationPolicies");function DSr(a,s){let l=new Set;a.policies?.forEach(m=>{m.handler?.export&&s.has(m.handler.export)&&m.handler.module==="$import(@zuplo/runtime)"&&l.add(m.name)});let _=kSr(a,l);return new Set([...l,..._])}t(DSr,"getPolicyNamesReferencingPolicyHandlers");function kSr(a,s){let l=new Set;return a.policies?.forEach(_=>{_.handler?.export==="CompositeInboundPolicy"&&_.handler?.options?.policies?.forEach(m=>{s.has(m)&&l.add(_.name)})}),l}t(kSr,"getCompositePoliciesContainingPolicy");function wSr(a,s){if(!a["x-zuplo-route"]||!a["x-zuplo-route"].policies)return!1;let l=a["x-zuplo-route"].policies.inbound;if(l){for(let m of l)if(s.has(m))return!0}let _=a["x-zuplo-route"].policies.outbound;if(_){for(let m of _)if(s.has(m))return!0}return!1}t(wSr,"isPolicyPresentInOperation");async function PSr(a,s){let l=[];for(let _ of a){let m=await ZFe.readFile(_,"utf-8"),D=JSON.parse(m).paths;for(let A in D){let M=D[A];for(let U in M){let ne=M[U];wSr(ne,s)&&l.push({fileName:uF.basename(_,".oas.json"),path:A,method:U})}}}return l}t(PSr,"getRoutesContainingPolicies");import{mkdirSync as ASr,writeFileSync as NSr}from"fs";import ISr from"path";import Uyt from"path";function kj(a,s){let l=Uyt.relative(process.cwd(),Uyt.join(a,bO));return Object.keys(s?.outputs??{}).map(m=>`.${m.replace(l,"")}`)}t(kj,"getBuildModules");function $yt(a){return{name:"write-modules-plugin",setup(s){s.onEnd(async l=>{if(l){let _=kj(a.sourceDirectory,l.metafile);ASr(a.outputDirectory,{recursive:!0}),NSr(ISr.join(a.outputDirectory,"modules.json"),JSON.stringify(_,null,2))}})}}}t($yt,"writeModulesPlugin");var OSr=sht("zuplo:core:build"),FSr=["workerd","worker","browser"],qyt=[...process.env.GLOBAL_MODULE_LOCATION?[process.env.GLOBAL_MODULE_LOCATION]:[],e7e.resolve(Jyt(zyt(import.meta.url)),"..","..","..","node_modules"),e7e.resolve(Jyt(zyt(import.meta.url)),"..","..","..","..","..","node_modules")];async function OK({systemDirectory:a,outputDirectory:s,sourceDirectory:l,cacheDirectory:_,logger:m,minify:b=!0,command:D,flags:A}){let M=e7e.join(a,Tce);OSr(`Building with node paths: ${qyt.join(", ")}`);let U=b&&D!=="dev"&&!process.env.DEBUG_BUILD_DISABLE_MINIFY?{minify:!0,chunkNames:"[hash]"}:{minify:!1,keepNames:!0,chunkNames:"[name]-[hash]"},ne={sourceDirectory:l,outputDirectory:s,cacheDirectory:_,logger:m,debugMode:Ym.DEBUG_BUILD_MODE,flags:A};return{platform:"browser",target:"es2022",outdir:s,splitting:!0,metafile:!0,format:"esm",nodePaths:qyt,entryPoints:[M],sourcemap:"linked",legalComments:"none",treeShaking:!0,bundle:!0,...U,external:[],logLevel:"silent",conditions:FSr,plugins:[_ht(ne),aht(ne),Nyt(ne),Oyt(ne),Byt(ne),Lyt(),cht(ne),kyt(ne),Pyt(ne),$yt(ne)]}}t(OK,"getBaseESBuildConfig");var fF="run-esbuild",Wyt=t(async function({systemDirectory:a,outputDirectory:s,sourceDirectory:l,cacheDirectory:_,buildId:m,logger:b,config:D,command:A,minify:M},U){return hf.timeFn("Running esbuild",async()=>{b.info(`Running build_id: ${m}`);let ne=await OK({command:A,minify:M,systemDirectory:a,outputDirectory:s,cacheDirectory:_,sourceDirectory:l,logger:b,flags:D.flags}),se;try{if(!await lM(l))throw new Error("Failed to build project because no open-api file was found on the 'config' folder");se=await Vyt.build(ne),U.set("metafile",se.metafile)}catch(Ae){if(b.error(Ae),Ae.errors||Ae.warnings)se=Ae;else if(Ae.message.includes("Failed to build project because no open-api file was found on the 'config' folder"))se={warnings:[],errors:[{id:"missing-open-api-file",text:"Failed to build project because no open-api file was found on the 'config' folder",pluginName:fF,location:null,notes:[],detail:"Failed to build project because no open-api file was found on the 'config' folder"}],outputFiles:void 0,metafile:void 0,mangleCache:void 0};else throw Ae}se.errors.length>0&&se.errors.length>1&&(se.errors.length=1);let{errors:Z,warnings:Re}=t7e({buildId:m,result:se});return{errors:Z,warnings:Re}})},"runEsbuild");function t7e({buildId:a,result:s}){return{status:s.errors.length>0?"Failed":s.warnings.length>0?"Warnings":"Good",runtimeVersion:"0.0.0",buildTime:"",buildTimeMs:0,buildId:a,warnings:s.warnings.map(_=>_.text==="Using direct eval with a bundler is not recommended and may cause problems"?{location:_.location,detail:_.detail,id:_.id,notes:_.notes,message:"We do not support the use of 'eval' or 'new Function(...)'",severity:mce,pluginName:_.pluginName||fF}:{location:_.location,detail:_.detail,id:_.id,notes:_.notes,message:_.text,severity:mce,pluginName:_.pluginName||fF}),errors:s.errors.map(_=>({location:_.location,detail:_.detail,id:_.id,notes:_.notes,message:_.text,severity:GAe,pluginName:_.pluginName||fF})),metafile:s.metafile}}t(t7e,"esbuildResultToBuildResult");var LSr=t((a,s)=>{let l=s;if(s.includes(a)){let _=new RegExp(`.*(${a})`,"g");l=s.replace(_,"")}return l.match(/^(\/)?(\.\.(\/)?)+/)&&(l=l.replace(/^(\/)?(\.\.(\/)?)+/,"/")),l},"removePrefixFromString"),RSr=t((a,s)=>{let l=s;if(l.includes(a)){let _=new RegExp(`[a-zA-Z0-9-_.\\/]+(${a})`,"g");l=l.replace(_,"")}return l},"cleanFilePathsInMessage"),Hyt=t((a,s,l)=>{if(!a||a.length<=0)return a;let _=a.filter(m=>m.message!=='Could not resolve "@zuplo/runtime"');return _&&_.length>0&&_.forEach(m=>{try{m.location&&m.location.file&&(m.location.file=LSr(s,m.location.file)),m.location&&m.location.lineText&&m.location.lineText.includes("@zuplo/core/index.minified.js")&&(m.location.lineText=m.location.lineText.substring(0,200)+"...<Truncated>"),m.message=RSr(s,m.message),m.notes&&m.notes.length>0&&delete m.notes,m.text&&delete m.text,m.pluginName===""&&(m.pluginName=l)}catch{}}),_},"cleanDataOnBuildIssue");function Gyt(a,s){let l=r7e.basename(s);a.errors&&(a.errors=Hyt(a.errors,l,fF)),a.warnings&&(a.warnings=Hyt(a.warnings,l,fF))}t(Gyt,"formatBuildResult");var MSr=t(a=>r7e.basename(a).startsWith("."),"isHiddenOnUnix"),jSr=t((a,s=[])=>s.map(l=>l.startsWith(".")?l:`.${l}`).some(l=>a.endsWith(l)),"hasMatchingExtname");function GFe(a,s=[],l=!1){let _=[],m;if(!Wfe.existsSync(a)){let b;if(IH.hasMagic(a))b=a;else{let D=s.map(A=>A.startsWith(".")?A:`.${A}`).join("|");b=`${a}+(${D})`}if(_.push(...IH.sync(b,{nodir:!0})),!_.length)throw Error(`Cannot find any files matching pattern "${a}"`);return _}try{if(m=Wfe.statSync(a),m.isFile())return[a]}catch{return[]}return Wfe.readdirSync(a).forEach(b=>{let D=r7e.join(a,b),A;try{if(A=Wfe.statSync(D),A.isDirectory()){l&&_.push(...GFe(D,s,l));return}}catch{return}if(!s.length)throw Error(`Argument '${s}' required when argument '${a}' is a directory`);!A.isFile()||!jSr(D,s)||MSr(D)||_.push(D)}),_}t(GFe,"lookupFiles");var tE=new kce({level:process.env.FORCE_BUILD_COLORS?2:void 0}),_F=` ${tE.gray("|")} `;function vUr(a,s){a.info(tE.green(s))}t(vUr,"outputSuccess");function bUr(a,s){a.warn(tE.yellow(s))}t(bUr,"outputWarning");function SUr(a,s){a.error(tE.red(s))}t(SUr,"outputCritical");function TUr(a,s){let l=s.sort((D,A)=>{let M=D.path.split("/").length,U=A.path.split("/").length;return M!==U?M-U:D.path.localeCompare(A.path)}),_=Math.max(...l.map(D=>D.path.length)),m=l.reduce((D,A)=>{let M=A.path.includes("/")?A.path.split("/")[0]:"/";return D[M]||(D[M]=[]),D[M].push(A),D},{}),b="";Object.keys(m).forEach(D=>{b+=D==="/"?`/
593
- `:`${D}/
594
- `,m[D].forEach(A=>{let M=" ".repeat(_-A.path.length),U=A.bytes/1024,ne=` ${A.path}${M} ${U.toFixed(2)} KB
595
- `;b+=U>1024?tE.red(ne):U>300?tE.yellow(ne):ne}),b+=`
596
- `}),a.info(b)}t(TUr,"outputFileTree");function xUr(a,s){if(s.length===0)return"";let l=Object.keys(s[0]).length,_=Array.from({length:l},(D,A)=>Math.max(...s.map(M=>String(Object.values(M)[A]).length))),b=s.map(D=>Object.values(D).map((A,M)=>String(A).padEnd(_[M])).join(" ")).join(`
592
+ export default environment;`;function _ht(a){return{name:"environment",setup(s){s.onResolve({filter:/@app\/environment$/},()=>({namespace:fht,pluginName:uht,path:lht.join(a.sourceDirectory,e3,"environment.js")})),s.onLoad({filter:/.*/,namespace:fht},async l=>({contents:bgr,loader:"ts",resolveDir:lht.dirname(l.path),pluginName:uht}))}}}t(_ht,"environmentPlugin");var xyt=S_(SFe(),1),Cyt=S_(V0t(),1),Eyt=S_(WFe(),1),Dyt=S_(HFe(),1);import vSr from"fs/promises";import q2 from"path";var dk="schemas",Jfe="json-schema";function kyt(a){return{name:dk,async setup(s){let l=new Eyt.Ajv2020({code:{source:!0},allErrors:!0,strict:!1,verbose:!0,meta:!0});(0,Cyt.default)(l,{mode:"fast"}),l.opts.code.formats=xyt._`require("ajv-formats/dist/formats").fastFormats`;let _=q2.join(a.sourceDirectory,uH),m,b=[],D=[];if(await yl.dirExists(_)&&(l.addKeyword("faker"),m=await yl.listFolderContents(_,uH),await Promise.all(m.map(async A=>{try{let M=yl.safePath(a.sourceDirectory).resolve(_,A);if(!M.startsWith(_))throw new Error("All schemas must be in the schemas directory");let U=await vSr.readFile(M,"utf-8");if(U===""||U===void 0)throw new Error(`Schema 'schemas/${A}' is empty and will be ignored.`);let ne=JSON.parse(U);if(ne.$schema&&ne.$schema!=="https://json-schema.org/draft/2020-12/schema")throw new Error(`Error in ${A}: All JSON schemas must use version 2020-12. See release notes for changes: https://json-schema.org/draft/2020-12/release-notes.html`);if(l.$dataMetaSchema,l.addSchema(ne,A),l.errors?.length){let se=l.errors[0];b.push({id:"json-schema-validation-error",pluginName:dk,text:`Error: ${se.message}`,location:{file:q2.join(uH,A)},detail:{params:se.params,propertyName:se.propertyName,schemaPath:se.schemaPath,data:se.data}})}}catch(M){if(M.message.endsWith("is empty and will be ignored.")){D.push({id:"empty-json-schema-file",pluginName:dk,text:`Schema 'schemas/${A}' is empty and will be ignored.`,location:{file:`schemas/${A}`,suggestion:"Add schema details or remove the file from the project."},detail:"EmptyJSONSchemaFile",notes:[{text:`Schema 'schemas/${A}' is empty and will be ignored.`,location:{file:`schemas/${A}`,suggestion:"Add schema details or remove the file from the project."}}]});return}let U=await k8e(A,a.sourceDirectory,M.message);b.push({id:"json-schema-add-error",pluginName:dk,text:`Error: ${M.message}`,location:U,detail:"InvalidAddSchemaError",notes:[{text:M.message}]})}})),await Promise.all(m.map(async A=>{try{let M=l.getSchema(A);M&&l.compile(M.schema).errors?.forEach(ne=>{b.push({text:`Failed to compile ${A}: ${ne.message}`})})}catch(M){let U=await k8e(A,a.sourceDirectory,M.message);b.push({id:"json-schema-compile-error",pluginName:dk,text:`The schema file '${A}' is not valid. Error: ${M.message}`,location:U,detail:"InvalidSchemaError",notes:[{text:M.message}]})}})),Ym.DEBUG_BUILD_MODE)){let A=q2.resolve(a.outputDirectory,uH);await yl.mkdirIfNotExists(A)}s.onStart(async()=>{if(m)return{errors:b,warnings:D}}),s.onResolve({filter:/schemas\/.*\.json$/},async A=>{let M=q2.isAbsolute(A.path)?A.path:q2.join(A.resolveDir,A.path);if(A.importer&&A.importer!==q2.join(a.sourceDirectory,"config/routes.json"))return{path:M};if(!await yl.fileExists(M)){let U="policies.json";return{errors:[{id:"json-schema-build-error",text:`Unable to resolve reference to '${A.path}' from ${U}`,location:{file:q2.join(A.resolveDir,U),namespace:Jfe,line:1,column:0,length:0,lineText:`Invalid JSON schema reference in ${U}`,suggestion:""},detail:"RouteReferenceError",pluginName:dk,notes:[{text:`Unable to resolve reference to '${A.path}' from ${U}`,location:null}]}],namespace:Jfe,path:M,pluginName:dk}}return{path:M,namespace:Jfe,pluginName:dk}}),s.onLoad({filter:/.*/,namespace:Jfe},async A=>hf.timeFn(`Generating json schema data: ${q2.basename(A.path)}`,async()=>{let M=[],U;try{let ne=q2.relative(_,A.path),se=l.getSchema(ne);if(!se)throw new Error(`Could not load schema at ${A.path}`);U=se.source?.validateCode;let Z=l.compile(se.schema);U=(0,Dyt.default)(l,Z)}catch(ne){M.push({pluginName:dk,text:`Cannot parse project's schemas/${q2.basename(A.path)} file. Error: ${ne.message}`,location:null,notes:[{text:ne.message,location:null}],detail:ne})}if(Ym.DEBUG_BUILD_MODE&&U){let ne=q2.relative(_,A.path),se=q2.join(a.sourceDirectory,".zuplo",`${ne}.js`);await ok(se,U)}return{contents:U,errors:M,pluginName:dk,resolveDir:q2.dirname(A.path),watchFiles:[A.path]}}))}}}t(kyt,"jsonSchemaPlugin");import{relative as bSr}from"path";var wyt=["node:assert","node:async_hooks","node:buffer","node:crypto","node:diagnostics_channel","node:events","node:path","node:process","node:stream","node:string_decoder","node:util"],SSr="nodejs-compat-plugin";function Pyt({sourceDirectory:a}){return{name:SSr,setup(s){let l=new Set;s.onStart(()=>{l.clear()}),s.onResolve({filter:/node:.*/},async({path:_,kind:m,resolveDir:b,...D})=>{let A=`${_}:${m}:${b}:${D.importer}`;if(l.has(A))return;l.add(A);let M=await s.resolve(_,{kind:m,resolveDir:b,importer:D.importer});return M.errors.length>0?wyt.includes(_)||_.includes("/")&&wyt.includes(_.split("/")[0])?{external:!0}:{external:!0,warnings:M.errors.map(ne=>({...ne,location:{file:bSr(a,D.importer),line:0,column:0,namespace:"",length:0,lineText:"",suggestion:"Remove the imported node module"},detail:`The package "${_}" wasn't found on the file system but is built into node. If this code is executed it will fail.`}))}:M})}}}t(Pyt,"nodejsCompatPlugin");import Ayt from"fs/promises";import eE from"path";var Dj="open-api-routes-plugin",zfe="open-api-routes-json";function Nyt(a){return{name:"open-api-routes-plugin",setup(s){s.onResolve({filter:/routes.json$/},l=>({watchFiles:[...GFe(eE.join(a.sourceDirectory,Ny),[".oas.json"],!0),eE.join(a.sourceDirectory,Ny,vce)],namespace:zfe,path:eE.isAbsolute(l.path)?l.path:eE.join(l.resolveDir,l.path),pluginName:Dj})),s.onResolve({filter:/^\.\.\/modules\/.*/,namespace:zfe},async l=>{let _=eE.join(l.resolveDir,`${l.path}.ts`);if(!await yl.fileExists(_)){let m=`$import(.${l.path.replace(/^../,"")})`,b=eE.resolve(a.sourceDirectory,"config"),D=await EO(b),A=await Tot(D,m,"Update your route configuration to use code from the 'modules' folder");return{errors:[{id:"route-build-error",text:`Invalid handler reference in routes.json. Unable to resolve reference to '${m}' from routes.json`,location:A,detail:"RouteReferenceError",pluginName:Dj}],namespace:zfe,path:l.path,pluginName:Dj}}}),s.onLoad({filter:/.*/,namespace:zfe},async l=>hf.timeFn("Generating route.json data",async()=>{let _=eE.resolve(a.sourceDirectory,"config"),m=await EO(_),b=await Promise.all(m.map(async U=>({content:await Ayt.readFile(U,"utf-8"),fileName:U}))),D=eE.resolve(_,"policies.json");if(!await yl.fileExists(D))return{errors:[{text:"The project must include a policies file ('/config/policies.json')",detail:"OASPoliciesFileMissing",pluginName:Dj,location:{line:0,column:0,file:"/config/policies.json"}}],pluginName:Dj};let A={content:await Ayt.readFile(D,"utf-8"),fileName:D},M;try{M=await x8e({sourceDirectory:a.sourceDirectory,oasContent:b,policiesContent:A})}catch(U){throw new Error("Error compiling routes: "+U.message)}if(Ym.DEBUG_BUILD_MODE&&M.content){let U=eE.join(a.sourceDirectory,".zuplo"),ne=eE.resolve(U,"routes.js");await ok(ne,M.content)}return{contents:M.content,errors:M.errors,pluginName:Dj,resolveDir:eE.dirname(l.path),watchFiles:[l.path]}}))}}}t(Nyt,"openApiRoutesPlugin");import qfe from"path";var KFe="raw-route-plugin",Iyt="raw-route";function Oyt(a){return{name:"raw-route-plugin",setup(s){s.onResolve({filter:/raw.json$/},l=>({namespace:Iyt,path:l.path,pluginName:KFe})),s.onLoad({filter:/.*/,namespace:Iyt},async l=>{let _=qfe.resolve(a.sourceDirectory,Ny);if(!await yl.dirExists(_))return{loader:"js",resolveDir:qfe.dirname(l.path),pluginName:KFe};let m=await EO(_),b=await D8e({oasFiles:m,sourceDirectory:a.sourceDirectory,logger:a.logger});if(Ym.DEBUG_BUILD_MODE&&b){let D=qfe.join(a.sourceDirectory,".zuplo","raw-routes.js");await ok(D,b)}return{contents:b,loader:"js",resolveDir:qfe.dirname(l.path),pluginName:KFe}})}}}t(Oyt,"rawRoutePlugin");import TSr from"fs/promises";import YFe from"path";var Vfe="runtime-config",Fyt="runtime-config-plugin";function Lyt(){return{name:Vfe,setup(a){a.onResolve({filter:/^\.\.\/modules\/zuplo.runtime.ts$/},s=>({namespace:Fyt,path:YFe.isAbsolute(s.path)?s.path:YFe.join(s.resolveDir,s.path),pluginName:Vfe})),a.onLoad({filter:/.*/,namespace:Fyt},async s=>hf.timeFn("Generating zuplo.runtime.ts data",async()=>{let l="export const runtimeInit = undefined;",_=[];return await yl.fileExists(s.path)?(l=await TSr.readFile(s.path,"utf-8"),{contents:l,loader:"ts",resolveDir:YFe.dirname(s.path),errors:_,pluginName:Vfe,watchFiles:[s.path]}):{contents:l,loader:"ts",errors:_,pluginName:Vfe}}))}}}t(Lyt,"runtimeConfigPlugin");var Myt=S_(WFe(),1),jyt=S_(HFe(),1);import ZFe from"fs/promises";import uF from"path";var XFe="schema-validation-plugin",Ryt="schema-validation",xSr="module.exports = {}";function Byt(a){return{name:"schema-validation-plugin",setup(s){s.onResolve({filter:/ajv-schema.json$/},l=>({namespace:Ryt,path:l.path,pluginName:XFe})),s.onLoad({filter:/.*/,namespace:Ryt},async l=>{let _=uF.resolve(a.sourceDirectory,Ny,"policies.json");if(!await yl.fileExists(_))return{contents:xSr,loader:"js",resolveDir:uF.dirname(l.path),pluginName:XFe};let m=await ESr(a.sourceDirectory),b=uF.resolve(a.sourceDirectory,Ny),D=await EO(b),A=await PSr(D,m),M=await CSr({oasFiles:D,routesWithSchemaValidation:A,sourceDirectory:a.sourceDirectory,logger:a.logger});if(Ym.DEBUG_BUILD_MODE&&M){let U=uF.join(a.sourceDirectory,".zuplo","schema-validation.js");await ok(U,M)}return{contents:M,loader:"js",resolveDir:uF.dirname(l.path),pluginName:XFe}})}}}t(Byt,"schemaValidationPlugin");async function CSr({oasFiles:a,routesWithSchemaValidation:s,sourceDirectory:l,logger:_}){let m="",b=new p3(l,_);if(s.length===0)return m;let D=new Myt.Ajv2020({code:{source:!0},allErrors:!0,strict:!1,verbose:!0,meta:!0});for(let A of a){let M=await ZFe.readFile(A,"utf-8"),U=uF.basename(A,".oas.json"),ne=s.filter(ke=>ke.fileName===U),se=await b.resolve(A),Z=JSON.parse(M),Re=[],Ae=new Map;ne.forEach(ke=>{let Ot=Z.paths[ke.path][ke.method];if(Ot.requestBody){let kt;if(Ot.requestBody.$ref){let br=Ot.requestBody.$ref;kt=se.get(br)?.content}else Ot.requestBody.content&&(kt=Ot.requestBody.content);if(kt)for(let br in kt){let Kr=kt[br].schema,on=a3e(ke.path,ke.method,br);Kr.$id=on,D.addSchema(Kr),QFe(Kr,A,U,D,se,Re,Ae)}}if(Ot.parameters)for(let kt of Ot.parameters){let br=kt.$ref?se.get(kt.$ref):kt,Kr=br.schema.$ref?se.get(br.schema.$ref):br.schema,on=s3e(ke.path,ke.method,br.in,br.name);Kr.$id=on,D.addSchema(Kr),QFe(br,A,U,D,se,Re,Ae)}});for(let ke of Re){let Ot=se.get(ke),kt=tG(U,ke);D.addSchema(Ot,kt)}}return m=(0,jyt.default)(D),m}t(CSr,"schemaValidationSource");function QFe(a,s,l,_,m,b,D){for(let A in a){let M=a[A];if(A==="$ref"){let U=tG(l,i3(s,M));a[A]=U,RH(s,l,i3(s,M),m,b,D,(ne,se)=>tG(ne,i3(s,se)))}else typeof M=="object"&&QFe(M,s,l,_,m,b,D)}}t(QFe,"addRefsToSchema");async function ESr(a){let s=new Set(["RequestValidationInboundPolicy"]),l=await ZFe.readFile(`${a}/config/policies.json`,"utf-8"),_=JSON.parse(l);return DSr(_,s)}t(ESr,"getPolicyNamesUsingSchemaValidationPolicies");function DSr(a,s){let l=new Set;a.policies?.forEach(m=>{m.handler?.export&&s.has(m.handler.export)&&m.handler.module==="$import(@zuplo/runtime)"&&l.add(m.name)});let _=kSr(a,l);return new Set([...l,..._])}t(DSr,"getPolicyNamesReferencingPolicyHandlers");function kSr(a,s){let l=new Set;return a.policies?.forEach(_=>{_.handler?.export==="CompositeInboundPolicy"&&_.handler?.options?.policies?.forEach(m=>{s.has(m)&&l.add(_.name)})}),l}t(kSr,"getCompositePoliciesContainingPolicy");function wSr(a,s){if(!a["x-zuplo-route"]||!a["x-zuplo-route"].policies)return!1;let l=a["x-zuplo-route"].policies.inbound;if(l){for(let m of l)if(s.has(m))return!0}let _=a["x-zuplo-route"].policies.outbound;if(_){for(let m of _)if(s.has(m))return!0}return!1}t(wSr,"isPolicyPresentInOperation");async function PSr(a,s){let l=[];for(let _ of a){let m=await ZFe.readFile(_,"utf-8"),D=JSON.parse(m).paths;for(let A in D){let M=D[A];for(let U in M){let ne=M[U];wSr(ne,s)&&l.push({fileName:uF.basename(_,".oas.json"),path:A,method:U})}}}return l}t(PSr,"getRoutesContainingPolicies");import{mkdirSync as ASr,writeFileSync as NSr}from"fs";import ISr from"path";import Uyt from"path";function kj(a,s){let l=Uyt.relative(process.cwd(),Uyt.join(a,bO));return Object.keys(s?.outputs??{}).map(m=>`.${m.replace(l,"")}`)}t(kj,"getBuildModules");function $yt(a){return{name:"write-modules-plugin",setup(s){s.onEnd(async l=>{if(l){let _=kj(a.sourceDirectory,l.metafile);ASr(a.outputDirectory,{recursive:!0}),NSr(ISr.join(a.outputDirectory,"modules.json"),JSON.stringify(_,null,2))}})}}}t($yt,"writeModulesPlugin");var OSr=sht("zuplo:core:build"),FSr=["workerd","worker","browser"],qyt=[...process.env.GLOBAL_MODULE_LOCATION?[process.env.GLOBAL_MODULE_LOCATION]:[],e7e.resolve(Jyt(zyt(import.meta.url)),"..","..","..","node_modules"),e7e.resolve(Jyt(zyt(import.meta.url)),"..","..","..","..","..","node_modules")];async function OK({systemDirectory:a,outputDirectory:s,sourceDirectory:l,cacheDirectory:_,logger:m,minify:b=!0,command:D,flags:A}){let M=e7e.join(a,Tce);OSr(`Building with node paths: ${qyt.join(", ")}`);let U=b&&D!=="dev"&&!process.env.DEBUG_BUILD_DISABLE_MINIFY?{minify:!0,chunkNames:"[hash]"}:{minify:!1,keepNames:!0,chunkNames:"[name]-[hash]"},ne={sourceDirectory:l,outputDirectory:s,cacheDirectory:_,logger:m,debugMode:Ym.DEBUG_BUILD_MODE,flags:A};return{platform:"browser",target:"es2022",outdir:s,splitting:!0,metafile:!0,format:"esm",nodePaths:qyt,entryPoints:[M],sourcemap:"linked",legalComments:"none",treeShaking:!0,bundle:!0,...U,external:[],logLevel:"silent",conditions:FSr,plugins:[_ht(ne),aht(ne),Nyt(ne),Oyt(ne),Byt(ne),Lyt(),cht(ne),kyt(ne),Pyt(ne),$yt(ne)]}}t(OK,"getBaseESBuildConfig");var fF="run-esbuild",Wyt=t(async function({systemDirectory:a,outputDirectory:s,sourceDirectory:l,cacheDirectory:_,buildId:m,logger:b,config:D,command:A,minify:M},U){return hf.timeFn("Running esbuild",async()=>{b.info(`Running build_id: ${m}`);let ne=await OK({command:A,minify:M,systemDirectory:a,outputDirectory:s,cacheDirectory:_,sourceDirectory:l,logger:b,flags:D.flags}),se;try{if(!await lM(l))throw new Error("Failed to build project because no open-api file was found on the 'config' folder");se=await Vyt.build(ne),U.set("metafile",se.metafile)}catch(Ae){if(b.error(Ae),Ae.errors||Ae.warnings)se=Ae;else if(Ae.message.includes("Failed to build project because no open-api file was found on the 'config' folder"))se={warnings:[],errors:[{id:"missing-open-api-file",text:"Failed to build project because no open-api file was found on the 'config' folder",pluginName:fF,location:null,notes:[],detail:"Failed to build project because no open-api file was found on the 'config' folder"}],outputFiles:void 0,metafile:void 0,mangleCache:void 0};else throw Ae}se.errors.length>0&&se.errors.length>1&&(se.errors.length=1);let{errors:Z,warnings:Re}=t7e({buildId:m,result:se});return{errors:Z,warnings:Re}})},"runEsbuild");function t7e({buildId:a,result:s}){return{status:s.errors.length>0?"Failed":s.warnings.length>0?"Warnings":"Good",runtimeVersion:"0.0.0",buildTime:"",buildTimeMs:0,buildId:a,warnings:s.warnings.map(_=>_.text==="Using direct eval with a bundler is not recommended and may cause problems"?{location:_.location,detail:_.detail,id:_.id,notes:_.notes,message:"We do not support the use of 'eval' or 'new Function(...)'",severity:mce,pluginName:_.pluginName||fF}:{location:_.location,detail:_.detail,id:_.id,notes:_.notes,message:_.text,severity:mce,pluginName:_.pluginName||fF}),errors:s.errors.map(_=>({location:_.location,detail:_.detail,id:_.id,notes:_.notes,message:_.text,severity:GAe,pluginName:_.pluginName||fF})),metafile:s.metafile}}t(t7e,"esbuildResultToBuildResult");var LSr=t((a,s)=>{let l=s;if(s.includes(a)){let _=new RegExp(`.*(${a})`,"g");l=s.replace(_,"")}return l.match(/^(\/)?(\.\.(\/)?)+/)&&(l=l.replace(/^(\/)?(\.\.(\/)?)+/,"/")),l},"removePrefixFromString"),RSr=t((a,s)=>{let l=s;if(l.includes(a)){let _=new RegExp(`[a-zA-Z0-9-_.\\/]+(${a})`,"g");l=l.replace(_,"")}return l},"cleanFilePathsInMessage"),Hyt=t((a,s,l)=>{if(!a||a.length<=0)return a;let _=a.filter(m=>m.message!=='Could not resolve "@zuplo/runtime"');return _&&_.length>0&&_.forEach(m=>{try{m.location&&m.location.file&&(m.location.file=LSr(s,m.location.file)),m.location&&m.location.lineText&&m.location.lineText.includes("@zuplo/core/index.minified.js")&&(m.location.lineText=m.location.lineText.substring(0,200)+"...<Truncated>"),m.message=RSr(s,m.message),m.notes&&m.notes.length>0&&delete m.notes,m.text&&delete m.text,m.pluginName===""&&(m.pluginName=l)}catch{}}),_},"cleanDataOnBuildIssue");function Gyt(a,s){let l=r7e.basename(s);a.errors&&(a.errors=Hyt(a.errors,l,fF)),a.warnings&&(a.warnings=Hyt(a.warnings,l,fF))}t(Gyt,"formatBuildResult");var MSr=t(a=>r7e.basename(a).startsWith("."),"isHiddenOnUnix"),jSr=t((a,s=[])=>s.map(l=>l.startsWith(".")?l:`.${l}`).some(l=>a.endsWith(l)),"hasMatchingExtname");function GFe(a,s=[],l=!1){let _=[],m;if(!Wfe.existsSync(a)){let b;if(IH.hasMagic(a))b=a;else{let D=s.map(A=>A.startsWith(".")?A:`.${A}`).join("|");b=`${a}+(${D})`}if(_.push(...IH.sync(b,{nodir:!0})),!_.length)throw Error(`Cannot find any files matching pattern "${a}"`);return _}try{if(m=Wfe.statSync(a),m.isFile())return[a]}catch{return[]}return Wfe.readdirSync(a).forEach(b=>{let D=r7e.join(a,b),A;try{if(A=Wfe.statSync(D),A.isDirectory()){l&&_.push(...GFe(D,s,l));return}}catch{return}if(!s.length)throw Error(`Argument '${s}' required when argument '${a}' is a directory`);!A.isFile()||!jSr(D,s)||MSr(D)||_.push(D)}),_}t(GFe,"lookupFiles");var tE=new kce({level:process.env.FORCE_BUILD_COLORS?2:void 0}),_F=` ${tE.gray("|")} `;function vUr(a,s){a.info(tE.green(s))}t(vUr,"outputSuccess");function bUr(a,s){a.warn(tE.yellow(s))}t(bUr,"outputWarning");function SUr(a,s){a.error(tE.red(s))}t(SUr,"outputCritical");function TUr(a,s,l){let _=l.sort((A,M)=>{let U=A.path.split("/").length,ne=M.path.split("/").length;return U!==ne?U-ne:A.path.localeCompare(M.path)}),m=Math.max(..._.map(A=>A.path.length)),b=_.reduce((A,M)=>{let U=M.path.includes("/")?M.path.split("/")[0]:"/";return A[U]||(A[U]=[]),A[U].push(M),A},{}),D=`${s}
593
+ `;Object.keys(b).forEach(A=>{D+=A==="/"?`/
594
+ `:`${A}/
595
+ `,b[A].forEach(M=>{let U=" ".repeat(m-M.path.length),ne=M.bytes/1024,se=` ${M.path}${U} ${ne.toFixed(2)} KB
596
+ `;D+=ne>1024?tE.red(se):ne>300?tE.yellow(se):se}),D+=`
597
+ `}),a.info(D)}t(TUr,"outputFileTree");function xUr(a,s){if(s.length===0)return"";let l=Object.keys(s[0]).length,_=Array.from({length:l},(D,A)=>Math.max(...s.map(M=>String(Object.values(M)[A]).length))),b=s.map(D=>Object.values(D).map((A,M)=>String(A).padEnd(_[M])).join(" ")).join(`
597
598
  `);a.info(b)}t(xUr,"outputTable");function n7e({output:a,buildId:s,runtimeVersion:l,compatibilityDate:_}){let m=["Building Zuplo API...",`${_F}Build ID: ${s}`,`${_F}Runtime Version: ${l}`];_&&m.push(`${_F}Compatibility Date: ${_}`),a.info(m.join(`
598
599
  `))}t(n7e,"outputBuildStart");async function Hfe(a,s,l){Gyt(l,a),await Promise.all(l.warnings.map(_=>Kyt(a,s,_))),await Promise.all(l.errors.map(_=>Kyt(a,s,_))),l.status==="Good"?s.info(tE.green("Build succeeded"),{status:"success"}):l.status==="Warnings"?s.warn(tE.yellow("Build succeeded with warnings"),{status:"success"}):l.status==="Failed"&&s.error(tE.red("Failed to build API"),{status:"failed"})}t(Hfe,"outputBuildResult");async function Kyt(a,s,l){let _=[],m=l.severity==="error"?tE.red:tE.yellow,b=m(`${l.severity.toUpperCase()}: ${l.message}${l.detail?`
599
- ${_F}${l.detail.split(`
600
+ ${_F}${l.detail.toString().split(`
600
601
  `).join(`
601
602
  ${_F}`)}`:""}`);_.push(b);let D=$Sr(l.location??void 0);if(D&&_.push(`${_F}${m(`The error was found in the file: ${D}`)}`),l.location&&l.location.column!==0&&l.location.line!==0){let A=USr.join(a,l.location.file),M=await BSr(A,"utf-8"),U=(0,Yyt.codeFrameColumns)(M,{start:{line:l.location.line,column:l.location.column}},{highlightCode:!0,message:l.message,linesAbove:3,linesBelow:3});_.push(_F),_.push(U)}_.push(""),l.severity==="warning"?s.warn(_.join(`
602
603
  `)):s.error(_.join(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuplo/core",
3
- "version": "6.18.16",
3
+ "version": "6.18.18",
4
4
  "repository": "https://github.com/zuplo/zuplo",
5
5
  "author": "Zuplo, Inc.",
6
6
  "type": "module",
@@ -40,8 +40,8 @@
40
40
  "prettier": "^3.3.3"
41
41
  },
42
42
  "peerDependencies": {
43
- "@zuplo/graphql": "^6.18.16",
44
- "@zuplo/otel": "^6.18.16",
45
- "@zuplo/runtime": "^6.18.16"
43
+ "@zuplo/graphql": "^6.18.18",
44
+ "@zuplo/otel": "^6.18.18",
45
+ "@zuplo/runtime": "^6.18.18"
46
46
  }
47
47
  }