import {z} from 'zod' export type GetApiV1CrmMetricsClientsGraphCountArgs = {attraction?: number | undefined, end_at: string, start_at: string, ticks?: Array | undefined, ticks__in?: Array | undefined, type?: (0 | 1) | undefined}; export type GetApiV1CrmMetricsClientsGraphCountOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const metricsClientCountGraph = z.object({date: z.string(), value: z.number().int()}); export const getApiV1CrmMetricsClientsGraphCountResponse = z.array(metricsClientCountGraph); 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 /v1/crm/metrics/clients/graph/count/ */ export const getApiV1CrmMetricsClientsGraphCount = async (args: GetApiV1CrmMetricsClientsGraphCountArgs, options?: GetApiV1CrmMetricsClientsGraphCountOptions) => { const {baseUrl = "https://api.yume.cloud", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.attraction != null) query.append("attraction", String(args.attraction)) if (args.end_at != null) query.append("end_at", String(args.end_at)) if (args.start_at != null) query.append("start_at", String(args.start_at)) for (const item of args.ticks ?? []) query.append("ticks", String(item)) if (args.ticks__in != null) query.append("ticks__in", args.ticks__in.join(',')) if (args.type != null) query.append("type", String(args.type)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/crm/metrics/clients/graph/count/${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(getApiV1CrmMetricsClientsGraphCountResponse, await res.json()) };