@verbatims/cli 1.0.0 → 1.0.1

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
@@ -29,12 +29,12 @@ verbatims quotes get 123 --format json
29
29
  verbatims quotes attributions list 123
30
30
  verbatims quotes attributions create 123 --author-id 1 --reference-id 2 --status manually_verified --primary
31
31
  verbatims quotes sources list 123
32
- verbatims quotes sources create 123 --source-type book --source-url https://example.com/edition --status externally_verified
32
+ verbatims quotes sources create 123 --attribution-id 7 --source-type book --source-url https://example.com/edition --status externally_verified
33
33
 
34
34
  # Create a quote with a source
35
- verbatims quotes create --provenance-source-type book --provenance-source-url https://example.com/edition
35
+ verbatims quotes create --name "Alea jacta est" --author-id 1 --source-type book --source-url https://example.com/edition
36
36
 
37
- Use the `--provenance-*` options for primary provenance. The dedicated `quotes attributions` and `quotes sources` commands manage secondary provenance.
37
+ Use `--author-id` or `--reference-id` to create the required primary attribution. Sources always require `--attribution-id`; use the dedicated `quotes attributions` and `quotes sources` commands for additional or edited provenance.
38
38
 
39
39
  # Browse interactively
40
40
  verbatims quotes browse
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verbatims/cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "CLI for the Verbatims quotes API",
5
5
  "type": "module",
6
6
  "bin": {
@@ -16,7 +16,7 @@
16
16
  "typecheck": "tsc --noEmit"
17
17
  },
18
18
  "dependencies": {
19
- "@verbatims/sdk": "^2.0.0",
19
+ "@verbatims/sdk": "^2.0.1",
20
20
  "@clack/prompts": "^0.10.1",
21
21
  "chalk": "^5.4.1",
22
22
  "commander": "^13.1.0",
@@ -66,10 +66,10 @@ export function registerQuotesCommand(program: Command) {
66
66
  .description('Create a quote')
67
67
  .option('--name <text>', 'Quote text')
68
68
  .option('--language <lang>', 'Language')
69
- .option('--provenance-author-id <id>', 'Primary provenance author ID')
70
- .option('--provenance-reference-id <id>', 'Primary provenance reference ID')
71
- .option('--provenance-source-type <type>', 'Primary provenance source type')
72
- .option('--provenance-source-url <url>', 'Primary provenance source URL')
69
+ .option('--author-id <id>', 'Primary attribution author ID')
70
+ .option('--reference-id <id>', 'Primary attribution reference ID')
71
+ .option('--source-type <type>', 'Source type for the primary attribution')
72
+ .option('--source-url <url>', 'Source URL for the primary attribution')
73
73
  .action(async (options: Record<string, string>) => {
74
74
  const client = await getClient()
75
75
  const format = getFormat(program)
@@ -80,22 +80,31 @@ export function registerQuotesCommand(program: Command) {
80
80
  const language = options.language ?? await text({ message: 'Language', initialValue: 'fr' })
81
81
  if (isCancel(language)) cancel('Cancelled')
82
82
 
83
- const authorId = options.provenanceAuthorId ? Number(options.provenanceAuthorId) : undefined
84
- const referenceId = options.provenanceReferenceId ? Number(options.provenanceReferenceId) : undefined
83
+ const authorId = options.authorId ? Number(options.authorId) : undefined
84
+ const referenceId = options.referenceId ? Number(options.referenceId) : undefined
85
+ if (authorId === undefined && referenceId === undefined) {
86
+ throw new Error('A quote requires --author-id or --reference-id')
87
+ }
85
88
 
86
89
  const { data } = await withSpinner('Creating quote', () =>
87
90
  client.quotes.create({
88
91
  content: name as string,
89
92
  name: name as string,
90
93
  language: language as string,
91
- provenance: {
92
- author_id: authorId,
93
- reference_id: referenceId,
94
- source: options.provenanceSourceType ? { source_type: options.provenanceSourceType, source_url: options.provenanceSourceUrl } : undefined,
95
- },
94
+ attributions: [{ author_id: authorId, reference_id: referenceId, is_primary: true }],
96
95
  }),
97
96
  format,
98
97
  )
98
+ if (options.sourceType && data) {
99
+ const primary = data.attributions?.find(attribution => attribution.is_primary)
100
+ if (!primary) throw new Error('The created quote has no primary attribution')
101
+ await withSpinner('Creating source', () => client.quotes.createSource(data.id, {
102
+ attribution_id: primary.id,
103
+ source_type: options.sourceType,
104
+ source_url: options.sourceUrl,
105
+ is_primary: true,
106
+ }), format)
107
+ }
99
108
  console.log(chalk.green(' Quote created'))
100
109
  output(data, format)
101
110
  })
@@ -105,10 +114,8 @@ export function registerQuotesCommand(program: Command) {
105
114
  .description('Update a quote')
106
115
  .option('--name <text>', 'Quote text')
107
116
  .option('--language <lang>', 'Language')
108
- .option('--provenance-author-id <id>', 'Primary provenance author ID')
109
- .option('--provenance-reference-id <id>', 'Primary provenance reference ID')
110
- .option('--provenance-source-type <type>', 'Primary provenance source type')
111
- .option('--provenance-source-url <url>', 'Primary provenance source URL')
117
+ .option('--author-id <id>', 'Primary attribution author ID')
118
+ .option('--reference-id <id>', 'Primary attribution reference ID')
112
119
  .action(async (id: string, options: Record<string, string>) => {
113
120
  const client = await getClient()
114
121
  const format = getFormat(program)
@@ -116,16 +123,19 @@ export function registerQuotesCommand(program: Command) {
116
123
  const data_: Record<string, unknown> = {}
117
124
  if (options.name) { data_.name = options.name; data_.content = options.name }
118
125
  if (options.language) data_.language = options.language
119
- if (options.provenanceAuthorId !== undefined) data_.provenance = { ...(data_.provenance as object), author_id: options.provenanceAuthorId === 'null' ? null : Number(options.provenanceAuthorId) }
120
- if (options.provenanceReferenceId !== undefined) data_.provenance = { ...(data_.provenance as object), reference_id: options.provenanceReferenceId === 'null' ? null : Number(options.provenanceReferenceId) }
121
- if (options.provenanceSourceType !== undefined || options.provenanceSourceUrl !== undefined) {
122
- data_.provenance = {
123
- ...(data_.provenance as object),
124
- source: { source_type: options.provenanceSourceType ?? 'manual', source_url: options.provenanceSourceUrl },
125
- }
126
- }
126
+ const authorId = options.authorId === undefined ? undefined : options.authorId === 'null' ? null : Number(options.authorId)
127
+ const referenceId = options.referenceId === undefined ? undefined : options.referenceId === 'null' ? null : Number(options.referenceId)
127
128
 
128
129
  const { data } = await withSpinner('Updating quote', () => client.quotes.update(Number(id), data_ as any), format)
130
+ if (authorId !== undefined || referenceId !== undefined) {
131
+ const attributions = await client.quotes.listAttributions(Number(id))
132
+ const primary = attributions.data?.find(attribution => attribution.is_primary)
133
+ if (!primary) throw new Error('The quote has no primary attribution')
134
+ await withSpinner('Updating primary attribution', () => client.quotes.updateAttribution(Number(id), primary.id, {
135
+ author_id: authorId === undefined ? primary.author_id : authorId,
136
+ reference_id: referenceId === undefined ? primary.reference_id : referenceId,
137
+ }), format)
138
+ }
129
139
  console.log(chalk.green(' Quote updated'))
130
140
  output(data, format)
131
141
  })
@@ -297,8 +307,9 @@ export function registerQuotesCommand(program: Command) {
297
307
  }
298
308
  if (action === 'create') {
299
309
  if (!options.sourceType) throw new Error('--source-type is required')
310
+ if (!options.attributionId) throw new Error('--attribution-id is required')
300
311
  const { data } = await withSpinner('Creating source', () => client.quotes.createSource(id, {
301
- attribution_id: options.attributionId ? Number(options.attributionId) : null,
312
+ attribution_id: Number(options.attributionId),
302
313
  source_type: options.sourceType,
303
314
  source_url: options.sourceUrl,
304
315
  label: options.label,