db-vendo-client
Advanced tools
Comparing version 6.1.2 to 6.2.0
@@ -36,3 +36,3 @@ import {createClient} from './index.js'; | ||
homepage: 'https://github.com/public-transport/db-vendo-client', | ||
version: '6.1.2', | ||
version: '6.2.0', | ||
docsLink: 'https://github.com/public-transport/db-vendo-client', | ||
@@ -50,3 +50,3 @@ openapiSpec: true, | ||
const start = async () => { | ||
const vendo = createClient(dbProfile, 'my-hafas-rest-api', config); | ||
const vendo = createClient(dbProfile, process.env.USER_AGENT || process.env.HOSTNAME || 'link-to-your-project-or-email', config); | ||
const api = await createApi(vendo, config); | ||
@@ -53,0 +53,0 @@ |
21
index.js
@@ -7,4 +7,2 @@ import isObj from 'lodash/isObject.js'; | ||
import {validateProfile} from './lib/validate-profile.js'; | ||
import {INVALID_REQUEST} from './lib/errors.js'; | ||
import {HafasError} from './lib/errors.js'; | ||
@@ -258,8 +256,6 @@ // background info: https://github.com/public-transport/hafas-client/issues/286 | ||
const stop = async (stop, opt = {}) => { // TODO | ||
if ('object' === typeof stop) { | ||
stop = profile.formatStation(stop.id); | ||
} else if ('string' === typeof stop) { | ||
stop = profile.formatStation(stop); | ||
} else { | ||
const stop = async (stop, opt = {}) => { | ||
if (isObj(stop) && stop.id) { | ||
stop = stop.id; | ||
} else if ('string' !== typeof stop) { | ||
throw new TypeError('stop must be an object or a string.'); | ||
@@ -278,11 +274,4 @@ } | ||
const {res} = await profile.request({profile, opt}, userAgent, req); | ||
if (!res || !Array.isArray(res.locL) || !res.locL[0]) { | ||
throw new HafasError('invalid response, expected locL[0]', null, { | ||
// This problem occurs on invalid input. 🙄 | ||
code: INVALID_REQUEST, | ||
}); | ||
} | ||
const ctx = {profile, opt, res, common}; | ||
return profile.parseLocation(ctx, res.locL[0]); | ||
return profile.parseStop(ctx, res, stop); | ||
}; | ||
@@ -289,0 +278,0 @@ |
@@ -6,3 +6,2 @@ import {request} from '../lib/request.js'; | ||
import {formatStationBoardReq} from '../format/station-board-req.js'; | ||
import {formatStopReq} from '../format/stop-req.js'; | ||
import {formatTripReq} from '../format/trip-req.js'; | ||
@@ -40,2 +39,3 @@ import {formatNearbyReq} from '../format/nearby-req.js'; | ||
import {formatLoyaltyCard} from '../format/loyalty-cards.js'; | ||
import {formatTransfers} from '../format/transfers.js'; | ||
@@ -67,3 +67,3 @@ const DEBUG = (/(^|,)hafas-client(,|$)/).test(process.env.DEBUG || ''); | ||
formatLocationsReq: notImplemented, | ||
formatStopReq, | ||
formatStopReq: notImplemented, | ||
formatTripReq, | ||
@@ -97,2 +97,3 @@ formatNearbyReq, | ||
parseTickets, | ||
parseStop: notImplemented, | ||
@@ -110,2 +111,3 @@ formatAddress, | ||
formatTimeOfDay, | ||
formatTransfers, | ||
formatTravellers, | ||
@@ -112,0 +114,0 @@ formatRectangle: id, |
@@ -7,6 +7,7 @@ const formatJourneysReq = (ctx, from, to, when, outFrwd, journeysRef) => { | ||
const filters = profile.formatProductsFilter({profile}, opt.products || {}); | ||
const transfers = profile.formatTransfers(opt.transfers); | ||
// TODO opt.accessibility | ||
// TODO routingMode | ||
let query = { | ||
maxUmstiege: opt.transfers, | ||
maxUmstiege: transfers, | ||
minUmstiegszeit: opt.transferTime, | ||
@@ -13,0 +14,0 @@ deutschlandTicketVorhanden: false, |
@@ -6,2 +6,3 @@ { | ||
"locationsEndpoint": "https://app.vendo.noncd.db.de/mob/location/search", | ||
"stopEndpoint": "https://app.vendo.noncd.db.de/mob/location/details/", | ||
"nearbyEndpoint": "https://app.vendo.noncd.db.de/mob/location/nearby", | ||
@@ -8,0 +9,0 @@ "tripEndpoint": "https://app.vendo.noncd.db.de/mob/zuglauf/", |
@@ -10,4 +10,6 @@ import {createRequire} from 'module'; | ||
import {formatLocationsReq} from './locations-req.js'; | ||
import {formatStopReq} from './stop-req.js'; | ||
import {formatNearbyReq} from './nearby-req.js'; | ||
import {formatStationBoardReq} from './station-board-req.js'; | ||
import {parseStop} from './parse-stop.js'; | ||
@@ -25,4 +27,7 @@ const profile = { | ||
formatLocationsReq, | ||
formatStopReq, | ||
formatStationBoardReq, | ||
formatLocationFilter, | ||
parseStop, | ||
}; | ||
@@ -29,0 +34,0 @@ |
@@ -34,2 +34,3 @@ import {getHeaders} from './header.js'; | ||
const filters = profile.formatProductsFilter({profile}, opt.products || {}, 'dbnav'); | ||
const transfers = profile.formatTransfers(opt.transfers) ?? undefined; // `dbnav` does not allow `null` here | ||
// TODO opt.accessibility | ||
@@ -50,3 +51,3 @@ // TODO routingMode | ||
zielLocationId: to.lid, | ||
maxUmstiege: opt.transfers || undefined, | ||
maxUmstiege: transfers, | ||
minUmstiegsdauer: opt.transferTime || undefined, | ||
@@ -53,0 +54,0 @@ fahrradmitnahme: opt.bike, |
{ | ||
"name": "db-vendo-client", | ||
"description": "Client for bahn.de public transport APIs.", | ||
"version": "6.1.2", | ||
"version": "6.2.0", | ||
"type": "module", | ||
@@ -6,0 +6,0 @@ "main": "index.js", |
@@ -19,5 +19,5 @@ # db-vendo-client | ||
* loadFactor and other details in boards | ||
* certain stop details like products for `locations()` and geopositions and remarks for boards – this can be remedied by turning on `enrichStations` in the options, enriching location info with [db-hafas-stations](https://github.com/derhuerst/db-hafas-stations). | ||
* certain stop details like products for `locations()` and geopositions and remarks for boards – this can be remedied by turning on `enrichStations` in the config, enriching location info with [db-hafas-stations](https://github.com/derhuerst/db-hafas-stations). | ||
* some query options/filters (e.g. routingMode for journeys, direction for boards) | ||
* all other endpoints (`tripsByName()`, `radar()`, `journeysFromTrip()`, `reachableFrom()`, `remarks()`, `lines()`, `stop()`, `station()`) | ||
* all other endpoints (`tripsByName()`, `radar()`, `journeysFromTrip()`, `reachableFrom()`, `remarks()`, `lines()`, `station()`) | ||
@@ -30,7 +30,9 @@ Depending on the configured profile, db-vendo-client will use multiple different DB APIs that offer varying functionality, so choose wisely: | ||
| max duration boards | 12h | 1h | | ||
| remarks | not for boards | ✅ | | ||
| remarks | not for boards | ✅ (still no `remarks()` endpoint) | | ||
| cancelled trips | not contained in boards | contained with cancelled flag | | ||
| tickets | only for `refreshJourney()` | only for `refreshJourney()`, mutually exclusive with polylines | | ||
| polylines | only for `trip()` | only for `refreshJourney()/trip()`, mutually exclusive with tickets | | ||
| trip ids used | HAFAS trip ids for journeys, RIS trip ids for boards | HAFAS trip ids | | ||
| trip ids used | HAFAS trip ids for journeys, RIS trip ids for boards (static on train splits?) | HAFAS trip ids | | ||
| line.id/fahrtNr used | unreliable/route id for journeys, actual fahrtNr for boards | unreliable/route id | | ||
| `stop()` | ❌ | ✅ | | ||
| assumed backend API stability | less stable | more stable | | ||
@@ -53,4 +55,14 @@ | ||
See an example in [api.js](api.js). It shows how you can use `db-vendo-client` together with `hafas-rest-api` in order to run a [FPTF](https://github.com/public-transport/friendly-public-transport-format) API server. The [Dockerfile](Dockerfile) serves this API. | ||
Use it as a dependency, e.g. just replacing [hafas-client](https://github.com/public-transport/hafas-client/): | ||
``` | ||
npm i db-vendo-client | ||
``` | ||
See an example in [api.js](api.js). It shows how you can use `db-vendo-client` together with [hafas-rest-api](https://github.com/public-transport/hafas-rest-api/) in order to run a [FPTF](https://github.com/public-transport/friendly-public-transport-format) API server. The [Dockerfile](Dockerfile) serves this API (using the `db` profile): | ||
``` | ||
docker run -e USER_AGENT=my-awesome-program -p 3000:3000 ghcr.io/public-transport/db-vendo-client | ||
``` | ||
There are [community-maintained TypeScript typings available as `@types/hafas-client`](https://www.npmjs.com/package/@types/hafas-client). | ||
@@ -57,0 +69,0 @@ |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
2036788
112
3103
81
12