'use server'; import { zoektRegexSearch } from "@/features/search/zoekt/searchApi"; import { isServiceError } from "@/lib/utils"; import { NextRequest } from "next/server"; import { sew, withAuth, withOrgMembership } from "@/actions"; import { schemaValidationError, serviceErrorResponse } from "@/lib/serviceError"; import { regexSearchRequestSchema } from "@/features/search/schemas"; import { RegexSearchRequest } from "@/features/search/types"; export const POST = async (request: NextRequest) => { const domain = request.headers.get("X-Org-Domain")!; const body = await request.json(); const parsed = await regexSearchRequestSchema.safeParseAsync(body); if (!parsed.success) { return serviceErrorResponse( schemaValidationError(parsed.error) ); } const response = await postSearch(parsed.data, domain); if (isServiceError(response)) { return serviceErrorResponse(response); } return Response.json(response); } const postSearch = (request: RegexSearchRequest, domain: string) => sew(() => withAuth((session) => withOrgMembership(session, domain, async ({ orgId }) => { return zoektRegexSearch(request, orgId); } ), /* allowSingleTenantUnauthedAccess */ true));