import {z} from 'zod' export type NillableString = {value?: (string | null) | undefined} | null; export type NillableGenderV1 = {value?: ('Male' | 'Female' | null) | undefined} | null; export type InMarketUpdateV1 = {brandIds?: Array | undefined, buyingPower?: (Array<'Low' | 'Medium' | 'High' | 'VeryHigh'>) | undefined, country?: string | undefined, gender?: NillableGenderV1 | 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 LocationUpdateV1 = {pointsOfInterest?: Array | undefined, radiusInKm?: number | undefined, registryType?: 'PointOfInterest' | undefined}; export type LookalikeUpdateV1 = {targetSize?: number | undefined}; export type NillableInt32 = {value?: (number | null) | undefined} | null; export type ProspectingUpdateV1 = {daysSinceLastVisitMax?: NillableInt32 | undefined, daysSinceLastVisitMin?: NillableInt32 | undefined, usersType?: ('Prospects' | 'ProspectsOrNonBuyers') | undefined}; export type RetargetingUpdateV1 = {daysSinceLastVisitMax?: number | undefined, daysSinceLastVisitMin?: number | undefined, visitorsType?: ('All' | 'Buyers' | 'NonBuyers') | undefined}; export type AudienceSegmentUpdateEntityV1 = {description?: NillableString | undefined, inMarket?: InMarketUpdateV1 | undefined, location?: LocationUpdateV1 | undefined, lookalike?: LookalikeUpdateV1 | undefined, name?: string | undefined, prospecting?: ProspectingUpdateV1 | undefined, retargeting?: RetargetingUpdateV1 | undefined}; export type AudienceSegmentUpdateEntityV1Resource = {attributes?: AudienceSegmentUpdateEntityV1 | undefined, id?: string | undefined, type?: string | undefined}; export type AudienceSegmentBulkUpdateInputV1 = {data?: Array | undefined}; export type PatchApi202601MarketingSolutionsAudienceSegmentsArgs = {body: AudienceSegmentBulkUpdateInputV1}; export type PatchApi202601MarketingSolutionsAudienceSegmentsOptions = {baseUrl?: string | undefined, oauth?: string | undefined, fetch?: typeof fetch | undefined}; export const behavioralV1 = z.object({category: z.enum(["Unknown", "Lifestyles", "LifeEvents", "Seasonal", "BuyingPatterns"]), country: z.string().nullable().optional(), endDate: z.string().nullable().optional(), startDate: z.string().nullable().optional()}).nullable(); export const contactListV1 = z.object({isReadOnly: z.boolean().nullable().optional()}).nullable(); export const inMarketV1 = z.object({brandIds: z.array(z.string()).nullable().optional(), buyingPower: z.array(z.enum(["Unknown", "Low", "Medium", "High", "VeryHigh"])).nullable().optional(), country: z.string().nullable().optional(), gender: z.enum(["Unknown", "Male", "Female"]).nullable().optional(), interestIds: z.array(z.string()).nullable().optional(), priceRange: z.array(z.enum(["Unknown", "Low", "Medium", "High"])).nullable().optional()}).nullable(); export const pointOfInterestV1 = z.object({latitude: z.number().nullable().optional(), longitude: z.number().nullable().optional(), name: z.string().nullable().optional()}); export const locationV1 = z.object({pointsOfInterest: z.array(pointOfInterestV1).nullable().optional(), radiusInKm: z.number().int().nullable().optional(), registryType: z.enum(["Unknown", "PointOfInterest"]).nullable().optional()}).nullable(); export const lookalikeV1 = z.object({seedSegmentId: z.string().nullable().optional(), targetSize: z.number().int().nullable().optional()}).nullable(); export const prospectingV1 = z.object({daysSinceLastVisitMax: z.number().int().nullable().optional(), daysSinceLastVisitMin: z.number().int().nullable().optional(), usersType: z.enum(["Unknown", "Prospects", "ProspectsOrNonBuyers"]).nullable().optional()}).nullable(); export const retargetingV1 = z.object({daysSinceLastVisitMax: z.number().int().nullable().optional(), daysSinceLastVisitMin: z.number().int().nullable().optional(), visitorsType: z.enum(["Unknown", "All", "Buyers", "NonBuyers"]).nullable().optional()}).nullable(); export const audienceSegmentEntityV1 = z.object({advertiserId: z.string().nullable().optional(), behavioral: behavioralV1.optional(), contactList: contactListV1.optional(), createdAt: z.string().nullable().optional(), description: z.string().nullable().optional(), inMarket: inMarketV1.optional(), location: locationV1.optional(), lookalike: lookalikeV1.optional(), name: z.string().nullable().optional(), prospecting: prospectingV1.optional(), retargeting: retargetingV1.optional(), type: z.enum(["Unknown", "InMarket", "Prospecting", "ContactList", "Location", "Behavioral", "Retargeting", "Lookalike"]).nullable().optional(), updatedAt: z.string().nullable().optional()}).nullable(); export const audienceSegmentEntityV1Resource = z.object({attributes: audienceSegmentEntityV1.optional(), id: z.string().nullable().optional(), type: z.string().nullable().optional()}); 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 audienceSegmentEntityV1ListResponse = z.object({data: z.array(audienceSegmentEntityV1Resource).nullable().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 * * PATCH /2026-01/marketing-solutions/audience-segments */ export const patchApi202601MarketingSolutionsAudienceSegments = async (args: PatchApi202601MarketingSolutionsAudienceSegmentsArgs, options?: PatchApi202601MarketingSolutionsAudienceSegmentsOptions) => { 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${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(audienceSegmentEntityV1ListResponse, await res.json()) };