{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Dalibre plugin manifest (plugin API 1)",
  "type": "object",
  "additionalProperties": false,
  "required": ["id", "name", "version", "api", "capabilities", "permissions"],
  "properties": {
    "$schema": { "type": "string" },
    "id": {
      "description": "Unique, permanent id: lowercase letters, digits and '-', in dot-separated parts. Prefer a domain you own, reversed: \"com.example.books\".",
      "type": "string", "maxLength": 64,
      "pattern": "^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$"
    },
    "name": { "type": "string", "minLength": 1, "maxLength": 64 },
    "version": {
      "description": "Semantic version of the plugin.",
      "type": "string",
      "pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(-[0-9A-Za-z.-]+)?(\\+[0-9A-Za-z.-]+)?$"
    },
    "api": { "description": "The plugin API the plugin is written for.", "const": 1 },
    "description": { "type": "string" },
    "author": { "type": "string" },
    "homepage": { "type": "string", "format": "uri" },
    "license": { "description": "An SPDX identifier, as \"MIT\".", "type": "string" },
    "main": { "description": "The script, relative to plugin.json. Default main.js.", "type": "string", "pattern": "\\.js$" },
    "icon": {
      "description": "The plugin's icon, from Dalibre's set.",
      "enum": ["globe", "library", "book-open", "database", "network", "building", "bookmark", "layers"]
    },
    "capabilities": {
      "description": "What the plugin adds to Dalibre.",
      "oneOf": [
        { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "enum": ["source", "bookSource", "metadata"] } },
        {
          "type": "object", "additionalProperties": false, "minProperties": 1,
          "properties": {
            "bookSource": {
              "description": "A catalogue in Dalibre's Get books page. Export search; with collections, also collections and list.",
              "type": "object", "additionalProperties": false,
              "properties": {
                "collections": { "description": "Lists to browse while the search box is empty.", "type": "boolean" },
                "filters": {
                  "type": "array", "maxItems": 4,
                  "items": {
                    "type": "object", "additionalProperties": false, "required": ["key", "title", "type", "options"],
                    "properties": {
                      "key": { "type": "string", "pattern": "^[A-Za-z][A-Za-z0-9_]{0,63}$" },
                      "title": { "type": "string", "minLength": 1 },
                      "type": { "enum": ["select", "language"] },
                      "default": { "type": "string" },
                      "options": {
                        "type": "array", "minItems": 1, "maxItems": 64,
                        "items": {
                          "type": "object", "additionalProperties": false, "required": ["value"],
                          "properties": {
                            "value": { "type": "string" },
                            "title": { "description": "Required for select; a language's name is Dalibre's.", "type": "string" }
                          }
                        }
                      }
                    }
                  }
                }
              }
            },
            "metadata": {
              "description": "Looks up books' details for Fetch metadata in Edit metadata. Export identify; needs permissions.library \"read\".",
              "type": "object", "additionalProperties": false,
              "properties": {
                "fields": {
                  "description": "The fields the source can fill, shown to the user.",
                  "type": "array", "uniqueItems": true,
                  "items": { "enum": ["title", "authors", "series", "tags", "publisher", "pubdate", "language", "identifiers", "cover", "description"] }
                }
              }
            }
          }
        }
      ]
    },
    "permissions": {
      "type": "object", "additionalProperties": false, "required": ["hosts"],
      "properties": {
        "hosts": {
          "description": "Every host the plugin fetches or downloads from, redirects included. \"*.example.com\" matches subdomains.",
          "type": "array", "uniqueItems": true,
          "items": { "type": "string", "pattern": "^(\\*\\.)?[a-z0-9]([a-z0-9-]*[a-z0-9])?(\\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$" }
        },
        "localNetwork": {
          "description": "Reach this computer and the local network, as a home OPDS server. Users are warned.",
          "type": "boolean"
        },
        "library": {
          "description": "\"read\": see the title, authors, identifiers and language of the books the user looks up with the plugin. Metadata sources need it.",
          "enum": ["read"]
        }
      }
    },
    "settings": {
      "type": "array", "maxItems": 32,
      "items": {
        "type": "object", "additionalProperties": false, "required": ["key", "title"],
        "properties": {
          "key": { "type": "string", "pattern": "^[A-Za-z][A-Za-z0-9_]{0,63}$" },
          "title": { "type": "string", "minLength": 1 },
          "type": { "enum": ["text", "secret"] },
          "description": { "type": "string" },
          "default": { "type": "string" },
          "required": { "type": "boolean" }
        }
      }
    }
  }
}
