@scalar/cli 2.0.1 → 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.
Files changed (83) hide show
  1. package/README.md +68 -24
  2. package/chunks/action-37EV4UHW.js +125 -0
  3. package/chunks/action-4XI7XJR4.js +204 -0
  4. package/chunks/action-5IU77OII.js +60 -0
  5. package/chunks/action-B3KKREWQ.js +64 -0
  6. package/chunks/action-CH24QGTE.js +86 -0
  7. package/chunks/action-F3UX5E3M.js +522 -0
  8. package/chunks/action-FDB7NEOK.js +81 -0
  9. package/chunks/action-FIXBOJEW.js +244 -0
  10. package/chunks/action-G26LSVZ7.js +40 -0
  11. package/chunks/action-H3RTILLM.js +46 -0
  12. package/chunks/action-HGBBV353.js +86 -0
  13. package/chunks/action-IUE4IOWO.js +2142 -0
  14. package/chunks/action-JZLZ7ZAD.js +110 -0
  15. package/chunks/action-LA6KVAXQ.js +374 -0
  16. package/chunks/action-M7RQKBSB.js +169 -0
  17. package/chunks/action-MSLBC2SO.js +92 -0
  18. package/chunks/action-NVSZT2ZD.js +37 -0
  19. package/chunks/action-OGQSTRMX.js +37 -0
  20. package/chunks/action-PAGJ5PWC.js +60 -0
  21. package/chunks/action-QE2ZQQX7.js +250 -0
  22. package/chunks/action-QPUSPD5M.js +54 -0
  23. package/chunks/action-R7IMFHQ5.js +147 -0
  24. package/chunks/action-SH4UUXPL.js +60 -0
  25. package/chunks/action-SNLCIBQC.js +84 -0
  26. package/chunks/action-SQG3JAII.js +150 -0
  27. package/chunks/action-UZQJNYK4.js +18 -0
  28. package/chunks/action-VC4DCVST.js +68 -0
  29. package/chunks/action-VTVFY2MP.js +181 -0
  30. package/chunks/action-WFWYGY7O.js +67 -0
  31. package/chunks/action-XMNX5ZYT.js +197 -0
  32. package/chunks/agent-HCQRMHQ5.js +132 -0
  33. package/chunks/asyncapi-QM76O55R.js +105 -0
  34. package/chunks/build.action-P7FCIMYU.js +108 -0
  35. package/chunks/chunk-24WAOKGG.js +105 -0
  36. package/chunks/chunk-3L6DLIXJ.js +25530 -0
  37. package/chunks/chunk-3MZYUBJ6.js +49 -0
  38. package/chunks/chunk-3ZJYGGAA.js +30 -0
  39. package/chunks/chunk-4NHMAG6F.js +21 -0
  40. package/chunks/chunk-4ORL4MST.js +16 -0
  41. package/chunks/chunk-4ZDQXWBT.js +26 -0
  42. package/chunks/chunk-6ZMT63IV.js +19 -0
  43. package/chunks/chunk-7AGLC7WV.js +107 -0
  44. package/chunks/chunk-AEFPCC4U.js +16 -0
  45. package/chunks/chunk-AO3F5XWR.js +3147 -0
  46. package/chunks/chunk-B2MHTD3R.js +90 -0
  47. package/chunks/chunk-CISTON3A.js +153 -0
  48. package/chunks/chunk-COBPBRQF.js +25 -0
  49. package/chunks/chunk-F467BYYR.js +568 -0
  50. package/chunks/chunk-GSGZHE26.js +352 -0
  51. package/chunks/chunk-HCPN3KNF.js +637 -0
  52. package/chunks/chunk-HPL3ZZ2P.js +1726 -0
  53. package/chunks/chunk-IKT5F47M.js +17344 -0
  54. package/chunks/chunk-JFIXNSPP.js +26 -0
  55. package/chunks/chunk-K4DTP5TV.js +32 -0
  56. package/chunks/chunk-K74E42RV.js +7311 -0
  57. package/chunks/chunk-KHDYYVYF.js +16 -0
  58. package/chunks/chunk-LFU5ZUAP.js +350 -0
  59. package/chunks/chunk-M37TP6U2.js +445 -0
  60. package/chunks/chunk-OQKDBLOZ.js +741 -0
  61. package/chunks/chunk-P7H7GY5A.js +14 -0
  62. package/chunks/chunk-PBXZN65A.js +63911 -0
  63. package/chunks/chunk-PT5TI77I.js +34 -0
  64. package/chunks/chunk-Q7DOQHZN.js +404 -0
  65. package/chunks/chunk-T5HJUAWB.js +242 -0
  66. package/chunks/chunk-T7B6WNZC.js +18 -0
  67. package/chunks/chunk-UGGNHILG.js +38 -0
  68. package/chunks/chunk-VNYE4R7N.js +499 -0
  69. package/chunks/chunk-X5T526CE.js +23 -0
  70. package/chunks/chunk-XCSR4RIT.js +210 -0
  71. package/chunks/chunk-Z2KMGFE6.js +295 -0
  72. package/chunks/create.action-HDD2WUON.js +108 -0
  73. package/chunks/delete.action-7GOZY7ID.js +88 -0
  74. package/chunks/delete.action-VE66JFDS.js +96 -0
  75. package/chunks/get.action-2745EB4N.js +86 -0
  76. package/chunks/list.action-3VTXQJRA.js +116 -0
  77. package/chunks/list.action-4QDCZLSZ.js +95 -0
  78. package/chunks/publish.action-ULQLZKWU.js +190 -0
  79. package/chunks/update.action-6QEFP7NA.js +95 -0
  80. package/chunks/update.action-OROQSP2S.js +101 -0
  81. package/docs.html +352 -250
  82. package/index.js +664 -99064
  83. package/package.json +17 -11
@@ -0,0 +1,92 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ apiService
4
+ } from "./chunk-AO3F5XWR.js";
5
+ import {
6
+ BaseCollections
7
+ } from "./chunk-F467BYYR.js";
8
+ import {
9
+ getDatabaseClient
10
+ } from "./chunk-Z2KMGFE6.js";
11
+ import "./chunk-HCPN3KNF.js";
12
+ import "./chunk-B2MHTD3R.js";
13
+ import "./chunk-3L6DLIXJ.js";
14
+ import "./chunk-P7H7GY5A.js";
15
+ import "./chunk-HPL3ZZ2P.js";
16
+ import {
17
+ getAuthData
18
+ } from "./chunk-M37TP6U2.js";
19
+ import "./chunk-4ZDQXWBT.js";
20
+ import {
21
+ teamSchema
22
+ } from "./chunk-VNYE4R7N.js";
23
+ import "./chunk-OQKDBLOZ.js";
24
+ import "./chunk-K74E42RV.js";
25
+ import "./chunk-CISTON3A.js";
26
+ import "./chunk-Q7DOQHZN.js";
27
+ import "./chunk-4ORL4MST.js";
28
+ import {
29
+ output,
30
+ printTable
31
+ } from "./chunk-T5HJUAWB.js";
32
+ import "./chunk-GSGZHE26.js";
33
+ import {
34
+ external_exports,
35
+ namespaceSchema
36
+ } from "./chunk-IKT5F47M.js";
37
+ import "./chunk-3MZYUBJ6.js";
38
+
39
+ // src/domains/registry/list/action.ts
40
+ import as from "ansis";
41
+ async function listAction(args) {
42
+ const { error, data } = external_exports.object({
43
+ namespace: namespaceSchema.optional()
44
+ }).safeParse({
45
+ namespace: args.namespace
46
+ });
47
+ if (error)
48
+ return output.error().title("Invalid input").message(error.issues[0].message).exit("error");
49
+ const auth = await getAuthData();
50
+ auth.addEventListener((state) => Object.assign(auth, state));
51
+ const client = await getDatabaseClient();
52
+ const team = await client.getOne({
53
+ collectionPath: BaseCollections.Teams,
54
+ query: {
55
+ uid: auth.teamUid
56
+ },
57
+ schema: teamSchema
58
+ });
59
+ if (team.error)
60
+ return output.error().title("An error occurred when fetching your team.").message(team.message).exit("error");
61
+ const namespace = data.namespace || team.data.namespaces.at(0);
62
+ if (!namespace) {
63
+ return output.error().title("Missing namespace").message(
64
+ "Could not find a valid namespace for your API. Please specify a namespace or contact support."
65
+ ).exit("error");
66
+ }
67
+ const apiClient = await apiService();
68
+ const listApisRes = await apiClient.managedDocs.getApiDocs(namespace);
69
+ if (listApisRes.error)
70
+ return output.error().title(listApisRes.message).exit("error");
71
+ if (listApisRes.data.length === 0) {
72
+ output.info().title(`No registry APIs found for namespace "${namespace}".`).print();
73
+ return;
74
+ }
75
+ printTable(
76
+ [
77
+ { name: "title", title: "Title", alignment: "left", maxLen: 40 },
78
+ { name: "name", title: "Name", alignment: "left", color: "blue" },
79
+ { name: "version", title: "Version", alignment: "left" },
80
+ { name: "access", title: "Access", alignment: "left" }
81
+ ],
82
+ listApisRes.data.map((api) => ({
83
+ title: api.title || as.dim("\u2014"),
84
+ name: `@${api.namespace}/${api.slug}`,
85
+ version: api.version,
86
+ access: api.isPrivate ? as.green("Private") : as.yellow("Public")
87
+ }))
88
+ );
89
+ }
90
+ export {
91
+ listAction
92
+ };
@@ -0,0 +1,37 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ readAndParseConfig,
4
+ renderConfigError
5
+ } from "./chunk-7AGLC7WV.js";
6
+ import "./chunk-PBXZN65A.js";
7
+ import "./chunk-OQKDBLOZ.js";
8
+ import "./chunk-K74E42RV.js";
9
+ import "./chunk-CISTON3A.js";
10
+ import "./chunk-Q7DOQHZN.js";
11
+ import {
12
+ output
13
+ } from "./chunk-T5HJUAWB.js";
14
+ import "./chunk-GSGZHE26.js";
15
+ import "./chunk-IKT5F47M.js";
16
+ import "./chunk-3MZYUBJ6.js";
17
+
18
+ // src/domains/project/check-config/action.ts
19
+ import as from "ansis";
20
+ async function checkConfigAction(inputArgument) {
21
+ const result = readAndParseConfig(inputArgument);
22
+ if (result.success) {
23
+ output.info().line(
24
+ `${as.green("[SUCCESS]")} ${as.green("The Scalar Configuration is valid:")} ${as.green(result.filePath)}`
25
+ ).line(
26
+ `${as.green("Scalar Configuration validated")} ${as.grey(
27
+ `in ${as.white.bold(`${result.validationTime} ms`)}`
28
+ )}
29
+ `
30
+ ).print();
31
+ } else {
32
+ renderConfigError(result.error);
33
+ }
34
+ }
35
+ export {
36
+ checkConfigAction
37
+ };
@@ -0,0 +1,37 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ apiService
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";
18
+ import {
19
+ output
20
+ } from "./chunk-T5HJUAWB.js";
21
+ import "./chunk-GSGZHE26.js";
22
+ import "./chunk-IKT5F47M.js";
23
+ import "./chunk-3MZYUBJ6.js";
24
+
25
+ // src/domains/registry/delete/action.ts
26
+ async function deleteAction(namespace, slug) {
27
+ const client = await apiService();
28
+ const logger = output.info().line().loader("Deleting the api document");
29
+ const deleteDocument = await client.managedDocs.delete(namespace, slug);
30
+ if (deleteDocument.error) {
31
+ return output.error().title(deleteDocument.message).exit("error");
32
+ }
33
+ logger.update("loader", 0, { content: "Successfully deleted document." }).print();
34
+ }
35
+ export {
36
+ deleteAction
37
+ };
@@ -0,0 +1,60 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ getUserTeams
4
+ } from "./chunk-6ZMT63IV.js";
5
+ import {
6
+ getDatabaseClient
7
+ } from "./chunk-Z2KMGFE6.js";
8
+ import "./chunk-B2MHTD3R.js";
9
+ import {
10
+ getAuthData,
11
+ refreshToken
12
+ } from "./chunk-M37TP6U2.js";
13
+ import "./chunk-4ZDQXWBT.js";
14
+ import "./chunk-VNYE4R7N.js";
15
+ import "./chunk-OQKDBLOZ.js";
16
+ import "./chunk-4ORL4MST.js";
17
+ import {
18
+ output
19
+ } from "./chunk-T5HJUAWB.js";
20
+ import "./chunk-IKT5F47M.js";
21
+ import "./chunk-3MZYUBJ6.js";
22
+
23
+ // src/domains/team/set/action.ts
24
+ import { select } from "@clack/prompts";
25
+ import as from "ansis";
26
+ async function setAction({ team }) {
27
+ const auth = await getAuthData();
28
+ auth.addEventListener((state) => Object.assign(auth, state));
29
+ if (!("refreshToken" in auth)) {
30
+ return output.error().title("Unsupported operation").message(
31
+ "You can not change the selected team because you are using a personal token, which is related to a specific team. \nTo be able to perform actions on other teams you need to generate a new personal token and login with the new token."
32
+ ).exit("error");
33
+ }
34
+ const client = await getDatabaseClient();
35
+ const userTeams = await getUserTeams(client, auth.email ?? "");
36
+ if (userTeams.error) {
37
+ return output.error().title("An error occurred while getting list of teams.").exit("error");
38
+ }
39
+ let teamValue = team;
40
+ if (!teamValue) {
41
+ teamValue = await select({
42
+ message: "Please select one of the teams",
43
+ options: userTeams.data.map((it) => ({
44
+ value: it.teamUid,
45
+ label: it.teamName
46
+ }))
47
+ });
48
+ }
49
+ const selectedTeam = userTeams.data.find((it) => it.teamUid === teamValue);
50
+ if (!selectedTeam) {
51
+ return output.error().title("Invalid team").message("Please choose a valid team id").exit("error");
52
+ }
53
+ await refreshToken(auth.refreshToken, teamValue);
54
+ output.info().message(
55
+ `Operation ${as.green("successful")}. Selected team: ${as.cyan(selectedTeam.teamName)}`
56
+ ).print();
57
+ }
58
+ export {
59
+ setAction
60
+ };
@@ -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
+ };
@@ -0,0 +1,54 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ getUserTeams
4
+ } from "./chunk-6ZMT63IV.js";
5
+ import {
6
+ getDatabaseClient
7
+ } from "./chunk-Z2KMGFE6.js";
8
+ import "./chunk-B2MHTD3R.js";
9
+ import {
10
+ getAuthData
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";
16
+ import {
17
+ output,
18
+ printTable
19
+ } from "./chunk-T5HJUAWB.js";
20
+ import "./chunk-IKT5F47M.js";
21
+ import "./chunk-3MZYUBJ6.js";
22
+
23
+ // src/domains/team/list/action.ts
24
+ import as from "ansis";
25
+ async function listAction() {
26
+ const auth = await getAuthData();
27
+ auth.addEventListener((state) => Object.assign(auth, state));
28
+ const client = await getDatabaseClient();
29
+ const teams = await getUserTeams(client, auth.email ?? "default email");
30
+ if (teams.error) {
31
+ return output.error().title("An error occurred while getting list of teams.").exit("error");
32
+ }
33
+ if (teams.data.length === 0) {
34
+ output.info().title("You are not part of any teams.").print();
35
+ return;
36
+ }
37
+ printTable(
38
+ [
39
+ { name: "current", title: " ", alignment: "center" },
40
+ { name: "team", title: "Team", alignment: "left" }
41
+ ],
42
+ teams.data.map((it) => {
43
+ const isCurrentTeam = it.teamUid === auth.teamUid;
44
+ const color = isCurrentTeam ? as.green : as.blue;
45
+ return {
46
+ current: isCurrentTeam ? color("\u279C") : " ",
47
+ team: isCurrentTeam ? color(`${it.teamName} (default)`) : color(it.teamName)
48
+ };
49
+ })
50
+ );
51
+ }
52
+ export {
53
+ listAction
54
+ };
@@ -0,0 +1,147 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ getFileOrUrl,
4
+ isAsyncApiContent,
5
+ loadOpenApiFile,
6
+ printSpecificationBanner
7
+ } from "./chunk-24WAOKGG.js";
8
+ import {
9
+ watchFile
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";
17
+ import {
18
+ output
19
+ } from "./chunk-T5HJUAWB.js";
20
+ import "./chunk-GSGZHE26.js";
21
+ import "./chunk-IKT5F47M.js";
22
+ import "./chunk-3MZYUBJ6.js";
23
+
24
+ // src/domains/document/mock/action.ts
25
+ import as2 from "ansis";
26
+
27
+ // src/domains/document/mock/helpers.ts
28
+ import { serve } from "@hono/node-server";
29
+ import as from "ansis";
30
+ import { createMockServer } from "@scalar/mock-server";
31
+ var bootServer = async ({
32
+ specification,
33
+ port
34
+ }) => {
35
+ const app = await createMockServer({
36
+ specification,
37
+ onRequest
38
+ });
39
+ return serve(
40
+ {
41
+ fetch: app.fetch,
42
+ port: port ?? 3e3
43
+ },
44
+ (info) => {
45
+ output.info().message(
46
+ `${as.green.bold("\u279C Mock Server")} ${as.white(
47
+ "listening on"
48
+ )} ${as.cyan(`http://localhost:${info.port}`)}`
49
+ ).print();
50
+ }
51
+ );
52
+ };
53
+ var printAvailablePaths = (specification) => {
54
+ output.info().message(as.white.bold("Available Paths")).print();
55
+ if (specification?.paths === void 0 || Object.keys(specification?.paths).length === 0) {
56
+ output.warn().title(as.grey("Could not find any paths in the OpenAPI file.")).print();
57
+ }
58
+ for (const path in specification?.paths ?? []) {
59
+ if (specification?.paths?.[path] === void 0) {
60
+ continue;
61
+ }
62
+ for (const method in specification.paths[path]) {
63
+ if (specification.paths[path][method] === void 0) {
64
+ continue;
65
+ }
66
+ output.info().line(
67
+ `${as[getMethodColor(method)].bold(method.toUpperCase().padEnd(6))} ${as.grey(`${path}`)}`
68
+ ).print();
69
+ }
70
+ }
71
+ output.info().line().print();
72
+ };
73
+ var onRequest = ({
74
+ context,
75
+ operation
76
+ }) => {
77
+ const { method } = context.req;
78
+ output.info().line(
79
+ `${as[getMethodColor(method)].bold(method.toUpperCase().padEnd(6))} ${as.grey(`${context.req.path}`)} ${as.grey("\u2192")} ${operation?.operationId ? as.white(operation.operationId) : as.red("[ERROR] 404 Not Found")}`
80
+ ).print();
81
+ };
82
+ function getMethodColor(method) {
83
+ const colors = {
84
+ get: "green",
85
+ post: "cyan",
86
+ put: "yellow",
87
+ delete: "red",
88
+ patch: "magenta"
89
+ };
90
+ return colors[method.toLowerCase()] ?? "grey";
91
+ }
92
+
93
+ // src/domains/document/mock/action.ts
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
+ }
99
+ let server;
100
+ const result = await loadOpenApiFile(fileArgument);
101
+ if (!result.valid) {
102
+ return output.error().title("Invalid OpenAPI document").exit("error");
103
+ }
104
+ printSpecificationBanner({
105
+ version: result.version,
106
+ schema: result.schema
107
+ });
108
+ let { specification } = result;
109
+ if (watch) {
110
+ await watchFile(fileArgument, async () => {
111
+ const newResult = await loadOpenApiFile(fileArgument);
112
+ const specificationHasChanged = newResult?.specification && JSON.stringify(specification) !== JSON.stringify(newResult.specification);
113
+ if (specificationHasChanged && newResult.valid) {
114
+ output.info().title(as2.grey("OpenAPI file modified")).print();
115
+ printSpecificationBanner({
116
+ version: newResult.version,
117
+ schema: newResult.schema
118
+ });
119
+ specification = newResult.specification;
120
+ if (specification) {
121
+ server.close();
122
+ server = await bootServer({
123
+ specification,
124
+ port
125
+ });
126
+ }
127
+ }
128
+ });
129
+ }
130
+ if (!specification) {
131
+ output.warn().title("Could not find any paths in the OpenAPI file.").print();
132
+ return;
133
+ }
134
+ printAvailablePaths(specification);
135
+ server = await bootServer({
136
+ specification,
137
+ port
138
+ });
139
+ if (once) {
140
+ setTimeout(() => {
141
+ server.close();
142
+ }, 2e3);
143
+ }
144
+ }
145
+ export {
146
+ mockAction
147
+ };