mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 07:42:23 +00:00
Every new endpoint of the contract exists, wrapped in apiHandler, with its authentication, module gate and request validation, and answers 501 not_implemented until its behaviour lands. The OpenAPI document carries the new operations and schemas and the additive response fields on the changed routes. The four server feature flags are published as false. contract-stub-inventory.test.ts registers the stubbed routes; each one leaves the register with the change that fills it. The route, sharing, session, security, module-gate and outcome inventories name the new routes deliberately, and the error-code catalogue lists the codes the routes emit today.
53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
/**
|
|
* v1.43 — a supplement's composition per unit (tablet, capsule).
|
|
*
|
|
* The shape is checked here; whether `nutrient` is a catalogue code and
|
|
* `unit` one of its input units is checked against the nutrient catalogue by
|
|
* the route (422 `medications.ingredients.unitMismatch` carries the index and
|
|
* the allowed units), so the catalogue stays the one place units live.
|
|
*/
|
|
import { z } from "zod/v4";
|
|
|
|
export const MEDICATION_INGREDIENTS_MAX = 40;
|
|
export const MEDICATION_INGREDIENT_SOURCES = ["MANUAL", "LABEL_AI"] as const;
|
|
|
|
export const medicationIngredientInputSchema = z.strictObject({
|
|
nutrient: z.string().trim().min(1).max(40),
|
|
amount: z.number().finite().positive(),
|
|
unit: z.string().trim().min(1).max(8),
|
|
});
|
|
|
|
export const medicationIngredientsPutSchema = z
|
|
.strictObject({
|
|
ingredients: z
|
|
.array(medicationIngredientInputSchema)
|
|
.max(MEDICATION_INGREDIENTS_MAX),
|
|
source: z.enum(MEDICATION_INGREDIENT_SOURCES).optional().default("MANUAL"),
|
|
})
|
|
.superRefine((value, ctx) => {
|
|
const seen = new Set<string>();
|
|
value.ingredients.forEach((ingredient, index) => {
|
|
if (seen.has(ingredient.nutrient)) {
|
|
ctx.addIssue({
|
|
code: "custom",
|
|
path: ["ingredients", index, "nutrient"],
|
|
message: "Each nutrient may appear once",
|
|
});
|
|
}
|
|
seen.add(ingredient.nutrient);
|
|
});
|
|
});
|
|
export type MedicationIngredientsPutInput = z.infer<
|
|
typeof medicationIngredientsPutSchema
|
|
>;
|
|
|
|
/** Label photo upload limits for `POST /api/medications/{id}/ingredients/extract`. */
|
|
export const SUPPLEMENT_LABEL_MAX_BYTES = 10 * 1024 * 1024;
|
|
export const SUPPLEMENT_LABEL_MIME_TYPES = [
|
|
"image/jpeg",
|
|
"image/png",
|
|
"image/heic",
|
|
"image/webp",
|
|
"application/pdf",
|
|
] as const;
|