import {z} from 'zod' export type CreateApiNetworksAffiliatesArgs = {notification?: boolean | undefined, body: {name: string, account_status: 'active' | 'inactive', network_employee_id: number, internal_notes?: string | undefined, default_currency_id: string, enable_media_cost_tracking_links?: boolean | undefined, referrer_id?: number | undefined, is_contact_address_enabled?: boolean | undefined, network_affiliate_tier_id?: number | undefined, contact_address?: ({address_1?: string | undefined, address_2?: string | undefined, city?: string | undefined, region_code?: string | undefined, country_code?: string | undefined, zip_postal_code?: string | undefined}) | undefined, labels?: Array | undefined, users?: (Array<{first_name: string, last_name: string, email: string, language_id: number, timezone_id: number, title?: string | undefined, work_phone?: string | undefined, cell_phone?: string | undefined, instant_messaging_id?: number | undefined, instant_messaging_identifier?: string | undefined, currency_id: string, account_status: 'active' | 'inactive', initial_password?: string | undefined}>) | undefined, billing: {billing_frequency: 'weekly' | 'bimonthly' | 'monthly' | 'two_months' | 'quarterly' | 'manual' | 'other', payment_type: 'none' | 'pay' | 'paypal' | 'check' | 'wire' | 'direct_deposit' | 'tipalti' | 'paxum' | 'veem' | 'payoneer' | 'bitcoin' | 'webmoney' | 'capitalist' | 'transferwise' | 'gift_card' | 'masspay' | 'skrill', tax_id?: string | undefined, is_invoice_creation_auto?: boolean | undefined, auto_invoice_start_date?: string | undefined, default_invoice_is_hidden?: boolean | undefined, invoice_generation_days_delay?: number | undefined, invoice_amount_threshold?: number | undefined, default_payment_terms?: number | undefined, details: {day_of_week?: number | undefined, day_of_month_one?: number | undefined, day_of_month_two?: number | undefined, day_of_month?: number | undefined, starting_month?: number | undefined}, billing: {paxum_id?: string | undefined, paypal_reception_method?: ('email' | 'phone' | 'paypal_account') | undefined, reception_identifier?: string | undefined, email?: string | undefined, is_existing_payee?: boolean | undefined, idap?: string | undefined, first_name?: string | undefined, last_name?: string | undefined, phone?: string | undefined, country_iso?: string | undefined, bank_name?: string | undefined, bank_address?: string | undefined, account_name?: string | undefined, account_number?: string | undefined, routing_number?: string | undefined, swift_code?: string | undefined}}}}; export type CreateApiNetworksAffiliatesOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const affiliate = z.object({network_affiliate_id: z.number().int().optional(), network_id: z.number().int().optional(), name: z.string().optional(), account_status: z.enum(["active", "inactive", "pending", "suspended"]).optional(), network_employee_id: z.number().int().optional(), internal_notes: z.string().optional(), default_currency_id: z.string().optional(), enable_media_cost_tracking_links: z.boolean().optional(), is_contact_address_enabled: z.boolean().optional(), network_affiliate_tier_id: z.number().int().optional(), has_notifications: z.boolean().optional(), network_traffic_source_id: z.number().int().optional(), account_executive_id: z.number().int().optional(), adress_id: z.number().int().optional(), address_id: z.number().int().optional(), referrer_id: z.number().int().optional(), contact_address: z.object({address_1: z.string().optional(), address_2: z.string().optional(), city: z.string().optional(), region_code: z.string().optional(), country_code: z.string().optional(), zip_postal_code: z.string().optional()}).optional(), labels: z.array(z.string()).optional(), time_created: z.number().int().optional(), time_saved: z.number().int().optional(), relationship: z.object({labels: z.object({total: z.number().int().optional(), entries: z.array(z.string()).optional()}).optional(), account_manager: z.object({first_name: z.string().optional(), last_name: z.string().optional(), email: z.string().optional(), work_phone: z.string().optional(), cell_phone: z.string().optional(), instant_messaging_id: z.number().int().optional(), instant_messaging_identifier: z.string().optional()}).optional(), encoded_value: z.string().optional(), ios_app_sources: z.object({total: z.number().int().optional(), entries: z.array(z.object({})).optional()}).optional(), users: z.object({total: z.number().int().optional(), entries: z.array(z.object({})).optional()}).optional(), overrides: z.object({total: z.number().int().optional(), entries: z.array(z.object({is_visible: z.boolean().optional(), variable: z.enum(["adv1", "adv2", "adv3", "adv4", "adv5", "adv6", "adv7", "adv8", "adv9", "adv10", "sale_amount"]).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 }; /** * Create Affiliate * * POST /networks/affiliates */ export const createApiNetworksAffiliates = async (args: CreateApiNetworksAffiliatesArgs, options?: CreateApiNetworksAffiliatesOptions) => { 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 (args.notification != null) query.append("notification", String(args.notification)) if (APIKey !== undefined) headers.set("X-Eflow-Api-Key", APIKey) const url = `${baseUrl.replace(/\/+$/, '')}/networks/affiliates${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(affiliate, await res.json()) };