import {z} from 'zod' export type InMarketSizeEstimationV1 = {brandIds?: Array | undefined, buyingPower?: (Array<'Low' | 'Medium' | 'High' | 'VeryHigh'>) | undefined, country: string, gender?: ('Male' | 'Female') | undefined, interestIds?: Array | undefined, priceRange?: (Array<'Low' | 'Medium' | 'High'>) | undefined}; export type PointOfInterestV1 = {latitude?: (number | null) | undefined, longitude?: (number | null) | undefined, name?: (string | null) | undefined}; export type LocationSizeEstimationV1 = {pointsOfInterest: Array, radiusInKm: number}; export type AudienceSegmentSizeEstimationEntityV1 = {advertiserId: string, inMarket?: InMarketSizeEstimationV1 | undefined, location?: LocationSizeEstimationV1 | undefined}; export type AudienceSegmentSizeEstimationEntityV1Resource = {attributes?: AudienceSegmentSizeEstimationEntityV1 | undefined, type?: string | undefined}; export type AudienceSegmentEstimateSizeInputV1 = {data?: AudienceSegmentSizeEstimationEntityV1Resource | undefined}; export type CreateApi202601MarketingSolutionsAudienceSegmentsEstimateSizeArgs = {body: AudienceSegmentEstimateSizeInputV1}; export type CreateApi202601MarketingSolutionsAudienceSegmentsEstimateSizeOptions = {baseUrl?: string | undefined, oauth?: string | undefined, fetch?: typeof fetch | undefined}; export const audienceSegmentSizeEstimationV1 = z.object({size: z.number().int().nullable().optional()}).nullable(); export const audienceSegmentSizeEstimationV1Resource = z.object({attributes: audienceSegmentSizeEstimationV1.optional(), type: z.string().nullable().optional()}).nullable(); export const commonProblem = z.object({code: z.string().nullable().optional(), detail: z.string().nullable().optional(), instance: z.string().nullable().optional(), source: z.record(z.string(), z.string()).nullable().optional(), stackTrace: z.string().nullable().optional(), title: z.string().nullable().optional(), traceId: z.string().nullable().optional(), traceIdentifier: z.string().nullable().optional(), type: z.enum(["unknown", "access-control", "authentication", "authorization", "availability", "deprecation", "quota", "validation"]).nullable().optional()}); export const audienceSegmentSizeEstimationV1Response = z.object({data: audienceSegmentSizeEstimationV1Resource.optional(), errors: z.array(commonProblem).nullable().optional(), warnings: z.array(commonProblem).nullable().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 }; /** * /2026-01/marketing-solutions/audience-segments/estimate-size * * POST /2026-01/marketing-solutions/audience-segments/estimate-size */ export const createApi202601MarketingSolutionsAudienceSegmentsEstimateSize = async (args: CreateApi202601MarketingSolutionsAudienceSegmentsEstimateSizeArgs, options?: CreateApi202601MarketingSolutionsAudienceSegmentsEstimateSizeOptions) => { const {baseUrl = "https://api.criteo.com", fetch: fetchFn = fetch, oauth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth !== undefined) headers.set('authorization', `Bearer ${oauth}`) const url = `${baseUrl.replace(/\/+$/, '')}/2026-01/marketing-solutions/audience-segments/estimate-size${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(audienceSegmentSizeEstimationV1Response, await res.json()) };