import {z} from 'zod' export type GetApiFg15GrdSurfaceOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const fg15GrdSurface = z.object({radionuclide: z.string(), age: z.string(), "brain_(Sv.s-1.Bq-1.m2)": z.string(), "o-mucosa_(Sv.s-1.Bq-1.m2)": z.string(), "s-glands_(Sv.s-1.Bq-1.m2)": z.string(), "esophagu_(Sv.s-1.Bq-1.m2)": z.string(), "et-regio_(Sv.s-1.Bq-1.m2)": z.string(), "lung_(Sv.s-1.Bq-1.m2)": z.string(), "breast_(Sv.s-1.Bq-1.m2)": z.string(), "thymus_(Sv.s-1.Bq-1.m2)": z.string(), "st-wall_(Sv.s-1.Bq-1.m2)": z.string(), "si-wall_(Sv.s-1.Bq-1.m2)": z.string(), "colon_(Sv.s-1.Bq-1.m2)": z.string(), "thyroid_(Sv.s-1.Bq-1.m2)": z.string(), "ht-wall_(Sv.s-1.Bq-1.m2)": z.string(), "liver_(Sv.s-1.Bq-1.m2)": z.string(), "spleen_(Sv.s-1.Bq-1.m2)": z.string(), "kidneys_(Sv.s-1.Bq-1.m2)": z.string(), "adrenals_(Sv.s-1.Bq-1.m2)": z.string(), "pancreas_(Sv.s-1.Bq-1.m2)": z.string(), "gb-wall_(Sv.s-1.Bq-1.m2)": z.string(), "b-surfac_(Sv.s-1.Bq-1.m2)": z.string(), "r-marrow_(Sv.s-1.Bq-1.m2)": z.string(), "muscle_(Sv.s-1.Bq-1.m2)": z.string(), "lymph_(Sv.s-1.Bq-1.m2)": z.string(), "testes_(Sv.s-1.Bq-1.m2)": z.string(), "ovaries_(Sv.s-1.Bq-1.m2)": z.string(), "prostate_(Sv.s-1.Bq-1.m2)": z.string(), "uterus_(Sv.s-1.Bq-1.m2)": z.string(), "ub-wall_(Sv.s-1.Bq-1.m2)": z.string(), "skin_(Sv.s-1.Bq-1.m2)": z.string(), "e_(Sv.s-1.Bq-1.m2)": z.string(), id_fg15_grd_surface: z.number().int()}); export const getApiFg15GrdSurfaceResponse = z.array(fg15GrdSurface); 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 15 - Surface du sol / Dose coefficients from Federal Guidance 15 - Ground surface * * GET /fg15_grd_surface */ export const getApiFg15GrdSurface = async (options: GetApiFg15GrdSurfaceOptions) => { 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(/\/+$/, '')}/fg15_grd_surface${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(getApiFg15GrdSurfaceResponse, await res.json()) };