The open source coding agent.
TypeScript
wip: zen black
Frankc0dc8ea39ef8
diff --git a/packages/console/core/script/black-onboard-waitlist.ts b/packages/console/core/script/black-onboard-waitlist.tsnew file mode 100644index 00000000000..96d0f8f9122--- /dev/null+++ b/packages/console/core/script/black-onboard-waitlist.ts@@ -0,0 +1,40 @@+import { subscribe } from "diagnostics_channel"+import { Billing } from "../src/billing.js"+import { and, Database, eq } from "../src/drizzle/index.js"+import { BillingTable, PaymentTable, SubscriptionTable } from "../src/schema/billing.sql.js"++const workspaceID = process.argv[2]++if (!workspaceID) {+ console.error("Usage: bun script/foo.ts <workspaceID>")+ process.exit(1)+}++console.log(`Onboarding to Black waitlist`)++const billing = await Database.use((tx) =>+ tx+ .select({+ subscriptionPlan: BillingTable.subscriptionPlan,+ timeSubscriptionBooked: BillingTable.timeSubscriptionBooked,+ })+ .from(BillingTable)+ .where(eq(BillingTable.workspaceID, workspaceID))+ .then((rows) => rows[0]),+)++if (!billing?.timeSubscriptionBooked) {+ console.error(`Error: Workspace is not on the waitlist`)+ process.exit(1)+}++await Database.use((tx) =>+ tx+ .update(BillingTable)+ .set({+ timeSubscriptionSelected: new Date(),+ })+ .where(eq(BillingTable.workspaceID, workspaceID)),+)++console.log(`Done`)diff --git a/packages/console/core/script/black-select-workspaces.ts b/packages/console/core/script/black-select-workspaces.tsnew file mode 100644index 00000000000..4e103b7c155--- /dev/null+++ b/packages/console/core/script/black-select-workspaces.ts@@ -0,0 +1,41 @@+import { Database, eq, and, sql, inArray, isNull, count } from "../src/drizzle/index.js"+import { BillingTable, SubscriptionPlan } from "../src/schema/billing.sql.js"+import { UserTable } from "../src/schema/user.sql.js"+import { AuthTable } from "../src/schema/auth.sql.js"++const plan = process.argv[2] as typeof SubscriptionPlan[number]+if (!SubscriptionPlan.includes(plan)) {+ console.error("Usage: bun foo.ts <count>")+ process.exit(1)+}++const workspaces = await Database.use((tx) =>+ tx+ .select({ workspaceID: BillingTable.workspaceID })+ .from(BillingTable)+ .where(and(eq(BillingTable.subscriptionPlan, plan), isNull(BillingTable.timeSubscriptionSelected)))+ .orderBy(sql`RAND()`)+ .limit(100),+)++console.log(`Found ${workspaces.length} workspaces on Black ${plan} waitlist`)++console.log("== Workspace IDs ==")+const ids = workspaces.map((w) => w.workspaceID)+for (const id of ids) {+ console.log(id)+}++console.log("\n== User Emails ==")+const emails = await Database.use((tx) =>+ tx+ .select({ email: AuthTable.subject })+ .from(UserTable)+ .innerJoin(AuthTable, and(eq(UserTable.accountID, AuthTable.accountID), eq(AuthTable.provider, "email")))+ .where(inArray(UserTable.workspaceID, ids)),+)++const unique = new Set(emails.map((row) => row.email))+for (const email of unique) {+ console.log(email)+}diff --git a/packages/console/core/script/lookup-user.ts b/packages/console/core/script/lookup-user.tsindex 0a614bc15a1..6367fd89a4a 100644--- a/packages/console/core/script/lookup-user.ts+++ b/packages/console/core/script/lookup-user.ts@@ -129,14 +129,17 @@ async function printWorkspace(workspaceID: string) {booked: BillingTable.timeSubscriptionBooked,enrichment: BillingTable.subscription,},+ timeSubscriptionSelected: BillingTable.timeSubscriptionSelected,}).from(BillingTable).where(eq(BillingTable.workspaceID, workspace.id)).then((rows) =>rows.map((row) => ({- ...row,balance: `$${(row.balance / 100000000).toFixed(2)}`,+ reload: row.reload ? "yes" : "no",+ customerID: row.customerID,+ subscriptionID: row.subscriptionID,subscription: row.subscriptionID? [`Black ${row.subscription.enrichment!.plan}`,@@ -145,7 +148,7 @@ async function printWorkspace(workspaceID: string) {`(ref: ${row.subscriptionID})`,].join(" "): row.subscription.booked- ? `Waitlist ${row.subscription.plan} plan`+ ? `Waitlist ${row.subscription.plan} plan${row.timeSubscriptionSelected ? " (selected)" : ""}`: undefined,}))[0],),