google-fli 0.1.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 +21 -0
- package/README.md +158 -0
- package/dist/core/airports.d.ts +31 -0
- package/dist/core/airports.d.ts.map +1 -0
- package/dist/core/airports.js +168 -0
- package/dist/core/airports.js.map +1 -0
- package/dist/core/builders.d.ts +30 -0
- package/dist/core/builders.d.ts.map +1 -0
- package/dist/core/builders.js +113 -0
- package/dist/core/builders.js.map +1 -0
- package/dist/core/currency.d.ts +21 -0
- package/dist/core/currency.d.ts.map +1 -0
- package/dist/core/currency.js +172 -0
- package/dist/core/currency.js.map +1 -0
- package/dist/core/dates.d.ts +22 -0
- package/dist/core/dates.d.ts.map +1 -0
- package/dist/core/dates.js +41 -0
- package/dist/core/dates.js.map +1 -0
- package/dist/core/index.d.ts +7 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +7 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/links.d.ts +39 -0
- package/dist/core/links.d.ts.map +1 -0
- package/dist/core/links.js +53 -0
- package/dist/core/links.js.map +1 -0
- package/dist/core/parsers.d.ts +34 -0
- package/dist/core/parsers.d.ts.map +1 -0
- package/dist/core/parsers.js +161 -0
- package/dist/core/parsers.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/models/airline.d.ts +1120 -0
- package/dist/models/airline.d.ts.map +1 -0
- package/dist/models/airline.js +2224 -0
- package/dist/models/airline.js.map +1 -0
- package/dist/models/airport.d.ts +7899 -0
- package/dist/models/airport.d.ts.map +1 -0
- package/dist/models/airport.js +15782 -0
- package/dist/models/airport.js.map +1 -0
- package/dist/models/google-flights/base.d.ts +232 -0
- package/dist/models/google-flights/base.d.ts.map +1 -0
- package/dist/models/google-flights/base.js +188 -0
- package/dist/models/google-flights/base.js.map +1 -0
- package/dist/models/google-flights/dates.d.ts +51 -0
- package/dist/models/google-flights/dates.d.ts.map +1 -0
- package/dist/models/google-flights/dates.js +222 -0
- package/dist/models/google-flights/dates.js.map +1 -0
- package/dist/models/google-flights/flights.d.ts +57 -0
- package/dist/models/google-flights/flights.d.ts.map +1 -0
- package/dist/models/google-flights/flights.js +224 -0
- package/dist/models/google-flights/flights.js.map +1 -0
- package/dist/models/google-flights/index.d.ts +4 -0
- package/dist/models/google-flights/index.d.ts.map +1 -0
- package/dist/models/google-flights/index.js +4 -0
- package/dist/models/google-flights/index.js.map +1 -0
- package/dist/models/index.d.ts +4 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +4 -0
- package/dist/models/index.js.map +1 -0
- package/dist/search/client.d.ts +66 -0
- package/dist/search/client.d.ts.map +1 -0
- package/dist/search/client.js +205 -0
- package/dist/search/client.js.map +1 -0
- package/dist/search/concurrency.d.ts +45 -0
- package/dist/search/concurrency.d.ts.map +1 -0
- package/dist/search/concurrency.js +148 -0
- package/dist/search/concurrency.js.map +1 -0
- package/dist/search/dates.d.ts +33 -0
- package/dist/search/dates.d.ts.map +1 -0
- package/dist/search/dates.js +159 -0
- package/dist/search/dates.js.map +1 -0
- package/dist/search/decoders.d.ts +22 -0
- package/dist/search/decoders.d.ts.map +1 -0
- package/dist/search/decoders.js +333 -0
- package/dist/search/decoders.js.map +1 -0
- package/dist/search/exceptions.d.ts +21 -0
- package/dist/search/exceptions.d.ts.map +1 -0
- package/dist/search/exceptions.js +37 -0
- package/dist/search/exceptions.js.map +1 -0
- package/dist/search/flights.d.ts +57 -0
- package/dist/search/flights.d.ts.map +1 -0
- package/dist/search/flights.js +298 -0
- package/dist/search/flights.js.map +1 -0
- package/dist/search/helpers.d.ts +10 -0
- package/dist/search/helpers.d.ts.map +1 -0
- package/dist/search/helpers.js +30 -0
- package/dist/search/helpers.js.map +1 -0
- package/dist/search/index.d.ts +10 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +10 -0
- package/dist/search/index.js.map +1 -0
- package/dist/search/proto.d.ts +69 -0
- package/dist/search/proto.d.ts.map +1 -0
- package/dist/search/proto.js +355 -0
- package/dist/search/proto.js.map +1 -0
- package/dist/search/urls.d.ts +9 -0
- package/dist/search/urls.d.ts.map +1 -0
- package/dist/search/urls.js +9 -0
- package/dist/search/urls.js.map +1 -0
- package/dist/search/wire.d.ts +14 -0
- package/dist/search/wire.d.ts.map +1 -0
- package/dist/search/wire.js +120 -0
- package/dist/search/wire.js.map +1 -0
- package/package.json +91 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DateSearchFilters — payload for Google Flights' GetCalendarGraph endpoint.
|
|
3
|
+
*
|
|
4
|
+
* 1:1 port of fli/models/google_flights/dates.py.
|
|
5
|
+
*/
|
|
6
|
+
import { formatIsoDate, parseIsoDate } from "../../core/dates.js";
|
|
7
|
+
import { AIRLINE_NAMES } from "../airline.js";
|
|
8
|
+
import { EmissionsFilter, MaxStops, SeatType, TripType, } from "./base.js";
|
|
9
|
+
const MAX_PAST_FROM_DATE_DAYS = 6;
|
|
10
|
+
function airlineSortKey(a) {
|
|
11
|
+
const code = a.startsWith("_") ? a.slice(1) : a;
|
|
12
|
+
return AIRLINE_NAMES[code] ?? code;
|
|
13
|
+
}
|
|
14
|
+
function serializeCode(code) {
|
|
15
|
+
return code.startsWith("_") ? code.slice(1) : code;
|
|
16
|
+
}
|
|
17
|
+
function todayUtc() {
|
|
18
|
+
const now = new Date();
|
|
19
|
+
return new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
|
|
20
|
+
}
|
|
21
|
+
export class DateSearchFilters {
|
|
22
|
+
trip_type;
|
|
23
|
+
passenger_info;
|
|
24
|
+
flight_segments;
|
|
25
|
+
stops;
|
|
26
|
+
seat_type;
|
|
27
|
+
price_limit;
|
|
28
|
+
airlines;
|
|
29
|
+
airlines_exclude;
|
|
30
|
+
alliances;
|
|
31
|
+
alliances_exclude;
|
|
32
|
+
max_duration;
|
|
33
|
+
layover_restrictions;
|
|
34
|
+
emissions;
|
|
35
|
+
bags;
|
|
36
|
+
from_date;
|
|
37
|
+
to_date;
|
|
38
|
+
duration;
|
|
39
|
+
constructor(input) {
|
|
40
|
+
this.trip_type = input.trip_type ?? TripType.ONE_WAY;
|
|
41
|
+
this.passenger_info = input.passenger_info;
|
|
42
|
+
this.flight_segments = input.flight_segments;
|
|
43
|
+
this.stops = input.stops ?? MaxStops.ANY;
|
|
44
|
+
this.seat_type = input.seat_type ?? SeatType.ECONOMY;
|
|
45
|
+
this.price_limit = input.price_limit ?? null;
|
|
46
|
+
this.airlines = input.airlines ?? null;
|
|
47
|
+
this.airlines_exclude = input.airlines_exclude ?? null;
|
|
48
|
+
this.alliances = input.alliances ?? null;
|
|
49
|
+
this.alliances_exclude = input.alliances_exclude ?? null;
|
|
50
|
+
this.max_duration = input.max_duration ?? null;
|
|
51
|
+
this.layover_restrictions = input.layover_restrictions ?? null;
|
|
52
|
+
this.emissions = input.emissions ?? EmissionsFilter.ALL;
|
|
53
|
+
this.bags = input.bags ?? null;
|
|
54
|
+
this.duration = input.duration ?? null;
|
|
55
|
+
// Validate / coerce the date range.
|
|
56
|
+
let { from_date, to_date } = input;
|
|
57
|
+
// Trip-type-specific segment-count validation.
|
|
58
|
+
if (this.trip_type === TripType.ONE_WAY && this.flight_segments.length !== 1) {
|
|
59
|
+
throw new Error("One-way trip must have one flight segment");
|
|
60
|
+
}
|
|
61
|
+
if (this.trip_type === TripType.ROUND_TRIP && this.flight_segments.length !== 2) {
|
|
62
|
+
throw new Error("Round trip must have two flight segments");
|
|
63
|
+
}
|
|
64
|
+
if (this.trip_type === TripType.ROUND_TRIP && this.duration == null) {
|
|
65
|
+
throw new Error("Duration must be set for round trip flights");
|
|
66
|
+
}
|
|
67
|
+
if (this.duration != null && this.flight_segments.length === 2) {
|
|
68
|
+
const a = this.flight_segments[0]?.parsed_travel_date.getTime() ?? 0;
|
|
69
|
+
const b = this.flight_segments[1]?.parsed_travel_date.getTime() ?? 0;
|
|
70
|
+
const diffDays = Math.round((b - a) / (1000 * 60 * 60 * 24));
|
|
71
|
+
if (diffDays !== this.duration) {
|
|
72
|
+
throw new Error("Flight segments travel dates difference must match duration");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// Swap from/to if from > to (mirrors the Python validator).
|
|
76
|
+
const fromDate = parseIsoDate(from_date);
|
|
77
|
+
const toDate = parseIsoDate(to_date);
|
|
78
|
+
if (fromDate > toDate) {
|
|
79
|
+
const swappedFrom = formatIsoDate(toDate);
|
|
80
|
+
const swappedTo = formatIsoDate(fromDate);
|
|
81
|
+
from_date = swappedFrom;
|
|
82
|
+
to_date = swappedTo;
|
|
83
|
+
}
|
|
84
|
+
// to_date must be strictly in the future.
|
|
85
|
+
const today = todayUtc();
|
|
86
|
+
if (parseIsoDate(to_date) <= today) {
|
|
87
|
+
throw new Error("To date must be in the future");
|
|
88
|
+
}
|
|
89
|
+
// If from_date is more than MAX_PAST_FROM_DATE_DAYS in the past, snap to today.
|
|
90
|
+
const fromParsed = parseIsoDate(from_date);
|
|
91
|
+
if (fromParsed < today) {
|
|
92
|
+
const deltaDays = Math.round((today.getTime() - fromParsed.getTime()) / (1000 * 60 * 60 * 24));
|
|
93
|
+
if (deltaDays > MAX_PAST_FROM_DATE_DAYS) {
|
|
94
|
+
from_date = formatIsoDate(today);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
this.from_date = from_date;
|
|
98
|
+
this.to_date = to_date;
|
|
99
|
+
}
|
|
100
|
+
get parsed_from_date() {
|
|
101
|
+
return parseIsoDate(this.from_date);
|
|
102
|
+
}
|
|
103
|
+
get parsed_to_date() {
|
|
104
|
+
return parseIsoDate(this.to_date);
|
|
105
|
+
}
|
|
106
|
+
format() {
|
|
107
|
+
const formattedSegments = [];
|
|
108
|
+
for (const segment of this.flight_segments) {
|
|
109
|
+
const departureBlock = [
|
|
110
|
+
segment.departure_airport.map((airports) => airports.map((airport) => [serializeCode(airport[0]), airport[1]])),
|
|
111
|
+
];
|
|
112
|
+
const arrivalBlock = [
|
|
113
|
+
segment.arrival_airport.map((airports) => airports.map((airport) => [serializeCode(airport[0]), airport[1]])),
|
|
114
|
+
];
|
|
115
|
+
const tr = segment.time_restrictions;
|
|
116
|
+
const timeFilters = tr
|
|
117
|
+
? [
|
|
118
|
+
tr.earliest_departure ?? null,
|
|
119
|
+
tr.latest_departure ?? null,
|
|
120
|
+
tr.earliest_arrival ?? null,
|
|
121
|
+
tr.latest_arrival ?? null,
|
|
122
|
+
]
|
|
123
|
+
: null;
|
|
124
|
+
const includeTokens = [];
|
|
125
|
+
if (this.airlines?.length) {
|
|
126
|
+
const sorted = [...this.airlines].sort((a, b) => {
|
|
127
|
+
const ka = airlineSortKey(a);
|
|
128
|
+
const kb = airlineSortKey(b);
|
|
129
|
+
return ka < kb ? -1 : ka > kb ? 1 : 0;
|
|
130
|
+
});
|
|
131
|
+
for (const a of sorted)
|
|
132
|
+
includeTokens.push(serializeCode(a));
|
|
133
|
+
}
|
|
134
|
+
if (this.alliances?.length) {
|
|
135
|
+
for (const a of [...this.alliances].sort())
|
|
136
|
+
includeTokens.push(a);
|
|
137
|
+
}
|
|
138
|
+
const airlinesFilters = includeTokens.length ? includeTokens : null;
|
|
139
|
+
const excludeTokens = [];
|
|
140
|
+
if (this.airlines_exclude?.length) {
|
|
141
|
+
const sorted = [...this.airlines_exclude].sort((a, b) => {
|
|
142
|
+
const ka = airlineSortKey(a);
|
|
143
|
+
const kb = airlineSortKey(b);
|
|
144
|
+
return ka < kb ? -1 : ka > kb ? 1 : 0;
|
|
145
|
+
});
|
|
146
|
+
for (const a of sorted)
|
|
147
|
+
excludeTokens.push(serializeCode(a));
|
|
148
|
+
}
|
|
149
|
+
if (this.alliances_exclude?.length) {
|
|
150
|
+
for (const a of [...this.alliances_exclude].sort())
|
|
151
|
+
excludeTokens.push(a);
|
|
152
|
+
}
|
|
153
|
+
const excludeFilters = excludeTokens.length ? excludeTokens : null;
|
|
154
|
+
const layoverAirports = this.layover_restrictions?.airports?.length
|
|
155
|
+
? this.layover_restrictions.airports.map(serializeCode)
|
|
156
|
+
: null;
|
|
157
|
+
const layoverMin = this.layover_restrictions?.min_duration ?? null;
|
|
158
|
+
const layoverMax = this.layover_restrictions?.max_duration ?? null;
|
|
159
|
+
const emissionsFilter = this.emissions !== EmissionsFilter.ALL ? [this.emissions] : null;
|
|
160
|
+
formattedSegments.push([
|
|
161
|
+
departureBlock[0],
|
|
162
|
+
arrivalBlock[0],
|
|
163
|
+
timeFilters,
|
|
164
|
+
this.stops,
|
|
165
|
+
airlinesFilters,
|
|
166
|
+
excludeFilters,
|
|
167
|
+
segment.travel_date,
|
|
168
|
+
this.max_duration != null ? [this.max_duration] : null,
|
|
169
|
+
null, // 8: selected flight (unused in date search)
|
|
170
|
+
layoverAirports,
|
|
171
|
+
null,
|
|
172
|
+
layoverMin,
|
|
173
|
+
layoverMax,
|
|
174
|
+
emissionsFilter,
|
|
175
|
+
3, // 14: hardcoded
|
|
176
|
+
]);
|
|
177
|
+
}
|
|
178
|
+
const bagsFilter = this.bags
|
|
179
|
+
? [this.bags.checked_bags, this.bags.carry_on ? 1 : 0]
|
|
180
|
+
: null;
|
|
181
|
+
const base = [
|
|
182
|
+
null,
|
|
183
|
+
[
|
|
184
|
+
null, // [0]
|
|
185
|
+
null, // [1]
|
|
186
|
+
this.trip_type, // [2]
|
|
187
|
+
null, // [3]
|
|
188
|
+
[], // [4]
|
|
189
|
+
this.seat_type, // [5]
|
|
190
|
+
[
|
|
191
|
+
this.passenger_info.adults,
|
|
192
|
+
this.passenger_info.children,
|
|
193
|
+
this.passenger_info.infants_on_lap,
|
|
194
|
+
this.passenger_info.infants_in_seat,
|
|
195
|
+
], // [6]
|
|
196
|
+
this.price_limit ? [null, this.price_limit.max_price] : null, // [7]
|
|
197
|
+
null, // [8]
|
|
198
|
+
null, // [9]
|
|
199
|
+
bagsFilter, // [10]
|
|
200
|
+
null, // [11]
|
|
201
|
+
null, // [12]
|
|
202
|
+
formattedSegments,
|
|
203
|
+
null, // [14]
|
|
204
|
+
null, // [15]
|
|
205
|
+
null, // [16]
|
|
206
|
+
1, // [17]
|
|
207
|
+
],
|
|
208
|
+
[this.from_date, this.to_date],
|
|
209
|
+
];
|
|
210
|
+
if (this.trip_type === TripType.ROUND_TRIP) {
|
|
211
|
+
base.push(null, [this.duration, this.duration]);
|
|
212
|
+
}
|
|
213
|
+
return base;
|
|
214
|
+
}
|
|
215
|
+
encode() {
|
|
216
|
+
const formatted = this.format();
|
|
217
|
+
const formattedJson = JSON.stringify(formatted);
|
|
218
|
+
const wrapped = [null, formattedJson];
|
|
219
|
+
return encodeURIComponent(JSON.stringify(wrapped));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=dates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dates.js","sourceRoot":"","sources":["../../../src/models/google-flights/dates.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAgB,MAAM,eAAe,CAAC;AAC5D,OAAO,EAGL,eAAe,EAGf,QAAQ,EAGR,QAAQ,EACR,QAAQ,GACT,MAAM,WAAW,CAAC;AAEnB,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAElC,SAAS,cAAc,CAAC,CAAU;IAChC,MAAM,IAAI,GAAG,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;AACrC,CAAC;AAED,SAAS,aAAa,CAAC,IAAY;IACjC,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,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gBACZ,IAAI,EAAE,MAAM;gBACZ,UAAU,EAAE,OAAO;gBACnB,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,OAAO;gBACb,iBAAiB;gBACjB,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,OAAO;gBACb,CAAC,EAAE,OAAO;aACX;YACD,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC;SAC/B,CAAC;QAEF,IAAI,IAAI,CAAC,SAAS,KAAK,QAAQ,CAAC,UAAU,EAAE,CAAC;YAC3C,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;QAClD,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM;QACJ,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAChC,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAChD,MAAM,OAAO,GAAc,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QACjD,OAAO,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IACrD,CAAC;CACF"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FlightSearchFilters — produces the nested-list payload Google's
|
|
3
|
+
* FlightsFrontendService.GetShoppingResults endpoint expects.
|
|
4
|
+
*
|
|
5
|
+
* 1:1 port of fli/models/google_flights/flights.py — the formatted output
|
|
6
|
+
* must remain byte-identical to the Python implementation (see
|
|
7
|
+
* tests/integration/test_filter_format_snapshots.test.ts).
|
|
8
|
+
*/
|
|
9
|
+
import { type Airline } from "../airline.ts";
|
|
10
|
+
import { type Alliance, type BagsFilter, EmissionsFilter, type FlightSegment, type LayoverRestrictions, MaxStops, type PassengerInfo, type PriceLimit, SeatType, SortBy, TripType } from "./base.ts";
|
|
11
|
+
export interface FlightSearchFiltersInput {
|
|
12
|
+
trip_type?: TripType;
|
|
13
|
+
passenger_info: PassengerInfo;
|
|
14
|
+
flight_segments: FlightSegment[];
|
|
15
|
+
stops?: MaxStops;
|
|
16
|
+
seat_type?: SeatType;
|
|
17
|
+
price_limit?: PriceLimit | null;
|
|
18
|
+
airlines?: Airline[] | null;
|
|
19
|
+
airlines_exclude?: Airline[] | null;
|
|
20
|
+
alliances?: Alliance[] | null;
|
|
21
|
+
alliances_exclude?: Alliance[] | null;
|
|
22
|
+
max_duration?: number | null;
|
|
23
|
+
layover_restrictions?: LayoverRestrictions | null;
|
|
24
|
+
sort_by?: SortBy;
|
|
25
|
+
exclude_basic_economy?: boolean;
|
|
26
|
+
emissions?: EmissionsFilter;
|
|
27
|
+
bags?: BagsFilter | null;
|
|
28
|
+
show_all_results?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export declare class FlightSearchFilters {
|
|
31
|
+
trip_type: TripType;
|
|
32
|
+
passenger_info: PassengerInfo;
|
|
33
|
+
flight_segments: FlightSegment[];
|
|
34
|
+
stops: MaxStops;
|
|
35
|
+
seat_type: SeatType;
|
|
36
|
+
price_limit: PriceLimit | null;
|
|
37
|
+
airlines: Airline[] | null;
|
|
38
|
+
airlines_exclude: Airline[] | null;
|
|
39
|
+
alliances: Alliance[] | null;
|
|
40
|
+
alliances_exclude: Alliance[] | null;
|
|
41
|
+
max_duration: number | null;
|
|
42
|
+
layover_restrictions: LayoverRestrictions | null;
|
|
43
|
+
sort_by: SortBy;
|
|
44
|
+
exclude_basic_economy: boolean;
|
|
45
|
+
emissions: EmissionsFilter;
|
|
46
|
+
bags: BagsFilter | null;
|
|
47
|
+
show_all_results: boolean;
|
|
48
|
+
constructor(input: FlightSearchFiltersInput);
|
|
49
|
+
/**
|
|
50
|
+
* Render the nested-list payload Google's GetShoppingResults RPC accepts.
|
|
51
|
+
* See the position map in the upstream Python flights.py.
|
|
52
|
+
*/
|
|
53
|
+
format(): unknown[];
|
|
54
|
+
/** URL-encode the formatted filters into the `f.req` body. */
|
|
55
|
+
encode(): string;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=flights.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flights.d.ts","sourceRoot":"","sources":["../../../src/models/google-flights/flights.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAiB,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,eAAe,EACf,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,QAAQ,EACR,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,QAAQ,EACR,MAAM,EACN,QAAQ,EACT,MAAM,WAAW,CAAC;AAWnB,MAAM,WAAW,wBAAwB;IACvC,SAAS,CAAC,EAAE,QAAQ,CAAC;IACrB,cAAc,EAAE,aAAa,CAAC;IAC9B,eAAe,EAAE,aAAa,EAAE,CAAC;IACjC,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,SAAS,CAAC,EAAE,QAAQ,CAAC;IACrB,WAAW,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC5B,gBAAgB,CAAC,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACpC,SAAS,CAAC,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IAC9B,iBAAiB,CAAC,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IACtC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,oBAAoB,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAClD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IACzB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAQD,qBAAa,mBAAmB;IAC9B,SAAS,EAAE,QAAQ,CAAC;IACpB,cAAc,EAAE,aAAa,CAAC;IAC9B,eAAe,EAAE,aAAa,EAAE,CAAC;IACjC,KAAK,EAAE,QAAQ,CAAC;IAChB,SAAS,EAAE,QAAQ,CAAC;IACpB,WAAW,EAAE,UAAU,GAAG,IAAI,CAAC;IAC/B,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC3B,gBAAgB,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACnC,SAAS,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IAC7B,iBAAiB,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IACrC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,oBAAoB,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACjD,OAAO,EAAE,MAAM,CAAC;IAChB,qBAAqB,EAAE,OAAO,CAAC;IAC/B,SAAS,EAAE,eAAe,CAAC;IAC3B,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC;IACxB,gBAAgB,EAAE,OAAO,CAAC;gBAEd,KAAK,EAAE,wBAAwB;IAoB3C;;;OAGG;IACH,MAAM,IAAI,OAAO,EAAE;IAwJnB,8DAA8D;IAC9D,MAAM,IAAI,MAAM;CAMjB"}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FlightSearchFilters — produces the nested-list payload Google's
|
|
3
|
+
* FlightsFrontendService.GetShoppingResults endpoint expects.
|
|
4
|
+
*
|
|
5
|
+
* 1:1 port of fli/models/google_flights/flights.py — the formatted output
|
|
6
|
+
* must remain byte-identical to the Python implementation (see
|
|
7
|
+
* tests/integration/test_filter_format_snapshots.test.ts).
|
|
8
|
+
*/
|
|
9
|
+
import { AIRLINE_NAMES } from "../airline.js";
|
|
10
|
+
import { EmissionsFilter, MaxStops, SeatType, SortBy, TripType, } from "./base.js";
|
|
11
|
+
function airlineSortKey(a) {
|
|
12
|
+
// Match Python's `sorted(airlines, key=lambda x: x.value)` — Python's
|
|
13
|
+
// Airline.X.value is the human-readable name. In TS the const value is
|
|
14
|
+
// the code; look up the name via AIRLINE_NAMES so encoding stays
|
|
15
|
+
// byte-identical to the Python upstream.
|
|
16
|
+
const code = serializeCode(a);
|
|
17
|
+
return AIRLINE_NAMES[code] ?? code;
|
|
18
|
+
}
|
|
19
|
+
function serializeCode(code) {
|
|
20
|
+
// Strip the leading "_" used to make digit-prefixed IATA codes valid
|
|
21
|
+
// identifiers in the Airline / Airport const objects.
|
|
22
|
+
return code.startsWith("_") ? code.slice(1) : code;
|
|
23
|
+
}
|
|
24
|
+
export class FlightSearchFilters {
|
|
25
|
+
trip_type;
|
|
26
|
+
passenger_info;
|
|
27
|
+
flight_segments;
|
|
28
|
+
stops;
|
|
29
|
+
seat_type;
|
|
30
|
+
price_limit;
|
|
31
|
+
airlines;
|
|
32
|
+
airlines_exclude;
|
|
33
|
+
alliances;
|
|
34
|
+
alliances_exclude;
|
|
35
|
+
max_duration;
|
|
36
|
+
layover_restrictions;
|
|
37
|
+
sort_by;
|
|
38
|
+
exclude_basic_economy;
|
|
39
|
+
emissions;
|
|
40
|
+
bags;
|
|
41
|
+
show_all_results;
|
|
42
|
+
constructor(input) {
|
|
43
|
+
this.trip_type = input.trip_type ?? TripType.ONE_WAY;
|
|
44
|
+
this.passenger_info = input.passenger_info;
|
|
45
|
+
this.flight_segments = input.flight_segments;
|
|
46
|
+
this.stops = input.stops ?? MaxStops.ANY;
|
|
47
|
+
this.seat_type = input.seat_type ?? SeatType.ECONOMY;
|
|
48
|
+
this.price_limit = input.price_limit ?? null;
|
|
49
|
+
this.airlines = input.airlines ?? null;
|
|
50
|
+
this.airlines_exclude = input.airlines_exclude ?? null;
|
|
51
|
+
this.alliances = input.alliances ?? null;
|
|
52
|
+
this.alliances_exclude = input.alliances_exclude ?? null;
|
|
53
|
+
this.max_duration = input.max_duration ?? null;
|
|
54
|
+
this.layover_restrictions = input.layover_restrictions ?? null;
|
|
55
|
+
this.sort_by = input.sort_by ?? SortBy.BEST;
|
|
56
|
+
this.exclude_basic_economy = input.exclude_basic_economy ?? false;
|
|
57
|
+
this.emissions = input.emissions ?? EmissionsFilter.ALL;
|
|
58
|
+
this.bags = input.bags ?? null;
|
|
59
|
+
this.show_all_results = input.show_all_results ?? true;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Render the nested-list payload Google's GetShoppingResults RPC accepts.
|
|
63
|
+
* See the position map in the upstream Python flights.py.
|
|
64
|
+
*/
|
|
65
|
+
format() {
|
|
66
|
+
const formattedSegments = [];
|
|
67
|
+
for (let segIdx = 0; segIdx < this.flight_segments.length; segIdx++) {
|
|
68
|
+
const segment = this.flight_segments[segIdx];
|
|
69
|
+
if (!segment)
|
|
70
|
+
continue;
|
|
71
|
+
const departureBlock = [
|
|
72
|
+
segment.departure_airport.map((airports) => airports.map((airport) => [serializeCode(airport[0]), airport[1]])),
|
|
73
|
+
];
|
|
74
|
+
const arrivalBlock = [
|
|
75
|
+
segment.arrival_airport.map((airports) => airports.map((airport) => [serializeCode(airport[0]), airport[1]])),
|
|
76
|
+
];
|
|
77
|
+
const tr = segment.time_restrictions;
|
|
78
|
+
const timeFilters = tr
|
|
79
|
+
? [
|
|
80
|
+
tr.earliest_departure ?? null,
|
|
81
|
+
tr.latest_departure ?? null,
|
|
82
|
+
tr.earliest_arrival ?? null,
|
|
83
|
+
tr.latest_arrival ?? null,
|
|
84
|
+
]
|
|
85
|
+
: null;
|
|
86
|
+
// Include list — airline codes (sorted) then alliance strings (sorted).
|
|
87
|
+
const includeTokens = [];
|
|
88
|
+
if (this.airlines?.length) {
|
|
89
|
+
const sorted = [...this.airlines].sort((a, b) => {
|
|
90
|
+
const ka = airlineSortKey(a);
|
|
91
|
+
const kb = airlineSortKey(b);
|
|
92
|
+
return ka < kb ? -1 : ka > kb ? 1 : 0;
|
|
93
|
+
});
|
|
94
|
+
for (const a of sorted)
|
|
95
|
+
includeTokens.push(serializeCode(a));
|
|
96
|
+
}
|
|
97
|
+
if (this.alliances?.length) {
|
|
98
|
+
for (const a of [...this.alliances].sort())
|
|
99
|
+
includeTokens.push(a);
|
|
100
|
+
}
|
|
101
|
+
const airlinesFilters = includeTokens.length ? includeTokens : null;
|
|
102
|
+
const excludeTokens = [];
|
|
103
|
+
if (this.airlines_exclude?.length) {
|
|
104
|
+
const sorted = [...this.airlines_exclude].sort((a, b) => {
|
|
105
|
+
const ka = airlineSortKey(a);
|
|
106
|
+
const kb = airlineSortKey(b);
|
|
107
|
+
return ka < kb ? -1 : ka > kb ? 1 : 0;
|
|
108
|
+
});
|
|
109
|
+
for (const a of sorted)
|
|
110
|
+
excludeTokens.push(serializeCode(a));
|
|
111
|
+
}
|
|
112
|
+
if (this.alliances_exclude?.length) {
|
|
113
|
+
for (const a of [...this.alliances_exclude].sort())
|
|
114
|
+
excludeTokens.push(a);
|
|
115
|
+
}
|
|
116
|
+
const excludeFilters = excludeTokens.length ? excludeTokens : null;
|
|
117
|
+
const layoverAirports = this.layover_restrictions?.airports?.length
|
|
118
|
+
? this.layover_restrictions.airports.map(serializeCode)
|
|
119
|
+
: null;
|
|
120
|
+
const layoverMin = this.layover_restrictions?.min_duration ?? null;
|
|
121
|
+
const layoverMax = this.layover_restrictions?.max_duration ?? null;
|
|
122
|
+
// selected_flight encoding (for round-trip / multi-city expansion calls).
|
|
123
|
+
let selectedFlights = null;
|
|
124
|
+
const isMultiLeg = this.trip_type === TripType.ROUND_TRIP || this.trip_type === TripType.MULTI_CITY;
|
|
125
|
+
if (isMultiLeg && segment.selected_flight != null) {
|
|
126
|
+
selectedFlights = segment.selected_flight.legs.map((leg) => [
|
|
127
|
+
serializeCode(leg.departure_airport),
|
|
128
|
+
formatDateOnly(leg.departure_datetime),
|
|
129
|
+
serializeCode(leg.arrival_airport),
|
|
130
|
+
null,
|
|
131
|
+
serializeCode(leg.airline),
|
|
132
|
+
leg.flight_number,
|
|
133
|
+
]);
|
|
134
|
+
}
|
|
135
|
+
const emissionsFilter = this.emissions !== EmissionsFilter.ALL ? [this.emissions] : null;
|
|
136
|
+
// 3 = outbound (or only leg), 1 = return (second leg of round-trip).
|
|
137
|
+
const isReturn = this.trip_type === TripType.ROUND_TRIP && segIdx > 0;
|
|
138
|
+
const classifier = isReturn ? 1 : 3;
|
|
139
|
+
formattedSegments.push([
|
|
140
|
+
departureBlock[0], // 0: departure airports
|
|
141
|
+
arrivalBlock[0], // 1: arrival airports
|
|
142
|
+
timeFilters, // 2: [edep, ldep, earr, larr]
|
|
143
|
+
this.stops, // 3: stops int
|
|
144
|
+
airlinesFilters, // 4: include list
|
|
145
|
+
excludeFilters, // 5: exclude list
|
|
146
|
+
segment.travel_date, // 6: travel date
|
|
147
|
+
this.max_duration != null ? [this.max_duration] : null, // 7
|
|
148
|
+
selectedFlights, // 8: selected flight (next-leg fetch)
|
|
149
|
+
layoverAirports, // 9
|
|
150
|
+
null, // 10
|
|
151
|
+
layoverMin, // 11
|
|
152
|
+
layoverMax, // 12
|
|
153
|
+
emissionsFilter, // 13
|
|
154
|
+
classifier, // 14
|
|
155
|
+
]);
|
|
156
|
+
}
|
|
157
|
+
const bagsFilter = this.bags
|
|
158
|
+
? [this.bags.checked_bags, this.bags.carry_on ? 1 : 0]
|
|
159
|
+
: null;
|
|
160
|
+
return [
|
|
161
|
+
[], // outer[0]
|
|
162
|
+
[
|
|
163
|
+
null, // [0]
|
|
164
|
+
null, // [1]
|
|
165
|
+
this.trip_type, // [2]
|
|
166
|
+
null, // [3]
|
|
167
|
+
[], // [4]
|
|
168
|
+
this.seat_type, // [5]
|
|
169
|
+
[
|
|
170
|
+
this.passenger_info.adults,
|
|
171
|
+
this.passenger_info.children,
|
|
172
|
+
this.passenger_info.infants_on_lap,
|
|
173
|
+
this.passenger_info.infants_in_seat,
|
|
174
|
+
], // [6]
|
|
175
|
+
this.price_limit ? [null, this.price_limit.max_price] : null, // [7]
|
|
176
|
+
null, // [8]
|
|
177
|
+
null, // [9]
|
|
178
|
+
bagsFilter, // [10]
|
|
179
|
+
null, // [11]
|
|
180
|
+
null, // [12]
|
|
181
|
+
formattedSegments, // [13]
|
|
182
|
+
null, // [14]
|
|
183
|
+
null, // [15]
|
|
184
|
+
null, // [16]
|
|
185
|
+
1, // [17]
|
|
186
|
+
null, // [18]
|
|
187
|
+
null, // [19]
|
|
188
|
+
null, // [20]
|
|
189
|
+
null, // [21]
|
|
190
|
+
null, // [22]
|
|
191
|
+
null, // [23]
|
|
192
|
+
null, // [24]
|
|
193
|
+
null, // [25]
|
|
194
|
+
null, // [26]
|
|
195
|
+
null, // [27]
|
|
196
|
+
this.exclude_basic_economy ? 1 : 0, // [28]
|
|
197
|
+
],
|
|
198
|
+
this.sort_by, // outer[2]
|
|
199
|
+
this.show_all_results ? 1 : 0, // outer[3]
|
|
200
|
+
0, // outer[4]
|
|
201
|
+
1, // outer[5]
|
|
202
|
+
];
|
|
203
|
+
}
|
|
204
|
+
/** URL-encode the formatted filters into the `f.req` body. */
|
|
205
|
+
encode() {
|
|
206
|
+
const formatted = this.format();
|
|
207
|
+
const formattedJson = JSON.stringify(formatted);
|
|
208
|
+
const wrapped = [null, formattedJson];
|
|
209
|
+
return encodeURIComponent(JSON.stringify(wrapped));
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function formatDateOnly(d) {
|
|
213
|
+
// Use local-time getters: `parseDateTime` in decoders.ts constructs
|
|
214
|
+
// `Date` via the local-time `new Date(y, m-1, d, h, min)` form, so the
|
|
215
|
+
// local components are what represent the flight's actual departure
|
|
216
|
+
// date. Reading back with `getUTC*` would shift the date by ±1 day for
|
|
217
|
+
// any caller not in UTC, sending the wrong day to Google's return-leg
|
|
218
|
+
// lookup.
|
|
219
|
+
const y = d.getFullYear();
|
|
220
|
+
const m = String(d.getMonth() + 1).padStart(2, "0");
|
|
221
|
+
const day = String(d.getDate()).padStart(2, "0");
|
|
222
|
+
return `${y}-${m}-${day}`;
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=flights.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flights.js","sourceRoot":"","sources":["../../../src/models/google-flights/flights.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAgB,MAAM,eAAe,CAAC;AAC5D,OAAO,EAGL,eAAe,EAGf,QAAQ,EAGR,QAAQ,EACR,MAAM,EACN,QAAQ,GACT,MAAM,WAAW,CAAC;AAEnB,SAAS,cAAc,CAAC,CAAU;IAChC,sEAAsE;IACtE,uEAAuE;IACvE,iEAAiE;IACjE,yCAAyC;IACzC,MAAM,IAAI,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;IAC9B,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;AACrC,CAAC;AAsBD,SAAS,aAAa,CAAC,IAAY;IACjC,qEAAqE;IACrE,sDAAsD;IACtD,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACrD,CAAC;AAED,MAAM,OAAO,mBAAmB;IAC9B,SAAS,CAAW;IACpB,cAAc,CAAgB;IAC9B,eAAe,CAAkB;IACjC,KAAK,CAAW;IAChB,SAAS,CAAW;IACpB,WAAW,CAAoB;IAC/B,QAAQ,CAAmB;IAC3B,gBAAgB,CAAmB;IACnC,SAAS,CAAoB;IAC7B,iBAAiB,CAAoB;IACrC,YAAY,CAAgB;IAC5B,oBAAoB,CAA6B;IACjD,OAAO,CAAS;IAChB,qBAAqB,CAAU;IAC/B,SAAS,CAAkB;IAC3B,IAAI,CAAoB;IACxB,gBAAgB,CAAU;IAE1B,YAAY,KAA+B;QACzC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI,QAAQ,CAA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,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW;YAC1C,CAAC,EAAE,WAAW;YACd,CAAC,EAAE,WAAW;SACf,CAAC;IACJ,CAAC;IAED,8DAA8D;IAC9D,MAAM;QACJ,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAChC,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAChD,MAAM,OAAO,GAAc,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QACjD,OAAO,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IACrD,CAAC;CACF;AAED,SAAS,cAAc,CAAC,CAAO;IAC7B,oEAAoE;IACpE,uEAAuE;IACvE,oEAAoE;IACpE,uEAAuE;IACvE,sEAAsE;IACtE,UAAU;IACV,MAAM,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;IAC1B,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACpD,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACjD,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { type AirportEntry, Alliance, type Amenities, AmenitiesSchema, type BagsFilter, BagsFilterSchema, type BookingOption, Currency, EmissionsFilter, type FlightLeg, type FlightResult, FlightSegment, type FlightSegmentInput, type Layover, type LayoverRestrictions, LayoverRestrictionsSchema, MaxStops, type PassengerInfo, PassengerInfoSchema, type PriceLimit, PriceLimitSchema, priceUnknown, SeatType, SortBy, type TimeRestrictions, TimeRestrictionsSchema, TripType, } from "./base.ts";
|
|
2
|
+
export { DateSearchFilters, type DateSearchFiltersInput } from "./dates.ts";
|
|
3
|
+
export { FlightSearchFilters, type FlightSearchFiltersInput } from "./flights.ts";
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/models/google-flights/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,QAAQ,EACR,KAAK,SAAS,EACd,eAAe,EACf,KAAK,UAAU,EACf,gBAAgB,EAChB,KAAK,aAAa,EAClB,QAAQ,EACR,eAAe,EACf,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,aAAa,EACb,KAAK,kBAAkB,EACvB,KAAK,OAAO,EACZ,KAAK,mBAAmB,EACxB,yBAAyB,EACzB,QAAQ,EACR,KAAK,aAAa,EAClB,mBAAmB,EACnB,KAAK,UAAU,EACf,gBAAgB,EAChB,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,KAAK,gBAAgB,EACrB,sBAAsB,EACtB,QAAQ,GACT,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,iBAAiB,EAAE,KAAK,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,KAAK,wBAAwB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { Alliance, AmenitiesSchema, BagsFilterSchema, Currency, EmissionsFilter, FlightSegment, LayoverRestrictionsSchema, MaxStops, PassengerInfoSchema, PriceLimitSchema, priceUnknown, SeatType, SortBy, TimeRestrictionsSchema, TripType, } from "./base.js";
|
|
2
|
+
export { DateSearchFilters } from "./dates.js";
|
|
3
|
+
export { FlightSearchFilters } from "./flights.js";
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/models/google-flights/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAER,eAAe,EAEf,gBAAgB,EAEhB,QAAQ,EACR,eAAe,EAGf,aAAa,EAIb,yBAAyB,EACzB,QAAQ,EAER,mBAAmB,EAEnB,gBAAgB,EAChB,YAAY,EACZ,QAAQ,EACR,MAAM,EAEN,sBAAsB,EACtB,QAAQ,GACT,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,iBAAiB,EAA+B,MAAM,YAAY,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAiC,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACtD,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACtD,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client with rate limiting, retries, and proxy support.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the Python `curl_cffi` impersonation with a `fetch`-based
|
|
5
|
+
* client that:
|
|
6
|
+
*
|
|
7
|
+
* - sends realistic Chrome-like headers
|
|
8
|
+
* - honours HTTPS_PROXY / HTTP_PROXY env vars (Bun's fetch supports this
|
|
9
|
+
* via the `proxy` option)
|
|
10
|
+
* - rate-limits at 10 req/sec via {@link TokenBucketRateLimiter}
|
|
11
|
+
* - retries network errors with exponential backoff
|
|
12
|
+
* - wraps low-level errors into the typed {@link SearchClientError} family
|
|
13
|
+
*/
|
|
14
|
+
export interface ClientOptions {
|
|
15
|
+
/** Calls per second budget. Defaults to 10. */
|
|
16
|
+
callsPerSecond?: number;
|
|
17
|
+
/** Per-request timeout in ms. Defaults to 60_000 (or `FLI_TIMEOUT` env var * 1000). */
|
|
18
|
+
timeoutMs?: number;
|
|
19
|
+
/** Total request attempts including the first try. Defaults to 3. */
|
|
20
|
+
retries?: number;
|
|
21
|
+
/** Initial backoff between attempts in ms. Defaults to 1_000. */
|
|
22
|
+
backoffMs?: number;
|
|
23
|
+
/** Proxy URL (e.g. `http://user:pass@host:port`). Defaults to HTTPS_PROXY/HTTP_PROXY env. */
|
|
24
|
+
proxy?: string | null;
|
|
25
|
+
/** Custom fetch implementation (test seam). */
|
|
26
|
+
fetchImpl?: typeof fetch;
|
|
27
|
+
}
|
|
28
|
+
export interface RequestOptions {
|
|
29
|
+
headers?: Record<string, string>;
|
|
30
|
+
body?: string | Uint8Array;
|
|
31
|
+
signal?: AbortSignal;
|
|
32
|
+
}
|
|
33
|
+
export interface ClientResponse {
|
|
34
|
+
status: number;
|
|
35
|
+
statusText: string;
|
|
36
|
+
text: string;
|
|
37
|
+
headers: Headers;
|
|
38
|
+
ok: boolean;
|
|
39
|
+
}
|
|
40
|
+
export declare class Client {
|
|
41
|
+
private readonly rateLimiter;
|
|
42
|
+
private readonly timeoutMs;
|
|
43
|
+
private readonly retries;
|
|
44
|
+
private readonly backoffMs;
|
|
45
|
+
private readonly proxy;
|
|
46
|
+
private readonly fetchImpl;
|
|
47
|
+
constructor(options?: ClientOptions);
|
|
48
|
+
get(url: string, options?: RequestOptions): Promise<ClientResponse>;
|
|
49
|
+
post(url: string, options?: RequestOptions): Promise<ClientResponse>;
|
|
50
|
+
private request;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Return the process-wide shared client.
|
|
54
|
+
*
|
|
55
|
+
* Lazy on the first call. If `options` is passed on a later call, the
|
|
56
|
+
* existing singleton is replaced with a new instance configured against
|
|
57
|
+
* those options (and that new instance becomes the cached singleton for
|
|
58
|
+
* subsequent no-arg callers). Callers that want a fully isolated client
|
|
59
|
+
* — e.g. to use a different proxy in one place without affecting
|
|
60
|
+
* others — should construct `new Client(options)` directly and pass it
|
|
61
|
+
* to `SearchFlights` / `SearchDates`.
|
|
62
|
+
*/
|
|
63
|
+
export declare function getClient(options?: ClientOptions): Client;
|
|
64
|
+
/** Replace the shared client (test helper). */
|
|
65
|
+
export declare function _setSharedClient(client: Client | null): void;
|
|
66
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/search/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAoDH,MAAM,WAAW,aAAa;IAC5B,+CAA+C;IAC/C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,uFAAuF;IACvF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6FAA6F;IAC7F,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,+CAA+C;IAC/C,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IAC3B,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,EAAE,EAAE,OAAO,CAAC;CACb;AA0CD,qBAAa,MAAM;IACjB,OAAO,CA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