import {z} from 'zod' export type UpdateCustomerRequest = {address?: ({line1?: string | undefined, line2?: string | undefined, city?: string | undefined, country?: string | undefined, state?: string | undefined, postalCode?: (string | string) | undefined}) | undefined, email?: string | undefined, phoneNumber?: string | undefined, firstName?: string | undefined, middleName?: string | undefined, lastName?: string | undefined, dateOfBirth?: string | undefined, supportedPaymentMethods?: (Array<'FIAT' | 'CRYPTO'>) | undefined, merchantTrustSignal?: ({playerId: string, hoursPlayed?: (number | null) | undefined, playerLevel?: (number | null) | undefined, trustStatus?: ('GOOD' | 'BAD' | 'null' | null) | undefined}) | undefined}; export type CreateApiV1CustomersIdArgs = {id: string, body: UpdateCustomerRequest}; export type CreateApiV1CustomersIdOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const updateCustomerResponse = z.object({id: z.string(), referenceId: z.string(), email: z.string().optional(), merchantId: z.string(), livemode: z.boolean(), signupAt: z.number(), supportedPaymentMethods: z.array(z.enum(["FIAT", "CRYPTO"])).optional(), supportedPayoutMethods: z.array(z.enum(["FIAT", "CRYPTO"])).optional(), firstName: z.string().optional(), middleName: z.string().optional(), lastName: z.string().optional(), dateOfBirth: z.string().optional(), phoneNumber: z.string().optional(), address: z.object({line1: z.string().optional(), line2: z.string().optional(), city: z.string().optional(), state: z.string().optional(), postalCode: z.string().optional(), country: z.string().optional()}).optional(), merchantTrustSignal: z.object({playerId: z.string(), trustStatus: z.enum(["GOOD", "BAD"]).optional(), hoursPlayed: z.number().optional(), playerLevel: z.number().optional()}).optional()}); export const createApiV1CustomersIdResponse = z.object({status: z.literal("SUCCEEDED"), data: updateCustomerResponse}); 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 }; /** * Update a customer * * POST /v1/customers/{id} */ export const createApiV1CustomersId = async (args: CreateApiV1CustomersIdArgs, options?: CreateApiV1CustomersIdOptions) => { const {baseUrl = "https://api.breeze.cash", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/customers/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiV1CustomersIdResponse, await res.json()) };