From c128579cfcbe4e177124e202251e95e412bd7e67 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 22 Jan 2026 22:04:55 +0000 Subject: chore: generate --- packages/console/core/src/billing.ts | 113 ++++++++++++++++++----------------- packages/console/core/src/black.ts | 45 ++++++++------ 2 files changed, 85 insertions(+), 73 deletions(-) (limited to 'packages/console/core/src') 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 { -- cgit v1.2.3