import {z} from 'zod' export type NumericTargetingDimension = {excludedIds?: Array | undefined, includedIds?: Array | undefined}; export type StringTargetingDimension = {targetingMode?: ('TARGETING_MODE_UNSPECIFIED' | 'INCLUSIVE' | 'EXCLUSIVE') | undefined, values?: Array | undefined}; export type AppTargeting = {mobileAppCategoryTargeting?: NumericTargetingDimension | undefined, mobileAppTargeting?: StringTargetingDimension | undefined}; export type CreativeDimensions = {height?: unknown | undefined, width?: unknown | undefined}; export type PretargetingConfig = {allowedUserTargetingModes?: (Array<'USER_TARGETING_MODE_UNSPECIFIED' | 'REMARKETING_ADS' | 'INTEREST_BASED_TARGETING'>) | undefined, appTargeting?: AppTargeting | undefined, billingId?: unknown | undefined, displayName?: string | undefined, excludedContentLabelIds?: Array | undefined, geoTargeting?: NumericTargetingDimension | undefined, includedCreativeDimensions?: Array | undefined, includedEnvironments?: (Array<'ENVIRONMENT_UNSPECIFIED' | 'APP' | 'WEB'>) | undefined, includedFormats?: (Array<'CREATIVE_FORMAT_UNSPECIFIED' | 'HTML' | 'VAST' | 'NATIVE'>) | undefined, includedLanguages?: Array | undefined, includedMobileOperatingSystemIds?: Array | undefined, includedPlatforms?: (Array<'PLATFORM_UNSPECIFIED' | 'PERSONAL_COMPUTER' | 'PHONE' | 'TABLET' | 'CONNECTED_TV'>) | undefined, includedUserIdTypes?: (Array<'USER_ID_TYPE_UNSPECIFIED' | 'HOSTED_MATCH_DATA' | 'GOOGLE_COOKIE' | 'DEVICE_ID' | 'PUBLISHER_PROVIDED_ID' | 'PUBLISHER_FIRST_PARTY_ID'>) | undefined, interstitialTargeting?: ('INTERSTITIAL_TARGETING_UNSPECIFIED' | 'ONLY_INTERSTITIAL_REQUESTS' | 'ONLY_NON_INTERSTITIAL_REQUESTS') | undefined, invalidGeoIds?: Array | undefined, maximumQps?: unknown | undefined, minimumViewabilityDecile?: number | undefined, name?: string | undefined, publisherTargeting?: StringTargetingDimension | undefined, state?: ('STATE_UNSPECIFIED' | 'ACTIVE' | 'SUSPENDED') | undefined, userListTargeting?: NumericTargetingDimension | undefined, verticalTargeting?: NumericTargetingDimension | undefined, webTargeting?: StringTargetingDimension | undefined}; export type CreateApiV1BiddersBiddersIdPretargetingConfigsArgs = {biddersId: string, body: PretargetingConfig}; export type CreateApiV1BiddersBiddersIdPretargetingConfigsOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const numericTargetingDimension = z.object({excludedIds: z.array(z.string()).optional(), includedIds: z.array(z.string()).optional()}); export const stringTargetingDimension = z.object({targetingMode: z.enum(["TARGETING_MODE_UNSPECIFIED", "INCLUSIVE", "EXCLUSIVE"]).optional(), values: z.array(z.string()).optional()}); export const appTargeting = z.object({mobileAppCategoryTargeting: numericTargetingDimension.optional(), mobileAppTargeting: stringTargetingDimension.optional()}); export const creativeDimensions = z.object({height: z.string().optional(), width: z.string().optional()}); export const pretargetingConfig = z.object({allowedUserTargetingModes: z.array(z.enum(["USER_TARGETING_MODE_UNSPECIFIED", "REMARKETING_ADS", "INTEREST_BASED_TARGETING"])).optional(), appTargeting: appTargeting.optional(), billingId: z.string().optional(), displayName: z.string().optional(), excludedContentLabelIds: z.array(z.string()).optional(), geoTargeting: numericTargetingDimension.optional(), includedCreativeDimensions: z.array(creativeDimensions).optional(), includedEnvironments: z.array(z.enum(["ENVIRONMENT_UNSPECIFIED", "APP", "WEB"])).optional(), includedFormats: z.array(z.enum(["CREATIVE_FORMAT_UNSPECIFIED", "HTML", "VAST", "NATIVE"])).optional(), includedLanguages: z.array(z.string()).optional(), includedMobileOperatingSystemIds: z.array(z.string()).optional(), includedPlatforms: z.array(z.enum(["PLATFORM_UNSPECIFIED", "PERSONAL_COMPUTER", "PHONE", "TABLET", "CONNECTED_TV"])).optional(), includedUserIdTypes: z.array(z.enum(["USER_ID_TYPE_UNSPECIFIED", "HOSTED_MATCH_DATA", "GOOGLE_COOKIE", "DEVICE_ID", "PUBLISHER_PROVIDED_ID", "PUBLISHER_FIRST_PARTY_ID"])).optional(), interstitialTargeting: z.enum(["INTERSTITIAL_TARGETING_UNSPECIFIED", "ONLY_INTERSTITIAL_REQUESTS", "ONLY_NON_INTERSTITIAL_REQUESTS"]).optional(), invalidGeoIds: z.array(z.string()).optional(), maximumQps: z.string().optional(), minimumViewabilityDecile: z.number().int().optional(), name: z.string().optional(), publisherTargeting: stringTargetingDimension.optional(), state: z.enum(["STATE_UNSPECIFIED", "ACTIVE", "SUSPENDED"]).optional(), userListTargeting: numericTargetingDimension.optional(), verticalTargeting: numericTargetingDimension.optional(), webTargeting: stringTargetingDimension.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 }; /** * Creates a pretargeting configuration. A pretargeting configuration's state (PretargetingConfig.state) is active upon creation, and it will start to affect traffic shortly after. A bidder may create a maximum of 10 pretargeting configurations. Attempts to exceed this maximum results in a 400 bad request error. * * POST /v1/bidders/{biddersId}/pretargetingConfigs */ export const createApiV1BiddersBiddersIdPretargetingConfigs = async (args: CreateApiV1BiddersBiddersIdPretargetingConfigsArgs, options?: CreateApiV1BiddersBiddersIdPretargetingConfigsOptions) => { const {baseUrl = "https://realtimebidding.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/bidders/${encodeURIComponent(String(args.biddersId))}/pretargetingConfigs${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(pretargetingConfig, await res.json()) };