@nuelink/nuelink-cli 1.4.2 → 1.4.4
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 +47 -41
- package/package.json +2 -2
- package/src/commands.js +52 -1
- package/src/http.js +126 -126
- package/src/validation.js +94 -50
- package/test/cli.test.mjs +84 -1
package/README.md
CHANGED
|
@@ -78,7 +78,7 @@ The token is stored in:
|
|
|
78
78
|
- Windows: `%USERPROFILE%/.nuelink-cli/config.json`
|
|
79
79
|
- macOS/Linux: `$HOME/.nuelink-cli/config.json`
|
|
80
80
|
|
|
81
|
-
The file stores:
|
|
81
|
+
The file stores:
|
|
82
82
|
|
|
83
83
|
```json
|
|
84
84
|
{
|
|
@@ -86,20 +86,20 @@ The file stores:
|
|
|
86
86
|
"encryptedApiKey": "...",
|
|
87
87
|
"iv": "...",
|
|
88
88
|
"authTag": "..."
|
|
89
|
-
}
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
Saved keys are written through a mode-`0700` config directory and an atomic
|
|
93
|
-
mode-`0600` file replacement where the operating system supports POSIX
|
|
94
|
-
permissions. The CLI refuses symbolic-link config paths. The bundled
|
|
95
|
-
encryption prevents casual disclosure but is not a substitute for filesystem
|
|
96
|
-
permissions; prefer `NUELINK_API_KEY` when a secret manager is available.
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Saved keys are written through a mode-`0700` config directory and an atomic
|
|
93
|
+
mode-`0600` file replacement where the operating system supports POSIX
|
|
94
|
+
permissions. The CLI refuses symbolic-link config paths. The bundled
|
|
95
|
+
encryption prevents casual disclosure but is not a substitute for filesystem
|
|
96
|
+
permissions; prefer `NUELINK_API_KEY` when a secret manager is available.
|
|
97
97
|
|
|
98
98
|
## Global Options
|
|
99
99
|
|
|
100
100
|
- `-a, --api-key <apiKey>`: Use API key for the current invocation only
|
|
101
101
|
- `--auth <apiKey>`: Deprecated alias for `--api-key`
|
|
102
|
-
- `--json`: Output machine-readable JSON for successes and failures
|
|
102
|
+
- `--json`: Output machine-readable JSON for successes and failures
|
|
103
103
|
- `-h, --help`: Show help
|
|
104
104
|
- `-V, --version`: Show version
|
|
105
105
|
|
|
@@ -116,6 +116,7 @@ nuelink-cli me
|
|
|
116
116
|
```bash
|
|
117
117
|
printf '%s' "$NUELINK_API_KEY" | nuelink-cli auth:login --stdin
|
|
118
118
|
nuelink-cli auth:status
|
|
119
|
+
nuelink-cli auth:validate
|
|
119
120
|
nuelink-cli auth:clear
|
|
120
121
|
```
|
|
121
122
|
|
|
@@ -145,9 +146,9 @@ Raw JSON mode:
|
|
|
145
146
|
nuelink-cli --json brands --per-page 5 --page 1
|
|
146
147
|
```
|
|
147
148
|
|
|
148
|
-
In `--json` mode, stdout contains one JSON value so it can be piped directly
|
|
149
|
-
into tools like `jq`. API successes retain the raw response shape. Failures use
|
|
150
|
-
`{"success":false,"error":{"code":"...","message":"...","httpStatus":null,"details":{}}}`.
|
|
149
|
+
In `--json` mode, stdout contains one JSON value so it can be piped directly
|
|
150
|
+
into tools like `jq`. API successes retain the raw response shape. Failures use
|
|
151
|
+
`{"success":false,"error":{"code":"...","message":"...","httpStatus":null,"details":{}}}`.
|
|
151
152
|
|
|
152
153
|
### Collections
|
|
153
154
|
|
|
@@ -160,14 +161,14 @@ Example output includes collection title, status-related fields, and pagination
|
|
|
160
161
|
Create collection:
|
|
161
162
|
|
|
162
163
|
```bash
|
|
163
|
-
nuelink-cli collections:create \
|
|
164
|
+
nuelink-cli collections:create \
|
|
164
165
|
--brand-id 13493 \
|
|
165
166
|
--title "API Brand" \
|
|
166
167
|
--description "Collection from CLI" \
|
|
167
168
|
--max-republish 5 \
|
|
168
169
|
--channels "300294,60112" \
|
|
169
|
-
--queues "Mon 10:10,Mon 12:12" \
|
|
170
|
-
--dry-run
|
|
170
|
+
--queues "Mon 10:10,Mon 12:12" \
|
|
171
|
+
--dry-run
|
|
171
172
|
```
|
|
172
173
|
|
|
173
174
|
### Automations
|
|
@@ -181,7 +182,7 @@ This table view is especially useful for quickly scanning automation status, sub
|
|
|
181
182
|
Create automation:
|
|
182
183
|
|
|
183
184
|
```bash
|
|
184
|
-
nuelink-cli automations:create \
|
|
185
|
+
nuelink-cli automations:create \
|
|
185
186
|
--brand-id 13493 \
|
|
186
187
|
--collection-id 720 \
|
|
187
188
|
--feed-url "https://www.nasa.gov/rss/dyn/breaking_news.rss" \
|
|
@@ -190,8 +191,8 @@ nuelink-cli automations:create \
|
|
|
190
191
|
--title "NASA Breaking News" \
|
|
191
192
|
--type FEED \
|
|
192
193
|
--dynamic-title "{{title}}" \
|
|
193
|
-
--dynamic-body "{
|
|
194
|
-
--dry-run
|
|
194
|
+
--dynamic-body "{{description}} {{link}}" \
|
|
195
|
+
--dry-run
|
|
195
196
|
```
|
|
196
197
|
|
|
197
198
|
### Channels
|
|
@@ -215,7 +216,7 @@ Media list output highlights file name, type, size, and timestamps.
|
|
|
215
216
|
Upload media:
|
|
216
217
|
|
|
217
218
|
```bash
|
|
218
|
-
nuelink-cli media:upload --brand-id 13493 --file ./assets/image.jpg --dry-run
|
|
219
|
+
nuelink-cli media:upload --brand-id 13493 --file ./assets/image.jpg --dry-run
|
|
219
220
|
```
|
|
220
221
|
|
|
221
222
|
### Posts
|
|
@@ -227,11 +228,14 @@ nuelink-cli posts --brand-id 13493 --collection-id 33273 --per-page 5 --page 1
|
|
|
227
228
|
```
|
|
228
229
|
|
|
229
230
|
Post list output highlights the post ID, type, status, and publish date.
|
|
231
|
+
Optional filters include `--status`, `--post-type`, `--posting-type`,
|
|
232
|
+
`--created-from`, `--created-to`, `--sort-by`, and `--sort-order`.
|
|
233
|
+
Creation date filters use `YYYY-MM-DD HH:mm:ss` UTC timestamps.
|
|
230
234
|
|
|
231
235
|
Create post from JSON payload file:
|
|
232
236
|
|
|
233
237
|
```bash
|
|
234
|
-
nuelink-cli posts:add-json --brand-id 13493 --collection-id 33273 --payload ./post.json --dry-run
|
|
238
|
+
nuelink-cli posts:add-json --brand-id 13493 --collection-id 33273 --payload ./post.json --dry-run
|
|
235
239
|
```
|
|
236
240
|
|
|
237
241
|
You can also pipe JSON through stdin with `--payload -`.
|
|
@@ -278,16 +282,18 @@ nuelink-cli posts:create \
|
|
|
278
282
|
--tiktok-auto-add-music false \
|
|
279
283
|
--youtube-tags "tag1,tag2,tag3" \
|
|
280
284
|
--youtube-playlists '[{"channelId":1,"playlistIds":["1","2"]}]' \
|
|
281
|
-
--googlemybusiness-upload-to-photos-section true \
|
|
282
|
-
--dry-run
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
Review each mutation preview, then repeat the same command without `--dry-run`
|
|
286
|
-
only when you intend to send it.
|
|
285
|
+
--googlemybusiness-upload-to-photos-section true \
|
|
286
|
+
--dry-run
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
Review each mutation preview, then repeat the same command without `--dry-run`
|
|
290
|
+
only when you intend to send it.
|
|
287
291
|
|
|
288
292
|
Supported publish modes are `DRAFT`, `QUEUE`, `SCHEDULE`, and `IMMEDIATE`. When using `SCHEDULE`, pass `--scheduled-at` in `YYYY-MM-DD HH:mm:ss` format. Poll correct-option indexes are zero-based.
|
|
289
293
|
|
|
290
|
-
Pagination uses `--page >= 1` and `--per-page` from 1 through 100. Media type
|
|
294
|
+
Pagination uses `--page >= 1` and `--per-page` from 1 through 100. Media type
|
|
295
|
+
filters are `IMAGE`, `VIDEO`, `GIF`, `APPLICATION`, `DOCUMENT`, and `CSV`.
|
|
296
|
+
Uploads accept JPEG, PNG, BMP, MP4, MOV, or PDF files up to 100 MiB.
|
|
291
297
|
|
|
292
298
|
## Output and Exit Codes
|
|
293
299
|
|
|
@@ -345,20 +351,20 @@ npm test
|
|
|
345
351
|
### Package validation
|
|
346
352
|
|
|
347
353
|
```bash
|
|
348
|
-
npm run check:pack
|
|
349
|
-
npm run check:pack:installed
|
|
354
|
+
npm run check:pack
|
|
355
|
+
npm run check:pack:installed
|
|
350
356
|
```
|
|
351
357
|
|
|
352
358
|
## Release Checklist
|
|
353
359
|
|
|
354
360
|
1. Update version in `package.json`
|
|
355
361
|
2. Run `npm test`
|
|
356
|
-
3. Run `npm run check:pack`
|
|
357
|
-
4. Run `npm run check:pack:installed`
|
|
358
|
-
5. Publish locally with `npm publish --access public`
|
|
359
|
-
|
|
360
|
-
Provenance is available when publishing from a supported cloud CI provider. Do
|
|
361
|
-
not enable it for a local publish.
|
|
362
|
+
3. Run `npm run check:pack`
|
|
363
|
+
4. Run `npm run check:pack:installed`
|
|
364
|
+
5. Publish locally with `npm publish --access public`
|
|
365
|
+
|
|
366
|
+
Provenance is available when publishing from a supported cloud CI provider. Do
|
|
367
|
+
not enable it for a local publish.
|
|
362
368
|
|
|
363
369
|
## Troubleshooting
|
|
364
370
|
|
|
@@ -373,11 +379,11 @@ not enable it for a local publish.
|
|
|
373
379
|
Increase timeout for slower operations:
|
|
374
380
|
|
|
375
381
|
```bash
|
|
376
|
-
NUELINK_TIMEOUT_MS=120000 nuelink-cli media --brand-id 13493
|
|
377
|
-
```
|
|
378
|
-
|
|
379
|
-
`NUELINK_TIMEOUT_MS` must be 1–600000. `NUELINK_GET_RETRIES` must be 0–10;
|
|
380
|
-
retry delay variables must be non-negative integers no greater than 600000.
|
|
382
|
+
NUELINK_TIMEOUT_MS=120000 nuelink-cli media --brand-id 13493
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
`NUELINK_TIMEOUT_MS` must be 1–600000. `NUELINK_GET_RETRIES` must be 0–10;
|
|
386
|
+
retry delay variables must be non-negative integers no greater than 600000.
|
|
381
387
|
|
|
382
388
|
### Command help
|
|
383
389
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuelink/nuelink-cli",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "The official Nuelink CLI for automating social media workflows from your terminal. Schedule posts, upload media, manage brands, and integrate Nuelink into scripts, CI/CD pipelines, and AI agents.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Nuelink",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"automation"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@nuelink/nuelink-cli": "^1.4.
|
|
44
|
+
"@nuelink/nuelink-cli": "^1.4.4",
|
|
45
45
|
"chalk": "^5.6.2",
|
|
46
46
|
"commander": "^13.1.0"
|
|
47
47
|
},
|
package/src/commands.js
CHANGED
|
@@ -12,6 +12,11 @@ import {
|
|
|
12
12
|
VALID_AUTOMATION_TYPES,
|
|
13
13
|
VALID_IMPORT_AS_TYPES,
|
|
14
14
|
VALID_MEDIA_FILTER_TYPES,
|
|
15
|
+
VALID_POST_STATUSES,
|
|
16
|
+
VALID_POST_TYPES,
|
|
17
|
+
VALID_POSTING_TYPES,
|
|
18
|
+
VALID_POST_SORT_FIELDS,
|
|
19
|
+
VALID_SORT_ORDERS,
|
|
15
20
|
normalizeEnum,
|
|
16
21
|
parseBooleanStrict,
|
|
17
22
|
parseIntegerInRange,
|
|
@@ -21,6 +26,7 @@ import {
|
|
|
21
26
|
splitCsv,
|
|
22
27
|
validateHttpUrl,
|
|
23
28
|
validateMediaFile,
|
|
29
|
+
validatePostDateTime,
|
|
24
30
|
validateQueueSlots,
|
|
25
31
|
validateRequiredString,
|
|
26
32
|
} from "./validation.js";
|
|
@@ -295,6 +301,13 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
295
301
|
);
|
|
296
302
|
}));
|
|
297
303
|
|
|
304
|
+
program
|
|
305
|
+
.command("auth:validate")
|
|
306
|
+
.description("Validate the configured API key with the Public API")
|
|
307
|
+
.action(withCommandErrorHandling(program, async () => {
|
|
308
|
+
await executeRequest(program, runtimeApiKey, { endpoint: "/auth" });
|
|
309
|
+
}));
|
|
310
|
+
|
|
298
311
|
program
|
|
299
312
|
.command("me")
|
|
300
313
|
.description("Get current profile")
|
|
@@ -386,7 +399,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
386
399
|
.requiredOption("--title <title>", "Automation title")
|
|
387
400
|
.option("--type <type>", "Automation type", "FEED")
|
|
388
401
|
.option("--dynamic-title <text>", "Dynamic title", "{{title}}")
|
|
389
|
-
.option("--dynamic-body <text>", "Dynamic body"
|
|
402
|
+
.option("--dynamic-body <text>", "Dynamic body")
|
|
390
403
|
.option("--description <text>", "Automation description")
|
|
391
404
|
.option("--load-old-posts <boolean>", "Import existing feed items: true/false")
|
|
392
405
|
.option("--add-posts-as-draft <boolean>", "Create imported posts as drafts: true/false")
|
|
@@ -488,7 +501,32 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
488
501
|
.requiredOption("--collection-id <id>", "Collection ID")
|
|
489
502
|
.option("--per-page <number>", "Items per page", "25")
|
|
490
503
|
.option("--page <number>", "Page number", "1")
|
|
504
|
+
.option("--status <status>", `Post status (${VALID_POST_STATUSES.join(", ")})`)
|
|
505
|
+
.option("--post-type <type>", `Post type (${VALID_POST_TYPES.join(", ")})`)
|
|
506
|
+
.option("--posting-type <type>", `Posting type (${VALID_POSTING_TYPES.join(", ")})`)
|
|
507
|
+
.option("--created-from <datetime>", "Created at or after UTC time (YYYY-MM-DD HH:mm:ss)")
|
|
508
|
+
.option("--created-to <datetime>", "Created at or before UTC time (YYYY-MM-DD HH:mm:ss)")
|
|
509
|
+
.option("--sort-by <field>", `Sort field (${VALID_POST_SORT_FIELDS.join(", ")})`)
|
|
510
|
+
.option("--sort-order <order>", `Sort order (${VALID_SORT_ORDERS.join(", ")})`)
|
|
491
511
|
.action(withCommandErrorHandling(program, async (options) => {
|
|
512
|
+
const createdFrom = validatePostDateTime(options.createdFrom, "created-from");
|
|
513
|
+
const createdTo = validatePostDateTime(options.createdTo, "created-to");
|
|
514
|
+
if (createdFrom && createdTo && createdTo < createdFrom) {
|
|
515
|
+
throw new Error("created-to must not precede created-from.");
|
|
516
|
+
}
|
|
517
|
+
const sortBy = options.sortBy === undefined
|
|
518
|
+
? undefined
|
|
519
|
+
: String(options.sortBy).trim().toLowerCase();
|
|
520
|
+
if (sortBy && !VALID_POST_SORT_FIELDS.includes(sortBy)) {
|
|
521
|
+
throw new Error(`Invalid sort-by "${options.sortBy}". Expected one of: ${VALID_POST_SORT_FIELDS.join(", ")}.`);
|
|
522
|
+
}
|
|
523
|
+
const sortOrder = options.sortOrder === undefined
|
|
524
|
+
? undefined
|
|
525
|
+
: String(options.sortOrder).trim().toLowerCase();
|
|
526
|
+
if (sortOrder && !VALID_SORT_ORDERS.includes(sortOrder)) {
|
|
527
|
+
throw new Error(`Invalid sort-order "${options.sortOrder}". Expected one of: ${VALID_SORT_ORDERS.join(", ")}.`);
|
|
528
|
+
}
|
|
529
|
+
|
|
492
530
|
await executeRequest(program, runtimeApiKey, {
|
|
493
531
|
endpoint: `${collectionPath(
|
|
494
532
|
parsePositiveInteger(options.brandId, "brand-id"),
|
|
@@ -497,6 +535,19 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
497
535
|
query: {
|
|
498
536
|
per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
|
|
499
537
|
page: parsePositiveInteger(options.page, "page"),
|
|
538
|
+
status: options.status
|
|
539
|
+
? normalizeEnum(options.status, "status", VALID_POST_STATUSES)
|
|
540
|
+
: undefined,
|
|
541
|
+
post_type: options.postType
|
|
542
|
+
? normalizeEnum(options.postType, "post-type", VALID_POST_TYPES)
|
|
543
|
+
: undefined,
|
|
544
|
+
posting_type: options.postingType
|
|
545
|
+
? normalizeEnum(options.postingType, "posting-type", VALID_POSTING_TYPES)
|
|
546
|
+
: undefined,
|
|
547
|
+
created_from: createdFrom,
|
|
548
|
+
created_to: createdTo,
|
|
549
|
+
sort_by: sortBy,
|
|
550
|
+
sort_order: sortOrder,
|
|
500
551
|
},
|
|
501
552
|
});
|
|
502
553
|
}));
|
package/src/http.js
CHANGED
|
@@ -2,10 +2,10 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import { CliError } from "./errors.js";
|
|
4
4
|
import { printApiResponse } from "./output.js";
|
|
5
|
-
|
|
6
|
-
const require = createRequire(import.meta.url);
|
|
7
|
-
const { version: cliVersion } = require("../package.json");
|
|
8
|
-
|
|
5
|
+
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
const { version: cliVersion } = require("../package.json");
|
|
8
|
+
|
|
9
9
|
const DEFAULT_API_BASE_URL = "https://app.nuelink.com/api/public/v1";
|
|
10
10
|
|
|
11
11
|
function readIntegerEnvironment(name, fallback, { minimum = 0, maximum = 600000 } = {}) {
|
|
@@ -34,25 +34,25 @@ function getRequestConfiguration() {
|
|
|
34
34
|
retryMaxDelayMs: readIntegerEnvironment("NUELINK_RETRY_MAX_MS", 2000),
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
function pathParam(value, label) {
|
|
39
|
-
const stringValue = String(value ?? "").trim();
|
|
40
|
-
|
|
41
|
-
if (!stringValue) {
|
|
42
|
-
throw new Error(`Missing required ${label}.`);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return encodeURIComponent(stringValue);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function brandPath(brandId) {
|
|
49
|
-
return `/brands/${pathParam(brandId, "brand-id")}`;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function collectionPath(brandId, collectionId) {
|
|
53
|
-
return `${brandPath(brandId)}/collections/${pathParam(collectionId, "collection-id")}`;
|
|
54
|
-
}
|
|
55
|
-
|
|
37
|
+
|
|
38
|
+
function pathParam(value, label) {
|
|
39
|
+
const stringValue = String(value ?? "").trim();
|
|
40
|
+
|
|
41
|
+
if (!stringValue) {
|
|
42
|
+
throw new Error(`Missing required ${label}.`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return encodeURIComponent(stringValue);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function brandPath(brandId) {
|
|
49
|
+
return `/brands/${pathParam(brandId, "brand-id")}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function collectionPath(brandId, collectionId) {
|
|
53
|
+
return `${brandPath(brandId)}/collections/${pathParam(collectionId, "collection-id")}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
56
|
function buildApiUrl(endpoint, apiBaseUrl) {
|
|
57
57
|
try {
|
|
58
58
|
return new URL(endpoint.replace(/^\//, ""), `${apiBaseUrl.replace(/\/?$/, "/")}`);
|
|
@@ -66,91 +66,91 @@ function shouldRetryRequest(method, statusCode, attempt, maxGetRetries) {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
function parseRetryAfterMs(headers, attempt, retryBaseDelayMs, retryMaxDelayMs) {
|
|
69
|
-
const retryAfter = headers.get("retry-after");
|
|
70
|
-
|
|
71
|
-
if (retryAfter) {
|
|
72
|
-
const seconds = Number(retryAfter);
|
|
73
|
-
|
|
74
|
-
if (!Number.isNaN(seconds)) {
|
|
75
|
-
return Math.max(seconds * 1000, 0);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const dateDelay = Date.parse(retryAfter) - Date.now();
|
|
79
|
-
if (!Number.isNaN(dateDelay)) {
|
|
80
|
-
return Math.max(dateDelay, 0);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
69
|
+
const retryAfter = headers.get("retry-after");
|
|
70
|
+
|
|
71
|
+
if (retryAfter) {
|
|
72
|
+
const seconds = Number(retryAfter);
|
|
73
|
+
|
|
74
|
+
if (!Number.isNaN(seconds)) {
|
|
75
|
+
return Math.max(seconds * 1000, 0);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const dateDelay = Date.parse(retryAfter) - Date.now();
|
|
79
|
+
if (!Number.isNaN(dateDelay)) {
|
|
80
|
+
return Math.max(dateDelay, 0);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
84
|
const exponentialDelay = Math.min(retryBaseDelayMs * (2 ** attempt), retryMaxDelayMs);
|
|
85
|
-
return Math.floor(Math.random() * (exponentialDelay + 1));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async function sleep(ms) {
|
|
89
|
-
if (ms <= 0) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function printDryRun({ method, url, query, body, multipart, dryRunBody }) {
|
|
97
|
-
console.log(JSON.stringify({
|
|
98
|
-
dryRun: true,
|
|
99
|
-
method,
|
|
100
|
-
url: url.toString(),
|
|
101
|
-
...(query ? { query } : {}),
|
|
102
|
-
...(body !== undefined ? { body } : {}),
|
|
103
|
-
...(multipart ? { multipart: dryRunBody || true } : {}),
|
|
104
|
-
}, null, 2));
|
|
105
|
-
}
|
|
106
|
-
|
|
85
|
+
return Math.floor(Math.random() * (exponentialDelay + 1));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function sleep(ms) {
|
|
89
|
+
if (ms <= 0) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function printDryRun({ method, url, query, body, multipart, dryRunBody }) {
|
|
97
|
+
console.log(JSON.stringify({
|
|
98
|
+
dryRun: true,
|
|
99
|
+
method,
|
|
100
|
+
url: url.toString(),
|
|
101
|
+
...(query ? { query } : {}),
|
|
102
|
+
...(body !== undefined ? { body } : {}),
|
|
103
|
+
...(multipart ? { multipart: dryRunBody || true } : {}),
|
|
104
|
+
}, null, 2));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
107
|
async function nuelinkRequest({ apiKey, method = "GET", endpoint, query, body, multipart, outputMode = "json", quiet = false, dryRun = false, dryRunBody }) {
|
|
108
108
|
const configuration = getRequestConfiguration();
|
|
109
109
|
const url = buildApiUrl(endpoint, configuration.apiBaseUrl);
|
|
110
|
-
|
|
111
|
-
if (query) {
|
|
112
|
-
Object.entries(query).forEach(([key, value]) => {
|
|
113
|
-
if (value !== undefined && value !== null && value !== "") {
|
|
114
|
-
url.searchParams.set(key, String(value));
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (dryRun) {
|
|
120
|
-
printDryRun({ method, url, query, body, multipart, dryRunBody });
|
|
121
|
-
return { dryRun: true };
|
|
122
|
-
}
|
|
123
|
-
|
|
110
|
+
|
|
111
|
+
if (query) {
|
|
112
|
+
Object.entries(query).forEach(([key, value]) => {
|
|
113
|
+
if (value !== undefined && value !== null && value !== "") {
|
|
114
|
+
url.searchParams.set(key, String(value));
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (dryRun) {
|
|
120
|
+
printDryRun({ method, url, query, body, multipart, dryRunBody });
|
|
121
|
+
return { dryRun: true };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
124
|
if (!apiKey) {
|
|
125
125
|
throw new CliError(
|
|
126
126
|
"AUTH_MISSING",
|
|
127
127
|
"Missing API key. Use --api-key <api_key> for a single command or auth:login to save one.",
|
|
128
128
|
);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const headers = {
|
|
132
|
-
Authorization: `Bearer ${apiKey}`,
|
|
133
|
-
Accept: "application/json",
|
|
134
|
-
"User-Agent": `nuelink-cli/${cliVersion}`,
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
const init = {
|
|
138
|
-
method,
|
|
139
|
-
headers,
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
if (multipart) {
|
|
143
|
-
init.body = multipart;
|
|
144
|
-
} else if (body !== undefined) {
|
|
145
|
-
headers["Content-Type"] = "application/json";
|
|
146
|
-
init.body = JSON.stringify(body);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
try {
|
|
150
|
-
let response;
|
|
151
|
-
|
|
152
|
-
for (let attempt = 0; ; attempt += 1) {
|
|
153
|
-
response = await fetch(url, {
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const headers = {
|
|
132
|
+
Authorization: `Bearer ${apiKey}`,
|
|
133
|
+
Accept: "application/json",
|
|
134
|
+
"User-Agent": `nuelink-cli/${cliVersion}`,
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const init = {
|
|
138
|
+
method,
|
|
139
|
+
headers,
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
if (multipart) {
|
|
143
|
+
init.body = multipart;
|
|
144
|
+
} else if (body !== undefined) {
|
|
145
|
+
headers["Content-Type"] = "application/json";
|
|
146
|
+
init.body = JSON.stringify(body);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
let response;
|
|
151
|
+
|
|
152
|
+
for (let attempt = 0; ; attempt += 1) {
|
|
153
|
+
response = await fetch(url, {
|
|
154
154
|
...init,
|
|
155
155
|
signal: AbortSignal.timeout(configuration.requestTimeoutMs),
|
|
156
156
|
});
|
|
@@ -165,13 +165,13 @@ async function nuelinkRequest({ apiKey, method = "GET", endpoint, query, body, m
|
|
|
165
165
|
configuration.retryBaseDelayMs,
|
|
166
166
|
configuration.retryMaxDelayMs,
|
|
167
167
|
));
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const text = await response.text();
|
|
171
|
-
let data = {};
|
|
172
|
-
|
|
173
|
-
if (text) {
|
|
174
|
-
try {
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const text = await response.text();
|
|
171
|
+
let data = {};
|
|
172
|
+
|
|
173
|
+
if (text) {
|
|
174
|
+
try {
|
|
175
175
|
data = JSON.parse(text);
|
|
176
176
|
} catch {
|
|
177
177
|
if (response.ok) {
|
|
@@ -180,25 +180,25 @@ async function nuelinkRequest({ apiKey, method = "GET", endpoint, query, body, m
|
|
|
180
180
|
`Protocol error: expected a JSON response (HTTP ${response.status}).`,
|
|
181
181
|
{ httpStatus: response.status },
|
|
182
182
|
);
|
|
183
|
-
}
|
|
184
|
-
data = { raw: text };
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
183
|
+
}
|
|
184
|
+
data = { raw: text };
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
188
|
if (!response.ok) {
|
|
189
189
|
throw new CliError(
|
|
190
190
|
"HTTP_ERROR",
|
|
191
191
|
`Request failed (${response.status} ${response.statusText})`,
|
|
192
192
|
{ httpStatus: response.status, details: data },
|
|
193
193
|
);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (outputMode !== "json" && !quiet) {
|
|
197
|
-
console.log(chalk.green(`OK ${method} ${url.pathname}`));
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
printApiResponse(data, { outputMode });
|
|
201
|
-
return data;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (outputMode !== "json" && !quiet) {
|
|
197
|
+
console.log(chalk.green(`OK ${method} ${url.pathname}`));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
printApiResponse(data, { outputMode });
|
|
201
|
+
return data;
|
|
202
202
|
} catch (error) {
|
|
203
203
|
if (error instanceof CliError) throw error;
|
|
204
204
|
|
|
@@ -212,10 +212,10 @@ async function nuelinkRequest({ apiKey, method = "GET", endpoint, query, body, m
|
|
|
212
212
|
throw new CliError("NETWORK_ERROR", `Request error: ${error.message}`);
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
|
-
|
|
216
|
-
export {
|
|
217
|
-
brandPath,
|
|
218
|
-
collectionPath,
|
|
219
|
-
nuelinkRequest,
|
|
220
|
-
pathParam,
|
|
221
|
-
};
|
|
215
|
+
|
|
216
|
+
export {
|
|
217
|
+
brandPath,
|
|
218
|
+
collectionPath,
|
|
219
|
+
nuelinkRequest,
|
|
220
|
+
pathParam,
|
|
221
|
+
};
|
package/src/validation.js
CHANGED
|
@@ -32,20 +32,29 @@ const VALID_AUTOMATION_SUB_TYPES = [
|
|
|
32
32
|
];
|
|
33
33
|
const VALID_IMPORT_AS_TYPES = ["LINK", "IMAGE", "VIDEO", "CAROUSEL"];
|
|
34
34
|
const VALID_MEDIA_FILTER_TYPES = ["IMAGE", "VIDEO", "GIF", "APPLICATION", "DOCUMENT", "CSV"];
|
|
35
|
+
const VALID_POST_STATUSES = ["PENDING", "DRAFT", "PUBLISHED"];
|
|
36
|
+
const VALID_POST_TYPES = [
|
|
37
|
+
"TEXT", "IMAGE", "VIDEO", "MULTIMEDIA", "SHORT", "DOCUMENT", "THREAD",
|
|
38
|
+
"SLIDES", "REEL", "TIKTOK", "STORY", "POLL", "ENGAGE_COMMENT",
|
|
39
|
+
];
|
|
40
|
+
const VALID_POSTING_TYPES = ["NOW", "SCHEDULE", "QUEUE", "DRAFT"];
|
|
41
|
+
const VALID_POST_SORT_FIELDS = ["id", "title", "post_date", "created_at", "updated_at"];
|
|
42
|
+
const VALID_SORT_ORDERS = ["asc", "desc"];
|
|
35
43
|
const SUPPORTED_MEDIA_TYPES = new Map([
|
|
36
44
|
[".jpg", "image/jpeg"],
|
|
37
45
|
[".jpeg", "image/jpeg"],
|
|
38
46
|
[".png", "image/png"],
|
|
39
|
-
[".
|
|
40
|
-
[".webp", "image/webp"],
|
|
47
|
+
[".bmp", "image/bmp"],
|
|
41
48
|
[".mp4", "video/mp4"],
|
|
42
49
|
[".mov", "video/quicktime"],
|
|
50
|
+
[".pdf", "application/pdf"],
|
|
43
51
|
]);
|
|
44
|
-
const DEFAULT_MAX_MEDIA_SIZE_BYTES = 100 * 1024 * 1024;
|
|
52
|
+
const DEFAULT_MAX_MEDIA_SIZE_BYTES = 100 * 1024 * 1024;
|
|
53
|
+
const MAX_MEDIA_SIZE_BYTES = 100 * 1024 * 1024;
|
|
45
54
|
const QUEUE_SLOT_PATTERN = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (?:[01][0-9]|2[0-3]):[0-5][0-9]$/;
|
|
46
55
|
const SQL_DATETIME_PATTERN = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
|
|
47
56
|
|
|
48
|
-
function splitCsv(value) {
|
|
57
|
+
function splitCsv(value) {
|
|
49
58
|
if (!value) {
|
|
50
59
|
return [];
|
|
51
60
|
}
|
|
@@ -54,40 +63,40 @@ function splitCsv(value) {
|
|
|
54
63
|
.split(",")
|
|
55
64
|
.map((item) => item.trim())
|
|
56
65
|
.filter(Boolean);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function validateRequiredString(value, maximum, label) {
|
|
60
|
-
const normalized = String(value ?? "").trim();
|
|
61
|
-
|
|
62
|
-
if (!normalized) {
|
|
63
|
-
throw new Error(`${label} must not be blank.`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (normalized.length > maximum) {
|
|
67
|
-
throw new Error(`${label} must not exceed ${maximum} characters.`);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return normalized;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function readPositiveIntegerEnvironment(name, fallback) {
|
|
74
|
-
const raw = process.env[name];
|
|
75
|
-
if (raw === undefined || raw === "") {
|
|
76
|
-
return fallback;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const normalized = String(raw).trim();
|
|
80
|
-
if (!/^\d+$/.test(normalized)) {
|
|
81
|
-
throw new Error(`${name} must be a positive integer.`);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const parsed = Number(normalized);
|
|
85
|
-
if (!Number.isSafeInteger(parsed) || parsed <= 0) {
|
|
86
|
-
throw new Error(`${name} must be a positive integer.`);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return parsed;
|
|
90
|
-
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function validateRequiredString(value, maximum, label) {
|
|
69
|
+
const normalized = String(value ?? "").trim();
|
|
70
|
+
|
|
71
|
+
if (!normalized) {
|
|
72
|
+
throw new Error(`${label} must not be blank.`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (normalized.length > maximum) {
|
|
76
|
+
throw new Error(`${label} must not exceed ${maximum} characters.`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return normalized;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function readPositiveIntegerEnvironment(name, fallback) {
|
|
83
|
+
const raw = process.env[name];
|
|
84
|
+
if (raw === undefined || raw === "") {
|
|
85
|
+
return fallback;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const normalized = String(raw).trim();
|
|
89
|
+
if (!/^\d+$/.test(normalized)) {
|
|
90
|
+
throw new Error(`${name} must be a positive integer.`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const parsed = Number(normalized);
|
|
94
|
+
if (!Number.isSafeInteger(parsed) || parsed <= 0) {
|
|
95
|
+
throw new Error(`${name} must be a positive integer.`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return parsed;
|
|
99
|
+
}
|
|
91
100
|
|
|
92
101
|
function normalizeEnum(value, label, allowedValues) {
|
|
93
102
|
const normalized = String(value ?? "").trim().toUpperCase();
|
|
@@ -224,6 +233,34 @@ function validateScheduledAt(value) {
|
|
|
224
233
|
return normalized;
|
|
225
234
|
}
|
|
226
235
|
|
|
236
|
+
function validatePostDateTime(value, label) {
|
|
237
|
+
if (value === undefined || value === null || value === "") {
|
|
238
|
+
return undefined;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const normalized = String(value).trim();
|
|
242
|
+
if (!SQL_DATETIME_PATTERN.test(normalized)) {
|
|
243
|
+
throw new Error(`Invalid ${label}. Expected YYYY-MM-DD HH:mm:ss.`);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const [datePart, timePart] = normalized.split(" ");
|
|
247
|
+
const [year, month, day] = datePart.split("-").map(Number);
|
|
248
|
+
const [hours, minutes, seconds] = timePart.split(":").map(Number);
|
|
249
|
+
const date = new Date(Date.UTC(year, month - 1, day, hours, minutes, seconds));
|
|
250
|
+
const isValidDate = date.getUTCFullYear() === year
|
|
251
|
+
&& date.getUTCMonth() === month - 1
|
|
252
|
+
&& date.getUTCDate() === day
|
|
253
|
+
&& date.getUTCHours() === hours
|
|
254
|
+
&& date.getUTCMinutes() === minutes
|
|
255
|
+
&& date.getUTCSeconds() === seconds;
|
|
256
|
+
|
|
257
|
+
if (!isValidDate) {
|
|
258
|
+
throw new Error(`Invalid ${label}. Expected a real calendar date and time.`);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return normalized;
|
|
262
|
+
}
|
|
263
|
+
|
|
227
264
|
function validatePollOptions(options, correctOptionIndex) {
|
|
228
265
|
if (options.length === 1) {
|
|
229
266
|
throw new Error("Polls require at least two options.");
|
|
@@ -242,12 +279,13 @@ function parseJsonString(value, label) {
|
|
|
242
279
|
}
|
|
243
280
|
}
|
|
244
281
|
|
|
245
|
-
function validateMediaFile(filePath, fileStat) {
|
|
246
|
-
const
|
|
247
|
-
"NUELINK_MAX_MEDIA_SIZE_BYTES",
|
|
248
|
-
DEFAULT_MAX_MEDIA_SIZE_BYTES,
|
|
249
|
-
);
|
|
250
|
-
|
|
282
|
+
function validateMediaFile(filePath, fileStat) {
|
|
283
|
+
const configuredMaximum = readPositiveIntegerEnvironment(
|
|
284
|
+
"NUELINK_MAX_MEDIA_SIZE_BYTES",
|
|
285
|
+
DEFAULT_MAX_MEDIA_SIZE_BYTES,
|
|
286
|
+
);
|
|
287
|
+
const maximumSize = Math.min(configuredMaximum, MAX_MEDIA_SIZE_BYTES);
|
|
288
|
+
|
|
251
289
|
if (!fileStat.isFile()) {
|
|
252
290
|
throw new Error("Invalid file. Expected a regular file path.");
|
|
253
291
|
}
|
|
@@ -256,8 +294,8 @@ function validateMediaFile(filePath, fileStat) {
|
|
|
256
294
|
throw new Error("Invalid file. File must not be empty.");
|
|
257
295
|
}
|
|
258
296
|
|
|
259
|
-
if (fileStat.size > maximumSize) {
|
|
260
|
-
throw new Error(`Invalid file. File exceeds ${maximumSize} bytes.`);
|
|
297
|
+
if (fileStat.size > maximumSize) {
|
|
298
|
+
throw new Error(`Invalid file. File exceeds ${maximumSize} bytes.`);
|
|
261
299
|
}
|
|
262
300
|
|
|
263
301
|
const extension = path.extname(filePath).toLowerCase();
|
|
@@ -278,6 +316,11 @@ export {
|
|
|
278
316
|
VALID_AUTOMATION_TYPES,
|
|
279
317
|
VALID_IMPORT_AS_TYPES,
|
|
280
318
|
VALID_MEDIA_FILTER_TYPES,
|
|
319
|
+
VALID_POST_STATUSES,
|
|
320
|
+
VALID_POST_TYPES,
|
|
321
|
+
VALID_POSTING_TYPES,
|
|
322
|
+
VALID_POST_SORT_FIELDS,
|
|
323
|
+
VALID_SORT_ORDERS,
|
|
281
324
|
parseBooleanStrict,
|
|
282
325
|
parseIntegerInRange,
|
|
283
326
|
parseJsonString,
|
|
@@ -287,9 +330,10 @@ export {
|
|
|
287
330
|
splitCsv,
|
|
288
331
|
validateHttpUrl,
|
|
289
332
|
validateMediaFile,
|
|
333
|
+
validatePostDateTime,
|
|
290
334
|
validatePollOptions,
|
|
291
335
|
validateScheduledAt,
|
|
292
|
-
validateQueueSlots,
|
|
293
|
-
validateRequiredString,
|
|
294
|
-
normalizeEnum,
|
|
295
|
-
};
|
|
336
|
+
validateQueueSlots,
|
|
337
|
+
validateRequiredString,
|
|
338
|
+
normalizeEnum,
|
|
339
|
+
};
|
package/test/cli.test.mjs
CHANGED
|
@@ -134,6 +134,89 @@ test("posts command builds pagination query", async () => {
|
|
|
134
134
|
assert.equal(url.searchParams.get("page"), "4");
|
|
135
135
|
});
|
|
136
136
|
|
|
137
|
+
test("auth:validate calls the documented token-validation route", async () => {
|
|
138
|
+
const homeDir = await setupTempHome();
|
|
139
|
+
const capturePath = path.join(homeDir, "capture-auth-validate.json");
|
|
140
|
+
|
|
141
|
+
const result = runCli({
|
|
142
|
+
args: ["auth:validate"],
|
|
143
|
+
homeDir,
|
|
144
|
+
capturePath,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
assert.equal(result.status, 0, result.stderr);
|
|
148
|
+
const capture = JSON.parse(await readFile(capturePath, "utf8"));
|
|
149
|
+
const url = new URL(capture.url);
|
|
150
|
+
assert.equal(url.origin, "https://app.nuelink.com");
|
|
151
|
+
assert.equal(url.pathname, "/api/public/v1/auth");
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("posts command supports all documented filter parameters", async () => {
|
|
155
|
+
const homeDir = await setupTempHome();
|
|
156
|
+
const capturePath = path.join(homeDir, "capture-posts-filters.json");
|
|
157
|
+
|
|
158
|
+
const result = runCli({
|
|
159
|
+
args: [
|
|
160
|
+
"posts", "--brand-id", "13493", "--collection-id", "33273",
|
|
161
|
+
"--status", "pending", "--post-type", "image", "--posting-type", "schedule",
|
|
162
|
+
"--created-from", "2026-10-01 00:00:00", "--created-to", "2026-10-31 23:59:59",
|
|
163
|
+
"--sort-by", "post_date", "--sort-order", "ASC",
|
|
164
|
+
],
|
|
165
|
+
homeDir,
|
|
166
|
+
capturePath,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
assert.equal(result.status, 0, result.stderr);
|
|
170
|
+
const url = new URL(JSON.parse(await readFile(capturePath, "utf8")).url);
|
|
171
|
+
assert.equal(url.searchParams.get("status"), "PENDING");
|
|
172
|
+
assert.equal(url.searchParams.get("post_type"), "IMAGE");
|
|
173
|
+
assert.equal(url.searchParams.get("posting_type"), "SCHEDULE");
|
|
174
|
+
assert.equal(url.searchParams.get("created_from"), "2026-10-01 00:00:00");
|
|
175
|
+
assert.equal(url.searchParams.get("created_to"), "2026-10-31 23:59:59");
|
|
176
|
+
assert.equal(url.searchParams.get("sort_by"), "post_date");
|
|
177
|
+
assert.equal(url.searchParams.get("sort_order"), "asc");
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test("posts command rejects reversed or invalid creation-time filters", async () => {
|
|
181
|
+
const homeDir = await setupTempHome();
|
|
182
|
+
const capturePath = path.join(homeDir, "capture-posts-invalid-filters.json");
|
|
183
|
+
|
|
184
|
+
const result = runCli({
|
|
185
|
+
args: [
|
|
186
|
+
"--json", "posts", "--brand-id", "13493", "--collection-id", "33273",
|
|
187
|
+
"--created-from", "2026-10-02 00:00:00", "--created-to", "2026-10-01 00:00:00",
|
|
188
|
+
],
|
|
189
|
+
homeDir,
|
|
190
|
+
capturePath,
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
assertJsonError(result, "VALIDATION_ERROR");
|
|
194
|
+
await assert.rejects(readFile(capturePath, "utf8"));
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test("media upload accepts documented PDF files and rejects unsupported GIF uploads", async () => {
|
|
198
|
+
const homeDir = await setupTempHome();
|
|
199
|
+
const pdfPath = path.join(homeDir, "document.pdf");
|
|
200
|
+
const gifPath = path.join(homeDir, "animation.gif");
|
|
201
|
+
await writeFile(pdfPath, "pdf content");
|
|
202
|
+
await writeFile(gifPath, "gif content");
|
|
203
|
+
|
|
204
|
+
const pdfResult = runCli({
|
|
205
|
+
args: ["media:upload", "--brand-id", "42", "--file", pdfPath, "--dry-run"],
|
|
206
|
+
homeDir,
|
|
207
|
+
capturePath: path.join(homeDir, "capture-pdf.json"),
|
|
208
|
+
});
|
|
209
|
+
assert.equal(pdfResult.status, 0, pdfResult.stderr);
|
|
210
|
+
assert.equal(JSON.parse(pdfResult.stdout).multipart.type, "application/pdf");
|
|
211
|
+
|
|
212
|
+
const gifResult = runCli({
|
|
213
|
+
args: ["--json", "media:upload", "--brand-id", "42", "--file", gifPath, "--dry-run"],
|
|
214
|
+
homeDir,
|
|
215
|
+
capturePath: path.join(homeDir, "capture-gif.json"),
|
|
216
|
+
});
|
|
217
|
+
assertJsonError(gifResult, "VALIDATION_ERROR");
|
|
218
|
+
});
|
|
219
|
+
|
|
137
220
|
test("brands command renders table output", async () => {
|
|
138
221
|
const homeDir = await setupTempHome();
|
|
139
222
|
const capturePath = path.join(homeDir, "capture-brands-table.json");
|
|
@@ -211,7 +294,7 @@ test("version flags print package version", async () => {
|
|
|
211
294
|
});
|
|
212
295
|
|
|
213
296
|
assert.equal(result.status, 0, result.stderr);
|
|
214
|
-
assert.equal(result.stdout.trim(), "1.4.
|
|
297
|
+
assert.equal(result.stdout.trim(), "1.4.4");
|
|
215
298
|
assert.equal(result.stderr, "");
|
|
216
299
|
}
|
|
217
300
|
});
|