import {z} from 'zod' export type GetApiFeverzoneSalesByResellerSearchSearchIdArgs = {search_id: string, page?: number | undefined, 'user-id-to-impersonate'?: number | undefined}; export type GetApiFeverzoneSalesByResellerSearchSearchIdOptions = {baseUrl: string, OAuth2PasswordBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const partitionInfo = z.object({partition_num: z.number().int().gte(0), endpoint: z.string(), size: z.number().int().gte(0), rows: z.number().int().gte(0)}); export const resellerGroupByDimension = z.enum(["TICKET_TYPE", "VENUE"]); export const salesByResellerParams = z.object({reseller_ids: z.array(z.string()).optional(), group_by_dimensions: z.array(resellerGroupByDimension).optional()}); export const reseller = z.object({id: z.string(), name: z.string(), email: z.string(), type: z.string(), contact_language: z.string(), accepts_comms: z.string()}); export const salesByReseller = z.object({ticket_type: z.string().optional(), tickets_sold: z.number().int(), gross_revenue: z.number(), reseller: reseller, venue_name: z.string().optional()}); export const searchSalesByResellerSalesByResellerParams = z.object({partition_info: z.array(partitionInfo).optional(), params: salesByResellerParams.optional(), data: z.array(salesByReseller)}); 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 sales by reseller * * GET /feverzone/sales-by-reseller/search/{search_id} */ export const getApiFeverzoneSalesByResellerSearchSearchId = async (args: GetApiFeverzoneSalesByResellerSearchSearchIdArgs, options: GetApiFeverzoneSalesByResellerSearchSearchIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2PasswordBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args['user-id-to-impersonate'] != null) headers.set("user-id-to-impersonate", String(args['user-id-to-impersonate'])) if (OAuth2PasswordBearer !== undefined) headers.set('authorization', `Bearer ${OAuth2PasswordBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/feverzone/sales-by-reseller/search/${encodeURIComponent(String(args.search_id))}${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(searchSalesByResellerSalesByResellerParams, await res.json()) };