@refhub/cli 1.0.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 ADDED
@@ -0,0 +1,212 @@
1
+ # refhub cli
2
+
3
+ > command-line execution layer for the [refhub.io](https://refhub.io) API.
4
+ > manage vaults, papers, tags, and relations — scriptable, pipeable, agent-ready.
5
+
6
+ ---
7
+
8
+ ## // install
9
+
10
+ ```bash
11
+ git clone https://github.com/refhub/refhub-cli
12
+ cd refhub-cli
13
+ npm install
14
+ npm run build
15
+ npm link
16
+ ```
17
+
18
+ `npm link` makes `refhub` available globally without publishing to npm.
19
+
20
+ **requires** node ≥ 18.
21
+
22
+ ---
23
+
24
+ ## // auth
25
+
26
+ ```bash
27
+ export REFHUB_API_KEY=your_key_here
28
+ ```
29
+
30
+ or pass inline:
31
+
32
+ ```bash
33
+ refhub --api-key <key> vaults list
34
+ ```
35
+
36
+ key resolution order: `--api-key` flag → `REFHUB_API_KEY` env → exit 3.
37
+
38
+ ---
39
+
40
+ ## // usage
41
+
42
+ ```
43
+ refhub [--api-key <key>] [--table] <command> [subcommand] [options]
44
+ ```
45
+
46
+ | flag | behavior |
47
+ |------|----------|
48
+ | `--api-key` | override `REFHUB_API_KEY` |
49
+ | `--table` | human-readable table output (default: json) |
50
+ | `--version` | print version |
51
+ | `--help` | available on every command and subcommand |
52
+
53
+ output to stdout is always json by default — pipe-friendly:
54
+
55
+ ```bash
56
+ refhub vaults list | jq .data
57
+ refhub items search --vault <id> --q "attention" | jq '.data[].title'
58
+ ```
59
+
60
+ errors always go to stderr as json, regardless of `--table`.
61
+
62
+ ---
63
+
64
+ ## // commands
65
+
66
+ ### vaults
67
+
68
+ ```bash
69
+ refhub vaults list
70
+ refhub vaults get <vaultId>
71
+ refhub vaults create --name <n> [--description] [--color] [--visibility] [--category]
72
+ refhub vaults update <vaultId> [--name] [--description] [--color] [--category]
73
+ refhub vaults delete <vaultId> --confirm
74
+ refhub vaults visibility <vaultId> --visibility <private|protected|public> [--slug]
75
+
76
+ # shares
77
+ refhub vaults shares list <vaultId>
78
+ refhub vaults shares add <vaultId> --email <e> --role <viewer|editor>
79
+ refhub vaults shares update <vaultId> <shareId> --role <viewer|editor>
80
+ refhub vaults shares remove <vaultId> <shareId>
81
+ ```
82
+
83
+ ### items
84
+
85
+ ```bash
86
+ refhub items list --vault <id> [--page] [--limit]
87
+ refhub items get --vault <id> <itemId>
88
+ refhub items add --vault <id> --title <t> [--authors "Smith J,Doe A"] [--year] [--doi] [--tags <id,id>]
89
+ refhub items update --vault <id> <itemId> [--title] [--authors] [--year] [--doi] [--tags <id,id>]
90
+ refhub items delete --vault <id> <itemId> --confirm
91
+ refhub items upsert --vault <id> --file <items.json> [--idempotency-key]
92
+ refhub items preview --vault <id> --file <items.json>
93
+ refhub items search --vault <id> --q <query> [--author] [--year] [--doi] [--tag] [--page] [--limit]
94
+ refhub items stats --vault <id>
95
+ refhub items changes --vault <id> --since <ISO>
96
+ ```
97
+
98
+ `--tags` on update is a **full replacement**, not an append. a warning is printed to stderr.
99
+
100
+ ### tags
101
+
102
+ ```bash
103
+ refhub tags list --vault <id>
104
+ refhub tags create --vault <id> --name <n> [--color] [--parent]
105
+ refhub tags update --vault <id> <tagId> [--name] [--color] [--parent]
106
+ refhub tags delete --vault <id> <tagId>
107
+ refhub tags attach --vault <id> --item <itemId> --tags <id,id>
108
+ refhub tags detach --vault <id> --item <itemId> --tags <id,id>
109
+ ```
110
+
111
+ ### relations
112
+
113
+ ```bash
114
+ refhub relations list --vault <id> [--type]
115
+ refhub relations create --vault <id> --pub <pubId> --related <pubId> [--type <cites|extends|builds_on|contradicts|reviews|related>]
116
+ refhub relations update --vault <id> <relationId> --type <...>
117
+ refhub relations delete --vault <id> <relationId>
118
+ ```
119
+
120
+ ### import
121
+
122
+ ```bash
123
+ refhub import doi --vault <id> --doi <doi> [--tags <id,id>]
124
+ refhub import bibtex --vault <id> (--bibtex <string> | --file <path>) [--tags]
125
+ refhub import url --vault <id> --url <url> [--tags]
126
+ ```
127
+
128
+ ### export
129
+
130
+ ```bash
131
+ refhub export --vault <id> [--format json|bibtex]
132
+ ```
133
+
134
+ ### audit
135
+
136
+ ```bash
137
+ refhub audit --vault <id> [--since <ISO>] [--until <ISO>] [--limit] [--page]
138
+ ```
139
+
140
+ ---
141
+
142
+ ## // exit codes
143
+
144
+ | code | meaning |
145
+ |------|---------|
146
+ | `0` | success |
147
+ | `1` | API error (4xx/5xx) |
148
+ | `2` | bad arguments |
149
+ | `3` | auth error (missing or invalid key) |
150
+
151
+ ---
152
+
153
+ ## // error shape
154
+
155
+ all errors are written to stderr as json:
156
+
157
+ ```json
158
+ {
159
+ "error": {
160
+ "code": "missing_scope",
161
+ "message": "key lacks vaults:write scope",
162
+ "request_id": "req_abc123"
163
+ }
164
+ }
165
+ ```
166
+
167
+ rate-limited responses (429) include `retry_after_seconds`.
168
+
169
+ ---
170
+
171
+ ## // guardrails
172
+
173
+ - `vaults delete` and `items delete` require `--confirm` — hard deletes, no undo
174
+ - `items upsert` without `--idempotency-key` emits a `partial_write_risk` warning before exiting 1 on failure
175
+ - `items update --tags` warns that the tags list is a full replacement
176
+
177
+ ---
178
+
179
+ ## // dev
180
+
181
+ ```bash
182
+ npm run dev # run via tsx (no build step)
183
+ npm test # vitest unit tests
184
+ npm run smoke # live end-to-end sequence (requires REFHUB_API_KEY)
185
+ npm run build # tsc → dist/
186
+ ```
187
+
188
+ smoke test covers: `list_vaults` → `create_vault` → `tag_crud` → `relation_crud` → `export` → `delete_vault`.
189
+
190
+ ---
191
+
192
+ ## // stack
193
+
194
+ | layer | tool |
195
+ |-------|------|
196
+ | runtime | node ≥ 18 |
197
+ | language | typescript 5.x |
198
+ | cli framework | commander |
199
+ | output | chalk • cli-table3 |
200
+ | tests | vitest |
201
+ | build | tsc + tsx |
202
+
203
+ ---
204
+
205
+ ## // out of scope (v1)
206
+
207
+ not exposed by the cli — these routes require a human session (jwt-only):
208
+
209
+ - api key management
210
+ - google drive integration
211
+ - semantic scholar recommendations / references
212
+ - global audit log (non-vault-scoped)
@@ -0,0 +1,136 @@
1
+ import type { ApiResponse, Vault, VaultDetail, Share, Item, UpsertResult, PreviewResult, Tag, Relation, BibTeXImportResult, AuditEntry, VaultStats, RelationType } from './types.js';
2
+ export declare class RefHubError extends Error {
3
+ readonly code: string;
4
+ readonly request_id: string;
5
+ readonly status: number;
6
+ readonly retry_after_seconds?: number;
7
+ constructor(status: number, code: string, message: string, request_id: string, retry_after_seconds?: number);
8
+ }
9
+ export declare class RefHubClient {
10
+ private readonly baseUrl;
11
+ private readonly headers;
12
+ constructor(apiKey: string);
13
+ private req;
14
+ private reqText;
15
+ listVaults(): Promise<ApiResponse<Vault[]>>;
16
+ getVault(vaultId: string): Promise<ApiResponse<VaultDetail>>;
17
+ createVault(body: {
18
+ name: string;
19
+ description?: string;
20
+ color?: string;
21
+ visibility?: string;
22
+ category?: string;
23
+ abstract?: string;
24
+ }): Promise<ApiResponse<Vault>>;
25
+ updateVault(vaultId: string, body: {
26
+ name?: string;
27
+ description?: string;
28
+ color?: string;
29
+ category?: string;
30
+ abstract?: string;
31
+ }): Promise<ApiResponse<Vault>>;
32
+ deleteVault(vaultId: string): Promise<ApiResponse<{
33
+ id: string;
34
+ }>>;
35
+ setVaultVisibility(vaultId: string, body: {
36
+ visibility: string;
37
+ public_slug?: string;
38
+ }): Promise<ApiResponse<Vault>>;
39
+ listShares(vaultId: string): Promise<ApiResponse<Share[]>>;
40
+ addShare(vaultId: string, body: {
41
+ email: string;
42
+ role: 'viewer' | 'editor';
43
+ name?: string;
44
+ }): Promise<ApiResponse<Share>>;
45
+ updateShare(vaultId: string, shareId: string, body: {
46
+ role: 'viewer' | 'editor';
47
+ }): Promise<ApiResponse<Share>>;
48
+ removeShare(vaultId: string, shareId: string): Promise<ApiResponse<{
49
+ id: string;
50
+ }>>;
51
+ listItems(vaultId: string, params?: {
52
+ page?: number;
53
+ limit?: number;
54
+ }): Promise<ApiResponse<Item[]>>;
55
+ getItem(vaultId: string, itemId: string): Promise<ApiResponse<Item>>;
56
+ addItems(vaultId: string, items: Array<{
57
+ title: string;
58
+ authors?: string[];
59
+ year?: number;
60
+ doi?: string;
61
+ tag_ids?: string[];
62
+ }>): Promise<ApiResponse<Item[]>>;
63
+ updateItem(vaultId: string, itemId: string, body: {
64
+ title?: string;
65
+ authors?: string[];
66
+ year?: number;
67
+ doi?: string;
68
+ tag_ids?: string[];
69
+ }): Promise<ApiResponse<Item>>;
70
+ deleteItem(vaultId: string, itemId: string): Promise<ApiResponse<{
71
+ id: string;
72
+ }>>;
73
+ upsertItems(vaultId: string, items: unknown[], idempotencyKey?: string): Promise<ApiResponse<UpsertResult>>;
74
+ previewImport(vaultId: string, items: unknown[]): Promise<ApiResponse<PreviewResult>>;
75
+ searchItems(vaultId: string, params: {
76
+ q?: string;
77
+ author?: string;
78
+ year?: number;
79
+ doi?: string;
80
+ tag_id?: string;
81
+ page?: number;
82
+ limit?: number;
83
+ }): Promise<ApiResponse<Item[]>>;
84
+ getStats(vaultId: string): Promise<ApiResponse<VaultStats>>;
85
+ getChanges(vaultId: string, since: string): Promise<ApiResponse<Item[]>>;
86
+ listTags(vaultId: string): Promise<ApiResponse<Tag[]>>;
87
+ createTag(vaultId: string, body: {
88
+ name: string;
89
+ color?: string;
90
+ parent_id?: string;
91
+ }): Promise<ApiResponse<Tag>>;
92
+ updateTag(vaultId: string, tagId: string, body: {
93
+ name?: string;
94
+ color?: string;
95
+ parent_id?: string;
96
+ }): Promise<ApiResponse<Tag>>;
97
+ deleteTag(vaultId: string, tagId: string): Promise<ApiResponse<{
98
+ id: string;
99
+ }>>;
100
+ attachTags(vaultId: string, itemId: string, tagIds: string[]): Promise<ApiResponse<{
101
+ item_id: string;
102
+ tag_ids: string[];
103
+ }>>;
104
+ detachTags(vaultId: string, itemId: string, tagIds: string[]): Promise<ApiResponse<{
105
+ item_id: string;
106
+ tag_ids: string[];
107
+ }>>;
108
+ listRelations(vaultId: string, type?: string): Promise<ApiResponse<Relation[]>>;
109
+ createRelation(vaultId: string, body: {
110
+ publication_id: string;
111
+ related_publication_id: string;
112
+ relation_type?: RelationType;
113
+ }): Promise<ApiResponse<Relation>>;
114
+ updateRelation(vaultId: string, relationId: string, body: {
115
+ relation_type: RelationType;
116
+ }): Promise<ApiResponse<Relation>>;
117
+ deleteRelation(vaultId: string, relationId: string): Promise<ApiResponse<{
118
+ id: string;
119
+ }>>;
120
+ importDoi(vaultId: string, doi: string, tagIds?: string[]): Promise<ApiResponse<{
121
+ item: Item;
122
+ }>>;
123
+ importBibtex(vaultId: string, bibtex: string, tagIds?: string[]): Promise<ApiResponse<BibTeXImportResult>>;
124
+ importUrl(vaultId: string, url: string, tagIds?: string[]): Promise<ApiResponse<{
125
+ item: Item;
126
+ }>>;
127
+ exportVault(vaultId: string, format?: 'json' | 'bibtex'): Promise<string>;
128
+ getAudit(vaultId: string, params?: {
129
+ since?: string;
130
+ until?: string;
131
+ limit?: number;
132
+ page?: number;
133
+ }): Promise<ApiResponse<AuditEntry[]>>;
134
+ }
135
+ export declare function resolveClient(apiKey?: string): RefHubClient;
136
+ export declare function run(fn: () => Promise<void>): Promise<void>;
package/dist/client.js ADDED
@@ -0,0 +1,223 @@
1
+ export class RefHubError extends Error {
2
+ code;
3
+ request_id;
4
+ status;
5
+ retry_after_seconds;
6
+ constructor(status, code, message, request_id, retry_after_seconds) {
7
+ super(message);
8
+ this.name = 'RefHubError';
9
+ this.status = status;
10
+ this.code = code;
11
+ this.request_id = request_id;
12
+ this.retry_after_seconds = retry_after_seconds;
13
+ }
14
+ }
15
+ export class RefHubClient {
16
+ baseUrl = 'https://refhub-api.netlify.app/api/v1';
17
+ headers;
18
+ constructor(apiKey) {
19
+ this.headers = {
20
+ Authorization: `Bearer ${apiKey}`,
21
+ 'Content-Type': 'application/json',
22
+ };
23
+ }
24
+ async req(method, path, body) {
25
+ const res = await fetch(`${this.baseUrl}${path}`, {
26
+ method,
27
+ headers: this.headers,
28
+ body: body !== undefined ? JSON.stringify(body) : undefined,
29
+ });
30
+ if (!res.ok) {
31
+ const payload = await res.json().catch(() => ({}));
32
+ const err = (payload['error'] ?? {});
33
+ throw new RefHubError(res.status, String(err['code'] ?? 'unknown_error'), String(err['message'] ?? `HTTP ${res.status}`), String(err['request_id'] ?? ''), typeof payload['retry_after_seconds'] === 'number' ? payload['retry_after_seconds'] : undefined);
34
+ }
35
+ return res.json();
36
+ }
37
+ async reqText(method, path) {
38
+ const res = await fetch(`${this.baseUrl}${path}`, { method, headers: this.headers });
39
+ if (!res.ok) {
40
+ const payload = await res.json().catch(() => ({}));
41
+ const err = (payload['error'] ?? {});
42
+ throw new RefHubError(res.status, String(err['code'] ?? 'unknown_error'), String(err['message'] ?? `HTTP ${res.status}`), String(err['request_id'] ?? ''));
43
+ }
44
+ return res.text();
45
+ }
46
+ // ── Vaults ──────────────────────────────────────────────────────────────────
47
+ listVaults() {
48
+ return this.req('GET', '/vaults');
49
+ }
50
+ getVault(vaultId) {
51
+ return this.req('GET', `/vaults/${vaultId}`);
52
+ }
53
+ createVault(body) {
54
+ return this.req('POST', '/vaults', body);
55
+ }
56
+ updateVault(vaultId, body) {
57
+ return this.req('PATCH', `/vaults/${vaultId}`, body);
58
+ }
59
+ deleteVault(vaultId) {
60
+ return this.req('DELETE', `/vaults/${vaultId}`);
61
+ }
62
+ setVaultVisibility(vaultId, body) {
63
+ return this.req('PATCH', `/vaults/${vaultId}/visibility`, body);
64
+ }
65
+ listShares(vaultId) {
66
+ return this.req('GET', `/vaults/${vaultId}/shares`);
67
+ }
68
+ addShare(vaultId, body) {
69
+ return this.req('POST', `/vaults/${vaultId}/shares`, body);
70
+ }
71
+ updateShare(vaultId, shareId, body) {
72
+ return this.req('PATCH', `/vaults/${vaultId}/shares/${shareId}`, body);
73
+ }
74
+ removeShare(vaultId, shareId) {
75
+ return this.req('DELETE', `/vaults/${vaultId}/shares/${shareId}`);
76
+ }
77
+ // ── Items ────────────────────────────────────────────────────────────────────
78
+ listItems(vaultId, params = {}) {
79
+ const q = new URLSearchParams();
80
+ if (params.page !== undefined)
81
+ q.set('page', String(params.page));
82
+ if (params.limit !== undefined)
83
+ q.set('limit', String(params.limit));
84
+ const qs = q.toString() ? `?${q}` : '';
85
+ return this.req('GET', `/vaults/${vaultId}/items${qs}`);
86
+ }
87
+ getItem(vaultId, itemId) {
88
+ return this.req('GET', `/vaults/${vaultId}/items/${itemId}`);
89
+ }
90
+ addItems(vaultId, items) {
91
+ return this.req('POST', `/vaults/${vaultId}/items`, { items });
92
+ }
93
+ updateItem(vaultId, itemId, body) {
94
+ return this.req('PATCH', `/vaults/${vaultId}/items/${itemId}`, body);
95
+ }
96
+ deleteItem(vaultId, itemId) {
97
+ return this.req('DELETE', `/vaults/${vaultId}/items/${itemId}`);
98
+ }
99
+ upsertItems(vaultId, items, idempotencyKey) {
100
+ return this.req('POST', `/vaults/${vaultId}/items/upsert`, {
101
+ items,
102
+ ...(idempotencyKey ? { idempotency_key: idempotencyKey } : {}),
103
+ });
104
+ }
105
+ previewImport(vaultId, items) {
106
+ return this.req('POST', `/vaults/${vaultId}/items/import-preview`, { items });
107
+ }
108
+ searchItems(vaultId, params) {
109
+ const q = new URLSearchParams();
110
+ if (params.q)
111
+ q.set('q', params.q);
112
+ if (params.author)
113
+ q.set('author', params.author);
114
+ if (params.year !== undefined)
115
+ q.set('year', String(params.year));
116
+ if (params.doi)
117
+ q.set('doi', params.doi);
118
+ if (params.tag_id)
119
+ q.set('tag_id', params.tag_id);
120
+ if (params.page !== undefined)
121
+ q.set('page', String(params.page));
122
+ if (params.limit !== undefined)
123
+ q.set('limit', String(params.limit));
124
+ const qs = q.toString() ? `?${q}` : '';
125
+ return this.req('GET', `/vaults/${vaultId}/search${qs}`);
126
+ }
127
+ getStats(vaultId) {
128
+ return this.req('GET', `/vaults/${vaultId}/stats`);
129
+ }
130
+ getChanges(vaultId, since) {
131
+ return this.req('GET', `/vaults/${vaultId}/changes?since=${encodeURIComponent(since)}`);
132
+ }
133
+ // ── Tags ─────────────────────────────────────────────────────────────────────
134
+ listTags(vaultId) {
135
+ return this.req('GET', `/vaults/${vaultId}/tags`);
136
+ }
137
+ createTag(vaultId, body) {
138
+ return this.req('POST', `/vaults/${vaultId}/tags`, body);
139
+ }
140
+ updateTag(vaultId, tagId, body) {
141
+ return this.req('PATCH', `/vaults/${vaultId}/tags/${tagId}`, body);
142
+ }
143
+ deleteTag(vaultId, tagId) {
144
+ return this.req('DELETE', `/vaults/${vaultId}/tags/${tagId}`);
145
+ }
146
+ attachTags(vaultId, itemId, tagIds) {
147
+ return this.req('POST', `/vaults/${vaultId}/tags/attach`, { item_id: itemId, tag_ids: tagIds });
148
+ }
149
+ detachTags(vaultId, itemId, tagIds) {
150
+ return this.req('POST', `/vaults/${vaultId}/tags/detach`, { item_id: itemId, tag_ids: tagIds });
151
+ }
152
+ // ── Relations ────────────────────────────────────────────────────────────────
153
+ listRelations(vaultId, type) {
154
+ const qs = type ? `?type=${encodeURIComponent(type)}` : '';
155
+ return this.req('GET', `/vaults/${vaultId}/relations${qs}`);
156
+ }
157
+ createRelation(vaultId, body) {
158
+ return this.req('POST', `/vaults/${vaultId}/relations`, body);
159
+ }
160
+ updateRelation(vaultId, relationId, body) {
161
+ return this.req('PATCH', `/vaults/${vaultId}/relations/${relationId}`, body);
162
+ }
163
+ deleteRelation(vaultId, relationId) {
164
+ return this.req('DELETE', `/vaults/${vaultId}/relations/${relationId}`);
165
+ }
166
+ // ── Import ───────────────────────────────────────────────────────────────────
167
+ importDoi(vaultId, doi, tagIds = []) {
168
+ return this.req('POST', `/vaults/${vaultId}/import/doi`, { doi, tag_ids: tagIds });
169
+ }
170
+ importBibtex(vaultId, bibtex, tagIds = []) {
171
+ return this.req('POST', `/vaults/${vaultId}/import/bibtex`, { bibtex, tag_ids: tagIds });
172
+ }
173
+ importUrl(vaultId, url, tagIds = []) {
174
+ return this.req('POST', `/vaults/${vaultId}/import/url`, { url, tag_ids: tagIds });
175
+ }
176
+ // ── Export ───────────────────────────────────────────────────────────────────
177
+ exportVault(vaultId, format = 'json') {
178
+ return this.reqText('GET', `/vaults/${vaultId}/export?format=${format}`);
179
+ }
180
+ // ── Audit ────────────────────────────────────────────────────────────────────
181
+ getAudit(vaultId, params = {}) {
182
+ const q = new URLSearchParams();
183
+ if (params.since)
184
+ q.set('since', params.since);
185
+ if (params.until)
186
+ q.set('until', params.until);
187
+ if (params.limit !== undefined)
188
+ q.set('limit', String(params.limit));
189
+ if (params.page !== undefined)
190
+ q.set('page', String(params.page));
191
+ const qs = q.toString() ? `?${q}` : '';
192
+ return this.req('GET', `/vaults/${vaultId}/audit${qs}`);
193
+ }
194
+ }
195
+ // ── Helpers ───────────────────────────────────────────────────────────────────
196
+ export function resolveClient(apiKey) {
197
+ const key = apiKey ?? process.env['REFHUB_API_KEY'];
198
+ if (!key) {
199
+ process.stderr.write(JSON.stringify({ error: { code: 'missing_api_key', message: 'No API key found. Set REFHUB_API_KEY or pass --api-key.' } }) + '\n');
200
+ process.exit(3);
201
+ }
202
+ return new RefHubClient(key);
203
+ }
204
+ export async function run(fn) {
205
+ try {
206
+ await fn();
207
+ }
208
+ catch (err) {
209
+ if (err instanceof RefHubError) {
210
+ process.stderr.write(JSON.stringify({
211
+ error: {
212
+ code: err.code,
213
+ message: err.message,
214
+ request_id: err.request_id,
215
+ ...(err.retry_after_seconds !== undefined ? { retry_after_seconds: err.retry_after_seconds } : {}),
216
+ },
217
+ }) + '\n');
218
+ process.exit(err.status === 401 ? 3 : 1);
219
+ }
220
+ process.stderr.write(JSON.stringify({ error: { code: 'unexpected_error', message: String(err) } }) + '\n');
221
+ process.exit(1);
222
+ }
223
+ }
@@ -0,0 +1,9 @@
1
+ import type { Command } from 'commander';
2
+ import { RefHubClient } from '../client.js';
3
+ export declare function handleAudit(client: RefHubClient, vaultId: string, opts: {
4
+ since?: string;
5
+ until?: string;
6
+ limit?: number;
7
+ page?: number;
8
+ }, tableMode: boolean): Promise<void>;
9
+ export declare function registerAudit(program: Command): void;
@@ -0,0 +1,21 @@
1
+ import { resolveClient, run } from '../client.js';
2
+ import { format } from '../format.js';
3
+ export async function handleAudit(client, vaultId, opts, tableMode) {
4
+ const result = await client.getAudit(vaultId, opts);
5
+ format(result, tableMode, ['id', 'action', 'entity_type', 'entity_id', 'created_at']);
6
+ }
7
+ export function registerAudit(program) {
8
+ program
9
+ .command('audit')
10
+ .description('Read vault audit log')
11
+ .requiredOption('--vault <id>')
12
+ .option('--since <ISO>', 'start timestamp (ISO 8601)')
13
+ .option('--until <ISO>', 'end timestamp (ISO 8601)')
14
+ .option('--limit <n>', 'results per page (max 200)', (v) => parseInt(v, 10))
15
+ .option('--page <n>', 'page number', (v) => parseInt(v, 10))
16
+ .action(async (opts, cmd) => {
17
+ const g = cmd.optsWithGlobals();
18
+ const client = resolveClient(g.apiKey);
19
+ await run(() => handleAudit(client, opts.vault, { since: opts.since, until: opts.until, limit: opts.limit, page: opts.page }, g.table ?? false));
20
+ });
21
+ }
@@ -0,0 +1,4 @@
1
+ import type { Command } from 'commander';
2
+ import { RefHubClient } from '../client.js';
3
+ export declare function handleExport(client: RefHubClient, vaultId: string, outputFormat: 'json' | 'bibtex'): Promise<void>;
4
+ export declare function registerExport(program: Command): void;
@@ -0,0 +1,22 @@
1
+ import { resolveClient, run } from '../client.js';
2
+ export async function handleExport(client, vaultId, outputFormat) {
3
+ const raw = await client.exportVault(vaultId, outputFormat);
4
+ process.stdout.write(raw + '\n');
5
+ }
6
+ export function registerExport(program) {
7
+ program
8
+ .command('export')
9
+ .description('Export a vault as JSON or BibTeX')
10
+ .requiredOption('--vault <id>')
11
+ .option('--format <format>', 'json|bibtex', 'json')
12
+ .action(async (opts, cmd) => {
13
+ const g = cmd.optsWithGlobals();
14
+ const client = resolveClient(g.apiKey);
15
+ if (opts.format !== 'json' && opts.format !== 'bibtex') {
16
+ process.stderr.write(JSON.stringify({ error: { code: 'invalid_format', message: `Unknown format '${opts.format}'. Use json or bibtex.` } }) + '\n');
17
+ process.exit(2);
18
+ }
19
+ const fmt = opts.format;
20
+ await run(() => handleExport(client, opts.vault, fmt));
21
+ });
22
+ }
@@ -0,0 +1,6 @@
1
+ import type { Command } from 'commander';
2
+ import { RefHubClient } from '../client.js';
3
+ export declare function handleImportDoi(client: RefHubClient, vaultId: string, doi: string, tagsCsv: string | undefined, tableMode: boolean): Promise<void>;
4
+ export declare function handleImportBibtex(client: RefHubClient, vaultId: string, bibtex: string, tagsCsv: string | undefined, tableMode: boolean): Promise<void>;
5
+ export declare function handleImportUrl(client: RefHubClient, vaultId: string, url: string, tagsCsv: string | undefined, tableMode: boolean): Promise<void>;
6
+ export declare function registerImport(program: Command): void;