@posterly/cli 0.1.0 → 0.1.1

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 CHANGED
@@ -5,8 +5,8 @@ Command line access to the posterly API.
5
5
  ```bash
6
6
  posterly auth:login
7
7
  posterly auth:key pst_live_your_key_here
8
- posterly whoami --pretty
9
- posterly accounts:list --pretty
8
+ posterly whoami --human
9
+ posterly accounts:list --human
10
10
  posterly accounts:disconnect 123 --confirm --pretty
11
11
  posterly platforms:schema --platform instagram --pretty
12
12
  posterly oauth:clients --pretty
@@ -27,7 +27,7 @@ posterly gbp:reply --account-id 123 --review-name accounts/123/locations/456/rev
27
27
  ```
28
28
 
29
29
  The CLI outputs JSON by default so it can be piped into `jq` or other tools. Use
30
- `--pretty` for formatted output.
30
+ `--pretty` for formatted JSON or `--human` for readable Markdown-style tables.
31
31
 
32
32
  Authentication order:
33
33
 
package/bin/posterly.mjs CHANGED
@@ -54,6 +54,7 @@ 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.',
57
58
  commands: COMMANDS,
58
59
  auth: 'Run `posterly auth:login`, `posterly auth:key pst_live_...`, or set POSTERLY_API_KEY.',
59
60
  }, flags);
@@ -839,7 +840,182 @@ function escapeHtml(value) {
839
840
  .replace(/'/g, '&#39;');
840
841
  }
841
842
 
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
+
842
1014
  function print(value, flags = {}) {
1015
+ if (flagEnabled(flags.human)) {
1016
+ process.stdout.write(`${formatHuman(value)}\n`);
1017
+ return;
1018
+ }
843
1019
  const json = flags.pretty ? JSON.stringify(value, null, 2) : JSON.stringify(value);
844
1020
  process.stdout.write(`${json}\n`);
845
1021
  }
@@ -131,6 +131,7 @@ export const PLATFORM_MANIFEST = Object.freeze({
131
131
  ],
132
132
  "analyticsPlatformIds": [
133
133
  "instagram",
134
+ "facebook",
134
135
  "linkedin",
135
136
  "youtube",
136
137
  "pinterest",
@@ -268,7 +269,7 @@ export const PLATFORM_MANIFEST = Object.freeze({
268
269
  "story",
269
270
  "cover_photo"
270
271
  ],
271
- "analyticsSupported": false,
272
+ "analyticsSupported": true,
272
273
  "helpers": []
273
274
  },
274
275
  {
@@ -692,4 +693,4 @@ export const ALL_PLATFORM_INPUTS = Object.freeze(["bluesky","devto","discord","f
692
693
  export const PLATFORM_HELPER_NAMES = Object.freeze(["linkedin.recent_mentions","pinterest.boards","tiktok.creator_info","x.quota","youtube.playlists"]);
693
694
  export const CONNECT_TARGET_IDS = Object.freeze(["instagram","meta","facebook","youtube","tiktok","linkedin","linkedin_page","threads","google_business","pinterest","twitter","telegram","bluesky","reddit","wordpress","mastodon","medium","devto","hashnode","discord","slack","skool","whop"]);
694
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"]);
695
- export const ANALYTICS_PLATFORM_IDS = Object.freeze(["instagram","linkedin","youtube","pinterest","google_business"]);
696
+ export const ANALYTICS_PLATFORM_IDS = Object.freeze(["instagram","facebook","linkedin","youtube","pinterest","google_business"]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posterly/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Command line interface for the posterly API",
5
5
  "license": "MIT",
6
6
  "type": "module",