import {z} from 'zod' export type GoogleAdsSearchads360V23CommonAdScheduleInfo = {dayOfWeek?: ('UNSPECIFIED' | 'UNKNOWN' | 'MONDAY' | 'TUESDAY' | 'WEDNESDAY' | 'THURSDAY' | 'FRIDAY' | 'SATURDAY' | 'SUNDAY') | undefined, endHour?: number | undefined, endMinute?: ('UNSPECIFIED' | 'UNKNOWN' | 'ZERO' | 'FIFTEEN' | 'THIRTY' | 'FORTY_FIVE') | undefined, startHour?: number | undefined, startMinute?: ('UNSPECIFIED' | 'UNKNOWN' | 'ZERO' | 'FIFTEEN' | 'THIRTY' | 'FORTY_FIVE') | undefined}; export type GoogleAdsSearchads360V23ServicesSmartCampaignSuggestionInfoBusinessContext = {businessName?: string | undefined}; export type GoogleAdsSearchads360V23CommonKeywordThemeInfo = {freeFormKeywordTheme?: string | undefined, keywordThemeConstant?: string | undefined}; export type GoogleAdsSearchads360V23CommonLocationInfo = {geoTargetConstant?: string | undefined}; export type GoogleAdsSearchads360V23ServicesSmartCampaignSuggestionInfoLocationList = {locations?: Array | undefined}; export type GoogleAdsSearchads360V23CommonAddressInfo = {cityName?: string | undefined, countryCode?: string | undefined, postalCode?: string | undefined, provinceCode?: string | undefined, provinceName?: string | undefined, streetAddress?: string | undefined, streetAddress2?: string | undefined}; export type GoogleAdsSearchads360V23CommonGeoPointInfo = {latitudeInMicroDegrees?: number | undefined, longitudeInMicroDegrees?: number | undefined}; export type GoogleAdsSearchads360V23CommonProximityInfo = {address?: GoogleAdsSearchads360V23CommonAddressInfo | undefined, geoPoint?: GoogleAdsSearchads360V23CommonGeoPointInfo | undefined, radius?: number | undefined, radiusUnits?: ('UNSPECIFIED' | 'UNKNOWN' | 'MILES' | 'KILOMETERS') | undefined}; export type GoogleAdsSearchads360V23ServicesSmartCampaignSuggestionInfo = {adSchedules?: Array | undefined, businessContext?: GoogleAdsSearchads360V23ServicesSmartCampaignSuggestionInfoBusinessContext | undefined, businessProfileLocation?: string | undefined, finalUrl?: string | undefined, keywordThemes?: Array | undefined, languageCode?: string | undefined, locationList?: GoogleAdsSearchads360V23ServicesSmartCampaignSuggestionInfoLocationList | undefined, proximity?: GoogleAdsSearchads360V23CommonProximityInfo | undefined}; export type GoogleAdsSearchads360V23ServicesSuggestSmartCampaignAdRequest = {suggestionInfo?: GoogleAdsSearchads360V23ServicesSmartCampaignSuggestionInfo | undefined}; export type CreateApiV23CustomersCustomersIdSuggestSmartCampaignAdArgs = {customersId: string, body: GoogleAdsSearchads360V23ServicesSuggestSmartCampaignAdRequest}; export type CreateApiV23CustomersCustomersIdSuggestSmartCampaignAdOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const googleAdsSearchads360V23CommonPolicyTopicConstraintCountryConstraint = z.object({countryCriterion: z.string().optional()}); export const googleAdsSearchads360V23CommonPolicyTopicConstraintCountryConstraintList = z.object({countries: z.array(googleAdsSearchads360V23CommonPolicyTopicConstraintCountryConstraint).optional(), totalTargetedCountries: z.number().int().optional()}); export const googleAdsSearchads360V23CommonPolicyTopicConstraintResellerConstraint = z.object({}); export const googleAdsSearchads360V23CommonPolicyTopicConstraint = z.object({certificateDomainMismatchInCountryList: googleAdsSearchads360V23CommonPolicyTopicConstraintCountryConstraintList.optional(), certificateMissingInCountryList: googleAdsSearchads360V23CommonPolicyTopicConstraintCountryConstraintList.optional(), countryConstraintList: googleAdsSearchads360V23CommonPolicyTopicConstraintCountryConstraintList.optional(), resellerConstraint: googleAdsSearchads360V23CommonPolicyTopicConstraintResellerConstraint.optional()}); export const googleAdsSearchads360V23CommonPolicyTopicEvidenceDestinationMismatch = z.object({urlTypes: z.array(z.enum(["UNSPECIFIED", "UNKNOWN", "DISPLAY_URL", "FINAL_URL", "FINAL_MOBILE_URL", "TRACKING_URL", "MOBILE_TRACKING_URL"])).optional()}); export const googleAdsSearchads360V23CommonPolicyTopicEvidenceDestinationNotWorking = z.object({device: z.enum(["UNSPECIFIED", "UNKNOWN", "DESKTOP", "ANDROID", "IOS"]).optional(), dnsErrorType: z.enum(["UNSPECIFIED", "UNKNOWN", "HOSTNAME_NOT_FOUND", "GOOGLE_CRAWLER_DNS_ISSUE"]).optional(), expandedUrl: z.string().optional(), httpErrorCode: z.string().optional(), lastCheckedDateTime: z.string().optional()}); export const googleAdsSearchads360V23CommonPolicyTopicEvidenceDestinationTextList = z.object({destinationTexts: z.array(z.string()).optional()}); export const googleAdsSearchads360V23CommonPolicyTopicEvidenceTextList = z.object({texts: z.array(z.string()).optional()}); export const googleAdsSearchads360V23CommonPolicyTopicEvidenceWebsiteList = z.object({websites: z.array(z.string()).optional()}); export const googleAdsSearchads360V23CommonPolicyTopicEvidence = z.object({destinationMismatch: googleAdsSearchads360V23CommonPolicyTopicEvidenceDestinationMismatch.optional(), destinationNotWorking: googleAdsSearchads360V23CommonPolicyTopicEvidenceDestinationNotWorking.optional(), destinationTextList: googleAdsSearchads360V23CommonPolicyTopicEvidenceDestinationTextList.optional(), languageCode: z.string().optional(), textList: googleAdsSearchads360V23CommonPolicyTopicEvidenceTextList.optional(), websiteList: googleAdsSearchads360V23CommonPolicyTopicEvidenceWebsiteList.optional()}); export const googleAdsSearchads360V23CommonPolicyTopicEntry = z.object({constraints: z.array(googleAdsSearchads360V23CommonPolicyTopicConstraint).optional(), evidences: z.array(googleAdsSearchads360V23CommonPolicyTopicEvidence).optional(), topic: z.string().optional(), type: z.enum(["UNSPECIFIED", "UNKNOWN", "PROHIBITED", "LIMITED", "FULLY_LIMITED", "DESCRIPTIVE", "BROADENING", "AREA_OF_INTEREST_ONLY"]).optional()}); export const googleAdsSearchads360V23CommonAdAssetPolicySummary = z.object({approvalStatus: z.enum(["UNSPECIFIED", "UNKNOWN", "DISAPPROVED", "APPROVED_LIMITED", "APPROVED", "AREA_OF_INTEREST_ONLY"]).optional(), policyTopicEntries: z.array(googleAdsSearchads360V23CommonPolicyTopicEntry).optional(), reviewStatus: z.enum(["UNSPECIFIED", "UNKNOWN", "REVIEW_IN_PROGRESS", "REVIEWED", "UNDER_APPEAL", "ELIGIBLE_MAY_SERVE"]).optional()}); export const googleAdsSearchads360V23CommonAdTextAsset = z.object({assetPerformanceLabel: z.enum(["UNSPECIFIED", "UNKNOWN", "PENDING", "LEARNING", "LOW", "GOOD", "BEST", "NOT_APPLICABLE"]).optional(), pinnedField: z.enum(["UNSPECIFIED", "UNKNOWN", "HEADLINE_1", "HEADLINE_2", "HEADLINE_3", "DESCRIPTION_1", "DESCRIPTION_2", "HEADLINE", "HEADLINE_IN_PORTRAIT", "LONG_HEADLINE", "DESCRIPTION", "DESCRIPTION_IN_PORTRAIT", "BUSINESS_NAME_IN_PORTRAIT", "BUSINESS_NAME", "MARKETING_IMAGE", "MARKETING_IMAGE_IN_PORTRAIT", "SQUARE_MARKETING_IMAGE", "PORTRAIT_MARKETING_IMAGE", "LOGO", "LANDSCAPE_LOGO", "CALL_TO_ACTION", "YOU_TUBE_VIDEO", "SITELINK", "CALL", "MOBILE_APP", "CALLOUT", "STRUCTURED_SNIPPET", "PRICE", "PROMOTION", "AD_IMAGE", "LEAD_FORM", "BUSINESS_LOGO", "DESCRIPTION_PREFIX", "HEADLINE_AS_SITELINK_POSITION_ONE", "HEADLINE_AS_SITELINK_POSITION_TWO", "DESCRIPTION_LINE_HEADLINE_AS_SITELINK_POSITION_ONE", "DESCRIPTION_LINE_HEADLINE_AS_SITELINK_POSITION_TWO"]).optional(), policySummaryInfo: googleAdsSearchads360V23CommonAdAssetPolicySummary.optional(), text: z.string().optional()}); export const googleAdsSearchads360V23CommonSmartCampaignAdInfo = z.object({descriptions: z.array(googleAdsSearchads360V23CommonAdTextAsset).optional(), headlines: z.array(googleAdsSearchads360V23CommonAdTextAsset).optional()}); export const googleAdsSearchads360V23ServicesSuggestSmartCampaignAdResponse = z.object({adInfo: googleAdsSearchads360V23CommonSmartCampaignAdInfo.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 }; /** * Suggests a Smart campaign ad compatible with the Ad family of resources, based on data points such as targeting and the business to advertise. * * POST /v23/customers/{customersId}:suggestSmartCampaignAd */ export const createApiV23CustomersCustomersIdSuggestSmartCampaignAd = async (args: CreateApiV23CustomersCustomersIdSuggestSmartCampaignAdArgs, options?: CreateApiV23CustomersCustomersIdSuggestSmartCampaignAdOptions) => { const {baseUrl = "https://searchads360.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(/\/+$/, '')}/v23/customers/${encodeURIComponent(String(args.customersId))}:suggestSmartCampaignAd${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(googleAdsSearchads360V23ServicesSuggestSmartCampaignAdResponse, await res.json()) };