import {z} from 'zod' export type CreateApiNetworksAffiliatesAffiliateIdUsersArgs = {affiliateId: number, notification?: boolean | undefined, body: {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}}; export type CreateApiNetworksAffiliatesAffiliateIdUsersOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const affiliateUser = z.object({network_affiliate_user_id: z.number().int().optional(), network_id: z.number().int().optional(), network_affiliate_id: z.number().int().optional(), first_name: z.string().optional(), last_name: z.string().optional(), email: z.string().optional(), title: 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(), language_id: z.number().int().optional(), timezone_id: z.number().int().optional(), currency_id: z.string().optional(), account_status: z.enum(["active", "inactive"]).optional(), relationship: z.object({logins: z.object({total: z.number().int().optional(), entries: z.array(z.object({})).optional()}).optional(), customization: z.object({}).optional(), audits: z.object({total: z.number().int().optional(), entries: z.array(z.object({})).optional()}).optional(), api: z.object({total: z.number().int().optional(), entries: z.array(z.object({})).optional()}).optional(), affiliate_account_status: z.string().optional()}).nullable().optional(), time_created: z.number().int().optional(), time_saved: z.number().int().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 User * * POST /networks/affiliates/{affiliateId}/users */ export const createApiNetworksAffiliatesAffiliateIdUsers = async (args: CreateApiNetworksAffiliatesAffiliateIdUsersArgs, options?: CreateApiNetworksAffiliatesAffiliateIdUsersOptions) => { 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/${encodeURIComponent(String(args.affiliateId))}/users${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(affiliateUser, await res.json()) };