@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.
@@ -1,47 +1,77 @@
1
- export declare const offer: {
1
+ export declare const offer1: {
2
+ accessTier: null;
2
3
  availableRooms: number;
3
- bookURI: string;
4
- calculatedTotalRate: number;
5
- canPayLater: boolean;
6
- cug: null;
4
+ cancellationPenalties: never[];
7
5
  currency: string;
8
- hasAnchorPrice: boolean;
9
- hasFreeCancellation: boolean;
10
6
  id: string;
11
- integrationType: string;
12
- isAnchorPriceOffer: boolean;
13
- isCheapest: boolean;
14
- isSharedRoom: boolean;
15
- isTopOffer: boolean;
16
- meals: never[];
17
- nightlyRate: number;
7
+ intermediaryProvider: string;
8
+ metadata: {
9
+ feedID: string;
10
+ };
11
+ package: {
12
+ amenities: string[];
13
+ canPayLater: boolean;
14
+ };
18
15
  providerCode: string;
19
- providerHotelId: string;
20
- proxyProviderCode: string;
21
- rateBasedOnNumberOfRooms: null;
22
- rateBreakdown: {
23
- baseRate: number;
16
+ rate: {
17
+ base: number;
24
18
  taxes: number;
25
- localTaxes: number;
19
+ hotelFees: number;
26
20
  };
21
+ roomName: string;
22
+ tags: string[];
23
+ url: string;
27
24
  };
28
- export declare const topOffersData: {
29
- offerIndexes: number[];
30
- };
31
- export declare const topOffersDataWithAnchorPrice: {
32
- anchorPrice: number;
33
- anchorPriceNightly: number;
34
- offerIndexes: number[];
25
+ export declare const offer2: {
26
+ accessTier: null;
27
+ availableRooms: number;
28
+ cancellationPenalties: never[];
29
+ currency: string;
30
+ id: string;
31
+ intermediaryProvider: string;
32
+ metadata: {
33
+ feedID: string;
34
+ };
35
+ package: {
36
+ amenities: string[];
37
+ canPayLater: boolean;
38
+ };
39
+ providerCode: string;
40
+ rate: {
41
+ base: number;
42
+ taxes: number;
43
+ hotelFees: number;
44
+ };
45
+ roomName: string;
46
+ tags: string[];
47
+ url: string;
35
48
  };
36
- export declare const topOffersDataWithAnchorPriceNotMatchedRules: {
37
- anchorPrice: number;
38
- anchorPriceNightly: number;
39
- offerIndexes: number[];
49
+ export declare const offer3: {
50
+ accessTier: null;
51
+ availableRooms: number;
52
+ cancellationPenalties: never[];
53
+ currency: string;
54
+ id: string;
55
+ intermediaryProvider: string;
56
+ metadata: {
57
+ feedID: string;
58
+ };
59
+ package: {
60
+ amenities: string[];
61
+ canPayLater: boolean;
62
+ };
63
+ providerCode: string;
64
+ rate: {
65
+ base: number;
66
+ taxes: number;
67
+ hotelFees: number;
68
+ };
69
+ roomName: string;
70
+ tags: string[];
71
+ url: string;
40
72
  };
41
73
  export declare const anchorPriceRateBreakdown: {
42
- baseRate: number;
43
- calculatedTotalRate: number;
44
- localTaxes: number;
45
- nightlyRate: number;
74
+ base: number;
75
+ hotelFees: number;
46
76
  taxes: number;
47
77
  };
@@ -1,4 +1,4 @@
1
- import { CugDeals, HotelId, HotelOfferEntity, Currency, RoomId, Meals, Options as ClientOptions, UserTier, Discount } from './types';
1
+ import { CugDeals, HotelId, HotelOfferEntity, Currency, RoomId, Amenities, Options as ClientOptions, UserTier, Discount } from './types';
2
2
  interface V3RateBreakdown {
3
3
  base: number;
4
4
  hotelFees: number;
@@ -10,7 +10,6 @@ interface CancellationPenalty {
10
10
  end: string;
11
11
  start: string;
12
12
  }
13
- declare type Amenities = Meals & 'internetIncluded';
14
13
  declare type OfferTag = 'top_offer' | 'anchor_price' | 'exclusive_cheapest_offer';
15
14
  interface SapiResponseOffer {
16
15
  accessTier: string;
@@ -40,8 +39,6 @@ declare type Rooms = Record<RoomId, {
40
39
  export interface SapiResponseOfferEntity {
41
40
  anchorRate: V3RateBreakdown;
42
41
  availableOffersCount: number;
43
- fetchedAllOffers: boolean;
44
- hasMoreOffers: boolean;
45
42
  id: HotelId;
46
43
  offers: SapiResponseOffer[];
47
44
  rooms: Rooms;
@@ -71,21 +68,14 @@ export interface OffersResponse {
71
68
  export interface OffersClient {
72
69
  getOffers: (parameters: GetOffersParameters, onOffersReceived?: (response: OffersResponse) => void) => Promise<OffersResponse>;
73
70
  }
74
- export declare function hasAnchorPrice(price: number, anchorPrice: number): boolean;
75
- interface MappingContext {
76
- checkIn: string;
77
- checkOut: string;
78
- includeTaxes?: boolean;
79
- includeLocalTaxes?: boolean;
80
- }
81
- export declare function sapiResponseToHotelOfferEntity(offerEntity: SapiResponseOfferEntity, context: MappingContext): HotelOfferEntity;
82
- interface ApiConfig {
71
+ export declare function sapiResponseToHotelOfferEntity(offerEntity: SapiResponseOfferEntity): HotelOfferEntity;
72
+ interface Config {
83
73
  baseUrl: string;
84
74
  endpoints: {
85
75
  offers: string;
86
76
  };
87
77
  }
88
- export declare function offersClient(config: ApiConfig, options: ClientOptions): {
78
+ export declare function offersClient(config: Config, options: ClientOptions): {
89
79
  getOffers: (parameters: GetOffersParameters, onOffersReceived?: ((response: OffersResponse) => void) | undefined) => Promise<OffersResponse>;
90
80
  };
91
81
  export {};
@@ -1,25 +1,8 @@
1
1
  import { Except } from 'type-fest';
2
- import { DealScores, DatesConfig } from './utils';
2
+ import { DatesConfig } from './utils';
3
3
  import { OffersClient } from './offers-client';
4
4
  import { AppConfig, ProfileKey, Features } from './app-config';
5
- import { SearchParameters, HotelId, Hotel, Anchor, ApiSearchParameters, HotelOfferEntity, AnchorType, Facets, Options as ClientOptions } from './types';
6
- export interface SearchResults {
7
- anchor: Anchor;
8
- anchorHotelId?: HotelId;
9
- anchorType: AnchorType;
10
- hotelEntities: Record<HotelId, Hotel>;
11
- hotelOfferEntities: Record<HotelId, HotelOfferEntity>;
12
- hotelIds: HotelId[];
13
- searchParameters: ApiSearchParameters | SearchParameters;
14
- searchId: string;
15
- hotelsHaveStaticPosition: boolean;
16
- facets: Facets;
17
- resultsCount: number;
18
- resultsCountTotal: number;
19
- offset: number;
20
- dealScores: DealScores;
21
- hasMoreResults: boolean;
22
- }
5
+ import { SearchResults, HotelId, ApiSearchParameters, HotelOfferEntity, Options as ClientOptions } from './types';
23
6
  declare type OnStart = (response: Pick<SearchResults, 'searchId' | 'searchParameters'>) => void;
24
7
  declare type OnAnchorReceived = (response: Pick<SearchResults, 'searchId' | 'searchParameters' | 'anchor' | 'anchorHotelId' | 'anchorType'>) => void;
25
8
  declare type OnHotelsReceived = (response: Except<SearchResults, 'hotelOfferEntities'>) => void;
@@ -1,6 +1,8 @@
1
1
  export * from './types';
2
2
  export * from './rooms';
3
+ export * from './offers';
3
4
  export * from './options';
4
5
  export * from './config';
5
6
  export * from './logger';
6
7
  export * from './errors';
8
+ export * from './search';
@@ -0,0 +1,66 @@
1
+ import { CancellationPenalties, Currency } from './types';
2
+ /**
3
+ * Object contains details about the price of the Offer, the rate is divided into 3 attributes:
4
+ *
5
+ * base: The rate charged by the hotel without considering extra taxes and other fees. \
6
+ * hotelFees: The sum of all other charges, like resort fee. \
7
+ * taxes: The sum of all taxes applied to the offer.
8
+ */
9
+ export interface RateBreakdown {
10
+ base: number;
11
+ hotelFees: number;
12
+ taxes: number;
13
+ }
14
+ /**
15
+ * Available amenities within the offer
16
+ */
17
+ export declare type Amenities = 'allInclusive' | 'breakfast' | 'partialBreakfast' | 'lunch' | 'dinner' | 'fullBoard' | 'halfBoard' | 'meals' | 'internetIncluded';
18
+ /**
19
+ * Attribute indicating the minimum tier the user should be in order to be able to book this offer.
20
+ */
21
+ export declare type AccessTier = string;
22
+ /**
23
+ * Hotel's offer
24
+ */
25
+ export interface Offer {
26
+ accessTier: AccessTier;
27
+ availableRooms: number;
28
+ cancellationPenalties: CancellationPenalties[];
29
+ currency: Currency;
30
+ id: string;
31
+ intermediaryProvider: string;
32
+ metadata: {
33
+ feedID: string;
34
+ providerRateType?: string;
35
+ };
36
+ package: {
37
+ amenities: Amenities[];
38
+ canPayLater: boolean;
39
+ };
40
+ providerCode: string;
41
+ rate: RateBreakdown;
42
+ roomName?: string;
43
+ tags: string[] | null;
44
+ url: string;
45
+ }
46
+ export interface Discount {
47
+ modifier: string;
48
+ hasParityProvider: boolean;
49
+ hasDiscountProvider: boolean;
50
+ discountProvider: string;
51
+ }
52
+ /**
53
+ * Hotel offer entity contains offers array as well as meta information about offers and hotel
54
+ */
55
+ export interface HotelOfferEntity {
56
+ /** Available offers count for the requested itinerary */
57
+ availableOffersCount: number;
58
+ /** The rate of the offer tagged as anchor price offer */
59
+ anchorRate: RateBreakdown;
60
+ /** Discount - meta information used in analytics */
61
+ discount?: Discount;
62
+ /** Id of the requested hotel */
63
+ id: string;
64
+ /** Hotel's offers */
65
+ offers: Offer[];
66
+ }
@@ -4,6 +4,8 @@ import { AppConfig } from '../app-config';
4
4
  import { Configs } from './config';
5
5
  import { AnonymousId, Language, Currency, Country, DeviceType, Brand } from './types';
6
6
  import { Logger } from './logger';
7
+ import { RateBreakdown } from './offers';
8
+ export declare type GetTotalRate = (rate: RateBreakdown) => number;
7
9
  /** Options for initializing the Search API client. Persistent within single SAPI instance but may vary for different users */
8
10
  export interface ClientOptions {
9
11
  /** Unique ID identifying users */
@@ -12,18 +14,10 @@ export interface ClientOptions {
12
14
  language: Language;
13
15
  /** Currency code for selected user currency */
14
16
  currency: Currency;
15
- /** @deprecated since 0.23.0 use countryCode instead */
16
- userCountry?: Country;
17
- /** Country code for selected user origin userCountry */
17
+ /** Country code for selected user origin country */
18
18
  countryCode: Country;
19
19
  /** Displayed page size */
20
20
  pageSize?: number;
21
- /** Include or not local taxes based on localisation logic */
22
- includeLocalTaxes?: boolean;
23
- /** Include or not taxes based on localisation logic */
24
- includeTaxes?: boolean;
25
- /** @deprecated since 0.23.0 use deviceType instead */
26
- deviceCategory?: DeviceType;
27
21
  /** User's device type */
28
22
  deviceType: DeviceType;
29
23
  /** Used to identify SAPI Cli interface on the RAA backend */
@@ -44,12 +38,19 @@ export interface ClientOptions {
44
38
  };
45
39
  /** Websoket implementation */
46
40
  WebSocket?: WebSocket;
41
+ /**
42
+ * Function to calculate total display rate based on tax display logic.
43
+ * If not provided SAPI will use rate including all taxes and fees.
44
+ * Used for price filter and sort by price functionalities.
45
+ */
46
+ getTotalRate?: GetTotalRate;
47
47
  }
48
48
  /**
49
49
  * Adjusted options
50
50
  */
51
- export declare type Options = Except<ClientOptions, 'variations' | 'logger'> & {
51
+ export declare type Options = Except<ClientOptions, 'variations' | 'logger' | 'getTotalRate'> & {
52
52
  logger: Logger;
53
+ getTotalRate: GetTotalRate;
53
54
  variations: string[];
54
55
  pageSize: number;
55
56
  languages: Language[];
@@ -1,4 +1,4 @@
1
- import { HotelId, AnonymousId, Currency, RoomId, UserTier } from './types';
1
+ import { HotelId, AnonymousId, Currency, RoomId, UserTier, CancellationPenalties } from './types';
2
2
  export interface RoomsRequestParameters {
3
3
  hotelId: HotelId;
4
4
  checkIn: string;
@@ -15,12 +15,6 @@ export interface RoomsRequestParameters {
15
15
  trafficSource?: string;
16
16
  }
17
17
  export declare type RoomPackageId = string;
18
- export interface RoomCancellationPenalties {
19
- start: string;
20
- end: string;
21
- amount: number;
22
- currency: string;
23
- }
24
18
  export interface RoomLinks {
25
19
  href: string;
26
20
  method: 'GET' | 'POST';
@@ -54,7 +48,7 @@ export interface MatchedDim {
54
48
  export interface RoomOffer {
55
49
  id: string;
56
50
  availableRooms: number;
57
- cancellationPenalties: RoomCancellationPenalties[];
51
+ cancellationPenalties: CancellationPenalties[];
58
52
  cug: string[];
59
53
  extraParams: unknown;
60
54
  links: RoomLinks[];
@@ -0,0 +1,18 @@
1
+ import { HotelId, Anchor, AnchorType, Hotel, Facets, ApiSearchParameters, SearchParameters, DealScores } from './types';
2
+ import { HotelOfferEntity } from './offers';
3
+ export interface SearchResults {
4
+ anchor: Anchor;
5
+ anchorHotelId?: HotelId;
6
+ anchorType: AnchorType;
7
+ hotelEntities: Record<HotelId, Hotel>;
8
+ hotelOfferEntities: Record<HotelId, HotelOfferEntity>;
9
+ hotelIds: HotelId[];
10
+ searchParameters: ApiSearchParameters | SearchParameters;
11
+ searchId: string;
12
+ hotelsHaveStaticPosition: boolean;
13
+ facets: Facets;
14
+ resultsCount: number;
15
+ resultsCountTotal: number;
16
+ offset: number;
17
+ dealScores: DealScores;
18
+ }
@@ -4,14 +4,36 @@
4
4
  * @default new UUID
5
5
  */
6
6
  export declare type AnonymousId = string;
7
+ /**
8
+ * 3-char uppercased ISO currency code
9
+ */
7
10
  export declare type Currency = string;
11
+ /**
12
+ * ISO language code
13
+ */
8
14
  export declare type Language = string;
15
+ /**
16
+ * 2-char uppercased ISO country code
17
+ */
9
18
  export declare type Country = string;
10
19
  export declare type DateString = string;
11
20
  export declare type DeviceType = 'desktop' | 'mobile' | 'tablet';
12
21
  export declare type CugDeals = string[];
13
22
  export declare type UserTier = string;
14
23
  export declare type Brand = string;
24
+ /**
25
+ * Cancellation penalties
26
+ * used to calculate the refund amount in case of a booking cancellation,
27
+ * reflecting the cancellation information that was informed to the customers when they made their reservation.
28
+ *
29
+ * https://engdocs.fih.io/engineering/cancellation_penalties/
30
+ */
31
+ export interface CancellationPenalties {
32
+ amount: number;
33
+ currency: string;
34
+ end: string;
35
+ start: string;
36
+ }
15
37
  /**
16
38
  * Search client types
17
39
  */
@@ -142,7 +164,10 @@ export interface HotelSuggestHit extends BasicSuggestHit {
142
164
  };
143
165
  }
144
166
  export declare type SuggestHit = HotelSuggestHit | PlaceSuggestHit;
145
- /** Search Hit */
167
+ export interface DatelessProviderLink {
168
+ provider: string;
169
+ url: string;
170
+ }
146
171
  export interface Hit {
147
172
  address: TranslatedString;
148
173
  checkInTime: string;
@@ -153,6 +178,7 @@ export interface Hit {
153
178
  guestType: GuestType;
154
179
  hotelName: TranslatedString;
155
180
  imageURIs: string[];
181
+ urls?: DatelessProviderLink[];
156
182
  isDeleted: boolean;
157
183
  lastBooked: number;
158
184
  objectID: string;
@@ -247,91 +273,5 @@ export interface Suggestion {
247
273
  }
248
274
  export declare type HotelId = Hotel['objectID'];
249
275
  export declare type RoomId = string;
250
- /**
251
- * RAA types
252
- */
253
- export interface RateBreakdown {
254
- baseRate: number;
255
- localTaxes: number;
256
- taxes: number;
257
- }
258
- export interface AnchorPriceRateBreakdown extends RateBreakdown {
259
- calculatedTotalRate: number;
260
- nightlyRate: number;
261
- }
262
- export interface TopOfferData {
263
- anchorPrice?: number;
264
- anchorPriceNightly?: number;
265
- offerIndexes: number[];
266
- }
267
- export declare type Meals = 'allInclusive' | 'breakfast' | 'partialBreakfast' | 'lunch' | 'dinner' | 'fullBoard' | 'halfBoard' | 'meals';
268
- export interface Offer {
269
- additionalProviderParams: {
270
- feedId: string;
271
- rateType?: string;
272
- };
273
- id: string;
274
- bookURI: string;
275
- providerCode: string;
276
- proxyProviderCode: string;
277
- rateBreakdown: RateBreakdown;
278
- nightlyRate: number;
279
- calculatedTotalRate: number;
280
- availableRooms: number;
281
- cug: string[] | null;
282
- currency: Currency;
283
- meals: Meals[];
284
- tags: string[];
285
- canPayLater?: boolean;
286
- hasAnchorPrice?: boolean;
287
- hasFreeCancellation?: boolean;
288
- integrationType?: string;
289
- isAnchorPriceOffer?: boolean;
290
- isCheapest?: boolean;
291
- isSharedRoom?: boolean;
292
- isTopOffer?: boolean;
293
- packageID?: string;
294
- providerHotelId?: string;
295
- roomID?: string;
296
- roomName?: string;
297
- rateBasedOnNumberOfRooms?: number;
298
- feedId?: string;
299
- providerOfferId?: string;
300
- rateType?: string;
301
- }
302
- export interface RaaResponseOffer {
303
- availableOffersCount: number;
304
- anchorPriceRateBreakdown?: AnchorPriceRateBreakdown;
305
- cheapestPriceRateBreakdown?: RateBreakdown;
306
- fetchedAllOffers: boolean;
307
- hasMoreOffers: boolean;
308
- id: string;
309
- offers: Offer[];
310
- topOfferData?: TopOfferData;
311
- errors: Array<Record<string, number | string>>;
312
- }
313
- export interface HotelOfferEntity {
314
- availableOffersCount: number;
315
- anchorPriceRateBreakdown?: AnchorPriceRateBreakdown;
316
- cheapestPriceRateBreakdown?: RateBreakdown;
317
- fetchedAllOffers: boolean;
318
- hasMoreOffers: boolean;
319
- id: string;
320
- offers: Offer[];
321
- topOfferData?: TopOfferData;
322
- discount?: Discount;
323
- }
324
- export interface Discount {
325
- modifier: string;
326
- hasParityProvider: boolean;
327
- hasDiscountProvider: boolean;
328
- discountProvider: string;
329
- }
330
- export interface RaaResponse {
331
- errors: any[];
332
- results: RaaResponseOffer[];
333
- status: {
334
- complete: boolean;
335
- };
336
- }
276
+ export declare type DealScores = Record<HotelId, number>;
337
277
  export {};
@@ -1,6 +1,8 @@
1
1
  import { OffersResponse } from '../offers-client';
2
- import { HotelOfferEntity, Offer } from '../types';
2
+ import { HotelOfferEntity, GetTotalRate } from '../types';
3
3
  interface Parameters {
4
+ checkIn: string;
5
+ checkOut: string;
4
6
  sortField?: string;
5
7
  sortOrder?: string;
6
8
  filters?: {
@@ -10,10 +12,11 @@ interface Parameters {
10
12
  priceBucketWidth?: number;
11
13
  priceBucketsCount: number;
12
14
  exchangeRate: number;
13
- variations?: string[];
15
+ getTotalRate: GetTotalRate;
14
16
  }
15
- export declare function isOfferInPriceRange(offer: Offer, upperBound: number, priceMin?: number, priceMax?: number): boolean;
17
+ export declare function isRateInPriceRange(rate: number, upperBound: number, priceMin?: number, priceMax?: number): boolean;
16
18
  export declare function applyPriceFilter(parameters: Parameters, hotelOfferEntity: HotelOfferEntity): HotelOfferEntity;
19
+ export declare function applySort(hotelOfferEntity: HotelOfferEntity[], parameters: Parameters): HotelOfferEntity[];
17
20
  export declare function buildOffersResponse(offersResults: OffersResponse, parameters: Parameters): {
18
21
  hotelIds: string[];
19
22
  hotelOfferEntities: Record<string, HotelOfferEntity>;
@@ -1,7 +1,7 @@
1
- import { HotelOfferEntity } from '../types';
1
+ import { HotelOfferEntity, GetTotalRate } from '../types';
2
2
  /**
3
3
  * Returns cheapest display rate for provided hotel offer entity
4
4
  *
5
5
  * @param hotelOfferEntity
6
6
  */
7
- export declare function getCheapestRate(hotelOfferEntity: HotelOfferEntity): number | undefined;
7
+ export declare function getCheapestRate(hotelOfferEntity: HotelOfferEntity, getTotalRate: GetTotalRate): number | undefined;
@@ -1,5 +1,4 @@
1
- import { HotelId, HotelOfferEntity, Hotel } from '../types';
2
- export declare type DealScores = Record<HotelId, number>;
1
+ import { HotelId, HotelOfferEntity, Hotel, DealScores, SearchParameters } from '../types';
3
2
  declare type DealScoreInput = [
4
3
  hotelId: HotelId,
5
4
  rate?: number,
@@ -20,6 +19,7 @@ export interface DealScoreParameters {
20
19
  hotelIds: HotelId[];
21
20
  hotelEntities: Record<HotelId, Hotel>;
22
21
  hotelOfferEntities: Record<HotelId, HotelOfferEntity>;
22
+ searchParameters: SearchParameters;
23
23
  }
24
24
  /**
25
25
  * Returns deal scores for provided hotels and offers
@@ -28,5 +28,5 @@ export interface DealScoreParameters {
28
28
  *
29
29
  * @returns DealScores - number in 0 to 1 range
30
30
  */
31
- export declare function getDealScores({ offset, anchorHotelId, hotelIds, hotelEntities, hotelOfferEntities, }: DealScoreParameters): DealScores;
31
+ export declare function getDealScores({ offset, anchorHotelId, hotelIds, hotelEntities, hotelOfferEntities, searchParameters, }: DealScoreParameters): DealScores;
32
32
  export {};
@@ -0,0 +1,8 @@
1
+ import { RateBreakdown } from '../types/offers';
2
+ /**
3
+ * Deafault funtion for calculating total rate
4
+ *
5
+ * @param rate - offer's rate breakdown
6
+ * @returns - total rate
7
+ */
8
+ export declare function getTotalRate(rate: RateBreakdown): number;
@@ -11,3 +11,4 @@ export * from './sorting-boosts';
11
11
  export * from './build-offers-response';
12
12
  export * from './algolia';
13
13
  export * from './search-parameters';
14
+ export * from './get-total-rate';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@findhotel/sapi",
3
- "version": "0.26.6",
3
+ "version": "1.0.0",
4
4
  "description": "FindHotel Search API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types/packages/core/src",