import {z} from 'zod' export type GetApiPlatformV2CustomersArgs = {name?: string | undefined, statuses?: (Array<'AGREEMENTS_PENDING' | 'INFO_REQUIRED' | 'PENDING' | 'ACTIONS_REQUIRED' | 'VERIFIED' | 'REJECTED' | 'TERMINATED'>) | undefined, types?: (Array<'COMPANY' | 'INDIVIDUAL'>) | undefined, models?: (Array<'EMBEDDED' | 'RELIANCE'>) | undefined, useCases?: (Array<'FIAT' | 'CRYPTO' | 'STABLECOIN_PAYOUTS' | 'EMBEDDED_STABLECOIN_WALLETS' | 'EMBEDDED_FIAT_ACCOUNTS' | 'CARD_AGREEMENT' | 'STABLECOIN_REWARDS'>) | undefined, reference?: string | undefined, pageNumber?: number | undefined, pageSize?: number | undefined}; export type GetApiPlatformV2CustomersOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const v2AuthenticatedLinkResponse = z.object({link: z.string().optional(), expiresAt: z.string().optional()}); export const v2CustomerSummaryResponse = z.object({id: z.string().optional(), reference: z.string().optional(), status: z.enum(["AGREEMENTS_PENDING", "INFO_REQUIRED", "PENDING", "ACTIONS_REQUIRED", "VERIFIED", "REJECTED", "TERMINATED"]).optional(), type: z.enum(["COMPANY", "INDIVIDUAL"]).optional(), model: z.enum(["EMBEDDED", "RELIANCE"]).optional(), name: z.string().optional(), createdAt: z.string().optional(), authenticatedLink: v2AuthenticatedLinkResponse.optional()}); export const v2Pageable = z.object({pageNumber: z.number().int().gte(0).optional(), pageSize: z.number().int().gte(1).lte(500).optional()}); export const v2PaginatedCustomerSummaryResponse = z.object({totalElements: z.number().int().optional(), totalPages: z.number().int().optional(), content: z.array(v2CustomerSummaryResponse).optional(), pageable: v2Pageable.optional(), hasNext: z.boolean().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 }; /** * Search customers * * GET /platform/v2/customers */ export const getApiPlatformV2Customers = async (args: GetApiPlatformV2CustomersArgs, options?: GetApiPlatformV2CustomersOptions) => { const {baseUrl = "https://api.sandbox.bvnk.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.name != null) query.append("name", String(args.name)) for (const item of args.statuses ?? []) query.append("statuses", String(item)) for (const item of args.types ?? []) query.append("types", String(item)) for (const item of args.models ?? []) query.append("models", String(item)) for (const item of args.useCases ?? []) query.append("useCases", String(item)) if (args.reference != null) query.append("reference", String(args.reference)) if (args.pageNumber != null) query.append("pageNumber", String(args.pageNumber)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/platform/v2/customers${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(v2PaginatedCustomerSummaryResponse, await res.json()) };