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

41 lines
1 KiB
TypeScript
Raw Permalink Normal View History

2026-01-07 04:34:10 +00:00
import { z } from "zod"
import { fn } from "./util/fn"
import { Resource } from "@opencode-ai/console-resource"
2026-02-24 09:45:39 +00:00
import { BlackPlans } from "./schema/billing.sql"
2026-03-03 05:25:03 +00:00
import { Subscription } from "./subscription"
2026-01-07 04:34:10 +00:00
export namespace BlackData {
2026-01-22 22:04:55 +00:00
export const getLimits = fn(
z.object({
2026-02-24 09:45:39 +00:00
plan: z.enum(BlackPlans),
2026-01-22 22:04:55 +00:00
}),
({ plan }) => {
2026-03-03 05:25:03 +00:00
return Subscription.getLimits()["black"][plan]
2026-01-22 22:04:55 +00:00
},
)
2026-01-22 21:59:32 +00:00
2026-02-24 09:45:39 +00:00
export const productID = fn(z.void(), () => Resource.ZEN_BLACK_PRICE.product)
2026-01-22 22:04:55 +00:00
export const planToPriceID = fn(
z.object({
2026-02-24 09:45:39 +00:00
plan: z.enum(BlackPlans),
2026-01-22 22:04:55 +00: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-22 21:59:32 +00:00
2026-01-22 22:04:55 +00: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 04:34:10 +00:00
}