import {z} from 'zod' export type CreateApiAffiliatesPixelstableArgs = {page?: number | undefined, page_size?: number | undefined, body: {search_terms?: Array | undefined, filters?: ({pixel_status?: ('active' | 'inactive') | undefined, pixel_type?: ('conversion' | 'post_conversion' | 'cpc') | undefined, delivery_method?: ('html' | 'postback' | 'facebook') | undefined, network_offer_id?: number | undefined}) | undefined}}; export type CreateApiAffiliatesPixelstableOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiAffiliatesPixelstableResponse = z.object({pixels: z.array(z.object({network_pixel_id: z.number().int().optional(), network_id: z.number().int().optional(), network_offer_payout_revenue_id: z.number().int().optional(), delivery_method: z.string().optional(), pixel_level: z.string().optional(), pixel_status: z.string().optional(), pixel_type: z.string().optional(), postback_url: z.string().optional(), html_code: z.string().optional(), network_affiliate_id: z.number().int().optional(), network_affiliate_name: z.string().optional(), network_offer_id: z.number().int().optional(), network_offer_name: z.string().optional(), delay_ms: z.number().int().optional(), time_created: z.number().int().optional(), time_saved: z.number().int().optional(), relationship: z.object({affiliate: z.object({}).optional(), offer: z.object({}).optional(), payout_revenue: z.object({}).optional()}).optional()})).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 }; /** * Find Postbacks (Advanced) * * POST /affiliates/pixelstable */ export const createApiAffiliatesPixelstable = async (args: CreateApiAffiliatesPixelstableArgs, options?: CreateApiAffiliatesPixelstableOptions) => { 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(/\/+$/, '')}/affiliates/pixelstable${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(createApiAffiliatesPixelstableResponse, await res.json()) };