import {z} from 'zod' export type SearchRequest = {search_terms?: (Array<{search_type: 'name' | 'offer' | 'affiliate', value: string}>) | undefined, filters?: ({custom_setting_status?: ('active' | 'inactive') | undefined, network_affiliate_ids?: Array | undefined, network_offer_ids?: Array | undefined, scrub_rate_status?: ('rejected' | 'pending') | undefined}) | undefined, sort?: ({field?: string | undefined, direction?: ('asc' | 'desc') | undefined}) | undefined}; export type CreateApiNetworksCustomScrubratetableArgs = {page?: number | undefined, page_size?: number | undefined, relationship?: 'all' | undefined, body: SearchRequest}; export type CreateApiNetworksCustomScrubratetableOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const paging = z.object({page: z.number().int().optional(), page_size: z.number().int().optional(), total_count: z.number().int().optional()}); export const createApiNetworksCustomScrubratetableResponse = z.object({custom_scrub_rate_settings: z.array(z.object({network_custom_scrub_rate_setting_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(), custom_setting_status: z.enum(["active", "inactive"]).optional(), name: z.string().optional(), scrub_rate_status: z.enum(["rejected", "pending"]).optional(), scrub_rate_percentage: z.number().int().optional(), time_created: z.number().int().optional(), time_saved: z.number().int().optional(), relationship: z.object({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()}).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(), ruleset: z.object({}).optional()}).optional()})).optional(), paging: paging.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 Custom Scrub Rates (Advanced) * * POST /networks/custom/scrubratetable */ export const createApiNetworksCustomScrubratetable = async (args: CreateApiNetworksCustomScrubratetableArgs, options?: CreateApiNetworksCustomScrubratetableOptions) => { 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 (args.relationship != null) query.append("relationship", String(args.relationship)) if (APIKey !== undefined) headers.set("X-Eflow-Api-Key", APIKey) const url = `${baseUrl.replace(/\/+$/, '')}/networks/custom/scrubratetable${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(createApiNetworksCustomScrubratetableResponse, await res.json()) };