import {z} from 'zod' export type ContactlistAmendment = {attributes: {gumCallerId?: number | undefined, identifiers: Array, identifierType?: ('email' | 'madid' | 'identityLink' | 'gum' | 'phoneNumber') | undefined, operation: 'add' | 'remove'}, type: string}; export type ContactlistAmendmentRequest = {data: ContactlistAmendment}; export type PatchApi202601MarketingSolutionsAudienceSegmentsAudienceSegmentIdContactListArgs = {body: ContactlistAmendmentRequest}; export type PatchApi202601MarketingSolutionsAudienceSegmentsAudienceSegmentIdContactListOptions = {baseUrl?: string | undefined, oauth?: string | undefined, fetch?: typeof fetch | undefined}; export const contactlistOperation = z.object({attributes: z.object({contactListId: z.number().int().nullable().optional(), identifierType: z.string().nullable().optional(), nbInvalidIdentifiers: z.number().int().nullable().optional(), nbValidIdentifiers: z.number().int().nullable().optional(), operation: z.string(), requestDate: z.string().nullable().optional(), sampleInvalidIdentifiers: z.array(z.string()).nullable().optional()}), type: z.string()}); export const audienceError = z.object({code: z.string(), detail: z.string().nullable().optional(), instance: z.string(), source: z.object({}).nullable().optional(), stackTrace: z.array(z.string()).nullable().optional(), title: z.string().nullable().optional(), traceId: z.string().nullable().optional(), type: z.enum(["access-control", "authentication", "authorization", "availability", "deprecation", "quota", "validation"])}); export const audienceWarning = z.object({code: z.string(), detail: z.string(), instance: z.string(), source: z.object({}).nullable().optional(), stackTrace: z.array(z.string()).nullable().optional(), title: z.string().nullable().optional(), traceId: z.string().nullable().optional(), type: z.enum(["access-control", "authentication", "authorization", "availability", "deprecation", "quota", "validation"])}); export const modifyAudienceResponse = z.object({data: contactlistOperation, errors: z.array(audienceError), warnings: z.array(audienceWarning)}); 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/{audience-segment-id}/contact-list * * PATCH /2026-01/marketing-solutions/audience-segments/{audience-segment-id}/contact-list */ export const patchApi202601MarketingSolutionsAudienceSegmentsAudienceSegmentIdContactList = async (args: PatchApi202601MarketingSolutionsAudienceSegmentsAudienceSegmentIdContactListArgs, options?: PatchApi202601MarketingSolutionsAudienceSegmentsAudienceSegmentIdContactListOptions) => { 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/${encodeURIComponent(String(args['audience-segment-id']))}/contact-list${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(modifyAudienceResponse, await res.json()) };