import {z} from 'zod' export type PartnerPostbackInput = {network_offer_id?: number | undefined, network_affiliate_id?: number | undefined, delivery_method: 'postback' | 'html' | 'facebook' | 'tiktok' | 'snapchat' | 'rumble', pixel_level: 'global' | 'specific' | 'global_offer', pixel_status: 'active' | 'inactive', pixel_type: 'conversion' | 'cpc' | 'event', postback_url?: string | undefined, html_code?: string | undefined, description?: string | undefined, delay_ms?: number | undefined, network_offer_payout_revenue_id?: number | undefined, facebook_pixel?: ({network_affiliate_integration_facebook_business_id?: number | undefined, pixel_id?: string | undefined, event_name?: string | undefined, event_id?: string | undefined, action_source?: string | undefined, event_source_url?: string | undefined, user_data?: (Array<{field?: ('email' | 'phone' | 'gender' | 'date_of_birth' | 'last_name' | 'first_name' | 'city' | 'state' | 'zipcode' | 'country_code' | 'external_id' | 'fbc' | 'fbp' | 'subscription_id' | 'fb_login_id') | undefined, value?: string | undefined}>) | undefined, custom_data?: (Array<{field?: ('value' | 'currency' | 'order_id' | 'predicted_ltv' | 'num_items' | 'status' | 'search_string') | undefined, value?: string | undefined}>) | undefined}) | undefined, tiktok_pixel?: ({network_affiliate_integration_tiktok_id?: number | undefined, pixel_code?: string | undefined, event_name?: ('view_content' | 'click_button' | 'search' | 'add_to_wishlist' | 'add_to_cart' | 'initiate_checkout' | 'add_payment_info' | 'complete_payment' | 'place_order' | 'contact' | 'download' | 'submit_form' | 'complete_registration' | 'subscribe') | undefined, url?: string | undefined, email?: string | undefined, phone?: string | undefined, properties?: (Array<{field?: ('price' | 'quantity' | 'content_type' | 'content_id' | 'content_category' | 'content_name' | 'currency' | 'value' | 'description' | 'query' | 'status') | undefined, value?: string | undefined}>) | undefined}) | undefined, snapchat_pixel?: ({network_affiliate_integration_snapchat_id?: number | undefined, asset_id?: string | undefined, event_name?: string | undefined, event_id?: string | undefined, action_source?: string | undefined, event_source_url?: string | undefined, user_data?: (Array<{field?: ('email' | 'phone' | 'first_name' | 'last_name' | 'gender' | 'city' | 'state' | 'zipcode' | 'country_code' | 'idfv' | 'sc_cid') | undefined, value?: string | undefined}>) | undefined, custom_data?: (Array<{field?: ('value' | 'currency' | 'order_id' | 'num_items' | 'status' | 'search_string') | undefined, value?: string | undefined}>) | undefined}) | undefined, rumble_pixel?: ({network_affiliate_integration_rumble_id?: number | undefined, conversion_action_id?: number | undefined}) | undefined}; export type UpdateApiNetworksPixelsPixelIdArgs = {pixelId: number, body: PartnerPostbackInput}; export type UpdateApiNetworksPixelsPixelIdOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const partnerPostback = z.object({network_pixel_id: z.number().int().optional(), network_id: z.number().int().optional(), network_affiliate_id: z.number().int().optional(), network_offer_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(), description: z.string().optional(), delay_ms: z.number().int().optional(), time_created: z.number().int().optional(), time_saved: z.number().int().optional(), facebook_pixel: z.object({network_affiliate_integration_facebook_business_id: z.number().int().optional(), pixel_id: z.string().optional(), event_name: z.string().optional(), event_id: z.string().optional(), action_source: z.string().optional(), event_source_url: z.string().optional(), user_data: z.array(z.object({field: z.enum(["email", "phone", "gender", "date_of_birth", "last_name", "first_name", "city", "state", "zipcode", "country_code", "external_id", "fbc", "fbp", "subscription_id", "fb_login_id"]).optional(), value: z.string().optional()})).optional(), custom_data: z.array(z.object({field: z.enum(["value", "currency", "order_id", "predicted_ltv", "num_items", "status", "search_string"]).optional(), value: z.string().optional()})).optional()}).nullable().optional(), tiktok_pixel: z.object({network_affiliate_integration_tiktok_id: z.number().int().optional(), pixel_code: z.string().optional(), event_name: z.string().optional(), url: z.string().optional(), email: z.string().optional(), phone: z.string().optional(), properties: z.array(z.object({field: z.enum(["price", "quantity", "content_type", "content_id", "content_category", "content_name", "currency", "value", "description", "query", "status"]).optional(), value: z.string().optional()})).optional()}).nullable().optional(), snapchat_pixel: z.object({network_affiliate_integration_snapchat_id: z.number().int().optional(), asset_id: z.string().optional(), event_name: z.string().optional(), event_id: z.string().optional(), action_source: z.string().optional(), event_source_url: z.string().optional(), user_data: z.array(z.object({field: z.enum(["email", "phone", "first_name", "last_name", "gender", "city", "state", "zipcode", "country_code", "idfv", "sc_cid"]).optional(), value: z.string().optional()})).optional(), custom_data: z.array(z.object({field: z.enum(["value", "currency", "order_id", "num_items", "status", "search_string"]).optional(), value: z.string().optional()})).optional()}).nullable().optional(), rumble_pixel: z.object({network_affiliate_integration_rumble_id: z.number().int().optional(), conversion_action_id: z.number().int().optional(), conversion_action_name: z.string().optional()}).nullable().optional(), relationship: z.object({offer: z.object({network_offer_id: z.number().int().optional(), network_id: z.number().int().optional(), network_advertiser_id: z.number().int().optional(), network_offer_group_id: z.number().int().optional(), name: z.string().optional(), offer_status: z.string().optional(), network_tracking_domain_id: z.number().int().optional(), visibility: z.string().optional(), currency_id: z.string().optional()}).optional(), affiliate: z.object({network_affiliate_id: z.number().int().optional(), network_id: z.number().int().optional(), name: z.string().optional(), account_status: z.string().optional(), network_employee_id: z.number().int().optional(), internal_notes: z.string().optional(), has_notifications: z.boolean().optional(), network_traffic_source_id: z.number().int().optional(), account_executive_id: z.number().int().optional(), adress_id: z.number().int().optional(), default_currency_id: z.string().optional(), is_contact_address_enabled: z.boolean().optional(), enable_media_cost_tracking_links: z.boolean().optional(), referrer_id: z.number().int().optional(), time_created: z.number().int().optional(), time_saved: z.number().int().optional()}).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 }; /** * Update Partner Postback * * PUT /networks/pixels/{pixelId} */ export const updateApiNetworksPixelsPixelId = async (args: UpdateApiNetworksPixelsPixelIdArgs, options?: UpdateApiNetworksPixelsPixelIdOptions) => { 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 (APIKey !== undefined) headers.set("X-Eflow-Api-Key", APIKey) const url = `${baseUrl.replace(/\/+$/, '')}/networks/pixels/${encodeURIComponent(String(args.pixelId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(partnerPostback, await res.json()) };