@posty5/social-publisher-post 4.1.0 → 4.2.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 CHANGED
@@ -190,34 +190,68 @@ const postId = await client.publishShortVideo({
190
190
  console.log("Published to YouTube and TikTok:", postId);
191
191
  ```
192
192
 
193
- **Example - Auto-Comment After Publish (Pro plan, +1 credit):**
193
+ **Example - Comments After Publish (25 credits each):**
194
194
 
195
195
  ```typescript
196
- // Publish a video and queue a comment for each platform.
197
- // TikTok comments are not supported — the platform will always
198
- // report `commentInfo.currentStatus === "notSupported"`.
196
+ // Publish a video and queue up to five comments under each platform post.
197
+ // TikTok is never one of them: it exposes no public comment-posting endpoint,
198
+ // so a comment aimed at it reports `notSupported` rather than failing.
199
199
  const postId = await client.publishShortVideo({
200
200
  workspaceId: "workspace-123",
201
201
  video: videoFile,
202
202
  youtube: { title: "Launch day", description: "We shipped!", tags: ["launch"] },
203
203
  facebook: { description: "We shipped!" },
204
204
  instagram: { description: "We shipped! 🚀" },
205
- comment: {
206
- text: "Drop your favourite feature below 👇",
207
- postToFacebook: true,
208
- postToInstagram: true,
209
- postToYoutube: true,
210
- // postToTiktok defaults to false — TikTok does not support API comments
211
- },
205
+ // Up to five, in the order they post. 25 credits each, charged per comment
206
+ // that actually posts.
207
+ comments: [
208
+ {
209
+ text: "Drop your favourite feature below",
210
+ postToFacebook: true,
211
+ postToInstagram: true,
212
+ postToYoutube: true,
213
+ // postToTiktok defaults to false - TikTok exposes no comment API
214
+ },
215
+ {
216
+ // An hour later, to catch the second wave.
217
+ text: "Still reading? The changelog is in the description.",
218
+ delayMinutes: 60,
219
+ },
220
+ {
221
+ // An image is Facebook only; Instagram and YouTube comments are
222
+ // text-only, so it is dropped there with a reason rather than failing.
223
+ text: "Here is the before and after.",
224
+ imageUrl: "https://cdn.example.com/before-after.jpg",
225
+ postToFacebook: true,
226
+ postToInstagram: false,
227
+ postToYoutube: false,
228
+ },
229
+ ],
212
230
  });
213
231
 
214
- // Later, poll status to see how each comment landed:
232
+ // Later, poll status to see how each comment landed.
215
233
  const status = await client.getStatus(postId);
216
- console.log("YouTube comment:", status.youtube?.commentInfo?.currentStatus);
217
- console.log("Facebook comment URL:", status.facebook?.commentInfo?.commentURL);
218
- console.log("TikTok comment:", status.tiktok?.commentInfo?.currentStatus); // "notSupported"
234
+
235
+ // One entry per comment, in posting order.
236
+ for (const comment of status.facebook?.comments ?? []) {
237
+ console.log(`#${comment.order}`, comment.currentStatus, comment.commentURL);
238
+ }
239
+
240
+ // TikTok reports every comment as notSupported - that is the permanent answer,
241
+ // not a failure.
242
+ console.log("TikTok:", status.tiktok?.comments?.[0]?.currentStatus); // "notSupported"
219
243
  ```
220
244
 
245
+ > **Migrating from `comment`.** The singular field still compiles and is
246
+ > deprecated for one major version. Send one or the other - the API refuses a
247
+ > request carrying both. The singular `commentInfo` on each platform's status
248
+ > also stays, mirroring the first entry of `comments`.
249
+
250
+ > **Pricing.** 25 credits per comment that actually posts, from the API's
251
+ > `socialMediaPublisher.commentOnPost`. Earlier releases of this README said
252
+ > "+1 credit", which was never the price. A comment aimed at no enabled platform
253
+ > is dropped before it is charged.
254
+
221
255
  **Example - Multi-Platform Publishing:**
222
256
 
223
257
  ```typescript
@@ -288,6 +322,188 @@ const postId = await client.publishShortVideo({
288
322
  console.log("Scheduled for", publishDate, "- Post ID:", postId);
289
323
  ```
290
324
 
325
+ ### publishLongVideoToWorkspace()
326
+
327
+ Publish a video of up to **60 minutes** to every account connected to a workspace.
328
+
329
+ The SDK handles the whole sequence for an uploaded file — reserve an upload
330
+ destination, push the bytes, create the post. Pass a URL string instead of a
331
+ `File` to publish something already hosted elsewhere.
332
+
333
+ ```typescript
334
+ const result = await client.publishLongVideoToWorkspace({
335
+ workspaceId: "workspace_123",
336
+ video: recordingFile, // File, or a direct https:// URL
337
+ youtube: {
338
+ title: "Full workshop recording",
339
+ description: "The complete two-part session.",
340
+ tags: ["workshop", "long-form"],
341
+ privacyStatus: "public",
342
+ },
343
+ facebook: { title: "Full workshop recording", description: "The complete session." },
344
+ onProgress: (percent) => console.log(`Upload ${percent}%`),
345
+ });
346
+
347
+ console.log(result.durationSeconds); // 2400 — measured by the server
348
+ console.log(result.credits); // 400 — 8 units x 50
349
+ ```
350
+
351
+ #### Cost
352
+
353
+ Long video is priced by **duration**: 50 credits for every *started* 5 minutes.
354
+
355
+ | Video length | Units | Credits |
356
+ | --- | --- | --- |
357
+ | 4m 30s | 1 | 50 |
358
+ | 12m | 3 | 150 |
359
+ | 15m | 3 | 150 |
360
+ | 15m 01s | 4 | 200 |
361
+ | 60m | 12 | 600 |
362
+
363
+ There is no `duration` option, and one would be ignored — the server measures
364
+ the video itself, because a client-supplied duration would be a
365
+ client-supplied price.
366
+
367
+ Requires the `socialMediaPublisher.longVideoPost` plan feature.
368
+
369
+ #### Quote before you publish
370
+
371
+ ```typescript
372
+ const quote = await client.getLongVideoQuote(videoURL);
373
+
374
+ if (!quote.withinLimit) throw new Error(quote.reason); // over 60 minutes
375
+ console.log(`${quote.durationSeconds}s costs ${quote.credits} credits`);
376
+
377
+ // Which targets can actually take a video this long?
378
+ for (const p of quote.platforms.filter((p) => !p.accepted)) {
379
+ console.warn(`${p.platform}: ${p.reason}`);
380
+ }
381
+ ```
382
+
383
+ #### Interrupted uploads resume
384
+
385
+ Long video uploads resumably: the file goes up in 8MiB chunks, so a dropped
386
+ connection costs one chunk rather than the hour of footage before it. Keep the
387
+ upload URL and you can continue the same transfer later — even after a page
388
+ reload.
389
+
390
+ ```typescript
391
+ let resumeFrom = localStorage.getItem("upload-url") ?? undefined;
392
+
393
+ await client.publishLongVideoToWorkspace({
394
+ workspaceId: "workspace_123",
395
+ video: recordingFile,
396
+ youtube: { title: "Full recording", description: "...", tags: [] },
397
+ resumeFrom,
398
+ onUploadUrl: (url) => localStorage.setItem("upload-url", url),
399
+ signal: controller.signal, // aborting keeps what was uploaded
400
+ });
401
+ ```
402
+
403
+ The SDK falls back to a single signed PUT when the server does not offer the
404
+ resumable service, so this needs no configuration on your side.
405
+
406
+ #### Cancelling for good
407
+
408
+ Aborting leaves the uploaded bytes on the server, because in most interfaces
409
+ "pause" and "cancel" are the same button and a user who paused a 40-minute video
410
+ does not expect to start over. Where the abort really is final — a wizard the
411
+ user closed, a file they swapped out — say so, and the server stops holding
412
+ megabytes nobody will claim:
413
+
414
+ ```typescript
415
+ await client.publishLongVideoToWorkspace({
416
+ // ...
417
+ signal: controller.signal,
418
+ terminateOnAbort: true,
419
+ });
420
+ ```
421
+
422
+ For an upload URL you persisted earlier and have decided not to resume, discard
423
+ it directly. It never throws — a cleanup that fails is not worth an error, since
424
+ the server expires abandoned uploads after 24 hours anyway:
425
+
426
+ ```typescript
427
+ import { terminateUpload } from "@posty5/social-publisher-post";
428
+
429
+ const discarded = await terminateUpload(savedUploadUrl);
430
+ localStorage.removeItem("upload-url");
431
+ ```
432
+
433
+ #### What counts as a video
434
+
435
+ Both long-video helpers take a **browser `File` or `Blob`**, or a URL to a video
436
+ already hosted somewhere reachable. They do **not** accept a Node `ReadStream` or
437
+ a filesystem path — the same boundary the short-video helpers have always had.
438
+
439
+ From Node, read the file and hand over a `Blob`:
440
+
441
+ ```typescript
442
+ import { readFile } from "node:fs/promises";
443
+
444
+ const bytes = await readFile("./recording.mp4");
445
+ const video = new File([bytes], "recording.mp4", { type: "video/mp4" });
446
+ ```
447
+
448
+ That buffers the whole file in memory, which is the reason the streaming variant
449
+ does not exist yet rather than an oversight. For anything large from a server,
450
+ prefer uploading to your own storage first and publishing by URL.
451
+
452
+ #### Platforms disagree about "long"
453
+
454
+ A 40-minute video is a fine YouTube post and an impossible Instagram one —
455
+ Reels stop at 15 minutes. Rather than fail the whole post, a workspace publish
456
+ goes out to the targets that accept it and tells you which it dropped:
457
+
458
+ ```typescript
459
+ for (const target of result.refusedTargets) {
460
+ console.warn(`${target.platform} skipped: ${target.reason}`);
461
+ }
462
+ ```
463
+
464
+ Limits are checked when the post is created, never mid-upload. TikTok's cap is
465
+ per-creator and read from the connected account.
466
+
467
+ ---
468
+
469
+ ### publishLongVideoToAccount()
470
+
471
+ The same, targeting one connected account. With a single target there is no
472
+ partial success: if that platform will not take a video this long, the call is
473
+ refused and nothing is charged.
474
+
475
+ ```typescript
476
+ const result = await client.publishLongVideoToAccount({
477
+ accountId: "account_456",
478
+ video: recordingFile,
479
+ youtube: { title: "Episode 14", description: "The full episode.", tags: ["podcast"] },
480
+ schedule: new Date("2026-09-15T10:00:00Z"),
481
+ });
482
+ ```
483
+
484
+ ---
485
+
486
+ ### reschedulePost()
487
+
488
+ Move a post that has not published yet to a different time, or send it out now.
489
+ Free — this costs no credits.
490
+
491
+ ```typescript
492
+ // Move it
493
+ await client.reschedulePost("post_123", { schedule: new Date("2026-09-01T09:00:00Z") });
494
+
495
+ // Or publish it immediately
496
+ await client.reschedulePost("post_123", { schedule: "now" });
497
+
498
+ // Optionally replace the caption at the same time
499
+ await client.reschedulePost("post_123", { schedule: "now", caption: "Updated caption" });
500
+ ```
501
+
502
+ Only posts still pending with a future publish time are eligible. Anything that
503
+ has already started publishing is refused by the server with a reason.
504
+
505
+ ---
506
+
291
507
  ---
292
508
 
293
509
  ### list()