{
  "openapi": "3.0.3",
  "info": {
    "title": "SenhaBox — API de cofre para IAs",
    "version": "1.1.0",
    "description": "Acesso delegado por token. Só as rotas abaixo existem; nada além do cofre das caixas autorizadas. Os valores trafegam sempre cifrados (v1:<base64>). Guia: https://www.senhabox.com/docs/ia e https://www.senhabox.com/llms.txt. Escopos: list, create, update, delete, read_secret, create_structure. Acesso total cobre todos eles (inclui criar categorias e caixas) nas caixas atuais e futuras do usuário, sempre dentro dos limites do plano. expires_at nulo = nunca expira (só para ao revogar ou excluir)."
  },
  "servers": [
    {
      "url": "https://lrhvakbwmuboreeyayfi.supabase.co/functions/v1/ai-vault-api"
    }
  ],
  "security": [
    {
      "bearerToken": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerToken": {
        "type": "http",
        "scheme": "bearer",
        "description": "sbx1.<id>.<segredo> (as 3 primeiras partes do token; a 4ª parte é a chave local e nunca é enviada)."
      }
    },
    "schemas": {
      "Erro": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "enum": [
              "nao_autorizado",
              "dados_invalidos",
              "nao_encontrado",
              "cota_excedida",
              "limite_excedido",
              "metodo_nao_permitido",
              "erro_interno"
            ]
          },
          "message": {
            "type": "string"
          },
          "request_id": {
            "type": "string"
          }
        }
      },
      "Valores": {
        "type": "object",
        "description": "Mapa idDoCampo (uuid) → valor cifrado no formato v1:<base64>. Texto claro é rejeitado.",
        "additionalProperties": {
          "type": "string",
          "pattern": "^v1:[A-Za-z0-9+/]{40,}={0,2}$"
        },
        "minProperties": 1,
        "maxProperties": 40
      },
      "CorpoValores": {
        "type": "object",
        "required": [
          "values"
        ],
        "properties": {
          "values": {
            "$ref": "#/components/schemas/Valores"
          }
        }
      },
      "CorpoCategoria": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "description": {
            "type": "string",
            "maxLength": 500
          }
        }
      },
      "CorpoCaixa": {
        "type": "object",
        "required": [
          "name",
          "category_id"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "category_id": {
            "type": "string",
            "format": "uuid",
            "description": "Também aceita block_id ou categoria_id."
          },
          "template": {
            "type": "string",
            "maxLength": 80,
            "description": "Id ou nome do modelo (ex.: Login). Opcional."
          },
          "description": {
            "type": "string",
            "maxLength": 500
          }
        }
      }
    },
    "responses": {
      "Erro": {
        "description": "Erro genérico",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Erro"
            }
          }
        }
      }
    },
    "parameters": {
      "boxId": {
        "name": "boxId",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "entryId": {
        "name": "entryId",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "maxLength": 64
        }
      }
    }
  },
  "paths": {
    "/v1/boxes": {
      "get": {
        "summary": "Caixas autorizadas para este token",
        "responses": {
          "200": {
            "description": "Lista",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "name": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Erro"
          }
        }
      },
      "post": {
        "summary": "Cria uma caixa do dono do token (escopo create_structure, incluso no Acesso total). Respeita o limite do plano.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CorpoCaixa"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Criado (sempre no nome do dono do token)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "name": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Limite do plano atingido (cota_excedida)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Erro"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Erro"
          }
        }
      }
    },
    "/v1/templates": {
      "get": {
        "summary": "Modelos de registro e seus campos",
        "responses": {
          "200": {
            "description": "Modelos",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "label": {
                            "type": "string"
                          },
                          "fields": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "id": {
                                  "type": "string",
                                  "format": "uuid"
                                },
                                "name": {
                                  "type": "string"
                                },
                                "type": {
                                  "type": "string"
                                },
                                "key": {
                                  "type": "string"
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Erro"
          }
        }
      }
    },
    "/v1/session": {
      "get": {
        "summary": "Chave do cofre embrulhada (abre só com a 4ª parte do token, localmente). Exige escopo criar, editar ou ler senhas.",
        "responses": {
          "200": {
            "description": "Chave embrulhada",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "wrapped_vault_key": {
                          "type": "string"
                        },
                        "scopes": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        "expires_at": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "date-time"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Erro"
          }
        }
      }
    },
    "/v1/boxes/{boxId}/entries": {
      "parameters": [
        {
          "$ref": "#/components/parameters/boxId"
        }
      ],
      "get": {
        "summary": "Registros da caixa. Os valores (sempre cifrados) só vêm se o token tem 'ler senhas'.",
        "responses": {
          "200": {
            "description": "Registros",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "values_included": {
                          "type": "boolean"
                        },
                        "entries": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "id": {
                                "type": "string"
                              },
                              "created_at": {
                                "type": "string"
                              },
                              "field_ids": {
                                "type": "array",
                                "items": {
                                  "type": "string"
                                }
                              },
                              "values": {
                                "$ref": "#/components/schemas/Valores"
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Erro"
          }
        }
      },
      "post": {
        "summary": "Cria um registro (escopo criar). Valores já cifrados no cliente.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CorpoValores"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Criado",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Erro"
          }
        }
      }
    },
    "/v1/boxes/{boxId}/entries/{entryId}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/boxId"
        },
        {
          "$ref": "#/components/parameters/entryId"
        }
      ],
      "patch": {
        "summary": "Altera campos de um registro (escopo editar).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CorpoValores"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Atualizado",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Erro"
          }
        }
      },
      "delete": {
        "summary": "Exclui um registro (escopo excluir).",
        "responses": {
          "200": {
            "description": "Excluído",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Erro"
          }
        }
      }
    },
    "/v1/categories": {
      "get": {
        "summary": "Categorias do dono do token (não inclui as de outras pessoas)",
        "responses": {
          "200": {
            "description": "Lista",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "name": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Erro"
          }
        }
      },
      "post": {
        "summary": "Cria uma categoria (escopo create_structure, incluso no Acesso total). Respeita o limite do plano.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CorpoCategoria"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Criado (sempre no nome do dono do token)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "name": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Limite do plano atingido (cota_excedida)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Erro"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Erro"
          }
        }
      }
    }
  },
  "externalDocs": {
    "description": "Docs para IA (humano e máquina)",
    "url": "https://www.senhabox.com/docs/ia"
  }
}
