@devtravelcode/widget-native 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +18 -0
- package/dist/App.d.ts +10 -0
- package/dist/App.js +192 -0
- package/dist/TravelHubWidget.d.ts +12 -0
- package/dist/TravelHubWidget.js +58 -0
- package/dist/components/ErrorBoundary.d.ts +18 -0
- package/dist/components/ErrorBoundary.js +63 -0
- package/dist/components/ui/Modal.d.ts +11 -0
- package/dist/components/ui/Modal.js +66 -0
- package/dist/components/ui/Skeleton.d.ts +8 -0
- package/dist/components/ui/Skeleton.js +33 -0
- package/dist/components/ui/badge.d.ts +11 -0
- package/dist/components/ui/badge.js +54 -0
- package/dist/components/ui/button.d.ts +14 -0
- package/dist/components/ui/button.js +101 -0
- package/dist/components/ui/card.d.ts +16 -0
- package/dist/components/ui/card.js +51 -0
- package/dist/components/ui/input.d.ts +8 -0
- package/dist/components/ui/input.js +61 -0
- package/dist/components/ui/label.d.ts +8 -0
- package/dist/components/ui/label.js +17 -0
- package/dist/context/WidgetContext.d.ts +29 -0
- package/dist/context/WidgetContext.js +64 -0
- package/dist/icons/CarIcon.d.ts +4 -0
- package/dist/icons/CarIcon.js +3 -0
- package/dist/icons/CloseIcon.d.ts +7 -0
- package/dist/icons/CloseIcon.js +3 -0
- package/dist/icons/FlightIcon.d.ts +4 -0
- package/dist/icons/FlightIcon.js +3 -0
- package/dist/icons/HotelIcon.d.ts +4 -0
- package/dist/icons/HotelIcon.js +3 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/lib/utils.js +3 -0
- package/dist/locales/widgetTranslations.d.ts +1 -0
- package/dist/locales/widgetTranslations.js +732 -0
- package/dist/modules/hooks/useAirportSearch.d.ts +21 -0
- package/dist/modules/hooks/useAirportSearch.js +48 -0
- package/dist/modules/hooks/useCarOffers.d.ts +7 -0
- package/dist/modules/hooks/useCarOffers.js +47 -0
- package/dist/modules/hooks/useCountriesByCodes.d.ts +4 -0
- package/dist/modules/hooks/useCountriesByCodes.js +60 -0
- package/dist/modules/hooks/useCountriesSearch.d.ts +11 -0
- package/dist/modules/hooks/useCountriesSearch.js +55 -0
- package/dist/modules/hooks/useDefaultHotelLocation.d.ts +7 -0
- package/dist/modules/hooks/useDefaultHotelLocation.js +44 -0
- package/dist/modules/hooks/useDetectNationality.d.ts +1 -0
- package/dist/modules/hooks/useDetectNationality.js +20 -0
- package/dist/modules/hooks/useFlightSearch.d.ts +20 -0
- package/dist/modules/hooks/useFlightSearch.js +243 -0
- package/dist/modules/hooks/useHotelDetails.d.ts +7 -0
- package/dist/modules/hooks/useHotelDetails.js +80 -0
- package/dist/modules/hooks/useHotelLocations.d.ts +5 -0
- package/dist/modules/hooks/useHotelLocations.js +42 -0
- package/dist/modules/hooks/useHotelMapData.d.ts +12 -0
- package/dist/modules/hooks/useHotelMapData.js +78 -0
- package/dist/modules/hooks/useHotelOffers.d.ts +11 -0
- package/dist/modules/hooks/useHotelOffers.js +122 -0
- package/dist/modules/hooks/useHotelSearchSSE.d.ts +18 -0
- package/dist/modules/hooks/useHotelSearchSSE.js +411 -0
- package/dist/modules/hooks/useSearchExpiration.d.ts +6 -0
- package/dist/modules/hooks/useSearchExpiration.js +35 -0
- package/dist/modules/hooks/useTranslationsHub.d.ts +5 -0
- package/dist/modules/hooks/useTranslationsHub.js +48 -0
- package/dist/modules/navbar/Navbar.d.ts +8 -0
- package/dist/modules/navbar/Navbar.js +69 -0
- package/dist/modules/search-form/AgeSelector.d.ts +9 -0
- package/dist/modules/search-form/AgeSelector.js +109 -0
- package/dist/modules/search-form/CustomSelect.d.ts +14 -0
- package/dist/modules/search-form/CustomSelect.js +94 -0
- package/dist/modules/search-form/FiltersSkeleton.d.ts +6 -0
- package/dist/modules/search-form/FiltersSkeleton.js +35 -0
- package/dist/modules/search-form/NationalityInput.d.ts +18 -0
- package/dist/modules/search-form/NationalityInput.js +172 -0
- package/dist/modules/search-form/Pagination.d.ts +8 -0
- package/dist/modules/search-form/Pagination.js +84 -0
- package/dist/modules/search-form/SearchExpiredPopup.d.ts +10 -0
- package/dist/modules/search-form/SearchExpiredPopup.js +91 -0
- package/dist/modules/search-form/SkeletonWidget.d.ts +2 -0
- package/dist/modules/search-form/SkeletonWidget.js +33 -0
- package/dist/modules/search-form/TimePicker.d.ts +9 -0
- package/dist/modules/search-form/TimePicker.js +182 -0
- package/dist/modules/search-form/cars/CarEmptyState.d.ts +6 -0
- package/dist/modules/search-form/cars/CarEmptyState.js +42 -0
- package/dist/modules/search-form/cars/CarFiltersSkeleton.d.ts +6 -0
- package/dist/modules/search-form/cars/CarFiltersSkeleton.js +35 -0
- package/dist/modules/search-form/cars/CarOffersList.d.ts +43 -0
- package/dist/modules/search-form/cars/CarOffersList.js +214 -0
- package/dist/modules/search-form/cars/CarResults.d.ts +25 -0
- package/dist/modules/search-form/cars/CarResults.js +116 -0
- package/dist/modules/search-form/cars/CarSearchForm.d.ts +19 -0
- package/dist/modules/search-form/cars/CarSearchForm.js +173 -0
- package/dist/modules/search-form/cars/CarSkeleton.d.ts +6 -0
- package/dist/modules/search-form/cars/CarSkeleton.js +46 -0
- package/dist/modules/search-form/cars/CarTopOffersSlider.d.ts +20 -0
- package/dist/modules/search-form/cars/CarTopOffersSlider.js +100 -0
- package/dist/modules/search-form/cars/car-filters/CarFilters.d.ts +8 -0
- package/dist/modules/search-form/cars/car-filters/CarFilters.js +318 -0
- package/dist/modules/search-form/cars/car-filters/FilterSection.d.ts +9 -0
- package/dist/modules/search-form/cars/car-filters/FilterSection.js +30 -0
- package/dist/modules/search-form/cars/car-filters/index.d.ts +6 -0
- package/dist/modules/search-form/cars/car-filters/index.js +3 -0
- package/dist/modules/search-form/cars/car-filters/useCarFilters.d.ts +24 -0
- package/dist/modules/search-form/cars/car-filters/useCarFilters.js +121 -0
- package/dist/modules/search-form/flight/AirlinesSelector.d.ts +8 -0
- package/dist/modules/search-form/flight/AirlinesSelector.js +235 -0
- package/dist/modules/search-form/flight/CabinClassSelector.d.ts +9 -0
- package/dist/modules/search-form/flight/CabinClassSelector.js +63 -0
- package/dist/modules/search-form/flight/DatePicker.d.ts +12 -0
- package/dist/modules/search-form/flight/DatePicker.js +536 -0
- package/dist/modules/search-form/flight/FlightSearchForm.d.ts +18 -0
- package/dist/modules/search-form/flight/FlightSearchForm.js +147 -0
- package/dist/modules/search-form/flight/LocationInput.d.ts +11 -0
- package/dist/modules/search-form/flight/LocationInput.js +294 -0
- package/dist/modules/search-form/flight/PassengersPicker.d.ts +16 -0
- package/dist/modules/search-form/flight/PassengersPicker.js +203 -0
- package/dist/modules/search-form/flight/SwitchLocationBtn.d.ts +9 -0
- package/dist/modules/search-form/flight/SwitchLocationBtn.js +48 -0
- package/dist/modules/search-form/flight/flight-filters/FiltersContent.d.ts +21 -0
- package/dist/modules/search-form/flight/flight-filters/FiltersContent.js +145 -0
- package/dist/modules/search-form/flight/flight-filters/FlightFiltersDynamic.d.ts +11 -0
- package/dist/modules/search-form/flight/flight-filters/FlightFiltersDynamic.js +213 -0
- package/dist/modules/search-form/flight/flight-filters/RangeBlock.d.ts +22 -0
- package/dist/modules/search-form/flight/flight-filters/RangeBlock.js +164 -0
- package/dist/modules/search-form/flight/flight-filters/index.d.ts +1 -0
- package/dist/modules/search-form/flight/flight-filters/index.js +1 -0
- package/dist/modules/search-form/flight/flight-results/FlightAdditionalInfo.d.ts +16 -0
- package/dist/modules/search-form/flight/flight-results/FlightAdditionalInfo.js +229 -0
- package/dist/modules/search-form/flight/flight-results/FlightBaggageToggle.d.ts +15 -0
- package/dist/modules/search-form/flight/flight-results/FlightBaggageToggle.js +110 -0
- package/dist/modules/search-form/flight/flight-results/FlightCard.d.ts +14 -0
- package/dist/modules/search-form/flight/flight-results/FlightCard.js +436 -0
- package/dist/modules/search-form/flight/flight-results/FlightInfo.d.ts +12 -0
- package/dist/modules/search-form/flight/flight-results/FlightInfo.js +48 -0
- package/dist/modules/search-form/flight/flight-results/FlightPriceBlock.d.ts +11 -0
- package/dist/modules/search-form/flight/flight-results/FlightPriceBlock.js +36 -0
- package/dist/modules/search-form/flight/flight-results/FlightResults.d.ts +22 -0
- package/dist/modules/search-form/flight/flight-results/FlightResults.js +109 -0
- package/dist/modules/search-form/flight/flight-results/FlightSegments.d.ts +40 -0
- package/dist/modules/search-form/flight/flight-results/FlightSegments.js +162 -0
- package/dist/modules/search-form/flight/flight-results/FlightsSkeleton.d.ts +6 -0
- package/dist/modules/search-form/flight/flight-results/FlightsSkeleton.js +52 -0
- package/dist/modules/search-form/flight/flight-results/ProvidersLoader.d.ts +9 -0
- package/dist/modules/search-form/flight/flight-results/ProvidersLoader.js +242 -0
- package/dist/modules/search-form/hotel/DatePicker.d.ts +1 -0
- package/dist/modules/search-form/hotel/DatePicker.js +1 -0
- package/dist/modules/search-form/hotel/GuestSelector.d.ts +13 -0
- package/dist/modules/search-form/hotel/GuestSelector.js +272 -0
- package/dist/modules/search-form/hotel/GuestSelectorMobilePopup.d.ts +2 -0
- package/dist/modules/search-form/hotel/GuestSelectorMobilePopup.js +1 -0
- package/dist/modules/search-form/hotel/HotelLocation.d.ts +17 -0
- package/dist/modules/search-form/hotel/HotelLocation.js +178 -0
- package/dist/modules/search-form/hotel/HotelLocationMobilePopup.d.ts +2 -0
- package/dist/modules/search-form/hotel/HotelLocationMobilePopup.js +1 -0
- package/dist/modules/search-form/hotel/HotelResults.d.ts +21 -0
- package/dist/modules/search-form/hotel/HotelResults.js +333 -0
- package/dist/modules/search-form/hotel/HotelSearchForm.d.ts +13 -0
- package/dist/modules/search-form/hotel/HotelSearchForm.js +130 -0
- package/dist/modules/search-form/hotel/HotelsSkeleton.d.ts +6 -0
- package/dist/modules/search-form/hotel/HotelsSkeleton.js +40 -0
- package/dist/modules/search-form/hotel/PassengersPicker.d.ts +2 -0
- package/dist/modules/search-form/hotel/PassengersPicker.js +1 -0
- package/dist/modules/search-form/hotel/components/HotelCard.d.ts +11 -0
- package/dist/modules/search-form/hotel/components/HotelCard.js +180 -0
- package/dist/modules/search-form/hotel/components/HotelEmptyState.d.ts +6 -0
- package/dist/modules/search-form/hotel/components/HotelEmptyState.js +34 -0
- package/dist/modules/search-form/hotel/components/HotelGallery.d.ts +6 -0
- package/dist/modules/search-form/hotel/components/HotelGallery.js +77 -0
- package/dist/modules/search-form/hotel/components/HotelList.d.ts +9 -0
- package/dist/modules/search-form/hotel/components/HotelList.js +12 -0
- package/dist/modules/search-form/hotel/components/HotelMap.d.ts +26 -0
- package/dist/modules/search-form/hotel/components/HotelMap.js +707 -0
- package/dist/modules/search-form/hotel/components/HotelPin.d.ts +7 -0
- package/dist/modules/search-form/hotel/components/HotelPin.js +1 -0
- package/dist/modules/search-form/hotel/hotel-filters/HotelFilters.d.ts +29 -0
- package/dist/modules/search-form/hotel/hotel-filters/HotelFilters.js +339 -0
- package/dist/modules/search-form/hotel/hotel-filters/HotelFiltersBar.d.ts +3 -0
- package/dist/modules/search-form/hotel/hotel-filters/HotelFiltersBar.js +2 -0
- package/dist/modules/search-form/hotel/hotel-filters/HotelFiltersContent.d.ts +2 -0
- package/dist/modules/search-form/hotel/hotel-filters/HotelFiltersContent.js +1 -0
- package/dist/modules/search-form/hotel/hotel-filters/HotelFiltersDynamic.d.ts +2 -0
- package/dist/modules/search-form/hotel/hotel-filters/HotelFiltersDynamic.js +1 -0
- package/dist/modules/search-form/hotel/hotel-filters/HotelFiltersMobilePopup.d.ts +2 -0
- package/dist/modules/search-form/hotel/hotel-filters/HotelFiltersMobilePopup.js +1 -0
- package/dist/modules/search-form/hotel/hotel-filters/RangeBlock.d.ts +1 -0
- package/dist/modules/search-form/hotel/hotel-filters/RangeBlock.js +1 -0
- package/dist/modules/search-form/hotel/hotel-filters/index.d.ts +1 -0
- package/dist/modules/search-form/hotel/hotel-filters/index.js +1 -0
- package/dist/modules/tabs/FlightsTab.d.ts +1 -0
- package/dist/modules/tabs/FlightsTab.js +1 -0
- package/dist/modules/tabs/HotelsTab.d.ts +1 -0
- package/dist/modules/tabs/HotelsTab.js +1 -0
- package/dist/store/index.d.ts +22 -0
- package/dist/store/index.js +19 -0
- package/dist/theme/colors.d.ts +56 -0
- package/dist/theme/colors.js +56 -0
- package/dist/theme/formStyles.d.ts +76 -0
- package/dist/theme/formStyles.js +78 -0
- package/dist/utils/applyWidgetColors.d.ts +1 -0
- package/dist/utils/applyWidgetColors.js +2 -0
- package/dist/utils/dateTime.d.ts +2 -0
- package/dist/utils/dateTime.js +23 -0
- package/dist/utils/fetchSSE.d.ts +23 -0
- package/dist/utils/fetchSSE.js +104 -0
- package/dist/utils/getToken.d.ts +3 -0
- package/dist/utils/getToken.js +12 -0
- package/package.json +64 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { StyleSheet } from "react-native";
|
|
2
|
+
import { Colors, Spacing, BorderRadius, FontSize } from "./colors";
|
|
3
|
+
export const formStyles = StyleSheet.create({
|
|
4
|
+
formCard: {
|
|
5
|
+
backgroundColor: Colors.surface,
|
|
6
|
+
borderRadius: BorderRadius.xxl,
|
|
7
|
+
padding: Spacing.xl,
|
|
8
|
+
gap: Spacing.lg,
|
|
9
|
+
marginHorizontal: Spacing.lg,
|
|
10
|
+
marginTop: Spacing.lg,
|
|
11
|
+
},
|
|
12
|
+
label: {
|
|
13
|
+
color: Colors.label,
|
|
14
|
+
fontWeight: "600",
|
|
15
|
+
fontSize: FontSize.sm,
|
|
16
|
+
marginBottom: 5,
|
|
17
|
+
},
|
|
18
|
+
inputTrigger: {
|
|
19
|
+
backgroundColor: Colors.inputBg,
|
|
20
|
+
borderRadius: BorderRadius.lg,
|
|
21
|
+
paddingHorizontal: Spacing.lg,
|
|
22
|
+
paddingVertical: Spacing.md,
|
|
23
|
+
minHeight: 56,
|
|
24
|
+
justifyContent: "center",
|
|
25
|
+
},
|
|
26
|
+
inputTriggerRow: {
|
|
27
|
+
flexDirection: "row",
|
|
28
|
+
alignItems: "center",
|
|
29
|
+
justifyContent: "space-between",
|
|
30
|
+
},
|
|
31
|
+
inputTriggerText: {
|
|
32
|
+
fontSize: FontSize.md,
|
|
33
|
+
color: Colors.text,
|
|
34
|
+
flex: 1,
|
|
35
|
+
fontWeight: "400",
|
|
36
|
+
},
|
|
37
|
+
inputTriggerPlaceholder: {
|
|
38
|
+
color: Colors.textTertiary,
|
|
39
|
+
},
|
|
40
|
+
inputTriggerCode: {
|
|
41
|
+
fontSize: FontSize.sm,
|
|
42
|
+
color: Colors.textTertiary,
|
|
43
|
+
fontWeight: "400",
|
|
44
|
+
marginLeft: Spacing.sm,
|
|
45
|
+
},
|
|
46
|
+
searchButton: {
|
|
47
|
+
borderRadius: BorderRadius.lg,
|
|
48
|
+
paddingVertical: Spacing.lg,
|
|
49
|
+
alignItems: "center",
|
|
50
|
+
justifyContent: "center",
|
|
51
|
+
minHeight: 48,
|
|
52
|
+
},
|
|
53
|
+
searchButtonDisabled: {
|
|
54
|
+
opacity: 0.7,
|
|
55
|
+
},
|
|
56
|
+
searchButtonContent: {
|
|
57
|
+
flexDirection: "row",
|
|
58
|
+
alignItems: "center",
|
|
59
|
+
gap: Spacing.sm,
|
|
60
|
+
},
|
|
61
|
+
searchButtonText: {
|
|
62
|
+
color: Colors.textOnPrimary,
|
|
63
|
+
fontSize: FontSize.lg,
|
|
64
|
+
fontWeight: "500",
|
|
65
|
+
},
|
|
66
|
+
errorText: {
|
|
67
|
+
fontSize: FontSize.sm,
|
|
68
|
+
color: Colors.error,
|
|
69
|
+
marginTop: Spacing.xs,
|
|
70
|
+
fontWeight: "500",
|
|
71
|
+
},
|
|
72
|
+
searchError: {
|
|
73
|
+
fontSize: FontSize.sm,
|
|
74
|
+
color: Colors.error,
|
|
75
|
+
textAlign: "center",
|
|
76
|
+
padding: Spacing.sm,
|
|
77
|
+
},
|
|
78
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function applyWidgetColors(_config: any): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const normalizeDateTimeFormat = (value) => {
|
|
2
|
+
return value === "usa" ? "usa" : "europe";
|
|
3
|
+
};
|
|
4
|
+
export const formatTimeByDateTimeFormat = (value, dateTimeFormat, fallback = "--:--") => {
|
|
5
|
+
if (!value || typeof value !== "string")
|
|
6
|
+
return fallback;
|
|
7
|
+
const date = new Date(value);
|
|
8
|
+
if (isNaN(date.getTime()))
|
|
9
|
+
return fallback;
|
|
10
|
+
const format = normalizeDateTimeFormat(dateTimeFormat);
|
|
11
|
+
const isUsa = format === "usa";
|
|
12
|
+
return date.toLocaleTimeString(isUsa ? "en-US" : "ru-RU", isUsa
|
|
13
|
+
? {
|
|
14
|
+
hour: "numeric",
|
|
15
|
+
minute: "2-digit",
|
|
16
|
+
hour12: true,
|
|
17
|
+
}
|
|
18
|
+
: {
|
|
19
|
+
hour: "2-digit",
|
|
20
|
+
minute: "2-digit",
|
|
21
|
+
hour12: false,
|
|
22
|
+
});
|
|
23
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type SSEEvent = {
|
|
2
|
+
event: string;
|
|
3
|
+
data: string;
|
|
4
|
+
};
|
|
5
|
+
export declare function parseSSEBuffer(buffer: string): {
|
|
6
|
+
events: SSEEvent[];
|
|
7
|
+
remainder: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function mergeHotels(existing: Map<string, any>, batch: any[]): {
|
|
10
|
+
merged: Map<string, any>;
|
|
11
|
+
updated: Set<string>;
|
|
12
|
+
};
|
|
13
|
+
type FetchSSEOptions = {
|
|
14
|
+
url: string;
|
|
15
|
+
body: Record<string, any>;
|
|
16
|
+
token: string;
|
|
17
|
+
onEvent: (event: string, data: string) => void;
|
|
18
|
+
onError: (error: Error) => void;
|
|
19
|
+
onComplete: () => void;
|
|
20
|
+
signal?: AbortSignal;
|
|
21
|
+
};
|
|
22
|
+
export declare function fetchSSE({ url, body, token, onEvent, onError, onComplete, signal, }: FetchSSEOptions): void;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
export function parseSSEBuffer(buffer) {
|
|
2
|
+
const events = [];
|
|
3
|
+
const blocks = buffer.split("\n\n");
|
|
4
|
+
const remainder = blocks.pop() || "";
|
|
5
|
+
for (const block of blocks) {
|
|
6
|
+
if (!block.trim())
|
|
7
|
+
continue;
|
|
8
|
+
let eventName = "";
|
|
9
|
+
const dataLines = [];
|
|
10
|
+
for (const line of block.split("\n")) {
|
|
11
|
+
if (line.startsWith("event:")) {
|
|
12
|
+
eventName = line.slice(6).trim();
|
|
13
|
+
}
|
|
14
|
+
else if (line.startsWith("data:")) {
|
|
15
|
+
dataLines.push(line.slice(5).trim());
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (eventName || dataLines.length > 0) {
|
|
19
|
+
events.push({ event: eventName, data: dataLines.join("\n") });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return { events, remainder };
|
|
23
|
+
}
|
|
24
|
+
export function mergeHotels(existing, batch) {
|
|
25
|
+
const merged = new Map(existing);
|
|
26
|
+
const updated = new Set();
|
|
27
|
+
for (const hotel of batch) {
|
|
28
|
+
const id = String(hotel.id);
|
|
29
|
+
const prev = merged.get(id);
|
|
30
|
+
if (prev && hotel.price != null && hotel.price < prev.price) {
|
|
31
|
+
updated.add(id);
|
|
32
|
+
merged.set(id, hotel);
|
|
33
|
+
}
|
|
34
|
+
else if (!prev) {
|
|
35
|
+
merged.set(id, hotel);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return { merged, updated };
|
|
39
|
+
}
|
|
40
|
+
export function fetchSSE({ url, body, token, onEvent, onError, onComplete, signal, }) {
|
|
41
|
+
const xhr = new XMLHttpRequest();
|
|
42
|
+
let buffer = "";
|
|
43
|
+
let processedLength = 0;
|
|
44
|
+
if (signal) {
|
|
45
|
+
if (signal.aborted) {
|
|
46
|
+
onError(new DOMException("Aborted", "AbortError"));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const onAbort = () => {
|
|
50
|
+
xhr.abort();
|
|
51
|
+
};
|
|
52
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
53
|
+
xhr.addEventListener("loadend", () => {
|
|
54
|
+
signal.removeEventListener("abort", onAbort);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
xhr.open("POST", url, true);
|
|
58
|
+
xhr.setRequestHeader("Content-Type", "application/json");
|
|
59
|
+
xhr.setRequestHeader("Accept", "text/event-stream");
|
|
60
|
+
xhr.setRequestHeader("Authorization", `Bearer ${token}`);
|
|
61
|
+
xhr.responseType = "";
|
|
62
|
+
xhr.onprogress = () => {
|
|
63
|
+
const newText = xhr.responseText.slice(processedLength);
|
|
64
|
+
processedLength = xhr.responseText.length;
|
|
65
|
+
if (!newText)
|
|
66
|
+
return;
|
|
67
|
+
buffer += newText;
|
|
68
|
+
const { events, remainder } = parseSSEBuffer(buffer);
|
|
69
|
+
buffer = remainder;
|
|
70
|
+
for (const sse of events) {
|
|
71
|
+
if (signal?.aborted)
|
|
72
|
+
break;
|
|
73
|
+
onEvent(sse.event, sse.data);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
xhr.onload = () => {
|
|
77
|
+
if (buffer.trim()) {
|
|
78
|
+
const { events } = parseSSEBuffer(buffer + "\n\n");
|
|
79
|
+
for (const sse of events) {
|
|
80
|
+
if (signal?.aborted)
|
|
81
|
+
break;
|
|
82
|
+
onEvent(sse.event, sse.data);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
86
|
+
onComplete();
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
onError(new Error(`Stream request failed: ${xhr.status}`));
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
xhr.onerror = () => {
|
|
93
|
+
onError(new Error("Network error during SSE stream"));
|
|
94
|
+
};
|
|
95
|
+
xhr.ontimeout = () => {
|
|
96
|
+
onError(new Error("SSE stream timed out"));
|
|
97
|
+
};
|
|
98
|
+
xhr.onabort = () => {
|
|
99
|
+
const err = new DOMException("Aborted", "AbortError");
|
|
100
|
+
onError(err);
|
|
101
|
+
};
|
|
102
|
+
xhr.timeout = 180000;
|
|
103
|
+
xhr.send(JSON.stringify(body));
|
|
104
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useWidget } from "../context/WidgetContext";
|
|
2
|
+
export function useApiToken() {
|
|
3
|
+
const { token } = useWidget();
|
|
4
|
+
return token;
|
|
5
|
+
}
|
|
6
|
+
let _token = "";
|
|
7
|
+
export function setGlobalToken(t) {
|
|
8
|
+
_token = t;
|
|
9
|
+
}
|
|
10
|
+
export function getApiToken() {
|
|
11
|
+
return _token;
|
|
12
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@devtravelcode/widget-native",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "TravelHub search widget for React Native (flights, hotels, cars)",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"!dist/**/*.map"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
13
|
+
"prepublishOnly": "npm run build",
|
|
14
|
+
"test": "npx tsc --noEmit",
|
|
15
|
+
"start": "npx expo start",
|
|
16
|
+
"android": "npx expo start --android",
|
|
17
|
+
"ios": "npx expo start --ios"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"@react-native-async-storage/async-storage": ">=1.21.0",
|
|
21
|
+
"react": ">=18.0.0",
|
|
22
|
+
"react-native": ">=0.72.0",
|
|
23
|
+
"react-native-gesture-handler": ">=2.14.0",
|
|
24
|
+
"react-native-maps": ">=1.10.0",
|
|
25
|
+
"react-native-reanimated": ">=3.6.0",
|
|
26
|
+
"react-native-safe-area-context": ">=4.8.0",
|
|
27
|
+
"react-native-svg": ">=14.0.0"
|
|
28
|
+
},
|
|
29
|
+
"peerDependenciesMeta": {
|
|
30
|
+
"react-native-maps": {
|
|
31
|
+
"optional": true
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@reduxjs/toolkit": "^2.9.0",
|
|
36
|
+
"date-fns": "^4.1.0",
|
|
37
|
+
"react-native-map-clustering": "^4.0.0",
|
|
38
|
+
"react-redux": "^9.2.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@react-native-async-storage/async-storage": "^2.1.2",
|
|
42
|
+
"@types/react": "~19.1.10",
|
|
43
|
+
"expo": "~54.0.0",
|
|
44
|
+
"expo-asset": "~12.0.12",
|
|
45
|
+
"expo-constants": "~18.0.13",
|
|
46
|
+
"expo-file-system": "~19.0.21",
|
|
47
|
+
"expo-font": "~14.0.11",
|
|
48
|
+
"expo-status-bar": "~3.0.9",
|
|
49
|
+
"lucide-react-native": "^0.475.0",
|
|
50
|
+
"react": "^19.1.0",
|
|
51
|
+
"react-native": "^0.81.5",
|
|
52
|
+
"react-native-gesture-handler": "~2.28.0",
|
|
53
|
+
"react-native-maps": "^1.20.1",
|
|
54
|
+
"react-native-reanimated": "~3.16.0",
|
|
55
|
+
"react-native-safe-area-context": "~5.4.0",
|
|
56
|
+
"react-native-svg": "^15.12.1",
|
|
57
|
+
"typescript": "^5.9.2"
|
|
58
|
+
},
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"access": "public"
|
|
61
|
+
},
|
|
62
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
63
|
+
"private": false
|
|
64
|
+
}
|