{
  "openapi": "3.1.0",
  "info": {
    "title": "Deckboard API",
    "version": "1.0.0",
    "summary": "Run a photoreal split-flap board from another service: notices, QR links, and pushed notices.",
    "description": "Deckboard (https://deckboard.party) shows a split-flap board in a room in the browser. A service holding an account API key can set a board's notices (each with an optional link, shown as a QR code in a frame beside the board), push notices that take the board in turn (for example a paid question on a stream), and read or clear that queue. Human-readable reference: https://deckboard.party/docs/api/ . Markdown: https://deckboard.party/docs/api.md . Call it from a server: an API key is a password.",
    "contact": { "url": "https://deckboard.party/docs/api/" }
  },
  "servers": [{ "url": "https://deckboard.party/api" }],
  "security": [{ "apiKey": [] }],
  "tags": [
    { "name": "Boards", "description": "Read and change the account's boards (up to 3)." },
    { "name": "Queue", "description": "Pushed notices: they take the board one after another, then it returns to its own notices." },
    { "name": "Public", "description": "No key needed." },
    { "name": "Account", "description": "Need a signed-in browser session (not an API key): keys, username, closing the account." }
  ],
  "paths": {
    "/catalog": {
      "get": {
        "tags": ["Public"], "summary": "Sizes, rooms, sounds and the characters the cards carry", "security": [],
        "responses": { "200": { "description": "The catalog", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Catalog" } } } } }
      }
    },
    "/me": {
      "get": {
        "tags": ["Account"], "summary": "The account behind the key or session",
        "responses": { "200": { "description": "The user", "content": { "application/json": { "schema": { "type": "object", "properties": { "user": { "$ref": "#/components/schemas/User" } } } } } }, "401": { "$ref": "#/components/responses/Error" } }
      },
      "patch": {
        "tags": ["Account"], "summary": "Change the username (session only). The account's board addresses change with it.", "security": [{ "session": [] }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "properties": { "username": { "type": "string", "pattern": "^[a-z0-9](?:[a-z0-9-]{1,28}[a-z0-9])$" } } } } } },
        "responses": { "200": { "description": "The user", "content": { "application/json": { "schema": { "type": "object", "properties": { "user": { "$ref": "#/components/schemas/User" } } } } } }, "400": { "$ref": "#/components/responses/Error" }, "409": { "$ref": "#/components/responses/Error" } }
      }
    },
    "/keys": {
      "get": {
        "tags": ["Account"], "summary": "List API keys (session only)", "security": [{ "session": [] }],
        "responses": { "200": { "description": "Keys", "content": { "application/json": { "schema": { "type": "object", "properties": { "keys": { "type": "array", "items": { "$ref": "#/components/schemas/ApiKey" } } } } } } } }
      },
      "post": {
        "tags": ["Account"], "summary": "Make an API key (session only). The raw key is returned once.", "security": [{ "session": [] }],
        "requestBody": { "content": { "application/json": { "schema": { "type": "object", "properties": { "name": { "type": "string", "maxLength": 60 } } } } } },
        "responses": { "201": { "description": "The key and its raw token", "content": { "application/json": { "schema": { "type": "object", "properties": { "key": { "$ref": "#/components/schemas/ApiKey" }, "token": { "type": "string", "pattern": "^dk_[0-9a-f]{40}$" } } } } } }, "409": { "$ref": "#/components/responses/Error" } }
      }
    },
    "/keys/{keyId}": {
      "delete": {
        "tags": ["Account"], "summary": "Revoke an API key (session only)", "security": [{ "session": [] }],
        "parameters": [{ "name": "keyId", "in": "path", "required": true, "schema": { "type": "string", "pattern": "^[0-9a-f]{16}$" } }],
        "responses": { "200": { "$ref": "#/components/responses/Ok" }, "404": { "$ref": "#/components/responses/Error" } }
      }
    },
    "/boards": {
      "get": {
        "tags": ["Boards"], "summary": "List the account's boards",
        "responses": { "200": { "description": "Boards", "content": { "application/json": { "schema": { "type": "object", "properties": { "boards": { "type": "array", "items": { "$ref": "#/components/schemas/OwnedBoard" } }, "max": { "type": "integer" } } } } } }, "401": { "$ref": "#/components/responses/Error" } }
      },
      "post": {
        "tags": ["Boards"], "summary": "Make a board (at most 3 per account)",
        "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BoardPatch" } } } },
        "responses": { "201": { "$ref": "#/components/responses/Board" }, "400": { "$ref": "#/components/responses/Error" }, "409": { "$ref": "#/components/responses/Error" } }
      }
    },
    "/boards/{id}": {
      "parameters": [{ "$ref": "#/components/parameters/BoardId" }],
      "get": { "tags": ["Boards"], "summary": "Read a board", "responses": { "200": { "$ref": "#/components/responses/Board" }, "404": { "$ref": "#/components/responses/Error" } } },
      "patch": {
        "tags": ["Boards"], "summary": "Change a board: any of the fields in BoardPatch",
        "description": "Notices can be set three ways: `notices` (a list of {message|text, link, seconds}), `messages` (+ optional parallel `links` and `seconds`), or a single `message`/`text` (+ `link`, `seconds`), which replaces the list with one notice. `text` word-wraps to the board. `links` and `seconds` lists may also be sent alone, for the current notices. Each notice holds for its own `seconds` (null = `holdSeconds`); `pinned` fixes one notice on the board (null = rotate); `buyLink` sets the buy-screentime QR code.",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BoardPatch" },
          "examples": {
            "notices": { "value": { "notices": [{ "text": "Ask me anything, live Fridays", "link": "https://pod.example/ask", "seconds": 40 }, { "message": ["", "NEXT SHOW", "FRIDAY 8PM"], "link": null, "seconds": null }], "holdSeconds": 15, "pinned": null, "buyLink": "https://pod.example/buy-screentime" } },
            "pin": { "value": { "pinned": 0 } },
            "one": { "value": { "text": "Back in five", "link": null } }
          } } } },
        "responses": { "200": { "$ref": "#/components/responses/Board" }, "400": { "$ref": "#/components/responses/Error" }, "404": { "$ref": "#/components/responses/Error" }, "409": { "$ref": "#/components/responses/Error" } }
      },
      "delete": { "tags": ["Boards"], "summary": "Take a board down (its queue goes with it)", "responses": { "200": { "$ref": "#/components/responses/Ok" }, "404": { "$ref": "#/components/responses/Error" } } }
    },
    "/boards/{id}/push": {
      "parameters": [{ "$ref": "#/components/parameters/BoardId" }],
      "post": {
        "tags": ["Queue"], "summary": "Push a notice: it joins the end of the queue and holds the board for `seconds`",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PushRequest" },
          "example": { "text": "SAM ASKS: WHAT IS THE BEST BOARD?", "link": "https://sam.example/show", "seconds": 45, "ref": "pay_8812" } } } },
        "responses": {
          "201": { "description": "Queued", "content": { "application/json": { "schema": { "type": "object", "properties": { "push": { "$ref": "#/components/schemas/Push" }, "position": { "type": "integer", "description": "0 = next (or showing)" }, "now": { "type": "integer", "description": "server time, Unix ms" } } } } } },
          "400": { "$ref": "#/components/responses/Error" }, "404": { "$ref": "#/components/responses/Error" }, "409": { "$ref": "#/components/responses/Error" }, "429": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/boards/{id}/queue": {
      "parameters": [{ "$ref": "#/components/parameters/BoardId" }],
      "get": { "tags": ["Queue"], "summary": "The pushed notice showing (if any) and those waiting, in order", "responses": { "200": { "$ref": "#/components/responses/Queue" } } },
      "delete": { "tags": ["Queue"], "summary": "Clear the queue (the one showing ends now)", "responses": { "200": { "$ref": "#/components/responses/Queue" } } }
    },
    "/boards/{id}/queue/{pushId}": {
      "parameters": [{ "$ref": "#/components/parameters/BoardId" }, { "name": "pushId", "in": "path", "required": true, "schema": { "type": "string", "pattern": "^p_[0-9a-f]{20}$" } }],
      "delete": { "tags": ["Queue"], "summary": "Remove one pushed notice; the ones after it move up", "responses": { "200": { "$ref": "#/components/responses/Queue" }, "404": { "$ref": "#/components/responses/Error" } } }
    },
    "/boards/{id}/display-link": {
      "parameters": [{ "$ref": "#/components/parameters/BoardId" }],
      "post": {
        "tags": ["Boards"], "summary": "Make (or replace) the board's private screen link; the old one stops working",
        "responses": { "201": { "description": "The raw link, shown once", "content": { "application/json": { "schema": { "type": "object", "properties": { "token": { "type": "string" }, "url": { "type": "string", "format": "uri" } } } } } } }
      },
      "delete": { "tags": ["Boards"], "summary": "Cut the private screen link", "responses": { "200": { "$ref": "#/components/responses/Ok" } } }
    },
    "/u/{owner}/{slug}": {
      "get": {
        "tags": ["Public"], "summary": "A public board by its address (deckboard.party/{owner}/{slug})", "security": [],
        "parameters": [{ "name": "owner", "in": "path", "required": true, "schema": { "type": "string" } }, { "name": "slug", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "The board", "content": { "application/json": { "schema": { "type": "object", "properties": { "board": { "$ref": "#/components/schemas/Board" } } } } } }, "404": { "$ref": "#/components/responses/Error" } }
      }
    },
    "/display/{token}": {
      "get": {
        "tags": ["Public"], "summary": "A board by its private screen link token", "security": [],
        "parameters": [{ "name": "token", "in": "path", "required": true, "schema": { "type": "string", "pattern": "^tv_[0-9a-f]{48}$" } }],
        "responses": { "200": { "description": "The board", "content": { "application/json": { "schema": { "type": "object", "properties": { "board": { "$ref": "#/components/schemas/Board" } } } } } }, "404": { "$ref": "#/components/responses/Error" } }
      }
    }
  },
  "webhooks": {},
  "components": {
    "securitySchemes": {
      "apiKey": { "type": "http", "scheme": "bearer", "bearerFormat": "dk_<40 hex>", "description": "An account API key made at https://deckboard.party/account" },
      "session": { "type": "apiKey", "in": "cookie", "name": "deckboard_session", "description": "A signed-in browser session" }
    },
    "parameters": {
      "BoardId": { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "pattern": "^[0-9a-f]{24}$" } }
    },
    "responses": {
      "Board": { "description": "The board", "content": { "application/json": { "schema": { "type": "object", "properties": { "board": { "$ref": "#/components/schemas/OwnedBoard" } } } } } },
      "Queue": { "description": "The queue", "content": { "application/json": { "schema": { "type": "object", "properties": { "queue": { "type": "array", "items": { "$ref": "#/components/schemas/Push" } }, "now": { "type": "integer" } } } } } },
      "Ok": { "description": "Done", "content": { "application/json": { "schema": { "type": "object", "properties": { "ok": { "const": true } } } } } },
      "Error": { "description": "An error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
    },
    "schemas": {
      "Rows": { "type": "array", "items": { "type": "string" }, "description": "One string per row. Upper-cased and padded to the board's columns on the way in; refused (bad_message) if a row is too long or a character is not on the cards." },
      "Link": { "type": ["string", "null"], "format": "uri", "maxLength": 2000, "description": "An http(s) URL, or null" },
      "Size": { "type": "string", "enum": ["note", "medium", "large"], "description": "note = 3 rows x 15, medium = 6 x 22, large = 8 x 32" },
      "Viewpoint": { "type": "object", "properties": { "pos": { "type": "array", "items": { "type": "number" }, "minItems": 3, "maxItems": 3 }, "target": { "type": "array", "items": { "type": "number" }, "minItems": 3, "maxItems": 3 }, "fov": { "type": "number", "minimum": 5, "maximum": 90 } } },
      "Push": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "pattern": "^p_[0-9a-f]{20}$" },
          "message": { "$ref": "#/components/schemas/Rows" },
          "link": { "$ref": "#/components/schemas/Link" },
          "qr": { "type": ["string", "null"], "description": "What the QR code encodes: the link, or a short deckboard.party/go/... address for links over 48 characters" },
          "ref": { "type": ["string", "null"], "description": "Your own reference, as sent" },
          "startsAt": { "type": "integer", "description": "Unix ms" },
          "endsAt": { "type": "integer", "description": "Unix ms" }
        }
      },
      "PushRequest": {
        "type": "object",
        "properties": {
          "text": { "type": "string", "description": "Free text; wraps at word boundaries; 400 too_long if it does not fit" },
          "message": { "$ref": "#/components/schemas/Rows" },
          "link": { "$ref": "#/components/schemas/Link" },
          "seconds": { "type": "integer", "minimum": 3, "maximum": 3600, "description": "Default: the board's pushSeconds" },
          "ref": { "type": "string", "maxLength": 200 }
        },
        "oneOf": [{ "required": ["text"] }, { "required": ["message"] }]
      },
      "Notice": {
        "type": "object",
        "properties": { "text": { "type": "string" }, "message": { "$ref": "#/components/schemas/Rows" }, "link": { "$ref": "#/components/schemas/Link" },
          "seconds": { "type": ["integer", "null"], "description": "This notice's own hold in seconds, 3-3600 (numbers outside are clamped); null or absent = the board's holdSeconds" } }
      },
      "BoardPatch": {
        "type": "object",
        "properties": {
          "name": { "type": "string", "minLength": 1, "maxLength": 40 },
          "slug": { "type": "string", "pattern": "^[a-z0-9](?:[a-z0-9-]{0,38}[a-z0-9])?$" },
          "public": { "type": "boolean" },
          "size": { "$ref": "#/components/schemas/Size" },
          "scene": { "type": "string", "description": "A room id from /catalog" },
          "sound": { "type": "string", "enum": ["station", "card", "enamel", "glass"] },
          "notices": { "type": "array", "minItems": 1, "maxItems": 12, "items": { "$ref": "#/components/schemas/Notice" } },
          "messages": { "type": "array", "minItems": 1, "maxItems": 12, "items": { "$ref": "#/components/schemas/Rows" } },
          "links": { "type": "array", "items": { "$ref": "#/components/schemas/Link" } },
          "seconds": { "type": "array", "maxItems": 12, "items": { "type": ["integer", "null"] }, "description": "Parallel to the notices: each one's own hold in seconds, or null for holdSeconds (with the single message/text shape, a number)" },
          "message": { "$ref": "#/components/schemas/Rows" },
          "text": { "type": "string" },
          "link": { "$ref": "#/components/schemas/Link" },
          "holdSeconds": { "type": "integer", "minimum": 3, "maximum": 3600, "description": "Default hold for notices without their own seconds" },
          "pinned": { "type": ["integer", "null"], "minimum": 0, "description": "Index of the notice to fix on the board (no rotation; pushes still take over); null = rotate. 400 bad_pinned if it names no notice" },
          "buyLink": { "$ref": "#/components/schemas/Link", "description": "The \"buy screentime\" URL, shown as a second QR code on screens; null removes it" },
          "pushSeconds": { "type": "integer", "minimum": 3, "maximum": 3600 },
          "viewpoint": { "oneOf": [{ "$ref": "#/components/schemas/Viewpoint" }, { "type": "null" }] }
        }
      },
      "Board": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "owner": { "type": "string", "description": "The owner's username" },
          "slug": { "type": "string", "description": "Public address: https://deckboard.party/{owner}/{slug}" },
          "public": { "type": "boolean" },
          "size": { "$ref": "#/components/schemas/Size" },
          "scene": { "type": "string" },
          "sound": { "type": "string" },
          "message": { "$ref": "#/components/schemas/Rows" },
          "messages": { "type": "array", "items": { "$ref": "#/components/schemas/Rows" } },
          "links": { "type": "array", "items": { "$ref": "#/components/schemas/Link" } },
          "qr": { "type": "array", "items": { "type": ["string", "null"] } },
          "holdSeconds": { "type": "integer", "description": "Default seconds each notice holds" },
          "seconds": { "type": "array", "items": { "type": ["integer", "null"] }, "description": "Parallel to messages: each notice's own hold in seconds, or null for holdSeconds" },
          "pinned": { "type": ["integer", "null"], "description": "Index of the notice fixed on the board (no rotation; pushes still take over); null = rotate" },
          "buyLink": { "type": ["string", "null"], "description": "The owner's \"buy screentime\" URL, or null" },
          "buyQr": { "type": ["string", "null"], "description": "What the buy-screentime QR code encodes: the link, or a short deckboard.party/go/... address for links over 48 characters" },
          "pushSeconds": { "type": "integer" },
          "queue": { "type": "array", "items": { "$ref": "#/components/schemas/Push" } },
          "viewpoint": { "oneOf": [{ "$ref": "#/components/schemas/Viewpoint" }, { "type": "null" }] },
          "updatedAt": { "type": "integer", "description": "Unix seconds" },
          "now": { "type": "integer", "description": "Server time, Unix ms" }
        }
      },
      "OwnedBoard": {
        "allOf": [{ "$ref": "#/components/schemas/Board" }, { "type": "object", "properties": { "displayLink": { "type": ["object", "null"], "properties": { "prefix": { "type": "string" } } } } }]
      },
      "User": { "type": "object", "properties": { "id": { "type": "string" }, "email": { "type": "string" }, "username": { "type": "string" }, "emailVerified": { "type": "boolean" }, "created": { "type": "integer" } } },
      "ApiKey": { "type": "object", "properties": { "id": { "type": "string" }, "name": { "type": "string" }, "prefix": { "type": "string" }, "created": { "type": "integer" }, "lastUsed": { "type": ["integer", "null"] } } },
      "Catalog": { "type": "object", "properties": { "sizes": { "type": "array", "items": { "type": "string" } }, "scenes": { "type": "array", "items": { "type": "object" } }, "sounds": { "type": "array", "items": { "type": "object" } }, "drum": { "type": "string", "description": "Every character the cards carry, in drum order (index 0 is the blank)" }, "maxBoards": { "type": "integer" } } },
      "Error": {
        "type": "object",
        "properties": { "error": { "type": "object", "properties": {
          "code": { "type": "string", "examples": ["bad_key", "session_required", "not_found", "bad_message", "too_long", "bad_link", "bad_seconds", "bad_hold", "bad_pinned", "queue_full", "slug_taken", "username_taken", "board_limit", "rate_limited"] },
          "message": { "type": "string" } } } }
      }
    }
  }
}
