@scalar/cli 2.0.1 → 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.
- package/README.md +40 -0
- package/chunks/action-45OGQB2M.js +138 -0
- package/chunks/action-5R5FDF6S.js +2097 -0
- package/chunks/action-ANU5HGC4.js +34 -0
- package/chunks/action-BMFXENMX.js +176 -0
- package/chunks/action-BNEGJBUH.js +38 -0
- package/chunks/action-BYZUBXVB.js +82 -0
- package/chunks/action-C5VB4ITT.js +132 -0
- package/chunks/action-CCW66QJN.js +72 -0
- package/chunks/action-CLSD7O2R.js +60 -0
- package/chunks/action-CQ56FVES.js +65 -0
- package/chunks/action-CYP4VDK3.js +148 -0
- package/chunks/action-DFKHSDFV.js +36 -0
- package/chunks/action-F4Y6Q2VB.js +92 -0
- package/chunks/action-GB6DM53B.js +70 -0
- package/chunks/action-GEBRPNRT.js +87 -0
- package/chunks/action-H5OHT2GV.js +56 -0
- package/chunks/action-HD2T6BFJ.js +54 -0
- package/chunks/action-HNKM3Q65.js +65 -0
- package/chunks/action-JOSVV6YA.js +71 -0
- package/chunks/action-MENXFJH3.js +204 -0
- package/chunks/action-P7LN6FGY.js +13 -0
- package/chunks/action-PVDDRIM6.js +130 -0
- package/chunks/action-Q5UJ32D6.js +46 -0
- package/chunks/action-R6ZZO26F.js +299 -0
- package/chunks/action-STIEAXOE.js +53 -0
- package/chunks/action-TPBKPHNS.js +110 -0
- package/chunks/action-TWFJNQ2R.js +95 -0
- package/chunks/action-TZ5KGAQT.js +64 -0
- package/chunks/action-UDZUUJSI.js +49 -0
- package/chunks/action-W5BATF4Q.js +197 -0
- package/chunks/agent-XGLOHXNA.js +112 -0
- package/chunks/build.action-LKOILPA6.js +108 -0
- package/chunks/chunk-23I5PKZZ.js +78 -0
- package/chunks/chunk-2BSG2QHO.js +455 -0
- package/chunks/chunk-3MZYUBJ6.js +49 -0
- package/chunks/chunk-47Y4L5IT.js +63361 -0
- package/chunks/chunk-4DGQIAJX.js +359 -0
- package/chunks/chunk-4QS7SJTG.js +138 -0
- package/chunks/chunk-5BISXQX4.js +447 -0
- package/chunks/chunk-5BPPGTUU.js +463 -0
- package/chunks/chunk-AEFPCC4U.js +16 -0
- package/chunks/chunk-AHWWJ3MD.js +32 -0
- package/chunks/chunk-ASMHW5AY.js +19 -0
- package/chunks/chunk-B6QZJWCQ.js +92 -0
- package/chunks/chunk-DOVIWNKQ.js +108 -0
- package/chunks/chunk-H2WRMLYY.js +13780 -0
- package/chunks/chunk-HQKBZOYU.js +34 -0
- package/chunks/chunk-ISGLWBXZ.js +4265 -0
- package/chunks/chunk-IX7LJ3AD.js +17 -0
- package/chunks/chunk-JFIXNSPP.js +26 -0
- package/chunks/chunk-K74E42RV.js +7311 -0
- package/chunks/chunk-KHDYYVYF.js +16 -0
- package/chunks/chunk-KWOL7A6J.js +23 -0
- package/chunks/chunk-NUXPNUSS.js +38 -0
- package/chunks/chunk-OAXFCOJV.js +25 -0
- package/chunks/chunk-P2VH7DOC.js +107 -0
- package/chunks/chunk-P646T2WH.js +1608 -0
- package/chunks/chunk-SHSHFGA7.js +297 -0
- package/chunks/chunk-SXYALPYK.js +2709 -0
- package/chunks/chunk-T7B6WNZC.js +18 -0
- package/chunks/chunk-T7MDADON.js +17 -0
- package/chunks/chunk-TLFMATXR.js +344 -0
- package/chunks/chunk-TQ5XC2E3.js +284 -0
- package/chunks/chunk-UPUTMFD4.js +465 -0
- package/chunks/chunk-VTYTPSXO.js +161 -0
- package/chunks/chunk-X4QLDBB5.js +221 -0
- package/chunks/chunk-ZTVWAKNJ.js +21 -0
- package/chunks/create.action-FFQLBSJH.js +108 -0
- package/chunks/delete.action-QNN3LC2F.js +96 -0
- package/chunks/delete.action-STHQHP4F.js +88 -0
- package/chunks/get.action-OTKYOP3Z.js +87 -0
- package/chunks/list.action-6I5EZAVB.js +95 -0
- package/chunks/list.action-KDM5RHEH.js +116 -0
- package/chunks/publish.action-PODTVRXS.js +182 -0
- package/chunks/update.action-4F6STTEQ.js +101 -0
- package/chunks/update.action-KMD4ZM75.js +95 -0
- package/docs.html +310 -209
- package/index.js +645 -99061
- package/package.json +13 -11
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/helpers/std-out/print-table.ts
|
|
4
|
+
import { Table } from "console-table-printer";
|
|
5
|
+
var printTable = (columns, rows) => {
|
|
6
|
+
const table2 = new Table({ columns });
|
|
7
|
+
for (const row of rows) {
|
|
8
|
+
table2.addRow(row);
|
|
9
|
+
}
|
|
10
|
+
table2.printTable();
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// src/helpers/std-out/output.ts
|
|
14
|
+
import as from "ansis";
|
|
15
|
+
import UpdateManager from "stdout-update";
|
|
16
|
+
|
|
17
|
+
// ../../node_modules/.pnpm/ansi-regex@6.2.2/node_modules/ansi-regex/index.js
|
|
18
|
+
function ansiRegex({ onlyFirst = false } = {}) {
|
|
19
|
+
const ST = "(?:\\u0007|\\u001B\\u005C|\\u009C)";
|
|
20
|
+
const osc = `(?:\\u001B\\][\\s\\S]*?${ST})`;
|
|
21
|
+
const csi = "[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]";
|
|
22
|
+
const pattern = `${osc}|${csi}`;
|
|
23
|
+
return new RegExp(pattern, onlyFirst ? void 0 : "g");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// ../../node_modules/.pnpm/strip-ansi@7.2.0/node_modules/strip-ansi/index.js
|
|
27
|
+
var regex = ansiRegex();
|
|
28
|
+
function stripAnsi(string) {
|
|
29
|
+
if (typeof string !== "string") {
|
|
30
|
+
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
|
|
31
|
+
}
|
|
32
|
+
if (!string.includes("\x1B") && !string.includes("\x9B")) {
|
|
33
|
+
return string;
|
|
34
|
+
}
|
|
35
|
+
return string.replace(regex, "");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// src/helpers/std-out/table.ts
|
|
39
|
+
var table = (data, options) => {
|
|
40
|
+
let maxCols = 0;
|
|
41
|
+
data.forEach((row) => {
|
|
42
|
+
if (row.length > maxCols) {
|
|
43
|
+
maxCols = row.length;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
const maxLengths = new Array(maxCols).fill(0);
|
|
47
|
+
for (const i of data.keys()) {
|
|
48
|
+
for (const j of data[i].keys()) {
|
|
49
|
+
if (stripAnsi(data[i][j]).length > maxLengths[j]) {
|
|
50
|
+
maxLengths[j] = stripAnsi(data[i][j]).length;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
for (const row of data) {
|
|
55
|
+
for (const [index, col] of row.entries()) {
|
|
56
|
+
const lengthDiff = col.length - stripAnsi(col).length;
|
|
57
|
+
row[index] = col.padEnd(
|
|
58
|
+
maxLengths[index] + (options?.padding ?? 1) + lengthDiff
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// src/helpers/std-out/output.ts
|
|
65
|
+
var levelColors = {
|
|
66
|
+
info: (s) => s,
|
|
67
|
+
warn: as.yellow,
|
|
68
|
+
error: as.red
|
|
69
|
+
};
|
|
70
|
+
var levelPrefixes = {
|
|
71
|
+
info: "",
|
|
72
|
+
warn: "[WARN]",
|
|
73
|
+
error: "[ERROR]"
|
|
74
|
+
};
|
|
75
|
+
var outputFactory = (level) => (options) => {
|
|
76
|
+
const titlePrefix = levelPrefixes[level];
|
|
77
|
+
const cl = levelColors[level];
|
|
78
|
+
const manager = UpdateManager.getInstance();
|
|
79
|
+
const state = [];
|
|
80
|
+
let i = 0;
|
|
81
|
+
const frames = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
82
|
+
function update(complete) {
|
|
83
|
+
i += 1;
|
|
84
|
+
manager.update(
|
|
85
|
+
state.map((it) => {
|
|
86
|
+
if (it.type === "title") {
|
|
87
|
+
return cl(as.bold(`${titlePrefix} ${it.content}`));
|
|
88
|
+
}
|
|
89
|
+
if (it.type === "loader") {
|
|
90
|
+
return complete ? cl(`\u2714 ${it.content}`) : cl(`${frames[i % frames.length]} ${it.content}`);
|
|
91
|
+
}
|
|
92
|
+
if (it.type === "table") {
|
|
93
|
+
return it.content.map((it2) => cl(it2.join(""))).join("\n");
|
|
94
|
+
}
|
|
95
|
+
return cl(it.content);
|
|
96
|
+
})
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
manager.hook();
|
|
100
|
+
const interval = setInterval(() => {
|
|
101
|
+
update();
|
|
102
|
+
}, options?.frameRate ?? 100);
|
|
103
|
+
function end() {
|
|
104
|
+
update(true);
|
|
105
|
+
process.stdout.write("");
|
|
106
|
+
manager.unhook();
|
|
107
|
+
clearInterval(interval);
|
|
108
|
+
return { state };
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
/** Current list of std-out state objects */
|
|
112
|
+
state,
|
|
113
|
+
/** Display a formatted title */
|
|
114
|
+
title: function(title) {
|
|
115
|
+
state.push({
|
|
116
|
+
type: "title",
|
|
117
|
+
content: title
|
|
118
|
+
});
|
|
119
|
+
return this;
|
|
120
|
+
},
|
|
121
|
+
/** Display a new line with the provided content */
|
|
122
|
+
line: function(content) {
|
|
123
|
+
state.push({
|
|
124
|
+
type: "line",
|
|
125
|
+
content: content ?? ""
|
|
126
|
+
});
|
|
127
|
+
return this;
|
|
128
|
+
},
|
|
129
|
+
/** Display a message with a line above and below */
|
|
130
|
+
message: function(content) {
|
|
131
|
+
state.push(
|
|
132
|
+
{
|
|
133
|
+
type: "line",
|
|
134
|
+
content: ""
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
type: "line",
|
|
138
|
+
content: content ?? ""
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
type: "line",
|
|
142
|
+
content: ""
|
|
143
|
+
}
|
|
144
|
+
);
|
|
145
|
+
return this;
|
|
146
|
+
},
|
|
147
|
+
/** Display a loader with a message alongside. */
|
|
148
|
+
loader: function(content) {
|
|
149
|
+
state.push({
|
|
150
|
+
type: "loader",
|
|
151
|
+
content: content ?? ""
|
|
152
|
+
});
|
|
153
|
+
return this;
|
|
154
|
+
},
|
|
155
|
+
/**
|
|
156
|
+
* Update a specific line of a specific type
|
|
157
|
+
* Only works when animate is set to true
|
|
158
|
+
*/
|
|
159
|
+
update: function(type, index, values) {
|
|
160
|
+
const operation = state.filter((it) => it.type === type)[index];
|
|
161
|
+
if (operation) {
|
|
162
|
+
Object.assign(operation, values);
|
|
163
|
+
}
|
|
164
|
+
if (operation.type === "table") {
|
|
165
|
+
table(operation.content, operation.options);
|
|
166
|
+
}
|
|
167
|
+
return this;
|
|
168
|
+
},
|
|
169
|
+
/**
|
|
170
|
+
* Delete a specific line of a specific type
|
|
171
|
+
* Only works when the animate is set to true
|
|
172
|
+
*/
|
|
173
|
+
delete: function(type, index) {
|
|
174
|
+
let count = 0;
|
|
175
|
+
for (let i2 = 0; i2 < state.length; i2++) {
|
|
176
|
+
if (state[i2].type === type) {
|
|
177
|
+
if (count === index) {
|
|
178
|
+
state.splice(i2, 1);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
count++;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return this;
|
|
185
|
+
},
|
|
186
|
+
/** Display a table that handles padding column widths automatically */
|
|
187
|
+
table: function(data, opt) {
|
|
188
|
+
table(data, opt);
|
|
189
|
+
state.push({
|
|
190
|
+
type: "table",
|
|
191
|
+
content: data,
|
|
192
|
+
options: opt
|
|
193
|
+
});
|
|
194
|
+
return this;
|
|
195
|
+
},
|
|
196
|
+
/** Print the current state to the console */
|
|
197
|
+
print: end,
|
|
198
|
+
/**
|
|
199
|
+
* Finish a log block and unhook from the std-out manager
|
|
200
|
+
* This closes out a running animation
|
|
201
|
+
*/
|
|
202
|
+
finish: end,
|
|
203
|
+
/** Exit the process with a success code */
|
|
204
|
+
exit: (code) => {
|
|
205
|
+
end();
|
|
206
|
+
return process.exit(code === "error" ? 1 : 0);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
// src/helpers/std-out/index.ts
|
|
212
|
+
var output = {
|
|
213
|
+
error: outputFactory("error"),
|
|
214
|
+
warn: outputFactory("warn"),
|
|
215
|
+
info: outputFactory("info")
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export {
|
|
219
|
+
printTable,
|
|
220
|
+
output
|
|
221
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
getPublishPreviewUrl,
|
|
4
|
+
getPublishUrl
|
|
5
|
+
} from "./chunk-DOVIWNKQ.js";
|
|
6
|
+
|
|
7
|
+
// src/domains/project/publish/url.ts
|
|
8
|
+
function getPublishDeploymentUrl(publish) {
|
|
9
|
+
try {
|
|
10
|
+
if (publish.preview) {
|
|
11
|
+
return getPublishPreviewUrl(publish.uid, publish.domain, publish.subpath);
|
|
12
|
+
}
|
|
13
|
+
return getPublishUrl(publish.domain, publish.subpath);
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
getPublishDeploymentUrl
|
|
21
|
+
};
|
|
@@ -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-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 {
|
|
14
|
+
SdkLanguage
|
|
15
|
+
} from "./chunk-5BPPGTUU.js";
|
|
16
|
+
import "./chunk-P646T2WH.js";
|
|
17
|
+
import "./chunk-4QS7SJTG.js";
|
|
18
|
+
import "./chunk-VTYTPSXO.js";
|
|
19
|
+
import {
|
|
20
|
+
getAuthData
|
|
21
|
+
} from "./chunk-5BISXQX4.js";
|
|
22
|
+
import {
|
|
23
|
+
config
|
|
24
|
+
} from "./chunk-OAXFCOJV.js";
|
|
25
|
+
import "./chunk-TLFMATXR.js";
|
|
26
|
+
import {
|
|
27
|
+
teamSchema
|
|
28
|
+
} from "./chunk-4DGQIAJX.js";
|
|
29
|
+
import {
|
|
30
|
+
namespaceSchema,
|
|
31
|
+
slugSchema
|
|
32
|
+
} from "./chunk-ISGLWBXZ.js";
|
|
33
|
+
import {
|
|
34
|
+
external_exports
|
|
35
|
+
} from "./chunk-H2WRMLYY.js";
|
|
36
|
+
import "./chunk-K74E42RV.js";
|
|
37
|
+
import "./chunk-IX7LJ3AD.js";
|
|
38
|
+
import {
|
|
39
|
+
output
|
|
40
|
+
} from "./chunk-X4QLDBB5.js";
|
|
41
|
+
import "./chunk-3MZYUBJ6.js";
|
|
42
|
+
|
|
43
|
+
// src/domains/sdk/create.action.ts
|
|
44
|
+
import { select, text } from "@clack/prompts";
|
|
45
|
+
import as from "ansis";
|
|
46
|
+
async function createAction(opts) {
|
|
47
|
+
const { error, data } = external_exports.object({
|
|
48
|
+
namespace: namespaceSchema.optional(),
|
|
49
|
+
language: external_exports.enum(SdkLanguage).optional(),
|
|
50
|
+
api: slugSchema.optional()
|
|
51
|
+
}).safeParse(opts);
|
|
52
|
+
if (error)
|
|
53
|
+
return output.error().title("Invalid input").message(error.issues[0].message).exit("error");
|
|
54
|
+
const auth = await getAuthData();
|
|
55
|
+
auth.addEventListener((state) => Object.assign(auth, state));
|
|
56
|
+
const db = await getDatabaseClient();
|
|
57
|
+
const client = await apiService();
|
|
58
|
+
const language = opts.language || await text({
|
|
59
|
+
message: "Please choose a language for your SDK",
|
|
60
|
+
placeholder: "typescript",
|
|
61
|
+
validate: (v) => {
|
|
62
|
+
return external_exports.enum(SdkLanguage).safeParse(v)?.error ? "Please select a valid language" : void 0;
|
|
63
|
+
},
|
|
64
|
+
defaultValue: void 0
|
|
65
|
+
});
|
|
66
|
+
const team = await db.getOne({
|
|
67
|
+
collectionPath: BaseCollections.Teams,
|
|
68
|
+
query: {
|
|
69
|
+
uid: auth.teamUid
|
|
70
|
+
},
|
|
71
|
+
schema: teamSchema
|
|
72
|
+
});
|
|
73
|
+
if (team.error)
|
|
74
|
+
return output.error().title("An error occurred when fetching your team.").message(team.message).exit("error");
|
|
75
|
+
const namespace = data.namespace || team.data.namespaces.at(0);
|
|
76
|
+
if (!namespace) {
|
|
77
|
+
return output.error().title("Missing namespace").message(
|
|
78
|
+
"Could not find a valid namespace for your API. Please specify a namespace or contact support."
|
|
79
|
+
).exit("error");
|
|
80
|
+
}
|
|
81
|
+
const namespaceApisRes = await client.managedDocs.getApiDocs(namespace);
|
|
82
|
+
if (namespaceApisRes.error)
|
|
83
|
+
return output.error().title(namespaceApisRes.message).exit("error");
|
|
84
|
+
const apiUid = namespaceApisRes.data.find((api) => api.slug === data.api)?.uid || await select({
|
|
85
|
+
message: "Please select an API",
|
|
86
|
+
options: namespaceApisRes.data.map((api) => ({
|
|
87
|
+
value: api.uid,
|
|
88
|
+
label: api.slug
|
|
89
|
+
}))
|
|
90
|
+
});
|
|
91
|
+
if (!apiUid) {
|
|
92
|
+
return output.error().title("No API found").message("Please provide a valid API slug").exit("error");
|
|
93
|
+
}
|
|
94
|
+
const logger = output.info().loader("Creating the SDK");
|
|
95
|
+
const response = await client.sdks.create({
|
|
96
|
+
apiUid,
|
|
97
|
+
languages: [language]
|
|
98
|
+
});
|
|
99
|
+
if (response.error) {
|
|
100
|
+
return output.error().title("Something went wrong").message(response.message).exit("error");
|
|
101
|
+
}
|
|
102
|
+
logger.update("loader", 0, { content: "SDK created successfully!" });
|
|
103
|
+
const dashboardUrl = `${config.projects.dashboard}/sdk/${response.data}`;
|
|
104
|
+
logger.message(`View your SDK in the Scalar dashboard: ${as.cyan(dashboardUrl)}`).exit("success");
|
|
105
|
+
}
|
|
106
|
+
export {
|
|
107
|
+
createAction
|
|
108
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
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 {
|
|
14
|
+
sdkSchema
|
|
15
|
+
} from "./chunk-5BPPGTUU.js";
|
|
16
|
+
import "./chunk-P646T2WH.js";
|
|
17
|
+
import "./chunk-4QS7SJTG.js";
|
|
18
|
+
import "./chunk-VTYTPSXO.js";
|
|
19
|
+
import {
|
|
20
|
+
getAuthData
|
|
21
|
+
} from "./chunk-5BISXQX4.js";
|
|
22
|
+
import "./chunk-OAXFCOJV.js";
|
|
23
|
+
import "./chunk-TLFMATXR.js";
|
|
24
|
+
import {
|
|
25
|
+
teamSchema
|
|
26
|
+
} from "./chunk-4DGQIAJX.js";
|
|
27
|
+
import {
|
|
28
|
+
namespaceSchema,
|
|
29
|
+
slugSchema
|
|
30
|
+
} from "./chunk-ISGLWBXZ.js";
|
|
31
|
+
import {
|
|
32
|
+
external_exports
|
|
33
|
+
} from "./chunk-H2WRMLYY.js";
|
|
34
|
+
import "./chunk-K74E42RV.js";
|
|
35
|
+
import "./chunk-IX7LJ3AD.js";
|
|
36
|
+
import {
|
|
37
|
+
output
|
|
38
|
+
} from "./chunk-X4QLDBB5.js";
|
|
39
|
+
import "./chunk-3MZYUBJ6.js";
|
|
40
|
+
|
|
41
|
+
// src/domains/sdk/delete.action.ts
|
|
42
|
+
import { select } from "@clack/prompts";
|
|
43
|
+
async function deleteAction(opts) {
|
|
44
|
+
const { error, data } = external_exports.object({
|
|
45
|
+
slug: slugSchema.optional(),
|
|
46
|
+
namespace: namespaceSchema.optional()
|
|
47
|
+
}).safeParse(opts);
|
|
48
|
+
if (error)
|
|
49
|
+
return output.error().title("Invalid input").message(error.issues[0].message).exit("error");
|
|
50
|
+
const auth = await getAuthData();
|
|
51
|
+
auth.addEventListener((state) => Object.assign(auth, state));
|
|
52
|
+
const db = await getDatabaseClient();
|
|
53
|
+
const client = await apiService();
|
|
54
|
+
const team = await db.getOne({
|
|
55
|
+
collectionPath: BaseCollections.Teams,
|
|
56
|
+
query: {
|
|
57
|
+
uid: auth.teamUid
|
|
58
|
+
},
|
|
59
|
+
schema: teamSchema
|
|
60
|
+
});
|
|
61
|
+
if (team.error)
|
|
62
|
+
return output.error().title("An error occurred when fetching your team.").message(team.message).exit("error");
|
|
63
|
+
const namespace = data.namespace || team.data.namespaces.at(0);
|
|
64
|
+
if (!namespace) {
|
|
65
|
+
return output.error().title("Missing namespace").message(
|
|
66
|
+
"Could not find a valid namespace for your SDK. Please specify a namespace or contact support."
|
|
67
|
+
).exit("error");
|
|
68
|
+
}
|
|
69
|
+
const sdks = await db.getMany({
|
|
70
|
+
collectionPath: BaseCollections.Sdks(team.data.uid),
|
|
71
|
+
query: {
|
|
72
|
+
namespace
|
|
73
|
+
},
|
|
74
|
+
schema: sdkSchema.array()
|
|
75
|
+
});
|
|
76
|
+
if (sdks.error) return output.error().title(sdks.message).exit("error");
|
|
77
|
+
const sdkUid = sdks.data.find((sdk) => sdk.slug === data.slug)?.uid || await select({
|
|
78
|
+
message: "Please select an SDK to delete",
|
|
79
|
+
options: sdks.data.map((sdk) => ({
|
|
80
|
+
value: sdk.uid,
|
|
81
|
+
label: sdk.slug
|
|
82
|
+
}))
|
|
83
|
+
});
|
|
84
|
+
if (!sdkUid) {
|
|
85
|
+
return output.error().title("No SDK found").message("Please provide a valid SDK slug").exit("error");
|
|
86
|
+
}
|
|
87
|
+
const logger = output.info().loader("Deleting the SDK");
|
|
88
|
+
const response = await client.sdks.delete(sdkUid);
|
|
89
|
+
if (response.error) {
|
|
90
|
+
return output.error().title("Something went wrong").message(response.message).exit("error");
|
|
91
|
+
}
|
|
92
|
+
logger.update("loader", 0, { content: "SDK deleted successfully!" }).exit("success");
|
|
93
|
+
}
|
|
94
|
+
export {
|
|
95
|
+
deleteAction
|
|
96
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
slugSchema
|
|
28
|
+
} from "./chunk-ISGLWBXZ.js";
|
|
29
|
+
import {
|
|
30
|
+
external_exports
|
|
31
|
+
} from "./chunk-H2WRMLYY.js";
|
|
32
|
+
import "./chunk-K74E42RV.js";
|
|
33
|
+
import "./chunk-IX7LJ3AD.js";
|
|
34
|
+
import {
|
|
35
|
+
output
|
|
36
|
+
} from "./chunk-X4QLDBB5.js";
|
|
37
|
+
import "./chunk-3MZYUBJ6.js";
|
|
38
|
+
|
|
39
|
+
// src/domains/schema/delete.action.ts
|
|
40
|
+
import { select } from "@clack/prompts";
|
|
41
|
+
async function deleteAction(opts) {
|
|
42
|
+
const { error, data } = external_exports.object({
|
|
43
|
+
slug: slugSchema.optional(),
|
|
44
|
+
namespace: namespaceSchema.optional()
|
|
45
|
+
}).safeParse(opts);
|
|
46
|
+
if (error)
|
|
47
|
+
return output.error().title("Invalid input").message(error.issues[0].message).exit("error");
|
|
48
|
+
const auth = await getAuthData();
|
|
49
|
+
auth.addEventListener((state) => Object.assign(auth, state));
|
|
50
|
+
const db = await getDatabaseClient();
|
|
51
|
+
const client = await apiService();
|
|
52
|
+
const team = await db.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 schema. Please specify a namespace or contact support."
|
|
65
|
+
).exit("error");
|
|
66
|
+
}
|
|
67
|
+
const schemas = await client.managedSchemas.getSchemas(namespace);
|
|
68
|
+
if (schemas.error) return output.error().title(schemas.message).exit("error");
|
|
69
|
+
const schemaSlug = schemas.data.find((schema) => schema.slug === data.slug)?.slug || await select({
|
|
70
|
+
message: "Please select a schema to delete",
|
|
71
|
+
options: schemas.data.map((schema) => ({
|
|
72
|
+
value: schema.slug,
|
|
73
|
+
label: schema.slug
|
|
74
|
+
}))
|
|
75
|
+
});
|
|
76
|
+
if (!schemaSlug) {
|
|
77
|
+
return output.error().title("No schema found").message("Please provide a valid schema slug").exit("error");
|
|
78
|
+
}
|
|
79
|
+
const logger = output.info().loader("Deleting the schema");
|
|
80
|
+
const response = await client.managedSchemas.delete(namespace, schemaSlug);
|
|
81
|
+
if (response.error) {
|
|
82
|
+
return output.error().title("Something went wrong").message(response.message).exit("error");
|
|
83
|
+
}
|
|
84
|
+
logger.update("loader", 0, { content: "Schema deleted successfully!" }).exit("success");
|
|
85
|
+
}
|
|
86
|
+
export {
|
|
87
|
+
deleteAction
|
|
88
|
+
};
|
|
@@ -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/schema/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 schema").exit("error");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (!slug) {
|
|
38
|
+
output.error().title("Invalid input").message("Please provide slug of the schema").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).schemas(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 schema").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 schema 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
|
+
};
|