import {z} from 'zod' export type GetApiNetworksLabelsLabelArgs = {label: string}; export type GetApiNetworksLabelsLabelOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const label = z.object({label: z.string().optional(), advertiser_ids: z.array(z.number().int()).nullable().optional(), affiliate_ids: z.array(z.number().int()).nullable().optional(), campaign_ids: z.array(z.number().int()).nullable().optional(), offer_ids: z.array(z.number().int()).nullable().optional(), offer_group_ids: z.array(z.number().int()).nullable().optional(), affiliate_tier_ids: z.array(z.number().int()).nullable().optional(), relationship: z.object({advertisers: z.array(z.object({network_advertiser_id: z.number().int().optional(), network_id: z.number().int().optional(), name: z.string().optional(), account_status: z.string().optional()})).optional(), 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(), campaigns: z.array(z.object({network_campaign_id: z.number().int().optional(), network_id: z.number().int().optional(), campaign_name: z.string().optional(), campaign_status: z.string().optional()})).optional(), offers: z.array(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(), offer_groups: z.array(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(), offer_group_status: z.string().optional(), offer_count: z.number().int().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 }; /** * Find By Label * * GET /networks/labels/{label} */ export const getApiNetworksLabelsLabel = async (args: GetApiNetworksLabelsLabelArgs, options?: GetApiNetworksLabelsLabelOptions) => { const {baseUrl = "https://api.eflow.team/v1", fetch: fetchFn = fetch, APIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (APIKey !== undefined) headers.set("X-Eflow-Api-Key", APIKey) const url = `${baseUrl.replace(/\/+$/, '')}/networks/labels/${encodeURIComponent(String(args.label))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(label, await res.json()) };