Follow-up to a7609ff for the whole frontend: all 30 API helpers in
src/lib now pass path values through encodeURIComponent, so an id taken
from the URL can never leave its own path segment and make the page call
another endpoint with the viewer's token.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
30 lines
914 B
TypeScript
30 lines
914 B
TypeScript
import { apiFetch } from "@/lib/auth/api-client";
|
|
import { CreateOptions, idempotencyHeaders } from "@/lib/offline/idempotency";
|
|
import { CreateHarvestInput, Harvest, UpdateHarvestInput } from "./types";
|
|
|
|
export function fetchHarvests(): Promise<Harvest[]> {
|
|
return apiFetch<Harvest[]>("/harvests");
|
|
}
|
|
|
|
export function fetchHarvest(id: string): Promise<Harvest> {
|
|
return apiFetch<Harvest>(`/harvests/${encodeURIComponent(id)}`);
|
|
}
|
|
|
|
export function createHarvest(
|
|
input: CreateHarvestInput,
|
|
options: CreateOptions = {},
|
|
): Promise<Harvest> {
|
|
return apiFetch<Harvest>("/harvests", {
|
|
method: "POST",
|
|
headers: idempotencyHeaders(options),
|
|
body: JSON.stringify(input),
|
|
});
|
|
}
|
|
|
|
export function updateHarvest(id: string, input: UpdateHarvestInput): Promise<Harvest> {
|
|
return apiFetch<Harvest>(`/harvests/${encodeURIComponent(id)}`, {
|
|
method: "PATCH",
|
|
body: JSON.stringify(input),
|
|
});
|
|
}
|