import {z} from 'zod' export type CreateApiNetworksOffergroupstableArgs = {page?: number | undefined, page_size?: number | undefined, body: {search_terms?: (Array<{search_type?: ('name' | 'advertiser_name') | undefined, value?: string | undefined}>) | undefined, filters?: ({network_advertiser_ids?: Array | undefined, network_offer_ids?: Array | undefined, offer_group_status?: ('active' | 'paused' | 'deleted') | undefined}) | undefined, network_offer_group_ids?: Array | undefined, order_field?: ('name' | 'network_offer_group_id' | 'offer_group_status' | 'network_advertiser_id' | 'time_created' | 'time_saved') | undefined, order_direction?: ('asc' | 'desc') | undefined}}; export type CreateApiNetworksOffergroupstableOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const offerGroupTableItem = z.object({network_offer_group_id: z.number().int().optional(), network_id: z.number().int().optional(), network_advertiser_id: z.number().int().optional(), name: z.string().optional(), offer_group_status: z.enum(["active", "paused", "deleted"]).optional(), offer_count: z.number().int().optional(), daily_conversion_cap: z.number().int().optional(), weekly_conversion_cap: z.number().int().optional(), monthly_conversion_cap: z.number().int().optional(), global_conversion_cap: z.number().int().optional(), daily_payout_cap: z.number().optional(), weekly_payout_cap: z.number().optional(), monthly_payout_cap: z.number().optional(), global_payout_cap: z.number().optional(), daily_revenue_cap: z.number().optional(), weekly_revenue_cap: z.number().optional(), monthly_revenue_cap: z.number().optional(), global_revenue_cap: z.number().optional(), daily_click_cap: z.number().int().optional(), weekly_click_cap: z.number().int().optional(), monthly_click_cap: z.number().int().optional(), global_click_cap: z.number().int().optional(), today_clicks: z.number().int().optional(), today_payout: z.number().optional(), today_revenue: z.number().optional(), time_created: z.number().int().optional(), time_saved: z.number().int().optional(), relationship: z.object({remaining_caps: z.object({remaining_daily_payout_cap: z.number().optional(), remaining_daily_revenue_cap: z.number().optional(), remaining_daily_conversion_cap: z.number().int().optional(), remaining_daily_click_cap: z.number().int().optional(), remaining_weekly_payout_cap: z.number().optional(), remaining_weekly_revenue_cap: z.number().optional(), remaining_weekly_conversion_cap: z.number().int().optional(), remaining_weekly_click_cap: z.number().int().optional(), remaining_monthly_payout_cap: z.number().optional(), remaining_monthly_revenue_cap: z.number().optional(), remaining_monthly_conversion_cap: z.number().int().optional(), remaining_monthly_click_cap: z.number().int().optional(), remaining_global_payout_cap: z.number().optional(), remaining_global_revenue_cap: z.number().optional(), remaining_global_conversion_cap: z.number().int().optional(), remaining_global_click_cap: z.number().int().optional()}).optional()}).optional()}); export const createApiNetworksOffergroupstableResponse = z.object({offer_groups: z.array(offerGroupTableItem).optional(), paging: z.object({page: z.number().int().optional(), page_size: z.number().int().optional(), total_count: z.number().int().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 }; /** * Find Offer Groups (Advanced) * * POST /networks/offergroupstable */ export const createApiNetworksOffergroupstable = async (args: CreateApiNetworksOffergroupstableArgs, options?: CreateApiNetworksOffergroupstableOptions) => { 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/offergroupstable${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(createApiNetworksOffergroupstableResponse, await res.json()) };