{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "donutgram plugin manifest v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "kind",
    "schemaVersion",
    "id",
    "name",
    "version",
    "description",
    "apiVersion",
    "permissions"
  ],
  "properties": {
    "kind": {
      "const": "donutgram.plugin"
    },
    "schemaVersion": {
      "const": 1
    },
    "id": {
      "type": "string",
      "maxLength": 128,
      "pattern": "^[a-z](?:[a-z0-9-]*[a-z0-9])?(\\.[a-z](?:[a-z0-9-]*[a-z0-9])?){2,}$"
    },
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 80
    },
    "version": {
      "type": "string",
      "maxLength": 64,
      "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$"
    },
    "description": {
      "type": "string",
      "minLength": 0,
      "maxLength": 4096
    },
    "author": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 0,
          "maxLength": 128
        },
        "username": {
          "type": "string",
          "minLength": 0,
          "maxLength": 64
        }
      }
    },
    "apiVersion": {
      "enum": [
        "^1.0.0",
        "1.0.0"
      ]
    },
    "minClientVersion": {
      "type": "string",
      "pattern": "^[0-9]{1,3}\\.[0-9]{1,3}(\\.[0-9]{1,3})?$"
    },
    "entry": {
      "type": "string",
      "maxLength": 240,
      "pattern": "^[^\\\\:%]+\\.js$"
    },
    "icon": {
      "type": "string",
      "maxLength": 240,
      "pattern": "^assets/"
    },
    "permissions": {
      "type": "array",
      "maxItems": 32,
      "items": {
        "$ref": "#/$defs/permission"
      }
    },
    "optionalPermissions": {
      "type": "array",
      "maxItems": 32,
      "items": {
        "$ref": "#/$defs/permission"
      }
    },
    "profile": {
      "enum": [
        "localPrivate",
        "publicNetwork"
      ]
    },
    "settingsSchema": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "properties"
      ],
      "properties": {
        "type": {
          "const": "object"
        },
        "properties": {
          "type": "object",
          "maxProperties": 32,
          "propertyNames": {
            "pattern": "^[A-Za-z][A-Za-z0-9_-]{0,63}$"
          },
          "additionalProperties": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "type",
              "title"
            ],
            "properties": {
              "type": {
                "enum": [
                  "boolean",
                  "string",
                  "number",
                  "integer"
                ]
              },
              "title": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128
              },
              "description": {
                "type": "string",
                "minLength": 0,
                "maxLength": 4096
              },
              "default": {},
              "minimum": {
                "type": "number"
              },
              "maximum": {
                "type": "number"
              },
              "maxLength": {
                "type": "integer",
                "minimum": 0,
                "maximum": 4096
              },
              "enum": {
                "type": "array",
                "maxItems": 64
              }
            }
          }
        }
      }
    },
    "changelog": {
      "type": "string",
      "minLength": 0,
      "maxLength": 8192
    }
  },
  "$defs": {
    "permission": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "capability",
        "scope",
        "reason"
      ],
      "properties": {
        "capability": {
          "enum": [
            "ui.contribute",
            "ui.transform",
            "theme.read",
            "theme.contribute",
            "composer.read",
            "composer.transform",
            "messages.selection.read",
            "messages.read",
            "chats.metadata.read",
            "peers.read",
            "storage.local",
            "network.public",
            "translation.request",
            "navigation.open",
            "notifications.local",
            "files.userSelected",
            "messages.compose",
            "messages.sendInteractive",
            "messages.send",
            "messages.edit",
            "messages.delete",
            "messages.intercept"
          ]
        },
        "scope": {
          "type": "string"
        },
        "reason": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512
        },
        "origins": {
          "type": "array",
          "maxItems": 16,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "pattern": "^https://[a-z0-9.-]+$"
          }
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "capability": {
                "const": "ui.contribute"
              }
            }
          },
          "then": {
            "properties": {
              "scope": {
                "enum": [
                  "settings",
                  "composer",
                  "selection",
                  "messageMenu",
                  "chatToolbar"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "capability": {
                "const": "ui.transform"
              }
            }
          },
          "then": {
            "properties": {
              "scope": {
                "enum": [
                  "profile",
                  "chatList",
                  "displayLinks"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "capability": {
                "const": "theme.read"
              }
            }
          },
          "then": {
            "properties": {
              "scope": {
                "enum": [
                  "currentTheme"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "capability": {
                "const": "theme.contribute"
              }
            }
          },
          "then": {
            "properties": {
              "scope": {
                "enum": [
                  "localTokens"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "capability": {
                "const": "composer.read"
              }
            }
          },
          "then": {
            "properties": {
              "scope": {
                "enum": [
                  "activeComposer"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "capability": {
                "const": "composer.transform"
              }
            }
          },
          "then": {
            "properties": {
              "scope": {
                "enum": [
                  "activeComposer"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "capability": {
                "const": "messages.selection.read"
              }
            }
          },
          "then": {
            "properties": {
              "scope": {
                "enum": [
                  "activeSelection"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "capability": {
                "const": "messages.read"
              }
            }
          },
          "then": {
            "properties": {
              "scope": {
                "enum": [
                  "selectedChats"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "capability": {
                "const": "chats.metadata.read"
              }
            }
          },
          "then": {
            "properties": {
              "scope": {
                "enum": [
                  "selectedChats"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "capability": {
                "const": "peers.read"
              }
            }
          },
          "then": {
            "properties": {
              "scope": {
                "enum": [
                  "selectedPeers"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "capability": {
                "const": "storage.local"
              }
            }
          },
          "then": {
            "properties": {
              "scope": {
                "enum": [
                  "pluginAccount"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "capability": {
                "const": "network.public"
              }
            }
          },
          "then": {
            "properties": {
              "scope": {
                "enum": [
                  "declaredOrigins"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "capability": {
                "const": "translation.request"
              }
            }
          },
          "then": {
            "properties": {
              "scope": {
                "enum": [
                  "selectedText"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "capability": {
                "const": "navigation.open"
              }
            }
          },
          "then": {
            "properties": {
              "scope": {
                "enum": [
                  "safeScreens"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "capability": {
                "const": "notifications.local"
              }
            }
          },
          "then": {
            "properties": {
              "scope": {
                "enum": [
                  "pluginAccount"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "capability": {
                "const": "files.userSelected"
              }
            }
          },
          "then": {
            "properties": {
              "scope": {
                "enum": [
                  "selectedFile"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "capability": {
                "const": "messages.compose"
              }
            }
          },
          "then": {
            "properties": {
              "scope": {
                "enum": [
                  "chosenRecipient"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "capability": {
                "const": "messages.sendInteractive"
              }
            }
          },
          "then": {
            "properties": {
              "scope": {
                "enum": [
                  "chosenRecipient"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "capability": {
                "const": "messages.send"
              }
            }
          },
          "then": {
            "properties": {
              "scope": {
                "enum": [
                  "chosenRecipient"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "capability": {
                "const": "messages.edit"
              }
            }
          },
          "then": {
            "properties": {
              "scope": {
                "enum": [
                  "selectedMessages"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "capability": {
                "const": "messages.delete"
              }
            }
          },
          "then": {
            "properties": {
              "scope": {
                "enum": [
                  "selectedMessages"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "capability": {
                "const": "messages.intercept"
              }
            }
          },
          "then": {
            "properties": {
              "scope": {
                "enum": [
                  "activeComposer"
                ]
              }
            }
          }
        }
      ]
    }
  },
  "description": "runtime validation additionally checks paths, profile combinations, semver prerelease numbers, minimum client, unicode, duplicates and package limits; schemas are not an execution sandbox"
}
