import {z} from 'zod' export type GetApiV1CrmMetricsTransactionsArgs = {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 GetApiV1CrmMetricsTransactionsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const categoryEnum = z.union([z.literal(0), z.literal(1)]); export const metricsTransaction = z.object({id: z.number().int(), method: categoryEnum.optional(), amount: z.string().optional(), type: z.number().int().nullable().optional(), created_at: z.string(), comment: z.string().nullable().optional(), created_by: z.number().int().nullable().optional(), sale: z.number().int().nullable().optional(), workshop: z.number().int().nullable().optional(), request: z.number().int().nullable().optional(), client_id: z.number().int(), client_name: z.string(), client_phone: z.string(), client_avatar: z.string(), request_status: z.number().int(), deposit: z.number().int().nullable().optional(), rental_point: z.number().int()}); export const paginatedMetricsTransactionList = z.object({count: z.number().int(), next: z.string().nullable().optional(), previous: z.string().nullable().optional(), results: z.array(metricsTransaction)}); 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/ */ export const getApiV1CrmMetricsTransactions = async (args: GetApiV1CrmMetricsTransactionsArgs, options?: GetApiV1CrmMetricsTransactionsOptions) => { 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/${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(paginatedMetricsTransactionList, await res.json()) };