import {z} from 'zod' export type GetApiSitesSiteIdCustomerMetricsArgs = {siteId: number, startDate?: string | undefined, endDate?: string | undefined, page?: number | undefined, pageSize?: number | undefined, customerIds?: string | undefined, excludeEventLogsData?: boolean | undefined}; export type GetApiSitesSiteIdCustomerMetricsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const qPilotCoreModelsDtoResponsesCustomerMetricsDto = z.object({customerId: z.string().nullable().optional(), customerEmail: z.string().nullable().optional(), customerCreatedDateUTC: z.string().optional(), firstScheduledOrderCreatedUTC: z.string().nullable().optional(), totalScheduledOrdersActive: z.number().int().optional(), totalScheduledOrdersActiveValue: z.number().optional(), totalScheduledOrdersPaused: z.number().int().optional(), totalScheduledOrdersPausedValue: z.number().optional(), totalScheduledOrdersFailed: z.number().int().optional(), totalScheduledOrdersFailedValue: z.number().optional(), totalScheduledOrdersDeleted: z.number().int().optional(), totalScheduledOrdersDeletedValue: z.number().optional(), totalScheduledOrdersLifetimeValue: z.number().optional(), averageProcessingCycleValue: z.number().optional(), lastSuccessfulProcessingCycleDate: z.string().nullable().optional(), lastFailedProcessingCycleDate: z.string().nullable().optional(), lastPausedScheduledOrderDate: z.string().nullable().optional(), totalSuccessfulProcessingCycles: z.number().int().optional()}); export const qPilotCoreModelsDtoResponsesSiteCustomerMetricsDto = z.object({totalPages: z.number().int().optional(), data: z.array(qPilotCoreModelsDtoResponsesCustomerMetricsDto).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 Site customers revenue metrics * * GET /Sites/{siteId}/CustomerMetrics */ export const getApiSitesSiteIdCustomerMetrics = async (args: GetApiSitesSiteIdCustomerMetricsArgs, options?: GetApiSitesSiteIdCustomerMetricsOptions) => { const {baseUrl = "https://api.qpilot.cloud", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.startDate != null) query.append("startDate", String(args.startDate)) if (args.endDate != null) query.append("endDate", String(args.endDate)) if (args.page != null) query.append("page", String(args.page)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.customerIds != null) query.append("customerIds", String(args.customerIds)) if (args.excludeEventLogsData != null) query.append("excludeEventLogsData", String(args.excludeEventLogsData)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/Sites/${encodeURIComponent(String(args.siteId))}/CustomerMetrics${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(qPilotCoreModelsDtoResponsesSiteCustomerMetricsDto, await res.json()) };