import {z} from 'zod' export type RmContactListCreateV1 = {identifierType?: ('Email' | 'UserIdentifier' | 'IdentityLink' | 'CustomerId' | 'PhoneNumber') | undefined}; export type RmEventsCreateV1 = {brandIds?: Array | undefined, categoryIds?: Array | undefined, lookbackDays: 'Last7Days' | 'Last14Days' | 'Last30Days' | 'Last45Days' | 'Last60Days' | 'Last90Days' | 'Last120Days' | 'Last150Days' | 'Last180Days', maxPrice?: number | undefined, minPrice?: number | undefined, shopperActivity: 'View' | 'Buy' | 'AddToCart'}; export type RmAudienceSegmentCreateEntityV1 = {contactList?: RmContactListCreateV1 | undefined, description?: string | undefined, events?: RmEventsCreateV1 | undefined, name: string, retailerId: string}; export type RmAudienceSegmentCreateEntityV1Resource = {attributes?: RmAudienceSegmentCreateEntityV1 | undefined, type?: string | undefined}; export type RmAudienceSegmentBulkCreateInputV1 = {data?: Array | undefined}; export type CreateApi202601RetailMediaAccountsAccountIdAudienceSegmentsCreateArgs = {'account-id': string, body: RmAudienceSegmentBulkCreateInputV1}; export type CreateApi202601RetailMediaAccountsAccountIdAudienceSegmentsCreateOptions = {baseUrl?: string | undefined, oauth?: string | undefined, fetch?: typeof fetch | undefined}; export const rmContactListV1 = z.object({identifierType: z.enum(["Unknown", "Email", "UserIdentifier", "IdentityLink", "CustomerId", "PhoneNumber"]).nullable().optional(), isReadOnly: z.boolean().nullable().optional(), sharingStatus: z.enum(["Unknown", "NotShared", "SharedWithAll", "SharedWithDemandAccounts"]).nullable().optional()}).nullable(); export const rmEventsV1 = z.object({brandIds: z.array(z.string()).nullable().optional(), categoryIds: z.array(z.string()).nullable().optional(), lookbackDays: z.enum(["Unknown", "Last7Days", "Last14Days", "Last30Days", "Last45Days", "Last60Days", "Last90Days", "Last120Days", "Last150Days", "Last180Days"]).nullable().optional(), maxPrice: z.number().nullable().optional(), minPrice: z.number().nullable().optional(), shopperActivity: z.enum(["Unknown", "View", "Buy", "AddToCart"]).nullable().optional()}).nullable(); export const rmAudienceSegmentEntityV1 = z.object({accountId: z.string().nullable().optional(), channels: z.array(z.enum(["Unknown", "Onsite", "Offsite"])).nullable().optional(), contactList: rmContactListV1.optional(), createdAt: z.string().nullable().optional(), createdById: z.string().nullable().optional(), description: z.string().nullable().optional(), events: rmEventsV1.optional(), name: z.string().nullable().optional(), retailerId: z.string().nullable().optional(), type: z.enum(["Unknown", "ContactList", "Events"]).nullable().optional(), updatedAt: z.string().nullable().optional()}).nullable(); export const rmAudienceSegmentEntityV1Resource = z.object({attributes: rmAudienceSegmentEntityV1.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 rmAudienceSegmentEntityV1ListResponse = z.object({data: z.array(rmAudienceSegmentEntityV1Resource).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/retail-media/accounts/{account-id}/audience-segments/create * * POST /2026-01/retail-media/accounts/{account-id}/audience-segments/create */ export const createApi202601RetailMediaAccountsAccountIdAudienceSegmentsCreate = async (args: CreateApi202601RetailMediaAccountsAccountIdAudienceSegmentsCreateArgs, options?: CreateApi202601RetailMediaAccountsAccountIdAudienceSegmentsCreateOptions) => { 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']))}/audience-segments/create${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(rmAudienceSegmentEntityV1ListResponse, await res.json()) };