From a46a04739355b220c9c45817f2b0d64b536e60b9 Mon Sep 17 00:00:00 2001 From: Xavier Er Date: Tue, 2 Nov 2021 16:45:33 +0800 Subject: [PATCH] Include ts code and remove hotel rates merging logic (#127) * Remove hotel rates merger logic * Add logging of rate count * Revert rate merger changes * Change ways of passing extra body params to metasearch * Update build * Remove merging of rate based on provider logic * Renmove comments * Include ts code in HotelDetailsClient.js * Bump version * Remove commented code --- dist/WegoSdk.js | 2 +- package.json | 2 +- src/Poller.js | 9 +- src/hotel-details/HotelDetailsClient.js | 6 +- src/hotel-search/HotelSearchClient.js | 12 +- src/hotel-search/Merger.js | 72 +-------- src/hotel-search/dataUtils.js | 37 ----- test/hotel-search/HotelSearchClient.spec.js | 9 +- test/hotel-search/Merger.spec.js | 95 +----------- test/hotel-search/dataUtils.spec.js | 162 -------------------- 10 files changed, 28 insertions(+), 378 deletions(-) diff --git a/dist/WegoSdk.js b/dist/WegoSdk.js index 6855339..adab82d 100644 --- a/dist/WegoSdk.js +++ b/dist/WegoSdk.js @@ -1 +1 @@ -!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.WegoSdk=r():e.WegoSdk=r()}(self,(function(){return e={22:e=>{var r={__host:{staging:{v3:"https://srv.wegostaging.com/v3",v2:"https://srv.wegostaging.com/v2",v1:"https://srv.wegostaging.com"},production:{v3:"https://srv.wego.com/v3",v2:"https://srv.wego.com/v2",v1:"https://srv.wego.com"}},_hotelEndpoints:{hotelDetailsUrl:function(e){return r.getHost("v1")+"/hotels/hotels/"+e}},getHost:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"v2";return this.__host[this.getEnvironment()][e]},setEnvironment:function(e){this.env=e},getEnvironment:function(){return this.env||Wego.ENV||"staging"},searchTrips:function(e,r,t,n){return this.post(r,e,t,n)},fetchTrips:function(e,r,t,n){var i="".concat(e,"/").concat(r,"/results");return this.get(i,t||{},n)},searchHotels:function(e,r,t,n){return this.post(r,e,t,n)},fetchHotels:function(e,r,t,n){var i="".concat(e,"/").concat(r,"/results");return this.get(i,t||{},n)},searchHotel:function(e,r,t,n){var i="".concat(e,"/").concat(r.search.hotelId,"/searches");return this.post(r,i,t,n)},fetchHotelRates:function(e,r){var t=this.__host[this.getEnvironment()].v3+"/metasearch/hotels/"+e+"/rates";return this.get(t,r)},fetchHotelDetails:function(e,r){var t=this._hotelEndpoints.hotelDetailsUrl(e);return this.get(t,r)},fetchCities:function(e){var r=this.__host[this.getEnvironment()].v1+"/places/cities";return this.get(r,e)},fetchAirports:function(e){var r=this.__host[this.getEnvironment()].v1+"/places/airports";return this.get(r,e)},post:function(e,r,t,n){return fetch(this.buildUrl(r,t),{method:"POST",credentials:"include",mode:"cors",headers:Object.assign({},n,{"Content-Type":"application/json"}),body:JSON.stringify(e)}).then((function(e){return e.ok?e.json():Promise.reject()})).catch((function(e){return Promise.reject(e)}))},get:function(e,r,t){return fetch(this.buildUrl(e,r),{method:"GET",credentials:"include",mode:"cors",headers:Object.assign({},t,{"Content-Type":"application/json"})}).then((function(e){return e.ok?e.json():Promise.reject()})).catch((function(e){return Promise.reject(e)}))},buildUrl:function(e,r){if(r){var t=[];for(var n in r){var i=r[n];i instanceof Array?i.forEach((function(e){t.push(n+"[]="+e)})):t.push(n+"="+r[n])}e+="?"+t.join("&")}return e}};e.exports=r},15:e=>{var r=function(e){e=e||{},this.initCallApi=e.initCallApi,this.callApi=e.callApi,this.delays=e.delays,this.onSuccessResponse=e.onSuccessResponse,this.pollLimit=e.pollLimit};r.prototype={start:function(){var e=this;this.timer=setTimeout((function(){e.pollCount++,e.retryCount=0,e.fetch(e.initCallApi||e.callApi)}),0)},reset:function(){clearTimeout(this.timer),this.abortLastFetch&&this.abortLastFetch(),this.pollCount=0,this.forceStop=!1},stop:function(){this.forceStop=!0},isStopping:function(){return this.forceStop},isLastPolling:function(){return this.pollCount===this.pollLimit},getProgress:function(){return this.pollCount===this.pollLimit?100:this.pollCount/this.pollLimit*100},handleSuccessResponse:function(e){this.onSuccessResponse(e),this.preparePoll()},preparePoll:function(){var e=this;this.pollCount{function n(e,r){for(var t=0;t2;if(2===i.length){var a=["departureCityCode","departureAirportCode","arrivalCityCode","arrivalAirportCode"];(t=i[0])===(n=i[1])||t[a[0]]===n[a[2]]&&t[a[1]]===n[a[3]]&&t[a[2]]===n[a[0]]&&t[a[3]]===n[a[1]]||(o=!0)}r.multiCity=o,r.merger.multiCity=o;var s=r.poller;s.delays=(o?[0,3,3,3,4,4,4,4,5,5,5,5,5,6]:[0,1,3,4,5,6,6,6]).map((function(e){return 1e3*e})),s.pollLimit=s.delays.length-1,r.updateResult(),s.start()}},{key:"handleSearchResponse",value:function(e){var r=this;r.mergeResponse(e),r.updateResult(),1===r.poller.pollCount&&r.onSearchCreated(e.search)}},{key:"mergeResponse",value:function(e){var r=this;r.merger.mergeResponse(e),r.processedFaresCount=e.count,r.responseSearch=e.search}},{key:"reset",value:function(){var e=this;e.poller.reset(),e.merger.reset(),e.responseSearch={},e.processedFaresCount=0}},{key:"updatePaymentMethodIds",value:function(e){var r=this;r.paymentMethodIds=e,r.reset(),r.updateResult(),r.poller.start()}},{key:"updateProviderTypes",value:function(e){var r=this;r.providerTypes=e,r.reset(),r.updateResult(),r.poller.start()}},{key:"updateSort",value:function(e){this.sort=e,this.updateResult()}},{key:"updateFilter",value:function(e){this.filter=e,this.updateResult()}},{key:"updateCurrency",value:function(e){var r=this;r.currency=e,r.merger.updateCurrency(e),r.updateResult()}},{key:"updateResult",value:function(){var e=this,r=e.merger.getTrips();0!==Object.keys(e.merger.getLegConditions()).length&&a.passLegConditions(e.merger.getLegConditions()),0!==Object.keys(e.merger.getFareConditions()).length&&a.passFareConditions(e.merger.getFareConditions());var t=a.filterTrips(r,e.filter,e.multiCity),n=o.sortTrips(t,e.sort,e.filter);e.onTripsChanged(n),e.onCheapestTripChanged(o.getCheapestTrip(t,e.filter)),e.onFastestTripChanged(o.getFastestTrip(t)),e.onBestExperienceTripChanged(o.getBestExperienceTrip(t)),e.onTotalTripsChanged(r),e.onDisplayedFilterChanged(e.merger.getFilter()),e.onProgressChanged(e.poller.getProgress()),e.onProvidersChanged(e.merger.getProviders());var i=e.merger.getSponsors(),s=a.filterSponsors(i,r,e.filter,e.multiCity);e.onSponsorsChanged(s)}},{key:"getSearchRequestBody",value:function(){var e=this,r=e.search||{},t=r.legs||[];return{search:{id:e.responseSearch.id,cabin:r.cabin,deviceType:e.deviceType,appType:e.appType,userLoggedIn:e.userLoggedIn,adultsCount:r.adultsCount,childrenCount:r.childrenCount,infantsCount:r.infantsCount,siteCode:e.siteCode,currencyCode:e.currency.code,locale:e.locale,showWegoFares:e.showWegoFares,legs:t.map((function(e){return{departureCityCode:e.departureCityCode,departureAirportCode:e.departureAirportCode,arrivalCityCode:e.arrivalCityCode,arrivalAirportCode:e.arrivalAirportCode,outboundDate:e.outboundDate}}))},offset:e.processedFaresCount,paymentMethodIds:e.paymentMethodIds,providerTypes:e.providerTypes}}},{key:"fetchTripsParams",value:function(){var e=this;return{currencyCode:e.currency.code,locale:e.locale,paymentMethodIds:e.paymentMethodIds||[],offset:e.processedFaresCount}}}])&&n(r.prototype,t),e}();e.exports=u},854:(e,r,t)=>{function n(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t=0;"stops"===t&&(e.code=a[e.code]);var s=(o?n+1+"_":"")+e.code;i.prepareFilterOption(e,t,r.currency,r.__staticData),r.__filterOptionsMap[t][s]=e,e.code=s,o&&(e.legIndex=n)}))};if(n&&o)for(var c=o.length;c--;)s(o[c][t],c);else s(e[t]);r._buildFilterOptions(t)})),r._cloneFilter()}},_getUpdatedTripIds:function(e){var r={},t=this;if(e.scores)for(var n in e.scores)r[n]=!0;return e.fares&&e.fares.forEach((function(e){r[e.tripId]=!0})),Object.keys(r).filter((function(e){return t.__tripMap[e]}))},_cloneTrips:function(e){var r=this.__tripMap;e.forEach((function(e){var t=r[e];t?(t.fares=o.cloneArray(t.fares),r[e]=o.cloneObject(t)):console.error("Trip with "+e+" is missing")})),this.__trips=o.mapValues(r)},_cloneFilter:function(){this.__filter=o.cloneObject(this.__filter)},_buildFilterOptions:function(e){var r=this,t=o.mapValues(r.__filterOptionsMap[e]);t.sort((function(t,n){if("stops"===e){var i=t.code,o=n.code;return r.multiCity&&(i=i.substr(2),o=o.substr(2)),i-o}return t.name{e.exports={prepareTrip:function(e){e.fares=[];var r=e.legs;if(r&&0!==r.length){e.legIdMap={},r.forEach((function(r,t){e.legIdMap[t+r.id]=!0}));var t,n,i=r[0];!function(e,r){var t=0,n=function(e){return Math.min(e,2)};r.forEach((function(e){var r=e.stopoversCount;t=Math.max(t,r),e.stopCode=n(r)})),e.stopCode=n(t)}(e,r),e.airlineCodes=a(r.map((function(e){return e.airlineCodes}))),e.allianceCodes=a(r.map((function(e){return e.allianceCodes}))),e.departureAirportCode=i.departureAirportCode,e.arrivalAirportCode=i.arrivalAirportCode,e.stopoverAirportCodeMap=o(r.map((function(e){return e.stopoverAirportCodes}))),e.changeAirportAtStopover=function(e){for(var r=e.length;r--;)for(var t=e[r].segments,n=t.length-1;n>0;n--)if(t[n].departureAirportCode!==t[n-1].arrivalAirportCode)return!0;return!1}(r),e.stopoverDurationMinutes=(t=r.map((function(e){return e.stopoverDurationMinutes})),n=0,t.forEach((function(e){n=Math.max(n,e)})),n),e.durationMinutes=function(e){return e.reduce((function(e,r){return e+r.durationMinutes}),0)}(r),e.departureTimeMinutes=i.departureTimeMinutes,e.arrivalTimeMinutes=r[r.length-1].arrivalTimeMinutes,e.marketingAirline=function(e){for(var r=null,t=0;t1)for(var t=1;t1)for(var t=1;t{var n=t(853).cloneObject,i=t(853);function o(e,r){return!r||function(e,r){return-1!==r.indexOf("instant")&&e.provider.instant}(e,r)||function(e,r){return-1!==r.indexOf("instant")&&e.provider.wegoFare}(e,r)||function(e,r){return-1!==r.indexOf(e.provider.type)&&!e.provider.instant}(e,r)}function a(e,r){return!r||i.filterByKey(e.provider.code,r)}function s(e,r){if(!r)return!0;for(var t=r.length;t--;){if("NOT_OVERNIGHT"===r[t]&&e.overnight)return!1;if("SHORT_STOPOVER"===r[t]&&e.longStopover)return!1}return!0}function c(e,r,t){if(!r)return!0;for(var n=0;n=1}function l(e,r){if(r)for(var t=Object.keys(r),n=0;n=0;if(!i)return!1}return!0};if(!O(n,I.airlineCodes))return!1;if(!O(l,I.allianceCodes))return!1;if(!O(d,I.stopoverAirportCodes))return!1;if(!s(I,h&&Object.keys(h[A]||{})))return!1;if(!c(e,v,"stopoverDurationMinutes"))return!1}return(C||i.filterByKey(e.stopCode,t))&&c(e,r.departureTimeMinutesRanges,"departureTimeMinutes")&&c(e,r.arrivalTimeMinutesRanges,"arrivalTimeMinutes")&&(C||function(e,r){return!r||!!e.marketingAirline&&i.filterByKey(e.marketingAirline.code,r)}(e,n))&&(C||i.filterByAllKeys(e.allianceCodes,l))&&function(e,r){if(!r)return!0;for(var t=0;t1)return!1;return!0}(e,r.tripOptions)&&i.filterByAllKeys(e.originAirportCodes,p)&&i.filterByAllKeys(e.destinationAirportCodes,f)&&(C||i.filterBySomeKeys(e.stopoverAirportCodeMap,r.stopoverAirportCodes))&&function(e,r){if(!r||0===r.length)return!0;for(var t=0;t0,i=r.providerCodeMap,s=r.providerTypes;if(!i&&!s)return!0;var c=e.fares;if(c&&c.length>0)for(var u=0;u{function n(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!t){if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return i(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?i(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,c=!1;return{s:function(){t=t.call(e)},n:function(){var e=t.next();return s=e.done,e},e:function(e){c=!0,a=e},f:function(){try{s||null==t.return||t.return()}finally{if(c)throw a}}}}function i(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t2&&void 0!==arguments[2]?arguments[2]:{};if(!r)return e;var i=t.providerTypes,a=t.providerCodes,s=t.flexibilities;function c(e){return e.fares[0]?e.fares[0].price.amountUsd:null}function u(e){return e.durationMinutes}function l(e){return function(r){var t=r.legs[e];return t&&t.departureTimeMinutes}}function p(e){return function(r){var t=r.legs[e];return t&&t.arrivalTimeMinutes+24*t.durationDays*60}}function f(e){return e.score}for(var d={PRICE:c,DURATION:u,SCORE:f},h=0;h<6;h++)d["LEG"+(h+1)+"_DEPARTURE_TIME"]=l(h),d["LEG"+(h+1)+"_ARRIVAL_TIME"]=p(h);var v=d[r.by]||function(){},y=o.cloneArray(e),g=!!i&&i.length>0,m=!!a&&a.length>0,C=!!s&&s.length>0;return(g||m||C)&&y.forEach((function(e){var r,t=[],o=[],c=n(e.fares);try{for(c.s();!(r=c.n()).done;){var u=r.value,l=!0,p=!0,f=!0;if(g){var d=i.includes("instant"),h=i.includes("airline");d&&h?l=u.provider.wegoFare||u.provider.instant||"airline"===u.provider.type:d?l=u.provider.wegoFare||u.provider.instant:h&&(l="airline"===u.provider.type)}if(m){var v=u.providerCode||u.provider.code;p=a.includes(v)}C&&s.includes("refundable")&&(f=u.refundable),l&&p&&f?t.push(u):o.push(u)}}catch(e){c.e(e)}finally{c.f()}e.fares=t.concat(o)})),y.sort((function(e,t){var n=o.compare(e,t,v,r.order);return 0==n&&"PRICE"!=r.by?o.compare(e,t,c,"ASC"):n})),y},getCheapestTrip:function(e,r){var t=!!r&&!!r.flexibilities&&r.flexibilities.length>0;return this._getBestTripBy(e,(function(e,n){if(!t)return e.fares[0].price.amountUsdr.score}))},_getBestTripBy:function(e,r){for(var t=e[0],n=1;n{function n(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function i(e){for(var r=1;r{function n(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function i(e){for(var r=1;r{var n=t(853),i=t(67),o=function(e){e=e||{},this.currency=e.currency};o.prototype={reset:function(){this.__staticData=this._getEmptyStaticData(),this.__hotelMap={},this.__hotels=[],this.__filter=this._getEmptyFilter(),this.__filterOptionsMap=this._getEmptyFilterOptionsMap()},mergeResponse:function(e){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],t=this._getUpdatedHotelIds(e);this._mergeStaticData(e),this._mergeHotels(e.hotels),this._mergeFilter(Object.assign({},e.rentalFilter,e.filter),e.providers),this._mergeRates(e.rates,r),this._mergeSortedRatesByBasePrice(),this._mergeSortedRatesByTotalPrice(),this._mergeScores(e.scores),this._mergeRatesCounts(e.providerRatesCounts),this._cloneHotels(t)},getFilter:function(){return this.__filter},getProviders:function(){var e=this.__staticData.providers;return e?Object.keys(e).map((function(r){return e[r]})):[]},getHotels:function(){return this.__hotels},getStaticData:function(){return this.__staticData},updateCurrency:function(e){this.currency=e;var r=this.__hotelMap;for(var t in r)r[t].rates.forEach((function(r){r.price=i.convertPrice(r.price,e)}));this._cloneHotels(Object.keys(r));var o=this.__filter;o.minPrice=i.convertPrice(o.minPrice,e),o.maxPrice=i.convertPrice(o.maxPrice,e),this.__filter=n.cloneObject(this.__filter)},_mergeStaticData:function(e){var r=this.__staticData;this.__staticDataTypes.forEach((function(t){!function(e,r,t){if(r)if(Array.isArray(r))r.forEach((function(r){var n="providers"===t||"cities"===t?r.code:r.id;e[n]=r}));else for(var n in r)r.hasOwnProperty(n)&&(e[n]=r[n])}(r[t],e[t],t)}))},_mergeHotels:function(e){if(e){var r=this,t=this.__hotelMap;e.forEach((function(e){i.prepareHotel(e,r.__staticData),t[e.id]=t[e.id]||e}))}},_mergeRates:function(e,r){if(e){var t=this;e.forEach((function(e){i.prepareRate(e,t.currency,t.__staticData);var r=e.hotelId,n=t.__hotelMap[r];if(n){var o,a=n.rates;for(o=0;o{var n=t(853);e.exports={prepareResponseSearch:function(e,r){var t=e&&e.region;if(t){var n=[],i=r.cities;t.cityCodes.forEach((function(e){n.push(i[e])})),t.cities=n}},prepareHotel:function(e,r){e.district=r.districts[e.districtId],e.city=r.cities[e.cityCode],e.reviewMap=function(e,r){if(!e)return{};var t={};return e.forEach((function(e){var r;t[(r=e,r.reviewerGroup)]=e})),t}(e.reviews),e.ratesCounts={total:0};var t={};if((e.amenityIds||[]).forEach((function(e){t[e]=!0})),e.amenityIdMap=t,e.rates=[],e.images=e.images||[],e.propertyType=r.propertyTypes[e.propertyTypeId],e.provider=r.propertyTypes[e.provider],e.badges&&39===e.propertyTypeId){var n=r.roomTypeCategories[e.roomTypeCategoryId];n&&e.badges.push({text:n.name})}},prepareRate:function(e,r,t){e.provider=t.providers[e.providerCode],e.price=this.convertPrice(e.price,r)},convertPrice:function(e,r){if(!r)return e;if(!e)return null;var t=e.amount,i=e.totalAmount,o=e.taxAmount,a=e.totalTaxAmount;if(e.currencyCode!=r.code){var s=r.rate;i=(t=Math.round(e.amountUsd*s))*Math.round(e.totalAmountUsd/e.amountUsd),a=(o=Math.round(e.taxAmountUsd*s))*Math.round(e.totalTaxAmountUsd/e.taxAmountUsd)}var c=n.cloneObject(e);return c.currency=r,c.amount=t,c.totalAmount=i,c.taxAmount=o,c.totalTaxAmount=a,c},prepareFilterOption:function(e,r,t){var n=(t[this.__filterOptionTypeToStaticDataType[r]]||{})[e.code]||{};e.name=n.name},trimArray:function(e){if(e)return Array.isArray(e)&&(e=e.filter((function(e){return!!e&&""!=e.trim()}))),e},isBetterRate:function(e,r){function t(e){var r=Math.round(e.price.amount);return r>99999&&(r=r/100*100),r}function n(e){return e.price.taxAmountUsd<0?-1:1}var i=n(e),o=n(r);if(i!=o)return i>o;var a=t(e),s=t(r);return a!=s?ar.price.ecpc)},__filterOptionTypeToStaticDataType:{stars:"stars",brands:"brands",propertyTypes:"propertyTypes",districts:"districts",cities:"cities",amenities:"amenities",rateAmenities:"rateAmenities",chains:"chains",providers:"providers",reviewerGroups:"reviewerGroups",roomTypeCategories:"roomTypeCategories"}}},464:(e,r,t)=>{var n=t(853);e.exports={filterHotels:function(e,r){if(!r)return e;var t=n.arrayToMap(r.stars),i=n.arrayToMap(r.districtIds),o=n.arrayToMap(r.cityCodes),a=n.arrayToMap(r.propertyTypeIds),s=n.arrayToMap(r.airbnbTypes),c=n.arrayToMap(r.brandIds),u=n.arrayToMap(r.chainIds);return e.filter((function(e){var l=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=r.providers,i=void 0===t?[]:t,o=r.providerCodes,a=void 0===o?[]:o,s=r.priceRange;if(!s)return!0;var c=e.rates||[];return i.length>0&&(c=c.filter((function(e){var r=-1!==i.indexOf("wego")&&e.provider.directBooking,t=-1!==i.indexOf("hotels")&&e.provider.isHotelWebsite,n=-1!==i.indexOf("ota")&&"OTA"===e.provider.type;return r||t||n}))),a.length>0&&(c=c.filter((function(e){return a.includes(e.providerCode)}))),c.length>0&&n.filterByRange(c[0].price.amountUsd,s)}(e,r)&&n.filterByKey(e.star,t)&&n.filterByContainAllKeys(e.amenityIdMap,r.amenityIds)&&n.filterByKey(e.districtId,i)&&n.filterByKey(e.cityCode,o)&&n.filterByKey(e.propertyTypeId,a)&&n.filterByKey(e.brandId,c)&&function(e,r){if(!r)return!0;if(n.filterByTextMatching(e.name,r))return!0;if(!e.nameI18n)return!1;for(var t in e.nameI18n)if(n.filterByTextMatching(e.nameI18n[t],r))return!0;return!1}(e,r.name)&&n.filterByKey(e.chainId,u)&&function(e,r){if(!r||0===r.length)return!0;for(var t=0;t=80&&n.count>=100)return!0}return!1}(e,r.reviewerGroups)&&function(e,r){if(!r||0===r.length)return!0;var t=e.rates;if(!t)return!1;for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:[];return 0===r.length||(e.rates||[]).some((function(e){return r.includes(e.providerCode)}))}(e,r.providerCodes)&&function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return 0===r.length||(e.rates||[]).some((function(e){var t=-1!==r.indexOf("wego")&&e.provider.directBooking,n=-1!==r.indexOf("hotels")&&e.provider.isHotelWebsite,i=-1!==r.indexOf("ota")&&"OTA"===e.provider.type;return t||n||i}))}(e,r.providers)&&function(e,r){if(!r||0===r.length)return!0;var t=e.rates;if(!t)return!1;for(var n=0;n0)return!0}return!1}(e,r.deals)&&function(e,r){if(!r)return!0;var t=e.reviewMap.ALL||{};return n.filterByRange(t.score,r)}(e,r.reviewScoreRange);return 39===e.propertyTypeId?l&&function(e,r){return!(r>0)||e.bedroomsCount>=r}(e,r.airbnbBedroomCount?r.airbnbBedroomCount:0)&&n.filterByKey(e.roomTypeCategoryId,s):l}))}}},369:(e,r,t)=>{function n(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!t){if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return i(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?i(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,c=!1;return{s:function(){t=t.call(e)},n:function(){var e=t.next();return s=e.done,e},e:function(e){c=!0,a=e},f:function(){try{s||null==t.return||t.return()}finally{if(c)throw a}}}}function i(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t2&&void 0!==arguments[2]?arguments[2]:{};if(!r)return e;var i=t.providers,a=void 0===i?[]:i,s=t.providerCodes,c=void 0===s?[]:s;function u(e){return e.rates&&e.rates.length>0?e.rates[0].price.amountUsd:null}function l(e){return f(e)&&d(e.rates[0].usualPrice)?Math.round(100*e.rates[0].usualPrice.discountToUsualAmount):null}function p(e){var r;return f(e)&&d(e.rates[0].usualPrice)?(r=e.rates[0].usualPrice,Math.round(r.usualAmountUsd*r.discountToUsualAmount)):null}function f(e){return e.rates&&e.rates.length>0}function d(e){return void 0!==e}function h(e){return function(r){var t=r.reviewMap[e];return t?t.score:null}}function v(e){return 0===e.star?void 0:e.star}function y(e){return e.score}function g(e){return e.distanceToCityCentre}function m(e){return e.distanceToNearestAirport}var C={PRICE:u,DISCOUNT:l,SAVINGS:p,ALL_REVIEW_SCORE:h("ALL"),FAMILY_REVIEW_SCORE:h("FAMILY"),BUSINESS_REVIEW_SCORE:h("BUSINESS"),COUPLE_REVIEW_SCORE:h("COUPLE"),SOLO_REVIEW_SCORE:h("SOLO"),STAR:v,SCORE:y,DISTANCE_TO_CITY_CENTER:g,DISTANCE_TO_NEAREST_AIRPORT:m},_=C[r.by]||function(){},T=o.cloneArray(e);if(a.length>0||c.length>0){var A,I=n(T);try{for(I.s();!(A=I.n()).done;){var O,b=A.value,S=function(e){var r=-1!==a.indexOf("wego")&&e.provider.directBooking,t=-1!==a.indexOf("hotels")&&e.provider.isHotelWebsite,n=-1!==a.indexOf("ota")&&"OTA"===e.provider.type;return r||t||n},M=function(e){return!!e.providerCode&&-1!==c.indexOf(e.providerCode)},P=[],E=[],R=n(b.rates);try{for(R.s();!(O=R.n()).done;){var w=O.value;S(w)||M(w)?P.push(w):E.push(w)}}catch(e){R.e(e)}finally{R.f()}b.rates=P.concat(E)}}catch(e){I.e(e)}finally{I.f()}}return T.sort((function(e,t){var n=o.compare(e,t,_,r.order);return 0==n&&"PRICE"!=r.by?o.compare(e,t,u,"ASC"):n})),T}}},579:(e,r,t)=>{var n=t(22),i=t(469),o=t(376),a=t(55);e.exports={Api:n,FlightSearchClient:i,HotelSearchClient:o,HotelDetailsClient:a}},853:e=>{var r={cloneObject:function(e){var r={};for(var t in e)r[t]=e[t];return r},cloneArray:function(e){var r=[];return e.forEach((function(e){r.push(e)})),r},mapValues:function(e){return Object.keys(e).map((function(r){return e[r]}))},compare:function(e,r,t,n){var i=t(e),o=t(r);return i===o?0:null==i?1:null==o?-1:i>o==("ASC"===n)?1:-1},filterByKey:function(e,r){return!r||r[e]},filterByAllKeys:function(e,r){if(!r)return!0;if(0===e.length)return!1;for(var t=0;t-1},filterByRange:function(e,r){if(!r)return!0;var t,n=r.min===t?0:r.min,i=r.max===t?1<<30:r.max;return n<=e&&e<=i},arrayToMap:function(e){if(!e||0===e.length)return null;var r={};return e.forEach((function(e){r[e]=!0})),r},arrayToMaps:function(e,r){if(!r)return this.arrayToMap(e);if(!e||0===e.length)return null;var t={};return e.forEach((function(e){var r=e[0]-1,n=e.substr(2);t[r]=t[r]||{},t[r][n]=!0})),t},stripAccents:function(){var e="àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ",r=new RegExp("["+e+"]","g"),t={};function n(e){return t[e]||e}for(var i=0;i{var r={__host:{staging:{v3:"https://srv.wegostaging.com/v3",v2:"https://srv.wegostaging.com/v2",v1:"https://srv.wegostaging.com"},production:{v3:"https://srv.wego.com/v3",v2:"https://srv.wego.com/v2",v1:"https://srv.wego.com"}},_hotelEndpoints:{hotelDetailsUrl:function(e){return r.getHost("v1")+"/hotels/hotels/"+e}},getHost:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"v2";return this.__host[this.getEnvironment()][e]},setEnvironment:function(e){this.env=e},getEnvironment:function(){return this.env||Wego.ENV||"staging"},searchTrips:function(e,r,t,n){return this.post(r,e,t,n)},fetchTrips:function(e,r,t,n){var o="".concat(e,"/").concat(r,"/results");return this.get(o,t||{},n)},searchHotels:function(e,r,t,n){return this.post(r,e,t,n)},fetchHotels:function(e,r,t,n){var o="".concat(e,"/").concat(r,"/results");return this.get(o,t||{},n)},searchHotel:function(e,r,t,n){var o="".concat(e,"/").concat(r.search.hotelId,"/searches");return this.post(r,o,t,n)},fetchHotelRates:function(e,r){var t=this.__host[this.getEnvironment()].v3+"/metasearch/hotels/"+e+"/rates";return this.get(t,r)},fetchHotelDetails:function(e,r){var t=this._hotelEndpoints.hotelDetailsUrl(e);return this.get(t,r)},fetchCities:function(e){var r=this.__host[this.getEnvironment()].v1+"/places/cities";return this.get(r,e)},fetchAirports:function(e){var r=this.__host[this.getEnvironment()].v1+"/places/airports";return this.get(r,e)},post:function(e,r,t,n){return fetch(this.buildUrl(r,t),{method:"POST",credentials:"include",mode:"cors",headers:Object.assign({},n,{"Content-Type":"application/json"}),body:JSON.stringify(e)}).then((function(e){return e.ok?e.json():Promise.reject()})).catch((function(e){return Promise.reject(e)}))},get:function(e,r,t){return fetch(this.buildUrl(e,r),{method:"GET",credentials:"include",mode:"cors",headers:Object.assign({},t,{"Content-Type":"application/json"})}).then((function(e){return e.ok?e.json():Promise.reject()})).catch((function(e){return Promise.reject(e)}))},buildUrl:function(e,r){if(r){var t=[];for(var n in r){var o=r[n];o instanceof Array?o.forEach((function(e){t.push(n+"[]="+e)})):t.push(n+"="+r[n])}e+="?"+t.join("&")}return e}};e.exports=r},15:e=>{var r=function(e){e=e||{},this.initCallApi=e.initCallApi,this.callApi=e.callApi,this.delays=e.delays,this.onSuccessResponse=e.onSuccessResponse,this.pollLimit=e.pollLimit};r.prototype={start:function(){var e=this;this.timer=setTimeout((function(){e.pollCount++,e.retryCount=0,e.fetch(e.initCallApi||e.callApi)}),0)},reset:function(){clearTimeout(this.timer),this.abortLastFetch&&this.abortLastFetch(),this.pollCount=0,this.forceStop=!1},stop:function(){this.forceStop=!0},isStopping:function(){return this.forceStop},isLastPolling:function(){return this.pollCount===this.pollLimit},getProgress:function(){return this.pollCount===this.pollLimit?100:this.pollCount/this.pollLimit*100},handleSuccessResponse:function(e){this.onSuccessResponse(e),this.preparePoll()},preparePoll:function(){var e=this;e.pollCount{function n(e,r){for(var t=0;t2;if(2===o.length){var a=["departureCityCode","departureAirportCode","arrivalCityCode","arrivalAirportCode"];(t=o[0])===(n=o[1])||t[a[0]]===n[a[2]]&&t[a[1]]===n[a[3]]&&t[a[2]]===n[a[0]]&&t[a[3]]===n[a[1]]||(i=!0)}r.multiCity=i,r.merger.multiCity=i;var s=r.poller;s.delays=(i?[0,3,3,3,4,4,4,4,5,5,5,5,5,6]:[0,1,3,4,5,6,6,6]).map((function(e){return 1e3*e})),s.pollLimit=s.delays.length-1,r.updateResult(),s.start()}},{key:"handleSearchResponse",value:function(e){var r=this;r.mergeResponse(e),r.updateResult(),1===r.poller.pollCount&&r.onSearchCreated(e.search)}},{key:"mergeResponse",value:function(e){var r=this;r.merger.mergeResponse(e),r.processedFaresCount=e.count,r.responseSearch=e.search}},{key:"reset",value:function(){var e=this;e.poller.reset(),e.merger.reset(),e.responseSearch={},e.processedFaresCount=0}},{key:"updatePaymentMethodIds",value:function(e){var r=this;r.paymentMethodIds=e,r.reset(),r.updateResult(),r.poller.start()}},{key:"updateProviderTypes",value:function(e){var r=this;r.providerTypes=e,r.reset(),r.updateResult(),r.poller.start()}},{key:"updateSort",value:function(e){this.sort=e,this.updateResult()}},{key:"updateFilter",value:function(e){this.filter=e,this.updateResult()}},{key:"updateCurrency",value:function(e){var r=this;r.currency=e,r.merger.updateCurrency(e),r.updateResult()}},{key:"updateResult",value:function(){var e=this,r=e.merger.getTrips();0!==Object.keys(e.merger.getLegConditions()).length&&a.passLegConditions(e.merger.getLegConditions()),0!==Object.keys(e.merger.getFareConditions()).length&&a.passFareConditions(e.merger.getFareConditions());var t=a.filterTrips(r,e.filter,e.multiCity),n=i.sortTrips(t,e.sort,e.filter);e.onTripsChanged(n),e.onCheapestTripChanged(i.getCheapestTrip(t,e.filter)),e.onFastestTripChanged(i.getFastestTrip(t)),e.onBestExperienceTripChanged(i.getBestExperienceTrip(t)),e.onTotalTripsChanged(r),e.onDisplayedFilterChanged(e.merger.getFilter()),e.onProgressChanged(e.poller.getProgress()),e.onProvidersChanged(e.merger.getProviders());var o=e.merger.getSponsors(),s=a.filterSponsors(o,r,e.filter,e.multiCity);e.onSponsorsChanged(s)}},{key:"getSearchRequestBody",value:function(){var e=this,r=e.search||{},t=r.legs||[];return{search:{id:e.responseSearch.id,cabin:r.cabin,deviceType:e.deviceType,appType:e.appType,userLoggedIn:e.userLoggedIn,adultsCount:r.adultsCount,childrenCount:r.childrenCount,infantsCount:r.infantsCount,siteCode:e.siteCode,currencyCode:e.currency.code,locale:e.locale,showWegoFares:e.showWegoFares,legs:t.map((function(e){return{departureCityCode:e.departureCityCode,departureAirportCode:e.departureAirportCode,arrivalCityCode:e.arrivalCityCode,arrivalAirportCode:e.arrivalAirportCode,outboundDate:e.outboundDate}}))},offset:e.processedFaresCount,paymentMethodIds:e.paymentMethodIds,providerTypes:e.providerTypes}}},{key:"fetchTripsParams",value:function(){var e=this;return{currencyCode:e.currency.code,locale:e.locale,paymentMethodIds:e.paymentMethodIds||[],offset:e.processedFaresCount}}}])&&n(r.prototype,t),e}();e.exports=u},854:(e,r,t)=>{function n(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t=0;"stops"===t&&(e.code=a[e.code]);var s=(i?n+1+"_":"")+e.code;o.prepareFilterOption(e,t,r.currency,r.__staticData),r.__filterOptionsMap[t][s]=e,e.code=s,i&&(e.legIndex=n)}))};if(n&&i)for(var c=i.length;c--;)s(i[c][t],c);else s(e[t]);r._buildFilterOptions(t)})),r._cloneFilter()}},_getUpdatedTripIds:function(e){var r={},t=this;if(e.scores)for(var n in e.scores)r[n]=!0;return e.fares&&e.fares.forEach((function(e){r[e.tripId]=!0})),Object.keys(r).filter((function(e){return t.__tripMap[e]}))},_cloneTrips:function(e){var r=this.__tripMap;e.forEach((function(e){var t=r[e];t?(t.fares=i.cloneArray(t.fares),r[e]=i.cloneObject(t)):console.error("Trip with "+e+" is missing")})),this.__trips=i.mapValues(r)},_cloneFilter:function(){this.__filter=i.cloneObject(this.__filter)},_buildFilterOptions:function(e){var r=this,t=i.mapValues(r.__filterOptionsMap[e]);t.sort((function(t,n){if("stops"===e){var o=t.code,i=n.code;return r.multiCity&&(o=o.substr(2),i=i.substr(2)),o-i}return t.name{e.exports={prepareTrip:function(e){e.fares=[];var r=e.legs;if(r&&0!==r.length){e.legIdMap={},r.forEach((function(r,t){e.legIdMap[t+r.id]=!0}));var t,n,o=r[0];!function(e,r){var t=0,n=function(e){return Math.min(e,2)};r.forEach((function(e){var r=e.stopoversCount;t=Math.max(t,r),e.stopCode=n(r)})),e.stopCode=n(t)}(e,r),e.airlineCodes=a(r.map((function(e){return e.airlineCodes}))),e.allianceCodes=a(r.map((function(e){return e.allianceCodes}))),e.departureAirportCode=o.departureAirportCode,e.arrivalAirportCode=o.arrivalAirportCode,e.stopoverAirportCodeMap=i(r.map((function(e){return e.stopoverAirportCodes}))),e.changeAirportAtStopover=function(e){for(var r=e.length;r--;)for(var t=e[r].segments,n=t.length-1;n>0;n--)if(t[n].departureAirportCode!==t[n-1].arrivalAirportCode)return!0;return!1}(r),e.stopoverDurationMinutes=(t=r.map((function(e){return e.stopoverDurationMinutes})),n=0,t.forEach((function(e){n=Math.max(n,e)})),n),e.durationMinutes=function(e){return e.reduce((function(e,r){return e+r.durationMinutes}),0)}(r),e.departureTimeMinutes=o.departureTimeMinutes,e.arrivalTimeMinutes=r[r.length-1].arrivalTimeMinutes,e.marketingAirline=function(e){for(var r=null,t=0;t1)for(var t=1;t1)for(var t=1;t{var n=t(853).cloneObject,o=t(853);function i(e,r){return!r||function(e,r){return-1!==r.indexOf("instant")&&e.provider.instant}(e,r)||function(e,r){return-1!==r.indexOf("instant")&&e.provider.wegoFare}(e,r)||function(e,r){return-1!==r.indexOf(e.provider.type)&&!e.provider.instant}(e,r)}function a(e,r){return!r||o.filterByKey(e.provider.code,r)}function s(e,r){if(!r)return!0;for(var t=r.length;t--;){if("NOT_OVERNIGHT"===r[t]&&e.overnight)return!1;if("SHORT_STOPOVER"===r[t]&&e.longStopover)return!1}return!0}function c(e,r,t){if(!r)return!0;for(var n=0;n=1}function l(e,r){if(r)for(var t=Object.keys(r),n=0;n=0;if(!o)return!1}return!0};if(!O(n,b.airlineCodes))return!1;if(!O(l,b.allianceCodes))return!1;if(!O(d,b.stopoverAirportCodes))return!1;if(!s(b,h&&Object.keys(h[A]||{})))return!1;if(!c(e,v,"stopoverDurationMinutes"))return!1}return(C||o.filterByKey(e.stopCode,t))&&c(e,r.departureTimeMinutesRanges,"departureTimeMinutes")&&c(e,r.arrivalTimeMinutesRanges,"arrivalTimeMinutes")&&(C||function(e,r){return!r||!!e.marketingAirline&&o.filterByKey(e.marketingAirline.code,r)}(e,n))&&(C||o.filterByAllKeys(e.allianceCodes,l))&&function(e,r){if(!r)return!0;for(var t=0;t1)return!1;return!0}(e,r.tripOptions)&&o.filterByAllKeys(e.originAirportCodes,p)&&o.filterByAllKeys(e.destinationAirportCodes,f)&&(C||o.filterBySomeKeys(e.stopoverAirportCodeMap,r.stopoverAirportCodes))&&function(e,r){if(!r||0===r.length)return!0;for(var t=0;t0,o=r.providerCodeMap,s=r.providerTypes;if(!o&&!s)return!0;var c=e.fares;if(c&&c.length>0)for(var u=0;u{function n(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!t){if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return o(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?o(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,c=!1;return{s:function(){t=t.call(e)},n:function(){var e=t.next();return s=e.done,e},e:function(e){c=!0,a=e},f:function(){try{s||null==t.return||t.return()}finally{if(c)throw a}}}}function o(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t2&&void 0!==arguments[2]?arguments[2]:{};if(!r)return e;var o=t.providerTypes,a=t.providerCodes,s=t.flexibilities;function c(e){return e.fares[0]?e.fares[0].price.amountUsd:null}function u(e){return e.durationMinutes}function l(e){return function(r){var t=r.legs[e];return t&&t.departureTimeMinutes}}function p(e){return function(r){var t=r.legs[e];return t&&t.arrivalTimeMinutes+24*t.durationDays*60}}function f(e){return e.score}for(var d={PRICE:c,DURATION:u,SCORE:f},h=0;h<6;h++)d["LEG"+(h+1)+"_DEPARTURE_TIME"]=l(h),d["LEG"+(h+1)+"_ARRIVAL_TIME"]=p(h);var v=d[r.by]||function(){},y=i.cloneArray(e),g=!!o&&o.length>0,m=!!a&&a.length>0,C=!!s&&s.length>0;return(g||m||C)&&y.forEach((function(e){var r,t=[],i=[],c=n(e.fares);try{for(c.s();!(r=c.n()).done;){var u=r.value,l=!0,p=!0,f=!0;if(g){var d=o.includes("instant"),h=o.includes("airline");d&&h?l=u.provider.wegoFare||u.provider.instant||"airline"===u.provider.type:d?l=u.provider.wegoFare||u.provider.instant:h&&(l="airline"===u.provider.type)}if(m){var v=u.providerCode||u.provider.code;p=a.includes(v)}C&&s.includes("refundable")&&(f=u.refundable),l&&p&&f?t.push(u):i.push(u)}}catch(e){c.e(e)}finally{c.f()}e.fares=t.concat(i)})),y.sort((function(e,t){var n=i.compare(e,t,v,r.order);return 0==n&&"PRICE"!=r.by?i.compare(e,t,c,"ASC"):n})),y},getCheapestTrip:function(e,r){var t=!!r&&!!r.flexibilities&&r.flexibilities.length>0;return this._getBestTripBy(e,(function(e,n){if(!t)return e.fares[0].price.amountUsdr.score}))},_getBestTripBy:function(e,r){for(var t=e[0],n=1;n{function n(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function o(e){for(var r=1;r{function n(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function o(e){for(var r=1;r{function n(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t{var n=t(853);e.exports={prepareResponseSearch:function(e,r){var t=e&&e.region;if(t){var n=[],o=r.cities;t.cityCodes.forEach((function(e){n.push(o[e])})),t.cities=n}},prepareHotel:function(e,r){e.district=r.districts[e.districtId],e.city=r.cities[e.cityCode],e.reviewMap=function(e,r){if(!e)return{};var t={};return e.forEach((function(e){var r;t[(r=e,r.reviewerGroup)]=e})),t}(e.reviews),e.ratesCounts={total:0};var t={};if((e.amenityIds||[]).forEach((function(e){t[e]=!0})),e.amenityIdMap=t,e.rates=[],e.images=e.images||[],e.propertyType=r.propertyTypes[e.propertyTypeId],e.provider=r.propertyTypes[e.provider],e.badges&&39===e.propertyTypeId){var n=r.roomTypeCategories[e.roomTypeCategoryId];n&&e.badges.push({text:n.name})}},prepareRate:function(e,r,t){e.provider=t.providers[e.providerCode],e.price=this.convertPrice(e.price,r)},convertPrice:function(e,r){if(!r)return e;if(!e)return null;var t=e.amount,o=e.totalAmount,i=e.taxAmount,a=e.totalTaxAmount;if(e.currencyCode!=r.code){var s=r.rate;o=(t=Math.round(e.amountUsd*s))*Math.round(e.totalAmountUsd/e.amountUsd),a=(i=Math.round(e.taxAmountUsd*s))*Math.round(e.totalTaxAmountUsd/e.taxAmountUsd)}var c=n.cloneObject(e);return c.currency=r,c.amount=t,c.totalAmount=o,c.taxAmount=i,c.totalTaxAmount=a,c},prepareFilterOption:function(e,r,t){var n=(t[this.__filterOptionTypeToStaticDataType[r]]||{})[e.code]||{};e.name=n.name},trimArray:function(e){if(e)return Array.isArray(e)&&(e=e.filter((function(e){return!!e&&""!=e.trim()}))),e},__filterOptionTypeToStaticDataType:{stars:"stars",brands:"brands",propertyTypes:"propertyTypes",districts:"districts",cities:"cities",amenities:"amenities",rateAmenities:"rateAmenities",chains:"chains",providers:"providers",reviewerGroups:"reviewerGroups",roomTypeCategories:"roomTypeCategories"}}},464:(e,r,t)=>{var n=t(853);e.exports={filterHotels:function(e,r){if(!r)return e;var t=n.arrayToMap(r.stars),o=n.arrayToMap(r.districtIds),i=n.arrayToMap(r.cityCodes),a=n.arrayToMap(r.propertyTypeIds),s=n.arrayToMap(r.airbnbTypes),c=n.arrayToMap(r.brandIds),u=n.arrayToMap(r.chainIds);return e.filter((function(e){var l=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=r.providers,o=void 0===t?[]:t,i=r.providerCodes,a=void 0===i?[]:i,s=r.priceRange;if(!s)return!0;var c=e.rates||[];return o.length>0&&(c=c.filter((function(e){var r=-1!==o.indexOf("wego")&&e.provider.directBooking,t=-1!==o.indexOf("hotels")&&e.provider.isHotelWebsite,n=-1!==o.indexOf("ota")&&"OTA"===e.provider.type;return r||t||n}))),a.length>0&&(c=c.filter((function(e){return a.includes(e.providerCode)}))),c.length>0&&n.filterByRange(c[0].price.amountUsd,s)}(e,r)&&n.filterByKey(e.star,t)&&n.filterByContainAllKeys(e.amenityIdMap,r.amenityIds)&&n.filterByKey(e.districtId,o)&&n.filterByKey(e.cityCode,i)&&n.filterByKey(e.propertyTypeId,a)&&n.filterByKey(e.brandId,c)&&function(e,r){if(!r)return!0;if(n.filterByTextMatching(e.name,r))return!0;if(!e.nameI18n)return!1;for(var t in e.nameI18n)if(n.filterByTextMatching(e.nameI18n[t],r))return!0;return!1}(e,r.name)&&n.filterByKey(e.chainId,u)&&function(e,r){if(!r||0===r.length)return!0;for(var t=0;t=80&&n.count>=100)return!0}return!1}(e,r.reviewerGroups)&&function(e,r){if(!r||0===r.length)return!0;var t=e.rates;if(!t)return!1;for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:[];return 0===r.length||(e.rates||[]).some((function(e){return r.includes(e.providerCode)}))}(e,r.providerCodes)&&function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return 0===r.length||(e.rates||[]).some((function(e){var t=-1!==r.indexOf("wego")&&e.provider.directBooking,n=-1!==r.indexOf("hotels")&&e.provider.isHotelWebsite,o=-1!==r.indexOf("ota")&&"OTA"===e.provider.type;return t||n||o}))}(e,r.providers)&&function(e,r){if(!r||0===r.length)return!0;var t=e.rates;if(!t)return!1;for(var n=0;n0)return!0}return!1}(e,r.deals)&&function(e,r){if(!r)return!0;var t=e.reviewMap.ALL||{};return n.filterByRange(t.score,r)}(e,r.reviewScoreRange);return 39===e.propertyTypeId?l&&function(e,r){return!(r>0)||e.bedroomsCount>=r}(e,r.airbnbBedroomCount?r.airbnbBedroomCount:0)&&n.filterByKey(e.roomTypeCategoryId,s):l}))}}},369:(e,r,t)=>{function n(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!t){if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return o(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?o(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,c=!1;return{s:function(){t=t.call(e)},n:function(){var e=t.next();return s=e.done,e},e:function(e){c=!0,a=e},f:function(){try{s||null==t.return||t.return()}finally{if(c)throw a}}}}function o(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t2&&void 0!==arguments[2]?arguments[2]:{};if(!r)return e;var o=t.providers,a=void 0===o?[]:o,s=t.providerCodes,c=void 0===s?[]:s;function u(e){return e.rates&&e.rates.length>0?e.rates[0].price.amountUsd:null}function l(e){return f(e)&&d(e.rates[0].usualPrice)?Math.round(100*e.rates[0].usualPrice.discountToUsualAmount):null}function p(e){var r;return f(e)&&d(e.rates[0].usualPrice)?(r=e.rates[0].usualPrice,Math.round(r.usualAmountUsd*r.discountToUsualAmount)):null}function f(e){return e.rates&&e.rates.length>0}function d(e){return void 0!==e}function h(e){return function(r){var t=r.reviewMap[e];return t?t.score:null}}function v(e){return 0===e.star?void 0:e.star}function y(e){return e.score}function g(e){return e.distanceToCityCentre}function m(e){return e.distanceToNearestAirport}var C={PRICE:u,DISCOUNT:l,SAVINGS:p,ALL_REVIEW_SCORE:h("ALL"),FAMILY_REVIEW_SCORE:h("FAMILY"),BUSINESS_REVIEW_SCORE:h("BUSINESS"),COUPLE_REVIEW_SCORE:h("COUPLE"),SOLO_REVIEW_SCORE:h("SOLO"),STAR:v,SCORE:y,DISTANCE_TO_CITY_CENTER:g,DISTANCE_TO_NEAREST_AIRPORT:m},_=C[r.by]||function(){},T=i.cloneArray(e);if(a.length>0||c.length>0){var A,b=n(T);try{for(b.s();!(A=b.n()).done;){var O,I=A.value,S=function(e){var r=-1!==a.indexOf("wego")&&e.provider.directBooking,t=-1!==a.indexOf("hotels")&&e.provider.isHotelWebsite,n=-1!==a.indexOf("ota")&&"OTA"===e.provider.type;return r||t||n},P=function(e){return!!e.providerCode&&-1!==c.indexOf(e.providerCode)},M=[],E=[],R=n(I.rates);try{for(R.s();!(O=R.n()).done;){var x=O.value;S(x)||P(x)?M.push(x):E.push(x)}}catch(e){R.e(e)}finally{R.f()}I.rates=M.concat(E)}}catch(e){b.e(e)}finally{b.f()}}return T.sort((function(e,t){var n=i.compare(e,t,_,r.order);return 0==n&&"PRICE"!=r.by?i.compare(e,t,u,"ASC"):n})),T}}},579:(e,r,t)=>{var n=t(22),o=t(469),i=t(376),a=t(55);e.exports={Api:n,FlightSearchClient:o,HotelSearchClient:i,HotelDetailsClient:a}},853:e=>{var r={cloneObject:function(e){var r={};for(var t in e)r[t]=e[t];return r},cloneArray:function(e){var r=[];return e.forEach((function(e){r.push(e)})),r},mapValues:function(e){return Object.keys(e).map((function(r){return e[r]}))},compare:function(e,r,t,n){var o=t(e),i=t(r);return o===i?0:null==o?1:null==i?-1:o>i==("ASC"===n)?1:-1},filterByKey:function(e,r){return!r||r[e]},filterByAllKeys:function(e,r){if(!r)return!0;if(0===e.length)return!1;for(var t=0;t-1},filterByRange:function(e,r){if(!r)return!0;var t,n=r.min===t?0:r.min,o=r.max===t?1<<30:r.max;return n<=e&&e<=o},arrayToMap:function(e){if(!e||0===e.length)return null;var r={};return e.forEach((function(e){r[e]=!0})),r},arrayToMaps:function(e,r){if(!r)return this.arrayToMap(e);if(!e||0===e.length)return null;var t={};return e.forEach((function(e){var r=e[0]-1,n=e.substr(2);t[r]=t[r]||{},t[r][n]=!0})),t},stripAccents:function(){var e="àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ",r=new RegExp("["+e+"]","g"),t={};function n(e){return t[e]||e}for(var o=0;o 99999) { - amount = (amount / 100) * 100; - } - return amount; - } - - function getPriceTaxAmountInclusive(rate) { - return rate.price.taxAmountUsd < 0 ? -1 : 1; - } - - var firstTax = getPriceTaxAmountInclusive(firstRate); - var secondTax = getPriceTaxAmountInclusive(secondRate); - - if (firstTax != secondTax) return firstTax > secondTax; - - var firstRateAmount = processRateAmount(firstRate); - var secondRateAmount = processRateAmount(secondRate); - if (firstRateAmount != secondRateAmount) return firstRateAmount < secondRateAmount; - - if (firstRate.provider.directBooking && !secondRate.provider.directBooking) { - return true; - } else if (secondRate.provider.directBooking && !firstRate.provider.directBooking) { - return false; - } - - if (firstRate.provider.type == 'DIRECT_PRIORITY' && secondRate.provider.type != 'DIRECT_PRIORITY') { - return true; - } else if (secondRate.provider.type == 'DIRECT_PRIORITY' && firstRate.provider.type != 'DIRECT_PRIORITY') { - return false; - } - - return firstRate.price.ecpc > secondRate.price.ecpc; - }, - __filterOptionTypeToStaticDataType: { stars: 'stars', brands: 'brands', diff --git a/test/hotel-search/HotelSearchClient.spec.js b/test/hotel-search/HotelSearchClient.spec.js index 58d95f4..273842e 100644 --- a/test/hotel-search/HotelSearchClient.spec.js +++ b/test/hotel-search/HotelSearchClient.spec.js @@ -384,7 +384,7 @@ describe("HotelSearchClient", function () { expect(client.merger.__staticData.brands[1]).to.equal(brand); }); - it("no hotel can have more than 1 rate from a provider when search's status is not'done'", () => { + it("rates should be assigned to respective hotel based on hotelId", () => { var response = { done: false, hotels: [{ id: 1 }, { id: 2 }], @@ -399,11 +399,10 @@ describe("HotelSearchClient", function () { client.poller.pollCount = 1; client.poller.pollLimit = 3; client.handleSearchResponse(response); - expect(client.merger.__hotelMap[1].rates.length).to.equal(1); + expect(client.merger.__hotelMap[1].rates.length).to.equal(3); expect(client.merger.__hotelMap[2].rates.length).to.equal(2); - expect(client.merger.__hotelMap[2].rates[0].providerCode).to.not.equal( - client.merger.__hotelMap[2].rates[1].providerCode); }); + it("some hotels may have more than 1 from a provider rate when search's status is not 'done' but reaching limit polling time", () => { var response = { done: true, @@ -577,7 +576,7 @@ describe("HotelSearchClient", function () { var params = client.fetchHotelsParams(); expect(params.currencyCode).to.equal(currencyCode); }); - it("returns moreRates", function() { + it("returns moreRates", function () { var params = client.fetchHotelsParams(); expect(params.moreRates).to.equal(true); }); diff --git a/test/hotel-search/Merger.spec.js b/test/hotel-search/Merger.spec.js index da65509..8a83442 100644 --- a/test/hotel-search/Merger.spec.js +++ b/test/hotel-search/Merger.spec.js @@ -301,9 +301,6 @@ describe('Merger', function() { hotels: [hotel], }); - var oldHotels = merger.getHotels(); - var oldHotel = oldHotels[0]; - merger.mergeResponse({ rates: [rate3] }); @@ -311,97 +308,7 @@ describe('Merger', function() { var newHotels = merger.getHotels(); var newHotel = newHotels[0]; - expect(getRateIds(newHotel.rates)).to.deep.equal([2, 3, 1]); - expect(newHotel).to.not.equal(oldHotel); - expect(newHotels).to.not.equal(oldHotels); - }); - - it('update with better rate', function() { - var rate1 = { - id: 1, - hotelId: 1, - providerCode: 'x', - price: { - amount: 100, - } - }; - - var rate2 = { - id: 2, - hotelId: 1, - providerCode: 'y', - price: { - amount: 70, - } - }; - - var rate3 = { - id: 3, - hotelId: 1, - providerCode: 'y', - price: { - amount: 60, - } - }; - - var hotel = { - id: 1, - }; - - merger.mergeResponse({ - rates: [rate1, rate2], - hotels: [hotel], - }); - - merger.mergeResponse({ - rates: [rate3] - }); - - expect(getRateIds(merger.__hotelMap[1].rates)).to.deep.equal([3, 1]); - }); - - it('not update with worse rate', function() { - var rate1 = { - id: 1, - hotelId: 1, - providerCode: 'x', - price: { - amount: 100, - } - }; - - var rate2 = { - id: 2, - hotelId: 1, - providerCode: 'y', - price: { - amount: 70, - } - }; - - var rate3 = { - id: 3, - hotelId: 1, - providerCode: 'y', - price: { - amount: 120, - } - }; - - var hotel = { - id: 1, - }; - - merger.mergeResponse({ - rates: [rate1, rate2], - hotels: [hotel], - }); - - merger.mergeResponse({ - rates: [rate3] - }); - - expect(getRateIds(merger.__hotelMap[1].rates)).to.deep.equal([2, 1]); + expect(getRateIds(newHotel.rates)).to.deep.equal([1, 2, 3]); }); it("some hotel may have more than 1 from a provider rate when search's is end", () => { diff --git a/test/hotel-search/dataUtils.spec.js b/test/hotel-search/dataUtils.spec.js index 71c64a8..7e51cca 100644 --- a/test/hotel-search/dataUtils.spec.js +++ b/test/hotel-search/dataUtils.spec.js @@ -232,168 +232,6 @@ describe('dataUtils', function() { }); }); - describe('#isBetterRate', function() { - function bestRateOf(rates) { - rates.sort(function(rate1, rate2) { - return dataUtils.isBetterRate(rate1, rate2) ? -1 : 1; - }); - return rates[0]; - } - - it('resolve by tax amount usd', function() { - var r1 = { - price: { - taxAmountUsd: 0, - } - }; - - var r2 = { - price: { - taxAmountUsd: -2, - } - }; - - expect(bestRateOf([r1, r2])).to.equal(r1); - }); - - it('resolve by price', function() { - var r1 = { - price: { - amount: 11.1 - } - }; - - var r2 = { - price: { - amount: 12.1 - } - }; - - expect(bestRateOf([r1, r2])).to.equal(r1); - }); - - it('resolve by ecpc', function() { - var r1 = { - price: { - amount: 100000.3, - ecpc: 1, - } - }; - - var r2 = { - price: { - amount: 100099.2, - ecpc: 2, - } - }; - - expect(bestRateOf([r1, r2])).to.equal(r1); - }); - - it('compare three prices', function() { - var r1 = { - price: { - amount: 100000, - ecpc: 1, - } - }; - - var r2 = { - price: { - amount: 100099, - ecpc: 2, - } - }; - - var r3 = { - price: { - amount: 1000, - ecpc: 1000, - } - }; - - expect(bestRateOf([r1, r2, r3])).to.equal(r3); - }); - - it('prioritizes directBooking when prices are the same but one is directBooking', function() { - var r1 = { - price: { - amount: 10000, - ecpc: 1 - }, - provider: { - code: 'provider1', - directBooking: false - } - }; - - var r2 = { - price: { - amount: 10000, - ecpc: 2 - }, - provider: { - code: 'provider2', - directBooking: true - } - }; - - expect(bestRateOf([r1, r2])).to.equals(r2); - }); - - it('compare two rates when price and provider type same', function() { - var r1 = { - price: { - amount: 10000, - ecpc: 1 - }, - provider: { - code: 'provider1', - type: 'DIRECT_PRIORITY' - } - }; - - var r2 = { - price: { - amount: 10000, - ecpc: 2 - }, - provider: { - code: 'provider2', - type: 'DIRECT_PRIORITY' - } - }; - - expect(bestRateOf([r1, r2])).to.equals(r2); - }); - - it('compare two rates when price is same but first with direct_priority provider', function() { - var r1 = { - price: { - amount: 10000, - ecpc: 1 - }, - provider: { - code: 'provider1', - type: 'DIRECT_PRIORITY' - } - }; - - var r2 = { - price: { - amount: 10000, - ecpc: 2 - }, - provider: { - code: 'provider2', - type: 'OTA' - } - }; - - expect(bestRateOf([r1, r2])).to.equals(r1) - }); - }); - function createStaticData(data) { return Object.assign({ districts: {},