@nuelink/nuelink-cli 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/main.js DELETED
@@ -1,734 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { program } from "commander";
4
- import chalk from "chalk";
5
- import crypto from "node:crypto";
6
- import os from "node:os";
7
- import path from "node:path";
8
- import { readFile, writeFile, mkdir, chmod, stat } from "node:fs/promises";
9
-
10
- const API_BASE_URL = "https://nuelink.com/api/public/v1";
11
- const CONFIG_DIR = path.join(os.homedir(), ".nuelink-cli");
12
- const CONFIG_FILE = path.join(CONFIG_DIR, "config.json");
13
- const REQUEST_TIMEOUT_MS = Number(process.env.NUELINK_TIMEOUT_MS || 30000);
14
- const CONFIG_ENCRYPTION_SALT = "nuelink-cli-config-salt-v1";
15
- const CONFIG_ENCRYPTION_PASSPHRASE = "nuelink-cli::config::v1::auth";
16
-
17
- async function readConfig() {
18
- try {
19
- const content = await readFile(CONFIG_FILE, "utf8");
20
- return JSON.parse(content);
21
- } catch {
22
- return {};
23
- }
24
- }
25
-
26
- function getConfigCipherKey() {
27
- return crypto.scryptSync(CONFIG_ENCRYPTION_PASSPHRASE, CONFIG_ENCRYPTION_SALT, 32);
28
- }
29
-
30
- function encryptApiKey(apiKey) {
31
- const iv = crypto.randomBytes(12);
32
- const cipher = crypto.createCipheriv("aes-256-gcm", getConfigCipherKey(), iv);
33
- const encrypted = Buffer.concat([cipher.update(apiKey, "utf8"), cipher.final()]);
34
- const authTag = cipher.getAuthTag();
35
-
36
- return {
37
- version: 1,
38
- encryptedApiKey: encrypted.toString("base64"),
39
- iv: iv.toString("base64"),
40
- authTag: authTag.toString("base64"),
41
- };
42
- }
43
-
44
- function decryptApiKey(config) {
45
- if (config?.encryptedApiKey && config?.iv && config?.authTag) {
46
- const decipher = crypto.createDecipheriv(
47
- "aes-256-gcm",
48
- getConfigCipherKey(),
49
- Buffer.from(config.iv, "base64"),
50
- );
51
- decipher.setAuthTag(Buffer.from(config.authTag, "base64"));
52
-
53
- const decrypted = Buffer.concat([
54
- decipher.update(Buffer.from(config.encryptedApiKey, "base64")),
55
- decipher.final(),
56
- ]);
57
-
58
- return decrypted.toString("utf8");
59
- }
60
-
61
- if (config?.apiKey) {
62
- return config.apiKey;
63
- }
64
-
65
- return undefined;
66
- }
67
-
68
- async function writeConfig(config) {
69
- await mkdir(CONFIG_DIR, { recursive: true });
70
- await writeFile(CONFIG_FILE, JSON.stringify(config, null, 2), "utf8");
71
-
72
- // Best effort to keep token readable only by the current user on POSIX systems.
73
- try {
74
- await chmod(CONFIG_FILE, 0o600);
75
- } catch {
76
- // Ignore on platforms where chmod permissions are not meaningful.
77
- }
78
- }
79
-
80
- async function saveApiKey(apiKey) {
81
- await writeConfig(encryptApiKey(apiKey));
82
- }
83
-
84
- async function clearApiKey() {
85
- await writeConfig({});
86
- }
87
-
88
- function maskToken(token) {
89
- if (!token || token.length < 8) {
90
- return "(set)";
91
- }
92
-
93
- return `${token.slice(0, 4)}...${token.slice(-4)}`;
94
- }
95
-
96
- async function resolveApiKey(runtimeApiKey) {
97
- if (runtimeApiKey) {
98
- return runtimeApiKey;
99
- }
100
-
101
- if (process.env.NUELINK_API_KEY) {
102
- return process.env.NUELINK_API_KEY;
103
- }
104
-
105
- const config = await readConfig();
106
- const storedApiKey = decryptApiKey(config);
107
-
108
- if (storedApiKey && config.apiKey) {
109
- await saveApiKey(storedApiKey);
110
- }
111
-
112
- return storedApiKey;
113
- }
114
-
115
- function pathParam(value, label) {
116
- const stringValue = String(value ?? "").trim();
117
-
118
- if (!stringValue) {
119
- throw new Error(`Missing required ${label}.`);
120
- }
121
-
122
- return encodeURIComponent(stringValue);
123
- }
124
-
125
- function brandPath(brandId) {
126
- return `/brands/${pathParam(brandId, "brand-id")}`;
127
- }
128
-
129
- function collectionPath(brandId, collectionId) {
130
- return `${brandPath(brandId)}/collections/${pathParam(collectionId, "collection-id")}`;
131
- }
132
-
133
- function extractAuthArg(args) {
134
- const sanitizedArgs = [];
135
- let apiKey;
136
-
137
- for (let index = 0; index < args.length; index += 1) {
138
- const arg = args[index];
139
-
140
- if (arg === "--auth" || arg === "-a") {
141
- const next = args[index + 1];
142
- if (next && !next.startsWith("-")) {
143
- apiKey = next;
144
- index += 1;
145
- continue;
146
- }
147
- }
148
-
149
- if (arg.startsWith("--auth=")) {
150
- apiKey = arg.slice("--auth=".length);
151
- continue;
152
- }
153
-
154
- sanitizedArgs.push(arg);
155
- }
156
-
157
- return { apiKey, sanitizedArgs };
158
- }
159
-
160
- function parseCsv(value) {
161
- if (!value) {
162
- return [];
163
- }
164
-
165
- return value
166
- .split(",")
167
- .map((item) => item.trim())
168
- .filter(Boolean);
169
- }
170
-
171
- function parseBoolean(value) {
172
- if (value === undefined || value === null || value === "") {
173
- return undefined;
174
- }
175
-
176
- const normalized = String(value).trim().toLowerCase();
177
-
178
- if (["true", "1", "yes", "y"].includes(normalized)) {
179
- return true;
180
- }
181
-
182
- if (["false", "0", "no", "n"].includes(normalized)) {
183
- return false;
184
- }
185
-
186
- return undefined;
187
- }
188
-
189
- function parseNumber(value) {
190
- if (value === undefined || value === null || value === "") {
191
- return undefined;
192
- }
193
-
194
- const parsed = Number(value);
195
- return Number.isNaN(parsed) ? undefined : parsed;
196
- }
197
-
198
- function mergeMedia(idsCsv, urlsCsv) {
199
- const idMedia = parseCsv(idsCsv).map((id) => ({ id }));
200
- const urlMedia = parseCsv(urlsCsv).map((url) => ({ url }));
201
- return [...idMedia, ...urlMedia];
202
- }
203
-
204
- async function nuelinkRequest({ apiKey, method = "GET", endpoint, query, body, multipart }) {
205
- if (!apiKey) {
206
- console.error(chalk.red("Missing API key. Use --auth <api_key> to set it."));
207
- process.exitCode = 1;
208
- return null;
209
- }
210
-
211
- const url = new URL(`${API_BASE_URL}${endpoint}`);
212
-
213
- if (query) {
214
- Object.entries(query).forEach(([key, value]) => {
215
- if (value !== undefined && value !== null && value !== "") {
216
- url.searchParams.set(key, String(value));
217
- }
218
- });
219
- }
220
-
221
- const headers = {
222
- Authorization: `Bearer ${apiKey}`,
223
- Accept: "application/json",
224
- "User-Agent": "nuelink-cli/1.0.0",
225
- };
226
-
227
- const init = {
228
- method,
229
- headers,
230
- };
231
-
232
- if (multipart) {
233
- init.body = multipart;
234
- } else if (body !== undefined) {
235
- headers["Content-Type"] = "application/json";
236
- init.body = JSON.stringify(body);
237
- }
238
-
239
- try {
240
- const response = await fetch(url, {
241
- ...init,
242
- signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
243
- });
244
- const text = await response.text();
245
- let data = {};
246
-
247
- if (text) {
248
- try {
249
- data = JSON.parse(text);
250
- } catch {
251
- data = { raw: text };
252
- }
253
- }
254
-
255
- if (!response.ok) {
256
- console.error(chalk.red(`Request failed (${response.status} ${response.statusText})`));
257
- console.error(chalk.red(JSON.stringify(data, null, 2)));
258
- process.exitCode = 1;
259
- return null;
260
- }
261
-
262
- console.log(chalk.green(`OK ${method} ${url.pathname}`));
263
- console.log(JSON.stringify(data, null, 2));
264
- return data;
265
- } catch (error) {
266
- if (error?.name === "TimeoutError") {
267
- console.error(chalk.red(`Request timed out after ${REQUEST_TIMEOUT_MS}ms.`));
268
- process.exitCode = 1;
269
- return null;
270
- }
271
-
272
- console.error(chalk.red("Request error:"), error.message);
273
- process.exitCode = 1;
274
- return null;
275
- }
276
- }
277
-
278
- const parsedAuth = extractAuthArg(process.argv.slice(2));
279
- const runtimeApiKey = parsedAuth.apiKey;
280
- const parseArgv = [process.argv[0], process.argv[1], ...parsedAuth.sanitizedArgs];
281
-
282
- if (runtimeApiKey) {
283
- await saveApiKey(runtimeApiKey);
284
- }
285
-
286
- program
287
- .name("nuelink-cli")
288
- .version("1.0.0")
289
- .description("Nuelink CLI for the Public API")
290
- .option("-a, --auth <apiKey>", "Set and use API key");
291
-
292
- program
293
- .command("auth:clear")
294
- .description("Remove the saved API key")
295
- .action(async () => {
296
- await clearApiKey();
297
- console.log(chalk.yellow("Saved API key removed."));
298
- });
299
-
300
- program
301
- .command("auth:status")
302
- .description("Show where auth is currently resolved from")
303
- .action(async () => {
304
- if (runtimeApiKey) {
305
- console.log(chalk.green(`Auth source: CLI flag (${maskToken(runtimeApiKey)})`));
306
- return;
307
- }
308
-
309
- if (process.env.NUELINK_API_KEY) {
310
- console.log(chalk.green(`Auth source: NUELINK_API_KEY (${maskToken(process.env.NUELINK_API_KEY)})`));
311
- return;
312
- }
313
-
314
- const config = await readConfig();
315
- const storedApiKey = decryptApiKey(config);
316
- if (storedApiKey) {
317
- console.log(chalk.green(`Auth source: saved config (${maskToken(storedApiKey)})`));
318
-
319
- try {
320
- const fileStat = await stat(CONFIG_FILE);
321
- console.log(chalk.blue(`Config path: ${CONFIG_FILE}`));
322
- console.log(chalk.blue(`Last updated: ${fileStat.mtime.toISOString()}`));
323
- } catch {
324
- // Ignore non-critical stat failure.
325
- }
326
-
327
- return;
328
- }
329
-
330
- console.log(chalk.yellow("No API key configured. Set one with --auth <api_key>."));
331
- });
332
-
333
- program
334
- .command("me")
335
- .description("Get current profile")
336
- .action(async () => {
337
- const apiKey = await resolveApiKey(runtimeApiKey);
338
- await nuelinkRequest({ apiKey, endpoint: "/me" });
339
- });
340
-
341
- program
342
- .command("brands")
343
- .description("List brands")
344
- .option("--per-page <number>", "Items per page", "25")
345
- .option("--page <number>", "Page number", "1")
346
- .action(async (options) => {
347
- const apiKey = await resolveApiKey(runtimeApiKey);
348
- await nuelinkRequest({
349
- apiKey,
350
- endpoint: "/brands",
351
- query: {
352
- per_page: options.perPage,
353
- page: options.page,
354
- },
355
- });
356
- });
357
-
358
- program
359
- .command("collections")
360
- .description("List collections for a brand")
361
- .requiredOption("--brand-id <id>", "Brand ID")
362
- .option("--per-page <number>", "Items per page", "25")
363
- .option("--page <number>", "Page number", "1")
364
- .action(async (options) => {
365
- const apiKey = await resolveApiKey(runtimeApiKey);
366
-
367
- try {
368
- await nuelinkRequest({
369
- apiKey,
370
- endpoint: `${brandPath(options.brandId)}/collections`,
371
- query: {
372
- per_page: options.perPage,
373
- page: options.page,
374
- },
375
- });
376
- } catch (error) {
377
- console.error(chalk.red(error.message));
378
- process.exitCode = 1;
379
- }
380
- });
381
-
382
- program
383
- .command("collections:create")
384
- .description("Create a collection")
385
- .requiredOption("--brand-id <id>", "Brand ID")
386
- .requiredOption("--title <title>", "Collection title")
387
- .option("--description <text>", "Collection description", "")
388
- .option("--max-republish <number>", "Max republish")
389
- .option("--channels <ids>", "Comma-separated channel IDs")
390
- .option("--queues <slots>", "Comma-separated queue slots (e.g. Mon 10:10,Mon 12:12)")
391
- .action(async (options) => {
392
- const apiKey = await resolveApiKey(runtimeApiKey);
393
- try {
394
- await nuelinkRequest({
395
- apiKey,
396
- method: "POST",
397
- endpoint: `${brandPath(options.brandId)}/collections`,
398
- body: {
399
- title: options.title,
400
- description: options.description,
401
- maxRepublish: options.maxRepublish ? Number(options.maxRepublish) : undefined,
402
- channels: parseCsv(options.channels).map((id) => Number(id)),
403
- queues: parseCsv(options.queues),
404
- },
405
- });
406
- } catch (error) {
407
- console.error(chalk.red(error.message));
408
- process.exitCode = 1;
409
- }
410
- });
411
-
412
- program
413
- .command("automations")
414
- .description("List automations for a brand")
415
- .requiredOption("--brand-id <id>", "Brand ID")
416
- .action(async (options) => {
417
- const apiKey = await resolveApiKey(runtimeApiKey);
418
- try {
419
- await nuelinkRequest({
420
- apiKey,
421
- endpoint: `${brandPath(options.brandId)}/automations`,
422
- });
423
- } catch (error) {
424
- console.error(chalk.red(error.message));
425
- process.exitCode = 1;
426
- }
427
- });
428
-
429
- program
430
- .command("automations:create")
431
- .description("Create an automation")
432
- .requiredOption("--brand-id <id>", "Brand ID")
433
- .requiredOption("--collection-id <id>", "Collection ID")
434
- .requiredOption("--feed-url <url>", "Feed URL")
435
- .requiredOption("--import-as-type <type>", "Import type, e.g. IMAGE")
436
- .requiredOption("--sub-type <type>", "Sub type, e.g. RSS")
437
- .requiredOption("--title <title>", "Automation title")
438
- .option("--type <type>", "Automation type", "FEED")
439
- .option("--dynamic-title <text>", "Dynamic title", "{{title}}")
440
- .option("--dynamic-body <text>", "Dynamic body", "{title} {link}")
441
- .option("--description <text>", "Automation description")
442
- .action(async (options) => {
443
- const apiKey = await resolveApiKey(runtimeApiKey);
444
- try {
445
- await nuelinkRequest({
446
- apiKey,
447
- method: "POST",
448
- endpoint: `${brandPath(options.brandId)}/automations`,
449
- body: {
450
- collectionId: Number(options.collectionId),
451
- feedUrl: options.feedUrl,
452
- importAsType: options.importAsType,
453
- subType: options.subType,
454
- title: options.title,
455
- type: options.type,
456
- dynamicTitle: options.dynamicTitle,
457
- dynamicBody: options.dynamicBody,
458
- description: options.description,
459
- },
460
- });
461
- } catch (error) {
462
- console.error(chalk.red(error.message));
463
- process.exitCode = 1;
464
- }
465
- });
466
-
467
- program
468
- .command("channels")
469
- .description("List channels for a brand")
470
- .requiredOption("--brand-id <id>", "Brand ID")
471
- .option("--per-page <number>", "Items per page", "25")
472
- .option("--page <number>", "Page number", "1")
473
- .action(async (options) => {
474
- const apiKey = await resolveApiKey(runtimeApiKey);
475
- try {
476
- await nuelinkRequest({
477
- apiKey,
478
- endpoint: `${brandPath(options.brandId)}/channels`,
479
- query: {
480
- per_page: options.perPage,
481
- page: options.page,
482
- },
483
- });
484
- } catch (error) {
485
- console.error(chalk.red(error.message));
486
- process.exitCode = 1;
487
- }
488
- });
489
-
490
- program
491
- .command("media")
492
- .description("List media for a brand")
493
- .requiredOption("--brand-id <id>", "Brand ID")
494
- .action(async (options) => {
495
- const apiKey = await resolveApiKey(runtimeApiKey);
496
- try {
497
- await nuelinkRequest({
498
- apiKey,
499
- endpoint: `${brandPath(options.brandId)}/media`,
500
- });
501
- } catch (error) {
502
- console.error(chalk.red(error.message));
503
- process.exitCode = 1;
504
- }
505
- });
506
-
507
- program
508
- .command("media:upload")
509
- .description("Upload a media file")
510
- .requiredOption("--brand-id <id>", "Brand ID")
511
- .requiredOption("--file <path>", "Path to local file")
512
- .action(async (options) => {
513
- const apiKey = await resolveApiKey(runtimeApiKey);
514
-
515
- const fileBuffer = await readFile(options.file);
516
- const formData = new FormData();
517
- formData.append("media", new Blob([fileBuffer]), path.basename(options.file));
518
-
519
- try {
520
- await nuelinkRequest({
521
- apiKey,
522
- method: "POST",
523
- endpoint: `${brandPath(options.brandId)}/media`,
524
- multipart: formData,
525
- });
526
- } catch (error) {
527
- console.error(chalk.red(error.message));
528
- process.exitCode = 1;
529
- }
530
- });
531
-
532
- program
533
- .command("posts")
534
- .description("List posts in a collection")
535
- .requiredOption("--brand-id <id>", "Brand ID")
536
- .requiredOption("--collection-id <id>", "Collection ID")
537
- .action(async (options) => {
538
- const apiKey = await resolveApiKey(runtimeApiKey);
539
- try {
540
- await nuelinkRequest({
541
- apiKey,
542
- endpoint: `${collectionPath(options.brandId, options.collectionId)}/posts`,
543
- });
544
- } catch (error) {
545
- console.error(chalk.red(error.message));
546
- process.exitCode = 1;
547
- }
548
- });
549
-
550
- program
551
- .command("posts:add-json")
552
- .description("Create a post using a JSON payload file")
553
- .requiredOption("--brand-id <id>", "Brand ID")
554
- .requiredOption("--collection-id <id>", "Collection ID")
555
- .requiredOption("--payload <file>", "Path to JSON payload file")
556
- .action(async (options) => {
557
- const apiKey = await resolveApiKey(runtimeApiKey);
558
- const payloadText = await readFile(options.payload, "utf8");
559
- const payload = JSON.parse(payloadText);
560
-
561
- try {
562
- await nuelinkRequest({
563
- apiKey,
564
- method: "POST",
565
- endpoint: `${collectionPath(options.brandId, options.collectionId)}/posts`,
566
- body: payload,
567
- });
568
- } catch (error) {
569
- console.error(chalk.red(error.message));
570
- process.exitCode = 1;
571
- }
572
- });
573
-
574
- program
575
- .command("posts:create")
576
- .description("Create a post using CLI options")
577
- .requiredOption("--brand-id <id>", "Brand ID")
578
- .requiredOption("--collection-id <id>", "Collection ID")
579
- .option("--title <text>", "Post title")
580
- .option("--caption <text>", "Post caption/body")
581
- .option("--alt <text>", "Alt text")
582
- .option("--link <url>", "Post link")
583
- .option("--publish-mode <mode>", "Publish mode (e.g. DRAFT, NOW, SCHEDULE)", "DRAFT")
584
- .option("--publish-at <value>", "Publish datetime (YYYY-MM-DD HH:mm:ss or ISO) or null")
585
- .option("--post-as-story <boolean>", "Post as story: true/false")
586
- .option("--post-type <type>", "Post type override")
587
- .option("--comment <text>", "First comment")
588
- .option("--comment-delay <seconds>", "First comment delay seconds")
589
- .option("--media-ids <ids>", "Comma-separated media IDs")
590
- .option("--media-urls <urls>", "Comma-separated media URLs")
591
- .option("--poll-question <text>", "Poll question")
592
- .option("--poll-options <items>", "Comma-separated poll options")
593
- .option("--poll-period <value>", "Poll period (e.g. 3d)")
594
- .option("--poll-correct-option-index <number>", "Poll correct option index")
595
- .option("--poll-explanation <text>", "Poll explanation")
596
- .option("--instagram-collab <username>", "Instagram collab username")
597
- .option("--instagram-location-id <id>", "Instagram location ID")
598
- .option("--instagram-location-name <name>", "Instagram location name")
599
- .option("--instagram-trial-reel <mode>", "Instagram trial reel mode")
600
- .option("--instagram-share-to-feed <boolean>", "Instagram share to feed true/false")
601
- .option("--facebook-collab <username>", "Facebook collab username")
602
- .option("--facebook-location-id <id>", "Facebook location ID")
603
- .option("--facebook-location-name <name>", "Facebook location name")
604
- .option("--tiktok-send-to-inbox <boolean>", "TikTok send to inbox true/false")
605
- .option("--youtube-tags <tags>", "Comma-separated YouTube tags")
606
- .option("--youtube-playlists <json>", "YouTube playlists JSON string")
607
- .action(async (options) => {
608
- const apiKey = await resolveApiKey(runtimeApiKey);
609
-
610
- const media = mergeMedia(options.mediaIds, options.mediaUrls);
611
-
612
- const poll = {
613
- ...(options.pollQuestion ? { question: options.pollQuestion } : {}),
614
- ...(options.pollOptions ? { options: parseCsv(options.pollOptions) } : {}),
615
- ...(options.pollPeriod ? { period: options.pollPeriod } : {}),
616
- ...(parseNumber(options.pollCorrectOptionIndex) !== undefined
617
- ? { correctOptionIndex: parseNumber(options.pollCorrectOptionIndex) }
618
- : {}),
619
- ...(options.pollExplanation ? { explanation: options.pollExplanation } : {}),
620
- };
621
-
622
- const instagram = {
623
- ...(options.instagramCollab ? { collab: options.instagramCollab } : {}),
624
- ...(options.instagramLocationId || options.instagramLocationName
625
- ? {
626
- location: {
627
- ...(options.instagramLocationId ? { id: options.instagramLocationId } : {}),
628
- ...(options.instagramLocationName ? { name: options.instagramLocationName } : {}),
629
- },
630
- }
631
- : {}),
632
- ...(options.instagramTrialReel ? { trialReel: options.instagramTrialReel } : {}),
633
- ...(parseBoolean(options.instagramShareToFeed) !== undefined
634
- ? { shareToFeed: parseBoolean(options.instagramShareToFeed) }
635
- : {}),
636
- };
637
-
638
- const facebook = {
639
- ...(options.facebookCollab ? { collab: options.facebookCollab } : {}),
640
- ...(options.facebookLocationId || options.facebookLocationName
641
- ? {
642
- location: {
643
- ...(options.facebookLocationId ? { id: options.facebookLocationId } : {}),
644
- ...(options.facebookLocationName ? { name: options.facebookLocationName } : {}),
645
- },
646
- }
647
- : {}),
648
- };
649
-
650
-
651
- const tiktok = {
652
- ...(parseBoolean(options.tiktokSendToInbox) !== undefined
653
- ? { sendToInbox: parseBoolean(options.tiktokSendToInbox) }
654
- : {}),
655
- };
656
-
657
- let youtubePlaylists;
658
- if (options.youtubePlaylists) {
659
- try {
660
- youtubePlaylists = JSON.parse(options.youtubePlaylists);
661
- } catch {
662
- console.error(chalk.red("Invalid --youtube-playlists JSON."));
663
- process.exitCode = 1;
664
- return;
665
- }
666
- }
667
-
668
- const youtube = {
669
- ...(options.youtubeTags ? { tags: parseCsv(options.youtubeTags) } : {}),
670
- ...(youtubePlaylists ? { playlists: youtubePlaylists } : {}),
671
- };
672
-
673
- const payload = {
674
- ...(options.title ? { title: options.title } : {}),
675
- ...(options.caption ? { caption: options.caption } : {}),
676
- ...(options.alt ? { alt: options.alt } : {}),
677
- ...(options.link ? { link: options.link } : {}),
678
- ...(options.postType ? { postType: options.postType } : {}),
679
- publishMode: options.publishMode,
680
- ...(options.publishAt && options.publishAt !== "null" ? { publishAt: options.publishAt } : { publishAt: null }),
681
- ...(parseBoolean(options.postAsStory) !== undefined
682
- ? { postAsStory: parseBoolean(options.postAsStory) }
683
- : {}),
684
- ...(options.comment
685
- ? {
686
- comment: {
687
- comment: options.comment,
688
- ...(parseNumber(options.commentDelay) !== undefined
689
- ? { delay: parseNumber(options.commentDelay) }
690
- : {}),
691
- },
692
- }
693
- : {}),
694
- ...(media.length > 0 ? { media } : {}),
695
- ...(Object.keys(poll).length > 0 ? { poll } : {}),
696
- ...(Object.keys(instagram).length > 0 || Object.keys(facebook).length > 0 || Object.keys(tiktok).length > 0 || Object.keys(youtube).length > 0
697
- ? {
698
- platforms: {
699
- ...(Object.keys(instagram).length > 0 ? { instagram } : {}),
700
- ...(Object.keys(facebook).length > 0 ? { facebook } : {}),
701
- ...(Object.keys(tiktok).length > 0 ? { tiktok } : {}),
702
- ...(Object.keys(youtube).length > 0 ? { youtube } : {}),
703
- },
704
- }
705
- : {}),
706
- };
707
-
708
- try {
709
- await nuelinkRequest({
710
- apiKey,
711
- method: "POST",
712
- endpoint: `${collectionPath(options.brandId, options.collectionId)}/posts`,
713
- body: payload,
714
- });
715
- } catch (error) {
716
- console.error(chalk.red(error.message));
717
- process.exitCode = 1;
718
- }
719
- });
720
-
721
- const argvHasCommand = parsedAuth.sanitizedArgs.some((arg) => !arg.startsWith("-"));
722
- const hasHelpFlag = parsedAuth.sanitizedArgs.includes("--help") || parsedAuth.sanitizedArgs.includes("-h");
723
-
724
- if (!argvHasCommand && runtimeApiKey && !hasHelpFlag) {
725
- console.log(chalk.green("API key saved and ready to use."));
726
- process.exit(0);
727
- }
728
-
729
- if (!argvHasCommand && !runtimeApiKey && !hasHelpFlag) {
730
- program.outputHelp();
731
- process.exit(0);
732
- }
733
-
734
- await program.parseAsync(parseArgv);