import {z} from 'zod' export type GetApiAffiliatesOffersOfferIdProductfeedsArgs = {offerId: number}; export type GetApiAffiliatesOffersOfferIdProductfeedsOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const productFeed = 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()}).optional()}); export const getApiAffiliatesOffersOfferIdProductfeedsResponse = z.object({product_feeds: z.array(productFeed).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 }; /** * Get Offer Product Feeds * * GET /affiliates/offers/{offerId}/productfeeds */ export const getApiAffiliatesOffersOfferIdProductfeeds = async (args: GetApiAffiliatesOffersOfferIdProductfeedsArgs, options?: GetApiAffiliatesOffersOfferIdProductfeedsOptions) => { const {baseUrl = "https://api.eflow.team/v1", fetch: fetchFn = fetch, APIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (APIKey !== undefined) headers.set("X-Eflow-Api-Key", APIKey) const url = `${baseUrl.replace(/\/+$/, '')}/affiliates/offers/${encodeURIComponent(String(args.offerId))}/productfeeds${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiAffiliatesOffersOfferIdProductfeedsResponse, await res.json()) };