forked from jorrit-stack/Raycast-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbolt-admin-hub.sh
More file actions
executable file
Β·187 lines (176 loc) Β· 6.82 KB
/
bolt-admin-hub.sh
File metadata and controls
executable file
Β·187 lines (176 loc) Β· 6.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Bolt Admin Hub
# @raycast.mode compact
# Optional parameters:
# @raycast.icon π€
# @raycast.argument1 { "type": "text", "placeholder": "User ID, Project ID, or Email (optional)", "optional": true }
# @raycast.argument2 { "type": "text", "placeholder": "Action (optional, else menu)", "optional": true }
# Documentation:
# @raycast.description Open bolt.new/StackBlitz admin sections: dashboard, users, rate limits, sites, Bolt DB, token usage, snapshots, Netlify. Pass ID or pick from menu.
# @raycast.author Jorrit Harmamny
set -euo pipefail
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
ID="${1:-}"
ACTION="${2:-}"
# Base URLs (StackBlitz admin = backend; bolt.new = product)
STACKBLITZ_ADMIN="https://stackblitz.com/admin"
BOLT_NEW="https://bolt.new"
BOLT_ADMIN="${BOLT_NEW}/admin"
# If no action given, show menu
if [[ -z "$ACTION" ]]; then
CHOICE=$(/usr/bin/osascript <<'APPLESCRIPT'
tell application "System Events" to activate
set theList to {"Admin dashboard (bolt.new/admin)", "Admin users (by ID/email)", "Rate limits (user ID)", "Token reset (user ID)", "Sites and Deployments", "Static Hosting Sites", "Import ZIP", "Bolt DB", "Token Usage", "Snapshots", "Netlify Partner Accounts", "Org rate limits"}
set choiceResult to choose from list theList with title "Bolt Admin Hub" with prompt "Choose section" OK button name "Open" cancel button name "Cancel" default items {"Admin dashboard (bolt.new/admin)"}
if choiceResult is false then
return ""
end if
return (item 1 of choiceResult) as text
APPLESCRIPT
) || true
CHOICE=$(printf '%s' "$CHOICE" | tr -d '\r\n' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
if [[ -z "$CHOICE" ]]; then
echo "Cancelled."
exit 0
fi
case "$CHOICE" in
*"Admin dashboard"*) ACTION="dashboard" ;;
*"Admin users"*) ACTION="users" ;;
*"Rate limits"*) ACTION="rate-limits" ;;
*"Token reset"*) ACTION="token-reset" ;;
*"Sites and Deployments"*) ACTION="sites" ;;
*"Static Hosting"*) ACTION="static-hosting" ;;
*"Import ZIP"*) ACTION="import-zip" ;;
*"Bolt DB"*) ACTION="bolt-db" ;;
*"Token Usage"*) ACTION="token-usage" ;;
*"Snapshots"*) ACTION="snapshots" ;;
*"Netlify Partner"*) ACTION="netlify" ;;
*"Org rate limits"*) ACTION="org-rate-limits" ;;
*) ACTION="dashboard" ;;
esac
fi
# Resolve URL for chosen action (optional ID)
open_url() {
local url="$1"
if [[ -n "$url" ]]; then
open "$url"
echo "Opened: $url"
else
echo "No URL for action: $ACTION"
exit 1
fi
}
case "$ACTION" in
dashboard)
open_url "$BOLT_ADMIN"
;;
users)
if [[ -n "$ID" ]]; then
if [[ "$ID" =~ ^[0-9]+$ ]]; then
open_url "https://stackblitz.com/admin/users?q%5Bid_eq%5D=${ID}&commit=Filter&order=id_desc"
else
enc=$(python3 -c "import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))" "$ID")
open_url "https://stackblitz.com/admin/users?q%5Bby_email_address%5D=${enc}&commit=Filter&order=id_desc"
fi
else
open_url "https://stackblitz.com/admin/users?commit=Filter&order=id_desc"
fi
;;
rate-limits)
if [[ -z "$ID" ]]; then
ID=$(pbpaste | tr -d '\n' | grep -Eo '^\d{4,}$' || true)
fi
if [[ -z "$ID" || ! "$ID" =~ ^[0-9]+$ ]]; then
echo "Provide User ID as argument or copy it to clipboard."
exit 1
fi
open_url "${BOLT_NEW}/api/rate-limits/${ID}"
;;
token-reset)
if [[ -z "$ID" ]]; then
ID=$(pbpaste | tr -d '\n' | grep -Eo '^\d{4,}$' || true)
fi
if [[ -z "$ID" || ! "$ID" =~ ^[0-9]+$ ]]; then
echo "Provide User ID as argument or copy it to clipboard."
exit 1
fi
reset_choice=$(/usr/bin/osascript -e "display dialog \"Reset tokens for user ${ID}\" with title \"Token Reset\" buttons {\"Cancel\", \"Monthly\", \"All\"} default button \"Monthly\" cancel button \"Cancel\"" -e 'return button returned of result') || true
case "$reset_choice" in
Monthly) open_url "${BOLT_NEW}/api/rate-limits/reset/${ID}/month" ;;
All) open_url "${BOLT_NEW}/api/rate-limits/reset/${ID}/all" ;;
*) echo "Cancelled." ;;
esac
;;
sites)
# https://bolt.new/admin/sites β Filter by project ID or user ID (createdBy)
if [[ -n "$ID" && "$ID" =~ ^[0-9]+$ ]]; then
open_url "${BOLT_ADMIN}/sites?q%5Bproject_id_eq%5D=${ID}&commit=Filter"
else
open_url "${BOLT_ADMIN}/sites"
fi
;;
static-hosting)
# https://bolt.new/admin/static-hosting β Search by domain, project ID, or user ID
if [[ -n "$ID" && "$ID" =~ ^[0-9]+$ ]]; then
open_url "${BOLT_ADMIN}/static-hosting?q%5Bproject_id_eq%5D=${ID}&commit=Filter"
else
open_url "${BOLT_ADMIN}/static-hosting"
fi
;;
import-zip)
# https://bolt.new/admin/import-zip β Upload ZIP to create project (no ID in URL)
open_url "${BOLT_ADMIN}/import-zip"
;;
bolt-db)
# https://bolt.new/admin/bolt-db β Supabase project integrations (project ID or slug)
if [[ -n "$ID" ]]; then
open_url "${BOLT_ADMIN}/bolt-db?q%5Bproject_id_eq%5D=${ID}&commit=Filter"
else
open_url "${BOLT_ADMIN}/bolt-db"
fi
;;
token-usage)
# https://bolt.new/admin/token-usage β Filter by user ID or project ID
if [[ -n "$ID" && "$ID" =~ ^[0-9]+$ ]]; then
open_url "${BOLT_ADMIN}/token-usage?q%5Buser_id_eq%5D=${ID}&commit=Filter"
else
open_url "${BOLT_ADMIN}/token-usage"
fi
;;
snapshots)
# https://bolt.new/admin/snapshots β Filter by project ID or user ID
if [[ -n "$ID" && "$ID" =~ ^[0-9]+$ ]]; then
open_url "${BOLT_ADMIN}/snapshots?q%5Bproject_id_eq%5D=${ID}&commit=Filter"
else
open_url "${BOLT_ADMIN}/snapshots"
fi
;;
netlify)
# https://bolt.new/admin/netlify-partner-accounts β Search by user ID, org ID, or account slug
if [[ -n "$ID" && "$ID" =~ ^[0-9]+$ ]]; then
open_url "${BOLT_ADMIN}/netlify-partner-accounts?q%5Buser_id_eq%5D=${ID}&commit=Filter"
else
open_url "${BOLT_ADMIN}/netlify-partner-accounts"
fi
;;
org-rate-limits)
# Delegate to org-rate-limits.sh (browser org extraction + prompt); avoids fragile clipboard-only org guessing.
if [[ -z "$ID" ]]; then
ID=$(pbpaste | tr -d '\n' | grep -Eo '^\d{4,}$' | head -n1 || true)
fi
if [[ -z "$ID" || ! "$ID" =~ ^[0-9]+$ ]]; then
echo "Provide User ID as argument or copy it to clipboard; or run org-rate-limits.sh <UserID> [OrgID]."
open_url "${STACKBLITZ_ADMIN}/organizations"
elif [[ -x "$SCRIPT_DIR/org-rate-limits.sh" ]]; then
exec "$SCRIPT_DIR/org-rate-limits.sh" "$ID"
else
echo "org-rate-limits.sh not found or not executable at $SCRIPT_DIR" >&2
open_url "${STACKBLITZ_ADMIN}/organizations"
fi
;;
*)
open_url "$BOLT_ADMIN"
;;
esac