Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI

on:
pull_request:
branches: [main]

permissions:
contents: read

jobs:
check:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.12']
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- run: python -m pip install -e '.[test]' ruff build
- run: ruff check arara_api_sdk
- run: python -m pytest
- run: python -m build
84 changes: 78 additions & 6 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,92 @@
name: Publish to PyPI

on:
release:
types: [published]
push:
branches: [main]
workflow_dispatch:

concurrency:
group: pypi-publish
cancel-in-progress: false

jobs:
publish:
build:
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
contents: read
outputs:
publish: ${{ steps.version.outputs.publish }}
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- run: python -m pip install build && python -m build
- run: python -m pip install -e '.[test]' ruff build
- run: ruff check arara_api_sdk
- run: python -m pytest
- run: python -m build

- name: Resolve version
id: version
run: |
NAME=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['name'])")
LOCAL=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
STATUS=$(curl -s -o /dev/null -w '%{http_code}' --max-time 30 "https://pypi.org/pypi/$NAME/$LOCAL/json" || true)
case "$STATUS" in
200)
echo "publish=false" >> "$GITHUB_OUTPUT"
echo "::notice::$NAME $LOCAL ja existe no PyPI, nada a publicar"
;;
404)
echo "publish=true" >> "$GITHUB_OUTPUT"
;;
*)
echo "::error::PyPI respondeu HTTP $STATUS ao checar $NAME $LOCAL; abortando sem publicar"
exit 1
;;
esac
echo "version=$LOCAL" >> "$GITHUB_OUTPUT"

- uses: actions/upload-artifact@v4
if: steps.version.outputs.publish == 'true'
with:
name: dist
path: dist/

publish:
needs: build
if: needs.build.outputs.publish == 'true'
runs-on: ubuntu-latest
environment: pypi
permissions:
contents: read
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/

- uses: pypa/gh-action-pypi-publish@release/v1

release:
needs: [build, publish]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/

- name: Tag and release
env:
GH_TOKEN: ${{ github.token }}
TAG: v${{ needs.build.outputs.version }}
run: |
git tag "$TAG"
git push origin "$TAG"
gh release create "$TAG" dist/* --title "$TAG" --generate-notes
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,4 @@ cython_debug/

# PyCharm
.idea/
.DS_Store
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Changelog

## 2.0.0 - 2026-09-24

Alinha o SDK ao contrato real da API por chave. Versão major porque remove recursos e muda retornos.

### Quebras
- Removidos `payments`, `brain`, `organizations`, `users` e `api_keys`: nenhum deles é alcançável por API key (403 ou rota inexistente).
- `templates.list()` e `smart_links.list()` devolvem `Page` (`data` + `pagination`) em vez de lista; aceitam `page`/`size` (e `name`/`status` em templates).
- `CreateTemplateRequest` manda `body` (obrigatório), `header`, `headerType`, `footer`, `buttons`, `samples`, `variableExamples` e `carouselCards`. `structure_json` saiu (a API ignorava e respondia 400).
- 401 levanta `AraraAuthError`; 403 sem envelope (chave sem permissão, rota fora da allowlist) levanta `AraraForbiddenError`; 403 com código levanta `AraraApiError` (ou `AraraPlanFeatureLockedError` para `PLAN_FEATURE_LOCKED`, com `feature`, `current_plan`, `upgrade_to`); 422 levanta `AraraUnprocessableError`.
- POST/PATCH sem `Idempotency-Key` não são mais repetidos em timeout, erro de conexão, 5xx ou 429.

### Novo
- `auth.me()` (`GET /auth/me`, exige chave ADMIN): `name`, `email`, `role`, `email_pending`.
- `messages.send` e `campaigns.create` sempre enviam `Idempotency-Key`: a do caller (`idempotency_key=`) ou um UUID v4 gerado por chamada e reaproveitado em todos os retries.
- `messages.send_batch` (até 1000 destinatários, resultado por item em `BatchMessageItemResponse`) e `messages.list_by_batch`.
- `campaigns.list`, `campaigns.get`, `campaigns.cancel`; `CampaignRequest` aceita `scheduled_at` e `ab_test`.
- `templates.analytics(id, period)`.
- `opt_outs` (`list`, `create`, `get`, `delete`).
- Todo erro expõe `status_code`, `code`, `message`, `details` e `retry_after`.

### Correções
- `MessageResponse.cost` é opcional (nulo em TEST, agendada ou sem pré-cálculo) e ganhou `reason`. Antes o SDK lançava depois de a API já ter aceitado o envio.
- Resposta 200 sem corpo (ex.: cancelar campanha) devolve `None` em vez de quebrar no parse.
- Configuração e modelos sem APIs obsoletas do pydantic (`class Config`, `Field(env=...)`).

### Publicação
- Publica no PyPI a cada push na `main` via Trusted Publishing quando a versão do `pyproject.toml` ainda não existe, e cria a tag `vX.Y.Z` com release no GitHub.
Loading
Loading