import {z} from 'zod' export type OfferGroupInput = {name: string, offer_group_status: 'active' | 'paused' | 'deleted', network_advertiser_id: number, network_offer_ids: Array, currency_id: string, labels?: Array | undefined, internal_notes?: string | undefined, is_caps_enabled?: boolean | undefined, is_soft_cap?: boolean | undefined, daily_conversion_cap?: number | undefined, weekly_conversion_cap?: number | undefined, monthly_conversion_cap?: number | undefined, global_conversion_cap?: number | undefined, daily_payout_cap?: number | undefined, weekly_payout_cap?: number | undefined, monthly_payout_cap?: number | undefined, global_payout_cap?: number | undefined, daily_revenue_cap?: number | undefined, weekly_revenue_cap?: number | undefined, monthly_revenue_cap?: number | undefined, global_revenue_cap?: number | undefined, daily_click_cap?: number | undefined, weekly_click_cap?: number | undefined, monthly_click_cap?: number | undefined, global_click_cap?: number | undefined}; export type UpdateApiNetworksOffergroupsOfferGroupIdArgs = {offerGroupId: number, body: OfferGroupInput}; export type UpdateApiNetworksOffergroupsOfferGroupIdOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const offerGroup = z.object({network_offer_group_id: z.number().int().optional(), network_id: z.number().int().optional(), network_advertiser_id: z.number().int().optional(), name: z.string().optional(), internal_notes: z.string().optional(), offer_group_status: z.enum(["active", "paused", "deleted"]).optional(), is_caps_enabled: z.boolean().optional(), daily_conversion_cap: z.number().int().optional(), weekly_conversion_cap: z.number().int().optional(), monthly_conversion_cap: z.number().int().optional(), global_conversion_cap: z.number().int().optional(), daily_payout_cap: z.number().optional(), weekly_payout_cap: z.number().optional(), monthly_payout_cap: z.number().optional(), global_payout_cap: z.number().optional(), daily_revenue_cap: z.number().optional(), weekly_revenue_cap: z.number().optional(), monthly_revenue_cap: z.number().optional(), global_revenue_cap: z.number().optional(), daily_click_cap: z.number().int().optional(), weekly_click_cap: z.number().int().optional(), monthly_click_cap: z.number().int().optional(), global_click_cap: z.number().int().optional(), time_created: z.number().int().optional(), time_saved: z.number().int().optional(), relationship: z.object({advertiser: z.object({network_advertiser_id: z.number().int().optional(), network_id: z.number().int().optional(), name: z.string().optional(), account_status: z.string().optional(), network_employee_id: z.number().int().optional(), sales_manager_id: z.number().int().optional(), address_id: z.number().int().optional(), is_contact_address_enabled: z.boolean().optional(), default_currency_id: z.string().optional(), platform_name: z.string().optional(), platform_url: z.string().optional(), platform_username: z.string().optional(), offer_id_macro: z.string().optional(), affiliate_id_macro: z.string().optional(), accounting_contact_email: z.string().optional(), internal_notes: z.string().optional(), attribution_method: z.string().optional(), email_attribution_method: z.string().optional(), attribution_priority: z.string().optional(), verification_token: z.string().optional(), is_expose_publisher_reporting_data: z.boolean().optional(), reporting_timezone_id: z.number().int().optional(), time_created: z.number().int().optional(), time_saved: z.number().int().optional()}).optional(), labels: z.object({total: z.number().int().optional(), entries: z.array(z.string()).optional()}).optional(), network_offer_ids: z.array(z.number().int()).optional(), remaining_caps: z.object({remaining_daily_payout_cap: z.number().optional(), remaining_daily_revenue_cap: z.number().optional(), remaining_daily_conversion_cap: z.number().int().optional(), remaining_daily_click_cap: z.number().int().optional(), remaining_weekly_payout_cap: z.number().optional(), remaining_weekly_revenue_cap: z.number().optional(), remaining_weekly_conversion_cap: z.number().int().optional(), remaining_weekly_click_cap: z.number().int().optional(), remaining_monthly_payout_cap: z.number().optional(), remaining_monthly_revenue_cap: z.number().optional(), remaining_monthly_conversion_cap: z.number().int().optional(), remaining_monthly_click_cap: z.number().int().optional(), remaining_global_payout_cap: z.number().optional(), remaining_global_revenue_cap: z.number().optional(), remaining_global_conversion_cap: z.number().int().optional(), remaining_global_click_cap: z.number().int().optional()}).optional()}).optional(), is_soft_cap: z.boolean().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 Offer Group * * PUT /networks/offergroups/{offerGroupId} */ export const updateApiNetworksOffergroupsOfferGroupId = async (args: UpdateApiNetworksOffergroupsOfferGroupIdArgs, options?: UpdateApiNetworksOffergroupsOfferGroupIdOptions) => { 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/offergroups/${encodeURIComponent(String(args.offerGroupId))}${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(offerGroup, await res.json()) };