import {z} from 'zod' export type GetApiV1CustomersCustomerIdRecipientsListArgs = {customer_id: string, search?: string | undefined, page?: number | undefined, size?: number | undefined}; export type GetApiV1CustomersCustomerIdRecipientsListOptions = {baseUrl?: string | undefined, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const cpid = z.string(); export const pid = z.string(); export const addressDetails = z.object({full_address: z.string(), country_code: z.string(), address_line1: z.string(), address_line2: z.string().nullable().optional(), city: z.string(), region: z.string().nullable().optional(), postal_code: z.string()}); export const rfiCaseId = z.string(); export const actionRequired = z.object({type: z.string(), case_id: rfiCaseId, action: z.string()}); export const recipientResponse = z.object({recipient_id: cpid, customer_id: pid, business_type: z.string(), full_name: z.string(), nickname: z.string().nullable().optional(), email: z.string().nullable().optional(), relationship: z.string().nullable().optional(), status: z.string(), address: addressDetails.nullable().optional(), action_required: actionRequired.nullable().optional(), created_at: z.string(), modified_at: z.string()}); export const recipientListResponse = z.object({list: z.array(recipientResponse), total: z.number().int().gte(0).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 }; /** * GET /v1/customers/{customer_id}/recipients/list */ export const getApiV1CustomersCustomerIdRecipientsList = async (args: GetApiV1CustomersCustomerIdRecipientsListArgs, options?: GetApiV1CustomersCustomerIdRecipientsListOptions) => { const {baseUrl = "https://api.1money.com", fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.search != null) query.append("search", String(args.search)) if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) if (Authorization !== undefined) headers.set('authorization', `Bearer ${Authorization}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/customers/${encodeURIComponent(String(args.customer_id))}/recipients/list${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(recipientListResponse, await res.json()) };