summaryrefslogtreecommitdiffhomepage
path: root/packages/console/core/src
diff options
context:
space:
mode:
authorGitHub Action <[email protected]>2026-01-22 22:04:55 +0000
committerGitHub Action <[email protected]>2026-01-22 22:04:55 +0000
commitc128579cfcbe4e177124e202251e95e412bd7e67 (patch)
tree390f5b5ff97b97a024f5116934a0e4a3ed9aa8bc /packages/console/core/src
parent5f3ab9395fc8f8543724dcda914d38fba0809049 (diff)
downloadopencode-c128579cfcbe4e177124e202251e95e412bd7e67.tar.gz
opencode-c128579cfcbe4e177124e202251e95e412bd7e67.zip
chore: generate
Diffstat (limited to 'packages/console/core/src')
-rw-r--r--packages/console/core/src/billing.ts113
-rw-r--r--packages/console/core/src/black.ts45
2 files changed, 85 insertions, 73 deletions
diff --git a/packages/console/core/src/billing.ts b/packages/console/core/src/billing.ts
index 373f0c595..7031a384b 100644
--- a/packages/console/core/src/billing.ts
+++ b/packages/console/core/src/billing.ts
@@ -290,65 +290,68 @@ export namespace Billing {
},
)
- export const subscribe = fn(z.object({
- seats: z.number(),
- coupon: z.string().optional(),
- }), async ({ seats, coupon }) => {
- const user = Actor.assert("user")
- const billing = await Database.use((tx) =>
- tx
- .select({
- customerID: BillingTable.customerID,
- paymentMethodID: BillingTable.paymentMethodID,
- subscriptionID: BillingTable.subscriptionID,
- subscriptionPlan: BillingTable.subscriptionPlan,
- timeSubscriptionSelected: BillingTable.timeSubscriptionSelected,
- })
- .from(BillingTable)
- .where(eq(BillingTable.workspaceID, Actor.workspace()))
- .then((rows) => rows[0]),
- )
+ export const subscribe = fn(
+ z.object({
+ seats: z.number(),
+ coupon: z.string().optional(),
+ }),
+ async ({ seats, coupon }) => {
+ const user = Actor.assert("user")
+ const billing = await Database.use((tx) =>
+ tx
+ .select({
+ customerID: BillingTable.customerID,
+ paymentMethodID: BillingTable.paymentMethodID,
+ subscriptionID: BillingTable.subscriptionID,
+ subscriptionPlan: BillingTable.subscriptionPlan,
+ timeSubscriptionSelected: BillingTable.timeSubscriptionSelected,
+ })
+ .from(BillingTable)
+ .where(eq(BillingTable.workspaceID, Actor.workspace()))
+ .then((rows) => rows[0]),
+ )
- if (!billing) throw new Error("Billing record not found")
- if (!billing.timeSubscriptionSelected) throw new Error("Not selected for subscription")
- if (billing.subscriptionID) throw new Error("Already subscribed")
- if (!billing.customerID) throw new Error("No customer ID")
- if (!billing.paymentMethodID) throw new Error("No payment method")
- if (!billing.subscriptionPlan) throw new Error("No subscription plan")
+ if (!billing) throw new Error("Billing record not found")
+ if (!billing.timeSubscriptionSelected) throw new Error("Not selected for subscription")
+ if (billing.subscriptionID) throw new Error("Already subscribed")
+ if (!billing.customerID) throw new Error("No customer ID")
+ if (!billing.paymentMethodID) throw new Error("No payment method")
+ if (!billing.subscriptionPlan) throw new Error("No subscription plan")
- const subscription = await Billing.stripe().subscriptions.create({
- customer: billing.customerID,
- default_payment_method: billing.paymentMethodID,
- items: [{ price: BlackData.planToPriceID({ plan: billing.subscriptionPlan }) }],
- metadata: {
- workspaceID: Actor.workspace(),
- },
- })
+ const subscription = await Billing.stripe().subscriptions.create({
+ customer: billing.customerID,
+ default_payment_method: billing.paymentMethodID,
+ items: [{ price: BlackData.planToPriceID({ plan: billing.subscriptionPlan }) }],
+ metadata: {
+ workspaceID: Actor.workspace(),
+ },
+ })
- await Database.transaction(async (tx) => {
- await tx
- .update(BillingTable)
- .set({
- subscriptionID: subscription.id,
- subscription: {
- status: "subscribed",
- coupon,
- seats,
- plan: billing.subscriptionPlan!,
- },
- subscriptionPlan: null,
- timeSubscriptionBooked: null,
- timeSubscriptionSelected: null,
- })
- .where(eq(BillingTable.workspaceID, Actor.workspace()))
+ await Database.transaction(async (tx) => {
+ await tx
+ .update(BillingTable)
+ .set({
+ subscriptionID: subscription.id,
+ subscription: {
+ status: "subscribed",
+ coupon,
+ seats,
+ plan: billing.subscriptionPlan!,
+ },
+ subscriptionPlan: null,
+ timeSubscriptionBooked: null,
+ timeSubscriptionSelected: null,
+ })
+ .where(eq(BillingTable.workspaceID, Actor.workspace()))
- await tx.insert(SubscriptionTable).values({
- workspaceID: Actor.workspace(),
- id: Identifier.create("subscription"),
- userID: user.properties.userID,
+ await tx.insert(SubscriptionTable).values({
+ workspaceID: Actor.workspace(),
+ id: Identifier.create("subscription"),
+ userID: user.properties.userID,
+ })
})
- })
- return subscription.id
- })
+ return subscription.id
+ },
+ )
}
diff --git a/packages/console/core/src/black.ts b/packages/console/core/src/black.ts
index 93134de55..5f8db6273 100644
--- a/packages/console/core/src/black.ts
+++ b/packages/console/core/src/black.ts
@@ -28,28 +28,37 @@ export namespace BlackData {
return input
})
- export const getLimits = fn(z.object({
+ export const getLimits = fn(
+ z.object({
plan: z.enum(SubscriptionPlan),
- }), ({ plan }) => {
- const json = JSON.parse(Resource.ZEN_BLACK_LIMITS.value)
- return Schema.parse(json)[plan]
- })
+ }),
+ ({ plan }) => {
+ const json = JSON.parse(Resource.ZEN_BLACK_LIMITS.value)
+ return Schema.parse(json)[plan]
+ },
+ )
- export const planToPriceID = fn(z.object({
+ export const planToPriceID = fn(
+ z.object({
plan: z.enum(SubscriptionPlan),
- }), ({ 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
- })
+ }),
+ ({ 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
+ },
+ )
- 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"
- })
+ 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"
+ },
+ )
}
export namespace Black {