@knowcode/doc-builder 1.9.30 → 1.9.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/package.json +12 -2
  2. package/.claude/settings.local.json +0 -56
  3. package/CACHE-BUSTING-GUIDE.md +0 -82
  4. package/CLAUDE.md +0 -86
  5. package/CONTRIBUTING.md +0 -148
  6. package/GITHUB_SETUP.md +0 -203
  7. package/RELEASE-NOTES-1.7.5.md +0 -64
  8. package/Screenshot 2025-07-22 at 19.51.21.png +0 -0
  9. package/Screenshot 2025-07-26 at 17.06.49.png +0 -0
  10. package/add-user-clive.sql +0 -35
  11. package/add-user-lindsay-fixed.sql +0 -85
  12. package/add-user-lindsay.sql +0 -68
  13. package/add-user-pmorgan.sql +0 -35
  14. package/add-user-robbie.sql +0 -35
  15. package/add-wru-users.sql +0 -105
  16. package/debug-login.sql +0 -30
  17. package/doc-builder.config.js +0 -126
  18. package/doc-builder.config.js.backup.1753793768283 +0 -47
  19. package/doc-builder.config.js.backup.1753803964423 +0 -114
  20. package/doc-builder.config.js.backup.1753945707032 +0 -115
  21. package/doc-builder.config.js.backup.1754059241330 +0 -115
  22. package/doc-builder.config.js.backup.1754119567787 +0 -123
  23. package/doc-builder.config.js.backup.1754120048862 +0 -124
  24. package/doc-builder.config.js.backup.1754120529913 +0 -124
  25. package/doc-builder.config.js.backup.1754218469785 +0 -124
  26. package/doc-builder.config.js.backup.1754384764054 +0 -124
  27. package/doc-builder.config.js.backup.1754567425847 +0 -124
  28. package/doc-builder.config.js.backup.1754568137859 +0 -126
  29. package/doc-builder.config.js.backup.1754569388252 +0 -126
  30. package/doc-builder.config.js.backup.1754576694123 +0 -126
  31. package/doc-builder.config.js.backup.1755031374829 +0 -126
  32. package/doc-builder.config.js.backup.1755034500990 +0 -126
  33. package/doc-builder.config.js.backup.1755034809236 +0 -126
  34. package/grant-access.sql +0 -15
  35. package/html/11.png +0 -0
  36. package/html/404.html +0 -115
  37. package/html/README.html +0 -522
  38. package/html/Screenshot 2025-08-12 at 21.35.07.png +0 -0
  39. package/html/about-doc-builder.html +0 -491
  40. package/html/auth.js +0 -157
  41. package/html/claude-workflow-guide.html +0 -525
  42. package/html/css/notion-style.css +0 -2502
  43. package/html/documentation-index.html +0 -471
  44. package/html/guides/authentication-default-change.html +0 -370
  45. package/html/guides/authentication-guide.html +0 -509
  46. package/html/guides/cache-control-anti-pattern.html +0 -361
  47. package/html/guides/claude-workflow-guide.html +0 -1074
  48. package/html/guides/configuration-guide.html +0 -472
  49. package/html/guides/document-standards.html +0 -518
  50. package/html/guides/documentation-standards.html +0 -694
  51. package/html/guides/html-embedding-guide.html +0 -461
  52. package/html/guides/image-modal-guide.html +0 -515
  53. package/html/guides/next-steps-walkthrough.html +0 -638
  54. package/html/guides/phosphor-icons-guide.html +0 -584
  55. package/html/guides/private-directory-authentication-troubleshooting.html +0 -555
  56. package/html/guides/private-directory-authentication.html +0 -541
  57. package/html/guides/public-site-deployment.html +0 -431
  58. package/html/guides/search-engine-verification-guide.html +0 -542
  59. package/html/guides/seo-guide.html +0 -661
  60. package/html/guides/seo-optimization-guide.html +0 -887
  61. package/html/guides/supabase-auth-implementation-plan.html +0 -543
  62. package/html/guides/supabase-auth-integration-plan.html +0 -671
  63. package/html/guides/supabase-auth-setup-guide.html +0 -498
  64. package/html/guides/supabase-authentication-complete-guide.html +0 -866
  65. package/html/guides/troubleshooting-guide.html +0 -633
  66. package/html/guides/vercel-deployment-auth-setup.html +0 -337
  67. package/html/guides/windows-setup-guide.html +0 -859
  68. package/html/image-modal-test.html +0 -318
  69. package/html/index.html +0 -522
  70. package/html/js/auth.js +0 -157
  71. package/html/js/main.js +0 -1754
  72. package/html/launch/README.html +0 -297
  73. package/html/launch/bubble-plugin-specification.html +0 -933
  74. package/html/launch/go-to-market-strategy.html +0 -663
  75. package/html/launch/launch-announcements.html +0 -593
  76. package/html/login.html +0 -102
  77. package/html/logout.html +0 -18
  78. package/html/private/cache-control-anti-pattern.html +0 -429
  79. package/html/private/launch/README.html +0 -371
  80. package/html/private/launch/auth-cleanup-summary.html +0 -361
  81. package/html/private/launch/bubble-plugin-specification.html +0 -1007
  82. package/html/private/launch/go-to-market-strategy.html +0 -737
  83. package/html/private/launch/launch-announcements.html +0 -667
  84. package/html/private/launch/vercel-deployment-auth-setup.html +0 -417
  85. package/html/private/next-steps-walkthrough.html +0 -679
  86. package/html/private/supabase-auth-implementation-completed.html +0 -454
  87. package/html/private/supabase-auth-implementation-plan.html +0 -594
  88. package/html/private/supabase-auth-integration-plan.html +0 -704
  89. package/html/private/supabase-auth-setup-guide.html +0 -555
  90. package/html/private/test-private-doc.html +0 -302
  91. package/html/private/user-management-tooling.html +0 -601
  92. package/html/prompts/Screenshot 2025-08-02 at 08.49.55.png +0 -0
  93. package/html/prompts/beautiful-documentation-design.html +0 -784
  94. package/html/prompts/markdown-document-standards.html +0 -422
  95. package/html/prompts/project-rename-strategy-sasha-publish.html +0 -530
  96. package/html/robots.txt +0 -9
  97. package/html/sitemap.xml +0 -357
  98. package/html/test-questions/how-does-it-work%3F.html +0 -294
  99. package/html/test-questions/step-1%3A%20getting-started.html +0 -289
  100. package/html/test-questions/what-is-the-purpose.html +0 -293
  101. package/html/test-status.html +0 -281
  102. package/html/vercel-cli-setup-guide.html +0 -495
  103. package/html/vercel-first-time-setup-guide.html +0 -454
  104. package/html/vercel.json +0 -29
  105. package/html-static/11.png +0 -0
  106. package/html-static/404.html +0 -115
  107. package/html-static/README.html +0 -609
  108. package/html-static/Screenshot 2025-08-12 at 21.35.07.png +0 -0
  109. package/html-static/about-doc-builder.html +0 -578
  110. package/html-static/css/notion-style.css +0 -2502
  111. package/html-static/documentation-index.html +0 -558
  112. package/html-static/guides/authentication-default-change.html +0 -457
  113. package/html-static/guides/authentication-guide.html +0 -596
  114. package/html-static/guides/claude-workflow-guide.html +0 -1161
  115. package/html-static/guides/configuration-guide.html +0 -559
  116. package/html-static/guides/documentation-standards.html +0 -781
  117. package/html-static/guides/html-embedding-guide.html +0 -548
  118. package/html-static/guides/image-modal-guide.html +0 -602
  119. package/html-static/guides/phosphor-icons-guide.html +0 -671
  120. package/html-static/guides/private-directory-authentication-troubleshooting.html +0 -642
  121. package/html-static/guides/private-directory-authentication.html +0 -628
  122. package/html-static/guides/public-site-deployment.html +0 -518
  123. package/html-static/guides/search-engine-verification-guide.html +0 -629
  124. package/html-static/guides/seo-guide.html +0 -748
  125. package/html-static/guides/seo-optimization-guide.html +0 -974
  126. package/html-static/guides/supabase-authentication-complete-guide.html +0 -953
  127. package/html-static/guides/troubleshooting-guide.html +0 -720
  128. package/html-static/guides/windows-setup-guide.html +0 -946
  129. package/html-static/image-modal-test.html +0 -405
  130. package/html-static/index.html +0 -609
  131. package/html-static/js/main.js +0 -1754
  132. package/html-static/prompts/Screenshot 2025-08-02 at 08.49.55.png +0 -0
  133. package/html-static/prompts/beautiful-documentation-design.html +0 -871
  134. package/html-static/prompts/markdown-document-standards.html +0 -509
  135. package/html-static/prompts/project-rename-strategy-sasha-publish.html +0 -617
  136. package/html-static/robots.txt +0 -5
  137. package/html-static/sitemap.xml +0 -195
  138. package/html-static/test-questions/how-does-it-work%3F.html +0 -381
  139. package/html-static/test-questions/step-1%3A%20getting-started.html +0 -376
  140. package/html-static/test-questions/what-is-the-purpose.html +0 -380
  141. package/html-static/vercel-cli-setup-guide.html +0 -582
  142. package/html-static/vercel-first-time-setup-guide.html +0 -541
  143. package/manage-users.sql +0 -191
  144. package/migrate-to-domain-auth.sql +0 -47
  145. package/package/CACHE-BUSTING-GUIDE.md +0 -82
  146. package/package/CHANGELOG.md +0 -902
  147. package/package/README.md +0 -248
  148. package/package/assets/css/notion-style.css +0 -2211
  149. package/package/assets/js/auth.js +0 -67
  150. package/package/assets/js/main.js +0 -1565
  151. package/package/cli.js +0 -764
  152. package/package/index.js +0 -38
  153. package/package/knowcode-doc-builder-1.3.15.tgz +0 -0
  154. package/package/lib/builder.js +0 -32
  155. package/package/lib/config.js +0 -278
  156. package/package/lib/core-builder.js +0 -957
  157. package/package/lib/deploy.js +0 -497
  158. package/package/lib/dev-server.js +0 -96
  159. package/package/package.json +0 -34
  160. package/package/scripts/npx-runner.js +0 -27
  161. package/package/scripts/setup.js +0 -56
  162. package/package/test-cache-bust.sh +0 -43
  163. package/public-config.js +0 -22
  164. package/public-html/404.html +0 -115
  165. package/public-html/README.html +0 -149
  166. package/public-html/css/notion-style.css +0 -2036
  167. package/public-html/index.html +0 -149
  168. package/public-html/js/auth.js +0 -67
  169. package/public-html/js/main.js +0 -1485
  170. package/quick-test-commands.md +0 -40
  171. package/recordings/Screenshot 2025-07-24 at 18.22.01.png +0 -0
  172. package/recordings/mh-ls-22jul.txt +0 -2305
  173. package/screenshot.png +0 -0
  174. package/scripts/Screenshot 2025-07-23 at 15.39.41.png +0 -0
  175. package/setup-database-v2.sql +0 -53
  176. package/setup-database.sql +0 -41
  177. package/test-auth-config.js +0 -17
  178. package/test-cache-bust.sh +0 -43
  179. package/test-docs/README.md +0 -39
  180. package/test-html/404.html +0 -115
  181. package/test-html/README.html +0 -172
  182. package/test-html/auth.js +0 -97
  183. package/test-html/css/notion-style.css +0 -2036
  184. package/test-html/index.html +0 -172
  185. package/test-html/js/auth.js +0 -97
  186. package/test-html/js/main.js +0 -1485
  187. package/test-html/login.html +0 -102
  188. package/test-html/logout.html +0 -18
  189. package/update-domain.sql +0 -9
  190. package/user-access-view.sql +0 -49
  191. package/user-management/README.md +0 -301
  192. package/user-management/add-users.sh +0 -776
  193. package/user-management/create-user.js +0 -65
  194. package/user-management/users.txt +0 -15
  195. package/view-all-users.sql +0 -40
  196. package/wru-auth-config.js +0 -17
@@ -1,776 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Doc-Builder User Management System
4
- # Uses Supabase CLI for user creation and database operations
5
-
6
- set -e
7
-
8
- # Colors for output
9
- RED='\033[0;31m'
10
- GREEN='\033[0;32m'
11
- YELLOW='\033[1;33m'
12
- BLUE='\033[0;34m'
13
- CYAN='\033[0;36m'
14
- MAGENTA='\033[0;35m'
15
- BOLD='\033[1m'
16
- NC='\033[0m' # No Color
17
-
18
- # Configuration
19
- SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
20
- CONFIG_FILE="$SCRIPT_DIR/.supabase-config"
21
- ENV_FILE="$SCRIPT_DIR/.env"
22
- PROJECT_ID="xcihhnfcitjrwbynxmka" # Default project ID
23
-
24
- # Load .env file if exists
25
- if [ -f "$ENV_FILE" ]; then
26
- source "$ENV_FILE"
27
- fi
28
-
29
- # Load configuration if exists
30
- if [ -f "$CONFIG_FILE" ]; then
31
- source "$CONFIG_FILE"
32
- fi
33
-
34
- # Show comprehensive help
35
- show_help() {
36
- cat << 'EOF'
37
- ═══════════════════════════════════════════════════════════════════════════════════
38
- DOC-BUILDER USER MANAGEMENT SYSTEM
39
- ═══════════════════════════════════════════════════════════════════════════════════
40
-
41
- Manage user access to Supabase-authenticated documentation sites using the
42
- Supabase CLI. This tool creates users and manages their site access.
43
-
44
- PREREQUISITES:
45
- ✓ Supabase CLI installed (npm install -g supabase)
46
- ✓ Logged in to Supabase (supabase login)
47
- ✓ Project linked (or use 'setup' command)
48
-
49
- USAGE:
50
- ./add-users.sh <command> [options]
51
-
52
- COMMANDS:
53
-
54
- setup Initial setup - link your Supabase project
55
- Example: ./add-users.sh setup
56
-
57
- add <site-url> <email> Grant user access to a site
58
- Example: ./add-users.sh add docs.example.com user@email.com
59
- - Checks if user exists
60
- - If not, prompts you to create via Supabase dashboard
61
- - Grants access to the specified site
62
-
63
- bulk <site-url> <file> Add multiple users from a file
64
- Example: ./add-users.sh bulk docs.example.com users.txt
65
- - File should contain one email per line
66
- - Lines starting with # are ignored
67
- - Empty lines are skipped
68
-
69
- list <site-url> List all users with access to a site
70
- Example: ./add-users.sh list docs.example.com
71
- - Shows email, creation date, last login
72
- - Shows total user count
73
-
74
- check <email> Check user status across all sites
75
- Example: ./add-users.sh check user@email.com
76
- - Shows if user exists
77
- - Lists all sites they have access to
78
- - Shows last login time
79
-
80
- remove <site-url> <email> Remove user's access to a site
81
- Example: ./add-users.sh remove docs.example.com user@email.com
82
- - Only removes access, doesn't delete user
83
- - User can still access other sites
84
-
85
- sites List all documentation sites
86
- Example: ./add-users.sh sites
87
- - Shows site URL, name, and user count
88
-
89
- delete-user <email> Remove user access from ALL sites
90
- Example: ./add-users.sh delete-user user@email.com
91
- - Removes access to all sites
92
- - Does NOT delete the user account (use dashboard for that)
93
-
94
- SITE URLS:
95
- - Use domain without https:// prefix
96
- - Examples: docs.example.com, my-app.vercel.app
97
-
98
- ENVIRONMENT VARIABLES:
99
- SUPABASE_PROJECT_ID Your Supabase project ID (optional)
100
- SUPABASE_DB_URL Database connection URL (optional)
101
-
102
- EXAMPLES:
103
-
104
- Initial Setup:
105
- ./add-users.sh setup
106
-
107
- Add a single user:
108
- ./add-users.sh add wru-bid-analysis.vercel.app lindsay@knowcode.tech
109
-
110
- Add multiple users:
111
- echo "user1@example.com" > users.txt
112
- echo "user2@example.com" >> users.txt
113
- ./add-users.sh bulk my-docs.vercel.app users.txt
114
-
115
- Check who has access:
116
- ./add-users.sh list my-docs.vercel.app
117
-
118
- Remove someone's access:
119
- ./add-users.sh remove my-docs.vercel.app user@example.com
120
-
121
- TROUBLESHOOTING:
122
-
123
- "Supabase CLI not found"
124
- → Install it: npm install -g supabase
125
-
126
- "Not logged in to Supabase"
127
- → Run: supabase login
128
-
129
- "Project not linked"
130
- → Run: ./add-users.sh setup
131
-
132
- "User already exists"
133
- → This is fine, the script will continue
134
-
135
- "Access already granted"
136
- → User already has access to this site
137
-
138
- MORE HELP:
139
- GitHub: https://github.com/wapdat/doc-builder
140
- Docs: https://doc-builder-delta.vercel.app
141
-
142
- ═══════════════════════════════════════════════════════════════════════════════════
143
- EOF
144
- }
145
-
146
- # Check if Supabase CLI is installed
147
- check_supabase_cli() {
148
- if ! command -v supabase &> /dev/null; then
149
- echo -e "${RED}❌ Supabase CLI is not installed${NC}"
150
- echo -e "${YELLOW}Install it with: ${CYAN}npm install -g supabase${NC}"
151
- echo -e "${YELLOW}Or visit: ${CYAN}https://supabase.com/docs/guides/cli${NC}"
152
- exit 1
153
- fi
154
- }
155
-
156
- # Check if logged in to Supabase
157
- check_supabase_login() {
158
- if ! supabase projects list &> /dev/null; then
159
- echo -e "${RED}❌ Not logged in to Supabase${NC}"
160
- echo -e "${YELLOW}Please run: ${CYAN}supabase login${NC}"
161
- exit 1
162
- fi
163
- }
164
-
165
- # Setup command - link project
166
- setup_project() {
167
- echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
168
- echo -e "${BOLD}Setting up Supabase User Management${NC}"
169
- echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
170
- echo
171
-
172
- check_supabase_cli
173
- check_supabase_login
174
-
175
- # Get project ID
176
- echo -e "${YELLOW}Enter your Supabase project ID (or press Enter for default):${NC}"
177
- echo -e "${CYAN}Default: $PROJECT_ID${NC}"
178
- read -p "> " input_project_id
179
-
180
- if [ ! -z "$input_project_id" ]; then
181
- PROJECT_ID="$input_project_id"
182
- fi
183
-
184
- # Link the project
185
- echo -e "\n${BLUE}Linking to project...${NC}"
186
- if supabase link --project-ref "$PROJECT_ID"; then
187
- echo -e "${GREEN}✅ Successfully linked to project${NC}"
188
-
189
- # Save configuration
190
- echo "PROJECT_ID=\"$PROJECT_ID\"" > "$CONFIG_FILE"
191
- echo -e "${GREEN}✅ Configuration saved${NC}"
192
-
193
- # Test database connection
194
- echo -e "\n${BLUE}Testing database connection...${NC}"
195
- if supabase db push --dry-run <<< "SELECT 1;" &> /dev/null; then
196
- echo -e "${GREEN}✅ Database connection successful${NC}"
197
- else
198
- echo -e "${YELLOW}⚠️ Could not verify database connection${NC}"
199
- fi
200
-
201
- echo -e "\n${GREEN}Setup complete! You can now manage users.${NC}"
202
- else
203
- echo -e "${RED}❌ Failed to link project${NC}"
204
- echo -e "${YELLOW}Make sure the project ID is correct${NC}"
205
- exit 1
206
- fi
207
- }
208
-
209
- # Execute SQL - try different methods based on what's available
210
- execute_sql() {
211
- local sql="$1"
212
- local temp_file=$(mktemp)
213
-
214
- echo "$sql" > "$temp_file"
215
-
216
- # Method 1: Try using psql if DATABASE_URL is available
217
- if [ ! -z "$DATABASE_URL" ]; then
218
- local output=$(psql "$DATABASE_URL" -t -A -f "$temp_file" 2>&1)
219
- local status=$?
220
- rm "$temp_file"
221
-
222
- if [ $status -eq 0 ]; then
223
- echo "$output"
224
- return 0
225
- fi
226
- fi
227
-
228
- # Method 2: Try using supabase db dump to get connection details
229
- if command -v supabase &> /dev/null; then
230
- # Get database URL from supabase status
231
- local db_url=$(supabase status --output json 2>/dev/null | grep -o '"db_url":"[^"]*' | cut -d'"' -f4)
232
-
233
- if [ ! -z "$db_url" ] && [ "$db_url" != "null" ]; then
234
- # Try psql with the extracted URL
235
- local output=$(psql "$db_url" -t -A -f "$temp_file" 2>&1)
236
- local status=$?
237
- rm "$temp_file"
238
-
239
- if [ $status -eq 0 ]; then
240
- echo "$output"
241
- return 0
242
- fi
243
- fi
244
- fi
245
-
246
- # Method 3: Manual instructions as fallback
247
- rm "$temp_file"
248
- echo -e "${YELLOW}⚠️ Cannot execute SQL automatically${NC}"
249
- echo -e "${CYAN}Your Supabase CLI version doesn't support direct SQL execution.${NC}"
250
- echo -e "${CYAN}Please run this SQL manually in Supabase SQL Editor:${NC}"
251
- echo -e "${CYAN}https://supabase.com/dashboard/project/$PROJECT_ID/sql${NC}"
252
- echo
253
- echo -e "${BLUE}--- SQL TO RUN ---${NC}"
254
- echo "$sql"
255
- echo -e "${BLUE}--- END SQL ---${NC}"
256
- echo
257
- echo -e "${YELLOW}Press Enter after running the SQL...${NC}"
258
- read -p ""
259
-
260
- return 0
261
- }
262
-
263
- # Create a user using SQL (Supabase doesn't have CLI user creation)
264
- create_user() {
265
- local email="$1"
266
-
267
- echo -e "${BLUE}Checking/Creating user: $email${NC}"
268
-
269
- # Check if user exists first
270
- local check_sql="SELECT id, email FROM auth.users WHERE email = '$email';"
271
-
272
- echo -e "${CYAN}Checking database for user...${NC}"
273
- local result=$(execute_sql "$check_sql" 2>&1)
274
-
275
- # Debug output
276
- if [ ! -z "$DEBUG" ]; then
277
- echo -e "${BLUE}[DEBUG] SQL Result:${NC}"
278
- echo "$result"
279
- fi
280
-
281
- # Check if the result contains the email (case insensitive)
282
- if echo "$result" | grep -qi "$email"; then
283
- echo -e "${YELLOW}ℹ️ User already exists${NC}"
284
- return 0
285
- else
286
- echo -e "${YELLOW}⚠️ User doesn't exist yet${NC}"
287
- echo -e "${CYAN}You have two options to create the user:${NC}"
288
- echo
289
- echo -e "${BOLD}Option 1: Use Supabase Dashboard (Recommended)${NC}"
290
- echo -e "${CYAN}1. Go to: https://supabase.com/dashboard/project/$PROJECT_ID/auth/users${NC}"
291
- echo -e "${CYAN}2. Click 'Invite user'${NC}"
292
- echo -e "${CYAN}3. Enter email: $email${NC}"
293
- echo
294
- echo -e "${BOLD}Option 2: Use Service Role Key (Advanced)${NC}"
295
- echo -e "${CYAN}If you have your service_role key, I can create the user programmatically.${NC}"
296
- echo -e "${CYAN}Find it at: https://supabase.com/dashboard/project/$PROJECT_ID/settings/api${NC}"
297
- echo
298
- echo -e "${YELLOW}Choose an option:${NC}"
299
- echo -e " 1) Open dashboard and create manually"
300
- echo -e " 2) Enter service role key"
301
- echo -e " 3) Skip (user already exists elsewhere)"
302
- read -p "Choice (1/2/3): " choice
303
-
304
- case $choice in
305
- 1)
306
- echo -e "${CYAN}Opening dashboard...${NC}"
307
- if command -v open &> /dev/null; then
308
- open "https://supabase.com/dashboard/project/$PROJECT_ID/auth/users"
309
- fi
310
- echo -e "${CYAN}Press Enter after creating the user...${NC}"
311
- read -p ""
312
- ;;
313
- 2)
314
- echo -e "${YELLOW}Enter your service_role key:${NC}"
315
- read -s service_key
316
- echo
317
- if [ ! -z "$service_key" ]; then
318
- echo -e "${BLUE}Creating user programmatically...${NC}"
319
- # Get Supabase URL from config
320
- local supabase_url="https://$PROJECT_ID.supabase.co"
321
- if node "$SCRIPT_DIR/create-user.js" "$email" "$supabase_url" "$service_key" 2>&1; then
322
- echo -e "${GREEN}✅ User created programmatically${NC}"
323
- return 0
324
- else
325
- echo -e "${RED}❌ Failed to create user programmatically${NC}"
326
- echo -e "${CYAN}Please try the dashboard method instead${NC}"
327
- return 1
328
- fi
329
- fi
330
- ;;
331
- 3)
332
- echo -e "${YELLOW}Skipping user creation...${NC}"
333
- ;;
334
- *)
335
- echo -e "${RED}Invalid choice${NC}"
336
- return 1
337
- ;;
338
- esac
339
-
340
- # Check again if user was created
341
- result=$(execute_sql "$check_sql")
342
- if echo "$result" | grep -q "$email"; then
343
- echo -e "${GREEN}✅ User confirmed in database${NC}"
344
- return 0
345
- else
346
- echo -e "${RED}❌ User not found. Please create the user first.${NC}"
347
- return 1
348
- fi
349
- fi
350
- }
351
-
352
- # Grant access to a site
353
- grant_access() {
354
- local site_url="$1"
355
- local email="$2"
356
-
357
- echo -e "${BLUE}Granting access to $site_url...${NC}"
358
-
359
- local sql="
360
- -- Get site info
361
- DO \$\$
362
- DECLARE
363
- v_site_id UUID;
364
- v_user_id UUID;
365
- v_site_name TEXT;
366
- BEGIN
367
- -- Get site ID
368
- SELECT id, name INTO v_site_id, v_site_name
369
- FROM docbuilder_sites
370
- WHERE domain = '$site_url';
371
-
372
- IF v_site_id IS NULL THEN
373
- RAISE EXCEPTION 'Site not found: $site_url';
374
- END IF;
375
-
376
- -- Get user ID
377
- SELECT id INTO v_user_id
378
- FROM auth.users
379
- WHERE email = '$email';
380
-
381
- IF v_user_id IS NULL THEN
382
- RAISE EXCEPTION 'User not found: $email';
383
- END IF;
384
-
385
- -- Grant access
386
- INSERT INTO docbuilder_access (user_id, site_id)
387
- VALUES (v_user_id, v_site_id)
388
- ON CONFLICT (user_id, site_id) DO NOTHING;
389
-
390
- RAISE NOTICE 'Access granted to % for site: %', '$email', v_site_name;
391
- END\$\$;
392
-
393
- -- Show result
394
- SELECT
395
- u.email,
396
- s.name as site_name,
397
- s.domain as site_url,
398
- da.created_at as access_granted
399
- FROM docbuilder_access da
400
- JOIN auth.users u ON u.id = da.user_id
401
- JOIN docbuilder_sites s ON s.id = da.site_id
402
- WHERE u.email = '$email' AND s.domain = '$site_url';
403
- "
404
-
405
- if execute_sql "$sql"; then
406
- echo -e "${GREEN}✅ Access granted successfully${NC}"
407
- return 0
408
- else
409
- echo -e "${RED}❌ Failed to grant access${NC}"
410
- return 1
411
- fi
412
- }
413
-
414
- # Add command - create user and grant access
415
- add_user() {
416
- local site_url="$1"
417
- local email="$2"
418
-
419
- echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
420
- echo -e "${BOLD}Adding User${NC}"
421
- echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
422
- echo -e "Site: ${CYAN}$site_url${NC}"
423
- echo -e "Email: ${CYAN}$email${NC}"
424
- echo
425
-
426
- # Create user first
427
- if create_user "$email"; then
428
- # Then grant access
429
- grant_access "$site_url" "$email"
430
- fi
431
- }
432
-
433
- # Bulk add users
434
- bulk_add() {
435
- local site_url="$1"
436
- local file_path="$2"
437
-
438
- if [ ! -f "$file_path" ]; then
439
- echo -e "${RED}❌ File not found: $file_path${NC}"
440
- exit 1
441
- fi
442
-
443
- echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
444
- echo -e "${BOLD}Bulk Adding Users${NC}"
445
- echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
446
- echo -e "Site: ${CYAN}$site_url${NC}"
447
- echo -e "File: ${CYAN}$file_path${NC}"
448
- echo
449
-
450
- local success_count=0
451
- local fail_count=0
452
-
453
- while IFS= read -r email; do
454
- # Skip empty lines and comments
455
- [[ -z "$email" || "$email" =~ ^#.*$ ]] && continue
456
-
457
- # Trim whitespace
458
- email=$(echo "$email" | xargs)
459
-
460
- echo -e "\n${MAGENTA}Processing: $email${NC}"
461
- echo -e "${CYAN}────────────────────────────────${NC}"
462
-
463
- if create_user "$email" && grant_access "$site_url" "$email"; then
464
- ((success_count++))
465
- else
466
- ((fail_count++))
467
- fi
468
- done < "$file_path"
469
-
470
- echo -e "\n${BLUE}═══════════════════════════════════════════════════════════════${NC}"
471
- echo -e "${BOLD}Summary${NC}"
472
- echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
473
- echo -e "${GREEN}✅ Successful: $success_count${NC}"
474
- echo -e "${RED}❌ Failed: $fail_count${NC}"
475
- }
476
-
477
- # List users for a site
478
- list_users() {
479
- local site_url="$1"
480
-
481
- echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
482
- echo -e "${BOLD}Users with access to: $site_url${NC}"
483
- echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
484
-
485
- local sql="
486
- -- Site info
487
- SELECT name, domain, created_at
488
- FROM docbuilder_sites
489
- WHERE domain = '$site_url';
490
-
491
- -- Users with access
492
- SELECT
493
- u.email,
494
- u.created_at as user_created,
495
- da.created_at as access_granted,
496
- CASE
497
- WHEN u.last_sign_in_at IS NULL THEN 'Never logged in'
498
- ELSE 'Last login: ' || to_char(u.last_sign_in_at, 'YYYY-MM-DD HH24:MI')
499
- END as login_status
500
- FROM docbuilder_access da
501
- JOIN auth.users u ON u.id = da.user_id
502
- JOIN docbuilder_sites s ON s.id = da.site_id
503
- WHERE s.domain = '$site_url'
504
- ORDER BY da.created_at DESC;
505
-
506
- -- Count
507
- SELECT COUNT(*) as total_users
508
- FROM docbuilder_access da
509
- JOIN docbuilder_sites s ON s.id = da.site_id
510
- WHERE s.domain = '$site_url';
511
- "
512
-
513
- execute_sql "$sql"
514
- }
515
-
516
- # Check user status
517
- check_user() {
518
- local email="$1"
519
-
520
- echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
521
- echo -e "${BOLD}User Status: $email${NC}"
522
- echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
523
-
524
- local sql="
525
- -- User info
526
- SELECT
527
- id,
528
- email,
529
- created_at,
530
- last_sign_in_at,
531
- CASE
532
- WHEN last_sign_in_at IS NULL THEN 'Never logged in'
533
- ELSE 'Last login: ' || to_char(last_sign_in_at, 'YYYY-MM-DD HH24:MI')
534
- END as login_status
535
- FROM auth.users
536
- WHERE email = '$email';
537
-
538
- -- Sites with access
539
- SELECT
540
- s.name as site_name,
541
- s.domain as site_url,
542
- da.created_at as access_granted
543
- FROM docbuilder_access da
544
- JOIN auth.users u ON u.id = da.user_id
545
- JOIN docbuilder_sites s ON s.id = da.site_id
546
- WHERE u.email = '$email'
547
- ORDER BY da.created_at DESC;
548
-
549
- -- Count
550
- SELECT COUNT(*) as total_sites
551
- FROM docbuilder_access da
552
- JOIN auth.users u ON u.id = da.user_id
553
- WHERE u.email = '$email';
554
- "
555
-
556
- execute_sql "$sql"
557
- }
558
-
559
- # Remove user access
560
- remove_access() {
561
- local site_url="$1"
562
- local email="$2"
563
-
564
- echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
565
- echo -e "${BOLD}Removing Access${NC}"
566
- echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
567
- echo -e "Site: ${CYAN}$site_url${NC}"
568
- echo -e "Email: ${CYAN}$email${NC}"
569
- echo
570
-
571
- # Confirm
572
- echo -e "${YELLOW}Are you sure you want to remove access? (y/N)${NC}"
573
- read -p "> " confirm
574
-
575
- if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
576
- echo -e "${YELLOW}Cancelled${NC}"
577
- return
578
- fi
579
-
580
- local sql="
581
- -- Remove access
582
- DELETE FROM docbuilder_access
583
- WHERE user_id = (SELECT id FROM auth.users WHERE email = '$email')
584
- AND site_id = (SELECT id FROM docbuilder_sites WHERE domain = '$site_url');
585
-
586
- -- Verify removal
587
- SELECT
588
- CASE
589
- WHEN COUNT(*) = 0 THEN 'Access removed successfully'
590
- ELSE 'ERROR: User still has access'
591
- END as status
592
- FROM docbuilder_access da
593
- JOIN auth.users u ON u.id = da.user_id
594
- JOIN docbuilder_sites s ON s.id = da.site_id
595
- WHERE u.email = '$email' AND s.domain = '$site_url';
596
-
597
- -- Show remaining sites for this user
598
- SELECT
599
- s.name as site_name,
600
- s.domain as site_url,
601
- da.created_at as access_granted
602
- FROM docbuilder_access da
603
- JOIN auth.users u ON u.id = da.user_id
604
- JOIN docbuilder_sites s ON s.id = da.site_id
605
- WHERE u.email = '$email'
606
- ORDER BY da.created_at DESC;
607
- "
608
-
609
- if execute_sql "$sql"; then
610
- echo -e "${GREEN}✅ Access removed${NC}"
611
- else
612
- echo -e "${RED}❌ Failed to remove access${NC}"
613
- fi
614
- }
615
-
616
- # List all sites
617
- list_sites() {
618
- echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
619
- echo -e "${BOLD}All Documentation Sites${NC}"
620
- echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
621
-
622
- local sql="
623
- SELECT
624
- id as site_id,
625
- domain,
626
- name,
627
- created_at,
628
- (SELECT COUNT(*) FROM docbuilder_access WHERE site_id = docbuilder_sites.id) as user_count
629
- FROM docbuilder_sites
630
- ORDER BY created_at DESC;
631
- "
632
-
633
- execute_sql "$sql"
634
- }
635
-
636
- # Delete user completely
637
- delete_user() {
638
- local email="$1"
639
-
640
- echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
641
- echo -e "${BOLD}${RED}⚠️ REMOVE USER ACCESS - NOT DELETE ⚠️${NC}"
642
- echo -e "${BLUE}═══════════════════════════════════════════════════════════════${NC}"
643
- echo -e "Email: ${CYAN}$email${NC}"
644
- echo
645
- echo -e "${YELLOW}Note: Supabase CLI cannot delete users directly.${NC}"
646
- echo -e "${YELLOW}This will remove the user's access to ALL sites.${NC}"
647
- echo -e "${YELLOW}To fully delete, use Supabase dashboard.${NC}"
648
- echo
649
- echo -e "${YELLOW}Type 'REMOVE' to confirm:${NC}"
650
- read -p "> " confirm
651
-
652
- if [[ "$confirm" != "REMOVE" ]]; then
653
- echo -e "${YELLOW}Cancelled${NC}"
654
- return
655
- fi
656
-
657
- echo -e "${BLUE}Removing all access...${NC}"
658
-
659
- local sql="
660
- -- Remove all access for user
661
- DELETE FROM docbuilder_access
662
- WHERE user_id = (SELECT id FROM auth.users WHERE email = '$email');
663
-
664
- -- Show result
665
- SELECT
666
- CASE
667
- WHEN COUNT(*) = 0 THEN 'All access removed successfully'
668
- ELSE 'ERROR: User still has some access'
669
- END as status
670
- FROM docbuilder_access da
671
- JOIN auth.users u ON u.id = da.user_id
672
- WHERE u.email = '$email';
673
- "
674
-
675
- if execute_sql "$sql"; then
676
- echo -e "${GREEN}✅ All access removed${NC}"
677
- echo -e "${CYAN}To fully delete user, go to:${NC}"
678
- echo -e "${CYAN}https://supabase.com/dashboard/project/$PROJECT_ID/auth/users${NC}"
679
- else
680
- echo -e "${RED}❌ Failed to remove access${NC}"
681
- fi
682
- }
683
-
684
- # Main script logic
685
- main() {
686
- case "$1" in
687
- setup)
688
- setup_project
689
- ;;
690
-
691
- add)
692
- if [ -z "$2" ] || [ -z "$3" ]; then
693
- echo -e "${RED}❌ Missing parameters${NC}"
694
- echo -e "${YELLOW}Usage: $0 add <site-url> <email>${NC}"
695
- echo -e "${CYAN}Example: $0 add docs.example.com user@email.com${NC}"
696
- exit 1
697
- fi
698
- check_supabase_cli
699
- check_supabase_login
700
- add_user "$2" "$3"
701
- ;;
702
-
703
- bulk)
704
- if [ -z "$2" ] || [ -z "$3" ]; then
705
- echo -e "${RED}❌ Missing parameters${NC}"
706
- echo -e "${YELLOW}Usage: $0 bulk <site-url> <file>${NC}"
707
- echo -e "${CYAN}Example: $0 bulk docs.example.com users.txt${NC}"
708
- exit 1
709
- fi
710
- check_supabase_cli
711
- check_supabase_login
712
- bulk_add "$2" "$3"
713
- ;;
714
-
715
- list)
716
- if [ -z "$2" ]; then
717
- echo -e "${RED}❌ Missing site URL${NC}"
718
- echo -e "${YELLOW}Usage: $0 list <site-url>${NC}"
719
- echo -e "${CYAN}Example: $0 list docs.example.com${NC}"
720
- exit 1
721
- fi
722
- check_supabase_cli
723
- check_supabase_login
724
- list_users "$2"
725
- ;;
726
-
727
- check)
728
- if [ -z "$2" ]; then
729
- echo -e "${RED}❌ Missing email${NC}"
730
- echo -e "${YELLOW}Usage: $0 check <email>${NC}"
731
- echo -e "${CYAN}Example: $0 check user@email.com${NC}"
732
- exit 1
733
- fi
734
- check_supabase_cli
735
- check_supabase_login
736
- check_user "$2"
737
- ;;
738
-
739
- remove)
740
- if [ -z "$2" ] || [ -z "$3" ]; then
741
- echo -e "${RED}❌ Missing parameters${NC}"
742
- echo -e "${YELLOW}Usage: $0 remove <site-url> <email>${NC}"
743
- echo -e "${CYAN}Example: $0 remove docs.example.com user@email.com${NC}"
744
- exit 1
745
- fi
746
- check_supabase_cli
747
- check_supabase_login
748
- remove_access "$2" "$3"
749
- ;;
750
-
751
- sites)
752
- check_supabase_cli
753
- check_supabase_login
754
- list_sites
755
- ;;
756
-
757
- delete-user)
758
- if [ -z "$2" ]; then
759
- echo -e "${RED}❌ Missing email${NC}"
760
- echo -e "${YELLOW}Usage: $0 delete-user <email>${NC}"
761
- echo -e "${CYAN}Example: $0 delete-user user@email.com${NC}"
762
- exit 1
763
- fi
764
- check_supabase_cli
765
- check_supabase_login
766
- delete_user "$2"
767
- ;;
768
-
769
- *)
770
- show_help
771
- ;;
772
- esac
773
- }
774
-
775
- # Run main function
776
- main "$@"