@nuelink/nuelink-cli 1.3.4 → 1.3.5

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 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 1 \
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-collab "karim.chamlal" \
266
- --facebook-location-id "abc123" \
267
- --facebook-location-name "bentaib" \
268
- --tiktok-send-to-inbox true \
269
- --youtube-tags "tag1,tag2,tag3" \
270
- --youtube-playlists '[{"channelId":"1","playlistIds":["1","2"]}]'
271
- ```
272
-
273
- Supported publish modes are `DRAFT`, `QUEUE`, `SCHEDULE`, and `IMMEDIATE`. When using `SCHEDULE`, pass `--scheduled-at`.
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.4",
3
+ "version": "1.3.5",
4
4
  "description": "The official Nuelink CLI for automating social media workflows from your terminal. Schedule posts, upload media, manage brands, and integrate Nuelink into scripts, CI/CD pipelines, and AI agents.",
5
5
  "license": "MIT",
6
6
  "author": "Nuelink",
package/src/commands.js CHANGED
@@ -8,13 +8,15 @@ import { clearApiKey, maskToken, readConfig, resolveApiKey, CONFIG_FILE, decrypt
8
8
  import { brandPath, collectionPath, nuelinkRequest } from "./http.js";
9
9
  import { buildPostPayload, parseCsv, VALID_PUBLISH_MODES } from "./postPayload.js";
10
10
  import {
11
- VALID_AUTOMATION_SUB_TYPES,
12
- VALID_AUTOMATION_TYPES,
13
- VALID_IMPORT_AS_TYPES,
14
- normalizeEnum,
15
- parseJsonString,
16
- parseOptionalPositiveInteger,
17
- parsePositiveInteger,
11
+ VALID_AUTOMATION_SUB_TYPES,
12
+ VALID_AUTOMATION_TYPES,
13
+ VALID_IMPORT_AS_TYPES,
14
+ VALID_MEDIA_FILTER_TYPES,
15
+ normalizeEnum,
16
+ parseIntegerInRange,
17
+ parseJsonString,
18
+ parseOptionalNonNegativeInteger,
19
+ parsePositiveInteger,
18
20
  splitCsv,
19
21
  validateHttpUrl,
20
22
  validateMediaFile,
@@ -148,7 +150,7 @@ async function resolveLoginApiKey(options) {
148
150
  return promptHidden("API key: ");
149
151
  }
150
152
 
151
- function buildRequestOptions(program) {
153
+ function buildRequestOptions(program) {
152
154
  const options = program.opts();
153
155
 
154
156
  return {
@@ -156,8 +158,15 @@ function buildRequestOptions(program) {
156
158
  outputMode: options.json ? "json" : "table",
157
159
  quiet: Boolean(options.quiet),
158
160
  };
159
- }
160
-
161
+ }
162
+
163
+ function validateMaxLength(value, maximum, label) {
164
+ if (value !== undefined && value !== null && String(value).length > maximum) {
165
+ throw new Error(`${label} must not exceed ${maximum} characters.`);
166
+ }
167
+ return value;
168
+ }
169
+
161
170
  async function executeRequest(program, runtimeApiKey, request) {
162
171
  const requestOptions = buildRequestOptions(program);
163
172
  const apiKey = requestOptions.dryRun ? undefined : await resolveApiKey(runtimeApiKey);
@@ -265,7 +274,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
265
274
  await executeRequest(program, runtimeApiKey, {
266
275
  endpoint: "/brands",
267
276
  query: {
268
- per_page: parsePositiveInteger(options.perPage, "per-page"),
277
+ per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
269
278
  page: parsePositiveInteger(options.page, "page"),
270
279
  },
271
280
  });
@@ -281,7 +290,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
281
290
  await executeRequest(program, runtimeApiKey, {
282
291
  endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/collections`,
283
292
  query: {
284
- per_page: parsePositiveInteger(options.perPage, "per-page"),
293
+ per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
285
294
  page: parsePositiveInteger(options.page, "page"),
286
295
  },
287
296
  });
@@ -304,9 +313,9 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
304
313
  method: "POST",
305
314
  endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/collections`,
306
315
  body: {
307
- title: options.title,
308
- description: options.description,
309
- maxRepublish: parseOptionalPositiveInteger(options.maxRepublish, "max-republish"),
316
+ title: validateMaxLength(options.title, 255, "title"),
317
+ description: validateMaxLength(options.description, 1000, "description"),
318
+ maxRepublish: parseOptionalNonNegativeInteger(options.maxRepublish, "max-republish"),
310
319
  channels,
311
320
  queues,
312
321
  },
@@ -323,7 +332,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
323
332
  await executeRequest(program, runtimeApiKey, {
324
333
  endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/automations`,
325
334
  query: {
326
- per_page: parsePositiveInteger(options.perPage, "per-page"),
335
+ per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
327
336
  page: parsePositiveInteger(options.page, "page"),
328
337
  },
329
338
  });
@@ -339,9 +348,12 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
339
348
  .requiredOption("--sub-type <type>", "Sub type, e.g. RSS")
340
349
  .requiredOption("--title <title>", "Automation title")
341
350
  .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")
351
+ .option("--dynamic-title <text>", "Dynamic title", "{{title}}")
352
+ .option("--dynamic-body <text>", "Dynamic body", "{title} {link}")
353
+ .option("--description <text>", "Automation description")
354
+ .option("--load-old-posts <boolean>", "Import existing feed items: true/false")
355
+ .option("--add-posts-as-draft <boolean>", "Create imported posts as drafts: true/false")
356
+ .option("--refresh-rate <hours>", "Refresh interval (24, 12, 6, or 1 hours)")
345
357
  .action(withCommandErrorHandling(async (options) => {
346
358
  await executeRequest(program, runtimeApiKey, {
347
359
  method: "POST",
@@ -351,12 +363,17 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
351
363
  feedUrl: validateHttpUrl(options.feedUrl, "feed-url"),
352
364
  importAsType: normalizeEnum(options.importAsType, "import-as-type", VALID_IMPORT_AS_TYPES),
353
365
  subType: normalizeEnum(options.subType, "sub-type", VALID_AUTOMATION_SUB_TYPES),
354
- title: options.title,
366
+ title: validateMaxLength(options.title, 255, "title"),
355
367
  type: normalizeEnum(options.type, "type", VALID_AUTOMATION_TYPES),
356
- dynamicTitle: options.dynamicTitle,
357
- dynamicBody: options.dynamicBody,
358
- description: options.description,
359
- },
368
+ dynamicTitle: validateMaxLength(options.dynamicTitle, 255, "dynamic-title"),
369
+ dynamicBody: validateMaxLength(options.dynamicBody, 255, "dynamic-body"),
370
+ description: options.description,
371
+ loadOldPosts: parseBooleanStrict(options.loadOldPosts, "load-old-posts"),
372
+ addPostsAsDraft: parseBooleanStrict(options.addPostsAsDraft, "add-posts-as-draft"),
373
+ refreshRate: options.refreshRate === undefined
374
+ ? undefined
375
+ : Number(normalizeEnum(options.refreshRate, "refresh-rate", ["24", "12", "6", "1"])),
376
+ },
360
377
  });
361
378
  }));
362
379
 
@@ -370,7 +387,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
370
387
  await executeRequest(program, runtimeApiKey, {
371
388
  endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/channels`,
372
389
  query: {
373
- per_page: parsePositiveInteger(options.perPage, "per-page"),
390
+ per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
374
391
  page: parsePositiveInteger(options.page, "page"),
375
392
  },
376
393
  });
@@ -379,15 +396,19 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
379
396
  program
380
397
  .command("media")
381
398
  .description("List media for a brand")
382
- .requiredOption("--brand-id <id>", "Brand ID")
383
- .option("--per-page <number>", "Items per page", "25")
399
+ .requiredOption("--brand-id <id>", "Brand ID")
400
+ .option("--type <type>", `Media type filter (${VALID_MEDIA_FILTER_TYPES.join(", ")})`)
401
+ .option("--per-page <number>", "Items per page", "25")
384
402
  .option("--page <number>", "Page number", "1")
385
403
  .action(withCommandErrorHandling(async (options) => {
386
404
  await executeRequest(program, runtimeApiKey, {
387
405
  endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/media`,
388
406
  query: {
389
- per_page: parsePositiveInteger(options.perPage, "per-page"),
390
- page: parsePositiveInteger(options.page, "page"),
407
+ per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
408
+ page: parsePositiveInteger(options.page, "page"),
409
+ type: options.type
410
+ ? normalizeEnum(options.type, "type", VALID_MEDIA_FILTER_TYPES)
411
+ : undefined,
391
412
  },
392
413
  });
393
414
  }));
@@ -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: parsePositiveInteger(options.perPage, "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 or ISO) or null")
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>", "Poll correct option index")
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-collab <username>", "Facebook collab username")
490
- .option("--facebook-location-id <id>", "Facebook location ID")
491
- .option("--facebook-location-name <name>", "Facebook location name")
492
- .option("--tiktok-send-to-inbox <boolean>", "TikTok send to inbox true/false")
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
 
@@ -1,14 +1,22 @@
1
1
  import {
2
- parseBooleanStrict,
3
- parseJsonString,
4
- parseOptionalPositiveInteger,
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 = parseOptionalPositiveInteger(options.pollCorrectOptionIndex, "poll-correct-option-index");
71
- const zeroBasedCorrectOptionIndex = pollCorrectOptionIndex !== undefined
72
- ? pollCorrectOptionIndex - 1
73
- : undefined;
74
-
75
- validatePollOptions(pollOptions, zeroBasedCorrectOptionIndex);
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
- ...(zeroBasedCorrectOptionIndex !== undefined
82
- ? { correctOptionIndex: zeroBasedCorrectOptionIndex }
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.facebookCollab ? { collab: options.facebookCollab } : {}),
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
- const youtube = {
127
- ...(options.youtubeTags ? { tags: parseCsv(options.youtubeTags) } : {}),
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
- ...(options.postType ? { postType: options.postType } : {}),
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
- ...(parseOptionalPositiveInteger(options.commentDelay, "comment-delay") !== undefined
147
- ? { delay: parseOptionalPositiveInteger(options.commentDelay, "comment-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 = ["RSS"];
5
- const VALID_IMPORT_AS_TYPES = ["IMAGE", "VIDEO", "CAROUSEL", "TEXT"];
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)\s\d{2}:\d{2}$/;
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
- return normalized;
118
- }
119
-
120
- if (Number.isNaN(Date.parse(normalized))) {
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
- parseBooleanStrict,
176
- parseJsonString,
177
- parseOptionalPositiveInteger,
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
+ };