@nuelink/nuelink-cli 1.4.5 → 1.5.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 +20 -13
- package/CONTRIBUTING.md +123 -0
- package/README.md +38 -5
- package/package.json +6 -6
- package/src/cli.js +1 -1
- package/src/commands.js +38 -0
- package/src/http.js +53 -5
- package/src/postPayload.js +15 -5
- package/test/cli.test.mjs +159 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## 1.
|
|
4
|
-
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
|
|
10
|
-
## 1.4.
|
|
11
|
-
|
|
12
|
-
-
|
|
13
|
-
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.5.0
|
|
4
|
+
|
|
5
|
+
- Preserve nullable post fields in `posts:add-json` and keep dry-run bodies aligned with sent requests.
|
|
6
|
+
- Restrict API base URLs to Nuelink or explicitly trusted HTTPS hosts; allow HTTP only for opted-in loopback development.
|
|
7
|
+
- Require delayed-comment text and delay together, reject GET dry-runs, and make no-command JSON errors machine-readable.
|
|
8
|
+
- Remove the package self-dependency and correct repository/package contents metadata.
|
|
9
|
+
|
|
10
|
+
## 1.4.1 - 2026-08-18
|
|
11
|
+
|
|
12
|
+
- Emit structured machine-readable errors when `--json` is enabled.
|
|
13
|
+
- Reject blank required mutation fields and invalid runtime configuration.
|
|
14
|
+
- Harden saved credential writes and avoid reading media during dry runs.
|
|
15
|
+
- Include tests, security guidance, license, and repository metadata in the npm package.
|
|
16
|
+
|
|
17
|
+
## 1.4.0
|
|
18
|
+
|
|
19
|
+
- Add dry-run mutation previews, stricter request validation, retries, timeouts,
|
|
20
|
+
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
|
@@ -246,6 +246,8 @@ nuelink-cli posts:add-json --brand-id 13493 --collection-id 33273 --payload ./po
|
|
|
246
246
|
```
|
|
247
247
|
|
|
248
248
|
You can also pipe JSON through stdin with `--payload -`.
|
|
249
|
+
CLI 1.5.0 preserves contract-nullable fields exactly; the dry-run body matches
|
|
250
|
+
the JSON body sent by the request.
|
|
249
251
|
|
|
250
252
|
Example `post.json`:
|
|
251
253
|
|
|
@@ -294,7 +296,10 @@ nuelink-cli posts:create \
|
|
|
294
296
|
```
|
|
295
297
|
|
|
296
298
|
Review each mutation preview, then repeat the same command without `--dry-run`
|
|
297
|
-
only when you intend to send it.
|
|
299
|
+
only when you intend to send it. `--dry-run` is supported for mutations; GET
|
|
300
|
+
commands reject it instead of silently suppressing the read. Post creation and
|
|
301
|
+
update schedule values are brand-local and must be at least 10 minutes ahead;
|
|
302
|
+
date filters and returned `postDate` values are UTC.
|
|
298
303
|
|
|
299
304
|
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
305
|
|
|
@@ -302,13 +307,39 @@ Preview a post lifecycle update or sensitive deletion before executing it:
|
|
|
302
307
|
|
|
303
308
|
```bash
|
|
304
309
|
nuelink-cli posts:update --brand-id 13493 --post-id 8801 \
|
|
305
|
-
--publish-mode SCHEDULE --scheduled-at "
|
|
310
|
+
--publish-mode SCHEDULE --scheduled-at "BRAND_LOCAL_YYYY-MM-DD_HH:mm:ss" --dry-run
|
|
306
311
|
nuelink-cli posts:update --brand-id 13493 --post-id 8801 \
|
|
307
312
|
--queue-position FRONT --dry-run
|
|
313
|
+
nuelink-cli posts:move --brand-id 13493 --source-collection-id 33273 \
|
|
314
|
+
--destination-collection-id 33274 --post-ids "8801,8802" --dry-run
|
|
308
315
|
nuelink-cli posts:delete --brand-id 13493 --post-id 8801 --dry-run
|
|
309
316
|
```
|
|
310
317
|
|
|
311
|
-
Deletion is permanent and the API rejects it unless sensitive AI actions are enabled for the account.
|
|
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.
|
|
319
|
+
|
|
320
|
+
Published-post results are returned unchanged in `--json` mode. Each per-channel
|
|
321
|
+
record includes `likes`, `comments`, `shares`, `views`, `saves`, `engagement`,
|
|
322
|
+
`clicks`, `impressions`, and `reach` under `results`:
|
|
323
|
+
|
|
324
|
+
```json
|
|
325
|
+
{
|
|
326
|
+
"id": 120045,
|
|
327
|
+
"postId": 8801,
|
|
328
|
+
"collectionId": 33273,
|
|
329
|
+
"channel": { "id": 501, "name": "Acme on LinkedIn", "type": "LinkedIn" },
|
|
330
|
+
"postType": "IMAGE",
|
|
331
|
+
"body": "Our new product is live.",
|
|
332
|
+
"url": "https://www.linkedin.com/feed/update/urn:li:share:123",
|
|
333
|
+
"status": "PUBLISHED",
|
|
334
|
+
"message": null,
|
|
335
|
+
"publishedAt": "2026-10-10T14:00:00.000000Z",
|
|
336
|
+
"results": {
|
|
337
|
+
"likes": 42, "comments": 5, "shares": 3, "views": 1200,
|
|
338
|
+
"saves": 18, "engagement": 68, "clicks": 27,
|
|
339
|
+
"impressions": 1540, "reach": 1310
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
```
|
|
312
343
|
|
|
313
344
|
Pagination uses `--page >= 1` and `--per-page` from 1 through 100. Media type
|
|
314
345
|
filters are `IMAGE`, `VIDEO`, `GIF`, `APPLICATION`, `DOCUMENT`, and `CSV`.
|
|
@@ -319,14 +350,16 @@ Uploads accept JPEG, PNG, BMP, MP4, MOV, or PDF files up to 100 MiB.
|
|
|
319
350
|
- Table-mode list requests print `OK <METHOD> <PATH>` plus formatted output
|
|
320
351
|
- JSON output mode prints only the JSON response body to stdout
|
|
321
352
|
- `--quiet` suppresses success banners while keeping the response output
|
|
322
|
-
- `--dry-run` prints the validated request without sending it
|
|
353
|
+
- `--dry-run` prints the validated mutation request without sending it; it is not supported for GET requests
|
|
323
354
|
- Failed requests print HTTP status and response payload when available
|
|
324
355
|
- Exit code is non-zero on failure
|
|
325
356
|
|
|
326
357
|
## Environment Variables
|
|
327
358
|
|
|
328
359
|
- `NUELINK_API_KEY`: API key fallback if not passed via CLI flag
|
|
329
|
-
- `NUELINK_BASE_URL`: Override API base URL
|
|
360
|
+
- `NUELINK_BASE_URL`: Override API base URL (Nuelink host or an exact trusted HTTPS host)
|
|
361
|
+
- `NUELINK_TRUSTED_HOSTS`: Comma-separated exact host allowlist for HTTPS API overrides you control; never include a production key for an untrusted host
|
|
362
|
+
- `NUELINK_ALLOW_INSECURE_HTTP=1`: Permit HTTP only for loopback development hosts
|
|
330
363
|
- `NUELINK_TIMEOUT_MS`: request timeout in milliseconds (default: `30000`)
|
|
331
364
|
|
|
332
365
|
Example:
|
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuelink/nuelink-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.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
|
@@ -611,6 +611,38 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
611
611
|
});
|
|
612
612
|
}));
|
|
613
613
|
|
|
614
|
+
program
|
|
615
|
+
.command("posts:move")
|
|
616
|
+
.description("Move posts between collections in a brand")
|
|
617
|
+
.requiredOption("--brand-id <id>", "Brand ID")
|
|
618
|
+
.requiredOption("--source-collection-id <id>", "Source collection ID")
|
|
619
|
+
.requiredOption("--destination-collection-id <id>", "Destination collection ID")
|
|
620
|
+
.requiredOption("--post-ids <ids>", "Comma-separated post IDs (1-100)")
|
|
621
|
+
.action(withCommandErrorHandling(program, async (options) => {
|
|
622
|
+
const sourceCollectionId = parsePositiveInteger(options.sourceCollectionId, "source-collection-id");
|
|
623
|
+
const destinationCollectionId = parsePositiveInteger(options.destinationCollectionId, "destination-collection-id");
|
|
624
|
+
if (sourceCollectionId === destinationCollectionId) {
|
|
625
|
+
throw new Error("destination-collection-id must differ from source-collection-id.");
|
|
626
|
+
}
|
|
627
|
+
const postIds = splitCsv(options.postIds).map((id) => parsePositiveInteger(id, "post-ids"));
|
|
628
|
+
if (postIds.length === 0 || postIds.length > 100) {
|
|
629
|
+
throw new Error("post-ids must contain between 1 and 100 post IDs.");
|
|
630
|
+
}
|
|
631
|
+
if (new Set(postIds).size !== postIds.length) {
|
|
632
|
+
throw new Error("post-ids must not contain duplicates.");
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
await executeRequest(program, runtimeApiKey, {
|
|
636
|
+
method: "PATCH",
|
|
637
|
+
endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/posts/move`,
|
|
638
|
+
body: {
|
|
639
|
+
sourceCollectionId,
|
|
640
|
+
destinationCollectionId,
|
|
641
|
+
postIds,
|
|
642
|
+
},
|
|
643
|
+
});
|
|
644
|
+
}));
|
|
645
|
+
|
|
614
646
|
program
|
|
615
647
|
.command("posts:update")
|
|
616
648
|
.description("Reschedule, re-queue, draft, or reposition a post")
|
|
@@ -767,6 +799,12 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
767
799
|
.option("--youtube-playlists <json>", "YouTube playlists JSON string")
|
|
768
800
|
.option("--googlemybusiness-upload-to-photos-section <boolean>", "Upload to Google Business Profile photos: true/false")
|
|
769
801
|
.action(withCommandErrorHandling(program, async (options) => {
|
|
802
|
+
if (options.comment === undefined && options.commentDelay !== undefined) {
|
|
803
|
+
throw new Error("comment and comment-delay must be provided together.");
|
|
804
|
+
}
|
|
805
|
+
if (options.comment !== undefined && options.commentDelay === undefined) {
|
|
806
|
+
throw new Error("comment and comment-delay must be provided together.");
|
|
807
|
+
}
|
|
770
808
|
const payload = buildPostPayload(options);
|
|
771
809
|
|
|
772
810
|
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
|
@@ -294,7 +294,7 @@ test("version flags print package version", async () => {
|
|
|
294
294
|
});
|
|
295
295
|
|
|
296
296
|
assert.equal(result.status, 0, result.stderr);
|
|
297
|
-
assert.equal(result.stdout.trim(), "1.
|
|
297
|
+
assert.equal(result.stdout.trim(), "1.5.0");
|
|
298
298
|
assert.equal(result.stderr, "");
|
|
299
299
|
}
|
|
300
300
|
});
|
|
@@ -607,6 +607,54 @@ test("posts:add-json can read payload from stdin", async () => {
|
|
|
607
607
|
assert.equal(capture.body.publishMode, "DRAFT");
|
|
608
608
|
});
|
|
609
609
|
|
|
610
|
+
test("posts:add-json preserves nullable contract fields for dry-run and request bodies", async () => {
|
|
611
|
+
const homeDir = await setupTempHome();
|
|
612
|
+
const payloadPath = path.join(homeDir, "nullable-payload.json");
|
|
613
|
+
const payloads = [
|
|
614
|
+
{
|
|
615
|
+
title: null,
|
|
616
|
+
caption: null,
|
|
617
|
+
poll: { question: "Question?", options: ["One", "Two"], period: "1d" },
|
|
618
|
+
alt: null,
|
|
619
|
+
link: null,
|
|
620
|
+
publishMode: "DRAFT",
|
|
621
|
+
scheduledAt: null,
|
|
622
|
+
media: null,
|
|
623
|
+
postAsStory: null,
|
|
624
|
+
autoThreadText: null,
|
|
625
|
+
comment: null,
|
|
626
|
+
},
|
|
627
|
+
{
|
|
628
|
+
caption: "Caption with a nullable poll",
|
|
629
|
+
poll: null,
|
|
630
|
+
publishMode: "DRAFT",
|
|
631
|
+
},
|
|
632
|
+
];
|
|
633
|
+
|
|
634
|
+
for (const [index, payload] of payloads.entries()) {
|
|
635
|
+
await writeFile(payloadPath, JSON.stringify(payload), "utf8");
|
|
636
|
+
const dryRun = runCli({
|
|
637
|
+
args: ["--dry-run", "posts:add-json", "--brand-id", "10", "--collection-id", "20", "--payload", payloadPath],
|
|
638
|
+
homeDir,
|
|
639
|
+
capturePath: path.join(homeDir, `capture-null-dry-run-${index}.json`),
|
|
640
|
+
extraEnv: { NUELINK_API_KEY: "" },
|
|
641
|
+
});
|
|
642
|
+
assert.equal(dryRun.status, 0, dryRun.stderr);
|
|
643
|
+
assert.deepEqual(JSON.parse(dryRun.stdout).body, payload);
|
|
644
|
+
|
|
645
|
+
const capturePath = path.join(homeDir, `capture-null-live-${index}.json`);
|
|
646
|
+
const live = runCli({
|
|
647
|
+
args: ["posts:add-json", "--brand-id", "10", "--collection-id", "20", "--payload", payloadPath],
|
|
648
|
+
homeDir,
|
|
649
|
+
capturePath,
|
|
650
|
+
});
|
|
651
|
+
assert.equal(live.status, 0, live.stderr);
|
|
652
|
+
const capture = JSON.parse(await readFile(capturePath, "utf8"));
|
|
653
|
+
assert.deepEqual(capture.body, payload);
|
|
654
|
+
assert.deepEqual(capture.body, JSON.parse(dryRun.stdout).body);
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
|
|
610
658
|
test("posts:add-json rejects invalid JSON payloads", async () => {
|
|
611
659
|
const homeDir = await setupTempHome();
|
|
612
660
|
|
|
@@ -1073,6 +1121,44 @@ test("posts:update builds the documented patch payload", async () => {
|
|
|
1073
1121
|
});
|
|
1074
1122
|
});
|
|
1075
1123
|
|
|
1124
|
+
test("posts:move builds the documented atomic move payload", async () => {
|
|
1125
|
+
const homeDir = await setupTempHome();
|
|
1126
|
+
const capturePath = path.join(homeDir, "capture-post-move.json");
|
|
1127
|
+
const result = runCli({
|
|
1128
|
+
args: [
|
|
1129
|
+
"posts:move", "--brand-id", "42", "--source-collection-id", "77",
|
|
1130
|
+
"--destination-collection-id", "81", "--post-ids", "8801,8802",
|
|
1131
|
+
],
|
|
1132
|
+
homeDir,
|
|
1133
|
+
capturePath,
|
|
1134
|
+
});
|
|
1135
|
+
|
|
1136
|
+
assert.equal(result.status, 0, result.stderr);
|
|
1137
|
+
const capture = JSON.parse(await readFile(capturePath, "utf8"));
|
|
1138
|
+
assert.equal(capture.method, "PATCH");
|
|
1139
|
+
assert.equal(new URL(capture.url).pathname, "/api/public/v1/brands/42/posts/move");
|
|
1140
|
+
assert.deepEqual(capture.body, {
|
|
1141
|
+
sourceCollectionId: 77,
|
|
1142
|
+
destinationCollectionId: 81,
|
|
1143
|
+
postIds: [8801, 8802],
|
|
1144
|
+
});
|
|
1145
|
+
});
|
|
1146
|
+
|
|
1147
|
+
test("posts:move rejects the same source and destination collection", async () => {
|
|
1148
|
+
const homeDir = await setupTempHome();
|
|
1149
|
+
const result = runCli({
|
|
1150
|
+
args: [
|
|
1151
|
+
"posts:move", "--brand-id", "42", "--source-collection-id", "77",
|
|
1152
|
+
"--destination-collection-id", "77", "--post-ids", "8801",
|
|
1153
|
+
],
|
|
1154
|
+
homeDir,
|
|
1155
|
+
capturePath: path.join(homeDir, "capture-invalid-post-move.json"),
|
|
1156
|
+
});
|
|
1157
|
+
|
|
1158
|
+
assert.equal(result.status, 1);
|
|
1159
|
+
assert.match(result.stderr, /destination-collection-id must differ from source-collection-id/);
|
|
1160
|
+
});
|
|
1161
|
+
|
|
1076
1162
|
test("posts:update requires an update operation", async () => {
|
|
1077
1163
|
const homeDir = await setupTempHome();
|
|
1078
1164
|
const result = runCli({
|
|
@@ -1132,6 +1218,7 @@ test("base url can be overridden for testing", async () => {
|
|
|
1132
1218
|
capturePath,
|
|
1133
1219
|
extraEnv: {
|
|
1134
1220
|
NUELINK_BASE_URL: "https://example.test/custom/v1",
|
|
1221
|
+
NUELINK_TRUSTED_HOSTS: "example.test",
|
|
1135
1222
|
},
|
|
1136
1223
|
});
|
|
1137
1224
|
|
|
@@ -1142,6 +1229,77 @@ test("base url can be overridden for testing", async () => {
|
|
|
1142
1229
|
assert.equal(new URL(capture.url).pathname, "/custom/v1/brands");
|
|
1143
1230
|
});
|
|
1144
1231
|
|
|
1232
|
+
for (const [name, baseUrl, extraEnv] of [
|
|
1233
|
+
["rejects plaintext remote base URLs before authentication", "http://api.example.test/v1", {}],
|
|
1234
|
+
["rejects untrusted HTTPS base URLs before authentication", "https://attacker.example.test/v1", {}],
|
|
1235
|
+
["rejects URL credentials in the base URL", "https://user:secret@app.nuelink.com/api/public/v1", {}],
|
|
1236
|
+
]) {
|
|
1237
|
+
test(name, async () => {
|
|
1238
|
+
const homeDir = await setupTempHome();
|
|
1239
|
+
const capturePath = path.join(homeDir, "capture-rejected-base-url.json");
|
|
1240
|
+
const result = runCli({
|
|
1241
|
+
args: ["--json", "brands"],
|
|
1242
|
+
homeDir,
|
|
1243
|
+
capturePath,
|
|
1244
|
+
extraEnv: { NUELINK_API_KEY: "", NUELINK_BASE_URL: baseUrl, ...extraEnv },
|
|
1245
|
+
});
|
|
1246
|
+
const error = assertJsonError(result, "CONFIG_INVALID");
|
|
1247
|
+
assert.match(error.message, /NUELINK_BASE_URL/);
|
|
1248
|
+
await assert.rejects(readFile(capturePath, "utf8"));
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
test("allows loopback HTTP only with explicit opt-in", async () => {
|
|
1253
|
+
const homeDir = await setupTempHome();
|
|
1254
|
+
const capturePath = path.join(homeDir, "capture-loopback-base-url.json");
|
|
1255
|
+
const result = runCli({
|
|
1256
|
+
args: ["brands"],
|
|
1257
|
+
homeDir,
|
|
1258
|
+
capturePath,
|
|
1259
|
+
extraEnv: {
|
|
1260
|
+
NUELINK_BASE_URL: "http://127.0.0.1:8787/api/public/v1",
|
|
1261
|
+
NUELINK_ALLOW_INSECURE_HTTP: "1",
|
|
1262
|
+
},
|
|
1263
|
+
});
|
|
1264
|
+
assert.equal(result.status, 0, result.stderr);
|
|
1265
|
+
const capture = JSON.parse(await readFile(capturePath, "utf8"));
|
|
1266
|
+
assert.equal(new URL(capture.url).origin, "http://127.0.0.1:8787");
|
|
1267
|
+
});
|
|
1268
|
+
|
|
1269
|
+
test("posts:create requires comment and comment-delay as a pair", async () => {
|
|
1270
|
+
const homeDir = await setupTempHome();
|
|
1271
|
+
for (const args of [
|
|
1272
|
+
["posts:create", "--brand-id", "1", "--collection-id", "2", "--comment-delay", "30", "--dry-run"],
|
|
1273
|
+
["posts:create", "--brand-id", "1", "--collection-id", "2", "--comment", "First comment", "--dry-run"],
|
|
1274
|
+
]) {
|
|
1275
|
+
const capturePath = path.join(homeDir, `capture-comment-${args.includes("--comment-delay") ? "delay" : "text"}.json`);
|
|
1276
|
+
const result = runCli({ args, homeDir, capturePath });
|
|
1277
|
+
assert.equal(result.status, 1);
|
|
1278
|
+
assert.match(result.stderr, /comment and comment-delay must be provided together/);
|
|
1279
|
+
await assert.rejects(readFile(capturePath, "utf8"));
|
|
1280
|
+
}
|
|
1281
|
+
});
|
|
1282
|
+
|
|
1283
|
+
test("JSON mode without a command returns a structured usage error", async () => {
|
|
1284
|
+
const homeDir = await setupTempHome();
|
|
1285
|
+
const result = runCli({
|
|
1286
|
+
args: ["--json"],
|
|
1287
|
+
homeDir,
|
|
1288
|
+
capturePath: path.join(homeDir, "capture-json-no-command.json"),
|
|
1289
|
+
extraEnv: { NUELINK_API_KEY: "" },
|
|
1290
|
+
});
|
|
1291
|
+
assertJsonError(result, "USAGE_ERROR");
|
|
1292
|
+
});
|
|
1293
|
+
|
|
1294
|
+
test("GET requests reject dry-run instead of silently suppressing the read", async () => {
|
|
1295
|
+
const homeDir = await setupTempHome();
|
|
1296
|
+
const capturePath = path.join(homeDir, "capture-get-dry-run.json");
|
|
1297
|
+
const result = runCli({ args: ["--dry-run", "brands"], homeDir, capturePath });
|
|
1298
|
+
assert.equal(result.status, 1);
|
|
1299
|
+
assert.match(result.stderr, /--dry-run is only supported for API mutations/);
|
|
1300
|
+
await assert.rejects(readFile(capturePath, "utf8"));
|
|
1301
|
+
});
|
|
1302
|
+
|
|
1145
1303
|
test("get requests retry on 429 and then succeed", async () => {
|
|
1146
1304
|
const homeDir = await setupTempHome();
|
|
1147
1305
|
const capturePath = path.join(homeDir, "capture-retry.json");
|