import {z} from 'zod' export type GetApiAgencyGroupAgencyGroupIdLookupArgs = {Authorization: unknown, Context: unknown, Accept: 'application/json', 'X-Accept-Timezone'?: string | undefined, 'X-Request-Id'?: string | undefined, agency_group_id: string, page?: number | undefined, items_per_page?: number | undefined, sortBy?: (Array<'lookup_type' | '-lookup_type'>) | undefined, lookup_type?: Array | undefined, category?: Array | undefined}; export type GetApiAgencyGroupAgencyGroupIdLookupOptions = {baseUrl?: string | undefined, staffshift?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const getApiAgencyGroupAgencyGroupIdLookupResponse = z.array(z.object({name: z.string(), parent: z.string().optional(), metadata: z.object({}).optional(), related: z.object({entity_type: z.string(), entity_id: z.string()}).optional(), _id: z.string(), updated_at: z.string(), created_at: z.string(), __v: z.number().int(), lookup_type: z.string(), category: z.array(z.string().min(1)).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 }; /** * Get lookup list for agency group * * GET /agency-group/{agency_group_id}/lookup */ export const getApiAgencyGroupAgencyGroupIdLookup = async (args: GetApiAgencyGroupAgencyGroupIdLookupArgs, options?: GetApiAgencyGroupAgencyGroupIdLookupOptions) => { 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 (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args.Context != null) headers.set("Context", String(args.Context)) if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (args['X-Accept-Timezone'] != null) headers.set("X-Accept-Timezone", String(args['X-Accept-Timezone'])) if (args['X-Request-Id'] != null) headers.set("X-Request-Id", String(args['X-Request-Id'])) 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.lookup_type ?? []) query.append("lookup_type", String(item)) for (const item of args.category ?? []) query.append("category", String(item)) if (staffshift !== undefined) headers.set('authorization', `Basic ${btoa(`${staffshift.username}:${staffshift.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/agency-group/${encodeURIComponent(String(args.agency_group_id))}/lookup${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(getApiAgencyGroupAgencyGroupIdLookupResponse, await res.json()) };