import {z} from 'zod' export type CreateApiNetworksOfferurlsTableArgs = {page?: number | undefined, page_size?: number | undefined, order_field?: ('network_offer_url_id' | 'time_saved' | 'time_created' | 'url_status') | undefined, order_direction?: ('asc' | 'desc') | undefined, body: {filters?: ({network_offer_ids?: Array | undefined, url_status?: ('active' | 'paused' | 'deleted') | undefined}) | undefined, search_terms?: (Array<{search_type?: ('name' | 'destination_url') | undefined, value?: string | undefined}>) | undefined}}; export type CreateApiNetworksOfferurlsTableOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const offerUrl = 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(), destination_url: z.string().optional(), preview_url: z.string().optional(), url_status: z.enum(["active", "paused", "deleted"]).optional(), network_affiliate_ids: z.array(z.number().int()).nullable().optional(), is_apply_specific_affiliates: z.boolean().optional(), is_hidden_affiliate: z.boolean().optional(), time_created: z.number().int().optional(), time_saved: z.number().int().optional(), remote_offer_resource: z.object({network_offer_id: z.number().int().optional(), network_id: z.number().int().optional(), resource_type: z.string().optional(), remote_resource_id: z.string().optional(), resource_id: z.number().int().optional(), last_value_md5: z.string().optional(), json_config: z.string().optional(), json_data: z.string().optional(), time_created: z.number().int().optional(), time_saved: z.number().int().optional()}).optional()}); export const createApiNetworksOfferurlsTableResponse = z.object({urls: z.array(offerUrl).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 URLs (Advanced) * * POST /networks/offerurls/table */ export const createApiNetworksOfferurlsTable = async (args: CreateApiNetworksOfferurlsTableArgs, options?: CreateApiNetworksOfferurlsTableOptions) => { 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.order_field != null) query.append("order_field", String(args.order_field)) if (args.order_direction != null) query.append("order_direction", String(args.order_direction)) if (APIKey !== undefined) headers.set("X-Eflow-Api-Key", APIKey) const url = `${baseUrl.replace(/\/+$/, '')}/networks/offerurls/table${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(createApiNetworksOfferurlsTableResponse, await res.json()) };