@voyantjs/flights-contracts 0.96.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 +45 -0
- package/dist/contract/adapter.d.ts +210 -0
- package/dist/contract/adapter.d.ts.map +1 -0
- package/dist/contract/adapter.js +43 -0
- package/dist/contract/post-book-types.d.ts +90 -0
- package/dist/contract/post-book-types.d.ts.map +1 -0
- package/dist/contract/post-book-types.js +1 -0
- package/dist/contract/schemas.d.ts +3896 -0
- package/dist/contract/schemas.d.ts.map +1 -0
- package/dist/contract/schemas.js +508 -0
- package/dist/contract/types.d.ts +504 -0
- package/dist/contract/types.d.ts.map +1 -0
- package/dist/contract/types.js +35 -0
- package/dist/contracts.test.d.ts +2 -0
- package/dist/contracts.test.d.ts.map +1 -0
- package/dist/contracts.test.js +18 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/reference/contract.d.ts +90 -0
- package/dist/reference/contract.d.ts.map +1 -0
- package/dist/reference/contract.js +26 -0
- package/dist/reference/static-bundle.d.ts +29 -0
- package/dist/reference/static-bundle.d.ts.map +1 -0
- package/dist/reference/static-bundle.js +83 -0
- package/package.json +81 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ReferenceDataProvider` contract — swappable provider for global
|
|
3
|
+
* reference data (airlines, airports, aircraft, currencies, countries).
|
|
4
|
+
*
|
|
5
|
+
* Per architecture §5.11.6 / §6, implementable at any layer:
|
|
6
|
+
* - **In-deployment local Postgres** (the simplest case)
|
|
7
|
+
* - Static JSON / CSV bundle
|
|
8
|
+
* - Internal data lake / warehouse
|
|
9
|
+
* - Third-party services (OAG, Cirium, RouteHappy)
|
|
10
|
+
* - GDS-bundled reference subscriptions
|
|
11
|
+
* - Voyant Data (the hosted default)
|
|
12
|
+
*
|
|
13
|
+
* No implementer is privileged. Operators can run a fully self-contained
|
|
14
|
+
* Voyant deployment with all reference data in their own database, no
|
|
15
|
+
* external dependency.
|
|
16
|
+
*
|
|
17
|
+
* See `docs/architecture/catalog-flights-architecture.md` §6.
|
|
18
|
+
*/
|
|
19
|
+
export interface Airline {
|
|
20
|
+
iataCode: string;
|
|
21
|
+
icaoCode?: string;
|
|
22
|
+
name: string;
|
|
23
|
+
/** ISO 3166-1 alpha-2 country code. */
|
|
24
|
+
country?: string;
|
|
25
|
+
/** Optional logo URL. */
|
|
26
|
+
logoUrl?: string;
|
|
27
|
+
/** Optional alliance affiliation: `"oneworld"`, `"star-alliance"`, `"skyteam"`. */
|
|
28
|
+
alliance?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface Airport {
|
|
31
|
+
iataCode: string;
|
|
32
|
+
icaoCode?: string;
|
|
33
|
+
name: string;
|
|
34
|
+
city: string;
|
|
35
|
+
/** ISO 3166-1 alpha-2. */
|
|
36
|
+
country: string;
|
|
37
|
+
timezone?: string;
|
|
38
|
+
latitude?: number;
|
|
39
|
+
longitude?: number;
|
|
40
|
+
}
|
|
41
|
+
export interface Aircraft {
|
|
42
|
+
iataCode: string;
|
|
43
|
+
icaoCode?: string;
|
|
44
|
+
name: string;
|
|
45
|
+
manufacturer?: string;
|
|
46
|
+
/** Optional capacity hint (typical seat count). */
|
|
47
|
+
typicalSeats?: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Capabilities declared by the provider. Lets the catalog plane fail
|
|
51
|
+
* fast when a deployment requests reference data the provider can't
|
|
52
|
+
* serve (e.g. asking for currencies from a provider that only covers
|
|
53
|
+
* airlines/airports).
|
|
54
|
+
*/
|
|
55
|
+
export interface ReferenceDataCapabilities {
|
|
56
|
+
coversAirlines: boolean;
|
|
57
|
+
coversAirports: boolean;
|
|
58
|
+
coversAircraft: boolean;
|
|
59
|
+
coversCurrencies: boolean;
|
|
60
|
+
coversCountries: boolean;
|
|
61
|
+
/** True for hosted/read-only providers; false for ones that allow upserts. */
|
|
62
|
+
isReadOnly: boolean;
|
|
63
|
+
/** How often the provider's data refreshes from upstream. */
|
|
64
|
+
refreshCadence: "static" | "weekly" | "daily" | "on-demand";
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The reference data contract. Used by flight integrations to hydrate
|
|
68
|
+
* IATA codes into human-readable names + metadata; usable by any other
|
|
69
|
+
* vertical that needs the same lookup surface.
|
|
70
|
+
*/
|
|
71
|
+
export interface ReferenceDataProvider {
|
|
72
|
+
readonly capabilities: ReferenceDataCapabilities;
|
|
73
|
+
/** Look up one airline by IATA code. Returns null if not found. */
|
|
74
|
+
getAirline(iataCode: string): Promise<Airline | null>;
|
|
75
|
+
/** Look up one airport by IATA code. */
|
|
76
|
+
getAirport(iataCode: string): Promise<Airport | null>;
|
|
77
|
+
/** Look up one aircraft type by IATA code. */
|
|
78
|
+
getAircraft(iataCode: string): Promise<Aircraft | null>;
|
|
79
|
+
/** Batch lookup — preferred for hydrating offers / orders with many codes. */
|
|
80
|
+
getAirlines(iataCodes: string[]): Promise<Map<string, Airline>>;
|
|
81
|
+
getAirports(iataCodes: string[]): Promise<Map<string, Airport>>;
|
|
82
|
+
getAircraftBatch(iataCodes: string[]): Promise<Map<string, Aircraft>>;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Helper that hydrates a batch of distinct IATA codes once and returns a
|
|
86
|
+
* Map. Used internally by providers that fetch from a slow upstream and
|
|
87
|
+
* want to serve repeated lookups from an in-memory cache.
|
|
88
|
+
*/
|
|
89
|
+
export declare function dedupeCodes(codes: string[]): string[];
|
|
90
|
+
//# sourceMappingURL=contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../src/reference/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,WAAW,OAAO;IACtB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,EA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C;IACxC,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IAErD,8CAA8C;IAC9C,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAA;IAEvD,8EAA8E;IAC9E,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IAC/D,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IAC/D,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAA;CACtE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAErD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ReferenceDataProvider` contract — swappable provider for global
|
|
3
|
+
* reference data (airlines, airports, aircraft, currencies, countries).
|
|
4
|
+
*
|
|
5
|
+
* Per architecture §5.11.6 / §6, implementable at any layer:
|
|
6
|
+
* - **In-deployment local Postgres** (the simplest case)
|
|
7
|
+
* - Static JSON / CSV bundle
|
|
8
|
+
* - Internal data lake / warehouse
|
|
9
|
+
* - Third-party services (OAG, Cirium, RouteHappy)
|
|
10
|
+
* - GDS-bundled reference subscriptions
|
|
11
|
+
* - Voyant Data (the hosted default)
|
|
12
|
+
*
|
|
13
|
+
* No implementer is privileged. Operators can run a fully self-contained
|
|
14
|
+
* Voyant deployment with all reference data in their own database, no
|
|
15
|
+
* external dependency.
|
|
16
|
+
*
|
|
17
|
+
* See `docs/architecture/catalog-flights-architecture.md` §6.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Helper that hydrates a batch of distinct IATA codes once and returns a
|
|
21
|
+
* Map. Used internally by providers that fetch from a slow upstream and
|
|
22
|
+
* want to serve repeated lookups from an in-memory cache.
|
|
23
|
+
*/
|
|
24
|
+
export function dedupeCodes(codes) {
|
|
25
|
+
return Array.from(new Set(codes.filter((c) => c.length > 0)));
|
|
26
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static-bundle `ReferenceDataProvider`.
|
|
3
|
+
*
|
|
4
|
+
* Even simpler than a local-Postgres provider — ship a JSON / CSV bundle
|
|
5
|
+
* with the deployment, load it into memory at startup, serve from a `Map`.
|
|
6
|
+
* Appropriate for small operators with stable, narrow geographic scope and
|
|
7
|
+
* no need for refresh.
|
|
8
|
+
*
|
|
9
|
+
* No DB, no external service, no network call.
|
|
10
|
+
*
|
|
11
|
+
* See `docs/architecture/catalog-flights-architecture.md` §6.2.
|
|
12
|
+
*/
|
|
13
|
+
import type { Aircraft, Airline, Airport, ReferenceDataCapabilities, ReferenceDataProvider } from "./contract.js";
|
|
14
|
+
export interface StaticBundleReferenceData {
|
|
15
|
+
airlines?: Airline[];
|
|
16
|
+
airports?: Airport[];
|
|
17
|
+
aircraft?: Aircraft[];
|
|
18
|
+
}
|
|
19
|
+
export interface StaticBundleProviderOptions {
|
|
20
|
+
data: StaticBundleReferenceData;
|
|
21
|
+
/** Override capabilities; defaults are inferred from which arrays are populated. */
|
|
22
|
+
capabilities?: Partial<ReferenceDataCapabilities>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Build a `ReferenceDataProvider` from in-memory bundles. Maps are built
|
|
26
|
+
* once at construction; lookups are O(1).
|
|
27
|
+
*/
|
|
28
|
+
export declare function createStaticBundleReferenceProvider(options: StaticBundleProviderOptions): ReferenceDataProvider;
|
|
29
|
+
//# sourceMappingURL=static-bundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static-bundle.d.ts","sourceRoot":"","sources":["../../src/reference/static-bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EACV,QAAQ,EACR,OAAO,EACP,OAAO,EACP,yBAAyB,EACzB,qBAAqB,EACtB,MAAM,eAAe,CAAA;AAGtB,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAA;IACpB,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAA;CACtB;AAED,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,yBAAyB,CAAA;IAC/B,oFAAoF;IACpF,YAAY,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,CAAA;CAClD;AAED;;;GAGG;AACH,wBAAgB,mCAAmC,CACjD,OAAO,EAAE,2BAA2B,GACnC,qBAAqB,CAuEvB"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static-bundle `ReferenceDataProvider`.
|
|
3
|
+
*
|
|
4
|
+
* Even simpler than a local-Postgres provider — ship a JSON / CSV bundle
|
|
5
|
+
* with the deployment, load it into memory at startup, serve from a `Map`.
|
|
6
|
+
* Appropriate for small operators with stable, narrow geographic scope and
|
|
7
|
+
* no need for refresh.
|
|
8
|
+
*
|
|
9
|
+
* No DB, no external service, no network call.
|
|
10
|
+
*
|
|
11
|
+
* See `docs/architecture/catalog-flights-architecture.md` §6.2.
|
|
12
|
+
*/
|
|
13
|
+
import { dedupeCodes } from "./contract.js";
|
|
14
|
+
/**
|
|
15
|
+
* Build a `ReferenceDataProvider` from in-memory bundles. Maps are built
|
|
16
|
+
* once at construction; lookups are O(1).
|
|
17
|
+
*/
|
|
18
|
+
export function createStaticBundleReferenceProvider(options) {
|
|
19
|
+
const airlines = new Map();
|
|
20
|
+
const airports = new Map();
|
|
21
|
+
const aircraft = new Map();
|
|
22
|
+
for (const airline of options.data.airlines ?? []) {
|
|
23
|
+
airlines.set(airline.iataCode, airline);
|
|
24
|
+
}
|
|
25
|
+
for (const airport of options.data.airports ?? []) {
|
|
26
|
+
airports.set(airport.iataCode, airport);
|
|
27
|
+
}
|
|
28
|
+
for (const ac of options.data.aircraft ?? []) {
|
|
29
|
+
aircraft.set(ac.iataCode, ac);
|
|
30
|
+
}
|
|
31
|
+
const inferredCapabilities = {
|
|
32
|
+
coversAirlines: airlines.size > 0,
|
|
33
|
+
coversAirports: airports.size > 0,
|
|
34
|
+
coversAircraft: aircraft.size > 0,
|
|
35
|
+
coversCurrencies: false,
|
|
36
|
+
coversCountries: false,
|
|
37
|
+
isReadOnly: true,
|
|
38
|
+
refreshCadence: "static",
|
|
39
|
+
...options.capabilities,
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
capabilities: inferredCapabilities,
|
|
43
|
+
async getAirline(iataCode) {
|
|
44
|
+
return airlines.get(iataCode) ?? null;
|
|
45
|
+
},
|
|
46
|
+
async getAirport(iataCode) {
|
|
47
|
+
return airports.get(iataCode) ?? null;
|
|
48
|
+
},
|
|
49
|
+
async getAircraft(iataCode) {
|
|
50
|
+
return aircraft.get(iataCode) ?? null;
|
|
51
|
+
},
|
|
52
|
+
async getAirlines(iataCodes) {
|
|
53
|
+
const codes = dedupeCodes(iataCodes);
|
|
54
|
+
const result = new Map();
|
|
55
|
+
for (const code of codes) {
|
|
56
|
+
const value = airlines.get(code);
|
|
57
|
+
if (value)
|
|
58
|
+
result.set(code, value);
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
},
|
|
62
|
+
async getAirports(iataCodes) {
|
|
63
|
+
const codes = dedupeCodes(iataCodes);
|
|
64
|
+
const result = new Map();
|
|
65
|
+
for (const code of codes) {
|
|
66
|
+
const value = airports.get(code);
|
|
67
|
+
if (value)
|
|
68
|
+
result.set(code, value);
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
},
|
|
72
|
+
async getAircraftBatch(iataCodes) {
|
|
73
|
+
const codes = dedupeCodes(iataCodes);
|
|
74
|
+
const result = new Map();
|
|
75
|
+
for (const code of codes) {
|
|
76
|
+
const value = aircraft.get(code);
|
|
77
|
+
if (value)
|
|
78
|
+
result.set(code, value);
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@voyantjs/flights-contracts",
|
|
3
|
+
"version": "0.96.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./src/index.ts",
|
|
8
|
+
"./contract/types": "./src/contract/types.ts",
|
|
9
|
+
"./contract/adapter": "./src/contract/adapter.ts",
|
|
10
|
+
"./contract/schemas": "./src/contract/schemas.ts",
|
|
11
|
+
"./contract/post-book-types": "./src/contract/post-book-types.ts",
|
|
12
|
+
"./reference/contract": "./src/reference/contract.ts",
|
|
13
|
+
"./reference/static-bundle": "./src/reference/static-bundle.ts"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"typecheck": "tsc --noEmit",
|
|
17
|
+
"lint": "biome check src/",
|
|
18
|
+
"test": "vitest run --passWithNoTests",
|
|
19
|
+
"build": "tsc -p tsconfig.json",
|
|
20
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
21
|
+
"prepack": "pnpm run build"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js",
|
|
32
|
+
"default": "./dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./contract/types": {
|
|
35
|
+
"types": "./dist/contract/types.d.ts",
|
|
36
|
+
"import": "./dist/contract/types.js",
|
|
37
|
+
"default": "./dist/contract/types.js"
|
|
38
|
+
},
|
|
39
|
+
"./contract/adapter": {
|
|
40
|
+
"types": "./dist/contract/adapter.d.ts",
|
|
41
|
+
"import": "./dist/contract/adapter.js",
|
|
42
|
+
"default": "./dist/contract/adapter.js"
|
|
43
|
+
},
|
|
44
|
+
"./contract/schemas": {
|
|
45
|
+
"types": "./dist/contract/schemas.d.ts",
|
|
46
|
+
"import": "./dist/contract/schemas.js",
|
|
47
|
+
"default": "./dist/contract/schemas.js"
|
|
48
|
+
},
|
|
49
|
+
"./contract/post-book-types": {
|
|
50
|
+
"types": "./dist/contract/post-book-types.d.ts",
|
|
51
|
+
"import": "./dist/contract/post-book-types.js",
|
|
52
|
+
"default": "./dist/contract/post-book-types.js"
|
|
53
|
+
},
|
|
54
|
+
"./reference/contract": {
|
|
55
|
+
"types": "./dist/reference/contract.d.ts",
|
|
56
|
+
"import": "./dist/reference/contract.js",
|
|
57
|
+
"default": "./dist/reference/contract.js"
|
|
58
|
+
},
|
|
59
|
+
"./reference/static-bundle": {
|
|
60
|
+
"types": "./dist/reference/static-bundle.d.ts",
|
|
61
|
+
"import": "./dist/reference/static-bundle.js",
|
|
62
|
+
"default": "./dist/reference/static-bundle.js"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"main": "./dist/index.js",
|
|
66
|
+
"types": "./dist/index.d.ts"
|
|
67
|
+
},
|
|
68
|
+
"dependencies": {
|
|
69
|
+
"zod": "^4.3.6"
|
|
70
|
+
},
|
|
71
|
+
"devDependencies": {
|
|
72
|
+
"@voyantjs/voyant-typescript-config": "workspace:*",
|
|
73
|
+
"typescript": "^6.0.2",
|
|
74
|
+
"vitest": "^4.1.2"
|
|
75
|
+
},
|
|
76
|
+
"repository": {
|
|
77
|
+
"type": "git",
|
|
78
|
+
"url": "https://github.com/voyantjs/voyant.git",
|
|
79
|
+
"directory": "packages/flights-contracts"
|
|
80
|
+
}
|
|
81
|
+
}
|