aves-sdk 1.5.1 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{request as e}from"undici";import*as t from"valibot";import{ValiError as n,parse as r,safeParse as i}from"valibot";import a from"fast-xml-builder";import{XMLParser as o}from"fast-xml-parser";const s={VALIDATION:`validation`,API:`api`,UNKNOWN:`unknown`};var c=class extends Error{kind;message;status;code;constructor(e,t,n,r){super(t),this.kind=e,this.message=t,this.status=n,this.code=r,this.name=`AvesError`,this.status=n?.toLowerCase(),this.code=this.parseCode(r)}parseCode(e){return typeof e==`string`?Number.parseInt(e,10):e??0}};function l(e){return new c(s.VALIDATION,e)}function u(e,t,n){return new c(s.API,e,t,n)}function d(e){return new c(s.UNKNOWN,e)}function ee(e){return e.map(f).join(`; `)}function f(e){let t=te(e.path),n=e.message??`Invalid value`;return t?`${t}: ${n}`:n}function te(e){if(!e||e.length===0)return;let t=e.map(ne).filter(e=>e!==void 0);return t.length>0?t.join(`.`):void 0}function ne(e){if(typeof e==`string`||typeof e==`number`)return String(e);if(typeof e==`object`&&e&&`key`in e)return String(e.key)}function re(e){return e instanceof Error&&e.name===`AbortError`}function ie(e){return e.charAt(0).toUpperCase()+e.slice(1)}function ae(e){return e.charAt(0).toLowerCase()+e.slice(1)}function p(e){return e instanceof Date||e instanceof RegExp||e instanceof Map||e instanceof Set||e instanceof Error}const m=new Set(Object.values({header:[`hostID`,`xtoken`,`interface`,`userName`,`status`],masterRecord:[`recordCode`,`insertCriteria`],financialDetail:[`currencyCode`,`creditLimit`,`c_PaymentType`,`c_SpecPaymentTypeCode`,`s_PaymentType`,`s_SpecPaymentTypeCode`,`enableElectronicInvoicing`,`electronicInvoicingType`],idDocumentDetail:[`idType`,`idCode`,`idIssueLocation`,`idIssueCounty`,`idIssueDate`,`idExpireDate`],accountPolicies:[`acceptProfilingPolicies`,`acceptPrivacyPolicies`,`acceptNewsletterPolicies`],dynamicFields:[`key`,`value`],search:[`minDate`,`maxDate`],bookingFileStatus:[`value`,`expiredDate`],statisticCodes:[`sCode1`,`sCode2`,`sCode3`,`sCode4`,`sCode5`,`sCode6`],destination:[`code`,`iataCode`,`nationCode`],customerDetail:[`recordCode`],bookingFileDocument:[`printDoc`,`sendDocViaEmail`],financialDeadlineDetail:[`reschedulingCode`,`expireDate`,`totalAmount`],deadlineDetail:[`deadlineCode`,`description`,`expireDate`],paymentDetail:[`paymentDate`,`paumentNote`,`amount`,`paymentUser`,`paymentType`],filePaymentDetail:[`paymentDate`,`paymentNote`,`payerMasterCode`,`payerName`,`amount`,`paymentType`],selectedPackageDetail:[`pCode`,`startDate`,`endDate`,`getServicesFromPackage`],selectedServiceDetail:[`sCode`,`ssCode`,`supplierMasterCode`,`supplierName`,`supplierMasterSearchField`,`supplierFiscalCode`],extraQuoteServiceDetail:[`sCode`,`ssCode`,`supplierMasterCode`,`supplierName`,`supplierMasterSearchField`,`supplierFiscalCode`],serviceFare:[`currencyCode`,`exchangeRate`,`cost`,`costTax`,`costType`,`vatCostCurrencyCode`,`price`,`priceTax`,`priceType`],cancellableBookedServiceDetail:[`cancelOperationType`,`serviceRefType`,`serviceRefValue`],fileStatus:[`value`,`expiredDate`,`optionedFileExpireDatePolicy`],penalty:[`apply`,`specificCode`],noteDetail:[`nType`,`title`],passengerDetail:[`rph`,`roomRph`,`billingHolder`],bookingFinancialInfo:[`customer_PaymentType`,`customer_SpecPaymentTypeCode`],reservationFormCustomizablePrintParameters:[`makeDocumentTo`],supplierRefMasterRecords:[`supplierRefCode`,`companyMainBusinessType`,`carrierType`]}).flat()),oe=(e,t,n=!1)=>n||t===`sCode`||t===`ssCode`||t===`pCode`?`@${t}`:`@${e}`,h=new Map([[`toServiceType`,`TOServiceType`],[`rph`,`RPH`]]),se=new Map([[`TOServiceType`,`toServiceType`],[`RPH`,`rph`]]);function g(e,t){if(!e||typeof e!=`object`||p(e))return e;if(Array.isArray(e))return e.map(e=>g(e));let n=t?.excludeFromAttributePrefix,r=t?.excludeAttributeFromCamelToPascal,i={};for(let[t,a]of Object.entries(e)){let e=h.has(t)?h.get(t):ie(t),o=m.has(t)&&!n?.includes(t),s=oe(e,t,r?.includes(t)),c=o?s:e;i[c]=v(a,e=>g(e,void 0))}return i}function _(e){if(typeof e!=`object`||!e||p(e))return e;if(Array.isArray(e))return e.map(e=>_(e));let t={};for(let[n,r]of Object.entries(e)){let e=n.startsWith(`@`)?n.slice(1):n,i=se.has(e)?se.get(e):ae(e);t[i]=v(r,_)}return t}function v(e,t){return!e||typeof e!=`object`||p(e)?e:Array.isArray(e)?e.map(e=>v(e,t)):t(e)}function y(e){return t.pipe(e,t.transform(e=>g(e)))}function b(e){return t.pipe(e,t.transform(e=>_(e)))}function x(e){let n={};for(let t in e.entries){let r=m.has(t),i=t.charAt(0).toUpperCase()+t.slice(1),a=r?`@${i}`:i;n[a]=e.entries[t]}return t.object(n)}const S=t.union([t.literal(`true`),t.literal(`false`),t.boolean()]),ce=t.union([t.literal(`QUOTATION`),t.literal(`WORK_IN_PROGRESS`),t.literal(`CONFIRMED`),t.literal(`OPTIONED`),t.literal(`CANCELED`)]),le=t.union([t.literal(`QUOTATION`),t.literal(`WORK_IN_PROGRESS`),t.literal(`CONFIRMED`),t.literal(`OPTIONED`),t.literal(`NULLIFIED`),t.literal(`CANCELED`)]),ue=t.union([t.literal(`QUOTATION`),t.literal(`WORK_IN_PROGRESS`),t.literal(`CONFIRM`),t.literal(`CONFIRMED`),t.literal(`OPTION`),t.literal(`OPTIONED`),t.literal(`REQUEST`),t.literal(`REQUESTED`),t.literal(`NULLIFIED`),t.literal(`CANCELED`)]),C={CONFIRM:`CONFIRMED`,OPTION:`OPTIONED`,REQUESTED:`REQUEST`};function de(e){return e in C?C[e]:e}const fe=t.union([t.literal(`TOP`),t.literal(`TOP_SS`),t.literal(`ADV`),t.literal(`GRP`),t.literal(`OTHER`)]),w=t.union([t.literal(`ACCOMODATION`),t.literal(`TRANSPORT`),t.literal(`CHARTER`),t.literal(`TRANSFER`),t.literal(`PULLMAN`),t.literal(`FERRY`),t.literal(`CRUISE`),t.literal(`INSURANCE`),t.literal(`EXTRAFEE`),t.literal(`PENALTY`),t.literal(`PROMO`),t.literal(`OTHER`),t.literal(`NOT_SET`),t.literal(`RESIDENCE`)]),pe=t.union([t.literal(`REQUEST`),t.literal(`ALLOTMENT_REQUEST`),t.literal(`CONFIRMED_REQUEST`),t.literal(`CONFIRMED_EXTRA_ALLOTMENT`),t.literal(`WAITLISTED`),t.literal(`ALLOTMENT`),t.literal(`REFUSED`),t.literal(`NULLIFIED`),t.literal(`CANCELED`),t.literal(`MESSAGE`)]);function me(e){let t=e=>{if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(t);let n={};for(let[r,i]of Object.entries(e)){if(r===`paxAssociated`&&Array.isArray(i)&&!i.length){n[r]=``;continue}n[r]=t(i)}return n};return t(e)}function he(e){return g(me(e),{excludeFromAttributePrefix:[`startDate`,`endDate`],excludeAttributeFromCamelToPascal:[`sCode`,`ssCode`,`pCode`]})}function T(e){return t.pipe(e,t.transform(he))}function E(e){return t.pipe(t.union([t.array(e),e]),t.transform(e=>Array.isArray(e)?e:[e]))}const D=t.union([t.string(),t.number()]),ge=t.pipe(t.object({"@Value":ue,"@ExpiredDate":t.optional(t.string()),"@ExpireDate":t.optional(t.string())}),t.transform(e=>({"@Value":de(e[`@Value`]),"@ExpiredDate":e[`@ExpiredDate`]??e[`@ExpireDate`]}))),_e=t.object({"@PaxRef":t.string(),"@Price":D}),ve=t.object({PricePerPaxDetail:t.optional(E(_e))}),ye=t.object({"@CommissionCode":t.optional(t.string()),"@CommissionPercentage":t.optional(D),"@CommissionAmount":t.optional(D),"@PriceListCode":t.optional(t.string()),"@CostListCode":t.optional(t.string()),"@ServiceTotalPrice":t.optional(D),PaxPriceList:t.optional(ve)}),be=t.object({"@Code":t.optional(t.string()),"@Name":t.optional(t.string()),"@Email":t.optional(t.string()),"@LanguageCode":t.optional(t.string())}),xe=t.object({"@Code":t.optional(t.string()),"@Description":t.optional(t.string())}),Se=t.object({"@RPH":t.string(),"@ServiceCode":t.optional(t.string()),"@FromExternalProvider":t.optional(D),"@isFromExternalProvider":t.optional(D),AvesServiceType:t.optional(fe),TOServiceType:t.optional(w),FirstDescription:t.optional(t.string()),SecondDescription:t.optional(t.string()),ThirdDescription:t.optional(t.string()),FourthDescription:t.optional(t.string()),ServiceStatus:t.optional(pe),StartDate:t.optional(t.string()),EndDate:t.optional(t.string()),Qty:t.optional(D),Pax:t.optional(D),PeriodType:t.optional(t.string()),PaxMultiplier:t.optional(t.string()),ExternalProviderCode:t.optional(t.string()),WebStatisticCode:t.optional(t.string()),WebStatisticDescription:t.optional(t.string()),WebStatistic:t.optional(xe),SupplierInfo:t.optional(be),ServiceTotalAmountDetail:t.optional(ye)}),Ce=t.pipe(Se,t.transform(e=>({"@RPH":e[`@RPH`],"@ServiceCode":e[`@ServiceCode`],"@FromExternalProvider":e[`@FromExternalProvider`]??e[`@isFromExternalProvider`],AvesServiceType:e.AvesServiceType,TOServiceType:e.TOServiceType,FirstDescription:e.FirstDescription,SecondDescription:e.SecondDescription,ThirdDescription:e.ThirdDescription,FourthDescription:e.FourthDescription,ServiceStatus:e.ServiceStatus,StartDate:e.StartDate,EndDate:e.EndDate,Qty:e.Qty,Pax:e.Pax,PeriodType:e.PeriodType,PaxMultiplier:e.PaxMultiplier,ExternalProviderCode:e.ExternalProviderCode,WebStatisticCode:e.WebStatisticCode,WebStatisticDescription:e.WebStatisticDescription,WebStatistic:e.WebStatistic,SupplierInfo:e.SupplierInfo,ServiceTotalAmountDetail:e.ServiceTotalAmountDetail}))),we=t.object({BookedServiceDetail:t.optional(E(Ce))}),O=t.object({"@CurrencyCode":t.optional(t.string()),"@TotalAmountBeforeDiscount":t.optional(D),"@TotalAmountAfterDiscount":t.optional(D),"@TotalDiscount":t.optional(D),"@TotalAmountWithoutVat":t.optional(D),"@DueAmount":t.optional(D),"@PaiedAmount":t.optional(D),"@Balance":t.optional(D)}),Te=t.object({"@RPH":t.string(),"@RoomRPH":t.optional(t.string()),"@BillingHolder":t.optional(D),Name:t.optional(t.string()),CategoryCode:t.optional(t.string()),Sex:t.optional(t.string()),BirthDate:t.optional(t.string()),BirthPlace:t.optional(t.string()),NationCode:t.optional(t.string()),CitizenshipCode:t.optional(t.string()),FiscalCode:t.optional(t.string()),PhoneNumber:t.optional(t.string()),EMail:t.optional(t.string()),MasterRecordCode:t.optional(t.string())}),Ee=t.object({PassengerDetail:t.optional(E(Te))}),De=t.object({"@ReschedulingCode":t.optional(t.string()),"@ExpireDate":t.optional(t.string()),"@TotalAmount":t.optional(D),ReschedulingCode:t.optional(t.string()),ExpireDate:t.optional(t.string()),TotalAmount:t.optional(D)}),Oe=t.pipe(De,t.transform(e=>({"@ReschedulingCode":e[`@ReschedulingCode`]??e.ReschedulingCode,"@ExpireDate":e[`@ExpireDate`]??e.ExpireDate,"@TotalAmount":e[`@TotalAmount`]??e.TotalAmount}))),ke=t.object({DeadlineDetail:t.optional(E(Oe))}),Ae=t.object({DocumentRefCode:t.optional(t.string()),DocumentType:t.optional(t.string()),DocumentName:t.optional(t.string()),ArchiviationDescription:t.optional(t.string())}),je=t.object({StoredDocumentDetail:t.optional(E(Ae))}),Me=t.object({DocumentType:t.optional(t.string()),DocumentName:t.optional(t.string()),Enabled:t.optional(D)}),k=t.object({PrintableDocumentDetail:t.optional(E(Me))}),Ne=t.object({"@BookingFileCode":t.optional(t.string()),BookingFileCode:t.optional(t.string()),CustomerRecordCode:t.optional(t.string()),CustomerName:t.optional(t.string()),CustomerEmail:t.optional(t.string()),TravelAgencyName:t.optional(t.string()),TravelAgencyEmail:t.optional(t.string()),BookingFileStatus:t.optional(ge),Description:t.optional(t.string()),Nation:t.optional(t.string()),Destination:t.optional(t.string()),CreationDate:t.optional(t.string()),FirstConfirmationDate:t.optional(t.string()),StartDate:t.optional(t.string()),EndDate:t.optional(t.string()),PackageCode:t.optional(t.string()),BookedServiceList:t.optional(we),TotalAmountDetail:t.optional(O),PaxNumber:t.optional(D),PassengerList:t.optional(Ee),Reference:t.optional(t.string()),ClerkName:t.optional(t.string()),StoredDocumentsList:t.optional(je),PrintableDocumentsList:t.optional(k),FinancialDeadlineList:t.optional(ke)}),Pe=t.pipe(Ne,t.transform(e=>({"@BookingFileCode":e[`@BookingFileCode`]??e.BookingFileCode,CustomerRecordCode:e.CustomerRecordCode,CustomerName:e.CustomerName,CustomerEmail:e.CustomerEmail,TravelAgencyName:e.TravelAgencyName,TravelAgencyEmail:e.TravelAgencyEmail,BookingFileStatus:e.BookingFileStatus,Description:e.Description,Nation:e.Nation,Destination:e.Destination,CreationDate:e.CreationDate,FirstConfirmationDate:e.FirstConfirmationDate,StartDate:e.StartDate,EndDate:e.EndDate,PackageCode:e.PackageCode,BookedServiceList:e.BookedServiceList,TotalAmountDetail:e.TotalAmountDetail,PaxNumber:e.PaxNumber,PassengerList:e.PassengerList,Reference:e.Reference,ClerkName:e.ClerkName,StoredDocumentsList:e.StoredDocumentsList,PrintableDocumentsList:e.PrintableDocumentsList,FinancialDeadlineList:e.FinancialDeadlineList}))),A=t.object({"@HostID":t.pipe(t.string(),t.minLength(6),t.maxLength(6)),"@Xtoken":t.string(),"@Interface":t.literal(`WEB`),"@UserName":t.literal(`WEB`),"@LanguageCode":t.optional(t.pipe(t.string(),t.minLength(2),t.maxLength(2)))}),Fe=t.optional(t.pipe(t.string(),t.transform(e=>e.split(`,`)))),j=t.pipe(t.object({"@Status":t.union([t.literal(`OK`),t.literal(`ERROR`),t.literal(`WARNING`),t.literal(`TIMEOUT`)]),ErrorCode:t.optional(t.pipe(t.union([t.string(),t.number()]),t.transform(e=>Number(e)))),ErrorDescription:t.optional(t.string()),Warnings:Fe}),t.transform(e=>({status:e[`@Status`],errorCode:e.ErrorCode,errorDescription:e.ErrorDescription,warnings:e.Warnings}))),Ie=t.object({value:ce,expiredDate:t.optional(t.string())}),Le=t.object({sCode1:t.optional(t.pipe(t.string(),t.maxLength(4))),sCode2:t.optional(t.pipe(t.string(),t.maxLength(4))),sCode3:t.optional(t.pipe(t.string(),t.maxLength(4))),sCode4:t.optional(t.pipe(t.string(),t.maxLength(4))),sCode5:t.optional(t.pipe(t.string(),t.maxLength(4))),sCode6:t.optional(t.pipe(t.string(),t.maxLength(4)))}),Re=t.object({code:t.optional(t.string()),iataCode:t.optional(t.string()),nationCode:t.optional(t.string())}),ze=t.object({recordCode:t.optional(t.string())}),Be=t.union([t.literal(`VISA_REQUEST`),t.literal(`TRAVEL_INFORMATION`),t.literal(`VOUCHER`),t.literal(`BOOKING_CONTRACT`),t.literal(`BOOKING_CONFIRMATION`),t.literal(`SUPPLIER_SERVICE_LIST`),t.literal(`INVOICE`),t.literal(`PROFORMA_INVOICE`),t.literal(`ADEGUAMENTO`),t.literal(`RESERVATION_FORM`),t.literal(`OPEN_XML`),t.literal(`SALES_INVOICE`),t.literal(`TICKETING_TMASTER`),t.literal(`SUMMARY_FORM`)]),Ve=t.object({makeDocumentTo:t.optional(t.union([t.literal(`BOOKING_CUSTOMER`),t.literal(`FIRST_PASSENGER`)]))}),He=t.object({fillInCode:t.optional(t.string())}),Ue=t.union([Ve,He]),We=t.object({documentType:Be,documentCustomizablePrintParameters:t.optional(Ue)}),Ge=t.object({printDoc:t.optional(S),sendDocViaEmail:t.optional(S),infoDocumentsToPrint:t.optional(t.array(We))}),Ke=t.object({reschedulingCode:t.optional(t.string()),expireDate:t.optional(t.string()),totalAmount:t.optional(t.string())}),qe=t.object({deadlineCode:t.optional(t.string()),description:t.optional(t.string()),expireDate:t.optional(t.string())}),Je=t.union([t.literal(`C`),t.literal(`B`),t.literal(`D`),t.literal(`T`),t.literal(`P`),t.literal(`R`),t.literal(`A`),t.literal(`H`),t.literal(`I`),t.literal(`J`),t.literal(`K`),t.literal(`L`),t.literal(`M`),t.literal(`N`),t.literal(`O`),t.literal(`Q`),t.literal(`S`),t.literal(`U`),t.literal(`V`)]),Ye=t.object({paymentDate:t.optional(t.string()),paumentNote:t.optional(t.string()),amount:t.optional(t.string()),paymentUser:t.optional(t.string()),paymentType:t.optional(Je)}),Xe=t.object({deadlineDetail:t.optional(t.array(Ke))}),Ze=t.object({deadlineDetail:t.optional(t.array(qe))}),Qe=t.object({paymentDetail:t.optional(t.array(Ye))}),$e=t.union([t.literal(`PAX_QTY_DAY`),t.literal(`PAX_QTY_NIGHT`),t.literal(`PAX_QTY_WEEK`),t.literal(`PAX_QTY`),t.literal(`PAX_DAY`),t.literal(`PAX_NIGHT`),t.literal(`PAX_WEEK`),t.literal(`PAX`),t.literal(`QTY_DAY`),t.literal(`QTY_NIGHT`),t.literal(`QTY_WEE`),t.literal(`QTY`),t.literal(`DAY`),t.literal(`NIGHT`),t.literal(`WEEK`),t.literal(`FORFAIT`)]),et=t.object({currencyCode:t.optional(t.string()),exchangeRate:t.optional(t.string()),cost:t.optional(t.string()),costTax:t.optional(t.string()),costType:t.optional($e),vatCostCurrencyCode:t.optional(t.string()),price:t.optional(t.string()),priceTax:t.optional(t.string()),priceType:t.optional($e)}),tt=t.object({packageCode:t.optional(t.string()),packageReference:t.optional(t.string()),suballotmentCode:t.optional(t.string()),priceListCode:t.optional(t.string()),costListCode:t.optional(t.string()),externalFileCode:t.optional(t.string()),externalReference:t.optional(t.string()),serviceStatus:t.optional(t.string()),serviceStatisticCode:t.optional(t.string()),serviceFare:t.optional(et)}),nt=t.object({pax:t.string()}),M=t.object({sCode:t.string(),ssCode:t.optional(t.string()),avesServiceType:fe,toServiceType:t.optional(w),subServiceDesc:t.optional(t.string()),startDate:t.string(),endDate:t.string(),qty:t.string(),pax:t.string(),paxAssociated:t.optional(t.array(nt)),avesSession:t.string(),avesServiceInfo:t.optional(tt),serviceFare:t.optional(et),bookedServiceRef:t.optional(t.string()),supplierMasterCode:t.optional(t.string()),voucherMasterCode:t.optional(t.string()),hotelServiceInfo:t.optional(t.string()),carRentalServiceInfo:t.optional(t.string()),flightServiceInfo:t.optional(t.string()),shipServiceInfo:t.optional(t.string()),ticketServiceInfo:t.optional(t.string()),commission:t.optional(t.string()),noteList:t.optional(t.string()),voucherInfo:t.optional(t.string()),firstDescription:t.optional(t.string()),secondDescription:t.optional(t.string())}),N=t.object({pCode:t.string(),startDate:t.string(),endDate:t.string(),getServicesFromPackage:t.optional(S)}),rt=t.object({selectedPackageDetail:t.optional(t.array(N))}),it=t.object({selectedServiceDetail:M}),at=t.object({extraQuoteServiceDetail:t.optional(t.array(M))}),P=t.object({nType:t.optional(t.string()),title:t.optional(t.string()),text:t.optional(t.string())}),ot=t.object({noteDetail:t.optional(t.array(P))}),F=t.union([t.literal(`AD`),t.literal(`CH`),t.literal(`IN`),t.literal(`OV`)]),I={rph:t.string(),roomRph:t.optional(t.string()),billingHolder:t.optional(S),masterRecordCode:t.optional(t.string()),name:t.string(),sex:t.union([t.literal(`M`),t.literal(`F`)]),birthDate:t.optional(t.string()),birthPlace:t.optional(t.string()),nationCode:t.optional(t.string()),citizenshipCode:t.optional(t.string()),fiscalCode:t.optional(t.string()),phoneNumber:t.optional(t.string()),eMail:t.optional(t.string()),notes:t.optional(t.array(P)),flagStatus:t.optional(t.string()),offerCode:t.optional(t.string()),idDocInfo:t.optional(t.object({idType:t.optional(t.string()),idCode:t.optional(t.string()),idIssueLocation:t.optional(t.string()),idIssueCounty:t.optional(t.string()),idIssueDate:t.optional(t.string()),idExpireDate:t.optional(t.string())}))},st=t.object({...I,categoryCode:F}),L=t.object({...I,categoryCode:t.optional(F)}),ct=t.object({passengerDetail:st}),lt=t.union([t.literal(`CASH`),t.literal(`BANK`),t.literal(`RID`),t.literal(`RIBA`),t.literal(`SPECIFIC_CODE`),t.literal(`NOT_SET`)]),R=t.object({customer_PaymentType:t.optional(lt),customer_SpecPaymentTypeCode:t.optional(t.string())}),ut=t.union([t.literal(`GROUPED_PAX`),t.literal(`NOT_GROUPED_PAX`),t.literal(`ONE_PAX_ONLY`)]),dt=t.union([t.literal(`AVES2AVES`),t.literal(`AVES2AVESVIA`),t.literal(`AVES2AVESITA`)]),ft=T(t.object({createDate:t.optional(t.string()),bookingFileRefCode:t.optional(t.string()),travelAgentCode:t.optional(t.string()),clerkName:t.optional(t.string()),customerDetail:ze,currencyCode:t.optional(t.string()),markupCode:t.optional(t.string()),bookingFileStatus:Ie,statisticCodes:t.optional(Le),destination:t.optional(Re),bookingFileDescription:t.optional(t.string()),startDate:t.string(),endDate:t.string(),earlyBookingDate:t.optional(t.string()),cupCode:t.optional(t.string()),cigCode:t.optional(t.string()),customerPromoterCode:t.optional(t.string()),billingReferenceCode:t.optional(t.string()),paymentReferenceCode:t.optional(t.string()),bookingFileDocument:t.optional(Ge),financialDeadlineList:t.optional(Xe),deadlineList:t.optional(Ze),paymentList:t.optional(Qe),selectedPackageList:t.optional(rt),selectedServiceList:t.array(it),extraQuotaRefCode:t.optional(t.string()),extraQuoteServiceList:t.optional(at),getExtraQuoteFromSystem:t.optional(S),passengerList:t.array(ct),noteList:t.optional(ot),bookingFinancialInfo:t.optional(R),bookingFileCode:t.optional(t.string()),groupingPaxPolicy:t.optional(ut),groupBookingFile:t.optional(S),typeDownloadFile:t.optional(dt),setBookingFileCodeFromStartDate:t.optional(S)})),z=b(t.object({RsStatus:j,BookingFileDetail:t.optional(Pe),PrintableDocumentsList:t.optional(k),TotalAmountDetailAfterCancellation:t.optional(O),Base64DocContent:t.optional(t.string())})),B=b(t.object({RsStatus:j})),V=z,pt=t.object({reschedulingCode:t.string(),description:t.optional(t.string()),expireDate:t.optional(t.string())}),mt=t.object({cancelOperationType:t.union([t.literal(`NULLIFY`),t.literal(`DELETE`)]),serviceRefType:t.union([t.literal(`RPH`),t.literal(`FILE`)]),serviceRefValue:t.string()}),ht=T(t.object({customerRecordCode:t.string(),bookingFileCode:t.string(),currencyCode:t.optional(t.string()),deadlineList:t.optional(t.object({deadlineDetail:t.optional(t.array(pt))})),selectedPackageDetail:t.optional(N),selectedServiceList:t.object({selectedServiceDetail:t.pipe(t.array(M),t.minLength(1))}),cancellableBookedServiceList:t.optional(t.object({cancellableBookedServiceDetail:t.optional(t.array(mt))})),passengerList:t.optional(t.object({passengerDetail:t.optional(t.array(L))}))})),gt=y(t.object({bookingFileCode:t.string(),bookingFileStartDate:t.string(),customerRecordCode:t.string(),newCustomerRecordCode:t.optional(t.string()),bookingFileReferenceName:t.optional(t.string()),travelAgentCode:t.optional(t.string()),billingReferenceCode:t.optional(t.string()),paymentReferenceCode:t.optional(t.string()),cupCode:t.optional(t.string()),cigCode:t.optional(t.string()),customerPromoterCode:t.optional(t.string()),bookingNote:t.optional(t.string()),passengerList:t.optional(t.object({passengerDetail:t.optional(t.array(L))})),statisticCodes:t.optional(Le),bookingFinancialInfo:t.optional(R),financialDeadlineList:t.optional(t.object({deadlineDetail:t.optional(t.array(t.object({reschedulingCode:t.string(),expireDate:t.string(),totalAmount:t.string()})))}))})),_t=y(t.object({bookingFileCode:t.string(),customerRecordCode:t.string()})),vt=t.union([t.literal(`NOT_SET`),t.literal(`CONSIDER_HOLIDAY`),t.literal(`CONSIDER_HOLIDAY_AND_SATURDAY`)]),yt=y(t.object({customerRecordCode:t.string(),bookingFileCode:t.string(),fileStatus:t.object({value:le,expiredDate:t.optional(t.string()),optionedFileExpireDatePolicy:t.optional(vt)}),backOfficeRequest:t.optional(S),bookingFileDocument:t.optional(Ge),penalty:t.optional(t.object({apply:t.optional(S),specificCode:t.optional(t.string())})),simulateCancelAndGetPenaltyAmount:t.optional(S)})),bt=y(t.object({customerRecordCode:t.string(),bookingFileCode:t.string(),bookingServiceRef:t.string(),bookingFileServiceStatus:t.literal(`NULLIFIED`),bookingFileServiceStatusDate:t.optional(t.string())})),xt=t.union([t.literal(`C`),t.literal(`B`),t.literal(`D`),t.literal(`T`),t.literal(`P`),t.literal(`R`),t.literal(`A`),t.literal(`H`),t.literal(`I`),t.literal(`J`),t.literal(`K`),t.literal(`L`),t.literal(`M`),t.literal(`N`),t.literal(`O`),t.literal(`Q`),t.literal(`S`),t.literal(`U`),t.literal(`V`)]),St=t.union([t.literal(`AbsoluteAmountsInsertion`),t.literal(`FinalAmountToAchieve`),t.literal(`FinalAmountToAchieveWithoutControls`)]),Ct=t.object({paymentDate:t.string(),paymentNote:t.optional(t.string()),payerMasterCode:t.optional(t.string()),payerName:t.optional(t.string()),amount:t.string(),paymentType:xt}),wt=y(t.pipe(t.object({bookingFileCode:t.optional(t.string()),bookingFileRefCode:t.optional(t.string()),paymentUser:t.optional(t.string()),enableMultiplePayments:S,operationType:St,filePaymentList:t.object({filePaymentDetail:t.pipe(t.array(Ct),t.minLength(1))})}),t.check(e=>!!(e.bookingFileCode||e.bookingFileRefCode),`bookingFileCode or bookingFileRefCode is required`))),H=t.union([t.literal(`CASH`),t.literal(`BANK`),t.literal(`RID`),t.literal(`RIBA`),t.literal(`SPECIFIC_CODE`)]),U=t.object({currencyCode:t.optional(t.string()),creditLimit:t.optional(t.string()),c_PaymentType:t.optional(H),c_SpecPaymentTypeCode:t.optional(t.string()),s_PaymentType:t.optional(H),s_SpecPaymentTypeCode:t.optional(t.string()),enableElectronicInvoicing:t.optional(t.union([t.literal(`true`),t.literal(`false`),t.boolean()])),electronicInvoicingType:t.optional(t.string())});y(U);const Tt=x(U),W=t.object({idType:t.optional(t.string()),idCode:t.optional(t.string()),idIssueLocation:t.optional(t.string()),idIssueCounty:t.optional(t.string()),idIssueDate:t.optional(t.string()),idExpireDate:t.optional(t.string())});y(W);const Et=x(W),G=t.object({key:t.string(),value:t.string()});y(t.array(G));const Dt=x(G),Ot=t.union([t.literal(`NOT_SET`),t.literal(`FLIGHT`),t.literal(`SHIP`),t.literal(`TRAIN`),t.literal(`RENTCAR`),t.literal(`BUS`),t.literal(`DP_HOTEL`),t.literal(`TO_HOTEL`),t.literal(`TO_TOUR`),t.literal(`TO_HOTEL_AND_TOUR`),t.literal(`DP_AUTO`),t.literal(`DP_GDS_NAVI`),t.literal(`DP_GDS_VOLI`),t.literal(`TOUR_OPERATOR`),t.literal(`TICKETING_EV`),t.literal(`OTHER`)]),K=t.object({supplierRefCode:t.optional(t.string()),companyMainBusinessType:t.optional(t.string()),carrierType:t.optional(Ot)});y(K);const kt=x(K),q=t.union([t.literal(0),t.literal(1)]),At=t.union([t.literal(`ENABLED`),t.literal(`DISABLED`),t.literal(`WARNING`),t.literal(`BLACKLISTED`)]),jt=t.union([t.literal(`CUSTOMER`),t.literal(`SUPPLIER`),t.literal(`GENERAL`)]),Mt=t.union([t.literal(`S`),t.literal(`N`),t.literal(`T`),t.literal(`M`)]),J=t.object({acceptProfilingPolicies:t.optional(q),acceptPrivacyPolicies:t.optional(q),acceptNewsletterPolicies:t.optional(q)});y(J);const Nt=x(J),Pt=y(t.object({recordCode:t.optional(t.pipe(t.string(),t.minLength(6),t.maxLength(6))),insertCriteria:t.optional(Mt),createdDate:t.optional(t.string()),recordType:t.optional(t.union([jt],`CUSTOMER`)),recordStatus:t.optional(t.union([At],`ENABLED`)),moniker:t.optional(t.string()),name:t.optional(t.string()),extraInfo:t.optional(t.string()),languageCode:t.pipe(t.string(),t.minLength(2),t.maxLength(2)),address:t.optional(t.string()),zipCode:t.optional(t.string()),cityName:t.optional(t.string()),countyCode:t.optional(t.string()),stateCode:t.optional(t.string()),categoryCode:t.optional(t.string()),firstPhoneNumber:t.optional(t.string()),mobilePhoneNumber:t.optional(t.string()),email:t.optional(t.string()),gender:t.optional(t.union([t.literal(`M`),t.literal(`F`)])),birthDate:t.optional(t.string()),birthCity:t.optional(t.string()),birthCounty:t.optional(t.string()),fiscalCode:t.optional(t.string()),vatCode:t.optional(t.string()),thirdPartRecordCode:t.optional(t.string()),idDocumentDetail:t.optional(W),accountPolicies:t.optional(J),financialDetail:t.optional(U),dynamicFields:t.optional(G),supplierRefMasterRecords:t.optional(K)}));b(Pt);const Y=t.object({"@RecordCode":t.optional(t.pipe(t.string(),t.minLength(6),t.maxLength(6))),"@InsertCriteria":t.optional(Mt),CreatedDate:t.optional(t.string()),ModifiedDate:t.optional(t.string()),RecordType:t.optional(t.union([t.literal(`CUSTOMER`),t.literal(`SUPPLIER`),t.literal(`GENERAL`)])),LoginType:t.optional(t.string()),RecordStatus:t.optional(At),Moniker:t.optional(t.string()),Name:t.optional(t.string()),ExtraInfo:t.optional(t.string()),LanguageCode:t.optional(t.pipe(t.string(),t.minLength(1),t.maxLength(2))),Address:t.optional(t.string()),ZipCode:t.optional(t.string()),CityName:t.optional(t.string()),CountyCode:t.optional(t.string()),StateCode:t.optional(t.string()),CategoryCode:t.optional(t.string()),PromoterCode:t.optional(t.string()),FirstPhoneNumber:t.optional(t.string()),MobilePhoneNumber:t.optional(t.string()),Email:t.optional(t.string()),Gender:t.optional(t.union([t.literal(`M`),t.literal(`F`)])),BirthDate:t.optional(t.string()),BirthCity:t.optional(t.string()),BirthCounty:t.optional(t.string()),EncryptedPassword:t.optional(t.union([t.literal(`true`),t.literal(`false`),t.boolean()])),FiscalCode:t.optional(t.string()),VatCode:t.optional(t.string()),ThirdPartRecordCode:t.optional(t.string()),IdDocumentDetail:t.optional(Et),NewsletterDisabled:t.optional(t.union([t.literal(`true`),t.literal(`false`),t.boolean()])),SupplierRefMasterRecords:t.optional(kt),AccountPolicies:t.optional(Nt),FinancialDetail:t.optional(Tt),DynamicFields:t.optional(Dt)}),Ft=t.object({minDate:t.string(),maxDate:t.string()}),X=t.optional(t.pipe(t.string(),t.minLength(2),t.maxLength(2))),It=t.object({searchType:t.literal(`CODE`),recordCode:t.pipe(t.string(),t.minLength(5),t.maxLength(6)),languageCode:X}),Lt=t.object({searchType:t.literal(`NAME`),name:t.string(),city:t.optional(t.string()),languageCode:X}),Rt=t.object({searchType:t.literal(`VATCODE`),vatCode:t.string(),phoneNumber:t.optional(t.string()),languageCode:X}),zt=t.object({searchType:t.literal(`ZONE`),zipCode:t.string(),countyCode:t.string(),city:t.optional(t.string()),languageCode:X}),Bt=t.object({searchType:t.literal(`CATEGORY`),categoryCode:t.string(),languageCode:X}),Vt=t.object({searchType:t.literal(`EMAIL`),email:t.string(),languageCode:X}),Ht=t.object({searchType:t.literal(`LASTMODDATE`),lastModificationDate:Ft,languageCode:X}),Ut=t.object({searchType:t.literal(`SEARCH_FIELD`),searchFieldValue:t.string(),languageCode:X}),Wt=t.object({searchType:t.literal(`EXTERNAL_REF_CODE`),searchFieldValue:t.string(),languageCode:X}),Gt=t.union([It,Lt,Rt,zt,Bt,Vt,Ht,Ut,Wt]),Kt=e=>{if(!(`@RecordCode`in e))return e;let t=e[`@RecordCode`];if(!t)return e;let{"@RecordCode":n,...r}=e;return{...r,RecordCode:t}},qt=t.pipe(y(Gt),t.transform(e=>Kt(e))),Jt=t.pipe(t.object({RqHeader:A,SearchMasterRecord:qt}),t.transform(e=>{let{SearchMasterRecord:t,RqHeader:n,...r}=e;return{RqHeader:n,...t,...r}})),Yt=t.object({MasterRecordDetail:t.optional(t.pipe(t.union([t.array(Y),Y]),t.transform(e=>{if(e)return Array.isArray(e)?e:[e]})))}),Xt=b(t.object({RsStatus:j,MasterRecordList:t.optional(Yt)})),Zt=t.object({RqHeader:A,MasterRecordDetail:Y}),Qt=b(t.object({RsStatus:j,MasterRecordDetail:t.optional(Y)}));function $t(e){return{success:!0,data:e}}function Z(e){return{success:!1,error:e}}function en(e){return e===200}function tn(e){let t=new AbortController;if(!e||e<=0)return{signal:t.signal};let n=setTimeout(()=>t.abort(),e);return{signal:t.signal,clear:()=>clearTimeout(n)}}function nn(e,t){try{let n=new URL(e),r=(n.pathname.endsWith(`/`)?n.pathname.slice(0,-1):n.pathname)+t;return new URL(r,n)}catch(e){throw new c(`validation`,`Invalid baseURL: ${e instanceof Error?e.message:`Invalid URL format`}`)}}function rn(e,t){if(!t.startsWith(`/`))throw new c(`validation`,`Invalid endpoint: endpoint must start with '/' but got '${t}'`);let n=nn(e.replace(/\/$/,``),t);if(n.protocol!==`http:`&&n.protocol!==`https:`)throw new c(`validation`,`Invalid protocol: baseURL must use http:// or https:// but got '${n.protocol}'`);return n.toString()}const an={ignoreAttributes:!1,attributeNamePrefix:`@`,parseAttributeValue:!1,trimValues:!0,ignoreNameSpace:!0,removeNSPrefix:!0,parseTagValue:!1},on={ignoreAttributes:!1,attributeNamePrefix:`@`,suppressEmptyNode:!0},sn=new o(an),cn=new a(on);function ln(e){try{return cn.build(e)}catch(e){throw new c(`validation`,`Failed to convert JSON to XML: ${e instanceof Error?e.message:`Unknown error`}`)}}function un(e){try{return sn.parse(e)}catch(e){throw new c(`validation`,`Failed to convert XML to JSON: ${e instanceof Error?e.message:`Unknown error`}`)}}const Q={SEARCH_REQUEST:`SearchMasterRecordRQ`,SEARCH_RESPONSE:`SearchMasterRecordRS`,UPSERT_REQUEST:`ManageMasterRecordRQ`,UPSERT_RESPONSE:`ManageMasterRecordRS`,BOOKING_REQUEST:`BookFileRQ`,BOOKING_RESPONSE:`BookingFileRS`,MOD_FILE_SERVICES_REQUEST:`ModFileServicesRQ`,MOD_FILE_HEADER_REQUEST:`ModFileHeaderRQ`,MOD_FILE_HEADER_RESPONSE:`ModFileHeaderRS`,CANCEL_FILE_REQUEST:`CancelFileRQ`,CANCEL_FILE_RESPONSE:`CancelFileRS`,SET_STATUS_REQUEST:`SetStatusRQ`,SET_STATUS_RESPONSE:`SetStatusRS`,SET_STATUS_SERVICE_REQUEST:`SetStatusServiceRQ`,SET_STATUS_SERVICE_RESPONSE:`SetStatusServiceRS`,FILE_PAYMENT_LIST_REQUEST:`FilePaymentListRQ`,FILE_PAYMENT_LIST_RESPONSE:`FilePaymentListRS`};function $(e,t){return{[e]:t}}var dn=class{options;constructor(e){this.options=e}createRqHeader(){return{"@HostID":this.options.hostID,"@Xtoken":this.options.xtoken,"@Interface":`WEB`,"@UserName":`WEB`,...this.options.languageCode&&{"@LanguageCode":this.options.languageCode}}}createUrl(e){return rn(this.options.baseURL,e)}get endpoints(){return{search:`/interop/masterRecords/v2/rest/Search`,upsert:`/interop/masterRecords/v2/rest/InsertOrUpdate`,createBooking:`/interop/booking/v2/rest/CreateBookingFile`,modBookingServices:`/interop/booking/v2/rest/ModBookingFileServices`,modBookingHeader:`/interop/booking/v2/rest/ModBookingFileHeader`,cancelBooking:`/interop/booking/v2/rest/CancelBookingFile`,setBookingStatus:`/interop/booking/v2/rest/SetBookingFileStatus`,setBookingServiceStatus:`/interop/booking/v2/rest/SetBookingFileServiceStatus`,insertFilePaymentList:`/interop/booking/v2/rest/InsertFilePaymentList`}}handleApiStatus(e){let t=e.rsStatus,n=t?.status;return n===`OK`?$t(e):Z(u(t.errorDescription,n,t.errorCode))}toAvesError(e,t){return e instanceof c?e:e instanceof n?l(`Validation error: ${ee(e.issues)}`):e instanceof Error?d(e.message):d(t)}async request(t,n,r,a){let{signal:o,clear:s}=tn(this.options.timeoutMs??3e4);try{let s=await e(this.createUrl(t),{method:`POST`,headers:{"Content-Type":`application/xml`},body:ln(n),signal:o}),c=await s.body.text();if(!en(s.statusCode))return Z(u(c,`ERROR`,s.statusCode));let d=un(c)[r];if(!d)return Z(l(`Invalid response structure: missing root element '${r}'`));let f=i(a,d);return f.success?this.handleApiStatus(f.output):Z(l(`Invalid response format: ${ee(f.issues)}`))}catch(e){return re(e)?Z(u(`Request timed out`,`TIMEOUT`)):Z(this.toAvesError(e,`Unknown error occurred`))}finally{s?.()}}async invokeOp(e){try{let t=r(e.apiSchema,e.params);return this.request(e.endpoint,$(e.requestRoot,{RqHeader:this.createRqHeader(),...t}),e.responseRoot,e.responseSchema)}catch(t){return Z(this.toAvesError(t,`Validation error occurred during ${e.op}`))}}async search(e){try{let t=r(Jt,{RqHeader:this.createRqHeader(),SearchMasterRecord:e}),n=$(Q.SEARCH_REQUEST,t);return this.request(this.endpoints.search,n,Q.SEARCH_RESPONSE,Xt)}catch(e){return Z(this.toAvesError(e,`Validation error occurred during search`))}}async upsertRecord(e){try{let t=r(Pt,e),n=r(Zt,{RqHeader:this.createRqHeader(),MasterRecordDetail:t}),i=$(Q.UPSERT_REQUEST,n);return this.request(this.endpoints.upsert,i,Q.UPSERT_RESPONSE,Qt)}catch(e){return Z(this.toAvesError(e,`Validation error occurred during upsert`))}}async createBooking(e){return this.invokeOp({op:`createBooking`,params:e,apiSchema:ft,endpoint:this.endpoints.createBooking,requestRoot:Q.BOOKING_REQUEST,responseRoot:Q.BOOKING_RESPONSE,responseSchema:z})}async modBookingServices(e){return this.invokeOp({op:`modBookingServices`,params:e,apiSchema:ht,endpoint:this.endpoints.modBookingServices,requestRoot:Q.MOD_FILE_SERVICES_REQUEST,responseRoot:Q.BOOKING_RESPONSE,responseSchema:V})}async modBookingHeader(e){return this.invokeOp({op:`modBookingHeader`,params:e,apiSchema:gt,endpoint:this.endpoints.modBookingHeader,requestRoot:Q.MOD_FILE_HEADER_REQUEST,responseRoot:Q.MOD_FILE_HEADER_RESPONSE,responseSchema:B})}async cancelBooking(e){return this.invokeOp({op:`cancelBooking`,params:e,apiSchema:_t,endpoint:this.endpoints.cancelBooking,requestRoot:Q.CANCEL_FILE_REQUEST,responseRoot:Q.CANCEL_FILE_RESPONSE,responseSchema:B})}async setBookingStatus(e){return this.invokeOp({op:`setBookingStatus`,params:e,apiSchema:yt,endpoint:this.endpoints.setBookingStatus,requestRoot:Q.SET_STATUS_REQUEST,responseRoot:Q.SET_STATUS_RESPONSE,responseSchema:V})}async setBookingServiceStatus(e){return this.invokeOp({op:`setBookingServiceStatus`,params:e,apiSchema:bt,endpoint:this.endpoints.setBookingServiceStatus,requestRoot:Q.SET_STATUS_SERVICE_REQUEST,responseRoot:Q.SET_STATUS_SERVICE_RESPONSE,responseSchema:V})}async insertFilePaymentList(e){return this.invokeOp({op:`insertFilePaymentList`,params:e,apiSchema:wt,endpoint:this.endpoints.insertFilePaymentList,requestRoot:Q.FILE_PAYMENT_LIST_REQUEST,responseRoot:Q.FILE_PAYMENT_LIST_RESPONSE,responseSchema:B})}};export{dn as AvesClient,c as AvesError};
1
+ import{request as e}from"undici";import*as t from"valibot";import{ValiError as n,parse as r,safeParse as i}from"valibot";import a from"fast-xml-builder";import{XMLParser as o}from"fast-xml-parser";const s={VALIDATION:`validation`,API:`api`,UNKNOWN:`unknown`};var c=class extends Error{kind;message;status;code;constructor(e,t,n,r){super(t),this.kind=e,this.message=t,this.status=n,this.code=r,this.name=`AvesError`,this.status=n?.toLowerCase(),this.code=this.parseCode(r)}parseCode(e){return typeof e==`string`?Number.parseInt(e,10):e??0}};function l(e){return new c(s.VALIDATION,e)}function u(e,t,n){return new c(s.API,e,t,n)}function d(e){return new c(s.UNKNOWN,e)}function ee(e){return e.map(f).join(`; `)}function f(e){let t=te(e.path),n=e.message??`Invalid value`;return t?`${t}: ${n}`:n}function te(e){if(!e||e.length===0)return;let t=e.map(ne).filter(e=>e!==void 0);return t.length>0?t.join(`.`):void 0}function ne(e){if(typeof e==`string`||typeof e==`number`)return String(e);if(typeof e==`object`&&e&&`key`in e)return String(e.key)}function re(e){return e instanceof Error&&e.name===`AbortError`}function ie(e){return e.charAt(0).toUpperCase()+e.slice(1)}function ae(e){return e.charAt(0).toLowerCase()+e.slice(1)}function p(e){return e instanceof Date||e instanceof RegExp||e instanceof Map||e instanceof Set||e instanceof Error}const m=new Set(Object.values({header:[`hostID`,`xtoken`,`interface`,`userName`,`status`],masterRecord:[`recordCode`,`insertCriteria`],financialDetail:[`currencyCode`,`creditLimit`,`c_PaymentType`,`c_SpecPaymentTypeCode`,`s_PaymentType`,`s_SpecPaymentTypeCode`,`enableElectronicInvoicing`,`electronicInvoicingType`],idDocumentDetail:[`idType`,`idCode`,`idIssueLocation`,`idIssueCounty`,`idIssueDate`,`idExpireDate`],accountPolicies:[`acceptProfilingPolicies`,`acceptPrivacyPolicies`,`acceptNewsletterPolicies`],dynamicFields:[`key`,`value`],search:[`minDate`,`maxDate`],bookingFileStatus:[`value`,`expiredDate`],statisticCodes:[`sCode1`,`sCode2`,`sCode3`,`sCode4`,`sCode5`,`sCode6`],destination:[`code`,`iataCode`,`nationCode`],customerDetail:[`recordCode`],bookingFileDocument:[`printDoc`,`sendDocViaEmail`],financialDeadlineDetail:[`reschedulingCode`,`expireDate`,`totalAmount`],deadlineDetail:[`deadlineCode`,`description`,`expireDate`],paymentDetail:[`paymentDate`,`paumentNote`,`amount`,`paymentUser`,`paymentType`],filePaymentDetail:[`paymentDate`,`paymentNote`,`payerMasterCode`,`payerName`,`amount`,`paymentType`],selectedPackageDetail:[`pCode`,`startDate`,`endDate`,`getServicesFromPackage`],selectedServiceDetail:[`sCode`,`ssCode`,`supplierMasterCode`,`supplierName`,`supplierMasterSearchField`,`supplierFiscalCode`],extraQuoteServiceDetail:[`sCode`,`ssCode`,`supplierMasterCode`,`supplierName`,`supplierMasterSearchField`,`supplierFiscalCode`],serviceFare:[`currencyCode`,`exchangeRate`,`cost`,`costTax`,`costType`,`vatCostCurrencyCode`,`price`,`priceTax`,`priceType`],cancellableBookedServiceDetail:[`cancelOperationType`,`serviceRefType`,`serviceRefValue`],fileStatus:[`value`,`expiredDate`,`optionedFileExpireDatePolicy`],penalty:[`apply`,`specificCode`],noteDetail:[`nType`,`title`],passengerDetail:[`rph`,`roomRph`,`billingHolder`],bookingFinancialInfo:[`customer_PaymentType`,`customer_SpecPaymentTypeCode`],reservationFormCustomizablePrintParameters:[`makeDocumentTo`],supplierRefMasterRecords:[`supplierRefCode`,`companyMainBusinessType`,`carrierType`]}).flat()),oe=(e,t,n=!1)=>n||t===`sCode`||t===`ssCode`||t===`pCode`?`@${t}`:`@${e}`,se=new Map([[`toServiceType`,`TOServiceType`],[`rph`,`RPH`]]),ce=new Map([[`TOServiceType`,`toServiceType`],[`RPH`,`rph`]]);function h(e,t){if(!e||typeof e!=`object`||p(e))return e;if(Array.isArray(e))return e.map(e=>h(e));let n=t?.excludeFromAttributePrefix,r=t?.excludeAttributeFromCamelToPascal,i={};for(let[t,a]of Object.entries(e)){let e=se.has(t)?se.get(t):ie(t),o=m.has(t)&&!n?.includes(t),s=oe(e,t,r?.includes(t)),c=o?s:e;i[c]=_(a,e=>h(e,void 0))}return i}function g(e){if(typeof e!=`object`||!e||p(e))return e;if(Array.isArray(e))return e.map(e=>g(e));let t={};for(let[n,r]of Object.entries(e)){let e=n.startsWith(`@`)?n.slice(1):n,i=ce.has(e)?ce.get(e):ae(e);t[i]=_(r,g)}return t}function _(e,t){return!e||typeof e!=`object`||p(e)?e:Array.isArray(e)?e.map(e=>_(e,t)):t(e)}const le={financialDeadlineList:`deadlineDetail`};function ue(e){return le[e]??e.replace(/List$/,`Detail`)}function de(e,{listKeys:t,arrayOfOne:n}){let r={...e},i=n??new Set;for(let e of t){let t=r[e];if(!Array.isArray(t))continue;let n=ue(e);r[e]=i.has(e)?t.map(e=>({[n]:e})):{[n]:t}}return r}const fe=[`selectedServiceList`,`passengerList`,`selectedPackageList`,`extraQuoteServiceList`,`deadlineList`,`financialDeadlineList`,`paymentList`,`noteList`],pe=new Set([`selectedServiceList`,`passengerList`]),me=[`selectedServiceList`,`passengerList`,`cancellableBookedServiceList`,`deadlineList`],he=[`passengerList`,`financialDeadlineList`],ge=[`filePaymentList`];function _e(e){let t=e=>{if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(t);let n={};for(let[r,i]of Object.entries(e)){if(r===`paxAssociated`&&Array.isArray(i)&&!i.length){n[r]=``;continue}n[r]=t(i)}return n};return t(e)}function ve(e,t){return h(_e(t?de(e,t):e),{excludeFromAttributePrefix:[`startDate`,`endDate`],excludeAttributeFromCamelToPascal:[`sCode`,`ssCode`,`pCode`]})}function v(e,n){return t.pipe(e,t.transform(e=>ve(e,n)))}function y(e){return t.pipe(e,t.transform(e=>h(e)))}function b(e){return t.pipe(t.union([t.array(e),e]),t.transform(e=>Array.isArray(e)?e:[e]))}function x(e){return t.pipe(e,t.transform(e=>g(e)))}function S(e){let n={};for(let t in e.entries){let r=m.has(t),i=t.charAt(0).toUpperCase()+t.slice(1),a=r?`@${i}`:i;n[a]=e.entries[t]}return t.object(n)}const C=t.union([t.literal(`true`),t.literal(`false`),t.boolean()]),ye=t.union([t.literal(`QUOTATION`),t.literal(`WORK_IN_PROGRESS`),t.literal(`CONFIRMED`),t.literal(`OPTIONED`),t.literal(`CANCELED`)]),be=t.union([t.literal(`QUOTATION`),t.literal(`WORK_IN_PROGRESS`),t.literal(`CONFIRMED`),t.literal(`OPTIONED`),t.literal(`NULLIFIED`),t.literal(`CANCELED`)]),xe=t.union([t.literal(`QUOTATION`),t.literal(`WORK_IN_PROGRESS`),t.literal(`CONFIRM`),t.literal(`CONFIRMED`),t.literal(`OPTION`),t.literal(`OPTIONED`),t.literal(`REQUEST`),t.literal(`REQUESTED`),t.literal(`NULLIFIED`),t.literal(`CANCELED`)]),w={CONFIRM:`CONFIRMED`,OPTION:`OPTIONED`,REQUESTED:`REQUEST`};function Se(e){return e in w?w[e]:e}const T=t.union([t.literal(`TOP`),t.literal(`TOP_SS`),t.literal(`ADV`),t.literal(`GRP`),t.literal(`OTHER`)]),E=t.union([t.literal(`ACCOMODATION`),t.literal(`TRANSPORT`),t.literal(`CHARTER`),t.literal(`TRANSFER`),t.literal(`PULLMAN`),t.literal(`FERRY`),t.literal(`CRUISE`),t.literal(`INSURANCE`),t.literal(`EXTRAFEE`),t.literal(`PENALTY`),t.literal(`PROMO`),t.literal(`OTHER`),t.literal(`NOT_SET`),t.literal(`RESIDENCE`)]),Ce=t.union([t.literal(`REQUEST`),t.literal(`ALLOTMENT_REQUEST`),t.literal(`CONFIRMED_REQUEST`),t.literal(`CONFIRMED_EXTRA_ALLOTMENT`),t.literal(`WAITLISTED`),t.literal(`ALLOTMENT`),t.literal(`REFUSED`),t.literal(`NULLIFIED`),t.literal(`CANCELED`),t.literal(`MESSAGE`)]),D=t.union([t.literal(`C`),t.literal(`B`),t.literal(`D`),t.literal(`T`),t.literal(`P`),t.literal(`R`),t.literal(`A`),t.literal(`H`),t.literal(`I`),t.literal(`J`),t.literal(`K`),t.literal(`L`),t.literal(`M`),t.literal(`N`),t.literal(`O`),t.literal(`Q`),t.literal(`S`),t.literal(`U`),t.literal(`V`)]),O=t.union([t.string(),t.number()]),we=t.pipe(t.object({"@Value":xe,"@ExpiredDate":t.optional(t.string()),"@ExpireDate":t.optional(t.string())}),t.transform(e=>({"@Value":Se(e[`@Value`]),"@ExpiredDate":e[`@ExpiredDate`]??e[`@ExpireDate`]}))),Te=t.object({"@PaxRef":t.string(),"@Price":O}),Ee=t.object({PricePerPaxDetail:t.optional(b(Te))}),De=t.object({"@CommissionCode":t.optional(t.string()),"@CommissionPercentage":t.optional(O),"@CommissionAmount":t.optional(O),"@PriceListCode":t.optional(t.string()),"@CostListCode":t.optional(t.string()),"@ServiceTotalPrice":t.optional(O),PaxPriceList:t.optional(Ee)}),Oe=t.object({"@Code":t.optional(t.string()),"@Name":t.optional(t.string()),"@Email":t.optional(t.string()),"@LanguageCode":t.optional(t.string())}),ke=t.object({"@Code":t.optional(t.string()),"@Description":t.optional(t.string())}),Ae=t.object({"@RPH":t.string(),"@ServiceCode":t.optional(t.string()),"@FromExternalProvider":t.optional(O),"@isFromExternalProvider":t.optional(O),AvesServiceType:t.optional(T),TOServiceType:t.optional(E),FirstDescription:t.optional(t.string()),SecondDescription:t.optional(t.string()),ThirdDescription:t.optional(t.string()),FourthDescription:t.optional(t.string()),ServiceStatus:t.optional(Ce),StartDate:t.optional(t.string()),EndDate:t.optional(t.string()),Qty:t.optional(O),Pax:t.optional(O),PeriodType:t.optional(t.string()),PaxMultiplier:t.optional(t.string()),ExternalProviderCode:t.optional(t.string()),WebStatisticCode:t.optional(t.string()),WebStatisticDescription:t.optional(t.string()),WebStatistic:t.optional(ke),SupplierInfo:t.optional(Oe),ServiceTotalAmountDetail:t.optional(De)}),je=t.pipe(Ae,t.transform(e=>({"@RPH":e[`@RPH`],"@ServiceCode":e[`@ServiceCode`],"@FromExternalProvider":e[`@FromExternalProvider`]??e[`@isFromExternalProvider`],AvesServiceType:e.AvesServiceType,TOServiceType:e.TOServiceType,FirstDescription:e.FirstDescription,SecondDescription:e.SecondDescription,ThirdDescription:e.ThirdDescription,FourthDescription:e.FourthDescription,ServiceStatus:e.ServiceStatus,StartDate:e.StartDate,EndDate:e.EndDate,Qty:e.Qty,Pax:e.Pax,PeriodType:e.PeriodType,PaxMultiplier:e.PaxMultiplier,ExternalProviderCode:e.ExternalProviderCode,WebStatisticCode:e.WebStatisticCode,WebStatisticDescription:e.WebStatisticDescription,WebStatistic:e.WebStatistic,SupplierInfo:e.SupplierInfo,ServiceTotalAmountDetail:e.ServiceTotalAmountDetail}))),Me=t.object({BookedServiceDetail:t.optional(b(je))}),k=t.object({"@CurrencyCode":t.optional(t.string()),"@TotalAmountBeforeDiscount":t.optional(O),"@TotalAmountAfterDiscount":t.optional(O),"@TotalDiscount":t.optional(O),"@TotalAmountWithoutVat":t.optional(O),"@DueAmount":t.optional(O),"@PaiedAmount":t.optional(O),"@Balance":t.optional(O)}),Ne=t.object({"@RPH":t.string(),"@RoomRPH":t.optional(t.string()),"@BillingHolder":t.optional(O),Name:t.optional(t.string()),CategoryCode:t.optional(t.string()),Sex:t.optional(t.string()),BirthDate:t.optional(t.string()),BirthPlace:t.optional(t.string()),NationCode:t.optional(t.string()),CitizenshipCode:t.optional(t.string()),FiscalCode:t.optional(t.string()),PhoneNumber:t.optional(t.string()),EMail:t.optional(t.string()),MasterRecordCode:t.optional(t.string())}),Pe=t.object({PassengerDetail:t.optional(b(Ne))}),Fe=t.object({"@ReschedulingCode":t.optional(t.string()),"@ExpireDate":t.optional(t.string()),"@TotalAmount":t.optional(O),ReschedulingCode:t.optional(t.string()),ExpireDate:t.optional(t.string()),TotalAmount:t.optional(O)}),Ie=t.pipe(Fe,t.transform(e=>({"@ReschedulingCode":e[`@ReschedulingCode`]??e.ReschedulingCode,"@ExpireDate":e[`@ExpireDate`]??e.ExpireDate,"@TotalAmount":e[`@TotalAmount`]??e.TotalAmount}))),Le=t.object({DeadlineDetail:t.optional(b(Ie))}),Re=t.object({DocumentRefCode:t.optional(t.string()),DocumentType:t.optional(t.string()),DocumentName:t.optional(t.string()),ArchiviationDescription:t.optional(t.string())}),ze=t.object({StoredDocumentDetail:t.optional(b(Re))}),Be=t.object({DocumentType:t.optional(t.string()),DocumentName:t.optional(t.string()),Enabled:t.optional(O)}),Ve=t.object({PrintableDocumentDetail:t.optional(b(Be))}),He=t.object({"@BookingFileCode":t.optional(t.string()),BookingFileCode:t.optional(t.string()),CustomerRecordCode:t.optional(t.string()),CustomerName:t.optional(t.string()),CustomerEmail:t.optional(t.string()),TravelAgencyName:t.optional(t.string()),TravelAgencyEmail:t.optional(t.string()),BookingFileStatus:t.optional(we),Description:t.optional(t.string()),Nation:t.optional(t.string()),Destination:t.optional(t.string()),CreationDate:t.optional(t.string()),FirstConfirmationDate:t.optional(t.string()),StartDate:t.optional(t.string()),EndDate:t.optional(t.string()),PackageCode:t.optional(t.string()),BookedServiceList:t.optional(Me),TotalAmountDetail:t.optional(k),PaxNumber:t.optional(O),PassengerList:t.optional(Pe),Reference:t.optional(t.string()),ClerkName:t.optional(t.string()),StoredDocumentsList:t.optional(ze),PrintableDocumentsList:t.optional(Ve),FinancialDeadlineList:t.optional(Le)}),Ue=t.pipe(He,t.transform(e=>({"@BookingFileCode":e[`@BookingFileCode`]??e.BookingFileCode,CustomerRecordCode:e.CustomerRecordCode,CustomerName:e.CustomerName,CustomerEmail:e.CustomerEmail,TravelAgencyName:e.TravelAgencyName,TravelAgencyEmail:e.TravelAgencyEmail,BookingFileStatus:e.BookingFileStatus,Description:e.Description,Nation:e.Nation,Destination:e.Destination,CreationDate:e.CreationDate,FirstConfirmationDate:e.FirstConfirmationDate,StartDate:e.StartDate,EndDate:e.EndDate,PackageCode:e.PackageCode,BookedServiceList:e.BookedServiceList,TotalAmountDetail:e.TotalAmountDetail,PaxNumber:e.PaxNumber,PassengerList:e.PassengerList,Reference:e.Reference,ClerkName:e.ClerkName,StoredDocumentsList:e.StoredDocumentsList,PrintableDocumentsList:e.PrintableDocumentsList,FinancialDeadlineList:e.FinancialDeadlineList}))),We=t.object({"@HostID":t.pipe(t.string(),t.minLength(6),t.maxLength(6)),"@Xtoken":t.string(),"@Interface":t.literal(`WEB`),"@UserName":t.literal(`WEB`),"@LanguageCode":t.optional(t.pipe(t.string(),t.minLength(2),t.maxLength(2)))}),Ge=t.optional(t.pipe(t.string(),t.transform(e=>e.split(`,`)))),A=t.pipe(t.object({"@Status":t.union([t.literal(`OK`),t.literal(`ERROR`),t.literal(`WARNING`),t.literal(`TIMEOUT`)]),ErrorCode:t.optional(t.pipe(t.union([t.string(),t.number()]),t.transform(e=>Number(e)))),ErrorDescription:t.optional(t.string()),Warnings:Ge}),t.transform(e=>({status:e[`@Status`],errorCode:e.ErrorCode,errorDescription:e.ErrorDescription,warnings:e.Warnings}))),Ke=t.object({value:ye,expiredDate:t.optional(t.string())}),j=t.object({sCode1:t.optional(t.pipe(t.string(),t.maxLength(4))),sCode2:t.optional(t.pipe(t.string(),t.maxLength(4))),sCode3:t.optional(t.pipe(t.string(),t.maxLength(4))),sCode4:t.optional(t.pipe(t.string(),t.maxLength(4))),sCode5:t.optional(t.pipe(t.string(),t.maxLength(4))),sCode6:t.optional(t.pipe(t.string(),t.maxLength(4)))}),qe=t.object({code:t.optional(t.string()),iataCode:t.optional(t.string()),nationCode:t.optional(t.string())}),Je=t.object({recordCode:t.optional(t.string())}),Ye=t.union([t.literal(`VISA_REQUEST`),t.literal(`TRAVEL_INFORMATION`),t.literal(`VOUCHER`),t.literal(`BOOKING_CONTRACT`),t.literal(`BOOKING_CONFIRMATION`),t.literal(`SUPPLIER_SERVICE_LIST`),t.literal(`INVOICE`),t.literal(`PROFORMA_INVOICE`),t.literal(`ADEGUAMENTO`),t.literal(`RESERVATION_FORM`),t.literal(`OPEN_XML`),t.literal(`SALES_INVOICE`),t.literal(`TICKETING_TMASTER`),t.literal(`SUMMARY_FORM`)]),Xe=t.object({makeDocumentTo:t.optional(t.union([t.literal(`BOOKING_CUSTOMER`),t.literal(`FIRST_PASSENGER`)]))}),Ze=t.object({fillInCode:t.optional(t.string())}),Qe=t.union([Xe,Ze]),$e=t.object({documentType:Ye,documentCustomizablePrintParameters:t.optional(Qe)}),et=t.object({printDoc:t.optional(C),sendDocViaEmail:t.optional(C),infoDocumentsToPrint:t.optional(t.array($e))}),tt=t.object({reschedulingCode:t.optional(t.string()),expireDate:t.optional(t.string()),totalAmount:t.optional(t.string())}),nt=t.object({deadlineCode:t.optional(t.string()),description:t.optional(t.string()),expireDate:t.optional(t.string())}),rt=t.object({paymentDate:t.optional(t.string()),paumentNote:t.optional(t.string()),amount:t.optional(t.string()),paymentUser:t.optional(t.string()),paymentType:t.optional(D)}),it=t.union([t.literal(`PAX_QTY_DAY`),t.literal(`PAX_QTY_NIGHT`),t.literal(`PAX_QTY_WEEK`),t.literal(`PAX_QTY`),t.literal(`PAX_DAY`),t.literal(`PAX_NIGHT`),t.literal(`PAX_WEEK`),t.literal(`PAX`),t.literal(`QTY_DAY`),t.literal(`QTY_NIGHT`),t.literal(`QTY_WEE`),t.literal(`QTY`),t.literal(`DAY`),t.literal(`NIGHT`),t.literal(`WEEK`),t.literal(`FORFAIT`)]),at=t.object({currencyCode:t.optional(t.string()),exchangeRate:t.optional(t.string()),cost:t.optional(t.string()),costTax:t.optional(t.string()),costType:t.optional(it),vatCostCurrencyCode:t.optional(t.string()),price:t.optional(t.string()),priceTax:t.optional(t.string()),priceType:t.optional(it)}),ot=t.object({packageCode:t.optional(t.string()),packageReference:t.optional(t.string()),suballotmentCode:t.optional(t.string()),priceListCode:t.optional(t.string()),costListCode:t.optional(t.string()),externalFileCode:t.optional(t.string()),externalReference:t.optional(t.string()),serviceStatus:t.optional(t.string()),serviceStatisticCode:t.optional(t.string()),serviceFare:t.optional(at)}),st=t.object({pax:t.string()}),M=t.object({sCode:t.string(),ssCode:t.optional(t.string()),avesServiceType:T,toServiceType:t.optional(E),subServiceDesc:t.optional(t.string()),startDate:t.string(),endDate:t.string(),qty:t.string(),pax:t.string(),paxAssociated:t.optional(t.array(st)),avesSession:t.string(),avesServiceInfo:t.optional(ot),serviceFare:t.optional(at),bookedServiceRef:t.optional(t.string()),supplierMasterCode:t.optional(t.string()),voucherMasterCode:t.optional(t.string()),hotelServiceInfo:t.optional(t.string()),carRentalServiceInfo:t.optional(t.string()),flightServiceInfo:t.optional(t.string()),shipServiceInfo:t.optional(t.string()),ticketServiceInfo:t.optional(t.string()),commission:t.optional(t.string()),noteList:t.optional(t.string()),voucherInfo:t.optional(t.string()),firstDescription:t.optional(t.string()),secondDescription:t.optional(t.string())}),N=t.object({pCode:t.string(),startDate:t.string(),endDate:t.string(),getServicesFromPackage:t.optional(C)}),P=t.object({nType:t.optional(t.string()),title:t.optional(t.string()),text:t.optional(t.string())}),F=t.union([t.literal(`AD`),t.literal(`CH`),t.literal(`IN`),t.literal(`OV`)]),I={rph:t.string(),roomRph:t.optional(t.string()),billingHolder:t.optional(C),masterRecordCode:t.optional(t.string()),name:t.string(),sex:t.union([t.literal(`M`),t.literal(`F`)]),birthDate:t.optional(t.string()),birthPlace:t.optional(t.string()),nationCode:t.optional(t.string()),citizenshipCode:t.optional(t.string()),fiscalCode:t.optional(t.string()),phoneNumber:t.optional(t.string()),eMail:t.optional(t.string()),notes:t.optional(t.array(P)),flagStatus:t.optional(t.string()),offerCode:t.optional(t.string()),idDocInfo:t.optional(t.object({idType:t.optional(t.string()),idCode:t.optional(t.string()),idIssueLocation:t.optional(t.string()),idIssueCounty:t.optional(t.string()),idIssueDate:t.optional(t.string()),idExpireDate:t.optional(t.string())}))},ct=t.object({...I,categoryCode:F}),L=t.object({...I,categoryCode:t.optional(F)}),lt=t.union([t.literal(`CASH`),t.literal(`BANK`),t.literal(`RID`),t.literal(`RIBA`),t.literal(`SPECIFIC_CODE`),t.literal(`NOT_SET`)]),R=t.object({customer_PaymentType:t.optional(lt),customer_SpecPaymentTypeCode:t.optional(t.string())}),ut=t.union([t.literal(`GROUPED_PAX`),t.literal(`NOT_GROUPED_PAX`),t.literal(`ONE_PAX_ONLY`)]),dt=t.union([t.literal(`AVES2AVES`),t.literal(`AVES2AVESVIA`),t.literal(`AVES2AVESITA`)]),ft=v(t.object({createDate:t.optional(t.string()),bookingFileRefCode:t.optional(t.string()),travelAgentCode:t.optional(t.string()),clerkName:t.optional(t.string()),customerDetail:Je,currencyCode:t.optional(t.string()),markupCode:t.optional(t.string()),bookingFileStatus:Ke,statisticCodes:t.optional(j),destination:t.optional(qe),bookingFileDescription:t.optional(t.string()),startDate:t.string(),endDate:t.string(),earlyBookingDate:t.optional(t.string()),cupCode:t.optional(t.string()),cigCode:t.optional(t.string()),customerPromoterCode:t.optional(t.string()),billingReferenceCode:t.optional(t.string()),paymentReferenceCode:t.optional(t.string()),bookingFileDocument:t.optional(et),financialDeadlineList:t.optional(t.array(tt)),deadlineList:t.optional(t.array(nt)),paymentList:t.optional(t.array(rt)),selectedPackageList:t.optional(t.array(N)),selectedServiceList:t.array(M),extraQuotaRefCode:t.optional(t.string()),extraQuoteServiceList:t.optional(t.array(M)),getExtraQuoteFromSystem:t.optional(C),passengerList:t.array(ct),noteList:t.optional(t.array(P)),bookingFinancialInfo:t.optional(R),bookingFileCode:t.optional(t.string()),groupingPaxPolicy:t.optional(ut),groupBookingFile:t.optional(C),typeDownloadFile:t.optional(dt),setBookingFileCodeFromStartDate:t.optional(C)}),{listKeys:fe,arrayOfOne:pe}),z=x(t.object({RsStatus:A,BookingFileDetail:t.optional(Ue),PrintableDocumentsList:t.optional(Ve),TotalAmountDetailAfterCancellation:t.optional(k),Base64DocContent:t.optional(t.string())})),B=x(t.object({RsStatus:A})),V=z,pt=t.object({reschedulingCode:t.string(),description:t.optional(t.string()),expireDate:t.optional(t.string())}),mt=t.object({cancelOperationType:t.union([t.literal(`NULLIFY`),t.literal(`DELETE`)]),serviceRefType:t.union([t.literal(`RPH`),t.literal(`FILE`)]),serviceRefValue:t.string()}),ht=v(t.object({customerRecordCode:t.string(),bookingFileCode:t.string(),currencyCode:t.optional(t.string()),deadlineList:t.optional(t.array(pt)),selectedPackageDetail:t.optional(N),selectedServiceList:t.pipe(t.array(M),t.minLength(1)),cancellableBookedServiceList:t.optional(t.array(mt)),passengerList:t.optional(t.array(L))}),{listKeys:me}),gt=v(t.object({bookingFileCode:t.string(),bookingFileStartDate:t.string(),customerRecordCode:t.string(),newCustomerRecordCode:t.optional(t.string()),bookingFileReferenceName:t.optional(t.string()),travelAgentCode:t.optional(t.string()),billingReferenceCode:t.optional(t.string()),paymentReferenceCode:t.optional(t.string()),cupCode:t.optional(t.string()),cigCode:t.optional(t.string()),customerPromoterCode:t.optional(t.string()),bookingNote:t.optional(t.string()),passengerList:t.optional(t.array(L)),statisticCodes:t.optional(j),bookingFinancialInfo:t.optional(R),financialDeadlineList:t.optional(t.array(t.object({reschedulingCode:t.string(),expireDate:t.string(),totalAmount:t.string()})))}),{listKeys:he}),_t=y(t.object({bookingFileCode:t.string(),customerRecordCode:t.string()})),vt=t.union([t.literal(`NOT_SET`),t.literal(`CONSIDER_HOLIDAY`),t.literal(`CONSIDER_HOLIDAY_AND_SATURDAY`)]),yt=y(t.object({customerRecordCode:t.string(),bookingFileCode:t.string(),fileStatus:t.object({value:be,expiredDate:t.optional(t.string()),optionedFileExpireDatePolicy:t.optional(vt)}),backOfficeRequest:t.optional(C),bookingFileDocument:t.optional(et),penalty:t.optional(t.object({apply:t.optional(C),specificCode:t.optional(t.string())})),simulateCancelAndGetPenaltyAmount:t.optional(C)})),bt=y(t.object({customerRecordCode:t.string(),bookingFileCode:t.string(),bookingServiceRef:t.string(),bookingFileServiceStatus:t.literal(`NULLIFIED`),bookingFileServiceStatusDate:t.optional(t.string())})),xt=t.union([t.literal(`AbsoluteAmountsInsertion`),t.literal(`FinalAmountToAchieve`),t.literal(`FinalAmountToAchieveWithoutControls`)]),St=t.object({paymentDate:t.string(),paymentNote:t.optional(t.string()),payerMasterCode:t.optional(t.string()),payerName:t.optional(t.string()),amount:t.string(),paymentType:D}),Ct=v(t.pipe(t.object({bookingFileCode:t.optional(t.string()),bookingFileRefCode:t.optional(t.string()),paymentUser:t.optional(t.string()),enableMultiplePayments:C,operationType:xt,filePaymentList:t.pipe(t.array(St),t.minLength(1))}),t.check(e=>!!(e.bookingFileCode||e.bookingFileRefCode),`bookingFileCode or bookingFileRefCode is required`)),{listKeys:ge}),H=t.union([t.literal(`CASH`),t.literal(`BANK`),t.literal(`RID`),t.literal(`RIBA`),t.literal(`SPECIFIC_CODE`)]),U=t.object({currencyCode:t.optional(t.string()),creditLimit:t.optional(t.string()),c_PaymentType:t.optional(H),c_SpecPaymentTypeCode:t.optional(t.string()),s_PaymentType:t.optional(H),s_SpecPaymentTypeCode:t.optional(t.string()),enableElectronicInvoicing:t.optional(t.union([t.literal(`true`),t.literal(`false`),t.boolean()])),electronicInvoicingType:t.optional(t.string())});y(U);const wt=S(U),W=t.object({idType:t.optional(t.string()),idCode:t.optional(t.string()),idIssueLocation:t.optional(t.string()),idIssueCounty:t.optional(t.string()),idIssueDate:t.optional(t.string()),idExpireDate:t.optional(t.string())});y(W);const Tt=S(W),G=t.object({key:t.string(),value:t.string()});y(t.array(G));const Et=S(G),Dt=t.union([t.literal(`NOT_SET`),t.literal(`FLIGHT`),t.literal(`SHIP`),t.literal(`TRAIN`),t.literal(`RENTCAR`),t.literal(`BUS`),t.literal(`DP_HOTEL`),t.literal(`TO_HOTEL`),t.literal(`TO_TOUR`),t.literal(`TO_HOTEL_AND_TOUR`),t.literal(`DP_AUTO`),t.literal(`DP_GDS_NAVI`),t.literal(`DP_GDS_VOLI`),t.literal(`TOUR_OPERATOR`),t.literal(`TICKETING_EV`),t.literal(`OTHER`)]),K=t.object({supplierRefCode:t.optional(t.string()),companyMainBusinessType:t.optional(t.string()),carrierType:t.optional(Dt)});y(K);const Ot=S(K),q=t.union([t.literal(0),t.literal(1)]),kt=t.union([t.literal(`ENABLED`),t.literal(`DISABLED`),t.literal(`WARNING`),t.literal(`BLACKLISTED`)]),At=t.union([t.literal(`CUSTOMER`),t.literal(`SUPPLIER`),t.literal(`GENERAL`)]),jt=t.union([t.literal(`S`),t.literal(`N`),t.literal(`T`),t.literal(`M`)]),J=t.object({acceptProfilingPolicies:t.optional(q),acceptPrivacyPolicies:t.optional(q),acceptNewsletterPolicies:t.optional(q)});y(J);const Mt=S(J),Nt=y(t.object({recordCode:t.optional(t.pipe(t.string(),t.minLength(6),t.maxLength(6))),insertCriteria:t.optional(jt),createdDate:t.optional(t.string()),recordType:t.optional(t.union([At],`CUSTOMER`)),recordStatus:t.optional(t.union([kt],`ENABLED`)),moniker:t.optional(t.string()),name:t.optional(t.string()),extraInfo:t.optional(t.string()),languageCode:t.pipe(t.string(),t.minLength(2),t.maxLength(2)),address:t.optional(t.string()),zipCode:t.optional(t.string()),cityName:t.optional(t.string()),countyCode:t.optional(t.string()),stateCode:t.optional(t.string()),categoryCode:t.optional(t.string()),firstPhoneNumber:t.optional(t.string()),mobilePhoneNumber:t.optional(t.string()),email:t.optional(t.string()),gender:t.optional(t.union([t.literal(`M`),t.literal(`F`)])),birthDate:t.optional(t.string()),birthCity:t.optional(t.string()),birthCounty:t.optional(t.string()),fiscalCode:t.optional(t.string()),vatCode:t.optional(t.string()),thirdPartRecordCode:t.optional(t.string()),idDocumentDetail:t.optional(W),accountPolicies:t.optional(J),financialDetail:t.optional(U),dynamicFields:t.optional(G),supplierRefMasterRecords:t.optional(K)}));x(Nt);const Y=t.object({"@RecordCode":t.optional(t.pipe(t.string(),t.minLength(6),t.maxLength(6))),"@InsertCriteria":t.optional(jt),CreatedDate:t.optional(t.string()),ModifiedDate:t.optional(t.string()),RecordType:t.optional(t.union([t.literal(`CUSTOMER`),t.literal(`SUPPLIER`),t.literal(`GENERAL`)])),LoginType:t.optional(t.string()),RecordStatus:t.optional(kt),Moniker:t.optional(t.string()),Name:t.optional(t.string()),ExtraInfo:t.optional(t.string()),LanguageCode:t.optional(t.pipe(t.string(),t.minLength(1),t.maxLength(2))),Address:t.optional(t.string()),ZipCode:t.optional(t.string()),CityName:t.optional(t.string()),CountyCode:t.optional(t.string()),StateCode:t.optional(t.string()),CategoryCode:t.optional(t.string()),PromoterCode:t.optional(t.string()),FirstPhoneNumber:t.optional(t.string()),MobilePhoneNumber:t.optional(t.string()),Email:t.optional(t.string()),Gender:t.optional(t.union([t.literal(`M`),t.literal(`F`)])),BirthDate:t.optional(t.string()),BirthCity:t.optional(t.string()),BirthCounty:t.optional(t.string()),EncryptedPassword:t.optional(t.union([t.literal(`true`),t.literal(`false`),t.boolean()])),FiscalCode:t.optional(t.string()),VatCode:t.optional(t.string()),ThirdPartRecordCode:t.optional(t.string()),IdDocumentDetail:t.optional(Tt),NewsletterDisabled:t.optional(t.union([t.literal(`true`),t.literal(`false`),t.boolean()])),SupplierRefMasterRecords:t.optional(Ot),AccountPolicies:t.optional(Mt),FinancialDetail:t.optional(wt),DynamicFields:t.optional(Et)}),Pt=t.object({minDate:t.string(),maxDate:t.string()}),X=t.optional(t.pipe(t.string(),t.minLength(2),t.maxLength(2))),Ft=t.object({searchType:t.literal(`CODE`),recordCode:t.pipe(t.string(),t.minLength(5),t.maxLength(6)),languageCode:X}),It=t.object({searchType:t.literal(`NAME`),name:t.string(),city:t.optional(t.string()),languageCode:X}),Lt=t.object({searchType:t.literal(`VATCODE`),vatCode:t.string(),phoneNumber:t.optional(t.string()),languageCode:X}),Rt=t.object({searchType:t.literal(`ZONE`),zipCode:t.string(),countyCode:t.string(),city:t.optional(t.string()),languageCode:X}),zt=t.object({searchType:t.literal(`CATEGORY`),categoryCode:t.string(),languageCode:X}),Bt=t.object({searchType:t.literal(`EMAIL`),email:t.string(),languageCode:X}),Vt=t.object({searchType:t.literal(`LASTMODDATE`),lastModificationDate:Pt,languageCode:X}),Ht=t.object({searchType:t.literal(`SEARCH_FIELD`),searchFieldValue:t.string(),languageCode:X}),Ut=t.object({searchType:t.literal(`EXTERNAL_REF_CODE`),searchFieldValue:t.string(),languageCode:X}),Wt=t.union([Ft,It,Lt,Rt,zt,Bt,Vt,Ht,Ut]),Gt=e=>{if(!(`@RecordCode`in e))return e;let t=e[`@RecordCode`];if(!t)return e;let{"@RecordCode":n,...r}=e;return{...r,RecordCode:t}},Kt=t.pipe(y(Wt),t.transform(e=>Gt(e))),qt=t.pipe(t.object({RqHeader:We,SearchMasterRecord:Kt}),t.transform(e=>{let{SearchMasterRecord:t,RqHeader:n,...r}=e;return{RqHeader:n,...t,...r}})),Jt=t.object({MasterRecordDetail:t.optional(t.pipe(t.union([t.array(Y),Y]),t.transform(e=>{if(e)return Array.isArray(e)?e:[e]})))}),Yt=x(t.object({RsStatus:A,MasterRecordList:t.optional(Jt)})),Xt=t.object({RqHeader:We,MasterRecordDetail:Y}),Zt=x(t.object({RsStatus:A,MasterRecordDetail:t.optional(Y)}));function Qt(e){return{success:!0,data:e}}function Z(e){return{success:!1,error:e}}function $t(e){return e===200}function en(e){let t=new AbortController;if(!e||e<=0)return{signal:t.signal};let n=setTimeout(()=>t.abort(),e);return{signal:t.signal,clear:()=>clearTimeout(n)}}function tn(e,t){try{let n=new URL(e),r=(n.pathname.endsWith(`/`)?n.pathname.slice(0,-1):n.pathname)+t;return new URL(r,n)}catch(e){throw new c(`validation`,`Invalid baseURL: ${e instanceof Error?e.message:`Invalid URL format`}`)}}function nn(e,t){if(!t.startsWith(`/`))throw new c(`validation`,`Invalid endpoint: endpoint must start with '/' but got '${t}'`);let n=tn(e.replace(/\/$/,``),t);if(n.protocol!==`http:`&&n.protocol!==`https:`)throw new c(`validation`,`Invalid protocol: baseURL must use http:// or https:// but got '${n.protocol}'`);return n.toString()}const rn={ignoreAttributes:!1,attributeNamePrefix:`@`,parseAttributeValue:!1,trimValues:!0,ignoreNameSpace:!0,removeNSPrefix:!0,parseTagValue:!1},an={ignoreAttributes:!1,attributeNamePrefix:`@`,suppressEmptyNode:!0},on=new o(rn),sn=new a(an);function cn(e){try{return sn.build(e)}catch(e){throw new c(`validation`,`Failed to convert JSON to XML: ${e instanceof Error?e.message:`Unknown error`}`)}}function ln(e){try{return on.parse(e)}catch(e){throw new c(`validation`,`Failed to convert XML to JSON: ${e instanceof Error?e.message:`Unknown error`}`)}}const Q={SEARCH_REQUEST:`SearchMasterRecordRQ`,SEARCH_RESPONSE:`SearchMasterRecordRS`,UPSERT_REQUEST:`ManageMasterRecordRQ`,UPSERT_RESPONSE:`ManageMasterRecordRS`,BOOKING_REQUEST:`BookFileRQ`,BOOKING_RESPONSE:`BookingFileRS`,MOD_FILE_SERVICES_REQUEST:`ModFileServicesRQ`,MOD_FILE_HEADER_REQUEST:`ModFileHeaderRQ`,MOD_FILE_HEADER_RESPONSE:`ModFileHeaderRS`,CANCEL_FILE_REQUEST:`CancelFileRQ`,CANCEL_FILE_RESPONSE:`CancelFileRS`,SET_STATUS_REQUEST:`SetStatusRQ`,SET_STATUS_RESPONSE:`SetStatusRS`,SET_STATUS_SERVICE_REQUEST:`SetStatusServiceRQ`,SET_STATUS_SERVICE_RESPONSE:`SetStatusServiceRS`,FILE_PAYMENT_LIST_REQUEST:`FilePaymentListRQ`,FILE_PAYMENT_LIST_RESPONSE:`FilePaymentListRS`};function $(e,t){return{[e]:t}}var un=class{options;constructor(e){this.options=e}createRqHeader(){return{"@HostID":this.options.hostID,"@Xtoken":this.options.xtoken,"@Interface":`WEB`,"@UserName":`WEB`,...this.options.languageCode&&{"@LanguageCode":this.options.languageCode}}}createUrl(e){return nn(this.options.baseURL,e)}get endpoints(){return{search:`/interop/masterRecords/v2/rest/Search`,upsert:`/interop/masterRecords/v2/rest/InsertOrUpdate`,createBooking:`/interop/booking/v2/rest/CreateBookingFile`,modBookingServices:`/interop/booking/v2/rest/ModBookingFileServices`,modBookingHeader:`/interop/booking/v2/rest/ModBookingFileHeader`,cancelBooking:`/interop/booking/v2/rest/CancelBookingFile`,setBookingStatus:`/interop/booking/v2/rest/SetBookingFileStatus`,setBookingServiceStatus:`/interop/booking/v2/rest/SetBookingFileServiceStatus`,insertFilePaymentList:`/interop/booking/v2/rest/InsertFilePaymentList`}}handleApiStatus(e){let t=e.rsStatus,n=t?.status;return n===`OK`?Qt(e):Z(u(t.errorDescription,n,t.errorCode))}toAvesError(e,t){return e instanceof c?e:e instanceof n?l(`Validation error: ${ee(e.issues)}`):e instanceof Error?d(e.message):d(t)}async request(t,n,r,a){let{signal:o,clear:s}=en(this.options.timeoutMs??3e4);try{let s=await e(this.createUrl(t),{method:`POST`,headers:{"Content-Type":`application/xml`},body:cn(n),signal:o}),c=await s.body.text();if(!$t(s.statusCode))return Z(u(c,`ERROR`,s.statusCode));let d=ln(c)[r];if(!d)return Z(l(`Invalid response structure: missing root element '${r}'`));let f=i(a,d);return f.success?this.handleApiStatus(f.output):Z(l(`Invalid response format: ${ee(f.issues)}`))}catch(e){return re(e)?Z(u(`Request timed out`,`TIMEOUT`)):Z(this.toAvesError(e,`Unknown error occurred`))}finally{s?.()}}async invokeOp(e){try{let t=r(e.apiSchema,e.params);return this.request(e.endpoint,$(e.requestRoot,{RqHeader:this.createRqHeader(),...t}),e.responseRoot,e.responseSchema)}catch(t){return Z(this.toAvesError(t,`Validation error occurred during ${e.op}`))}}async search(e){try{let t=r(qt,{RqHeader:this.createRqHeader(),SearchMasterRecord:e}),n=$(Q.SEARCH_REQUEST,t);return this.request(this.endpoints.search,n,Q.SEARCH_RESPONSE,Yt)}catch(e){return Z(this.toAvesError(e,`Validation error occurred during search`))}}async upsertRecord(e){try{let t=r(Nt,e),n=r(Xt,{RqHeader:this.createRqHeader(),MasterRecordDetail:t}),i=$(Q.UPSERT_REQUEST,n);return this.request(this.endpoints.upsert,i,Q.UPSERT_RESPONSE,Zt)}catch(e){return Z(this.toAvesError(e,`Validation error occurred during upsert`))}}async createBooking(e){return this.invokeOp({op:`createBooking`,params:e,apiSchema:ft,endpoint:this.endpoints.createBooking,requestRoot:Q.BOOKING_REQUEST,responseRoot:Q.BOOKING_RESPONSE,responseSchema:z})}async modBookingServices(e){return this.invokeOp({op:`modBookingServices`,params:e,apiSchema:ht,endpoint:this.endpoints.modBookingServices,requestRoot:Q.MOD_FILE_SERVICES_REQUEST,responseRoot:Q.BOOKING_RESPONSE,responseSchema:V})}async modBookingHeader(e){return this.invokeOp({op:`modBookingHeader`,params:e,apiSchema:gt,endpoint:this.endpoints.modBookingHeader,requestRoot:Q.MOD_FILE_HEADER_REQUEST,responseRoot:Q.MOD_FILE_HEADER_RESPONSE,responseSchema:B})}async cancelBooking(e){return this.invokeOp({op:`cancelBooking`,params:e,apiSchema:_t,endpoint:this.endpoints.cancelBooking,requestRoot:Q.CANCEL_FILE_REQUEST,responseRoot:Q.CANCEL_FILE_RESPONSE,responseSchema:B})}async setBookingStatus(e){return this.invokeOp({op:`setBookingStatus`,params:e,apiSchema:yt,endpoint:this.endpoints.setBookingStatus,requestRoot:Q.SET_STATUS_REQUEST,responseRoot:Q.SET_STATUS_RESPONSE,responseSchema:V})}async setBookingServiceStatus(e){return this.invokeOp({op:`setBookingServiceStatus`,params:e,apiSchema:bt,endpoint:this.endpoints.setBookingServiceStatus,requestRoot:Q.SET_STATUS_SERVICE_REQUEST,responseRoot:Q.SET_STATUS_SERVICE_RESPONSE,responseSchema:V})}async insertFilePaymentList(e){return this.invokeOp({op:`insertFilePaymentList`,params:e,apiSchema:Ct,endpoint:this.endpoints.insertFilePaymentList,requestRoot:Q.FILE_PAYMENT_LIST_REQUEST,responseRoot:Q.FILE_PAYMENT_LIST_RESPONSE,responseSchema:B})}};export{un as AvesClient,c as AvesError};
2
2
  //# sourceMappingURL=index.mjs.map