@zuplo/core 7.9.17 → 7.9.19
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.
- package/customer.cli.minified.js +1 -1
- package/index.minified.js +1 -1
- package/package.json +4 -4
package/customer.cli.minified.js
CHANGED
|
@@ -572,7 +572,7 @@ globstar while`,s,le,o,se,tt),this.matchOne(s.slice(le),o.slice(se),f))return th
|
|
|
572
572
|
`),stderr:E.join(`
|
|
573
573
|
`),exitCode:A},"Tar process logs")}}t(JXt,"tarFolder");async function $Xt({tarFilePath:s,outputDir:o,logger:f}){let d=[],y=[],E;try{await new Promise((A,R)=>{let q=sit("sh",["-c",`tar -xvf ${s} -C ${o};`]);q.stdout.on("data",K=>{let ye=K.toString().trim();ye.length>0&&d.push(ye.trim())}),q.stderr.on("data",K=>{let ye=K.toString().trim();ye.length>0&&y.push(ye.trim())}),q.on("close",K=>{E=K,K===0?A():R(new Error(`tar process exited with code ${K}`))}),q.on("error",K=>{R(K)})})}catch(A){throw new Error("Failed to untar file",{cause:A})}finally{f.info({stdout:d.join(`
|
|
574
574
|
`),stderr:y.join(`
|
|
575
|
-
`),exitCode:E},"Untar process logs")}}t($Xt,"untarFile");async function WXt(s){if(await QPe(s))return await qN.rm(s,{recursive:!0})}t(WXt,"deleteFolder");var nu=eAe;var Qct=wp(Dst(),1);import{AssertionError as ger}from"node:assert";function UP(s,o){if(s===!1)throw new ger({message:o})}t(UP,"assert");var qo;(function(s){s.Object="Object",s.Property="Property",s.Array="Array",s.Literal="Literal",s.TemplateString="TemplateString",s.Identifier="Identifier",s.FunctionCall="FunctionCall",s.Raw="Raw"})(qo||(qo={}));function H9(s){return s.type===qo.Object}t(H9,"isAstObject");function zP(s){return s.type===qo.Property}t(zP,"isAstProperty");function FAe(s){return s.type===qo.Array}t(FAe,"isAstArray");function fO(s){return s.type===qo.Literal}t(fO,"isAstLiteral");function GN(s){if(s===void 0)throw new Error("Node is undefined");if(!H9(s))throw new Error("Node is not object")}t(GN,"assertAstObject");import{findNodeAtLocation as yer,getNodeValue as ver,printParseErrorCode as ber,visit as Ser}from"jsonc-parser";var Ter={DEFAULT:{allowTrailingComma:!1}};function JV(s,o=[],f=Ter.DEFAULT){let d={type:"array",offset:-1,length:-1,line:-1,column:-1,children:[],parent:void 0};function y(q){d.type==="property"&&(d.length=q-d.offset,d=d.parent)}t(y,"ensurePropertyComplete");function E(q){return d.children?.push(q),q}t(E,"onValue"),Ser(s,{onObjectBegin:t((q,K,ye,le)=>{d=E({type:"object",offset:q,length:-1,line:ye+1,column:le+1,parent:d,children:[]})},"onObjectBegin"),onObjectProperty:t((q,K,ye,le,se)=>{d=E({type:"property",offset:K,length:-1,line:le+1,column:se+1,parent:d,children:[]}),d.children?.push({type:"string",value:q,offset:K,length:ye,line:le,column:se,parent:d})},"onObjectProperty"),onObjectEnd:t((q,K)=>{y(q+K),d.length=q+K-d.offset,d=d.parent,y(q+K)},"onObjectEnd"),onArrayBegin:t((q,K,ye,le)=>{d=E({type:"array",offset:q,length:-1,line:ye+1,column:le+1,parent:d,children:[]})},"onArrayBegin"),onArrayEnd:t((q,K)=>{d.length=q+K-d.offset,d=d.parent,y(q+K)},"onArrayEnd"),onLiteralValue:t((q,K,ye,le,se)=>{E({type:xer(q),offset:K,length:ye,line:le+1,column:se+1,parent:d,value:q}),y(K+ye)},"onLiteralValue"),onSeparator:t((q,K)=>{d.type==="property"&&(q===":"?d.colonOffset=K:q===","&&y(K))},"onSeparator"),onError:t((q,K,ye,le,se)=>{o.push({error:q,offset:K,length:ye,line:le+1,column:se+1})},"onError")},f);let R=d.children?.[0];return R&&delete R.parent,R}t(JV,"parse");function xer(s){switch(typeof s){case"boolean":return"boolean";case"number":return"number";case"string":return"string";case"object":{if(s){if(Array.isArray(s))return"array"}else return"null";return"object"}default:return"null"}}t(xer,"getNodeType");function G9(s,o){return yer(s,o)}t(G9,"findNodeAtLocation");function $V(s){return ver(s)}t($V,"getNodeValue");function Pst(s){return ber(s)}t(Pst,"printParseErrorCode");var WV=class{static{t(this,"AstAdapter")}parse(o){let d=JV(o,[]);if(d)return this.parseNode(d,void 0);throw new Error("Failed to parse JSON")}convert(o){return this.parseNode(o,void 0)}parseNode(o,f){switch(o.type){case"object":return this.createObject(o,f);case"array":return this.createArray(o,f);case"property":return this.createProperty(o,f);case"string":return this.createLiteral(o,f);case"number":return this.createLiteral(o,f);case"boolean":return this.createLiteral(o,f);case"null":return this.createLiteral(o,f)}}createLiteral(o,f){return{type:qo.Literal,location:{line:o.line,column:o.column},parent:f,value:o.type==="null"?null:o.value}}createObject(o,f){let d={type:qo.Object,children:[],parent:f,location:{line:o.line,column:o.column}};return o.children?.forEach(y=>{d.children.push(this.parseNode(y,d))}),d}createProperty(o,f){UP(o.children?.length===2,"Invalid property node");let d={type:qo.Property,location:{line:o.line,column:o.column},parent:f,name:null,value:null};return d.name={value:o.children[0].value,location:{line:o.line,column:o.column},type:qo.Identifier,parent:d},d.value=this.parseNode(o.children[1],d),d}createArray(o,f){let d={type:qo.Array,location:{line:o.line,column:o.column},parent:f,children:[]};return o.children?.forEach(y=>d.children.push(this.parseNode(y,d))),d}};var PS={createLiteral:t((s,o)=>({type:qo.Literal,parent:o,value:s}),"createLiteral"),createTemplateString:t((s,o)=>({type:qo.TemplateString,parent:o,value:s}),"createTemplateString"),createIdentifier:t((s,o)=>({type:qo.Identifier,value:s,parent:o}),"createIdentifier"),createProperty:t((s,o,f)=>{let d={type:qo.Property,parent:f,name:null,value:o};return d.name={value:s,type:qo.Identifier,parent:d},d.value.parent=d,d},"createProperty"),createArrayOfLiterals:t((s,o)=>{let f={type:qo.Array,parent:o,children:[]};for(let d of s)f.children.push(PS.createLiteral(d,f));return f},"createArrayOfLiterals")};var Eer=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/,qV=class{static{t(this,"SourceGenerator")}generate(o){let f=[];return this.generateSource(f,o),f.join("")}generateSource(o,f){switch(f.type){case qo.Array:return this.generateArray(o,f);case qo.Object:return this.generateObject(o,f);case qo.Property:return this.generateProperty(o,f);case qo.Literal:return this.generateLiteral(o,f);case qo.FunctionCall:return this.generateFunctionCall(o,f);case qo.Identifier:return this.generateIdentifier(o,f);case qo.Raw:return this.generateRaw(o,f);case qo.TemplateString:return this.generateTemplateString(o,f)}}generateArray(o,f){o.push("["),f.children.map(d=>{this.generateSource(o,d),o.push(",")}),o.push("]")}generateObject(o,f){o.push("{"),f.children.forEach(d=>{this.generateSource(o,d),o.push(",")}),o.push("}")}generateProperty(o,f){this.generateIdentifier(o,f.name),o.push(":"),this.generateSource(o,f.value)}generateFunctionCall(o,f){o.push(f.name.value),o.push("("),f.children.forEach((d,y,E)=>{this.generateSource(o,d),y<E.length&&o.push(",")}),o.push(")")}generateRaw(o,f){o.push(f.value)}generateTemplateString(o,f){o.push("`"),o.push(f.value.replaceAll("`","\\`")),o.push("`")}generateLiteral(o,f){if(f.value===null)return o.push("null");switch(typeof f.value){case"number":case"boolean":return o.push(`${f.value}`);case"string":{let d=f.value,y=JSON.stringify(d);return o.push(`${y}`)}}}generateIdentifier(o,f){let d=Eer.test(f.value)?f.value:`'${f.value}'`;o.push(d)}};import Cer from"node:fs/promises";import{parse as ker}from"@swc/core";var Ast=t(async s=>{let o=new Set;try{let f=await Cer.readFile(s,"utf-8");(await ker(f,{syntax:"typescript"})).body.forEach(y=>{y.type==="ExportDefaultDeclaration"||y.type==="ExportDefaultExpression"?o.add("default"):y.type==="ExportDeclaration"&&y.declaration.type==="FunctionDeclaration"?o.add(y.declaration.identifier.value):y.type==="ExportDeclaration"&&y.declaration.type==="VariableDeclaration"&&y.declaration.declarations[0].id.type==="Identifier"&&o.add(y.declaration.declarations[0].id.value)})}catch{return null}return o},"getJSFileExports");var Nst=["ai-gateway-akamai-firewall","ai-gateway-auth","ai-gateway-configuration-executor","ai-gateway-configuration-loader","ai-gateway-dlp","ai-gateway-fallback-model","ai-gateway-galileo-tracing","ai-gateway-metering","ai-gateway-model-filtering","ai-gateway-model-override","ai-gateway-opik-tracing","ai-gateway-prompt-injection","ai-gateway-semantic-cache","ai-gateway-smart-router","akamai-firewall-for-ai","prompt-injection","semantic-cache"],Ist={"ai-gateway-akamai-firewall-inbound":"ai-gateway-akamai-firewall","ai-gateway-auth-inbound":"ai-gateway-auth","ai-gateway-auth-v2":"ai-gateway-auth","ai-gateway-auth-v2-inbound":"ai-gateway-auth","ai-gateway-configuration-executor-inbound":"ai-gateway-configuration-executor","ai-gateway-configuration-executor-v2":"ai-gateway-configuration-executor","ai-gateway-configuration-executor-v2-inbound":"ai-gateway-configuration-executor","ai-gateway-configuration-loader-inbound":"ai-gateway-configuration-loader","ai-gateway-configuration-loader-v2":"ai-gateway-configuration-loader","ai-gateway-configuration-loader-v2-inbound":"ai-gateway-configuration-loader","ai-gateway-dlp-inbound":"ai-gateway-dlp","ai-gateway-fallback-model-inbound":"ai-gateway-fallback-model","ai-gateway-fallback-model-v2":"ai-gateway-fallback-model","ai-gateway-fallback-model-v2-inbound":"ai-gateway-fallback-model","ai-gateway-galileo-tracing-inbound":"ai-gateway-galileo-tracing","ai-gateway-metering-inbound":"ai-gateway-metering","ai-gateway-metering-v2":"ai-gateway-metering","ai-gateway-metering-v2-inbound":"ai-gateway-metering","ai-gateway-model-filtering-inbound":"ai-gateway-model-filtering","ai-gateway-model-filtering-v2":"ai-gateway-model-filtering","ai-gateway-model-filtering-v2-inbound":"ai-gateway-model-filtering","ai-gateway-model-override-inbound":"ai-gateway-model-override","ai-gateway-opik-tracing-inbound":"ai-gateway-opik-tracing","ai-gateway-semantic-cache-inbound":"ai-gateway-semantic-cache","ai-gateway-semantic-cache-inbound-v2":"ai-gateway-semantic-cache","ai-gateway-semantic-cache-v2":"ai-gateway-semantic-cache","ai-gateway-semantic-cache-v2-inbound":"ai-gateway-semantic-cache","ai-gateway-smart-router-inbound":"ai-gateway-smart-router","akamai-ai-firewall-inbound-v2":"ai-gateway-akamai-firewall","akamai-ai-firewall-v2":"ai-gateway-akamai-firewall","akamai-ai-firewall-v2-inbound":"ai-gateway-akamai-firewall","akamai-firewall-for-ai-inbound":"akamai-firewall-for-ai","akamai-firewall-for-ai-outbound":"akamai-firewall-for-ai","comet-opik-tracing-inbound-v2":"ai-gateway-opik-tracing","comet-opik-tracing-v2":"ai-gateway-opik-tracing","comet-opik-tracing-v2-inbound":"ai-gateway-opik-tracing","galileo-tracing-inbound-v2":"ai-gateway-galileo-tracing","galileo-tracing-v2":"ai-gateway-galileo-tracing","galileo-tracing-v2-inbound":"ai-gateway-galileo-tracing","prompt-injection-outbound":"prompt-injection","semantic-cache-inbound":"semantic-cache"};var Ost={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/fragments.schema.json",$defs:{corsPolicyConfiguration:{type:"object",required:["name","allowedOrigins"],additionalProperties:!1,properties:{name:{type:"string",pattern:"^[0-9a-z-]+$"},allowCredentials:{type:"boolean"},maxAge:{type:"number"},allowedOrigins:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]},allowedMethods:{oneOf:[{type:"array",items:{$ref:"fragments.schema.json#/$defs/httpMethod"}},{type:"string"}]},allowedHeaders:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]},exposeHeaders:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]}}},handlerDefinition:{type:"object",properties:{module:{type:"string",pattern:"^\\$import\\([^ )]*?\\)$"},export:{type:"string"},options:{type:"object",additionalProperties:!0}},additionalProperties:!1,required:["module","export"]},httpMethod:{type:"string",enum:["GET","HEAD","POST","PUT","DELETE","CONNECT","OPTIONS","TRACE","PATCH"]}}};var LAe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/policies.schema.json",title:"Policies Config File",type:"object",additionalProperties:!1,properties:{policies:{type:"array",items:{$ref:"policy-configuration.schema.json"}},corsPolicies:{type:"array",items:{$ref:"fragments.schema.json#/$defs/corsPolicyConfiguration"}}}};var Fst={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/policy-configuration.schema.json",title:"Policy Configuration Fragment",type:"object",required:["name","policyType","handler"],additionalProperties:!1,properties:{name:{type:"string",pattern:"^[0-9a-z-]+$"},policyType:{type:"string"},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},options:{type:"object",additionalProperties:!0}}};var RAe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/route-configuration.schema.json",title:"Route Configuration Fragment",description:"",type:"object",required:["path","methods","handler"],additionalProperties:!1,$defs:{corsPolicy:{type:"string",pattern:"^[0-9a-z-]+$"}},properties:{operationId:{type:"string"},path:{type:"string",pattern:"^/[^\\s]*$"},methods:{type:"array",items:{$ref:"fragments.schema.json#/$defs/httpMethod"}},label:{type:"string",description:"An internal user-friendly identifier of the route."},enforceOpenApi:{type:"boolean",description:"If true, schema validation found in the OpenAPI spec will be enforced on requests/responses."},key:{type:"string",deprecated:!0},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},corsPolicy:{$ref:"#/$defs/corsPolicy"},custom:{},mcp:{type:"object",additionalProperties:!1,properties:{enabled:{type:"boolean"}}},policies:{type:"object",additionalProperties:!1,properties:{inbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}},outbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}}}},summary:{type:"string"},description:{type:"string"},excludeFromOpenApi:{type:"boolean"},tags:{type:"array",items:{type:"string"}}}};var MAe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/route-configuration-open-api.schema.json",title:"Open API Route Configuration Fragment",description:"These are the properties that can appear under the x-zuplo-route extension in a PathObject in Open API. It's a subset of what can appear in Zuplo's routes.json.",type:"object",required:["handler"],additionalProperties:!1,properties:{label:{type:"string",description:"An internal user-friendly identifier of the route."},key:{type:"string",deprecated:!0},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},corsPolicy:{type:"string",pattern:"^[0-9a-z-]+$"},custom:{},mcp:{oneOf:[{type:"object",additionalProperties:!1,properties:{type:{const:"tool"},name:{type:"string"},description:{type:"string"},enabled:{type:"boolean"},includeOutputSchema:{type:"boolean"},includeStructuredContent:{type:"boolean"},toolInputStyle:{enum:["flat","nested"]},annotations:{type:"object",additionalProperties:!1,properties:{title:{type:"string"},readOnlyHint:{type:"boolean"},destructiveHint:{type:"boolean"},idempotentHint:{type:"boolean"},openWorldHint:{type:"boolean"}}},_meta:{type:"object",additionalProperties:!0}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"prompt"},name:{type:"string"},description:{type:"string"},enabled:{type:"boolean"}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"resource"},name:{type:"string"},description:{type:"string"},uri:{type:"string"},mimeType:{type:"string"},enabled:{type:"boolean"},_meta:{type:"object",additionalProperties:!0}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"graphql"},enabled:{type:"boolean"},introspectionTool:{type:"object",additionalProperties:!1,properties:{name:{type:"string"},description:{type:"string"}}},executeTool:{type:"object",additionalProperties:!1,properties:{name:{type:"string"},description:{type:"string"}}}},required:["type"]}]},policies:{type:"object",additionalProperties:!1,properties:{inbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}},outbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}}}},tags:{type:"array",items:{type:"string"}}}};var $ct=wp(Kce(),1),Wct=wp(ele(),1);var tle=class s{static{t(this,"JsonValidator")}static#e=new s;static get instance(){return s.#e}ajv;constructor(){this.ajv=new $ct.Ajv2020({allErrors:!0,allowUnionTypes:!0}),this.ajv.addKeyword("faker"),(0,Wct.default)(this.ajv,{mode:"fast"})}addSchema(o,f){this.ajv.addSchema(o,f)}compile(o){let f=this.ajv.compile(o);return t(y=>({isValid:f(y),errors:this.toSimpleErrors(f.errors,y),warnings:[]}),"validator")}toSimpleErrors(o,f){let d=[];return o?.forEach(y=>{y.keyword==="enum"&&y.params.allowedValues&&Array.isArray(y.params.allowedValues)&&(y.message+=`; ${y.params.allowedValues.join(", ")}`),y.instancePath&&(y.instancePath=y.instancePath.replaceAll(/(\/)?(~1)(\/)?/gm,"/"));let E={details:{}},A=y.instancePath.split("/");if(A.length>2){let q=A[1],K=A[2]?parseInt(A[2],10):0,ye=A[3],le=Number.isNaN(K)?void 0:f[q][K][ye];E={details:{property:q,index:K,field:ye,fieldValue:le}}}if(y.keyword==="required"&&y.params.missingProperty&&y.instancePath&&(y.message=`A 'path' is missing required property '${y.params.missingProperty}'`),y.keyword==="additionalProperties"&&y.params.additionalProperty&&y.instancePath&&(y.message=`A 'path' should NOT include property '${y.params.additionalProperty}'`),y.keyword==="type"&&y.params.type&&y.instancePath){let q=y.instancePath.split("/"),K=q[q.length-1];y.message=`Value of property '${K}' must be '${y.params.type}'`}let R=Object.assign(y,E);d.push(R)}),d}};var iI=tle.instance;iI.addSchema(RAe,"route-configuration.schema.json");iI.addSchema(Fst,"policy-configuration.schema.json");iI.addSchema(LAe,"policies.schema.json");iI.addSchema(MAe,"open-api-route-configuration.schema.json");iI.addSchema(Ost,"fragments.schema.json");var i6r=iI.compile(RAe),qct=iI.compile(MAe),QNe=iI.compile(LAe);var rle=class{static{t(this,"PoliciesConfigurationValidator")}results;validate(o){return this.results=QNe(o),this.results}};var nle=class{static{t(this,"OpenAPILocalizedValidator")}results;validate(o){return this.results=qct(o),this.results}};import Xor from"node:path";var eIe=/\$import\((.*)\)/,TH=/\$env\((.*?)\)/g;var jk=class extends Error{static{t(this,"CodeGenError")}location;constructor(o,f,d,y){super(o),this.location={file:f,namespace:"",line:d?d.line:0,column:d?d.column:0,length:0,lineText:y??"",suggestion:""}}},Kor=t(s=>{let o=[],f=s;for(;f.parent;)o.push(f),f=f.parent;return o.reverse()},"invertTree"),qP=t((s,o)=>{if(!s)return!1;let f=Kor(s);return o.split("/").every((E,A)=>{let R=f[A];return R?E==="*"||zP(R)&&R.name.value===E?!0:E==="{}"?R.type===qo.Object:E==="[]"?R.type===qo.Array:!1:!1})},"testPosition");var ile=class{static{t(this,"AstTransformer")}errors=[];transform(o){return this.visitor(o),o}visitor(o){this.visit(o),H9(o)?o.children.forEach(f=>{this.visitor(f)}):FAe(o)?o.children.forEach(f=>{this.visitor(f)}):zP(o)&&this.visitor(o.value)}},Vct=t(s=>{let o=new RegExp(TH).exec(s);if(o?.length===2&&o[0]===s)return{type:"raw",value:`environment["${o[1]}"]`};{let f=s.replaceAll(new RegExp(TH),(d,y)=>`\${environment["${y}"] ? environment["${y}"] : ""}`);if(f!==s)return{type:"template",value:f}}return null},"replaceEnvInString"),Hct=t((s,o,f)=>d=>{if(fO(d)&&typeof d.value=="string"&&d.parent&&FAe(d.parent)){if(!s.some(A=>qP(d.parent,A))){TH.test(d.value)&&o.push(new jk("An $env() statement is not expected at this location.",f,d.location,d.value));return}let E=Vct(d.value);if(E){let A=d.parent,R=A.children.indexOf(d);if(R!==-1)if(E.type==="raw"){let q={type:qo.Raw,parent:A,value:E.value};A.children[R]=q}else A.children[R]=PS.createTemplateString(E.value,d)}return}if(!zP(d)||!fO(d.value)||typeof d.value.value!="string")return;if(!s.some(E=>qP(d,E))){TH.test(d.value.value)&&o.push(new jk("An $env() statement is not expected at this location.",f,d.location,d.value.value));return}let y=Vct(d.value.value);if(y)if(y.type==="raw"){let E={type:qo.Raw,parent:null,value:y.value};d.value=E}else d.value=PS.createTemplateString(y.value,d)},"getEnvStatementTransformer");var xH="config/routes.json",Zor=["handler/{}/options/*","handler/{}/options/*/[]","policies/[]/{}/handler/{}/options/*","policies/[]/{}/handler/{}/options/*/[]","corsPolicies/[]/{}/*","corsPolicies/[]/{}/*/[]"],Qor=["handler/{}/module","handler/{}/options/{}/policies/{}/inbound/[]/{}/module","handler/{}/options/{}/policies/{}/outbound/[]/{}/module","handler/{}/options/{}/onOpen/{}/module","policies/[]/{}/handler/{}/module","policies/[]/{}/handler/{}/options/{}/identifier/{}/module","policies/[]/{}/handler/{}/options/{}/validator"],Gct=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*"],ecr="handler/{}/options/{}/rewritePattern",tcr="handler/{}/options/{}/baseUrl",sle=class extends ile{static{t(this,"OpenAPIRoutesFragmentAstTransformer")}importCount=0;addedImports=new Map;getImportName(o){this.addedImports.has(o)||this.addedImports.set(o,`__import${this.importCount++}`);let f=this.addedImports.get(o);if(!f)throw new Error("Import name is undefined. This should not happen.");return f}getImports(){let o=[];return this.addedImports.forEach((f,d)=>{o.push({name:f,path:d})}),o}visit(o){this.rewriteHandlerFunction(o),this.rewriteForwardFunction(o),this.replaceImportStatements(o),this.replaceEnvStatements(o)}rewriteHandlerFunction(o){if(!(!zP(o)||!fO(o.value)||typeof o.value.value!="string")&&qP(o,ecr)){if(!o.parent||!H9(o.parent)){this.errors.push(new jk("Invalid node, expected object",xH,o.parent?o.parent.location:o.location,void 0));return}let f=o.value.value,d={type:qo.Raw,parent:null,value:Yct(f)},y=PS.createProperty("__rewriteFunction",d,o);o.parent.children.push(y)}}rewriteForwardFunction(o){if(!(!zP(o)||!fO(o.value)||typeof o.value.value!="string")&&qP(o,tcr)){if(!o.parent||!H9(o.parent)){this.errors.push(new jk("Invalid node, expected object",xH,o.parent?o.parent.location:o.location,void 0));return}let f=o.value.value,d={type:qo.Raw,parent:null,value:Yct(f)},y=PS.createProperty("__rewriteFunction",d,o);o.parent.children.push(y)}}replaceImportStatements(o){if(!zP(o)||!fO(o.value))return;let f=o.value.value;if(typeof f!="string")return;if(!Qor.some(R=>qP(o,R))&&!Gct.some(R=>qP(o,R))){if(eIe.test(f)){if(o.name.value==="$ref")return;this.errors.push(new jk("An $import() statement is not expected at this location.",xH,o.location,f))}return}let d=eIe.exec(f);if(Gct.some(R=>qP(o,R))&&!d)return;if(!d){this.errors.push(new jk("Invalid $import() statement",xH,o.location,f));return}let y=d[1];y=y.replace(/\\/g,"/"),y.startsWith(".")&&(y=Xor.posix.join("..",y));let E=this.getImportName(y),A={type:qo.Identifier,parent:o.parent,value:E};o.value=A}replaceEnvStatements=Hct(Zor,this.errors,xH)};function Yct(s){return`(request, context) => {
|
|
575
|
+
`),exitCode:E},"Untar process logs")}}t($Xt,"untarFile");async function WXt(s){if(await QPe(s))return await qN.rm(s,{recursive:!0})}t(WXt,"deleteFolder");var nu=eAe;var Qct=wp(Dst(),1);import{AssertionError as ger}from"node:assert";function UP(s,o){if(s===!1)throw new ger({message:o})}t(UP,"assert");var qo;(function(s){s.Object="Object",s.Property="Property",s.Array="Array",s.Literal="Literal",s.TemplateString="TemplateString",s.Identifier="Identifier",s.FunctionCall="FunctionCall",s.Raw="Raw"})(qo||(qo={}));function H9(s){return s.type===qo.Object}t(H9,"isAstObject");function zP(s){return s.type===qo.Property}t(zP,"isAstProperty");function FAe(s){return s.type===qo.Array}t(FAe,"isAstArray");function fO(s){return s.type===qo.Literal}t(fO,"isAstLiteral");function GN(s){if(s===void 0)throw new Error("Node is undefined");if(!H9(s))throw new Error("Node is not object")}t(GN,"assertAstObject");import{findNodeAtLocation as yer,getNodeValue as ver,printParseErrorCode as ber,visit as Ser}from"jsonc-parser";var Ter={DEFAULT:{allowTrailingComma:!1}};function JV(s,o=[],f=Ter.DEFAULT){let d={type:"array",offset:-1,length:-1,line:-1,column:-1,children:[],parent:void 0};function y(q){d.type==="property"&&(d.length=q-d.offset,d=d.parent)}t(y,"ensurePropertyComplete");function E(q){return d.children?.push(q),q}t(E,"onValue"),Ser(s,{onObjectBegin:t((q,K,ye,le)=>{d=E({type:"object",offset:q,length:-1,line:ye+1,column:le+1,parent:d,children:[]})},"onObjectBegin"),onObjectProperty:t((q,K,ye,le,se)=>{d=E({type:"property",offset:K,length:-1,line:le+1,column:se+1,parent:d,children:[]}),d.children?.push({type:"string",value:q,offset:K,length:ye,line:le,column:se,parent:d})},"onObjectProperty"),onObjectEnd:t((q,K)=>{y(q+K),d.length=q+K-d.offset,d=d.parent,y(q+K)},"onObjectEnd"),onArrayBegin:t((q,K,ye,le)=>{d=E({type:"array",offset:q,length:-1,line:ye+1,column:le+1,parent:d,children:[]})},"onArrayBegin"),onArrayEnd:t((q,K)=>{d.length=q+K-d.offset,d=d.parent,y(q+K)},"onArrayEnd"),onLiteralValue:t((q,K,ye,le,se)=>{E({type:xer(q),offset:K,length:ye,line:le+1,column:se+1,parent:d,value:q}),y(K+ye)},"onLiteralValue"),onSeparator:t((q,K)=>{d.type==="property"&&(q===":"?d.colonOffset=K:q===","&&y(K))},"onSeparator"),onError:t((q,K,ye,le,se)=>{o.push({error:q,offset:K,length:ye,line:le+1,column:se+1})},"onError")},f);let R=d.children?.[0];return R&&delete R.parent,R}t(JV,"parse");function xer(s){switch(typeof s){case"boolean":return"boolean";case"number":return"number";case"string":return"string";case"object":{if(s){if(Array.isArray(s))return"array"}else return"null";return"object"}default:return"null"}}t(xer,"getNodeType");function G9(s,o){return yer(s,o)}t(G9,"findNodeAtLocation");function $V(s){return ver(s)}t($V,"getNodeValue");function Pst(s){return ber(s)}t(Pst,"printParseErrorCode");var WV=class{static{t(this,"AstAdapter")}parse(o){let d=JV(o,[]);if(d)return this.parseNode(d,void 0);throw new Error("Failed to parse JSON")}convert(o){return this.parseNode(o,void 0)}parseNode(o,f){switch(o.type){case"object":return this.createObject(o,f);case"array":return this.createArray(o,f);case"property":return this.createProperty(o,f);case"string":return this.createLiteral(o,f);case"number":return this.createLiteral(o,f);case"boolean":return this.createLiteral(o,f);case"null":return this.createLiteral(o,f)}}createLiteral(o,f){return{type:qo.Literal,location:{line:o.line,column:o.column},parent:f,value:o.type==="null"?null:o.value}}createObject(o,f){let d={type:qo.Object,children:[],parent:f,location:{line:o.line,column:o.column}};return o.children?.forEach(y=>{d.children.push(this.parseNode(y,d))}),d}createProperty(o,f){UP(o.children?.length===2,"Invalid property node");let d={type:qo.Property,location:{line:o.line,column:o.column},parent:f,name:null,value:null};return d.name={value:o.children[0].value,location:{line:o.line,column:o.column},type:qo.Identifier,parent:d},d.value=this.parseNode(o.children[1],d),d}createArray(o,f){let d={type:qo.Array,location:{line:o.line,column:o.column},parent:f,children:[]};return o.children?.forEach(y=>d.children.push(this.parseNode(y,d))),d}};var PS={createLiteral:t((s,o)=>({type:qo.Literal,parent:o,value:s}),"createLiteral"),createTemplateString:t((s,o)=>({type:qo.TemplateString,parent:o,value:s}),"createTemplateString"),createIdentifier:t((s,o)=>({type:qo.Identifier,value:s,parent:o}),"createIdentifier"),createProperty:t((s,o,f)=>{let d={type:qo.Property,parent:f,name:null,value:o};return d.name={value:s,type:qo.Identifier,parent:d},d.value.parent=d,d},"createProperty"),createArrayOfLiterals:t((s,o)=>{let f={type:qo.Array,parent:o,children:[]};for(let d of s)f.children.push(PS.createLiteral(d,f));return f},"createArrayOfLiterals")};var Eer=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/,qV=class{static{t(this,"SourceGenerator")}generate(o){let f=[];return this.generateSource(f,o),f.join("")}generateSource(o,f){switch(f.type){case qo.Array:return this.generateArray(o,f);case qo.Object:return this.generateObject(o,f);case qo.Property:return this.generateProperty(o,f);case qo.Literal:return this.generateLiteral(o,f);case qo.FunctionCall:return this.generateFunctionCall(o,f);case qo.Identifier:return this.generateIdentifier(o,f);case qo.Raw:return this.generateRaw(o,f);case qo.TemplateString:return this.generateTemplateString(o,f)}}generateArray(o,f){o.push("["),f.children.map(d=>{this.generateSource(o,d),o.push(",")}),o.push("]")}generateObject(o,f){o.push("{"),f.children.forEach(d=>{this.generateSource(o,d),o.push(",")}),o.push("}")}generateProperty(o,f){this.generateIdentifier(o,f.name),o.push(":"),this.generateSource(o,f.value)}generateFunctionCall(o,f){o.push(f.name.value),o.push("("),f.children.forEach((d,y,E)=>{this.generateSource(o,d),y<E.length&&o.push(",")}),o.push(")")}generateRaw(o,f){o.push(f.value)}generateTemplateString(o,f){o.push("`"),o.push(f.value.replaceAll("`","\\`")),o.push("`")}generateLiteral(o,f){if(f.value===null)return o.push("null");switch(typeof f.value){case"number":case"boolean":return o.push(`${f.value}`);case"string":{let d=f.value,y=JSON.stringify(d);return o.push(`${y}`)}}}generateIdentifier(o,f){let d=Eer.test(f.value)?f.value:`'${f.value}'`;o.push(d)}};import Cer from"node:fs/promises";import{parse as ker}from"@swc/core";var Ast=t(async s=>{let o=new Set;try{let f=await Cer.readFile(s,"utf-8");(await ker(f,{syntax:"typescript"})).body.forEach(y=>{y.type==="ExportDefaultDeclaration"||y.type==="ExportDefaultExpression"?o.add("default"):y.type==="ExportDeclaration"&&y.declaration.type==="FunctionDeclaration"?o.add(y.declaration.identifier.value):y.type==="ExportDeclaration"&&y.declaration.type==="VariableDeclaration"&&y.declaration.declarations[0].id.type==="Identifier"&&o.add(y.declaration.declarations[0].id.value)})}catch{return null}return o},"getJSFileExports");var Nst=["ai-gateway-akamai-firewall","ai-gateway-auth","ai-gateway-configuration-executor","ai-gateway-configuration-loader","ai-gateway-dlp","ai-gateway-fallback-model","ai-gateway-galileo-tracing","ai-gateway-load-balancing","ai-gateway-metering","ai-gateway-model-filtering","ai-gateway-model-override","ai-gateway-opik-tracing","ai-gateway-prompt-injection","ai-gateway-semantic-cache","ai-gateway-smart-router","akamai-firewall-for-ai","prompt-injection","semantic-cache"],Ist={"ai-gateway-akamai-firewall-inbound":"ai-gateway-akamai-firewall","ai-gateway-auth-inbound":"ai-gateway-auth","ai-gateway-auth-v2":"ai-gateway-auth","ai-gateway-auth-v2-inbound":"ai-gateway-auth","ai-gateway-configuration-executor-inbound":"ai-gateway-configuration-executor","ai-gateway-configuration-executor-v2":"ai-gateway-configuration-executor","ai-gateway-configuration-executor-v2-inbound":"ai-gateway-configuration-executor","ai-gateway-configuration-loader-inbound":"ai-gateway-configuration-loader","ai-gateway-configuration-loader-v2":"ai-gateway-configuration-loader","ai-gateway-configuration-loader-v2-inbound":"ai-gateway-configuration-loader","ai-gateway-dlp-inbound":"ai-gateway-dlp","ai-gateway-fallback-model-inbound":"ai-gateway-fallback-model","ai-gateway-fallback-model-v2":"ai-gateway-fallback-model","ai-gateway-fallback-model-v2-inbound":"ai-gateway-fallback-model","ai-gateway-galileo-tracing-inbound":"ai-gateway-galileo-tracing","ai-gateway-load-balancing-inbound":"ai-gateway-load-balancing","ai-gateway-metering-inbound":"ai-gateway-metering","ai-gateway-metering-v2":"ai-gateway-metering","ai-gateway-metering-v2-inbound":"ai-gateway-metering","ai-gateway-model-filtering-inbound":"ai-gateway-model-filtering","ai-gateway-model-filtering-v2":"ai-gateway-model-filtering","ai-gateway-model-filtering-v2-inbound":"ai-gateway-model-filtering","ai-gateway-model-override-inbound":"ai-gateway-model-override","ai-gateway-opik-tracing-inbound":"ai-gateway-opik-tracing","ai-gateway-semantic-cache-inbound":"ai-gateway-semantic-cache","ai-gateway-semantic-cache-inbound-v2":"ai-gateway-semantic-cache","ai-gateway-semantic-cache-v2":"ai-gateway-semantic-cache","ai-gateway-semantic-cache-v2-inbound":"ai-gateway-semantic-cache","ai-gateway-smart-router-inbound":"ai-gateway-smart-router","akamai-ai-firewall-inbound-v2":"ai-gateway-akamai-firewall","akamai-ai-firewall-v2":"ai-gateway-akamai-firewall","akamai-ai-firewall-v2-inbound":"ai-gateway-akamai-firewall","akamai-firewall-for-ai-inbound":"akamai-firewall-for-ai","akamai-firewall-for-ai-outbound":"akamai-firewall-for-ai","comet-opik-tracing-inbound-v2":"ai-gateway-opik-tracing","comet-opik-tracing-v2":"ai-gateway-opik-tracing","comet-opik-tracing-v2-inbound":"ai-gateway-opik-tracing","galileo-tracing-inbound-v2":"ai-gateway-galileo-tracing","galileo-tracing-v2":"ai-gateway-galileo-tracing","galileo-tracing-v2-inbound":"ai-gateway-galileo-tracing","prompt-injection-outbound":"prompt-injection","semantic-cache-inbound":"semantic-cache"};var Ost={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/fragments.schema.json",$defs:{corsPolicyConfiguration:{type:"object",required:["name","allowedOrigins"],additionalProperties:!1,properties:{name:{type:"string",pattern:"^[0-9a-z-]+$"},allowCredentials:{type:"boolean"},maxAge:{type:"number"},allowedOrigins:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]},allowedMethods:{oneOf:[{type:"array",items:{$ref:"fragments.schema.json#/$defs/httpMethod"}},{type:"string"}]},allowedHeaders:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]},exposeHeaders:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]}}},handlerDefinition:{type:"object",properties:{module:{type:"string",pattern:"^\\$import\\([^ )]*?\\)$"},export:{type:"string"},options:{type:"object",additionalProperties:!0}},additionalProperties:!1,required:["module","export"]},httpMethod:{type:"string",enum:["GET","HEAD","POST","PUT","DELETE","CONNECT","OPTIONS","TRACE","PATCH"]}}};var LAe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/policies.schema.json",title:"Policies Config File",type:"object",additionalProperties:!1,properties:{policies:{type:"array",items:{$ref:"policy-configuration.schema.json"}},corsPolicies:{type:"array",items:{$ref:"fragments.schema.json#/$defs/corsPolicyConfiguration"}}}};var Fst={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/policy-configuration.schema.json",title:"Policy Configuration Fragment",type:"object",required:["name","policyType","handler"],additionalProperties:!1,properties:{name:{type:"string",pattern:"^[0-9a-z-]+$"},policyType:{type:"string"},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},options:{type:"object",additionalProperties:!0}}};var RAe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/route-configuration.schema.json",title:"Route Configuration Fragment",description:"",type:"object",required:["path","methods","handler"],additionalProperties:!1,$defs:{corsPolicy:{type:"string",pattern:"^[0-9a-z-]+$"}},properties:{operationId:{type:"string"},path:{type:"string",pattern:"^/[^\\s]*$"},methods:{type:"array",items:{$ref:"fragments.schema.json#/$defs/httpMethod"}},label:{type:"string",description:"An internal user-friendly identifier of the route."},enforceOpenApi:{type:"boolean",description:"If true, schema validation found in the OpenAPI spec will be enforced on requests/responses."},key:{type:"string",deprecated:!0},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},corsPolicy:{$ref:"#/$defs/corsPolicy"},custom:{},mcp:{type:"object",additionalProperties:!1,properties:{enabled:{type:"boolean"}}},policies:{type:"object",additionalProperties:!1,properties:{inbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}},outbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}}}},summary:{type:"string"},description:{type:"string"},excludeFromOpenApi:{type:"boolean"},tags:{type:"array",items:{type:"string"}}}};var MAe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/route-configuration-open-api.schema.json",title:"Open API Route Configuration Fragment",description:"These are the properties that can appear under the x-zuplo-route extension in a PathObject in Open API. It's a subset of what can appear in Zuplo's routes.json.",type:"object",required:["handler"],additionalProperties:!1,properties:{label:{type:"string",description:"An internal user-friendly identifier of the route."},key:{type:"string",deprecated:!0},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},corsPolicy:{type:"string",pattern:"^[0-9a-z-]+$"},custom:{},mcp:{oneOf:[{type:"object",additionalProperties:!1,properties:{type:{const:"tool"},name:{type:"string"},description:{type:"string"},enabled:{type:"boolean"},includeOutputSchema:{type:"boolean"},includeStructuredContent:{type:"boolean"},toolInputStyle:{enum:["flat","nested"]},annotations:{type:"object",additionalProperties:!1,properties:{title:{type:"string"},readOnlyHint:{type:"boolean"},destructiveHint:{type:"boolean"},idempotentHint:{type:"boolean"},openWorldHint:{type:"boolean"}}},_meta:{type:"object",additionalProperties:!0}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"prompt"},name:{type:"string"},description:{type:"string"},enabled:{type:"boolean"}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"resource"},name:{type:"string"},description:{type:"string"},uri:{type:"string"},mimeType:{type:"string"},enabled:{type:"boolean"},_meta:{type:"object",additionalProperties:!0}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"graphql"},enabled:{type:"boolean"},introspectionTool:{type:"object",additionalProperties:!1,properties:{name:{type:"string"},description:{type:"string"}}},executeTool:{type:"object",additionalProperties:!1,properties:{name:{type:"string"},description:{type:"string"}}}},required:["type"]}]},policies:{type:"object",additionalProperties:!1,properties:{inbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}},outbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}}}},tags:{type:"array",items:{type:"string"}}}};var $ct=wp(Kce(),1),Wct=wp(ele(),1);var tle=class s{static{t(this,"JsonValidator")}static#e=new s;static get instance(){return s.#e}ajv;constructor(){this.ajv=new $ct.Ajv2020({allErrors:!0,allowUnionTypes:!0}),this.ajv.addKeyword("faker"),(0,Wct.default)(this.ajv,{mode:"fast"})}addSchema(o,f){this.ajv.addSchema(o,f)}compile(o){let f=this.ajv.compile(o);return t(y=>({isValid:f(y),errors:this.toSimpleErrors(f.errors,y),warnings:[]}),"validator")}toSimpleErrors(o,f){let d=[];return o?.forEach(y=>{y.keyword==="enum"&&y.params.allowedValues&&Array.isArray(y.params.allowedValues)&&(y.message+=`; ${y.params.allowedValues.join(", ")}`),y.instancePath&&(y.instancePath=y.instancePath.replaceAll(/(\/)?(~1)(\/)?/gm,"/"));let E={details:{}},A=y.instancePath.split("/");if(A.length>2){let q=A[1],K=A[2]?parseInt(A[2],10):0,ye=A[3],le=Number.isNaN(K)?void 0:f[q][K][ye];E={details:{property:q,index:K,field:ye,fieldValue:le}}}if(y.keyword==="required"&&y.params.missingProperty&&y.instancePath&&(y.message=`A 'path' is missing required property '${y.params.missingProperty}'`),y.keyword==="additionalProperties"&&y.params.additionalProperty&&y.instancePath&&(y.message=`A 'path' should NOT include property '${y.params.additionalProperty}'`),y.keyword==="type"&&y.params.type&&y.instancePath){let q=y.instancePath.split("/"),K=q[q.length-1];y.message=`Value of property '${K}' must be '${y.params.type}'`}let R=Object.assign(y,E);d.push(R)}),d}};var iI=tle.instance;iI.addSchema(RAe,"route-configuration.schema.json");iI.addSchema(Fst,"policy-configuration.schema.json");iI.addSchema(LAe,"policies.schema.json");iI.addSchema(MAe,"open-api-route-configuration.schema.json");iI.addSchema(Ost,"fragments.schema.json");var i6r=iI.compile(RAe),qct=iI.compile(MAe),QNe=iI.compile(LAe);var rle=class{static{t(this,"PoliciesConfigurationValidator")}results;validate(o){return this.results=QNe(o),this.results}};var nle=class{static{t(this,"OpenAPILocalizedValidator")}results;validate(o){return this.results=qct(o),this.results}};import Xor from"node:path";var eIe=/\$import\((.*)\)/,TH=/\$env\((.*?)\)/g;var jk=class extends Error{static{t(this,"CodeGenError")}location;constructor(o,f,d,y){super(o),this.location={file:f,namespace:"",line:d?d.line:0,column:d?d.column:0,length:0,lineText:y??"",suggestion:""}}},Kor=t(s=>{let o=[],f=s;for(;f.parent;)o.push(f),f=f.parent;return o.reverse()},"invertTree"),qP=t((s,o)=>{if(!s)return!1;let f=Kor(s);return o.split("/").every((E,A)=>{let R=f[A];return R?E==="*"||zP(R)&&R.name.value===E?!0:E==="{}"?R.type===qo.Object:E==="[]"?R.type===qo.Array:!1:!1})},"testPosition");var ile=class{static{t(this,"AstTransformer")}errors=[];transform(o){return this.visitor(o),o}visitor(o){this.visit(o),H9(o)?o.children.forEach(f=>{this.visitor(f)}):FAe(o)?o.children.forEach(f=>{this.visitor(f)}):zP(o)&&this.visitor(o.value)}},Vct=t(s=>{let o=new RegExp(TH).exec(s);if(o?.length===2&&o[0]===s)return{type:"raw",value:`environment["${o[1]}"]`};{let f=s.replaceAll(new RegExp(TH),(d,y)=>`\${environment["${y}"] ? environment["${y}"] : ""}`);if(f!==s)return{type:"template",value:f}}return null},"replaceEnvInString"),Hct=t((s,o,f)=>d=>{if(fO(d)&&typeof d.value=="string"&&d.parent&&FAe(d.parent)){if(!s.some(A=>qP(d.parent,A))){TH.test(d.value)&&o.push(new jk("An $env() statement is not expected at this location.",f,d.location,d.value));return}let E=Vct(d.value);if(E){let A=d.parent,R=A.children.indexOf(d);if(R!==-1)if(E.type==="raw"){let q={type:qo.Raw,parent:A,value:E.value};A.children[R]=q}else A.children[R]=PS.createTemplateString(E.value,d)}return}if(!zP(d)||!fO(d.value)||typeof d.value.value!="string")return;if(!s.some(E=>qP(d,E))){TH.test(d.value.value)&&o.push(new jk("An $env() statement is not expected at this location.",f,d.location,d.value.value));return}let y=Vct(d.value.value);if(y)if(y.type==="raw"){let E={type:qo.Raw,parent:null,value:y.value};d.value=E}else d.value=PS.createTemplateString(y.value,d)},"getEnvStatementTransformer");var xH="config/routes.json",Zor=["handler/{}/options/*","handler/{}/options/*/[]","policies/[]/{}/handler/{}/options/*","policies/[]/{}/handler/{}/options/*/[]","corsPolicies/[]/{}/*","corsPolicies/[]/{}/*/[]"],Qor=["handler/{}/module","handler/{}/options/{}/policies/{}/inbound/[]/{}/module","handler/{}/options/{}/policies/{}/outbound/[]/{}/module","handler/{}/options/{}/onOpen/{}/module","policies/[]/{}/handler/{}/module","policies/[]/{}/handler/{}/options/{}/identifier/{}/module","policies/[]/{}/handler/{}/options/{}/validator"],Gct=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*"],ecr="handler/{}/options/{}/rewritePattern",tcr="handler/{}/options/{}/baseUrl",sle=class extends ile{static{t(this,"OpenAPIRoutesFragmentAstTransformer")}importCount=0;addedImports=new Map;getImportName(o){this.addedImports.has(o)||this.addedImports.set(o,`__import${this.importCount++}`);let f=this.addedImports.get(o);if(!f)throw new Error("Import name is undefined. This should not happen.");return f}getImports(){let o=[];return this.addedImports.forEach((f,d)=>{o.push({name:f,path:d})}),o}visit(o){this.rewriteHandlerFunction(o),this.rewriteForwardFunction(o),this.replaceImportStatements(o),this.replaceEnvStatements(o)}rewriteHandlerFunction(o){if(!(!zP(o)||!fO(o.value)||typeof o.value.value!="string")&&qP(o,ecr)){if(!o.parent||!H9(o.parent)){this.errors.push(new jk("Invalid node, expected object",xH,o.parent?o.parent.location:o.location,void 0));return}let f=o.value.value,d={type:qo.Raw,parent:null,value:Yct(f)},y=PS.createProperty("__rewriteFunction",d,o);o.parent.children.push(y)}}rewriteForwardFunction(o){if(!(!zP(o)||!fO(o.value)||typeof o.value.value!="string")&&qP(o,tcr)){if(!o.parent||!H9(o.parent)){this.errors.push(new jk("Invalid node, expected object",xH,o.parent?o.parent.location:o.location,void 0));return}let f=o.value.value,d={type:qo.Raw,parent:null,value:Yct(f)},y=PS.createProperty("__rewriteFunction",d,o);o.parent.children.push(y)}}replaceImportStatements(o){if(!zP(o)||!fO(o.value))return;let f=o.value.value;if(typeof f!="string")return;if(!Qor.some(R=>qP(o,R))&&!Gct.some(R=>qP(o,R))){if(eIe.test(f)){if(o.name.value==="$ref")return;this.errors.push(new jk("An $import() statement is not expected at this location.",xH,o.location,f))}return}let d=eIe.exec(f);if(Gct.some(R=>qP(o,R))&&!d)return;if(!d){this.errors.push(new jk("Invalid $import() statement",xH,o.location,f));return}let y=d[1];y=y.replace(/\\/g,"/"),y.startsWith(".")&&(y=Xor.posix.join("..",y));let E=this.getImportName(y),A={type:qo.Identifier,parent:o.parent,value:E};o.value=A}replaceEnvStatements=Hct(Zor,this.errors,xH)};function Yct(s){return`(request, context) => {
|
|
576
576
|
const { params, url, query, method, headers } = request;
|
|
577
577
|
const { host, hostname, origin, pathname, port, search } = new URL(url);
|
|
578
578
|
const e = encodeURIComponent;
|
package/index.minified.js
CHANGED
|
@@ -572,7 +572,7 @@ globstar while`,s,le,o,se,tt),this.matchOne(s.slice(le),o.slice(se),f))return th
|
|
|
572
572
|
`),stderr:E.join(`
|
|
573
573
|
`),exitCode:A},"Tar process logs")}}t(_Zt,"tarFolder");async function pZt({tarFilePath:s,outputDir:o,logger:f}){let d=[],y=[],E;try{await new Promise((A,R)=>{let q=_it("sh",["-c",`tar -xvf ${s} -C ${o};`]);q.stdout.on("data",K=>{let ye=K.toString().trim();ye.length>0&&d.push(ye.trim())}),q.stderr.on("data",K=>{let ye=K.toString().trim();ye.length>0&&y.push(ye.trim())}),q.on("close",K=>{E=K,K===0?A():R(new Error(`tar process exited with code ${K}`))}),q.on("error",K=>{R(K)})})}catch(A){throw new Error("Failed to untar file",{cause:A})}finally{f.info({stdout:d.join(`
|
|
574
574
|
`),stderr:y.join(`
|
|
575
|
-
`),exitCode:E},"Untar process logs")}}t(pZt,"untarFile");async function dZt(s){if(await sAe(s))return await GN.rm(s,{recursive:!0})}t(dZt,"deleteFolder");var nu=aAe;var alt=R_(Lst(),1);import{AssertionError as zer}from"node:assert";function $P(s,o){if(s===!1)throw new zer({message:o})}t($P,"assert");var qo;(function(s){s.Object="Object",s.Property="Property",s.Array="Array",s.Literal="Literal",s.TemplateString="TemplateString",s.Identifier="Identifier",s.FunctionCall="FunctionCall",s.Raw="Raw"})(qo||(qo={}));function H9(s){return s.type===qo.Object}t(H9,"isAstObject");function WP(s){return s.type===qo.Property}t(WP,"isAstProperty");function UAe(s){return s.type===qo.Array}t(UAe,"isAstArray");function pO(s){return s.type===qo.Literal}t(pO,"isAstLiteral");function XN(s){if(s===void 0)throw new Error("Node is undefined");if(!H9(s))throw new Error("Node is not object")}t(XN,"assertAstObject");import{findNodeAtLocation as Jer,getNodeValue as $er,printParseErrorCode as Wer,visit as qer}from"jsonc-parser";var Ver={DEFAULT:{allowTrailingComma:!1}};function $V(s,o=[],f=Ver.DEFAULT){let d={type:"array",offset:-1,length:-1,line:-1,column:-1,children:[],parent:void 0};function y(q){d.type==="property"&&(d.length=q-d.offset,d=d.parent)}t(y,"ensurePropertyComplete");function E(q){return d.children?.push(q),q}t(E,"onValue"),qer(s,{onObjectBegin:t((q,K,ye,le)=>{d=E({type:"object",offset:q,length:-1,line:ye+1,column:le+1,parent:d,children:[]})},"onObjectBegin"),onObjectProperty:t((q,K,ye,le,se)=>{d=E({type:"property",offset:K,length:-1,line:le+1,column:se+1,parent:d,children:[]}),d.children?.push({type:"string",value:q,offset:K,length:ye,line:le,column:se,parent:d})},"onObjectProperty"),onObjectEnd:t((q,K)=>{y(q+K),d.length=q+K-d.offset,d=d.parent,y(q+K)},"onObjectEnd"),onArrayBegin:t((q,K,ye,le)=>{d=E({type:"array",offset:q,length:-1,line:ye+1,column:le+1,parent:d,children:[]})},"onArrayBegin"),onArrayEnd:t((q,K)=>{d.length=q+K-d.offset,d=d.parent,y(q+K)},"onArrayEnd"),onLiteralValue:t((q,K,ye,le,se)=>{E({type:Her(q),offset:K,length:ye,line:le+1,column:se+1,parent:d,value:q}),y(K+ye)},"onLiteralValue"),onSeparator:t((q,K)=>{d.type==="property"&&(q===":"?d.colonOffset=K:q===","&&y(K))},"onSeparator"),onError:t((q,K,ye,le,se)=>{o.push({error:q,offset:K,length:ye,line:le+1,column:se+1})},"onError")},f);let R=d.children?.[0];return R&&delete R.parent,R}t($V,"parse");function Her(s){switch(typeof s){case"boolean":return"boolean";case"number":return"number";case"string":return"string";case"object":{if(s){if(Array.isArray(s))return"array"}else return"null";return"object"}default:return"null"}}t(Her,"getNodeType");function G9(s,o){return Jer(s,o)}t(G9,"findNodeAtLocation");function WV(s){return $er(s)}t(WV,"getNodeValue");function Rst(s){return Wer(s)}t(Rst,"printParseErrorCode");var qV=class{static{t(this,"AstAdapter")}parse(o){let d=$V(o,[]);if(d)return this.parseNode(d,void 0);throw new Error("Failed to parse JSON")}convert(o){return this.parseNode(o,void 0)}parseNode(o,f){switch(o.type){case"object":return this.createObject(o,f);case"array":return this.createArray(o,f);case"property":return this.createProperty(o,f);case"string":return this.createLiteral(o,f);case"number":return this.createLiteral(o,f);case"boolean":return this.createLiteral(o,f);case"null":return this.createLiteral(o,f)}}createLiteral(o,f){return{type:qo.Literal,location:{line:o.line,column:o.column},parent:f,value:o.type==="null"?null:o.value}}createObject(o,f){let d={type:qo.Object,children:[],parent:f,location:{line:o.line,column:o.column}};return o.children?.forEach(y=>{d.children.push(this.parseNode(y,d))}),d}createProperty(o,f){$P(o.children?.length===2,"Invalid property node");let d={type:qo.Property,location:{line:o.line,column:o.column},parent:f,name:null,value:null};return d.name={value:o.children[0].value,location:{line:o.line,column:o.column},type:qo.Identifier,parent:d},d.value=this.parseNode(o.children[1],d),d}createArray(o,f){let d={type:qo.Array,location:{line:o.line,column:o.column},parent:f,children:[]};return o.children?.forEach(y=>d.children.push(this.parseNode(y,d))),d}};var PS={createLiteral:t((s,o)=>({type:qo.Literal,parent:o,value:s}),"createLiteral"),createTemplateString:t((s,o)=>({type:qo.TemplateString,parent:o,value:s}),"createTemplateString"),createIdentifier:t((s,o)=>({type:qo.Identifier,value:s,parent:o}),"createIdentifier"),createProperty:t((s,o,f)=>{let d={type:qo.Property,parent:f,name:null,value:o};return d.name={value:s,type:qo.Identifier,parent:d},d.value.parent=d,d},"createProperty"),createArrayOfLiterals:t((s,o)=>{let f={type:qo.Array,parent:o,children:[]};for(let d of s)f.children.push(PS.createLiteral(d,f));return f},"createArrayOfLiterals")};var Ger=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/,VV=class{static{t(this,"SourceGenerator")}generate(o){let f=[];return this.generateSource(f,o),f.join("")}generateSource(o,f){switch(f.type){case qo.Array:return this.generateArray(o,f);case qo.Object:return this.generateObject(o,f);case qo.Property:return this.generateProperty(o,f);case qo.Literal:return this.generateLiteral(o,f);case qo.FunctionCall:return this.generateFunctionCall(o,f);case qo.Identifier:return this.generateIdentifier(o,f);case qo.Raw:return this.generateRaw(o,f);case qo.TemplateString:return this.generateTemplateString(o,f)}}generateArray(o,f){o.push("["),f.children.map(d=>{this.generateSource(o,d),o.push(",")}),o.push("]")}generateObject(o,f){o.push("{"),f.children.forEach(d=>{this.generateSource(o,d),o.push(",")}),o.push("}")}generateProperty(o,f){this.generateIdentifier(o,f.name),o.push(":"),this.generateSource(o,f.value)}generateFunctionCall(o,f){o.push(f.name.value),o.push("("),f.children.forEach((d,y,E)=>{this.generateSource(o,d),y<E.length&&o.push(",")}),o.push(")")}generateRaw(o,f){o.push(f.value)}generateTemplateString(o,f){o.push("`"),o.push(f.value.replaceAll("`","\\`")),o.push("`")}generateLiteral(o,f){if(f.value===null)return o.push("null");switch(typeof f.value){case"number":case"boolean":return o.push(`${f.value}`);case"string":{let d=f.value,y=JSON.stringify(d);return o.push(`${y}`)}}}generateIdentifier(o,f){let d=Ger.test(f.value)?f.value:`'${f.value}'`;o.push(d)}};import Yer from"node:fs/promises";import{parse as Ker}from"@swc/core";var Mst=t(async s=>{let o=new Set;try{let f=await Yer.readFile(s,"utf-8");(await Ker(f,{syntax:"typescript"})).body.forEach(y=>{y.type==="ExportDefaultDeclaration"||y.type==="ExportDefaultExpression"?o.add("default"):y.type==="ExportDeclaration"&&y.declaration.type==="FunctionDeclaration"?o.add(y.declaration.identifier.value):y.type==="ExportDeclaration"&&y.declaration.type==="VariableDeclaration"&&y.declaration.declarations[0].id.type==="Identifier"&&o.add(y.declaration.declarations[0].id.value)})}catch{return null}return o},"getJSFileExports");var jst=["ai-gateway-akamai-firewall","ai-gateway-auth","ai-gateway-configuration-executor","ai-gateway-configuration-loader","ai-gateway-dlp","ai-gateway-fallback-model","ai-gateway-galileo-tracing","ai-gateway-metering","ai-gateway-model-filtering","ai-gateway-model-override","ai-gateway-opik-tracing","ai-gateway-prompt-injection","ai-gateway-semantic-cache","ai-gateway-smart-router","akamai-firewall-for-ai","prompt-injection","semantic-cache"],Bst={"ai-gateway-akamai-firewall-inbound":"ai-gateway-akamai-firewall","ai-gateway-auth-inbound":"ai-gateway-auth","ai-gateway-auth-v2":"ai-gateway-auth","ai-gateway-auth-v2-inbound":"ai-gateway-auth","ai-gateway-configuration-executor-inbound":"ai-gateway-configuration-executor","ai-gateway-configuration-executor-v2":"ai-gateway-configuration-executor","ai-gateway-configuration-executor-v2-inbound":"ai-gateway-configuration-executor","ai-gateway-configuration-loader-inbound":"ai-gateway-configuration-loader","ai-gateway-configuration-loader-v2":"ai-gateway-configuration-loader","ai-gateway-configuration-loader-v2-inbound":"ai-gateway-configuration-loader","ai-gateway-dlp-inbound":"ai-gateway-dlp","ai-gateway-fallback-model-inbound":"ai-gateway-fallback-model","ai-gateway-fallback-model-v2":"ai-gateway-fallback-model","ai-gateway-fallback-model-v2-inbound":"ai-gateway-fallback-model","ai-gateway-galileo-tracing-inbound":"ai-gateway-galileo-tracing","ai-gateway-metering-inbound":"ai-gateway-metering","ai-gateway-metering-v2":"ai-gateway-metering","ai-gateway-metering-v2-inbound":"ai-gateway-metering","ai-gateway-model-filtering-inbound":"ai-gateway-model-filtering","ai-gateway-model-filtering-v2":"ai-gateway-model-filtering","ai-gateway-model-filtering-v2-inbound":"ai-gateway-model-filtering","ai-gateway-model-override-inbound":"ai-gateway-model-override","ai-gateway-opik-tracing-inbound":"ai-gateway-opik-tracing","ai-gateway-semantic-cache-inbound":"ai-gateway-semantic-cache","ai-gateway-semantic-cache-inbound-v2":"ai-gateway-semantic-cache","ai-gateway-semantic-cache-v2":"ai-gateway-semantic-cache","ai-gateway-semantic-cache-v2-inbound":"ai-gateway-semantic-cache","ai-gateway-smart-router-inbound":"ai-gateway-smart-router","akamai-ai-firewall-inbound-v2":"ai-gateway-akamai-firewall","akamai-ai-firewall-v2":"ai-gateway-akamai-firewall","akamai-ai-firewall-v2-inbound":"ai-gateway-akamai-firewall","akamai-firewall-for-ai-inbound":"akamai-firewall-for-ai","akamai-firewall-for-ai-outbound":"akamai-firewall-for-ai","comet-opik-tracing-inbound-v2":"ai-gateway-opik-tracing","comet-opik-tracing-v2":"ai-gateway-opik-tracing","comet-opik-tracing-v2-inbound":"ai-gateway-opik-tracing","galileo-tracing-inbound-v2":"ai-gateway-galileo-tracing","galileo-tracing-v2":"ai-gateway-galileo-tracing","galileo-tracing-v2-inbound":"ai-gateway-galileo-tracing","prompt-injection-outbound":"prompt-injection","semantic-cache-inbound":"semantic-cache"};var Ust={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/fragments.schema.json",$defs:{corsPolicyConfiguration:{type:"object",required:["name","allowedOrigins"],additionalProperties:!1,properties:{name:{type:"string",pattern:"^[0-9a-z-]+$"},allowCredentials:{type:"boolean"},maxAge:{type:"number"},allowedOrigins:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]},allowedMethods:{oneOf:[{type:"array",items:{$ref:"fragments.schema.json#/$defs/httpMethod"}},{type:"string"}]},allowedHeaders:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]},exposeHeaders:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]}}},handlerDefinition:{type:"object",properties:{module:{type:"string",pattern:"^\\$import\\([^ )]*?\\)$"},export:{type:"string"},options:{type:"object",additionalProperties:!0}},additionalProperties:!1,required:["module","export"]},httpMethod:{type:"string",enum:["GET","HEAD","POST","PUT","DELETE","CONNECT","OPTIONS","TRACE","PATCH"]}}};var zAe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/policies.schema.json",title:"Policies Config File",type:"object",additionalProperties:!1,properties:{policies:{type:"array",items:{$ref:"policy-configuration.schema.json"}},corsPolicies:{type:"array",items:{$ref:"fragments.schema.json#/$defs/corsPolicyConfiguration"}}}};var zst={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/policy-configuration.schema.json",title:"Policy Configuration Fragment",type:"object",required:["name","policyType","handler"],additionalProperties:!1,properties:{name:{type:"string",pattern:"^[0-9a-z-]+$"},policyType:{type:"string"},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},options:{type:"object",additionalProperties:!0}}};var JAe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/route-configuration.schema.json",title:"Route Configuration Fragment",description:"",type:"object",required:["path","methods","handler"],additionalProperties:!1,$defs:{corsPolicy:{type:"string",pattern:"^[0-9a-z-]+$"}},properties:{operationId:{type:"string"},path:{type:"string",pattern:"^/[^\\s]*$"},methods:{type:"array",items:{$ref:"fragments.schema.json#/$defs/httpMethod"}},label:{type:"string",description:"An internal user-friendly identifier of the route."},enforceOpenApi:{type:"boolean",description:"If true, schema validation found in the OpenAPI spec will be enforced on requests/responses."},key:{type:"string",deprecated:!0},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},corsPolicy:{$ref:"#/$defs/corsPolicy"},custom:{},mcp:{type:"object",additionalProperties:!1,properties:{enabled:{type:"boolean"}}},policies:{type:"object",additionalProperties:!1,properties:{inbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}},outbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}}}},summary:{type:"string"},description:{type:"string"},excludeFromOpenApi:{type:"boolean"},tags:{type:"array",items:{type:"string"}}}};var $Ae={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/route-configuration-open-api.schema.json",title:"Open API Route Configuration Fragment",description:"These are the properties that can appear under the x-zuplo-route extension in a PathObject in Open API. It's a subset of what can appear in Zuplo's routes.json.",type:"object",required:["handler"],additionalProperties:!1,properties:{label:{type:"string",description:"An internal user-friendly identifier of the route."},key:{type:"string",deprecated:!0},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},corsPolicy:{type:"string",pattern:"^[0-9a-z-]+$"},custom:{},mcp:{oneOf:[{type:"object",additionalProperties:!1,properties:{type:{const:"tool"},name:{type:"string"},description:{type:"string"},enabled:{type:"boolean"},includeOutputSchema:{type:"boolean"},includeStructuredContent:{type:"boolean"},toolInputStyle:{enum:["flat","nested"]},annotations:{type:"object",additionalProperties:!1,properties:{title:{type:"string"},readOnlyHint:{type:"boolean"},destructiveHint:{type:"boolean"},idempotentHint:{type:"boolean"},openWorldHint:{type:"boolean"}}},_meta:{type:"object",additionalProperties:!0}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"prompt"},name:{type:"string"},description:{type:"string"},enabled:{type:"boolean"}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"resource"},name:{type:"string"},description:{type:"string"},uri:{type:"string"},mimeType:{type:"string"},enabled:{type:"boolean"},_meta:{type:"object",additionalProperties:!0}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"graphql"},enabled:{type:"boolean"},introspectionTool:{type:"object",additionalProperties:!1,properties:{name:{type:"string"},description:{type:"string"}}},executeTool:{type:"object",additionalProperties:!1,properties:{name:{type:"string"},description:{type:"string"}}}},required:["type"]}]},policies:{type:"object",additionalProperties:!1,properties:{inbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}},outbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}}}},tags:{type:"array",items:{type:"string"}}}};var Kct=R_(Xce(),1),Xct=R_(tle(),1);var rle=class s{static{t(this,"JsonValidator")}static#e=new s;static get instance(){return s.#e}ajv;constructor(){this.ajv=new Kct.Ajv2020({allErrors:!0,allowUnionTypes:!0}),this.ajv.addKeyword("faker"),(0,Xct.default)(this.ajv,{mode:"fast"})}addSchema(o,f){this.ajv.addSchema(o,f)}compile(o){let f=this.ajv.compile(o);return t(y=>({isValid:f(y),errors:this.toSimpleErrors(f.errors,y),warnings:[]}),"validator")}toSimpleErrors(o,f){let d=[];return o?.forEach(y=>{y.keyword==="enum"&&y.params.allowedValues&&Array.isArray(y.params.allowedValues)&&(y.message+=`; ${y.params.allowedValues.join(", ")}`),y.instancePath&&(y.instancePath=y.instancePath.replaceAll(/(\/)?(~1)(\/)?/gm,"/"));let E={details:{}},A=y.instancePath.split("/");if(A.length>2){let q=A[1],K=A[2]?parseInt(A[2],10):0,ye=A[3],le=Number.isNaN(K)?void 0:f[q][K][ye];E={details:{property:q,index:K,field:ye,fieldValue:le}}}if(y.keyword==="required"&&y.params.missingProperty&&y.instancePath&&(y.message=`A 'path' is missing required property '${y.params.missingProperty}'`),y.keyword==="additionalProperties"&&y.params.additionalProperty&&y.instancePath&&(y.message=`A 'path' should NOT include property '${y.params.additionalProperty}'`),y.keyword==="type"&&y.params.type&&y.instancePath){let q=y.instancePath.split("/"),K=q[q.length-1];y.message=`Value of property '${K}' must be '${y.params.type}'`}let R=Object.assign(y,E);d.push(R)}),d}};var oI=rle.instance;oI.addSchema(JAe,"route-configuration.schema.json");oI.addSchema(zst,"policy-configuration.schema.json");oI.addSchema(zAe,"policies.schema.json");oI.addSchema($Ae,"open-api-route-configuration.schema.json");oI.addSchema(Ust,"fragments.schema.json");var P6r=oI.compile(JAe),Zct=oI.compile($Ae),sIe=oI.compile(zAe);var nle=class{static{t(this,"PoliciesConfigurationValidator")}results;validate(o){return this.results=sIe(o),this.results}};var ile=class{static{t(this,"OpenAPILocalizedValidator")}results;validate(o){return this.results=Zct(o),this.results}};import Scr from"node:path";var aIe=/\$import\((.*)\)/,xH=/\$env\((.*?)\)/g;var Uk=class extends Error{static{t(this,"CodeGenError")}location;constructor(o,f,d,y){super(o),this.location={file:f,namespace:"",line:d?d.line:0,column:d?d.column:0,length:0,lineText:y??"",suggestion:""}}},bcr=t(s=>{let o=[],f=s;for(;f.parent;)o.push(f),f=f.parent;return o.reverse()},"invertTree"),GP=t((s,o)=>{if(!s)return!1;let f=bcr(s);return o.split("/").every((E,A)=>{let R=f[A];return R?E==="*"||WP(R)&&R.name.value===E?!0:E==="{}"?R.type===qo.Object:E==="[]"?R.type===qo.Array:!1:!1})},"testPosition");var sle=class{static{t(this,"AstTransformer")}errors=[];transform(o){return this.visitor(o),o}visitor(o){this.visit(o),H9(o)?o.children.forEach(f=>{this.visitor(f)}):UAe(o)?o.children.forEach(f=>{this.visitor(f)}):WP(o)&&this.visitor(o.value)}},Qct=t(s=>{let o=new RegExp(xH).exec(s);if(o?.length===2&&o[0]===s)return{type:"raw",value:`environment["${o[1]}"]`};{let f=s.replaceAll(new RegExp(xH),(d,y)=>`\${environment["${y}"] ? environment["${y}"] : ""}`);if(f!==s)return{type:"template",value:f}}return null},"replaceEnvInString"),elt=t((s,o,f)=>d=>{if(pO(d)&&typeof d.value=="string"&&d.parent&&UAe(d.parent)){if(!s.some(A=>GP(d.parent,A))){xH.test(d.value)&&o.push(new Uk("An $env() statement is not expected at this location.",f,d.location,d.value));return}let E=Qct(d.value);if(E){let A=d.parent,R=A.children.indexOf(d);if(R!==-1)if(E.type==="raw"){let q={type:qo.Raw,parent:A,value:E.value};A.children[R]=q}else A.children[R]=PS.createTemplateString(E.value,d)}return}if(!WP(d)||!pO(d.value)||typeof d.value.value!="string")return;if(!s.some(E=>GP(d,E))){xH.test(d.value.value)&&o.push(new Uk("An $env() statement is not expected at this location.",f,d.location,d.value.value));return}let y=Qct(d.value.value);if(y)if(y.type==="raw"){let E={type:qo.Raw,parent:null,value:y.value};d.value=E}else d.value=PS.createTemplateString(y.value,d)},"getEnvStatementTransformer");var EH="config/routes.json",Tcr=["handler/{}/options/*","handler/{}/options/*/[]","policies/[]/{}/handler/{}/options/*","policies/[]/{}/handler/{}/options/*/[]","corsPolicies/[]/{}/*","corsPolicies/[]/{}/*/[]"],xcr=["handler/{}/module","handler/{}/options/{}/policies/{}/inbound/[]/{}/module","handler/{}/options/{}/policies/{}/outbound/[]/{}/module","handler/{}/options/{}/onOpen/{}/module","policies/[]/{}/handler/{}/module","policies/[]/{}/handler/{}/options/{}/identifier/{}/module","policies/[]/{}/handler/{}/options/{}/validator"],tlt=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*"],Ecr="handler/{}/options/{}/rewritePattern",Ccr="handler/{}/options/{}/baseUrl",ale=class extends sle{static{t(this,"OpenAPIRoutesFragmentAstTransformer")}importCount=0;addedImports=new Map;getImportName(o){this.addedImports.has(o)||this.addedImports.set(o,`__import${this.importCount++}`);let f=this.addedImports.get(o);if(!f)throw new Error("Import name is undefined. This should not happen.");return f}getImports(){let o=[];return this.addedImports.forEach((f,d)=>{o.push({name:f,path:d})}),o}visit(o){this.rewriteHandlerFunction(o),this.rewriteForwardFunction(o),this.replaceImportStatements(o),this.replaceEnvStatements(o)}rewriteHandlerFunction(o){if(!(!WP(o)||!pO(o.value)||typeof o.value.value!="string")&&GP(o,Ecr)){if(!o.parent||!H9(o.parent)){this.errors.push(new Uk("Invalid node, expected object",EH,o.parent?o.parent.location:o.location,void 0));return}let f=o.value.value,d={type:qo.Raw,parent:null,value:rlt(f)},y=PS.createProperty("__rewriteFunction",d,o);o.parent.children.push(y)}}rewriteForwardFunction(o){if(!(!WP(o)||!pO(o.value)||typeof o.value.value!="string")&&GP(o,Ccr)){if(!o.parent||!H9(o.parent)){this.errors.push(new Uk("Invalid node, expected object",EH,o.parent?o.parent.location:o.location,void 0));return}let f=o.value.value,d={type:qo.Raw,parent:null,value:rlt(f)},y=PS.createProperty("__rewriteFunction",d,o);o.parent.children.push(y)}}replaceImportStatements(o){if(!WP(o)||!pO(o.value))return;let f=o.value.value;if(typeof f!="string")return;if(!xcr.some(R=>GP(o,R))&&!tlt.some(R=>GP(o,R))){if(aIe.test(f)){if(o.name.value==="$ref")return;this.errors.push(new Uk("An $import() statement is not expected at this location.",EH,o.location,f))}return}let d=aIe.exec(f);if(tlt.some(R=>GP(o,R))&&!d)return;if(!d){this.errors.push(new Uk("Invalid $import() statement",EH,o.location,f));return}let y=d[1];y=y.replace(/\\/g,"/"),y.startsWith(".")&&(y=Scr.posix.join("..",y));let E=this.getImportName(y),A={type:qo.Identifier,parent:o.parent,value:E};o.value=A}replaceEnvStatements=elt(Tcr,this.errors,EH)};function rlt(s){return`(request, context) => {
|
|
575
|
+
`),exitCode:E},"Untar process logs")}}t(pZt,"untarFile");async function dZt(s){if(await sAe(s))return await GN.rm(s,{recursive:!0})}t(dZt,"deleteFolder");var nu=aAe;var alt=R_(Lst(),1);import{AssertionError as zer}from"node:assert";function $P(s,o){if(s===!1)throw new zer({message:o})}t($P,"assert");var qo;(function(s){s.Object="Object",s.Property="Property",s.Array="Array",s.Literal="Literal",s.TemplateString="TemplateString",s.Identifier="Identifier",s.FunctionCall="FunctionCall",s.Raw="Raw"})(qo||(qo={}));function H9(s){return s.type===qo.Object}t(H9,"isAstObject");function WP(s){return s.type===qo.Property}t(WP,"isAstProperty");function UAe(s){return s.type===qo.Array}t(UAe,"isAstArray");function pO(s){return s.type===qo.Literal}t(pO,"isAstLiteral");function XN(s){if(s===void 0)throw new Error("Node is undefined");if(!H9(s))throw new Error("Node is not object")}t(XN,"assertAstObject");import{findNodeAtLocation as Jer,getNodeValue as $er,printParseErrorCode as Wer,visit as qer}from"jsonc-parser";var Ver={DEFAULT:{allowTrailingComma:!1}};function $V(s,o=[],f=Ver.DEFAULT){let d={type:"array",offset:-1,length:-1,line:-1,column:-1,children:[],parent:void 0};function y(q){d.type==="property"&&(d.length=q-d.offset,d=d.parent)}t(y,"ensurePropertyComplete");function E(q){return d.children?.push(q),q}t(E,"onValue"),qer(s,{onObjectBegin:t((q,K,ye,le)=>{d=E({type:"object",offset:q,length:-1,line:ye+1,column:le+1,parent:d,children:[]})},"onObjectBegin"),onObjectProperty:t((q,K,ye,le,se)=>{d=E({type:"property",offset:K,length:-1,line:le+1,column:se+1,parent:d,children:[]}),d.children?.push({type:"string",value:q,offset:K,length:ye,line:le,column:se,parent:d})},"onObjectProperty"),onObjectEnd:t((q,K)=>{y(q+K),d.length=q+K-d.offset,d=d.parent,y(q+K)},"onObjectEnd"),onArrayBegin:t((q,K,ye,le)=>{d=E({type:"array",offset:q,length:-1,line:ye+1,column:le+1,parent:d,children:[]})},"onArrayBegin"),onArrayEnd:t((q,K)=>{d.length=q+K-d.offset,d=d.parent,y(q+K)},"onArrayEnd"),onLiteralValue:t((q,K,ye,le,se)=>{E({type:Her(q),offset:K,length:ye,line:le+1,column:se+1,parent:d,value:q}),y(K+ye)},"onLiteralValue"),onSeparator:t((q,K)=>{d.type==="property"&&(q===":"?d.colonOffset=K:q===","&&y(K))},"onSeparator"),onError:t((q,K,ye,le,se)=>{o.push({error:q,offset:K,length:ye,line:le+1,column:se+1})},"onError")},f);let R=d.children?.[0];return R&&delete R.parent,R}t($V,"parse");function Her(s){switch(typeof s){case"boolean":return"boolean";case"number":return"number";case"string":return"string";case"object":{if(s){if(Array.isArray(s))return"array"}else return"null";return"object"}default:return"null"}}t(Her,"getNodeType");function G9(s,o){return Jer(s,o)}t(G9,"findNodeAtLocation");function WV(s){return $er(s)}t(WV,"getNodeValue");function Rst(s){return Wer(s)}t(Rst,"printParseErrorCode");var qV=class{static{t(this,"AstAdapter")}parse(o){let d=$V(o,[]);if(d)return this.parseNode(d,void 0);throw new Error("Failed to parse JSON")}convert(o){return this.parseNode(o,void 0)}parseNode(o,f){switch(o.type){case"object":return this.createObject(o,f);case"array":return this.createArray(o,f);case"property":return this.createProperty(o,f);case"string":return this.createLiteral(o,f);case"number":return this.createLiteral(o,f);case"boolean":return this.createLiteral(o,f);case"null":return this.createLiteral(o,f)}}createLiteral(o,f){return{type:qo.Literal,location:{line:o.line,column:o.column},parent:f,value:o.type==="null"?null:o.value}}createObject(o,f){let d={type:qo.Object,children:[],parent:f,location:{line:o.line,column:o.column}};return o.children?.forEach(y=>{d.children.push(this.parseNode(y,d))}),d}createProperty(o,f){$P(o.children?.length===2,"Invalid property node");let d={type:qo.Property,location:{line:o.line,column:o.column},parent:f,name:null,value:null};return d.name={value:o.children[0].value,location:{line:o.line,column:o.column},type:qo.Identifier,parent:d},d.value=this.parseNode(o.children[1],d),d}createArray(o,f){let d={type:qo.Array,location:{line:o.line,column:o.column},parent:f,children:[]};return o.children?.forEach(y=>d.children.push(this.parseNode(y,d))),d}};var PS={createLiteral:t((s,o)=>({type:qo.Literal,parent:o,value:s}),"createLiteral"),createTemplateString:t((s,o)=>({type:qo.TemplateString,parent:o,value:s}),"createTemplateString"),createIdentifier:t((s,o)=>({type:qo.Identifier,value:s,parent:o}),"createIdentifier"),createProperty:t((s,o,f)=>{let d={type:qo.Property,parent:f,name:null,value:o};return d.name={value:s,type:qo.Identifier,parent:d},d.value.parent=d,d},"createProperty"),createArrayOfLiterals:t((s,o)=>{let f={type:qo.Array,parent:o,children:[]};for(let d of s)f.children.push(PS.createLiteral(d,f));return f},"createArrayOfLiterals")};var Ger=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/,VV=class{static{t(this,"SourceGenerator")}generate(o){let f=[];return this.generateSource(f,o),f.join("")}generateSource(o,f){switch(f.type){case qo.Array:return this.generateArray(o,f);case qo.Object:return this.generateObject(o,f);case qo.Property:return this.generateProperty(o,f);case qo.Literal:return this.generateLiteral(o,f);case qo.FunctionCall:return this.generateFunctionCall(o,f);case qo.Identifier:return this.generateIdentifier(o,f);case qo.Raw:return this.generateRaw(o,f);case qo.TemplateString:return this.generateTemplateString(o,f)}}generateArray(o,f){o.push("["),f.children.map(d=>{this.generateSource(o,d),o.push(",")}),o.push("]")}generateObject(o,f){o.push("{"),f.children.forEach(d=>{this.generateSource(o,d),o.push(",")}),o.push("}")}generateProperty(o,f){this.generateIdentifier(o,f.name),o.push(":"),this.generateSource(o,f.value)}generateFunctionCall(o,f){o.push(f.name.value),o.push("("),f.children.forEach((d,y,E)=>{this.generateSource(o,d),y<E.length&&o.push(",")}),o.push(")")}generateRaw(o,f){o.push(f.value)}generateTemplateString(o,f){o.push("`"),o.push(f.value.replaceAll("`","\\`")),o.push("`")}generateLiteral(o,f){if(f.value===null)return o.push("null");switch(typeof f.value){case"number":case"boolean":return o.push(`${f.value}`);case"string":{let d=f.value,y=JSON.stringify(d);return o.push(`${y}`)}}}generateIdentifier(o,f){let d=Ger.test(f.value)?f.value:`'${f.value}'`;o.push(d)}};import Yer from"node:fs/promises";import{parse as Ker}from"@swc/core";var Mst=t(async s=>{let o=new Set;try{let f=await Yer.readFile(s,"utf-8");(await Ker(f,{syntax:"typescript"})).body.forEach(y=>{y.type==="ExportDefaultDeclaration"||y.type==="ExportDefaultExpression"?o.add("default"):y.type==="ExportDeclaration"&&y.declaration.type==="FunctionDeclaration"?o.add(y.declaration.identifier.value):y.type==="ExportDeclaration"&&y.declaration.type==="VariableDeclaration"&&y.declaration.declarations[0].id.type==="Identifier"&&o.add(y.declaration.declarations[0].id.value)})}catch{return null}return o},"getJSFileExports");var jst=["ai-gateway-akamai-firewall","ai-gateway-auth","ai-gateway-configuration-executor","ai-gateway-configuration-loader","ai-gateway-dlp","ai-gateway-fallback-model","ai-gateway-galileo-tracing","ai-gateway-load-balancing","ai-gateway-metering","ai-gateway-model-filtering","ai-gateway-model-override","ai-gateway-opik-tracing","ai-gateway-prompt-injection","ai-gateway-semantic-cache","ai-gateway-smart-router","akamai-firewall-for-ai","prompt-injection","semantic-cache"],Bst={"ai-gateway-akamai-firewall-inbound":"ai-gateway-akamai-firewall","ai-gateway-auth-inbound":"ai-gateway-auth","ai-gateway-auth-v2":"ai-gateway-auth","ai-gateway-auth-v2-inbound":"ai-gateway-auth","ai-gateway-configuration-executor-inbound":"ai-gateway-configuration-executor","ai-gateway-configuration-executor-v2":"ai-gateway-configuration-executor","ai-gateway-configuration-executor-v2-inbound":"ai-gateway-configuration-executor","ai-gateway-configuration-loader-inbound":"ai-gateway-configuration-loader","ai-gateway-configuration-loader-v2":"ai-gateway-configuration-loader","ai-gateway-configuration-loader-v2-inbound":"ai-gateway-configuration-loader","ai-gateway-dlp-inbound":"ai-gateway-dlp","ai-gateway-fallback-model-inbound":"ai-gateway-fallback-model","ai-gateway-fallback-model-v2":"ai-gateway-fallback-model","ai-gateway-fallback-model-v2-inbound":"ai-gateway-fallback-model","ai-gateway-galileo-tracing-inbound":"ai-gateway-galileo-tracing","ai-gateway-load-balancing-inbound":"ai-gateway-load-balancing","ai-gateway-metering-inbound":"ai-gateway-metering","ai-gateway-metering-v2":"ai-gateway-metering","ai-gateway-metering-v2-inbound":"ai-gateway-metering","ai-gateway-model-filtering-inbound":"ai-gateway-model-filtering","ai-gateway-model-filtering-v2":"ai-gateway-model-filtering","ai-gateway-model-filtering-v2-inbound":"ai-gateway-model-filtering","ai-gateway-model-override-inbound":"ai-gateway-model-override","ai-gateway-opik-tracing-inbound":"ai-gateway-opik-tracing","ai-gateway-semantic-cache-inbound":"ai-gateway-semantic-cache","ai-gateway-semantic-cache-inbound-v2":"ai-gateway-semantic-cache","ai-gateway-semantic-cache-v2":"ai-gateway-semantic-cache","ai-gateway-semantic-cache-v2-inbound":"ai-gateway-semantic-cache","ai-gateway-smart-router-inbound":"ai-gateway-smart-router","akamai-ai-firewall-inbound-v2":"ai-gateway-akamai-firewall","akamai-ai-firewall-v2":"ai-gateway-akamai-firewall","akamai-ai-firewall-v2-inbound":"ai-gateway-akamai-firewall","akamai-firewall-for-ai-inbound":"akamai-firewall-for-ai","akamai-firewall-for-ai-outbound":"akamai-firewall-for-ai","comet-opik-tracing-inbound-v2":"ai-gateway-opik-tracing","comet-opik-tracing-v2":"ai-gateway-opik-tracing","comet-opik-tracing-v2-inbound":"ai-gateway-opik-tracing","galileo-tracing-inbound-v2":"ai-gateway-galileo-tracing","galileo-tracing-v2":"ai-gateway-galileo-tracing","galileo-tracing-v2-inbound":"ai-gateway-galileo-tracing","prompt-injection-outbound":"prompt-injection","semantic-cache-inbound":"semantic-cache"};var Ust={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/fragments.schema.json",$defs:{corsPolicyConfiguration:{type:"object",required:["name","allowedOrigins"],additionalProperties:!1,properties:{name:{type:"string",pattern:"^[0-9a-z-]+$"},allowCredentials:{type:"boolean"},maxAge:{type:"number"},allowedOrigins:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]},allowedMethods:{oneOf:[{type:"array",items:{$ref:"fragments.schema.json#/$defs/httpMethod"}},{type:"string"}]},allowedHeaders:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]},exposeHeaders:{oneOf:[{type:"array",items:{type:"string"}},{type:"string"}]}}},handlerDefinition:{type:"object",properties:{module:{type:"string",pattern:"^\\$import\\([^ )]*?\\)$"},export:{type:"string"},options:{type:"object",additionalProperties:!0}},additionalProperties:!1,required:["module","export"]},httpMethod:{type:"string",enum:["GET","HEAD","POST","PUT","DELETE","CONNECT","OPTIONS","TRACE","PATCH"]}}};var zAe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/policies.schema.json",title:"Policies Config File",type:"object",additionalProperties:!1,properties:{policies:{type:"array",items:{$ref:"policy-configuration.schema.json"}},corsPolicies:{type:"array",items:{$ref:"fragments.schema.json#/$defs/corsPolicyConfiguration"}}}};var zst={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/policy-configuration.schema.json",title:"Policy Configuration Fragment",type:"object",required:["name","policyType","handler"],additionalProperties:!1,properties:{name:{type:"string",pattern:"^[0-9a-z-]+$"},policyType:{type:"string"},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},options:{type:"object",additionalProperties:!0}}};var JAe={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/route-configuration.schema.json",title:"Route Configuration Fragment",description:"",type:"object",required:["path","methods","handler"],additionalProperties:!1,$defs:{corsPolicy:{type:"string",pattern:"^[0-9a-z-]+$"}},properties:{operationId:{type:"string"},path:{type:"string",pattern:"^/[^\\s]*$"},methods:{type:"array",items:{$ref:"fragments.schema.json#/$defs/httpMethod"}},label:{type:"string",description:"An internal user-friendly identifier of the route."},enforceOpenApi:{type:"boolean",description:"If true, schema validation found in the OpenAPI spec will be enforced on requests/responses."},key:{type:"string",deprecated:!0},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},corsPolicy:{$ref:"#/$defs/corsPolicy"},custom:{},mcp:{type:"object",additionalProperties:!1,properties:{enabled:{type:"boolean"}}},policies:{type:"object",additionalProperties:!1,properties:{inbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}},outbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}}}},summary:{type:"string"},description:{type:"string"},excludeFromOpenApi:{type:"boolean"},tags:{type:"array",items:{type:"string"}}}};var $Ae={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"http://schemas.zuplo.com/route-configuration-open-api.schema.json",title:"Open API Route Configuration Fragment",description:"These are the properties that can appear under the x-zuplo-route extension in a PathObject in Open API. It's a subset of what can appear in Zuplo's routes.json.",type:"object",required:["handler"],additionalProperties:!1,properties:{label:{type:"string",description:"An internal user-friendly identifier of the route."},key:{type:"string",deprecated:!0},handler:{$ref:"fragments.schema.json#/$defs/handlerDefinition"},corsPolicy:{type:"string",pattern:"^[0-9a-z-]+$"},custom:{},mcp:{oneOf:[{type:"object",additionalProperties:!1,properties:{type:{const:"tool"},name:{type:"string"},description:{type:"string"},enabled:{type:"boolean"},includeOutputSchema:{type:"boolean"},includeStructuredContent:{type:"boolean"},toolInputStyle:{enum:["flat","nested"]},annotations:{type:"object",additionalProperties:!1,properties:{title:{type:"string"},readOnlyHint:{type:"boolean"},destructiveHint:{type:"boolean"},idempotentHint:{type:"boolean"},openWorldHint:{type:"boolean"}}},_meta:{type:"object",additionalProperties:!0}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"prompt"},name:{type:"string"},description:{type:"string"},enabled:{type:"boolean"}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"resource"},name:{type:"string"},description:{type:"string"},uri:{type:"string"},mimeType:{type:"string"},enabled:{type:"boolean"},_meta:{type:"object",additionalProperties:!0}},required:["type"]},{type:"object",additionalProperties:!1,properties:{type:{const:"graphql"},enabled:{type:"boolean"},introspectionTool:{type:"object",additionalProperties:!1,properties:{name:{type:"string"},description:{type:"string"}}},executeTool:{type:"object",additionalProperties:!1,properties:{name:{type:"string"},description:{type:"string"}}}},required:["type"]}]},policies:{type:"object",additionalProperties:!1,properties:{inbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}},outbound:{type:"array",items:{type:"string",pattern:"^[0-9a-z-]+$"}}}},tags:{type:"array",items:{type:"string"}}}};var Kct=R_(Xce(),1),Xct=R_(tle(),1);var rle=class s{static{t(this,"JsonValidator")}static#e=new s;static get instance(){return s.#e}ajv;constructor(){this.ajv=new Kct.Ajv2020({allErrors:!0,allowUnionTypes:!0}),this.ajv.addKeyword("faker"),(0,Xct.default)(this.ajv,{mode:"fast"})}addSchema(o,f){this.ajv.addSchema(o,f)}compile(o){let f=this.ajv.compile(o);return t(y=>({isValid:f(y),errors:this.toSimpleErrors(f.errors,y),warnings:[]}),"validator")}toSimpleErrors(o,f){let d=[];return o?.forEach(y=>{y.keyword==="enum"&&y.params.allowedValues&&Array.isArray(y.params.allowedValues)&&(y.message+=`; ${y.params.allowedValues.join(", ")}`),y.instancePath&&(y.instancePath=y.instancePath.replaceAll(/(\/)?(~1)(\/)?/gm,"/"));let E={details:{}},A=y.instancePath.split("/");if(A.length>2){let q=A[1],K=A[2]?parseInt(A[2],10):0,ye=A[3],le=Number.isNaN(K)?void 0:f[q][K][ye];E={details:{property:q,index:K,field:ye,fieldValue:le}}}if(y.keyword==="required"&&y.params.missingProperty&&y.instancePath&&(y.message=`A 'path' is missing required property '${y.params.missingProperty}'`),y.keyword==="additionalProperties"&&y.params.additionalProperty&&y.instancePath&&(y.message=`A 'path' should NOT include property '${y.params.additionalProperty}'`),y.keyword==="type"&&y.params.type&&y.instancePath){let q=y.instancePath.split("/"),K=q[q.length-1];y.message=`Value of property '${K}' must be '${y.params.type}'`}let R=Object.assign(y,E);d.push(R)}),d}};var oI=rle.instance;oI.addSchema(JAe,"route-configuration.schema.json");oI.addSchema(zst,"policy-configuration.schema.json");oI.addSchema(zAe,"policies.schema.json");oI.addSchema($Ae,"open-api-route-configuration.schema.json");oI.addSchema(Ust,"fragments.schema.json");var P6r=oI.compile(JAe),Zct=oI.compile($Ae),sIe=oI.compile(zAe);var nle=class{static{t(this,"PoliciesConfigurationValidator")}results;validate(o){return this.results=sIe(o),this.results}};var ile=class{static{t(this,"OpenAPILocalizedValidator")}results;validate(o){return this.results=Zct(o),this.results}};import Scr from"node:path";var aIe=/\$import\((.*)\)/,xH=/\$env\((.*?)\)/g;var Uk=class extends Error{static{t(this,"CodeGenError")}location;constructor(o,f,d,y){super(o),this.location={file:f,namespace:"",line:d?d.line:0,column:d?d.column:0,length:0,lineText:y??"",suggestion:""}}},bcr=t(s=>{let o=[],f=s;for(;f.parent;)o.push(f),f=f.parent;return o.reverse()},"invertTree"),GP=t((s,o)=>{if(!s)return!1;let f=bcr(s);return o.split("/").every((E,A)=>{let R=f[A];return R?E==="*"||WP(R)&&R.name.value===E?!0:E==="{}"?R.type===qo.Object:E==="[]"?R.type===qo.Array:!1:!1})},"testPosition");var sle=class{static{t(this,"AstTransformer")}errors=[];transform(o){return this.visitor(o),o}visitor(o){this.visit(o),H9(o)?o.children.forEach(f=>{this.visitor(f)}):UAe(o)?o.children.forEach(f=>{this.visitor(f)}):WP(o)&&this.visitor(o.value)}},Qct=t(s=>{let o=new RegExp(xH).exec(s);if(o?.length===2&&o[0]===s)return{type:"raw",value:`environment["${o[1]}"]`};{let f=s.replaceAll(new RegExp(xH),(d,y)=>`\${environment["${y}"] ? environment["${y}"] : ""}`);if(f!==s)return{type:"template",value:f}}return null},"replaceEnvInString"),elt=t((s,o,f)=>d=>{if(pO(d)&&typeof d.value=="string"&&d.parent&&UAe(d.parent)){if(!s.some(A=>GP(d.parent,A))){xH.test(d.value)&&o.push(new Uk("An $env() statement is not expected at this location.",f,d.location,d.value));return}let E=Qct(d.value);if(E){let A=d.parent,R=A.children.indexOf(d);if(R!==-1)if(E.type==="raw"){let q={type:qo.Raw,parent:A,value:E.value};A.children[R]=q}else A.children[R]=PS.createTemplateString(E.value,d)}return}if(!WP(d)||!pO(d.value)||typeof d.value.value!="string")return;if(!s.some(E=>GP(d,E))){xH.test(d.value.value)&&o.push(new Uk("An $env() statement is not expected at this location.",f,d.location,d.value.value));return}let y=Qct(d.value.value);if(y)if(y.type==="raw"){let E={type:qo.Raw,parent:null,value:y.value};d.value=E}else d.value=PS.createTemplateString(y.value,d)},"getEnvStatementTransformer");var EH="config/routes.json",Tcr=["handler/{}/options/*","handler/{}/options/*/[]","policies/[]/{}/handler/{}/options/*","policies/[]/{}/handler/{}/options/*/[]","corsPolicies/[]/{}/*","corsPolicies/[]/{}/*/[]"],xcr=["handler/{}/module","handler/{}/options/{}/policies/{}/inbound/[]/{}/module","handler/{}/options/{}/policies/{}/outbound/[]/{}/module","handler/{}/options/{}/onOpen/{}/module","policies/[]/{}/handler/{}/module","policies/[]/{}/handler/{}/options/{}/identifier/{}/module","policies/[]/{}/handler/{}/options/{}/validator"],tlt=["handler/{}/options/*","policies/[]/{}/handler/{}/options/*"],Ecr="handler/{}/options/{}/rewritePattern",Ccr="handler/{}/options/{}/baseUrl",ale=class extends sle{static{t(this,"OpenAPIRoutesFragmentAstTransformer")}importCount=0;addedImports=new Map;getImportName(o){this.addedImports.has(o)||this.addedImports.set(o,`__import${this.importCount++}`);let f=this.addedImports.get(o);if(!f)throw new Error("Import name is undefined. This should not happen.");return f}getImports(){let o=[];return this.addedImports.forEach((f,d)=>{o.push({name:f,path:d})}),o}visit(o){this.rewriteHandlerFunction(o),this.rewriteForwardFunction(o),this.replaceImportStatements(o),this.replaceEnvStatements(o)}rewriteHandlerFunction(o){if(!(!WP(o)||!pO(o.value)||typeof o.value.value!="string")&&GP(o,Ecr)){if(!o.parent||!H9(o.parent)){this.errors.push(new Uk("Invalid node, expected object",EH,o.parent?o.parent.location:o.location,void 0));return}let f=o.value.value,d={type:qo.Raw,parent:null,value:rlt(f)},y=PS.createProperty("__rewriteFunction",d,o);o.parent.children.push(y)}}rewriteForwardFunction(o){if(!(!WP(o)||!pO(o.value)||typeof o.value.value!="string")&&GP(o,Ccr)){if(!o.parent||!H9(o.parent)){this.errors.push(new Uk("Invalid node, expected object",EH,o.parent?o.parent.location:o.location,void 0));return}let f=o.value.value,d={type:qo.Raw,parent:null,value:rlt(f)},y=PS.createProperty("__rewriteFunction",d,o);o.parent.children.push(y)}}replaceImportStatements(o){if(!WP(o)||!pO(o.value))return;let f=o.value.value;if(typeof f!="string")return;if(!xcr.some(R=>GP(o,R))&&!tlt.some(R=>GP(o,R))){if(aIe.test(f)){if(o.name.value==="$ref")return;this.errors.push(new Uk("An $import() statement is not expected at this location.",EH,o.location,f))}return}let d=aIe.exec(f);if(tlt.some(R=>GP(o,R))&&!d)return;if(!d){this.errors.push(new Uk("Invalid $import() statement",EH,o.location,f));return}let y=d[1];y=y.replace(/\\/g,"/"),y.startsWith(".")&&(y=Scr.posix.join("..",y));let E=this.getImportName(y),A={type:qo.Identifier,parent:o.parent,value:E};o.value=A}replaceEnvStatements=elt(Tcr,this.errors,EH)};function rlt(s){return`(request, context) => {
|
|
576
576
|
const { params, url, query, method, headers } = request;
|
|
577
577
|
const { host, hostname, origin, pathname, port, search } = new URL(url);
|
|
578
578
|
const e = encodeURIComponent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zuplo/core",
|
|
3
|
-
"version": "7.9.
|
|
3
|
+
"version": "7.9.19",
|
|
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": "7.9.
|
|
44
|
-
"@zuplo/otel": "7.9.
|
|
45
|
-
"@zuplo/runtime": "7.9.
|
|
43
|
+
"@zuplo/graphql": "7.9.19",
|
|
44
|
+
"@zuplo/otel": "7.9.19",
|
|
45
|
+
"@zuplo/runtime": "7.9.19",
|
|
46
46
|
"deno": "2.8.3"
|
|
47
47
|
}
|
|
48
48
|
}
|