0.3.48: revert trigger dev bypass for enterprise users

This commit is contained in:
Vikhyath Mondreti
2025-09-04 23:57:22 -07:00
committed by GitHub
3 changed files with 4 additions and 24 deletions

View File

@@ -23,7 +23,6 @@ import { userStats, workflow, workflowSchedule } from '@/db/schema'
import { Executor } from '@/executor'
import { Serializer } from '@/serializer'
import { RateLimiter } from '@/services/queue'
import type { SubscriptionPlan } from '@/services/queue/types'
import { mergeSubblockState } from '@/stores/workflows/server-utils'
// Add dynamic export to prevent caching
@@ -112,8 +111,6 @@ export async function GET() {
// Check rate limits for scheduled execution (checks both personal and org subscriptions)
const userSubscription = await getHighestPrioritySubscription(workflowRecord.userId)
const subscriptionPlan = (userSubscription?.plan || 'free') as SubscriptionPlan
const rateLimiter = new RateLimiter()
const rateLimitCheck = await rateLimiter.checkRateLimitWithSubscription(
workflowRecord.userId,

View File

@@ -14,7 +14,6 @@ import { executeWebhookJob } from '@/background/webhook-execution'
import { db } from '@/db'
import { webhook, workflow } from '@/db/schema'
import { RateLimiter } from '@/services/queue'
import type { SubscriptionPlan } from '@/services/queue/types'
const logger = createLogger('WebhookTriggerAPI')
@@ -248,14 +247,10 @@ export async function POST(
}
// --- PHASE 3: Rate limiting for webhook execution ---
let isEnterprise = false
try {
// Get user subscription for rate limiting (checks both personal and org subscriptions)
const userSubscription = await getHighestPrioritySubscription(foundWorkflow.userId)
const subscriptionPlan = (userSubscription?.plan || 'free') as SubscriptionPlan
isEnterprise = subscriptionPlan === 'enterprise'
// Check async rate limits (webhooks are processed asynchronously)
const rateLimiter = new RateLimiter()
const rateLimitCheck = await rateLimiter.checkRateLimitWithSubscription(
@@ -332,7 +327,7 @@ export async function POST(
// Continue processing - better to risk usage limit bypass than fail webhook
}
// --- PHASE 5: Queue webhook execution (trigger.dev or direct based on plan/env) ---
// --- PHASE 5: Queue webhook execution (trigger.dev or direct based on env) ---
try {
const payload = {
webhookId: foundWebhook.id,
@@ -345,9 +340,7 @@ export async function POST(
blockId: foundWebhook.blockId,
}
// Enterprise users always execute directly, others check TRIGGER_DEV_ENABLED env
// Note: isEnterprise was already determined during rate limiting phase
const useTrigger = !isEnterprise && isTruthy(env.TRIGGER_DEV_ENABLED)
const useTrigger = isTruthy(env.TRIGGER_DEV_ENABLED)
if (useTrigger) {
const handle = await tasks.trigger('webhook-execution', payload)
@@ -359,9 +352,8 @@ export async function POST(
void executeWebhookJob(payload).catch((error) => {
logger.error(`[${requestId}] Direct webhook execution failed`, error)
})
const reason = isEnterprise ? 'Enterprise plan' : 'Trigger.dev disabled'
logger.info(
`[${requestId}] Queued direct webhook execution for ${foundWebhook.provider} webhook (${reason})`
`[${requestId}] Queued direct webhook execution for ${foundWebhook.provider} webhook (Trigger.dev disabled)`
)
}

View File

@@ -23,12 +23,7 @@ import { db } from '@/db'
import { userStats } from '@/db/schema'
import { Executor } from '@/executor'
import { Serializer } from '@/serializer'
import {
RateLimitError,
RateLimiter,
type SubscriptionPlan,
type TriggerType,
} from '@/services/queue'
import { RateLimitError, RateLimiter, type TriggerType } from '@/services/queue'
import { mergeSubblockState } from '@/stores/workflows/server-utils'
const logger = createLogger('WorkflowExecuteAPI')
@@ -378,8 +373,6 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
// Get user subscription (checks both personal and org subscriptions)
const userSubscription = await getHighestPrioritySubscription(validation.workflow.userId)
const subscriptionPlan = (userSubscription?.plan || 'free') as SubscriptionPlan
const rateLimiter = new RateLimiter()
const rateLimitCheck = await rateLimiter.checkRateLimitWithSubscription(
validation.workflow.userId,
@@ -505,8 +498,6 @@ export async function POST(
// Get user subscription (checks both personal and org subscriptions)
const userSubscription = await getHighestPrioritySubscription(authenticatedUserId)
const subscriptionPlan = (userSubscription?.plan || 'free') as SubscriptionPlan
if (isAsync) {
try {
const rateLimiter = new RateLimiter()