@findhotel/sapi 0.26.6 → 1.0.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/README.md +66 -114
- package/dist/index.js +1 -1
- package/dist/types/packages/core/src/__fixtures__/offers.d.ts +65 -35
- package/dist/types/packages/core/src/offers-client.d.ts +4 -14
- package/dist/types/packages/core/src/search.d.ts +2 -19
- package/dist/types/packages/core/src/types/index.d.ts +2 -0
- package/dist/types/packages/core/src/types/offers.d.ts +66 -0
- package/dist/types/packages/core/src/types/options.d.ts +11 -10
- package/dist/types/packages/core/src/types/rooms.d.ts +2 -8
- package/dist/types/packages/core/src/types/search.d.ts +18 -0
- package/dist/types/packages/core/src/types/types.d.ts +28 -88
- package/dist/types/packages/core/src/utils/build-offers-response.d.ts +6 -3
- package/dist/types/packages/core/src/utils/cheapest-rate.d.ts +2 -2
- package/dist/types/packages/core/src/utils/deal-score.d.ts +3 -3
- package/dist/types/packages/core/src/utils/get-total-rate.d.ts +8 -0
- package/dist/types/packages/core/src/utils/index.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -242,8 +242,6 @@ const sapiClient = await sapi(profileKey, {
|
|
|
242
242
|
currency: 'USD',
|
|
243
243
|
countryCode: 'US',
|
|
244
244
|
deviceType: 'mobile',
|
|
245
|
-
includeLocalTaxes: true,
|
|
246
|
-
includeTaxes: false,
|
|
247
245
|
pageSize: 20,
|
|
248
246
|
initWithAppConfig: {
|
|
249
247
|
features: ['search', 'configs'],
|
|
@@ -259,6 +257,13 @@ const sapiClient = await sapi(profileKey, {
|
|
|
259
257
|
onConfigReceived: (config) => {
|
|
260
258
|
log('Config received', config)
|
|
261
259
|
}
|
|
260
|
+
},
|
|
261
|
+
getTotalRate: (rate) => {
|
|
262
|
+
let totalRate = rate.base
|
|
263
|
+
if (includeTaxes) totalRate += rate.taxes
|
|
264
|
+
if (includeHotelFees) totalRate += rate.hotelFees
|
|
265
|
+
|
|
266
|
+
return totalRate
|
|
262
267
|
}
|
|
263
268
|
})
|
|
264
269
|
```
|
|
@@ -266,20 +271,19 @@ const sapiClient = await sapi(profileKey, {
|
|
|
266
271
|
### Supported options
|
|
267
272
|
<a id="client-options"></a>
|
|
268
273
|
|
|
269
|
-
| name | required | type | default
|
|
270
|
-
| ---------------------- | -------- | ------------------------ |
|
|
271
|
-
| `anonymousId` | yes | `string` |
|
|
272
|
-
| `language` | no | `string` | `en`
|
|
273
|
-
| `currency` | no | `string` | `USD`
|
|
274
|
-
| `countryCode` | no | `string` | `US`
|
|
275
|
-
| `deviceType` | yes | `string` |
|
|
276
|
-
| `
|
|
277
|
-
| `
|
|
278
|
-
| `
|
|
279
|
-
| `
|
|
280
|
-
| `
|
|
281
|
-
| `
|
|
282
|
-
| `callbacks` | no | `Record<string, fnc>` | | Client callbasks | |
|
|
274
|
+
| name | required | type | default | description | example |
|
|
275
|
+
| ---------------------- | -------- | ------------------------ | ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ |
|
|
276
|
+
| `anonymousId` | yes | `string` | | Unique ID identifying users | `2d360284-577b-4a53-8b91-68f72b9227fa` |
|
|
277
|
+
| `language` | no | `string` | `en` | 2-char language code | `en` |
|
|
278
|
+
| `currency` | no | `string` | `USD` | 3-char uppercased ISO currency code | `USD` |
|
|
279
|
+
| `countryCode` | no | `string` | `US` | 2-char uppercased ISO country code | `US` |
|
|
280
|
+
| `deviceType` | yes | `string` | | `desktop` or `mobile` | `desktop` |
|
|
281
|
+
| `pageSize` | no | `number` | `20` | Displayed page size | `20` |
|
|
282
|
+
| `initWithAppConfig` | no | `AppConfig` | | External app config to override internal one | |
|
|
283
|
+
| `algoliaClientOptions` | no | `AlgoliaSearchOptions` | | Algolia client options used for debugging and setting additional options like timeouts etc. | |
|
|
284
|
+
| `variations` | no | `Record<string, string>` | | A/B test variations | `{'pp000004-tags2': 'b', 'pp000004-tags3': '1'}` |
|
|
285
|
+
| `callbacks` | no | `Record<string, fnc>` | | Client callbasks | |
|
|
286
|
+
| `getTotalRate` | no | `function` | Total rate including taxes and fees | Function to calculate total display rate based on tax display logic. Used for price filter and sort by price functionalities. | |
|
|
283
287
|
|
|
284
288
|
### Available client callbacks
|
|
285
289
|
<a id="client-callbacks"></a>
|
|
@@ -333,7 +337,7 @@ const search = await sapiClient.search(searchParameters, callbacks)
|
|
|
333
337
|
All parameters are optional.
|
|
334
338
|
|
|
335
339
|
| name | type | description | example |
|
|
336
|
-
|
|
340
|
+
| --------------- | ------------------------------ | ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- |
|
|
337
341
|
| `hotelId` | `string` | Hotel Id for hotel search. If present, takes precedence over `placeId`, `query` and `geolocation`. | `1371626` |
|
|
338
342
|
| `placeId` | `string` | Place Id for place search. If present, takes precedence over `query` and `geolocation`. | `47319` |
|
|
339
343
|
| `geolocation` | `{lat: number, lon: number}` | Geolocation query. If present, takes precedence over `query` | `{lat: 36.114303, lon: -115.178312}` |
|
|
@@ -387,7 +391,7 @@ time of callbacks executions. This means that each subsequent callback
|
|
|
387
391
|
incrementally adds new properties and returns updated state. The data in
|
|
388
392
|
the state can be repeated between different callbacks.
|
|
389
393
|
|
|
390
|
-
1. onStart()
|
|
394
|
+
1. ### onStart()
|
|
391
395
|
|
|
392
396
|
Runs at the beginning of the each new search.
|
|
393
397
|
|
|
@@ -399,7 +403,7 @@ the state can be repeated between different callbacks.
|
|
|
399
403
|
hotels search has started, in Search SPA the event is
|
|
400
404
|
[HotelsSearched](https://engdocs.fih.io/event-analytics/sources/#event-hotelssearched).
|
|
401
405
|
|
|
402
|
-
2. onAnchorReceived()
|
|
406
|
+
2. ### onAnchorReceived()
|
|
403
407
|
|
|
404
408
|
Runs when SAPI receives anchor and(?) anchor hotel (in case of hotel
|
|
405
409
|
search)\
|
|
@@ -407,26 +411,28 @@ the state can be repeated between different callbacks.
|
|
|
407
411
|
anchor hotel inside `response.hotelEntities` object (in
|
|
408
412
|
case of hotel search).
|
|
409
413
|
|
|
410
|
-
3. onHotelsReceived()
|
|
414
|
+
3. ### onHotelsReceived()
|
|
411
415
|
|
|
412
416
|
Runs when SAPI receives static search results\
|
|
413
417
|
Returns static data about hotels inside
|
|
414
418
|
`response.hotelEntities` object as well as appropriate
|
|
415
419
|
hotel sort order in `response.hotelIds` array (sorted
|
|
416
|
-
according HSO).
|
|
420
|
+
according to HSO).
|
|
417
421
|
|
|
418
|
-
4. onOffersReceived()
|
|
422
|
+
4. ### onOffersReceived()
|
|
419
423
|
|
|
420
424
|
Runs when SAPI receives a bunch of offers\
|
|
421
425
|
Returns hotel's offers (incomplete response) in
|
|
422
426
|
`response.hotelOfferEntities` object as well as updated
|
|
423
427
|
hotel sort order in `response.hotelIds` array (sorted
|
|
424
|
-
according HSO and taking into account the real offers data)
|
|
428
|
+
according to HSO and taking into account the real offers data)\
|
|
429
|
+
The offers response with the detailed description can be found in the [Offers Response](./docs/offers.md)
|
|
425
430
|
|
|
426
|
-
5. onComplete()
|
|
431
|
+
5. ### onComplete()
|
|
427
432
|
|
|
428
433
|
Runs when current search is complete and all offers are retrieved\
|
|
429
|
-
Return complete SAPI seearch response
|
|
434
|
+
Return complete SAPI seearch response.\
|
|
435
|
+
The offers response with the detailed description can be found in the [Offers Response](./docs/offers.md)
|
|
430
436
|
|
|
431
437
|
### Response
|
|
432
438
|
<a id="search-response"></a>
|
|
@@ -492,52 +498,48 @@ so there is a simplified example:
|
|
|
492
498
|
"hotelIds": ["1840170", "2766940", "3310443", "3035769"],
|
|
493
499
|
"hotelOfferEntities": {
|
|
494
500
|
"1041597": {
|
|
495
|
-
"
|
|
496
|
-
"
|
|
497
|
-
"
|
|
498
|
-
"localTaxes": 23.122149135,
|
|
499
|
-
"nightlyRate": 288.13897963499994,
|
|
501
|
+
"anchorRate": {
|
|
502
|
+
"base": 244.6021305,
|
|
503
|
+
"hotelFees": 23.122149135,
|
|
500
504
|
"taxes": 20.4147
|
|
501
505
|
},
|
|
502
506
|
"availableOffersCount": 23,
|
|
503
|
-
"fetchedAllOffers": false,
|
|
504
|
-
"hasMoreOffers": true,
|
|
505
507
|
"id": "1041597",
|
|
506
508
|
"offers": [
|
|
507
509
|
{
|
|
508
|
-
"
|
|
509
|
-
"feedId": "1524856"
|
|
510
|
-
},
|
|
511
|
-
"availableRooms": 10,
|
|
512
|
-
"bookURI": "https://r.findhotel.net?...",
|
|
513
|
-
"calculatedTotalRate": 110.72,
|
|
514
|
-
"canPayLater": true,
|
|
515
|
-
"cug": null,
|
|
510
|
+
"id": "o5vFF4-wmvcc",
|
|
516
511
|
"currency": "EUR",
|
|
517
|
-
"
|
|
518
|
-
"
|
|
519
|
-
"
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
"
|
|
512
|
+
"availableRooms": 6,
|
|
513
|
+
"url": "https://r.vio.com?...",
|
|
514
|
+
"rate": {
|
|
515
|
+
"base": 197.17,
|
|
516
|
+
"taxes": 17.75,
|
|
517
|
+
"hotelFees": 31.8
|
|
518
|
+
},
|
|
519
|
+
"accessTier": "",
|
|
525
520
|
"providerCode": "BKS",
|
|
526
|
-
"
|
|
527
|
-
"
|
|
528
|
-
|
|
529
|
-
"
|
|
530
|
-
|
|
521
|
+
"intermediaryProvider": "BKS",
|
|
522
|
+
"roomName": "Standard Twin Room",
|
|
523
|
+
"package": {
|
|
524
|
+
"amenities": [
|
|
525
|
+
"breakfast"
|
|
526
|
+
],
|
|
527
|
+
"canPayLater": false
|
|
531
528
|
},
|
|
532
|
-
"
|
|
533
|
-
"
|
|
534
|
-
|
|
529
|
+
"cancellationPenalties": [],
|
|
530
|
+
"tags": [
|
|
531
|
+
"top_offer"
|
|
532
|
+
],
|
|
533
|
+
"metadata": {
|
|
534
|
+
"feedID": ""
|
|
535
|
+
}
|
|
535
536
|
}
|
|
536
537
|
],
|
|
537
|
-
"
|
|
538
|
-
"
|
|
539
|
-
"
|
|
540
|
-
"
|
|
538
|
+
"discount": {
|
|
539
|
+
"discountProvider": "FHT",
|
|
540
|
+
"hasDiscountProvider": true,
|
|
541
|
+
"hasParityProvider": true,
|
|
542
|
+
"modifier": "b"
|
|
541
543
|
}
|
|
542
544
|
}
|
|
543
545
|
},
|
|
@@ -870,17 +872,17 @@ const callbacks = {
|
|
|
870
872
|
}
|
|
871
873
|
```
|
|
872
874
|
|
|
873
|
-
1. onStart()
|
|
875
|
+
1. ### onStart()
|
|
874
876
|
|
|
875
877
|
Runs at the beginning of the each new offers request.\
|
|
876
878
|
Returns adjusted and validated offers request parameters.
|
|
877
879
|
|
|
878
|
-
2. onOffersReceived()
|
|
880
|
+
2. ### onOffersReceived()
|
|
879
881
|
|
|
880
882
|
Runs on every received batch of offers.\
|
|
881
883
|
Returns hotel\'s offers (incomplete response).
|
|
882
884
|
|
|
883
|
-
3. onComplete()
|
|
885
|
+
3. ### onComplete()
|
|
884
886
|
|
|
885
887
|
Runs after offers request complete.\
|
|
886
888
|
Returns hotel\'s offers (complete response).
|
|
@@ -899,54 +901,4 @@ const parameters = {
|
|
|
899
901
|
}
|
|
900
902
|
```
|
|
901
903
|
|
|
902
|
-
|
|
903
|
-
{
|
|
904
|
-
"anchorPriceRateBreakdown": {
|
|
905
|
-
"baseRate": 113.21,
|
|
906
|
-
"localTaxes": 8.64,
|
|
907
|
-
"taxes": 10.19,
|
|
908
|
-
"calculatedTotalRate": 132.04,
|
|
909
|
-
"nightlyRate": 132.04
|
|
910
|
-
},
|
|
911
|
-
"availableOffersCount": 19,
|
|
912
|
-
"fetchedAllOffers": false,
|
|
913
|
-
"hasMoreOffers": true,
|
|
914
|
-
"id": "1926746",
|
|
915
|
-
"offers": [
|
|
916
|
-
{
|
|
917
|
-
"additionalProviderParams": {
|
|
918
|
-
"feedId": "1524856"
|
|
919
|
-
},
|
|
920
|
-
"availableRooms": 10,
|
|
921
|
-
"bookURI": "https://r.findhotel.net?...",
|
|
922
|
-
"calculatedTotalRate": 110.72,
|
|
923
|
-
"canPayLater": true,
|
|
924
|
-
"cug": null,
|
|
925
|
-
"currency": "EUR",
|
|
926
|
-
"hasAnchorPrice": true,
|
|
927
|
-
"hasFreeCancellation": true,
|
|
928
|
-
"id": "oO8jdRHaO8y0",
|
|
929
|
-
"isAnchorPriceOffer": false,
|
|
930
|
-
"isCheapest": false,
|
|
931
|
-
"isTopOffer": true,
|
|
932
|
-
"meals": ["breakfast"],
|
|
933
|
-
"nightlyRate": 110.72,
|
|
934
|
-
"providerCode": "BKS",
|
|
935
|
-
"proxyProviderCode": "BKS",
|
|
936
|
-
"rateBreakdown": {
|
|
937
|
-
"baseRate": 90.28,
|
|
938
|
-
"localTaxes": 12.32,
|
|
939
|
-
"taxes": 8.12
|
|
940
|
-
},
|
|
941
|
-
"roomID": "moc_08Ap8BcbIDg",
|
|
942
|
-
"roomName": "Standard Double Room",
|
|
943
|
-
"tags": ["top_offer"]
|
|
944
|
-
}
|
|
945
|
-
],
|
|
946
|
-
"topOfferData": {
|
|
947
|
-
"anchorPrice": 132.04,
|
|
948
|
-
"anchorPriceNightly": 132.04,
|
|
949
|
-
"offerIndexes": [0, 1, 2, 3]
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
```
|
|
904
|
+
The response with the detailed description can be found in the [Offers Response](./docs/offers.md)
|