wip: zen
This commit is contained in:
@@ -3,6 +3,7 @@ import { AuthTable } from "../src/schema/auth.sql.js"
|
|||||||
import { UserTable } from "../src/schema/user.sql.js"
|
import { UserTable } from "../src/schema/user.sql.js"
|
||||||
import { BillingTable, PaymentTable, SubscriptionTable, BlackPlans, UsageTable } from "../src/schema/billing.sql.js"
|
import { BillingTable, PaymentTable, SubscriptionTable, BlackPlans, UsageTable } from "../src/schema/billing.sql.js"
|
||||||
import { WorkspaceTable } from "../src/schema/workspace.sql.js"
|
import { WorkspaceTable } from "../src/schema/workspace.sql.js"
|
||||||
|
import { KeyTable } from "../src/schema/key.sql.js"
|
||||||
import { BlackData } from "../src/black.js"
|
import { BlackData } from "../src/black.js"
|
||||||
import { centsToMicroCents } from "../src/util/price.js"
|
import { centsToMicroCents } from "../src/util/price.js"
|
||||||
import { getWeekBounds } from "../src/util/date.js"
|
import { getWeekBounds } from "../src/util/date.js"
|
||||||
@@ -10,13 +11,31 @@ import { getWeekBounds } from "../src/util/date.js"
|
|||||||
// get input from command line
|
// get input from command line
|
||||||
const identifier = process.argv[2]
|
const identifier = process.argv[2]
|
||||||
if (!identifier) {
|
if (!identifier) {
|
||||||
console.error("Usage: bun lookup-user.ts <email|workspaceID>")
|
console.error("Usage: bun lookup-user.ts <email|workspaceID|apiKey>")
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// loop up by workspace ID
|
||||||
if (identifier.startsWith("wrk_")) {
|
if (identifier.startsWith("wrk_")) {
|
||||||
await printWorkspace(identifier)
|
await printWorkspace(identifier)
|
||||||
} else {
|
}
|
||||||
|
// lookup by API key
|
||||||
|
else if (identifier.startsWith("key_")) {
|
||||||
|
const key = await Database.use((tx) =>
|
||||||
|
tx
|
||||||
|
.select()
|
||||||
|
.from(KeyTable)
|
||||||
|
.where(eq(KeyTable.id, identifier))
|
||||||
|
.then((rows) => rows[0]),
|
||||||
|
)
|
||||||
|
if (!key) {
|
||||||
|
console.error("API key not found")
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
await printWorkspace(key.workspaceID)
|
||||||
|
}
|
||||||
|
// lookup by email
|
||||||
|
else {
|
||||||
const authData = await Database.use(async (tx) =>
|
const authData = await Database.use(async (tx) =>
|
||||||
tx.select().from(AuthTable).where(eq(AuthTable.subject, identifier)),
|
tx.select().from(AuthTable).where(eq(AuthTable.subject, identifier)),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user