@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,197 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ getPublishDeploymentUrl
4
+ } from "./chunk-4NHMAG6F.js";
5
+ import {
6
+ getProjectDeployments
7
+ } from "./chunk-PT5TI77I.js";
8
+ import {
9
+ resolveProject
10
+ } from "./chunk-T7B6WNZC.js";
11
+ import {
12
+ formatAbsoluteTime
13
+ } from "./chunk-AEFPCC4U.js";
14
+ import "./chunk-XCSR4RIT.js";
15
+ import {
16
+ apiService
17
+ } from "./chunk-AO3F5XWR.js";
18
+ import "./chunk-F467BYYR.js";
19
+ import "./chunk-Z2KMGFE6.js";
20
+ import "./chunk-HCPN3KNF.js";
21
+ import "./chunk-B2MHTD3R.js";
22
+ import "./chunk-3L6DLIXJ.js";
23
+ import "./chunk-P7H7GY5A.js";
24
+ import "./chunk-HPL3ZZ2P.js";
25
+ import {
26
+ getAuthData
27
+ } from "./chunk-M37TP6U2.js";
28
+ import "./chunk-4ZDQXWBT.js";
29
+ import "./chunk-VNYE4R7N.js";
30
+ import "./chunk-OQKDBLOZ.js";
31
+ import "./chunk-K74E42RV.js";
32
+ import "./chunk-CISTON3A.js";
33
+ import "./chunk-Q7DOQHZN.js";
34
+ import "./chunk-4ORL4MST.js";
35
+ import {
36
+ output
37
+ } from "./chunk-T5HJUAWB.js";
38
+ import "./chunk-GSGZHE26.js";
39
+ import {
40
+ external_exports,
41
+ slugSchema
42
+ } from "./chunk-IKT5F47M.js";
43
+ import "./chunk-3MZYUBJ6.js";
44
+
45
+ // src/domains/project/rollback/action.ts
46
+ import { confirm } from "@clack/prompts";
47
+
48
+ // src/domains/project/rollback/select-rollback-target.ts
49
+ function selectRollbackTarget({
50
+ deployments,
51
+ activeUid,
52
+ to
53
+ }) {
54
+ const deployed = deployments.filter((record) => record.status === "deployed");
55
+ if (to) {
56
+ const target = deployed.find((record) => record.uid === to);
57
+ if (!target) {
58
+ const existing = deployments.find((record) => record.uid === to);
59
+ if (existing) {
60
+ return {
61
+ success: false,
62
+ error: {
63
+ code: "target-not-deployable",
64
+ uid: to,
65
+ status: existing.status
66
+ }
67
+ };
68
+ }
69
+ return { success: false, error: { code: "target-not-found", uid: to } };
70
+ }
71
+ if (target.uid === activeUid) {
72
+ return { success: false, error: { code: "already-live", uid: to } };
73
+ }
74
+ return { success: true, target };
75
+ }
76
+ if (deployed.length === 0) {
77
+ return { success: false, error: { code: "no-history" } };
78
+ }
79
+ if (!activeUid) {
80
+ return { success: false, error: { code: "no-live-deployment" } };
81
+ }
82
+ const liveIndex = deployed.findIndex((record) => record.uid === activeUid);
83
+ if (liveIndex === -1) {
84
+ return { success: false, error: { code: "no-live-deployment" } };
85
+ }
86
+ const previous = deployed[liveIndex + 1];
87
+ if (!previous) {
88
+ return { success: false, error: { code: "no-previous" } };
89
+ }
90
+ return { success: true, target: previous };
91
+ }
92
+
93
+ // src/domains/project/rollback/action.ts
94
+ var rollbackArgsSchema = external_exports.object({
95
+ slug: slugSchema.optional(),
96
+ to: external_exports.string().trim().min(1, "A build id is required for --to").optional(),
97
+ yes: external_exports.coerce.boolean().default(false)
98
+ });
99
+ async function rollbackAction(args) {
100
+ const argsParseResult = rollbackArgsSchema.safeParse(args);
101
+ if (argsParseResult.error) {
102
+ return output.error().title("Invalid Arguments").message(argsParseResult.error.issues[0].message).exit("error");
103
+ }
104
+ const { slug, to, yes } = argsParseResult.data;
105
+ if (!slug) {
106
+ return output.error().title("Invalid argument").message("Slug is required. Try passing --slug flag.").exit("error");
107
+ }
108
+ const apiClient = await apiService();
109
+ const auth = await getAuthData();
110
+ auth.addEventListener((state) => Object.assign(auth, state));
111
+ const resolved = await resolveProject(slug, apiClient);
112
+ if (resolved.kind === "not-found") {
113
+ return output.error().title("Project not found").message(`No project with slug "${slug}" was found for your team.`).exit("error");
114
+ }
115
+ const { project } = resolved;
116
+ const activeUid = project.activeDeployment?.uid ?? null;
117
+ const deploymentsResult = await getProjectDeployments({
118
+ teamUid: auth.teamUid,
119
+ projectUid: project.uid
120
+ });
121
+ if (!deploymentsResult.success) {
122
+ return output.error().title("Could not load deployment history").message(deploymentsResult.error).exit("error");
123
+ }
124
+ const targetResult = selectRollbackTarget({
125
+ deployments: deploymentsResult.deployments,
126
+ activeUid,
127
+ to
128
+ });
129
+ if (!targetResult.success) {
130
+ if (targetResult.error.code === "already-live") {
131
+ output.info().title("Already live").message(
132
+ `Build "${targetResult.error.uid}" is already the live deployment.`
133
+ ).print();
134
+ return;
135
+ }
136
+ return renderRollbackError(targetResult.error, slug);
137
+ }
138
+ const { target } = targetResult;
139
+ const deployedLabel = formatAbsoluteTime(
140
+ (target.deployedAt ?? target.createdAt) * 1e3
141
+ );
142
+ if (!yes) {
143
+ const shouldContinue = await confirm({
144
+ message: `Roll back the live deployment of "${slug}" to build ${target.uid} (${deployedLabel})?`,
145
+ initialValue: false
146
+ });
147
+ if (shouldContinue !== true) {
148
+ output.info().title("Rollback cancelled.").print();
149
+ return;
150
+ }
151
+ }
152
+ const logger = output.info({ animate: true }).loader(`Rolling back to build ${target.uid} (${deployedLabel})`);
153
+ const redeployResult = await apiClient.publish.redeploy(target.uid);
154
+ if (redeployResult.error) {
155
+ logger.update("loader", 0, {
156
+ content: `Rollback to build ${target.uid} failed`
157
+ });
158
+ logger.finish();
159
+ return output.error().title("Rollback failed").message(redeployResult.message).exit("error");
160
+ }
161
+ logger.update("loader", 0, {
162
+ content: `Rolled back to build ${target.uid} (${deployedLabel})`
163
+ });
164
+ logger.finish();
165
+ const deploymentUrl = getPublishDeploymentUrl(target);
166
+ if (deploymentUrl) {
167
+ output.info().line(`Deployment URL: ${deploymentUrl}`).print();
168
+ }
169
+ }
170
+ function renderRollbackError(error, slug) {
171
+ switch (error.code) {
172
+ case "no-history":
173
+ return output.error().title("Nothing to roll back to").message(
174
+ `Project "${slug}" has no previous deployed builds. Publish a build first.`
175
+ ).exit("error");
176
+ case "no-previous":
177
+ return output.error().title("Nothing to roll back to").message(
178
+ `Project "${slug}" is already on its oldest deployed build, so there is no earlier build to roll back to. Run "scalar project deployments list --slug ${slug}" to see all builds, then pass --to <buildId> to deploy a specific one.`
179
+ ).exit("error");
180
+ case "no-live-deployment":
181
+ return output.error().title("No live deployment").message(
182
+ `Project "${slug}" has no build currently live, so there is no default to roll back to. Pass --to <buildId> to pick a specific build. Run "scalar project deployments list --slug ${slug}" to see available builds.`
183
+ ).exit("error");
184
+ case "target-not-found":
185
+ return output.error().title("Build not found").message(
186
+ `No deployed build with id "${error.uid}" was found. Run "scalar project deployments list --slug ${slug}" to see available builds.`
187
+ ).exit("error");
188
+ case "target-not-deployable":
189
+ return output.error().title("Build cannot be made live").message(
190
+ `Build "${error.uid}" has status "${error.status}", so it never finished deploying and cannot be rolled back to. Only builds with status "deployed" can be made live.`
191
+ ).exit("error");
192
+ }
193
+ }
194
+ export {
195
+ rollbackAction,
196
+ rollbackArgsSchema
197
+ };
@@ -0,0 +1,132 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ DASHBOARD_CHAT_CONTEXT_MAX_CHARS,
4
+ DASHBOARD_CHAT_MAX_MESSAGES,
5
+ DASHBOARD_EDITOR_CONTEXT_KEY,
6
+ DASHBOARD_EDITOR_TOOL_NAMES,
7
+ DASHBOARD_SDK_CONTEXT_KEY,
8
+ DASHBOARD_SDK_TOOL_NAMES,
9
+ agentApi,
10
+ agentApiErrorSchema,
11
+ analyticsGranularitySchema,
12
+ analyticsRangeSchema,
13
+ analyticsRoutes,
14
+ bumpKindSchema,
15
+ bumpStrategySchema,
16
+ dashboardChatBodySchema,
17
+ dashboardChatSettingsSchema,
18
+ dashboardRoutes,
19
+ docsChatContextSchema,
20
+ docsProjectAgentInfoSchema,
21
+ docsRoutes,
22
+ editorChatBodySchema,
23
+ editorRoutes,
24
+ installationParamSchema,
25
+ installationSummarySchema,
26
+ installationToolSchema,
27
+ internalRoutes,
28
+ mcpAnalyticsParamsSchema,
29
+ mcpCategoryTotalsSchema,
30
+ mcpConsumerKindSchema,
31
+ mcpConsumerStatSchema,
32
+ mcpConsumersResultSchema,
33
+ mcpDocsPageToolDetailSchema,
34
+ mcpErrorEntrySchema,
35
+ mcpErrorsResultSchema,
36
+ mcpExportDatasetSchema,
37
+ mcpInstallationRoutes,
38
+ mcpLatencyByToolEntrySchema,
39
+ mcpLatencyResultSchema,
40
+ mcpOperationToolDetailSchema,
41
+ mcpOverviewResultSchema,
42
+ mcpOverviewTotalsSchema,
43
+ mcpServerRoutes,
44
+ mcpServerWithInstallationsSchema,
45
+ mcpTimeseriesPointSchema,
46
+ mcpToolCategorySchema,
47
+ mcpToolKindSchema,
48
+ mcpToolStatSchema,
49
+ mcpToolsResultSchema,
50
+ mcpVersionRoutes,
51
+ mcpVersionToolsSchema,
52
+ openapiRoutes,
53
+ pubsubPushMessageSchema,
54
+ pubsubRoutes,
55
+ pullRequestDescriptionBodySchema,
56
+ registryDocumentSchema,
57
+ registryRoutes,
58
+ registrySearchResultSchema,
59
+ registryVersionOperationSchema,
60
+ semverParamSchema,
61
+ teamUsageResponseSchema,
62
+ usageRecordSchema,
63
+ usageRoutes
64
+ } from "./chunk-HPL3ZZ2P.js";
65
+ import "./chunk-VNYE4R7N.js";
66
+ import "./chunk-OQKDBLOZ.js";
67
+ import "./chunk-GSGZHE26.js";
68
+ import "./chunk-IKT5F47M.js";
69
+ import "./chunk-3MZYUBJ6.js";
70
+ export {
71
+ DASHBOARD_CHAT_CONTEXT_MAX_CHARS,
72
+ DASHBOARD_CHAT_MAX_MESSAGES,
73
+ DASHBOARD_EDITOR_CONTEXT_KEY,
74
+ DASHBOARD_EDITOR_TOOL_NAMES,
75
+ DASHBOARD_SDK_CONTEXT_KEY,
76
+ DASHBOARD_SDK_TOOL_NAMES,
77
+ agentApi,
78
+ agentApiErrorSchema,
79
+ analyticsGranularitySchema,
80
+ analyticsRangeSchema,
81
+ analyticsRoutes,
82
+ bumpKindSchema,
83
+ bumpStrategySchema,
84
+ dashboardChatBodySchema,
85
+ dashboardChatSettingsSchema,
86
+ dashboardRoutes,
87
+ docsChatContextSchema,
88
+ docsProjectAgentInfoSchema,
89
+ docsRoutes,
90
+ editorChatBodySchema,
91
+ editorRoutes,
92
+ installationParamSchema,
93
+ installationSummarySchema,
94
+ installationToolSchema,
95
+ internalRoutes,
96
+ mcpAnalyticsParamsSchema,
97
+ mcpCategoryTotalsSchema,
98
+ mcpConsumerKindSchema,
99
+ mcpConsumerStatSchema,
100
+ mcpConsumersResultSchema,
101
+ mcpDocsPageToolDetailSchema,
102
+ mcpErrorEntrySchema,
103
+ mcpErrorsResultSchema,
104
+ mcpExportDatasetSchema,
105
+ mcpInstallationRoutes,
106
+ mcpLatencyByToolEntrySchema,
107
+ mcpLatencyResultSchema,
108
+ mcpOperationToolDetailSchema,
109
+ mcpOverviewResultSchema,
110
+ mcpOverviewTotalsSchema,
111
+ mcpServerRoutes,
112
+ mcpServerWithInstallationsSchema,
113
+ mcpTimeseriesPointSchema,
114
+ mcpToolCategorySchema,
115
+ mcpToolKindSchema,
116
+ mcpToolStatSchema,
117
+ mcpToolsResultSchema,
118
+ mcpVersionRoutes,
119
+ mcpVersionToolsSchema,
120
+ openapiRoutes,
121
+ pubsubPushMessageSchema,
122
+ pubsubRoutes,
123
+ pullRequestDescriptionBodySchema,
124
+ registryDocumentSchema,
125
+ registryRoutes,
126
+ registrySearchResultSchema,
127
+ registryVersionOperationSchema,
128
+ semverParamSchema,
129
+ teamUsageResponseSchema,
130
+ usageRecordSchema,
131
+ usageRoutes
132
+ };
@@ -0,0 +1,105 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ isAsyncApiDocument,
4
+ isDocument
5
+ } from "./chunk-24WAOKGG.js";
6
+ import {
7
+ watchFile
8
+ } from "./chunk-M37TP6U2.js";
9
+ import "./chunk-4ZDQXWBT.js";
10
+ import "./chunk-VNYE4R7N.js";
11
+ import "./chunk-OQKDBLOZ.js";
12
+ import "./chunk-CISTON3A.js";
13
+ import "./chunk-Q7DOQHZN.js";
14
+ import "./chunk-4ORL4MST.js";
15
+ import {
16
+ output
17
+ } from "./chunk-T5HJUAWB.js";
18
+ import "./chunk-GSGZHE26.js";
19
+ import "./chunk-IKT5F47M.js";
20
+ import "./chunk-3MZYUBJ6.js";
21
+
22
+ // src/domains/document/mock/asyncapi.ts
23
+ import { serve } from "@hono/node-server";
24
+ import { upgrade } from "@scalar/asyncapi-upgrader";
25
+ import { validate } from "@scalar/asyncapi-validator";
26
+ import { bundle } from "@scalar/json-magic/bundle";
27
+ import { fetchUrls, readFiles } from "@scalar/json-magic/bundle/plugins/node";
28
+ import { createAsyncApiMockServer } from "@scalar/mock-server";
29
+ var loadAsyncApiMockDocument = async (input) => {
30
+ const document = await bundle(input, {
31
+ plugins: [readFiles(), fetchUrls()],
32
+ treeShake: false
33
+ });
34
+ if (!isDocument(document) || !isAsyncApiDocument(document)) {
35
+ throw new Error("Expected an AsyncAPI document");
36
+ }
37
+ const result = validate(document);
38
+ if (!result.valid) {
39
+ throw new Error("Invalid AsyncAPI document");
40
+ }
41
+ return upgrade(document);
42
+ };
43
+ var mockAsyncApi = async (input, options) => {
44
+ const document = await loadAsyncApiMockDocument(input).catch(
45
+ (error) => {
46
+ output.error().title(error.message).exit("error");
47
+ }
48
+ );
49
+ if (!document) return;
50
+ const connections = /* @__PURE__ */ new Set();
51
+ const start = async (nextDocument) => {
52
+ const { app, injectWebSocket } = await createAsyncApiMockServer({
53
+ document: nextDocument,
54
+ logger: (line) => output.info().line(line).print(),
55
+ onMessage: ({ channel, direction }) => {
56
+ output.info().line(`${direction} ${channel}`).print();
57
+ }
58
+ });
59
+ const server2 = serve(
60
+ { fetch: app.fetch, port: options.port ?? 3e3 },
61
+ ({ port }) => {
62
+ output.info().line(`AsyncAPI Mock Server listening on http://localhost:${port}`).print();
63
+ }
64
+ );
65
+ server2.on("connection", (socket) => {
66
+ connections.add(socket);
67
+ socket.once("close", () => connections.delete(socket));
68
+ });
69
+ injectWebSocket(server2);
70
+ return server2;
71
+ };
72
+ let server = await start(document);
73
+ let current = JSON.stringify(document);
74
+ let reloading = false;
75
+ const watcher = options.watch && !options.once ? await watchFile(input, async () => {
76
+ if (reloading) return;
77
+ reloading = true;
78
+ try {
79
+ const nextDocument = await loadAsyncApiMockDocument(input);
80
+ const serialized = JSON.stringify(nextDocument);
81
+ if (serialized === current) return;
82
+ await new Promise((resolve, reject) => {
83
+ server.close((error) => error ? reject(error) : resolve());
84
+ for (const socket of connections) socket.destroy();
85
+ });
86
+ server = await start(nextDocument);
87
+ current = serialized;
88
+ } catch (error) {
89
+ output.warn().title(String(error)).print();
90
+ } finally {
91
+ reloading = false;
92
+ }
93
+ }) : void 0;
94
+ if (options.once) {
95
+ setTimeout(() => {
96
+ void watcher?.unsubscribe();
97
+ server.close();
98
+ for (const socket of connections) socket.destroy();
99
+ }, 2e3);
100
+ }
101
+ };
102
+ export {
103
+ loadAsyncApiMockDocument,
104
+ mockAsyncApi
105
+ };
@@ -0,0 +1,108 @@
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 {
14
+ sdkSchema
15
+ } from "./chunk-3L6DLIXJ.js";
16
+ import "./chunk-P7H7GY5A.js";
17
+ import "./chunk-HPL3ZZ2P.js";
18
+ import {
19
+ getAuthData
20
+ } from "./chunk-M37TP6U2.js";
21
+ import "./chunk-4ZDQXWBT.js";
22
+ import {
23
+ teamSchema
24
+ } from "./chunk-VNYE4R7N.js";
25
+ import "./chunk-OQKDBLOZ.js";
26
+ import "./chunk-K74E42RV.js";
27
+ import "./chunk-CISTON3A.js";
28
+ import "./chunk-Q7DOQHZN.js";
29
+ import "./chunk-4ORL4MST.js";
30
+ import {
31
+ output
32
+ } from "./chunk-T5HJUAWB.js";
33
+ import "./chunk-GSGZHE26.js";
34
+ import {
35
+ docVersionSchema,
36
+ external_exports,
37
+ namespaceSchema,
38
+ slugSchema
39
+ } from "./chunk-IKT5F47M.js";
40
+ import "./chunk-3MZYUBJ6.js";
41
+
42
+ // src/domains/sdk/build.action.ts
43
+ import { select } from "@clack/prompts";
44
+ async function buildAction(opts) {
45
+ const { error, data } = external_exports.object({
46
+ slug: slugSchema.optional(),
47
+ namespace: namespaceSchema.optional(),
48
+ version: docVersionSchema.optional()
49
+ }).safeParse(opts);
50
+ if (error)
51
+ return output.error().title("Invalid input").message(error.issues[0].message).exit("error");
52
+ const auth = await getAuthData();
53
+ auth.addEventListener((state) => Object.assign(auth, state));
54
+ const db = await getDatabaseClient();
55
+ const client = await apiService();
56
+ const team = await db.getOne({
57
+ collectionPath: BaseCollections.Teams,
58
+ query: {
59
+ uid: auth.teamUid
60
+ },
61
+ schema: teamSchema
62
+ });
63
+ if (team.error)
64
+ return output.error().title("An error occurred when fetching your team.").message(team.message).exit("error");
65
+ const namespace = data.namespace || team.data.namespaces.at(0);
66
+ if (!namespace) {
67
+ return output.error().title("Missing namespace").message(
68
+ "Could not find a valid namespace for your SDK. Please specify a namespace or contact support."
69
+ ).exit("error");
70
+ }
71
+ const sdks = await db.getMany({
72
+ collectionPath: BaseCollections.Sdks(team.data.uid),
73
+ query: {
74
+ namespace
75
+ },
76
+ schema: sdkSchema.array()
77
+ });
78
+ if (sdks.error) return output.error().title(sdks.message).exit("error");
79
+ const sdkUid = sdks.data.find((sdk) => sdk.slug === data.slug)?.uid || await select({
80
+ message: "Please select an SDK to update",
81
+ options: sdks.data.map((sdk) => ({
82
+ value: sdk.uid,
83
+ label: sdk.slug
84
+ }))
85
+ });
86
+ const matchingSdk = sdks.data.find((sdk) => sdk.uid === sdkUid);
87
+ if (!matchingSdk) {
88
+ return output.error().title("No SDK found").message("Please provide a valid SDK slug").exit("error");
89
+ }
90
+ const version = matchingSdk.versions.find((v) => v.version === data.version)?.version || await select({
91
+ message: "Please select an SDK version to build",
92
+ options: matchingSdk.versions.map((version2) => ({
93
+ value: version2.version,
94
+ label: `v${version2.version}`
95
+ }))
96
+ });
97
+ const logger = output.info().loader("Creating SDK Build");
98
+ const response = await client.sdks.build(sdkUid, version);
99
+ if (response.error) {
100
+ return output.error().title("Something went wrong").message(response.message).exit("error");
101
+ }
102
+ logger.update("loader", 0, {
103
+ content: `SDK build kicked off for version v${version}`
104
+ }).exit("success");
105
+ }
106
+ export {
107
+ buildAction
108
+ };
@@ -0,0 +1,105 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ detectManagedDocType
4
+ } from "./chunk-CISTON3A.js";
5
+ import {
6
+ isUrl
7
+ } from "./chunk-4ORL4MST.js";
8
+ import {
9
+ output
10
+ } from "./chunk-T5HJUAWB.js";
11
+
12
+ // src/domains/document/helpers/banner.ts
13
+ import as from "ansis";
14
+ var printSpecificationBanner = (result) => {
15
+ const { version, schema } = result;
16
+ if (!schema?.info?.title || !version) {
17
+ return;
18
+ }
19
+ const pathsCount = Object.keys(schema.paths ?? {}).length;
20
+ const operationsCount = Object.values(schema.paths ?? {}).reduce(
21
+ (acc, path) => acc + Object.keys(path).length,
22
+ 0
23
+ );
24
+ output.info().title(
25
+ `${as.white.bold(schema?.info?.title)} ${as.grey(`(OpenAPI v${version})`)}`
26
+ ).title(as.grey(`${pathsCount} paths, ${operationsCount} operations`)).print();
27
+ };
28
+
29
+ // src/domains/document/helpers/safe-normalize.ts
30
+ import { normalize } from "@scalar/json-magic/helpers/normalize";
31
+ var safeNormalize = (value) => {
32
+ try {
33
+ return normalize(value);
34
+ } catch {
35
+ return void 0;
36
+ }
37
+ };
38
+
39
+ // src/domains/document/helpers/document-type.ts
40
+ var isAsyncApiDocument = (document) => detectManagedDocType(document) === "asyncapi";
41
+ var isAsyncApiContent = (content) => content.includes("asyncapi") && isAsyncApiDocument(safeNormalize(content));
42
+
43
+ // src/domains/document/helpers/imports.ts
44
+ import fs from "node:fs";
45
+ import as2 from "ansis";
46
+ import { load, validate } from "@scalar/openapi-parser";
47
+ var getFileOrUrl = async (input) => {
48
+ if (isUrl(input)) {
49
+ const response = await fetch(input);
50
+ if (!response.ok) {
51
+ return output.error().title("Failed to fetch from URL.").exit("error");
52
+ }
53
+ return await response.text();
54
+ }
55
+ if (!fs.existsSync(input)) {
56
+ return output.error().title("Could not read file.").exit("error");
57
+ }
58
+ return fs.readFileSync(input, "utf-8");
59
+ };
60
+ var loadOpenApiFile = async (input) => {
61
+ return loadOpenApiDocument(await getFileOrUrl(input));
62
+ };
63
+ var loadOpenApiDocument = async (specification) => {
64
+ try {
65
+ const { filesystem } = await load(specification);
66
+ const result = await validate(filesystem);
67
+ if (!result.valid) {
68
+ output.warn().title("File does not match the OpenAPI specification.").print();
69
+ result.errors?.forEach((error) => {
70
+ output.warn().title(`${error.message} (${error.path})`).print();
71
+ });
72
+ return result;
73
+ }
74
+ return result;
75
+ } catch (error) {
76
+ output.error().title(error ? as2.red(error.toString()) : "Unknown error.").print();
77
+ const message = typeof error === "object" && error !== null && "message" in error ? String(error.message) : "Unknown error";
78
+ return {
79
+ valid: false,
80
+ version: void 0,
81
+ specification: void 0,
82
+ schema: void 0,
83
+ errors: [
84
+ {
85
+ message,
86
+ path: []
87
+ }
88
+ ]
89
+ };
90
+ }
91
+ };
92
+
93
+ // src/domains/document/helpers/is-document.ts
94
+ var isDocument = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
95
+
96
+ export {
97
+ printSpecificationBanner,
98
+ safeNormalize,
99
+ isAsyncApiDocument,
100
+ isAsyncApiContent,
101
+ getFileOrUrl,
102
+ loadOpenApiFile,
103
+ loadOpenApiDocument,
104
+ isDocument
105
+ };