import {z} from 'zod' export type GetApiAccountLookupsAccountLookupIdArgs = {account_lookup_id: string}; export type GetApiAccountLookupsAccountLookupIdOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const accountLookup = z.object({account_lookup_id: z.string(), account_lookup_status: z.enum(["REQUESTED", "PROCESSED", "FAILED", "EXPIRED"]), first_name: z.string().max(40).optional(), middle_name: z.string().max(40).optional(), last_name: z.string().max(40).optional(), org_name: z.string().max(140).optional(), country_code: z.string().optional(), account_currency: z.string().optional(), account_id: z.string().max(40).optional(), account_id_type: z.enum(["AIIN", "BBAN", "CARD", "CUID", "UPIC", "EMAIL", "MSISDN", "DMST", "OTHER"]).optional(), result_code: z.string().optional(), result_status: z.enum(["PASS", "FAIL"]).optional(), result_description: z.string().optional(), redacted_first_name: z.string().max(40).optional(), redacted_middle_name: z.string().max(40).optional(), redacted_last_name: z.string().max(40).optional(), redacted_org_name: z.string().max(140).optional(), redacted_country_code: z.string().optional(), redacted_account_id: z.string().max(40).optional(), redacted_account_id_type: z.enum(["AIIN", "BBAN", "CARD", "CUID", "UPIC", "EMAIL", "MSISDN", "DMST", "OTHER"]).optional(), redacted_account_currency: z.string().optional(), clearing_system_code: z.string().optional(), branch_code: z.string().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 account lookup by ID * * GET /account_lookups/{account_lookup_id} */ export const getApiAccountLookupsAccountLookupId = async (args: GetApiAccountLookupsAccountLookupIdArgs, options: GetApiAccountLookupsAccountLookupIdOptions) => { const {baseUrl, 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) const url = `${baseUrl.replace(/\/+$/, '')}/account_lookups/${encodeURIComponent(String(args.account_lookup_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(accountLookup, await res.json()) };