mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-23 05:47:59 -05:00
* my test changes for branch protection * feat(api): introduced 'deploy as an API' button and updated workflows db to include status of deployment * feat(api): added 'trigger' column for logs table to indicate source of workflow run, persist logs from API executions, removed session validation in favor of API key * fix(bug): cleanup old reference to JSX element in favor of ReactElement * feat(api): added persistent notification for one-click deployment with copy boxes for url, keys, & ex curl * fix(ui/notifications): cleaned up deploy with one-click button ui
57 lines
1.2 KiB
TypeScript
57 lines
1.2 KiB
TypeScript
import { NextRequest } from 'next/server'
|
|
import { getWorkflowById } from '@/lib/workflows'
|
|
|
|
export interface ValidationResult {
|
|
error?: { message: string; status: number }
|
|
workflow?: any
|
|
}
|
|
|
|
export async function validateWorkflowAccess(
|
|
request: NextRequest,
|
|
workflowId: string,
|
|
requireDeployment = true
|
|
): Promise<ValidationResult> {
|
|
try {
|
|
const workflow = await getWorkflowById(workflowId)
|
|
if (!workflow) {
|
|
return {
|
|
error: {
|
|
message: 'Workflow not found',
|
|
status: 404,
|
|
},
|
|
}
|
|
}
|
|
|
|
if (requireDeployment) {
|
|
if (!workflow.isDeployed) {
|
|
return {
|
|
error: {
|
|
message: 'Workflow is not deployed',
|
|
status: 403,
|
|
},
|
|
}
|
|
}
|
|
|
|
// API key authentication
|
|
const apiKey = request.headers.get('x-api-key')
|
|
if (!apiKey || !workflow.apiKey || apiKey !== workflow.apiKey) {
|
|
return {
|
|
error: {
|
|
message: 'Unauthorized',
|
|
status: 401,
|
|
},
|
|
}
|
|
}
|
|
}
|
|
return { workflow }
|
|
} catch (error) {
|
|
console.error('Validation error:', error)
|
|
return {
|
|
error: {
|
|
message: 'Internal server error',
|
|
status: 500,
|
|
},
|
|
}
|
|
}
|
|
}
|