Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleanup enterprise typing code
  • Loading branch information
icecrasher321 committed Mar 16, 2026
commit d5fbc3c12d177d06cc62cee6c972921276dac249
5 changes: 3 additions & 2 deletions apps/sim/app/api/workflows/[id]/execute/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,9 @@ async function handleAsyncExecution(params: AsyncExecutionParams): Promise<NextR
}

try {
const jobQueue = shouldUseBullMQ() ? null : await getJobQueue()
const jobId = shouldUseBullMQ()
const useBullMQ = shouldUseBullMQ()
const jobQueue = useBullMQ ? null : await getJobQueue()
const jobId = useBullMQ
? await enqueueWorkspaceDispatch({
id: executionId,
workspaceId,
Expand Down
5 changes: 4 additions & 1 deletion apps/sim/lib/billing/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import { z } from 'zod'

export const enterpriseSubscriptionMetadataSchema = z.object({
plan: z.literal('enterprise'),
plan: z
.string()
.transform((v) => v.toLowerCase())
.pipe(z.literal('enterprise')),
// The referenceId must be provided in Stripe metadata to link to the organization
// This gets stored in the subscription.referenceId column
referenceId: z.string().min(1),
Expand Down
30 changes: 2 additions & 28 deletions apps/sim/lib/billing/webhooks/enterprise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,8 @@ export async function handleManualEnterpriseSubscription(event: Stripe.Event) {
})
throw new Error('Invalid enterprise metadata for subscription')
}
const metadataJson: Record<string, unknown> = {
...metadata,
workspaceConcurrencyLimit:
typeof metadata.workspaceConcurrencyLimit === 'string'
? Number.parseInt(metadata.workspaceConcurrencyLimit, 10)
: metadata.workspaceConcurrencyLimit,
}

const seats = enterpriseMetadata.seats
const monthlyPrice = enterpriseMetadata.monthlyPrice

if (!seats || seats <= 0 || Number.isNaN(seats)) {
logger.error('[subscription.created] Invalid or missing seats in enterprise metadata', {
subscriptionId: stripeSubscription.id,
seatsRaw: enterpriseMetadata.seats,
seatsParsed: seats,
})
throw new Error('Enterprise subscription must include valid seats in metadata')
}

if (!monthlyPrice || monthlyPrice <= 0 || Number.isNaN(monthlyPrice)) {
logger.error('[subscription.created] Invalid or missing monthlyPrice in enterprise metadata', {
subscriptionId: stripeSubscription.id,
monthlyPriceRaw: enterpriseMetadata.monthlyPrice,
monthlyPriceParsed: monthlyPrice,
})
throw new Error('Enterprise subscription must include valid monthlyPrice in metadata')
}
const { seats, monthlyPrice } = enterpriseMetadata

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

const existing = await db
Expand Down
Loading