SPB Git forge

spb/fetcha

Public
11commits 1branches 0releases
1.5 MBsize
maindefault branch
16 days agolast push
TypeScript 97.5% SQL 1.4% Python 0.8%
1.8 KB · 26 lines typescript
Raw Blame History
1/** Creates a verified dev admin user + org + project + API key and allowlists the email. Prints the key once. */2import { getDb, closeDb, users, organizations, organizationMembers, projects, apiKeys, signupAllowlist, eq } from "@fetcha/db";3import { generateApiKey, newId } from "@fetcha/core";4import { randomUUID } from "node:crypto";56const email = (process.argv[2] ?? "dev@fetcha.local").trim().toLowerCase();7async function main() {8  const db = getDb();9  const userId = randomUUID();10  await db.insert(users).values({ id: userId, name: "Dev User", email, emailVerified: true, role: "admin" }).onConflictDoNothing();11  const [u] = await db.select().from(users).where(eq(users.email, email));12  // Invitation-only platform: keep the allowlist consistent with the account we just created.13  await db.insert(signupAllowlist).values({ email, note: "dev-seed", userId: u!.id, usedAt: new Date() }).onConflictDoNothing();14  const orgId = newId("org");15  // `plan` defaults to "unlimited" (the only plan).16  await db.insert(organizations).values({ id: orgId, name: "Dev Org", slug: `dev-${orgId.slice(4, 10)}`, ownerUserId: u!.id, providerVisibility: true });17  await db.insert(organizationMembers).values({ organizationId: orgId, userId: u!.id, role: "owner" });18  const projectId = newId("proj");19  await db.insert(projects).values({ id: projectId, organizationId: orgId, name: "Development", slug: "development" });20  const key = generateApiKey("live");21  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" });22  console.log(JSON.stringify({ userId: u!.id, orgId, projectId, apiKey: key.plaintext }));23  await closeDb();24}25main().catch((e) => { console.error(e); process.exit(1); });26