@posterly/cli 0.1.3 → 0.1.5
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 +20 -0
- package/bin/posterly.mjs +569 -20
- package/generated/platform-manifest.mjs +128 -78
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@ Run the CLI without installing anything globally:
|
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
npx @posterly/cli@latest auth:login
|
|
11
|
+
npx @posterly/cli@latest doctor --pretty
|
|
11
12
|
npx @posterly/cli@latest whoami --pretty
|
|
12
13
|
```
|
|
13
14
|
|
|
@@ -20,6 +21,7 @@ Optional global install:
|
|
|
20
21
|
```bash
|
|
21
22
|
npm i -g @posterly/cli@latest
|
|
22
23
|
posterly auth:login
|
|
24
|
+
posterly doctor --pretty
|
|
23
25
|
posterly whoami --pretty
|
|
24
26
|
```
|
|
25
27
|
|
|
@@ -36,6 +38,7 @@ folder. In that case `posterly` will only be available as
|
|
|
36
38
|
```bash
|
|
37
39
|
posterly auth:login
|
|
38
40
|
posterly auth:key
|
|
41
|
+
posterly doctor --pretty
|
|
39
42
|
posterly whoami --pretty
|
|
40
43
|
posterly accounts:list --pretty
|
|
41
44
|
posterly accounts:disconnect 123 --confirm --pretty
|
|
@@ -43,16 +46,25 @@ posterly platforms:schema --platform instagram --pretty
|
|
|
43
46
|
posterly oauth:clients --pretty
|
|
44
47
|
posterly oauth:create-client --client-name "Agency approval app" --redirect-uri https://agency.example.com/oauth/callback --scopes accounts:read,posts:read,posts:write --pretty
|
|
45
48
|
posterly oauth:update-client poc_abc123 --client-name "Agency approval app v2" --confirm --pretty
|
|
49
|
+
posterly version
|
|
50
|
+
posterly ai:captions --platforms instagram,linkedin --brief "Announcing our summer sale" --tone playful --count 3 --pretty
|
|
51
|
+
posterly ai:captions --platforms twitter --mode adapt --source-caption "Long LinkedIn post text" --source-platform linkedin --pretty
|
|
52
|
+
posterly ai:image "A minimal flat-lay of a desk with coffee" --aspect-ratio 1:1 --style photographic --pretty
|
|
46
53
|
posterly ai:video-options --pretty
|
|
47
54
|
posterly ai:video-function google_veo estimate_cost --params '{"duration_seconds":8,"resolution":"720p","output":"vertical"}' --pretty
|
|
48
55
|
posterly posts:create --account-id 123 --caption "Launching soon" --scheduled-at 2026-06-01T09:00:00Z
|
|
49
56
|
posterly posts:status 123 --status paused --confirm --pretty
|
|
50
57
|
posterly posts:missing 123 --pretty
|
|
51
58
|
posterly posts:release-id 123 --release-id launch-2026-05-16 --group-id campaign-42 --pretty
|
|
59
|
+
posterly posts:delete 123 --confirm --pretty
|
|
52
60
|
posterly posts:delete-group campaign-42 --confirm --pretty
|
|
61
|
+
posterly webhooks:delete wh_123 --confirm --pretty
|
|
53
62
|
posterly gbp:reviews --account-id 123 --unanswered --pretty
|
|
54
63
|
posterly gbp:review-link 123 --pretty
|
|
55
64
|
posterly gbp:audit 123 --pretty
|
|
65
|
+
posterly gbp:media --account-id 123 --pretty
|
|
66
|
+
posterly gbp:add-media --account-id 123 --source-url https://cdn.example.com/front.jpg --category COVER --confirm --pretty
|
|
67
|
+
posterly gbp:delete-media --account-id 123 --media-name accounts/123/locations/456/media/abc --confirm --pretty
|
|
56
68
|
posterly gbp:suggest-reply --account-id 123 --star-rating 5 --review-text "Great service" --pretty
|
|
57
69
|
posterly gbp:reply --account-id 123 --review-name accounts/123/locations/456/reviews/abc --comment "Thanks Alex. Glad we could help." --confirm --pretty
|
|
58
70
|
```
|
|
@@ -61,6 +73,11 @@ The CLI outputs JSON by default so it can be piped into `jq` or other tools. Use
|
|
|
61
73
|
`--pretty` for formatted output. `--human` is accepted as an alias for
|
|
62
74
|
`--pretty` for older examples.
|
|
63
75
|
|
|
76
|
+
Use `posterly doctor --pretty` to check Node version, the configured API origin,
|
|
77
|
+
whether an API key is present, whether the key works against `/api/v1/whoami`,
|
|
78
|
+
and whether a newer `@posterly/cli` package is published. Add `--no-npm` to skip
|
|
79
|
+
the npm registry check in locked-down environments.
|
|
80
|
+
|
|
64
81
|
Authentication:
|
|
65
82
|
|
|
66
83
|
- Prefer `posterly auth:login` for browser-based OAuth.
|
|
@@ -73,3 +90,6 @@ command-line arguments in interactive shells because argv can be stored in shell
|
|
|
73
90
|
history or exposed through local process listings.
|
|
74
91
|
|
|
75
92
|
Set `--url` or `POSTERLY_URL` to point at a non-production posterly deployment.
|
|
93
|
+
The CLI refuses to send API keys to non-local `http://` URLs by default. Use
|
|
94
|
+
`https://`, `http://localhost` for local development, or `--allow-insecure-url`
|
|
95
|
+
only for a trusted private development endpoint.
|
package/bin/posterly.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { readFile, mkdir, writeFile, rm } from 'node:fs/promises';
|
|
3
|
+
import { readFile, mkdir, writeFile, rm, chmod, rename } from 'node:fs/promises';
|
|
4
4
|
import { existsSync } from 'node:fs';
|
|
5
5
|
import os from 'node:os';
|
|
6
6
|
import path from 'node:path';
|
|
@@ -15,16 +15,38 @@ import {
|
|
|
15
15
|
const DEFAULT_BASE_URL = 'https://www.poster.ly';
|
|
16
16
|
const CONFIG_DIR = path.join(os.homedir(), '.posterly');
|
|
17
17
|
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
|
18
|
+
const CLI_PACKAGE_NAME = '@posterly/cli';
|
|
19
|
+
const CLI_NPM_LATEST_URL = 'https://registry.npmjs.org/@posterly%2fcli/latest';
|
|
20
|
+
const REQUEST_TIMEOUT_MS = 2500;
|
|
21
|
+
const REQUIRED_NODE_MAJOR = 20;
|
|
18
22
|
const OAUTH_CLIENT_ID = 'posterly-cli';
|
|
19
23
|
const OAUTH_CALLBACK_PORT = 37373;
|
|
20
24
|
const OAUTH_CALLBACK_PATH = '/oauth/callback';
|
|
21
25
|
const OAUTH_SCOPES = ['accounts:read', 'accounts:write', 'posts:read', 'posts:write', 'media:write', 'analytics:read'];
|
|
26
|
+
const TRUSTED_POSTERLY_HOSTS = new Set(['poster.ly', 'www.poster.ly']);
|
|
27
|
+
const GOOGLE_BUSINESS_MEDIA_CATEGORIES = [
|
|
28
|
+
'COVER',
|
|
29
|
+
'PROFILE',
|
|
30
|
+
'LOGO',
|
|
31
|
+
'EXTERIOR',
|
|
32
|
+
'INTERIOR',
|
|
33
|
+
'PRODUCT',
|
|
34
|
+
'AT_WORK',
|
|
35
|
+
'FOOD_AND_DRINK',
|
|
36
|
+
'MENU',
|
|
37
|
+
'COMMON_AREA',
|
|
38
|
+
'ROOMS',
|
|
39
|
+
'TEAMS',
|
|
40
|
+
'ADDITIONAL',
|
|
41
|
+
];
|
|
22
42
|
|
|
23
43
|
const COMMANDS = [
|
|
24
44
|
'auth:login [--url https://www.poster.ly] [--no-open]',
|
|
25
45
|
'auth:key [--url https://www.poster.ly]',
|
|
26
46
|
'auth:status',
|
|
27
47
|
'auth:logout',
|
|
48
|
+
'doctor [--url https://www.poster.ly] [--no-npm]',
|
|
49
|
+
'version',
|
|
28
50
|
'whoami',
|
|
29
51
|
'accounts:list|disconnect [--workspace-id id]',
|
|
30
52
|
'connect:link [platform] [--workspace-id id] [--include-planned]',
|
|
@@ -35,8 +57,8 @@ const COMMANDS = [
|
|
|
35
57
|
'slots:next',
|
|
36
58
|
'media:upload|signed-upload|upload-from-url',
|
|
37
59
|
'analytics:account|posts',
|
|
38
|
-
'gbp:reviews|review-link|audit|suggest-reply|reply|delete-reply',
|
|
39
|
-
'ai:video-options|video-function|generate-video|video-jobs|video-job',
|
|
60
|
+
'gbp:reviews|review-link|audit|media|add-media|delete-media|suggest-reply|reply|delete-reply',
|
|
61
|
+
'ai:captions|image|video-options|video-function|generate-video|video-jobs|video-job',
|
|
40
62
|
'activity:list',
|
|
41
63
|
'notifications:list',
|
|
42
64
|
'x:quota',
|
|
@@ -63,6 +85,11 @@ async function main() {
|
|
|
63
85
|
if (command === 'auth:key') return saveKey(positional[0], flags);
|
|
64
86
|
if (command === 'auth:status') return authStatus(flags);
|
|
65
87
|
if (command === 'auth:logout') return logout(flags);
|
|
88
|
+
if (command === 'doctor') return doctor(flags);
|
|
89
|
+
if (command === 'version' || command === '--version' || flags.version === true) {
|
|
90
|
+
const pkg = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'));
|
|
91
|
+
return print({ name: CLI_PACKAGE_NAME, version: pkg.version }, flags);
|
|
92
|
+
}
|
|
66
93
|
|
|
67
94
|
const client = await createClient(flags);
|
|
68
95
|
|
|
@@ -165,6 +192,9 @@ async function main() {
|
|
|
165
192
|
group_id: flags.groupId,
|
|
166
193
|
})), flags);
|
|
167
194
|
case 'posts:delete':
|
|
195
|
+
if (!flagEnabled(flags.confirm)) {
|
|
196
|
+
throw new Error('Deleting a post is irreversible. Re-run with --confirm after verifying the post ID.');
|
|
197
|
+
}
|
|
168
198
|
return print(await client.delete(`/posts/${required(positional[0] || flags.id, 'post id')}`), flags);
|
|
169
199
|
case 'posts:delete-group':
|
|
170
200
|
if (!flagEnabled(flags.confirm)) {
|
|
@@ -236,6 +266,34 @@ async function main() {
|
|
|
236
266
|
account_id: flags.accountId || positional[0],
|
|
237
267
|
location_id: flags.locationId,
|
|
238
268
|
})), flags);
|
|
269
|
+
case 'gbp:media':
|
|
270
|
+
return print(await client.get(withQuery('/google-business/media', {
|
|
271
|
+
workspace_id: flags.workspaceId,
|
|
272
|
+
account_id: flags.accountId || positional[0],
|
|
273
|
+
location_id: flags.locationId,
|
|
274
|
+
})), flags);
|
|
275
|
+
case 'gbp:add-media':
|
|
276
|
+
if (!flagEnabled(flags.confirm)) {
|
|
277
|
+
throw new Error('Adding Google Business profile media changes the public listing. Re-run with --confirm after verifying the location, category, and media URL.');
|
|
278
|
+
}
|
|
279
|
+
return print(await client.post('/google-business/media', clean({
|
|
280
|
+
workspace_id: flags.workspaceId,
|
|
281
|
+
account_id: flags.accountId,
|
|
282
|
+
location_id: flags.locationId,
|
|
283
|
+
source_url: required(flags.sourceUrl || positional[0], '--source-url'),
|
|
284
|
+
category: validateGoogleBusinessMediaCategory(required(flags.category || positional[1], '--category')),
|
|
285
|
+
media_format: flags.mediaFormat ? validateGoogleBusinessMediaFormat(flags.mediaFormat) : undefined,
|
|
286
|
+
})), flags);
|
|
287
|
+
case 'gbp:delete-media':
|
|
288
|
+
if (!flagEnabled(flags.confirm)) {
|
|
289
|
+
throw new Error('Deleting Google Business profile media is irreversible. Re-run with --confirm after verifying the media resource name.');
|
|
290
|
+
}
|
|
291
|
+
return print(await client.delete('/google-business/media', clean({
|
|
292
|
+
workspace_id: flags.workspaceId,
|
|
293
|
+
account_id: flags.accountId,
|
|
294
|
+
location_id: flags.locationId,
|
|
295
|
+
media_name: required(flags.mediaName || positional[0], '--media-name'),
|
|
296
|
+
})), flags);
|
|
239
297
|
case 'gbp:suggest-reply':
|
|
240
298
|
return print(await client.post('/google-business/reviews/suggest-reply', clean({
|
|
241
299
|
workspace_id: flags.workspaceId,
|
|
@@ -270,6 +328,11 @@ async function main() {
|
|
|
270
328
|
review_name: required(flags.reviewName || positional[0], '--review-name'),
|
|
271
329
|
})), flags);
|
|
272
330
|
|
|
331
|
+
case 'ai:captions':
|
|
332
|
+
return print(await client.post('/ai/generate-captions', await captionsPayloadFromFlags(flags)), flags);
|
|
333
|
+
case 'ai:image':
|
|
334
|
+
return print(await client.post('/ai/generate-image', await imagePayloadFromFlags(flags, positional)), flags);
|
|
335
|
+
|
|
273
336
|
case 'ai:video-options':
|
|
274
337
|
return print(await client.get('/ai/video-options'), flags);
|
|
275
338
|
case 'ai:video-function':
|
|
@@ -322,6 +385,9 @@ async function main() {
|
|
|
322
385
|
is_active: flags.active === undefined ? undefined : booleanFlag(flags.active),
|
|
323
386
|
})), flags);
|
|
324
387
|
case 'webhooks:delete':
|
|
388
|
+
if (!flagEnabled(flags.confirm)) {
|
|
389
|
+
throw new Error('Deleting a webhook is irreversible. Re-run with --confirm after verifying the webhook ID.');
|
|
390
|
+
}
|
|
325
391
|
return print(await client.delete(`/webhooks/${required(positional[0] || flags.id, 'webhook id')}`), flags);
|
|
326
392
|
case 'webhooks:test':
|
|
327
393
|
return print(await client.post(`/webhooks/${required(positional[0] || flags.id, 'webhook id')}/test`, {}), flags);
|
|
@@ -366,12 +432,11 @@ function parseArgs(args) {
|
|
|
366
432
|
}
|
|
367
433
|
|
|
368
434
|
async function createClient(flags) {
|
|
369
|
-
const
|
|
370
|
-
const apiKey = flags.apiKey || process.env.POSTERLY_API_KEY || config.apiKey;
|
|
371
|
-
const baseUrl = normalizeBaseUrl(flags.url || process.env.POSTERLY_URL || config.baseUrl || DEFAULT_BASE_URL);
|
|
435
|
+
const { apiKey, baseUrl } = await resolveAuthContext(flags);
|
|
372
436
|
if (!apiKey) {
|
|
373
437
|
throw new Error('Missing API key. Run `npx @posterly/cli@latest auth:login`, `posterly auth:login` after global install, run `posterly auth:key` and paste a key at the prompt, or set POSTERLY_API_KEY.');
|
|
374
438
|
}
|
|
439
|
+
validateBaseUrlForKeyUse(baseUrl, flags, 'send an API key to');
|
|
375
440
|
|
|
376
441
|
async function request(method, path, body) {
|
|
377
442
|
const res = await fetch(`${baseUrl}/api/v1${path}`, {
|
|
@@ -404,6 +469,31 @@ async function createClient(flags) {
|
|
|
404
469
|
};
|
|
405
470
|
}
|
|
406
471
|
|
|
472
|
+
async function resolveAuthContext(flags = {}) {
|
|
473
|
+
const config = await readConfig();
|
|
474
|
+
const apiKey = flags.apiKey || process.env.POSTERLY_API_KEY || config.apiKey || '';
|
|
475
|
+
const baseUrl = normalizeBaseUrl(flags.url || process.env.POSTERLY_URL || config.baseUrl || DEFAULT_BASE_URL);
|
|
476
|
+
const authSource = flags.apiKey
|
|
477
|
+
? 'flag'
|
|
478
|
+
: process.env.POSTERLY_API_KEY
|
|
479
|
+
? 'env'
|
|
480
|
+
: config.apiKey
|
|
481
|
+
? 'config'
|
|
482
|
+
: null;
|
|
483
|
+
|
|
484
|
+
return {
|
|
485
|
+
config,
|
|
486
|
+
apiKey,
|
|
487
|
+
baseUrl,
|
|
488
|
+
authSource,
|
|
489
|
+
authType: authSource === 'env'
|
|
490
|
+
? 'env'
|
|
491
|
+
: authSource === 'flag'
|
|
492
|
+
? 'api_key'
|
|
493
|
+
: config.authType || (config.apiKey ? 'api_key' : null),
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
|
|
407
497
|
async function saveKey(key, flags) {
|
|
408
498
|
if (key || flags.apiKey) {
|
|
409
499
|
console.warn('Warning: passing API keys as command-line arguments can expose them through shell history or process listings. Prefer `posterly auth:key` with no argument or POSTERLY_API_KEY.');
|
|
@@ -413,13 +503,14 @@ async function saveKey(key, flags) {
|
|
|
413
503
|
if (!apiKey) {
|
|
414
504
|
throw new Error('Missing API key. Run `posterly auth:key` and paste a key at the prompt, pipe a key on stdin, use `npx @posterly/cli@latest auth:key`, or set POSTERLY_API_KEY.');
|
|
415
505
|
}
|
|
416
|
-
|
|
506
|
+
const baseUrl = normalizeBaseUrl(flags.url || process.env.POSTERLY_URL || DEFAULT_BASE_URL);
|
|
507
|
+
validateBaseUrlForKeyUse(baseUrl, flags, 'store an API key for');
|
|
417
508
|
const config = {
|
|
418
509
|
apiKey,
|
|
419
|
-
baseUrl
|
|
510
|
+
baseUrl,
|
|
420
511
|
updatedAt: new Date().toISOString(),
|
|
421
512
|
};
|
|
422
|
-
await
|
|
513
|
+
await writeConfig(config);
|
|
423
514
|
return print({ saved: true, config_file: CONFIG_FILE, base_url: config.baseUrl }, flags);
|
|
424
515
|
}
|
|
425
516
|
|
|
@@ -479,6 +570,7 @@ async function readApiKeyFromInput() {
|
|
|
479
570
|
|
|
480
571
|
async function authLogin(flags) {
|
|
481
572
|
const baseUrl = normalizeBaseUrl(flags.url || process.env.POSTERLY_URL || DEFAULT_BASE_URL);
|
|
573
|
+
validateBaseUrlForKeyUse(baseUrl, flags, 'start OAuth login against');
|
|
482
574
|
const redirectUri = `http://127.0.0.1:${OAUTH_CALLBACK_PORT}${OAUTH_CALLBACK_PATH}`;
|
|
483
575
|
const state = randomBytes(18).toString('base64url');
|
|
484
576
|
const codeVerifier = randomBytes(48).toString('base64url');
|
|
@@ -509,7 +601,6 @@ async function authLogin(flags) {
|
|
|
509
601
|
}
|
|
510
602
|
|
|
511
603
|
const token = await loginPromise;
|
|
512
|
-
await mkdir(CONFIG_DIR, { recursive: true });
|
|
513
604
|
const config = {
|
|
514
605
|
apiKey: token.access_token,
|
|
515
606
|
baseUrl,
|
|
@@ -518,7 +609,7 @@ async function authLogin(flags) {
|
|
|
518
609
|
expiresAt: token.expires_in ? new Date(Date.now() + Number(token.expires_in) * 1000).toISOString() : null,
|
|
519
610
|
updatedAt: new Date().toISOString(),
|
|
520
611
|
};
|
|
521
|
-
await
|
|
612
|
+
await writeConfig(config);
|
|
522
613
|
|
|
523
614
|
return print({
|
|
524
615
|
authenticated: true,
|
|
@@ -639,16 +730,18 @@ function errorHtml(message) {
|
|
|
639
730
|
}
|
|
640
731
|
|
|
641
732
|
async function authStatus(flags) {
|
|
642
|
-
const
|
|
643
|
-
const
|
|
733
|
+
const context = await resolveAuthContext(flags);
|
|
734
|
+
const baseUrlCheck = inspectBaseUrl(context.baseUrl);
|
|
644
735
|
return print({
|
|
645
|
-
authenticated: Boolean(
|
|
646
|
-
source:
|
|
647
|
-
base_url:
|
|
736
|
+
authenticated: Boolean(context.apiKey),
|
|
737
|
+
source: context.authSource,
|
|
738
|
+
base_url: context.baseUrl,
|
|
648
739
|
config_file: CONFIG_FILE,
|
|
649
|
-
auth_type:
|
|
650
|
-
scopes: config.scopes,
|
|
651
|
-
expires_at: config.expiresAt,
|
|
740
|
+
auth_type: context.authType,
|
|
741
|
+
scopes: context.config.scopes,
|
|
742
|
+
expires_at: context.config.expiresAt,
|
|
743
|
+
base_url_check: summarizeBaseUrlCheck(baseUrlCheck),
|
|
744
|
+
next_step: authStatusNextStep({ hasApiKey: Boolean(context.apiKey), baseUrlCheck }),
|
|
652
745
|
}, flags);
|
|
653
746
|
}
|
|
654
747
|
|
|
@@ -657,6 +750,58 @@ async function logout(flags) {
|
|
|
657
750
|
return print({ logged_out: true, config_file: CONFIG_FILE }, flags);
|
|
658
751
|
}
|
|
659
752
|
|
|
753
|
+
async function doctor(flags) {
|
|
754
|
+
const context = await resolveAuthContext(flags);
|
|
755
|
+
const packageInfo = await readPackageInfo();
|
|
756
|
+
const baseUrlCheck = inspectBaseUrl(context.baseUrl);
|
|
757
|
+
const checks = [
|
|
758
|
+
nodeVersionCheck(),
|
|
759
|
+
{
|
|
760
|
+
name: 'base_url',
|
|
761
|
+
ok: baseUrlCheck.valid && (baseUrlCheck.secure || flagEnabled(flags.allowInsecureUrl)),
|
|
762
|
+
severity: baseUrlSeverity(baseUrlCheck, flags),
|
|
763
|
+
value: context.baseUrl,
|
|
764
|
+
...summarizeBaseUrlCheck(baseUrlCheck),
|
|
765
|
+
},
|
|
766
|
+
{
|
|
767
|
+
name: 'auth_config',
|
|
768
|
+
ok: Boolean(context.apiKey),
|
|
769
|
+
severity: context.apiKey ? 'info' : 'error',
|
|
770
|
+
source: context.authSource,
|
|
771
|
+
config_file: CONFIG_FILE,
|
|
772
|
+
message: context.apiKey
|
|
773
|
+
? `API key found via ${context.authSource}.`
|
|
774
|
+
: 'No API key found in POSTERLY_API_KEY, --api-key, or local config.',
|
|
775
|
+
},
|
|
776
|
+
];
|
|
777
|
+
|
|
778
|
+
const latest = flagEnabled(flags.noNpm)
|
|
779
|
+
? { skipped: true, reason: '--no-npm' }
|
|
780
|
+
: await fetchLatestCliVersion();
|
|
781
|
+
checks.push(npmVersionCheck(packageInfo.version, latest));
|
|
782
|
+
|
|
783
|
+
const canProbeApi = context.apiKey && baseUrlCheck.valid && (baseUrlCheck.secure || flagEnabled(flags.allowInsecureUrl));
|
|
784
|
+
const authProbe = canProbeApi
|
|
785
|
+
? await probeWhoami(context.baseUrl, context.apiKey)
|
|
786
|
+
: null;
|
|
787
|
+
checks.push(apiAuthCheck(authProbe, { skippedBecause: context.apiKey ? 'base_url' : 'auth_config' }));
|
|
788
|
+
|
|
789
|
+
const ok = checks.every((check) => check.severity !== 'error');
|
|
790
|
+
if (!ok) {
|
|
791
|
+
process.exitCode = 1;
|
|
792
|
+
}
|
|
793
|
+
return print({
|
|
794
|
+
ok,
|
|
795
|
+
package: packageInfo,
|
|
796
|
+
base_url: context.baseUrl,
|
|
797
|
+
checks,
|
|
798
|
+
user: authProbe?.ok ? authProbe.user : undefined,
|
|
799
|
+
default_workspace: authProbe?.ok ? authProbe.default_workspace : undefined,
|
|
800
|
+
scopes: authProbe?.ok ? authProbe.scopes : undefined,
|
|
801
|
+
next_step: doctorNextStep({ checks, latest, authProbe }),
|
|
802
|
+
}, flags);
|
|
803
|
+
}
|
|
804
|
+
|
|
660
805
|
async function readConfig() {
|
|
661
806
|
try {
|
|
662
807
|
return JSON.parse(await readFile(CONFIG_FILE, 'utf8'));
|
|
@@ -665,6 +810,33 @@ async function readConfig() {
|
|
|
665
810
|
}
|
|
666
811
|
}
|
|
667
812
|
|
|
813
|
+
async function ensureConfigDir() {
|
|
814
|
+
await mkdir(CONFIG_DIR, { recursive: true, mode: 0o700 });
|
|
815
|
+
await chmodIfPresent(CONFIG_DIR, 0o700);
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
async function writeConfig(config) {
|
|
819
|
+
await ensureConfigDir();
|
|
820
|
+
const tempFile = path.join(CONFIG_DIR, `.config.${process.pid}.${randomBytes(6).toString('hex')}.tmp`);
|
|
821
|
+
try {
|
|
822
|
+
await writeFile(tempFile, `${JSON.stringify(config, null, 2)}\n`, { encoding: 'utf8', mode: 0o600 });
|
|
823
|
+
await chmodIfPresent(tempFile, 0o600);
|
|
824
|
+
await rename(tempFile, CONFIG_FILE);
|
|
825
|
+
await chmodIfPresent(CONFIG_FILE, 0o600);
|
|
826
|
+
} catch (error) {
|
|
827
|
+
await rm(tempFile, { force: true }).catch(() => {});
|
|
828
|
+
throw error;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
async function chmodIfPresent(filePath, mode) {
|
|
833
|
+
try {
|
|
834
|
+
await chmod(filePath, mode);
|
|
835
|
+
} catch {
|
|
836
|
+
// Best-effort hardening for filesystems that do not fully support POSIX modes.
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
|
|
668
840
|
async function postPayloadFromFlags(flags) {
|
|
669
841
|
if (flags.file) return validatePostPayload(await readJson(required(flags.file, '--file')));
|
|
670
842
|
return clean({
|
|
@@ -713,6 +885,36 @@ async function mediaUploadPayload(flags, positional) {
|
|
|
713
885
|
};
|
|
714
886
|
}
|
|
715
887
|
|
|
888
|
+
async function captionsPayloadFromFlags(flags) {
|
|
889
|
+
if (flags.file) return readJson(required(flags.file, '--file'));
|
|
890
|
+
return clean({
|
|
891
|
+
platforms: csv(required(flags.platforms || flags.platform, '--platforms')),
|
|
892
|
+
brief: flags.brief,
|
|
893
|
+
tone: flags.tone,
|
|
894
|
+
allow_emojis: flags.allowEmojis === undefined ? undefined : booleanFlag(flags.allowEmojis),
|
|
895
|
+
hashtag_strategy: flags.hashtagStrategy,
|
|
896
|
+
count: flags.count ? Number(flags.count) : undefined,
|
|
897
|
+
mode: flags.mode,
|
|
898
|
+
source_caption: flags.sourceCaption,
|
|
899
|
+
source_platform: flags.sourcePlatform,
|
|
900
|
+
preserve_links: flags.preserveLinks === undefined ? undefined : booleanFlag(flags.preserveLinks),
|
|
901
|
+
preserve_mentions: flags.preserveMentions === undefined ? undefined : booleanFlag(flags.preserveMentions),
|
|
902
|
+
preserve_call_to_action: flags.preserveCallToAction === undefined ? undefined : booleanFlag(flags.preserveCallToAction),
|
|
903
|
+
account_id: flags.accountId,
|
|
904
|
+
workspace_id: flags.workspaceId,
|
|
905
|
+
manual_brand_voice: jsonFlag(flags.manualBrandVoice),
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
async function imagePayloadFromFlags(flags, positional) {
|
|
910
|
+
if (flags.file) return readJson(required(flags.file, '--file'));
|
|
911
|
+
return clean({
|
|
912
|
+
prompt: required(flags.prompt || positional[0], '--prompt'),
|
|
913
|
+
aspect_ratio: flags.aspectRatio,
|
|
914
|
+
style: flags.style,
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
|
|
716
918
|
async function videoPayloadFromFlags(flags) {
|
|
717
919
|
if (flags.file) return readJson(required(flags.file, '--file'));
|
|
718
920
|
return clean({
|
|
@@ -866,6 +1068,22 @@ function validatePostStatus(value) {
|
|
|
866
1068
|
return status;
|
|
867
1069
|
}
|
|
868
1070
|
|
|
1071
|
+
function validateGoogleBusinessMediaCategory(value) {
|
|
1072
|
+
const category = String(value || '').trim().toUpperCase();
|
|
1073
|
+
if (!GOOGLE_BUSINESS_MEDIA_CATEGORIES.includes(category)) {
|
|
1074
|
+
throw new Error(`Unknown Google Business media category "${value}". Allowed categories: ${formatList(GOOGLE_BUSINESS_MEDIA_CATEGORIES)}.`);
|
|
1075
|
+
}
|
|
1076
|
+
return category;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
function validateGoogleBusinessMediaFormat(value) {
|
|
1080
|
+
const format = String(value || '').trim().toUpperCase();
|
|
1081
|
+
if (!['PHOTO', 'VIDEO'].includes(format)) {
|
|
1082
|
+
throw new Error(`Unknown Google Business media format "${value}". Allowed formats: PHOTO, VIDEO.`);
|
|
1083
|
+
}
|
|
1084
|
+
return format;
|
|
1085
|
+
}
|
|
1086
|
+
|
|
869
1087
|
function normalizeManifestKey(value) {
|
|
870
1088
|
return String(value || '').trim().toLowerCase().replace(/[\s-]+/g, '_');
|
|
871
1089
|
}
|
|
@@ -885,7 +1103,338 @@ function flagEnabled(value) {
|
|
|
885
1103
|
}
|
|
886
1104
|
|
|
887
1105
|
function normalizeBaseUrl(value) {
|
|
888
|
-
|
|
1106
|
+
const raw = String(value || DEFAULT_BASE_URL).trim();
|
|
1107
|
+
try {
|
|
1108
|
+
const url = new URL(raw);
|
|
1109
|
+
url.pathname = url.pathname.replace(/\/api\/v1\/?$/, '').replace(/\/+$/, '') || '/';
|
|
1110
|
+
url.search = '';
|
|
1111
|
+
url.hash = '';
|
|
1112
|
+
return url.toString().replace(/\/$/, '');
|
|
1113
|
+
} catch {
|
|
1114
|
+
return raw.replace(/\/api\/v1\/?$/, '').replace(/\/$/, '');
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
function inspectBaseUrl(baseUrl) {
|
|
1119
|
+
try {
|
|
1120
|
+
const url = new URL(baseUrl);
|
|
1121
|
+
const hostname = url.hostname.toLowerCase().replace(/^\[|\]$/g, '');
|
|
1122
|
+
const local = isLocalHost(hostname);
|
|
1123
|
+
const trustedPosterlyHost = TRUSTED_POSTERLY_HOSTS.has(hostname);
|
|
1124
|
+
const secure = url.protocol === 'https:' || (url.protocol === 'http:' && local);
|
|
1125
|
+
const warnings = [];
|
|
1126
|
+
if (!trustedPosterlyHost) {
|
|
1127
|
+
warnings.push(local ? 'local_development_host' : 'custom_host');
|
|
1128
|
+
}
|
|
1129
|
+
if (!secure) {
|
|
1130
|
+
warnings.push('insecure_non_local_url');
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
return {
|
|
1134
|
+
valid: true,
|
|
1135
|
+
secure,
|
|
1136
|
+
protocol: url.protocol.replace(/:$/, ''),
|
|
1137
|
+
host: url.host,
|
|
1138
|
+
trusted_posterly_host: trustedPosterlyHost,
|
|
1139
|
+
local_development_host: local,
|
|
1140
|
+
warnings,
|
|
1141
|
+
message: baseUrlMessage({ secure, trustedPosterlyHost, local }),
|
|
1142
|
+
};
|
|
1143
|
+
} catch {
|
|
1144
|
+
return {
|
|
1145
|
+
valid: false,
|
|
1146
|
+
secure: false,
|
|
1147
|
+
warnings: ['invalid_url'],
|
|
1148
|
+
message: 'Base URL must include a scheme and host, for example https://www.poster.ly.',
|
|
1149
|
+
};
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
function summarizeBaseUrlCheck(check) {
|
|
1154
|
+
return clean({
|
|
1155
|
+
valid: check.valid,
|
|
1156
|
+
secure: check.secure,
|
|
1157
|
+
protocol: check.protocol,
|
|
1158
|
+
host: check.host,
|
|
1159
|
+
trusted_posterly_host: check.trusted_posterly_host,
|
|
1160
|
+
local_development_host: check.local_development_host,
|
|
1161
|
+
warnings: check.warnings,
|
|
1162
|
+
message: check.message,
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
function baseUrlSeverity(check, flags) {
|
|
1167
|
+
if (!check.valid) return 'error';
|
|
1168
|
+
if (!check.secure && !flagEnabled(flags.allowInsecureUrl)) return 'error';
|
|
1169
|
+
if (!check.trusted_posterly_host) return 'warning';
|
|
1170
|
+
return 'info';
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
function validateBaseUrlForKeyUse(baseUrl, flags, action) {
|
|
1174
|
+
const check = inspectBaseUrl(baseUrl);
|
|
1175
|
+
if (!check.valid) {
|
|
1176
|
+
throw new Error(`${check.message} Received: ${baseUrl}`);
|
|
1177
|
+
}
|
|
1178
|
+
if (!check.secure && !flagEnabled(flags.allowInsecureUrl)) {
|
|
1179
|
+
throw new Error(`Refusing to ${action} ${baseUrl}. Use https, http://localhost for local development, or re-run with --allow-insecure-url only for a trusted private development endpoint.`);
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
function baseUrlMessage({ secure, trustedPosterlyHost, local }) {
|
|
1184
|
+
if (!secure) {
|
|
1185
|
+
return 'Non-local HTTP URLs are blocked for API-key requests.';
|
|
1186
|
+
}
|
|
1187
|
+
if (local) {
|
|
1188
|
+
return 'Local development URL accepted.';
|
|
1189
|
+
}
|
|
1190
|
+
if (!trustedPosterlyHost) {
|
|
1191
|
+
return 'Custom HTTPS host accepted; verify it is your intended posterly deployment before sending API keys.';
|
|
1192
|
+
}
|
|
1193
|
+
return 'Official posterly API host.';
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
function isLocalHost(hostname) {
|
|
1197
|
+
return hostname === 'localhost'
|
|
1198
|
+
|| hostname.endsWith('.localhost')
|
|
1199
|
+
|| hostname === '::1'
|
|
1200
|
+
|| hostname === '0.0.0.0'
|
|
1201
|
+
|| hostname === '127.0.0.1'
|
|
1202
|
+
|| hostname.startsWith('127.');
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
let packageInfoCache;
|
|
1206
|
+
|
|
1207
|
+
async function readPackageInfo() {
|
|
1208
|
+
if (packageInfoCache) return packageInfoCache;
|
|
1209
|
+
try {
|
|
1210
|
+
const pkg = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'));
|
|
1211
|
+
packageInfoCache = {
|
|
1212
|
+
name: typeof pkg.name === 'string' ? pkg.name : CLI_PACKAGE_NAME,
|
|
1213
|
+
version: typeof pkg.version === 'string' ? pkg.version : 'unknown',
|
|
1214
|
+
};
|
|
1215
|
+
} catch {
|
|
1216
|
+
packageInfoCache = { name: CLI_PACKAGE_NAME, version: 'unknown' };
|
|
1217
|
+
}
|
|
1218
|
+
return packageInfoCache;
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
function nodeVersionCheck() {
|
|
1222
|
+
const major = Number.parseInt(process.versions.node.split('.')[0], 10);
|
|
1223
|
+
const ok = Number.isFinite(major) && major >= REQUIRED_NODE_MAJOR;
|
|
1224
|
+
return {
|
|
1225
|
+
name: 'node',
|
|
1226
|
+
ok,
|
|
1227
|
+
severity: ok ? 'info' : 'error',
|
|
1228
|
+
version: process.version,
|
|
1229
|
+
required: `>=${REQUIRED_NODE_MAJOR}`,
|
|
1230
|
+
message: ok
|
|
1231
|
+
? 'Node version is supported.'
|
|
1232
|
+
: `Node ${REQUIRED_NODE_MAJOR}+ is required.`,
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
function npmVersionCheck(currentVersion, latest) {
|
|
1237
|
+
if (latest.skipped) {
|
|
1238
|
+
return {
|
|
1239
|
+
name: 'npm_latest',
|
|
1240
|
+
ok: true,
|
|
1241
|
+
severity: 'info',
|
|
1242
|
+
skipped: true,
|
|
1243
|
+
message: `Skipped npm latest check (${latest.reason}).`,
|
|
1244
|
+
};
|
|
1245
|
+
}
|
|
1246
|
+
if (latest.error) {
|
|
1247
|
+
return {
|
|
1248
|
+
name: 'npm_latest',
|
|
1249
|
+
ok: false,
|
|
1250
|
+
severity: 'warning',
|
|
1251
|
+
current_version: currentVersion,
|
|
1252
|
+
message: latest.error,
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
const comparison = compareSemver(currentVersion, latest.version);
|
|
1257
|
+
return {
|
|
1258
|
+
name: 'npm_latest',
|
|
1259
|
+
ok: comparison >= 0,
|
|
1260
|
+
severity: comparison < 0 ? 'warning' : 'info',
|
|
1261
|
+
current_version: currentVersion,
|
|
1262
|
+
latest_version: latest.version,
|
|
1263
|
+
update_status: comparison < 0
|
|
1264
|
+
? 'update_available'
|
|
1265
|
+
: comparison > 0
|
|
1266
|
+
? 'newer_than_npm'
|
|
1267
|
+
: 'current',
|
|
1268
|
+
message: comparison < 0
|
|
1269
|
+
? `Update available: ${latest.version}.`
|
|
1270
|
+
: comparison > 0
|
|
1271
|
+
? 'Local package is newer than npm latest; publish may still be pending.'
|
|
1272
|
+
: 'CLI package is current.',
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
function apiAuthCheck(probe, { skippedBecause }) {
|
|
1277
|
+
if (!probe) {
|
|
1278
|
+
return {
|
|
1279
|
+
name: 'api_auth',
|
|
1280
|
+
ok: false,
|
|
1281
|
+
severity: 'error',
|
|
1282
|
+
skipped: true,
|
|
1283
|
+
skipped_because: skippedBecause,
|
|
1284
|
+
message: skippedBecause === 'auth_config'
|
|
1285
|
+
? 'Skipped because no API key is configured.'
|
|
1286
|
+
: 'Skipped because the base URL is not safe for API-key requests.',
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
if (probe.ok) {
|
|
1291
|
+
return {
|
|
1292
|
+
name: 'api_auth',
|
|
1293
|
+
ok: true,
|
|
1294
|
+
severity: 'info',
|
|
1295
|
+
status: probe.status,
|
|
1296
|
+
duration_ms: probe.duration_ms,
|
|
1297
|
+
message: 'API key validated against /api/v1/whoami.',
|
|
1298
|
+
};
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
return {
|
|
1302
|
+
name: 'api_auth',
|
|
1303
|
+
ok: false,
|
|
1304
|
+
severity: 'error',
|
|
1305
|
+
status: probe.status,
|
|
1306
|
+
duration_ms: probe.duration_ms,
|
|
1307
|
+
message: probe.error || 'API key validation failed.',
|
|
1308
|
+
};
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
async function probeWhoami(baseUrl, apiKey, timeoutMs = REQUEST_TIMEOUT_MS) {
|
|
1312
|
+
const startedAt = Date.now();
|
|
1313
|
+
const controller = new AbortController();
|
|
1314
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
1315
|
+
|
|
1316
|
+
try {
|
|
1317
|
+
const res = await fetch(`${baseUrl}/api/v1/whoami`, {
|
|
1318
|
+
method: 'GET',
|
|
1319
|
+
headers: {
|
|
1320
|
+
Authorization: `Bearer ${apiKey}`,
|
|
1321
|
+
Accept: 'application/json',
|
|
1322
|
+
'X-Posterly-Source': 'cli_doctor',
|
|
1323
|
+
},
|
|
1324
|
+
signal: controller.signal,
|
|
1325
|
+
});
|
|
1326
|
+
const text = await res.text();
|
|
1327
|
+
const data = text ? safeJson(text) : {};
|
|
1328
|
+
if (!res.ok) {
|
|
1329
|
+
return {
|
|
1330
|
+
ok: false,
|
|
1331
|
+
status: res.status,
|
|
1332
|
+
duration_ms: Date.now() - startedAt,
|
|
1333
|
+
error: formatResponseError(data, text, res.statusText),
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
return {
|
|
1337
|
+
ok: true,
|
|
1338
|
+
status: res.status,
|
|
1339
|
+
duration_ms: Date.now() - startedAt,
|
|
1340
|
+
user: data.user,
|
|
1341
|
+
default_workspace: data.default_workspace,
|
|
1342
|
+
scopes: Array.isArray(data.api_key?.scopes) ? data.api_key.scopes : undefined,
|
|
1343
|
+
};
|
|
1344
|
+
} catch (error) {
|
|
1345
|
+
return {
|
|
1346
|
+
ok: false,
|
|
1347
|
+
duration_ms: Date.now() - startedAt,
|
|
1348
|
+
error: error?.name === 'AbortError' ? `timed out after ${timeoutMs}ms` : error?.message || String(error),
|
|
1349
|
+
};
|
|
1350
|
+
} finally {
|
|
1351
|
+
clearTimeout(timeout);
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
async function fetchLatestCliVersion() {
|
|
1356
|
+
const controller = new AbortController();
|
|
1357
|
+
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
1358
|
+
|
|
1359
|
+
try {
|
|
1360
|
+
const res = await fetch(CLI_NPM_LATEST_URL, {
|
|
1361
|
+
headers: { Accept: 'application/json' },
|
|
1362
|
+
signal: controller.signal,
|
|
1363
|
+
});
|
|
1364
|
+
if (!res.ok) {
|
|
1365
|
+
return { error: `npm registry returned HTTP ${res.status}` };
|
|
1366
|
+
}
|
|
1367
|
+
const data = await res.json();
|
|
1368
|
+
return typeof data.version === 'string'
|
|
1369
|
+
? { version: data.version }
|
|
1370
|
+
: { error: 'npm registry response did not include a version' };
|
|
1371
|
+
} catch (error) {
|
|
1372
|
+
const reason = error?.name === 'AbortError' ? 'timed out' : error?.message || String(error);
|
|
1373
|
+
return { error: `could not check npm latest: ${reason}` };
|
|
1374
|
+
} finally {
|
|
1375
|
+
clearTimeout(timeout);
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
function authStatusNextStep({ hasApiKey, baseUrlCheck }) {
|
|
1380
|
+
if (!baseUrlCheck.valid) {
|
|
1381
|
+
return 'Fix POSTERLY_URL or --url so it includes a scheme and host.';
|
|
1382
|
+
}
|
|
1383
|
+
if (!baseUrlCheck.secure) {
|
|
1384
|
+
return 'Use an https posterly URL, or http://localhost for local development.';
|
|
1385
|
+
}
|
|
1386
|
+
if (!hasApiKey) {
|
|
1387
|
+
return 'Run `posterly auth:login`, `posterly auth:key`, or set POSTERLY_API_KEY.';
|
|
1388
|
+
}
|
|
1389
|
+
return 'Run `posterly doctor --pretty` to validate the API key against /api/v1/whoami.';
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
function doctorNextStep({ checks, latest, authProbe }) {
|
|
1393
|
+
const byName = Object.fromEntries(checks.map((check) => [check.name, check]));
|
|
1394
|
+
if (byName.node?.severity === 'error') {
|
|
1395
|
+
return 'Install Node 20 or newer, then run `posterly doctor --pretty` again.';
|
|
1396
|
+
}
|
|
1397
|
+
if (byName.base_url?.severity === 'error') {
|
|
1398
|
+
return 'Fix POSTERLY_URL or --url before sending an API key.';
|
|
1399
|
+
}
|
|
1400
|
+
if (byName.auth_config?.severity === 'error') {
|
|
1401
|
+
return 'Run `posterly auth:login`, `posterly auth:key`, or set POSTERLY_API_KEY.';
|
|
1402
|
+
}
|
|
1403
|
+
if (byName.api_auth?.severity === 'error') {
|
|
1404
|
+
return 'Check the API key and base URL, then run `posterly whoami --pretty`.';
|
|
1405
|
+
}
|
|
1406
|
+
if (latest.version && compareSemver((byName.npm_latest?.current_version || '0.0.0'), latest.version) < 0) {
|
|
1407
|
+
return 'Update with `npm i -g @posterly/cli@latest`, or keep using `npx @posterly/cli@latest`.';
|
|
1408
|
+
}
|
|
1409
|
+
if (authProbe?.ok) {
|
|
1410
|
+
return 'CLI is ready. Try `posterly accounts:list --pretty` or `posterly platforms:list --pretty`.';
|
|
1411
|
+
}
|
|
1412
|
+
return 'Run `posterly whoami --pretty` after configuring auth.';
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
function formatResponseError(data, fallback, statusText) {
|
|
1416
|
+
if (data && typeof data === 'object') {
|
|
1417
|
+
return data.error || data.message || data.code || statusText || 'API request failed';
|
|
1418
|
+
}
|
|
1419
|
+
return fallback || statusText || 'API request failed';
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
function compareSemver(a, b) {
|
|
1423
|
+
const left = semverParts(a);
|
|
1424
|
+
const right = semverParts(b);
|
|
1425
|
+
for (let i = 0; i < 3; i += 1) {
|
|
1426
|
+
if (left[i] !== right[i]) return left[i] > right[i] ? 1 : -1;
|
|
1427
|
+
}
|
|
1428
|
+
return 0;
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
function semverParts(value) {
|
|
1432
|
+
const parts = String(value || '').split(/[.-]/).slice(0, 3).map((part) => Number.parseInt(part, 10));
|
|
1433
|
+
return [
|
|
1434
|
+
Number.isFinite(parts[0]) ? parts[0] : 0,
|
|
1435
|
+
Number.isFinite(parts[1]) ? parts[1] : 0,
|
|
1436
|
+
Number.isFinite(parts[2]) ? parts[2] : 0,
|
|
1437
|
+
];
|
|
889
1438
|
}
|
|
890
1439
|
|
|
891
1440
|
function safeJson(text) {
|
|
@@ -12,16 +12,17 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
12
12
|
"threads",
|
|
13
13
|
"google_business",
|
|
14
14
|
"telegram",
|
|
15
|
-
"bluesky"
|
|
15
|
+
"bluesky",
|
|
16
|
+
"discord",
|
|
17
|
+
"mastodon",
|
|
18
|
+
"devto",
|
|
19
|
+
"hashnode",
|
|
20
|
+
"wordpress",
|
|
21
|
+
"lemmy"
|
|
16
22
|
],
|
|
17
23
|
"plannedPlatformIds": [
|
|
18
24
|
"reddit",
|
|
19
|
-
"wordpress",
|
|
20
|
-
"mastodon",
|
|
21
25
|
"medium",
|
|
22
|
-
"devto",
|
|
23
|
-
"hashnode",
|
|
24
|
-
"discord",
|
|
25
26
|
"slack",
|
|
26
27
|
"skool",
|
|
27
28
|
"whop"
|
|
@@ -38,32 +39,39 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
38
39
|
"google_business",
|
|
39
40
|
"telegram",
|
|
40
41
|
"bluesky",
|
|
41
|
-
"
|
|
42
|
-
"wordpress",
|
|
42
|
+
"discord",
|
|
43
43
|
"mastodon",
|
|
44
|
-
"medium",
|
|
45
44
|
"devto",
|
|
46
45
|
"hashnode",
|
|
47
|
-
"
|
|
46
|
+
"wordpress",
|
|
47
|
+
"lemmy",
|
|
48
|
+
"reddit",
|
|
49
|
+
"medium",
|
|
48
50
|
"slack",
|
|
49
51
|
"skool",
|
|
50
52
|
"whop"
|
|
51
53
|
],
|
|
52
54
|
"supportedPlatformInputs": [
|
|
53
55
|
"bluesky",
|
|
56
|
+
"devto",
|
|
57
|
+
"discord",
|
|
54
58
|
"facebook",
|
|
55
59
|
"gmb",
|
|
56
60
|
"google-business",
|
|
57
61
|
"google_business",
|
|
58
62
|
"google_business_profile",
|
|
63
|
+
"hashnode",
|
|
59
64
|
"instagram",
|
|
60
65
|
"instagram-standalone",
|
|
66
|
+
"lemmy",
|
|
61
67
|
"linkedin",
|
|
68
|
+
"mastodon",
|
|
62
69
|
"pinterest",
|
|
63
70
|
"telegram",
|
|
64
71
|
"threads",
|
|
65
72
|
"tiktok",
|
|
66
73
|
"twitter",
|
|
74
|
+
"wordpress",
|
|
67
75
|
"x",
|
|
68
76
|
"youtube"
|
|
69
77
|
],
|
|
@@ -79,6 +87,7 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
79
87
|
"hashnode",
|
|
80
88
|
"instagram",
|
|
81
89
|
"instagram-standalone",
|
|
90
|
+
"lemmy",
|
|
82
91
|
"linkedin",
|
|
83
92
|
"mastodon",
|
|
84
93
|
"medium",
|
|
@@ -106,6 +115,7 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
106
115
|
"hashnode": "hashnode",
|
|
107
116
|
"instagram": "instagram",
|
|
108
117
|
"instagram_standalone": "instagram",
|
|
118
|
+
"lemmy": "lemmy",
|
|
109
119
|
"linkedin": "linkedin",
|
|
110
120
|
"mastodon": "mastodon",
|
|
111
121
|
"medium": "medium",
|
|
@@ -126,8 +136,7 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
126
136
|
"linkedin.recent_mentions",
|
|
127
137
|
"pinterest.boards",
|
|
128
138
|
"tiktok.creator_info",
|
|
129
|
-
"x.quota"
|
|
130
|
-
"youtube.playlists"
|
|
139
|
+
"x.quota"
|
|
131
140
|
],
|
|
132
141
|
"analyticsPlatformIds": [
|
|
133
142
|
"instagram",
|
|
@@ -135,6 +144,7 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
135
144
|
"linkedin",
|
|
136
145
|
"youtube",
|
|
137
146
|
"pinterest",
|
|
147
|
+
"threads",
|
|
138
148
|
"google_business"
|
|
139
149
|
],
|
|
140
150
|
"connectTargetIds": [
|
|
@@ -151,13 +161,14 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
151
161
|
"twitter",
|
|
152
162
|
"telegram",
|
|
153
163
|
"bluesky",
|
|
154
|
-
"
|
|
155
|
-
"wordpress",
|
|
164
|
+
"discord",
|
|
156
165
|
"mastodon",
|
|
157
|
-
"medium",
|
|
158
166
|
"devto",
|
|
159
167
|
"hashnode",
|
|
160
|
-
"
|
|
168
|
+
"wordpress",
|
|
169
|
+
"lemmy",
|
|
170
|
+
"reddit",
|
|
171
|
+
"medium",
|
|
161
172
|
"slack",
|
|
162
173
|
"skool",
|
|
163
174
|
"whop"
|
|
@@ -177,6 +188,7 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
177
188
|
"instagram",
|
|
178
189
|
"instagram-standalone",
|
|
179
190
|
"instagram_direct",
|
|
191
|
+
"lemmy",
|
|
180
192
|
"linkedin",
|
|
181
193
|
"linkedin-company",
|
|
182
194
|
"linkedin-page",
|
|
@@ -215,6 +227,7 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
215
227
|
"instagram": "instagram",
|
|
216
228
|
"instagram_direct": "instagram",
|
|
217
229
|
"instagram_standalone": "instagram",
|
|
230
|
+
"lemmy": "lemmy",
|
|
218
231
|
"linkedin": "linkedin",
|
|
219
232
|
"linkedin_company": "linkedin_page",
|
|
220
233
|
"linkedin_page": "linkedin_page",
|
|
@@ -279,7 +292,8 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
279
292
|
"aliases": [],
|
|
280
293
|
"postTypes": [
|
|
281
294
|
"video",
|
|
282
|
-
"image"
|
|
295
|
+
"image",
|
|
296
|
+
"carousel"
|
|
283
297
|
],
|
|
284
298
|
"analyticsSupported": false,
|
|
285
299
|
"helpers": [
|
|
@@ -331,9 +345,7 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
331
345
|
"video"
|
|
332
346
|
],
|
|
333
347
|
"analyticsSupported": true,
|
|
334
|
-
"helpers": [
|
|
335
|
-
"youtube.playlists"
|
|
336
|
-
]
|
|
348
|
+
"helpers": []
|
|
337
349
|
},
|
|
338
350
|
{
|
|
339
351
|
"id": "pinterest",
|
|
@@ -362,7 +374,7 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
362
374
|
"carousel",
|
|
363
375
|
"threads_thread"
|
|
364
376
|
],
|
|
365
|
-
"analyticsSupported":
|
|
377
|
+
"analyticsSupported": true,
|
|
366
378
|
"helpers": []
|
|
367
379
|
},
|
|
368
380
|
{
|
|
@@ -410,53 +422,84 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
410
422
|
"helpers": []
|
|
411
423
|
},
|
|
412
424
|
{
|
|
413
|
-
"id": "
|
|
414
|
-
"label": "
|
|
415
|
-
"status": "
|
|
425
|
+
"id": "discord",
|
|
426
|
+
"label": "Discord",
|
|
427
|
+
"status": "supported",
|
|
416
428
|
"aliases": [],
|
|
417
|
-
"postTypes": [
|
|
429
|
+
"postTypes": [
|
|
430
|
+
"text",
|
|
431
|
+
"image",
|
|
432
|
+
"video",
|
|
433
|
+
"carousel"
|
|
434
|
+
],
|
|
418
435
|
"analyticsSupported": false,
|
|
419
436
|
"helpers": []
|
|
420
437
|
},
|
|
421
438
|
{
|
|
422
|
-
"id": "
|
|
423
|
-
"label": "
|
|
424
|
-
"status": "
|
|
439
|
+
"id": "mastodon",
|
|
440
|
+
"label": "Mastodon",
|
|
441
|
+
"status": "supported",
|
|
425
442
|
"aliases": [],
|
|
426
|
-
"postTypes": [
|
|
443
|
+
"postTypes": [
|
|
444
|
+
"text",
|
|
445
|
+
"image",
|
|
446
|
+
"video",
|
|
447
|
+
"carousel"
|
|
448
|
+
],
|
|
427
449
|
"analyticsSupported": false,
|
|
428
450
|
"helpers": []
|
|
429
451
|
},
|
|
430
452
|
{
|
|
431
|
-
"id": "
|
|
432
|
-
"label": "
|
|
433
|
-
"status": "
|
|
453
|
+
"id": "devto",
|
|
454
|
+
"label": "Dev.to",
|
|
455
|
+
"status": "supported",
|
|
434
456
|
"aliases": [],
|
|
435
|
-
"postTypes": [
|
|
457
|
+
"postTypes": [
|
|
458
|
+
"text",
|
|
459
|
+
"image"
|
|
460
|
+
],
|
|
436
461
|
"analyticsSupported": false,
|
|
437
462
|
"helpers": []
|
|
438
463
|
},
|
|
439
464
|
{
|
|
440
|
-
"id": "
|
|
441
|
-
"label": "
|
|
442
|
-
"status": "
|
|
465
|
+
"id": "hashnode",
|
|
466
|
+
"label": "Hashnode",
|
|
467
|
+
"status": "supported",
|
|
443
468
|
"aliases": [],
|
|
444
|
-
"postTypes": [
|
|
469
|
+
"postTypes": [
|
|
470
|
+
"text",
|
|
471
|
+
"image"
|
|
472
|
+
],
|
|
445
473
|
"analyticsSupported": false,
|
|
446
474
|
"helpers": []
|
|
447
475
|
},
|
|
448
476
|
{
|
|
449
|
-
"id": "
|
|
450
|
-
"label": "
|
|
451
|
-
"status": "
|
|
477
|
+
"id": "wordpress",
|
|
478
|
+
"label": "WordPress",
|
|
479
|
+
"status": "supported",
|
|
452
480
|
"aliases": [],
|
|
453
|
-
"postTypes": [
|
|
481
|
+
"postTypes": [
|
|
482
|
+
"text",
|
|
483
|
+
"image"
|
|
484
|
+
],
|
|
454
485
|
"analyticsSupported": false,
|
|
455
486
|
"helpers": []
|
|
456
487
|
},
|
|
457
488
|
{
|
|
458
|
-
"id": "
|
|
459
|
-
"label": "
|
|
489
|
+
"id": "lemmy",
|
|
490
|
+
"label": "Lemmy",
|
|
491
|
+
"status": "supported",
|
|
492
|
+
"aliases": [],
|
|
493
|
+
"postTypes": [
|
|
494
|
+
"text",
|
|
495
|
+
"image"
|
|
496
|
+
],
|
|
497
|
+
"analyticsSupported": false,
|
|
498
|
+
"helpers": []
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
"id": "reddit",
|
|
502
|
+
"label": "Reddit",
|
|
460
503
|
"status": "planned",
|
|
461
504
|
"aliases": [],
|
|
462
505
|
"postTypes": [],
|
|
@@ -464,8 +507,8 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
464
507
|
"helpers": []
|
|
465
508
|
},
|
|
466
509
|
{
|
|
467
|
-
"id": "
|
|
468
|
-
"label": "
|
|
510
|
+
"id": "medium",
|
|
511
|
+
"label": "Medium",
|
|
469
512
|
"status": "planned",
|
|
470
513
|
"aliases": [],
|
|
471
514
|
"postTypes": [],
|
|
@@ -614,50 +657,57 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
614
657
|
"method": "manual_credentials"
|
|
615
658
|
},
|
|
616
659
|
{
|
|
617
|
-
"id": "
|
|
618
|
-
"label": "
|
|
619
|
-
"status": "
|
|
620
|
-
"aliases": [],
|
|
621
|
-
"method": "planned"
|
|
622
|
-
},
|
|
623
|
-
{
|
|
624
|
-
"id": "wordpress",
|
|
625
|
-
"label": "WordPress",
|
|
626
|
-
"status": "planned",
|
|
660
|
+
"id": "discord",
|
|
661
|
+
"label": "Discord",
|
|
662
|
+
"status": "supported",
|
|
627
663
|
"aliases": [],
|
|
628
|
-
"method": "
|
|
664
|
+
"method": "manual_credentials"
|
|
629
665
|
},
|
|
630
666
|
{
|
|
631
667
|
"id": "mastodon",
|
|
632
668
|
"label": "Mastodon",
|
|
633
|
-
"status": "
|
|
634
|
-
"aliases": [],
|
|
635
|
-
"method": "planned"
|
|
636
|
-
},
|
|
637
|
-
{
|
|
638
|
-
"id": "medium",
|
|
639
|
-
"label": "Medium",
|
|
640
|
-
"status": "planned",
|
|
669
|
+
"status": "supported",
|
|
641
670
|
"aliases": [],
|
|
642
|
-
"method": "
|
|
671
|
+
"method": "manual_credentials"
|
|
643
672
|
},
|
|
644
673
|
{
|
|
645
674
|
"id": "devto",
|
|
646
675
|
"label": "Dev.to",
|
|
647
|
-
"status": "
|
|
676
|
+
"status": "supported",
|
|
648
677
|
"aliases": [],
|
|
649
|
-
"method": "
|
|
678
|
+
"method": "manual_credentials"
|
|
650
679
|
},
|
|
651
680
|
{
|
|
652
681
|
"id": "hashnode",
|
|
653
682
|
"label": "Hashnode",
|
|
683
|
+
"status": "supported",
|
|
684
|
+
"aliases": [],
|
|
685
|
+
"method": "manual_credentials"
|
|
686
|
+
},
|
|
687
|
+
{
|
|
688
|
+
"id": "wordpress",
|
|
689
|
+
"label": "WordPress",
|
|
690
|
+
"status": "supported",
|
|
691
|
+
"aliases": [],
|
|
692
|
+
"method": "manual_credentials"
|
|
693
|
+
},
|
|
694
|
+
{
|
|
695
|
+
"id": "lemmy",
|
|
696
|
+
"label": "Lemmy",
|
|
697
|
+
"status": "supported",
|
|
698
|
+
"aliases": [],
|
|
699
|
+
"method": "manual_credentials"
|
|
700
|
+
},
|
|
701
|
+
{
|
|
702
|
+
"id": "reddit",
|
|
703
|
+
"label": "Reddit",
|
|
654
704
|
"status": "planned",
|
|
655
705
|
"aliases": [],
|
|
656
706
|
"method": "planned"
|
|
657
707
|
},
|
|
658
708
|
{
|
|
659
|
-
"id": "
|
|
660
|
-
"label": "
|
|
709
|
+
"id": "medium",
|
|
710
|
+
"label": "Medium",
|
|
661
711
|
"status": "planned",
|
|
662
712
|
"aliases": [],
|
|
663
713
|
"method": "planned"
|
|
@@ -685,12 +735,12 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
685
735
|
}
|
|
686
736
|
]
|
|
687
737
|
});
|
|
688
|
-
export const SUPPORTED_PLATFORM_IDS = Object.freeze(["instagram","facebook","tiktok","twitter","linkedin","youtube","pinterest","threads","google_business","telegram","bluesky"]);
|
|
689
|
-
export const PLANNED_PLATFORM_IDS = Object.freeze(["reddit","
|
|
690
|
-
export const ALL_PLATFORM_IDS = Object.freeze(["instagram","facebook","tiktok","twitter","linkedin","youtube","pinterest","threads","google_business","telegram","bluesky","
|
|
691
|
-
export const SUPPORTED_PLATFORM_INPUTS = Object.freeze(["bluesky","facebook","gmb","google-business","google_business","google_business_profile","instagram","instagram-standalone","linkedin","pinterest","telegram","threads","tiktok","twitter","x","youtube"]);
|
|
692
|
-
export const ALL_PLATFORM_INPUTS = Object.freeze(["bluesky","devto","discord","facebook","gmb","google-business","google_business","google_business_profile","hashnode","instagram","instagram-standalone","linkedin","mastodon","medium","pinterest","reddit","skool","slack","telegram","threads","tiktok","twitter","whop","wordpress","x","youtube"]);
|
|
693
|
-
export const PLATFORM_HELPER_NAMES = Object.freeze(["linkedin.recent_mentions","pinterest.boards","tiktok.creator_info","x.quota"
|
|
694
|
-
export const CONNECT_TARGET_IDS = Object.freeze(["instagram","meta","facebook","youtube","tiktok","linkedin","linkedin_page","threads","google_business","pinterest","twitter","telegram","bluesky","
|
|
695
|
-
export const CONNECT_INPUTS = Object.freeze(["bluesky","devto","discord","facebook","facebook_instagram","facebook_pages","gmb","google-business","google_business","google_business_profile","hashnode","instagram","instagram-standalone","instagram_direct","linkedin","linkedin-company","linkedin-page","linkedin_company","linkedin_page","linkedin_personal","mastodon","medium","meta","meta_business","pinterest","reddit","skool","slack","telegram","threads","tiktok","twitter","whop","wordpress","x","x_twitter","youtube"]);
|
|
696
|
-
export const ANALYTICS_PLATFORM_IDS = Object.freeze(["instagram","facebook","linkedin","youtube","pinterest","google_business"]);
|
|
738
|
+
export const SUPPORTED_PLATFORM_IDS = Object.freeze(["instagram","facebook","tiktok","twitter","linkedin","youtube","pinterest","threads","google_business","telegram","bluesky","discord","mastodon","devto","hashnode","wordpress","lemmy"]);
|
|
739
|
+
export const PLANNED_PLATFORM_IDS = Object.freeze(["reddit","medium","slack","skool","whop"]);
|
|
740
|
+
export const ALL_PLATFORM_IDS = Object.freeze(["instagram","facebook","tiktok","twitter","linkedin","youtube","pinterest","threads","google_business","telegram","bluesky","discord","mastodon","devto","hashnode","wordpress","lemmy","reddit","medium","slack","skool","whop"]);
|
|
741
|
+
export const SUPPORTED_PLATFORM_INPUTS = Object.freeze(["bluesky","devto","discord","facebook","gmb","google-business","google_business","google_business_profile","hashnode","instagram","instagram-standalone","lemmy","linkedin","mastodon","pinterest","telegram","threads","tiktok","twitter","wordpress","x","youtube"]);
|
|
742
|
+
export const ALL_PLATFORM_INPUTS = Object.freeze(["bluesky","devto","discord","facebook","gmb","google-business","google_business","google_business_profile","hashnode","instagram","instagram-standalone","lemmy","linkedin","mastodon","medium","pinterest","reddit","skool","slack","telegram","threads","tiktok","twitter","whop","wordpress","x","youtube"]);
|
|
743
|
+
export const PLATFORM_HELPER_NAMES = Object.freeze(["linkedin.recent_mentions","pinterest.boards","tiktok.creator_info","x.quota"]);
|
|
744
|
+
export const CONNECT_TARGET_IDS = Object.freeze(["instagram","meta","facebook","youtube","tiktok","linkedin","linkedin_page","threads","google_business","pinterest","twitter","telegram","bluesky","discord","mastodon","devto","hashnode","wordpress","lemmy","reddit","medium","slack","skool","whop"]);
|
|
745
|
+
export const CONNECT_INPUTS = Object.freeze(["bluesky","devto","discord","facebook","facebook_instagram","facebook_pages","gmb","google-business","google_business","google_business_profile","hashnode","instagram","instagram-standalone","instagram_direct","lemmy","linkedin","linkedin-company","linkedin-page","linkedin_company","linkedin_page","linkedin_personal","mastodon","medium","meta","meta_business","pinterest","reddit","skool","slack","telegram","threads","tiktok","twitter","whop","wordpress","x","x_twitter","youtube"]);
|
|
746
|
+
export const ANALYTICS_PLATFORM_IDS = Object.freeze(["instagram","facebook","linkedin","youtube","pinterest","threads","google_business"]);
|