@verbatims/cli 0.1.9 → 0.1.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verbatims/cli",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "CLI for the Verbatims quotes API",
5
5
  "type": "module",
6
6
  "bin": {
@@ -80,6 +80,23 @@ export function registerAuthorsCommand(program: Command) {
80
80
  output(data, format)
81
81
  })
82
82
 
83
+ authors
84
+ .command('delete <id>')
85
+ .description('Delete an author')
86
+ .option('--strategy <strategy>', 'Strategy if quotes exist: delete or anonymize')
87
+ .option('--yes', 'Skip confirmation')
88
+ .action(async (id: string, options: Record<string, string>) => {
89
+ if (!options.yes) {
90
+ const { confirm } = await import('@clack/prompts')
91
+ const confirmed = await confirm({ message: `Delete author #${id}?` })
92
+ if (isCancel(confirmed) || !confirmed) cancel('Cancelled')
93
+ }
94
+
95
+ const client = await getClient()
96
+ await withSpinner('Deleting author', () => client.authors.delete(Number(id), options.strategy as 'delete' | 'anonymize' | undefined))
97
+ console.log(chalk.green(` Author #${id} deleted`))
98
+ })
99
+
83
100
  authors
84
101
  .command('browse')
85
102
  .description('Browse authors interactively')
@@ -85,6 +85,23 @@ export function registerReferencesCommand(program: Command) {
85
85
  output(data, format)
86
86
  })
87
87
 
88
+ refs
89
+ .command('delete <id>')
90
+ .description('Delete a reference')
91
+ .option('--strategy <strategy>', 'Strategy if quotes exist: delete or anonymize')
92
+ .option('--yes', 'Skip confirmation')
93
+ .action(async (id: string, options: Record<string, string>) => {
94
+ if (!options.yes) {
95
+ const { confirm } = await import('@clack/prompts')
96
+ const confirmed = await confirm({ message: `Delete reference #${id}?` })
97
+ if (isCancel(confirmed) || !confirmed) cancel('Cancelled')
98
+ }
99
+
100
+ const client = await getClient()
101
+ await withSpinner('Deleting reference', () => client.references.delete(Number(id), options.strategy as 'delete' | 'anonymize' | undefined))
102
+ console.log(chalk.green(` Reference #${id} deleted`))
103
+ })
104
+
88
105
  refs
89
106
  .command('browse')
90
107
  .description('Browse references interactively')
package/src/index.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  import { Command } from 'commander'
4
4
  import { registerCommands } from './commands/index.js'
5
5
  import { setSilent } from './utils/spinner.js'
6
+ import pkg from '../package.json' with { type: 'json' }
6
7
 
7
8
  process.on('unhandledRejection', (err) => {
8
9
  console.error(err instanceof Error ? err.message : String(err))
@@ -14,6 +15,7 @@ const program = new Command()
14
15
  program
15
16
  .name('verbatims')
16
17
  .description('CLI for the Verbatims quotes API')
18
+ .version(pkg.version)
17
19
  .option('--api-key <key>', 'API key (overrides config and env)')
18
20
  .option('--format <type>', 'Output format: table|json|plain', 'table')
19
21
  .showHelpAfterError()
@@ -3,6 +3,14 @@ import { loadConfig } from './config.js'
3
3
 
4
4
  const DEFAULT_BASE_URL = 'https://verbatims.cc/api/v1'
5
5
 
6
+ function withCliSource(fetchFn: typeof globalThis.fetch): typeof globalThis.fetch {
7
+ return (input, init) => {
8
+ const headers = new Headers(init?.headers)
9
+ headers.set('x-client-source', 'cli')
10
+ return fetchFn(input, { ...init, headers })
11
+ }
12
+ }
13
+
6
14
  export async function getClient(): Promise<VerbatimsClient> {
7
15
  const config = await loadConfig()
8
16
  const apiKey = process.env.VERBATIMS_API_KEY ?? config.apiKey
@@ -14,5 +22,6 @@ export async function getClient(): Promise<VerbatimsClient> {
14
22
 
15
23
  return new VerbatimsClient(apiKey, {
16
24
  baseUrl: process.env.VERBATIMS_BASE_URL ?? config.baseUrl ?? DEFAULT_BASE_URL,
25
+ fetch: withCliSource(globalThis.fetch),
17
26
  })
18
27
  }