{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://ha-barkley.github.io/disclosure/v1/schema.json",
  "title": "disclosure.yaml, version 1",
  "description": "What a Home Assistant integration, card or app connects to and handles, as stated by its developer. Version 1 never changes; any change is a new version.",
  "type": "object",
  "required": ["version"],
  "properties": {
    "version": { "const": 1, "description": "The version of this specification the file follows." },
    "connections": { "type": "array", "items": { "$ref": "#/$defs/connection" }, "description": "Servers outside Home Assistant that the app contacts. An empty list says it contacts none." },
    "links": { "type": "array", "items": { "$ref": "#/$defs/link" }, "description": "Sites the app only links to. They open when a person selects the link." },
    "pages": { "type": "array", "items": { "$ref": "#/$defs/page" }, "description": "Pages and endpoints the app adds that answer without a Home Assistant login." },
    "credentials": { "type": "array", "items": { "$ref": "#/$defs/credential" }, "description": "Passwords, tokens and keys the app asks the user for." },
    "login_tokens": { "type": "array", "items": { "$ref": "#/$defs/login_token" }, "description": "Home Assistant login tokens the app creates, reads or hands on. An empty list says it uses none." },
    "home_assistant_access": { "type": "array", "items": { "$ref": "#/$defs/home_assistant_access" }, "description": "Parts of Home Assistant the app uses beyond its own entities and settings. An empty list says it uses none." },
    "embedded_keys": { "type": "array", "items": { "$ref": "#/$defs/embedded_key" }, "description": "Keys, tokens and certificates written into the code the app ships." },
    "telemetry": { "type": "array", "items": { "$ref": "#/$defs/telemetry" }, "description": "Usage statistics, analytics and crash reports. An empty list says the app sends none." },
    "encoded_content": { "type": "array", "items": { "$ref": "#/$defs/encoded_content" }, "description": "Large base64, hex or compressed content in the code." },
    "compiled_code": { "type": "array", "items": { "$ref": "#/$defs/compiled_code" }, "description": "Compiled files the app ships, such as native modules or Python bytecode. An empty list says it ships none." },
    "runtime_downloads": { "type": "array", "items": { "$ref": "#/$defs/runtime_download" }, "description": "Code the app downloads and runs while it runs. An empty list says it downloads none." },
    "generated_files": { "type": "array", "items": { "$ref": "#/$defs/generated_file" }, "description": "Files the app writes outside its own storage." }
  },
  "patternProperties": { "^x-": {} },
  "additionalProperties": false,

  "$defs": {
    "text": { "type": "string", "minLength": 1 },
    "host": {
      "type": "string",
      "description": "A host name, optionally starting with *. for any subdomain, or an IP address.",
      "pattern": "^((\\*\\.)?[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?(\\.[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?)*|[0-9]{1,3}(\\.[0-9]{1,3}){3}|[0-9A-Fa-f:]*:[0-9A-Fa-f:.]*)$"
    },
    "url": { "type": "string", "pattern": "^https?://[^\\s]+$" },
    "destination": {
      "description": "One host, or a list of hosts that share everything else in the entry.",
      "oneOf": [
        { "$ref": "#/$defs/host" },
        { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "$ref": "#/$defs/host" } }
      ]
    },
    "destination_set_by": {
      "enum": ["setup", "setting", "server_reply"],
      "description": "Who supplies the address when it isn't written in the code. setup: the user enters it while setting the app up. setting: a setting the user can change later. server_reply: a server's answer tells the app where to go next."
    },
    "run_by": {
      "enum": ["developer", "vendor", "third_party", "user"],
      "description": "Who runs the server. developer: the app's developer. vendor: the company or public body whose device or service the app is for. third_party: anyone else, such as a map tile service. user: the user's own device or server."
    },
    "component": { "$ref": "#/$defs/text", "description": "Which integration, card or app in the repository the entry is about, by its domain or name. Only needed when the repository has more than one." },
    "sends": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "enum": ["ip_address", "physical_location", "map_area", "entity_states", "credentials", "device_ids", "ha_address", "media", "personal_details", "versions"]
      },
      "description": "What requests carry, beyond the request itself. An empty list says nothing more. ip_address: the user's IP address. physical_location: coordinates or a street address, of the home, a person or a device. map_area: the part of a map being viewed. entity_states: states or attributes of Home Assistant entities. credentials: a password, token or key the user gave. device_ids: serial numbers, MAC addresses or account ids of devices. ha_address: the address of the user's Home Assistant. media: camera images, audio or video. personal_details: a name, email address or phone number. versions: the app's or Home Assistant's version."
    },

    "connection": {
      "type": "object",
      "required": ["source", "purpose", "when"],
      "anyOf": [{ "required": ["destination"] }, { "required": ["destination_set_by"] }],
      "properties": {
        "destination": { "$ref": "#/$defs/destination" },
        "destination_set_by": { "$ref": "#/$defs/destination_set_by" },
        "port": { "type": "integer", "minimum": 1, "maximum": 65535, "description": "Only when it isn't the usual port for the protocol." },
        "source": { "enum": ["home_assistant", "browser"], "description": "Where the connection starts: Home Assistant itself, or the browser showing the dashboard." },
        "purpose": { "$ref": "#/$defs/text" },
        "run_by": { "$ref": "#/$defs/run_by" },
        "run_by_name": { "$ref": "#/$defs/text", "description": "The name of whoever runs the server, such as a company or a town." },
        "network": { "enum": ["home", "internet", "either"], "description": "Where the server is: on the user's home network, on the internet, or either one, depending on the user's setup." },
        "encrypted": { "enum": ["always", "never", "setting"], "description": "Whether the connection is encrypted (https, wss, TLS). setting: a setting decides, named in encryption_setting." },
        "encryption_setting": { "$ref": "#/$defs/text", "description": "The setting that turns encryption on, as users see it or write it." },
        "when": { "enum": ["always", "setting", "user_action"], "description": "always: whenever the app runs. setting: only when a setting turns it on. user_action: only when a person does something, such as opening a popup." },
        "setting": { "$ref": "#/$defs/text", "description": "The setting's name as users see it or write it." },
        "condition": { "$ref": "#/$defs/text", "description": "The exact condition in words, when it's more than one setting." },
        "on_by_default": { "type": "boolean", "description": "true when the setting that turns this connection on is on out of the box." },
        "sends": { "$ref": "#/$defs/sends" },
        "component": { "$ref": "#/$defs/component" },
        "note": { "$ref": "#/$defs/text" }
      },
      "allOf": [
        { "if": { "properties": { "when": { "const": "setting" } }, "required": ["when"] }, "then": { "required": ["setting"] } },
        { "if": { "properties": { "destination_set_by": { "const": "setting" } }, "required": ["destination_set_by"] }, "then": { "required": ["setting"] } },
        { "if": { "properties": { "encrypted": { "const": "setting" } }, "required": ["encrypted"] }, "then": { "required": ["encryption_setting"] } }
      ],
      "patternProperties": { "^x-": {} },
      "additionalProperties": false
    },

    "link": {
      "type": "object",
      "anyOf": [{ "required": ["host"] }, { "required": ["url"] }],
      "properties": {
        "host": { "$ref": "#/$defs/host" },
        "url": { "$ref": "#/$defs/url" },
        "purpose": { "$ref": "#/$defs/text" },
        "component": { "$ref": "#/$defs/component" },
        "note": { "$ref": "#/$defs/text" }
      },
      "patternProperties": { "^x-": {} },
      "additionalProperties": false
    },

    "page": {
      "type": "object",
      "required": ["path", "protection", "purpose"],
      "properties": {
        "path": { "type": "string", "pattern": "^/" },
        "protection": { "enum": ["none", "own_token", "signed_link", "webhook"], "description": "What stands in for the Home Assistant login. none: nothing, anyone who can reach Home Assistant gets an answer. own_token: the app checks a token of its own. signed_link: a link Home Assistant signed. webhook: a Home Assistant webhook id." },
        "local_only": { "type": "boolean", "description": "true when it only answers on the local network." },
        "purpose": { "$ref": "#/$defs/text" },
        "checks": { "$ref": "#/$defs/text", "description": "What the app checks itself before it answers." },
        "component": { "$ref": "#/$defs/component" },
        "note": { "$ref": "#/$defs/text" }
      },
      "patternProperties": { "^x-": {} },
      "additionalProperties": false
    },

    "credential": {
      "type": "object",
      "required": ["what", "asked_in", "sent_to"],
      "properties": {
        "what": { "$ref": "#/$defs/text" },
        "asked_in": { "enum": ["config_flow", "options_flow", "yaml", "card_config", "environment"] },
        "stored_in": { "enum": ["config_entry", "secrets_yaml", "card_config", "own_storage"] },
        "sent_to": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": { "anyOf": [{ "$ref": "#/$defs/host" }, { "const": "setup_address" }] },
          "description": "The hosts it goes to. setup_address: the address the user entered at setup."
        },
        "component": { "$ref": "#/$defs/component" },
        "note": { "$ref": "#/$defs/text" }
      },
      "patternProperties": { "^x-": {} },
      "additionalProperties": false
    },

    "login_token": {
      "type": "object",
      "required": ["kind", "purpose"],
      "properties": {
        "kind": { "enum": ["long_lived", "refresh", "access", "dashboard_session"], "description": "long_lived: a long-lived access token. refresh: a refresh token, which can make new access tokens. access: a short-lived access token. dashboard_session: the token of the person using the dashboard, which a card can read in the browser." },
        "admin_user": { "type": "boolean", "description": "true when the token belongs to an administrator." },
        "lifetime": { "type": "string", "pattern": "^[1-9][0-9]* (minutes?|hours?|days?)$", "description": "How long the token lasts, such as \"30 minutes\" or \"365 days\"." },
        "given_to": {
          "type": "array",
          "uniqueItems": true,
          "items": { "anyOf": [{ "$ref": "#/$defs/host" }, { "const": "setup_address" }] },
          "description": "Where the token goes outside Home Assistant. setup_address: the address the user entered at setup. An empty list says it stays in Home Assistant, or in the browser for a dashboard_session."
        },
        "purpose": { "$ref": "#/$defs/text" },
        "component": { "$ref": "#/$defs/component" },
        "note": { "$ref": "#/$defs/text" }
      },
      "patternProperties": { "^x-": {} },
      "additionalProperties": false
    },

    "home_assistant_access": {
      "type": "object",
      "required": ["uses", "purpose"],
      "properties": {
        "uses": {
          "enum": ["secrets_file", "other_apps_settings", "other_apps_credentials", "user_list", "change_users", "login_store", "storage_files", "supervisor_api", "location_history", "patches_home_assistant", "actions"],
          "description": "secrets_file: reads secrets.yaml. other_apps_settings: reads other integrations' options. other_apps_credentials: reads other integrations' stored passwords, tokens or keys. user_list: reads the list of users. change_users: adds, changes or removes users. login_store: reads Home Assistant's login store. storage_files: reads or writes files in .storage directly. supervisor_api: calls the Supervisor API. location_history: reads location history for many entities at once. patches_home_assistant: replaces or wraps Home Assistant's own code while it runs. actions: runs actions on entities that aren't its own, or actions that change Home Assistant itself, listed in actions."
        },
        "actions": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "pattern": "^[a-z0-9_]+\\.[a-z0-9_]+$" }, "description": "The actions, such as lock.unlock on any lock, or homeassistant.restart." },
        "purpose": { "$ref": "#/$defs/text" },
        "component": { "$ref": "#/$defs/component" },
        "note": { "$ref": "#/$defs/text" }
      },
      "allOf": [
        { "if": { "properties": { "uses": { "const": "actions" } }, "required": ["uses"] }, "then": { "required": ["actions"] } }
      ],
      "patternProperties": { "^x-": {} },
      "additionalProperties": false
    },

    "embedded_key": {
      "type": "object",
      "required": ["file", "kind", "same_for_every_user"],
      "properties": {
        "file": { "$ref": "#/$defs/text" },
        "kind": { "enum": ["vendor_client_key", "vendor_certificate", "public_key", "test_value", "service_key"], "description": "service_key: a key for a service the developer runs." },
        "same_for_every_user": { "type": "boolean" },
        "component": { "$ref": "#/$defs/component" },
        "note": { "$ref": "#/$defs/text" }
      },
      "patternProperties": { "^x-": {} },
      "additionalProperties": false
    },

    "telemetry": {
      "type": "object",
      "required": ["destination", "type", "contents", "on_by_default"],
      "properties": {
        "destination": { "$ref": "#/$defs/destination" },
        "type": { "enum": ["usage_stats", "analytics", "crash_reports"] },
        "contents": { "$ref": "#/$defs/text", "description": "What's in a report, and how often it's sent." },
        "on_by_default": { "type": "boolean", "description": "true when it's on out of the box." },
        "setting": { "$ref": "#/$defs/text", "description": "The setting that turns it on or off." },
        "run_by": { "$ref": "#/$defs/run_by" },
        "run_by_name": { "$ref": "#/$defs/text" },
        "sends": { "$ref": "#/$defs/sends" },
        "component": { "$ref": "#/$defs/component" },
        "note": { "$ref": "#/$defs/text" }
      },
      "patternProperties": { "^x-": {} },
      "additionalProperties": false
    },

    "encoded_content": {
      "type": "object",
      "required": ["file", "kind"],
      "properties": {
        "file": { "$ref": "#/$defs/text" },
        "kind": { "enum": ["image", "font", "key", "lookup_table", "data", "code"] },
        "component": { "$ref": "#/$defs/component" },
        "note": { "$ref": "#/$defs/text" }
      },
      "patternProperties": { "^x-": {} },
      "additionalProperties": false
    },

    "compiled_code": {
      "type": "object",
      "required": ["file", "built_by"],
      "properties": {
        "file": { "$ref": "#/$defs/text" },
        "built_from": { "$ref": "#/$defs/url", "description": "Where its source code is, such as a repository or a file in one." },
        "built_by": { "enum": ["ci", "developer"], "description": "ci: a public build workflow made it. developer: the developer built it on their own machine." },
        "component": { "$ref": "#/$defs/component" },
        "note": { "$ref": "#/$defs/text" }
      },
      "patternProperties": { "^x-": {} },
      "additionalProperties": false
    },

    "runtime_download": {
      "type": "object",
      "required": ["what", "kind", "pinned"],
      "anyOf": [{ "required": ["destination"] }, { "required": ["destination_set_by"] }],
      "properties": {
        "what": { "$ref": "#/$defs/text" },
        "kind": { "enum": ["python_package", "javascript", "script", "lua", "binary"] },
        "destination": { "anyOf": [{ "$ref": "#/$defs/host" }, { "$ref": "#/$defs/url" }], "description": "The host or URL it comes from." },
        "destination_set_by": { "$ref": "#/$defs/destination_set_by" },
        "setting": { "$ref": "#/$defs/text", "description": "The setting's name, when destination_set_by is setting." },
        "pinned": { "type": "boolean", "description": "true when the app asks for one exact version or checks a checksum." },
        "component": { "$ref": "#/$defs/component" },
        "note": { "$ref": "#/$defs/text" }
      },
      "allOf": [
        { "if": { "properties": { "destination_set_by": { "const": "setting" } }, "required": ["destination_set_by"] }, "then": { "required": ["setting"] } }
      ],
      "patternProperties": { "^x-": {} },
      "additionalProperties": false
    },

    "generated_file": {
      "type": "object",
      "required": ["path"],
      "properties": {
        "path": { "$ref": "#/$defs/text" },
        "component": { "$ref": "#/$defs/component" },
        "note": { "$ref": "#/$defs/text" }
      },
      "patternProperties": { "^x-": {} },
      "additionalProperties": false
    }
  }
}
