JavaScript client SDK client for Flexport's API v2
Note: This library is not feature complete, until then 1.x releases may contain breaking changes.
npm i --save @distributeaid/flexport-sdk
see ./src/examples
for working examples.
import { v2Client } from "@distributeaid/flexport-sdk";
const client = v2Client({ apiKey: "your api key" });
import * as TE from "fp-ts/lib/TaskEither";
import { pipe } from "fp-ts/lib/pipeable";
pipe(
client.shipment_index(),
TE.map((shipments) => {
console.dir(shipments, { depth: 9 });
})
)();
import { liftShipmentLeg } from "@distributeaid/flexport-sdk";
pipe(
client.shipment_show({ id: shipmentId }),
TE.map(({ legs }) => legs), // Extract legs link, Option<ResolvableCollection>
TE.chain(TE.fromOption(() => createError("Shipment has no legs!"))),
TE.chain(client.resolveCollection(liftShipmentLeg)), // Resolve the link to the collection
TE.map((legs) => {
console.dir(legs, { depth: 9 });
})
)();
import { paginate } from "@distributeaid/flexport-sdk";
pipe(
client.shipment_index(),
TE.chain(paginate(client.resolvePage(liftShipment))),
TE.map((shipments) => {
console.dir(shipments, { depth: 9 });
})
)();
The types in ./src/generated
are generated using
./src/bin/generateTypes.ts
, which parses the
Open API 3 definition file
(source). However this API
documentation contains errors, which are corrected in the schema through
a file containing corrections, before the base
types are generated.
The lifters in the same files lift the Flexport API responses into the SDK
domain, by augmenting them with higher level properties. They are generated with
the API client using
./src/bin/generateApiOperations.ts
.
see ./adr.