import {z} from 'zod' export type ChoiceVariableValue = {chosenOptions: Array} | null; export type ColorVariableValue = {color: string | null} | null; export type FilesVariableValue = {assetIds: Array} | null; export type HyperlinkVariableValue = {url: string | null} | null; export type TextVariableValue = {text: string | null} | null; export type VideoVariableValue = {duration: string, height: number, url: string, width: number} | null; export type TemplateVariableValue = {choiceVariableValue?: ChoiceVariableValue | undefined, colorVariableValue?: ColorVariableValue | undefined, filesVariableValue?: FilesVariableValue | undefined, hyperlinkVariableValue?: HyperlinkVariableValue | undefined, id: string, textVariableValue?: TextVariableValue | undefined, videoVariableValue?: VideoVariableValue | undefined}; export type CreativeUpdateModel202207 = {brandId?: number | undefined, id?: (string | null) | undefined, name: string, retailerId: number, templateId: number, templateVariableValues: Array}; export type UpdateApi202601RetailMediaAccountsAccountIdCreativesCreativeIdArgs = {'account-id': string, 'creative-id': string, body: CreativeUpdateModel202207}; export type UpdateApi202601RetailMediaAccountsAccountIdCreativesCreativeIdOptions = {baseUrl?: string | undefined, oauth?: string | undefined, fetch?: typeof fetch | undefined}; export const pageTypeEnvironment202210 = z.object({environments: z.array(z.enum(["Web", "Mobile", "App", "Lockout", "Mixed", "iOS", "Android"])).nullable().optional(), pageType: z.enum(["Search", "Home", "Browse", "Checkout", "Category", "ProductDetail", "Confirmation", "Merchandising", "Deals"]).nullable().optional()}); export const choiceVariableValue = z.object({chosenOptions: z.array(z.string())}).nullable(); export const colorVariableValue = z.object({color: z.string().nullable()}).nullable(); export const filesVariableValue = z.object({assetIds: z.array(z.string())}).nullable(); export const hyperlinkVariableValue = z.object({url: z.string().nullable()}).nullable(); export const textVariableValue = z.object({text: z.string().nullable()}).nullable(); export const videoVariableValue = z.object({duration: z.string().min(1), height: z.number().int(), url: z.string().min(1), width: z.number().int()}).nullable(); export const templateVariableValue = z.object({choiceVariableValue: choiceVariableValue.optional(), colorVariableValue: colorVariableValue.optional(), filesVariableValue: filesVariableValue.optional(), hyperlinkVariableValue: hyperlinkVariableValue.optional(), id: z.string(), textVariableValue: textVariableValue.optional(), videoVariableValue: videoVariableValue.optional()}); export const creative202210 = z.object({associatedLineItemIds: z.array(z.string()).nullable().optional(), brandId: z.number().int().nullable().optional(), creativeFormatType: z.enum(["Unknown", "FlagShip", "Showcase", "SponsoredProducts", "Butterfly", "BundleBoost", "IAB", "CUSTOM", "DisplayPanel", "DigitalShelfTalker"]), environments: z.array(pageTypeEnvironment202210), formatId: z.number().int(), id: z.string().nullable().optional(), name: z.string(), retailerId: z.number().int(), status: z.enum(["Ready", "In_Use", "Archived", "Deleted"]), templateId: z.number().int(), templateName: z.string(), templateVariableValues: z.array(templateVariableValue), updatedAt: z.string().nullable().optional()}).nullable(); export const resourceOfCreative202210 = z.object({attributes: creative202210.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 creative202210Response = z.object({data: resourceOfCreative202210.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/retail-media/accounts/{account-id}/creatives/{creative-id} * * PUT /2026-01/retail-media/accounts/{account-id}/creatives/{creative-id} */ export const updateApi202601RetailMediaAccountsAccountIdCreativesCreativeId = async (args: UpdateApi202601RetailMediaAccountsAccountIdCreativesCreativeIdArgs, options?: UpdateApi202601RetailMediaAccountsAccountIdCreativesCreativeIdOptions) => { 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/retail-media/accounts/${encodeURIComponent(String(args['account-id']))}/creatives/${encodeURIComponent(String(args['creative-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(creative202210Response, await res.json()) };