import {z} from 'zod' export type GetApiAffiliatesOffersOfferIdDealsArgs = {offerId: number}; export type GetApiAffiliatesOffersOfferIdDealsOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const deal = z.object({network_advertiser_deal_id: z.number().int(), network_id: z.number().int().optional(), name: z.string(), description: z.string().optional(), brand_name: z.string().optional(), deal_type: z.string(), deal_status: z.string(), deal_categories: z.array(z.string()), scope: z.string().optional(), restrictions: z.string().optional(), coupon_code: z.string().optional(), coupon_code_discount_amount: z.number().optional(), coupon_code_discount_percentage: z.number().optional(), coupon_code_discount_currency_id: z.string().optional(), threshold_amount: z.number().optional(), threshold_amount_currency_id: z.string().optional(), threshold_quantity: z.number().int().optional(), purchase_limit_amount: z.number().optional(), purchase_limit_amount_currency_id: z.string().optional(), purchase_limit_quantity: 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(), time_deleted: z.number().int().optional(), relationship: z.object({}).optional()}); export const getApiAffiliatesOffersOfferIdDealsResponse = z.object({deals: z.array(deal).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 Deals * * GET /affiliates/offers/{offerId}/deals */ export const getApiAffiliatesOffersOfferIdDeals = async (args: GetApiAffiliatesOffersOfferIdDealsArgs, options?: GetApiAffiliatesOffersOfferIdDealsOptions) => { 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))}/deals${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(getApiAffiliatesOffersOfferIdDealsResponse, await res.json()) };