import {z} from 'zod' export type GoogleAdsSearchads360V23CommonPolicyTopicConstraintCountryConstraint = {countryCriterion?: string | undefined}; export type GoogleAdsSearchads360V23CommonPolicyTopicConstraintCountryConstraintList = {countries?: Array | undefined, totalTargetedCountries?: number | undefined}; export type GoogleAdsSearchads360V23CommonPolicyTopicConstraintResellerConstraint = Record; export type GoogleAdsSearchads360V23CommonPolicyTopicConstraint = {certificateDomainMismatchInCountryList?: GoogleAdsSearchads360V23CommonPolicyTopicConstraintCountryConstraintList | undefined, certificateMissingInCountryList?: GoogleAdsSearchads360V23CommonPolicyTopicConstraintCountryConstraintList | undefined, countryConstraintList?: GoogleAdsSearchads360V23CommonPolicyTopicConstraintCountryConstraintList | undefined, resellerConstraint?: GoogleAdsSearchads360V23CommonPolicyTopicConstraintResellerConstraint | undefined}; export type GoogleAdsSearchads360V23CommonPolicyTopicEvidenceDestinationMismatch = {urlTypes?: (Array<'UNSPECIFIED' | 'UNKNOWN' | 'DISPLAY_URL' | 'FINAL_URL' | 'FINAL_MOBILE_URL' | 'TRACKING_URL' | 'MOBILE_TRACKING_URL'>) | undefined}; export type GoogleAdsSearchads360V23CommonPolicyTopicEvidenceDestinationNotWorking = {device?: ('UNSPECIFIED' | 'UNKNOWN' | 'DESKTOP' | 'ANDROID' | 'IOS') | undefined, dnsErrorType?: ('UNSPECIFIED' | 'UNKNOWN' | 'HOSTNAME_NOT_FOUND' | 'GOOGLE_CRAWLER_DNS_ISSUE') | undefined, expandedUrl?: string | undefined, httpErrorCode?: unknown | undefined, lastCheckedDateTime?: string | undefined}; export type GoogleAdsSearchads360V23CommonPolicyTopicEvidenceDestinationTextList = {destinationTexts?: Array | undefined}; export type GoogleAdsSearchads360V23CommonPolicyTopicEvidenceTextList = {texts?: Array | undefined}; export type GoogleAdsSearchads360V23CommonPolicyTopicEvidenceWebsiteList = {websites?: Array | undefined}; export type GoogleAdsSearchads360V23CommonPolicyTopicEvidence = {destinationMismatch?: GoogleAdsSearchads360V23CommonPolicyTopicEvidenceDestinationMismatch | undefined, destinationNotWorking?: GoogleAdsSearchads360V23CommonPolicyTopicEvidenceDestinationNotWorking | undefined, destinationTextList?: GoogleAdsSearchads360V23CommonPolicyTopicEvidenceDestinationTextList | undefined, languageCode?: string | undefined, textList?: GoogleAdsSearchads360V23CommonPolicyTopicEvidenceTextList | undefined, websiteList?: GoogleAdsSearchads360V23CommonPolicyTopicEvidenceWebsiteList | undefined}; export type GoogleAdsSearchads360V23CommonPolicyTopicEntry = {constraints?: Array | undefined, evidences?: Array | undefined, topic?: string | undefined, type?: ('UNSPECIFIED' | 'UNKNOWN' | 'PROHIBITED' | 'LIMITED' | 'FULLY_LIMITED' | 'DESCRIPTIVE' | 'BROADENING' | 'AREA_OF_INTEREST_ONLY') | undefined}; export type GoogleAdsSearchads360V23CommonPolicySummary = {approvalStatus?: ('UNSPECIFIED' | 'UNKNOWN' | 'DISAPPROVED' | 'APPROVED_LIMITED' | 'APPROVED' | 'AREA_OF_INTEREST_ONLY') | undefined, policyTopicEntries?: Array | undefined, reviewStatus?: ('UNSPECIFIED' | 'UNKNOWN' | 'REVIEW_IN_PROGRESS' | 'REVIEWED' | 'UNDER_APPEAL' | 'ELIGIBLE_MAY_SERVE') | undefined}; export type GoogleAdsSearchads360V23CommonAssetDisapproved = {offlineEvaluationErrorReasons?: (Array<'UNSPECIFIED' | 'UNKNOWN' | 'PRICE_ASSET_DESCRIPTION_REPEATS_ROW_HEADER' | 'PRICE_ASSET_REPETITIVE_HEADERS' | 'PRICE_ASSET_HEADER_INCOMPATIBLE_WITH_PRICE_TYPE' | 'PRICE_ASSET_DESCRIPTION_INCOMPATIBLE_WITH_ITEM_HEADER' | 'PRICE_ASSET_DESCRIPTION_HAS_PRICE_QUALIFIER' | 'PRICE_ASSET_UNSUPPORTED_LANGUAGE' | 'PRICE_ASSET_OTHER_ERROR'>) | undefined}; export type GoogleAdsSearchads360V23CommonAssetLinkPrimaryStatusDetails = {assetDisapproved?: GoogleAdsSearchads360V23CommonAssetDisapproved | undefined, reason?: ('UNSPECIFIED' | 'UNKNOWN' | 'ASSET_LINK_PAUSED' | 'ASSET_LINK_REMOVED' | 'ASSET_DISAPPROVED' | 'ASSET_UNDER_REVIEW' | 'ASSET_APPROVED_LABELED') | undefined, status?: ('UNSPECIFIED' | 'UNKNOWN' | 'ELIGIBLE' | 'PAUSED' | 'REMOVED' | 'PENDING' | 'LIMITED' | 'NOT_ELIGIBLE') | undefined}; export type GoogleAdsSearchads360V23ResourcesAssetGroupAsset = {asset?: string | undefined, assetGroup?: string | undefined, fieldType?: ('UNSPECIFIED' | 'UNKNOWN' | 'HEADLINE' | 'DESCRIPTION' | 'MANDATORY_AD_TEXT' | 'MARKETING_IMAGE' | 'MEDIA_BUNDLE' | 'YOUTUBE_VIDEO' | 'BOOK_ON_GOOGLE' | 'LEAD_FORM' | 'PROMOTION' | 'CALLOUT' | 'STRUCTURED_SNIPPET' | 'SITELINK' | 'MOBILE_APP' | 'HOTEL_CALLOUT' | 'CALL' | 'PRICE' | 'LONG_HEADLINE' | 'BUSINESS_NAME' | 'SQUARE_MARKETING_IMAGE' | 'PORTRAIT_MARKETING_IMAGE' | 'LOGO' | 'LANDSCAPE_LOGO' | 'VIDEO' | 'CALL_TO_ACTION_SELECTION' | 'AD_IMAGE' | 'BUSINESS_LOGO' | 'HOTEL_PROPERTY' | 'DEMAND_GEN_CAROUSEL_CARD' | 'BUSINESS_MESSAGE' | 'TALL_PORTRAIT_MARKETING_IMAGE' | 'LANDING_PAGE_PREVIEW' | 'LONG_DESCRIPTION' | 'CALL_TO_ACTION') | undefined, policySummary?: GoogleAdsSearchads360V23CommonPolicySummary | undefined, primaryStatus?: ('UNSPECIFIED' | 'UNKNOWN' | 'ELIGIBLE' | 'PAUSED' | 'REMOVED' | 'PENDING' | 'LIMITED' | 'NOT_ELIGIBLE') | undefined, primaryStatusDetails?: Array | undefined, primaryStatusReasons?: (Array<'UNSPECIFIED' | 'UNKNOWN' | 'ASSET_LINK_PAUSED' | 'ASSET_LINK_REMOVED' | 'ASSET_DISAPPROVED' | 'ASSET_UNDER_REVIEW' | 'ASSET_APPROVED_LABELED'>) | undefined, resourceName?: string | undefined, source?: ('UNSPECIFIED' | 'UNKNOWN' | 'ADVERTISER' | 'AUTOMATICALLY_CREATED') | undefined, status?: ('UNSPECIFIED' | 'UNKNOWN' | 'ENABLED' | 'REMOVED' | 'PAUSED') | undefined}; export type GoogleAdsSearchads360V23ServicesAssetGroupAssetOperation = {create?: GoogleAdsSearchads360V23ResourcesAssetGroupAsset | undefined, remove?: string | undefined, update?: GoogleAdsSearchads360V23ResourcesAssetGroupAsset | undefined, updateMask?: unknown | undefined}; export type GoogleAdsSearchads360V23ServicesMutateAssetGroupAssetsRequest = {operations?: Array | undefined, partialFailure?: boolean | undefined, validateOnly?: boolean | undefined}; export type CreateApiV23CustomersCustomersIdAssetGroupAssetsMutateArgs = {customersId: string, body: GoogleAdsSearchads360V23ServicesMutateAssetGroupAssetsRequest}; export type CreateApiV23CustomersCustomersIdAssetGroupAssetsMutateOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const googleRpcStatus = z.object({code: z.number().int().optional(), details: z.array(z.record(z.string(), z.unknown())).optional(), message: z.string().optional()}); export const googleAdsSearchads360V23ServicesMutateAssetGroupAssetResult = z.object({resourceName: z.string().optional()}); export const googleAdsSearchads360V23ServicesMutateAssetGroupAssetsResponse = z.object({partialFailureError: googleRpcStatus.optional(), results: z.array(googleAdsSearchads360V23ServicesMutateAssetGroupAssetResult).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, updates or removes asset group assets. Operation statuses are returned. * * POST /v23/customers/{customersId}/assetGroupAssets:mutate */ export const createApiV23CustomersCustomersIdAssetGroupAssetsMutate = async (args: CreateApiV23CustomersCustomersIdAssetGroupAssetsMutateArgs, options?: CreateApiV23CustomersCustomersIdAssetGroupAssetsMutateOptions) => { 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))}/assetGroupAssets:mutate${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(googleAdsSearchads360V23ServicesMutateAssetGroupAssetsResponse, await res.json()) };