@posty5/social-publisher-post 4.1.0 β 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +273 -15
- package/dist/index.d.mts +833 -54
- package/dist/index.d.ts +833 -54
- package/dist/index.js +1552 -217
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1544 -218
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -106,6 +106,33 @@ console.log("YouTube:", status.youtube?.postInfo.currentStatus);
|
|
|
106
106
|
|
|
107
107
|
---
|
|
108
108
|
|
|
109
|
+
## π Versioned writes (5.0.0)
|
|
110
|
+
|
|
111
|
+
Every write to an existing document carries the version you read, so two
|
|
112
|
+
people (or two scripts) can never silently overwrite each other.
|
|
113
|
+
|
|
114
|
+
- **Where `__v` comes from:** every entity this SDK returns (`get`, `list`,
|
|
115
|
+
and every write) has `__v`. Keep the `__v` a write returns for your next write.
|
|
116
|
+
- **A stale version** throws `ConflictError` (409). It carries
|
|
117
|
+
`currentVersion`, the document's version now.
|
|
118
|
+
- **Merging deliberately:** reload, re-apply your change, and resend with the
|
|
119
|
+
fresh version (`currentVersion`). There is no "overwrite anyway" flag;
|
|
120
|
+
resending blindly is exactly the lost update this prevents.
|
|
121
|
+
- Versioned writes are never retried automatically.
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
import { ConflictError } from "@posty5/core";
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
const post = await client.getStatus(id);
|
|
128
|
+
await client.reschedulePost(id, { schedule: 'now' }, post.__v);
|
|
129
|
+
} catch (error) {
|
|
130
|
+
if (error instanceof ConflictError) {
|
|
131
|
+
// error.currentVersion: reload, merge, and resend with the fresh __v
|
|
132
|
+
} else throw error;
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
109
136
|
## Γ°ΕΈβΕ‘ API Reference & Examples
|
|
110
137
|
|
|
111
138
|
### publishShortVideo()
|
|
@@ -190,34 +217,68 @@ const postId = await client.publishShortVideo({
|
|
|
190
217
|
console.log("Published to YouTube and TikTok:", postId);
|
|
191
218
|
```
|
|
192
219
|
|
|
193
|
-
**Example -
|
|
220
|
+
**Example - Comments After Publish (25 credits each):**
|
|
194
221
|
|
|
195
222
|
```typescript
|
|
196
|
-
// Publish a video and queue
|
|
197
|
-
// TikTok
|
|
198
|
-
//
|
|
223
|
+
// Publish a video and queue up to five comments under each platform post.
|
|
224
|
+
// TikTok is never one of them: it exposes no public comment-posting endpoint,
|
|
225
|
+
// so a comment aimed at it reports `notSupported` rather than failing.
|
|
199
226
|
const postId = await client.publishShortVideo({
|
|
200
227
|
workspaceId: "workspace-123",
|
|
201
228
|
video: videoFile,
|
|
202
229
|
youtube: { title: "Launch day", description: "We shipped!", tags: ["launch"] },
|
|
203
230
|
facebook: { description: "We shipped!" },
|
|
204
231
|
instagram: { description: "We shipped! Γ°ΕΈΕ‘β¬" },
|
|
205
|
-
comment
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
232
|
+
// Up to five, in the order they post. 25 credits each, charged per comment
|
|
233
|
+
// that actually posts.
|
|
234
|
+
comments: [
|
|
235
|
+
{
|
|
236
|
+
text: "Drop your favourite feature below",
|
|
237
|
+
postToFacebook: true,
|
|
238
|
+
postToInstagram: true,
|
|
239
|
+
postToYoutube: true,
|
|
240
|
+
// postToTiktok defaults to false - TikTok exposes no comment API
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
// An hour later, to catch the second wave.
|
|
244
|
+
text: "Still reading? The changelog is in the description.",
|
|
245
|
+
delayMinutes: 60,
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
// An image is Facebook only; Instagram and YouTube comments are
|
|
249
|
+
// text-only, so it is dropped there with a reason rather than failing.
|
|
250
|
+
text: "Here is the before and after.",
|
|
251
|
+
imageUrl: "https://cdn.example.com/before-after.jpg",
|
|
252
|
+
postToFacebook: true,
|
|
253
|
+
postToInstagram: false,
|
|
254
|
+
postToYoutube: false,
|
|
255
|
+
},
|
|
256
|
+
],
|
|
212
257
|
});
|
|
213
258
|
|
|
214
|
-
// Later, poll status to see how each comment landed
|
|
259
|
+
// Later, poll status to see how each comment landed.
|
|
215
260
|
const status = await client.getStatus(postId);
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
261
|
+
|
|
262
|
+
// One entry per comment, in posting order.
|
|
263
|
+
for (const comment of status.facebook?.comments ?? []) {
|
|
264
|
+
console.log(`#${comment.order}`, comment.currentStatus, comment.commentURL);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// TikTok reports every comment as notSupported - that is the permanent answer,
|
|
268
|
+
// not a failure.
|
|
269
|
+
console.log("TikTok:", status.tiktok?.comments?.[0]?.currentStatus); // "notSupported"
|
|
219
270
|
```
|
|
220
271
|
|
|
272
|
+
> **Migrating from `comment`.** The singular field still compiles and is
|
|
273
|
+
> deprecated for one major version. Send one or the other - the API refuses a
|
|
274
|
+
> request carrying both. The singular `commentInfo` on each platform's status
|
|
275
|
+
> also stays, mirroring the first entry of `comments`.
|
|
276
|
+
|
|
277
|
+
> **Pricing.** 25 credits per comment that actually posts, from the API's
|
|
278
|
+
> `socialMediaPublisher.commentOnPost`. Earlier releases of this README said
|
|
279
|
+
> "+1 credit", which was never the price. A comment aimed at no enabled platform
|
|
280
|
+
> is dropped before it is charged.
|
|
281
|
+
|
|
221
282
|
**Example - Multi-Platform Publishing:**
|
|
222
283
|
|
|
223
284
|
```typescript
|
|
@@ -288,6 +349,188 @@ const postId = await client.publishShortVideo({
|
|
|
288
349
|
console.log("Scheduled for", publishDate, "- Post ID:", postId);
|
|
289
350
|
```
|
|
290
351
|
|
|
352
|
+
### publishLongVideoToWorkspace()
|
|
353
|
+
|
|
354
|
+
Publish a video of up to **60 minutes** to every account connected to a workspace.
|
|
355
|
+
|
|
356
|
+
The SDK handles the whole sequence for an uploaded file β reserve an upload
|
|
357
|
+
destination, push the bytes, create the post. Pass a URL string instead of a
|
|
358
|
+
`File` to publish something already hosted elsewhere.
|
|
359
|
+
|
|
360
|
+
```typescript
|
|
361
|
+
const result = await client.publishLongVideoToWorkspace({
|
|
362
|
+
workspaceId: "workspace_123",
|
|
363
|
+
video: recordingFile, // File, or a direct https:// URL
|
|
364
|
+
youtube: {
|
|
365
|
+
title: "Full workshop recording",
|
|
366
|
+
description: "The complete two-part session.",
|
|
367
|
+
tags: ["workshop", "long-form"],
|
|
368
|
+
privacyStatus: "public",
|
|
369
|
+
},
|
|
370
|
+
facebook: { title: "Full workshop recording", description: "The complete session." },
|
|
371
|
+
onProgress: (percent) => console.log(`Upload ${percent}%`),
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
console.log(result.durationSeconds); // 2400 β measured by the server
|
|
375
|
+
console.log(result.credits); // 400 β 8 units x 50
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
#### Cost
|
|
379
|
+
|
|
380
|
+
Long video is priced by **duration**: 50 credits for every *started* 5 minutes.
|
|
381
|
+
|
|
382
|
+
| Video length | Units | Credits |
|
|
383
|
+
| --- | --- | --- |
|
|
384
|
+
| 4m 30s | 1 | 50 |
|
|
385
|
+
| 12m | 3 | 150 |
|
|
386
|
+
| 15m | 3 | 150 |
|
|
387
|
+
| 15m 01s | 4 | 200 |
|
|
388
|
+
| 60m | 12 | 600 |
|
|
389
|
+
|
|
390
|
+
There is no `duration` option, and one would be ignored β the server measures
|
|
391
|
+
the video itself, because a client-supplied duration would be a
|
|
392
|
+
client-supplied price.
|
|
393
|
+
|
|
394
|
+
Requires the `socialMediaPublisher.longVideoPost` plan feature.
|
|
395
|
+
|
|
396
|
+
#### Quote before you publish
|
|
397
|
+
|
|
398
|
+
```typescript
|
|
399
|
+
const quote = await client.getLongVideoQuote(videoURL);
|
|
400
|
+
|
|
401
|
+
if (!quote.withinLimit) throw new Error(quote.reason); // over 60 minutes
|
|
402
|
+
console.log(`${quote.durationSeconds}s costs ${quote.credits} credits`);
|
|
403
|
+
|
|
404
|
+
// Which targets can actually take a video this long?
|
|
405
|
+
for (const p of quote.platforms.filter((p) => !p.accepted)) {
|
|
406
|
+
console.warn(`${p.platform}: ${p.reason}`);
|
|
407
|
+
}
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
#### Interrupted uploads resume
|
|
411
|
+
|
|
412
|
+
Long video uploads resumably: the file goes up in 8MiB chunks, so a dropped
|
|
413
|
+
connection costs one chunk rather than the hour of footage before it. Keep the
|
|
414
|
+
upload URL and you can continue the same transfer later β even after a page
|
|
415
|
+
reload.
|
|
416
|
+
|
|
417
|
+
```typescript
|
|
418
|
+
let resumeFrom = localStorage.getItem("upload-url") ?? undefined;
|
|
419
|
+
|
|
420
|
+
await client.publishLongVideoToWorkspace({
|
|
421
|
+
workspaceId: "workspace_123",
|
|
422
|
+
video: recordingFile,
|
|
423
|
+
youtube: { title: "Full recording", description: "...", tags: [] },
|
|
424
|
+
resumeFrom,
|
|
425
|
+
onUploadUrl: (url) => localStorage.setItem("upload-url", url),
|
|
426
|
+
signal: controller.signal, // aborting keeps what was uploaded
|
|
427
|
+
});
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
The SDK falls back to a single signed PUT when the server does not offer the
|
|
431
|
+
resumable service, so this needs no configuration on your side.
|
|
432
|
+
|
|
433
|
+
#### Cancelling for good
|
|
434
|
+
|
|
435
|
+
Aborting leaves the uploaded bytes on the server, because in most interfaces
|
|
436
|
+
"pause" and "cancel" are the same button and a user who paused a 40-minute video
|
|
437
|
+
does not expect to start over. Where the abort really is final β a wizard the
|
|
438
|
+
user closed, a file they swapped out β say so, and the server stops holding
|
|
439
|
+
megabytes nobody will claim:
|
|
440
|
+
|
|
441
|
+
```typescript
|
|
442
|
+
await client.publishLongVideoToWorkspace({
|
|
443
|
+
// ...
|
|
444
|
+
signal: controller.signal,
|
|
445
|
+
terminateOnAbort: true,
|
|
446
|
+
});
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
For an upload URL you persisted earlier and have decided not to resume, discard
|
|
450
|
+
it directly. It never throws β a cleanup that fails is not worth an error, since
|
|
451
|
+
the server expires abandoned uploads after 24 hours anyway:
|
|
452
|
+
|
|
453
|
+
```typescript
|
|
454
|
+
import { terminateUpload } from "@posty5/social-publisher-post";
|
|
455
|
+
|
|
456
|
+
const discarded = await terminateUpload(savedUploadUrl);
|
|
457
|
+
localStorage.removeItem("upload-url");
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
#### What counts as a video
|
|
461
|
+
|
|
462
|
+
Both long-video helpers take a **browser `File` or `Blob`**, or a URL to a video
|
|
463
|
+
already hosted somewhere reachable. They do **not** accept a Node `ReadStream` or
|
|
464
|
+
a filesystem path β the same boundary the short-video helpers have always had.
|
|
465
|
+
|
|
466
|
+
From Node, read the file and hand over a `Blob`:
|
|
467
|
+
|
|
468
|
+
```typescript
|
|
469
|
+
import { readFile } from "node:fs/promises";
|
|
470
|
+
|
|
471
|
+
const bytes = await readFile("./recording.mp4");
|
|
472
|
+
const video = new File([bytes], "recording.mp4", { type: "video/mp4" });
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
That buffers the whole file in memory, which is the reason the streaming variant
|
|
476
|
+
does not exist yet rather than an oversight. For anything large from a server,
|
|
477
|
+
prefer uploading to your own storage first and publishing by URL.
|
|
478
|
+
|
|
479
|
+
#### Platforms disagree about "long"
|
|
480
|
+
|
|
481
|
+
A 40-minute video is a fine YouTube post and an impossible Instagram one β
|
|
482
|
+
Reels stop at 15 minutes. Rather than fail the whole post, a workspace publish
|
|
483
|
+
goes out to the targets that accept it and tells you which it dropped:
|
|
484
|
+
|
|
485
|
+
```typescript
|
|
486
|
+
for (const target of result.refusedTargets) {
|
|
487
|
+
console.warn(`${target.platform} skipped: ${target.reason}`);
|
|
488
|
+
}
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
Limits are checked when the post is created, never mid-upload. TikTok's cap is
|
|
492
|
+
per-creator and read from the connected account.
|
|
493
|
+
|
|
494
|
+
---
|
|
495
|
+
|
|
496
|
+
### publishLongVideoToAccount()
|
|
497
|
+
|
|
498
|
+
The same, targeting one connected account. With a single target there is no
|
|
499
|
+
partial success: if that platform will not take a video this long, the call is
|
|
500
|
+
refused and nothing is charged.
|
|
501
|
+
|
|
502
|
+
```typescript
|
|
503
|
+
const result = await client.publishLongVideoToAccount({
|
|
504
|
+
accountId: "account_456",
|
|
505
|
+
video: recordingFile,
|
|
506
|
+
youtube: { title: "Episode 14", description: "The full episode.", tags: ["podcast"] },
|
|
507
|
+
schedule: new Date("2026-09-15T10:00:00Z"),
|
|
508
|
+
});
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
---
|
|
512
|
+
|
|
513
|
+
### reschedulePost()
|
|
514
|
+
|
|
515
|
+
Move a post that has not published yet to a different time, or send it out now.
|
|
516
|
+
Free β this costs no credits.
|
|
517
|
+
|
|
518
|
+
```typescript
|
|
519
|
+
// Move it
|
|
520
|
+
await client.reschedulePost("post_123", { schedule: new Date("2026-09-01T09:00:00Z") });
|
|
521
|
+
|
|
522
|
+
// Or publish it immediately
|
|
523
|
+
await client.reschedulePost("post_123", { schedule: "now" });
|
|
524
|
+
|
|
525
|
+
// Optionally replace the caption at the same time
|
|
526
|
+
await client.reschedulePost("post_123", { schedule: "now", caption: "Updated caption" });
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
Only posts still pending with a future publish time are eligible. Anything that
|
|
530
|
+
has already started publishing is refused by the server with a reason.
|
|
531
|
+
|
|
532
|
+
---
|
|
533
|
+
|
|
291
534
|
---
|
|
292
535
|
|
|
293
536
|
### list()
|
|
@@ -910,6 +1153,21 @@ We're here to help you succeed with Posty5!
|
|
|
910
1153
|
|
|
911
1154
|
---
|
|
912
1155
|
|
|
1156
|
+
## π Text posts and stories (4.6.0)
|
|
1157
|
+
|
|
1158
|
+
```ts
|
|
1159
|
+
await posts.createTextPostToWorkspace({ workspaceId, caption: "Launching today!", threads: { topic_tag: "launch" } });
|
|
1160
|
+
await posts.createTextPostToAccount({ accountId, caption: "Hello X", twitter: { reply_settings: "following" } });
|
|
1161
|
+
|
|
1162
|
+
await posts.createStoryPostToWorkspace({ workspaceId, kind: "image", image: { source: "image-url", externalUrl } });
|
|
1163
|
+
await posts.createStoryPostToAccount({ accountId, platform: "instagram", kind: "video", source: "video-url", videoURL });
|
|
1164
|
+
```
|
|
1165
|
+
|
|
1166
|
+
Each answers `{ _id, refusedTargets?, truncatedTargets?, skippedPlatforms? }`.
|
|
1167
|
+
Story media is by URL in this release.
|
|
1168
|
+
|
|
1169
|
+
---
|
|
1170
|
+
|
|
913
1171
|
## Γ°ΕΈββ License
|
|
914
1172
|
|
|
915
1173
|
MIT License - see [LICENSE](./LICENSE) file for details.
|