@nuelink/nuelink-cli 1.3.6 → 1.3.8

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuelink/nuelink-cli",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
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/cli.js CHANGED
@@ -11,10 +11,6 @@ const parsedAuth = extractApiKeyArg(process.argv.slice(2));
11
11
  const runtimeApiKey = parsedAuth.apiKey;
12
12
  const parseArgv = [process.argv[0], process.argv[1], ...parsedAuth.sanitizedArgs];
13
13
 
14
- if (!process.env.NUELINK_API_KEY && runtimeApiKey) {
15
- process.env.NUELINK_API_KEY = runtimeApiKey;
16
- }
17
-
18
14
  registerCommands(program, runtimeApiKey, cliVersion);
19
15
 
20
16
  const argvHasCommand = parsedAuth.sanitizedArgs.some((arg) => !arg.startsWith("-"));
@@ -22,6 +18,11 @@ const hasHelpFlag = parsedAuth.sanitizedArgs.includes("--help") || parsedAuth.sa
22
18
  const hasVersionFlag = parsedAuth.sanitizedArgs.includes("--version") || parsedAuth.sanitizedArgs.includes("-V");
23
19
 
24
20
  if (!argvHasCommand && !hasHelpFlag && !hasVersionFlag) {
21
+ if (runtimeApiKey) {
22
+ console.error("Missing command. Provide a command such as 'me' or 'auth:login'.");
23
+ process.exit(1);
24
+ }
25
+
25
26
  program.outputHelp();
26
27
  process.exit(0);
27
28
  }
package/src/commands.js CHANGED
@@ -1,4 +1,4 @@
1
- import { readFile, stat } from "node:fs/promises";
1
+ import { readFile, stat } from "node:fs/promises";
2
2
  import readline from "node:readline";
3
3
  import path from "node:path";
4
4
  import chalk from "chalk";
@@ -7,15 +7,16 @@ import { clearApiKey, maskToken, readConfig, resolveApiKey, CONFIG_FILE, decrypt
7
7
  import { brandPath, collectionPath, nuelinkRequest } from "./http.js";
8
8
  import { buildPostPayload, parseCsv, VALID_PUBLISH_MODES } from "./postPayload.js";
9
9
  import {
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,
10
+ VALID_AUTOMATION_SUB_TYPES,
11
+ VALID_AUTOMATION_TYPES,
12
+ VALID_IMPORT_AS_TYPES,
13
+ VALID_MEDIA_FILTER_TYPES,
14
+ normalizeEnum,
15
+ parseBooleanStrict,
16
+ parseIntegerInRange,
17
+ parseJsonString,
18
+ parseOptionalNonNegativeInteger,
19
+ parsePositiveInteger,
19
20
  splitCsv,
20
21
  validateHttpUrl,
21
22
  validateMediaFile,
@@ -137,9 +138,9 @@ async function promptHidden(promptText) {
137
138
  });
138
139
  }
139
140
 
140
- async function resolveLoginApiKey(options) {
141
- if (options.apiKey) {
142
- return options.apiKey.trim();
141
+ async function resolveLoginApiKey(options, fallbackApiKey) {
142
+ if (options.apiKey || fallbackApiKey) {
143
+ return String(options.apiKey || fallbackApiKey).trim();
143
144
  }
144
145
 
145
146
  if (options.stdin || !process.stdin.isTTY) {
@@ -149,7 +150,7 @@ async function resolveLoginApiKey(options) {
149
150
  return promptHidden("API key: ");
150
151
  }
151
152
 
152
- function buildRequestOptions(program) {
153
+ function buildRequestOptions(program) {
153
154
  const options = program.opts();
154
155
 
155
156
  return {
@@ -157,15 +158,15 @@ function buildRequestOptions(program) {
157
158
  outputMode: options.json ? "json" : "table",
158
159
  quiet: Boolean(options.quiet),
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
+ }
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
+
169
170
  async function executeRequest(program, runtimeApiKey, request) {
170
171
  const requestOptions = buildRequestOptions(program);
171
172
  const apiKey = requestOptions.dryRun ? undefined : await resolveApiKey(runtimeApiKey);
@@ -205,7 +206,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
205
206
  .option("--api-key <apiKey>", "API key to save (prefer stdin or interactive prompt)")
206
207
  .option("--stdin", "Read API key from stdin")
207
208
  .action(withCommandErrorHandling(async (options) => {
208
- const apiKey = await resolveLoginApiKey(options);
209
+ const apiKey = await resolveLoginApiKey(options, runtimeApiKey);
209
210
 
210
211
  if (!apiKey) {
211
212
  throw new Error("Missing API key. Provide --stdin, pipe a key to auth:login, or enter it interactively.");
@@ -228,13 +229,13 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
228
229
  .command("auth:status")
229
230
  .description("Show where auth is currently resolved from")
230
231
  .action(withCommandErrorHandling(async () => {
231
- if (process.env.NUELINK_API_KEY) {
232
- console.log(chalk.green(`Auth source: NUELINK_API_KEY (${maskToken(process.env.NUELINK_API_KEY)})`));
232
+ if (runtimeApiKey) {
233
+ console.log(chalk.green(`Auth source: runtime CLI flag (${maskToken(runtimeApiKey)})`));
233
234
  return;
234
235
  }
235
236
 
236
- if (runtimeApiKey) {
237
- console.log(chalk.green(`Auth source: runtime CLI flag (${maskToken(runtimeApiKey)})`));
237
+ if (process.env.NUELINK_API_KEY) {
238
+ console.log(chalk.green(`Auth source: NUELINK_API_KEY (${maskToken(process.env.NUELINK_API_KEY)})`));
238
239
  return;
239
240
  }
240
241
 
@@ -255,6 +256,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
255
256
  }
256
257
 
257
258
  console.log(chalk.yellow("No API key configured. Use auth:login to save one, or pass --api-key for a single command."));
259
+ process.exitCode = 1;
258
260
  }));
259
261
 
260
262
  program
@@ -273,7 +275,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
273
275
  await executeRequest(program, runtimeApiKey, {
274
276
  endpoint: "/brands",
275
277
  query: {
276
- per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
278
+ per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
277
279
  page: parsePositiveInteger(options.page, "page"),
278
280
  },
279
281
  });
@@ -289,7 +291,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
289
291
  await executeRequest(program, runtimeApiKey, {
290
292
  endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/collections`,
291
293
  query: {
292
- per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
294
+ per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
293
295
  page: parsePositiveInteger(options.page, "page"),
294
296
  },
295
297
  });
@@ -312,9 +314,9 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
312
314
  method: "POST",
313
315
  endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/collections`,
314
316
  body: {
315
- title: validateMaxLength(options.title, 255, "title"),
316
- description: validateMaxLength(options.description, 1000, "description"),
317
- maxRepublish: parseOptionalNonNegativeInteger(options.maxRepublish, "max-republish"),
317
+ title: validateMaxLength(options.title, 255, "title"),
318
+ description: validateMaxLength(options.description, 1000, "description"),
319
+ maxRepublish: parseOptionalNonNegativeInteger(options.maxRepublish, "max-republish"),
318
320
  channels,
319
321
  queues,
320
322
  },
@@ -331,7 +333,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
331
333
  await executeRequest(program, runtimeApiKey, {
332
334
  endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/automations`,
333
335
  query: {
334
- per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
336
+ per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
335
337
  page: parsePositiveInteger(options.page, "page"),
336
338
  },
337
339
  });
@@ -347,12 +349,12 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
347
349
  .requiredOption("--sub-type <type>", "Sub type, e.g. RSS")
348
350
  .requiredOption("--title <title>", "Automation title")
349
351
  .option("--type <type>", "Automation type", "FEED")
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)")
352
+ .option("--dynamic-title <text>", "Dynamic title", "{{title}}")
353
+ .option("--dynamic-body <text>", "Dynamic body", "{title} {link}")
354
+ .option("--description <text>", "Automation description")
355
+ .option("--load-old-posts <boolean>", "Import existing feed items: true/false")
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)")
356
358
  .action(withCommandErrorHandling(async (options) => {
357
359
  await executeRequest(program, runtimeApiKey, {
358
360
  method: "POST",
@@ -362,17 +364,17 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
362
364
  feedUrl: validateHttpUrl(options.feedUrl, "feed-url"),
363
365
  importAsType: normalizeEnum(options.importAsType, "import-as-type", VALID_IMPORT_AS_TYPES),
364
366
  subType: normalizeEnum(options.subType, "sub-type", VALID_AUTOMATION_SUB_TYPES),
365
- title: validateMaxLength(options.title, 255, "title"),
367
+ title: validateMaxLength(options.title, 255, "title"),
366
368
  type: normalizeEnum(options.type, "type", VALID_AUTOMATION_TYPES),
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
- },
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
+ },
376
378
  });
377
379
  }));
378
380
 
@@ -386,7 +388,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
386
388
  await executeRequest(program, runtimeApiKey, {
387
389
  endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/channels`,
388
390
  query: {
389
- per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
391
+ per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
390
392
  page: parsePositiveInteger(options.page, "page"),
391
393
  },
392
394
  });
@@ -395,19 +397,19 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
395
397
  program
396
398
  .command("media")
397
399
  .description("List media for a brand")
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")
400
+ .requiredOption("--brand-id <id>", "Brand ID")
401
+ .option("--type <type>", `Media type filter (${VALID_MEDIA_FILTER_TYPES.join(", ")})`)
402
+ .option("--per-page <number>", "Items per page", "25")
401
403
  .option("--page <number>", "Page number", "1")
402
404
  .action(withCommandErrorHandling(async (options) => {
403
405
  await executeRequest(program, runtimeApiKey, {
404
406
  endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/media`,
405
407
  query: {
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,
408
+ per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
409
+ page: parsePositiveInteger(options.page, "page"),
410
+ type: options.type
411
+ ? normalizeEnum(options.type, "type", VALID_MEDIA_FILTER_TYPES)
412
+ : undefined,
411
413
  },
412
414
  });
413
415
  }));
@@ -422,8 +424,8 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
422
424
  const fileStat = await stat(options.file);
423
425
  const { mediaType, size } = validateMediaFile(options.file, fileStat);
424
426
  const formData = new FormData();
425
- const fileBuffer = await readFile(options.file);
426
- const fileBlob = new Blob([fileBuffer], { type: mediaType });
427
+ const fileBuffer = await readFile(options.file);
428
+ const fileBlob = new Blob([fileBuffer], { type: mediaType });
427
429
  formData.append("media", fileBlob, path.basename(options.file));
428
430
 
429
431
  await executeRequest(program, runtimeApiKey, {
@@ -452,7 +454,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
452
454
  parsePositiveInteger(options.collectionId, "collection-id"),
453
455
  )}/posts`,
454
456
  query: {
455
- per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
457
+ per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
456
458
  page: parsePositiveInteger(options.page, "page"),
457
459
  },
458
460
  });
@@ -470,6 +472,10 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
470
472
  : await readFile(options.payload, "utf8");
471
473
  const payload = parseJsonString(payloadText, "payload");
472
474
 
475
+ if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
476
+ throw new Error("Invalid payload. Expected a JSON object.");
477
+ }
478
+
473
479
  await executeRequest(program, runtimeApiKey, {
474
480
  method: "POST",
475
481
  endpoint: `${collectionPath(
@@ -490,8 +496,8 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
490
496
  .option("--alt <text>", "Alt text")
491
497
  .option("--link <url>", "Post link")
492
498
  .option("--publish-mode <mode>", `Publish mode (${VALID_PUBLISH_MODES.join(", ")})`, "DRAFT")
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")
499
+ .option("--scheduled-at <value>", "Publish datetime (YYYY-MM-DD HH:mm:ss) or null")
500
+ .option("--post-as-story <boolean>", "Post as story: true/false")
495
501
  .option("--comment <text>", "First comment")
496
502
  .option("--comment-delay <seconds>", "First comment delay seconds")
497
503
  .option("--media-ids <ids>", "Comma-separated media IDs")
@@ -499,20 +505,20 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
499
505
  .option("--poll-question <text>", "Poll question")
500
506
  .option("--poll-options <items>", "Comma-separated poll options")
501
507
  .option("--poll-period <value>", "Poll period (e.g. 3d)")
502
- .option("--poll-correct-option-index <number>", "Zero-based poll correct option index")
508
+ .option("--poll-correct-option-index <number>", "Zero-based poll correct option index")
503
509
  .option("--poll-explanation <text>", "Poll explanation")
504
510
  .option("--instagram-collab <username>", "Instagram collab username")
505
511
  .option("--instagram-location-id <id>", "Instagram location ID")
506
512
  .option("--instagram-location-name <name>", "Instagram location name")
507
513
  .option("--instagram-trial-reel <mode>", "Instagram trial reel mode")
508
514
  .option("--instagram-share-to-feed <boolean>", "Instagram share to feed true/false")
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")
515
+ .option("--facebook-location-id <id>", "Facebook location ID")
516
+ .option("--facebook-location-name <name>", "Facebook location name")
517
+ .option("--tiktok-send-to-inbox <boolean>", "TikTok send to inbox true/false")
518
+ .option("--tiktok-auto-add-music <boolean>", "TikTok auto-add music: true/false")
519
+ .option("--youtube-tags <tags>", "Comma-separated YouTube tags")
520
+ .option("--youtube-playlists <json>", "YouTube playlists JSON string")
521
+ .option("--googlemybusiness-upload-to-photos-section <boolean>", "Upload to Google Business Profile photos: true/false")
516
522
  .action(withCommandErrorHandling(async (options) => {
517
523
  const payload = buildPostPayload(options);
518
524
 
package/src/config.js CHANGED
@@ -79,15 +79,14 @@ async function clearApiKey() {
79
79
  }
80
80
 
81
81
  async function resolveApiKey(runtimeApiKey) {
82
- if (process.env.NUELINK_API_KEY) {
83
- return process.env.NUELINK_API_KEY;
84
- }
85
-
86
82
  if (runtimeApiKey) {
87
- process.env.NUELINK_API_KEY = runtimeApiKey;
88
83
  return runtimeApiKey;
89
84
  }
90
85
 
86
+ if (process.env.NUELINK_API_KEY) {
87
+ return process.env.NUELINK_API_KEY;
88
+ }
89
+
91
90
  const config = await readConfig();
92
91
  const storedApiKey = decryptApiKey(config);
93
92
 
package/src/validation.js CHANGED
@@ -1,37 +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
- "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"];
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"];
35
35
  const SUPPORTED_MEDIA_TYPES = new Map([
36
36
  [".jpg", "image/jpeg"],
37
37
  [".jpeg", "image/jpeg"],
@@ -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][0-9]:[0-5][0-9]$/;
45
+ const QUEUE_SLOT_PATTERN = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) [0-2][0-9]:[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) {
@@ -82,40 +82,40 @@ function parsePositiveInteger(value, label) {
82
82
  return parsed;
83
83
  }
84
84
 
85
- function parseOptionalPositiveInteger(value, label) {
85
+ function parseOptionalPositiveInteger(value, label) {
86
86
  if (value === undefined || value === null || value === "") {
87
87
  return undefined;
88
88
  }
89
89
 
90
90
  return parsePositiveInteger(value, label);
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
-
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
+
119
119
  function parseBooleanStrict(value, label) {
120
120
  if (value === undefined || value === null || value === "") {
121
121
  return undefined;
@@ -168,11 +168,27 @@ function validateScheduledAt(value) {
168
168
 
169
169
  const normalized = String(value).trim();
170
170
 
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;
171
+ if (!SQL_DATETIME_PATTERN.test(normalized)) {
172
+ throw new Error("Invalid scheduled-at. Expected YYYY-MM-DD HH:mm:ss.");
173
+ }
174
+
175
+ const [datePart, timePart] = normalized.split(" ");
176
+ const [year, month, day] = datePart.split("-").map(Number);
177
+ const [hours, minutes, seconds] = timePart.split(":").map(Number);
178
+
179
+ const date = new Date(Date.UTC(year, month - 1, day, hours, minutes, seconds));
180
+ const isValidDate = date.getUTCFullYear() === year
181
+ && date.getUTCMonth() === month - 1
182
+ && date.getUTCDate() === day
183
+ && date.getUTCHours() === hours
184
+ && date.getUTCMinutes() === minutes
185
+ && date.getUTCSeconds() === seconds;
186
+
187
+ if (!isValidDate) {
188
+ throw new Error("Invalid scheduled-at. Expected a real calendar date and time.");
189
+ }
190
+
191
+ return normalized;
176
192
  }
177
193
 
178
194
  function validatePollOptions(options, correctOptionIndex) {
@@ -220,15 +236,15 @@ function validateMediaFile(filePath, fileStat) {
220
236
  }
221
237
 
222
238
  export {
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,
239
+ VALID_AUTOMATION_SUB_TYPES,
240
+ VALID_AUTOMATION_TYPES,
241
+ VALID_IMPORT_AS_TYPES,
242
+ VALID_MEDIA_FILTER_TYPES,
243
+ parseBooleanStrict,
244
+ parseIntegerInRange,
245
+ parseJsonString,
246
+ parseOptionalNonNegativeInteger,
247
+ parseOptionalPositiveInteger,
232
248
  parsePositiveInteger,
233
249
  splitCsv,
234
250
  validateHttpUrl,
@@ -237,4 +253,4 @@ export {
237
253
  validateScheduledAt,
238
254
  validateQueueSlots,
239
255
  normalizeEnum,
240
- };
256
+ };