@sylphx/cli 0.1.3 → 0.1.5
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/dist/index.js +104 -42
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -27,6 +27,52 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
var import_chalk17 = __toESM(require("chalk"));
|
|
28
28
|
var import_commander16 = require("commander");
|
|
29
29
|
|
|
30
|
+
// package.json
|
|
31
|
+
var package_default = {
|
|
32
|
+
name: "@sylphx/cli",
|
|
33
|
+
version: "0.1.5",
|
|
34
|
+
description: "Sylphx Platform CLI \u2014 deploy, manage logs, env vars, and more",
|
|
35
|
+
type: "commonjs",
|
|
36
|
+
bin: {
|
|
37
|
+
sylphx: "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
scripts: {
|
|
40
|
+
build: "tsup src/index.ts --format cjs --dts",
|
|
41
|
+
dev: "tsx src/index.ts",
|
|
42
|
+
typecheck: "tsc --noEmit",
|
|
43
|
+
test: "vitest run",
|
|
44
|
+
"test:watch": "vitest",
|
|
45
|
+
"test:coverage": "vitest run --coverage",
|
|
46
|
+
clean: "rm -rf dist",
|
|
47
|
+
prepublishOnly: "tsup src/index.ts --format cjs --dts"
|
|
48
|
+
},
|
|
49
|
+
files: [
|
|
50
|
+
"dist",
|
|
51
|
+
"README.md"
|
|
52
|
+
],
|
|
53
|
+
publishConfig: {
|
|
54
|
+
access: "public",
|
|
55
|
+
registry: "https://registry.npmjs.org/"
|
|
56
|
+
},
|
|
57
|
+
dependencies: {
|
|
58
|
+
chalk: "^5.3.0",
|
|
59
|
+
commander: "^12.1.0",
|
|
60
|
+
conf: "^13.0.0",
|
|
61
|
+
eventsource: "^2.0.2",
|
|
62
|
+
open: "^10.1.0",
|
|
63
|
+
ora: "^8.1.0"
|
|
64
|
+
},
|
|
65
|
+
devDependencies: {
|
|
66
|
+
"@types/eventsource": "^1.1.15",
|
|
67
|
+
"@types/node": "^22.0.0",
|
|
68
|
+
"@vitest/coverage-v8": "^3.2.0",
|
|
69
|
+
tsup: "^8.3.0",
|
|
70
|
+
tsx: "^4.19.0",
|
|
71
|
+
typescript: "^5.9.3",
|
|
72
|
+
vitest: "^3.2.0"
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
30
76
|
// src/commands/db.ts
|
|
31
77
|
var import_node_readline = __toESM(require("readline"));
|
|
32
78
|
var import_chalk = __toESM(require("chalk"));
|
|
@@ -182,9 +228,14 @@ var api = {
|
|
|
182
228
|
},
|
|
183
229
|
/** List env vars for a project environment */
|
|
184
230
|
async listEnvVars(projectId, envType) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
231
|
+
const res = await request(
|
|
232
|
+
"GET",
|
|
233
|
+
`/projects/${projectId}/env-vars`,
|
|
234
|
+
{
|
|
235
|
+
query: { envType }
|
|
236
|
+
}
|
|
237
|
+
);
|
|
238
|
+
return Array.isArray(res) ? res : res.data ?? [];
|
|
188
239
|
},
|
|
189
240
|
/** Set an env var (or batch of vars) for a project environment */
|
|
190
241
|
async setEnvVar(projectId, key, value, envType, secret) {
|
|
@@ -201,29 +252,38 @@ var api = {
|
|
|
201
252
|
query: { envType }
|
|
202
253
|
});
|
|
203
254
|
},
|
|
204
|
-
/**
|
|
205
|
-
*
|
|
255
|
+
/** Resolve environment ID from project ID + envType.
|
|
256
|
+
* The domains API requires an envId (not projectId).
|
|
206
257
|
*/
|
|
258
|
+
async resolveEnvId(projectId, envType) {
|
|
259
|
+
const project = await request("GET", `/projects/${projectId}`);
|
|
260
|
+
const env = project.environments.find((e) => e.envType === envType || e.name === envType);
|
|
261
|
+
if (!env) throw new ApiError(404, `No environment '${envType}' found for project`);
|
|
262
|
+
return env.id;
|
|
263
|
+
},
|
|
264
|
+
/** List domains for a project environment */
|
|
207
265
|
async listDomains(projectId, envType) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
266
|
+
const envId = await this.resolveEnvId(projectId, envType);
|
|
267
|
+
const res = await request(
|
|
268
|
+
"GET",
|
|
269
|
+
`/domains/projects/${envId}/domains`
|
|
270
|
+
);
|
|
271
|
+
return Array.isArray(res) ? res : res.domains ?? [];
|
|
211
272
|
},
|
|
212
|
-
/** Add a domain for a project environment
|
|
213
|
-
* NOTE: Endpoint needs backend verification; follows RESTful convention.
|
|
214
|
-
*/
|
|
273
|
+
/** Add a domain for a project environment */
|
|
215
274
|
async addDomain(projectId, domain, envType) {
|
|
216
|
-
|
|
217
|
-
|
|
275
|
+
const envId = await this.resolveEnvId(projectId, envType);
|
|
276
|
+
return request("POST", `/domains/projects/${envId}/domains`, {
|
|
277
|
+
body: { domain }
|
|
218
278
|
});
|
|
219
279
|
},
|
|
220
|
-
/** Remove a domain from a project environment
|
|
221
|
-
* NOTE: Endpoint needs backend verification; follows RESTful convention.
|
|
222
|
-
*/
|
|
280
|
+
/** Remove a domain from a project environment */
|
|
223
281
|
async removeDomain(projectId, domain, envType) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
282
|
+
const envId = await this.resolveEnvId(projectId, envType);
|
|
283
|
+
return request(
|
|
284
|
+
"DELETE",
|
|
285
|
+
`/domains/projects/${envId}/domains/${encodeURIComponent(domain)}`
|
|
286
|
+
);
|
|
227
287
|
},
|
|
228
288
|
/** Get current user and orgs */
|
|
229
289
|
async whoami() {
|
|
@@ -231,7 +291,8 @@ var api = {
|
|
|
231
291
|
},
|
|
232
292
|
/** List projects (org is scoped to token) */
|
|
233
293
|
async listProjects() {
|
|
234
|
-
|
|
294
|
+
const res = await request("GET", "/projects");
|
|
295
|
+
return Array.isArray(res) ? res : res.data ?? [];
|
|
235
296
|
},
|
|
236
297
|
/** Create a new project */
|
|
237
298
|
async createProject(data) {
|
|
@@ -245,25 +306,32 @@ var api = {
|
|
|
245
306
|
async listApps(_orgId) {
|
|
246
307
|
return this.listProjects();
|
|
247
308
|
},
|
|
248
|
-
/** List all databases */
|
|
309
|
+
/** List all databases (via unified Resources API) */
|
|
249
310
|
async listDatabases() {
|
|
250
|
-
|
|
311
|
+
const res = await request(
|
|
312
|
+
"GET",
|
|
313
|
+
"/resources",
|
|
314
|
+
{
|
|
315
|
+
query: { kind: "database" }
|
|
316
|
+
}
|
|
317
|
+
);
|
|
318
|
+
return Array.isArray(res) ? res : res.data ?? [];
|
|
251
319
|
},
|
|
252
|
-
/** Provision a new database */
|
|
320
|
+
/** Provision a new database (via unified Resources API) */
|
|
253
321
|
async createDatabase(data) {
|
|
254
|
-
return request("POST", "/
|
|
322
|
+
return request("POST", "/resources", { body: { ...data, kind: "database" } });
|
|
255
323
|
},
|
|
256
|
-
/** Get database details (
|
|
324
|
+
/** Get database details (via unified Resources API) */
|
|
257
325
|
async getDatabase(id) {
|
|
258
|
-
return request("GET", `/
|
|
326
|
+
return request("GET", `/resources/${encodeURIComponent(id)}`);
|
|
259
327
|
},
|
|
260
|
-
/** Delete a database */
|
|
328
|
+
/** Delete a database (via unified Resources API) */
|
|
261
329
|
async deleteDatabase(id) {
|
|
262
|
-
return request("DELETE", `/
|
|
330
|
+
return request("DELETE", `/resources/${encodeURIComponent(id)}`);
|
|
263
331
|
},
|
|
264
|
-
/** Branch a database for staging/preview */
|
|
332
|
+
/** Branch a database for staging/preview (via unified Resources API) */
|
|
265
333
|
async branchDatabase(id, data) {
|
|
266
|
-
return request("POST", `/
|
|
334
|
+
return request("POST", `/resources/${encodeURIComponent(id)}/branch`, { body: data });
|
|
267
335
|
},
|
|
268
336
|
/** Batch-set env vars for a project environment */
|
|
269
337
|
async setEnvVars(projectId, vars, envType) {
|
|
@@ -503,20 +571,13 @@ function streamLogs(url, token, opts = {}) {
|
|
|
503
571
|
return new Promise((resolve) => {
|
|
504
572
|
const EventSource = require("eventsource");
|
|
505
573
|
const headers = {
|
|
506
|
-
"User-Agent": "sylphx-cli/0.1.0"
|
|
574
|
+
"User-Agent": "sylphx-cli/0.1.0",
|
|
575
|
+
Accept: "text/event-stream"
|
|
507
576
|
};
|
|
508
577
|
if (token) {
|
|
509
578
|
headers.Authorization = `Bearer ${token}`;
|
|
510
579
|
}
|
|
511
|
-
const es = new EventSource(url, {
|
|
512
|
-
fetch: (input, init) => fetch(input, {
|
|
513
|
-
...init,
|
|
514
|
-
headers: {
|
|
515
|
-
...typeof init?.headers === "object" ? init.headers : {},
|
|
516
|
-
...headers
|
|
517
|
-
}
|
|
518
|
-
})
|
|
519
|
-
});
|
|
580
|
+
const es = new EventSource(url, { headers });
|
|
520
581
|
let succeeded = false;
|
|
521
582
|
let timeout;
|
|
522
583
|
const finish = (success) => {
|
|
@@ -1394,7 +1455,7 @@ var projectsListCommand = new import_commander11.Command("list").description("Li
|
|
|
1394
1455
|
);
|
|
1395
1456
|
console.log(import_chalk12.default.dim(` ${"\u2500".repeat(colSlug + colName + 30)}`));
|
|
1396
1457
|
for (const p of projects) {
|
|
1397
|
-
const envNames = p.environments && p.environments.length > 0 ? p.environments.map((e) => e.
|
|
1458
|
+
const envNames = p.environments && p.environments.length > 0 ? p.environments.map((e) => e.name || e.envType || e.id).join(", ") : import_chalk12.default.dim("\u2014");
|
|
1398
1459
|
console.log(
|
|
1399
1460
|
` ${import_chalk12.default.cyan(p.slug.padEnd(colSlug))} ${p.name.padEnd(colName)} ${envNames}`
|
|
1400
1461
|
);
|
|
@@ -1639,8 +1700,9 @@ var whoamiCommand = new import_commander15.Command("whoami").description("Show c
|
|
|
1639
1700
|
});
|
|
1640
1701
|
|
|
1641
1702
|
// src/index.ts
|
|
1703
|
+
var { version } = package_default;
|
|
1642
1704
|
var program = new import_commander16.Command();
|
|
1643
|
-
program.name("sylphx").description(`${import_chalk17.default.bold("Sylphx Platform CLI")} \u2014 deploy and manage your applications`).version(
|
|
1705
|
+
program.name("sylphx").description(`${import_chalk17.default.bold("Sylphx Platform CLI")} \u2014 deploy and manage your applications`).version(version, "-v, --version", "Print version").helpOption("-h, --help", "Show help").addHelpText(
|
|
1644
1706
|
"after",
|
|
1645
1707
|
`
|
|
1646
1708
|
${import_chalk17.default.bold("Examples:")}
|