@zuplo/core 6.63.11 → 6.63.13

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.
@@ -602,7 +602,7 @@ globstar while`,s,ae,f,Ke,$e),this.matchOne(s.slice(ae),f.slice(Ke),d))return th
602
602
  `,this.indentLevel=f.startingIndentLevel!=null?f.startingIndentLevel:0,this.writeComments=f.comments?f.comments:!1,f.sourceMap!=null&&(this.write=f.output==null?this.writeAndMap:this.writeToStreamAndMap,this.sourceMap=f.sourceMap,this.line=1,this.column=0,this.lineEndSize=this.lineEnd.split(`
603
603
  `).length-1,this.mapping={original:null,generated:this,name:void 0,source:f.sourceMap.file||f.sourceMap._file})}write(s){this.output+=s}writeToStream(s){this.output.write(s)}writeAndMap(s,f){this.output+=s,this.map(s,f)}writeToStreamAndMap(s,f){this.output.write(s),this.map(s,f)}map(s,f){if(f!=null){let{type:x}=f;if(x[0]==="L"&&x[2]==="n"){this.column=0,this.line++;return}if(f.loc!=null){let{mapping:P}=this;P.original=f.loc.start,P.name=f.name,this.sourceMap.addMapping(P)}if(x[0]==="T"&&x[8]==="E"||x[0]==="L"&&x[1]==="i"&&typeof f.value=="string"){let{length:P}=s,{column:F,line:J}=this;for(let G=0;G<P;G++)s[G]===`
604
604
  `?(F=0,J++):F++;this.column=F,this.line=J;return}}let{length:d}=s,{lineEnd:y}=this;d>0&&(this.lineEndSize>0&&(y.length===1?s[d-1]===y:s.endsWith(y))?(this.line+=this.lineEndSize,this.column=0):this.column+=d)}toString(){return this.output}};function Xft(o,s){let f=new j4e(s);return f.generator[o.type](o,f),f.output}t(Xft,"generate");async function B4e({oasFiles:o,sourceDirectory:s,logger:f}){let d=await mpr({oasFiles:o,sourceDirectory:s,logger:f});return Xft(d)}t(B4e,"generateRawRouteSource");async function mpr({oasFiles:o,sourceDirectory:s,logger:f}){let d=new rI(s,f),y=[];for(let P of o){let F=dpr.basename(P,".oas.json"),J=await d.resolve(P),G=[],Se=new Map,de=await ppr.readFile(P,"utf-8"),ae=JSON.parse(de);for(let Ke in ae.paths){let $e=ae.paths[Ke],Fe=$e.parameters||[],Gt={};$e.summary&&(Gt.pathSummary=$e.summary),$e.description&&(Gt.pathDescription=$e.description),$e.servers&&(Gt.pathServers=$e.servers);for(let jt in $e){if(!Vle(jt))continue;let Pr=$e[jt],Fn=[...Fe,...Pr.parameters||[]],sn={...Pr,...Fn.length>0&&{parameters:Fn},...Gt,...Pr.description&&{description:Pr.description.length>350?`${Pr.description.substring(0,350).trim()}...`:Pr.description}},Un=sH(F,Ke,jt),Er=Kle(P,F,sn,J,G,Se);y.unshift(Qft(Un,Er))}}y.unshift(...hpr(F,J,G,Se).reverse())}return{type:"Program",body:y,sourceType:"module"}}t(mpr,"generateAst");function Kle(o,s,f,d,y,x){let P=[];for(let F in f){let J=f[F];if(F==="$ref")return BV(o,s,GN(o,J),d,y,x),{type:"Identifier",name:e_t(s,x.get(GN(o,J)))};let G;switch(typeof J){case"string":case"number":case"boolean":G={type:"Literal",value:J};break;default:Array.isArray(J)?G=Zft(J,o,s,d,y,x):typeof J=="object"&&J!==null&&(G=Kle(o,s,J,d,y,x));break}if(G){let Se=/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(F),de=Se?{type:"Identifier",name:F}:{type:"Literal",value:F};P.push({type:"Property",key:de,value:G,kind:"init",method:!1,shorthand:!1,computed:!Se})}}return{type:"ObjectExpression",properties:P}}t(Kle,"processNode");function Zft(o,s,f,d,y,x){return{type:"ArrayExpression",elements:o.map(P=>{if(Array.isArray(P))return Zft(P,s,f,d,y,x);if(typeof P=="object"&&P!==null){let F=Kle(s,f,P,d,y,x);return F.type==="Identifier"?F:{type:"ObjectExpression",properties:F.properties||[]}}else return{type:"Literal",value:P}})}}t(Zft,"processArray");function Qft(o,s){return{type:"ExportNamedDeclaration",declaration:{type:"VariableDeclaration",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:o},init:s}],kind:"var"},specifiers:[],source:null}}t(Qft,"createExportedConstAssignment");function hpr(o,s,f,d){let y=[];for(let x=0;x<f.length;x++){let P=e_t(o,x),F=s.get(f[x]),J=Kle(Woe(f[x]),o,F,s,f,d);y.push(Qft(P,J))}return y}t(hpr,"generateRefs");function e_t(o,s){return`${qP(o)}__ref__${s}`}t(e_t,"getRefIdentifierName");import t_t from"node:path";var r_t=t(o=>{let s=null;if(o.value.type==="Object"&&o.value.members.length>0)for(let f of o.value.members){let d=r_t(f);if(d!==null&&(s=d),f.name.value==="enum"&&f.value.type==="Array"&&f.value.elements.length===0){let y=f.value,x=y.loc.start.line,P=y.loc.start.column,F=y.loc.end.column;s={line:x,column:P,length:F-P,lineText:""}}}return s},"findEmptyEnums"),gpr=t(o=>{if(o.startsWith("schema with key or id")&&o.endsWith("already exists"))return"Update your schema's '$id' to be unique across your project.";if(o.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(o==='"nullable" cannot be used without "type"')return'Property "nullable" can only be used when property "type" value is "object".';if(o==='NOT SUPPORTED: keyword "id", use "$id" for schema ID')return'Replace keyword "id" with "$id" when defining a schema Id.';if(o.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(o.startsWith("can't resolve reference"))return"Make sure all references are defined in the schema.";if(o.includes("oneOf must NOT have fewer than 1 items"))return'Property "oneOf" must have at least 1 item configured.';if(o.includes("enum must have non-empty array"))return'Property "enum" must be configured with at least one value.';if(o.includes("Unexpected")&&o.includes("in JSON at position"))return"Update your schema to only use valid properties."},"getSuggestions"),U4e=t(async(o,s,f)=>{if(!o)return null;let d={file:t_t.join(aAe,o),suggestion:gpr(f)},y=t_t.join(s,aAe),x=tu.safePath(s).resolve(y,o),P=await $oe(x);if(f.includes("enum must have non-empty array")){if(P){let F=await jV(P);if(F&&F.body.members!==null)for(let J of F.body.members){let G=r_t(J);G&&G!==null&&(d=Object.assign(d??{},G))}if(d){let J=d.line?d.line:0;d.lineText=MV(P,J)}}}else if(f.includes("Unexpected")&&f.includes("in JSON at position")&&P){let F=await jV(P);F&&"lineText"in F&&(d=Object.assign(d??{},F))}return d},"getLocation");import*as Y_t from"esbuild";import t3e,{dirname as V_t}from"node:path";import{fileURLToPath as H_t}from"node:url";var z4e=class{static{t(this,"Environment")}get DEV_SERVER_PORT(){return process.env.DEV_SERVER_PORT?parseInt(process.env.DEV_SERVER_PORT,10):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"}},ypr=new z4e,Gm=ypr;var $4e="no-remote-module";function n_t({logger:o}){return{name:$4e,async setup(s){s.onResolve({filter:/^https?:\/\//},f=>(o.error(f,"User attempted to load a remote module"),{errors:[{text:`Remote modules are not supported. Attempted to load module ${f.path}`,detail:"InvalidRemoteModule",pluginName:$4e,location:{line:0,column:0,file:""}}],pluginName:$4e}))}}}t(n_t,"blockRemoteModulePlugin");import i_t from"node:path";var s_t="legacy-environment",a_t="legacy-environment",vpr=`import { environment } from "@zuplo/runtime";
605
- export default environment;`;function o_t(o){return{name:"environment",setup(s){s.onResolve({filter:/@app\/environment$/},()=>({namespace:a_t,pluginName:s_t,path:i_t.join(o.sourceDirectory,Ng,"environment.js")})),s.onLoad({filter:/.*/,namespace:a_t},async f=>({contents:vpr,loader:"ts",resolveDir:i_t.dirname(f.path),pluginName:s_t}))}}}t(o_t,"environmentPlugin");import zpr from"node:fs/promises";import bT from"node:path";var x_t=Sd(Lle(),1),E_t=Sd(b_t(),1),C_t=Sd(Mle(),1),k_t=Sd(K4e(),1);import{performance as jE}from"node:perf_hooks";var iG=[];async function jpr(o,s){let f=jE.now();try{return await s()}finally{let d=jE.now()-f;iG.push({name:o,duration:d})}}t(jpr,"timeFn");var Bpr={mark:t(o=>{jE.mark(o)},"mark"),measure:t((o,s,f)=>{try{jE.measure(o,s,f)}finally{jE.clearMarks(s),jE.clearMarks(f),jE.clearMeasures(o)}},"measure"),timeFn:jpr,report:t(()=>{if(iG.length>0){let o=iG.reduce((s,{name:f,duration:d})=>(s[f]=`${d.toFixed(0)}ms`,s),{});console.table(o),iG.length=0}},"report"),getDuration:t(o=>{let s=jE.getEntriesByName(o);if(s.length===0)return 0;let f=s[0].duration;return jE.clearMeasures(o),f},"getDuration"),clear:t(()=>{iG.length=0,jE.clearMarks(),jE.clearMeasures()},"clear")},Ou=Bpr;import{writeFile as Upr}from"node:fs/promises";async function qk(o,s){await tu.mkdirForFilePathIfNotExits(o);let f=await import("prettier"),d=s;try{d=await f.format(s,{parser:"babel"})}catch{}await Upr(o,d,"utf-8")}t(qk,"writeDebugSourceFile");var Vk="schemas",Zle="json-schema";function w_t(o){return{name:Vk,async setup(s){let f=new C_t.Ajv2020({code:{source:!0},allErrors:!0,strict:!1,verbose:!0,meta:!0}),d=bT.join(o.sourceDirectory,mV),y=[],x=[],P;await Ou.timeFn("Initializing schema validation",async()=>{if((0,E_t.default)(f,{mode:"fast"}),f.opts.code.formats=x_t._`require("ajv-formats/dist/formats").fastFormats`,await tu.dirExists(d)&&(f.addKeyword("faker"),P=(await tu.listFolderContents(d,mV)).sort(),await Promise.all(P.map(async F=>{try{let J=tu.safePath(o.sourceDirectory).resolve(d,F);if(!J.startsWith(d))throw new Error("All schemas must be in the schemas directory");let G=await zpr.readFile(J,"utf-8");if(G===""||G===void 0)throw new Error(`Schema 'schemas/${F}' is empty and will be ignored.`);let Se=JSON.parse(G);if(Se.$schema&&Se.$schema!=="https://json-schema.org/draft/2020-12/schema")throw new Error(`Error in ${F}: All JSON schemas must use version 2020-12. See release notes for changes: https://json-schema.org/draft/2020-12/release-notes.html`);if(f.addSchema(Se,F),f.errors?.length){let de=f.errors[0];y.push({id:"json-schema-validation-error",pluginName:Vk,text:`Error: ${de.message}`,location:{file:bT.join(mV,F)},detail:{params:de.params,propertyName:de.propertyName,schemaPath:de.schemaPath,data:de.data}})}}catch(J){if(J.message.endsWith("is empty and will be ignored.")){x.push({id:"empty-json-schema-file",pluginName:Vk,text:`Schema 'schemas/${F}' is empty and will be ignored.`,location:{file:`schemas/${F}`,suggestion:"Add schema details or remove the file from the project."},detail:"EmptyJSONSchemaFile",notes:[{text:`Schema 'schemas/${F}' is empty and will be ignored.`,location:{file:`schemas/${F}`,suggestion:"Add schema details or remove the file from the project."}}]});return}let G=await U4e(F,o.sourceDirectory,J.message);y.push({id:"json-schema-add-error",pluginName:Vk,text:`Error: ${J.message}`,location:G,detail:"InvalidAddSchemaError",notes:[{text:J.message}]})}})),await Promise.all(P.map(async F=>{try{let J=f.getSchema(F);J&&f.compile(J.schema).errors?.forEach(Se=>{y.push({text:`Failed to compile ${F}: ${Se.message}`})})}catch(J){let G=await U4e(F,o.sourceDirectory,J.message);y.push({id:"json-schema-compile-error",pluginName:Vk,text:`The schema file '${F}' is not valid. Error: ${J.message}`,location:G,detail:"InvalidSchemaError",notes:[{text:J.message}]})}})),Gm.DEBUG_BUILD_MODE)){let F=bT.resolve(o.outputDirectory,mV);await tu.mkdirIfNotExists(F)}}),s.onStart(async()=>{if(P)return{errors:y,warnings:x}}),s.onResolve({filter:/schemas\/.*\.json$/},async F=>Ou.timeFn("Generating JSON schemas...",async()=>{let J=bT.isAbsolute(F.path)?F.path:bT.join(F.resolveDir,F.path);if(F.importer&&F.namespace!=="open-api-routes-json")return{path:J};if(!await tu.fileExists(J)){let G="policies.json";return{errors:[{id:"json-schema-build-error",text:`Unable to resolve reference to '${F.path}' from ${G}`,location:{file:bT.join(F.resolveDir,G),namespace:Zle,line:1,column:0,length:0,lineText:`Invalid JSON schema reference in ${G}`,suggestion:""},detail:"RouteReferenceError",pluginName:Vk,notes:[{text:`Unable to resolve reference to '${F.path}' from ${G}`,location:null}]}],namespace:Zle,path:J,pluginName:Vk}}return{path:J,namespace:Zle,pluginName:Vk}})),s.onLoad({filter:/.*/,namespace:Zle},async F=>Ou.timeFn(`Generating json schema data: ${bT.basename(F.path)}`,async()=>{let J=[],G;try{let Se=bT.relative(d,F.path),de=f.getSchema(Se);if(!de)throw new Error(`Could not load schema at ${F.path}`);G=de.source?.validateCode;let ae=f.compile(de.schema);G=(0,k_t.default)(f,ae)}catch(Se){J.push({pluginName:Vk,text:`Cannot parse project's schemas/${bT.basename(F.path)} file. Error: ${Se.message}`,location:null,notes:[{text:Se.message,location:null}],detail:Se})}if(Gm.DEBUG_BUILD_MODE&&G){let Se=bT.relative(d,F.path),de=bT.join(o.sourceDirectory,Ng,`${Se}.js`);await qk(de,G)}return{contents:G,errors:J,pluginName:Vk,resolveDir:bT.dirname(F.path),watchFiles:[F.path]}}))}}}t(w_t,"jsonSchemaPlugin");import{relative as $pr}from"node:path";var D_t=["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"],Jpr="nodejs-compat-plugin";function P_t({sourceDirectory:o}){return{name:Jpr,setup(s){let f=new Set;s.onStart(()=>{f.clear()}),s.onResolve({filter:/node:.*/},async({path:d,kind:y,resolveDir:x,...P})=>{let F=`${d}:${y}:${x}:${P.importer}`;if(f.has(F))return;f.add(F);let J=await s.resolve(d,{kind:y,resolveDir:x,importer:P.importer});return J.errors.length>0?D_t.includes(d)||d.includes("/")&&D_t.includes(d.split("/")[0])?{external:!0}:{external:!0,warnings:J.errors.map(Se=>({...Se,location:{file:$pr(o,P.importer),line:0,column:0,namespace:"",length:0,lineText:"",suggestion:"Remove the imported node module"},detail:`The package "${d}" wasn't found on the file system but is built into node. If this code is executed it will fail.`}))}:J})}}}t(P_t,"nodejsCompatPlugin");import A_t from"node:fs/promises";import BE from"node:path";var SI="open-api-routes-plugin",sG="open-api-routes-json";function N_t(o){return{name:"open-api-routes-plugin",setup(s){s.onResolve({filter:/zuplo:routes$/},f=>({watchFiles:[...X4e(BE.join(o.sourceDirectory,D1),[".oas.json"],!0),BE.join(o.sourceDirectory,D1,doe)],namespace:sG,path:BE.isAbsolute(f.path)?f.path:BE.join(f.resolveDir,f.path),pluginName:SI})),s.onResolve({filter:/^\.\.\/modules\/.*/,namespace:sG},async f=>Ou.timeFn("Generating route data...",async()=>{async function d(){let x=BE.resolve(o.sourceDirectory,"config"),P=await mO(x),F=`$import(.${f.path.replace(/^../,"")})`;return{location:await qnt(P,F,"Update your route configuration to use code from the 'modules' folder"),originalImportValue:F}}t(d,"getLocation");let y=BE.join(f.resolveDir,`${f.path}.ts`);if(f.path.endsWith(".ts")){let{location:x,originalImportValue:P}=await d();return{errors:[{id:"route-build-error",text:`Invalid handler reference '${P}' in ${x?.file??"OpenAPI file"}. Imports must NOT include the '.ts' file extension.`,location:x,detail:"RouteReferenceError",pluginName:SI}],namespace:sG,path:f.path,pluginName:SI}}else if(!await tu.fileExists(y)){let{location:x,originalImportValue:P}=await d();return{errors:[{id:"route-build-error",text:`Invalid handler reference in route. Unable to resolve reference to '${P}' in ${x?.file??"OpenAPI file"}`,location:x,detail:"RouteReferenceError",pluginName:SI}],namespace:sG,path:f.path,pluginName:SI}}})),s.onLoad({filter:/.*/,namespace:sG},async f=>Ou.timeFn("Generating route.json data",async()=>{let d=BE.resolve(o.sourceDirectory,"config"),y=await mO(d),x=await Promise.all(y.map(async G=>({content:await A_t.readFile(G,"utf-8"),fileName:G}))),P=BE.resolve(d,"policies.json");if(!await tu.fileExists(P))return{errors:[{text:"The project must include a policies file ('/config/policies.json')",detail:"OASPoliciesFileMissing",pluginName:SI,location:{line:0,column:0,file:"/config/policies.json"}}],pluginName:SI};let F={content:await A_t.readFile(P,"utf-8"),fileName:P},J;try{J=await R4e({sourceDirectory:o.sourceDirectory,oasContent:x,policiesContent:F,compatibilityDate:o.config.compatibilityDate,allowDuplicateRoutes:o.config.allowDuplicateRoutes})}catch(G){throw new Error(`Error compiling routes: ${G.message}`)}if(Gm.DEBUG_BUILD_MODE&&J.content){let G=BE.join(o.sourceDirectory,Ng),Se=BE.resolve(G,"routes.js");await qk(Se,J.content)}return{contents:J.content,errors:J.errors,pluginName:SI,resolveDir:BE.dirname(f.path),watchFiles:[f.path]}}))}}}t(N_t,"openApiRoutesPlugin");import Qle from"node:path";var aG="raw-route-plugin",I_t="raw-route";function O_t(o){return{name:"raw-route-plugin",setup(s){s.onResolve({filter:/zuplo:raw-routes$/},f=>({namespace:I_t,path:f.path,pluginName:aG})),s.onLoad({filter:/.*/,namespace:I_t},async f=>Ou.timeFn("Building route data",async()=>{let d=Qle.resolve(o.sourceDirectory,D1);if(!await tu.dirExists(d))return{loader:"js",resolveDir:Qle.dirname(f.path),pluginName:aG};let y=await mO(d);try{let x=await B4e({oasFiles:y,sourceDirectory:o.sourceDirectory,logger:o.logger});if(Gm.DEBUG_BUILD_MODE&&x){let P=Qle.join(o.sourceDirectory,Ng,"raw-routes.js");await qk(P,x)}return{contents:x,loader:"js",resolveDir:Qle.dirname(f.path),pluginName:aG}}catch(x){if(x instanceof w1)return{contents:"",loader:"ts",errors:[{id:"route-build-error",text:x.issue.text,location:x.issue.location,detail:x.issue.detail,pluginName:aG}],pluginName:aG};throw x}}))}}}t(O_t,"rawRoutePlugin");import Wpr from"node:fs/promises";import F_t from"node:path";var eue="runtime-extensions-plugin",L_t="runtime-extensions";function R_t(o){return{name:eue,setup(s){s.onResolve({filter:/zuplo:runtime-extension$/},f=>({namespace:L_t,path:f.path,pluginName:eue})),s.onLoad({filter:/.*/,namespace:L_t},async()=>Ou.timeFn("Generating zuplo.runtime.ts data",async()=>{let f="export const runtimeInit = undefined;",d=F_t.resolve(o.sourceDirectory,frt,"zuplo.runtime.ts"),y=[];return await tu.fileExists(d)?(f=await Wpr.readFile(d,"utf-8"),{contents:f,loader:"ts",resolveDir:F_t.dirname(d),errors:y,pluginName:eue,watchFiles:[d]}):{contents:f,loader:"ts",errors:y,pluginName:eue}}))}}}t(R_t,"runtimeExtensionsPlugin");import j_t from"node:path";import{readFile as qpr}from"node:fs/promises";import TI from"node:path";var VM=class extends Error{static{t(this,"DevPortalConfigError")}filename;constructor(s,f){super(s,f),this.name="DevPortalConfigError",this.filename=f?.filename}};async function M_t(o){let s=TI.join(D1,prt),f=TI.join(o,s),d=!0,y;if(await tu.fileExists(f)){try{let P=await qpr(f,"utf-8"),F=JSON.parse(P);F.enabled===!1&&(d=!1),y=F.sitePathname}catch(P){throw new VM("Failed to parse dev-portal.json file.",{cause:P,filename:s})}return{enabled:d,type:"legacy",basePath:y,filepath:s}}let x=["zudoku.config.js","zudoku.config.jsx","zudoku.config.ts","zudoku.config.tsx","zudoku.config.mjs"];for(;x.length;){let P=x.pop();if(P){let F=TI.join("docs",P),J=TI.join(o,F);try{if(await tu.fileExists(J))return{enabled:!0,type:"zudoku",basePath:void 0,filepath:F}}catch(G){throw new VM("Failed to read dev portal configuration file.",{cause:G,filename:F})}}}return{enabled:!1,type:void 0,basePath:void 0,filepath:void 0}}t(M_t,"getDevPortalConfig");function HM(o,s){let f=TI.resolve(o,U9);return Object.keys(s?.outputs??{}).map(x=>{let P=TI.normalize(x);return`./${TI.relative(f,P).split(TI.sep).join("/")}`})}t(HM,"getBuildModules");var B_t="/docs",Vpr="/__zuplo/dev-portal";function Hpr(o){let s=o.trim().toLowerCase();return s.endsWith("/")&&(s=s.slice(0,-1)),s}t(Hpr,"normalizePathname");function Gpr(o,s){let d={developerPortal:{basePath:o?.basePath===Vpr?B_t:o?.basePath?Hpr(o.basePath):B_t,enabled:o?o.enabled??!0:!1,type:o?.type??void 0,urls:o?.urls?{defaultUrl:o.urls.defaultUrl,urls:o.urls.urls.map(x=>new URL(x).origin)}:void 0},api:s};return`const runtimeSettings = ${JSON.stringify(d)};
605
+ export default environment;`;function o_t(o){return{name:"environment",setup(s){s.onResolve({filter:/@app\/environment$/},()=>({namespace:a_t,pluginName:s_t,path:i_t.join(o.sourceDirectory,Ng,"environment.js")})),s.onLoad({filter:/.*/,namespace:a_t},async f=>({contents:vpr,loader:"ts",resolveDir:i_t.dirname(f.path),pluginName:s_t}))}}}t(o_t,"environmentPlugin");import zpr from"node:fs/promises";import bT from"node:path";var x_t=Sd(Lle(),1),E_t=Sd(b_t(),1),C_t=Sd(Mle(),1),k_t=Sd(K4e(),1);import{performance as jE}from"node:perf_hooks";var iG=[];async function jpr(o,s){let f=jE.now();try{return await s()}finally{let d=jE.now()-f;iG.push({name:o,duration:d})}}t(jpr,"timeFn");var Bpr={mark:t(o=>{jE.mark(o)},"mark"),measure:t((o,s,f)=>{try{jE.measure(o,s,f)}finally{jE.clearMarks(s),jE.clearMarks(f),jE.clearMeasures(o)}},"measure"),timeFn:jpr,report:t(()=>{if(iG.length>0){let o=iG.reduce((s,{name:f,duration:d})=>(s[f]=`${d.toFixed(0)}ms`,s),{});console.table(o),iG.length=0}},"report"),getDuration:t(o=>{let s=jE.getEntriesByName(o);if(s.length===0)return 0;let f=s[0].duration;return jE.clearMeasures(o),f},"getDuration"),clear:t(()=>{iG.length=0,jE.clearMarks(),jE.clearMeasures()},"clear")},Ou=Bpr;import{writeFile as Upr}from"node:fs/promises";async function qk(o,s){await tu.mkdirForFilePathIfNotExits(o);let f=await import("prettier"),d=s;try{d=await f.format(s,{parser:"babel"})}catch{}await Upr(o,d,"utf-8")}t(qk,"writeDebugSourceFile");var Vk="schemas",Zle="json-schema";function w_t(o){return{name:Vk,async setup(s){let f=new C_t.Ajv2020({code:{source:!0},allErrors:!0,strict:!1,verbose:!0,meta:!0}),d=bT.join(o.sourceDirectory,mV),y=[],x=[],P;await Ou.timeFn("Initializing schema validation",async()=>{if((0,E_t.default)(f,{mode:"fast"}),f.opts.code.formats=x_t._`require("ajv-formats/dist/formats").fastFormats`,await tu.dirExists(d)&&(f.addKeyword("faker"),P=(await tu.listFolderContents(d,mV)).sort(),await Promise.all(P.map(async F=>{try{let J=tu.safePath(o.sourceDirectory).resolve(d,F);if(!J.startsWith(d))throw new Error("All schemas must be in the schemas directory");let G=await zpr.readFile(J,"utf-8");if(G===""||G===void 0)throw new Error(`Schema 'schemas/${F}' is empty and will be ignored.`);let Se=JSON.parse(G);if(Se.$schema&&Se.$schema!=="https://json-schema.org/draft/2020-12/schema")throw new Error(`Error in ${F}: All JSON schemas must use version 2020-12. See release notes for changes: https://json-schema.org/draft/2020-12/release-notes.html`);if(f.addSchema(Se,F),f.errors?.length){let de=f.errors[0];y.push({id:"json-schema-validation-error",pluginName:Vk,text:`Error: ${de.message}`,location:{file:bT.join(mV,F)},detail:{params:de.params,propertyName:de.propertyName,schemaPath:de.schemaPath,data:de.data}})}}catch(J){if(J.message.endsWith("is empty and will be ignored.")){x.push({id:"empty-json-schema-file",pluginName:Vk,text:`Schema 'schemas/${F}' is empty and will be ignored.`,location:{file:`schemas/${F}`,suggestion:"Add schema details or remove the file from the project."},detail:"EmptyJSONSchemaFile",notes:[{text:`Schema 'schemas/${F}' is empty and will be ignored.`,location:{file:`schemas/${F}`,suggestion:"Add schema details or remove the file from the project."}}]});return}let G=await U4e(F,o.sourceDirectory,J.message);y.push({id:"json-schema-add-error",pluginName:Vk,text:`Error: ${J.message}`,location:G,detail:"InvalidAddSchemaError",notes:[{text:J.message}]})}})),await Promise.all(P.map(async F=>{try{let J=f.getSchema(F);J&&f.compile(J.schema).errors?.forEach(Se=>{y.push({text:`Failed to compile ${F}: ${Se.message}`})})}catch(J){let G=await U4e(F,o.sourceDirectory,J.message);y.push({id:"json-schema-compile-error",pluginName:Vk,text:`The schema file '${F}' is not valid. Error: ${J.message}`,location:G,detail:"InvalidSchemaError",notes:[{text:J.message}]})}})),Gm.DEBUG_BUILD_MODE)){let F=bT.resolve(o.outputDirectory,mV);await tu.mkdirIfNotExists(F)}}),s.onStart(async()=>{if(P)return{errors:y,warnings:x}}),s.onResolve({filter:/schemas\/.*\.json$/},async F=>Ou.timeFn("Generating JSON schemas...",async()=>{let J=bT.isAbsolute(F.path)?F.path:bT.join(F.resolveDir,F.path);if(F.importer&&F.namespace!=="open-api-routes-json")return{path:J};if(!await tu.fileExists(J)){let G="policies.json";return{errors:[{id:"json-schema-build-error",text:`Unable to resolve reference to '${F.path}' from ${G}`,location:{file:bT.join(F.resolveDir,G),namespace:Zle,line:1,column:0,length:0,lineText:`Invalid JSON schema reference in ${G}`,suggestion:""},detail:"RouteReferenceError",pluginName:Vk,notes:[{text:`Unable to resolve reference to '${F.path}' from ${G}`,location:null}]}],namespace:Zle,path:J,pluginName:Vk}}return{path:J,namespace:Zle,pluginName:Vk}})),s.onLoad({filter:/.*/,namespace:Zle},async F=>Ou.timeFn(`Generating json schema data: ${bT.basename(F.path)}`,async()=>{let J=[],G;try{let Se=bT.relative(d,F.path),de=f.getSchema(Se);if(!de)throw new Error(`Could not load schema at ${F.path}`);G=de.source?.validateCode;let ae=f.compile(de.schema);G=(0,k_t.default)(f,ae)}catch(Se){J.push({pluginName:Vk,text:`Cannot parse project's schemas/${bT.basename(F.path)} file. Error: ${Se.message}`,location:null,notes:[{text:Se.message,location:null}],detail:Se})}if(Gm.DEBUG_BUILD_MODE&&G){let Se=bT.relative(d,F.path),de=bT.join(o.sourceDirectory,Ng,`${Se}.js`);await qk(de,G)}return{contents:G,errors:J,pluginName:Vk,resolveDir:bT.dirname(F.path),watchFiles:[F.path]}}))}}}t(w_t,"jsonSchemaPlugin");import{relative as $pr}from"node:path";var D_t=["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"],Jpr="nodejs-compat-plugin";function P_t({sourceDirectory:o}){return{name:Jpr,setup(s){let f=new Set;s.onStart(()=>{f.clear()}),s.onResolve({filter:/node:.*/},async({path:d,kind:y,resolveDir:x,...P})=>{let F=`${d}:${y}:${x}:${P.importer}`;if(f.has(F))return;f.add(F);let J=await s.resolve(d,{kind:y,resolveDir:x,importer:P.importer});return J.errors.length>0?D_t.includes(d)||d.includes("/")&&D_t.includes(d.split("/")[0])?{external:!0}:{external:!0,warnings:J.errors.map(Se=>({...Se,location:{file:$pr(o,P.importer),line:0,column:0,namespace:"",length:0,lineText:"",suggestion:"Remove the imported node module"},detail:`The package "${d}" wasn't found on the file system but is built into node. If this code is executed it will fail.`}))}:J})}}}t(P_t,"nodejsCompatPlugin");import A_t from"node:fs/promises";import BE from"node:path";var SI="open-api-routes-plugin",sG="open-api-routes-json";function N_t(o){return{name:"open-api-routes-plugin",setup(s){s.onResolve({filter:/zuplo:routes$/},f=>({watchFiles:[...X4e(BE.join(o.sourceDirectory,D1),[".oas.json"],!0),BE.join(o.sourceDirectory,D1,doe)],namespace:sG,path:BE.isAbsolute(f.path)?f.path:BE.join(f.resolveDir,f.path),pluginName:SI})),s.onResolve({filter:/^\.\.\/modules\/.*/,namespace:sG},async f=>Ou.timeFn("Generating route data...",async()=>{async function d(){let x=BE.resolve(o.sourceDirectory,"config"),P=await mO(x),F=`$import(.${f.path.replace(/^../,"")})`;return{location:await qnt(P,F,"Update your route configuration to use code from the 'modules' folder"),originalImportValue:F}}t(d,"getLocation");let y=BE.join(f.resolveDir,`${f.path}.ts`);if(f.path.endsWith(".ts")){let{location:x,originalImportValue:P}=await d();return{errors:[{id:"route-build-error",text:`Invalid handler reference '${P}' in ${x?.file??"OpenAPI file"}. Imports must NOT include the '.ts' file extension.`,location:x,detail:"RouteReferenceError",pluginName:SI}],namespace:sG,path:f.path,pluginName:SI}}else if(!await tu.fileExists(y)){let{location:x,originalImportValue:P}=await d();return{errors:[{id:"route-build-error",text:`Invalid handler reference in route. Unable to resolve reference to '${P}' in ${x?.file??"OpenAPI file"}`,location:x,detail:"RouteReferenceError",pluginName:SI}],namespace:sG,path:f.path,pluginName:SI}}})),s.onLoad({filter:/.*/,namespace:sG},async f=>Ou.timeFn("Generating route.json data",async()=>{let d=BE.resolve(o.sourceDirectory,"config"),y=await mO(d),x=await Promise.all(y.map(async G=>({content:await A_t.readFile(G,"utf-8"),fileName:G}))),P=BE.resolve(d,"policies.json");if(!await tu.fileExists(P))return{errors:[{text:"The project must include a policies file ('/config/policies.json')",detail:"OASPoliciesFileMissing",pluginName:SI,location:{line:0,column:0,file:"/config/policies.json"}}],pluginName:SI};let F={content:await A_t.readFile(P,"utf-8"),fileName:P},J;try{J=await R4e({sourceDirectory:o.sourceDirectory,oasContent:x,policiesContent:F,compatibilityDate:o.config.compatibilityDate,allowDuplicateRoutes:o.config.allowDuplicateRoutes})}catch(G){throw new Error(`Error compiling routes: ${G.message}`)}if(Gm.DEBUG_BUILD_MODE&&J.content){let G=BE.join(o.sourceDirectory,Ng),Se=BE.resolve(G,"routes.js");await qk(Se,J.content)}return{contents:J.content,errors:J.errors,pluginName:SI,resolveDir:BE.dirname(f.path),watchFiles:[f.path]}}))}}}t(N_t,"openApiRoutesPlugin");import Qle from"node:path";var aG="raw-route-plugin",I_t="raw-route";function O_t(o){return{name:"raw-route-plugin",setup(s){s.onResolve({filter:/zuplo:raw-routes$/},f=>({namespace:I_t,path:f.path,pluginName:aG})),s.onLoad({filter:/.*/,namespace:I_t},async f=>Ou.timeFn("Building route data",async()=>{let d=Qle.resolve(o.sourceDirectory,D1);if(!await tu.dirExists(d))return{loader:"js",resolveDir:Qle.dirname(f.path),pluginName:aG};let y=await mO(d);try{let x=await B4e({oasFiles:y,sourceDirectory:o.sourceDirectory,logger:o.logger});if(Gm.DEBUG_BUILD_MODE&&x){let P=Qle.join(o.sourceDirectory,Ng,"raw-routes.js");await qk(P,x)}return{contents:x,loader:"js",resolveDir:Qle.dirname(f.path),pluginName:aG}}catch(x){if(x instanceof w1)return{contents:"",loader:"ts",errors:[{id:"route-build-error",text:x.issue.text,location:x.issue.location,detail:x.issue.detail,pluginName:aG}],pluginName:aG};throw x}}))}}}t(O_t,"rawRoutePlugin");import Wpr from"node:fs/promises";import F_t from"node:path";var eue="runtime-extensions-plugin",L_t="runtime-extensions";function R_t(o){return{name:eue,setup(s){s.onResolve({filter:/zuplo:runtime-extension$/},f=>({namespace:L_t,path:f.path,pluginName:eue})),s.onLoad({filter:/.*/,namespace:L_t},async()=>Ou.timeFn("Generating zuplo.runtime.ts data",async()=>{let f="export const runtimeInit = undefined;",d=F_t.resolve(o.sourceDirectory,frt,"zuplo.runtime.ts"),y=[];return await tu.fileExists(d)?(f=await Wpr.readFile(d,"utf-8"),{contents:f,loader:"ts",resolveDir:F_t.dirname(d),errors:y,pluginName:eue,watchFiles:[d]}):{contents:f,loader:"ts",errors:y,pluginName:eue}}))}}}t(R_t,"runtimeExtensionsPlugin");import j_t from"node:path";import{readFile as qpr}from"node:fs/promises";import TI from"node:path";var VM=class extends Error{static{t(this,"DevPortalConfigError")}filename;constructor(s,f){super(s,f),this.name="DevPortalConfigError",this.filename=f?.filename}};async function M_t(o){let s=["zudoku.config.tsx","zudoku.config.ts","zudoku.config.js","zudoku.config.jsx","zudoku.config.mjs"];for(;s.length;){let P=s.pop();if(P){let F=TI.join("docs",P),J=TI.join(o,F);try{if(await tu.fileExists(J))return{enabled:!0,type:"zudoku",basePath:void 0,filepath:F}}catch(G){throw new VM("Failed to read dev portal configuration file.",{cause:G,filename:F})}}}let f=TI.join(D1,prt),d=TI.join(o,f),y=!0,x;if(await tu.fileExists(d)){try{let P=await qpr(d,"utf-8"),F=JSON.parse(P);F.enabled===!1&&(y=!1),x=F.sitePathname}catch(P){throw new VM("Failed to parse dev-portal.json file.",{cause:P,filename:f})}return{enabled:y,type:"legacy",basePath:x,filepath:f}}return{enabled:!1,type:void 0,basePath:void 0,filepath:void 0}}t(M_t,"getDevPortalConfig");function HM(o,s){let f=TI.resolve(o,U9);return Object.keys(s?.outputs??{}).map(x=>{let P=TI.normalize(x);return`./${TI.relative(f,P).split(TI.sep).join("/")}`})}t(HM,"getBuildModules");var B_t="/docs",Vpr="/__zuplo/dev-portal";function Hpr(o){let s=o.trim().toLowerCase();return s.endsWith("/")&&(s=s.slice(0,-1)),s}t(Hpr,"normalizePathname");function Gpr(o,s){let d={developerPortal:{basePath:o?.basePath===Vpr?B_t:o?.basePath?Hpr(o.basePath):B_t,enabled:o?o.enabled??!0:!1,type:o?.type??void 0,urls:o?.urls?{defaultUrl:o.urls.defaultUrl,urls:o.urls.urls.map(x=>new URL(x).origin)}:void 0},api:s};return`const runtimeSettings = ${JSON.stringify(d)};
606
606
  export default runtimeSettings;`}t(Gpr,"generateSource");var oG="runtime-settings-plugin",tue="runtime-settings";function U_t(o){return{name:oG,setup(s){s.onResolve({filter:/zuplo:runtime-settings$/},f=>({namespace:tue,path:f.path,pluginName:oG})),s.onLoad({filter:/.*/,namespace:tue},async()=>Ou.timeFn("Generating runtime settings",async()=>{let f=[],d,y;try{let F=await M_t(o.sourceDirectory);y=F.filepath,d={...F,urls:o.urls?.devPortal}}catch(F){let J="Failed to load dev portal config",G="config/dev-portal.json";F instanceof VM&&(J=F.message,G=F.filename??G),f.push({id:"dev-portal-build-error",text:J,location:{file:G,namespace:tue,line:1,column:0,length:0,lineText:"",suggestion:""},detail:"DevPortalValidationError",pluginName:oG,notes:[{text:F.message,location:null}]})}let x={urls:o.urls?.api},P;try{if(P=Gpr(d,x),Gm.DEBUG_BUILD_MODE&&P){let F=j_t.join(o.sourceDirectory,Ng,"dev-portal.js");await qk(F,P)}}catch(F){f.push({id:"dev-portal-build-error",text:F.message,location:{file:"dev-portal.json",namespace:tue,line:1,column:0,length:0,lineText:"issue",suggestion:""},detail:"DevPortalValidationError",pluginName:oG,notes:[{text:F.message,location:null}]})}return{contents:P,errors:f,pluginName:oG,loader:"js",resolveDir:y?j_t.dirname(y):void 0}}))}}}t(U_t,"runtimeSettingsPlugin");import e3e from"node:fs/promises";import UO from"node:path";var $_t=Sd(Mle(),1),J_t=Sd(K4e(),1);var Z4e="schema-validation-plugin",z_t="schema-validation",Ypr="module.exports = {}";function W_t(o){return{name:"schema-validation-plugin",setup(s){s.onResolve({filter:/zuplo:schema-validations$/},f=>({namespace:z_t,path:f.path,pluginName:Z4e})),s.onLoad({filter:/.*/,namespace:z_t},async()=>Ou.timeFn("Validating schemas",async()=>{let f=UO.resolve(o.sourceDirectory,D1,"policies.json");if(!await tu.fileExists(f))return{contents:Ypr,loader:"js",resolveDir:UO.dirname(f),pluginName:Z4e};let d=await Xpr(o.sourceDirectory),y=UO.resolve(o.sourceDirectory,D1),x=await mO(y),P=await tdr(x,d),F=await Kpr({oasFiles:x,routesWithSchemaValidation:P,sourceDirectory:o.sourceDirectory,logger:o.logger});if(Gm.DEBUG_BUILD_MODE&&F){let J=UO.join(o.sourceDirectory,Ng,"schema-validation.js");await qk(J,F)}return{contents:F,loader:"js",resolveDir:UO.dirname(f),pluginName:Z4e}}))}}}t(W_t,"schemaValidationPlugin");async function Kpr({oasFiles:o,routesWithSchemaValidation:s,sourceDirectory:f,logger:d}){let y="",x=new rI(f,d);if(s.length===0)return y;let P=new $_t.Ajv2020({code:{source:!0},allErrors:!0,strict:!1,verbose:!0,meta:!0});for(let F of o){let J=await e3e.readFile(F,"utf-8"),G=UO.basename(F,".oas.json"),Se=s.filter(Fe=>Fe.fileName===G),de=await x.resolve(F),ae=JSON.parse(J),Ke=[],$e=new Map;Se.forEach(Fe=>{let Gt=ae.paths[Fe.path][Fe.method];if(Gt.requestBody){let jt;if(Gt.requestBody.$ref){let Pr=Gt.requestBody.$ref;jt=de.get(Pr)?.content}else Gt.requestBody.content&&(jt=Gt.requestBody.content);if(jt)for(let Pr in jt){let Fn=jt[Pr].schema,sn=O6e(Fe.path,Fe.method,Pr);Fn.$id=sn,P.addSchema(Fn),Q4e(Fn,F,G,P,de,Ke,$e)}}if(Gt.parameters)for(let jt of Gt.parameters){let Pr=jt.$ref?de.get(jt.$ref):jt,Fn=Pr.schema.$ref?de.get(Pr.schema.$ref):Pr.schema,sn=I6e(Fe.path,Fe.method,Pr.in,Pr.name);Fn.$id=sn,P.addSchema(Fn),Q4e(Pr,F,G,P,de,Ke,$e)}});for(let Fe of Ke){let Gt=de.get(Fe),jt=aH(G,Fe);P.addSchema(Gt,jt)}}return y=(0,J_t.default)(P),y}t(Kpr,"schemaValidationSource");function Q4e(o,s,f,d,y,x,P){for(let F in o){let J=o[F];if(F==="$ref"){let G=aH(f,GN(s,J));o[F]=G,BV(s,f,GN(s,J),y,x,P,(Se,de,ae)=>aH(Se,GN(ae,de)))}else typeof J=="object"&&Q4e(J,s,f,d,y,x,P)}}t(Q4e,"addRefsToSchema");async function Xpr(o){let s=new Set(["RequestValidationInboundPolicy"]),f=await e3e.readFile(`${o}/config/policies.json`,"utf-8"),d=JSON.parse(f);return Zpr(d,s)}t(Xpr,"getPolicyNamesUsingSchemaValidationPolicies");function Zpr(o,s){let f=new Set;o.policies?.forEach(y=>{y.handler?.export&&s.has(y.handler.export)&&y.handler.module==="$import(@zuplo/runtime)"&&f.add(y.name)});let d=Qpr(o,f);return new Set([...f,...d])}t(Zpr,"getPolicyNamesReferencingPolicyHandlers");function Qpr(o,s){let f=new Set;return o.policies?.forEach(d=>{d.handler?.export==="CompositeInboundPolicy"&&d.handler?.options?.policies?.forEach(y=>{s.has(y)&&f.add(d.name)})}),f}t(Qpr,"getCompositePoliciesContainingPolicy");function edr(o,s){if(!o["x-zuplo-route"]||!o["x-zuplo-route"].policies)return!1;let f=o["x-zuplo-route"].policies.inbound;if(f){for(let y of f)if(s.has(y))return!0}let d=o["x-zuplo-route"].policies.outbound;if(d){for(let y of d)if(s.has(y))return!0}return!1}t(edr,"isPolicyPresentInOperation");async function tdr(o,s){let f=[];for(let d of o){let y=await e3e.readFile(d,"utf-8"),P=JSON.parse(y).paths;for(let F in P){let J=P[F];for(let G in J){let Se=J[G];edr(Se,s)&&f.push({fileName:UO.basename(d,".oas.json"),path:F,method:G})}}}return f}t(tdr,"getRoutesContainingPolicies");import{mkdirSync as rdr,writeFileSync as ndr}from"node:fs";import idr from"node:path";function q_t(o){return{name:"write-modules-plugin",setup(s){s.onEnd(async f=>{if(f){let d=HM(o.sourceDirectory,f.metafile);rdr(o.outputDirectory,{recursive:!0}),ndr(idr.join(o.outputDirectory,"modules.json"),JSON.stringify(d,null,2))}})}}}t(q_t,"writeModulesPlugin");var sdr=Sce("zuplo:core:build"),adr=["workerd","worker","browser"],G_t=[...process.env.GLOBAL_MODULE_LOCATION?[process.env.GLOBAL_MODULE_LOCATION]:[],t3e.resolve(V_t(H_t(import.meta.url)),"..","..","..","node_modules"),t3e.resolve(V_t(H_t(import.meta.url)),"..","..","..","..","..","node_modules")];async function cG({systemDirectory:o,outputDirectory:s,sourceDirectory:f,cacheDirectory:d,logger:y,minify:x=!0,command:P,config:F,urls:J}){let G=t3e.join(o,hoe);sdr(`Building with node paths: ${G_t.join(", ")}`);let Se=x&&P!=="dev"&&!process.env.DEBUG_BUILD_DISABLE_MINIFY?{minify:!0,chunkNames:"[hash]"}:{minify:!1,keepNames:!0,chunkNames:"[name]-[hash]"},de=Object.freeze({sourceDirectory:f,outputDirectory:s,cacheDirectory:d,logger:y,debugMode:Gm.DEBUG_BUILD_MODE,config:F,urls:J});return{platform:"browser",target:"es2022",outdir:s,splitting:!0,metafile:!0,format:"esm",nodePaths:G_t,entryPoints:[G],sourcemap:"linked",legalComments:"none",treeShaking:!0,bundle:!0,...Se,external:[],logLevel:"silent",conditions:adr,plugins:[o_t(de),n_t(de),N_t(de),O_t(de),W_t(de),R_t(de),U_t(de),w_t(de),P_t(de),q_t(de)]}}t(cG,"getBaseESBuildConfig");var zO="run-esbuild",K_t=t(async function({systemDirectory:o,outputDirectory:s,sourceDirectory:f,cacheDirectory:d,buildId:y,logger:x,config:P,command:F,minify:J,urls:G},{data:Se}){x.debug("Running esbuild");let de=await cG({command:F,minify:J,systemDirectory:o,outputDirectory:s,cacheDirectory:d,sourceDirectory:f,logger:x,config:P,urls:G}),ae;try{if(!await X9(f))throw new Error("Failed to build project because no open-api file was found on the 'config' folder");ae=await Y_t.build(de),Se.set("metafile",ae.metafile)}catch(Fe){if(x.error(Fe),Fe.errors||Fe.warnings)ae=Fe;else if(Fe.message.includes("Failed to build project because no open-api file was found on the 'config' folder"))ae={warnings:[],errors:[{id:"missing-open-api-file",text:"Failed to build project because no open-api file was found on the 'config' folder",pluginName:zO,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 Fe}ae.errors.length>0&&ae.errors.length>1&&(ae.errors.length=1);let{errors:Ke,warnings:$e}=r3e({buildId:y,result:ae});return{errors:Ke,warnings:$e}},"runEsbuild");function r3e({buildId:o,result:s}){return{status:s.errors.length>0?"Failed":s.warnings.length>0?"Warnings":"Good",runtimeVersion:"0.0.0",buildTime:"",buildTimeMs:0,buildId:o,warnings:s.warnings.map(d=>d.text==="Using direct eval with a bundler is not recommended and may cause problems"?{location:d.location,detail:d.detail,id:d.id,notes:d.notes,message:"We do not support the use of 'eval' or 'new Function(...)'",severity:loe,pluginName:d.pluginName||zO}:{location:d.location,detail:d.detail,id:d.id,notes:d.notes,message:d.text,severity:loe,pluginName:d.pluginName||zO}),errors:s.errors.map(d=>({location:d.location,detail:d.detail,id:d.id,notes:d.notes,message:d.text,severity:bPe,pluginName:d.pluginName||zO})),metafile:s.metafile}}t(r3e,"esbuildResultToBuildResult");var odr=t((o,s)=>{let f=s;if(s.includes(o)){let d=new RegExp(`.*(${o})`,"g");f=s.replace(d,"")}return f.match(/^(\/)?(\.\.(\/)?)+/)&&(f=f.replace(/^(\/)?(\.\.(\/)?)+/,"/")),f},"removePrefixFromString"),cdr=t((o,s)=>{let f=s;if(f.includes(o)){let d=new RegExp(`[a-zA-Z0-9-_.\\/]+(${o})`,"g");f=f.replace(d,"")}return f},"cleanFilePathsInMessage"),X_t=t((o,s,f)=>{if(!o||o.length<=0)return o;let d=o.filter(y=>y.message!=='Could not resolve "@zuplo/runtime"');return d&&d.length>0&&d.forEach(y=>{try{y.location?.file&&(y.location.file=odr(s,y.location.file)),y.location?.lineText?.includes("@zuplo/core/index.minified.js")&&(y.location.lineText=`${y.location.lineText.substring(0,200)}...<Truncated>`),y.message=cdr(s,y.message),y.notes&&y.notes.length>0&&delete y.notes,y.text&&delete y.text,y.pluginName===""&&(y.pluginName=f)}catch{}}),d},"cleanDataOnBuildIssue");function Z_t(o,s){let f=n3e.basename(s);o.errors&&(o.errors=X_t(o.errors,f,zO)),o.warnings&&(o.warnings=X_t(o.warnings,f,zO))}t(Z_t,"formatBuildResult");var ldr=t(o=>n3e.basename(o).startsWith("."),"isHiddenOnUnix"),udr=t((o,s=[])=>s.map(f=>f.startsWith(".")?f:`.${f}`).some(f=>o.endsWith(f)),"hasMatchingExtname");function X4e(o,s=[],f=!1){let d=[],y;if(!rue.existsSync(o)){let x;if(LV.hasMagic(o))x=o;else{let P=s.map(F=>F.startsWith(".")?F:`.${F}`).join("|");x=`${o}+(${P})`}if(d.push(...LV.sync(x,{nodir:!0})),!d.length)throw Error(`Cannot find any files matching pattern "${o}"`);return d}try{if(y=rue.statSync(o),y.isFile())return[o]}catch{return[]}return rue.readdirSync(o).forEach(x=>{let P=n3e.join(o,x),F;try{if(F=rue.statSync(P),F.isDirectory()){f&&d.push(...X4e(P,s,f));return}}catch{return}if(!s.length)throw Error(`Argument '${s}' required when argument '${o}' is a directory`);!F.isFile()||!udr(P,s)||ldr(P)||d.push(P)}),d}t(X4e,"lookupFiles");var $O=new _oe,xI=` ${$O.gray("|")} `;function i3e({output:o,buildId:s,runtimeVersion:f,compatibilityDate:d}){let y=["Building Zuplo API...",`${xI}Build ID: ${s}`,`${xI}Runtime Version: ${f}`];d&&y.push(`${xI}Compatibility Date: ${d}`),o.info(y.join(`
607
607
  `))}t(i3e,"outputApiBuildStart");async function nue(o,s,f){Z_t(f,o),await Promise.all(f.warnings.map(async y=>Q_t(o,s,y))),await Promise.all(f.errors.map(async y=>Q_t(o,s,y)));let d=process.env.CODEBUILD_BUILD_ID?new Date(Date.now()+1):new Date;f.status==="Good"?s.info($O.green("Build succeeded"),{timestamp:d}):f.status==="Warnings"?s.warn($O.yellow("Build succeeded with warnings"),{timestamp:d}):f.status==="Failed"&&s.error($O.red("Build failed."),{timestamp:d})}t(nue,"outputBuildResult");async function Q_t(o,s,f){let d=[],y=f.severity??"error",x=y==="error"?$O.red:$O.yellow,P=x(`${y.toUpperCase()}: ${f.message}${f.detail?`
608
608
  ${xI}${f.detail.toString().split(`
package/index.minified.js CHANGED
@@ -602,7 +602,7 @@ globstar while`,s,ae,f,Ke,$e),this.matchOne(s.slice(ae),f.slice(Ke),d))return th
602
602
  `,this.indentLevel=f.startingIndentLevel!=null?f.startingIndentLevel:0,this.writeComments=f.comments?f.comments:!1,f.sourceMap!=null&&(this.write=f.output==null?this.writeAndMap:this.writeToStreamAndMap,this.sourceMap=f.sourceMap,this.line=1,this.column=0,this.lineEndSize=this.lineEnd.split(`
603
603
  `).length-1,this.mapping={original:null,generated:this,name:void 0,source:f.sourceMap.file||f.sourceMap._file})}write(s){this.output+=s}writeToStream(s){this.output.write(s)}writeAndMap(s,f){this.output+=s,this.map(s,f)}writeToStreamAndMap(s,f){this.output.write(s),this.map(s,f)}map(s,f){if(f!=null){let{type:x}=f;if(x[0]==="L"&&x[2]==="n"){this.column=0,this.line++;return}if(f.loc!=null){let{mapping:P}=this;P.original=f.loc.start,P.name=f.name,this.sourceMap.addMapping(P)}if(x[0]==="T"&&x[8]==="E"||x[0]==="L"&&x[1]==="i"&&typeof f.value=="string"){let{length:P}=s,{column:F,line:J}=this;for(let G=0;G<P;G++)s[G]===`
604
604
  `?(F=0,J++):F++;this.column=F,this.line=J;return}}let{length:d}=s,{lineEnd:y}=this;d>0&&(this.lineEndSize>0&&(y.length===1?s[d-1]===y:s.endsWith(y))?(this.line+=this.lineEndSize,this.column=0):this.column+=d)}toString(){return this.output}};function s_t(o,s){let f=new J4e(s);return f.generator[o.type](o,f),f.output}t(s_t,"generate");async function W4e({oasFiles:o,sourceDirectory:s,logger:f}){let d=await Bpr({oasFiles:o,sourceDirectory:s,logger:f});return s_t(d)}t(W4e,"generateRawRouteSource");async function Bpr({oasFiles:o,sourceDirectory:s,logger:f}){let d=new sI(s,f),y=[];for(let P of o){let F=jpr.basename(P,".oas.json"),J=await d.resolve(P),G=[],Se=new Map,de=await Mpr.readFile(P,"utf-8"),ae=JSON.parse(de);for(let Ke in ae.paths){let $e=ae.paths[Ke],Fe=$e.parameters||[],Gt={};$e.summary&&(Gt.pathSummary=$e.summary),$e.description&&(Gt.pathDescription=$e.description),$e.servers&&(Gt.pathServers=$e.servers);for(let jt in $e){if(!Vle(jt))continue;let Pr=$e[jt],Fn=[...Fe,...Pr.parameters||[]],sn={...Pr,...Fn.length>0&&{parameters:Fn},...Gt,...Pr.description&&{description:Pr.description.length>350?`${Pr.description.substring(0,350).trim()}...`:Pr.description}},Un=aH(F,Ke,jt),Er=Kle(P,F,sn,J,G,Se);y.unshift(o_t(Un,Er))}}y.unshift(...Upr(F,J,G,Se).reverse())}return{type:"Program",body:y,sourceType:"module"}}t(Bpr,"generateAst");function Kle(o,s,f,d,y,x){let P=[];for(let F in f){let J=f[F];if(F==="$ref")return UV(o,s,XN(o,J),d,y,x),{type:"Identifier",name:c_t(s,x.get(XN(o,J)))};let G;switch(typeof J){case"string":case"number":case"boolean":G={type:"Literal",value:J};break;default:Array.isArray(J)?G=a_t(J,o,s,d,y,x):typeof J=="object"&&J!==null&&(G=Kle(o,s,J,d,y,x));break}if(G){let Se=/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(F),de=Se?{type:"Identifier",name:F}:{type:"Literal",value:F};P.push({type:"Property",key:de,value:G,kind:"init",method:!1,shorthand:!1,computed:!Se})}}return{type:"ObjectExpression",properties:P}}t(Kle,"processNode");function a_t(o,s,f,d,y,x){return{type:"ArrayExpression",elements:o.map(P=>{if(Array.isArray(P))return a_t(P,s,f,d,y,x);if(typeof P=="object"&&P!==null){let F=Kle(s,f,P,d,y,x);return F.type==="Identifier"?F:{type:"ObjectExpression",properties:F.properties||[]}}else return{type:"Literal",value:P}})}}t(a_t,"processArray");function o_t(o,s){return{type:"ExportNamedDeclaration",declaration:{type:"VariableDeclaration",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:o},init:s}],kind:"var"},specifiers:[],source:null}}t(o_t,"createExportedConstAssignment");function Upr(o,s,f,d){let y=[];for(let x=0;x<f.length;x++){let P=c_t(o,x),F=s.get(f[x]),J=Kle(Woe(f[x]),o,F,s,f,d);y.push(o_t(P,J))}return y}t(Upr,"generateRefs");function c_t(o,s){return`${GP(o)}__ref__${s}`}t(c_t,"getRefIdentifierName");import l_t from"node:path";var u_t=t(o=>{let s=null;if(o.value.type==="Object"&&o.value.members.length>0)for(let f of o.value.members){let d=u_t(f);if(d!==null&&(s=d),f.name.value==="enum"&&f.value.type==="Array"&&f.value.elements.length===0){let y=f.value,x=y.loc.start.line,P=y.loc.start.column,F=y.loc.end.column;s={line:x,column:P,length:F-P,lineText:""}}}return s},"findEmptyEnums"),zpr=t(o=>{if(o.startsWith("schema with key or id")&&o.endsWith("already exists"))return"Update your schema's '$id' to be unique across your project.";if(o.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(o==='"nullable" cannot be used without "type"')return'Property "nullable" can only be used when property "type" value is "object".';if(o==='NOT SUPPORTED: keyword "id", use "$id" for schema ID')return'Replace keyword "id" with "$id" when defining a schema Id.';if(o.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(o.startsWith("can't resolve reference"))return"Make sure all references are defined in the schema.";if(o.includes("oneOf must NOT have fewer than 1 items"))return'Property "oneOf" must have at least 1 item configured.';if(o.includes("enum must have non-empty array"))return'Property "enum" must be configured with at least one value.';if(o.includes("Unexpected")&&o.includes("in JSON at position"))return"Update your schema to only use valid properties."},"getSuggestions"),q4e=t(async(o,s,f)=>{if(!o)return null;let d={file:l_t.join(fAe,o),suggestion:zpr(f)},y=l_t.join(s,fAe),x=tu.safePath(s).resolve(y,o),P=await $oe(x);if(f.includes("enum must have non-empty array")){if(P){let F=await BV(P);if(F&&F.body.members!==null)for(let J of F.body.members){let G=u_t(J);G&&G!==null&&(d=Object.assign(d??{},G))}if(d){let J=d.line?d.line:0;d.lineText=jV(P,J)}}}else if(f.includes("Unexpected")&&f.includes("in JSON at position")&&P){let F=await BV(P);F&&"lineText"in F&&(d=Object.assign(d??{},F))}return d},"getLocation");import*as rpt from"esbuild";import o3e,{dirname as Q_t}from"node:path";import{fileURLToPath as ept}from"node:url";var V4e=class{static{t(this,"Environment")}get DEV_SERVER_PORT(){return process.env.DEV_SERVER_PORT?parseInt(process.env.DEV_SERVER_PORT,10):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"}},$pr=new V4e,km=$pr;var H4e="no-remote-module";function f_t({logger:o}){return{name:H4e,async setup(s){s.onResolve({filter:/^https?:\/\//},f=>(o.error(f,"User attempted to load a remote module"),{errors:[{text:`Remote modules are not supported. Attempted to load module ${f.path}`,detail:"InvalidRemoteModule",pluginName:H4e,location:{line:0,column:0,file:""}}],pluginName:H4e}))}}}t(f_t,"blockRemoteModulePlugin");import __t from"node:path";var p_t="legacy-environment",d_t="legacy-environment",Jpr=`import { environment } from "@zuplo/runtime";
605
- export default environment;`;function m_t(o){return{name:"environment",setup(s){s.onResolve({filter:/@app\/environment$/},()=>({namespace:d_t,pluginName:p_t,path:__t.join(o.sourceDirectory,Ng,"environment.js")})),s.onLoad({filter:/.*/,namespace:d_t},async f=>({contents:Jpr,loader:"ts",resolveDir:__t.dirname(f.path),pluginName:p_t}))}}}t(m_t,"environmentPlugin");import fdr from"node:fs/promises";import bT from"node:path";var N_t=Dp(Lle(),1),I_t=Dp(D_t(),1),O_t=Dp(Mle(),1),F_t=Dp(t3e(),1);import{performance as BE}from"node:perf_hooks";var sG=[];async function cdr(o,s){let f=BE.now();try{return await s()}finally{let d=BE.now()-f;sG.push({name:o,duration:d})}}t(cdr,"timeFn");var ldr={mark:t(o=>{BE.mark(o)},"mark"),measure:t((o,s,f)=>{try{BE.measure(o,s,f)}finally{BE.clearMarks(s),BE.clearMarks(f),BE.clearMeasures(o)}},"measure"),timeFn:cdr,report:t(()=>{if(sG.length>0){let o=sG.reduce((s,{name:f,duration:d})=>(s[f]=`${d.toFixed(0)}ms`,s),{});console.table(o),sG.length=0}},"report"),getDuration:t(o=>{let s=BE.getEntriesByName(o);if(s.length===0)return 0;let f=s[0].duration;return BE.clearMeasures(o),f},"getDuration"),clear:t(()=>{sG.length=0,BE.clearMarks(),BE.clearMeasures()},"clear")},Ou=ldr;import{writeFile as udr}from"node:fs/promises";async function Vk(o,s){await tu.mkdirForFilePathIfNotExits(o);let f=await import("prettier"),d=s;try{d=await f.format(s,{parser:"babel"})}catch{}await udr(o,d,"utf-8")}t(Vk,"writeDebugSourceFile");var Hk="schemas",Zle="json-schema";function L_t(o){return{name:Hk,async setup(s){let f=new O_t.Ajv2020({code:{source:!0},allErrors:!0,strict:!1,verbose:!0,meta:!0}),d=bT.join(o.sourceDirectory,hV),y=[],x=[],P;await Ou.timeFn("Initializing schema validation",async()=>{if((0,I_t.default)(f,{mode:"fast"}),f.opts.code.formats=N_t._`require("ajv-formats/dist/formats").fastFormats`,await tu.dirExists(d)&&(f.addKeyword("faker"),P=(await tu.listFolderContents(d,hV)).sort(),await Promise.all(P.map(async F=>{try{let J=tu.safePath(o.sourceDirectory).resolve(d,F);if(!J.startsWith(d))throw new Error("All schemas must be in the schemas directory");let G=await fdr.readFile(J,"utf-8");if(G===""||G===void 0)throw new Error(`Schema 'schemas/${F}' is empty and will be ignored.`);let Se=JSON.parse(G);if(Se.$schema&&Se.$schema!=="https://json-schema.org/draft/2020-12/schema")throw new Error(`Error in ${F}: All JSON schemas must use version 2020-12. See release notes for changes: https://json-schema.org/draft/2020-12/release-notes.html`);if(f.addSchema(Se,F),f.errors?.length){let de=f.errors[0];y.push({id:"json-schema-validation-error",pluginName:Hk,text:`Error: ${de.message}`,location:{file:bT.join(hV,F)},detail:{params:de.params,propertyName:de.propertyName,schemaPath:de.schemaPath,data:de.data}})}}catch(J){if(J.message.endsWith("is empty and will be ignored.")){x.push({id:"empty-json-schema-file",pluginName:Hk,text:`Schema 'schemas/${F}' is empty and will be ignored.`,location:{file:`schemas/${F}`,suggestion:"Add schema details or remove the file from the project."},detail:"EmptyJSONSchemaFile",notes:[{text:`Schema 'schemas/${F}' is empty and will be ignored.`,location:{file:`schemas/${F}`,suggestion:"Add schema details or remove the file from the project."}}]});return}let G=await q4e(F,o.sourceDirectory,J.message);y.push({id:"json-schema-add-error",pluginName:Hk,text:`Error: ${J.message}`,location:G,detail:"InvalidAddSchemaError",notes:[{text:J.message}]})}})),await Promise.all(P.map(async F=>{try{let J=f.getSchema(F);J&&f.compile(J.schema).errors?.forEach(Se=>{y.push({text:`Failed to compile ${F}: ${Se.message}`})})}catch(J){let G=await q4e(F,o.sourceDirectory,J.message);y.push({id:"json-schema-compile-error",pluginName:Hk,text:`The schema file '${F}' is not valid. Error: ${J.message}`,location:G,detail:"InvalidSchemaError",notes:[{text:J.message}]})}})),km.DEBUG_BUILD_MODE)){let F=bT.resolve(o.outputDirectory,hV);await tu.mkdirIfNotExists(F)}}),s.onStart(async()=>{if(P)return{errors:y,warnings:x}}),s.onResolve({filter:/schemas\/.*\.json$/},async F=>Ou.timeFn("Generating JSON schemas...",async()=>{let J=bT.isAbsolute(F.path)?F.path:bT.join(F.resolveDir,F.path);if(F.importer&&F.namespace!=="open-api-routes-json")return{path:J};if(!await tu.fileExists(J)){let G="policies.json";return{errors:[{id:"json-schema-build-error",text:`Unable to resolve reference to '${F.path}' from ${G}`,location:{file:bT.join(F.resolveDir,G),namespace:Zle,line:1,column:0,length:0,lineText:`Invalid JSON schema reference in ${G}`,suggestion:""},detail:"RouteReferenceError",pluginName:Hk,notes:[{text:`Unable to resolve reference to '${F.path}' from ${G}`,location:null}]}],namespace:Zle,path:J,pluginName:Hk}}return{path:J,namespace:Zle,pluginName:Hk}})),s.onLoad({filter:/.*/,namespace:Zle},async F=>Ou.timeFn(`Generating json schema data: ${bT.basename(F.path)}`,async()=>{let J=[],G;try{let Se=bT.relative(d,F.path),de=f.getSchema(Se);if(!de)throw new Error(`Could not load schema at ${F.path}`);G=de.source?.validateCode;let ae=f.compile(de.schema);G=(0,F_t.default)(f,ae)}catch(Se){J.push({pluginName:Hk,text:`Cannot parse project's schemas/${bT.basename(F.path)} file. Error: ${Se.message}`,location:null,notes:[{text:Se.message,location:null}],detail:Se})}if(km.DEBUG_BUILD_MODE&&G){let Se=bT.relative(d,F.path),de=bT.join(o.sourceDirectory,Ng,`${Se}.js`);await Vk(de,G)}return{contents:G,errors:J,pluginName:Hk,resolveDir:bT.dirname(F.path),watchFiles:[F.path]}}))}}}t(L_t,"jsonSchemaPlugin");import{relative as _dr}from"node:path";var R_t=["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"],pdr="nodejs-compat-plugin";function M_t({sourceDirectory:o}){return{name:pdr,setup(s){let f=new Set;s.onStart(()=>{f.clear()}),s.onResolve({filter:/node:.*/},async({path:d,kind:y,resolveDir:x,...P})=>{let F=`${d}:${y}:${x}:${P.importer}`;if(f.has(F))return;f.add(F);let J=await s.resolve(d,{kind:y,resolveDir:x,importer:P.importer});return J.errors.length>0?R_t.includes(d)||d.includes("/")&&R_t.includes(d.split("/")[0])?{external:!0}:{external:!0,warnings:J.errors.map(Se=>({...Se,location:{file:_dr(o,P.importer),line:0,column:0,namespace:"",length:0,lineText:"",suggestion:"Remove the imported node module"},detail:`The package "${d}" wasn't found on the file system but is built into node. If this code is executed it will fail.`}))}:J})}}}t(M_t,"nodejsCompatPlugin");import j_t from"node:fs/promises";import UE from"node:path";var EI="open-api-routes-plugin",aG="open-api-routes-json";function B_t(o){return{name:"open-api-routes-plugin",setup(s){s.onResolve({filter:/zuplo:routes$/},f=>({watchFiles:[...r3e(UE.join(o.sourceDirectory,Ey),[".oas.json"],!0),UE.join(o.sourceDirectory,Ey,doe)],namespace:aG,path:UE.isAbsolute(f.path)?f.path:UE.join(f.resolveDir,f.path),pluginName:EI})),s.onResolve({filter:/^\.\.\/modules\/.*/,namespace:aG},async f=>Ou.timeFn("Generating route data...",async()=>{async function d(){let x=UE.resolve(o.sourceDirectory,"config"),P=await gO(x),F=`$import(.${f.path.replace(/^../,"")})`;return{location:await Qnt(P,F,"Update your route configuration to use code from the 'modules' folder"),originalImportValue:F}}t(d,"getLocation");let y=UE.join(f.resolveDir,`${f.path}.ts`);if(f.path.endsWith(".ts")){let{location:x,originalImportValue:P}=await d();return{errors:[{id:"route-build-error",text:`Invalid handler reference '${P}' in ${x?.file??"OpenAPI file"}. Imports must NOT include the '.ts' file extension.`,location:x,detail:"RouteReferenceError",pluginName:EI}],namespace:aG,path:f.path,pluginName:EI}}else if(!await tu.fileExists(y)){let{location:x,originalImportValue:P}=await d();return{errors:[{id:"route-build-error",text:`Invalid handler reference in route. Unable to resolve reference to '${P}' in ${x?.file??"OpenAPI file"}`,location:x,detail:"RouteReferenceError",pluginName:EI}],namespace:aG,path:f.path,pluginName:EI}}})),s.onLoad({filter:/.*/,namespace:aG},async f=>Ou.timeFn("Generating route.json data",async()=>{let d=UE.resolve(o.sourceDirectory,"config"),y=await gO(d),x=await Promise.all(y.map(async G=>({content:await j_t.readFile(G,"utf-8"),fileName:G}))),P=UE.resolve(d,"policies.json");if(!await tu.fileExists(P))return{errors:[{text:"The project must include a policies file ('/config/policies.json')",detail:"OASPoliciesFileMissing",pluginName:EI,location:{line:0,column:0,file:"/config/policies.json"}}],pluginName:EI};let F={content:await j_t.readFile(P,"utf-8"),fileName:P},J;try{J=await z4e({sourceDirectory:o.sourceDirectory,oasContent:x,policiesContent:F,compatibilityDate:o.config.compatibilityDate,allowDuplicateRoutes:o.config.allowDuplicateRoutes})}catch(G){throw new Error(`Error compiling routes: ${G.message}`)}if(km.DEBUG_BUILD_MODE&&J.content){let G=UE.join(o.sourceDirectory,Ng),Se=UE.resolve(G,"routes.js");await Vk(Se,J.content)}return{contents:J.content,errors:J.errors,pluginName:EI,resolveDir:UE.dirname(f.path),watchFiles:[f.path]}}))}}}t(B_t,"openApiRoutesPlugin");import Qle from"node:path";var oG="raw-route-plugin",U_t="raw-route";function z_t(o){return{name:"raw-route-plugin",setup(s){s.onResolve({filter:/zuplo:raw-routes$/},f=>({namespace:U_t,path:f.path,pluginName:oG})),s.onLoad({filter:/.*/,namespace:U_t},async f=>Ou.timeFn("Building route data",async()=>{let d=Qle.resolve(o.sourceDirectory,Ey);if(!await tu.dirExists(d))return{loader:"js",resolveDir:Qle.dirname(f.path),pluginName:oG};let y=await gO(d);try{let x=await W4e({oasFiles:y,sourceDirectory:o.sourceDirectory,logger:o.logger});if(km.DEBUG_BUILD_MODE&&x){let P=Qle.join(o.sourceDirectory,Ng,"raw-routes.js");await Vk(P,x)}return{contents:x,loader:"js",resolveDir:Qle.dirname(f.path),pluginName:oG}}catch(x){if(x instanceof D1)return{contents:"",loader:"ts",errors:[{id:"route-build-error",text:x.issue.text,location:x.issue.location,detail:x.issue.detail,pluginName:oG}],pluginName:oG};throw x}}))}}}t(z_t,"rawRoutePlugin");import ddr from"node:fs/promises";import $_t from"node:path";var eue="runtime-extensions-plugin",J_t="runtime-extensions";function W_t(o){return{name:eue,setup(s){s.onResolve({filter:/zuplo:runtime-extension$/},f=>({namespace:J_t,path:f.path,pluginName:eue})),s.onLoad({filter:/.*/,namespace:J_t},async()=>Ou.timeFn("Generating zuplo.runtime.ts data",async()=>{let f="export const runtimeInit = undefined;",d=$_t.resolve(o.sourceDirectory,Srt,"zuplo.runtime.ts"),y=[];return await tu.fileExists(d)?(f=await ddr.readFile(d,"utf-8"),{contents:f,loader:"ts",resolveDir:$_t.dirname(d),errors:y,pluginName:eue,watchFiles:[d]}):{contents:f,loader:"ts",errors:y,pluginName:eue}}))}}}t(W_t,"runtimeExtensionsPlugin");import q_t from"node:path";import{readFile as mdr}from"node:fs/promises";import CI from"node:path";var VM=class extends Error{static{t(this,"DevPortalConfigError")}filename;constructor(s,f){super(s,f),this.name="DevPortalConfigError",this.filename=f?.filename}};async function n3e(o){let s=CI.join(Ey,xrt),f=CI.join(o,s),d=!0,y;if(await tu.fileExists(f)){try{let P=await mdr(f,"utf-8"),F=JSON.parse(P);F.enabled===!1&&(d=!1),y=F.sitePathname}catch(P){throw new VM("Failed to parse dev-portal.json file.",{cause:P,filename:s})}return{enabled:d,type:"legacy",basePath:y,filepath:s}}let x=["zudoku.config.js","zudoku.config.jsx","zudoku.config.ts","zudoku.config.tsx","zudoku.config.mjs"];for(;x.length;){let P=x.pop();if(P){let F=CI.join("docs",P),J=CI.join(o,F);try{if(await tu.fileExists(J))return{enabled:!0,type:"zudoku",basePath:void 0,filepath:F}}catch(G){throw new VM("Failed to read dev portal configuration file.",{cause:G,filename:F})}}}return{enabled:!1,type:void 0,basePath:void 0,filepath:void 0}}t(n3e,"getDevPortalConfig");function HM(o,s){let f=CI.resolve(o,_O);return Object.keys(s?.outputs??{}).map(x=>{let P=CI.normalize(x);return`./${CI.relative(f,P).split(CI.sep).join("/")}`})}t(HM,"getBuildModules");var V_t="/docs",hdr="/__zuplo/dev-portal";function gdr(o){let s=o.trim().toLowerCase();return s.endsWith("/")&&(s=s.slice(0,-1)),s}t(gdr,"normalizePathname");function ydr(o,s){let d={developerPortal:{basePath:o?.basePath===hdr?V_t:o?.basePath?gdr(o.basePath):V_t,enabled:o?o.enabled??!0:!1,type:o?.type??void 0,urls:o?.urls?{defaultUrl:o.urls.defaultUrl,urls:o.urls.urls.map(x=>new URL(x).origin)}:void 0},api:s};return`const runtimeSettings = ${JSON.stringify(d)};
605
+ export default environment;`;function m_t(o){return{name:"environment",setup(s){s.onResolve({filter:/@app\/environment$/},()=>({namespace:d_t,pluginName:p_t,path:__t.join(o.sourceDirectory,Ng,"environment.js")})),s.onLoad({filter:/.*/,namespace:d_t},async f=>({contents:Jpr,loader:"ts",resolveDir:__t.dirname(f.path),pluginName:p_t}))}}}t(m_t,"environmentPlugin");import fdr from"node:fs/promises";import bT from"node:path";var N_t=Dp(Lle(),1),I_t=Dp(D_t(),1),O_t=Dp(Mle(),1),F_t=Dp(t3e(),1);import{performance as BE}from"node:perf_hooks";var sG=[];async function cdr(o,s){let f=BE.now();try{return await s()}finally{let d=BE.now()-f;sG.push({name:o,duration:d})}}t(cdr,"timeFn");var ldr={mark:t(o=>{BE.mark(o)},"mark"),measure:t((o,s,f)=>{try{BE.measure(o,s,f)}finally{BE.clearMarks(s),BE.clearMarks(f),BE.clearMeasures(o)}},"measure"),timeFn:cdr,report:t(()=>{if(sG.length>0){let o=sG.reduce((s,{name:f,duration:d})=>(s[f]=`${d.toFixed(0)}ms`,s),{});console.table(o),sG.length=0}},"report"),getDuration:t(o=>{let s=BE.getEntriesByName(o);if(s.length===0)return 0;let f=s[0].duration;return BE.clearMeasures(o),f},"getDuration"),clear:t(()=>{sG.length=0,BE.clearMarks(),BE.clearMeasures()},"clear")},Ou=ldr;import{writeFile as udr}from"node:fs/promises";async function Vk(o,s){await tu.mkdirForFilePathIfNotExits(o);let f=await import("prettier"),d=s;try{d=await f.format(s,{parser:"babel"})}catch{}await udr(o,d,"utf-8")}t(Vk,"writeDebugSourceFile");var Hk="schemas",Zle="json-schema";function L_t(o){return{name:Hk,async setup(s){let f=new O_t.Ajv2020({code:{source:!0},allErrors:!0,strict:!1,verbose:!0,meta:!0}),d=bT.join(o.sourceDirectory,hV),y=[],x=[],P;await Ou.timeFn("Initializing schema validation",async()=>{if((0,I_t.default)(f,{mode:"fast"}),f.opts.code.formats=N_t._`require("ajv-formats/dist/formats").fastFormats`,await tu.dirExists(d)&&(f.addKeyword("faker"),P=(await tu.listFolderContents(d,hV)).sort(),await Promise.all(P.map(async F=>{try{let J=tu.safePath(o.sourceDirectory).resolve(d,F);if(!J.startsWith(d))throw new Error("All schemas must be in the schemas directory");let G=await fdr.readFile(J,"utf-8");if(G===""||G===void 0)throw new Error(`Schema 'schemas/${F}' is empty and will be ignored.`);let Se=JSON.parse(G);if(Se.$schema&&Se.$schema!=="https://json-schema.org/draft/2020-12/schema")throw new Error(`Error in ${F}: All JSON schemas must use version 2020-12. See release notes for changes: https://json-schema.org/draft/2020-12/release-notes.html`);if(f.addSchema(Se,F),f.errors?.length){let de=f.errors[0];y.push({id:"json-schema-validation-error",pluginName:Hk,text:`Error: ${de.message}`,location:{file:bT.join(hV,F)},detail:{params:de.params,propertyName:de.propertyName,schemaPath:de.schemaPath,data:de.data}})}}catch(J){if(J.message.endsWith("is empty and will be ignored.")){x.push({id:"empty-json-schema-file",pluginName:Hk,text:`Schema 'schemas/${F}' is empty and will be ignored.`,location:{file:`schemas/${F}`,suggestion:"Add schema details or remove the file from the project."},detail:"EmptyJSONSchemaFile",notes:[{text:`Schema 'schemas/${F}' is empty and will be ignored.`,location:{file:`schemas/${F}`,suggestion:"Add schema details or remove the file from the project."}}]});return}let G=await q4e(F,o.sourceDirectory,J.message);y.push({id:"json-schema-add-error",pluginName:Hk,text:`Error: ${J.message}`,location:G,detail:"InvalidAddSchemaError",notes:[{text:J.message}]})}})),await Promise.all(P.map(async F=>{try{let J=f.getSchema(F);J&&f.compile(J.schema).errors?.forEach(Se=>{y.push({text:`Failed to compile ${F}: ${Se.message}`})})}catch(J){let G=await q4e(F,o.sourceDirectory,J.message);y.push({id:"json-schema-compile-error",pluginName:Hk,text:`The schema file '${F}' is not valid. Error: ${J.message}`,location:G,detail:"InvalidSchemaError",notes:[{text:J.message}]})}})),km.DEBUG_BUILD_MODE)){let F=bT.resolve(o.outputDirectory,hV);await tu.mkdirIfNotExists(F)}}),s.onStart(async()=>{if(P)return{errors:y,warnings:x}}),s.onResolve({filter:/schemas\/.*\.json$/},async F=>Ou.timeFn("Generating JSON schemas...",async()=>{let J=bT.isAbsolute(F.path)?F.path:bT.join(F.resolveDir,F.path);if(F.importer&&F.namespace!=="open-api-routes-json")return{path:J};if(!await tu.fileExists(J)){let G="policies.json";return{errors:[{id:"json-schema-build-error",text:`Unable to resolve reference to '${F.path}' from ${G}`,location:{file:bT.join(F.resolveDir,G),namespace:Zle,line:1,column:0,length:0,lineText:`Invalid JSON schema reference in ${G}`,suggestion:""},detail:"RouteReferenceError",pluginName:Hk,notes:[{text:`Unable to resolve reference to '${F.path}' from ${G}`,location:null}]}],namespace:Zle,path:J,pluginName:Hk}}return{path:J,namespace:Zle,pluginName:Hk}})),s.onLoad({filter:/.*/,namespace:Zle},async F=>Ou.timeFn(`Generating json schema data: ${bT.basename(F.path)}`,async()=>{let J=[],G;try{let Se=bT.relative(d,F.path),de=f.getSchema(Se);if(!de)throw new Error(`Could not load schema at ${F.path}`);G=de.source?.validateCode;let ae=f.compile(de.schema);G=(0,F_t.default)(f,ae)}catch(Se){J.push({pluginName:Hk,text:`Cannot parse project's schemas/${bT.basename(F.path)} file. Error: ${Se.message}`,location:null,notes:[{text:Se.message,location:null}],detail:Se})}if(km.DEBUG_BUILD_MODE&&G){let Se=bT.relative(d,F.path),de=bT.join(o.sourceDirectory,Ng,`${Se}.js`);await Vk(de,G)}return{contents:G,errors:J,pluginName:Hk,resolveDir:bT.dirname(F.path),watchFiles:[F.path]}}))}}}t(L_t,"jsonSchemaPlugin");import{relative as _dr}from"node:path";var R_t=["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"],pdr="nodejs-compat-plugin";function M_t({sourceDirectory:o}){return{name:pdr,setup(s){let f=new Set;s.onStart(()=>{f.clear()}),s.onResolve({filter:/node:.*/},async({path:d,kind:y,resolveDir:x,...P})=>{let F=`${d}:${y}:${x}:${P.importer}`;if(f.has(F))return;f.add(F);let J=await s.resolve(d,{kind:y,resolveDir:x,importer:P.importer});return J.errors.length>0?R_t.includes(d)||d.includes("/")&&R_t.includes(d.split("/")[0])?{external:!0}:{external:!0,warnings:J.errors.map(Se=>({...Se,location:{file:_dr(o,P.importer),line:0,column:0,namespace:"",length:0,lineText:"",suggestion:"Remove the imported node module"},detail:`The package "${d}" wasn't found on the file system but is built into node. If this code is executed it will fail.`}))}:J})}}}t(M_t,"nodejsCompatPlugin");import j_t from"node:fs/promises";import UE from"node:path";var EI="open-api-routes-plugin",aG="open-api-routes-json";function B_t(o){return{name:"open-api-routes-plugin",setup(s){s.onResolve({filter:/zuplo:routes$/},f=>({watchFiles:[...r3e(UE.join(o.sourceDirectory,Ey),[".oas.json"],!0),UE.join(o.sourceDirectory,Ey,doe)],namespace:aG,path:UE.isAbsolute(f.path)?f.path:UE.join(f.resolveDir,f.path),pluginName:EI})),s.onResolve({filter:/^\.\.\/modules\/.*/,namespace:aG},async f=>Ou.timeFn("Generating route data...",async()=>{async function d(){let x=UE.resolve(o.sourceDirectory,"config"),P=await gO(x),F=`$import(.${f.path.replace(/^../,"")})`;return{location:await Qnt(P,F,"Update your route configuration to use code from the 'modules' folder"),originalImportValue:F}}t(d,"getLocation");let y=UE.join(f.resolveDir,`${f.path}.ts`);if(f.path.endsWith(".ts")){let{location:x,originalImportValue:P}=await d();return{errors:[{id:"route-build-error",text:`Invalid handler reference '${P}' in ${x?.file??"OpenAPI file"}. Imports must NOT include the '.ts' file extension.`,location:x,detail:"RouteReferenceError",pluginName:EI}],namespace:aG,path:f.path,pluginName:EI}}else if(!await tu.fileExists(y)){let{location:x,originalImportValue:P}=await d();return{errors:[{id:"route-build-error",text:`Invalid handler reference in route. Unable to resolve reference to '${P}' in ${x?.file??"OpenAPI file"}`,location:x,detail:"RouteReferenceError",pluginName:EI}],namespace:aG,path:f.path,pluginName:EI}}})),s.onLoad({filter:/.*/,namespace:aG},async f=>Ou.timeFn("Generating route.json data",async()=>{let d=UE.resolve(o.sourceDirectory,"config"),y=await gO(d),x=await Promise.all(y.map(async G=>({content:await j_t.readFile(G,"utf-8"),fileName:G}))),P=UE.resolve(d,"policies.json");if(!await tu.fileExists(P))return{errors:[{text:"The project must include a policies file ('/config/policies.json')",detail:"OASPoliciesFileMissing",pluginName:EI,location:{line:0,column:0,file:"/config/policies.json"}}],pluginName:EI};let F={content:await j_t.readFile(P,"utf-8"),fileName:P},J;try{J=await z4e({sourceDirectory:o.sourceDirectory,oasContent:x,policiesContent:F,compatibilityDate:o.config.compatibilityDate,allowDuplicateRoutes:o.config.allowDuplicateRoutes})}catch(G){throw new Error(`Error compiling routes: ${G.message}`)}if(km.DEBUG_BUILD_MODE&&J.content){let G=UE.join(o.sourceDirectory,Ng),Se=UE.resolve(G,"routes.js");await Vk(Se,J.content)}return{contents:J.content,errors:J.errors,pluginName:EI,resolveDir:UE.dirname(f.path),watchFiles:[f.path]}}))}}}t(B_t,"openApiRoutesPlugin");import Qle from"node:path";var oG="raw-route-plugin",U_t="raw-route";function z_t(o){return{name:"raw-route-plugin",setup(s){s.onResolve({filter:/zuplo:raw-routes$/},f=>({namespace:U_t,path:f.path,pluginName:oG})),s.onLoad({filter:/.*/,namespace:U_t},async f=>Ou.timeFn("Building route data",async()=>{let d=Qle.resolve(o.sourceDirectory,Ey);if(!await tu.dirExists(d))return{loader:"js",resolveDir:Qle.dirname(f.path),pluginName:oG};let y=await gO(d);try{let x=await W4e({oasFiles:y,sourceDirectory:o.sourceDirectory,logger:o.logger});if(km.DEBUG_BUILD_MODE&&x){let P=Qle.join(o.sourceDirectory,Ng,"raw-routes.js");await Vk(P,x)}return{contents:x,loader:"js",resolveDir:Qle.dirname(f.path),pluginName:oG}}catch(x){if(x instanceof D1)return{contents:"",loader:"ts",errors:[{id:"route-build-error",text:x.issue.text,location:x.issue.location,detail:x.issue.detail,pluginName:oG}],pluginName:oG};throw x}}))}}}t(z_t,"rawRoutePlugin");import ddr from"node:fs/promises";import $_t from"node:path";var eue="runtime-extensions-plugin",J_t="runtime-extensions";function W_t(o){return{name:eue,setup(s){s.onResolve({filter:/zuplo:runtime-extension$/},f=>({namespace:J_t,path:f.path,pluginName:eue})),s.onLoad({filter:/.*/,namespace:J_t},async()=>Ou.timeFn("Generating zuplo.runtime.ts data",async()=>{let f="export const runtimeInit = undefined;",d=$_t.resolve(o.sourceDirectory,Srt,"zuplo.runtime.ts"),y=[];return await tu.fileExists(d)?(f=await ddr.readFile(d,"utf-8"),{contents:f,loader:"ts",resolveDir:$_t.dirname(d),errors:y,pluginName:eue,watchFiles:[d]}):{contents:f,loader:"ts",errors:y,pluginName:eue}}))}}}t(W_t,"runtimeExtensionsPlugin");import q_t from"node:path";import{readFile as mdr}from"node:fs/promises";import CI from"node:path";var VM=class extends Error{static{t(this,"DevPortalConfigError")}filename;constructor(s,f){super(s,f),this.name="DevPortalConfigError",this.filename=f?.filename}};async function n3e(o){let s=["zudoku.config.tsx","zudoku.config.ts","zudoku.config.js","zudoku.config.jsx","zudoku.config.mjs"];for(;s.length;){let P=s.pop();if(P){let F=CI.join("docs",P),J=CI.join(o,F);try{if(await tu.fileExists(J))return{enabled:!0,type:"zudoku",basePath:void 0,filepath:F}}catch(G){throw new VM("Failed to read dev portal configuration file.",{cause:G,filename:F})}}}let f=CI.join(Ey,xrt),d=CI.join(o,f),y=!0,x;if(await tu.fileExists(d)){try{let P=await mdr(d,"utf-8"),F=JSON.parse(P);F.enabled===!1&&(y=!1),x=F.sitePathname}catch(P){throw new VM("Failed to parse dev-portal.json file.",{cause:P,filename:f})}return{enabled:y,type:"legacy",basePath:x,filepath:f}}return{enabled:!1,type:void 0,basePath:void 0,filepath:void 0}}t(n3e,"getDevPortalConfig");function HM(o,s){let f=CI.resolve(o,_O);return Object.keys(s?.outputs??{}).map(x=>{let P=CI.normalize(x);return`./${CI.relative(f,P).split(CI.sep).join("/")}`})}t(HM,"getBuildModules");var V_t="/docs",hdr="/__zuplo/dev-portal";function gdr(o){let s=o.trim().toLowerCase();return s.endsWith("/")&&(s=s.slice(0,-1)),s}t(gdr,"normalizePathname");function ydr(o,s){let d={developerPortal:{basePath:o?.basePath===hdr?V_t:o?.basePath?gdr(o.basePath):V_t,enabled:o?o.enabled??!0:!1,type:o?.type??void 0,urls:o?.urls?{defaultUrl:o.urls.defaultUrl,urls:o.urls.urls.map(x=>new URL(x).origin)}:void 0},api:s};return`const runtimeSettings = ${JSON.stringify(d)};
606
606
  export default runtimeSettings;`}t(ydr,"generateSource");var cG="runtime-settings-plugin",tue="runtime-settings";function H_t(o){return{name:cG,setup(s){s.onResolve({filter:/zuplo:runtime-settings$/},f=>({namespace:tue,path:f.path,pluginName:cG})),s.onLoad({filter:/.*/,namespace:tue},async()=>Ou.timeFn("Generating runtime settings",async()=>{let f=[],d,y;try{let F=await n3e(o.sourceDirectory);y=F.filepath,d={...F,urls:o.urls?.devPortal}}catch(F){let J="Failed to load dev portal config",G="config/dev-portal.json";F instanceof VM&&(J=F.message,G=F.filename??G),f.push({id:"dev-portal-build-error",text:J,location:{file:G,namespace:tue,line:1,column:0,length:0,lineText:"",suggestion:""},detail:"DevPortalValidationError",pluginName:cG,notes:[{text:F.message,location:null}]})}let x={urls:o.urls?.api},P;try{if(P=ydr(d,x),km.DEBUG_BUILD_MODE&&P){let F=q_t.join(o.sourceDirectory,Ng,"dev-portal.js");await Vk(F,P)}}catch(F){f.push({id:"dev-portal-build-error",text:F.message,location:{file:"dev-portal.json",namespace:tue,line:1,column:0,length:0,lineText:"issue",suggestion:""},detail:"DevPortalValidationError",pluginName:cG,notes:[{text:F.message,location:null}]})}return{contents:P,errors:f,pluginName:cG,loader:"js",resolveDir:y?q_t.dirname(y):void 0}}))}}}t(H_t,"runtimeSettingsPlugin");import a3e from"node:fs/promises";import $O from"node:path";var Y_t=Dp(Mle(),1),K_t=Dp(t3e(),1);var i3e="schema-validation-plugin",G_t="schema-validation",vdr="module.exports = {}";function X_t(o){return{name:"schema-validation-plugin",setup(s){s.onResolve({filter:/zuplo:schema-validations$/},f=>({namespace:G_t,path:f.path,pluginName:i3e})),s.onLoad({filter:/.*/,namespace:G_t},async()=>Ou.timeFn("Validating schemas",async()=>{let f=$O.resolve(o.sourceDirectory,Ey,"policies.json");if(!await tu.fileExists(f))return{contents:vdr,loader:"js",resolveDir:$O.dirname(f),pluginName:i3e};let d=await Sdr(o.sourceDirectory),y=$O.resolve(o.sourceDirectory,Ey),x=await gO(y),P=await Cdr(x,d),F=await bdr({oasFiles:x,routesWithSchemaValidation:P,sourceDirectory:o.sourceDirectory,logger:o.logger});if(km.DEBUG_BUILD_MODE&&F){let J=$O.join(o.sourceDirectory,Ng,"schema-validation.js");await Vk(J,F)}return{contents:F,loader:"js",resolveDir:$O.dirname(f),pluginName:i3e}}))}}}t(X_t,"schemaValidationPlugin");async function bdr({oasFiles:o,routesWithSchemaValidation:s,sourceDirectory:f,logger:d}){let y="",x=new sI(f,d);if(s.length===0)return y;let P=new Y_t.Ajv2020({code:{source:!0},allErrors:!0,strict:!1,verbose:!0,meta:!0});for(let F of o){let J=await a3e.readFile(F,"utf-8"),G=$O.basename(F,".oas.json"),Se=s.filter(Fe=>Fe.fileName===G),de=await x.resolve(F),ae=JSON.parse(J),Ke=[],$e=new Map;Se.forEach(Fe=>{let Gt=ae.paths[Fe.path][Fe.method];if(Gt.requestBody){let jt;if(Gt.requestBody.$ref){let Pr=Gt.requestBody.$ref;jt=de.get(Pr)?.content}else Gt.requestBody.content&&(jt=Gt.requestBody.content);if(jt)for(let Pr in jt){let Fn=jt[Pr].schema,sn=j6e(Fe.path,Fe.method,Pr);Fn.$id=sn,P.addSchema(Fn),s3e(Fn,F,G,P,de,Ke,$e)}}if(Gt.parameters)for(let jt of Gt.parameters){let Pr=jt.$ref?de.get(jt.$ref):jt,Fn=Pr.schema.$ref?de.get(Pr.schema.$ref):Pr.schema,sn=M6e(Fe.path,Fe.method,Pr.in,Pr.name);Fn.$id=sn,P.addSchema(Fn),s3e(Pr,F,G,P,de,Ke,$e)}});for(let Fe of Ke){let Gt=de.get(Fe),jt=oH(G,Fe);P.addSchema(Gt,jt)}}return y=(0,K_t.default)(P),y}t(bdr,"schemaValidationSource");function s3e(o,s,f,d,y,x,P){for(let F in o){let J=o[F];if(F==="$ref"){let G=oH(f,XN(s,J));o[F]=G,UV(s,f,XN(s,J),y,x,P,(Se,de,ae)=>oH(Se,XN(ae,de)))}else typeof J=="object"&&s3e(J,s,f,d,y,x,P)}}t(s3e,"addRefsToSchema");async function Sdr(o){let s=new Set(["RequestValidationInboundPolicy"]),f=await a3e.readFile(`${o}/config/policies.json`,"utf-8"),d=JSON.parse(f);return Tdr(d,s)}t(Sdr,"getPolicyNamesUsingSchemaValidationPolicies");function Tdr(o,s){let f=new Set;o.policies?.forEach(y=>{y.handler?.export&&s.has(y.handler.export)&&y.handler.module==="$import(@zuplo/runtime)"&&f.add(y.name)});let d=xdr(o,f);return new Set([...f,...d])}t(Tdr,"getPolicyNamesReferencingPolicyHandlers");function xdr(o,s){let f=new Set;return o.policies?.forEach(d=>{d.handler?.export==="CompositeInboundPolicy"&&d.handler?.options?.policies?.forEach(y=>{s.has(y)&&f.add(d.name)})}),f}t(xdr,"getCompositePoliciesContainingPolicy");function Edr(o,s){if(!o["x-zuplo-route"]||!o["x-zuplo-route"].policies)return!1;let f=o["x-zuplo-route"].policies.inbound;if(f){for(let y of f)if(s.has(y))return!0}let d=o["x-zuplo-route"].policies.outbound;if(d){for(let y of d)if(s.has(y))return!0}return!1}t(Edr,"isPolicyPresentInOperation");async function Cdr(o,s){let f=[];for(let d of o){let y=await a3e.readFile(d,"utf-8"),P=JSON.parse(y).paths;for(let F in P){let J=P[F];for(let G in J){let Se=J[G];Edr(Se,s)&&f.push({fileName:$O.basename(d,".oas.json"),path:F,method:G})}}}return f}t(Cdr,"getRoutesContainingPolicies");import{mkdirSync as kdr,writeFileSync as wdr}from"node:fs";import Ddr from"node:path";function Z_t(o){return{name:"write-modules-plugin",setup(s){s.onEnd(async f=>{if(f){let d=HM(o.sourceDirectory,f.metafile);kdr(o.outputDirectory,{recursive:!0}),wdr(Ddr.join(o.outputDirectory,"modules.json"),JSON.stringify(d,null,2))}})}}}t(Z_t,"writeModulesPlugin");var Pdr=Sce("zuplo:core:build"),Adr=["workerd","worker","browser"],tpt=[...process.env.GLOBAL_MODULE_LOCATION?[process.env.GLOBAL_MODULE_LOCATION]:[],o3e.resolve(Q_t(ept(import.meta.url)),"..","..","..","node_modules"),o3e.resolve(Q_t(ept(import.meta.url)),"..","..","..","..","..","node_modules")];async function lG({systemDirectory:o,outputDirectory:s,sourceDirectory:f,cacheDirectory:d,logger:y,minify:x=!0,command:P,config:F,urls:J}){let G=o3e.join(o,hoe);Pdr(`Building with node paths: ${tpt.join(", ")}`);let Se=x&&P!=="dev"&&!process.env.DEBUG_BUILD_DISABLE_MINIFY?{minify:!0,chunkNames:"[hash]"}:{minify:!1,keepNames:!0,chunkNames:"[name]-[hash]"},de=Object.freeze({sourceDirectory:f,outputDirectory:s,cacheDirectory:d,logger:y,debugMode:km.DEBUG_BUILD_MODE,config:F,urls:J});return{platform:"browser",target:"es2022",outdir:s,splitting:!0,metafile:!0,format:"esm",nodePaths:tpt,entryPoints:[G],sourcemap:"linked",legalComments:"none",treeShaking:!0,bundle:!0,...Se,external:[],logLevel:"silent",conditions:Adr,plugins:[m_t(de),f_t(de),B_t(de),z_t(de),X_t(de),W_t(de),H_t(de),L_t(de),M_t(de),Z_t(de)]}}t(lG,"getBaseESBuildConfig");var JO="run-esbuild",npt=t(async function({systemDirectory:o,outputDirectory:s,sourceDirectory:f,cacheDirectory:d,buildId:y,logger:x,config:P,command:F,minify:J,urls:G},{data:Se}){x.debug("Running esbuild");let de=await lG({command:F,minify:J,systemDirectory:o,outputDirectory:s,cacheDirectory:d,sourceDirectory:f,logger:x,config:P,urls:G}),ae;try{if(!await X9(f))throw new Error("Failed to build project because no open-api file was found on the 'config' folder");ae=await rpt.build(de),Se.set("metafile",ae.metafile)}catch(Fe){if(x.error(Fe),Fe.errors||Fe.warnings)ae=Fe;else if(Fe.message.includes("Failed to build project because no open-api file was found on the 'config' folder"))ae={warnings:[],errors:[{id:"missing-open-api-file",text:"Failed to build project because no open-api file was found on the 'config' folder",pluginName:JO,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 Fe}ae.errors.length>0&&ae.errors.length>1&&(ae.errors.length=1);let{errors:Ke,warnings:$e}=c3e({buildId:y,result:ae});return{errors:Ke,warnings:$e}},"runEsbuild");function c3e({buildId:o,result:s}){return{status:s.errors.length>0?"Failed":s.warnings.length>0?"Warnings":"Good",runtimeVersion:"0.0.0",buildTime:"",buildTimeMs:0,buildId:o,warnings:s.warnings.map(d=>d.text==="Using direct eval with a bundler is not recommended and may cause problems"?{location:d.location,detail:d.detail,id:d.id,notes:d.notes,message:"We do not support the use of 'eval' or 'new Function(...)'",severity:loe,pluginName:d.pluginName||JO}:{location:d.location,detail:d.detail,id:d.id,notes:d.notes,message:d.text,severity:loe,pluginName:d.pluginName||JO}),errors:s.errors.map(d=>({location:d.location,detail:d.detail,id:d.id,notes:d.notes,message:d.text,severity:xPe,pluginName:d.pluginName||JO})),metafile:s.metafile}}t(c3e,"esbuildResultToBuildResult");var Ndr=t((o,s)=>{let f=s;if(s.includes(o)){let d=new RegExp(`.*(${o})`,"g");f=s.replace(d,"")}return f.match(/^(\/)?(\.\.(\/)?)+/)&&(f=f.replace(/^(\/)?(\.\.(\/)?)+/,"/")),f},"removePrefixFromString"),Idr=t((o,s)=>{let f=s;if(f.includes(o)){let d=new RegExp(`[a-zA-Z0-9-_.\\/]+(${o})`,"g");f=f.replace(d,"")}return f},"cleanFilePathsInMessage"),ipt=t((o,s,f)=>{if(!o||o.length<=0)return o;let d=o.filter(y=>y.message!=='Could not resolve "@zuplo/runtime"');return d&&d.length>0&&d.forEach(y=>{try{y.location?.file&&(y.location.file=Ndr(s,y.location.file)),y.location?.lineText?.includes("@zuplo/core/index.minified.js")&&(y.location.lineText=`${y.location.lineText.substring(0,200)}...<Truncated>`),y.message=Idr(s,y.message),y.notes&&y.notes.length>0&&delete y.notes,y.text&&delete y.text,y.pluginName===""&&(y.pluginName=f)}catch{}}),d},"cleanDataOnBuildIssue");function spt(o,s){let f=l3e.basename(s);o.errors&&(o.errors=ipt(o.errors,f,JO)),o.warnings&&(o.warnings=ipt(o.warnings,f,JO))}t(spt,"formatBuildResult");var Odr=t(o=>l3e.basename(o).startsWith("."),"isHiddenOnUnix"),Fdr=t((o,s=[])=>s.map(f=>f.startsWith(".")?f:`.${f}`).some(f=>o.endsWith(f)),"hasMatchingExtname");function r3e(o,s=[],f=!1){let d=[],y;if(!rue.existsSync(o)){let x;if(RV.hasMagic(o))x=o;else{let P=s.map(F=>F.startsWith(".")?F:`.${F}`).join("|");x=`${o}+(${P})`}if(d.push(...RV.sync(x,{nodir:!0})),!d.length)throw Error(`Cannot find any files matching pattern "${o}"`);return d}try{if(y=rue.statSync(o),y.isFile())return[o]}catch{return[]}return rue.readdirSync(o).forEach(x=>{let P=l3e.join(o,x),F;try{if(F=rue.statSync(P),F.isDirectory()){f&&d.push(...r3e(P,s,f));return}}catch{return}if(!s.length)throw Error(`Argument '${s}' required when argument '${o}' is a directory`);!F.isFile()||!Fdr(P,s)||Odr(P)||d.push(P)}),d}t(r3e,"lookupFiles");var ST=new _oe,Gk=` ${ST.gray("|")} `;function TOr(o,s){o.info(ST.green(s))}t(TOr,"outputSuccess");function xOr(o,s){o.warn(ST.yellow(s))}t(xOr,"outputWarning");function EOr(o,s){o.error(`
607
607
  ${ST.red(s)}`)}t(EOr,"outputCritical");function COr(o,s,f){let d=f.sort((P,F)=>{let J=P.path.split("/").length,G=F.path.split("/").length;return J!==G?J-G:P.path.localeCompare(F.path)}),y=Math.max(...d.map(P=>P.path.length)),x=`${s}
608
608
  `;d.forEach(P=>{let F=" ".repeat(y-P.path.length),J=P.bytes/1024,G=` ${P.path}${F} ${J.toFixed(2)} KB
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuplo/core",
3
- "version": "6.63.11",
3
+ "version": "6.63.13",
4
4
  "repository": "https://github.com/zuplo/zuplo",
5
5
  "author": "Zuplo, Inc.",
6
6
  "type": "module",
@@ -40,9 +40,9 @@
40
40
  "source-map": "^0.7.4"
41
41
  },
42
42
  "peerDependencies": {
43
- "@zuplo/graphql": "6.63.11",
44
- "@zuplo/otel": "6.63.11",
45
- "@zuplo/runtime": "6.63.11",
43
+ "@zuplo/graphql": "6.63.13",
44
+ "@zuplo/otel": "6.63.13",
45
+ "@zuplo/runtime": "6.63.13",
46
46
  "deno": "2.3.1"
47
47
  }
48
48
  }