{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/postnext-io/json-schema/postnext-io-publish-envelope-schema.json",
  "title": "PublishEnvelope",
  "x-generated": "2026-11-21",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/postnext-io-openapi.json#/components/schemas/PublishEnvelope",
  "type": "object",
  "properties": {
    "success": {
      "type": "boolean"
    },
    "data": {
      "type": "object",
      "properties": {
        "group": {
          "$ref": "#/$defs/PostGroup"
        },
        "providerPosts": {
          "type": "array",
          "items": {
            "type": "object"
          }
        },
        "queuedProviders": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "The YouTube channels (provider keys) handed to the publishing worker\nand still uploading. YouTube uploads asynchronously, so these are\nneither published nor failed yet.\n"
        },
        "publishStatus": {
          "type": "object",
          "properties": {
            "success": {
              "type": "boolean"
            },
            "partial": {
              "type": "boolean"
            },
            "successfulPublishes": {
              "type": "integer"
            },
            "queuedPublishes": {
              "type": "integer",
              "description": "Channels handed to the publishing worker (YouTube uploads\nasynchronously), counted in neither `successfulPublishes` nor\n`failures`.\n"
            },
            "totalPublishes": {
              "type": "integer"
            },
            "failures": {
              "type": "array",
              "items": {
                "type": "object"
              }
            }
          }
        }
      }
    }
  },
  "$defs": {
    "LegacyPostContent": {
      "type": "object",
      "description": "Single-post content (an object).",
      "properties": {
        "text": {
          "type": "string"
        },
        "mediaUrls": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "uri"
          }
        },
        "mediaType": {
          "type": "string",
          "enum": [
            "IMAGE",
            "VIDEO",
            "GIF",
            "CAROUSEL"
          ]
        },
        "hashtags": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "assetIds": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "instagramPostType": {
          "type": "string",
          "enum": [
            "feed",
            "post",
            "story",
            "reel"
          ]
        }
      }
    },
    "MediaItem": {
      "type": "object",
      "required": [
        "url",
        "type"
      ],
      "properties": {
        "url": {
          "type": "string",
          "format": "uri"
        },
        "type": {
          "type": "string",
          "enum": [
            "IMAGE",
            "VIDEO",
            "GIF"
          ]
        },
        "assetId": {
          "type": "string"
        },
        "thumbnail": {
          "type": "string",
          "format": "uri"
        }
      }
    },
    "PostContent": {
      "description": "Either a single LegacyPostContent object, or an array of ThreadPost for a\nmulti-part thread (twitter/threads).\n",
      "oneOf": [
        {
          "$ref": "#/$defs/LegacyPostContent"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/ThreadPost"
          }
        }
      ]
    },
    "PostGroup": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "description": "Post group uuid."
        },
        "_id": {
          "type": "string",
          "description": "Mongo ObjectId."
        },
        "userId": {
          "type": "string"
        },
        "teamId": {
          "type": "string"
        },
        "title": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "imageUrl": {
          "type": "string",
          "format": "uri"
        },
        "providers": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/ProviderResponse"
          }
        },
        "tags": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "scheduledTime": {
          "type": "string",
          "format": "date-time"
        },
        "status": {
          "$ref": "#/$defs/PostStatus"
        },
        "assigneeId": {
          "type": "string"
        },
        "watchers": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "createdAt": {
          "type": "string",
          "format": "date-time"
        },
        "updatedAt": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "PostStatus": {
      "type": "string",
      "enum": [
        "DRAFT",
        "SCHEDULED",
        "PUBLISHING",
        "PUBLISHED",
        "FAILED",
        "APPROVAL"
      ]
    },
    "ProviderResponse": {
      "type": "object",
      "properties": {
        "providerId": {
          "type": "string"
        },
        "channelName": {
          "type": "string"
        },
        "content": {
          "$ref": "#/$defs/PostContent"
        },
        "firstComment": {
          "type": "string"
        },
        "publishResult": {
          "$ref": "#/$defs/PublishResult"
        }
      }
    },
    "PublishResult": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string"
        },
        "publishedAt": {
          "type": "string",
          "format": "date-time"
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "tweetId": {
          "type": "string"
        },
        "postId": {
          "type": "string"
        },
        "error": {
          "type": "string"
        },
        "attempts": {
          "type": "integer"
        }
      }
    },
    "ThreadPost": {
      "type": "object",
      "required": [
        "order"
      ],
      "properties": {
        "order": {
          "type": "integer",
          "description": "1-based sequential position, no gaps."
        },
        "text": {
          "type": "string"
        },
        "media": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/MediaItem"
          }
        },
        "hashtags": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "assetIds": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    }
  }
}