import {z} from 'zod' export type GetApiV1CustomersCustomerIdMandatesArgs = {'X-API-Key'?: string | undefined, customerId: string, limit?: number | undefined, offset?: number | undefined, status?: ('ACTIVE' | 'REVOKED') | undefined}; export type GetApiV1CustomersCustomerIdMandatesOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const mandateLimitsResponseDto = z.object({currency: z.string(), perTransaction: z.string(), perDay: z.string().nullable(), perMonth: z.string().nullable()}); export const mandateResponseDto = z.object({id: z.string(), organizationId: z.string(), customerId: z.string(), name: z.string(), description: z.string().nullable(), status: z.enum(["ACTIVE", "REVOKED"]), limits: mandateLimitsResponseDto, allowedPayeeAccountIds: z.array(z.string()).nullable(), allowedRails: z.array(z.string()).nullable(), allowedDrafterPrincipalIds: z.array(z.string()).nullable(), validFrom: z.string(), validUntil: z.string().nullable(), metadata: z.record(z.string(), z.unknown()), createdBy: z.string().nullable(), createdAt: z.string(), updatedAt: z.string()}); export const getApiV1CustomersCustomerIdMandatesResponse = z.object({data: z.array(mandateResponseDto).optional(), total: z.number().optional(), limit: z.number().optional(), offset: z.number().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 mandates for a customer * * GET /v1/customers/{customerId}/mandates */ export const getApiV1CustomersCustomerIdMandates = async (args: GetApiV1CustomersCustomerIdMandatesArgs, options?: GetApiV1CustomersCustomerIdMandatesOptions) => { const {baseUrl = "https://sandbox.api.infinite.dev", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-API-Key'] != null) headers.set("X-API-Key", String(args['X-API-Key'])) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.status != null) query.append("status", String(args.status)) if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/customers/${encodeURIComponent(String(args.customerId))}/mandates${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(getApiV1CustomersCustomerIdMandatesResponse, await res.json()) };