import {z} from 'zod' export type SearchQuery = {search_terms?: (Array<{search_type: 'name' | 'offer' | 'affiliate', value: string}>) | undefined, filters?: ({status?: ('active' | 'inactive') | undefined, pixel_type?: ('conversion' | 'cpc' | 'event') | undefined, network_offer_ids?: Array | undefined, network_affiliate_ids?: Array | undefined, delivery_methods?: (Array<'postback' | 'html' | 'facebook' | 'tiktok' | 'snapchat' | 'rumble'>) | undefined}) | undefined}; export type CreateApiNetworksPixelstableArgs = {page?: number | undefined, page_size?: number | undefined, body: {query?: SearchQuery | undefined}}; export type CreateApiNetworksPixelstableOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const partnerPostbackTable = 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.enum(["postback", "html", "facebook", "tiktok", "snapchat", "rumble"]).optional(), pixel_level: z.enum(["global", "specific", "global_offer"]).optional(), pixel_status: z.enum(["active", "inactive"]).optional(), pixel_type: z.enum(["conversion", "cpc", "event"]).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(), description: z.string().optional(), delay_ms: z.number().int().optional(), time_created: z.number().int().optional(), time_saved: z.number().int().optional(), relationship: z.object({}).optional()}); export const paging = z.object({page: z.number().int().optional(), page_size: z.number().int().optional(), total_count: z.number().int().optional()}); export const createApiNetworksPixelstableResponse = z.object({pixels: z.array(partnerPostbackTable).optional(), paging: paging.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 Partner Postbacks (Advanced) * * POST /networks/pixelstable */ export const createApiNetworksPixelstable = async (args: CreateApiNetworksPixelstableArgs, options?: CreateApiNetworksPixelstableOptions) => { 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/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(createApiNetworksPixelstableResponse, await res.json()) };