import {z} from 'zod' export type AsyncLineItemsReport = {activationPlatforms?: (Array<'CommerceMax' | 'PrivateMarket'>) | undefined, budgetModels?: (Array<'CriteoBudget' | 'RetailerBudget'>) | undefined, buyTypes?: (Array<'auction' | 'preferredDeals' | 'sponsorship'>) | undefined, campaignType?: ('all' | 'sponsoredProducts' | 'onSiteDisplays') | undefined, clickAttributionWindow?: ('none' | '7D' | '14D' | '30D') | undefined, dimensions?: (Array<'date' | 'hour' | 'accountId' | 'accountName' | 'campaignId' | 'campaignName' | 'campaignTypeName' | 'lineItemId' | 'lineItemName' | 'retailerId' | 'retailerName' | 'brandId' | 'brandName' | 'advProductCategory' | 'advProductId' | 'advProductName' | 'salesChannel' | 'mediaType' | 'buyType' | 'budgetModel' | 'activationPlatform' | 'environment' | 'pageTypeName' | 'pageCategory' | 'servedCategory' | 'taxonomyBreadcrumb' | 'keyword' | 'searchTerm' | 'searchTermType' | 'searchTermTargeting' | 'creativeId' | 'creativeName' | 'creativeTypeId' | 'creativeTypeName' | 'creativeTemplateId' | 'creativeTemplateName' | 'targetedKeywordType'>) | undefined, endDate: string, format?: ('json' | 'json-compact' | 'json-newline' | 'csv') | undefined, id?: string | undefined, ids?: Array | undefined, mediaType?: ('unknown' | 'video' | 'display' | 'all') | undefined, metrics?: (Array<'impressions' | 'clicks' | 'spend' | 'attributedSales' | 'attributedUnits' | 'attributedOrders' | 'assistedSales' | 'assistedUnits' | 'ctr' | 'cpc' | 'cpo' | 'cpm' | 'roas' | 'videoViews' | 'videosStarted' | 'videosPlayedTo25' | 'videosPlayedTo50' | 'videosPlayedTo75' | 'videosPlayedTo100' | 'videoPlayingRate' | 'videoCompletionRate' | 'videoImpressions' | 'videoMuted' | 'videoUnmuted' | 'videoPaused' | 'videoResumed' | 'videoAvgInteractionRate' | 'videoViewability' | 'videoStartingRate' | 'videoCPC' | 'videoCPCV' | 'newToBrandAttributedSales' | 'newToBrandAttributedSalesRate' | 'newToBrandAttributedUnits' | 'newToBrandAttributedUnitsRate' | 'uniqueVisitors' | 'frequency' | 'winRate' | 'sampledBidsWon' | 'sampledBidsParticipated'>) | undefined, reportType?: ('summary' | 'pageType' | 'keyword' | 'productCategory' | 'product' | 'attributedTransactions' | 'environment' | 'servedCategory' | 'capout') | undefined, salesChannel?: ('online' | 'offline' | 'all') | undefined, searchTermTargetings?: (Array<'unknown' | 'automatic' | 'manual'>) | undefined, searchTermTypes?: (Array<'unknown' | 'searched' | 'entered'>) | undefined, startDate: string, targetedKeywordTypes?: (Array<'unknown' | 'generic' | 'branded' | 'conquesting'>) | undefined, timezone?: string | undefined, viewAttributionWindow?: ('none' | '1D' | '7D' | '14D' | '30D') | undefined}; export type AsyncLineItemsReportResource = {attributes?: AsyncLineItemsReport | undefined, type?: string | undefined}; export type AsyncLineItemsReportRequest = {data?: AsyncLineItemsReportResource | undefined}; export type CreateApi202601RetailMediaReportsLineItemsArgs = {body: AsyncLineItemsReportRequest}; export type CreateApi202601RetailMediaReportsLineItemsOptions = {baseUrl?: string | undefined, oauth?: string | undefined, fetch?: typeof fetch | undefined}; export const statusResponse = z.object({createdAt: z.string().nullable().optional(), expiresAt: z.string().nullable().optional(), fileSizeBytes: z.number().int().nullable().optional(), id: z.string().nullable().optional(), md5CheckSum: z.string().nullable().optional(), message: z.string().nullable().optional(), rowCount: z.number().int().nullable().optional(), status: z.enum(["pending", "success", "failure", "expired"]).nullable().optional()}).nullable(); export const statusResponseResource = z.object({attributes: statusResponse.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 asyncReportResponse = z.object({data: statusResponseResource.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/reports/line-items * * POST /2026-01/retail-media/reports/line-items */ export const createApi202601RetailMediaReportsLineItems = async (args: CreateApi202601RetailMediaReportsLineItemsArgs, options?: CreateApi202601RetailMediaReportsLineItemsOptions) => { 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/reports/line-items${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(asyncReportResponse, await res.json()) };