import {z} from 'zod' export type UpdateApiNetworksCustomLandingpagesSettingIdArgs = {settingId: number, body: {is_apply_all_affiliates?: boolean | undefined, network_affiliate_ids?: Array | undefined, network_offer_id?: number | undefined, name?: string | undefined, network_offer_landing_page_id?: number | undefined, description?: string | undefined, destination_url?: string | undefined, custom_setting_status?: ('active' | 'inactive') | undefined, date_valid_from?: string | undefined, date_valid_to?: string | undefined, network_offer_creative_ids?: Array | undefined, ruleset?: Record | undefined, variables?: (Array<{variable: string, variable_value: string, variable_secondary_value?: string | undefined, comparison_method: 'exact_match' | 'contains' | 'begins_with' | 'ends_with' | 'does_not_contain' | 'does_not_match' | 'is_empty'}>) | undefined}}; export type UpdateApiNetworksCustomLandingpagesSettingIdOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const customLandingPage = z.object({network_custom_landing_page_setting_id: z.number().int().optional(), network_id: z.number().int().optional(), is_apply_all_affiliates: z.boolean().optional(), network_affiliate_ids: z.array(z.number().int()).optional(), network_offer_id: z.number().int().optional(), name: z.string().optional(), network_offer_landing_page_id: z.number().int().optional(), description: z.string().optional(), destination_url: z.string().optional(), custom_setting_status: z.enum(["active", "inactive"]).optional(), date_valid_from: z.string().optional(), date_valid_to: z.string().optional(), network_offer_creative_ids: z.array(z.number().int()).nullable().optional(), time_created: z.number().int().optional(), time_saved: z.number().int().optional(), relationship: z.object({affiliates: z.array(z.object({network_affiliate_id: z.number().int().optional(), network_id: z.number().int().optional(), name: z.string().optional(), account_status: z.string().optional()})).optional(), offer: z.object({network_offer_id: z.number().int().optional(), network_id: z.number().int().optional(), network_advertiser_id: z.number().int().optional(), network_offer_group_id: z.number().int().optional(), name: z.string().optional(), offer_status: z.string().optional(), network_tracking_domain_id: z.number().int().optional(), visibility: z.string().optional(), currency_id: z.string().optional()}).optional(), variables: z.object({total: z.number().int().optional(), entries: z.array(z.object({network___custom___landing___page___setting___variable___id: z.number().int().optional(), network___custom___landing___page___setting___id: z.number().int().optional(), comparison_method: z.string().optional(), variable: z.string().optional(), variable_value: z.string().optional(), variable_secondary_value: z.string().optional()})).optional()}).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 }; /** * Update Custom Landing Page Setting * * PUT /networks/custom/landingpages/{settingId} */ export const updateApiNetworksCustomLandingpagesSettingId = async (args: UpdateApiNetworksCustomLandingpagesSettingIdArgs, options?: UpdateApiNetworksCustomLandingpagesSettingIdOptions) => { 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/landingpages/${encodeURIComponent(String(args.settingId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(customLandingPage, await res.json()) };