33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
"use server";
|
|
|
|
import type { HousekeepingErrorCode } from "@/features/housekeeping/foundation/contracts";
|
|
import { createCorrelationId } from "@/features/housekeeping/foundation/correlation";
|
|
import {
|
|
type HousekeepingSearchResponse,
|
|
searchHousekeeping,
|
|
} from "@/features/housekeeping/foundation/search/search-service";
|
|
import { getHousekeepingCapabilityContext } from "@/features/housekeeping/foundation/server-capability-context";
|
|
|
|
function failedSearch(code: HousekeepingErrorCode): HousekeepingSearchResponse {
|
|
return {
|
|
navigation: [],
|
|
commands: [],
|
|
entities: [],
|
|
errors: [{ providerId: "search", code }],
|
|
correlationId: createCorrelationId(),
|
|
};
|
|
}
|
|
|
|
export async function executeHousekeepingSearch(
|
|
term: unknown,
|
|
): Promise<HousekeepingSearchResponse> {
|
|
if (typeof term !== "string") return failedSearch("VALIDATION");
|
|
try {
|
|
await import("@/features/housekeeping/commands");
|
|
const context = await getHousekeepingCapabilityContext();
|
|
return await searchHousekeeping(term, context);
|
|
} catch {
|
|
return failedSearch("INTERNAL");
|
|
}
|
|
}
|