opencode/packages/console/core/src/black.ts

41 lines
1.0 KiB
TypeScript
Raw Normal View History

2026-01-07 12:34:10 +08:00
import { z } from "zod"
import { fn } from "./util/fn"
import { Resource } from "@opencode-ai/console-resource"
2026-02-24 17:45:39 +08:00
import { BlackPlans } from "./schema/billing.sql"
2026-03-03 13:25:03 +08:00
import { Subscription } from "./subscription"
2026-01-07 12:34:10 +08:00
export namespace BlackData {
2026-01-23 06:04:55 +08:00
export const getLimits = fn(
z.object({
2026-02-24 17:45:39 +08:00
plan: z.enum(BlackPlans),
2026-01-23 06:04:55 +08:00
}),
({ plan }) => {
2026-03-03 13:25:03 +08:00
return Subscription.getLimits()["black"][plan]
2026-01-23 06:04:55 +08:00
},
)
2026-01-23 05:59:32 +08:00
2026-02-24 17:45:39 +08:00
export const productID = fn(z.void(), () => Resource.ZEN_BLACK_PRICE.product)
2026-01-23 06:04:55 +08:00
export const planToPriceID = fn(
z.object({
2026-02-24 17:45:39 +08:00
plan: z.enum(BlackPlans),
2026-01-23 06:04:55 +08:00
}),
({ plan }) => {
if (plan === "200") return Resource.ZEN_BLACK_PRICE.plan200
if (plan === "100") return Resource.ZEN_BLACK_PRICE.plan100
return Resource.ZEN_BLACK_PRICE.plan20
},
)
2026-01-23 05:59:32 +08:00
2026-01-23 06:04:55 +08:00
export const priceIDToPlan = fn(
z.object({
priceID: z.string(),
}),
({ priceID }) => {
if (priceID === Resource.ZEN_BLACK_PRICE.plan200) return "200"
if (priceID === Resource.ZEN_BLACK_PRICE.plan100) return "100"
return "20"
},
)
2026-01-07 12:34:10 +08:00
}