import {z} from 'zod' export type GetApiAgencyAgencyIdCandidateCandidateIdActivityArgs = {page?: number | undefined, items_per_page?: number | undefined, sortBy?: (Array<'activity_type' | 'created_by_user' | 'created_by_user_name' | 'activity_date' | '-activity_type' | '-created_by_user' | '-created_by_user_name' | '-activity_date'>) | undefined, activity_type?: Array | undefined, activity_date_at_from?: string | undefined, activity_date_at_to?: string | undefined, created_by_user?: string | undefined, created_by_user_name?: string | undefined}; export type GetApiAgencyAgencyIdCandidateCandidateIdActivityOptions = {baseUrl?: string | undefined, staffshift?: {username: string, password: string} | undefined, agencyCandidate?: {username: string, password: string} | undefined, pathContextValidator?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const entityObject = z.object({entity_id: z.string().optional(), entity_type: z.string(), name: z.string().optional()}); export const candidateActivityResponseDef = z.object({activity_type: z.string(), description: z.string().min(3).optional(), subject_candidate_name: z.string().min(3).optional(), created_by_user: z.string().optional(), created_by_user_name: z.string().min(3).optional(), comment: z.string().optional(), _id: z.string(), updated_at: z.string(), created_at: z.string(), __v: z.number().int(), activity_date: z.string(), linked_entities: z.array(entityObject).optional()}); export const getApiAgencyAgencyIdCandidateCandidateIdActivityResponse = z.array(candidateActivityResponseDef); 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 }; /** * List Agency Candidate Activity * * GET /agency/{agency_id}/candidate/{candidate_id}/activity */ export const getApiAgencyAgencyIdCandidateCandidateIdActivity = async (args: GetApiAgencyAgencyIdCandidateCandidateIdActivityArgs, options?: GetApiAgencyAgencyIdCandidateCandidateIdActivityOptions) => { const {baseUrl = "http://localhost:3010/v1", fetch: fetchFn = fetch, staffshift, agencyCandidate, pathContextValidator} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.items_per_page != null) query.append("items_per_page", String(args.items_per_page)) for (const item of args.sortBy ?? []) query.append("sortBy", String(item)) for (const item of args.activity_type ?? []) query.append("activity_type", String(item)) if (args.activity_date_at_from != null) query.append("activity_date_at_from", String(args.activity_date_at_from)) if (args.activity_date_at_to != null) query.append("activity_date_at_to", String(args.activity_date_at_to)) if (args.created_by_user != null) query.append("created_by_user", String(args.created_by_user)) if (args.created_by_user_name != null) query.append("created_by_user_name", String(args.created_by_user_name)) if (staffshift !== undefined) headers.set('authorization', `Basic ${btoa(`${staffshift.username}:${staffshift.password}`)}`) if (agencyCandidate !== undefined) headers.set('authorization', `Basic ${btoa(`${agencyCandidate.username}:${agencyCandidate.password}`)}`) if (pathContextValidator !== undefined) headers.set('authorization', `Basic ${btoa(`${pathContextValidator.username}:${pathContextValidator.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/agency/${encodeURIComponent(String(args.agency_id))}/candidate/${encodeURIComponent(String(args.candidate_id))}/activity${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(getApiAgencyAgencyIdCandidateCandidateIdActivityResponse, await res.json()) };