@nuelink/nuelink-cli 1.4.5 → 1.6.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/CHANGELOG.md +27 -13
- package/CONTRIBUTING.md +123 -0
- package/README.md +62 -6
- package/package.json +6 -6
- package/src/cli.js +1 -1
- package/src/commands.js +149 -3
- package/src/http.js +53 -5
- package/src/postPayload.js +15 -5
- package/test/cli.test.mjs +240 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## 1.
|
|
4
|
-
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
|
|
10
|
-
## 1.
|
|
11
|
-
|
|
12
|
-
-
|
|
13
|
-
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.6.0
|
|
4
|
+
|
|
5
|
+
- Add collection update, channel assignment, and queue slot management commands.
|
|
6
|
+
- Add automation pause and activate support.
|
|
7
|
+
- Support collection post view filtering and caption-only post updates.
|
|
8
|
+
- Add an explicit option to clear a collection description.
|
|
9
|
+
|
|
10
|
+
## 1.5.0
|
|
11
|
+
|
|
12
|
+
- Preserve nullable post fields in `posts:add-json` and keep dry-run bodies aligned with sent requests.
|
|
13
|
+
- Restrict API base URLs to Nuelink or explicitly trusted HTTPS hosts; allow HTTP only for opted-in loopback development.
|
|
14
|
+
- Require delayed-comment text and delay together, reject GET dry-runs, and make no-command JSON errors machine-readable.
|
|
15
|
+
- Remove the package self-dependency and correct repository/package contents metadata.
|
|
16
|
+
|
|
17
|
+
## 1.4.1 - 2026-08-18
|
|
18
|
+
|
|
19
|
+
- Emit structured machine-readable errors when `--json` is enabled.
|
|
20
|
+
- Reject blank required mutation fields and invalid runtime configuration.
|
|
21
|
+
- Harden saved credential writes and avoid reading media during dry runs.
|
|
22
|
+
- Include tests, security guidance, license, and repository metadata in the npm package.
|
|
23
|
+
|
|
24
|
+
## 1.4.0
|
|
25
|
+
|
|
26
|
+
- Add dry-run mutation previews, stricter request validation, retries, timeouts,
|
|
27
|
+
and expanded post creation options.
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Contributing to Nuelink CLI
|
|
2
|
+
|
|
3
|
+
Thanks for your interest in contributing.
|
|
4
|
+
|
|
5
|
+
This document describes the contribution workflow, code standards, and release expectations for this repository.
|
|
6
|
+
|
|
7
|
+
## Prerequisites
|
|
8
|
+
|
|
9
|
+
- Node.js 18.17+
|
|
10
|
+
- npm 9+
|
|
11
|
+
- Git
|
|
12
|
+
|
|
13
|
+
## Local Setup
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm ci
|
|
17
|
+
npm test
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Development Workflow
|
|
21
|
+
|
|
22
|
+
1. Create a branch from `main`.
|
|
23
|
+
2. Make focused changes with clear intent.
|
|
24
|
+
3. Add or update tests for behavioral changes.
|
|
25
|
+
4. Run validation locally.
|
|
26
|
+
5. Open a pull request with context and testing notes.
|
|
27
|
+
|
|
28
|
+
## Recommended Branch Naming
|
|
29
|
+
|
|
30
|
+
Use one of these patterns:
|
|
31
|
+
|
|
32
|
+
- `feat/<short-description>`
|
|
33
|
+
- `fix/<short-description>`
|
|
34
|
+
- `docs/<short-description>`
|
|
35
|
+
- `chore/<short-description>`
|
|
36
|
+
|
|
37
|
+
Examples:
|
|
38
|
+
|
|
39
|
+
- `feat/add-posts-delete-command`
|
|
40
|
+
- `fix/auth-status-token-mask`
|
|
41
|
+
|
|
42
|
+
## Commit Guidance
|
|
43
|
+
|
|
44
|
+
Conventional commit style is recommended:
|
|
45
|
+
|
|
46
|
+
- `feat: add channels filtering support`
|
|
47
|
+
- `fix: handle non-json error responses`
|
|
48
|
+
- `docs: add security policy`
|
|
49
|
+
- `test: add mocked brands pagination test`
|
|
50
|
+
|
|
51
|
+
## Quality Gates
|
|
52
|
+
|
|
53
|
+
Run before pushing:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npm test
|
|
57
|
+
npm run check:pack
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Code Style
|
|
61
|
+
|
|
62
|
+
- Keep code simple and explicit.
|
|
63
|
+
- Prefer small functions with single responsibility.
|
|
64
|
+
- Do not log secrets or raw API tokens.
|
|
65
|
+
- Preserve command names and flag behavior unless intentionally versioned.
|
|
66
|
+
- Favor backward compatibility for CLI UX.
|
|
67
|
+
|
|
68
|
+
## Tests
|
|
69
|
+
|
|
70
|
+
The test suite uses Node's built-in test runner with a mocked fetch preload.
|
|
71
|
+
|
|
72
|
+
- Main test file: `test/cli.test.mjs`
|
|
73
|
+
- Mock layer: `test/mock-fetch.mjs`
|
|
74
|
+
|
|
75
|
+
When adding commands, include tests for:
|
|
76
|
+
|
|
77
|
+
1. URL path and query construction
|
|
78
|
+
2. Request method and body shape
|
|
79
|
+
3. Auth behavior where applicable
|
|
80
|
+
|
|
81
|
+
## Pull Request Checklist
|
|
82
|
+
|
|
83
|
+
- [ ] Changes are scoped and documented
|
|
84
|
+
- [ ] Tests updated or added
|
|
85
|
+
- [ ] `npm test` passes
|
|
86
|
+
- [ ] `npm run check:pack` passes
|
|
87
|
+
- [ ] No credentials or sensitive values committed
|
|
88
|
+
|
|
89
|
+
## Reporting Bugs
|
|
90
|
+
|
|
91
|
+
Include:
|
|
92
|
+
|
|
93
|
+
1. CLI version (`nuelink-cli --version`)
|
|
94
|
+
2. Node version (`node -v`)
|
|
95
|
+
3. Reproduction command
|
|
96
|
+
4. Expected vs actual behavior
|
|
97
|
+
5. Relevant sanitized output
|
|
98
|
+
|
|
99
|
+
## Feature Requests
|
|
100
|
+
|
|
101
|
+
Provide:
|
|
102
|
+
|
|
103
|
+
1. Problem statement
|
|
104
|
+
2. Proposed command/flags UX
|
|
105
|
+
3. Example input/output
|
|
106
|
+
4. Compatibility considerations
|
|
107
|
+
|
|
108
|
+
## Release Process (Maintainers)
|
|
109
|
+
|
|
110
|
+
1. Ensure CI is passing.
|
|
111
|
+
2. Bump version in `package.json`.
|
|
112
|
+
3. Validate with:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
npm test
|
|
116
|
+
npm run check:pack
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
4. Publish:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
npm publish --access public
|
|
123
|
+
```
|
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,6 +267,8 @@ 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 -`.
|
|
270
|
+
CLI 1.5.0 preserves contract-nullable fields exactly; the dry-run body matches
|
|
271
|
+
the JSON body sent by the request.
|
|
249
272
|
|
|
250
273
|
Example `post.json`:
|
|
251
274
|
|
|
@@ -294,7 +317,10 @@ nuelink-cli posts:create \
|
|
|
294
317
|
```
|
|
295
318
|
|
|
296
319
|
Review each mutation preview, then repeat the same command without `--dry-run`
|
|
297
|
-
only when you intend to send it.
|
|
320
|
+
only when you intend to send it. `--dry-run` is supported for mutations; GET
|
|
321
|
+
commands reject it instead of silently suppressing the read. Post creation and
|
|
322
|
+
update schedule values are brand-local and must be at least 10 minutes ahead;
|
|
323
|
+
date filters and returned `postDate` values are UTC.
|
|
298
324
|
|
|
299
325
|
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.
|
|
300
326
|
|
|
@@ -302,13 +328,41 @@ Preview a post lifecycle update or sensitive deletion before executing it:
|
|
|
302
328
|
|
|
303
329
|
```bash
|
|
304
330
|
nuelink-cli posts:update --brand-id 13493 --post-id 8801 \
|
|
305
|
-
--
|
|
331
|
+
--caption "Updated launch announcement." --dry-run
|
|
332
|
+
nuelink-cli posts:update --brand-id 13493 --post-id 8801 \
|
|
333
|
+
--publish-mode SCHEDULE --scheduled-at "BRAND_LOCAL_YYYY-MM-DD_HH:mm:ss" --dry-run
|
|
306
334
|
nuelink-cli posts:update --brand-id 13493 --post-id 8801 \
|
|
307
335
|
--queue-position FRONT --dry-run
|
|
336
|
+
nuelink-cli posts:move --brand-id 13493 --source-collection-id 33273 \
|
|
337
|
+
--destination-collection-id 33274 --post-ids "8801,8802" --dry-run
|
|
308
338
|
nuelink-cli posts:delete --brand-id 13493 --post-id 8801 --dry-run
|
|
309
339
|
```
|
|
310
340
|
|
|
311
|
-
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.
|
|
342
|
+
|
|
343
|
+
Published-post results are returned unchanged in `--json` mode. Each per-channel
|
|
344
|
+
record includes `likes`, `comments`, `shares`, `views`, `saves`, `engagement`,
|
|
345
|
+
`clicks`, `impressions`, and `reach` under `results`:
|
|
346
|
+
|
|
347
|
+
```json
|
|
348
|
+
{
|
|
349
|
+
"id": 120045,
|
|
350
|
+
"postId": 8801,
|
|
351
|
+
"collectionId": 33273,
|
|
352
|
+
"channel": { "id": 501, "name": "Acme on LinkedIn", "type": "LinkedIn" },
|
|
353
|
+
"postType": "IMAGE",
|
|
354
|
+
"body": "Our new product is live.",
|
|
355
|
+
"url": "https://www.linkedin.com/feed/update/urn:li:share:123",
|
|
356
|
+
"status": "PUBLISHED",
|
|
357
|
+
"message": null,
|
|
358
|
+
"publishedAt": "2026-10-10T14:00:00.000000Z",
|
|
359
|
+
"results": {
|
|
360
|
+
"likes": 42, "comments": 5, "shares": 3, "views": 1200,
|
|
361
|
+
"saves": 18, "engagement": 68, "clicks": 27,
|
|
362
|
+
"impressions": 1540, "reach": 1310
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
```
|
|
312
366
|
|
|
313
367
|
Pagination uses `--page >= 1` and `--per-page` from 1 through 100. Media type
|
|
314
368
|
filters are `IMAGE`, `VIDEO`, `GIF`, `APPLICATION`, `DOCUMENT`, and `CSV`.
|
|
@@ -319,14 +373,16 @@ Uploads accept JPEG, PNG, BMP, MP4, MOV, or PDF files up to 100 MiB.
|
|
|
319
373
|
- Table-mode list requests print `OK <METHOD> <PATH>` plus formatted output
|
|
320
374
|
- JSON output mode prints only the JSON response body to stdout
|
|
321
375
|
- `--quiet` suppresses success banners while keeping the response output
|
|
322
|
-
- `--dry-run` prints the validated request without sending it
|
|
376
|
+
- `--dry-run` prints the validated mutation request without sending it; it is not supported for GET requests
|
|
323
377
|
- Failed requests print HTTP status and response payload when available
|
|
324
378
|
- Exit code is non-zero on failure
|
|
325
379
|
|
|
326
380
|
## Environment Variables
|
|
327
381
|
|
|
328
382
|
- `NUELINK_API_KEY`: API key fallback if not passed via CLI flag
|
|
329
|
-
- `NUELINK_BASE_URL`: Override API base URL
|
|
383
|
+
- `NUELINK_BASE_URL`: Override API base URL (Nuelink host or an exact trusted HTTPS host)
|
|
384
|
+
- `NUELINK_TRUSTED_HOSTS`: Comma-separated exact host allowlist for HTTPS API overrides you control; never include a production key for an untrusted host
|
|
385
|
+
- `NUELINK_ALLOW_INSECURE_HTTP=1`: Permit HTTP only for loopback development hosts
|
|
330
386
|
- `NUELINK_TIMEOUT_MS`: request timeout in milliseconds (default: `30000`)
|
|
331
387
|
|
|
332
388
|
Example:
|
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuelink/nuelink-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
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",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/
|
|
9
|
+
"url": "git+https://github.com/kreatinc/nuelink-cli.git"
|
|
10
10
|
},
|
|
11
|
-
"homepage": "https://github.com/
|
|
11
|
+
"homepage": "https://github.com/kreatinc/nuelink-cli#readme",
|
|
12
12
|
"bugs": {
|
|
13
|
-
"url": "https://github.com/
|
|
13
|
+
"url": "https://github.com/kreatinc/nuelink-cli/issues"
|
|
14
14
|
},
|
|
15
15
|
"type": "module",
|
|
16
16
|
"main": "./src/cli.js",
|
|
17
17
|
"scripts": {
|
|
18
18
|
"test": "node --test test/cli.test.mjs",
|
|
19
19
|
"smoke:auth": "node src/cli.js auth:status",
|
|
20
|
-
"check:pack": "
|
|
20
|
+
"check:pack": "node scripts/check-pack.mjs",
|
|
21
21
|
"check:pack:installed": "node scripts/check-packed-package.mjs"
|
|
22
22
|
},
|
|
23
23
|
"engines": {
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"test",
|
|
29
29
|
"CHANGELOG.md",
|
|
30
30
|
"README.md",
|
|
31
|
+
"CONTRIBUTING.md",
|
|
31
32
|
"SECURITY.md",
|
|
32
33
|
"LICENSE"
|
|
33
34
|
],
|
|
@@ -41,7 +42,6 @@
|
|
|
41
42
|
"automation"
|
|
42
43
|
],
|
|
43
44
|
"dependencies": {
|
|
44
|
-
"@nuelink/nuelink-cli": "^1.4.5",
|
|
45
45
|
"chalk": "^5.6.2",
|
|
46
46
|
"commander": "^13.1.0"
|
|
47
47
|
},
|
package/src/cli.js
CHANGED
|
@@ -28,7 +28,7 @@ const hasHelpFlag = parsedAuth.sanitizedArgs.includes("--help") || parsedAuth.sa
|
|
|
28
28
|
const hasVersionFlag = parsedAuth.sanitizedArgs.includes("--version") || parsedAuth.sanitizedArgs.includes("-V");
|
|
29
29
|
|
|
30
30
|
if (!argvHasCommand && !hasHelpFlag && !hasVersionFlag) {
|
|
31
|
-
if (runtimeApiKey) {
|
|
31
|
+
if (runtimeApiKey || jsonMode) {
|
|
32
32
|
printCliError(
|
|
33
33
|
new CliError("USAGE_ERROR", "Missing command. Provide a command such as 'me' or 'auth:login'."),
|
|
34
34
|
{ json: jsonMode },
|
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,
|
|
@@ -611,14 +716,47 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
611
716
|
});
|
|
612
717
|
}));
|
|
613
718
|
|
|
719
|
+
program
|
|
720
|
+
.command("posts:move")
|
|
721
|
+
.description("Move posts between collections in a brand")
|
|
722
|
+
.requiredOption("--brand-id <id>", "Brand ID")
|
|
723
|
+
.requiredOption("--source-collection-id <id>", "Source collection ID")
|
|
724
|
+
.requiredOption("--destination-collection-id <id>", "Destination collection ID")
|
|
725
|
+
.requiredOption("--post-ids <ids>", "Comma-separated post IDs (1-100)")
|
|
726
|
+
.action(withCommandErrorHandling(program, async (options) => {
|
|
727
|
+
const sourceCollectionId = parsePositiveInteger(options.sourceCollectionId, "source-collection-id");
|
|
728
|
+
const destinationCollectionId = parsePositiveInteger(options.destinationCollectionId, "destination-collection-id");
|
|
729
|
+
if (sourceCollectionId === destinationCollectionId) {
|
|
730
|
+
throw new Error("destination-collection-id must differ from source-collection-id.");
|
|
731
|
+
}
|
|
732
|
+
const postIds = splitCsv(options.postIds).map((id) => parsePositiveInteger(id, "post-ids"));
|
|
733
|
+
if (postIds.length === 0 || postIds.length > 100) {
|
|
734
|
+
throw new Error("post-ids must contain between 1 and 100 post IDs.");
|
|
735
|
+
}
|
|
736
|
+
if (new Set(postIds).size !== postIds.length) {
|
|
737
|
+
throw new Error("post-ids must not contain duplicates.");
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
await executeRequest(program, runtimeApiKey, {
|
|
741
|
+
method: "PATCH",
|
|
742
|
+
endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/posts/move`,
|
|
743
|
+
body: {
|
|
744
|
+
sourceCollectionId,
|
|
745
|
+
destinationCollectionId,
|
|
746
|
+
postIds,
|
|
747
|
+
},
|
|
748
|
+
});
|
|
749
|
+
}));
|
|
750
|
+
|
|
614
751
|
program
|
|
615
752
|
.command("posts:update")
|
|
616
|
-
.description("
|
|
753
|
+
.description("Edit a caption or change lifecycle of an unpublished non-poll post")
|
|
617
754
|
.requiredOption("--brand-id <id>", "Brand ID")
|
|
618
755
|
.requiredOption("--post-id <id>", "Post ID")
|
|
619
756
|
.option("--publish-mode <mode>", `Publish mode (${VALID_POST_UPDATE_MODES.join(", ")})`)
|
|
620
757
|
.option("--scheduled-at <value>", "Brand-local publish datetime (YYYY-MM-DD HH:mm:ss)")
|
|
621
758
|
.option("--queue-position <position>", `Queue position (${VALID_QUEUE_POSITIONS.join(", ")})`)
|
|
759
|
+
.option("--caption <text>", "Updated post caption (up to 3000 characters)")
|
|
622
760
|
.action(withCommandErrorHandling(program, async (options) => {
|
|
623
761
|
const publishMode = options.publishMode
|
|
624
762
|
? normalizeEnum(options.publishMode, "publish-mode", VALID_POST_UPDATE_MODES)
|
|
@@ -627,8 +765,9 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
627
765
|
? normalizeEnum(options.queuePosition, "queue-position", VALID_QUEUE_POSITIONS)
|
|
628
766
|
: undefined;
|
|
629
767
|
const scheduledAt = validatePostDateTime(options.scheduledAt, "scheduled-at");
|
|
630
|
-
|
|
631
|
-
|
|
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.");
|
|
632
771
|
}
|
|
633
772
|
if (publishMode === "SCHEDULE" && !scheduledAt) {
|
|
634
773
|
throw new Error("scheduled-at is required when publish-mode is SCHEDULE.");
|
|
@@ -644,6 +783,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
644
783
|
publishMode,
|
|
645
784
|
scheduledAt,
|
|
646
785
|
queuePosition,
|
|
786
|
+
caption,
|
|
647
787
|
},
|
|
648
788
|
});
|
|
649
789
|
}));
|
|
@@ -767,6 +907,12 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
767
907
|
.option("--youtube-playlists <json>", "YouTube playlists JSON string")
|
|
768
908
|
.option("--googlemybusiness-upload-to-photos-section <boolean>", "Upload to Google Business Profile photos: true/false")
|
|
769
909
|
.action(withCommandErrorHandling(program, async (options) => {
|
|
910
|
+
if (options.comment === undefined && options.commentDelay !== undefined) {
|
|
911
|
+
throw new Error("comment and comment-delay must be provided together.");
|
|
912
|
+
}
|
|
913
|
+
if (options.comment !== undefined && options.commentDelay === undefined) {
|
|
914
|
+
throw new Error("comment and comment-delay must be provided together.");
|
|
915
|
+
}
|
|
770
916
|
const payload = buildPostPayload(options);
|
|
771
917
|
|
|
772
918
|
await executeRequest(program, runtimeApiKey, {
|
package/src/http.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
+
import { isIP } from "node:net";
|
|
2
3
|
import chalk from "chalk";
|
|
3
4
|
import { CliError } from "./errors.js";
|
|
4
5
|
import { printApiResponse } from "./output.js";
|
|
@@ -8,6 +9,53 @@ const { version: cliVersion } = require("../package.json");
|
|
|
8
9
|
|
|
9
10
|
const DEFAULT_API_BASE_URL = "https://app.nuelink.com/api/public/v1";
|
|
10
11
|
|
|
12
|
+
function isLoopbackHostname(hostname) {
|
|
13
|
+
const normalized = hostname.toLowerCase().replace(/^\[|\]$/g, "");
|
|
14
|
+
if (normalized === "localhost" || normalized.endsWith(".localhost") || normalized === "::1") {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
const addressType = isIP(normalized);
|
|
18
|
+
if (addressType === 4) {
|
|
19
|
+
return Number(normalized.split(".")[0]) === 127;
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function validateApiBaseUrl(apiBaseUrl) {
|
|
25
|
+
let url;
|
|
26
|
+
try {
|
|
27
|
+
url = new URL(apiBaseUrl);
|
|
28
|
+
} catch {
|
|
29
|
+
throw new CliError("CONFIG_INVALID", "NUELINK_BASE_URL must be a valid absolute URL.");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (url.username || url.password || url.search || url.hash) {
|
|
33
|
+
throw new CliError("CONFIG_INVALID", "NUELINK_BASE_URL must not include credentials, a query, or a fragment.");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const trustedHosts = new Set([
|
|
37
|
+
"app.nuelink.com",
|
|
38
|
+
...(process.env.NUELINK_TRUSTED_HOSTS || "")
|
|
39
|
+
.split(",")
|
|
40
|
+
.map((host) => host.trim().toLowerCase())
|
|
41
|
+
.filter(Boolean),
|
|
42
|
+
]);
|
|
43
|
+
const loopback = isLoopbackHostname(url.hostname);
|
|
44
|
+
const allowInsecureLoopback = process.env.NUELINK_ALLOW_INSECURE_HTTP === "1";
|
|
45
|
+
|
|
46
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback && allowInsecureLoopback)) {
|
|
47
|
+
throw new CliError("CONFIG_INVALID", "NUELINK_BASE_URL must use HTTPS (HTTP is allowed only for loopback with NUELINK_ALLOW_INSECURE_HTTP=1).");
|
|
48
|
+
}
|
|
49
|
+
if (!loopback && !trustedHosts.has(url.host.toLowerCase())) {
|
|
50
|
+
throw new CliError(
|
|
51
|
+
"CONFIG_INVALID",
|
|
52
|
+
"NUELINK_BASE_URL host is not trusted. Add its exact host to NUELINK_TRUSTED_HOSTS only if you control that HTTPS endpoint.",
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return url;
|
|
57
|
+
}
|
|
58
|
+
|
|
11
59
|
function readIntegerEnvironment(name, fallback, { minimum = 0, maximum = 600000 } = {}) {
|
|
12
60
|
const raw = process.env[name];
|
|
13
61
|
if (raw === undefined || raw === "") return fallback;
|
|
@@ -54,11 +102,8 @@ function collectionPath(brandId, collectionId) {
|
|
|
54
102
|
}
|
|
55
103
|
|
|
56
104
|
function buildApiUrl(endpoint, apiBaseUrl) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
} catch {
|
|
60
|
-
throw new CliError("CONFIG_INVALID", "NUELINK_BASE_URL must be a valid absolute URL.");
|
|
61
|
-
}
|
|
105
|
+
const baseUrl = validateApiBaseUrl(apiBaseUrl);
|
|
106
|
+
return new URL(endpoint.replace(/^\//, ""), `${baseUrl.toString().replace(/\/?$/, "/")}`);
|
|
62
107
|
}
|
|
63
108
|
|
|
64
109
|
function shouldRetryRequest(method, statusCode, attempt, maxGetRetries) {
|
|
@@ -117,6 +162,9 @@ async function nuelinkRequest({ apiKey, method = "GET", endpoint, query, body, m
|
|
|
117
162
|
}
|
|
118
163
|
|
|
119
164
|
if (dryRun) {
|
|
165
|
+
if (method === "GET") {
|
|
166
|
+
throw new CliError("VALIDATION_ERROR", "--dry-run is only supported for API mutations; GET requests are not sent or previewed.");
|
|
167
|
+
}
|
|
120
168
|
printDryRun({ method, url, query, body, multipart, dryRunBody });
|
|
121
169
|
return { dryRun: true };
|
|
122
170
|
}
|
package/src/postPayload.js
CHANGED
|
@@ -83,7 +83,7 @@ function validateRawPostPayload(payload) {
|
|
|
83
83
|
if (payload.autoThreadText !== undefined && payload.autoThreadText !== null && typeof payload.autoThreadText !== "boolean") {
|
|
84
84
|
throw new Error("Invalid autoThreadText. Expected a boolean or null.");
|
|
85
85
|
}
|
|
86
|
-
if (payload.link !== undefined) {
|
|
86
|
+
if (payload.link !== undefined && payload.link !== null) {
|
|
87
87
|
validateHttpUrl(payload.link, "link");
|
|
88
88
|
}
|
|
89
89
|
|
|
@@ -92,8 +92,10 @@ function validateRawPostPayload(payload) {
|
|
|
92
92
|
? validateRequiredString(payload.caption, 3000, "caption")
|
|
93
93
|
: payload.caption === undefined
|
|
94
94
|
? undefined
|
|
95
|
-
:
|
|
96
|
-
|
|
95
|
+
: payload.caption === null
|
|
96
|
+
? null
|
|
97
|
+
: String(payload.caption).trim();
|
|
98
|
+
if (poll !== undefined && poll !== null) {
|
|
97
99
|
if (!poll || typeof poll !== "object" || Array.isArray(poll)) {
|
|
98
100
|
throw new Error("Invalid poll. Expected a JSON object.");
|
|
99
101
|
}
|
|
@@ -107,7 +109,7 @@ function validateRawPostPayload(payload) {
|
|
|
107
109
|
options.forEach((option) => validateOptionalLength(option, 30, "poll-option"));
|
|
108
110
|
}
|
|
109
111
|
|
|
110
|
-
if (payload.media !== undefined) {
|
|
112
|
+
if (payload.media !== undefined && payload.media !== null) {
|
|
111
113
|
if (!Array.isArray(payload.media)) {
|
|
112
114
|
throw new Error("Invalid media. Expected an array.");
|
|
113
115
|
}
|
|
@@ -130,7 +132,9 @@ function validateRawPostPayload(payload) {
|
|
|
130
132
|
...payload,
|
|
131
133
|
...(payload.caption !== undefined ? { caption } : {}),
|
|
132
134
|
publishMode,
|
|
133
|
-
...(payload.scheduledAt !== undefined
|
|
135
|
+
...(payload.scheduledAt !== undefined
|
|
136
|
+
? { scheduledAt: payload.scheduledAt === null ? null : scheduledAt }
|
|
137
|
+
: {}),
|
|
134
138
|
};
|
|
135
139
|
}
|
|
136
140
|
|
|
@@ -158,6 +162,12 @@ function buildPostPayload(options) {
|
|
|
158
162
|
if (options.pollPeriod && !VALID_POLL_PERIODS.includes(options.pollPeriod)) {
|
|
159
163
|
throw new Error(`Invalid poll-period. Expected one of: ${VALID_POLL_PERIODS.join(", ")}.`);
|
|
160
164
|
}
|
|
165
|
+
if ((options.comment === undefined) !== (options.commentDelay === undefined)) {
|
|
166
|
+
throw new Error("comment and comment-delay must be provided together.");
|
|
167
|
+
}
|
|
168
|
+
if (options.comment !== undefined) {
|
|
169
|
+
validateRequiredString(options.comment, 1000, "comment");
|
|
170
|
+
}
|
|
161
171
|
if (options.instagramTrialReel && !VALID_TRIAL_REEL_MODES.includes(options.instagramTrialReel)) {
|
|
162
172
|
throw new Error(`Invalid instagram-trial-reel. Expected one of: ${VALID_TRIAL_REEL_MODES.join(", ")}.`);
|
|
163
173
|
}
|
package/test/cli.test.mjs
CHANGED
|
@@ -158,7 +158,7 @@ test("posts command supports all documented filter parameters", async () => {
|
|
|
158
158
|
const result = runCli({
|
|
159
159
|
args: [
|
|
160
160
|
"posts", "--brand-id", "13493", "--collection-id", "33273",
|
|
161
|
-
"--status", "pending", "--post-type", "image", "--posting-type", "schedule",
|
|
161
|
+
"--view", "queue", "--status", "pending", "--post-type", "image", "--posting-type", "schedule",
|
|
162
162
|
"--created-from", "2026-10-01 00:00:00", "--created-to", "2026-10-31 23:59:59",
|
|
163
163
|
"--sort-by", "post_date", "--sort-order", "ASC",
|
|
164
164
|
],
|
|
@@ -168,6 +168,7 @@ test("posts command supports all documented filter parameters", async () => {
|
|
|
168
168
|
|
|
169
169
|
assert.equal(result.status, 0, result.stderr);
|
|
170
170
|
const url = new URL(JSON.parse(await readFile(capturePath, "utf8")).url);
|
|
171
|
+
assert.equal(url.searchParams.get("view"), "QUEUE");
|
|
171
172
|
assert.equal(url.searchParams.get("status"), "PENDING");
|
|
172
173
|
assert.equal(url.searchParams.get("post_type"), "IMAGE");
|
|
173
174
|
assert.equal(url.searchParams.get("posting_type"), "SCHEDULE");
|
|
@@ -284,6 +285,7 @@ test("quiet mode suppresses success banner", async () => {
|
|
|
284
285
|
|
|
285
286
|
test("version flags print package version", async () => {
|
|
286
287
|
const homeDir = await setupTempHome();
|
|
288
|
+
const packageManifest = JSON.parse(await readFile(path.join(workspaceRoot, "package.json"), "utf8"));
|
|
287
289
|
|
|
288
290
|
for (const flag of ["--version", "-V"]) {
|
|
289
291
|
const result = runCli({
|
|
@@ -294,7 +296,7 @@ test("version flags print package version", async () => {
|
|
|
294
296
|
});
|
|
295
297
|
|
|
296
298
|
assert.equal(result.status, 0, result.stderr);
|
|
297
|
-
assert.equal(result.stdout.trim(),
|
|
299
|
+
assert.equal(result.stdout.trim(), packageManifest.version);
|
|
298
300
|
assert.equal(result.stderr, "");
|
|
299
301
|
}
|
|
300
302
|
});
|
|
@@ -607,6 +609,54 @@ test("posts:add-json can read payload from stdin", async () => {
|
|
|
607
609
|
assert.equal(capture.body.publishMode, "DRAFT");
|
|
608
610
|
});
|
|
609
611
|
|
|
612
|
+
test("posts:add-json preserves nullable contract fields for dry-run and request bodies", async () => {
|
|
613
|
+
const homeDir = await setupTempHome();
|
|
614
|
+
const payloadPath = path.join(homeDir, "nullable-payload.json");
|
|
615
|
+
const payloads = [
|
|
616
|
+
{
|
|
617
|
+
title: null,
|
|
618
|
+
caption: null,
|
|
619
|
+
poll: { question: "Question?", options: ["One", "Two"], period: "1d" },
|
|
620
|
+
alt: null,
|
|
621
|
+
link: null,
|
|
622
|
+
publishMode: "DRAFT",
|
|
623
|
+
scheduledAt: null,
|
|
624
|
+
media: null,
|
|
625
|
+
postAsStory: null,
|
|
626
|
+
autoThreadText: null,
|
|
627
|
+
comment: null,
|
|
628
|
+
},
|
|
629
|
+
{
|
|
630
|
+
caption: "Caption with a nullable poll",
|
|
631
|
+
poll: null,
|
|
632
|
+
publishMode: "DRAFT",
|
|
633
|
+
},
|
|
634
|
+
];
|
|
635
|
+
|
|
636
|
+
for (const [index, payload] of payloads.entries()) {
|
|
637
|
+
await writeFile(payloadPath, JSON.stringify(payload), "utf8");
|
|
638
|
+
const dryRun = runCli({
|
|
639
|
+
args: ["--dry-run", "posts:add-json", "--brand-id", "10", "--collection-id", "20", "--payload", payloadPath],
|
|
640
|
+
homeDir,
|
|
641
|
+
capturePath: path.join(homeDir, `capture-null-dry-run-${index}.json`),
|
|
642
|
+
extraEnv: { NUELINK_API_KEY: "" },
|
|
643
|
+
});
|
|
644
|
+
assert.equal(dryRun.status, 0, dryRun.stderr);
|
|
645
|
+
assert.deepEqual(JSON.parse(dryRun.stdout).body, payload);
|
|
646
|
+
|
|
647
|
+
const capturePath = path.join(homeDir, `capture-null-live-${index}.json`);
|
|
648
|
+
const live = runCli({
|
|
649
|
+
args: ["posts:add-json", "--brand-id", "10", "--collection-id", "20", "--payload", payloadPath],
|
|
650
|
+
homeDir,
|
|
651
|
+
capturePath,
|
|
652
|
+
});
|
|
653
|
+
assert.equal(live.status, 0, live.stderr);
|
|
654
|
+
const capture = JSON.parse(await readFile(capturePath, "utf8"));
|
|
655
|
+
assert.deepEqual(capture.body, payload);
|
|
656
|
+
assert.deepEqual(capture.body, JSON.parse(dryRun.stdout).body);
|
|
657
|
+
}
|
|
658
|
+
});
|
|
659
|
+
|
|
610
660
|
test("posts:add-json rejects invalid JSON payloads", async () => {
|
|
611
661
|
const homeDir = await setupTempHome();
|
|
612
662
|
|
|
@@ -695,6 +745,67 @@ test("dry-run prints validated request without sending", async () => {
|
|
|
695
745
|
await assert.rejects(readFile(capturePath, "utf8"));
|
|
696
746
|
});
|
|
697
747
|
|
|
748
|
+
test("new public API management commands build the documented requests", async () => {
|
|
749
|
+
const cases = [
|
|
750
|
+
{
|
|
751
|
+
args: ["automations:update-status", "--brand-id", "42", "--automation-id", "15", "--status", "paused"],
|
|
752
|
+
method: "PATCH",
|
|
753
|
+
pathname: "/api/public/v1/brands/42/automations/15",
|
|
754
|
+
body: { status: "PAUSED" },
|
|
755
|
+
},
|
|
756
|
+
{
|
|
757
|
+
args: ["collections:update", "--brand-id", "42", "--collection-id", "77", "--status", "paused"],
|
|
758
|
+
method: "PATCH",
|
|
759
|
+
pathname: "/api/public/v1/brands/42/collections/77",
|
|
760
|
+
body: { status: "PAUSED" },
|
|
761
|
+
},
|
|
762
|
+
{
|
|
763
|
+
args: ["collections:update", "--brand-id", "42", "--collection-id", "77", "--clear-description"],
|
|
764
|
+
method: "PATCH",
|
|
765
|
+
pathname: "/api/public/v1/brands/42/collections/77",
|
|
766
|
+
body: { description: null },
|
|
767
|
+
},
|
|
768
|
+
{
|
|
769
|
+
args: ["collections:add-channel", "--brand-id", "42", "--collection-id", "77", "--channel-id", "501"],
|
|
770
|
+
method: "POST",
|
|
771
|
+
pathname: "/api/public/v1/brands/42/collections/77/channels",
|
|
772
|
+
body: { channelId: 501 },
|
|
773
|
+
},
|
|
774
|
+
{
|
|
775
|
+
args: ["collections:remove-channel", "--brand-id", "42", "--collection-id", "77", "--channel-id", "501"],
|
|
776
|
+
method: "DELETE",
|
|
777
|
+
pathname: "/api/public/v1/brands/42/collections/77/channels/501",
|
|
778
|
+
},
|
|
779
|
+
{
|
|
780
|
+
args: ["collections:add-queue", "--brand-id", "42", "--collection-id", "77", "--date", "Mon 09:30"],
|
|
781
|
+
method: "POST",
|
|
782
|
+
pathname: "/api/public/v1/brands/42/collections/77/queues",
|
|
783
|
+
body: { date: "Mon 09:30" },
|
|
784
|
+
},
|
|
785
|
+
{
|
|
786
|
+
args: ["collections:delete-queue", "--brand-id", "42", "--collection-id", "77", "--queue-id", "911"],
|
|
787
|
+
method: "DELETE",
|
|
788
|
+
pathname: "/api/public/v1/brands/42/collections/77/queues/911",
|
|
789
|
+
},
|
|
790
|
+
];
|
|
791
|
+
|
|
792
|
+
for (const [index, expected] of cases.entries()) {
|
|
793
|
+
const homeDir = await setupTempHome();
|
|
794
|
+
const result = runCli({
|
|
795
|
+
args: ["--dry-run", ...expected.args],
|
|
796
|
+
homeDir,
|
|
797
|
+
capturePath: path.join(homeDir, `capture-management-${index}.json`),
|
|
798
|
+
extraEnv: { NUELINK_API_KEY: "" },
|
|
799
|
+
});
|
|
800
|
+
assert.equal(result.status, 0, result.stderr);
|
|
801
|
+
const output = JSON.parse(result.stdout);
|
|
802
|
+
assert.equal(output.dryRun, true);
|
|
803
|
+
assert.equal(output.method, expected.method);
|
|
804
|
+
assert.equal(new URL(output.url).pathname, expected.pathname);
|
|
805
|
+
if (expected.body) assert.deepEqual(output.body, expected.body);
|
|
806
|
+
}
|
|
807
|
+
});
|
|
808
|
+
|
|
698
809
|
test("posts:create builds full payload from options", async () => {
|
|
699
810
|
const homeDir = await setupTempHome();
|
|
700
811
|
const capturePath = path.join(homeDir, "capture-posts-create.json");
|
|
@@ -1073,6 +1184,60 @@ test("posts:update builds the documented patch payload", async () => {
|
|
|
1073
1184
|
});
|
|
1074
1185
|
});
|
|
1075
1186
|
|
|
1187
|
+
test("posts:update can edit a caption without changing its lifecycle state", async () => {
|
|
1188
|
+
const homeDir = await setupTempHome();
|
|
1189
|
+
const capturePath = path.join(homeDir, "capture-post-caption-update.json");
|
|
1190
|
+
const result = runCli({
|
|
1191
|
+
args: ["posts:update", "--brand-id", "42", "--post-id", "8801", "--caption", "Updated launch announcement."],
|
|
1192
|
+
homeDir,
|
|
1193
|
+
capturePath,
|
|
1194
|
+
});
|
|
1195
|
+
|
|
1196
|
+
assert.equal(result.status, 0, result.stderr);
|
|
1197
|
+
const capture = JSON.parse(await readFile(capturePath, "utf8"));
|
|
1198
|
+
assert.equal(capture.method, "PATCH");
|
|
1199
|
+
assert.equal(new URL(capture.url).pathname, "/api/public/v1/brands/42/posts/8801");
|
|
1200
|
+
assert.deepEqual(capture.body, { caption: "Updated launch announcement." });
|
|
1201
|
+
});
|
|
1202
|
+
|
|
1203
|
+
test("posts:move builds the documented atomic move payload", async () => {
|
|
1204
|
+
const homeDir = await setupTempHome();
|
|
1205
|
+
const capturePath = path.join(homeDir, "capture-post-move.json");
|
|
1206
|
+
const result = runCli({
|
|
1207
|
+
args: [
|
|
1208
|
+
"posts:move", "--brand-id", "42", "--source-collection-id", "77",
|
|
1209
|
+
"--destination-collection-id", "81", "--post-ids", "8801,8802",
|
|
1210
|
+
],
|
|
1211
|
+
homeDir,
|
|
1212
|
+
capturePath,
|
|
1213
|
+
});
|
|
1214
|
+
|
|
1215
|
+
assert.equal(result.status, 0, result.stderr);
|
|
1216
|
+
const capture = JSON.parse(await readFile(capturePath, "utf8"));
|
|
1217
|
+
assert.equal(capture.method, "PATCH");
|
|
1218
|
+
assert.equal(new URL(capture.url).pathname, "/api/public/v1/brands/42/posts/move");
|
|
1219
|
+
assert.deepEqual(capture.body, {
|
|
1220
|
+
sourceCollectionId: 77,
|
|
1221
|
+
destinationCollectionId: 81,
|
|
1222
|
+
postIds: [8801, 8802],
|
|
1223
|
+
});
|
|
1224
|
+
});
|
|
1225
|
+
|
|
1226
|
+
test("posts:move rejects the same source and destination collection", async () => {
|
|
1227
|
+
const homeDir = await setupTempHome();
|
|
1228
|
+
const result = runCli({
|
|
1229
|
+
args: [
|
|
1230
|
+
"posts:move", "--brand-id", "42", "--source-collection-id", "77",
|
|
1231
|
+
"--destination-collection-id", "77", "--post-ids", "8801",
|
|
1232
|
+
],
|
|
1233
|
+
homeDir,
|
|
1234
|
+
capturePath: path.join(homeDir, "capture-invalid-post-move.json"),
|
|
1235
|
+
});
|
|
1236
|
+
|
|
1237
|
+
assert.equal(result.status, 1);
|
|
1238
|
+
assert.match(result.stderr, /destination-collection-id must differ from source-collection-id/);
|
|
1239
|
+
});
|
|
1240
|
+
|
|
1076
1241
|
test("posts:update requires an update operation", async () => {
|
|
1077
1242
|
const homeDir = await setupTempHome();
|
|
1078
1243
|
const result = runCli({
|
|
@@ -1082,7 +1247,7 @@ test("posts:update requires an update operation", async () => {
|
|
|
1082
1247
|
});
|
|
1083
1248
|
|
|
1084
1249
|
assert.equal(result.status, 1);
|
|
1085
|
-
assert.match(result.stderr, /At least one of publish-mode or queue-position is required/);
|
|
1250
|
+
assert.match(result.stderr, /At least one of caption, publish-mode, or queue-position is required/);
|
|
1086
1251
|
});
|
|
1087
1252
|
|
|
1088
1253
|
test("posts:delete targets the sensitive delete endpoint", async () => {
|
|
@@ -1132,6 +1297,7 @@ test("base url can be overridden for testing", async () => {
|
|
|
1132
1297
|
capturePath,
|
|
1133
1298
|
extraEnv: {
|
|
1134
1299
|
NUELINK_BASE_URL: "https://example.test/custom/v1",
|
|
1300
|
+
NUELINK_TRUSTED_HOSTS: "example.test",
|
|
1135
1301
|
},
|
|
1136
1302
|
});
|
|
1137
1303
|
|
|
@@ -1142,6 +1308,77 @@ test("base url can be overridden for testing", async () => {
|
|
|
1142
1308
|
assert.equal(new URL(capture.url).pathname, "/custom/v1/brands");
|
|
1143
1309
|
});
|
|
1144
1310
|
|
|
1311
|
+
for (const [name, baseUrl, extraEnv] of [
|
|
1312
|
+
["rejects plaintext remote base URLs before authentication", "http://api.example.test/v1", {}],
|
|
1313
|
+
["rejects untrusted HTTPS base URLs before authentication", "https://attacker.example.test/v1", {}],
|
|
1314
|
+
["rejects URL credentials in the base URL", "https://user:secret@app.nuelink.com/api/public/v1", {}],
|
|
1315
|
+
]) {
|
|
1316
|
+
test(name, async () => {
|
|
1317
|
+
const homeDir = await setupTempHome();
|
|
1318
|
+
const capturePath = path.join(homeDir, "capture-rejected-base-url.json");
|
|
1319
|
+
const result = runCli({
|
|
1320
|
+
args: ["--json", "brands"],
|
|
1321
|
+
homeDir,
|
|
1322
|
+
capturePath,
|
|
1323
|
+
extraEnv: { NUELINK_API_KEY: "", NUELINK_BASE_URL: baseUrl, ...extraEnv },
|
|
1324
|
+
});
|
|
1325
|
+
const error = assertJsonError(result, "CONFIG_INVALID");
|
|
1326
|
+
assert.match(error.message, /NUELINK_BASE_URL/);
|
|
1327
|
+
await assert.rejects(readFile(capturePath, "utf8"));
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
test("allows loopback HTTP only with explicit opt-in", async () => {
|
|
1332
|
+
const homeDir = await setupTempHome();
|
|
1333
|
+
const capturePath = path.join(homeDir, "capture-loopback-base-url.json");
|
|
1334
|
+
const result = runCli({
|
|
1335
|
+
args: ["brands"],
|
|
1336
|
+
homeDir,
|
|
1337
|
+
capturePath,
|
|
1338
|
+
extraEnv: {
|
|
1339
|
+
NUELINK_BASE_URL: "http://127.0.0.1:8787/api/public/v1",
|
|
1340
|
+
NUELINK_ALLOW_INSECURE_HTTP: "1",
|
|
1341
|
+
},
|
|
1342
|
+
});
|
|
1343
|
+
assert.equal(result.status, 0, result.stderr);
|
|
1344
|
+
const capture = JSON.parse(await readFile(capturePath, "utf8"));
|
|
1345
|
+
assert.equal(new URL(capture.url).origin, "http://127.0.0.1:8787");
|
|
1346
|
+
});
|
|
1347
|
+
|
|
1348
|
+
test("posts:create requires comment and comment-delay as a pair", async () => {
|
|
1349
|
+
const homeDir = await setupTempHome();
|
|
1350
|
+
for (const args of [
|
|
1351
|
+
["posts:create", "--brand-id", "1", "--collection-id", "2", "--comment-delay", "30", "--dry-run"],
|
|
1352
|
+
["posts:create", "--brand-id", "1", "--collection-id", "2", "--comment", "First comment", "--dry-run"],
|
|
1353
|
+
]) {
|
|
1354
|
+
const capturePath = path.join(homeDir, `capture-comment-${args.includes("--comment-delay") ? "delay" : "text"}.json`);
|
|
1355
|
+
const result = runCli({ args, homeDir, capturePath });
|
|
1356
|
+
assert.equal(result.status, 1);
|
|
1357
|
+
assert.match(result.stderr, /comment and comment-delay must be provided together/);
|
|
1358
|
+
await assert.rejects(readFile(capturePath, "utf8"));
|
|
1359
|
+
}
|
|
1360
|
+
});
|
|
1361
|
+
|
|
1362
|
+
test("JSON mode without a command returns a structured usage error", async () => {
|
|
1363
|
+
const homeDir = await setupTempHome();
|
|
1364
|
+
const result = runCli({
|
|
1365
|
+
args: ["--json"],
|
|
1366
|
+
homeDir,
|
|
1367
|
+
capturePath: path.join(homeDir, "capture-json-no-command.json"),
|
|
1368
|
+
extraEnv: { NUELINK_API_KEY: "" },
|
|
1369
|
+
});
|
|
1370
|
+
assertJsonError(result, "USAGE_ERROR");
|
|
1371
|
+
});
|
|
1372
|
+
|
|
1373
|
+
test("GET requests reject dry-run instead of silently suppressing the read", async () => {
|
|
1374
|
+
const homeDir = await setupTempHome();
|
|
1375
|
+
const capturePath = path.join(homeDir, "capture-get-dry-run.json");
|
|
1376
|
+
const result = runCli({ args: ["--dry-run", "brands"], homeDir, capturePath });
|
|
1377
|
+
assert.equal(result.status, 1);
|
|
1378
|
+
assert.match(result.stderr, /--dry-run is only supported for API mutations/);
|
|
1379
|
+
await assert.rejects(readFile(capturePath, "utf8"));
|
|
1380
|
+
});
|
|
1381
|
+
|
|
1145
1382
|
test("get requests retry on 429 and then succeed", async () => {
|
|
1146
1383
|
const homeDir = await setupTempHome();
|
|
1147
1384
|
const capturePath = path.join(homeDir, "capture-retry.json");
|