@scalar/cli 2.7.1 → 2.10.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/README.md +475 -80
- package/chunks/action-4GZI2M5B.js +62 -0
- package/chunks/action-4W5GUGEG.js +63 -0
- package/chunks/{action-HJYZCPUN.js → action-5LF4XYHX.js} +10 -7
- package/chunks/{action-SRBN7N3R.js → action-5N3P43MD.js} +17 -12
- package/chunks/{action-RBOLLIGX.js → action-5RL4NWUZ.js} +17 -17
- package/chunks/{action-SNPOOW6S.js → action-657A4K2D.js} +16 -16
- package/chunks/{action-EOAVVL52.js → action-7XOHYWYM.js} +11 -14
- package/chunks/{action-AQRPFQKI.js → action-CABLS46Q.js} +9 -7
- package/chunks/{action-F7A2K74G.js → action-CB55NWAU.js} +9 -13
- package/chunks/{action-5SK5NE7E.js → action-DKDRAIKV.js} +11 -14
- package/chunks/{action-7PEQXDWT.js → action-DTEO4YNX.js} +127 -20
- package/chunks/{action-BAQYJ6UE.js → action-EAUTQ77U.js} +27 -23
- package/chunks/{action-QYGOPSTY.js → action-FBRY5JKU.js} +16 -16
- package/chunks/{action-VOFDW3U2.js → action-GFLRD7LO.js} +6 -5
- package/chunks/{action-LPVITMWA.js → action-GWYYTUTM.js} +4 -3
- package/chunks/{action-4NGK5XMD.js → action-HT42NUUX.js} +29 -24
- package/chunks/action-JEYDBB3P.js +147 -0
- package/chunks/{action-E4YSRFGT.js → action-KDUFU7TZ.js} +11 -13
- package/chunks/{action-BRSSC2SR.js → action-LYCNT3KA.js} +29 -10
- package/chunks/{action-CA4QYPI6.js → action-OJ2NK25F.js} +4 -8
- package/chunks/{action-NVI5DWFP.js → action-PAM2EZ22.js} +4 -8
- package/chunks/action-PPTFYZWD.js +1552 -0
- package/chunks/{action-OX2566BE.js → action-R4PGILN4.js} +30 -26
- package/chunks/{action-CPLH2CQ5.js → action-TOBU74JH.js} +23 -19
- package/chunks/action-U2L5DCFG.js +91 -0
- package/chunks/{action-H6OUJWWM.js → action-UUL6SWV4.js} +11 -14
- package/chunks/{action-T5XMJXPO.js → action-X7BA7PQQ.js} +10 -8
- package/chunks/{action-LVDU6YOI.js → action-XLE37MZL.js} +16 -16
- package/chunks/{action-BOZNBCNZ.js → action-XOADBXSX.js} +16 -12
- package/chunks/{action-SCOXTCPR.js → action-YSVTZVKV.js} +38 -19
- package/chunks/{action-YRX6SN5F.js → action-ZFI77WA5.js} +8 -6
- package/chunks/{action-ATGZOWSH.js → action-ZKA3RR3S.js} +15 -11
- package/chunks/actions-3SAMH7A5.js +182 -0
- package/chunks/{agent-ASPV3R5U.js → agent-2ESZI7NO.js} +7 -5
- package/chunks/{asyncapi-H4FU6GPC.js → asyncapi-4HGVM3PR.js} +14 -10
- package/chunks/{build.action-6V6GXI3X.js → build.action-VBGFGACM.js} +21 -19
- package/chunks/chunk-35Z7VTJT.js +453 -0
- package/chunks/chunk-36LXIJIZ.js +52 -0
- package/chunks/{chunk-BIKOD3SG.js → chunk-43WALAW3.js} +251 -103
- package/chunks/{chunk-C2KAWRIX.js → chunk-5ENKYZA4.js} +1 -1
- package/chunks/{chunk-ZJVYOZFB.js → chunk-5SMP756H.js} +2 -2
- package/chunks/{chunk-5JLVQVKO.js → chunk-6M7TL2G2.js} +146 -148
- package/chunks/chunk-6PSYZO3U.js +24 -0
- package/chunks/{chunk-ISXH6Q7I.js → chunk-ATNTXKMS.js} +45 -274
- package/chunks/{chunk-BDEPNGTO.js → chunk-BIMLCGKS.js} +1 -1
- package/chunks/{chunk-HGOD6THU.js → chunk-CWVYOXXM.js} +2 -19
- package/chunks/chunk-DFOZG7ZV.js +15 -0
- package/chunks/chunk-DHZW7Q7U.js +133 -0
- package/chunks/{chunk-R5LK6VPY.js → chunk-G4HRW2FZ.js} +13 -20
- package/chunks/{chunk-KCCFN4F7.js → chunk-GLWTVLKM.js} +29 -29
- package/chunks/{chunk-5UHLAJQD.js → chunk-GYRQPDTK.js} +24 -10
- package/chunks/chunk-H467HDVV.js +24 -0
- package/chunks/chunk-IPZP3VRA.js +327 -0
- package/chunks/{chunk-LG7IFACX.js → chunk-JXGF5EHC.js} +152 -18
- package/chunks/chunk-K2HIB5BA.js +92 -0
- package/chunks/{chunk-FDC2IESH.js → chunk-KHF2QXBG.js} +1352 -8327
- package/chunks/{chunk-IMG35UXX.js → chunk-KZNRQVMY.js} +1 -1
- package/chunks/{chunk-OJ2EWIJH.js → chunk-MC4EMNOR.js} +5 -1
- package/chunks/{chunk-YILQODZF.js → chunk-MMWSCTDB.js} +7 -4
- package/chunks/{chunk-6XWCMJDB.js → chunk-MNNGUUKJ.js} +12 -11
- package/chunks/chunk-NAC63XJF.js +10 -0
- package/chunks/{chunk-XXSQUBXS.js → chunk-UDBSV3CK.js} +107 -453
- package/chunks/{chunk-IKT5F47M.js → chunk-VVRUSQCY.js} +11 -11
- package/chunks/{chunk-2PPRO2QB.js → chunk-VYFGRLVQ.js} +1 -1
- package/chunks/{chunk-GPNB7ISG.js → chunk-WB6PWTMU.js} +5 -13
- package/chunks/{chunk-4X47MN6Q.js → chunk-WDIWLXLV.js} +3 -15
- package/chunks/{chunk-6YPQGVF4.js → chunk-WIEXQUTD.js} +1 -1
- package/chunks/{chunk-W24BETFG.js → chunk-XAGJJNQW.js} +3 -3
- package/chunks/{chunk-2DSVF5AD.js → chunk-ZGNDXPLU.js} +3 -3
- package/chunks/{chunk-XEDGMZJD.js → chunk-ZGVZU6L2.js} +81 -25
- package/chunks/{chunk-QXQZVEDC.js → chunk-ZKJPLWRJ.js} +2 -2
- package/chunks/{chunk-MLSZVVTT.js → chunk-ZYBLQ5CT.js} +13 -7
- package/chunks/{create.action-P6DLCK4W.js → create.action-DBNIS665.js} +21 -19
- package/chunks/{delete.action-HJKRRHE2.js → delete.action-GBOZC45K.js} +21 -19
- package/chunks/{delete.action-Z3GAA4ZN.js → delete.action-K7BLK7DK.js} +21 -19
- package/chunks/{get.action-IT4EHAV4.js → get.action-N3JOY3OU.js} +17 -12
- package/chunks/get.action-QHKMYZBK.js +91 -0
- package/chunks/{list.action-WLIAO5UW.js → list.action-6SSO3JVN.js} +45 -15
- package/chunks/{list.action-2FU5UZNH.js → list.action-TJCS6UEY.js} +41 -21
- package/chunks/{publish.action-T4J4DRXR.js → publish.action-T24VHRMR.js} +29 -24
- package/chunks/query-WKATAJJ6.js +129 -0
- package/chunks/scripts-VIBLGKYG.js +102 -0
- package/chunks/{update.action-3OVS3HWC.js → update.action-OGYNBXRU.js} +24 -19
- package/chunks/{update.action-MY7QPSSU.js → update.action-VOE6PH5F.js} +24 -19
- package/docs.html +1363 -320
- package/index.js +417 -174
- package/package.json +14 -13
- package/skills/scalar-cli/SKILL.md +13 -1
- package/template.md +157 -15
- package/chunks/action-JAHFRYWZ.js +0 -423
- package/chunks/action-N7BA5I3E.js +0 -229
- package/chunks/chunk-CWCETP6H.js +0 -610
- package/chunks/chunk-K74E42RV.js +0 -7311
|
@@ -1,423 +0,0 @@
|
|
|
1
|
-
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
getFileOrUrl,
|
|
4
|
-
isAsyncApiContent
|
|
5
|
-
} from "./chunk-HGOD6THU.js";
|
|
6
|
-
import {
|
|
7
|
-
err,
|
|
8
|
-
ok
|
|
9
|
-
} from "./chunk-C2KAWRIX.js";
|
|
10
|
-
import {
|
|
11
|
-
require_dist
|
|
12
|
-
} from "./chunk-K74E42RV.js";
|
|
13
|
-
import "./chunk-KCCFN4F7.js";
|
|
14
|
-
import "./chunk-6XWCMJDB.js";
|
|
15
|
-
import "./chunk-4ORL4MST.js";
|
|
16
|
-
import {
|
|
17
|
-
output
|
|
18
|
-
} from "./chunk-T5HJUAWB.js";
|
|
19
|
-
import "./chunk-XEDGMZJD.js";
|
|
20
|
-
import "./chunk-IKT5F47M.js";
|
|
21
|
-
import {
|
|
22
|
-
__toESM
|
|
23
|
-
} from "./chunk-3MZYUBJ6.js";
|
|
24
|
-
|
|
25
|
-
// src/domains/document/lint/action.ts
|
|
26
|
-
import as from "ansis";
|
|
27
|
-
|
|
28
|
-
// ../../packages/api-document-lint/dist/constants.js
|
|
29
|
-
var DEFAULT_RULESET = `extends: spectral:oas
|
|
30
|
-
rules: {}`;
|
|
31
|
-
var ASYNCAPI_RULESET = `extends: spectral:asyncapi
|
|
32
|
-
rules: {}`;
|
|
33
|
-
|
|
34
|
-
// ../../packages/api-document-lint/dist/default-ruleset.js
|
|
35
|
-
function isAsyncApiContent2(content) {
|
|
36
|
-
const head = content.slice(0, 500);
|
|
37
|
-
if (head.includes('"asyncapi"')) {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
return head.split("\n").some((line) => /^asyncapi\s*:/.test(line.trimStart()));
|
|
41
|
-
}
|
|
42
|
-
function defaultRulesetFor(content) {
|
|
43
|
-
return isAsyncApiContent2(content) ? ASYNCAPI_RULESET : DEFAULT_RULESET;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// ../../packages/api-document-lint/dist/run-spectral.js
|
|
47
|
-
import spectralCore from "@stoplight/spectral-core";
|
|
48
|
-
import { bundleAndLoadRuleset } from "@stoplight/spectral-ruleset-bundler/with-loader";
|
|
49
|
-
import "@stoplight/spectral-rulesets";
|
|
50
|
-
var { Spectral } = spectralCore;
|
|
51
|
-
async function runSpectral(input) {
|
|
52
|
-
const rulesetSource = input.ruleset && input.ruleset.trim().length > 0 ? input.ruleset : defaultRulesetFor(input.document);
|
|
53
|
-
const ruleset = await loadRuleset(rulesetSource);
|
|
54
|
-
if (!ruleset.ok) {
|
|
55
|
-
return ruleset;
|
|
56
|
-
}
|
|
57
|
-
const spectral = new Spectral();
|
|
58
|
-
spectral.setRuleset(ruleset.data);
|
|
59
|
-
const diagnostics = await spectral.run(input.document).catch((error) => error instanceof Error ? error : new Error(String(error)));
|
|
60
|
-
if (diagnostics instanceof Error) {
|
|
61
|
-
return err(`Spectral failed to lint the document \u2014 ${diagnostics.message}`);
|
|
62
|
-
}
|
|
63
|
-
return ok(diagnostics);
|
|
64
|
-
}
|
|
65
|
-
async function loadRuleset(source) {
|
|
66
|
-
const ruleset = await bundleAndLoadRuleset("/.spectral.yaml", {
|
|
67
|
-
fs: {
|
|
68
|
-
promises: {
|
|
69
|
-
// @ts-expect-error The loader only ever reads our single virtual file.
|
|
70
|
-
async readFile() {
|
|
71
|
-
return source;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
format: "esm"
|
|
76
|
-
}).catch((error) => error instanceof Error ? error : new Error(String(error)));
|
|
77
|
-
if (ruleset instanceof Error) {
|
|
78
|
-
return err(`Failed to load ruleset \u2014 ${ruleset.message}`);
|
|
79
|
-
}
|
|
80
|
-
return ok(ruleset);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// ../../packages/api-document-lint/dist/run-vacuum.js
|
|
84
|
-
import { execFile } from "node:child_process";
|
|
85
|
-
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
86
|
-
import { tmpdir } from "node:os";
|
|
87
|
-
import { join as join2 } from "node:path";
|
|
88
|
-
import { promisify } from "node:util";
|
|
89
|
-
|
|
90
|
-
// ../../packages/api-document-lint/dist/normalize-diagnostics.js
|
|
91
|
-
var EMPTY_RANGE = {
|
|
92
|
-
start: { line: 0, character: 0 },
|
|
93
|
-
end: { line: 0, character: 0 }
|
|
94
|
-
};
|
|
95
|
-
function normalizeDiagnostics(raw) {
|
|
96
|
-
if (!Array.isArray(raw)) {
|
|
97
|
-
return [];
|
|
98
|
-
}
|
|
99
|
-
return raw.filter(isObject).map((item) => {
|
|
100
|
-
const source = item.source;
|
|
101
|
-
return {
|
|
102
|
-
code: isCode(item.code) ? item.code : "",
|
|
103
|
-
message: typeof item.message === "string" ? item.message : "",
|
|
104
|
-
severity: normalizeSeverity(item.severity),
|
|
105
|
-
path: Array.isArray(item.path) ? item.path.filter(isSegment) : [],
|
|
106
|
-
range: normalizeRange(item.range),
|
|
107
|
-
...typeof source === "string" ? { source } : {}
|
|
108
|
-
};
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
function isObject(value) {
|
|
112
|
-
return typeof value === "object" && value !== null;
|
|
113
|
-
}
|
|
114
|
-
function isCode(value) {
|
|
115
|
-
return typeof value === "string" || typeof value === "number";
|
|
116
|
-
}
|
|
117
|
-
function isSegment(value) {
|
|
118
|
-
return typeof value === "string" || typeof value === "number";
|
|
119
|
-
}
|
|
120
|
-
function normalizeRange(range) {
|
|
121
|
-
if (!isObject(range)) {
|
|
122
|
-
return EMPTY_RANGE;
|
|
123
|
-
}
|
|
124
|
-
return {
|
|
125
|
-
start: normalizePosition(range.start),
|
|
126
|
-
end: normalizePosition(range.end)
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
function normalizePosition(position) {
|
|
130
|
-
if (!isObject(position)) {
|
|
131
|
-
return { line: 0, character: 0 };
|
|
132
|
-
}
|
|
133
|
-
return {
|
|
134
|
-
line: toCoordinate(position.line),
|
|
135
|
-
character: toCoordinate(position.character)
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
function toCoordinate(value) {
|
|
139
|
-
return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : 0;
|
|
140
|
-
}
|
|
141
|
-
function normalizeSeverity(severity) {
|
|
142
|
-
return severity === 1 || severity === 2 || severity === 3 ? severity : 0;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// ../../packages/api-document-lint/dist/resolve-binary.js
|
|
146
|
-
import { statSync } from "node:fs";
|
|
147
|
-
import { createRequire } from "node:module";
|
|
148
|
-
import { dirname, join } from "node:path";
|
|
149
|
-
var binaryName = process.platform === "win32" ? "vacuum.exe" : "vacuum";
|
|
150
|
-
function resolveVacuumBinary(override) {
|
|
151
|
-
const explicit = override ?? process.env.VACUUM_BINARY;
|
|
152
|
-
if (explicit) {
|
|
153
|
-
return isFile(explicit) ? ok(explicit) : err(`vacuum binary not found at ${explicit}`);
|
|
154
|
-
}
|
|
155
|
-
const packaged = resolvePackagedBinary();
|
|
156
|
-
if (packaged) {
|
|
157
|
-
return ok(packaged);
|
|
158
|
-
}
|
|
159
|
-
return ok("vacuum");
|
|
160
|
-
}
|
|
161
|
-
function resolvePackagedBinary() {
|
|
162
|
-
try {
|
|
163
|
-
const require2 = createRequire(import.meta.url);
|
|
164
|
-
const packageJsonPath = require2.resolve("@quobix/vacuum/package.json");
|
|
165
|
-
const candidate = join(dirname(packageJsonPath), "bin", binaryName);
|
|
166
|
-
return isFile(candidate) ? candidate : null;
|
|
167
|
-
} catch {
|
|
168
|
-
return null;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
function isFile(path) {
|
|
172
|
-
try {
|
|
173
|
-
return statSync(path, { throwIfNoEntry: false })?.isFile() ?? false;
|
|
174
|
-
} catch {
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// ../../packages/api-document-lint/dist/validate-inline-document.js
|
|
180
|
-
var import_yaml = __toESM(require_dist(), 1);
|
|
181
|
-
function validateInlineDocument(document) {
|
|
182
|
-
const parsed = (() => {
|
|
183
|
-
try {
|
|
184
|
-
return ok((0, import_yaml.parse)(document));
|
|
185
|
-
} catch {
|
|
186
|
-
return err("Document must be valid YAML or JSON before linting.");
|
|
187
|
-
}
|
|
188
|
-
})();
|
|
189
|
-
if (!parsed.ok)
|
|
190
|
-
return parsed;
|
|
191
|
-
const references = /* @__PURE__ */ new Set([
|
|
192
|
-
"$ref",
|
|
193
|
-
"$dynamicRef",
|
|
194
|
-
"$recursiveRef",
|
|
195
|
-
"operationRef"
|
|
196
|
-
]);
|
|
197
|
-
const seen = /* @__PURE__ */ new Set();
|
|
198
|
-
const pending = [parsed.data];
|
|
199
|
-
while (pending.length) {
|
|
200
|
-
const value = pending.pop();
|
|
201
|
-
if (!value || typeof value !== "object" || seen.has(value))
|
|
202
|
-
continue;
|
|
203
|
-
seen.add(value);
|
|
204
|
-
for (const [key, child] of Object.entries(value)) {
|
|
205
|
-
if (references.has(key) && typeof child === "string" && child !== "" && !child.startsWith("#")) {
|
|
206
|
-
return err("External references are not supported by hosted linting. Bundle the document first.");
|
|
207
|
-
}
|
|
208
|
-
if (child && typeof child === "object")
|
|
209
|
-
pending.push(child);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
return ok(void 0);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// ../../packages/api-document-lint/dist/run-vacuum.js
|
|
216
|
-
var execFileAsync = promisify(execFile);
|
|
217
|
-
var MAX_BUFFER = 64 * 1024 * 1024;
|
|
218
|
-
var TIMEOUT_MS = 6e4;
|
|
219
|
-
async function runVacuum(input, options = {}) {
|
|
220
|
-
if (input.document.trim().length === 0) {
|
|
221
|
-
return ok([]);
|
|
222
|
-
}
|
|
223
|
-
if (options.allowExternalReferences === false) {
|
|
224
|
-
const validation = validateInlineDocument(input.document);
|
|
225
|
-
if (!validation.ok)
|
|
226
|
-
return validation;
|
|
227
|
-
}
|
|
228
|
-
const binary = resolveVacuumBinary(options.binaryPath);
|
|
229
|
-
if (!binary.ok) {
|
|
230
|
-
return binary;
|
|
231
|
-
}
|
|
232
|
-
const directory = await mkdtemp(join2(tmpdir(), "scalar-lint-")).catch(() => null);
|
|
233
|
-
if (directory === null) {
|
|
234
|
-
return err("vacuum lint failed \u2014 could not create a temporary directory");
|
|
235
|
-
}
|
|
236
|
-
const documentPath = join2(directory, "document.yaml");
|
|
237
|
-
const reportPath = join2(directory, "report.json");
|
|
238
|
-
try {
|
|
239
|
-
const wroteDocument = await writeFile(documentPath, input.document, "utf8").then(() => true).catch(() => false);
|
|
240
|
-
if (!wroteDocument) {
|
|
241
|
-
return err("vacuum lint failed \u2014 could not write the document to a temporary file");
|
|
242
|
-
}
|
|
243
|
-
const args = [
|
|
244
|
-
"spectral-report",
|
|
245
|
-
"--no-style",
|
|
246
|
-
"--no-update-check",
|
|
247
|
-
"--skip-check",
|
|
248
|
-
// Match Spectral's working-directory base for document strings.
|
|
249
|
-
"--base",
|
|
250
|
-
options.allowExternalReferences === false ? directory : process.cwd()
|
|
251
|
-
];
|
|
252
|
-
if (options.allowExternalReferences === false) {
|
|
253
|
-
const configPath = join2(directory, "vacuum.conf.yaml");
|
|
254
|
-
const configured = await writeFile(configPath, "{}").then(() => true).catch(() => false);
|
|
255
|
-
if (!configured)
|
|
256
|
-
return err("Could not create hosted lint configuration");
|
|
257
|
-
args.push("--remote=false", "--config", configPath);
|
|
258
|
-
}
|
|
259
|
-
if (input.ruleset && input.ruleset.trim().length > 0) {
|
|
260
|
-
const rulesetPath = join2(directory, "ruleset.yaml");
|
|
261
|
-
const wroteRuleset = await writeFile(rulesetPath, input.ruleset, "utf8").then(() => true).catch(() => false);
|
|
262
|
-
if (!wroteRuleset) {
|
|
263
|
-
return err("vacuum lint failed \u2014 could not write the ruleset to a temporary file");
|
|
264
|
-
}
|
|
265
|
-
args.push("--ruleset", rulesetPath);
|
|
266
|
-
}
|
|
267
|
-
args.push(documentPath, reportPath);
|
|
268
|
-
const failure = await execFileAsync(binary.data, args, {
|
|
269
|
-
maxBuffer: MAX_BUFFER,
|
|
270
|
-
timeout: options.timeoutMs ?? TIMEOUT_MS,
|
|
271
|
-
...options.allowExternalReferences === false ? { cwd: directory } : {}
|
|
272
|
-
}).then(() => null).catch((error) => error);
|
|
273
|
-
const report = await readFile(reportPath, "utf8").catch(() => null);
|
|
274
|
-
if (report === null) {
|
|
275
|
-
if (failure === null) {
|
|
276
|
-
return err("vacuum ran but its report could not be read");
|
|
277
|
-
}
|
|
278
|
-
return err(`vacuum failed to lint the document \u2014 ${describeFailure(failure)}`);
|
|
279
|
-
}
|
|
280
|
-
const parsed = parseReport(report);
|
|
281
|
-
if (!parsed.ok) {
|
|
282
|
-
return parsed;
|
|
283
|
-
}
|
|
284
|
-
return ok(normalizeDiagnostics(parsed.data));
|
|
285
|
-
} finally {
|
|
286
|
-
await rm(directory, { recursive: true, force: true }).catch(() => void 0);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
function describeFailure(failure) {
|
|
290
|
-
if (failure && typeof failure === "object") {
|
|
291
|
-
const stderr = failure.stderr;
|
|
292
|
-
if (typeof stderr === "string" && stderr.trim().length > 0) {
|
|
293
|
-
return stderr.trim();
|
|
294
|
-
}
|
|
295
|
-
if (failure instanceof Error) {
|
|
296
|
-
return failure.message;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
return "no report was written";
|
|
300
|
-
}
|
|
301
|
-
function parseReport(report) {
|
|
302
|
-
try {
|
|
303
|
-
const parsed = JSON.parse(report);
|
|
304
|
-
if (!Array.isArray(parsed)) {
|
|
305
|
-
return err("vacuum produced a report in an unexpected shape");
|
|
306
|
-
}
|
|
307
|
-
return ok(parsed);
|
|
308
|
-
} catch {
|
|
309
|
-
return err("vacuum produced an unreadable report");
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
// ../../packages/api-document-lint/dist/select-engine.js
|
|
314
|
-
var import_yaml2 = __toESM(require_dist(), 1);
|
|
315
|
-
function selectEngine(ruleset) {
|
|
316
|
-
if (!ruleset || ruleset.trim().length === 0) {
|
|
317
|
-
return "vacuum";
|
|
318
|
-
}
|
|
319
|
-
const parsed = parseRuleset(ruleset);
|
|
320
|
-
if (parsed === null) {
|
|
321
|
-
return "spectral";
|
|
322
|
-
}
|
|
323
|
-
if (hasCustomFunctions(parsed) || hasRuleCustomizations(parsed) || extendsUninspectableRuleset(parsed) || overridesRequireSpectral(parsed)) {
|
|
324
|
-
return "spectral";
|
|
325
|
-
}
|
|
326
|
-
return "vacuum";
|
|
327
|
-
}
|
|
328
|
-
function overridesRequireSpectral(ruleset) {
|
|
329
|
-
const overrides = ruleset.overrides;
|
|
330
|
-
if (!Array.isArray(overrides)) {
|
|
331
|
-
return false;
|
|
332
|
-
}
|
|
333
|
-
return overrides.some((entry) => isRecord(entry) && (hasCustomFunctions(entry) || hasRuleCustomizations(entry) || extendsUninspectableRuleset(entry)));
|
|
334
|
-
}
|
|
335
|
-
function hasRuleCustomizations(ruleset) {
|
|
336
|
-
return ruleset.rules !== void 0 && (!isRecord(ruleset.rules) || Object.keys(ruleset.rules).length > 0);
|
|
337
|
-
}
|
|
338
|
-
function isRecord(value) {
|
|
339
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
340
|
-
}
|
|
341
|
-
function parseRuleset(ruleset) {
|
|
342
|
-
try {
|
|
343
|
-
const value = (0, import_yaml2.parse)(ruleset);
|
|
344
|
-
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
345
|
-
return value;
|
|
346
|
-
}
|
|
347
|
-
return null;
|
|
348
|
-
} catch {
|
|
349
|
-
return null;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
function hasCustomFunctions(ruleset) {
|
|
353
|
-
const functions = ruleset.functions;
|
|
354
|
-
if (Array.isArray(functions) && functions.length > 0) {
|
|
355
|
-
return true;
|
|
356
|
-
}
|
|
357
|
-
return typeof ruleset.functionsDir === "string" && ruleset.functionsDir.length > 0;
|
|
358
|
-
}
|
|
359
|
-
function extendsUninspectableRuleset(ruleset) {
|
|
360
|
-
const extended = ruleset.extends;
|
|
361
|
-
if (extended === void 0) {
|
|
362
|
-
return false;
|
|
363
|
-
}
|
|
364
|
-
const entries = Array.isArray(extended) ? extended : [extended];
|
|
365
|
-
return entries.some((entry) => !isBuiltInRuleset(entry));
|
|
366
|
-
}
|
|
367
|
-
function isBuiltInRuleset(entry) {
|
|
368
|
-
const source = Array.isArray(entry) ? entry[0] : entry;
|
|
369
|
-
return source === "spectral:oas" || source === "spectral:asyncapi";
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
// ../../packages/api-document-lint/dist/lint.js
|
|
373
|
-
async function lint(input, options = {}) {
|
|
374
|
-
const ruleset = input.ruleset && input.ruleset.trim().length > 0 ? input.ruleset : defaultRulesetFor(input.document);
|
|
375
|
-
const resolved = { document: input.document, ruleset };
|
|
376
|
-
const engine = selectEngine(ruleset);
|
|
377
|
-
const diagnostics = engine === "vacuum" ? await runVacuum(resolved, options) : await runSpectral(resolved);
|
|
378
|
-
if (!diagnostics.ok) {
|
|
379
|
-
return diagnostics;
|
|
380
|
-
}
|
|
381
|
-
return ok({ diagnostics: diagnostics.data, engine });
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
// src/domains/document/lint/helpers.ts
|
|
385
|
-
var severityToLabel = (severity) => {
|
|
386
|
-
return {
|
|
387
|
-
0: "Error",
|
|
388
|
-
1: "Warning",
|
|
389
|
-
2: "Information",
|
|
390
|
-
3: "Hint"
|
|
391
|
-
}[severity];
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
// src/domains/document/lint/action.ts
|
|
395
|
-
async function lintAction(inputArgument, { rule: ruleArgument }) {
|
|
396
|
-
if (!inputArgument) {
|
|
397
|
-
return output.error().title("Invalid argument").message("Please provide a file path").exit("error");
|
|
398
|
-
}
|
|
399
|
-
const specification = await getFileOrUrl(inputArgument);
|
|
400
|
-
const ruleset = ruleArgument ? await getFileOrUrl(ruleArgument) : isAsyncApiContent(specification) ? ASYNCAPI_RULESET : DEFAULT_RULESET;
|
|
401
|
-
const result = await lint({ document: specification, ruleset });
|
|
402
|
-
if (!result.ok) {
|
|
403
|
-
return output.error().title("Failed to lint the document").message(result.error).exit("error");
|
|
404
|
-
}
|
|
405
|
-
const diagnostics = result.data.diagnostics;
|
|
406
|
-
const hasErrors = diagnostics.some((diagnostic) => diagnostic.severity === 0);
|
|
407
|
-
if (!hasErrors) {
|
|
408
|
-
output.info().message(as.green("\u2714 No issues found!")).print();
|
|
409
|
-
} else {
|
|
410
|
-
output.warn().line(as.red("\u2716 Issues found:")).print();
|
|
411
|
-
}
|
|
412
|
-
for (const diagnostic of diagnostics) {
|
|
413
|
-
output.info().line(`${as.yellow("Rule:")} ${as.bold(String(diagnostic.code))}`).line(`${as.yellow("Message:")} ${diagnostic.message}`).line(`${as.yellow("Severity:")} ${severityToLabel(diagnostic.severity)}`).line(
|
|
414
|
-
`${as.yellow("Location:")} ${diagnostic.range.start.line}:${diagnostic.range.start.character} - ${diagnostic.range.end.line}:${diagnostic.range.end.character}`
|
|
415
|
-
).line(as.gray("---")).print();
|
|
416
|
-
}
|
|
417
|
-
if (hasErrors) {
|
|
418
|
-
output.error().exit("error");
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
export {
|
|
422
|
-
lintAction
|
|
423
|
-
};
|
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
openBrowser
|
|
4
|
-
} from "./chunk-JFIXNSPP.js";
|
|
5
|
-
import {
|
|
6
|
-
accessTokenPayloadSchema,
|
|
7
|
-
decode,
|
|
8
|
-
generateAccessByPersonalToken,
|
|
9
|
-
setAuthData,
|
|
10
|
-
tokenResponseSchema
|
|
11
|
-
} from "./chunk-CWCETP6H.js";
|
|
12
|
-
import {
|
|
13
|
-
config
|
|
14
|
-
} from "./chunk-GPNB7ISG.js";
|
|
15
|
-
import "./chunk-5UHLAJQD.js";
|
|
16
|
-
import "./chunk-5JLVQVKO.js";
|
|
17
|
-
import "./chunk-4ORL4MST.js";
|
|
18
|
-
import {
|
|
19
|
-
output
|
|
20
|
-
} from "./chunk-T5HJUAWB.js";
|
|
21
|
-
import {
|
|
22
|
-
external_exports
|
|
23
|
-
} from "./chunk-IKT5F47M.js";
|
|
24
|
-
import "./chunk-3MZYUBJ6.js";
|
|
25
|
-
|
|
26
|
-
// src/domains/auth/login/action.ts
|
|
27
|
-
import as2 from "ansis";
|
|
28
|
-
|
|
29
|
-
// ../../packages/mongobase-client/dist/auth/node/exchange-callback-server.js
|
|
30
|
-
import getPort from "get-port";
|
|
31
|
-
var generateTokenCallbackEndpoint = async (exchangeUrl, allowedOrigin) => {
|
|
32
|
-
const parsedAllowedOrigin = URL.parse(allowedOrigin);
|
|
33
|
-
if (!parsedAllowedOrigin) {
|
|
34
|
-
throw new Error(`Invalid dashboard URL "${allowedOrigin}". Provide an absolute URL such as https://dashboard.scalar.com.`);
|
|
35
|
-
}
|
|
36
|
-
const allowedCorsOrigin = parsedAllowedOrigin.origin;
|
|
37
|
-
const http = await import("node:http");
|
|
38
|
-
const port = await getPort();
|
|
39
|
-
const server = http.createServer();
|
|
40
|
-
server.listen({ port, host: "127.0.0.1" });
|
|
41
|
-
const getTokens = async () => {
|
|
42
|
-
const resultPromise = new Promise((resolve) => {
|
|
43
|
-
server.on("request", async (req, res) => {
|
|
44
|
-
const corsHeaders = req.headers.origin === allowedCorsOrigin ? {
|
|
45
|
-
"Access-Control-Allow-Origin": allowedCorsOrigin,
|
|
46
|
-
Vary: "Origin"
|
|
47
|
-
} : { Vary: "Origin" };
|
|
48
|
-
if (req.method === "OPTIONS") {
|
|
49
|
-
res.writeHead(204, {
|
|
50
|
-
...corsHeaders,
|
|
51
|
-
"Access-Control-Allow-Methods": "POST",
|
|
52
|
-
"Access-Control-Allow-Headers": "*",
|
|
53
|
-
"Access-Control-Allow-Private-Network": "true"
|
|
54
|
-
});
|
|
55
|
-
res.end();
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
const errorResponse = (message, code) => {
|
|
59
|
-
res.writeHead(code, {
|
|
60
|
-
"Content-Type": "application/json",
|
|
61
|
-
...corsHeaders
|
|
62
|
-
});
|
|
63
|
-
res.end(JSON.stringify({
|
|
64
|
-
success: false,
|
|
65
|
-
error: true,
|
|
66
|
-
message
|
|
67
|
-
}));
|
|
68
|
-
server.close();
|
|
69
|
-
return resolve({ data: null, error: true });
|
|
70
|
-
};
|
|
71
|
-
if (req.method !== "POST") {
|
|
72
|
-
return errorResponse("Method not allowed", 405);
|
|
73
|
-
}
|
|
74
|
-
const url = new URL(`http://localhost:${port}${req.url}`);
|
|
75
|
-
const exchangeToken = url.searchParams.get("exchangeToken");
|
|
76
|
-
if (!exchangeToken) {
|
|
77
|
-
return errorResponse("Missing exchange token", 400);
|
|
78
|
-
}
|
|
79
|
-
try {
|
|
80
|
-
const tokens = await exchangeTokenForAccess(exchangeUrl, exchangeToken);
|
|
81
|
-
if (tokens) {
|
|
82
|
-
res.writeHead(200, {
|
|
83
|
-
"Content-Type": "application/json",
|
|
84
|
-
...corsHeaders
|
|
85
|
-
});
|
|
86
|
-
res.end(JSON.stringify({
|
|
87
|
-
success: true,
|
|
88
|
-
error: false,
|
|
89
|
-
message: "Token exchanged. "
|
|
90
|
-
}));
|
|
91
|
-
server.close();
|
|
92
|
-
return resolve({ data: tokens, error: false });
|
|
93
|
-
}
|
|
94
|
-
return errorResponse("Failed to exchange token", 400);
|
|
95
|
-
} catch (err) {
|
|
96
|
-
console.error(err);
|
|
97
|
-
return errorResponse("Internal server error", 500);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
const timeoutPromise = new Promise((resolve) => {
|
|
102
|
-
setTimeout(() => {
|
|
103
|
-
server.close();
|
|
104
|
-
resolve({ data: null, error: true });
|
|
105
|
-
}, 3 * 60 * 1e3);
|
|
106
|
-
});
|
|
107
|
-
return Promise.race([resultPromise, timeoutPromise]);
|
|
108
|
-
};
|
|
109
|
-
return {
|
|
110
|
-
port,
|
|
111
|
-
cancel: () => server.close(),
|
|
112
|
-
getTokens
|
|
113
|
-
};
|
|
114
|
-
};
|
|
115
|
-
var exchangeTokenForAccess = async (serverUrl, exchangeToken) => {
|
|
116
|
-
const result = await fetch(serverUrl, {
|
|
117
|
-
method: "POST",
|
|
118
|
-
headers: {
|
|
119
|
-
"Content-Type": "application/json"
|
|
120
|
-
},
|
|
121
|
-
body: JSON.stringify({
|
|
122
|
-
exchangeToken
|
|
123
|
-
})
|
|
124
|
-
});
|
|
125
|
-
if (result.ok) {
|
|
126
|
-
return tokenResponseSchema.parse(await result.json());
|
|
127
|
-
}
|
|
128
|
-
return null;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
// src/domains/auth/login/helpers/messages.ts
|
|
132
|
-
import as from "ansis";
|
|
133
|
-
function loggedInMessage(userIdentifier) {
|
|
134
|
-
if (process.env.CI || !userIdentifier)
|
|
135
|
-
return "Successfully authenticated to Scalar CLI";
|
|
136
|
-
return `Successfully authenticated to Scalar CLI as ${as.cyan(userIdentifier)}`;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// src/domains/auth/login/helpers/email-pass-auth.ts
|
|
140
|
-
var tokenResponseSchema2 = external_exports.object({
|
|
141
|
-
accessToken: external_exports.string(),
|
|
142
|
-
refreshToken: external_exports.string()
|
|
143
|
-
});
|
|
144
|
-
var emailPasswordAuth = async ({
|
|
145
|
-
email,
|
|
146
|
-
password
|
|
147
|
-
}) => {
|
|
148
|
-
const result = await fetch(`${config.services.api}/core/login/email`, {
|
|
149
|
-
method: "POST",
|
|
150
|
-
headers: {
|
|
151
|
-
"Content-Type": "application/json"
|
|
152
|
-
},
|
|
153
|
-
credentials: "include",
|
|
154
|
-
body: JSON.stringify({
|
|
155
|
-
email,
|
|
156
|
-
password
|
|
157
|
-
})
|
|
158
|
-
});
|
|
159
|
-
if (!result.ok) {
|
|
160
|
-
const data = await result.json();
|
|
161
|
-
throw new Error(data.message ?? "Could not login with email");
|
|
162
|
-
}
|
|
163
|
-
return tokenResponseSchema2.parse(await result.json());
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
// src/domains/auth/login/action.ts
|
|
167
|
-
async function loginAction({
|
|
168
|
-
email,
|
|
169
|
-
password,
|
|
170
|
-
token: _token
|
|
171
|
-
}) {
|
|
172
|
-
const token = process.env.SCALAR_API_KEY || _token;
|
|
173
|
-
if (token) {
|
|
174
|
-
try {
|
|
175
|
-
const { accessToken } = await generateAccessByPersonalToken({
|
|
176
|
-
personalToken: token
|
|
177
|
-
});
|
|
178
|
-
const { email: userEmail } = decode(accessToken, accessTokenPayloadSchema);
|
|
179
|
-
output.info().message(loggedInMessage(userEmail)).print();
|
|
180
|
-
} catch (err) {
|
|
181
|
-
return output.error().title("Invalid token").message(err.message ?? "Please provide a valid personal token").exit("error");
|
|
182
|
-
}
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
if (email || password) {
|
|
186
|
-
if (!email || !password) {
|
|
187
|
-
return output.error().title("Please provide both email and password combination").message().exit("error");
|
|
188
|
-
}
|
|
189
|
-
try {
|
|
190
|
-
const { accessToken, refreshToken } = await emailPasswordAuth({
|
|
191
|
-
email,
|
|
192
|
-
password
|
|
193
|
-
});
|
|
194
|
-
await setAuthData({ accessToken, refreshToken });
|
|
195
|
-
output.info().message(loggedInMessage(email)).print();
|
|
196
|
-
} catch (err) {
|
|
197
|
-
output.error().title(err.message).exit("error");
|
|
198
|
-
}
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
let callbackEndpoint;
|
|
202
|
-
try {
|
|
203
|
-
callbackEndpoint = await generateTokenCallbackEndpoint(
|
|
204
|
-
`${config.services.api}/core/login/exchange`,
|
|
205
|
-
config.projects.dashboard
|
|
206
|
-
);
|
|
207
|
-
} catch (err) {
|
|
208
|
-
return output.error().title("Unable to start the login callback server").message(err.message).exit("error");
|
|
209
|
-
}
|
|
210
|
-
const { port, getTokens } = callbackEndpoint;
|
|
211
|
-
const loginUrl = `${config.projects.dashboard}/login?externalRedirect=local&port=${port}`;
|
|
212
|
-
output.info().message(`Please follow the link to login: ${as2.cyan(loginUrl)}`).print();
|
|
213
|
-
openBrowser(loginUrl);
|
|
214
|
-
try {
|
|
215
|
-
const tokenResult = await getTokens();
|
|
216
|
-
if (tokenResult.error) throw Error("Unable to exchange token");
|
|
217
|
-
await setAuthData(tokenResult.data);
|
|
218
|
-
const { email: userEmail } = decode(
|
|
219
|
-
tokenResult.data.accessToken,
|
|
220
|
-
accessTokenPayloadSchema
|
|
221
|
-
);
|
|
222
|
-
return output.info().message(loggedInMessage(userEmail)).exit("success");
|
|
223
|
-
} catch {
|
|
224
|
-
return output.error().title("Something went wrong. Please try again.").exit("error");
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
export {
|
|
228
|
-
loginAction
|
|
229
|
-
};
|