Feature/api (#82)

* 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
This commit is contained in:
waleedlatif1
2025-02-23 13:46:50 -08:00
committed by GitHub
parent 48b6095d53
commit f52de5d1d6
27 changed files with 2184 additions and 1480 deletions

View File

@@ -9,6 +9,7 @@ export interface LogEntry {
message: string
createdAt: Date
duration?: string
trigger?: string
}
export async function persistLog(log: LogEntry) {

View File

@@ -1,5 +1,5 @@
import { type ClassValue, clsx } from 'clsx'
import { createCipheriv, createDecipheriv, randomBytes } from 'crypto'
import { createCipheriv, createDecipheriv, createHash, randomBytes } from 'crypto'
import { twMerge } from 'tailwind-merge'
export function cn(...inputs: ClassValue[]) {
@@ -117,3 +117,17 @@ export function convertScheduleOptionsToCron(
throw new Error('Unsupported schedule type')
}
}
export async function generateApiKey(): Promise<string> {
const buffer = randomBytes(32)
const hash = createHash('sha256').update(buffer).digest('hex')
return `wf_${hash}`
}
export async function validateApiKey(
apiKey: string | null,
storedApiKey: string | null
): Promise<boolean> {
if (!apiKey || !storedApiKey) return false
return apiKey === storedApiKey
}

30
lib/workflows.ts Normal file
View File

@@ -0,0 +1,30 @@
import { eq } from 'drizzle-orm'
import { db } from '@/db'
import { workflow as workflowTable } from '@/db/schema'
export async function getWorkflowById(id: string) {
const workflows = await db.select().from(workflowTable).where(eq(workflowTable.id, id)).limit(1)
return workflows[0]
}
export async function updateWorkflowDeploymentStatus(
id: string,
isDeployed: boolean,
apiKey?: string
) {
return db
.update(workflowTable)
.set({
isDeployed,
deployedAt: isDeployed ? new Date() : null,
updatedAt: new Date(),
apiKey: apiKey || null,
})
.where(eq(workflowTable.id, id))
}
export function getWorkflowEndpoint(id: string) {
const baseUrl = process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:3000'
return `${baseUrl}/api/workflow/${id}`
}