import {z} from 'zod' export type CustomPayoutRevenueInput = {network_offer_payout_revenue_id: number, network_offer_id: number, name: string, custom_setting_status: 'active' | 'inactive', is_apply_all_affiliates: boolean, network_affiliate_ids?: Array | undefined, is_custom_payout_enabled?: boolean | undefined, payout_type: 'blank' | 'cpc' | 'cpa' | 'cpm' | 'cps' | 'cpa_cps' | 'prv' | 'cpa_sku' | 'cps_sku' | 'cpa_cps_sku' | 'prv_sku', payout_amount: number, payout_percentage: number, is_custom_revenue_enabled?: boolean | undefined, revenue_type: 'blank' | 'rpc' | 'rpa' | 'rpm' | 'rps' | 'rpa_rps' | 'rpa_sku' | 'rps_sku' | 'rpa_rps_sku', revenue_amount: number, revenue_percentage: number, description?: string | undefined, public_description?: string | undefined, is_postback_disabled?: boolean | undefined, date_valid_from?: string | undefined, date_valid_to?: string | undefined, is_apply_specific_offer_urls?: boolean | undefined, network_offer_url_ids?: Array | undefined, ruleset?: Record | undefined, variables?: (Array<{variable: string, variable_value: string, variable_secondary_value?: string | undefined, comparison_method: 'exact_match' | 'contains' | 'begins_with' | 'ends_with' | 'equals' | 'greater_than' | 'greater_than_or_equal' | 'less_than' | 'less_than_or_equal' | 'is_present' | 'not_present' | 'between'}>) | undefined}; export type CreateApiNetworksCustomPayoutrevenueArgs = {body: CustomPayoutRevenueInput}; export type CreateApiNetworksCustomPayoutrevenueOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const customPayoutRevenue = z.object({network_custom_payout_revenue_setting_id: z.number().int().optional(), network_id: z.number().int().optional(), network_offer_id: z.number().int().optional(), network_offer_payout_revenue_id: z.number().int().optional(), name: z.string().optional(), custom_setting_status: z.enum(["active", "inactive"]).optional(), is_apply_all_affiliates: z.boolean().optional(), is_custom_payout_enabled: z.boolean().optional(), payout_type: z.enum(["blank", "cpc", "cpa", "cpm", "cps", "cpa_cps", "prv", "cpa_sku", "cps_sku", "cpa_cps_sku", "prv_sku"]).optional(), payout_amount: z.number().optional(), payout_percentage: z.number().optional(), is_custom_revenue_enabled: z.boolean().optional(), revenue_type: z.enum(["blank", "rpc", "rpa", "rpm", "rps", "rpa_rps", "rpa_sku", "rps_sku", "rpa_rps_sku"]).optional(), revenue_amount: z.number().optional(), revenue_percentage: z.number().optional(), description: z.string().optional(), public_description: z.string().optional(), is_postback_disabled: z.boolean().optional(), date_valid_from: z.string().optional(), date_valid_to: z.string().optional(), is_apply_specific_offer_urls: z.boolean().optional(), network_affiliate_ids: z.array(z.number().int()).optional(), time_created: z.number().int().optional(), time_saved: z.number().int().optional(), network_offer_url_ids: z.array(z.number().int()).nullable().optional(), relationship: z.object({affiliates: z.object({total: z.number().int().optional(), entries: z.array(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(), time_created: z.number().int().optional(), time_saved: z.number().int().optional(), referrer_id: z.number().int().optional()})).optional()}).optional(), 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(), payout_revenue: z.object({network_offer_payout_revenue_id: z.number().int().optional(), network_id: z.number().int().optional(), network_offer_id: z.number().int().optional(), entry_name: z.string().optional(), payout_type: z.string().optional(), payout_amount: z.number().optional(), payout_percentage: z.number().optional(), revenue_type: z.string().optional(), revenue_amount: z.number().optional(), revenue_percentage: z.number().optional(), is_default: z.boolean().optional(), is_private: z.boolean().optional(), is_postback_disabled: z.boolean().optional(), is_enforce_caps: z.boolean().optional(), time_created: z.number().int().optional(), global_advertiser_event_id: z.number().int().optional(), is_must_approve_conversion: z.boolean().optional(), is_allow_duplicate_conversion: z.boolean().optional(), is_email_attribution_default_event: z.boolean().optional(), remote_offer_resource: z.object({}).optional()}).optional(), currency_id: z.string().optional(), ruleset: z.object({}).optional(), variables: z.object({total: z.number().int().optional(), entries: z.array(z.object({network_custom_payout_revenue_setting_variable_id: z.number().int().optional(), network_custom_payout_revenue_setting_id: z.number().int().optional(), comparison_method: z.string().optional(), variable: z.string().optional(), variable_value: z.string().optional(), variable_secondary_value: z.string().optional()})).optional()}).optional(), offer_urls: z.array(z.object({network_offer_url_id: z.number().int().optional(), network_id: z.number().int().optional(), network_offer_id: z.number().int().optional(), name: z.string().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 }; /** * Create Custom Payout/Revenue * * POST /networks/custom/payoutrevenue */ export const createApiNetworksCustomPayoutrevenue = async (args: CreateApiNetworksCustomPayoutrevenueArgs, options?: CreateApiNetworksCustomPayoutrevenueOptions) => { 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/custom/payoutrevenue${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(customPayoutRevenue, await res.json()) };