import {z} from 'zod' export type GetApiV1CrmMetricsTransactionsGeneralArgs = {client?: number | undefined, content_type?: ('request' | 'sale' | 'workshop') | undefined, created_at__date__gte?: string | undefined, created_at__date__lte?: string | undefined, created_by?: number | undefined, created_by__in?: Array | undefined, method?: (0 | 1) | undefined, method__in?: Array | undefined, ordering?: string | undefined, page?: number | undefined, pageSize?: number | undefined, refund?: boolean | undefined, rental_point?: number | undefined, request__isnull?: boolean | undefined, request__status?: (0 | 1 | 2 | 3 | 4 | 5) | undefined, request__status__in?: Array | undefined, sale__isnull?: boolean | undefined, search?: string | undefined, type?: number | undefined, type__in?: Array | undefined, workshop__isnull?: boolean | undefined}; export type GetApiV1CrmMetricsTransactionsGeneralOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const metricsTransactionGeneral = z.object({date: z.string(), request: z.string(), shop: z.string(), workshop: z.string(), amount: z.string()}); export const paginatedMetricsTransactionGeneralList = z.object({count: z.number().int(), next: z.string().nullable().optional(), previous: z.string().nullable().optional(), results: z.array(metricsTransactionGeneral)}); 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/transactions/general/ */ export const getApiV1CrmMetricsTransactionsGeneral = async (args: GetApiV1CrmMetricsTransactionsGeneralArgs, options?: GetApiV1CrmMetricsTransactionsGeneralOptions) => { 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.client != null) query.append("client", String(args.client)) if (args.content_type != null) query.append("content_type", String(args.content_type)) if (args.created_at__date__gte != null) query.append("created_at__date__gte", String(args.created_at__date__gte)) if (args.created_at__date__lte != null) query.append("created_at__date__lte", String(args.created_at__date__lte)) if (args.created_by != null) query.append("created_by", String(args.created_by)) if (args.created_by__in != null) query.append("created_by__in", args.created_by__in.join(',')) if (args.method != null) query.append("method", String(args.method)) if (args.method__in != null) query.append("method__in", args.method__in.join(',')) if (args.ordering != null) query.append("ordering", String(args.ordering)) if (args.page != null) query.append("page", String(args.page)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.refund != null) query.append("refund", String(args.refund)) if (args.rental_point != null) query.append("rental_point", String(args.rental_point)) if (args.request__isnull != null) query.append("request__isnull", String(args.request__isnull)) if (args.request__status != null) query.append("request__status", String(args.request__status)) if (args.request__status__in != null) query.append("request__status__in", args.request__status__in.join(',')) if (args.sale__isnull != null) query.append("sale__isnull", String(args.sale__isnull)) if (args.search != null) query.append("search", String(args.search)) if (args.type != null) query.append("type", String(args.type)) if (args.type__in != null) query.append("type__in", args.type__in.join(',')) if (args.workshop__isnull != null) query.append("workshop__isnull", String(args.workshop__isnull)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/crm/metrics/transactions/general/${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(paginatedMetricsTransactionGeneralList, await res.json()) };