{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/samva-dev/json-schema/samva-dev-extension-version-schema.json",
  "title": "ExtensionVersion",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/samva-dev-extensions-api-openapi.yml#/components/schemas/ExtensionVersion",
  "type": "object",
  "properties": {
    "id": {
      "$ref": "#/$defs/ExtensionVersionId"
    },
    "version": {
      "type": "string"
    },
    "runtime": {
      "type": "string",
      "enum": [
        "hosted",
        "webhook"
      ]
    },
    "bundle": {
      "anyOf": [
        {
          "$ref": "#/$defs/ExtensionBundle"
        },
        {
          "type": "null"
        }
      ]
    },
    "publishedAt": {
      "type": "string"
    },
    "manifest": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9-]{1,62}[a-z0-9]$"
        },
        "displayName": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80,
          "x-samva-string-checks": [
            {
              "id": "effect/schema/isMaxLength",
              "payload": {
                "maxLength": 80
              }
            }
          ]
        },
        "description": {
          "anyOf": [
            {
              "type": "string",
              "maxLength": 500,
              "x-samva-string-checks": [
                {
                  "id": "effect/schema/isMaxLength",
                  "payload": {
                    "maxLength": 500
                  }
                }
              ]
            },
            {
              "type": "null"
            }
          ]
        },
        "version": {
          "type": "string",
          "pattern": "^\\d{1,6}\\.\\d{1,6}\\.\\d{1,6}(?:-[0-9A-Za-z.-]{1,64})?$"
        },
        "runtime": {
          "type": "string",
          "enum": [
            "hosted",
            "webhook"
          ]
        },
        "events": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "mailbox.message.received",
              "mailbox.message.sent",
              "mailbox.action.pending_approval",
              "mailbox.action.resolved",
              "mailbox.message.quarantined",
              "mailbox.message.released",
              "mailbox.message.discarded"
            ]
          },
          "minItems": 1
        },
        "permissions": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "read",
              "update",
              "send",
              "quarantine.read"
            ]
          }
        }
      },
      "required": [
        "name",
        "displayName",
        "version",
        "runtime",
        "events",
        "permissions"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "id",
    "version",
    "runtime",
    "bundle",
    "publishedAt",
    "manifest"
  ],
  "additionalProperties": false,
  "$defs": {
    "ExtensionBundle": {
      "type": "object",
      "properties": {
        "sha256": {
          "type": "string"
        },
        "sizeBytes": {
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "sha256",
        "sizeBytes"
      ],
      "additionalProperties": false
    },
    "ExtensionVersionId": {
      "type": "string",
      "pattern": "^extver_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "ExtensionVersionId"
    }
  }
}