@findhotel/sapi
Advanced tools
Comparing version 0.23.11 to 0.23.12
@@ -36,2 +36,3 @@ import { ProfileKey, IndexVariation } from './types'; | ||
client: { | ||
defaultRooms: string; | ||
features: Features[]; | ||
@@ -38,0 +39,0 @@ blockedDefaultDates: string[]; |
@@ -1,107 +0,34 @@ | ||
import { CugDeals, HotelId, HotelOfferEntity, Brand, Currency, DeviceType, RoomId, Meals, Logger } from './types'; | ||
interface V3RateBreakdown { | ||
base: number; | ||
hotelFees: number; | ||
taxes: number; | ||
} | ||
interface CancellationPenalty { | ||
amount: number; | ||
percent?: number; | ||
nights?: number; | ||
currency: string; | ||
end: string; | ||
start: string; | ||
} | ||
declare type Amenities = Meals & 'internetIncluded'; | ||
declare type OfferTag = 'top_offer' | 'anchor_price' | 'exclusive_cheapest_offer'; | ||
interface SapiResponseOffer { | ||
accessTier: string; | ||
availableRooms: number; | ||
cancellationPenalties: CancellationPenalty[]; | ||
currency: Currency; | ||
id: string; | ||
intermediaryProvider: string; | ||
metadata: { | ||
feedID: string; | ||
providerRateType?: string; | ||
}; | ||
occupancy: string | number | null; | ||
package: { | ||
amenities: Amenities[]; | ||
canPayLater: boolean; | ||
refundable: boolean; | ||
}; | ||
providerCode: string; | ||
rate: V3RateBreakdown; | ||
roomID: RoomId; | ||
tags: OfferTag[] | null; | ||
url: string; | ||
} | ||
declare type Rooms = Record<RoomId, { | ||
name: string; | ||
}>; | ||
export interface SapiResponseOfferEntity { | ||
anchorRate: V3RateBreakdown; | ||
availableOffersCount: number; | ||
fetchedAllOffers: boolean; | ||
hasMoreOffers: boolean; | ||
id: HotelId; | ||
offers: SapiResponseOffer[]; | ||
rooms: Rooms; | ||
} | ||
interface Options { | ||
brand?: Brand; | ||
anonymousId: string; | ||
currency: string; | ||
countryCode: string; | ||
language: string; | ||
includeLocalTaxes?: boolean; | ||
includeTaxes?: boolean; | ||
skipBackendAugmentation?: boolean; | ||
facetsEnabled?: boolean; | ||
WebSocket?: any; | ||
sapiCliKey?: string; | ||
deviceType: DeviceType; | ||
variations: string[]; | ||
logger: Logger; | ||
} | ||
export interface GetOffersParameters { | ||
anchorHotelId?: HotelId; | ||
hotelIds?: HotelId[]; | ||
import { BaseWithConfig } from '.'; | ||
import { GetOffersParameters } from './offers-client'; | ||
import { HotelId, HotelOfferEntity, CugDeals } from './types'; | ||
import { AppConfig } from './app-config'; | ||
interface OffersParameters { | ||
hotelId: HotelId; | ||
checkIn: string; | ||
checkOut: string; | ||
rooms: string; | ||
searchId?: string; | ||
cugDeals?: CugDeals; | ||
isAnchor?: boolean; | ||
getAllOffers?: boolean; | ||
originId?: string; | ||
checkIn: string; | ||
checkOut: string; | ||
rooms: string; | ||
searchId: string; | ||
filters?: { | ||
freeCancellation?: boolean; | ||
}; | ||
freeCancellation?: boolean; | ||
preferredRate?: number; | ||
trafficSource?: string; | ||
} | ||
export interface OffersResponse { | ||
anchorHotelOfferEntity?: HotelOfferEntity; | ||
hotelOfferEntities?: HotelOfferEntity[]; | ||
interface Callbacks { | ||
onStart?: (parameters: GetOffersParameters) => void; | ||
onOffersReceived?: (response: HotelOfferEntity | undefined) => void; | ||
onComplete?: (response: HotelOfferEntity | undefined) => void; | ||
} | ||
export interface OffersClient { | ||
getOffers: (parameters: GetOffersParameters, onOffersReceived?: (response: OffersResponse) => void) => Promise<OffersResponse>; | ||
} | ||
interface MappingContext { | ||
checkIn: string; | ||
checkOut: string; | ||
includeTaxes?: boolean; | ||
includeLocalTaxes?: boolean; | ||
} | ||
export declare function sapiResponseToHotelOfferEntity(offerEntity: SapiResponseOfferEntity, context: MappingContext): HotelOfferEntity; | ||
interface ApiConfig { | ||
baseUrl: string; | ||
endpoints: { | ||
offers: string; | ||
}; | ||
} | ||
export declare function offers(config: ApiConfig, options: Options): { | ||
getOffers: (parameters: GetOffersParameters, onOffersReceived?: ((response: OffersResponse) => void) | undefined) => Promise<OffersResponse>; | ||
}; | ||
export declare type OffersHandler = (parameters: OffersParameters, callbacks: Callbacks) => Promise<HotelOfferEntity | undefined>; | ||
export declare function getOffersParameters(parameters: OffersParameters, options: BaseWithConfig['options'], appConfig: AppConfig): GetOffersParameters; | ||
/** | ||
* Creates offers function with configuration object | ||
* | ||
* @param configuration - Configuration for offers initialisation | ||
* | ||
* @returns function for fetching offers | ||
*/ | ||
export declare function offers({ offersClient, options, appConfig }: Pick<BaseWithConfig, 'offersClient' | 'options' | 'appConfig'>): OffersHandler; | ||
export {}; |
import { SearchClient } from 'algoliasearch'; | ||
import { Except } from 'type-fest'; | ||
import { OffersClient } from './offers'; | ||
import { OffersClient } from './offers-client'; | ||
import { Configs } from './algolia'; | ||
@@ -5,0 +5,0 @@ import { AppConfig, Features } from './app-config'; |
@@ -9,2 +9,3 @@ import { AlgoliaSearchOptions } from 'algoliasearch'; | ||
import { Configs } from '../algolia'; | ||
import { OffersHandler } from '../offers'; | ||
export declare type ProfileKey = 'findhotel-website' | 'findhotel-website-e2e' | 'findhotel-website-stg' | 'findhotel-website-ci' | 'findhotel-website-dev' | 'findhotel-checkout' | 'findhotel-checkout-e2e' | 'findhotel-checkout-stg'; | ||
@@ -23,2 +24,3 @@ interface Event { | ||
hotel: HotelHandler; | ||
offers: OffersHandler; | ||
} | ||
@@ -25,0 +27,0 @@ /** Options for initializing the Search API client. Persistent within single SAPI instance but may vary for different users */ |
@@ -55,3 +55,2 @@ export interface IndexVariation { | ||
searchId?: string; | ||
useAlternativeRaaKeys?: boolean; | ||
skipGeoSearch?: boolean; | ||
@@ -58,0 +57,0 @@ preferredRate?: number; |
@@ -10,1 +10,3 @@ export * from './cheapest-rate'; | ||
export * from './remove-empty'; | ||
export * from './sorting-boosts'; | ||
export * from './build-offers-response'; |
@@ -1,7 +0,7 @@ | ||
import { AnonymousId, ApiSearchParameters } from '../types'; | ||
import { AnonymousId, ApiSearchParameters, Country, Currency, Language } from '../types'; | ||
interface SearchIdOptions { | ||
anonymousId: AnonymousId; | ||
language: string; | ||
currency: string; | ||
countryCode: string; | ||
language: Language; | ||
currency: Currency; | ||
countryCode: Country; | ||
} | ||
@@ -8,0 +8,0 @@ /** |
{ | ||
"name": "@findhotel/sapi", | ||
"version": "0.23.11", | ||
"version": "0.23.12", | ||
"description": "FindHotel Search API", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
377
README.md
@@ -8,5 +8,6 @@ | ||
2. [Usage](#usage) | ||
1. [Hotels search](#tutorial-hotels-search) | ||
2. [Get rooms data](#tutorial-get-rooms) | ||
1. [Search](#tutorial-hotels-search) | ||
2. [Get hotel's rooms offers](#tutorial-get-rooms) | ||
3. [Get hotel](#tutorial-get-hotel) | ||
4. [Get hotel offers](#tutorial-get-offers) | ||
3. [API Reference](#api-reference) | ||
@@ -29,2 +30,6 @@ 1. [SAPI client](#sapi-client) | ||
2. [Response](#hotel-response) | ||
6. [`offers()` method](#offers-method) | ||
1. [Offers parameters](#hotel-parameters) | ||
2. [Callbacks](#offers-callbacks) | ||
3. [Response](#offers-response) | ||
@@ -85,3 +90,3 @@ SDK provides a high level TypeScript/JavaScript API for searching | ||
### Hotels search | ||
### Search | ||
@@ -99,15 +104,15 @@ Search for the hotels and hotels' offers: | ||
onStart: (response) => { | ||
console.log('Search started', response) | ||
log('Search started', response) | ||
}, | ||
onAnchorReceived: (response) => { | ||
console.log('Anchor received', response) | ||
log('Anchor received', response) | ||
}, | ||
onHotelsReceived: (response) => { | ||
console.log('Hotels received', response) | ||
log('Hotels received', response) | ||
}, | ||
onOffersReceived: (response) => { | ||
console.log('Offers received', response) | ||
log('Offers received', response) | ||
}, | ||
onComplete: (response) => { | ||
console.log('Search completed', response) | ||
log('Search completed', response) | ||
} | ||
@@ -123,5 +128,5 @@ } | ||
### Get rooms data | ||
### Get hotel's rooms offers | ||
Get rooms and rooms' offers: | ||
Get rooms data and rooms' offers: | ||
@@ -149,2 +154,29 @@ const rooms = await sapiClient.rooms({ | ||
<a id="tutorial-get-offers"></a> | ||
### Get hotel offers | ||
Get offers for a single hotel: | ||
const parameters = { | ||
hotelId: '1196472' | ||
} | ||
const callbacks = { | ||
onStart: (response) => { | ||
log('Offers started', response) | ||
}, | ||
onOffersReceived: (response) => { | ||
log('Offers received', response) | ||
}, | ||
onComplete: (response) => { | ||
log('Offers completed', response) | ||
} | ||
} | ||
const offers = await sapiClient.offers(parameters, callbacks) | ||
For full documentation, check [offers method api](#offers-method). | ||
<a id="api-reference"></a> | ||
@@ -184,3 +216,3 @@ | ||
onConfigReceived: (config) => { | ||
console.log('Config received', config) | ||
log('Config received', config) | ||
} | ||
@@ -538,15 +570,15 @@ } | ||
onStart: (response) => { | ||
console.log('Search started', response) | ||
log('Search started', response) | ||
}, | ||
onAnchorReceived: (response) => { | ||
console.log('Anchor received', response) | ||
log('Anchor received', response) | ||
}, | ||
onHotelsReceived: (response) => { | ||
console.log('Hotels received', response) | ||
log('Hotels received', response) | ||
}, | ||
onOffersReceived: (response) => { | ||
console.log('Offers received', response) | ||
log('Offers received', response) | ||
}, | ||
onComplete: (response) => { | ||
console.log('Search completed', response) | ||
log('Search completed', response) | ||
} | ||
@@ -660,16 +692,16 @@ } | ||
{ | ||
highlightValue: "<em>London</em>", | ||
objectID: "158584", | ||
objectType: "place", | ||
placeDisplayName: "United Kingdom", | ||
placeTypeName: "city", | ||
value: "London" | ||
"highlightValue": "<em>London</em>", | ||
"objectID": "158584", | ||
"objectType": "place", | ||
"placeDisplayName": "United Kingdom", | ||
"placeTypeName": "city", | ||
"value": "London" | ||
}, | ||
{ | ||
highlightValue: "<em>London</em> Heathrow Airport", | ||
objectID: "167733", | ||
objectType: "place", | ||
placeDisplayName: "London, United Kingdom", | ||
placeTypeName: "airport", | ||
value: "London Heathrow Airport" | ||
"highlightValue": "<em>London</em> Heathrow Airport", | ||
"objectID": "167733", | ||
"objectType": "place", | ||
"placeDisplayName": "London, United Kingdom", | ||
"placeTypeName": "airport", | ||
"value": "London Heathrow Airport" | ||
} | ||
@@ -682,16 +714,16 @@ ] | ||
{ | ||
highlightValue: "Park Plaza Westminster Bridge <em>London</em>", | ||
objectID: "1546646", | ||
objectType: "hotel", | ||
placeDisplayName: "London, United Kingdom", | ||
placeTypeName: "property", | ||
value: "Park Plaza Westminster Bridge London" | ||
"highlightValue": "Park Plaza Westminster Bridge <em>London</em>", | ||
"objectID": "1546646", | ||
"objectType": "hotel", | ||
"placeDisplayName": "London, United Kingdom", | ||
"placeTypeName": "property", | ||
"value": "Park Plaza Westminster Bridge London" | ||
}, | ||
{ | ||
highlightValue: "Hampton by Hilton <em>London</em> Stansted Airport", | ||
objectID: "3333916", | ||
objectType: "hotel", | ||
placeDisplayName: "United Kingdom", | ||
placeTypeName: "property", | ||
value: "Hampton by Hilton London Stansted Airport" | ||
"highlightValue": "Hampton by Hilton <em>London</em> Stansted Airport", | ||
"objectID": "3333916", | ||
"objectType": "hotel", | ||
"placeDisplayName": "United Kingdom", | ||
"placeTypeName": "property", | ||
"value": "Hampton by Hilton London Stansted Airport" | ||
} | ||
@@ -950,1 +982,266 @@ ] | ||
<a id="offers-method"></a> | ||
## `offers()` method | ||
Retrieves offers for a single hotel by provided parameters | ||
const parameters = { | ||
hotelId: '1196472', | ||
checkIn: '2022-10-10', | ||
checkOut: '2022-10-11', | ||
rooms: '2' | ||
} | ||
const callbacks = { | ||
onStart: (response) => { | ||
log('Offers started', response) | ||
}, | ||
onOffersReceived: (response) => { | ||
log('Offers received', response) | ||
}, | ||
onComplete: (response) => { | ||
log('Offers completed', response) | ||
} | ||
} | ||
const offers = await sapiClient.offers(parameters, callbacks) | ||
<a id="hotel-parameters"></a> | ||
### Offers parameters | ||
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> | ||
<colgroup> | ||
<col class="org-left" /> | ||
<col class="org-left" /> | ||
<col class="org-left" /> | ||
<col class="org-left" /> | ||
<col class="org-left" /> | ||
</colgroup> | ||
<thead> | ||
<tr> | ||
<th scope="col" class="org-left">name</th> | ||
<th scope="col" class="org-left">type</th> | ||
<th scope="col" class="org-left">description</th> | ||
<th scope="col" class="org-left">required</th> | ||
<th scope="col" class="org-left">example</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td class="org-left">`hotelId`</td> | ||
<td class="org-left">`string`</td> | ||
<td class="org-left">Hotel Id</td> | ||
<td class="org-left">yes</td> | ||
<td class="org-left">`1196472`</td> | ||
</tr> | ||
<tr> | ||
<td class="org-left">`checkIn`</td> | ||
<td class="org-left">`string`</td> | ||
<td class="org-left">Check in date (YYYY-MM-DD) (SDK generates default date if no provided)</td> | ||
<td class="org-left">no</td> | ||
<td class="org-left">`2022-10-10`</td> | ||
</tr> | ||
<tr> | ||
<td class="org-left">`checkOut`</td> | ||
<td class="org-left">`string`</td> | ||
<td class="org-left">Check out date (YYYY-MM-DD)) (SDK generates default date if no provided)</td> | ||
<td class="org-left">no</td> | ||
<td class="org-left">`2022-10-11`</td> | ||
</tr> | ||
<tr> | ||
<td class="org-left">`rooms`</td> | ||
<td class="org-left">`string`</td> | ||
<td class="org-left">[Rooms configuration](https://github.com/FindHotel/search-data-pipelines/wiki/Glossary#rooms-configuration)</td> | ||
<td class="org-left">no</td> | ||
<td class="org-left">`2`</td> | ||
</tr> | ||
<tr> | ||
<td class="org-left">`searchId`</td> | ||
<td class="org-left">`string`</td> | ||
<td class="org-left">SearchId override (SDK generates a new one if no provided)</td> | ||
<td class="org-left">no</td> | ||
<td class="org-left">`08230dfcc5f0fb95caaa82ce559ea60c4a975d6f`</td> | ||
</tr> | ||
<tr> | ||
<td class="org-left">`cugDeals`</td> | ||
<td class="org-left">`string[]`</td> | ||
<td class="org-left">Codes of closed user group deals to retrieve offers</td> | ||
<td class="org-left">no</td> | ||
<td class="org-left">`['signed_in', 'offline']`</td> | ||
</tr> | ||
<tr> | ||
<td class="org-left">`freeCancellation`</td> | ||
<td class="org-left">`boolean`</td> | ||
<td class="org-left">Promote offers with free cancelation (default `false`)</td> | ||
<td class="org-left">no</td> | ||
<td class="org-left">`true`</td> | ||
</tr> | ||
<tr> | ||
<td class="org-left">`isAnchor`</td> | ||
<td class="org-left">`boolean`</td> | ||
<td class="org-left">Anchor/Non anchor hotel (default `false`)</td> | ||
<td class="org-left">no</td> | ||
<td class="org-left">`true`</td> | ||
</tr> | ||
<tr> | ||
<td class="org-left">`getAllOffers`</td> | ||
<td class="org-left">`boolean`</td> | ||
<td class="org-left">Get all/only top offers (default `false`)</td> | ||
<td class="org-left">no</td> | ||
<td class="org-left">`true`</td> | ||
</tr> | ||
<tr> | ||
<td class="org-left">`originId`</td> | ||
<td class="org-left">`string`</td> | ||
<td class="org-left">Identifier of origin where the request was originated</td> | ||
<td class="org-left">no</td> | ||
<td class="org-left">`c3po6twr70`</td> | ||
</tr> | ||
<tr> | ||
<td class="org-left">`trafficSource`</td> | ||
<td class="org-left">`string`</td> | ||
<td class="org-left">Visitor's traffic source. Opaque value that will be passed to tracking systems</td> | ||
<td class="org-left">no</td> | ||
<td class="org-left">`gha-vr`</td> | ||
</tr> | ||
<tr> | ||
<td class="org-left">`preferredRate`</td> | ||
<td class="org-left">`number`</td> | ||
<td class="org-left">Offer's price user saw on a CA (meta) platform</td> | ||
<td class="org-left">no</td> | ||
<td class="org-left">`196`</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<a id="offers-callbacks"></a> | ||
### Callbacks | ||
Object with callbacks: | ||
const callbacks = { | ||
onStart: (response) => { | ||
log('Offers started', response) | ||
}, | ||
onOffersReceived: (response) => { | ||
log('Offers received', response) | ||
}, | ||
onComplete: (response) => { | ||
log('Offers completed', response) | ||
} | ||
} | ||
1. onStart() | ||
Runs at the beginning of the each new offers request. | ||
Returns adjusted and validated offers request parameters. | ||
2. onOffersReceived() | ||
Runs on every received batch of offers. | ||
Returns hotel's offers (incomplete response). | ||
3. onComplete() | ||
Runs after offers request complete. | ||
Returns hotel's offers (complete response). | ||
<a id="offers-response"></a> | ||
### Response | ||
An example of the response for request parameters: | ||
const parameters = { | ||
hotelId: '1926746', | ||
checkIn: '2022-07-10', | ||
checkOut: '2022-07-11', | ||
rooms: '2' | ||
} | ||
{ | ||
"anchorPriceRateBreakdown": { | ||
"baseRate": 113.21, | ||
"localTaxes": 8.64, | ||
"taxes": 10.19, | ||
"calculatedTotalRate": 132.04, | ||
"nightlyRate": 132.04 | ||
}, | ||
"availableOffersCount": 19, | ||
"fetchedAllOffers": false, | ||
"hasMoreOffers": true, | ||
"id": "1926746", | ||
"offers": [ | ||
{ | ||
"additionalProviderParams": { | ||
"feedId": "1524856" | ||
}, | ||
"availableRooms": 10, | ||
"bookURI": "https://r.findhotel.net?...", | ||
"calculatedTotalRate": 110.72, | ||
"canPayLater": true, | ||
"cug": null, | ||
"currency": "EUR", | ||
"hasAnchorPrice": true, | ||
"hasFreeCancellation": true, | ||
"id": "oO8jdRHaO8y0", | ||
"isAnchorPriceOffer": false, | ||
"isCheapest": false, | ||
"isTopOffer": true, | ||
"meals": ["breakfast"], | ||
"nightlyRate": 110.72, | ||
"providerCode": "BKS", | ||
"proxyProviderCode": "BKS", | ||
"rateBreakdown": { | ||
"baseRate": 90.28, | ||
"localTaxes": 12.32, | ||
"taxes": 8.12 | ||
}, | ||
"roomID": "moc_08Ap8BcbIDg", | ||
"roomName": "Standard Double Room", | ||
"tags": ["top_offer"] | ||
} | ||
], | ||
"topOfferData": { | ||
"anchorPrice": 132.04, | ||
"anchorPriceNightly": 132.04, | ||
"offerIndexes": [0, 1, 2, 3] | ||
} | ||
} | ||
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
299269
61
1237
2538