@findhotel/sapi 0.24.0 → 0.24.3

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,4 +1,4 @@
1
- import { ProfileKey, IndexVariation } from './types';
1
+ 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';
2
2
  export declare type Features = 'offers' | 'search' | 'suggests' | 'configs' | 'rooms' | 'get-hotel';
3
3
  export interface AppConfig {
4
4
  sapiBackend: {
@@ -20,11 +20,7 @@ export interface AppConfig {
20
20
  algolia: {
21
21
  appId: string;
22
22
  apiKey: string;
23
- hotelIndex: string;
24
23
  autocompleteIndex: string;
25
- lovIndex: string;
26
- currencyIndex: string;
27
- hsoIndex: IndexVariation[];
28
24
  };
29
25
  client: {
30
26
  defaultRooms: string;
@@ -1,5 +1,5 @@
1
- import { Base } from '.';
2
- import { Language, HotelId, TranslatedString, GuestRating, GuestType, Location, TranslatedArray, Pricing, ContentHotel, LOVItem, Currency } from './types';
1
+ import { Language, HotelId, TranslatedString, GuestRating, GuestType, Location, TranslatedArray, Pricing, ContentHotel, LOVItem, Currency, Options as ClientOptions } from './types';
2
+ import { AppConfig } from './app-config';
3
3
  export interface SafHotel {
4
4
  objectID: HotelId;
5
5
  _geoloc: Location;
@@ -50,6 +50,10 @@ export declare function safToSapiHotel(safHotel: SafHotel, languages: Language[]
50
50
  * @returns request string
51
51
  */
52
52
  export declare function createRequestString(hotelId: HotelId, languages: Language[]): string;
53
+ export interface Parameters {
54
+ appConfig: AppConfig;
55
+ options: ClientOptions;
56
+ }
53
57
  /**
54
58
  * Creates hotel function with binded in configuration object
55
59
  *
@@ -57,4 +61,4 @@ export declare function createRequestString(hotelId: HotelId, languages: Languag
57
61
  *
58
62
  * @returns function that asynchronously returns hotel's content by hotelId
59
63
  */
60
- export declare function hotel({ appConfig, options }: Pick<Base, 'options' | 'appConfig'>): HotelHandler;
64
+ export declare function hotel({ appConfig, options }: Parameters): HotelHandler;
@@ -1,4 +1,3 @@
1
- import { sapi } from './sapi';
2
1
  export * from './sapi';
3
2
  export * from './types';
4
- export default sapi;
3
+ export { sapi as default } from './sapi';
@@ -1,4 +1,4 @@
1
- import { CugDeals, HotelId, HotelOfferEntity, Brand, Currency, DeviceType, RoomId, Meals, Logger } from './types';
1
+ import { CugDeals, HotelId, HotelOfferEntity, Currency, RoomId, Meals, Options as ClientOptions, UserTier } from './types';
2
2
  interface V3RateBreakdown {
3
3
  base: number;
4
4
  hotelFees: number;
@@ -49,26 +49,11 @@ export interface SapiResponseOfferEntity {
49
49
  offers: SapiResponseOffer[];
50
50
  rooms: Rooms;
51
51
  }
52
- interface Options {
53
- brand?: Brand;
54
- anonymousId: string;
55
- currency: string;
56
- countryCode: string;
57
- language: string;
58
- includeLocalTaxes?: boolean;
59
- includeTaxes?: boolean;
60
- skipBackendAugmentation?: boolean;
61
- facetsEnabled?: boolean;
62
- WebSocket?: any;
63
- sapiCliKey?: string;
64
- deviceType: DeviceType;
65
- variations: string[];
66
- logger: Logger;
67
- }
68
52
  export interface GetOffersParameters {
69
53
  anchorHotelId?: HotelId;
70
54
  hotelIds?: HotelId[];
71
55
  cugDeals?: CugDeals;
56
+ tier?: UserTier;
72
57
  getAllOffers?: boolean;
73
58
  originId?: string;
74
59
  checkIn: string;
@@ -102,7 +87,7 @@ interface ApiConfig {
102
87
  offers: string;
103
88
  };
104
89
  }
105
- export declare function offersClient(config: ApiConfig, options: Options): {
90
+ export declare function offersClient(config: ApiConfig, options: ClientOptions): {
106
91
  getOffers: (parameters: GetOffersParameters, onOffersReceived?: ((response: OffersResponse) => void) | undefined) => Promise<OffersResponse>;
107
92
  };
108
93
  export {};
@@ -1,6 +1,5 @@
1
- import { Base } from '.';
2
- import { GetOffersParameters } from './offers-client';
3
- import { HotelId, HotelOfferEntity, CugDeals } from './types';
1
+ import { OffersClient, GetOffersParameters } from './offers-client';
2
+ import { HotelId, HotelOfferEntity, CugDeals, UserTier } from './types';
4
3
  import { AppConfig } from './app-config';
5
4
  interface OffersParameters {
6
5
  hotelId: HotelId;
@@ -9,6 +8,7 @@ interface OffersParameters {
9
8
  rooms: string;
10
9
  searchId?: string;
11
10
  cugDeals?: CugDeals;
11
+ tier?: UserTier;
12
12
  isAnchor?: boolean;
13
13
  getAllOffers?: boolean;
14
14
  originId?: string;
@@ -22,7 +22,11 @@ interface Callbacks {
22
22
  onComplete?: (response: HotelOfferEntity | undefined) => void;
23
23
  }
24
24
  export declare type OffersHandler = (parameters: OffersParameters, callbacks: Callbacks) => Promise<HotelOfferEntity | undefined>;
25
- export declare function getOffersParameters(parameters: OffersParameters, options: Base['options'], appConfig: AppConfig): GetOffersParameters;
25
+ export declare function getOffersParameters(parameters: OffersParameters, appConfig: AppConfig): GetOffersParameters;
26
+ export interface Parameters {
27
+ appConfig: AppConfig;
28
+ offersClient?: OffersClient;
29
+ }
26
30
  /**
27
31
  * Creates offers function with configuration object
28
32
  *
@@ -30,5 +34,5 @@ export declare function getOffersParameters(parameters: OffersParameters, option
30
34
  *
31
35
  * @returns function for fetching offers
32
36
  */
33
- export declare function offers({ offersClient, options, appConfig }: Pick<Base, 'offersClient' | 'options' | 'appConfig'>): OffersHandler;
37
+ export declare function offers({ offersClient, appConfig }: Parameters): OffersHandler;
34
38
  export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Get sapi override parameter directly from the URL. Used only for debugging purposes.
3
+ */
4
+ export declare function getSapiOverrideParameter(): string | null | undefined;
@@ -1,5 +1,5 @@
1
- import { Base } from '.';
2
- import { RoomsRequestParameters, RoomsRequestOptions, RoomsResults } from './types';
1
+ import { RoomsRequestParameters, RoomsResults, Options as ClientOptions } from './types';
2
+ import { AppConfig } from './app-config';
3
3
  export declare type RoomsHandler = (parameters: RoomsRequestParameters) => Promise<RoomsResults>;
4
4
  /**
5
5
  * Creates rooms request string.
@@ -30,7 +30,11 @@ export declare type RoomsHandler = (parameters: RoomsRequestParameters) => Promi
30
30
  * ```
31
31
  *
32
32
  */
33
- export declare function createRequestString(parameters: RoomsRequestParameters, options: RoomsRequestOptions): string;
33
+ export declare function createRequestString(parameters: RoomsRequestParameters, options: ClientOptions): string;
34
+ export interface Parameters {
35
+ appConfig: AppConfig;
36
+ options: ClientOptions;
37
+ }
34
38
  /**
35
39
  * Creates rooms search function with binded base configuration object
36
40
  *
@@ -38,4 +42,4 @@ export declare function createRequestString(parameters: RoomsRequestParameters,
38
42
  *
39
43
  * @returns rooms search function
40
44
  */
41
- export declare function rooms({ appConfig, options }: Pick<Base, 'options' | 'appConfig'>): RoomsHandler;
45
+ export declare function rooms({ appConfig, options }: Parameters): RoomsHandler;
@@ -1,30 +1,23 @@
1
- import { Except } from 'type-fest';
2
- import { OffersClient } from './offers-client';
3
- import { AppConfig, Features } from './app-config';
4
- import { ProfileKey, ClientOptions, SapiClient, Language, Logger } from './types';
5
- export interface Base {
6
- /** SAPI client application config */
7
- appConfig: AppConfig;
8
- /** Check if SAPI feature is enabled */
9
- getFeatureEnabled: (feature: Features) => boolean;
10
- /** Instance of Offers Client */
11
- offersClient?: OffersClient;
12
- /** Profile key of specific client */
13
- profileKey: ProfileKey;
14
- /** Options persistent within single SAPI instance */
15
- options: Except<ClientOptions, 'variations' | 'logger'> & {
16
- logger: Logger;
17
- variations: string[];
18
- pageSize: number;
19
- languages: Language[];
20
- };
21
- }
1
+ import { ProfileKey } from './app-config';
2
+ import { SearchHandler } from './search';
3
+ import { SuggestHandler } from './suggest';
4
+ import { RoomsHandler } from './rooms';
5
+ import { HotelHandler } from './hotel';
6
+ import { OffersHandler } from './offers';
7
+ import { ClientOptions } from './types';
22
8
  /**
23
9
  * Converts map of A/B tests variations to array of string
24
10
  *
25
11
  * @param variations - variations map
26
12
  */
27
13
  export declare function variationsToArray(variations?: Record<string, string>): string[];
14
+ export interface SapiClient {
15
+ rooms: RoomsHandler;
16
+ search: SearchHandler;
17
+ suggest: SuggestHandler;
18
+ hotel: HotelHandler;
19
+ offers: OffersHandler;
20
+ }
28
21
  /**
29
22
  * SAPI constructor
30
23
  *
@@ -1,8 +1,8 @@
1
1
  import { Except } from 'type-fest';
2
- import { Base, ProfileKey } from '.';
3
2
  import { DealScores, DatesConfig } from './utils';
4
- import { SearchParameters, HotelId, Hotel, Anchor, ApiSearchParameters, HotelOfferEntity, AnchorType, Facets } from './types';
5
- export declare type SearchFnParameters = Pick<Base, 'profileKey' | 'options' | 'appConfig' | 'offersClient' | 'getFeatureEnabled'>;
3
+ import { OffersClient } from './offers-client';
4
+ import { AppConfig, ProfileKey, Features } from './app-config';
5
+ import { SearchParameters, HotelId, Hotel, Anchor, ApiSearchParameters, HotelOfferEntity, AnchorType, Facets, Options as ClientOptions } from './types';
6
6
  export interface SearchResults {
7
7
  anchor: Anchor;
8
8
  anchorHotelId?: HotelId;
@@ -36,23 +36,30 @@ export declare type SearchHandler = (parameters: ApiSearchParameters, callbacks?
36
36
  loadMore: () => Promise<SearchResults>;
37
37
  }>;
38
38
  export declare function prepareSearchParameters(parameters: ApiSearchParameters, dates: DatesConfig): SearchParameters;
39
- declare type AttributesToRetrieve = keyof SearchResults;
40
- interface SearchRequestParameters {
39
+ export declare type AttributesToRetrieve = keyof SearchResults;
40
+ export interface SearchRequestParameters {
41
41
  searchId: string;
42
42
  profileKey: ProfileKey;
43
43
  searchParameters: SearchParameters;
44
- options: Base['options'];
44
+ options: ClientOptions;
45
45
  offset: number;
46
46
  attributes?: AttributesToRetrieve[];
47
47
  }
48
- export declare function createSearchRequestString({ profileKey, searchId, searchParameters, options, offset, attributes }: SearchRequestParameters): string;
48
+ export declare function createSearchRequestString({ profileKey, searchId, searchParameters, options, offset, attributes, }: SearchRequestParameters): string;
49
49
  interface AnchorRequestParameters {
50
50
  searchId: string;
51
51
  profileKey: ProfileKey;
52
52
  searchParameters: SearchParameters;
53
- options: Base['options'];
53
+ options: ClientOptions;
54
54
  attributes?: AttributesToRetrieve[];
55
55
  }
56
- export declare function createAnchorRequestString({ profileKey, searchId, searchParameters, options, attributes }: AnchorRequestParameters): string;
57
- export declare function search({ getFeatureEnabled, profileKey, appConfig, offersClient, options }: SearchFnParameters): SearchHandler;
56
+ export declare function createAnchorRequestString({ profileKey, searchId, searchParameters, options, attributes, }: AnchorRequestParameters): string;
57
+ export interface Parameters {
58
+ appConfig: AppConfig;
59
+ profileKey: ProfileKey;
60
+ offersClient?: OffersClient;
61
+ getFeatureEnabled: (feature: Features) => boolean;
62
+ options: ClientOptions;
63
+ }
64
+ export declare function search({ getFeatureEnabled, profileKey, appConfig, offersClient, options, }: Parameters): SearchHandler;
58
65
  export {};
@@ -1,4 +1,9 @@
1
- import { Base } from '.';
2
- import { Suggestion } from './types';
1
+ import { Suggestion, Options as ClientOptions } from './types';
2
+ import { AppConfig } from './app-config';
3
+ interface Parameters {
4
+ appConfig: AppConfig;
5
+ options: ClientOptions;
6
+ }
3
7
  export declare type SuggestHandler = (query: string, suggestsCount?: number) => Promise<Suggestion[]>;
4
- export declare function suggest(base: Base): SuggestHandler;
8
+ export declare function suggest({ appConfig, options }: Parameters): SuggestHandler;
9
+ export {};
@@ -1,4 +1,5 @@
1
1
  export * from './types';
2
2
  export * from './rooms';
3
- export * from './sapi-client';
3
+ export * from './options';
4
4
  export * from './config';
5
+ export * from './logger';
@@ -0,0 +1,8 @@
1
+ interface Event {
2
+ name: string;
3
+ value: any;
4
+ }
5
+ export interface Logger {
6
+ log: (event: Event) => void;
7
+ }
8
+ export {};
@@ -1,27 +1,9 @@
1
+ import { Except } from 'type-fest';
1
2
  import { AlgoliaSearchOptions } from 'algoliasearch';
2
- import { AnonymousId, Language, Currency, Country, DeviceType, Brand } from './types';
3
- import { Configs } from './config';
4
3
  import { AppConfig } from '../app-config';
5
- import { SearchHandler } from '../search';
6
- import { RoomsHandler } from '../rooms';
7
- import { HotelHandler } from '../hotel';
8
- import { SuggestHandler } from '../suggest';
9
- import { OffersHandler } from '../offers';
10
- 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';
11
- interface Event {
12
- name: string;
13
- value: any;
14
- }
15
- export interface Logger {
16
- log: (event: Event) => void;
17
- }
18
- export interface SapiClient {
19
- rooms: RoomsHandler;
20
- search: SearchHandler;
21
- suggest: SuggestHandler;
22
- hotel: HotelHandler;
23
- offers: OffersHandler;
24
- }
4
+ import { Configs } from './config';
5
+ import { AnonymousId, Language, Currency, Country, DeviceType, Brand } from './types';
6
+ import { Logger } from './logger';
25
7
  /** Options for initializing the Search API client. Persistent within single SAPI instance but may vary for different users */
26
8
  export interface ClientOptions {
27
9
  /** Unique ID identifying users */
@@ -60,5 +42,15 @@ export interface ClientOptions {
60
42
  callbacks?: {
61
43
  onConfigReceived?: (config: Pick<Configs, 'lov' | 'exchangeRates'>) => void;
62
44
  };
45
+ /** Websoket implementation */
46
+ WebSocket?: WebSocket;
63
47
  }
64
- export {};
48
+ /**
49
+ * Adjusted options
50
+ */
51
+ export declare type Options = Except<ClientOptions, 'variations' | 'logger'> & {
52
+ logger: Logger;
53
+ variations: string[];
54
+ pageSize: number;
55
+ languages: Language[];
56
+ };
@@ -1,4 +1,4 @@
1
- import { HotelId, AnonymousId, Currency, Language, DeviceType, RoomId } from './types';
1
+ import { HotelId, AnonymousId, Currency, RoomId, UserTier } from './types';
2
2
  export interface RoomsRequestParameters {
3
3
  hotelId: HotelId;
4
4
  checkIn: string;
@@ -6,15 +6,9 @@ export interface RoomsRequestParameters {
6
6
  rooms: string;
7
7
  providerCode?: string;
8
8
  cugDeals?: string;
9
+ tier?: UserTier;
9
10
  clickedOfferId?: string;
10
11
  }
11
- export interface RoomsRequestOptions {
12
- deviceType: DeviceType;
13
- language: Language;
14
- currency: Currency;
15
- anonymousId: AnonymousId;
16
- variations: string[];
17
- }
18
12
  export declare type RoomPackageId = string;
19
13
  export interface RoomCancellationPenalties {
20
14
  start: string;
@@ -57,6 +51,7 @@ export interface RoomOffer {
57
51
  canPayLater: boolean;
58
52
  services: string[];
59
53
  isClicked?: boolean;
54
+ matchType?: 'exact' | 'partial';
60
55
  }
61
56
  export interface RoomImage {
62
57
  url: string;
@@ -1,8 +1,3 @@
1
- export interface IndexVariation {
2
- name: string;
3
- objectID?: string;
4
- variationID?: string;
5
- }
6
1
  /**
7
2
  * Unique ID identifying users
8
3
  *
@@ -15,6 +10,7 @@ export declare type Country = string;
15
10
  export declare type DateString = string;
16
11
  export declare type DeviceType = 'desktop' | 'mobile' | 'tablet';
17
12
  export declare type CugDeals = string[];
13
+ export declare type UserTier = string;
18
14
  export declare type Brand = string;
19
15
  /**
20
16
  * Search client types
@@ -50,6 +46,7 @@ export interface OptionalSearchParameters {
50
46
  boundingBox?: BoundingBox;
51
47
  polygon?: Polygon;
52
48
  cugDeals?: CugDeals;
49
+ tier?: UserTier;
53
50
  originId?: string;
54
51
  searchId?: string;
55
52
  skipGeoSearch?: boolean;
@@ -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, }: DealScoreParameters): DealScores;
32
32
  export {};
@@ -1,15 +1,4 @@
1
- import { AnonymousId, ApiSearchParameters, Country, Currency, Language } from '../types';
2
- interface SearchIdOptions {
3
- anonymousId: AnonymousId;
4
- language: Language;
5
- currency: Currency;
6
- countryCode: Country;
7
- }
8
1
  /**
9
- * Generates a deterministic hash of a combination of ApiSearchParameters and SAPI options.
10
- *
11
- * @param parameters all relevant search parameters to generate an id
12
- * @param options SAPI options used to generate an id
2
+ * Generates a random searchId string
13
3
  */
14
- export declare function generateSearchId(parameters: ApiSearchParameters, options: SearchIdOptions): string;
15
- export {};
4
+ export declare function generateSearchId(): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@findhotel/sapi",
3
- "version": "0.24.0",
3
+ "version": "0.24.3",
4
4
  "description": "FindHotel Search API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types/packages/core/src",
@@ -18,17 +18,19 @@
18
18
  "lerna:bootstrap": "lerna bootstrap",
19
19
  "lerna:publish": "lerna publish",
20
20
  "test": "lerna run test",
21
- "test:watch": "lerna run test:watch",
22
21
  "rollup": "rollup -c",
23
- "rollup:watch": "npm run clean:dist && tsc --outDir dist/lib --declarationDir dist/types --declaration true --emitDeclarationOnly && rollup -c --watch",
24
22
  "typedoc": "lerna run typedoc",
25
23
  "typedoc:publish": " aws s3 cp packages/core/docs/ s3://fh-search/metrics/sapi/typedoc --recursive",
26
24
  "typescript": "tsc",
27
25
  "typescript:watch": "tsc --watch",
28
- "install:all": "cd packages/core && npm install && cd ../playground && npm install && cd ../cli && npm install && cd ../../ && npm install",
29
- "playground": "cd packages/playground && npm run dev",
26
+ "install:all": "cd packages/core && npm install && cd ../playground && npm install && cd ../cli && npm install && cd ../webclient && npm install && cd ../../ && npm install",
30
27
  "webclient:start": "cd packages/webclient && npm start",
31
28
  "webclient:build": "cd packages/core && npm install && cd ../../ npm run build && cd packages/webclient && npm run build",
29
+ "playground:start": "cd packages/playground && npm run dev",
30
+ "core:dev": "npm run clean:dist && tsc --outDir dist/lib --declarationDir dist/types --declaration true --emitDeclarationOnly && rollup -c --watch",
31
+ "core:test": "cd packages/core && npm run test",
32
+ "core:xo:report": "xo packages/core/src/*.{ts,js,json}",
33
+ "core:xo:fix": "xo packages/core/src/*.{ts,js,json} --fix",
32
34
  "release": "shipjs prepare"
33
35
  },
34
36
  "repository": {
@@ -45,23 +47,24 @@
45
47
  "@rollup/plugin-commonjs": "^16.0.0",
46
48
  "@rollup/plugin-node-resolve": "^10.0.0",
47
49
  "@rollup/plugin-typescript": "^6.1.0",
50
+ "@types/jest": "^28.1.6",
48
51
  "eslint-config-xo-react": "^0.23.0",
49
- "eslint-plugin-jest": "^24.1.3",
50
- "eslint-plugin-react": "^7.28.0",
51
- "eslint-plugin-react-hooks": "^4.2.0",
52
+ "eslint-plugin-jest": "^26.6.0",
53
+ "eslint-plugin-react": "^7.30.1",
54
+ "eslint-plugin-react-hooks": "^4.6.0",
52
55
  "husky": "^5.0.6",
53
- "jest": "^26.6.3",
56
+ "jest": "^28.1.3",
54
57
  "lerna": "^4.0.0",
55
58
  "rollup": "^2.33.3",
56
59
  "rollup-plugin-cleanup": "^3.2.1",
57
60
  "rollup-plugin-terser": "^7.0.2",
58
61
  "rollup-plugin-visualizer": "^5.5.0",
59
62
  "shipjs": "^0.24.3",
60
- "ts-jest": "^26.4.4",
63
+ "ts-jest": "^28.0.7",
61
64
  "tslib": "^2.3.1",
62
65
  "type-fest": "^0.20.2",
63
66
  "typedoc": "^0.22.13",
64
67
  "typescript": "^4.1.2",
65
- "xo": "^0.39.1"
68
+ "xo": "^0.50.0"
66
69
  }
67
70
  }