stow-cli 2.0.3 → 2.1.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,363 @@
1
+ # stow-cli
2
+
3
+ CLI for [Stow](https://stow.sh) file storage. Upload, search, and manage files from the terminal.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install -g stow-cli
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```bash
14
+ # Set your API key
15
+ export STOW_API_KEY="stow_..."
16
+
17
+ # Check connection
18
+ stow whoami
19
+
20
+ # Upload a file
21
+ stow upload ./photo.jpg --bucket photos
22
+
23
+ # Quick share (returns a short URL)
24
+ stow drop ./screenshot.png
25
+
26
+ # Search
27
+ stow search text 'sunset beach' -b photos
28
+ ```
29
+
30
+ ## Authentication
31
+
32
+ Stow CLI uses environment variables for authentication:
33
+
34
+ | Variable | Required | Description |
35
+ |---|---|---|
36
+ | `STOW_API_KEY` | Yes | Your Stow API key (get one at `app.stow.sh/dashboard/api-keys`) |
37
+ | `STOW_API_URL` | No | Override the default API URL (`https://api.stow.sh`) |
38
+ | `STOW_ADMIN_SECRET` | No | Required for `admin` commands only |
39
+
40
+ ## Commands
41
+
42
+ ### Upload and Share
43
+
44
+ **`stow upload <file>`** -- Upload a file to a bucket.
45
+
46
+ ```bash
47
+ stow upload ./logo.png --bucket brand-assets
48
+ stow upload ./clip.mov --quiet
49
+ ```
50
+
51
+ Options: `-b, --bucket <name>`, `-q, --quiet`
52
+
53
+ **`stow drop <file>`** -- Upload a file and get a short URL (quick share).
54
+
55
+ ```bash
56
+ stow drop ./video.mp4
57
+ stow drop ./notes.txt --quiet
58
+ ```
59
+
60
+ Options: `-q, --quiet`
61
+
62
+ ### Buckets
63
+
64
+ **`stow buckets`** -- List your buckets.
65
+
66
+ **`stow buckets create <name>`** -- Create a new bucket.
67
+
68
+ ```bash
69
+ stow buckets create photos
70
+ stow buckets create docs --description "Product docs"
71
+ stow buckets create public-media --public
72
+ ```
73
+
74
+ Options: `-d, --description <text>`, `--public`
75
+
76
+ **`stow buckets rename <name> <new-name>`** -- Rename a bucket. Note: renaming can break existing public URLs.
77
+
78
+ ```bash
79
+ stow buckets rename old-name new-name --yes
80
+ ```
81
+
82
+ Options: `-y, --yes` (skip confirmation)
83
+
84
+ **`stow buckets delete <id>`** -- Delete a bucket by ID.
85
+
86
+ ```bash
87
+ stow buckets delete 8f3d1ab4-...
88
+ ```
89
+
90
+ ### Files
91
+
92
+ **`stow files <bucket>`** -- List files in a bucket.
93
+
94
+ ```bash
95
+ stow files photos
96
+ stow files photos --search avatars/ --limit 100
97
+ stow files photos --json
98
+ ```
99
+
100
+ Options: `-s, --search <prefix>`, `-l, --limit <count>`, `--json`
101
+
102
+ **`stow files get <bucket> <key>`** -- Get details for a single file.
103
+
104
+ ```bash
105
+ stow files get photos hero.png
106
+ stow files get photos hero.png --json
107
+ ```
108
+
109
+ Options: `--json`
110
+
111
+ **`stow files update <bucket> <key>`** -- Update file metadata.
112
+
113
+ ```bash
114
+ stow files update photos hero.png -m alt='Hero image'
115
+ stow files update photos hero.png -m category=banner -m priority=high
116
+ ```
117
+
118
+ Options: `-m, --metadata <kv...>`, `--json`
119
+
120
+ **`stow files enrich <bucket> <key>`** -- Generate title, description, and alt text for an image. Requires a searchable bucket with image files.
121
+
122
+ ```bash
123
+ stow files enrich photos hero.jpg
124
+ ```
125
+
126
+ **`stow files missing <bucket> <type>`** -- List files missing processing data. Valid types: `dimensions`, `embeddings`, `colors`.
127
+
128
+ ```bash
129
+ stow files missing brera dimensions
130
+ stow files missing brera embeddings --limit 200
131
+ stow files missing brera colors --json
132
+ ```
133
+
134
+ Options: `-l, --limit <count>`, `--json`
135
+
136
+ ### Search
137
+
138
+ **`stow search text <query>`** -- Semantic text search.
139
+
140
+ ```bash
141
+ stow search text 'sunset beach' -b photos --limit 10 --json
142
+ ```
143
+
144
+ **`stow search similar --file <key>`** -- Find files similar to a given file.
145
+
146
+ ```bash
147
+ stow search similar --file hero.png -b photos
148
+ ```
149
+
150
+ **`stow search color --hex <color>`** -- Search by color.
151
+
152
+ ```bash
153
+ stow search color --hex "#ff0000" -b photos --limit 20
154
+ ```
155
+
156
+ **`stow search diverse`** -- Diversity-aware search.
157
+
158
+ ```bash
159
+ stow search diverse -b photos --limit 20
160
+ ```
161
+
162
+ All search commands accept: `-b, --bucket <name>`, `-l, --limit <count>`, `--json`
163
+
164
+ ### Tags
165
+
166
+ **`stow tags`** -- List tags.
167
+
168
+ **`stow tags create <name>`** -- Create a new tag.
169
+
170
+ ```bash
171
+ stow tags create "Hero Images"
172
+ stow tags create "Featured" --color "#ff6600"
173
+ ```
174
+
175
+ Options: `--color <hex>`, `--json`
176
+
177
+ **`stow tags delete <id>`** -- Delete a tag by ID.
178
+
179
+ ### Drops
180
+
181
+ **`stow drops`** -- List your drops with usage info.
182
+
183
+ **`stow drops delete <id>`** -- Delete a drop by ID.
184
+
185
+ ```bash
186
+ stow drops delete drop_abc123
187
+ ```
188
+
189
+ ### Profiles
190
+
191
+ **`stow profiles create`** -- Create a taste profile.
192
+
193
+ ```bash
194
+ stow profiles create --name "My Profile" -b photos
195
+ ```
196
+
197
+ Options: `--name <name>` (required), `-b, --bucket <id>`, `--json`
198
+
199
+ **`stow profiles get <id>`** -- Get a taste profile with clusters.
200
+
201
+ ```bash
202
+ stow profiles get profile_abc123 --json
203
+ ```
204
+
205
+ Options: `--json`
206
+
207
+ **`stow profiles delete <id>`** -- Delete a taste profile.
208
+
209
+ ### Jobs
210
+
211
+ **`stow jobs`** -- List processing jobs for a bucket.
212
+
213
+ ```bash
214
+ stow jobs --bucket <id>
215
+ stow jobs --bucket <id> --status failed
216
+ stow jobs --bucket <id> --queue extract-colors --json
217
+ ```
218
+
219
+ Options: `-b, --bucket <id>` (required), `-s, --status <status>`, `-q, --queue <name>`, `-l, --limit <count>`, `--json`
220
+
221
+ **`stow jobs retry <id>`** -- Retry a failed job.
222
+
223
+ ```bash
224
+ stow jobs retry job123 --queue generate-title --bucket <id>
225
+ ```
226
+
227
+ Options: `-q, --queue <name>` (required), `-b, --bucket <id>` (required)
228
+
229
+ **`stow jobs delete <id>`** -- Remove a job.
230
+
231
+ ```bash
232
+ stow jobs delete job123 --queue extract-colors --bucket <id>
233
+ ```
234
+
235
+ Options: `-q, --queue <name>` (required), `-b, --bucket <id>` (required)
236
+
237
+ ### Admin
238
+
239
+ All admin commands require the `STOW_ADMIN_SECRET` environment variable.
240
+
241
+ **`stow admin health`** -- Check system health and queue depths.
242
+
243
+ ```bash
244
+ stow admin health
245
+ stow admin health --json
246
+ ```
247
+
248
+ **`stow admin backfill <type>`** -- Backfill processing data. Valid types: `dimensions`, `colors`, `embeddings`.
249
+
250
+ ```bash
251
+ stow admin backfill dimensions --bucket <id> --dry-run
252
+ stow admin backfill colors --bucket <id> --limit 200
253
+ stow admin backfill embeddings --bucket <id> --limit 100 --json
254
+ ```
255
+
256
+ Options: `--bucket <id>`, `-l, --limit <count>`, `--dry-run`, `--json`
257
+
258
+ **`stow admin cleanup-drops`** -- Remove expired drops.
259
+
260
+ ```bash
261
+ stow admin cleanup-drops --max-age-hours 24 --dry-run
262
+ ```
263
+
264
+ Options: `--max-age-hours <hours>`, `--dry-run`, `--json`
265
+
266
+ **`stow admin purge-events`** -- Purge old webhook events.
267
+
268
+ ```bash
269
+ stow admin purge-events --dry-run
270
+ ```
271
+
272
+ Options: `--dry-run`, `--json`
273
+
274
+ **`stow admin reconcile-files`** -- Reconcile files between R2 and database.
275
+
276
+ ```bash
277
+ stow admin reconcile-files --bucket <id> --dry-run
278
+ ```
279
+
280
+ Options: `--bucket <id>` (required), `--dry-run`, `--json`
281
+
282
+ **`stow admin retry-sync-failures`** -- Retry failed S3 sync operations.
283
+
284
+ ```bash
285
+ stow admin retry-sync-failures
286
+ ```
287
+
288
+ Options: `--json`
289
+
290
+ **`stow admin jobs`** -- List and manage processing jobs (cross-org).
291
+
292
+ ```bash
293
+ stow admin jobs
294
+ stow admin jobs --status failed
295
+ stow admin jobs --org <id> --queue generate-title
296
+ ```
297
+
298
+ Options: `--org <id>`, `--bucket <id>`, `-s, --status`, `-q, --queue`, `-l, --limit`, `--json`
299
+
300
+ **`stow admin jobs retry <id>`** / **`stow admin jobs delete <id>`** -- Retry or remove a job.
301
+
302
+ ```bash
303
+ stow admin jobs retry job123 --queue generate-title
304
+ stow admin jobs delete job123 --queue extract-colors
305
+ ```
306
+
307
+ **`stow admin queues`** -- Show queue depths and counts.
308
+
309
+ ```bash
310
+ stow admin queues
311
+ stow admin queues --json
312
+ ```
313
+
314
+ **`stow admin queues clean <name>`** -- Clean jobs from a queue.
315
+
316
+ ```bash
317
+ stow admin queues clean generate-title --failed
318
+ stow admin queues clean extract-colors --completed --grace 3600
319
+ ```
320
+
321
+ Options: `--failed`, `--completed`, `--grace <seconds>`
322
+
323
+ ### Utility
324
+
325
+ **`stow whoami`** -- Show account info, usage stats, and API key details.
326
+
327
+ **`stow open <bucket>`** -- Open a bucket in the browser.
328
+
329
+ **`stow delete <bucket> <key>`** -- Delete a file from a bucket.
330
+
331
+ ```bash
332
+ stow delete photos hero/banner.png
333
+ ```
334
+
335
+ ## Interactive Mode
336
+
337
+ Run `stow` with no arguments or `stow -i` to launch the interactive TUI. Browse buckets, files, and perform actions with a keyboard-driven interface.
338
+
339
+ ```bash
340
+ stow
341
+ stow --interactive
342
+ ```
343
+
344
+ ## JSON Output
345
+
346
+ Most commands support `--json` for machine-readable output. Useful for scripting and piping into tools like `jq`:
347
+
348
+ ```bash
349
+ stow files photos --json | jq '.[].key'
350
+ stow search text 'landscape' -b photos --json | jq length
351
+ ```
352
+
353
+ ## Environment Variables
354
+
355
+ | Variable | Default | Description |
356
+ |---|---|---|
357
+ | `STOW_API_KEY` | -- | API key for authentication |
358
+ | `STOW_API_URL` | `https://api.stow.sh` | API base URL |
359
+ | `STOW_ADMIN_SECRET` | -- | Secret for admin commands |
360
+
361
+ ## License
362
+
363
+ MIT
@@ -0,0 +1,115 @@
1
+ import {
2
+ validateBucketName
3
+ } from "./chunk-OHAFRKN5.js";
4
+ import {
5
+ formatBytes,
6
+ formatTable
7
+ } from "./chunk-ELSDWMEB.js";
8
+ import {
9
+ createStow
10
+ } from "./chunk-5LU25QZK.js";
11
+ import "./chunk-TOADDO2F.js";
12
+
13
+ // src/commands/buckets.ts
14
+ async function listBuckets() {
15
+ const stow = createStow();
16
+ const data = await stow.listBuckets();
17
+ if (data.buckets.length === 0) {
18
+ console.log("No buckets yet. Create one with: stow buckets create <name>");
19
+ return;
20
+ }
21
+ const rows = data.buckets.map((b) => [
22
+ b.name,
23
+ b.isPublic ? "public" : "private",
24
+ b.searchable ? "yes" : "no",
25
+ `${b.fileCount ?? 0} files`,
26
+ formatBytes(b.usageBytes ?? 0),
27
+ b.description || ""
28
+ ]);
29
+ console.log(
30
+ formatTable(
31
+ ["Name", "Access", "Search", "Files", "Size", "Description"],
32
+ rows
33
+ )
34
+ );
35
+ }
36
+ async function createBucket(name, options) {
37
+ validateBucketName(name);
38
+ if (options.dryRun) {
39
+ console.log(
40
+ JSON.stringify(
41
+ {
42
+ dryRun: true,
43
+ action: "createBucket",
44
+ details: {
45
+ name,
46
+ description: options.description ?? null,
47
+ isPublic: options.public ?? false
48
+ }
49
+ },
50
+ null,
51
+ 2
52
+ )
53
+ );
54
+ return;
55
+ }
56
+ const stow = createStow();
57
+ const bucket = await stow.createBucket({
58
+ name,
59
+ ...options.description ? { description: options.description } : {},
60
+ ...options.public ? { isPublic: true } : {}
61
+ });
62
+ console.log(`Created bucket: ${bucket.name}`);
63
+ }
64
+ async function renameBucket(name, newName, options) {
65
+ validateBucketName(name);
66
+ validateBucketName(newName);
67
+ if (options.dryRun) {
68
+ console.log(
69
+ JSON.stringify(
70
+ {
71
+ dryRun: true,
72
+ action: "renameBucket",
73
+ details: { name, newName }
74
+ },
75
+ null,
76
+ 2
77
+ )
78
+ );
79
+ return;
80
+ }
81
+ if (!options.yes) {
82
+ console.error(
83
+ "Warning: Renaming a bucket will break any existing URLs using the old name."
84
+ );
85
+ console.error("Use --yes to skip this warning.");
86
+ }
87
+ const stow = createStow();
88
+ const bucket = await stow.renameBucket(name, newName);
89
+ console.log(`Renamed bucket: ${name} \u2192 ${bucket.name}`);
90
+ }
91
+ async function deleteBucket(id, options = {}) {
92
+ if (options.dryRun) {
93
+ console.log(
94
+ JSON.stringify(
95
+ {
96
+ dryRun: true,
97
+ action: "deleteBucket",
98
+ details: { id }
99
+ },
100
+ null,
101
+ 2
102
+ )
103
+ );
104
+ return;
105
+ }
106
+ const stow = createStow();
107
+ await stow.deleteBucket(id);
108
+ console.log(`Deleted bucket: ${id}`);
109
+ }
110
+ export {
111
+ createBucket,
112
+ deleteBucket,
113
+ listBuckets,
114
+ renameBucket
115
+ };
@@ -0,0 +1,40 @@
1
+ // src/lib/validate-input.ts
2
+ var InputValidationError = class extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = "InputValidationError";
6
+ }
7
+ };
8
+ function validateInput(value, context) {
9
+ if (value.includes("../") || value.includes("..\\")) {
10
+ throw new InputValidationError(`${context}: path traversal not allowed`);
11
+ }
12
+ if (context !== "url" && value.includes("?")) {
13
+ throw new InputValidationError(
14
+ `${context}: embedded query parameters not allowed`
15
+ );
16
+ }
17
+ if (/[\x00-\x08\x0b\x0c\x0e-\x1f]/.test(value)) {
18
+ throw new InputValidationError(
19
+ `${context}: control characters not allowed`
20
+ );
21
+ }
22
+ if (/%25/.test(value)) {
23
+ throw new InputValidationError(
24
+ `${context}: double-encoded values not allowed`
25
+ );
26
+ }
27
+ return value;
28
+ }
29
+ function validateBucketName(name) {
30
+ return validateInput(name, "bucket name");
31
+ }
32
+ function validateFileKey(key) {
33
+ return validateInput(key, "file key");
34
+ }
35
+
36
+ export {
37
+ validateInput,
38
+ validateBucketName,
39
+ validateFileKey
40
+ };