import {z} from 'zod' export type AdaptiveColors = {backgroundColor: string, ctaBackgroundColor: string, ctaTextColor: string, logoAreaAndTitleColor: string, text1Color: string, text2Color: string} | null; export type ImageSetBase64 = {headlineText?: (string | null) | undefined, imageBase64Strings: Array}; export type AdaptiveWriteAttributes = {callsToAction: Array, colors: AdaptiveColors, descriptionFont: string, descriptionText: string, headlineFont: string, headlineText: string, imageDisplay?: ('ShowFullImage' | 'ZoomOnImage' | null) | undefined, imageSetsBase64?: (Array | null) | undefined, landingPageUrl: string, layouts: Array<'Editorial' | 'Montage' | 'InBannerVideo'>, logoBase64String: string, videoBase64Strings?: (Array | null) | undefined}; export type DynamicWriteAttributes = {bodyTextColor: string, callsToAction: Array, creativeBackgroundColor?: (string | null) | undefined, logoBase64String: string, pricesColor: string, primaryFont?: (string | null) | undefined, productImageDisplay: 'ShowFullImage' | 'ZoomOnImage'}; export type Size = {height?: (number | null) | undefined, width?: (number | null) | undefined} | null; export type Tag = {htmlTag?: (string | null) | undefined, size?: Size | undefined}; export type HtmlTagWriteAttributes = {tags: Array}; export type ImageWriteAttributes = {base64Strings: Array, landingPageUrl: string}; export type CreativeWrite = {adaptiveWriteAttributes?: AdaptiveWriteAttributes | undefined, datasetId: string, description?: (string | null) | undefined, dynamicWriteAttributes?: DynamicWriteAttributes | undefined, format: 'Image' | 'HtmlTag' | 'Dynamic' | 'Adaptive', htmlTagWriteAttributes?: HtmlTagWriteAttributes | undefined, imageWriteAttributes?: ImageWriteAttributes | undefined, name: string}; export type ResourceOfCreativeWrite = {attributes?: CreativeWrite | undefined, id?: (string | null) | undefined, type?: (string | null) | undefined}; export type ResourceInputOfCreativeWrite = {data?: ResourceOfCreativeWrite | undefined}; export type UpdateApi202601MarketingSolutionsCreativesIdArgs = {id: string, body: ResourceInputOfCreativeWrite}; export type UpdateApi202601MarketingSolutionsCreativesIdOptions = {baseUrl?: string | undefined, oauth?: string | undefined, fetch?: typeof fetch | undefined}; export const adaptiveColors = z.object({backgroundColor: z.string(), ctaBackgroundColor: z.string(), ctaTextColor: z.string(), logoAreaAndTitleColor: z.string(), text1Color: z.string(), text2Color: z.string()}).nullable(); export const imageShape = z.object({shape: z.enum(["Horizontal", "Vertical", "Square"]), url: z.string()}); export const imageSet = z.object({headlineText: z.string().nullable().optional(), images: z.array(imageShape)}); export const videoDetail = z.object({duration: z.number(), shape: z.enum(["Horizontal", "Vertical", "Square"]), url: z.string()}); export const adaptiveAttributes = z.object({callsToAction: z.array(z.string()), colors: adaptiveColors, descriptionFont: z.string(), descriptionText: z.string(), headlineFont: z.string(), headlineText: z.string(), imageDisplay: z.enum(["ShowFullImage", "ZoomOnImage"]).nullable().optional(), imageSets: z.array(imageSet).nullable().optional(), landingPageUrl: z.string(), layouts: z.array(z.enum(["Editorial", "Montage", "InBannerVideo"])), logos: z.array(imageShape), videos: z.array(videoDetail).nullable().optional()}).nullable(); export const dynamicAttributes = z.object({bodyTextColor: z.string().nullable().optional(), callsToAction: z.array(z.string()).nullable().optional(), creativeBackgroundColor: z.string().nullable().optional(), logos: z.array(imageShape).nullable().optional(), pricesColor: z.string().nullable().optional(), primaryFont: z.string().nullable().optional(), productImageDisplay: z.enum(["ShowFullImage", "ZoomOnImage"]).nullable().optional()}).nullable(); export const size = z.object({height: z.number().int().nullable().optional(), width: z.number().int().nullable().optional()}).nullable(); export const tag = z.object({htmlTag: z.string().nullable().optional(), size: size.optional()}); export const htmlTagAttributes = z.object({tags: z.array(tag).nullable().optional()}).nullable(); export const imageAttributes = z.object({landingPageUrl: z.string().nullable().optional(), urls: z.array(z.string()).nullable().optional()}).nullable(); export const creative = z.object({adaptiveAttributes: adaptiveAttributes.optional(), advertiserId: z.string(), author: z.string(), datasetId: z.string().nullable().optional(), description: z.string().nullable().optional(), dynamicAttributes: dynamicAttributes.optional(), format: z.string().nullable().optional(), htmlTagAttributes: htmlTagAttributes.optional(), id: z.string().nullable().optional(), imageAttributes: imageAttributes.optional(), name: z.string(), status: z.string()}).nullable(); export const resourceOfCreative = z.object({attributes: creative.optional(), id: z.string().nullable().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 resourceOutcomeOfCreative = z.object({data: resourceOfCreative.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/creatives/{id} * * PUT /2026-01/marketing-solutions/creatives/{id} */ export const updateApi202601MarketingSolutionsCreativesId = async (args: UpdateApi202601MarketingSolutionsCreativesIdArgs, options?: UpdateApi202601MarketingSolutionsCreativesIdOptions) => { 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/creatives/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(resourceOutcomeOfCreative, await res.json()) };