mirror of
https://github.com/simstudioai/sim.git
synced 2026-02-08 05:35:14 -05:00
* feat(deployed-form): added deployed form input * styling consolidation, finishing touches on form * updated docs * remove unused files with knip * added more form fields * consolidated more test utils * remove unused/unneeded zustand stores, refactored stores for consistency * improvement(files): uncolorized plan name * feat(emcn): button-group * feat(emcn): tag input, tooltip shortcut * improvement(emcn): modal padding, api, chat, form * fix: deleted migrations * feat(form): added migrations * fix(emcn): tag input * fix: failing tests on build * add suplementary hover and fix bg color in date picker * fix: build errors --------- Co-authored-by: Emir Karabeg <emirkarabeg@berkeley.edu>
64 lines
1.6 KiB
TypeScript
64 lines
1.6 KiB
TypeScript
import { NextResponse } from 'next/server'
|
|
import { getSession } from '@/lib/auth'
|
|
import { generateRequestId } from '@/lib/core/utils/request'
|
|
|
|
export type { NotificationStatus } from '@/lib/copilot/types'
|
|
|
|
export interface CopilotAuthResult {
|
|
userId: string | null
|
|
isAuthenticated: boolean
|
|
}
|
|
|
|
export function createUnauthorizedResponse(): NextResponse {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
}
|
|
|
|
export function createBadRequestResponse(message: string): NextResponse {
|
|
return NextResponse.json({ error: message }, { status: 400 })
|
|
}
|
|
|
|
export function createNotFoundResponse(message: string): NextResponse {
|
|
return NextResponse.json({ error: message }, { status: 404 })
|
|
}
|
|
|
|
export function createInternalServerErrorResponse(message: string): NextResponse {
|
|
return NextResponse.json({ error: message }, { status: 500 })
|
|
}
|
|
|
|
export function createRequestId(): string {
|
|
return crypto.randomUUID()
|
|
}
|
|
|
|
export function createShortRequestId(): string {
|
|
return generateRequestId()
|
|
}
|
|
|
|
export interface RequestTracker {
|
|
requestId: string
|
|
startTime: number
|
|
getDuration(): number
|
|
}
|
|
|
|
export function createRequestTracker(short = true): RequestTracker {
|
|
const requestId = short ? createShortRequestId() : createRequestId()
|
|
const startTime = Date.now()
|
|
|
|
return {
|
|
requestId,
|
|
startTime,
|
|
getDuration(): number {
|
|
return Date.now() - startTime
|
|
},
|
|
}
|
|
}
|
|
|
|
export async function authenticateCopilotRequestSessionOnly(): Promise<CopilotAuthResult> {
|
|
const session = await getSession()
|
|
const userId = session?.user?.id || null
|
|
|
|
return {
|
|
userId,
|
|
isAuthenticated: userId !== null,
|
|
}
|
|
}
|