@redocly/cli 2.54.3 → 2.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/THIRD_PARTY_NOTICES +3 -3
- package/lib/chunks/{I44GHHET.js → 3L35HFJG.js} +1 -1
- package/lib/chunks/{LZRNA4HH.js → 3R32Y5ZJ.js} +1 -1
- package/lib/chunks/{SOTTFVAK.js → 5KSMVZSO.js} +1 -1
- package/lib/chunks/{Z2BI77LK.js → 6WNK6ZW5.js} +1 -1
- package/lib/chunks/{UJ6WQ2OD.js → 7BAI3GZ5.js} +1 -1
- package/lib/chunks/{SJCEHWE2.js → 7MISZQY2.js} +1 -1
- package/lib/chunks/{77KV43X2.js → AOFLS3JM.js} +1 -1
- package/lib/chunks/{RAYH3MG6.js → ARIBTVNO.js} +1 -1
- package/lib/chunks/{FDI3NUCB.js → BDCNFVGZ.js} +1 -1
- package/lib/chunks/{LFQ7H446.js → BH4SKQ6M.js} +1 -1
- package/lib/chunks/{ITRAFA2I.js → DOJW7C4M.js} +2 -2
- package/lib/chunks/{GTBZLPVY.js → DSD57XD4.js} +1 -1
- package/lib/chunks/{HITQPK62.js → DXEOF3IX.js} +1 -1
- package/lib/chunks/{3TYRUZAW.js → E2KKD73B.js} +1 -1
- package/lib/chunks/{HYALAA3H.js → EJXJAU3Z.js} +1 -1
- package/lib/chunks/{G66T7F2A.js → EVTLV6L3.js} +1 -1
- package/lib/chunks/{B6JQC3AM.js → FKC3B2RN.js} +1 -1
- package/lib/chunks/FTARAJQN.js +9 -0
- package/lib/chunks/{TH4J5VUW.js → GORWWTSA.js} +1 -1
- package/lib/chunks/{HNVJYHEV.js → HOUAVEH6.js} +1 -1
- package/lib/chunks/{KVPIWPOL.js → ICOYFJR4.js} +1 -1
- package/lib/chunks/{KCRCWPLX.js → ISBVQBNS.js} +1 -1
- package/lib/chunks/{UNBNSCWN.js → JADJJP6R.js} +1 -1
- package/lib/chunks/{OYAP4QAE.js → JDBGRKTP.js} +1 -1
- package/lib/chunks/{DE4ZFTDG.js → LGQZK7NR.js} +1 -1
- package/lib/chunks/{32ZHA42N.js → LPB2X45H.js} +1 -1
- package/lib/chunks/LRUXN6H5.js +59 -0
- package/lib/chunks/{CUB5GMHZ.js → M4FV4I2Z.js} +4 -4
- package/lib/chunks/{DFVJG4OO.js → MGMNYFOR.js} +2 -2
- package/lib/chunks/{NRCWSDXN.js → MWNK3IKD.js} +11 -11
- package/lib/chunks/{OJUJ2R6B.js → N2D5LLBV.js} +1 -1
- package/lib/chunks/{XY2QUSMZ.js → N2FNYVCN.js} +1 -1
- package/lib/chunks/{LWDUZ2W4.js → NHMYQF3F.js} +1 -1
- package/lib/chunks/{GKBR6HC7.js → NPBKCM7B.js} +1 -1
- package/lib/chunks/{PZTYMEH7.js → O64VVDHW.js} +1 -1
- package/lib/chunks/{XZM2ITNF.js → P43DKA2E.js} +1 -1
- package/lib/chunks/{UR72TK6I.js → QKT4AI5U.js} +1 -1
- package/lib/chunks/QXIVVOOR.js +13 -0
- package/lib/chunks/{NRAZJDJM.js → RDLDTF4L.js} +1 -1
- package/lib/chunks/{2FXTKF3U.js → RZ6XOBIA.js} +1 -1
- package/lib/chunks/{HR7ZTPFZ.js → SH75MWAC.js} +1 -1
- package/lib/chunks/{SN3OGJPW.js → TC3EIKUK.js} +1 -1
- package/lib/chunks/TVL6DMBV.js +89 -0
- package/lib/chunks/{BZWFV3MX.js → UNHSYVDZ.js} +1 -1
- package/lib/chunks/{5OBAGRRJ.js → UQHIGGP6.js} +1 -1
- package/lib/chunks/{OA5XCUEZ.js → UTZVN6YA.js} +1 -1
- package/lib/chunks/UVKEIQXW.js +193 -0
- package/lib/chunks/{KPWZVETN.js → VM6OOWSF.js} +1 -1
- package/lib/chunks/{4R5G4SNU.js → WUXDP2A3.js} +1 -1
- package/lib/chunks/{PZLKJXIF.js → XKNG65W6.js} +1 -1
- package/lib/chunks/{OW3COOIS.js → YJ2CV2FV.js} +1 -1
- package/lib/chunks/{BABBSLVN.js → ZHK7GAOT.js} +1 -1
- package/lib/chunks/{KZPCQAG3.js → ZQHPJPJ2.js} +1 -1
- package/lib/eject-assets/generators/cli/docs.ts +1 -1
- package/lib/eject-assets/generators/cli/engine-source.ts +1 -1
- package/lib/eject-assets/generators/cli/index.ts +2 -2
- package/lib/eject-assets/generators/cli/render.ts +1 -1
- package/lib/eject-assets/generators/go/client.ts +1 -1
- package/lib/eject-assets/generators/go/descriptor.ts +1 -1
- package/lib/eject-assets/generators/go/index.ts +2 -2
- package/lib/eject-assets/generators/go/models.ts +1 -1
- package/lib/eject-assets/generators/go/naming.ts +1 -1
- package/lib/eject-assets/generators/go/operations.ts +1 -1
- package/lib/eject-assets/generators/go/pagination.ts +1 -1
- package/lib/eject-assets/generators/go/types.ts +1 -1
- package/lib/eject-assets/generators/mock/faker.ts +1 -1
- package/lib/eject-assets/generators/mock/index.ts +2 -2
- package/lib/eject-assets/generators/mock/render.ts +1 -1
- package/lib/eject-assets/generators/mock/sample.ts +1 -1
- package/lib/eject-assets/generators/mock/values.ts +1 -1
- package/lib/eject-assets/generators/php/client.ts +1 -1
- package/lib/eject-assets/generators/php/descriptor.ts +1 -1
- package/lib/eject-assets/generators/php/index.ts +2 -2
- package/lib/eject-assets/generators/php/models.ts +1 -1
- package/lib/eject-assets/generators/php/naming.ts +1 -1
- package/lib/eject-assets/generators/php/operations.ts +1 -1
- package/lib/eject-assets/generators/php/pagination.ts +1 -1
- package/lib/eject-assets/generators/php/types.ts +1 -1
- package/lib/eject-assets/generators/python/client.ts +1 -1
- package/lib/eject-assets/generators/python/descriptor.ts +1 -1
- package/lib/eject-assets/generators/python/index.ts +2 -2
- package/lib/eject-assets/generators/python/models.ts +1 -1
- package/lib/eject-assets/generators/python/naming.ts +1 -1
- package/lib/eject-assets/generators/python/operations.ts +1 -1
- package/lib/eject-assets/generators/python/pagination.ts +1 -1
- package/lib/eject-assets/generators/python/types.ts +1 -1
- package/lib/eject-assets/generators/swr/index.ts +2 -2
- package/lib/eject-assets/generators/swr/render.ts +1 -1
- package/lib/eject-assets/generators/tanstack-query/index.ts +2 -2
- package/lib/eject-assets/generators/tanstack-query/render.ts +1 -1
- package/lib/eject-assets/generators/transformers/index.ts +2 -2
- package/lib/eject-assets/generators/transformers/render.ts +1 -1
- package/lib/eject-assets/generators/typescript/banner.ts +1 -1
- package/lib/eject-assets/generators/typescript/client.ts +1 -1
- package/lib/eject-assets/generators/typescript/descriptor.ts +1 -1
- package/lib/eject-assets/generators/typescript/index.ts +2 -2
- package/lib/eject-assets/generators/typescript/inline-runtime.ts +1 -1
- package/lib/eject-assets/generators/typescript/operation-signature.ts +1 -1
- package/lib/eject-assets/generators/typescript/operation-types.ts +1 -1
- package/lib/eject-assets/generators/typescript/operations.ts +1 -1
- package/lib/eject-assets/generators/typescript/response-headers.ts +1 -1
- package/lib/eject-assets/generators/typescript/type-guards.ts +1 -1
- package/lib/eject-assets/generators/typescript/types.ts +1 -1
- package/lib/eject-assets/generators/zod/index.ts +2 -2
- package/lib/eject-assets/generators/zod/schemas.ts +1 -1
- package/lib/index.js +124 -124
- package/package.json +1 -1
- package/lib/chunks/BXI4SF2U.js +0 -59
- package/lib/chunks/HPJKQNL7.js +0 -13
- package/lib/chunks/K2PGWUA3.js +0 -9
- package/lib/chunks/L2EEGRZN.js +0 -184
- package/lib/chunks/YOV4L7V6.js +0 -97
package/lib/chunks/HPJKQNL7.js
DELETED
|
@@ -1,13 +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{b as x,c as P,d as h}from"./77KV43X2.js";import{e as y,g as b,m as w,n as $}from"./K2PGWUA3.js";import"./HNVJYHEV.js";import{f as l}from"./CUB5GMHZ.js";import"./BXI4SF2U.js";import{P as g,X as n,l as p}from"./L2EEGRZN.js";import"./NEWT5A6S.js";import"./RFWIIJFG.js";async function C({argv:t,config:o,version:c}){let f=performance.now(),A=Date.now(),{organization:s,project:m,"mount-path":F,verbose:I}=t,d=t.domain||b(),e,i,u=[];try{let r=y();if(e=$(t.files,(a,S)=>{n.warn(`File ${a} is overwritten by ${S}
|
|
8
|
-
`)}),!e.length)return l("push",f,"No files to upload");i=(await w({domain:d,apiKey:r,organization:s,project:m,mountPath:F,files:e,defaultBranch:t["default-branch"],commit:{message:t.message,branchName:t.branch,sha:t["commit-sha"],url:t["commit-url"],createdAt:t["created-at"],namespace:t.namespace,repository:t.repository,author:T(t.author)},version:c,onUploadStart:a=>{n.info(`Uploading to ${a.mountPath} ${e.length} ${p("file",e.length)}:
|
|
9
|
-
`)},onSunsetWarning:a=>u.push(a)})).pushId}catch(r){h("push",u),P("\u2717 File upload failed.",r)}for(let r of e)n.info(g(`\u2713 ${r.name}
|
|
10
|
-
`));return n.info(`
|
|
11
|
-
`),n.info(`Push ID: ${i}
|
|
12
|
-
`),h("push",u),t["wait-for-deployment"]&&(n.info(`
|
|
13
|
-
`),await x({argv:{organization:s,project:m,pushId:i,wait:!0,domain:d,"max-execution-time":t["max-execution-time"],"start-time":A,"continue-on-deploy-failures":t["continue-on-deploy-failures"]},config:o,version:c})),I&&l("push",f,`${p("file",e.length)} uploaded to organization ${s}, project ${m}. Push ID: ${i}.`),{pushId:i}}function T(t){let o=t.match(/^(?<name>.+)\s<(?<email>[^<>]+)>$/);if(!o?.groups)throw new Error('Invalid author format. Use "Author Name <author@email.com>"');return{name:o.groups.name.trim(),email:o.groups.email.trim()}}export{C as handlePush};
|
package/lib/chunks/K2PGWUA3.js
DELETED
|
@@ -1,9 +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 se}from"./BXI4SF2U.js";import{ea as M,j as L,l as $,la as W,na as m,o as j,p as B}from"./L2EEGRZN.js";import{e as ne}from"./RFWIIJFG.js";var S=ne(se(),1);function b(){return process.env.HTTPS_PROXY||process.env.HTTP_PROXY||process.env.http_proxy||process.env.https_proxy}function H(o){let t=process.env.NO_PROXY||process.env.no_proxy;if(!t)return!1;let e=t.split(",").map(s=>s.trim().toLowerCase()).filter(Boolean);if(e.length===0)return!1;let r;try{r=new URL(o).hostname.toLowerCase()}catch{return!1}return e.some(s=>!!(s==="*"||r===s||s.startsWith(".")&&r.endsWith(s)||!s.startsWith(".")&&r.endsWith("."+s)))}var q=async(o,{timeout:t,...e}={})=>{let r=b(),s=r&&!H(o),n,i=t?{connect:{timeout:t}}:{};return s?n=new S.ProxyAgent({uri:r,...i}):t&&(n=new S.Agent(i)),await fetch(o,{signal:t?AbortSignal.timeout(t):void 0,...e,dispatcher:n})};var oe=/^[\x21-\x7e]+( [\x21-\x7e]+)*$/;function Y(){let o=process.env.REDOCLY_ENVIRONMENT?.trim();return o&&oe.test(o)?o:void 0}var u=class extends Error{status;constructor(t,e){super(t),this.status=e}},y=class{command;version;sunsetWarnings=[];constructor(t,e="2.0"){this.command=t,this.version=e}async request(t,e){let r=Y(),s={...e.headers,"user-agent":`redocly-cli/${this.version} ${this.command}${r?` ${r}`:""}`};try{let n=await q(t,{...e,headers:s});return this.collectSunsetWarning(n),n}catch(n){let i="Failed to fetch.";throw n.cause&&(i+=` Caused by ${n.cause.message||n.cause.name}.`),(n.code||n.cause?.code)&&(i+=` Code: ${n.code||n.cause?.code}`),new Error(i)}}collectSunsetWarning(t){let e=this.getSunsetDate(t);if(!e)return;let r=new Date(e);e>Date.now()?this.sunsetWarnings.push({sunsetDate:r,isSunsetExpired:!1}):this.sunsetWarnings.push({sunsetDate:r,isSunsetExpired:!0})}getSunsetDate(t){let{headers:e}=t;if(!e)return;let r=e.get("sunset")||e.get("Sunset");if(r)return Date.parse(r)}},A=class{client;domain;apiKey;constructor(t,e,r){this.client=t,this.domain=e,this.apiKey=r}async getParsedResponse(t){let e=await t.json();if(t.ok)return e;throw new u(`${e.title||t.statusText||"Unknown error"}.`,t.status)}async getDefaultBranch(t,e){try{let r=await this.client.request(`${this.domain}/api/orgs/${t}/projects/${e}/source`,{timeout:6e3,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 u?new u(s,r.status):new Error(s)}}async upsert(t,e,r){try{let s=await this.client.request(`${this.domain}/api/orgs/${t}/projects/${e}/remotes`,{timeout:6e3,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 u?new u(n,s.status):new Error(n)}}async push(t,e,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 a=Buffer.isBuffer(i.stream)?new Blob([i.stream]):new Blob([await ie(i.stream)]);n.append(`files[${i.path}]`,a,i.path)}r.isMainBranch&&n.append("isMainBranch","true");try{let i=await this.client.request(`${this.domain}/api/orgs/${t}/projects/${e}/pushes`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`},body:n});return await this.getParsedResponse(i)}catch(i){let a=`Failed to push. ${i.message}`;throw i instanceof u?new u(a,i.status):new Error(a)}}async getPush({organizationId:t,projectId:e,pushId:r}){try{let s=await this.client.request(`${this.domain}/api/orgs/${t}/projects/${e}/pushes/${r}`,{timeout:6e3,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 u?new u(n,s.status):new Error(n)}}},p=class{apiClient;remotes;constructor({domain:t,apiKey:e,command:r,version:s}){this.apiClient=new y(r,s),this.remotes=new A(this.apiClient,t,e)}getSunsetWarning(){return V(this.apiClient.sunsetWarnings)}};function V(o){let[t]=[...o].sort((e,r)=>e.isSunsetExpired!==r.isSunsetExpired?e.isSunsetExpired?-1:1:e.sunsetDate>r.sunsetDate?1:-1);return t}async function ie(o){let t=[];for await(let e of o)t.push(e);return Buffer.concat(t)}function ae(){if(process.env.REDOCLY_AUTHORIZATION)return process.env.REDOCLY_AUTHORIZATION;throw new Error("No api key provided, please use environment variable REDOCLY_AUTHORIZATION.")}var v={us:"https://app.cloud.redocly.com",eu:"https://app.cloud.eu.redocly.com"};function ce(){return process.env.REDOCLY_DOMAIN||v.us}var z=ue((o,t)=>{try{let e=t||o?.resolvedConfig.residency;return le(e)?v[e]:e?new URL(e).origin:o?.resolvedConfig.scorecard?.fromProjectUrl?new URL(o.resolvedConfig.scorecard.fromProjectUrl).origin:v.us}catch{throw new T}});function N(o){try{z(void 0,o)}catch{return!1}return!0}function ue(o){return(...t)=>{let e=o(...t);if(!e.startsWith("https://"))throw new T;return e}}var T=class extends Error{constructor(){super("Invalid Reunite URL")}};function le(o){return typeof o=="string"&&o in v}import{Buffer as I}from"node:buffer";import _ from"node:crypto";import{mkdirSync as he,existsSync as G,writeFileSync as de,readFileSync as me,rmSync as pe}from"node:fs";import{homedir as fe}from"node:os";import X from"node:path";import*as K from"node:child_process";var f=class{baseUrl;apiClient;clientName="redocly-cli";constructor(t,e){this.baseUrl=t,this.apiClient=new y("login",e)}async run(t){let e=await this.getDeviceCode();t?.({verificationUri:e.verificationUri,verificationUriComplete:e.verificationUriComplete,userCode:e.userCode}),this.openBrowser(e.verificationUriComplete);let r=await this.pollingAccessToken(e.deviceCode,e.interval,e.expiresIn);return this.withResidency(r)}openBrowser(t){if(!/^https?:\/\//.test(t))return;let[e,r]=process.platform==="win32"?["rundll32",["url.dll,FileProtocolHandler",t]]:process.platform==="darwin"?["open",[t]]:["xdg-open",[t]];K.spawn(e,r,{stdio:"ignore",detached:!0}).on("error",()=>{}).unref()}async verifyToken(t){try{return!!(await this.sendRequest("/session","GET",void 0,{Cookie:`accessToken=${t};`})).user}catch{return!1}}async verifyApiKey(t){try{return!!(await this.sendRequest("/api-keys-verify","POST",{apiKey:t})).success}catch{return!1}}async refreshToken(t){let e=await this.sendRequest("/device-rotate-token","POST",{grant_type:"refresh_token",client_name:this.clientName,refresh_token:t});if(!e.access_token)throw new Error("Failed to refresh token");return this.withResidency({access_token:e.access_token,refresh_token:e.refresh_token,expires_in:e.expires_in})}async pollingAccessToken(t,e,r){return new Promise((s,n)=>{let i=setInterval(async()=>{let c=await this.getAccessToken(t);c.access_token&&(clearInterval(i),clearTimeout(a),s(c)),c.error&&c.error!=="authorization_pending"&&(clearInterval(i),clearTimeout(a),n(c.error_description))},e*1e3),a=setTimeout(async()=>{clearInterval(i),clearTimeout(a),n("Authorization has expired. Please try again.")},r*1e3)})}async getAccessToken(t){return await this.sendRequest("/device-token","POST",{client_name:this.clientName,device_code:t,grant_type:"urn:ietf:params:oauth:grant-type:device_code"})}async getDeviceCode(){let{device_code:t,user_code:e,verification_uri:r,verification_uri_complete:s,interval:n=10,expires_in:i=300}=await this.sendRequest("/device-authorize","POST",{client_name:this.clientName});return{deviceCode:t,userCode:e,verificationUri:r,verificationUriComplete:s,interval:n,expiresIn:i}}async sendRequest(t,e="GET",r=void 0,s={}){let n=`${this.baseUrl}/api${t}`,i=await this.apiClient.request(n,{body:r&&JSON.stringify(r),method:e,headers:{"Content-Type":"application/json",...s},timeout:6e3});return i.status===204?{success:!0}:await i.json()}withResidency(t){return{...t,residency:this.baseUrl}}};var ge="4618dbc9-8aed-4e27-aaf0-225f4603e5a4",J="aes-256-cbc",D=class{version;credentialsFolderPath;credentialsFilePath;credentialsFileName;key;iv;constructor(t){this.version=t;let e=fe();this.credentialsFolderPath=X.join(e,".redocly"),this.credentialsFileName="credentials",this.credentialsFilePath=X.join(this.credentialsFolderPath,this.credentialsFileName),this.key=_.createHash("sha256").update(`${this.credentialsFolderPath}${ge}`).digest(),this.iv=_.createHash("md5").update(this.credentialsFolderPath).digest(),he(this.credentialsFolderPath,{recursive:!0})}async login(t,e){let s=await new f(t,this.version).run(e);if(!s)throw new Error("Failed to login. No credentials received.");await this.saveCredentials(s)}async logout(){try{this.removeCredentials()}catch{}}async isAuthorized(t,e){return e?new f(t,this.version).verifyApiKey(e):!!await this.getAccessToken(t)}getAccessToken=async t=>{let e=new f(t,this.version),r=await this.readCredentials();if(!r||!N(t)||r.residency&&r.residency!==t)return null;if(await e.verifyToken(r.access_token))return r.access_token;try{let n=await e.refreshToken(r.refresh_token);return await this.saveCredentials(n),n.access_token}catch{return null}};async saveCredentials(t){try{let e=this.encryptCredentials(t);de(this.credentialsFilePath,e,"utf8")}catch(e){throw new Error(`Failed to save credentials: ${e.message}`)}}async readCredentials(){if(!G(this.credentialsFilePath))return null;try{let t=me(this.credentialsFilePath,"utf8");return this.decryptCredentials(t)}catch{return null}}async removeCredentials(){G(this.credentialsFilePath)&&pe(this.credentialsFilePath)}encryptCredentials(t){let e=_.createCipheriv(J,this.key,this.iv);return I.concat([e.update(JSON.stringify(t),"utf8"),e.final()]).toString("hex")}decryptCredentials(t){let e=_.createDecipheriv(J,this.key,this.iv),r=I.concat([e.update(I.from(t,"hex")),e.final()]);return JSON.parse(r.toString("utf8"))}};import*as g from"node:fs";import*as d from"node:path";async function we({domain:o,apiKey:t,organization:e,project:r,mountPath:s,files:n,defaultBranch:i,commit:a,version:c,onUploadStart:x,onSunsetWarning:C}){let h=new p({domain:o,apiKey:t,command:"push",version:c});try{let w=await h.remotes.getDefaultBranch(e,r),P=await h.remotes.upsert(e,r,{mountBranchName:w,mountPath:s});x?.(P);let{id:E}=await h.remotes.push(e,r,{remoteId:P.id,commit:a,isMainBranch:i===a.branchName},n.map(l=>({path:j(l.name),stream:g.createReadStream(l.path)})));return{pushId:E}}finally{let w=h.getSunsetWarning();w&&C?.(w)}}function ye(o,t){let e={};for(let s of o)if(g.statSync(s).isDirectory()){let n=s;Z(n,[]).forEach(a=>r(a,n))}else r(s,d.dirname(s));function r(s,n){let i=d.relative(n,s);e[i]&&t?.(e[i],s),e[i]=s}return Object.entries(e).map(([s,n])=>({name:s,path:d.resolve(n)}))}function Z(o,t){let e=g.readdirSync(o);for(let r of e){let s=d.join(o,r);g.statSync(s).isDirectory()?t=Z(s,t):t.push(s)}return t}async function Q({operation:o,condition:t,onConditionNotMet:e,startTime:r=Date.now(),retryTimeoutMs:s=6e5,retryIntervalMs:n=5e3}){async function i(){let a=await o();if(t(a))return a;if(Date.now()-r>s)throw new Error("Timeout exceeded.");return await e?.(a),await L(n),i()}return i()}var ve=1200,Te=5e3,xe=["pending","running"];async function Ce(o){let t=ee(o);try{return await re(t,o)}finally{te(t,o)}}async function Pe({buildType:o,maxExecutionTime:t=ve,retryIntervalMs:e=Te,startTime:r=Date.now(),onRetry:s,...n}){let i=ee(n);try{return await Q({operation:()=>re(i,n),condition:a=>!xe.includes(a.status[o].deploy.status),onConditionNotMet:s,startTime:r,retryTimeoutMs:t*1e3,retryIntervalMs:e})}finally{te(i,n)}}function ee({domain:o,apiKey:t,version:e}){return new p({domain:o,apiKey:t,command:"push-status",version:e})}function te(o,{onSunsetWarning:t}){let e=o.getSunsetWarning();e&&t?.(e)}function re(o,{organization:t,project:e,pushId:r}){return o.remotes.getPush({organizationId:t,projectId:e,pushId:r})}async function Ee({projectUrl:o,auth:t,isApiKey:e=!1,onDebug:r}){let s=Re(o);if(!s)throw new m(`Invalid project URL format: ${o}`);try{let n=await Se({...s,auth:t,isApiKey:e,onDebug:r}),i=n.config.scorecardClassic||n.config.scorecard;if(!i)throw new Error("No scorecard configuration found.");let a=n.config.pluginsUrl,c=a?await _e(a,r):void 0;return{scorecard:i,plugins:c,pluginsUrl:a}}catch(n){throw new m(n instanceof Error?n.message:String(n))}}function Re(o){let t=new URL(o),e=t.pathname.match(/\/org\/(?<orgSlug>[^/]+)\/project\/(?<projectSlug>[^/]+)/);if(!e?.groups)return;let{orgSlug:r,projectSlug:s}=e.groups;return{residency:t.origin,orgSlug:r,projectSlug:s}}async function Se({residency:o,orgSlug:t,projectSlug:e,auth:r,isApiKey:s,onDebug:n}){let i=new URL(`${o}/api/orgs/${t}/projects/${e}`),a=await fetch(i,{headers:Fe(r,s)});if(n?.(`Project fetch response status: ${a.status}`),a.status===401||a.status===403)throw n?.(`Authentication failed with status ${a.status}.`),n?.("Check that your credentials are valid and have the necessary permissions."),new Error(`Unauthorized access to project: ${e}. Please check your credentials.`);if(a.status!==200)throw new Error(`Failed to fetch project: ${e}. Status: ${a.status}`);return n?.("Successfully received project configuration."),a.json()}async function _e(o,t){t?.(`Fetching plugins from: ${o}`);try{let e=await fetch(o);if(t?.(`Plugins fetch response status: ${e.status}`),e.status!==200){t?.("Failed to fetch plugins");return}return e.text()}catch(e){t?.(`Error fetching plugins: ${e instanceof Error?e.message:String(e)}`);return}}function Fe(o,t){return t?{Authorization:`Bearer ${o}`}:{Cookie:`accessToken=${o}`}}async function O(o,t,e=[],r=[],s){let n={};for(let i of e){let a={[i.name]:{root:o,rules:t}},c=await M({apis:a,...i,plugins:r},{configPath:s});n[i.name]=c.forAlias(i.name)}return n}function k(o,t){if(o){for(let e of o)if(Object.entries(e.where?.metadata||{}).every(([s,n])=>$e(s,n,t)))return e}}function $e(o,t,e){if(t.match(/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}Z)?\/(\d{4}-\d{2}-\d{2})?$/)){if(!e[o])return!1;let[r,s]=t.split("/"),n=new Date(e[o]);return!(n<new Date(r)||s&&n>new Date(s))}else if(t.match(/^\/.*\//)){if(!e[o])return!1;try{return B(t).test(e[o])}catch{throw new m(`Invalid regex in scorecard target "${o}": ${t}`)}}return e[o]===t}import{pathToFileURL as Ue}from"node:url";async function Ae(o,t){if(!o)return[];let e=Ue(t??process.cwd()).href+"/",r=o.replaceAll("__redocly_dirname",`"${e}"`);return(await import(`data:text/javascript;base64,${btoa(r)}`)).default.map(i=>i())}var Ne=".redocly.com";function Ie(o){try{return new URL(o).hostname.toLowerCase().endsWith(Ne)}catch{return!1}}async function De({apiPath:o,document:t,externalRefResolver:e,scorecardConfig:r,configPath:s,plugins:n=[],targetLevel:i,metadata:a={},onDebug:c}){let x=[],C=new Map,h=r.levels||[];if(i&&!h.some(l=>l.name===i))throw new m(`Target level "${i}" not found in the scorecard configuration levels.
|
|
8
|
-
`);let w=k(r.targets,a)?.rules,P=await O(o,w,h,n,s||"");for(let l of h){c?.(`
|
|
9
|
-
Validating level: "${l.name}"`),n.length>0&&c?.(`Using ${n.length} ${$("plugin",n.length)} for this level.`),c?.("Linting document against level rules...");let R=(await W({document:t,externalRefResolver:e,config:P[l.name]})).filter(({ignored:F})=>!F).map(F=>({...F,scorecardLevel:l.name}));c?.(`Found ${R.length} ${$("problem",R.length)} for level "${l.name}".`),C.set(l.name,R),x.push(...R)}let E=Oe(C,h,i);return{problems:x,achievedLevel:E,targetLevelAchieved:i?E===i:!0}}function Oe(o,t,e){let r=null;for(let s of t){if((o.get(s.name)||[]).some(a=>a.severity==="error"))return r||"Non Conformant";if(r=s.name,e&&s.name===e)return s.name}return r||"Non Conformant"}export{u as a,y as b,p as c,V as d,ae as e,v as f,ce as g,z as h,N as i,T as j,f as k,D as l,we as m,ye as n,Ce as o,Pe as p,Ee as q,O as r,k as s,Ae as t,Ie as u,De as v};
|