import {z} from 'zod' export type CreateApiNetworksCustomCreativetableArgs = {page?: number | undefined, page_size?: number | undefined, order_field?: ('name' | 'time_created' | 'time_saved' | 'id') | undefined, order_direction?: ('asc' | 'desc') | undefined, relationship?: 'all' | undefined, body: {filters?: ({network_offer_ids?: Array | undefined, network_affiliate_ids?: Array | undefined, custom_setting_status?: ('active' | 'inactive') | undefined}) | undefined, search_terms?: (Array<{search_type: 'name' | 'offer' | 'affiliate', value: string}>) | undefined}}; export type CreateApiNetworksCustomCreativetableOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiNetworksCustomCreativetableResponse = z.object({custom_creative_settings: z.array(z.object({network_custom_creative_setting_id: z.number().int().optional(), network_id: z.number().int().optional(), network_offer_creative_id: z.number().int().optional(), network_offer_ids: z.array(z.number().int()).optional(), network_affiliate_ids: z.array(z.number().int()).optional(), name: z.string().optional(), custom_setting_status: z.enum(["active", "inactive"]).optional(), time_created: z.number().int().optional(), time_saved: z.number().int().optional(), optimized_thumbnail_url: z.string().optional(), relationship: z.object({affiliates: z.array(z.object({})).optional(), offers: z.array(z.object({})).optional(), creative: z.object({}).optional()}).optional()})).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 Custom Creative Settings (Advanced) * * POST /networks/custom/creativetable */ export const createApiNetworksCustomCreativetable = async (args: CreateApiNetworksCustomCreativetableArgs, options?: CreateApiNetworksCustomCreativetableOptions) => { 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 (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/creativetable${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(createApiNetworksCustomCreativetableResponse, await res.json()) };