@verbatims/cli 0.1.9 → 0.1.10
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 +1 -1
- package/src/index.ts +2 -0
- package/src/utils/client.ts +9 -0
package/package.json
CHANGED
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()
|
package/src/utils/client.ts
CHANGED
|
@@ -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
|
}
|