"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("./replay-index-wIVtujmr.js");async function ho(r){const{descriptionPath:t,externalRefResolver:e,base:n}=r,a=await d.bundle({base:n,ref:t,config:r.config,dereference:!0,externalRefResolver:e});if(!a)throw new Error(`Could not find source description file '${t}'.`);return a.bundle.parsed}function Nt(r){if(typeof r!="object")return;const t=Object.keys(r)[0];return t?r[t]?.value:void 0}const go=r=>/\{.*?\}/.test(r);function oe({value:r,ctx:t,logger:e}){if(!r)return r;if(typeof r=="object"){for(const n in r)r[n]=oe({value:r[n],ctx:t,logger:e});return r}return typeof r=="number"||typeof r=="boolean"?r:r.toString().startsWith("$faker.")?De({pointer:r.slice(1),ctx:t,logger:e}):go(r)?$o(r,t,e):vo(r,t,e)}function mo(r,t,e){const n=r.indexOf("{");if(n!==-1){const c=r.substring(n+1).slice(0,-1),f=De({pointer:c.slice(1),ctx:t,logger:e});return f&&r.replace(/{(.*)}/,f)}else return r}function yo(r,t){const e=Object.keys(t),n=Object.values(t);return new Function(...e,`return ${r}`)(...n)}function $o(r,t,e){const n=/\{\$(\{[^{}]*\}|[^{}])*\}/g;let a=r;return a=a.replace(n,(c,f)=>wo(c,t,e)),a}function wo(r,t,e){if(!r.includes("$"))return r;if(r.includes("$faker."))return mo(r,t,e);const n=Fe(t)(Eo(r));return n!==void 0?n:""}const vo=(r,t,e)=>{if(!r)return r;const n=r.toString();if(!n.includes("$"))return r;if(n.startsWith("$file(")&&n.endsWith(")"))return n.slice(7,-2);if(n.startsWith("$sourceDescriptions.")&&n.includes(".workflows.")){const a=n.split("."),c=a[1],f=a[3];if(!c||!f)return;const l=Fe(t)("$sourceDescriptions");return l[c]?l[c].workflows.find(g=>g.workflowId===f):void 0}return n&&n.trim().startsWith("faker.")?De({pointer:n,ctx:t,logger:e}):n?Fe(t)(kt(n)):n.replace(/\$\{([^}]+)}/g,(a,c)=>Fe(t)(kt(c)))};function Eo(r){return r.replace(/\{(.*)\}/,"$1")}function kt(r){return r.replace(/\['(.*?)'\]/g,".$1")}const Fe=(r,t="")=>e=>{if(t||(t=e),!e)return r;const[n,...a]=e.split(".");if(!r)throw Error(`Cannot get ${d.red(n)} from ${d.red(t)}`);if(r?.[n]===void 0){const c=` Undefined ${d.red(n)} at ${d.red(t)}.`,f=Object.keys(r).length?`Did you mean to use another key? Available keys:
${Object.keys(r).join(", ")}.
`:"",l=`${c} ${f}`;throw Error(l)}return Fe(r[n],t)(a.join("."))};function De({pointer:r,ctx:t,logger:e}){const n=r.split("."),a={ctx:{faker:t.$faker}};try{const c=n.map(f=>f.trim()).map((f,l)=>f.endsWith(")")?`${l==0?"":"."}${f}`:`["${f}"]`).join("");return yo(`ctx${c}`,a)}catch(c){e.error(d.red(c.toString()));return}}function jt(r,t,e){if(typeof r=="string"&&r)return oe({value:r,ctx:t,logger:e});if(!(typeof r=="string"||typeof r=="number"||typeof r=="boolean"||typeof r>"u"||r instanceof Blob||r===null))for(const n in r)typeof r[n]=="string"?r[n]&&(r[n]=oe({value:r[n],ctx:t,logger:e})):jt(r[n],t,e)}function St(r,t,e){return jt(r,t,e)||r}function Ct(r,t){if(!r)return;const e={};for(const n in t)e[`{${n}}`]=String(t[n]);return r.split(/(\{[a-zA-Z0-9_.-]+\}+)/g).map(n=>e[n]?e[n]:n).join("")}function ko(r){return typeof r=="object"&&r!==null&&"name"in r&&"value"in r&&!("in"in r)}function Ir(r){return typeof r=="object"&&r!==null&&"in"in r&&["header","query","path","cookie"].includes(r.in)}const So=/^image\/(png|jpeg|gif|bmp|webp|svg\+xml)|application\/pdf$/;function Wt(r){return r.startsWith("$file(")&&r.endsWith(")")?r.substring(7,r.length-2):r}const bt=async(r,t,e,n,a)=>{const c=d.pathBrowserifyExports.dirname(n),f=d.pathBrowserifyExports.resolve(c,Wt(e));r.append(t,await a.options.requestFileLoader.getFileBody(f))},qt=(r,t,e,n,a,c)=>{Object.entries(e).forEach(([f,l])=>{const g=c?`${c}[${f}]`:f;typeof l=="string"&&l.startsWith("$file(")&&l.endsWith(")")?r.push(bt(t,g,l,n,a)):Array.isArray(l)?l.forEach(h=>{typeof h=="string"&&h.startsWith("$file(")&&h.endsWith(")")?r.push(bt(t,g,h,n,a)):t.append(g,h.toString())}):typeof l=="object"&&l!==null?qt(r,t,l,n,a,g):(typeof l=="string"||typeof l=="number"||typeof l=="boolean")&&t.append(g,l.toString())})},Co=async(r,t,e,n)=>{if(r&&typeof r=="object"&&!Array.isArray(r)){const a=[];qt(a,t,r,e,n),await Promise.all(a)}},bo=async(r,t)=>{if(typeof r=="string"&&r.startsWith("$file(")&&r.endsWith(")")){const e=d.pathBrowserifyExports.resolve(d.pathBrowserifyExports.dirname(t.options.filePath),Wt(r));return t.options.requestFileLoader.getFileBody(e)}else return r};async function Ao(r,t){if(!r)return{payload:void 0,contentType:void 0,encoding:void 0,replacements:void 0};const{payload:e,contentType:n}=r;if(n==="multipart/form-data"){const a=new FormData,c=d.pathBrowserifyExports.resolve(t.options.filePath);return await Co(e,a,c,t),{...r,payload:a}}else{if(n==="application/octet-stream"||typeof n=="string"&&So.test(n))return{...r,payload:await bo(e,t),contentType:"application/octet-stream"};if(n==="application/x-www-form-urlencoded"&&typeof e=="string")return{...r,payload:Object.fromEntries(new URLSearchParams(e).entries()),contentType:"application/x-www-form-urlencoded"}}return r}function Ro(r){try{return d.parseRuntimeExpression(r)}catch{throw new Error(`Runtime expression is not valid: ${r}`)}}function Oo(r,t){const e=[{pattern:/\$response\.body#\/([\w/]+)/g,ctxFunction:(a,c)=>Te(t.$response?.body,c,a)},{pattern:/\$request\.body#\/([\w/]+)/g,ctxFunction:(a,c)=>Te(t.$request?.body,c,a)},{pattern:/\$outputs\.([\w-]+)#\/([\w/]+)/g,ctxFunction:(a,c,f)=>Te(t.$outputs?.[c],f,a)},{pattern:/\$workflows\.([\w-]+)\.outputs\.([\w-]+)#\/([\w/]+)/g,ctxFunction:(a,c,f,l)=>Te(t.$workflows?.[c]?.outputs?.[f],l,a)},{pattern:/\$steps\.([\w-]+)\.outputs\.([\w-]+)#\/([\w/]+)/g,ctxFunction:(a,c,f,l)=>Te(t.$steps?.[c]?.outputs?.[f],l,a)}];let n=r;for(const{pattern:a,ctxFunction:c}of e)n=n.replaceAll(a,c);return n}function Te(r,t,e){if(r)try{const n=d.pointer.get(r,`/${t}`);return typeof n=="string"||Array.isArray(n)||typeof n=="object"?JSON.stringify(n):n!==void 0?n:e}catch{return e}return e}function re({payload:r,context:t,contentType:e,logger:n}){if(e?.includes("application/octet-stream"))return St(r,t,n);if(e?.includes("multipart/form-data")){if(r instanceof FormData){const a=new FormData;for(const[c,f]of r.entries())if(f instanceof File)a.append(c,f);else{const l=re({payload:f,context:t,logger:n});a.append(c,l)}return a}return St(r,t,n)}return typeof r=="string"?No(r)?ye(r,t,n):Lo(r,t,n):d.isPlainObject(r)?Object.entries(r).reduce((a,[c,f])=>(a[c]=re({payload:f,context:t,logger:n}),a),{}):Array.isArray(r)?r.map(a=>re({payload:a,context:t,logger:n})):r}function ye(r,t,e){return typeof r=="string"?To(r,t,e):d.isPlainObject(r)?Object.entries(r).reduce((n,[a,c])=>(n[a]=c&&ye(c,t,e),n),{}):Array.isArray(r)?r.map(n=>ye(n,t,e)):r}function To(r,t,e){if(/^\$faker\.[a-zA-Z0-9._-]+(\([^\\)]*\))?$/.test(r))return De({pointer:r.slice(1),ctx:t,logger:e});if(r.includes("$faker.")){const c=/\$faker\.[a-zA-Z0-9._-]+(\([^\\)]*\))?/g;r=r.replace(c,f=>De({pointer:f.slice(1),ctx:t,logger:e})).replace(/{(.*?)}/g,"$1")}if(!r.includes("$")&&!/[=<>]/.test(r))return r;Ro(r);const n=_o(r,t),a=Fo(t);try{return new Function(...Object.keys(a),`return ${n};`)(...Object.values(a))}catch{throw new Error(`Error in resolving runtime expression '${r}'. 
This could be because the expression references a value from a previous failed step, or is trying to reference a variable that hasn't been set.`)}}function Po(r){return r.replace(/\$([a-zA-Z0-9._-]+)/g,(t,e)=>`$${e.replace(/-/g,"_")}`)}function _o(r,t){const e=Oo(r,t),a=Po(e).replace(/{(.*?)}/g,"$1"),c=Do(a),f=/\.header\.([a-zA-Z0-9._-]+)/g;return c.replace(f,(g,h)=>`.header.${h.toLowerCase()}`)}function Fo(r){const t={};for(const[e,n]of Object.entries(r)){const a=e.replace(/-/g,"_");t[a]=Ut(n)}return t}function Ut(r){return Array.isArray(r)?r:typeof r=="object"&&r!==null?Io(r):r}function Io(r){return Object.keys(r).reduce((t,e)=>{const n=e.replace(/-/g,"_");return t[n]=Ut(r[e]),t},{})}function Do(r){return r.replace(/\.(\d+)/g,(t,e,n,a)=>{const c=a[n-1];return/\d/.test(c)?t:`[${e}]`})}function Lo(r,t,e){const n=/\{(?:[^{}]|\{[^{}]*\})*\}|\$[^\s{}]+(?:\([^()]*\))*/g;return r.replace(n,a=>{const c=a.trim(),f=ye(c,t,e);return f!==void 0?f:a})}function No(r){return/^\$[^\s{}]+(\([^)]*\))?$|^\{[^{}]*\}$/.test(r.trim())}function jo({payload:r,replacements:t,expressionContext:e,logger:n}){for(const a of t){const{target:c,value:f}=a;if(typeof c!="string")throw new Error(`Invalid JSON Pointer: ${c}`);try{const l=d.pointer.get(r,c),g=re({payload:f,context:e,logger:n});l!==void 0&&d.pointer.set(r,c,g)}catch{throw new Error(`Invalid JSON Pointer: ${c}`)}}}const Wo=["parameters","failureActions","successActions"];function qo(r,t){const{reference:e,value:n}=r;if(!Wo.some(c=>e.includes(`$components.${c}`)))throw new Error("Invalid reference: available components are $components.parameters, $components.failureActions, or $components.successActions");const a=oe({value:e,ctx:t,logger:t.options.logger});return"value"in a&&n?{...a,value:n}:a}function _e(r,t){return"reference"in r?qo(r,t):r}function Uo(r,t){const e=r?.requestBody?.content||{},[n,a]=Object.entries(e)[0]||[],c=a?.example||Nt(a?.examples)||zt(a?.schema,t),f=zo(r);return{parameters:Bo([...At(r.pathParameters,t),...At(r.parameters,t)]).filter(({value:g})=>g),contentTypeParameters:[...n?[{name:"content-type",in:"header",value:n}]:[],...f?[{name:"accept",in:"header",value:f}]:[]],requestBody:c,contentType:n}}function zo(r){return r?.responses?Array.from(new Set(Object.values(r.responses).flatMap(t=>d.isPlainObject(t)&&"content"in t?Object.keys(t.content||{}):[]))).join(", "):void 0}function At(r,t){return(r||[]).filter(e=>e?.required===!0).map(e=>{if(Ir(e))return{name:e.name,in:e.in,value:Xo(e,t)}}).filter(e=>e!==void 0)}function Bo(r){const t={};for(const e of r)Ir(e)&&(t[(e.name+":"+e.in).toLowerCase()]=e);return Object.values(t)}function xo(r,t){let e,n;if(r.includes("$sourceDescriptions.")){const[,g,h]=r.split(".");e=g,n=h}else r.includes(".")?[e,n]=r.split("."):(n=r,e=Object.keys(t)[0]);const a=Object.keys(t);if(!t[e])throw new Error(`Unknown description name ${d.red(e)} at ${d.red(r)}. Available descriptions: ${a.join(", ")}.`);const c=t[e],f=c?.components?.securitySchemes,l=c.servers;for(const[g,h]of Object.entries(t[e].paths)){if(!h)return;for(const[y,w]of Object.entries(h))if(w.operationId===n)return{servers:h.servers||l,...w,pathParameters:w.parameters||[],path:g,method:y,descriptionName:e,securitySchemes:f}}throw new Error(`Unknown operationId ${d.red(n)} at ${d.red(r)}.`)}function Mo(r,t){const{$sourceDescriptions:e,sourceDescriptions:n}=t,[a,c]=r.split("#");if(!n)throw new Error("Missing described sourceDescriptions");const f=n.find(P=>{if(["openapi","arazzo"].includes(P.type)){if(a.includes("$sourceDescriptions.")){const[,N]=a.split(".");return P.name===N}return"url"in P&&P.url===a}return!1})?.name;if(!f)throw new Error(`Unknown operationPath ${d.red(r)}. API description ${d.red(a)} is not listed in 'sourceDescriptions' workflow section.`);const l=e[f]||{},g=l?.components?.securitySchemes,[h,y,w]=d.pointer.parse(c);if(h!=="paths")throw new Error(`Invalid fragment identifier: ${c} at operationPath ${d.red(r)}.`);const{servers:k}=l,C=d.pointer.get(l,c)||{},j=d.pointer.get(l,d.pointer.compile(["paths",y]))||{};return{servers:j.servers||k,...C,pathParameters:j.parameters||[],path:y,method:w,descriptionName:f,securitySchemes:g}}function Vo(r,t){if(!r.operationId&&!r.operationPath)return;const{$sourceDescriptions:e,sourceDescriptions:n}=t,{operationId:a,operationPath:c}=r;return a?xo(a,e):c?Mo(c,{$sourceDescriptions:e,sourceDescriptions:n}):void 0}function Ko({statusCode:r,contentType:t,descriptionResponses:e}){return e?(e[r]||e.default)?.content?.[t]?.schema:void 0}function Ho(r,t){if(!t)return;const n=t.requestBody?.content;return n&&n[r]?.schema||void 0}const Jo={title:"[REPLACE WITH API title]",version:"[REPLACE WITH API version]"};function zt(r,t){if(r)try{return d.sample(r,{skipReadOnly:!0,skipNonRequired:!1,quiet:!0})}catch(e){t.error(d.bgRed(" Error while generating test data from JSON Schema ")+`
`+e);return}}function Xo(r,t){if(r?.example)return r.example;if(r?.examples)return Nt(r.examples);if(r?.schema)return zt(r.schema,t)}function Qo(r){return r==null?!0:r.constructor.name==="FormData"||r instanceof Blob&&r.size>0?!1:typeof r=="object"?Object.keys(r).length===0:typeof r=="string"||Array.isArray(r)?r.length===0:!1}function Go(r){return!d.isBrowser&&process.env.NODE_ENV==="test"?"<test>ms":`${Math.ceil(performance.now()-r)}ms`}function Ye(r){const t=r.length;let e=0,n=0,a=0,c=0,f=0,l=0,g=0;const h=new Set;let y=0;const w=new Set,k=new Set;for(const C of r){const j=Bt(C.executedSteps);let P=!1;for(const N of j){if(c++,N.retriesLeft&&N.retriesLeft!==0)continue;a++;let q=!1;for(const L of N.checks)if(n++,!L.passed)switch(L.severity){case"warn":f++,h.add(C.workflowId),k.add(C.workflowId+":"+N.stepId);break;case"off":l++,w.add(C.workflowId+":"+N.stepId);break;default:e++,q=!0}q&&(y++,P=!0)}P&&g++}return{workflows:{passed:t-g,failed:g,warnings:h.size,skipped:0,total:t},steps:{passed:a-y,failed:y,warnings:k.size,skipped:w.size,total:a},checks:{passed:n-e,failed:e,warnings:f,skipped:l,total:n},totalRequests:c}}function Bt(r){return r.flatMap(t=>"executedSteps"in t?Bt(t.executedSteps):[t])}function Zo({startedAt:r,workflows:t,options:e}){const{logger:n}=e,a=d.pathBrowserifyExports.basename(e?.file||""),c=Ze(e?.workflow)||[],f=Ze(e?.skip)||[];let l=c&&c.length?t.filter(({workflowId:y})=>c.includes(y)):t;l=f&&f.length?l.filter(({workflowId:y})=>!f.includes(y)):l;const g=Ye(l),h=Go(r);n.printNewLine(),n.output(d.defaultOutdent`
        ${d.yellow(d.indent(`Summary for ${d.blue(a)}`,2))}
        ${d.indent("",2)}
        ${d.indent(Yo("Workflows:",g.workflows),2)}
        ${d.indent(Rt("Steps:",g.steps),2)}
        ${d.indent(Rt("Checks:",g.checks),2)}
        ${d.indent(d.inverse(`Time: ${h}`),2)}
  `),n.printNewLine(),n.printNewLine()}function Yo(r,t){return d.bold(r)+(t.passed?` ${d.green(t.passed+" passed")},`:"")+(t.failed?` ${d.red(t.failed+" failed")},`:"")+` ${t.total} total`}function Rt(r,t){return d.bold(r)+(t.passed?` ${d.green(t.passed+" passed")},`:"")+(t.failed?` ${d.red(t.failed+" failed")},`:"")+(t.warnings?` ${d.yellow(t.warnings+" warnings")},`:"")+(t.skipped?` ${d.gray(t.skipped+" ignored")},`:"")+` ${t.total} total`}const Ot={SUCCESS_CRITERIA_CHECK:"error",STATUS_CODE_CHECK:"error",SCHEMA_CHECK:"error",CONTENT_TYPE_CHECK:"error",GLOBAL_TIMEOUT_ERROR:"error",MAX_STEPS_REACHED_ERROR:"error",NETWORK_ERROR:"error",UNEXPECTED_ERROR:"error"};function ei(r){if(!r)return Ot;const t=Dr(r);if(Object.keys(t).length===0)throw new Error(`Failed to parse severity configuration, please check the format ${r}`);return{...Ot,...t,UNEXPECTED_ERROR:"error",NETWORK_ERROR:"error"}}function xt(r){return r.flatMap(t=>"executedSteps"in t?xt(t.executedSteps):[t])}function ri(r,t){t.output(`${d.RESET_ESCAPE_CODE}
${d.indent(d.red("Failed tests info:"),2)}
`);for(const e of r){const n=xt(e.executedSteps);if(n.some(c=>c.checks.some(f=>!f.passed)&&(!c.retriesLeft||c.retriesLeft===0))){t.output(`${d.RESET_ESCAPE_CODE}
${d.indent(d.gray("Workflow name:"),2)} ${d.underline(e.workflowId)}${d.RESET_ESCAPE_CODE}
`);for(const c of n){const f=c.checks.filter(l=>!l.passed);if(f.length&&!(c.retriesLeft&&c.retriesLeft!==0)){t.printNewLine(),t.output(d.indent(`${d.blue("stepId - ")}`,4)+(c?.stepId?d.red(c.stepId):d.red(c?.operationId||c?.operationPath||"")));for(const l in f){const{name:g,message:h,severity:y}=f[l],k=[d.CHECKS.UNEXPECTED_ERROR,d.CHECKS.GLOBAL_TIMEOUT_ERROR,d.CHECKS.MAX_STEPS_REACHED_ERROR].includes(g)?d.indent(`Reason: ${h}`,4):d.indent(`${d.removeExtraIndentation(h)}${d.RESET_ESCAPE_CODE}
`,6);t.printNewLine(),y==="error"?t.output(d.indent(`${d.red("✗")} ${d.gray(g.toLowerCase())}`,4)):y==="off"?t.output(d.indent(`${d.gray("○")} ${d.gray(g.toLowerCase())} ${d.gray("(skipped)")}`,4)):t.output(d.indent(`${d.yellow("⚠")} ${d.gray(g.toLowerCase())}`,4)),t.printNewLine(),t.output(`${k}`)}}}}}}function br({headerParams:r,path:t,method:e,host:n,body:a,statusCode:c,responseTime:f,responseSize:l}){const g={path:t,method:e,host:n};return r&&Object.keys(r).length>0&&(g.headerParams=r),a&&(a instanceof FormData||a instanceof File||a instanceof ArrayBuffer||Object.keys(a).length>0)&&(g.body=a),c&&(g.statusCode=c),f&&(g.responseTime=f),l!==void 0&&(g.responseSize=l),g}function Rr(r,t=new WeakMap){if(!Array.isArray(r)&&!d.isPlainObject(r))return r;if(t.has(r))return t.get(r);if(r instanceof ArrayBuffer||r instanceof File||r instanceof Blob||r instanceof FormData||r instanceof Date||r instanceof RegExp||r instanceof Map||r instanceof Set||r instanceof URL||r instanceof Error)return r;if(Array.isArray(r)){const n=[];t.set(r,n);for(let a=0;a<r.length;a++)n[a]=Rr(r[a],t);return n}const e={};t.set(r,e);for(const n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=Rr(r[n],t));return e}const ti=["token","access_token","id_token","password","client_secret"];function Mt(r,t){const e=(f,l)=>f.replace(l,"*".repeat(8));if(typeof r=="string"){let f=r;return t.forEach(l=>{f=f.split(l).join("*".repeat(8))}),f}const n=Rr(r),a=f=>{let l=f;for(const g of t)l.includes(g)&&(l=e(l,g));return l},c=f=>{for(const l in f)typeof f[l]=="string"?f[l]=a(f[l]):typeof f[l]=="object"&&f[l]!==null&&!(f[l]instanceof File)&&!(f[l]instanceof ArrayBuffer)&&!(f[l]instanceof Blob)&&!(f[l]instanceof FormData)&&!(f[l]instanceof Date)&&!(f[l]instanceof RegExp)&&!(f[l]instanceof Map)&&!(f[l]instanceof Set)&&!(f[l]instanceof URL)&&!(f[l]instanceof Error)&&c(f[l])};return c(n),n}function Tt(r,t=ti){const e=[];if(!r||typeof r!="object")return e;const n=a=>{if(!(!a||typeof a!="object")){if(Array.isArray(a)){for(const c of a)n(c);return}for(const c in a){const f=a[c];if(t.some(l=>l.toLowerCase()===c.toLowerCase())&&typeof f=="string"&&f.trim()&&e.push(f),typeof f=="string"&&f.trim())for(const l of t){const g=f.match(new RegExp(`${l}=([^;\\s]+)`,"i")),[,h]=g||[];h&&e.push(h)}f&&typeof f=="object"&&n(f)}}};return n(r),e}function fe({value:r,noSecretsMasking:t,secretsSet:e}){return t?r:Mt(r,e)}function Vt({ctx:r,security:t,operation:e}){const{scheme:n,schemeName:a}=t;if(n)return t.scheme;if(a){if(typeof a=="string"&&a.startsWith("$sourceDescriptions.")){const[c,f,l]=a.split("."),h=(f&&r.$sourceDescriptions[f])?.components?.securitySchemes;return l&&h?h[l]:void 0}return e?.securitySchemes?.[a]}}function si(r){const t=r.replace("Digest ","").split(",").map(a=>a.trim());return Object.fromEntries(["realm","nonce","opaque","qop","algorithm","cnonce","nc"].map(a=>[a,t.find(c=>c.startsWith(`${a}=`))?.split("=")[1]?.replace(/"/g,"")]))}const Kt="MD5",Ht="00000001";function ni({username:r,password:t,nonce:e,realm:n,cnonce:a,algorithm:c=Kt,qop:f,nc:l=Ht,opaque:g,uri:h,method:y,bodyContent:w=""}){const k={username:r,password:t,realm:n,nonce:e,qop:f,opaque:g,uri:h,method:y},C=Object.entries(k).filter(([N,q])=>!q).map(([N])=>N);if(C.length>0)throw new Error(`Missing required digest auth parameters: ${C.join(", ")}`);const j=oi({...k,cnonce:a,algorithm:c,nc:l,bodyContent:w}),P=[`username="${r}"`,`realm="${n}"`,`nonce="${e}"`,`uri="${h}"`,`qop=${f}`,`nc=${l}`,`cnonce="${a}"`,`response="${j}"`,`algorithm=${c}`];return g&&P.push(`opaque="${g}"`),`Digest ${P.join(", ")}`}function oi(r){const{username:t,password:e,realm:n,nonce:a,cnonce:c,algorithm:f=Kt,qop:l,nc:g=Ht,uri:h,method:y,bodyContent:w}=r,k=f.endsWith("-sess")?pe(f)(pe(f)(`${t}:${n}:${e}`)+`:${a}:${c}`):pe(f)(`${t}:${n}:${e}`),C=l.includes("auth-int")?pe(f)(`${y}:${h}:${pe(f)(w)}`):pe(f)(`${y}:${h}`);return pe(f)(`${k}:${a}:${g}:${c}:${l}:${C}`)}function pe(r){switch(r.replace("-sess","").toUpperCase()){case"SHA-256":return e=>d.bytesToHex(d.sha256(e));default:return e=>d.bytesToHex(d.md5(e))}}function ii(r){return["application/octet-stream","application/pdf","image/","audio/","video/","application/zip","application/x-zip-compressed","application/gzip","application/x-gzip","application/x-bzip2","application/x-tar","application/x-rar-compressed","application/x-7z-compressed","application/vnd.openxmlformats-officedocument","application/vnd.ms-excel","application/vnd.ms-powerpoint","application/msword","application/x-shockwave-flash","application/x-font-","font/","application/x-font-ttf"].some(e=>r.startsWith(e))}function Pe(r){return/^application\/([a-z.-]+\+)?json$/.test(r)}function ai(r){return/^application\/([a-z.-]+\+)?xml$/.test(r)}function ci(r){return r.endsWith("/")?r.slice(0,-1):r}class fi{constructor(t){this.initVerboseLogs=({headerParams:e,host:n,path:a,method:c,body:f})=>{this.verboseLogs=br({headerParams:e,host:n,path:a,method:c,body:f instanceof FormData||f instanceof File?f:JSON.stringify(f)})},this.getVerboseLogs=()=>this.verboseLogs,this.updateVerboseLogs=e=>{if(!this.verboseLogs)throw new Error("Verbose logs not initialized");this.verboseLogs=br({...this.verboseLogs,...e})},this.initVerboseResponseLogs=({headerParams:e,host:n,path:a,method:c,body:f,statusCode:l,responseTime:g,responseSize:h})=>{this.verboseResponseLogs=br({headerParams:e,host:n,path:a,method:c,body:f,statusCode:l,responseTime:g,responseSize:h})},this.getVerboseResponseLogs=()=>this.verboseResponseLogs,this.clearVerboseResponseLogs=()=>{this.verboseResponseLogs=void 0},this.fetchResult=async({ctx:e,step:n,requestData:a,workflowId:c})=>{const{serverUrl:f,path:l,method:g,parameters:h,requestBody:y,openapiOperation:w}=a;if(!f?.url)throw e.options.logger.error(d.bgRed(" No server url provided ")),new Error("No server url provided");const k={},C=new URLSearchParams,j={},P={};for(const T of h)switch(T.in){case"header":k[T.name.toLowerCase()]=String(T.value);break;case"query":C.set(T.name,String(T.value));break;case"path":j[T.name]=String(T.value);break;case"cookie":P[T.name]=String(T.value);break}typeof y=="object"&&!k["content-type"]&&(k["content-type"]="application/json"),Object.keys(P).length&&(k.cookie=Object.entries(P).map(([T,X])=>`${T}=${X}`).join("; "));const q=`${Ct(l,j)||""}${C.toString()?"?"+C.toString():""}`,L=Ct(f.url,j)||"",_=`${ci(L)}${q}`;_.startsWith("/")&&e.options.logger.error(d.bgRed(` Wrong url: ${d.inverse(_)} `)+` Did you forget to provide a correct "serverUrl"?
`);const b=k["content-type"]||"";y&&!b&&e.options.logger.error(d.bgRed(" Incorrect request ")+` Please provide a correct "content-type" header or specify the "content-type" field in the test case itself. 
`);let R;if(b==="application/x-www-form-urlencoded")R=new URLSearchParams(y).toString();else if(Pe(b||""))R=JSON.stringify(y);else if(ai(b))R=y;else if(b.includes("multipart/form-data"))R=y,delete k["content-type"];else if(b==="application/octet-stream"){if(R=y,y instanceof File){const T=y.name;k["content-disposition"]=`attachment; filename=${T}`}}else R=y;const V=fe({value:k,noSecretsMasking:e.noSecretsMasking,secretsSet:e.secretsSet});let I;if(R instanceof FormData){const T=new FormData;for(const[X,ae]of R.entries())if(ae instanceof File)T.append(X,ae);else{const be=fe({value:ae,noSecretsMasking:e.noSecretsMasking,secretsSet:e.secretsSet});T.append(X,be)}I=T}else Pe(b)&&R?I=fe({value:JSON.parse(R),noSecretsMasking:e.noSecretsMasking,secretsSet:e.secretsSet}):I=R;const W=fe({value:q,noSecretsMasking:e.noSecretsMasking,secretsSet:e.secretsSet});this.initVerboseLogs({headerParams:V,host:L,method:g.toUpperCase(),path:W||"",body:I});const z=e.options.fetch,x=performance.now();let D,B,K;const Q={method:g.toUpperCase(),headers:k,...!Qo(y)&&{body:R},redirect:"follow",signal:AbortSignal.timeout(e.options.maxFetchTimeout),...k["content-type"]==="application/octet-stream"&&{duplex:"half"}},ee=[...e.workflows.find(T=>T.workflowId===c)?.["x-security"]||[],...n["x-security"]||[]].reverse().find(T=>{const X=Vt({ctx:e,security:T,operation:w});return X?.type==="http"&&X?.scheme==="digest"});if(ee){const T=await z(_,Q),X=await T.text(),ae=T.headers.get("www-authenticate");if(T.status!==401)throw this.initVerboseResponseLogs({body:X,method:g,host:f.url,path:q||"",statusCode:T.status,responseTime:0,responseSize:void 0}),new d.StatusCodeError(`Digest auth failed, expected 401 status code, but received ${T.status} in the first response`);if(!ae)throw this.initVerboseResponseLogs({body:X,method:g,host:f.url,path:q||"",statusCode:T.status,responseTime:0,responseSize:void 0}),new d.UnexpectedError("Digest auth failed, no www-authenticate header received in the first response");const{realm:be,nonce:sr,opaque:nr,qop:or,algorithm:ir,cnonce:ar,nc:cr}=si(ae),{username:fr,password:ur}=ee.values,lr=new URL(_).pathname+new URL(_).search,pr=ni({username:fr,password:ur,realm:be,nonce:sr,opaque:nr,qop:or,algorithm:ir,cnonce:ar,nc:cr,uri:lr,method:g.toUpperCase(),bodyContent:JSON.stringify(R)||""}),Ae={...k,authorization:pr},we=e.$workflows[c].steps[n.stepId]?.request;we&&(we.header=Ae),this.updateVerboseLogs({headerParams:fe({value:Ae,noSecretsMasking:e.noSecretsMasking,secretsSet:e.secretsSet})}),D=await z(_,{...Q,headers:Ae}),K=Math.ceil(performance.now()-x)}else D=await z(_,Q),K=Math.ceil(performance.now()-x);if(!D)throw new Error("Failed to fetch, no result received");const[G]=D.headers.get("content-type")?.split(";")||["application/json"];ii(G)?B=await D.arrayBuffer():B=await D.text();const ie=B?B instanceof ArrayBuffer?B:Pe(G)?JSON.parse(B):B:{},rr=Ko({statusCode:D.status,contentType:G,descriptionResponses:w?.responses});Le(e,rr,ie);const tr=Tt(ie);for(const T of tr)e.secretsSet.add(T);const je=Pe(G)?fe({value:ie,noSecretsMasking:e.noSecretsMasking,secretsSet:e.secretsSet}):ie,We=Object.fromEntries(D.headers?.entries()||[]),qe=Tt(We);for(const T of qe)e.secretsSet.add(T);let te;const Ce=D.headers.get("content-length");return Ce&&!isNaN(+Ce)?te=+Ce:B instanceof ArrayBuffer?te=B.byteLength:typeof B=="string"?te=new TextEncoder().encode(B).length:te=void 0,this.initVerboseResponseLogs({body:Pe(G)?JSON.stringify(je):je,method:g,host:f.url,path:q||"",statusCode:D.status,responseTime:K,headerParams:fe({value:We,noSecretsMasking:e.noSecretsMasking,secretsSet:e.secretsSet}),responseSize:te}),{body:ie,statusCode:D.status,time:K,header:Object.fromEntries(D.headers?.entries()||[]),contentType:G,requestUrl:_,responseSize:te}},this.fetch=t.fetch||fetch}}function ui(){return{address:{city:()=>d.ye.address.city(),country:()=>d.ye.address.country(),zipCode:()=>d.ye.address.zipCode(),street:()=>d.ye.address.street()},date:{past:()=>d.ye.date.past(),future:()=>d.ye.date.future()},number:{integer:({min:a,max:c}={})=>d.ye.datatype.number({min:a,max:c,precision:1}),float:a=>d.ye.datatype.float(a)},string:{email:({provider:a,domain:c="com"}={})=>d.ye.internet.email(void 0,void 0,`${a}.${c}`),userName:()=>d.ye.internet.userName(),firstName:()=>d.ye.name.firstName(),lastName:()=>d.ye.name.lastName(),fullName:()=>d.ye.name.fullName(),uuid:()=>d.ye.datatype.uuid(),string:({length:a}={})=>d.ye.datatype.string(a)}}}function Dr(r){return r?Array.isArray(r)?r.reduce((t,e)=>{const n=Pt(e);return{...t,...n}},{}):Pt(r):{}}function Pt(r){try{const t=JSON.parse(r);if(typeof t=="object"&&t!==null)return t}catch{}if(typeof r=="string"){if(r.includes(","))return r.split(",").reduce((t,e)=>{const[n,a]=e.split("=");return n&&a&&(t[n.trim()]=a.trim()),t},{});if(r.includes("=")){const[t,e]=r.split("=");return{[t.trim()]:e.trim()}}}return{}}function _t(r,t){if(!t||Object.keys(t).length===0)return{};const e=new d.Ajv({useDefaults:!0,removeAdditional:"all",coerceTypes:!0,strictTypes:!1});e.addFormat("password",!0),e.addFormat("int32",!0),e.addFormat("int64",!0),e.addFormat("float",!0),e.addFormat("double",!0);const n=e.compile(t),a={...r};return n(a),a}function li(r,t){return/\.(yaml|yml|json)$/i.test(r)&&!!t.arazzo}async function Jt(r){const{filePath:t,base:e,externalRefResolver:n,collectSpecData:a,version:c,skipLint:f=!1}=r;let l=[];const g=d.pathBrowserifyExports.basename(t);if(!g)throw new Error("Invalid file name");const h=await d.createConfig({extends:["recommended-strict"],arazzo1Rules:{"no-criteria-xpath":"error","respect-supported-versions":"warn","no-x-security-scheme-name-without-openapi":"error","x-security-scheme-required-values":"error","x-security-scheme-name-reference":"error","no-x-security-both-scheme-and-scheme-name":"error"}});if(!f&&(l=await d.lint({ref:t,config:h,externalRefResolver:n}),l.length)){const k=d.getTotals(l);d.formatProblems(l,{totals:k,version:c}),d.printConfigLintTotals(k,r.logger)}const y=await d.bundle({base:e,ref:t,config:h,dereference:!0,externalRefResolver:n});if(!y)throw new Error(`Could not find source description file '${g}'.`);if(!li(g,y.bundle.parsed))throw new Error(`No test files found. File ${g} does not follows naming pattern "*.[yaml | yml | json]" or have not valid "Arazzo" description.`);if(a?.(y.bundle.parsed||{}),l.filter(k=>k.severity==="error").length)throw new Error(`${d.red("Found errors in Arazzo description")} ${d.bold(g)}`);return y.bundle.parsed||{}}function pi(r,t){let e=r;for(const n of t)if(e&&e[n]!==void 0)e=e[n];else return;return e}function di(r){const t={};for(const e of r)t[e.stepId]={};return t}function hi({workflows:r,inputs:t,env:e={}}){const n={};for(const a of r){const c=a.inputs,f=Xt({inputs:t,workflowInputSchema:c,env:e});n[a.workflowId]={steps:di(a.steps||[]),inputs:c?f:void 0,outputs:a.outputs}}return n}function Xt({inputs:r,workflowInputSchema:t,env:e}){let n={},a={};return t&&(n=_t(r,t)),t?.properties?.env&&(a=_t(e||{},t.properties.env)),Object.keys(a).length>0?{...n,env:a}:n}const gi=ui();async function Qt(r,t,e){const n=r?.sourceDescriptions,a={};n&&await Promise.all(n.map(async f=>{if(f.type==="openapi"){const l=await ho({descriptionPath:f.url,config:t.config,base:t.filePath,externalRefResolver:t?.externalRefResolver}),{paths:g,servers:h,info:y,security:w,components:k}=l;a[f.name]={paths:g,servers:h,info:y,security:w,components:k}}else if(f.type==="arazzo"){const{url:l,name:g}=f,h=d.pathBrowserifyExports.resolve(d.pathBrowserifyExports.dirname(t.filePath),l),y=await Jt({filePath:h,version:t?.version,logger:t.logger,externalRefResolver:t?.externalRefResolver,skipLint:t?.skipLint});a[g]=y}}));for(const f of r.workflows||[])for(const l of f.steps)l.checks=[];const c={$response:void 0,$request:void 0,$inputs:{env:{}},$faker:gi,$sourceDescriptions:a,$workflows:hi({workflows:r.workflows||[],inputs:Dr(t?.input),env:t.envVariables||{}}),$steps:{},$components:r.components||{},$outputs:{},executedSteps:[],workflows:r.workflows||[],options:t,testDescription:r,info:r.info||Jo,arazzo:r.arazzo||"",sourceDescriptions:r.sourceDescriptions||[],noSecretsMasking:t.noSecretsMasking||!1,secretsSet:new Set,severity:ei(t.severity),apiClient:e};for(const f of r.workflows||[])f.inputs&&Le(c,f.inputs,c.$workflows[f.workflowId].inputs);return c}function Le(r,t,e,n=[]){if(!t||!e)return;const a=pi(e,n);t.format==="password"&&a&&r.secretsSet.add(a),t.properties&&Object.entries(t.properties).forEach(([c,f])=>{const l=[...n,c];Le(r,f,e,l)})}function mi({workflows:r,workflowsToRun:t,workflowsToSkip:e,logger:n}){let a=[];return t&&t.length?a=$i(r,t,n):e&&e.length?a=yi(r,e,n):a=r,a}function yi(r,t,e){const n=r.filter(a=>!t.includes(a.workflowId));return n.length?(e.output(`${d.yellow(`Following workflows are skipped: ${t.join(", ")}`)}`),e.printNewLine(),n):(e.output(`${d.red("All workflows are skipped")}`),e.printNewLine(),[])}function $i(r,t,e){const n=wi(r,t);if(!n.length)throw new Error(`Following workflows don't exist: ${t.join(", ")}`);if(n.length===t.length)return n;{const a=t.filter(c=>!r.find(f=>f.workflowId===c));return e.output(`Following workflows don't exist: ${a.join(", ")}`),n}}function wi(r,t){return r.filter(e=>t.includes(e.workflowId))}function Gt(r){return r.type==="regex"}function Zt(r){const t=r?.type;return t==="jsonpath"||typeof t=="object"&&t?.type==="jsonpath"}const Ft=["$url","$method","$statusCode","$request","$response","$inputs","$outputs","$steps","$workflows","$sourceDescriptions","$components"];function vi(r){r.forEach(t=>{const{condition:e}=t;if(Gt(t)){const{context:n}=t,a=/\$[a-zA-Z_]\w*/g,c=n.match(a);if(!c)throw new Error(`"${n}" does not contain any valid context.`);if(c.filter(l=>!Ft.includes(l)).length)throw new Error(`Success criteria context "${n}" is not allowed.`)}else if(Zt(t)){if(!t.context)throw new Error("jsonpath success criteria context is required.");if(!t.condition)throw new Error("jsonpath success criteria condition is required.")}else{const n=/\$[a-zA-Z_]\w*/g,a=e.match(n);if(!a)return;if(a.filter(f=>!Ft.includes(f)).length)throw new Error(`Success criteria condition ${e} is not allowed.`)}})}function er({ctx:r,workflowId:t,step:e}){if(!e||!t)return{$statusCode:void 0,$method:"",$response:void 0,$url:"",$request:void 0,$outputs:r.$outputs,$steps:r.$steps,$workflows:r.$workflows,$inputs:r.$inputs,$sourceDescriptions:r.$sourceDescriptions,$components:r.$components,$faker:r.$faker};const n=r.$workflows[t].steps[e.stepId].request,a=n?.path,c=n?.query,f=n?.body||{},l=n?.header,g=n?.method,h=e.response?.statusCode,y=e.response?.header||{},w=e.response?.body||{};return{$statusCode:h,$method:g,$response:{header:y,body:w,path:a,query:c},$url:n&&n.url,$request:{header:l,body:f,path:a,query:c},$outputs:r.$outputs,$steps:r.$steps,$workflows:r.$workflows,$inputs:r.$inputs,$sourceDescriptions:r.$sourceDescriptions,$components:r.$components,$faker:r.$faker}}function Ei(r,t){function e(){this.constructor=r}e.prototype=t.prototype,r.prototype=new e}function Ee(r,t,e,n){var a=Error.call(this,r);return Object.setPrototypeOf&&Object.setPrototypeOf(a,Ee.prototype),a.expected=t,a.found=e,a.location=n,a.name="SyntaxError",a}Ei(Ee,Error);function Ar(r,t,e){return e=e||" ",r.length>t?r:(t-=r.length,e+=e.repeat(t),r+e.slice(0,t))}Ee.prototype.format=function(r){var t="Error: "+this.message;if(this.location){var e=null,n;for(n=0;n<r.length;n++)if(r[n].source===this.location.source){e=r[n].text.split(/\r\n|\n|\r/g);break}var a=this.location.start,c=this.location.source&&typeof this.location.source.offset=="function"?this.location.source.offset(a):a,f=this.location.source+":"+c.line+":"+c.column;if(e){var l=this.location.end,g=Ar("",c.line.toString().length," "),h=e[a.line-1],y=a.line===l.line?l.column:h.length+1,w=y-a.column||1;t+=`
 --> `+f+`
`+g+` |
`+c.line+" | "+h+`
`+g+" | "+Ar("",a.column-1," ")+Ar("",w,"^")}else t+=`
 at `+f}return t};Ee.buildMessage=function(r,t){var e={literal:function(h){return'"'+a(h.text)+'"'},class:function(h){var y=h.parts.map(function(w){return Array.isArray(w)?c(w[0])+"-"+c(w[1]):c(w)});return"["+(h.inverted?"^":"")+y.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(h){return h.description}};function n(h){return h.charCodeAt(0).toString(16).toUpperCase()}function a(h){return h.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(y){return"\\x0"+n(y)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(y){return"\\x"+n(y)})}function c(h){return h.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(y){return"\\x0"+n(y)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(y){return"\\x"+n(y)})}function f(h){return e[h.type](h)}function l(h){var y=h.map(f),w,k;if(y.sort(),y.length>0){for(w=1,k=1;w<y.length;w++)y[w-1]!==y[w]&&(y[k]=y[w],k++);y.length=k}switch(y.length){case 1:return y[0];case 2:return y[0]+" or "+y[1];default:return y.slice(0,-1).join(", ")+", or "+y[y.length-1]}}function g(h){return h?'"'+a(h)+'"':"end of input"}return"Expected "+l(r)+" but "+g(t)+" found."};function ki(r,t){t=t!==void 0?t:{};var e={},n=t.grammarSource,a={jsonpath_query:mr},c=mr,f="$",l=".",g="..",h="[",y=",",w="]",k="*",C=":",j="?",P='"',N="'",q="0",L="-",_="||",b="\\",R="u",V="&&",I="d",W="(",z=")",x="!",D="==",B="!=",K="<=",Q=">=",le="-0",ee="true",G="false",ie="null",rr="@",tr="e",je=/^[\t-\n\r ]/,We=/^[A-Z_a-z\x80-\uD7FF\uE000-\uFFFF]/,qe=/^[\uD800-\uDBFF]/,te=/^[\uDC00-\uDFFF]/,Ce=/^[0-9]/,T=/^[1-9]/,X=/^[ -!#-&(-[\]-\uD7FF\uE000-\uFFFF]/,ae=/^[\/\\bfnrt]/,be=/^[A-CE-F]/i,sr=/^[0-7]/,nr=/^[8-9]/,or=/^[A-B]/i,ir=/^[C-F]/i,ar=/^[A-F]/i,cr=/^[<>]/,fr=/^[0-9_a-z]/,ur=/^[+\-]/,lr=/^[a-z]/,pr=F("$",!1),Ae=M([["	",`
`],"\r"," "],!1,!1),we=F(".",!1),ms=F("..",!1),dr=F("[",!1),Ue=F(",",!1),hr=F("]",!1),ys=F("*",!1),$s=M([["A","Z"],"_",["a","z"],["","퟿"],["",""]],!1,!1),Nr=M([["\uD800","\uDBFF"]],!1,!1),jr=M([["\uDC00","\uDFFF"]],!1,!1),Wr=F(":",!1),ws=F("?",!1),vs=M([["0","9"]],!1,!1),ze=F('"',!1),Be=F("'",!1),Es=F("0",!1),ks=F("-",!1),Ss=M([["1","9"]],!1,!1),qr=F("||",!1),Cs=M([[" ","!"],["#","&"],["(","["],["]","퟿"],["",""]],!1,!1),Ur=F("\\",!1),bs=M(["/","\\","b","f","n","r","t"],!1,!1),zr=F("u",!1),Br=F("&&",!1),As=M([["A","C"],["E","F"]],!1,!0),gr=F("D",!0),Rs=M([["0","7"]],!1,!1),Os=M([["8","9"]],!1,!1),Ts=M([["A","B"]],!1,!0),Ps=M([["C","F"]],!1,!0),xr=F("(",!1),Mr=F(")",!1),_s=M([["A","F"]],!1,!0),Fs=F("!",!1),Is=F("==",!1),Ds=F("!=",!1),Ls=F("<=",!1),Ns=F(">=",!1),js=M(["<",">"],!1,!1),Ws=F("-0",!1),qs=F("true",!1),Us=F("false",!1),zs=F("null",!1),Bs=F("@",!1),xs=M([["0","9"],"_",["a","z"]],!1,!1),Ms=F("e",!0),Vs=M(["+","-"],!1,!1),Ks=M([["a","z"]],!1,!1),Hs=function(s){return{type:"JsonPathQuery",segments:s}},Vr=function(s){return s},Js=function(s){return s},Xs=function(s){return{type:"ChildSegment",node:s}},Qs=function(s){return{type:"DescendantSegment",node:s}},Kr=function(s,o){return o},Gs=function(s,o){return[s,...o]},Zs=function(s){return{type:"BracketedSelection",selectors:s}},Ys=function(){return{type:"WildcardSelector"}},en=function(s){return{type:"MemberNameShorthand",value:s}},rn=function(s){return{type:"NameSelector",value:s}},tn=function(s,o,u){return u},sn=function(s,o,u){return{start:s,end:o,step:u}},nn=function(s){return{type:"SliceSelector",start:s.start===""?null:Number.parseInt(s.start.trim(),10),end:s.end===""?null:Number.parseInt(s.end.trim(),10),step:s.step===""||s.step===null?null:Number.parseInt(s.step.trim(),10)}},on=function(s){return{type:"IndexSelector",value:Number.parseInt(s,10)}},an=function(s){return{type:"FilterSelector",value:s}},cn=function(s){return s},fn=function(s){return s},un=function(s){return s.join("")},ln=function(){return'"'},pn=function(s){switch(s){case"b":return"\b";case"f":return"\f";case"n":return`
`;case"r":return"\r";case"t":return"	";case"/":return"/";case"\\":return"\\";default:return s.slice(1)}},dn=function(){return"'"},hn=function(s){switch(s){case"b":return"\b";case"f":return"\f";case"n":return`
`;case"r":return"\r";case"t":return"	";case"/":return"/";case"\\":return"\\";default:return s.slice(1)}},Hr=function(s,o){return o},gn=function(s,o){return o.length===0?s:{type:"LogicalOrExpr",left:s,right:o.length===1?o[0]:o.slice(1).reduce((u,p)=>({type:"LogicalOrExpr",left:u,right:p}),o[0])}},Jr=function(s,o){return o},mn=function(s,o){return[s,...o]},yn=function(s){return s.length===1?s[0]:{type:"LogicalAndExpr",left:s[0],right:s.length===2?s[1]:s.slice(2).reduce((o,u)=>({type:"LogicalOrExpr",left:o,right:u}),s[1])}},$n=function(){return String.fromCharCode(Number.parseInt(qn(),16))},wn=function(s,o){return String.fromCharCode(Number.parseInt(s,16))+String.fromCharCode(Number.parseInt(o,16))},vn=function(s){return s},En=function(s,o){return s!==null?{type:"LogicalNotExpr",expression:o}:o},kn=function(s,o,u){return{type:"ComparisonExpr",left:s,op:o,right:u}},Sn=function(s,o){return s!==null?{type:"LogicalNotExpr",expression:{type:"TestExpr",expression:o}}:{type:"TestExpr",expression:o}},Cn=function(s){return{type:"FilterQuery",value:s}},Xr=function(s,o,u){return u},bn=function(s,o,u){return[o,...u]},An=function(s,o){return{type:"FunctionExpr",name:s,arguments:o}},Rn=function(s){return{type:"Literal",value:s}},On=function(s){return{type:"RelQuery",segments:s}},Tn=function(s){return Number(s)},Pn=function(){return!0},_n=function(){return!1},Fn=function(){return null},In=function(s){return{type:"RelSingularQuery",segments:s}},Dn=function(s){return{type:"AbsSingularQuery",segments:s}},Qr=function(s){return{type:"SingularQuerySegment",node:s}},Ln=function(s){return s},Nn=function(s){return s},jn=function(s){return s},Wn=function(s){return{type:"IndexSelector",selector:s}},i=t.peg$currPos|0,S=i,ve=[{line:1,column:1}],Z=i,xe=t.peg$maxFailExpected||[],E=t.peg$silentFails|0,Re;if(t.startRule){if(!(t.startRule in a))throw new Error(`Can't start parsing from rule "`+t.startRule+'".');c=a[t.startRule]}function qn(){return r.substring(S,i)}function F(s,o){return{type:"literal",text:s,ignoreCase:o}}function M(s,o,u){return{type:"class",parts:s,inverted:o,ignoreCase:u}}function Un(){return{type:"end"}}function Gr(s){var o=ve[s],u;if(o)return o;if(s>=ve.length)u=ve.length-1;else for(u=s;!ve[--u];);for(o=ve[u],o={line:o.line,column:o.column};u<s;)r.charCodeAt(u)===10?(o.line++,o.column=1):o.column++,u++;return ve[s]=o,o}function Zr(s,o,u){var p=Gr(s),m=Gr(o),$={source:n,start:{offset:s,line:p.line,column:p.column},end:{offset:o,line:m.line,column:m.column}};return $}function v(s){i<Z||(i>Z&&(Z=i,xe=[]),xe.push(s))}function zn(s,o,u){return new Ee(Ee.buildMessage(s,o),s,o,u)}function mr(){var s,o,u;return s=i,o=Yr(),o!==e?(u=et(),S=s,s=Hs(u)):(i=s,s=e),s}function Yr(){var s;return r.charCodeAt(i)===36?(s=f,i++):(s=e,E===0&&v(pr)),s}function et(){var s,o,u;for(s=[],o=i,O(),u=rt(),u!==e?(S=o,o=Vr(u)):(i=o,o=e);o!==e;)s.push(o),o=i,O(),u=rt(),u!==e?(S=o,o=Vr(u)):(i=o,o=e);return s}function O(){var s,o;for(s=[],o=tt();o!==e;)s.push(o),o=tt();return s}function rt(){var s;return s=Bn(),s===e&&(s=xn()),s}function tt(){var s;return s=r.charAt(i),je.test(s)?i++:(s=e,E===0&&v(Ae)),s}function Bn(){var s,o,u,p;return s=i,o=st(),o===e&&(o=i,r.charCodeAt(i)===46?(u=l,i++):(u=e,E===0&&v(we)),u!==e?(p=yr(),p===e&&(p=$r()),p!==e?(S=o,o=Js(p)):(i=o,o=e)):(i=o,o=e)),o!==e&&(S=s,o=Xs(o)),s=o,s}function xn(){var s,o,u;return s=i,r.substr(i,2)===g?(o=g,i+=2):(o=e,E===0&&v(ms)),o!==e?(u=st(),u===e&&(u=yr(),u===e&&(u=$r())),u!==e?(S=s,s=Qs(u)):(i=s,s=e)):(i=s,s=e),s}function st(){var s,o,u,p,m,$,A,U;if(s=i,r.charCodeAt(i)===91?(o=h,i++):(o=e,E===0&&v(dr)),o!==e){if(u=i,O(),p=wr(),p!==e){for(m=[],$=i,O(),r.charCodeAt(i)===44?(A=y,i++):(A=e,E===0&&v(Ue)),A!==e?(O(),U=wr(),U!==e?(S=$,$=Kr(p,U)):(i=$,$=e)):(i=$,$=e);$!==e;)m.push($),$=i,O(),r.charCodeAt(i)===44?(A=y,i++):(A=e,E===0&&v(Ue)),A!==e?(O(),U=wr(),U!==e?(S=$,$=Kr(p,U)):(i=$,$=e)):(i=$,$=e);S=u,u=Gs(p,m)}else i=u,u=e;u!==e?(O(),r.charCodeAt(i)===93?(p=w,i++):(p=e,E===0&&v(hr)),p!==e?(S=s,s=Zs(u)):(i=s,s=e)):(i=s,s=e)}else i=s,s=e;return s}function yr(){var s,o;return s=i,r.charCodeAt(i)===42?(o=k,i++):(o=e,E===0&&v(ys)),o!==e&&(S=s,o=Ys()),s=o,s}function $r(){var s,o,u,p,m,$;if(s=i,o=i,u=i,p=nt(),p!==e){for(m=[],$=ot();$!==e;)m.push($),$=ot();p=[p,m],u=p}else i=u,u=e;return u!==e?o=r.substring(o,i):o=u,o!==e&&(S=s,o=en(o)),s=o,s}function wr(){var s;return s=it(),s===e&&(s=yr(),s===e&&(s=Mn(),s===e&&(s=at(),s===e&&(s=Vn())))),s}function nt(){var s,o,u;return s=r.charAt(i),We.test(s)?i++:(s=e,E===0&&v($s)),s===e&&(s=i,o=r.charAt(i),qe.test(o)?i++:(o=e,E===0&&v(Nr)),o!==e?(u=r.charAt(i),te.test(u)?i++:(u=e,E===0&&v(jr)),u!==e?(o=[o,u],s=o):(i=s,s=e)):(i=s,s=e)),s}function ot(){var s;return s=nt(),s===e&&(s=se()),s}function it(){var s,o;return s=i,o=ct(),o!==e&&(S=s,o=rn(o)),s=o,s}function Mn(){var s,o,u,p,m,$,A,U,J;return s=i,o=i,u=i,p=i,m=Oe(),m!==e?($=O(),m=[m,$],p=m):(i=p,p=e),p===e&&(p=null),u=r.substring(u,i),r.charCodeAt(i)===58?(p=C,i++):(p=e,E===0&&v(Wr)),p!==e?(m=O(),$=i,A=i,U=Oe(),U!==e?(J=O(),U=[U,J],A=U):(i=A,A=e),A===e&&(A=null),$=r.substring($,i),A=i,r.charCodeAt(i)===58?(U=C,i++):(U=e,E===0&&v(Wr)),U!==e?(J=i,O(),Oe(),J=r.substring(J,i),S=A,A=tn(u,$,J)):(i=A,A=e),A===e&&(A=null),S=o,o=sn(u,$,A)):(i=o,o=e),o!==e&&(S=s,o=nn(o)),s=o,s}function at(){var s,o,u;return s=i,o=i,u=Oe(),u!==e?o=r.substring(o,i):o=u,o!==e&&(S=s,o=on(o)),s=o,s}function Vn(){var s,o,u;return s=i,r.charCodeAt(i)===63?(o=j,i++):(o=e,E===0&&v(ws)),o!==e?(O(),u=vr(),u!==e?(S=s,s=an(u)):(i=s,s=e)):(i=s,s=e),s}function se(){var s;return s=r.charAt(i),Ce.test(s)?i++:(s=e,E===0&&v(vs)),s}function ct(){var s,o,u,p,m;if(s=i,o=i,r.charCodeAt(i)===34?(u=P,i++):(u=e,E===0&&v(ze)),u!==e){for(p=[],m=ft();m!==e;)p.push(m),m=ft();r.charCodeAt(i)===34?(m=P,i++):(m=e,E===0&&v(ze)),m!==e?(S=o,o=cn(p)):(i=o,o=e)}else i=o,o=e;if(o===e)if(o=i,r.charCodeAt(i)===39?(u=N,i++):(u=e,E===0&&v(Be)),u!==e){for(p=[],m=ut();m!==e;)p.push(m),m=ut();r.charCodeAt(i)===39?(m=N,i++):(m=e,E===0&&v(Be)),m!==e?(S=o,o=fn(p)):(i=o,o=e)}else i=o,o=e;return o!==e&&(S=s,o=un(o)),s=o,s}function Oe(){var s,o,u,p,m;if(r.charCodeAt(i)===48?(s=q,i++):(s=e,E===0&&v(Es)),s===e)if(s=i,r.charCodeAt(i)===45?(o=L,i++):(o=e,E===0&&v(ks)),o===e&&(o=null),u=Kn(),u!==e){for(p=[],m=se();m!==e;)p.push(m),m=se();o=[o,u,p],s=o}else i=s,s=e;return s}function ft(){var s,o,u;return s=i,o=lt(),o!==e?s=r.substring(s,i):s=o,s===e&&(r.charCodeAt(i)===39?(s=N,i++):(s=e,E===0&&v(Be)),s===e&&(s=i,o=Me(),o!==e?(r.charCodeAt(i)===34?(u=P,i++):(u=e,E===0&&v(ze)),u!==e?(S=s,s=ln()):(i=s,s=e)):(i=s,s=e),s===e&&(s=i,o=Me(),o!==e?(u=pt(),u!==e?(S=s,s=pn(u)):(i=s,s=e)):(i=s,s=e)))),s}function ut(){var s,o,u;return s=i,o=lt(),o!==e?s=r.substring(s,i):s=o,s===e&&(r.charCodeAt(i)===34?(s=P,i++):(s=e,E===0&&v(ze)),s===e&&(s=i,o=Me(),o!==e?(r.charCodeAt(i)===39?(u=N,i++):(u=e,E===0&&v(Be)),u!==e?(S=s,s=dn()):(i=s,s=e)):(i=s,s=e),s===e&&(s=i,o=Me(),o!==e?(u=pt(),u!==e?(S=s,s=hn(u)):(i=s,s=e)):(i=s,s=e)))),s}function Kn(){var s;return s=r.charAt(i),T.test(s)?i++:(s=e,E===0&&v(Ss)),s}function vr(){var s,o,u,p,m,$;if(s=i,o=Er(),o!==e){for(u=[],p=i,O(),r.substr(i,2)===_?(m=_,i+=2):(m=e,E===0&&v(qr)),m!==e?(O(),$=Er(),$!==e?(S=p,p=Hr(o,$)):(i=p,p=e)):(i=p,p=e);p!==e;)u.push(p),p=i,O(),r.substr(i,2)===_?(m=_,i+=2):(m=e,E===0&&v(qr)),m!==e?(O(),$=Er(),$!==e?(S=p,p=Hr(o,$)):(i=p,p=e)):(i=p,p=e);S=s,s=gn(o,u)}else i=s,s=e;return s}function lt(){var s,o,u;return s=r.charAt(i),X.test(s)?i++:(s=e,E===0&&v(Cs)),s===e&&(s=i,o=r.charAt(i),qe.test(o)?i++:(o=e,E===0&&v(Nr)),o!==e?(u=r.charAt(i),te.test(u)?i++:(u=e,E===0&&v(jr)),u!==e?(o=[o,u],s=o):(i=s,s=e)):(i=s,s=e)),s}function Me(){var s;return r.charCodeAt(i)===92?(s=b,i++):(s=e,E===0&&v(Ur)),s}function pt(){var s,o,u;return s=r.charAt(i),ae.test(s)?i++:(s=e,E===0&&v(bs)),s===e&&(s=i,r.charCodeAt(i)===117?(o=R,i++):(o=e,E===0&&v(zr)),o!==e?(u=Hn(),u!==e?(o=[o,u],s=o):(i=s,s=e)):(i=s,s=e)),s}function Er(){var s,o,u,p,m,$,A;if(s=i,o=i,u=kr(),u!==e){for(p=[],m=i,O(),r.substr(i,2)===V?($=V,i+=2):($=e,E===0&&v(Br)),$!==e?(O(),A=kr(),A!==e?(S=m,m=Jr(u,A)):(i=m,m=e)):(i=m,m=e);m!==e;)p.push(m),m=i,O(),r.substr(i,2)===V?($=V,i+=2):($=e,E===0&&v(Br)),$!==e?(O(),A=kr(),A!==e?(S=m,m=Jr(u,A)):(i=m,m=e)):(i=m,m=e);S=o,o=mn(u,p)}else i=o,o=e;return o!==e&&(S=s,o=yn(o)),s=o,s}function Hn(){var s,o,u,p,m,$,A;return s=i,o=i,u=Jn(),u!==e&&(S=o,u=$n()),o=u,o===e&&(o=i,u=i,p=Xn(),p!==e?u=r.substring(u,i):u=p,u!==e?(r.charCodeAt(i)===92?(p=b,i++):(p=e,E===0&&v(Ur)),p!==e?(r.charCodeAt(i)===117?(m=R,i++):(m=e,E===0&&v(zr)),m!==e?($=i,A=Qn(),A!==e?$=r.substring($,i):$=A,$!==e?(S=o,o=wn(u,$)):(i=o,o=e)):(i=o,o=e)):(i=o,o=e)):(i=o,o=e)),o!==e&&(S=s,o=vn(o)),s=o,s}function kr(){var s;return s=Gn(),s===e&&(s=Zn(),s===e&&(s=Yn())),s}function Jn(){var s,o,u,p,m,$;if(s=i,o=se(),o===e&&(o=r.charAt(i),be.test(o)?i++:(o=e,E===0&&v(As))),o!==e){for(u=i,p=[],m=ce();m!==e;)p.push(m),p.length>=3?m=e:m=ce();p.length<3?(i=u,u=e):u=p,u!==e?(o=[o,u],s=o):(i=s,s=e)}else i=s,s=e;if(s===e)if(s=i,o=r.charAt(i),o.toLowerCase()===I?i++:(o=e,E===0&&v(gr)),o!==e)if(u=r.charAt(i),sr.test(u)?i++:(u=e,E===0&&v(Rs)),u!==e){for(p=i,m=[],$=ce();$!==e;)m.push($),m.length>=2?$=e:$=ce();m.length<2?(i=p,p=e):p=m,p!==e?(o=[o,u,p],s=o):(i=s,s=e)}else i=s,s=e;else i=s,s=e;return s}function Xn(){var s,o,u,p,m,$;if(s=i,o=r.charAt(i),o.toLowerCase()===I?i++:(o=e,E===0&&v(gr)),o!==e)if(u=r.charAt(i),nr.test(u)?i++:(u=e,E===0&&v(Os)),u===e&&(u=r.charAt(i),or.test(u)?i++:(u=e,E===0&&v(Ts))),u!==e){for(p=i,m=[],$=ce();$!==e;)m.push($),m.length>=2?$=e:$=ce();m.length<2?(i=p,p=e):p=m,p!==e?(o=[o,u,p],s=o):(i=s,s=e)}else i=s,s=e;else i=s,s=e;return s}function Qn(){var s,o,u,p,m,$;if(s=i,o=r.charAt(i),o.toLowerCase()===I?i++:(o=e,E===0&&v(gr)),o!==e)if(u=r.charAt(i),ir.test(u)?i++:(u=e,E===0&&v(Ps)),u!==e){for(p=i,m=[],$=ce();$!==e;)m.push($),m.length>=2?$=e:$=ce();m.length<2?(i=p,p=e):p=m,p!==e?(o=[o,u,p],s=o):(i=s,s=e)}else i=s,s=e;else i=s,s=e;return s}function Gn(){var s,o,u,p,m,$;return s=i,o=i,u=dt(),u!==e?(p=O(),u=[u,p],o=u):(i=o,o=e),o===e&&(o=null),r.charCodeAt(i)===40?(u=W,i++):(u=e,E===0&&v(xr)),u!==e?(p=O(),m=vr(),m!==e?(O(),r.charCodeAt(i)===41?($=z,i++):($=e,E===0&&v(Mr)),$!==e?(S=s,s=En(o,m)):(i=s,s=e)):(i=s,s=e)):(i=s,s=e),s}function Zn(){var s,o,u,p;return s=i,o=ht(),o!==e?(O(),u=eo(),u!==e?(O(),p=ht(),p!==e?(S=s,s=kn(o,u,p)):(i=s,s=e)):(i=s,s=e)):(i=s,s=e),s}function Yn(){var s,o,u,p;return s=i,o=i,u=dt(),u!==e?(p=O(),u=[u,p],o=u):(i=o,o=e),o===e&&(o=null),u=gt(),u===e&&(u=Sr()),u!==e?(S=s,s=Sn(o,u)):(i=s,s=e),s}function ce(){var s;return s=se(),s===e&&(s=r.charAt(i),ar.test(s)?i++:(s=e,E===0&&v(_s))),s}function dt(){var s;return r.charCodeAt(i)===33?(s=x,i++):(s=e,E===0&&v(Fs)),s}function ht(){var s;return s=mt(),s===e&&(s=ro(),s===e&&(s=Sr())),s}function eo(){var s;return r.substr(i,2)===D?(s=D,i+=2):(s=e,E===0&&v(Is)),s===e&&(r.substr(i,2)===B?(s=B,i+=2):(s=e,E===0&&v(Ds)),s===e&&(r.substr(i,2)===K?(s=K,i+=2):(s=e,E===0&&v(Ls)),s===e&&(r.substr(i,2)===Q?(s=Q,i+=2):(s=e,E===0&&v(Ns)),s===e&&(s=r.charAt(i),cr.test(s)?i++:(s=e,E===0&&v(js)))))),s}function gt(){var s,o;return s=i,o=to(),o===e&&(o=mr()),o!==e&&(S=s,o=Cn(o)),s=o,s}function Sr(){var s,o,u,p,m,$,A,U,J;if(s=i,o=so(),o!==e)if(r.charCodeAt(i)===40?(u=W,i++):(u=e,E===0&&v(xr)),u!==e){if(O(),p=i,m=Cr(),m!==e){for($=[],A=i,O(),r.charCodeAt(i)===44?(U=y,i++):(U=e,E===0&&v(Ue)),U!==e?(O(),J=Cr(),J!==e?(S=A,A=Xr(o,m,J)):(i=A,A=e)):(i=A,A=e);A!==e;)$.push(A),A=i,O(),r.charCodeAt(i)===44?(U=y,i++):(U=e,E===0&&v(Ue)),U!==e?(O(),J=Cr(),J!==e?(S=A,A=Xr(o,m,J)):(i=A,A=e)):(i=A,A=e);S=p,p=bn(o,m,$)}else i=p,p=e;p===e&&(p=null),m=O(),r.charCodeAt(i)===41?($=z,i++):($=e,E===0&&v(Mr)),$!==e?(S=s,s=An(o,p)):(i=s,s=e)}else i=s,s=e;else i=s,s=e;return s}function mt(){var s,o;return s=i,o=no(),o===e&&(o=ct(),o===e&&(o=oo(),o===e&&(o=io(),o===e&&(o=ao())))),o!==e&&(S=s,o=Rn(o)),s=o,s}function ro(){var s;return s=co(),s===e&&(s=fo()),s}function to(){var s,o,u;return s=i,o=yt(),o!==e?(u=et(),u!==e?(S=s,s=On(u)):(i=s,s=e)):(i=s,s=e),s}function so(){var s,o,u,p,m;if(s=i,o=i,u=po(),u!==e){for(p=[],m=$t();m!==e;)p.push(m),m=$t();u=[u,p],o=u}else i=o,o=e;return o!==e?s=r.substring(s,i):s=o,s}function Cr(){var s;return s=mt(),s===e&&(s=gt(),s===e&&(s=Sr(),s===e&&(s=vr()))),s}function no(){var s,o,u,p,m,$;return s=i,o=i,u=i,p=Oe(),p===e&&(r.substr(i,2)===le?(p=le,i+=2):(p=e,E===0&&v(Ws))),p!==e?(m=uo(),m===e&&(m=null),$=lo(),$===e&&($=null),p=[p,m,$],u=p):(i=u,u=e),u!==e?o=r.substring(o,i):o=u,o!==e&&(S=s,o=Tn(o)),s=o,s}function oo(){var s,o;return s=i,r.substr(i,4)===ee?(o=ee,i+=4):(o=e,E===0&&v(qs)),o!==e&&(S=s,o=Pn()),s=o,s}function io(){var s,o;return s=i,r.substr(i,5)===G?(o=G,i+=5):(o=e,E===0&&v(Us)),o!==e&&(S=s,o=_n()),s=o,s}function ao(){var s,o;return s=i,r.substr(i,4)===ie?(o=ie,i+=4):(o=e,E===0&&v(zs)),o!==e&&(S=s,o=Fn()),s=o,s}function co(){var s,o,u;return s=i,o=yt(),o!==e?(u=wt(),S=s,s=In(u)):(i=s,s=e),s}function fo(){var s,o,u;return s=i,o=Yr(),o!==e?(u=wt(),S=s,s=Dn(u)):(i=s,s=e),s}function yt(){var s;return r.charCodeAt(i)===64?(s=rr,i++):(s=e,E===0&&v(Bs)),s}function $t(){var s;return s=r.charAt(i),fr.test(s)?i++:(s=e,E===0&&v(xs)),s}function uo(){var s,o,u,p;if(s=i,r.charCodeAt(i)===46?(o=l,i++):(o=e,E===0&&v(we)),o!==e){if(u=[],p=se(),p!==e)for(;p!==e;)u.push(p),p=se();else u=e;u!==e?(o=[o,u],s=o):(i=s,s=e)}else i=s,s=e;return s}function lo(){var s,o,u,p,m;if(s=i,o=r.charAt(i),o.toLowerCase()===tr?i++:(o=e,E===0&&v(Ms)),o!==e){if(u=r.charAt(i),ur.test(u)?i++:(u=e,E===0&&v(Vs)),u===e&&(u=null),p=[],m=se(),m!==e)for(;m!==e;)p.push(m),m=se();else p=e;p!==e?(o=[o,u,p],s=o):(i=s,s=e)}else i=s,s=e;return s}function wt(){var s,o,u,p;for(s=i,o=[],u=i,O(),p=vt(),p===e&&(p=Et()),p!==e?(S=u,u=Qr(p)):(i=u,u=e);u!==e;)o.push(u),u=i,O(),p=vt(),p===e&&(p=Et()),p!==e?(S=u,u=Qr(p)):(i=u,u=e);return S=s,o=Ln(o),s=o,s}function po(){var s;return s=r.charAt(i),lr.test(s)?i++:(s=e,E===0&&v(Ks)),s}function vt(){var s,o,u,p;return s=i,r.charCodeAt(i)===91?(o=h,i++):(o=e,E===0&&v(dr)),o!==e?(u=it(),u!==e?(r.charCodeAt(i)===93?(p=w,i++):(p=e,E===0&&v(hr)),p!==e?(S=s,s=Nn(u)):(i=s,s=e)):(i=s,s=e)):(i=s,s=e),s===e&&(s=i,r.charCodeAt(i)===46?(o=l,i++):(o=e,E===0&&v(we)),o!==e?(u=$r(),u!==e?(S=s,s=jn(u)):(i=s,s=e)):(i=s,s=e)),s}function Et(){var s,o,u,p;return s=i,r.charCodeAt(i)===91?(o=h,i++):(o=e,E===0&&v(dr)),o!==e?(u=at(),u!==e?(r.charCodeAt(i)===93?(p=w,i++):(p=e,E===0&&v(hr)),p!==e?(S=s,s=Wn(u)):(i=s,s=e)):(i=s,s=e)):(i=s,s=e),s}if(Re=c(),t.peg$library)return{peg$result:Re,peg$currPos:i,peg$FAILED:e,peg$maxFailExpected:xe,peg$maxFailPos:Z};if(Re!==e&&i===r.length)return Re;throw Re!==e&&i<r.length&&v(Un()),zn(xe,Z<r.length?r.charAt(Z):null,Z<r.length?Zr(Z,Z+1):Zr(Z,Z))}function Si(r){return ki(r)}class Ci{head=null;tail=null;size=0;push(t){const e={value:t,next:null};this.tail!==null&&(this.tail.next=e),this.tail=e,this.head===null&&(this.head=e),this.size++}pop(){if(this.head===null)return;const t=this.head.value;return this.head=this.head.next,this.head===null&&(this.tail=null),this.size--,t}}function Ne(r){if(typeof r!="object"||r===null)return!1;const t=Object.getPrototypeOf(r);return t===null||t===Object.prototype}const He=r=>Array.isArray(r.value),Xe=r=>Ne(r.value),Yt=new WeakSet,H=r=>typeof r=="object"&&r!==null&&Yt.has(r),bi=r=>{switch(typeof r){case"string":case"number":case"boolean":return!0;case"object":return r===null||Ne(r)||es(r);default:return!1}},es=r=>Array.isArray(r)&&!H(r),rs=()=>{const r=[];return Yt.add(r),r},Se=Symbol("Nothing"),Ai={declaration:function(t,e){return H(e)?e.length:0},definition:{parameters:["NodesType"],returnType:"ValueType"}};function Ri(r){let t=0;for(let e=0;e<r.length;e++){const n=r.charCodeAt(e);(n>=0&&n<=55295||n>=57344&&n<=1114111)&&t++}return t}const Oi={declaration:function(t,e){return typeof e=="string"?Ri(e):Array.isArray(e)?e.length:Ne(e)?Object.keys(e).length:Se},definition:{parameters:["ValueType"],returnType:"ValueType"}};function ts(r){return r===92}function Ti(r,t){let e=!1,n=t;for(;n<r.length;){const a=r.charCodeAt(n);if(n++,ts(a)){e=!0;continue}if(a===93){if(!e)break;e=!1}}return n}function Pi(r){let t=r;for(let e=0;e<r.length;e++){const n=r.charCodeAt(e);ts(n)?e++:n===91?e=Ti(r,e):n===46&&(t=`${r.slice(0,e)}[^
\r]${r.slice(e+1)}`)}return t}function ss({cache:r},t){const e=r.get("regexps")??{};if(r.has("regexps")||r.set("regexps",e),Object.hasOwn(e,t))return e[t];try{const n=RegExp(Pi(t),"u");return e[t]=n,n}catch{return e[t]=null,null}}const _i={declaration:function(t,e,n){return typeof e!="string"||typeof n!="string"?!1:ss(t,`^${n}$`)?.test(e)===!0},definition:{parameters:["ValueType","ValueType"],returnType:"LogicalType"}},Fi={declaration:function(t,e,n){return typeof e!="string"||typeof n!="string"?!1:ss(t,n)?.test(e)===!0},definition:{parameters:["ValueType","ValueType"],returnType:"LogicalType"}},Ii={declaration:function(t,e){return e.length===1?e[0]:Se},definition:{parameters:["NodesType"],returnType:"ValueType"}},Or=[];function Y(r,t){return r===Or?Or:typeof t=="number"?[...r,t]:[...r,ji(t)]}function Di(r){return r?[]:Or}const Li=/[\u0000-\u001f'\\]/g;function Ni(r){const t=r.charCodeAt(0);switch(t){case 8:return"\\b";case 12:return"\\f";case 10:return"\\n";case 13:return"\\r";case 9:return"\\t";case 39:return"\\'";case 92:return"\\\\";default:return`\\u${t.toString(16).padStart(4,"0")}`}}function ji(r){return r.replace(Li,Ni)}function $e(r){throw new TypeError(`Unexpected node type: ${r.type}`)}function ue(r){throw new TypeError(`Unexpected comparison operator: ${r}`)}function ns(r,t){throw new Error(t)}function Je(r){switch(typeof r){case"object":if(r===null)return"null";if(H(r))return"NodeList";if(es(r))return"array";if(Ne(r))return"object";throw new TypeError(`Unknown type: ${r}`);case"string":return"string";case"number":return"number";case"boolean":return"boolean";default:if(r===Se)return"Nothing";throw new TypeError(`Unknown type: ${r}`)}}function Wi(r,t){if(r.length!==t.length)return!1;for(let e=0;e<r.length;e++)if(!ke(r[e],t[e]))return!1;return!0}function qi(r,t){const e=Object.keys(r),n=Object.keys(t);if(e.length!==n.length)return!1;for(const a of e)if(!Object.hasOwn(t,a)||!ke(r[a],t[a]))return!1;return!0}function ke(r,t){if(Je(r)!==Je(t))return!1;switch(Je(r)){case"string":case"number":case"boolean":case"null":return r===t;case"object":return qi(r,t);case"array":case"NodeList":return Wi(r,t);default:return!1}}function os(r,t,e){switch(e){case"==":case">=":case"<=":return!H(r)&&!H(t)&&ke(r,t);case"<":case">":return!1;case"!=":return!os(r,t,"==");default:ue(e)}}function is(r,t,e){switch(e){case"==":case"<=":case">=":return H(r)&&(H(t)&&ke(r,t)||t===Se);case"<":case">":return!1;case"!=":return!is(r,t,"==");default:ue(e)}}function as(r,t,e){switch(e){case"==":case"<=":case">=":return t===Se||H(t)&&t.length===0;case"<":case">":return!1;case"!=":return!as(r,t,"==");default:ue(e)}}function ge(r,t,e){switch(e){case"==":return r===t;case"<":return typeof t=="number"&&r<t;case"!=":return!ge(r,t,"==");case"<=":return ge(r,t,"<")||ge(r,t,"==");case">":return typeof t=="number"&&ge(t,r,"<");case">=":return typeof t=="number"&&ge(t,r,"<")||ge(r,t,"==");default:ue(e)}}function Ui(r,t,e){switch(e){case"==":case"<=":case">=":return ke(r,t);case"<":case">":return!1;case"!=":return!ke(r,t);default:ue(e)}}function cs(r,t,e){switch(e){case"==":case"<=":case">=":return r===t;case"<":case">":return!1;case"!=":return!cs(r,t,"==");default:ue(e)}}function de(r,t,e){if(typeof r!="string"||typeof t!="string")return!1;switch(e){case"==":return r===t;case"<":{let n=0;for(;r.length>n&&t.length>n;){const a=r.charCodeAt(n),c=t.charCodeAt(n);if(a===c){n++;continue}return r.charCodeAt(n)<t.charCodeAt(n)}return r.length<t.length}default:ue(e)}}function zi(r,t,e){switch(e){case"==":case"<":return de(r,t,e);case"!=":return!de(r,t,"==");case"<=":return de(r,t,"<")||de(r,t,"==");case">":return de(t,r,"<");case">=":return de(t,r,"<")||de(r,t,"==");default:ue(e)}}function Bi(r,t,e){const n=H(r)&&r.length===1?r[0]:r,a=Je(n),c=H(t)&&t.length===1?t[0]:t;switch(a){case"string":return zi(n,c,e);case"number":return ge(n,c,e);case"boolean":case"null":return cs(n,c,e);case"object":return Ui(n,c,e);case"array":return os(n,c,e);case"Nothing":return as(n,c,e);case"NodeList":return is(n,c,e);default:ns(a,"Unknown type")}}function fs(r,t,e){const n=rs();switch(e.value.type){case"RelQuery":Ge(r,t.root,t.value,e.value,a=>{n.push(a)});break;case"JsonPathQuery":Ge(r,t.root,t.root,e.value,a=>{n.push(a)});break;default:$e(e.value)}return n}function xi(r,t,e){switch(e.expression.type){case"FilterQuery":return fs(r,t,e.expression).length>0;case"FunctionExpr":return Lr(r,t,e.expression)===!0;default:$e(e.expression)}}function me(r,t,e){switch(e.type){case"LogicalNotExpr":return!me(r,t,e.expression);case"LogicalAndExpr":return me(r,t,e.left)&&me(r,t,e.right);case"LogicalOrExpr":return me(r,t,e.left)||me(r,t,e.right);case"TestExpr":return xi(r,t,e);case"ComparisonExpr":return us(r,t,e);default:$e(e)}}function Mi(r,t,e){switch(e.type){case"FunctionExpr":return Lr(r,t,e);case"FilterQuery":return fs(r,t,e);case"LogicalNotExpr":case"LogicalAndExpr":case"LogicalOrExpr":case"TestExpr":return me(r,t,e);case"Literal":return e.value;default:$e(e)}}function Vi(r){return H(r)?r.length===1?r[0]:Se:r}function Lr(r,t,e){if(!Ki(r.functions,e.name))return!1;const n=r.functions[e.name];if(n.definition.parameters.length!==e.arguments.length)return!1;const a=[];for(let c=0;c<e.arguments.length;c++){const f=Mi(r,t,e.arguments[c]),l=n.definition.parameters[c];switch(l){case"ValueType":if(!H(f)&&!bi(f))return!1;a.push(Vi(f));break;case"NodesType":if(!H(f))return!1;a.push(f);break;case"LogicalType":if(typeof f=="boolean")a.push(f);else if(H(f))a.push(f.length>0);else return!1;break;default:ns(l,"Unknown function argument type")}}return n.declaration(r,...a)}function Ki(r,t){return Object.hasOwn(r,t)}function It(r,t,e){switch(e.type){case"Literal":return e.value;case"RelSingularQuery":case"AbsSingularQuery":{const n=e.type==="RelSingularQuery"?t.value:t.root;if(e.segments.length===0)return n;const a=rs();return Ge(r,t.root,n,e,c=>{a.push(c)}),a}case"FunctionExpr":return Lr(r,t,e);default:$e(e)}}function us(r,t,e){const n=It(r,t,e.left),a=It(r,t,e.right);return Bi(n,a,e.op)}function ls(r,t,e){if(e.value.type==="ComparisonExpr"){if(!us(r,t,e.value))return}else if(!me(r,t,e.value))return;r.stack.push({root:t.root,path:t.path,value:t.value,index:t.index+1})}function Hi(r,t){return r<0?t+r:r}function ps(r,t,e){const n=Hi(e.value,t.value.length);n>=0&&n<t.value.length&&r.stack.push({root:t.root,path:Y(t.path,n),value:t.value[n],index:t.index+1})}function ds(r,{root:t,path:e,value:n,index:a},c){Object.hasOwn(n,c.value)&&r.stack.push({root:t,path:Y(e,c.value),value:n[c.value],index:a+1})}function Qe(r,t){return r>=0?r:t+r}function Ji(r,t,e,n){const a=Qe(r,n),c=Qe(t,n);if(e>=0){const g=Math.min(Math.max(a,0),n),h=Math.min(Math.max(c,0),n);return[g,h]}const f=Math.min(Math.max(a,-1),n-1);return[Math.min(Math.max(c,-1),n-1),f]}function Xi(r,{root:t,path:e,value:n,index:a},c){const f=c.step??1,l=f>=0?0:n.length-1,g=f>=0?n.length:-n.length-1,h=c.start===null?l:Qe(c.start,n.length),y=c.end===null?g:Qe(c.end,n.length),[w,k]=Ji(h,y,f,n.length);if(f>0){let C=w;for(;C<k;)r.stack.push({root:t,path:Y(e,C),value:n[C],index:a+1}),C+=f}else if(f<0){let C=k;for(;w<C;)r.stack.push({root:t,path:Y(e,C),value:n[C],index:a+1}),C+=f}}function hs(r,{root:t,path:e,value:n,index:a}){if(Array.isArray(n))for(let c=0;c<n.length;c++)r.stack.push({root:t,path:Y(e,c),value:n[c],index:a+1});else if(Ne(n))for(const c of Object.keys(n))r.stack.push({root:t,path:Y(e,c),value:n[c],index:a+1})}function Qi(r,t,e){for(const n of e.selectors)switch(n.type){case"NameSelector":Xe(t)&&ds(r,t,n);break;case"SliceSelector":He(t)&&Xi(r,t,n);break;case"IndexSelector":{He(t)&&ps(r,t,n);break}case"WildcardSelector":hs(r,t);break;case"FilterSelector":{He(t)?Gi(r,t,n):Xe(t)&&Zi(r,t,n);break}default:$e(n)}}function Gi(r,{root:t,path:e,value:n,index:a},c){for(let f=0;f<n.length;f++)ls(r,{root:t,path:Y(e,f),value:n[f],index:a},c)}function Zi(r,{root:t,path:e,value:n,index:a},c){for(const f of Object.keys(n))ls(r,{root:t,path:Y(e,f),value:n[f],index:a},c)}function Yi(r,{root:t,path:e,value:n,index:a},c){Object.hasOwn(n,c.value)&&r.stack.push({root:t,path:Y(e,c.value),value:n[c.value],index:a+1})}function ea(r,t,e){switch(e.type){case"BracketedSelection":return Qi(r,t,e);case"WildcardSelector":return hs(r,t);case"MemberNameShorthand":Xe(t)&&Yi(r,t,e);break;case"NameSelector":Xe(t)&&ds(r,t,e);break;case"IndexSelector":He(t)&&ps(r,t,e);break;default:$e(e)}}function Ge(r,t,e,n,a){const c=new Ci;c.push({root:t,path:Di(r.capturePaths),value:e,index:0});const f={cache:r.cache,capturePaths:!1,functions:r.functions,regexp:r.regexp,stack:c};for(;c.size>0;){const l=c.pop();if(l.index===n.segments.length){a(l.value,l.path);continue}const{path:g,value:h,index:y}=l,w=n.segments[y];if(ea(f,l,w.node),w.type==="DescendantSegment"){if(Array.isArray(h))for(let k=0;k<h.length;k++)c.push({root:t,path:Y(g,k),value:h[k],index:y});else if(h!==null&&typeof h=="object")for(const k of Object.keys(h))c.push({root:t,path:Y(g,k),value:h[k],index:y})}}}function ra(r,t,e,n){const a={cache:new Map,capturePaths:e.capturePaths,functions:{count:Ai,search:Fi,value:Ii,match:_i,length:Oi},regexp:"i-regexp"};Ge(a,r,r,Si(t),n)}function Tr(r,t){const e=[];return ra(r,t,{capturePaths:!1},n=>{e.push(n)}),e}function ta(r,t){try{const e=sa(r,t);return!!new Function(`return ${e};`)()}catch{return!1}}function sa(r,t){const e=[];let n=0,a="";for(;n<r.length;)if(r[n]==="$"){a.length>0&&(e.push(a),a="");const c=n,f=na(r,n);if(f.length>1){const l=oa(f,t);e.push(l)}n=c+f.length}else a+=r[n],n++;return a.length>0&&e.push(a),e.join("")}function na(r,t){let e="$",n=0,a=!1,c="",f=!1,l=0,g=t+1;for(;g<r.length;){const h=r[g];if((h==='"'||h==="'")&&!a){a=!0,c=h,e+=h,g++;continue}if(h===c&&a){a=!1,e+=h,g++;continue}if(a){e+=h,g++;continue}if(h==="["){n++,g+1<r.length&&r[g+1]==="?"&&(f=!0,l=n),e+=h,g++;continue}if(h==="]"){n--,f&&n<l&&(f=!1),e+=h,g++;continue}if(!f&&(/\s/.test(h)||/[<>=!&|,)]/.test(h)))break;e+=h,g++}return e}function oa(r,t){if(r.endsWith(".length")){const a=r.slice(0,-7),c=Pr(a),l=Tr(t,c)[0]??null;return Array.isArray(l)?String(l.length):"0"}if(r.includes("[?(")&&r.includes(")]"))return ia(r,t);const e=Pr(r),n=Tr(t,e);return JSON.stringify(n[0])}function ia(r,t){const e=r.match(/\[\?\((.*)\)\]/);if(!e)return"false";const n=e[1],a=r.substring(0,r.indexOf("[?(")),c=Pr(a),f=Tr(t,c),l=Array.isArray(f)?f.flat():f;if(!Array.isArray(l))return"false";const g=l.filter(y=>{const w=aa(n,y);try{return!!new Function("item",`return ${w};`)(y)}catch{return!1}}),h=r.substring(r.indexOf(")]")+2);if(h.startsWith(".")){const y=h.match(/\.([a-zA-Z0-9_-]+)/);if(y){const w=y[1].replace(/-/g,"_"),k=g.map(C=>C[w]);return JSON.stringify(k)}}return g.length>0?JSON.stringify(g):"false"}function aa(r,t){let e=r;return e=e.replace(/@\.([a-zA-Z0-9_-]+)\.match\(([^)]+)\)/g,(n,a,c)=>{const f=a.replace(/-/g,"_"),l=t[f];if(typeof l!="string")return"false";try{let g=c.replace(/^["']|["']$/g,"");g=g.replace(/^\/|\/$/g,"");const h=new RegExp(g);return String(h.test(l))}catch{return"false"}}),e=e.replace(/@\.([a-zA-Z0-9_-]+)/g,(n,a)=>{const c=a.replace(/-/g,"_"),f=t[c];return JSON.stringify(f)}),e}function Pr(r){return r.replace(/\.([a-zA-Z0-9_-]+)/g,(t,e)=>"."+e.replace(/-/g,"_"))}function gs({workflowId:r,step:t,criteria:e=[],ctx:n}){vi(e);const a=[];if(!r)return a.push({name:d.CHECKS.SUCCESS_CRITERIA_CHECK,passed:!1,message:`Undefined workflowId for step ${t.stepId}`,severity:n.severity.SUCCESS_CRITERIA_CHECK}),a;const c=er({ctx:n,workflowId:r,step:t});return e.forEach(f=>{const{condition:l}=f;try{if(Gt(f)){const g=l.match(/^\/(.*)\/([gimsuy]*)$/);let h,y;g?(h=g[1],y=g[2]):(h=l,y="");const{context:w}=f,k=new RegExp(h,y);a.push({name:d.CHECKS.SUCCESS_CRITERIA_CHECK,passed:k.test(ye(w,c,n.options.logger)),message:`Checking regex criteria: ${JSON.stringify(f)}`,severity:n.severity.SUCCESS_CRITERIA_CHECK,condition:l})}else if(Zt(f)){const{context:g}=f,h=ye(g,c,n.options.logger);a.push({name:d.CHECKS.SUCCESS_CRITERIA_CHECK,passed:ta(l,h),message:`Checking jsonpath criteria: ${l}`,severity:n.severity.SUCCESS_CRITERIA_CHECK,condition:l})}else a.push({name:d.CHECKS.SUCCESS_CRITERIA_CHECK,passed:ye(l,c,n.options.logger),message:`Checking simple criteria: ${JSON.stringify(f)}`,severity:n.severity.SUCCESS_CRITERIA_CHECK,condition:l})}catch(g){a.push({name:d.CHECKS.SUCCESS_CRITERIA_CHECK,passed:!1,message:`Failed to pass ${JSON.stringify(f)}: ${g.message}`,severity:n.severity.SUCCESS_CRITERIA_CHECK,condition:f.condition})}}),a}async function ca({ctx:r,workflowId:t,step:e,requestData:n}){e.checks=[];const a={successCriteriaCheck:!0,schemaCheck:!0,networkCheck:!0,unexpectedErrorCheck:!0,statusCodeCheck:!0};try{e.response=await r.apiClient.fetchResult({ctx:r,step:e,requestData:n,workflowId:t})}catch(g){return g instanceof d.UnexpectedError?(e.checks.push({name:d.CHECKS.UNEXPECTED_ERROR,passed:!1,message:g.message,severity:r.severity.UNEXPECTED_ERROR}),a.unexpectedErrorCheck=!1,a):g instanceof d.StatusCodeError?(e.checks.push({name:d.CHECKS.STATUS_CODE_CHECK,passed:!1,message:g.message,severity:r.severity.STATUS_CODE_CHECK}),a.statusCodeCheck=!1,a):(e.checks.push({name:d.CHECKS.NETWORK_ERROR,passed:!1,message:g.cause?.code?g.message+` (cause: ${g.cause.code})`:g.message,severity:r.severity.NETWORK_ERROR}),a.networkCheck=!1,r.apiClient.clearVerboseResponseLogs(),a)}const c=r.$workflows[t].steps[e.stepId].request;if(e.request=c,e.verboseLog=r.apiClient.getVerboseResponseLogs(),e.successCriteria){const g=gs({workflowId:t,step:e,criteria:e.successCriteria,ctx:{...r,$request:c,$response:e.response,$inputs:r.$workflows[t].inputs}});a.successCriteriaCheck=g.every(h=>h.passed||["off","warn"].includes(h.severity)),e.checks.push(...g)}const f=d.checkSchema({stepCallCtx:{$response:e.response,$inputs:r.$workflows[t].inputs},descriptionOperation:n.openapiOperation,ctx:r});f.length&&(a.schemaCheck=f.every(g=>g.passed||["off","warn"].includes(g.severity)),e.checks.push(...f));const l={};if(e.outputs){const g=er({ctx:{...r,$response:e.response,$inputs:r.$workflows[t].inputs},workflowId:t,step:e});for(const h of Object.keys(e.outputs))l[h]=re({payload:e.outputs[h],context:g,logger:r.options.logger})}return r.$steps[e.stepId]={outputs:{...r.$steps[e.stepId].outputs,...l}},r.$workflows[t].steps[e.stepId]={outputs:{...r.$steps[e.stepId].outputs,...l},request:c,response:e.response},a}function fa(r=0){return new Promise(t=>setTimeout(t,r*1e3))}function ua({ctx:r,descriptionName:t,openapiOperation:e,xOperation:n}){if(!t&&n?.url)return{url:n?.url};if(r.options?.server&&t){const c=Dr(r.options.server);if(c[t])return{url:c[t]}}const a=r.sourceDescriptions?.find(c=>c.name===t);if(a&&a.type==="openapi"&&a["x-serverUrl"]){if(a["x-serverUrl"].startsWith("http"))return{url:a["x-serverUrl"]};const c=a["x-serverUrl"].startsWith("$servers.")?a["x-serverUrl"].split(".")[1]:void 0;if(!c)return;const f=oe({value:`$sourceDescriptions.${t}.servers.${c}`,ctx:r,logger:r.options.logger});return Ve(f)}if(e?.servers?.[0]){const c=r.sourceDescriptions?.find(l=>l.name===e.sourceDescriptionName);let f;return r.sourceDescriptions?.length===1&&r.sourceDescriptions[0]?f="x-serverUrl"in r.sourceDescriptions[0]?r.sourceDescriptions[0]["x-serverUrl"]:void 0:c&&(f="x-serverUrl"in c?c["x-serverUrl"]:void 0),f?{url:f}:Ve(e.servers[0])}if(!t&&r?.sourceDescriptions&&r.sourceDescriptions.length===1){const c=r.sourceDescriptions[0];return"x-serverUrl"in c&&c["x-serverUrl"]?{url:c["x-serverUrl"]}:Ve(r.$sourceDescriptions[c.name]?.servers[0])||void 0}if(!(!t||!r.$sourceDescriptions||!r.$sourceDescriptions[t]||!r.$sourceDescriptions[t]?.servers?.length))return Ve(r.$sourceDescriptions[t].servers?.[0])}function Ve(r){if(r)return{url:r.url,parameters:Object.entries(r.variables||{}).map(([t,e])=>({in:"path",name:t,value:e.default})).filter(({value:t})=>!!t)}}function la(r,t){if(ha(r))return{in:r.scheme.in,name:r.scheme.name,value:r.values.apiKey};if(ga(r)){const{username:e,password:n}=r.values,a=btoa(`${e}:${n}`);return t.secretsSet.add(a),Ke(`Basic ${a}`)}if(ma(r)){const{token:e}=r.values;return t.secretsSet.add(e),Ke(`Bearer ${e}`)}if(da(r)){const{accessToken:e}=r.values;return t.secretsSet.add(e),Ke(`Bearer ${e}`)}if(pa(r)){const{accessToken:e}=r.values;return t.secretsSet.add(e),Ke(`Bearer ${e}`)}}function Ke(r,t){return{in:"header",name:"Authorization",value:r}}function pa(r){return r.scheme.type==="oauth2"}function da(r){return r.scheme.type==="openIdConnect"}function ha(r){return r.scheme.type==="apiKey"}function ga(r){return r.scheme.type==="http"&&r.scheme.scheme==="basic"}function ma(r){return r.scheme.type==="http"&&r.scheme.scheme==="bearer"}const ya={apiKey:["apiKey"],basic:["username","password"],digest:["username","password"],bearer:["token"],oauth2:["accessToken"],openIdConnect:["accessToken"],mutualTLS:[]};function $a({scheme:r,values:t}){const e=r.type==="http"?r.scheme:r.type,n=ya[e];if(!n)throw new Error(`Unsupported security scheme type: ${e}`);for(const a of n)if(!t?.[a])throw new Error(`Missing required value \`${a}\` for ${e} security scheme`);return{scheme:r,values:t}}function wa({ctx:r,runtimeContext:t,step:e,operation:n,workflowLevelXSecurityParameters:a}){const c=e["x-security"],l=[...a||[],...c||[]],g=[];for(const h of l){const y=Vt({ctx:r,security:h,operation:n});if("schemeName"in h&&!y)throw new Error(`Security scheme "${h.schemeName}" not found`);if(!y)continue;const w=Object.fromEntries(Object.entries(h?.values??{}).map(([j,P])=>{const N=re({payload:P,context:t,logger:r.options.logger});return h.values&&(h.values[j]=N),[j,N]})),k=$a({scheme:y,values:w}),C=la(k,r);C&&g.push(C)}return g}async function va(r,t,e){const{stepId:n,operationId:a,operationPath:c,"x-operation":f}=t,l=r.workflows.find(x=>x.workflowId===e),g=l&&l.parameters||[],h=f?void 0:Vo({operationId:a,operationPath:c},r);let y="",w;const k=ua({ctx:r,descriptionName:h?.descriptionName,openapiOperation:h,xOperation:f});if(f)w=f.method;else if(h)y=h?.path,w=h?.method;else throw new Error("No operation found");if(!k&&!y.includes("http"))throw new Error("No servers found in API description");if(!w)throw new Error('"method" is required to make a request');const C=h&&Uo(h,r.options.logger),{payload:j,contentType:P,replacements:N}=await Ao(t.requestBody,r),q=j||C?.requestBody,L=P||C?.contentType,_=Dt(typeof q=="object"?[{in:"header",name:"content-type",value:"application/json"}]:[],k?.parameters||[],C?.contentTypeParameters||[],t.parameters?[]:C?.parameters||[],Lt(g,r),P?[{in:"header",name:"content-type",value:P}]:[],Lt(t.parameters||[],r));r.$steps[n]||(r.$steps[n]={}),r.$workflows[e].steps[n]||(r.$workflows[e].steps[n]={}),w?.toLowerCase()==="x-query"&&(w="query"),r.$workflows[e].steps[n].request={body:q,header:he(_,"header"),path:he(_,"path"),query:he(_,"query"),url:k?.url&&y?`${k?.url}${y}`:k?.url,method:w};const b={...r,$inputs:{...r.$inputs||{},...r.$workflows[e]?.inputs||{}}},R=er({ctx:b,workflowId:e,step:t}),V=l?.["x-security"]||[],I=wa({ctx:b,runtimeContext:R,step:t,operation:h,workflowLevelXSecurityParameters:V}),W=Dt(_,I).map(x=>({...x,value:re({payload:x.value,context:R,logger:r.options.logger})}));for(const x of h?.parameters||[]){const{schema:D,name:B}=x;Le(r,D,he(_,x.in),[B])}const z=re({payload:q,context:R,contentType:L,logger:r.options.logger});if(N&&typeof z=="object"&&jo({payload:z,replacements:N,expressionContext:R,logger:r.options.logger}),L&&h?.requestBody){const x=Ho(L,h);typeof q=="object"&&Le(r,x,q)}return r.$workflows[e].steps[n].request={body:z,header:he(W,"header"),path:he(W,"path"),query:he(W,"query"),url:k?.url&&y?`${k?.url}${y}`:k?.url,method:w},{serverUrl:k,path:y,method:w,parameters:Ea(W),requestBody:z,openapiOperation:h}}function Dt(...r){const e=r.flat().filter(n=>"name"in n).reduce((n,a)=>{const c=`${a.name}:${a.in}`;return n[c]=a,n},{});return Object.values(e)}function he(r,t){return r.reduce((e,n)=>(n.in===t&&"name"in n&&(e[n.in==="header"?n.name.toLowerCase():n.name]=n.value),e),{})}function Lt(r,t){return r.map(e=>{const n=_e(e,t);if(Ir(n))return n}).filter(e=>e!==void 0)}function Ea(r){const t=[];for(const e of r)if(e.in==="header"&&e.name.toLowerCase()==="cookie"){const n=String(e.value).split(";").map(a=>{const[c,f]=a.split("=");return{name:c,value:f,in:"cookie"}});t.push(...n)}else t.push(e);return t}class ne{constructor(t){this.startTime=Date.now(),this.timeout=t}static getInstance(t){return ne.instance||(ne.instance=new ne(t)),ne.instance}static reset(){ne.instance=void 0}isTimedOut(){return Date.now()-this.startTime>this.timeout}}async function _r({step:r,ctx:t,workflowId:e,retriesLeft:n,executedStepsCount:a}){r={...r},r.retriesLeft=n;const c=t.workflows.find(b=>b.workflowId===e),{stepId:f,onFailure:l,onSuccess:g,workflowId:h,parameters:y}=r,w=(l||c?.failureActions||[]).map(b=>_e(b,t)),k=(g||c?.successActions||[]).map(b=>_e(b,t)),C=y?.map(b=>_e(b,t));if(h){const b=t.workflows.find(W=>W.workflowId===h)||oe({value:h,ctx:t,logger:t.options.logger});if(!b){const W={name:d.CHECKS.UNEXPECTED_ERROR,message:`Workflow ${d.red(h)} not found.`,passed:!1,severity:t.severity.UNEXPECTED_ERROR};r.checks.push(W);return}const R=await Fr(h,b,t,t.options.config);if(C&&C.length){const W=C.filter(ko).reduce((z,x)=>{const D={...t,$inputs:{...t.$inputs||{},...e?t.$workflows[e]?.inputs||{}:{}}};return z[x.name]=oe({value:x.value,ctx:D,logger:t.options.logger}),z},{});R.$workflows[b.workflowId].inputs={...R.$workflows[b.workflowId].inputs,...W}}d.printChildWorkflowSeparator(f,t.options.logger);const V=await Ie({workflowInput:b,ctx:R,skipLineSeparator:!0,parentStepId:f,invocationContext:`Child workflow of step ${f}`,executedStepsCount:a});t.executedSteps.push(V);const I={};if(r?.outputs){try{for(const[W,z]of Object.entries(r.outputs))I[W]=re({payload:z,context:{$outputs:R.$outputs?.[b.workflowId]||{}},logger:t.options.logger})}catch(W){const z={name:d.CHECKS.UNEXPECTED_ERROR,message:W.message,passed:!1,severity:t.severity.UNEXPECTED_ERROR};r.checks.push(z)}t.$steps[f]={outputs:I},c?.workflowId&&(t.$workflows[c.workflowId].steps[f]={outputs:I,request:void 0,response:void 0})}return{shouldEnd:!1}}if(t.executedSteps.push(r),a.value++,a.value>t.options.maxSteps)return r.checks.push({name:d.CHECKS.MAX_STEPS_REACHED_ERROR,message:`Max steps (${t.options.maxSteps}) reached`,passed:!1,severity:t.severity.MAX_STEPS_REACHED_ERROR}),{shouldEnd:!0};if(t.options.executionTimeout&&ne.getInstance(t.options.executionTimeout).isTimedOut())return r.checks.push({name:d.CHECKS.GLOBAL_TIMEOUT_ERROR,message:"Global Respect timer reached",passed:!1,severity:t.severity.GLOBAL_TIMEOUT_ERROR}),{shouldEnd:!0};if(C&&C.length){const b=C.find(R=>!("in"in _e(R,t)));if(b)throw new Error(`Parameter "in" is required for ${f} step parameter ${b.name}`)}let j=!1,P;try{if(!e)throw new Error("Workflow name is required to run a step");P=await va(t,r,e);const b=await ca({ctx:t,workflowId:e,step:r,requestData:P});j=Object.values(b).every(R=>R)}catch(b){r.verboseLog=t.apiClient.getVerboseResponseLogs();const R={name:d.CHECKS.UNEXPECTED_ERROR,message:b.message,passed:!1,severity:t.severity.UNEXPECTED_ERROR};r.checks.push(R)}const N=t.options.verbose?t.apiClient.getVerboseLogs():void 0,q=t.options.verbose?t.apiClient.getVerboseResponseLogs():void 0,L=P?.path||P?.serverUrl?.url;if(L?d.printStepDetails({testNameToDisplay:`${P?.method.toUpperCase()} ${d.white(L)}${r.stepId?` ${d.blue("- step")} ${d.white(d.bold(r.stepId))}`:""}`,checks:r.checks,verboseLogs:N,verboseResponseLogs:q,logger:t.options.logger}):d.printUnknownStep(r,t.options.logger),!j){const b=await _(w,"failure",a);if(b?.retriesLeft&&b.retriesLeft>0)return b.stepResult;if(b?.shouldEnd)return{shouldEnd:!0}}if(k.length&&j&&(await _(k,"success",a))?.shouldEnd)return{shouldEnd:!0};async function _(b=[],R,V){for(const I of b){const{type:W,criteria:z}=I;if(I.workflowId&&I.stepId)throw new Error(`Cannot use both workflowId: ${I.workflowId} and stepId: ${I.stepId} in ${I.type} action`);if(gs({workflowId:e,step:r,criteria:z,ctx:t}).every(D=>D.passed)){const D=I.workflowId?oe({value:I.workflowId,ctx:t,logger:t.options.logger}):void 0,B=I.workflowId?await Fr(I.workflowId,D,t,t.options.config):{...t,executedSteps:[]},K=I.stepId?I.stepId:void 0;if(W==="retry"){const{retryAfter:Q,retryLimit:le=0}=I;if(n=n??le,r.retriesLeft=n,n===0)return{retriesLeft:0,shouldEnd:!1};if(Q&&await fa(Q),(D||K)&&d.printActionsSeparator({stepId:f,actionName:I.name,kind:R,logger:t.options.logger}),D){const ee=await Ie({workflowInput:D,ctx:B,skipLineSeparator:!0,invocationContext:`Retry action for step ${f}`,executedStepsCount:V,retriesLeft:n-1});t.executedSteps.push(ee)}else if(K){const ee=c?.steps.find(G=>G.stepId===K);if(!ee)throw new Error(`Step ${K} not found in workflow ${e}`);await _r({step:ee,ctx:B,workflowId:e,executedStepsCount:V})}return t.options.logger.output(`
  Retrying step ${d.blue(f)} (${le-n+1}/${le})
`),{stepResult:await _r({step:r,ctx:t,workflowId:e,retriesLeft:n-1,executedStepsCount:V}),retriesLeft:n}}else{if(W==="end")return{shouldEnd:!0};if(W==="goto"){if(!D&&!K)throw new Error("Either workflowId or stepId must be provided in goto action");(D||K)&&d.printActionsSeparator({stepId:f,actionName:I.name,kind:R,logger:t.options.logger});const Q=await Ie({workflowInput:D||c,ctx:B,fromStepId:K,skipLineSeparator:!0,invocationContext:`Goto from step ${f}`,executedStepsCount:V});return t.executedSteps.push(Q),{shouldEnd:!0}}}break}}if(R==="failure")return{shouldEnd:!0}}}function Ze(r){if(r){if(typeof r=="string")return r.includes(",")?r.split(",").map(t=>t.trim()):[r];if(Array.isArray(r)){const t=[];for(const e of r)e.includes(",")?t.push(...e.split(",").map(n=>n.trim())):t.push(e);return t}}}async function ka({options:r,collectSpecData:t,executedStepsCount:e}){const n={...r,filePath:r.file,metadata:{...r}},a=await Jt({filePath:r.file,collectSpecData:t,version:r?.version,logger:r.logger,externalRefResolver:r?.externalRefResolver,skipLint:r?.skipLint});return await Sa({testDescription:a,options:n,executedStepsCount:e})}async function Sa({testDescription:r,options:t,executedStepsCount:e}){const n=new fi({fetch:t.fetch}),a=await Qt(r,t,n),c=Ze(t.workflow),f=Ze(t.skip),l=mi({workflows:a.workflows,workflowsToRun:c,workflowsToSkip:f,logger:a.options.logger}),g=[];for(const h of l){a.executedSteps=[],h.dependsOn?.length&&await Ca({workflow:h,ctx:a,config:t.config,executedStepsCount:e});const y=await Ie({workflowInput:h.workflowId,ctx:a,executedStepsCount:e});g.push(y)}return{ctx:a,executedWorkflows:g}}async function Ie({workflowInput:r,ctx:t,fromStepId:e,skipLineSeparator:n,parentStepId:a,invocationContext:c,executedStepsCount:f,retriesLeft:l}){const{logger:g}=t.options,h=performance.now(),y=d.pathBrowserifyExports.basename(t.options.filePath),w=typeof r=="string"?t.workflows.find(L=>L.workflowId===r):r;if(!w)throw new Error(`
 ${d.blue("Workflow")} ${r} ${d.blue("not found")} 
`);const k=w.inputs;if(k){const L=t.$workflows[w.workflowId].inputs;t.$workflows[w.workflowId].inputs=Xt({inputs:L,workflowInputSchema:k,env:t.options.envVariables})}const C=w.workflowId;e||d.printWorkflowSeparator({fileName:y,workflowName:C,skipLineSeparator:n,logger:g});const j=e?w.steps.findIndex(L=>L.stepId===e):0,P=w.steps.slice(j);t.$steps={};for(const L of P)try{if((await _r({step:L,ctx:t,workflowId:C,executedStepsCount:f,retriesLeft:l}))?.shouldEnd)break}catch(_){const b={name:d.CHECKS.UNEXPECTED_ERROR,message:_.message,passed:!1,severity:t.severity.UNEXPECTED_ERROR};L.checks.push(b),t.executedSteps.push(L)}const N=w.steps.some(L=>L.checks?.some(_=>!_.passed&&_.name==d.CHECKS.GLOBAL_TIMEOUT_ERROR));if(w.outputs&&C&&!N){t.$outputs||(t.$outputs={}),t.$outputs[C]||(t.$outputs[C]={});const L=er({ctx:{...t,$inputs:{...t.$inputs||{},...t.$workflows[C]?.inputs||{}}},workflowId:C}),_={};for(const b of Object.keys(w.outputs))try{_[b]=re({payload:w.outputs[b],context:L,logger:t.options.logger})}catch(R){throw new Error(`Failed to resolve output "${b}" in workflow "${C}": ${R.message}`)}t.$outputs[C]=_,t.$workflows[C].outputs=_}w.time=Math.ceil(performance.now()-h),g.printNewLine();const q=performance.now();return{type:"workflow",invocationContext:c,workflowId:C,stepId:a,startTime:h,endTime:q,totalTimeMs:Ra(t.executedSteps),executedSteps:t.executedSteps,ctx:t,globalTimeoutError:N}}async function Ca({workflow:r,ctx:t,config:e,executedStepsCount:n}){if(!r.dependsOn?.length)return;const a=await Promise.all(r.dependsOn.map(async l=>{const g=oe({value:l,ctx:t,logger:t.options.logger}),h=await Fr(l,g,t,e);return d.printRequiredWorkflowSeparator(r.workflowId,t.options.logger),Ie({workflowInput:g,ctx:h,skipLineSeparator:!0,executedStepsCount:n})}));if(Ye(a).steps.failed>0)throw new Error("Dependent workflows has failed steps")}async function Fr(r,t,e,n){const a=r&&r.startsWith("$sourceDescriptions.")&&r.split(".")[1],c=a&&e.$sourceDescriptions[a];return c?await Qt(c,{...e.options,filePath:ba(a,e.sourceDescriptions,e.options),workflow:[t.workflowId],skip:void 0,config:n},e.apiClient):{...e,executedSteps:[]}}function ba(r,t,e){const n=t&&t.find(({name:a})=>a===r);if(n){if(n.type==="openapi")return n.url;if(n.type==="arazzo")return d.pathBrowserifyExports.resolve(d.pathBrowserifyExports.dirname(e.filePath),n.url);throw new Error(`Unknown source description type ${n.type}`)}else return""}function Aa(r){return"type"in r&&r.type==="workflow"}function Ra(r){let t=0;for(const e of r)Aa(e)?t+=e.totalTimeMs:t+=e.response?.time||0;return t}async function Oa(r){const t={value:0},{files:e,executionTimeout:n,collectSpecData:a}=r;n&&(ne.reset(),ne.getInstance(n));const c=[],f=[];for(const l of e){const g=await Ta({options:{...r,file:l},startedAt:performance.now(),collectSpecData:a,executedStepsCount:t});c.push(g.hasProblems),f.push(g)}return f}async function Ta({options:r,startedAt:t,executedStepsCount:e,collectSpecData:n}){const a=await ka({options:r,collectSpecData:n,executedStepsCount:e}),{executedWorkflows:c,ctx:f}=a,l=Ye(c),g=l.workflows.failed>0,h=l.workflows.warnings>0,y=c.some(w=>w.globalTimeoutError);return(l.steps.failed>0||l.steps.warnings>0||l.steps.skipped>0)&&ri(c,r.logger),Zo({startedAt:t,workflows:c,options:r}),{hasProblems:g,hasWarnings:h,file:r.file,executedWorkflows:c,options:r,ctx:f,totalTimeMs:performance.now()-t,totalRequests:l.totalRequests,globalTimeoutError:y,...f.noSecretsMasking&&{secretValues:Array.from(f.secretsSet)||[]}}}exports.RESET_ESCAPE_CODE=d.RESET_ESCAPE_CODE;exports.parseRuntimeExpression=d.parseRuntimeExpression;exports.calculateTotals=Ye;exports.conditionallyMaskSecrets=fe;exports.maskSecrets=Mt;exports.run=Oa;
