@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.cjs CHANGED
@@ -187,6 +187,7 @@ __export(exports_sdk_gen, {
187
187
  postsRetry: () => postsRetry,
188
188
  postsUpdate: () => postsUpdate,
189
189
  postsValidate: () => postsValidate,
190
+ postsValidateBody: () => postsValidateBody,
190
191
  profileDeactivate: () => profileDeactivate,
191
192
  profileGet: () => profileGet,
192
193
  profileUpdate: () => profileUpdate,
@@ -396,6 +397,8 @@ var IssueCode = import_effect6.Schema.Literals([
396
397
  "tiktok_upload_required",
397
398
  "tiktok_too_many_mentions",
398
399
  "queue_and_time_conflict",
400
+ "queue_not_found",
401
+ "queue_unavailable",
399
402
  "invalid_field",
400
403
  "account_ambiguous",
401
404
  "unsupported_placement",
@@ -406,8 +409,9 @@ var IssueCode = import_effect6.Schema.Literals([
406
409
  var PostIssue = import_effect6.Schema.Struct({
407
410
  code: IssueCode,
408
411
  path: import_effect6.Schema.Array(import_effect6.Schema.Union([import_effect6.Schema.String, import_effect6.Schema.Int])),
409
- message: import_effect6.Schema.String
410
- });
412
+ message: import_effect6.Schema.String,
413
+ candidates: import_effect6.Schema.optionalKey(import_effect6.Schema.Array(import_effect6.Schema.Struct({ accountId: AccountId, name: import_effect6.Schema.String })))
414
+ }).annotate({ identifier: "PostIssue" });
411
415
  var schemaIssueFormatter = import_effect6.SchemaIssue.makeFormatterStandardSchemaV1();
412
416
 
413
417
  // ../protocol/src/provider.ts
@@ -509,18 +513,22 @@ var PublishPlacement = import_effect8.Schema.Literals([
509
513
  var ScheduleOverride = import_effect8.Schema.Union([ScheduledAt, import_effect8.Schema.Null]);
510
514
  var DestinationSelection = import_effect8.Schema.Struct({
511
515
  accountId: AccountId,
512
- placement: PublishPlacement,
516
+ placement: import_effect8.Schema.optionalKey(PublishPlacement).annotate({
517
+ description: "Omit to select the draft's only destination for this account."
518
+ }),
513
519
  scheduledAt: import_effect8.Schema.optionalKey(ScheduleOverride),
514
520
  queueId: import_effect8.Schema.optionalKey(uuid2)
515
521
  }).annotate({ identifier: "DestinationSelection" });
516
522
  var PublishInput = import_effect8.Schema.Struct({
517
- expectedRevision: PublishRevision,
523
+ expectedRevision: import_effect8.Schema.optionalKey(PublishRevision).annotate({
524
+ description: "Publish only if the draft is still at this revision. Omit to publish the saved draft as it is."
525
+ }),
518
526
  scheduledAt: import_effect8.Schema.optionalKey(ScheduledAt),
519
- accountIds: import_effect8.Schema.optionalKey(import_effect8.Schema.Array(AccountId).check(import_effect8.Schema.isMinLength(1), import_effect8.Schema.isMaxLength(50)).annotate({
527
+ accounts: import_effect8.Schema.optionalKey(import_effect8.Schema.Array(AccountId).check(import_effect8.Schema.isMinLength(1), import_effect8.Schema.isMaxLength(50)).annotate({
520
528
  description: "Select every draft placement for these accounts. Use targets for exact selection instead."
521
529
  })),
522
530
  targets: import_effect8.Schema.optionalKey(import_effect8.Schema.Array(DestinationSelection).check(import_effect8.Schema.isMinLength(1), import_effect8.Schema.isMaxLength(50)).annotate({
523
- description: "Select exact draft destinations and optionally override each schedule. Omit accountIds when using targets."
531
+ description: "Select exact draft destinations and optionally override each schedule. Omit accounts when using targets."
524
532
  }))
525
533
  });
526
534
  var PostRef = import_effect8.Schema.Struct({ postId: PostId });
@@ -624,7 +632,10 @@ var DeliveryIssue = import_effect8.Schema.Literals([
624
632
  "tiktok_settings_not_allowed",
625
633
  "tiktok_processing_failed",
626
634
  "submission_uncertain",
627
- "confirmation_unavailable"
635
+ "confirmation_unavailable",
636
+ "billing_inactive",
637
+ "spend_cap_reached",
638
+ "insufficient_credit"
628
639
  ]);
629
640
  var FirstCommentStatus = import_effect8.Schema.Literals([
630
641
  "pending",
@@ -723,6 +734,7 @@ var BillingSubscriptionStatus = import_effect9.Schema.Literals([
723
734
  var UsageMeter = import_effect9.Schema.Literals([
724
735
  "confirmed_publish",
725
736
  "x_passthrough",
737
+ "x_read",
726
738
  "managed_ad",
727
739
  "inbox_reply",
728
740
  "automation_run"
@@ -739,10 +751,15 @@ var BillingPlan = import_effect9.Schema.Struct({
739
751
  monthlyPrice: import_effect9.Schema.NullOr(Money),
740
752
  annualPrice: import_effect9.Schema.NullOr(Money),
741
753
  meters: import_effect9.Schema.Array(BillingPlanMeter),
754
+ xReads: import_effect9.Schema.Boolean,
755
+ includedXReadMicros: import_effect9.Schema.NullOr(import_effect9.Schema.Int),
742
756
  seatsLimit: import_effect9.Schema.NullOr(import_effect9.Schema.Int),
743
757
  analyticsRetentionDays: import_effect9.Schema.Int,
744
758
  whiteLabelOAuth: import_effect9.Schema.Boolean,
745
- ssoSaml: import_effect9.Schema.Boolean
759
+ ssoSaml: import_effect9.Schema.Boolean,
760
+ priorityQueue: import_effect9.Schema.Boolean,
761
+ adsInsights: import_effect9.Schema.Boolean,
762
+ adsWrite: import_effect9.Schema.Boolean
746
763
  }).annotate({ identifier: "BillingPlan" });
747
764
  var BillingPlanList = import_effect9.Schema.Struct({
748
765
  data: import_effect9.Schema.Array(BillingPlan)
@@ -778,6 +795,8 @@ var WorkspaceBilling = import_effect9.Schema.Struct({
778
795
  creditBalance: Money,
779
796
  spendControls: BillingSpendControls,
780
797
  currentPeriod: import_effect9.Schema.Struct({
798
+ start: import_effect9.Schema.String,
799
+ end: import_effect9.Schema.String,
781
800
  meters: import_effect9.Schema.Array(BillingMeterUsage),
782
801
  totalVariableSpendMicros: import_effect9.Schema.Int,
783
802
  seatsUsed: import_effect9.Schema.Int,
@@ -1919,7 +1938,51 @@ var ApiLimits = import_effect15.Schema.Struct({
1919
1938
  media: MediaLimits,
1920
1939
  rateLimits: RateLimits
1921
1940
  }).annotate({ identifier: "ApiLimits" });
1941
+ var pollOptionCount = { minOptions: 2, maxOptions: 4 };
1942
+ var xPollLimits = {
1943
+ ...pollOptionCount,
1944
+ optionCharacters: 25,
1945
+ minDurationMinutes: 5,
1946
+ maxDurationMinutes: 10080
1947
+ };
1948
+ var linkedinPollLimits = {
1949
+ ...pollOptionCount,
1950
+ questionCharacters: 140,
1951
+ optionCharacters: 30,
1952
+ durations: ["ONE_DAY", "THREE_DAYS", "SEVEN_DAYS", "FOURTEEN_DAYS"]
1953
+ };
1954
+ var xReplySettings = [
1955
+ "following",
1956
+ "mentionedUsers",
1957
+ "subscribers",
1958
+ "verified"
1959
+ ];
1960
+ var xMediaTagLimit = 10;
1961
+ var pollOptionLimits = {
1962
+ minOptions: import_effect15.Schema.Int,
1963
+ maxOptions: import_effect15.Schema.Int,
1964
+ optionCharacters: import_effect15.Schema.Int
1965
+ };
1966
+ var FeedSettingsCapability = import_effect15.Schema.Struct({
1967
+ poll: import_effect15.Schema.Union([
1968
+ import_effect15.Schema.Struct({
1969
+ ...pollOptionLimits,
1970
+ minDurationMinutes: import_effect15.Schema.Int,
1971
+ maxDurationMinutes: import_effect15.Schema.Int
1972
+ }),
1973
+ import_effect15.Schema.Struct({
1974
+ ...pollOptionLimits,
1975
+ questionCharacters: import_effect15.Schema.Int,
1976
+ durations: import_effect15.Schema.Array(import_effect15.Schema.Literals(linkedinPollLimits.durations))
1977
+ })
1978
+ ]),
1979
+ replySettings: import_effect15.Schema.optionalKey(import_effect15.Schema.Array(import_effect15.Schema.Literals(xReplySettings))),
1980
+ maxMediaTags: import_effect15.Schema.optionalKey(import_effect15.Schema.Int),
1981
+ placeId: import_effect15.Schema.optionalKey(import_effect15.Schema.Boolean),
1982
+ quotePostId: import_effect15.Schema.optionalKey(import_effect15.Schema.Boolean)
1983
+ });
1922
1984
  var PlacementCapability = import_effect15.Schema.Struct({
1985
+ settings: import_effect15.Schema.optionalKey(FeedSettingsCapability),
1923
1986
  placement: PublishPlacement,
1924
1987
  default: import_effect15.Schema.Boolean,
1925
1988
  mediaTypes: import_effect15.Schema.Array(MediaType),
@@ -2293,6 +2356,11 @@ var import_effect28 = require("effect");
2293
2356
  var import_effect18 = require("effect");
2294
2357
  var postTextLimit = 128000;
2295
2358
  var threadPostTextLimit = 1250;
2359
+ var blueskyPostMaxBytes = 3000;
2360
+ var graphemeSegmenter = new Intl.Segmenter(undefined, {
2361
+ granularity: "grapheme"
2362
+ });
2363
+ var utf8 = new TextEncoder;
2296
2364
  var redditTitleMaxLength = 300;
2297
2365
  var threadsTextLimit = 500;
2298
2366
  var xArticleTitleMaxLength = 100;
@@ -2400,12 +2468,34 @@ var InstagramStorySettings = import_effect18.Schema.Struct({
2400
2468
  muteAudio: import_effect18.Schema.optionalKey(import_effect18.Schema.Boolean),
2401
2469
  userTags: instagramTags
2402
2470
  }).annotate({ identifier: "InstagramStorySettings" });
2471
+ var blueskyPostText = import_effect18.Schema.String.check(import_effect18.Schema.isMinLength(1), import_effect18.Schema.isMaxLength(blueskyPostMaxBytes));
2403
2472
  var BlueskyFeedSettings = import_effect18.Schema.Struct({
2404
- firstComment: import_effect18.Schema.optionalKey(import_effect18.Schema.String.check(import_effect18.Schema.isMinLength(1), import_effect18.Schema.isMaxLength(300))),
2405
- thread: import_effect18.Schema.optionalKey(import_effect18.Schema.Array(import_effect18.Schema.String.check(import_effect18.Schema.isMinLength(1), import_effect18.Schema.isMaxLength(300))).check(import_effect18.Schema.isMaxLength(24))),
2473
+ firstComment: import_effect18.Schema.optionalKey(blueskyPostText),
2474
+ thread: import_effect18.Schema.optionalKey(import_effect18.Schema.Array(blueskyPostText).check(import_effect18.Schema.isMaxLength(24))),
2406
2475
  altText: import_effect18.Schema.optionalKey(import_effect18.Schema.String.check(import_effect18.Schema.isMaxLength(1000)))
2407
2476
  }).annotate({ identifier: "BlueskyFeedSettings" });
2477
+ var nonblank = import_effect18.Schema.makeFilter((value) => value.trim().length > 0 || "Supply a nonblank string.", { toJsonSchema: () => ({ pattern: "\\S" }) });
2478
+ function pollText(maximum) {
2479
+ return import_effect18.Schema.String.check(import_effect18.Schema.isBetweenCodePoints(1, maximum, {
2480
+ expected: `between 1 and ${maximum} characters`
2481
+ }), nonblank);
2482
+ }
2483
+ function pollOptions({
2484
+ minOptions,
2485
+ maxOptions,
2486
+ optionCharacters
2487
+ }) {
2488
+ return import_effect18.Schema.Array(pollText(optionCharacters)).check(import_effect18.Schema.isMinLength(minOptions), import_effect18.Schema.isMaxLength(maxOptions));
2489
+ }
2490
+ var LinkedInPoll = import_effect18.Schema.Struct({
2491
+ question: pollText(linkedinPollLimits.questionCharacters),
2492
+ options: pollOptions(linkedinPollLimits),
2493
+ duration: import_effect18.Schema.Literals(linkedinPollLimits.durations)
2494
+ }).annotate({
2495
+ description: "Organic LinkedIn poll. Include post text and omit media, altText, and documentTitle."
2496
+ });
2408
2497
  var LinkedInFeedSettings = import_effect18.Schema.Struct({
2498
+ poll: import_effect18.Schema.optionalKey(LinkedInPoll),
2409
2499
  firstComment: import_effect18.Schema.optionalKey(text),
2410
2500
  thread: import_effect18.Schema.optionalKey(import_effect18.Schema.Array(import_effect18.Schema.String.check(import_effect18.Schema.isMinLength(1), import_effect18.Schema.isMaxLength(threadPostTextLimit))).check(import_effect18.Schema.isMaxLength(24))),
2411
2501
  visibility: import_effect18.Schema.optionalKey(import_effect18.Schema.Literals(["PUBLIC", "CONNECTIONS"])),
@@ -2442,6 +2532,7 @@ var YouTubeVideoSettings = import_effect18.Schema.Struct({
2442
2532
  title: import_effect18.Schema.String.check(import_effect18.Schema.isMinLength(1), import_effect18.Schema.isMaxLength(100)),
2443
2533
  description: import_effect18.Schema.optionalKey(import_effect18.Schema.String.check(import_effect18.Schema.isMaxLength(5000))),
2444
2534
  privacyStatus: import_effect18.Schema.Literals(["public", "unlisted", "private"]),
2535
+ firstComment: import_effect18.Schema.optionalKey(text),
2445
2536
  tags: import_effect18.Schema.optionalKey(import_effect18.Schema.Array(import_effect18.Schema.String.check(import_effect18.Schema.isMaxLength(100))).check(import_effect18.Schema.isMaxLength(30))),
2446
2537
  categoryId: import_effect18.Schema.optionalKey(import_effect18.Schema.String.check(import_effect18.Schema.isPattern(/^\d{1,3}$/))),
2447
2538
  madeForKids: import_effect18.Schema.optionalKey(import_effect18.Schema.Boolean),
@@ -2456,14 +2547,66 @@ var XArticleDraftSettings = import_effect18.Schema.Struct({
2456
2547
  title: import_effect18.Schema.String.check(import_effect18.Schema.isMinLength(1), import_effect18.Schema.isMaxLength(xArticleTitleMaxLength)),
2457
2548
  content: import_effect18.Schema.String.check(import_effect18.Schema.isMinLength(1), import_effect18.Schema.isMaxLength(xArticleContentMaxLength))
2458
2549
  }).annotate({ identifier: "XArticleDraftSettings" });
2550
+ var XPoll = import_effect18.Schema.Struct({
2551
+ options: pollOptions(xPollLimits),
2552
+ durationMinutes: import_effect18.Schema.Number.check(import_effect18.Schema.isInt({ expected: "an integer number of minutes" }), import_effect18.Schema.isBetween({
2553
+ minimum: xPollLimits.minDurationMinutes,
2554
+ maximum: xPollLimits.maxDurationMinutes
2555
+ }, {
2556
+ expected: `between ${xPollLimits.minDurationMinutes} and ${xPollLimits.maxDurationMinutes} minutes`
2557
+ }))
2558
+ }).annotate({
2559
+ description: "X poll on the root post. Include post text and omit attachments."
2560
+ });
2561
+ var xPostOptionId = import_effect18.Schema.String.check(import_effect18.Schema.isPattern(/^[0-9]{1,19}$/, {
2562
+ expected: "an X ID string of 1 to 19 digits"
2563
+ }));
2459
2564
  var XFeedSettings = import_effect18.Schema.Struct({
2565
+ poll: import_effect18.Schema.optionalKey(XPoll),
2566
+ replySettings: import_effect18.Schema.optionalKey(import_effect18.Schema.Literals(xReplySettings).annotate({
2567
+ description: "Who may reply to the root X post. Omit for the provider default."
2568
+ })),
2569
+ quotePostId: import_effect18.Schema.optionalKey(xPostOptionId.annotate({
2570
+ 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."
2571
+ })),
2572
+ mediaTaggedUserIds: import_effect18.Schema.optionalKey(import_effect18.Schema.Array(xPostOptionId).check(import_effect18.Schema.isMaxLength(xMediaTagLimit)).annotate({
2573
+ description: "X user ID strings to tag on root post photos (JPEG, PNG, or WebP)."
2574
+ })),
2575
+ placeId: import_effect18.Schema.optionalKey(import_effect18.Schema.String.check(import_effect18.Schema.isTrimmed({
2576
+ expected: "an X Place ID without surrounding whitespace"
2577
+ }), nonblank).annotate({
2578
+ description: "Opaque X Place ID such as geo.place_id from a post lookup."
2579
+ })),
2460
2580
  firstComment: import_effect18.Schema.optionalKey(text),
2461
- thread: import_effect18.Schema.optionalKey(import_effect18.Schema.Array(import_effect18.Schema.String.check(import_effect18.Schema.isMinLength(1), import_effect18.Schema.isMaxLength(280))).check(import_effect18.Schema.isMaxLength(24))),
2581
+ thread: import_effect18.Schema.optionalKey(import_effect18.Schema.Array(import_effect18.Schema.String.check(import_effect18.Schema.isMinLength(1), import_effect18.Schema.isMaxLength(threadPostTextLimit))).check(import_effect18.Schema.isMaxLength(24))),
2462
2582
  article: import_effect18.Schema.optionalKey(XArticleDraftSettings)
2463
2583
  }).annotate({ identifier: "XFeedSettings" });
2464
- var GoogleBusinessFeedSettings = import_effect18.Schema.Struct({}).annotate({
2465
- identifier: "GoogleBusinessFeedSettings"
2466
- });
2584
+ var googleBusinessLocalTimeFormat = "Use a valid location-local date and time in YYYY-MM-DDTHH:MM format.";
2585
+ var googleBusinessLocalTime = import_effect18.Schema.String.check(import_effect18.Schema.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]$/, {
2586
+ message: googleBusinessLocalTimeFormat
2587
+ }), import_effect18.Schema.makeFilter((value) => {
2588
+ const year = Number(value.slice(0, 4));
2589
+ const date = new Date(`${value}:00Z`);
2590
+ return year > 0 && date.getUTCMonth() + 1 === Number(value.slice(5, 7)) && date.getUTCDate() === Number(value.slice(8, 10)) || googleBusinessLocalTimeFormat;
2591
+ })).annotate({ description: googleBusinessLocalTimeFormat });
2592
+ var googleBusinessNonblank = import_effect18.Schema.String.check(import_effect18.Schema.isPattern(/\S/, {
2593
+ message: "Enter a string with non-whitespace content."
2594
+ }));
2595
+ var googleBusinessLink = MediaUrl.annotate({
2596
+ description: "Use an HTTPS URL of at most 2,048 characters without embedded credentials.",
2597
+ message: "Use an HTTPS URL of at most 2,048 characters without embedded credentials."
2598
+ });
2599
+ var GoogleBusinessFeedSettings = import_effect18.Schema.Struct({
2600
+ topicType: import_effect18.Schema.optionalKey(import_effect18.Schema.Literals(["standard", "event", "offer"])),
2601
+ title: import_effect18.Schema.optionalKey(googleBusinessNonblank),
2602
+ startsAt: import_effect18.Schema.optionalKey(googleBusinessLocalTime),
2603
+ endsAt: import_effect18.Schema.optionalKey(googleBusinessLocalTime),
2604
+ couponCode: import_effect18.Schema.optionalKey(googleBusinessNonblank),
2605
+ redeemUrl: import_effect18.Schema.optionalKey(googleBusinessLink),
2606
+ terms: import_effect18.Schema.optionalKey(googleBusinessNonblank),
2607
+ callToAction: import_effect18.Schema.optionalKey(import_effect18.Schema.Literals(["book", "order", "shop", "learn_more", "sign_up", "call"])),
2608
+ callToActionUrl: import_effect18.Schema.optionalKey(googleBusinessLink)
2609
+ }).annotate({ identifier: "GoogleBusinessFeedSettings" });
2467
2610
  var ThreadsFeedSettings = import_effect18.Schema.Struct({
2468
2611
  firstComment: import_effect18.Schema.optionalKey(import_effect18.Schema.String.check(import_effect18.Schema.isMinLength(1), import_effect18.Schema.isMaxLength(threadsTextLimit))),
2469
2612
  thread: import_effect18.Schema.optionalKey(import_effect18.Schema.Array(import_effect18.Schema.String.check(import_effect18.Schema.isMinLength(1), import_effect18.Schema.isMaxLength(threadsTextLimit))).check(import_effect18.Schema.isMaxLength(24)))
@@ -2642,6 +2785,41 @@ var providerSettings = import_effect18.Schema.Union([
2642
2785
  TikTokFeedSettings,
2643
2786
  GoogleBusinessFeedSettings
2644
2787
  ]);
2788
+ function settingsShapeErrors(issue, depth = 0) {
2789
+ switch (issue._tag) {
2790
+ case "Composite":
2791
+ return issue.issues.reduce((count, child) => count + settingsShapeErrors(child, depth), 0);
2792
+ case "AnyOf":
2793
+ return issue.issues.length === 0 ? 0 : Math.min(...issue.issues.map((child) => settingsShapeErrors(child, depth)));
2794
+ case "Pointer":
2795
+ return settingsShapeErrors(issue.issue, depth + issue.path.length);
2796
+ case "UnexpectedKey":
2797
+ return depth === 1 ? 3 : 2;
2798
+ case "MissingKey":
2799
+ return depth === 1 ? 4 : 1;
2800
+ default:
2801
+ return 0;
2802
+ }
2803
+ }
2804
+ var createTargetSettings = providerSettings.pipe(import_effect18.Schema.catchDecoding((issue) => {
2805
+ if (issue._tag !== "AnyOf")
2806
+ return import_effect18.Effect.fail(issue);
2807
+ const [first, ...others] = issue.issues;
2808
+ if (!first)
2809
+ return import_effect18.Effect.fail(issue);
2810
+ let closest = first;
2811
+ let fewest = settingsShapeErrors(first);
2812
+ for (const candidate of others) {
2813
+ if (fewest === 0)
2814
+ break;
2815
+ const errors = settingsShapeErrors(candidate);
2816
+ if (errors < fewest) {
2817
+ closest = candidate;
2818
+ fewest = errors;
2819
+ }
2820
+ }
2821
+ return import_effect18.Effect.fail(closest);
2822
+ }));
2645
2823
  var CreatePostTarget = import_effect18.Schema.Struct({
2646
2824
  accountId: AccountId,
2647
2825
  provider: import_effect18.Schema.optionalKey(Provider),
@@ -2653,29 +2831,26 @@ var CreatePostTarget = import_effect18.Schema.Struct({
2653
2831
  queueId: import_effect18.Schema.optionalKey(import_effect18.Schema.String.check(import_effect18.Schema.isUUID()).annotate({
2654
2832
  description: "Assign this destination to its connected account's schedule queue."
2655
2833
  })),
2656
- settings: import_effect18.Schema.optionalKey(providerSettings)
2834
+ settings: import_effect18.Schema.optionalKey(createTargetSettings)
2657
2835
  }).annotate({ identifier: "CreatePostTarget" });
2658
2836
  var postText = import_effect18.Schema.Trim.check(import_effect18.Schema.isMaxLength(postTextLimit)).pipe(import_effect18.Schema.annotateEncoded({
2659
2837
  description: `At most ${postTextLimit} characters after trimming.`
2660
2838
  }));
2661
2839
  var postTargets = import_effect18.Schema.Array(PublishTarget).check(import_effect18.Schema.isMaxLength(50));
2662
- var postContent = {
2840
+ var PostContent = import_effect18.Schema.Struct({
2663
2841
  text: import_effect18.Schema.optionalKey(postText),
2664
2842
  targets: import_effect18.Schema.optionalKey(postTargets),
2665
- media: import_effect18.Schema.optionalKey(MediaInputs)
2666
- };
2667
- var PostContent = import_effect18.Schema.Struct(postContent).annotate({
2668
- identifier: "PostContent"
2669
- });
2670
- var PostPreflight = import_effect18.Schema.Struct({
2671
- ...postContent,
2843
+ media: import_effect18.Schema.optionalKey(MediaInputs),
2672
2844
  scheduledAt: import_effect18.Schema.optionalKey(ScheduledAt)
2673
- }).annotate({ identifier: "PostPreflight" });
2674
- var CreatePost = import_effect18.Schema.Struct({
2675
- text: import_effect18.Schema.optionalKey(postText),
2845
+ }).annotate({ identifier: "PostContent" });
2846
+ var destinationSelectors = {
2676
2847
  platforms: import_effect18.Schema.optionalKey(import_effect18.Schema.Array(Provider).check(import_effect18.Schema.isMinLength(1), import_effect18.Schema.isMaxLength(publishTargetLimit))),
2677
2848
  accounts: import_effect18.Schema.optionalKey(import_effect18.Schema.Array(AccountId).check(import_effect18.Schema.isMinLength(1), import_effect18.Schema.isMaxLength(publishTargetLimit))),
2678
- targets: import_effect18.Schema.optionalKey(import_effect18.Schema.Array(CreatePostTarget).check(import_effect18.Schema.isMinLength(1), import_effect18.Schema.isMaxLength(publishTargetLimit))),
2849
+ targets: import_effect18.Schema.optionalKey(import_effect18.Schema.Array(CreatePostTarget).check(import_effect18.Schema.isMinLength(1), import_effect18.Schema.isMaxLength(publishTargetLimit)))
2850
+ };
2851
+ var CreatePost = import_effect18.Schema.Struct({
2852
+ text: import_effect18.Schema.optionalKey(postText),
2853
+ ...destinationSelectors,
2679
2854
  media: import_effect18.Schema.optionalKey(MediaInputs),
2680
2855
  scheduledAt: import_effect18.Schema.optionalKey(ScheduledAt),
2681
2856
  publishNow: import_effect18.Schema.optionalKey(import_effect18.Schema.Boolean),
@@ -2683,12 +2858,18 @@ var CreatePost = import_effect18.Schema.Struct({
2683
2858
  description: "Save the post as a draft without submitting it. Defaults to false."
2684
2859
  })
2685
2860
  }).annotate({ identifier: "CreatePost" }).annotate({
2686
- 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."
2861
+ 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."
2687
2862
  });
2688
2863
  var UpdatePost = import_effect18.Schema.Struct({
2689
- ...postContent,
2864
+ text: import_effect18.Schema.optionalKey(postText),
2865
+ media: import_effect18.Schema.optionalKey(MediaInputs),
2866
+ scheduledAt: import_effect18.Schema.optionalKey(ScheduleOverride),
2867
+ ...destinationSelectors,
2868
+ targets: import_effect18.Schema.optionalKey(import_effect18.Schema.Array(CreatePostTarget).check(import_effect18.Schema.isMaxLength(publishTargetLimit))),
2690
2869
  expectedRevision: import_effect18.Schema.optionalKey(revision)
2691
- }).annotate({ identifier: "UpdatePost" });
2870
+ }).annotate({ identifier: "UpdatePost" }).annotate({
2871
+ 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."
2872
+ });
2692
2873
  var Post = import_effect18.Schema.Struct({
2693
2874
  postId: PostId,
2694
2875
  isDraft: import_effect18.Schema.Boolean,
@@ -2696,6 +2877,9 @@ var Post = import_effect18.Schema.Struct({
2696
2877
  text: postText,
2697
2878
  media: MediaInputs,
2698
2879
  targets: postTargets,
2880
+ scheduledAt: import_effect18.Schema.NullOr(ScheduledAt).annotate({
2881
+ description: "The default time for targets without their own scheduledAt. null publishes them when submitted."
2882
+ }),
2699
2883
  deliveries: import_effect18.Schema.Array(DeliveryStatus),
2700
2884
  status: PostState,
2701
2885
  createdAt: import_effect18.Schema.String,
@@ -3345,6 +3529,31 @@ var InboxReviewList = import_effect21.Schema.Struct({
3345
3529
  var InboxUnreadCount = import_effect21.Schema.Struct({
3346
3530
  unreadCount: import_effect21.Schema.Int
3347
3531
  }).annotate({ identifier: "InboxUnreadCount" });
3532
+ var InboxUnavailableReason = import_effect21.Schema.Literals([
3533
+ "provider_subscription_limit",
3534
+ "missing_scopes",
3535
+ "webhook_invalid",
3536
+ "subscription_pending",
3537
+ "plan_required",
3538
+ "insufficient_credit",
3539
+ "spend_cap_reached"
3540
+ ]);
3541
+ var InboxUnavailableState = import_effect21.Schema.Struct({
3542
+ reason: InboxUnavailableReason,
3543
+ action: import_effect21.Schema.Literals([
3544
+ "contact_pubnio",
3545
+ "reconnect_account",
3546
+ "wait_for_repair",
3547
+ "upgrade_plan",
3548
+ "add_credit",
3549
+ "raise_spend_cap"
3550
+ ])
3551
+ });
3552
+ var InboxDeliveryGap = import_effect21.Schema.Struct({
3553
+ from: import_effect21.Schema.String,
3554
+ to: import_effect21.Schema.String,
3555
+ action: import_effect21.Schema.Literal("review_on_x")
3556
+ });
3348
3557
  var InboxChannelCapability = import_effect21.Schema.Struct({
3349
3558
  resource: InboxResource,
3350
3559
  supported: import_effect21.Schema.Boolean,
@@ -3357,7 +3566,8 @@ var InboxChannelCapability = import_effect21.Schema.Struct({
3357
3566
  syncMode: InboxSyncMode,
3358
3567
  backfillDays: import_effect21.Schema.Int,
3359
3568
  missingScopes: import_effect21.Schema.Array(import_effect21.Schema.String),
3360
- missingTasks: import_effect21.Schema.Array(import_effect21.Schema.String)
3569
+ missingTasks: import_effect21.Schema.Array(import_effect21.Schema.String),
3570
+ unavailable: import_effect21.Schema.NullOr(InboxUnavailableState)
3361
3571
  }).annotate({ identifier: "InboxChannelCapability" });
3362
3572
  var InboxAccountCapabilities = import_effect21.Schema.Struct({
3363
3573
  accountId: AccountId,
@@ -3372,6 +3582,7 @@ var InboxAccountCapabilities = import_effect21.Schema.Struct({
3372
3582
  mentions: InboxChannelCapability,
3373
3583
  replyWindow: InboxReplyWindow,
3374
3584
  lastSyncError: import_effect21.Schema.NullOr(import_effect21.Schema.String),
3585
+ deliveryGap: import_effect21.Schema.NullOr(InboxDeliveryGap),
3375
3586
  checkedAt: import_effect21.Schema.String
3376
3587
  }).annotate({ identifier: "InboxAccountCapabilities" });
3377
3588
  var InboxCapabilities = import_effect21.Schema.Struct({
@@ -4284,7 +4495,8 @@ var WorkspaceEventType = import_effect26.Schema.Literals([
4284
4495
  "billing.credit.topped_up",
4285
4496
  "billing.credit.low",
4286
4497
  "billing.spend_cap.reached",
4287
- "billing.invoice.payment_failed"
4498
+ "billing.invoice.payment_failed",
4499
+ "billing.subscription.duplicate_refunded"
4288
4500
  ]);
4289
4501
  var WorkspaceEventEnvelope = import_effect26.Schema.Struct({
4290
4502
  id: import_effect26.Schema.String.check(import_effect26.Schema.isUUID()),
@@ -4865,6 +5077,15 @@ var WebhookEvent = import_effect27.Schema.Union([
4865
5077
  hostedInvoiceUrl: import_effect27.Schema.NullOr(import_effect27.Schema.String)
4866
5078
  })
4867
5079
  }),
5080
+ import_effect27.Schema.Struct({
5081
+ ...envelope,
5082
+ type: import_effect27.Schema.Literal("billing.subscription.duplicate_refunded"),
5083
+ data: import_effect27.Schema.Struct({
5084
+ subscriptionId: import_effect27.Schema.String,
5085
+ amountRefundedMinor: import_effect27.Schema.Int,
5086
+ currency: import_effect27.Schema.String
5087
+ })
5088
+ }),
4868
5089
  import_effect27.Schema.Struct({
4869
5090
  ...envelope,
4870
5091
  type: import_effect27.Schema.Literal("webhook.test"),
@@ -5048,6 +5269,27 @@ class SeatLimitReached extends import_http_api.HttpApiError.Problem()("SeatLimit
5048
5269
  }) {
5049
5270
  }
5050
5271
 
5272
+ class PlanRequired extends import_http_api.HttpApiError.Problem()("PlanRequired", {
5273
+ type: "urn:pubnio:problem:plan-required",
5274
+ status: 402,
5275
+ title: "Plan upgrade required"
5276
+ }, {
5277
+ code: import_effect28.Schema.Literal("plan_required"),
5278
+ entitlement: import_effect28.Schema.Literals([
5279
+ "adsInsights",
5280
+ "adsWrite",
5281
+ "analyticsHistory"
5282
+ ]),
5283
+ currentPlan: BillingPlanId,
5284
+ minimumPlan: BillingPlanId,
5285
+ fundingUrl: import_effect28.Schema.String,
5286
+ canManageBilling: import_effect28.Schema.Boolean,
5287
+ nextAction: import_effect28.Schema.String,
5288
+ param: import_effect28.Schema.optionalKey(import_effect28.Schema.String),
5289
+ earliestDate: import_effect28.Schema.optionalKey(import_effect28.Schema.String)
5290
+ }) {
5291
+ }
5292
+
5051
5293
  class AlreadyMember extends import_http_api.HttpApiError.Problem()("AlreadyMember", {
5052
5294
  type: "urn:pubnio:problem:already-member",
5053
5295
  status: 409,
@@ -5237,6 +5479,17 @@ class DestinationAlreadySubmitted extends import_http_api.HttpApiError.Problem()
5237
5479
  }) {
5238
5480
  }
5239
5481
 
5482
+ class PostSubmitted extends import_http_api.HttpApiError.Problem()("PostSubmitted", {
5483
+ type: "urn:pubnio:problem:post-submitted",
5484
+ status: 409,
5485
+ title: "Post already submitted"
5486
+ }, {
5487
+ code: import_effect28.Schema.Literal("post_submitted"),
5488
+ targetIds: import_effect28.Schema.Array(TargetId),
5489
+ nextAction: import_effect28.Schema.String
5490
+ }) {
5491
+ }
5492
+
5240
5493
  class DeliveryNotRetryable extends import_http_api.HttpApiError.Problem()("DeliveryNotRetryable", {
5241
5494
  type: "urn:pubnio:problem:delivery-not-retryable",
5242
5495
  status: 409,
@@ -5519,7 +5772,15 @@ class InboxUnsupportedContent extends import_http_api.HttpApiError.Problem()("In
5519
5772
  capability: ProductCapability
5520
5773
  }) {
5521
5774
  }
5775
+
5776
+ class InboxUnavailable extends import_http_api.HttpApiError.Problem()("InboxUnavailable", {
5777
+ type: "urn:pubnio:problem:inbox-unavailable",
5778
+ status: 409,
5779
+ title: "Inbox unavailable"
5780
+ }, InboxUnavailableState.fields) {
5781
+ }
5522
5782
  var InboxProblems = [
5783
+ InboxUnavailable,
5523
5784
  InboxReplyWindowClosed,
5524
5785
  InboxTargetChanged,
5525
5786
  InboxSyncInProgress,
@@ -5734,6 +5995,7 @@ var PublishProblems = [
5734
5995
  AttemptChanged,
5735
5996
  IdempotencyConflict,
5736
5997
  DestinationAlreadySubmitted,
5998
+ PostSubmitted,
5737
5999
  DeliveryNotRetryable,
5738
6000
  DeliveryNotReconcilable,
5739
6001
  DeliveryScheduleLocked,
@@ -5760,7 +6022,8 @@ var AdsProblems = [
5760
6022
  AdKillSwitchActive,
5761
6023
  AdOperationNotRetryable,
5762
6024
  AdProviderRejected,
5763
- InvalidAdRequest
6025
+ InvalidAdRequest,
6026
+ PlanRequired
5764
6027
  ];
5765
6028
  var SchedulingProblems = [
5766
6029
  QueueNotFound,
@@ -6191,7 +6454,7 @@ var import_http = require("effect/http");
6191
6454
  // package.json
6192
6455
  var package_default = {
6193
6456
  name: "@pubnio/sdk",
6194
- version: "0.2.13",
6457
+ version: "0.4.0",
6195
6458
  description: "JavaScript and TypeScript client for the PubNio API",
6196
6459
  type: "module",
6197
6460
  exports: {
@@ -7858,6 +8121,15 @@ var postsCreate = (options) => (options.client ?? client).post({
7858
8121
  ...options.headers
7859
8122
  }
7860
8123
  });
8124
+ var postsValidateBody = (options) => (options.client ?? client).post({
8125
+ security: [{ scheme: "bearer", type: "http" }],
8126
+ url: "/api/v1/posts/validate",
8127
+ ...options,
8128
+ headers: {
8129
+ "Content-Type": "application/json",
8130
+ ...options.headers
8131
+ }
8132
+ });
7861
8133
  var postsDelete = (options) => (options.client ?? client).delete({
7862
8134
  security: [{ scheme: "bearer", type: "http" }],
7863
8135
  url: "/api/v1/posts/{postId}",
@@ -8710,7 +8982,7 @@ function createPubNioClient({
8710
8982
  return withIdempotencyKey(idempotencyKey, async () => {
8711
8983
  const body = post;
8712
8984
  if (post.isDraft) {
8713
- return decode(Post, postsCreate({
8985
+ return decode(PostCreated, postsCreate({
8714
8986
  client,
8715
8987
  query: { workspaceId },
8716
8988
  headers: { "idempotency-key": idempotencyKey },
@@ -9395,7 +9667,16 @@ function createPubNioClient({
9395
9667
  query: { workspaceId },
9396
9668
  ...transport()
9397
9669
  })),
9398
- publish: (postId, input) => {
9670
+ validateBody: (input) => {
9671
+ const body = input;
9672
+ return decode(PostValidation, postsValidateBody({
9673
+ client,
9674
+ query: { workspaceId },
9675
+ body,
9676
+ ...transport()
9677
+ }));
9678
+ },
9679
+ publish: (postId, input = {}) => {
9399
9680
  const { idempotencyKey = crypto.randomUUID(), ...publish } = input;
9400
9681
  return withIdempotencyKey(idempotencyKey, async () => {
9401
9682
  const accepted = await decode(PublishAccepted, postsPublish({
@@ -9406,7 +9687,7 @@ function createPubNioClient({
9406
9687
  body: {
9407
9688
  expectedRevision: publish.expectedRevision,
9408
9689
  scheduledAt: publish.scheduledAt,
9409
- accountIds: publish.accountIds && [...publish.accountIds],
9690
+ accounts: publish.accounts && [...publish.accounts],
9410
9691
  targets: publish.targets && [...publish.targets]
9411
9692
  },
9412
9693
  ...transport()