@pubnio/sdk 0.2.13 → 0.4.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/dist/internal.js CHANGED
@@ -139,6 +139,7 @@ __export(exports_sdk_gen, {
139
139
  postsRetry: () => postsRetry,
140
140
  postsUpdate: () => postsUpdate,
141
141
  postsValidate: () => postsValidate,
142
+ postsValidateBody: () => postsValidateBody,
142
143
  profileDeactivate: () => profileDeactivate,
143
144
  profileGet: () => profileGet,
144
145
  profileUpdate: () => profileUpdate,
@@ -348,6 +349,8 @@ var IssueCode = Schema6.Literals([
348
349
  "tiktok_upload_required",
349
350
  "tiktok_too_many_mentions",
350
351
  "queue_and_time_conflict",
352
+ "queue_not_found",
353
+ "queue_unavailable",
351
354
  "invalid_field",
352
355
  "account_ambiguous",
353
356
  "unsupported_placement",
@@ -358,8 +361,9 @@ var IssueCode = Schema6.Literals([
358
361
  var PostIssue = Schema6.Struct({
359
362
  code: IssueCode,
360
363
  path: Schema6.Array(Schema6.Union([Schema6.String, Schema6.Int])),
361
- message: Schema6.String
362
- });
364
+ message: Schema6.String,
365
+ candidates: Schema6.optionalKey(Schema6.Array(Schema6.Struct({ accountId: AccountId, name: Schema6.String })))
366
+ }).annotate({ identifier: "PostIssue" });
363
367
  var schemaIssueFormatter = SchemaIssue.makeFormatterStandardSchemaV1();
364
368
 
365
369
  // ../protocol/src/provider.ts
@@ -461,18 +465,22 @@ var PublishPlacement = Schema8.Literals([
461
465
  var ScheduleOverride = Schema8.Union([ScheduledAt, Schema8.Null]);
462
466
  var DestinationSelection = Schema8.Struct({
463
467
  accountId: AccountId,
464
- placement: PublishPlacement,
468
+ placement: Schema8.optionalKey(PublishPlacement).annotate({
469
+ description: "Omit to select the draft's only destination for this account."
470
+ }),
465
471
  scheduledAt: Schema8.optionalKey(ScheduleOverride),
466
472
  queueId: Schema8.optionalKey(uuid2)
467
473
  }).annotate({ identifier: "DestinationSelection" });
468
474
  var PublishInput = Schema8.Struct({
469
- expectedRevision: PublishRevision,
475
+ expectedRevision: Schema8.optionalKey(PublishRevision).annotate({
476
+ description: "Publish only if the draft is still at this revision. Omit to publish the saved draft as it is."
477
+ }),
470
478
  scheduledAt: Schema8.optionalKey(ScheduledAt),
471
- accountIds: Schema8.optionalKey(Schema8.Array(AccountId).check(Schema8.isMinLength(1), Schema8.isMaxLength(50)).annotate({
479
+ accounts: Schema8.optionalKey(Schema8.Array(AccountId).check(Schema8.isMinLength(1), Schema8.isMaxLength(50)).annotate({
472
480
  description: "Select every draft placement for these accounts. Use targets for exact selection instead."
473
481
  })),
474
482
  targets: Schema8.optionalKey(Schema8.Array(DestinationSelection).check(Schema8.isMinLength(1), Schema8.isMaxLength(50)).annotate({
475
- description: "Select exact draft destinations and optionally override each schedule. Omit accountIds when using targets."
483
+ description: "Select exact draft destinations and optionally override each schedule. Omit accounts when using targets."
476
484
  }))
477
485
  });
478
486
  var PostRef = Schema8.Struct({ postId: PostId });
@@ -576,7 +584,10 @@ var DeliveryIssue = Schema8.Literals([
576
584
  "tiktok_settings_not_allowed",
577
585
  "tiktok_processing_failed",
578
586
  "submission_uncertain",
579
- "confirmation_unavailable"
587
+ "confirmation_unavailable",
588
+ "billing_inactive",
589
+ "spend_cap_reached",
590
+ "insufficient_credit"
580
591
  ]);
581
592
  var FirstCommentStatus = Schema8.Literals([
582
593
  "pending",
@@ -675,6 +686,7 @@ var BillingSubscriptionStatus = Schema9.Literals([
675
686
  var UsageMeter = Schema9.Literals([
676
687
  "confirmed_publish",
677
688
  "x_passthrough",
689
+ "x_read",
678
690
  "managed_ad",
679
691
  "inbox_reply",
680
692
  "automation_run"
@@ -691,10 +703,15 @@ var BillingPlan = Schema9.Struct({
691
703
  monthlyPrice: Schema9.NullOr(Money),
692
704
  annualPrice: Schema9.NullOr(Money),
693
705
  meters: Schema9.Array(BillingPlanMeter),
706
+ xReads: Schema9.Boolean,
707
+ includedXReadMicros: Schema9.NullOr(Schema9.Int),
694
708
  seatsLimit: Schema9.NullOr(Schema9.Int),
695
709
  analyticsRetentionDays: Schema9.Int,
696
710
  whiteLabelOAuth: Schema9.Boolean,
697
- ssoSaml: Schema9.Boolean
711
+ ssoSaml: Schema9.Boolean,
712
+ priorityQueue: Schema9.Boolean,
713
+ adsInsights: Schema9.Boolean,
714
+ adsWrite: Schema9.Boolean
698
715
  }).annotate({ identifier: "BillingPlan" });
699
716
  var BillingPlanList = Schema9.Struct({
700
717
  data: Schema9.Array(BillingPlan)
@@ -730,6 +747,8 @@ var WorkspaceBilling = Schema9.Struct({
730
747
  creditBalance: Money,
731
748
  spendControls: BillingSpendControls,
732
749
  currentPeriod: Schema9.Struct({
750
+ start: Schema9.String,
751
+ end: Schema9.String,
733
752
  meters: Schema9.Array(BillingMeterUsage),
734
753
  totalVariableSpendMicros: Schema9.Int,
735
754
  seatsUsed: Schema9.Int,
@@ -1871,7 +1890,51 @@ var ApiLimits = Schema15.Struct({
1871
1890
  media: MediaLimits,
1872
1891
  rateLimits: RateLimits
1873
1892
  }).annotate({ identifier: "ApiLimits" });
1893
+ var pollOptionCount = { minOptions: 2, maxOptions: 4 };
1894
+ var xPollLimits = {
1895
+ ...pollOptionCount,
1896
+ optionCharacters: 25,
1897
+ minDurationMinutes: 5,
1898
+ maxDurationMinutes: 10080
1899
+ };
1900
+ var linkedinPollLimits = {
1901
+ ...pollOptionCount,
1902
+ questionCharacters: 140,
1903
+ optionCharacters: 30,
1904
+ durations: ["ONE_DAY", "THREE_DAYS", "SEVEN_DAYS", "FOURTEEN_DAYS"]
1905
+ };
1906
+ var xReplySettings = [
1907
+ "following",
1908
+ "mentionedUsers",
1909
+ "subscribers",
1910
+ "verified"
1911
+ ];
1912
+ var xMediaTagLimit = 10;
1913
+ var pollOptionLimits = {
1914
+ minOptions: Schema15.Int,
1915
+ maxOptions: Schema15.Int,
1916
+ optionCharacters: Schema15.Int
1917
+ };
1918
+ var FeedSettingsCapability = Schema15.Struct({
1919
+ poll: Schema15.Union([
1920
+ Schema15.Struct({
1921
+ ...pollOptionLimits,
1922
+ minDurationMinutes: Schema15.Int,
1923
+ maxDurationMinutes: Schema15.Int
1924
+ }),
1925
+ Schema15.Struct({
1926
+ ...pollOptionLimits,
1927
+ questionCharacters: Schema15.Int,
1928
+ durations: Schema15.Array(Schema15.Literals(linkedinPollLimits.durations))
1929
+ })
1930
+ ]),
1931
+ replySettings: Schema15.optionalKey(Schema15.Array(Schema15.Literals(xReplySettings))),
1932
+ maxMediaTags: Schema15.optionalKey(Schema15.Int),
1933
+ placeId: Schema15.optionalKey(Schema15.Boolean),
1934
+ quotePostId: Schema15.optionalKey(Schema15.Boolean)
1935
+ });
1874
1936
  var PlacementCapability = Schema15.Struct({
1937
+ settings: Schema15.optionalKey(FeedSettingsCapability),
1875
1938
  placement: PublishPlacement,
1876
1939
  default: Schema15.Boolean,
1877
1940
  mediaTypes: Schema15.Array(MediaType),
@@ -2242,9 +2305,14 @@ var InstagramAudioSearch = Schema17.Struct({
2242
2305
  import { Schema as Schema28 } from "effect";
2243
2306
 
2244
2307
  // ../protocol/src/publishing.ts
2245
- import { Schema as Schema18 } from "effect";
2308
+ import { Effect, Schema as Schema18 } from "effect";
2246
2309
  var postTextLimit = 128000;
2247
2310
  var threadPostTextLimit = 1250;
2311
+ var blueskyPostMaxBytes = 3000;
2312
+ var graphemeSegmenter = new Intl.Segmenter(undefined, {
2313
+ granularity: "grapheme"
2314
+ });
2315
+ var utf8 = new TextEncoder;
2248
2316
  var redditTitleMaxLength = 300;
2249
2317
  var threadsTextLimit = 500;
2250
2318
  var xArticleTitleMaxLength = 100;
@@ -2352,12 +2420,34 @@ var InstagramStorySettings = Schema18.Struct({
2352
2420
  muteAudio: Schema18.optionalKey(Schema18.Boolean),
2353
2421
  userTags: instagramTags
2354
2422
  }).annotate({ identifier: "InstagramStorySettings" });
2423
+ var blueskyPostText = Schema18.String.check(Schema18.isMinLength(1), Schema18.isMaxLength(blueskyPostMaxBytes));
2355
2424
  var BlueskyFeedSettings = Schema18.Struct({
2356
- firstComment: Schema18.optionalKey(Schema18.String.check(Schema18.isMinLength(1), Schema18.isMaxLength(300))),
2357
- thread: Schema18.optionalKey(Schema18.Array(Schema18.String.check(Schema18.isMinLength(1), Schema18.isMaxLength(300))).check(Schema18.isMaxLength(24))),
2425
+ firstComment: Schema18.optionalKey(blueskyPostText),
2426
+ thread: Schema18.optionalKey(Schema18.Array(blueskyPostText).check(Schema18.isMaxLength(24))),
2358
2427
  altText: Schema18.optionalKey(Schema18.String.check(Schema18.isMaxLength(1000)))
2359
2428
  }).annotate({ identifier: "BlueskyFeedSettings" });
2429
+ var nonblank = Schema18.makeFilter((value) => value.trim().length > 0 || "Supply a nonblank string.", { toJsonSchema: () => ({ pattern: "\\S" }) });
2430
+ function pollText(maximum) {
2431
+ return Schema18.String.check(Schema18.isBetweenCodePoints(1, maximum, {
2432
+ expected: `between 1 and ${maximum} characters`
2433
+ }), nonblank);
2434
+ }
2435
+ function pollOptions({
2436
+ minOptions,
2437
+ maxOptions,
2438
+ optionCharacters
2439
+ }) {
2440
+ return Schema18.Array(pollText(optionCharacters)).check(Schema18.isMinLength(minOptions), Schema18.isMaxLength(maxOptions));
2441
+ }
2442
+ var LinkedInPoll = Schema18.Struct({
2443
+ question: pollText(linkedinPollLimits.questionCharacters),
2444
+ options: pollOptions(linkedinPollLimits),
2445
+ duration: Schema18.Literals(linkedinPollLimits.durations)
2446
+ }).annotate({
2447
+ description: "Organic LinkedIn poll. Include post text and omit media, altText, and documentTitle."
2448
+ });
2360
2449
  var LinkedInFeedSettings = Schema18.Struct({
2450
+ poll: Schema18.optionalKey(LinkedInPoll),
2361
2451
  firstComment: Schema18.optionalKey(text),
2362
2452
  thread: Schema18.optionalKey(Schema18.Array(Schema18.String.check(Schema18.isMinLength(1), Schema18.isMaxLength(threadPostTextLimit))).check(Schema18.isMaxLength(24))),
2363
2453
  visibility: Schema18.optionalKey(Schema18.Literals(["PUBLIC", "CONNECTIONS"])),
@@ -2394,6 +2484,7 @@ var YouTubeVideoSettings = Schema18.Struct({
2394
2484
  title: Schema18.String.check(Schema18.isMinLength(1), Schema18.isMaxLength(100)),
2395
2485
  description: Schema18.optionalKey(Schema18.String.check(Schema18.isMaxLength(5000))),
2396
2486
  privacyStatus: Schema18.Literals(["public", "unlisted", "private"]),
2487
+ firstComment: Schema18.optionalKey(text),
2397
2488
  tags: Schema18.optionalKey(Schema18.Array(Schema18.String.check(Schema18.isMaxLength(100))).check(Schema18.isMaxLength(30))),
2398
2489
  categoryId: Schema18.optionalKey(Schema18.String.check(Schema18.isPattern(/^\d{1,3}$/))),
2399
2490
  madeForKids: Schema18.optionalKey(Schema18.Boolean),
@@ -2408,14 +2499,66 @@ var XArticleDraftSettings = Schema18.Struct({
2408
2499
  title: Schema18.String.check(Schema18.isMinLength(1), Schema18.isMaxLength(xArticleTitleMaxLength)),
2409
2500
  content: Schema18.String.check(Schema18.isMinLength(1), Schema18.isMaxLength(xArticleContentMaxLength))
2410
2501
  }).annotate({ identifier: "XArticleDraftSettings" });
2502
+ var XPoll = Schema18.Struct({
2503
+ options: pollOptions(xPollLimits),
2504
+ durationMinutes: Schema18.Number.check(Schema18.isInt({ expected: "an integer number of minutes" }), Schema18.isBetween({
2505
+ minimum: xPollLimits.minDurationMinutes,
2506
+ maximum: xPollLimits.maxDurationMinutes
2507
+ }, {
2508
+ expected: `between ${xPollLimits.minDurationMinutes} and ${xPollLimits.maxDurationMinutes} minutes`
2509
+ }))
2510
+ }).annotate({
2511
+ description: "X poll on the root post. Include post text and omit attachments."
2512
+ });
2513
+ var xPostOptionId = Schema18.String.check(Schema18.isPattern(/^[0-9]{1,19}$/, {
2514
+ expected: "an X ID string of 1 to 19 digits"
2515
+ }));
2411
2516
  var XFeedSettings = Schema18.Struct({
2517
+ poll: Schema18.optionalKey(XPoll),
2518
+ replySettings: Schema18.optionalKey(Schema18.Literals(xReplySettings).annotate({
2519
+ description: "Who may reply to the root X post. Omit for the provider default."
2520
+ })),
2521
+ quotePostId: Schema18.optionalKey(xPostOptionId.annotate({
2522
+ description: "Native quotes require an X Enterprise app. With PubNio's current app, omit this field and put the X post URL in the text."
2523
+ })),
2524
+ mediaTaggedUserIds: Schema18.optionalKey(Schema18.Array(xPostOptionId).check(Schema18.isMaxLength(xMediaTagLimit)).annotate({
2525
+ description: "X user ID strings to tag on root post photos (JPEG, PNG, or WebP)."
2526
+ })),
2527
+ placeId: Schema18.optionalKey(Schema18.String.check(Schema18.isTrimmed({
2528
+ expected: "an X Place ID without surrounding whitespace"
2529
+ }), nonblank).annotate({
2530
+ description: "Opaque X Place ID such as geo.place_id from a post lookup."
2531
+ })),
2412
2532
  firstComment: Schema18.optionalKey(text),
2413
- thread: Schema18.optionalKey(Schema18.Array(Schema18.String.check(Schema18.isMinLength(1), Schema18.isMaxLength(280))).check(Schema18.isMaxLength(24))),
2533
+ thread: Schema18.optionalKey(Schema18.Array(Schema18.String.check(Schema18.isMinLength(1), Schema18.isMaxLength(threadPostTextLimit))).check(Schema18.isMaxLength(24))),
2414
2534
  article: Schema18.optionalKey(XArticleDraftSettings)
2415
2535
  }).annotate({ identifier: "XFeedSettings" });
2416
- var GoogleBusinessFeedSettings = Schema18.Struct({}).annotate({
2417
- identifier: "GoogleBusinessFeedSettings"
2418
- });
2536
+ var googleBusinessLocalTimeFormat = "Use a valid location-local date and time in YYYY-MM-DDTHH:MM format.";
2537
+ var googleBusinessLocalTime = Schema18.String.check(Schema18.isPattern(/^[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01])T(?:[01][0-9]|2[0-3]):[0-5][0-9]$/, {
2538
+ message: googleBusinessLocalTimeFormat
2539
+ }), Schema18.makeFilter((value) => {
2540
+ const year = Number(value.slice(0, 4));
2541
+ const date = new Date(`${value}:00Z`);
2542
+ return year > 0 && date.getUTCMonth() + 1 === Number(value.slice(5, 7)) && date.getUTCDate() === Number(value.slice(8, 10)) || googleBusinessLocalTimeFormat;
2543
+ })).annotate({ description: googleBusinessLocalTimeFormat });
2544
+ var googleBusinessNonblank = Schema18.String.check(Schema18.isPattern(/\S/, {
2545
+ message: "Enter a string with non-whitespace content."
2546
+ }));
2547
+ var googleBusinessLink = MediaUrl.annotate({
2548
+ description: "Use an HTTPS URL of at most 2,048 characters without embedded credentials.",
2549
+ message: "Use an HTTPS URL of at most 2,048 characters without embedded credentials."
2550
+ });
2551
+ var GoogleBusinessFeedSettings = Schema18.Struct({
2552
+ topicType: Schema18.optionalKey(Schema18.Literals(["standard", "event", "offer"])),
2553
+ title: Schema18.optionalKey(googleBusinessNonblank),
2554
+ startsAt: Schema18.optionalKey(googleBusinessLocalTime),
2555
+ endsAt: Schema18.optionalKey(googleBusinessLocalTime),
2556
+ couponCode: Schema18.optionalKey(googleBusinessNonblank),
2557
+ redeemUrl: Schema18.optionalKey(googleBusinessLink),
2558
+ terms: Schema18.optionalKey(googleBusinessNonblank),
2559
+ callToAction: Schema18.optionalKey(Schema18.Literals(["book", "order", "shop", "learn_more", "sign_up", "call"])),
2560
+ callToActionUrl: Schema18.optionalKey(googleBusinessLink)
2561
+ }).annotate({ identifier: "GoogleBusinessFeedSettings" });
2419
2562
  var ThreadsFeedSettings = Schema18.Struct({
2420
2563
  firstComment: Schema18.optionalKey(Schema18.String.check(Schema18.isMinLength(1), Schema18.isMaxLength(threadsTextLimit))),
2421
2564
  thread: Schema18.optionalKey(Schema18.Array(Schema18.String.check(Schema18.isMinLength(1), Schema18.isMaxLength(threadsTextLimit))).check(Schema18.isMaxLength(24)))
@@ -2594,6 +2737,41 @@ var providerSettings = Schema18.Union([
2594
2737
  TikTokFeedSettings,
2595
2738
  GoogleBusinessFeedSettings
2596
2739
  ]);
2740
+ function settingsShapeErrors(issue, depth = 0) {
2741
+ switch (issue._tag) {
2742
+ case "Composite":
2743
+ return issue.issues.reduce((count, child) => count + settingsShapeErrors(child, depth), 0);
2744
+ case "AnyOf":
2745
+ return issue.issues.length === 0 ? 0 : Math.min(...issue.issues.map((child) => settingsShapeErrors(child, depth)));
2746
+ case "Pointer":
2747
+ return settingsShapeErrors(issue.issue, depth + issue.path.length);
2748
+ case "UnexpectedKey":
2749
+ return depth === 1 ? 3 : 2;
2750
+ case "MissingKey":
2751
+ return depth === 1 ? 4 : 1;
2752
+ default:
2753
+ return 0;
2754
+ }
2755
+ }
2756
+ var createTargetSettings = providerSettings.pipe(Schema18.catchDecoding((issue) => {
2757
+ if (issue._tag !== "AnyOf")
2758
+ return Effect.fail(issue);
2759
+ const [first, ...others] = issue.issues;
2760
+ if (!first)
2761
+ return Effect.fail(issue);
2762
+ let closest = first;
2763
+ let fewest = settingsShapeErrors(first);
2764
+ for (const candidate of others) {
2765
+ if (fewest === 0)
2766
+ break;
2767
+ const errors = settingsShapeErrors(candidate);
2768
+ if (errors < fewest) {
2769
+ closest = candidate;
2770
+ fewest = errors;
2771
+ }
2772
+ }
2773
+ return Effect.fail(closest);
2774
+ }));
2597
2775
  var CreatePostTarget = Schema18.Struct({
2598
2776
  accountId: AccountId,
2599
2777
  provider: Schema18.optionalKey(Provider),
@@ -2605,29 +2783,26 @@ var CreatePostTarget = Schema18.Struct({
2605
2783
  queueId: Schema18.optionalKey(Schema18.String.check(Schema18.isUUID()).annotate({
2606
2784
  description: "Assign this destination to its connected account's schedule queue."
2607
2785
  })),
2608
- settings: Schema18.optionalKey(providerSettings)
2786
+ settings: Schema18.optionalKey(createTargetSettings)
2609
2787
  }).annotate({ identifier: "CreatePostTarget" });
2610
2788
  var postText = Schema18.Trim.check(Schema18.isMaxLength(postTextLimit)).pipe(Schema18.annotateEncoded({
2611
2789
  description: `At most ${postTextLimit} characters after trimming.`
2612
2790
  }));
2613
2791
  var postTargets = Schema18.Array(PublishTarget).check(Schema18.isMaxLength(50));
2614
- var postContent = {
2792
+ var PostContent = Schema18.Struct({
2615
2793
  text: Schema18.optionalKey(postText),
2616
2794
  targets: Schema18.optionalKey(postTargets),
2617
- media: Schema18.optionalKey(MediaInputs)
2618
- };
2619
- var PostContent = Schema18.Struct(postContent).annotate({
2620
- identifier: "PostContent"
2621
- });
2622
- var PostPreflight = Schema18.Struct({
2623
- ...postContent,
2795
+ media: Schema18.optionalKey(MediaInputs),
2624
2796
  scheduledAt: Schema18.optionalKey(ScheduledAt)
2625
- }).annotate({ identifier: "PostPreflight" });
2626
- var CreatePost = Schema18.Struct({
2627
- text: Schema18.optionalKey(postText),
2797
+ }).annotate({ identifier: "PostContent" });
2798
+ var destinationSelectors = {
2628
2799
  platforms: Schema18.optionalKey(Schema18.Array(Provider).check(Schema18.isMinLength(1), Schema18.isMaxLength(publishTargetLimit))),
2629
2800
  accounts: Schema18.optionalKey(Schema18.Array(AccountId).check(Schema18.isMinLength(1), Schema18.isMaxLength(publishTargetLimit))),
2630
- targets: Schema18.optionalKey(Schema18.Array(CreatePostTarget).check(Schema18.isMinLength(1), Schema18.isMaxLength(publishTargetLimit))),
2801
+ targets: Schema18.optionalKey(Schema18.Array(CreatePostTarget).check(Schema18.isMinLength(1), Schema18.isMaxLength(publishTargetLimit)))
2802
+ };
2803
+ var CreatePost = Schema18.Struct({
2804
+ text: Schema18.optionalKey(postText),
2805
+ ...destinationSelectors,
2631
2806
  media: Schema18.optionalKey(MediaInputs),
2632
2807
  scheduledAt: Schema18.optionalKey(ScheduledAt),
2633
2808
  publishNow: Schema18.optionalKey(Schema18.Boolean),
@@ -2635,12 +2810,18 @@ var CreatePost = Schema18.Struct({
2635
2810
  description: "Save the post as a draft without submitting it. Defaults to false."
2636
2811
  })
2637
2812
  }).annotate({ identifier: "CreatePost" }).annotate({
2638
- description: "Send exactly one selector for a direct post: platforms resolves the single ready account per provider, accounts selects exact account IDs, and targets selects exact destinations. Provider and placement are derived when omitted. publishNow defaults to true when scheduledAt is absent. Set isDraft to true to save a draft without submitting; drafts accept text, media, and targets."
2813
+ description: "Send one selector: platforms, accounts, or targets. scheduledAt is the default time; targets[].scheduledAt overrides it per destination. isDraft saves the same body without submitting."
2639
2814
  });
2640
2815
  var UpdatePost = Schema18.Struct({
2641
- ...postContent,
2816
+ text: Schema18.optionalKey(postText),
2817
+ media: Schema18.optionalKey(MediaInputs),
2818
+ scheduledAt: Schema18.optionalKey(ScheduleOverride),
2819
+ ...destinationSelectors,
2820
+ targets: Schema18.optionalKey(Schema18.Array(CreatePostTarget).check(Schema18.isMaxLength(publishTargetLimit))),
2642
2821
  expectedRevision: Schema18.optionalKey(revision)
2643
- }).annotate({ identifier: "UpdatePost" });
2822
+ }).annotate({ identifier: "UpdatePost" }).annotate({
2823
+ description: "Edit a draft with the same fields as create. scheduledAt sets the default time; null clears it. One selector (platforms, accounts, or targets) replaces the saved targets; an empty targets array removes them."
2824
+ });
2644
2825
  var Post = Schema18.Struct({
2645
2826
  postId: PostId,
2646
2827
  isDraft: Schema18.Boolean,
@@ -2648,6 +2829,9 @@ var Post = Schema18.Struct({
2648
2829
  text: postText,
2649
2830
  media: MediaInputs,
2650
2831
  targets: postTargets,
2832
+ scheduledAt: Schema18.NullOr(ScheduledAt).annotate({
2833
+ description: "The default time for targets without their own scheduledAt. null publishes them when submitted."
2834
+ }),
2651
2835
  deliveries: Schema18.Array(DeliveryStatus),
2652
2836
  status: PostState,
2653
2837
  createdAt: Schema18.String,
@@ -3297,6 +3481,31 @@ var InboxReviewList = Schema21.Struct({
3297
3481
  var InboxUnreadCount = Schema21.Struct({
3298
3482
  unreadCount: Schema21.Int
3299
3483
  }).annotate({ identifier: "InboxUnreadCount" });
3484
+ var InboxUnavailableReason = Schema21.Literals([
3485
+ "provider_subscription_limit",
3486
+ "missing_scopes",
3487
+ "webhook_invalid",
3488
+ "subscription_pending",
3489
+ "plan_required",
3490
+ "insufficient_credit",
3491
+ "spend_cap_reached"
3492
+ ]);
3493
+ var InboxUnavailableState = Schema21.Struct({
3494
+ reason: InboxUnavailableReason,
3495
+ action: Schema21.Literals([
3496
+ "contact_pubnio",
3497
+ "reconnect_account",
3498
+ "wait_for_repair",
3499
+ "upgrade_plan",
3500
+ "add_credit",
3501
+ "raise_spend_cap"
3502
+ ])
3503
+ });
3504
+ var InboxDeliveryGap = Schema21.Struct({
3505
+ from: Schema21.String,
3506
+ to: Schema21.String,
3507
+ action: Schema21.Literal("review_on_x")
3508
+ });
3300
3509
  var InboxChannelCapability = Schema21.Struct({
3301
3510
  resource: InboxResource,
3302
3511
  supported: Schema21.Boolean,
@@ -3309,7 +3518,8 @@ var InboxChannelCapability = Schema21.Struct({
3309
3518
  syncMode: InboxSyncMode,
3310
3519
  backfillDays: Schema21.Int,
3311
3520
  missingScopes: Schema21.Array(Schema21.String),
3312
- missingTasks: Schema21.Array(Schema21.String)
3521
+ missingTasks: Schema21.Array(Schema21.String),
3522
+ unavailable: Schema21.NullOr(InboxUnavailableState)
3313
3523
  }).annotate({ identifier: "InboxChannelCapability" });
3314
3524
  var InboxAccountCapabilities = Schema21.Struct({
3315
3525
  accountId: AccountId,
@@ -3324,6 +3534,7 @@ var InboxAccountCapabilities = Schema21.Struct({
3324
3534
  mentions: InboxChannelCapability,
3325
3535
  replyWindow: InboxReplyWindow,
3326
3536
  lastSyncError: Schema21.NullOr(Schema21.String),
3537
+ deliveryGap: Schema21.NullOr(InboxDeliveryGap),
3327
3538
  checkedAt: Schema21.String
3328
3539
  }).annotate({ identifier: "InboxAccountCapabilities" });
3329
3540
  var InboxCapabilities = Schema21.Struct({
@@ -4236,7 +4447,8 @@ var WorkspaceEventType = Schema26.Literals([
4236
4447
  "billing.credit.topped_up",
4237
4448
  "billing.credit.low",
4238
4449
  "billing.spend_cap.reached",
4239
- "billing.invoice.payment_failed"
4450
+ "billing.invoice.payment_failed",
4451
+ "billing.subscription.duplicate_refunded"
4240
4452
  ]);
4241
4453
  var WorkspaceEventEnvelope = Schema26.Struct({
4242
4454
  id: Schema26.String.check(Schema26.isUUID()),
@@ -4817,6 +5029,15 @@ var WebhookEvent = Schema27.Union([
4817
5029
  hostedInvoiceUrl: Schema27.NullOr(Schema27.String)
4818
5030
  })
4819
5031
  }),
5032
+ Schema27.Struct({
5033
+ ...envelope,
5034
+ type: Schema27.Literal("billing.subscription.duplicate_refunded"),
5035
+ data: Schema27.Struct({
5036
+ subscriptionId: Schema27.String,
5037
+ amountRefundedMinor: Schema27.Int,
5038
+ currency: Schema27.String
5039
+ })
5040
+ }),
4820
5041
  Schema27.Struct({
4821
5042
  ...envelope,
4822
5043
  type: Schema27.Literal("webhook.test"),
@@ -5000,6 +5221,27 @@ class SeatLimitReached extends HttpApiError.Problem()("SeatLimitReached", {
5000
5221
  }) {
5001
5222
  }
5002
5223
 
5224
+ class PlanRequired extends HttpApiError.Problem()("PlanRequired", {
5225
+ type: "urn:pubnio:problem:plan-required",
5226
+ status: 402,
5227
+ title: "Plan upgrade required"
5228
+ }, {
5229
+ code: Schema28.Literal("plan_required"),
5230
+ entitlement: Schema28.Literals([
5231
+ "adsInsights",
5232
+ "adsWrite",
5233
+ "analyticsHistory"
5234
+ ]),
5235
+ currentPlan: BillingPlanId,
5236
+ minimumPlan: BillingPlanId,
5237
+ fundingUrl: Schema28.String,
5238
+ canManageBilling: Schema28.Boolean,
5239
+ nextAction: Schema28.String,
5240
+ param: Schema28.optionalKey(Schema28.String),
5241
+ earliestDate: Schema28.optionalKey(Schema28.String)
5242
+ }) {
5243
+ }
5244
+
5003
5245
  class AlreadyMember extends HttpApiError.Problem()("AlreadyMember", {
5004
5246
  type: "urn:pubnio:problem:already-member",
5005
5247
  status: 409,
@@ -5189,6 +5431,17 @@ class DestinationAlreadySubmitted extends HttpApiError.Problem()("DestinationAlr
5189
5431
  }) {
5190
5432
  }
5191
5433
 
5434
+ class PostSubmitted extends HttpApiError.Problem()("PostSubmitted", {
5435
+ type: "urn:pubnio:problem:post-submitted",
5436
+ status: 409,
5437
+ title: "Post already submitted"
5438
+ }, {
5439
+ code: Schema28.Literal("post_submitted"),
5440
+ targetIds: Schema28.Array(TargetId),
5441
+ nextAction: Schema28.String
5442
+ }) {
5443
+ }
5444
+
5192
5445
  class DeliveryNotRetryable extends HttpApiError.Problem()("DeliveryNotRetryable", {
5193
5446
  type: "urn:pubnio:problem:delivery-not-retryable",
5194
5447
  status: 409,
@@ -5471,7 +5724,15 @@ class InboxUnsupportedContent extends HttpApiError.Problem()("InboxUnsupportedCo
5471
5724
  capability: ProductCapability
5472
5725
  }) {
5473
5726
  }
5727
+
5728
+ class InboxUnavailable extends HttpApiError.Problem()("InboxUnavailable", {
5729
+ type: "urn:pubnio:problem:inbox-unavailable",
5730
+ status: 409,
5731
+ title: "Inbox unavailable"
5732
+ }, InboxUnavailableState.fields) {
5733
+ }
5474
5734
  var InboxProblems = [
5735
+ InboxUnavailable,
5475
5736
  InboxReplyWindowClosed,
5476
5737
  InboxTargetChanged,
5477
5738
  InboxSyncInProgress,
@@ -5686,6 +5947,7 @@ var PublishProblems = [
5686
5947
  AttemptChanged,
5687
5948
  IdempotencyConflict,
5688
5949
  DestinationAlreadySubmitted,
5950
+ PostSubmitted,
5689
5951
  DeliveryNotRetryable,
5690
5952
  DeliveryNotReconcilable,
5691
5953
  DeliveryScheduleLocked,
@@ -5712,7 +5974,8 @@ var AdsProblems = [
5712
5974
  AdKillSwitchActive,
5713
5975
  AdOperationNotRetryable,
5714
5976
  AdProviderRejected,
5715
- InvalidAdRequest
5977
+ InvalidAdRequest,
5978
+ PlanRequired
5716
5979
  ];
5717
5980
  var SchedulingProblems = [
5718
5981
  QueueNotFound,
@@ -6143,7 +6406,7 @@ import { ProblemDetails } from "effect/http";
6143
6406
  // package.json
6144
6407
  var package_default = {
6145
6408
  name: "@pubnio/sdk",
6146
- version: "0.2.13",
6409
+ version: "0.4.0",
6147
6410
  description: "JavaScript and TypeScript client for the PubNio API",
6148
6411
  type: "module",
6149
6412
  exports: {
@@ -7810,6 +8073,15 @@ var postsCreate = (options) => (options.client ?? client).post({
7810
8073
  ...options.headers
7811
8074
  }
7812
8075
  });
8076
+ var postsValidateBody = (options) => (options.client ?? client).post({
8077
+ security: [{ scheme: "bearer", type: "http" }],
8078
+ url: "/api/v1/posts/validate",
8079
+ ...options,
8080
+ headers: {
8081
+ "Content-Type": "application/json",
8082
+ ...options.headers
8083
+ }
8084
+ });
7813
8085
  var postsDelete = (options) => (options.client ?? client).delete({
7814
8086
  security: [{ scheme: "bearer", type: "http" }],
7815
8087
  url: "/api/v1/posts/{postId}",
@@ -8662,7 +8934,7 @@ function createPubNioClient({
8662
8934
  return withIdempotencyKey(idempotencyKey, async () => {
8663
8935
  const body = post;
8664
8936
  if (post.isDraft) {
8665
- return decode(Post, postsCreate({
8937
+ return decode(PostCreated, postsCreate({
8666
8938
  client,
8667
8939
  query: { workspaceId },
8668
8940
  headers: { "idempotency-key": idempotencyKey },
@@ -9347,7 +9619,16 @@ function createPubNioClient({
9347
9619
  query: { workspaceId },
9348
9620
  ...transport()
9349
9621
  })),
9350
- publish: (postId, input) => {
9622
+ validateBody: (input) => {
9623
+ const body = input;
9624
+ return decode(PostValidation, postsValidateBody({
9625
+ client,
9626
+ query: { workspaceId },
9627
+ body,
9628
+ ...transport()
9629
+ }));
9630
+ },
9631
+ publish: (postId, input = {}) => {
9351
9632
  const { idempotencyKey = crypto.randomUUID(), ...publish } = input;
9352
9633
  return withIdempotencyKey(idempotencyKey, async () => {
9353
9634
  const accepted = await decode(PublishAccepted, postsPublish({
@@ -9358,7 +9639,7 @@ function createPubNioClient({
9358
9639
  body: {
9359
9640
  expectedRevision: publish.expectedRevision,
9360
9641
  scheduledAt: publish.scheduledAt,
9361
- accountIds: publish.accountIds && [...publish.accountIds],
9642
+ accounts: publish.accounts && [...publish.accounts],
9362
9643
  targets: publish.targets && [...publish.targets]
9363
9644
  },
9364
9645
  ...transport()