@nuelink/nuelink-cli 1.3.4 → 1.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -12
- package/package.json +2 -2
- package/src/commands.js +64 -43
- package/src/postPayload.js +105 -33
- package/src/validation.js +76 -22
package/README.md
CHANGED
|
@@ -197,7 +197,7 @@ Channel list output highlights name, status, and platform type.
|
|
|
197
197
|
List media:
|
|
198
198
|
|
|
199
199
|
```bash
|
|
200
|
-
nuelink-cli media --brand-id 13493 --per-page 5 --page 1
|
|
200
|
+
nuelink-cli media --brand-id 13493 --type IMAGE --per-page 5 --page 1
|
|
201
201
|
```
|
|
202
202
|
|
|
203
203
|
Media list output highlights file name, type, size, and timestamps.
|
|
@@ -254,23 +254,26 @@ nuelink-cli posts:create \
|
|
|
254
254
|
--media-urls "https://media.nuelink.com/media/abc" \
|
|
255
255
|
--poll-question "what is the new role?" \
|
|
256
256
|
--poll-options "iron,dudee" \
|
|
257
|
-
--poll-period 3d \
|
|
258
|
-
--poll-correct-option-index
|
|
257
|
+
--poll-period 3d \
|
|
258
|
+
--poll-correct-option-index 0 \
|
|
259
259
|
--poll-explanation "iwa ash idir lwaaa7ad" \
|
|
260
260
|
--instagram-collab "karim.chamlal" \
|
|
261
261
|
--instagram-location-id "abc123" \
|
|
262
262
|
--instagram-location-name "bentaib" \
|
|
263
263
|
--instagram-trial-reel MANUAL \
|
|
264
264
|
--instagram-share-to-feed true \
|
|
265
|
-
--facebook-
|
|
266
|
-
--facebook-location-
|
|
267
|
-
--
|
|
268
|
-
--tiktok-
|
|
269
|
-
--youtube-tags "tag1,tag2,tag3" \
|
|
270
|
-
--youtube-playlists '[{"channelId":
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
265
|
+
--facebook-location-id "abc123" \
|
|
266
|
+
--facebook-location-name "bentaib" \
|
|
267
|
+
--tiktok-send-to-inbox true \
|
|
268
|
+
--tiktok-auto-add-music false \
|
|
269
|
+
--youtube-tags "tag1,tag2,tag3" \
|
|
270
|
+
--youtube-playlists '[{"channelId":1,"playlistIds":["1","2"]}]' \
|
|
271
|
+
--googlemybusiness-upload-to-photos-section true
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
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.
|
|
275
|
+
|
|
276
|
+
Pagination uses `--page >= 1` and `--per-page` from 1 through 100. Media type filters are `IMAGE`, `VIDEO`, `GIF`, `APPLICATION`, `DOCUMENT`, and `CSV`.
|
|
274
277
|
|
|
275
278
|
## Output and Exit Codes
|
|
276
279
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuelink/nuelink-cli",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.6",
|
|
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",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"chalk": "^5.6.2",
|
|
28
|
-
"commander": "^
|
|
28
|
+
"commander": "^13.1.0"
|
|
29
29
|
},
|
|
30
30
|
"bin": {
|
|
31
31
|
"nuelink-cli": "./src/cli.js"
|
package/src/commands.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { readFile, stat } from "node:fs/promises";
|
|
1
|
+
import { readFile, stat } from "node:fs/promises";
|
|
3
2
|
import readline from "node:readline";
|
|
4
3
|
import path from "node:path";
|
|
5
4
|
import chalk from "chalk";
|
|
@@ -8,13 +7,15 @@ import { clearApiKey, maskToken, readConfig, resolveApiKey, CONFIG_FILE, decrypt
|
|
|
8
7
|
import { brandPath, collectionPath, nuelinkRequest } from "./http.js";
|
|
9
8
|
import { buildPostPayload, parseCsv, VALID_PUBLISH_MODES } from "./postPayload.js";
|
|
10
9
|
import {
|
|
11
|
-
VALID_AUTOMATION_SUB_TYPES,
|
|
12
|
-
VALID_AUTOMATION_TYPES,
|
|
13
|
-
VALID_IMPORT_AS_TYPES,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
VALID_AUTOMATION_SUB_TYPES,
|
|
11
|
+
VALID_AUTOMATION_TYPES,
|
|
12
|
+
VALID_IMPORT_AS_TYPES,
|
|
13
|
+
VALID_MEDIA_FILTER_TYPES,
|
|
14
|
+
normalizeEnum,
|
|
15
|
+
parseIntegerInRange,
|
|
16
|
+
parseJsonString,
|
|
17
|
+
parseOptionalNonNegativeInteger,
|
|
18
|
+
parsePositiveInteger,
|
|
18
19
|
splitCsv,
|
|
19
20
|
validateHttpUrl,
|
|
20
21
|
validateMediaFile,
|
|
@@ -148,7 +149,7 @@ async function resolveLoginApiKey(options) {
|
|
|
148
149
|
return promptHidden("API key: ");
|
|
149
150
|
}
|
|
150
151
|
|
|
151
|
-
function buildRequestOptions(program) {
|
|
152
|
+
function buildRequestOptions(program) {
|
|
152
153
|
const options = program.opts();
|
|
153
154
|
|
|
154
155
|
return {
|
|
@@ -156,8 +157,15 @@ function buildRequestOptions(program) {
|
|
|
156
157
|
outputMode: options.json ? "json" : "table",
|
|
157
158
|
quiet: Boolean(options.quiet),
|
|
158
159
|
};
|
|
159
|
-
}
|
|
160
|
-
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function validateMaxLength(value, maximum, label) {
|
|
163
|
+
if (value !== undefined && value !== null && String(value).length > maximum) {
|
|
164
|
+
throw new Error(`${label} must not exceed ${maximum} characters.`);
|
|
165
|
+
}
|
|
166
|
+
return value;
|
|
167
|
+
}
|
|
168
|
+
|
|
161
169
|
async function executeRequest(program, runtimeApiKey, request) {
|
|
162
170
|
const requestOptions = buildRequestOptions(program);
|
|
163
171
|
const apiKey = requestOptions.dryRun ? undefined : await resolveApiKey(runtimeApiKey);
|
|
@@ -265,7 +273,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
265
273
|
await executeRequest(program, runtimeApiKey, {
|
|
266
274
|
endpoint: "/brands",
|
|
267
275
|
query: {
|
|
268
|
-
per_page:
|
|
276
|
+
per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
|
|
269
277
|
page: parsePositiveInteger(options.page, "page"),
|
|
270
278
|
},
|
|
271
279
|
});
|
|
@@ -281,7 +289,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
281
289
|
await executeRequest(program, runtimeApiKey, {
|
|
282
290
|
endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/collections`,
|
|
283
291
|
query: {
|
|
284
|
-
per_page:
|
|
292
|
+
per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
|
|
285
293
|
page: parsePositiveInteger(options.page, "page"),
|
|
286
294
|
},
|
|
287
295
|
});
|
|
@@ -304,9 +312,9 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
304
312
|
method: "POST",
|
|
305
313
|
endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/collections`,
|
|
306
314
|
body: {
|
|
307
|
-
title: options.title,
|
|
308
|
-
description: options.description,
|
|
309
|
-
maxRepublish:
|
|
315
|
+
title: validateMaxLength(options.title, 255, "title"),
|
|
316
|
+
description: validateMaxLength(options.description, 1000, "description"),
|
|
317
|
+
maxRepublish: parseOptionalNonNegativeInteger(options.maxRepublish, "max-republish"),
|
|
310
318
|
channels,
|
|
311
319
|
queues,
|
|
312
320
|
},
|
|
@@ -323,7 +331,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
323
331
|
await executeRequest(program, runtimeApiKey, {
|
|
324
332
|
endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/automations`,
|
|
325
333
|
query: {
|
|
326
|
-
per_page:
|
|
334
|
+
per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
|
|
327
335
|
page: parsePositiveInteger(options.page, "page"),
|
|
328
336
|
},
|
|
329
337
|
});
|
|
@@ -339,9 +347,12 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
339
347
|
.requiredOption("--sub-type <type>", "Sub type, e.g. RSS")
|
|
340
348
|
.requiredOption("--title <title>", "Automation title")
|
|
341
349
|
.option("--type <type>", "Automation type", "FEED")
|
|
342
|
-
.option("--dynamic-title <text>", "Dynamic title", "{{title}}")
|
|
343
|
-
.option("--dynamic-body <text>", "Dynamic body", "{title} {link}")
|
|
344
|
-
.option("--description <text>", "Automation description")
|
|
350
|
+
.option("--dynamic-title <text>", "Dynamic title", "{{title}}")
|
|
351
|
+
.option("--dynamic-body <text>", "Dynamic body", "{title} {link}")
|
|
352
|
+
.option("--description <text>", "Automation description")
|
|
353
|
+
.option("--load-old-posts <boolean>", "Import existing feed items: true/false")
|
|
354
|
+
.option("--add-posts-as-draft <boolean>", "Create imported posts as drafts: true/false")
|
|
355
|
+
.option("--refresh-rate <hours>", "Refresh interval (24, 12, 6, or 1 hours)")
|
|
345
356
|
.action(withCommandErrorHandling(async (options) => {
|
|
346
357
|
await executeRequest(program, runtimeApiKey, {
|
|
347
358
|
method: "POST",
|
|
@@ -351,12 +362,17 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
351
362
|
feedUrl: validateHttpUrl(options.feedUrl, "feed-url"),
|
|
352
363
|
importAsType: normalizeEnum(options.importAsType, "import-as-type", VALID_IMPORT_AS_TYPES),
|
|
353
364
|
subType: normalizeEnum(options.subType, "sub-type", VALID_AUTOMATION_SUB_TYPES),
|
|
354
|
-
title: options.title,
|
|
365
|
+
title: validateMaxLength(options.title, 255, "title"),
|
|
355
366
|
type: normalizeEnum(options.type, "type", VALID_AUTOMATION_TYPES),
|
|
356
|
-
dynamicTitle: options.dynamicTitle,
|
|
357
|
-
dynamicBody: options.dynamicBody,
|
|
358
|
-
description: options.description,
|
|
359
|
-
|
|
367
|
+
dynamicTitle: validateMaxLength(options.dynamicTitle, 255, "dynamic-title"),
|
|
368
|
+
dynamicBody: validateMaxLength(options.dynamicBody, 255, "dynamic-body"),
|
|
369
|
+
description: options.description,
|
|
370
|
+
loadOldPosts: parseBooleanStrict(options.loadOldPosts, "load-old-posts"),
|
|
371
|
+
addPostsAsDraft: parseBooleanStrict(options.addPostsAsDraft, "add-posts-as-draft"),
|
|
372
|
+
refreshRate: options.refreshRate === undefined
|
|
373
|
+
? undefined
|
|
374
|
+
: Number(normalizeEnum(options.refreshRate, "refresh-rate", ["24", "12", "6", "1"])),
|
|
375
|
+
},
|
|
360
376
|
});
|
|
361
377
|
}));
|
|
362
378
|
|
|
@@ -370,7 +386,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
370
386
|
await executeRequest(program, runtimeApiKey, {
|
|
371
387
|
endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/channels`,
|
|
372
388
|
query: {
|
|
373
|
-
per_page:
|
|
389
|
+
per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
|
|
374
390
|
page: parsePositiveInteger(options.page, "page"),
|
|
375
391
|
},
|
|
376
392
|
});
|
|
@@ -379,15 +395,19 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
379
395
|
program
|
|
380
396
|
.command("media")
|
|
381
397
|
.description("List media for a brand")
|
|
382
|
-
.requiredOption("--brand-id <id>", "Brand ID")
|
|
383
|
-
.option("--
|
|
398
|
+
.requiredOption("--brand-id <id>", "Brand ID")
|
|
399
|
+
.option("--type <type>", `Media type filter (${VALID_MEDIA_FILTER_TYPES.join(", ")})`)
|
|
400
|
+
.option("--per-page <number>", "Items per page", "25")
|
|
384
401
|
.option("--page <number>", "Page number", "1")
|
|
385
402
|
.action(withCommandErrorHandling(async (options) => {
|
|
386
403
|
await executeRequest(program, runtimeApiKey, {
|
|
387
404
|
endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/media`,
|
|
388
405
|
query: {
|
|
389
|
-
per_page:
|
|
390
|
-
page: parsePositiveInteger(options.page, "page"),
|
|
406
|
+
per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
|
|
407
|
+
page: parsePositiveInteger(options.page, "page"),
|
|
408
|
+
type: options.type
|
|
409
|
+
? normalizeEnum(options.type, "type", VALID_MEDIA_FILTER_TYPES)
|
|
410
|
+
: undefined,
|
|
391
411
|
},
|
|
392
412
|
});
|
|
393
413
|
}));
|
|
@@ -402,7 +422,8 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
402
422
|
const fileStat = await stat(options.file);
|
|
403
423
|
const { mediaType, size } = validateMediaFile(options.file, fileStat);
|
|
404
424
|
const formData = new FormData();
|
|
405
|
-
const
|
|
425
|
+
const fileBuffer = await readFile(options.file);
|
|
426
|
+
const fileBlob = new Blob([fileBuffer], { type: mediaType });
|
|
406
427
|
formData.append("media", fileBlob, path.basename(options.file));
|
|
407
428
|
|
|
408
429
|
await executeRequest(program, runtimeApiKey, {
|
|
@@ -431,7 +452,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
431
452
|
parsePositiveInteger(options.collectionId, "collection-id"),
|
|
432
453
|
)}/posts`,
|
|
433
454
|
query: {
|
|
434
|
-
per_page:
|
|
455
|
+
per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
|
|
435
456
|
page: parsePositiveInteger(options.page, "page"),
|
|
436
457
|
},
|
|
437
458
|
});
|
|
@@ -469,9 +490,8 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
469
490
|
.option("--alt <text>", "Alt text")
|
|
470
491
|
.option("--link <url>", "Post link")
|
|
471
492
|
.option("--publish-mode <mode>", `Publish mode (${VALID_PUBLISH_MODES.join(", ")})`, "DRAFT")
|
|
472
|
-
.option("--scheduled-at <value>", "Publish datetime (YYYY-MM-DD HH:mm:ss
|
|
473
|
-
.option("--post-as-story <boolean>", "Post as story: true/false")
|
|
474
|
-
.option("--post-type <type>", "Post type override")
|
|
493
|
+
.option("--scheduled-at <value>", "Publish datetime (YYYY-MM-DD HH:mm:ss) or null")
|
|
494
|
+
.option("--post-as-story <boolean>", "Post as story: true/false")
|
|
475
495
|
.option("--comment <text>", "First comment")
|
|
476
496
|
.option("--comment-delay <seconds>", "First comment delay seconds")
|
|
477
497
|
.option("--media-ids <ids>", "Comma-separated media IDs")
|
|
@@ -479,19 +499,20 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
479
499
|
.option("--poll-question <text>", "Poll question")
|
|
480
500
|
.option("--poll-options <items>", "Comma-separated poll options")
|
|
481
501
|
.option("--poll-period <value>", "Poll period (e.g. 3d)")
|
|
482
|
-
.option("--poll-correct-option-index <number>", "
|
|
502
|
+
.option("--poll-correct-option-index <number>", "Zero-based poll correct option index")
|
|
483
503
|
.option("--poll-explanation <text>", "Poll explanation")
|
|
484
504
|
.option("--instagram-collab <username>", "Instagram collab username")
|
|
485
505
|
.option("--instagram-location-id <id>", "Instagram location ID")
|
|
486
506
|
.option("--instagram-location-name <name>", "Instagram location name")
|
|
487
507
|
.option("--instagram-trial-reel <mode>", "Instagram trial reel mode")
|
|
488
508
|
.option("--instagram-share-to-feed <boolean>", "Instagram share to feed true/false")
|
|
489
|
-
.option("--facebook-
|
|
490
|
-
.option("--facebook-location-
|
|
491
|
-
.option("--
|
|
492
|
-
.option("--tiktok-
|
|
493
|
-
.option("--youtube-tags <tags>", "Comma-separated YouTube tags")
|
|
494
|
-
.option("--youtube-playlists <json>", "YouTube playlists JSON string")
|
|
509
|
+
.option("--facebook-location-id <id>", "Facebook location ID")
|
|
510
|
+
.option("--facebook-location-name <name>", "Facebook location name")
|
|
511
|
+
.option("--tiktok-send-to-inbox <boolean>", "TikTok send to inbox true/false")
|
|
512
|
+
.option("--tiktok-auto-add-music <boolean>", "TikTok auto-add music: true/false")
|
|
513
|
+
.option("--youtube-tags <tags>", "Comma-separated YouTube tags")
|
|
514
|
+
.option("--youtube-playlists <json>", "YouTube playlists JSON string")
|
|
515
|
+
.option("--googlemybusiness-upload-to-photos-section <boolean>", "Upload to Google Business Profile photos: true/false")
|
|
495
516
|
.action(withCommandErrorHandling(async (options) => {
|
|
496
517
|
const payload = buildPostPayload(options);
|
|
497
518
|
|
package/src/postPayload.js
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
|
-
parseBooleanStrict,
|
|
3
|
-
parseJsonString,
|
|
4
|
-
|
|
2
|
+
parseBooleanStrict,
|
|
3
|
+
parseJsonString,
|
|
4
|
+
parseOptionalNonNegativeInteger,
|
|
5
5
|
splitCsv,
|
|
6
6
|
validateHttpUrl,
|
|
7
7
|
validatePollOptions,
|
|
8
8
|
validateScheduledAt,
|
|
9
9
|
} from "./validation.js";
|
|
10
10
|
|
|
11
|
-
const VALID_PUBLISH_MODES = ["DRAFT", "QUEUE", "SCHEDULE", "IMMEDIATE"];
|
|
11
|
+
const VALID_PUBLISH_MODES = ["DRAFT", "QUEUE", "SCHEDULE", "IMMEDIATE"];
|
|
12
|
+
const VALID_POLL_PERIODS = ["1d", "3d", "7d"];
|
|
13
|
+
const VALID_TRIAL_REEL_MODES = ["MANUAL", "SS_PERFORMANCE"];
|
|
14
|
+
|
|
15
|
+
function validateOptionalLength(value, maximum, label) {
|
|
16
|
+
if (value !== undefined && value !== null && String(value).length > maximum) {
|
|
17
|
+
throw new Error(`${label} must not exceed ${maximum} characters.`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
12
20
|
|
|
13
21
|
function parseCsv(value) {
|
|
14
22
|
return splitCsv(value);
|
|
@@ -57,7 +65,7 @@ function normalizePublishMode(value) {
|
|
|
57
65
|
return normalized;
|
|
58
66
|
}
|
|
59
67
|
|
|
60
|
-
function buildPostPayload(options) {
|
|
68
|
+
function buildPostPayload(options) {
|
|
61
69
|
const media = mergeMedia(options.mediaIds, options.mediaUrls);
|
|
62
70
|
const publishMode = normalizePublishMode(options.publishMode);
|
|
63
71
|
const scheduledAt = validateScheduledAt(options.scheduledAt);
|
|
@@ -66,21 +74,38 @@ function buildPostPayload(options) {
|
|
|
66
74
|
throw new Error("scheduledAt is required when publishMode is SCHEDULE.");
|
|
67
75
|
}
|
|
68
76
|
|
|
69
|
-
const pollOptions = options.pollOptions ? parseCsv(options.pollOptions) : [];
|
|
70
|
-
const pollCorrectOptionIndex =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
const pollOptions = options.pollOptions ? parseCsv(options.pollOptions) : [];
|
|
78
|
+
const pollCorrectOptionIndex = parseOptionalNonNegativeInteger(options.pollCorrectOptionIndex, "poll-correct-option-index");
|
|
79
|
+
validatePollOptions(pollOptions, pollCorrectOptionIndex);
|
|
80
|
+
validateOptionalLength(options.title, 255, "title");
|
|
81
|
+
validateOptionalLength(options.caption, 3000, "caption");
|
|
82
|
+
validateOptionalLength(options.alt, 255, "alt");
|
|
83
|
+
validateOptionalLength(options.pollQuestion, 280, "poll-question");
|
|
84
|
+
validateOptionalLength(options.pollExplanation, 512, "poll-explanation");
|
|
85
|
+
validateOptionalLength(options.comment, 1000, "comment");
|
|
86
|
+
validateOptionalLength(options.instagramCollab, 1000, "instagram-collab");
|
|
87
|
+
pollOptions.forEach((option) => validateOptionalLength(option, 30, "poll-option"));
|
|
88
|
+
|
|
89
|
+
if (options.pollPeriod && !VALID_POLL_PERIODS.includes(options.pollPeriod)) {
|
|
90
|
+
throw new Error(`Invalid poll-period. Expected one of: ${VALID_POLL_PERIODS.join(", ")}.`);
|
|
91
|
+
}
|
|
92
|
+
if (options.instagramTrialReel && !VALID_TRIAL_REEL_MODES.includes(options.instagramTrialReel)) {
|
|
93
|
+
throw new Error(`Invalid instagram-trial-reel. Expected one of: ${VALID_TRIAL_REEL_MODES.join(", ")}.`);
|
|
94
|
+
}
|
|
95
|
+
if (Boolean(options.instagramLocationId) !== Boolean(options.instagramLocationName)) {
|
|
96
|
+
throw new Error("instagram-location-id and instagram-location-name must be provided together.");
|
|
97
|
+
}
|
|
98
|
+
if (Boolean(options.facebookLocationId) !== Boolean(options.facebookLocationName)) {
|
|
99
|
+
throw new Error("facebook-location-id and facebook-location-name must be provided together.");
|
|
100
|
+
}
|
|
76
101
|
|
|
77
102
|
const poll = {
|
|
78
103
|
...(options.pollQuestion ? { question: options.pollQuestion } : {}),
|
|
79
104
|
...(pollOptions.length > 0 ? { options: pollOptions } : {}),
|
|
80
105
|
...(options.pollPeriod ? { period: options.pollPeriod } : {}),
|
|
81
|
-
...(
|
|
82
|
-
? { correctOptionIndex:
|
|
83
|
-
: {}),
|
|
106
|
+
...(pollCorrectOptionIndex !== undefined
|
|
107
|
+
? { correctOptionIndex: pollCorrectOptionIndex }
|
|
108
|
+
: {}),
|
|
84
109
|
...(options.pollExplanation ? { explanation: options.pollExplanation } : {}),
|
|
85
110
|
};
|
|
86
111
|
|
|
@@ -101,8 +126,7 @@ function buildPostPayload(options) {
|
|
|
101
126
|
};
|
|
102
127
|
|
|
103
128
|
const facebook = {
|
|
104
|
-
...(options.
|
|
105
|
-
...(options.facebookLocationId || options.facebookLocationName
|
|
129
|
+
...(options.facebookLocationId || options.facebookLocationName
|
|
106
130
|
? {
|
|
107
131
|
location: {
|
|
108
132
|
...(options.facebookLocationId ? { id: options.facebookLocationId } : {}),
|
|
@@ -113,28 +137,75 @@ function buildPostPayload(options) {
|
|
|
113
137
|
};
|
|
114
138
|
|
|
115
139
|
const tiktok = {
|
|
116
|
-
...(parseBooleanStrict(options.tiktokSendToInbox, "tiktok-send-to-inbox") !== undefined
|
|
117
|
-
? { sendToInbox: parseBooleanStrict(options.tiktokSendToInbox, "tiktok-send-to-inbox") }
|
|
118
|
-
: {}),
|
|
140
|
+
...(parseBooleanStrict(options.tiktokSendToInbox, "tiktok-send-to-inbox") !== undefined
|
|
141
|
+
? { sendToInbox: parseBooleanStrict(options.tiktokSendToInbox, "tiktok-send-to-inbox") }
|
|
142
|
+
: {}),
|
|
143
|
+
...(parseBooleanStrict(options.tiktokAutoAddMusic, "tiktok-auto-add-music") !== undefined
|
|
144
|
+
? { autoAddMusic: parseBooleanStrict(options.tiktokAutoAddMusic, "tiktok-auto-add-music") }
|
|
145
|
+
: {}),
|
|
119
146
|
};
|
|
120
147
|
|
|
121
148
|
let youtubePlaylists;
|
|
122
|
-
if (options.youtubePlaylists) {
|
|
123
|
-
youtubePlaylists = parseJsonString(options.youtubePlaylists, "youtube-playlists");
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
149
|
+
if (options.youtubePlaylists) {
|
|
150
|
+
youtubePlaylists = parseJsonString(options.youtubePlaylists, "youtube-playlists");
|
|
151
|
+
if (!Array.isArray(youtubePlaylists)) {
|
|
152
|
+
throw new Error("Invalid youtube-playlists. Expected a JSON array.");
|
|
153
|
+
}
|
|
154
|
+
youtubePlaylists = youtubePlaylists.map((playlist) => ({
|
|
155
|
+
...playlist,
|
|
156
|
+
channelId: Number(playlist.channelId),
|
|
157
|
+
}));
|
|
158
|
+
if (youtubePlaylists.some((playlist) =>
|
|
159
|
+
!Number.isSafeInteger(playlist.channelId) ||
|
|
160
|
+
playlist.channelId < 1 ||
|
|
161
|
+
!Array.isArray(playlist.playlistIds)
|
|
162
|
+
)) {
|
|
163
|
+
throw new Error("Invalid youtube-playlists. Each item requires a positive integer channelId and playlistIds array.");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const youtube = {
|
|
168
|
+
...(options.youtubeTags
|
|
169
|
+
? {
|
|
170
|
+
tags: parseCsv(options.youtubeTags).map((tag) => {
|
|
171
|
+
validateOptionalLength(tag, 255, "youtube-tag");
|
|
172
|
+
return tag;
|
|
173
|
+
}),
|
|
174
|
+
}
|
|
175
|
+
: {}),
|
|
128
176
|
...(youtubePlaylists ? { playlists: youtubePlaylists } : {}),
|
|
129
|
-
};
|
|
177
|
+
};
|
|
178
|
+
const googlemybusiness = {
|
|
179
|
+
...(parseBooleanStrict(
|
|
180
|
+
options.googlemybusinessUploadToPhotosSection,
|
|
181
|
+
"googlemybusiness-upload-to-photos-section",
|
|
182
|
+
) !== undefined
|
|
183
|
+
? {
|
|
184
|
+
uploadToPhotosSection: parseBooleanStrict(
|
|
185
|
+
options.googlemybusinessUploadToPhotosSection,
|
|
186
|
+
"googlemybusiness-upload-to-photos-section",
|
|
187
|
+
),
|
|
188
|
+
}
|
|
189
|
+
: {}),
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const hasPoll = Object.keys(poll).length > 0;
|
|
193
|
+
if (!hasPoll && !options.caption) {
|
|
194
|
+
throw new Error("caption is required when poll is not provided.");
|
|
195
|
+
}
|
|
196
|
+
if (hasPoll && (!poll.question || poll.options?.length < 2 || !poll.period)) {
|
|
197
|
+
throw new Error("poll requires question, 2 to 4 options, and period.");
|
|
198
|
+
}
|
|
199
|
+
if (poll.options?.length > 4) {
|
|
200
|
+
throw new Error("Polls allow at most four options.");
|
|
201
|
+
}
|
|
130
202
|
|
|
131
203
|
return {
|
|
132
204
|
...(options.title ? { title: options.title } : {}),
|
|
133
205
|
...(options.caption ? { caption: options.caption } : {}),
|
|
134
206
|
...(options.alt ? { alt: options.alt } : {}),
|
|
135
207
|
...(options.link ? { link: validateHttpUrl(options.link, "link") } : {}),
|
|
136
|
-
|
|
137
|
-
publishMode,
|
|
208
|
+
publishMode,
|
|
138
209
|
scheduledAt,
|
|
139
210
|
...(parseBooleanStrict(options.postAsStory, "post-as-story") !== undefined
|
|
140
211
|
? { postAsStory: parseBooleanStrict(options.postAsStory, "post-as-story") }
|
|
@@ -143,21 +214,22 @@ function buildPostPayload(options) {
|
|
|
143
214
|
? {
|
|
144
215
|
comment: {
|
|
145
216
|
comment: options.comment,
|
|
146
|
-
...(
|
|
147
|
-
? { delay:
|
|
217
|
+
...(parseOptionalNonNegativeInteger(options.commentDelay, "comment-delay") !== undefined
|
|
218
|
+
? { delay: parseOptionalNonNegativeInteger(options.commentDelay, "comment-delay") }
|
|
148
219
|
: {}),
|
|
149
220
|
},
|
|
150
221
|
}
|
|
151
222
|
: {}),
|
|
152
223
|
...(media.length > 0 ? { media } : {}),
|
|
153
224
|
...(Object.keys(poll).length > 0 ? { poll } : {}),
|
|
154
|
-
...(Object.keys(instagram).length > 0 || Object.keys(facebook).length > 0 || Object.keys(tiktok).length > 0 || Object.keys(youtube).length > 0
|
|
225
|
+
...(Object.keys(instagram).length > 0 || Object.keys(facebook).length > 0 || Object.keys(tiktok).length > 0 || Object.keys(youtube).length > 0 || Object.keys(googlemybusiness).length > 0
|
|
155
226
|
? {
|
|
156
227
|
platforms: {
|
|
157
228
|
...(Object.keys(instagram).length > 0 ? { instagram } : {}),
|
|
158
229
|
...(Object.keys(facebook).length > 0 ? { facebook } : {}),
|
|
159
230
|
...(Object.keys(tiktok).length > 0 ? { tiktok } : {}),
|
|
160
|
-
...(Object.keys(youtube).length > 0 ? { youtube } : {}),
|
|
231
|
+
...(Object.keys(youtube).length > 0 ? { youtube } : {}),
|
|
232
|
+
...(Object.keys(googlemybusiness).length > 0 ? { googlemybusiness } : {}),
|
|
161
233
|
},
|
|
162
234
|
}
|
|
163
235
|
: {}),
|
package/src/validation.js
CHANGED
|
@@ -1,8 +1,37 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
|
|
3
3
|
const VALID_AUTOMATION_TYPES = ["FEED"];
|
|
4
|
-
const VALID_AUTOMATION_SUB_TYPES = [
|
|
5
|
-
|
|
4
|
+
const VALID_AUTOMATION_SUB_TYPES = [
|
|
5
|
+
"YOUTUBE",
|
|
6
|
+
"RSS",
|
|
7
|
+
"ATOM",
|
|
8
|
+
"MEDIUM",
|
|
9
|
+
"SHOPIFY",
|
|
10
|
+
"WORDPRESS",
|
|
11
|
+
"WOOCOMMERCE",
|
|
12
|
+
"ETSY",
|
|
13
|
+
"GHOST",
|
|
14
|
+
"SUBSTACK",
|
|
15
|
+
"ANCHOR",
|
|
16
|
+
"TRANSISTOR",
|
|
17
|
+
"CAPTIVATE",
|
|
18
|
+
"SOUNDCLOUD",
|
|
19
|
+
"BLOGGER",
|
|
20
|
+
"WIX",
|
|
21
|
+
"SQUARESPACEBLOG",
|
|
22
|
+
"SQUARESPACESHOP",
|
|
23
|
+
"WEEBLY",
|
|
24
|
+
"TUMBLR",
|
|
25
|
+
"SHOPIFY2",
|
|
26
|
+
"WOOCOMMERCE2",
|
|
27
|
+
"PRESTASHOP",
|
|
28
|
+
"BUZZSPROUT",
|
|
29
|
+
"RSSCOM",
|
|
30
|
+
"CASTOS",
|
|
31
|
+
"PODCASTCO",
|
|
32
|
+
];
|
|
33
|
+
const VALID_IMPORT_AS_TYPES = ["LINK", "IMAGE", "VIDEO", "CAROUSEL"];
|
|
34
|
+
const VALID_MEDIA_FILTER_TYPES = ["IMAGE", "VIDEO", "GIF", "APPLICATION", "DOCUMENT", "CSV"];
|
|
6
35
|
const SUPPORTED_MEDIA_TYPES = new Map([
|
|
7
36
|
[".jpg", "image/jpeg"],
|
|
8
37
|
[".jpeg", "image/jpeg"],
|
|
@@ -13,7 +42,7 @@ const SUPPORTED_MEDIA_TYPES = new Map([
|
|
|
13
42
|
[".mov", "video/quicktime"],
|
|
14
43
|
]);
|
|
15
44
|
const DEFAULT_MAX_MEDIA_SIZE_BYTES = Number(process.env.NUELINK_MAX_MEDIA_SIZE_BYTES || 100 * 1024 * 1024);
|
|
16
|
-
const QUEUE_SLOT_PATTERN = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun)
|
|
45
|
+
const QUEUE_SLOT_PATTERN = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) [0-2][0-9]:[0-5][0-9]$/;
|
|
17
46
|
const SQL_DATETIME_PATTERN = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
|
|
18
47
|
|
|
19
48
|
function splitCsv(value) {
|
|
@@ -53,14 +82,40 @@ function parsePositiveInteger(value, label) {
|
|
|
53
82
|
return parsed;
|
|
54
83
|
}
|
|
55
84
|
|
|
56
|
-
function parseOptionalPositiveInteger(value, label) {
|
|
85
|
+
function parseOptionalPositiveInteger(value, label) {
|
|
57
86
|
if (value === undefined || value === null || value === "") {
|
|
58
87
|
return undefined;
|
|
59
88
|
}
|
|
60
89
|
|
|
61
90
|
return parsePositiveInteger(value, label);
|
|
62
|
-
}
|
|
63
|
-
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function parseOptionalNonNegativeInteger(value, label) {
|
|
94
|
+
if (value === undefined || value === null || value === "") {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const normalized = String(value).trim();
|
|
99
|
+
if (!/^\d+$/.test(normalized)) {
|
|
100
|
+
throw new Error(`Invalid ${label}. Expected a non-negative integer.`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const parsed = Number(normalized);
|
|
104
|
+
if (!Number.isSafeInteger(parsed)) {
|
|
105
|
+
throw new Error(`Invalid ${label}. Expected a non-negative integer.`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return parsed;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function parseIntegerInRange(value, label, minimum, maximum) {
|
|
112
|
+
const parsed = parsePositiveInteger(value, label);
|
|
113
|
+
if (parsed < minimum || parsed > maximum) {
|
|
114
|
+
throw new Error(`Invalid ${label}. Expected an integer from ${minimum} to ${maximum}.`);
|
|
115
|
+
}
|
|
116
|
+
return parsed;
|
|
117
|
+
}
|
|
118
|
+
|
|
64
119
|
function parseBooleanStrict(value, label) {
|
|
65
120
|
if (value === undefined || value === null || value === "") {
|
|
66
121
|
return undefined;
|
|
@@ -113,15 +168,11 @@ function validateScheduledAt(value) {
|
|
|
113
168
|
|
|
114
169
|
const normalized = String(value).trim();
|
|
115
170
|
|
|
116
|
-
if (SQL_DATETIME_PATTERN.test(normalized)) {
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
throw new Error("Invalid scheduled-at. Expected YYYY-MM-DD HH:mm:ss or an ISO 8601 datetime.");
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return normalized;
|
|
171
|
+
if (!SQL_DATETIME_PATTERN.test(normalized)) {
|
|
172
|
+
throw new Error("Invalid scheduled-at. Expected YYYY-MM-DD HH:mm:ss.");
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return normalized;
|
|
125
176
|
}
|
|
126
177
|
|
|
127
178
|
function validatePollOptions(options, correctOptionIndex) {
|
|
@@ -169,12 +220,15 @@ function validateMediaFile(filePath, fileStat) {
|
|
|
169
220
|
}
|
|
170
221
|
|
|
171
222
|
export {
|
|
172
|
-
VALID_AUTOMATION_SUB_TYPES,
|
|
173
|
-
VALID_AUTOMATION_TYPES,
|
|
174
|
-
VALID_IMPORT_AS_TYPES,
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
223
|
+
VALID_AUTOMATION_SUB_TYPES,
|
|
224
|
+
VALID_AUTOMATION_TYPES,
|
|
225
|
+
VALID_IMPORT_AS_TYPES,
|
|
226
|
+
VALID_MEDIA_FILTER_TYPES,
|
|
227
|
+
parseBooleanStrict,
|
|
228
|
+
parseIntegerInRange,
|
|
229
|
+
parseJsonString,
|
|
230
|
+
parseOptionalNonNegativeInteger,
|
|
231
|
+
parseOptionalPositiveInteger,
|
|
178
232
|
parsePositiveInteger,
|
|
179
233
|
splitCsv,
|
|
180
234
|
validateHttpUrl,
|
|
@@ -183,4 +237,4 @@ export {
|
|
|
183
237
|
validateScheduledAt,
|
|
184
238
|
validateQueueSlots,
|
|
185
239
|
normalizeEnum,
|
|
186
|
-
};
|
|
240
|
+
};
|