import {z} from 'zod' export type GoogleAdsSearchads360V23ResourcesConversionValueRuleValueRuleAction = {operation?: ('UNSPECIFIED' | 'UNKNOWN' | 'ADD' | 'MULTIPLY' | 'SET') | undefined, value?: number | undefined}; export type GoogleAdsSearchads360V23ResourcesConversionValueRuleValueRuleAudienceCondition = {userInterests?: Array | undefined, userLists?: Array | undefined}; export type GoogleAdsSearchads360V23ResourcesConversionValueRuleValueRuleDeviceCondition = {deviceTypes?: (Array<'UNSPECIFIED' | 'UNKNOWN' | 'MOBILE' | 'DESKTOP' | 'TABLET'>) | undefined}; export type GoogleAdsSearchads360V23ResourcesConversionValueRuleValueRuleGeoLocationCondition = {excludedGeoMatchType?: ('UNSPECIFIED' | 'UNKNOWN' | 'ANY' | 'LOCATION_OF_PRESENCE') | undefined, excludedGeoTargetConstants?: Array | undefined, geoMatchType?: ('UNSPECIFIED' | 'UNKNOWN' | 'ANY' | 'LOCATION_OF_PRESENCE') | undefined, geoTargetConstants?: Array | undefined}; export type GoogleAdsSearchads360V23ResourcesConversionValueRuleValueRuleItineraryAdvanceBookingWindow = {maxDays?: number | undefined, minDays?: number | undefined}; export type GoogleAdsSearchads360V23ResourcesConversionValueRuleValueRuleItineraryTravelLength = {maxNights?: number | undefined, minNights?: number | undefined}; export type GoogleAdsSearchads360V23ResourcesConversionValueRuleValueRuleItineraryTravelStartDay = {friday?: boolean | undefined, monday?: boolean | undefined, saturday?: boolean | undefined, sunday?: boolean | undefined, thursday?: boolean | undefined, tuesday?: boolean | undefined, wednesday?: boolean | undefined}; export type GoogleAdsSearchads360V23ResourcesConversionValueRuleValueRuleItineraryCondition = {advanceBookingWindow?: GoogleAdsSearchads360V23ResourcesConversionValueRuleValueRuleItineraryAdvanceBookingWindow | undefined, travelLength?: GoogleAdsSearchads360V23ResourcesConversionValueRuleValueRuleItineraryTravelLength | undefined, travelStartDay?: GoogleAdsSearchads360V23ResourcesConversionValueRuleValueRuleItineraryTravelStartDay | undefined}; export type GoogleAdsSearchads360V23ResourcesConversionValueRule = {action?: GoogleAdsSearchads360V23ResourcesConversionValueRuleValueRuleAction | undefined, audienceCondition?: GoogleAdsSearchads360V23ResourcesConversionValueRuleValueRuleAudienceCondition | undefined, deviceCondition?: GoogleAdsSearchads360V23ResourcesConversionValueRuleValueRuleDeviceCondition | undefined, geoLocationCondition?: GoogleAdsSearchads360V23ResourcesConversionValueRuleValueRuleGeoLocationCondition | undefined, id?: unknown | undefined, itineraryCondition?: GoogleAdsSearchads360V23ResourcesConversionValueRuleValueRuleItineraryCondition | undefined, ownerCustomer?: string | undefined, resourceName?: string | undefined, status?: ('UNSPECIFIED' | 'UNKNOWN' | 'ENABLED' | 'REMOVED' | 'PAUSED') | undefined}; export type GoogleAdsSearchads360V23ServicesConversionValueRuleOperation = {create?: GoogleAdsSearchads360V23ResourcesConversionValueRule | undefined, remove?: string | undefined, update?: GoogleAdsSearchads360V23ResourcesConversionValueRule | undefined, updateMask?: unknown | undefined}; export type GoogleAdsSearchads360V23ServicesMutateConversionValueRulesRequest = {operations?: Array | undefined, partialFailure?: boolean | undefined, responseContentType?: ('UNSPECIFIED' | 'RESOURCE_NAME_ONLY' | 'MUTABLE_RESOURCE') | undefined, validateOnly?: boolean | undefined}; export type CreateApiV23CustomersCustomersIdConversionValueRulesMutateArgs = {customersId: string, body: GoogleAdsSearchads360V23ServicesMutateConversionValueRulesRequest}; export type CreateApiV23CustomersCustomersIdConversionValueRulesMutateOptions = {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 googleAdsSearchads360V23ResourcesConversionValueRuleValueRuleAction = z.object({operation: z.enum(["UNSPECIFIED", "UNKNOWN", "ADD", "MULTIPLY", "SET"]).optional(), value: z.number().optional()}); export const googleAdsSearchads360V23ResourcesConversionValueRuleValueRuleAudienceCondition = z.object({userInterests: z.array(z.string()).optional(), userLists: z.array(z.string()).optional()}); export const googleAdsSearchads360V23ResourcesConversionValueRuleValueRuleDeviceCondition = z.object({deviceTypes: z.array(z.enum(["UNSPECIFIED", "UNKNOWN", "MOBILE", "DESKTOP", "TABLET"])).optional()}); export const googleAdsSearchads360V23ResourcesConversionValueRuleValueRuleGeoLocationCondition = z.object({excludedGeoMatchType: z.enum(["UNSPECIFIED", "UNKNOWN", "ANY", "LOCATION_OF_PRESENCE"]).optional(), excludedGeoTargetConstants: z.array(z.string()).optional(), geoMatchType: z.enum(["UNSPECIFIED", "UNKNOWN", "ANY", "LOCATION_OF_PRESENCE"]).optional(), geoTargetConstants: z.array(z.string()).optional()}); export const googleAdsSearchads360V23ResourcesConversionValueRuleValueRuleItineraryAdvanceBookingWindow = z.object({maxDays: z.number().int().optional(), minDays: z.number().int().optional()}); export const googleAdsSearchads360V23ResourcesConversionValueRuleValueRuleItineraryTravelLength = z.object({maxNights: z.number().int().optional(), minNights: z.number().int().optional()}); export const googleAdsSearchads360V23ResourcesConversionValueRuleValueRuleItineraryTravelStartDay = z.object({friday: z.boolean().optional(), monday: z.boolean().optional(), saturday: z.boolean().optional(), sunday: z.boolean().optional(), thursday: z.boolean().optional(), tuesday: z.boolean().optional(), wednesday: z.boolean().optional()}); export const googleAdsSearchads360V23ResourcesConversionValueRuleValueRuleItineraryCondition = z.object({advanceBookingWindow: googleAdsSearchads360V23ResourcesConversionValueRuleValueRuleItineraryAdvanceBookingWindow.optional(), travelLength: googleAdsSearchads360V23ResourcesConversionValueRuleValueRuleItineraryTravelLength.optional(), travelStartDay: googleAdsSearchads360V23ResourcesConversionValueRuleValueRuleItineraryTravelStartDay.optional()}); export const googleAdsSearchads360V23ResourcesConversionValueRule = z.object({action: googleAdsSearchads360V23ResourcesConversionValueRuleValueRuleAction.optional(), audienceCondition: googleAdsSearchads360V23ResourcesConversionValueRuleValueRuleAudienceCondition.optional(), deviceCondition: googleAdsSearchads360V23ResourcesConversionValueRuleValueRuleDeviceCondition.optional(), geoLocationCondition: googleAdsSearchads360V23ResourcesConversionValueRuleValueRuleGeoLocationCondition.optional(), id: z.string().optional(), itineraryCondition: googleAdsSearchads360V23ResourcesConversionValueRuleValueRuleItineraryCondition.optional(), ownerCustomer: z.string().optional(), resourceName: z.string().optional(), status: z.enum(["UNSPECIFIED", "UNKNOWN", "ENABLED", "REMOVED", "PAUSED"]).optional()}); export const googleAdsSearchads360V23ServicesMutateConversionValueRuleResult = z.object({conversionValueRule: googleAdsSearchads360V23ResourcesConversionValueRule.optional(), resourceName: z.string().optional()}); export const googleAdsSearchads360V23ServicesMutateConversionValueRulesResponse = z.object({partialFailureError: googleRpcStatus.optional(), results: z.array(googleAdsSearchads360V23ServicesMutateConversionValueRuleResult).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 conversion value rules. Operation statuses are returned. * * POST /v23/customers/{customersId}/conversionValueRules:mutate */ export const createApiV23CustomersCustomersIdConversionValueRulesMutate = async (args: CreateApiV23CustomersCustomersIdConversionValueRulesMutateArgs, options?: CreateApiV23CustomersCustomersIdConversionValueRulesMutateOptions) => { 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))}/conversionValueRules: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(googleAdsSearchads360V23ServicesMutateConversionValueRulesResponse, await res.json()) };