import {z} from 'zod' export type GetApiEmployeesFinancialsArgs = {Authorization: string, accountHolderName?: string | undefined, bankName?: string | undefined, accountNumber?: string | undefined, iban?: string | undefined, swiftCode?: string | undefined, nationalId?: string | undefined, passport?: string | undefined, nationalInsuranceNumber?: string | undefined, taxCode?: string | undefined, taxIdentificationNumber?: string | undefined}; export type GetApiEmployeesFinancialsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiEmployeesFinancialsResponse = z.object({data: z.array(z.object({_id: z.string().optional(), accountHolderName: z.string().optional(), bankName: z.string().optional(), accountNumber: z.string().optional(), iban: z.string().optional(), swiftCode: z.string().optional(), nationalId: z.string().optional(), passport: z.string().optional(), nationalInsuranceNumber: z.string().optional(), taxCode: z.string().optional(), taxIdentificationNumber: z.string().optional()})).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 }; /** * Return a list of employee financials. * * GET /employees/financials */ export const getApiEmployeesFinancials = async (args: GetApiEmployeesFinancialsArgs, options?: GetApiEmployeesFinancialsOptions) => { const {baseUrl = "https://sandbox-api.kenjo.io/api/v1", fetch: fetchFn = fetch} = 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.accountHolderName != null) query.append("accountHolderName", String(args.accountHolderName)) if (args.bankName != null) query.append("bankName", String(args.bankName)) if (args.accountNumber != null) query.append("accountNumber", String(args.accountNumber)) if (args.iban != null) query.append("iban", String(args.iban)) if (args.swiftCode != null) query.append("swiftCode", String(args.swiftCode)) if (args.nationalId != null) query.append("nationalId", String(args.nationalId)) if (args.passport != null) query.append("passport", String(args.passport)) if (args.nationalInsuranceNumber != null) query.append("nationalInsuranceNumber", String(args.nationalInsuranceNumber)) if (args.taxCode != null) query.append("taxCode", String(args.taxCode)) if (args.taxIdentificationNumber != null) query.append("taxIdentificationNumber", String(args.taxIdentificationNumber)) const url = `${baseUrl.replace(/\/+$/, '')}/employees/financials${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(getApiEmployeesFinancialsResponse, await res.json()) };