Skip to content
Open
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
2 changes: 2 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ before:

builds:
- id: abacatepay
main: ./cmd/abacatepay
binary: abacatepay
env:
- CGO_ENABLED=0
Expand All @@ -23,6 +24,7 @@ builds:

# Alias (abkt)
- id: abkt
main: ./cmd/abacatepay
binary: abkt
env:
- CGO_ENABLED=0
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.PHONY: build test lint clean coverage install

BINARY=abacate
BINARY=abacatepay

build:
go build -o $(BINARY) .
go build -o $(BINARY) ./cmd/abacatepay

test:
go test -v -race ./...
Expand All @@ -12,7 +12,7 @@ lint:
golangci-lint run

install:
go install .
go install ./cmd/abacatepay

check: test lint

Expand Down
44 changes: 15 additions & 29 deletions PR_DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
## Summary

Adds `init` command that initializes new projects with interactive scaffolding, allowing choice between frameworks (Next.js/Elysia), linters (ESLint/Biome), and optional BetterAuth configuration.
- Fixes Go installation by using the canonical module path and adding `cmd/abacatepay` so Go users can install the expected `abacatepay` binary.
- Narrows the CLI to the requested supported surface: auth, webhook listening, and dev-mode payment simulation.
- Updates payment simulation to API v2: `POST /v2/transparents/simulate-payment?id=<charge-id>`.
- Removes unsupported commands/features from the current codebase until there is documented API v2 parity.
- Updates README installation and usage docs.

## Related Issue
Closes #32.

Closes (N/A)
## Validation

## Why
- `go mod tidy`
- `go test ./...`
- `go build ./...`
- `GOBIN=/tmp/abacatepay-cli-bin go install .` and root CLI help smoke test
- `GOBIN=/tmp/abacatepay-bin go install ./cmd/abacatepay` and `abacatepay` help smoke test

The CLI needed a simple way to create new projects integrated with AbacatePay. Before, developers had to manually clone templates and configure everything by hand. The `init` command automates this entire process with an interactive onboarding flow.
## Notes

## What changed
The `--local` flag is kept as a backwards-compatible no-op because API v2 uses the same public endpoint for production and dev mode; the API key determines the environment.

- Created `cmd/init.go` with interactive onboarding flow using prompts from the `style` package
- Created `internal/scaffold/config.go` with `Config` structure and validation methods
- Created `internal/scaffold/git.go` for repository clone operations
- Created `internal/scaffold/package.go` for `package.json` manipulation and merging
- Created `internal/scaffold/fs.go` for file and directory copy operations
- Created `internal/scaffold/scaffold.go` with scaffolding orchestration via `ProjectBuilder`
- Implemented layer-based composition system that combines base templates + linters + features (BetterAuth)

## Breaking changes

- [ ] Yes
- [X] No

## Checklist

- [ ] Docs updated
- [X] CI passing
- [X] I followed the CONTRIBUTING guidelines
- [X] I added or updated tests (if applicable)

## Additional context

The command uses the `github.com/albuquerquesz/abacatepay-templates` repository as the source for templates. The layer-based composition architecture allows adding new frameworks, linters, and features without creating a combinatorial explosion of templates.
The old root Go install path still works and produces `abacatepay-cli`; the documented Go path now installs `abacatepay`.
120 changes: 56 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,125 +1,117 @@
<h1 align="center">AbacatePay CLI</h1>

<p align="center">
CLI oficial do AbacatePay para desenvolvimento local, webhooks e testes rápidos via terminal.
CLI oficial da AbacatePay para autenticação, recebimento de webhooks e simulação de pagamentos em modo de desenvolvimento.
</p>

<p align="center">
<sub>
<samp>
<a href="#instalação">Instalação</a> •
<a href="#uso-rápido">Uso</a> •
<a href="#uso-rápido">Uso rápido</a> •
<a href="#autenticação">Autenticação</a> •
<a href="#ambientes">Ambientes</a>
<a href="#webhooks">Webhooks</a> •
<a href="#pagamentos-em-dev-mode">Pagamentos em dev mode</a>
</samp>
</sub>
</p>

<h2 align="center">Instalação</h2>
## Instalação

<h3 align="center">Go (recomendado)</h3>
### Go

```bash
go install github.com/AbacatePay/abacatepay-cli@latest
go install github.com/AbacatePay/abacatepay-cli/cmd/abacatepay@latest
```

<p align="center">O binário automáticamente será instalado como <em>abacatepay</em> com um aliás <em>abkt</em>.</p>
Isso instala o binário `abacatepay`.

<h3 align="center">Homebrew (macOS / Linux)</h3>
O comando antigo também funciona, mas instala o binário com o nome do repositório:

```bash
brew install --build-from-source github.com/AbacatePay/abacatepay-cli
go install github.com/AbacatePay/abacatepay-cli@latest
# binário: abacatepay-cli
```

<h2 align="center">Uso Rápido</h2>
### Binários prontos

```bash
abacatepay login
```
Os releases publicam binários para Linux, macOS e Windows nas arquiteturas `amd64` e `arm64`.

<p align="center">Após a autenticação <em>(OAuth Device Flow)</em>, você deve informar a URL do seu servidor local, então a CLI encaminhará todos os webhooks para você.</p>

<p align="center">Todos os comandos podem ser usados com a seguinte sintaxe:</p>
## Uso rápido

```bash
abacatepay <command> [...flags] [...args]
abacatepay login --key "$ABACATEPAY_API_KEY"
abacatepay listen --forward-to http://localhost:3000/webhooks/abacatepay
abacatepay payments simulate <charge-id>
```

<p align="center">Use a flag <code>-h</code> para obter informações detalhadas sobre cada comando.</p>

<h2 align="center">Ambientes</h2>
Use `abacatepay <command> -h` para ver as flags de cada comando.

<p align="center">Atualmente a CLI suporta dois ambientes, o de <em>produção</em> (Padrão) e <em>teste</em>.</p>
## Autenticação

<h3 align="center">Produção (Padrão)</h3>
A CLI aceita login por chave de API ou pelo fluxo de device login:

```bash
# API: https://api.abacatepay.com
# WebSocket: wss://ws.abacatepay.com/ws
# Recomendado para automações e ambientes sem navegador
abacatepay login --key "$ABACATEPAY_API_KEY"

# Fluxo interativo pelo navegador
abacatepay login
```

<h3 align="center">Servidor de Teste</h3>
A chave fica salva no keyring nativo do sistema operacional. Se nenhum nome for informado com `--name`, a CLI usa o perfil `default`.

<p align="center">Para usar o modo de desenvolvimento, use a flag <code>-l</code></p>
A API v2 usa o mesmo endpoint público para produção e desenvolvimento. O ambiente é determinado pela chave utilizada: chaves de dev mode simulam transações; chaves de produção operam em produção.

## Webhooks

```bash
# API: http://191.252.202.128:8080
# WebSocket: ws://191.252.202.128:8080/ws
Receba eventos da AbacatePay e encaminhe para sua aplicação local:

abacatepay login -l
```bash
abacatepay listen --forward-to http://localhost:3000/webhooks/abacatepay
```

<h2 align="center">Autenticação</h2>
Flags úteis:

<p align="center">A CLI usa <em>OAuth2 Device Flow</em>, sem necessidade de copiar tokens manualmente, apenas seguindo o fluxo abaixo</p>
| Flag | Descrição | Padrão |
| ---- | --------- | ------ |
| `--forward-to` | URL local que receberá os eventos | `http://localhost:3000/webhooks/abacatepay` |
| `--mock` | Gera webhooks locais sem conectar na API | `false` |

1. Use `abacatepay login`
2. Abra a URL exibida no navegador
3. Autorize o acesso na sua conta AbacatePay
4. A CLI detecta a autorização automaticamente
5. Informe a URL para encaminhar webhooks (Ou pressione a tecla <em>Enter</em> para usar o padrão)
A CLI assina os eventos encaminhados com o header `X-Abacate-Signature`, facilitando testes locais de validação de assinatura.

<h3 align="center">Armazenamento</h3>
## Pagamentos em dev mode

<p align="center">O token da sua conta é armazenado com segurança no <em>keyring nativo</em> do seu sistema operacional:</p>

- **macOS**: Keychain
- **Linux**: gnome-keyring ou kwallet
- **Windows**: Credential Manager

<p align="center">Caso o token não consiga ser salvo, você deverá instalar o keyring no seu sistema operacional (Linux)</p>
Simule o pagamento de uma cobrança transparente criada com uma chave de dev mode:

```bash
# Debian/Ubuntu
sudo apt install gnome-keyring

# Fedora
sudo dnf install gnome-keyring
abacatepay payments simulate <charge-id>
```

<h2 align="center">Logs</h2>
Esse comando chama a API v2:

```http
POST /v2/transparents/simulate-payment?id=<charge-id>
```

<p align="center">Todos os logs são salvos ni caminho <code>~/.abacatepay/logs/</code> com uma rotação automática de 10mb por arquivo, 5 backups e 30 dias de retenção</p>
Ele só funciona para cobranças em `devMode`. Em produção, o pagamento precisa acontecer pelo fluxo real.

- **abacatepay.log** - Log geral (JSON)
- **transactions.log** - Webhooks recebidos e encaminhados
## Output

<h3 align="center">Use jq para analisar os logs</h3>
A flag global `--output` permite trocar o formato de saída:

```bash
# Erros
cat ~/.abacatepay/logs/abacatepay.log | jq 'select(.level=="ERROR")'
abacatepay payments simulate <charge-id> --output json
```

# Webhooks recebidos
cat ~/.abacatepay/logs/transactions.log | jq 'select(.msg=="webhook_received")'
Formatos disponíveis: `text`, `json` e `table`.

# Tempo médio de encaminhamento
cat ~/.abacatepay/logs/transactions.log | jq 'select(.msg=="webhook_forwarded") | .duration_ms' | jq -s 'add/length'
```
## Escopo atual

Para manter a CLI simples e alinhada com a API v2, o escopo atual é:

<h2 align="center">Documentação</h2>
- login/logout;
- receber webhooks;
- simular pagamento de cobranças transparentes em dev mode.

<p align="center">Para uma documentação completa, veja a <a href="https://docs.abacatepay.com/pages/cli">documentação oficial</a>.</p>
Recursos fora desse escopo foram removidos da codebase até existir paridade clara com a API v2 e documentação atualizada.
24 changes: 24 additions & 0 deletions cmd/abacatepay/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"fmt"
"os"

rootcmd "github.com/AbacatePay/abacatepay-cli/cmd"
"github.com/AbacatePay/abacatepay-cli/internal/logger"
)

func main() {
logCfg, err := logger.DefaultConfig()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to configure logger: %v\n", err)
os.Exit(1)
}

if _, err := logger.Setup(logCfg); err != nil {
fmt.Fprintf(os.Stderr, "Failed to initialize logger: %v\n", err)
os.Exit(1)
}

rootcmd.Exec()
}
20 changes: 0 additions & 20 deletions cmd/docs.go

This file was deleted.

13 changes: 0 additions & 13 deletions cmd/events.go

This file was deleted.

Loading
Loading