@redocly/cli 2.43.3 → 2.44.1

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.
@@ -1,8 +0,0 @@
1
- import { createRequire as __createRequire } from 'node:module';
2
- import { fileURLToPath as __fileURLToPath } from 'node:url';
3
- import { dirname as __pathDirname } from 'node:path';
4
- const require = __createRequire(import.meta.url);
5
- var __filename = __fileURLToPath(import.meta.url);
6
- var __dirname = __pathDirname(__filename);
7
- import{a as ce}from"./WZXA5XPB.js";import"./RFWIIJFG.js";function fe(e){return e}async function V(e){return typeof e=="function"?await e():e}function le(e){let t="";for(let n of new TextEncoder().encode(e))t+=String.fromCharCode(n);return btoa(t)}function pe(e,t){return e.kind==="apiKey"?t.auth?.apiKey?.[e.scheme]!==void 0:e.kind==="bearer"?t.auth?.bearer!==void 0:t.auth?.basic!==void 0}async function Q(e,t){let n=e.find(d=>d.every(a=>pe(a,t)))??e[0]??[],o={},r={},s=[];for(let d of n)if(d.kind==="apiKey"){let a=t.auth?.apiKey?.[d.scheme];if(a===void 0)continue;let f=await V(a);d.in==="header"?o[d.name]=f:d.in==="query"?r[d.name]=f:s.push(`${d.name}=${encodeURIComponent(f)}`)}else if(d.kind==="bearer"){let a=t.auth?.bearer;a!==void 0&&(o.Authorization=`Bearer ${await V(a)}`)}else{let a=t.auth?.basic;a!==void 0&&(o.Authorization=`Basic ${le(`${a.username}:${a.password}`)}`)}return s.length>0&&(o.Cookie=s.join("; ")),{headers:o,query:r}}var S=class extends Error{url;status;statusText;body;constructor(t,n,o,r){super(`Request failed with status ${n}`),this.name="ApiError",this.url=t,this.status=n,this.statusText=o,this.body=r}},O=class extends Error{operationId;timeout;attempt;constructor(t,n,o){super(`Request "${t}" timed out after ${n} ms (attempt ${o})`),this.name="TimeoutError",this.operationId=t,this.timeout=n,this.attempt=o}};function j(e){let t=e.reason;return t instanceof Error?t:new DOMException("The operation was aborted.","AbortError")}async function L(e,t){if(t==="void"){if(e.status===204||e.status===205||e.status===304||!(e.headers.get("content-type")??"").toLowerCase().includes("json"))return;let s=await e.text().catch(()=>"");if(s==="")return;try{return JSON.parse(s)}catch{return}}if(e.status===204)return;if(t==="stream")return e.body;if(t==="blob")return e.blob();if(t==="arrayBuffer")return e.arrayBuffer();if(t==="formData")return e.formData();if(t==="text")return e.text();if(t==="json")return e.json();let n=(e.headers.get("content-type")??"").toLowerCase();if(n.includes("json"))return e.json();if(n.startsWith("text/"))return e.text();let o=await e.blob();return o.size>0?o:void 0}async function k(e){return(e.headers.get("content-type")??"").toLowerCase().includes("json")?e.json().catch(()=>{}):e.text().catch(()=>{})}var me=new Set(["GET","HEAD","PUT","DELETE","OPTIONS"]),ye=new Set([408,429,500,502,503,504]);function U(e){return me.has(e.request.method.toUpperCase())||"Idempotency-Key"in e.request.headers||"idempotency-key"in e.request.headers?e.response===void 0||ye.has(e.response.status):!1}function z(e,t,n){if(n){let s=Number(n);if(!Number.isNaN(s))return s*1e3;let d=Date.parse(n);if(!Number.isNaN(d))return Math.max(0,d-Date.now())}let o=e.retryDelay??1e3,r=e.retryStrategy==="fixed"?o:o*Math.pow(2,t-1);return e.jitter===!1?r:Math.random()*r}function $(e,t){return new Promise((n,o)=>{if(t?.aborted){o(j(t));return}let r=()=>{clearTimeout(s),o(j(t))},s=setTimeout(()=>{t&&t.removeEventListener("abort",r),n()},e);t&&t.addEventListener("abort",r,{once:!0})})}function D(e){if(e===void 0)return{};if(e instanceof Headers){let t={};return e.forEach((n,o)=>{t[o]=n}),t}return Array.isArray(e)?Object.fromEntries(e):e}function J(e){return[...e.onRequest||e.onResponse||e.onError?[{onRequest:e.onRequest,onResponse:e.onResponse,onError:e.onError}]:[],...e.middleware??[]]}async function I(e,t,n,o,r,s,d,a="application/json"){let{retry:f,timeout:u,idempotencyKey:i,...c}=o,l={...e.retry,...f},p=u??e.timeout,h=i??e.idempotencyKey,R=typeof e.headers=="function"?await e.headers():e.headers,A={Accept:a,...R,...D(c.headers)},B=(c.method??"GET").toUpperCase();h!==void 0&&h!==!1&&(B==="POST"||B==="PATCH")&&!("Idempotency-Key"in A)&&!("idempotency-key"in A)&&(A["Idempotency-Key"]=typeof h=="string"?h:typeof h=="function"?h():crypto.randomUUID()),typeof e.clientHeader=="string"&&typeof document>"u"&&!("X-Redocly-Client"in A)&&!("x-redocly-client"in A)&&(A["X-Redocly-Client"]=e.clientHeader);let m={url:n,method:c.method??"GET",headers:A,body:r,operation:t},v=J(e);for(let y of v)y.onRequest&&await y.onRequest(m);let C;if(m.body!==void 0){let y=m.body,w=y instanceof Blob||y instanceof ArrayBuffer||ArrayBuffer.isView(y),g=typeof FormData<"u"&&y instanceof FormData,P=y instanceof URLSearchParams;if(g||P||w||typeof y=="string")C=y;else if(s?.multipart===!0){if(!d.serializeMultipart)throw new Error("Multipart capability not wired: cannot serialize the request body");C=d.serializeMultipart(y)}else C=JSON.stringify(y),!("Content-Type"in m.headers)&&!("content-type"in m.headers)&&(m.headers["Content-Type"]=s?.contentType??"application/json")}let q=e.fetch??fetch,E=1+(l.retries??0),T=l.retryOn??U,x=c.signal??void 0,b=0;for(;;){if(b++,x?.aborted)throw j(x);let y=p?x?AbortSignal.any([x,AbortSignal.timeout(p)]):AbortSignal.timeout(p):x,w;try{w=await q(m.url,{...c,signal:y,method:m.method,headers:m.headers,body:C})}catch(g){if(b<E&&!x?.aborted&&await T({attempt:b,request:m,error:g})){await $(z(l,b,null),x);continue}throw p&&!x?.aborted&&g instanceof DOMException&&g.name==="TimeoutError"?new O(t.id,p,b):g}for(let g=v.length-1;g>=0;g--){let P=v[g].onResponse;if(P){let H=await P(w,m);H&&H!==w&&(await w.body?.cancel().catch(()=>{}),w=H)}}if(!w.ok&&b<E&&!x?.aborted&&await T({attempt:b,request:m,response:w})){let g=w.headers.get("retry-after");await w.body?.cancel().catch(()=>{}),await $(z(l,b,g),x);continue}return{response:w,context:m}}}function M(e){return encodeURIComponent(e).replace(/%(3A|2F|3F|23|5B|5D|40|21|24|26|27|28|29|2A|2B|2C|3B|3D)/g,t=>decodeURIComponent(t))}function X(e,t){return e.replace(/\{([^{}]+)\}/g,(n,o)=>{let r=t[o];if(r===void 0)throw new Error(`Missing path parameter "${o}"`);return encodeURIComponent(String(r))})}function Y(e,t,n,o){let r=e.length;for(;r>0&&e.charCodeAt(r-1)===47;)r--;let s=e.slice(0,r)+t;if(!n)return s;let d=new URLSearchParams,a=[];for(let[u,i]of Object.entries(n)){if(i==null)continue;let c=o?.[u];if(!c){if(Array.isArray(i))for(let l of i)l!=null&&d.append(u,String(l));else if(Object(i)===i)for(let[l,p]of Object.entries(i))p!=null&&d.append(`${u}[${l}]`,String(p));else d.append(u,String(i));continue}if(Array.isArray(i)){let l=i.filter(p=>p!=null).map(String);if(c.style==="form"&&c.explode)for(let p of l)c.allowReserved?a.push(`${u}=${M(p)}`):d.append(u,p);else{let p=c.style==="pipeDelimited"?"|":c.style==="spaceDelimited"?"%20":",",h=c.allowReserved?M:encodeURIComponent;a.push(`${encodeURIComponent(u)}=${l.map(h).join(p)}`)}}else if(Object(i)===i)for(let[l,p]of Object.entries(i))p!=null&&(c.allowReserved?a.push(`${u}[${l}]=${M(String(p))}`):d.append(`${u}[${l}]`,String(p)));else c.allowReserved?a.push(`${u}=${M(String(i))}`):d.append(u,String(i))}let f=[d.toString(),...a].filter(Boolean).join("&");return f?`${s}?${f}`:s}function te(e){return e==="text"?"text/*":e==="blob"||e==="arrayBuffer"||e==="stream"||e==="formData"?"*/*":"application/json"}function re(e){return e.responseKind==="void"||e.responseKind==="blob"||e.responseKind==="text"?e.responseKind:"auto"}function he(e,t){let n={},o=new Set;for(let r of e.params??[])r.in==="path"&&(o.add(r.name),n[r.name]=t[r.name]);for(let r of Object.keys(t))if(!(r==="params"||r==="body"||r==="headers"||r==="cookies")&&!o.has(r))throw new TypeError(`Unknown argument "${r}" for operation "${e.id}". Query parameters go under params: { \u2026 } and the request body under body; valid keys are params, body, headers, cookies`+(o.size>0?`, and the path parameters (${[...o].join(", ")}).`:"."));return{path:n,query:t.params,body:t.body,headers:t.headers,cookies:t.cookies}}function we(e){let t;for(let n of e.params??[])n.in!=="query"||!(n.style!==void 0&&n.style!=="form"||n.explode===!1||n.allowReserved===!0)||(t??={},t[n.name]={style:n.style??"form",explode:n.explode??!0,allowReserved:n.allowReserved});return t}function be(e){let t={};for(let[n,o]of Object.entries(e??{}))o!=null&&(t[n]=String(o));return t}async function _(e,t,n,o,r){let{path:s,query:d,body:a,headers:f,cookies:u}=he(t,n),i=t.security?.length&&r.resolveAuth?await r.resolveAuth(t.security,e):{headers:{},query:{}},c=Object.entries(u??{}).filter(([,R])=>R!=null).map(([R,A])=>`${R}=${encodeURIComponent(String(A))}`);c.length>0&&(i.headers.Cookie=[i.headers.Cookie,...c].filter(Boolean).join("; "));let l={...d,...i.query},p=Y(e.serverUrl??"",X(t.path,s),Object.keys(l).length>0?l:void 0,we(t)),h={...o,method:t.method.toUpperCase(),headers:{...i.headers,...be(f),...D(o.headers)}};return{url:p,init:h,body:a}}async function xe(e,t,n,o,r){let s=await _(e,t,n,o,r),d={id:t.id,path:t.path,tags:[...t.tags??[]]},{parseAs:a,...f}=s.init,u=a??re(t),{response:i,context:c}=await I(e,d,s.url,f,s.body,t.body,r,te(u));if(e.errorMode==="result")return i.ok?{data:await L(i,u),error:void 0,response:i}:{data:void 0,error:await k(i),response:i};if(!i.ok){let l=new S(c.url,i.status,i.statusText,await k(i));for(let p of J(e))p.onError&&(l=await p.onError(l,c));throw l}return L(i,u)}function F(e,t){if(!e.paginate)throw new Error(`Pagination capability not wired: cannot iterate operation "${t.id}"`);return e.paginate}function Z(e,t){return t.errorMode!=="result"?e:async(n,o)=>{let r=await e(n,o);if(!r.response.ok){let{response:s}=r;throw new S(s.url,s.status,s.statusText,r.error)}return r.data}}function ee(e,t,n){return async(o={},r={})=>{let s=await _(e,t,o,r,n),{parseAs:d,...a}=s.init,f=d??re(t),u={id:t.id,path:t.path,tags:[...t.tags??[]]},{response:i}=await I(e,u,s.url,a,s.body,t.body,n,te(f));if(!i.ok)throw new S(s.url,i.status,i.statusText,await k(i));return{page:await L(i,f),linkHeader:i.headers.get("link"),url:i.url===""?s.url:i.url}}}function ne(e,t={},n={}){let o=t,r={...o,middleware:[...o.middleware??[]]},s={};for(let[d,a]of Object.entries(e))if(a.responseKind==="sse"){let f=(u={},i={})=>{if(!n.sse)throw new Error(`SSE capability not wired: cannot stream operation "${a.id}"`);let c=n.sse;return(async function*(){let l={id:a.id,path:a.path,tags:[...a.tags??[]]};yield*c(r,l,async()=>{let h=await _(r,a,u,i,n);return{url:h.url,init:h.init,body:h.body}},a.sseDataKind??"text")})()};Object.defineProperty(f,"name",{value:d}),Object.defineProperty(f,"operationId",{value:a.id}),s[d]=f}else{let f=(i={},c={})=>xe(r,a,i,c,n);Object.defineProperty(f,"name",{value:d}),Object.defineProperty(f,"operationId",{value:a.id});let u=a.pagination;s[d]=u===void 0?f:u.style==="link"?Object.assign(f,{pages:(i,c)=>F(n,a).pagesByLink(ee(r,a,n),i,c),items:(i,c)=>F(n,a).itemsByLink(ee(r,a,n),u,i,c)}):Object.assign(f,{pages:(i,c)=>F(n,a).pages(Z(f,r),u,i,c),items:(i,c)=>F(n,a).items(Z(f,r),u,i,c)})}return s.configure=d=>{let{errorMode:a,auth:f,...u}=d;Object.assign(r,u),f&&(r.auth={...r.auth,...f,...f.apiKey?{apiKey:{...r.auth?.apiKey,...f.apiKey}}:{}})},s.use=(...d)=>{r.middleware=[...r.middleware??[],...d]},s.auth={bearer(d){r.auth={...r.auth,bearer:d}},basic(d,a){r.auth={...r.auth,basic:{username:d,password:a}}},apiKey(d,a){r.auth={...r.auth,apiKey:{...r.auth?.apiKey,[d]:a}}}},s}function oe(e){let t=new FormData,n=(o,r)=>{r!=null&&(r instanceof Blob||typeof r=="string"?t.append(o,r):r instanceof Date?t.append(o,r.toISOString()):Object(r)===r?t.append(o,JSON.stringify(r)):t.append(o,String(r)))};for(let[o,r]of Object.entries(e))if(Array.isArray(r))for(let s of r)n(o,s);else n(o,r);return t}function N(e,t){if(t==="")return e;if(!t.startsWith("/"))return;let n=e;for(let o of t.slice(1).split("/")){let r=o.replaceAll("~1","/").replaceAll("~0","~");if(Array.isArray(n)){if(!/^(0|[1-9]\d*)$/.test(r))return;n=n[Number(r)]}else if(Object(n)===n&&r in n)n=n[r];else return}return n}async function*G(e,t,n={},o){if(t.style==="cursor"){let r=n.params?.[t.param];for(;;){let s={...n.params};r!==void 0&&(s[t.param]=r);let d=await e({...n,params:s},o);if(yield d,t.hasMore!==void 0&&N(d,t.hasMore)===!1)return;let a=N(d,t.nextCursor);if(a==null||a==="")return;if(typeof a!="string"&&typeof a!="number")throw new Error(`Pagination cursor at ${t.nextCursor} is not a string or number`);if(a===r)throw new Error("Pagination did not advance: operation returned the same cursor twice");r=a}}else{if(t.style==="link")throw new Error("link-style pagination iterates via pagesByLink");{let r=n.params?.[t.param],s=t.style==="page"?1:0,a=r==null||r===""||Number.isNaN(Number(r))?s:Number(r),f;for(;;){let u=await e({...n,params:{...n.params,[t.param]:a}},o),i=N(u,t.items),c=Array.isArray(i)?JSON.stringify(i):void 0;if(c!==void 0&&c===f)throw new Error("Pagination did not advance: the operation returned the same page twice");if(yield u,!Array.isArray(i)||i.length===0)return;f=c,a+=t.style==="page"?1:i.length}}}}async function*ie(e,t,n,o){for await(let r of G(e,t,n,o)){let s=N(r,t.items);Array.isArray(s)&&(yield*s)}}function ge(e){if(e!==null)for(let t of e.split(/,\s*(?=<)/)){let n=/^\s*<([^>]*)>(.*)$/.exec(t);if(!n)continue;let o=/;\s*rel\s*=\s*"?([^";]+)"?/i.exec(n[2]);if(o&&o[1].split(/\s+/).includes("next"))return n[1]}}async function*W(e,t={},n){let o=t.params,r;for(;;){let{page:s,linkHeader:d,url:a}=await e({...t,params:o},n);yield s;let f=ge(d);if(f===void 0)return;let u=new URL(a,"http://relative.invalid"),i=new URL(f,u).toString();if(i===r||i===u.toString())throw new Error('Pagination did not advance: the Link rel="next" target repeats');r=i;let c={};for(let[l,p]of new URL(i).searchParams){let h=c[l];h===void 0?c[l]=p:Array.isArray(h)?h.push(p):c[l]=[h,p]}o={...t.params,...c}}}async function*ae(e,t,n,o){for await(let r of W(e,n,o)){let s=N(r,t.items);Array.isArray(s)&&(yield*s)}}var Ee=/(?:\r\n|\r|\n){2}/,K=class extends Error{};async function*de(e,t,n,o="text"){let r,s,d=0;for(;;){let{url:a,init:f,body:u}=await n(),{reconnect:i=!0,reconnectDelay:c,...l}=f,p=l.signal??void 0;if(p?.aborted)return;let h={Accept:"text/event-stream",...D(l.headers)},R=r===void 0?h:{...h,"Last-Event-ID":r};try{let{response:m}=await I(e,t,a,{...l,method:l.method??"GET",headers:R,timeout:0},u,void 0,{});if(!m.ok){let T=await k(m);throw new S(a,m.status,m.statusText,T)}d=0;let v=m.body;if(!v)return;let C=v.getReader(),q=new TextDecoder,E="";try{for(;;){let{done:T,value:x}=await C.read();E+=T?q.decode():q.decode(x,{stream:!0});let b;for(;(b=Ee.exec(E))!==null;){let y=E.slice(0,b.index);E=E.slice(b.index+b[0].length);let w=se(y,o);w&&(w.id!==void 0&&(r=w.id),w.retry!==void 0&&(s=w.retry),yield w)}if(T){let y=E.length>0?se(E,o):void 0;y&&(y.id!==void 0&&(r=y.id),y.retry!==void 0&&(s=y.retry),yield y);return}if(E.length>1048576)throw new K("SSE frame exceeded 1048576 characters without a delimiter")}}finally{await C.cancel().catch(()=>{})}}catch(m){if(p?.aborted)return;if(m instanceof S||m instanceof K||!i)throw m}d++;let B=Math.min((s??c??1e3)*Math.pow(2,d-1),3e4);try{await $(Math.random()*B,p)}catch{return}}}function se(e,t){let n,o=[],r,s,d=!1;for(let u of e.split(/\r\n|\n|\r/)){if(u===""||u.startsWith(":"))continue;let i=u.indexOf(":"),c=i===-1?u:u.slice(0,i),l=i===-1?"":u.slice(i+1);l.startsWith(" ")&&(l=l.slice(1)),d=!0,c==="event"?n=l:c==="data"?o.push(l):c==="id"?r=l:c==="retry"&&/^\d+$/.test(l)&&(s=Number(l))}if(!d)return;let a=o.join(`
8
- `),f=a;if(t==="json"&&a!=="")try{f=JSON.parse(a)}catch(u){throw new K(`Failed to parse SSE event data as JSON: ${u instanceof Error?u.message:String(u)}`)}return{event:n,data:f,id:r,retry:s}}function ue(e,t={}){return{...e?.config,...t,middleware:[...e?.middleware??[],...t.middleware??[]]}}function Se(e,t){return ne(e,t,{serializeMultipart:oe,resolveAuth:Q,sse:de,paginate:{pages:G,items:ie,pagesByLink:W,itemsByLink:ae}})}function Ae(e,t){let n={...e};for(let[o,r]of Object.entries(t))r!==void 0&&(n[o]=r);return n}function nt(e){return e}async function it(e){return(await import("./47NNACMG.js")).generateClient(e)}export{S as ApiError,ce as NotSupportedError,O as TimeoutError,Se as createClient,U as defaultRetryOn,fe as defineClientSetup,nt as defineGenerator,it as generateClient,Ae as mergeConfig,ue as mergeSetup};