@nuelink/nuelink-cli 1.3.5 → 1.3.7

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.5",
3
+ "version": "1.3.7",
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": "^15.0.0"
28
+ "commander": "^13.1.0"
29
29
  },
30
30
  "bin": {
31
31
  "nuelink-cli": "./src/cli.js"
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,3 @@
1
- import { openAsBlob } from "node:fs";
2
1
  import { readFile, stat } from "node:fs/promises";
3
2
  import readline from "node:readline";
4
3
  import path from "node:path";
@@ -8,15 +7,16 @@ 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
- VALID_MEDIA_FILTER_TYPES,
15
- normalizeEnum,
16
- parseIntegerInRange,
17
- parseJsonString,
18
- parseOptionalNonNegativeInteger,
19
- 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,
20
20
  splitCsv,
21
21
  validateHttpUrl,
22
22
  validateMediaFile,
@@ -138,9 +138,9 @@ async function promptHidden(promptText) {
138
138
  });
139
139
  }
140
140
 
141
- async function resolveLoginApiKey(options) {
142
- if (options.apiKey) {
143
- return options.apiKey.trim();
141
+ async function resolveLoginApiKey(options, fallbackApiKey) {
142
+ if (options.apiKey || fallbackApiKey) {
143
+ return String(options.apiKey || fallbackApiKey).trim();
144
144
  }
145
145
 
146
146
  if (options.stdin || !process.stdin.isTTY) {
@@ -150,7 +150,7 @@ async function resolveLoginApiKey(options) {
150
150
  return promptHidden("API key: ");
151
151
  }
152
152
 
153
- function buildRequestOptions(program) {
153
+ function buildRequestOptions(program) {
154
154
  const options = program.opts();
155
155
 
156
156
  return {
@@ -158,15 +158,15 @@ function buildRequestOptions(program) {
158
158
  outputMode: options.json ? "json" : "table",
159
159
  quiet: Boolean(options.quiet),
160
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
+ }
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
+
170
170
  async function executeRequest(program, runtimeApiKey, request) {
171
171
  const requestOptions = buildRequestOptions(program);
172
172
  const apiKey = requestOptions.dryRun ? undefined : await resolveApiKey(runtimeApiKey);
@@ -206,7 +206,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
206
206
  .option("--api-key <apiKey>", "API key to save (prefer stdin or interactive prompt)")
207
207
  .option("--stdin", "Read API key from stdin")
208
208
  .action(withCommandErrorHandling(async (options) => {
209
- const apiKey = await resolveLoginApiKey(options);
209
+ const apiKey = await resolveLoginApiKey(options, runtimeApiKey);
210
210
 
211
211
  if (!apiKey) {
212
212
  throw new Error("Missing API key. Provide --stdin, pipe a key to auth:login, or enter it interactively.");
@@ -229,13 +229,13 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
229
229
  .command("auth:status")
230
230
  .description("Show where auth is currently resolved from")
231
231
  .action(withCommandErrorHandling(async () => {
232
- if (process.env.NUELINK_API_KEY) {
233
- 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)})`));
234
234
  return;
235
235
  }
236
236
 
237
- if (runtimeApiKey) {
238
- 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)})`));
239
239
  return;
240
240
  }
241
241
 
@@ -256,6 +256,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
256
256
  }
257
257
 
258
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;
259
260
  }));
260
261
 
261
262
  program
@@ -274,7 +275,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
274
275
  await executeRequest(program, runtimeApiKey, {
275
276
  endpoint: "/brands",
276
277
  query: {
277
- per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
278
+ per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
278
279
  page: parsePositiveInteger(options.page, "page"),
279
280
  },
280
281
  });
@@ -290,7 +291,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
290
291
  await executeRequest(program, runtimeApiKey, {
291
292
  endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/collections`,
292
293
  query: {
293
- per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
294
+ per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
294
295
  page: parsePositiveInteger(options.page, "page"),
295
296
  },
296
297
  });
@@ -313,9 +314,9 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
313
314
  method: "POST",
314
315
  endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/collections`,
315
316
  body: {
316
- title: validateMaxLength(options.title, 255, "title"),
317
- description: validateMaxLength(options.description, 1000, "description"),
318
- 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"),
319
320
  channels,
320
321
  queues,
321
322
  },
@@ -332,7 +333,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
332
333
  await executeRequest(program, runtimeApiKey, {
333
334
  endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/automations`,
334
335
  query: {
335
- per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
336
+ per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
336
337
  page: parsePositiveInteger(options.page, "page"),
337
338
  },
338
339
  });
@@ -348,12 +349,12 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
348
349
  .requiredOption("--sub-type <type>", "Sub type, e.g. RSS")
349
350
  .requiredOption("--title <title>", "Automation title")
350
351
  .option("--type <type>", "Automation type", "FEED")
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)")
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)")
357
358
  .action(withCommandErrorHandling(async (options) => {
358
359
  await executeRequest(program, runtimeApiKey, {
359
360
  method: "POST",
@@ -363,17 +364,17 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
363
364
  feedUrl: validateHttpUrl(options.feedUrl, "feed-url"),
364
365
  importAsType: normalizeEnum(options.importAsType, "import-as-type", VALID_IMPORT_AS_TYPES),
365
366
  subType: normalizeEnum(options.subType, "sub-type", VALID_AUTOMATION_SUB_TYPES),
366
- title: validateMaxLength(options.title, 255, "title"),
367
+ title: validateMaxLength(options.title, 255, "title"),
367
368
  type: normalizeEnum(options.type, "type", VALID_AUTOMATION_TYPES),
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
- },
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
+ },
377
378
  });
378
379
  }));
379
380
 
@@ -387,7 +388,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
387
388
  await executeRequest(program, runtimeApiKey, {
388
389
  endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/channels`,
389
390
  query: {
390
- per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
391
+ per_page: parseIntegerInRange(options.perPage, "per-page", 1, 100),
391
392
  page: parsePositiveInteger(options.page, "page"),
392
393
  },
393
394
  });
@@ -396,19 +397,19 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
396
397
  program
397
398
  .command("media")
398
399
  .description("List media for a brand")
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")
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")
402
403
  .option("--page <number>", "Page number", "1")
403
404
  .action(withCommandErrorHandling(async (options) => {
404
405
  await executeRequest(program, runtimeApiKey, {
405
406
  endpoint: `${brandPath(parsePositiveInteger(options.brandId, "brand-id"))}/media`,
406
407
  query: {
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,
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,
412
413
  },
413
414
  });
414
415
  }));
@@ -423,7 +424,8 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
423
424
  const fileStat = await stat(options.file);
424
425
  const { mediaType, size } = validateMediaFile(options.file, fileStat);
425
426
  const formData = new FormData();
426
- const fileBlob = await openAsBlob(options.file, { 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
  });
@@ -490,8 +492,8 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
490
492
  .option("--alt <text>", "Alt text")
491
493
  .option("--link <url>", "Post link")
492
494
  .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")
495
+ .option("--scheduled-at <value>", "Publish datetime (YYYY-MM-DD HH:mm:ss) or null")
496
+ .option("--post-as-story <boolean>", "Post as story: true/false")
495
497
  .option("--comment <text>", "First comment")
496
498
  .option("--comment-delay <seconds>", "First comment delay seconds")
497
499
  .option("--media-ids <ids>", "Comma-separated media IDs")
@@ -499,20 +501,20 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
499
501
  .option("--poll-question <text>", "Poll question")
500
502
  .option("--poll-options <items>", "Comma-separated poll options")
501
503
  .option("--poll-period <value>", "Poll period (e.g. 3d)")
502
- .option("--poll-correct-option-index <number>", "Zero-based poll correct option index")
504
+ .option("--poll-correct-option-index <number>", "Zero-based poll correct option index")
503
505
  .option("--poll-explanation <text>", "Poll explanation")
504
506
  .option("--instagram-collab <username>", "Instagram collab username")
505
507
  .option("--instagram-location-id <id>", "Instagram location ID")
506
508
  .option("--instagram-location-name <name>", "Instagram location name")
507
509
  .option("--instagram-trial-reel <mode>", "Instagram trial reel mode")
508
510
  .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")
511
+ .option("--facebook-location-id <id>", "Facebook location ID")
512
+ .option("--facebook-location-name <name>", "Facebook location name")
513
+ .option("--tiktok-send-to-inbox <boolean>", "TikTok send to inbox true/false")
514
+ .option("--tiktok-auto-add-music <boolean>", "TikTok auto-add music: true/false")
515
+ .option("--youtube-tags <tags>", "Comma-separated YouTube tags")
516
+ .option("--youtube-playlists <json>", "YouTube playlists JSON string")
517
+ .option("--googlemybusiness-upload-to-photos-section <boolean>", "Upload to Google Business Profile photos: true/false")
516
518
  .action(withCommandErrorHandling(async (options) => {
517
519
  const payload = buildPostPayload(options);
518
520
 
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