import {z} from 'zod' export type GetApiAspspsArgs = {offset?: number | undefined, limit?: number | undefined, filter?: string | undefined, auth_type?: 'redirect' | undefined, bic?: string | undefined, currency?: ('AED' | 'AUD' | 'CAD' | 'CHF' | 'CNY' | 'DKK' | 'EUR' | 'GBP' | 'HKD' | 'JPY' | 'MXN' | 'SEK' | 'USD' | 'ZAR') | undefined, country?: string | undefined, scheme?: string | undefined, 'Company-Id'?: string | undefined}; export type GetApiAspspsOptions = {baseUrl?: string | undefined, token?: string | undefined, fetch?: typeof fetch | undefined}; export const aspsp = z.object({aspsp_id: z.enum(["santander", "bank_of_scotland", "first_direct", "halifax", "hsbc", "lloyds", "monzo", "nationwide", "natwest", "starling_bank", "revolut", "rbs", "tsb"]).optional(), logo_url: z.string().optional(), icon_url: z.string().optional(), display_name: z.string().optional(), auth_type: z.enum(["redirect", "embedded"]).optional(), country: z.literal("gb").optional(), bic_code: z.string().optional(), devisions: z.array(z.string()).optional(), supported_currencies: z.array(z.string()).optional(), supported_services: z.array(z.string()).optional(), supported_formats: z.array(z.string()).optional(), supported_schemes: z.array(z.string()).optional()}); export const aspspsListPaged = z.object({meta: z.object({count: z.number().int().optional(), offset: z.number().int().optional(), limit: z.number().int().optional(), total: z.number().int().optional(), links: z.array(z.object({rel: z.enum(["self", "first", "last", "prev", "next"]).optional(), href: z.string().optional(), title: z.string().optional()})).optional()}).optional(), data: z.array(aspsp).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 a list of support banks * * GET /aspsps */ export const getApiAspsps = async (args: GetApiAspspsArgs, options?: GetApiAspspsOptions) => { const {baseUrl = "https://test-api.acquired.com/v1", fetch: fetchFn = fetch, token} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.filter != null) query.append("filter", String(args.filter)) if (args.auth_type != null) query.append("auth_type", String(args.auth_type)) if (args.bic != null) query.append("bic", String(args.bic)) if (args.currency != null) query.append("currency", String(args.currency)) if (args.country != null) query.append("country", String(args.country)) if (args.scheme != null) query.append("scheme", String(args.scheme)) if (args['Company-Id'] != null) headers.set("Company-Id", String(args['Company-Id'])) if (token !== undefined) headers.set('authorization', `Bearer ${token}`) const url = `${baseUrl.replace(/\/+$/, '')}/aspsps${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(aspspsListPaged, await res.json()) };