chore: import upstream snapshot with attribution
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* Admin API Response Helpers
|
||||
*
|
||||
* Consistent response formatting for all Admin API endpoints.
|
||||
*/
|
||||
|
||||
import { NextResponse } from 'next/server'
|
||||
import type { z } from 'zod'
|
||||
import { getValidationErrorMessage, serializeZodIssues } from '@/lib/api/server'
|
||||
import type {
|
||||
AdminErrorResponse,
|
||||
AdminListResponse,
|
||||
AdminSingleResponse,
|
||||
PaginationMeta,
|
||||
} from '@/app/api/v1/admin/types'
|
||||
|
||||
/**
|
||||
* Create a successful list response with pagination
|
||||
*/
|
||||
export function listResponse<T>(
|
||||
data: T[],
|
||||
pagination: PaginationMeta
|
||||
): NextResponse<AdminListResponse<T>> {
|
||||
return NextResponse.json({ data, pagination })
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a successful single resource response
|
||||
*/
|
||||
export function singleResponse<T>(data: T): NextResponse<AdminSingleResponse<T>> {
|
||||
return NextResponse.json({ data })
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an error response
|
||||
*/
|
||||
export function errorResponse(
|
||||
code: string,
|
||||
message: string,
|
||||
status: number,
|
||||
details?: unknown
|
||||
): NextResponse<AdminErrorResponse> {
|
||||
const body: AdminErrorResponse = {
|
||||
error: { code, message },
|
||||
}
|
||||
|
||||
if (details !== undefined) {
|
||||
body.error.details = details
|
||||
}
|
||||
|
||||
return NextResponse.json(body, { status })
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Common Error Responses
|
||||
// =============================================================================
|
||||
|
||||
export function unauthorizedResponse(message = 'Authentication required'): NextResponse {
|
||||
return errorResponse('UNAUTHORIZED', message, 401)
|
||||
}
|
||||
|
||||
export function forbiddenResponse(message = 'Access denied'): NextResponse {
|
||||
return errorResponse('FORBIDDEN', message, 403)
|
||||
}
|
||||
|
||||
export function notFoundResponse(resource: string): NextResponse {
|
||||
return errorResponse('NOT_FOUND', `${resource} not found`, 404)
|
||||
}
|
||||
|
||||
export function badRequestResponse(message: string, details?: unknown): NextResponse {
|
||||
return errorResponse('BAD_REQUEST', message, 400, details)
|
||||
}
|
||||
|
||||
export function adminValidationErrorResponse(error: z.ZodError): NextResponse {
|
||||
return badRequestResponse(
|
||||
getValidationErrorMessage(error, 'Invalid request body'),
|
||||
serializeZodIssues(error)
|
||||
)
|
||||
}
|
||||
|
||||
export function adminInvalidJsonResponse(): NextResponse {
|
||||
return badRequestResponse('Request body must be valid JSON')
|
||||
}
|
||||
|
||||
export function internalErrorResponse(message = 'Internal server error'): NextResponse {
|
||||
return errorResponse('INTERNAL_ERROR', message, 500)
|
||||
}
|
||||
|
||||
export function notConfiguredResponse(): NextResponse {
|
||||
return errorResponse(
|
||||
'NOT_CONFIGURED',
|
||||
'Admin API is not configured. Set ADMIN_API_KEY environment variable.',
|
||||
503
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user