letsfg 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.
@@ -0,0 +1,278 @@
1
+ /**
2
+ * LetsFG — Agent-native flight search & booking SDK for Node.js/TypeScript.
3
+ *
4
+ * 75 airline connectors run locally via Python + backend API for enterprise GDS/NDC sources.
5
+ * Zero external JS dependencies. Uses native fetch (Node 18+).
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { LetsFG, searchLocal } from 'letsfg';
10
+ *
11
+ * // Local search — FREE, no API key
12
+ * const local = await searchLocal('SHA', 'CTU', '2026-03-20');
13
+ *
14
+ * // Full API — search + unlock + book
15
+ * const bt = new LetsFG({ apiKey: 'trav_...' });
16
+ * const flights = await bt.search('GDN', 'BER', '2026-03-03');
17
+ * ```
18
+ */
19
+ interface FlightSegment {
20
+ airline: string;
21
+ airline_name: string;
22
+ flight_no: string;
23
+ origin: string;
24
+ destination: string;
25
+ origin_city: string;
26
+ destination_city: string;
27
+ departure: string;
28
+ arrival: string;
29
+ duration_seconds: number;
30
+ cabin_class: string;
31
+ aircraft: string;
32
+ }
33
+ interface FlightRoute {
34
+ segments: FlightSegment[];
35
+ total_duration_seconds: number;
36
+ stopovers: number;
37
+ }
38
+ interface FlightOffer {
39
+ id: string;
40
+ price: number;
41
+ currency: string;
42
+ price_formatted: string;
43
+ outbound: FlightRoute;
44
+ inbound: FlightRoute | null;
45
+ airlines: string[];
46
+ owner_airline: string;
47
+ bags_price: Record<string, number>;
48
+ availability_seats: number | null;
49
+ conditions: Record<string, string>;
50
+ is_locked: boolean;
51
+ fetched_at: string;
52
+ booking_url: string;
53
+ }
54
+ interface FlightSearchResult {
55
+ search_id: string;
56
+ offer_request_id: string;
57
+ passenger_ids: string[];
58
+ origin: string;
59
+ destination: string;
60
+ currency: string;
61
+ offers: FlightOffer[];
62
+ total_results: number;
63
+ search_params: Record<string, unknown>;
64
+ pricing_note: string;
65
+ }
66
+ interface UnlockResult {
67
+ offer_id: string;
68
+ unlock_status: string;
69
+ payment_charged: boolean;
70
+ payment_amount_cents: number;
71
+ payment_currency: string;
72
+ payment_intent_id: string;
73
+ confirmed_price: number | null;
74
+ confirmed_currency: string;
75
+ offer_expires_at: string;
76
+ message: string;
77
+ }
78
+ interface Passenger {
79
+ id: string;
80
+ given_name: string;
81
+ family_name: string;
82
+ born_on: string;
83
+ gender?: string;
84
+ title?: string;
85
+ email?: string;
86
+ phone_number?: string;
87
+ }
88
+ interface BookingResult {
89
+ booking_id: string;
90
+ status: string;
91
+ booking_type: string;
92
+ offer_id: string;
93
+ flight_price: number;
94
+ service_fee: number;
95
+ service_fee_percentage: number;
96
+ total_charged: number;
97
+ currency: string;
98
+ order_id: string;
99
+ booking_reference: string;
100
+ unlock_payment_id: string;
101
+ fee_payment_id: string;
102
+ created_at: string;
103
+ details: Record<string, unknown>;
104
+ }
105
+ interface SearchOptions {
106
+ returnDate?: string;
107
+ adults?: number;
108
+ children?: number;
109
+ infants?: number;
110
+ cabinClass?: 'M' | 'W' | 'C' | 'F';
111
+ maxStopovers?: number;
112
+ currency?: string;
113
+ limit?: number;
114
+ sort?: 'price' | 'duration';
115
+ /** Max concurrent browser instances (1-32). Omit for auto-detect based on system RAM. */
116
+ maxBrowsers?: number;
117
+ }
118
+ interface CheckoutProgress {
119
+ status: string;
120
+ step: string;
121
+ step_index: number;
122
+ airline: string;
123
+ source: string;
124
+ offer_id: string;
125
+ total_price: number;
126
+ currency: string;
127
+ booking_url: string;
128
+ screenshot_b64: string;
129
+ message: string;
130
+ can_complete_manually: boolean;
131
+ elapsed_seconds: number;
132
+ details: Record<string, unknown>;
133
+ }
134
+ interface LetsFGConfig {
135
+ apiKey?: string;
136
+ baseUrl?: string;
137
+ timeout?: number;
138
+ }
139
+ declare const ErrorCode: {
140
+ readonly SUPPLIER_TIMEOUT: "SUPPLIER_TIMEOUT";
141
+ readonly RATE_LIMITED: "RATE_LIMITED";
142
+ readonly SERVICE_UNAVAILABLE: "SERVICE_UNAVAILABLE";
143
+ readonly NETWORK_ERROR: "NETWORK_ERROR";
144
+ readonly INVALID_IATA: "INVALID_IATA";
145
+ readonly INVALID_DATE: "INVALID_DATE";
146
+ readonly INVALID_PASSENGERS: "INVALID_PASSENGERS";
147
+ readonly UNSUPPORTED_ROUTE: "UNSUPPORTED_ROUTE";
148
+ readonly MISSING_PARAMETER: "MISSING_PARAMETER";
149
+ readonly INVALID_PARAMETER: "INVALID_PARAMETER";
150
+ readonly AUTH_INVALID: "AUTH_INVALID";
151
+ readonly PAYMENT_REQUIRED: "PAYMENT_REQUIRED";
152
+ readonly PAYMENT_DECLINED: "PAYMENT_DECLINED";
153
+ readonly OFFER_EXPIRED: "OFFER_EXPIRED";
154
+ readonly OFFER_NOT_UNLOCKED: "OFFER_NOT_UNLOCKED";
155
+ readonly FARE_CHANGED: "FARE_CHANGED";
156
+ readonly ALREADY_BOOKED: "ALREADY_BOOKED";
157
+ readonly BOOKING_FAILED: "BOOKING_FAILED";
158
+ };
159
+ type ErrorCodeType = (typeof ErrorCode)[keyof typeof ErrorCode];
160
+ declare const ErrorCategory: {
161
+ readonly TRANSIENT: "transient";
162
+ readonly VALIDATION: "validation";
163
+ readonly BUSINESS: "business";
164
+ };
165
+ type ErrorCategoryType = (typeof ErrorCategory)[keyof typeof ErrorCategory];
166
+ declare class LetsFGError extends Error {
167
+ statusCode: number;
168
+ response: Record<string, unknown>;
169
+ errorCode: string;
170
+ errorCategory: ErrorCategoryType;
171
+ isRetryable: boolean;
172
+ constructor(message: string, statusCode?: number, response?: Record<string, unknown>, errorCode?: string);
173
+ }
174
+ declare class AuthenticationError extends LetsFGError {
175
+ constructor(message: string, response?: Record<string, unknown>);
176
+ }
177
+ declare class PaymentRequiredError extends LetsFGError {
178
+ constructor(message: string, response?: Record<string, unknown>);
179
+ }
180
+ declare class OfferExpiredError extends LetsFGError {
181
+ constructor(message: string, response?: Record<string, unknown>);
182
+ }
183
+ declare class ValidationError extends LetsFGError {
184
+ constructor(message: string, statusCode?: number, response?: Record<string, unknown>, errorCode?: string);
185
+ }
186
+ /** One-line offer summary */
187
+ declare function offerSummary(offer: FlightOffer): string;
188
+ /** Get cheapest offer from search results */
189
+ declare function cheapestOffer(result: FlightSearchResult): FlightOffer | null;
190
+ /**
191
+ * Search flights using 73 local airline connectors — FREE, no API key needed.
192
+ *
193
+ * Requires: pip install letsfg && playwright install chromium
194
+ *
195
+ * @param origin - IATA code (e.g., "SHA")
196
+ * @param destination - IATA code (e.g., "CTU")
197
+ * @param dateFrom - Departure date "YYYY-MM-DD"
198
+ * @param options - Optional: currency, adults, limit, etc.
199
+ */
200
+ declare function searchLocal(origin: string, destination: string, dateFrom: string, options?: Partial<SearchOptions>): Promise<FlightSearchResult>;
201
+ declare class LetsFG {
202
+ private apiKey;
203
+ private baseUrl;
204
+ private timeout;
205
+ constructor(config?: LetsFGConfig);
206
+ private requireApiKey;
207
+ /**
208
+ * Search for flights — FREE, unlimited.
209
+ *
210
+ * @param origin - IATA code (e.g., "GDN", "LON")
211
+ * @param destination - IATA code (e.g., "BER", "BCN")
212
+ * @param dateFrom - Departure date "YYYY-MM-DD"
213
+ * @param options - Optional search parameters
214
+ */
215
+ search(origin: string, destination: string, dateFrom: string, options?: SearchOptions): Promise<FlightSearchResult>;
216
+ /**
217
+ * Resolve a city/airport name to IATA codes.
218
+ */
219
+ resolveLocation(query: string): Promise<Array<Record<string, unknown>>>;
220
+ /**
221
+ * Unlock a flight offer — $1 fee.
222
+ * Confirms price, reserves for 30 minutes.
223
+ */
224
+ unlock(offerId: string): Promise<UnlockResult>;
225
+ /**
226
+ * Book a flight — FREE after unlock.
227
+ * Creates a real airline reservation with PNR.
228
+ *
229
+ * Always provide idempotencyKey to prevent double-bookings on retry.
230
+ */
231
+ book(offerId: string, passengers: Passenger[], contactEmail: string, contactPhone?: string, idempotencyKey?: string): Promise<BookingResult>;
232
+ /**
233
+ * Set up payment method (payment token).
234
+ */
235
+ setupPayment(token?: string): Promise<Record<string, unknown>>;
236
+ /**
237
+ * Start automated checkout — drives to payment page, NEVER submits payment.
238
+ *
239
+ * Requires unlock first ($1 fee). Returns progress with screenshot and
240
+ * booking URL for manual completion.
241
+ *
242
+ * @param offerId - Offer ID from search results
243
+ * @param passengers - Passenger details (use test data for safety)
244
+ * @param checkoutToken - Token from unlock() response
245
+ */
246
+ startCheckout(offerId: string, passengers: Passenger[], checkoutToken: string): Promise<CheckoutProgress>;
247
+ /**
248
+ * Start checkout locally via Python (runs on your machine).
249
+ * Requires: pip install letsfg && playwright install chromium
250
+ *
251
+ * @param offer - Full FlightOffer object from search results
252
+ * @param passengers - Passenger details
253
+ * @param checkoutToken - Token from unlock()
254
+ */
255
+ startCheckoutLocal(offer: FlightOffer, passengers: Passenger[], checkoutToken: string): Promise<CheckoutProgress>;
256
+ /**
257
+ * Get current agent profile and usage stats.
258
+ */
259
+ me(): Promise<Record<string, unknown>>;
260
+ /**
261
+ * Register a new agent — no API key needed.
262
+ */
263
+ static register(agentName: string, email: string, baseUrl?: string, ownerName?: string, description?: string): Promise<Record<string, unknown>>;
264
+ private post;
265
+ private get;
266
+ private request;
267
+ }
268
+ /**
269
+ * Get system resource profile and recommended concurrency settings.
270
+ * Calls the Python backend's system-info detection.
271
+ */
272
+ declare function systemInfo(): Promise<Record<string, unknown>>;
273
+
274
+ declare const BoostedTravel: typeof LetsFG;
275
+ declare const BoostedTravelError: typeof LetsFGError;
276
+ type BoostedTravelConfig = LetsFGConfig;
277
+
278
+ export { AuthenticationError, type BookingResult, BoostedTravel, type BoostedTravelConfig, BoostedTravelError, type CheckoutProgress, ErrorCategory, type ErrorCategoryType, ErrorCode, type ErrorCodeType, type FlightOffer, type FlightRoute, type FlightSearchResult, type FlightSegment, LetsFG, type LetsFGConfig, LetsFGError, OfferExpiredError, type Passenger, PaymentRequiredError, type SearchOptions, type UnlockResult, ValidationError, cheapestOffer, LetsFG as default, systemInfo as getSystemInfo, searchLocal as localSearch, offerSummary, searchLocal, systemInfo };