#!/usr/bin/env bash # 08-paginacion-keyset.sh — la paginación keyset del buzón (pieza de la trampa doc). # # Envía 3 avisos con la clave `monitor`, pide `unread?limit=1` y muestra que # `next_cursor` NO es null: la vista SÍ pagina. Luego encadena el cursor. # # NOTA: el cursor contiene un espacio (`"|"`), así que hay que # URL-encodearlo: se usa `curl -G --data-urlencode`. # # Uso: ./08-paginacion-keyset.sh set -euo pipefail BASE="${VALET_BASE:-http://127.0.0.1:3458}" WORK="${WORKDIR:-/tmp/opencode/valet-847}" T2="$(cat "$WORK/token2.txt")" for i in 1 2 3; do curl -s -X POST "$BASE/api/notifications" \ -H "Authorization: Bearer $T2" -H "Content-Type: application/json" \ -d "{\"message\":\"aviso $i\",\"origin\":\"monitor\",\"author\":\"cron\",\"level\":\"info\"}" >/dev/null done echo "== GET /api/notifications/unread?limit=1 ==" P1=$(curl -s "$BASE/api/notifications/unread?limit=1") echo "$P1" CUR=$(printf '%s' "$P1" | python3 -c 'import sys,json;print(json.load(sys.stdin)["next_cursor"] or "")') echo echo "-- next_cursor = $CUR (¡NO es null!)" echo echo "== siguiente página con el cursor (URL-encoded) ==" curl -s -G -w "\n[%{http_code}]\n" "$BASE/api/notifications/unread" \ --data-urlencode "limit=1" --data-urlencode "cursor=$CUR"