@scalar/cli 2.5.2 → 2.8.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 (79) hide show
  1. package/README.md +319 -55
  2. package/chunks/{action-XUQ7TKKJ.js → action-354TUG4H.js} +11 -7
  3. package/chunks/{action-PHLOE27S.js → action-43YBNBDR.js} +33 -26
  4. package/chunks/{action-DGD6Q6Y5.js → action-5SK5NE7E.js} +10 -4
  5. package/chunks/{action-Y6CEKYEK.js → action-6BYGBXRC.js} +40 -23
  6. package/chunks/{action-LUVBQEIQ.js → action-7PEQXDWT.js} +4 -4
  7. package/chunks/action-AQRPFQKI.js +231 -0
  8. package/chunks/{action-RBVPKCRI.js → action-CA4QYPI6.js} +6 -6
  9. package/chunks/{action-7H3XARJP.js → action-EOAVVL52.js} +11 -5
  10. package/chunks/action-F2ZJNURT.js +72 -0
  11. package/chunks/{action-AMNYOA4B.js → action-F7A2K74G.js} +4 -4
  12. package/chunks/{action-HIL5ZFNB.js → action-FCAYFPVR.js} +5 -5
  13. package/chunks/{action-42D2C47G.js → action-GWXLHL2Z.js} +3 -3
  14. package/chunks/{action-ZWQLQENM.js → action-H6OUJWWM.js} +4 -4
  15. package/chunks/{action-TWHLZW4V.js → action-HT2DJ34Z.js} +49 -26
  16. package/chunks/{action-PAA4NWUJ.js → action-JAHFRYWZ.js} +58 -9
  17. package/chunks/{action-HXHBU7XC.js → action-KTYOCA2V.js} +37 -12
  18. package/chunks/{action-LFL3ZZKN.js → action-LEUD5P2U.js} +17 -17
  19. package/chunks/{action-FF2OMGAS.js → action-LLH4QPXM.js} +34 -20
  20. package/chunks/{action-OILGZAMK.js → action-LXGXKXZZ.js} +20 -15
  21. package/chunks/{action-W62AIEBN.js → action-NVI5DWFP.js} +6 -6
  22. package/chunks/{action-EPNE5XCM.js → action-QQZLPI42.js} +17 -17
  23. package/chunks/{action-ZLTUMRO2.js → action-UIKH4SZX.js} +25 -21
  24. package/chunks/{action-6FAJNP6C.js → action-VOFDW3U2.js} +4 -4
  25. package/chunks/{action-OK55BFGM.js → action-W3C53GPH.js} +7 -7
  26. package/chunks/{action-P7RFXIC7.js → action-WFDNRA7D.js} +32 -23
  27. package/chunks/{action-V5KYG7XD.js → action-XIUO64C7.js} +10 -10
  28. package/chunks/{action-X7TZA3RE.js → action-Y6NXJQ4H.js} +89 -14
  29. package/chunks/{action-6MZZHPVQ.js → action-Y7OUGD56.js} +27 -14
  30. package/chunks/{action-DCINFQ57.js → action-YLF2G4G5.js} +13 -13
  31. package/chunks/{action-SJYAMXYI.js → action-YRX6SN5F.js} +10 -4
  32. package/chunks/actions-OGIVBQC7.js +158 -0
  33. package/chunks/{agent-JAXLLDPE.js → agent-ASPV3R5U.js} +4 -4
  34. package/chunks/{asyncapi-P6Y3L7RG.js → asyncapi-QNFKXHEI.js} +10 -11
  35. package/chunks/{build.action-AZ5ECU4B.js → build.action-NM6CAE5F.js} +37 -33
  36. package/chunks/{chunk-FOKFF4EP.js → chunk-22HYZ7LE.js} +3 -3
  37. package/chunks/{chunk-KEOCJ3NJ.js → chunk-2OCWX42S.js} +38 -87
  38. package/chunks/{chunk-RPVHJMQT.js → chunk-5DEU2DVL.js} +2 -2
  39. package/chunks/{chunk-OQKDBLOZ.js → chunk-5JLVQVKO.js} +8 -0
  40. package/chunks/{chunk-VNYE4R7N.js → chunk-5UHLAJQD.js} +2 -1
  41. package/chunks/{chunk-CX7ZRMTC.js → chunk-6XWCMJDB.js} +1 -1
  42. package/chunks/{chunk-6ZMT63IV.js → chunk-6YPQGVF4.js} +1 -1
  43. package/chunks/{chunk-HXIDUCSZ.js → chunk-BPGFSSUH.js} +1 -1
  44. package/chunks/{chunk-M622VXRQ.js → chunk-C2KAWRIX.js} +1 -1
  45. package/chunks/chunk-EGOXR5FB.js +15 -0
  46. package/chunks/{chunk-UB3XGOUW.js → chunk-EXY3ZTV4.js} +262 -9
  47. package/chunks/{chunk-3BWGTPPT.js → chunk-FDC2IESH.js} +1776 -1113
  48. package/chunks/{chunk-TYLWJ2UL.js → chunk-GTV2BVXV.js} +2 -2
  49. package/chunks/{chunk-SWWWYWHC.js → chunk-HGOD6THU.js} +27 -18
  50. package/chunks/{chunk-3DJ2GKEG.js → chunk-IMG35UXX.js} +1 -1
  51. package/chunks/{chunk-MNLXYOVF.js → chunk-KCCFN4F7.js} +2 -2
  52. package/chunks/{chunk-FQVVKQPU.js → chunk-KKRGBXCE.js} +137 -1
  53. package/chunks/{chunk-UMPODUJO.js → chunk-L3UXDCBI.js} +105 -15
  54. package/chunks/{chunk-B2MHTD3R.js → chunk-MLSZVVTT.js} +1 -1
  55. package/chunks/{chunk-LCPFHE4Z.js → chunk-OJ2EWIJH.js} +21 -2
  56. package/chunks/{chunk-RAO7VUGM.js → chunk-PH3WFNXJ.js} +1 -1
  57. package/chunks/{chunk-NIXG4KDE.js → chunk-QVQ4PNVL.js} +170 -5
  58. package/chunks/{chunk-CIFOFSZ3.js → chunk-R5LK6VPY.js} +72 -7
  59. package/chunks/{chunk-T7B6WNZC.js → chunk-TSURUX4A.js} +12 -3
  60. package/chunks/{chunk-JV7TUEXQ.js → chunk-UXJ753NV.js} +14 -1
  61. package/chunks/{chunk-HUCR333E.js → chunk-W24BETFG.js} +2 -2
  62. package/chunks/{chunk-LQN4S62O.js → chunk-XEDGMZJD.js} +18 -4
  63. package/chunks/{chunk-NNMSZVAB.js → chunk-XXSQUBXS.js} +82 -6
  64. package/chunks/{chunk-M6Q3ARBV.js → chunk-YILQODZF.js} +2 -2
  65. package/chunks/{create.action-34OTO2SB.js → create.action-FUQ2BVJA.js} +29 -17
  66. package/chunks/{delete.action-ZYXFMIOW.js → delete.action-47E66R3I.js} +26 -17
  67. package/chunks/{delete.action-6LRT4M3S.js → delete.action-BTDFH7WY.js} +26 -17
  68. package/chunks/{get.action-XP36SA2J.js → get.action-XC7KC2JO.js} +10 -10
  69. package/chunks/{list.action-6LF6KSD5.js → list.action-LXKEUYKO.js} +13 -13
  70. package/chunks/{list.action-WVRVLX5E.js → list.action-OFGLMRE7.js} +17 -17
  71. package/chunks/{publish.action-AHFUBT5C.js → publish.action-OS27XOX4.js} +50 -24
  72. package/chunks/{update.action-YQTVUDYE.js → update.action-AEIBLCWD.js} +27 -18
  73. package/chunks/{update.action-ZREAFJVG.js → update.action-ZMS4CQ3T.js} +27 -18
  74. package/docs.html +679 -175
  75. package/index.js +492 -406
  76. package/package.json +14 -22
  77. package/skills/scalar-cli/SKILL.md +77 -0
  78. package/template.md +101 -3
  79. package/chunks/action-YRWHX2AE.js +0 -64
@@ -1,19 +1,19 @@
1
1
  import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
2
  import {
3
3
  getFileOrUrl
4
- } from "./chunk-SWWWYWHC.js";
4
+ } from "./chunk-HGOD6THU.js";
5
5
  import {
6
6
  require_dist
7
7
  } from "./chunk-K74E42RV.js";
8
- import "./chunk-MNLXYOVF.js";
9
- import "./chunk-CX7ZRMTC.js";
8
+ import "./chunk-KCCFN4F7.js";
9
+ import "./chunk-6XWCMJDB.js";
10
10
  import {
11
11
  isYamlFileName
12
12
  } from "./chunk-4ORL4MST.js";
13
13
  import {
14
14
  output
15
15
  } from "./chunk-T5HJUAWB.js";
16
- import "./chunk-LQN4S62O.js";
16
+ import "./chunk-XEDGMZJD.js";
17
17
  import "./chunk-IKT5F47M.js";
18
18
  import {
19
19
  __toESM
@@ -2,17 +2,17 @@ import { createRequire as $$cR } from "node:module"; const require = $$cR(import
2
2
  import {
3
3
  getFileOrUrl,
4
4
  isAsyncApiContent
5
- } from "./chunk-SWWWYWHC.js";
5
+ } from "./chunk-HGOD6THU.js";
6
6
  import {
7
7
  config
8
- } from "./chunk-JV7TUEXQ.js";
9
- import "./chunk-MNLXYOVF.js";
10
- import "./chunk-CX7ZRMTC.js";
8
+ } from "./chunk-UXJ753NV.js";
9
+ import "./chunk-KCCFN4F7.js";
10
+ import "./chunk-6XWCMJDB.js";
11
11
  import "./chunk-4ORL4MST.js";
12
12
  import {
13
13
  output
14
14
  } from "./chunk-T5HJUAWB.js";
15
- import "./chunk-LQN4S62O.js";
15
+ import "./chunk-XEDGMZJD.js";
16
16
  import "./chunk-IKT5F47M.js";
17
17
  import "./chunk-3MZYUBJ6.js";
18
18
 
@@ -4,10 +4,10 @@ import {
4
4
  downloadIsolate,
5
5
  isDiskWriteError,
6
6
  updateIsolate
7
- } from "./chunk-UMPODUJO.js";
7
+ } from "./chunk-L3UXDCBI.js";
8
8
  import "./chunk-3ZJYGGAA.js";
9
- import "./chunk-HXIDUCSZ.js";
10
- import "./chunk-JV7TUEXQ.js";
9
+ import "./chunk-BPGFSSUH.js";
10
+ import "./chunk-UXJ753NV.js";
11
11
  import "./chunk-T5HJUAWB.js";
12
12
  import "./chunk-3MZYUBJ6.js";
13
13
  export {
@@ -3,12 +3,12 @@ import {
3
3
  getFileOrUrl,
4
4
  isDocument,
5
5
  safeNormalize
6
- } from "./chunk-SWWWYWHC.js";
6
+ } from "./chunk-HGOD6THU.js";
7
7
  import {
8
8
  require_dist
9
9
  } from "./chunk-K74E42RV.js";
10
- import "./chunk-MNLXYOVF.js";
11
- import "./chunk-CX7ZRMTC.js";
10
+ import "./chunk-KCCFN4F7.js";
11
+ import "./chunk-6XWCMJDB.js";
12
12
  import {
13
13
  isUrl,
14
14
  isYamlFileName
@@ -16,7 +16,7 @@ import {
16
16
  import {
17
17
  output
18
18
  } from "./chunk-T5HJUAWB.js";
19
- import "./chunk-LQN4S62O.js";
19
+ import "./chunk-XEDGMZJD.js";
20
20
  import "./chunk-IKT5F47M.js";
21
21
  import {
22
22
  __toESM
@@ -2,40 +2,57 @@ import { createRequire as $$cR } from "node:module"; const require = $$cR(import
2
2
  import {
3
3
  getFileOrUrl,
4
4
  isAsyncApiContent,
5
- loadOpenApiFile,
5
+ loadOpenApiDocument,
6
6
  printSpecificationBanner
7
- } from "./chunk-SWWWYWHC.js";
7
+ } from "./chunk-HGOD6THU.js";
8
8
  import {
9
9
  watchFile
10
- } from "./chunk-NIXG4KDE.js";
11
- import "./chunk-JV7TUEXQ.js";
12
- import "./chunk-VNYE4R7N.js";
13
- import "./chunk-OQKDBLOZ.js";
14
- import "./chunk-MNLXYOVF.js";
15
- import "./chunk-CX7ZRMTC.js";
16
- import "./chunk-4ORL4MST.js";
10
+ } from "./chunk-QVQ4PNVL.js";
11
+ import "./chunk-UXJ753NV.js";
12
+ import "./chunk-5UHLAJQD.js";
13
+ import "./chunk-5JLVQVKO.js";
14
+ import "./chunk-KCCFN4F7.js";
15
+ import "./chunk-6XWCMJDB.js";
16
+ import {
17
+ isUrl
18
+ } from "./chunk-4ORL4MST.js";
17
19
  import {
18
20
  output
19
21
  } from "./chunk-T5HJUAWB.js";
20
- import "./chunk-LQN4S62O.js";
22
+ import "./chunk-XEDGMZJD.js";
21
23
  import "./chunk-IKT5F47M.js";
22
24
  import "./chunk-3MZYUBJ6.js";
23
25
 
24
26
  // src/domains/document/mock/action.ts
27
+ import path2 from "node:path";
25
28
  import as2 from "ansis";
26
29
 
27
30
  // src/domains/document/mock/helpers.ts
31
+ import path from "node:path";
28
32
  import { serve } from "@hono/node-server";
29
33
  import as from "ansis";
34
+ import { bundle } from "@scalar/json-magic/bundle";
35
+ import { fetchUrls, readFiles } from "@scalar/json-magic/bundle/plugins/node";
30
36
  import { createMockServer } from "@scalar/mock-server";
31
37
  var bootServer = async ({
32
- specification,
38
+ document,
39
+ origin,
33
40
  port
34
41
  }) => {
35
- const app = await createMockServer({
36
- specification,
37
- onRequest
38
- });
42
+ const app = await bundle(document, {
43
+ origin,
44
+ plugins: [
45
+ readFiles({
46
+ basePath: isUrl(origin) ? process.cwd() : path.dirname(origin)
47
+ }),
48
+ fetchUrls({ blockPrivateNetworks: true })
49
+ ],
50
+ treeShake: false
51
+ }).then((bundled) => createMockServer({ document: bundled, onRequest })).catch(
52
+ (error) => output.error().title(
53
+ `Could not start mock server: ${error instanceof Error ? error.message : String(error)}`
54
+ ).exit("error")
55
+ );
39
56
  return serve(
40
57
  {
41
58
  fetch: app.fetch,
@@ -55,16 +72,16 @@ var printAvailablePaths = (specification) => {
55
72
  if (specification?.paths === void 0 || Object.keys(specification?.paths).length === 0) {
56
73
  output.warn().title(as.grey("Could not find any paths in the OpenAPI file.")).print();
57
74
  }
58
- for (const path in specification?.paths ?? []) {
59
- if (specification?.paths?.[path] === void 0) {
75
+ for (const path3 in specification?.paths ?? []) {
76
+ if (specification?.paths?.[path3] === void 0) {
60
77
  continue;
61
78
  }
62
- for (const method in specification.paths[path]) {
63
- if (specification.paths[path][method] === void 0) {
79
+ for (const method in specification.paths[path3]) {
80
+ if (specification.paths[path3][method] === void 0) {
64
81
  continue;
65
82
  }
66
83
  output.info().line(
67
- `${as[getMethodColor(method)].bold(method.toUpperCase().padEnd(6))} ${as.grey(`${path}`)}`
84
+ `${as[getMethodColor(method)].bold(method.toUpperCase().padEnd(6))} ${as.grey(`${path3}`)}`
68
85
  ).print();
69
86
  }
70
87
  }
@@ -92,12 +109,14 @@ function getMethodColor(method) {
92
109
 
93
110
  // src/domains/document/mock/action.ts
94
111
  async function mockAction(fileArgument, { watch, once, port }) {
95
- if (isAsyncApiContent(await getFileOrUrl(fileArgument))) {
96
- const { mockAsyncApi } = await import("./asyncapi-P6Y3L7RG.js");
112
+ const content = await getFileOrUrl(fileArgument);
113
+ if (isAsyncApiContent(content)) {
114
+ const { mockAsyncApi } = await import("./asyncapi-QNFKXHEI.js");
97
115
  return mockAsyncApi(fileArgument, { watch, once, port });
98
116
  }
117
+ const origin = isUrl(fileArgument) ? fileArgument : path2.resolve(fileArgument);
99
118
  let server;
100
- const result = await loadOpenApiFile(fileArgument);
119
+ const result = await loadOpenApiDocument(content);
101
120
  if (!result.valid) {
102
121
  return output.error().title("Invalid OpenAPI document").exit("error");
103
122
  }
@@ -108,7 +127,9 @@ async function mockAction(fileArgument, { watch, once, port }) {
108
127
  let { specification } = result;
109
128
  if (watch) {
110
129
  await watchFile(fileArgument, async () => {
111
- const newResult = await loadOpenApiFile(fileArgument);
130
+ const newResult = await loadOpenApiDocument(
131
+ await getFileOrUrl(fileArgument)
132
+ );
112
133
  const specificationHasChanged = newResult?.specification && JSON.stringify(specification) !== JSON.stringify(newResult.specification);
113
134
  if (specificationHasChanged && newResult.valid) {
114
135
  output.info().title(as2.grey("OpenAPI file modified")).print();
@@ -120,7 +141,8 @@ async function mockAction(fileArgument, { watch, once, port }) {
120
141
  if (specification) {
121
142
  server.close();
122
143
  server = await bootServer({
123
- specification,
144
+ document: specification,
145
+ origin,
124
146
  port
125
147
  });
126
148
  }
@@ -133,7 +155,8 @@ async function mockAction(fileArgument, { watch, once, port }) {
133
155
  }
134
156
  printAvailablePaths(specification);
135
157
  server = await bootServer({
136
- specification,
158
+ document: specification,
159
+ origin,
137
160
  port
138
161
  });
139
162
  if (once) {
@@ -2,21 +2,21 @@ import { createRequire as $$cR } from "node:module"; const require = $$cR(import
2
2
  import {
3
3
  getFileOrUrl,
4
4
  isAsyncApiContent
5
- } from "./chunk-SWWWYWHC.js";
5
+ } from "./chunk-HGOD6THU.js";
6
6
  import {
7
7
  err,
8
8
  ok
9
- } from "./chunk-M622VXRQ.js";
9
+ } from "./chunk-C2KAWRIX.js";
10
10
  import {
11
11
  require_dist
12
12
  } from "./chunk-K74E42RV.js";
13
- import "./chunk-MNLXYOVF.js";
14
- import "./chunk-CX7ZRMTC.js";
13
+ import "./chunk-KCCFN4F7.js";
14
+ import "./chunk-6XWCMJDB.js";
15
15
  import "./chunk-4ORL4MST.js";
16
16
  import {
17
17
  output
18
18
  } from "./chunk-T5HJUAWB.js";
19
- import "./chunk-LQN4S62O.js";
19
+ import "./chunk-XEDGMZJD.js";
20
20
  import "./chunk-IKT5F47M.js";
21
21
  import {
22
22
  __toESM
@@ -176,6 +176,42 @@ function isFile(path) {
176
176
  }
177
177
  }
178
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
+
179
215
  // ../../packages/api-document-lint/dist/run-vacuum.js
180
216
  var execFileAsync = promisify(execFile);
181
217
  var MAX_BUFFER = 64 * 1024 * 1024;
@@ -184,6 +220,11 @@ async function runVacuum(input, options = {}) {
184
220
  if (input.document.trim().length === 0) {
185
221
  return ok([]);
186
222
  }
223
+ if (options.allowExternalReferences === false) {
224
+ const validation = validateInlineDocument(input.document);
225
+ if (!validation.ok)
226
+ return validation;
227
+ }
187
228
  const binary = resolveVacuumBinary(options.binaryPath);
188
229
  if (!binary.ok) {
189
230
  return binary;
@@ -206,8 +247,15 @@ async function runVacuum(input, options = {}) {
206
247
  "--skip-check",
207
248
  // Match Spectral's working-directory base for document strings.
208
249
  "--base",
209
- process.cwd()
250
+ options.allowExternalReferences === false ? directory : process.cwd()
210
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
+ }
211
259
  if (input.ruleset && input.ruleset.trim().length > 0) {
212
260
  const rulesetPath = join2(directory, "ruleset.yaml");
213
261
  const wroteRuleset = await writeFile(rulesetPath, input.ruleset, "utf8").then(() => true).catch(() => false);
@@ -219,7 +267,8 @@ async function runVacuum(input, options = {}) {
219
267
  args.push(documentPath, reportPath);
220
268
  const failure = await execFileAsync(binary.data, args, {
221
269
  maxBuffer: MAX_BUFFER,
222
- timeout: TIMEOUT_MS
270
+ timeout: options.timeoutMs ?? TIMEOUT_MS,
271
+ ...options.allowExternalReferences === false ? { cwd: directory } : {}
223
272
  }).then(() => null).catch((error) => error);
224
273
  const report = await readFile(reportPath, "utf8").catch(() => null);
225
274
  if (report === null) {
@@ -262,7 +311,7 @@ function parseReport(report) {
262
311
  }
263
312
 
264
313
  // ../../packages/api-document-lint/dist/select-engine.js
265
- var import_yaml = __toESM(require_dist(), 1);
314
+ var import_yaml2 = __toESM(require_dist(), 1);
266
315
  function selectEngine(ruleset) {
267
316
  if (!ruleset || ruleset.trim().length === 0) {
268
317
  return "vacuum";
@@ -291,7 +340,7 @@ function isRecord(value) {
291
340
  }
292
341
  function parseRuleset(ruleset) {
293
342
  try {
294
- const value = (0, import_yaml.parse)(ruleset);
343
+ const value = (0, import_yaml2.parse)(ruleset);
295
344
  if (value && typeof value === "object" && !Array.isArray(value)) {
296
345
  return value;
297
346
  }
@@ -8,12 +8,12 @@ import {
8
8
  generateAccessByPersonalToken,
9
9
  setAuthData,
10
10
  tokenResponseSchema
11
- } from "./chunk-NIXG4KDE.js";
11
+ } from "./chunk-QVQ4PNVL.js";
12
12
  import {
13
13
  config
14
- } from "./chunk-JV7TUEXQ.js";
15
- import "./chunk-VNYE4R7N.js";
16
- import "./chunk-OQKDBLOZ.js";
14
+ } from "./chunk-UXJ753NV.js";
15
+ import "./chunk-5UHLAJQD.js";
16
+ import "./chunk-5JLVQVKO.js";
17
17
  import "./chunk-4ORL4MST.js";
18
18
  import {
19
19
  output
@@ -28,7 +28,12 @@ import as2 from "ansis";
28
28
 
29
29
  // ../../packages/mongobase-client/dist/auth/node/exchange-callback-server.js
30
30
  import getPort from "get-port";
31
- var generateTokenCallbackEndpoint = async (exchangeUrl) => {
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;
32
37
  const http = await import("node:http");
33
38
  const port = await getPort();
34
39
  const server = http.createServer();
@@ -36,11 +41,24 @@ var generateTokenCallbackEndpoint = async (exchangeUrl) => {
36
41
  const getTokens = async () => {
37
42
  const resultPromise = new Promise((resolve) => {
38
43
  server.on("request", async (req, res) => {
39
- const corsOrigin = `http://127.0.0.1:${port}`;
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
+ }
40
58
  const errorResponse = (message, code) => {
41
59
  res.writeHead(code, {
42
60
  "Content-Type": "application/json",
43
- "Access-Control-Allow-Origin": corsOrigin
61
+ ...corsHeaders
44
62
  });
45
63
  res.end(JSON.stringify({
46
64
  success: false,
@@ -63,7 +81,7 @@ var generateTokenCallbackEndpoint = async (exchangeUrl) => {
63
81
  if (tokens) {
64
82
  res.writeHead(200, {
65
83
  "Content-Type": "application/json",
66
- "Access-Control-Allow-Origin": corsOrigin
84
+ ...corsHeaders
67
85
  });
68
86
  res.end(JSON.stringify({
69
87
  success: true,
@@ -176,13 +194,20 @@ async function loginAction({
176
194
  await setAuthData({ accessToken, refreshToken });
177
195
  output.info().message(loggedInMessage(email)).print();
178
196
  } catch (err) {
179
- output.error().title(err.message).print();
197
+ output.error().title(err.message).exit("error");
180
198
  }
181
199
  return;
182
200
  }
183
- const { port, getTokens } = await generateTokenCallbackEndpoint(
184
- `${config.services.api}/core/login/exchange`
185
- );
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;
186
211
  const loginUrl = `${config.projects.dashboard}/login?externalRedirect=local&port=${port}`;
187
212
  output.info().message(`Please follow the link to login: ${as2.cyan(loginUrl)}`).print();
188
213
  openBrowser(loginUrl);
@@ -1,35 +1,35 @@
1
1
  import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
- import {
3
- apiService
4
- } from "./chunk-UB3XGOUW.js";
5
2
  import {
6
3
  BaseCollections
7
- } from "./chunk-KEOCJ3NJ.js";
4
+ } from "./chunk-2OCWX42S.js";
8
5
  import {
9
6
  getDatabaseClient
10
- } from "./chunk-RPVHJMQT.js";
11
- import "./chunk-FQVVKQPU.js";
12
- import "./chunk-B2MHTD3R.js";
13
- import "./chunk-3BWGTPPT.js";
14
- import "./chunk-M622VXRQ.js";
15
- import "./chunk-CIFOFSZ3.js";
7
+ } from "./chunk-5DEU2DVL.js";
8
+ import {
9
+ apiService
10
+ } from "./chunk-EXY3ZTV4.js";
11
+ import "./chunk-KKRGBXCE.js";
12
+ import "./chunk-MLSZVVTT.js";
13
+ import "./chunk-FDC2IESH.js";
14
+ import "./chunk-C2KAWRIX.js";
15
+ import "./chunk-R5LK6VPY.js";
16
16
  import {
17
17
  getAuthData
18
- } from "./chunk-NIXG4KDE.js";
19
- import "./chunk-JV7TUEXQ.js";
18
+ } from "./chunk-QVQ4PNVL.js";
19
+ import "./chunk-UXJ753NV.js";
20
20
  import {
21
21
  teamSchema
22
- } from "./chunk-VNYE4R7N.js";
23
- import "./chunk-OQKDBLOZ.js";
22
+ } from "./chunk-5UHLAJQD.js";
23
+ import "./chunk-5JLVQVKO.js";
24
24
  import "./chunk-K74E42RV.js";
25
- import "./chunk-MNLXYOVF.js";
26
- import "./chunk-CX7ZRMTC.js";
25
+ import "./chunk-KCCFN4F7.js";
26
+ import "./chunk-6XWCMJDB.js";
27
27
  import "./chunk-4ORL4MST.js";
28
28
  import {
29
29
  output,
30
30
  printTable
31
31
  } from "./chunk-T5HJUAWB.js";
32
- import "./chunk-LQN4S62O.js";
32
+ import "./chunk-XEDGMZJD.js";
33
33
  import {
34
34
  external_exports,
35
35
  namespaceSchema
@@ -1,42 +1,45 @@
1
1
  import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
2
  import {
3
3
  downloadIsolate
4
- } from "./chunk-UMPODUJO.js";
4
+ } from "./chunk-L3UXDCBI.js";
5
5
  import "./chunk-3ZJYGGAA.js";
6
6
  import {
7
7
  readAndParseConfig,
8
8
  renderConfigError
9
- } from "./chunk-HUCR333E.js";
9
+ } from "./chunk-W24BETFG.js";
10
10
  import {
11
11
  CONFIG_FILE_DEFAULT,
12
12
  findConfig
13
- } from "./chunk-NNMSZVAB.js";
13
+ } from "./chunk-XXSQUBXS.js";
14
14
  import {
15
15
  ISOLATE_DIR
16
- } from "./chunk-HXIDUCSZ.js";
16
+ } from "./chunk-BPGFSSUH.js";
17
17
  import {
18
18
  getAuthData
19
- } from "./chunk-NIXG4KDE.js";
19
+ } from "./chunk-QVQ4PNVL.js";
20
20
  import {
21
21
  config
22
- } from "./chunk-JV7TUEXQ.js";
23
- import "./chunk-VNYE4R7N.js";
22
+ } from "./chunk-UXJ753NV.js";
23
+ import "./chunk-5UHLAJQD.js";
24
24
  import {
25
25
  ConfigVersion
26
- } from "./chunk-OQKDBLOZ.js";
26
+ } from "./chunk-5JLVQVKO.js";
27
+ import {
28
+ requireInteractive
29
+ } from "./chunk-EGOXR5FB.js";
27
30
  import "./chunk-K74E42RV.js";
28
- import "./chunk-MNLXYOVF.js";
29
- import "./chunk-CX7ZRMTC.js";
31
+ import "./chunk-KCCFN4F7.js";
32
+ import "./chunk-6XWCMJDB.js";
30
33
  import "./chunk-4ORL4MST.js";
31
34
  import {
32
35
  output
33
36
  } from "./chunk-T5HJUAWB.js";
34
- import "./chunk-LQN4S62O.js";
37
+ import "./chunk-XEDGMZJD.js";
35
38
  import "./chunk-IKT5F47M.js";
36
39
  import "./chunk-3MZYUBJ6.js";
37
40
 
38
41
  // src/domains/project/preview/action.ts
39
- import { text } from "@clack/prompts";
42
+ import { isCancel, text } from "@clack/prompts";
40
43
  import as from "ansis";
41
44
 
42
45
  // src/domains/project/preview/v2.ts
@@ -86,7 +89,8 @@ async function previewV2Project({
86
89
  configPath,
87
90
  port,
88
91
  config: config2,
89
- host
92
+ host,
93
+ openBrowser
90
94
  }) {
91
95
  const root = path.resolve(path.dirname(configPath), config2.root ?? "./");
92
96
  const relativeConfigPath = path.relative(root, configPath);
@@ -103,7 +107,8 @@ async function previewV2Project({
103
107
  registryBaseUrl: config.projects.registry,
104
108
  baseUrl: config.services.api,
105
109
  token: accessToken,
106
- host
110
+ host,
111
+ openBrowser
107
112
  });
108
113
  }
109
114
 
@@ -116,11 +121,19 @@ async function previewAction(__configPath, options) {
116
121
  if (_port < 0 || _port > 65535) {
117
122
  return output.error().title("Invalid port").message("Port number must be between 0 and 65535").exit("error");
118
123
  }
119
- const configPath = __configPath || findConfig() || await text({
120
- message: "Where is your configuration file located?",
121
- defaultValue: CONFIG_FILE_DEFAULT,
122
- placeholder: CONFIG_FILE_DEFAULT
123
- });
124
+ let configPath = __configPath || findConfig();
125
+ if (!configPath) {
126
+ requireInteractive(
127
+ "Pass the path to your Scalar configuration file to preview non-interactively."
128
+ );
129
+ const response = await text({
130
+ message: "Where is your configuration file located?",
131
+ defaultValue: CONFIG_FILE_DEFAULT,
132
+ placeholder: CONFIG_FILE_DEFAULT
133
+ });
134
+ if (isCancel(response)) return;
135
+ configPath = response;
136
+ }
124
137
  const parseConfigResult = readAndParseConfig(configPath);
125
138
  if (!parseConfigResult.success) {
126
139
  renderConfigError(parseConfigResult.error);
@@ -140,7 +153,8 @@ async function previewAction(__configPath, options) {
140
153
  configPath,
141
154
  config: config2,
142
155
  port: _port,
143
- host: options.host
156
+ host: options.host,
157
+ openBrowser: (options.open ?? true) && Boolean(process.stdin.isTTY) && !process.env.CI
144
158
  });
145
159
  return;
146
160
  }
@@ -1,24 +1,27 @@
1
1
  import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
2
  import {
3
3
  apiService
4
- } from "./chunk-UB3XGOUW.js";
5
- import "./chunk-FQVVKQPU.js";
6
- import "./chunk-B2MHTD3R.js";
7
- import "./chunk-3BWGTPPT.js";
8
- import "./chunk-M622VXRQ.js";
9
- import "./chunk-CIFOFSZ3.js";
10
- import "./chunk-NIXG4KDE.js";
11
- import "./chunk-JV7TUEXQ.js";
12
- import "./chunk-VNYE4R7N.js";
13
- import "./chunk-OQKDBLOZ.js";
4
+ } from "./chunk-EXY3ZTV4.js";
5
+ import "./chunk-KKRGBXCE.js";
6
+ import "./chunk-MLSZVVTT.js";
7
+ import "./chunk-FDC2IESH.js";
8
+ import "./chunk-C2KAWRIX.js";
9
+ import "./chunk-R5LK6VPY.js";
10
+ import "./chunk-QVQ4PNVL.js";
11
+ import "./chunk-UXJ753NV.js";
12
+ import "./chunk-5UHLAJQD.js";
13
+ import "./chunk-5JLVQVKO.js";
14
+ import {
15
+ requireInteractive
16
+ } from "./chunk-EGOXR5FB.js";
14
17
  import "./chunk-K74E42RV.js";
15
- import "./chunk-MNLXYOVF.js";
16
- import "./chunk-CX7ZRMTC.js";
18
+ import "./chunk-KCCFN4F7.js";
19
+ import "./chunk-6XWCMJDB.js";
17
20
  import "./chunk-4ORL4MST.js";
18
21
  import {
19
22
  output
20
23
  } from "./chunk-T5HJUAWB.js";
21
- import "./chunk-LQN4S62O.js";
24
+ import "./chunk-XEDGMZJD.js";
22
25
  import "./chunk-IKT5F47M.js";
23
26
  import "./chunk-3MZYUBJ6.js";
24
27
 
@@ -36,6 +39,9 @@ async function updateAction(namespace, slug, { title, description }) {
36
39
  let titleValue = title;
37
40
  let descriptionValue = description;
38
41
  const shouldPrompt = ![title, description].some((it) => it !== void 0);
42
+ if (shouldPrompt) {
43
+ requireInteractive("Please provide --title or --description.");
44
+ }
39
45
  if (!titleValue && shouldPrompt) {
40
46
  titleValue = await text({
41
47
  message: `What is the new title of your document? ${as.grey("(Optional)")}`
@@ -52,8 +58,7 @@ async function updateAction(namespace, slug, { title, description }) {
52
58
  const logger = output.info().line().loader("Updating the api document");
53
59
  const updateDocument = await client.managedDocs.update(namespace, slug, {
54
60
  title: titleValue,
55
- description: descriptionValue,
56
- isPrivate: false
61
+ description: descriptionValue
57
62
  });
58
63
  if (updateDocument.error) {
59
64
  return output.error().title(updateDocument.message).exit("error");