black.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { z } from "zod"
  2. import { fn } from "./util/fn"
  3. import { Resource } from "@opencode-ai/console-resource"
  4. import { BlackPlans } from "./schema/billing.sql"
  5. import { Subscription } from "./subscription"
  6. export namespace BlackData {
  7. export const getLimits = fn(
  8. z.object({
  9. plan: z.enum(BlackPlans),
  10. }),
  11. ({ plan }) => {
  12. return Subscription.getLimits()["black"][plan]
  13. },
  14. )
  15. export const productID = fn(z.void(), () => Resource.ZEN_BLACK_PRICE.product)
  16. export const planToPriceID = fn(
  17. z.object({
  18. plan: z.enum(BlackPlans),
  19. }),
  20. ({ plan }) => {
  21. if (plan === "200") return Resource.ZEN_BLACK_PRICE.plan200
  22. if (plan === "100") return Resource.ZEN_BLACK_PRICE.plan100
  23. return Resource.ZEN_BLACK_PRICE.plan20
  24. },
  25. )
  26. export const priceIDToPlan = fn(
  27. z.object({
  28. priceID: z.string(),
  29. }),
  30. ({ priceID }) => {
  31. if (priceID === Resource.ZEN_BLACK_PRICE.plan200) return "200"
  32. if (priceID === Resource.ZEN_BLACK_PRICE.plan100) return "100"
  33. return "20"
  34. },
  35. )
  36. }