import {z} from 'zod' export type DeleteApiCandidateCandidateIdRegistrationBodyCandidateRegistrationBodyIdOptions = {baseUrl?: string | undefined, staffshift?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const registrationBodyEntriesRegistrationBodyEntryResponseDef = z.object({_id: z.string(), name: z.string().min(1), short_name: z.string().min(1)}); export const registrationBodyEntriesStatusResponseDef = z.object({_id: z.string(), name: z.string().min(1)}); export const agencyGroupCandidateRegistrationBodyEntryResponseDef = z.object({_id: z.string(), updated_at: z.string(), created_at: z.string(), obtained_at: z.string().optional(), valid_at: z.string().optional(), expires_at: z.string().optional(), registration_body_entry: registrationBodyEntriesRegistrationBodyEntryResponseDef, status: registrationBodyEntriesStatusResponseDef}); export const candidateRegistrationBodyResponseDef = z.object({_id: z.string(), updated_at: z.string(), created_at: z.string(), __v: z.number().int(), candidate_id: z.string(), reference: z.string().min(1), status: z.object({_id: z.string(), name: z.string().min(1), description: z.string().min(1), editable: z.boolean()}), registration_body: z.object({_id: z.string(), name: z.string().min(1), short_name: z.string().min(1), country_code: z.string().min(2).max(2), position_types: z.array(z.string())}), registration_body_entries: z.array(agencyGroupCandidateRegistrationBodyEntryResponseDef).optional()}); 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 }; /** * Removes the specific Candidate Registration body * * DELETE /candidate/{candidate_id}/registration-body/{candidate_registration_body_id} */ export const deleteApiCandidateCandidateIdRegistrationBodyCandidateRegistrationBodyId = async (options?: DeleteApiCandidateCandidateIdRegistrationBodyCandidateRegistrationBodyIdOptions) => { const {baseUrl = "http://localhost:3010/v1", fetch: fetchFn = fetch, staffshift} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (staffshift !== undefined) headers.set('authorization', `Basic ${btoa(`${staffshift.username}:${staffshift.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/candidate/${encodeURIComponent(String(args.candidate_id))}/registration-body/${encodeURIComponent(String(args.candidate_registration_body_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(candidateRegistrationBodyResponseDef, await res.json()) };