{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/sourcefinch-com/json-schema/sourcefinch-com-watch-schema.json",
  "title": "Watch",
  "description": "The result of watching a URL in one call: the source that was created, its first run, the first records and what the preview found. The source exists and keeps its schedule whatever the outcome of the first run.",
  "x-generated": "2026-11-25",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/sourcefinch-com-openapi.json#/components/schemas/Watch",
  "type": "object",
  "properties": {
    "source": {
      "$ref": "#/$defs/Source"
    },
    "run": {
      "anyOf": [
        {
          "$ref": "#/$defs/Run"
        },
        {
          "type": "null"
        }
      ],
      "description": "The first run in its state when the wait ended, or null when it could not be queued"
    },
    "outcome": {
      "type": "string",
      "enum": [
        "records_ready",
        "run_pending",
        "run_degraded",
        "run_failed",
        "run_not_queued"
      ],
      "description": "records_ready: the first run validated and `records` holds its first page. run_pending: still queued or running when the wait ended. run_degraded: finished, but held for review. run_failed: the run failed or was blocked (failed runs are free). run_not_queued: the source was created but its first run was refused, for example by the run quota."
    },
    "message": {
      "type": "string",
      "description": "What happened and what to do next, in one or two sentences"
    },
    "records": {
      "type": "array",
      "items": {},
      "description": "The first records of the first run (up to 20); empty unless outcome is records_ready"
    },
    "evidence_ids": {
      "type": "array",
      "items": {
        "type": "string",
        "format": "uuid"
      },
      "description": "The captures the records were read from"
    },
    "preview": {
      "type": "object",
      "properties": {
        "url": {
          "type": "string",
          "description": "The address the source was saved with (after any approved redirects)"
        },
        "format": {
          "type": "string",
          "description": "html, json, xml or csv"
        },
        "needs_browser": {
          "type": "boolean",
          "description": "The page renders its content with JavaScript; an HTTP source may miss records"
        },
        "candidates": {
          "type": "integer",
          "description": "How many record groups the preview found"
        },
        "chosen": {
          "type": "object",
          "properties": {
            "index": {
              "type": "integer"
            },
            "label": {
              "type": "string"
            },
            "records": {
              "type": "integer",
              "description": "Records found in the sample"
            },
            "confidence": {
              "type": "number"
            },
            "low_confidence": {
              "type": "boolean"
            },
            "key_field": {
              "type": [
                "string",
                "null"
              ]
            },
            "fields": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          "required": [
            "index",
            "label",
            "records",
            "confidence",
            "low_confidence",
            "key_field",
            "fields"
          ],
          "additionalProperties": false
        },
        "alternatives": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "kind": {
                "type": "string"
              },
              "url": {
                "type": "string"
              },
              "title": {
                "type": "string"
              },
              "reason": {
                "type": "string"
              }
            },
            "required": [
              "kind",
              "url",
              "title",
              "reason"
            ],
            "additionalProperties": false
          },
          "description": "Feeds, APIs and downloads that carry the same data and are usually better sources than the page"
        }
      },
      "required": [
        "url",
        "format",
        "needs_browser",
        "candidates",
        "chosen",
        "alternatives"
      ],
      "additionalProperties": false
    },
    "next": {
      "type": "object",
      "properties": {
        "source_url": {
          "type": "string"
        },
        "run_url": {
          "type": [
            "string",
            "null"
          ]
        },
        "records_url": {
          "type": "string"
        },
        "changes_url": {
          "type": "string"
        }
      },
      "required": [
        "source_url",
        "run_url",
        "records_url",
        "changes_url"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "source",
    "run",
    "outcome",
    "message",
    "records",
    "evidence_ids",
    "preview",
    "next"
  ],
  "additionalProperties": false,
  "$defs": {
    "AcquisitionPath": {
      "type": "string",
      "enum": [
        "official_api",
        "bulk_file",
        "open_data_portal",
        "licensed_feed",
        "publisher_partnership",
        "pay_per_crawl",
        "public_web",
        "customer_authorized",
        "records_request",
        "manual_upload"
      ]
    },
    "FailureClass": {
      "type": "string",
      "enum": [
        "transient_network",
        "origin_5xx",
        "rate_limited",
        "robots_unavailable",
        "robots_disallowed",
        "blocked_challenge",
        "http_4xx",
        "payment_required",
        "redirect_blocked",
        "budget_exceeded",
        "policy_refused",
        "extraction_failed",
        "validation_failed"
      ]
    },
    "Run": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "source_id": {
          "type": "string",
          "format": "uuid"
        },
        "source_version": {
          "type": [
            "integer",
            "null"
          ]
        },
        "status": {
          "$ref": "#/$defs/RunStatus"
        },
        "trigger": {
          "$ref": "#/$defs/RunTrigger"
        },
        "attempt": {
          "type": "integer"
        },
        "created_at": {
          "type": "string",
          "description": "ISO-8601 timestamp (UTC)"
        },
        "completed_at": {
          "type": [
            "string",
            "null"
          ],
          "description": "ISO-8601 timestamp (UTC)"
        },
        "error": {
          "type": [
            "string",
            "null"
          ]
        },
        "validation": {
          "type": [
            "object",
            "null"
          ],
          "additionalProperties": {}
        },
        "health": {
          "type": [
            "object",
            "null"
          ],
          "additionalProperties": {}
        },
        "metrics": {
          "type": [
            "object",
            "null"
          ],
          "additionalProperties": {}
        },
        "changes": {
          "type": [
            "object",
            "null"
          ],
          "additionalProperties": {}
        },
        "acquisition_path": {
          "anyOf": [
            {
              "$ref": "#/$defs/AcquisitionPath"
            },
            {
              "type": "null"
            }
          ]
        },
        "usage_rights": {
          "anyOf": [
            {
              "$ref": "#/$defs/UsageRights"
            },
            {
              "type": "null"
            }
          ]
        },
        "failure_class": {
          "anyOf": [
            {
              "$ref": "#/$defs/FailureClass"
            },
            {
              "type": "null"
            }
          ],
          "description": "Why the last attempt failed; transient classes are retried automatically"
        },
        "compliance": {
          "description": "Compliance state at capture: acquisition path, usage rights, terms posture, robots.txt hash and verdict, AI/TDM signals, crawler identity, pay-per-crawl",
          "type": [
            "object",
            "null"
          ],
          "additionalProperties": {}
        }
      },
      "required": [
        "id",
        "source_id",
        "source_version",
        "status",
        "trigger",
        "attempt",
        "created_at",
        "completed_at",
        "error",
        "validation",
        "health",
        "metrics",
        "changes",
        "acquisition_path",
        "usage_rights",
        "failure_class",
        "compliance"
      ],
      "additionalProperties": false
    },
    "RunStatus": {
      "type": "string",
      "enum": [
        "queued",
        "running",
        "success",
        "degraded",
        "failed",
        "blocked"
      ]
    },
    "RunTrigger": {
      "type": "string",
      "enum": [
        "manual",
        "schedule",
        "api"
      ]
    },
    "Schedule": {
      "type": "string",
      "enum": [
        "manual",
        "quarter_hourly",
        "hourly",
        "daily",
        "weekly"
      ]
    },
    "Source": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "project_id": {
          "type": "string",
          "format": "uuid"
        },
        "name": {
          "type": "string"
        },
        "url": {
          "type": "string"
        },
        "recipe": {
          "type": "object",
          "additionalProperties": {},
          "description": "A recipe@1 document (see the Recipe schema)"
        },
        "version": {
          "type": "integer"
        },
        "recipe_version_id": {
          "default": null,
          "description": "The immutable reviewed recipe version, or null for a custom source",
          "type": [
            "string",
            "null"
          ],
          "format": "uuid"
        },
        "schedule": {
          "$ref": "#/$defs/Schedule"
        },
        "key_field": {
          "type": [
            "string",
            "null"
          ]
        },
        "next_run_at": {
          "type": [
            "string",
            "null"
          ],
          "description": "ISO-8601 timestamp (UTC)"
        },
        "created_at": {
          "type": "string",
          "description": "ISO-8601 timestamp (UTC)"
        },
        "updated_at": {
          "type": "string",
          "description": "ISO-8601 timestamp (UTC)"
        }
      },
      "required": [
        "id",
        "project_id",
        "name",
        "url",
        "recipe",
        "version",
        "schedule",
        "key_field",
        "next_run_at",
        "created_at",
        "updated_at"
      ],
      "description": "A monitored source: a URL, a recipe and a schedule.",
      "additionalProperties": false
    },
    "UsageRights": {
      "type": "object",
      "properties": {
        "basis": {
          "type": "string",
          "enum": [
            "catalog",
            "private_recipe"
          ]
        },
        "licence_basis": {
          "type": "string",
          "enum": [
            "public_domain_gov",
            "open_data_licence",
            "site_terms",
            "licensed_feed",
            "customer_supplied",
            "unknown"
          ]
        },
        "licence_id": {
          "type": [
            "string",
            "null"
          ]
        },
        "commercial_use": {
          "type": "string",
          "enum": [
            "allowed",
            "restricted",
            "prohibited",
            "unknown"
          ]
        },
        "redistribution": {
          "type": "string",
          "enum": [
            "allowed",
            "restricted",
            "prohibited",
            "unknown"
          ]
        },
        "attribution_required": {
          "type": "boolean"
        },
        "attribution_text": {
          "type": [
            "string",
            "null"
          ]
        },
        "terms_snapshot_sha256": {
          "type": [
            "string",
            "null"
          ]
        },
        "reviewed_at": {
          "type": [
            "string",
            "null"
          ],
          "description": "ISO-8601 timestamp (UTC)"
        },
        "usage_rights_id": {
          "type": "string",
          "format": "uuid"
        },
        "version": {
          "type": "integer"
        }
      },
      "required": [
        "basis",
        "licence_basis",
        "commercial_use",
        "redistribution",
        "attribution_required"
      ],
      "description": "Usage rights snapshotted at capture (documented provenance and terms posture; not legal advice)",
      "additionalProperties": false
    }
  }
}