SDK Shell (curl)
Todos os endpoints com curl e saida formatada com jq.
Configuracao inicial
# Copie e cole no seu .bashrc ou .zshrc, ou exporte na sessao atual
export SUPABASE_URL="https://<PROJECT>.supabase.co"
export SUPABASE_ANON_KEY="<ANON_KEY>"
export BASE_URL="https://fast-deliv-backend.vercel.app"
# Autenticar e salvar token
auth() {
local EMAIL="${1:-admin@empresa.com}"
local PASSWORD="${2:-senha123}"
local RESP
RESP=$(curl -s -X POST \
"${SUPABASE_URL}/auth/v1/token?grant_type=password" \
-H "apikey: ${SUPABASE_ANON_KEY}" \
-H "Content-Type: application/json" \
-d "{\"email\":\"${EMAIL}\",\"password\":\"${PASSWORD}\"}")
export TOKEN=$(echo "$RESP" | jq -r '.access_token')
export REFRESH_TOKEN=$(echo "$RESP" | jq -r '.refresh_token')
echo "Autenticado. Token: ${TOKEN:0:20}..."
}
# Renovar token
refresh_token() {
local RESP
RESP=$(curl -s -X POST \
"${SUPABASE_URL}/auth/v1/token?grant_type=refresh_token" \
-H "apikey: ${SUPABASE_ANON_KEY}" \
-H "Content-Type: application/json" \
-d "{\"refresh_token\":\"${REFRESH_TOKEN}\"}")
export TOKEN=$(echo "$RESP" | jq -r '.access_token')
echo "Token renovado"
}
auth
Health check
Resposta esperada:
Entregas
Listar todas
curl -s "${BASE_URL}/api/v1/deliveries" \
-H "Authorization: Bearer ${TOKEN}" \
| jq '.[] | {id, status, title}'
Listar pendentes
curl -s "${BASE_URL}/api/v1/deliveries?status=pending" \
-H "Authorization: Bearer ${TOKEN}" \
| jq 'length'
Criar entrega
DELIVERY=$(curl -s -X POST "${BASE_URL}/api/v1/deliveries" \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"title": "Entrega Centro",
"origin_address": "Rua das Flores, 100, Goiania",
"origin_lat": -16.6869,
"origin_lng": -49.2648,
"destination_address": "Av. Anhanguera, 500, Goiania",
"destination_lat": -16.6643,
"destination_lng": -49.2744
}')
DELIVERY_ID=$(echo "$DELIVERY" | jq -r '.id')
echo "Criada: $DELIVERY_ID"
echo "$DELIVERY" | jq '{id, status, distance_km, driver_earnings}'
Aceitar entrega (driver)
curl -s -X PATCH "${BASE_URL}/api/v1/deliveries/${DELIVERY_ID}/assign" \
-H "Authorization: Bearer ${TOKEN}" \
| jq '{id, status}'
Iniciar coleta (driver)
curl -s -X PATCH "${BASE_URL}/api/v1/deliveries/${DELIVERY_ID}/start" \
-H "Authorization: Bearer ${TOKEN}" \
| jq '.status'
Finalizar entrega (driver)
curl -s -X PATCH "${BASE_URL}/api/v1/deliveries/${DELIVERY_ID}/complete" \
-H "Authorization: Bearer ${TOKEN}" \
| jq '{status, driver_earnings}'
Cancelar entrega (admin)
curl -s -X PATCH "${BASE_URL}/api/v1/deliveries/${DELIVERY_ID}/cancel" \
-H "Authorization: Bearer ${TOKEN}" \
| jq '.status'
Motoristas
Listar motoristas
curl -s "${BASE_URL}/api/v1/drivers" \
-H "Authorization: Bearer ${TOKEN}" \
| jq '.[] | {id, full_name, is_active}'
Contar motoristas ativos
curl -s "${BASE_URL}/api/v1/drivers" \
-H "Authorization: Bearer ${TOKEN}" \
| jq '[.[] | select(.is_active == true)] | length'
Carteira
Ver saldo
curl -s "${BASE_URL}/api/v1/wallets/me" \
-H "Authorization: Bearer ${TOKEN}" \
| jq '{balance, updated_at}'
Historico de transacoes
curl -s "${BASE_URL}/api/v1/wallets/me/transactions" \
-H "Authorization: Bearer ${TOKEN}" \
| jq '.[] | {type, amount, description, created_at}'
Total de creditos
curl -s "${BASE_URL}/api/v1/wallets/me/transactions" \
-H "Authorization: Bearer ${TOKEN}" \
| jq '[.[] | select(.type == "credit") | .amount | tonumber] | add'
Solicitar saque Pix
curl -s -X POST "${BASE_URL}/api/v1/wallets/withdraw" \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"amount": "50.00",
"pix_key": "motorista@email.com",
"pix_key_type": "email"
}' | jq '{id, status, amount}'
Localizacao
Atualizar posicao GPS (driver)
curl -s -X PUT "${BASE_URL}/api/v1/locations/me" \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \
-d '{"lat": -16.6869, "lng": -49.2648, "heading": 90.0}' \
| jq '{updated_at}'
Listar posicoes de todos os motoristas (admin)
curl -s "${BASE_URL}/api/v1/locations" \
-H "Authorization: Bearer ${TOKEN}" \
| jq '.[] | {driver_name, lat, lng, updated_at}'
Precos
Ver configuracao atual
Atualizar precos
curl -s -X PUT "${BASE_URL}/api/v1/pricing" \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \
-d '{"base_fare": "18.00", "min_km": 5.0, "price_per_km": "2.50"}' \
| jq .
Funcoes bash reutilizaveis
# Listar entregas de hoje
deliveries_today() {
local TODAY
TODAY=$(date -u +"%Y-%m-%d")
curl -s "${BASE_URL}/api/v1/deliveries" \
-H "Authorization: Bearer ${TOKEN}" \
| jq --arg d "$TODAY" '[.[] | select(.created_at | startswith($d))]'
}
# Resumo financeiro do dia
daily_summary() {
local DELIVERIES
DELIVERIES=$(deliveries_today)
echo "$DELIVERIES" | jq '{
total: length,
completed: [.[] | select(.status == "completed")] | length,
cancelled: [.[] | select(.status == "cancelled")] | length,
total_earnings: [.[] | select(.status == "completed") | .driver_earnings | tonumber] | add // 0
}'
}
# Esperar entrega concluir (polling)
wait_delivery() {
local ID="$1"
while true; do
STATUS=$(curl -s "${BASE_URL}/api/v1/deliveries" \
-H "Authorization: Bearer ${TOKEN}" \
| jq -r --arg id "$ID" '.[] | select(.id == $id) | .status')
echo "Status: $STATUS"
case "$STATUS" in
"completed"|"cancelled") break ;;
esac
sleep 30
done
}