import {z} from 'zod' export type CreatePaymentAccountMigrationModel = {accountNumber?: (string | null) | undefined, accountHolder?: (string | null) | undefined, expiryMonth?: (string | null) | undefined, expiryYear?: (string | null) | undefined, paymentMethod?: (string | null) | undefined, payerEmail?: (string | null) | undefined, payerReference?: (string | null) | undefined, isVirtual?: boolean | undefined, inactiveReason?: (string | null) | undefined}; export type PersonAddressModel = {addressLine1?: (string | null) | undefined, addressLine2?: (string | null) | undefined, postalCode?: (string | null) | undefined, city?: (string | null) | undefined, regionCode?: (string | null) | undefined, countryCode?: (string | null) | undefined}; export type PersonCompanyMigrationModel = {name?: (string | null) | undefined, taxId?: (string | null) | undefined}; export type BookerMigrationModel = {title?: ('Mr' | 'Ms' | 'Dr' | 'Prof' | 'Mrs' | 'Other' | null) | undefined, gender?: ('Female' | 'Male' | 'Other' | 'Unknown' | null) | undefined, firstName?: (string | null) | undefined, middleInitial?: (string | null) | undefined, lastName: string, email?: (string | null) | undefined, phone?: (string | null) | undefined, address?: PersonAddressModel | undefined, nationalityCountryCode?: (string | null) | undefined, identificationNumber?: (string | null) | undefined, identificationIssueDate?: (string | null) | undefined, identificationExpiryDate?: (string | null) | undefined, identificationType?: ('SocialInsuranceNumber' | 'PassportNumber' | 'IdNumber' | 'DriverLicenseNumber' | 'VisaNumber' | 'ForeignerIdentityNumber' | 'TaxIdentificationNumber' | 'Other' | null) | undefined, company?: PersonCompanyMigrationModel | undefined, preferredLanguage?: (string | null) | undefined, birthDate?: (string | null) | undefined, birthPlace?: (string | null) | undefined}; export type GuestMigrationModel = {title?: ('Mr' | 'Ms' | 'Dr' | 'Prof' | 'Mrs' | 'Other' | null) | undefined, gender?: ('Female' | 'Male' | 'Other' | 'Unknown' | null) | undefined, firstName?: (string | null) | undefined, middleInitial?: (string | null) | undefined, lastName: string, secondLastName?: (string | null) | undefined, email?: (string | null) | undefined, phone?: (string | null) | undefined, address?: PersonAddressModel | undefined, nationalityCountryCode?: (string | null) | undefined, identificationNumber?: (string | null) | undefined, identificationAdditionalNumber?: (string | null) | undefined, identificationIssueDate?: (string | null) | undefined, identificationExpiryDate?: (string | null) | undefined, identificationIssuePlace?: (string | null) | undefined, identificationType?: ('SocialInsuranceNumber' | 'PassportNumber' | 'IdNumber' | 'DriverLicenseNumber' | 'VisaNumber' | 'ForeignerIdentityNumber' | 'TaxIdentificationNumber' | 'Other' | null) | undefined, personalTaxId?: (string | null) | undefined, company?: PersonCompanyMigrationModel | undefined, preferredLanguage?: (string | null) | undefined, birthDate?: (string | null) | undefined, birthPlace?: (string | null) | undefined, birthFirstName?: (string | null) | undefined, birthLastName?: (string | null) | undefined, motherFirstName?: (string | null) | undefined, motherLastName?: (string | null) | undefined, borderCrossingPlace?: (string | null) | undefined, borderCrossingDate?: (string | null) | undefined, nextDestination?: (string | null) | undefined, relationshipToPrimaryGuest?: ('Grandparent' | 'Grandchild' | 'GreatGrandparent' | 'GreatGrandchild' | 'Parent' | 'Child' | 'Sibling' | 'ParentInLaw' | 'ChildInLaw' | 'SiblingInLaw' | 'Spouse' | 'UncleOrAunt' | 'NephewOrNiece' | 'Guardian' | 'Other' | null) | undefined}; export type MonetaryValueModel = {amount: number, currency: string}; export type CreateReservationTimeSliceMigrationModel = {ratePlanId: string, totalAmount?: MonetaryValueModel | undefined}; export type Date = {serviceDate: string, count?: (number | null) | undefined, amount?: MonetaryValueModel | undefined}; export type BookReservationServiceMigrationModel = {serviceId: string, count?: (number | null) | undefined, amount?: MonetaryValueModel | undefined, dates?: (Array | null) | undefined}; export type CommissionModel = {commissionAmount: MonetaryValueModel, beforeCommissionAmount?: MonetaryValueModel | undefined}; export type ExternalReferencesMigrationModel = {globalDistributionSystemId?: (string | null) | undefined, onlineTravelAgencyId?: (string | null) | undefined, onlineBookingToolId?: (string | null) | undefined, channelManagerId?: (string | null) | undefined, centralReservationSystemId?: (string | null) | undefined, legacyId?: (string | null) | undefined}; export type RegisteredCardModel = {cardNumber?: (string | null) | undefined, cardHolder?: (string | null) | undefined, expiryMonth?: (string | null) | undefined, expiryYear?: (string | null) | undefined, paymentMethod?: (string | null) | undefined, payerEmail?: (string | null) | undefined, note?: (string | null) | undefined, isVirtual?: boolean | undefined}; export type CreateReservationMigrationModel = {arrival: string, departure: string, adults: number, childrenAges?: (Array | null) | undefined, comment?: (string | null) | undefined, guestComment?: (string | null) | undefined, externalCode?: (string | null) | undefined, channelCode: 'Direct' | 'BookingCom' | 'Ibe' | 'ChannelManager' | 'Expedia' | 'Homelike' | 'Hrs' | 'AltoVita' | 'DesVu' | 'Gimsi', source?: (string | null) | undefined, primaryGuest?: GuestMigrationModel | undefined, additionalGuests?: (Array | null) | undefined, guaranteeType?: ('PM6Hold' | 'CreditCard' | 'Prepayment' | 'Company' | null) | undefined, travelPurpose?: ('Business' | 'Leisure' | null) | undefined, timeSlices: Array, services?: (Array | null) | undefined, companyId?: (string | null) | undefined, corporateCode?: (string | null) | undefined, prePaymentAmount?: MonetaryValueModel | undefined, commission?: CommissionModel | undefined, promoCode?: (string | null) | undefined, externalReferences?: ExternalReferencesMigrationModel | undefined, registeredCard?: RegisteredCardModel | undefined}; export type CreateBookingMigrationModel = {paymentAccount?: CreatePaymentAccountMigrationModel | undefined, booker: BookerMigrationModel, comment?: (string | null) | undefined, bookerComment?: (string | null) | undefined, reservations: Array, transactionReference?: (string | null) | undefined, registeredCard?: RegisteredCardModel | undefined}; export type CreateApiDataV0NsfwBookingsArgs = {'Idempotency-Key'?: string | undefined, body: CreateBookingMigrationModel}; export type CreateApiDataV0NsfwBookingsOptions = {baseUrl: string, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const reservationCreatedMigrationModel = z.object({id: z.string()}); export const bookingCreatedMigrationModel = z.object({id: z.string(), reservationIds: z.array(reservationCreatedMigrationModel)}); 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 }; /** *
You must have this scope: 'reservations.import'. * * POST /data/v0-nsfw/bookings */ export const createApiDataV0NsfwBookings = async (args: CreateApiDataV0NsfwBookingsArgs, options: CreateApiDataV0NsfwBookingsOptions) => { const {baseUrl, fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/data/v0-nsfw/bookings${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(bookingCreatedMigrationModel, await res.json()) };