import {z} from 'zod' export type GetApiApiReservationsUpsellInquiryIdListingIdFeeArgs = {inquiryId: string, listingId: string}; export type GetApiApiReservationsUpsellInquiryIdListingIdFeeOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiReservationsUpsellInquiryIdListingIdFeeResponse = z.array(z.object({_id: z.string().optional(), value: z.number().optional(), isPercentage: z.boolean().optional(), name: z.string().optional(), channelFeeType: z.enum(["ADDITIONAL_BED", "AIR_CONDITIONING", "EARLY_CHECK_IN", "LATE_CHECK_IN", "BABY_BED", "CLEANING", "CLUB_CARD", "CONCIERGE", "EARLY_CHECKOUT", "LATE_CHECKOUT", "DEPOSIT", "ELECTRICITY", "FOOD", "HEATING", "INTERNET", "LAUNDRY", "LINENS", "TOWELS", "MANAGEMENT", "OIL", "PARKING", "PET", "POOL", "POOL_HEATING", "RESORT", "SERVICE", "TOILETRIES", "TOUR", "TRANSPORTATION", "CAR_RENTAL", "WATER", "WOOD", "TRANSFER", "HOUSEKEEPING", "INSURANCE", "COMMUNITY", "CREDIT_CARD_PROCESSING_FEE", "DAMAGE_WAIVER", "VIP_SERVICES", "PAYMENT_FEE", "ADDITIONAL_CHARGE", "MISCELLANEOUS", "SHIPPING", "VALET", "ACTIVITIES", "FLIGHTS", "GIFT_BASKET", "SPA", "CHEF", "MEET_AND_GREET", "DOCK_FEE", "UTILITY_FEE", "HOT_TUB", "BOOKING_FEE", "BREAKFAST", "BEVERAGE", "MEAL", "WELLNESS", "MINIBAR", "BUSINESS_CENTER", "WIFI", "GUEST_SERVICE", "COMMISSION_CHARGE", "EQUIPMENT_RENTAL", "RESERVATION_FEE", "DAMAGE_CHARGE", "HOMEOWNERS_ASSOCIATION", "GOLF_CART_RENTAL"]).optional(), isUpsell: z.boolean().optional(), upsell: z.object({images: z.array(z.object({url: z.string().optional(), isDefault: z.boolean().optional()})).optional(), description: z.string().optional()}).optional(), multiplier: z.enum(["PER_NIGHT", "PER_GUEST", "PER_GUEST_PER_NIGHT", "PER_STAY"]).optional(), price: z.number().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 }; /** * Retrieve upsell [Pilot] * * GET /api/reservations/upsell/{inquiryId}/{listingId}/fee */ export const getApiApiReservationsUpsellInquiryIdListingIdFee = async (args: GetApiApiReservationsUpsellInquiryIdListingIdFeeArgs, options?: GetApiApiReservationsUpsellInquiryIdListingIdFeeOptions) => { const {baseUrl = "https://booking.guesty.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set("authorization", bearerAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/reservations/upsell/${encodeURIComponent(String(args.inquiryId))}/${encodeURIComponent(String(args.listingId))}/fee${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiApiReservationsUpsellInquiryIdListingIdFeeResponse, await res.json()) };