@findhotel/sapi 0.26.6 → 1.0.1-beta.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 +94 -98
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -0
- 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 +23 -87
- 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,23 +411,23 @@ 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)
|
|
425
429
|
|
|
426
|
-
5. onComplete()
|
|
430
|
+
5. ### onComplete()
|
|
427
431
|
|
|
428
432
|
Runs when current search is complete and all offers are retrieved\
|
|
429
433
|
Return complete SAPI seearch response.
|
|
@@ -493,51 +497,47 @@ so there is a simplified example:
|
|
|
493
497
|
"hotelOfferEntities": {
|
|
494
498
|
"1041597": {
|
|
495
499
|
"anchorPriceRateBreakdown": {
|
|
496
|
-
"
|
|
497
|
-
"
|
|
498
|
-
"localTaxes": 23.122149135,
|
|
499
|
-
"nightlyRate": 288.13897963499994,
|
|
500
|
+
"base": 244.6021305,
|
|
501
|
+
"hotelFees": 23.122149135,
|
|
500
502
|
"taxes": 20.4147
|
|
501
503
|
},
|
|
502
504
|
"availableOffersCount": 23,
|
|
503
|
-
"fetchedAllOffers": false,
|
|
504
|
-
"hasMoreOffers": true,
|
|
505
505
|
"id": "1041597",
|
|
506
506
|
"offers": [
|
|
507
507
|
{
|
|
508
|
-
"
|
|
509
|
-
"feedId": "1524856"
|
|
510
|
-
},
|
|
511
|
-
"availableRooms": 10,
|
|
512
|
-
"bookURI": "https://r.findhotel.net?...",
|
|
513
|
-
"calculatedTotalRate": 110.72,
|
|
514
|
-
"canPayLater": true,
|
|
515
|
-
"cug": null,
|
|
508
|
+
"id": "o5vFF4-wmvcc",
|
|
516
509
|
"currency": "EUR",
|
|
517
|
-
"
|
|
518
|
-
"
|
|
519
|
-
"
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
"
|
|
510
|
+
"availableRooms": 6,
|
|
511
|
+
"url": "https://r.findhotel.net?...",
|
|
512
|
+
"rate": {
|
|
513
|
+
"base": 197.17,
|
|
514
|
+
"taxes": 17.75,
|
|
515
|
+
"hotelFees": 31.8
|
|
516
|
+
},
|
|
517
|
+
"accessTier": "",
|
|
525
518
|
"providerCode": "BKS",
|
|
526
|
-
"
|
|
527
|
-
"
|
|
528
|
-
|
|
529
|
-
"
|
|
530
|
-
|
|
519
|
+
"intermediaryProvider": "BKS",
|
|
520
|
+
"roomName": "Standard Twin Room",
|
|
521
|
+
"package": {
|
|
522
|
+
"amenities": [
|
|
523
|
+
"breakfast"
|
|
524
|
+
],
|
|
525
|
+
"canPayLater": false
|
|
531
526
|
},
|
|
532
|
-
"
|
|
533
|
-
"
|
|
534
|
-
|
|
527
|
+
"cancellationPenalties": [],
|
|
528
|
+
"tags": [
|
|
529
|
+
"top_offer"
|
|
530
|
+
],
|
|
531
|
+
"metadata": {
|
|
532
|
+
"feedID": ""
|
|
533
|
+
}
|
|
535
534
|
}
|
|
536
535
|
],
|
|
537
|
-
"
|
|
538
|
-
"
|
|
539
|
-
"
|
|
540
|
-
"
|
|
536
|
+
"discount": {
|
|
537
|
+
"discountProvider": "FHT",
|
|
538
|
+
"hasDiscountProvider": true,
|
|
539
|
+
"hasParityProvider": true,
|
|
540
|
+
"modifier": "b"
|
|
541
541
|
}
|
|
542
542
|
}
|
|
543
543
|
},
|
|
@@ -870,17 +870,17 @@ const callbacks = {
|
|
|
870
870
|
}
|
|
871
871
|
```
|
|
872
872
|
|
|
873
|
-
1. onStart()
|
|
873
|
+
1. ### onStart()
|
|
874
874
|
|
|
875
875
|
Runs at the beginning of the each new offers request.\
|
|
876
876
|
Returns adjusted and validated offers request parameters.
|
|
877
877
|
|
|
878
|
-
2. onOffersReceived()
|
|
878
|
+
2. ### onOffersReceived()
|
|
879
879
|
|
|
880
880
|
Runs on every received batch of offers.\
|
|
881
881
|
Returns hotel\'s offers (incomplete response).
|
|
882
882
|
|
|
883
|
-
3. onComplete()
|
|
883
|
+
3. ### onComplete()
|
|
884
884
|
|
|
885
885
|
Runs after offers request complete.\
|
|
886
886
|
Returns hotel\'s offers (complete response).
|
|
@@ -902,51 +902,47 @@ const parameters = {
|
|
|
902
902
|
```js
|
|
903
903
|
{
|
|
904
904
|
"anchorPriceRateBreakdown": {
|
|
905
|
-
"
|
|
906
|
-
"
|
|
907
|
-
"taxes":
|
|
908
|
-
"calculatedTotalRate": 132.04,
|
|
909
|
-
"nightlyRate": 132.04
|
|
905
|
+
"base": 244.6021305,
|
|
906
|
+
"hotelFees": 23.122149135,
|
|
907
|
+
"taxes": 20.4147
|
|
910
908
|
},
|
|
911
|
-
"availableOffersCount":
|
|
912
|
-
"
|
|
913
|
-
"hasMoreOffers": true,
|
|
914
|
-
"id": "1926746",
|
|
909
|
+
"availableOffersCount": 23,
|
|
910
|
+
"id": "1041597",
|
|
915
911
|
"offers": [
|
|
916
912
|
{
|
|
917
|
-
"
|
|
918
|
-
"feedId": "1524856"
|
|
919
|
-
},
|
|
920
|
-
"availableRooms": 10,
|
|
921
|
-
"bookURI": "https://r.findhotel.net?...",
|
|
922
|
-
"calculatedTotalRate": 110.72,
|
|
923
|
-
"canPayLater": true,
|
|
924
|
-
"cug": null,
|
|
913
|
+
"id": "o5vFF4-wmvcc",
|
|
925
914
|
"currency": "EUR",
|
|
926
|
-
"
|
|
927
|
-
"
|
|
928
|
-
"
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
"
|
|
915
|
+
"availableRooms": 6,
|
|
916
|
+
"url": "https://r.findhotel.net?...",
|
|
917
|
+
"rate": {
|
|
918
|
+
"base": 197.17,
|
|
919
|
+
"taxes": 17.75,
|
|
920
|
+
"hotelFees": 31.8
|
|
921
|
+
},
|
|
922
|
+
"accessTier": "",
|
|
934
923
|
"providerCode": "BKS",
|
|
935
|
-
"
|
|
936
|
-
"
|
|
937
|
-
|
|
938
|
-
"
|
|
939
|
-
|
|
924
|
+
"intermediaryProvider": "BKS",
|
|
925
|
+
"roomName": "Standard Twin Room",
|
|
926
|
+
"package": {
|
|
927
|
+
"amenities": [
|
|
928
|
+
"breakfast"
|
|
929
|
+
],
|
|
930
|
+
"canPayLater": false
|
|
940
931
|
},
|
|
941
|
-
"
|
|
942
|
-
"
|
|
943
|
-
|
|
932
|
+
"cancellationPenalties": [],
|
|
933
|
+
"tags": [
|
|
934
|
+
"top_offer"
|
|
935
|
+
],
|
|
936
|
+
"metadata": {
|
|
937
|
+
"feedID": ""
|
|
938
|
+
}
|
|
944
939
|
}
|
|
945
940
|
],
|
|
946
|
-
"
|
|
947
|
-
"
|
|
948
|
-
"
|
|
949
|
-
"
|
|
941
|
+
"discount": {
|
|
942
|
+
"discountProvider": "FHT",
|
|
943
|
+
"hasDiscountProvider": true,
|
|
944
|
+
"hasParityProvider": true,
|
|
945
|
+
"modifier": "b"
|
|
950
946
|
}
|
|
951
947
|
}
|
|
952
948
|
```
|