@molecule/api-flights 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 ADDED
@@ -0,0 +1,115 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work.
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship.
43
+
44
+ "Contribution" shall mean any work of authorship, including the
45
+ original version of the Work and any modifications or additions
46
+ to that Work, that is intentionally submitted to the Licensor for
47
+ inclusion in the Work by the copyright owner or by an individual or
48
+ Legal Entity authorized to submit on behalf of the copyright owner.
49
+
50
+ "Contributor" shall mean Licensor and any individual or Legal Entity
51
+ on behalf of whom a Contribution has been received by the Licensor and
52
+ subsequently incorporated within the Work.
53
+
54
+ 2. Grant of Copyright License. Subject to the terms and conditions of
55
+ this License, each Contributor hereby grants to You a perpetual,
56
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
57
+ copyright license to reproduce, prepare Derivative Works of,
58
+ publicly display, publicly perform, sublicense, and distribute the
59
+ Work and such Derivative Works in Source or Object form.
60
+
61
+ 3. Grant of Patent License. Subject to the terms and conditions of
62
+ this License, each Contributor hereby grants to You a perpetual,
63
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
64
+ patent license to make, have made, use, offer to sell, sell, import,
65
+ and otherwise transfer the Work.
66
+
67
+ 4. Redistribution. You may reproduce and distribute copies of the
68
+ Work or Derivative Works thereof in any medium, with or without
69
+ modifications, and in Source or Object form, provided that You
70
+ meet the following conditions:
71
+
72
+ (a) You must give any other recipients of the Work or
73
+ Derivative Works a copy of this License; and
74
+
75
+ (b) You must cause any modified files to carry prominent notices
76
+ stating that You changed the files; and
77
+
78
+ (c) You must retain, in the Source form of any Derivative Works
79
+ that You distribute, all copyright, patent, trademark, and
80
+ attribution notices from the Source form of the Work,
81
+ excluding those notices that do not pertain to any part of
82
+ the Derivative Works; and
83
+
84
+ (d) If the Work includes a "NOTICE" text file as part of its
85
+ distribution, then any Derivative Works that You distribute must
86
+ include a readable copy of the attribution notices contained
87
+ within such NOTICE file.
88
+
89
+ 5. Submission of Contributions.
90
+
91
+ 6. Trademarks. This License does not grant permission to use the trade
92
+ names, trademarks, service marks, or product names of the Licensor.
93
+
94
+ 7. Disclaimer of Warranty. Unless required by applicable law or
95
+ agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
96
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
97
+
98
+ 8. Limitation of Liability. In no event and under no legal theory shall
99
+ any Contributor be liable to You for damages.
100
+
101
+ 9. Accepting Warranty or Additional Liability.
102
+
103
+ Copyright 2026 Molecule Dev, Inc.
104
+
105
+ Licensed under the Apache License, Version 2.0 (the "License");
106
+ you may not use this file except in compliance with the License.
107
+ You may obtain a copy of the License at
108
+
109
+ http://www.apache.org/licenses/LICENSE-2.0
110
+
111
+ Unless required by applicable law or agreed to in writing, software
112
+ distributed under the License is distributed on an "AS IS" BASIS,
113
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
114
+ See the License for the specific language governing permissions and
115
+ limitations under the License.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=browser-guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-guard.d.ts","sourceRoot":"","sources":["../src/browser-guard.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,CAAA"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Browser guard — `@molecule/api-flights` is SERVER-ONLY.
3
+ *
4
+ * Generated by scripts/gen-browser-guards.mjs (workspace root) — edit THAT, not this.
5
+ * Evaluating a server package in a browser bundle is always an import-graph mistake
6
+ * (node APIs, secrets); without this guard it surfaces as a cryptic downstream crash
7
+ * ("Buffer is not defined") far from the culprit. Throwing here names the package and
8
+ * the fix at the exact moment the client bundle evaluates it. jsdom tests and SSR are
9
+ * unaffected: the throw requires browser globals AND the absence of a node runtime.
10
+ */
11
+ const g = globalThis;
12
+ if (g.window !== undefined && g.document !== undefined && !g.process?.versions?.node) {
13
+ throw new Error('@molecule/api-flights is SERVER-ONLY: it was bundled into browser/client code. Import it only ' +
14
+ 'from server code (a server route/function or your API), or dynamic-import it inside ' +
15
+ 'the server handler — never from components or shared client modules, and never ' +
16
+ 'polyfill Buffer/process to silence this.');
17
+ }
18
+ export {};
19
+ //# sourceMappingURL=browser-guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-guard.js","sourceRoot":"","sources":["../src/browser-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,GAAG,UAIT,CAAA;AACD,IAAI,CAAC,CAAC,MAAM,KAAK,SAAS,IAAI,CAAC,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACrF,MAAM,IAAI,KAAK,CACb,gGAAgG;QAC9F,sFAAsF;QACtF,iFAAiF;QACjF,0CAA0C,CAC7C,CAAA;AACH,CAAC"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Provider-agnostic flights interface for molecule.dev.
3
+ *
4
+ * Defines the {@link FlightsProvider} interface for flight search +
5
+ * pricing. Bond packages (Amadeus, Duffel, Sabre, etc.) implement this
6
+ * interface. Application code uses the convenience functions
7
+ * (`searchFlights`, `getOffer`, `priceOffer`) which delegate to the bonded
8
+ * provider.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { setProvider, searchFlights, priceOffer } from '@molecule/api-flights'
13
+ * import { provider as amadeus } from '@molecule/api-flights-amadeus'
14
+ *
15
+ * setProvider(amadeus)
16
+ * const offers = await searchFlights({
17
+ * origin: 'JFK',
18
+ * destination: 'LHR',
19
+ * departureDate: '2026-07-15',
20
+ * adults: 1,
21
+ * })
22
+ * const priced = await priceOffer(offers[0].id)
23
+ * ```
24
+ *
25
+ * @remarks
26
+ * - **Offer ids are opaque, provider-scoped, and short-lived.** Never parse
27
+ * them and never persist them as durable references — a stale id fails
28
+ * `getOffer`/`priceOffer`; re-run the search instead of replaying old ids.
29
+ * - **Re-price before you commit.** `PricingResult.price` is the
30
+ * authoritative total at pricing time and MAY differ from the search-time
31
+ * `FlightOffer.price` — call `priceOffer()` right before the checkout/
32
+ * summary step and display the re-priced figure.
33
+ * - **This contract is search + pricing only — there is no booking method.**
34
+ * Don't invent a `bookFlight()`; booking needs vendor-specific work outside
35
+ * this interface.
36
+ * - **Server-side only; cache searches.** Flight-search APIs are slow,
37
+ * rate-limited, and often billed per call — cache results per (origin,
38
+ * destination, dates, passengers) for a short TTL and never fire a search
39
+ * per keystroke.
40
+ * - Airports/cities are IATA codes (`'JFK'`, `'NYC'`), dates are ISO calendar
41
+ * dates (`'2026-07-15'`), and prices carry an explicit ISO 4217 `currency` —
42
+ * format with it, never a hardcoded `$`.
43
+ *
44
+ * @e2e
45
+ * Integration checklist — drive the real UI (live preview, no mocks), adapt
46
+ * each item to this app's actual search / results screens, and check every box
47
+ * off one by one. A box you can't check is an integration bug to fix — not a
48
+ * skip:
49
+ * - [ ] Searching a real route + future date (e.g. JFK→LHR, a date weeks out)
50
+ * returns REAL `searchFlights` offers rendered in the results list — each
51
+ * showing an origin, a destination, departure/arrival times, and a price. No
52
+ * empty list, `null`, or placeholder row is presented as a successful search.
53
+ * - [ ] Results match the query: each offer's first `segment.departure.airport`
54
+ * and last `segment.arrival.airport` are the searched cities and the
55
+ * `departure.at` falls on the requested date — not random routes or dates.
56
+ * - [ ] Every price shows its `currency` (ISO 4217, formatted with it — never a
57
+ * hardcoded `$`) and is sane (positive, right order of magnitude). If a
58
+ * checkout/summary step re-prices via `priceOffer`/`getOffer`, the displayed
59
+ * total is the re-priced figure, not the stale search-time price.
60
+ * - [ ] Any exposed filter/sort (price, stops, departure/arrival time, cabin)
61
+ * actually narrows or reorders the SAME result set — not a fresh random list.
62
+ * - [ ] An impossible or invalid search — no availability, a past date, or a
63
+ * bad airport code — shows a clear "no flights" / "invalid" state, not a
64
+ * crash and not a blank list presented as a successful search.
65
+ * - [ ] A provider outage or rate-limit (HTTP 429) surfaces as a graceful,
66
+ * retryable error in the UI — not a hung spinner or a silent empty list.
67
+ * - [ ] This contract is search + pricing ONLY (there is no `bookFlight`). If
68
+ * the app adds a book/hold step it goes OUT-OF-BAND to the vendor — verify
69
+ * the app records the SELECTED offer (its priced total + itinerary), since
70
+ * opaque `OfferId`s are short-lived and can't be replayed later.
71
+ * - [ ] The provider API key stays server-side: searches run through the API
72
+ * bond and no key or upstream credential is ever exposed to the browser.
73
+ *
74
+ * @module
75
+ */
76
+ export * from './browser-guard.js';
77
+ export * from './types.js';
78
+ export * from './provider.js';
79
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0EG;AAGH,cAAc,oBAAoB,CAAA;AAClC,cAAc,YAAY,CAAA;AAG1B,cAAc,eAAe,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Provider-agnostic flights interface for molecule.dev.
3
+ *
4
+ * Defines the {@link FlightsProvider} interface for flight search +
5
+ * pricing. Bond packages (Amadeus, Duffel, Sabre, etc.) implement this
6
+ * interface. Application code uses the convenience functions
7
+ * (`searchFlights`, `getOffer`, `priceOffer`) which delegate to the bonded
8
+ * provider.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { setProvider, searchFlights, priceOffer } from '@molecule/api-flights'
13
+ * import { provider as amadeus } from '@molecule/api-flights-amadeus'
14
+ *
15
+ * setProvider(amadeus)
16
+ * const offers = await searchFlights({
17
+ * origin: 'JFK',
18
+ * destination: 'LHR',
19
+ * departureDate: '2026-07-15',
20
+ * adults: 1,
21
+ * })
22
+ * const priced = await priceOffer(offers[0].id)
23
+ * ```
24
+ *
25
+ * @remarks
26
+ * - **Offer ids are opaque, provider-scoped, and short-lived.** Never parse
27
+ * them and never persist them as durable references — a stale id fails
28
+ * `getOffer`/`priceOffer`; re-run the search instead of replaying old ids.
29
+ * - **Re-price before you commit.** `PricingResult.price` is the
30
+ * authoritative total at pricing time and MAY differ from the search-time
31
+ * `FlightOffer.price` — call `priceOffer()` right before the checkout/
32
+ * summary step and display the re-priced figure.
33
+ * - **This contract is search + pricing only — there is no booking method.**
34
+ * Don't invent a `bookFlight()`; booking needs vendor-specific work outside
35
+ * this interface.
36
+ * - **Server-side only; cache searches.** Flight-search APIs are slow,
37
+ * rate-limited, and often billed per call — cache results per (origin,
38
+ * destination, dates, passengers) for a short TTL and never fire a search
39
+ * per keystroke.
40
+ * - Airports/cities are IATA codes (`'JFK'`, `'NYC'`), dates are ISO calendar
41
+ * dates (`'2026-07-15'`), and prices carry an explicit ISO 4217 `currency` —
42
+ * format with it, never a hardcoded `$`.
43
+ *
44
+ * @e2e
45
+ * Integration checklist — drive the real UI (live preview, no mocks), adapt
46
+ * each item to this app's actual search / results screens, and check every box
47
+ * off one by one. A box you can't check is an integration bug to fix — not a
48
+ * skip:
49
+ * - [ ] Searching a real route + future date (e.g. JFK→LHR, a date weeks out)
50
+ * returns REAL `searchFlights` offers rendered in the results list — each
51
+ * showing an origin, a destination, departure/arrival times, and a price. No
52
+ * empty list, `null`, or placeholder row is presented as a successful search.
53
+ * - [ ] Results match the query: each offer's first `segment.departure.airport`
54
+ * and last `segment.arrival.airport` are the searched cities and the
55
+ * `departure.at` falls on the requested date — not random routes or dates.
56
+ * - [ ] Every price shows its `currency` (ISO 4217, formatted with it — never a
57
+ * hardcoded `$`) and is sane (positive, right order of magnitude). If a
58
+ * checkout/summary step re-prices via `priceOffer`/`getOffer`, the displayed
59
+ * total is the re-priced figure, not the stale search-time price.
60
+ * - [ ] Any exposed filter/sort (price, stops, departure/arrival time, cabin)
61
+ * actually narrows or reorders the SAME result set — not a fresh random list.
62
+ * - [ ] An impossible or invalid search — no availability, a past date, or a
63
+ * bad airport code — shows a clear "no flights" / "invalid" state, not a
64
+ * crash and not a blank list presented as a successful search.
65
+ * - [ ] A provider outage or rate-limit (HTTP 429) surfaces as a graceful,
66
+ * retryable error in the UI — not a hung spinner or a silent empty list.
67
+ * - [ ] This contract is search + pricing ONLY (there is no `bookFlight`). If
68
+ * the app adds a book/hold step it goes OUT-OF-BAND to the vendor — verify
69
+ * the app records the SELECTED offer (its priced total + itinerary), since
70
+ * opaque `OfferId`s are short-lived and can't be replayed later.
71
+ * - [ ] The provider API key stays server-side: searches run through the API
72
+ * bond and no key or upstream credential is ever exposed to the browser.
73
+ *
74
+ * @module
75
+ */
76
+ // Type exports
77
+ export * from './browser-guard.js';
78
+ export * from './types.js';
79
+ // Provider exports
80
+ export * from './provider.js';
81
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0EG;AAEH,eAAe;AACf,cAAc,oBAAoB,CAAA;AAClC,cAAc,YAAY,CAAA;AAE1B,mBAAmB;AACnB,cAAc,eAAe,CAAA"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Flights provider bond accessor and convenience functions.
3
+ *
4
+ * Bond packages (e.g. `@molecule/api-flights-amadeus`) call
5
+ * `setProvider()` during application startup. Application code uses the
6
+ * convenience functions (`searchFlights`, `getOffer`, `priceOffer`) which
7
+ * delegate to the bonded provider via `@molecule/api-bond`.
8
+ *
9
+ * @module
10
+ */
11
+ import type { FlightOffer, FlightOfferDetail, FlightsProvider, OfferId, PricingResult, SearchFlightsOptions } from './types.js';
12
+ /**
13
+ * Registers a flights provider as the active singleton. Called by bond
14
+ * packages (e.g. `@molecule/api-flights-amadeus`) during application
15
+ * startup.
16
+ *
17
+ * @param provider - The flights provider implementation to bond.
18
+ */
19
+ export declare const setProvider: (provider: FlightsProvider) => void;
20
+ /**
21
+ * Retrieves the bonded flights provider, throwing if none is configured.
22
+ *
23
+ * @returns The bonded flights provider.
24
+ * @throws {Error} If no flights provider has been bonded.
25
+ */
26
+ export declare const getProvider: () => FlightsProvider;
27
+ /**
28
+ * Checks whether a flights provider is currently bonded.
29
+ *
30
+ * @returns `true` if a flights provider is bonded.
31
+ */
32
+ export declare const hasProvider: () => boolean;
33
+ /**
34
+ * Searches for flight offers matching the supplied itinerary.
35
+ *
36
+ * @param options - Search parameters (origin, destination, dates,
37
+ * passenger counts, cabin, etc.).
38
+ * @returns Array of normalized flight offers.
39
+ * @throws {Error} If no flights provider has been bonded.
40
+ */
41
+ export declare const searchFlights: (options: SearchFlightsOptions) => Promise<FlightOffer[]>;
42
+ /**
43
+ * Retrieves a previously-searched offer in detail.
44
+ *
45
+ * @param offerId - Opaque offer identifier returned by `searchFlights`.
46
+ * @returns The offer with per-passenger price breakdown when available.
47
+ * @throws {Error} If no flights provider has been bonded.
48
+ */
49
+ export declare const getOffer: (offerId: OfferId) => Promise<FlightOfferDetail>;
50
+ /**
51
+ * Confirms the up-to-the-minute price for a previously-searched offer.
52
+ *
53
+ * @param offerId - Opaque offer identifier returned by `searchFlights`.
54
+ * @returns Authoritative price snapshot.
55
+ * @throws {Error} If no flights provider has been bonded.
56
+ */
57
+ export declare const priceOffer: (offerId: OfferId) => Promise<PricingResult>;
58
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,OAAO,EACP,aAAa,EACb,oBAAoB,EACrB,MAAM,YAAY,CAAA;AAKnB;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,UAAU,eAAe,KAAG,IAEvD,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,WAAW,QAAO,eAW9B,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,WAAW,QAAO,OAE9B,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,GAAU,SAAS,oBAAoB,KAAG,OAAO,CAAC,WAAW,EAAE,CAExF,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAU,SAAS,OAAO,KAAG,OAAO,CAAC,iBAAiB,CAE1E,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,GAAU,SAAS,OAAO,KAAG,OAAO,CAAC,aAAa,CAExE,CAAA"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Flights provider bond accessor and convenience functions.
3
+ *
4
+ * Bond packages (e.g. `@molecule/api-flights-amadeus`) call
5
+ * `setProvider()` during application startup. Application code uses the
6
+ * convenience functions (`searchFlights`, `getOffer`, `priceOffer`) which
7
+ * delegate to the bonded provider via `@molecule/api-bond`.
8
+ *
9
+ * @module
10
+ */
11
+ import { bond, expectBond, isBonded, require as bondRequire } from '@molecule/api-bond';
12
+ import { t } from '@molecule/api-i18n';
13
+ const BOND_TYPE = 'flights';
14
+ expectBond(BOND_TYPE);
15
+ /**
16
+ * Registers a flights provider as the active singleton. Called by bond
17
+ * packages (e.g. `@molecule/api-flights-amadeus`) during application
18
+ * startup.
19
+ *
20
+ * @param provider - The flights provider implementation to bond.
21
+ */
22
+ export const setProvider = (provider) => {
23
+ bond(BOND_TYPE, provider);
24
+ };
25
+ /**
26
+ * Retrieves the bonded flights provider, throwing if none is configured.
27
+ *
28
+ * @returns The bonded flights provider.
29
+ * @throws {Error} If no flights provider has been bonded.
30
+ */
31
+ export const getProvider = () => {
32
+ try {
33
+ return bondRequire(BOND_TYPE);
34
+ }
35
+ catch (error) {
36
+ throw new Error(t('flights.error.noProvider', undefined, {
37
+ defaultValue: 'Flights provider not configured. Call setProvider() first.',
38
+ }), { cause: error });
39
+ }
40
+ };
41
+ /**
42
+ * Checks whether a flights provider is currently bonded.
43
+ *
44
+ * @returns `true` if a flights provider is bonded.
45
+ */
46
+ export const hasProvider = () => {
47
+ return isBonded(BOND_TYPE);
48
+ };
49
+ /**
50
+ * Searches for flight offers matching the supplied itinerary.
51
+ *
52
+ * @param options - Search parameters (origin, destination, dates,
53
+ * passenger counts, cabin, etc.).
54
+ * @returns Array of normalized flight offers.
55
+ * @throws {Error} If no flights provider has been bonded.
56
+ */
57
+ export const searchFlights = async (options) => {
58
+ return getProvider().searchFlights(options);
59
+ };
60
+ /**
61
+ * Retrieves a previously-searched offer in detail.
62
+ *
63
+ * @param offerId - Opaque offer identifier returned by `searchFlights`.
64
+ * @returns The offer with per-passenger price breakdown when available.
65
+ * @throws {Error} If no flights provider has been bonded.
66
+ */
67
+ export const getOffer = async (offerId) => {
68
+ return getProvider().getOffer(offerId);
69
+ };
70
+ /**
71
+ * Confirms the up-to-the-minute price for a previously-searched offer.
72
+ *
73
+ * @param offerId - Opaque offer identifier returned by `searchFlights`.
74
+ * @returns Authoritative price snapshot.
75
+ * @throws {Error} If no flights provider has been bonded.
76
+ */
77
+ export const priceOffer = async (offerId) => {
78
+ return getProvider().priceOffer(offerId);
79
+ };
80
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACvF,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAWtC,MAAM,SAAS,GAAG,SAAS,CAAA;AAC3B,UAAU,CAAC,SAAS,CAAC,CAAA;AAErB;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,QAAyB,EAAQ,EAAE;IAC7D,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;AAC3B,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAoB,EAAE;IAC/C,IAAI,CAAC;QACH,OAAO,WAAW,CAAkB,SAAS,CAAC,CAAA;IAChD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,CAAC,CAAC,0BAA0B,EAAE,SAAS,EAAE;YACvC,YAAY,EAAE,4DAA4D;SAC3E,CAAC,EACF,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAA;IACH,CAAC;AACH,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAY,EAAE;IACvC,OAAO,QAAQ,CAAC,SAAS,CAAC,CAAA;AAC5B,CAAC,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,OAA6B,EAA0B,EAAE;IAC3F,OAAO,WAAW,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;AAC7C,CAAC,CAAA;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAAE,OAAgB,EAA8B,EAAE;IAC7E,OAAO,WAAW,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;AACxC,CAAC,CAAA;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAAE,OAAgB,EAA0B,EAAE;IAC3E,OAAO,WAAW,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;AAC1C,CAAC,CAAA"}
@@ -0,0 +1,291 @@
1
+ /**
2
+ * Type definitions for the flights core interface.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * IATA airport or city code (e.g. `'JFK'`, `'LAX'`, `'PAR'`).
8
+ *
9
+ * Kept as a plain `string` alias rather than a string-literal union so
10
+ * providers can support whatever set of airports / metropolitan codes their
11
+ * upstream exposes.
12
+ */
13
+ export type AirportCode = string;
14
+ /**
15
+ * IATA two-character airline / marketing carrier code (e.g. `'AA'`,
16
+ * `'BA'`, `'AF'`).
17
+ */
18
+ export type CarrierCode = string;
19
+ /**
20
+ * ISO 8601 calendar date (e.g. `'2026-07-15'`). Time-of-day MUST NOT be
21
+ * included; this is a date for searching availability, not a timestamp.
22
+ */
23
+ export type IsoDate = string;
24
+ /**
25
+ * ISO 8601 instant including timezone offset
26
+ * (e.g. `'2026-07-15T08:30:00+02:00'`).
27
+ *
28
+ * Providers SHOULD preserve the upstream offset where available; consumers
29
+ * that want a `Date` can `new Date(value)` it.
30
+ */
31
+ export type IsoDateTime = string;
32
+ /**
33
+ * ISO 8601 duration string (e.g. `'PT2H30M'`, `'PT11H45M'`).
34
+ *
35
+ * Plain string for the same reason as {@link IsoDate} — providers differ on
36
+ * whether they expose seconds-precision, fractional minutes, etc.
37
+ */
38
+ export type IsoDuration = string;
39
+ /**
40
+ * ISO 4217 three-letter currency code (e.g. `'USD'`, `'EUR'`, `'JPY'`).
41
+ *
42
+ * Conventionally upper-case to match {@link FlightOffer.currency} and the
43
+ * vast majority of upstream travel APIs.
44
+ */
45
+ export type CurrencyCode = string;
46
+ /**
47
+ * Provider-specific offer identifier.
48
+ *
49
+ * Opaque token returned by {@link FlightsProvider.searchFlights} that can
50
+ * be passed back to {@link FlightsProvider.getOffer} or
51
+ * {@link FlightsProvider.priceOffer}. Identifier scheme is provider-defined
52
+ * and MUST NOT be parsed by consumers.
53
+ */
54
+ export type OfferId = string;
55
+ /**
56
+ * Cabin class enumeration.
57
+ *
58
+ * Providers map each value onto whatever upstream code they require
59
+ * (e.g. Amadeus uses `'ECONOMY' | 'PREMIUM_ECONOMY' | 'BUSINESS' | 'FIRST'`).
60
+ */
61
+ export type CabinClass = 'economy' | 'premium-economy' | 'business' | 'first';
62
+ /**
63
+ * One leg of a {@link FlightOffer} — a single take-off / landing pair on a
64
+ * single operated flight.
65
+ */
66
+ export interface Segment {
67
+ /**
68
+ * Departure airport / instant.
69
+ */
70
+ departure: SegmentEndpoint;
71
+ /**
72
+ * Arrival airport / instant.
73
+ */
74
+ arrival: SegmentEndpoint;
75
+ /**
76
+ * Marketing carrier IATA code (e.g. `'AA'`, `'BA'`).
77
+ */
78
+ carrier: CarrierCode;
79
+ /**
80
+ * Marketing flight number (e.g. `'100'`, `'1234'`).
81
+ *
82
+ * String rather than number to preserve any leading zeros and to
83
+ * accommodate alphanumeric carriers (e.g. EasyJet's `'EZY'` prefix).
84
+ */
85
+ flightNumber: string;
86
+ /**
87
+ * IATA aircraft code (e.g. `'77W'`, `'320'`). `null` when the upstream
88
+ * does not supply aircraft data for this segment.
89
+ */
90
+ aircraft?: string | null;
91
+ /**
92
+ * Block / total time the segment is in the air. `null` when the upstream
93
+ * does not supply per-segment duration.
94
+ */
95
+ duration?: IsoDuration | null;
96
+ }
97
+ /**
98
+ * Departure or arrival point on a {@link Segment}.
99
+ */
100
+ export interface SegmentEndpoint {
101
+ /**
102
+ * IATA airport code (e.g. `'JFK'`).
103
+ */
104
+ airport: AirportCode;
105
+ /**
106
+ * Local-time instant including timezone offset.
107
+ */
108
+ at: IsoDateTime;
109
+ /**
110
+ * Terminal designator (e.g. `'4'`, `'2A'`). `null` when not supplied.
111
+ */
112
+ terminal?: string | null;
113
+ }
114
+ /**
115
+ * Normalized flight offer returned by
116
+ * {@link FlightsProvider.searchFlights}.
117
+ */
118
+ export interface FlightOffer {
119
+ /**
120
+ * Provider-specific opaque offer identifier.
121
+ */
122
+ id: OfferId;
123
+ /**
124
+ * Total grand-total price for ALL passengers in {@link currency}.
125
+ */
126
+ price: number;
127
+ /**
128
+ * Currency the {@link price} is expressed in (e.g. `'USD'`).
129
+ */
130
+ currency: CurrencyCode;
131
+ /**
132
+ * Flight segments, in chronological order. For round-trip itineraries
133
+ * outbound segments precede return segments. For multi-city the order
134
+ * matches the requested itinerary.
135
+ */
136
+ segments: Segment[];
137
+ /**
138
+ * Total elapsed time across all segments (including layovers).
139
+ */
140
+ duration: IsoDuration;
141
+ }
142
+ /**
143
+ * Detailed flight offer returned by {@link FlightsProvider.getOffer}.
144
+ *
145
+ * Extends {@link FlightOffer} with a per-passenger price breakdown and an
146
+ * optional source-data envelope. Providers that do not naturally support a
147
+ * "fetch single offer" call MAY return the same offer they previously
148
+ * returned from `searchFlights` here (without a fresh upstream round-trip).
149
+ */
150
+ export interface FlightOfferDetail extends FlightOffer {
151
+ /**
152
+ * Per-passenger price breakdown rows. `null` when the upstream does not
153
+ * supply the breakdown.
154
+ */
155
+ travelerPricings?: TravelerPricing[] | null;
156
+ }
157
+ /**
158
+ * Per-passenger price row inside {@link FlightOfferDetail.travelerPricings}.
159
+ */
160
+ export interface TravelerPricing {
161
+ /**
162
+ * Provider-specific traveler id (typically a 1-indexed string).
163
+ */
164
+ travelerId: string;
165
+ /**
166
+ * Adult, child, or infant. The infant variant is split between
167
+ * lap-infants (`'held-infant'`) and seated infants (`'seated-infant'`)
168
+ * because they are priced differently by most carriers.
169
+ */
170
+ travelerType: 'adult' | 'child' | 'held-infant' | 'seated-infant';
171
+ /**
172
+ * Total price for this traveler in the offer's currency.
173
+ */
174
+ price: number;
175
+ /**
176
+ * Cabin class booked for this traveler. `null` when mixed across
177
+ * segments or not supplied.
178
+ */
179
+ cabin?: CabinClass | null;
180
+ }
181
+ /**
182
+ * Result returned by {@link FlightsProvider.priceOffer}.
183
+ *
184
+ * The `price` and `currency` reflect the upstream's authoritative price as
185
+ * of the moment of the call — providers MAY return a different price than
186
+ * the original {@link FlightOffer.price} if availability or fare rules
187
+ * have shifted between search and pricing.
188
+ */
189
+ export interface PricingResult {
190
+ /**
191
+ * Original opaque offer identifier the call was made for.
192
+ */
193
+ offerId: OfferId;
194
+ /**
195
+ * Authoritative grand-total price as of the moment of pricing.
196
+ */
197
+ price: number;
198
+ /**
199
+ * Currency the {@link price} is expressed in.
200
+ */
201
+ currency: CurrencyCode;
202
+ /**
203
+ * Per-passenger price breakdown rows. `null` when the upstream does not
204
+ * supply the breakdown.
205
+ */
206
+ travelerPricings?: TravelerPricing[] | null;
207
+ /**
208
+ * Timestamp the pricing snapshot was observed/published.
209
+ */
210
+ pricedAt: Date;
211
+ }
212
+ /**
213
+ * Options accepted by {@link FlightsProvider.searchFlights}.
214
+ */
215
+ export interface SearchFlightsOptions {
216
+ /**
217
+ * Origin IATA airport / city code (e.g. `'JFK'`, `'NYC'`).
218
+ */
219
+ origin: AirportCode;
220
+ /**
221
+ * Destination IATA airport / city code.
222
+ */
223
+ destination: AirportCode;
224
+ /**
225
+ * Outbound departure date (ISO 8601 calendar date, e.g. `'2026-07-15'`).
226
+ */
227
+ departureDate: IsoDate;
228
+ /**
229
+ * Return date for round-trip searches. Omit for one-way.
230
+ */
231
+ returnDate?: IsoDate;
232
+ /**
233
+ * Adult passenger count (>=12 years). Defaults to `1` when omitted.
234
+ */
235
+ adults?: number;
236
+ /**
237
+ * Child passenger count (2-11 years). Defaults to `0` when omitted.
238
+ */
239
+ children?: number;
240
+ /**
241
+ * Infant passenger count (<2 years, lap or seated). Defaults to `0`
242
+ * when omitted.
243
+ */
244
+ infants?: number;
245
+ /**
246
+ * Cabin class to search for. Defaults to `'economy'` when omitted.
247
+ */
248
+ cabin?: CabinClass;
249
+ /**
250
+ * Maximum number of offers to return. Implementations MAY clamp this
251
+ * to whatever upper bound their upstream API enforces.
252
+ */
253
+ maxResults?: number;
254
+ }
255
+ /**
256
+ * Flights provider interface.
257
+ *
258
+ * All flight providers (Amadeus, Duffel, Sabre, etc.) implement this
259
+ * interface. The interface is deliberately minimal so providers with very
260
+ * different upstream APIs can satisfy it identically. Providers that lack
261
+ * a "fetch single offer" call typically implement {@link getOffer} by
262
+ * round-tripping through their pricing endpoint and returning the priced
263
+ * offer.
264
+ */
265
+ export interface FlightsProvider {
266
+ /**
267
+ * Searches for flight offers matching the supplied itinerary.
268
+ *
269
+ * @param options - Search parameters (origin, destination, dates,
270
+ * passenger counts, cabin, etc.).
271
+ * @returns Array of normalized flight offers.
272
+ */
273
+ searchFlights(options: SearchFlightsOptions): Promise<FlightOffer[]>;
274
+ /**
275
+ * Retrieves a previously-searched offer in detail.
276
+ *
277
+ * @param offerId - Opaque offer identifier returned by
278
+ * {@link searchFlights}.
279
+ * @returns The offer with per-passenger price breakdown when available.
280
+ */
281
+ getOffer(offerId: OfferId): Promise<FlightOfferDetail>;
282
+ /**
283
+ * Confirms the up-to-the-minute price for a previously-searched offer.
284
+ *
285
+ * @param offerId - Opaque offer identifier returned by
286
+ * {@link searchFlights}.
287
+ * @returns Authoritative price snapshot.
288
+ */
289
+ priceOffer(offerId: OfferId): Promise<PricingResult>;
290
+ }
291
+ //#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O,CAAC,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,KAAK,CAAC,EAAE,UAAU,CAAA;IAElB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;;OAMG;IACH,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAAA;IAEpE;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAA;IAEtD;;;;;;OAMG;IACH,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,CAAA;CACrD"}
package/dist/types.js ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Type definitions for the flights core interface.
3
+ *
4
+ * @module
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@molecule/api-flights",
3
+ "version": "1.0.0",
4
+ "description": "Flight search + offer pricing core interface for molecule.dev",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "test": "vitest run",
11
+ "test:watch": "vitest"
12
+ },
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "keywords": [
23
+ "molecule",
24
+ "flights",
25
+ "travel",
26
+ "search",
27
+ "pricing"
28
+ ],
29
+ "license": "Apache-2.0",
30
+ "peerDependencies": {
31
+ "@molecule/api-bond": "^1.0.0",
32
+ "@molecule/api-i18n": "^1.0.0"
33
+ },
34
+ "devDependencies": {
35
+ "@molecule/api-bond": "1.0.0",
36
+ "@molecule/api-i18n": "1.0.0",
37
+ "@types/node": "26.1.2",
38
+ "typescript": "6.0.3",
39
+ "vitest": "4.1.10"
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "https://github.com/molecule-dev/molecule.git",
44
+ "directory": "packages/api/core/flights"
45
+ },
46
+ "homepage": "https://github.com/molecule-dev/molecule/tree/main/packages/api/core/flights",
47
+ "bugs": "https://github.com/molecule-dev/molecule/issues",
48
+ "publishConfig": {
49
+ "access": "public"
50
+ }
51
+ }