{"openapi":"3.1.0","info":{"title":"Datalivro API","version":"1.0.0","description":"API de metadados de livros do **Datalivro** — dados consolidados e validados a partir de múltiplas fontes\n(CBL/Agência Brasileira do ISBN, Mercado Editorial, Google Books, Open Library, sites de editoras…).\n\nCada campo vem com **proveniência** (quais fontes concordam, quais divergem) e **confiança** de 0 a 1,\npara que seu ERP ou e-commerce decida o que publicar automaticamente e o que revisar.\n\n### Autenticação\nEnvie sua chave em `Authorization: Bearer dl_live_…` (ou `X-API-Key`). Chaves `dl_test_…` são para homologação.\n\n### Limites\nCada chave tem um rate limit por minuto (headers `RateLimit-*`) e a organização tem uma cota mensal\n(headers `X-Quota-*`). Somente consultas que retornam um livro consomem cota; `304 Not Modified`, `202` e `404` são gratuitos.\n\n### Erros\nTodos os erros seguem a RFC 9457 (`application/problem+json`) com um `code` estável.","contact":{"name":"Datalivro","url":"https://datalivro.com.br","email":"dev@datalivro.com.br"}},"servers":[{"url":"https://api.datalivro.com.br","description":"Produção"}],"security":[{"apiKey":[]}],"tags":[{"name":"Livros","description":"Consulta de metadados por ISBN"},{"name":"Busca","description":"Busca textual e semântica"},{"name":"Sincronização","description":"Feed incremental para ERPs"},{"name":"Webhooks","description":"Notificações assinadas de mudanças"},{"name":"Integrações","description":"Conectores prontos (WooCommerce)"},{"name":"Conta","description":"Consumo e limites"},{"name":"Utilitários","description":"Ferramentas de ISBN"}],"externalDocs":{"description":"Guia de integração","url":"https://0.0.0.0:3000/docs"},"components":{"securitySchemes":{"apiKey":{"type":"http","scheme":"bearer","description":"Chave de API no formato `dl_live_…` ou `dl_test_…`."}},"schemas":{"BookResponse":{"type":"object","properties":{"data":{"anyOf":[{"$ref":"#/components/schemas/Book"},{"$ref":"#/components/schemas/ErpBook"}]},"meta":{"$ref":"#/components/schemas/Meta"}},"required":["data","meta"]},"Book":{"type":"object","properties":{"isbn13":{"type":"string","example":"9788535914849"},"isbn10":{"type":["string","null"],"example":"8535914846"},"ean":{"type":"string","description":"Código de barras EAN-13 (igual ao ISBN-13).","example":"9788535914849"},"title":{"type":["string","null"],"example":"1984"},"subtitle":{"type":["string","null"]},"original_title":{"type":["string","null"],"example":"Nineteen Eighty-Four"},"contributors":{"type":"array","items":{"type":"object","properties":{"name":{"type":"string"},"role":{"type":"string","enum":["author","translator","illustrator","editor","organizer","foreword","afterword","adapter","narrator","other"]}},"required":["name","role"]},"example":[{"name":"George Orwell","role":"author"},{"name":"Heloísa Jahn","role":"translator"}]},"publisher":{"type":["string","null"],"example":"Companhia das Letras"},"imprint":{"type":["string","null"]},"edition":{"type":["string","null"],"example":"1ª ed."},"publication_date":{"type":["object","null"],"properties":{"value":{"type":"string"},"year":{"type":"integer"},"precision":{"type":"string","enum":["year","month","day"]}},"required":["value","year","precision"],"example":{"value":"2009-07-21","year":2009,"precision":"day"}},"publication_place":{"type":["string","null"],"example":"São Paulo, SP"},"language":{"type":["string","null"],"description":"ISO 639-1.","example":"pt"},"page_count":{"type":["integer","null"],"example":416},"format":{"type":["string","null"],"enum":["paperback","hardcover","spiral","print","ebook","audiobook","other",null],"example":"paperback"},"dimensions":{"type":["object","null"],"properties":{"height_mm":{"type":["number","null"]},"width_mm":{"type":["number","null"]},"thickness_mm":{"type":["number","null"]}},"required":["height_mm","width_mm","thickness_mm"],"example":{"height_mm":210,"width_mm":140,"thickness_mm":24}},"weight_g":{"type":["integer","null"],"example":480},"synopsis":{"type":["string","null"]},"subjects":{"type":"array","items":{"type":"string"},"example":["Ficção","Distopia"]},"classification":{"type":"object","properties":{"cdd":{"type":"array","items":{"type":"string"}},"cdu":{"type":"array","items":{"type":"string"}}},"required":["cdd","cdu"],"example":{"cdd":["823"],"cdu":[]}},"series":{"type":["object","null"],"properties":{"name":{"type":"string"},"number":{"type":["string","null"]}},"required":["name","number"]},"cover":{"type":"object","properties":{"url":{"type":["string","null"],"format":"uri"},"alternatives":{"type":"array","items":{"type":"string","format":"uri"}}},"required":["url","alternatives"],"description":"URLs verificadas (respondem com uma imagem real)."},"list_price":{"type":["object","null"],"properties":{"amount":{"type":"number"},"amount_cents":{"type":"integer"},"currency":{"type":"string"}},"required":["amount","amount_cents","currency"],"description":"Preço de capa sugerido (somente BRL).","example":{"amount":59.9,"amount_cents":5990,"currency":"BRL"}},"age_range":{"type":["string","null"]},"fiscal":{"type":"object","properties":{"ncm":{"type":["string","null"],"example":"4901.99.00"},"tax_immune":{"type":"boolean","description":"Imunidade tributária (CF/88, art. 150, VI, \"d\")."}},"required":["ncm","tax_immune"],"description":"Sugestão fiscal para NF-e. Confirme com sua contabilidade."},"quality":{"type":"object","properties":{"score":{"type":"integer","minimum":0,"maximum":100,"description":"Completude ponderada pela confiança.","example":92},"warnings":{"type":"array","items":{"$ref":"#/components/schemas/BookWarning"}}},"required":["score","warnings"]},"sources":{"type":"array","items":{"type":"string"},"description":"Fontes que contribuíram.","example":["cbl","open-library","google-books"]},"provenance":{"type":"object","additionalProperties":{"$ref":"#/components/schemas/FieldProvenance"},"description":"Proveniência por campo. Incluído com `include=provenance`."}},"required":["isbn13","isbn10","ean","title","subtitle","original_title","contributors","publisher","imprint","edition","publication_date","publication_place","language","page_count","format","dimensions","weight_g","synopsis","subjects","classification","series","cover","list_price","age_range","fiscal","quality","sources"]},"BookWarning":{"type":"object","properties":{"code":{"type":"string","example":"conflict"},"field":{"type":"string","example":"format"},"message":{"type":"string","example":"Fontes divergem sobre formato: open-library × cbl."}},"required":["code","message"]},"FieldProvenance":{"type":"object","properties":{"confidence":{"type":"number","minimum":0,"maximum":1,"description":"Concordância ponderada entre as fontes (0–1).","example":0.97},"sources":{"type":"array","items":{"type":"string"},"description":"Fontes que concordam com o valor escolhido.","example":["cbl","google-books"]},"dissent":{"type":"array","items":{"type":"string"},"description":"Fontes que informaram um valor diferente.","example":[]}},"required":["confidence","sources","dissent"]},"ErpBook":{"type":"object","additionalProperties":{"anyOf":[{"type":"string"},{"type":"number"},{"type":"boolean"},{"type":"null"}]},"description":"Projeção plana com chaves em português, pronta para importação em ERPs (`view=erp`).","example":{"isbn":"9788535914849","titulo":"1984","autor_principal":"George Orwell","editora":"Companhia das Letras","paginas":416,"altura_cm":21,"largura_cm":14,"profundidade_cm":2.4,"peso_kg":0.48,"ncm":"4901.99.00","unidade":"UN"}},"Meta":{"type":"object","properties":{"request_id":{"type":"string"},"version":{"type":"integer","description":"Incrementa a cada mudança no conteúdo do livro."},"updated_at":{"type":"string","format":"date-time"}},"required":["request_id"]},"Processing":{"type":"object","properties":{"status":{"type":"string","enum":["processing"]},"isbn13":{"type":"string"},"retry_after_seconds":{"type":"integer"},"meta":{"$ref":"#/components/schemas/Meta"}},"required":["status","isbn13","retry_after_seconds","meta"]},"Problem":{"type":"object","properties":{"type":{"type":"string","format":"uri"},"title":{"type":"string"},"status":{"type":"integer"},"code":{"type":"string","example":"invalid_isbn"},"detail":{"type":"string"},"instance":{"type":"string"},"request_id":{"type":"string"},"errors":{"type":"array","items":{"type":"object","properties":{"path":{"type":"string"},"message":{"type":"string"}},"required":["path","message"]}}},"required":["type","title","status","code","detail","instance"]},"BatchItem":{"type":"object","properties":{"input":{"type":"string"},"isbn13":{"type":["string","null"]},"status":{"type":"string","enum":["ready","processing","not_found","invalid"]},"data":{"anyOf":[{"$ref":"#/components/schemas/Book"},{"type":"object","additionalProperties":{}},{"type":"null"}]},"version":{"type":["integer","null"]}},"required":["input","isbn13","status","data","version"]},"BatchRequest":{"type":"object","properties":{"isbns":{"type":"array","items":{"type":"string","maxLength":20},"minItems":1,"maxItems":100,"example":["9788535914849","8595084742"]},"view":{"type":"string","enum":["full","erp"],"default":"full"},"include":{"type":"string"},"wait_ms":{"type":"integer","minimum":0,"maximum":15000,"default":0,"description":"Tempo máximo para enriquecer ao vivo os ISBNs ainda não catalogados. 0 = apenas enfileirar."}},"required":["isbns"]},"SearchHit":{"type":"object","properties":{"score":{"type":"number"},"book":{"$ref":"#/components/schemas/Book"}},"required":["score","book"]},"WebhookEndpoint":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"url":{"type":"string","format":"uri"},"description":{"type":["string","null"]},"events":{"type":"array","items":{"type":"string","enum":["book.enriched","book.updated","sync.completed"]}},"active":{"type":"boolean"},"disabled_reason":{"type":["string","null"]},"created_at":{"type":"string","format":"date-time"}},"required":["id","url","description","events","active","disabled_reason","created_at"]},"Integration":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"kind":{"type":"string","enum":["woocommerce"]},"name":{"type":"string"},"store_url":{"type":"string","format":"uri"},"mode":{"type":"string","enum":["fill_empty","overwrite"]},"fields":{"type":"array","items":{"type":"string"}},"active":{"type":"boolean"},"last_sync_at":{"type":["string","null"],"format":"date-time"}},"required":["id","kind","name","store_url","mode","fields","active","last_sync_at"]},"WooCommerceIntegrationInput":{"type":"object","properties":{"name":{"type":"string","minLength":1,"maxLength":100,"example":"Loja principal"},"store_url":{"type":"string","format":"uri","example":"https://minhalivraria.com.br"},"consumer_key":{"type":"string","pattern":"^ck_[a-f0-9]{40}$"},"consumer_secret":{"type":"string","pattern":"^cs_[a-f0-9]{40}$"},"isbn_field":{"type":"string","pattern":"^(global_unique_id|sku|meta:[A-Za-z0-9_-]{1,64})$","default":"global_unique_id","description":"Onde está o ISBN: `global_unique_id` (campo GTIN nativo, WooCommerce 9.2+), `sku` ou `meta:<chave>`."},"mode":{"type":"string","enum":["fill_empty","overwrite"],"default":"fill_empty"},"fields":{"type":"array","items":{"type":"string","enum":["name","description","short_description","images","dimensions","weight","attributes","categories"]},"default":["name","description","short_description","images","dimensions","weight","attributes"]},"weight_unit":{"type":"string","enum":["kg","g"],"default":"kg"},"dimension_unit":{"type":"string","enum":["cm","mm"],"default":"cm"}},"required":["name","store_url","consumer_key","consumer_secret"]},"SyncRun":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"status":{"type":"string","enum":["queued","running","succeeded","failed"]},"dry_run":{"type":"boolean"},"stats":{"type":["object","null"],"properties":{"scanned":{"type":"number"},"matched":{"type":"number"},"updated":{"type":"number"},"skipped":{"type":"number"},"notFound":{"type":"number"},"failed":{"type":"number"}},"required":["scanned","matched","updated","skipped","notFound","failed"]},"error":{"type":["string","null"]},"created_at":{"type":"string","format":"date-time"},"finished_at":{"type":["string","null"],"format":"date-time"}},"required":["id","status","dry_run","stats","error","created_at","finished_at"]}},"parameters":{}},"paths":{"/api/v1/books/{isbn}":{"get":{"tags":["Livros"],"summary":"Consultar livro por ISBN","description":"Retorna os metadados consolidados do livro. ISBNs ainda não catalogados são enriquecidos ao vivo — se isso levar mais que `wait_ms`, a resposta é `202` e o resultado fica disponível em seguida. Respostas trazem `ETag`; envie `If-None-Match` para receber `304` sem consumir cota.","parameters":[{"schema":{"type":"string","minLength":10,"maxLength":20,"description":"ISBN-10, ISBN-13 ou EAN, com ou sem hífens.","example":"978-85-359-1484-9"},"required":true,"description":"ISBN-10, ISBN-13 ou EAN, com ou sem hífens.","name":"isbn","in":"path"},{"schema":{"type":"string","enum":["full","erp"],"default":"full","description":"`erp` retorna a projeção plana em português."},"required":false,"description":"`erp` retorna a projeção plana em português.","name":"view","in":"query"},{"schema":{"type":"string","description":"Lista separada por vírgulas. Suportado: `provenance`.","example":"provenance"},"required":false,"description":"Lista separada por vírgulas. Suportado: `provenance`.","name":"include","in":"query"},{"schema":{"type":"string","description":"Campos de primeiro nível a retornar (sparse fieldset).","example":"isbn13,title,contributors,cover"},"required":false,"description":"Campos de primeiro nível a retornar (sparse fieldset).","name":"fields","in":"query"},{"schema":{"type":["integer","null"],"minimum":0,"maximum":15000,"description":"Tempo máximo de espera pelo enriquecimento ao vivo de um ISBN novo.","example":4000},"required":false,"description":"Tempo máximo de espera pelo enriquecimento ao vivo de um ISBN novo.","name":"wait_ms","in":"query"}],"responses":{"200":{"description":"Livro encontrado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/BookResponse"}}}},"202":{"description":"Enriquecimento em andamento — tente novamente após `Retry-After`","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Processing"}}}},"304":{"description":"Não modificado desde o `ETag` informado"},"400":{"description":"Requisição inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"401":{"description":"Chave ausente ou inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"403":{"description":"Sem permissão (escopo ou IP)","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"404":{"description":"Não encontrado","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"429":{"description":"Rate limit ou cota mensal excedidos","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}}}}},"/api/v1/books/batch":{"post":{"tags":["Livros"],"summary":"Consultar até 100 ISBNs","description":"Ideal para cargas iniciais de catálogo em ERPs. Itens já catalogados retornam imediatamente; os demais são enfileirados (`processing`) — acompanhe por webhook `book.enriched` ou repita a chamada. Só itens `ready` consomem cota.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/BatchRequest"}}}},"responses":{"200":{"description":"Resultado por item, na mesma ordem da entrada","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/BatchItem"}},"summary":{"type":"object","properties":{"ready":{"type":"number"},"processing":{"type":"number"},"not_found":{"type":"number"},"invalid":{"type":"number"}},"required":["ready","processing","not_found","invalid"]},"meta":{"$ref":"#/components/schemas/Meta"}},"required":["data","summary","meta"]}}}},"401":{"description":"Chave ausente ou inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"403":{"description":"Sem permissão (escopo ou IP)","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"422":{"description":"Parâmetros inválidos","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"429":{"description":"Rate limit ou cota mensal excedidos","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}}}}},"/api/v1/books/{isbn}/sources":{"get":{"tags":["Livros"],"summary":"Evidências por fonte","description":"Registro normalizado que cada fonte retornou na última consulta — útil para auditoria e revisão humana.","parameters":[{"schema":{"type":"string","minLength":10,"maxLength":20,"description":"ISBN-10, ISBN-13 ou EAN, com ou sem hífens.","example":"978-85-359-1484-9"},"required":true,"description":"ISBN-10, ISBN-13 ou EAN, com ou sem hífens.","name":"isbn","in":"path"}],"responses":{"200":{"description":"Registros por fonte","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"type":"object","properties":{"source":{"type":"string"},"status":{"type":"string","enum":["ok","not_found","error"]},"record":{"type":["object","null"],"additionalProperties":{}},"error":{"type":["string","null"]},"latency_ms":{"type":["number","null"]},"fetched_at":{"type":"string","format":"date-time"}},"required":["source","status","record","error","latency_ms","fetched_at"]}},"meta":{"$ref":"#/components/schemas/Meta"}},"required":["data","meta"]}}}},"400":{"description":"Requisição inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"401":{"description":"Chave ausente ou inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"403":{"description":"Sem permissão (escopo ou IP)","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"404":{"description":"Não encontrado","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}}}}},"/api/v1/books/{isbn}/refresh":{"post":{"tags":["Livros"],"summary":"Forçar nova consulta às fontes","description":"Reprocessa o ISBN em todas as fontes com prioridade alta. Mudanças disparam o webhook `book.updated`.","parameters":[{"schema":{"type":"string","minLength":10,"maxLength":20,"description":"ISBN-10, ISBN-13 ou EAN, com ou sem hífens.","example":"978-85-359-1484-9"},"required":true,"description":"ISBN-10, ISBN-13 ou EAN, com ou sem hífens.","name":"isbn","in":"path"}],"responses":{"202":{"description":"Reprocessamento enfileirado","content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string","enum":["queued"]},"isbn13":{"type":"string"},"meta":{"$ref":"#/components/schemas/Meta"}},"required":["status","isbn13","meta"]}}}},"400":{"description":"Requisição inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"401":{"description":"Chave ausente ou inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"403":{"description":"Sem permissão (escopo ou IP)","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"429":{"description":"Rate limit ou cota mensal excedidos","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}}}}},"/api/v1/isbn/{isbn}":{"get":{"tags":["Utilitários"],"summary":"Validar e converter ISBN","description":"Valida o dígito verificador e converte entre ISBN-10, ISBN-13 e EAN. Não consome cota.","parameters":[{"schema":{"type":"string","minLength":10,"maxLength":20,"description":"ISBN-10, ISBN-13 ou EAN, com ou sem hífens.","example":"978-85-359-1484-9"},"required":true,"description":"ISBN-10, ISBN-13 ou EAN, com ou sem hífens.","name":"isbn","in":"path"}],"responses":{"200":{"description":"ISBN válido","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"object","properties":{"isbn13":{"type":"string"},"isbn10":{"type":["string","null"]},"ean":{"type":"string"},"group":{"type":["string","null"]},"brazilian":{"type":"boolean","description":"Registrado pela Agência Brasileira do ISBN (prefixos 978-65 / 978-85)."}},"required":["isbn13","isbn10","ean","group","brazilian"]},"meta":{"$ref":"#/components/schemas/Meta"}},"required":["data","meta"]}}}},"400":{"description":"Requisição inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"401":{"description":"Chave ausente ou inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}}}}},"/api/v1/books":{"get":{"tags":["Busca"],"summary":"Buscar livros","description":"Busca textual (português, sem acento, tolerante a erros de digitação) sobre título, subtítulo, autores e editora, com filtros. Use `semantic=true` para busca por significado (quando habilitada).","parameters":[{"schema":{"type":"string","maxLength":200,"example":"senhor dos aneis"},"required":false,"name":"q","in":"query"},{"schema":{"type":"string","maxLength":200,"example":"Tolkien"},"required":false,"name":"author","in":"query"},{"schema":{"type":"string","maxLength":200,"example":"HarperCollins"},"required":false,"name":"publisher","in":"query"},{"schema":{"type":"string","minLength":2,"maxLength":2,"example":"pt"},"required":false,"name":"language","in":"query"},{"schema":{"type":"integer","minimum":1450,"maximum":2100},"required":false,"name":"year","in":"query"},{"schema":{"type":"string","enum":["paperback","hardcover","spiral","print","ebook","audiobook","other"]},"required":false,"name":"format","in":"query"},{"schema":{"type":["integer","null"],"minimum":0,"maximum":100},"required":false,"name":"min_quality","in":"query"},{"schema":{"type":"string","enum":["true","false"],"default":"false"},"required":false,"name":"semantic","in":"query"},{"schema":{"type":"integer","minimum":1,"maximum":50,"default":20},"required":false,"name":"limit","in":"query"},{"schema":{"type":["integer","null"],"minimum":0,"maximum":1000,"default":0},"required":false,"name":"offset","in":"query"}],"responses":{"200":{"description":"Resultados ordenados por relevância","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/SearchHit"}},"has_more":{"type":"boolean"},"meta":{"$ref":"#/components/schemas/Meta"}},"required":["data","has_more","meta"]}}}},"400":{"description":"Requisição inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"401":{"description":"Chave ausente ou inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"403":{"description":"Sem permissão (escopo ou IP)","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"422":{"description":"Parâmetros inválidos","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"429":{"description":"Rate limit ou cota mensal excedidos","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}}}}},"/api/v1/books/{isbn}/similar":{"get":{"tags":["Busca"],"summary":"Livros semelhantes","description":"Vizinhos mais próximos por embedding (pgvector). Requer busca semântica habilitada.","parameters":[{"schema":{"type":"string","minLength":10,"maxLength":20,"description":"ISBN-10, ISBN-13 ou EAN, com ou sem hífens.","example":"978-85-359-1484-9"},"required":true,"description":"ISBN-10, ISBN-13 ou EAN, com ou sem hífens.","name":"isbn","in":"path"},{"schema":{"type":"integer","minimum":1,"maximum":50,"default":10},"required":false,"name":"limit","in":"query"}],"responses":{"200":{"description":"Livros semelhantes","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/SearchHit"}},"meta":{"$ref":"#/components/schemas/Meta"}},"required":["data","meta"]}}}},"400":{"description":"Requisição inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"401":{"description":"Chave ausente ou inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"403":{"description":"Sem permissão (escopo ou IP)","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"429":{"description":"Rate limit ou cota mensal excedidos","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}}}}},"/api/v1/changes":{"get":{"tags":["Sincronização"],"summary":"Feed de alterações (sincronização incremental)","description":"Lista livros alterados desde `since`, do mais antigo para o mais recente, com paginação por cursor estável. Padrão recomendado para ERPs: guarde o `next_cursor` e chame periodicamente. Com `scope=catalog` (padrão) retorna apenas livros que sua organização já consultou ou sincronizou.","parameters":[{"schema":{"type":"string","format":"date-time","example":"2026-10-01T00:00:00Z"},"required":false,"name":"since","in":"query"},{"schema":{"type":"string","maxLength":200},"required":false,"name":"cursor","in":"query"},{"schema":{"type":"string","enum":["catalog","all"],"default":"catalog"},"required":false,"name":"scope","in":"query"},{"schema":{"type":"integer","minimum":1,"maximum":500,"default":100},"required":false,"name":"limit","in":"query"}],"responses":{"200":{"description":"Página do feed","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"type":"object","properties":{"version":{"type":"integer"},"updated_at":{"type":"string","format":"date-time"},"book":{"$ref":"#/components/schemas/Book"}},"required":["version","updated_at","book"]}},"next_cursor":{"type":["string","null"],"description":"Null quando não há mais itens. Guarde o último cursor recebido."},"meta":{"$ref":"#/components/schemas/Meta"}},"required":["data","next_cursor","meta"]}}}},"400":{"description":"Requisição inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"401":{"description":"Chave ausente ou inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"403":{"description":"Sem permissão (escopo ou IP)","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"422":{"description":"Parâmetros inválidos","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"429":{"description":"Rate limit ou cota mensal excedidos","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}}}}},"/api/v1/usage":{"get":{"tags":["Conta"],"summary":"Consumo do mês","responses":{"200":{"description":"Consumo e limites","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"object","properties":{"organization":{"type":"string"},"period":{"type":"string","example":"2026-10"},"quota":{"type":"integer"},"used":{"type":"integer"},"remaining":{"type":"integer"},"rate_limit_per_minute":{"type":"integer"},"key":{"type":"object","properties":{"id":{"type":"string"},"environment":{"type":"string","enum":["live","test"]},"scopes":{"type":"array","items":{"type":"string"}}},"required":["id","environment","scopes"]}},"required":["organization","period","quota","used","remaining","rate_limit_per_minute","key"]},"meta":{"$ref":"#/components/schemas/Meta"}},"required":["data","meta"]}}}},"401":{"description":"Chave ausente ou inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"403":{"description":"Sem permissão (escopo ou IP)","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}}}}},"/api/v1/webhooks":{"get":{"tags":["Webhooks"],"summary":"Listar endpoints","responses":{"200":{"description":"Endpoints","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/WebhookEndpoint"}},"meta":{"$ref":"#/components/schemas/Meta"}},"required":["data","meta"]}}}},"401":{"description":"Chave ausente ou inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"403":{"description":"Sem permissão (escopo ou IP)","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}}}},"post":{"tags":["Webhooks"],"summary":"Cadastrar endpoint","description":"O `secret` de assinatura é exibido **somente nesta resposta**. Use-o para validar o header `Datalivro-Signature` (HMAC-SHA256). A URL precisa ser HTTPS e pública.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"url":{"type":"string","maxLength":2000,"format":"uri","example":"https://erp.minhalivraria.com.br/webhooks/datalivro"},"events":{"type":"array","items":{"type":"string","enum":["book.enriched","book.updated","sync.completed"]},"minItems":1,"example":["book.updated","book.enriched"]},"description":{"type":"string","maxLength":200}},"required":["url","events"]}}}},"responses":{"201":{"description":"Endpoint criado","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"allOf":[{"$ref":"#/components/schemas/WebhookEndpoint"},{"type":"object","properties":{"secret":{"type":"string","example":"whsec_…"}},"required":["secret"]}]},"meta":{"$ref":"#/components/schemas/Meta"}},"required":["data","meta"]}}}},"400":{"description":"Requisição inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"401":{"description":"Chave ausente ou inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"403":{"description":"Sem permissão (escopo ou IP)","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"422":{"description":"Parâmetros inválidos","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}}}}},"/api/v1/webhooks/{id}":{"delete":{"tags":["Webhooks"],"summary":"Remover endpoint","parameters":[{"schema":{"type":"string","format":"uuid"},"required":true,"name":"id","in":"path"}],"responses":{"204":{"description":"Removido"},"401":{"description":"Chave ausente ou inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"403":{"description":"Sem permissão (escopo ou IP)","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"404":{"description":"Não encontrado","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}}}}},"/api/v1/integrations/woocommerce":{"post":{"tags":["Integrações"],"summary":"Conectar loja WooCommerce","description":"Valida as credenciais da REST API do WooCommerce (permissão **Leitura/Escrita**) e as armazena criptografadas (AES-256-GCM). Gere-as em WooCommerce → Configurações → Avançado → REST API.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/WooCommerceIntegrationInput"}}}},"responses":{"201":{"description":"Integração criada","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/Integration"},"meta":{"$ref":"#/components/schemas/Meta"}},"required":["data","meta"]}}}},"400":{"description":"Requisição inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"401":{"description":"Chave ausente ou inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"403":{"description":"Sem permissão (escopo ou IP)","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"422":{"description":"Parâmetros inválidos","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}}}}},"/api/v1/integrations":{"get":{"tags":["Integrações"],"summary":"Listar integrações","responses":{"200":{"description":"Integrações","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Integration"}},"meta":{"$ref":"#/components/schemas/Meta"}},"required":["data","meta"]}}}},"401":{"description":"Chave ausente ou inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"403":{"description":"Sem permissão (escopo ou IP)","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}}}}},"/api/v1/integrations/{id}/sync":{"post":{"tags":["Integrações"],"summary":"Sincronizar catálogo","description":"Percorre todos os produtos da loja, identifica o ISBN e preenche os campos configurados. Use `dry_run: true` para simular sem alterar a loja. Ao final dispara o webhook `sync.completed`.","parameters":[{"schema":{"type":"string","format":"uuid"},"required":true,"name":"id","in":"path"}],"requestBody":{"required":false,"content":{"application/json":{"schema":{"type":"object","properties":{"dry_run":{"type":"boolean","default":false}}}}}},"responses":{"202":{"description":"Sincronização enfileirada","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/SyncRun"},"meta":{"$ref":"#/components/schemas/Meta"}},"required":["data","meta"]}}}},"401":{"description":"Chave ausente ou inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"403":{"description":"Sem permissão (escopo ou IP)","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"404":{"description":"Não encontrado","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}}}}},"/api/v1/integrations/{id}/runs":{"get":{"tags":["Integrações"],"summary":"Histórico de sincronizações","parameters":[{"schema":{"type":"string","format":"uuid"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Últimas 20 execuções","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/SyncRun"}},"meta":{"$ref":"#/components/schemas/Meta"}},"required":["data","meta"]}}}},"401":{"description":"Chave ausente ou inválida","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"403":{"description":"Sem permissão (escopo ou IP)","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}},"404":{"description":"Não encontrado","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Problem"}}}}}}}},"webhooks":{}}