import {z} from 'zod' export type GoogleAdsSearchads360V23CommonAgeSegment = {maxAge?: number | undefined, minAge?: number | undefined}; export type GoogleAdsSearchads360V23CommonAgeDimension = {ageRanges?: Array | undefined, includeUndetermined?: boolean | undefined}; export type GoogleAdsSearchads360V23CommonCustomAudienceSegment = {customAudience?: string | undefined}; export type GoogleAdsSearchads360V23CommonDetailedDemographicSegment = {detailedDemographic?: string | undefined}; export type GoogleAdsSearchads360V23CommonLifeEventSegment = {lifeEvent?: string | undefined}; export type GoogleAdsSearchads360V23CommonUserInterestSegment = {userInterestCategory?: string | undefined}; export type GoogleAdsSearchads360V23CommonUserListSegment = {userList?: string | undefined}; export type GoogleAdsSearchads360V23CommonAudienceSegment = {customAudience?: GoogleAdsSearchads360V23CommonCustomAudienceSegment | undefined, detailedDemographic?: GoogleAdsSearchads360V23CommonDetailedDemographicSegment | undefined, lifeEvent?: GoogleAdsSearchads360V23CommonLifeEventSegment | undefined, userInterest?: GoogleAdsSearchads360V23CommonUserInterestSegment | undefined, userList?: GoogleAdsSearchads360V23CommonUserListSegment | undefined}; export type GoogleAdsSearchads360V23CommonAudienceSegmentDimension = {segments?: Array | undefined}; export type GoogleAdsSearchads360V23CommonGenderDimension = {genders?: (Array<'UNSPECIFIED' | 'UNKNOWN' | 'MALE' | 'FEMALE' | 'UNDETERMINED'>) | undefined, includeUndetermined?: boolean | undefined}; export type GoogleAdsSearchads360V23CommonHouseholdIncomeDimension = {includeUndetermined?: boolean | undefined, incomeRanges?: (Array<'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 GoogleAdsSearchads360V23CommonParentalStatusDimension = {includeUndetermined?: boolean | undefined, parentalStatuses?: (Array<'UNSPECIFIED' | 'UNKNOWN' | 'PARENT' | 'NOT_A_PARENT' | 'UNDETERMINED'>) | undefined}; export type GoogleAdsSearchads360V23CommonAudienceDimension = {age?: GoogleAdsSearchads360V23CommonAgeDimension | undefined, audienceSegments?: GoogleAdsSearchads360V23CommonAudienceSegmentDimension | undefined, gender?: GoogleAdsSearchads360V23CommonGenderDimension | undefined, householdIncome?: GoogleAdsSearchads360V23CommonHouseholdIncomeDimension | undefined, parentalStatus?: GoogleAdsSearchads360V23CommonParentalStatusDimension | undefined}; export type GoogleAdsSearchads360V23CommonExclusionSegment = {userList?: GoogleAdsSearchads360V23CommonUserListSegment | undefined}; export type GoogleAdsSearchads360V23CommonAudienceExclusionDimension = {exclusions?: Array | undefined}; export type GoogleAdsSearchads360V23ResourcesAudience = {assetGroup?: string | undefined, description?: string | undefined, dimensions?: Array | undefined, exclusionDimension?: GoogleAdsSearchads360V23CommonAudienceExclusionDimension | undefined, id?: unknown | undefined, name?: string | undefined, resourceName?: string | undefined, scope?: ('UNSPECIFIED' | 'UNKNOWN' | 'CUSTOMER' | 'ASSET_GROUP') | undefined, status?: ('UNSPECIFIED' | 'UNKNOWN' | 'ENABLED' | 'REMOVED') | undefined}; export type GoogleAdsSearchads360V23ServicesAudienceOperation = {create?: GoogleAdsSearchads360V23ResourcesAudience | undefined, update?: GoogleAdsSearchads360V23ResourcesAudience | undefined, updateMask?: unknown | undefined}; export type GoogleAdsSearchads360V23ServicesMutateAudiencesRequest = {operations?: Array | undefined, partialFailure?: boolean | undefined, responseContentType?: ('UNSPECIFIED' | 'RESOURCE_NAME_ONLY' | 'MUTABLE_RESOURCE') | undefined, validateOnly?: boolean | undefined}; export type CreateApiV23CustomersCustomersIdAudiencesMutateArgs = {customersId: string, body: GoogleAdsSearchads360V23ServicesMutateAudiencesRequest}; export type CreateApiV23CustomersCustomersIdAudiencesMutateOptions = {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 googleAdsSearchads360V23CommonAgeSegment = z.object({maxAge: z.number().int().optional(), minAge: z.number().int().optional()}); export const googleAdsSearchads360V23CommonAgeDimension = z.object({ageRanges: z.array(googleAdsSearchads360V23CommonAgeSegment).optional(), includeUndetermined: z.boolean().optional()}); export const googleAdsSearchads360V23CommonCustomAudienceSegment = z.object({customAudience: z.string().optional()}); export const googleAdsSearchads360V23CommonDetailedDemographicSegment = z.object({detailedDemographic: z.string().optional()}); export const googleAdsSearchads360V23CommonLifeEventSegment = z.object({lifeEvent: z.string().optional()}); export const googleAdsSearchads360V23CommonUserInterestSegment = z.object({userInterestCategory: z.string().optional()}); export const googleAdsSearchads360V23CommonUserListSegment = z.object({userList: z.string().optional()}); export const googleAdsSearchads360V23CommonAudienceSegment = z.object({customAudience: googleAdsSearchads360V23CommonCustomAudienceSegment.optional(), detailedDemographic: googleAdsSearchads360V23CommonDetailedDemographicSegment.optional(), lifeEvent: googleAdsSearchads360V23CommonLifeEventSegment.optional(), userInterest: googleAdsSearchads360V23CommonUserInterestSegment.optional(), userList: googleAdsSearchads360V23CommonUserListSegment.optional()}); export const googleAdsSearchads360V23CommonAudienceSegmentDimension = z.object({segments: z.array(googleAdsSearchads360V23CommonAudienceSegment).optional()}); export const googleAdsSearchads360V23CommonGenderDimension = z.object({genders: z.array(z.enum(["UNSPECIFIED", "UNKNOWN", "MALE", "FEMALE", "UNDETERMINED"])).optional(), includeUndetermined: z.boolean().optional()}); export const googleAdsSearchads360V23CommonHouseholdIncomeDimension = z.object({includeUndetermined: z.boolean().optional(), incomeRanges: z.array(z.enum(["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"])).optional()}); export const googleAdsSearchads360V23CommonParentalStatusDimension = z.object({includeUndetermined: z.boolean().optional(), parentalStatuses: z.array(z.enum(["UNSPECIFIED", "UNKNOWN", "PARENT", "NOT_A_PARENT", "UNDETERMINED"])).optional()}); export const googleAdsSearchads360V23CommonAudienceDimension = z.object({age: googleAdsSearchads360V23CommonAgeDimension.optional(), audienceSegments: googleAdsSearchads360V23CommonAudienceSegmentDimension.optional(), gender: googleAdsSearchads360V23CommonGenderDimension.optional(), householdIncome: googleAdsSearchads360V23CommonHouseholdIncomeDimension.optional(), parentalStatus: googleAdsSearchads360V23CommonParentalStatusDimension.optional()}); export const googleAdsSearchads360V23CommonExclusionSegment = z.object({userList: googleAdsSearchads360V23CommonUserListSegment.optional()}); export const googleAdsSearchads360V23CommonAudienceExclusionDimension = z.object({exclusions: z.array(googleAdsSearchads360V23CommonExclusionSegment).optional()}); export const googleAdsSearchads360V23ResourcesAudience = z.object({assetGroup: z.string().optional(), description: z.string().optional(), dimensions: z.array(googleAdsSearchads360V23CommonAudienceDimension).optional(), exclusionDimension: googleAdsSearchads360V23CommonAudienceExclusionDimension.optional(), id: z.string().optional(), name: z.string().optional(), resourceName: z.string().optional(), scope: z.enum(["UNSPECIFIED", "UNKNOWN", "CUSTOMER", "ASSET_GROUP"]).optional(), status: z.enum(["UNSPECIFIED", "UNKNOWN", "ENABLED", "REMOVED"]).optional()}); export const googleAdsSearchads360V23ServicesMutateAudienceResult = z.object({audience: googleAdsSearchads360V23ResourcesAudience.optional(), resourceName: z.string().optional()}); export const googleAdsSearchads360V23ServicesMutateAudiencesResponse = z.object({partialFailureError: googleRpcStatus.optional(), results: z.array(googleAdsSearchads360V23ServicesMutateAudienceResult).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 audiences. Operation statuses are returned. List of thrown errors: [AudienceError]() * * POST /v23/customers/{customersId}/audiences:mutate */ export const createApiV23CustomersCustomersIdAudiencesMutate = async (args: CreateApiV23CustomersCustomersIdAudiencesMutateArgs, options?: CreateApiV23CustomersCustomersIdAudiencesMutateOptions) => { 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))}/audiences: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(googleAdsSearchads360V23ServicesMutateAudiencesResponse, await res.json()) };