11import { db , workflowDeploymentVersion } from '@sim/db'
22import { and , desc , eq } from 'drizzle-orm'
33import type { NextRequest , NextResponse } from 'next/server'
4+ import { verifyInternalToken } from '@/lib/auth/internal'
45import { createLogger } from '@/lib/logs/console/logger'
56import { generateRequestId } from '@/lib/utils'
67import { validateWorkflowPermissions } from '@/lib/workflows/utils'
@@ -23,10 +24,22 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
2324 try {
2425 logger . debug ( `[${ requestId } ] Fetching deployed state for workflow: ${ id } ` )
2526
26- const { error } = await validateWorkflowPermissions ( id , requestId , 'read' )
27- if ( error ) {
28- const response = createErrorResponse ( error . message , error . status )
29- return addNoCacheHeaders ( response )
27+ const authHeader = request . headers . get ( 'authorization' )
28+ let isInternalCall = false
29+
30+ if ( authHeader ?. startsWith ( 'Bearer ' ) ) {
31+ const token = authHeader . split ( ' ' ) [ 1 ]
32+ isInternalCall = await verifyInternalToken ( token )
33+ }
34+
35+ if ( ! isInternalCall ) {
36+ const { error } = await validateWorkflowPermissions ( id , requestId , 'read' )
37+ if ( error ) {
38+ const response = createErrorResponse ( error . message , error . status )
39+ return addNoCacheHeaders ( response )
40+ }
41+ } else {
42+ logger . debug ( `[${ requestId } ] Internal API call for deployed workflow: ${ id } ` )
3043 }
3144
3245 const [ active ] = await db
0 commit comments