{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/shruwd-io/json-schema/shruwd-io-ingest-token-schema.json",
  "title": "IngestToken",
  "x-generated": "2026-11-24",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/shruwd-io-openapi.json#/components/schemas/IngestToken",
  "type": "object",
  "required": [
    "token",
    "tokenPrefix",
    "label",
    "endpoint",
    "revokedPrevious",
    "setup"
  ],
  "properties": {
    "token": {
      "type": "string",
      "description": "Shown once. Stored hashed; a lost token is replaced, not recovered."
    },
    "tokenPrefix": {
      "type": "string",
      "description": "Enough to recognise the token in settings, never enough to use it."
    },
    "label": {
      "type": "string"
    },
    "endpoint": {
      "type": "string",
      "format": "uri",
      "description": "Where to POST log lines, with `Authorization: Bearer <token>`."
    },
    "revokedPrevious": {
      "type": "integer",
      "description": "How many earlier tokens this one replaced."
    },
    "setup": {
      "type": "object",
      "description": "The three ways to get logs to the endpoint. Show the one that fits the site.",
      "required": [
        "httpDrain",
        "cloudflareLogpush",
        "cloudflareWorker"
      ],
      "properties": {
        "httpDrain": {
          "type": "object",
          "required": [
            "endpoint",
            "header",
            "contentType",
            "note"
          ],
          "properties": {
            "endpoint": {
              "type": "string",
              "format": "uri"
            },
            "header": {
              "type": "string",
              "const": "X-Shruwd-Ingest-Token"
            },
            "contentType": {
              "type": "string",
              "const": "application/x-ndjson"
            },
            "note": {
              "type": "string"
            }
          }
        },
        "cloudflareLogpush": {
          "type": "object",
          "description": "A Logpush job with an HTTP destination (Cloudflare Enterprise zones).",
          "required": [
            "destinationUrl",
            "dataset",
            "fields",
            "filter",
            "note"
          ],
          "properties": {
            "destinationUrl": {
              "type": "string",
              "format": "uri",
              "description": "The endpoint with the token as a `header_Authorization` URL parameter, which Logpush turns into a request header. Contains the token."
            },
            "dataset": {
              "type": "string",
              "const": "http_requests"
            },
            "fields": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "filter": {
              "type": "string",
              "description": "The job's filter as the Logpush API takes it, a JSON string, keeping the job to the brand's domain and its www host."
            },
            "note": {
              "type": "string"
            }
          }
        },
        "cloudflareWorker": {
          "type": "object",
          "description": "The reference forwarder Worker for any other Cloudflare plan or CDN-served site.",
          "required": [
            "note",
            "ingestUrl",
            "secretName"
          ],
          "properties": {
            "note": {
              "type": "string"
            },
            "ingestUrl": {
              "type": "string",
              "format": "uri"
            },
            "secretName": {
              "type": "string",
              "const": "SHRUWD_INGEST_TOKEN"
            }
          }
        }
      }
    }
  }
}