import {z} from 'zod' export type StatisticsReportQueryMessage = {adSetIds?: (Array | null) | undefined, adSetNames?: (Array | null) | undefined, adSetStatus?: (Array<'Active' | 'NotRunning' | 'Dead'> | null) | undefined, advertiserIds: string, currency: string, dimensions: Array<'AdsetId' | 'Adset' | 'AdvertiserId' | 'Advertiser' | 'CategoryId' | 'Category' | 'Hour' | 'Day' | 'Week' | 'Month' | 'Year' | 'Os' | 'Device' | 'CampaignId' | 'Campaign' | 'AdId' | 'Ad' | 'CouponId' | 'Coupon' | 'MarketingObjectiveId' | 'MarketingObjective' | 'ChannelId' | 'Channel' | 'Goal' | 'AdChannel' | 'SocialPlatform'>, endDate: string, format?: ('csv' | 'excel' | 'xml' | 'json') | undefined, metrics: Array<'Clicks' | 'Displays' | 'AdvertiserCost' | 'SalesPc30dClientAttribution' | 'SalesClientAttribution' | 'SalesPc30d' | 'SalesAllPc30dClientAttribution' | 'SalesAllClientAttribution' | 'SalesAllPc30d' | 'SalesPv24h' | 'SalesAllPv24h' | 'SalesPc30Pv24' | 'SalesAllPc30Pv24' | 'SalesPc30dPv24h' | 'SalesAllPc30dPv24h' | 'SalesPc7dPv24' | 'SalesAllPc7dPv24' | 'SalesLc' | 'SalesAllLc' | 'SalesPc7d' | 'SalesAllPc7d' | 'SalesPc1d' | 'SalesAllPc1d' | 'SalesPiPc' | 'SalesPiPv' | 'SalesPiPcPv' | 'PostInstallSales' | 'SalesOfflinePc' | 'SalesOfflinePv' | 'SalesOfflinePc30d' | 'SalesOfflinePv24h' | 'RevenueGeneratedPc30dClientAttribution' | 'RevenueGeneratedClientAttribution' | 'RevenueGeneratedPc30d' | 'RevenueGeneratedAllPc30dClientAttribution' | 'RevenueGeneratedAllClientAttribution' | 'RevenueGeneratedAllPc30d' | 'RevenueGeneratedPv24h' | 'RevenueGeneratedAllPv24h' | 'RevenueGeneratedPc30Pv24' | 'RevenueGeneratedAllPc30Pv24' | 'RevenueGeneratedPc30dPv24h' | 'RevenueGeneratedAllPc30dPv24h' | 'RevenueGeneratedPc7dPv24' | 'RevenueGeneratedAllPc7dPv24' | 'RevenueGeneratedLc' | 'RevenueGeneratedAllLc' | 'RevenueGeneratedPc7d' | 'RevenueGeneratedAllPc7d' | 'RevenueGeneratedPc1d' | 'RevenueGeneratedAllPc1d' | 'RevenueGeneratedOfflinePc' | 'RevenueGeneratedOfflinePv' | 'RevenueGeneratedOfflinePc30d' | 'RevenueGeneratedOfflinePv24h' | 'ConversionRatePc30dClientAttribution' | 'ConversionRateClientAttribution' | 'ConversionRatePc30d' | 'ConversionRateAllPc30dClientAttribution' | 'ConversionRateAllClientAttribution' | 'ConversionRateAllPc30d' | 'ConversionRatePv24h' | 'ConversionRateAllPv24h' | 'ConversionRatePc30Pv24' | 'ConversionRateAllPc30Pv24' | 'ConversionRatePc30dPv24h' | 'ConversionRateAllPc30dPv24h' | 'ConversionRatePc7dPv24' | 'ConversionRateAllPc7dPv24' | 'ConversionRatePc7d' | 'ConversionRateAllPc7d' | 'ConversionRatePc1d' | 'ConversionRateAllPc1d' | 'ConversionRatePiPcPv' | 'PostInstallConversionRate' | 'ECosPc30dClientAttribution' | 'ECosClientAttribution' | 'ECosPc30d' | 'ECosAllPc30dClientAttribution' | 'ECosAllClientAttribution' | 'ECosAllPc30d' | 'ECosPv24h' | 'ECosAllPv24h' | 'ECosPc30Pv24' | 'ECosAllPc30Pv24' | 'ECosPc30dPv24h' | 'ECosAllPc30dPv24h' | 'ECosPc7dPv24' | 'ECosAllPc7dPv24' | 'ECosPc7d' | 'ECosAllPc7d' | 'ECosPc1d' | 'ECosAllPc1d' | 'CostPerOrderPc30dClientAttribution' | 'CostPerOrderClientAttribution' | 'CostPerOrderPc30d' | 'CostPerOrderAllPc30dClientAttribution' | 'CostPerOrderAllClientAttribution' | 'CostPerOrderAllPc30d' | 'CostPerOrderPv24h' | 'CostPerOrderAllPv24h' | 'CostPerOrderPc30Pv24' | 'CostPerOrderAllPc30Pv24' | 'CostPerOrderPc30dPv24h' | 'CostPerOrderAllPc30dPv24h' | 'CostPerOrderPc7dPv24' | 'CostPerOrderAllPc7dPv24' | 'CostPerOrderPc7d' | 'CostPerOrderAllPc7d' | 'CostPerOrderPc1d' | 'CostPerOrderAllPc1d' | 'ExposedUsers' | 'Audience' | 'Reach' | 'AverageCartPc30dClientAttribution' | 'AverageCartAllPc30dClientAttribution' | 'AverageCartClientAttribution' | 'AverageCartAllClientAttribution' | 'AverageCartPc30d' | 'AverageCartAllPc30d' | 'AverageCartPv24h' | 'AverageCartAllPv24h' | 'AverageCartPc1d' | 'AverageCartAllPc1d' | 'AverageCartPc7d' | 'AverageCartAllPc7d' | 'AverageCartPc30Pv24' | 'AverageCartAllPc30Pv24' | 'AverageCartPc30dPv24h' | 'AverageCartAllPc30dPv24h' | 'AverageCartPc7dPv24' | 'AverageCartAllPc7dPv24' | 'ClickThroughRate' | 'ECpc' | 'Cpc' | 'ECpm' | 'ReturnOnAdvertisingSpendingClientAttribution' | 'ReturnOnAdvertisingSpendingAllClientAttribution' | 'AdvertiserValue' | 'AdvertiserAllValue' | 'CostOfAdvertiserValue' | 'CostOfAdvertiserValueAll' | 'AppInstallsPcPv' | 'AppInstalls' | 'QualifiedVisits' | 'Visits' | 'VisitsPV1D' | 'VisitsAllPv1d' | 'OrderValuePi' | 'PostInstallOrderValue' | 'BounceRate' | 'CostPerInstallPcPv' | 'CostPerInstall' | 'CostPerVisit' | 'CostPerVisitPV1D' | 'CostPerQualifiedVisit' | 'InstallRatePcPv' | 'InstallRate' | 'OmnichannelRoasPc30d' | 'OmnichannelRoasAllPc30d' | 'OmnichannelRevenuePc30d' | 'OmnichannelRevenueAllPc30d' | 'OmnichannelSalesPc30d' | 'OmnichannelSalesAllPc30d' | 'OmnichannelRoasAllPv24h' | 'OmnichannelRoasPv24h' | 'OmnichannelRevenueAllPv24h' | 'OmnichannelRevenuePv24h' | 'OmnichannelSalesAllPv24h' | 'OmnichannelSalesPv24h' | 'OmnichannelRoasClientAttribution' | 'OmnichannelRevenueClientAttribution' | 'OmnichannelSalesClientAttribution' | 'RoasAllPc30dClientAttribution' | 'RoasPc30dClientAttribution' | 'RoasAllClientAttribution' | 'RoasClientAttribution' | 'RoasAllPc30d' | 'RoasPc30d' | 'RoasAllPc7d' | 'RoasPc7d' | 'RoasAllPc1d' | 'RoasPc1d' | 'RoasAllPv24h' | 'RoasPv24h' | 'RoasPc30Pv24' | 'RoasAllPc30Pv24' | 'RoasPc30dPv24h' | 'RoasAllPc30dPv24h' | 'RoasPc7dPv24' | 'RoasAllPc7dPv24' | 'CostOfSalePi' | 'CostPerOrderPi' | 'PostInstallCostOfSale' | 'PostInstallCostPerOrder' | 'ReturnOnAdvertiserSpendingPi' | 'PostInstallRoas' | 'ReturnOnAdvertiserSpendingOfflinePc' | 'ReturnOnAdvertiserSpendingOfflinePv' | 'RoasOfflinePc30d' | 'RoasOfflinePv24h' | 'PotentialDisplays' | 'OverallCompetitionWin' | 'ViewableDisplays' | 'NonViewableDisplays' | 'UntrackableDisplays' | 'Frequency' | 'InvalidDisplays' | 'InvalidClicks' | 'ResultType' | 'VideoStarted' | 'VideoFirstQuartile' | 'VideoMidpoint' | 'VideoThirdQuartile' | 'VideoCompleted' | 'VideoAvoc' | 'VideoStartRate' | 'VideoCompletionRate' | 'VideoAverageViewRate' | 'VideoCpv' | 'VideoCpcv' | 'PotentialUsers' | 'RetailerMarginEuro' | 'PlatformFeeEuro' | 'AllInMediaCost' | 'NetMediaCost' | 'Cos'>, startDate: string, timezone?: (string | null) | undefined}; export type CreateApi202601StatisticsReportArgs = {body: StatisticsReportQueryMessage}; export type CreateApi202601StatisticsReportOptions = {baseUrl?: string | undefined, oauth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApi202601StatisticsReportResponse = z.string(); 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/statistics/report * * POST /2026-01/statistics/report */ export const createApi202601StatisticsReport = async (args: CreateApi202601StatisticsReportArgs, options?: CreateApi202601StatisticsReportOptions) => { 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/statistics/report${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(createApi202601StatisticsReportResponse, await res.json()) };