@pubnio/sdk 0.3.0 → 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/index.cjs CHANGED
@@ -505,18 +505,22 @@ var PublishPlacement = import_effect8.Schema.Literals([
505
505
  var ScheduleOverride = import_effect8.Schema.Union([ScheduledAt, import_effect8.Schema.Null]);
506
506
  var DestinationSelection = import_effect8.Schema.Struct({
507
507
  accountId: AccountId,
508
- placement: PublishPlacement,
508
+ placement: import_effect8.Schema.optionalKey(PublishPlacement).annotate({
509
+ description: "Omit to select the draft's only destination for this account."
510
+ }),
509
511
  scheduledAt: import_effect8.Schema.optionalKey(ScheduleOverride),
510
512
  queueId: import_effect8.Schema.optionalKey(uuid2)
511
513
  }).annotate({ identifier: "DestinationSelection" });
512
514
  var PublishInput = import_effect8.Schema.Struct({
513
- expectedRevision: PublishRevision,
515
+ expectedRevision: import_effect8.Schema.optionalKey(PublishRevision).annotate({
516
+ description: "Publish only if the draft is still at this revision. Omit to publish the saved draft as it is."
517
+ }),
514
518
  scheduledAt: import_effect8.Schema.optionalKey(ScheduledAt),
515
- accountIds: import_effect8.Schema.optionalKey(import_effect8.Schema.Array(AccountId).check(import_effect8.Schema.isMinLength(1), import_effect8.Schema.isMaxLength(50)).annotate({
519
+ accounts: import_effect8.Schema.optionalKey(import_effect8.Schema.Array(AccountId).check(import_effect8.Schema.isMinLength(1), import_effect8.Schema.isMaxLength(50)).annotate({
516
520
  description: "Select every draft placement for these accounts. Use targets for exact selection instead."
517
521
  })),
518
522
  targets: import_effect8.Schema.optionalKey(import_effect8.Schema.Array(DestinationSelection).check(import_effect8.Schema.isMinLength(1), import_effect8.Schema.isMaxLength(50)).annotate({
519
- description: "Select exact draft destinations and optionally override each schedule. Omit accountIds when using targets."
523
+ description: "Select exact draft destinations and optionally override each schedule. Omit accounts when using targets."
520
524
  }))
521
525
  });
522
526
  var PostRef = import_effect8.Schema.Struct({ postId: PostId });
@@ -2825,23 +2829,20 @@ var postText = import_effect18.Schema.Trim.check(import_effect18.Schema.isMaxLen
2825
2829
  description: `At most ${postTextLimit} characters after trimming.`
2826
2830
  }));
2827
2831
  var postTargets = import_effect18.Schema.Array(PublishTarget).check(import_effect18.Schema.isMaxLength(50));
2828
- var postContent = {
2832
+ var PostContent = import_effect18.Schema.Struct({
2829
2833
  text: import_effect18.Schema.optionalKey(postText),
2830
2834
  targets: import_effect18.Schema.optionalKey(postTargets),
2831
- media: import_effect18.Schema.optionalKey(MediaInputs)
2832
- };
2833
- var PostContent = import_effect18.Schema.Struct(postContent).annotate({
2834
- identifier: "PostContent"
2835
- });
2836
- var PostPreflight = import_effect18.Schema.Struct({
2837
- ...postContent,
2835
+ media: import_effect18.Schema.optionalKey(MediaInputs),
2838
2836
  scheduledAt: import_effect18.Schema.optionalKey(ScheduledAt)
2839
- }).annotate({ identifier: "PostPreflight" });
2840
- var CreatePost = import_effect18.Schema.Struct({
2841
- text: import_effect18.Schema.optionalKey(postText),
2837
+ }).annotate({ identifier: "PostContent" });
2838
+ var destinationSelectors = {
2842
2839
  platforms: import_effect18.Schema.optionalKey(import_effect18.Schema.Array(Provider).check(import_effect18.Schema.isMinLength(1), import_effect18.Schema.isMaxLength(publishTargetLimit))),
2843
2840
  accounts: import_effect18.Schema.optionalKey(import_effect18.Schema.Array(AccountId).check(import_effect18.Schema.isMinLength(1), import_effect18.Schema.isMaxLength(publishTargetLimit))),
2844
- targets: import_effect18.Schema.optionalKey(import_effect18.Schema.Array(CreatePostTarget).check(import_effect18.Schema.isMinLength(1), import_effect18.Schema.isMaxLength(publishTargetLimit))),
2841
+ targets: import_effect18.Schema.optionalKey(import_effect18.Schema.Array(CreatePostTarget).check(import_effect18.Schema.isMinLength(1), import_effect18.Schema.isMaxLength(publishTargetLimit)))
2842
+ };
2843
+ var CreatePost = import_effect18.Schema.Struct({
2844
+ text: import_effect18.Schema.optionalKey(postText),
2845
+ ...destinationSelectors,
2845
2846
  media: import_effect18.Schema.optionalKey(MediaInputs),
2846
2847
  scheduledAt: import_effect18.Schema.optionalKey(ScheduledAt),
2847
2848
  publishNow: import_effect18.Schema.optionalKey(import_effect18.Schema.Boolean),
@@ -2849,12 +2850,18 @@ var CreatePost = import_effect18.Schema.Struct({
2849
2850
  description: "Save the post as a draft without submitting it. Defaults to false."
2850
2851
  })
2851
2852
  }).annotate({ identifier: "CreatePost" }).annotate({
2852
- 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."
2853
+ 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."
2853
2854
  });
2854
2855
  var UpdatePost = import_effect18.Schema.Struct({
2855
- ...postContent,
2856
+ text: import_effect18.Schema.optionalKey(postText),
2857
+ media: import_effect18.Schema.optionalKey(MediaInputs),
2858
+ scheduledAt: import_effect18.Schema.optionalKey(ScheduleOverride),
2859
+ ...destinationSelectors,
2860
+ targets: import_effect18.Schema.optionalKey(import_effect18.Schema.Array(CreatePostTarget).check(import_effect18.Schema.isMaxLength(publishTargetLimit))),
2856
2861
  expectedRevision: import_effect18.Schema.optionalKey(revision)
2857
- }).annotate({ identifier: "UpdatePost" });
2862
+ }).annotate({ identifier: "UpdatePost" }).annotate({
2863
+ 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."
2864
+ });
2858
2865
  var Post = import_effect18.Schema.Struct({
2859
2866
  postId: PostId,
2860
2867
  isDraft: import_effect18.Schema.Boolean,
@@ -2862,6 +2869,9 @@ var Post = import_effect18.Schema.Struct({
2862
2869
  text: postText,
2863
2870
  media: MediaInputs,
2864
2871
  targets: postTargets,
2872
+ scheduledAt: import_effect18.Schema.NullOr(ScheduledAt).annotate({
2873
+ description: "The default time for targets without their own scheduledAt. null publishes them when submitted."
2874
+ }),
2865
2875
  deliveries: import_effect18.Schema.Array(DeliveryStatus),
2866
2876
  status: PostState,
2867
2877
  createdAt: import_effect18.Schema.String,
@@ -5461,6 +5471,17 @@ class DestinationAlreadySubmitted extends import_http_api.HttpApiError.Problem()
5461
5471
  }) {
5462
5472
  }
5463
5473
 
5474
+ class PostSubmitted extends import_http_api.HttpApiError.Problem()("PostSubmitted", {
5475
+ type: "urn:pubnio:problem:post-submitted",
5476
+ status: 409,
5477
+ title: "Post already submitted"
5478
+ }, {
5479
+ code: import_effect28.Schema.Literal("post_submitted"),
5480
+ targetIds: import_effect28.Schema.Array(TargetId),
5481
+ nextAction: import_effect28.Schema.String
5482
+ }) {
5483
+ }
5484
+
5464
5485
  class DeliveryNotRetryable extends import_http_api.HttpApiError.Problem()("DeliveryNotRetryable", {
5465
5486
  type: "urn:pubnio:problem:delivery-not-retryable",
5466
5487
  status: 409,
@@ -5966,6 +5987,7 @@ var PublishProblems = [
5966
5987
  AttemptChanged,
5967
5988
  IdempotencyConflict,
5968
5989
  DestinationAlreadySubmitted,
5990
+ PostSubmitted,
5969
5991
  DeliveryNotRetryable,
5970
5992
  DeliveryNotReconcilable,
5971
5993
  DeliveryScheduleLocked,
@@ -6424,7 +6446,7 @@ var import_http = require("effect/http");
6424
6446
  // package.json
6425
6447
  var package_default = {
6426
6448
  name: "@pubnio/sdk",
6427
- version: "0.3.0",
6449
+ version: "0.4.0",
6428
6450
  description: "JavaScript and TypeScript client for the PubNio API",
6429
6451
  type: "module",
6430
6452
  exports: {
@@ -8952,7 +8974,7 @@ function createPubNioClient({
8952
8974
  return withIdempotencyKey(idempotencyKey, async () => {
8953
8975
  const body = post;
8954
8976
  if (post.isDraft) {
8955
- return decode(Post, postsCreate({
8977
+ return decode(PostCreated, postsCreate({
8956
8978
  client,
8957
8979
  query: { workspaceId },
8958
8980
  headers: { "idempotency-key": idempotencyKey },
@@ -9646,7 +9668,7 @@ function createPubNioClient({
9646
9668
  ...transport()
9647
9669
  }));
9648
9670
  },
9649
- publish: (postId, input) => {
9671
+ publish: (postId, input = {}) => {
9650
9672
  const { idempotencyKey = crypto.randomUUID(), ...publish } = input;
9651
9673
  return withIdempotencyKey(idempotencyKey, async () => {
9652
9674
  const accepted = await decode(PublishAccepted, postsPublish({
@@ -9657,7 +9679,7 @@ function createPubNioClient({
9657
9679
  body: {
9658
9680
  expectedRevision: publish.expectedRevision,
9659
9681
  scheduledAt: publish.scheduledAt,
9660
- accountIds: publish.accountIds && [...publish.accountIds],
9682
+ accounts: publish.accounts && [...publish.accounts],
9661
9683
  targets: publish.targets && [...publish.targets]
9662
9684
  },
9663
9685
  ...transport()