{
  "format": "codable-outbound-webhook-contract/v1",
  "title": "Codable outbound webhook contract",
  "description": "Version 1 of the buyer-facing Codable outbound product webhook contract.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "id",
    "type",
    "version",
    "occurred_at",
    "workspace_id",
    "data"
  ],
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid",
      "description": "Stable event ID used for receiver-side deduplication."
    },
    "type": {
      "type": "string",
      "enum": [
        "workspace.updated",
        "workspace.member.joined",
        "workspace.member.removed",
        "support.ticket.created",
        "support.ticket.updated"
      ]
    },
    "version": {
      "const": 1
    },
    "occurred_at": {
      "type": "string",
      "format": "date-time",
      "description": "UTC timestamp with millisecond precision."
    },
    "workspace_id": {
      "type": "string",
      "pattern": "^[0-9A-HJKMNP-TV-Z]{26}$"
    },
    "data": {
      "type": "object",
      "description": "Event-specific object selected by type; see the top-level events catalog."
    }
  },
  "transport": {
      "method": "POST",
      "content_type": "application/json",
      "headers": [
        "X-Webhook-Id",
        "X-Webhook-Timestamp",
        "X-Webhook-Signature"
      ],
      "signature": {
        "algorithm": "HMAC-SHA256",
        "input": "{timestamp}.{event-id}.{raw-body}",
        "encoding": "v1={lowercase-hex}"
      },
      "success_status": "200-299",
      "queue": "webhooks",
      "max_attempts": 8,
      "retry_base_seconds": 30,
      "retry_max_seconds": 3600,
      "retry_jitter_percent": 20
  },
  "events": {
      "workspace.updated": {
        "version": 1,
        "required": [
          "workspace_id",
          "status"
        ],
        "optional": [
          "name",
          "slug"
        ],
        "properties": {
          "workspace_id": "string:ulid",
          "name": "string",
          "slug": "string",
          "status": "string"
        }
      },
      "workspace.member.joined": {
        "version": 1,
        "required": [
          "user_id",
          "role"
        ],
        "optional": [],
        "properties": {
          "user_id": "integer",
          "role": "string"
        }
      },
      "workspace.member.removed": {
        "version": 1,
        "required": [
          "user_id",
          "role"
        ],
        "optional": [],
        "properties": {
          "user_id": "integer",
          "role": "string"
        }
      },
      "support.ticket.created": {
        "version": 1,
        "required": [
          "ticket_id",
          "status"
        ],
        "optional": [
          "reference",
          "priority"
        ],
        "properties": {
          "ticket_id": "string:ulid",
          "reference": "string",
          "status": "string",
          "priority": "string"
        }
      },
      "support.ticket.updated": {
        "version": 1,
        "required": [
          "ticket_id",
          "status"
        ],
        "optional": [
          "reference",
          "priority"
        ],
        "properties": {
          "ticket_id": "string:ulid",
          "reference": "string",
          "status": "string",
          "priority": "string"
        }
      }
  }
}
