import {z} from 'zod' export type GoogleAdsSearchads360V23CommonAgeRangeInfo = {type?: ('UNSPECIFIED' | 'UNKNOWN' | 'AGE_RANGE_18_24' | 'AGE_RANGE_25_34' | 'AGE_RANGE_35_44' | 'AGE_RANGE_45_54' | 'AGE_RANGE_55_64' | 'AGE_RANGE_65_UP' | 'AGE_RANGE_UNDETERMINED') | undefined}; export type GoogleAdsSearchads360V23CommonLocationInfo = {geoTargetConstant?: string | undefined}; export type GoogleAdsSearchads360V23CommonGenderInfo = {type?: ('UNSPECIFIED' | 'UNKNOWN' | 'MALE' | 'FEMALE' | 'UNDETERMINED') | undefined}; export type GoogleAdsSearchads360V23CommonIncomeRangeInfo = {type?: ('UNSPECIFIED' | 'UNKNOWN' | 'INCOME_RANGE_0_50' | 'INCOME_RANGE_50_60' | 'INCOME_RANGE_60_70' | 'INCOME_RANGE_70_80' | 'INCOME_RANGE_80_90' | 'INCOME_RANGE_90_UP' | 'INCOME_RANGE_UNDETERMINED') | undefined}; export type GoogleAdsSearchads360V23CommonAudienceInsightsLineup = {lineupId?: string | undefined}; export type GoogleAdsSearchads360V23CommonParentalStatusInfo = {type?: ('UNSPECIFIED' | 'UNKNOWN' | 'PARENT' | 'NOT_A_PARENT' | 'UNDETERMINED') | undefined}; export type GoogleAdsSearchads360V23CommonAudienceInsightsCategory = {categoryId?: string | undefined}; export type GoogleAdsSearchads360V23CommonDeviceInfo = {type?: ('UNSPECIFIED' | 'UNKNOWN' | 'MOBILE' | 'TABLET' | 'DESKTOP' | 'CONNECTED_TV' | 'OTHER') | undefined}; export type GoogleAdsSearchads360V23CommonAudienceInsightsEntity = {knowledgeGraphMachineId?: string | undefined}; export type GoogleAdsSearchads360V23CommonUserInterestInfo = {userInterestCategory?: string | undefined}; export type GoogleAdsSearchads360V23CommonUserListInfo = {userList?: string | undefined}; export type GoogleAdsSearchads360V23CommonYouTubeChannelInfo = {channelId?: string | undefined}; export type GoogleAdsSearchads360V23CommonYouTubeVideoInfo = {videoId?: string | undefined}; export type GoogleAdsSearchads360V23CommonAudienceInsightsAttribute = {ageRange?: GoogleAdsSearchads360V23CommonAgeRangeInfo | undefined, category?: GoogleAdsSearchads360V23CommonAudienceInsightsCategory | undefined, device?: GoogleAdsSearchads360V23CommonDeviceInfo | undefined, entity?: GoogleAdsSearchads360V23CommonAudienceInsightsEntity | undefined, gender?: GoogleAdsSearchads360V23CommonGenderInfo | undefined, incomeRange?: GoogleAdsSearchads360V23CommonIncomeRangeInfo | undefined, lineup?: GoogleAdsSearchads360V23CommonAudienceInsightsLineup | undefined, location?: GoogleAdsSearchads360V23CommonLocationInfo | undefined, parentalStatus?: GoogleAdsSearchads360V23CommonParentalStatusInfo | undefined, userInterest?: GoogleAdsSearchads360V23CommonUserInterestInfo | undefined, userList?: GoogleAdsSearchads360V23CommonUserListInfo | undefined, youtubeChannel?: GoogleAdsSearchads360V23CommonYouTubeChannelInfo | undefined, youtubeVideo?: GoogleAdsSearchads360V23CommonYouTubeVideoInfo | undefined}; export type GoogleAdsSearchads360V23ServicesInsightsAudienceAttributeGroup = {attributes?: Array | undefined}; export type GoogleAdsSearchads360V23ServicesInsightsAudience = {ageRanges?: Array | undefined, countryLocations?: Array | undefined, gender?: GoogleAdsSearchads360V23CommonGenderInfo | undefined, incomeRanges?: Array | undefined, lineups?: Array | undefined, parentalStatus?: GoogleAdsSearchads360V23CommonParentalStatusInfo | undefined, subCountryLocations?: Array | undefined, topicAudienceCombinations?: Array | undefined, userList?: GoogleAdsSearchads360V23CommonUserListInfo | undefined}; export type GoogleAdsSearchads360V23CommonAdditionalApplicationInfo = {applicationId?: string | undefined, applicationInstance?: ('UNSPECIFIED' | 'UNKNOWN' | 'DEVELOPMENT_AND_TESTING' | 'PRODUCTION') | undefined}; export type GoogleAdsSearchads360V23ServicesGenerateInsightsFinderReportRequest = {baselineAudience?: GoogleAdsSearchads360V23ServicesInsightsAudience | undefined, customerInsightsGroup?: string | undefined, insightsApplicationInfo?: GoogleAdsSearchads360V23CommonAdditionalApplicationInfo | undefined, specificAudience?: GoogleAdsSearchads360V23ServicesInsightsAudience | undefined}; export type CreateApiV23CustomersCustomersIdGenerateInsightsFinderReportArgs = {customersId: string, body: GoogleAdsSearchads360V23ServicesGenerateInsightsFinderReportRequest}; export type CreateApiV23CustomersCustomersIdGenerateInsightsFinderReportOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const googleAdsSearchads360V23ServicesGenerateInsightsFinderReportResponse = z.object({savedReportUrl: z.string().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 saved report that can be viewed in the Insights Finder tool. List of thrown errors: [AuthenticationError]() [AuthorizationError]() [FieldError]() [HeaderError]() [InternalError]() [QuotaError]() [RangeError]() [RequestError]() * * POST /v23/customers/{customersId}:generateInsightsFinderReport */ export const createApiV23CustomersCustomersIdGenerateInsightsFinderReport = async (args: CreateApiV23CustomersCustomersIdGenerateInsightsFinderReportArgs, options?: CreateApiV23CustomersCustomersIdGenerateInsightsFinderReportOptions) => { 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))}:generateInsightsFinderReport${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(googleAdsSearchads360V23ServicesGenerateInsightsFinderReportResponse, await res.json()) };