@posterly/cli 0.1.1 → 0.1.2
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 +35 -3
- package/bin/posterly.mjs +7 -179
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,11 +2,42 @@
|
|
|
2
2
|
|
|
3
3
|
Command line access to the posterly API.
|
|
4
4
|
|
|
5
|
+
## Quick start
|
|
6
|
+
|
|
7
|
+
Run the CLI without installing anything globally:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx @posterly/cli@latest auth:login
|
|
11
|
+
npx @posterly/cli@latest whoami --pretty
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
`npx` downloads and runs the CLI for that command. It does not leave a permanent
|
|
15
|
+
`posterly` binary on your shell `PATH`, so keep using `npx @posterly/cli@latest`
|
|
16
|
+
for each command unless you install the CLI globally.
|
|
17
|
+
|
|
18
|
+
Optional global install:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm i -g @posterly/cli@latest
|
|
22
|
+
posterly auth:login
|
|
23
|
+
posterly whoami --pretty
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
If global install fails with `EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@posterly'`,
|
|
27
|
+
your npm global folder is not writable by your user. Use the `npx` commands
|
|
28
|
+
above, or fix your npm setup with a user-owned Node install such as `nvm`.
|
|
29
|
+
|
|
30
|
+
Running `npm i @posterly/cli` without `-g` installs the package into the current
|
|
31
|
+
folder. In that case `posterly` will only be available as
|
|
32
|
+
`./node_modules/.bin/posterly` from that folder, not as a global terminal command.
|
|
33
|
+
|
|
34
|
+
## Examples
|
|
35
|
+
|
|
5
36
|
```bash
|
|
6
37
|
posterly auth:login
|
|
7
38
|
posterly auth:key pst_live_your_key_here
|
|
8
|
-
posterly whoami --
|
|
9
|
-
posterly accounts:list --
|
|
39
|
+
posterly whoami --pretty
|
|
40
|
+
posterly accounts:list --pretty
|
|
10
41
|
posterly accounts:disconnect 123 --confirm --pretty
|
|
11
42
|
posterly platforms:schema --platform instagram --pretty
|
|
12
43
|
posterly oauth:clients --pretty
|
|
@@ -27,7 +58,8 @@ posterly gbp:reply --account-id 123 --review-name accounts/123/locations/456/rev
|
|
|
27
58
|
```
|
|
28
59
|
|
|
29
60
|
The CLI outputs JSON by default so it can be piped into `jq` or other tools. Use
|
|
30
|
-
`--pretty` for formatted
|
|
61
|
+
`--pretty` for formatted output. `--human` is accepted as an alias for
|
|
62
|
+
`--pretty` for older examples.
|
|
31
63
|
|
|
32
64
|
Authentication order:
|
|
33
65
|
|
package/bin/posterly.mjs
CHANGED
|
@@ -54,9 +54,8 @@ async function main() {
|
|
|
54
54
|
return print({
|
|
55
55
|
posterly: 'CLI for the posterly API',
|
|
56
56
|
usage: 'posterly <command> [--flag value]',
|
|
57
|
-
output: 'JSON by default. Add --human for readable Markdown-style tables, or --pretty for formatted JSON.',
|
|
58
57
|
commands: COMMANDS,
|
|
59
|
-
auth: 'Run `posterly auth:login
|
|
58
|
+
auth: 'Run `npx @posterly/cli@latest auth:login` for the no-install flow, `posterly auth:login` after global install, `posterly auth:key pst_live_...`, or set POSTERLY_API_KEY.',
|
|
60
59
|
}, flags);
|
|
61
60
|
}
|
|
62
61
|
|
|
@@ -359,6 +358,10 @@ function parseArgs(args) {
|
|
|
359
358
|
}
|
|
360
359
|
}
|
|
361
360
|
|
|
361
|
+
if (flags.human && flags.pretty === undefined) {
|
|
362
|
+
flags.pretty = true;
|
|
363
|
+
}
|
|
364
|
+
|
|
362
365
|
return { command, flags, positional };
|
|
363
366
|
}
|
|
364
367
|
|
|
@@ -366,7 +369,7 @@ async function createClient(flags) {
|
|
|
366
369
|
const config = await readConfig();
|
|
367
370
|
const apiKey = flags.apiKey || process.env.POSTERLY_API_KEY || config.apiKey;
|
|
368
371
|
const baseUrl = normalizeBaseUrl(flags.url || process.env.POSTERLY_URL || config.baseUrl || DEFAULT_BASE_URL);
|
|
369
|
-
if (!apiKey) throw new Error('Missing API key. Run `posterly auth:key pst_live_
|
|
372
|
+
if (!apiKey) throw new Error('Missing API key. Run `npx @posterly/cli@latest auth:login`, `posterly auth:key pst_live_...`, or set POSTERLY_API_KEY.');
|
|
370
373
|
|
|
371
374
|
async function request(method, path, body) {
|
|
372
375
|
const res = await fetch(`${baseUrl}/api/v1${path}`, {
|
|
@@ -401,7 +404,7 @@ async function createClient(flags) {
|
|
|
401
404
|
|
|
402
405
|
async function saveKey(key, flags) {
|
|
403
406
|
const apiKey = key || flags.apiKey || process.env.POSTERLY_API_KEY;
|
|
404
|
-
if (!apiKey) throw new Error('Pass an API key: posterly auth:key pst_live_...');
|
|
407
|
+
if (!apiKey) throw new Error('Pass an API key: posterly auth:key pst_live_... or npx @posterly/cli@latest auth:key pst_live_...');
|
|
405
408
|
await mkdir(CONFIG_DIR, { recursive: true });
|
|
406
409
|
const config = {
|
|
407
410
|
apiKey,
|
|
@@ -840,182 +843,7 @@ function escapeHtml(value) {
|
|
|
840
843
|
.replace(/'/g, ''');
|
|
841
844
|
}
|
|
842
845
|
|
|
843
|
-
function formatHuman(value) {
|
|
844
|
-
if (value === null || value === undefined) return 'No response body.';
|
|
845
|
-
if (typeof value !== 'object' || Array.isArray(value)) return JSON.stringify(value, null, 2);
|
|
846
|
-
|
|
847
|
-
if (Array.isArray(value.accounts)) {
|
|
848
|
-
return [
|
|
849
|
-
`## Connected accounts (${value.accounts.length})`,
|
|
850
|
-
markdownTable(['Platform', 'Account', 'Account ID', 'Workspace'], value.accounts.map((account) => [
|
|
851
|
-
account.platform,
|
|
852
|
-
account.username ? `@${account.username}` : 'n/a',
|
|
853
|
-
codeCell(account.id),
|
|
854
|
-
account.workspace_id ? codeCell(account.workspace_id) : 'default',
|
|
855
|
-
])),
|
|
856
|
-
].join('\n\n');
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
if (Array.isArray(value.brands)) {
|
|
860
|
-
return [
|
|
861
|
-
`## Brands (${value.brands.length})`,
|
|
862
|
-
markdownTable(['Brand', 'Brand ID', 'Accounts', 'Source', 'Workspace'], value.brands.map((brand) => [
|
|
863
|
-
brand.name,
|
|
864
|
-
codeCell(brand.id),
|
|
865
|
-
brand.account_count,
|
|
866
|
-
brand.source,
|
|
867
|
-
brand.workspace_id ? codeCell(brand.workspace_id) : 'default',
|
|
868
|
-
])),
|
|
869
|
-
].join('\n\n');
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
if (Array.isArray(value.posts)) {
|
|
873
|
-
return [
|
|
874
|
-
`## Posts (${value.posts.length}${value.total !== undefined ? ` of ${value.total}` : ''})`,
|
|
875
|
-
markdownTable(['Status', 'Post ID', 'Caption', 'Scheduled', 'Type'], value.posts.map((post) => [
|
|
876
|
-
post.status,
|
|
877
|
-
codeCell(post.id),
|
|
878
|
-
compactCell(post.content || post.caption || post.caption_snippet, 80) || '(empty)',
|
|
879
|
-
formatDateCell(post.scheduled_at || post.posted_at),
|
|
880
|
-
post.post_type || post.media_type || 'post',
|
|
881
|
-
])),
|
|
882
|
-
].join('\n\n');
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
if (value.account && value.summary && value.range) {
|
|
886
|
-
return [
|
|
887
|
-
`## Analytics for @${value.account.username}`,
|
|
888
|
-
`_${value.account.platform} · ${value.range.from} → ${value.range.to}_`,
|
|
889
|
-
'',
|
|
890
|
-
markdownTable(['Metric', 'Value'], analyticsRows(value.summary)),
|
|
891
|
-
].join('\n');
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
if (Array.isArray(value.reviews)) {
|
|
895
|
-
return [
|
|
896
|
-
`## Google Business reviews (${value.reviews.length}${value.total !== undefined ? ` of ${value.total}` : ''})`,
|
|
897
|
-
markdownTable(['Reviewer', 'Rating', 'Location', 'Reply', 'Comment'], value.reviews.map((review) => [
|
|
898
|
-
review.reviewer?.displayName || 'Anonymous',
|
|
899
|
-
review.starRating ? `${review.starRating} stars` : 'unrated',
|
|
900
|
-
review.businessName || review.locationName || review.locationId || 'location',
|
|
901
|
-
review.reviewReply ? 'replied' : 'unanswered',
|
|
902
|
-
compactCell(review.comment, 120) || '(rating only)',
|
|
903
|
-
])),
|
|
904
|
-
].join('\n\n');
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
if (Array.isArray(value.webhooks)) {
|
|
908
|
-
return [
|
|
909
|
-
`## Webhooks (${value.webhooks.length})`,
|
|
910
|
-
markdownTable(['Webhook ID', 'State', 'URL', 'Events'], value.webhooks.map((webhook) => [
|
|
911
|
-
codeCell(webhook.id),
|
|
912
|
-
webhook.is_active ? 'active' : 'inactive',
|
|
913
|
-
webhook.url,
|
|
914
|
-
Array.isArray(webhook.events) && webhook.events.length ? webhook.events.join(', ') : 'default events',
|
|
915
|
-
])),
|
|
916
|
-
].join('\n\n');
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
if (Array.isArray(value.platforms)) {
|
|
920
|
-
return [
|
|
921
|
-
`## Posterly platforms (${value.platforms.length})`,
|
|
922
|
-
markdownTable(['Platform', 'ID', 'Status', 'Post types', 'Analytics'], value.platforms.map((platform) => [
|
|
923
|
-
platform.label,
|
|
924
|
-
codeCell(platform.id),
|
|
925
|
-
platform.status,
|
|
926
|
-
Array.isArray(platform.post_types) ? platform.post_types.join(', ') : 'n/a',
|
|
927
|
-
Boolean(platform.analytics_supported) ? 'yes' : 'no',
|
|
928
|
-
])),
|
|
929
|
-
].join('\n\n');
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
if (value.post) {
|
|
933
|
-
return [
|
|
934
|
-
`## Post ${codeCell(value.post.id)}`,
|
|
935
|
-
markdownTable(['Field', 'Value'], [
|
|
936
|
-
['Status', value.post.status],
|
|
937
|
-
['Type', value.post.post_type || 'unknown'],
|
|
938
|
-
['Scheduled', formatDateCell(value.post.scheduled_at)],
|
|
939
|
-
['Published URL', value.post.platform_post_url],
|
|
940
|
-
]),
|
|
941
|
-
value.post.content ? `\n### Caption\n> ${String(value.post.content).replace(/\n/g, '\n> ')}` : '',
|
|
942
|
-
].filter(Boolean).join('\n\n');
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
return [
|
|
946
|
-
'## Posterly response',
|
|
947
|
-
markdownTable(['Field', 'Value'], Object.entries(value).map(([key, item]) => [
|
|
948
|
-
key,
|
|
949
|
-
Array.isArray(item)
|
|
950
|
-
? item.join('\n')
|
|
951
|
-
: typeof item === 'object' && item !== null
|
|
952
|
-
? JSON.stringify(item)
|
|
953
|
-
: item,
|
|
954
|
-
])),
|
|
955
|
-
].join('\n\n');
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
function analyticsRows(summary) {
|
|
959
|
-
return [
|
|
960
|
-
['Followers', summary.current_followers],
|
|
961
|
-
['Followers change', signedCell(summary.followers_change)],
|
|
962
|
-
['Reach', summary.total_reach],
|
|
963
|
-
['Views', summary.total_views],
|
|
964
|
-
['Profile views', summary.total_profile_views],
|
|
965
|
-
['Accounts engaged', summary.total_accounts_engaged],
|
|
966
|
-
['Engagement rate', summary.engagement_rate == null ? undefined : `${summary.engagement_rate}%`],
|
|
967
|
-
['Engagement rate by followers', summary.engagement_rate_by_followers == null ? undefined : `${summary.engagement_rate_by_followers}%`],
|
|
968
|
-
];
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
function markdownTable(headers, rows) {
|
|
972
|
-
const visibleRows = rows.filter((row) => row.some((cell) => cell !== undefined && cell !== null && cell !== ''));
|
|
973
|
-
if (visibleRows.length === 0) return '';
|
|
974
|
-
return [
|
|
975
|
-
`| ${headers.map(escapeTableCell).join(' | ')} |`,
|
|
976
|
-
`| ${headers.map(() => '---').join(' | ')} |`,
|
|
977
|
-
...visibleRows.map((row) => `| ${row.map(formatTableCell).map(escapeTableCell).join(' | ')} |`),
|
|
978
|
-
].join('\n');
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
function formatTableCell(value) {
|
|
982
|
-
if (value === undefined || value === null || value === '') return 'n/a';
|
|
983
|
-
if (typeof value === 'boolean') return value ? 'yes' : 'no';
|
|
984
|
-
if (typeof value === 'number') return value.toLocaleString();
|
|
985
|
-
return String(value);
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
function escapeTableCell(value) {
|
|
989
|
-
return String(value).replace(/\|/g, '\\|').replace(/\r?\n/g, '<br>');
|
|
990
|
-
}
|
|
991
|
-
|
|
992
|
-
function codeCell(value) {
|
|
993
|
-
return `\`${formatTableCell(value).replace(/`/g, '\\`')}\``;
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
function compactCell(value, maxLength = 80) {
|
|
997
|
-
const text = String(value || '').replace(/\s+/g, ' ').trim();
|
|
998
|
-
return text.length > maxLength ? `${text.slice(0, Math.max(0, maxLength - 1))}…` : text;
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
function signedCell(value) {
|
|
1002
|
-
if (value === undefined || value === null || value === '') return 'n/a';
|
|
1003
|
-
const number = Number(value);
|
|
1004
|
-
if (Number.isNaN(number)) return String(value);
|
|
1005
|
-
return number >= 0 ? `+${number.toLocaleString()}` : number.toLocaleString();
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
function formatDateCell(value) {
|
|
1009
|
-
if (!value) return 'n/a';
|
|
1010
|
-
const date = new Date(value);
|
|
1011
|
-
return Number.isNaN(date.getTime()) ? String(value) : date.toLocaleString();
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
846
|
function print(value, flags = {}) {
|
|
1015
|
-
if (flagEnabled(flags.human)) {
|
|
1016
|
-
process.stdout.write(`${formatHuman(value)}\n`);
|
|
1017
|
-
return;
|
|
1018
|
-
}
|
|
1019
847
|
const json = flags.pretty ? JSON.stringify(value, null, 2) : JSON.stringify(value);
|
|
1020
848
|
process.stdout.write(`${json}\n`);
|
|
1021
849
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posterly/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Command line interface for the posterly API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
|
-
"posterly": "
|
|
8
|
+
"posterly": "bin/posterly.mjs"
|
|
9
9
|
},
|
|
10
10
|
"engines": {
|
|
11
11
|
"node": ">=20"
|