@vibecodemax/cli 0.1.3 → 0.1.5
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.
- package/dist/cli.js +31 -18
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -492,31 +492,44 @@ async function createAdminUser(supabaseUrl, serviceRoleKey, email, temporaryPass
|
|
|
492
492
|
}
|
|
493
493
|
return userId;
|
|
494
494
|
}
|
|
495
|
-
async function
|
|
495
|
+
async function findAdminMembership(supabaseUrl, serviceRoleKey, userId) {
|
|
496
|
+
const result = await supabaseAdminRequest({
|
|
497
|
+
supabaseUrl,
|
|
498
|
+
serviceRoleKey,
|
|
499
|
+
method: "GET",
|
|
500
|
+
endpoint: `/rest/v1/admin_users?user_id=eq.${userId}&select=user_id,role`,
|
|
501
|
+
});
|
|
502
|
+
const rows = Array.isArray(result) ? result : [];
|
|
503
|
+
const row = rows.find((candidate) => {
|
|
504
|
+
if (!candidate || typeof candidate !== "object")
|
|
505
|
+
return false;
|
|
506
|
+
return candidate.user_id === userId;
|
|
507
|
+
});
|
|
508
|
+
return {
|
|
509
|
+
exists: Boolean(row),
|
|
510
|
+
role: typeof row?.role === "string" ? row.role : null,
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
async function promoteAdminUser(supabaseUrl, serviceRoleKey, userId) {
|
|
514
|
+
const existing = await findAdminMembership(supabaseUrl, serviceRoleKey, userId);
|
|
515
|
+
if (existing.exists)
|
|
516
|
+
return;
|
|
496
517
|
await supabaseAdminRequest({
|
|
497
518
|
supabaseUrl,
|
|
498
519
|
serviceRoleKey,
|
|
499
520
|
method: "POST",
|
|
500
|
-
endpoint: "/rest/v1/
|
|
521
|
+
endpoint: "/rest/v1/admin_users",
|
|
501
522
|
body: [
|
|
502
523
|
{
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
name: "Admin User",
|
|
506
|
-
role: "admin",
|
|
524
|
+
user_id: userId,
|
|
525
|
+
role: "super",
|
|
507
526
|
},
|
|
508
527
|
],
|
|
509
528
|
});
|
|
510
529
|
}
|
|
511
|
-
async function
|
|
512
|
-
const
|
|
513
|
-
|
|
514
|
-
serviceRoleKey,
|
|
515
|
-
method: "GET",
|
|
516
|
-
endpoint: `/rest/v1/profiles?id=eq.${userId}&select=id,role`,
|
|
517
|
-
});
|
|
518
|
-
const rows = Array.isArray(result) ? result : [];
|
|
519
|
-
return rows.some((row) => row && typeof row === "object" && row.role === "admin");
|
|
530
|
+
async function verifyAdminUser(supabaseUrl, serviceRoleKey, userId) {
|
|
531
|
+
const membership = await findAdminMembership(supabaseUrl, serviceRoleKey, userId);
|
|
532
|
+
return membership.exists;
|
|
520
533
|
}
|
|
521
534
|
async function ensureAdmin(flags) {
|
|
522
535
|
const { values } = loadLocalEnv();
|
|
@@ -538,8 +551,8 @@ async function ensureAdmin(flags) {
|
|
|
538
551
|
if (!userId) {
|
|
539
552
|
fail("INVALID_RESPONSE", "Resolved admin user ID is missing after ensure-admin.");
|
|
540
553
|
}
|
|
541
|
-
await
|
|
542
|
-
const verified = await
|
|
554
|
+
await promoteAdminUser(supabaseUrl, serviceRoleKey, userId);
|
|
555
|
+
const verified = await verifyAdminUser(supabaseUrl, serviceRoleKey, userId);
|
|
543
556
|
if (!verified) {
|
|
544
557
|
fail("ADMIN_VERIFY_FAILED", "The admin role could not be verified after promotion.");
|
|
545
558
|
}
|
|
@@ -553,7 +566,7 @@ async function ensureAdmin(flags) {
|
|
|
553
566
|
promoted: true,
|
|
554
567
|
verified: true,
|
|
555
568
|
defaultName: "Admin User",
|
|
556
|
-
applied: ["auth_user", "
|
|
569
|
+
applied: ["auth_user", "admin_users"],
|
|
557
570
|
};
|
|
558
571
|
if (temporaryPassword) {
|
|
559
572
|
result.temporaryPassword = temporaryPassword;
|