{
    "openapi": "3.1.0",
    "info": {
        "title": "Orchestrator panel API",
        "version": "2026.11",
        "description": "The REST API of an Orchestrator panel. Replace the server URL with the address of your panel. Authenticate with a personal access token: Authorization: Bearer orch_…. Documentation: https://orch.digital/docs/api"
    },
    "servers": [
        {
            "url": "https://{panel}",
            "description": "Your Orchestrator panel",
            "variables": {
                "panel": {
                    "default": "panel.example.com",
                    "description": "Host name of your panel"
                }
            }
        }
    ],
    "security": [
        {
            "bearerAuth": []
        }
    ],
    "tags": [
        {
            "name": "Sites",
            "description": "Create, list, update and delete sites, and provision them on a server."
        },
        {
            "name": "Deployments",
            "description": "Start deploys, follow their logs, roll back and inspect releases."
        },
        {
            "name": "Push-to-deploy webhook",
            "description": "The endpoint GitHub calls when you push."
        },
        {
            "name": "Staging and promote",
            "description": "Clone sites, create staging copies and promote a tested commit to production."
        },
        {
            "name": "Presets",
            "description": "Reusable deploy settings and applying them to sites."
        },
        {
            "name": "Configuration files",
            "description": "nginx, .env and PHP-FPM configuration, with version history."
        },
        {
            "name": "Workers and scheduler",
            "description": "Supervisor queue workers and the Laravel scheduler."
        },
        {
            "name": "Maintenance mode",
            "description": "Take a Laravel site down for maintenance and bring it back."
        },
        {
            "name": "Artisan and Composer",
            "description": "Run allowed Artisan commands and manage Composer packages."
        },
        {
            "name": "Queue",
            "description": "Pending and failed queue jobs."
        },
        {
            "name": "File manager",
            "description": "Read and change files inside a site’s folder."
        },
        {
            "name": "Terminal",
            "description": "The site terminal (WebSocket)."
        },
        {
            "name": "Databases and backups",
            "description": "Databases, users, queries, imports, backups and off-site copies."
        },
        {
            "name": "SSL",
            "description": "Let’s Encrypt certificates and hostnames."
        },
        {
            "name": "Logs and errors",
            "description": "Laravel logs and grouped errors."
        },
        {
            "name": "Performance and uptime",
            "description": "Laravel Telescope APM and uptime checks."
        },
        {
            "name": "Status pages and site security",
            "description": "Public status pages, HTTP basic auth and IP rules."
        },
        {
            "name": "Usage",
            "description": "Disk, database and traffic usage per site."
        },
        {
            "name": "Servers",
            "description": "Servers the panel manages, over SSH or with the agent."
        },
        {
            "name": "Fleet",
            "description": "Live metrics, inventory, logs, actions, alert rules and settings of fleet servers."
        },
        {
            "name": "Fleet commands and scripts",
            "description": "Commands on many servers, saved scripts and run history."
        },
        {
            "name": "Fleet live and terminal",
            "description": "WebSockets for live metrics and the server terminal."
        },
        {
            "name": "Fleet agent",
            "description": "Endpoints the monitoring agent and its installer use."
        },
        {
            "name": "DigitalOcean",
            "description": "Control the connected DigitalOcean droplet."
        },
        {
            "name": "Monitoring",
            "description": "Panel host metrics, services, alert rules and the health check."
        },
        {
            "name": "Notifications",
            "description": "The notification bell."
        },
        {
            "name": "Dashboard",
            "description": "Dashboard layouts and directory helpers."
        },
        {
            "name": "System",
            "description": "Packages, firewall, reboots, panel updates and the Doctor."
        },
        {
            "name": "Billing: clients",
            "description": "Clients and their portal links."
        },
        {
            "name": "Billing: plans and subscriptions",
            "description": "Plans and per-site subscriptions."
        },
        {
            "name": "Billing: invoices and payments",
            "description": "Invoices, payments and voiding."
        },
        {
            "name": "Billing: enforcement and reports",
            "description": "The overdue ladder, the daily run, previews and reports."
        },
        {
            "name": "Automation",
            "description": "Outgoing webhooks, automation rules and their logs."
        },
        {
            "name": "AI assistant",
            "description": "AI configuration, chat, explanations and history."
        },
        {
            "name": "Telegram",
            "description": "Telegram bot connection and account linking."
        },
        {
            "name": "Authentication",
            "description": "Log in, your profile and two-factor authentication."
        },
        {
            "name": "Users",
            "description": "Team members, roles and site access."
        },
        {
            "name": "Access tokens",
            "description": "Personal access tokens."
        },
        {
            "name": "Settings",
            "description": "Panel settings and the weekly digest."
        },
        {
            "name": "Audit and AI activity",
            "description": "The audit log and the log of token (AI) requests."
        },
        {
            "name": "Tasks, notes and calendar",
            "description": "Tasks, notes and calendar events."
        },
        {
            "name": "Public",
            "description": "Endpoints that need no login: health, status pages and the client portal."
        },
        {
            "name": "Internal",
            "description": "Loopback-only endpoints. Not reachable from outside the panel host."
        }
    ],
    "paths": {
        "/api/ai/chat": {
            "post": {
                "operationId": "aiChat",
                "summary": "Chat with the assistant",
                "description": "Asks the read-only assistant a question, optionally grounded in a site's context (PHP version, status, last deploy and up to 5 unresolved errors, redacted). Conversations are stored server-side per user: omit conversationId to start a new one, pass it to continue (the last 8 answered turns are replayed). Secrets and email addresses are redacted before anything is sent to the provider.\n\n**Roles:** admin.\n\n- Error bodies: pre-flight refusals (disabled / no key / limit) for a NEW conversation return { error } and the just-created conversation is deleted again; otherwise errors return { error, conversationId, interactionId } (interactionId null when nothing reached the provider).\n\n- conversationId in the reply is null only when the conversation could not be stored (the answer is still valid); interactionId is null when the history row could not be written. title is the conversation title (first ~80 chars of the first question by default).\n\n- The answer is capped at 900 tokens; the provider call times out after 45 s. Every provider request counts toward the daily limit (dailyLimit; 0 = unlimited) per UTC day; the counter is incremented before the check, so refused requests count too.\n\n- All /api/ai routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "AI assistant"
                ],
                "responses": {
                    "200": {
                        "description": "The answer and the conversation it belongs to.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "reply": "Check whether the queue worker is running: supervisorctl status…",
                                    "conversationId": 31,
                                    "title": "Why is the queue on shop.example.com backing up?",
                                    "interactionId": 512,
                                    "model": "gpt-4o-mini"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The assistant is not enabled. — \"AI assistant is disabled. Enable it in Settings → Integrations.\"\n\nNo API key is stored. — \"No AI API key configured.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "AI assistant is disabled. Enable it in Settings → Integrations."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "conversationId does not exist or belongs to another user. — \"Conversation not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Conversation not found"
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "The daily limit is exceeded. — \"Daily AI request limit reached (100). Raise it in Settings → Integrations.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Daily AI request limit reached (100). Raise it in Settings → Integrations."
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The provider call failed: its own error message, \"AI request failed (<status>)\", or \"AI request timed out.\" after 45 s. The body then also carries conversationId and interactionId of the stored failed turn. — \"<provider error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<provider error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "message": {
                                        "type": "string",
                                        "description": "The question. (1–4000 chars)"
                                    },
                                    "siteId": {
                                        "type": "integer",
                                        "description": "Site to use as context (an unknown id is ignored)."
                                    },
                                    "conversationId": {
                                        "type": "integer",
                                        "description": "Your existing conversation to continue. (must belong to the caller)"
                                    },
                                    "history": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Legacy: client-side transcript, only used when no stored conversation is continued (last 10 items). (max 20 items)"
                                    }
                                },
                                "required": [
                                    "message"
                                ]
                            },
                            "example": {
                                "message": "Why is the queue on shop.example.com backing up?",
                                "siteId": 7,
                                "conversationId": 31
                            }
                        }
                    }
                }
            }
        },
        "/api/ai/config": {
            "get": {
                "operationId": "aiConfigGet",
                "summary": "Get AI configuration",
                "description": "Returns the AI assistant configuration and today's usage. The API key is never returned; configured tells whether one is stored.\n\n**Roles:** admin.\n\n- model is the effective model (the provider's default model when none is set, e.g. gpt-4o-mini for openai); baseUrl is the raw stored value (\"\" = provider default https://api.anthropic.com or https://api.openai.com/v1).\n\n- provider is openai unless the stored value is anthropic. usageToday counts provider requests for the current UTC date; dailyLimit 0 = unlimited.\n\n- All /api/ai routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "AI assistant"
                ],
                "responses": {
                    "200": {
                        "description": "Current AI configuration.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "enabled": true,
                                    "provider": "openai",
                                    "model": "gpt-4o-mini",
                                    "baseUrl": "",
                                    "configured": true,
                                    "usageToday": 14,
                                    "dailyLimit": 100
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "patch": {
                "operationId": "aiConfigUpdate",
                "summary": "Update AI configuration",
                "description": "Updates the AI provider settings; only the fields sent are changed. The API key is write-only and stored encrypted.\n\n**Roles:** admin.\n\n- The stored API key cannot be cleared through this endpoint (empty strings are ignored).\n\n- Unknown body fields are removed silently (additionalProperties: false).\n\n- All /api/ai routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "AI assistant"
                ],
                "responses": {
                    "200": {
                        "description": "Confirmation.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Schema validation failure (FST_ERR_VALIDATION; message varies). — \"body/provider must be equal to one of the allowed values\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "body/provider must be equal to one of the allowed values"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "enabled": {
                                        "type": "boolean",
                                        "description": "Turn the assistant on or off."
                                    },
                                    "provider": {
                                        "type": "string",
                                        "description": "Provider API style. openai covers any OpenAI-compatible endpoint (Ollama, LocalAI, groq…). (one of: openai, anthropic)"
                                    },
                                    "model": {
                                        "type": "string",
                                        "description": "Model name; \"\" = provider default. (max 100 chars)"
                                    },
                                    "baseUrl": {
                                        "type": "string",
                                        "description": "API base URL; \"\" = provider default. Trailing slashes are removed when used. (max 300 chars; format not checked)"
                                    },
                                    "apiKey": {
                                        "type": "string",
                                        "description": "Provider API key (write-only, encrypted at rest). (max 300 chars; an empty string is ignored (the stored key is kept))"
                                    },
                                    "dailyLimit": {
                                        "type": "integer",
                                        "description": "Max provider requests per UTC day; 0 = unlimited. (0–100000)"
                                    }
                                }
                            },
                            "example": {
                                "enabled": true,
                                "provider": "openai",
                                "model": "gpt-4o-mini",
                                "apiKey": "sk-ant-example-key",
                                "dailyLimit": 100
                            }
                        }
                    }
                }
            }
        },
        "/api/ai/conversations": {
            "get": {
                "operationId": "aiConversationsList",
                "summary": "List my conversations",
                "description": "Lists the caller's own chat conversations (up to 200), most recently updated first, with the number of stored turns.\n\n**Roles:** admin.\n\n- Only conversations whose userId is the caller are returned (works the same with a personal access token, which acts as its owner).\n\n- All /api/ai routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "AI assistant"
                ],
                "responses": {
                    "200": {
                        "description": "The caller's conversations.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "conversations": [
                                        {
                                            "id": 31,
                                            "title": "Why is the queue on shop.example.com backing up?",
                                            "siteId": 7,
                                            "createdAt": "2026-11-27T10:00:00.000Z",
                                            "updatedAt": "2026-11-27T10:00:00.000Z",
                                            "messages": 4
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/ai/conversations/{id}": {
            "get": {
                "operationId": "aiConversationsGet",
                "summary": "Get a conversation",
                "description": "Returns one of the caller's conversations with its turns, oldest first (the newest 200 turns at most).\n\n**Roles:** admin.\n\n- question is the redacted question without the site-context prefix; a failed turn has response null and error set.\n\n- All /api/ai routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "AI assistant"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Conversation id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The conversation with its turns.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 31,
                                    "title": "Why is the queue on shop.example.com backing up?",
                                    "siteId": 7,
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z",
                                    "turns": [
                                        {
                                            "id": 512,
                                            "createdAt": "2026-11-27T10:00:00.000Z",
                                            "question": "Why is the queue on shop.example.com backing up?",
                                            "response": "Check whether the queue worker is running…",
                                            "error": null,
                                            "model": "gpt-4o-mini",
                                            "siteId": 7,
                                            "siteDomain": "shop.example.com"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No such conversation or it belongs to another user. — \"Conversation not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Conversation not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "patch": {
                "operationId": "aiConversationsRename",
                "summary": "Rename a conversation",
                "description": "Renames one of the caller's conversations. Whitespace runs are collapsed and the title is trimmed.\n\n**Roles:** admin.\n\n- No audit entry is written.\n\n- All /api/ai routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "AI assistant"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Conversation id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Confirmation with the stored title.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "title": "Queue backlog on shop"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The title is only whitespace. — \"Title is required\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Title is required"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No such conversation or it belongs to another user. — \"Conversation not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Conversation not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "title": {
                                        "type": "string",
                                        "description": "New title. (1–120 chars)"
                                    }
                                },
                                "required": [
                                    "title"
                                ]
                            },
                            "example": {
                                "title": "Queue backlog on shop"
                            }
                        }
                    }
                }
            },
            "delete": {
                "operationId": "aiConversationsDelete",
                "summary": "Delete a conversation",
                "description": "Removes one of the caller's conversations from the chat list. Its questions and answers stay in the AI history (detached from the conversation).\n\n**Roles:** admin.\n\n- All /api/ai routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "AI assistant"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Conversation id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Confirmation.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No such conversation or it belongs to another user. — \"Conversation not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Conversation not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/ai/explain-deploy/{deploymentId}": {
            "get": {
                "operationId": "aiExplainDeployGet",
                "summary": "Get stored deploy diagnoses",
                "description": "Returns the stored AI diagnoses of a deployment (newest first, up to 100) and the latest successful one, without calling the provider.\n\n**Roles:** admin.\n\n- explanation is null when there is no successful diagnosis. An unknown deployment id returns { explanation: null, history: [] } (no 404).\n\n- All /api/ai routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "AI assistant"
                ],
                "parameters": [
                    {
                        "name": "deploymentId",
                        "in": "path",
                        "required": true,
                        "description": "Deployment id. (not validated)",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Latest diagnosis and history.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "explanation": "The build failed because composer could not resolve…",
                                    "history": [
                                        {
                                            "id": 121,
                                            "kind": "explain_deploy",
                                            "createdAt": "2026-11-27T10:00:00.000Z",
                                            "userEmail": "ada@example.com",
                                            "provider": "openai",
                                            "model": "gpt-4o-mini",
                                            "durationMs": 4210,
                                            "response": "The build failed because composer could not resolve…",
                                            "error": null
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "aiExplainDeployCreate",
                "summary": "Diagnose a deployment",
                "description": "Asks the AI to diagnose a deployment from the redacted tail of its log (last 6000 chars) plus site, status, branch and commit. Returns the latest stored diagnosis without calling the provider unless force=1.\n\n**Roles:** admin.\n\n- Cached response: { explanation, cached: true, interactionId: <id of the stored answer>, history } with no provider call and no audit. The answer is capped at 800 tokens. No body is read.\n\n- Every provider request counts toward the daily limit (dailyLimit; 0 = unlimited) per UTC day; the counter is incremented before the check, so refused requests count too.\n\n- All /api/ai routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "AI assistant"
                ],
                "parameters": [
                    {
                        "name": "deploymentId",
                        "in": "path",
                        "required": true,
                        "description": "Deployment id. (not validated)",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "force",
                        "in": "query",
                        "required": false,
                        "description": "Set to 1 to diagnose again even when a diagnosis is stored. (only the exact value \"1\" forces)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The diagnosis, whether it came from the history, and the stored history.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "explanation": "The build failed because composer could not resolve…",
                                    "cached": false,
                                    "interactionId": 121,
                                    "history": [
                                        {
                                            "id": 121,
                                            "kind": "explain_deploy",
                                            "createdAt": "2026-11-27T10:00:00.000Z",
                                            "userEmail": "ada@example.com",
                                            "provider": "openai",
                                            "model": "gpt-4o-mini",
                                            "durationMs": 4210,
                                            "response": "The build failed because composer could not resolve…",
                                            "error": null
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The assistant is not enabled. — \"AI assistant is disabled. Enable it in Settings → Integrations.\"\n\nNo API key is stored. — \"No AI API key configured.\"\n\nA new diagnosis is needed and the deployment has no log. — \"This deployment has no log to analyse.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "AI assistant is disabled. Enable it in Settings → Integrations."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No deployment with this id. — \"Deployment not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Deployment not found"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The provider call failed: its own error message, \"AI request failed (<status>)\", or \"AI request timed out.\" after 45 s. — \"<provider error message>\"\n\nThe daily limit is exceeded — this route maps it to 502, not 429. — \"Daily AI request limit reached (100). Raise it in Settings → Integrations.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<provider error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/ai/explain-error/{id}": {
            "get": {
                "operationId": "aiExplainErrorGet",
                "summary": "Get stored error explanations",
                "description": "Returns what the AI has already said about a grouped log error — the cached explanation and every stored explanation (newest first, up to 100) — without calling the provider.\n\n**Roles:** admin.\n\n- explanation is null when the error was never explained. A history read failure yields an empty history rather than an error.\n\n- All /api/ai routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "AI assistant"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Grouped log error id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Cached explanation and history.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "explanation": "Likely cause: the queue worker cannot reach Redis…",
                                    "history": [
                                        {
                                            "id": 120,
                                            "kind": "explain_error",
                                            "createdAt": "2026-11-27T10:00:00.000Z",
                                            "userEmail": "ada@example.com",
                                            "provider": "openai",
                                            "model": "gpt-4o-mini",
                                            "durationMs": 4210,
                                            "response": "Likely cause: the queue worker cannot reach Redis…",
                                            "error": null
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No log error with this id. — \"Error not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Error not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "aiExplainErrorCreate",
                "summary": "Explain a log error",
                "description": "Asks the AI to explain a grouped log error (level, exception class, count, redacted message and sample line) and caches the answer on the error. Returns the cached explanation without calling the provider unless force=1.\n\n**Roles:** admin.\n\n- Cached response: { explanation, cached: true, history } (no interactionId, no provider call, no audit). No body is read.\n\n- Every provider request counts toward the daily limit (dailyLimit; 0 = unlimited) per UTC day; the counter is incremented before the check, so refused requests count too.\n\n- All /api/ai routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "AI assistant"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Grouped log error id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "force",
                        "in": "query",
                        "required": false,
                        "description": "Set to 1 to regenerate even when an explanation is cached. (only the exact value \"1\" forces)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The explanation, whether it came from the cache, and the stored history.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "explanation": "Likely cause: the queue worker cannot reach Redis…",
                                    "cached": false,
                                    "interactionId": 120,
                                    "history": [
                                        {
                                            "id": 120,
                                            "kind": "explain_error",
                                            "createdAt": "2026-11-27T10:00:00.000Z",
                                            "userEmail": "ada@example.com",
                                            "provider": "openai",
                                            "model": "gpt-4o-mini",
                                            "durationMs": 4210,
                                            "response": "Likely cause: the queue worker cannot reach Redis…",
                                            "error": null
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The assistant is not enabled. — \"AI assistant is disabled. Enable it in Settings → Integrations.\"\n\nNo API key is stored. — \"No AI API key configured.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "AI assistant is disabled. Enable it in Settings → Integrations."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No log error with this id. — \"Error not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Error not found"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The provider call failed: its own error message, \"AI request failed (<status>)\", or \"AI request timed out.\" after 45 s. — \"<provider error message>\"\n\nThe daily limit is exceeded — this route maps it to 502, not 429. — \"Daily AI request limit reached (100). Raise it in Settings → Integrations.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<provider error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/ai/history": {
            "get": {
                "operationId": "aiHistoryList",
                "summary": "List AI history",
                "description": "Lists everything the AI was asked across the panel, by any user, newest first, with cursor pagination. Each item carries a short title and a preview of the answer.\n\n**Roles:** admin.\n\n- nextCursor is the id of the last item when more entries exist, otherwise null. Pass it as cursor to get the next page.\n\n- preview is the first 220 chars of the response (null when the call failed; then failed is true); error is also truncated to 220 chars; title falls back to the first 120 chars of the question/prompt.\n\n- All admins see every user's entries. Only the newest ~5000 interactions are retained. The first call per process also backfills explanations created before the history existed.\n\n- All /api/ai routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "AI assistant"
                ],
                "parameters": [
                    {
                        "name": "kind",
                        "in": "query",
                        "required": false,
                        "description": "Only this kind of interaction. (one of: chat, explain_error, explain_deploy, test)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "siteId",
                        "in": "query",
                        "required": false,
                        "description": "Only interactions about this site. (digits only; other values are ignored)",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "q",
                        "in": "query",
                        "required": false,
                        "description": "Text search in title, prompt, response, site domain and error. (trimmed, first 200 chars used)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "logErrorId",
                        "in": "query",
                        "required": false,
                        "description": "Only explanations of this log error. (digits only; other values are ignored)",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "deploymentId",
                        "in": "query",
                        "required": false,
                        "description": "Only diagnoses of this deployment. (digits only; other values are ignored)",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "cursor",
                        "in": "query",
                        "required": false,
                        "description": "nextCursor from the previous page: returns entries with an id lower than this. (digits only; other values are ignored)",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "required": false,
                        "description": "Page size. (default 30, min 1, max 100 (clamped))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "A page of history items and the cursor for the next page.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "items": [
                                        {
                                            "id": 512,
                                            "kind": "chat",
                                            "createdAt": "2026-11-27T10:00:00.000Z",
                                            "userEmail": "ada@example.com",
                                            "siteId": 7,
                                            "siteDomain": "shop.example.com",
                                            "logErrorId": null,
                                            "deploymentId": null,
                                            "conversationId": 31,
                                            "title": "Why is the queue on shop.example.com backing up?",
                                            "preview": "Check whether the queue worker is running…",
                                            "failed": false,
                                            "error": null,
                                            "provider": "openai",
                                            "model": "gpt-4o-mini",
                                            "durationMs": 3920
                                        }
                                    ],
                                    "nextCursor": 512
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "kind is not one of chat, explain_error, explain_deploy, test. — \"Unknown history kind\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Unknown history kind"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/ai/history/{id}": {
            "get": {
                "operationId": "aiHistoryGet",
                "summary": "Get an AI history entry",
                "description": "Returns one stored AI interaction in full (prompt as sent, response or error), plus whether the site, error, deployment and conversation it refers to still exist.\n\n**Roles:** admin.\n\n- conversationOpenable is true only when the conversation still exists and belongs to the caller. prompt is stored already redacted.\n\n- All /api/ai routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "AI assistant"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Interaction id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The full interaction.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 512,
                                    "kind": "chat",
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "userEmail": "ada@example.com",
                                    "siteId": 7,
                                    "siteDomain": "shop.example.com",
                                    "logErrorId": null,
                                    "deploymentId": null,
                                    "conversationId": 31,
                                    "title": "Why is the queue on shop.example.com backing up?",
                                    "prompt": "CONTEXT — site shop.example.com (PHP 8.3), status active. …\n\nQuestion: Why is the queue on shop.example.com backing up?",
                                    "response": "Check whether the queue worker is running…",
                                    "error": null,
                                    "provider": "openai",
                                    "model": "gpt-4o-mini",
                                    "durationMs": 3920,
                                    "siteExists": true,
                                    "errorExists": false,
                                    "deploymentExists": false,
                                    "conversationTitle": "Why is the queue on shop.example.com backing up?",
                                    "conversationOpenable": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No interaction with this id. — \"History entry not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "History entry not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "delete": {
                "operationId": "aiHistoryDelete",
                "summary": "Delete an AI history entry",
                "description": "Permanently deletes one stored AI interaction. Chat entries can only be deleted by the user who asked. Deleting the explanation currently cached on a log error replaces that cache with the newest remaining explanation (or clears it).\n\n**Roles:** admin.\n\n- All /api/ai routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "AI assistant"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Interaction id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Confirmation.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nThe entry is a chat turn of another user. — \"Only the person who asked can delete a chat entry.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No interaction with this id. — \"History entry not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "History entry not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/ai/test": {
            "post": {
                "operationId": "aiTest",
                "summary": "Test the AI connection",
                "description": "Sends a tiny prompt (\"Reply with the single word: OK\", max 5 tokens) to the configured provider to check connectivity and the API key. The attempt is stored in the AI history as kind test.\n\n**Roles:** admin.\n\n- Every provider request counts toward the daily limit (dailyLimit; 0 = unlimited) per UTC day; the counter is incremented before the check, so refused requests count too.\n\n- No body is read. No audit entry is written.\n\n- All /api/ai routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "AI assistant"
                ],
                "responses": {
                    "200": {
                        "description": "The provider's reply.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "reply": "OK"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The assistant is not enabled. — \"AI assistant is disabled. Enable it in Settings → Integrations.\"\n\nNo API key is stored. — \"No AI API key configured.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "AI assistant is disabled. Enable it in Settings → Integrations."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The provider call failed: its own error message, \"AI request failed (<status>)\", or \"AI request timed out.\" after 45 s. — \"<provider error message>\"\n\nThe daily limit is exceeded — this route maps it to 502, not 429. — \"Daily AI request limit reached (100). Raise it in Settings → Integrations.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<provider error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/alerts": {
            "get": {
                "operationId": "alertsList",
                "summary": "List alert rules",
                "description": "Returns all threshold alert rules (panel host and fleet scopes), oldest first.\n\n**Roles:** admin.",
                "tags": [
                    "Monitoring"
                ],
                "responses": {
                    "200": {
                        "description": "All AlertRule rows.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "rules": [
                                        {
                                            "id": 3,
                                            "metric": "disk",
                                            "operator": "gt",
                                            "threshold": 85,
                                            "enabled": true,
                                            "cooldownMins": 30,
                                            "lastTriggeredAt": null,
                                            "createdAt": "2026-11-27T10:00:00.000Z",
                                            "scope": "local",
                                            "serverId": null,
                                            "groupName": null,
                                            "durationSecs": 0
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "alertsCreate",
                "summary": "Create an alert rule",
                "description": "Creates a threshold alert rule. Scope local (the default) watches the panel host and supports cpu, ram, disk and swap only; scopes server, group and all are evaluated by the fleet engine and may also use load, inode and disk_forecast.\n\n**Roles:** admin.\n\n- Rules are created enabled (schema default); enabled cannot be set on create.\n\n- Unknown body fields are removed silently.",
                "tags": [
                    "Monitoring"
                ],
                "responses": {
                    "201": {
                        "description": "The created AlertRule row.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 4,
                                    "metric": "disk",
                                    "operator": "gt",
                                    "threshold": 85,
                                    "enabled": true,
                                    "cooldownMins": 60,
                                    "lastTriggeredAt": null,
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "scope": "server",
                                    "serverId": 2,
                                    "groupName": null,
                                    "durationSecs": 300
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "scope group without a non-empty groupName. — \"Choose a group for this alert.\"\n\nscope server without serverId. — \"Choose a server for this alert.\"\n\nserverId does not match a fleet server. — \"Selected server not found\"\n\nmetric disk_forecast with threshold outside 1–365. — \"The disk forecast threshold must be between 1 and 365 days.\"\n\nmetric load with threshold 0. — \"The load threshold must be between 1 and 10000 (% of CPU cores).\"\n\nscope local with metric load, inode or disk_forecast. — \"The panel host (scope \"local\") supports only the cpu, ram, disk and swap metrics.\"\n\nAny other metric with threshold above 100. — \"The threshold must be between 0 and 100%.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Choose a group for this alert."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "metric": {
                                        "type": "string",
                                        "description": "Metric to watch. (one of: cpu, ram, disk, swap, load, inode, disk_forecast; scope local allows only cpu, ram, disk, swap)"
                                    },
                                    "threshold": {
                                        "type": "integer",
                                        "description": "Threshold value: percent for most metrics, % of CPU cores for load, days for disk_forecast. (schema 0–10000; then disk_forecast 1–365, load 1–10000, all others 0–100)"
                                    },
                                    "operator": {
                                        "type": "string",
                                        "description": "gt fires above the threshold, lt below. (one of: gt, lt; default gt)"
                                    },
                                    "cooldownMins": {
                                        "type": "integer",
                                        "description": "Minimum minutes between two notifications. (1–1440, default 30)"
                                    },
                                    "scope": {
                                        "type": "string",
                                        "description": "What the rule watches. (one of: local, server, group, all; default local)"
                                    },
                                    "serverId": {
                                        "type": "integer",
                                        "description": "Fleet server id; required for scope server, ignored (stored null) otherwise. (integer ≥ 1 or null)"
                                    },
                                    "groupName": {
                                        "type": "string",
                                        "description": "Server group name; required for scope group (trimmed), ignored otherwise. (max 100 chars or null)"
                                    },
                                    "durationSecs": {
                                        "type": "integer",
                                        "description": "How long the condition must hold before firing. Forced to 0 for scope local. (0–86400, default 0)"
                                    }
                                },
                                "required": [
                                    "metric",
                                    "threshold"
                                ]
                            },
                            "example": {
                                "metric": "disk",
                                "operator": "gt",
                                "threshold": 85,
                                "cooldownMins": 60,
                                "scope": "server",
                                "serverId": 2,
                                "durationSecs": 300
                            }
                        }
                    }
                }
            }
        },
        "/api/alerts/{id}": {
            "patch": {
                "operationId": "alertsUpdate",
                "summary": "Update an alert rule",
                "description": "Partially updates a rule; omitted fields keep their stored values and the merged rule is validated with the same rules as on create. Switching scope clears the fields that do not belong to it (serverId outside server, groupName outside group, durationSecs forced to 0 for local).\n\n**Roles:** admin.\n\n- Changing only metric (e.g. to load) re-validates the stored threshold against the new metric's range.",
                "tags": [
                    "Monitoring"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Alert rule id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The updated AlertRule row.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 4,
                                    "metric": "disk",
                                    "operator": "gt",
                                    "threshold": 85,
                                    "enabled": false,
                                    "cooldownMins": 60,
                                    "lastTriggeredAt": null,
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "scope": "server",
                                    "serverId": 2,
                                    "groupName": null,
                                    "durationSecs": 300
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The merged rule is scope group without groupName. — \"Choose a group for this alert.\"\n\nThe merged rule is scope server without serverId. — \"Choose a server for this alert.\"\n\nA changed serverId does not match a fleet server. — \"Selected server not found\"\n\ndisk_forecast threshold outside 1–365. — \"The disk forecast threshold must be between 1 and 365 days.\"\n\nload threshold 0. — \"The load threshold must be between 1 and 10000 (% of CPU cores).\"\n\nThe merged rule is scope local with a fleet-only metric. — \"The panel host (scope \"local\") supports only the cpu, ram, disk and swap metrics.\"\n\nOther metrics with threshold above 100. — \"The threshold must be between 0 and 100%.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Choose a group for this alert."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No rule with this id (or the id is not an integer). — \"Rule not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Rule not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "enabled": {
                                        "type": "boolean",
                                        "description": "Enable or pause the rule."
                                    },
                                    "metric": {
                                        "type": "string",
                                        "description": "Metric to watch. (one of: cpu, ram, disk, swap, load, inode, disk_forecast)"
                                    },
                                    "operator": {
                                        "type": "string",
                                        "description": "Comparison. (one of: gt, lt)"
                                    },
                                    "threshold": {
                                        "type": "integer",
                                        "description": "Threshold value. (schema 0–10000; metric-specific ranges as on create)"
                                    },
                                    "cooldownMins": {
                                        "type": "integer",
                                        "description": "Minutes between notifications. (1–1440)"
                                    },
                                    "scope": {
                                        "type": "string",
                                        "description": "What the rule watches. (one of: local, server, group, all)"
                                    },
                                    "serverId": {
                                        "type": "integer",
                                        "description": "Fleet server id for scope server. (integer ≥ 1 or null)"
                                    },
                                    "groupName": {
                                        "type": "string",
                                        "description": "Group name for scope group. (max 100 chars or null)"
                                    },
                                    "durationSecs": {
                                        "type": "integer",
                                        "description": "Hold time before firing (fleet scopes). (0–86400)"
                                    }
                                }
                            },
                            "example": {
                                "enabled": false
                            }
                        }
                    }
                }
            },
            "delete": {
                "operationId": "alertsDelete",
                "summary": "Delete an alert rule",
                "description": "Deletes an alert rule.\n\n**Roles:** admin.\n\n- Idempotent: an unknown id still returns {\"ok\": true} and an alert.deleted audit entry is written anyway.",
                "tags": [
                    "Monitoring"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Alert rule id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Deleted (or did not exist).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/audit": {
            "get": {
                "operationId": "auditList",
                "summary": "List audit log entries",
                "description": "Returns audit log entries, newest first, with paging and an optional site filter. Each entry includes the email and role of the user who performed the action.\n\n**Roles:** admin, developer, viewer.\n\n- Not admin-only: every authenticated user, viewers included, can read the full audit log of all sites. The siteId filter is not checked against the caller's site grants.\n\n- meta is parsed from its stored JSON string into an object (null when absent). userEmail/userRole are null when the user was deleted or the action had no user.\n\n- There is no query schema: non-numeric siteId/limit/offset values are not rejected cleanly and lead to a 500 error. limit has no lower bound.\n\n- total counts all entries matching the filter.",
                "tags": [
                    "Audit and AI activity"
                ],
                "parameters": [
                    {
                        "name": "siteId",
                        "in": "query",
                        "required": false,
                        "description": "Only entries for this site. (not validated)",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "required": false,
                        "description": "Page size. (default 50, max 200; not validated)",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "offset",
                        "in": "query",
                        "required": false,
                        "description": "Number of entries to skip. (default 0; not validated)",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "A page of audit entries and the total count.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "logs": [
                                        {
                                            "id": 812,
                                            "action": "user.created",
                                            "siteId": null,
                                            "userId": 1,
                                            "meta": {
                                                "email": "grace@example.com",
                                                "role": "developer"
                                            },
                                            "createdAt": "2026-11-27T10:00:00.000Z",
                                            "userEmail": "ada@example.com",
                                            "userRole": "admin"
                                        }
                                    ],
                                    "total": 1,
                                    "limit": 50,
                                    "offset": 0
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/auth/2fa": {
            "delete": {
                "operationId": "auth2faDisable",
                "summary": "Disable two-factor authentication",
                "description": "Turns 2FA off for the current user and deletes the stored TOTP secret. Any active fleet 2FA step-up (elevation) of this user ends immediately.\n\n**Roles:** admin, developer, viewer.\n\n- No current TOTP code or password is required to disable 2FA; the session or access token alone is enough.\n\n- Always succeeds, also when 2FA was not enabled. No audit entry is written.",
                "tags": [
                    "Authentication"
                ],
                "responses": {
                    "200": {
                        "description": "2FA is now disabled.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/auth/2fa/enable": {
            "post": {
                "operationId": "auth2faEnable",
                "summary": "Enable two-factor authentication",
                "description": "Verifies a code from the authenticator app against the pending secret created by GET /api/auth/2fa/setup and turns 2FA on. From then on, login requires a TOTP code.\n\n**Roles:** admin, developer, viewer.\n\n- Accepts one 30-second step of clock drift either way.\n\n- No audit entry is written.",
                "tags": [
                    "Authentication"
                ],
                "responses": {
                    "200": {
                        "description": "2FA is now enabled.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The code does not verify against the stored secret. — \"Invalid code — try again\"\n\nNo TOTP secret is stored for the user. — \"Run /2fa/setup first\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid code — try again"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "totpCode": {
                                        "type": "string",
                                        "description": "Current code from the authenticator app. (6–8 chars)"
                                    }
                                },
                                "required": [
                                    "totpCode"
                                ]
                            },
                            "example": {
                                "totpCode": "492817"
                            }
                        }
                    }
                }
            }
        },
        "/api/auth/2fa/setup": {
            "get": {
                "operationId": "auth2faSetup",
                "summary": "Start two-factor setup",
                "description": "Generates a new TOTP secret for the current user and returns it with a QR code to scan in an authenticator app. 2FA is not enabled yet: confirm with POST /api/auth/2fa/enable.\n\n**Roles:** admin, developer, viewer.\n\n- Although it is a GET, it has a side effect: the new secret is stored (encrypted at rest) as the pending secret, replacing any earlier pending one. Calling it twice invalidates the first QR code.\n\n- The QR code encodes an otpauth:// URL with the account label \"Orchestrator (<email>)\".",
                "tags": [
                    "Authentication"
                ],
                "responses": {
                    "200": {
                        "description": "The base32 secret and a QR code image as a data URL.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "secret": "JBSWY3DPEHPK3PXPJBSWY3DPEHPK3PXP",
                                    "qrDataUrl": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The user already has 2FA enabled. — \"2FA is already enabled — disable it first to set up a new device.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "2FA is already enabled — disable it first to set up a new device."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/auth/login": {
            "post": {
                "operationId": "authLogin",
                "summary": "Log in",
                "description": "Checks an email and password and returns a signed session token (JWT). When the account has two-factor authentication enabled and no totpCode is sent, the response is {\"requiresTOTP\": true} instead of a token; repeat the request with the current 6-digit code in totpCode.\n\n**Rate limit:** 10 per 15 minutes per IP.\n\n- The JWT payload is {userId, email, role}; it expires after JWT_EXPIRES_IN (default \"24h\"). Send it as Authorization: Bearer <token>.\n\n- The role is baked into the JWT at login: a later role change only affects this session after a new login.\n\n- A 2FA challenge returns HTTP 200 with {\"requiresTOTP\": true}, not an error status.\n\n- TOTP verification accepts one 30-second step of clock drift either way. A code used to log in is remembered so it cannot be replayed for the fleet 2FA step-up.\n\n- A bcrypt comparison runs even for unknown emails so response time does not reveal whether an account exists.\n\n- Unknown body fields are removed silently (additionalProperties: false).",
                "tags": [
                    "Authentication"
                ],
                "responses": {
                    "200": {
                        "description": "A session token, or {\"requiresTOTP\": true} when a 2FA code is still needed.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEyfQ.c2lnbmF0dXJl"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "2FA is enabled and the totpCode does not verify. — \"Invalid TOTP code\"\n\nNo account with this email, or the password is wrong. — \"Invalid credentials\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid TOTP code"
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "More than 10 login attempts from this IP within 15 minutes (@fastify/rate-limit default body). — \"Rate limit exceeded, retry in 15 minutes\"\n\nToo many requests — see the Retry-After header. — \"Rate limit exceeded, retry in …\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Rate limit exceeded, retry in 15 minutes"
                                }
                            }
                        }
                    }
                },
                "x-auth": "public",
                "x-roles": [],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": [],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "email": {
                                        "type": "string",
                                        "description": "Account email, matched exactly as stored. (1–254 chars)"
                                    },
                                    "password": {
                                        "type": "string",
                                        "description": "Account password. (1–128 chars)"
                                    },
                                    "totpCode": {
                                        "type": "string",
                                        "description": "Current authenticator code. Needed only when the account has 2FA enabled. (max 8 chars)"
                                    }
                                },
                                "required": [
                                    "email",
                                    "password"
                                ]
                            },
                            "example": {
                                "email": "ada@example.com",
                                "password": "correct-horse-battery",
                                "totpCode": "492817"
                            }
                        }
                    }
                }
            }
        },
        "/api/auth/me": {
            "get": {
                "operationId": "authMeGet",
                "summary": "Get the current user",
                "description": "Returns the account behind the session token or access token used for the request.\n\n**Roles:** admin, developer, viewer.\n\n- locale is null when the user never chose a language.\n\n- If the user was deleted while their JWT is still valid, the response is 200 with a null body.\n\n- The field is named id (the web client's TypeScript type calls it userId, but the API returns id).",
                "tags": [
                    "Authentication"
                ],
                "responses": {
                    "200": {
                        "description": "The current user.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 12,
                                    "email": "ada@example.com",
                                    "totpEnabled": true,
                                    "role": "admin",
                                    "locale": "en"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "patch": {
                "operationId": "authMeUpdate",
                "summary": "Update own preferences",
                "description": "Changes the signed-in user's own preferences. Currently only the UI language (locale) can be changed. Any role may call it.\n\n**Roles:** admin, developer, viewer.\n\n- Only the shape of locale is checked; the set of available languages is defined by the web client.\n\n- An empty body is a no-op that returns the user unchanged. locale cannot be reset to null through this endpoint (null fails validation).\n\n- Unknown body fields are removed silently.",
                "tags": [
                    "Authentication"
                ],
                "responses": {
                    "200": {
                        "description": "The updated user.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 12,
                                    "email": "ada@example.com",
                                    "totpEnabled": true,
                                    "role": "admin",
                                    "locale": "ka"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "locale": {
                                        "type": "string",
                                        "description": "UI language code such as en, ka or pt-BR. (pattern ^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})?$)"
                                    }
                                }
                            },
                            "example": {
                                "locale": "ka"
                            }
                        }
                    }
                }
            }
        },
        "/api/automation/event-types": {
            "get": {
                "operationId": "automationEventTypes",
                "summary": "List event and action types",
                "description": "Returns the catalogue of panel event types (for webhook filters and rule triggers) and the supported rule action types.\n\n**Roles:** admin.\n\n- site.down, site.up and ssl.expiring are listed but no code in apps/api/src currently emits them.\n\n- All /api/automation routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Automation"
                ],
                "responses": {
                    "200": {
                        "description": "Event and action catalogues.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "events": [
                                        "deploy.succeeded",
                                        "deploy.failed",
                                        "site.down",
                                        "site.up",
                                        "ssl.expiring",
                                        "billing.invoice_paid",
                                        "billing.suspended",
                                        "billing.restored",
                                        "fleet.alert",
                                        "fleet.alert_resolved"
                                    ],
                                    "actions": [
                                        "notify",
                                        "telegram",
                                        "webhook"
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/automation/rules": {
            "get": {
                "operationId": "automationRulesList",
                "summary": "List automation rules",
                "description": "Lists automation rules, newest first, with conditions and actionConfig parsed from JSON.\n\n**Roles:** admin.\n\n- Rules run asynchronously (fire-and-forget) when the panel emits an event whose type equals trigger, and only while enabled. Each evaluation is logged as an AutomationRun (newest 100 kept per rule); with dryRun the run records actionTaken \"would <actionType>\".\n\n- Actions: notify creates a panel notification; telegram sends via the configured notification channel; webhook POSTs { event, data: <payload>, at } as JSON to actionConfig.url with a 10-second timeout. No action can change a hosted site.\n\n- Event payload fields usable in conditions/placeholders: deploy.succeeded / deploy.failed → siteId, domain, branch, commit, status, testsPassed, testsFailed, testsTotal; billing.invoice_paid → invoiceId, number, currency, fullyPaid, restored; billing.suspended → siteId, domain, level; billing.restored → invoiceId, subscriptionId; fleet.alert → eventId, serverId, serverName, kind, ruleId, message, value; fleet.alert_resolved → eventId, serverId, serverName, kind, ruleId, message.\n\n- site.down, site.up and ssl.expiring are in the event catalogue but no code in apps/api/src currently emits them.\n\n- All /api/automation routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Automation"
                ],
                "responses": {
                    "200": {
                        "description": "The rules.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "rules": [
                                        {
                                            "id": 2,
                                            "name": "Alert on failed deploys",
                                            "trigger": "deploy.failed",
                                            "conditions": [
                                                {
                                                    "field": "domain",
                                                    "op": "contains",
                                                    "value": "shop"
                                                }
                                            ],
                                            "actionType": "notify",
                                            "actionConfig": {
                                                "title": "Deploy failed on {{domain}}",
                                                "body": "Branch {{branch}} at {{commit}}",
                                                "level": "critical"
                                            },
                                            "enabled": true,
                                            "dryRun": false,
                                            "lastFiredAt": "2026-11-27T10:00:00.000Z",
                                            "createdAt": "2026-11-27T10:00:00.000Z",
                                            "updatedAt": "2026-11-27T10:00:00.000Z"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "automationRulesCreate",
                "summary": "Create an automation rule",
                "description": "Creates a rule that reacts to a panel event: when an event of type trigger is emitted and all conditions match, the action runs. New rules are disabled and in dry-run mode unless enabled/dryRun say otherwise.\n\n**Roles:** admin.\n\n- Unlike GET /rules, the response returns conditions and actionConfig as raw JSON strings.\n\n- Unknown body fields are removed silently (additionalProperties: false).\n\n- Rules run asynchronously (fire-and-forget) when the panel emits an event whose type equals trigger, and only while enabled. Each evaluation is logged as an AutomationRun (newest 100 kept per rule); with dryRun the run records actionTaken \"would <actionType>\".\n\n- Actions: notify creates a panel notification; telegram sends via the configured notification channel; webhook POSTs { event, data: <payload>, at } as JSON to actionConfig.url with a 10-second timeout. No action can change a hosted site.\n\n- Event payload fields usable in conditions/placeholders: deploy.succeeded / deploy.failed → siteId, domain, branch, commit, status, testsPassed, testsFailed, testsTotal; billing.invoice_paid → invoiceId, number, currency, fullyPaid, restored; billing.suspended → siteId, domain, level; billing.restored → invoiceId, subscriptionId; fleet.alert → eventId, serverId, serverName, kind, ruleId, message, value; fleet.alert_resolved → eventId, serverId, serverName, kind, ruleId, message.\n\n- site.down, site.up and ssl.expiring are in the event catalogue but no code in apps/api/src currently emits them.\n\n- All /api/automation routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Automation"
                ],
                "responses": {
                    "201": {
                        "description": "The created AutomationRule row (conditions and actionConfig as JSON strings).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 2,
                                    "name": "Alert on failed deploys",
                                    "trigger": "deploy.failed",
                                    "conditions": "[{\"field\":\"domain\",\"op\":\"contains\",\"value\":\"shop\"}]",
                                    "actionType": "notify",
                                    "actionConfig": "{\"title\":\"Deploy failed on {{domain}}\",\"body\":\"Branch {{branch}} at {{commit}}\",\"level\":\"critical\"}",
                                    "enabled": false,
                                    "dryRun": true,
                                    "lastFiredAt": null,
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Schema validation failure (FST_ERR_VALIDATION; message varies). — \"body/actionType must be equal to one of the allowed values\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "body/actionType must be equal to one of the allowed values"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Rule name. (1–100 chars)"
                                    },
                                    "trigger": {
                                        "type": "string",
                                        "description": "Event type that fires the rule (exact match). (1–64 chars; not checked against the event catalogue)"
                                    },
                                    "conditions": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Conditions, all of which must match (AND). [] = always matches. (max 20 items; items not validated; default [])"
                                    },
                                    "actionType": {
                                        "type": "string",
                                        "description": "What to do when the rule matches. (one of: notify, telegram, webhook)"
                                    },
                                    "actionConfig": {
                                        "type": "object",
                                        "description": "Action parameters (keys depend on actionType; see notes). title/body/message support {{field}} placeholders from the event payload. (object; keys not validated; default {})"
                                    },
                                    "enabled": {
                                        "type": "boolean",
                                        "description": "Rules only run while enabled. (default false)"
                                    },
                                    "dryRun": {
                                        "type": "boolean",
                                        "description": "Record what would happen without performing the action. (default true)"
                                    }
                                },
                                "required": [
                                    "name",
                                    "trigger",
                                    "actionType"
                                ]
                            },
                            "example": {
                                "name": "Alert on failed deploys",
                                "trigger": "deploy.failed",
                                "conditions": [
                                    {
                                        "field": "domain",
                                        "op": "contains",
                                        "value": "shop"
                                    }
                                ],
                                "actionType": "notify",
                                "actionConfig": {
                                    "title": "Deploy failed on {{domain}}",
                                    "body": "Branch {{branch}} at {{commit}}",
                                    "level": "critical"
                                },
                                "enabled": false,
                                "dryRun": true
                            }
                        }
                    }
                }
            }
        },
        "/api/automation/rules/{id}": {
            "patch": {
                "operationId": "automationRulesUpdate",
                "summary": "Update an automation rule",
                "description": "Updates the given rule fields only (e.g. enable it or switch dry-run off).\n\n**Roles:** admin.\n\n- The response returns conditions and actionConfig as raw JSON strings.\n\n- Unknown body fields are removed silently (additionalProperties: false).\n\n- All /api/automation routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Automation"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Rule id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The updated AutomationRule row (conditions and actionConfig as JSON strings).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 2,
                                    "name": "Alert on failed deploys",
                                    "trigger": "deploy.failed",
                                    "conditions": "[{\"field\":\"domain\",\"op\":\"contains\",\"value\":\"shop\"}]",
                                    "actionType": "notify",
                                    "actionConfig": "{\"title\":\"Deploy failed on {{domain}}\",\"body\":\"Branch {{branch}} at {{commit}}\",\"level\":\"critical\"}",
                                    "enabled": true,
                                    "dryRun": false,
                                    "lastFiredAt": "2026-11-27T10:00:00.000Z",
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No rule with this id (any update failure is reported as 404). — \"Rule not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Rule not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Rule name. (1–100 chars)"
                                    },
                                    "trigger": {
                                        "type": "string",
                                        "description": "Event type that fires the rule (exact match). (1–64 chars; not checked against the event catalogue)"
                                    },
                                    "conditions": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Conditions, all of which must match (AND). [] = always matches. (max 20 items; items not validated)"
                                    },
                                    "actionType": {
                                        "type": "string",
                                        "description": "What to do when the rule matches. (one of: notify, telegram, webhook)"
                                    },
                                    "actionConfig": {
                                        "type": "object",
                                        "description": "Action parameters (keys depend on actionType; see notes). title/body/message support {{field}} placeholders from the event payload. (object; keys not validated)"
                                    },
                                    "enabled": {
                                        "type": "boolean",
                                        "description": "Rules only run while enabled."
                                    },
                                    "dryRun": {
                                        "type": "boolean",
                                        "description": "Record what would happen without performing the action."
                                    }
                                }
                            },
                            "example": {
                                "enabled": true,
                                "dryRun": false
                            }
                        }
                    }
                }
            },
            "delete": {
                "operationId": "automationRulesDelete",
                "summary": "Delete an automation rule",
                "description": "Deletes a rule and its run log.\n\n**Roles:** admin.\n\n- Returns { ok: true } (and writes the audit entry) even when no rule has this id.\n\n- All /api/automation routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Automation"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Rule id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Always { ok: true }.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/automation/rules/{id}/runs": {
            "get": {
                "operationId": "automationRulesRuns",
                "summary": "List rule runs",
                "description": "Returns the newest 50 evaluations of a rule: whether its conditions matched, whether it was a dry run, and what action was taken.\n\n**Roles:** admin.\n\n- actionTaken: the action type when executed, \"would <type>\" in dry run, \"error\" when the action threw (detail = error message), null when conditions did not match. detail examples: \"notification created\", \"telegram sent\", \"POST <url> → 200\", or in dry run \"notify: <title>\" / \"telegram: <message>\" / \"POST <url>\".\n\n- An unknown rule id returns an empty list.\n\n- All /api/automation routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Automation"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Rule id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Run log rows, newest first.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "runs": [
                                        {
                                            "id": 77,
                                            "ruleId": 2,
                                            "event": "deploy.failed",
                                            "matched": true,
                                            "dryRun": false,
                                            "actionTaken": "notify",
                                            "detail": "notification created",
                                            "createdAt": "2026-11-27T10:00:00.000Z"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/automation/webhooks": {
            "get": {
                "operationId": "automationWebhooksList",
                "summary": "List outbound webhooks",
                "description": "Lists outbound webhooks, newest first. Secrets are never returned; hasSecret tells whether one is set.\n\n**Roles:** admin.\n\n- events is the parsed filter array ([] = all events).\n\n- All /api/automation routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Automation"
                ],
                "responses": {
                    "200": {
                        "description": "The webhooks.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "webhooks": [
                                        {
                                            "id": 4,
                                            "name": "Ops channel",
                                            "url": "https://hooks.example.com/orchestrator",
                                            "events": [
                                                "deploy.failed",
                                                "billing.suspended"
                                            ],
                                            "active": true,
                                            "hasSecret": true,
                                            "createdAt": "2026-11-27T10:00:00.000Z"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "automationWebhooksCreate",
                "summary": "Create an outbound webhook",
                "description": "Creates an outbound webhook. While active, the panel POSTs every matching event as JSON { event, data, at } with headers x-orchestrator-event and, when a secret is set, x-orchestrator-signature: sha256=<hex HMAC-SHA256 of the raw body>. Inactive by default.\n\n**Roles:** admin.\n\n- Deliveries are fire-and-forget with a 10-second timeout and no retries; each attempt is logged (newest 100 kept per webhook).\n\n- Unknown body fields are removed silently (additionalProperties: false).\n\n- All /api/automation routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Automation"
                ],
                "responses": {
                    "201": {
                        "description": "The created webhook (without the secret).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 4,
                                    "name": "Ops channel",
                                    "url": "https://hooks.example.com/orchestrator",
                                    "events": [
                                        "deploy.failed",
                                        "billing.suspended"
                                    ],
                                    "active": true,
                                    "hasSecret": true,
                                    "createdAt": "2026-11-27T10:00:00.000Z"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "url has another scheme. — \"URL must start with http:// or https://\"\n\nSchema validation failure (FST_ERR_VALIDATION; message varies). — \"body must have required property 'url'\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "URL must start with http:// or https://"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Display name. (1–100 chars)"
                                    },
                                    "url": {
                                        "type": "string",
                                        "description": "Endpoint the panel POSTs events to. (1–2000 chars; must start with http:// or https://)"
                                    },
                                    "secret": {
                                        "type": "string",
                                        "description": "HMAC-SHA256 signing key (write-only; encrypted at rest, never returned — responses only show hasSecret). (max 200 chars)"
                                    },
                                    "events": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Event types to deliver; [] (default) = all events. (array of strings, max 50 items; values are not checked against the event catalogue)"
                                    },
                                    "active": {
                                        "type": "boolean",
                                        "description": "Deliveries only happen while active. (default false)"
                                    }
                                },
                                "required": [
                                    "name",
                                    "url"
                                ]
                            },
                            "example": {
                                "name": "Ops channel",
                                "url": "https://hooks.example.com/orchestrator",
                                "secret": "example-signing-secret",
                                "events": [
                                    "deploy.failed",
                                    "billing.suspended"
                                ],
                                "active": true
                            }
                        }
                    }
                }
            }
        },
        "/api/automation/webhooks/{id}": {
            "patch": {
                "operationId": "automationWebhooksUpdate",
                "summary": "Update an outbound webhook",
                "description": "Updates the given webhook fields only. Sending secret replaces the signing key; an empty string removes it.\n\n**Roles:** admin.\n\n- Unknown body fields are removed silently (additionalProperties: false).\n\n- All /api/automation routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Automation"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Webhook id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The updated webhook (without the secret).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 4,
                                    "name": "Ops channel",
                                    "url": "https://hooks.example.com/orchestrator",
                                    "events": [],
                                    "active": false,
                                    "hasSecret": true,
                                    "createdAt": "2026-11-27T10:00:00.000Z"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "url given with another scheme. — \"URL must start with http:// or https://\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "URL must start with http:// or https://"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No webhook with this id (any update failure is reported as 404). — \"Webhook not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Webhook not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Display name. (1–100 chars)"
                                    },
                                    "url": {
                                        "type": "string",
                                        "description": "Endpoint the panel POSTs events to. (1–2000 chars; must start with http:// or https://)"
                                    },
                                    "secret": {
                                        "type": "string",
                                        "description": "HMAC-SHA256 signing key (write-only; encrypted at rest, never returned — responses only show hasSecret). An empty string removes the secret. (max 200 chars)"
                                    },
                                    "events": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Event types to deliver; [] (default) = all events. (array of strings, max 50 items; values are not checked against the event catalogue)"
                                    },
                                    "active": {
                                        "type": "boolean",
                                        "description": "Deliveries only happen while active."
                                    }
                                }
                            },
                            "example": {
                                "active": false,
                                "events": []
                            }
                        }
                    }
                }
            },
            "delete": {
                "operationId": "automationWebhooksDelete",
                "summary": "Delete an outbound webhook",
                "description": "Deletes a webhook and its delivery log.\n\n**Roles:** admin.\n\n- Returns { ok: true } (and writes the audit entry) even when no webhook has this id.\n\n- All /api/automation routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Automation"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Webhook id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Always { ok: true }.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/automation/webhooks/{id}/deliveries": {
            "get": {
                "operationId": "automationWebhooksDeliveries",
                "summary": "List webhook deliveries",
                "description": "Returns the newest 50 delivery attempts of a webhook, including test pings.\n\n**Roles:** admin.\n\n- statusCode is null and error holds the exception message when the request failed or timed out. An unknown webhook id returns an empty list.\n\n- All /api/automation routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Automation"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Webhook id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Delivery log rows, newest first.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "deliveries": [
                                        {
                                            "id": 310,
                                            "webhookId": 4,
                                            "event": "deploy.failed",
                                            "success": false,
                                            "statusCode": 500,
                                            "error": "HTTP 500",
                                            "createdAt": "2026-11-27T10:00:00.000Z"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/automation/webhooks/{id}/test": {
            "post": {
                "operationId": "automationWebhooksTest",
                "summary": "Send a test delivery",
                "description": "Immediately POSTs a test.ping event to the webhook URL (even if the webhook is inactive), signed like a real delivery, waits up to 10 seconds, logs the attempt and reports the outcome.\n\n**Roles:** admin.\n\n- Sent body: { \"event\": \"test.ping\", \"data\": { \"message\": \"Orchestrator test delivery\" }, \"at\": <ISO time> } with headers content-type: application/json, x-orchestrator-event: test.ping and, when a secret is set, x-orchestrator-signature: sha256=<hex HMAC-SHA256 of the body>.\n\n- A non-2xx answer from the endpoint still returns HTTP 200 here, with ok: false and its statusCode.\n\n- No audit entry is written. The test route itself does not prune the delivery log (real deliveries keep the newest 100).\n\n- All /api/automation routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Automation"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Webhook id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Whether the endpoint answered with a 2xx status, and the status code.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "statusCode": 200
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No webhook with this id. — \"Webhook not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Webhook not found"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The request could not be sent or timed out after 10 s; body is { ok: false, error: <message> }. — \"<network or timeout error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<network or timeout error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/billing/clients": {
            "get": {
                "operationId": "billingClientsList",
                "summary": "List clients",
                "description": "Lists every billing client (archived ones included), ordered by name, with their subscriptions (each including its site), the outstanding balance across their open invoices, and the domains they are billed for.\n\n**Roles:** admin.\n\n- outstanding is in minor units (sum of amount − amountPaid over open/partial/overdue invoices, summed across currencies).\n\n- The response includes each client's portalToken (the secret for the read-only client portal at /api/portal/{token}).\n\n- subscriptions includes cancelled ones; each subscription embeds the full Site row.\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: clients"
                ],
                "responses": {
                    "200": {
                        "description": "Array of Client rows plus subscriptions, outstanding and sites.",
                        "content": {
                            "application/json": {
                                "example": [
                                    {
                                        "id": 12,
                                        "name": "Ada Lovelace",
                                        "email": "ada@example.com",
                                        "phone": "+995 555 12 34 56",
                                        "telegramChatId": null,
                                        "company": "Example LLC",
                                        "taxId": "404123456",
                                        "currency": "GEL",
                                        "locale": "en",
                                        "portalToken": "9f1c2e7a4b6d8f0a1c3e5a7b9d1f3a5c7e9b1d3f5a7c9e1b",
                                        "notes": null,
                                        "archived": false,
                                        "createdAt": "2026-11-27T10:00:00.000Z",
                                        "updatedAt": "2026-11-27T10:00:00.000Z",
                                        "subscriptions": [
                                            {
                                                "id": 5,
                                                "siteId": 7,
                                                "clientId": 12,
                                                "planId": 3,
                                                "amount": 3000,
                                                "currency": "GEL",
                                                "interval": "monthly",
                                                "intervalDays": null,
                                                "anchorDay": 1,
                                                "startDate": "2026-11-27T10:00:00.000Z",
                                                "nextInvoiceAt": "2026-12-01T00:00:00.000Z",
                                                "status": "active",
                                                "enforcementLevel": "none",
                                                "lastEnforcedAt": null,
                                                "neverAutoSuspend": false,
                                                "gracePeriodDays": 3,
                                                "dunningPolicy": "",
                                                "suspendedAt": null,
                                                "cancelledAt": null,
                                                "createdAt": "2026-11-27T10:00:00.000Z",
                                                "updatedAt": "2026-11-27T10:00:00.000Z",
                                                "site": {
                                                    "id": 7,
                                                    "domain": "shop.example.com",
                                                    "serverId": null,
                                                    "status": "active",
                                                    "phpVersion": "8.3"
                                                }
                                            }
                                        ],
                                        "outstanding": 2000,
                                        "sites": [
                                            "shop.example.com"
                                        ]
                                    }
                                ]
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "billingClientsCreate",
                "summary": "Create a client",
                "description": "Creates a billing client and generates its read-only portal token (48 hex characters).\n\n**Roles:** admin.\n\n- Unknown body fields are removed silently (additionalProperties: false); archived cannot be set at creation.\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: clients"
                ],
                "responses": {
                    "201": {
                        "description": "The created Client row, including portalToken.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 12,
                                    "name": "Ada Lovelace",
                                    "email": "ada@example.com",
                                    "phone": "+995 555 12 34 56",
                                    "telegramChatId": null,
                                    "company": "Example LLC",
                                    "taxId": "404123456",
                                    "currency": "GEL",
                                    "locale": "en",
                                    "portalToken": "9f1c2e7a4b6d8f0a1c3e5a7b9d1f3a5c7e9b1d3f5a7c9e1b",
                                    "notes": null,
                                    "archived": false,
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Schema validation failure (FST_ERR_VALIDATION; message varies by field). — \"body/name must NOT have fewer than 1 characters\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "body/name must NOT have fewer than 1 characters"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Client name. (1–200 chars)"
                                    },
                                    "email": {
                                        "type": "string",
                                        "description": "Contact email (also shown on the suspension page as contact). (max 200 chars; format not checked)"
                                    },
                                    "phone": {
                                        "type": "string",
                                        "description": "Contact phone (used as contact when there is no email). (max 60 chars)"
                                    },
                                    "telegramChatId": {
                                        "type": "string",
                                        "description": "Telegram chat id. (max 60 chars)"
                                    },
                                    "company": {
                                        "type": "string",
                                        "description": "Company name. (max 200 chars)"
                                    },
                                    "taxId": {
                                        "type": "string",
                                        "description": "Tax id. (max 60 chars)"
                                    },
                                    "currency": {
                                        "type": "string",
                                        "description": "Client currency. (one of: GEL, USD, EUR; default GEL)"
                                    },
                                    "locale": {
                                        "type": "string",
                                        "description": "Language of dunning messages and the suspension page. (one of: ka, en; default ka)"
                                    },
                                    "notes": {
                                        "type": "string",
                                        "description": "Free-form notes. (max 2000 chars)"
                                    }
                                },
                                "required": [
                                    "name"
                                ]
                            },
                            "example": {
                                "name": "Ada Lovelace",
                                "email": "ada@example.com",
                                "company": "Example LLC",
                                "currency": "GEL",
                                "locale": "en"
                            }
                        }
                    }
                }
            }
        },
        "/api/billing/clients/{id}": {
            "patch": {
                "operationId": "billingClientsUpdate",
                "summary": "Update a client",
                "description": "Updates a client. The body is passed to the database as-is after removing id and portalToken (use rotate-token to change the portal token). Send archived: true to archive a client.\n\n**Roles:** admin.\n\n- No request schema: any field that is not a Client column (or a value of the wrong type) makes Prisma throw → 500. id and portalToken are silently dropped.\n\n- No client with this id makes the Prisma call throw; there is no 404 branch, so Fastify's default error handler answers 500.\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: clients"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Client id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The updated Client row.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 12,
                                    "name": "Ada Lovelace",
                                    "email": "ada@example.com",
                                    "phone": "+995 555 12 34 56",
                                    "telegramChatId": null,
                                    "company": "Example LLC",
                                    "taxId": "404123456",
                                    "currency": "GEL",
                                    "locale": "en",
                                    "portalToken": "9f1c2e7a4b6d8f0a1c3e5a7b9d1f3a5c7e9b1d3f5a7c9e1b",
                                    "notes": null,
                                    "archived": false,
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Client name. (not validated)"
                                    },
                                    "email": {
                                        "type": "string",
                                        "description": "Contact email. (not validated)"
                                    },
                                    "phone": {
                                        "type": "string",
                                        "description": "Contact phone. (not validated)"
                                    },
                                    "telegramChatId": {
                                        "type": "string",
                                        "description": "Telegram chat id. (not validated)"
                                    },
                                    "company": {
                                        "type": "string",
                                        "description": "Company name. (not validated)"
                                    },
                                    "taxId": {
                                        "type": "string",
                                        "description": "Tax id. (not validated)"
                                    },
                                    "currency": {
                                        "type": "string",
                                        "description": "Client currency (GEL, USD or EUR expected). (not validated)"
                                    },
                                    "locale": {
                                        "type": "string",
                                        "description": "ka or en. (not validated)"
                                    },
                                    "notes": {
                                        "type": "string",
                                        "description": "Free-form notes. (not validated)"
                                    },
                                    "archived": {
                                        "type": "boolean",
                                        "description": "Archive (true) or unarchive (false) the client. (not validated)"
                                    }
                                }
                            },
                            "example": {
                                "phone": "+995 555 12 34 56",
                                "archived": false
                            }
                        }
                    }
                }
            },
            "delete": {
                "operationId": "billingClientsDelete",
                "summary": "Delete a client",
                "description": "Permanently deletes a client that has no subscriptions and no invoices. Clients with billing history must be archived instead (PATCH with archived: true).\n\n**Roles:** admin.\n\n- No client with this id makes the Prisma call throw; there is no 404 branch, so Fastify's default error handler answers 500.\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: clients"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Client id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Deletion confirmation.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "deleted": true
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The client has any subscription (including cancelled) or any invoice; the counts are filled in. — \"Client has 1 subscription(s) and 3 invoice(s). Archive the client instead of deleting.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Client has 1 subscription(s) and 3 invoice(s). Archive the client instead of deleting."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/billing/clients/{id}/rotate-token": {
            "post": {
                "operationId": "billingClientsRotateToken",
                "summary": "Rotate client portal token",
                "description": "Generates a new random portal token (24 random bytes, 48 hex characters) for the client, immediately invalidating the old read-only portal link.\n\n**Roles:** admin.\n\n- The token is the credential for the public client portal (/api/portal/{token}; the web UI builds the link as <origin>/client/<token>). Treat it as a secret.\n\n- No body is read; the web client sends {}.\n\n- No client with this id makes the Prisma call throw; there is no 404 branch, so Fastify's default error handler answers 500.\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: clients"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Client id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The new portal token.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "portalToken": "3b7e1f9a2c4d6e8f0a1b3c5d7e9f1a2b4c6d8e0f1a3b5c7d"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/billing/default-policy": {
            "get": {
                "operationId": "billingDefaultPolicy",
                "summary": "Get the default dunning ladder",
                "description": "Returns the built-in dunning ladder used when neither the subscription nor its plan defines one.\n\n**Roles:** admin.\n\n- Actions: remind / invoice_due / final_warning only notify; banner injects a payment-overdue banner; restrict blocks /admin and /login while the public site stays up; suspend serves a branded 503 page; stop_workers also stops queue workers and the scheduler (site stays suspended); archive maps to level archived. The type comment in dunning.ts describes archive as \"backup + remove files, never deletes the database\", but site-suspend.sh serves archived exactly like suspend (503 page) and no backup/file removal is implemented in the tick or the script.\n\n- Days are calendar days in the Asia/Tbilisi time zone.\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: plans and subscriptions"
                ],
                "responses": {
                    "200": {
                        "description": "The default ladder.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "policy": [
                                        {
                                            "offsetDays": -7,
                                            "action": "remind"
                                        },
                                        {
                                            "offsetDays": 0,
                                            "action": "invoice_due"
                                        },
                                        {
                                            "offsetDays": 4,
                                            "action": "banner"
                                        },
                                        {
                                            "offsetDays": 7,
                                            "action": "restrict"
                                        },
                                        {
                                            "offsetDays": 10,
                                            "action": "suspend"
                                        },
                                        {
                                            "offsetDays": 30,
                                            "action": "stop_workers"
                                        },
                                        {
                                            "offsetDays": 60,
                                            "action": "final_warning"
                                        },
                                        {
                                            "offsetDays": 90,
                                            "action": "archive"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/billing/enforcement": {
            "get": {
                "operationId": "billingEnforcementGet",
                "summary": "Get enforcement mode",
                "description": "Returns the billing enforcement master switch. Anything other than \"on\" or \"dry_run\" stored in the setting (including no setting) reads as \"off\".\n\n**Roles:** admin.\n\n- Modes: off = never touch a site (default; billing fails closed), dry_run = record what would happen without changing anything, on = apply banners/restrictions/suspensions.\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: enforcement and reports"
                ],
                "responses": {
                    "200": {
                        "description": "The current mode.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "mode": "off"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "put": {
                "operationId": "billingEnforcementSet",
                "summary": "Set enforcement mode",
                "description": "Sets the billing enforcement master switch (stored in the settings table under the key billing_enforcement). It only gates automatic and manual escalation; restoring a site is always allowed.\n\n**Roles:** admin.\n\n- Unknown body fields are removed silently (additionalProperties: false).\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: enforcement and reports"
                ],
                "responses": {
                    "200": {
                        "description": "The mode that was saved.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "mode": "dry_run"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "mode missing or not one of off, dry_run, on (Fastify schema validation, code FST_ERR_VALIDATION). — \"body/mode must be equal to one of the allowed values\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "body/mode must be equal to one of the allowed values"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "mode": {
                                        "type": "string",
                                        "description": "New master-switch mode. (one of: off, dry_run, on)"
                                    }
                                },
                                "required": [
                                    "mode"
                                ]
                            },
                            "example": {
                                "mode": "dry_run"
                            }
                        }
                    }
                }
            }
        },
        "/api/billing/invoices": {
            "get": {
                "operationId": "billingInvoicesList",
                "summary": "List invoices",
                "description": "Lists up to 500 invoices, newest first, optionally filtered, with client, site and payments, plus the remaining balance and a formatted amount.\n\n**Roles:** admin.\n\n- balance (minor units) is 0 for void invoices, otherwise max(0, amount − amountPaid). amountFormatted formats amount (not balance), e.g. \"30.00 ₾\", \"$30.00\", \"€30.00\".\n\n- lineItems is a JSON string. Invoice status values: draft | open | partial | paid | overdue | void (the code creates open; the tick flips open → overdue once past due; payments set partial/paid).\n\n- A non-numeric clientId/siteId becomes NaN and makes Prisma throw → 500. Hard limit of 500 rows, no pagination.\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: invoices and payments"
                ],
                "parameters": [
                    {
                        "name": "status",
                        "in": "query",
                        "required": false,
                        "description": "Exact invoice status. (not validated; draft, open, partial, paid, overdue or void)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "clientId",
                        "in": "query",
                        "required": false,
                        "description": "Only this client's invoices. (not validated)",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "siteId",
                        "in": "query",
                        "required": false,
                        "description": "Only this site's invoices. (not validated)",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Array of Invoice rows with client, site, payments, balance and amountFormatted.",
                        "content": {
                            "application/json": {
                                "example": [
                                    {
                                        "id": 42,
                                        "number": "INV-2026-0042",
                                        "clientId": 12,
                                        "subscriptionId": 5,
                                        "siteId": 7,
                                        "periodStart": "2026-11-01T00:00:00.000Z",
                                        "periodEnd": "2026-12-01T00:00:00.000Z",
                                        "issuedAt": "2026-11-01T00:00:00.000Z",
                                        "dueDate": "2026-11-01T00:00:00.000Z",
                                        "amount": 3000,
                                        "amountPaid": 1000,
                                        "currency": "GEL",
                                        "status": "partial",
                                        "paidAt": null,
                                        "lineItems": "[{\"description\":\"Hosting — shop.example.com\",\"periodStart\":\"2026-11-01T00:00:00.000Z\",\"periodEnd\":\"2026-12-01T00:00:00.000Z\",\"amount\":3000,\"currency\":\"GEL\"}]",
                                        "notes": null,
                                        "createdAt": "2026-11-27T10:00:00.000Z",
                                        "updatedAt": "2026-11-27T10:00:00.000Z",
                                        "client": {
                                            "id": 12,
                                            "name": "Ada Lovelace",
                                            "email": "ada@example.com",
                                            "phone": "+995 555 12 34 56",
                                            "telegramChatId": null,
                                            "company": "Example LLC",
                                            "taxId": "404123456",
                                            "currency": "GEL",
                                            "locale": "en",
                                            "portalToken": "9f1c2e7a4b6d8f0a1c3e5a7b9d1f3a5c7e9b1d3f5a7c9e1b",
                                            "notes": null,
                                            "archived": false,
                                            "createdAt": "2026-11-27T10:00:00.000Z",
                                            "updatedAt": "2026-11-27T10:00:00.000Z"
                                        },
                                        "site": {
                                            "id": 7,
                                            "domain": "shop.example.com",
                                            "serverId": null,
                                            "status": "active",
                                            "phpVersion": "8.3"
                                        },
                                        "payments": [
                                            {
                                                "id": 9,
                                                "invoiceId": 42,
                                                "amount": 1000,
                                                "currency": "GEL",
                                                "method": "bank_transfer",
                                                "source": "manual",
                                                "reference": "TBC-778812",
                                                "externalId": null,
                                                "receivedAt": "2026-11-27T10:00:00.000Z",
                                                "recordedById": null,
                                                "note": null,
                                                "createdAt": "2026-11-27T10:00:00.000Z"
                                            }
                                        ],
                                        "balance": 2000,
                                        "amountFormatted": "30.00 ₾"
                                    }
                                ]
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/billing/invoices/overdue": {
            "get": {
                "operationId": "billingInvoicesOverdue",
                "summary": "List overdue invoices",
                "description": "Lists every open, partial or overdue invoice whose due date has passed, oldest due first, in a compact shape.\n\n**Roles:** admin.\n\n- balance is in minor units. Selection is by due date < now (not by status = overdue).\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: invoices and payments"
                ],
                "responses": {
                    "200": {
                        "description": "Compact overdue invoice rows.",
                        "content": {
                            "application/json": {
                                "example": [
                                    {
                                        "id": 42,
                                        "number": "INV-2026-0042",
                                        "client": "Ada Lovelace",
                                        "domain": "shop.example.com",
                                        "balance": 2000,
                                        "currency": "GEL",
                                        "dueDate": "2026-11-01T00:00:00.000Z"
                                    }
                                ]
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/billing/invoices/{id}/pay": {
            "post": {
                "operationId": "billingInvoicesPay",
                "summary": "Record a payment",
                "description": "Records a manual payment against an invoice; omit amount to settle the full remaining balance. The invoice status is recomputed from the sum of its payments (partial or paid). When the invoice becomes fully paid and nothing else is owed on that subscription, the site is restored immediately (regardless of the master switch) and the subscription returns to active.\n\n**Roles:** admin.\n\n- Money: every stored/returned amount is an INTEGER in the currency's minor unit (tetri for GEL, cents for USD/EUR; 3000 = 30.00). Where a field accepts both, a JSON number is taken as minor units as-is, while a string is parsed as MAJOR units (\"30\", \"30.5\", \"1 200,75\" — whitespace removed, comma accepted as decimal separator, rounded half-up to 2 decimals). Here the schema limits amount to an integer or a string.\n\n- Overpayment is allowed: an amount larger than the balance is recorded in full and the invoice becomes paid (balance never goes below 0). Explicit amounts can also be recorded on an already paid invoice.\n\n- amount, amountPaid and balance in the response are minor units. duplicate is always false for this route (it records with source manual and no externalId). restored is true only when the site was actually moved back to none.\n\n- Emits the billing.invoice_paid event (payload { invoiceId, number, currency, fullyPaid, restored }) on every recorded payment, partial ones included, and billing.restored ({ invoiceId, subscriptionId }) when the site was restored.\n\n- The payment's recordedById is read from request.user.id, which the auth payload does not set (it uses userId), so it appears to be stored as null.\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: invoices and payments"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Invoice id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The invoice's new payment state and whether the site was restored.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "invoiceId": 42,
                                    "status": "paid",
                                    "amount": 3000,
                                    "amountPaid": 3000,
                                    "balance": 0,
                                    "fullyPaid": true,
                                    "duplicate": false,
                                    "restored": true
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The invoice is void, or amount was omitted and nothing is left to pay. — \"Could not record payment (void invoice or zero amount)\"\n\namount given but does not parse or is ≤ 0. — \"Invalid amount\"\n\nSchema validation failure (FST_ERR_VALIDATION; message varies). — \"body/method must be equal to one of the allowed values\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Could not record payment (void invoice or zero amount)"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No invoice with this id. — \"Invoice not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invoice not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "amount": {
                                        "type": "integer",
                                        "description": "Amount received: integer = minor units (2000), string = major units in the invoice currency (\"20.00\"). Omit for the full remaining balance. (integer (minor units) or string (major units); must resolve to > 0)"
                                    },
                                    "method": {
                                        "type": "string",
                                        "description": "Payment method. (one of: cash, bank_transfer, card, other; default cash)"
                                    },
                                    "reference": {
                                        "type": "string",
                                        "description": "Bank reference or receipt number. (max 200 chars)"
                                    },
                                    "note": {
                                        "type": "string",
                                        "description": "Free-form note. (max 500 chars)"
                                    },
                                    "receivedAt": {
                                        "type": "string",
                                        "description": "When the money was received. Default now. (date string parsed with new Date())"
                                    }
                                }
                            },
                            "example": {
                                "amount": "20.00",
                                "method": "bank_transfer",
                                "reference": "TBC-778812"
                            }
                        }
                    }
                }
            }
        },
        "/api/billing/invoices/{id}/void": {
            "post": {
                "operationId": "billingInvoicesVoid",
                "summary": "Void an invoice",
                "description": "Voids an unpaid invoice that has no payments. If the subscription's billing anchor had already moved past this invoice's period, it is rolled back to the period start so the period is billed again by the next tick.\n\n**Roles:** admin.\n\n- Voiding an already void invoice returns { voided: true } (no periodRestored field) and writes no audit entry.\n\n- An invoice_voided billing event is recorded on the subscription. Voiding does not lift enforcement by itself; the next tick restores the site if nothing else is owed.\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: invoices and payments"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Invoice id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Void confirmation and whether the billing anchor was rolled back.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "voided": true,
                                    "periodRestored": true
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The invoice status is paid. — \"A paid invoice cannot be voided.\"\n\nThe invoice is partially paid (amountPaid > 0). — \"This invoice has recorded payments — refund or reallocate them before voiding.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "A paid invoice cannot be voided."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No invoice with this id. — \"Invoice not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invoice not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/billing/overview": {
            "get": {
                "operationId": "billingOverview",
                "summary": "Get billing overview",
                "description": "Dashboard totals: master-switch mode, client and subscription counts, monthly recurring revenue, outstanding receivables with an aging breakdown, and how many subscriptions are suspended or past due.\n\n**Roles:** admin.\n\n- currency is simply the currency of the first non-cancelled subscription (GEL when there are none); mrr and outstanding are plain sums of minor units across ALL currencies — they are not converted.\n\n- clients counts non-archived clients; subscriptions counts every subscription whose status is not cancelled.\n\n- mrr counts active, past_due and suspended subscriptions: monthly = amount, yearly = round(amount/12), custom_days = round(amount*30/intervalDays).\n\n- aging buckets (minor units) are by whole days past dueDate over open/partial/overdue invoices: current (≤0 days), d1_30, d31_60, d61_plus; total = sum.\n\n- suspended = subscriptions with enforcementLevel suspend or archived; pastDue = subscriptions with status past_due.\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: enforcement and reports"
                ],
                "responses": {
                    "200": {
                        "description": "Billing totals (amounts in minor units).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "mode": "off",
                                    "currency": "GEL",
                                    "clients": 8,
                                    "subscriptions": 11,
                                    "mrr": 33000,
                                    "outstanding": 9000,
                                    "aging": {
                                        "current": 3000,
                                        "d1_30": 6000,
                                        "d31_60": 0,
                                        "d61_plus": 0,
                                        "total": 9000
                                    },
                                    "suspended": 1,
                                    "pastDue": 2
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/billing/plans": {
            "get": {
                "operationId": "billingPlansList",
                "summary": "List plans",
                "description": "Lists all billing plans (archived included), ordered by name.\n\n**Roles:** admin.\n\n- amount is in minor units; dunningPolicy is the stored JSON string (\"\" = default ladder).\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: plans and subscriptions"
                ],
                "responses": {
                    "200": {
                        "description": "Array of Plan rows.",
                        "content": {
                            "application/json": {
                                "example": [
                                    {
                                        "id": 3,
                                        "name": "Standard",
                                        "amount": 3000,
                                        "currency": "GEL",
                                        "interval": "monthly",
                                        "intervalDays": null,
                                        "dunningPolicy": "",
                                        "gracePeriodDays": 3,
                                        "autoSuspend": true,
                                        "archived": false,
                                        "createdAt": "2026-11-27T10:00:00.000Z",
                                        "updatedAt": "2026-11-27T10:00:00.000Z"
                                    }
                                ]
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "billingPlansCreate",
                "summary": "Create a plan",
                "description": "Creates a billing plan: a reusable price, interval, grace period and optional dunning ladder that subscriptions can reference.\n\n**Roles:** admin.\n\n- Money: every stored/returned amount is an INTEGER in the currency's minor unit (tetri for GEL, cents for USD/EUR; 3000 = 30.00). Where a field accepts both, a JSON number is taken as minor units as-is, while a string is parsed as MAJOR units (\"30\", \"30.5\", \"1 200,75\" — whitespace removed, comma accepted as decimal separator, rounded half-up to 2 decimals).\n\n- No request schema: missing name, a duplicate name or wrong-typed fields make Prisma throw → 500. Negative or zero amounts are NOT rejected here, and a fractional JSON number is passed to an Int column (Prisma error → 500).\n\n- Passing dunningPolicy as a string stores JSON.stringify(<string>) (double-encoded), which reads back as \"not an array\" → default ladder. Send an array.\n\n- No audit entry is written.\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: plans and subscriptions"
                ],
                "responses": {
                    "201": {
                        "description": "The created Plan row.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 3,
                                    "name": "Standard",
                                    "amount": 3000,
                                    "currency": "GEL",
                                    "interval": "monthly",
                                    "intervalDays": null,
                                    "dunningPolicy": "[{\"offsetDays\":-7,\"action\":\"remind\"},{\"offsetDays\":0,\"action\":\"invoice_due\"},{\"offsetDays\":5,\"action\":\"banner\"},{\"offsetDays\":14,\"action\":\"suspend\"}]",
                                    "gracePeriodDays": 3,
                                    "autoSuspend": true,
                                    "archived": false,
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "amount is not a number and does not parse as a decimal amount (missing amount included). — \"Invalid amount\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid amount"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Plan name (unique). (not validated; required by the database)"
                                    },
                                    "amount": {
                                        "type": "integer",
                                        "description": "Price. JSON number = minor units (3000 = 30.00); string = major units (\"30.00\"). (not validated beyond parsing; number or decimal string)"
                                    },
                                    "currency": {
                                        "type": "string",
                                        "description": "Currency (used for string parsing too). (not validated; GEL, USD or EUR expected; default GEL)"
                                    },
                                    "interval": {
                                        "type": "string",
                                        "description": "Billing interval. (not validated; monthly, yearly or custom_days expected; default monthly)"
                                    },
                                    "intervalDays": {
                                        "type": "integer",
                                        "description": "Days per period when interval is custom_days. (not validated; default null)"
                                    },
                                    "gracePeriodDays": {
                                        "type": "integer",
                                        "description": "Days past due before any enforcement (notifications still go out). (not validated; default 3)"
                                    },
                                    "autoSuspend": {
                                        "type": "boolean",
                                        "description": "false = subscriptions on this plan never escalate past banner. (not validated; default true)"
                                    },
                                    "dunningPolicy": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Dunning ladder: JSON array of steps { offsetDays: integer (days relative to the invoice due date; negative = before it is due), action: one of remind, invoice_due, banner, restrict, suspend, stop_workers, final_warning, archive }. Stored JSON-stringified; empty/omitted = inherit (subscription → plan → built-in default ladder). Invalid steps are dropped when read; if nothing valid remains the default ladder is used. (not validated; JSON-stringified when truthy)"
                                    }
                                },
                                "required": [
                                    "name",
                                    "amount"
                                ]
                            },
                            "example": {
                                "name": "Standard",
                                "amount": "30.00",
                                "currency": "GEL",
                                "interval": "monthly",
                                "gracePeriodDays": 3,
                                "autoSuspend": true,
                                "dunningPolicy": [
                                    {
                                        "offsetDays": -7,
                                        "action": "remind"
                                    },
                                    {
                                        "offsetDays": 0,
                                        "action": "invoice_due"
                                    },
                                    {
                                        "offsetDays": 5,
                                        "action": "banner"
                                    },
                                    {
                                        "offsetDays": 14,
                                        "action": "suspend"
                                    }
                                ]
                            }
                        }
                    }
                }
            }
        },
        "/api/billing/plans/{id}": {
            "patch": {
                "operationId": "billingPlansUpdate",
                "summary": "Update a plan",
                "description": "Updates a plan. The body is passed to the database as-is (id removed), except that a string amount is parsed from major units and an array dunningPolicy is JSON-stringified. Changing a plan never rewrites existing subscriptions' amount or issued invoices.\n\n**Roles:** admin.\n\n- Money: every stored/returned amount is an INTEGER in the currency's minor unit (tetri for GEL, cents for USD/EUR; 3000 = 30.00). Where a field accepts both, a JSON number is taken as minor units as-is, while a string is parsed as MAJOR units (\"30\", \"30.5\", \"1 200,75\" — whitespace removed, comma accepted as decimal separator, rounded half-up to 2 decimals).\n\n- No request schema: unknown fields or wrong types make Prisma throw → 500. No plan with this id makes the Prisma call throw; there is no 404 branch, so Fastify's default error handler answers 500.\n\n- No audit entry is written.\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: plans and subscriptions"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Plan id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The updated Plan row.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 3,
                                    "name": "Standard",
                                    "amount": 3500,
                                    "currency": "GEL",
                                    "interval": "monthly",
                                    "intervalDays": null,
                                    "dunningPolicy": "",
                                    "gracePeriodDays": 5,
                                    "autoSuspend": true,
                                    "archived": false,
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Plan name. (not validated)"
                                    },
                                    "amount": {
                                        "type": "integer",
                                        "description": "Price: number = minor units; string = major units. (not validated; an unparseable string is silently ignored)"
                                    },
                                    "currency": {
                                        "type": "string",
                                        "description": "Currency. (not validated)"
                                    },
                                    "interval": {
                                        "type": "string",
                                        "description": "monthly, yearly or custom_days. (not validated)"
                                    },
                                    "intervalDays": {
                                        "type": "integer",
                                        "description": "Days per period for custom_days. (not validated)"
                                    },
                                    "gracePeriodDays": {
                                        "type": "integer",
                                        "description": "Grace period in days. (not validated)"
                                    },
                                    "autoSuspend": {
                                        "type": "boolean",
                                        "description": "Allow escalation past banner. (not validated)"
                                    },
                                    "archived": {
                                        "type": "boolean",
                                        "description": "Archive flag. (not validated)"
                                    },
                                    "dunningPolicy": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Dunning ladder: JSON array of steps { offsetDays: integer (days relative to the invoice due date; negative = before it is due), action: one of remind, invoice_due, banner, restrict, suspend, stop_workers, final_warning, archive }. Stored JSON-stringified; empty/omitted = inherit (subscription → plan → built-in default ladder). Invalid steps are dropped when read; if nothing valid remains the default ladder is used. A string is stored verbatim (so \"\" resets to the default ladder). (not validated)"
                                    }
                                }
                            },
                            "example": {
                                "amount": "35.00",
                                "gracePeriodDays": 5
                            }
                        }
                    }
                }
            }
        },
        "/api/billing/profitability": {
            "get": {
                "operationId": "billingProfitability",
                "summary": "Get per-site profitability",
                "description": "For every non-cancelled subscription, compares what the site is billed with its share of the hosting server's monthly cost (server cost divided by ALL sites on that server, billed or not).\n\n**Roles:** admin.\n\n- Sites with serverId null live on the local server and use the local server row's monthlyCostMinor.\n\n- netMarginMinor = amount − costShareMinor with no currency conversion (the subscription currency and the server cost currency may differ).\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: enforcement and reports"
                ],
                "responses": {
                    "200": {
                        "description": "One row per non-cancelled subscription (amounts in minor units).",
                        "content": {
                            "application/json": {
                                "example": [
                                    {
                                        "siteId": 7,
                                        "domain": "shop.example.com",
                                        "client": "Ada Lovelace",
                                        "amount": 3000,
                                        "currency": "GEL",
                                        "amountFormatted": "30.00 ₾",
                                        "serverId": null,
                                        "sitesOnServer": 4,
                                        "serverCostMinor": 8000,
                                        "costShareMinor": 2000,
                                        "netMarginMinor": 1000,
                                        "status": "active",
                                        "enforcementLevel": "none"
                                    }
                                ]
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/billing/run-tick": {
            "post": {
                "operationId": "billingTickRun",
                "summary": "Run the billing tick now",
                "description": "Runs the same daily billing tick the scheduler runs, synchronously, and returns its report: issues invoices whose anchor date has arrived, flips past-due invoices to overdue, sends each due dunning notification once, and moves sites up or down the dunning ladder according to the master switch. With dryRun: true nothing is written, sent or applied — the report only describes what a real run would do.\n\n**Roles:** admin.\n\n- Response shape: { mode: \"off\"|\"dry_run\"|\"on\", issued: string[], notified: string[], escalated: string[], restored: string[], skipped: string[], errors: string[] }. mode is \"dry_run\" when dryRun was true, otherwise the master-switch value.\n\n- Real run line formats: issued = invoice numbers (\"INV-2026-0042\"); notified = \"<domain>: <action>\"; escalated = \"<domain>: <from> → <to>\"; restored = \"<domain>\"; skipped = \"<domain>: <reason>\" (e.g. \"billing enforcement is off\", \"site is deploying — deferred\", \"apply failed: …\"); errors = \"issue #<subId>: <message>\" or \"sub #<subId>: <message>\". Dry-run lines are prefixed with \"would …\".\n\n- A real (non-dry) run issues invoices and SENDS notifications (panel notification + Telegram) even when the master switch is \"off\"; only escalation is blocked by \"off\" (reported under skipped). Restoring a site that no longer owes anything is applied even when the switch is \"off\".\n\n- Only subscriptions with status active, past_due or suspended are processed. The oldest unpaid (open/partial/overdue) invoice drives the ladder; the grace period (subscription → plan) withholds enforcement but not notifications; neverAutoSuspend or a plan with autoSuspend=false caps the level at banner.\n\n- Idempotent: invoices are issued once per period, notifications once per invoice per rung, and enforcement only acts when the target level differs from the stored one. Can take a while — runs nginx changes over SSH for remote sites.\n\n- Emits the billing.suspended event when a site is moved to suspend or archived.\n\n- The body is read without a schema; send a JSON object (an empty JSON body with Content-Type application/json is rejected by Fastify).\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: enforcement and reports"
                ],
                "responses": {
                    "200": {
                        "description": "Tick report: lists of human-readable lines per category.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "mode": "dry_run",
                                    "issued": [
                                        "would issue for shop.example.com"
                                    ],
                                    "notified": [
                                        "shop.example.com: would send invoice_due"
                                    ],
                                    "escalated": [
                                        "blog.example.com: would enforce (none → banner)"
                                    ],
                                    "restored": [],
                                    "skipped": [],
                                    "errors": []
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "dryRun": {
                                        "type": "boolean",
                                        "description": "Preview only: forces mode dry_run for this run regardless of the master switch. (not validated (no schema; truthy check), default false)"
                                    }
                                }
                            },
                            "example": {
                                "dryRun": true
                            }
                        }
                    }
                }
            }
        },
        "/api/billing/server-economics": {
            "get": {
                "operationId": "billingServerEconomics",
                "summary": "Get server economics",
                "description": "Read-only report per server: monthly cost, revenue from the billed sites it hosts (per currency), margin in the server's cost currency, revenue per site and the latest CPU/RAM/disk utilisation sample.\n\n**Roles:** admin.\n\n- Sites with serverId null are counted under the local server. Revenue counts non-cancelled subscriptions only.\n\n- marginMinor and revenuePerSiteMinor only use revenue in the server's costCurrency (default GEL); revenue in other currencies appears only in revenueByCurrency.\n\n- utilization is null when the server has no metric sample.\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: enforcement and reports"
                ],
                "responses": {
                    "200": {
                        "description": "Per-server cost, revenue, margin and utilisation.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "servers": [
                                        {
                                            "serverId": 1,
                                            "name": "Local",
                                            "kind": "local",
                                            "siteCount": 4,
                                            "billedSiteCount": 3,
                                            "costMinor": 8000,
                                            "costCurrency": "GEL",
                                            "costFormatted": "80.00 ₾",
                                            "revenueByCurrency": [
                                                {
                                                    "currency": "GEL",
                                                    "minor": 9000,
                                                    "formatted": "90.00 ₾"
                                                }
                                            ],
                                            "marginMinor": 1000,
                                            "marginCurrency": "GEL",
                                            "marginFormatted": "10.00 ₾",
                                            "revenuePerSiteMinor": 2250,
                                            "utilization": {
                                                "cpu": 23.5,
                                                "ram": 61.2,
                                                "disk": 48,
                                                "at": "2026-11-27T10:00:00.000Z"
                                            }
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/billing/subscriptions": {
            "get": {
                "operationId": "billingSubscriptionsList",
                "summary": "List subscriptions",
                "description": "Lists every subscription (cancelled included), ordered by id, with its site, client and plan.\n\n**Roles:** admin.\n\n- status: active | past_due | suspended | cancelled | paused. enforcementLevel: none | banner | restrict | suspend | archived. amount in minor units.\n\n- Embedded client rows include portalToken; site rows are full Site rows.\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: plans and subscriptions"
                ],
                "responses": {
                    "200": {
                        "description": "Array of Subscription rows with site, client and plan.",
                        "content": {
                            "application/json": {
                                "example": [
                                    {
                                        "id": 5,
                                        "siteId": 7,
                                        "clientId": 12,
                                        "planId": 3,
                                        "amount": 3000,
                                        "currency": "GEL",
                                        "interval": "monthly",
                                        "intervalDays": null,
                                        "anchorDay": 1,
                                        "startDate": "2026-11-27T10:00:00.000Z",
                                        "nextInvoiceAt": "2026-12-01T00:00:00.000Z",
                                        "status": "active",
                                        "enforcementLevel": "none",
                                        "lastEnforcedAt": null,
                                        "neverAutoSuspend": false,
                                        "gracePeriodDays": 3,
                                        "dunningPolicy": "",
                                        "suspendedAt": null,
                                        "cancelledAt": null,
                                        "createdAt": "2026-11-27T10:00:00.000Z",
                                        "updatedAt": "2026-11-27T10:00:00.000Z",
                                        "site": {
                                            "id": 7,
                                            "domain": "shop.example.com",
                                            "serverId": null,
                                            "status": "active",
                                            "phpVersion": "8.3"
                                        },
                                        "client": {
                                            "id": 12,
                                            "name": "Ada Lovelace",
                                            "email": "ada@example.com",
                                            "phone": "+995 555 12 34 56",
                                            "telegramChatId": null,
                                            "company": "Example LLC",
                                            "taxId": "404123456",
                                            "currency": "GEL",
                                            "locale": "en",
                                            "portalToken": "9f1c2e7a4b6d8f0a1c3e5a7b9d1f3a5c7e9b1d3f5a7c9e1b",
                                            "notes": null,
                                            "archived": false,
                                            "createdAt": "2026-11-27T10:00:00.000Z",
                                            "updatedAt": "2026-11-27T10:00:00.000Z"
                                        },
                                        "plan": {
                                            "id": 3,
                                            "name": "Standard",
                                            "amount": 3000,
                                            "currency": "GEL",
                                            "interval": "monthly",
                                            "intervalDays": null,
                                            "dunningPolicy": "",
                                            "gracePeriodDays": 3,
                                            "autoSuspend": true,
                                            "archived": false,
                                            "createdAt": "2026-11-27T10:00:00.000Z",
                                            "updatedAt": "2026-11-27T10:00:00.000Z"
                                        }
                                    }
                                ]
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "billingSubscriptionsCreate",
                "summary": "Create a subscription",
                "description": "Starts billing a site for a client. Price, currency, interval and grace period come from the body, falling back to the plan. The first invoice is due at startDate (default now) and is issued by the next billing tick. A site can hold only one subscription: if its previous one was cancelled, that row is reactivated in place (same id and invoice history, leftover open invoices voided, enforcement cleared).\n\n**Roles:** admin.\n\n- Money: every stored/returned amount is an INTEGER in the currency's minor unit (tetri for GEL, cents for USD/EUR; 3000 = 30.00). Where a field accepts both, a JSON number is taken as minor units as-is, while a string is parsed as MAJOR units (\"30\", \"30.5\", \"1 200,75\" — whitespace removed, comma accepted as decimal separator, rounded half-up to 2 decimals). Here the schema limits amount to an integer or a string.\n\n- Audit action is billing.subscription_reactivated instead when a cancelled subscription is reused. Both return 201.\n\n- nextInvoiceAt is set to startDate, so the first invoice is issued (due immediately) by the next tick once startDate has passed, or right away with POST /subscriptions/{id}/issue-invoice.\n\n- A planId that does not exist is treated as \"no plan\"; a siteId/clientId that does not exist makes Prisma throw → 500.\n\n- Passing dunningPolicy as a string stores it double-encoded (→ default ladder when read). Send an array.\n\n- Unknown body fields are removed silently (additionalProperties: false). status/enforcementLevel cannot be set.\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: plans and subscriptions"
                ],
                "responses": {
                    "201": {
                        "description": "The created or reactivated Subscription row with site and client.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 5,
                                    "siteId": 7,
                                    "clientId": 12,
                                    "planId": 3,
                                    "amount": 3000,
                                    "currency": "GEL",
                                    "interval": "monthly",
                                    "intervalDays": null,
                                    "anchorDay": 1,
                                    "startDate": "2026-11-27T10:00:00.000Z",
                                    "nextInvoiceAt": "2026-12-01T00:00:00.000Z",
                                    "status": "active",
                                    "enforcementLevel": "none",
                                    "lastEnforcedAt": null,
                                    "neverAutoSuspend": false,
                                    "gracePeriodDays": 3,
                                    "dunningPolicy": "",
                                    "suspendedAt": null,
                                    "cancelledAt": null,
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z",
                                    "site": {
                                        "id": 7,
                                        "domain": "shop.example.com",
                                        "serverId": null,
                                        "status": "active",
                                        "phpVersion": "8.3"
                                    },
                                    "client": {
                                        "id": 12,
                                        "name": "Ada Lovelace",
                                        "email": "ada@example.com",
                                        "phone": "+995 555 12 34 56",
                                        "telegramChatId": null,
                                        "company": "Example LLC",
                                        "taxId": "404123456",
                                        "currency": "GEL",
                                        "locale": "en",
                                        "portalToken": "9f1c2e7a4b6d8f0a1c3e5a7b9d1f3a5c7e9b1d3f5a7c9e1b",
                                        "notes": null,
                                        "archived": false,
                                        "createdAt": "2026-11-27T10:00:00.000Z",
                                        "updatedAt": "2026-11-27T10:00:00.000Z"
                                    }
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "No amount in the body or plan, it does not parse, or it is ≤ 0. — \"Invalid amount\"\n\nSchema validation failure (FST_ERR_VALIDATION; message varies). — \"body must have required property 'siteId'\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid amount"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "The site already has a subscription that is not cancelled. — \"This site already has a subscription.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "This site already has a subscription."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "siteId": {
                                        "type": "integer",
                                        "description": "Site to bill."
                                    },
                                    "clientId": {
                                        "type": "integer",
                                        "description": "Client who pays."
                                    },
                                    "planId": {
                                        "type": "integer",
                                        "description": "Plan to inherit defaults from. (nullable)"
                                    },
                                    "amount": {
                                        "type": "integer",
                                        "description": "Price per period: integer = minor units (3000), string = major units (\"30.00\"). Falls back to the plan amount. (integer (minor units) or string (major units); must resolve to > 0)"
                                    },
                                    "currency": {
                                        "type": "string",
                                        "description": "Currency; falls back to the plan, then GEL. (one of: GEL, USD, EUR)"
                                    },
                                    "interval": {
                                        "type": "string",
                                        "description": "Billing interval; falls back to the plan, then monthly. (one of: monthly, yearly, custom_days)"
                                    },
                                    "intervalDays": {
                                        "type": "integer",
                                        "description": "Days per period for custom_days; falls back to the plan. (nullable)"
                                    },
                                    "anchorDay": {
                                        "type": "integer",
                                        "description": "Day of the month invoices are anchored to (monthly/yearly). (1–28, nullable)"
                                    },
                                    "startDate": {
                                        "type": "string",
                                        "description": "Start of the first period (and due date of the first invoice). Default now. (date string parsed with new Date(); an invalid date fails with 500)"
                                    },
                                    "gracePeriodDays": {
                                        "type": "integer",
                                        "description": "Days past due before enforcement; falls back to the plan, then 3. (0–60)"
                                    },
                                    "neverAutoSuspend": {
                                        "type": "boolean",
                                        "description": "VIP valve: never escalate past banner. (default false)"
                                    },
                                    "dunningPolicy": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Dunning ladder: JSON array of steps { offsetDays: integer (days relative to the invoice due date; negative = before it is due), action: one of remind, invoice_due, banner, restrict, suspend, stop_workers, final_warning, archive }. Stored JSON-stringified; empty/omitted = inherit (subscription → plan → built-in default ladder). Invalid steps are dropped when read; if nothing valid remains the default ladder is used. (any JSON accepted by the schema; JSON-stringified when truthy)"
                                    }
                                },
                                "required": [
                                    "siteId",
                                    "clientId"
                                ]
                            },
                            "example": {
                                "siteId": 7,
                                "clientId": 12,
                                "planId": 3,
                                "amount": "30.00",
                                "currency": "GEL",
                                "interval": "monthly",
                                "anchorDay": 1,
                                "startDate": "2026-12-01",
                                "gracePeriodDays": 3,
                                "neverAutoSuspend": false
                            }
                        }
                    }
                }
            }
        },
        "/api/billing/subscriptions/{id}": {
            "patch": {
                "operationId": "billingSubscriptionsUpdate",
                "summary": "Update a subscription",
                "description": "Updates a subscription's billing terms. The body is passed to the database after removing id, siteId and the serving-layer state fields (enforcementLevel, status, suspendedAt, lastEnforcedAt), which only change through enforcement. A string amount is parsed from major units, an array dunningPolicy is JSON-stringified, and startDate / nextInvoiceAt strings are converted to dates.\n\n**Roles:** admin.\n\n- Money: every stored/returned amount is an INTEGER in the currency's minor unit (tetri for GEL, cents for USD/EUR; 3000 = 30.00). Where a field accepts both, a JSON number is taken as minor units as-is, while a string is parsed as MAJOR units (\"30\", \"30.5\", \"1 200,75\" — whitespace removed, comma accepted as decimal separator, rounded half-up to 2 decimals).\n\n- enforcementLevel, status, suspendedAt, lastEnforcedAt, id and siteId are silently dropped. Use /enforce to change the level and DELETE to cancel; there is no API to set status paused.\n\n- No request schema: unknown fields or wrong types make Prisma throw → 500. No subscription with this id makes the Prisma call throw; there is no 404 branch, so Fastify's default error handler answers 500.\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: plans and subscriptions"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Subscription id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The updated Subscription row (no relations).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 5,
                                    "siteId": 7,
                                    "clientId": 12,
                                    "planId": 3,
                                    "amount": 4500,
                                    "currency": "GEL",
                                    "interval": "monthly",
                                    "intervalDays": null,
                                    "anchorDay": 1,
                                    "startDate": "2026-11-27T10:00:00.000Z",
                                    "nextInvoiceAt": "2026-12-01T00:00:00.000Z",
                                    "status": "active",
                                    "enforcementLevel": "none",
                                    "lastEnforcedAt": null,
                                    "neverAutoSuspend": true,
                                    "gracePeriodDays": 3,
                                    "dunningPolicy": "",
                                    "suspendedAt": null,
                                    "cancelledAt": null,
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "clientId": {
                                        "type": "integer",
                                        "description": "Move the subscription to another client. (not validated)"
                                    },
                                    "planId": {
                                        "type": "integer",
                                        "description": "Plan id or null. (not validated)"
                                    },
                                    "amount": {
                                        "type": "integer",
                                        "description": "Price: number = minor units; string = major units (parsed with body currency, default GEL decimals). (not validated; an unparseable string is silently ignored)"
                                    },
                                    "currency": {
                                        "type": "string",
                                        "description": "GEL, USD or EUR. (not validated)"
                                    },
                                    "interval": {
                                        "type": "string",
                                        "description": "monthly, yearly or custom_days. (not validated)"
                                    },
                                    "intervalDays": {
                                        "type": "integer",
                                        "description": "Days per period for custom_days. (not validated)"
                                    },
                                    "anchorDay": {
                                        "type": "integer",
                                        "description": "Billing day of month. (not validated (1–28 is only enforced on create; values are clamped to 1–28 when computing dates))"
                                    },
                                    "startDate": {
                                        "type": "string",
                                        "description": "Subscription start date. (not validated; converted with new Date() when truthy)"
                                    },
                                    "nextInvoiceAt": {
                                        "type": "string",
                                        "description": "When the next invoice is issued (moves the billing anchor). (not validated; converted with new Date() when truthy)"
                                    },
                                    "gracePeriodDays": {
                                        "type": "integer",
                                        "description": "Grace period in days. (not validated)"
                                    },
                                    "neverAutoSuspend": {
                                        "type": "boolean",
                                        "description": "VIP valve: never escalate past banner. (not validated)"
                                    },
                                    "dunningPolicy": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Dunning ladder: JSON array of steps { offsetDays: integer (days relative to the invoice due date; negative = before it is due), action: one of remind, invoice_due, banner, restrict, suspend, stop_workers, final_warning, archive }. Stored JSON-stringified; empty/omitted = inherit (subscription → plan → built-in default ladder). Invalid steps are dropped when read; if nothing valid remains the default ladder is used. null/\"\"/false clears the override (inherit); a string is stored verbatim. (not validated)"
                                    }
                                }
                            },
                            "example": {
                                "amount": "45.00",
                                "neverAutoSuspend": true
                            }
                        }
                    }
                }
            },
            "delete": {
                "operationId": "billingSubscriptionsCancel",
                "summary": "Cancel a subscription",
                "description": "Stops billing a site. Any enforcement on the site is lifted first (always applied, regardless of the master switch), every still-open invoice (open, partial, overdue) is voided, and the subscription is marked cancelled. The row is kept so billing can be re-added later (POST /subscriptions reactivates it).\n\n**Roles:** admin.\n\n- Not a hard delete: status → cancelled, cancelledAt set, enforcementLevel → none. A billing event of type cancelled is recorded.\n\n- Partially paid invoices are voided too (their payments stay recorded).\n\n- No subscription with this id makes the Prisma call throw; there is no 404 branch, so Fastify's default error handler answers 500.\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: plans and subscriptions"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Subscription id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Cancellation result with the number of voided invoices.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "cancelled": true,
                                    "invoicesVoided": 1
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/billing/subscriptions/{id}/enforce": {
            "post": {
                "operationId": "billingSubscriptionsEnforce",
                "summary": "Force an enforcement level",
                "description": "Manually moves one subscription's site to an enforcement level. \"none\" restores the site and is always applied; banner, restrict and suspend go through the same guarded path as the tick and respect the master switch, the neverAutoSuspend cap and running deploys. When applied, the subscription's enforcementLevel, status, suspendedAt and lastEnforcedAt are updated.\n\n**Roles:** admin.\n\n- Response shape: { applied: boolean, dryRun: boolean, from: level, to: level, reason?: string, output?: string } — always 200, even when nothing was applied. Typical reasons: \"billing enforcement is off\", \"already at this level\", \"site is deploying — deferred\", \"dry run: would move none → banner\", \"site not found\", \"apply failed: <message>\". output is the site-suspend.sh stdout+stderr when applied.\n\n- to is the capped level: with neverAutoSuspend=true, restrict/suspend are capped to banner.\n\n- \"none\" is forced: it bypasses the \"off\" switch and also dry_run mode (the site really is restored).\n\n- Status mapping on success: none → active, suspend → suspended, banner/restrict → past_due. \"archived\" cannot be requested here (only the tick's archive rung reaches it).\n\n- Audit: the route itself writes no audit entry; the enforcer writes billing.enforce on a successful apply (without a user id) or billing.enforce_failed when the script fails. A BillingEvent row is recorded for every attempt except the \"already at this level\" no-op.\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: enforcement and reports"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Subscription id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "What the enforcer did.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "applied": true,
                                    "dryRun": false,
                                    "from": "none",
                                    "to": "banner",
                                    "output": "billing enforcement for shop.example.com set to: banner\n"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "level missing or invalid (schema validation). — \"body/level must be equal to one of the allowed values\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "body/level must be equal to one of the allowed values"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No subscription with this id, or its site no longer exists. — \"Subscription not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Subscription not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "level": {
                                        "type": "string",
                                        "description": "Target level. (one of: none, banner, restrict, suspend)"
                                    }
                                },
                                "required": [
                                    "level"
                                ]
                            },
                            "example": {
                                "level": "banner"
                            }
                        }
                    }
                }
            }
        },
        "/api/billing/subscriptions/{id}/events": {
            "get": {
                "operationId": "billingSubscriptionsEvents",
                "summary": "List subscription billing events",
                "description": "Returns the newest 100 billing events of a subscription (invoices issued, payments, notifications, enforcement transitions, dry runs, voids, cancellation).\n\n**Roles:** admin.\n\n- Types written by the code: invoice_issued, payment_recorded, invoice_voided, cancelled, notify:<action> (remind, invoice_due, final_warning), dry_run (an enforcement that was not applied, with detail = reason), and the applied level name (banner, restrict, suspend, archived) or restored.\n\n- An unknown subscription id returns [] (no 404).\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: plans and subscriptions"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Subscription id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Array of BillingEvent rows, newest first.",
                        "content": {
                            "application/json": {
                                "example": [
                                    {
                                        "id": 88,
                                        "subscriptionId": 5,
                                        "invoiceId": 42,
                                        "type": "banner",
                                        "fromLevel": "none",
                                        "toLevel": "banner",
                                        "detail": null,
                                        "dryRun": false,
                                        "createdAt": "2026-11-27T10:00:00.000Z"
                                    },
                                    {
                                        "id": 87,
                                        "subscriptionId": 5,
                                        "invoiceId": 42,
                                        "type": "notify:invoice_due",
                                        "fromLevel": null,
                                        "toLevel": null,
                                        "detail": "Hosting payment due today",
                                        "dryRun": false,
                                        "createdAt": "2026-11-27T10:00:00.000Z"
                                    }
                                ]
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/billing/subscriptions/{id}/issue-invoice": {
            "post": {
                "operationId": "billingSubscriptionsIssueInvoice",
                "summary": "Issue the next invoice now",
                "description": "Issues the invoice for the subscription's current billing period (starting at nextInvoiceAt) immediately and advances the billing anchor to the next period. The invoice number is allocated sequentially per year (INV-<year>-<4-digit seq>) and the invoice is due at the period start.\n\n**Roles:** admin.\n\n- Idempotent per period: if a non-void invoice already covers the period it is returned instead of creating a duplicate (the anchor is moved past it).\n\n- It does not wait for nextInvoiceAt to arrive: calling it repeatedly issues one invoice per call for successive future periods.\n\n- amount is in minor units (a snapshot of the subscription amount). The created Invoice has status open and one line item \"Hosting — <domain>\".\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: invoices and payments"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Subscription id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The issued (or already existing) invoice summary.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 42,
                                    "number": "INV-2026-0042",
                                    "amount": 3000,
                                    "currency": "GEL",
                                    "dueDate": "2026-11-01T00:00:00.000Z"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "No subscription with this id, or its status is cancelled or paused. — \"Nothing to invoice (cancelled/paused subscription?)\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Nothing to invoice (cancelled/paused subscription?)"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/billing/subscriptions/{id}/preview": {
            "get": {
                "operationId": "billingSubscriptionsPreview",
                "summary": "Preview next dunning step",
                "description": "Read-only \"what happens next\" for one subscription: the oldest unpaid invoice, days overdue, the level the site should be at now and the next ladder step that can actually fire (steps beyond the neverAutoSuspend/autoSuspend cap are skipped).\n\n**Roles:** admin.\n\n- When nothing is owed the shape is reduced: { domain, currentLevel, balance: 0, daysOverdue: null, targetLevel: \"none\", next: null, policy }.\n\n- balance is in minor units; next is null when no further step can fire; next.level is null for notify-only actions; policy is the effective ladder (subscription → plan → default).\n\n- Works for any status including cancelled; it does not check the master switch.\n\n- All /api/billing routes are admin-only (file-level preHandler hooks: authenticate + requireRole(['admin'])).",
                "tags": [
                    "Billing: plans and subscriptions"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Subscription id. (not validated (Number(...) of the path segment))",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Preview of the subscription's dunning state.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "domain": "shop.example.com",
                                    "invoice": "INV-2026-0042",
                                    "balance": 2000,
                                    "currency": "GEL",
                                    "daysOverdue": 5,
                                    "currentLevel": "banner",
                                    "targetLevel": "banner",
                                    "withinGrace": false,
                                    "cappedByPolicy": false,
                                    "next": {
                                        "action": "restrict",
                                        "level": "restrict",
                                        "date": "2026-11-08T00:00:00.000Z",
                                        "daysAway": 2
                                    },
                                    "policy": [
                                        {
                                            "offsetDays": -7,
                                            "action": "remind"
                                        },
                                        {
                                            "offsetDays": 0,
                                            "action": "invoice_due"
                                        },
                                        {
                                            "offsetDays": 4,
                                            "action": "banner"
                                        },
                                        {
                                            "offsetDays": 7,
                                            "action": "restrict"
                                        },
                                        {
                                            "offsetDays": 10,
                                            "action": "suspend"
                                        },
                                        {
                                            "offsetDays": 30,
                                            "action": "stop_workers"
                                        },
                                        {
                                            "offsetDays": 60,
                                            "action": "final_warning"
                                        },
                                        {
                                            "offsetDays": 90,
                                            "action": "archive"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No subscription with this id. — \"Subscription not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Subscription not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/calendar/events": {
            "get": {
                "operationId": "calendarEventsList",
                "summary": "List calendar entries",
                "description": "Returns the calendar entries in a date range: stored events (recurring ones expanded into individual occurrences) followed by virtual entries for task due dates. Every user sees all stored events; non-admins see only due dates of their own tasks (created or assigned).\n\n**Roles:** admin, developer, viewer.\n\n- ids are strings: \"event-<id>\" for the first occurrence of a stored event in the range, \"event-<id>-<n>\" for later occurrences in the range (n counts occurrences within the range), and \"task-<taskId>\" for task due dates. Virtual task entries are never stored and cannot be edited through the event endpoints.\n\n- Recurrence: daily and weekly advance by a fixed 24 h / 7 d; monthly advances by calendar month. Expansion starts at the event's first startAt and stops after 500 steps, counting steps before the range too, so very old recurring events eventually stop producing occurrences.\n\n- Task due-date colours: #d72c0d for urgent, #e4a11b for high, #5c6ac4 otherwise.\n\n- editable is true for every stored event when the caller is an admin, false otherwise. Results are not sorted.\n\n- reminderMins is not included in list entries (use GET /api/calendar/events/{id}).\n\n- Unparseable start/end values are not rejected cleanly and can lead to a 500 error.",
                "tags": [
                    "Tasks, notes and calendar"
                ],
                "parameters": [
                    {
                        "name": "start",
                        "in": "query",
                        "required": false,
                        "description": "Range start (ISO 8601 date-time). (default now − 30 days; not validated)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "end",
                        "in": "query",
                        "required": false,
                        "description": "Range end (ISO 8601 date-time). (default now + 60 days; not validated)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "siteId",
                        "in": "query",
                        "required": false,
                        "description": "Only events and task due dates linked to this site. (not validated)",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Calendar entries in the range.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "events": [
                                        {
                                            "id": "event-3",
                                            "kind": "event",
                                            "title": "Monthly maintenance",
                                            "description": "Patch the server.",
                                            "type": "maintenance",
                                            "startAt": "2026-12-01T02:00:00.000Z",
                                            "endAt": "2026-12-01T03:00:00.000Z",
                                            "allDay": false,
                                            "color": "#5c6ac4",
                                            "recurrence": "monthly",
                                            "siteId": 12,
                                            "site": {
                                                "id": 12,
                                                "domain": "shop.example.com",
                                                "name": "Shop"
                                            },
                                            "taskId": null,
                                            "task": null,
                                            "createdBy": {
                                                "id": 1,
                                                "email": "ada@example.com"
                                            },
                                            "attendees": [
                                                {
                                                    "userId": 12,
                                                    "user": {
                                                        "id": 12,
                                                        "email": "grace@example.com"
                                                    }
                                                }
                                            ],
                                            "editable": true
                                        },
                                        {
                                            "id": "task-42",
                                            "kind": "task_due",
                                            "title": "Renew SSL for shop",
                                            "description": null,
                                            "type": "task_deadline",
                                            "startAt": "2026-11-30T00:00:00.000Z",
                                            "endAt": null,
                                            "allDay": true,
                                            "color": "#e4a11b",
                                            "recurrence": null,
                                            "siteId": 12,
                                            "site": {
                                                "id": 12,
                                                "domain": "shop.example.com",
                                                "name": "Shop"
                                            },
                                            "taskId": 42,
                                            "task": {
                                                "id": 42,
                                                "title": "Renew SSL for shop",
                                                "status": "in_progress"
                                            },
                                            "createdBy": null,
                                            "attendees": [],
                                            "editable": false
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "calendarEventsCreate",
                "summary": "Create a calendar event",
                "description": "Creates a calendar event, optionally recurring, linked to a site or task, and with attendees. Admin only.\n\n**Roles:** admin.\n\n- The admin check is a file-level preHandler hook, so body validation (400) runs before it.\n\n- reminderMins is stored and returned but nothing in the API sends reminders.\n\n- Unparseable dates, duplicate attendee ids or non-existent site/task/user ids are rejected by the database and surface as a 500 error.",
                "tags": [
                    "Tasks, notes and calendar"
                ],
                "responses": {
                    "201": {
                        "description": "The created event (same shape as GET /api/calendar/events/{id}).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 3,
                                    "title": "Monthly maintenance",
                                    "description": "Patch the server.",
                                    "type": "maintenance",
                                    "startAt": "2026-12-01T02:00:00.000Z",
                                    "endAt": "2026-12-01T03:00:00.000Z",
                                    "allDay": false,
                                    "color": "#5c6ac4",
                                    "recurrence": "monthly",
                                    "reminderMins": 30,
                                    "siteId": 12,
                                    "taskId": null,
                                    "createdById": 1,
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z",
                                    "site": {
                                        "id": 12,
                                        "domain": "shop.example.com",
                                        "name": "Shop"
                                    },
                                    "task": null,
                                    "createdBy": {
                                        "id": 1,
                                        "email": "ada@example.com"
                                    },
                                    "attendees": [
                                        {
                                            "userId": 12,
                                            "user": {
                                                "id": 12,
                                                "email": "grace@example.com"
                                            }
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nThe caller is not an admin. — \"Only admins can manage calendar events.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "title": {
                                        "type": "string",
                                        "description": "Event title. (1–200 chars)"
                                    },
                                    "description": {
                                        "type": "string",
                                        "description": "Description. (max 5000 chars)"
                                    },
                                    "type": {
                                        "type": "string",
                                        "description": "Event type; the UI uses custom, reminder, maintenance. (max 50 chars; default custom; values not restricted)"
                                    },
                                    "startAt": {
                                        "type": "string",
                                        "description": "Start (ISO 8601 date-time). (format not validated)"
                                    },
                                    "endAt": {
                                        "type": "string",
                                        "description": "End (ISO 8601 date-time). (format not validated)"
                                    },
                                    "allDay": {
                                        "type": "boolean",
                                        "description": "All-day event. (default false)"
                                    },
                                    "color": {
                                        "type": "string",
                                        "description": "Display colour, e.g. a hex code. (max 20 chars)"
                                    },
                                    "recurrence": {
                                        "type": "string",
                                        "description": "Repeat rule; omit for a one-off event. (one of: daily, weekly, monthly)"
                                    },
                                    "reminderMins": {
                                        "type": "integer",
                                        "description": "Reminder offset in minutes (stored only)."
                                    },
                                    "siteId": {
                                        "type": "integer",
                                        "description": "Linked site."
                                    },
                                    "taskId": {
                                        "type": "integer",
                                        "description": "Linked task."
                                    },
                                    "attendeeIds": {
                                        "type": "array",
                                        "items": {},
                                        "description": "User ids of attendees (array of integers). (items: integer)"
                                    }
                                },
                                "required": [
                                    "title",
                                    "startAt"
                                ]
                            },
                            "example": {
                                "title": "Monthly maintenance",
                                "description": "Patch the server.",
                                "type": "maintenance",
                                "startAt": "2026-12-01T02:00:00.000Z",
                                "endAt": "2026-12-01T03:00:00.000Z",
                                "allDay": false,
                                "color": "#5c6ac4",
                                "recurrence": "monthly",
                                "reminderMins": 30,
                                "siteId": 12,
                                "attendeeIds": [
                                    12
                                ]
                            }
                        }
                    }
                }
            }
        },
        "/api/calendar/events/{id}": {
            "get": {
                "operationId": "calendarEventsGet",
                "summary": "Get a calendar event",
                "description": "Returns one stored calendar event as saved (not expanded for recurrence). Available to every role.\n\n**Roles:** admin, developer, viewer.",
                "tags": [
                    "Tasks, notes and calendar"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Numeric event id (without the \"event-\" prefix used in the list).",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The event.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 3,
                                    "title": "Monthly maintenance",
                                    "description": "Patch the server.",
                                    "type": "maintenance",
                                    "startAt": "2026-12-01T02:00:00.000Z",
                                    "endAt": "2026-12-01T03:00:00.000Z",
                                    "allDay": false,
                                    "color": "#5c6ac4",
                                    "recurrence": "monthly",
                                    "reminderMins": 30,
                                    "siteId": 12,
                                    "taskId": null,
                                    "createdById": 1,
                                    "createdAt": "2026-11-20T09:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z",
                                    "site": {
                                        "id": 12,
                                        "domain": "shop.example.com",
                                        "name": "Shop"
                                    },
                                    "task": null,
                                    "createdBy": {
                                        "id": 1,
                                        "email": "ada@example.com"
                                    },
                                    "attendees": [
                                        {
                                            "userId": 12,
                                            "user": {
                                                "id": 12,
                                                "email": "grace@example.com"
                                            }
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No event with this id. — \"Event not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Event not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "patch": {
                "operationId": "calendarEventsUpdate",
                "summary": "Update a calendar event",
                "description": "Changes a calendar event. Only the fields sent are changed; attendeeIds, when sent, replaces the whole attendee list. Admin only.\n\n**Roles:** admin.\n\n- The attendee replacement is written before the event update and not in a transaction; if the event update then fails, the new attendee list is kept.\n\n- Unparseable dates, duplicate attendee ids or non-existent site/task/user ids surface as a 500 error.",
                "tags": [
                    "Tasks, notes and calendar"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Numeric event id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The updated event.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 3,
                                    "title": "Monthly maintenance",
                                    "description": "Patch the server.",
                                    "type": "maintenance",
                                    "startAt": "2026-12-02T02:00:00.000Z",
                                    "endAt": "2026-12-02T03:00:00.000Z",
                                    "allDay": false,
                                    "color": "#5c6ac4",
                                    "recurrence": "monthly",
                                    "reminderMins": 30,
                                    "siteId": 12,
                                    "taskId": null,
                                    "createdById": 1,
                                    "createdAt": "2026-11-20T09:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z",
                                    "site": {
                                        "id": 12,
                                        "domain": "shop.example.com",
                                        "name": "Shop"
                                    },
                                    "task": null,
                                    "createdBy": {
                                        "id": 1,
                                        "email": "ada@example.com"
                                    },
                                    "attendees": [
                                        {
                                            "userId": 12,
                                            "user": {
                                                "id": 12,
                                                "email": "grace@example.com"
                                            }
                                        },
                                        {
                                            "userId": 15,
                                            "user": {
                                                "id": 15,
                                                "email": "linus@example.com"
                                            }
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nThe caller is not an admin. — \"Only admins can manage calendar events.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No event with this id. — \"Event not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Event not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "title": {
                                        "type": "string",
                                        "description": "Event title. (1–200 chars)"
                                    },
                                    "description": {
                                        "type": "string",
                                        "description": "Description; null clears it. (max 5000 chars, nullable)"
                                    },
                                    "type": {
                                        "type": "string",
                                        "description": "Event type. (max 50 chars)"
                                    },
                                    "startAt": {
                                        "type": "string",
                                        "description": "Start (ISO 8601 date-time). (format not validated)"
                                    },
                                    "endAt": {
                                        "type": "string",
                                        "description": "End; null or empty string clears it. (nullable; format not validated)"
                                    },
                                    "allDay": {
                                        "type": "boolean",
                                        "description": "All-day event."
                                    },
                                    "color": {
                                        "type": "string",
                                        "description": "Display colour; null clears it. (max 20 chars, nullable)"
                                    },
                                    "recurrence": {
                                        "type": "string",
                                        "description": "Repeat rule; null makes it a one-off event. (one of: daily, weekly, monthly; nullable)"
                                    },
                                    "reminderMins": {
                                        "type": "integer",
                                        "description": "Reminder offset in minutes; null clears it. (nullable)"
                                    },
                                    "siteId": {
                                        "type": "integer",
                                        "description": "Linked site; null unlinks. (nullable)"
                                    },
                                    "taskId": {
                                        "type": "integer",
                                        "description": "Linked task; null unlinks. (nullable)"
                                    },
                                    "attendeeIds": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Replaces all attendees (array of user ids); [] removes all. (items: integer)"
                                    }
                                }
                            },
                            "example": {
                                "startAt": "2026-12-02T02:00:00.000Z",
                                "endAt": "2026-12-02T03:00:00.000Z",
                                "attendeeIds": [
                                    12,
                                    15
                                ]
                            }
                        }
                    }
                }
            },
            "delete": {
                "operationId": "calendarEventsDelete",
                "summary": "Delete a calendar event",
                "description": "Deletes a calendar event with all its occurrences and attendees. Admin only.\n\n**Roles:** admin.\n\n- Single occurrences of a recurring event cannot be deleted; this always removes the whole series.",
                "tags": [
                    "Tasks, notes and calendar"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Numeric event id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The event was deleted.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nThe caller is not an admin. — \"Only admins can manage calendar events.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No event with this id. — \"Event not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Event not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/dashboard": {
            "get": {
                "operationId": "dashboardGet",
                "summary": "Get dashboard layouts",
                "description": "Returns the caller's current (auto-saved) monitoring dashboard layout and their named layout presets. Layouts are private to each user.\n\n**Roles:** admin, developer, viewer.\n\n- config values are opaque strings stored as sent. The web client stores a JSON-encoded array of {id, width: \"half\"|\"full\", visible} widget entries.\n\n- auto is null until the working layout has been saved once. The auto layout is stored as a reserved preset named \"__auto__\", which is not included in presets.",
                "tags": [
                    "Dashboard"
                ],
                "responses": {
                    "200": {
                        "description": "The working layout (or null) and the named presets, most recently updated first.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "auto": "[{\"id\":\"metrics-history\",\"width\":\"full\",\"visible\":true},{\"id\":\"system-stats\",\"width\":\"half\",\"visible\":true}]",
                                    "presets": [
                                        {
                                            "id": 9,
                                            "name": "Incident view",
                                            "config": "[{\"id\":\"system-stats\",\"width\":\"full\",\"visible\":true}]",
                                            "updatedAt": "2026-11-27T10:00:00.000Z"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/dashboard/auto": {
            "put": {
                "operationId": "dashboardAutoSave",
                "summary": "Save the working layout",
                "description": "Creates or replaces the caller's current working dashboard layout. The web client calls it, debounced, whenever the layout changes.\n\n**Roles:** admin, developer, viewer.\n\n- The content of config is not parsed or validated beyond its length.",
                "tags": [
                    "Dashboard"
                ],
                "responses": {
                    "200": {
                        "description": "The layout was saved.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "config": {
                                        "type": "string",
                                        "description": "Layout as an opaque string (the web client sends a JSON-encoded widget array). (max 20000 chars)"
                                    }
                                },
                                "required": [
                                    "config"
                                ]
                            },
                            "example": {
                                "config": "[{\"id\":\"metrics-history\",\"width\":\"full\",\"visible\":true}]"
                            }
                        }
                    }
                }
            }
        },
        "/api/dashboard/presets": {
            "post": {
                "operationId": "dashboardPresetsSave",
                "summary": "Save a named layout preset",
                "description": "Creates a named dashboard layout preset for the caller, or replaces the layout of the caller's existing preset with the same name.\n\n**Roles:** admin, developer, viewer.\n\n- Returns 201 both when a preset is created and when an existing one with the same name is overwritten.",
                "tags": [
                    "Dashboard"
                ],
                "responses": {
                    "201": {
                        "description": "The created or replaced preset.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 9,
                                    "name": "Incident view",
                                    "config": "[{\"id\":\"system-stats\",\"width\":\"full\",\"visible\":true}]",
                                    "updatedAt": "2026-11-27T10:00:00.000Z"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The trimmed name is \"__auto__\". — \"That name is reserved.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "That name is reserved."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Preset name (leading/trailing spaces are trimmed). Unique per user. (1–60 chars; \"__auto__\" is reserved)"
                                    },
                                    "config": {
                                        "type": "string",
                                        "description": "Layout as an opaque string (the web client sends a JSON-encoded widget array). (max 20000 chars)"
                                    }
                                },
                                "required": [
                                    "name",
                                    "config"
                                ]
                            },
                            "example": {
                                "name": "Incident view",
                                "config": "[{\"id\":\"system-stats\",\"width\":\"full\",\"visible\":true}]"
                            }
                        }
                    }
                }
            }
        },
        "/api/dashboard/presets/{id}": {
            "delete": {
                "operationId": "dashboardPresetsDelete",
                "summary": "Delete a layout preset",
                "description": "Deletes one of the caller's named dashboard presets.\n\n**Roles:** admin, developer, viewer.",
                "tags": [
                    "Dashboard"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Preset id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The preset was deleted.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The id is that of the caller's working (\"__auto__\") layout. — \"The auto layout cannot be deleted.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "The auto layout cannot be deleted."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No preset with this id, or it belongs to another user. — \"Preset not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Preset not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/digest": {
            "get": {
                "operationId": "digestGet",
                "summary": "Get weekly digest settings",
                "description": "Returns the weekly digest configuration and a live preview of the digest for the last 7 days, computed from data already in the database. Admin only.\n\n**Roles:** admin.\n\n- day is the weekday the digest is sent on: 0 = Sunday … 6 = Saturday (server local time); defaults to 1 (Monday) when never set.\n\n- lastSent is the date (YYYY-MM-DD, UTC) of the last scheduled send, or null. Manual sends via POST /api/digest/send-now do not update it.\n\n- preview.uptimePct (one decimal) and preview.avgMs are null when there were no uptime checks in the period. errOpen counts unresolved, non-ignored log errors; errNew counts non-ignored log errors first seen in the period.",
                "tags": [
                    "Settings"
                ],
                "responses": {
                    "200": {
                        "description": "Digest configuration and preview.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "enabled": true,
                                    "day": 1,
                                    "lastSent": "2026-11-23",
                                    "preview": {
                                        "since": "2026-11-20T10:00:00.000Z",
                                        "deploySuccess": 14,
                                        "deployFailed": 1,
                                        "uptimePct": 99.8,
                                        "avgMs": 312,
                                        "errOpen": 3,
                                        "errNew": 2,
                                        "sites": 6
                                    }
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "patch": {
                "operationId": "digestUpdate",
                "summary": "Update weekly digest settings",
                "description": "Turns the weekly digest on or off and sets the weekday it is sent on. Admin only. Only the fields sent are changed.\n\n**Roles:** admin.\n\n- When enabled, an hourly background check sends the digest once on the configured weekday (server local time) to all configured notification channels and the in-app feed.\n\n- The audit entry stores the request body.",
                "tags": [
                    "Settings"
                ],
                "responses": {
                    "200": {
                        "description": "The settings were saved.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "enabled": {
                                        "type": "boolean",
                                        "description": "Send the digest automatically every week."
                                    },
                                    "day": {
                                        "type": "integer",
                                        "description": "Weekday to send on: 0 = Sunday … 6 = Saturday. (0–6)"
                                    }
                                }
                            },
                            "example": {
                                "enabled": true,
                                "day": 1
                            }
                        }
                    }
                }
            }
        },
        "/api/digest/send-now": {
            "post": {
                "operationId": "digestSendNow",
                "summary": "Send the weekly digest now",
                "description": "Builds the 7-day digest and sends it immediately to every configured notification channel (email, Slack, Discord, Telegram, generic webhook — whichever are set up), and adds it to the in-app notification feed. Admin only. Works whether or not the weekly digest is enabled.\n\n**Roles:** admin.\n\n- Does not update lastSent, so the scheduled send still happens on the configured weekday.\n\n- Channel delivery failures are not reported in the response.",
                "tags": [
                    "Settings"
                ],
                "responses": {
                    "200": {
                        "description": "The digest that was sent.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "digest": {
                                        "since": "2026-11-20T10:00:00.000Z",
                                        "deploySuccess": 14,
                                        "deployFailed": 1,
                                        "uptimePct": 99.8,
                                        "avgMs": 312,
                                        "errOpen": 3,
                                        "errNew": 2,
                                        "sites": 6
                                    }
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/directory": {
            "get": {
                "operationId": "directoryList",
                "summary": "List the user directory",
                "description": "Returns a minimal list of all panel users (id, email, role), sorted by email. Available to every role; used for assignee, share and attendee pickers.\n\n**Roles:** admin, developer, viewer.\n\n- Unlike GET /api/users this is not admin-only, and it exposes every user's email and role to any authenticated user.",
                "tags": [
                    "Dashboard"
                ],
                "responses": {
                    "200": {
                        "description": "All users, minimal fields.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "users": [
                                        {
                                            "id": 1,
                                            "email": "ada@example.com",
                                            "role": "admin"
                                        },
                                        {
                                            "id": 12,
                                            "email": "grace@example.com",
                                            "role": "developer"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/fleet/agent/binary/{file}": {
            "get": {
                "operationId": "fleetAgentBinary",
                "summary": "Download an agent binary",
                "description": "Downloads a prebuilt agent binary or its sha256 checksum file from the panel (strict allowlist of file names). Used by the installer and by agent self-updates.\n\n- The arch aliases (amd64, arm64) return the full binary orchestrator-agent-linux-<arch>; the Content-Disposition filename is always the full name.\n\n- Headers: Cache-Control: no-cache, X-Content-Type-Options: nosniff.",
                "tags": [
                    "Fleet agent"
                ],
                "parameters": [
                    {
                        "name": "file",
                        "in": "path",
                        "required": true,
                        "description": "File to download. (one of: orchestrator-agent-linux-amd64, orchestrator-agent-linux-arm64, orchestrator-agent-linux-amd64.sha256, orchestrator-agent-linux-arm64.sha256, and the aliases amd64, arm64, amd64.sha256, arm64.sha256)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The binary (application/octet-stream) or, for .sha256 files, the checksum as text/plain; charset=utf-8. Sent as an attachment with Content-Length.",
                        "content": {
                            "application/octet-stream": {
                                "schema": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "The file does not exist in apps/agent/dist. — \"Agent binaries are not built on this panel — run scripts/build-agent.sh\"\n\nfile is not in the allowlist. — \"Unknown agent file.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Agent binaries are not built on this panel — run scripts/build-agent.sh"
                                }
                            }
                        }
                    }
                },
                "x-auth": "public",
                "x-roles": [],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": []
            }
        },
        "/api/fleet/agent/enroll": {
            "post": {
                "operationId": "fleetAgentEnroll",
                "summary": "Enroll an agent",
                "description": "Called by the agent installer: exchanges a one-time enrollment token (from the panel's install command) for the server's permanent agent key. The token is consumed atomically, any previous agent key of the server stops working and a still-connected agent is disconnected.\n\n**Rate limit:** 10 per minute per IP.\n\n- No panel login: the enrollment token is the credential.\n\n- Only the sha256 of the agent key is stored. The agent then connects to the WebSocket /api/terminal/fleet/agent with Authorization: Bearer <agentKey>.\n\n- The server's agent status becomes \"pending\" until the agent connects.\n\n- The body schema has no additionalProperties:false, so unknown fields are accepted and ignored.\n\n- Protocol details: apps/agent/PROTOCOL.md.",
                "tags": [
                    "Fleet agent"
                ],
                "responses": {
                    "200": {
                        "description": "The server id and its agent key (format oa_<serverId>_<secret>), returned only once.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "serverId": 12,
                                    "agentKey": "oa_12_EXAMPLEagentKeyEXAMPLEagentKeyEXAMPLE12"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Unknown token (or its server no longer exists). — \"Invalid enrollment token.\"\n\nOlder than 1 hour. — \"This enrollment token has expired. Generate a new install command in the panel.\"\n\nThe token was used before, or a concurrent request consumed it first. — \"This enrollment token was already used. Generate a new install command in the panel.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid enrollment token."
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Too many requests — see the Retry-After header. — \"Rate limit exceeded, retry in …\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Rate limit exceeded, retry in …"
                                }
                            }
                        }
                    }
                },
                "x-auth": "public",
                "x-roles": [],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": [],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "token": {
                                        "type": "string",
                                        "description": "The enrollment token from the install command (trimmed). (16–200 chars)"
                                    },
                                    "mode": {
                                        "type": "string",
                                        "description": "The agent's own configured mode (stored as the server's agentMode; the token's mode is only recorded in the audit log). (one of: control, monitor)"
                                    },
                                    "hostname": {
                                        "type": "string",
                                        "description": "Machine hostname (stored in the server's system info). (max 255 chars)"
                                    },
                                    "arch": {
                                        "type": "string",
                                        "description": "CPU architecture, e.g. amd64 or arm64. (max 16 chars; stored only when it matches ^[a-z0-9_]{1,16}$)"
                                    },
                                    "version": {
                                        "type": "string",
                                        "description": "Agent version. (max 64 chars)"
                                    },
                                    "machineId": {
                                        "type": "string",
                                        "description": "Machine id (e.g. /etc/machine-id). (max 128 chars)"
                                    }
                                },
                                "required": [
                                    "token",
                                    "mode"
                                ]
                            },
                            "example": {
                                "token": "3q2-7wEXAMPLEtokenEXAMPLEtokenEXAMPLE1234",
                                "mode": "control",
                                "hostname": "web-1",
                                "arch": "amd64",
                                "version": "1.4.0",
                                "machineId": "5f1c0a8e2b7d4c9a8f3e6d2b1a0c9e8f"
                            }
                        }
                    }
                }
            }
        },
        "/api/fleet/alerts": {
            "get": {
                "operationId": "fleetAlertsList",
                "summary": "List fleet alert events",
                "description": "Lists fleet alert events (what fired, on which server, when it cleared), newest first. Alert rules themselves are managed under /api/alerts.\n\n**Roles:** admin.\n\n- kind is one of cpu, ram, disk, swap, load, inode, offline, disk_forecast, service_failed.\n\n- ruleId is null for built-in alerts (offline, disk forecast).",
                "tags": [
                    "Fleet"
                ],
                "parameters": [
                    {
                        "name": "active",
                        "in": "query",
                        "required": false,
                        "description": "Only unresolved events (\"1\" or \"true\"). (max 5 chars)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "serverId",
                        "in": "query",
                        "required": false,
                        "description": "Only events of this server. (minimum 1)",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "required": false,
                        "description": "Maximum number of events. (1–500, default 100)",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Alert events.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "events": [
                                        {
                                            "id": 77,
                                            "serverId": 12,
                                            "serverName": "web-1",
                                            "ruleId": 3,
                                            "kind": "cpu",
                                            "message": "CPU above 90% for 5 minutes",
                                            "value": 94.2,
                                            "startedAt": "2026-11-27T10:00:00.000Z",
                                            "resolvedAt": null
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/fleet/elevate": {
            "get": {
                "operationId": "fleetElevationGet",
                "summary": "Get 2FA step-up state",
                "description": "Tells whether the caller has two-factor authentication enabled and whether the current browser session is elevated (2FA step-up), and until when.\n\n**Roles:** admin.\n\n- For a personal access token elevated is always false and until null (tokens can never be elevated).\n\n- Elevation is in memory only: a panel restart ends every elevation.",
                "tags": [
                    "Fleet commands and scripts"
                ],
                "responses": {
                    "200": {
                        "description": "Elevation state; until is null when not elevated.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "totpEnabled": true,
                                    "elevated": true,
                                    "until": "2026-11-27T10:15:00.000Z"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "fleetElevationCreate",
                "summary": "Confirm a 2FA step-up",
                "description": "Verifies a current TOTP code of the caller (the same authenticator as login, ±30 s) and elevates the current browser session for 15 minutes. Elevation is needed for free commands, running and editing saved scripts from the panel, granting server permissions and the fleet terminal.\n\n**Roles:** admin.\n\n**Rate limit:** 10 per minute per IP.\n\n- A wrong code writes the audit action fleet.elevation_failed.\n\n- The elevation is bound to the exact JWT used for this request (sha256 of the token); other tokens of the same user, including a new login, are not elevated.\n\n- In memory only: a panel restart drops every elevation.",
                "tags": [
                    "Fleet commands and scripts"
                ],
                "responses": {
                    "200": {
                        "description": "The session is elevated until the given time.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "totpEnabled": true,
                                    "elevated": true,
                                    "until": "2026-11-27T10:15:00.000Z"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "No bearer session token could be identified. — \"A 2FA step-up needs a browser session.\"\n\nThe user has no TOTP configured. — \"Two-factor authentication is not enabled for your account. Enable it first to use this feature.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "A 2FA step-up needs a browser session."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "No token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Unauthorized"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nWrong code, wrong format, or a code that was just used (for login or a step-up) within the last 2 minutes. — \"Invalid 2FA code.\"\n\nCalled with a personal access token. — \"The AI cannot confirm a 2FA step-up.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Too many requests — see the Retry-After header. — \"Rate limit exceeded, retry in …\"\n\n5 wrong codes within 10 minutes for this user. — \"Too many wrong 2FA codes. Try again in 10 minutes.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Rate limit exceeded, retry in …"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": [
                    {
                        "sessionAuth": []
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "code": {
                                        "type": "string",
                                        "description": "Current 6–8 digit TOTP code (whitespace is removed). (6–12 chars; must be 6–8 digits after removing whitespace)"
                                    }
                                },
                                "required": [
                                    "code"
                                ]
                            },
                            "example": {
                                "code": "492039"
                            }
                        }
                    }
                }
            }
        },
        "/api/fleet/install.sh": {
            "get": {
                "operationId": "fleetAgentInstallScript",
                "summary": "Download the agent installer",
                "description": "Returns the agent installer shell script with this panel's public URL baked in (no secrets). Used as `curl -fsSL https://<panel>/api/fleet/install.sh | sudo bash -s -- --token <token> --mode control|monitor`. When the panel cannot determine its public https URL, it returns a script that prints an error and exits 1.\n\n- The panel URL is the panel_public_url setting when set, else the https origin of the request (Host + X-Forwarded-Proto / CF-Visitor).\n\n- The \"no URL\" fallback script is still answered with 200, so `curl -f` does not fail — the script itself exits 1.\n\n- Uncertain: the 404 path sends a JSON object after Content-Type text/x-shellscript was already set; Fastify may refuse to serialize it and answer 500 instead.",
                "tags": [
                    "Fleet agent"
                ],
                "responses": {
                    "200": {
                        "description": "The installer script (charset utf-8, Cache-Control: no-store).",
                        "content": {
                            "text/x-shellscript": {
                                "schema": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "The installer file is missing from the panel installation. — \"scripts/agent-install.sh is missing on this panel.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "scripts/agent-install.sh is missing on this panel."
                                }
                            }
                        }
                    }
                },
                "x-auth": "public",
                "x-roles": [],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": []
            }
        },
        "/api/fleet/runs": {
            "post": {
                "operationId": "fleetRunsCreate",
                "summary": "Run a command or script",
                "description": "Runs a free shell command or a saved script on 1–50 servers in the background (at most 5 servers at a time) and answers immediately with the run id. Targets that are not allowed are not executed and end as \"denied\" with the reason in their output. From the panel both kinds need an active 2FA step-up; personal access tokens can only run scripts marked aiAllowed.\n\n**Roles:** admin.\n\n**Requires a 2FA step-up** in the browser session.\n\n**Rate limit:** 30 per minute per credential (Authorization header; per IP without one).\n\n- The audit action is fleet.command for kind=command (meta includes the first 2000 chars of the command) and fleet.script.run for kind=script.\n\n- Per target, kind=command needs the server's commandsEnabled switch, else the target is denied with \"Free commands are disabled for this server (enable them in its settings).\".\n\n- Per target, kind=script from the panel needs commandsEnabled (else denied: \"Commands and scripts are disabled for this server (enable \\\"free commands\\\" in its settings).\") and from a personal access token needs \"scripts\" in the server's aiActions (else denied: \"The AI may not run scripts on this server (the \\\"scripts\\\" AI permission is off in the panel).\").\n\n- The switches are checked again when each target starts; the agent additionally enforces its own mode / allowCommands (refusals end as \"denied\").\n\n- A target whose server cannot be reached ends as \"offline\".\n\n- Personal access tokens need no elevation for scripts (they are gated by aiAllowed + the \"scripts\" permission).\n\n- Target status values: pending, running, success, failed, timeout, offline, denied, cancelled. Run kind: command | script | action. Run source: ui | mcp (personal access token). finishedAt is null while the run is still executing.\n\n- Elevation error body: {\"error\": \"Confirm with your 2FA code first (step-up required).\", \"code\": \"elevation_required\"} (403). Elevate with POST /api/fleet/elevate; it lasts 15 minutes for the browser session (JWT) it was confirmed with.",
                "tags": [
                    "Fleet commands and scripts"
                ],
                "responses": {
                    "200": {
                        "description": "The id of the created run.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "runId": 347
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "kind=command and command is missing or blank. — \"A command is required.\"\n\nkind=script without scriptId. — \"A script is required.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "A command is required."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The browser session has no active 2FA step-up (POST /api/fleet/elevate). The body also carries \"code\": \"elevation_required\". — \"Confirm with your 2FA code first (step-up required).\"\n\nYour role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nkind=command with a personal access token. — \"The AI cannot run free commands. Use a saved script that is allowed for the AI.\"\n\nPersonal access token and the script has aiAllowed false. — \"This script is not allowed for the AI (enable \"AI may run\" on the script in the panel).\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Confirm with your 2FA code first (step-up required)."
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "kind=script and no script with scriptId. — \"Script not found\"\n\nOne of serverIds does not exist. — \"Server not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Script not found"
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Too many requests — see the Retry-After header. — \"Rate limit exceeded, retry in …\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Rate limit exceeded, retry in …"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "kind": {
                                        "type": "string",
                                        "description": "command = free shell command; script = a saved script. (one of: command, script)"
                                    },
                                    "serverIds": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Target server ids (duplicates are merged). (1–50 items, integers ≥ 1)"
                                    },
                                    "command": {
                                        "type": "string",
                                        "description": "kind=command: the shell command (required, not blank). (1–20000 chars)"
                                    },
                                    "timeoutSec": {
                                        "type": "integer",
                                        "description": "kind=command: per-server timeout in seconds (ignored for scripts, which use their own timeoutSecs). (1–3600, default 300)"
                                    },
                                    "scriptId": {
                                        "type": "integer",
                                        "description": "kind=script: id of the saved script (required). (minimum 1)"
                                    }
                                },
                                "required": [
                                    "kind",
                                    "serverIds"
                                ]
                            },
                            "example": {
                                "kind": "script",
                                "serverIds": [
                                    12,
                                    13
                                ],
                                "scriptId": 4
                            }
                        }
                    }
                }
            },
            "get": {
                "operationId": "fleetRunsList",
                "summary": "List runs",
                "description": "Lists runs (actions, commands, scripts, agent installs) newest first with their per-server targets, without output. Page with nextCursor.\n\n**Roles:** admin.\n\n- Target status values: pending, running, success, failed, timeout, offline, denied, cancelled. Run kind: command | script | action. Run source: ui | mcp (personal access token). finishedAt is null while the run is still executing.",
                "tags": [
                    "Fleet commands and scripts"
                ],
                "parameters": [
                    {
                        "name": "limit",
                        "in": "query",
                        "required": false,
                        "description": "Page size. (1–100, default 30)",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "cursor",
                        "in": "query",
                        "required": false,
                        "description": "Return runs with an id lower than this (the nextCursor of the previous page). (minimum 1)",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "serverId",
                        "in": "query",
                        "required": false,
                        "description": "Only runs that targeted this server. (minimum 1)",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "A page of runs; target output is always null here. nextCursor is null on the last page.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "runs": [
                                        {
                                            "id": 345,
                                            "kind": "action",
                                            "scriptId": null,
                                            "scriptName": null,
                                            "command": "service.restart name=nginx",
                                            "source": "ui",
                                            "createdByEmail": "ada@example.com",
                                            "createdAt": "2026-11-27T10:00:00.000Z",
                                            "finishedAt": "2026-11-27T10:00:04.000Z",
                                            "targets": [
                                                {
                                                    "id": 901,
                                                    "serverId": 12,
                                                    "serverName": "web-1",
                                                    "status": "success",
                                                    "channel": "agent",
                                                    "exitCode": 0,
                                                    "output": null,
                                                    "startedAt": "2026-11-27T10:00:01.000Z",
                                                    "finishedAt": "2026-11-27T10:00:04.000Z"
                                                }
                                            ]
                                        }
                                    ],
                                    "nextCursor": null
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/fleet/runs/{id}": {
            "get": {
                "operationId": "fleetRunsGet",
                "summary": "Get a run",
                "description": "Returns one run with each target's status, exit code and output. While the run is executing, unfinished targets show their live output so far.\n\n**Roles:** admin.\n\n- Target status values: pending, running, success, failed, timeout, offline, denied, cancelled. Run kind: command | script | action. Run source: ui | mcp (personal access token). finishedAt is null while the run is still executing.\n\n- channel is agent, ssh or null (null for the panel host or when not executed).\n\n- Poll this, or use GET /api/fleet/runs/{id}/stream, to wait for completion.",
                "tags": [
                    "Fleet commands and scripts"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Run id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The run with per-target output (the last 256 KiB per target).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 345,
                                    "kind": "action",
                                    "scriptId": null,
                                    "scriptName": null,
                                    "command": "service.restart name=nginx",
                                    "source": "ui",
                                    "createdByEmail": "ada@example.com",
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "finishedAt": "2026-11-27T10:00:04.000Z",
                                    "targets": [
                                        {
                                            "id": 901,
                                            "serverId": 12,
                                            "serverName": "web-1",
                                            "status": "success",
                                            "channel": "agent",
                                            "exitCode": 0,
                                            "output": "",
                                            "startedAt": "2026-11-27T10:00:01.000Z",
                                            "finishedAt": "2026-11-27T10:00:04.000Z"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No run with this id. — \"Run not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Run not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/fleet/runs/{id}/cancel": {
            "post": {
                "operationId": "fleetRunsCancel",
                "summary": "Cancel a run",
                "description": "Cancels a run that is still executing: running targets are stopped (the remote process is killed) and pending ones are marked cancelled. Answers ok:true even when the run had already finished.\n\n**Roles:** admin.\n\n- Personal access tokens may cancel only runs they (any token) started (source \"mcp\").\n\n- Takes no body; needs no elevation.\n\n- Only runs executing in this panel process can be cancelled (audit meta wasRunning tells whether it was).",
                "tags": [
                    "Fleet commands and scripts"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Run id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Cancellation requested.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nA personal access token tried to cancel a run started from the panel (source \"ui\"). — \"Not available to the AI: this can only be done by an admin in the panel.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No run with this id. — \"Run not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Run not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/fleet/runs/{id}/stream": {
            "get": {
                "operationId": "fleetRunsStream",
                "summary": "Stream run output",
                "description": "Server-Sent Events of a run. First replays what already happened, then streams: {\"serverId\": n, \"chunk\": \"…\"} for output, {\"serverId\": n, \"status\": \"<status>\", \"exitCode\": n|null} on each status change, and finally {\"done\": true}, after which the stream closes.\n\n**Roles:** admin.\n\n**Streams** Server-Sent Events.\n\n- For runs no longer in memory (finished more than 30 minutes ago, or from before a panel restart) the stored output and final status of each target are replayed from the database, followed by {done:true}.\n\n- Chunks are at most 64 KiB.\n\n- Target status values: pending, running, success, failed, timeout, offline, denied, cancelled. Run kind: command | script | action. Run source: ui | mcp (personal access token). finishedAt is null while the run is still executing.\n\n- Keep-alive comments \": ka\" every 20 s. Send the token in the Authorization header.",
                "tags": [
                    "Fleet commands and scripts"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Run id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "SSE stream of chunk/status events ending with {done:true}.",
                        "content": {
                            "text/event-stream": {
                                "schema": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No run with this id. — \"Run not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Run not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/fleet/scripts": {
            "get": {
                "operationId": "fleetScriptsList",
                "summary": "List saved scripts",
                "description": "Lists all saved scripts by name, including their body.\n\n**Roles:** admin.\n\n- Personal access tokens can read all scripts (including ones not allowed for the AI).",
                "tags": [
                    "Fleet commands and scripts"
                ],
                "responses": {
                    "200": {
                        "description": "All scripts.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "scripts": [
                                        {
                                            "id": 4,
                                            "name": "Clear tmp",
                                            "description": "Remove files older than 7 days from /tmp",
                                            "body": "find /tmp -type f -mtime +7 -delete",
                                            "timeoutSecs": 300,
                                            "aiAllowed": false,
                                            "createdAt": "2026-11-27T10:00:00.000Z",
                                            "updatedAt": "2026-11-27T10:00:00.000Z"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "fleetScriptsCreate",
                "summary": "Create a saved script",
                "description": "Saves a shell script that can later be run on one or many servers with POST /api/fleet/runs. Needs an active 2FA step-up.\n\n**Roles:** admin.\n\n**Requires a 2FA step-up** in the browser session.\n\n- Elevation error body: {\"error\": \"Confirm with your 2FA code first (step-up required).\", \"code\": \"elevation_required\"} (403). Elevate with POST /api/fleet/elevate; it lasts 15 minutes for the browser session (JWT) it was confirmed with.\n\n- The body is stored as sent (not trimmed).",
                "tags": [
                    "Fleet commands and scripts"
                ],
                "responses": {
                    "201": {
                        "description": "The created script.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 4,
                                    "name": "Clear tmp",
                                    "description": "Remove files older than 7 days from /tmp",
                                    "body": "find /tmp -type f -mtime +7 -delete",
                                    "timeoutSecs": 300,
                                    "aiAllowed": false,
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "name is only whitespace. — \"A name is required.\"\n\nbody is only whitespace. — \"The script body is empty.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "A name is required."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "No token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Unauthorized"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The browser session has no active 2FA step-up (POST /api/fleet/elevate). The body also carries \"code\": \"elevation_required\". — \"Confirm with your 2FA code first (step-up required).\"\n\nYour role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCalled with a personal access token (orch_…). — \"Not available to the AI: this can only be done by an admin in the panel.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Confirm with your 2FA code first (step-up required)."
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "Script names are unique. — \"A script with this name already exists.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "A script with this name already exists."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": [
                    {
                        "sessionAuth": []
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Unique script name (trimmed). (1–100 chars, not blank)"
                                    },
                                    "description": {
                                        "type": "string",
                                        "description": "Short description; blank → null. (max 500 chars)"
                                    },
                                    "body": {
                                        "type": "string",
                                        "description": "Shell script executed with bash on each target. (1–100000 chars, not blank)"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "description": "Per-server timeout in seconds. (1–3600, default 300)"
                                    },
                                    "aiAllowed": {
                                        "type": "boolean",
                                        "description": "Whether personal access tokens (AI / MCP) may run it; they also need the \"scripts\" AI permission on each target server. (default false)"
                                    }
                                },
                                "required": [
                                    "name",
                                    "body"
                                ]
                            },
                            "example": {
                                "name": "Clear tmp",
                                "description": "Remove files older than 7 days from /tmp",
                                "body": "find /tmp -type f -mtime +7 -delete",
                                "timeoutSecs": 300,
                                "aiAllowed": false
                            }
                        }
                    }
                }
            }
        },
        "/api/fleet/scripts/{id}": {
            "patch": {
                "operationId": "fleetScriptsUpdate",
                "summary": "Update a saved script",
                "description": "Changes the given fields of a saved script. Needs an active 2FA step-up.\n\n**Roles:** admin.\n\n**Requires a 2FA step-up** in the browser session.\n\n- Elevation error body: {\"error\": \"Confirm with your 2FA code first (step-up required).\", \"code\": \"elevation_required\"} (403). Elevate with POST /api/fleet/elevate; it lasts 15 minutes for the browser session (JWT) it was confirmed with.\n\n- The token and elevation checks run before the script is looked up.",
                "tags": [
                    "Fleet commands and scripts"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Script id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The updated script.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 4,
                                    "name": "Clear tmp",
                                    "description": "Remove files older than 7 days from /tmp",
                                    "body": "find /tmp -type f -mtime +3 -delete",
                                    "timeoutSecs": 300,
                                    "aiAllowed": true,
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:05:00.000Z"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "name is only whitespace. — \"A name is required.\"\n\nbody is only whitespace. — \"The script body is empty.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "A name is required."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "No token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Unauthorized"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The browser session has no active 2FA step-up (POST /api/fleet/elevate). The body also carries \"code\": \"elevation_required\". — \"Confirm with your 2FA code first (step-up required).\"\n\nYour role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCalled with a personal access token (orch_…). — \"Not available to the AI: this can only be done by an admin in the panel.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Confirm with your 2FA code first (step-up required)."
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No saved script with this id. — \"Script not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Script not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "Script names are unique. — \"A script with this name already exists.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "A script with this name already exists."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": [
                    {
                        "sessionAuth": []
                    }
                ],
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Unique script name (trimmed). (1–100 chars, not blank)"
                                    },
                                    "description": {
                                        "type": "string",
                                        "description": "Short description; null or blank clears it. (max 500 chars, nullable)"
                                    },
                                    "body": {
                                        "type": "string",
                                        "description": "Shell script executed with bash on each target. (1–100000 chars, not blank)"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "description": "Per-server timeout in seconds. (1–3600)"
                                    },
                                    "aiAllowed": {
                                        "type": "boolean",
                                        "description": "Whether personal access tokens (AI / MCP) may run it; they also need the \"scripts\" AI permission on each target server."
                                    }
                                }
                            },
                            "example": {
                                "body": "find /tmp -type f -mtime +3 -delete",
                                "aiAllowed": true
                            }
                        }
                    }
                }
            },
            "delete": {
                "operationId": "fleetScriptsDelete",
                "summary": "Delete a saved script",
                "description": "Deletes a saved script. Past runs keep the script id and name. Needs an active 2FA step-up.\n\n**Roles:** admin.\n\n**Requires a 2FA step-up** in the browser session.\n\n- Elevation error body: {\"error\": \"Confirm with your 2FA code first (step-up required).\", \"code\": \"elevation_required\"} (403). Elevate with POST /api/fleet/elevate; it lasts 15 minutes for the browser session (JWT) it was confirmed with.",
                "tags": [
                    "Fleet commands and scripts"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Script id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Deleted.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "No token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Unauthorized"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The browser session has no active 2FA step-up (POST /api/fleet/elevate). The body also carries \"code\": \"elevation_required\". — \"Confirm with your 2FA code first (step-up required).\"\n\nYour role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCalled with a personal access token (orch_…). — \"Not available to the AI: this can only be done by an admin in the panel.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Confirm with your 2FA code first (step-up required)."
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No saved script with this id. — \"Script not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Script not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": [
                    {
                        "sessionAuth": []
                    }
                ]
            }
        },
        "/api/fleet/servers": {
            "get": {
                "operationId": "fleetServersList",
                "summary": "List fleet servers",
                "description": "Lists every server with its fleet state: agent status and version, the channel actions would use right now, permissions, organisation fields, site and open-alert counts and the latest metrics. Also returns the agent version this panel ships.\n\n**Roles:** admin.\n\n- FleetServer: id, name, kind (local|remote), host, hasSsh, sshStatus, agentStatus (none|pending|online|offline), agentVersion, agentArch, agentMode (monitor|control|null), agentAllowTerminal, agentAllowCommands, agentLastSeenAt, agentAutoUpdate, agentUpdateAvailable, channel (agent|ssh|local|none — the channel actions would use right now), location, groupName, tags, provider, notes, preferredChannel (auto|agent|ssh), latencyMs, maintenanceUntil, offlineAlertSecs, terminalEnabled, commandsEnabled, aiActions, siteCount, system{os,kernel,hostname,cpuModel,cores,memTotal,bootTime,capabilities}, latest{at,source,m}|null, activeAlerts. Never contains the SSH key or agent key hash/prefix.\n\n- Personal access tokens can call all fleet read endpoints.",
                "tags": [
                    "Fleet"
                ],
                "responses": {
                    "200": {
                        "description": "All servers plus the shipped agent version (null when no agent binary is built).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "servers": [
                                        {
                                            "id": 12,
                                            "name": "web-1",
                                            "kind": "remote",
                                            "host": "web1.example.com",
                                            "hasSsh": true,
                                            "sshStatus": "online",
                                            "agentStatus": "online",
                                            "agentVersion": "1.4.0",
                                            "agentArch": "amd64",
                                            "agentMode": "control",
                                            "agentAllowTerminal": true,
                                            "agentAllowCommands": false,
                                            "agentLastSeenAt": "2026-11-27T10:00:00.000Z",
                                            "agentAutoUpdate": true,
                                            "agentUpdateAvailable": false,
                                            "channel": "agent",
                                            "location": "Frankfurt",
                                            "groupName": "production",
                                            "tags": [
                                                "web",
                                                "php"
                                            ],
                                            "provider": "Hetzner",
                                            "notes": null,
                                            "preferredChannel": "auto",
                                            "latencyMs": 24,
                                            "maintenanceUntil": null,
                                            "offlineAlertSecs": 120,
                                            "terminalEnabled": false,
                                            "commandsEnabled": false,
                                            "aiActions": [
                                                "services"
                                            ],
                                            "siteCount": 3,
                                            "system": {
                                                "os": "Ubuntu 24.04.1 LTS",
                                                "kernel": "6.8.0-45-generic",
                                                "hostname": "web-1",
                                                "cpuModel": "AMD EPYC Processor",
                                                "cores": 2,
                                                "memTotal": 4123000000,
                                                "bootTime": 1794909600,
                                                "capabilities": [
                                                    "systemd",
                                                    "docker",
                                                    "apt",
                                                    "journal"
                                                ]
                                            },
                                            "latest": {
                                                "at": "2026-11-27T10:00:00.000Z",
                                                "source": "agent",
                                                "m": {
                                                    "ts": 1795773600,
                                                    "cpu": {
                                                        "percent": 12.4,
                                                        "perCore": [
                                                            10.2,
                                                            14.6
                                                        ],
                                                        "load1": 0.32,
                                                        "load5": 0.28,
                                                        "load15": 0.25,
                                                        "cores": 2,
                                                        "steal": 0,
                                                        "iowait": 0.4
                                                    },
                                                    "mem": {
                                                        "total": 4123000000,
                                                        "used": 1610000000,
                                                        "available": 2400000000,
                                                        "swapTotal": 1073741824,
                                                        "swapUsed": 0
                                                    },
                                                    "disks": [
                                                        {
                                                            "mount": "/",
                                                            "fs": "ext4",
                                                            "device": "/dev/vda1",
                                                            "total": 80000000000,
                                                            "used": 31000000000,
                                                            "inodesTotal": 5000000,
                                                            "inodesUsed": 410000
                                                        }
                                                    ],
                                                    "diskIO": {
                                                        "readBps": 1200,
                                                        "writeBps": 54000,
                                                        "readOps": 1,
                                                        "writeOps": 9
                                                    },
                                                    "net": {
                                                        "rxBps": 18000,
                                                        "txBps": 42000,
                                                        "rxTotal": 912000000000,
                                                        "txTotal": 1340000000000,
                                                        "ifaces": [
                                                            {
                                                                "name": "eth0",
                                                                "rxBps": 18000,
                                                                "txBps": 42000,
                                                                "rxTotal": 912000000000,
                                                                "txTotal": 1340000000000
                                                            }
                                                        ]
                                                    },
                                                    "uptime": 864000,
                                                    "procs": 142,
                                                    "tcpConns": 37
                                                }
                                            },
                                            "activeAlerts": 0
                                        }
                                    ],
                                    "shippedAgentVersion": "1.4.0"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "fleetServersCreate",
                "summary": "Add an agent-only server",
                "description": "Creates a remote server without SSH access, to be monitored through the Orchestrator agent only. Generate the install command afterwards with POST /api/fleet/servers/{id}/agent/enroll-token. SSH servers are created with POST /api/servers.\n\n**Roles:** admin.\n\n- New servers start with all permissions off (terminalEnabled, commandsEnabled false, aiActions []), offlineAlertSecs 120 and agentAutoUpdate true.\n\n- An agent-only server can never host sites.",
                "tags": [
                    "Fleet"
                ],
                "responses": {
                    "201": {
                        "description": "The created server (FleetServer).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 13,
                                    "name": "db-2",
                                    "kind": "remote",
                                    "host": null,
                                    "hasSsh": false,
                                    "sshStatus": "unknown",
                                    "agentStatus": "none",
                                    "agentVersion": null,
                                    "agentArch": null,
                                    "agentMode": null,
                                    "agentAllowTerminal": null,
                                    "agentAllowCommands": null,
                                    "agentLastSeenAt": null,
                                    "agentAutoUpdate": true,
                                    "agentUpdateAvailable": false,
                                    "channel": "none",
                                    "location": "Frankfurt",
                                    "groupName": "production",
                                    "tags": [
                                        "db"
                                    ],
                                    "provider": "Hetzner",
                                    "notes": "Replica",
                                    "preferredChannel": "auto",
                                    "latencyMs": null,
                                    "maintenanceUntil": null,
                                    "offlineAlertSecs": 120,
                                    "terminalEnabled": false,
                                    "commandsEnabled": false,
                                    "aiActions": [],
                                    "siteCount": 0,
                                    "system": {
                                        "os": null,
                                        "kernel": null,
                                        "hostname": null,
                                        "cpuModel": null,
                                        "cores": null,
                                        "memTotal": null,
                                        "bootTime": null,
                                        "capabilities": []
                                    },
                                    "latest": null,
                                    "activeAlerts": 0
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "name is only whitespace. — \"A name is required.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "A name is required."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "No token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Unauthorized"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCalled with a personal access token (orch_…). — \"Not available to the AI: this can only be done by an admin in the panel.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": [
                    {
                        "sessionAuth": []
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Display name (trimmed). (1–100 chars, not blank)"
                                    },
                                    "location": {
                                        "type": "string",
                                        "description": "Free-text location, e.g. \"Frankfurt\". (max 100 chars; blank → null)"
                                    },
                                    "groupName": {
                                        "type": "string",
                                        "description": "Group used to organise servers and scope alert rules. (max 100 chars; blank → null)"
                                    },
                                    "tags": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Tags (trimmed, blanks and duplicates dropped). (max 20 items, each max 40 chars)"
                                    },
                                    "provider": {
                                        "type": "string",
                                        "description": "Hosting provider, free text. (max 100 chars; blank → null)"
                                    },
                                    "notes": {
                                        "type": "string",
                                        "description": "Free-text notes. (max 1000 chars; blank → null)"
                                    }
                                },
                                "required": [
                                    "name"
                                ]
                            },
                            "example": {
                                "name": "db-2",
                                "location": "Frankfurt",
                                "groupName": "production",
                                "tags": [
                                    "db"
                                ],
                                "provider": "Hetzner",
                                "notes": "Replica"
                            }
                        }
                    }
                }
            }
        },
        "/api/fleet/servers/{id}": {
            "get": {
                "operationId": "fleetServersGet",
                "summary": "Get a fleet server",
                "description": "Returns one server (FleetServer) and the newest known inventory (services, containers, pending updates) from either the agent or an earlier SSH read, without contacting the server.\n\n**Roles:** admin.\n\n- FleetServer: id, name, kind (local|remote), host, hasSsh, sshStatus, agentStatus (none|pending|online|offline), agentVersion, agentArch, agentMode (monitor|control|null), agentAllowTerminal, agentAllowCommands, agentLastSeenAt, agentAutoUpdate, agentUpdateAvailable, channel (agent|ssh|local|none — the channel actions would use right now), location, groupName, tags, provider, notes, preferredChannel (auto|agent|ssh), latencyMs, maintenanceUntil, offlineAlertSecs, terminalEnabled, commandsEnabled, aiActions, siteCount, system{os,kernel,hostname,cpuModel,cores,memTotal,bootTime,capabilities}, latest{at,source,m}|null, activeAlerts. Never contains the SSH key or agent key hash/prefix.\n\n- Use GET /api/fleet/servers/{id}/inventory?refresh=1 to read a fresh inventory.",
                "tags": [
                    "Fleet"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Server id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The server and its cached inventory (null when none is known).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "server": {
                                        "id": 12,
                                        "name": "web-1",
                                        "kind": "remote",
                                        "host": "web1.example.com",
                                        "hasSsh": true,
                                        "sshStatus": "online",
                                        "agentStatus": "online",
                                        "agentVersion": "1.4.0",
                                        "agentArch": "amd64",
                                        "agentMode": "control",
                                        "agentAllowTerminal": true,
                                        "agentAllowCommands": false,
                                        "agentLastSeenAt": "2026-11-27T10:00:00.000Z",
                                        "agentAutoUpdate": true,
                                        "agentUpdateAvailable": false,
                                        "channel": "agent",
                                        "location": "Frankfurt",
                                        "groupName": "production",
                                        "tags": [
                                            "web",
                                            "php"
                                        ],
                                        "provider": "Hetzner",
                                        "notes": null,
                                        "preferredChannel": "auto",
                                        "latencyMs": 24,
                                        "maintenanceUntil": null,
                                        "offlineAlertSecs": 120,
                                        "terminalEnabled": false,
                                        "commandsEnabled": false,
                                        "aiActions": [
                                            "services"
                                        ],
                                        "siteCount": 3,
                                        "system": {
                                            "os": "Ubuntu 24.04.1 LTS",
                                            "kernel": "6.8.0-45-generic",
                                            "hostname": "web-1",
                                            "cpuModel": "AMD EPYC Processor",
                                            "cores": 2,
                                            "memTotal": 4123000000,
                                            "bootTime": 1794909600,
                                            "capabilities": [
                                                "systemd",
                                                "docker",
                                                "apt",
                                                "journal"
                                            ]
                                        },
                                        "latest": {
                                            "at": "2026-11-27T10:00:00.000Z",
                                            "source": "agent",
                                            "m": {
                                                "ts": 1795773600,
                                                "cpu": {
                                                    "percent": 12.4,
                                                    "perCore": [
                                                        10.2,
                                                        14.6
                                                    ],
                                                    "load1": 0.32,
                                                    "load5": 0.28,
                                                    "load15": 0.25,
                                                    "cores": 2,
                                                    "steal": 0,
                                                    "iowait": 0.4
                                                },
                                                "mem": {
                                                    "total": 4123000000,
                                                    "used": 1610000000,
                                                    "available": 2400000000,
                                                    "swapTotal": 1073741824,
                                                    "swapUsed": 0
                                                },
                                                "disks": [
                                                    {
                                                        "mount": "/",
                                                        "fs": "ext4",
                                                        "device": "/dev/vda1",
                                                        "total": 80000000000,
                                                        "used": 31000000000,
                                                        "inodesTotal": 5000000,
                                                        "inodesUsed": 410000
                                                    }
                                                ],
                                                "diskIO": {
                                                    "readBps": 1200,
                                                    "writeBps": 54000,
                                                    "readOps": 1,
                                                    "writeOps": 9
                                                },
                                                "net": {
                                                    "rxBps": 18000,
                                                    "txBps": 42000,
                                                    "rxTotal": 912000000000,
                                                    "txTotal": 1340000000000,
                                                    "ifaces": [
                                                        {
                                                            "name": "eth0",
                                                            "rxBps": 18000,
                                                            "txBps": 42000,
                                                            "rxTotal": 912000000000,
                                                            "txTotal": 1340000000000
                                                        }
                                                    ]
                                                },
                                                "uptime": 864000,
                                                "procs": 142,
                                                "tcpConns": 37
                                            }
                                        },
                                        "activeAlerts": 0
                                    },
                                    "inventory": {
                                        "at": "2026-11-27T10:00:00.000Z",
                                        "inv": {
                                            "services": [
                                                {
                                                    "name": "nginx.service",
                                                    "description": "A high performance web server",
                                                    "active": "active",
                                                    "sub": "running",
                                                    "enabled": "enabled"
                                                }
                                            ],
                                            "failedUnits": [],
                                            "docker": {
                                                "available": true,
                                                "containers": [
                                                    {
                                                        "id": "a3f9c21b7d10",
                                                        "name": "redis",
                                                        "image": "redis:7",
                                                        "state": "running",
                                                        "status": "Up 3 days",
                                                        "cpu": 0.4,
                                                        "memBytes": 12000000
                                                    }
                                                ]
                                            },
                                            "updates": {
                                                "manager": "apt",
                                                "count": 4,
                                                "security": 1,
                                                "rebootRequired": false,
                                                "packages": [
                                                    {
                                                        "name": "openssl",
                                                        "current": "3.0.13-0ubuntu3.4",
                                                        "available": "3.0.13-0ubuntu3.5",
                                                        "security": true
                                                    }
                                                ]
                                            },
                                            "os": "Ubuntu 24.04.1 LTS",
                                            "kernel": "6.8.0-45-generic",
                                            "hostname": "web-1",
                                            "timezone": "Etc/UTC"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No server with this id (or the id is not a positive integer). — \"Server not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Server not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "patch": {
                "operationId": "fleetServersUpdate",
                "summary": "Update fleet settings",
                "description": "Updates organisation fields, channel preference, alerting, maintenance window, agent auto-update and the server's permissions (web terminal, free commands, AI permissions). Granting anything new — turning terminalEnabled or commandsEnabled on, or adding an AI permission the server did not have — requires an active 2FA step-up. Turning things off or removing AI permissions does not.\n\n**Roles:** admin.\n\n**Requires a 2FA step-up** in the browser session.\n\n- The audit action is fleet.server.permissions when terminalEnabled, commandsEnabled or aiActions was sent, else fleet.server.updated.\n\n- Elevation error body: {\"error\": \"Confirm with your 2FA code first (step-up required).\", \"code\": \"elevation_required\"} (403).\n\n- aiActions is stored in the fixed order services, docker, reboot, packages, scripts.\n\n- Elevation is only needed when granting; organisation fields alone never need it.",
                "tags": [
                    "Fleet"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Server id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The updated server (FleetServer).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 12,
                                    "name": "web-1",
                                    "kind": "remote",
                                    "host": "web1.example.com",
                                    "hasSsh": true,
                                    "sshStatus": "online",
                                    "agentStatus": "online",
                                    "agentVersion": "1.4.0",
                                    "agentArch": "amd64",
                                    "agentMode": "control",
                                    "agentAllowTerminal": true,
                                    "agentAllowCommands": false,
                                    "agentLastSeenAt": "2026-11-27T10:00:00.000Z",
                                    "agentAutoUpdate": true,
                                    "agentUpdateAvailable": false,
                                    "channel": "agent",
                                    "location": "Frankfurt",
                                    "groupName": "production",
                                    "tags": [
                                        "web",
                                        "php"
                                    ],
                                    "provider": "Hetzner",
                                    "notes": null,
                                    "preferredChannel": "auto",
                                    "latencyMs": 24,
                                    "maintenanceUntil": "2026-11-27T12:00:00.000Z",
                                    "offlineAlertSecs": 300,
                                    "terminalEnabled": false,
                                    "commandsEnabled": false,
                                    "aiActions": [
                                        "services",
                                        "docker"
                                    ],
                                    "siteCount": 3,
                                    "system": {
                                        "os": "Ubuntu 24.04.1 LTS",
                                        "kernel": "6.8.0-45-generic",
                                        "hostname": "web-1",
                                        "cpuModel": "AMD EPYC Processor",
                                        "cores": 2,
                                        "memTotal": 4123000000,
                                        "bootTime": 1794909600,
                                        "capabilities": [
                                            "systemd",
                                            "docker",
                                            "apt",
                                            "journal"
                                        ]
                                    },
                                    "latest": {
                                        "at": "2026-11-27T10:00:00.000Z",
                                        "source": "agent",
                                        "m": {
                                            "ts": 1795773600,
                                            "cpu": {
                                                "percent": 12.4,
                                                "perCore": [
                                                    10.2,
                                                    14.6
                                                ],
                                                "load1": 0.32,
                                                "load5": 0.28,
                                                "load15": 0.25,
                                                "cores": 2,
                                                "steal": 0,
                                                "iowait": 0.4
                                            },
                                            "mem": {
                                                "total": 4123000000,
                                                "used": 1610000000,
                                                "available": 2400000000,
                                                "swapTotal": 1073741824,
                                                "swapUsed": 0
                                            },
                                            "disks": [
                                                {
                                                    "mount": "/",
                                                    "fs": "ext4",
                                                    "device": "/dev/vda1",
                                                    "total": 80000000000,
                                                    "used": 31000000000,
                                                    "inodesTotal": 5000000,
                                                    "inodesUsed": 410000
                                                }
                                            ],
                                            "diskIO": {
                                                "readBps": 1200,
                                                "writeBps": 54000,
                                                "readOps": 1,
                                                "writeOps": 9
                                            },
                                            "net": {
                                                "rxBps": 18000,
                                                "txBps": 42000,
                                                "rxTotal": 912000000000,
                                                "txTotal": 1340000000000,
                                                "ifaces": [
                                                    {
                                                        "name": "eth0",
                                                        "rxBps": 18000,
                                                        "txBps": 42000,
                                                        "rxTotal": 912000000000,
                                                        "txTotal": 1340000000000
                                                    }
                                                ]
                                            },
                                            "uptime": 864000,
                                            "procs": 142,
                                            "tcpConns": 37
                                        }
                                    },
                                    "activeAlerts": 0
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "maintenanceUntil is more than 366 days in the future. — \"A maintenance window can last at most one year.\"\n\nname is only whitespace. — \"A name is required.\"\n\nmaintenanceUntil is not a parsable date. — \"Invalid maintenance end time.\"\n\nofflineAlertSecs is 1–29. — \"The offline alert delay must be 0 (off) or at least 30 seconds.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "A maintenance window can last at most one year."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The browser session has no active 2FA step-up (POST /api/fleet/elevate). The body also carries \"code\": \"elevation_required\". — \"Confirm with your 2FA code first (step-up required).\"\n\nYour role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nA personal access token sent terminalEnabled, commandsEnabled or aiActions (even to turn them off). — \"The AI cannot change the permissions of a server (terminal, commands, AI actions).\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Confirm with your 2FA code first (step-up required)."
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No server with this id (or the id is not a positive integer). — \"Server not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Server not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Display name (trimmed). (1–100 chars, not blank)"
                                    },
                                    "location": {
                                        "type": "string",
                                        "description": "Location; null or blank clears it. (max 100 chars, nullable)"
                                    },
                                    "groupName": {
                                        "type": "string",
                                        "description": "Group; null or blank clears it. (max 100 chars, nullable)"
                                    },
                                    "tags": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Replaces the tags (trimmed, blanks and duplicates dropped). (max 20 items, each max 40 chars)"
                                    },
                                    "provider": {
                                        "type": "string",
                                        "description": "Provider; null or blank clears it. (max 100 chars, nullable)"
                                    },
                                    "notes": {
                                        "type": "string",
                                        "description": "Notes; null or blank clears it. (max 1000 chars, nullable)"
                                    },
                                    "preferredChannel": {
                                        "type": "string",
                                        "description": "auto: agent when online, else SSH (or the panel host locally); agent: agent only; ssh: SSH (or local) first, agent as fallback. (one of: auto, agent, ssh)"
                                    },
                                    "offlineAlertSecs": {
                                        "type": "integer",
                                        "description": "Seconds offline before the \"server offline\" alert fires; 0 disables it. (0 or 30–604800)"
                                    },
                                    "maintenanceUntil": {
                                        "type": "string",
                                        "description": "ISO date-time until which alerts are muted; null or \"\" ends the window. (max 40 chars, nullable, parsable date, at most 366 days ahead)"
                                    },
                                    "terminalEnabled": {
                                        "type": "boolean",
                                        "description": "Allow the web terminal (WebSocket /api/terminal/fleet/term/{serverId}). Turning it on needs elevation. (not allowed for personal access tokens)"
                                    },
                                    "commandsEnabled": {
                                        "type": "boolean",
                                        "description": "Allow free commands and saved scripts from the panel. Turning it on needs elevation. (not allowed for personal access tokens)"
                                    },
                                    "aiActions": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Replaces what personal access tokens (AI / MCP) may do on this server. Adding a permission needs elevation. (max 10 items, each one of: services, docker, reboot, packages, scripts; not allowed for personal access tokens)"
                                    },
                                    "agentAutoUpdate": {
                                        "type": "boolean",
                                        "description": "Let the panel update the agent automatically when it connects with an older version (control mode only)."
                                    }
                                }
                            },
                            "example": {
                                "groupName": "production",
                                "tags": [
                                    "web",
                                    "php"
                                ],
                                "preferredChannel": "auto",
                                "offlineAlertSecs": 300,
                                "maintenanceUntil": "2026-11-27T12:00:00.000Z",
                                "aiActions": [
                                    "services",
                                    "docker"
                                ]
                            }
                        }
                    }
                }
            }
        },
        "/api/fleet/servers/{id}/actions": {
            "post": {
                "operationId": "fleetServersAction",
                "summary": "Run a fixed action",
                "description": "Starts one of the fixed, validated server actions (service control, reboot, package update, Docker container control) as a background run and answers immediately with the run id. Follow it with GET /api/fleet/runs/{id}/stream or GET /api/fleet/runs/{id}. Needs no 2FA step-up and does not depend on the commandsEnabled switch.\n\n**Roles:** admin.\n\n**Rate limit:** 60 per minute per credential (Authorization header; per IP without one).\n\n- Allowed actions — args — AI permission needed by personal access tokens — timeout: service.start — args {name: string} — AI permission \"services\" — timeout 180 s; service.stop — args {name: string} — AI permission \"services\" — timeout 180 s; service.restart — args {name: string} — AI permission \"services\" — timeout 180 s; service.reload — args {name: string} — AI permission \"services\" — timeout 180 s; service.status — args {name: string} — no AI permission needed (read-only, always allowed for tokens) — timeout 30 s; reboot — args {delayMin?: integer 0–10080, default 0} — AI permission \"reboot\" — timeout 60 s; reboot.cancel — no args ({}) — AI permission \"reboot\" — timeout 60 s; packages.update — args {mode?: \"upgrade\" | \"dist-upgrade\", default \"upgrade\"} — AI permission \"packages\" — timeout 3600 s; docker.start — args {id: string} — AI permission \"docker\" — timeout 180 s; docker.stop — args {id: string} — AI permission \"docker\" — timeout 180 s; docker.restart — args {id: string} — AI permission \"docker\" — timeout 180 s.\n\n- The audit action is \"fleet.action.\" + action, e.g. fleet.action.service.restart.\n\n- The run's command text is \"<action> <key>=<value> …\", e.g. \"service.restart name=nginx\"; its source is \"mcp\" for personal access tokens, else \"ui\".\n\n- The result (success | failed | timeout | offline | denied | cancelled, exit code, output) is only known from the run. An agent in monitor mode refuses actions; that target ends as \"denied\".\n\n- An unknown action is rejected by the schema enum (400 FST_ERR_VALIDATION).\n\n- The rate-limit key hashes the Authorization header, so each session/token has its own budget.",
                "tags": [
                    "Fleet"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Server id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The id of the created run (kind \"action\").",
                        "content": {
                            "application/json": {
                                "example": {
                                    "runId": 345
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "docker.*: args.id missing or not matching the pattern. — \"Invalid container id.\"\n\nservice.*: args.name missing or not matching the pattern. — \"Invalid service name.\"\n\nreboot: delayMin not an integer in range. — \"The reboot delay must be between 0 and 10080 minutes.\"\n\npackages.update: invalid mode. — \"The update mode must be \"upgrade\" or \"dist-upgrade\".\"\n\nargs contains a key the action does not take (reboot.cancel takes none). — \"Unexpected argument \"<key>\" for <action>.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid container id."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nPersonal access token and the server's aiActions lack the permission the action needs. — \"The AI is not allowed to run <action> on this server (the \"<permission>\" AI permission is off in the panel).\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No server with this id (or the id is not a positive integer). — \"Server not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Server not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "preferredChannel is \"agent\" and no agent is connected. — \"The agent of this server is offline (the server is set to use the agent only).\"\n\nAgent-only server (no host) whose agent is not connected. — \"The agent of this server is offline and the server has no SSH access configured.\"\n\nNo agent connected and no SSH host + key. — \"This server is not reachable: the agent is not connected and SSH access is not configured.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "The agent of this server is offline (the server is set to use the agent only)."
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Too many requests — see the Retry-After header. — \"Rate limit exceeded, retry in …\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Rate limit exceeded, retry in …"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "action": {
                                        "type": "string",
                                        "description": "The action to run. (one of: service.start, service.stop, service.restart, service.reload, service.status, reboot, reboot.cancel, packages.update, docker.start, docker.stop, docker.restart)"
                                    },
                                    "args": {
                                        "type": "object",
                                        "description": "Action arguments. Only the keys listed for the action are accepted. (max 4 properties; values string (max 200 chars) or number; default {})"
                                    }
                                },
                                "required": [
                                    "action"
                                ]
                            },
                            "example": {
                                "action": "service.restart",
                                "args": {
                                    "name": "nginx"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/api/fleet/servers/{id}/agent/enroll-token": {
            "post": {
                "operationId": "fleetAgentEnrollToken",
                "summary": "Create an agent install command",
                "description": "Creates a one-time enrollment token (valid 1 hour) and returns the install command to run as root on the server. Any older unused token of the server is invalidated, and a server without an agent is marked \"pending\".\n\n**Roles:** admin.\n\n- Only the sha256 of the token is stored; it is shown once.\n\n- The agent exchanges it at POST /api/fleet/agent/enroll.\n\n- Does not need a 2FA step-up.",
                "tags": [
                    "Fleet"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Server id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Install command, the token and when it expires.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "command": "curl -fsSL https://panel.example.com/api/fleet/install.sh | sudo bash -s -- --token 3q2-7wEXAMPLEtokenEXAMPLEtokenEXAMPLE1234 --mode control",
                                    "token": "3q2-7wEXAMPLEtokenEXAMPLEtokenEXAMPLE1234",
                                    "expiresAt": "2026-11-27T11:00:00.000Z"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The panel_public_url setting is not a clean https origin and the request did not arrive over https with a usable Host header. — \"The panel could not determine its public https:// URL. Set panel_public_url in Settings first.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "The panel could not determine its public https:// URL. Set panel_public_url in Settings first."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "No token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Unauthorized"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCalled with a personal access token (orch_…). — \"Not available to the AI: this can only be done by an admin in the panel.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No server with this id (or the id is not a positive integer). — \"Server not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Server not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": [
                    {
                        "sessionAuth": []
                    }
                ],
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "mode": {
                                        "type": "string",
                                        "description": "Agent mode the install command is generated for: control (actions, commands, terminal possible) or monitor (read-only). (one of: control, monitor; default control)"
                                    }
                                }
                            },
                            "example": {
                                "mode": "control"
                            }
                        }
                    }
                }
            }
        },
        "/api/fleet/servers/{id}/agent/install-ssh": {
            "post": {
                "operationId": "fleetAgentInstallSsh",
                "summary": "Install the agent over SSH",
                "description": "Installs the agent on a server that has SSH access: creates an enrollment token and runs the installer (fetched with curl or wget from this panel) over SSH as a background run (kind \"action\", command \"agent.install mode=<mode>\", timeout 900 s). A non-root SSH user must have passwordless sudo, which is checked first.\n\n**Roles:** admin.\n\n- Follow the output with GET /api/fleet/runs/{runId}/stream.\n\n- Does not need a 2FA step-up.",
                "tags": [
                    "Fleet"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Server id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The id of the run that performs the installation.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "runId": 346
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Non-root SSH user without passwordless sudo. — \"The SSH user needs root or passwordless sudo (sudo -n) to install the agent.\"\n\nThe panel_public_url setting is not a clean https origin and the request did not arrive over https with a usable Host header. — \"The panel could not determine its public https:// URL. Set panel_public_url in Settings first.\"\n\nNo host or key, or the panel host itself. — \"This server has no SSH access configured.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "The SSH user needs root or passwordless sudo (sudo -n) to install the agent."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "No token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Unauthorized"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCalled with a personal access token (orch_…). — \"Not available to the AI: this can only be done by an admin in the panel.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No server with this id (or the id is not a positive integer). — \"Server not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Server not found"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The sudo probe (non-root user) could not connect. — \"Could not connect over SSH.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Could not connect over SSH."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": [
                    {
                        "sessionAuth": []
                    }
                ],
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "mode": {
                                        "type": "string",
                                        "description": "Agent mode the install command is generated for: control (actions, commands, terminal possible) or monitor (read-only). (one of: control, monitor; default control)"
                                    }
                                }
                            },
                            "example": {
                                "mode": "control"
                            }
                        }
                    }
                }
            }
        },
        "/api/fleet/servers/{id}/agent/revoke": {
            "post": {
                "operationId": "fleetAgentRevoke",
                "summary": "Revoke the agent key",
                "description": "Deletes the server's agent key and unused enrollment tokens, disconnects a connected agent and sets the agent status to \"none\". The agent keeps running on the server but can no longer connect until it is enrolled again.\n\n**Roles:** admin.\n\n- Takes no body.\n\n- Nothing is uninstalled on the server.",
                "tags": [
                    "Fleet"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Server id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Revoked.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "No token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Unauthorized"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCalled with a personal access token (orch_…). — \"Not available to the AI: this can only be done by an admin in the panel.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No server with this id (or the id is not a positive integer). — \"Server not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Server not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": [
                    {
                        "sessionAuth": []
                    }
                ]
            }
        },
        "/api/fleet/servers/{id}/agent/update": {
            "post": {
                "operationId": "fleetAgentUpdate",
                "summary": "Update the agent",
                "description": "Asks the connected agent to update itself to the binary this panel ships (download URL and sha256 are sent to the agent) and waits for its answer. Works only for agents in control mode.\n\n**Roles:** admin.\n\n- The audit entry (with from/to versions) is written before the update is attempted, whatever the outcome.\n\n- Takes no body.",
                "tags": [
                    "Fleet"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Server id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The agent updated itself.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "No token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Unauthorized"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCalled with a personal access token (orch_…). — \"Not available to the AI: this can only be done by an admin in the panel.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No server with this id (or the id is not a positive integer). — \"Server not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Server not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "No agent connected for this server (or the hub is not running). — \"The agent of this server is offline.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "The agent of this server is offline."
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The agent answered with an error, or the panel could not prepare the update (e.g. monitor mode, binaries not built, panel URL unknown, unsupported architecture). — \"The agent could not update itself: <error>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "The agent could not update itself: <error>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": [
                    {
                        "sessionAuth": []
                    }
                ]
            }
        },
        "/api/fleet/servers/{id}/forecast": {
            "get": {
                "operationId": "fleetServersForecast",
                "summary": "Get disk-full forecast",
                "description": "Returns the current usage of each mounted disk and, for the root disk only, the estimated days until it is full from a linear trend over the last 7 days.\n\n**Roles:** admin.\n\n- daysLeft is null for every mount except \"/\", and for \"/\" when there are fewer than 10 samples, less than 6 hours of history, no growing trend or more than 3650 days left; 0 when already full.\n\n- Per-mount usage comes from the latest live metrics; without them only \"/\" from the stored samples is listed (or an empty list).",
                "tags": [
                    "Fleet"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Server id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Mounts with used percent and days left (null when unknown).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "mounts": [
                                        {
                                            "mount": "/",
                                            "usedPct": 38.8,
                                            "daysLeft": 41.5
                                        },
                                        {
                                            "mount": "/var/lib/docker",
                                            "usedPct": 61.2,
                                            "daysLeft": null
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No server with this id (or the id is not a positive integer). — \"Server not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Server not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/fleet/servers/{id}/inventory": {
            "get": {
                "operationId": "fleetServersInventory",
                "summary": "Get server inventory",
                "description": "Returns the server's services, failed units, Docker containers, pending package updates and OS facts. Without refresh a cached inventory is returned when it is fresh (agent: any age, SSH: under 60 s); with refresh=1 it is read live.\n\n**Roles:** admin.\n\n- When no channel is available it answers 200 with the cached inventory (or inventory:null, at:null) and channel \"none\" instead of an error.\n\n- A failed live read without refresh falls back to the cached inventory; with refresh=1 the error is returned.\n\n- Agent request timeout 90 s.",
                "tags": [
                    "Fleet"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Server id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "refresh",
                        "in": "query",
                        "required": false,
                        "description": "Force a live read (\"1\" or \"true\"). (max 5 chars)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The inventory, when it was read, and the channel (agent|ssh|local|none).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "inventory": {
                                        "services": [
                                            {
                                                "name": "nginx.service",
                                                "description": "A high performance web server",
                                                "active": "active",
                                                "sub": "running",
                                                "enabled": "enabled"
                                            }
                                        ],
                                        "failedUnits": [],
                                        "docker": {
                                            "available": true,
                                            "containers": [
                                                {
                                                    "id": "a3f9c21b7d10",
                                                    "name": "redis",
                                                    "image": "redis:7",
                                                    "state": "running",
                                                    "status": "Up 3 days",
                                                    "cpu": 0.4,
                                                    "memBytes": 12000000
                                                }
                                            ]
                                        },
                                        "updates": {
                                            "manager": "apt",
                                            "count": 4,
                                            "security": 1,
                                            "rebootRequired": false,
                                            "packages": [
                                                {
                                                    "name": "openssl",
                                                    "current": "3.0.13-0ubuntu3.4",
                                                    "available": "3.0.13-0ubuntu3.5",
                                                    "security": true
                                                }
                                            ]
                                        },
                                        "os": "Ubuntu 24.04.1 LTS",
                                        "kernel": "6.8.0-45-generic",
                                        "hostname": "web-1",
                                        "timezone": "Etc/UTC"
                                    },
                                    "at": "2026-11-27T10:00:00.000Z",
                                    "channel": "agent"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No server with this id (or the id is not a positive integer). — \"Server not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Server not found"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "SSH channel: the remote read script failed (the panel host itself: \"Local command failed: <stderr>\"). — \"SSH command failed: <stderr>\"\n\nThe agent disconnected while answering. — \"The agent of this server is offline.\"\n\nThe agent answered with an error. — \"The agent rejected the request: <reason>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "SSH command failed: <stderr>"
                                }
                            }
                        }
                    },
                    "504": {
                        "description": "Agent request timed out. — \"The agent did not answer in time.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "The agent did not answer in time."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/fleet/servers/{id}/logs": {
            "get": {
                "operationId": "fleetServersLogs",
                "summary": "Read server logs",
                "description": "Non-streaming variant for scripts and the AI: reads the last lines of the journal or a log file under /var/log and returns them as JSON. follow is ignored.\n\n**Roles:** admin.\n\n- If the read failed but produced some output, it answers 200 with that output and the non-success status.\n\n- One-shot reads time out after 60 s.",
                "tags": [
                    "Fleet"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Server id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "source",
                        "in": "query",
                        "required": false,
                        "description": "Where to read from: the systemd journal or a log file. (one of: journal, file; default journal)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "unit",
                        "in": "query",
                        "required": false,
                        "description": "systemd unit to filter the journal by (source=journal only). (max 128 chars; pattern ^[A-Za-z0-9@:._-]{1,128}$)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "path",
                        "in": "query",
                        "required": false,
                        "description": "Log file to read (required when source=file). (absolute path under /var/log/, 10–512 chars, characters [A-Za-z0-9._@:+=,~/-], no \"..\", no trailing slash, must be normalised)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "lines",
                        "in": "query",
                        "required": false,
                        "description": "Number of most recent lines. (1–2000, default 200)",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "grep",
                        "in": "query",
                        "required": false,
                        "description": "Only lines containing this text. (max 200 chars, no control characters)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "follow",
                        "in": "query",
                        "required": false,
                        "description": "Accepted but ignored (always one-shot). (max 5 chars)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The lines, the read status and the channel.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "lines": [
                                        "Nov 27 10:00:01 web-1 nginx[812]: 2026/11/27 10:00:01 [notice] signal process started"
                                    ],
                                    "status": "success",
                                    "channel": "agent"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "unit does not match the allowed pattern. — \"Invalid service name.\"\n\nlines out of range (normally caught by the schema first). — \"Lines must be between 1 and 2000.\"\n\ngrep contains control characters. — \"The filter text is too long or contains control characters.\"\n\nsource=file with a missing or invalid path. — \"The log file must be an absolute path under /var/log (no \"..\").\"\n\nInvalid source (normally caught by the schema first). — \"The log source must be \"journal\" or \"file\".\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid service name."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No server with this id (or the id is not a positive integer). — \"Server not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Server not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "preferredChannel is \"agent\" and no agent is connected. — \"The agent of this server is offline (the server is set to use the agent only).\"\n\nAgent-only server (no host) whose agent is not connected. — \"The agent of this server is offline and the server has no SSH access configured.\"\n\nNo agent connected and no SSH host + key. — \"This server is not reachable: the agent is not connected and SSH access is not configured.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "The agent of this server is offline (the server is set to use the agent only)."
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The read failed and produced no output (\"Could not read the logs.\" when there is no error text). — \"Could not read the logs: <error>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Could not read the logs: <error>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/fleet/servers/{id}/logs/stream": {
            "get": {
                "operationId": "fleetServersLogsStream",
                "summary": "Stream server logs",
                "description": "Server-Sent Events of a server's journal or a log file under /var/log: {\"line\": \"…\"} per line, then {\"done\": true, \"status\": \"<status>\"} (plus \"error\" when it failed). With follow=1 new lines keep streaming until the client disconnects (closing the connection stops the remote process) or 2 hours pass.\n\n**Roles:** admin.\n\n**Streams** Server-Sent Events.\n\n- Validation and channel errors are answered as JSON before the stream starts.\n\n- When the read fails a \"[<status>] <error>\" line is sent before the done event.\n\n- status is one of success, failed, timeout, offline, cancelled, denied.\n\n- One-shot reads time out after 60 s.\n\n- Keep-alive comments \": ka\" every 20 s. Send the token in the Authorization header.",
                "tags": [
                    "Fleet"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Server id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "source",
                        "in": "query",
                        "required": false,
                        "description": "Where to read from: the systemd journal or a log file. (one of: journal, file; default journal)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "unit",
                        "in": "query",
                        "required": false,
                        "description": "systemd unit to filter the journal by (source=journal only). (max 128 chars; pattern ^[A-Za-z0-9@:._-]{1,128}$)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "path",
                        "in": "query",
                        "required": false,
                        "description": "Log file to read (required when source=file). (absolute path under /var/log/, 10–512 chars, characters [A-Za-z0-9._@:+=,~/-], no \"..\", no trailing slash, must be normalised)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "lines",
                        "in": "query",
                        "required": false,
                        "description": "Number of most recent lines. (1–2000, default 200)",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "follow",
                        "in": "query",
                        "required": false,
                        "description": "Keep streaming new lines (\"1\" or \"true\"). (max 5 chars; \"1\"/\"true\" = on)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "grep",
                        "in": "query",
                        "required": false,
                        "description": "Only lines containing this text. (max 200 chars, no control characters)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "SSE stream of {line} events ending with {done, status[, error]}.",
                        "content": {
                            "text/event-stream": {
                                "schema": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "unit does not match the allowed pattern. — \"Invalid service name.\"\n\nlines out of range (normally caught by the schema first). — \"Lines must be between 1 and 2000.\"\n\ngrep contains control characters. — \"The filter text is too long or contains control characters.\"\n\nsource=file with a missing or invalid path. — \"The log file must be an absolute path under /var/log (no \"..\").\"\n\nInvalid source (normally caught by the schema first). — \"The log source must be \"journal\" or \"file\".\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid service name."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No server with this id (or the id is not a positive integer). — \"Server not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Server not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "preferredChannel is \"agent\" and no agent is connected. — \"The agent of this server is offline (the server is set to use the agent only).\"\n\nAgent-only server (no host) whose agent is not connected. — \"The agent of this server is offline and the server has no SSH access configured.\"\n\nNo agent connected and no SSH host + key. — \"This server is not reachable: the agent is not connected and SSH access is not configured.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "The agent of this server is offline (the server is set to use the agent only)."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/fleet/servers/{id}/metrics": {
            "get": {
                "operationId": "fleetServersMetrics",
                "summary": "Get metrics history",
                "description": "Returns the stored metric samples of a server over a time range, averaged into at most 400 points. For the panel host the classic monitor samples (serverId null) are included.\n\n**Roles:** admin.\n\n- swap, load1, rx, tx, dr and dw are null when the source could not measure them (e.g. SSH samples have no network or disk I/O).\n\n- When downsampled, t is the middle of each bucket.",
                "tags": [
                    "Fleet"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Server id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "range",
                        "in": "query",
                        "required": false,
                        "description": "Time range. (one of: 1h, 6h, 24h, 7d, 30d; default 24h)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Points in time order: cpu/ram/disk/swap in percent, load1, rx/tx network bytes per second, dr/dw disk read/write bytes per second.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "points": [
                                        {
                                            "t": "2026-11-27T10:00:00.000Z",
                                            "cpu": 12.4,
                                            "ram": 39.1,
                                            "disk": 38.8,
                                            "swap": 0,
                                            "load1": 0.32,
                                            "rx": 18000,
                                            "tx": 42000,
                                            "dr": 1200,
                                            "dw": 54000
                                        },
                                        {
                                            "t": "2026-11-27T10:01:00.000Z",
                                            "cpu": 14.1,
                                            "ram": 39.1,
                                            "disk": 38.8,
                                            "swap": 0,
                                            "load1": 0.32,
                                            "rx": 18000,
                                            "tx": 42000,
                                            "dr": 1200,
                                            "dw": 54000
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No server with this id (or the id is not a positive integer). — \"Server not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Server not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/fleet/servers/{id}/processes": {
            "get": {
                "operationId": "fleetServersProcesses",
                "summary": "List top processes",
                "description": "Reads the current top processes live from the server through the agent, SSH or the panel host itself.\n\n**Roles:** admin.\n\n- Agent request timeout 20 s.",
                "tags": [
                    "Fleet"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Server id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "sort",
                        "in": "query",
                        "required": false,
                        "description": "Sort by CPU or memory. (one of: cpu, mem; default cpu)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "required": false,
                        "description": "Maximum number of processes. (1–100, default 50)",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Processes (cpu/mem in percent, rss in bytes) and the channel that answered.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "processes": [
                                        {
                                            "pid": 1234,
                                            "user": "www-data",
                                            "name": "php-fpm8.3",
                                            "cmd": "php-fpm: pool www",
                                            "cpu": 6.2,
                                            "mem": 2.1,
                                            "rss": 88000000
                                        }
                                    ],
                                    "channel": "agent"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No server with this id (or the id is not a positive integer). — \"Server not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Server not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "preferredChannel is \"agent\" and no agent is connected. — \"The agent of this server is offline (the server is set to use the agent only).\"\n\nAgent-only server (no host) whose agent is not connected. — \"The agent of this server is offline and the server has no SSH access configured.\"\n\nNo agent connected and no SSH host + key. — \"This server is not reachable: the agent is not connected and SSH access is not configured.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "The agent of this server is offline (the server is set to use the agent only)."
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "SSH channel: the remote read script failed (the panel host itself: \"Local command failed: <stderr>\"). — \"SSH command failed: <stderr>\"\n\nThe agent disconnected while answering. — \"The agent of this server is offline.\"\n\nThe agent answered with an error. — \"The agent rejected the request: <reason>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "SSH command failed: <stderr>"
                                }
                            }
                        }
                    },
                    "504": {
                        "description": "Agent request timed out. — \"The agent did not answer in time.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "The agent did not answer in time."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/fleet/servers/{id}/traffic": {
            "get": {
                "operationId": "fleetServersTraffic",
                "summary": "Get network traffic per day",
                "description": "Returns received/transmitted bytes per day (from the agent's interface counters, panel-local dates) for the last N days, plus totals for this and last calendar month.\n\n**Roles:** admin.\n\n- Only agent-connected servers record traffic; others return empty lists and zero totals.\n\n- Monthly totals are computed independently of \"days\".",
                "tags": [
                    "Fleet"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Server id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "days",
                        "in": "query",
                        "required": false,
                        "description": "Number of days in the \"days\" list, ending today. (1–400, default 62)",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Daily traffic in bytes and monthly totals.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "days": [
                                        {
                                            "date": "2026-11-26",
                                            "rx": 4800000000,
                                            "tx": 9100000000
                                        },
                                        {
                                            "date": "2026-11-27",
                                            "rx": 2100000000,
                                            "tx": 3900000000
                                        }
                                    ],
                                    "thisMonth": {
                                        "rx": 98000000000,
                                        "tx": 170000000000
                                    },
                                    "lastMonth": {
                                        "rx": 120000000000,
                                        "tx": 210000000000
                                    }
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No server with this id (or the id is not a positive integer). — \"Server not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Server not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/health": {
            "get": {
                "operationId": "monitorHealth",
                "summary": "Check API liveness",
                "description": "Unauthenticated liveness probe. Returns ok with the server's current time whenever the API process is up and serving.\n\n- It does not check the database or other dependencies. The panel self-update script uses it to verify a new build; in that smoke-test mode (ORCH_SMOKE_TEST=1) the process first reads each main table and exits on a mismatch, before serving.\n\n- Subject to the global rate limit (600 requests per minute per IP).",
                "tags": [
                    "Monitoring"
                ],
                "responses": {
                    "200": {
                        "description": "Liveness status.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "status": "ok",
                                    "ts": "2026-11-27T10:00:00.000Z"
                                }
                            }
                        }
                    }
                },
                "x-auth": "public",
                "x-roles": [],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": []
            }
        },
        "/api/log-errors": {
            "get": {
                "operationId": "logErrorsList",
                "summary": "List error groups",
                "description": "Lists grouped application errors collected from site logs (up to 200, most recently seen first). Ignored groups are hidden unless ignored=1. unresolved is the total number of unresolved, not-ignored groups.\n\n**Roles:** admin.\n\n- Admin only; error groups span all sites (no per-site access check).\n\n- unresolved is not filtered by siteId or search.\n\n- The search uses Prisma contains on SQLite (LIKE), which is case-insensitive for ASCII only.",
                "tags": [
                    "Logs and errors"
                ],
                "parameters": [
                    {
                        "name": "siteId",
                        "in": "query",
                        "required": false,
                        "description": "Only groups of this site.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "search",
                        "in": "query",
                        "required": false,
                        "description": "Text contained in message or exceptionClass.",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "resolved",
                        "in": "query",
                        "required": false,
                        "description": "\"0\" = unresolved only, \"1\" = resolved only; anything else = both. Ignored when ignored=1. (one of: 0, 1)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "ignored",
                        "in": "query",
                        "required": false,
                        "description": "\"1\" = show only ignored (muted) groups; otherwise ignored groups are excluded. (one of: 1)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Error groups and the global unresolved count.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "errors": [
                                        {
                                            "id": 31,
                                            "siteId": 12,
                                            "level": "error",
                                            "exceptionClass": "Illuminate\\Database\\QueryException",
                                            "message": "SQLSTATE[HY000] [2002] Connection refused",
                                            "count": 14,
                                            "firstSeenAt": "2026-11-26T08:12:00.000Z",
                                            "lastSeenAt": "2026-11-27T10:00:00.000Z",
                                            "resolved": false,
                                            "ignored": false,
                                            "site": {
                                                "domain": "shop.example.com"
                                            }
                                        }
                                    ],
                                    "unresolved": 5
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/log-errors/{id}": {
            "get": {
                "operationId": "logErrorsGet",
                "summary": "Get an error group",
                "description": "Returns one error group with all stored fields, its site, and the most recent deployment created at or before the group was first seen (introducedBy, best-effort, or null).\n\n**Roles:** admin.\n\n- Admin only; error groups span all sites (no per-site access check).\n\n- Error samples can contain sensitive request data.",
                "tags": [
                    "Logs and errors"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Error group id (LogError id).",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The error group with its site and the suspected deploy.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 31,
                                    "siteId": 12,
                                    "fingerprint": "9b2e4c71d0a8",
                                    "level": "error",
                                    "exceptionClass": "Illuminate\\Database\\QueryException",
                                    "message": "SQLSTATE[HY000] [2002] Connection refused",
                                    "sample": "[2026-11-26 08:12:00] production.ERROR: SQLSTATE[HY000] [2002] Connection refused",
                                    "count": 14,
                                    "firstSeenAt": "2026-11-26T08:12:00.000Z",
                                    "lastSeenAt": "2026-11-27T10:00:00.000Z",
                                    "resolved": false,
                                    "ignored": false,
                                    "aiExplanation": null,
                                    "createdAt": "2026-11-26T08:12:05.000Z",
                                    "site": {
                                        "id": 12,
                                        "domain": "shop.example.com"
                                    },
                                    "introducedBy": {
                                        "id": 88,
                                        "branch": "main",
                                        "commit": "a3f9c21",
                                        "createdAt": "2026-11-26T07:55:00.000Z"
                                    }
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No error group with this id. — \"Not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "patch": {
                "operationId": "logErrorsUpdate",
                "summary": "Resolve or ignore an error group",
                "description": "Sets the resolved and/or ignored flags of an error group and returns the updated row. Ignored groups are no longer re-surfaced by the collector.\n\n**Roles:** admin.\n\n- Admin only; error groups span all sites (no per-site access check).\n\n- Both fields are optional; an empty object changes nothing and returns the row.\n\n- No audit entry is written.",
                "tags": [
                    "Logs and errors"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Error group id (LogError id).",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The updated error group (all stored fields, without site).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 31,
                                    "siteId": 12,
                                    "fingerprint": "9b2e4c71d0a8",
                                    "level": "error",
                                    "exceptionClass": "Illuminate\\Database\\QueryException",
                                    "message": "SQLSTATE[HY000] [2002] Connection refused",
                                    "sample": "[2026-11-26 08:12:00] production.ERROR: SQLSTATE[HY000] [2002] Connection refused",
                                    "count": 14,
                                    "firstSeenAt": "2026-11-26T08:12:00.000Z",
                                    "lastSeenAt": "2026-11-27T10:00:00.000Z",
                                    "resolved": true,
                                    "ignored": false,
                                    "aiExplanation": null,
                                    "createdAt": "2026-11-26T08:12:05.000Z"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No error group with this id. — \"Not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "resolved": {
                                        "type": "boolean",
                                        "description": "Mark resolved (true) or unresolved (false)."
                                    },
                                    "ignored": {
                                        "type": "boolean",
                                        "description": "Mute (true) or unmute (false) the group."
                                    }
                                }
                            },
                            "example": {
                                "resolved": true
                            }
                        }
                    }
                }
            },
            "delete": {
                "operationId": "logErrorsDelete",
                "summary": "Dismiss an error group",
                "description": "Deletes an error group. If the error occurs again, the collector creates a new group.\n\n**Roles:** admin.\n\n- Admin only; error groups span all sites (no per-site access check).\n\n- Returns { ok: true } even when the id does not exist.\n\n- No audit entry is written.",
                "tags": [
                    "Logs and errors"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Error group id (LogError id).",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Always ok.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/mcp-activity": {
            "get": {
                "operationId": "mcpActivityList",
                "summary": "List AI client activity",
                "description": "Lists requests made with personal access tokens (typically MCP/AI clients), newest first, with optional filters, plus a summary of the last 24 hours. Admin only.\n\n**Roles:** admin.\n\n- Recorded by a global onResponse hook for every request authenticated with a personal access token (reads and writes); panel (JWT) sessions are not recorded. Recording is best-effort.\n\n- siteId is filled only for paths containing /sites/<number>. path never includes the query string. ok is status < 400.\n\n- The recorder never fills detail, so it is always null in practice.\n\n- The summary always covers the last 24 hours of all activity and ignores the filters. actions24h counts non-GET requests; errors24h counts requests with ok = false.\n\n- The table is pruned to roughly the 10,000 most recent rows (the prune runs at random on about 2% of recorded requests).\n\n- tokenId is kept even after the token is revoked.",
                "tags": [
                    "Audit and AI activity"
                ],
                "parameters": [
                    {
                        "name": "tokenId",
                        "in": "query",
                        "required": false,
                        "description": "Only requests made with this access token. (not validated)",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "siteId",
                        "in": "query",
                        "required": false,
                        "description": "Only requests that targeted this site. (not validated)",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "tool",
                        "in": "query",
                        "required": false,
                        "description": "Only requests with this exact MCP tool name (from the X-MCP-Tool header). (exact match)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "type",
                        "in": "query",
                        "required": false,
                        "description": "write = POST/PUT/PATCH/DELETE only; read = GET only. Any other value means no method filter. (one of: read, write)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "q",
                        "in": "query",
                        "required": false,
                        "description": "Substring to look for in the request path.",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "required": false,
                        "description": "Maximum number of items. (default 100, min 1, max 500)",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Activity items and a 24-hour summary.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "items": [
                                        {
                                            "id": 5310,
                                            "createdAt": "2026-11-27T10:00:00.000Z",
                                            "tokenId": 4,
                                            "tokenName": "CI deploys",
                                            "userEmail": "ada@example.com",
                                            "tool": "deploy_site",
                                            "method": "POST",
                                            "path": "/api/sites/12/deploy",
                                            "siteId": 12,
                                            "status": 200,
                                            "ok": true,
                                            "durationMs": 184,
                                            "ip": "203.0.113.25",
                                            "detail": null
                                        }
                                    ],
                                    "summary": {
                                        "last24h": 42,
                                        "actions24h": 5,
                                        "errors24h": 1
                                    }
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/mcp-activity/filters": {
            "get": {
                "operationId": "mcpActivityFilters",
                "summary": "List AI activity filter values",
                "description": "Returns the distinct access tokens and MCP tool names found in the activity log, to populate filter dropdowns. Admin only.\n\n**Roles:** admin.\n\n- At most 100 tokens and 200 tools (tools sorted alphabetically).\n\n- tokenName comes from one of the recorded rows for that token; if a token was renamed, which name appears is not guaranteed.",
                "tags": [
                    "Audit and AI activity"
                ],
                "responses": {
                    "200": {
                        "description": "Distinct tokens and tool names.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "tokens": [
                                        {
                                            "tokenId": 4,
                                            "tokenName": "CI deploys"
                                        }
                                    ],
                                    "tools": [
                                        "deploy_site",
                                        "list_sites"
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/monitor/apm": {
            "get": {
                "operationId": "monitorApm",
                "summary": "Get response-time percentiles",
                "description": "For every site with uptime monitoring enabled, computes uptime % and response-time statistics (avg, p50, p95, p99, max in ms) from the stored uptime checks of the last N hours. Sites are sorted by p95, slowest first.\n\n**Roles:** admin.\n\n- Statistics are null when a site has no checks (or no response times) in the window. Read-only; it sends no requests to the sites.",
                "tags": [
                    "Monitoring"
                ],
                "parameters": [
                    {
                        "name": "hours",
                        "in": "query",
                        "required": false,
                        "description": "Look-back window in hours. (1–168, default 24)",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Per-site statistics.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "hours": 24,
                                    "sites": [
                                        {
                                            "siteId": 12,
                                            "domain": "shop.example.com",
                                            "samples": 288,
                                            "uptimePct": 99.7,
                                            "avg": 182,
                                            "p50": 160,
                                            "p95": 410,
                                            "p99": 780,
                                            "max": 1250
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/monitor/health-score/{siteId}": {
            "get": {
                "operationId": "monitorHealthScore",
                "summary": "Get a site's health score",
                "description": "Computes a 0–100 health score for a site: uptime over the last 24 h (40 points), last deployment status (30: success 30, failed 0, none or other 15), SSL enabled (20) and not in maintenance (10). A billing-suspended or archived site always scores 0 with suspended=true.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- An unknown site id (for an admin) returns 200 with {\"score\": 0, \"breakdown\": {}} instead of 404.\n\n- With no uptime checks in the last 24 h the uptime component counts as 100% (40 points).\n\n- enforcementLevel is the billing subscription's level (none, banner, restrict, suspend, archived); suspend and archived force score 0.",
                "tags": [
                    "Monitoring"
                ],
                "parameters": [
                    {
                        "name": "siteId",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The score and its breakdown.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "score": 92,
                                    "suspended": false,
                                    "enforcementLevel": "none",
                                    "breakdown": {
                                        "uptime": 32,
                                        "deploy": 30,
                                        "ssl": 20,
                                        "maintenance": 10
                                    }
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Non-admin caller without a grant for this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/monitor/history": {
            "get": {
                "operationId": "monitorHistory",
                "summary": "Get metric history",
                "description": "Returns the stored CPU/RAM/disk percentage samples captured by the metrics monitor for the last N hours, oldest first. Without serverId it returns the panel host's own history.\n\n**Roles:** admin.\n\n- Unknown query parameters are removed silently (additionalProperties false). An unknown serverId simply returns an empty samples array.",
                "tags": [
                    "Monitoring"
                ],
                "parameters": [
                    {
                        "name": "hours",
                        "in": "query",
                        "required": false,
                        "description": "Look-back window in hours. (1–168, default 24)",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "serverId",
                        "in": "query",
                        "required": false,
                        "description": "Fleet server id; omit for the panel host (samples with serverId null).",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The window and its samples.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "hours": 24,
                                    "samples": [
                                        {
                                            "cpuPercent": 12,
                                            "ramPercent": 48,
                                            "diskPercent": 37,
                                            "checkedAt": "2026-11-27T10:00:00.000Z"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/monitor/logs/{siteId}/stream": {
            "get": {
                "operationId": "monitorSiteLogStream",
                "summary": "Stream a site's Laravel log",
                "description": "Server-Sent Events stream of tail -F -n 100 on <rootPath>/current/storage/logs/laravel.log, run on the site's own server (locally or over SSH). Sends the last 100 lines, then follows new output until the client disconnects.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n**Streams** Server-Sent Events.\n\n- Event payloads: {\"line\": \"<raw output chunk>\"} — one event per stdout chunk, which may contain several log lines (not split on newlines); {\"error\": \"<stderr text>\"} for tail errors other than \"No such file\" messages.\n\n- End signal: {\"done\": true} when tail exits, or {\"error\": \"<message>\", \"done\": true} when tail cannot be started; then the response ends. Normally it runs until the client disconnects.\n\n- A comment line \": ka\" is sent every 20 seconds as keep-alive.\n\n- The log path is fixed to the Laravel location; a missing file produces no error event (tail -F waits for it).",
                "tags": [
                    "Monitoring"
                ],
                "parameters": [
                    {
                        "name": "siteId",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "SSE stream; every event is a single \"data: <json>\" line.",
                        "content": {
                            "text/event-stream": {
                                "schema": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Non-admin caller without a grant for this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id (sent before the stream starts). — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/monitor/processes": {
            "get": {
                "operationId": "monitorProcesses",
                "summary": "List top processes",
                "description": "Returns the panel host's top resource consumers, grouped by command into services (e.g. all php-fpm workers summed as PHP-FPM), sorted by CPU descending.\n\n**Roles:** admin.\n\n- cpuPercent is summed over processes and can exceed 100 on multi-core hosts.\n\n- Uses GNU ps; on hosts without it services is an empty array.",
                "tags": [
                    "Monitoring"
                ],
                "parameters": [
                    {
                        "name": "limit",
                        "in": "query",
                        "required": false,
                        "description": "Number of service groups to return. (1–25, default 8)",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Core count and grouped services.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "cores": 4,
                                    "services": [
                                        {
                                            "name": "PHP-FPM",
                                            "cpuPercent": 38.5,
                                            "memPercent": 12.1,
                                            "rssBytes": 1010000000,
                                            "count": 9
                                        }
                                    ],
                                    "capturedAt": "2026-11-27T10:00:00.000Z"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/monitor/services": {
            "get": {
                "operationId": "monitorServices",
                "summary": "List core service status",
                "description": "Reports whether each core service on the panel host is active according to systemctl is-active. The fixed catalogue is nginx, mysql (mysql or mariadb), redis (redis-server or redis), php-fpm (php8.3-fpm, php8.2-fpm or php8.1-fpm) and supervisor.\n\n**Roles:** admin.\n\n- status is active or inactive only; a service that is not installed reports inactive.\n\n- Only checks the panel host, not remote fleet servers.",
                "tags": [
                    "Monitoring"
                ],
                "responses": {
                    "200": {
                        "description": "A JSON array with one entry per catalogue service (a bare array, not wrapped in an object).",
                        "content": {
                            "application/json": {
                                "example": [
                                    {
                                        "key": "nginx",
                                        "name": "Nginx",
                                        "status": "active"
                                    },
                                    {
                                        "key": "redis",
                                        "name": "Redis",
                                        "status": "inactive"
                                    }
                                ]
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/monitor/services/{key}/control": {
            "post": {
                "operationId": "monitorServiceControl",
                "summary": "Start, stop or restart a service",
                "description": "Runs systemctl <action> on the panel host for one catalogue service and returns the command output and the service status afterwards. The unit name is the first installed candidate for the key.\n\n**Roles:** admin.\n\n- systemctl is called directly without sudo, so it only succeeds when the API has the privileges to manage units.\n\n- Not audited.\n\n- Stopping nginx makes the panel itself unreachable behind its reverse proxy.",
                "tags": [
                    "Monitoring"
                ],
                "parameters": [
                    {
                        "name": "key",
                        "in": "path",
                        "required": true,
                        "description": "Service key. (one of: nginx, mysql, redis, php-fpm, supervisor)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The outcome. ok is false when systemctl exited non-zero; the HTTP status is still 200.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "key": "nginx",
                                    "serviceName": "nginx",
                                    "action": "restart",
                                    "status": "active",
                                    "output": ""
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "action is not allowed (normally caught earlier by schema validation). — \"Invalid action: <action>\"\n\nkey is not in the catalogue. — \"Unknown service: <key>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid action: <action>"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "action": {
                                        "type": "string",
                                        "description": "systemctl action. (one of: start, stop, restart, reload)"
                                    }
                                },
                                "required": [
                                    "action"
                                ]
                            },
                            "example": {
                                "action": "restart"
                            }
                        }
                    }
                }
            }
        },
        "/api/monitor/services/{key}/logs": {
            "get": {
                "operationId": "monitorServiceLogs",
                "summary": "Stream service logs",
                "description": "Server-Sent Events stream of journalctl -u <unit> -f on the panel host: the last 100 lines, then new lines as they are written, until the client disconnects.\n\n**Roles:** admin.\n\n**Streams** Server-Sent Events.\n\n- Event payloads: {\"line\": \"<one log line, short-iso format>\"} per line; {\"error\": \"<stderr text>\"} for journalctl stderr.\n\n- End signal: {\"done\": true} when journalctl exits, or {\"error\": \"<message>\", \"done\": true} when journalctl cannot be started; then the response ends. With -f it normally runs until the client closes the connection.\n\n- A comment line \": ka\" is sent every 20 seconds as keep-alive.\n\n- EventSource cannot send an Authorization header; the web client reads the stream with fetch() and a Bearer header.",
                "tags": [
                    "Monitoring"
                ],
                "parameters": [
                    {
                        "name": "key",
                        "in": "path",
                        "required": true,
                        "description": "Service key. (one of: nginx, mysql, redis, php-fpm, supervisor)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "SSE stream; every event is a single \"data: <json>\" line.",
                        "content": {
                            "text/event-stream": {
                                "schema": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "key is not in the catalogue (sent before the stream starts). — \"Unknown service: <key>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Unknown service: <key>"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/monitor/ssl": {
            "get": {
                "operationId": "monitorSsl",
                "summary": "Check SSL expiry for all sites",
                "description": "Opens a live TLS connection to port 443 of every active site with SSL enabled and reports the certificate's expiry date and days left.\n\n**Roles:** admin.\n\n- Each site has a 10-second timeout (error \"Timeout\"); a handshake without a certificate gives error \"No certificate\"; connection errors give the socket error message.\n\n- Certificates are read with rejectUnauthorized false, so invalid or self-signed certificates still report an expiry.",
                "tags": [
                    "Monitoring"
                ],
                "responses": {
                    "200": {
                        "description": "One result per site.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "sites": [
                                        {
                                            "siteId": 12,
                                            "domain": "shop.example.com",
                                            "daysLeft": 63,
                                            "expiresAt": "2027-01-29T10:00:00.000Z",
                                            "error": null
                                        },
                                        {
                                            "siteId": 14,
                                            "domain": "blog.example.com",
                                            "daysLeft": null,
                                            "expiresAt": null,
                                            "error": "Timeout"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/monitor/stats/history": {
            "get": {
                "operationId": "monitorDeployStats",
                "summary": "Get 7-day deploy counts",
                "description": "Returns, for each of the last 7 days including today, the number of successful and failed deployments across all sites, oldest day first.\n\n**Roles:** admin.\n\n- Day boundaries use the API server's local midnight, while date is printed from the UTC ISO string, so labels can be shifted by one day on servers not running in UTC.",
                "tags": [
                    "Monitoring"
                ],
                "responses": {
                    "200": {
                        "description": "Seven day buckets.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "days": [
                                        {
                                            "date": "2026-11-21",
                                            "success": 4,
                                            "failed": 0
                                        },
                                        {
                                            "date": "2026-11-27",
                                            "success": 2,
                                            "failed": 1
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/monitor/system": {
            "get": {
                "operationId": "monitorSystem",
                "summary": "Get panel host stats",
                "description": "Returns a live CPU, RAM, disk, swap and uptime snapshot of the panel host (the machine the API runs on). Sizes are in bytes.\n\n**Roles:** admin.\n\n- cpu.percent is load1 / cores × 100, capped at 100 — a load estimate, not a sampled CPU utilisation.\n\n- disk is for the / filesystem. Disk and swap fall back to zeros when df/free are unavailable.",
                "tags": [
                    "Monitoring"
                ],
                "responses": {
                    "200": {
                        "description": "The host snapshot.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "cpu": {
                                        "load1": 0.42,
                                        "load5": 0.38,
                                        "load15": 0.3,
                                        "cores": 4,
                                        "percent": 11
                                    },
                                    "ram": {
                                        "total": 8340000000,
                                        "used": 4120000000,
                                        "free": 4220000000,
                                        "percent": 49
                                    },
                                    "disk": {
                                        "total": 85000000000,
                                        "used": 31000000000,
                                        "percent": 37
                                    },
                                    "swap": {
                                        "total": 2147483648,
                                        "used": 104857600,
                                        "percent": 5
                                    },
                                    "uptime": 1209600,
                                    "hostname": "panel-01"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/notes": {
            "get": {
                "operationId": "notesList",
                "summary": "List notes",
                "description": "Lists every note the caller can see — their own, notes shared with them and public notes — pinned first, then most recently updated. Each note carries a canEdit flag for the caller.\n\n**Roles:** admin, developer, viewer.\n\n- Admins have no special visibility: they also see only their own, shared and public notes.\n\n- tags is a JSON-encoded string array. body is Markdown.\n\n- Public notes are read-only for everyone except the owner and users with an edit share.",
                "tags": [
                    "Tasks, notes and calendar"
                ],
                "parameters": [
                    {
                        "name": "search",
                        "in": "query",
                        "required": false,
                        "description": "Substring to look for in title or body.",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "tag",
                        "in": "query",
                        "required": false,
                        "description": "Only notes that have exactly this tag. (exact match)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "pinned",
                        "in": "query",
                        "required": false,
                        "description": "Set to 1 to return only pinned notes. (only \"1\" has an effect)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "siteId",
                        "in": "query",
                        "required": false,
                        "description": "Only notes linked to this site. (not validated)",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The visible notes.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "notes": [
                                        {
                                            "id": 5,
                                            "title": "Shop deploy checklist",
                                            "body": "1. Run migrations\n2. Clear cache",
                                            "pinned": true,
                                            "isPublic": false,
                                            "tags": "[\"runbook\"]",
                                            "siteId": 12,
                                            "ownerId": 1,
                                            "createdAt": "2026-11-01T09:00:00.000Z",
                                            "updatedAt": "2026-11-27T10:00:00.000Z",
                                            "owner": {
                                                "id": 1,
                                                "email": "ada@example.com"
                                            },
                                            "site": {
                                                "id": 12,
                                                "domain": "shop.example.com",
                                                "name": "Shop"
                                            },
                                            "shares": [
                                                {
                                                    "userId": 12,
                                                    "canEdit": true,
                                                    "user": {
                                                        "id": 12,
                                                        "email": "grace@example.com"
                                                    }
                                                }
                                            ],
                                            "canEdit": true
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "notesCreate",
                "summary": "Create a note",
                "description": "Creates a note owned by the caller.\n\n**Roles:** admin, developer, viewer.\n\n- siteId is not checked against the caller's site grants; a non-existent siteId surfaces as a 500 error.",
                "tags": [
                    "Tasks, notes and calendar"
                ],
                "responses": {
                    "201": {
                        "description": "The created note.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 5,
                                    "title": "Shop deploy checklist",
                                    "body": "1. Run migrations\n2. Clear cache",
                                    "pinned": true,
                                    "isPublic": false,
                                    "tags": "[\"runbook\"]",
                                    "siteId": 12,
                                    "ownerId": 1,
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z",
                                    "owner": {
                                        "id": 1,
                                        "email": "ada@example.com"
                                    },
                                    "site": {
                                        "id": 12,
                                        "domain": "shop.example.com",
                                        "name": "Shop"
                                    },
                                    "shares": [],
                                    "canEdit": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "title": {
                                        "type": "string",
                                        "description": "Note title. (1–200 chars)"
                                    },
                                    "body": {
                                        "type": "string",
                                        "description": "Markdown content. (max 100000 chars; default \"\")"
                                    },
                                    "tags": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Tags (array of strings). (items: string; default [])"
                                    },
                                    "pinned": {
                                        "type": "boolean",
                                        "description": "Pin the note to the top of the list. (default false)"
                                    },
                                    "isPublic": {
                                        "type": "boolean",
                                        "description": "Make the note visible (read-only) to every panel user. (default false)"
                                    },
                                    "siteId": {
                                        "type": "integer",
                                        "description": "Site to link the note to."
                                    }
                                },
                                "required": [
                                    "title"
                                ]
                            },
                            "example": {
                                "title": "Shop deploy checklist",
                                "body": "1. Run migrations\n2. Clear cache",
                                "tags": [
                                    "runbook"
                                ],
                                "pinned": true,
                                "isPublic": false,
                                "siteId": 12
                            }
                        }
                    }
                }
            }
        },
        "/api/notes/{id}": {
            "get": {
                "operationId": "notesGet",
                "summary": "Get a note",
                "description": "Returns one note if the caller owns it, it is shared with them, or it is public.\n\n**Roles:** admin, developer, viewer.",
                "tags": [
                    "Tasks, notes and calendar"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Note id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The note with the caller's canEdit flag.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 5,
                                    "title": "Shop deploy checklist",
                                    "body": "1. Run migrations\n2. Clear cache",
                                    "pinned": true,
                                    "isPublic": false,
                                    "tags": "[\"runbook\"]",
                                    "siteId": 12,
                                    "ownerId": 1,
                                    "createdAt": "2026-11-01T09:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z",
                                    "owner": {
                                        "id": 1,
                                        "email": "ada@example.com"
                                    },
                                    "site": {
                                        "id": 12,
                                        "domain": "shop.example.com",
                                        "name": "Shop"
                                    },
                                    "shares": [
                                        {
                                            "userId": 12,
                                            "canEdit": true,
                                            "user": {
                                                "id": 12,
                                                "email": "grace@example.com"
                                            }
                                        }
                                    ],
                                    "canEdit": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No note with this id, or the caller may not see it. — \"Note not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Note not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "patch": {
                "operationId": "notesUpdate",
                "summary": "Update a note",
                "description": "Changes a note. Allowed for the owner and for users the note is shared with edit rights. Only the fields sent are changed; only the owner can change isPublic.\n\n**Roles:** admin, developer, viewer.\n\n- isPublic sent by a non-owner editor is silently ignored (no error).\n\n- pinned is a property of the note, so pinning affects everyone who sees it.",
                "tags": [
                    "Tasks, notes and calendar"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Note id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The updated note.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 5,
                                    "title": "Shop deploy checklist",
                                    "body": "1. Run migrations\n2. Clear cache\n3. Warm up",
                                    "pinned": false,
                                    "isPublic": false,
                                    "tags": "[\"runbook\"]",
                                    "siteId": 12,
                                    "ownerId": 1,
                                    "createdAt": "2026-11-01T09:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z",
                                    "owner": {
                                        "id": 1,
                                        "email": "ada@example.com"
                                    },
                                    "site": {
                                        "id": 12,
                                        "domain": "shop.example.com",
                                        "name": "Shop"
                                    },
                                    "shares": [
                                        {
                                            "userId": 12,
                                            "canEdit": true,
                                            "user": {
                                                "id": 12,
                                                "email": "grace@example.com"
                                            }
                                        }
                                    ],
                                    "canEdit": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller can see the note (public or read-only share) but may not edit it. — \"You do not have edit access to this note.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "You do not have edit access to this note."
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No note with this id, or the caller may not see it. — \"Note not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Note not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "title": {
                                        "type": "string",
                                        "description": "Note title. (1–200 chars)"
                                    },
                                    "body": {
                                        "type": "string",
                                        "description": "Markdown content. (max 100000 chars)"
                                    },
                                    "tags": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Replaces all tags (array of strings). (items: string)"
                                    },
                                    "pinned": {
                                        "type": "boolean",
                                        "description": "Pin or unpin."
                                    },
                                    "isPublic": {
                                        "type": "boolean",
                                        "description": "Public visibility. Ignored unless the caller is the owner."
                                    },
                                    "siteId": {
                                        "type": "integer",
                                        "description": "Linked site; null unlinks. (nullable)"
                                    }
                                }
                            },
                            "example": {
                                "body": "1. Run migrations\n2. Clear cache\n3. Warm up",
                                "pinned": false
                            }
                        }
                    }
                }
            },
            "delete": {
                "operationId": "notesDelete",
                "summary": "Delete a note",
                "description": "Deletes a note and its shares. Only the owner may delete it.\n\n**Roles:** admin, developer, viewer.\n\n- Unlike the other note endpoints, a note the caller cannot see returns 403 here, not 404.",
                "tags": [
                    "Tasks, notes and calendar"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Note id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The note was deleted.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not the owner (admins included). — \"Only the owner can delete this note.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Only the owner can delete this note."
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No note with this id. — \"Note not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Note not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/notes/{id}/shares": {
            "put": {
                "operationId": "notesSharesSet",
                "summary": "Replace a note's shares",
                "description": "Replaces the full list of users a note is shared with, and whether each may edit it. Only the owner may manage sharing. Send an empty array to stop sharing.\n\n**Roles:** admin, developer, viewer.\n\n- Entries for the owner are dropped silently.\n\n- Duplicate userIds or ids of non-existent users make the database reject the transaction (surfaces as a 500 error); the previous shares are kept.\n\n- The audit entry stores {noteId, shareCount}, where shareCount is the number of entries sent (before dropping the owner).",
                "tags": [
                    "Tasks, notes and calendar"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Note id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The note with its new shares.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 5,
                                    "title": "Shop deploy checklist",
                                    "body": "1. Run migrations\n2. Clear cache",
                                    "pinned": true,
                                    "isPublic": false,
                                    "tags": "[\"runbook\"]",
                                    "siteId": 12,
                                    "ownerId": 1,
                                    "createdAt": "2026-11-01T09:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z",
                                    "owner": {
                                        "id": 1,
                                        "email": "ada@example.com"
                                    },
                                    "site": {
                                        "id": 12,
                                        "domain": "shop.example.com",
                                        "name": "Shop"
                                    },
                                    "shares": [
                                        {
                                            "userId": 12,
                                            "canEdit": true,
                                            "user": {
                                                "id": 12,
                                                "email": "grace@example.com"
                                            }
                                        },
                                        {
                                            "userId": 15,
                                            "canEdit": false,
                                            "user": {
                                                "id": 15,
                                                "email": "linus@example.com"
                                            }
                                        }
                                    ],
                                    "canEdit": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not the owner. — \"Only the owner can manage sharing.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Only the owner can manage sharing."
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No note with this id. — \"Note not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Note not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "shares": {
                                        "type": "array",
                                        "items": {},
                                        "description": "The new share list."
                                    }
                                },
                                "required": [
                                    "shares"
                                ]
                            },
                            "example": {
                                "shares": [
                                    {
                                        "userId": 12,
                                        "canEdit": true
                                    },
                                    {
                                        "userId": 15
                                    }
                                ]
                            }
                        }
                    }
                }
            }
        },
        "/api/notifications": {
            "get": {
                "operationId": "notificationsList",
                "summary": "List notifications",
                "description": "Returns the 50 most recent in-app notifications (the bell feed) and the number of unread notifications. The feed is global to the panel: every user sees the same notifications and read state.\n\n**Roles:** admin, developer, viewer.\n\n- type is one of deploy, alert, ssl, uptime, system; level is one of info, success, warning, critical.\n\n- meta is returned as the raw stored JSON string (or null), not as an object.\n\n- Notifications are not filtered by the caller's site access. The feed keeps only the latest 200 rows.\n\n- unread counts all unread notifications, not only the 50 returned.",
                "tags": [
                    "Notifications"
                ],
                "responses": {
                    "200": {
                        "description": "Recent notifications and the unread count.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "notifications": [
                                        {
                                            "id": 301,
                                            "type": "deploy",
                                            "level": "success",
                                            "title": "Deploy succeeded",
                                            "body": "shop.example.com deployed a3f9c21",
                                            "meta": "{\"siteId\":12,\"domain\":\"shop.example.com\"}",
                                            "read": false,
                                            "createdAt": "2026-11-27T10:00:00.000Z"
                                        }
                                    ],
                                    "unread": 1
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "delete": {
                "operationId": "notificationsClear",
                "summary": "Clear all notifications",
                "description": "Deletes every notification in the global feed. Admin only.\n\n**Roles:** admin.\n\n- Irreversible and affects all users.",
                "tags": [
                    "Notifications"
                ],
                "responses": {
                    "200": {
                        "description": "The feed is empty.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/notifications/read-all": {
            "post": {
                "operationId": "notificationsReadAll",
                "summary": "Mark all notifications read",
                "description": "Marks every unread notification as read. Because the feed is global, this marks them read for all users.\n\n**Roles:** admin, developer, viewer.\n\n- Send no body (or no Content-Type: application/json header); an empty JSON body is rejected by Fastify with 400.",
                "tags": [
                    "Notifications"
                ],
                "responses": {
                    "200": {
                        "description": "All notifications are read.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/notifications/{id}": {
            "delete": {
                "operationId": "notificationsDelete",
                "summary": "Delete a notification",
                "description": "Removes one notification from the global feed. Admin only.\n\n**Roles:** admin.\n\n- Returns {\"ok\": true} even when no notification has this id.",
                "tags": [
                    "Notifications"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Notification id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Always returns ok.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/notifications/{id}/read": {
            "post": {
                "operationId": "notificationsRead",
                "summary": "Mark a notification read",
                "description": "Marks one notification as read (for all users, as the feed is global).\n\n**Roles:** admin, developer, viewer.\n\n- Returns {\"ok\": true} even when no notification has this id (errors are swallowed).",
                "tags": [
                    "Notifications"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Notification id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Always returns ok.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/portal/{token}": {
            "get": {
                "operationId": "portalGet",
                "summary": "Get the client portal",
                "description": "Read-only billing portal for one client, found by the client's portal token. Returns the client's name and currency, their active sites with uptime, the outstanding balance and their invoices (latest 50, without drafts and voided ones) with payments. Amounts are integers in minor units (e.g. tetri, cents) plus formatted strings.\n\n- invoices[].status is one of open, partial, paid, overdue (draft and void are filtered out). payments[] items have amount, amountFormatted, method (cash | bank_transfer | card | other) and receivedAt.\n\n- sites[].active is false when the subscription's enforcement level is suspend or archived; the internal level itself is not exposed. uptime24h is null without checks in the last 24 h.\n\n- Only the global rate limit (600 requests per minute per IP) applies.",
                "tags": [
                    "Public"
                ],
                "parameters": [
                    {
                        "name": "token",
                        "in": "path",
                        "required": true,
                        "description": "The client's portal token. (at least 24 chars)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The client's portal data.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "client": {
                                        "name": "Ada Lovelace",
                                        "company": "Example Ltd",
                                        "locale": "en",
                                        "currency": "GEL"
                                    },
                                    "sites": [
                                        {
                                            "domain": "shop.example.com",
                                            "active": true,
                                            "amountFormatted": "30.00 ₾",
                                            "nextInvoiceAt": "2026-12-01T00:00:00.000Z",
                                            "uptime24h": 100,
                                            "currentStatus": "up",
                                            "lastCheckedAt": "2026-11-27T10:00:00.000Z"
                                        }
                                    ],
                                    "outstanding": 3000,
                                    "outstandingFormatted": "30.00 ₾",
                                    "invoices": [
                                        {
                                            "number": "INV-2026-0042",
                                            "periodStart": "2026-11-01T00:00:00.000Z",
                                            "periodEnd": "2026-11-30T23:59:59.000Z",
                                            "dueDate": "2026-11-10T00:00:00.000Z",
                                            "status": "open",
                                            "amount": 3000,
                                            "amountPaid": 0,
                                            "balance": 3000,
                                            "currency": "GEL",
                                            "amountFormatted": "30.00 ₾",
                                            "balanceFormatted": "30.00 ₾",
                                            "paidAt": null,
                                            "payments": []
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Token shorter than 24 chars, unknown, client archived, or the client has no subscription that is not cancelled. — \"Not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "token-in-path",
                "x-roles": [],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": []
            }
        },
        "/api/portal/{token}/backups": {
            "get": {
                "operationId": "portalBackups",
                "summary": "List the client's backups",
                "description": "Lists the database backup files (*.sql or *.sql.gz in <rootPath>/backups) of each of the client's active sites hosted on the panel host, newest first, max 20 per site.\n\n- Sites on remote servers are omitted entirely. A site without a backups directory is listed with an empty files array. Only names matching ^[\\w.\\-]+\\.sql(\\.gz)?$ are listed.",
                "tags": [
                    "Public"
                ],
                "parameters": [
                    {
                        "name": "token",
                        "in": "path",
                        "required": true,
                        "description": "The client's portal token. (at least 24 chars)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Backups per site.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "sites": [
                                        {
                                            "siteId": 12,
                                            "domain": "shop.example.com",
                                            "files": [
                                                {
                                                    "filename": "shop_2026-11-27.sql.gz",
                                                    "sizeBytes": 4821033,
                                                    "createdAt": "2026-11-27T03:00:00.000Z"
                                                }
                                            ]
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Token invalid, client archived, or no active billing. — \"Not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "token-in-path",
                "x-roles": [],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": []
            }
        },
        "/api/portal/{token}/backups/{siteId}/{filename}": {
            "get": {
                "operationId": "portalBackupDownload",
                "summary": "Download a backup",
                "description": "Streams one backup file of one of the client's own active sites (panel host only) as an attachment.\n\n- Content-Type is always application/gzip, also for uncompressed .sql files.",
                "tags": [
                    "Public"
                ],
                "parameters": [
                    {
                        "name": "token",
                        "in": "path",
                        "required": true,
                        "description": "The client's portal token. (at least 24 chars)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "siteId",
                        "in": "path",
                        "required": true,
                        "description": "Id of one of the client's sites (from the backups list).",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "filename",
                        "in": "path",
                        "required": true,
                        "description": "Backup file name (from the backups list). (pattern ^[\\w.\\-]+\\.sql(\\.gz)?$)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The file bytes with Content-Disposition: attachment; filename=\"<filename>\" and Content-Length.",
                        "content": {
                            "application/gzip": {
                                "schema": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "filename does not match the backup pattern. — \"Invalid filename\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid filename"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Token invalid, the site is not one of the client's active sites, the site is on a remote server, or the file does not exist. — \"Not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "token-in-path",
                "x-roles": [],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": []
            }
        },
        "/api/portal/{token}/support": {
            "post": {
                "operationId": "portalSupport",
                "summary": "Send a support request",
                "description": "Lets a client send a support message from the portal. It is stored as an in-panel notification (type support) for the operator.\n\n**Rate limit:** 5 per hour per IP.\n\n- A failure to store the notification is swallowed; the response is still {\"ok\": true}.\n\n- The notification title is \"Support request — <client name>\".",
                "tags": [
                    "Public"
                ],
                "parameters": [
                    {
                        "name": "token",
                        "in": "path",
                        "required": true,
                        "description": "The client's portal token. (at least 24 chars)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The request was accepted.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Token invalid, client archived, or no active billing. — \"Not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Not found"
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Too many requests — see the Retry-After header. — \"Rate limit exceeded, retry in …\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Rate limit exceeded, retry in …"
                                }
                            }
                        }
                    }
                },
                "x-auth": "token-in-path",
                "x-roles": [],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": [],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "subject": {
                                        "type": "string",
                                        "description": "Optional subject, prepended to the message. (max 200 chars)"
                                    },
                                    "message": {
                                        "type": "string",
                                        "description": "The request text. (1–2000 chars)"
                                    }
                                },
                                "required": [
                                    "message"
                                ]
                            },
                            "example": {
                                "subject": "Checkout page is slow",
                                "message": "Since this morning the checkout takes about 10 seconds to load."
                            }
                        }
                    }
                }
            }
        },
        "/api/presets": {
            "get": {
                "operationId": "presetsList",
                "summary": "List presets",
                "description": "Lists all site presets (reusable bundles of deploy settings), sorted by name.\n\n**Roles:** admin, developer.\n\n- Viewers cannot read presets (they contain deploy hook scripts).\n\n- config is the parsed and re-validated JSON; a stored config that no longer validates is returned as {}.",
                "tags": [
                    "Presets"
                ],
                "responses": {
                    "200": {
                        "description": "All presets.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "presets": [
                                        {
                                            "id": 3,
                                            "name": "Laravel production",
                                            "description": "Optimize after deploy, health check, tests",
                                            "config": {
                                                "postDeploy": "php artisan optimize",
                                                "healthCheck": true,
                                                "healthCheckUrl": "https://{{domain}}/up",
                                                "runTests": true,
                                                "testCommand": "php artisan test",
                                                "testFailureMode": "block",
                                                "tags": [
                                                    "production"
                                                ]
                                            },
                                            "createdById": 1,
                                            "createdAt": "2026-11-20T09:30:00.000Z",
                                            "updatedAt": "2026-11-27T10:00:00.000Z"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is a viewer (only admin and developer may call this). — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "presetsCreate",
                "summary": "Create a preset",
                "description": "Creates a named preset from an explicit settings object.\n\n**Roles:** admin.\n\n- config may only contain: preDeploy (string ≤ 4096), postDeploy (string ≤ 4096), healthCheck (boolean), healthCheckUrl (string ≤ 500; \"{{domain}}\" is replaced by the target site's domain when applied), runTests (boolean), testCommand (non-empty string ≤ 500), testFailureMode (\"block\" | \"warn\"), testTimeout (integer 10–3600), testUseSqlite (boolean), tags (array of ≤ 10 strings of 1–50 chars; trimmed and de-duplicated), uptimeMonitor (boolean). Unknown keys inside config are rejected with 400 (not dropped), and config must contain at least one setting.",
                "tags": [
                    "Presets"
                ],
                "responses": {
                    "201": {
                        "description": "The created preset.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 3,
                                    "name": "Laravel production",
                                    "description": "Optimize after deploy, health check, tests",
                                    "config": {
                                        "postDeploy": "php artisan optimize",
                                        "healthCheck": true,
                                        "healthCheckUrl": "https://{{domain}}/up",
                                        "runTests": true,
                                        "testCommand": "php artisan test",
                                        "testFailureMode": "block",
                                        "tags": [
                                            "production"
                                        ]
                                    },
                                    "createdById": 1,
                                    "createdAt": "2026-11-20T09:30:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "config fails validation, e.g. \"Invalid preset: Unknown preset field: domain\", \"Invalid preset: testTimeout must be a whole number between 10 and 3600\", \"Invalid preset: A preset must contain at least one setting\". — \"Invalid preset: <reason>\"\n\nname is only whitespace. — \"Preset name is required\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid preset: <reason>"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "Another preset has this name. — \"A preset with this name already exists.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "A preset with this name already exists."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Unique preset name (trimmed). (1–80 chars)"
                                    },
                                    "description": {
                                        "type": "string",
                                        "description": "Description (trimmed; empty → null). (max 500 chars)"
                                    },
                                    "config": {
                                        "type": "object",
                                        "description": "The settings the preset applies. See notes for the allowed keys. (object; whitelisted keys only, at least one)"
                                    }
                                },
                                "required": [
                                    "name",
                                    "config"
                                ]
                            },
                            "example": {
                                "name": "Laravel production",
                                "description": "Optimize after deploy, health check, tests",
                                "config": {
                                    "postDeploy": "php artisan optimize",
                                    "healthCheck": true,
                                    "healthCheckUrl": "https://{{domain}}/up",
                                    "runTests": true,
                                    "testFailureMode": "block"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/api/presets/from-site/{id}": {
            "post": {
                "operationId": "presetsCreateFromSite",
                "summary": "Create a preset from a site",
                "description": "Creates a preset from a site's current deploy settings (all preset fields, or the chosen subset). The site's own domain inside healthCheckUrl is stored as the {{domain}} placeholder.\n\n**Roles:** admin.\n\n- Mounted under /api/presets, so the site-access check does not run (admins have access to every site anyway).\n\n- Empty values are captured as they are (e.g. preDeploy \"\" when the site has no hook); an empty testCommand is left out.",
                "tags": [
                    "Presets"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "201": {
                        "description": "The created preset.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 4,
                                    "name": "Shop defaults",
                                    "description": null,
                                    "config": {
                                        "postDeploy": "php artisan optimize",
                                        "healthCheck": true,
                                        "healthCheckUrl": "https://{{domain}}/up"
                                    },
                                    "createdById": 1,
                                    "createdAt": "2026-11-20T09:30:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "config fails validation, e.g. \"Invalid preset: Unknown preset field: domain\", \"Invalid preset: testTimeout must be a whole number between 10 and 3600\", \"Invalid preset: A preset must contain at least one setting\". — \"Invalid preset: <reason>\"\n\nname is only whitespace. — \"Preset name is required\"\n\nfields contains a name that is not a preset field. — \"Unknown preset field: <field>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid preset: <reason>"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "Another preset has this name. — \"A preset with this name already exists.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "A preset with this name already exists."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Unique preset name (trimmed). (1–80 chars)"
                                    },
                                    "description": {
                                        "type": "string",
                                        "description": "Description. (max 500 chars)"
                                    },
                                    "fields": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Preset fields to capture; default all. (max 20 items; each one of: preDeploy, postDeploy, healthCheck, healthCheckUrl, runTests, testCommand, testFailureMode, testTimeout, testUseSqlite, tags, uptimeMonitor)"
                                    }
                                },
                                "required": [
                                    "name"
                                ]
                            },
                            "example": {
                                "name": "Shop defaults",
                                "fields": [
                                    "postDeploy",
                                    "healthCheck",
                                    "healthCheckUrl"
                                ]
                            }
                        }
                    }
                }
            }
        },
        "/api/presets/{presetId}": {
            "get": {
                "operationId": "presetsGet",
                "summary": "Get a preset",
                "description": "Returns one preset.\n\n**Roles:** admin, developer.",
                "tags": [
                    "Presets"
                ],
                "parameters": [
                    {
                        "name": "presetId",
                        "in": "path",
                        "required": true,
                        "description": "Preset id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The preset.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 3,
                                    "name": "Laravel production",
                                    "description": "Optimize after deploy, health check, tests",
                                    "config": {
                                        "postDeploy": "php artisan optimize",
                                        "healthCheck": true,
                                        "healthCheckUrl": "https://{{domain}}/up",
                                        "runTests": true,
                                        "testCommand": "php artisan test",
                                        "testFailureMode": "block",
                                        "tags": [
                                            "production"
                                        ]
                                    },
                                    "createdById": 1,
                                    "createdAt": "2026-11-20T09:30:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is a viewer (only admin and developer may call this). — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No preset with this id. — \"Preset not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Preset not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "patch": {
                "operationId": "presetsUpdate",
                "summary": "Update a preset",
                "description": "Renames a preset, changes its description, or replaces its whole config. Sites the preset was applied to are not changed.\n\n**Roles:** admin.\n\n- config may only contain: preDeploy (string ≤ 4096), postDeploy (string ≤ 4096), healthCheck (boolean), healthCheckUrl (string ≤ 500; \"{{domain}}\" is replaced by the target site's domain when applied), runTests (boolean), testCommand (non-empty string ≤ 500), testFailureMode (\"block\" | \"warn\"), testTimeout (integer 10–3600), testUseSqlite (boolean), tags (array of ≤ 10 strings of 1–50 chars; trimmed and de-duplicated), uptimeMonitor (boolean). Unknown keys inside config are rejected with 400 (not dropped), and config must contain at least one setting.",
                "tags": [
                    "Presets"
                ],
                "parameters": [
                    {
                        "name": "presetId",
                        "in": "path",
                        "required": true,
                        "description": "Preset id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The updated preset.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 3,
                                    "name": "Laravel production",
                                    "description": "Optimize after deploy, health check, tests",
                                    "config": {
                                        "postDeploy": "php artisan optimize",
                                        "healthCheck": true,
                                        "healthCheckUrl": "https://{{domain}}/up",
                                        "runTests": true,
                                        "testCommand": "php artisan test",
                                        "testFailureMode": "block",
                                        "tags": [
                                            "production"
                                        ]
                                    },
                                    "createdById": 1,
                                    "createdAt": "2026-11-20T09:30:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "config fails validation, e.g. \"Invalid preset: Unknown preset field: domain\", \"Invalid preset: testTimeout must be a whole number between 10 and 3600\", \"Invalid preset: A preset must contain at least one setting\". — \"Invalid preset: <reason>\"\n\nname is only whitespace. — \"Preset name is required\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid preset: <reason>"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No preset with this id. — \"Preset not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Preset not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "Another preset has this name. — \"A preset with this name already exists.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "A preset with this name already exists."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "New name (trimmed). (1–80 chars)"
                                    },
                                    "description": {
                                        "type": "string",
                                        "description": "New description; empty string clears it. (max 500 chars)"
                                    },
                                    "config": {
                                        "type": "object",
                                        "description": "Replaces the full config (not merged). (same rules as on create)"
                                    }
                                }
                            },
                            "example": {
                                "description": "Optimize after deploy + health check",
                                "config": {
                                    "postDeploy": "php artisan optimize",
                                    "healthCheck": true
                                }
                            }
                        }
                    }
                }
            },
            "delete": {
                "operationId": "presetsDelete",
                "summary": "Delete a preset",
                "description": "Deletes a preset. Sites that had it applied keep their settings.\n\n**Roles:** admin.",
                "tags": [
                    "Presets"
                ],
                "parameters": [
                    {
                        "name": "presetId",
                        "in": "path",
                        "required": true,
                        "description": "Preset id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Deleted.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No preset with this id. — \"Preset not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Preset not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/public/status/{token}": {
            "get": {
                "operationId": "publicStatus",
                "summary": "Get a public status page",
                "description": "Unauthenticated status-page data for one site, found by its status page token (the page must be enabled). Covers the last 90 days of uptime checks: current state, overall uptime %, average response time, per-day uptime and the last 10 incidents.\n\n- current is the status of the latest check, or \"unknown\" when there are no checks. overallPct and avgMs are null without data.\n\n- Incidents are runs of consecutive non-up checks; from/to are the first and last failing check times. Newest first, max 10.\n\n- Only the global rate limit (600 requests per minute per IP) applies.",
                "tags": [
                    "Public"
                ],
                "parameters": [
                    {
                        "name": "token",
                        "in": "path",
                        "required": true,
                        "description": "The site's status page token. (at least 8 chars)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Public status data.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "domain": "shop.example.com",
                                    "name": "Shop",
                                    "current": "up",
                                    "overallPct": 99.8,
                                    "avgMs": 184,
                                    "days": [
                                        {
                                            "date": "2026-11-26",
                                            "upPct": 100
                                        },
                                        {
                                            "date": "2026-11-27",
                                            "upPct": 99.3
                                        }
                                    ],
                                    "incidents": [
                                        {
                                            "from": "2026-11-27T03:10:00.000Z",
                                            "to": "2026-11-27T03:15:00.000Z"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "The token is shorter than 8 chars, unknown, or the site's status page is disabled. — \"Not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "token-in-path",
                "x-roles": [],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": []
            }
        },
        "/api/server/actions": {
            "post": {
                "operationId": "digitaloceanAction",
                "summary": "Run a droplet action",
                "description": "Starts a parameterless DigitalOcean droplet action (power, IPv6, backups toggle, root password reset) on the selected droplet. DigitalOcean executes it asynchronously; poll GET /api/server/actions/{id}.\n\n**Roles:** admin.\n\n- The audit action is \"server.\" + type, e.g. server.reboot, server.power_off.\n\n- power_off, shutdown and power_cycle really stop the production droplet.\n\n- The body is the DigitalOcean API v2 object passed through unchanged; only a few fields are shown in the example.",
                "tags": [
                    "DigitalOcean"
                ],
                "responses": {
                    "200": {
                        "description": "The DigitalOcean action object.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 2087263451,
                                    "status": "in-progress",
                                    "type": "reboot",
                                    "started_at": "2026-11-27T10:00:00.000Z",
                                    "completed_at": null,
                                    "resource_id": 412345678,
                                    "resource_type": "droplet",
                                    "region_slug": "fra1"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The do_api_token setting is empty. — \"DigitalOcean API token not configured. Add it in Settings → DigitalOcean.\"\n\nThe do_droplet_id setting is empty. — \"No droplet selected. Pick one in Settings first.\"\n\ntype is not one of the allowed actions. — \"Unsupported action: <type>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "DigitalOcean API token not configured. Add it in Settings → DigitalOcean."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The DigitalOcean API failed: its own HTTP status (400–599) and message are passed through (\"DigitalOcean API error (HTTP <status>)\" when it sent none); network errors → 502 with the error text. — \"<DigitalOcean error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<DigitalOcean error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "type": {
                                        "type": "string",
                                        "description": "Droplet action type. (one of: reboot, power_cycle, power_off, power_on, shutdown, enable_ipv6, enable_backups, disable_backups, password_reset (checked in code))"
                                    }
                                },
                                "required": [
                                    "type"
                                ]
                            },
                            "example": {
                                "type": "reboot"
                            }
                        }
                    }
                }
            },
            "get": {
                "operationId": "digitaloceanActions",
                "summary": "List droplet actions",
                "description": "Returns the 30 most recent actions of the selected droplet. Answers an empty array when no droplet is selected.\n\n**Roles:** admin.\n\n- The body is the DigitalOcean API v2 object passed through unchanged; only a few fields are shown in the example.",
                "tags": [
                    "DigitalOcean"
                ],
                "responses": {
                    "200": {
                        "description": "Array of DigitalOcean action objects.",
                        "content": {
                            "application/json": {
                                "example": [
                                    {
                                        "id": 2087263451,
                                        "status": "completed",
                                        "type": "reboot",
                                        "started_at": "2026-11-27T10:00:00.000Z",
                                        "completed_at": "2026-11-27T10:00:40.000Z",
                                        "resource_id": 412345678,
                                        "resource_type": "droplet",
                                        "region_slug": "fra1"
                                    }
                                ]
                            }
                        }
                    },
                    "400": {
                        "description": "The do_api_token setting is empty. — \"DigitalOcean API token not configured. Add it in Settings → DigitalOcean.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "DigitalOcean API token not configured. Add it in Settings → DigitalOcean."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The DigitalOcean API failed: its own HTTP status (400–599) and message are passed through (\"DigitalOcean API error (HTTP <status>)\" when it sent none); network errors → 502 with the error text. — \"<DigitalOcean error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<DigitalOcean error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/server/actions/{id}": {
            "get": {
                "operationId": "digitaloceanActionGet",
                "summary": "Get a droplet action",
                "description": "Returns one DigitalOcean action by id, to poll long operations such as resize or snapshot.\n\n**Roles:** admin.\n\n- Any action of the account can be read (it is not checked against the selected droplet).\n\n- The body is the DigitalOcean API v2 object passed through unchanged; only a few fields are shown in the example.",
                "tags": [
                    "DigitalOcean"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "DigitalOcean action id. (not validated)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The DigitalOcean action object.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 2087263451,
                                    "status": "completed",
                                    "type": "reboot",
                                    "started_at": "2026-11-27T10:00:00.000Z",
                                    "completed_at": "2026-11-27T10:00:40.000Z",
                                    "resource_id": 412345678,
                                    "resource_type": "droplet",
                                    "region_slug": "fra1"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The do_api_token setting is empty. — \"DigitalOcean API token not configured. Add it in Settings → DigitalOcean.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "DigitalOcean API token not configured. Add it in Settings → DigitalOcean."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The DigitalOcean API failed: its own HTTP status (400–599) and message are passed through (\"DigitalOcean API error (HTTP <status>)\" when it sent none); network errors → 502 with the error text. — \"<DigitalOcean error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<DigitalOcean error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/server/backups": {
            "get": {
                "operationId": "digitaloceanBackups",
                "summary": "List droplet backups",
                "description": "Lists up to 100 automatic backups of the selected droplet (read-only; enable or disable backups with POST /api/server/actions). Answers an empty array when no droplet is selected.\n\n**Roles:** admin.\n\n- The body is the DigitalOcean API v2 object passed through unchanged; only a few fields are shown in the example.",
                "tags": [
                    "DigitalOcean"
                ],
                "responses": {
                    "200": {
                        "description": "Array of DigitalOcean backup objects.",
                        "content": {
                            "application/json": {
                                "example": [
                                    {
                                        "id": 168204600,
                                        "name": "shop-prod 2026-11-26",
                                        "regions": [
                                            "fra1"
                                        ],
                                        "created_at": "2026-11-27T10:00:00.000Z",
                                        "min_disk_size": 80,
                                        "size_gigabytes": 11.9,
                                        "type": "backup"
                                    }
                                ]
                            }
                        }
                    },
                    "400": {
                        "description": "The do_api_token setting is empty. — \"DigitalOcean API token not configured. Add it in Settings → DigitalOcean.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "DigitalOcean API token not configured. Add it in Settings → DigitalOcean."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The DigitalOcean API failed: its own HTTP status (400–599) and message are passed through (\"DigitalOcean API error (HTTP <status>)\" when it sent none); network errors → 502 with the error text. — \"<DigitalOcean error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<DigitalOcean error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/server/droplets": {
            "get": {
                "operationId": "digitaloceanDroplets",
                "summary": "List droplets",
                "description": "Lists the droplets of the DigitalOcean account (first 200), used to pick the droplet the panel controls.\n\n**Roles:** admin.\n\n- The body is the DigitalOcean API v2 object passed through unchanged; only a few fields are shown in the example.\n\n- Only one page of up to 200 droplets is fetched.",
                "tags": [
                    "DigitalOcean"
                ],
                "responses": {
                    "200": {
                        "description": "Array of DigitalOcean droplet objects.",
                        "content": {
                            "application/json": {
                                "example": [
                                    {
                                        "id": 412345678,
                                        "name": "shop-prod",
                                        "memory": 4096,
                                        "vcpus": 2,
                                        "disk": 80,
                                        "status": "active",
                                        "created_at": "2026-11-27T10:00:00.000Z",
                                        "size_slug": "s-2vcpu-4gb",
                                        "region": {
                                            "slug": "fra1",
                                            "name": "Frankfurt 1"
                                        },
                                        "networks": {
                                            "v4": [
                                                {
                                                    "ip_address": "203.0.113.10",
                                                    "type": "public"
                                                }
                                            ]
                                        }
                                    }
                                ]
                            }
                        }
                    },
                    "400": {
                        "description": "The do_api_token setting is empty. — \"DigitalOcean API token not configured. Add it in Settings → DigitalOcean.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "DigitalOcean API token not configured. Add it in Settings → DigitalOcean."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The DigitalOcean API failed: its own HTTP status (400–599) and message are passed through (\"DigitalOcean API error (HTTP <status>)\" when it sent none); network errors → 502 with the error text. — \"<DigitalOcean error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<DigitalOcean error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/server/firewalls": {
            "get": {
                "operationId": "digitaloceanFirewalls",
                "summary": "List droplet firewalls",
                "description": "Lists the DigitalOcean cloud firewalls (first 100 of the account) that are attached to the selected droplet. Answers an empty array when no droplet is selected.\n\n**Roles:** admin.\n\n- The body is the DigitalOcean API v2 object passed through unchanged; only a few fields are shown in the example.",
                "tags": [
                    "DigitalOcean"
                ],
                "responses": {
                    "200": {
                        "description": "Array of DigitalOcean firewall objects.",
                        "content": {
                            "application/json": {
                                "example": [
                                    {
                                        "id": "bb4b2611-3d72-467b-8602-280330ecd65c",
                                        "name": "web",
                                        "status": "succeeded",
                                        "inbound_rules": [
                                            {
                                                "protocol": "tcp",
                                                "ports": "443",
                                                "sources": {
                                                    "addresses": [
                                                        "0.0.0.0/0",
                                                        "::/0"
                                                    ]
                                                }
                                            }
                                        ],
                                        "outbound_rules": [
                                            {
                                                "protocol": "tcp",
                                                "ports": "all",
                                                "destinations": {
                                                    "addresses": [
                                                        "0.0.0.0/0",
                                                        "::/0"
                                                    ]
                                                }
                                            }
                                        ],
                                        "droplet_ids": [
                                            412345678
                                        ],
                                        "created_at": "2026-11-27T10:00:00.000Z"
                                    }
                                ]
                            }
                        }
                    },
                    "400": {
                        "description": "The do_api_token setting is empty. — \"DigitalOcean API token not configured. Add it in Settings → DigitalOcean.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "DigitalOcean API token not configured. Add it in Settings → DigitalOcean."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The DigitalOcean API failed: its own HTTP status (400–599) and message are passed through (\"DigitalOcean API error (HTTP <status>)\" when it sent none); network errors → 502 with the error text. — \"<DigitalOcean error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<DigitalOcean error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/server/firewalls/{id}/rules": {
            "post": {
                "operationId": "digitaloceanFirewallRulesAdd",
                "summary": "Add firewall rules",
                "description": "Adds inbound and/or outbound rules to a DigitalOcean cloud firewall. The body is forwarded to DigitalOcean unchanged.\n\n**Roles:** admin.\n\n- Any firewall of the account can be changed (it is not checked against the selected droplet).\n\n- Rule objects are validated by DigitalOcean only.",
                "tags": [
                    "DigitalOcean"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "DigitalOcean firewall id (UUID). (not validated)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Rules added.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The do_api_token setting is empty. — \"DigitalOcean API token not configured. Add it in Settings → DigitalOcean.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "DigitalOcean API token not configured. Add it in Settings → DigitalOcean."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The DigitalOcean API failed: its own HTTP status (400–599) and message are passed through (\"DigitalOcean API error (HTTP <status>)\" when it sent none); network errors → 502 with the error text. — \"<DigitalOcean error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<DigitalOcean error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "inbound_rules": {
                                        "type": "array",
                                        "items": {},
                                        "description": "DigitalOcean inbound rule objects (protocol, ports, sources), passed to DigitalOcean unchanged. (array; items not validated)"
                                    },
                                    "outbound_rules": {
                                        "type": "array",
                                        "items": {},
                                        "description": "DigitalOcean outbound rule objects (protocol, ports, destinations), passed to DigitalOcean unchanged. (array; items not validated)"
                                    }
                                }
                            },
                            "example": {
                                "inbound_rules": [
                                    {
                                        "protocol": "tcp",
                                        "ports": "8080",
                                        "sources": {
                                            "addresses": [
                                                "198.51.100.0/24"
                                            ]
                                        }
                                    }
                                ]
                            }
                        }
                    }
                }
            },
            "delete": {
                "operationId": "digitaloceanFirewallRulesRemove",
                "summary": "Remove firewall rules",
                "description": "Removes the given inbound and/or outbound rules from a DigitalOcean cloud firewall. Takes a JSON body (the rules to remove), forwarded to DigitalOcean unchanged.\n\n**Roles:** admin.\n\n- This DELETE request carries a JSON body.\n\n- Any firewall of the account can be changed (it is not checked against the selected droplet).",
                "tags": [
                    "DigitalOcean"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "DigitalOcean firewall id (UUID). (not validated)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Rules removed.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The do_api_token setting is empty. — \"DigitalOcean API token not configured. Add it in Settings → DigitalOcean.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "DigitalOcean API token not configured. Add it in Settings → DigitalOcean."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The DigitalOcean API failed: its own HTTP status (400–599) and message are passed through (\"DigitalOcean API error (HTTP <status>)\" when it sent none); network errors → 502 with the error text. — \"<DigitalOcean error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<DigitalOcean error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "inbound_rules": {
                                        "type": "array",
                                        "items": {},
                                        "description": "DigitalOcean inbound rule objects (protocol, ports, sources), passed to DigitalOcean unchanged. (array; items not validated)"
                                    },
                                    "outbound_rules": {
                                        "type": "array",
                                        "items": {},
                                        "description": "DigitalOcean outbound rule objects (protocol, ports, destinations), passed to DigitalOcean unchanged. (array; items not validated)"
                                    }
                                }
                            },
                            "example": {
                                "inbound_rules": [
                                    {
                                        "protocol": "tcp",
                                        "ports": "8080",
                                        "sources": {
                                            "addresses": [
                                                "198.51.100.0/24"
                                            ]
                                        }
                                    }
                                ]
                            }
                        }
                    }
                }
            }
        },
        "/api/server/rename": {
            "patch": {
                "operationId": "digitaloceanRename",
                "summary": "Rename the droplet",
                "description": "Renames the selected droplet at DigitalOcean.\n\n**Roles:** admin.\n\n- The body is the DigitalOcean API v2 object passed through unchanged; only a few fields are shown in the example.",
                "tags": [
                    "DigitalOcean"
                ],
                "responses": {
                    "200": {
                        "description": "The DigitalOcean action object.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 2087263451,
                                    "status": "in-progress",
                                    "type": "rename",
                                    "started_at": "2026-11-27T10:00:00.000Z",
                                    "completed_at": null,
                                    "resource_id": 412345678,
                                    "resource_type": "droplet",
                                    "region_slug": "fra1"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The do_api_token setting is empty. — \"DigitalOcean API token not configured. Add it in Settings → DigitalOcean.\"\n\nThe do_droplet_id setting is empty. — \"No droplet selected.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "DigitalOcean API token not configured. Add it in Settings → DigitalOcean."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The DigitalOcean API failed: its own HTTP status (400–599) and message are passed through (\"DigitalOcean API error (HTTP <status>)\" when it sent none); network errors → 502 with the error text. — \"<DigitalOcean error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<DigitalOcean error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "New droplet name. (1–255 chars)"
                                    }
                                },
                                "required": [
                                    "name"
                                ]
                            },
                            "example": {
                                "name": "shop-prod-fra1"
                            }
                        }
                    }
                }
            }
        },
        "/api/server/resize": {
            "post": {
                "operationId": "digitaloceanResize",
                "summary": "Resize the droplet",
                "description": "Starts a resize of the selected droplet to another size; with disk:true the disk is resized too. DigitalOcean requires the droplet to be powered off and reports its own error otherwise.\n\n**Roles:** admin.\n\n- The body is the DigitalOcean API v2 object passed through unchanged; only a few fields are shown in the example.",
                "tags": [
                    "DigitalOcean"
                ],
                "responses": {
                    "200": {
                        "description": "The DigitalOcean action object.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 2087263451,
                                    "status": "in-progress",
                                    "type": "resize",
                                    "started_at": "2026-11-27T10:00:00.000Z",
                                    "completed_at": null,
                                    "resource_id": 412345678,
                                    "resource_type": "droplet",
                                    "region_slug": "fra1"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The do_api_token setting is empty. — \"DigitalOcean API token not configured. Add it in Settings → DigitalOcean.\"\n\nThe do_droplet_id setting is empty. — \"No droplet selected.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "DigitalOcean API token not configured. Add it in Settings → DigitalOcean."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The DigitalOcean API failed: its own HTTP status (400–599) and message are passed through (\"DigitalOcean API error (HTTP <status>)\" when it sent none); network errors → 502 with the error text. — \"<DigitalOcean error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<DigitalOcean error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "size": {
                                        "type": "string",
                                        "description": "Target size slug (see GET /api/server/sizes). (not validated by the panel)"
                                    },
                                    "disk": {
                                        "type": "boolean",
                                        "description": "Also resize the disk. (default false)"
                                    }
                                },
                                "required": [
                                    "size"
                                ]
                            },
                            "example": {
                                "size": "s-4vcpu-8gb",
                                "disk": false
                            }
                        }
                    }
                }
            }
        },
        "/api/server/sizes": {
            "get": {
                "operationId": "digitaloceanSizes",
                "summary": "List droplet sizes",
                "description": "Lists the DigitalOcean sizes that are currently available, for the resize picker.\n\n**Roles:** admin.\n\n- The body is the DigitalOcean API v2 object passed through unchanged; only a few fields are shown in the example.",
                "tags": [
                    "DigitalOcean"
                ],
                "responses": {
                    "200": {
                        "description": "Array of DigitalOcean size objects with available:true.",
                        "content": {
                            "application/json": {
                                "example": [
                                    {
                                        "slug": "s-2vcpu-4gb",
                                        "memory": 4096,
                                        "vcpus": 2,
                                        "disk": 80,
                                        "transfer": 4,
                                        "price_monthly": 24,
                                        "price_hourly": 0.03571,
                                        "regions": [
                                            "fra1",
                                            "ams3"
                                        ],
                                        "available": true,
                                        "description": "Basic"
                                    }
                                ]
                            }
                        }
                    },
                    "400": {
                        "description": "The do_api_token setting is empty. — \"DigitalOcean API token not configured. Add it in Settings → DigitalOcean.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "DigitalOcean API token not configured. Add it in Settings → DigitalOcean."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The DigitalOcean API failed: its own HTTP status (400–599) and message are passed through (\"DigitalOcean API error (HTTP <status>)\" when it sent none); network errors → 502 with the error text. — \"<DigitalOcean error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<DigitalOcean error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/server/snapshots": {
            "get": {
                "operationId": "digitaloceanSnapshots",
                "summary": "List droplet snapshots",
                "description": "Lists up to 100 snapshots of the selected droplet. Answers an empty array when no droplet is selected.\n\n**Roles:** admin.\n\n- The body is the DigitalOcean API v2 object passed through unchanged; only a few fields are shown in the example.",
                "tags": [
                    "DigitalOcean"
                ],
                "responses": {
                    "200": {
                        "description": "Array of DigitalOcean snapshot objects.",
                        "content": {
                            "application/json": {
                                "example": [
                                    {
                                        "id": 168204513,
                                        "name": "before-upgrade",
                                        "regions": [
                                            "fra1"
                                        ],
                                        "created_at": "2026-11-27T10:00:00.000Z",
                                        "resource_id": "412345678",
                                        "resource_type": "droplet",
                                        "min_disk_size": 80,
                                        "size_gigabytes": 12.4,
                                        "type": "snapshot"
                                    }
                                ]
                            }
                        }
                    },
                    "400": {
                        "description": "The do_api_token setting is empty. — \"DigitalOcean API token not configured. Add it in Settings → DigitalOcean.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "DigitalOcean API token not configured. Add it in Settings → DigitalOcean."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The DigitalOcean API failed: its own HTTP status (400–599) and message are passed through (\"DigitalOcean API error (HTTP <status>)\" when it sent none); network errors → 502 with the error text. — \"<DigitalOcean error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<DigitalOcean error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "digitaloceanSnapshotCreate",
                "summary": "Create a droplet snapshot",
                "description": "Starts a snapshot of the selected droplet. DigitalOcean runs it asynchronously; poll the returned action.\n\n**Roles:** admin.\n\n- The body is the DigitalOcean API v2 object passed through unchanged; only a few fields are shown in the example.",
                "tags": [
                    "DigitalOcean"
                ],
                "responses": {
                    "200": {
                        "description": "The DigitalOcean action object.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 2087263451,
                                    "status": "in-progress",
                                    "type": "snapshot",
                                    "started_at": "2026-11-27T10:00:00.000Z",
                                    "completed_at": null,
                                    "resource_id": 412345678,
                                    "resource_type": "droplet",
                                    "region_slug": "fra1"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The do_api_token setting is empty. — \"DigitalOcean API token not configured. Add it in Settings → DigitalOcean.\"\n\nThe do_droplet_id setting is empty. — \"No droplet selected.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "DigitalOcean API token not configured. Add it in Settings → DigitalOcean."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The DigitalOcean API failed: its own HTTP status (400–599) and message are passed through (\"DigitalOcean API error (HTTP <status>)\" when it sent none); network errors → 502 with the error text. — \"<DigitalOcean error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<DigitalOcean error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Snapshot name. (1–255 chars)"
                                    }
                                },
                                "required": [
                                    "name"
                                ]
                            },
                            "example": {
                                "name": "before-upgrade"
                            }
                        }
                    }
                }
            }
        },
        "/api/server/snapshots/{id}": {
            "delete": {
                "operationId": "digitaloceanSnapshotDelete",
                "summary": "Delete a snapshot",
                "description": "Permanently deletes a DigitalOcean snapshot.\n\n**Roles:** admin.\n\n- Any snapshot of the account can be deleted (it is not checked against the selected droplet).\n\n- Does not require a selected droplet.",
                "tags": [
                    "DigitalOcean"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "DigitalOcean snapshot id. (not validated)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Deleted.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The do_api_token setting is empty. — \"DigitalOcean API token not configured. Add it in Settings → DigitalOcean.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "DigitalOcean API token not configured. Add it in Settings → DigitalOcean."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The DigitalOcean API failed: its own HTTP status (400–599) and message are passed through (\"DigitalOcean API error (HTTP <status>)\" when it sent none); network errors → 502 with the error text. — \"<DigitalOcean error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<DigitalOcean error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/server/status": {
            "get": {
                "operationId": "digitaloceanStatus",
                "summary": "Get droplet status",
                "description": "Tells whether DigitalOcean is configured and returns the selected droplet. Without a token it answers configured:false; with a token but no droplet id it asks for a droplet to be selected.\n\n**Roles:** admin.\n\n- The body is the DigitalOcean API v2 object passed through unchanged; only a few fields are shown in the example.\n\n- Credentials come from the settings do_api_token (encrypted) and do_droplet_id.",
                "tags": [
                    "DigitalOcean"
                ],
                "responses": {
                    "200": {
                        "description": "Configuration state and the droplet object (or null).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "configured": true,
                                    "droplet": {
                                        "id": 412345678,
                                        "name": "shop-prod",
                                        "memory": 4096,
                                        "vcpus": 2,
                                        "disk": 80,
                                        "status": "active",
                                        "created_at": "2026-11-27T10:00:00.000Z",
                                        "size_slug": "s-2vcpu-4gb",
                                        "region": {
                                            "slug": "fra1",
                                            "name": "Frankfurt 1"
                                        },
                                        "networks": {
                                            "v4": [
                                                {
                                                    "ip_address": "203.0.113.10",
                                                    "type": "public"
                                                }
                                            ]
                                        }
                                    },
                                    "needsDropletSelection": false
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The DigitalOcean API failed: its own HTTP status (400–599) and message are passed through (\"DigitalOcean API error (HTTP <status>)\" when it sent none); network errors → 502 with the error text. — \"<DigitalOcean error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<DigitalOcean error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/servers": {
            "get": {
                "operationId": "serversList",
                "summary": "List servers",
                "description": "Lists every managed server (the panel host first, then remote servers by creation date) with the number of sites each one hosts. Private keys are never returned.\n\n**Roles:** admin.\n\n- Sites with serverId null are counted on the local (panel host) row.\n\n- For fleet data (agent status, metrics, permissions) use GET /api/fleet/servers.",
                "tags": [
                    "Servers"
                ],
                "responses": {
                    "200": {
                        "description": "All servers.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "servers": [
                                        {
                                            "id": 1,
                                            "name": "Panel host",
                                            "kind": "local",
                                            "host": null,
                                            "port": 22,
                                            "sshUser": "root",
                                            "hasKey": false,
                                            "sshKeyFingerprint": null,
                                            "status": "online",
                                            "lastSeenAt": "2026-11-27T10:00:00.000Z",
                                            "scriptsSynced": true,
                                            "notes": null,
                                            "createdAt": "2026-11-27T10:00:00.000Z",
                                            "monthlyCostMinor": 0,
                                            "costCurrency": "GEL",
                                            "siteCount": 8
                                        },
                                        {
                                            "id": 12,
                                            "name": "web-1",
                                            "kind": "remote",
                                            "host": "web1.example.com",
                                            "port": 22,
                                            "sshUser": "root",
                                            "hasKey": true,
                                            "sshKeyFingerprint": "9f2c4a1be07d3c55",
                                            "status": "online",
                                            "lastSeenAt": "2026-11-27T10:00:00.000Z",
                                            "scriptsSynced": true,
                                            "notes": null,
                                            "createdAt": "2026-11-27T10:00:00.000Z",
                                            "monthlyCostMinor": 4500,
                                            "costCurrency": "GEL",
                                            "siteCount": 3
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "serversCreate",
                "summary": "Add an SSH server",
                "description": "Registers a remote server reachable over SSH. The private key is encrypted at rest and only a 16-character sha256 checksum is kept for display. Nothing is installed on the server; use POST /api/servers/{id}/prepare for that.\n\n**Roles:** admin.\n\n- The connection is not tested on create; call POST /api/servers/test-connection first or POST /api/servers/{id}/test afterwards.\n\n- siteCount is always 0 in this response.\n\n- Unlike POST /api/fleet/servers this route has no personal-access-token restriction: an admin token can call it.",
                "tags": [
                    "Servers"
                ],
                "responses": {
                    "201": {
                        "description": "The created server.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 12,
                                    "name": "web-1",
                                    "kind": "remote",
                                    "host": "web1.example.com",
                                    "port": 22,
                                    "sshUser": "root",
                                    "hasKey": true,
                                    "sshKeyFingerprint": "9f2c4a1be07d3c55",
                                    "status": "unknown",
                                    "lastSeenAt": null,
                                    "scriptsSynced": false,
                                    "notes": null,
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "monthlyCostMinor": 4500,
                                    "costCurrency": "GEL",
                                    "siteCount": 0
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Display name. (1–100 chars)"
                                    },
                                    "host": {
                                        "type": "string",
                                        "description": "Hostname or IP address for SSH. (1–255 chars)"
                                    },
                                    "port": {
                                        "type": "integer",
                                        "description": "SSH port. (1–65535, default 22)"
                                    },
                                    "sshUser": {
                                        "type": "string",
                                        "description": "SSH login user. (1–64 chars, default \"root\")"
                                    },
                                    "sshKey": {
                                        "type": "string",
                                        "description": "Private SSH key (PEM). Stored encrypted; never returned. (1–20000 chars)"
                                    },
                                    "notes": {
                                        "type": "string",
                                        "description": "Free-text notes. (max 1000 chars)"
                                    },
                                    "monthlyCostMinor": {
                                        "type": "integer",
                                        "description": "Monthly hosting cost in minor currency units (used by the server economics report). (0–100000000, default 0)"
                                    },
                                    "costCurrency": {
                                        "type": "string",
                                        "description": "ISO currency code; stored upper-cased. (exactly 3 chars, default \"GEL\")"
                                    }
                                },
                                "required": [
                                    "name",
                                    "host",
                                    "sshKey"
                                ]
                            },
                            "example": {
                                "name": "web-1",
                                "host": "web1.example.com",
                                "port": 22,
                                "sshUser": "root",
                                "sshKey": "-----BEGIN OPENSSH PRIVATE KEY-----\n…\n-----END OPENSSH PRIVATE KEY-----",
                                "notes": "Main shop server",
                                "monthlyCostMinor": 4500,
                                "costCurrency": "GEL"
                            }
                        }
                    }
                }
            }
        },
        "/api/servers/test-connection": {
            "post": {
                "operationId": "serversTestConnection",
                "summary": "Test unsaved SSH settings",
                "description": "Opens an SSH connection with the given (unsaved) settings and runs a short identity probe (uname -sr; id -un), 15-second timeout. Always answers 200: a failed connection is reported as ok:false with the error text.\n\n**Roles:** admin.\n\n- On failure the body is {\"ok\": false, \"error\": \"<stderr or message, max 300 chars>\"} (or \"Unexpected response from server\" when the marker is missing).\n\n- Not audited.",
                "tags": [
                    "Servers"
                ],
                "responses": {
                    "200": {
                        "description": "Probe result: {ok:true, info} or {ok:false, error}.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "info": "Linux 6.8.0-45-generic root"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "host": {
                                        "type": "string",
                                        "description": "Hostname or IP address. (1–255 chars)"
                                    },
                                    "port": {
                                        "type": "integer",
                                        "description": "SSH port. (1–65535, default 22)"
                                    },
                                    "sshUser": {
                                        "type": "string",
                                        "description": "SSH login user. (1–64 chars, default \"root\")"
                                    },
                                    "sshKey": {
                                        "type": "string",
                                        "description": "Private SSH key (PEM). Not stored. (1–20000 chars)"
                                    }
                                },
                                "required": [
                                    "host",
                                    "sshKey"
                                ]
                            },
                            "example": {
                                "host": "web1.example.com",
                                "port": 22,
                                "sshUser": "root",
                                "sshKey": "-----BEGIN OPENSSH PRIVATE KEY-----\n…\n-----END OPENSSH PRIVATE KEY-----"
                            }
                        }
                    }
                }
            }
        },
        "/api/servers/{id}": {
            "patch": {
                "operationId": "serversUpdate",
                "summary": "Update a server",
                "description": "Updates the given fields. For the local (panel host) row only name, notes, monthlyCostMinor and costCurrency are applied; host, port, sshUser and sshKey are silently ignored. A new sshKey resets scriptsSynced to false so the helper scripts are copied again.\n\n**Roles:** admin.\n\n- siteCount is always 0 in this response.\n\n- An empty sshKey is ignored (the key is only replaced when a non-empty value is sent).\n\n- The id is converted with Number() without validation; a non-numeric id makes the Prisma lookup throw, which surfaces as a 500 instead of a 404.",
                "tags": [
                    "Servers"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Server id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The updated server.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 12,
                                    "name": "web-1 (Frankfurt)",
                                    "kind": "remote",
                                    "host": "web1.example.com",
                                    "port": 22,
                                    "sshUser": "root",
                                    "hasKey": true,
                                    "sshKeyFingerprint": "9f2c4a1be07d3c55",
                                    "status": "online",
                                    "lastSeenAt": "2026-11-27T10:00:00.000Z",
                                    "scriptsSynced": true,
                                    "notes": "Upgraded to 4 GB",
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "monthlyCostMinor": 6000,
                                    "costCurrency": "GEL",
                                    "siteCount": 0
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No server with this id. — \"Server not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Server not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Display name. (1–100 chars)"
                                    },
                                    "host": {
                                        "type": "string",
                                        "description": "Hostname or IP address for SSH. (1–255 chars)"
                                    },
                                    "port": {
                                        "type": "integer",
                                        "description": "SSH port. (1–65535)"
                                    },
                                    "sshUser": {
                                        "type": "string",
                                        "description": "SSH login user. (1–64 chars)"
                                    },
                                    "sshKey": {
                                        "type": "string",
                                        "description": "Private SSH key (PEM). Stored encrypted; never returned. (1–20000 chars)"
                                    },
                                    "notes": {
                                        "type": "string",
                                        "description": "Free-text notes. (max 1000 chars)"
                                    },
                                    "monthlyCostMinor": {
                                        "type": "integer",
                                        "description": "Monthly hosting cost in minor currency units (used by the server economics report). (0–100000000)"
                                    },
                                    "costCurrency": {
                                        "type": "string",
                                        "description": "ISO currency code; stored upper-cased. (exactly 3 chars)"
                                    }
                                }
                            },
                            "example": {
                                "name": "web-1 (Frankfurt)",
                                "notes": "Upgraded to 4 GB",
                                "monthlyCostMinor": 6000
                            }
                        }
                    }
                }
            },
            "delete": {
                "operationId": "serversDelete",
                "summary": "Delete a server",
                "description": "Deletes a remote server. Its agent connection is dropped and in-memory fleet data is forgotten; related fleet rows (enroll tokens, traffic, alert events, run targets) are removed by cascade.\n\n**Roles:** admin.\n\n- Nothing is uninstalled on the remote machine.\n\n- The id is converted with Number() without validation; a non-numeric id makes the Prisma lookup throw, which surfaces as a 500 instead of a 404.",
                "tags": [
                    "Servers"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Server id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Deleted.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The id is the panel host (kind \"local\"). — \"The local server cannot be deleted.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "The local server cannot be deleted."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No server with this id. — \"Server not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Server not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "At least one site has this serverId. — \"Server still hosts <n> site(s). Move or remove them first.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Server still hosts <n> site(s). Move or remove them first."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/servers/{id}/health": {
            "get": {
                "operationId": "serversHealth",
                "summary": "Get live server stats",
                "description": "Reads CPU load, RAM, root disk, swap and uptime: in-process for the panel host, one SSH round-trip (15-second timeout) for a remote server. Updates status/lastSeenAt as a side effect.\n\n**Roles:** admin.\n\n- For a remote server cpu.percent is load1 / cores × 100 (capped at 100), not a measured CPU usage.\n\n- The id is converted with Number() without validation; a non-numeric id makes the Prisma lookup throw, which surfaces as a 500 instead of a 404.",
                "tags": [
                    "Servers"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Server id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Current stats (bytes; percent 0–100; uptime in seconds).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "stats": {
                                        "cpu": {
                                            "load1": 0.32,
                                            "load5": 0.28,
                                            "load15": 0.25,
                                            "cores": 2,
                                            "percent": 16
                                        },
                                        "ram": {
                                            "total": 4123000000,
                                            "used": 1610000000,
                                            "free": 812000000,
                                            "percent": 39
                                        },
                                        "disk": {
                                            "total": 80000000000,
                                            "used": 31000000000,
                                            "percent": 39
                                        },
                                        "swap": {
                                            "total": 1073741824,
                                            "used": 0,
                                            "percent": 0
                                        },
                                        "uptime": 864000,
                                        "hostname": "web-1"
                                    }
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Remote server without a host (agent-only fleet server). — \"This server has no SSH access configured.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "This server has no SSH access configured."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No server with this id. — \"Server not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Server not found"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The SSH call failed (message clipped to 300 chars, \"Failed to reach server\" when empty). The server is marked offline. — \"<stderr or error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<stderr or error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/servers/{id}/prepare": {
            "post": {
                "operationId": "serversPrepare",
                "summary": "Bootstrap a server",
                "description": "Copies the panel's helper scripts to the remote server if needed and starts bootstrap-server.sh over SSH, which installs the full LEMP stack (PHP 8.1–8.5 with extensions, nginx, MariaDB, Composer, Supervisor, Certbot, Redis). Answers at once; follow the output with GET /api/servers/{id}/prepare/stream.\n\n**Roles:** admin.\n\n- The bootstrap runs in the background without a TTY; its state lives in memory only (a panel restart loses the stream).\n\n- Can take many minutes.\n\n- The id is converted with Number() without validation; a non-numeric id makes the Prisma lookup throw, which surfaces as a 500 instead of a 404.",
                "tags": [
                    "Servers"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Server id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The bootstrap was started.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "started": true
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The id is the panel host. — \"The local server is already set up and cannot be bootstrapped from the panel.\"\n\nRemote server without a host (agent-only fleet server). — \"This server has no SSH access configured.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "The local server is already set up and cannot be bootstrapped from the panel."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No server with this id. — \"Server not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Server not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "A previous bootstrap of this server has not finished. — \"A bootstrap is already running for this server.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "A bootstrap is already running for this server."
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "Copying the helper scripts over SSH failed. — \"Could not reach the server: <error>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Could not reach the server: <error>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/servers/{id}/prepare/stream": {
            "get": {
                "operationId": "serversPrepareStream",
                "summary": "Stream bootstrap output",
                "description": "Server-Sent Events of a server bootstrap. Replays the output buffered so far as {\"line\": \"…\"} events, then streams new output, and ends with {\"done\": true, \"status\": \"success\"|\"failed\"}. When no bootstrap is running it replays any buffered output and sends {\"done\": true, \"status\": \"idle\"} immediately.\n\n**Roles:** admin.\n\n**Streams** Server-Sent Events.\n\n- Each event is \"data: <json>\\n\\n\"; keep-alive comments \": ka\" are sent every 20 s.\n\n- \"line\" events carry raw output chunks, not necessarily whole lines.\n\n- The output buffer is kept 30 minutes after the bootstrap finished.\n\n- Does not check that the server exists: an unknown id simply answers {done:true,status:\"idle\"}.\n\n- Send the token in the Authorization header (the web client uses fetch, not EventSource).",
                "tags": [
                    "Servers"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Server id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "SSE stream of {line} events ending with {done, status}.",
                        "content": {
                            "text/event-stream": {
                                "schema": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/servers/{id}/test": {
            "post": {
                "operationId": "serversTest",
                "summary": "Test a saved server",
                "description": "Runs the identity probe over the saved SSH settings (or locally for the panel host) and updates the server's status (online/offline) and lastSeenAt. A failed probe still answers 200 with ok:false.\n\n**Roles:** admin.\n\n- The id is converted with Number() without validation; a non-numeric id makes the Prisma lookup throw, which surfaces as a 500 instead of a 404.",
                "tags": [
                    "Servers"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Server id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Probe result.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "info": "Linux 6.8.0-45-generic root"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Remote server without a host (agent-only fleet server). — \"This server has no SSH access configured.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "This server has no SSH access configured."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No server with this id. — \"Server not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Server not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/settings": {
            "get": {
                "operationId": "settingsGet",
                "summary": "Get panel settings",
                "description": "Returns the panel-wide settings as a flat key/value object. Admin only. Secret settings are write-only: they come back as \"••••••••\" when set and as an empty string when empty.\n\n**Roles:** admin.\n\n- Only keys that have been saved at least once appear; unset keys are absent from the object (not null).\n\n- Accepted keys (ALLOWED_KEYS): panel_title, panel_url, notify_email, deploy_slack_webhook, deploy_discord_webhook, deploy_telegram_bot_token, deploy_telegram_chat_id, deploy_generic_webhook, s3_access_key, s3_secret_key, s3_region, s3_bucket, s3_endpoint, mysql_root_user, mysql_root_password, do_api_token, do_droplet_id, cloudflare_api_token, cloudflare_zone_id, server_public_ip.\n\n- Write-only / redacted in this response (REDACTED_KEYS): s3_secret_key, mysql_root_password, do_api_token, deploy_telegram_bot_token, cloudflare_api_token, deploy_slack_webhook, deploy_discord_webhook, deploy_generic_webhook, s3_access_key.\n\n- Encrypted at rest with AES-256-GCM (ENCRYPTED_SETTING_KEYS): mysql_root_password, s3_secret_key, do_api_token, deploy_telegram_bot_token, cloudflare_api_token. The other redacted keys (webhook URLs, s3_access_key) are stored in plaintext but never returned.\n\n- Internal settings kept in the same table (telegram_webhook_secret, weekly_digest_enabled, weekly_digest_day, weekly_digest_last) are never returned here; the digest ones are exposed through /api/digest.",
                "tags": [
                    "Settings"
                ],
                "responses": {
                    "200": {
                        "description": "Stored settings, secrets redacted.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "panel_title": "Orchestrator",
                                    "panel_url": "https://panel.example.com",
                                    "notify_email": "ops@example.com",
                                    "deploy_slack_webhook": "••••••••",
                                    "deploy_telegram_bot_token": "••••••••",
                                    "deploy_telegram_chat_id": "-1001234567890",
                                    "s3_access_key": "••••••••",
                                    "s3_secret_key": "••••••••",
                                    "s3_region": "auto",
                                    "s3_bucket": "backups",
                                    "s3_endpoint": "https://s3.example.com",
                                    "mysql_root_user": "root",
                                    "mysql_root_password": "••••••••",
                                    "server_public_ip": "203.0.113.10"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "put": {
                "operationId": "settingsUpdate",
                "summary": "Update panel settings",
                "description": "Saves one or more panel-wide settings. Admin only. Send only the keys you want to change; each is created or overwritten. Unknown keys are ignored, and the redaction placeholder \"••••••••\" sent for a secret key is ignored so an unchanged secret is never overwritten.\n\n**Roles:** admin.\n\n- There is no request schema: the body is a free-form JSON object and values must be strings. A non-string value or a missing/null body is not validated and fails with a 500 error.\n\n- An empty string is stored as-is, which clears the setting.\n\n- Write-only keys: s3_secret_key, mysql_root_password, do_api_token, deploy_telegram_bot_token, cloudflare_api_token, deploy_slack_webhook, deploy_discord_webhook, deploy_generic_webhook, s3_access_key. Of these, mysql_root_password, s3_secret_key, do_api_token, deploy_telegram_bot_token and cloudflare_api_token are encrypted at rest (AES-256-GCM).\n\n- Internal keys such as telegram_webhook_secret or weekly_digest_* cannot be written here (they are not in the allow-list and are ignored).\n\n- No audit entry is written for settings changes.",
                "tags": [
                    "Settings"
                ],
                "responses": {
                    "200": {
                        "description": "The keys that were written.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "updated": [
                                        "panel_url",
                                        "deploy_telegram_chat_id"
                                    ]
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "After dropping unknown keys and redaction placeholders, nothing is left to save. — \"No valid settings keys provided.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "No valid settings keys provided."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "panel_title": {
                                        "type": "string",
                                        "description": "Panel name shown in the UI. (not validated)"
                                    },
                                    "panel_url": {
                                        "type": "string",
                                        "description": "Public base URL of the panel (used e.g. for the Telegram webhook URL). (not validated)"
                                    },
                                    "notify_email": {
                                        "type": "string",
                                        "description": "Recipient address for email notifications (sent only when SMTP is configured on the server). (not validated)"
                                    },
                                    "deploy_slack_webhook": {
                                        "type": "string",
                                        "description": "Slack incoming-webhook URL for notifications. Write-only. (not validated)"
                                    },
                                    "deploy_discord_webhook": {
                                        "type": "string",
                                        "description": "Discord webhook URL for notifications. Write-only. (not validated)"
                                    },
                                    "deploy_telegram_bot_token": {
                                        "type": "string",
                                        "description": "Telegram bot token for notifications and the Telegram bot. Write-only, encrypted at rest. (not validated)"
                                    },
                                    "deploy_telegram_chat_id": {
                                        "type": "string",
                                        "description": "Telegram chat id that receives notifications. (not validated)"
                                    },
                                    "deploy_generic_webhook": {
                                        "type": "string",
                                        "description": "Generic webhook URL that receives notification payloads. Write-only. (not validated)"
                                    },
                                    "s3_access_key": {
                                        "type": "string",
                                        "description": "S3/R2 access key for backups. Write-only. (not validated)"
                                    },
                                    "s3_secret_key": {
                                        "type": "string",
                                        "description": "S3/R2 secret key for backups. Write-only, encrypted at rest. (not validated)"
                                    },
                                    "s3_region": {
                                        "type": "string",
                                        "description": "S3 region. (not validated)"
                                    },
                                    "s3_bucket": {
                                        "type": "string",
                                        "description": "S3 bucket name. (not validated)"
                                    },
                                    "s3_endpoint": {
                                        "type": "string",
                                        "description": "S3-compatible endpoint URL (e.g. for R2). (not validated)"
                                    },
                                    "mysql_root_user": {
                                        "type": "string",
                                        "description": "MySQL user used to create and drop site databases. (not validated)"
                                    },
                                    "mysql_root_password": {
                                        "type": "string",
                                        "description": "Password of that MySQL user. Write-only, encrypted at rest. (not validated)"
                                    },
                                    "do_api_token": {
                                        "type": "string",
                                        "description": "DigitalOcean API token (Server page, droplet control). Write-only, encrypted at rest. (not validated)"
                                    },
                                    "do_droplet_id": {
                                        "type": "string",
                                        "description": "DigitalOcean droplet id of this server. (not validated)"
                                    },
                                    "cloudflare_api_token": {
                                        "type": "string",
                                        "description": "Cloudflare API token for automatic DNS A records on provisioning. Write-only, encrypted at rest. (not validated)"
                                    },
                                    "cloudflare_zone_id": {
                                        "type": "string",
                                        "description": "Cloudflare zone id. (not validated)"
                                    },
                                    "server_public_ip": {
                                        "type": "string",
                                        "description": "Public IP address used for DNS records. (not validated)"
                                    }
                                }
                            },
                            "example": {
                                "panel_url": "https://panel.example.com",
                                "deploy_telegram_chat_id": "-1001234567890",
                                "s3_secret_key": "••••••••"
                            }
                        }
                    }
                }
            }
        },
        "/api/settings/change-password": {
            "post": {
                "operationId": "settingsChangePassword",
                "summary": "Change your password",
                "description": "Changes the caller's own password after checking the current one. Any role may call it.\n\n**Roles:** admin, developer, viewer.\n\n- Existing JWT sessions and personal access tokens stay valid after a password change.\n\n- No audit entry is written.",
                "tags": [
                    "Settings"
                ],
                "responses": {
                    "200": {
                        "description": "The password was changed.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "message": "Password changed successfully."
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "oldPassword does not match. — \"Current password is incorrect.\"\n\nnewPassword is shorter than 8 characters (in practice schema validation rejects this first with FST_ERR_VALIDATION). — \"New password must be at least 8 characters.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Current password is incorrect."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "The caller's account no longer exists. — \"User not found.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "User not found."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "oldPassword": {
                                        "type": "string",
                                        "description": "Current password. (1–128 chars)"
                                    },
                                    "newPassword": {
                                        "type": "string",
                                        "description": "New password. (8–128 chars)"
                                    }
                                },
                                "required": [
                                    "oldPassword",
                                    "newPassword"
                                ]
                            },
                            "example": {
                                "oldPassword": "correct-horse-battery",
                                "newPassword": "a-new-long-password"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites": {
            "get": {
                "operationId": "sitesList",
                "summary": "List sites",
                "description": "Returns every site the caller can see, pinned sites first, then newest first. Admins and users with all-sites access get every site; other users get only the sites they were granted. Each site carries its most recent deployment, the cached SSL expiry and the flattened billing state.\n\n**Roles:** admin, developer, viewer.\n\n- Only gitToken is hidden: it is removed and replaced by the boolean hasGitToken. Every other Site column is returned as stored, including webhookToken (the push-to-deploy secret), statusPageToken, secBasicUser/secBasicHash (bcrypt hash of the basic-auth password) and secIpList (JSON string). tags is a JSON-encoded string array, not an array.\n\n- deployments contains at most 1 item (the newest deployment), including its full log.\n\n- sslDaysLeft / sslExpiresAt come from the background SSL monitor cache (null when never checked).\n\n- enforcementLevel is the site's billing subscription enforcement level (\"none\" when there is no subscription; otherwise e.g. banner, restrict, suspend, archived). billingSuspended = level is suspend or archived; billingPastDue = level is banner or restrict. The subscription object itself is not returned.\n\n- Not paginated.",
                "tags": [
                    "Sites"
                ],
                "responses": {
                    "200": {
                        "description": "Array of sites.",
                        "content": {
                            "application/json": {
                                "example": [
                                    {
                                        "id": 12,
                                        "name": "Shop",
                                        "domain": "shop.example.com",
                                        "serverId": null,
                                        "phpVersion": "8.3",
                                        "stackType": "laravel",
                                        "stagingOf": null,
                                        "dbName": "shop",
                                        "dbUser": "shop",
                                        "sslEnabled": true,
                                        "rootPath": "/var/www/sites/shop.example.com",
                                        "status": "active",
                                        "repoUrl": "https://github.com/example/shop.git",
                                        "branch": "main",
                                        "webhookToken": "5f0c2a9e7b1d4c3a8e6f0b2d4a6c8e0f1a3b5c7d9e1f2a4b",
                                        "preDeploy": null,
                                        "postDeploy": "php artisan optimize",
                                        "healthCheck": true,
                                        "healthCheckUrl": "https://shop.example.com/up",
                                        "runTests": false,
                                        "testCommand": "php artisan test",
                                        "testFailureMode": "block",
                                        "testTimeout": 300,
                                        "testUseSqlite": true,
                                        "deployQueued": false,
                                        "maintenanceMode": false,
                                        "uptimeMonitor": true,
                                        "statusPageEnabled": false,
                                        "statusPageToken": null,
                                        "secBasicAuth": false,
                                        "secBasicUser": null,
                                        "secBasicHash": null,
                                        "secIpMode": null,
                                        "secIpList": null,
                                        "pinned": true,
                                        "disabled": false,
                                        "tags": "[\"client-a\",\"production\"]",
                                        "notes": null,
                                        "createdAt": "2026-11-20T09:30:00.000Z",
                                        "updatedAt": "2026-11-27T10:00:00.000Z",
                                        "trafficLog": false,
                                        "deployments": [
                                            {
                                                "id": 345,
                                                "siteId": 12,
                                                "commit": "a3f9c21",
                                                "branch": "main",
                                                "status": "success",
                                                "log": "[1/9] Cloning repository...\n...\n=== Deploy complete! ===\n__COMMIT__:a3f9c21\n",
                                                "comment": null,
                                                "testResult": null,
                                                "testsPassed": null,
                                                "testsFailed": null,
                                                "testsTotal": null,
                                                "testDurationMs": null,
                                                "createdAt": "2026-11-27T10:00:00.000Z"
                                            }
                                        ],
                                        "hasGitToken": true,
                                        "sslDaysLeft": 61,
                                        "sslExpiresAt": "2027-01-27T08:00:00.000Z",
                                        "enforcementLevel": "none",
                                        "billingSuspended": false,
                                        "billingPastDue": false
                                    }
                                ]
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "sitesCreate",
                "summary": "Create a site",
                "description": "Creates a site record in status \"pending\" with rootPath /var/www/sites/<domain>. Nothing is set up on the server yet: call the provision endpoint next.\n\n**Roles:** admin.\n\n- The response has no deployments field. gitToken is replaced by hasGitToken.\n\n- A duplicate domain is not checked by the handler; the unique constraint makes Prisma throw, which surfaces as a 500.",
                "tags": [
                    "Sites"
                ],
                "responses": {
                    "201": {
                        "description": "The created site.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 13,
                                    "name": "Shop",
                                    "domain": "shop.example.com",
                                    "serverId": null,
                                    "phpVersion": "8.3",
                                    "stackType": "laravel",
                                    "stagingOf": null,
                                    "dbName": null,
                                    "dbUser": null,
                                    "sslEnabled": false,
                                    "rootPath": "/var/www/sites/shop.example.com",
                                    "status": "pending",
                                    "repoUrl": null,
                                    "branch": "main",
                                    "webhookToken": null,
                                    "preDeploy": null,
                                    "postDeploy": null,
                                    "healthCheck": false,
                                    "healthCheckUrl": null,
                                    "runTests": false,
                                    "testCommand": "php artisan test",
                                    "testFailureMode": "block",
                                    "testTimeout": 300,
                                    "testUseSqlite": true,
                                    "deployQueued": false,
                                    "maintenanceMode": false,
                                    "uptimeMonitor": true,
                                    "statusPageEnabled": false,
                                    "statusPageToken": null,
                                    "secBasicAuth": false,
                                    "secBasicUser": null,
                                    "secBasicHash": null,
                                    "secIpMode": null,
                                    "secIpList": null,
                                    "pinned": false,
                                    "disabled": false,
                                    "tags": "[]",
                                    "notes": null,
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z",
                                    "trafficLog": false,
                                    "hasGitToken": false
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "serverId does not match a server. — \"Selected server not found\"\n\nserverId is an agent-only fleet server (no SSH host). — \"Sites can only be placed on a server with SSH access. This server is connected through the agent only.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Selected server not found"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Display name. (1–100 chars)"
                                    },
                                    "domain": {
                                        "type": "string",
                                        "description": "Primary hostname. Must be unique across sites. (3–253 chars, pattern ^[a-zA-Z0-9][a-zA-Z0-9\\-\\.]*[a-zA-Z0-9]$)"
                                    },
                                    "phpVersion": {
                                        "type": "string",
                                        "description": "PHP version. (pattern ^\\d+\\.\\d+$, default \"8.2\")"
                                    },
                                    "serverId": {
                                        "type": "integer",
                                        "description": "Server to host the site on. Omit (or 0) for the panel's local server. (must be an existing server with SSH access)"
                                    }
                                },
                                "required": [
                                    "name",
                                    "domain"
                                ]
                            },
                            "example": {
                                "name": "Shop",
                                "domain": "shop.example.com",
                                "phpVersion": "8.3"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/tags": {
            "get": {
                "operationId": "sitesTags",
                "summary": "List all site tags",
                "description": "Returns the distinct tags used across all sites, sorted alphabetically.\n\n**Roles:** admin, developer, viewer.\n\n- Tags are collected from every site in the panel, not only the sites the caller has access to.",
                "tags": [
                    "Sites"
                ],
                "responses": {
                    "200": {
                        "description": "Sorted distinct tags.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "tags": [
                                        "client-a",
                                        "production",
                                        "staging"
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}": {
            "get": {
                "operationId": "sitesGet",
                "summary": "Get a site",
                "description": "Returns one site with its 20 most recent deployments (newest first).\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- Only gitToken is hidden: it is removed and replaced by the boolean hasGitToken. Every other Site column is returned as stored, including webhookToken (the push-to-deploy secret), statusPageToken, secBasicUser/secBasicHash (bcrypt hash of the basic-auth password) and secIpList (JSON string). tags is a JSON-encoded string array, not an array.\n\n- Each deployment includes its full log text.\n\n- status is one of pending, provisioning, active, error. stackType is one of laravel, wordpress, static, node. serverId null = the panel's local server. stagingOf is the production site id when this site is a staging copy.\n\n- Unlike GET /api/sites, this does not include sslDaysLeft, sslExpiresAt or the billing fields.",
                "tags": [
                    "Sites"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The site.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 12,
                                    "name": "Shop",
                                    "domain": "shop.example.com",
                                    "serverId": null,
                                    "phpVersion": "8.3",
                                    "stackType": "laravel",
                                    "stagingOf": null,
                                    "dbName": "shop",
                                    "dbUser": "shop",
                                    "sslEnabled": true,
                                    "rootPath": "/var/www/sites/shop.example.com",
                                    "status": "active",
                                    "repoUrl": "https://github.com/example/shop.git",
                                    "branch": "main",
                                    "webhookToken": "5f0c2a9e7b1d4c3a8e6f0b2d4a6c8e0f1a3b5c7d9e1f2a4b",
                                    "preDeploy": null,
                                    "postDeploy": "php artisan optimize",
                                    "healthCheck": true,
                                    "healthCheckUrl": "https://shop.example.com/up",
                                    "runTests": false,
                                    "testCommand": "php artisan test",
                                    "testFailureMode": "block",
                                    "testTimeout": 300,
                                    "testUseSqlite": true,
                                    "deployQueued": false,
                                    "maintenanceMode": false,
                                    "uptimeMonitor": true,
                                    "statusPageEnabled": false,
                                    "statusPageToken": null,
                                    "secBasicAuth": false,
                                    "secBasicUser": null,
                                    "secBasicHash": null,
                                    "secIpMode": null,
                                    "secIpList": null,
                                    "pinned": true,
                                    "disabled": false,
                                    "tags": "[\"client-a\",\"production\"]",
                                    "notes": null,
                                    "createdAt": "2026-11-20T09:30:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z",
                                    "trafficLog": false,
                                    "deployments": [
                                        {
                                            "id": 345,
                                            "siteId": 12,
                                            "commit": "a3f9c21",
                                            "branch": "main",
                                            "status": "success",
                                            "log": "[1/9] Cloning repository...\n...\n=== Deploy complete! ===\n__COMMIT__:a3f9c21\n",
                                            "comment": null,
                                            "testResult": null,
                                            "testsPassed": null,
                                            "testsFailed": null,
                                            "testsTotal": null,
                                            "testDurationMs": null,
                                            "createdAt": "2026-11-27T10:00:00.000Z"
                                        }
                                    ],
                                    "hasGitToken": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            },
            "delete": {
                "operationId": "sitesDelete",
                "summary": "Delete a site",
                "description": "Deletes the site record (and, by cascade, its deployments, config history and other site-owned rows). With cleanup=true it first runs cleanup.sh on the site's server to remove the vhost, site directory, database and database user.\n\n**Roles:** admin (with access to the site).\n\n- With cleanup=true the status is 200 and the body is {\"ok\": true, \"cleanupOk\": true|false, \"cleanupLog\": \"<script output>\"}, e.g. {\"ok\":true,\"cleanupOk\":true,\"cleanupLog\":\"Removed nginx vhost\\nDropped database shop\"}.\n\n- A failing cleanup does NOT stop the deletion: the panel record is deleted anyway and cleanupOk is false. The script has a 60 s timeout.\n\n- If the site has traffic logging on, it is switched off first (best effort).\n\n- Additional audit entries with cleanup: site.cleanup_ok or site.cleanup_failed.",
                "tags": [
                    "Sites"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "cleanup",
                        "in": "query",
                        "required": false,
                        "description": "Set to \"true\" to remove the site from the server as well. Any other value only deletes the panel record. (only the exact string \"true\" enables cleanup)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "204": {
                        "description": "Empty body when cleanup is not requested; 200 with a cleanup report when cleanup=true.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            },
            "patch": {
                "operationId": "sitesUpdate",
                "summary": "Update a site",
                "description": "Updates site settings: repository, branch, git token, deploy hooks, health check, deploy-time tests, stack, tags, pin, notes, name, and (admin only) domain and enabled state. Only the fields sent are changed. Hook scripts are written to the server immediately when preDeploy or postDeploy is sent.\n\n**Roles:** admin, developer (with access to the site).\n\n- Response: the Site row (no deployments) with gitToken replaced by hasGitToken, plus renameLog (script output) only when a domain rename ran on the server.\n\n- A domain rename runs rename-domain.sh on the site's server (30 s timeout) and sets rootPath to /var/www/sites/<new domain>; with renameOnDisk=false only the domain column changes and rootPath stays as it was. Opt-in traffic logging is moved to the new name.\n\n- tags is sent as an array but stored and returned as a JSON-encoded string.\n\n- Audit entries are only written for rename and enable/disable; other field changes are not audited.\n\n- Fields not listed are removed silently (additionalProperties: false).",
                "tags": [
                    "Sites"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The updated site (without deployments).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 12,
                                    "name": "Shop",
                                    "domain": "shop.example.com",
                                    "serverId": null,
                                    "phpVersion": "8.3",
                                    "stackType": "laravel",
                                    "stagingOf": null,
                                    "dbName": "shop",
                                    "dbUser": "shop",
                                    "sslEnabled": true,
                                    "rootPath": "/var/www/sites/shop.example.com",
                                    "status": "active",
                                    "repoUrl": "https://github.com/example/shop.git",
                                    "branch": "main",
                                    "webhookToken": "5f0c2a9e7b1d4c3a8e6f0b2d4a6c8e0f1a3b5c7d9e1f2a4b",
                                    "preDeploy": null,
                                    "postDeploy": "php artisan optimize",
                                    "healthCheck": true,
                                    "healthCheckUrl": "https://shop.example.com/up",
                                    "runTests": false,
                                    "testCommand": "php artisan test",
                                    "testFailureMode": "block",
                                    "testTimeout": 300,
                                    "testUseSqlite": true,
                                    "deployQueued": false,
                                    "maintenanceMode": false,
                                    "uptimeMonitor": true,
                                    "statusPageEnabled": false,
                                    "statusPageToken": null,
                                    "secBasicAuth": false,
                                    "secBasicUser": null,
                                    "secBasicHash": null,
                                    "secIpMode": null,
                                    "secIpList": null,
                                    "pinned": true,
                                    "disabled": false,
                                    "tags": "[\"client-a\",\"production\"]",
                                    "notes": null,
                                    "createdAt": "2026-11-20T09:30:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z",
                                    "trafficLog": false,
                                    "hasGitToken": true
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "repoUrl is not empty and not a valid git URL. — \"Invalid repository URL. Use an https:// or git@host:owner/repo URL.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid repository URL. Use an https:// or git@host:owner/repo URL."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"\n\nA non-admin sends a different domain, or sends disabled at all (even unchanged). — \"Only admins can change a site's domain or enabled status\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "The new domain belongs to another site. — \"That domain is already in use by another site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "That domain is already in use by another site"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "toggle-site.sh failed (or \"Failed to enable site on the server\"); body also has \"log\". Nothing is saved. — \"Failed to disable site on the server\"\n\nrename-domain.sh failed; body also has \"log\" with the script output. Nothing is saved. — \"Failed to rename domain on the server\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Failed to disable site on the server"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "repoUrl": {
                                        "type": "string",
                                        "description": "Git repository URL. Empty string clears it. (max 500 chars; must be http(s):// or scp-like user@host:path; no whitespace, must not start with \"-\")"
                                    },
                                    "branch": {
                                        "type": "string",
                                        "description": "Branch to deploy. (1–100 chars)"
                                    },
                                    "name": {
                                        "type": "string",
                                        "description": "Display name. (1–100 chars)"
                                    },
                                    "domain": {
                                        "type": "string",
                                        "description": "New domain (admin only). Renames the site on the server unless renameOnDisk is false. (3–253 chars, pattern ^[a-zA-Z0-9][a-zA-Z0-9\\-\\.]*[a-zA-Z0-9]$)"
                                    },
                                    "disabled": {
                                        "type": "boolean",
                                        "description": "true stops nginx serving the site, false serves it again (admin only)."
                                    },
                                    "renameOnDisk": {
                                        "type": "boolean",
                                        "description": "With a domain change: false only updates the panel record (use when the site was never provisioned on the server). (default true)"
                                    },
                                    "gitToken": {
                                        "type": "string",
                                        "description": "Access token for private HTTPS repositories. Stored encrypted; empty string removes it. Never returned (see hasGitToken). (max 500 chars)"
                                    },
                                    "preDeploy": {
                                        "type": "string",
                                        "description": "Bash run before the release is built (hooks/pre-deploy.sh). Empty string removes the hook file. (max 4096 chars)"
                                    },
                                    "postDeploy": {
                                        "type": "string",
                                        "description": "Bash run after the release went live (hooks/post-deploy.sh). Empty string removes the hook file. (max 4096 chars)"
                                    },
                                    "healthCheck": {
                                        "type": "boolean",
                                        "description": "Run an HTTP health check after each deploy and auto-roll back when it fails."
                                    },
                                    "healthCheckUrl": {
                                        "type": "string",
                                        "description": "URL for the health check. Defaults to http://<domain>/ when empty. (max 500 chars)"
                                    },
                                    "runTests": {
                                        "type": "boolean",
                                        "description": "Run tests before the release goes live."
                                    },
                                    "testCommand": {
                                        "type": "string",
                                        "description": "Test command. (max 500 chars)"
                                    },
                                    "testFailureMode": {
                                        "type": "string",
                                        "description": "block aborts the deploy on failing tests; warn continues. (one of: block, warn)"
                                    },
                                    "testTimeout": {
                                        "type": "integer",
                                        "description": "Test timeout in seconds. (10–3600)"
                                    },
                                    "testUseSqlite": {
                                        "type": "boolean",
                                        "description": "Run tests against an isolated in-memory SQLite database."
                                    },
                                    "tags": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Replaces the site's tags. (max 10 items, each a string of max 50 chars)"
                                    },
                                    "pinned": {
                                        "type": "boolean",
                                        "description": "Pin the site to the top of the list."
                                    },
                                    "notes": {
                                        "type": "string",
                                        "description": "Free-text notes. (max 2000 chars)"
                                    },
                                    "stackType": {
                                        "type": "string",
                                        "description": "Runtime stack used by deploy.sh. (one of: laravel, wordpress, static, node)"
                                    }
                                }
                            },
                            "example": {
                                "branch": "main",
                                "gitToken": "ghp_exampletoken",
                                "postDeploy": "php artisan optimize",
                                "healthCheck": true,
                                "healthCheckUrl": "https://shop.example.com/up",
                                "tags": [
                                    "client-a",
                                    "production"
                                ]
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/apm": {
            "get": {
                "operationId": "apmGet",
                "summary": "Get Laravel APM data",
                "description": "Reads the site's own Laravel Telescope data (telescope_entries) for the last 24 hours with the site's DB credentials from shared/.env: the 15 slowest queries, 15 slowest requests, 15 most recent exceptions and totals. Read-only (SELECT only).\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- Status 200 without data in these cases: remote server → { installed: false, supported: false, message: \"Laravel APM currently supports sites on the local server.\" }; unreadable .env / no DB_DATABASE → { installed: false, supported: true, message: \"Could not read database credentials from shared/.env.\" }; no telescope_entries table → { installed: false, supported: true, message: \"Laravel Telescope is not installed on this site. Install it (composer require laravel/telescope) to enable APM.\" }.\n\n- counts.slowQueries counts queries over 100 ms.\n\n- ms values are MySQL DECIMAL results and are returned as strings by the mysql2 driver; status is a string; at is the entry's created_at serialized as an ISO date (time-zone handling follows the driver defaults).\n\n- The window is fixed at 24 hours (no query parameter).",
                "tags": [
                    "Performance and uptime"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "APM data, or installed: false with a message.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "installed": true,
                                    "windowHours": 24,
                                    "counts": {
                                        "queries": 18250,
                                        "slowQueries": 42,
                                        "requests": 3100,
                                        "exceptions": 3
                                    },
                                    "slowQueries": [
                                        {
                                            "query": "select * from `orders` where `status` = ? order by `created_at` desc",
                                            "ms": "812.40",
                                            "at": "2026-11-27T09:41:00.000Z"
                                        }
                                    ],
                                    "slowRequests": [
                                        {
                                            "uri": "/checkout",
                                            "method": "POST",
                                            "status": "200",
                                            "ms": "1530.00",
                                            "at": "2026-11-27T09:40:58.000Z"
                                        }
                                    ],
                                    "exceptions": [
                                        {
                                            "class": "Illuminate\\Database\\QueryException",
                                            "message": "SQLSTATE[HY000] [2002] Connection refused",
                                            "at": "2026-11-27T08:12:00.000Z"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "Connecting to MySQL or a query failed; the error is the raw mysql2 message. — \"<error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/apply-preset": {
            "post": {
                "operationId": "presetsApply",
                "summary": "Apply a preset to a site",
                "description": "Copies the preset's settings onto the site; only the columns the preset contains are written. For an active site the deploy hook files are rewritten on the server when the preset contains preDeploy or postDeploy.\n\n**Roles:** admin, developer (with access to the site).\n\n- site is the Site row without deployments, gitToken replaced by hasGitToken.\n\n- hookWarning (string) is added when writing the hook files failed; the settings are saved anyway (every deploy rewrites the hooks).\n\n- A preset never changes the repository, branch, domain, stack, tokens, nginx, PHP-FPM, database or .env. An empty healthCheckUrl in the preset is stored as null.",
                "tags": [
                    "Presets"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The updated site and the fields that changed.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "site": {
                                        "id": 12,
                                        "name": "Shop",
                                        "domain": "shop.example.com",
                                        "serverId": null,
                                        "phpVersion": "8.3",
                                        "stackType": "laravel",
                                        "stagingOf": null,
                                        "dbName": "shop",
                                        "dbUser": "shop",
                                        "sslEnabled": true,
                                        "rootPath": "/var/www/sites/shop.example.com",
                                        "status": "active",
                                        "repoUrl": "https://github.com/example/shop.git",
                                        "branch": "main",
                                        "webhookToken": "5f0c2a9e7b1d4c3a8e6f0b2d4a6c8e0f1a3b5c7d9e1f2a4b",
                                        "preDeploy": null,
                                        "postDeploy": "php artisan optimize",
                                        "healthCheck": true,
                                        "healthCheckUrl": "https://shop.example.com/up",
                                        "runTests": true,
                                        "testCommand": "php artisan test",
                                        "testFailureMode": "block",
                                        "testTimeout": 300,
                                        "testUseSqlite": true,
                                        "deployQueued": false,
                                        "maintenanceMode": false,
                                        "uptimeMonitor": true,
                                        "statusPageEnabled": false,
                                        "statusPageToken": null,
                                        "secBasicAuth": false,
                                        "secBasicUser": null,
                                        "secBasicHash": null,
                                        "secIpMode": null,
                                        "secIpList": null,
                                        "pinned": true,
                                        "disabled": false,
                                        "tags": "[\"client-a\",\"production\"]",
                                        "notes": null,
                                        "createdAt": "2026-11-20T09:30:00.000Z",
                                        "updatedAt": "2026-11-27T10:00:00.000Z",
                                        "trafficLog": false,
                                        "hasGitToken": true
                                    },
                                    "changed": [
                                        "runTests",
                                        "healthCheckUrl"
                                    ]
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The stored config is empty or no longer validates. — \"This preset is empty or invalid.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "This preset is empty or invalid."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No preset with this id. — \"Preset not found\"\n\nNo site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Preset not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "presetId": {
                                        "type": "integer",
                                        "description": "Preset to apply. (minimum 1)"
                                    }
                                },
                                "required": [
                                    "presetId"
                                ]
                            },
                            "example": {
                                "presetId": 3
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/artisan/commands": {
            "get": {
                "operationId": "artisanCommands",
                "summary": "List allowed Artisan commands",
                "description": "Returns the fixed allow-list of Artisan commands that POST /artisan/run accepts, with a label, description and group for each. The list is the same for every site.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- Allow-list (15 commands): cache:clear, config:cache, config:clear, view:clear, route:cache, route:clear, optimize, optimize:clear, migrate, migrate:status, migrate:rollback, queue:restart, storage:link, telescope:clear, horizon:terminate. Any other value, including arguments or options (e.g. \"migrate --force\"), is rejected.\n\n- Groups: Cache, Database, Queue, Other.\n\n- The site is not looked up (no 404).",
                "tags": [
                    "Artisan and Composer"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The allowed commands.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "commands": [
                                        {
                                            "cmd": "cache:clear",
                                            "label": "Clear cache",
                                            "description": "Clear the application cache",
                                            "group": "Cache"
                                        },
                                        {
                                            "cmd": "migrate",
                                            "label": "Migrate",
                                            "description": "Run pending database migrations",
                                            "group": "Database"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/artisan/run": {
            "post": {
                "operationId": "artisanRun",
                "summary": "Run an Artisan command",
                "description": "Starts php<phpVersion> <rootPath>/current/artisan <command> --no-interaction --ansi in <rootPath>/current on the site's server. Returns immediately; follow the output with GET /api/sites/{id}/artisan/stream.\n\n**Roles:** admin, developer (with access to the site).\n\n- Allow-list (15 commands): cache:clear, config:cache, config:clear, view:clear, route:cache, route:clear, optimize, optimize:clear, migrate, migrate:status, migrate:rollback, queue:restart, storage:link, telescope:clear, horizon:terminate. Any other value, including arguments or options (e.g. \"migrate --force\"), is rejected.\n\n- Only --no-interaction and --ansi are added; --force is never passed, so commands that ask for confirmation in production (e.g. migrate) follow Laravel's non-interactive default.\n\n- One command per site at a time; the lock is held until 10 seconds after the process exits.\n\n- No audit entry is written.",
                "tags": [
                    "Artisan and Composer"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The command was started.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "started": true,
                                    "command": "optimize:clear",
                                    "siteId": 12
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "command is not one of the allowed commands. — \"Command not in allowlist: <command>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Command not in allowlist: <command>"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "A command for this site is running or finished less than 10 seconds ago. — \"Another artisan command is already running for this site.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Another artisan command is already running for this site."
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "The process could not be spawned (e.g. SSH not configured for the server). — \"<error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "command": {
                                        "type": "string",
                                        "description": "One command from the allow-list, exactly as listed. (1–100 chars; one of: cache:clear, config:cache, config:clear, view:clear, route:cache, route:clear, optimize, optimize:clear, migrate, migrate:status, migrate:rollback, queue:restart, storage:link, telescope:clear, horizon:terminate)"
                                    }
                                },
                                "required": [
                                    "command"
                                ]
                            },
                            "example": {
                                "command": "optimize:clear"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/artisan/stream": {
            "get": {
                "operationId": "artisanStream",
                "summary": "Stream Artisan output",
                "description": "Server-Sent Events stream of the site's current Artisan command. Buffered lines are replayed first, then live lines follow until the process exits.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n**Streams** Server-Sent Events.\n\n- Events (unnamed, data only): {\"line\": \"<one output line>\"} — stdout and stderr are split on newlines, empty lines dropped, ANSI colour codes kept (--ansi); {\"done\": true, \"status\": \"success\" | \"failed\"} when the process exits — the server then closes the stream.\n\n- When no command is running (or its buffer was already released) the stream sends {\"done\": true, \"status\": \"idle\"} and closes immediately.\n\n- Edge case: connecting in the 10 seconds after a command finished replays its lines but receives no done event (it was already emitted); the stream then stays open until the client disconnects.\n\n- If the process fails to start after spawning, a line \"Error: <message>\" and {\"done\": true, \"status\": \"failed\"} are sent.\n\n- No keep-alive comments are sent. The site id is not checked for existence.",
                "tags": [
                    "Artisan and Composer"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "SSE stream; each event is a \"data: <JSON>\" line.",
                        "content": {
                            "text/event-stream": {
                                "schema": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/branches": {
            "get": {
                "operationId": "sitesBranches",
                "summary": "List repository branches",
                "description": "Runs git ls-remote --heads against the site's repository URL and returns the branch names.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- The site's gitToken is NOT used, so a private HTTPS repository returns {\"branches\": []}. Any git failure (auth, network, 15 s timeout) also returns an empty list instead of an error.\n\n- git runs on the panel host, not on the site's server.",
                "tags": [
                    "Sites"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Branch names.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "branches": [
                                        "main",
                                        "develop",
                                        "feature/checkout"
                                    ]
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The site does not exist or has no repoUrl (no separate 404). — \"No repository configured\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "No repository configured"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/clone": {
            "post": {
                "operationId": "stagingClone",
                "summary": "Clone a site",
                "description": "Creates a new site (status \"pending\") that copies the source site's deploy configuration under a new name and domain. Only the panel record is created; the clone still has to be provisioned and deployed.\n\n**Roles:** admin, developer (with access to the site).\n\n- Copied: phpVersion, repoUrl, branch, preDeploy, postDeploy, healthCheck, healthCheckUrl (verbatim, so it may still point at the source domain), tags.\n\n- Not copied: gitToken, webhookToken, dbName/dbUser, deployments, stackType (defaults to laravel), serverId (the clone is always on the local server), test settings, security and status-page settings.\n\n- A duplicate domain is not checked by the handler; the unique constraint makes Prisma throw, which surfaces as a 500.",
                "tags": [
                    "Staging and promote"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Source site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "201": {
                        "description": "The new site.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 14,
                                    "name": "Shop EU",
                                    "domain": "eu.shop.example.com",
                                    "serverId": null,
                                    "phpVersion": "8.3",
                                    "stackType": "laravel",
                                    "stagingOf": null,
                                    "dbName": null,
                                    "dbUser": null,
                                    "sslEnabled": false,
                                    "rootPath": "/var/www/sites/eu.shop.example.com",
                                    "status": "pending",
                                    "repoUrl": "https://github.com/example/shop.git",
                                    "branch": "main",
                                    "webhookToken": null,
                                    "preDeploy": null,
                                    "postDeploy": "php artisan optimize",
                                    "healthCheck": true,
                                    "healthCheckUrl": "https://shop.example.com/up",
                                    "runTests": false,
                                    "testCommand": "php artisan test",
                                    "testFailureMode": "block",
                                    "testTimeout": 300,
                                    "testUseSqlite": true,
                                    "deployQueued": false,
                                    "maintenanceMode": false,
                                    "uptimeMonitor": true,
                                    "statusPageEnabled": false,
                                    "statusPageToken": null,
                                    "secBasicAuth": false,
                                    "secBasicUser": null,
                                    "secBasicHash": null,
                                    "secIpMode": null,
                                    "secIpList": null,
                                    "pinned": false,
                                    "disabled": false,
                                    "tags": "[\"client-a\",\"production\"]",
                                    "notes": null,
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z",
                                    "trafficLog": false,
                                    "hasGitToken": false
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Source site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Source site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Name of the new site. (1–100 chars)"
                                    },
                                    "domain": {
                                        "type": "string",
                                        "description": "Domain of the new site. (3–253 chars, pattern ^[a-zA-Z0-9][a-zA-Z0-9\\-\\.]*[a-zA-Z0-9]$)"
                                    }
                                },
                                "required": [
                                    "name",
                                    "domain"
                                ]
                            },
                            "example": {
                                "name": "Shop EU",
                                "domain": "eu.shop.example.com"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/composer/info": {
            "get": {
                "operationId": "composerInfo",
                "summary": "Get the root package info",
                "description": "Runs composer show --self --format=json in <rootPath>/current and returns the root package's name, description and first listed version.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- Timeout 15 seconds. Any failure returns { name: null, description: null, version: null } with status 200.",
                "tags": [
                    "Artisan and Composer"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The root package info (all null when Composer fails).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "name": "laravel/laravel",
                                    "description": "The skeleton application for the Laravel framework.",
                                    "version": "dev-main"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/composer/outdated": {
            "get": {
                "operationId": "composerOutdated",
                "summary": "List outdated Composer packages",
                "description": "Runs composer outdated --format=json in <rootPath>/current with the site's PHP version and returns Composer's package objects unchanged.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- The package objects are passed through from Composer, so their fields depend on the Composer version (the web client reads name, version, latest, latest-status, description).\n\n- Timeout 60 seconds. A non-zero exit with valid JSON output still returns 200.",
                "tags": [
                    "Artisan and Composer"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Composer's \"installed\" array.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "packages": [
                                        {
                                            "name": "laravel/framework",
                                            "direct-dependency": true,
                                            "homepage": "https://laravel.com",
                                            "source": "https://github.com/laravel/framework/tree/v11.30.0",
                                            "version": "v11.30.0",
                                            "latest": "v12.2.0",
                                            "latest-status": "update-possible",
                                            "description": "The Laravel Framework.",
                                            "abandoned": false
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "composer failed and printed no parseable JSON. — \"<error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/composer/update": {
            "post": {
                "operationId": "composerUpdate",
                "summary": "Update Composer packages",
                "description": "Runs composer as www-data in <rootPath>/current: composer update (all packages), composer update <package> -W (one package), or composer require <package>:^<targetVersion> -W for a major upgrade (keeping it in require-dev when it was there). Waits for Composer and returns its combined output.\n\n**Roles:** admin, developer (with access to the site).\n\n- Timeout 5 minutes. Runs with --no-interaction --ignore-platform-reqs; COMPOSER_HOME is <rootPath>/shared/.composer.\n\n- Send a JSON body (at least {}): the route has a body schema, and a missing body fails validation with 400 \"body must be object\".\n\n- Changes composer.json/composer.lock in the current release only; the next deploy uses the repository's files again.\n\n- The audit entry is written without the calling user. Meta: { package (or \"all\"), domain, majorTo? }.",
                "tags": [
                    "Artisan and Composer"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Composer finished; output is its stdout+stderr.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "output": "Loading composer repositories with package information\nUpdating dependencies\nLock file operations: 0 installs, 3 updates, 0 removals\n…"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "targetVersion given without package. — \"A package is required for a major upgrade\"\n\npackage does not match the allowed pattern. — \"Invalid composer package name\"\n\ntargetVersion is not 1–3 dot-separated numbers. — \"Invalid target version (expected e.g. 13 or 13.4.1)\"\n\nSite status is not \"active\". — \"Site is not active\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "A package is required for a major upgrade"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "Composer exited non-zero or timed out; error holds its output. — \"<composer output or error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<composer output or error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "package": {
                                        "type": "string",
                                        "description": "Package to update; omit to update everything. (max 200 chars; pattern ^[a-z0-9]([a-z0-9._-]*)/[a-z0-9]([a-z0-9._-]*)(:[A-Za-z0-9._^~*<>=. -]+)?$)"
                                    },
                                    "targetVersion": {
                                        "type": "string",
                                        "description": "Major upgrade target; sets the constraint to ^targetVersion. Requires package. (max 32 chars; pattern ^\\d+(\\.\\d+){0,2}$ (e.g. 13 or 13.4.1))"
                                    }
                                }
                            },
                            "example": {
                                "package": "laravel/framework",
                                "targetVersion": "12"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/config/env": {
            "get": {
                "operationId": "configEnvGet",
                "summary": "Get .env file",
                "description": "Returns the site's <rootPath>/shared/.env from the site's server. When the file does not exist, a Laravel .env template with a freshly generated APP_KEY is returned instead (nothing is written).\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- The content is returned in plain text, secrets included, to every role with site access (viewers too).\n\n- The template generates a new random APP_KEY on every call.",
                "tags": [
                    "Configuration files"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "File content and path.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "content": "APP_NAME=\"shop.example.com\"\nAPP_ENV=production\nAPP_DEBUG=false\nAPP_URL=https://shop.example.com\nDB_DATABASE=shop\n",
                                    "path": "/var/www/sites/shop.example.com/shared/.env"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            },
            "put": {
                "operationId": "configEnvUpdate",
                "summary": "Save .env file",
                "description": "Normalises and writes the site's shared .env (after backing up the old file to .env.bak) and stores an encrypted version in the .env history (latest 50 kept). The running app only picks it up after the next deploy.\n\n**Roles:** admin, developer (with access to the site).\n\n- Normalisation: CRLF/CR → LF, trailing spaces/tabs removed on every line, runs of 3+ newlines collapsed to one blank line, exactly one trailing newline.\n\n- On the first save through the panel the pre-existing file is stored as a version with note \"Before first panel edit\".\n\n- No audit entry is written. A write failure on the server surfaces as a 500.",
                "tags": [
                    "Configuration files"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Saved.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "message": ".env saved. Re-deploy to apply changes."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "content": {
                                        "type": "string",
                                        "description": "Full file content. (max 65536 chars)"
                                    }
                                },
                                "required": [
                                    "content"
                                ]
                            },
                            "example": {
                                "content": "APP_NAME=\"shop.example.com\"\nAPP_ENV=production\nAPP_DEBUG=false\nAPP_URL=https://shop.example.com\nDB_DATABASE=shop\n"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/config/env/versions": {
            "get": {
                "operationId": "configEnvVersions",
                "summary": "List .env versions",
                "description": "Lists the stored .env versions of the site, newest first (metadata only).\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- note is null for a normal save, \"Before first panel edit\" or \"Before restore\". createdBy is null when the author is unknown or deleted.\n\n- No 404: an unknown site returns {\"versions\": []}.",
                "tags": [
                    "Configuration files"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Version metadata.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "versions": [
                                        {
                                            "id": 41,
                                            "note": null,
                                            "createdAt": "2026-11-27T10:00:00.000Z",
                                            "createdBy": {
                                                "email": "ada@example.com"
                                            }
                                        },
                                        {
                                            "id": 40,
                                            "note": "Before first panel edit",
                                            "createdAt": "2026-11-20T09:30:00.000Z",
                                            "createdBy": {
                                                "email": "ada@example.com"
                                            }
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/config/env/versions/{vid}": {
            "get": {
                "operationId": "configEnvVersion",
                "summary": "Get a .env version",
                "description": "Returns the decrypted content of one stored .env version.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- content is \"\" when the version can no longer be decrypted (encryption key changed).",
                "tags": [
                    "Configuration files"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "vid",
                        "in": "path",
                        "required": true,
                        "description": ".env version id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Version content.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "content": "APP_NAME=\"shop.example.com\"\nAPP_ENV=production\nAPP_DEBUG=false\nAPP_URL=https://shop.example.com\nDB_DATABASE=shop\n",
                                    "createdAt": "2026-11-27T10:00:00.000Z"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No such version, or it belongs to another site. — \"Version not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Version not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/config/env/versions/{vid}/restore": {
            "post": {
                "operationId": "configEnvRestore",
                "summary": "Restore a .env version",
                "description": "Writes a stored version back to the site's shared .env. The current file is first saved as a version (\"Before restore\") and copied to .env.bak, so the restore can be undone.\n\n**Roles:** admin, developer (with access to the site).\n\n- A version that can no longer be decrypted is restored as an EMPTY file.\n\n- No request body. Send this request without a body (or with a JSON body such as {}). Sending Content-Type: application/json with an empty body is rejected by Fastify with 400 FST_ERR_CTP_EMPTY_JSON_BODY.",
                "tags": [
                    "Configuration files"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "vid",
                        "in": "path",
                        "required": true,
                        "description": ".env version id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Restored content.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "content": "APP_NAME=\"shop.example.com\"\nAPP_ENV=production\nAPP_DEBUG=false\nAPP_URL=https://shop.example.com\nDB_DATABASE=shop\n",
                                    "message": ".env restored. Re-deploy to apply."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"\n\nNo such version, or it belongs to another site. — \"Version not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/config/nginx": {
            "get": {
                "operationId": "configNginxGet",
                "summary": "Get nginx config",
                "description": "Returns the site's nginx vhost from /etc/nginx/sites-available/<domain> on the site's server. When the file does not exist, a default Laravel vhost template is returned instead (nothing is written).\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- The response does not say whether the content is the real file or the template.",
                "tags": [
                    "Configuration files"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "File content and path.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "content": "server {\n    listen 80;\n    server_name shop.example.com;\n    root /var/www/sites/shop.example.com/current/public;\n    ...\n}\n",
                                    "path": "/etc/nginx/sites-available/shop.example.com"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            },
            "put": {
                "operationId": "configNginxUpdate",
                "summary": "Save nginx config",
                "description": "Replaces the site's nginx vhost: backs up the current file, writes the new one, makes sure it is enabled, runs nginx -t and reloads nginx. When the test fails the previous config is restored (or the new file removed on a first save). Saved content is recorded in the config history.\n\n**Roles:** admin, developer (with access to the site).\n\n- Developers (with site access) may save the vhost; only admins may save PHP-FPM and supervisor configs.\n\n- No audit entry is written.\n\n- Before saving, the file currently on disk is added to the history if it is not there yet (note before-first-edit or external-change).",
                "tags": [
                    "Configuration files"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Saved and reloaded.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "message": "Nginx config saved and reloaded."
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "nginx -t failed; body also has \"details\" with the nginx output. — \"Nginx config test failed — reverted.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Nginx config test failed — reverted."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "The test passed but systemctl reload nginx failed; the new file stays on disk. Body also has \"details\". — \"Nginx reload failed\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Nginx reload failed"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "content": {
                                        "type": "string",
                                        "description": "Full file content. (max 65536 chars)"
                                    }
                                },
                                "required": [
                                    "content"
                                ]
                            },
                            "example": {
                                "content": "server {\n    listen 80;\n    server_name shop.example.com;\n    root /var/www/sites/shop.example.com/current/public;\n    ...\n}\n"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/config/nginx/versions": {
            "get": {
                "operationId": "configNginxVersions",
                "summary": "List nginx config versions",
                "description": "Lists the stored versions of the site's nginx vhost, newest first (metadata only).\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- note is null for a normal save, or a code: before-first-edit (the original file), external-change (file was changed outside the panel), php-switch, ssl-change, restored:<versionId>. The latest 50 versions per site and kind are kept; content is stored encrypted.\n\n- Declared in a loop over the kinds nginx, phpfpm and supervisor (one route per kind).",
                "tags": [
                    "Configuration files"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Version metadata.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "versions": [
                                        {
                                            "id": 88,
                                            "note": null,
                                            "createdAt": "2026-11-27T10:00:00.000Z",
                                            "createdByEmail": "ada@example.com"
                                        },
                                        {
                                            "id": 71,
                                            "note": "before-first-edit",
                                            "createdAt": "2026-11-20T09:30:00.000Z",
                                            "createdByEmail": null
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/config/nginx/versions/{vid}": {
            "get": {
                "operationId": "configNginxVersion",
                "summary": "Get a nginx config version",
                "description": "Returns one stored version of the site's nginx vhost, decrypted.\n\n**Roles:** admin, developer, viewer (with access to the site).",
                "tags": [
                    "Configuration files"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "vid",
                        "in": "path",
                        "required": true,
                        "description": "Config version id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The version.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 88,
                                    "content": "server {\n    listen 80;\n    server_name shop.example.com;\n    root /var/www/sites/shop.example.com/current/public;\n    ...\n}\n",
                                    "note": null,
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "createdByEmail": "ada@example.com"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No such version, it belongs to another site or kind, or it can no longer be decrypted. — \"Version not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Version not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/config/nginx/versions/{vid}/restore": {
            "post": {
                "operationId": "configNginxRestore",
                "summary": "Restore a nginx config version",
                "description": "Writes a stored version of the nginx vhost back to the server through the same guarded path as a normal save (nginx -t, revert on failure, reload). The file currently on disk is first added to the history if it is not there yet, so the restore can be undone.\n\n**Roles:** admin, developer (with access to the site).\n\n- The response is {\"ok\": true, \"content\": \"<restored content>\"}.\n\n- The restored content is recorded as a new version with note restored:<vid> (also when the file was written but the reload/update failed).\n\n- No request body. Send this request without a body (or with a JSON body such as {}). Sending Content-Type: application/json with an empty body is rejected by Fastify with 400 FST_ERR_CTP_EMPTY_JSON_BODY.",
                "tags": [
                    "Configuration files"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "vid",
                        "in": "path",
                        "required": true,
                        "description": "Config version id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Restored.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "content": "server {\n    listen 80;\n    server_name shop.example.com;\n    root /var/www/sites/shop.example.com/current/public;\n    ...\n}\n"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "nginx -t failed; body also has \"details\". — \"Nginx config test failed — reverted.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Nginx config test failed — reverted."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"\n\nNo such version for this site and kind, or it can no longer be decrypted. — \"Version not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "The version does not contain the current domain, or references php<x.y>-fpm for other PHP versions only (then the PHP message is used). Body also has \"code\": \"version_mismatch\". — \"This version was saved for a different domain and does not mention shop.example.com — restoring it would take the site offline. Copy what you need from it by hand instead.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "This version was saved for a different domain and does not mention shop.example.com — restoring it would take the site offline. Copy what you need from it by hand instead."
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "Reload failed after a passing test (file stays written); body also has \"details\". — \"Nginx reload failed\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Nginx reload failed"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/config/phpfpm/versions": {
            "get": {
                "operationId": "configPhpfpmVersions",
                "summary": "List PHP-FPM config versions",
                "description": "Lists the stored versions of the site's PHP-FPM pool, newest first (metadata only).\n\n**Roles:** admin (with access to the site).\n\n- note is null for a normal save, or a code: before-first-edit (the original file), external-change (file was changed outside the panel), php-switch, ssl-change, restored:<versionId>. The latest 50 versions per site and kind are kept; content is stored encrypted.\n\n- Declared in a loop over the kinds nginx, phpfpm and supervisor (one route per kind).",
                "tags": [
                    "Configuration files"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Version metadata.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "versions": [
                                        {
                                            "id": 88,
                                            "note": null,
                                            "createdAt": "2026-11-27T10:00:00.000Z",
                                            "createdByEmail": "ada@example.com"
                                        },
                                        {
                                            "id": 71,
                                            "note": "before-first-edit",
                                            "createdAt": "2026-11-20T09:30:00.000Z",
                                            "createdByEmail": null
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/config/phpfpm/versions/{vid}": {
            "get": {
                "operationId": "configPhpfpmVersion",
                "summary": "Get a PHP-FPM config version",
                "description": "Returns one stored version of the site's PHP-FPM pool, decrypted.\n\n**Roles:** admin (with access to the site).",
                "tags": [
                    "Configuration files"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "vid",
                        "in": "path",
                        "required": true,
                        "description": "Config version id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The version.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 88,
                                    "content": "[shop.example.com]\nuser = www-data\ngroup = www-data\nlisten = /run/php/php8.3-fpm-shop.example.com.sock\npm = dynamic\npm.max_children = 10\n",
                                    "note": null,
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "createdByEmail": "ada@example.com"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No such version, it belongs to another site or kind, or it can no longer be decrypted. — \"Version not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Version not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/config/phpfpm/versions/{vid}/restore": {
            "post": {
                "operationId": "configPhpfpmRestore",
                "summary": "Restore a PHP-FPM config version",
                "description": "Writes a stored version of the PHP-FPM pool back to the server through the same guarded path as a normal save (php-fpm -t, revert on failure, reload). The file currently on disk is first added to the history if it is not there yet, so the restore can be undone.\n\n**Roles:** admin (with access to the site).\n\n- reloaded is false when the php-fpm reload failed (the file is still installed).\n\n- The restored content is recorded as a new version with note restored:<vid> (also when the file was written but the reload/update failed).\n\n- No request body. Send this request without a body (or with a JSON body such as {}). Sending Content-Type: application/json with an empty body is rejected by Fastify with 400 FST_ERR_CTP_EMPTY_JSON_BODY.",
                "tags": [
                    "Configuration files"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "vid",
                        "in": "path",
                        "required": true,
                        "description": "Config version id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Restored.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "content": "[shop.example.com]\nuser = www-data\ngroup = www-data\nlisten = /run/php/php8.3-fpm-shop.example.com.sock\npm = dynamic\npm.max_children = 10\n",
                                    "reloaded": true
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The content has no \"[\" (no pool name). — \"Invalid PHP-FPM pool config\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid PHP-FPM pool config"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"\n\nNo such version for this site and kind, or it can no longer be decrypted. — \"Version not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "The version references php<x.y> versions none of which is the site's current PHP version. Body also has \"code\": \"version_mismatch\". — \"This version was saved for PHP 8.2, but the site now runs PHP 8.3 — restoring it could break PHP for other sites. Copy what you need from it by hand instead.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "This version was saved for PHP 8.2, but the site now runs PHP 8.3 — restoring it could break PHP for other sites. Copy what you need from it by hand instead."
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "php-fpm -t failed; the previous pool file is put back. — \"Config syntax error: <php-fpm -t output>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Config syntax error: <php-fpm -t output>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/config/supervisor/versions": {
            "get": {
                "operationId": "configSupervisorVersions",
                "summary": "List supervisor config versions",
                "description": "Lists the stored versions of the site's supervisor worker config, newest first (metadata only).\n\n**Roles:** admin (with access to the site).\n\n- note is null for a normal save, or a code: before-first-edit (the original file), external-change (file was changed outside the panel), php-switch, ssl-change, restored:<versionId>. The latest 50 versions per site and kind are kept; content is stored encrypted.\n\n- Declared in a loop over the kinds nginx, phpfpm and supervisor (one route per kind).",
                "tags": [
                    "Configuration files"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Version metadata.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "versions": [
                                        {
                                            "id": 88,
                                            "note": null,
                                            "createdAt": "2026-11-27T10:00:00.000Z",
                                            "createdByEmail": "ada@example.com"
                                        },
                                        {
                                            "id": 71,
                                            "note": "before-first-edit",
                                            "createdAt": "2026-11-20T09:30:00.000Z",
                                            "createdByEmail": null
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/config/supervisor/versions/{vid}": {
            "get": {
                "operationId": "configSupervisorVersion",
                "summary": "Get a supervisor config version",
                "description": "Returns one stored version of the site's supervisor worker config, decrypted.\n\n**Roles:** admin (with access to the site).",
                "tags": [
                    "Configuration files"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "vid",
                        "in": "path",
                        "required": true,
                        "description": "Config version id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The version.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 88,
                                    "content": "[program:shop.example.com-worker]\ncommand=php8.3 /var/www/sites/shop.example.com/current/artisan queue:work redis --sleep=3 --tries=3 --max-time=3600\nnumprocs=2\nstdout_logfile=/var/www/sites/shop.example.com/shared/logs/worker.log\n",
                                    "note": null,
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "createdByEmail": "ada@example.com"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No such version, it belongs to another site or kind, or it can no longer be decrypted. — \"Version not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Version not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/config/supervisor/versions/{vid}/restore": {
            "post": {
                "operationId": "configSupervisorRestore",
                "summary": "Restore a supervisor config version",
                "description": "Writes a stored version of the supervisor worker config back to the server through the same guarded path as a normal save (supervisorctl reread && update). The file currently on disk is first added to the history if it is not there yet, so the restore can be undone.\n\n**Roles:** admin (with access to the site).\n\n- output is the supervisorctl output.\n\n- The restored content is recorded as a new version with note restored:<vid> (also when the file was written but the reload/update failed).\n\n- No request body. Send this request without a body (or with a JSON body such as {}). Sending Content-Type: application/json with an empty body is rejected by Fastify with 400 FST_ERR_CTP_EMPTY_JSON_BODY.",
                "tags": [
                    "Configuration files"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "vid",
                        "in": "path",
                        "required": true,
                        "description": "Config version id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Restored.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "content": "[program:shop.example.com-worker]\ncommand=php8.3 /var/www/sites/shop.example.com/current/artisan queue:work redis --sleep=3 --tries=3 --max-time=3600\nnumprocs=2\nstdout_logfile=/var/www/sites/shop.example.com/shared/logs/worker.log\n",
                                    "output": "shop.example.com-worker: changed\nshop.example.com-worker: stopped\nshop.example.com-worker: updated process group"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"\n\nNo such version for this site and kind, or it can no longer be decrypted. — \"Version not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "The version does not contain the site's current rootPath. Body also has \"code\": \"version_mismatch\". — \"This version was saved for a different site folder and does not mention /var/www/sites/shop.example.com — restoring it would break the queue workers. Copy what you need from it by hand instead.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "This version was saved for a different site folder and does not mention /var/www/sites/shop.example.com — restoring it would break the queue workers. Copy what you need from it by hand instead."
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "supervisorctl reread/update failed; the file stays written. Body also has \"details\". — \"supervisorctl update failed\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "supervisorctl update failed"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/cron": {
            "get": {
                "operationId": "workersCronGet",
                "summary": "Get scheduler cron file",
                "description": "Returns the site's Laravel scheduler cron file /etc/cron.d/<domain with dots replaced by \"-\">-scheduler, whether it exists, and the line the panel would write.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- active=false and content \"\" when the file does not exist (or cannot be read).\n\n- This and GET /api/sites/{id}/scheduler manage the same cron file for ordinary domains but write slightly different content; see the scheduler endpoints.",
                "tags": [
                    "Workers and scheduler"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Cron state.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "active": true,
                                    "content": "# Laravel Scheduler — shop.example.com\n* * * * * www-data php8.3 /var/www/sites/shop.example.com/current/artisan schedule:run >> /dev/null 2>&1\n",
                                    "path": "/etc/cron.d/shop-example-com-scheduler",
                                    "expected": "# Laravel Scheduler — shop.example.com\n* * * * * www-data php8.3 /var/www/sites/shop.example.com/current/artisan schedule:run >> /dev/null 2>&1"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            },
            "put": {
                "operationId": "workersCronEnable",
                "summary": "Enable scheduler cron",
                "description": "Writes the Laravel scheduler cron file (runs php<version> artisan schedule:run every minute as www-data) on the site's server and sets mode 644.\n\n**Roles:** admin, developer (with access to the site).\n\n- Writes directly (no sudo): if the panel process cannot write to /etc/cron.d the request fails with a 500. The PUT /api/sites/{id}/scheduler variant writes through sudo install.\n\n- No audit entry is written. No request body is read (the web client sends {}).",
                "tags": [
                    "Workers and scheduler"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Written.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "path": "/etc/cron.d/shop-example-com-scheduler"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            },
            "delete": {
                "operationId": "workersCronDisable",
                "summary": "Disable scheduler cron",
                "description": "Deletes the site's Laravel scheduler cron file on the site's server.\n\n**Roles:** admin, developer (with access to the site).\n\n- Deletes without sudo; a permission error surfaces as a 500. No audit entry is written.",
                "tags": [
                    "Workers and scheduler"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Deleted.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/database/backup": {
            "post": {
                "operationId": "databaseBackupsCreate",
                "summary": "Create a database backup",
                "description": "Runs mysqldump for the database named in the site's shared/.env (DB_DATABASE, DB_USERNAME, DB_PASSWORD) and gzips it into <rootPath>/backups/<DB_DATABASE>_<UTC timestamp>.sql.gz on the site's server. The request waits until the dump has finished.\n\n**Roles:** admin, developer (with access to the site).\n\n- Filename rule: \"<DB_DATABASE>_\" + new Date().toISOString() with \":\" and \".\" replaced by \"-\", cut to 19 characters → e.g. shop_2026-11-27T10-00-00.sql.gz (UTC).\n\n- The dump runs through the shared exec helper with its default 30-second timeout (local and over SSH); a dump that takes longer is killed and the request returns 500 \"mysqldump failed\".\n\n- sizeHuman uses B / KB / MB with one decimal (1024-based).\n\n- No audit entry is written.\n\n- Send the POST without a JSON Content-Type header (no body) — Fastify rejects an empty body declared as application/json.",
                "tags": [
                    "Databases and backups"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The new backup file.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "filename": "shop_2026-11-27T10-00-00.sql.gz",
                                    "sizeBytes": 5242880,
                                    "sizeHuman": "5.0 MB",
                                    "createdAt": "2026-11-27T10:00:00.000Z"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "shared/.env cannot be read. The body also has \"details\": \"No shared/.env found at <rootPath>/shared/.env — configure it in the Config tab first.\" — \"Cannot read database credentials.\"\n\nshared/.env has no DB_DATABASE value. — \"DB_DATABASE is not set in .env\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Cannot read database credentials."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "mysqldump/gzip exited non-zero or timed out; \"details\" holds stderr or the error message. The partial file is deleted. — \"mysqldump failed\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "mysqldump failed"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/database/backup-schedule": {
            "get": {
                "operationId": "databaseScheduleGet",
                "summary": "Get the backup schedule",
                "description": "Reads the site's backup cron file (/etc/cron.d/<domain with dots replaced by hyphens>-backup) on the site's server and returns its time. active is false when the file does not exist.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- When the cron file cannot be read the response is { active: false, hour: 2, minute: 0, days: \"*\", cronPath }.\n\n- days is the cron day-of-week field as written (e.g. \"*\", \"1-5\", \"0,6\").",
                "tags": [
                    "Databases and backups"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The schedule (defaults 02:00 every day when not active).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "active": true,
                                    "hour": 2,
                                    "minute": 0,
                                    "days": "*",
                                    "cronPath": "/etc/cron.d/shop-example-com-backup"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            },
            "put": {
                "operationId": "databaseScheduleSet",
                "summary": "Set the backup schedule",
                "description": "Writes /etc/cron.d/<domain-with-hyphens>-backup on the site's server so scripts/backup.sh runs as www-data at the given time and days, logging to /var/log/orchestrator/backup.log. Also syncs the panel scripts to the server first.\n\n**Roles:** admin, developer (with access to the site).\n\n- Cron line: \"<minute> <hour> * * <days> www-data bash \\\"<scriptsDir>/backup.sh\\\" \\\"<rootPath>\\\" >> /var/log/orchestrator/backup.log 2>&1\".\n\n- The scheduled script names files \"<DB_DATABASE>_<YYYYMMDDHHMMSS>.sql.gz\" and deletes all but the 30 newest *.sql.gz backups in <rootPath>/backups (manual backups count towards the 30).\n\n- Unknown body fields are silently removed (additionalProperties: false).\n\n- Audit meta: { domain, hour, minute, days }.",
                "tags": [
                    "Databases and backups"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The schedule that was written.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "cronPath": "/etc/cron.d/shop-example-com-backup",
                                    "hour": 3,
                                    "minute": 30,
                                    "days": "1-5"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "hour": {
                                        "type": "integer",
                                        "description": "Hour of day (server time). (0–23)"
                                    },
                                    "minute": {
                                        "type": "integer",
                                        "description": "Minute of the hour. (0–59, default 0)"
                                    },
                                    "days": {
                                        "type": "string",
                                        "description": "Cron day-of-week field. (pattern ^[0-7,\\-\\*]+$, default \"*\")"
                                    }
                                },
                                "required": [
                                    "hour"
                                ]
                            },
                            "example": {
                                "hour": 3,
                                "minute": 30,
                                "days": "1-5"
                            }
                        }
                    }
                }
            },
            "delete": {
                "operationId": "databaseScheduleDelete",
                "summary": "Disable scheduled backups",
                "description": "Deletes the site's backup cron file on its server. Existing backup files are kept.\n\n**Roles:** admin, developer (with access to the site).\n\n- The audit entry is written without the calling user (userId null). Meta: { domain }.\n\n- Deleting a missing cron file is not an error.",
                "tags": [
                    "Databases and backups"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The schedule was removed (also when it did not exist).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/database/backups": {
            "get": {
                "operationId": "databaseBackupsList",
                "summary": "List database backups",
                "description": "Lists the *.sql.gz files in the site's <rootPath>/backups directory on the site's server (local disk or over SSH for remote servers), newest first. createdAt is the file modification time.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- Any error reading the directory (missing folder, SSH failure) returns {\"backups\": []} with status 200.\n\n- Only files ending in .sql.gz are listed.\n\n- Backups created by POST /database/backup are named \"<DB_DATABASE>_<YYYY-MM-DDTHH-MM-SS>.sql.gz\" (UTC, e.g. shop_2026-11-27T10-00-00.sql.gz). Scheduled backups (scripts/backup.sh) are named \"<DB_DATABASE>_<YYYYMMDDHHMMSS>.sql.gz\" in the server's local time and the script keeps only the 30 newest *.sql.gz files.",
                "tags": [
                    "Databases and backups"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The backup files, newest first.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "backups": [
                                        {
                                            "name": "shop_2026-11-27T10-00-00.sql.gz",
                                            "sizeBytes": 5242880,
                                            "createdAt": "2026-11-27T10:00:00.000Z"
                                        },
                                        {
                                            "name": "shop_20261126020000.sql.gz",
                                            "sizeBytes": 5110000,
                                            "createdAt": "2026-11-26T02:00:04.000Z"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/database/backups/{filename}": {
            "get": {
                "operationId": "databaseBackupsDownload",
                "summary": "Download a database backup",
                "description": "Streams one backup file from <rootPath>/backups as a gzip download. For remote servers the file is streamed over SSH with cat.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- Response headers: Content-Type: application/gzip, Content-Disposition: attachment; filename=\"<filename>\". Content-Length is set only for sites on the local server; remote downloads are streamed without it.\n\n- The filename check is stricter than the list: a listed backup whose name contains a dot or other character before .sql.gz cannot be downloaded, restored or deleted.",
                "tags": [
                    "Databases and backups"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "filename",
                        "in": "path",
                        "required": true,
                        "description": "Backup file name as returned by the list endpoint (URL-encode it). (pattern ^[\\w\\-]+\\.sql\\.gz$ (letters, digits, underscore, hyphen, then .sql.gz; no dots, slashes or spaces before the extension))",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The raw .sql.gz file, sent with Content-Disposition: attachment; filename=\"<filename>\".",
                        "content": {
                            "application/gzip": {
                                "schema": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "filename does not match ^[\\w\\-]+\\.sql\\.gz$. — \"Invalid filename\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid filename"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No regular file with this name in <rootPath>/backups. — \"Backup file not found\"\n\nNo site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Backup file not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            },
            "delete": {
                "operationId": "databaseBackupsDelete",
                "summary": "Delete a database backup",
                "description": "Deletes one backup file from <rootPath>/backups on the site's server.\n\n**Roles:** admin, developer (with access to the site).\n\n- No audit entry is written.\n\n- Copies uploaded to S3/R2 are not affected.",
                "tags": [
                    "Databases and backups"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "filename",
                        "in": "path",
                        "required": true,
                        "description": "Backup file name (URL-encode it). (pattern ^[\\w\\-]+\\.sql\\.gz$ (letters, digits, underscore, hyphen, then .sql.gz; no dots, slashes or spaces before the extension))",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The file was deleted.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "filename does not match ^[\\w\\-]+\\.sql\\.gz$. — \"Invalid filename\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid filename"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No regular file with this name in <rootPath>/backups. — \"Backup file not found\"\n\nNo site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Backup file not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/database/backups/{filename}/restore": {
            "post": {
                "operationId": "databaseBackupsRestore",
                "summary": "Restore a database backup",
                "description": "Destructive: replays a backup file into the site's database (DB_DATABASE from shared/.env) with the site's own DB credentials. Local sites stream the gunzipped file into mysql; remote sites run zcat | mysql on their own host over SSH.\n\n**Roles:** admin, developer (with access to the site).\n\n- The request waits for the restore to finish. Local restores have no timeout; remote restores use the shared exec helper's default 30-second SSH timeout, so a large remote restore can fail with 500 \"Restore failed\".\n\n- There is no confirmation step and no automatic backup before restoring.\n\n- Audit meta: { domain, filename }.",
                "tags": [
                    "Databases and backups"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "filename",
                        "in": "path",
                        "required": true,
                        "description": "Backup file name in <rootPath>/backups (URL-encode it). (pattern ^[\\w\\-]+\\.sql\\.gz$ (letters, digits, underscore, hyphen, then .sql.gz; no dots, slashes or spaces before the extension))",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The backup was restored.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "filename": "shop_2026-11-27T10-00-00.sql.gz"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "shared/.env missing or has no DB_DATABASE. — \"Cannot read database credentials from shared/.env.\"\n\nfilename does not match ^[\\w\\-]+\\.sql\\.gz$. — \"Invalid filename\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Cannot read database credentials from shared/.env."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No regular file with this name in <rootPath>/backups. — \"Backup file not found\"\n\nNo site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Backup file not found"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "mysql exited non-zero (or the remote command timed out); \"details\" holds up to 2000 chars of stderr. — \"Restore failed\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Restore failed"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/databases": {
            "get": {
                "operationId": "databasesList",
                "summary": "List site databases",
                "description": "Lists the MySQL databases recorded for the site: the primary one (created at provisioning, credentials in shared/.env) first, then secondary ones in creation order. Passwords are never returned.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- Every route in this file first refuses sites on a remote server with 400 (the routes talk to MySQL on the panel host at 127.0.0.1).",
                "tags": [
                    "Databases and backups"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The site's databases.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "databases": [
                                        {
                                            "id": 3,
                                            "siteId": 12,
                                            "dbName": "shop",
                                            "dbUser": "shop",
                                            "isPrimary": true,
                                            "createdAt": "2026-10-01T09:00:00.000Z"
                                        },
                                        {
                                            "id": 7,
                                            "siteId": 12,
                                            "dbName": "shop_reports",
                                            "dbUser": "shop_reports",
                                            "isPrimary": false,
                                            "createdAt": "2026-11-27T10:00:00.000Z"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The site is placed on a remote server (serverId set). Checked before the handler runs. — \"Database management (phpMyAdmin, users, import) is not yet available for sites on remote servers. Use the Backups tab, or manage the database directly on that server.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Database management (phpMyAdmin, users, import) is not yet available for sites on remote servers. Use the Backups tab, or manage the database directly on that server."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "databasesCreate",
                "summary": "Create a database",
                "description": "Creates a secondary MySQL database and user on the panel host using the MySQL root credentials from Settings, with a generated 28-character password, and grants the user ALL PRIVILEGES on it for both 'localhost' and '127.0.0.1'. The password is stored encrypted and never returned.\n\n**Roles:** admin (with access to the site).\n\n- Every route in this file first refuses sites on a remote server with 400 (the routes talk to MySQL on the panel host at 127.0.0.1).\n\n- Uses CREATE ... IF NOT EXISTS and then ALTER USER: if the MySQL user already exists, its password is reset to the new generated one.\n\n- Audit meta: { dbName, dbUser }.",
                "tags": [
                    "Databases and backups"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "201": {
                        "description": "The created database record.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 7,
                                    "siteId": 12,
                                    "dbName": "shop_reports",
                                    "dbUser": "shop_reports",
                                    "isPrimary": false,
                                    "createdAt": "2026-11-27T10:00:00.000Z"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The site is placed on a remote server (serverId set). Checked before the handler runs. — \"Database management (phpMyAdmin, users, import) is not yet available for sites on remote servers. Use the Backups tab, or manage the database directly on that server.\"\n\nSetting mysql_root_user is empty. \"details\": \"Set mysql_root_user and mysql_root_password in Settings first.\" — \"MySQL root credentials not configured.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Database management (phpMyAdmin, users, import) is not yet available for sites on remote servers. Use the Backups tab, or manage the database directly on that server."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "A SiteDatabase with this dbName exists (on any site). — \"Database \"<dbName>\" already exists.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Database \"<dbName>\" already exists."
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "A MySQL statement failed; \"details\" holds the MySQL error message. — \"Failed to create database\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Failed to create database"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "dbName": {
                                        "type": "string",
                                        "description": "Database name (unique across the panel). (1–64 chars, pattern ^[a-zA-Z0-9_]+$)"
                                    },
                                    "dbUser": {
                                        "type": "string",
                                        "description": "MySQL user to create (or update) for it. (1–32 chars, pattern ^[a-zA-Z0-9_]+$)"
                                    }
                                },
                                "required": [
                                    "dbName",
                                    "dbUser"
                                ]
                            },
                            "example": {
                                "dbName": "shop_reports",
                                "dbUser": "shop_reports"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/databases/{dbId}": {
            "delete": {
                "operationId": "databasesDelete",
                "summary": "Drop a database",
                "description": "Destructive: drops a secondary database and its MySQL user (both 'localhost' and '127.0.0.1' hosts) using the MySQL root credentials, then deletes the record. The primary database cannot be deleted.\n\n**Roles:** admin (with access to the site).\n\n- Every route in this file first refuses sites on a remote server with 400 (the routes talk to MySQL on the panel host at 127.0.0.1).\n\n- The site itself is not looked up — a missing site gives 404 \"Database not found\".\n\n- Audit meta: { dbName }.",
                "tags": [
                    "Databases and backups"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "dbId",
                        "in": "path",
                        "required": true,
                        "description": "SiteDatabase id (from GET /api/sites/{id}/databases). Must belong to the site.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The database was dropped.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The database is the site's primary one. — \"Cannot delete the primary database.\"\n\nThe site is placed on a remote server (serverId set). Checked before the handler runs. — \"Database management (phpMyAdmin, users, import) is not yet available for sites on remote servers. Use the Backups tab, or manage the database directly on that server.\"\n\nSetting mysql_root_user is empty. — \"MySQL root credentials not configured.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Cannot delete the primary database."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No database with this dbId on this site. — \"Database not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Database not found"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "A MySQL statement failed; \"details\" holds the MySQL error message. — \"Failed to drop database\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Failed to drop database"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/databases/{dbId}/import": {
            "post": {
                "operationId": "databasesImport",
                "summary": "Import a SQL dump",
                "description": "Imports an uploaded .sql or .sql.gz file into the database with the MySQL root credentials (multipart/form-data upload). The file is buffered to a temp file, piped into mysql (zcat first for .gz), then deleted. The request waits until the import has finished.\n\n**Roles:** admin, developer (with access to the site).\n\n**Rate limit:** 5 per minute per IP.\n\n- Content-Type must be multipart/form-data (let the HTTP client set the boundary). Example: curl -H \"Authorization: Bearer orch_…\" -F \"file=@dump.sql.gz\" https://panel.example.com/api/sites/12/databases/3/import\n\n- Any file name ending in \".gz\" is treated as gzip; \".sql\" as plain SQL. The content itself is not checked.\n\n- Upload limit 512 MB (global multipart fileSize limit). The whole file is held in memory before it is written to the temp file.\n\n- Import timeout 30 minutes. Runs as the MySQL root user from Settings, not the database's own user, so the dump can contain any statement (no SQL allow-list here).\n\n- Audit meta: { dbName, filename }.\n\n- Every route in this file first refuses sites on a remote server with 400 (the routes talk to MySQL on the panel host at 127.0.0.1).",
                "tags": [
                    "Databases and backups"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "dbId",
                        "in": "path",
                        "required": true,
                        "description": "SiteDatabase id (from GET /api/sites/{id}/databases). Must belong to the site.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The import finished; warnings holds mysql's stderr or null.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "warnings": null
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The site is placed on a remote server (serverId set). Checked before the handler runs. — \"Database management (phpMyAdmin, users, import) is not yet available for sites on remote servers. Use the Backups tab, or manage the database directly on that server.\"\n\nSetting mysql_root_user is empty. — \"MySQL root credentials not configured.\"\n\nThe request is not multipart/form-data or has no file part. — \"No file uploaded.\"\n\nThe uploaded file name does not end in .sql or .gz. — \"Only .sql and .sql.gz files are supported.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Database management (phpMyAdmin, users, import) is not yet available for sites on remote servers. Use the Backups tab, or manage the database directly on that server."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is neither admin nor developer. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No database with this dbId on this site. — \"Database not found\"\n\nNo site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Database not found"
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Too many requests — see the Retry-After header. — \"Rate limit exceeded, retry in …\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Rate limit exceeded, retry in …"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "mysql/zcat failed, the 30-minute timeout was hit, or the upload exceeded 512 MB; \"details\" holds up to 2000 chars of stderr or the error message. — \"Import failed\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Import failed"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "multipart/form-data": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "file": {
                                        "type": "string",
                                        "format": "binary",
                                        "description": "The dump file. The first file part is used whatever its field name (the web client sends \"file\"). (file name must end in .sql or .gz (.sql.gz); max 512 MB)"
                                    }
                                },
                                "required": [
                                    "file"
                                ]
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/databases/{dbId}/pma-session": {
            "post": {
                "operationId": "databasesPmaSession",
                "summary": "Open phpMyAdmin for a database",
                "description": "Issues a single-use phpMyAdmin sign-on link for one database. The URL carries an opaque token; phpMyAdmin's signon bridge redeems it over a loopback call for the real credentials, so the MySQL password never reaches the browser.\n\n**Roles:** admin, developer (with access to the site).\n\n- The token is single-use and expires after 60 seconds (kept in memory; lost on API restart). Open the URL right away.\n\n- The 503 configuration check runs before the site lookup.\n\n- Audit meta: { dbName }.\n\n- Every route in this file first refuses sites on a remote server with 400 (the routes talk to MySQL on the panel host at 127.0.0.1).",
                "tags": [
                    "Databases and backups"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "dbId",
                        "in": "path",
                        "required": true,
                        "description": "SiteDatabase id (from GET /api/sites/{id}/databases). Must belong to the site.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The one-time sign-on URL.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "url": "https://pma.example.com/signon.php?token=4f9c2a7e1b8d3c6f"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Primary database and shared/.env cannot be read. — \"Cannot resolve database credentials.\"\n\nThe site is placed on a remote server (serverId set). Checked before the handler runs. — \"Database management (phpMyAdmin, users, import) is not yet available for sites on remote servers. Use the Backups tab, or manage the database directly on that server.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Cannot resolve database credentials."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No database with this dbId on this site. — \"Database not found\"\n\nNo site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Database not found"
                                }
                            }
                        }
                    },
                    "503": {
                        "description": "PMA_BASE_URL or PMA_BRIDGE_SECRET is not set in the API environment. \"details\": \"Set PMA_BASE_URL and PMA_BRIDGE_SECRET in the API environment.\" — \"phpMyAdmin SSO is not configured on this server.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "phpMyAdmin SSO is not configured on this server."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/databases/{dbId}/query": {
            "post": {
                "operationId": "databasesQuery",
                "summary": "Run a SQL query",
                "description": "Runs one SQL statement against the database with that database's own credentials (primary: shared/.env; secondary: its stored generated password) and returns up to 1000 rows. Only SELECT, INSERT, UPDATE, DELETE, EXPLAIN, SHOW, DESCRIBE/DESC and WITH statements are accepted.\n\n**Roles:** admin, developer (with access to the site).\n\n**Rate limit:** 30 per minute per IP.\n\n- Allowed statement types: SELECT, INSERT, UPDATE, DELETE, EXPLAIN, SHOW, DESCRIBE, DESC, WITH.\n\n- Blocked statement types: DROP, CREATE, ALTER, TRUNCATE, GRANT, REVOKE, RENAME, SET, FLUSH, LOAD, LOCK, UNLOCK, CALL, EXEC, EXECUTE, REPLACE, USE, XA, KILL, PURGE, RESET, SOURCE; plus any statement containing INTO OUTFILE / INTO DUMPFILE.\n\n- Validation splits the text on \";\" and checks every part, but the query is sent with multipleStatements disabled (as a prepared statement), so more than one statement fails with 400 \"Query failed\".\n\n- Limits: 10,000 characters of SQL, 30-second query timeout, 10-second connect timeout, at most 1000 rows returned (truncated is true when the result had more). rowCount is the number of rows returned, not the total.\n\n- Write statements (INSERT/UPDATE/DELETE) return columns: [] and rows: [] — affected-row counts are not reported.\n\n- Writes are not blocked: INSERT, UPDATE and DELETE run for real. Viewers cannot call it (POST).\n\n- Audit meta: { dbName, sql (first 200 chars) }. Written only for successful queries.\n\n- Every route in this file first refuses sites on a remote server with 400 (the routes talk to MySQL on the panel host at 127.0.0.1).",
                "tags": [
                    "Databases and backups"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "dbId",
                        "in": "path",
                        "required": true,
                        "description": "SiteDatabase id (from GET /api/sites/{id}/databases). Must belong to the site.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Column names and rows as arrays in column order.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "columns": [
                                        "id",
                                        "email"
                                    ],
                                    "rows": [
                                        [
                                            42,
                                            "ada@example.com"
                                        ],
                                        [
                                            41,
                                            "grace@example.com"
                                        ]
                                    ],
                                    "rowCount": 2,
                                    "truncated": false,
                                    "elapsedMs": 4
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "A statement starts with DROP, CREATE, ALTER, TRUNCATE, GRANT, REVOKE, RENAME, SET, FLUSH, LOAD, LOCK, UNLOCK, CALL, EXEC, EXECUTE, REPLACE, USE, XA, KILL, PURGE, RESET or SOURCE (<TYPE> is its first word, upper-cased). — \"<TYPE> statements are not permitted. Only SELECT, INSERT, UPDATE, DELETE, EXPLAIN, SHOW, DESCRIBE are allowed.\"\n\nPrimary database and shared/.env cannot be read. — \"Cannot read database credentials from shared/.env\"\n\nThe site is placed on a remote server (serverId set). Checked before the handler runs. — \"Database management (phpMyAdmin, users, import) is not yet available for sites on remote servers. Use the Backups tab, or manage the database directly on that server.\"\n\nNothing left after stripping -- and /* */ comments. — \"Empty query.\"\n\nMySQL rejected the statement, it timed out, or the connection failed. Body also has \"details\" (MySQL message) and \"code\" (MySQL error code, e.g. ER_PARSE_ERROR). — \"Query failed\"\n\nA statement contains INTO OUTFILE or INTO DUMPFILE. — \"SELECT … INTO OUTFILE/DUMPFILE is not permitted.\"\n\nA statement does not start with an allowed keyword. — \"Unrecognized or disallowed statement type.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<TYPE> statements are not permitted. Only SELECT, INSERT, UPDATE, DELETE, EXPLAIN, SHOW, DESCRIBE are allowed."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No database with this dbId on this site. — \"Database not found\"\n\nNo site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Database not found"
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Too many requests — see the Retry-After header. — \"Rate limit exceeded, retry in …\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Rate limit exceeded, retry in …"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "sql": {
                                        "type": "string",
                                        "description": "The SQL statement. (1–10000 chars; must start with SELECT, INSERT, UPDATE, DELETE, EXPLAIN, SHOW, DESCRIBE, DESC or WITH (case-insensitive, after comments are stripped))"
                                    }
                                },
                                "required": [
                                    "sql"
                                ]
                            },
                            "example": {
                                "sql": "SELECT id, email FROM users ORDER BY id DESC LIMIT 2"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/deploy": {
            "post": {
                "operationId": "deploymentsTrigger",
                "summary": "Deploy a site",
                "description": "Starts a deploy of the site's branch (or of a given ref) in the background and returns the new deployment id. If a deploy or rollback is already running for the site, the request is queued instead and starts automatically about 2 seconds after the current one finishes.\n\n**Roles:** admin, developer (with access to the site).\n\n- Queued response (also 200): {\"queued\": true, \"message\": \"Deploy queued — will start automatically after the current one finishes.\"}. The queue is a single flag (Site.deployQueued): several queued requests collapse into one deploy, and the queued deploy re-reads the site settings and deploys the branch HEAD without skipTests or ref.\n\n- Deployment lifecycle: a Deployment row is created with status \"running\"; it ends as \"success\" or \"failed\". Deployment.status values: running, success, failed (legacy \"pending\" rows are marked failed at API startup). testResult is null (not run), passed, failed or skipped (tests enabled but skipTests=1).\n\n- After a successful script run the optional health check (3 attempts, 5 s apart; HTTP < 500 = OK) runs; if it fails the deploy is marked failed and the previous release is restored automatically (audit deploy.health_rollback).\n\n- A deploy that runs longer than DEPLOY_TIMEOUT_MS (default 25 minutes) is killed and marked failed.\n\n- Audit entries are written when the deploy ends (deploy.success or deploy.failed), not when it starts. On completion the panel also sends the configured deploy notifications, an in-app notification and the deploy.succeeded / deploy.failed event (outbound webhooks, automation).\n\n- Follow the output with GET /api/sites/{id}/deploy/stream.\n\n- No request body. Send this request without a body (or with a JSON body such as {}). Sending Content-Type: application/json with an empty body is rejected by Fastify with 400 FST_ERR_CTP_EMPTY_JSON_BODY.",
                "tags": [
                    "Deployments"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "skipTests",
                        "in": "query",
                        "required": false,
                        "description": "Set to \"1\" to skip the site's deploy-time tests for this deploy only (emergency override). The site setting is unchanged. (only \"1\" is recognised)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "ref",
                        "in": "query",
                        "required": false,
                        "description": "Tag, branch or commit to deploy instead of the branch HEAD. (pattern ^[A-Za-z0-9._/\\-]{1,100}$; an invalid value is silently ignored (the branch HEAD is deployed))",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Either {started, deploymentId} when the deploy started, or {queued, message} when it was queued.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "started": true,
                                    "deploymentId": 346
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The site has no repoUrl. — \"No repository URL configured\"\n\nSite status is not \"active\" (e.g. not provisioned yet). — \"Site is not active\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "No repository URL configured"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "Race: another deploy claimed the site between the queue check and the start. — \"Deploy already in progress\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Deploy already in progress"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "Setup failed before the deploy process started (e.g. the remote server is unreachable or the hook files could not be written). — \"<error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/deploy/cancel": {
            "post": {
                "operationId": "deploymentsCancel",
                "summary": "Cancel a stuck deploy",
                "description": "Kills the running deploy process of the site (SIGKILL to the whole process group) if this API process started it; otherwise force-marks the newest \"running\" deployment row as failed and clears the deploy queue.\n\n**Roles:** admin (with access to the site).\n\n- Live process: returns {\"ok\": true, \"message\": \"Kill signal sent — the deploy will be marked failed shortly.\"}; the deploy then finishes as failed through the normal path (audit deploy.failed). In this case deployQueued is NOT cleared, so a queued deploy still starts afterwards.\n\n- Orphaned row (e.g. left over from an API restart): returns {\"ok\": true, \"message\": \"Marked the stuck deploy as failed.\"}, appends \"[orchestrator] Deploy cancelled by admin.\" to its log, clears deployQueued and writes audit deploy.cancelled.\n\n- Rollbacks are not tracked as killable processes; for a running rollback this endpoint takes the orphaned-row path.\n\n- No request body. Send this request without a body (or with a JSON body such as {}). Sending Content-Type: application/json with an empty body is rejected by Fastify with 400 FST_ERR_CTP_EMPTY_JSON_BODY.",
                "tags": [
                    "Deployments"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "What was done.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "message": "Kill signal sent — the deploy will be marked failed shortly."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No live deploy process and no deployment row in status \"running\". — \"No running deploy found for this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "No running deploy found for this site"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/deploy/pending": {
            "get": {
                "operationId": "deploymentsPending",
                "summary": "List undeployed commits",
                "description": "Shows the commits on the site's branch that are newer than the last successful deployment. Makes a temporary blob-less bare clone of the repository (using the site's git token) on the panel host, reads the log and deletes the clone. Read-only.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- currentCommit is the commit of the newest successful deployment (null if none). range=true means commits lists currentCommit..HEAD (max 50); range=false means the last commit could not be found in the branch history (force-push, or no previous deploy) and commits is simply the latest 20 commits.\n\n- hash and remoteCommit are 7-character short hashes; date is the author date in ISO 8601 with offset.\n\n- Successful rollback rows also count as \"successful deployments\" here; their commit is the 14-digit release name, so right after a rollback range is usually false.",
                "tags": [
                    "Deployments"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Pending commits.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "branch": "main",
                                    "currentCommit": "a3f9c21",
                                    "remoteCommit": "c81e0b4",
                                    "upToDate": false,
                                    "range": true,
                                    "commits": [
                                        {
                                            "hash": "c81e0b4",
                                            "subject": "Fix checkout rounding",
                                            "author": "Ada Lovelace",
                                            "date": "2026-11-27T09:12:44+00:00"
                                        },
                                        {
                                            "hash": "b07d3f2",
                                            "subject": "Add order export",
                                            "author": "Ada Lovelace",
                                            "date": "2026-11-26T16:40:02+00:00"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The site has no repoUrl. — \"No repository URL configured\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "No repository URL configured"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The clone or git log failed (auth, network, 60 s clone timeout, unknown branch). — \"Could not read the remote: <reason>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Could not read the remote: <reason>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/deploy/stream": {
            "get": {
                "operationId": "deploymentsStream",
                "summary": "Stream deploy log",
                "description": "Server-Sent Events stream of the site's current deploy or rollback. Replays the output buffered so far, then streams new output live and ends with a done event carrying the final status.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n**Streams** Server-Sent Events.\n\n- Each event is a single \"data: <JSON>\" line followed by a blank line. Output events: data: {\"line\":\"<chunk>\"}. For a deploy, <chunk> is a raw stdout/stderr chunk of deploy.sh (may contain several lines or a partial line, newlines included; git tokens are masked as ***). For a rollback, each event is one message without a trailing newline (e.g. \"✓  current → releases/20261120093000\").\n\n- Lines matching __COMMIT__:<hash>, __COMMIT_MSG__:, __COMMIT_AUTHOR__: and __TESTS__:passed|failed are machine markers emitted by deploy.sh and appear in the stream.\n\n- End of stream: data: {\"done\":true,\"status\":\"success\"} or {\"done\":true,\"status\":\"failed\"}, after which the server closes the connection.\n\n- If nothing is running for the site in this API process, the server immediately sends {\"done\":true,\"status\":\"running\"} when an orphaned \"running\" row exists (after replaying nothing), or {\"done\":true,\"status\":\"unknown\"} otherwise — including right after a deploy finished — and closes. Read the deployment row (GET /api/sites/{id}) for the final result in that case.\n\n- There is no 404: any site id the caller may access gets a stream.\n\n- A comment line \": ka\" is sent every 20 s as keep-alive.\n\n- Authenticate with the Authorization header (Bearer JWT or personal access token); the browser EventSource API cannot set it.",
                "tags": [
                    "Deployments"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "SSE stream of {\"line\"} events followed by one {\"done\"} event.",
                        "content": {
                            "text/event-stream": {
                                "schema": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/deployments/heatmap": {
            "get": {
                "operationId": "deploymentsHeatmap",
                "summary": "Get deploy activity heatmap",
                "description": "Counts the site's deployments per day over the last 52 weeks.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- Keys are UTC dates (YYYY-MM-DD); days without deployments are absent. total also counts rollbacks and running deployments.\n\n- No 404: an unknown site id returns {\"days\": {}}.",
                "tags": [
                    "Deployments"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Counts keyed by date.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "days": {
                                        "2026-11-20": {
                                            "total": 2,
                                            "success": 1,
                                            "failed": 1
                                        },
                                        "2026-11-27": {
                                            "total": 1,
                                            "success": 1,
                                            "failed": 0
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/deployments/{deployId}/redeploy": {
            "post": {
                "operationId": "deploymentsRedeploy",
                "summary": "Redeploy a site",
                "description": "Starts a new deploy with the site's current repository and branch settings, exactly like POST /api/sites/{id}/deploy without query options, but answers 202. Queues the deploy when one is already running.\n\n**Roles:** admin, developer (with access to the site).\n\n- Queued response (also 202): {\"ok\": true, \"queued\": true, \"message\": \"Deploy queued — will start automatically after the current one finishes.\"}.\n\n- Same lifecycle, health check, notifications and audit as the deploy trigger.\n\n- No request body. Send this request without a body (or with a JSON body such as {}). Sending Content-Type: application/json with an empty body is rejected by Fastify with 400 FST_ERR_CTP_EMPTY_JSON_BODY.",
                "tags": [
                    "Deployments"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "deployId",
                        "in": "path",
                        "required": true,
                        "description": "Id of the deployment being redeployed. Currently ignored: the branch HEAD is always deployed, not that deployment's commit. (not validated)",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "202": {
                        "description": "Deploy started (or queued).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "deploymentId": 347
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The site has no repoUrl. — \"No repository URL configured\"\n\nSite status is not \"active\". — \"Site is not active\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "No repository URL configured"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "Race with another deploy starting at the same moment. — \"Deploy already in progress\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Deploy already in progress"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "Deploy setup failed before the process started. — \"<error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/failed-jobs": {
            "get": {
                "operationId": "queueFailedList",
                "summary": "List failed jobs",
                "description": "Returns the 50 most recent rows of the Laravel failed_jobs table (newest first) through artisan tinker. Falls back to parsing artisan queue:failed text output when tinker fails.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- Rows are passed through from the site's own failed_jobs table, so their columns depend on the Laravel version.\n\n- Fallback shape (text parse of queue:failed): { id, connection, queue, class, failed_at } — all strings.\n\n- Returns { jobs: [] } when both methods fail. Timeout 15 seconds each; output above 1 MB makes tinker fail and triggers the fallback.",
                "tags": [
                    "Queue"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Failed jobs as raw failed_jobs rows.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "jobs": [
                                        {
                                            "id": 17,
                                            "uuid": "6f1c2b9e-1a2b-4c3d-9e8f-0a1b2c3d4e5f",
                                            "connection": "database",
                                            "queue": "default",
                                            "payload": "{\"displayName\":\"App\\\\Jobs\\\\SendInvoice\",…}",
                                            "exception": "RuntimeException: Mail server unreachable in /var/www/shop.example.com/current/app/Jobs/SendInvoice.php:42 …",
                                            "failed_at": "2026-11-27 09:58:12"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            },
            "delete": {
                "operationId": "queueFailedFlush",
                "summary": "Delete all failed jobs",
                "description": "Runs artisan queue:flush on the site's server, deleting every failed job.\n\n**Roles:** admin, developer (with access to the site).\n\n- The audit entry is written without the calling user. Meta: { domain }.",
                "tags": [
                    "Queue"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "artisan output.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "output": "   INFO  All failed jobs deleted successfully.\n"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "artisan exited non-zero or timed out (10 s). — \"<error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/failed-jobs/retry-all": {
            "post": {
                "operationId": "queueFailedRetryAll",
                "summary": "Retry all failed jobs",
                "description": "Runs artisan queue:retry all on the site's server and returns its output.\n\n**Roles:** admin, developer (with access to the site).\n\n- The audit entry is written without the calling user and without meta.\n\n- Fastify matches this static path before /failed-jobs/{jobId}/retry, so \"retry-all\" is never treated as a job id.",
                "tags": [
                    "Queue"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "artisan output.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "output": "   INFO  Pushing failed queue jobs back onto the queue.\n\n  17 ... DONE\n  18 ... DONE\n"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "artisan exited non-zero or timed out (15 s). — \"<error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/failed-jobs/{jobId}": {
            "delete": {
                "operationId": "queueFailedDelete",
                "summary": "Delete a failed job",
                "description": "Runs artisan queue:forget <jobId> on the site's server.\n\n**Roles:** admin, developer (with access to the site).\n\n- No audit entry is written.",
                "tags": [
                    "Queue"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "jobId",
                        "in": "path",
                        "required": true,
                        "description": "Failed job id as listed (passed to artisan queue:retry / queue:forget). (pattern ^[a-zA-Z0-9_-]+$)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The job was forgotten.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "jobId does not match ^[a-zA-Z0-9_-]+$. — \"Invalid job ID\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid job ID"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "artisan exited non-zero or timed out (10 s). — \"<error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/failed-jobs/{jobId}/retry": {
            "post": {
                "operationId": "queueFailedRetry",
                "summary": "Retry a failed job",
                "description": "Runs artisan queue:retry <jobId> on the site's server and returns its output.\n\n**Roles:** admin, developer (with access to the site).\n\n- The audit entry is written without the calling user. Meta: { jobId }.",
                "tags": [
                    "Queue"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "jobId",
                        "in": "path",
                        "required": true,
                        "description": "Failed job id as listed (passed to artisan queue:retry / queue:forget). (pattern ^[a-zA-Z0-9_-]+$)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "artisan output.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "output": "   INFO  Pushing failed queue jobs back onto the queue.\n\n  17 ... DONE\n"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "jobId does not match ^[a-zA-Z0-9_-]+$. — \"Invalid job ID\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid job ID"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "artisan exited non-zero or timed out (15 s). — \"<error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/files": {
            "get": {
                "operationId": "filemanagerList",
                "summary": "List a directory",
                "description": "Lists the entries of a directory inside the site's root path, on the server the site lives on (local host or a remote server over SSH). Directories are always listed first, then entries are sorted by the chosen key. Dotfiles are hidden unless hidden=1.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- Path rule (all file manager endpoints): the given path is normalised as if rooted at \"/\" and joined to the site's rootPath, so \"../\" segments are clamped at the site root rather than escaping it. Symlinks are NOT resolved, so a symlink inside the root that points elsewhere is followed by later operations.\n\n- type is one of file, dir, symlink. For directories size is 0. permissions is the octal mode (e.g. \"755\"), permsDisplay the rwx form.\n\n- On a remote server a listing error returns an empty entries array instead of an error.\n\n- mime is derived from the file extension only (fixed map); unknown or missing extensions give application/octet-stream.",
                "tags": [
                    "File manager"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "path",
                        "in": "query",
                        "required": false,
                        "description": "Directory relative to the site root. Leading slashes are optional; \"/\" or empty means the site root. (default \"/\"; jailed to the site root)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "hidden",
                        "in": "query",
                        "required": false,
                        "description": "Set to 1 to include entries whose name starts with a dot. (only the value \"1\" enables it)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "sort",
                        "in": "query",
                        "required": false,
                        "description": "Sort key. Any other value sorts by name (case-insensitive). (one of: name, size, modified; default name; not validated)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "order",
                        "in": "query",
                        "required": false,
                        "description": "Sort direction. Any value other than desc is ascending. (one of: asc, desc; default asc; not validated)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The directory entries, the normalised display path and the site's absolute root path.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "entries": [
                                        {
                                            "name": "current",
                                            "type": "symlink",
                                            "size": 38,
                                            "modified": "2026-11-27T10:00:00.000Z",
                                            "permissions": "777",
                                            "permsDisplay": "rwxrwxrwx",
                                            "owner": "www-data",
                                            "group": "www-data",
                                            "ext": "",
                                            "mime": "application/octet-stream"
                                        },
                                        {
                                            "name": "deploy.log",
                                            "type": "file",
                                            "size": 2048,
                                            "modified": "2026-11-27T10:00:00.000Z",
                                            "permissions": "644",
                                            "permsDisplay": "rw-r--r--",
                                            "owner": "www-data",
                                            "group": "www-data",
                                            "ext": "log",
                                            "mime": "text/plain"
                                        }
                                    ],
                                    "path": "/",
                                    "rootPath": "/var/www/shop.example.com"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Non-admin caller without a grant for this site. — \"Forbidden: no access to this site\"\n\nThe resolved path is outside the site root. — \"Path traversal denied\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "Listing a local directory failed (e.g. ENOENT for a directory that does not exist). Body is {\"error\": \"…\"}. — \"<system error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<system error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/files/chmod": {
            "post": {
                "operationId": "filemanagerChmod",
                "summary": "Change permissions",
                "description": "Runs chmod with an octal mode on each given path, optionally recursively.\n\n**Roles:** admin, developer (with access to the site).\n\n- Paths that fail the jail check or whose chmod fails are skipped silently.",
                "tags": [
                    "File manager"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Always ok after the site was found.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nNon-admin caller without a grant for this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role. — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "paths": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Paths relative to the site root. (array of strings; each jailed to the site root)"
                                    },
                                    "mode": {
                                        "type": "string",
                                        "description": "Octal permission mode. (pattern ^[0-7]{3,4}$)"
                                    },
                                    "recursive": {
                                        "type": "boolean",
                                        "description": "Apply recursively (chmod -R). (default false)"
                                    }
                                },
                                "required": [
                                    "paths",
                                    "mode"
                                ]
                            },
                            "example": {
                                "paths": [
                                    "/shared/storage"
                                ],
                                "mode": "775",
                                "recursive": true
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/files/chown": {
            "post": {
                "operationId": "filemanagerChown",
                "summary": "Change owner",
                "description": "Runs chown owner[:group] on each given path, optionally recursively.\n\n**Roles:** admin, developer (with access to the site).\n\n- Paths that fail the jail check or whose chown fails (e.g. the API user lacks privileges) are skipped silently.",
                "tags": [
                    "File manager"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Always ok after the site was found.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nNon-admin caller without a grant for this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role. — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "paths": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Paths relative to the site root. (array of strings; each jailed to the site root)"
                                    },
                                    "owner": {
                                        "type": "string",
                                        "description": "User name. (max 64 chars, pattern ^[a-zA-Z0-9._-]+$)"
                                    },
                                    "group": {
                                        "type": "string",
                                        "description": "Group name; when omitted only the owner changes. (max 64 chars, pattern ^[a-zA-Z0-9._-]+$)"
                                    },
                                    "recursive": {
                                        "type": "boolean",
                                        "description": "Apply recursively (chown -R). (default false)"
                                    }
                                },
                                "required": [
                                    "paths",
                                    "owner"
                                ]
                            },
                            "example": {
                                "paths": [
                                    "/shared/storage"
                                ],
                                "owner": "www-data",
                                "group": "www-data",
                                "recursive": true
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/files/copy": {
            "post": {
                "operationId": "filemanagerCopy",
                "summary": "Copy paths into a directory",
                "description": "Recursively copies each path into the destination directory, keeping its base name (cp -r src dest/<basename>).\n\n**Roles:** admin, developer (with access to the site).\n\n- Sources that fail the jail check or whose copy fails are skipped silently; the response is still {\"ok\": true}. The destination directory is not created.",
                "tags": [
                    "File manager"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Always ok once the destination passed the jail check.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nNon-admin caller without a grant for this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role. — \"Forbidden: viewer role is read-only\"\n\ndest resolves outside the site root. — \"Path traversal denied\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "paths": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Source paths relative to the site root. (array of strings; each jailed to the site root)"
                                    },
                                    "dest": {
                                        "type": "string",
                                        "description": "Destination directory relative to the site root. (jailed to the site root)"
                                    }
                                },
                                "required": [
                                    "paths",
                                    "dest"
                                ]
                            },
                            "example": {
                                "paths": [
                                    "/shared/.env"
                                ],
                                "dest": "/backups"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/files/delete": {
            "delete": {
                "operationId": "filemanagerDelete",
                "summary": "Delete files and directories",
                "description": "Recursively deletes each given path (rm -rf) inside the site root and reports a result per path. A path that fails the jail check is reported as failed and the others still run.\n\n**Roles:** admin, developer (with access to the site).\n\n- DELETE with a JSON body: send Content-Type: application/json.\n\n- Dangerous: the path \"/\" (or an empty string) resolves to the site root itself, so it deletes the whole site directory.\n\n- rm -rf of a non-existent path succeeds, so ok is true for paths that did not exist.\n\n- Each rm runs with the default 30-second command timeout.",
                "tags": [
                    "File manager"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "One result per requested path.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "results": [
                                        {
                                            "path": "/shared/storage/exports/old.csv",
                                            "ok": true
                                        },
                                        {
                                            "path": "/tmp-build",
                                            "ok": false,
                                            "error": "Command failed: …"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nNon-admin caller without a grant for this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role. — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "paths": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Paths relative to the site root. (array of strings, max 500 items; each jailed to the site root)"
                                    }
                                },
                                "required": [
                                    "paths"
                                ]
                            },
                            "example": {
                                "paths": [
                                    "/shared/storage/exports/old.csv",
                                    "/tmp-build"
                                ]
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/files/diff": {
            "get": {
                "operationId": "filemanagerDiff",
                "summary": "Diff two files",
                "description": "Returns the unified diff (diff -u) between two files of the site root. An empty string means the files are identical.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- The diff headers contain absolute server paths.\n\n- A missing file yields an empty diff rather than an error. Timeout 10 seconds.",
                "tags": [
                    "File manager"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "a",
                        "in": "query",
                        "required": true,
                        "description": "First file, relative to the site root. (jailed to the site root)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "b",
                        "in": "query",
                        "required": true,
                        "description": "Second file, relative to the site root. (jailed to the site root)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The unified diff text.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "diff": "--- /var/www/shop.example.com/shared/.env.example\n+++ /var/www/shop.example.com/shared/.env\n@@ -1 +1 @@\n-APP_DEBUG=true\n+APP_DEBUG=false\n"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "a or b is missing. — \"a and b required\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "a and b required"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Non-admin caller without a grant for this site. — \"Forbidden: no access to this site\"\n\na or b resolves outside the site root. — \"Path traversal denied\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/files/download": {
            "get": {
                "operationId": "filemanagerDownload",
                "summary": "Download a file",
                "description": "Streams a single file from the site root as an attachment. Works for any size and type (no 10 MB limit).\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- No Content-Type is set by the handler, so Fastify sends application/octet-stream for the stream.\n\n- Content-Length is sent only for sites on the local host; remote files are streamed over SSH (cat) without a length.\n\n- Auth is read from the Authorization header only; a plain browser link without the header is rejected with 401.",
                "tags": [
                    "File manager"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "path",
                        "in": "query",
                        "required": true,
                        "description": "File path relative to the site root. (jailed to the site root)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The raw file bytes with Content-Disposition: attachment; filename=\"<basename>\".",
                        "content": {
                            "application/octet-stream": {
                                "schema": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The path query parameter is missing or empty. — \"path required\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "path required"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Non-admin caller without a grant for this site. — \"Forbidden: no access to this site\"\n\nThe resolved path is outside the site root. — \"Path traversal denied\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "The path does not exist or is not a regular file. — \"File not found\"\n\nNo site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "File not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/files/download-zip": {
            "post": {
                "operationId": "filemanagerDownloadZip",
                "summary": "Download paths as a zip",
                "description": "Builds a temporary zip of the given paths (relative to the site root) in /tmp on the site's server, streams it back as <name>.zip and deletes the temporary file afterwards.\n\n**Roles:** admin, developer (with access to the site).\n\n- No Content-Type is set by the handler, so Fastify sends application/octet-stream.\n\n- zip has a 2-minute timeout; a zip failure (e.g. no valid paths) is not caught and returns Fastify's default 500 error body.\n\n- name is not sanitised and is placed directly in the Content-Disposition header.",
                "tags": [
                    "File manager"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The zip bytes with Content-Disposition: attachment; filename=\"<name>.zip\".",
                        "content": {
                            "application/octet-stream": {
                                "schema": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nNon-admin caller without a grant for this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (this is a POST, so viewers are blocked even though it only reads). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "paths": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Paths to include, relative to the site root. (array of strings; each jailed to the site root (invalid ones dropped silently))"
                                    },
                                    "name": {
                                        "type": "string",
                                        "description": "Download file name without the .zip extension. (default \"download\")"
                                    }
                                },
                                "required": [
                                    "paths"
                                ]
                            },
                            "example": {
                                "paths": [
                                    "/shared/storage/app",
                                    "/shared/.env"
                                ],
                                "name": "shop-files"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/files/mkdir": {
            "post": {
                "operationId": "filemanagerMkdir",
                "summary": "Create a directory",
                "description": "Creates a directory (and any missing parents, like mkdir -p) inside the site root.\n\n**Roles:** admin, developer (with access to the site).\n\n- Succeeds silently when the directory already exists (recursive mkdir).",
                "tags": [
                    "File manager"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The directory exists.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nNon-admin caller without a grant for this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role. — \"Forbidden: viewer role is read-only\"\n\nThe resolved path is outside the site root. — \"Path traversal denied\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "path": {
                                        "type": "string",
                                        "description": "Directory path relative to the site root. (jailed to the site root)"
                                    }
                                },
                                "required": [
                                    "path"
                                ]
                            },
                            "example": {
                                "path": "/shared/storage/exports"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/files/move": {
            "post": {
                "operationId": "filemanagerMove",
                "summary": "Move paths into a directory",
                "description": "Moves each path into the destination directory, keeping its base name (mv src dest/<basename>).\n\n**Roles:** admin, developer (with access to the site).\n\n- Sources that fail the jail check or whose move fails are skipped silently; the response is still {\"ok\": true}.",
                "tags": [
                    "File manager"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Always ok once the destination passed the jail check.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nNon-admin caller without a grant for this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role. — \"Forbidden: viewer role is read-only\"\n\ndest resolves outside the site root. — \"Path traversal denied\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "paths": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Source paths relative to the site root. (array of strings; each jailed to the site root)"
                                    },
                                    "dest": {
                                        "type": "string",
                                        "description": "Destination directory relative to the site root. (jailed to the site root)"
                                    }
                                },
                                "required": [
                                    "paths",
                                    "dest"
                                ]
                            },
                            "example": {
                                "paths": [
                                    "/shared/storage/exports/report.csv"
                                ],
                                "dest": "/backups"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/files/properties": {
            "get": {
                "operationId": "filemanagerProperties",
                "summary": "Get file properties",
                "description": "Returns the metadata of one file or directory. For directories totalSize is the recursive disk usage in bytes (du -sb); for files it equals size.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- Uses lstat locally, so a symlink is reported as type symlink, not as its target.",
                "tags": [
                    "File manager"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "path",
                        "in": "query",
                        "required": true,
                        "description": "Path relative to the site root. (jailed to the site root)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The entry plus totalSize.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "name": "storage",
                                    "type": "dir",
                                    "size": 0,
                                    "modified": "2026-11-27T10:00:00.000Z",
                                    "permissions": "775",
                                    "permsDisplay": "rwxrwxr-x",
                                    "owner": "www-data",
                                    "group": "www-data",
                                    "ext": "",
                                    "mime": "application/octet-stream",
                                    "totalSize": 52428800
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The path query parameter is missing or empty. — \"path required\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "path required"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Non-admin caller without a grant for this site. — \"Forbidden: no access to this site\"\n\npath resolves outside the site root. — \"Path traversal denied\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "The path does not exist. — \"Not found\"\n\nNo site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/files/read": {
            "get": {
                "operationId": "filemanagerRead",
                "summary": "Read a file",
                "description": "Returns the content of a file inside the site root for inline viewing or editing. Text types are returned as UTF-8 text; everything else is returned base64-encoded with binary=true. Files larger than 10 MB are refused.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- binary is true when the extension's mime is not text/* and not application/json or application/xml; then content is base64.\n\n- The type comes from the extension only. Files without an extension — including dotfiles such as .env (path.extname('.env') is empty) — map to application/octet-stream and are therefore returned base64-encoded with binary=true. SVG (image/svg+xml) is also returned as base64.\n\n- path in the response echoes the query value as given, not a normalised path.",
                "tags": [
                    "File manager"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "path",
                        "in": "query",
                        "required": true,
                        "description": "File path relative to the site root. (jailed to the site root)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The file content and its detected type.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "content": "APP_NAME=Shop\nAPP_ENV=production\n",
                                    "ext": "txt",
                                    "mime": "text/plain",
                                    "size": 34,
                                    "binary": false,
                                    "path": "/shared/notes.txt"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The path query parameter is missing or empty. — \"path required\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "path required"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Non-admin caller without a grant for this site. — \"Forbidden: no access to this site\"\n\nThe resolved path is outside the site root. — \"Path traversal denied\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "The path does not exist or is not a regular file. — \"File not found\"\n\nNo site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "File not found"
                                }
                            }
                        }
                    },
                    "413": {
                        "description": "The file is larger than 10 MB (10485760 bytes); the size in the message is the actual size. — \"File too large (12.4 MB). Max 10 MB for inline editing.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "File too large (12.4 MB). Max 10 MB for inline editing."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/files/rename": {
            "post": {
                "operationId": "filemanagerRename",
                "summary": "Rename or move one path",
                "description": "Renames a file or directory (mv), creating the destination's parent directory if needed. Both paths are relative to the site root.\n\n**Roles:** admin, developer (with access to the site).\n\n- A failing mv (e.g. source missing) is not caught and returns Fastify's default 500 error body.",
                "tags": [
                    "File manager"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The path was renamed.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nNon-admin caller without a grant for this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role. — \"Forbidden: viewer role is read-only\"\n\nEither path resolves outside the site root. — \"Path traversal denied\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "from": {
                                        "type": "string",
                                        "description": "Current path. (jailed to the site root)"
                                    },
                                    "to": {
                                        "type": "string",
                                        "description": "New path (full path, not just the new name). (jailed to the site root)"
                                    }
                                },
                                "required": [
                                    "from",
                                    "to"
                                ]
                            },
                            "example": {
                                "from": "/shared/notes.txt",
                                "to": "/shared/docs/notes.txt"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/files/search": {
            "get": {
                "operationId": "filemanagerSearch",
                "summary": "Search files",
                "description": "Searches below a directory of the site root, either by file name (case-insensitive substring, find -iname) or by content (grep -rl). Returns at most 100 matches.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- type in each result is always \"file\", even when a name search matches a directory.\n\n- The search command times out after 20 seconds; partial output collected so far is still returned.",
                "tags": [
                    "File manager"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "q",
                        "in": "query",
                        "required": false,
                        "description": "Search term. Empty or whitespace-only returns no results.",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "path",
                        "in": "query",
                        "required": false,
                        "description": "Directory to search in, relative to the site root. (default \"/\"; jailed to the site root)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "type",
                        "in": "query",
                        "required": false,
                        "description": "content searches file contents; any other value searches names. (one of: name, content; default name; not validated)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Matching paths relative to the site root.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "results": [
                                        {
                                            "path": "/shared/.env",
                                            "name": ".env",
                                            "type": "file"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Non-admin caller without a grant for this site. — \"Forbidden: no access to this site\"\n\npath resolves outside the site root. — \"Path traversal denied\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/files/tar": {
            "post": {
                "operationId": "filemanagerTar",
                "summary": "Create a tar.gz archive",
                "description": "Runs tar -czf from the site root to pack the given paths into a gzip-compressed tarball at dest.\n\n**Roles:** admin, developer (with access to the site).\n\n- Unlike zip, a failing tar is not caught and returns Fastify's default 500 error body.\n\n- Not audited. Timeout 5 minutes.",
                "tags": [
                    "File manager"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The archive was created.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nNon-admin caller without a grant for this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role. — \"Forbidden: viewer role is read-only\"\n\ndest resolves outside the site root. — \"Path traversal denied\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "paths": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Paths to include, relative to the site root. (array of strings; each jailed to the site root (invalid ones dropped))"
                                    },
                                    "dest": {
                                        "type": "string",
                                        "description": "Archive file path to create (e.g. /backups/site.tar.gz). (jailed to the site root)"
                                    }
                                },
                                "required": [
                                    "paths",
                                    "dest"
                                ]
                            },
                            "example": {
                                "paths": [
                                    "/shared"
                                ],
                                "dest": "/backups/shared.tar.gz"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/files/touch": {
            "post": {
                "operationId": "filemanagerTouch",
                "summary": "Create an empty file",
                "description": "Creates an empty file inside the site root (parent directories are created). Runs touch, so an existing file is kept and only its modification time is updated.\n\n**Roles:** admin, developer (with access to the site).",
                "tags": [
                    "File manager"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The file exists.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nNon-admin caller without a grant for this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role. — \"Forbidden: viewer role is read-only\"\n\nThe resolved path is outside the site root. — \"Path traversal denied\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "path": {
                                        "type": "string",
                                        "description": "File path relative to the site root. (jailed to the site root)"
                                    }
                                },
                                "required": [
                                    "path"
                                ]
                            },
                            "example": {
                                "path": "/shared/storage/logs/.gitkeep"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/files/untar": {
            "post": {
                "operationId": "filemanagerUntar",
                "summary": "Extract a tar archive",
                "description": "Extracts a tar archive (tar -xf, compression auto-detected) into the destination directory, which is created if missing.\n\n**Roles:** admin, developer (with access to the site).\n\n- ok is always true: a failing tar is reported only through output. Not audited. Timeout 5 minutes.",
                "tags": [
                    "File manager"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The combined stdout and stderr of tar.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "output": ""
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nNon-admin caller without a grant for this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role. — \"Forbidden: viewer role is read-only\"\n\npath or dest resolves outside the site root. — \"Path traversal denied\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "path": {
                                        "type": "string",
                                        "description": "Tar file relative to the site root. (jailed to the site root)"
                                    },
                                    "dest": {
                                        "type": "string",
                                        "description": "Target directory relative to the site root. (jailed to the site root)"
                                    }
                                },
                                "required": [
                                    "path",
                                    "dest"
                                ]
                            },
                            "example": {
                                "path": "/backups/shared.tar.gz",
                                "dest": "/restore"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/files/unzip": {
            "post": {
                "operationId": "filemanagerUnzip",
                "summary": "Extract a zip archive",
                "description": "Extracts a zip archive into the destination directory (created if missing), overwriting existing files (unzip -o).\n\n**Roles:** admin, developer (with access to the site).\n\n- ok is always true: a failing unzip is reported only through output. Timeout 5 minutes.\n\n- Entries inside the archive are extracted by unzip itself; the API does not check archive member paths.",
                "tags": [
                    "File manager"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The combined stdout and stderr of unzip.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "output": "Archive:  /var/www/shop.example.com/backups/storage.zip\n  inflating: /var/www/shop.example.com/restore/shared/storage/app/a.txt"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nNon-admin caller without a grant for this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role. — \"Forbidden: viewer role is read-only\"\n\npath or dest resolves outside the site root. — \"Path traversal denied\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "path": {
                                        "type": "string",
                                        "description": "Zip file relative to the site root. (jailed to the site root)"
                                    },
                                    "dest": {
                                        "type": "string",
                                        "description": "Target directory relative to the site root. (jailed to the site root)"
                                    }
                                },
                                "required": [
                                    "path",
                                    "dest"
                                ]
                            },
                            "example": {
                                "path": "/backups/storage.zip",
                                "dest": "/restore"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/files/upload": {
            "post": {
                "operationId": "filemanagerUpload",
                "summary": "Upload files",
                "description": "Accepts a multipart/form-data request and writes every file part into the destination directory (created if missing), streaming to the site's server. Returns a result per file.\n\n**Roles:** admin, developer (with access to the site).\n\n- One filemanager.upload audit entry is written per successfully stored file.\n\n- Per-file failures are returned in results with ok=false and the error message; the request itself still answers 200.\n\n- Uncertain: when a file exceeds the size limit, the truncated part may already have been written before the 413 is raised from the multipart iterator.",
                "tags": [
                    "File manager"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "dest",
                        "in": "query",
                        "required": false,
                        "description": "Destination directory relative to the site root. (default \"/\"; jailed to the site root)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "overwrite",
                        "in": "query",
                        "required": false,
                        "description": "Set to 0 to skip files that already exist; any other value (or omitted) overwrites. (default overwrite; only \"0\" disables it)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "One result per uploaded file.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "results": [
                                        {
                                            "filename": "logo.png",
                                            "ok": true,
                                            "size": 18234
                                        },
                                        {
                                            "filename": "robots.txt",
                                            "ok": false,
                                            "error": "File already exists"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nNon-admin caller without a grant for this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role. — \"Forbidden: viewer role is read-only\"\n\ndest resolves outside the site root. — \"Path traversal denied\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "406": {
                        "description": "The request is not multipart/form-data (@fastify/multipart FST_INVALID_MULTIPART_CONTENT_TYPE, Fastify error body). — \"the request is not multipart\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "the request is not multipart"
                                }
                            }
                        }
                    },
                    "413": {
                        "description": "A file exceeds 512 MB (@fastify/multipart FST_REQ_FILE_TOO_LARGE, Fastify error body). — \"request file too large\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "request file too large"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "multipart/form-data": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "files": {
                                        "type": "string",
                                        "format": "binary",
                                        "description": "One or more file parts. The web client uses the field name \"files\"; every file part is processed regardless of its field name. Only the base name of the part's filename is used. (max 512 MB per file (multipart fileSize limit); nginx client_max_body_size 512m for the whole request; max 1000 parts)"
                                    }
                                },
                                "required": [
                                    "files"
                                ]
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/files/write": {
            "put": {
                "operationId": "filemanagerWrite",
                "summary": "Write a file",
                "description": "Creates or overwrites a text file inside the site root with the given UTF-8 content. Missing parent directories are created.\n\n**Roles:** admin, developer (with access to the site).\n\n- No bodyLimit is configured on the Fastify instance, so a JSON body larger than 1 MiB is rejected with 413 FST_ERR_CTP_BODY_TOO_LARGE before the handler runs, even though the schema allows up to 10 MB of content.\n\n- Write failures (permissions, unreachable server) are not caught and surface as Fastify's default 500 error body.\n\n- Only text content is supported; there is no base64 input for binary files (use the upload endpoint).",
                "tags": [
                    "File manager"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The file was written.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nNon-admin caller without a grant for this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role. — \"Forbidden: viewer role is read-only\"\n\nThe resolved path is outside the site root. — \"Path traversal denied\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "path": {
                                        "type": "string",
                                        "description": "File path relative to the site root. (jailed to the site root)"
                                    },
                                    "content": {
                                        "type": "string",
                                        "description": "Full new file content (UTF-8 text). (max 10485760 chars by schema, but the JSON body is capped at Fastify's default 1 MiB bodyLimit)"
                                    }
                                },
                                "required": [
                                    "path",
                                    "content"
                                ]
                            },
                            "example": {
                                "path": "/shared/notes.txt",
                                "content": "Deployed by the ops team.\n"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/files/zip": {
            "post": {
                "operationId": "filemanagerZip",
                "summary": "Create a zip archive",
                "description": "Runs zip -r from the site root to pack the given paths into the archive at dest, and returns the command output. Paths are stored in the archive relative to the site root.\n\n**Roles:** admin, developer (with access to the site).\n\n- ok is always true: a failing zip is reported only through output. Timeout 5 minutes.",
                "tags": [
                    "File manager"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The combined stdout and stderr of zip.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "output": "adding: shared/storage/app/ (stored 0%)"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nNon-admin caller without a grant for this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role. — \"Forbidden: viewer role is read-only\"\n\ndest resolves outside the site root. — \"Path traversal denied\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "paths": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Paths to include, relative to the site root. (array of strings; each jailed to the site root (invalid ones dropped))"
                                    },
                                    "dest": {
                                        "type": "string",
                                        "description": "Archive file path to create, relative to the site root (e.g. /backups/site.zip). (jailed to the site root)"
                                    }
                                },
                                "required": [
                                    "paths",
                                    "dest"
                                ]
                            },
                            "example": {
                                "paths": [
                                    "/shared/storage/app"
                                ],
                                "dest": "/backups/storage.zip"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/logs": {
            "get": {
                "operationId": "logsGet",
                "summary": "Read the Laravel log",
                "description": "Reads the last ~2 MB of <rootPath>/shared/logs/laravel.log (falling back to <rootPath>/current/storage/logs/laravel.log) on the site's server, splits it into entries at each \"[YYYY-MM-DD\" line and returns them newest first, optionally filtered by level and text.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- Filters are applied after taking the newest `lines` entries, so total is the number of matches among those entries, not in the whole file.\n\n- An entry whose header cannot be parsed is returned as { timestamp: null, environment: null, level: \"unknown\", message }. message includes the stack trace lines.\n\n- When neither log file can be read the response is { entries: [], total: 0, path: <shared log path> }.\n\n- A non-numeric lines value makes the result empty (entries: []).\n\n- The tail is read through the shared exec helper whose output buffer is 1 MB; as written, a log file larger than about 1 MB exceeds that buffer, the read fails and the endpoint falls back to the other path or returns no entries (not verified at runtime).",
                "tags": [
                    "Logs and errors"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "level",
                        "in": "query",
                        "required": false,
                        "description": "Only entries with this level (case-insensitive), e.g. error, warning, info. (exact match against the parsed level; \"unknown\" matches unparseable entries)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "search",
                        "in": "query",
                        "required": false,
                        "description": "Only entries whose message contains this text (case-insensitive).",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "lines",
                        "in": "query",
                        "required": false,
                        "description": "How many of the newest entries to consider. (default 500, max 2000)",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Parsed log entries, newest first.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "entries": [
                                        {
                                            "timestamp": "2026-11-27 10:00:00",
                                            "environment": "production",
                                            "level": "error",
                                            "message": "SQLSTATE[HY000] [2002] Connection refused (SQL: select * from `users` where `id` = 42) {\"exception\":\"[object] (Illuminate\\\\Database\\\\QueryException(code: 2002): …\"}"
                                        }
                                    ],
                                    "total": 1,
                                    "path": "/var/www/shop.example.com/shared/logs/laravel.log"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            },
            "delete": {
                "operationId": "logsClear",
                "summary": "Clear the Laravel log",
                "description": "Truncates <rootPath>/shared/logs/laravel.log to an empty file on the site's server (or, if that write fails, <rootPath>/current/storage/logs/laravel.log).\n\n**Roles:** admin, developer (with access to the site).\n\n- The write creates the file (and missing folders) if it does not exist, so ok is normally true even without a prior log.\n\n- Returns { ok: false } with status 200 when both writes fail.\n\n- No audit entry is written.",
                "tags": [
                    "Logs and errors"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "ok is true when one of the files was emptied.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/maintenance": {
            "post": {
                "operationId": "maintenanceSet",
                "summary": "Turn maintenance mode on or off",
                "description": "Runs php artisan down (optionally with a bypass secret) or php artisan up in the site's current release on its server, then stores the new maintenanceMode flag.\n\n**Roles:** admin, developer (with access to the site).\n\n- Uses Laravel's artisan, so it only works for Laravel sites.",
                "tags": [
                    "Maintenance mode"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Command output.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "action": "down",
                                    "output": "INFO  Application is now in maintenance mode."
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "secret has other characters. — \"Secret may only contain letters, numbers, hyphen and underscore\"\n\nSite status is not \"active\". — \"Site is not active\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Secret may only contain letters, numbers, hyphen and underscore"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "The artisan command failed or timed out (15 s); maintenanceMode is not changed. — \"<artisan output or error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<artisan output or error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "action": {
                                        "type": "string",
                                        "description": "down enables maintenance mode, up disables it. (one of: down, up)"
                                    },
                                    "secret": {
                                        "type": "string",
                                        "description": "Bypass secret for artisan down --secret (visit https://<domain>/<secret> to bypass). Ignored for up. (max 128 chars, pattern ^[A-Za-z0-9_-]{1,128}$)"
                                    }
                                },
                                "required": [
                                    "action"
                                ]
                            },
                            "example": {
                                "action": "down",
                                "secret": "team-preview-2026"
                            }
                        }
                    }
                }
            },
            "get": {
                "operationId": "maintenanceGet",
                "summary": "Get maintenance mode state",
                "description": "Returns the maintenance-mode flag stored in the panel.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- This is the panel's stored flag, not a live check of the application (artisan down run outside the panel is not detected).",
                "tags": [
                    "Maintenance mode"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Stored flag.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "maintenanceMode": false
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/php-version": {
            "post": {
                "operationId": "configPhpVersionSwitch",
                "summary": "Switch PHP version",
                "description": "Switches the site to another installed PHP version: replaces php<old>-fpm.sock with php<new>-fpm.sock in the nginx vhost, tests and reloads nginx, then saves the new version on the site.\n\n**Roles:** admin, developer (with access to the site).\n\n- When the vhost does not exist yet, only the database is updated: {\"ok\": true, \"reloaded\": false, \"message\": \"PHP version updated to 8.4 in database. Re-provision to apply to nginx.\"}.\n\n- When the vhost has no php<old>-fpm.sock reference, only the database is updated: {\"ok\": true, \"reloaded\": false, \"message\": \"PHP version updated to 8.4. No socket reference found in nginx config — may need manual nginx update.\"}.\n\n- Only nginx is changed: the site's PHP-FPM pool file is not moved to the new version, supervisor/cron configs keep the old php binary until regenerated, and the change applies to the next deploy.\n\n- The vhost change is recorded in the nginx config history with note \"php-switch\".",
                "tags": [
                    "Configuration files"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Switched.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "reloaded": true,
                                    "message": "Switched to PHP 8.4 and reloaded nginx."
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "nginx -t failed after the edit; body also has \"details\". — \"Nginx config test failed — previous config restored.\"\n\nversion is not among the detected versions. — \"PHP 8.4 is not installed on this server.\"\n\nversion equals the current version (message contains it). — \"Site is already using PHP 8.4.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Nginx config test failed — previous config restored."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "Reload failed; the old vhost is put back and the DB is not changed. Body also has \"details\". — \"Nginx reload failed — reverted.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Nginx reload failed — reverted."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "version": {
                                        "type": "string",
                                        "description": "Target PHP version. (pattern ^\\d+\\.\\d+$; must be installed on the server)"
                                    }
                                },
                                "required": [
                                    "version"
                                ]
                            },
                            "example": {
                                "version": "8.4"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/php-versions": {
            "get": {
                "operationId": "configPhpVersions",
                "summary": "List installed PHP versions",
                "description": "Returns the site's PHP version and the PHP versions installed on the site's server (from /etc/php/<x.y>, update-alternatives, or which php8.0…php8.4).\n\n**Roles:** admin, developer, viewer (with access to the site).",
                "tags": [
                    "Configuration files"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Current and available versions.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "current": "8.3",
                                    "available": [
                                        "8.2",
                                        "8.3",
                                        "8.4"
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/phpfpm": {
            "get": {
                "operationId": "configPhpfpmGet",
                "summary": "Get PHP-FPM pool config",
                "description": "Returns the site's PHP-FPM pool file /etc/php/<phpVersion>/fpm/pool.d/<domain>.conf from the site's server. When it does not exist, a default pool template is returned with exists=false (nothing is written).\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- Characters other than letters, digits, \".\" and \"-\" in the domain are replaced by \"_\" in the file name.",
                "tags": [
                    "Configuration files"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Content, path and whether the file exists.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "content": "[shop.example.com]\nuser = www-data\ngroup = www-data\nlisten = /run/php/php8.3-fpm-shop.example.com.sock\npm = dynamic\npm.max_children = 10\n",
                                    "path": "/etc/php/8.3/fpm/pool.d/shop.example.com.conf",
                                    "exists": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            },
            "put": {
                "operationId": "configPhpfpmUpdate",
                "summary": "Save PHP-FPM pool config",
                "description": "Installs a new PHP-FPM pool file for the site (via sudo install), runs php-fpm<version> -t and reloads php<version>-fpm. A failing syntax test puts the previous file back (or removes the new one). The saved content is recorded in the config history.\n\n**Roles:** admin (with access to the site).\n\n- reloaded is false when the php-fpm reload failed; the file is still installed.\n\n- Admin only: pool settings (user, php_admin_value…) control how PHP runs.",
                "tags": [
                    "Configuration files"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Saved.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "reloaded": true,
                                    "path": "/etc/php/8.3/fpm/pool.d/shop.example.com.conf"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "content contains no \"[\" (no pool name). — \"Invalid PHP-FPM pool config\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid PHP-FPM pool config"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "The site's server could not be resolved or a command failed. — \"<error message>\"\n\nphp-fpm -t reported FAILED; the previous pool is restored. — \"Config syntax error: <php-fpm -t output>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "content": {
                                        "type": "string",
                                        "description": "Full file content. (1–20000 chars)"
                                    }
                                },
                                "required": [
                                    "content"
                                ]
                            },
                            "example": {
                                "content": "[shop.example.com]\nuser = www-data\ngroup = www-data\nlisten = /run/php/php8.3-fpm-shop.example.com.sock\npm = dynamic\npm.max_children = 10\n"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/preset-preview/{presetId}": {
            "get": {
                "operationId": "presetsPreview",
                "summary": "Preview applying a preset",
                "description": "Shows which of the site's settings applying the preset would change (with old and new values) and which already match. Read-only.\n\n**Roles:** admin, developer (with access to the site).\n\n- \"to\" values have {{domain}} already replaced by this site's domain. Unset site values appear as \"\" (strings) in \"from\"; tags are compared as arrays.",
                "tags": [
                    "Presets"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "presetId",
                        "in": "path",
                        "required": true,
                        "description": "Preset id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The diff.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "preset": {
                                        "id": 3,
                                        "name": "Laravel production"
                                    },
                                    "changes": [
                                        {
                                            "field": "runTests",
                                            "from": false,
                                            "to": true
                                        },
                                        {
                                            "field": "healthCheckUrl",
                                            "from": "",
                                            "to": "https://shop.example.com/up"
                                        }
                                    ],
                                    "unchanged": [
                                        "postDeploy",
                                        "healthCheck"
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is a viewer (only admin and developer may call this). — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No preset with this id. — \"Preset not found\"\n\nNo site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Preset not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/promote": {
            "post": {
                "operationId": "stagingPromote",
                "summary": "Promote staging to production",
                "description": "Called on the STAGING site. Deploys the production site at exactly the commit staging is on, through the normal deploy pipeline (tests, health check, atomic release switch and auto-rollback apply). Optionally takes a production database backup first. Never queues.\n\n**Roles:** admin (with access to the site).\n\n- The new production Deployment row carries comment \"Promoted from <staging domain> @ <short commit>\"; the deploy uses production's own repository token, branch, hooks and test settings and deploys the resolved full SHA as ref.\n\n- Follow the deploy with GET /api/sites/{productionId}/deploy/stream.\n\n- backupDb calls POST /api/sites/{productionId}/database/backup internally with the caller's Authorization header; backup is null in the response when not requested.\n\n- Error bodies other than the plain {\"error\"} ones carry a machine-readable \"code\" (and for 422/502 a \"details\" string).\n\n- site.promote_aborted is written only when the backup fails.\n\n- The body is optional; an empty JSON object is fine.",
                "tags": [
                    "Staging and promote"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Staging site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Production deploy started.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "started": true,
                                    "deploymentId": 353,
                                    "productionId": 12,
                                    "productionDomain": "shop.example.com",
                                    "commit": "c81e0b4",
                                    "backup": {
                                        "filename": "shop-2026-11-27-100000.sql.gz",
                                        "sizeBytes": 482113
                                    }
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The plan has a blocker. Body: {\"error\": <first blocker message>, \"code\": <blocker code>, \"blockers\": [...]}. Status per code: production_missing 404; staging_deploy_running, production_deploy_running, production_deploy_queued 409; all others 400. — \"<blocker message>\"\n\nid is not an integer. — \"Invalid site id\"\n\nNo production site or no staging commit (defensive). — \"Nothing to promote.\"\n\nProduction became inactive while the backup ran (code \"production_inactive\"). — \"The production site is not active.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<blocker message>"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "Production became busy while the backup ran (code \"production_deploy_running\"). — \"A deploy is already running or queued on the production site.\"\n\nRace with another deploy starting on production. — \"Deploy already in progress\"\n\nProduction is on the same commit and force is not true (code \"same_commit\"). — \"Production is already on this commit.\"\n\nexpectedCommit differs from the current staging commit (code \"plan_changed\"). — \"Staging has changed since you opened this dialog. Review the new commit and try again.\"\n\nStaging was rolled back and force is not true (code \"staging_rolled_back\"). — \"Staging was rolled back after its last deploy, so it is currently serving an older release than the commit that would be promoted.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "A deploy is already running or queued on the production site."
                                }
                            }
                        }
                    },
                    "422": {
                        "description": "The short hash could not be resolved to exactly one full SHA from the staging release checkouts or the remote refs (code \"commit_unresolved\", plus \"details\"). — \"Could not resolve the full commit hash for c81e0b4.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Could not resolve the full commit hash for c81e0b4."
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "backupDb=true and the backup failed or is under 64 bytes (code \"backup_failed\", plus \"details\"). — \"Production database backup failed — promote aborted. Nothing was deployed.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Production database backup failed — promote aborted. Nothing was deployed."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "force": {
                                        "type": "boolean",
                                        "description": "Promote even when production is already on this commit or staging was rolled back after deploying it."
                                    },
                                    "backupDb": {
                                        "type": "boolean",
                                        "description": "Back up the production database first; abort the promote when the backup fails or is empty."
                                    },
                                    "expectedCommit": {
                                        "type": "string",
                                        "description": "The staging commit shown in the preview. If staging has moved on since, the promote is refused. (max 64 chars)"
                                    }
                                }
                            },
                            "example": {
                                "backupDb": true,
                                "expectedCommit": "c81e0b4"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/promote/preview": {
            "get": {
                "operationId": "stagingPromotePreview",
                "summary": "Preview a promote",
                "description": "Called on the STAGING site. Shows what promoting would do: which commit staging is on, what production is on, and any blockers or warnings. Read-only.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- Commits are the short hashes of the newest successful non-rollback deployment of each site. differs is false only when production is known to be on the same commit (prefix match) and was not rolled back since.\n\n- Blocker codes (promote is refused): not_staging, production_missing, production_is_staging, production_inactive, no_repo, repo_mismatch, no_successful_deploy, staging_deploy_running, production_deploy_running, production_deploy_queued. Each item is {\"code\", \"message\"}.\n\n- Warning codes: staging_rolled_back, production_rolled_back, branch_differs.\n\n- When the site is not a staging copy, production is null and blockers contains not_staging (still 200).",
                "tags": [
                    "Staging and promote"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Staging site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The promote plan.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "staging": {
                                        "id": 15,
                                        "name": "Shop (staging)",
                                        "domain": "staging.shop.example.com",
                                        "branch": "main"
                                    },
                                    "production": {
                                        "id": 12,
                                        "name": "Shop",
                                        "domain": "shop.example.com",
                                        "branch": "main",
                                        "status": "active",
                                        "stackType": "laravel"
                                    },
                                    "stagingCommit": "c81e0b4",
                                    "stagingDeploymentId": 352,
                                    "stagingDeployedAt": "2026-11-27T10:00:00.000Z",
                                    "productionCommit": "a3f9c21",
                                    "productionDeployedAt": "2026-11-20T09:30:00.000Z",
                                    "differs": true,
                                    "blockers": [],
                                    "warnings": []
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "id is not an integer. — \"Invalid site id\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid site id"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/provision": {
            "post": {
                "operationId": "sitesProvision",
                "summary": "Provision a site",
                "description": "Starts provision.sh on the site's server in the background (directories, MySQL database and user, nginx vhost) and returns immediately. Optionally installs a fresh app of the chosen template afterwards (1-click install). Follow progress with the provision stream.\n\n**Roles:** admin, developer (with access to the site).\n\n- Status flow: the site is set to \"provisioning\" (and dbName, dbUser, stackType are saved) before the script starts; on success it becomes \"active\", on any failure \"error\".\n\n- On success a primary SiteDatabase row is registered and, if Cloudflare is configured in settings, an A record for the domain is created (best effort; result appears in the log).\n\n- For template=node a loopback port 3000 + siteId is assigned to the app.\n\n- If installApp fails after a successful base provision, the site ends in \"error\" even though the vhost and database exist.\n\n- Provisioning state is in memory: an API restart loses the running provision and its log.",
                "tags": [
                    "Sites"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Provisioning started.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "started": true,
                                    "siteId": 12
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "template=wordpress, installApp=true and wpAdminEmail or wpAdminPass is missing. — \"WordPress install requires an admin email and password.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "WordPress install requires an admin email and password."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "A provision for this site is already running in this API process (checked before the site lookup). — \"Provisioning already running for this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Provisioning already running for this site"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "The site's server could not be resolved or the scripts could not be synced to it; the site status is put back to \"pending\". — \"Could not reach target server: <reason>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Could not reach target server: <reason>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "dbName": {
                                        "type": "string",
                                        "description": "MySQL database name to create. (1–64 chars, pattern ^[a-zA-Z0-9_]+$)"
                                    },
                                    "dbUser": {
                                        "type": "string",
                                        "description": "MySQL user to create. (1–32 chars, pattern ^[a-zA-Z0-9_]+$)"
                                    },
                                    "dbPassword": {
                                        "type": "string",
                                        "description": "Password for the MySQL user. Not stored by the panel. (8–128 chars, no ' \" \\ or backtick)"
                                    },
                                    "template": {
                                        "type": "string",
                                        "description": "Stack to provision; also stored as the site's stackType. (one of: laravel, wordpress, static, node; default laravel)"
                                    },
                                    "installApp": {
                                        "type": "boolean",
                                        "description": "Install a fresh app of the template after the base provision. (default false)"
                                    },
                                    "siteTitle": {
                                        "type": "string",
                                        "description": "WordPress site title (template=wordpress and installApp only). Defaults to the site name, then the domain. (max 120 chars, no ' \" \\ backtick $ or newline)"
                                    },
                                    "wpAdminUser": {
                                        "type": "string",
                                        "description": "WordPress admin username. Defaults to \"admin\". (max 60 chars, pattern ^[A-Za-z0-9_.@ -]+$)"
                                    },
                                    "wpAdminEmail": {
                                        "type": "string",
                                        "description": "WordPress admin email. Required when template=wordpress and installApp=true. (max 120 chars, pattern ^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$)"
                                    },
                                    "wpAdminPass": {
                                        "type": "string",
                                        "description": "WordPress admin password. Required when template=wordpress and installApp=true. (8–128 chars, no ' \" \\ backtick $ or space)"
                                    }
                                },
                                "required": [
                                    "dbName",
                                    "dbUser",
                                    "dbPassword"
                                ]
                            },
                            "example": {
                                "dbName": "shop",
                                "dbUser": "shop",
                                "dbPassword": "S3cure-pass-2026",
                                "template": "laravel",
                                "installApp": false
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/provision/stream": {
            "get": {
                "operationId": "sitesProvisionStream",
                "summary": "Stream provisioning log",
                "description": "Server-Sent Events stream of the provisioning output. Replays the buffered output first, then streams new output live and ends with a done event.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n**Streams** Server-Sent Events.\n\n- Each event is a single \"data: <JSON>\" line followed by a blank line. Output events: data: {\"line\":\"<chunk>\"} where <chunk> is a raw stdout/stderr chunk of the script (may hold several lines or a partial line, newlines included).\n\n- End of stream: data: {\"done\":true,\"status\":\"active\"} (success) or {\"done\":true,\"status\":\"error\"}, after which the server closes the connection.\n\n- If no provision is running for the site, the server sends the buffered output (kept for 30 minutes after a run finishes, if any) and then immediately {\"done\":true,\"status\":\"<current site.status>\"} — e.g. \"pending\", \"active\" or \"error\" — and closes.\n\n- A comment line \": ka\" is sent every 20 s as keep-alive while waiting.\n\n- Authenticate with the Authorization header (Bearer JWT or personal access token); the browser EventSource API cannot set it, the web client uses fetch() and parses the stream itself.",
                "tags": [
                    "Sites"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "SSE stream of {\"line\"} events followed by one {\"done\"} event.",
                        "content": {
                            "text/event-stream": {
                                "schema": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/queue/stats": {
            "get": {
                "operationId": "queueStats",
                "summary": "Get queue counts",
                "description": "Counts rows in the Laravel jobs and failed_jobs tables through artisan tinker. Read-only.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- Both values are null when tinker fails or the database queue tables do not exist (e.g. redis or sync queue drivers).\n\n- Timeout 15 seconds.",
                "tags": [
                    "Queue"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Pending and failed job counts.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "pending": 3,
                                    "failed": 1
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/releases": {
            "get": {
                "operationId": "deploymentsReleases",
                "summary": "List releases",
                "description": "Lists the release directories under <rootPath>/releases on the site's server, newest first, and which one the \"current\" symlink points to. These names are what the rollback endpoint accepts.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- Release names are deploy timestamps in the form YYYYMMDDHHMMSS (server time); deploy.sh keeps the 5 most recent releases.\n\n- createdAt is the directory birth time on the local server and its modification time on a remote server.\n\n- Any read error returns {\"releases\": [], \"current\": \"\"} instead of an error.",
                "tags": [
                    "Deployments"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Releases and the current one.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "releases": [
                                        {
                                            "name": "20261127100000",
                                            "isCurrent": true,
                                            "createdAt": "2026-11-27T10:00:00.000Z"
                                        },
                                        {
                                            "name": "20261120093000",
                                            "isCurrent": false,
                                            "createdAt": "2026-11-20T09:30:00.000Z"
                                        }
                                    ],
                                    "current": "20261127100000"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/rollback": {
            "post": {
                "operationId": "deploymentsRollback",
                "summary": "Roll back to a release",
                "description": "Points the site's \"current\" symlink at an earlier release directory and sends queue:restart, in the background. Creates a deployment row (branch \"rollback\", commit = release name) that ends as success or failed; follow it with the deploy stream.\n\n**Roles:** admin, developer (with access to the site).\n\n- Only the symlink is switched: no build, migrations or hooks run, and the database is not rolled back.\n\n- php<version> artisan queue:restart is attempted for every stack; its failure is only logged (\"⚠  queue:restart failed\") and does not fail the rollback.\n\n- The site status is not checked (unlike deploy).\n\n- The rollback deployment row shows up in the deployment history with branch \"rollback\" and commit set to the release name, and counts as a successful deployment in some views.",
                "tags": [
                    "Deployments"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Rollback started.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "started": true,
                                    "deploymentId": 348
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No such directory under <rootPath>/releases (message contains the requested name). — \"Release 20261120093000 not found.\"\n\nNo site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Release 20261120093000 not found."
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "A deploy or rollback is running for the site. Rollbacks are never queued. — \"A deploy / rollback is already running.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "A deploy / rollback is already running."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "release": {
                                        "type": "string",
                                        "description": "Release directory name from GET /api/sites/{id}/releases. (14 digits (pattern ^\\d{14}$))"
                                    }
                                },
                                "required": [
                                    "release"
                                ]
                            },
                            "example": {
                                "release": "20261120093000"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/scheduler": {
            "get": {
                "operationId": "schedulerGet",
                "summary": "Get Laravel scheduler state",
                "description": "Reports whether the site's scheduler cron file exists on the site's server, its path, and the content the panel writes when enabling it.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- cronContent is the template the panel would write, not the file's actual content.\n\n- The path replaces every character other than letters, digits and \"-\" in the domain with \"-\" (/etc/cron.d/<domain>-scheduler).",
                "tags": [
                    "Workers and scheduler"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Scheduler state.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "active": true,
                                    "cronPath": "/etc/cron.d/shop-example-com-scheduler",
                                    "cronContent": "# Laravel Scheduler — managed by Orchestrator\nSHELL=/bin/bash\nPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n* * * * * www-data php8.3 \"/var/www/sites/shop.example.com/current/artisan\" schedule:run >> /dev/null 2>&1\n"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            },
            "put": {
                "operationId": "schedulerEnable",
                "summary": "Enable Laravel scheduler",
                "description": "Installs the scheduler cron file (php<version> artisan schedule:run every minute as www-data) on the site's server via sudo install.\n\n**Roles:** admin, developer (with access to the site).\n\n- No request body is read (the web client sends {}).",
                "tags": [
                    "Workers and scheduler"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Enabled.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "cronPath": "/etc/cron.d/shop-example-com-scheduler"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "Writing or installing the file failed. — \"Failed to write cron file: <reason>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Failed to write cron file: <reason>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            },
            "delete": {
                "operationId": "schedulerDisable",
                "summary": "Disable Laravel scheduler",
                "description": "Removes the scheduler cron file from the site's server via sudo rm -f.\n\n**Roles:** admin, developer (with access to the site).\n\n- Errors while removing are ignored: the response is always {\"ok\": true} (and the audit entry written) once the site exists.",
                "tags": [
                    "Workers and scheduler"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Disabled.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/security": {
            "get": {
                "operationId": "siteSecurityGet",
                "summary": "Get site access protection",
                "description": "Returns the site's nginx access protection: HTTP basic auth (username, never the password hash) and the IP allow/deny list.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- ipMode is \"allow\", \"deny\" or null (off).\n\n- hasPassword is derived from whether a username is set (!!basicUser), not from the stored hash.",
                "tags": [
                    "Status pages and site security"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Current protection settings.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "basicAuth": true,
                                    "basicUser": "preview",
                                    "hasPassword": true,
                                    "ipMode": "allow",
                                    "ipList": [
                                        "203.0.113.10",
                                        "198.51.100.0/24"
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "siteSecuritySet",
                "summary": "Set site access protection",
                "description": "Merges the given fields onto the current settings, applies them to nginx with scripts/site-security.sh (snippet + htpasswd file under /etc/nginx/orchestrator-security, backed up, checked with nginx -t and rolled back on failure), and stores them only after nginx accepted them.\n\n**Roles:** admin (with access to the site).\n\n- Omitted fields keep their current value. ipMode \"off\" is stored and returned as null.\n\n- With ipMode \"allow\" the snippet is the listed \"allow\" lines followed by \"deny all;\". An empty ipList adds no IP rules regardless of ipMode.\n\n- Only IPv4 is accepted; IPv6 addresses are rejected with 400.\n\n- The script runs on the panel host (scripts/site-security.sh, local execFile), not through the site's server connection; sites on remote servers are not handled specially by this route.\n\n- The 500 error body uses the key \"detail\", not \"details\".\n\n- Audit meta: { basicAuth, ipMode }.",
                "tags": [
                    "Status pages and site security"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The settings now in effect.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "basicAuth": true,
                                    "basicUser": "preview",
                                    "hasPassword": true,
                                    "ipMode": "allow",
                                    "ipList": [
                                        "203.0.113.10",
                                        "198.51.100.0/24"
                                    ]
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "An ipList entry is not an IPv4 address or IPv4 CIDR. — \"Invalid IP/CIDR: <value>\"\n\nBasic auth would be enabled without both a username and a stored/new password. — \"Set a username and password to enable basic auth.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid IP/CIDR: <value>"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "The apply script failed or nginx -t rejected the config; the body also has \"detail\" (singular) with up to 500 chars of stderr. — \"nginx did not accept the security config (no changes applied to the live site).\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "nginx did not accept the security config (no changes applied to the live site)."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "basicAuth": {
                                        "type": "boolean",
                                        "description": "Enable HTTP basic auth."
                                    },
                                    "basicUser": {
                                        "type": "string",
                                        "description": "Basic auth username; an empty string clears it. (max 64 chars)"
                                    },
                                    "basicPassword": {
                                        "type": "string",
                                        "description": "New basic auth password (stored as a bcrypt hash). Omit or send empty to keep the current one. (max 128 chars)"
                                    },
                                    "ipMode": {
                                        "type": "string",
                                        "description": "\"allow\" = only listed IPs may access (everything else denied), \"deny\" = listed IPs are blocked, \"off\" = no IP rules. (one of: allow, deny, off)"
                                    },
                                    "ipList": {
                                        "type": "array",
                                        "items": {},
                                        "description": "IPv4 addresses or CIDR ranges. (max 100 items, each max 43 chars; IPv4 or IPv4/CIDR (prefix 0–32) only)"
                                    }
                                }
                            },
                            "example": {
                                "basicAuth": true,
                                "basicUser": "preview",
                                "basicPassword": "a-long-test-password",
                                "ipMode": "allow",
                                "ipList": [
                                    "203.0.113.10",
                                    "198.51.100.0/24"
                                ]
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/ssl": {
            "get": {
                "operationId": "sslGet",
                "summary": "Get certificate status",
                "description": "Runs certbot certificates --cert-name <domain> on the site's server and returns the certificate's expiry, issuer and names, plus the site's sslEnabled flag and whether a certbot run is in progress.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- When no certificate is found: active false, expiresAt/issuer/daysLeft null, domains [].\n\n- expiresAt is certbot's own \"Expiry Date\" text (not ISO 8601). issuer is parsed from an \"Issuer:\" line, which certbot certificates normally does not print, so it is usually null. daysLeft is floored and never below 0.",
                "tags": [
                    "SSL"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Certificate status.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "active": true,
                                    "expiresAt": "2027-02-25 10:00:00+00:00",
                                    "issuer": null,
                                    "daysLeft": 90,
                                    "domains": [
                                        "shop.example.com",
                                        "www.shop.example.com"
                                    ],
                                    "sslEnabled": true,
                                    "running": false
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "sslIssue",
                "summary": "Issue a certificate",
                "description": "Starts certbot --nginx for the site's domain (plus www.<domain> when that name resolves in DNS) with --expand, --agree-tos and --redirect. On success the site's sslEnabled flag is set to true.\n\n**Roles:** admin, developer (with access to the site).\n\n- The call returns immediately; certbot keeps running in the background. Follow its output with GET /api/sites/{id}/ssl/stream.\n\n- Audit is written when certbot exits, without the calling user: \"ssl.issued\" on success, \"ssl.issue_failed\" otherwise. Meta: { domain }.\n\n- The Let's Encrypt account email is the notify_email setting when it looks valid (not localhost/.local/.internal/.test/.invalid); otherwise certbot registers without an email.\n\n- Only one certbot run per site at a time (in-memory lock shared by issue, renew, remove and the host add/remove routes); the lock and log are lost on API restart.\n\n- Send the POST without a JSON Content-Type header (no body).",
                "tags": [
                    "SSL"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "certbot was started.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "started": true
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Site status is not \"active\". — \"Site must be active before issuing SSL.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site must be active before issuing SSL."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "Another certbot run for this site is in progress. — \"Certbot is already running for this site.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Certbot is already running for this site."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            },
            "delete": {
                "operationId": "sslDelete",
                "summary": "Delete the certificate",
                "description": "Runs certbot delete --cert-name <domain> on the site's server (best-effort: failures are ignored) and sets the site's sslEnabled flag to false. The call waits for certbot.\n\n**Roles:** admin, developer (with access to the site).\n\n- The certificate is deleted, not revoked at Let's Encrypt. The nginx vhost is not rewritten by this route.\n\n- Always returns { ok: true } once the site exists, even when certbot failed.\n\n- The audit entry is written without the calling user. Meta: { domain }.",
                "tags": [
                    "SSL"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The certificate was removed (or was already gone).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "Another certbot run for this site is in progress. — \"Certbot is already running for this site.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Certbot is already running for this site."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/ssl/hosts": {
            "get": {
                "operationId": "sslHostsList",
                "summary": "List hostnames and coverage",
                "description": "Lists every hostname of the site's nginx vhost (primary domain first, then vhost order, then names that are only on the certificate) with whether nginx serves it, over HTTPS, with which certificate, whether the certificate covers it and whether it resolves in DNS.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- cert is \"site\" (the server block uses /live/<domain>/ certificate), \"other\" (another certificate) or \"none\".\n\n- dns is true when the name has an A, AAAA or CNAME record (looked up from the panel host). Wildcard / regex server_names are skipped.\n\n- The vhost read is /etc/nginx/sites-available/<domain>; an unreadable vhost gives an empty block list.",
                "tags": [
                    "SSL"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Per-hostname certificate coverage.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "certActive": true,
                                    "certName": "shop.example.com",
                                    "running": false,
                                    "hosts": [
                                        {
                                            "host": "shop.example.com",
                                            "primary": true,
                                            "inNginx": true,
                                            "https": true,
                                            "cert": "site",
                                            "covered": true,
                                            "dns": true
                                        },
                                        {
                                            "host": "admin.shop.example.com",
                                            "primary": false,
                                            "inNginx": true,
                                            "https": false,
                                            "cert": "none",
                                            "covered": false,
                                            "dns": true
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/ssl/hosts/add": {
            "post": {
                "operationId": "sslHostsAdd",
                "summary": "Add a hostname to the certificate",
                "description": "Re-issues the site's certificate (cert name = site domain) with one more hostname via certbot --nginx --cert-name <domain> -d … --redirect. The hostname must already be in a server_name of the site's vhost and resolve in DNS.\n\n**Roles:** admin, developer (with access to the site).\n\n- The call returns immediately; certbot keeps running in the background. Follow its output with GET /api/sites/{id}/ssl/stream.\n\n- Audit is written when certbot exits, with the calling user: \"ssl.host_added\" on success, \"ssl.host_change_failed\" otherwise. Meta: { domain, host, action, names }.\n\n- Before certbot runs, the current vhost is saved to the config history (kind nginx); on success the vhost certbot leaves behind is saved too (note: SSL change).\n\n- On success the site's sslEnabled flag is set to true.\n\n- The first stream line is the command echo \"$ certbot --nginx --cert-name <domain> -d <name> …\".\n\n- Declared in a loop over [\"add\", \"remove\"] at routes/ssl.ts:295-296.\n\n- Only one certbot run per site at a time (in-memory lock shared by issue, renew, remove and the host add/remove routes); the lock and log are lost on API restart.",
                "tags": [
                    "SSL"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "certbot was started; names is the full list the certificate will cover.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "started": true,
                                    "names": [
                                        "shop.example.com",
                                        "www.shop.example.com",
                                        "admin.shop.example.com"
                                    ]
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The resulting name list is longer than 100. — \"A certificate can cover at most 100 hostnames.\"\n\nhost is not a plain fully-qualified hostname. — \"Invalid hostname.\"\n\nThe site has no active certificate. — \"Issue the site certificate first, then add hostnames to it.\"\n\nSite status is not \"active\". — \"Site must be active before issuing SSL.\"\n\nhost is already on the certificate. — \"The certificate already covers this hostname.\"\n\nhost has no A, AAAA or CNAME record. — \"This hostname does not resolve in DNS yet. Create its DNS record, wait until it is live, then try again.\"\n\nNo server block of the vhost lists host. — \"This hostname is not in the site's nginx config. Add it to a server_name line first (Config tab).\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "A certificate can cover at most 100 hostnames."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "Another certbot run for this site is in progress. — \"Certbot is already running for this site.\"\n\nThe host's server block uses another certificate. — \"The server block of this hostname uses a different certificate. Point it at the site certificate in the nginx config first.\"\n\nThe certificate holds a wildcard or other non-plain name. — \"This certificate contains wildcard names and was not issued by the panel. Manage its hostnames with certbot on the server.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Certbot is already running for this site."
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "Spawning certbot failed; \"details\" holds the error message. — \"Could not start certbot.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Could not start certbot."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "host": {
                                        "type": "string",
                                        "description": "Hostname (trimmed and lower-cased before use). (3–253 chars; must be a plain fully-qualified hostname (no wildcard))"
                                    }
                                },
                                "required": [
                                    "host"
                                ]
                            },
                            "example": {
                                "host": "admin.shop.example.com"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/ssl/hosts/remove": {
            "post": {
                "operationId": "sslHostsRemove",
                "summary": "Remove a hostname from the certificate",
                "description": "Re-issues the site's certificate (cert name = site domain) without one hostname via certbot --nginx --cert-name <domain> -d …. The site's main domain cannot be removed.\n\n**Roles:** admin, developer (with access to the site).\n\n- The call returns immediately; certbot keeps running in the background. Follow its output with GET /api/sites/{id}/ssl/stream.\n\n- Audit is written when certbot exits, with the calling user: \"ssl.host_removed\" on success, \"ssl.host_change_failed\" otherwise. Meta: { domain, host, action, names }.\n\n- Before certbot runs, the current vhost is saved to the config history (kind nginx); on success the vhost certbot leaves behind is saved too (note: SSL change).\n\n- On success the site's sslEnabled flag is set to true.\n\n- The first stream line is the command echo \"$ certbot --nginx --cert-name <domain> -d <name> …\".\n\n- Declared in a loop over [\"add\", \"remove\"] at routes/ssl.ts:295-296.\n\n- Only one certbot run per site at a time (in-memory lock shared by issue, renew, remove and the host add/remove routes); the lock and log are lost on API restart.",
                "tags": [
                    "SSL"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "certbot was started; names is the full list the certificate will cover.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "started": true,
                                    "names": [
                                        "shop.example.com",
                                        "www.shop.example.com"
                                    ]
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The resulting name list is longer than 100. — \"A certificate can cover at most 100 hostnames.\"\n\nhost is not a plain fully-qualified hostname. — \"Invalid hostname.\"\n\nThe site has no active certificate. — \"Issue the site certificate first, then add hostnames to it.\"\n\nSite status is not \"active\". — \"Site must be active before issuing SSL.\"\n\nhost is not on the certificate. — \"The certificate does not cover this hostname.\"\n\nhost equals the site's domain. — \"The site's main domain cannot be removed from its certificate.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "A certificate can cover at most 100 hostnames."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "Another certbot run for this site is in progress. — \"Certbot is already running for this site.\"\n\nThe certificate holds a wildcard or other non-plain name. — \"This certificate contains wildcard names and was not issued by the panel. Manage its hostnames with certbot on the server.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Certbot is already running for this site."
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "Spawning certbot failed; \"details\" holds the error message. — \"Could not start certbot.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Could not start certbot."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "host": {
                                        "type": "string",
                                        "description": "Hostname (trimmed and lower-cased before use). (3–253 chars; must be a plain fully-qualified hostname (no wildcard))"
                                    }
                                },
                                "required": [
                                    "host"
                                ]
                            },
                            "example": {
                                "host": "admin.shop.example.com"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/ssl/renew": {
            "post": {
                "operationId": "sslRenew",
                "summary": "Force-renew the certificate",
                "description": "Starts certbot renew --cert-name <domain> --force-renewal on the site's server.\n\n**Roles:** admin, developer (with access to the site).\n\n- The call returns immediately; certbot keeps running in the background. Follow its output with GET /api/sites/{id}/ssl/stream.\n\n- Audit is written when certbot exits, without the calling user: \"ssl.renewed\" on success, \"ssl.renew_failed\" otherwise. Meta: { domain }.\n\n- Repeated forced renewals count against Let's Encrypt rate limits.\n\n- Only one certbot run per site at a time (in-memory lock shared by issue, renew, remove and the host add/remove routes); the lock and log are lost on API restart.",
                "tags": [
                    "SSL"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "certbot was started.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "started": true
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The site's sslEnabled flag is false. — \"SSL is not enabled for this site.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "SSL is not enabled for this site."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "Another certbot run for this site is in progress. — \"Certbot is already running for this site.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Certbot is already running for this site."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/ssl/stream": {
            "get": {
                "operationId": "sslStream",
                "summary": "Stream certbot output",
                "description": "Server-Sent Events stream of the site's current certbot run (issue, renew, host add/remove). Buffered output is replayed first, then live lines follow until certbot exits.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n**Streams** Server-Sent Events.\n\n- Events (all unnamed, data only): {\"line\": \"<raw certbot stdout/stderr chunk>\"} for output (a chunk may contain several lines or a partial line); {\"done\": true, \"status\": \"success\" | \"failed\"} when certbot exits — the server then closes the stream.\n\n- When no certbot run is in progress, the stream replays the log of the last run (kept 10 minutes after it ended) and then sends {\"done\": true, \"status\": \"unknown\"} and closes. The real final status of a finished run is not repeated.\n\n- A comment line \": ka\" is sent every 20 seconds as keep-alive. Headers: Cache-Control: no-cache, X-Accel-Buffering: no.\n\n- The site id is not checked for existence (no 404).\n\n- Authenticate with the Authorization header (the web client uses fetch with a Bearer token, not EventSource), so personal access tokens work.",
                "tags": [
                    "SSL"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "SSE stream; each event is a \"data: <JSON>\" line.",
                        "content": {
                            "text/event-stream": {
                                "schema": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/staging": {
            "post": {
                "operationId": "stagingCreate",
                "summary": "Create a staging copy",
                "description": "Creates a staging copy of the site at staging.<domain> (status \"pending\") with the same repository, branch, hooks, stack and server, and stagingOf set to the source site. Only the panel record is created; provision and deploy it with the normal endpoints.\n\n**Roles:** admin, developer (with access to the site).\n\n- No request body. Send this request without a body (or with a JSON body such as {}). Sending Content-Type: application/json with an empty body is rejected by Fastify with 400 FST_ERR_CTP_EMPTY_JSON_BODY.\n\n- Copied: phpVersion, stackType, repoUrl, branch, preDeploy, postDeploy, serverId. healthCheck is forced to false and tags is set to [\"staging\"].\n\n- Not copied: gitToken (set one with PATCH /api/sites/{id} before deploying a private repository), webhookToken, healthCheckUrl, test settings, database settings.\n\n- Enable basic auth on the staging site if the preview must not be public; this endpoint does not do it.",
                "tags": [
                    "Staging and promote"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Production (source) site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "201": {
                        "description": "The staging site.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 15,
                                    "name": "Shop (staging)",
                                    "domain": "staging.shop.example.com",
                                    "serverId": null,
                                    "phpVersion": "8.3",
                                    "stackType": "laravel",
                                    "stagingOf": 12,
                                    "dbName": null,
                                    "dbUser": null,
                                    "sslEnabled": false,
                                    "rootPath": "/var/www/sites/staging.shop.example.com",
                                    "status": "pending",
                                    "repoUrl": "https://github.com/example/shop.git",
                                    "branch": "main",
                                    "webhookToken": null,
                                    "preDeploy": null,
                                    "postDeploy": "php artisan optimize",
                                    "healthCheck": false,
                                    "healthCheckUrl": null,
                                    "runTests": false,
                                    "testCommand": "php artisan test",
                                    "testFailureMode": "block",
                                    "testTimeout": 300,
                                    "testUseSqlite": true,
                                    "deployQueued": false,
                                    "maintenanceMode": false,
                                    "uptimeMonitor": true,
                                    "statusPageEnabled": false,
                                    "statusPageToken": null,
                                    "secBasicAuth": false,
                                    "secBasicUser": null,
                                    "secBasicHash": null,
                                    "secIpMode": null,
                                    "secIpList": null,
                                    "pinned": false,
                                    "disabled": false,
                                    "tags": "[\"staging\"]",
                                    "notes": null,
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z",
                                    "trafficLog": false,
                                    "hasGitToken": false
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The source site itself has stagingOf set. — \"This site is already a staging copy.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "This site is already a staging copy."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Source site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Source site not found"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "A site with domain staging.<domain> already exists (message contains the actual domain). — \"A site for staging.shop.example.com already exists.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "A site for staging.shop.example.com already exists."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/staging-copies": {
            "get": {
                "operationId": "stagingCopies",
                "summary": "List staging copies",
                "description": "Lists the staging copies of a production site (sites whose stagingOf is this id), oldest first, each with the commit of its last successful deploy.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- lastCommit / lastDeployedAt come from the newest successful non-rollback deployment (null if none).\n\n- No 404: an unknown id returns {\"copies\": []}.",
                "tags": [
                    "Staging and promote"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Production site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Staging copies.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "copies": [
                                        {
                                            "id": 15,
                                            "name": "Shop (staging)",
                                            "domain": "staging.shop.example.com",
                                            "status": "active",
                                            "branch": "main",
                                            "lastCommit": "c81e0b4",
                                            "lastDeployedAt": "2026-11-27T10:00:00.000Z"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "id is not an integer. — \"Invalid site id\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid site id"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/status-page": {
            "get": {
                "operationId": "statusPageGet",
                "summary": "Get status page settings",
                "description": "Returns whether the site's public status page is enabled, its token and its public URL (<panel_url>/status/<token>, or a relative /status/<token> when panel_url is not set).\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- token and url are null until the page has been enabled once.\n\n- The public data behind the page is served by GET /api/public/status/{token} (no auth).",
                "tags": [
                    "Status pages and site security"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Status page settings.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "enabled": true,
                                    "token": "3f9a1c7e5b2d8f40a6c1e9b7",
                                    "url": "https://panel.example.com/status/3f9a1c7e5b2d8f40a6c1e9b7"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "statusPageSet",
                "summary": "Enable or disable the status page",
                "description": "Turns the site's public status page on or off. The first time it is enabled a random 24-hex-character token is generated; the token stays the same afterwards, also when the page is disabled and enabled again.\n\n**Roles:** admin, developer (with access to the site).\n\n- There is no way to rotate the token through this endpoint.\n\n- Disabling before it was ever enabled returns token: null, url: null.\n\n- Audit meta: { enabled }.",
                "tags": [
                    "Status pages and site security"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The new settings.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "enabled": true,
                                    "token": "3f9a1c7e5b2d8f40a6c1e9b7",
                                    "url": "https://panel.example.com/status/3f9a1c7e5b2d8f40a6c1e9b7"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "enabled": {
                                        "type": "boolean",
                                        "description": "true to publish the status page, false to hide it."
                                    }
                                },
                                "required": [
                                    "enabled"
                                ]
                            },
                            "example": {
                                "enabled": true
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/supervisor": {
            "get": {
                "operationId": "workersSupervisorGet",
                "summary": "Get queue worker config",
                "description": "Returns the site's supervisor config /etc/supervisor/conf.d/<domain>-worker.conf from the site's server. When it does not exist, a default Laravel queue:work template (2 processes, redis) is returned instead (nothing is written).\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- The response does not say whether the content is the real file or the template.",
                "tags": [
                    "Workers and scheduler"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Content and path.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "content": "[program:shop.example.com-worker]\ncommand=php8.3 /var/www/sites/shop.example.com/current/artisan queue:work redis --sleep=3 --tries=3 --max-time=3600\nnumprocs=2\nstdout_logfile=/var/www/sites/shop.example.com/shared/logs/worker.log\n",
                                    "path": "/etc/supervisor/conf.d/shop.example.com-worker.conf"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            },
            "put": {
                "operationId": "workersSupervisorUpdate",
                "summary": "Save queue worker config",
                "description": "Writes the site's supervisor worker config (creating <rootPath>/shared/logs if needed) and runs supervisorctl reread && supervisorctl update. The saved content is recorded in the config history.\n\n**Roles:** admin (with access to the site).\n\n- No validation of the content and no revert: the file is written as sent.\n\n- No audit entry is written.\n\n- Admin only: supervisor programs run commands as any user, root included.",
                "tags": [
                    "Workers and scheduler"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Saved and applied.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "output": "shop.example.com-worker: changed\nshop.example.com-worker: stopped\nshop.example.com-worker: updated process group"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "reread/update failed; the file stays written and is recorded in history. Body also has \"details\". — \"supervisorctl update failed\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "supervisorctl update failed"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "content": {
                                        "type": "string",
                                        "description": "Full file content. (max 8192 chars)"
                                    }
                                },
                                "required": [
                                    "content"
                                ]
                            },
                            "example": {
                                "content": "[program:shop.example.com-worker]\ncommand=php8.3 /var/www/sites/shop.example.com/current/artisan queue:work redis --sleep=3 --tries=3 --max-time=3600\nnumprocs=2\nstdout_logfile=/var/www/sites/shop.example.com/shared/logs/worker.log\n"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/supervisor/control": {
            "post": {
                "operationId": "workersControl",
                "summary": "Start, stop or restart workers",
                "description": "Runs supervisorctl start|stop|restart on the site's worker group and returns the output and the fresh process status. On start, a missing worker config is first created from the default template.\n\n**Roles:** admin, developer (with access to the site).\n\n- ok is false (still HTTP 200) when supervisorctl failed for another reason; output then holds the error text.\n\n- No audit entry is written.",
                "tags": [
                    "Workers and scheduler"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Command result and current status.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "action": "restart",
                                    "output": "shop.example.com-worker:shop.example.com-worker_00: stopped\nshop.example.com-worker:shop.example.com-worker_00: started",
                                    "processes": [
                                        {
                                            "name": "shop.example.com-worker:shop.example.com-worker_00",
                                            "state": "RUNNING",
                                            "description": "pid 4121, uptime 2:14:07"
                                        },
                                        {
                                            "name": "shop.example.com-worker:shop.example.com-worker_01",
                                            "state": "RUNNING",
                                            "description": "pid 4122, uptime 2:14:07"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "\"no such group\", the default config was written and the retry still failed. Body also has \"details\". — \"Supervisor group not found. Config was written but failed to load — check supervisor logs.\"\n\n\"no such group\" and a config file exists. Body also has \"details\". — \"Supervisor group not found. Try saving the supervisor config to reload it.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Supervisor group not found. Config was written but failed to load — check supervisor logs."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "action": {
                                        "type": "string",
                                        "description": "Action to run. (one of: start, stop, restart)"
                                    }
                                },
                                "required": [
                                    "action"
                                ]
                            },
                            "example": {
                                "action": "restart"
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/supervisor/status": {
            "get": {
                "operationId": "workersStatus",
                "summary": "Get queue worker status",
                "description": "Runs supervisorctl status \"<domain>-worker:\" on the site's server and returns the parsed process list.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- state is upper-cased (RUNNING, STOPPED, FATAL, BACKOFF, …).\n\n- Output lines are parsed as \"<name> <state> <description>\", so when the group does not exist supervisorctl's message yields an entry like {\"name\": \"shop.example.com-worker:\", \"state\": \"ERROR\", \"description\": \"(no such group)\"} rather than an empty list.",
                "tags": [
                    "Workers and scheduler"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Worker processes.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "processes": [
                                        {
                                            "name": "shop.example.com-worker:shop.example.com-worker_00",
                                            "state": "RUNNING",
                                            "description": "pid 4121, uptime 2:14:07"
                                        },
                                        {
                                            "name": "shop.example.com-worker:shop.example.com-worker_01",
                                            "state": "RUNNING",
                                            "description": "pid 4122, uptime 2:14:07"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/test-stats": {
            "get": {
                "operationId": "deploymentsTestStats",
                "summary": "Get deploy test statistics",
                "description": "Aggregates the test results of the site's last 30 deployments that ran tests (testResult passed or failed).\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- passRate is a whole percentage, null when there are no runs; avgDurationMs is null when no run has a parsed duration; lastRun is the newest run or null; trend is ordered oldest → newest.\n\n- No 404: an unknown site id returns totalRuns 0.",
                "tags": [
                    "Deployments"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Test analytics.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "totalRuns": 2,
                                    "passRate": 50,
                                    "avgDurationMs": 41250,
                                    "lastRun": {
                                        "id": 345,
                                        "commit": "a3f9c21",
                                        "testResult": "passed",
                                        "createdAt": "2026-11-27T10:00:00.000Z",
                                        "testsPassed": 128,
                                        "testsFailed": 0,
                                        "testsTotal": 128,
                                        "testDurationMs": 40100
                                    },
                                    "trend": [
                                        {
                                            "date": "2026-11-20T09:30:00.000Z",
                                            "result": "failed",
                                            "passed": 126,
                                            "failed": 2,
                                            "total": 128
                                        },
                                        {
                                            "date": "2026-11-27T10:00:00.000Z",
                                            "result": "passed",
                                            "passed": 128,
                                            "failed": 0,
                                            "total": 128
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/usage": {
            "get": {
                "operationId": "usageSiteGet",
                "summary": "Get site resource usage",
                "description": "Returns the stored daily usage measurements of a site (disk, database size, and — when traffic logging is on — requests and bytes sent) and the latest values. Never runs a measurement.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- latest.diskBytes/dbBytes come from the newest history row that has them; latest.requests/bytesOut come from today's row only and are null when traffic logging is off. measuredAt is the updatedAt of the newest row. Dates (today, history[].date) are YYYY-MM-DD in the panel server's local time zone.\n\n- notes is always [] here (it is filled only by the refresh endpoint).\n\n- Measurements are taken automatically every 6 hours and kept 400 days.",
                "tags": [
                    "Usage"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "days",
                        "in": "query",
                        "required": false,
                        "description": "How many days of history to return (counting today). (default 30, max 400; values below 1 or non-numeric fall back to 30; decimals are floored)",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Usage history and latest values.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "siteId": 12,
                                    "trafficLog": true,
                                    "remote": false,
                                    "today": "2026-11-27",
                                    "latest": {
                                        "diskBytes": 734003200,
                                        "diskDate": "2026-11-27",
                                        "dbBytes": 52428800,
                                        "dbDate": "2026-11-27",
                                        "requests": 1840,
                                        "bytesOut": 96468992,
                                        "measuredAt": "2026-11-27T10:00:00.000Z"
                                    },
                                    "history": [
                                        {
                                            "date": "2026-11-26",
                                            "diskBytes": 733000000,
                                            "dbBytes": 52000000,
                                            "requests": 15230,
                                            "bytesOut": 812000000,
                                            "updatedAt": "2026-11-27T00:05:00.000Z"
                                        },
                                        {
                                            "date": "2026-11-27",
                                            "diskBytes": 734003200,
                                            "dbBytes": 52428800,
                                            "requests": 1840,
                                            "bytesOut": 96468992,
                                            "updatedAt": "2026-11-27T10:00:00.000Z"
                                        }
                                    ],
                                    "notes": []
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/usage/refresh": {
            "post": {
                "operationId": "usageSiteRefresh",
                "summary": "Measure site usage now",
                "description": "Measures the site now (du of the site folder, database size, and today's traffic from the opt-in traffic log), stores the result for today and returns the same payload as GET /usage. Read-only on the site itself.\n\n**Roles:** admin, developer (with access to the site).\n\n- notes lists machine-readable reasons a metric is missing: disk_unavailable, no_database, db_unreachable, traffic_unavailable, traffic_no_log.\n\n- Concurrent refreshes of the same site share one measurement run. The request waits for the measurement.\n\n- days is read from the query string (the web client sends ?days=30).\n\n- latest.diskBytes/dbBytes come from the newest history row that has them; latest.requests/bytesOut come from today's row only and are null when traffic logging is off. measuredAt is the updatedAt of the newest row. Dates (today, history[].date) are YYYY-MM-DD in the panel server's local time zone.\n\n- No audit entry is written.",
                "tags": [
                    "Usage"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "days",
                        "in": "query",
                        "required": false,
                        "description": "How many days of history to return (counting today). (default 30, max 400; values below 1 or non-numeric fall back to 30; decimals are floored)",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Usage history including the new measurement, with notes on missing metrics.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "siteId": 12,
                                    "trafficLog": true,
                                    "remote": false,
                                    "today": "2026-11-27",
                                    "latest": {
                                        "diskBytes": 734003200,
                                        "diskDate": "2026-11-27",
                                        "dbBytes": 52428800,
                                        "dbDate": "2026-11-27",
                                        "requests": 1840,
                                        "bytesOut": 96468992,
                                        "measuredAt": "2026-11-27T10:00:00.000Z"
                                    },
                                    "history": [
                                        {
                                            "date": "2026-11-26",
                                            "diskBytes": 733000000,
                                            "dbBytes": 52000000,
                                            "requests": 15230,
                                            "bytesOut": 812000000,
                                            "updatedAt": "2026-11-27T00:05:00.000Z"
                                        },
                                        {
                                            "date": "2026-11-27",
                                            "diskBytes": 734003200,
                                            "dbBytes": 52428800,
                                            "requests": 1840,
                                            "bytesOut": 96468992,
                                            "updatedAt": "2026-11-27T10:00:00.000Z"
                                        }
                                    ],
                                    "notes": [
                                        "traffic_no_log"
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{id}/usage/traffic": {
            "put": {
                "operationId": "usageSiteTraffic",
                "summary": "Turn traffic logging on or off",
                "description": "Switches the site's opt-in traffic access log on or off by editing its nginx vhost through a script that backs up the vhost, checks it with nginx -t and restores it on failure. The flag is stored only after nginx accepted the change. Returns the usage payload for 30 days.\n\n**Roles:** admin (with access to the site).\n\n- A failure writes the audit action \"site.traffic_log_failed\" (meta: { domain, enabled, error }). Success meta: { domain, enabled }.\n\n- Works for local and remote servers (the script runs on the site's server).\n\n- The returned history always covers 30 days (no days parameter).",
                "tags": [
                    "Usage"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Usage payload (30 days) with the new trafficLog value.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "siteId": 12,
                                    "trafficLog": true,
                                    "remote": false,
                                    "today": "2026-11-27",
                                    "latest": {
                                        "diskBytes": 734003200,
                                        "diskDate": "2026-11-27",
                                        "dbBytes": 52428800,
                                        "dbDate": "2026-11-27",
                                        "requests": 1840,
                                        "bytesOut": 96468992,
                                        "measuredAt": "2026-11-27T10:00:00.000Z"
                                    },
                                    "history": [
                                        {
                                            "date": "2026-11-26",
                                            "diskBytes": 733000000,
                                            "dbBytes": 52000000,
                                            "requests": 15230,
                                            "bytesOut": 812000000,
                                            "updatedAt": "2026-11-27T00:05:00.000Z"
                                        },
                                        {
                                            "date": "2026-11-27",
                                            "diskBytes": 734003200,
                                            "dbBytes": 52428800,
                                            "requests": 1840,
                                            "bytesOut": 96468992,
                                            "updatedAt": "2026-11-27T10:00:00.000Z"
                                        }
                                    ],
                                    "notes": []
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "The script failed; \"details\" holds up to 800 chars of its stderr/stdout. — \"Could not change traffic logging (the site's nginx config was left unchanged).\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Could not change traffic logging (the site's nginx config was left unchanged)."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "enabled": {
                                        "type": "boolean",
                                        "description": "true to start counting requests and bytes, false to stop."
                                    }
                                },
                                "required": [
                                    "enabled"
                                ]
                            },
                            "example": {
                                "enabled": true
                            }
                        }
                    }
                }
            }
        },
        "/api/sites/{id}/webhook-token": {
            "post": {
                "operationId": "webhookToken",
                "summary": "Generate webhook token",
                "description": "Generates a new random webhook token (48 hex characters) for the site, replacing any previous one. The token is both the secret part of the push-to-deploy URL /api/webhooks/github/{token} and the HMAC secret GitHub must sign with.\n\n**Roles:** admin, developer (with access to the site).\n\n- The previous token stops working immediately: update both the payload URL and the secret in the GitHub webhook settings.\n\n- No 404 check: for an unknown site id an admin gets a 500 (Prisma update error).\n\n- No audit entry is written.\n\n- No request body. Send this request without a body (or with a JSON body such as {}). Sending Content-Type: application/json with an empty body is rejected by Fastify with 400 FST_ERR_CTP_EMPTY_JSON_BODY.",
                "tags": [
                    "Push-to-deploy webhook"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The new token.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "webhookToken": "5f0c2a9e7b1d4c3a8e6f0b2d4a6c8e0f1a3b5c7d9e1f2a4b"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{siteId}/database/backup/s3": {
            "get": {
                "operationId": "databaseS3List",
                "summary": "List S3 backups",
                "description": "Lists the objects under backups/<domain>/ in the configured S3/R2 bucket, newest first. When S3 is not configured it returns an empty list with configured: false.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- When s3_access_key or s3_bucket is missing the response is { files: [], configured: false } (no bucket field).\n\n- Uses a single ListObjectsV2 call, so at most 1000 objects are returned (no pagination).\n\n- S3/R2 settings come from Settings keys s3_access_key, s3_secret_key, s3_region (default \"auto\"), s3_bucket, s3_endpoint (when set, path-style addressing is used).",
                "tags": [
                    "Databases and backups"
                ],
                "parameters": [
                    {
                        "name": "siteId",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Remote backup objects.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "files": [
                                        {
                                            "key": "backups/shop.example.com/shop_2026-11-27T10-00-00.sql.gz",
                                            "filename": "shop_2026-11-27T10-00-00.sql.gz",
                                            "sizeBytes": 5242880,
                                            "lastModified": "2026-11-27T10:01:00.000Z"
                                        }
                                    ],
                                    "configured": true,
                                    "bucket": "orchestrator-backups"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "The S3 list call failed; the error is the raw SDK message. — \"<error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{siteId}/database/backup/s3/{filename}": {
            "post": {
                "operationId": "databaseS3Upload",
                "summary": "Upload a backup to S3",
                "description": "Reads a backup file from the site's <rootPath>/backups (local disk, or over SSH for remote servers) and uploads it to the configured S3/R2 bucket under the key backups/<domain>/<filename>.\n\n**Roles:** admin, developer (with access to the site).\n\n- The whole file is read into memory and uploaded with one PutObject (Content-Type application/octet-stream); an existing object with the same key is overwritten.\n\n- The audit entry is written without the calling user (userId null). Meta: { filename, key }.\n\n- S3/R2 settings come from Settings keys s3_access_key, s3_secret_key, s3_region (default \"auto\"), s3_bucket, s3_endpoint (when set, path-style addressing is used).\n\n- The path parameter is named siteId in this file (not id).",
                "tags": [
                    "Databases and backups"
                ],
                "parameters": [
                    {
                        "name": "siteId",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "filename",
                        "in": "path",
                        "required": true,
                        "description": "Backup file name in <rootPath>/backups. (pattern ^[\\w._-]+\\.sql(\\.gz)?$)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The object key and bucket.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "key": "backups/shop.example.com/shop_2026-11-27T10-00-00.sql.gz",
                                    "bucket": "orchestrator-backups"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "filename does not match ^[\\w._-]+\\.sql(\\.gz)?$. — \"Invalid filename\"\n\ns3_access_key, s3_secret_key or s3_bucket is not set. — \"S3/R2 credentials not configured. Set them in Settings → S3 Backup.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid filename"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "Reading the file failed (remote: \"Backup not found on remote host\") or the S3 upload failed; the error is the raw message. — \"<error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/sites/{siteId}/database/backup/s3/{key}": {
            "delete": {
                "operationId": "databaseS3Delete",
                "summary": "Delete an S3 backup",
                "description": "Deletes one object from the S3/R2 bucket. The key is everything after /s3/ in the URL (a wildcard, slashes included) and must start with this site's prefix backups/<domain>/.\n\n**Roles:** admin, developer (with access to the site).\n\n- In Fastify the route is declared as /:siteId/database/backup/s3/*; the OpenAPI {key} stands for the wildcard. Send the slashes literally (the web client does not encode them).\n\n- No audit entry is written.\n\n- S3/R2 settings come from Settings keys s3_access_key, s3_secret_key, s3_region (default \"auto\"), s3_bucket, s3_endpoint (when set, path-style addressing is used).",
                "tags": [
                    "Databases and backups"
                ],
                "parameters": [
                    {
                        "name": "siteId",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "key",
                        "in": "path",
                        "required": true,
                        "description": "Full object key as returned by the list endpoint, e.g. backups/shop.example.com/shop_2026-11-27T10-00-00.sql.gz. Declared as a Fastify wildcard (*), so it may contain slashes. (must start with backups/<site domain>/ and must not contain \"..\")",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The object was deleted.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "s3_access_key or s3_bucket is not set. — \"S3/R2 not configured\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "S3/R2 not configured"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"\n\nThe key is empty, does not start with backups/<domain>/ or contains \"..\". — \"Key is outside this site's backup prefix\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "The S3 delete call failed; the error is the raw SDK message. — \"<error message>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "<error message>"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/system/doctor": {
            "get": {
                "operationId": "systemDoctor",
                "summary": "Run the installation doctor",
                "description": "Runs a read-only health check of the panel installation and the host and returns every finding. Checks cover the panel (run user, file ownership, database and backups, git checkout and remote, secrets, restart capability, Node version, agent build), tools, systemd services and nginx -t, system resources (disk, inodes, memory, swap, reboot, NTP, sudo) and local sites. Nothing is changed.\n\n**Roles:** admin.\n\n- Check shape: id (stable identifier, e.g. git, tool.nginx, svc.nginx, site.12.siteNoVhost), group (panel | tools | services | system | sites), status (ok | info | warn | fail), optional label (an untranslated proper name such as a tool, unit or domain), code (message key; the UI translates system.doctor.msg.<code>), optional params (values for the message), optional fix (a shell command that fixes it — shown, never executed).\n\n- summary counts the checks per status.\n\n- A check that throws is reported as status warn with code checkError and params.detail instead of failing the whole report.\n\n- Can take several seconds (file ownership scan, git ls-remote, nginx -t).",
                "tags": [
                    "System"
                ],
                "responses": {
                    "200": {
                        "description": "The doctor report.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "generatedAt": "2026-11-27T10:00:00.000Z",
                                    "durationMs": 2140,
                                    "summary": {
                                        "ok": 31,
                                        "info": 3,
                                        "warn": 2,
                                        "fail": 0
                                    },
                                    "checks": [
                                        {
                                            "id": "database",
                                            "group": "panel",
                                            "status": "ok",
                                            "code": "dbOk",
                                            "params": {
                                                "sizeMb": 42
                                            }
                                        },
                                        {
                                            "id": "svc.php8.3-fpm",
                                            "group": "services",
                                            "status": "fail",
                                            "label": "php8.3-fpm",
                                            "code": "svcInactive",
                                            "fix": "sudo systemctl restart php8.3-fpm"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/system/heartbeat": {
            "get": {
                "operationId": "systemHeartbeat",
                "summary": "Check schedulers and queue workers",
                "description": "For every active site, reports whether its Laravel scheduler cron is enabled and recently ran, and the state of its supervisor queue workers. Each server is probed once (cron.d listing, the cron journal for the last 20 minutes, supervisorctl status), locally or over SSH. Read-only.\n\n**Roles:** admin.\n\n- scheduler.state: off (no cron file), ok (ran within the last 3 minutes), stale, unknown (journal not readable). workers.state: none, ok, degraded, down, unknown.\n\n- server is null for sites on the panel host, otherwise the remote server's name. reachable false (with scheduler and workers null) means the server probe failed.\n\n- workers.processes is capped at 20 entries.",
                "tags": [
                    "System"
                ],
                "responses": {
                    "200": {
                        "description": "One row per active site, ordered by domain.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "generatedAt": "2026-11-27T10:00:00.000Z",
                                    "sites": [
                                        {
                                            "id": 12,
                                            "name": "Shop",
                                            "domain": "shop.example.com",
                                            "stackType": "laravel",
                                            "server": null,
                                            "reachable": true,
                                            "scheduler": {
                                                "enabled": true,
                                                "state": "ok",
                                                "lastRun": "2026-11-27T09:59:00.000Z"
                                            },
                                            "workers": {
                                                "state": "ok",
                                                "running": 2,
                                                "total": 2,
                                                "processes": [
                                                    {
                                                        "name": "shop.example.com-worker:shop.example.com-worker_00",
                                                        "state": "RUNNING"
                                                    }
                                                ]
                                            }
                                        },
                                        {
                                            "id": 15,
                                            "name": "Docs",
                                            "domain": "docs.example.com",
                                            "stackType": "static",
                                            "server": "edge-2",
                                            "reachable": false,
                                            "scheduler": null,
                                            "workers": null
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/system/info": {
            "get": {
                "operationId": "systemInfo",
                "summary": "Get host system info",
                "description": "Read-only snapshot of the panel host: hostname, kernel, OS name, uptime, number of pending apt upgrades (simulated, no changes), whether a reboot is required and the ufw firewall state.\n\n**Roles:** admin.\n\n- pendingUpdates is -1 when apt-get is unavailable or failed. ufwStatus is null when ufw is absent or passwordless sudo for ufw is not granted.",
                "tags": [
                    "System"
                ],
                "responses": {
                    "200": {
                        "description": "The host snapshot.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "hostname": "panel-01",
                                    "kernel": "6.8.0-48-generic",
                                    "os": "Ubuntu 24.04.1 LTS",
                                    "uptimeSeconds": 1209600,
                                    "pendingUpdates": 7,
                                    "rebootRequired": false,
                                    "ufwStatus": "active"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/system/packages": {
            "get": {
                "operationId": "systemPackages",
                "summary": "List upgradable packages",
                "description": "Lists the apt packages that have an upgrade available on the panel host (apt list --upgradable, no sudo, no changes), with a count of security updates.\n\n**Roles:** admin.\n\n- On hosts without apt it returns {\"available\": false, \"packages\": [], \"security\": 0}. security is true when the suite contains \"-security\".",
                "tags": [
                    "System"
                ],
                "responses": {
                    "200": {
                        "description": "Upgradable packages.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "available": true,
                                    "packages": [
                                        {
                                            "name": "openssl",
                                            "suite": "noble-updates,noble-security",
                                            "version": "3.0.13-0ubuntu3.4",
                                            "arch": "amd64",
                                            "current": "3.0.13-0ubuntu3.1",
                                            "security": true
                                        }
                                    ],
                                    "security": 1
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/system/reboot-schedule": {
            "get": {
                "operationId": "systemRebootScheduleGet",
                "summary": "Get the scheduled reboot",
                "description": "Reports whether a reboot or shutdown is pending on the panel host (read from systemd's /run/systemd/shutdown/scheduled, so it also shows one scheduled from a shell), plus the server's current time and timezone.\n\n**Roles:** admin.\n\n- When nothing is pending the body is {\"scheduled\": false, \"serverTime\": …, \"timezone\": …}.",
                "tags": [
                    "System"
                ],
                "responses": {
                    "200": {
                        "description": "The schedule. at and mode are present only when scheduled is true.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "scheduled": true,
                                    "at": "2026-11-28T03:00:00.000Z",
                                    "mode": "reboot",
                                    "serverTime": "2026-11-27T10:00:00.000Z",
                                    "timezone": "UTC"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "systemRebootScheduleCreate",
                "summary": "Schedule a reboot",
                "description": "Schedules a reboot of the panel host at the given time with sudo -n shutdown -r +<minutes>, replacing any reboot already pending. The time is rounded up to whole minutes from now.\n\n**Roles:** admin.\n\n- Unlike GET, the response has no serverTime/timezone fields.",
                "tags": [
                    "System"
                ],
                "responses": {
                    "200": {
                        "description": "The new schedule as read back from systemd.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "scheduled": true,
                                    "at": "2026-11-28T03:00:00.000Z",
                                    "mode": "reboot"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "at is unparsable or outside the allowed window. — \"Pick a time between 2 minutes and 7 days from now.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Pick a time between 2 minutes and 7 days from now."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "shutdown failed (e.g. no passwordless sudo); the body also has details with the stderr text. — \"Could not schedule the reboot.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Could not schedule the reboot."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "at": {
                                        "type": "string",
                                        "description": "Reboot time, any string JavaScript Date can parse (ISO 8601 recommended). (max 40 chars; must be 2 minutes to 7 days from now)"
                                    }
                                },
                                "required": [
                                    "at"
                                ]
                            },
                            "example": {
                                "at": "2026-11-28T03:00:00.000Z"
                            }
                        }
                    }
                }
            },
            "delete": {
                "operationId": "systemRebootScheduleCancel",
                "summary": "Cancel the scheduled reboot",
                "description": "Cancels any pending shutdown or reboot on the panel host with sudo -n shutdown -c.\n\n**Roles:** admin.",
                "tags": [
                    "System"
                ],
                "responses": {
                    "200": {
                        "description": "The schedule after cancelling.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "scheduled": false
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "shutdown -c failed; the body also has details with the stderr text. — \"Could not cancel the scheduled reboot.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Could not cancel the scheduled reboot."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/system/run/{key}/stream": {
            "get": {
                "operationId": "systemRunStream",
                "summary": "Run a maintenance action",
                "description": "Runs one allow-listed, fixed maintenance command on the panel host and streams its output as Server-Sent Events. Commands are spawned with an argument array (no shell) through sudo -n, so passwordless sudo must be granted for them. Nothing the client sends becomes part of the command except the validated ufw target.\n\n**Roles:** admin.\n\n**Streams** Server-Sent Events.\n\n- The audit action is \"system.\" + key (e.g. system.apt-upgrade, system.ufw-allow, system.reboot) with meta {label, arg}; it is written before the command starts, whatever its outcome.\n\n- Event payloads: first {\"line\": \"$ <label> [arg]\\n\"} echoing the command, then {\"line\": \"<text>\"} for every non-empty stdout/stderr line, and {\"line\": \"[error] <message>\"} if the process cannot be spawned.\n\n- End signal: {\"done\": true, \"status\": \"success\"} (exit code 0) or {\"done\": true, \"status\": \"failed\"}, after which the response ends.\n\n- A comment line \": ka\" is sent every 20 seconds as keep-alive. Closing the connection sends SIGTERM to the command.\n\n- This is a GET with side effects: actions such as reboot, apt-upgrade and ufw-enable change the host. reboot takes the panel down; ufw-enable without an ssh/port rule can lock out SSH.\n\n- Without passwordless sudo, sudo -n fails immediately and the stream ends with status failed.\n\n- EventSource cannot send an Authorization header; the web client reads the stream with fetch() and a Bearer header.",
                "tags": [
                    "System"
                ],
                "parameters": [
                    {
                        "name": "key",
                        "in": "path",
                        "required": true,
                        "description": "Action key. apt-update: sudo -n apt-get update. apt-upgrade: sudo -n apt-get -y -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold upgrade (DEBIAN_FRONTEND=noninteractive). apt-dist-upgrade: same options with dist-upgrade. apt-autoremove: sudo -n apt-get -y autoremove --purge (noninteractive). apt-clean: sudo -n apt-get clean. journal-vacuum: sudo -n journalctl --vacuum-time=7d. ufw-status: sudo -n ufw status verbose. ufw-enable: sudo -n ufw --force enable. ufw-allow: sudo -n ufw allow <arg>. ufw-deny: sudo -n ufw deny <arg>. reboot: sudo -n reboot. (one of: apt-update, apt-upgrade, apt-dist-upgrade, apt-autoremove, apt-clean, journal-vacuum, ufw-status, ufw-enable, ufw-allow, ufw-deny, reboot)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "arg",
                        "in": "query",
                        "required": false,
                        "description": "Firewall target; required for ufw-allow and ufw-deny, ignored for other keys. (a port 1–65535 optionally followed by /tcp or /udp (pattern ^\\d{1,5}(/(tcp|udp))?$), or one of: ssh, http, https, ftp, smtp)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "SSE stream; every event is a single \"data: <json>\" line.",
                        "content": {
                            "text/event-stream": {
                                "schema": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "ufw-allow or ufw-deny with a missing or invalid arg. — \"Invalid firewall target. Use a port (e.g. 8080 or 8080/tcp) or ssh/http/https.\"\n\nkey is not in the allow-list. — \"Unknown action: <key>\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid firewall target. Use a port (e.g. 8080 or 8080/tcp) or ssh/http/https."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/system/update/check": {
            "post": {
                "operationId": "systemUpdateCheck",
                "summary": "Check for panel updates",
                "description": "Fetches the current branch from origin (git, as the checkout's owner) and reports how far behind/ahead the checkout is, the incoming commits (up to 50), which sensitive areas they touch and whether an update can run.\n\n**Roles:** admin.\n\n- Send no body (or a valid JSON body): Fastify rejects Content-Type: application/json with an empty body (FST_ERR_CTP_EMPTY_JSON_BODY).\n\n- blocker: dirty (tracked local changes, listed in dirty, max 30), diverged (local commits not on origin), detached (HEAD detached; nothing is fetched). canUpdate is true only when behind > 0 and there is no blocker.\n\n- touches flags: schema (apps/api/prisma/schema.prisma), scripts (scripts/*.sh), serviceUnit (scripts/orchestrator-*.service|timer), nginx (scripts/nginx-panel.conf), dependencies (pnpm-lock.yaml).\n\n- POST because it runs git fetch, which updates the remote-tracking refs; it does not change the working tree.",
                "tags": [
                    "System"
                ],
                "responses": {
                    "200": {
                        "description": "The update check.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "branch": "main",
                                    "current": "a3f9c21",
                                    "latest": "b71e0d4",
                                    "behind": 2,
                                    "ahead": 0,
                                    "dirty": [],
                                    "commits": [
                                        {
                                            "hash": "b71e0d4",
                                            "subject": "Add disk forecast alerts",
                                            "author": "Ada Lovelace",
                                            "date": "2026-11-26T18:30:00+04:00"
                                        }
                                    ],
                                    "touches": {
                                        "schema": true,
                                        "scripts": false,
                                        "serviceUnit": false,
                                        "nginx": false,
                                        "dependencies": true
                                    },
                                    "canUpdate": true,
                                    "blocker": null
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "A git command failed (e.g. origin unreachable); the body also has details (stderr, max 2000 chars). — \"Panel update request failed.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Panel update request failed."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/system/update/restart": {
            "post": {
                "operationId": "systemUpdateRestart",
                "summary": "Restart the panel after an update",
                "description": "Finishes an update that stopped at needs_restart by restarting the panel. Only possible when the restart mode is self: the API exits about 300 ms after answering (after waiting for running deployments, max 10 minutes) and systemd starts the new build.\n\n**Roles:** admin.\n\n- Send no body (or a valid JSON body).\n\n- Any restart mode other than self (including detached and sudo) is refused with code manual.",
                "tags": [
                    "System"
                ],
                "responses": {
                    "200": {
                        "description": "The restart was scheduled.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "mode": "self"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "state.status is not needs_restart (code not_needed). — \"No finished update is waiting for a restart.\"\n\nrestartMode is not self (code manual); the service name comes from PANEL_SERVICE. — \"The panel cannot restart itself on this host. Run: sudo systemctl restart orchestrator-api\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "No finished update is waiting for a restart."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "Any other failure; the body also has details. — \"Panel update request failed.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Panel update request failed."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/system/update/start": {
            "post": {
                "operationId": "systemUpdateStart",
                "summary": "Start a panel self-update",
                "description": "Launches scripts/panel-update.sh, which builds the new version next to the running one, smoke-tests it and only then switches and restarts. The call returns immediately; follow progress with GET /api/system/update/status.\n\n**Roles:** admin.\n\n- Refusals have the body {\"error\": \"<message>\", \"code\": \"<code>\"}.\n\n- The state is set to running/phase init immediately so a second call gets 409.\n\n- The panel restarts at the end of a successful update; in-flight requests and streams are cut. When the new process boots it records state success and writes the audit entry system.panel_updated.\n\n- In self mode the API waits up to 10 minutes for running deployments before exiting. In manual mode the update ends in needs_restart.",
                "tags": [
                    "System"
                ],
                "responses": {
                    "200": {
                        "description": "The update was launched, with the restart mode that will be used.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "started": true,
                                    "mode": "detached"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "systemd-run failed in detached mode (code launch_failed). — \"Could not start the update: <reason>\"\n\nThe API is not root and not the checkout owner (code not_owner). — \"The panel runs as a different user than the owner of <repo root> (<owner>) and cannot update it.\"\n\nThe update script does not exist (code no_script). — \"scripts/panel-update.sh is missing from the checkout.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Could not start the update: <reason>"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "The update state is running or restarting (code in_progress). — \"A panel update is already running.\"\n\nAt least one deployment has status running (code deploy_running). — \"A site deployment is running. Wait for it to finish, then update the panel.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "A panel update is already running."
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "Any other failure; the body also has details. — \"Panel update request failed.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Panel update request failed."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "force": {
                                        "type": "boolean",
                                        "description": "Rebuild even when already up to date (sets ORCH_FORCE=1 for the script). (default false; body optional)"
                                    }
                                }
                            },
                            "example": {
                                "force": false
                            }
                        }
                    }
                }
            }
        },
        "/api/system/update/status": {
            "get": {
                "operationId": "systemUpdateStatus",
                "summary": "Get panel update progress",
                "description": "Returns the self-update state, whether an update is in progress and the log of the most recent run (last ~120 KB of .update/update.log). Poll it while an update runs.\n\n**Roles:** admin.\n\n- inProgress is true when state.status is running or restarting.\n\n- Expect the request to fail briefly while the panel restarts at the end of an update.\n\n- The state shape is the same as in GET /api/system/update/version; phase and message are free text written by the script. The dbBackup and log values in the example are illustrative.",
                "tags": [
                    "System"
                ],
                "responses": {
                    "200": {
                        "description": "State, in-progress flag and log text.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "state": {
                                        "status": "running",
                                        "phase": "build",
                                        "message": "Building the web app…",
                                        "startedAt": "2026-11-27T10:00:00.000Z",
                                        "finishedAt": null,
                                        "fromCommit": "a3f9c21",
                                        "toCommit": "b71e0d4",
                                        "branch": "main",
                                        "dbBackup": "/opt/orchestrator/backups/panel/pre-update-20261127-1000.db",
                                        "pid": 48211
                                    },
                                    "inProgress": true,
                                    "log": "[10:00:01] ════════ Panel update started ════════\n[10:00:03] Fetching origin/main…\n"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/system/update/version": {
            "get": {
                "operationId": "systemUpdateVersion",
                "summary": "Get panel version and update state",
                "description": "Returns the running panel's version (git commit, branch, Node version, boot time), the current self-update state and how the panel can restart itself on this host.\n\n**Roles:** admin.\n\n- state.status is one of: idle, running, restarting, success, failed, rolled_back, needs_restart, up_to_date. A running state whose process is gone (or stuck in phase init for more than 90 s) is reported as failed with an explanatory message.\n\n- capabilities.restartMode: detached (systemd-run outside the service, with verify and auto-rollback), sudo (the script restarts the unit through passwordless sudo), self (the API exits and systemd restarts it), manual (someone must run systemctl restart).\n\n- version fields are null when the checkout is not a git repository. service comes from PANEL_SERVICE (default orchestrator-api).",
                "tags": [
                    "System"
                ],
                "responses": {
                    "200": {
                        "description": "Version, update state, restart capabilities and the systemd service name.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "version": {
                                        "commit": "a3f9c21",
                                        "commitFull": "a3f9c21e5b7d4c0f9a8e6b3d2c1f0e9d8c7b6a50",
                                        "commitDate": "2026-11-20T09:12:00+04:00",
                                        "subject": "Fix SSL renew cron",
                                        "branch": "main",
                                        "node": "v20.18.0",
                                        "startedAt": "2026-11-26T08:00:00.000Z"
                                    },
                                    "state": {
                                        "status": "idle",
                                        "phase": "",
                                        "message": "",
                                        "startedAt": null,
                                        "finishedAt": null,
                                        "fromCommit": "",
                                        "toCommit": "",
                                        "branch": "",
                                        "dbBackup": "",
                                        "pid": 0
                                    },
                                    "capabilities": {
                                        "restartMode": "detached",
                                        "underSystemd": true,
                                        "runsAsRoot": true,
                                        "scriptPresent": true
                                    },
                                    "service": "orchestrator-api"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/tasks": {
            "get": {
                "operationId": "tasksList",
                "summary": "List tasks",
                "description": "Lists Kanban tasks with optional filters, ordered by status and then position. Admins see all tasks; other roles see only tasks they created or are assigned to.\n\n**Roles:** admin, developer, viewer.\n\n- tags is returned as a JSON-encoded string array (e.g. \"[\\\"ssl\\\"]\"), not as an array.\n\n- Ordering is by status alphabetically (done, in_progress, review, todo) and then by position.\n\n- Tasks are not filtered by the caller's site grants; a non-admin's visibility depends only on being creator or assignee.\n\n- When mine=1 and assigneeId are both sent, assigneeId wins. Non-numeric siteId/assigneeId lead to a 500 error.",
                "tags": [
                    "Tasks, notes and calendar"
                ],
                "parameters": [
                    {
                        "name": "siteId",
                        "in": "query",
                        "required": false,
                        "description": "Only tasks linked to this site. (not validated)",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "assigneeId",
                        "in": "query",
                        "required": false,
                        "description": "Only tasks assigned to this user. (not validated)",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "status",
                        "in": "query",
                        "required": false,
                        "description": "Only tasks in this column. (todo, in_progress, review or done (not validated))",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "mine",
                        "in": "query",
                        "required": false,
                        "description": "Set to 1 to return only tasks assigned to the caller. (only \"1\" has an effect)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The matching tasks.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "tasks": [
                                        {
                                            "id": 42,
                                            "title": "Renew SSL for shop",
                                            "description": "Check the certificate before Friday.",
                                            "status": "in_progress",
                                            "priority": "high",
                                            "position": 3,
                                            "dueDate": "2026-11-30T00:00:00.000Z",
                                            "tags": "[\"ssl\",\"shop\"]",
                                            "siteId": 12,
                                            "assigneeId": 12,
                                            "createdById": 1,
                                            "createdAt": "2026-11-20T09:00:00.000Z",
                                            "updatedAt": "2026-11-27T10:00:00.000Z",
                                            "assignee": {
                                                "id": 12,
                                                "email": "grace@example.com"
                                            },
                                            "createdBy": {
                                                "id": 1,
                                                "email": "ada@example.com"
                                            },
                                            "site": {
                                                "id": 12,
                                                "domain": "shop.example.com",
                                                "name": "Shop"
                                            },
                                            "checklist": [
                                                {
                                                    "id": 7,
                                                    "taskId": 42,
                                                    "text": "Check expiry date",
                                                    "done": true,
                                                    "position": 0
                                                }
                                            ],
                                            "_count": {
                                                "comments": 2
                                            }
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "tasksCreate",
                "summary": "Create a task",
                "description": "Creates a task; it is placed at the bottom of its status column. Non-admins may only leave a task unassigned or assign it to themselves.\n\n**Roles:** admin, developer, viewer.\n\n- Any role, viewers included, can create tasks.\n\n- siteId is not checked against the caller's site grants; a non-existent siteId or assigneeId, or an unparseable dueDate, is rejected by the database and surfaces as a 500 error.\n\n- position is the highest position in the target status column across all tasks, plus 1.",
                "tags": [
                    "Tasks, notes and calendar"
                ],
                "responses": {
                    "201": {
                        "description": "The created task (same shape as in the task list).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 42,
                                    "title": "Renew SSL for shop",
                                    "description": "Check the certificate before Friday.",
                                    "status": "todo",
                                    "priority": "high",
                                    "position": 4,
                                    "dueDate": "2026-11-30T00:00:00.000Z",
                                    "tags": "[\"ssl\",\"shop\"]",
                                    "siteId": 12,
                                    "assigneeId": 12,
                                    "createdById": 1,
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z",
                                    "assignee": {
                                        "id": 12,
                                        "email": "grace@example.com"
                                    },
                                    "createdBy": {
                                        "id": 1,
                                        "email": "ada@example.com"
                                    },
                                    "site": {
                                        "id": 12,
                                        "domain": "shop.example.com",
                                        "name": "Shop"
                                    },
                                    "checklist": [],
                                    "_count": {
                                        "comments": 0
                                    }
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "A non-admin sends an assigneeId other than their own. — \"Only admins can assign tasks to other users.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Only admins can assign tasks to other users."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "title": {
                                        "type": "string",
                                        "description": "Task title. (1–200 chars)"
                                    },
                                    "description": {
                                        "type": "string",
                                        "description": "Longer description. (max 10000 chars)"
                                    },
                                    "status": {
                                        "type": "string",
                                        "description": "Column. (one of: todo, in_progress, review, done; default todo)"
                                    },
                                    "priority": {
                                        "type": "string",
                                        "description": "Priority. (one of: low, medium, high, urgent; default medium)"
                                    },
                                    "dueDate": {
                                        "type": "string",
                                        "description": "Due date, any string JavaScript's Date can parse (ISO 8601 recommended). (format not validated)"
                                    },
                                    "tags": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Tags (array of strings). (items: string; default [])"
                                    },
                                    "siteId": {
                                        "type": "integer",
                                        "description": "Site to link the task to."
                                    },
                                    "assigneeId": {
                                        "type": "integer",
                                        "description": "User to assign the task to. (non-admins: only their own id)"
                                    }
                                },
                                "required": [
                                    "title"
                                ]
                            },
                            "example": {
                                "title": "Renew SSL for shop",
                                "description": "Check the certificate before Friday.",
                                "status": "todo",
                                "priority": "high",
                                "dueDate": "2026-11-30T00:00:00.000Z",
                                "tags": [
                                    "ssl",
                                    "shop"
                                ],
                                "siteId": 12,
                                "assigneeId": 12
                            }
                        }
                    }
                }
            }
        },
        "/api/tasks/{id}": {
            "get": {
                "operationId": "tasksGet",
                "summary": "Get a task",
                "description": "Returns one task with its checklist and comments. Non-admins can only open tasks they created or are assigned to.\n\n**Roles:** admin, developer, viewer.\n\n- tags is a JSON-encoded string array.",
                "tags": [
                    "Tasks, notes and calendar"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Task id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The task, including comments (oldest first).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 42,
                                    "title": "Renew SSL for shop",
                                    "description": "Check the certificate before Friday.",
                                    "status": "in_progress",
                                    "priority": "high",
                                    "position": 3,
                                    "dueDate": "2026-11-30T00:00:00.000Z",
                                    "tags": "[\"ssl\",\"shop\"]",
                                    "siteId": 12,
                                    "assigneeId": 12,
                                    "createdById": 1,
                                    "createdAt": "2026-11-20T09:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z",
                                    "assignee": {
                                        "id": 12,
                                        "email": "grace@example.com"
                                    },
                                    "createdBy": {
                                        "id": 1,
                                        "email": "ada@example.com"
                                    },
                                    "site": {
                                        "id": 12,
                                        "domain": "shop.example.com",
                                        "name": "Shop"
                                    },
                                    "checklist": [
                                        {
                                            "id": 7,
                                            "taskId": 42,
                                            "text": "Check expiry date",
                                            "done": true,
                                            "position": 0
                                        }
                                    ],
                                    "_count": {
                                        "comments": 1
                                    },
                                    "comments": [
                                        {
                                            "id": 88,
                                            "taskId": 42,
                                            "userId": 12,
                                            "body": "Expires on 2 December.",
                                            "createdAt": "2026-11-27T10:00:00.000Z",
                                            "user": {
                                                "id": 12,
                                                "email": "grace@example.com"
                                            }
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not an admin and neither created nor is assigned to the task. — \"Forbidden\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No task with this id. — \"Task not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Task not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "patch": {
                "operationId": "tasksUpdate",
                "summary": "Update a task",
                "description": "Changes any task fields, including moving it to another column or position. Only the fields sent are changed. Admins can edit any task; others only tasks they created or are assigned to, and they may only unassign it or assign it to themselves.\n\n**Roles:** admin, developer, viewer.\n\n- Other tasks' positions are not renumbered; the client is expected to send a position between its neighbours.\n\n- The audit entry stores the task id and every changed field (tags as the JSON string).\n\n- A non-admin assignee who unassigns themselves loses access to the task unless they created it.",
                "tags": [
                    "Tasks, notes and calendar"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Task id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The updated task (same shape as in the task list).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 42,
                                    "title": "Renew SSL for shop",
                                    "description": "Check the certificate before Friday.",
                                    "status": "done",
                                    "priority": "high",
                                    "position": 2.5,
                                    "dueDate": "2026-11-30T00:00:00.000Z",
                                    "tags": "[\"ssl\",\"shop\"]",
                                    "siteId": 12,
                                    "assigneeId": 12,
                                    "createdById": 1,
                                    "createdAt": "2026-11-20T09:00:00.000Z",
                                    "updatedAt": "2026-11-27T10:00:00.000Z",
                                    "assignee": {
                                        "id": 12,
                                        "email": "grace@example.com"
                                    },
                                    "createdBy": {
                                        "id": 1,
                                        "email": "ada@example.com"
                                    },
                                    "site": {
                                        "id": 12,
                                        "domain": "shop.example.com",
                                        "name": "Shop"
                                    },
                                    "checklist": [
                                        {
                                            "id": 7,
                                            "taskId": 42,
                                            "text": "Check expiry date",
                                            "done": true,
                                            "position": 0
                                        }
                                    ],
                                    "_count": {
                                        "comments": 2
                                    }
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not an admin and neither created nor is assigned to the task. — \"Forbidden\"\n\nA non-admin sends an assigneeId other than their own id or null. — \"Only admins can reassign tasks to other users.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No task with this id. — \"Task not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Task not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "title": {
                                        "type": "string",
                                        "description": "Task title. (1–200 chars)"
                                    },
                                    "description": {
                                        "type": "string",
                                        "description": "Description; null clears it. (max 10000 chars, nullable)"
                                    },
                                    "status": {
                                        "type": "string",
                                        "description": "Column. (one of: todo, in_progress, review, done)"
                                    },
                                    "priority": {
                                        "type": "string",
                                        "description": "Priority. (one of: low, medium, high, urgent)"
                                    },
                                    "position": {
                                        "type": "number",
                                        "description": "Sort position within the column (fractional values allowed)."
                                    },
                                    "dueDate": {
                                        "type": "string",
                                        "description": "Due date; null or empty string clears it. (nullable; format not validated)"
                                    },
                                    "tags": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Replaces all tags (array of strings). (items: string)"
                                    },
                                    "siteId": {
                                        "type": "integer",
                                        "description": "Linked site; null unlinks. (nullable)"
                                    },
                                    "assigneeId": {
                                        "type": "integer",
                                        "description": "Assignee; null unassigns. (nullable; non-admins: only their own id or null)"
                                    }
                                }
                            },
                            "example": {
                                "status": "done",
                                "position": 2.5
                            }
                        }
                    }
                }
            },
            "delete": {
                "operationId": "tasksDelete",
                "summary": "Delete a task",
                "description": "Deletes a task together with its checklist and comments. Only the task's creator or an admin may delete it.\n\n**Roles:** admin, developer, viewer.\n\n- Calendar events linked to the task are kept, with their taskId set to null.",
                "tags": [
                    "Tasks, notes and calendar"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Task id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The task was deleted.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is neither an admin nor the creator (assignees cannot delete). — \"Only the creator or an admin can delete this task.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Only the creator or an admin can delete this task."
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No task with this id. — \"Task not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Task not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/tasks/{id}/checklist": {
            "post": {
                "operationId": "tasksChecklistCreate",
                "summary": "Add a checklist item",
                "description": "Appends a checklist item to the end of a task's checklist. Allowed for admins and for the task's creator or assignee.\n\n**Roles:** admin, developer, viewer.\n\n- position is the task's highest checklist position plus 1 (0 for the first item).",
                "tags": [
                    "Tasks, notes and calendar"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Task id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "201": {
                        "description": "The created checklist item.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 7,
                                    "taskId": 42,
                                    "text": "Check expiry date",
                                    "done": false,
                                    "position": 0
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not an admin and neither created nor is assigned to the task. — \"Forbidden\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No task with this id. — \"Task not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Task not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "text": {
                                        "type": "string",
                                        "description": "Item text. (1–300 chars)"
                                    }
                                },
                                "required": [
                                    "text"
                                ]
                            },
                            "example": {
                                "text": "Check expiry date"
                            }
                        }
                    }
                }
            }
        },
        "/api/tasks/{id}/checklist/{itemId}": {
            "patch": {
                "operationId": "tasksChecklistUpdate",
                "summary": "Update a checklist item",
                "description": "Changes a checklist item's text, done state or position. Allowed for admins and for the task's creator or assignee.\n\n**Roles:** admin, developer, viewer.\n\n- Permissions are checked on task {id} only; the handler does not check that {itemId} belongs to that task.\n\n- A non-existent itemId is not handled and surfaces as a 500 error.",
                "tags": [
                    "Tasks, notes and calendar"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Task id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "itemId",
                        "in": "path",
                        "required": true,
                        "description": "Checklist item id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The updated checklist item.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 7,
                                    "taskId": 42,
                                    "text": "Check expiry date",
                                    "done": true,
                                    "position": 0
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not an admin and neither created nor is assigned to the task. — \"Forbidden\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No task with this id. — \"Task not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Task not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "text": {
                                        "type": "string",
                                        "description": "Item text. (1–300 chars)"
                                    },
                                    "done": {
                                        "type": "boolean",
                                        "description": "Ticked or not."
                                    },
                                    "position": {
                                        "type": "integer",
                                        "description": "Sort position."
                                    }
                                }
                            },
                            "example": {
                                "done": true
                            }
                        }
                    }
                }
            },
            "delete": {
                "operationId": "tasksChecklistDelete",
                "summary": "Delete a checklist item",
                "description": "Removes a checklist item. Allowed for admins and for the task's creator or assignee.\n\n**Roles:** admin, developer, viewer.\n\n- Permissions are checked on task {id} only; the handler does not check that {itemId} belongs to that task.\n\n- A non-existent itemId is not handled and surfaces as a 500 error.",
                "tags": [
                    "Tasks, notes and calendar"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Task id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "itemId",
                        "in": "path",
                        "required": true,
                        "description": "Checklist item id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The item was deleted.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not an admin and neither created nor is assigned to the task. — \"Forbidden\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No task with this id. — \"Task not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Task not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/tasks/{id}/comments": {
            "post": {
                "operationId": "tasksCommentsCreate",
                "summary": "Comment on a task",
                "description": "Adds a comment by the caller to a task. Allowed for admins and for the task's creator or assignee.\n\n**Roles:** admin, developer, viewer.\n\n- Comments cannot be edited, only deleted.",
                "tags": [
                    "Tasks, notes and calendar"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Task id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "201": {
                        "description": "The created comment with its author.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 88,
                                    "taskId": 42,
                                    "userId": 12,
                                    "body": "Expires on 2 December.",
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "user": {
                                        "id": 12,
                                        "email": "grace@example.com"
                                    }
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not an admin and neither created nor is assigned to the task. — \"Forbidden\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No task with this id. — \"Task not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Task not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "body": {
                                        "type": "string",
                                        "description": "Comment text. (1–5000 chars)"
                                    }
                                },
                                "required": [
                                    "body"
                                ]
                            },
                            "example": {
                                "body": "Expires on 2 December."
                            }
                        }
                    }
                }
            }
        },
        "/api/tasks/{id}/comments/{commentId}": {
            "delete": {
                "operationId": "tasksCommentsDelete",
                "summary": "Delete a task comment",
                "description": "Deletes a comment. Users can delete their own comments; admins can delete any comment.\n\n**Roles:** admin, developer, viewer.\n\n- The task id in the path is ignored: neither its existence nor the comment's membership in it is checked.",
                "tags": [
                    "Tasks, notes and calendar"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Task id (not used by the handler).",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "commentId",
                        "in": "path",
                        "required": true,
                        "description": "Comment id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The comment was deleted.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "A non-admin tries to delete someone else's comment. — \"You can only delete your own comments.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "You can only delete your own comments."
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No comment with this id. — \"Comment not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Comment not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/telegram/link-code": {
            "post": {
                "operationId": "telegramLinkCode",
                "summary": "Create a Telegram link code",
                "description": "Issues a one-time code, valid for 10 minutes, that links the caller's panel account to a Telegram account. Open the deep link (or send /start <code> to the bot) in Telegram to complete linking.\n\n**Roles:** admin, developer, viewer.\n\n- The code is 8 hex characters. Requesting a new code replaces the previous one.\n\n- deepLink is null (and botUsername empty) when Telegram's getMe call fails.\n\n- Linking needs the webhook to be set up (POST /api/telegram/setup) so the bot receives the /start message.",
                "tags": [
                    "Telegram"
                ],
                "responses": {
                    "200": {
                        "description": "The code, the bot's username and a t.me deep link.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "code": "1a2b3c4d",
                                    "botUsername": "orchestrator_example_bot",
                                    "deepLink": "https://t.me/orchestrator_example_bot?start=1a2b3c4d",
                                    "expiresAt": "2026-11-27T10:10:00.000Z"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "No Telegram bot token is configured. — \"Configure the Telegram bot token in Settings → Notifications first.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Configure the Telegram bot token in Settings → Notifications first."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/telegram/me": {
            "get": {
                "operationId": "telegramMe",
                "summary": "Get Telegram link status",
                "description": "Returns whether the caller's Telegram account is linked, and whether the panel's Telegram bot and webhook are configured.\n\n**Roles:** admin, developer, viewer.\n\n- When a bot token is set, the handler calls Telegram's getMe to read botUsername; it is an empty string when that call fails or no token is set.\n\n- webhookConfigured only means a webhook secret has been generated; it stays true after POST /api/telegram/remove-webhook.",
                "tags": [
                    "Telegram"
                ],
                "responses": {
                    "200": {
                        "description": "Link and bot status for the caller.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "linked": true,
                                    "username": "ada_example",
                                    "linkedAt": "2026-11-27T10:00:00.000Z",
                                    "botConfigured": true,
                                    "botUsername": "orchestrator_example_bot",
                                    "webhookConfigured": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/telegram/remove-webhook": {
            "post": {
                "operationId": "telegramRemoveWebhook",
                "summary": "Remove the Telegram webhook",
                "description": "Asks Telegram to stop sending updates to the panel (deleteWebhook). Admin only.\n\n**Roles:** admin.\n\n- Returns ok even when no bot token is set or Telegram's answer is an error (the answer is not returned).\n\n- The stored webhook secret is not deleted: the webhook endpoint keeps accepting requests with the old secret, and GET /api/telegram/me still reports webhookConfigured: true.",
                "tags": [
                    "Telegram"
                ],
                "responses": {
                    "200": {
                        "description": "Always returns ok.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/telegram/setup": {
            "post": {
                "operationId": "telegramSetup",
                "summary": "Register the Telegram webhook",
                "description": "Registers the panel's webhook URL with Telegram so the bot receives messages. Generates the webhook secret on first use and reuses it afterwards. Admin only.\n\n**Roles:** admin.\n\n- ok is always true; check result.ok for Telegram's verdict. result is null when Telegram could not be reached.\n\n- The webhook is registered for message and callback_query updates only.\n\n- The returned url contains the webhook secret, and the same url is stored in the audit entry's meta.",
                "tags": [
                    "Telegram"
                ],
                "responses": {
                    "200": {
                        "description": "The webhook URL and Telegram's raw setWebhook answer.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "url": "https://panel.example.com/api/telegram/webhook/3f1c0000000000000000000000000000000000000000a9e2",
                                    "result": {
                                        "ok": true,
                                        "result": true,
                                        "description": "Webhook was set"
                                    }
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The panel_url setting is empty. — \"Set the Panel URL in Settings → General first (needed for the webhook URL).\"\n\nNo Telegram bot token is configured. — \"Set the Telegram bot token in Settings → Notifications first.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Set the Panel URL in Settings → General first (needed for the webhook URL)."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/telegram/unlink": {
            "post": {
                "operationId": "telegramUnlink",
                "summary": "Unlink your Telegram account",
                "description": "Detaches the caller's Telegram account and clears any pending link code.\n\n**Roles:** admin, developer, viewer.\n\n- Always returns {\"ok\": true}, also when nothing was linked.",
                "tags": [
                    "Telegram"
                ],
                "responses": {
                    "200": {
                        "description": "The account is unlinked.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/telegram/webhook/{secret}": {
            "post": {
                "operationId": "telegramWebhook",
                "summary": "Receive Telegram bot updates",
                "description": "Webhook called by Telegram's Bot API with bot updates (messages and button presses). The secret in the path is the credential. The update is acknowledged immediately and processed in the background by the panel's Telegram bot.\n\n- Intended for Telegram only; it is not meant to be called by API clients.\n\n- Processing errors are never reported to the caller. Updates are ignored when no bot token is configured; other update types are ignored.\n\n- Sending /start <code> to the bot with a code from POST /api/telegram/link-code links the Telegram account to the panel user.",
                "tags": [
                    "Telegram"
                ],
                "parameters": [
                    {
                        "name": "secret",
                        "in": "path",
                        "required": true,
                        "description": "Webhook secret generated by POST /api/telegram/setup. (48 hex chars)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "X-Telegram-Bot-Api-Secret-Token",
                        "in": "header",
                        "required": false,
                        "description": "Secret token Telegram sends with each update. If present it must equal the webhook secret.",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Acknowledgement; processing happens afterwards.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No webhook secret is configured, the path secret is wrong, or the header token is present and does not match. The body is empty. — \"\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": ""
                                }
                            }
                        }
                    }
                },
                "x-auth": "token-in-path",
                "x-roles": [],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": [],
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "message": {
                                        "type": "object",
                                        "description": "Telegram Update.message; handled when it has text (commands such as /start <link code>). (not validated)"
                                    },
                                    "callback_query": {
                                        "type": "object",
                                        "description": "Telegram Update.callback_query (inline keyboard button press). (not validated)"
                                    }
                                }
                            },
                            "example": {
                                "update_id": 100000001,
                                "message": {
                                    "message_id": 7,
                                    "from": {
                                        "id": 555000111,
                                        "username": "ada_example"
                                    },
                                    "chat": {
                                        "id": 555000111,
                                        "type": "private"
                                    },
                                    "date": 1795773600,
                                    "text": "/start 1a2b3c4d"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/api/terminal/fleet/agent": {
            "get": {
                "operationId": "fleetAgentWebsocket",
                "summary": "Agent WebSocket",
                "description": "The persistent WebSocket the installed agent keeps open to the panel: it pushes hello, metrics and inventory and receives requests (inventory, processes, action, exec, logs, PTY, update). The agent key is checked before the upgrade; a bad key gets a plain HTTP 401 and never becomes a WebSocket.\n\n**Rate limit:** 30 per minute per IP.\n\n**WebSocket** endpoint.\n\n- Lives under /api/terminal/ because the panel's nginx already upgrades that prefix.\n\n- A newer connection of the same server replaces the older one (the old socket is closed with code 4409).\n\n- Not meant for API clients; documented for completeness. Message types are defined in apps/agent/PROTOCOL.md and lib/fleet/contract.ts.",
                "tags": [
                    "Fleet agent"
                ],
                "responses": {
                    "101": {
                        "description": "Switching protocols to a WebSocket. WebSocket upgrade; JSON text frames in the agent protocol (apps/agent/PROTOCOL.md)."
                    },
                    "401": {
                        "description": "Missing, malformed, revoked or wrong agent key. — \"Invalid agent key.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid agent key."
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Too many requests — see the Retry-After header. — \"Rate limit exceeded, retry in …\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Rate limit exceeded, retry in …"
                                }
                            }
                        }
                    },
                    "503": {
                        "description": "The fleet hub is not started. — \"The fleet hub is not running on this panel instance.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "The fleet hub is not running on this panel instance."
                                }
                            }
                        }
                    }
                },
                "x-auth": "agent",
                "x-roles": [],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": []
            }
        },
        "/api/terminal/fleet/live": {
            "get": {
                "operationId": "fleetLiveWebsocket",
                "summary": "Live metrics WebSocket",
                "description": "Browser WebSocket for live fleet metrics. After connecting the server sends {t:\"snapshot\"} with every server's status, channel and latest metrics; the client then sends {\"t\":\"watch\",\"serverIds\":[…]|\"all\"} and receives {t:\"metrics\"}, {t:\"status\"} and {t:\"inventory\"} events for the watched servers. Watching a server switches its agent to live mode (metrics every 2 s); servers without a connected agent are polled every 10 s (SSH or the panel host).\n\n**Roles:** admin.\n\n**WebSocket** endpoint.\n\n- Messages: {t:\"metrics\", serverId, at, source (agent|ssh|local), m: FleetMetrics}; {t:\"status\", serverId, agentStatus (online|offline|pending|none), channel (agent|ssh|local|none)}; {t:\"inventory\", serverId, at} (fetch the inventory over REST).\n\n- A new watch message replaces the previous watch set; at most 500 server ids; unknown ids are dropped; other message types are ignored; frames over 64 KiB are ignored.\n\n- Metrics frames are skipped for slow clients (more than 2 MiB buffered).\n\n- Error \"statuses\" here are WebSocket close codes, not HTTP statuses: the upgrade itself always succeeds and authentication happens afterwards.\n\n- The role is read from the database, not from the JWT claim.",
                "tags": [
                    "Fleet live and terminal"
                ],
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "description": "The panel session JWT (browsers cannot set headers on a WebSocket). Personal access tokens are refused.",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "101": {
                        "description": "Switching protocols to a WebSocket. WebSocket upgrade; JSON text frames. Server → client: snapshot, metrics, status, inventory, error.\n\nClose codes: 1013: The fleet hub is not running on this panel instance.; 4401: Forbidden: administrators only; 4401: Invalid token; 4401: Unauthorized."
                    },
                    "401": {
                        "description": "No token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Unauthorized"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "session",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": [
                    {
                        "sessionAuth": []
                    }
                ]
            }
        },
        "/api/terminal/fleet/term/{serverId}": {
            "get": {
                "operationId": "fleetTerminalWebsocket",
                "summary": "Server terminal WebSocket",
                "description": "Interactive shell on a fleet server through the agent (control mode with terminal allowed) or SSH (`ssh -tt`, starting in the login user's home), honouring the server's preferredChannel. Requires an admin browser session, the server's terminalEnabled switch and an active 2FA step-up confirmed with the same JWT. Same message format as the site terminal.\n\n**Roles:** admin.\n\n**Requires a 2FA step-up** in the browser session.\n\n**WebSocket** endpoint.\n\n- fleet.terminal.disconnect is audited when the socket closes.\n\n- Error \"statuses\" are WebSocket close codes sent after an error frame; the HTTP upgrade itself always succeeds.\n\n- Keystrokes and resizes sent before the shell is ready are queued (up to 200 messages).\n\n- Elevation is per JWT: elevate with POST /api/fleet/elevate using the same token, then connect within 15 minutes.\n\n- SSH start-up errors are sent as the error text of the failure (close code 4403).",
                "tags": [
                    "Fleet live and terminal"
                ],
                "parameters": [
                    {
                        "name": "serverId",
                        "in": "path",
                        "required": true,
                        "description": "Server id. (positive integer)",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "description": "The panel session JWT. Must be the token the 2FA step-up was confirmed with. Personal access tokens are refused.",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "cols",
                        "in": "query",
                        "required": false,
                        "description": "Terminal width. (10–500, default 120)",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "rows",
                        "in": "query",
                        "required": false,
                        "description": "Terminal height. (5–200, default 30)",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "101": {
                        "description": "Switching protocols to a WebSocket. WebSocket upgrade; JSON text frames. Client → server: {type:\"input\", data} and {type:\"resize\", cols, rows}. Server → client: {type:\"output\", data}, {type:\"exit\", exitCode}, {type:\"error\", error}.\n\nClose codes: 4401: Unauthorized; 4403: Confirm your two-factor code first (2FA step-up), then open the terminal again.; 4403: No terminal is available for this server: the agent is not connected and SSH access is not configured.; 4403: The agent could not open a terminal.; 4403: The agent of this server is offline (the server is set to use the agent only).; 4403: The web terminal is disabled for this server. Turn it on in the server settings first.; 4403: forbidden: monitor mode; 4403: forbidden: terminal disabled on this server; 4404: Server not found."
                    },
                    "401": {
                        "description": "No token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Unauthorized"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "session",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": [
                    {
                        "sessionAuth": []
                    }
                ]
            }
        },
        "/api/terminal/{siteId}": {
            "get": {
                "operationId": "terminalSite",
                "summary": "Open a site web terminal",
                "description": "WebSocket that opens an interactive shell for a site: a bash pty in <rootPath>/current (falling back to the site root, then /tmp) on the panel host, or an interactive SSH session into the site's remote server starting in the same directory. It is a real, unsandboxed shell running as the API user, not restricted to the site.\n\n**Roles:** admin, developer (with access to the site).\n\n**WebSocket** endpoint.\n\n- URL: wss://<panel-host>/api/terminal/{siteId}?token=<JWT> (ws:// on plain HTTP). nginx proxies /api/terminal/ with the Upgrade headers and a 3600 s read timeout.\n\n- Client → server messages: {\"type\": \"input\", \"data\": \"<keystrokes>\"} and {\"type\": \"resize\", \"cols\": 120, \"rows\": 30}. Other or malformed messages are ignored. The initial pty size is 120×30.\n\n- Server → client messages: {\"type\": \"output\", \"data\": \"<terminal output>\"} and, when the shell exits, {\"type\": \"exit\", \"exitCode\": 0} followed by the socket closing.\n\n- Auth/permission failures are not HTTP errors: the upgrade succeeds, the server sends one JSON message and closes. Messages: {\"error\": \"Unauthorized\"} (no token), {\"error\": \"Invalid token\"} (JWT verification failed, also for PATs), {\"error\": \"Site not found\"}, {\"error\": \"Forbidden: no access to this site\"} (non-admin without a site grant or allSitesAccess), {\"error\": \"Forbidden: viewer role cannot use the terminal\"}.\n\n- Admins may open any site. Developers need a grant for the site (or allSitesAccess). Viewers are always refused.\n\n- Audit: terminal.connect on open and terminal.disconnect on close (both with siteId and meta.domain).\n\n- The shell gets a minimal environment (PATH, HOME, LANG, LC_ALL, USER, LOGNAME, SHELL, TZ, TERM=xterm-256color); the API's secrets are not inherited.\n\n- The JWT in the query string can end up in proxy access logs.",
                "tags": [
                    "Terminal"
                ],
                "parameters": [
                    {
                        "name": "siteId",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "description": "The panel session JWT (browsers cannot set headers on WebSocket requests). URL-encode it. (session JWT only; personal access tokens (orch_…) are rejected)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "101": {
                        "description": "Switching protocols to a WebSocket. WebSocket upgrade. Every frame in both directions is a JSON text message."
                    },
                    "401": {
                        "description": "No token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Unauthorized"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nYour account has no access to this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "session",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": false,
                "security": [
                    {
                        "sessionAuth": []
                    }
                ]
            }
        },
        "/api/tokens": {
            "get": {
                "operationId": "tokensList",
                "summary": "List your access tokens",
                "description": "Lists the caller's own personal access tokens, newest first. The secret token value is never returned; tokenPrefix identifies each token.\n\n**Roles:** admin, developer, viewer.\n\n- Only the caller's tokens are listed; admins cannot see other users' tokens here.\n\n- lastUsedAt is updated best-effort on every request made with the token. Expired tokens are still listed.",
                "tags": [
                    "Access tokens"
                ],
                "responses": {
                    "200": {
                        "description": "The caller's tokens.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "tokens": [
                                        {
                                            "id": 4,
                                            "name": "CI deploys",
                                            "tokenPrefix": "orch_1a2b3c",
                                            "lastUsedAt": "2026-11-27T09:42:00.000Z",
                                            "expiresAt": null,
                                            "createdAt": "2026-10-01T08:00:00.000Z"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "tokensCreate",
                "summary": "Create an access token",
                "description": "Creates a personal access token for the caller and returns the plaintext token once. The token acts as the caller, with the caller's current role and site access; send it as Authorization: Bearer orch_…\n\n**Roles:** admin, developer, viewer.\n\n- The token is \"orch_\" followed by 64 hex characters. Only its SHA-256 hash is stored, so it cannot be shown again; tokenPrefix is its first 11 characters.\n\n- Role and site access are not frozen at creation: they are read from the owner's account on every request.\n\n- Every request made with a personal access token is recorded in the AI activity log (GET /api/mcp-activity). An optional X-MCP-Tool header (max 64 chars kept) labels the request with a tool name.\n\n- An access token can itself create further tokens.",
                "tags": [
                    "Access tokens"
                ],
                "responses": {
                    "201": {
                        "description": "The created token, including the plaintext token (shown only in this response).",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 4,
                                    "name": "CI deploys",
                                    "tokenPrefix": "orch_1a2b3c",
                                    "expiresAt": "2027-02-25T10:00:00.000Z",
                                    "createdAt": "2026-11-27T10:00:00.000Z",
                                    "token": "orch_1a2b3c0000000000000000000000000000000000000000000000000000000000"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Label shown in the token list and in the AI activity log. (1–80 chars)"
                                    },
                                    "expiresInDays": {
                                        "type": "integer",
                                        "description": "Days until the token expires. Omit for a token that never expires. (1–3650)"
                                    }
                                },
                                "required": [
                                    "name"
                                ]
                            },
                            "example": {
                                "name": "CI deploys",
                                "expiresInDays": 90
                            }
                        }
                    }
                }
            }
        },
        "/api/tokens/{id}": {
            "delete": {
                "operationId": "tokensRevoke",
                "summary": "Revoke an access token",
                "description": "Deletes one of the caller's own access tokens. It stops working immediately.\n\n**Roles:** admin, developer, viewer.\n\n- Admins cannot revoke other users' tokens with this endpoint (they get 404).",
                "tags": [
                    "Access tokens"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Token id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The token was revoked.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No token with this id, or it belongs to another user. — \"Token not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Token not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/uptime": {
            "get": {
                "operationId": "uptimeList",
                "summary": "List uptime status",
                "description": "Returns the latest uptime check for every site whose status is active.\n\n**Roles:** admin, developer, viewer.\n\n- Not filtered by site access: any authenticated user (including viewers without site grants) sees every active site.\n\n- status is \"up\", \"down\" (HTTP status >= 500, timeout or connection error) or \"unknown\" when the site has no checks yet.",
                "tags": [
                    "Performance and uptime"
                ],
                "responses": {
                    "200": {
                        "description": "Latest status per active site.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "sites": [
                                        {
                                            "siteId": 12,
                                            "domain": "shop.example.com",
                                            "monitoring": true,
                                            "status": "up",
                                            "responseMs": 182,
                                            "statusCode": 200,
                                            "checkedAt": "2026-11-27T10:00:00.000Z"
                                        },
                                        {
                                            "siteId": 14,
                                            "domain": "blog.example.com",
                                            "monitoring": false,
                                            "status": "unknown",
                                            "responseMs": null,
                                            "statusCode": null,
                                            "checkedAt": null
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/uptime/{siteId}": {
            "patch": {
                "operationId": "uptimeToggle",
                "summary": "Turn uptime monitoring on or off",
                "description": "Sets the site's uptimeMonitor flag, which controls whether the uptime monitor checks the site.\n\n**Roles:** admin, developer (with access to the site).\n\n- No audit entry is written.",
                "tags": [
                    "Performance and uptime"
                ],
                "parameters": [
                    {
                        "name": "siteId",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The new setting.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "monitoring": false
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Your role may not call this endpoint. — \"Forbidden: insufficient role\"\n\nCaller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"\n\nCaller has the viewer role (write method on a site route). — \"Forbidden: viewer role is read-only\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No site with this id. — \"Site not found\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Site not found"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "monitoring": {
                                        "type": "boolean",
                                        "description": "true to monitor the site, false to stop."
                                    }
                                },
                                "required": [
                                    "monitoring"
                                ]
                            },
                            "example": {
                                "monitoring": false
                            }
                        }
                    }
                }
            }
        },
        "/api/uptime/{siteId}/history": {
            "get": {
                "operationId": "uptimeHistory",
                "summary": "Get 24-hour uptime history",
                "description": "Returns the site's uptime checks from the last 24 hours (oldest first, at most 300) and the percentage of them that were up.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- uptime24h is null when there are no checks in the window. It is rounded to a whole percent.\n\n- An unknown site id returns { checks: [], uptime24h: null } for admins (no 404).",
                "tags": [
                    "Performance and uptime"
                ],
                "parameters": [
                    {
                        "name": "siteId",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Checks and rounded uptime percentage.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "checks": [
                                        {
                                            "id": 5012,
                                            "siteId": 12,
                                            "status": "up",
                                            "responseMs": 182,
                                            "statusCode": 200,
                                            "checkedAt": "2026-11-27T09:55:00.000Z"
                                        },
                                        {
                                            "id": 5013,
                                            "siteId": 12,
                                            "status": "up",
                                            "responseMs": 175,
                                            "statusCode": 200,
                                            "checkedAt": "2026-11-27T10:00:00.000Z"
                                        }
                                    ],
                                    "uptime24h": 100
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/uptime/{siteId}/sparkline": {
            "get": {
                "operationId": "uptimeSparkline",
                "summary": "Get recent response times",
                "description": "Returns the site's last 20 uptime checks, oldest first, as compact points for a mini chart.\n\n**Roles:** admin, developer, viewer (with access to the site).\n\n- ms is null for checks without a response time. An unknown site id returns { points: [] } for admins.",
                "tags": [
                    "Performance and uptime"
                ],
                "parameters": [
                    {
                        "name": "siteId",
                        "in": "path",
                        "required": true,
                        "description": "Site id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Up to 20 points.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "points": [
                                        {
                                            "ms": 182,
                                            "status": "up",
                                            "at": "2026-11-27T09:55:00.000Z"
                                        },
                                        {
                                            "ms": 175,
                                            "status": "up",
                                            "at": "2026-11-27T10:00:00.000Z"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin, has no all-sites access and no grant on this site. — \"Forbidden: no access to this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: no access to this site"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin",
                    "developer",
                    "viewer"
                ],
                "x-site-access": true,
                "x-personal-access-tokens": true
            }
        },
        "/api/usage/sites": {
            "get": {
                "operationId": "usageSites",
                "summary": "List usage for all sites",
                "description": "Cross-site overview: for every site, the latest disk and database size and the request and byte totals of the last 30 days (only when traffic logging is on).\n\n**Roles:** admin.\n\n- Registered from usage.ts as usageRoutes under /api/usage (admin only for the whole plugin).\n\n- requests30d/bytesOut30d are null when traffic logging is off or there is no traffic data in the window. Values are numbers converted from BigInt.",
                "tags": [
                    "Usage"
                ],
                "responses": {
                    "200": {
                        "description": "One summary per site.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "sites": [
                                        {
                                            "siteId": 12,
                                            "domain": "shop.example.com",
                                            "trafficLog": true,
                                            "diskBytes": 734003200,
                                            "dbBytes": 52428800,
                                            "measuredAt": "2026-11-27T10:00:00.000Z",
                                            "requests30d": 412870,
                                            "bytesOut30d": 21474836480
                                        },
                                        {
                                            "siteId": 14,
                                            "domain": "blog.example.com",
                                            "trafficLog": false,
                                            "diskBytes": 120586240,
                                            "dbBytes": null,
                                            "measuredAt": "2026-11-27T10:00:00.000Z",
                                            "requests30d": null,
                                            "bytesOut30d": null
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nMissing or invalid session token. An unknown or expired personal access token gets \"Invalid or expired access token\". — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/users": {
            "get": {
                "operationId": "usersList",
                "summary": "List users",
                "description": "Lists every panel user, oldest first. Admin only.\n\n**Roles:** admin.\n\n- Password hashes and TOTP fields are never returned.",
                "tags": [
                    "Users"
                ],
                "responses": {
                    "200": {
                        "description": "All users.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "users": [
                                        {
                                            "id": 1,
                                            "email": "ada@example.com",
                                            "role": "admin",
                                            "allSitesAccess": false,
                                            "createdAt": "2026-01-15T09:00:00.000Z"
                                        },
                                        {
                                            "id": 12,
                                            "email": "grace@example.com",
                                            "role": "developer",
                                            "allSitesAccess": true,
                                            "createdAt": "2026-11-27T10:00:00.000Z"
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "post": {
                "operationId": "usersCreate",
                "summary": "Create a user",
                "description": "Creates a panel user with a password and role. Admin only. New non-admin users have no site access until sites are granted with PUT /api/users/{id}/sites or allSitesAccess is turned on.\n\n**Roles:** admin.\n\n- The audit entry stores {email, role}.\n\n- Unknown body fields are removed silently.",
                "tags": [
                    "Users"
                ],
                "responses": {
                    "201": {
                        "description": "The created user.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 12,
                                    "email": "grace@example.com",
                                    "role": "developer",
                                    "allSitesAccess": false,
                                    "createdAt": "2026-11-27T10:00:00.000Z"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "The email is already taken. — \"A user with this email already exists.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "A user with this email already exists."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "email": {
                                        "type": "string",
                                        "description": "Login email. Must be unique. (3–254 chars (format not checked))"
                                    },
                                    "password": {
                                        "type": "string",
                                        "description": "Initial password (stored as a bcrypt hash). (8–128 chars)"
                                    },
                                    "role": {
                                        "type": "string",
                                        "description": "Role of the new user. (one of: admin, developer, viewer)"
                                    }
                                },
                                "required": [
                                    "email",
                                    "password",
                                    "role"
                                ]
                            },
                            "example": {
                                "email": "grace@example.com",
                                "password": "a-long-initial-password",
                                "role": "developer"
                            }
                        }
                    }
                }
            }
        },
        "/api/users/{id}": {
            "patch": {
                "operationId": "usersUpdate",
                "summary": "Update a user",
                "description": "Changes a user's email, role or blanket access to all sites. Admin only. Only the fields sent are changed. Admins cannot change their own role.\n\n**Roles:** admin.\n\n- Changing email to one that another user already has is not checked by the handler; the database unique constraint rejects it, which surfaces as a 500 error.\n\n- A role change applies immediately to the user's personal access tokens (role is read from the database per request), but existing JWT sessions keep the old role until they expire or the user logs in again.\n\n- The self-role check applies even when the role sent equals the current role.\n\n- There is no check that at least one admin remains when demoting an admin.",
                "tags": [
                    "Users"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "User id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The updated user.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 12,
                                    "email": "grace@example.com",
                                    "role": "viewer",
                                    "allSitesAccess": true,
                                    "createdAt": "2026-11-27T10:00:00.000Z"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "role is sent and {id} is the caller. — \"You cannot change your own role.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "You cannot change your own role."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No user with this id. — \"User not found.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "User not found."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": false,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "email": {
                                        "type": "string",
                                        "description": "New login email. (3–254 chars)"
                                    },
                                    "role": {
                                        "type": "string",
                                        "description": "New role. (one of: admin, developer, viewer)"
                                    },
                                    "allSitesAccess": {
                                        "type": "boolean",
                                        "description": "Grant (true) or remove (false) access to every site, including sites created later. Only matters for non-admins."
                                    }
                                }
                            },
                            "example": {
                                "role": "viewer",
                                "allSitesAccess": true
                            }
                        }
                    }
                }
            },
            "delete": {
                "operationId": "usersDelete",
                "summary": "Delete a user",
                "description": "Permanently deletes a user. Admin only. You cannot delete your own account or the last remaining admin.\n\n**Roles:** admin.\n\n- Deletion cascades in the database: the user's personal access tokens, site grants, dashboard presets, Telegram link, task comments, note shares, calendar attendance, and also the tasks they created, the notes they own and the calendar events they created are deleted. Tasks assigned to them become unassigned; their audit log entries keep the action with userId set to null.\n\n- JWT sessions of the deleted user are not revoked; they remain cryptographically valid until they expire.\n\n- The audit entry stores the deleted user's email.",
                "tags": [
                    "Users"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "User id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The user was deleted.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "The target is the only admin. — \"Cannot delete the last admin user.\"\n\n{id} is the caller. — \"You cannot delete your own account.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Cannot delete the last admin user."
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No user with this id. — \"User not found.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "User not found."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            }
        },
        "/api/users/{id}/sites": {
            "get": {
                "operationId": "usersSitesGet",
                "summary": "List a user's site grants",
                "description": "Returns the ids of the sites explicitly granted to a user, plus whether the user has blanket access to all sites. Admin only.\n\n**Roles:** admin.\n\n- Admins always have access to every site regardless of this list.",
                "tags": [
                    "Users"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "User id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Granted site ids and the blanket-access flag.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "siteIds": [
                                        3,
                                        7
                                    ],
                                    "allSitesAccess": false
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No user with this id. — \"User not found.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "User not found."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true
            },
            "put": {
                "operationId": "usersSitesSet",
                "summary": "Replace a user's site grants",
                "description": "Replaces all explicit site grants of a user with the given list, in one transaction. Admin only. Send an empty array to remove every grant.\n\n**Roles:** admin.\n\n- Site ids are not checked by the handler. A duplicate id or an id of a site that does not exist makes the database reject the transaction (surfaces as a 500 error) and the previous grants are kept.\n\n- Grants are ignored for admins and for users with allSitesAccess: true, who can access every site anyway.\n\n- Viewers stay read-only on the granted sites.",
                "tags": [
                    "Users"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "User id.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The new list of granted site ids.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "ok": true,
                                    "siteIds": [
                                        3,
                                        7
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "The personal access token is unknown, revoked or expired. — \"Invalid or expired access token\"\n\nNo token, or an invalid session. — \"Unauthorized\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid or expired access token"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "The caller is not an admin. — \"Forbidden: insufficient role\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Forbidden: insufficient role"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "No user with this id. — \"User not found.\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "User not found."
                                }
                            }
                        }
                    }
                },
                "x-auth": "user",
                "x-roles": [
                    "admin"
                ],
                "x-site-access": false,
                "x-personal-access-tokens": true,
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "siteIds": {
                                        "type": "array",
                                        "items": {},
                                        "description": "Ids of the sites the user may access (array of integers). (items: integer)"
                                    }
                                },
                                "required": [
                                    "siteIds"
                                ]
                            },
                            "example": {
                                "siteIds": [
                                    3,
                                    7
                                ]
                            }
                        }
                    }
                }
            }
        },
        "/api/webhooks/github/{token}": {
            "post": {
                "operationId": "webhookGithub",
                "summary": "Receive a GitHub push",
                "description": "GitHub webhook receiver. A signed push event for the site's configured branch starts a deploy of that site. Ping and other events are acknowledged without deploying.\n\n- Order of checks and every 200 response: (1) X-GitHub-Event \"ping\" → {\"pong\": true} (no token or signature check); (2) any event other than \"push\" → {\"skipped\": true, \"event\": \"<event>\"}; (3) token lookup (404) and signature check (401); (4) duplicate X-GitHub-Delivery within 10 minutes → {\"skipped\": true, \"reason\": \"Duplicate delivery (replay ignored)\"}; (5) branch mismatch → {\"skipped\": true, \"reason\": \"Branch '<pushed>' ≠ configured '<branch>'\"}; (6) no repoUrl → 400; (7) site status not active → {\"skipped\": true, \"reason\": \"Site status is '<status>'\"}; (8) a deployment row in status running → {\"skipped\": true, \"reason\": \"Deploy already in progress\"}; otherwise the deploy starts → {\"triggered\": true, \"deploymentId\": <id>, \"commit\": \"<first 7 chars of after>\"}.\n\n- Branch rule: \"refs/heads/\" is stripped from ref and the rest must equal the site's branch exactly. Tag pushes (refs/tags/…) are therefore always skipped as a branch mismatch.\n\n- The deploy always builds the branch HEAD (not necessarily the \"after\" commit). Webhook pushes are never queued: if a deploy is running, the push is skipped.\n\n- Behaviour differs from a manual deploy: the webhook starts the deploy without the site's domain, health-check settings, server and hook scripts. Consequently no post-deploy health check or auto-rollback runs, no external deploy notification (Slack/Discord/Telegram/generic) is sent, the deploy runs on the panel's local server even if the site lives on a remote server, and the existing hooks/pre-deploy.sh and hooks/post-deploy.sh files are deleted before the deploy (so the hooks do not run). Deploy-time test settings are applied.\n\n- Content types other than application/json are rejected by Fastify with 415 before the handler runs (this includes GitHub's application/x-www-form-urlencoded option). A body that is not valid JSON, or a push payload without ref/after, ends in a 500 error.\n\n- If another deploy claims the site at the same moment, runDeploy's \"Deploy already in progress\" error is not caught here and surfaces as a 500.\n\n- Replay protection is in memory (lost on API restart).\n\n- Audit entries come from the deploy itself (deploy.success / deploy.failed when it ends).",
                "tags": [
                    "Push-to-deploy webhook"
                ],
                "parameters": [
                    {
                        "name": "token",
                        "in": "path",
                        "required": true,
                        "description": "The site's webhook token (see POST /api/sites/{id}/webhook-token). Also the HMAC secret.",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "X-GitHub-Event",
                        "in": "header",
                        "required": true,
                        "description": "GitHub event name. \"ping\" is acknowledged, \"push\" is processed, anything else is skipped.",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "X-Hub-Signature-256",
                        "in": "header",
                        "required": true,
                        "description": "sha256=<hex HMAC-SHA256 of the raw request body, keyed with the webhook token>. Required for push events. (exactly \"sha256=\" + 64 hex chars)",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "X-GitHub-Delivery",
                        "in": "header",
                        "required": false,
                        "description": "GitHub delivery id; used for replay protection (a repeated id within 10 minutes is ignored).",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "Content-Type",
                        "in": "header",
                        "required": true,
                        "description": "Must be application/json (set \"Content type: application/json\" in the GitHub webhook settings). (application/json)",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Deploy triggered.",
                        "content": {
                            "application/json": {
                                "example": {
                                    "triggered": true,
                                    "deploymentId": 349,
                                    "commit": "a3f9c21"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Signature valid and branch matches, but the site has no repoUrl. — \"No repository URL configured for this site\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "No repository URL configured for this site"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "X-Hub-Signature-256 is missing or does not match the HMAC of the raw body. — \"Invalid signature\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Invalid signature"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "push event and no site has this webhook token. — \"Unknown webhook token\"",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "example": {
                                    "error": "Unknown webhook token"
                                }
                            }
                        }
                    }
                },
                "x-auth": "signature",
                "x-roles": [],
                "x-site-access": false,
                "x-personal-access-tokens": false,
                "security": [],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "ref": {
                                        "type": "string",
                                        "description": "Pushed ref, e.g. refs/heads/main. (not validated)"
                                    },
                                    "after": {
                                        "type": "string",
                                        "description": "Commit SHA after the push; the first 7 characters are echoed in the response. (not validated)"
                                    }
                                },
                                "required": [
                                    "ref",
                                    "after"
                                ]
                            },
                            "example": {
                                "ref": "refs/heads/main",
                                "after": "a3f9c21d8e4b5f6a7c8d9e0f1a2b3c4d5e6f7a8b",
                                "repository": {
                                    "full_name": "example/shop",
                                    "clone_url": "https://github.com/example/shop.git",
                                    "ssh_url": "git@github.com:example/shop.git"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "securitySchemes": {
            "bearerAuth": {
                "type": "http",
                "scheme": "bearer",
                "bearerFormat": "orch_<64 hex characters> (personal access token)",
                "description": "Create a token in Settings → Security → Personal Access Tokens."
            },
            "sessionAuth": {
                "type": "http",
                "scheme": "bearer",
                "bearerFormat": "JWT",
                "description": "The browser login session. Personal access tokens are not accepted by these operations."
            }
        },
        "schemas": {
            "Error": {
                "type": "object",
                "properties": {
                    "error": {
                        "type": "string"
                    },
                    "code": {
                        "type": "string"
                    }
                },
                "required": [
                    "error"
                ]
            },
            "FastifyError": {
                "type": "object",
                "description": "Validation, rate-limit and not-found errors.",
                "properties": {
                    "statusCode": {
                        "type": "integer"
                    },
                    "code": {
                        "type": "string"
                    },
                    "error": {
                        "type": "string"
                    },
                    "message": {
                        "type": "string"
                    }
                }
            }
        }
    }
}