@refhub/cli 1.3.0 → 1.5.0
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 +7 -15
- package/bin/refhub.js +2 -0
- package/dist/client.d.ts +11 -5
- package/dist/client.js +6 -32
- package/dist/commands/items.d.ts +4 -0
- package/dist/commands/items.js +14 -2
- package/dist/index.js +0 -1
- package/dist/types.d.ts +3 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -91,8 +91,8 @@ refhub vaults shares remove <vaultId> <shareId>
|
|
|
91
91
|
```bash
|
|
92
92
|
refhub items list --vault <id> [--page] [--limit]
|
|
93
93
|
refhub items get --vault <id> <itemId>
|
|
94
|
-
refhub items add --vault <id> --title <t> [--authors "Smith J,Doe A"] [--year] [--doi] [--tags <id,id>]
|
|
95
|
-
refhub items update --vault <id> <itemId> [--title] [--authors] [--year] [--doi] [--tags <id,id>]
|
|
94
|
+
refhub items add --vault <id> --title <t> [--authors "Smith J,Doe A"] [--year] [--doi] [--url] [--pdf-url] [--tags <id,id>] [--notes]
|
|
95
|
+
refhub items update --vault <id> <itemId> [--title] [--authors] [--year] [--doi] [--url] [--pdf-url] [--tags <id,id>] [--notes]
|
|
96
96
|
refhub items delete --vault <id> <itemId> --confirm
|
|
97
97
|
refhub items upsert --vault <id> --file <items.json> [--idempotency-key]
|
|
98
98
|
refhub items preview --vault <id> --file <items.json>
|
|
@@ -103,6 +103,8 @@ refhub items changes --vault <id> --since <ISO>
|
|
|
103
103
|
|
|
104
104
|
`--tags` on update is a **full replacement**, not an append. a warning is printed to stderr.
|
|
105
105
|
|
|
106
|
+
`--pdf-url` sets the frontend's `publisher_pdf` field (a link to a publisher-hosted PDF). it is distinct from the frontend's `drive_pdf` field (the Google Drive-hosted copy created by `refhub pdf upload`, see below) — the Drive copy is readable back afterward too, as `drive_pdf_url` on item reads (see the `pdf` command below).
|
|
107
|
+
|
|
106
108
|
### tags
|
|
107
109
|
|
|
108
110
|
```bash
|
|
@@ -181,10 +183,10 @@ Uploads a PDF file to the user's linked Google Drive and links it to a vault ite
|
|
|
181
183
|
refhub pdf upload --vault <vaultId> --item <itemId> --file <path/to/file.pdf>
|
|
182
184
|
```
|
|
183
185
|
|
|
184
|
-
-
|
|
185
|
-
- raw API uploads are capped by the backend at the smallest of `REFHUB_API_MAX_BODY_BYTES`, `GOOGLE_DRIVE_MAX_UPLOAD_BYTES`, and the Netlify synchronous Function ceiling (6 MiB); oversized raw requests return structured `413 pdf_upload_too_large_for_api`
|
|
186
|
-
- larger PDFs use the API-key resumable Drive flow: `POST /api/v1/vaults/:vaultId/items/:itemId/pdf/session`, direct `PUT` of the PDF bytes to the returned Google Drive `upload_url`, then `POST /api/v1/vaults/:vaultId/items/:itemId/pdf/complete`
|
|
186
|
+
- all PDF uploads use the resumable Drive flow, regardless of file size — there is no raw-body upload route anymore: `POST /api/v1/vaults/:vaultId/items/:itemId/pdf/session`, direct `PUT` of the PDF bytes to the returned Google Drive `upload_url`, then `POST /api/v1/vaults/:vaultId/items/:itemId/pdf/complete`
|
|
187
187
|
- max file size: 26 MB by default, matching the backend Google Drive upload limit
|
|
188
|
+
- on success the response body carries the resulting Google Drive URL directly: `{ data: { stored: true, provider: "google_drive", fileId, driveUrl, folderId, folderName } }`. Deliberately named differently from `pdf_url` (the publisher-hosted link set via `--pdf-url`, see above) since they are unrelated fields.
|
|
189
|
+
- the stored Drive link is also readable afterward as `drive_pdf_url` on `items get`/`items list`/vault reads, and in the refreshed row returned by `items update` — it's the same value the frontend calls `drive_pdf`.
|
|
188
190
|
|
|
189
191
|
---
|
|
190
192
|
|
|
@@ -252,13 +254,3 @@ Releases are published from GitHub Actions via npm Trusted Publishing. See [RELE
|
|
|
252
254
|
| output | chalk • cli-table3 |
|
|
253
255
|
| tests | vitest |
|
|
254
256
|
| build | tsc + tsx |
|
|
255
|
-
|
|
256
|
-
---
|
|
257
|
-
|
|
258
|
-
## // out of scope (v1)
|
|
259
|
-
|
|
260
|
-
not exposed by the cli:
|
|
261
|
-
|
|
262
|
-
- api key management (jwt-only, no cli command)
|
|
263
|
-
- google drive link/unlink setup (browser/JWT-only, no cli command)
|
|
264
|
-
- global audit log (jwt-only, non-vault-scoped, no cli command)
|
package/bin/refhub.js
ADDED
package/dist/client.d.ts
CHANGED
|
@@ -7,12 +7,10 @@ export declare class RefHubError extends Error {
|
|
|
7
7
|
constructor(status: number, code: string, message: string, request_id: string, retry_after_seconds?: number);
|
|
8
8
|
}
|
|
9
9
|
export declare class RefHubClient {
|
|
10
|
-
static readonly RAW_PDF_UPLOAD_LIMIT_BYTES: number;
|
|
11
10
|
private readonly baseUrl;
|
|
12
11
|
private readonly headers;
|
|
13
12
|
constructor(apiKey: string);
|
|
14
13
|
private req;
|
|
15
|
-
private reqBinary;
|
|
16
14
|
private reqText;
|
|
17
15
|
listVaults(): Promise<ApiResponse<Vault[]>>;
|
|
18
16
|
getVault(vaultId: string): Promise<ApiResponse<VaultDetail>>;
|
|
@@ -60,16 +58,20 @@ export declare class RefHubClient {
|
|
|
60
58
|
authors?: string[];
|
|
61
59
|
year?: number;
|
|
62
60
|
doi?: string;
|
|
61
|
+
url?: string;
|
|
63
62
|
tag_ids?: string[];
|
|
64
63
|
notes?: string;
|
|
64
|
+
pdf_url?: string;
|
|
65
65
|
}>): Promise<ApiResponse<Item[]>>;
|
|
66
66
|
updateItem(vaultId: string, itemId: string, body: {
|
|
67
67
|
title?: string;
|
|
68
68
|
authors?: string[];
|
|
69
69
|
year?: number;
|
|
70
70
|
doi?: string;
|
|
71
|
+
url?: string;
|
|
71
72
|
tag_ids?: string[];
|
|
72
73
|
notes?: string;
|
|
74
|
+
pdf_url?: string;
|
|
73
75
|
}): Promise<ApiResponse<Item>>;
|
|
74
76
|
deleteItem(vaultId: string, itemId: string): Promise<ApiResponse<{
|
|
75
77
|
id: string;
|
|
@@ -144,14 +146,17 @@ export declare class RefHubClient {
|
|
|
144
146
|
}>>;
|
|
145
147
|
semanticScholarSearch(query: string, limit?: number): Promise<ApiResponse<SemanticScholarPaper[]>>;
|
|
146
148
|
semanticScholarPaperList(kind: 'recommendations' | 'related' | 'references' | 'citations' | 'cited-by', paperId: string, limit?: number): Promise<ApiResponse<SemanticScholarPaper[]>>;
|
|
147
|
-
uploadItemPdfRaw(vaultId: string, itemId: string, pdfBuffer: Buffer): Promise<ApiResponse<PdfUploadResult>>;
|
|
148
149
|
createItemPdfUploadSession(vaultId: string, itemId: string): Promise<ApiResponse<PdfUploadSession>>;
|
|
149
150
|
completeItemPdfUpload(vaultId: string, itemId: string, body: {
|
|
150
151
|
file_id: string;
|
|
151
152
|
web_view_link?: string | null;
|
|
152
153
|
source_url?: string | null;
|
|
153
154
|
}): Promise<ApiResponse<PdfUploadResult>>;
|
|
154
|
-
|
|
155
|
+
/**
|
|
156
|
+
* The only PDF upload mechanism: create a resumable session, PUT the bytes
|
|
157
|
+
* directly to Google Drive, then record completion. Works at any file
|
|
158
|
+
* size — there is no raw-bytes upload path.
|
|
159
|
+
*/
|
|
155
160
|
uploadItemPdf(vaultId: string, itemId: string, pdfBuffer: Buffer): Promise<ApiResponse<PdfUploadResult>>;
|
|
156
161
|
}
|
|
157
162
|
export interface PdfUploadResult {
|
|
@@ -161,7 +166,8 @@ export interface PdfUploadResult {
|
|
|
161
166
|
fileId?: string;
|
|
162
167
|
folderId?: string;
|
|
163
168
|
folderName?: string;
|
|
164
|
-
|
|
169
|
+
/** URL of the stored copy at `provider` (e.g. Google Drive) — distinct from `pdf_url` (the publisher-hosted PDF link) on Item. */
|
|
170
|
+
driveUrl?: string;
|
|
165
171
|
sourceUrl?: string | null;
|
|
166
172
|
}
|
|
167
173
|
export interface PdfUploadSession {
|
package/dist/client.js
CHANGED
|
@@ -13,7 +13,6 @@ export class RefHubError extends Error {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
export class RefHubClient {
|
|
16
|
-
static RAW_PDF_UPLOAD_LIMIT_BYTES = 6 * 1024 * 1024;
|
|
17
16
|
baseUrl = 'https://refhub-api.netlify.app/api/v1';
|
|
18
17
|
headers;
|
|
19
18
|
constructor(apiKey) {
|
|
@@ -37,19 +36,6 @@ export class RefHubClient {
|
|
|
37
36
|
}
|
|
38
37
|
return res.json();
|
|
39
38
|
}
|
|
40
|
-
async reqBinary(method, path, body, contentType = 'application/octet-stream') {
|
|
41
|
-
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
42
|
-
method,
|
|
43
|
-
headers: { ...this.headers, 'Content-Type': contentType },
|
|
44
|
-
body: body,
|
|
45
|
-
});
|
|
46
|
-
if (!res.ok) {
|
|
47
|
-
const payload = await res.json().catch(() => ({}));
|
|
48
|
-
const err = (payload['error'] ?? {});
|
|
49
|
-
throw new RefHubError(res.status, String(err['code'] ?? 'unknown_error'), String(err['message'] ?? `HTTP ${res.status}`), String(payload['meta']?.['request_id'] ?? err['request_id'] ?? ''));
|
|
50
|
-
}
|
|
51
|
-
return res.json();
|
|
52
|
-
}
|
|
53
39
|
async reqText(method, path) {
|
|
54
40
|
const res = await fetch(`${this.baseUrl}${path}`, { method, headers: this.headers });
|
|
55
41
|
if (!res.ok) {
|
|
@@ -220,16 +206,18 @@ export class RefHubClient {
|
|
|
220
206
|
semanticScholarPaperList(kind, paperId, limit) {
|
|
221
207
|
return this.req('POST', `/semantic-scholar/${kind}`, { paper_id: paperId, ...(limit !== undefined ? { limit } : {}) });
|
|
222
208
|
}
|
|
223
|
-
uploadItemPdfRaw(vaultId, itemId, pdfBuffer) {
|
|
224
|
-
return this.reqBinary('POST', `/vaults/${encodeURIComponent(vaultId)}/items/${encodeURIComponent(itemId)}/pdf`, pdfBuffer, 'application/pdf');
|
|
225
|
-
}
|
|
226
209
|
createItemPdfUploadSession(vaultId, itemId) {
|
|
227
210
|
return this.req('POST', `/vaults/${encodeURIComponent(vaultId)}/items/${encodeURIComponent(itemId)}/pdf/session`, {});
|
|
228
211
|
}
|
|
229
212
|
completeItemPdfUpload(vaultId, itemId, body) {
|
|
230
213
|
return this.req('POST', `/vaults/${encodeURIComponent(vaultId)}/items/${encodeURIComponent(itemId)}/pdf/complete`, body);
|
|
231
214
|
}
|
|
232
|
-
|
|
215
|
+
/**
|
|
216
|
+
* The only PDF upload mechanism: create a resumable session, PUT the bytes
|
|
217
|
+
* directly to Google Drive, then record completion. Works at any file
|
|
218
|
+
* size — there is no raw-bytes upload path.
|
|
219
|
+
*/
|
|
220
|
+
async uploadItemPdf(vaultId, itemId, pdfBuffer) {
|
|
233
221
|
const session = await this.createItemPdfUploadSession(vaultId, itemId);
|
|
234
222
|
const driveResponse = await fetch(session.data.upload_url, {
|
|
235
223
|
method: 'PUT',
|
|
@@ -252,20 +240,6 @@ export class RefHubClient {
|
|
|
252
240
|
web_view_link: driveUpload.webViewLink ?? null,
|
|
253
241
|
});
|
|
254
242
|
}
|
|
255
|
-
async uploadItemPdf(vaultId, itemId, pdfBuffer) {
|
|
256
|
-
if (pdfBuffer.length > RefHubClient.RAW_PDF_UPLOAD_LIMIT_BYTES) {
|
|
257
|
-
return this.uploadItemPdfResumable(vaultId, itemId, pdfBuffer);
|
|
258
|
-
}
|
|
259
|
-
try {
|
|
260
|
-
return await this.uploadItemPdfRaw(vaultId, itemId, pdfBuffer);
|
|
261
|
-
}
|
|
262
|
-
catch (err) {
|
|
263
|
-
if (err instanceof RefHubError && err.status === 413 && err.code === 'pdf_upload_too_large_for_api') {
|
|
264
|
-
return this.uploadItemPdfResumable(vaultId, itemId, pdfBuffer);
|
|
265
|
-
}
|
|
266
|
-
throw err;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
243
|
}
|
|
270
244
|
// ── Helpers ───────────────────────────────────────────────────────────────────
|
|
271
245
|
export function resolveClient(apiKey) {
|
package/dist/commands/items.d.ts
CHANGED
|
@@ -10,16 +10,20 @@ export declare function handleItemAdd(client: RefHubClient, vaultId: string, opt
|
|
|
10
10
|
authors?: string;
|
|
11
11
|
year?: number;
|
|
12
12
|
doi?: string;
|
|
13
|
+
url?: string;
|
|
13
14
|
tags?: string;
|
|
14
15
|
notes?: string;
|
|
16
|
+
pdfUrl?: string;
|
|
15
17
|
}, tableMode: boolean): Promise<void>;
|
|
16
18
|
export declare function handleItemUpdate(client: RefHubClient, vaultId: string, itemId: string, opts: {
|
|
17
19
|
title?: string;
|
|
18
20
|
authors?: string;
|
|
19
21
|
year?: number;
|
|
20
22
|
doi?: string;
|
|
23
|
+
url?: string;
|
|
21
24
|
tags?: string;
|
|
22
25
|
notes?: string;
|
|
26
|
+
pdfUrl?: string;
|
|
23
27
|
}, tableMode: boolean): Promise<void>;
|
|
24
28
|
export declare function handleItemDelete(client: RefHubClient, vaultId: string, itemId: string, confirmed: boolean): Promise<void>;
|
|
25
29
|
export declare function handleItemUpsert(client: RefHubClient, vaultId: string, filePath: string, idempotencyKey: string | undefined, tableMode: boolean): Promise<void>;
|
package/dist/commands/items.js
CHANGED
|
@@ -18,10 +18,14 @@ export async function handleItemAdd(client, vaultId, opts, tableMode) {
|
|
|
18
18
|
item['year'] = opts.year;
|
|
19
19
|
if (opts.doi)
|
|
20
20
|
item['doi'] = opts.doi;
|
|
21
|
+
if (opts.url !== undefined)
|
|
22
|
+
item['url'] = opts.url;
|
|
21
23
|
if (opts.tags)
|
|
22
24
|
item['tag_ids'] = opts.tags.split(',').map((t) => t.trim());
|
|
23
25
|
if (opts.notes !== undefined)
|
|
24
26
|
item['notes'] = opts.notes;
|
|
27
|
+
if (opts.pdfUrl !== undefined)
|
|
28
|
+
item['pdf_url'] = opts.pdfUrl;
|
|
25
29
|
const result = await client.addItems(vaultId, [item]);
|
|
26
30
|
format(result, tableMode, ['id', 'title', 'doi', 'year']);
|
|
27
31
|
}
|
|
@@ -35,8 +39,12 @@ export async function handleItemUpdate(client, vaultId, itemId, opts, tableMode)
|
|
|
35
39
|
body['year'] = opts.year;
|
|
36
40
|
if (opts.doi)
|
|
37
41
|
body['doi'] = opts.doi;
|
|
42
|
+
if (opts.url !== undefined)
|
|
43
|
+
body['url'] = opts.url;
|
|
38
44
|
if (opts.notes !== undefined)
|
|
39
45
|
body['notes'] = opts.notes;
|
|
46
|
+
if (opts.pdfUrl !== undefined)
|
|
47
|
+
body['pdf_url'] = opts.pdfUrl;
|
|
40
48
|
if (opts.tags) {
|
|
41
49
|
process.stderr.write(JSON.stringify({ warning: 'tag_replacement', message: '--tags replaces the full tag set, not an append. Existing tags will be removed.' }) + '\n');
|
|
42
50
|
body['tag_ids'] = opts.tags.split(',').map((t) => t.trim());
|
|
@@ -121,12 +129,14 @@ export function registerItems(program) {
|
|
|
121
129
|
.option('--authors <authors>', 'comma-separated, e.g. "Smith J,Doe A"')
|
|
122
130
|
.option('--year <year>', 'publication year', (v) => parseInt(v, 10))
|
|
123
131
|
.option('--doi <doi>')
|
|
132
|
+
.option('--url <url>', 'publication URL')
|
|
124
133
|
.option('--tags <ids>', 'comma-separated tag IDs')
|
|
125
134
|
.option('--notes <text>', 'free-text notes on the item')
|
|
135
|
+
.option('--pdf-url <url>', "publisher PDF link (the frontend's publisher_pdf field)")
|
|
126
136
|
.action(async (opts, cmd) => {
|
|
127
137
|
const g = cmd.optsWithGlobals();
|
|
128
138
|
const client = resolveClient(g.apiKey);
|
|
129
|
-
await run(() => handleItemAdd(client, opts.vault, { title: opts.title, authors: opts.authors, year: opts.year, doi: opts.doi, tags: opts.tags, notes: opts.notes }, g.table ?? false));
|
|
139
|
+
await run(() => handleItemAdd(client, opts.vault, { title: opts.title, authors: opts.authors, year: opts.year, doi: opts.doi, url: opts.url, tags: opts.tags, notes: opts.notes, pdfUrl: opts.pdfUrl }, g.table ?? false));
|
|
130
140
|
});
|
|
131
141
|
items
|
|
132
142
|
.command('update')
|
|
@@ -137,12 +147,14 @@ export function registerItems(program) {
|
|
|
137
147
|
.option('--authors <authors>')
|
|
138
148
|
.option('--year <year>', '', (v) => parseInt(v, 10))
|
|
139
149
|
.option('--doi <doi>')
|
|
150
|
+
.option('--url <url>', 'publication URL')
|
|
140
151
|
.option('--tags <ids>', 'comma-separated tag IDs — REPLACES the full tag set')
|
|
141
152
|
.option('--notes <text>', 'free-text notes on the item')
|
|
153
|
+
.option('--pdf-url <url>', "publisher PDF link (the frontend's publisher_pdf field)")
|
|
142
154
|
.action(async (itemId, opts, cmd) => {
|
|
143
155
|
const g = cmd.optsWithGlobals();
|
|
144
156
|
const client = resolveClient(g.apiKey);
|
|
145
|
-
await run(() => handleItemUpdate(client, opts.vault, itemId, { title: opts.title, authors: opts.authors, year: opts.year, doi: opts.doi, tags: opts.tags, notes: opts.notes }, g.table ?? false));
|
|
157
|
+
await run(() => handleItemUpdate(client, opts.vault, itemId, { title: opts.title, authors: opts.authors, year: opts.year, doi: opts.doi, url: opts.url, tags: opts.tags, notes: opts.notes, pdfUrl: opts.pdfUrl }, g.table ?? false));
|
|
146
158
|
});
|
|
147
159
|
items
|
|
148
160
|
.command('delete')
|
package/dist/index.js
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -20,9 +20,12 @@ export interface Item {
|
|
|
20
20
|
authors?: string[];
|
|
21
21
|
year?: number;
|
|
22
22
|
doi?: string;
|
|
23
|
+
url?: string;
|
|
23
24
|
bibtex_key?: string;
|
|
24
25
|
abstract?: string;
|
|
25
26
|
notes?: string;
|
|
27
|
+
pdf_url?: string;
|
|
28
|
+
drive_pdf_url?: string | null;
|
|
26
29
|
tag_ids: string[];
|
|
27
30
|
version: number;
|
|
28
31
|
created_at: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@refhub/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "refhub CLI execution layer for agent skills",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -12,15 +12,15 @@
|
|
|
12
12
|
"url": "https://github.com/refhub-io/refhub-cli/issues"
|
|
13
13
|
},
|
|
14
14
|
"engines": { "node": ">=18" },
|
|
15
|
-
"bin": { "refhub": "
|
|
15
|
+
"bin": { "refhub": "bin/refhub.js" },
|
|
16
16
|
"scripts": {
|
|
17
|
-
"build": "tsc
|
|
17
|
+
"build": "tsc",
|
|
18
18
|
"test": "vitest run",
|
|
19
19
|
"test:watch": "vitest",
|
|
20
20
|
"smoke": "tsx scripts/smoke.ts",
|
|
21
21
|
"dev": "tsx src/index.ts"
|
|
22
22
|
},
|
|
23
|
-
"files": ["dist"],
|
|
23
|
+
"files": ["dist", "bin"],
|
|
24
24
|
"publishConfig": {
|
|
25
25
|
"access": "public"
|
|
26
26
|
},
|