import {z} from 'zod' export type OfferPatchRequestBody = {network_offer_ids: Array, fields: Array<{field_type: 'offer_status' | 'network_advertiser_id' | 'network_offer_group_id' | 'network_category_id' | 'currency_id' | 'labels' | 'app_identifier' | 'internal_notes' | 'project_id' | 'channels' | 'date_live_until' | 'html_description' | 'is_offer_description_plaintext' | 'destination_url' | 'destination_url_replace' | 'offer_name' | 'preview_url' | 'preview_url_replace' | 'invoca_enabled' | 'payout_revenue_name' | 'revenue' | 'payout' | 'is_must_approve_conversion' | 'is_allow_duplicate_conversion' | 'is_postback_disabled' | 'additional_events' | 'network_tracking_domain_id' | 'conversion_method' | 'is_use_secure_link' | 'is_allow_deep_link' | 'is_use_direct_linking' | 'is_caps_enabled' | 'is_soft_cap' | 'daily_click_cap' | 'weekly_click_cap' | 'monthly_click_cap' | 'global_click_cap' | 'daily_conversion_cap' | 'weekly_conversion_cap' | 'monthly_conversion_cap' | 'global_conversion_cap' | 'daily_payout_cap' | 'weekly_payout_cap' | 'monthly_payout_cap' | 'global_payout_cap' | 'daily_revenue_cap' | 'weekly_revenue_cap' | 'monthly_revenue_cap' | 'global_revenue_cap' | 'visibility' | 'is_using_explicit_terms_and_conditions' | 'is_force_terms_and_conditions' | 'terms_and_conditions' | 'is_whitelist_check_enabled' | 'session_definition' | 'session_duration' | 'is_duplicate_filter_enabled' | 'duplicate_filter_targeting_action' | 'redirect_mode' | 'requirement_kpis' | 'requirement_tracking_parameters' | 'is_block_already_converted' | 'already_converted_action' | 'is_use_scrub_rate' | 'scrub_rate_status' | 'scrub_rate_percentage' | 'is_session_tracking_enabled' | 'session_tracking_lifespan_hour' | 'session_tracking_minimum_lifespan_second' | 'attribution_method' | 'is_view_through_enabled' | 'is_view_through_session_tracking_enabled' | 'view_through_session_tracking_lifespan_minute' | 'view_through_session_tracking_minimal_lifespan_second' | 'twentyfour_metrics_network_integration_twentyfour_metrics_tracker_id' | 'forensiq_is_forensiq_click_threshold_enabled' | 'forensiq_click_threshold' | 'forensiq_action' | 'forensiq_is_forensiq_conversion_threshold_enabled' | 'forensiq_conversion_threshold' | 'forensiq_conversion_status' | 'anura_enabled' | 'ip_quality_score_enabled' | 'ip_quality_score_min_fraud_score' | 'ip_quality_score_min_fraud_score_mobile' | 'ip_quality_score_action' | 'server_side_url' | 'server_side_url_replace' | 'view_through_destination_url' | 'view_through_destination_url_replace' | 'ruleset_platforms' | 'ruleset_device_types' | 'ruleset_browsers' | 'ruleset_os_versions' | 'ruleset_languages' | 'ruleset_countries' | 'ruleset_regions' | 'ruleset_cities' | 'ruleset_dmas' | 'ruleset_mobile_carriers' | 'ruleset_isps' | 'ruleset_connection_types' | 'ruleset_ips' | 'ruleset_is_block_proxy' | 'ruleset_brands' | 'ruleset_postal_codes' | 'traffic_filters' | 'ruleset_is_use_day_parting' | 'ruleset_day_parting_apply_to' | 'ruleset_day_parting_timezone_id' | 'ruleset_days_parting' | 'is_fail_traffic_enabled' | 'redirect_internal_routing_type' | 'email_is_enabled' | 'email_subject_lines' | 'email_from_lines' | 'email_optout_is_enabled' | 'email_optout_suppression_file_link' | 'email_optout_unsub_link' | 'email_suppression_file' | 'ezepo_enabled' | 'optizmo_optoutlist_id' | 'unsubcentral_list_id', field_value: unknown, operator: 'overwrite' | 'append' | 'delete' | 'clear'}>}; export type CreateApiNetworksPatchOffersSubmitArgs = {body: OfferPatchRequestBody}; export type CreateApiNetworksPatchOffersSubmitOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiNetworksPatchOffersSubmitResponse = z.object({changes: z.array(z.object({network_offer: z.object({network_offer_id: z.number().int().optional(), network_id: z.number().int().optional(), name: z.string().optional(), offer_status: z.string().optional()}).optional(), change_status: z.enum(["ok", "error", "no_change"]).optional(), current_field: z.object({field_type: z.string().optional(), field_value: z.unknown(), operator: z.string().optional()}).optional(), changed_field: z.object({field_type: z.string().optional(), field_value: z.unknown(), operator: z.string().optional()}).optional(), error_message: z.string().optional(), related_changes: z.string().optional()})).optional(), resource_errors: z.array(z.object({id: z.number().int().optional(), label: z.string().optional(), type: z.string().optional(), message: z.string().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 }; /** * Offer Bulk Edit Preview * * POST /networks/patch/offers/submit */ export const createApiNetworksPatchOffersSubmit = async (args: CreateApiNetworksPatchOffersSubmitArgs, options?: CreateApiNetworksPatchOffersSubmitOptions) => { 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/patch/offers/submit${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(createApiNetworksPatchOffersSubmitResponse, await res.json()) };