Skip to content

Commit d5fbc3c

Browse files
committed
cleanup enterprise typing code
1 parent 7eab00b commit d5fbc3c

File tree

3 files changed

+9
-31
lines changed

3 files changed

+9
-31
lines changed

apps/sim/app/api/workflows/[id]/execute/route.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,9 @@ async function handleAsyncExecution(params: AsyncExecutionParams): Promise<NextR
207207
}
208208

209209
try {
210-
const jobQueue = shouldUseBullMQ() ? null : await getJobQueue()
211-
const jobId = shouldUseBullMQ()
210+
const useBullMQ = shouldUseBullMQ()
211+
const jobQueue = useBullMQ ? null : await getJobQueue()
212+
const jobId = useBullMQ
212213
? await enqueueWorkspaceDispatch({
213214
id: executionId,
214215
workspaceId,

apps/sim/lib/billing/types/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import { z } from 'zod'
66

77
export const enterpriseSubscriptionMetadataSchema = z.object({
8-
plan: z.literal('enterprise'),
8+
plan: z
9+
.string()
10+
.transform((v) => v.toLowerCase())
11+
.pipe(z.literal('enterprise')),
912
// The referenceId must be provided in Stripe metadata to link to the organization
1013
// This gets stored in the subscription.referenceId column
1114
referenceId: z.string().min(1),

apps/sim/lib/billing/webhooks/enterprise.ts

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -55,34 +55,8 @@ export async function handleManualEnterpriseSubscription(event: Stripe.Event) {
5555
})
5656
throw new Error('Invalid enterprise metadata for subscription')
5757
}
58-
const metadataJson: Record<string, unknown> = {
59-
...metadata,
60-
workspaceConcurrencyLimit:
61-
typeof metadata.workspaceConcurrencyLimit === 'string'
62-
? Number.parseInt(metadata.workspaceConcurrencyLimit, 10)
63-
: metadata.workspaceConcurrencyLimit,
64-
}
65-
66-
const seats = enterpriseMetadata.seats
67-
const monthlyPrice = enterpriseMetadata.monthlyPrice
6858

69-
if (!seats || seats <= 0 || Number.isNaN(seats)) {
70-
logger.error('[subscription.created] Invalid or missing seats in enterprise metadata', {
71-
subscriptionId: stripeSubscription.id,
72-
seatsRaw: enterpriseMetadata.seats,
73-
seatsParsed: seats,
74-
})
75-
throw new Error('Enterprise subscription must include valid seats in metadata')
76-
}
77-
78-
if (!monthlyPrice || monthlyPrice <= 0 || Number.isNaN(monthlyPrice)) {
79-
logger.error('[subscription.created] Invalid or missing monthlyPrice in enterprise metadata', {
80-
subscriptionId: stripeSubscription.id,
81-
monthlyPriceRaw: enterpriseMetadata.monthlyPrice,
82-
monthlyPriceParsed: monthlyPrice,
83-
})
84-
throw new Error('Enterprise subscription must include valid monthlyPrice in metadata')
85-
}
59+
const { seats, monthlyPrice } = enterpriseMetadata
8660

8761
// Get the first subscription item which contains the period information
8862
const referenceItem = stripeSubscription.items?.data?.[0]
@@ -106,7 +80,7 @@ export async function handleManualEnterpriseSubscription(event: Stripe.Event) {
10680
? new Date(stripeSubscription.trial_start * 1000)
10781
: null,
10882
trialEnd: stripeSubscription.trial_end ? new Date(stripeSubscription.trial_end * 1000) : null,
109-
metadata: metadataJson,
83+
metadata: metadata as Record<string, unknown>,
11084
}
11185

11286
const existing = await db

0 commit comments

Comments
 (0)