import {z} from 'zod' export type GetApiBankdetailsIdArgs = {id: string}; export type GetApiBankdetailsIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const bankAddress = z.object({Address1: z.string().max(50).nullable().optional(), Address2: z.string().max(50).nullable().optional(), Address3: z.string().max(50).nullable().optional(), Address4: z.string().max(50).nullable().optional(), PostCode: z.string().max(50).nullable().optional()}); export const bankDetailsModel = z.object({EmployeeId: z.string().min(1).max(36), BankName: z.string().max(50).nullable().optional(), BankAddress: bankAddress.optional(), AccountName: z.string().max(50).nullable().optional(), AccountNumber: z.string().max(50).nullable().optional(), SortCode: z.string().max(50).nullable().optional(), RollNumber: z.string().max(50).nullable().optional(), SourceSystemId: z.string().max(36).nullable().optional(), SourceSystemCreatedOn: z.string().nullable().optional(), SourceSystemLastModifiedOn: z.string().nullable().optional(), Id: z.string().max(36).nullable().optional(), CreatedOn: z.string().optional(), CreatedBy: z.string().max(36).nullable().optional(), LastModifiedOn: z.string().nullable().optional(), LastModifiedBy: z.string().max(36).nullable().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 }; /** * Gets a single Bank Details by an ID. * * GET /bankdetails/{id} */ export const getApiBankdetailsId = async (args: GetApiBankdetailsIdArgs, options?: GetApiBankdetailsIdOptions) => { const {baseUrl = "https://api.iris.co.uk/hr/v2", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/bankdetails/${encodeURIComponent(String(args.id))}${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(bankDetailsModel, await res.json()) };