import {z} from 'zod' export type CreateApiNetworksReportingOnholdArgs = {page?: number | undefined, page_size?: number | undefined, body: {from: string, to: string, timezone_id: number, show_conversions: boolean, show_events: boolean, query?: ({filters?: (Array<{resource_type?: ('offer' | 'offer_group' | 'affiliate' | 'advertiser' | 'offer_creative' | 'transaction_id' | 'campaign' | 'billing_frequency' | 'business_unit' | 'label' | 'category' | 'sub1' | 'sub2' | 'sub3' | 'sub4' | 'sub5' | 'sub6' | 'sub7' | 'sub8' | 'sub9' | 'sub10' | 'source_id' | 'country' | 'account_manager' | 'affiliate_manager' | 'status' | 'offer_url' | 'currency_id' | 'affiliate_tier' | 'adv1' | 'adv2' | 'adv3' | 'adv4' | 'adv5' | 'adv6' | 'adv7' | 'adv8' | 'adv9' | 'adv10' | 'browser' | 'carrier' | 'city' | 'coupon_code' | 'dma' | 'date' | 'hourly' | 'device_brand' | 'device_type' | 'hour' | 'isp' | 'language' | 'month' | 'os_version' | 'payout_amount' | 'payout_type' | 'platform' | 'project_id' | 'referrer' | 'region' | 'revenue_amount' | 'revenue_type' | 'week' | 'conversion_id' | 'order_id' | 'tracking_domain' | 'offer_payout_revenue_id' | 'country_code' | 'advertiser_billing_frequency' | 'error_code') | undefined, filter_id_value?: string | undefined}>) | undefined, search_terms?: (Array<{search_type?: ('transaction_id' | 'sub_1' | 'sub_2' | 'sub_3' | 'sub_4' | 'sub_5' | 'adv_1' | 'adv_2' | 'adv_3' | 'adv_4' | 'adv_5' | 'source_id' | 'user_ip' | 'user_agent' | 'order_id' | 'country' | 'region' | 'city' | 'status' | 'is_scrub' | 'email' | 'coupon_code' | 'event_name') | undefined, value?: string | undefined}>) | undefined}) | undefined}}; export type CreateApiNetworksReportingOnholdOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiNetworksReportingOnholdResponse = z.object({conversions: z.array(z.object({})).optional(), paging: z.object({page: z.number().int().optional(), page_size: z.number().int().optional(), total_count: z.number().int().optional()}).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 }; /** * Search On-Hold Conversions * * POST /networks/reporting/onhold */ export const createApiNetworksReportingOnhold = async (args: CreateApiNetworksReportingOnholdArgs, options?: CreateApiNetworksReportingOnholdOptions) => { const {baseUrl = "https://api.eflow.team/v1", fetch: fetchFn = fetch, APIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (APIKey !== undefined) headers.set("X-Eflow-Api-Key", APIKey) const url = `${baseUrl.replace(/\/+$/, '')}/networks/reporting/onhold${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiNetworksReportingOnholdResponse, await res.json()) };