import {z} from 'zod' export type CreateApiNetworksSupplementsArgs = {body: {unix_timestamp: number, supplement_source: 'appsflyer' | 'adjust' | 'google_ads_cost' | 'tiktok_ads_mbc' | 'generic', network_offer_id: number, network_affiliate_id: number, source_id?: string | undefined, sub1?: string | undefined, sub2?: string | undefined, sub3?: string | undefined, sub4?: string | undefined, sub5?: string | undefined, sub6?: string | undefined, sub7?: string | undefined, sub8?: string | undefined, sub9?: string | undefined, sub10?: string | undefined, adv1?: string | undefined, adv2?: string | undefined, adv3?: string | undefined, adv4?: string | undefined, adv5?: string | undefined, adv6?: string | undefined, adv7?: string | undefined, adv8?: string | undefined, adv9?: string | undefined, adv10?: string | undefined, currency_id?: string | undefined, reporting?: ({imp?: number | undefined, total_click?: number | undefined, unique_click?: number | undefined, invalid_click?: number | undefined, duplicate_click?: number | undefined, gross_click?: number | undefined, cv?: number | undefined, total_cv?: number | undefined, invalid_cv_scrub?: number | undefined, view_through_cv?: number | undefined, event?: number | undefined, event_vt?: number | undefined, payout?: number | undefined, revenue?: number | undefined, event_revenue?: number | undefined, gross_sales?: number | undefined, gross_sales_vt?: number | undefined, gross_sales_cv?: number | undefined, gross_sales_event?: number | undefined, cost?: number | undefined, media_buying_cost?: number | undefined, redirect_traffic_revenue?: number | undefined}) | undefined, network_offer_payout_revenue_id?: number | undefined, source_details_json?: string | undefined, relationship?: ({appsflyer?: ({appsflyer_campaign_id?: string | undefined, appsflyer_publisher_id?: string | undefined, appsflyer_event_id?: string | undefined, network_integration_appsflyer_data_import_app_id?: number | undefined}) | undefined, tiktok_ads_mbc?: ({network_integration_tiktok_ads_mbc_config_id?: number | undefined, mapping_id?: string | undefined, mapping_name?: string | undefined, mapping_type?: string | undefined, service_type?: string | undefined}) | undefined, adjust?: ({adjust_campaign_id?: string | undefined, adjust_adgroup_id?: string | undefined, adjust_creative_id?: string | undefined, adjust_partner_id?: string | undefined, adjust_event_id?: string | undefined, network_integration_adjust_data_import_app_id?: number | undefined}) | undefined}) | undefined}}; export type CreateApiNetworksSupplementsOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiNetworksSupplementsResponse = z.object({network_data_supplement_id: z.number().int().optional(), network_id: z.number().int().optional(), unix_timestamp: z.number().int().optional(), supplement_source: z.string().optional(), network_offer_id: z.number().int().optional(), network_affiliate_id: z.number().int().optional(), source_id: z.string().optional(), currency_id: z.string().optional(), reporting: z.object({}).optional(), time_created: z.number().int().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 Data Supplement * * POST /networks/supplements */ export const createApiNetworksSupplements = async (args: CreateApiNetworksSupplementsArgs, options?: CreateApiNetworksSupplementsOptions) => { 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/supplements${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(createApiNetworksSupplementsResponse, await res.json()) };