diff options
| author | Frank <[email protected]> | 2026-01-22 12:40:42 -0500 |
|---|---|---|
| committer | Frank <[email protected]> | 2026-01-22 13:02:28 -0500 |
| commit | a890d51bbc6a5608ad5992c74ee49153775aceb3 (patch) | |
| tree | 5b4e4b53cfc44db4242b23d3bce48bba4a303a67 /packages/console/core/script | |
| parent | bb582416f216de684bf6861353a3111cde2c461d (diff) | |
| download | opencode-a890d51bbc6a5608ad5992c74ee49153775aceb3.tar.gz opencode-a890d51bbc6a5608ad5992c74ee49153775aceb3.zip | |
wip: zen black
Diffstat (limited to 'packages/console/core/script')
| -rw-r--r-- | packages/console/core/script/lookup-user.ts | 11 | ||||
| -rwxr-xr-x | packages/console/core/script/promote-black.ts | 6 | ||||
| -rwxr-xr-x | packages/console/core/script/update-black.ts | 8 |
3 files changed, 15 insertions, 10 deletions
diff --git a/packages/console/core/script/lookup-user.ts b/packages/console/core/script/lookup-user.ts index 3dc5e7a96..355716d1d 100644 --- a/packages/console/core/script/lookup-user.ts +++ b/packages/console/core/script/lookup-user.ts @@ -1,7 +1,7 @@ import { Database, and, eq, sql } from "../src/drizzle/index.js" import { AuthTable } from "../src/schema/auth.sql.js" import { UserTable } from "../src/schema/user.sql.js" -import { BillingTable, PaymentTable, SubscriptionTable, UsageTable } from "../src/schema/billing.sql.js" +import { BillingTable, PaymentTable, SubscriptionTable, SubscriptionPlan, UsageTable } from "../src/schema/billing.sql.js" import { WorkspaceTable } from "../src/schema/workspace.sql.js" import { BlackData } from "../src/black.js" import { centsToMicroCents } from "../src/util/price.js" @@ -86,8 +86,10 @@ async function printWorkspace(workspaceID: string) { timeFixedUpdated: SubscriptionTable.timeFixedUpdated, timeRollingUpdated: SubscriptionTable.timeRollingUpdated, timeSubscriptionCreated: SubscriptionTable.timeCreated, + subscription: BillingTable.subscription, }) .from(UserTable) + .innerJoin(BillingTable, eq(BillingTable.workspaceID, workspace.id)) .leftJoin(AuthTable, and(eq(UserTable.accountID, AuthTable.accountID), eq(AuthTable.provider, "email"))) .leftJoin(SubscriptionTable, eq(SubscriptionTable.userID, UserTable.id)) .where(eq(UserTable.workspaceID, workspace.id)) @@ -223,17 +225,20 @@ function formatRetryTime(seconds: number) { } function getSubscriptionStatus(row: { + subscription: { + plan: typeof SubscriptionPlan[number] + } | null timeSubscriptionCreated: Date | null fixedUsage: number | null rollingUsage: number | null timeFixedUpdated: Date | null timeRollingUpdated: Date | null }) { - if (!row.timeSubscriptionCreated) { + if (!row.timeSubscriptionCreated || !row.subscription) { return { weekly: null, rolling: null, rateLimited: null, retryIn: null } } - const black = BlackData.get() + const black = BlackData.get({ plan: row.subscription.plan }) const now = new Date() const week = getWeekBounds(now) diff --git a/packages/console/core/script/promote-black.ts b/packages/console/core/script/promote-black.ts index bb3dcc6f7..4338d0e42 100755 --- a/packages/console/core/script/promote-black.ts +++ b/packages/console/core/script/promote-black.ts @@ -12,11 +12,11 @@ const root = path.resolve(process.cwd(), "..", "..", "..") // read the secret const ret = await $`bun sst secret list`.cwd(root).text() const lines = ret.split("\n") -const value = lines.find((line) => line.startsWith("ZEN_BLACK"))?.split("=")[1] -if (!value) throw new Error("ZEN_BLACK not found") +const value = lines.find((line) => line.startsWith("ZEN_BLACK_LIMITS"))?.split("=")[1] +if (!value) throw new Error("ZEN_BLACK_LIMITS not found") // validate value BlackData.validate(JSON.parse(value)) // update the secret -await $`bun sst secret set ZEN_BLACK ${value} --stage ${stage}` +await $`bun sst secret set ZEN_BLACK_LIMITS ${value} --stage ${stage}` diff --git a/packages/console/core/script/update-black.ts b/packages/console/core/script/update-black.ts index 58923b457..695a5d3ce 100755 --- a/packages/console/core/script/update-black.ts +++ b/packages/console/core/script/update-black.ts @@ -8,10 +8,10 @@ import { BlackData } from "../src/black" const root = path.resolve(process.cwd(), "..", "..", "..") const secrets = await $`bun sst secret list`.cwd(root).text() -// read the line starting with "ZEN_BLACK" +// read value const lines = secrets.split("\n") -const oldValue = lines.find((line) => line.startsWith("ZEN_BLACK"))?.split("=")[1] -if (!oldValue) throw new Error("ZEN_BLACK not found") +const oldValue = lines.find((line) => line.startsWith("ZEN_BLACK_LIMITS"))?.split("=")[1] ?? "{}" +if (!oldValue) throw new Error("ZEN_BLACK_LIMITS not found") // store the prettified json to a temp file const filename = `black-${Date.now()}.json` @@ -25,4 +25,4 @@ const newValue = JSON.stringify(JSON.parse(await tempFile.text())) BlackData.validate(JSON.parse(newValue)) // update the secret -await $`bun sst secret set ZEN_BLACK ${newValue}` +await $`bun sst secret set ZEN_BLACK_LIMITS ${newValue}` |
