@lifestreamdynamics/vault-cli 1.3.5 → 1.3.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.
@@ -67,9 +67,19 @@ export class Output {
67
67
  }
68
68
  /**
69
69
  * Print an error message to stderr.
70
+ * When output format is json, writes a JSON error envelope instead of colored text.
70
71
  */
71
72
  error(message) {
72
- process.stderr.write(chalk.red(message) + '\n');
73
+ if (this.flags.output === 'json') {
74
+ process.stderr.write(JSON.stringify({ error: true, message }) + '\n');
75
+ }
76
+ else {
77
+ process.stderr.write(chalk.red(message) + '\n');
78
+ }
79
+ }
80
+ /** Expose the current output format (for error handlers that need it). */
81
+ get format() {
82
+ return this.flags.output;
73
83
  }
74
84
  /**
75
85
  * Print a warning message to stderr.
@@ -107,14 +117,16 @@ export class Output {
107
117
  */
108
118
  list(data, options) {
109
119
  if (data.length === 0) {
120
+ if (this.flags.quiet)
121
+ return;
110
122
  if (this.flags.output === 'json') {
111
123
  process.stdout.write('[]\n');
112
124
  return;
113
125
  }
114
- if (options?.emptyMessage && !this.flags.quiet) {
126
+ if (options?.emptyMessage) {
115
127
  this.status(options.emptyMessage);
116
128
  }
117
- else if (!this.flags.quiet && !options?.emptyMessage) {
129
+ else {
118
130
  process.stdout.write('No results found.\n');
119
131
  }
120
132
  return;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Accepts either a vault UUID or a vault slug. If a UUID is given it is
3
+ * returned unchanged. If a slug is given, the vault list is fetched and the
4
+ * matching vault's ID is returned.
5
+ *
6
+ * @throws {Error} If the slug does not match any vault.
7
+ */
8
+ export declare function resolveVaultId(idOrSlug: string): Promise<string>;
@@ -0,0 +1,19 @@
1
+ import { getClientAsync } from '../client.js';
2
+ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
3
+ /**
4
+ * Accepts either a vault UUID or a vault slug. If a UUID is given it is
5
+ * returned unchanged. If a slug is given, the vault list is fetched and the
6
+ * matching vault's ID is returned.
7
+ *
8
+ * @throws {Error} If the slug does not match any vault.
9
+ */
10
+ export async function resolveVaultId(idOrSlug) {
11
+ if (UUID_RE.test(idOrSlug))
12
+ return idOrSlug;
13
+ const client = await getClientAsync();
14
+ const vaults = await client.vaults.list();
15
+ const match = vaults.find(v => v.slug === idOrSlug);
16
+ if (!match)
17
+ throw new Error(`Vault not found: "${idOrSlug}"`);
18
+ return match.id;
19
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifestreamdynamics/vault-cli",
3
- "version": "1.3.5",
3
+ "version": "1.3.6",
4
4
  "description": "Command-line interface for Lifestream Vault",
5
5
  "engines": {
6
6
  "node": ">=20"