@nuelink/nuelink-cli 1.6.5 → 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 +12 -0
- package/CONTRIBUTING.md +7 -2
- package/README.md +47 -7
- package/package.json +4 -7
- package/scripts/check-pack.mjs +30 -0
- package/scripts/check-packed-package.mjs +60 -0
- package/src/commands.js +2 -1
- package/src/postPayload.js +139 -2
- package/test/cli.test.mjs +171 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
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
|
+
|
|
9
|
+
## 1.6.6
|
|
10
|
+
|
|
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.
|
|
12
|
+
- Point package documentation and bug reports to the public Nuelink documentation and support pages; remove the inaccessible source-repository link.
|
|
13
|
+
- Include the package-check scripts in the npm package and verify their presence and execution after installation.
|
|
14
|
+
|
|
3
15
|
## 1.6.5
|
|
4
16
|
|
|
5
17
|
- Use minutes, with a minimum of 1, for delayed-comment values in post creation.
|
package/CONTRIBUTING.md
CHANGED
|
@@ -50,11 +50,13 @@ Conventional commit style is recommended:
|
|
|
50
50
|
|
|
51
51
|
## Quality Gates
|
|
52
52
|
|
|
53
|
-
Run before pushing
|
|
53
|
+
Run before pushing from the `nuelink-cli/` source checkout. The package checks
|
|
54
|
+
are also shipped in the npm package for validation from its installed directory:
|
|
54
55
|
|
|
55
56
|
```bash
|
|
56
57
|
npm test
|
|
57
58
|
npm run check:pack
|
|
59
|
+
npm run check:pack:installed
|
|
58
60
|
```
|
|
59
61
|
|
|
60
62
|
## Code Style
|
|
@@ -88,6 +90,8 @@ When adding commands, include tests for:
|
|
|
88
90
|
|
|
89
91
|
## Reporting Bugs
|
|
90
92
|
|
|
93
|
+
Report bugs through [Nuelink support](https://nuelink.com/contact).
|
|
94
|
+
|
|
91
95
|
Include:
|
|
92
96
|
|
|
93
97
|
1. CLI version (`nuelink-cli --version`)
|
|
@@ -108,12 +112,13 @@ Provide:
|
|
|
108
112
|
## Release Process (Maintainers)
|
|
109
113
|
|
|
110
114
|
1. Ensure CI is passing.
|
|
111
|
-
2. Bump version in `package.json
|
|
115
|
+
2. Bump the version in `package.json` and `package-lock.json`, and add a matching changelog entry.
|
|
112
116
|
3. Validate with:
|
|
113
117
|
|
|
114
118
|
```bash
|
|
115
119
|
npm test
|
|
116
120
|
npm run check:pack
|
|
121
|
+
npm run check:pack:installed
|
|
117
122
|
```
|
|
118
123
|
|
|
119
124
|
4. Publish:
|
package/README.md
CHANGED
|
@@ -4,6 +4,9 @@ Official command-line interface for the Nuelink Public API.
|
|
|
4
4
|
|
|
5
5
|
Published by the Nuelink organization as the scoped npm package `@nuelink/nuelink-cli`.
|
|
6
6
|
|
|
7
|
+
See the [CLI documentation](https://docs.nuelink.com/cli/) for usage and
|
|
8
|
+
[Nuelink support](https://nuelink.com/contact) for bug reports.
|
|
9
|
+
|
|
7
10
|
Use this CLI to manage brands, collections, automations, channels, media, and posts from local scripts, CI/CD pipelines, and terminal workflows.
|
|
8
11
|
|
|
9
12
|
## Features
|
|
@@ -15,6 +18,7 @@ Use this CLI to manage brands, collections, automations, channels, media, and po
|
|
|
15
18
|
- Dry-run request preview for mutation commands
|
|
16
19
|
- Strict local validation for common CLI input mistakes
|
|
17
20
|
- Built-in timeout support for safer production usage
|
|
21
|
+
- Redirect protection introduced in CLI 1.6.1, so API requests do not forward credentials or mutation bodies to redirect destinations
|
|
18
22
|
- Command coverage for key Nuelink Public API resources
|
|
19
23
|
|
|
20
24
|
## Requirements
|
|
@@ -327,18 +331,44 @@ nuelink-cli posts:create \
|
|
|
327
331
|
--dry-run
|
|
328
332
|
```
|
|
329
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
|
+
|
|
330
353
|
`--comment-delay` is measured in minutes after publishing and must be a positive
|
|
331
354
|
integer (minimum `1`). Provide it together with `--comment`; the JSON/API field
|
|
332
355
|
is `comment.delay` and uses the same minutes unit.
|
|
333
356
|
|
|
334
357
|
Review each mutation preview, then repeat the same command without `--dry-run`
|
|
335
358
|
only when you intend to send it. `--dry-run` is supported for mutations; GET
|
|
336
|
-
commands reject it instead of silently suppressing the read.
|
|
337
|
-
|
|
338
|
-
|
|
359
|
+
commands reject it instead of silently suppressing the read. Before executing a
|
|
360
|
+
scheduled mutation, confirm an absolute date and time in the brand's timezone;
|
|
361
|
+
it must be at least 10 minutes ahead. Date filters and returned `postDate`
|
|
362
|
+
values are UTC.
|
|
339
363
|
|
|
340
364
|
Supported publish modes are `DRAFT`, `QUEUE`, `SCHEDULE`, and `IMMEDIATE`. When using `SCHEDULE`, pass `--scheduled-at` in `YYYY-MM-DD HH:mm:ss` format. Poll correct-option indexes are zero-based.
|
|
341
365
|
|
|
366
|
+
Polls require `--poll-question`, `--poll-options` with 2 to 4 choices, and
|
|
367
|
+
`--poll-period` set to `1d`, `3d`, or `7d`. Missing or empty options fail local
|
|
368
|
+
validation, including during `--dry-run`. JSON payloads use the same required
|
|
369
|
+
`question`, `options`, and `period` fields inside `poll`; `poll: null` is accepted
|
|
370
|
+
when a caption is supplied.
|
|
371
|
+
|
|
342
372
|
Preview a post lifecycle update or sensitive deletion before executing it:
|
|
343
373
|
|
|
344
374
|
```bash
|
|
@@ -353,7 +383,12 @@ nuelink-cli posts:move --brand-id 13493 --source-collection-id 33273 \
|
|
|
353
383
|
nuelink-cli posts:delete --brand-id 13493 --post-id 8801 --dry-run
|
|
354
384
|
```
|
|
355
385
|
|
|
356
|
-
`posts:update`
|
|
386
|
+
`posts:update` requires at least one of `--caption`, `--publish-mode`, or
|
|
387
|
+
`--queue-position`. A caption-only update does not require changing the
|
|
388
|
+
publishing mode. Captions must contain 1–3000 characters; caption edits are not
|
|
389
|
+
available for poll or published posts. Moving is atomic: all supplied posts (at
|
|
390
|
+
most 100) must belong to the source collection. Deletion is permanent and the
|
|
391
|
+
API rejects it unless sensitive AI actions are enabled for the account.
|
|
357
392
|
|
|
358
393
|
Published-post results are returned unchanged in `--json` mode. Each per-channel
|
|
359
394
|
record includes `likes`, `comments`, `shares`, `views`, `saves`, `engagement`,
|
|
@@ -440,6 +475,11 @@ npm test
|
|
|
440
475
|
|
|
441
476
|
### Package validation
|
|
442
477
|
|
|
478
|
+
Run these checks from the `nuelink-cli/` source checkout before a release.
|
|
479
|
+
The scripts are also included in the npm package and can run from the installed
|
|
480
|
+
package directory. The installed-package check creates a temporary package
|
|
481
|
+
installation and needs access to the npm registry.
|
|
482
|
+
|
|
443
483
|
```bash
|
|
444
484
|
npm run check:pack
|
|
445
485
|
npm run check:pack:installed
|
|
@@ -448,9 +488,9 @@ npm run check:pack:installed
|
|
|
448
488
|
## Release Checklist
|
|
449
489
|
|
|
450
490
|
1. Update the version in package.json and package-lock.json, and add a matching entry at the top of CHANGELOG.md
|
|
451
|
-
2.
|
|
452
|
-
3.
|
|
453
|
-
4.
|
|
491
|
+
2. From the source checkout, run `npm test`
|
|
492
|
+
3. From the source checkout, run `npm run check:pack`
|
|
493
|
+
4. From the source checkout, run `npm run check:pack:installed`
|
|
454
494
|
5. Publish locally with `npm publish --access public`
|
|
455
495
|
|
|
456
496
|
Provenance is available when publishing from a supported cloud CI provider. Do
|
package/package.json
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
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",
|
|
7
|
-
"
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/kreatinc/nuelink-cli.git"
|
|
10
|
-
},
|
|
11
|
-
"homepage": "https://github.com/kreatinc/nuelink-cli#readme",
|
|
7
|
+
"homepage": "https://docs.nuelink.com/cli/",
|
|
12
8
|
"bugs": {
|
|
13
|
-
"url": "https://
|
|
9
|
+
"url": "https://nuelink.com/contact"
|
|
14
10
|
},
|
|
15
11
|
"type": "module",
|
|
16
12
|
"main": "./src/cli.js",
|
|
@@ -26,6 +22,7 @@
|
|
|
26
22
|
"files": [
|
|
27
23
|
"src",
|
|
28
24
|
"test",
|
|
25
|
+
"scripts",
|
|
29
26
|
"CHANGELOG.md",
|
|
30
27
|
"README.md",
|
|
31
28
|
"CONTRIBUTING.md",
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { spawnSync } from "node:child_process";
|
|
5
|
+
|
|
6
|
+
const npmCli = process.env.npm_execpath;
|
|
7
|
+
const cacheDirectory = fs.mkdtempSync(path.join(os.tmpdir(), "nuelink-cli-npm-cache-"));
|
|
8
|
+
|
|
9
|
+
if (!npmCli || !fs.existsSync(npmCli)) {
|
|
10
|
+
throw new Error("Run this check through `npm run check:pack`.");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const result = spawnSync(process.execPath, [npmCli, "pack", "--dry-run", "--json"], {
|
|
15
|
+
encoding: "utf8",
|
|
16
|
+
env: { ...process.env, CI: "1", npm_config_cache: cacheDirectory },
|
|
17
|
+
});
|
|
18
|
+
if (result.status !== 0) {
|
|
19
|
+
throw new Error(`npm pack --dry-run failed:\n${result.stdout}\n${result.stderr}`);
|
|
20
|
+
}
|
|
21
|
+
const [packed] = JSON.parse(result.stdout);
|
|
22
|
+
for (const script of ["scripts/check-pack.mjs", "scripts/check-packed-package.mjs"]) {
|
|
23
|
+
if (!packed.files.some((file) => file.path === script)) {
|
|
24
|
+
throw new Error(`Package advertises a check command but omits ${script}.`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
process.stdout.write(result.stdout);
|
|
28
|
+
} finally {
|
|
29
|
+
fs.rmSync(cacheDirectory, { recursive: true, force: true });
|
|
30
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { spawnSync } from "node:child_process";
|
|
5
|
+
|
|
6
|
+
const root = process.cwd();
|
|
7
|
+
const npmCli = process.env.npm_execpath;
|
|
8
|
+
const temporaryRoot = fs.mkdtempSync(path.join(os.tmpdir(), "nuelink-cli-pack-"));
|
|
9
|
+
const cacheDirectory = path.join(temporaryRoot, "npm-cache");
|
|
10
|
+
const packDirectory = path.join(temporaryRoot, "pack");
|
|
11
|
+
const installDirectory = path.join(temporaryRoot, "install");
|
|
12
|
+
|
|
13
|
+
if (!npmCli || !fs.existsSync(npmCli)) {
|
|
14
|
+
throw new Error("Run this check through `npm run check:pack:installed`.");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
fs.mkdirSync(packDirectory);
|
|
18
|
+
fs.mkdirSync(installDirectory);
|
|
19
|
+
|
|
20
|
+
function runNpm(args, cwd = root) {
|
|
21
|
+
const result = spawnSync(process.execPath, [npmCli, ...args], {
|
|
22
|
+
cwd,
|
|
23
|
+
encoding: "utf8",
|
|
24
|
+
env: { ...process.env, CI: "1", npm_config_cache: cacheDirectory },
|
|
25
|
+
});
|
|
26
|
+
if (result.status !== 0) {
|
|
27
|
+
throw new Error(`npm ${args.join(" ")} failed:\n${result.stdout}\n${result.stderr}`);
|
|
28
|
+
}
|
|
29
|
+
return result.stdout;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
const packed = JSON.parse(runNpm(["pack", "--json", "--pack-destination", packDirectory]));
|
|
34
|
+
const tarball = path.join(packDirectory, packed[0].filename);
|
|
35
|
+
runNpm(["install", tarball, "--ignore-scripts", "--prefix", installDirectory], installDirectory);
|
|
36
|
+
|
|
37
|
+
const installedPackage = path.join(installDirectory, "node_modules", "@nuelink", "nuelink-cli");
|
|
38
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(installedPackage, "package.json"), "utf8"));
|
|
39
|
+
const runtimeDependencies = Object.keys(manifest.dependencies || {}).sort();
|
|
40
|
+
if (JSON.stringify(runtimeDependencies) !== JSON.stringify(["chalk", "commander"])) {
|
|
41
|
+
throw new Error(`Unexpected runtime dependencies in the packed CLI: ${runtimeDependencies.join(", ")}.`);
|
|
42
|
+
}
|
|
43
|
+
if (!fs.existsSync(path.join(installedPackage, "CONTRIBUTING.md"))) {
|
|
44
|
+
throw new Error("Packed README links to CONTRIBUTING.md, but the package omitted that file.");
|
|
45
|
+
}
|
|
46
|
+
if (!fs.readFileSync(path.join(installedPackage, "CHANGELOG.md"), "utf8").includes(`## ${manifest.version}`)) {
|
|
47
|
+
throw new Error(`Packed changelog does not contain package version ${manifest.version}.`);
|
|
48
|
+
}
|
|
49
|
+
for (const script of ["scripts/check-pack.mjs", "scripts/check-packed-package.mjs"]) {
|
|
50
|
+
if (!fs.existsSync(path.join(installedPackage, script))) {
|
|
51
|
+
throw new Error(`Installed package omits advertised check script ${script}.`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
runNpm(["test", "--prefix", installedPackage], installedPackage);
|
|
55
|
+
runNpm(["run", "check:pack", "--prefix", installedPackage], installedPackage);
|
|
56
|
+
|
|
57
|
+
console.log("Packed-package test passed (fresh install, npm test, and installed packaging scripts).");
|
|
58
|
+
} finally {
|
|
59
|
+
fs.rmSync(temporaryRoot, { recursive: true, force: true });
|
|
60
|
+
}
|
package/src/commands.js
CHANGED
|
@@ -890,7 +890,7 @@ function registerCommands(program, runtimeApiKey, cliVersion) {
|
|
|
890
890
|
.option("--media-ids <ids>", "Comma-separated media IDs")
|
|
891
891
|
.option("--media-urls <urls>", "Comma-separated media URLs")
|
|
892
892
|
.option("--poll-question <text>", "Poll question")
|
|
893
|
-
.option("--poll-options <items>", "
|
|
893
|
+
.option("--poll-options <items>", "2 to 4 comma-separated options; required with a poll")
|
|
894
894
|
.option("--poll-period <value>", "Poll period (e.g. 3d)")
|
|
895
895
|
.option("--poll-correct-option-index <number>", "Zero-based poll correct option index")
|
|
896
896
|
.option("--poll-explanation <text>", "Poll explanation")
|
|
@@ -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;
|
|
@@ -276,10 +413,10 @@ function buildPostPayload(options) {
|
|
|
276
413
|
: options.caption === undefined
|
|
277
414
|
? undefined
|
|
278
415
|
: String(options.caption).trim();
|
|
279
|
-
if (hasPoll && (!poll.question ||
|
|
416
|
+
if (hasPoll && (!poll.question || pollOptions.length < 2 || !poll.period)) {
|
|
280
417
|
throw new Error("poll requires question, 2 to 4 options, and period.");
|
|
281
418
|
}
|
|
282
|
-
if (
|
|
419
|
+
if (pollOptions.length > 4) {
|
|
283
420
|
throw new Error("Polls allow at most four options.");
|
|
284
421
|
}
|
|
285
422
|
|
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,89 @@ 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"));
|
|
1168
|
+
});
|
|
1169
|
+
|
|
1170
|
+
test("posts:create rejects missing, empty, or out-of-range poll options before preview or request", async () => {
|
|
1171
|
+
const homeDir = await setupTempHome();
|
|
1172
|
+
const invalidOptions = [[], ["--poll-options", ""], ["--poll-options", " , "],
|
|
1173
|
+
["--poll-options", "One"], ["--poll-options", "1,2,3,4,5"]];
|
|
1174
|
+
|
|
1175
|
+
for (const [index, options] of invalidOptions.entries()) {
|
|
1176
|
+
for (const dryRun of [false, true]) {
|
|
1177
|
+
const capturePath = path.join(homeDir, `capture-invalid-poll-${index}-${dryRun}.json`);
|
|
1178
|
+
const result = runCli({
|
|
1179
|
+
args: ["--json", ...(dryRun ? ["--dry-run"] : []), "posts:create",
|
|
1180
|
+
"--brand-id", "10", "--collection-id", "20",
|
|
1181
|
+
"--poll-question", "Which one?", "--poll-period", "1d", ...options],
|
|
1182
|
+
homeDir,
|
|
1183
|
+
capturePath,
|
|
1184
|
+
});
|
|
1185
|
+
const error = assertJsonError(result, "VALIDATION_ERROR");
|
|
1186
|
+
assert.match(error.message, /poll/i);
|
|
1187
|
+
await assert.rejects(readFile(capturePath, "utf8"));
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
});
|
|
1191
|
+
|
|
1192
|
+
test("posts:create previews polls with two or four options", async () => {
|
|
1193
|
+
const homeDir = await setupTempHome();
|
|
1194
|
+
for (const options of [["One", "Two"], ["One", "Two", "Three", "Four"]]) {
|
|
1195
|
+
const result = runCli({
|
|
1196
|
+
args: ["--dry-run", "posts:create", "--brand-id", "10", "--collection-id", "20",
|
|
1197
|
+
"--poll-question", "Which one?", "--poll-period", "1d", "--poll-options", options.join(",")],
|
|
1198
|
+
homeDir,
|
|
1199
|
+
capturePath: path.join(homeDir, `capture-valid-poll-${options.length}.json`),
|
|
1200
|
+
});
|
|
1201
|
+
assert.equal(result.status, 0, result.stderr);
|
|
1202
|
+
assert.deepEqual(JSON.parse(result.stdout).body.poll, { question: "Which one?", options, period: "1d" });
|
|
1203
|
+
}
|
|
1204
|
+
});
|
|
1205
|
+
|
|
1206
|
+
test("posts:add-json rejects polls with missing or empty options before preview or request", async () => {
|
|
1207
|
+
const homeDir = await setupTempHome();
|
|
1208
|
+
for (const options of [undefined, []]) {
|
|
1209
|
+
for (const dryRun of [false, true]) {
|
|
1210
|
+
const capturePath = path.join(homeDir, `capture-invalid-json-poll-${options ? "empty" : "missing"}-${dryRun}.json`);
|
|
1211
|
+
const result = runCli({
|
|
1212
|
+
args: ["--json", ...(dryRun ? ["--dry-run"] : []), "posts:add-json",
|
|
1213
|
+
"--brand-id", "10", "--collection-id", "20", "--payload", "-"],
|
|
1214
|
+
homeDir,
|
|
1215
|
+
capturePath,
|
|
1216
|
+
input: JSON.stringify({ publishMode: "DRAFT", poll: { question: "Which one?", period: "1d", options } }),
|
|
1217
|
+
});
|
|
1218
|
+
assertJsonError(result, "VALIDATION_ERROR");
|
|
1219
|
+
await assert.rejects(readFile(capturePath, "utf8"));
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1051
1222
|
});
|
|
1052
1223
|
|
|
1053
1224
|
test("posts:create defaults autoThreadText to true and accepts false override", async () => {
|