import {z} from 'zod' export type ProductSetRule = {field?: ('OBSOLETE_Extradata' | 'Category1' | 'Category2' | 'Category3' | 'ExternalItemId' | 'SalePrice' | 'Brand' | 'CustomLabel0' | 'CustomLabel1' | 'CustomLabel2' | 'CustomLabel3' | 'CustomLabel4' | null) | undefined, operator?: ('IsIn' | 'IsNotIn' | 'Between' | 'NotBetween' | 'LessThan' | 'GreaterThan' | null) | undefined, values?: (Array | null) | undefined}; export type PatchProductSetRequest = {isDraft?: (boolean | null) | undefined, minimumNumberOfProducts?: (number | null) | undefined, name?: string | undefined, rules?: Array | undefined}; export type ValueResourceOfPatchProductSetRequest = {attributes?: PatchProductSetRequest | undefined, type?: string | undefined}; export type ValueResourceInputOfPatchProductSetRequest = {data?: ValueResourceOfPatchProductSetRequest | undefined}; export type PatchApi202601MarketingSolutionsProductSetsProductSetIdArgs = {'product-set-id': string, body: ValueResourceInputOfPatchProductSetRequest}; export type PatchApi202601MarketingSolutionsProductSetsProductSetIdOptions = {baseUrl?: string | undefined, oauth?: string | undefined, fetch?: typeof fetch | undefined}; export const productSetRule = z.object({field: z.enum(["OBSOLETE_Extradata", "Category1", "Category2", "Category3", "ExternalItemId", "SalePrice", "Brand", "CustomLabel0", "CustomLabel1", "CustomLabel2", "CustomLabel3", "CustomLabel4"]).nullable().optional(), operator: z.enum(["IsIn", "IsNotIn", "Between", "NotBetween", "LessThan", "GreaterThan"]).nullable().optional(), values: z.array(z.string()).nullable().optional()}); export const productSet = z.object({clientType: z.enum(["Unknown", "CGrowth", "CMax"]), creationDate: z.string(), datasetId: z.string(), id: z.string().nullable().optional(), isFallbackAllowed: z.boolean().optional(), keepVariantProducts: z.boolean(), minimumNumberOfProducts: z.number().int(), name: z.string(), numberOfProducts: z.number().int().nullable(), rules: z.array(productSetRule), status: z.enum(["Unknown", "Draft", "Pending", "Valid", "Invalid", "Deleted"])}).nullable(); export const resourceOfProductSet = z.object({attributes: productSet.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 resourceOutcomeOfProductSet = z.object({data: resourceOfProductSet.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/product-sets/{product-set-id} * * PATCH /2026-01/marketing-solutions/product-sets/{product-set-id} */ export const patchApi202601MarketingSolutionsProductSetsProductSetId = async (args: PatchApi202601MarketingSolutionsProductSetsProductSetIdArgs, options?: PatchApi202601MarketingSolutionsProductSetsProductSetIdOptions) => { 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/product-sets/${encodeURIComponent(String(args['product-set-id']))}${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(resourceOutcomeOfProductSet, await res.json()) };