import {z} from 'zod' export type AsyncFillRateReport = {adServerType?: ('all' | 'gam' | 'criteo') | undefined, dimensions: Array<'date' | 'retailerId' | 'retailerName' | 'placementId' | 'placementName' | 'pageTypeName' | 'environment' | 'servedCategory' | 'retailerCategoryId' | 'retailerCategoryName' | 'adServerType'>, endDate: string, format?: ('json' | 'json-compact' | 'json-newline' | 'csv') | undefined, metrics: Array<'pageViews' | 'availablePlacements' | 'unfilledPlacements' | 'fillRate' | 'placementImpressions' | 'productImpressions' | 'impressions' | 'placementClicks' | 'productClicks' | 'clicks' | 'placementImpressionsCTR' | 'productImpressionsCTR' | 'cpm' | 'cpc' | 'placementImpressionsRevenue' | 'productClicksRevenue' | 'revenue' | 'workingMedia' | 'netRevenue' | 'nonDeliverablePlacements' | 'deliverablePlacements' | 'placementsWithCandidates' | 'coveredPlacements' | 'coverageRate'>, startDate: string, supplyAccountIds: Array, timezone?: string | undefined}; export type AsyncFillRateReportResource = {attributes?: AsyncFillRateReport | undefined, type?: string | undefined}; export type AsyncFillRateReportRequest = {data?: AsyncFillRateReportResource | undefined}; export type CreateApi202601RetailMediaReportsFillrateArgs = {body: AsyncFillRateReportRequest}; export type CreateApi202601RetailMediaReportsFillrateOptions = {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/fillrate * * POST /2026-01/retail-media/reports/fillrate */ export const createApi202601RetailMediaReportsFillrate = async (args: CreateApi202601RetailMediaReportsFillrateArgs, options?: CreateApi202601RetailMediaReportsFillrateOptions) => { 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/fillrate${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()) };