import {z} from 'zod' export type GetApiAgencyGroupGroupIdCandidateCandidateIdPolicyArgs = {action?: ('acknowledged' | 'not_acknowledged') | undefined, version_from?: number | undefined, version?: number | undefined, version_to?: number | undefined, latest_only?: boolean | undefined, policy_type_id?: string | undefined, policy_effective_at_from?: string | undefined, policy_effective_at?: string | undefined, policy_effective_at_to?: string | undefined, sortBy?: (Array<'_id' | '-_id' | 'updated_at' | '-updated_at' | 'created_at' | '-created_at' | 'policy_type_title' | '-policy_type_title' | 'resource_id' | '-resource_id' | 'policy_type_id' | '-policy_type_id'>) | undefined, policy_type_classification?: ('viewable' | 'acknowledgeable') | undefined, page?: number | undefined, items_per_page?: number | undefined}; export type GetApiAgencyGroupGroupIdCandidateCandidateIdPolicyOptions = {baseUrl?: string | undefined, staffshift?: {username: string, password: string} | undefined, agencyGroupCandidate?: {username: string, password: string} | undefined, pathContextValidator?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const embeddedPolicy = z.object({version: z.number().int().gte(1).optional(), effective_at: z.string().optional()}); export const candidateOrUserPolicyReturn = z.object({_id: z.string(), updated_at: z.string(), created_at: z.string(), __v: z.number().int(), latest_policy: embeddedPolicy.optional(), acknowledged_policy: embeddedPolicy.optional(), resource_type: z.string(), resource_id: z.string(), policy_type_id: z.string(), policy_type_title: z.string(), policy_type_description: z.string(), policy_type_classification: z.enum(["viewable", "acknowledgeable"]).optional()}); export const getApiAgencyGroupGroupIdCandidateCandidateIdPolicyResponse = z.array(candidateOrUserPolicyReturn); 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 }; /** * Agency group policy listing for a particular candidate * * GET /agency-group/{group_id}/candidate/{candidate_id}/policy */ export const getApiAgencyGroupGroupIdCandidateCandidateIdPolicy = async (args: GetApiAgencyGroupGroupIdCandidateCandidateIdPolicyArgs, options?: GetApiAgencyGroupGroupIdCandidateCandidateIdPolicyOptions) => { const {baseUrl = "http://localhost:3010/v1", fetch: fetchFn = fetch, staffshift, agencyGroupCandidate, pathContextValidator} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.action != null) query.append("action", String(args.action)) if (args.version_from != null) query.append("version_from", String(args.version_from)) if (args.version != null) query.append("version", String(args.version)) if (args.version_to != null) query.append("version_to", String(args.version_to)) if (args.latest_only != null) query.append("latest_only", String(args.latest_only)) if (args.policy_type_id != null) query.append("policy_type_id", String(args.policy_type_id)) if (args.policy_effective_at_from != null) query.append("policy_effective_at_from", String(args.policy_effective_at_from)) if (args.policy_effective_at != null) query.append("policy_effective_at", String(args.policy_effective_at)) if (args.policy_effective_at_to != null) query.append("policy_effective_at_to", String(args.policy_effective_at_to)) for (const item of args.sortBy ?? []) query.append("sortBy", String(item)) if (args.policy_type_classification != null) query.append("policy_type_classification", String(args.policy_type_classification)) 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)) if (staffshift !== undefined) headers.set('authorization', `Basic ${btoa(`${staffshift.username}:${staffshift.password}`)}`) if (agencyGroupCandidate !== undefined) headers.set('authorization', `Basic ${btoa(`${agencyGroupCandidate.username}:${agencyGroupCandidate.password}`)}`) if (pathContextValidator !== undefined) headers.set('authorization', `Basic ${btoa(`${pathContextValidator.username}:${pathContextValidator.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/agency-group/${encodeURIComponent(String(args.group_id))}/candidate/${encodeURIComponent(String(args.candidate_id))}/policy${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(getApiAgencyGroupGroupIdCandidateCandidateIdPolicyResponse, await res.json()) };