import {z} from 'zod' export type GetApiApiAssociationCharityAssociationAssocIdArgs = {assocId: number}; export type GetApiApiAssociationCharityAssociationAssocIdOptions = {baseUrl: string, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const associationCharity = z.object({first_Inserted_By: z.string().optional(), first_Inserted_Datetime: z.string().optional(), last_Changed_By: z.string().optional(), last_Changed_Datetime: z.string().optional(), source_System_Id: z.number().int().optional(), source_Method_Id: z.number().int().optional(), firstName: z.string().optional(), lastName: z.string().optional(), coreEntityStatusCode: z.string().optional(), canEdit: z.string().optional(), sourceSystemDisplayName: z.string().optional(), isInternal: z.boolean().optional(), returnField: z.boolean().optional(), isPubSub: z.boolean().optional(), id: z.number().int().optional(), association_Id: z.number().int().optional(), charity_Name: z.string().optional(), charity_Description: z.string().optional(), charity_Website: z.string().optional(), charity_Logo_Url: z.string().optional()}); export const getApiApiAssociationCharityAssociationAssocIdResponse = z.array(associationCharity); 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 /api/AssociationCharity/Association/{assocId} */ export const getApiApiAssociationCharityAssociationAssocId = async (args: GetApiApiAssociationCharityAssociationAssocIdArgs, options: GetApiApiAssociationCharityAssociationAssocIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/AssociationCharity/Association/${encodeURIComponent(String(args.assocId))}${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(getApiApiAssociationCharityAssociationAssocIdResponse, await res.json()) };