Skip to content

Commit 0772a95

Browse files
committed
wip: zen
1 parent dadddc9 commit 0772a95

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

packages/console/core/script/lookup-user.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,39 @@ import { AuthTable } from "../src/schema/auth.sql.js"
33
import { UserTable } from "../src/schema/user.sql.js"
44
import { BillingTable, PaymentTable, SubscriptionTable, BlackPlans, UsageTable } from "../src/schema/billing.sql.js"
55
import { WorkspaceTable } from "../src/schema/workspace.sql.js"
6+
import { KeyTable } from "../src/schema/key.sql.js"
67
import { BlackData } from "../src/black.js"
78
import { centsToMicroCents } from "../src/util/price.js"
89
import { getWeekBounds } from "../src/util/date.js"
910

1011
// get input from command line
1112
const identifier = process.argv[2]
1213
if (!identifier) {
13-
console.error("Usage: bun lookup-user.ts <email|workspaceID>")
14+
console.error("Usage: bun lookup-user.ts <email|workspaceID|apiKey>")
1415
process.exit(1)
1516
}
1617

18+
// loop up by workspace ID
1719
if (identifier.startsWith("wrk_")) {
1820
await printWorkspace(identifier)
19-
} else {
21+
}
22+
// lookup by API key
23+
else if (identifier.startsWith("key_")) {
24+
const key = await Database.use((tx) =>
25+
tx
26+
.select()
27+
.from(KeyTable)
28+
.where(eq(KeyTable.id, identifier))
29+
.then((rows) => rows[0]),
30+
)
31+
if (!key) {
32+
console.error("API key not found")
33+
process.exit(1)
34+
}
35+
await printWorkspace(key.workspaceID)
36+
}
37+
// lookup by email
38+
else {
2039
const authData = await Database.use(async (tx) =>
2140
tx.select().from(AuthTable).where(eq(AuthTable.subject, identifier)),
2241
)

0 commit comments

Comments
 (0)