import {z} from 'zod' export type GetApiA2023Tab11IngestionPublicOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const a2023Tab11IngestionPublic = z.object({id_a2023_tab11_ingestion_public: z.number().int(), radionucleide: z.string(), forme_chimique: z.string(), extension_chimique: z.string().nullable().optional(), par_def: z.number().int(), "h(g)<1an_(Sv.Bq-1)": z.string(), "h(g)1-2ans_(Sv.Bq-1)": z.string(), "h(g)2-7ans_(Sv.Bq-1)": z.string(), "h(g)7-12ans_(Sv.Bq-1)": z.string(), "h(g)12-17ans_(Sv.Bq-1)": z.string(), "h(g)>17ans_(Sv.Bq-1)": z.string()}); export const getApiA2023Tab11IngestionPublicResponse = z.array(a2023Tab11IngestionPublic); 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 }; /** * Décret 2023, table 1.1 / Decree 2023, table 1.1 * * GET /a2023_tab11_ingestion_public */ export const getApiA2023Tab11IngestionPublic = async (options: GetApiA2023Tab11IngestionPublicOptions) => { 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(/\/+$/, '')}/a2023_tab11_ingestion_public${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(getApiA2023Tab11IngestionPublicResponse, await res.json()) };