import {z} from 'zod' export type AdWordsLocationExtensions = {adPhone?: string | undefined}; export type MoreHoursType = {displayName?: string | undefined, hoursTypeId?: string | undefined, localizedDisplayName?: string | undefined}; export type ServiceType = {displayName?: string | undefined, serviceTypeId?: string | undefined}; export type Category = {displayName?: string | undefined, moreHoursTypes?: Array | undefined, name?: string | undefined, serviceTypes?: Array | undefined}; export type Categories = {additionalCategories?: Array | undefined, primaryCategory?: Category | undefined}; export type LatLng = {latitude?: number | undefined, longitude?: number | undefined}; export type Metadata = {canDelete?: boolean | undefined, canHaveBusinessCalls?: boolean | undefined, canHaveFoodMenus?: boolean | undefined, canModifyServiceList?: boolean | undefined, canOperateHealthData?: boolean | undefined, canOperateLocalPost?: boolean | undefined, canOperateLodgingData?: boolean | undefined, duplicateLocation?: string | undefined, hasGoogleUpdated?: boolean | undefined, hasPendingEdits?: boolean | undefined, hasVoiceOfMerchant?: boolean | undefined, isParticularlyPersonalPlace?: boolean | undefined, mapsUri?: string | undefined, newReviewUri?: string | undefined, placeId?: string | undefined}; export type TimeOfDay = {hours?: number | undefined, minutes?: number | undefined, nanos?: number | undefined, seconds?: number | undefined}; export type TimePeriod = {closeDay?: ('DAY_OF_WEEK_UNSPECIFIED' | 'MONDAY' | 'TUESDAY' | 'WEDNESDAY' | 'THURSDAY' | 'FRIDAY' | 'SATURDAY' | 'SUNDAY') | undefined, closeTime?: TimeOfDay | undefined, openDay?: ('DAY_OF_WEEK_UNSPECIFIED' | 'MONDAY' | 'TUESDAY' | 'WEDNESDAY' | 'THURSDAY' | 'FRIDAY' | 'SATURDAY' | 'SUNDAY') | undefined, openTime?: TimeOfDay | undefined}; export type MoreHours = {hoursTypeId?: string | undefined, periods?: Array | undefined}; export type Date = {day?: number | undefined, month?: number | undefined, year?: number | undefined}; export type OpenInfo = {canReopen?: boolean | undefined, openingDate?: Date | undefined, status?: ('OPEN_FOR_BUSINESS_UNSPECIFIED' | 'OPEN' | 'CLOSED_PERMANENTLY' | 'CLOSED_TEMPORARILY') | undefined}; export type PhoneNumbers = {additionalPhones?: Array | undefined, primaryPhone?: string | undefined}; export type Profile = {description?: string | undefined}; export type BusinessHours = {periods?: Array | undefined}; export type RelevantLocation = {placeId?: string | undefined, relationType?: ('RELATION_TYPE_UNSPECIFIED' | 'DEPARTMENT_OF' | 'INDEPENDENT_ESTABLISHMENT_IN') | undefined}; export type RelationshipData = {childrenLocations?: Array | undefined, parentChain?: string | undefined, parentLocation?: RelevantLocation | undefined}; export type PlaceInfo = {placeId?: string | undefined, placeName?: string | undefined}; export type Places = {placeInfos?: Array | undefined}; export type ServiceAreaBusiness = {businessType?: ('BUSINESS_TYPE_UNSPECIFIED' | 'CUSTOMER_LOCATION_ONLY' | 'CUSTOMER_AND_BUSINESS_LOCATION') | undefined, places?: Places | undefined, regionCode?: string | undefined}; export type Label = {description?: string | undefined, displayName?: string | undefined, languageCode?: string | undefined}; export type FreeFormServiceItem = {category?: string | undefined, label?: Label | undefined}; export type Money = {currencyCode?: string | undefined, nanos?: number | undefined, units?: unknown | undefined}; export type StructuredServiceItem = {description?: string | undefined, serviceTypeId?: string | undefined}; export type ServiceItem = {freeFormServiceItem?: FreeFormServiceItem | undefined, price?: Money | undefined, structuredServiceItem?: StructuredServiceItem | undefined}; export type SpecialHourPeriod = {closeTime?: TimeOfDay | undefined, closed?: boolean | undefined, endDate?: Date | undefined, openTime?: TimeOfDay | undefined, startDate?: Date | undefined}; export type SpecialHours = {specialHourPeriods?: Array | undefined}; export type PostalAddress = {addressLines?: Array | undefined, administrativeArea?: string | undefined, languageCode?: string | undefined, locality?: string | undefined, organization?: string | undefined, postalCode?: string | undefined, recipients?: Array | undefined, regionCode?: string | undefined, revision?: number | undefined, sortingCode?: string | undefined, sublocality?: string | undefined}; export type Location = {adWordsLocationExtensions?: AdWordsLocationExtensions | undefined, categories?: Categories | undefined, labels?: Array | undefined, languageCode?: string | undefined, latlng?: LatLng | undefined, metadata?: Metadata | undefined, moreHours?: Array | undefined, name?: string | undefined, openInfo?: OpenInfo | undefined, phoneNumbers?: PhoneNumbers | undefined, profile?: Profile | undefined, regularHours?: BusinessHours | undefined, relationshipData?: RelationshipData | undefined, serviceArea?: ServiceAreaBusiness | undefined, serviceItems?: Array | undefined, specialHours?: SpecialHours | undefined, storeCode?: string | undefined, storefrontAddress?: PostalAddress | undefined, title?: string | undefined, websiteUri?: string | undefined}; export type PatchApiV1LocationsLocationsIdArgs = {locationsId: string, updateMask?: unknown | undefined, validateOnly?: boolean | undefined, body: Location}; export type PatchApiV1LocationsLocationsIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const adWordsLocationExtensions = z.object({adPhone: z.string().optional()}); export const moreHoursType = z.object({displayName: z.string().optional(), hoursTypeId: z.string().optional(), localizedDisplayName: z.string().optional()}); export const serviceType = z.object({displayName: z.string().optional(), serviceTypeId: z.string().optional()}); export const category = z.object({displayName: z.string().optional(), moreHoursTypes: z.array(moreHoursType).optional(), name: z.string().optional(), serviceTypes: z.array(serviceType).optional()}); export const categories = z.object({additionalCategories: z.array(category).optional(), primaryCategory: category.optional()}); export const latLng = z.object({latitude: z.number().optional(), longitude: z.number().optional()}); export const metadata = z.object({canDelete: z.boolean().optional(), canHaveBusinessCalls: z.boolean().optional(), canHaveFoodMenus: z.boolean().optional(), canModifyServiceList: z.boolean().optional(), canOperateHealthData: z.boolean().optional(), canOperateLocalPost: z.boolean().optional(), canOperateLodgingData: z.boolean().optional(), duplicateLocation: z.string().optional(), hasGoogleUpdated: z.boolean().optional(), hasPendingEdits: z.boolean().optional(), hasVoiceOfMerchant: z.boolean().optional(), isParticularlyPersonalPlace: z.boolean().optional(), mapsUri: z.string().optional(), newReviewUri: z.string().optional(), placeId: z.string().optional()}); export const timeOfDay = z.object({hours: z.number().int().optional(), minutes: z.number().int().optional(), nanos: z.number().int().optional(), seconds: z.number().int().optional()}); export const timePeriod = z.object({closeDay: z.enum(["DAY_OF_WEEK_UNSPECIFIED", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"]).optional(), closeTime: timeOfDay.optional(), openDay: z.enum(["DAY_OF_WEEK_UNSPECIFIED", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"]).optional(), openTime: timeOfDay.optional()}); export const moreHours = z.object({hoursTypeId: z.string().optional(), periods: z.array(timePeriod).optional()}); export const date = z.object({day: z.number().int().optional(), month: z.number().int().optional(), year: z.number().int().optional()}); export const openInfo = z.object({canReopen: z.boolean().optional(), openingDate: date.optional(), status: z.enum(["OPEN_FOR_BUSINESS_UNSPECIFIED", "OPEN", "CLOSED_PERMANENTLY", "CLOSED_TEMPORARILY"]).optional()}); export const phoneNumbers = z.object({additionalPhones: z.array(z.string()).optional(), primaryPhone: z.string().optional()}); export const profile = z.object({description: z.string().optional()}); export const businessHours = z.object({periods: z.array(timePeriod).optional()}); export const relevantLocation = z.object({placeId: z.string().optional(), relationType: z.enum(["RELATION_TYPE_UNSPECIFIED", "DEPARTMENT_OF", "INDEPENDENT_ESTABLISHMENT_IN"]).optional()}); export const relationshipData = z.object({childrenLocations: z.array(relevantLocation).optional(), parentChain: z.string().optional(), parentLocation: relevantLocation.optional()}); export const placeInfo = z.object({placeId: z.string().optional(), placeName: z.string().optional()}); export const places = z.object({placeInfos: z.array(placeInfo).optional()}); export const serviceAreaBusiness = z.object({businessType: z.enum(["BUSINESS_TYPE_UNSPECIFIED", "CUSTOMER_LOCATION_ONLY", "CUSTOMER_AND_BUSINESS_LOCATION"]).optional(), places: places.optional(), regionCode: z.string().optional()}); export const label = z.object({description: z.string().optional(), displayName: z.string().optional(), languageCode: z.string().optional()}); export const freeFormServiceItem = z.object({category: z.string().optional(), label: label.optional()}); export const money = z.object({currencyCode: z.string().optional(), nanos: z.number().int().optional(), units: z.string().optional()}); export const structuredServiceItem = z.object({description: z.string().optional(), serviceTypeId: z.string().optional()}); export const serviceItem = z.object({freeFormServiceItem: freeFormServiceItem.optional(), price: money.optional(), structuredServiceItem: structuredServiceItem.optional()}); export const specialHourPeriod = z.object({closeTime: timeOfDay.optional(), closed: z.boolean().optional(), endDate: date.optional(), openTime: timeOfDay.optional(), startDate: date.optional()}); export const specialHours = z.object({specialHourPeriods: z.array(specialHourPeriod).optional()}); export const postalAddress = z.object({addressLines: z.array(z.string()).optional(), administrativeArea: z.string().optional(), languageCode: z.string().optional(), locality: z.string().optional(), organization: z.string().optional(), postalCode: z.string().optional(), recipients: z.array(z.string()).optional(), regionCode: z.string().optional(), revision: z.number().int().optional(), sortingCode: z.string().optional(), sublocality: z.string().optional()}); export const location = z.object({adWordsLocationExtensions: adWordsLocationExtensions.optional(), categories: categories.optional(), labels: z.array(z.string()).optional(), languageCode: z.string().optional(), latlng: latLng.optional(), metadata: metadata.optional(), moreHours: z.array(moreHours).optional(), name: z.string().optional(), openInfo: openInfo.optional(), phoneNumbers: phoneNumbers.optional(), profile: profile.optional(), regularHours: businessHours.optional(), relationshipData: relationshipData.optional(), serviceArea: serviceAreaBusiness.optional(), serviceItems: z.array(serviceItem).optional(), specialHours: specialHours.optional(), storeCode: z.string().optional(), storefrontAddress: postalAddress.optional(), title: z.string().optional(), websiteUri: 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 }; /** * Updates the specified location. * * PATCH /v1/locations/{locationsId} */ export const patchApiV1LocationsLocationsId = async (args: PatchApiV1LocationsLocationsIdArgs, options?: PatchApiV1LocationsLocationsIdOptions) => { const {baseUrl = "https://mybusinessbusinessinformation.googleapis.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.updateMask != null) query.append("updateMask", String(args.updateMask)) if (args.validateOnly != null) query.append("validateOnly", String(args.validateOnly)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/locations/${encodeURIComponent(String(args.locationsId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(location, await res.json()) };