boostedtravel 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/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # BoostedTravel — Agent-Native Flight Search & Booking (Node.js)
2
+
3
+ Search 300+ airlines at prices **$10-30 cheaper** than booking.com, Kayak, and other OTAs. Zero dependencies. Built for autonomous AI agents.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install boostedtravel
9
+ ```
10
+
11
+ ## Quick Start (SDK)
12
+
13
+ ```typescript
14
+ import { BoostedTravel, cheapestOffer, offerSummary } from 'boostedtravel';
15
+
16
+ // Register (one-time)
17
+ const creds = await BoostedTravel.register('my-agent', 'agent@example.com');
18
+ console.log(creds.api_key); // Save this
19
+
20
+ // Use
21
+ const bt = new BoostedTravel({ apiKey: 'trav_...' });
22
+
23
+ // Search — FREE
24
+ const flights = await bt.search('GDN', 'BER', '2026-03-03');
25
+ const best = cheapestOffer(flights);
26
+ console.log(offerSummary(best));
27
+
28
+ // Unlock — $1
29
+ const unlock = await bt.unlock(best.id);
30
+
31
+ // Book — 2.5% fee
32
+ const booking = await bt.book(
33
+ best.id,
34
+ [{
35
+ id: flights.passenger_ids[0],
36
+ given_name: 'John',
37
+ family_name: 'Doe',
38
+ born_on: '1990-01-15',
39
+ gender: 'm',
40
+ title: 'mr',
41
+ email: 'john@example.com',
42
+ }],
43
+ 'john@example.com'
44
+ );
45
+ console.log(`PNR: ${booking.booking_reference}`);
46
+ ```
47
+
48
+ ## Quick Start (CLI)
49
+
50
+ ```bash
51
+ export BOOSTEDTRAVEL_API_KEY=trav_...
52
+
53
+ boostedtravel search GDN BER 2026-03-03 --sort price
54
+ boostedtravel search LON BCN 2026-04-01 --json # Machine-readable
55
+ boostedtravel unlock off_xxx
56
+ boostedtravel book off_xxx -p '{"id":"pas_xxx","given_name":"John",...}' -e john@example.com
57
+ ```
58
+
59
+ ## API
60
+
61
+ ### `new BoostedTravel({ apiKey, baseUrl?, timeout? })`
62
+
63
+ ### `bt.search(origin, destination, dateFrom, options?)`
64
+ ### `bt.resolveLocation(query)`
65
+ ### `bt.unlock(offerId)`
66
+ ### `bt.book(offerId, passengers, contactEmail, contactPhone?)`
67
+ ### `bt.setupPayment(token?)`
68
+ ### `bt.me()`
69
+ ### `BoostedTravel.register(agentName, email, baseUrl?, ownerName?, description?)`
70
+
71
+ ### Helpers
72
+ - `offerSummary(offer)` — One-line string summary
73
+ - `cheapestOffer(result)` — Get cheapest offer from search
74
+
75
+ ## Zero Dependencies
76
+
77
+ Uses native `fetch` (Node 18+). No `axios`, no `node-fetch`, nothing. Safe for sandboxed environments.
78
+
79
+ ## License
80
+
81
+ MIT
@@ -0,0 +1,199 @@
1
+ // src/index.ts
2
+ var BoostedTravelError = class extends Error {
3
+ statusCode;
4
+ response;
5
+ constructor(message, statusCode = 0, response = {}) {
6
+ super(message);
7
+ this.name = "BoostedTravelError";
8
+ this.statusCode = statusCode;
9
+ this.response = response;
10
+ }
11
+ };
12
+ var AuthenticationError = class extends BoostedTravelError {
13
+ constructor(message, response = {}) {
14
+ super(message, 401, response);
15
+ this.name = "AuthenticationError";
16
+ }
17
+ };
18
+ var PaymentRequiredError = class extends BoostedTravelError {
19
+ constructor(message, response = {}) {
20
+ super(message, 402, response);
21
+ this.name = "PaymentRequiredError";
22
+ }
23
+ };
24
+ function routeStr(route) {
25
+ if (!route.segments.length) return "";
26
+ const codes = [route.segments[0].origin, ...route.segments.map((s) => s.destination)];
27
+ return codes.join(" \u2192 ");
28
+ }
29
+ function durationHuman(seconds) {
30
+ const h = Math.floor(seconds / 3600);
31
+ const m = Math.floor(seconds % 3600 / 60);
32
+ return `${h}h${m.toString().padStart(2, "0")}m`;
33
+ }
34
+ function offerSummary(offer) {
35
+ const route = routeStr(offer.outbound);
36
+ const dur = durationHuman(offer.outbound.total_duration_seconds);
37
+ const airline = offer.owner_airline || offer.airlines[0] || "?";
38
+ return `${offer.currency} ${offer.price.toFixed(2)} | ${airline} | ${route} | ${dur} | ${offer.outbound.stopovers} stop(s)`;
39
+ }
40
+ function cheapestOffer(result) {
41
+ if (!result.offers.length) return null;
42
+ return result.offers.reduce((min, o) => o.price < min.price ? o : min, result.offers[0]);
43
+ }
44
+ var DEFAULT_BASE_URL = "https://api.boostedchat.com";
45
+ var BoostedTravel = class {
46
+ apiKey;
47
+ baseUrl;
48
+ timeout;
49
+ constructor(config = {}) {
50
+ this.apiKey = config.apiKey || process.env.BOOSTEDTRAVEL_API_KEY || "";
51
+ this.baseUrl = (config.baseUrl || process.env.BOOSTEDTRAVEL_BASE_URL || DEFAULT_BASE_URL).replace(/\/$/, "");
52
+ this.timeout = config.timeout || 3e4;
53
+ if (!this.apiKey) {
54
+ throw new AuthenticationError(
55
+ "API key required. Set apiKey in config or BOOSTEDTRAVEL_API_KEY env var. Get one: POST /api/v1/agents/register"
56
+ );
57
+ }
58
+ }
59
+ // ── Core methods ─────────────────────────────────────────────────────
60
+ /**
61
+ * Search for flights — FREE, unlimited.
62
+ *
63
+ * @param origin - IATA code (e.g., "GDN", "LON")
64
+ * @param destination - IATA code (e.g., "BER", "BCN")
65
+ * @param dateFrom - Departure date "YYYY-MM-DD"
66
+ * @param options - Optional search parameters
67
+ */
68
+ async search(origin, destination, dateFrom, options = {}) {
69
+ const body = {
70
+ origin: origin.toUpperCase(),
71
+ destination: destination.toUpperCase(),
72
+ date_from: dateFrom,
73
+ adults: options.adults ?? 1,
74
+ children: options.children ?? 0,
75
+ infants: options.infants ?? 0,
76
+ max_stopovers: options.maxStopovers ?? 2,
77
+ currency: options.currency ?? "EUR",
78
+ limit: options.limit ?? 20,
79
+ sort: options.sort ?? "price"
80
+ };
81
+ if (options.returnDate) body.return_from = options.returnDate;
82
+ if (options.cabinClass) body.cabin_class = options.cabinClass;
83
+ return this.post("/api/v1/flights/search", body);
84
+ }
85
+ /**
86
+ * Resolve a city/airport name to IATA codes.
87
+ */
88
+ async resolveLocation(query) {
89
+ const data = await this.get(`/api/v1/flights/locations/${encodeURIComponent(query)}`);
90
+ if (Array.isArray(data)) return data;
91
+ if (data && Array.isArray(data.locations)) return data.locations;
92
+ return data ? [data] : [];
93
+ }
94
+ /**
95
+ * Unlock a flight offer — $1 fee.
96
+ * Confirms price, reserves for 30 minutes.
97
+ */
98
+ async unlock(offerId) {
99
+ return this.post("/api/v1/bookings/unlock", { offer_id: offerId });
100
+ }
101
+ /**
102
+ * Book a flight — 2.5% service fee.
103
+ * Creates a real airline reservation with PNR.
104
+ */
105
+ async book(offerId, passengers, contactEmail, contactPhone = "") {
106
+ return this.post("/api/v1/bookings/book", {
107
+ offer_id: offerId,
108
+ booking_type: "flight",
109
+ passengers,
110
+ contact_email: contactEmail,
111
+ contact_phone: contactPhone
112
+ });
113
+ }
114
+ /**
115
+ * Set up payment method (payment token).
116
+ */
117
+ async setupPayment(token = "tok_visa") {
118
+ return this.post("/api/v1/agents/setup-payment", { token });
119
+ }
120
+ /**
121
+ * Get current agent profile and usage stats.
122
+ */
123
+ async me() {
124
+ return this.get("/api/v1/agents/me");
125
+ }
126
+ // ── Static methods ───────────────────────────────────────────────────
127
+ /**
128
+ * Register a new agent — no API key needed.
129
+ */
130
+ static async register(agentName, email, baseUrl, ownerName = "", description = "") {
131
+ const url = (baseUrl || DEFAULT_BASE_URL).replace(/\/$/, "");
132
+ const resp = await fetch(`${url}/api/v1/agents/register`, {
133
+ method: "POST",
134
+ headers: { "Content-Type": "application/json" },
135
+ body: JSON.stringify({
136
+ agent_name: agentName,
137
+ email,
138
+ owner_name: ownerName,
139
+ description
140
+ })
141
+ });
142
+ const data = await resp.json();
143
+ if (!resp.ok) {
144
+ throw new BoostedTravelError(
145
+ data.detail || `Registration failed (${resp.status})`,
146
+ resp.status,
147
+ data
148
+ );
149
+ }
150
+ return data;
151
+ }
152
+ // ── Internal ────────────────────────────────────────────────────────
153
+ async post(path, body) {
154
+ return this.request(path, {
155
+ method: "POST",
156
+ body: JSON.stringify(body)
157
+ });
158
+ }
159
+ async get(path) {
160
+ return this.request(path, { method: "GET" });
161
+ }
162
+ async request(path, init) {
163
+ const controller = new AbortController();
164
+ const timer = setTimeout(() => controller.abort(), this.timeout);
165
+ try {
166
+ const resp = await fetch(`${this.baseUrl}${path}`, {
167
+ ...init,
168
+ headers: {
169
+ "Content-Type": "application/json",
170
+ "X-API-Key": this.apiKey,
171
+ "User-Agent": "boostedtravel-js/0.1.0",
172
+ ...init.headers || {}
173
+ },
174
+ signal: controller.signal
175
+ });
176
+ const data = await resp.json();
177
+ if (!resp.ok) {
178
+ const detail = data.detail || `API error (${resp.status})`;
179
+ if (resp.status === 401) throw new AuthenticationError(detail, data);
180
+ if (resp.status === 402) throw new PaymentRequiredError(detail, data);
181
+ throw new BoostedTravelError(detail, resp.status, data);
182
+ }
183
+ return data;
184
+ } finally {
185
+ clearTimeout(timer);
186
+ }
187
+ }
188
+ };
189
+ var index_default = BoostedTravel;
190
+
191
+ export {
192
+ BoostedTravelError,
193
+ AuthenticationError,
194
+ PaymentRequiredError,
195
+ offerSummary,
196
+ cheapestOffer,
197
+ BoostedTravel,
198
+ index_default
199
+ };
package/dist/cli.d.mts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node