/** Creates a verified dev admin user + org + project + API key and allowlists the email. Prints the key once. */ import { getDb, closeDb, users, organizations, organizationMembers, projects, apiKeys, signupAllowlist, eq } from "@fetcha/db"; import { generateApiKey, newId } from "@fetcha/core"; import { randomUUID } from "node:crypto"; const email = (process.argv[2] ?? "dev@fetcha.local").trim().toLowerCase(); async function main() { const db = getDb(); const userId = randomUUID(); await db.insert(users).values({ id: userId, name: "Dev User", email, emailVerified: true, role: "admin" }).onConflictDoNothing(); const [u] = await db.select().from(users).where(eq(users.email, email)); // Invitation-only platform: keep the allowlist consistent with the account we just created. await db.insert(signupAllowlist).values({ email, note: "dev-seed", userId: u!.id, usedAt: new Date() }).onConflictDoNothing(); const orgId = newId("org"); // `plan` defaults to "unlimited" (the only plan). await db.insert(organizations).values({ id: orgId, name: "Dev Org", slug: `dev-${orgId.slice(4, 10)}`, ownerUserId: u!.id, providerVisibility: true }); await db.insert(organizationMembers).values({ organizationId: orgId, userId: u!.id, role: "owner" }); const projectId = newId("proj"); await db.insert(projects).values({ id: projectId, organizationId: orgId, name: "Development", slug: "development" }); const key = generateApiKey("live"); await db.insert(apiKeys).values({ id: newId("key"), organizationId: orgId, projectId, createdByUserId: u!.id, name: "dev", keyHash: key.hash, keyPrefix: key.prefix, last4: key.last4, mode: "live" }); console.log(JSON.stringify({ userId: u!.id, orgId, projectId, apiKey: key.plaintext })); await closeDb(); } main().catch((e) => { console.error(e); process.exit(1); });