@admin-layout/tailwind-travel-pro 12.2.5-alpha.29 → 12.2.5-alpha.35
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/lib/config/__tests__/env-config.test.d.ts +2 -0
- package/lib/config/__tests__/env-config.test.d.ts.map +1 -0
- package/lib/config/env-config.d.ts +0 -7
- package/lib/config/env-config.d.ts.map +1 -1
- package/lib/config/env-config.js +0 -26
- package/lib/config/env-config.js.map +1 -1
- package/lib/middlewares/__tests__/unavailableDatasource.test.d.ts +2 -0
- package/lib/middlewares/__tests__/unavailableDatasource.test.d.ts.map +1 -0
- package/lib/middlewares/airbnbDatasourcesMiddleware.d.ts +5 -2
- package/lib/middlewares/airbnbDatasourcesMiddleware.d.ts.map +1 -1
- package/lib/middlewares/airbnbDatasourcesMiddleware.js +5 -123
- package/lib/middlewares/airbnbDatasourcesMiddleware.js.map +1 -1
- package/lib/middlewares/bookingCarRentalMiddleware.d.ts +5 -2
- package/lib/middlewares/bookingCarRentalMiddleware.d.ts.map +1 -1
- package/lib/middlewares/bookingCarRentalMiddleware.js +5 -111
- package/lib/middlewares/bookingCarRentalMiddleware.js.map +1 -1
- package/lib/middlewares/bookingDatasourcesMiddleware.d.ts +5 -3
- package/lib/middlewares/bookingDatasourcesMiddleware.d.ts.map +1 -1
- package/lib/middlewares/bookingDatasourcesMiddleware.js +5 -139
- package/lib/middlewares/bookingDatasourcesMiddleware.js.map +1 -1
- package/lib/middlewares/pricelineDatasourcesMiddleware.d.ts +5 -3
- package/lib/middlewares/pricelineDatasourcesMiddleware.d.ts.map +1 -1
- package/lib/middlewares/pricelineDatasourcesMiddleware.js +5 -97
- package/lib/middlewares/pricelineDatasourcesMiddleware.js.map +1 -1
- package/lib/middlewares/unavailableDatasource.d.ts +34 -0
- package/lib/middlewares/unavailableDatasource.d.ts.map +1 -0
- package/lib/middlewares/unavailableDatasource.js +50 -0
- package/lib/middlewares/unavailableDatasource.js.map +1 -0
- package/package.json +9 -9
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-config.test.d.ts","sourceRoot":"","sources":["../../../src/config/__tests__/env-config.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
export declare const config: Readonly<{
|
|
2
2
|
ENABLE_PROPERTY_PRICE_COMPARISON: boolean;
|
|
3
3
|
SCROLL_THRESHOLD: string;
|
|
4
|
-
BOOKING_CAR_RENTAL_API_KEY: string;
|
|
5
|
-
AIRBNB_API_KEY: string;
|
|
6
|
-
BOOKING_COM_API_KEY: string;
|
|
7
4
|
SEARCH_LAYOUT: string;
|
|
8
5
|
GOOGLE_MAPS_API_KEY: string;
|
|
9
6
|
PROPERTY_SEARCH_DEFAULT_PAGE_SIZE: number;
|
|
10
7
|
PROPERTY_COUPONS_DEFAULT_PAGE_SIZE: number;
|
|
11
8
|
DEFAULT_NEARBY_PROPERTY_RADIUS: number;
|
|
12
|
-
AIRBNB_DEFAULT_TOTAL_PAGES: number;
|
|
13
|
-
BOOKING_COM_DEFAULT_PAGE_SIZE: number;
|
|
14
|
-
PRICELINE_API_KEY: string;
|
|
15
9
|
DEFAULT_COORDINATES: string;
|
|
16
10
|
GOOGLE_ANALYTICS_ID: string;
|
|
17
|
-
RAPID_API_KEY: string;
|
|
18
11
|
} & import("envalid").CleanedEnvAccessors>;
|
|
19
12
|
//# sourceMappingURL=env-config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env-config.d.ts","sourceRoot":"","sources":["../../src/config/env-config.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,MAAM
|
|
1
|
+
{"version":3,"file":"env-config.d.ts","sourceRoot":"","sources":["../../src/config/env-config.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,MAAM;;;;;;;;;;0CAuBjB,CAAC"}
|
package/lib/config/env-config.js
CHANGED
|
@@ -14,18 +14,6 @@ const config = cleanEnv(env, {
|
|
|
14
14
|
default: defaultScrollThreshold,
|
|
15
15
|
desc: 'Scroll threshold configuration'
|
|
16
16
|
}),
|
|
17
|
-
BOOKING_CAR_RENTAL_API_KEY: str({
|
|
18
|
-
default: '',
|
|
19
|
-
desc: 'Booking car rental API key'
|
|
20
|
-
}),
|
|
21
|
-
AIRBNB_API_KEY: str({
|
|
22
|
-
default: '',
|
|
23
|
-
desc: 'Airbnb API key'
|
|
24
|
-
}),
|
|
25
|
-
BOOKING_COM_API_KEY: str({
|
|
26
|
-
default: '',
|
|
27
|
-
desc: 'Booking com API key'
|
|
28
|
-
}),
|
|
29
17
|
SEARCH_LAYOUT: str({
|
|
30
18
|
default: '/search',
|
|
31
19
|
desc: 'Layout Search route'
|
|
@@ -46,25 +34,11 @@ const config = cleanEnv(env, {
|
|
|
46
34
|
// The value is in meter so its actually 100 miles
|
|
47
35
|
desc: 'Sets the default distance for searching nearby properties'
|
|
48
36
|
}),
|
|
49
|
-
AIRBNB_DEFAULT_TOTAL_PAGES: num({
|
|
50
|
-
default: 8,
|
|
51
|
-
desc: 'Number of property to fetch in each request'
|
|
52
|
-
}),
|
|
53
|
-
BOOKING_COM_DEFAULT_PAGE_SIZE: num({
|
|
54
|
-
default: 20,
|
|
55
|
-
desc: 'Number of property to fetch in each request'
|
|
56
|
-
}),
|
|
57
|
-
PRICELINE_API_KEY: str({
|
|
58
|
-
default: ''
|
|
59
|
-
}),
|
|
60
37
|
DEFAULT_COORDINATES: str({
|
|
61
38
|
default: '{"lat":40.7127281,"lng":-74.0060152}',
|
|
62
39
|
desc: 'Default coordinates for property search'
|
|
63
40
|
}),
|
|
64
41
|
GOOGLE_ANALYTICS_ID: str({
|
|
65
42
|
default: 'G-L5J3SYZ69C'
|
|
66
|
-
}),
|
|
67
|
-
RAPID_API_KEY: str({
|
|
68
|
-
default: '7c2d15ba29msh468be2f129d847cp183e95jsnc7c279116f6e'
|
|
69
43
|
})
|
|
70
44
|
});export{config};//# sourceMappingURL=env-config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env-config.js","sources":["../../src/config/env-config.ts"],"sourcesContent":[null],"names":[],"mappings":"0IAIA,MAAM,GAAG,GAAG,cAAc,EAAE;AAE5B,MAAM,sBAAsB,GAAG,IAAI,CAAC,SAAS,CAAC;KAC1C,EAAG,gBAAE,CAAA,GAAiB;KACtB,EAAG,gBAAE,CAAA,GAAiB;MACtB,EAAI,gBAAE,CAAA,IAAiB;SACvB,EAAO,gBAAE,CAAA;AACZ,CAAA,CAAC;AAEK,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,EAAE;AAChC,EAAA,gCAAA,EAAgC,IAAE,CAAA;AAClC,IAAA,OAAA,EAAA,KAAA;
|
|
1
|
+
{"version":3,"file":"env-config.js","sources":["../../src/config/env-config.ts"],"sourcesContent":[null],"names":[],"mappings":"0IAIA,MAAM,GAAG,GAAG,cAAc,EAAE;AAE5B,MAAM,sBAAsB,GAAG,IAAI,CAAC,SAAS,CAAC;KAC1C,EAAG,gBAAE,CAAA,GAAiB;KACtB,EAAG,gBAAE,CAAA,GAAiB;MACtB,EAAI,gBAAE,CAAA,IAAiB;SACvB,EAAO,gBAAE,CAAA;AACZ,CAAA,CAAC;AAEK,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,EAAE;AAChC,EAAA,gCAAA,EAAgC,IAAE,CAAA;AAClC,IAAA,OAAA,EAAA,KAAA;AAEA,IAAA,IAAA,EAAA;IACA;kBACA,EAAA,GAAA,CAAA;AACI,IAAA,OAAA,EAAA,sBAAW;AACX,IAAA,IAAA,EAAA;;eAEJ,EAAA,GAAA,CAAA;AACI,IAAA,OAAA,EAAA,SAAW;AACX,IAAA,IAAA,EAAA;;qBAEJ,EAAA,GAAA,CAAA;WACI,EAAA;AACA,GAAA,CAAA;mCACF,EAAA,GAAA,CAAA;IACF,OAAA,EAAA,EAAA;AACI,IAAA,IAAA,EAAA;AACA,GAAA,CAAA;oCACF,EAAA,GAAA,CAAA;IACF,OAAA,EAAA,EAAA;AACH,IAAE,IAAA,EAAA;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unavailableDatasource.test.d.ts","sourceRoot":"","sources":["../../../src/middlewares/__tests__/unavailableDatasource.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Publishes an empty `airbnbResults` and says why: this package no longer calls the travel data provider
|
|
3
|
+
* (see ./unavailableDatasource). Kept so that a route that still lists this middleware keeps loading.
|
|
4
|
+
*/
|
|
5
|
+
export declare const middleware: ({ context, request }: {
|
|
2
6
|
context: any;
|
|
3
7
|
request: any;
|
|
4
|
-
params: any;
|
|
5
8
|
}, dataLoader: any, next: any) => Promise<void>;
|
|
6
9
|
//# sourceMappingURL=airbnbDatasourcesMiddleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"airbnbDatasourcesMiddleware.d.ts","sourceRoot":"","sources":["../../src/middlewares/airbnbDatasourcesMiddleware.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"airbnbDatasourcesMiddleware.d.ts","sourceRoot":"","sources":["../../src/middlewares/airbnbDatasourcesMiddleware.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,UAAU;;;+CAAyD,CAAC"}
|
|
@@ -1,123 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const {
|
|
7
|
-
apolloClient,
|
|
8
|
-
container
|
|
9
|
-
} = context;
|
|
10
|
-
// Prefer logger from dataLoader (pre-resolved by loaderWithMiddleware) to avoid repeated container.get() calls
|
|
11
|
-
const logger = dataLoader.logger ?? container.get(ClientTypes.Logger);
|
|
12
|
-
let airbnbQuery;
|
|
13
|
-
try {
|
|
14
|
-
const url = new URL(request.url);
|
|
15
|
-
const searchParams = url.searchParams;
|
|
16
|
-
// Parse basic parameters
|
|
17
|
-
const from = searchParams.get('from') ? new Date(searchParams.get('from')) : null;
|
|
18
|
-
const to = searchParams.get('to') ? new Date(searchParams.get('to')) : null;
|
|
19
|
-
const adults = parseInt(searchParams.get('adults') || '0', 10);
|
|
20
|
-
const children = parseInt(searchParams.get('children') || '0', 10);
|
|
21
|
-
const infants = parseInt(searchParams.get('infants') || '0', 10);
|
|
22
|
-
// Parse viewport coordinates
|
|
23
|
-
let viewport = {};
|
|
24
|
-
try {
|
|
25
|
-
viewport = searchParams.get('viewport') ? JSON.parse(searchParams.get('viewport')) : null;
|
|
26
|
-
} catch (e) {
|
|
27
|
-
logger.warn('Failed to parse viewport parameter');
|
|
28
|
-
}
|
|
29
|
-
// Validate total passengers
|
|
30
|
-
const totalPassengers = adults + children + infants;
|
|
31
|
-
if (totalPassengers > 16) {
|
|
32
|
-
throw new Error('Maximum total number of passengers cannot exceed 16');
|
|
33
|
-
}
|
|
34
|
-
// Validate infants range
|
|
35
|
-
if (infants < 0 || infants > 5) {
|
|
36
|
-
throw new Error('Number of infants must be between 0 and 5');
|
|
37
|
-
}
|
|
38
|
-
// Parse additional parameters
|
|
39
|
-
const minBeds = parseInt(searchParams.get('minBeds') || '0', 10);
|
|
40
|
-
const minBedrooms = parseInt(searchParams.get('minBedrooms') || '0', 10);
|
|
41
|
-
const page = parseInt(searchParams.get('page') || '1', 10);
|
|
42
|
-
// Create a promise that will fetch the Airbnb data
|
|
43
|
-
airbnbQuery = new Promise(async (resolve, reject) => {
|
|
44
|
-
try {
|
|
45
|
-
// Create apiParams with the defined type
|
|
46
|
-
const apiParams = {
|
|
47
|
-
checkin: from ? from.toISOString().split('T')[0] : '',
|
|
48
|
-
checkout: to ? to.toISOString().split('T')[0] : '',
|
|
49
|
-
adults: adults.toString(),
|
|
50
|
-
children: children.toString(),
|
|
51
|
-
infants: infants.toString(),
|
|
52
|
-
page: page.toString(),
|
|
53
|
-
currency: 'USD' // You might want to make this configurable
|
|
54
|
-
};
|
|
55
|
-
// Add viewport parameters if available
|
|
56
|
-
if (viewport && viewport.northeast && viewport.southwest) {
|
|
57
|
-
apiParams.ne_lat = viewport.northeast.lat.toString();
|
|
58
|
-
apiParams.ne_lng = viewport.northeast.lng.toString();
|
|
59
|
-
apiParams.sw_lat = viewport.southwest.lat.toString();
|
|
60
|
-
apiParams.sw_lng = viewport.southwest.lng.toString();
|
|
61
|
-
}
|
|
62
|
-
// Add optional parameters if they exist
|
|
63
|
-
if (minBeds > 0) apiParams.min_beds = minBeds.toString();
|
|
64
|
-
if (minBedrooms > 0) apiParams.min_bedrooms = minBedrooms.toString();
|
|
65
|
-
const rapidApiKey = config.AIRBNB_API_KEY;
|
|
66
|
-
const response = await fetch('https://airbnb13.p.rapidapi.com/search-geo?' + new URLSearchParams(apiParams), {
|
|
67
|
-
headers: {
|
|
68
|
-
'x-rapidapi-host': 'airbnb13.p.rapidapi.com',
|
|
69
|
-
'x-rapidapi-key': rapidApiKey
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
const responseData = await response.json();
|
|
73
|
-
// Restructure the response data
|
|
74
|
-
const results = responseData.results || [];
|
|
75
|
-
const resultsPerPage = 40; // Assuming each page can have up to 40 results
|
|
76
|
-
const totalResults = (page - 1) * resultsPerPage + results.length; // Calculate total results seen so far
|
|
77
|
-
// Determine if there might be a next page
|
|
78
|
-
const hasNextPage = results.length === resultsPerPage;
|
|
79
|
-
const totalPages = hasNextPage ? page + 1 : page; // If current page is full, assume next page exists
|
|
80
|
-
const restructuredData = {
|
|
81
|
-
...responseData,
|
|
82
|
-
data: results,
|
|
83
|
-
pagination: {
|
|
84
|
-
currentPage: page,
|
|
85
|
-
totalPages: totalPages,
|
|
86
|
-
// Use the calculated totalPages
|
|
87
|
-
totalCount: totalResults // Use the calculated totalResults
|
|
88
|
-
},
|
|
89
|
-
metadata: {
|
|
90
|
-
viewport: viewport,
|
|
91
|
-
filters: {
|
|
92
|
-
adults,
|
|
93
|
-
children,
|
|
94
|
-
infants,
|
|
95
|
-
minBeds,
|
|
96
|
-
minBedrooms
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
resolve(restructuredData);
|
|
101
|
-
} catch (error) {
|
|
102
|
-
logger.error(error, 'Failed to load Airbnb properties data:');
|
|
103
|
-
resolve({
|
|
104
|
-
pagination: {
|
|
105
|
-
currentPage: page,
|
|
106
|
-
totalCount: 0,
|
|
107
|
-
totalPages: 0
|
|
108
|
-
},
|
|
109
|
-
data: []
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
logger.info('Airbnb properties data loaded and cached');
|
|
114
|
-
// Ensure componentData is initialized
|
|
115
|
-
dataLoader.componentData = dataLoader.componentData || {};
|
|
116
|
-
// Store as an async function that returns the promise
|
|
117
|
-
dataLoader.componentData.airbnbResults = async () => await airbnbQuery;
|
|
118
|
-
await next();
|
|
119
|
-
} catch (error) {
|
|
120
|
-
logger.error(error, 'Failed to load Airbnb properties data:');
|
|
121
|
-
throw error;
|
|
122
|
-
}
|
|
123
|
-
};export{middleware};//# sourceMappingURL=airbnbDatasourcesMiddleware.js.map
|
|
1
|
+
import {createUnavailableDatasourceMiddleware}from'./unavailableDatasource.js';/**
|
|
2
|
+
* Publishes an empty `airbnbResults` and says why: this package no longer calls the travel data provider
|
|
3
|
+
* (see ./unavailableDatasource). Kept so that a route that still lists this middleware keeps loading.
|
|
4
|
+
*/
|
|
5
|
+
const middleware = createUnavailableDatasourceMiddleware('airbnbResults');export{middleware};//# sourceMappingURL=airbnbDatasourcesMiddleware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"airbnbDatasourcesMiddleware.js","sources":["../../src/middlewares/airbnbDatasourcesMiddleware.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"airbnbDatasourcesMiddleware.js","sources":["../../src/middlewares/airbnbDatasourcesMiddleware.ts"],"sourcesContent":[null],"names":[],"mappings":"+EAEA;;;AAGG;MACU,UAAU,GAAG,qCAAqC,CAAC,eAAe"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Publishes an empty `bookingCarRentalResults` and says why: this package no longer calls the travel data provider
|
|
3
|
+
* (see ./unavailableDatasource). Kept so that a route that still lists this middleware keeps loading.
|
|
4
|
+
*/
|
|
5
|
+
export declare const middleware: ({ context, request }: {
|
|
2
6
|
context: any;
|
|
3
7
|
request: any;
|
|
4
|
-
params: any;
|
|
5
8
|
}, dataLoader: any, next: any) => Promise<void>;
|
|
6
9
|
//# sourceMappingURL=bookingCarRentalMiddleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bookingCarRentalMiddleware.d.ts","sourceRoot":"","sources":["../../src/middlewares/bookingCarRentalMiddleware.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bookingCarRentalMiddleware.d.ts","sourceRoot":"","sources":["../../src/middlewares/bookingCarRentalMiddleware.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,UAAU;;;+CAAmE,CAAC"}
|
|
@@ -1,111 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const {
|
|
7
|
-
container
|
|
8
|
-
} = context;
|
|
9
|
-
// Prefer logger from dataLoader (pre-resolved by loaderWithMiddleware) to avoid repeated container.get() calls
|
|
10
|
-
const logger = dataLoader.logger ?? container.get(ClientTypes.Logger);
|
|
11
|
-
let carRentalQuery;
|
|
12
|
-
try {
|
|
13
|
-
const url = new URL(request.url);
|
|
14
|
-
const searchParams = url.searchParams;
|
|
15
|
-
// Parse and validate parameters
|
|
16
|
-
const currency = searchParams.get('currency') || 'USD';
|
|
17
|
-
const locale = searchParams.get('locale') || 'en-gb';
|
|
18
|
-
const pickUpDateTime = searchParams.get('pick_up_datetime');
|
|
19
|
-
const dropOffDateTime = searchParams.get('drop_off_datetime');
|
|
20
|
-
const pickUpLongitude = parseFloat(searchParams.get('pick_up_longitude') || '0');
|
|
21
|
-
const dropOffLongitude = parseFloat(searchParams.get('drop_off_longitude') || '0');
|
|
22
|
-
const pickUpLatitude = parseFloat(searchParams.get('pick_up_latitude') || '0');
|
|
23
|
-
const dropOffLatitude = parseFloat(searchParams.get('drop_off_latitude') || '0');
|
|
24
|
-
const fromCountry = searchParams.get('from_country') || 'us';
|
|
25
|
-
const sortBy = searchParams.get('sort_by') || 'recommended';
|
|
26
|
-
// Validate required parameters
|
|
27
|
-
if (!dropOffDateTime) {
|
|
28
|
-
throw new Error('Drop-off date is required');
|
|
29
|
-
}
|
|
30
|
-
// Validate coordinates
|
|
31
|
-
if (isNaN(pickUpLongitude) || isNaN(dropOffLongitude) || isNaN(pickUpLatitude) || isNaN(dropOffLatitude)) {
|
|
32
|
-
throw new Error('Invalid coordinates provided');
|
|
33
|
-
}
|
|
34
|
-
// Create a promise that will fetch the car rental data
|
|
35
|
-
carRentalQuery = new Promise(async (resolve, reject) => {
|
|
36
|
-
try {
|
|
37
|
-
// Create carRentalParams with the defined type
|
|
38
|
-
const carRentalParams = {
|
|
39
|
-
currency,
|
|
40
|
-
locale,
|
|
41
|
-
pick_up_longitude: pickUpLongitude.toString(),
|
|
42
|
-
from_country: fromCountry,
|
|
43
|
-
drop_off_datetime: dropOffDateTime,
|
|
44
|
-
drop_off_longitude: dropOffLongitude.toString(),
|
|
45
|
-
sort_by: sortBy,
|
|
46
|
-
drop_off_latitude: dropOffLatitude.toString(),
|
|
47
|
-
pick_up_latitude: pickUpLatitude.toString()
|
|
48
|
-
};
|
|
49
|
-
// Add pick_up_datetime only if it exists
|
|
50
|
-
if (pickUpDateTime) {
|
|
51
|
-
carRentalParams.pick_up_datetime = pickUpDateTime;
|
|
52
|
-
}
|
|
53
|
-
const rapidApiKey = config.BOOKING_CAR_RENTAL_API_KEY;
|
|
54
|
-
const response = await fetch('https://booking-com.p.rapidapi.com/v1/car-rental/search?' + new URLSearchParams(carRentalParams), {
|
|
55
|
-
headers: {
|
|
56
|
-
'X-RapidAPI-Key': rapidApiKey,
|
|
57
|
-
'X-RapidAPI-Host': 'booking-com.p.rapidapi.com'
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
if (!response.ok) {
|
|
61
|
-
throw new Error(`API request failed with status ${response.status}`);
|
|
62
|
-
}
|
|
63
|
-
const responseData = await response.json();
|
|
64
|
-
// const formattedData = formatCarRentalResponse(responseData);
|
|
65
|
-
const results = responseData.search_results || [];
|
|
66
|
-
const restructuredData = {
|
|
67
|
-
...responseData,
|
|
68
|
-
data: results,
|
|
69
|
-
metadata: {
|
|
70
|
-
filters: {
|
|
71
|
-
currency,
|
|
72
|
-
locale,
|
|
73
|
-
fromCountry,
|
|
74
|
-
sortBy,
|
|
75
|
-
pickUpDateTime,
|
|
76
|
-
dropOffDateTime,
|
|
77
|
-
coordinates: {
|
|
78
|
-
pickUp: {
|
|
79
|
-
latitude: pickUpLatitude,
|
|
80
|
-
longitude: pickUpLongitude
|
|
81
|
-
},
|
|
82
|
-
dropOff: {
|
|
83
|
-
latitude: dropOffLatitude,
|
|
84
|
-
longitude: dropOffLongitude
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
resolve(restructuredData);
|
|
91
|
-
} catch (error) {
|
|
92
|
-
logger.error(error, 'Failed to load car rental data:');
|
|
93
|
-
resolve({
|
|
94
|
-
data: [],
|
|
95
|
-
metadata: {
|
|
96
|
-
filters: {}
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
logger.info('Car rental data loaded and cached');
|
|
102
|
-
// Ensure componentData is initialized
|
|
103
|
-
dataLoader.componentData = dataLoader.componentData || {};
|
|
104
|
-
// Store as an async function that returns the promise
|
|
105
|
-
dataLoader.componentData.bookingCarRentalResults = async () => await carRentalQuery;
|
|
106
|
-
await next();
|
|
107
|
-
} catch (error) {
|
|
108
|
-
logger.error(error, 'Failed to load car rental data:');
|
|
109
|
-
throw error;
|
|
110
|
-
}
|
|
111
|
-
};export{middleware};//# sourceMappingURL=bookingCarRentalMiddleware.js.map
|
|
1
|
+
import {createUnavailableDatasourceMiddleware}from'./unavailableDatasource.js';/**
|
|
2
|
+
* Publishes an empty `bookingCarRentalResults` and says why: this package no longer calls the travel data provider
|
|
3
|
+
* (see ./unavailableDatasource). Kept so that a route that still lists this middleware keeps loading.
|
|
4
|
+
*/
|
|
5
|
+
const middleware = createUnavailableDatasourceMiddleware('bookingCarRentalResults');export{middleware};//# sourceMappingURL=bookingCarRentalMiddleware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bookingCarRentalMiddleware.js","sources":["../../src/middlewares/bookingCarRentalMiddleware.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bookingCarRentalMiddleware.js","sources":["../../src/middlewares/bookingCarRentalMiddleware.ts"],"sourcesContent":[null],"names":[],"mappings":"+EAEA;;;AAGG;MACU,UAAU,GAAG,qCAAqC,CAAC,yBAAyB"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Publishes an empty `bookingResults` and says why: this package no longer calls the travel data provider
|
|
3
|
+
* (see ./unavailableDatasource). Kept so that a route that still lists this middleware keeps loading.
|
|
4
|
+
*/
|
|
5
|
+
export declare const middleware: ({ context, request }: {
|
|
2
6
|
context: any;
|
|
3
7
|
request: any;
|
|
4
|
-
params: any;
|
|
5
8
|
}, dataLoader: any, next: any) => Promise<void>;
|
|
6
|
-
export { middleware };
|
|
7
9
|
//# sourceMappingURL=bookingDatasourcesMiddleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bookingDatasourcesMiddleware.d.ts","sourceRoot":"","sources":["../../src/middlewares/bookingDatasourcesMiddleware.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bookingDatasourcesMiddleware.d.ts","sourceRoot":"","sources":["../../src/middlewares/bookingDatasourcesMiddleware.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,UAAU;;;+CAA0D,CAAC"}
|
|
@@ -1,139 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const {
|
|
7
|
-
apolloClient,
|
|
8
|
-
container
|
|
9
|
-
} = context;
|
|
10
|
-
// Prefer logger from dataLoader (pre-resolved by loaderWithMiddleware) to avoid repeated container.get() calls
|
|
11
|
-
const logger = dataLoader.logger ?? container.get(ClientTypes.Logger);
|
|
12
|
-
let bookingQuery;
|
|
13
|
-
try {
|
|
14
|
-
// Create a promise that will fetch the Booking.com data
|
|
15
|
-
const url = new URL(request.url);
|
|
16
|
-
const searchParams = url.searchParams;
|
|
17
|
-
const from = searchParams.get('from') ? new Date(searchParams.get('from')) : null;
|
|
18
|
-
const to = searchParams.get('to') ? new Date(searchParams.get('to')) : null;
|
|
19
|
-
const adults = parseInt(searchParams.get('adults') || '0', 10);
|
|
20
|
-
const children = parseInt(searchParams.get('children') || '0', 10);
|
|
21
|
-
const coordinates = searchParams.get('coordinates') ? JSON.parse(searchParams.get('coordinates')) : {};
|
|
22
|
-
const page = parseInt(searchParams.get('page') || '1', 10);
|
|
23
|
-
const infants = parseInt(searchParams.get('infants') || '0', 10);
|
|
24
|
-
const maxPrice = parseInt(searchParams.get('priceSliderValue') || '0', 10);
|
|
25
|
-
const latitude = coordinates.lat || '';
|
|
26
|
-
const longitude = coordinates.lng || '';
|
|
27
|
-
const radiusParamValue = parseInt(searchParams.get('distanceSliderValue') || '0', 10);
|
|
28
|
-
const zoom = parseInt(searchParams.get('zoom') || '12', 10);
|
|
29
|
-
// Calculate the radius based on the zoom level
|
|
30
|
-
// Assuming zoom level 12 is the closest view and 1 is the farthest
|
|
31
|
-
const calculateRadius = zoomLevel => {
|
|
32
|
-
const maxZoom = 12;
|
|
33
|
-
const minZoom = 1;
|
|
34
|
-
const minRadius = 10; // Minimum radius when fully zoomed in
|
|
35
|
-
const maxRadius = 360; // Maximum radius when fully zoomed out
|
|
36
|
-
// Linear interpolation between minRadius and maxRadius based on zoom level
|
|
37
|
-
const radius = minRadius + (maxZoom - zoomLevel) / (maxZoom - minZoom) * (maxRadius - minRadius);
|
|
38
|
-
return Math.round(Math.max(minRadius, Math.min(maxRadius, radius))); // Ensure radius is within bounds
|
|
39
|
-
};
|
|
40
|
-
const radius = calculateRadius(zoom);
|
|
41
|
-
// Parse viewport coordinates
|
|
42
|
-
let viewport = {};
|
|
43
|
-
try {
|
|
44
|
-
viewport = searchParams.get('viewport') ? JSON.parse(searchParams.get('viewport')) : null;
|
|
45
|
-
} catch (e) {
|
|
46
|
-
logger.warn('Failed to parse viewport parameter');
|
|
47
|
-
}
|
|
48
|
-
bookingQuery = new Promise(async (resolve, reject) => {
|
|
49
|
-
try {
|
|
50
|
-
const sampleParams = {
|
|
51
|
-
checkIn: from || '',
|
|
52
|
-
checkOut: to || '',
|
|
53
|
-
guest: adults + children || 1
|
|
54
|
-
};
|
|
55
|
-
const {
|
|
56
|
-
checkIn,
|
|
57
|
-
checkOut,
|
|
58
|
-
guest
|
|
59
|
-
} = sampleParams;
|
|
60
|
-
const rapidApiKey = config.BOOKING_COM_API_KEY;
|
|
61
|
-
const response = await fetch('https://booking-com15.p.rapidapi.com/api/v1/hotels/searchHotelsByCoordinates?' + new URLSearchParams({
|
|
62
|
-
latitude: latitude.toString(),
|
|
63
|
-
longitude: longitude.toString(),
|
|
64
|
-
arrival_date: from ? from.toISOString().split('T')[0] : '',
|
|
65
|
-
departure_date: to ? to.toISOString().split('T')[0] : '',
|
|
66
|
-
adults: guest.toString(),
|
|
67
|
-
page_number: page.toString(),
|
|
68
|
-
languagecode: 'en-us',
|
|
69
|
-
radius: radiusParamValue > 0 ? radiusParamValue.toString() : radius.toString(),
|
|
70
|
-
...(maxPrice > 0 ? {
|
|
71
|
-
price_max: maxPrice.toString()
|
|
72
|
-
} : {})
|
|
73
|
-
}), {
|
|
74
|
-
headers: {
|
|
75
|
-
'x-rapidapi-host': 'booking-com15.p.rapidapi.com',
|
|
76
|
-
'x-rapidapi-key': rapidApiKey
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
const responseData = await response.json();
|
|
80
|
-
// Check if responseData.data is not present and responseData.message exists
|
|
81
|
-
if (!responseData.data && responseData.message) {
|
|
82
|
-
logger.error('Booking.com API error:', JSON.stringify(responseData.message));
|
|
83
|
-
// Instead of throwing, return empty results
|
|
84
|
-
const emptyResponse = {
|
|
85
|
-
data: {
|
|
86
|
-
count: 0,
|
|
87
|
-
result: []
|
|
88
|
-
},
|
|
89
|
-
pagination: {
|
|
90
|
-
currentPage: page,
|
|
91
|
-
totalPages: 0,
|
|
92
|
-
totalCount: 0
|
|
93
|
-
},
|
|
94
|
-
metadata: {
|
|
95
|
-
viewport: viewport,
|
|
96
|
-
filters: {
|
|
97
|
-
adults,
|
|
98
|
-
children,
|
|
99
|
-
infants
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
resolve(emptyResponse);
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
const restructuredData = {
|
|
107
|
-
...responseData,
|
|
108
|
-
pagination: {
|
|
109
|
-
currentPage: page,
|
|
110
|
-
totalPages: Math.ceil(responseData.data.count / config.BOOKING_COM_DEFAULT_PAGE_SIZE),
|
|
111
|
-
// Use the calculated totalPages
|
|
112
|
-
totalCount: responseData.data.count
|
|
113
|
-
},
|
|
114
|
-
metadata: {
|
|
115
|
-
viewport: viewport,
|
|
116
|
-
filters: {
|
|
117
|
-
adults,
|
|
118
|
-
children,
|
|
119
|
-
infants
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
data: responseData.data.result || [] // Assuming the Booking.com API returns results in 'result' field
|
|
123
|
-
};
|
|
124
|
-
resolve(restructuredData);
|
|
125
|
-
} catch (error) {
|
|
126
|
-
reject(error);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
logger.info('Booking.com properties data loaded and cached');
|
|
130
|
-
// Ensure componentData is initialized
|
|
131
|
-
dataLoader.componentData = dataLoader.componentData || {};
|
|
132
|
-
// Store as an async function that returns the promise
|
|
133
|
-
dataLoader.componentData.bookingResults = async () => await bookingQuery;
|
|
134
|
-
await next();
|
|
135
|
-
} catch (error) {
|
|
136
|
-
logger.error(error, 'Failed to load Booking.com properties data:');
|
|
137
|
-
throw error;
|
|
138
|
-
}
|
|
139
|
-
};export{middleware};//# sourceMappingURL=bookingDatasourcesMiddleware.js.map
|
|
1
|
+
import {createUnavailableDatasourceMiddleware}from'./unavailableDatasource.js';/**
|
|
2
|
+
* Publishes an empty `bookingResults` and says why: this package no longer calls the travel data provider
|
|
3
|
+
* (see ./unavailableDatasource). Kept so that a route that still lists this middleware keeps loading.
|
|
4
|
+
*/
|
|
5
|
+
const middleware = createUnavailableDatasourceMiddleware('bookingResults');export{middleware};//# sourceMappingURL=bookingDatasourcesMiddleware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bookingDatasourcesMiddleware.js","sources":["../../src/middlewares/bookingDatasourcesMiddleware.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bookingDatasourcesMiddleware.js","sources":["../../src/middlewares/bookingDatasourcesMiddleware.ts"],"sourcesContent":[null],"names":[],"mappings":"+EAEA;;;AAGG;MACU,UAAU,GAAG,qCAAqC,CAAC,gBAAgB"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Publishes an empty `pricelineResults` and says why: this package no longer calls the travel data provider
|
|
3
|
+
* (see ./unavailableDatasource). Kept so that a route that still lists this middleware keeps loading.
|
|
4
|
+
*/
|
|
5
|
+
export declare const middleware: ({ context, request }: {
|
|
2
6
|
context: any;
|
|
3
7
|
request: any;
|
|
4
|
-
params: any;
|
|
5
8
|
}, dataLoader: any, next: any) => Promise<void>;
|
|
6
|
-
export { middleware };
|
|
7
9
|
//# sourceMappingURL=pricelineDatasourcesMiddleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pricelineDatasourcesMiddleware.d.ts","sourceRoot":"","sources":["../../src/middlewares/pricelineDatasourcesMiddleware.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pricelineDatasourcesMiddleware.d.ts","sourceRoot":"","sources":["../../src/middlewares/pricelineDatasourcesMiddleware.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,UAAU;;;+CAA4D,CAAC"}
|
|
@@ -1,97 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const {
|
|
7
|
-
container
|
|
8
|
-
} = context;
|
|
9
|
-
// Prefer logger from dataLoader (pre-resolved by loaderWithMiddleware) to avoid repeated container.get() calls
|
|
10
|
-
const logger = dataLoader.logger ?? container.get(ClientTypes.Logger);
|
|
11
|
-
let pricelineQuery;
|
|
12
|
-
try {
|
|
13
|
-
const url = new URL(request.url);
|
|
14
|
-
const searchParams = url.searchParams;
|
|
15
|
-
const coordinates = searchParams.get('coordinates') ? JSON.parse(searchParams.get('coordinates')) : {};
|
|
16
|
-
const latitude = coordinates?.lat || JSON.parse(config.DEFAULT_COORDINATES).lat;
|
|
17
|
-
const longitude = coordinates?.lng || JSON.parse(config.DEFAULT_COORDINATES).lng;
|
|
18
|
-
const page = parseInt(searchParams.get('page') || '1', 10);
|
|
19
|
-
const limit = 100;
|
|
20
|
-
const offset = page * limit;
|
|
21
|
-
const from = searchParams.get('from') ? new Date(searchParams.get('from')) : null;
|
|
22
|
-
const to = searchParams.get('to') ? new Date(searchParams.get('to')) : null;
|
|
23
|
-
pricelineQuery = new Promise(async resolve => {
|
|
24
|
-
try {
|
|
25
|
-
const options = {
|
|
26
|
-
method: 'GET',
|
|
27
|
-
url: 'https://priceline-com-provider.p.rapidapi.com/v2/hotels/expressResults',
|
|
28
|
-
params: {
|
|
29
|
-
limit: offset,
|
|
30
|
-
check_in: from ? from.toISOString().split('T')[0] : '',
|
|
31
|
-
check_out: to ? to.toISOString().split('T')[0] : '',
|
|
32
|
-
latitude: latitude,
|
|
33
|
-
longitude: longitude,
|
|
34
|
-
output_version: '3'
|
|
35
|
-
},
|
|
36
|
-
headers: {
|
|
37
|
-
'x-rapidapi-key': config.PRICELINE_API_KEY,
|
|
38
|
-
'x-rapidapi-host': 'priceline-com-provider.p.rapidapi.com',
|
|
39
|
-
Accept: 'application/json'
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
const response = await axios.request(options);
|
|
43
|
-
// Handle API error response
|
|
44
|
-
if (!response.data || response.data['getHotelExpress.Results'].error) {
|
|
45
|
-
logger.error('Priceline API error:', response.data?.['getHotelExpress.Results']?.error || 'Unknown error');
|
|
46
|
-
resolve({
|
|
47
|
-
pagination: {
|
|
48
|
-
currentPage: page,
|
|
49
|
-
totalCount: 0,
|
|
50
|
-
totalPages: 0
|
|
51
|
-
},
|
|
52
|
-
data: []
|
|
53
|
-
});
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const restructuredData = {
|
|
57
|
-
...response.data,
|
|
58
|
-
pagination: {
|
|
59
|
-
currentPage: page,
|
|
60
|
-
totalCount: response.data['getHotelExpress.Results'].results.results_data.rate_count,
|
|
61
|
-
totalPages: Math.ceil(response.data['getHotelExpress.Results'].results.results_data.rate_count / limit)
|
|
62
|
-
},
|
|
63
|
-
data: response.data['getHotelExpress.Results'].results?.hotel_data || []
|
|
64
|
-
};
|
|
65
|
-
resolve(restructuredData);
|
|
66
|
-
} catch (error) {
|
|
67
|
-
// Handle any other errors (network, parsing, etc.)
|
|
68
|
-
logger.error('Error in Priceline API request:', error);
|
|
69
|
-
resolve({
|
|
70
|
-
pagination: {
|
|
71
|
-
currentPage: page,
|
|
72
|
-
totalCount: 0,
|
|
73
|
-
totalPages: 0
|
|
74
|
-
},
|
|
75
|
-
data: []
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
logger.info('Priceline nearby hotels data loaded and cached');
|
|
80
|
-
dataLoader.componentData = dataLoader.componentData || {};
|
|
81
|
-
dataLoader.componentData.pricelineResults = async () => await pricelineQuery;
|
|
82
|
-
await next();
|
|
83
|
-
} catch (error) {
|
|
84
|
-
// Handle setup errors
|
|
85
|
-
logger.error('Failed to load Priceline nearby hotels data:', error);
|
|
86
|
-
dataLoader.componentData = dataLoader.componentData || {};
|
|
87
|
-
dataLoader.componentData.pricelineResults = async () => ({
|
|
88
|
-
pagination: {
|
|
89
|
-
currentPage: 1,
|
|
90
|
-
totalCount: 0,
|
|
91
|
-
totalPages: 0
|
|
92
|
-
},
|
|
93
|
-
data: []
|
|
94
|
-
});
|
|
95
|
-
await next();
|
|
96
|
-
}
|
|
97
|
-
};export{middleware};//# sourceMappingURL=pricelineDatasourcesMiddleware.js.map
|
|
1
|
+
import {createUnavailableDatasourceMiddleware}from'./unavailableDatasource.js';/**
|
|
2
|
+
* Publishes an empty `pricelineResults` and says why: this package no longer calls the travel data provider
|
|
3
|
+
* (see ./unavailableDatasource). Kept so that a route that still lists this middleware keeps loading.
|
|
4
|
+
*/
|
|
5
|
+
const middleware = createUnavailableDatasourceMiddleware('pricelineResults');export{middleware};//# sourceMappingURL=pricelineDatasourcesMiddleware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pricelineDatasourcesMiddleware.js","sources":["../../src/middlewares/pricelineDatasourcesMiddleware.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pricelineDatasourcesMiddleware.js","sources":["../../src/middlewares/pricelineDatasourcesMiddleware.ts"],"sourcesContent":[null],"names":[],"mappings":"+EAEA;;;AAGG;MACU,UAAU,GAAG,qCAAqC,CAAC,kBAAkB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The price comparison data sources of this package used to call a travel data provider straight from
|
|
3
|
+
* here, with an API key read from the app's environment. This package also runs in the browser, where the
|
|
4
|
+
* environment is public: a key read here is a key handed to every visitor.
|
|
5
|
+
*
|
|
6
|
+
* So this package no longer reads such a key and no longer calls the provider. The middlewares keep their
|
|
7
|
+
* names and the shape of their results, which are now always empty, so a route that still lists one keeps
|
|
8
|
+
* loading. An app that wants the comparison serves the results from its own backend, which can keep the key.
|
|
9
|
+
*/
|
|
10
|
+
/** Goes with the empty result, where a page may show it to the person using the app. */
|
|
11
|
+
export declare const DATASOURCE_UNAVAILABLE_MESSAGE = "Price comparison is not available.";
|
|
12
|
+
/** For the developer of the app: written to the log (in the browser, its console), never into the result. */
|
|
13
|
+
export declare const DATASOURCE_DISABLED_WARNING: string;
|
|
14
|
+
export type UnavailableDatasourceResult = {
|
|
15
|
+
data: never[];
|
|
16
|
+
pagination: {
|
|
17
|
+
currentPage: number;
|
|
18
|
+
totalPages: 0;
|
|
19
|
+
totalCount: 0;
|
|
20
|
+
};
|
|
21
|
+
unavailable: true;
|
|
22
|
+
message: string;
|
|
23
|
+
};
|
|
24
|
+
export declare const unavailableDatasourceResult: (currentPage?: number) => UnavailableDatasourceResult;
|
|
25
|
+
/**
|
|
26
|
+
* A loader middleware that publishes an empty result under `resultKey` and says why, once per request.
|
|
27
|
+
* It makes no network call and reads nothing from the environment. The warning is the same for every data
|
|
28
|
+
* source: the result keys are named after travel sites, and the warning reaches the visitor's console.
|
|
29
|
+
*/
|
|
30
|
+
export declare const createUnavailableDatasourceMiddleware: (resultKey: string) => ({ context, request }: {
|
|
31
|
+
context: any;
|
|
32
|
+
request: any;
|
|
33
|
+
}, dataLoader: any, next: any) => Promise<void>;
|
|
34
|
+
//# sourceMappingURL=unavailableDatasource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unavailableDatasource.d.ts","sourceRoot":"","sources":["../../src/middlewares/unavailableDatasource.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AACH,wFAAwF;AACxF,eAAO,MAAM,8BAA8B,uCAAuC,CAAC;AAEnF,6GAA6G;AAC7G,eAAO,MAAM,2BAA2B,QAEmC,CAAC;AAE5E,MAAM,MAAM,2BAA2B,GAAG;IACtC,IAAI,EAAE,KAAK,EAAE,CAAC;IACd,UAAU,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,CAAC,CAAC;QAAC,UAAU,EAAE,CAAC,CAAA;KAAE,CAAC;IAClE,WAAW,EAAE,IAAI,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACnB,CAAC;AAWF,eAAO,MAAM,2BAA2B,GAAI,oBAAe,KAAG,2BAK5D,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,qCAAqC,GAC7C,WAAW,MAAM,MACX;;;CAAoB,EAAE,eAAU,EAAE,SAAI,kBAc5C,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {ClientTypes}from'@common-stack/client-core';/**
|
|
2
|
+
* The price comparison data sources of this package used to call a travel data provider straight from
|
|
3
|
+
* here, with an API key read from the app's environment. This package also runs in the browser, where the
|
|
4
|
+
* environment is public: a key read here is a key handed to every visitor.
|
|
5
|
+
*
|
|
6
|
+
* So this package no longer reads such a key and no longer calls the provider. The middlewares keep their
|
|
7
|
+
* names and the shape of their results, which are now always empty, so a route that still lists one keeps
|
|
8
|
+
* loading. An app that wants the comparison serves the results from its own backend, which can keep the key.
|
|
9
|
+
*/
|
|
10
|
+
/** Goes with the empty result, where a page may show it to the person using the app. */
|
|
11
|
+
const DATASOURCE_UNAVAILABLE_MESSAGE = 'Price comparison is not available.';
|
|
12
|
+
/** For the developer of the app: written to the log (in the browser, its console), never into the result. */
|
|
13
|
+
const DATASOURCE_DISABLED_WARNING = 'This price comparison data source is turned off: the shared travel UI no longer calls a travel data ' + 'provider from the browser. Serve these results from your own backend.';
|
|
14
|
+
const requestedPage = request => {
|
|
15
|
+
try {
|
|
16
|
+
const page = parseInt(new URL(request.url).searchParams.get('page') || '1', 10);
|
|
17
|
+
return Number.isFinite(page) && page > 0 ? page : 1;
|
|
18
|
+
} catch {
|
|
19
|
+
return 1;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const unavailableDatasourceResult = (currentPage = 1) => ({
|
|
23
|
+
data: [],
|
|
24
|
+
pagination: {
|
|
25
|
+
currentPage,
|
|
26
|
+
totalPages: 0,
|
|
27
|
+
totalCount: 0
|
|
28
|
+
},
|
|
29
|
+
unavailable: true,
|
|
30
|
+
message: DATASOURCE_UNAVAILABLE_MESSAGE
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* A loader middleware that publishes an empty result under `resultKey` and says why, once per request.
|
|
34
|
+
* It makes no network call and reads nothing from the environment. The warning is the same for every data
|
|
35
|
+
* source: the result keys are named after travel sites, and the warning reaches the visitor's console.
|
|
36
|
+
*/
|
|
37
|
+
const createUnavailableDatasourceMiddleware = resultKey => async ({
|
|
38
|
+
context,
|
|
39
|
+
request
|
|
40
|
+
}, dataLoader, next) => {
|
|
41
|
+
const logger = dataLoader.logger ?? context?.container?.get(ClientTypes.Logger);
|
|
42
|
+
logger?.warn(DATASOURCE_DISABLED_WARNING);
|
|
43
|
+
const result = unavailableDatasourceResult(requestedPage(request));
|
|
44
|
+
// The loader contract: a middleware publishes its data on the shared dataLoader.
|
|
45
|
+
/* eslint-disable no-param-reassign */
|
|
46
|
+
dataLoader.componentData = dataLoader.componentData || {};
|
|
47
|
+
dataLoader.componentData[resultKey] = async () => result;
|
|
48
|
+
/* eslint-enable no-param-reassign */
|
|
49
|
+
await next();
|
|
50
|
+
};export{DATASOURCE_DISABLED_WARNING,DATASOURCE_UNAVAILABLE_MESSAGE,createUnavailableDatasourceMiddleware,unavailableDatasourceResult};//# sourceMappingURL=unavailableDatasource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unavailableDatasource.js","sources":["../../src/middlewares/unavailableDatasource.ts"],"sourcesContent":[null],"names":[],"mappings":"oDAGA;;;;;;;;AAQG;AACH;AACO,MAAM,8BAA8B,GAAG;AAE9C;AACO,MAAM,2BAA2B,GACpC,sGAAsG,GAAA;AACtG,MAAA,aAAA,GAAA,OAAA,IAAA;AASJ,EAAA,IAAM;AACF,IAAA,MAAK,IAAA,GAAA,QAAA,CAAA,IAAA,GAAA,CAAA,OAAA,CAAA,GAAA,CAAA,CAAA,YAAA,CAAA,GAAA,CAAA,MAAA,CAAA,IAAA,GAAA,EAAA,EAAA,CAAA;WACD,MAAM,CAAI,QAAG,CAAA,SAAa,IAAI,GAAA,CAAA,GAAQ,IAAK,GAAA,CAAA;AAC3C,EAAA,CAAA,CAAA,MAAA;IACJ,OAAC,CAAA;AAAC,EAAA;AACE,CAAA;AACH,MAAA,2BAAA,GAAA,CAAA,WAAA,GAAA,CAAA,MAAA;AACL,EAAE,IAAA,EAAA,EAAA;AAEF,EAAA,UAAO,EAAM;AACT,IAAA,WAAQ;IACR,UAAU,EAAE,CAAA;AACZ,IAAA,UAAA;AACA,GAAA;AACH,EAAC,WAAC,EAAA,IAAA;AAEH,EAAA,OAAA,EAAA;;;;AAIG;AACH;AAGQ;AAGQ,MAAA,qCAAkC,GAAA,SAAA,IAAA,OAAA;SAE1C;;aAEA,EAAA,IAAA,KAAA;QACA,MAAU,cAAc,MAAG,IAAA,OAAW,EAAA,SAAa,EAAA,GAAM,CAAC,WAAA,CAAA,MAAA,CAAA;QAC1D,EAAA,IAAU,CAAC,2BAA2B,CAAA;QACtC,MAAA,GAAA,2BAAqC,CAAA,aAAA,CAAA,OAAA,CAAA,CAAA;;AAGzC;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@admin-layout/tailwind-travel-pro",
|
|
3
|
-
"version": "12.2.5-alpha.
|
|
3
|
+
"version": "12.2.5-alpha.35",
|
|
4
4
|
"description": "Sample core for higher packages to depend on",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "CDMBase LLC",
|
|
@@ -13,16 +13,15 @@
|
|
|
13
13
|
"build:clean": "rimraf lib",
|
|
14
14
|
"build:lib": "rollup -c rollup.config.mjs",
|
|
15
15
|
"build:lib:watch": "yarn build:lib -- --watch",
|
|
16
|
-
"jest": "./node_modules/.bin/jest",
|
|
17
16
|
"prepublish": "yarn build",
|
|
18
|
-
"test": "
|
|
19
|
-
"test:debug": "
|
|
20
|
-
"test:watch": "
|
|
17
|
+
"test": "vitest run",
|
|
18
|
+
"test:debug": "vitest run --no-file-parallelism",
|
|
19
|
+
"test:watch": "vitest",
|
|
21
20
|
"watch": "yarn build:lib:watch"
|
|
22
21
|
},
|
|
23
22
|
"dependencies": {
|
|
24
|
-
"@admin-layout/tailwind-design-pro": "12.2.5-alpha.
|
|
25
|
-
"@admin-layout/tailwind-ui": "12.2.5-alpha.
|
|
23
|
+
"@admin-layout/tailwind-design-pro": "12.2.5-alpha.35",
|
|
24
|
+
"@admin-layout/tailwind-ui": "12.2.5-alpha.31",
|
|
26
25
|
"@cdmbase/react-splide": "^0.7.12",
|
|
27
26
|
"@react-google-maps/api": "^2.20.7",
|
|
28
27
|
"@vis.gl/react-google-maps": "^1.5.4",
|
|
@@ -34,7 +33,8 @@
|
|
|
34
33
|
"@tailwindcss/aspect-ratio": "^0.4.2",
|
|
35
34
|
"@tailwindcss/forms": "^0.5.4",
|
|
36
35
|
"@tailwindcss/typography": "^0.5.9",
|
|
37
|
-
"tailwindcss": "^3.3.3"
|
|
36
|
+
"tailwindcss": "^3.3.3",
|
|
37
|
+
"vitest": "^3.0.4"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@adminide-stack/extension-api": "*",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"typescript": {
|
|
47
47
|
"definition": "lib/index.d.ts"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "a30575fadefffd0961f4fc9561741d00dc7be2cc"
|
|
50
50
|
}
|