@scalar/cli 2.0.0 → 2.1.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.
Files changed (80) hide show
  1. package/README.md +42 -2
  2. package/chunks/action-45OGQB2M.js +138 -0
  3. package/chunks/action-5R5FDF6S.js +2097 -0
  4. package/chunks/action-ANU5HGC4.js +34 -0
  5. package/chunks/action-BMFXENMX.js +176 -0
  6. package/chunks/action-BNEGJBUH.js +38 -0
  7. package/chunks/action-BYZUBXVB.js +82 -0
  8. package/chunks/action-C5VB4ITT.js +132 -0
  9. package/chunks/action-CCW66QJN.js +72 -0
  10. package/chunks/action-CLSD7O2R.js +60 -0
  11. package/chunks/action-CQ56FVES.js +65 -0
  12. package/chunks/action-CYP4VDK3.js +148 -0
  13. package/chunks/action-DFKHSDFV.js +36 -0
  14. package/chunks/action-F4Y6Q2VB.js +92 -0
  15. package/chunks/action-GB6DM53B.js +70 -0
  16. package/chunks/action-GEBRPNRT.js +87 -0
  17. package/chunks/action-H5OHT2GV.js +56 -0
  18. package/chunks/action-HD2T6BFJ.js +54 -0
  19. package/chunks/action-HNKM3Q65.js +65 -0
  20. package/chunks/action-JOSVV6YA.js +71 -0
  21. package/chunks/action-MENXFJH3.js +204 -0
  22. package/chunks/action-P7LN6FGY.js +13 -0
  23. package/chunks/action-PVDDRIM6.js +130 -0
  24. package/chunks/action-Q5UJ32D6.js +46 -0
  25. package/chunks/action-R6ZZO26F.js +299 -0
  26. package/chunks/action-STIEAXOE.js +53 -0
  27. package/chunks/action-TPBKPHNS.js +110 -0
  28. package/chunks/action-TWFJNQ2R.js +95 -0
  29. package/chunks/action-TZ5KGAQT.js +64 -0
  30. package/chunks/action-UDZUUJSI.js +49 -0
  31. package/chunks/action-W5BATF4Q.js +197 -0
  32. package/chunks/agent-XGLOHXNA.js +112 -0
  33. package/chunks/build.action-LKOILPA6.js +108 -0
  34. package/chunks/chunk-23I5PKZZ.js +78 -0
  35. package/chunks/chunk-2BSG2QHO.js +455 -0
  36. package/chunks/chunk-3MZYUBJ6.js +49 -0
  37. package/chunks/chunk-47Y4L5IT.js +63361 -0
  38. package/chunks/chunk-4DGQIAJX.js +359 -0
  39. package/chunks/chunk-4QS7SJTG.js +138 -0
  40. package/chunks/chunk-5BISXQX4.js +447 -0
  41. package/chunks/chunk-5BPPGTUU.js +463 -0
  42. package/chunks/chunk-AEFPCC4U.js +16 -0
  43. package/chunks/chunk-AHWWJ3MD.js +32 -0
  44. package/chunks/chunk-ASMHW5AY.js +19 -0
  45. package/chunks/chunk-B6QZJWCQ.js +92 -0
  46. package/chunks/chunk-DOVIWNKQ.js +108 -0
  47. package/chunks/chunk-H2WRMLYY.js +13780 -0
  48. package/chunks/chunk-HQKBZOYU.js +34 -0
  49. package/chunks/chunk-ISGLWBXZ.js +4265 -0
  50. package/chunks/chunk-IX7LJ3AD.js +17 -0
  51. package/chunks/chunk-JFIXNSPP.js +26 -0
  52. package/chunks/chunk-K74E42RV.js +7311 -0
  53. package/chunks/chunk-KHDYYVYF.js +16 -0
  54. package/chunks/chunk-KWOL7A6J.js +23 -0
  55. package/chunks/chunk-NUXPNUSS.js +38 -0
  56. package/chunks/chunk-OAXFCOJV.js +25 -0
  57. package/chunks/chunk-P2VH7DOC.js +107 -0
  58. package/chunks/chunk-P646T2WH.js +1608 -0
  59. package/chunks/chunk-SHSHFGA7.js +297 -0
  60. package/chunks/chunk-SXYALPYK.js +2709 -0
  61. package/chunks/chunk-T7B6WNZC.js +18 -0
  62. package/chunks/chunk-T7MDADON.js +17 -0
  63. package/chunks/chunk-TLFMATXR.js +344 -0
  64. package/chunks/chunk-TQ5XC2E3.js +284 -0
  65. package/chunks/chunk-UPUTMFD4.js +465 -0
  66. package/chunks/chunk-VTYTPSXO.js +161 -0
  67. package/chunks/chunk-X4QLDBB5.js +221 -0
  68. package/chunks/chunk-ZTVWAKNJ.js +21 -0
  69. package/chunks/create.action-FFQLBSJH.js +108 -0
  70. package/chunks/delete.action-QNN3LC2F.js +96 -0
  71. package/chunks/delete.action-STHQHP4F.js +88 -0
  72. package/chunks/get.action-OTKYOP3Z.js +87 -0
  73. package/chunks/list.action-6I5EZAVB.js +95 -0
  74. package/chunks/list.action-KDM5RHEH.js +116 -0
  75. package/chunks/publish.action-PODTVRXS.js +182 -0
  76. package/chunks/update.action-4F6STTEQ.js +101 -0
  77. package/chunks/update.action-KMD4ZM75.js +95 -0
  78. package/docs.html +393 -230
  79. package/index.js +645 -98865
  80. package/package.json +16 -14
@@ -0,0 +1,148 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ readAndParseConfig,
4
+ renderConfigError
5
+ } from "./chunk-P2VH7DOC.js";
6
+ import {
7
+ CONFIG_FILE_DEFAULT,
8
+ findConfig,
9
+ legacyTo2_0_0
10
+ } from "./chunk-47Y4L5IT.js";
11
+ import "./chunk-5BPPGTUU.js";
12
+ import "./chunk-4QS7SJTG.js";
13
+ import "./chunk-VTYTPSXO.js";
14
+ import "./chunk-TLFMATXR.js";
15
+ import {
16
+ ConfigVersion
17
+ } from "./chunk-ISGLWBXZ.js";
18
+ import "./chunk-H2WRMLYY.js";
19
+ import "./chunk-K74E42RV.js";
20
+ import {
21
+ output
22
+ } from "./chunk-X4QLDBB5.js";
23
+ import "./chunk-3MZYUBJ6.js";
24
+
25
+ // src/domains/project/upgrade/action.ts
26
+ import fs from "node:fs/promises";
27
+ import path from "node:path";
28
+ import { text } from "@clack/prompts";
29
+ import as from "ansis";
30
+ import { n } from "neverpanic";
31
+
32
+ // src/errors.ts
33
+ function createError(code, detail) {
34
+ return {
35
+ code,
36
+ detail
37
+ };
38
+ }
39
+ function displayError(error, fallback = "Unknown error occurred. Please contact support@scalar.com") {
40
+ try {
41
+ if (error instanceof Error) {
42
+ return error.message;
43
+ }
44
+ if (typeof error === "object") {
45
+ return JSON.stringify(error);
46
+ }
47
+ if (typeof error === "string") {
48
+ return error;
49
+ }
50
+ return fallback;
51
+ } catch {
52
+ return fallback;
53
+ }
54
+ }
55
+
56
+ // src/domains/project/upgrade/action.ts
57
+ async function upgradeAction(__configPath) {
58
+ const configPath = __configPath || findConfig() || await text({
59
+ message: "Where is your configuration file located?",
60
+ defaultValue: CONFIG_FILE_DEFAULT,
61
+ placeholder: CONFIG_FILE_DEFAULT
62
+ });
63
+ const parseConfigResult = readAndParseConfig(configPath);
64
+ if (!parseConfigResult.success) {
65
+ renderConfigError(parseConfigResult.error);
66
+ }
67
+ if (parseConfigResult.success) {
68
+ output.info().line(
69
+ `${as.green("[SUCCESS]")} ${as.green("Configuration is valid:")} ${as.green(parseConfigResult.filePath)}`
70
+ ).print();
71
+ }
72
+ const { config } = parseConfigResult;
73
+ if (config.version === ConfigVersion.V2) {
74
+ return output.info().title("Your Scalar configuration is already upgraded").message(
75
+ "You are already on the latest Scalar docs version. No further action required."
76
+ ).exit("success");
77
+ }
78
+ const upgradedConfigResult = n.fromUnsafe(
79
+ () => legacyTo2_0_0(config),
80
+ (originalError) => createError("FAILED_TO_UPGRADE_CONFIG_V1", originalError)
81
+ );
82
+ if (!upgradedConfigResult.success) {
83
+ return output.error().title("Could not upgrade config.").message(upgradedConfigResult.error.code).message(displayError(upgradedConfigResult.error.detail)).exit("error");
84
+ }
85
+ const { upgradedConfig, legacyTheme, legacyFooter, legacyScript } = upgradedConfigResult.data;
86
+ if (legacyTheme) {
87
+ const writeUpgradedThemeResult = await n.fromUnsafe(
88
+ () => fs.writeFile(
89
+ path.resolve(
90
+ path.dirname(parseConfigResult.filePath),
91
+ config.root ?? "./",
92
+ legacyTheme.path
93
+ ),
94
+ legacyTheme.cssString
95
+ ),
96
+ (originalError) => createError("FAILED_TO_WRITE_UPGRADED_THEME", originalError)
97
+ );
98
+ if (!writeUpgradedThemeResult.success) {
99
+ return output.error().title("Could not save upgraded theme.").message(writeUpgradedThemeResult.error.code).message(displayError(writeUpgradedThemeResult.error.detail)).exit("error");
100
+ }
101
+ }
102
+ if (legacyFooter) {
103
+ const writeUpgradedFooterResult = await n.fromUnsafe(
104
+ () => fs.writeFile(
105
+ path.resolve(
106
+ path.dirname(parseConfigResult.filePath),
107
+ config.root ?? "./",
108
+ legacyFooter.path
109
+ ),
110
+ legacyFooter.footerString
111
+ ),
112
+ (originalError) => createError("FAILED_TO_WRITE_UPGRADED_FOOTER", originalError)
113
+ );
114
+ if (!writeUpgradedFooterResult.success) {
115
+ return output.error().title("Could not save upgraded footer.").message(writeUpgradedFooterResult.error.code).message(displayError(writeUpgradedFooterResult.error.detail)).exit("error");
116
+ }
117
+ }
118
+ if (legacyScript) {
119
+ const writeUpgradedScriptResult = await n.fromUnsafe(
120
+ () => fs.writeFile(
121
+ path.resolve(
122
+ path.dirname(parseConfigResult.filePath),
123
+ config.root ?? "./",
124
+ legacyScript.path
125
+ ),
126
+ legacyScript.scriptString
127
+ ),
128
+ (originalError) => createError("FAILED_TO_WRITE_UPGRADED_SCRIPT", originalError)
129
+ );
130
+ if (!writeUpgradedScriptResult.success) {
131
+ return output.error().title("Could not save upgraded head script.").message(writeUpgradedScriptResult.error.code).message(displayError(writeUpgradedScriptResult.error.detail)).exit("error");
132
+ }
133
+ }
134
+ const writeUpgradedConfigResult = await n.fromUnsafe(
135
+ () => fs.writeFile(
136
+ parseConfigResult.filePath,
137
+ JSON.stringify(upgradedConfig, null, 2)
138
+ ),
139
+ (originalError) => createError("FAILED_TO_WRITE_UPGRADED_CONFIG", originalError)
140
+ );
141
+ if (!writeUpgradedConfigResult.success) {
142
+ return output.error().title("Could not save upgraded config.").message(writeUpgradedConfigResult.error.code).message(displayError(writeUpgradedConfigResult.error.detail)).exit("error");
143
+ }
144
+ return output.info().title("Successfully upgraded Scalar Docs configuration!").message("Run `scalar project preview` to preview your project").exit("success");
145
+ }
146
+ export {
147
+ upgradeAction
148
+ };
@@ -0,0 +1,36 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ getFileOrUrl
4
+ } from "./chunk-23I5PKZZ.js";
5
+ import "./chunk-IX7LJ3AD.js";
6
+ import {
7
+ output
8
+ } from "./chunk-X4QLDBB5.js";
9
+ import "./chunk-3MZYUBJ6.js";
10
+
11
+ // src/domains/document/markdown/action.ts
12
+ import fs from "node:fs";
13
+ import as from "ansis";
14
+ import { createMarkdownFromOpenApi } from "@scalar/openapi-to-markdown";
15
+ async function markdownAction(inputArgument, { output: outputPath }) {
16
+ const startTime = performance.now();
17
+ if (!inputArgument) {
18
+ return output.error().title("Invalid argument").message("Please provide a file path or URL").exit("error");
19
+ }
20
+ const specification = await getFileOrUrl(inputArgument);
21
+ const markdown = await createMarkdownFromOpenApi(specification);
22
+ if (outputPath) {
23
+ fs.writeFileSync(outputPath, markdown, "utf8");
24
+ const endTime = performance.now();
25
+ output.info().line(
26
+ `${as.green("Markdown generated")} ${as.grey(
27
+ `in ${as.white(`${as.bold(`${Math.round(endTime - startTime)}`)} ms`)}`
28
+ )}`
29
+ ).line(`Written to ${as.cyan(outputPath)}`).print();
30
+ return;
31
+ }
32
+ process.stdout.write(markdown);
33
+ }
34
+ export {
35
+ markdownAction
36
+ };
@@ -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-SXYALPYK.js";
5
+ import {
6
+ BaseCollections
7
+ } from "./chunk-2BSG2QHO.js";
8
+ import {
9
+ getDatabaseClient
10
+ } from "./chunk-SHSHFGA7.js";
11
+ import "./chunk-UPUTMFD4.js";
12
+ import "./chunk-B6QZJWCQ.js";
13
+ import "./chunk-5BPPGTUU.js";
14
+ import "./chunk-P646T2WH.js";
15
+ import "./chunk-4QS7SJTG.js";
16
+ import "./chunk-VTYTPSXO.js";
17
+ import {
18
+ getAuthData
19
+ } from "./chunk-5BISXQX4.js";
20
+ import "./chunk-OAXFCOJV.js";
21
+ import "./chunk-TLFMATXR.js";
22
+ import {
23
+ teamSchema
24
+ } from "./chunk-4DGQIAJX.js";
25
+ import {
26
+ namespaceSchema
27
+ } from "./chunk-ISGLWBXZ.js";
28
+ import {
29
+ external_exports
30
+ } from "./chunk-H2WRMLYY.js";
31
+ import "./chunk-K74E42RV.js";
32
+ import "./chunk-IX7LJ3AD.js";
33
+ import {
34
+ output,
35
+ printTable
36
+ } from "./chunk-X4QLDBB5.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,70 @@
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
+ getFileOrUrl
7
+ } from "./chunk-23I5PKZZ.js";
8
+ import {
9
+ require_dist
10
+ } from "./chunk-K74E42RV.js";
11
+ import {
12
+ isUrl,
13
+ isYamlFileName
14
+ } from "./chunk-IX7LJ3AD.js";
15
+ import {
16
+ output
17
+ } from "./chunk-X4QLDBB5.js";
18
+ import {
19
+ __toESM
20
+ } from "./chunk-3MZYUBJ6.js";
21
+
22
+ // src/domains/document/upgrade/action.ts
23
+ var import_yaml = __toESM(require_dist(), 1);
24
+ import fs from "node:fs/promises";
25
+ import { confirm } from "@clack/prompts";
26
+ import as from "ansis";
27
+ import { normalize } from "@scalar/json-magic/helpers/normalize";
28
+ import { upgrade } from "@scalar/openapi-upgrader";
29
+ var isDocument = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
30
+ async function upgradeAction(input, { output: outputFilePath }) {
31
+ if (!input) {
32
+ return output.error().title("Missing input").message("Please provide a file path or URL to upgrade").exit("error");
33
+ }
34
+ const isUrlInput = isUrl(input);
35
+ if (!outputFilePath) {
36
+ if (isUrlInput) {
37
+ return output.error().message(
38
+ "Please provide an output file using the -o flag when upgrading from a URL."
39
+ ).exit("error");
40
+ }
41
+ const shouldContinue = await confirm({
42
+ message: "No output file specified - this will overwrite the input file. Continue?",
43
+ initialValue: false
44
+ });
45
+ if (shouldContinue !== true) {
46
+ return output.error().message("Operation cancelled by user").exit("error");
47
+ }
48
+ }
49
+ const outputFileName = outputFilePath ?? input;
50
+ const document = normalize(await getFileOrUrl(input));
51
+ if (!isDocument(document)) {
52
+ return output.error().title("Invalid input").message(
53
+ "Could not read an OpenAPI document from the input. Please provide a valid JSON or YAML file."
54
+ ).exit("error");
55
+ }
56
+ const { result: upgraded, executionTimeMs } = await measureTime(
57
+ () => upgrade(document, "3.1")
58
+ );
59
+ const isYaml = isYamlFileName(outputFileName);
60
+ await fs.writeFile(
61
+ outputFileName,
62
+ isYaml ? import_yaml.default.stringify(upgraded) : JSON.stringify(upgraded, null, 2)
63
+ );
64
+ output.info().message(
65
+ `${as.green(`\u2728 OpenAPI Schema upgraded to version ${upgraded.openapi}`)} in ${as.white(`${as.bold(`${executionTimeMs.toFixed(2)}`)} ms`)}`
66
+ ).print();
67
+ }
68
+ export {
69
+ upgradeAction
70
+ };
@@ -0,0 +1,87 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ fetchFromRegistry
4
+ } from "./chunk-NUXPNUSS.js";
5
+ import "./chunk-T7MDADON.js";
6
+ import {
7
+ registry
8
+ } from "./chunk-DOVIWNKQ.js";
9
+ import "./chunk-4QS7SJTG.js";
10
+ import "./chunk-VTYTPSXO.js";
11
+ import {
12
+ getAuthData
13
+ } from "./chunk-5BISXQX4.js";
14
+ import "./chunk-OAXFCOJV.js";
15
+ import "./chunk-TLFMATXR.js";
16
+ import "./chunk-4DGQIAJX.js";
17
+ import {
18
+ docVersionSchema
19
+ } from "./chunk-ISGLWBXZ.js";
20
+ import {
21
+ external_exports
22
+ } from "./chunk-H2WRMLYY.js";
23
+ import "./chunk-IX7LJ3AD.js";
24
+ import {
25
+ output
26
+ } from "./chunk-X4QLDBB5.js";
27
+ import "./chunk-3MZYUBJ6.js";
28
+
29
+ // src/domains/registry/get/action.ts
30
+ import fs from "node:fs/promises";
31
+ var versionSchema = external_exports.union([docVersionSchema, external_exports.literal("latest")]);
32
+ async function getAction(namespace, slug, args) {
33
+ if (!namespace) {
34
+ output.error().title("Invalid input").message("Please provide namespace of the document").exit("error");
35
+ return;
36
+ }
37
+ if (!slug) {
38
+ output.error().title("Invalid input").message("Please provide slug of the document").exit("error");
39
+ return;
40
+ }
41
+ const result = external_exports.object({
42
+ version: versionSchema,
43
+ format: external_exports.enum(["json", "yaml"]),
44
+ output: external_exports.string().min(1).optional()
45
+ }).safeParse({
46
+ version: args.version ?? "latest",
47
+ format: args.format,
48
+ output: args.output
49
+ });
50
+ if (result.error) {
51
+ output.error().title("Invalid input").message(result.error.issues[0].message).exit("error");
52
+ return;
53
+ }
54
+ const auth = await getAuthData();
55
+ auth.addEventListener((state) => Object.assign(auth, state));
56
+ const fetchResult = await fetchFromRegistry(
57
+ registry(namespace).apis(slug).url({
58
+ version: result.data.version,
59
+ format: result.data.format
60
+ }),
61
+ auth.accessToken
62
+ );
63
+ if (fetchResult.error) {
64
+ output.error().title("Unable to download document").message(fetchResult.message).exit("error");
65
+ return;
66
+ }
67
+ const document = fetchResult.data;
68
+ const withTrailingNewline = document.endsWith("\n") ? document : `${document}
69
+ `;
70
+ if (result.data.output) {
71
+ try {
72
+ await fs.writeFile(result.data.output, withTrailingNewline, "utf8");
73
+ } catch (error) {
74
+ const message = error instanceof Error && error.message.length > 0 ? error.message : `Could not write to ${result.data.output}.`;
75
+ output.error().title("Unable to write document to file").message(message).exit("error");
76
+ return;
77
+ }
78
+ output.info().line(
79
+ `Downloaded ${namespace}/${slug}@${result.data.version} (${result.data.format})`
80
+ ).line(`Written to ${result.data.output}`).print();
81
+ return;
82
+ }
83
+ process.stdout.write(withTrailingNewline);
84
+ }
85
+ export {
86
+ getAction
87
+ };
@@ -0,0 +1,56 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ getFileOrUrl
4
+ } from "./chunk-23I5PKZZ.js";
5
+ import {
6
+ require_dist
7
+ } from "./chunk-K74E42RV.js";
8
+ import {
9
+ isYamlFileName
10
+ } from "./chunk-IX7LJ3AD.js";
11
+ import {
12
+ output
13
+ } from "./chunk-X4QLDBB5.js";
14
+ import {
15
+ __toESM
16
+ } from "./chunk-3MZYUBJ6.js";
17
+
18
+ // src/domains/document/postman/action.ts
19
+ var import_yaml = __toESM(require_dist(), 1);
20
+ import fs from "node:fs";
21
+ import as from "ansis";
22
+ import { convert } from "@scalar/postman-to-openapi";
23
+ async function convertAction(inputArgument, {
24
+ output: outputPath,
25
+ mergeOperations
26
+ }) {
27
+ const startTime = performance.now();
28
+ if (!inputArgument) {
29
+ return output.error().title("Invalid argument").message("Please provide a Postman collection file path or URL").exit("error");
30
+ }
31
+ const collection = await getFileOrUrl(inputArgument);
32
+ let specification;
33
+ try {
34
+ specification = convert(collection, {
35
+ mergeOperation: !!mergeOperations
36
+ });
37
+ } catch {
38
+ return output.error().title("Failed to convert Postman collection").message("The provided input is not a valid Postman collection").exit("error");
39
+ }
40
+ const openApiDocument = outputPath ? isYamlFileName(outputPath) ? import_yaml.default.stringify(specification) : JSON.stringify(specification, null, 2) : JSON.stringify(specification, null, 2);
41
+ if (outputPath) {
42
+ fs.writeFileSync(outputPath, openApiDocument, "utf8");
43
+ const endTime = performance.now();
44
+ output.info().line(
45
+ `${as.green("OpenAPI document generated")} ${as.grey(
46
+ `in ${as.white(`${as.bold(`${Math.round(endTime - startTime)}`)} ms`)}`
47
+ )}`
48
+ ).line(`Written to ${as.cyan(outputPath)}`).print();
49
+ return;
50
+ }
51
+ process.stdout.write(`${openApiDocument}
52
+ `);
53
+ }
54
+ export {
55
+ convertAction
56
+ };
@@ -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-ASMHW5AY.js";
5
+ import {
6
+ getDatabaseClient
7
+ } from "./chunk-SHSHFGA7.js";
8
+ import "./chunk-B6QZJWCQ.js";
9
+ import {
10
+ getAuthData
11
+ } from "./chunk-5BISXQX4.js";
12
+ import "./chunk-OAXFCOJV.js";
13
+ import "./chunk-4DGQIAJX.js";
14
+ import "./chunk-ISGLWBXZ.js";
15
+ import "./chunk-H2WRMLYY.js";
16
+ import "./chunk-IX7LJ3AD.js";
17
+ import {
18
+ output,
19
+ printTable
20
+ } from "./chunk-X4QLDBB5.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,65 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ apiService
4
+ } from "./chunk-SXYALPYK.js";
5
+ import "./chunk-UPUTMFD4.js";
6
+ import "./chunk-B6QZJWCQ.js";
7
+ import "./chunk-P646T2WH.js";
8
+ import "./chunk-4QS7SJTG.js";
9
+ import "./chunk-VTYTPSXO.js";
10
+ import "./chunk-5BISXQX4.js";
11
+ import "./chunk-OAXFCOJV.js";
12
+ import "./chunk-TLFMATXR.js";
13
+ import "./chunk-4DGQIAJX.js";
14
+ import "./chunk-ISGLWBXZ.js";
15
+ import "./chunk-H2WRMLYY.js";
16
+ import "./chunk-IX7LJ3AD.js";
17
+ import {
18
+ output
19
+ } from "./chunk-X4QLDBB5.js";
20
+ import "./chunk-3MZYUBJ6.js";
21
+
22
+ // src/domains/project/create/action.ts
23
+ import { text } from "@clack/prompts";
24
+ import as from "ansis";
25
+ async function createAction({
26
+ name,
27
+ slug
28
+ }) {
29
+ const apiClient = await apiService();
30
+ let nameValue = name;
31
+ let slugValue = slug;
32
+ if (!nameValue) {
33
+ nameValue = await text({
34
+ message: "What is the name of your project?",
35
+ validate(value) {
36
+ if (value.trim().length === 0) {
37
+ return "You did not provide a project name. Please provide a name!";
38
+ }
39
+ return;
40
+ }
41
+ });
42
+ }
43
+ if (!slugValue) {
44
+ slugValue = await text({
45
+ message: "What is the slug of your project? (Optional)",
46
+ defaultValue: void 0
47
+ });
48
+ }
49
+ const logger = output.info().loader("Creating the project");
50
+ const response = await apiClient.github.createProject({
51
+ name: nameValue,
52
+ slug: slugValue
53
+ });
54
+ if (response.error) {
55
+ return output.error().title("Something went wrong").message(response.message).exit("error");
56
+ }
57
+ logger.update("loader", 0, { content: "Project created successfully!" });
58
+ logger.message(
59
+ `Project uid: ${as.cyan(response.data.uid)}
60
+ Project slug: ${as.cyan(response.data.slug)}`
61
+ ).exit("success");
62
+ }
63
+ export {
64
+ createAction
65
+ };
@@ -0,0 +1,71 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ getFileOrUrl
4
+ } from "./chunk-23I5PKZZ.js";
5
+ import "./chunk-IX7LJ3AD.js";
6
+ import {
7
+ output
8
+ } from "./chunk-X4QLDBB5.js";
9
+ import "./chunk-3MZYUBJ6.js";
10
+
11
+ // src/domains/document/lint/action.ts
12
+ import spectralCore from "@stoplight/spectral-core";
13
+ import "@stoplight/spectral-rulesets";
14
+ import as from "ansis";
15
+
16
+ // src/domains/document/lint/helpers.ts
17
+ import { bundleAndLoadRuleset } from "@stoplight/spectral-ruleset-bundler/with-loader";
18
+ async function loadRuleset(ruleset) {
19
+ return await bundleAndLoadRuleset("/.spectral.yaml", {
20
+ fs: {
21
+ promises: {
22
+ // @ts-expect-error No need for overloading here.
23
+ async readFile(_filepath) {
24
+ return ruleset;
25
+ }
26
+ }
27
+ },
28
+ format: "esm"
29
+ });
30
+ }
31
+ var defaultRuleset = `extends: spectral:oas
32
+ rules: {}`;
33
+ var severityToLabel = (severity) => {
34
+ return {
35
+ 0: "Error",
36
+ 1: "Warning",
37
+ 2: "Information",
38
+ 3: "Hint"
39
+ }[severity];
40
+ };
41
+
42
+ // src/domains/document/lint/action.ts
43
+ var { Spectral } = spectralCore;
44
+ async function lintAction(inputArgument, { rule: ruleArgument }) {
45
+ if (!inputArgument) {
46
+ return output.error().title("Invalid argument").message("Please provide a file path").exit("error");
47
+ }
48
+ const spectral = new Spectral();
49
+ const specification = await getFileOrUrl(inputArgument);
50
+ const ruleFileContents = ruleArgument ? await getFileOrUrl(ruleArgument) : defaultRuleset;
51
+ const ruleset = await loadRuleset(ruleFileContents);
52
+ spectral.setRuleset(ruleset);
53
+ const spectralDiagnostics = await spectral.run(specification);
54
+ const hasErrors = spectralDiagnostics.filter((d) => d.severity === 0).length !== 0;
55
+ if (!hasErrors) {
56
+ output.info().message(as.green("\u2714 No issues found!")).print();
57
+ } else {
58
+ output.warn().line(as.red("\u2716 Issues found:")).print();
59
+ }
60
+ for (const diagnostic of spectralDiagnostics) {
61
+ output.info().line(`${as.yellow("Rule:")} ${as.bold(diagnostic.code)}`).line(`${as.yellow("Message:")} ${diagnostic.message}`).line(`${as.yellow("Severity:")} ${severityToLabel(diagnostic.severity)}`).line(
62
+ `${as.yellow("Location:")} ${diagnostic.range.start.line}:${diagnostic.range.start.character} - ${diagnostic.range.end.line}:${diagnostic.range.end.character}`
63
+ ).line(as.gray("---")).print();
64
+ }
65
+ if (hasErrors) {
66
+ output.error().exit("error");
67
+ }
68
+ }
69
+ export {
70
+ lintAction
71
+ };