import {z} from 'zod' export type GetApiFgr12f33Options = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const fgr12f33 = z.object({radionuclide: z.string(), z: z.number().int(), zamid: z.number().int(), adrenals: z.string(), bld_wall: z.string(), bsurface: z.string(), brain: z.string(), breasts: z.string(), esophagu: z.string(), st_wall: z.string(), si_wall: z.string(), uli_wall: z.string(), lli_wall: z.string(), kidneys: z.string(), liver: z.string(), lungs: z.string(), muscle: z.string(), ovaries: z.string(), pancreas: z.string(), r_marrow: z.string(), skin: z.string(), spleen: z.string(), testes: z.string(), thymus: z.string(), thyroid: z.string(), uterus: z.string(), h_subE: z.string(), E: z.string(), id_fgr12f33: z.number().int()}); export const getApiFgr12f33Response = z.array(fgr12f33); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Coefficients de dose issus du Fédéral Guidance 12 - Table 33 / Dose coefficients from Federal Guidance 12 - Table 33 * * GET /fgr12f33 */ export const getApiFgr12f33 = async (options: GetApiFgr12f33Options) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/fgr12f33${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiFgr12f33Response, await res.json()) };