import {z} from 'zod' export type DayOfTheWeekType = 'MONDAY' | 'TUESDAY' | 'WEDNESDAY' | 'THURSDAY' | 'FRIDAY' | 'SATURDAY' | 'SUNDAY'; export type BusinessHoursSlotInput = {start: string, end: string}; export type BusinessHours = 'OPEN' | 'CLOSED'; export type BusinessHoursDayInput = {day: DayOfTheWeekType, slots?: Array | undefined, type: BusinessHours}; export type MoreHourDayInput = {day: DayOfTheWeekType, openTime?: string | undefined, closeTime?: string | undefined}; export type MoreHourInput = {type: string, days?: Array | undefined}; export type PlaceInfoInput = {placeId: string, placeName?: string | undefined}; export type ServiceAreaInput = {businessType?: string | undefined, regionCode?: string | undefined, placeInfos?: Array | undefined}; export type CustomAttributeInputTypeEnum = 'STRING' | 'NUMBER' | 'BOOLEAN' | 'DATE' | 'ENUM' | 'URL'; export type CustomAttributeLevelTypeEnum = 'ACCOUNT' | 'LOCATION'; export type CustomAttributeInputType = {name: string, value?: string | undefined, type?: CustomAttributeInputTypeEnum | undefined, levelType?: CustomAttributeLevelTypeEnum | undefined}; export type PlaceActionTypeEnum = 'APPOINTMENT' | 'ONLINE_APPOINTMENT' | 'DINING_RESERVATION' | 'FOOD_ORDERING' | 'FOOD_DELIVERY' | 'FOOD_TAKEOUT' | 'SHOP_ONLINE'; export type PlaceActionLinkInputType = {placeActionType: PlaceActionTypeEnum, uri: string, isPreferred?: boolean | undefined, name?: string | undefined, providerType?: string | undefined, isEditable?: boolean | undefined, action?: string | undefined}; export type LanguageEnumType = 'ENGLISH' | 'SPANISH' | 'PORTUGUESE' | 'FRENCH' | 'GERMAN' | 'JAPANESE' | 'ABKHAZIAN' | 'AFAR' | 'AFRIKAANS' | 'AKAN' | 'ALBANIAN' | 'AMHARIC' | 'ARABIC' | 'ARAGONESE' | 'ARMENIAN' | 'ASSAMESE' | 'AVARIC' | 'AVESTAN' | 'AYMARA' | 'AZERBAIJANI' | 'BAMBARA' | 'BASHKIR' | 'BASQUE' | 'BELARUSIAN' | 'BENGALI' | 'BISLAMA' | 'BOSNIAN' | 'BRETON' | 'BULGARIAN' | 'BURMESE' | 'CATALAN' | 'CHAMORRO' | 'CHECHEN' | 'CHICHEWA' | 'CHINESE' | 'CHUVASH' | 'CORNISH' | 'CORSICAN' | 'CREE' | 'CROATIAN' | 'CZECH' | 'DANISH' | 'DIVEHI' | 'DUTCH' | 'DZONGKHA' | 'ESPERANTO' | 'ESTONIAN' | 'EWE' | 'FAROESE' | 'FIJIAN' | 'FINNISH' | 'FULAH' | 'GALICIAN' | 'GEORGIAN' | 'GREEK' | 'GUARANI' | 'GUJARATI' | 'HAITIAN' | 'HAUSA' | 'HEBREW' | 'HERERO' | 'HINDI' | 'HIRI_MOTU' | 'HUNGARIAN' | 'ICELANDIC' | 'IGBO' | 'INDONESIAN' | 'INTERLINGUA' | 'INTERLINGUE' | 'INUKTITUT' | 'INUPIAQ' | 'IRISH' | 'ITALIAN' | 'JAVANESE' | 'KANNADA' | 'KANURI' | 'KASHMIRI' | 'KAZAKH' | 'KHMER' | 'KIKUYU' | 'KINYARWANDA' | 'KIRGHIZ' | 'KOMI' | 'KOREAN' | 'KURDISH' | 'LAO' | 'LATIN' | 'LATVIAN' | 'LIMBURGAN' | 'LINGALA' | 'LITHUANIAN' | 'LUBA_KATANGA' | 'LUXEMBOURGISH' | 'MACEDONIAN' | 'MALAGASY' | 'MALAY' | 'MALAYALAM' | 'MALTESE' | 'MANX' | 'MAORI' | 'MARATHI' | 'MARSHALLESE' | 'MONGOLIAN' | 'NAURU' | 'NAVAJO' | 'NDONGA' | 'NEPALI' | 'NORTHERN_SAMI' | 'NORWEGIAN' | 'NORWEGIAN_BOKMAL' | 'NORWEGIAN_NYNORSK' | 'OCCITAN' | 'OJIBWA' | 'ORIYA' | 'OROMO' | 'OSSETIAN' | 'PASHTO' | 'PERSIAN' | 'POLISH' | 'PUNJABI' | 'QUECHUA' | 'ROMANIAN' | 'ROMANSH' | 'RUSSIAN' | 'SAMOAN' | 'SANGO' | 'SANSKRIT' | 'SCOTTISH_GAELIC' | 'SERBIAN' | 'SHONA' | 'SINDHI' | 'SINHALA' | 'SLOVAK' | 'SLOVENIAN' | 'SOMALI' | 'SOUTHERN_SOTHO' | 'SUNDANESE' | 'SWAHILI' | 'SWEDISH' | 'TAGALOG' | 'TAJIK' | 'TAMIL' | 'TATAR' | 'TELUGU' | 'THAI' | 'TIBETAN' | 'TIGRINYA' | 'TONGA' | 'TSONGA' | 'TSWANA' | 'TURKISH' | 'TURKMEN' | 'TWI' | 'UIGHUR' | 'UKRAINIAN' | 'URDU' | 'UZBEK' | 'VENDA' | 'VIETNAMESE' | 'VOLAPUK' | 'WALLOON' | 'WELSH' | 'WESTERN_FRISIAN' | 'WOLOF' | 'XHOSA' | 'YIDDISH' | 'YORUBA' | 'ZULU'; export type ServiceItemInputType = {name: string, categoryId?: string | undefined, price?: number | undefined, description?: string | undefined, currencyCode?: string | undefined}; export type PaymentMethodType = 'VISA' | 'MASTERCARD' | 'AMEX' | 'CASH' | 'CHEQUE' | 'CRYPTO' | 'DINERS_CLUB' | 'DISCOVER' | 'FINANCING' | 'INVOICE' | 'TRAVELERS_CHECK' | 'APPLE_PAY' | 'SAMSUNG_PAY' | 'PAYPAL' | 'ANDROID_PAY'; export type UpdateLocationInput = {clientMutationId?: string | undefined, id: string, name?: string | undefined, storeId?: string | undefined, street?: string | undefined, city?: string | undefined, stateIso?: string | undefined, postalCode?: string | undefined, countryIso?: string | undefined, subCategoryId?: number | undefined, phone?: string | undefined, businessHours?: Array | undefined, moreHours?: Array | undefined, serviceArea?: ServiceAreaInput | undefined, customAttributes?: Array | undefined, placeActionLinks?: Array | undefined, bizUrl?: string | undefined, primaryGbpSiteCategoryId?: string | undefined, additionalGbpSiteCategoryIds?: Array | undefined, offeringsUrl?: string | undefined, bookingUrl?: string | undefined, reservationUrl?: string | undefined, street1?: string | undefined, latitude?: string | undefined, longitude?: string | undefined, ownerEmail?: string | undefined, ownerName?: string | undefined, facebookUrl?: string | undefined, twitterUrl?: string | undefined, linkedinUrl?: string | undefined, instagramUrl?: string | undefined, youtubeUrl?: string | undefined, tiktokUrl?: string | undefined, pinterestUrl?: string | undefined, tagline?: string | undefined, description?: string | undefined, yearOfIncorporation?: string | undefined, enabledSiteIds?: Array | undefined, googleAdsPhone?: string | undefined, additionalPhones?: Array | undefined, videos?: Array | undefined, additionalCategoryIds?: Array | undefined, submissionDisabledSiteIds?: Array | undefined, updateOnlySiteIds?: Array | undefined, hideAddress?: boolean | undefined, temporarilyClosed?: boolean | undefined, contentPreferredLanguage?: LanguageEnumType | undefined, serviceItems?: Array | undefined, paymentMethods?: Array | undefined}; export type CreateApiApiV4LocationsUpdateArgs = {body: {input: UpdateLocationInput}}; export type CreateApiApiV4LocationsUpdateOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const locationStatusType = z.enum(["ACTIVE", "ARCHIVED", "PENDING", "TEMPORARILY_CLOSED", "SCHEDULED_FOR_ARCHIVE"]); export const placeInfoType = z.object({placeId: z.string(), placeName: z.string().optional()}); export const serviceAreaType = z.object({businessType: z.string().optional(), regionCode: z.string().optional(), placeInfos: z.array(placeInfoType).optional()}); export const placeActionLinkType = z.object({placeActionType: z.string(), uri: z.string(), isPreferred: z.boolean().optional(), name: z.string().optional(), providerType: z.string().optional(), isEditable: z.boolean().optional(), submissionStatus: z.string().optional(), submissionMessage: z.string().optional(), submissionCode: z.string().optional(), lastSubmittedAt: z.string().optional()}); export const locationSummaryType = z.object({id: z.string(), databaseId: z.number().int().optional(), storeId: z.string().optional(), name: z.string(), street: z.string().optional(), city: z.string().optional(), stateIso: z.string().optional(), countryIso: z.string().optional(), postalCode: z.string().optional(), latitude: z.number().optional(), longitude: z.number().optional(), phone: z.string().optional(), website: z.string().optional(), status: locationStatusType.optional(), primaryGbpSiteCategoryId: z.string().optional(), additionalGbpSiteCategoryIds: z.array(z.string()).optional(), serviceArea: z.array(serviceAreaType).optional(), placeActionLinks: z.array(placeActionLinkType).optional(), discoveredPlaceActionLinks: z.array(placeActionLinkType).optional()}); export const mutationErrorType = z.object({code: z.string().optional(), message: z.string(), path: z.array(z.string()).optional()}); export const updateLocationPayload = z.object({clientMutationId: z.string().optional(), location: locationSummaryType.optional(), errors: z.array(mutationErrorType).optional(), success: z.boolean().optional()}); export const apiError = z.object({message: z.string(), code: z.string().optional(), contextInfo: z.array(z.object({key: z.string().optional(), value: z.string().optional()})).optional()}); export const createApiApiV4LocationsUpdateResponse = z.object({data: z.object({updateLocation: updateLocationPayload.optional()}), errors: z.array(apiError).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 }; /** * Update information on a location. * * POST /api/v4/locations/update * * Also accepts auth: rapidApiKey + rapidApiHost */ export const createApiApiV4LocationsUpdate = async (args: CreateApiApiV4LocationsUpdateArgs, options?: CreateApiApiV4LocationsUpdateOptions) => { const {baseUrl = "https://listingsapi.com", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v4/locations/update${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(createApiApiV4LocationsUpdateResponse, await res.json()) };