@scalar/cli 2.1.0 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -24
- package/chunks/{action-CYP4VDK3.js → action-37EV4UHW.js} +12 -35
- package/chunks/{action-MENXFJH3.js → action-4XI7XJR4.js} +9 -9
- package/chunks/{action-H5OHT2GV.js → action-5IU77OII.js} +7 -3
- package/chunks/{action-STIEAXOE.js → action-B3KKREWQ.js} +16 -5
- package/chunks/{action-BYZUBXVB.js → action-CH24QGTE.js} +8 -4
- package/chunks/action-F3UX5E3M.js +522 -0
- package/chunks/{action-GB6DM53B.js → action-FDB7NEOK.js} +21 -10
- package/chunks/action-FIXBOJEW.js +244 -0
- package/chunks/{action-DFKHSDFV.js → action-G26LSVZ7.js} +7 -3
- package/chunks/{action-Q5UJ32D6.js → action-H3RTILLM.js} +1 -1
- package/chunks/{action-GEBRPNRT.js → action-HGBBV353.js} +15 -16
- package/chunks/{action-5R5FDF6S.js → action-IUE4IOWO.js} +67 -22
- package/chunks/{action-TPBKPHNS.js → action-JZLZ7ZAD.js} +22 -22
- package/chunks/action-LA6KVAXQ.js +374 -0
- package/chunks/{action-PVDDRIM6.js → action-M7RQKBSB.js} +65 -26
- package/chunks/{action-F4Y6Q2VB.js → action-MSLBC2SO.js} +21 -21
- package/chunks/{action-BNEGJBUH.js → action-NVSZT2ZD.js} +8 -9
- package/chunks/{action-ANU5HGC4.js → action-OGQSTRMX.js} +17 -14
- package/chunks/{action-CLSD7O2R.js → action-PAGJ5PWC.js} +10 -10
- package/chunks/action-QE2ZQQX7.js +250 -0
- package/chunks/{action-HD2T6BFJ.js → action-QPUSPD5M.js} +10 -10
- package/chunks/{action-45OGQB2M.js → action-R7IMFHQ5.js} +17 -8
- package/chunks/{action-UDZUUJSI.js → action-SH4UUXPL.js} +18 -7
- package/chunks/action-SNLCIBQC.js +84 -0
- package/chunks/{action-C5VB4ITT.js → action-SQG3JAII.js} +36 -18
- package/chunks/action-UZQJNYK4.js +18 -0
- package/chunks/{action-HNKM3Q65.js → action-VC4DCVST.js} +17 -14
- package/chunks/{action-BMFXENMX.js → action-VTVFY2MP.js} +39 -34
- package/chunks/{action-TZ5KGAQT.js → action-WFWYGY7O.js} +17 -14
- package/chunks/{action-W5BATF4Q.js → action-XMNX5ZYT.js} +24 -24
- package/chunks/{agent-XGLOHXNA.js → agent-HCQRMHQ5.js} +25 -5
- package/chunks/asyncapi-QM76O55R.js +105 -0
- package/chunks/{build.action-LKOILPA6.js → build.action-P7FCIMYU.js} +22 -22
- package/chunks/{chunk-23I5PKZZ.js → chunk-24WAOKGG.js} +32 -5
- package/chunks/chunk-3L6DLIXJ.js +25530 -0
- package/chunks/chunk-3ZJYGGAA.js +30 -0
- package/chunks/{chunk-ZTVWAKNJ.js → chunk-4NHMAG6F.js} +1 -1
- package/chunks/{chunk-IX7LJ3AD.js → chunk-4ORL4MST.js} +2 -3
- package/chunks/{chunk-OAXFCOJV.js → chunk-4ZDQXWBT.js} +2 -1
- package/chunks/{chunk-ASMHW5AY.js → chunk-6ZMT63IV.js} +1 -1
- package/chunks/{chunk-P2VH7DOC.js → chunk-7AGLC7WV.js} +6 -6
- package/chunks/{chunk-SXYALPYK.js → chunk-AO3F5XWR.js} +498 -60
- package/chunks/{chunk-B6QZJWCQ.js → chunk-B2MHTD3R.js} +4 -6
- package/chunks/{chunk-4QS7SJTG.js → chunk-CISTON3A.js} +51 -36
- package/chunks/chunk-COBPBRQF.js +25 -0
- package/chunks/{chunk-2BSG2QHO.js → chunk-F467BYYR.js} +133 -20
- package/chunks/{chunk-TLFMATXR.js → chunk-GSGZHE26.js} +33 -25
- package/chunks/{chunk-UPUTMFD4.js → chunk-HCPN3KNF.js} +185 -13
- package/chunks/{chunk-P646T2WH.js → chunk-HPL3ZZ2P.js} +131 -13
- package/chunks/{chunk-H2WRMLYY.js → chunk-IKT5F47M.js} +3571 -7
- package/chunks/{chunk-AHWWJ3MD.js → chunk-K4DTP5TV.js} +1 -1
- package/chunks/{chunk-TQ5XC2E3.js → chunk-LFU5ZUAP.js} +77 -11
- package/chunks/{chunk-5BISXQX4.js → chunk-M37TP6U2.js} +11 -13
- package/chunks/chunk-OQKDBLOZ.js +741 -0
- package/chunks/chunk-P7H7GY5A.js +14 -0
- package/chunks/{chunk-47Y4L5IT.js → chunk-PBXZN65A.js} +1031 -481
- package/chunks/{chunk-HQKBZOYU.js → chunk-PT5TI77I.js} +3 -3
- package/chunks/chunk-Q7DOQHZN.js +404 -0
- package/chunks/{chunk-X4QLDBB5.js → chunk-T5HJUAWB.js} +24 -3
- package/chunks/{chunk-NUXPNUSS.js → chunk-UGGNHILG.js} +1 -1
- package/chunks/{chunk-4DGQIAJX.js → chunk-VNYE4R7N.js} +154 -14
- package/chunks/{chunk-KWOL7A6J.js → chunk-X5T526CE.js} +2 -2
- package/chunks/chunk-XCSR4RIT.js +210 -0
- package/chunks/{chunk-SHSHFGA7.js → chunk-Z2KMGFE6.js} +4 -6
- package/chunks/{create.action-FFQLBSJH.js → create.action-HDD2WUON.js} +22 -22
- package/chunks/{delete.action-STHQHP4F.js → delete.action-7GOZY7ID.js} +22 -22
- package/chunks/{delete.action-QNN3LC2F.js → delete.action-VE66JFDS.js} +22 -22
- package/chunks/{get.action-OTKYOP3Z.js → get.action-2745EB4N.js} +15 -16
- package/chunks/{list.action-KDM5RHEH.js → list.action-3VTXQJRA.js} +19 -19
- package/chunks/{list.action-6I5EZAVB.js → list.action-4QDCZLSZ.js} +22 -22
- package/chunks/{publish.action-PODTVRXS.js → publish.action-ULQLZKWU.js} +44 -36
- package/chunks/{update.action-KMD4ZM75.js → update.action-6QEFP7NA.js} +22 -22
- package/chunks/{update.action-4F6STTEQ.js → update.action-OROQSP2S.js} +22 -22
- package/docs.html +104 -103
- package/index.js +84 -68
- package/package.json +16 -12
- package/chunks/action-CCW66QJN.js +0 -72
- package/chunks/action-CQ56FVES.js +0 -65
- package/chunks/action-JOSVV6YA.js +0 -71
- package/chunks/action-P7LN6FGY.js +0 -13
- package/chunks/action-R6ZZO26F.js +0 -299
- package/chunks/action-TWFJNQ2R.js +0 -95
- package/chunks/chunk-5BPPGTUU.js +0 -463
- package/chunks/chunk-DOVIWNKQ.js +0 -108
- package/chunks/chunk-ISGLWBXZ.js +0 -4265
- package/chunks/chunk-T7MDADON.js +0 -17
- package/chunks/chunk-VTYTPSXO.js +0 -161
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
measureTime
|
|
4
|
+
} from "./chunk-KHDYYVYF.js";
|
|
5
|
+
import {
|
|
6
|
+
isAsyncApiDocument,
|
|
7
|
+
isDocument,
|
|
8
|
+
safeNormalize
|
|
9
|
+
} from "./chunk-24WAOKGG.js";
|
|
10
|
+
import {
|
|
11
|
+
require_dist
|
|
12
|
+
} from "./chunk-K74E42RV.js";
|
|
13
|
+
import "./chunk-CISTON3A.js";
|
|
14
|
+
import "./chunk-Q7DOQHZN.js";
|
|
15
|
+
import {
|
|
16
|
+
isYamlFileName
|
|
17
|
+
} from "./chunk-4ORL4MST.js";
|
|
18
|
+
import {
|
|
19
|
+
output
|
|
20
|
+
} from "./chunk-T5HJUAWB.js";
|
|
21
|
+
import "./chunk-GSGZHE26.js";
|
|
22
|
+
import {
|
|
23
|
+
external_exports
|
|
24
|
+
} from "./chunk-IKT5F47M.js";
|
|
25
|
+
import {
|
|
26
|
+
__toESM
|
|
27
|
+
} from "./chunk-3MZYUBJ6.js";
|
|
28
|
+
|
|
29
|
+
// src/domains/document/join/action.ts
|
|
30
|
+
var import_yaml = __toESM(require_dist(), 1);
|
|
31
|
+
import fs from "node:fs/promises";
|
|
32
|
+
import path from "node:path";
|
|
33
|
+
import as from "ansis";
|
|
34
|
+
import { bundle } from "@scalar/json-magic/bundle";
|
|
35
|
+
import { fetchUrls, readFiles } from "@scalar/json-magic/bundle/plugins/node";
|
|
36
|
+
import { join } from "@scalar/openapi-parser";
|
|
37
|
+
|
|
38
|
+
// src/domains/document/join/helpers.ts
|
|
39
|
+
import { getValueByPath as getValueByPathWithContext } from "@scalar/json-magic/helpers/get-value-by-path";
|
|
40
|
+
var getValueByPath = (input, path2) => {
|
|
41
|
+
return getValueByPathWithContext(input, path2).value;
|
|
42
|
+
};
|
|
43
|
+
var getPrefixes = (documents, path2) => {
|
|
44
|
+
const segments = path2.split(".");
|
|
45
|
+
return documents.map((doc) => {
|
|
46
|
+
const value = getValueByPath(doc, segments);
|
|
47
|
+
if (value === void 0) {
|
|
48
|
+
return "";
|
|
49
|
+
}
|
|
50
|
+
return String(value);
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// src/domains/document/join/asyncapi.ts
|
|
55
|
+
import { isDeepStrictEqual } from "node:util";
|
|
56
|
+
import { upgrade } from "@scalar/asyncapi-upgrader";
|
|
57
|
+
import { validate } from "@scalar/asyncapi-validator";
|
|
58
|
+
var escapePointer = (value) => value.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
59
|
+
var unescapePointer = (value) => value.replaceAll("~1", "/").replaceAll("~0", "~");
|
|
60
|
+
var prefixReferences = (value, prefix, section = "components") => {
|
|
61
|
+
if (Array.isArray(value))
|
|
62
|
+
return value.map((item) => prefixReferences(item, prefix, section));
|
|
63
|
+
if (!isDocument(value)) return value;
|
|
64
|
+
return Object.fromEntries(
|
|
65
|
+
Object.entries(value).map(([key, child]) => {
|
|
66
|
+
if (key === "$ref" && typeof child === "string" && child.startsWith(`#/${section}/`)) {
|
|
67
|
+
const segments = child.split("/");
|
|
68
|
+
const offset = section === "components" ? 3 : 2;
|
|
69
|
+
if (segments[offset])
|
|
70
|
+
segments[offset] = escapePointer(
|
|
71
|
+
prefix + unescapePointer(segments[offset])
|
|
72
|
+
);
|
|
73
|
+
return [key, segments.join("/")];
|
|
74
|
+
}
|
|
75
|
+
return [key, prefixReferences(child, prefix, section)];
|
|
76
|
+
})
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
var joinAsyncApi = (inputs, prefixes) => {
|
|
80
|
+
const conflicts = [];
|
|
81
|
+
const documents = inputs.map((input, index) => {
|
|
82
|
+
if (!validate(input).valid)
|
|
83
|
+
conflicts.push({
|
|
84
|
+
type: "asyncapi",
|
|
85
|
+
path: `input ${index + 1} is invalid`
|
|
86
|
+
});
|
|
87
|
+
const externalPrefix = `document${index}-`;
|
|
88
|
+
const document = prefixReferences(
|
|
89
|
+
upgrade(structuredClone(input)),
|
|
90
|
+
externalPrefix,
|
|
91
|
+
"x-ext"
|
|
92
|
+
);
|
|
93
|
+
if (isDocument(document["x-ext"])) {
|
|
94
|
+
document["x-ext"] = Object.fromEntries(
|
|
95
|
+
Object.entries(document["x-ext"]).map(([key, value]) => [
|
|
96
|
+
externalPrefix + key,
|
|
97
|
+
value
|
|
98
|
+
])
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
const prefix = prefixes[index] ?? "";
|
|
102
|
+
if (!prefix) return document;
|
|
103
|
+
const renamed = prefixReferences(document, prefix);
|
|
104
|
+
if (isDocument(renamed.components)) {
|
|
105
|
+
renamed.components = Object.fromEntries(
|
|
106
|
+
Object.entries(renamed.components).map(([kind, entries]) => [
|
|
107
|
+
kind,
|
|
108
|
+
isDocument(entries) ? Object.fromEntries(
|
|
109
|
+
Object.entries(entries).map(([name, value]) => [
|
|
110
|
+
prefix + name,
|
|
111
|
+
value
|
|
112
|
+
])
|
|
113
|
+
) : entries
|
|
114
|
+
])
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
return renamed;
|
|
118
|
+
});
|
|
119
|
+
const mergeNamed = (values, pointer) => {
|
|
120
|
+
const merged = /* @__PURE__ */ new Map();
|
|
121
|
+
for (const value of values) {
|
|
122
|
+
if (!isDocument(value)) continue;
|
|
123
|
+
for (const [name, entry] of Object.entries(value)) {
|
|
124
|
+
if (merged.has(name) && !isDeepStrictEqual(merged.get(name), entry)) {
|
|
125
|
+
conflicts.push({
|
|
126
|
+
type: "asyncapi",
|
|
127
|
+
path: `${pointer}/${escapePointer(name)}`
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
merged.set(name, entry);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return Object.fromEntries(merged);
|
|
134
|
+
};
|
|
135
|
+
const namedSections = ["channels", "operations", "servers", "x-ext"];
|
|
136
|
+
const separatelyMerged = /* @__PURE__ */ new Set(["info", "components", ...namedSections]);
|
|
137
|
+
const result = mergeNamed(
|
|
138
|
+
documents.map(
|
|
139
|
+
(document) => Object.fromEntries(
|
|
140
|
+
Object.entries(document).filter(([key]) => !separatelyMerged.has(key))
|
|
141
|
+
)
|
|
142
|
+
),
|
|
143
|
+
"#"
|
|
144
|
+
);
|
|
145
|
+
result.info = Object.assign(
|
|
146
|
+
{},
|
|
147
|
+
...[...documents].reverse().map((document) => document.info)
|
|
148
|
+
);
|
|
149
|
+
for (const section of namedSections) {
|
|
150
|
+
result[section] = mergeNamed(
|
|
151
|
+
documents.map((document) => document[section]),
|
|
152
|
+
`#/${section}`
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
const componentKinds = new Set(
|
|
156
|
+
documents.flatMap(
|
|
157
|
+
(document) => isDocument(document.components) ? Object.keys(document.components) : []
|
|
158
|
+
)
|
|
159
|
+
);
|
|
160
|
+
result.components = Object.fromEntries(
|
|
161
|
+
[...componentKinds].map((kind) => [
|
|
162
|
+
kind,
|
|
163
|
+
mergeNamed(
|
|
164
|
+
documents.map(
|
|
165
|
+
(document) => isDocument(document.components) ? document.components[kind] : void 0
|
|
166
|
+
),
|
|
167
|
+
`#/components/${escapePointer(kind)}`
|
|
168
|
+
)
|
|
169
|
+
])
|
|
170
|
+
);
|
|
171
|
+
return conflicts.length ? { ok: false, conflicts } : { ok: true, document: result };
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// src/domains/document/join/action.ts
|
|
175
|
+
var formatErrorMessage = (conflicts) => {
|
|
176
|
+
return conflicts.map((conflict) => {
|
|
177
|
+
if (conflict.type === "asyncapi")
|
|
178
|
+
return `AsyncAPI conflict at ${conflict.path}`;
|
|
179
|
+
if (conflict.type === "component") {
|
|
180
|
+
return `Component '/${conflict.componentType}/${conflict.name}' has conflicts`;
|
|
181
|
+
}
|
|
182
|
+
if (conflict.type === "path") {
|
|
183
|
+
return `Path '${conflict.path} ${conflict.method}' has conflicts`;
|
|
184
|
+
}
|
|
185
|
+
return `Webhook '${conflict.path} ${conflict.method}' has conflicts`;
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
async function joinAction(rawInput, rawOpt) {
|
|
189
|
+
const { error, data: input } = external_exports.array(external_exports.string()).safeParse(rawInput);
|
|
190
|
+
if (error) {
|
|
191
|
+
return output.error().title("Invalid input").message(error.issues[0].message).exit("error");
|
|
192
|
+
}
|
|
193
|
+
const { error: optsError, data: opts } = external_exports.object({
|
|
194
|
+
output: external_exports.string(),
|
|
195
|
+
prefixComponentsWithPathValue: external_exports.string().optional()
|
|
196
|
+
}).safeParse(rawOpt);
|
|
197
|
+
if (optsError) {
|
|
198
|
+
return output.error().title("Invalid options").line("").line(
|
|
199
|
+
optsError.issues.map((e) => `${e.message} property: '${e.path}'`).join("\n")
|
|
200
|
+
).line("").exit("error");
|
|
201
|
+
}
|
|
202
|
+
const files = (await Promise.all(input.map((file) => fs.readFile(file, "utf-8")))).map((it) => {
|
|
203
|
+
const document = safeNormalize(it);
|
|
204
|
+
if (!isDocument(document)) {
|
|
205
|
+
return output.error().title("Invalid input").message(
|
|
206
|
+
"Could not read an API document from one of the input files. Please provide valid JSON or YAML files."
|
|
207
|
+
).exit("error");
|
|
208
|
+
}
|
|
209
|
+
return document;
|
|
210
|
+
});
|
|
211
|
+
const asyncApiCount = files.filter(isAsyncApiDocument).length;
|
|
212
|
+
if (asyncApiCount > 0 && asyncApiCount !== files.length) {
|
|
213
|
+
return output.error().title("Cannot join OpenAPI and AsyncAPI documents together").exit("error");
|
|
214
|
+
}
|
|
215
|
+
const specification = asyncApiCount ? "AsyncAPI" : "OpenAPI";
|
|
216
|
+
const documents = asyncApiCount ? await Promise.all(
|
|
217
|
+
input.map(async (file) => {
|
|
218
|
+
const document = await bundle(path.resolve(file), {
|
|
219
|
+
plugins: [readFiles(), fetchUrls()],
|
|
220
|
+
treeShake: false
|
|
221
|
+
});
|
|
222
|
+
if (!isDocument(document)) {
|
|
223
|
+
return output.error().title("Invalid input").message(
|
|
224
|
+
"Could not read an API document from one of the input files. Please provide valid JSON or YAML files."
|
|
225
|
+
).exit("error");
|
|
226
|
+
}
|
|
227
|
+
return document;
|
|
228
|
+
})
|
|
229
|
+
) : files;
|
|
230
|
+
const prefixes = opts.prefixComponentsWithPathValue ? getPrefixes(files, opts.prefixComponentsWithPathValue) : [];
|
|
231
|
+
const { executionTimeMs, result } = await measureTime(
|
|
232
|
+
async () => asyncApiCount ? joinAsyncApi(documents, prefixes) : await join(files, { prefixComponents: prefixes })
|
|
233
|
+
);
|
|
234
|
+
if (!result.ok) {
|
|
235
|
+
return output.error().title(`Failed to join ${specification} documents`).line().line(`Conflicts:
|
|
236
|
+
${formatErrorMessage(result.conflicts).join("\n")}`).line().exit("error");
|
|
237
|
+
}
|
|
238
|
+
const isYaml = isYamlFileName(opts.output);
|
|
239
|
+
await fs.writeFile(
|
|
240
|
+
opts.output,
|
|
241
|
+
isYaml ? import_yaml.default.stringify(result.document) : JSON.stringify(result.document, null, 2),
|
|
242
|
+
"utf8"
|
|
243
|
+
);
|
|
244
|
+
output.info().message(
|
|
245
|
+
`${as.green(`\u{1F91D} ${specification} Documents joined`)} in ${as.white(`${as.bold(`${Math.round(executionTimeMs)}`)} ms`)}`
|
|
246
|
+
).print();
|
|
247
|
+
}
|
|
248
|
+
export {
|
|
249
|
+
joinAction
|
|
250
|
+
};
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
getUserTeams
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-6ZMT63IV.js";
|
|
5
5
|
import {
|
|
6
6
|
getDatabaseClient
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-Z2KMGFE6.js";
|
|
8
|
+
import "./chunk-B2MHTD3R.js";
|
|
9
9
|
import {
|
|
10
10
|
getAuthData
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import "./chunk-
|
|
13
|
-
import "./chunk-
|
|
14
|
-
import "./chunk-
|
|
15
|
-
import "./chunk-
|
|
16
|
-
import "./chunk-IX7LJ3AD.js";
|
|
11
|
+
} from "./chunk-M37TP6U2.js";
|
|
12
|
+
import "./chunk-4ZDQXWBT.js";
|
|
13
|
+
import "./chunk-VNYE4R7N.js";
|
|
14
|
+
import "./chunk-OQKDBLOZ.js";
|
|
15
|
+
import "./chunk-4ORL4MST.js";
|
|
17
16
|
import {
|
|
18
17
|
output,
|
|
19
18
|
printTable
|
|
20
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-T5HJUAWB.js";
|
|
20
|
+
import "./chunk-IKT5F47M.js";
|
|
21
21
|
import "./chunk-3MZYUBJ6.js";
|
|
22
22
|
|
|
23
23
|
// src/domains/team/list/action.ts
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
2
|
import {
|
|
3
|
+
getFileOrUrl,
|
|
4
|
+
isAsyncApiContent,
|
|
3
5
|
loadOpenApiFile,
|
|
4
6
|
printSpecificationBanner
|
|
5
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-24WAOKGG.js";
|
|
6
8
|
import {
|
|
7
9
|
watchFile
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
11
|
-
import "./chunk-
|
|
12
|
-
import "./chunk-
|
|
13
|
-
import "./chunk-
|
|
10
|
+
} from "./chunk-M37TP6U2.js";
|
|
11
|
+
import "./chunk-4ZDQXWBT.js";
|
|
12
|
+
import "./chunk-VNYE4R7N.js";
|
|
13
|
+
import "./chunk-OQKDBLOZ.js";
|
|
14
|
+
import "./chunk-CISTON3A.js";
|
|
15
|
+
import "./chunk-Q7DOQHZN.js";
|
|
16
|
+
import "./chunk-4ORL4MST.js";
|
|
14
17
|
import {
|
|
15
18
|
output
|
|
16
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-T5HJUAWB.js";
|
|
20
|
+
import "./chunk-GSGZHE26.js";
|
|
21
|
+
import "./chunk-IKT5F47M.js";
|
|
17
22
|
import "./chunk-3MZYUBJ6.js";
|
|
18
23
|
|
|
19
24
|
// src/domains/document/mock/action.ts
|
|
@@ -87,6 +92,10 @@ function getMethodColor(method) {
|
|
|
87
92
|
|
|
88
93
|
// src/domains/document/mock/action.ts
|
|
89
94
|
async function mockAction(fileArgument, { watch, once, port }) {
|
|
95
|
+
if (isAsyncApiContent(await getFileOrUrl(fileArgument))) {
|
|
96
|
+
const { mockAsyncApi } = await import("./asyncapi-QM76O55R.js");
|
|
97
|
+
return mockAsyncApi(fileArgument, { watch, once, port });
|
|
98
|
+
}
|
|
90
99
|
let server;
|
|
91
100
|
const result = await loadOpenApiFile(fileArgument);
|
|
92
101
|
if (!result.valid) {
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
2
|
import {
|
|
3
|
-
getFileOrUrl
|
|
4
|
-
|
|
3
|
+
getFileOrUrl,
|
|
4
|
+
isDocument,
|
|
5
|
+
safeNormalize
|
|
6
|
+
} from "./chunk-24WAOKGG.js";
|
|
5
7
|
import {
|
|
6
8
|
require_dist
|
|
7
9
|
} from "./chunk-K74E42RV.js";
|
|
10
|
+
import "./chunk-CISTON3A.js";
|
|
11
|
+
import "./chunk-Q7DOQHZN.js";
|
|
8
12
|
import {
|
|
9
13
|
isUrl,
|
|
10
14
|
isYamlFileName
|
|
11
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-4ORL4MST.js";
|
|
12
16
|
import {
|
|
13
17
|
output
|
|
14
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-T5HJUAWB.js";
|
|
19
|
+
import "./chunk-GSGZHE26.js";
|
|
20
|
+
import "./chunk-IKT5F47M.js";
|
|
15
21
|
import {
|
|
16
22
|
__toESM
|
|
17
23
|
} from "./chunk-3MZYUBJ6.js";
|
|
@@ -20,14 +26,19 @@ import {
|
|
|
20
26
|
var import_yaml = __toESM(require_dist(), 1);
|
|
21
27
|
import fs from "node:fs";
|
|
22
28
|
import as from "ansis";
|
|
23
|
-
import { normalize, toJson } from "@scalar/openapi-parser";
|
|
24
29
|
async function formatAction(inputArgument, { output: outputPath }) {
|
|
25
30
|
const startTime = performance.now();
|
|
26
31
|
if (!inputArgument) {
|
|
27
32
|
return output.error().title("Invalid argument").message("Please provide a file path").exit("error");
|
|
28
33
|
}
|
|
29
|
-
const
|
|
30
|
-
const
|
|
34
|
+
const content = await getFileOrUrl(inputArgument);
|
|
35
|
+
const document = safeNormalize(content);
|
|
36
|
+
if (!isDocument(document)) {
|
|
37
|
+
return output.error().title("Invalid input").message(
|
|
38
|
+
"Could not read a document from the input. Please provide a valid JSON or YAML file."
|
|
39
|
+
).exit("error");
|
|
40
|
+
}
|
|
41
|
+
const newContent = isYamlFileName(outputPath || inputArgument) ? (0, import_yaml.stringify)(document) : JSON.stringify(document, null, 2);
|
|
31
42
|
if (outputPath) {
|
|
32
43
|
fs.writeFileSync(outputPath, newContent, "utf8");
|
|
33
44
|
} else if (!isUrl(inputArgument)) {
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
getFileOrUrl,
|
|
4
|
+
isAsyncApiContent
|
|
5
|
+
} from "./chunk-24WAOKGG.js";
|
|
6
|
+
import {
|
|
7
|
+
config
|
|
8
|
+
} from "./chunk-4ZDQXWBT.js";
|
|
9
|
+
import "./chunk-CISTON3A.js";
|
|
10
|
+
import "./chunk-Q7DOQHZN.js";
|
|
11
|
+
import "./chunk-4ORL4MST.js";
|
|
12
|
+
import {
|
|
13
|
+
output
|
|
14
|
+
} from "./chunk-T5HJUAWB.js";
|
|
15
|
+
import "./chunk-GSGZHE26.js";
|
|
16
|
+
import "./chunk-IKT5F47M.js";
|
|
17
|
+
import "./chunk-3MZYUBJ6.js";
|
|
18
|
+
|
|
19
|
+
// src/domains/document/share/action.ts
|
|
20
|
+
import as from "ansis";
|
|
21
|
+
async function shareAction(fileArgument, { token }) {
|
|
22
|
+
if (!fileArgument) {
|
|
23
|
+
return output.error().title("Invalid argument").message("Please provide a file path").exit("error");
|
|
24
|
+
}
|
|
25
|
+
const content = await getFileOrUrl(fileArgument);
|
|
26
|
+
const specification = isAsyncApiContent(content) ? "AsyncAPI" : "OpenAPI";
|
|
27
|
+
const sandboxUrl = new URL(config.projects.sandbox);
|
|
28
|
+
const url = new URL("/api/share", sandboxUrl);
|
|
29
|
+
url.pathname = "/api/share";
|
|
30
|
+
if (token) {
|
|
31
|
+
url.searchParams.append("token", token);
|
|
32
|
+
}
|
|
33
|
+
return fetch(url.toString(), {
|
|
34
|
+
method: "POST",
|
|
35
|
+
headers: {
|
|
36
|
+
"Content-Type": "application/json"
|
|
37
|
+
},
|
|
38
|
+
body: JSON.stringify({
|
|
39
|
+
content
|
|
40
|
+
})
|
|
41
|
+
}).then(async (response) => {
|
|
42
|
+
if (!response.ok)
|
|
43
|
+
throw new Error(`Sandbox returned HTTP ${response.status}`);
|
|
44
|
+
return response.json();
|
|
45
|
+
}).then((data) => {
|
|
46
|
+
if (data === null || typeof data !== "object" || Array.isArray(data)) {
|
|
47
|
+
throw new Error("Invalid sandbox response");
|
|
48
|
+
}
|
|
49
|
+
if (data.error || typeof data.id !== "string" || typeof data.token !== "string") {
|
|
50
|
+
throw new Error(data.message || "Invalid sandbox response");
|
|
51
|
+
}
|
|
52
|
+
const { id, token: newToken } = data;
|
|
53
|
+
const link = (pathname) => new URL(pathname, sandboxUrl).toString();
|
|
54
|
+
output.info().line(as.green.bold(`Your ${specification} file is public.`)).line().table(
|
|
55
|
+
[
|
|
56
|
+
[
|
|
57
|
+
`${as.green("\u279C")} ${as.white.bold("API Reference:")}`,
|
|
58
|
+
as.cyan(link(`/p/${id}`))
|
|
59
|
+
],
|
|
60
|
+
[
|
|
61
|
+
`${as.grey("\u279C")} ${as.grey.bold("Editor:")}`,
|
|
62
|
+
as.cyan(link(`/e/${id}`))
|
|
63
|
+
],
|
|
64
|
+
[],
|
|
65
|
+
[
|
|
66
|
+
`${as.grey("\u279C")} ${as.grey.bold(`${specification} JSON:`)}`,
|
|
67
|
+
as.cyan(link(`/files/${id}/openapi.json`))
|
|
68
|
+
],
|
|
69
|
+
[
|
|
70
|
+
`${as.grey("\u279C")} ${as.grey.bold(`${specification} YAML:`)}`,
|
|
71
|
+
as.cyan(link(`/files/${id}/openapi.yaml`))
|
|
72
|
+
]
|
|
73
|
+
],
|
|
74
|
+
{ padding: 1 }
|
|
75
|
+
).line().line("Use the token to update the existing sandbox:").line().line(
|
|
76
|
+
`${as.grey("$")} ${as.white.bold("scalar document share --token=")}${as.cyan.bold(`${newToken}`)} `
|
|
77
|
+
).line().print();
|
|
78
|
+
}).catch((error) => {
|
|
79
|
+
output.error().title("Failed to share the file.").message(`Details: ${error}`).exit("error");
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
export {
|
|
83
|
+
shareAction
|
|
84
|
+
};
|
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
downloadIsolate
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-LFU5ZUAP.js";
|
|
5
|
+
import "./chunk-3ZJYGGAA.js";
|
|
5
6
|
import {
|
|
6
7
|
readAndParseConfig,
|
|
7
8
|
renderConfigError
|
|
8
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-7AGLC7WV.js";
|
|
9
10
|
import {
|
|
10
11
|
CONFIG_FILE_DEFAULT,
|
|
11
12
|
findConfig
|
|
12
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-PBXZN65A.js";
|
|
13
14
|
import {
|
|
14
15
|
ISOLATE_DIR
|
|
15
|
-
} from "./chunk-
|
|
16
|
-
import "./chunk-5BPPGTUU.js";
|
|
17
|
-
import "./chunk-4QS7SJTG.js";
|
|
18
|
-
import "./chunk-VTYTPSXO.js";
|
|
16
|
+
} from "./chunk-X5T526CE.js";
|
|
19
17
|
import {
|
|
20
18
|
getAuthData
|
|
21
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-M37TP6U2.js";
|
|
22
20
|
import {
|
|
23
21
|
config
|
|
24
|
-
} from "./chunk-
|
|
25
|
-
import "./chunk-
|
|
26
|
-
import "./chunk-4DGQIAJX.js";
|
|
22
|
+
} from "./chunk-4ZDQXWBT.js";
|
|
23
|
+
import "./chunk-VNYE4R7N.js";
|
|
27
24
|
import {
|
|
28
25
|
ConfigVersion
|
|
29
|
-
} from "./chunk-
|
|
30
|
-
import "./chunk-H2WRMLYY.js";
|
|
26
|
+
} from "./chunk-OQKDBLOZ.js";
|
|
31
27
|
import "./chunk-K74E42RV.js";
|
|
32
|
-
import "./chunk-
|
|
28
|
+
import "./chunk-CISTON3A.js";
|
|
29
|
+
import "./chunk-Q7DOQHZN.js";
|
|
30
|
+
import "./chunk-4ORL4MST.js";
|
|
33
31
|
import {
|
|
34
32
|
output
|
|
35
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-T5HJUAWB.js";
|
|
34
|
+
import "./chunk-GSGZHE26.js";
|
|
35
|
+
import "./chunk-IKT5F47M.js";
|
|
36
36
|
import "./chunk-3MZYUBJ6.js";
|
|
37
37
|
|
|
38
38
|
// src/domains/project/preview/action.ts
|
|
@@ -43,13 +43,31 @@ import as from "ansis";
|
|
|
43
43
|
import { spawn } from "node:child_process";
|
|
44
44
|
import path from "node:path";
|
|
45
45
|
async function runIsolate(isolateOptions) {
|
|
46
|
-
const
|
|
46
|
+
const executable = process.env.SCALAR_CLI_DISTRIBUTION === "portable" ? path.join(
|
|
47
|
+
path.dirname(process.execPath),
|
|
48
|
+
"runtime",
|
|
49
|
+
process.platform === "win32" ? "node.exe" : "node"
|
|
50
|
+
) : process.execPath;
|
|
51
|
+
const child = spawn(executable, ["dist/isolate-entry.js"], {
|
|
52
|
+
cwd: ISOLATE_DIR,
|
|
53
|
+
env: {
|
|
54
|
+
...process.env,
|
|
55
|
+
PATH: `${path.dirname(executable)}${path.delimiter}${process.env.PATH ?? ""}`
|
|
56
|
+
}
|
|
57
|
+
});
|
|
47
58
|
child.stdin.write(JSON.stringify(isolateOptions));
|
|
48
59
|
child.stdin.end();
|
|
49
60
|
child.stdout.pipe(process.stdout);
|
|
50
61
|
child.stderr.pipe(process.stderr);
|
|
51
|
-
child.on("
|
|
52
|
-
console.
|
|
62
|
+
child.on("error", (error) => {
|
|
63
|
+
console.error(`Could not start docs preview: ${error.message}`);
|
|
64
|
+
process.exitCode = 1;
|
|
65
|
+
});
|
|
66
|
+
child.on("close", (code, signal) => {
|
|
67
|
+
console.log(
|
|
68
|
+
`Process exited with code ${code}${signal ? ` (signal ${signal})` : ""}.`
|
|
69
|
+
);
|
|
70
|
+
process.exitCode = code ?? 1;
|
|
53
71
|
});
|
|
54
72
|
}
|
|
55
73
|
async function getAccessToken() {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
IsolateDownloadError,
|
|
4
|
+
downloadIsolate,
|
|
5
|
+
isDiskWriteError,
|
|
6
|
+
updateIsolate
|
|
7
|
+
} from "./chunk-LFU5ZUAP.js";
|
|
8
|
+
import "./chunk-3ZJYGGAA.js";
|
|
9
|
+
import "./chunk-X5T526CE.js";
|
|
10
|
+
import "./chunk-4ZDQXWBT.js";
|
|
11
|
+
import "./chunk-T5HJUAWB.js";
|
|
12
|
+
import "./chunk-3MZYUBJ6.js";
|
|
13
|
+
export {
|
|
14
|
+
IsolateDownloadError,
|
|
15
|
+
downloadIsolate,
|
|
16
|
+
isDiskWriteError,
|
|
17
|
+
updateIsolate
|
|
18
|
+
};
|
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
apiService
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
11
|
-
import "./chunk-
|
|
12
|
-
import "./chunk-
|
|
13
|
-
import "./chunk-
|
|
14
|
-
import "./chunk-
|
|
15
|
-
import "./chunk-
|
|
16
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-AO3F5XWR.js";
|
|
5
|
+
import "./chunk-HCPN3KNF.js";
|
|
6
|
+
import "./chunk-B2MHTD3R.js";
|
|
7
|
+
import "./chunk-3L6DLIXJ.js";
|
|
8
|
+
import "./chunk-P7H7GY5A.js";
|
|
9
|
+
import "./chunk-HPL3ZZ2P.js";
|
|
10
|
+
import "./chunk-M37TP6U2.js";
|
|
11
|
+
import "./chunk-4ZDQXWBT.js";
|
|
12
|
+
import "./chunk-VNYE4R7N.js";
|
|
13
|
+
import "./chunk-OQKDBLOZ.js";
|
|
14
|
+
import "./chunk-K74E42RV.js";
|
|
15
|
+
import "./chunk-CISTON3A.js";
|
|
16
|
+
import "./chunk-Q7DOQHZN.js";
|
|
17
|
+
import "./chunk-4ORL4MST.js";
|
|
17
18
|
import {
|
|
18
19
|
output
|
|
19
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-T5HJUAWB.js";
|
|
21
|
+
import "./chunk-GSGZHE26.js";
|
|
22
|
+
import "./chunk-IKT5F47M.js";
|
|
20
23
|
import "./chunk-3MZYUBJ6.js";
|
|
21
24
|
|
|
22
25
|
// src/domains/project/create/action.ts
|