Monorepo for Aesthetic.Computer
aesthetic.computer
1#!/bin/bash
2#
3# Test keep-mint endpoint with authentication
4#
5# Usage: ./test-keep-authenticated.sh <piece-name>
6# Note: Run 'ac-login' first to authenticate
7#
8
9set -e
10
11if [ -z "$1" ]; then
12 echo "Usage: $0 <piece-name>"
13 echo "Example: $0 test-keep-123"
14 echo ""
15 echo "Authenticate first with: ac-login"
16 exit 1
17fi
18
19PIECE=$1
20ENDPOINT="${ENDPOINT:-https://localhost:8888/api/keep-mint}"
21
22echo "╔══════════════════════════════════════════════════════════════╗"
23echo "║ 🧪 Testing Keep-Mint (Authenticated) ║"
24echo "╚══════════════════════════════════════════════════════════════╝"
25echo ""
26
27# Check if AC_TOKEN is set (from ac-login fish function)
28if [ -z "$AC_TOKEN" ]; then
29 # Try to load from file as fallback
30 TOKEN_FILE="$HOME/.ac-token"
31 if [ ! -f "$TOKEN_FILE" ]; then
32 echo "❌ Not logged in"
33 echo ""
34 echo "Run first: ac-login"
35 exit 1
36 fi
37
38 # Extract access token from file
39 ACCESS_TOKEN=$(node -e "console.log(JSON.parse(require('fs').readFileSync('$TOKEN_FILE', 'utf8')).access_token)")
40else
41 # Use environment variable from ac-login
42 ACCESS_TOKEN="$AC_TOKEN"
43fi
44
45if [ -z "$ACCESS_TOKEN" ]; then
46 echo "❌ Could not read access token"
47 exit 1
48fi
49
50echo "✅ Authenticated"
51if [ -n "$AC_USER_EMAIL" ]; then
52 echo "👤 User: $AC_USER_EMAIL"
53fi
54echo "📍 Piece: $PIECE"
55echo "🌐 Endpoint: $ENDPOINT"
56echo "🔧 Mode: mint (server-side)"
57echo ""
58
59# Make authenticated request
60echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
61echo "📤 Sending authenticated request..."
62echo ""
63
64curl -N -X POST "$ENDPOINT" \
65 -H "Content-Type: application/json" \
66 -H "Authorization: Bearer $ACCESS_TOKEN" \
67 -d "{\"piece\": \"$PIECE\", \"mode\": \"mint\"}" \
68 2>&1 | while IFS= read -r line; do
69 # Parse SSE events
70 if [[ "$line" =~ ^data:\ (.*)$ ]]; then
71 DATA="${BASH_REMATCH[1]}"
72
73 # Pretty print JSON if jq is available
74 if command -v jq &> /dev/null; then
75 echo "$DATA" | jq -C '.'
76 else
77 echo "$DATA"
78 fi
79 echo ""
80 fi
81done
82
83echo ""
84echo "✅ Test complete"