@nuelink/nuelink-cli 1.6.6 → 1.7.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/CHANGELOG.md +6 -0
- package/README.md +19 -0
- package/package.json +1 -1
- package/src/commands.js +1 -0
- package/src/postPayload.js +137 -0
- package/test/cli.test.mjs +117 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.7.0
|
|
4
|
+
|
|
5
|
+
- Add `posts:create --googlemybusiness-post <json>` support for Google Business Profile STANDARD, EVENT, and OFFER post settings.
|
|
6
|
+
- Validate Google Business event dates, times, required fields, and offer details before previewing or sending requests.
|
|
7
|
+
- Document Google Business Profile request fields and include the supported payload in the Postman collection.
|
|
8
|
+
|
|
3
9
|
## 1.6.6
|
|
4
10
|
|
|
5
11
|
- Reject polls with missing or empty options before requests and dry-run previews; every poll requires a question, 2 to 4 options, and a supported period.
|
package/README.md
CHANGED
|
@@ -331,6 +331,25 @@ nuelink-cli posts:create \
|
|
|
331
331
|
--dry-run
|
|
332
332
|
```
|
|
333
333
|
|
|
334
|
+
Pass the nested Google Business Profile post data as JSON with
|
|
335
|
+
`--googlemybusiness-post`. The JSON object must include `type`, which accepts
|
|
336
|
+
`STANDARD`, `EVENT`, or `OFFER`; the fields map directly under
|
|
337
|
+
`platforms.googlemybusiness`.
|
|
338
|
+
Both `EVENT` and `OFFER` require an `event` with a title (up to 58 characters),
|
|
339
|
+
start and end dates (`YYYY-MM-DD`), and start and end times (`HH:mm:ss`).
|
|
340
|
+
`offer` may include a coupon code (up to 58 characters), a redemption URL, and
|
|
341
|
+
terms (up to 1000 characters).
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
nuelink-cli posts:create \
|
|
345
|
+
--brand-id 13493 \
|
|
346
|
+
--collection-id 33273 \
|
|
347
|
+
--caption "Holiday promotion" \
|
|
348
|
+
--publish-mode DRAFT \
|
|
349
|
+
--googlemybusiness-post '{"type":"OFFER","event":{"title":"Holiday offer","startDate":"2099-12-30","startTime":"09:00:00","endDate":"2099-12-31","endTime":"18:00:00"},"offer":{"couponCode":"SAVE20","redeemOnlineUrl":"https://example.com/offer","termsConditions":"One per customer."}}' \
|
|
350
|
+
--dry-run
|
|
351
|
+
```
|
|
352
|
+
|
|
334
353
|
`--comment-delay` is measured in minutes after publishing and must be a positive
|
|
335
354
|
integer (minimum `1`). Provide it together with `--comment`; the JSON/API field
|
|
336
355
|
is `comment.delay` and uses the same minutes unit.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuelink/nuelink-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
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
|
@@ -906,6 +906,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
906
906
|
.option("--youtube-tags <tags>", "Comma-separated YouTube tags")
|
|
907
907
|
.option("--youtube-playlists <json>", "YouTube playlists JSON string")
|
|
908
908
|
.option("--googlemybusiness-upload-to-photos-section <boolean>", "Upload to Google Business Profile photos: true/false")
|
|
909
|
+
.option("--googlemybusiness-post <json>", "Google Business Profile post settings JSON (type, event, and offer)")
|
|
909
910
|
.action(withCommandErrorHandling(program, async (options) => {
|
|
910
911
|
if (options.comment === undefined && options.commentDelay !== undefined) {
|
|
911
912
|
throw new Error("comment and comment-delay must be provided together.");
|
package/src/postPayload.js
CHANGED
|
@@ -67,6 +67,129 @@ function normalizePublishMode(value) {
|
|
|
67
67
|
return normalized;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
function validateGoogleBusinessPostOptions(value, label = "googlemybusiness-post", requireType = false) {
|
|
71
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
72
|
+
throw new Error(`Invalid ${label}. Expected a JSON object.`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const allowedKeys = ["type", "event", "offer"];
|
|
76
|
+
const unexpectedKey = Object.keys(value).find((key) => !allowedKeys.includes(key));
|
|
77
|
+
if (unexpectedKey) {
|
|
78
|
+
throw new Error(`Invalid ${label}. Unexpected field "${unexpectedKey}".`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const validTypes = ["STANDARD", "OFFER", "EVENT"];
|
|
82
|
+
if (requireType && (value.type === undefined || value.type === null)) {
|
|
83
|
+
throw new Error(`Invalid ${label}. type is required.`);
|
|
84
|
+
}
|
|
85
|
+
if (value.type !== undefined && value.type !== null && !validTypes.includes(value.type)) {
|
|
86
|
+
throw new Error(`Invalid ${label}. type must be one of: ${validTypes.join(", ")}, or null.`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (
|
|
90
|
+
((value.event !== undefined && value.event !== null) || (value.offer !== undefined && value.offer !== null)) &&
|
|
91
|
+
(value.type === undefined || value.type === null)
|
|
92
|
+
) {
|
|
93
|
+
throw new Error(`Invalid ${label}. A non-null type is required when event or offer is provided.`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const requiresEvent = value.type === "OFFER" || value.type === "EVENT";
|
|
97
|
+
if (requiresEvent && (value.event === undefined || value.event === null)) {
|
|
98
|
+
throw new Error(`Invalid ${label}. event is required when type is ${value.type}.`);
|
|
99
|
+
}
|
|
100
|
+
if (value.event !== undefined && value.event !== null) {
|
|
101
|
+
const event = value.event;
|
|
102
|
+
const eventLabel = `${label}.event`;
|
|
103
|
+
if (!event || typeof event !== "object" || Array.isArray(event)) {
|
|
104
|
+
throw new Error(`Invalid ${eventLabel}. Expected a JSON object or null.`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const eventFields = ["title", "startDate", "startTime", "endDate", "endTime"];
|
|
108
|
+
const unexpectedEventField = Object.keys(event).find((key) => !eventFields.includes(key));
|
|
109
|
+
if (unexpectedEventField) {
|
|
110
|
+
throw new Error(`Invalid ${eventLabel}. Unexpected field "${unexpectedEventField}".`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
for (const field of eventFields) {
|
|
114
|
+
const fieldValue = event[field];
|
|
115
|
+
const fieldLabel = `${eventLabel}.${field}`;
|
|
116
|
+
if (requiresEvent && (fieldValue === undefined || fieldValue === null || String(fieldValue).trim() === "")) {
|
|
117
|
+
throw new Error(`Invalid ${fieldLabel}. This field is required when type is ${value.type}.`);
|
|
118
|
+
}
|
|
119
|
+
if (fieldValue === undefined || fieldValue === null) continue;
|
|
120
|
+
if (typeof fieldValue !== "string") {
|
|
121
|
+
throw new Error(`Invalid ${fieldLabel}. Expected a string or null.`);
|
|
122
|
+
}
|
|
123
|
+
if (field === "title") {
|
|
124
|
+
validateOptionalLength(fieldValue, 58, fieldLabel);
|
|
125
|
+
} else if (field === "startDate" || field === "endDate") {
|
|
126
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(fieldValue)) {
|
|
127
|
+
throw new Error(`Invalid ${fieldLabel}. Expected YYYY-MM-DD.`);
|
|
128
|
+
}
|
|
129
|
+
const date = new Date(`${fieldValue}T00:00:00.000Z`);
|
|
130
|
+
if (Number.isNaN(date.getTime()) || date.toISOString().slice(0, 10) !== fieldValue) {
|
|
131
|
+
throw new Error(`Invalid ${fieldLabel}. Expected a real calendar date in YYYY-MM-DD format.`);
|
|
132
|
+
}
|
|
133
|
+
} else if (!/^([01]\d|2[0-3]):[0-5]\d:[0-5]\d$/.test(fieldValue)) {
|
|
134
|
+
throw new Error(`Invalid ${fieldLabel}. Expected HH:mm:ss.`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (value.offer !== undefined && value.offer !== null) {
|
|
140
|
+
const offer = value.offer;
|
|
141
|
+
const offerLabel = `${label}.offer`;
|
|
142
|
+
if (!offer || typeof offer !== "object" || Array.isArray(offer)) {
|
|
143
|
+
throw new Error(`Invalid ${offerLabel}. Expected a JSON object or null.`);
|
|
144
|
+
}
|
|
145
|
+
const offerFields = ["couponCode", "redeemOnlineUrl", "termsConditions"];
|
|
146
|
+
const unexpectedOfferField = Object.keys(offer).find((key) => !offerFields.includes(key));
|
|
147
|
+
if (unexpectedOfferField) {
|
|
148
|
+
throw new Error(`Invalid ${offerLabel}. Unexpected field "${unexpectedOfferField}".`);
|
|
149
|
+
}
|
|
150
|
+
for (const field of ["couponCode", "termsConditions"]) {
|
|
151
|
+
const fieldValue = offer[field];
|
|
152
|
+
if (fieldValue !== undefined && fieldValue !== null) {
|
|
153
|
+
if (typeof fieldValue !== "string") {
|
|
154
|
+
throw new Error(`Invalid ${offerLabel}.${field}. Expected a string or null.`);
|
|
155
|
+
}
|
|
156
|
+
validateOptionalLength(fieldValue, field === "couponCode" ? 58 : 1000, `${offerLabel}.${field}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (offer.redeemOnlineUrl !== undefined && offer.redeemOnlineUrl !== null) {
|
|
160
|
+
if (typeof offer.redeemOnlineUrl !== "string") {
|
|
161
|
+
throw new Error(`Invalid ${offerLabel}.redeemOnlineUrl. Expected a string or null.`);
|
|
162
|
+
}
|
|
163
|
+
validateHttpUrl(offer.redeemOnlineUrl, `${offerLabel}.redeemOnlineUrl`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return value;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function validateGoogleBusinessOptions(value, label = "platforms.googlemybusiness") {
|
|
171
|
+
if (value === undefined || value === null) return;
|
|
172
|
+
if (typeof value !== "object" || Array.isArray(value)) {
|
|
173
|
+
throw new Error(`Invalid ${label}. Expected a JSON object or null.`);
|
|
174
|
+
}
|
|
175
|
+
if (
|
|
176
|
+
value.uploadToPhotosSection !== undefined &&
|
|
177
|
+
value.uploadToPhotosSection !== null &&
|
|
178
|
+
typeof value.uploadToPhotosSection !== "boolean"
|
|
179
|
+
) {
|
|
180
|
+
throw new Error(`Invalid ${label}.uploadToPhotosSection. Expected a boolean or null.`);
|
|
181
|
+
}
|
|
182
|
+
const postOptions = {};
|
|
183
|
+
for (const field of ["type", "event", "offer"]) {
|
|
184
|
+
if (Object.prototype.hasOwnProperty.call(value, field)) {
|
|
185
|
+
postOptions[field] = value[field];
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (Object.keys(postOptions).length > 0) {
|
|
189
|
+
validateGoogleBusinessPostOptions(postOptions, label);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
70
193
|
function validateRawPostPayload(payload) {
|
|
71
194
|
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
72
195
|
throw new Error("Invalid payload. Expected a JSON object.");
|
|
@@ -87,6 +210,12 @@ function validateRawPostPayload(payload) {
|
|
|
87
210
|
if (payload.link !== undefined && payload.link !== null) {
|
|
88
211
|
validateHttpUrl(payload.link, "link");
|
|
89
212
|
}
|
|
213
|
+
if (payload.platforms !== undefined && payload.platforms !== null) {
|
|
214
|
+
if (typeof payload.platforms !== "object" || Array.isArray(payload.platforms)) {
|
|
215
|
+
throw new Error("Invalid platforms. Expected a JSON object or null.");
|
|
216
|
+
}
|
|
217
|
+
validateGoogleBusinessOptions(payload.platforms.googlemybusiness);
|
|
218
|
+
}
|
|
90
219
|
|
|
91
220
|
const poll = payload.poll;
|
|
92
221
|
const caption = !poll
|
|
@@ -256,6 +385,13 @@ function buildPostPayload(options) {
|
|
|
256
385
|
: {}),
|
|
257
386
|
...(youtubePlaylists ? { playlists: youtubePlaylists } : {}),
|
|
258
387
|
};
|
|
388
|
+
const googleBusinessPost = options.googlemybusinessPost === undefined
|
|
389
|
+
? undefined
|
|
390
|
+
: validateGoogleBusinessPostOptions(
|
|
391
|
+
parseJsonString(options.googlemybusinessPost, "googlemybusiness-post"),
|
|
392
|
+
"googlemybusiness-post",
|
|
393
|
+
true,
|
|
394
|
+
);
|
|
259
395
|
const googlemybusiness = {
|
|
260
396
|
...(parseBooleanStrict(
|
|
261
397
|
options.googlemybusinessUploadToPhotosSection,
|
|
@@ -268,6 +404,7 @@ function buildPostPayload(options) {
|
|
|
268
404
|
),
|
|
269
405
|
}
|
|
270
406
|
: {}),
|
|
407
|
+
...(googleBusinessPost !== undefined ? googleBusinessPost : {}),
|
|
271
408
|
};
|
|
272
409
|
|
|
273
410
|
const hasPoll = Object.keys(poll).length > 0;
|
package/test/cli.test.mjs
CHANGED
|
@@ -778,6 +778,23 @@ test("posts:add-json preserves nullable contract fields for dry-run and request
|
|
|
778
778
|
poll: null,
|
|
779
779
|
publishMode: "DRAFT",
|
|
780
780
|
},
|
|
781
|
+
{
|
|
782
|
+
caption: "Google Business event draft",
|
|
783
|
+
publishMode: "DRAFT",
|
|
784
|
+
platforms: {
|
|
785
|
+
googlemybusiness: {
|
|
786
|
+
uploadToPhotosSection: true,
|
|
787
|
+
type: "EVENT",
|
|
788
|
+
event: {
|
|
789
|
+
title: "Store opening",
|
|
790
|
+
startDate: "2099-12-30",
|
|
791
|
+
startTime: "09:00:00",
|
|
792
|
+
endDate: "2099-12-31",
|
|
793
|
+
endTime: "18:00:00",
|
|
794
|
+
},
|
|
795
|
+
},
|
|
796
|
+
},
|
|
797
|
+
},
|
|
781
798
|
];
|
|
782
799
|
|
|
783
800
|
for (const [index, payload] of payloads.entries()) {
|
|
@@ -859,6 +876,60 @@ test("posts:add-json rejects invalid autoThreadText values", async () => {
|
|
|
859
876
|
assert.match(result.stderr, /Invalid autoThreadText/);
|
|
860
877
|
});
|
|
861
878
|
|
|
879
|
+
test("posts:add-json rejects invalid Google Business post fields", async () => {
|
|
880
|
+
const homeDir = await setupTempHome();
|
|
881
|
+
const invalidGoogleBusinessOptions = [
|
|
882
|
+
{ type: "UNKNOWN" },
|
|
883
|
+
{ type: "EVENT" },
|
|
884
|
+
{
|
|
885
|
+
type: "EVENT",
|
|
886
|
+
event: {
|
|
887
|
+
title: " ",
|
|
888
|
+
startDate: "2099-12-30",
|
|
889
|
+
startTime: "10:00:00",
|
|
890
|
+
endDate: "2099-12-31",
|
|
891
|
+
endTime: "11:00:00",
|
|
892
|
+
},
|
|
893
|
+
},
|
|
894
|
+
{
|
|
895
|
+
type: "EVENT",
|
|
896
|
+
event: {
|
|
897
|
+
title: "Event",
|
|
898
|
+
startDate: "2026-02-30",
|
|
899
|
+
startTime: "10:00:00",
|
|
900
|
+
endDate: "2026-03-01",
|
|
901
|
+
endTime: "11:00:00",
|
|
902
|
+
},
|
|
903
|
+
},
|
|
904
|
+
{ type: "STANDARD", event: { unexpected: true } },
|
|
905
|
+
{ event: { title: "Event" } },
|
|
906
|
+
{ offer: { couponCode: "SAVE20" } },
|
|
907
|
+
{
|
|
908
|
+
type: "OFFER",
|
|
909
|
+
event: {
|
|
910
|
+
title: "Offer",
|
|
911
|
+
startDate: "2099-12-30",
|
|
912
|
+
startTime: "10:00:00",
|
|
913
|
+
endDate: "2099-12-31",
|
|
914
|
+
endTime: "11:00:00",
|
|
915
|
+
},
|
|
916
|
+
offer: { redeemOnlineUrl: "not a url" },
|
|
917
|
+
},
|
|
918
|
+
];
|
|
919
|
+
|
|
920
|
+
for (const [index, googleBusinessOptions] of invalidGoogleBusinessOptions.entries()) {
|
|
921
|
+
const result = runCli({
|
|
922
|
+
args: ["posts:add-json", "--brand-id", "10", "--collection-id", "20", "--payload", "-"],
|
|
923
|
+
homeDir,
|
|
924
|
+
capturePath: path.join(homeDir, `capture-invalid-gmb-post-${index}.json`),
|
|
925
|
+
input: JSON.stringify({ caption: "Google Business post", publishMode: "DRAFT", platforms: { googlemybusiness: googleBusinessOptions } }),
|
|
926
|
+
});
|
|
927
|
+
assert.equal(result.status, 1, result.stderr);
|
|
928
|
+
assert.match(result.stderr, /googlemybusiness|Google Business/i);
|
|
929
|
+
await assert.rejects(readFile(path.join(homeDir, `capture-invalid-gmb-post-${index}.json`), "utf8"));
|
|
930
|
+
}
|
|
931
|
+
});
|
|
932
|
+
|
|
862
933
|
test("dry-run prints validated request without sending", async () => {
|
|
863
934
|
const homeDir = await setupTempHome();
|
|
864
935
|
const capturePath = path.join(homeDir, "capture-dry-run.json");
|
|
@@ -956,6 +1027,21 @@ test("new public API management commands build the documented requests", async (
|
|
|
956
1027
|
test("posts:create builds full payload from options", async () => {
|
|
957
1028
|
const homeDir = await setupTempHome();
|
|
958
1029
|
const capturePath = path.join(homeDir, "capture-posts-create.json");
|
|
1030
|
+
const googleBusinessPost = {
|
|
1031
|
+
type: "OFFER",
|
|
1032
|
+
event: {
|
|
1033
|
+
title: "Holiday offer",
|
|
1034
|
+
startDate: "2099-12-30",
|
|
1035
|
+
startTime: "09:00:00",
|
|
1036
|
+
endDate: "2099-12-31",
|
|
1037
|
+
endTime: "18:00:00",
|
|
1038
|
+
},
|
|
1039
|
+
offer: {
|
|
1040
|
+
couponCode: "SAVE20",
|
|
1041
|
+
redeemOnlineUrl: "https://example.com/offer",
|
|
1042
|
+
termsConditions: "One per customer.",
|
|
1043
|
+
},
|
|
1044
|
+
};
|
|
959
1045
|
|
|
960
1046
|
const result = runCli({
|
|
961
1047
|
args: [
|
|
@@ -1020,6 +1106,8 @@ test("posts:create builds full payload from options", async () => {
|
|
|
1020
1106
|
'[{"channelId":1,"playlistIds":["1","2"]}]',
|
|
1021
1107
|
"--googlemybusiness-upload-to-photos-section",
|
|
1022
1108
|
"true",
|
|
1109
|
+
"--googlemybusiness-post",
|
|
1110
|
+
JSON.stringify(googleBusinessPost),
|
|
1023
1111
|
],
|
|
1024
1112
|
homeDir,
|
|
1025
1113
|
capturePath,
|
|
@@ -1048,6 +1136,35 @@ test("posts:create builds full payload from options", async () => {
|
|
|
1048
1136
|
{ channelId: 1, playlistIds: ["1", "2"] },
|
|
1049
1137
|
]);
|
|
1050
1138
|
assert.equal(capture.body.platforms.googlemybusiness.uploadToPhotosSection, true);
|
|
1139
|
+
assert.deepEqual(capture.body.platforms.googlemybusiness, {
|
|
1140
|
+
uploadToPhotosSection: true,
|
|
1141
|
+
...googleBusinessPost,
|
|
1142
|
+
});
|
|
1143
|
+
});
|
|
1144
|
+
|
|
1145
|
+
test("posts:create requires a Google Business Profile type in its post JSON option", async () => {
|
|
1146
|
+
const homeDir = await setupTempHome();
|
|
1147
|
+
const capturePath = path.join(homeDir, "capture-gmb-post-without-type.json");
|
|
1148
|
+
const result = runCli({
|
|
1149
|
+
args: [
|
|
1150
|
+
"--dry-run",
|
|
1151
|
+
"posts:create",
|
|
1152
|
+
"--brand-id",
|
|
1153
|
+
"10",
|
|
1154
|
+
"--collection-id",
|
|
1155
|
+
"20",
|
|
1156
|
+
"--caption",
|
|
1157
|
+
"Google Business post",
|
|
1158
|
+
"--googlemybusiness-post",
|
|
1159
|
+
JSON.stringify({ event: { title: "Event" } }),
|
|
1160
|
+
],
|
|
1161
|
+
homeDir,
|
|
1162
|
+
capturePath,
|
|
1163
|
+
});
|
|
1164
|
+
|
|
1165
|
+
assert.equal(result.status, 1);
|
|
1166
|
+
assert.match(result.stderr, /type is required/i);
|
|
1167
|
+
await assert.rejects(readFile(capturePath, "utf8"));
|
|
1051
1168
|
});
|
|
1052
1169
|
|
|
1053
1170
|
test("posts:create rejects missing, empty, or out-of-range poll options before preview or request", async () => {
|