import {z} from 'zod' export type GetApiAccountUpdaterArgs = {offset?: number | undefined, limit?: number | undefined, card_id?: string | undefined, customer_id?: string | undefined, company_id?: string | undefined, merchant_id?: number | undefined, status?: string | undefined, created_from?: string | undefined, created_to?: string | undefined, completed_from?: string | undefined, completed_to?: string | undefined, 'Company-Id'?: string | undefined, Mid?: string | undefined}; export type GetApiAccountUpdaterOptions = {baseUrl?: string | undefined, token?: string | undefined, fetch?: typeof fetch | undefined}; export const accountUpdaterRequest = z.object({id: z.string().optional(), card_id: z.string().optional(), customer_id: z.string().optional(), mid_id: z.string().optional(), initiated_by: z.enum(["manual", "decline", "retry_advice", "card_expiry"]).nullable().optional(), status: z.enum(["pending", "submitted", "completed", "failed"]).optional(), outcome: z.enum(["card_updated", "card_expiry_updated", "no_change", "account_closed", "card_not_found", "provider_error", "unknown"]).nullable().optional(), outcome_detail: z.object({previous_bin: z.string().optional(), previous_last4: z.string().optional(), previous_expiry_month: z.number().int().gte(1).lte(12).optional(), previous_expiry_year: z.number().int().gte(26).lte(56).optional(), new_bin: z.string().nullable().optional(), new_last4: z.string().nullable().optional(), new_expiry_month: z.number().int().gte(1).lte(12).nullable().optional(), new_expiry_year: z.number().int().gte(26).lte(56).nullable().optional()}).nullable().optional(), created_datetime: z.string().optional(), submitted_datetime: z.string().nullable().optional(), completed_datetime: z.string().nullable().optional()}); export const accountUpdaterRequestListPaged = 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(accountUpdaterRequest).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 }; /** * List Account Updater requests * * GET /account-updater */ export const getApiAccountUpdater = async (args: GetApiAccountUpdaterArgs, options?: GetApiAccountUpdaterOptions) => { 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.card_id != null) query.append("card_id", String(args.card_id)) if (args.customer_id != null) query.append("customer_id", String(args.customer_id)) if (args.company_id != null) query.append("company_id", String(args.company_id)) if (args.merchant_id != null) query.append("merchant_id", String(args.merchant_id)) if (args.status != null) query.append("status", String(args.status)) if (args.created_from != null) query.append("created_from", String(args.created_from)) if (args.created_to != null) query.append("created_to", String(args.created_to)) if (args.completed_from != null) query.append("completed_from", String(args.completed_from)) if (args.completed_to != null) query.append("completed_to", String(args.completed_to)) if (args['Company-Id'] != null) headers.set("Company-Id", String(args['Company-Id'])) if (args.Mid != null) headers.set("Mid", String(args.Mid)) if (token !== undefined) headers.set('authorization', `Bearer ${token}`) const url = `${baseUrl.replace(/\/+$/, '')}/account-updater${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(accountUpdaterRequestListPaged, await res.json()) };