@nuelink/nuelink-cli 1.3.8 → 1.4.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/package.json +2 -2
- package/src/commands.js +43 -47
- package/src/http.js +8 -4
- package/src/postPayload.js +68 -5
- package/src/validation.js +5 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuelink/nuelink-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.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",
|
|
@@ -30,4 +30,4 @@
|
|
|
30
30
|
"bin": {
|
|
31
31
|
"nuelink-cli": "./src/cli.js"
|
|
32
32
|
}
|
|
33
|
-
}
|
|
33
|
+
}
|
package/src/commands.js
CHANGED
|
@@ -5,7 +5,7 @@ import chalk from "chalk";
|
|
|
5
5
|
|
|
6
6
|
import { clearApiKey, maskToken, readConfig, resolveApiKey, CONFIG_FILE, decryptApiKey, saveApiKey } from "./config.js";
|
|
7
7
|
import { brandPath, collectionPath, nuelinkRequest } from "./http.js";
|
|
8
|
-
import { buildPostPayload, parseCsv, VALID_PUBLISH_MODES } from "./postPayload.js";
|
|
8
|
+
import { buildPostPayload, parseCsv, validateRawPostPayload, VALID_PUBLISH_MODES } from "./postPayload.js";
|
|
9
9
|
import {
|
|
10
10
|
VALID_AUTOMATION_SUB_TYPES,
|
|
11
11
|
VALID_AUTOMATION_TYPES,
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
parsePositiveInteger,
|
|
20
20
|
splitCsv,
|
|
21
21
|
validateHttpUrl,
|
|
22
|
-
validateMediaFile,
|
|
22
|
+
validateMediaFile,
|
|
23
23
|
validateQueueSlots,
|
|
24
24
|
} from "./validation.js";
|
|
25
25
|
|
|
@@ -138,7 +138,7 @@ async function promptHidden(promptText) {
|
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
async function resolveLoginApiKey(options, fallbackApiKey) {
|
|
141
|
+
async function resolveLoginApiKey(options, fallbackApiKey) {
|
|
142
142
|
if (options.apiKey || fallbackApiKey) {
|
|
143
143
|
return String(options.apiKey || fallbackApiKey).trim();
|
|
144
144
|
}
|
|
@@ -148,8 +148,8 @@ async function resolveLoginApiKey(options, fallbackApiKey) {
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
return promptHidden("API key: ");
|
|
151
|
-
}
|
|
152
|
-
|
|
151
|
+
}
|
|
152
|
+
|
|
153
153
|
function buildRequestOptions(program) {
|
|
154
154
|
const options = program.opts();
|
|
155
155
|
|
|
@@ -196,7 +196,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
196
196
|
.description("Nuelink CLI for the Public API")
|
|
197
197
|
.option("-a, --api-key <apiKey>", "Use API key for this invocation only")
|
|
198
198
|
.option("--auth <apiKey>", "Deprecated alias for --api-key")
|
|
199
|
-
.option("--dry-run", "Print the validated request without sending it")
|
|
199
|
+
.option("--dry-run", "Print the validated request without sending it")
|
|
200
200
|
.option("--json", "Output raw JSON instead of tables for list commands")
|
|
201
201
|
.option("--quiet", "Suppress non-essential success banners");
|
|
202
202
|
|
|
@@ -314,7 +314,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
314
314
|
method: "POST",
|
|
315
315
|
endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/collections`,
|
|
316
316
|
body: {
|
|
317
|
-
title: validateMaxLength(options.title, 255, "title"),
|
|
317
|
+
title: validateMaxLength(options.title, 255, "title"),
|
|
318
318
|
description: validateMaxLength(options.description, 1000, "description"),
|
|
319
319
|
maxRepublish: parseOptionalNonNegativeInteger(options.maxRepublish, "max-republish"),
|
|
320
320
|
channels,
|
|
@@ -328,9 +328,9 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
328
328
|
.description("List automations for a brand")
|
|
329
329
|
.requiredOption("--brand-id <id>", "Brand ID")
|
|
330
330
|
.option("--per-page <number>", "Items per page", "25")
|
|
331
|
-
.option("--page <number>", "Page number", "1")
|
|
332
|
-
.action(withCommandErrorHandling(async (options) => {
|
|
333
|
-
await executeRequest(program, runtimeApiKey, {
|
|
331
|
+
.option("--page <number>", "Page number", "1")
|
|
332
|
+
.action(withCommandErrorHandling(async (options) => {
|
|
333
|
+
await executeRequest(program, runtimeApiKey, {
|
|
334
334
|
endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/automations`,
|
|
335
335
|
query: {
|
|
336
336
|
per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
|
|
@@ -354,28 +354,28 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
354
354
|
.option("--description <text>", "Automation description")
|
|
355
355
|
.option("--load-old-posts <boolean>", "Import existing feed items: true/false")
|
|
356
356
|
.option("--add-posts-as-draft <boolean>", "Create imported posts as drafts: true/false")
|
|
357
|
-
.option("--refresh-rate <hours>", "Refresh interval (24, 12, 6, or 1 hours)")
|
|
358
|
-
.action(withCommandErrorHandling(async (options) => {
|
|
359
|
-
await executeRequest(program, runtimeApiKey, {
|
|
360
|
-
method: "POST",
|
|
361
|
-
endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/automations`,
|
|
362
|
-
body: {
|
|
363
|
-
collectionId: parsePositiveInteger(options.collectionId, "collection-id"),
|
|
364
|
-
feedUrl: validateHttpUrl(options.feedUrl, "feed-url"),
|
|
365
|
-
importAsType: normalizeEnum(options.importAsType, "import-as-type", VALID_IMPORT_AS_TYPES),
|
|
366
|
-
subType: normalizeEnum(options.subType, "sub-type", VALID_AUTOMATION_SUB_TYPES),
|
|
367
|
-
title: validateMaxLength(options.title, 255, "title"),
|
|
368
|
-
type: normalizeEnum(options.type, "type", VALID_AUTOMATION_TYPES),
|
|
369
|
-
dynamicTitle: validateMaxLength(options.dynamicTitle, 255, "dynamic-title"),
|
|
370
|
-
dynamicBody: validateMaxLength(options.dynamicBody, 255, "dynamic-body"),
|
|
371
|
-
description: options.description,
|
|
372
|
-
loadOldPosts: parseBooleanStrict(options.loadOldPosts, "load-old-posts"),
|
|
373
|
-
addPostsAsDraft: parseBooleanStrict(options.addPostsAsDraft, "add-posts-as-draft"),
|
|
374
|
-
refreshRate: options.refreshRate === undefined
|
|
375
|
-
? undefined
|
|
376
|
-
: Number(normalizeEnum(options.refreshRate, "refresh-rate", ["24", "12", "6", "1"])),
|
|
377
|
-
},
|
|
378
|
-
});
|
|
357
|
+
.option("--refresh-rate <hours>", "Refresh interval (24, 12, 6, or 1 hours)")
|
|
358
|
+
.action(withCommandErrorHandling(async (options) => {
|
|
359
|
+
await executeRequest(program, runtimeApiKey, {
|
|
360
|
+
method: "POST",
|
|
361
|
+
endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/automations`,
|
|
362
|
+
body: {
|
|
363
|
+
collectionId: parsePositiveInteger(options.collectionId, "collection-id"),
|
|
364
|
+
feedUrl: validateHttpUrl(options.feedUrl, "feed-url"),
|
|
365
|
+
importAsType: normalizeEnum(options.importAsType, "import-as-type", VALID_IMPORT_AS_TYPES),
|
|
366
|
+
subType: normalizeEnum(options.subType, "sub-type", VALID_AUTOMATION_SUB_TYPES),
|
|
367
|
+
title: validateMaxLength(options.title, 255, "title"),
|
|
368
|
+
type: normalizeEnum(options.type, "type", VALID_AUTOMATION_TYPES),
|
|
369
|
+
dynamicTitle: validateMaxLength(options.dynamicTitle, 255, "dynamic-title"),
|
|
370
|
+
dynamicBody: validateMaxLength(options.dynamicBody, 255, "dynamic-body"),
|
|
371
|
+
description: options.description,
|
|
372
|
+
loadOldPosts: parseBooleanStrict(options.loadOldPosts, "load-old-posts"),
|
|
373
|
+
addPostsAsDraft: parseBooleanStrict(options.addPostsAsDraft, "add-posts-as-draft"),
|
|
374
|
+
refreshRate: options.refreshRate === undefined
|
|
375
|
+
? undefined
|
|
376
|
+
: Number(normalizeEnum(options.refreshRate, "refresh-rate", ["24", "12", "6", "1"])),
|
|
377
|
+
},
|
|
378
|
+
});
|
|
379
379
|
}));
|
|
380
380
|
|
|
381
381
|
program
|
|
@@ -419,19 +419,19 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
419
419
|
.description("Upload a media file")
|
|
420
420
|
.requiredOption("--brand-id <id>", "Brand ID")
|
|
421
421
|
.requiredOption("--file <path>", "Path to local file")
|
|
422
|
-
.action(withCommandErrorHandling(async (options) => {
|
|
423
|
-
const brandId = parsePositiveInteger(options.brandId, "brand-id");
|
|
424
|
-
const fileStat = await stat(options.file);
|
|
425
|
-
const { mediaType, size } = validateMediaFile(options.file, fileStat);
|
|
426
|
-
const formData = new FormData();
|
|
427
|
-
const fileBuffer = await readFile(options.file);
|
|
428
|
-
const fileBlob = new Blob([fileBuffer], { type: mediaType });
|
|
429
|
-
formData.append("media", fileBlob, path.basename(options.file));
|
|
422
|
+
.action(withCommandErrorHandling(async (options) => {
|
|
423
|
+
const brandId = parsePositiveInteger(options.brandId, "brand-id");
|
|
424
|
+
const fileStat = await stat(options.file);
|
|
425
|
+
const { mediaType, size } = validateMediaFile(options.file, fileStat);
|
|
426
|
+
const formData = new FormData();
|
|
427
|
+
const fileBuffer = await readFile(options.file);
|
|
428
|
+
const fileBlob = new Blob([fileBuffer], { type: mediaType });
|
|
429
|
+
formData.append("media", fileBlob, path.basename(options.file));
|
|
430
430
|
|
|
431
431
|
await executeRequest(program, runtimeApiKey, {
|
|
432
432
|
method: "POST",
|
|
433
433
|
endpoint: `${brandPath(brandId)}/media`,
|
|
434
|
-
multipart: formData,
|
|
434
|
+
multipart: formData,
|
|
435
435
|
dryRunBody: {
|
|
436
436
|
file: path.basename(options.file),
|
|
437
437
|
size,
|
|
@@ -470,11 +470,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
470
470
|
const payloadText = options.payload === "-"
|
|
471
471
|
? await readStdinText()
|
|
472
472
|
: await readFile(options.payload, "utf8");
|
|
473
|
-
const payload = parseJsonString(payloadText, "payload");
|
|
474
|
-
|
|
475
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
476
|
-
throw new Error("Invalid payload. Expected a JSON object.");
|
|
477
|
-
}
|
|
473
|
+
const payload = validateRawPostPayload(parseJsonString(payloadText, "payload"));
|
|
478
474
|
|
|
479
475
|
await executeRequest(program, runtimeApiKey, {
|
|
480
476
|
method: "POST",
|
|
@@ -520,7 +516,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
520
516
|
.option("--youtube-playlists <json>", "YouTube playlists JSON string")
|
|
521
517
|
.option("--googlemybusiness-upload-to-photos-section <boolean>", "Upload to Google Business Profile photos: true/false")
|
|
522
518
|
.action(withCommandErrorHandling(async (options) => {
|
|
523
|
-
const payload = buildPostPayload(options);
|
|
519
|
+
const payload = buildPostPayload(options);
|
|
524
520
|
|
|
525
521
|
await executeRequest(program, runtimeApiKey, {
|
|
526
522
|
method: "POST",
|
package/src/http.js
CHANGED
|
@@ -5,7 +5,7 @@ import { printApiResponse } from "./output.js";
|
|
|
5
5
|
const require = createRequire(import.meta.url);
|
|
6
6
|
const { version: cliVersion } = require("../package.json");
|
|
7
7
|
|
|
8
|
-
const API_BASE_URL = process.env.NUELINK_BASE_URL || "https://nuelink.com/api/public/v1";
|
|
8
|
+
const API_BASE_URL = process.env.NUELINK_BASE_URL || "https://app.nuelink.com/api/public/v1";
|
|
9
9
|
const REQUEST_TIMEOUT_MS = Number(process.env.NUELINK_TIMEOUT_MS || 30000);
|
|
10
10
|
const MAX_GET_RETRIES = Number(process.env.NUELINK_GET_RETRIES || 2);
|
|
11
11
|
const RETRY_BASE_DELAY_MS = Number(process.env.NUELINK_RETRY_BASE_MS || 500);
|
|
@@ -44,16 +44,17 @@ function parseRetryAfterMs(headers, attempt) {
|
|
|
44
44
|
const seconds = Number(retryAfter);
|
|
45
45
|
|
|
46
46
|
if (!Number.isNaN(seconds)) {
|
|
47
|
-
return Math.
|
|
47
|
+
return Math.max(seconds * 1000, 0);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
const dateDelay = Date.parse(retryAfter) - Date.now();
|
|
51
51
|
if (!Number.isNaN(dateDelay)) {
|
|
52
|
-
return Math.
|
|
52
|
+
return Math.max(dateDelay, 0);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
const exponentialDelay = Math.min(RETRY_BASE_DELAY_MS * (2 ** attempt), RETRY_MAX_DELAY_MS);
|
|
57
|
+
return Math.floor(Math.random() * (exponentialDelay + 1));
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
async function sleep(ms) {
|
|
@@ -138,6 +139,9 @@ async function nuelinkRequest({ apiKey, method = "GET", endpoint, query, body, m
|
|
|
138
139
|
try {
|
|
139
140
|
data = JSON.parse(text);
|
|
140
141
|
} catch {
|
|
142
|
+
if (response.ok) {
|
|
143
|
+
throw new Error(`Protocol error: expected a JSON response (HTTP ${response.status}).`);
|
|
144
|
+
}
|
|
141
145
|
data = { raw: text };
|
|
142
146
|
}
|
|
143
147
|
}
|
package/src/postPayload.js
CHANGED
|
@@ -55,7 +55,7 @@ function mergeMedia(idsCsv, urlsCsv) {
|
|
|
55
55
|
return [...idMedia, ...urlMedia];
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
function normalizePublishMode(value) {
|
|
58
|
+
function normalizePublishMode(value) {
|
|
59
59
|
const normalized = String(value ?? "").trim().toUpperCase();
|
|
60
60
|
|
|
61
61
|
if (!VALID_PUBLISH_MODES.includes(normalized)) {
|
|
@@ -63,7 +63,69 @@ function normalizePublishMode(value) {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
return normalized;
|
|
66
|
-
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function validateRawPostPayload(payload) {
|
|
69
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
70
|
+
throw new Error("Invalid payload. Expected a JSON object.");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const publishMode = normalizePublishMode(payload.publishMode);
|
|
74
|
+
const scheduledAt = validateScheduledAt(payload.scheduledAt);
|
|
75
|
+
if (publishMode === "SCHEDULE" && !scheduledAt) {
|
|
76
|
+
throw new Error("scheduledAt is required when publishMode is SCHEDULE.");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
validateOptionalLength(payload.title, 255, "title");
|
|
80
|
+
validateOptionalLength(payload.caption, 3000, "caption");
|
|
81
|
+
validateOptionalLength(payload.alt, 255, "alt");
|
|
82
|
+
if (payload.link !== undefined) {
|
|
83
|
+
validateHttpUrl(payload.link, "link");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const poll = payload.poll;
|
|
87
|
+
if (!poll && (!payload.caption || !String(payload.caption).trim())) {
|
|
88
|
+
throw new Error("caption is required when poll is not provided.");
|
|
89
|
+
}
|
|
90
|
+
if (poll !== undefined) {
|
|
91
|
+
if (!poll || typeof poll !== "object" || Array.isArray(poll)) {
|
|
92
|
+
throw new Error("Invalid poll. Expected a JSON object.");
|
|
93
|
+
}
|
|
94
|
+
const options = Array.isArray(poll.options) ? poll.options : [];
|
|
95
|
+
validatePollOptions(options, poll.correctOptionIndex);
|
|
96
|
+
if (!poll.question || options.length < 2 || options.length > 4 || !VALID_POLL_PERIODS.includes(poll.period)) {
|
|
97
|
+
throw new Error("poll requires question, 2 to 4 options, and period (1d, 3d, or 7d).");
|
|
98
|
+
}
|
|
99
|
+
validateOptionalLength(poll.question, 280, "poll-question");
|
|
100
|
+
validateOptionalLength(poll.explanation, 512, "poll-explanation");
|
|
101
|
+
options.forEach((option) => validateOptionalLength(option, 30, "poll-option"));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (payload.media !== undefined) {
|
|
105
|
+
if (!Array.isArray(payload.media)) {
|
|
106
|
+
throw new Error("Invalid media. Expected an array.");
|
|
107
|
+
}
|
|
108
|
+
payload.media.forEach((item, index) => {
|
|
109
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) {
|
|
110
|
+
throw new Error(`Invalid media item at index ${index}.`);
|
|
111
|
+
}
|
|
112
|
+
const hasId = typeof item.id === "string" && item.id.trim().length > 0;
|
|
113
|
+
const hasUrl = typeof item.url === "string" && item.url.trim().length > 0;
|
|
114
|
+
if (hasId === hasUrl) {
|
|
115
|
+
throw new Error(`Invalid media item at index ${index}. Expected exactly one of id or url.`);
|
|
116
|
+
}
|
|
117
|
+
if (hasUrl) {
|
|
118
|
+
validateHttpUrl(item.url, `media[${index}].url`);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
...payload,
|
|
125
|
+
publishMode,
|
|
126
|
+
...(payload.scheduledAt !== undefined ? { scheduledAt } : {}),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
67
129
|
|
|
68
130
|
function buildPostPayload(options) {
|
|
69
131
|
const media = mergeMedia(options.mediaIds, options.mediaUrls);
|
|
@@ -241,6 +303,7 @@ export {
|
|
|
241
303
|
mergeMedia,
|
|
242
304
|
parseBoolean,
|
|
243
305
|
parseCsv,
|
|
244
|
-
parseNumber,
|
|
245
|
-
|
|
246
|
-
|
|
306
|
+
parseNumber,
|
|
307
|
+
validateRawPostPayload,
|
|
308
|
+
VALID_PUBLISH_MODES,
|
|
309
|
+
};
|
package/src/validation.js
CHANGED
|
@@ -42,7 +42,7 @@ const SUPPORTED_MEDIA_TYPES = new Map([
|
|
|
42
42
|
[".mov", "video/quicktime"],
|
|
43
43
|
]);
|
|
44
44
|
const DEFAULT_MAX_MEDIA_SIZE_BYTES = Number(process.env.NUELINK_MAX_MEDIA_SIZE_BYTES || 100 * 1024 * 1024);
|
|
45
|
-
const QUEUE_SLOT_PATTERN = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) [0-2
|
|
45
|
+
const QUEUE_SLOT_PATTERN = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (?:[01][0-9]|2[0-3]):[0-5][0-9]$/;
|
|
46
46
|
const SQL_DATETIME_PATTERN = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
|
|
47
47
|
|
|
48
48
|
function splitCsv(value) {
|
|
@@ -151,7 +151,7 @@ function validateHttpUrl(value, label) {
|
|
|
151
151
|
return parsedUrl.toString();
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
function validateQueueSlots(queueSlots) {
|
|
154
|
+
function validateQueueSlots(queueSlots) {
|
|
155
155
|
queueSlots.forEach((slot) => {
|
|
156
156
|
if (!QUEUE_SLOT_PATTERN.test(slot)) {
|
|
157
157
|
throw new Error(`Invalid queue slot \"${slot}\". Expected values like Mon 10:10.`);
|
|
@@ -159,8 +159,8 @@ function validateQueueSlots(queueSlots) {
|
|
|
159
159
|
});
|
|
160
160
|
|
|
161
161
|
return queueSlots;
|
|
162
|
-
}
|
|
163
|
-
|
|
162
|
+
}
|
|
163
|
+
|
|
164
164
|
function validateScheduledAt(value) {
|
|
165
165
|
if (value === undefined || value === null || value === "" || value === "null") {
|
|
166
166
|
return null;
|
|
@@ -248,7 +248,7 @@ export {
|
|
|
248
248
|
parsePositiveInteger,
|
|
249
249
|
splitCsv,
|
|
250
250
|
validateHttpUrl,
|
|
251
|
-
validateMediaFile,
|
|
251
|
+
validateMediaFile,
|
|
252
252
|
validatePollOptions,
|
|
253
253
|
validateScheduledAt,
|
|
254
254
|
validateQueueSlots,
|