@redocly/cli 2.46.0 → 2.46.2

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.
@@ -4,5 +4,5 @@ import { dirname as __pathDirname } from 'node:path';
4
4
  const require = __createRequire(import.meta.url);
5
5
  var __filename = __fileURLToPath(import.meta.url);
6
6
  var __dirname = __pathDirname(__filename);
7
- import{c}from"./CN6PFMVJ.js";import{open as C,readdir as N,stat as P}from"node:fs/promises";import d from"node:path";var $=new Set([".yaml",".yml",".json"]);async function D(e){let n=[];async function t(r){let o=await N(r,{withFileTypes:!0});for(let s of o){if(s.name.startsWith("."))continue;let i=d.join(r,s.name);if(s.isDirectory()){await t(i);continue}s.isFile()&&$.has(d.extname(s.name).toLowerCase())&&n.push(i)}}return await t(e),n.sort(),n}async function _(e,n=4096){let t=await C(e,"r");try{let r=Buffer.allocUnsafe(n),{bytesRead:o}=await t.read(r,0,n,0);return r.toString("utf8",0,o)}finally{await t.close()}}function M(e){return d.resolve(process.cwd(),e)}async function K(e){let n=await P(e);if(n.isFile())return[e];if(!n.isDirectory())return[];let t=[];async function r(o){let s=await N(o,{withFileTypes:!0});for(let i of s){if(i.name.startsWith("."))continue;let a=d.join(o,i.name);if(i.isDirectory()){await r(a);continue}i.isFile()&&t.push(a)}}return await r(e),t.sort(),t}var k="drift.local",O=`http://${k}`;function u(e){return e===k}var U=new Set(["accept","accept-charset","accept-encoding","accept-language","authorization","baggage","cache-control","cdn-loop","cookie","connection","content-length","content-type","dpr","dnt","downlink","ect","forwarded","host","if-match","if-modified-since","if-none-match","if-range","if-unmodified-since","origin","pragma","priority","range","referer","sec-fetch-dest","sec-fetch-mode","sec-fetch-site","sec-fetch-user","sec-gpc","sentry-trace","te","traceparent","tracestate","upgrade","upgrade-insecure-requests","user-agent","via","x-client-trace-id","x-cloud-trace-context","x-correlation-id","x-http-method-override","x-hub-signature","x-hub-signature-256","x-method-override","x-real-ip","x-request-id","x-forwarded-for","x-forwarded-host","x-forwarded-port","x-forwarded-proto"]),J=["cf-","sec-ch-","sec-fetch-","x-amz-","x-amzn-","x-b3-","x-envoy-","x-forwarded-","x-github-"],R=`
7
+ import{c}from"./ODUYC4TH.js";import{open as C,readdir as N,stat as P}from"node:fs/promises";import d from"node:path";var $=new Set([".yaml",".yml",".json"]);async function D(e){let n=[];async function t(r){let o=await N(r,{withFileTypes:!0});for(let s of o){if(s.name.startsWith("."))continue;let i=d.join(r,s.name);if(s.isDirectory()){await t(i);continue}s.isFile()&&$.has(d.extname(s.name).toLowerCase())&&n.push(i)}}return await t(e),n.sort(),n}async function _(e,n=4096){let t=await C(e,"r");try{let r=Buffer.allocUnsafe(n),{bytesRead:o}=await t.read(r,0,n,0);return r.toString("utf8",0,o)}finally{await t.close()}}function M(e){return d.resolve(process.cwd(),e)}async function K(e){let n=await P(e);if(n.isFile())return[e];if(!n.isDirectory())return[];let t=[];async function r(o){let s=await N(o,{withFileTypes:!0});for(let i of s){if(i.name.startsWith("."))continue;let a=d.join(o,i.name);if(i.isDirectory()){await r(a);continue}i.isFile()&&t.push(a)}}return await r(e),t.sort(),t}var k="drift.local",O=`http://${k}`;function u(e){return e===k}var U=new Set(["accept","accept-charset","accept-encoding","accept-language","authorization","baggage","cache-control","cdn-loop","cookie","connection","content-length","content-type","dpr","dnt","downlink","ect","forwarded","host","if-match","if-modified-since","if-none-match","if-range","if-unmodified-since","origin","pragma","priority","range","referer","sec-fetch-dest","sec-fetch-mode","sec-fetch-site","sec-fetch-user","sec-gpc","sentry-trace","te","traceparent","tracestate","upgrade","upgrade-insecure-requests","user-agent","via","x-client-trace-id","x-cloud-trace-context","x-correlation-id","x-http-method-override","x-hub-signature","x-hub-signature-256","x-method-override","x-real-ip","x-request-id","x-forwarded-for","x-forwarded-host","x-forwarded-port","x-forwarded-proto"]),J=["cf-","sec-ch-","sec-fetch-","x-amz-","x-amzn-","x-b3-","x-envoy-","x-forwarded-","x-github-"],R=`
8
8
  `;function Y(e){return e.split(R)}function g(e,n,t){let r=n.toLowerCase(),o=e[r];if(o===void 0){e[r]=t;return}e[r]=r==="set-cookie"?`${o}${R}${t}`:`${o},${t}`}function p(e){if(!c(e)&&!Array.isArray(e))return{};let n={};if(Array.isArray(e)){for(let t of e){if(!c(t))continue;let{name:r,value:o}=t;typeof r=="string"&&o!==void 0&&g(n,r,String(o))}return n}for(let[t,r]of Object.entries(e))if(r!=null){if(Array.isArray(r)){for(let o of r)g(n,t,String(o));continue}g(n,t,String(r))}return n}function f(e){try{return new URL(e)}catch{return new URL(e,O)}}function m(e){return e.length>1&&e.endsWith("/")?e.slice(0,-1):e}function L(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function V(e){let n=[],t=0,r=e.startsWith("/")?e:`/${e}`,s=m(r).split("/").map(i=>{if(!i)return"";let a=i.match(/^\{([^}]+)\}$/);return a?(n.push(a[1]),"([^/]+)"):(t+=2,L(i))}).join("/");return{regex:new RegExp(`^${s||"/"}$`),params:n,score:t}}function l(e,n){if(n&&A(e))try{return JSON.parse(n)}catch{return}}function E(e){return e?e.split(";")[0]?.trim().toLowerCase()??"":""}function A(e){let n=E(e);return n==="application/json"||n.endsWith("+json")}function Q(e,n){let t=E(n);if(!t)return e["application/json"]??e["*/*"];if(e[t]!==void 0)return e[t];let[r,o]=t.split("/");if(r&&o){let s=`${r}/*`;if(e[s]!==void 0)return e[s]}return e["*/*"]}function Z(e){let n=new Set,t=[];for(let r of e){let o=r.trim().toLowerCase();o.length!==0&&(o.endsWith("*")?t.push(o.slice(0,-1)):n.add(o))}return{names:n,prefixes:t}}function v(e,n){let t=e.toLowerCase();return t.startsWith(":")||U.has(t)||J.some(r=>t.startsWith(r))?!0:n?n.names.has(t)||n.prefixes.some(r=>t.startsWith(r)):!1}import{createReadStream as q}from"node:fs";import{readFile as B}from"node:fs/promises";import{createInterface as F}from"node:readline";function I(e){if(e!=null){if(typeof e=="string")return e;if(Buffer.isBuffer(e))return e.toString("utf8");if(c(e)||Array.isArray(e))try{return JSON.stringify(e)}catch{return String(e)}return String(e)}}function se(e){if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"&&e.trim()!==""){let n=Number(e);if(Number.isFinite(n))return n}}function H(e,n){if(e!=null){if(n==="base64"&&typeof e=="string")try{return Buffer.from(e,"base64").toString("utf8")}catch{return e}return I(e)}}function ae(e,n,t){let r=e.method?.toUpperCase(),o=e.url;if(!r||!o)return null;let s=p(e.requestHeaders),i=f(o);if(u(i.host)&&s.host)try{i=new URL(`${i.protocol}//${s.host}${i.pathname}${i.search}`)}catch{i=f(o)}let a=e.requestContentType??s["content-type"],y=H(e.requestBody),T={method:r,url:i.toString(),path:i.pathname,query:i.searchParams,protocol:i.protocol,protocolKnown:e.schemeKnown??/^https?:\/\//i.test(o),host:u(i.host)?void 0:i.host||void 0,headers:s,contentType:a,bodyText:y,bodyJson:l(a,y)},h,x=e.responseStatus;if(x!==void 0){let w=p(e.responseHeaders),S=e.responseContentType??w["content-type"],b=H(e.responseBody);h={status:x,statusText:e.responseStatusText,headers:w,contentType:S,bodyText:b,bodyJson:l(S,b)}}return{index:n,source:t,startedAt:e.startedAt,request:T,response:h,raw:e.raw}}async function*ce(e){let n=q(e,{encoding:"utf8"}),t=F({input:n,crlfDelay:1/0});for await(let r of t){let o=r.trim();if(o)try{let s=JSON.parse(o);c(s)&&(yield s)}catch{}}}async function*ue(e,n){let t=await B(e,"utf8"),r=JSON.parse(t);if(n)for(let o of n.split("."))r=c(r)?r[o]:void 0;if(Array.isArray(r))for(let o of r)c(o)&&(yield o)}function fe(e){return p(e)["content-type"]}function ge(e){return e?.replace(/\/+$/,"")||void 0}function z(e,n){if(!n||n==="/")return e||"/";if(e===n)return"/";if(e.startsWith(`${n}/`))return e.slice(n.length)||"/"}function me(e,n){if(n.startsWith("/"))return z(e.path,n);let t=f(n.includes("://")?n:`http://${n}`);if(!(u(t.host)||e.host!==void 0&&e.host.toLowerCase()!==t.host))return z(e.path,m(t.pathname))}export{D as a,_ as b,M as c,K as d,u as e,Y as f,f as g,m as h,V as i,E as j,A as k,Q as l,Z as m,v as n,I as o,se as p,H as q,ae as r,ce as s,ue as t,fe as u,ge as v,me as w};
@@ -4,7 +4,7 @@ import { dirname as __pathDirname } from 'node:path';
4
4
  const require = __createRequire(import.meta.url);
5
5
  var __filename = __fileURLToPath(import.meta.url);
6
6
  var __dirname = __pathDirname(__filename);
7
- import{a as G}from"./GCKQFE6S.js";import{c as I,d as N,e as fe,h as q,j as _,k as ue,v as D,w as B}from"./LLREHKJO.js";import{a as ce,c as pe}from"./QGADGBO2.js";import{b as ae}from"./7KOLBOQ5.js";import{B as oe,C as P,O as y,c as b,ca as se,ia as ie,l as $}from"./CN6PFMVJ.js";import"./NEWT5A6S.js";import"./RFWIIJFG.js";import{mkdir as Bt,writeFile as zt}from"node:fs/promises";import Ht from"node:path";import*as Ce from"node:process";var Ve=/^[a-zA-Z][a-zA-Z0-9]*(?:[_\-.][a-zA-Z0-9]+)*$/,Fe=/^[0-9a-f-]{8,}$/i,Ye=[["uuid",/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i],["date-time",/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/],["date",/^\d{4}-\d{2}-\d{2}$/],["email",/^[^\s@]+@[^\s@]+\.[^\s@]+$/],["uri",/^https?:\/\/\S+$/],["ipv4",/^(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)$/]],J=new WeakMap;function z(e){return{formats:Ye.filter(([,t])=>t.test(e)).map(([t])=>t),values:[e],count:1,overflow:!1}}function C(e,t){if(!e)return t;if(!t)return e;let r={formats:e.formats.filter(n=>t.formats.includes(n)),values:[],count:e.count+t.count,overflow:e.overflow||t.overflow};if(!r.overflow){let n=[...e.values];for(let o of t.values)n.includes(o)||n.push(o);n.length>10?r.overflow=!0:r.values=n}return r}function H(e,t){J.set(e,t)}function L(e){return J.get(e)}function U(e,t){let r=J.get(e);r&&J.set(t,r)}function Ke(e){return e.length<=30&&!Fe.test(e)&&Ve.test(e)}function W(e,t){return e.formats.length>0?{format:e.formats[0]}:t&&!e.overflow&&e.count>=4&&e.values.length>0&&e.values.length<=5&&e.values.length*2<=e.count&&e.values.every(Ke)?{enum:[...e.values].sort()}:{}}function R(e){let t=J.get(e);if(t){let r=typeof e.type=="string"?[e.type]:e.type??[];r.includes("string")&&Object.assign(e,W(t,r.length===1))}for(let r of Object.values(e.properties??{}))R(r);e.additionalProperties&&R(e.additionalProperties),e.items&&R(e.items);for(let r of e.oneOf??[])R(r)}function me(e){for(let t of Object.values(e.paths))for(let r of Object.values(t)){for(let n of Object.values(r.requestBody?.content??{}))R(n.schema);for(let n of Object.values(r.responses))for(let o of Object.values(n.content??{}))R(o.schema)}for(let t of Object.values(e.components?.schemas??{}))R(t);return e}var be=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,F=/^\d+$/,We=/^[0-9a-hjkmnp-tv-z]{26}$/i,Xe=/^[a-z][a-z0-9]*_(?=[0-9a-z]*\d)[0-9a-z]{10,}$/i,Ze=/^[a-z](?=[a-z0-9]*\d)[a-z0-9]{23,24}$/,Z=new Set(ce),Qe=new Set(["get","head"]),de="application/x-www-form-urlencoded",le="multipart/form-data";function et(e){return e?F.test(e)||be.test(e)||We.test(e)||Xe.test(e)||Ze.test(e)?!0:/^[0-9a-f]{16,}$/i.test(e):!1}function Q(e){let t=e.split("/"),r=[],n=new Set;return{template:t.map((s,a)=>{if(!et(s))return s;let i=t[a-1],c=i?`${$(i,1)}Id`:"id",p=1;for(;n.has(c);)p+=1,c=i?`${$(i,1)}Id${p}`:`id${p}`;return n.add(c),r.push({name:c,value:s}),`{${c}}`}).join("/")||"/",params:r}}function A(e){if(e===null)return{type:"null"};if(Array.isArray(e)){if(e.length===0)return{type:"array"};let t=e.slice(0,20).map(A);return{type:"array",items:x(t)}}switch(typeof e){case"string":{let t={type:"string"};return H(t,z(e)),t}case"boolean":return{type:"boolean"};case"number":return Number.isInteger(e)?{type:"integer"}:{type:"number"};case"object":{let t=Object.entries(e);if(t.length>0&&(t.every(([a])=>F.test(a))||t.every(([a])=>be.test(a))))return{type:"object",additionalProperties:x(t.map(([,a])=>A(a)))};let r={},n=[];for(let[s,a]of t)r[s]=A(a),n.push(s);let o={type:"object",properties:r};return n.length>0&&(o.required=n),o}default:return{}}}function x(e){if(e.length===0)return{};let[t,...r]=e,n=t;for(let o of r)n=V(n,o);return n}function he(e){return Object.keys(e).length===0}function k(e){return e.additionalProperties?"map":e.type==="object"?"object":e.type==="array"?"array":"scalar"}function X(e){return e.oneOf?e.oneOf.flatMap(X):Array.isArray(e.type)?e.type.map(t=>{if(t==="object"){let n={type:"object"};return e.properties&&(n.properties=e.properties),e.required&&(n.required=e.required),e.additionalProperties&&(n.additionalProperties=e.additionalProperties),n}if(t==="array")return e.items?{type:"array",items:e.items}:{type:"array"};let r={type:t};return t==="string"&&U(e,r),r}):[e]}var tt=.5,rt=3;function we(e,t){let r=Object.keys(e.properties??{}),n=Object.keys(t.properties??{});if(r.length===0||n.length===0)return 1;let o=new Set(n),s=r.filter(a=>o.has(a)).length;return s/(r.length+n.length-s)}function nt(e,t){let r=k(e);if(r!==k(t))return!1;switch(r){case"scalar":return e.type===t.type||e.type==="integer"&&t.type==="number"||e.type==="number"&&t.type==="integer";case"object":return we(e,t)>=tt;default:return!0}}function ve(e,t){switch(k(e)){case"scalar":{if(e.type!==t.type)return{type:"number"};if(e.type==="string"){let r=C(L(e),L(t));if(r){let n={type:"string"};return H(n,r),n}}return e}case"map":return{type:"object",additionalProperties:V(e.additionalProperties??{},t.additionalProperties??{})};case"object":{let r={...e.properties??{}};for(let[a,i]of Object.entries(t.properties??{}))r[a]=r[a]?V(r[a],i):i;let n=new Set(t.required??[]),o=(e.required??[]).filter(a=>n.has(a)),s={type:"object",properties:r};return o.length>0&&(s.required=o),s}case"array":{if(!e.items||!t.items){let r=e.items??t.items;return r?{type:"array",items:r}:{type:"array"}}return{type:"array",items:V(e.items,t.items)}}}}function ot(e){let t=[...e],r=()=>t.filter(n=>k(n)==="object").length;for(;r()>rt;){let n=-1,o=-1,s=-1;for(let a=0;a<t.length;a++)if(k(t[a])==="object")for(let i=a+1;i<t.length;i++){if(k(t[i])!=="object")continue;let c=we(t[a],t[i]);c>s&&(s=c,n=a,o=i)}t[n]=ve(t[n],t[o]),t.splice(o,1)}return t}var st=["boolean","integer","number","string","null"];function it(e){if(e.length===1)return e[0];let t=[],r=new Set,n;for(let i of e)k(i)==="scalar"&&typeof i.type=="string"?(r.add(i.type),i.type==="string"&&(n=C(n,L(i)))):t.push(i);let o=st.filter(i=>r.has(i)),s=i=>{let c={type:i};return(typeof i=="string"?i==="string":i.includes("string"))&&n&&H(c,n),c};if(t.length===0)return o.length===1?s(o[0]):s(o);if(t.length===1&&o.length===1&&o[0]==="null"&&typeof t[0].type=="string")return{...t[0],type:[t[0].type,"null"]};let a=[...t];return o.length===1?a.push(s(o[0])):o.length>1&&a.push(s(o)),{oneOf:a}}function V(e,t){if(he(e)||he(t))return{};let r=X(e);for(let n of X(t)){let o=r.findIndex(s=>nt(s,n));o===-1?r.push(n):r[o]=ve(r[o],n)}return it(ot(r))}function at(e){if(!e)return;let t=e.trim();if(!(!t.startsWith("{")&&!t.startsWith("[")))try{return JSON.parse(t)}catch{return}}function ct(e,t){let r=t?.match(/boundary="?([^";,]+)"?/i)?.[1];if(!r)return;let n={};for(let o of e.split(`--${r}`)){let s=o.match(/^\r?\n([\s\S]*?)\r?\n\r?\n([\s\S]*)\r?\n$/);if(!s)continue;let[,a,i]=s,c=a.match(/\bname="([^"]*)"/i)?.[1];c!==void 0&&(n[c]=/\bfilename="/i.test(a)?{type:"string",format:"binary"}:A(i))}if(Object.keys(n).length!==0)return{type:"object",properties:n,required:Object.keys(n)}}function ge(e){let t=_(e.contentType);if(e.bodyJson!==void 0)return{mime:ue(t)?t:"application/json",schema:A(e.bodyJson)};if(t===de&&e.bodyText){let n={};for(let[o,s]of new URLSearchParams(e.bodyText))n[o]=s;return Object.keys(n).length===0?void 0:{mime:de,schema:A(n)}}if(t===le&&e.bodyText){let n=ct(e.bodyText,e.contentType);return n?{mime:le,schema:n}:void 0}let r=at(e.bodyText);if(r!==void 0)return{mime:"application/json",schema:A(r)}}function ye(e,t,r){let n=e.get(t);e.set(t,n?x([n,r]):r)}async function Oe(e){let t=await N(e.trafficPath);if(t.length===0)throw new Error("No traffic files found in the provided traffic path.");let r=D(e.server),n=new Map,o=new Set,s=0,a=c=>{let p=c.request.method.toLowerCase();if(!Z.has(p))return;let f=c.request.path||"/";if(r){let u=B(c.request,r);if(u===void 0)return;f=u}else c.request.host&&!fe(c.request.host)&&o.add(`${c.request.protocol}//${c.request.host}`);let{template:l,params:m}=Q(q(f)),w=`${p} ${l}`,d=n.get(w);d||(d={method:p,template:l,pathParams:new Map,queryParams:new Map,requestBodies:new Map,responses:new Map},n.set(w,d));for(let{name:u,value:h}of m){let g=d.pathParams.get(u);d.pathParams.set(u,{numeric:(g?.numeric??!0)&&F.test(h),observations:C(g?.observations,z(h))})}for(let u of new Set(c.request.query.keys())){let h=c.request.query.getAll(u),g=d.queryParams.get(u),v=h.length>0&&h.every(O=>F.test(O)),S=g?.observations;for(let O of h)S=C(S,z(O));d.queryParams.set(u,{numeric:(g?.numeric??!0)&&v,observations:S})}if(!Qe.has(p)){let u=ge(c.request);u&&ye(d.requestBodies,u.mime,u.schema)}if(c.response&&c.response.status>=100){let u=String(c.response.status),h=d.responses.get(u);h||(h={bodies:new Map},d.responses.set(u,h)),h.statusText??=c.response.statusText||void 0;let g=ge(c.response);g&&ye(h.bodies,g.mime,g.schema)}};for(let c of t){let p=await G(c,e.format);if(!p){y.warn(`Skipping traffic file with unrecognized format: ${c}
7
+ import{a as G}from"./VGDBAMVB.js";import{c as I,d as N,e as fe,h as q,j as _,k as ue,v as D,w as B}from"./BVLQXPFR.js";import{a as ce,c as pe}from"./ZI2AMSO7.js";import{b as ae}from"./Y6SAZFRX.js";import{B as oe,C as P,O as y,c as b,ca as se,ia as ie,l as $}from"./ODUYC4TH.js";import"./NEWT5A6S.js";import"./RFWIIJFG.js";import{mkdir as Bt,writeFile as zt}from"node:fs/promises";import Ht from"node:path";import*as Ce from"node:process";var Ve=/^[a-zA-Z][a-zA-Z0-9]*(?:[_\-.][a-zA-Z0-9]+)*$/,Fe=/^[0-9a-f-]{8,}$/i,Ye=[["uuid",/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i],["date-time",/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/],["date",/^\d{4}-\d{2}-\d{2}$/],["email",/^[^\s@]+@[^\s@]+\.[^\s@]+$/],["uri",/^https?:\/\/\S+$/],["ipv4",/^(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)$/]],J=new WeakMap;function z(e){return{formats:Ye.filter(([,t])=>t.test(e)).map(([t])=>t),values:[e],count:1,overflow:!1}}function C(e,t){if(!e)return t;if(!t)return e;let r={formats:e.formats.filter(n=>t.formats.includes(n)),values:[],count:e.count+t.count,overflow:e.overflow||t.overflow};if(!r.overflow){let n=[...e.values];for(let o of t.values)n.includes(o)||n.push(o);n.length>10?r.overflow=!0:r.values=n}return r}function H(e,t){J.set(e,t)}function L(e){return J.get(e)}function U(e,t){let r=J.get(e);r&&J.set(t,r)}function Ke(e){return e.length<=30&&!Fe.test(e)&&Ve.test(e)}function W(e,t){return e.formats.length>0?{format:e.formats[0]}:t&&!e.overflow&&e.count>=4&&e.values.length>0&&e.values.length<=5&&e.values.length*2<=e.count&&e.values.every(Ke)?{enum:[...e.values].sort()}:{}}function R(e){let t=J.get(e);if(t){let r=typeof e.type=="string"?[e.type]:e.type??[];r.includes("string")&&Object.assign(e,W(t,r.length===1))}for(let r of Object.values(e.properties??{}))R(r);e.additionalProperties&&R(e.additionalProperties),e.items&&R(e.items);for(let r of e.oneOf??[])R(r)}function me(e){for(let t of Object.values(e.paths))for(let r of Object.values(t)){for(let n of Object.values(r.requestBody?.content??{}))R(n.schema);for(let n of Object.values(r.responses))for(let o of Object.values(n.content??{}))R(o.schema)}for(let t of Object.values(e.components?.schemas??{}))R(t);return e}var be=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,F=/^\d+$/,We=/^[0-9a-hjkmnp-tv-z]{26}$/i,Xe=/^[a-z][a-z0-9]*_(?=[0-9a-z]*\d)[0-9a-z]{10,}$/i,Ze=/^[a-z](?=[a-z0-9]*\d)[a-z0-9]{23,24}$/,Z=new Set(ce),Qe=new Set(["get","head"]),de="application/x-www-form-urlencoded",le="multipart/form-data";function et(e){return e?F.test(e)||be.test(e)||We.test(e)||Xe.test(e)||Ze.test(e)?!0:/^[0-9a-f]{16,}$/i.test(e):!1}function Q(e){let t=e.split("/"),r=[],n=new Set;return{template:t.map((s,a)=>{if(!et(s))return s;let i=t[a-1],c=i?`${$(i,1)}Id`:"id",p=1;for(;n.has(c);)p+=1,c=i?`${$(i,1)}Id${p}`:`id${p}`;return n.add(c),r.push({name:c,value:s}),`{${c}}`}).join("/")||"/",params:r}}function A(e){if(e===null)return{type:"null"};if(Array.isArray(e)){if(e.length===0)return{type:"array"};let t=e.slice(0,20).map(A);return{type:"array",items:x(t)}}switch(typeof e){case"string":{let t={type:"string"};return H(t,z(e)),t}case"boolean":return{type:"boolean"};case"number":return Number.isInteger(e)?{type:"integer"}:{type:"number"};case"object":{let t=Object.entries(e);if(t.length>0&&(t.every(([a])=>F.test(a))||t.every(([a])=>be.test(a))))return{type:"object",additionalProperties:x(t.map(([,a])=>A(a)))};let r={},n=[];for(let[s,a]of t)r[s]=A(a),n.push(s);let o={type:"object",properties:r};return n.length>0&&(o.required=n),o}default:return{}}}function x(e){if(e.length===0)return{};let[t,...r]=e,n=t;for(let o of r)n=V(n,o);return n}function he(e){return Object.keys(e).length===0}function k(e){return e.additionalProperties?"map":e.type==="object"?"object":e.type==="array"?"array":"scalar"}function X(e){return e.oneOf?e.oneOf.flatMap(X):Array.isArray(e.type)?e.type.map(t=>{if(t==="object"){let n={type:"object"};return e.properties&&(n.properties=e.properties),e.required&&(n.required=e.required),e.additionalProperties&&(n.additionalProperties=e.additionalProperties),n}if(t==="array")return e.items?{type:"array",items:e.items}:{type:"array"};let r={type:t};return t==="string"&&U(e,r),r}):[e]}var tt=.5,rt=3;function we(e,t){let r=Object.keys(e.properties??{}),n=Object.keys(t.properties??{});if(r.length===0||n.length===0)return 1;let o=new Set(n),s=r.filter(a=>o.has(a)).length;return s/(r.length+n.length-s)}function nt(e,t){let r=k(e);if(r!==k(t))return!1;switch(r){case"scalar":return e.type===t.type||e.type==="integer"&&t.type==="number"||e.type==="number"&&t.type==="integer";case"object":return we(e,t)>=tt;default:return!0}}function ve(e,t){switch(k(e)){case"scalar":{if(e.type!==t.type)return{type:"number"};if(e.type==="string"){let r=C(L(e),L(t));if(r){let n={type:"string"};return H(n,r),n}}return e}case"map":return{type:"object",additionalProperties:V(e.additionalProperties??{},t.additionalProperties??{})};case"object":{let r={...e.properties??{}};for(let[a,i]of Object.entries(t.properties??{}))r[a]=r[a]?V(r[a],i):i;let n=new Set(t.required??[]),o=(e.required??[]).filter(a=>n.has(a)),s={type:"object",properties:r};return o.length>0&&(s.required=o),s}case"array":{if(!e.items||!t.items){let r=e.items??t.items;return r?{type:"array",items:r}:{type:"array"}}return{type:"array",items:V(e.items,t.items)}}}}function ot(e){let t=[...e],r=()=>t.filter(n=>k(n)==="object").length;for(;r()>rt;){let n=-1,o=-1,s=-1;for(let a=0;a<t.length;a++)if(k(t[a])==="object")for(let i=a+1;i<t.length;i++){if(k(t[i])!=="object")continue;let c=we(t[a],t[i]);c>s&&(s=c,n=a,o=i)}t[n]=ve(t[n],t[o]),t.splice(o,1)}return t}var st=["boolean","integer","number","string","null"];function it(e){if(e.length===1)return e[0];let t=[],r=new Set,n;for(let i of e)k(i)==="scalar"&&typeof i.type=="string"?(r.add(i.type),i.type==="string"&&(n=C(n,L(i)))):t.push(i);let o=st.filter(i=>r.has(i)),s=i=>{let c={type:i};return(typeof i=="string"?i==="string":i.includes("string"))&&n&&H(c,n),c};if(t.length===0)return o.length===1?s(o[0]):s(o);if(t.length===1&&o.length===1&&o[0]==="null"&&typeof t[0].type=="string")return{...t[0],type:[t[0].type,"null"]};let a=[...t];return o.length===1?a.push(s(o[0])):o.length>1&&a.push(s(o)),{oneOf:a}}function V(e,t){if(he(e)||he(t))return{};let r=X(e);for(let n of X(t)){let o=r.findIndex(s=>nt(s,n));o===-1?r.push(n):r[o]=ve(r[o],n)}return it(ot(r))}function at(e){if(!e)return;let t=e.trim();if(!(!t.startsWith("{")&&!t.startsWith("[")))try{return JSON.parse(t)}catch{return}}function ct(e,t){let r=t?.match(/boundary="?([^";,]+)"?/i)?.[1];if(!r)return;let n={};for(let o of e.split(`--${r}`)){let s=o.match(/^\r?\n([\s\S]*?)\r?\n\r?\n([\s\S]*)\r?\n$/);if(!s)continue;let[,a,i]=s,c=a.match(/\bname="([^"]*)"/i)?.[1];c!==void 0&&(n[c]=/\bfilename="/i.test(a)?{type:"string",format:"binary"}:A(i))}if(Object.keys(n).length!==0)return{type:"object",properties:n,required:Object.keys(n)}}function ge(e){let t=_(e.contentType);if(e.bodyJson!==void 0)return{mime:ue(t)?t:"application/json",schema:A(e.bodyJson)};if(t===de&&e.bodyText){let n={};for(let[o,s]of new URLSearchParams(e.bodyText))n[o]=s;return Object.keys(n).length===0?void 0:{mime:de,schema:A(n)}}if(t===le&&e.bodyText){let n=ct(e.bodyText,e.contentType);return n?{mime:le,schema:n}:void 0}let r=at(e.bodyText);if(r!==void 0)return{mime:"application/json",schema:A(r)}}function ye(e,t,r){let n=e.get(t);e.set(t,n?x([n,r]):r)}async function Oe(e){let t=await N(e.trafficPath);if(t.length===0)throw new Error("No traffic files found in the provided traffic path.");let r=D(e.server),n=new Map,o=new Set,s=0,a=c=>{let p=c.request.method.toLowerCase();if(!Z.has(p))return;let f=c.request.path||"/";if(r){let u=B(c.request,r);if(u===void 0)return;f=u}else c.request.host&&!fe(c.request.host)&&o.add(`${c.request.protocol}//${c.request.host}`);let{template:l,params:m}=Q(q(f)),w=`${p} ${l}`,d=n.get(w);d||(d={method:p,template:l,pathParams:new Map,queryParams:new Map,requestBodies:new Map,responses:new Map},n.set(w,d));for(let{name:u,value:h}of m){let g=d.pathParams.get(u);d.pathParams.set(u,{numeric:(g?.numeric??!0)&&F.test(h),observations:C(g?.observations,z(h))})}for(let u of new Set(c.request.query.keys())){let h=c.request.query.getAll(u),g=d.queryParams.get(u),v=h.length>0&&h.every(O=>F.test(O)),S=g?.observations;for(let O of h)S=C(S,z(O));d.queryParams.set(u,{numeric:(g?.numeric??!0)&&v,observations:S})}if(!Qe.has(p)){let u=ge(c.request);u&&ye(d.requestBodies,u.mime,u.schema)}if(c.response&&c.response.status>=100){let u=String(c.response.status),h=d.responses.get(u);h||(h={bodies:new Map},d.responses.set(u,h)),h.statusText??=c.response.statusText||void 0;let g=ge(c.response);g&&ye(h.bodies,g.mime,g.schema)}};for(let c of t){let p=await G(c,e.format);if(!p){y.warn(`Skipping traffic file with unrecognized format: ${c}
8
8
  `);continue}s+=1;for await(let f of p.parse(c))a(f)}if(s===0)throw new Error("No supported traffic files found to generate an OpenAPI description from.");if(n.size===0)throw new Error(r?`No HTTP exchanges in the traffic matched the server "${r}".`:"No HTTP exchanges were observed in the traffic. Cannot generate an OpenAPI description.");let i=r?[r]:Array.from(o).sort();return pt(n,e.title??"Generated API",i)}function $e(e){return Object.values(e.paths).reduce((t,r)=>t+Object.keys(r).length,0)}function Se(e,t){if(e.numeric)return{type:"integer"};let r={type:"string"};return e.observations&&Object.assign(r,W(e.observations,t)),r}function pt(e,t,r){let n={};for(let o of e.values()){let s=n[o.template]??={},a=[...Array.from(o.pathParams).map(([c,p])=>({name:c,in:"path",required:!0,schema:Se(p,!1)})),...Array.from(o.queryParams).map(([c,p])=>({name:c,in:"query",required:!1,schema:Se(p,!0)}))],i={operationId:ft(o.method,o.template),responses:{}};if(a.length>0&&(i.parameters=a),o.requestBodies.size>0){let c={};for(let[p,f]of o.requestBodies)c[p]={schema:f};i.requestBody={content:c}}if(o.responses.size===0)i.responses.default={description:"Observed response"};else for(let[c,p]of o.responses){let f={description:p.statusText||"Observed response"};if(p.bodies.size>0){let l={};for(let[m,w]of p.bodies)l[m]={schema:w};f.content=l}i.responses[c]=f}s[o.method]=i}return{openapi:"3.2.0",info:{title:t,version:"1.0.0"},...r.length>0?{servers:r.map(o=>({url:o}))}:{},paths:n}}function ft(e,t){let r=t.split("/").filter(Boolean).map(n=>n.replace(/[{}]/g,"")).join("-");return`${e}-${r||"root"}`}function Y(e,t){return`${e.toUpperCase()} ${t}`}function Pe(e,t){let r;if(e.bodyJson!==void 0)try{r=JSON.stringify(e.bodyJson)}catch{r=void 0}if(r??=e.bodyText,!r)return;let n=r.trim();if(n)return n.length>t?`${n.slice(0,t)}\u2026[truncated]`:n}function Te(e){if(!e)return"";let t=e.bodyJson;return t===void 0?e.bodyText?_(e.contentType)||"text":"":t===null?"null":Array.isArray(t)?`array<${t.length>0?Ee(t[0]):""}>`:Ee(t)}function Ee(e){return b(e)?Object.keys(e).sort().join(","):e===null?"null":typeof e}async function Re(e){let t=e.perGroup??2,r=e.perOperation??4,n=e.maxBodyChars??2e3,o=D(e.server),s=await N(e.trafficPath),a=new Map;for(let c of s){let p=await G(c,e.format);if(p)for await(let f of p.parse(c)){let l=f.request.method.toUpperCase();if(!Z.has(l.toLowerCase()))continue;let m=f.request.path||"/";if(o){let ne=B(f.request,o);if(ne===void 0)continue;m=ne}let w=q(m),{template:d}=Q(w),u=f.response&&f.response.status>=100?f.response:void 0,h=u?.status,g=`${Te(f.request)}\u2192${Te(u)}`,v=a.get(Y(l,d));v||(v=new Map,a.set(Y(l,d),v));let S=`${h??""} ${g}`,O=v.get(S);O||(O=[],v.set(S,O)),!(O.length>=t)&&O.push({method:l,path:w,query:f.request.query.toString(),status:h,requestContentType:f.request.contentType,requestBody:Pe(f.request,n),responseContentType:u?.contentType,responseBody:u?Pe(u,n):void 0})}}let i=new Map;for(let[c,p]of a){let f=[];for(let l=0;l<t&&f.length<r;l++)for(let m of p.values()){if(f.length>=r)break;m[l]&&f.push(m[l])}i.set(c,f)}return i}var ut=`You are an expert API designer. You are given one operation from an OpenAPI 3.2 description that was inferred mechanically from recorded HTTP traffic, the component schemas it references, and a sample of the real recorded HTTP exchanges for that operation. The inferred description is only a hypothesis: types are coarse, every observed property is marked required, and descriptions are missing. Alternative body shapes observed in the traffic appear as "oneOf" variants or type unions. Common string formats (uuid, date-time, date, email, uri, ipv4) and small closed enums are detected conservatively from the observed values.
9
9
 
10
10
  Refine the operation into the most accurate OpenAPI 3.2 definition you can justify from the evidence, while staying conservative:
@@ -4,4 +4,4 @@ import { dirname as __pathDirname } from 'node:path';
4
4
  const require = __createRequire(import.meta.url);
5
5
  var __filename = __fileURLToPath(import.meta.url);
6
6
  var __dirname = __pathDirname(__filename);
7
- import{a,b,c,d,e,f,g}from"./UJCMWVNQ.js";import"./O6PRCLSV.js";import"./32XCOMOR.js";import"./CN6PFMVJ.js";import"./NEWT5A6S.js";import"./RFWIIJFG.js";export{d as RESET_ESCAPE_CODE,c as calculateTotals,f as conditionallyMaskSecrets,b as generate,e as maskSecrets,a as parseRuntimeExpression,g as run};
7
+ import{a,b,c,d,e,f,g}from"./ZVSZFNKL.js";import"./O6PRCLSV.js";import"./32XCOMOR.js";import"./ODUYC4TH.js";import"./NEWT5A6S.js";import"./RFWIIJFG.js";export{d as RESET_ESCAPE_CODE,c as calculateTotals,f as conditionallyMaskSecrets,b as generate,e as maskSecrets,a as parseRuntimeExpression,g as run};
@@ -4,7 +4,7 @@ import { dirname as __pathDirname } from 'node:path';
4
4
  const require = __createRequire(import.meta.url);
5
5
  var __filename = __fileURLToPath(import.meta.url);
6
6
  var __dirname = __pathDirname(__filename);
7
- import{c as p}from"./P26PQ2RU.js";import{a as O}from"./RS5PUOTT.js";import{a as R}from"./SSAJRVQ6.js";import{a as I}from"./BXI4SF2U.js";import{G as T,I as w,O as a}from"./CN6PFMVJ.js";import{e as C}from"./RFWIIJFG.js";import{Buffer as P}from"node:buffer";import y from"node:crypto";import{mkdirSync as j,existsSync as F,writeFileSync as q,readFileSync as z,rmSync as M}from"node:fs";import{homedir as H}from"node:os";import B from"node:path";var l={us:"https://app.cloud.redocly.com",eu:"https://app.cloud.eu.redocly.com"};function G(){return process.env.REDOCLY_DOMAIN||l.us}var U=D((o,e)=>{try{let t=e||o?.resolvedConfig.residency;return W(t)?l[t]:t?new URL(t).origin:o?.resolvedConfig.scorecard?.fromProjectUrl?new URL(o.resolvedConfig.scorecard.fromProjectUrl).origin:l.us}catch{throw new f}});function x(o){try{U(void 0,o)}catch{return!1}return!0}function D(o){return(...e)=>{let t=o(...e);if(!t.startsWith("https://"))throw new f;return t}}var f=class extends Error{constructor(){super("Invalid Reunite URL")}};function W(o){return typeof o=="string"&&o in l}import*as k from"node:child_process";var g=C(I(),1);var N=C(O(),1);function b(){return process.env.HTTPS_PROXY||process.env.HTTP_PROXY||process.env.http_proxy||process.env.https_proxy}function S(o){let e=process.env.NO_PROXY||process.env.no_proxy;if(!e)return!1;let t=e.split(",").map(s=>s.trim().toLowerCase()).filter(Boolean);if(t.length===0)return!1;let r;try{r=new URL(o).hostname.toLowerCase()}catch{return!1}return t.some(s=>!!(s==="*"||r===s||s.startsWith(".")&&r.endsWith(s)||!s.startsWith(".")&&r.endsWith("."+s)))}var _=async(o,{timeout:e,...t}={})=>{let r=b(),s=r&&!S(o),n,i=e?{connect:{timeout:e}}:{};return s?n=new g.ProxyAgent({uri:r,...i}):e&&(n=new g.Agent(i)),await fetch(o,{signal:e?AbortSignal.timeout(e):void 0,...t,dispatcher:n})};var c=class extends Error{constructor(t,r){super(t);this.status=r}status},h=class{constructor(e){this.command=e}command;sunsetWarnings=[];async request(e,t){let r={...t.headers,"user-agent":`redocly-cli/${R} ${this.command}`};try{let s=await _(e,{...t,headers:r});return this.collectSunsetWarning(s),s}catch(s){let n="Failed to fetch.";throw s.cause&&(n+=` Caused by ${s.cause.message||s.cause.name}.`),(s.code||s.cause?.code)&&(n+=` Code: ${s.code||s.cause?.code}`),new Error(n)}}collectSunsetWarning(e){let t=this.getSunsetDate(e);if(!t)return;let r=new Date(t);t>Date.now()?this.sunsetWarnings.push({sunsetDate:r,isSunsetExpired:!1}):this.sunsetWarnings.push({sunsetDate:r,isSunsetExpired:!0})}getSunsetDate(e){let{headers:t}=e;if(!t)return;let r=t.get("sunset")||t.get("Sunset");if(r)return Date.parse(r)}},v=class{constructor(e,t,r){this.client=e;this.domain=t;this.apiKey=r}client;domain;apiKey;async getParsedResponse(e){let t=await e.json();if(e.ok)return t;throw new c(`${t.title||e.statusText||"Unknown error"}.`,e.status)}async getDefaultBranch(e,t){try{let r=await this.client.request(`${this.domain}/api/orgs/${e}/projects/${t}/source`,{timeout:p,method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`}});return(await this.getParsedResponse(r)).branchName}catch(r){let s=`Failed to fetch default branch. ${r.message}`;throw r instanceof c?new c(s,r.status):new Error(s)}}async upsert(e,t,r){try{let s=await this.client.request(`${this.domain}/api/orgs/${e}/projects/${t}/remotes`,{timeout:p,method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`},body:JSON.stringify({mountPath:r.mountPath,mountBranchName:r.mountBranchName,type:"CICD",autoMerge:!0})});return await this.getParsedResponse(s)}catch(s){let n=`Failed to upsert remote. ${s.message}`;throw s instanceof c?new c(n,s.status):new Error(n)}}async push(e,t,r,s){let n=new globalThis.FormData;n.append("remoteId",r.remoteId),n.append("commit[message]",r.commit.message),n.append("commit[author][name]",r.commit.author.name),n.append("commit[author][email]",r.commit.author.email),n.append("commit[branchName]",r.commit.branchName),r.commit.url&&n.append("commit[url]",r.commit.url),r.commit.namespace&&n.append("commit[namespaceId]",r.commit.namespace),r.commit.sha&&n.append("commit[sha]",r.commit.sha),r.commit.repository&&n.append("commit[repositoryId]",r.commit.repository),r.commit.createdAt&&n.append("commit[createdAt]",r.commit.createdAt);for(let i of s){let u=Buffer.isBuffer(i.stream)?new Blob([i.stream]):new Blob([await L(i.stream)]);n.append(`files[${i.path}]`,u,i.path)}r.isMainBranch&&n.append("isMainBranch","true");try{let i=await this.client.request(`${this.domain}/api/orgs/${e}/projects/${t}/pushes`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:n});return await this.getParsedResponse(i)}catch(i){let u=`Failed to push. ${i.message}`;throw i instanceof c?new c(u,i.status):new Error(u)}}async getRemotesList({organizationId:e,projectId:t,mountPath:r}){try{let s=await this.client.request(`${this.domain}/api/orgs/${e}/projects/${t}/remotes?filter=mountPath:/${r}/`,{timeout:p,method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`}});return await this.getParsedResponse(s)}catch(s){let n=`Failed to get remote list. ${s.message}`;throw s instanceof c?new c(n,s.status):new Error(n)}}async getPush({organizationId:e,projectId:t,pushId:r}){try{let s=await this.client.request(`${this.domain}/api/orgs/${e}/projects/${t}/pushes/${r}`,{timeout:p,method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`}});return await this.getParsedResponse(s)}catch(s){let n=`Failed to get push status. ${s.message}`;throw s instanceof c?new c(n,s.status):new Error(n)}}},$=class{apiClient;command;remotes;constructor({domain:e,apiKey:t,command:r}){this.command=r,this.apiClient=new h(this.command),this.remotes=new v(this.apiClient,e,t)}reportSunsetWarnings(){let e=this.apiClient.sunsetWarnings;if(e.length){let[{isSunsetExpired:t,sunsetDate:r}]=e.sort((n,i)=>n.isSunsetExpired!==i.isSunsetExpired?n.isSunsetExpired?-1:1:n.sunsetDate>i.sunsetDate?1:-1),s='Update to the latest version by running "npm install @redocly/cli@latest".';t?a.error(`The "${this.command}" command is not compatible with your version of Redocly CLI. ${s}
7
+ import{c as p}from"./P26PQ2RU.js";import{a as O}from"./RS5PUOTT.js";import{a as R}from"./Q5R5AHEE.js";import{a as I}from"./BXI4SF2U.js";import{G as T,I as w,O as a}from"./ODUYC4TH.js";import{e as C}from"./RFWIIJFG.js";import{Buffer as P}from"node:buffer";import y from"node:crypto";import{mkdirSync as j,existsSync as F,writeFileSync as q,readFileSync as z,rmSync as M}from"node:fs";import{homedir as H}from"node:os";import B from"node:path";var l={us:"https://app.cloud.redocly.com",eu:"https://app.cloud.eu.redocly.com"};function G(){return process.env.REDOCLY_DOMAIN||l.us}var U=D((o,e)=>{try{let t=e||o?.resolvedConfig.residency;return W(t)?l[t]:t?new URL(t).origin:o?.resolvedConfig.scorecard?.fromProjectUrl?new URL(o.resolvedConfig.scorecard.fromProjectUrl).origin:l.us}catch{throw new f}});function x(o){try{U(void 0,o)}catch{return!1}return!0}function D(o){return(...e)=>{let t=o(...e);if(!t.startsWith("https://"))throw new f;return t}}var f=class extends Error{constructor(){super("Invalid Reunite URL")}};function W(o){return typeof o=="string"&&o in l}import*as k from"node:child_process";var g=C(I(),1);var N=C(O(),1);function b(){return process.env.HTTPS_PROXY||process.env.HTTP_PROXY||process.env.http_proxy||process.env.https_proxy}function S(o){let e=process.env.NO_PROXY||process.env.no_proxy;if(!e)return!1;let t=e.split(",").map(s=>s.trim().toLowerCase()).filter(Boolean);if(t.length===0)return!1;let r;try{r=new URL(o).hostname.toLowerCase()}catch{return!1}return t.some(s=>!!(s==="*"||r===s||s.startsWith(".")&&r.endsWith(s)||!s.startsWith(".")&&r.endsWith("."+s)))}var _=async(o,{timeout:e,...t}={})=>{let r=b(),s=r&&!S(o),n,i=e?{connect:{timeout:e}}:{};return s?n=new g.ProxyAgent({uri:r,...i}):e&&(n=new g.Agent(i)),await fetch(o,{signal:e?AbortSignal.timeout(e):void 0,...t,dispatcher:n})};var c=class extends Error{constructor(t,r){super(t);this.status=r}status},h=class{constructor(e){this.command=e}command;sunsetWarnings=[];async request(e,t){let r={...t.headers,"user-agent":`redocly-cli/${R} ${this.command}`};try{let s=await _(e,{...t,headers:r});return this.collectSunsetWarning(s),s}catch(s){let n="Failed to fetch.";throw s.cause&&(n+=` Caused by ${s.cause.message||s.cause.name}.`),(s.code||s.cause?.code)&&(n+=` Code: ${s.code||s.cause?.code}`),new Error(n)}}collectSunsetWarning(e){let t=this.getSunsetDate(e);if(!t)return;let r=new Date(t);t>Date.now()?this.sunsetWarnings.push({sunsetDate:r,isSunsetExpired:!1}):this.sunsetWarnings.push({sunsetDate:r,isSunsetExpired:!0})}getSunsetDate(e){let{headers:t}=e;if(!t)return;let r=t.get("sunset")||t.get("Sunset");if(r)return Date.parse(r)}},v=class{constructor(e,t,r){this.client=e;this.domain=t;this.apiKey=r}client;domain;apiKey;async getParsedResponse(e){let t=await e.json();if(e.ok)return t;throw new c(`${t.title||e.statusText||"Unknown error"}.`,e.status)}async getDefaultBranch(e,t){try{let r=await this.client.request(`${this.domain}/api/orgs/${e}/projects/${t}/source`,{timeout:p,method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`}});return(await this.getParsedResponse(r)).branchName}catch(r){let s=`Failed to fetch default branch. ${r.message}`;throw r instanceof c?new c(s,r.status):new Error(s)}}async upsert(e,t,r){try{let s=await this.client.request(`${this.domain}/api/orgs/${e}/projects/${t}/remotes`,{timeout:p,method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`},body:JSON.stringify({mountPath:r.mountPath,mountBranchName:r.mountBranchName,type:"CICD",autoMerge:!0})});return await this.getParsedResponse(s)}catch(s){let n=`Failed to upsert remote. ${s.message}`;throw s instanceof c?new c(n,s.status):new Error(n)}}async push(e,t,r,s){let n=new globalThis.FormData;n.append("remoteId",r.remoteId),n.append("commit[message]",r.commit.message),n.append("commit[author][name]",r.commit.author.name),n.append("commit[author][email]",r.commit.author.email),n.append("commit[branchName]",r.commit.branchName),r.commit.url&&n.append("commit[url]",r.commit.url),r.commit.namespace&&n.append("commit[namespaceId]",r.commit.namespace),r.commit.sha&&n.append("commit[sha]",r.commit.sha),r.commit.repository&&n.append("commit[repositoryId]",r.commit.repository),r.commit.createdAt&&n.append("commit[createdAt]",r.commit.createdAt);for(let i of s){let u=Buffer.isBuffer(i.stream)?new Blob([i.stream]):new Blob([await L(i.stream)]);n.append(`files[${i.path}]`,u,i.path)}r.isMainBranch&&n.append("isMainBranch","true");try{let i=await this.client.request(`${this.domain}/api/orgs/${e}/projects/${t}/pushes`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:n});return await this.getParsedResponse(i)}catch(i){let u=`Failed to push. ${i.message}`;throw i instanceof c?new c(u,i.status):new Error(u)}}async getRemotesList({organizationId:e,projectId:t,mountPath:r}){try{let s=await this.client.request(`${this.domain}/api/orgs/${e}/projects/${t}/remotes?filter=mountPath:/${r}/`,{timeout:p,method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`}});return await this.getParsedResponse(s)}catch(s){let n=`Failed to get remote list. ${s.message}`;throw s instanceof c?new c(n,s.status):new Error(n)}}async getPush({organizationId:e,projectId:t,pushId:r}){try{let s=await this.client.request(`${this.domain}/api/orgs/${e}/projects/${t}/pushes/${r}`,{timeout:p,method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`}});return await this.getParsedResponse(s)}catch(s){let n=`Failed to get push status. ${s.message}`;throw s instanceof c?new c(n,s.status):new Error(n)}}},$=class{apiClient;command;remotes;constructor({domain:e,apiKey:t,command:r}){this.command=r,this.apiClient=new h(this.command),this.remotes=new v(this.apiClient,e,t)}reportSunsetWarnings(){let e=this.apiClient.sunsetWarnings;if(e.length){let[{isSunsetExpired:t,sunsetDate:r}]=e.sort((n,i)=>n.isSunsetExpired!==i.isSunsetExpired?n.isSunsetExpired?-1:1:n.sunsetDate>i.sunsetDate?1:-1),s='Update to the latest version by running "npm install @redocly/cli@latest".';t?a.error(`The "${this.command}" command is not compatible with your version of Redocly CLI. ${s}
8
8
 
9
9
  `):a.warn(`The "${this.command}" command will be incompatible with your version of Redocly CLI after ${r.toLocaleString()}. ${s}
10
10