@zuvo/cli 0.1.8 → 0.1.9

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 CHANGED
@@ -22,8 +22,9 @@ zuvo hosting apps
22
22
  zuvo hosting deploy --wait
23
23
  zuvo hosting deploy --commit abc1234 --app my-app
24
24
  zuvo hosting deployments
25
- zuvo hosting logs --since 6h
26
- zuvo hosting logs -f
25
+ zuvo hosting logs --app sklive-events --since 6h
26
+ zuvo hosting logs --app sklive-super-admin -f
27
+ zuvo hosting logs --app all
27
28
  zuvo hosting deploy-logs
28
29
  zuvo hosting env list
29
30
  zuvo hosting env set API_KEY=secret FOO=bar
package/dist/hosting.js CHANGED
@@ -47,14 +47,39 @@ export function sortLogsChronological(rows) {
47
47
  return ta.localeCompare(tb);
48
48
  });
49
49
  }
50
+ export function hostingAppSlugFromLog(row) {
51
+ const meta = row.metadata && typeof row.metadata.app_slug === 'string' ? row.metadata.app_slug : '';
52
+ if (meta)
53
+ return meta;
54
+ const container = row.metadata && typeof row.metadata.app_container === 'string' ? row.metadata.app_container : '';
55
+ const match = String(container)
56
+ .replace(/^\//, '')
57
+ .match(/^app_([a-z0-9][a-z0-9-]*)(?:_[a-z0-9-]+)?$/);
58
+ return match?.[1] || '';
59
+ }
50
60
  export function formatHostingLogLine(row) {
51
61
  const ts = formatLogTimestamp(row.timestamp);
62
+ const slug = hostingAppSlugFromLog(row);
52
63
  const msg = row.event_message ?? '';
53
- return ts ? `${ts} ${msg}` : msg;
64
+ const bits = [ts, slug ? `[${slug}]` : '', msg].filter(Boolean);
65
+ return bits.join(' ');
54
66
  }
55
- export function hostingLogsSql(limit) {
67
+ export function assertSafeHostingSlug(key) {
68
+ const trimmed = key.trim();
69
+ if (trimmed === 'all')
70
+ return trimmed;
71
+ if (!/^[a-z0-9][a-z0-9-]{0,62}$/.test(trimmed)) {
72
+ throw new Error(`Invalid app slug: ${key} (use letters, digits, hyphen)`);
73
+ }
74
+ return trimmed;
75
+ }
76
+ export function hostingLogsSql(limit, appSlug) {
56
77
  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}`;
78
+ if (!appSlug || appSlug === 'all') {
79
+ return `select id, timestamp, event_message, metadata from hosting_logs order by timestamp desc limit ${safe}`;
80
+ }
81
+ const slug = assertSafeHostingSlug(appSlug);
82
+ return `select id, timestamp, event_message, metadata from hosting_logs where metadata.app_slug = '${slug}' order by timestamp desc limit ${safe}`;
58
83
  }
59
84
  /** Slug or UUID safe to embed in analytics SQL. */
60
85
  export function assertSafeFunctionKey(key) {
package/dist/index.js CHANGED
@@ -27,7 +27,7 @@ Commands:
27
27
  hosting apps
28
28
  hosting deployments [--app <appId|slug>]
29
29
  hosting deploy [--app <appId|slug>] [--commit <sha>] [--wait]
30
- hosting logs [--limit N] [--since 1h|30m|ISO] [-f|--follow]
30
+ hosting logs [--app <appId|slug|all>] [--limit N] [--since 1h|30m|ISO] [-f|--follow]
31
31
  hosting deploy-logs [deploymentId] [--app <appId|slug>]
32
32
  hosting env list [--app <appId|slug>]
33
33
  hosting env set NAME=VALUE [...] [--env-file <path>] [--app <appId|slug>]
@@ -403,7 +403,7 @@ async function cmdHostingDeployments(apiUrl, argv) {
403
403
  }
404
404
  async function fetchHostingRuntimeLogs(apiUrl, ref, opts) {
405
405
  const body = {
406
- sql: hostingLogsSql(opts.limit),
406
+ sql: hostingLogsSql(opts.limit, opts.appSlug),
407
407
  };
408
408
  if (opts.since)
409
409
  body.iso_timestamp_start = opts.since.toISOString();
@@ -414,6 +414,7 @@ async function cmdHostingLogs(apiUrl, argv) {
414
414
  const { values } = parseArgs({
415
415
  args: argv,
416
416
  options: {
417
+ app: { type: 'string' },
417
418
  limit: { type: 'string' },
418
419
  since: { type: 'string' },
419
420
  follow: { type: 'boolean', short: 'f' },
@@ -429,6 +430,19 @@ async function cmdHostingLogs(apiUrl, argv) {
429
430
  ? parseSince(values.since)
430
431
  : parseSince('1h');
431
432
  const follow = Boolean(values.follow);
433
+ const appArg = typeof values.app === 'string' ? values.app.trim() : '';
434
+ let appSlug;
435
+ if (appArg === 'all') {
436
+ appSlug = 'all';
437
+ }
438
+ else if (appArg) {
439
+ const app = await resolveHostingApp(apiUrl, ref, appArg);
440
+ appSlug = app.slug || app.id;
441
+ }
442
+ else {
443
+ const app = await resolveHostingApp(apiUrl, ref, undefined);
444
+ appSlug = app.slug || app.id;
445
+ }
432
446
  const seen = new Set();
433
447
  const printNew = (rows) => {
434
448
  for (const row of sortLogsChronological(rows)) {
@@ -439,9 +453,9 @@ async function cmdHostingLogs(apiUrl, argv) {
439
453
  console.log(formatHostingLogLine(row));
440
454
  }
441
455
  };
442
- const initial = await fetchHostingRuntimeLogs(apiUrl, ref, { limit, since });
456
+ const initial = await fetchHostingRuntimeLogs(apiUrl, ref, { limit, since, appSlug });
443
457
  if (!initial.length && !follow) {
444
- console.log('No hosting logs in range.');
458
+ console.log(`No hosting logs in range${appSlug && appSlug !== 'all' ? ` for ${appSlug}` : ''}.`);
445
459
  return;
446
460
  }
447
461
  printNew(initial);
@@ -454,13 +468,14 @@ async function cmdHostingLogs(apiUrl, argv) {
454
468
  if (parsed && !Number.isNaN(parsed.getTime()) && parsed > cursor)
455
469
  cursor = parsed;
456
470
  }
457
- console.error('Following hosting logs… (Ctrl+C to stop)');
471
+ console.error(`Following hosting logs${appSlug && appSlug !== 'all' ? ` for ${appSlug}` : ''}… (Ctrl+C to stop)`);
458
472
  for (;;) {
459
473
  await new Promise((r) => setTimeout(r, 2_500));
460
474
  const nextSince = new Date(Math.max(0, cursor.getTime() - 1_000));
461
475
  const rows = await fetchHostingRuntimeLogs(apiUrl, ref, {
462
476
  limit: Math.max(limit, 200),
463
477
  since: nextSince,
478
+ appSlug,
464
479
  });
465
480
  printNew(rows);
466
481
  for (const row of sortLogsChronological(rows)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuvo/cli",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "type": "module",
5
5
  "description": "Zuvo CLI — login, link, functions/hosting deploy, secrets, env, domains, db push, and logs",
6
6
  "license": "MIT",