{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://lexlint.io/schema/activities.schema.json",
  "title": "ACTIVITIES.md front matter",
  "description": "The record at the top of a repository's ACTIVITIES.md: which legal activities each component it ships performs or enables, which it does not, and which counterparties it necessarily talks to. Ids come from the activity registry at https://lexlint.io/activities/v1, and this schema is generated from that registry: a role id, a retired id and a deployment activity on a library fail here.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "version",
    "registry",
    "date",
    "components"
  ],
  "properties": {
    "version": {
      "const": 1,
      "description": "The file format's version."
    },
    "registry": {
      "const": "https://lexlint.io/activities/v1",
      "description": "The activity list the ids come from, as its versioned URL."
    },
    "date": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
      "description": "The day the declaration was last reviewed, YYYY-MM-DD."
    },
    "declared_by": {
      "type": "string",
      "minLength": 1,
      "description": "Who reviewed it: a handle, a team, the maintainers."
    },
    "components": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/component"
      }
    }
  },
  "$defs": {
    "component": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "shape",
        "aggregate",
        "activities"
      ],
      "anyOf": [
        {
          "required": [
            "purl"
          ]
        },
        {
          "required": [
            "name"
          ]
        }
      ],
      "properties": {
        "purl": {
          "type": "string",
          "pattern": "^pkg:[a-z][a-z0-9.+-]*/\\S+$",
          "description": "The package URL (ECMA-427)."
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "description": "A display name, for a component on no registry."
        },
        "shape": {
          "enum": [
            "application",
            "framework",
            "library",
            "protocol-spec",
            "runtime",
            "service"
          ]
        },
        "aggregate": {
          "enum": [
            "complete",
            "incomplete",
            "unknown"
          ],
          "description": "complete: the list covers every activity the component carries."
        },
        "activities": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/activity"
          }
        },
        "not": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/ruledOut"
          }
        },
        "talks_to": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/counterparty"
          }
        }
      },
      "if": {
        "properties": {
          "shape": {
            "enum": [
              "framework",
              "library",
              "protocol-spec",
              "runtime"
            ]
          }
        },
        "required": [
          "shape"
        ]
      },
      "then": {
        "properties": {
          "activities": {
            "items": {
              "properties": {
                "id": {
                  "not": {
                    "enum": [
                      "publishes_adult_content",
                      "operates_social_platform",
                      "serves_minors",
                      "operates_app_store",
                      "ships_mobile_app"
                    ]
                  }
                }
              }
            }
          }
        }
      }
    },
    "activity": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "mentioned",
        "enabled",
        "note"
      ],
      "properties": {
        "id": {
          "enum": [
            "crawls_web",
            "trains_models",
            "generates_content",
            "deploys_chatbot",
            "processes_voice",
            "processes_biometrics",
            "automated_outreach",
            "high_risk_decisions",
            "aggregates_content",
            "statutory_requests",
            "records_calls",
            "records_text_chat",
            "tracks_devices",
            "employment_decisions",
            "credit_decisions",
            "insurance_decisions",
            "housing_decisions",
            "education_decisions",
            "health_care_decisions",
            "public_services_decisions",
            "justice_decisions",
            "publishes_adult_content",
            "operates_social_platform",
            "serves_minors",
            "operates_app_store",
            "ships_mobile_app",
            "distributes_software_product"
          ]
        },
        "mentioned": {
          "enum": [
            "performs",
            "enables"
          ]
        },
        "enabled": {
          "enum": [
            "by_default",
            "requires_configuration",
            "requires_dependency",
            "requires_environment"
          ]
        },
        "where": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "since": {
          "type": "string",
          "minLength": 1
        },
        "until": {
          "type": "string",
          "minLength": 1
        },
        "note": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200,
          "not": {
            "pattern": "\\b([Cc]ompliant|COMPLIANT|[Cc]ertified|CERTIFIED|[Ss]afe|SAFE)\\b"
          }
        }
      },
      "if": {
        "properties": {
          "id": {
            "enum": [
              "publishes_adult_content",
              "operates_social_platform",
              "serves_minors",
              "operates_app_store",
              "ships_mobile_app",
              "distributes_software_product"
            ]
          }
        },
        "required": [
          "id"
        ]
      },
      "then": {
        "properties": {
          "mentioned": {
            "const": "performs"
          }
        }
      }
    },
    "ruledOut": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "why"
      ],
      "properties": {
        "id": {
          "enum": [
            "crawls_web",
            "trains_models",
            "generates_content",
            "deploys_chatbot",
            "processes_voice",
            "processes_biometrics",
            "automated_outreach",
            "high_risk_decisions",
            "aggregates_content",
            "statutory_requests",
            "records_calls",
            "records_text_chat",
            "tracks_devices",
            "employment_decisions",
            "credit_decisions",
            "insurance_decisions",
            "housing_decisions",
            "education_decisions",
            "health_care_decisions",
            "public_services_decisions",
            "justice_decisions",
            "publishes_adult_content",
            "operates_social_platform",
            "serves_minors",
            "operates_app_store",
            "ships_mobile_app",
            "distributes_software_product"
          ]
        },
        "why": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "counterparty": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "host",
        "required",
        "why"
      ],
      "properties": {
        "host": {
          "type": "string",
          "pattern": "^(?=.{1,253}$)(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\\.)+[A-Za-z][A-Za-z0-9-]{0,61}[A-Za-z0-9]$"
        },
        "party": {
          "type": "string",
          "minLength": 1
        },
        "jurisdiction": {
          "type": "string",
          "pattern": "^[a-z]{2}(?:/[a-z0-9-]+)*$"
        },
        "required": {
          "type": "boolean"
        },
        "why": {
          "type": "string",
          "minLength": 1
        }
      }
    }
  }
}
