import {z} from 'zod' export type GetApiApiV40IntegrationsCustomersCustomerIdDetailsArgs = {customerId: string}; export type GetApiApiV40IntegrationsCustomersCustomerIdDetailsOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, secretKey?: string | undefined, fetch?: typeof fetch | undefined}; export const customerDetailsResponse = z.object({customerId: z.string().optional(), gameballId: z.number().optional(), customerAttributes: z.object({displayName: z.string().optional(), firstName: z.string().optional(), lastName: z.string().optional(), email: z.string().optional(), gender: z.string().optional(), mobile: z.string().optional(), mobileCountryCode: z.string().optional(), dateOfBirth: z.string().optional(), joinDate: z.string().optional(), country: z.string().optional(), city: z.string().optional(), zip: z.string().optional(), preferredLanguage: z.string().optional(), tags: z.array(z.string()).optional(), source: z.string().optional(), utms: z.array(z.unknown()).optional(), utMs: z.array(z.unknown()).optional(), devices: z.array(z.object({userAgent: z.string().optional(), os: z.string().optional(), device: z.string().optional(), browser: z.string().optional()})).optional(), paymentMethods: z.array(z.string()).optional(), totalSpent: z.number().optional(), lastOrderDate: z.string().optional(), totalOrders: z.number().optional(), avgOrderAmount: z.number().optional(), channel: z.enum(["mobile", "pos", "web", "callcenter"]).optional(), custom: z.record(z.string(), z.unknown()).optional(), manualDate: z.string().optional()}).optional(), referralCode: z.string().optional(), referralLink: z.string().optional(), isReferred: z.boolean().optional(), dynamicReferralLink: z.string().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 Customer Details * * GET /api/v4.0/integrations/customers/{customerId}/details */ export const getApiApiV40IntegrationsCustomersCustomerIdDetails = async (args: GetApiApiV40IntegrationsCustomersCustomerIdDetailsArgs, options?: GetApiApiV40IntegrationsCustomersCustomerIdDetailsOptions) => { const {baseUrl = "https://api.gameball.co", fetch: fetchFn = fetch, apiKey, secretKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("apikey", apiKey) if (secretKey !== undefined) headers.set("secretkey", secretKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v4.0/integrations/customers/${encodeURIComponent(String(args.customerId))}/details${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(customerDetailsResponse, await res.json()) };