@nuelink/nuelink-cli 1.5.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +26 -3
- package/package.json +1 -1
- package/src/commands.js +111 -3
- package/src/http.js +2 -0
- package/test/cli.test.mjs +166 -4
- package/test/mock-fetch.cjs +1 -0
- package/test/mock-fetch.mjs +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.6.1
|
|
4
|
+
|
|
5
|
+
- Reject HTTP redirects for API requests so mutation bodies and credentials are never forwarded to redirect destinations.
|
|
6
|
+
|
|
7
|
+
## 1.6.0
|
|
8
|
+
|
|
9
|
+
- Add collection update, channel assignment, and queue slot management commands.
|
|
10
|
+
- Add automation pause and activate support.
|
|
11
|
+
- Support collection post view filtering and caption-only post updates.
|
|
12
|
+
- Add an explicit option to clear a collection description.
|
|
13
|
+
|
|
3
14
|
## 1.5.0
|
|
4
15
|
|
|
5
16
|
- Preserve nullable post fields in `posts:add-json` and keep dry-run bodies aligned with sent requests.
|
package/README.md
CHANGED
|
@@ -171,6 +171,20 @@ nuelink-cli collections:create \
|
|
|
171
171
|
--dry-run
|
|
172
172
|
```
|
|
173
173
|
|
|
174
|
+
Update collection settings and manage channel assignments or queue slots:
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
nuelink-cli collections:update --brand-id 13493 --collection-id 33273 --status PAUSED --dry-run
|
|
178
|
+
nuelink-cli collections:update --brand-id 13493 --collection-id 33273 --clear-description --dry-run
|
|
179
|
+
nuelink-cli collections:add-channel --brand-id 13493 --collection-id 33273 --channel-id 300294 --dry-run
|
|
180
|
+
nuelink-cli collections:remove-channel --brand-id 13493 --collection-id 33273 --channel-id 300294 --dry-run
|
|
181
|
+
nuelink-cli collections:add-queue --brand-id 13493 --collection-id 33273 --date "Mon 09:30" --dry-run
|
|
182
|
+
nuelink-cli collections:delete-queue --brand-id 13493 --collection-id 33273 --queue-id 911 --dry-run
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Use `--clear-description` to send `description: null`; it cannot be combined
|
|
186
|
+
with `--description`.
|
|
187
|
+
|
|
174
188
|
### Automations
|
|
175
189
|
|
|
176
190
|
```bash
|
|
@@ -194,6 +208,12 @@ nuelink-cli automations:create \
|
|
|
194
208
|
--dry-run
|
|
195
209
|
```
|
|
196
210
|
|
|
211
|
+
Pause or activate an automation:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
nuelink-cli automations:update-status --brand-id 13493 --automation-id 315 --status PAUSED --dry-run
|
|
215
|
+
```
|
|
216
|
+
|
|
197
217
|
### Channels
|
|
198
218
|
|
|
199
219
|
```bash
|
|
@@ -228,7 +248,8 @@ nuelink-cli posts --brand-id 13493 --collection-id 33273 --per-page 5 --page 1
|
|
|
228
248
|
|
|
229
249
|
Post list output highlights the post ID, type, status, and publish date.
|
|
230
250
|
Optional filters include `--status`, `--post-type`, `--posting-type`,
|
|
231
|
-
`--
|
|
251
|
+
`--view` (`QUEUE`, `SCHEDULED`, `DRAFT`, or `PUBLISHED`), `--created-from`,
|
|
252
|
+
`--created-to`, `--sort-by`, and `--sort-order`.
|
|
232
253
|
Creation date filters use `YYYY-MM-DD HH:mm:ss` UTC timestamps.
|
|
233
254
|
|
|
234
255
|
List posts across all collections, inspect the brand queue, or review published results:
|
|
@@ -246,7 +267,7 @@ nuelink-cli posts:add-json --brand-id 13493 --collection-id 33273 --payload ./po
|
|
|
246
267
|
```
|
|
247
268
|
|
|
248
269
|
You can also pipe JSON through stdin with `--payload -`.
|
|
249
|
-
CLI 1.
|
|
270
|
+
CLI 1.6.0 preserves contract-nullable fields exactly; the dry-run body matches
|
|
250
271
|
the JSON body sent by the request.
|
|
251
272
|
|
|
252
273
|
Example `post.json`:
|
|
@@ -306,6 +327,8 @@ Supported publish modes are `DRAFT`, `QUEUE`, `SCHEDULE`, and `IMMEDIATE`. When
|
|
|
306
327
|
Preview a post lifecycle update or sensitive deletion before executing it:
|
|
307
328
|
|
|
308
329
|
```bash
|
|
330
|
+
nuelink-cli posts:update --brand-id 13493 --post-id 8801 \
|
|
331
|
+
--caption "Updated launch announcement." --dry-run
|
|
309
332
|
nuelink-cli posts:update --brand-id 13493 --post-id 8801 \
|
|
310
333
|
--publish-mode SCHEDULE --scheduled-at "BRAND_LOCAL_YYYY-MM-DD_HH:mm:ss" --dry-run
|
|
311
334
|
nuelink-cli posts:update --brand-id 13493 --post-id 8801 \
|
|
@@ -315,7 +338,7 @@ nuelink-cli posts:move --brand-id 13493 --source-collection-id 33273 \
|
|
|
315
338
|
nuelink-cli posts:delete --brand-id 13493 --post-id 8801 --dry-run
|
|
316
339
|
```
|
|
317
340
|
|
|
318
|
-
Moving is atomic: all supplied posts (at most 100) must belong to the source collection. Deletion is permanent and the API rejects it unless sensitive AI actions are enabled for the account.
|
|
341
|
+
`posts:update` accepts `--caption` (1–3000 characters) alongside or instead of a scheduling change. Caption edits are not available for poll or published posts. Moving is atomic: all supplied posts (at most 100) must belong to the source collection. Deletion is permanent and the API rejects it unless sensitive AI actions are enabled for the account.
|
|
319
342
|
|
|
320
343
|
Published-post results are returned unchanged in `--json` mode. Each per-channel
|
|
321
344
|
record includes `likes`, `comments`, `shares`, `views`, `saves`, `engagement`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuelink/nuelink-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
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",
|
package/src/commands.js
CHANGED
|
@@ -377,6 +377,95 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
377
377
|
});
|
|
378
378
|
}));
|
|
379
379
|
|
|
380
|
+
program
|
|
381
|
+
.command("collections:update")
|
|
382
|
+
.description("Update collection properties")
|
|
383
|
+
.requiredOption("--brand-id <id>", "Brand ID")
|
|
384
|
+
.requiredOption("--collection-id <id>", "Collection ID")
|
|
385
|
+
.option("--title <title>", "Collection title")
|
|
386
|
+
.option("--description <text>", "Collection description")
|
|
387
|
+
.option("--clear-description", "Set the collection description to null")
|
|
388
|
+
.option("--status <status>", "Collection status (ACTIVE or PAUSED)")
|
|
389
|
+
.option("--max-republish <number>", "Maximum republish count")
|
|
390
|
+
.action(withCommandErrorHandling(program, async (options) => {
|
|
391
|
+
if (options.clearDescription && options.description !== undefined) {
|
|
392
|
+
throw new Error("Use either --description or --clear-description, not both.");
|
|
393
|
+
}
|
|
394
|
+
const body = {
|
|
395
|
+
title: options.title === undefined ? undefined : validateRequiredString(options.title, 255, "title"),
|
|
396
|
+
description: options.clearDescription
|
|
397
|
+
? null
|
|
398
|
+
: options.description === undefined
|
|
399
|
+
? undefined
|
|
400
|
+
: validateMaxLength(options.description, 1000, "description"),
|
|
401
|
+
status: options.status === undefined ? undefined : normalizeEnum(options.status, "status", ["ACTIVE", "PAUSED"]),
|
|
402
|
+
maxRepublish: parseOptionalNonNegativeInteger(options.maxRepublish, "max-republish"),
|
|
403
|
+
};
|
|
404
|
+
if (Object.values(body).every((value) => value === undefined)) {
|
|
405
|
+
throw new Error("Provide at least one collection property to update.");
|
|
406
|
+
}
|
|
407
|
+
await executeRequest(program, runtimeApiKey, {
|
|
408
|
+
method: "PATCH",
|
|
409
|
+
endpoint: `${collectionPath(parsePositiveInteger(options.brandId, "brand-id"), parsePositiveInteger(options.collectionId, "collection-id"))}`,
|
|
410
|
+
body,
|
|
411
|
+
});
|
|
412
|
+
}));
|
|
413
|
+
|
|
414
|
+
program
|
|
415
|
+
.command("collections:add-channel")
|
|
416
|
+
.description("Add a channel to a collection")
|
|
417
|
+
.requiredOption("--brand-id <id>", "Brand ID")
|
|
418
|
+
.requiredOption("--collection-id <id>", "Collection ID")
|
|
419
|
+
.requiredOption("--channel-id <id>", "Channel ID")
|
|
420
|
+
.action(withCommandErrorHandling(program, async (options) => {
|
|
421
|
+
await executeRequest(program, runtimeApiKey, {
|
|
422
|
+
method: "POST",
|
|
423
|
+
endpoint: `${collectionPath(parsePositiveInteger(options.brandId, "brand-id"), parsePositiveInteger(options.collectionId, "collection-id"))}/channels`,
|
|
424
|
+
body: { channelId: parsePositiveInteger(options.channelId, "channel-id") },
|
|
425
|
+
});
|
|
426
|
+
}));
|
|
427
|
+
|
|
428
|
+
program
|
|
429
|
+
.command("collections:remove-channel")
|
|
430
|
+
.description("Remove a channel from a collection")
|
|
431
|
+
.requiredOption("--brand-id <id>", "Brand ID")
|
|
432
|
+
.requiredOption("--collection-id <id>", "Collection ID")
|
|
433
|
+
.requiredOption("--channel-id <id>", "Channel ID")
|
|
434
|
+
.action(withCommandErrorHandling(program, async (options) => {
|
|
435
|
+
await executeRequest(program, runtimeApiKey, {
|
|
436
|
+
method: "DELETE",
|
|
437
|
+
endpoint: `${collectionPath(parsePositiveInteger(options.brandId, "brand-id"), parsePositiveInteger(options.collectionId, "collection-id"))}/channels/${parsePositiveInteger(options.channelId, "channel-id")}`,
|
|
438
|
+
});
|
|
439
|
+
}));
|
|
440
|
+
|
|
441
|
+
program
|
|
442
|
+
.command("collections:add-queue")
|
|
443
|
+
.description("Add a weekly queue slot to a collection")
|
|
444
|
+
.requiredOption("--brand-id <id>", "Brand ID")
|
|
445
|
+
.requiredOption("--collection-id <id>", "Collection ID")
|
|
446
|
+
.requiredOption("--date <slot>", "Weekly slot in brand timezone (e.g. Mon 09:30)")
|
|
447
|
+
.action(withCommandErrorHandling(program, async (options) => {
|
|
448
|
+
const [date] = validateQueueSlots([options.date]);
|
|
449
|
+
await executeRequest(program, runtimeApiKey, {
|
|
450
|
+
method: "POST",
|
|
451
|
+
endpoint: `${collectionPath(parsePositiveInteger(options.brandId, "brand-id"), parsePositiveInteger(options.collectionId, "collection-id"))}/queues`,
|
|
452
|
+
body: { date },
|
|
453
|
+
});
|
|
454
|
+
}));
|
|
455
|
+
|
|
456
|
+
program
|
|
457
|
+
.command("collections:delete-queue")
|
|
458
|
+
.description("Delete a weekly queue slot")
|
|
459
|
+
.requiredOption("--brand-id <id>", "Brand ID")
|
|
460
|
+
.requiredOption("--collection-id <id>", "Collection ID")
|
|
461
|
+
.requiredOption("--queue-id <id>", "Queue slot ID")
|
|
462
|
+
.action(withCommandErrorHandling(program, async (options) => {
|
|
463
|
+
await executeRequest(program, runtimeApiKey, {
|
|
464
|
+
method: "DELETE",
|
|
465
|
+
endpoint: `${collectionPath(parsePositiveInteger(options.brandId, "brand-id"), parsePositiveInteger(options.collectionId, "collection-id"))}/queues/${parsePositiveInteger(options.queueId, "queue-id")}`,
|
|
466
|
+
});
|
|
467
|
+
}));
|
|
468
|
+
|
|
380
469
|
program
|
|
381
470
|
.command("automations")
|
|
382
471
|
.description("List automations for a brand")
|
|
@@ -428,6 +517,20 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
428
517
|
});
|
|
429
518
|
}));
|
|
430
519
|
|
|
520
|
+
program
|
|
521
|
+
.command("automations:update-status")
|
|
522
|
+
.description("Pause or activate an automation")
|
|
523
|
+
.requiredOption("--brand-id <id>", "Brand ID")
|
|
524
|
+
.requiredOption("--automation-id <id>", "Automation ID")
|
|
525
|
+
.requiredOption("--status <status>", "Automation status (ACTIVE, PAUSED, or INACTIVE)")
|
|
526
|
+
.action(withCommandErrorHandling(program, async (options) => {
|
|
527
|
+
await executeRequest(program, runtimeApiKey, {
|
|
528
|
+
method: "PATCH",
|
|
529
|
+
endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/automations/${parsePositiveInteger(options.automationId, "automation-id")}`,
|
|
530
|
+
body: { status: normalizeEnum(options.status, "status", ["ACTIVE", "PAUSED", "INACTIVE"]) },
|
|
531
|
+
});
|
|
532
|
+
}));
|
|
533
|
+
|
|
431
534
|
program
|
|
432
535
|
.command("channels")
|
|
433
536
|
.description("List channels for a brand")
|
|
@@ -502,6 +605,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
502
605
|
.requiredOption("--collection-id <id>", "Collection ID")
|
|
503
606
|
.option("--per-page <number>", "Items per page", "25")
|
|
504
607
|
.option("--page <number>", "Page number", "1")
|
|
608
|
+
.option("--view <view>", `Post view (${VALID_POST_VIEWS.join(", ")})`)
|
|
505
609
|
.option("--status <status>", `Post status (${VALID_POST_STATUSES.join(", ")})`)
|
|
506
610
|
.option("--post-type <type>", `Post type (${VALID_POST_TYPES.join(", ")})`)
|
|
507
611
|
.option("--posting-type <type>", `Posting type (${VALID_POSTING_TYPES.join(", ")})`)
|
|
@@ -536,6 +640,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
536
640
|
query: {
|
|
537
641
|
per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
|
|
538
642
|
page: parsePositiveInteger(options.page, "page"),
|
|
643
|
+
view: options.view ? normalizeEnum(options.view, "view", VALID_POST_VIEWS) : undefined,
|
|
539
644
|
status: options.status
|
|
540
645
|
? normalizeEnum(options.status, "status", VALID_POST_STATUSES)
|
|
541
646
|
: undefined,
|
|
@@ -645,12 +750,13 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
645
750
|
|
|
646
751
|
program
|
|
647
752
|
.command("posts:update")
|
|
648
|
-
.description("
|
|
753
|
+
.description("Edit a caption or change lifecycle of an unpublished non-poll post")
|
|
649
754
|
.requiredOption("--brand-id <id>", "Brand ID")
|
|
650
755
|
.requiredOption("--post-id <id>", "Post ID")
|
|
651
756
|
.option("--publish-mode <mode>", `Publish mode (${VALID_POST_UPDATE_MODES.join(", ")})`)
|
|
652
757
|
.option("--scheduled-at <value>", "Brand-local publish datetime (YYYY-MM-DD HH:mm:ss)")
|
|
653
758
|
.option("--queue-position <position>", `Queue position (${VALID_QUEUE_POSITIONS.join(", ")})`)
|
|
759
|
+
.option("--caption <text>", "Updated post caption (up to 3000 characters)")
|
|
654
760
|
.action(withCommandErrorHandling(program, async (options) => {
|
|
655
761
|
const publishMode = options.publishMode
|
|
656
762
|
? normalizeEnum(options.publishMode, "publish-mode", VALID_POST_UPDATE_MODES)
|
|
@@ -659,8 +765,9 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
659
765
|
? normalizeEnum(options.queuePosition, "queue-position", VALID_QUEUE_POSITIONS)
|
|
660
766
|
: undefined;
|
|
661
767
|
const scheduledAt = validatePostDateTime(options.scheduledAt, "scheduled-at");
|
|
662
|
-
|
|
663
|
-
|
|
768
|
+
const caption = options.caption === undefined ? undefined : validateRequiredString(options.caption, 3000, "caption");
|
|
769
|
+
if (!caption && !publishMode && !queuePosition) {
|
|
770
|
+
throw new Error("At least one of caption, publish-mode, or queue-position is required.");
|
|
664
771
|
}
|
|
665
772
|
if (publishMode === "SCHEDULE" && !scheduledAt) {
|
|
666
773
|
throw new Error("scheduled-at is required when publish-mode is SCHEDULE.");
|
|
@@ -676,6 +783,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
676
783
|
publishMode,
|
|
677
784
|
scheduledAt,
|
|
678
785
|
queuePosition,
|
|
786
|
+
caption,
|
|
679
787
|
},
|
|
680
788
|
});
|
|
681
789
|
}));
|
package/src/http.js
CHANGED
|
@@ -185,6 +185,8 @@ async function nuelinkRequest({ apiKey, method = "GET", endpoint, query, body, m
|
|
|
185
185
|
const init = {
|
|
186
186
|
method,
|
|
187
187
|
headers,
|
|
188
|
+
// API mutations must never replay a body or credentials to a redirect target.
|
|
189
|
+
redirect: "error",
|
|
188
190
|
};
|
|
189
191
|
|
|
190
192
|
if (multipart) {
|
package/test/cli.test.mjs
CHANGED
|
@@ -3,9 +3,10 @@ import assert from "node:assert/strict";
|
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { mkdir, mkdtemp, readFile, readdir, writeFile } from "node:fs/promises";
|
|
6
|
-
import { spawnSync } from "node:child_process";
|
|
6
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { pathToFileURL } from "node:url";
|
|
9
|
+
import { createServer } from "node:http";
|
|
9
10
|
|
|
10
11
|
const __filename = fileURLToPath(import.meta.url);
|
|
11
12
|
const __dirname = path.dirname(__filename);
|
|
@@ -43,6 +44,32 @@ function runCli({ args, homeDir, capturePath, withMock = true, input, extraEnv =
|
|
|
43
44
|
});
|
|
44
45
|
}
|
|
45
46
|
|
|
47
|
+
function runCliAsync({ args, homeDir, capturePath, withMock = false, extraEnv = {} }) {
|
|
48
|
+
const nodeArgs = withMock
|
|
49
|
+
? ["--require", mockCjsPath, mainPath, ...args]
|
|
50
|
+
: [mainPath, ...args];
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
const child = spawn(process.execPath, nodeArgs, {
|
|
53
|
+
cwd: workspaceRoot,
|
|
54
|
+
env: {
|
|
55
|
+
...process.env,
|
|
56
|
+
HOME: homeDir,
|
|
57
|
+
USERPROFILE: homeDir,
|
|
58
|
+
NUELINK_API_KEY: currentApiKey(),
|
|
59
|
+
NUELINK_MOCK_CAPTURE_PATH: capturePath,
|
|
60
|
+
...extraEnv,
|
|
61
|
+
},
|
|
62
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
63
|
+
});
|
|
64
|
+
let stdout = "";
|
|
65
|
+
let stderr = "";
|
|
66
|
+
child.stdout.setEncoding("utf8").on("data", (chunk) => { stdout += chunk; });
|
|
67
|
+
child.stderr.setEncoding("utf8").on("data", (chunk) => { stderr += chunk; });
|
|
68
|
+
child.on("error", reject);
|
|
69
|
+
child.on("close", (status) => resolve({ status, stdout, stderr }));
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
46
73
|
function assertJsonError(result, code) {
|
|
47
74
|
assert.equal(result.status, 1, result.stderr);
|
|
48
75
|
assert.equal(result.stderr, "");
|
|
@@ -68,12 +95,68 @@ test("brands command builds pagination query", async () => {
|
|
|
68
95
|
const url = new URL(capture.url);
|
|
69
96
|
|
|
70
97
|
assert.equal(capture.method, "GET");
|
|
98
|
+
assert.equal(capture.redirect, "error");
|
|
71
99
|
assert.equal(url.pathname, "/api/public/v1/brands");
|
|
72
100
|
assert.equal(url.searchParams.get("per_page"), "2");
|
|
73
101
|
assert.equal(url.searchParams.get("page"), "3");
|
|
74
102
|
assert.match(capture.headers.Authorization || capture.headers.authorization, /^Bearer\s+/);
|
|
75
103
|
});
|
|
76
104
|
|
|
105
|
+
test("mutation requests reject cross-origin redirects before forwarding their body", async () => {
|
|
106
|
+
const homeDir = await setupTempHome();
|
|
107
|
+
let forwardedRequests = 0;
|
|
108
|
+
let originalRequest;
|
|
109
|
+
const destination = createServer(() => {
|
|
110
|
+
forwardedRequests += 1;
|
|
111
|
+
});
|
|
112
|
+
const destinationAddress = await new Promise((resolve) => {
|
|
113
|
+
destination.listen(0, "127.0.0.1", () => resolve(destination.address()));
|
|
114
|
+
});
|
|
115
|
+
const origin = createServer((request, response) => {
|
|
116
|
+
let body = "";
|
|
117
|
+
request.setEncoding("utf8");
|
|
118
|
+
request.on("data", (chunk) => { body += chunk; });
|
|
119
|
+
request.on("end", () => {
|
|
120
|
+
originalRequest = {
|
|
121
|
+
method: request.method,
|
|
122
|
+
authorization: request.headers.authorization,
|
|
123
|
+
body,
|
|
124
|
+
};
|
|
125
|
+
response.writeHead(307, { location: `http://127.0.0.1:${destinationAddress.port}/capture` });
|
|
126
|
+
response.end();
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
const originAddress = await new Promise((resolve) => {
|
|
132
|
+
origin.listen(0, "127.0.0.1", () => resolve(origin.address()));
|
|
133
|
+
});
|
|
134
|
+
const result = await runCliAsync({
|
|
135
|
+
args: ["collections:create", "--brand-id", "13493", "--title", "redirect guard"],
|
|
136
|
+
homeDir,
|
|
137
|
+
capturePath: path.join(homeDir, "capture-redirect-policy.json"),
|
|
138
|
+
withMock: false,
|
|
139
|
+
extraEnv: {
|
|
140
|
+
NUELINK_BASE_URL: `http://127.0.0.1:${originAddress.port}/api/public/v1`,
|
|
141
|
+
NUELINK_ALLOW_INSECURE_HTTP: "1",
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
assert.equal(result.status, 1);
|
|
146
|
+
assert.deepEqual(originalRequest, {
|
|
147
|
+
method: "POST",
|
|
148
|
+
authorization: `Bearer ${currentApiKey()}`,
|
|
149
|
+
body: JSON.stringify({ title: "redirect guard", description: "", channels: [], queues: [] }),
|
|
150
|
+
});
|
|
151
|
+
assert.equal(forwardedRequests, 0);
|
|
152
|
+
} finally {
|
|
153
|
+
await Promise.all([
|
|
154
|
+
new Promise((resolve) => origin.close(resolve)),
|
|
155
|
+
new Promise((resolve) => destination.close(resolve)),
|
|
156
|
+
]);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
77
160
|
test("automations command builds pagination query", async () => {
|
|
78
161
|
const homeDir = await setupTempHome();
|
|
79
162
|
const capturePath = path.join(homeDir, "capture-automations.json");
|
|
@@ -158,7 +241,7 @@ test("posts command supports all documented filter parameters", async () => {
|
|
|
158
241
|
const result = runCli({
|
|
159
242
|
args: [
|
|
160
243
|
"posts", "--brand-id", "13493", "--collection-id", "33273",
|
|
161
|
-
"--status", "pending", "--post-type", "image", "--posting-type", "schedule",
|
|
244
|
+
"--view", "queue", "--status", "pending", "--post-type", "image", "--posting-type", "schedule",
|
|
162
245
|
"--created-from", "2026-10-01 00:00:00", "--created-to", "2026-10-31 23:59:59",
|
|
163
246
|
"--sort-by", "post_date", "--sort-order", "ASC",
|
|
164
247
|
],
|
|
@@ -168,6 +251,7 @@ test("posts command supports all documented filter parameters", async () => {
|
|
|
168
251
|
|
|
169
252
|
assert.equal(result.status, 0, result.stderr);
|
|
170
253
|
const url = new URL(JSON.parse(await readFile(capturePath, "utf8")).url);
|
|
254
|
+
assert.equal(url.searchParams.get("view"), "QUEUE");
|
|
171
255
|
assert.equal(url.searchParams.get("status"), "PENDING");
|
|
172
256
|
assert.equal(url.searchParams.get("post_type"), "IMAGE");
|
|
173
257
|
assert.equal(url.searchParams.get("posting_type"), "SCHEDULE");
|
|
@@ -284,6 +368,7 @@ test("quiet mode suppresses success banner", async () => {
|
|
|
284
368
|
|
|
285
369
|
test("version flags print package version", async () => {
|
|
286
370
|
const homeDir = await setupTempHome();
|
|
371
|
+
const packageManifest = JSON.parse(await readFile(path.join(workspaceRoot, "package.json"), "utf8"));
|
|
287
372
|
|
|
288
373
|
for (const flag of ["--version", "-V"]) {
|
|
289
374
|
const result = runCli({
|
|
@@ -294,7 +379,7 @@ test("version flags print package version", async () => {
|
|
|
294
379
|
});
|
|
295
380
|
|
|
296
381
|
assert.equal(result.status, 0, result.stderr);
|
|
297
|
-
assert.equal(result.stdout.trim(),
|
|
382
|
+
assert.equal(result.stdout.trim(), packageManifest.version);
|
|
298
383
|
assert.equal(result.stderr, "");
|
|
299
384
|
}
|
|
300
385
|
});
|
|
@@ -743,6 +828,67 @@ test("dry-run prints validated request without sending", async () => {
|
|
|
743
828
|
await assert.rejects(readFile(capturePath, "utf8"));
|
|
744
829
|
});
|
|
745
830
|
|
|
831
|
+
test("new public API management commands build the documented requests", async () => {
|
|
832
|
+
const cases = [
|
|
833
|
+
{
|
|
834
|
+
args: ["automations:update-status", "--brand-id", "42", "--automation-id", "15", "--status", "paused"],
|
|
835
|
+
method: "PATCH",
|
|
836
|
+
pathname: "/api/public/v1/brands/42/automations/15",
|
|
837
|
+
body: { status: "PAUSED" },
|
|
838
|
+
},
|
|
839
|
+
{
|
|
840
|
+
args: ["collections:update", "--brand-id", "42", "--collection-id", "77", "--status", "paused"],
|
|
841
|
+
method: "PATCH",
|
|
842
|
+
pathname: "/api/public/v1/brands/42/collections/77",
|
|
843
|
+
body: { status: "PAUSED" },
|
|
844
|
+
},
|
|
845
|
+
{
|
|
846
|
+
args: ["collections:update", "--brand-id", "42", "--collection-id", "77", "--clear-description"],
|
|
847
|
+
method: "PATCH",
|
|
848
|
+
pathname: "/api/public/v1/brands/42/collections/77",
|
|
849
|
+
body: { description: null },
|
|
850
|
+
},
|
|
851
|
+
{
|
|
852
|
+
args: ["collections:add-channel", "--brand-id", "42", "--collection-id", "77", "--channel-id", "501"],
|
|
853
|
+
method: "POST",
|
|
854
|
+
pathname: "/api/public/v1/brands/42/collections/77/channels",
|
|
855
|
+
body: { channelId: 501 },
|
|
856
|
+
},
|
|
857
|
+
{
|
|
858
|
+
args: ["collections:remove-channel", "--brand-id", "42", "--collection-id", "77", "--channel-id", "501"],
|
|
859
|
+
method: "DELETE",
|
|
860
|
+
pathname: "/api/public/v1/brands/42/collections/77/channels/501",
|
|
861
|
+
},
|
|
862
|
+
{
|
|
863
|
+
args: ["collections:add-queue", "--brand-id", "42", "--collection-id", "77", "--date", "Mon 09:30"],
|
|
864
|
+
method: "POST",
|
|
865
|
+
pathname: "/api/public/v1/brands/42/collections/77/queues",
|
|
866
|
+
body: { date: "Mon 09:30" },
|
|
867
|
+
},
|
|
868
|
+
{
|
|
869
|
+
args: ["collections:delete-queue", "--brand-id", "42", "--collection-id", "77", "--queue-id", "911"],
|
|
870
|
+
method: "DELETE",
|
|
871
|
+
pathname: "/api/public/v1/brands/42/collections/77/queues/911",
|
|
872
|
+
},
|
|
873
|
+
];
|
|
874
|
+
|
|
875
|
+
for (const [index, expected] of cases.entries()) {
|
|
876
|
+
const homeDir = await setupTempHome();
|
|
877
|
+
const result = runCli({
|
|
878
|
+
args: ["--dry-run", ...expected.args],
|
|
879
|
+
homeDir,
|
|
880
|
+
capturePath: path.join(homeDir, `capture-management-${index}.json`),
|
|
881
|
+
extraEnv: { NUELINK_API_KEY: "" },
|
|
882
|
+
});
|
|
883
|
+
assert.equal(result.status, 0, result.stderr);
|
|
884
|
+
const output = JSON.parse(result.stdout);
|
|
885
|
+
assert.equal(output.dryRun, true);
|
|
886
|
+
assert.equal(output.method, expected.method);
|
|
887
|
+
assert.equal(new URL(output.url).pathname, expected.pathname);
|
|
888
|
+
if (expected.body) assert.deepEqual(output.body, expected.body);
|
|
889
|
+
}
|
|
890
|
+
});
|
|
891
|
+
|
|
746
892
|
test("posts:create builds full payload from options", async () => {
|
|
747
893
|
const homeDir = await setupTempHome();
|
|
748
894
|
const capturePath = path.join(homeDir, "capture-posts-create.json");
|
|
@@ -1121,6 +1267,22 @@ test("posts:update builds the documented patch payload", async () => {
|
|
|
1121
1267
|
});
|
|
1122
1268
|
});
|
|
1123
1269
|
|
|
1270
|
+
test("posts:update can edit a caption without changing its lifecycle state", async () => {
|
|
1271
|
+
const homeDir = await setupTempHome();
|
|
1272
|
+
const capturePath = path.join(homeDir, "capture-post-caption-update.json");
|
|
1273
|
+
const result = runCli({
|
|
1274
|
+
args: ["posts:update", "--brand-id", "42", "--post-id", "8801", "--caption", "Updated launch announcement."],
|
|
1275
|
+
homeDir,
|
|
1276
|
+
capturePath,
|
|
1277
|
+
});
|
|
1278
|
+
|
|
1279
|
+
assert.equal(result.status, 0, result.stderr);
|
|
1280
|
+
const capture = JSON.parse(await readFile(capturePath, "utf8"));
|
|
1281
|
+
assert.equal(capture.method, "PATCH");
|
|
1282
|
+
assert.equal(new URL(capture.url).pathname, "/api/public/v1/brands/42/posts/8801");
|
|
1283
|
+
assert.deepEqual(capture.body, { caption: "Updated launch announcement." });
|
|
1284
|
+
});
|
|
1285
|
+
|
|
1124
1286
|
test("posts:move builds the documented atomic move payload", async () => {
|
|
1125
1287
|
const homeDir = await setupTempHome();
|
|
1126
1288
|
const capturePath = path.join(homeDir, "capture-post-move.json");
|
|
@@ -1168,7 +1330,7 @@ test("posts:update requires an update operation", async () => {
|
|
|
1168
1330
|
});
|
|
1169
1331
|
|
|
1170
1332
|
assert.equal(result.status, 1);
|
|
1171
|
-
assert.match(result.stderr, /At least one of publish-mode or queue-position is required/);
|
|
1333
|
+
assert.match(result.stderr, /At least one of caption, publish-mode, or queue-position is required/);
|
|
1172
1334
|
});
|
|
1173
1335
|
|
|
1174
1336
|
test("posts:delete targets the sensitive delete endpoint", async () => {
|
package/test/mock-fetch.cjs
CHANGED