import {z} from 'zod' export type CustomCreativeSettingInput = {network_offer_creative_ids?: Array | undefined, network_affiliate_ids: Array, name: string, custom_setting_status: 'active' | 'inactive', creative: {network_offer_id: number, name: string, creative_type: 'image' | 'html' | 'thumbnail' | 'email' | 'archive' | 'video' | 'text' | 'link', is_private: boolean, creative_status: 'active' | 'paused' | 'deleted', html_code?: string | undefined, width?: number | undefined, height?: number | undefined, email_from?: string | undefined, email_subject?: string | undefined, additional_offer_ids?: Array | undefined, is_apply_specific_affiliates?: boolean | undefined, resource_file?: ({temp_url?: string | undefined, original_file_name?: string | undefined}) | undefined, html_files?: Array> | undefined, html_assets?: Array> | undefined}}; export type CreateApiNetworksCustomCreativeArgs = {body: CustomCreativeSettingInput}; export type CreateApiNetworksCustomCreativeOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const customCreativeSetting = z.object({network_custom_creative_setting_id: z.number().int().optional(), network_id: z.number().int().optional(), network_offer_creative_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(), relationship: z.object({affiliates: z.array(z.object({})).optional(), creative: z.object({}).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 }; /** * Create Custom Creative Setting * * POST /networks/custom/creative */ export const createApiNetworksCustomCreative = async (args: CreateApiNetworksCustomCreativeArgs, options?: CreateApiNetworksCustomCreativeOptions) => { 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(/\/+$/, '')}/networks/custom/creative${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(customCreativeSetting, await res.json()) };