@posterly/cli 0.1.5 → 0.2.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/bin/posterly.mjs +95 -9
- package/generated/platform-manifest.mjs +33 -26
- package/package.json +1 -1
package/bin/posterly.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { readFile, mkdir, writeFile, rm, chmod, rename } from 'node:fs/promises';
|
|
3
|
+
import { readFile, mkdir, writeFile, rm, chmod, rename, stat } 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';
|
|
@@ -58,7 +58,7 @@ const COMMANDS = [
|
|
|
58
58
|
'media:upload|signed-upload|upload-from-url',
|
|
59
59
|
'analytics:account|posts',
|
|
60
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',
|
|
61
|
+
'ai:captions|image|image-jobs|image-job|video-options|video-function|generate-video|video-jobs|video-job',
|
|
62
62
|
'activity:list',
|
|
63
63
|
'notifications:list',
|
|
64
64
|
'x:quota',
|
|
@@ -217,11 +217,7 @@ async function main() {
|
|
|
217
217
|
})), flags);
|
|
218
218
|
|
|
219
219
|
case 'media:signed-upload':
|
|
220
|
-
return print(await client.post('/media/signed-upload',
|
|
221
|
-
filename: required(flags.filename || positional[0], 'filename'),
|
|
222
|
-
content_type: required(flags.contentType, '--content-type'),
|
|
223
|
-
size: Number(required(flags.size, '--size')),
|
|
224
|
-
}), flags);
|
|
220
|
+
return print(await client.post('/media/signed-upload', await mediaSignedUploadPayload(flags, positional)), flags);
|
|
225
221
|
case 'media:upload-from-url':
|
|
226
222
|
return print(await client.post('/media/upload-from-url', {
|
|
227
223
|
url: required(flags.url || positional[0], 'url'),
|
|
@@ -330,8 +326,23 @@ async function main() {
|
|
|
330
326
|
|
|
331
327
|
case 'ai:captions':
|
|
332
328
|
return print(await client.post('/ai/generate-captions', await captionsPayloadFromFlags(flags)), flags);
|
|
333
|
-
case 'ai:image':
|
|
334
|
-
|
|
329
|
+
case 'ai:image': {
|
|
330
|
+
const queued = await client.post('/ai/generate-image', await imagePayloadFromFlags(flags, positional));
|
|
331
|
+
if (flagEnabled(flags.noWait)) {
|
|
332
|
+
return print(queued, flags);
|
|
333
|
+
}
|
|
334
|
+
if (!queued?.job_id) {
|
|
335
|
+
return print(queued, flags);
|
|
336
|
+
}
|
|
337
|
+
return print(await pollImageJob(client, queued.job_id), flags);
|
|
338
|
+
}
|
|
339
|
+
case 'ai:image-jobs':
|
|
340
|
+
return print(await client.get(withQuery('/ai/image-jobs', {
|
|
341
|
+
status: flags.status,
|
|
342
|
+
limit: flags.limit,
|
|
343
|
+
})), flags);
|
|
344
|
+
case 'ai:image-job':
|
|
345
|
+
return print(await client.get(`/ai/image-jobs/${required(positional[0] || flags.id, 'image job id')}`), flags);
|
|
335
346
|
|
|
336
347
|
case 'ai:video-options':
|
|
337
348
|
return print(await client.get('/ai/video-options'), flags);
|
|
@@ -398,6 +409,8 @@ async function main() {
|
|
|
398
409
|
}
|
|
399
410
|
|
|
400
411
|
function parseArgs(args) {
|
|
412
|
+
// Flags that are plain on/off switches and never take the next argument.
|
|
413
|
+
const BOOLEAN_FLAGS = new Set(['pinContentType']);
|
|
401
414
|
const [command, ...rest] = args;
|
|
402
415
|
const flags = {};
|
|
403
416
|
const positional = [];
|
|
@@ -415,6 +428,12 @@ function parseArgs(args) {
|
|
|
415
428
|
flags[key] = arg.slice(eq + 1);
|
|
416
429
|
continue;
|
|
417
430
|
}
|
|
431
|
+
// Pure boolean flags never take the next argument as their value, so
|
|
432
|
+
// `a.jpg --pin-content-type b.jpg` keeps both files.
|
|
433
|
+
if (BOOLEAN_FLAGS.has(key)) {
|
|
434
|
+
flags[key] = true;
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
418
437
|
const next = rest[i + 1];
|
|
419
438
|
if (!next || next.startsWith('--')) {
|
|
420
439
|
flags[key] = true;
|
|
@@ -885,6 +904,48 @@ async function mediaUploadPayload(flags, positional) {
|
|
|
885
904
|
};
|
|
886
905
|
}
|
|
887
906
|
|
|
907
|
+
// One file: `media:signed-upload launch.mp4 --content-type video/mp4 --size N`
|
|
908
|
+
// (unchanged). Several files, up to 20 in one call: pass local paths with no
|
|
909
|
+
// --content-type, `media:signed-upload a.jpg b.jpg c.mp4`, and the CLI reads
|
|
910
|
+
// each name, type and size from disk. `--files '[{"filename","content_type",
|
|
911
|
+
// "size"}]'` sends a batch you describe yourself. `--pin-content-type` locks
|
|
912
|
+
// each slot to the declared content type: the PUT must then send exactly the
|
|
913
|
+
// returned Content-Type header or storage answers 403.
|
|
914
|
+
function takePinContentType(flags) {
|
|
915
|
+
// --pin-content-type (true) or --pin-content-type=true|false
|
|
916
|
+
return flagEnabled(flags.pinContentType) ? { pin_content_type: true } : {};
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
async function mediaSignedUploadPayload(flags, positional) {
|
|
920
|
+
const pin = takePinContentType(flags);
|
|
921
|
+
const workspace = { ...(flags.workspaceId ? { workspace_id: flags.workspaceId } : {}), ...pin };
|
|
922
|
+
if (flags.files !== undefined) {
|
|
923
|
+
const files = jsonFlag(flags.files);
|
|
924
|
+
if (!Array.isArray(files)) throw new Error('--files must be a JSON array of { filename, content_type, size }');
|
|
925
|
+
return { files, ...workspace };
|
|
926
|
+
}
|
|
927
|
+
if (flags.contentType === undefined && positional.length > 0) {
|
|
928
|
+
const files = [];
|
|
929
|
+
for (const filePath of positional) {
|
|
930
|
+
const info = await stat(filePath).catch(() => null);
|
|
931
|
+
if (!info || !info.isFile()) throw new Error(`Not a readable file: ${filePath}`);
|
|
932
|
+
files.push({
|
|
933
|
+
filename: path.basename(filePath),
|
|
934
|
+
content_type: guessContentType(filePath),
|
|
935
|
+
size: info.size,
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
if (files.length === 1) return { ...files[0], ...workspace };
|
|
939
|
+
return { files, ...workspace };
|
|
940
|
+
}
|
|
941
|
+
return {
|
|
942
|
+
filename: required(flags.filename || positional[0], 'filename'),
|
|
943
|
+
content_type: required(flags.contentType, '--content-type'),
|
|
944
|
+
size: Number(required(flags.size, '--size')),
|
|
945
|
+
...workspace,
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
|
|
888
949
|
async function captionsPayloadFromFlags(flags) {
|
|
889
950
|
if (flags.file) return readJson(required(flags.file, '--file'));
|
|
890
951
|
return clean({
|
|
@@ -912,12 +973,36 @@ async function imagePayloadFromFlags(flags, positional) {
|
|
|
912
973
|
prompt: required(flags.prompt || positional[0], '--prompt'),
|
|
913
974
|
aspect_ratio: flags.aspectRatio,
|
|
914
975
|
style: flags.style,
|
|
976
|
+
variations: flags.variations ? Number(flags.variations) : undefined,
|
|
977
|
+
provider: flags.provider,
|
|
978
|
+
model: flags.model,
|
|
979
|
+
resolution: flags.resolution,
|
|
980
|
+
quality: flags.quality,
|
|
981
|
+
thinking_level: flags.thinkingLevel,
|
|
982
|
+
reference_image_urls: csv(flags.referenceImageUrls || flags.referenceImages),
|
|
915
983
|
});
|
|
916
984
|
}
|
|
917
985
|
|
|
986
|
+
async function pollImageJob(client, jobId, options = {}) {
|
|
987
|
+
const timeoutMs = Number(options.timeoutMs || 8 * 60 * 1000);
|
|
988
|
+
const intervalMs = Number(options.intervalMs || 2000);
|
|
989
|
+
const started = Date.now();
|
|
990
|
+
while (Date.now() - started < timeoutMs) {
|
|
991
|
+
const data = await client.get(`/ai/image-jobs/${encodeURIComponent(jobId)}`);
|
|
992
|
+
const job = data.job || data;
|
|
993
|
+
if (job.status === 'completed') return job;
|
|
994
|
+
if (job.status === 'failed') {
|
|
995
|
+
throw new Error(job.error_message || 'Image job failed');
|
|
996
|
+
}
|
|
997
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
998
|
+
}
|
|
999
|
+
throw new Error(`Image job ${jobId} is still running. Poll with: posterly ai:image-job ${jobId}`);
|
|
1000
|
+
}
|
|
1001
|
+
|
|
918
1002
|
async function videoPayloadFromFlags(flags) {
|
|
919
1003
|
if (flags.file) return readJson(required(flags.file, '--file'));
|
|
920
1004
|
return clean({
|
|
1005
|
+
provider: flags.provider,
|
|
921
1006
|
prompt: required(flags.prompt, '--prompt'),
|
|
922
1007
|
negative_prompt: flags.negativePrompt,
|
|
923
1008
|
aspect_ratio: flags.aspectRatio,
|
|
@@ -944,6 +1029,7 @@ async function videoFunctionPayloadFromFlags(flags, positional) {
|
|
|
944
1029
|
duration_seconds: flags.durationSeconds ? Number(flags.durationSeconds) : undefined,
|
|
945
1030
|
resolution: flags.resolution,
|
|
946
1031
|
output: flags.output,
|
|
1032
|
+
input_image_count: flags.inputImageCount ? Number(flags.inputImageCount) : undefined,
|
|
947
1033
|
prompt: flags.prompt,
|
|
948
1034
|
negative_prompt: flags.negativePrompt,
|
|
949
1035
|
aspect_ratio: flags.aspectRatio,
|
|
@@ -14,6 +14,7 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
14
14
|
"telegram",
|
|
15
15
|
"bluesky",
|
|
16
16
|
"discord",
|
|
17
|
+
"slack",
|
|
17
18
|
"mastodon",
|
|
18
19
|
"devto",
|
|
19
20
|
"hashnode",
|
|
@@ -23,7 +24,6 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
23
24
|
"plannedPlatformIds": [
|
|
24
25
|
"reddit",
|
|
25
26
|
"medium",
|
|
26
|
-
"slack",
|
|
27
27
|
"skool",
|
|
28
28
|
"whop"
|
|
29
29
|
],
|
|
@@ -40,6 +40,7 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
40
40
|
"telegram",
|
|
41
41
|
"bluesky",
|
|
42
42
|
"discord",
|
|
43
|
+
"slack",
|
|
43
44
|
"mastodon",
|
|
44
45
|
"devto",
|
|
45
46
|
"hashnode",
|
|
@@ -47,7 +48,6 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
47
48
|
"lemmy",
|
|
48
49
|
"reddit",
|
|
49
50
|
"medium",
|
|
50
|
-
"slack",
|
|
51
51
|
"skool",
|
|
52
52
|
"whop"
|
|
53
53
|
],
|
|
@@ -67,6 +67,7 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
67
67
|
"linkedin",
|
|
68
68
|
"mastodon",
|
|
69
69
|
"pinterest",
|
|
70
|
+
"slack",
|
|
70
71
|
"telegram",
|
|
71
72
|
"threads",
|
|
72
73
|
"tiktok",
|
|
@@ -141,6 +142,7 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
141
142
|
"analyticsPlatformIds": [
|
|
142
143
|
"instagram",
|
|
143
144
|
"facebook",
|
|
145
|
+
"twitter",
|
|
144
146
|
"linkedin",
|
|
145
147
|
"youtube",
|
|
146
148
|
"pinterest",
|
|
@@ -162,6 +164,7 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
162
164
|
"telegram",
|
|
163
165
|
"bluesky",
|
|
164
166
|
"discord",
|
|
167
|
+
"slack",
|
|
165
168
|
"mastodon",
|
|
166
169
|
"devto",
|
|
167
170
|
"hashnode",
|
|
@@ -169,7 +172,6 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
169
172
|
"lemmy",
|
|
170
173
|
"reddit",
|
|
171
174
|
"medium",
|
|
172
|
-
"slack",
|
|
173
175
|
"skool",
|
|
174
176
|
"whop"
|
|
175
177
|
],
|
|
@@ -314,7 +316,7 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
314
316
|
"carousel",
|
|
315
317
|
"x_thread"
|
|
316
318
|
],
|
|
317
|
-
"analyticsSupported":
|
|
319
|
+
"analyticsSupported": true,
|
|
318
320
|
"helpers": [
|
|
319
321
|
"x.quota"
|
|
320
322
|
]
|
|
@@ -435,6 +437,20 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
435
437
|
"analyticsSupported": false,
|
|
436
438
|
"helpers": []
|
|
437
439
|
},
|
|
440
|
+
{
|
|
441
|
+
"id": "slack",
|
|
442
|
+
"label": "Slack",
|
|
443
|
+
"status": "supported",
|
|
444
|
+
"aliases": [],
|
|
445
|
+
"postTypes": [
|
|
446
|
+
"text",
|
|
447
|
+
"image",
|
|
448
|
+
"video",
|
|
449
|
+
"carousel"
|
|
450
|
+
],
|
|
451
|
+
"analyticsSupported": false,
|
|
452
|
+
"helpers": []
|
|
453
|
+
},
|
|
438
454
|
{
|
|
439
455
|
"id": "mastodon",
|
|
440
456
|
"label": "Mastodon",
|
|
@@ -515,15 +531,6 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
515
531
|
"analyticsSupported": false,
|
|
516
532
|
"helpers": []
|
|
517
533
|
},
|
|
518
|
-
{
|
|
519
|
-
"id": "slack",
|
|
520
|
-
"label": "Slack",
|
|
521
|
-
"status": "planned",
|
|
522
|
-
"aliases": [],
|
|
523
|
-
"postTypes": [],
|
|
524
|
-
"analyticsSupported": false,
|
|
525
|
-
"helpers": []
|
|
526
|
-
},
|
|
527
534
|
{
|
|
528
535
|
"id": "skool",
|
|
529
536
|
"label": "Skool",
|
|
@@ -663,6 +670,13 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
663
670
|
"aliases": [],
|
|
664
671
|
"method": "manual_credentials"
|
|
665
672
|
},
|
|
673
|
+
{
|
|
674
|
+
"id": "slack",
|
|
675
|
+
"label": "Slack",
|
|
676
|
+
"status": "supported",
|
|
677
|
+
"aliases": [],
|
|
678
|
+
"method": "dashboard_oauth"
|
|
679
|
+
},
|
|
666
680
|
{
|
|
667
681
|
"id": "mastodon",
|
|
668
682
|
"label": "Mastodon",
|
|
@@ -712,13 +726,6 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
712
726
|
"aliases": [],
|
|
713
727
|
"method": "planned"
|
|
714
728
|
},
|
|
715
|
-
{
|
|
716
|
-
"id": "slack",
|
|
717
|
-
"label": "Slack",
|
|
718
|
-
"status": "planned",
|
|
719
|
-
"aliases": [],
|
|
720
|
-
"method": "planned"
|
|
721
|
-
},
|
|
722
729
|
{
|
|
723
730
|
"id": "skool",
|
|
724
731
|
"label": "Skool",
|
|
@@ -735,12 +742,12 @@ export const PLATFORM_MANIFEST = Object.freeze({
|
|
|
735
742
|
}
|
|
736
743
|
]
|
|
737
744
|
});
|
|
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","
|
|
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","
|
|
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"]);
|
|
745
|
+
export const SUPPORTED_PLATFORM_IDS = Object.freeze(["instagram","facebook","tiktok","twitter","linkedin","youtube","pinterest","threads","google_business","telegram","bluesky","discord","slack","mastodon","devto","hashnode","wordpress","lemmy"]);
|
|
746
|
+
export const PLANNED_PLATFORM_IDS = Object.freeze(["reddit","medium","skool","whop"]);
|
|
747
|
+
export const ALL_PLATFORM_IDS = Object.freeze(["instagram","facebook","tiktok","twitter","linkedin","youtube","pinterest","threads","google_business","telegram","bluesky","discord","slack","mastodon","devto","hashnode","wordpress","lemmy","reddit","medium","skool","whop"]);
|
|
748
|
+
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","slack","telegram","threads","tiktok","twitter","wordpress","x","youtube"]);
|
|
742
749
|
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
750
|
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","
|
|
751
|
+
export const CONNECT_TARGET_IDS = Object.freeze(["instagram","meta","facebook","youtube","tiktok","linkedin","linkedin_page","threads","google_business","pinterest","twitter","telegram","bluesky","discord","slack","mastodon","devto","hashnode","wordpress","lemmy","reddit","medium","skool","whop"]);
|
|
745
752
|
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"]);
|
|
753
|
+
export const ANALYTICS_PLATFORM_IDS = Object.freeze(["instagram","facebook","twitter","linkedin","youtube","pinterest","threads","google_business"]);
|