@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/README.md +61 -12
- package/package.json +4 -4
- package/src/cli.js +29 -0
- package/src/commands.js +497 -0
- package/src/config.js +121 -0
- package/src/http.js +176 -0
- package/src/output.js +183 -0
- package/src/postPayload.js +174 -0
- package/src/validation.js +186 -0
- package/src/main.js +0 -734
package/src/http.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { printApiResponse } from "./output.js";
|
|
4
|
+
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
const { version: cliVersion } = require("../package.json");
|
|
7
|
+
|
|
8
|
+
const API_BASE_URL = process.env.NUELINK_BASE_URL || "https://nuelink.com/api/public/v1";
|
|
9
|
+
const REQUEST_TIMEOUT_MS = Number(process.env.NUELINK_TIMEOUT_MS || 30000);
|
|
10
|
+
const MAX_GET_RETRIES = Number(process.env.NUELINK_GET_RETRIES || 2);
|
|
11
|
+
const RETRY_BASE_DELAY_MS = Number(process.env.NUELINK_RETRY_BASE_MS || 500);
|
|
12
|
+
const RETRY_MAX_DELAY_MS = Number(process.env.NUELINK_RETRY_MAX_MS || 2000);
|
|
13
|
+
|
|
14
|
+
function pathParam(value, label) {
|
|
15
|
+
const stringValue = String(value ?? "").trim();
|
|
16
|
+
|
|
17
|
+
if (!stringValue) {
|
|
18
|
+
throw new Error(`Missing required ${label}.`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return encodeURIComponent(stringValue);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function brandPath(brandId) {
|
|
25
|
+
return `/brands/${pathParam(brandId, "brand-id")}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function collectionPath(brandId, collectionId) {
|
|
29
|
+
return `${brandPath(brandId)}/collections/${pathParam(collectionId, "collection-id")}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function buildApiUrl(endpoint) {
|
|
33
|
+
return new URL(endpoint.replace(/^\//, ""), `${API_BASE_URL.replace(/\/?$/, "/")}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function shouldRetryRequest(method, statusCode, attempt) {
|
|
37
|
+
return method === "GET" && attempt < MAX_GET_RETRIES && (statusCode === 429 || statusCode >= 500);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function parseRetryAfterMs(headers, attempt) {
|
|
41
|
+
const retryAfter = headers.get("retry-after");
|
|
42
|
+
|
|
43
|
+
if (retryAfter) {
|
|
44
|
+
const seconds = Number(retryAfter);
|
|
45
|
+
|
|
46
|
+
if (!Number.isNaN(seconds)) {
|
|
47
|
+
return Math.min(Math.max(seconds * 1000, 0), RETRY_MAX_DELAY_MS);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const dateDelay = Date.parse(retryAfter) - Date.now();
|
|
51
|
+
if (!Number.isNaN(dateDelay)) {
|
|
52
|
+
return Math.min(Math.max(dateDelay, 0), RETRY_MAX_DELAY_MS);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return Math.min(RETRY_BASE_DELAY_MS * (attempt + 1), RETRY_MAX_DELAY_MS);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function sleep(ms) {
|
|
60
|
+
if (ms <= 0) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function printDryRun({ method, url, query, body, multipart, dryRunBody }) {
|
|
68
|
+
console.log(JSON.stringify({
|
|
69
|
+
dryRun: true,
|
|
70
|
+
method,
|
|
71
|
+
url: url.toString(),
|
|
72
|
+
...(query ? { query } : {}),
|
|
73
|
+
...(body !== undefined ? { body } : {}),
|
|
74
|
+
...(multipart ? { multipart: dryRunBody || true } : {}),
|
|
75
|
+
}, null, 2));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function nuelinkRequest({ apiKey, method = "GET", endpoint, query, body, multipart, outputMode = "json", quiet = false, dryRun = false, dryRunBody }) {
|
|
79
|
+
const url = buildApiUrl(endpoint);
|
|
80
|
+
|
|
81
|
+
if (query) {
|
|
82
|
+
Object.entries(query).forEach(([key, value]) => {
|
|
83
|
+
if (value !== undefined && value !== null && value !== "") {
|
|
84
|
+
url.searchParams.set(key, String(value));
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (dryRun) {
|
|
90
|
+
printDryRun({ method, url, query, body, multipart, dryRunBody });
|
|
91
|
+
return { dryRun: true };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!apiKey) {
|
|
95
|
+
console.error(chalk.red("Missing API key. Use --api-key <api_key> for a single command or auth:login to save one."));
|
|
96
|
+
process.exitCode = 1;
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const headers = {
|
|
101
|
+
Authorization: `Bearer ${apiKey}`,
|
|
102
|
+
Accept: "application/json",
|
|
103
|
+
"User-Agent": `nuelink-cli/${cliVersion}`,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const init = {
|
|
107
|
+
method,
|
|
108
|
+
headers,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
if (multipart) {
|
|
112
|
+
init.body = multipart;
|
|
113
|
+
} else if (body !== undefined) {
|
|
114
|
+
headers["Content-Type"] = "application/json";
|
|
115
|
+
init.body = JSON.stringify(body);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
let response;
|
|
120
|
+
|
|
121
|
+
for (let attempt = 0; ; attempt += 1) {
|
|
122
|
+
response = await fetch(url, {
|
|
123
|
+
...init,
|
|
124
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
if (!shouldRetryRequest(method, response.status, attempt)) {
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
await sleep(parseRetryAfterMs(response.headers, attempt));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const text = await response.text();
|
|
135
|
+
let data = {};
|
|
136
|
+
|
|
137
|
+
if (text) {
|
|
138
|
+
try {
|
|
139
|
+
data = JSON.parse(text);
|
|
140
|
+
} catch {
|
|
141
|
+
data = { raw: text };
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (!response.ok) {
|
|
146
|
+
console.error(chalk.red(`Request failed (${response.status} ${response.statusText})`));
|
|
147
|
+
console.error(chalk.red(JSON.stringify(data, null, 2)));
|
|
148
|
+
process.exitCode = 1;
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (outputMode !== "json" && !quiet) {
|
|
153
|
+
console.log(chalk.green(`OK ${method} ${url.pathname}`));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
printApiResponse(data, { outputMode });
|
|
157
|
+
return data;
|
|
158
|
+
} catch (error) {
|
|
159
|
+
if (error?.name === "TimeoutError") {
|
|
160
|
+
console.error(chalk.red(`Request timed out after ${REQUEST_TIMEOUT_MS}ms.`));
|
|
161
|
+
process.exitCode = 1;
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
console.error(chalk.red("Request error:"), error.message);
|
|
166
|
+
process.exitCode = 1;
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export {
|
|
172
|
+
brandPath,
|
|
173
|
+
collectionPath,
|
|
174
|
+
nuelinkRequest,
|
|
175
|
+
pathParam,
|
|
176
|
+
};
|
package/src/output.js
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
function toTitleCase(value) {
|
|
2
|
+
return String(value)
|
|
3
|
+
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
|
4
|
+
.replace(/[_-]+/g, " ")
|
|
5
|
+
.replace(/\s+/g, " ")
|
|
6
|
+
.trim()
|
|
7
|
+
.replace(/^./, (char) => char.toUpperCase());
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function formatCell(value, maxLength = 42) {
|
|
11
|
+
if (value === undefined || value === null) {
|
|
12
|
+
return "";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let text;
|
|
16
|
+
|
|
17
|
+
if (typeof value === "string") {
|
|
18
|
+
text = value;
|
|
19
|
+
} else if (typeof value === "number" || typeof value === "boolean") {
|
|
20
|
+
text = String(value);
|
|
21
|
+
} else if (Array.isArray(value)) {
|
|
22
|
+
text = `[${value.map((item) => formatCell(item, 18)).join(", ")}]`;
|
|
23
|
+
} else {
|
|
24
|
+
text = JSON.stringify(value);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
text = text.replace(/\s+/g, " ").trim();
|
|
28
|
+
|
|
29
|
+
if (text.length > maxLength) {
|
|
30
|
+
return `${text.slice(0, maxLength - 1)}…`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return text;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function pickColumns(items) {
|
|
37
|
+
const preferredKeys = [
|
|
38
|
+
"id",
|
|
39
|
+
"title",
|
|
40
|
+
"name",
|
|
41
|
+
"description",
|
|
42
|
+
"status",
|
|
43
|
+
"type",
|
|
44
|
+
"subType",
|
|
45
|
+
"timezone",
|
|
46
|
+
"collectionId",
|
|
47
|
+
"postType",
|
|
48
|
+
"postingType",
|
|
49
|
+
"postDate",
|
|
50
|
+
"feedUrl",
|
|
51
|
+
"size",
|
|
52
|
+
"createdAt",
|
|
53
|
+
"updatedAt",
|
|
54
|
+
];
|
|
55
|
+
const excludedKeys = new Set(["body", "caption", "media", "poll", "platforms", "queues", "channels"]);
|
|
56
|
+
const presentKeys = new Set(items.flatMap((item) => Object.keys(item)));
|
|
57
|
+
|
|
58
|
+
const columns = preferredKeys.filter((key) => presentKeys.has(key) && !excludedKeys.has(key));
|
|
59
|
+
|
|
60
|
+
for (const item of items) {
|
|
61
|
+
for (const key of Object.keys(item)) {
|
|
62
|
+
if (!excludedKeys.has(key) && !columns.includes(key)) {
|
|
63
|
+
columns.push(key);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (columns.length >= 7) {
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (columns.length >= 7) {
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return columns.slice(0, 7);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function renderTable(items) {
|
|
80
|
+
const columns = pickColumns(items);
|
|
81
|
+
|
|
82
|
+
if (columns.length === 0) {
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const rows = items.map((item) => columns.map((column) => formatCell(item[column])));
|
|
87
|
+
const headers = columns.map((column) => toTitleCase(column));
|
|
88
|
+
const widths = headers.map((header, index) => {
|
|
89
|
+
const cellWidths = rows.map((row) => row[index].length);
|
|
90
|
+
return Math.max(header.length, 0, ...cellWidths);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const divider = `+${widths.map((width) => "-".repeat(width + 2)).join("+")}+`;
|
|
94
|
+
const renderRow = (values) => `| ${values.map((value, index) => value.padEnd(widths[index])).join(" | ")} |`;
|
|
95
|
+
|
|
96
|
+
return [
|
|
97
|
+
divider,
|
|
98
|
+
renderRow(headers),
|
|
99
|
+
divider,
|
|
100
|
+
...rows.map(renderRow),
|
|
101
|
+
divider,
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function renderPagination(pagination) {
|
|
106
|
+
if (!pagination) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const parts = [];
|
|
111
|
+
|
|
112
|
+
if (pagination.currentPage !== undefined && pagination.lastPage !== undefined) {
|
|
113
|
+
parts.push(`Page ${pagination.currentPage} of ${pagination.lastPage}`);
|
|
114
|
+
} else if (pagination.currentPage !== undefined) {
|
|
115
|
+
parts.push(`Page ${pagination.currentPage}`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (pagination.perPage !== undefined) {
|
|
119
|
+
parts.push(`${pagination.perPage} per page`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (pagination.total !== undefined) {
|
|
123
|
+
parts.push(`${pagination.total} total`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (pagination.nextPageUrl) {
|
|
127
|
+
try {
|
|
128
|
+
const nextPage = new URL(pagination.nextPageUrl).searchParams.get("page");
|
|
129
|
+
parts.push(nextPage ? `next page ${nextPage}` : "next page available");
|
|
130
|
+
} catch {
|
|
131
|
+
parts.push("next page available");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (pagination.prevPageUrl) {
|
|
136
|
+
try {
|
|
137
|
+
const prevPage = new URL(pagination.prevPageUrl).searchParams.get("page");
|
|
138
|
+
parts.push(prevPage ? `prev page ${prevPage}` : "prev page available");
|
|
139
|
+
} catch {
|
|
140
|
+
parts.push("prev page available");
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return parts.length > 0 ? `Pagination: ${parts.join(" | ")}` : null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function printApiResponse(response, { outputMode = "json" } = {}) {
|
|
148
|
+
if (outputMode !== "table" || !response || !Array.isArray(response.data)) {
|
|
149
|
+
console.log(JSON.stringify(response, null, 2));
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const items = response.data;
|
|
154
|
+
|
|
155
|
+
if (items.length === 0) {
|
|
156
|
+
console.log("No results.");
|
|
157
|
+
const paginationLine = renderPagination(response.pagination);
|
|
158
|
+
if (paginationLine) {
|
|
159
|
+
console.log(paginationLine);
|
|
160
|
+
}
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const lines = renderTable(items);
|
|
165
|
+
|
|
166
|
+
if (lines.length === 0) {
|
|
167
|
+
console.log(JSON.stringify(response, null, 2));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
lines.forEach((line) => console.log(line));
|
|
172
|
+
|
|
173
|
+
const paginationLine = renderPagination(response.pagination);
|
|
174
|
+
if (paginationLine) {
|
|
175
|
+
console.log(paginationLine);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export {
|
|
180
|
+
printApiResponse,
|
|
181
|
+
renderPagination,
|
|
182
|
+
renderTable,
|
|
183
|
+
};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseBooleanStrict,
|
|
3
|
+
parseJsonString,
|
|
4
|
+
parseOptionalPositiveInteger,
|
|
5
|
+
splitCsv,
|
|
6
|
+
validateHttpUrl,
|
|
7
|
+
validatePollOptions,
|
|
8
|
+
validatePublishAt,
|
|
9
|
+
} from "./validation.js";
|
|
10
|
+
|
|
11
|
+
const VALID_PUBLISH_MODES = ["DRAFT", "QUEUE", "SCHEDULE", "IMMEDIATE"];
|
|
12
|
+
|
|
13
|
+
function parseCsv(value) {
|
|
14
|
+
return splitCsv(value);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function parseBoolean(value) {
|
|
18
|
+
if (value === undefined || value === null || value === "") {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const normalized = String(value).trim().toLowerCase();
|
|
23
|
+
|
|
24
|
+
if (["true", "1", "yes", "y"].includes(normalized)) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (["false", "0", "no", "n"].includes(normalized)) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function parseNumber(value) {
|
|
36
|
+
if (value === undefined || value === null || value === "") {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const parsed = Number(value);
|
|
41
|
+
return Number.isNaN(parsed) ? undefined : parsed;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function mergeMedia(idsCsv, urlsCsv) {
|
|
45
|
+
const idMedia = parseCsv(idsCsv).map((id) => ({ id }));
|
|
46
|
+
const urlMedia = parseCsv(urlsCsv).map((url) => ({ url: validateHttpUrl(url, "media-url") }));
|
|
47
|
+
return [...idMedia, ...urlMedia];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function normalizePublishMode(value) {
|
|
51
|
+
const normalized = String(value ?? "").trim().toUpperCase();
|
|
52
|
+
|
|
53
|
+
if (!VALID_PUBLISH_MODES.includes(normalized)) {
|
|
54
|
+
throw new Error(`Invalid publish mode \"${value}\". Expected one of: ${VALID_PUBLISH_MODES.join(", ")}.`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return normalized;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function buildPostPayload(options) {
|
|
61
|
+
const media = mergeMedia(options.mediaIds, options.mediaUrls);
|
|
62
|
+
const publishMode = normalizePublishMode(options.publishMode);
|
|
63
|
+
const publishAt = validatePublishAt(options.publishAt);
|
|
64
|
+
|
|
65
|
+
if (publishMode === "SCHEDULE" && !publishAt) {
|
|
66
|
+
throw new Error("publishAt is required when publishMode is SCHEDULE.");
|
|
67
|
+
}
|
|
68
|
+
|
|
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);
|
|
76
|
+
|
|
77
|
+
const poll = {
|
|
78
|
+
...(options.pollQuestion ? { question: options.pollQuestion } : {}),
|
|
79
|
+
...(pollOptions.length > 0 ? { options: pollOptions } : {}),
|
|
80
|
+
...(options.pollPeriod ? { period: options.pollPeriod } : {}),
|
|
81
|
+
...(zeroBasedCorrectOptionIndex !== undefined
|
|
82
|
+
? { correctOptionIndex: zeroBasedCorrectOptionIndex }
|
|
83
|
+
: {}),
|
|
84
|
+
...(options.pollExplanation ? { explanation: options.pollExplanation } : {}),
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const instagram = {
|
|
88
|
+
...(options.instagramCollab ? { collab: options.instagramCollab } : {}),
|
|
89
|
+
...(options.instagramLocationId || options.instagramLocationName
|
|
90
|
+
? {
|
|
91
|
+
location: {
|
|
92
|
+
...(options.instagramLocationId ? { id: options.instagramLocationId } : {}),
|
|
93
|
+
...(options.instagramLocationName ? { name: options.instagramLocationName } : {}),
|
|
94
|
+
},
|
|
95
|
+
}
|
|
96
|
+
: {}),
|
|
97
|
+
...(options.instagramTrialReel ? { trialReel: options.instagramTrialReel } : {}),
|
|
98
|
+
...(parseBooleanStrict(options.instagramShareToFeed, "instagram-share-to-feed") !== undefined
|
|
99
|
+
? { shareToFeed: parseBooleanStrict(options.instagramShareToFeed, "instagram-share-to-feed") }
|
|
100
|
+
: {}),
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const facebook = {
|
|
104
|
+
...(options.facebookCollab ? { collab: options.facebookCollab } : {}),
|
|
105
|
+
...(options.facebookLocationId || options.facebookLocationName
|
|
106
|
+
? {
|
|
107
|
+
location: {
|
|
108
|
+
...(options.facebookLocationId ? { id: options.facebookLocationId } : {}),
|
|
109
|
+
...(options.facebookLocationName ? { name: options.facebookLocationName } : {}),
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
: {}),
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const tiktok = {
|
|
116
|
+
...(parseBooleanStrict(options.tiktokSendToInbox, "tiktok-send-to-inbox") !== undefined
|
|
117
|
+
? { sendToInbox: parseBooleanStrict(options.tiktokSendToInbox, "tiktok-send-to-inbox") }
|
|
118
|
+
: {}),
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
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) } : {}),
|
|
128
|
+
...(youtubePlaylists ? { playlists: youtubePlaylists } : {}),
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
...(options.title ? { title: options.title } : {}),
|
|
133
|
+
...(options.caption ? { caption: options.caption } : {}),
|
|
134
|
+
...(options.alt ? { alt: options.alt } : {}),
|
|
135
|
+
...(options.link ? { link: validateHttpUrl(options.link, "link") } : {}),
|
|
136
|
+
...(options.postType ? { postType: options.postType } : {}),
|
|
137
|
+
publishMode,
|
|
138
|
+
publishAt,
|
|
139
|
+
...(parseBooleanStrict(options.postAsStory, "post-as-story") !== undefined
|
|
140
|
+
? { postAsStory: parseBooleanStrict(options.postAsStory, "post-as-story") }
|
|
141
|
+
: {}),
|
|
142
|
+
...(options.comment
|
|
143
|
+
? {
|
|
144
|
+
comment: {
|
|
145
|
+
comment: options.comment,
|
|
146
|
+
...(parseOptionalPositiveInteger(options.commentDelay, "comment-delay") !== undefined
|
|
147
|
+
? { delay: parseOptionalPositiveInteger(options.commentDelay, "comment-delay") }
|
|
148
|
+
: {}),
|
|
149
|
+
},
|
|
150
|
+
}
|
|
151
|
+
: {}),
|
|
152
|
+
...(media.length > 0 ? { media } : {}),
|
|
153
|
+
...(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
|
|
155
|
+
? {
|
|
156
|
+
platforms: {
|
|
157
|
+
...(Object.keys(instagram).length > 0 ? { instagram } : {}),
|
|
158
|
+
...(Object.keys(facebook).length > 0 ? { facebook } : {}),
|
|
159
|
+
...(Object.keys(tiktok).length > 0 ? { tiktok } : {}),
|
|
160
|
+
...(Object.keys(youtube).length > 0 ? { youtube } : {}),
|
|
161
|
+
},
|
|
162
|
+
}
|
|
163
|
+
: {}),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export {
|
|
168
|
+
buildPostPayload,
|
|
169
|
+
mergeMedia,
|
|
170
|
+
parseBoolean,
|
|
171
|
+
parseCsv,
|
|
172
|
+
parseNumber,
|
|
173
|
+
VALID_PUBLISH_MODES,
|
|
174
|
+
};
|