Files
ApiCore/ApiCore-Frontend/src/lib/treatments/api.ts
T
Nick SzaunigandClaude Opus 5.5 fc887d8431
Backend Image / build-and-push (push) Successful in 1m9s
Frontend Image / build-and-push (push) Successful in 2m2s
fix(ui): encode every id in API paths (client-side path traversal)
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]>
2026-10-06 06:40:25 +02:00

45 lines
1.2 KiB
TypeScript

import { apiFetch } from "@/lib/auth/api-client";
import { CreateOptions, idempotencyHeaders } from "@/lib/offline/idempotency";
import {
CreateTreatmentInput,
Treatment,
UpdateTreatmentInput,
WithdrawalStatus,
} from "./types";
export function fetchColonyTreatments(colonyId: string): Promise<Treatment[]> {
return apiFetch<Treatment[]>(`/colonies/${encodeURIComponent(colonyId)}/treatments`);
}
export function fetchWithdrawalStatus(
colonyIds: string[],
): Promise<WithdrawalStatus[]> {
if (colonyIds.length === 0) {
return Promise.resolve([]);
}
return apiFetch<WithdrawalStatus[]>(
`/treatments/withdrawal-status?colonyIds=${colonyIds.join(",")}`,
);
}
export function createTreatment(
input: CreateTreatmentInput,
options: CreateOptions = {},
): Promise<Treatment> {
return apiFetch<Treatment>("/treatments", {
method: "POST",
headers: idempotencyHeaders(options),
body: JSON.stringify(input),
});
}
export function updateTreatment(
id: string,
input: UpdateTreatmentInput,
): Promise<Treatment> {
return apiFetch<Treatment>(`/treatments/${encodeURIComponent(id)}`, {
method: "PATCH",
body: JSON.stringify(input),
});
}