import {z} from 'zod' export type AlgebraNodeV1 = {and?: (Array | null) | undefined, audienceSegmentId?: (string | null) | undefined, not?: AlgebraNodeV1 | undefined, or?: (Array | null) | undefined} | null; export type NillableString = {value?: (string | null) | undefined} | null; export type AudienceUpdateEntityV1 = {algebra?: AlgebraNodeV1 | undefined, description?: NillableString | undefined, name?: string | undefined}; export type AudienceUpdateEntityV1Resource = {attributes?: AudienceUpdateEntityV1 | undefined, id?: string | undefined, type?: string | undefined}; export type AudienceBulkUpdateInputV1 = {data?: Array | undefined}; export type PatchApi202601MarketingSolutionsAudiencesArgs = {body: AudienceBulkUpdateInputV1}; export type PatchApi202601MarketingSolutionsAudiencesOptions = {baseUrl?: string | undefined, oauth?: string | undefined, fetch?: typeof fetch | undefined}; export const algebraNodeV1: z.ZodType = z.object({and: z.array(z.lazy(() => algebraNodeV1)).nullable().optional(), audienceSegmentId: z.string().nullable().optional(), not: z.lazy(() => algebraNodeV1.optional()), or: z.array(z.lazy(() => algebraNodeV1)).nullable().optional()}).nullable(); export const audienceEntityV1 = z.object({adSetIds: z.array(z.string()).nullable().optional(), advertiserId: z.string().nullable().optional(), algebra: algebraNodeV1.optional(), createdAt: z.string().nullable().optional(), description: z.string().nullable().optional(), name: z.string().nullable().optional(), updatedAt: z.string().nullable().optional()}).nullable(); export const audienceEntityV1Resource = z.object({attributes: audienceEntityV1.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 audienceEntityV1ListResponse = z.object({data: z.array(audienceEntityV1Resource).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/audiences * * PATCH /2026-01/marketing-solutions/audiences */ export const patchApi202601MarketingSolutionsAudiences = async (args: PatchApi202601MarketingSolutionsAudiencesArgs, options?: PatchApi202601MarketingSolutionsAudiencesOptions) => { 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/audiences${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(audienceEntityV1ListResponse, await res.json()) };