@voyant-travel/connect-flights 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 +38 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +75 -0
- package/package.json +70 -0
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# @voyant-travel/connect-flights
|
|
2
|
+
|
|
3
|
+
Voyant Connect flights adapter. Implements the Voyant `FlightConnectorAdapter`
|
|
4
|
+
contract by proxying to a Voyant Connect deployment's connect-api over HTTP
|
|
5
|
+
(via [`@voyant-travel/connect-sdk`](../connect-sdk)).
|
|
6
|
+
|
|
7
|
+
A Voyant deployment swaps its in-process demo flight adapter for this to route
|
|
8
|
+
flights through Voyant Connect to the real GDS connector behind a connection
|
|
9
|
+
(e.g. HiSky): search, price, book/hold, list orders, issue tickets, and cancel.
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createConnectFlightAdapter } from "@voyant-travel/connect-flights";
|
|
15
|
+
|
|
16
|
+
const adapter = createConnectFlightAdapter({
|
|
17
|
+
connect: {
|
|
18
|
+
apiKey: process.env.VOYANT_CONNECT_API_KEY!,
|
|
19
|
+
operatorId: process.env.VOYANT_OPERATOR_ID!,
|
|
20
|
+
baseUrl: process.env.VOYANT_CONNECT_BASE_URL, // defaults to the hosted API
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// In the deployment's flights runtime:
|
|
25
|
+
// resolveAdapter(c) => adapter (connectionId is supplied per request via ctx)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The connection id targeted by each call comes from `ctx.connectionId`.
|
|
29
|
+
|
|
30
|
+
## Scope
|
|
31
|
+
|
|
32
|
+
Implements the flight order lifecycle: `searchFlights`, `priceOffer`,
|
|
33
|
+
`bookFlight`, `getOrder`, `cancelOrder`, `listOrders`, `ticketOrder`.
|
|
34
|
+
|
|
35
|
+
Seat maps and ancillaries are not proxied yet: the connector contract models
|
|
36
|
+
them per-offer (pre-book), whereas the connect-sdk client exposes them
|
|
37
|
+
per-order (post-book), so they need an explicit mapping rather than a
|
|
38
|
+
pass-through. Tracked as a follow-up.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Voyant Connect flights adapter.
|
|
3
|
+
*
|
|
4
|
+
* Implements the Voyant `FlightConnectorAdapter` contract by proxying to a
|
|
5
|
+
* Voyant Connect deployment's connect-api over HTTP (via `@voyant-travel/
|
|
6
|
+
* connect-sdk`). A deployment swaps its in-process demo adapter for this to
|
|
7
|
+
* route flights through Voyant Connect to the real GDS connector behind a
|
|
8
|
+
* connection (e.g. HiSky) — book/hold, list, ticket, and cancel orders.
|
|
9
|
+
*
|
|
10
|
+
* Flights speak one contract end-to-end (connect-api ↔ hosted connector ↔
|
|
11
|
+
* deployment all use `@voyant-travel/flights-contracts`), and connect-api
|
|
12
|
+
* returns those contract shapes verbatim under its `{ data }` envelope (which
|
|
13
|
+
* the connect-sdk transport unwraps). The connect-sdk client types flight
|
|
14
|
+
* payloads opaquely as `JsonObject`, so this adapter is a thin, typed
|
|
15
|
+
* pass-through: forward the contract request, return the contract response.
|
|
16
|
+
*
|
|
17
|
+
* The connection id is taken from `ctx.connectionId` on every call — the
|
|
18
|
+
* deployment supplies which connection each request targets.
|
|
19
|
+
*/
|
|
20
|
+
import { type VoyantConnectClient, type VoyantConnectClientOptions } from "@voyant-travel/connect-sdk";
|
|
21
|
+
import type { FlightAdapterCapabilities, FlightConnectorAdapter } from "@voyant-travel/flights-contracts/contract/adapter";
|
|
22
|
+
export interface ConnectFlightAdapterOptions {
|
|
23
|
+
/** A pre-built Voyant Connect client. */
|
|
24
|
+
client?: VoyantConnectClient;
|
|
25
|
+
/** Options to build a client (apiKey, operatorId, baseUrl) when `client` is not supplied. */
|
|
26
|
+
connect?: VoyantConnectClientOptions;
|
|
27
|
+
/** `capabilities.provider` label — default `"connect"`. */
|
|
28
|
+
provider?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Declared flight capabilities for connections behind this adapter. The
|
|
31
|
+
* authoritative capabilities live per-connection at connect-api (from the
|
|
32
|
+
* connector's manifest); this static value is a best-effort hint for the
|
|
33
|
+
* deployment's orchestration. Defaults to holds + list-orders (Voyant
|
|
34
|
+
* Connect always lists orders from its own store, even when the underlying
|
|
35
|
+
* GDS connector cannot enumerate them).
|
|
36
|
+
*/
|
|
37
|
+
capabilities?: FlightAdapterCapabilities;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Build a `FlightConnectorAdapter` backed by Voyant Connect. Drop the result
|
|
41
|
+
* into the deployment's flights runtime `resolveAdapter` in place of the demo
|
|
42
|
+
* adapter.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createConnectFlightAdapter(options: ConnectFlightAdapterOptions): FlightConnectorAdapter;
|
|
45
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAML,KAAK,mBAAmB,EACxB,KAAK,0BAA0B,EAChC,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EACV,yBAAyB,EAGzB,sBAAsB,EAKvB,MAAM,mDAAmD,CAAC;AAE3D,MAAM,WAAW,2BAA2B;IAC1C,yCAAyC;IACzC,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAC7B,6FAA6F;IAC7F,OAAO,CAAC,EAAE,0BAA0B,CAAC;IACrC,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,yBAAyB,CAAC;CAC1C;AAYD;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,2BAA2B,GACnC,sBAAsB,CAsExB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Voyant Connect flights adapter.
|
|
3
|
+
*
|
|
4
|
+
* Implements the Voyant `FlightConnectorAdapter` contract by proxying to a
|
|
5
|
+
* Voyant Connect deployment's connect-api over HTTP (via `@voyant-travel/
|
|
6
|
+
* connect-sdk`). A deployment swaps its in-process demo adapter for this to
|
|
7
|
+
* route flights through Voyant Connect to the real GDS connector behind a
|
|
8
|
+
* connection (e.g. HiSky) — book/hold, list, ticket, and cancel orders.
|
|
9
|
+
*
|
|
10
|
+
* Flights speak one contract end-to-end (connect-api ↔ hosted connector ↔
|
|
11
|
+
* deployment all use `@voyant-travel/flights-contracts`), and connect-api
|
|
12
|
+
* returns those contract shapes verbatim under its `{ data }` envelope (which
|
|
13
|
+
* the connect-sdk transport unwraps). The connect-sdk client types flight
|
|
14
|
+
* payloads opaquely as `JsonObject`, so this adapter is a thin, typed
|
|
15
|
+
* pass-through: forward the contract request, return the contract response.
|
|
16
|
+
*
|
|
17
|
+
* The connection id is taken from `ctx.connectionId` on every call — the
|
|
18
|
+
* deployment supplies which connection each request targets.
|
|
19
|
+
*/
|
|
20
|
+
import { createVoyantConnectClient, } from "@voyant-travel/connect-sdk";
|
|
21
|
+
function resolveClient(options) {
|
|
22
|
+
if (options.client)
|
|
23
|
+
return options.client;
|
|
24
|
+
if (!options.connect) {
|
|
25
|
+
throw new Error("createConnectFlightAdapter requires either a `client` or `connect` option");
|
|
26
|
+
}
|
|
27
|
+
return createVoyantConnectClient(options.connect);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Build a `FlightConnectorAdapter` backed by Voyant Connect. Drop the result
|
|
31
|
+
* into the deployment's flights runtime `resolveAdapter` in place of the demo
|
|
32
|
+
* adapter.
|
|
33
|
+
*/
|
|
34
|
+
export function createConnectFlightAdapter(options) {
|
|
35
|
+
const client = resolveClient(options);
|
|
36
|
+
const capabilities = options.capabilities ?? {
|
|
37
|
+
provider: options.provider ?? "connect",
|
|
38
|
+
declared: ["flight/holds", "flight/list-orders"],
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
capabilities,
|
|
42
|
+
async searchFlights(ctx, request) {
|
|
43
|
+
return (await client.flights.searchOnConnection(ctx.connectionId, request));
|
|
44
|
+
},
|
|
45
|
+
async priceOffer(ctx, request) {
|
|
46
|
+
return (await client.flights.price(ctx.connectionId, request));
|
|
47
|
+
},
|
|
48
|
+
async bookFlight(ctx, request) {
|
|
49
|
+
return (await client.flights.book(ctx.connectionId, request));
|
|
50
|
+
},
|
|
51
|
+
async getOrder(ctx, orderId) {
|
|
52
|
+
return (await client.flights.getOrder(ctx.connectionId, orderId));
|
|
53
|
+
},
|
|
54
|
+
// connect-api's cancel route takes no reason body, so it is not forwarded.
|
|
55
|
+
async cancelOrder(ctx, orderId) {
|
|
56
|
+
return (await client.flights.cancelOrder(ctx.connectionId, orderId));
|
|
57
|
+
},
|
|
58
|
+
// Reads connect-api's operator-scoped order store — GDS connectors can't
|
|
59
|
+
// enumerate orders, so this does not depend on adapter list support.
|
|
60
|
+
async listOrders(ctx, query) {
|
|
61
|
+
const clientQuery = {
|
|
62
|
+
...(query.cursor ? { cursor: query.cursor } : {}),
|
|
63
|
+
...(query.limit !== undefined ? { limit: query.limit } : {}),
|
|
64
|
+
...(query.search ? { q: query.search } : {}),
|
|
65
|
+
...(query.status ? { status: query.status } : {}),
|
|
66
|
+
};
|
|
67
|
+
return (await client.flights.listOrders(ctx.connectionId, clientQuery));
|
|
68
|
+
},
|
|
69
|
+
// Promote a held order to ticketed (connect-api gates on the connector's
|
|
70
|
+
// `flight/holds` capability).
|
|
71
|
+
async ticketOrder(ctx, orderId) {
|
|
72
|
+
return (await client.flights.ticketOrder(ctx.connectionId, orderId));
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@voyant-travel/connect-flights",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Voyant Connect flights adapter for Voyant deployments.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/voyant-travel/connect.git",
|
|
9
|
+
"directory": "packages/connect-flights"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/voyant-travel/connect#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/voyant-travel/connect/issues"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./src/index.ts",
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"keywords": [
|
|
20
|
+
"voyant",
|
|
21
|
+
"voyant-connect",
|
|
22
|
+
"flights",
|
|
23
|
+
"adapter",
|
|
24
|
+
"sdk",
|
|
25
|
+
"typescript"
|
|
26
|
+
],
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./src/index.ts",
|
|
30
|
+
"default": "./dist/index.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc -p tsconfig.json",
|
|
38
|
+
"lint": "eslint src --max-warnings 0",
|
|
39
|
+
"check-types": "tsc --noEmit"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@voyant-travel/connect-sdk": "workspace:*"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"@voyant-travel/flights-contracts": ">=0.104.6 <1"
|
|
46
|
+
},
|
|
47
|
+
"peerDependenciesMeta": {
|
|
48
|
+
"@voyant-travel/flights-contracts": {
|
|
49
|
+
"optional": true
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@voyant-sdk/eslint-config": "workspace:*",
|
|
54
|
+
"@voyant-sdk/typescript-config": "workspace:*",
|
|
55
|
+
"@voyant-travel/flights-contracts": "^0.104.6",
|
|
56
|
+
"eslint": "^9.39.1",
|
|
57
|
+
"typescript": "5.9.2"
|
|
58
|
+
},
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"access": "public",
|
|
61
|
+
"main": "./dist/index.js",
|
|
62
|
+
"types": "./dist/index.d.ts",
|
|
63
|
+
"exports": {
|
|
64
|
+
".": {
|
|
65
|
+
"types": "./dist/index.d.ts",
|
|
66
|
+
"import": "./dist/index.js"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|