import {z} from 'zod' export type BookingSummary = {from?: string | undefined, id?: number | undefined, to?: string | undefined}; export type DBStringSlice = Array; export type ReviewOwner = {avatar_url?: string | undefined, first_name?: string | undefined, id?: number | undefined, last_name?: string | undefined}; export type OwnerResponseReview = {text?: string | undefined, timestamp?: string | undefined}; export type CampsiteSummary = {beds?: number | undefined, campground_id?: number | undefined, campground_name?: string | undefined, campground_sitemap_url?: string | undefined, display_campsite_type?: string | undefined, display_max_vehicle_length?: string | undefined, display_site_type?: string | undefined, is_odn?: boolean | undefined, rental_id?: number | undefined, site_type?: string | undefined, sleeps?: number | undefined, type?: string | undefined}; export type StaySummary = {baths?: number | undefined, bedrooms?: number | undefined, beds?: number | undefined, check_in_type?: string | undefined, display_stay_type?: string | undefined, location_description?: string | undefined, max_parking_spaces?: number | undefined, parking_onsite?: boolean | undefined, rental_id?: number | undefined, sleeps?: number | undefined, type?: string | undefined}; export type RentalSummary = {campsite_summary?: CampsiteSummary | undefined, disallow_movement?: boolean | undefined, display_type?: string | undefined, formatted_length?: string | undefined, id?: number | undefined, interior_primary_image_url?: string | undefined, internal_id?: string | undefined, location?: string | undefined, name?: string | undefined, primary_image_url?: string | undefined, rental_category?: string | undefined, sleeps?: number | undefined, slug?: string | undefined, stay_summary?: StaySummary | undefined, style?: string | undefined, type?: string | undefined}; export type TagRental = {Created?: string | undefined, ID?: number | undefined, Name?: string | undefined, Slug?: string | undefined, Updated?: string | undefined, position?: number | undefined, usage_by_rental_count?: number | undefined}; export type ID = string; export type ReviewImage = {created?: string | undefined, id?: ID | undefined, lat?: number | undefined, lng?: number | undefined, rental_id?: string | undefined, review_id?: string | undefined, reviewed?: boolean | undefined, reviewed_by?: string | undefined, status?: string | undefined, updated?: string | undefined, url?: string | undefined}; export type Reviewer = {avatar_url?: string | undefined, first_name?: string | undefined, id?: number | undefined, last_name?: string | undefined}; export type Tag = {allow_for_review?: boolean | undefined, created?: string | undefined, description?: string | undefined, id?: number | undefined, name?: string | undefined, owner_user_id?: (number | null) | undefined, position?: number | undefined, slug?: string | undefined, updated?: string | undefined}; export type Review = {apply_credit?: boolean | undefined, booking_id?: number | undefined, booking_summary?: BookingSummary | undefined, can_edit?: boolean | undefined, can_edit_until?: string | undefined, cleanliness_score?: number | undefined, communication_score?: number | undefined, deleted?: string | undefined, exclude_from_rating?: boolean | undefined, id?: number | undefined, images?: DBStringSlice | undefined, imported?: boolean | undefined, listing_score?: number | undefined, mechanical_score?: number | undefined, name?: string | undefined, outdoorsy_only?: boolean | undefined, owner?: ReviewOwner | undefined, owner_can_respond?: boolean | undefined, owner_response?: OwnerResponseReview | undefined, published?: boolean | undefined, rental_id?: number | undefined, rental_summary?: RentalSummary | undefined, rental_tags?: Array | undefined, review_images?: Array | undefined, reviewer?: Reviewer | undefined, reviewer_id?: number | undefined, score?: number | undefined, source_page?: string | undefined, tags?: Array | undefined, text?: string | undefined, timestamp?: string | undefined, user_id?: number | undefined, user_recommend?: boolean | undefined, value_score?: number | undefined}; export type CreateApiReviewsArgs = {body: Review}; export type CreateApiReviewsOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const bookingSummary = z.object({from: z.string().optional(), id: z.number().int().optional(), to: z.string().optional()}); export const dBStringSlice = z.array(z.string()); export const reviewOwner = z.object({avatar_url: z.string().optional(), first_name: z.string().optional(), id: z.number().int().optional(), last_name: z.string().optional()}); export const ownerResponseReview = z.object({text: z.string().optional(), timestamp: z.string().optional()}); export const campsiteSummary = z.object({beds: z.number().int().optional(), campground_id: z.number().int().optional(), campground_name: z.string().optional(), campground_sitemap_url: z.string().optional(), display_campsite_type: z.string().optional(), display_max_vehicle_length: z.string().optional(), display_site_type: z.string().optional(), is_odn: z.boolean().optional(), rental_id: z.number().int().optional(), site_type: z.string().optional(), sleeps: z.number().int().optional(), type: z.string().optional()}); export const staySummary = z.object({baths: z.number().int().optional(), bedrooms: z.number().int().optional(), beds: z.number().int().optional(), check_in_type: z.string().optional(), display_stay_type: z.string().optional(), location_description: z.string().optional(), max_parking_spaces: z.number().int().optional(), parking_onsite: z.boolean().optional(), rental_id: z.number().int().optional(), sleeps: z.number().int().optional(), type: z.string().optional()}); export const rentalSummary = z.object({campsite_summary: campsiteSummary.optional(), disallow_movement: z.boolean().optional(), display_type: z.string().optional(), formatted_length: z.string().optional(), id: z.number().int().optional(), interior_primary_image_url: z.string().optional(), internal_id: z.string().optional(), location: z.string().optional(), name: z.string().optional(), primary_image_url: z.string().optional(), rental_category: z.string().optional(), sleeps: z.number().int().optional(), slug: z.string().optional(), stay_summary: staySummary.optional(), style: z.string().optional(), type: z.string().optional()}); export const tagRental = z.object({Created: z.string().optional(), ID: z.number().int().optional(), Name: z.string().optional(), Slug: z.string().optional(), Updated: z.string().optional(), position: z.number().int().optional(), usage_by_rental_count: z.number().int().optional()}); export const iD = z.string(); export const reviewImage = z.object({created: z.string().optional(), id: iD.optional(), lat: z.number().optional(), lng: z.number().optional(), rental_id: z.string().optional(), review_id: z.string().optional(), reviewed: z.boolean().optional(), reviewed_by: z.string().optional(), status: z.string().optional(), updated: z.string().optional(), url: z.string().optional()}); export const reviewer = z.object({avatar_url: z.string().optional(), first_name: z.string().optional(), id: z.number().int().optional(), last_name: z.string().optional()}); export const tag = z.object({allow_for_review: z.boolean().optional(), created: z.string().optional(), description: z.string().optional(), id: z.number().int().optional(), name: z.string().optional(), owner_user_id: z.number().int().nullable().optional(), position: z.number().int().optional(), slug: z.string().optional(), updated: z.string().optional()}); export const review = z.object({apply_credit: z.boolean().optional(), booking_id: z.number().int().optional(), booking_summary: bookingSummary.optional(), can_edit: z.boolean().optional(), can_edit_until: z.string().optional(), cleanliness_score: z.number().optional(), communication_score: z.number().optional(), deleted: z.string().optional(), exclude_from_rating: z.boolean().optional(), id: z.number().int().optional(), images: dBStringSlice.optional(), imported: z.boolean().optional(), listing_score: z.number().optional(), mechanical_score: z.number().optional(), name: z.string().optional(), outdoorsy_only: z.boolean().optional(), owner: reviewOwner.optional(), owner_can_respond: z.boolean().optional(), owner_response: ownerResponseReview.optional(), published: z.boolean().optional(), rental_id: z.number().int().optional(), rental_summary: rentalSummary.optional(), rental_tags: z.array(tagRental).optional(), review_images: z.array(reviewImage).optional(), reviewer: reviewer.optional(), reviewer_id: z.number().int().optional(), score: z.number().optional(), source_page: z.string().optional(), tags: z.array(tag).optional(), text: z.string().optional(), timestamp: z.string().optional(), user_id: z.number().int().optional(), user_recommend: z.boolean().optional(), value_score: 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 }; /** * Create a new review for a user or rental owner * * POST /reviews * * Also accepts auth: API-Key */ export const createApiReviews = async (args: CreateApiReviewsArgs, options: CreateApiReviewsOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/reviews${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(review, await res.json()) };