import {z} from 'zod' export type GetApiV4AdvertisersAdvertisersIdReachForecastRetrievePlannableProductsArgs = {advertisersId: string, plannableLocationId?: string | undefined}; export type GetApiV4AdvertisersAdvertisersIdReachForecastRetrievePlannableProductsOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const plannableProductCoreAttributes = z.object({buyingMethod: z.enum(["PLANNABLE_BUYING_METHOD_UNSPECIFIED", "PLANNABLE_BUYING_METHOD_AUCTION", "PLANNABLE_BUYING_METHOD_RESERVATION"]).optional(), costModel: z.enum(["PLANNABLE_COST_MODEL_UNSPECIFIED", "PLANNABLE_COST_MODEL_CPM", "PLANNABLE_COST_MODEL_CPV", "PLANNABLE_COST_MODEL_CPC", "PLANNABLE_COST_MODEL_CPA"]).optional(), productCategory: z.enum(["PLANNABLE_PRODUCT_CATEGORY_UNSPECIFIED", "YOUTUBE", "OPEN_AUCTION"]).optional()}); export const youTubeSelectLineUp = z.object({displayName: z.string().optional(), lineupId: z.string().optional()}); export const surfaceTargetingCombination = z.object({choices: z.array(z.enum(["PLANNABLE_SURFACE_UNSPECIFIED", "PLANNABLE_SURFACE_IN_FEED", "PLANNABLE_SURFACE_IN_STREAM_BUMPER", "PLANNABLE_SURFACE_IN_STREAM_NON_SKIPPABLE", "PLANNABLE_SURFACE_IN_STREAM_SKIPPABLE", "PLANNABLE_SURFACE_SHORTS", "PLANNABLE_SURFACE_DISCOVER_FEED", "PLANNABLE_SURFACE_GMAIL", "PLANNABLE_SURFACE_GOOGLE_DISPLAY_NETWORK", "PLANNABLE_SURFACE_IN_STREAM_NON_SKIPPABLE_THIRTY_SECONDS"])).optional()}); export const surfaceTargetingCombinations = z.object({availableSurfaceTypes: z.array(z.enum(["PLANNABLE_SURFACE_UNSPECIFIED", "PLANNABLE_SURFACE_IN_FEED", "PLANNABLE_SURFACE_IN_STREAM_BUMPER", "PLANNABLE_SURFACE_IN_STREAM_NON_SKIPPABLE", "PLANNABLE_SURFACE_IN_STREAM_SKIPPABLE", "PLANNABLE_SURFACE_SHORTS", "PLANNABLE_SURFACE_DISCOVER_FEED", "PLANNABLE_SURFACE_GMAIL", "PLANNABLE_SURFACE_GOOGLE_DISPLAY_NETWORK", "PLANNABLE_SURFACE_IN_STREAM_NON_SKIPPABLE_THIRTY_SECONDS"])).optional(), defaultSurfaceTypes: z.array(z.enum(["PLANNABLE_SURFACE_UNSPECIFIED", "PLANNABLE_SURFACE_IN_FEED", "PLANNABLE_SURFACE_IN_STREAM_BUMPER", "PLANNABLE_SURFACE_IN_STREAM_NON_SKIPPABLE", "PLANNABLE_SURFACE_IN_STREAM_SKIPPABLE", "PLANNABLE_SURFACE_SHORTS", "PLANNABLE_SURFACE_DISCOVER_FEED", "PLANNABLE_SURFACE_GMAIL", "PLANNABLE_SURFACE_GOOGLE_DISPLAY_NETWORK", "PLANNABLE_SURFACE_IN_STREAM_NON_SKIPPABLE_THIRTY_SECONDS"])).optional(), validSurfaceCombinations: z.array(surfaceTargetingCombination).optional()}); export const plannableTargeting = z.object({ageRanges: z.array(z.enum(["PLANNABLE_AGE_RANGE_UNSPECIFIED", "PLANNABLE_AGE_RANGE_18_24", "PLANNABLE_AGE_RANGE_18_34", "PLANNABLE_AGE_RANGE_18_44", "PLANNABLE_AGE_RANGE_18_49", "PLANNABLE_AGE_RANGE_18_54", "PLANNABLE_AGE_RANGE_18_64", "PLANNABLE_AGE_RANGE_18_65_UP", "PLANNABLE_AGE_RANGE_21_34", "PLANNABLE_AGE_RANGE_21_44", "PLANNABLE_AGE_RANGE_21_49", "PLANNABLE_AGE_RANGE_21_54", "PLANNABLE_AGE_RANGE_21_64", "PLANNABLE_AGE_RANGE_21_65_UP", "PLANNABLE_AGE_RANGE_25_34", "PLANNABLE_AGE_RANGE_25_44", "PLANNABLE_AGE_RANGE_25_49", "PLANNABLE_AGE_RANGE_25_54", "PLANNABLE_AGE_RANGE_25_64", "PLANNABLE_AGE_RANGE_25_65_UP", "PLANNABLE_AGE_RANGE_35_44", "PLANNABLE_AGE_RANGE_35_49", "PLANNABLE_AGE_RANGE_35_54", "PLANNABLE_AGE_RANGE_35_64", "PLANNABLE_AGE_RANGE_35_65_UP", "PLANNABLE_AGE_RANGE_45_54", "PLANNABLE_AGE_RANGE_45_64", "PLANNABLE_AGE_RANGE_45_65_UP", "PLANNABLE_AGE_RANGE_50_65_UP", "PLANNABLE_AGE_RANGE_55_64", "PLANNABLE_AGE_RANGE_55_65_UP", "PLANNABLE_AGE_RANGE_65_UP"])).optional(), defaultYoutubeSelectLineup: youTubeSelectLineUp.optional(), devices: z.array(z.enum(["DEVICE_TYPE_UNSPECIFIED", "DEVICE_TYPE_COMPUTER", "DEVICE_TYPE_CONNECTED_TV", "DEVICE_TYPE_SMART_PHONE", "DEVICE_TYPE_TABLET", "DEVICE_TYPE_CONNECTED_DEVICE"])).optional(), genders: z.array(z.enum(["GENDER_UNSPECIFIED", "GENDER_MALE", "GENDER_FEMALE", "GENDER_UNKNOWN"])).optional(), networks: z.array(z.enum(["PLANNABLE_NETWORK_UNSPECIFIED", "PLANNABLE_NETWORK_YOUTUBE", "PLANNABLE_NETWORK_GOOGLE_VIDEO_PARTNERS", "PLANNABLE_NETWORK_YOUTUBE_AND_GOOGLE_VIDEO_PARTNERS"])).optional(), surfaceTargetingCombinations: surfaceTargetingCombinations.optional(), youtubeSelectLineups: z.array(youTubeSelectLineUp).optional()}); export const productMetadata = z.object({displayName: z.string().optional(), plannableProductCode: z.string().optional(), plannableProductCoreAttributes: plannableProductCoreAttributes.optional(), plannableProductDescription: z.string().optional(), plannableTargeting: plannableTargeting.optional()}); export const retrievePlannableProductsResponse = z.object({productMetadata: z.array(productMetadata).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 }; /** * Retrieves the list of products that can be planned for a location. API support for generating reach forecasts and retrieving related metadata is in beta. This method is only available to allowlisted users. * * GET /v4/advertisers/{advertisersId}/reachForecast:retrievePlannableProducts */ export const getApiV4AdvertisersAdvertisersIdReachForecastRetrievePlannableProducts = async (args: GetApiV4AdvertisersAdvertisersIdReachForecastRetrievePlannableProductsArgs, options?: GetApiV4AdvertisersAdvertisersIdReachForecastRetrievePlannableProductsOptions) => { const {baseUrl = "https://displayvideo.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.plannableLocationId != null) query.append("plannableLocationId", String(args.plannableLocationId)) if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v4/advertisers/${encodeURIComponent(String(args.advertisersId))}/reachForecast:retrievePlannableProducts${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(retrievePlannableProductsResponse, await res.json()) };