@zuvo/cli 0.1.4 → 0.1.6
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 +20 -1
- package/dist/hosting.js +58 -0
- package/dist/index.js +347 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @zuvo/cli
|
|
2
2
|
|
|
3
|
-
Login, link a project, deploy Edge Functions, manage secrets,
|
|
3
|
+
Login, link a project, deploy Edge Functions / App Hosting, manage secrets & hosting env, `db push`, and fetch logs against [Zuvo](https://studio.zuvodev.com).
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
npm i -g @zuvo/cli
|
|
@@ -13,7 +13,26 @@ zuvo secrets set --env-file ./supabase/.env.local
|
|
|
13
13
|
zuvo secrets list
|
|
14
14
|
zuvo secrets unset OPENAI_API_KEY
|
|
15
15
|
zuvo db push
|
|
16
|
+
|
|
17
|
+
# App Hosting
|
|
18
|
+
zuvo hosting apps
|
|
19
|
+
zuvo hosting deploy --wait
|
|
20
|
+
zuvo hosting deploy --commit abc1234 --app my-app
|
|
21
|
+
zuvo hosting deployments
|
|
22
|
+
zuvo hosting logs --since 6h
|
|
23
|
+
zuvo hosting logs -f
|
|
24
|
+
zuvo hosting deploy-logs
|
|
25
|
+
zuvo hosting env list
|
|
26
|
+
zuvo hosting env set API_KEY=secret FOO=bar
|
|
27
|
+
zuvo hosting env set --env-file ./.env.hosting
|
|
28
|
+
zuvo hosting env unset API_KEY
|
|
29
|
+
zuvo hosting secrets list # alias for hosting env
|
|
16
30
|
```
|
|
17
31
|
|
|
18
32
|
Token: Studio → Account → Access Tokens, or `zuvo login --token zpat_…`.
|
|
19
33
|
API override: `ZUVO_API_URL` / `--api-url` (default `https://api.zuvodev.com`).
|
|
34
|
+
|
|
35
|
+
**Notes**
|
|
36
|
+
- Hosting env keys must be `UPPER_SNAKE` (`^[A-Z][A-Z0-9_]{0,127}$`).
|
|
37
|
+
- After `hosting env set|unset`, run `zuvo hosting deploy --wait` so the container picks up new vars.
|
|
38
|
+
- `zuvo secrets` = project Edge Function secrets; `zuvo hosting env` = App Hosting container env.
|
package/dist/hosting.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** Parse `--since 30m|2h|1d` or an ISO timestamp into a Date. */
|
|
2
|
+
export function parseSince(input, now = Date.now()) {
|
|
3
|
+
const trimmed = input.trim();
|
|
4
|
+
const relative = trimmed.match(/^(\d+)\s*(s|m|h|d)$/i);
|
|
5
|
+
if (relative) {
|
|
6
|
+
const amount = Number(relative[1]);
|
|
7
|
+
if (!Number.isFinite(amount) || amount < 0) {
|
|
8
|
+
throw new Error(`Invalid --since: ${input}`);
|
|
9
|
+
}
|
|
10
|
+
const unit = relative[2].toLowerCase();
|
|
11
|
+
const ms = unit === 's'
|
|
12
|
+
? amount * 1_000
|
|
13
|
+
: unit === 'm'
|
|
14
|
+
? amount * 60_000
|
|
15
|
+
: unit === 'h'
|
|
16
|
+
? amount * 3_600_000
|
|
17
|
+
: amount * 86_400_000;
|
|
18
|
+
return new Date(now - ms);
|
|
19
|
+
}
|
|
20
|
+
const absolute = new Date(trimmed);
|
|
21
|
+
if (Number.isNaN(absolute.getTime())) {
|
|
22
|
+
throw new Error(`Invalid --since: ${input} (use 30m, 2h, 1d, or ISO timestamp)`);
|
|
23
|
+
}
|
|
24
|
+
return absolute;
|
|
25
|
+
}
|
|
26
|
+
export function formatLogTimestamp(value) {
|
|
27
|
+
if (value == null || value === '')
|
|
28
|
+
return '';
|
|
29
|
+
const n = typeof value === 'number' ? value : Number(value);
|
|
30
|
+
let ms;
|
|
31
|
+
if (Number.isFinite(n)) {
|
|
32
|
+
// Studio analytics returns microseconds when numeric.
|
|
33
|
+
ms = n > 1e14 ? Math.floor(n / 1000) : n;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
ms = new Date(String(value)).getTime();
|
|
37
|
+
}
|
|
38
|
+
if (!Number.isFinite(ms))
|
|
39
|
+
return String(value);
|
|
40
|
+
return new Date(ms).toISOString();
|
|
41
|
+
}
|
|
42
|
+
/** Oldest → newest for terminal reading. */
|
|
43
|
+
export function sortLogsChronological(rows) {
|
|
44
|
+
return [...rows].sort((a, b) => {
|
|
45
|
+
const ta = formatLogTimestamp(a.timestamp);
|
|
46
|
+
const tb = formatLogTimestamp(b.timestamp);
|
|
47
|
+
return ta.localeCompare(tb);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
export function formatHostingLogLine(row) {
|
|
51
|
+
const ts = formatLogTimestamp(row.timestamp);
|
|
52
|
+
const msg = row.event_message ?? '';
|
|
53
|
+
return ts ? `${ts} ${msg}` : msg;
|
|
54
|
+
}
|
|
55
|
+
export function hostingLogsSql(limit) {
|
|
56
|
+
const safe = Math.min(Math.max(1, Math.floor(limit)), 5_000);
|
|
57
|
+
return `select id, timestamp, event_message from hosting_logs order by timestamp desc limit ${safe}`;
|
|
58
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { apiRequest, ApiError } from './api.js';
|
|
|
4
4
|
import { argvAfterCommand } from './argv.js';
|
|
5
5
|
import { apiUrlFromEnv, deleteAccessToken, isAccessToken, requireLinkedRef, saveLinkedRef, } from './config.js';
|
|
6
6
|
import { encodeFunctionForm, listFunctionSlugs, loadFunctionBundle } from './functions.js';
|
|
7
|
+
import { formatHostingLogLine, formatLogTimestamp, hostingLogsSql, parseSince, sortLogsChronological, } from './hosting.js';
|
|
7
8
|
import { loginBrowser, loginWithToken } from './login.js';
|
|
8
9
|
import { loadLocalMigrations, pendingMigrations } from './migrations.js';
|
|
9
10
|
import { loadSecretsEnvFile, parseSecretArgs } from './secrets.js';
|
|
@@ -22,6 +23,15 @@ Commands:
|
|
|
22
23
|
secrets set --env-file <path>
|
|
23
24
|
secrets unset NAME [NAME ...]
|
|
24
25
|
db push
|
|
26
|
+
hosting apps
|
|
27
|
+
hosting deployments [--app <appId|slug>]
|
|
28
|
+
hosting deploy [--app <appId|slug>] [--commit <sha>] [--wait]
|
|
29
|
+
hosting logs [--limit N] [--since 1h|30m|ISO] [-f|--follow]
|
|
30
|
+
hosting deploy-logs [deploymentId] [--app <appId|slug>]
|
|
31
|
+
hosting env list [--app <appId|slug>]
|
|
32
|
+
hosting env set NAME=VALUE [...] [--env-file <path>] [--app <appId|slug>]
|
|
33
|
+
hosting env unset NAME [...] [--app <appId|slug>]
|
|
34
|
+
hosting secrets … Alias for hosting env …
|
|
25
35
|
|
|
26
36
|
Global:
|
|
27
37
|
--api-url <url> Default https://api.zuvodev.com (or ZUVO_API_URL)
|
|
@@ -243,6 +253,330 @@ async function cmdDbPush(apiUrl) {
|
|
|
243
253
|
console.log(`Applied ${migration.filename}`);
|
|
244
254
|
}
|
|
245
255
|
}
|
|
256
|
+
async function listHostingApps(apiUrl, ref) {
|
|
257
|
+
const data = await apiRequest(apiUrl, 'GET', `/platform/projects/${ref}/hosting/apps`);
|
|
258
|
+
return Array.isArray(data?.apps) ? data.apps : [];
|
|
259
|
+
}
|
|
260
|
+
async function resolveHostingApp(apiUrl, ref, appId) {
|
|
261
|
+
const apps = await listHostingApps(apiUrl, ref);
|
|
262
|
+
if (!apps.length)
|
|
263
|
+
throw new Error('No hosting apps on this project.');
|
|
264
|
+
if (appId) {
|
|
265
|
+
const match = apps.find((app) => app.id === appId || app.slug === appId || app.name === appId);
|
|
266
|
+
if (!match)
|
|
267
|
+
throw new Error(`Hosting app not found: ${appId}`);
|
|
268
|
+
return match;
|
|
269
|
+
}
|
|
270
|
+
if (apps.length === 1)
|
|
271
|
+
return apps[0];
|
|
272
|
+
throw new Error(`Multiple hosting apps — pass --app <id|slug>. Available: ${apps
|
|
273
|
+
.map((app) => app.slug || app.id)
|
|
274
|
+
.join(', ')}`);
|
|
275
|
+
}
|
|
276
|
+
async function listHostingDeployments(apiUrl, ref, appId) {
|
|
277
|
+
const data = await apiRequest(apiUrl, 'GET', `/platform/projects/${ref}/hosting/apps/${appId}/deployments`);
|
|
278
|
+
return Array.isArray(data?.deployments) ? data.deployments : [];
|
|
279
|
+
}
|
|
280
|
+
async function cmdHostingApps(apiUrl) {
|
|
281
|
+
const ref = await requireLinkedRef();
|
|
282
|
+
const apps = await listHostingApps(apiUrl, ref);
|
|
283
|
+
if (!apps.length) {
|
|
284
|
+
console.log('No hosting apps.');
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
for (const app of apps) {
|
|
288
|
+
console.log([app.id, app.slug || app.name || '', app.status || '', app.branch || '', app.public_url || '']
|
|
289
|
+
.filter(Boolean)
|
|
290
|
+
.join('\t'));
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
async function cmdHostingDeployments(apiUrl, argv) {
|
|
294
|
+
const { values } = parseArgs({
|
|
295
|
+
args: argv,
|
|
296
|
+
options: {
|
|
297
|
+
app: { type: 'string' },
|
|
298
|
+
'api-url': { type: 'string' },
|
|
299
|
+
},
|
|
300
|
+
allowPositionals: true,
|
|
301
|
+
strict: false,
|
|
302
|
+
});
|
|
303
|
+
const ref = await requireLinkedRef();
|
|
304
|
+
const app = await resolveHostingApp(apiUrl, ref, typeof values.app === 'string' ? values.app : undefined);
|
|
305
|
+
const deployments = await listHostingDeployments(apiUrl, ref, app.id);
|
|
306
|
+
if (!deployments.length) {
|
|
307
|
+
console.log('No deployments.');
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
for (const dep of deployments) {
|
|
311
|
+
console.log([
|
|
312
|
+
dep.id,
|
|
313
|
+
dep.status || '',
|
|
314
|
+
dep.commit_sha ? String(dep.commit_sha).slice(0, 12) : '',
|
|
315
|
+
dep.created_at || '',
|
|
316
|
+
]
|
|
317
|
+
.filter(Boolean)
|
|
318
|
+
.join('\t'));
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
async function fetchHostingRuntimeLogs(apiUrl, ref, opts) {
|
|
322
|
+
const body = {
|
|
323
|
+
sql: hostingLogsSql(opts.limit),
|
|
324
|
+
};
|
|
325
|
+
if (opts.since)
|
|
326
|
+
body.iso_timestamp_start = opts.since.toISOString();
|
|
327
|
+
const data = await apiRequest(apiUrl, 'POST', `/platform/projects/${ref}/analytics/endpoints/logs.all`, { json: body });
|
|
328
|
+
return Array.isArray(data?.result) ? data.result : [];
|
|
329
|
+
}
|
|
330
|
+
async function cmdHostingLogs(apiUrl, argv) {
|
|
331
|
+
const { values } = parseArgs({
|
|
332
|
+
args: argv,
|
|
333
|
+
options: {
|
|
334
|
+
limit: { type: 'string' },
|
|
335
|
+
since: { type: 'string' },
|
|
336
|
+
follow: { type: 'boolean', short: 'f' },
|
|
337
|
+
'api-url': { type: 'string' },
|
|
338
|
+
},
|
|
339
|
+
allowPositionals: true,
|
|
340
|
+
strict: false,
|
|
341
|
+
});
|
|
342
|
+
const ref = await requireLinkedRef();
|
|
343
|
+
const limitRaw = typeof values.limit === 'string' ? Number(values.limit) : 100;
|
|
344
|
+
const limit = Number.isFinite(limitRaw) ? limitRaw : 100;
|
|
345
|
+
const since = typeof values.since === 'string' && values.since.trim()
|
|
346
|
+
? parseSince(values.since)
|
|
347
|
+
: parseSince('1h');
|
|
348
|
+
const follow = Boolean(values.follow);
|
|
349
|
+
const seen = new Set();
|
|
350
|
+
const printNew = (rows) => {
|
|
351
|
+
for (const row of sortLogsChronological(rows)) {
|
|
352
|
+
const key = row.id || `${formatHostingLogLine(row)}`;
|
|
353
|
+
if (seen.has(key))
|
|
354
|
+
continue;
|
|
355
|
+
seen.add(key);
|
|
356
|
+
console.log(formatHostingLogLine(row));
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
const initial = await fetchHostingRuntimeLogs(apiUrl, ref, { limit, since });
|
|
360
|
+
if (!initial.length && !follow) {
|
|
361
|
+
console.log('No hosting logs in range.');
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
printNew(initial);
|
|
365
|
+
if (!follow)
|
|
366
|
+
return;
|
|
367
|
+
let cursor = since;
|
|
368
|
+
for (const row of sortLogsChronological(initial)) {
|
|
369
|
+
const iso = formatLogTimestamp(row.timestamp);
|
|
370
|
+
const parsed = iso ? new Date(iso) : null;
|
|
371
|
+
if (parsed && !Number.isNaN(parsed.getTime()) && parsed > cursor)
|
|
372
|
+
cursor = parsed;
|
|
373
|
+
}
|
|
374
|
+
console.error('Following hosting logs… (Ctrl+C to stop)');
|
|
375
|
+
for (;;) {
|
|
376
|
+
await new Promise((r) => setTimeout(r, 2_500));
|
|
377
|
+
const nextSince = new Date(Math.max(0, cursor.getTime() - 1_000));
|
|
378
|
+
const rows = await fetchHostingRuntimeLogs(apiUrl, ref, {
|
|
379
|
+
limit: Math.max(limit, 200),
|
|
380
|
+
since: nextSince,
|
|
381
|
+
});
|
|
382
|
+
printNew(rows);
|
|
383
|
+
for (const row of sortLogsChronological(rows)) {
|
|
384
|
+
const iso = formatLogTimestamp(row.timestamp);
|
|
385
|
+
const parsed = iso ? new Date(iso) : null;
|
|
386
|
+
if (parsed && !Number.isNaN(parsed.getTime()) && parsed > cursor)
|
|
387
|
+
cursor = parsed;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
async function cmdHostingDeployLogs(apiUrl, argv) {
|
|
392
|
+
const { values, positionals } = parseArgs({
|
|
393
|
+
args: argv,
|
|
394
|
+
options: {
|
|
395
|
+
app: { type: 'string' },
|
|
396
|
+
'api-url': { type: 'string' },
|
|
397
|
+
},
|
|
398
|
+
allowPositionals: true,
|
|
399
|
+
strict: false,
|
|
400
|
+
});
|
|
401
|
+
const ref = await requireLinkedRef();
|
|
402
|
+
const app = await resolveHostingApp(apiUrl, ref, typeof values.app === 'string' ? values.app : undefined);
|
|
403
|
+
let deploymentId = positionals.find((arg) => !arg.startsWith('-')) || '';
|
|
404
|
+
if (!deploymentId) {
|
|
405
|
+
const deployments = await listHostingDeployments(apiUrl, ref, app.id);
|
|
406
|
+
if (!deployments.length)
|
|
407
|
+
throw new Error('No deployments found.');
|
|
408
|
+
deploymentId = deployments[0].id;
|
|
409
|
+
console.error(`Using latest deployment ${deploymentId} (${deployments[0].status || 'unknown'})`);
|
|
410
|
+
}
|
|
411
|
+
const data = await apiRequest(apiUrl, 'GET', `/platform/projects/${ref}/hosting/apps/${app.id}/deployments/${deploymentId}/logs`);
|
|
412
|
+
const log = data?.log || '';
|
|
413
|
+
if (!log) {
|
|
414
|
+
console.log(`(empty build log) status=${data?.status || 'unknown'}`);
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
process.stdout.write(log.endsWith('\n') ? log : `${log}\n`);
|
|
418
|
+
}
|
|
419
|
+
const HOSTING_ENV_KEY = /^[A-Z][A-Z0-9_]{0,127}$/;
|
|
420
|
+
function assertHostingEnvKey(key) {
|
|
421
|
+
if (!HOSTING_ENV_KEY.test(key)) {
|
|
422
|
+
throw new Error(`Invalid env key: ${key} (must match /^[A-Z][A-Z0-9_]{0,127}$/)`);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
async function getDeploymentStatus(apiUrl, ref, appId, deploymentId) {
|
|
426
|
+
return apiRequest(apiUrl, 'GET', `/platform/projects/${ref}/hosting/apps/${appId}/deployments/${deploymentId}/logs`);
|
|
427
|
+
}
|
|
428
|
+
async function cmdHostingDeploy(apiUrl, argv) {
|
|
429
|
+
const { values } = parseArgs({
|
|
430
|
+
args: argv,
|
|
431
|
+
options: {
|
|
432
|
+
app: { type: 'string' },
|
|
433
|
+
commit: { type: 'string' },
|
|
434
|
+
wait: { type: 'boolean' },
|
|
435
|
+
'api-url': { type: 'string' },
|
|
436
|
+
},
|
|
437
|
+
allowPositionals: true,
|
|
438
|
+
strict: false,
|
|
439
|
+
});
|
|
440
|
+
const ref = await requireLinkedRef();
|
|
441
|
+
const app = await resolveHostingApp(apiUrl, ref, typeof values.app === 'string' ? values.app : undefined);
|
|
442
|
+
const commitSha = typeof values.commit === 'string' && values.commit.trim()
|
|
443
|
+
? values.commit.trim()
|
|
444
|
+
: undefined;
|
|
445
|
+
const data = await apiRequest(apiUrl, 'POST', `/platform/projects/${ref}/hosting/apps/${app.id}/deploy`, {
|
|
446
|
+
json: commitSha ? { commit_sha: commitSha } : {},
|
|
447
|
+
});
|
|
448
|
+
const deployment = data?.deployment;
|
|
449
|
+
if (!deployment?.id)
|
|
450
|
+
throw new Error('Deploy enqueue failed (no deployment id).');
|
|
451
|
+
console.log(`Queued deploy ${deployment.id} for ${app.slug || app.id} (${deployment.status || 'queued'})`);
|
|
452
|
+
if (!values.wait) {
|
|
453
|
+
console.error(`Tip: zuvo hosting deploy-logs ${deployment.id} --app ${app.slug || app.id}`);
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
console.error('Waiting for deploy…');
|
|
457
|
+
const started = Date.now();
|
|
458
|
+
const timeoutMs = 20 * 60_000;
|
|
459
|
+
let lastStatus = deployment.status || 'queued';
|
|
460
|
+
for (;;) {
|
|
461
|
+
if (Date.now() - started > timeoutMs) {
|
|
462
|
+
throw new Error(`Timed out waiting for deploy (last status: ${lastStatus})`);
|
|
463
|
+
}
|
|
464
|
+
await new Promise((r) => setTimeout(r, 3_000));
|
|
465
|
+
const statusRes = await getDeploymentStatus(apiUrl, ref, app.id, deployment.id);
|
|
466
|
+
const status = statusRes.status || 'unknown';
|
|
467
|
+
if (status !== lastStatus) {
|
|
468
|
+
console.error(`status: ${status}`);
|
|
469
|
+
lastStatus = status;
|
|
470
|
+
}
|
|
471
|
+
if (status === 'ready') {
|
|
472
|
+
console.log(`Deploy ready: ${deployment.id}`);
|
|
473
|
+
if (app.public_url)
|
|
474
|
+
console.log(app.public_url);
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
if (status === 'failed') {
|
|
478
|
+
const log = statusRes.log || '';
|
|
479
|
+
if (log)
|
|
480
|
+
process.stderr.write(log.endsWith('\n') ? log : `${log}\n`);
|
|
481
|
+
throw new Error(`Deploy failed: ${deployment.id}`);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
async function cmdHostingEnvList(apiUrl, argv) {
|
|
486
|
+
const { values } = parseArgs({
|
|
487
|
+
args: argv,
|
|
488
|
+
options: {
|
|
489
|
+
app: { type: 'string' },
|
|
490
|
+
'api-url': { type: 'string' },
|
|
491
|
+
},
|
|
492
|
+
allowPositionals: true,
|
|
493
|
+
strict: false,
|
|
494
|
+
});
|
|
495
|
+
const ref = await requireLinkedRef();
|
|
496
|
+
const app = await resolveHostingApp(apiUrl, ref, typeof values.app === 'string' ? values.app : undefined);
|
|
497
|
+
const data = await apiRequest(apiUrl, 'GET', `/platform/projects/${ref}/hosting/apps/${app.id}/env`);
|
|
498
|
+
const auto = Array.isArray(data?.auto) ? data.auto : [];
|
|
499
|
+
const custom = Array.isArray(data?.custom) ? data.custom : [];
|
|
500
|
+
if (!auto.length && !custom.length) {
|
|
501
|
+
console.log('No env vars.');
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
for (const row of auto) {
|
|
505
|
+
console.log([row.key, row.value || '(auto)', 'auto'].filter(Boolean).join('\t'));
|
|
506
|
+
}
|
|
507
|
+
for (const row of custom) {
|
|
508
|
+
console.log([row.key, row.value || '********', 'custom'].filter(Boolean).join('\t'));
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
async function cmdHostingEnvSet(apiUrl, argv) {
|
|
512
|
+
const { values, positionals } = parseArgs({
|
|
513
|
+
args: argv,
|
|
514
|
+
options: {
|
|
515
|
+
app: { type: 'string' },
|
|
516
|
+
'env-file': { type: 'string' },
|
|
517
|
+
'api-url': { type: 'string' },
|
|
518
|
+
},
|
|
519
|
+
allowPositionals: true,
|
|
520
|
+
strict: false,
|
|
521
|
+
});
|
|
522
|
+
const ref = await requireLinkedRef();
|
|
523
|
+
const app = await resolveHostingApp(apiUrl, ref, typeof values.app === 'string' ? values.app : undefined);
|
|
524
|
+
const fromFile = typeof values['env-file'] === 'string' && values['env-file'].trim()
|
|
525
|
+
? await loadSecretsEnvFile(values['env-file'].trim())
|
|
526
|
+
: [];
|
|
527
|
+
const fromArgs = parseSecretArgs(positionals);
|
|
528
|
+
const pairs = [...fromFile, ...fromArgs];
|
|
529
|
+
if (!pairs.length) {
|
|
530
|
+
throw new Error('Usage: zuvo hosting env set NAME=VALUE [...] | --env-file <path> [--app <id|slug>]');
|
|
531
|
+
}
|
|
532
|
+
for (const pair of pairs) {
|
|
533
|
+
assertHostingEnvKey(pair.name);
|
|
534
|
+
}
|
|
535
|
+
await apiRequest(apiUrl, 'PUT', `/platform/projects/${ref}/hosting/apps/${app.id}/env`, {
|
|
536
|
+
json: { vars: pairs.map((p) => ({ key: p.name, value: p.value })) },
|
|
537
|
+
});
|
|
538
|
+
console.log(`Set ${pairs.map((p) => p.name).join(', ')} on ${app.slug || app.id}`);
|
|
539
|
+
console.error('Redeploy to apply env changes: zuvo hosting deploy --wait');
|
|
540
|
+
}
|
|
541
|
+
async function cmdHostingEnvUnset(apiUrl, argv) {
|
|
542
|
+
const { values, positionals } = parseArgs({
|
|
543
|
+
args: argv,
|
|
544
|
+
options: {
|
|
545
|
+
app: { type: 'string' },
|
|
546
|
+
'api-url': { type: 'string' },
|
|
547
|
+
},
|
|
548
|
+
allowPositionals: true,
|
|
549
|
+
strict: false,
|
|
550
|
+
});
|
|
551
|
+
const names = positionals
|
|
552
|
+
.filter((arg) => !arg.startsWith('-'))
|
|
553
|
+
.map((n) => n.trim())
|
|
554
|
+
.filter(Boolean);
|
|
555
|
+
if (!names.length) {
|
|
556
|
+
throw new Error('Usage: zuvo hosting env unset NAME [NAME ...] [--app <id|slug>]');
|
|
557
|
+
}
|
|
558
|
+
for (const name of names)
|
|
559
|
+
assertHostingEnvKey(name);
|
|
560
|
+
const ref = await requireLinkedRef();
|
|
561
|
+
const app = await resolveHostingApp(apiUrl, ref, typeof values.app === 'string' ? values.app : undefined);
|
|
562
|
+
await apiRequest(apiUrl, 'DELETE', `/platform/projects/${ref}/hosting/apps/${app.id}/env`, {
|
|
563
|
+
json: { keys: names },
|
|
564
|
+
});
|
|
565
|
+
console.log(`Unset ${names.join(', ')} on ${app.slug || app.id}`);
|
|
566
|
+
console.error('Redeploy to apply env changes: zuvo hosting deploy --wait');
|
|
567
|
+
}
|
|
568
|
+
async function cmdHostingEnv(apiUrl, argv) {
|
|
569
|
+
const [action, ...rest] = argv;
|
|
570
|
+
if (action === 'list' || !action)
|
|
571
|
+
await cmdHostingEnvList(apiUrl, rest);
|
|
572
|
+
else if (action === 'set')
|
|
573
|
+
await cmdHostingEnvSet(apiUrl, rest);
|
|
574
|
+
else if (action === 'unset' || action === 'delete')
|
|
575
|
+
await cmdHostingEnvUnset(apiUrl, rest);
|
|
576
|
+
else {
|
|
577
|
+
throw new Error('Usage: zuvo hosting env list|set|unset … (alias: zuvo hosting secrets …)');
|
|
578
|
+
}
|
|
579
|
+
}
|
|
246
580
|
async function main() {
|
|
247
581
|
const argv = process.argv.slice(2);
|
|
248
582
|
const global = parseGlobal(argv);
|
|
@@ -273,6 +607,18 @@ async function main() {
|
|
|
273
607
|
await cmdSecretsUnset(apiUrl, argvAfterCommand(argv, 'secrets', sub));
|
|
274
608
|
else if (command === 'db' && sub === 'push')
|
|
275
609
|
await cmdDbPush(apiUrl);
|
|
610
|
+
else if (command === 'hosting' && (sub === 'apps' || sub === 'list'))
|
|
611
|
+
await cmdHostingApps(apiUrl);
|
|
612
|
+
else if (command === 'hosting' && sub === 'deployments')
|
|
613
|
+
await cmdHostingDeployments(apiUrl, argvAfterCommand(argv, 'hosting', 'deployments'));
|
|
614
|
+
else if (command === 'hosting' && sub === 'deploy')
|
|
615
|
+
await cmdHostingDeploy(apiUrl, argvAfterCommand(argv, 'hosting', 'deploy'));
|
|
616
|
+
else if (command === 'hosting' && sub === 'logs')
|
|
617
|
+
await cmdHostingLogs(apiUrl, argvAfterCommand(argv, 'hosting', 'logs'));
|
|
618
|
+
else if (command === 'hosting' && (sub === 'deploy-logs' || sub === 'build-logs'))
|
|
619
|
+
await cmdHostingDeployLogs(apiUrl, argvAfterCommand(argv, 'hosting', sub));
|
|
620
|
+
else if (command === 'hosting' && (sub === 'env' || sub === 'secrets'))
|
|
621
|
+
await cmdHostingEnv(apiUrl, argvAfterCommand(argv, 'hosting', sub));
|
|
276
622
|
else {
|
|
277
623
|
console.error(usage());
|
|
278
624
|
process.exit(command ? 1 : 0);
|
|
@@ -280,7 +626,7 @@ async function main() {
|
|
|
280
626
|
}
|
|
281
627
|
catch (error) {
|
|
282
628
|
if (error instanceof ApiError && error.status === 403) {
|
|
283
|
-
fail('Forbidden. Functions, secrets,
|
|
629
|
+
fail('Forbidden. Functions, secrets, db push, and hosting require owner, admin, or developer.');
|
|
284
630
|
}
|
|
285
631
|
fail(error);
|
|
286
632
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zuvo/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Zuvo CLI — login, link, functions deploy, secrets,
|
|
5
|
+
"description": "Zuvo CLI — login, link, functions/hosting deploy, secrets, env, db push, and logs",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
8
8
|
"zuvo": "bin/zuvo.js"
|