import {z} from 'zod' export type CreateApiAffiliatesProductfeedsArgs = {body: {filters?: ({network_offer_ids?: Array | undefined}) | undefined}}; export type CreateApiAffiliatesProductfeedsOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiAffiliatesProductfeedsResponse = z.object({product_feeds: z.array(z.object({network_advertiser_product_feed_id: z.number().int().optional(), network_id: z.number().int().optional(), network_advertiser_id: z.number().int().optional(), name: z.string().optional(), status: z.string().optional(), file_asset_id: z.number().int().optional(), date_valid_from: z.number().int().optional(), date_valid_to: z.number().int().optional(), date_valid_timezone_id: z.number().int().optional(), time_created: z.number().int().optional(), time_saved: z.number().int().optional(), relationship: z.object({document_file_asset: z.object({network_asset_id: z.number().int().optional(), content_type: z.string().optional(), filename: z.string().optional(), url: z.string().optional(), file_size: z.number().int().optional(), image_width: z.number().int().optional(), image_height: z.number().int().optional(), optimized_thumbnail_url: z.string().optional()}).optional(), offers: z.array(z.object({network_offer_id: z.number().int().optional(), network_id: z.number().int().optional(), name: z.string().optional(), offer_status: z.string().optional()})).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 }; /** * Search Product Feeds * * POST /affiliates/productfeeds */ export const createApiAffiliatesProductfeeds = async (args: CreateApiAffiliatesProductfeedsArgs, options?: CreateApiAffiliatesProductfeedsOptions) => { 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(/\/+$/, '')}/affiliates/productfeeds${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(createApiAffiliatesProductfeedsResponse, await res.json()) };