import {z} from 'zod' export type BudgetAutomationConfiguration = {adSetObjectives?: ('conversions' | 'revenue' | 'visits' | 'videoViews') | undefined} | null; export type BudgetAutomation = {budgetConfiguration?: BudgetAutomationConfiguration | undefined, enabled?: boolean | undefined}; export type CreateCampaignSpendLimit = {spendLimitAmount?: (number | null) | undefined, spendLimitRenewal?: ('undefined' | 'daily' | 'monthly' | 'lifetime') | undefined, spendLimitType: 'capped' | 'uncapped'}; export type CreateCampaign = {advertiserId: string | null, budgetAutomation?: BudgetAutomation | undefined, goal: 'Unspecified' | 'Acquisition' | 'Retention', name: string | null, spendLimit: CreateCampaignSpendLimit}; export type CreateCampaignResource = {attributes?: CreateCampaign | undefined, type?: string | undefined}; export type CreateCampaignRequest = {data?: CreateCampaignResource | undefined}; export type CreateApi202601MarketingSolutionsCampaignsArgs = {body: CreateCampaignRequest}; export type CreateApi202601MarketingSolutionsCampaignsOptions = {baseUrl?: string | undefined, oauth?: string | undefined, fetch?: typeof fetch | undefined}; export const automatedBudgetConfigurationV23Q1 = z.object({adSetOptimizationObjective: z.enum(["conversions", "revenue", "visits", "videoViews"]).nullable().optional()}).nullable(); export const campaignBudgetAutomationV23Q1 = z.object({automatedBudgetConfiguration: automatedBudgetConfigurationV23Q1.optional(), enabled: z.boolean().nullable().optional()}).nullable(); export const nillableDecimal = z.object({value: z.number().nullable().optional()}).nullable(); export const campaignSpendLimitV23Q1 = z.object({spendLimitAmount: nillableDecimal.optional(), spendLimitRenewal: z.enum(["undefined", "daily", "monthly", "lifetime"]).nullable().optional(), spendLimitType: z.enum(["capped", "uncapped"]).nullable().optional()}).nullable(); export const campaignV23Q1 = z.object({advertiserId: z.string().nullable().optional(), budgetAutomation: campaignBudgetAutomationV23Q1.optional(), goal: z.enum(["unspecified", "acquisition", "retention"]).nullable().optional(), id: z.string().nullable().optional(), name: z.string().nullable().optional(), spendLimit: campaignSpendLimitV23Q1.optional()}).nullable(); export const campaignV23Q1Resource = z.object({attributes: campaignV23Q1.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 campaignV23Q1Response = z.object({data: campaignV23Q1Resource.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/marketing-solutions/campaigns * * POST /2026-01/marketing-solutions/campaigns */ export const createApi202601MarketingSolutionsCampaigns = async (args: CreateApi202601MarketingSolutionsCampaignsArgs, options?: CreateApi202601MarketingSolutionsCampaignsOptions) => { 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/campaigns${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(campaignV23Q1Response, await res.json()) };