@@ -3,20 +3,39 @@ import { AuthTable } from "../src/schema/auth.sql.js"
33import { UserTable } from "../src/schema/user.sql.js"
44import { BillingTable , PaymentTable , SubscriptionTable , BlackPlans , UsageTable } from "../src/schema/billing.sql.js"
55import { WorkspaceTable } from "../src/schema/workspace.sql.js"
6+ import { KeyTable } from "../src/schema/key.sql.js"
67import { BlackData } from "../src/black.js"
78import { centsToMicroCents } from "../src/util/price.js"
89import { getWeekBounds } from "../src/util/date.js"
910
1011// get input from command line
1112const identifier = process . argv [ 2 ]
1213if ( ! 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
1719if ( 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