mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-05-02 04:30:00 +03:00
Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
|
b59d7b3084 | ||
|
db4c03054a | ||
|
eac21d188b | ||
|
ad09f8b1be |
15 changed files with 2400 additions and 35 deletions
|
@ -627,6 +627,8 @@
|
||||||
"Intervalle",
|
"Intervalle",
|
||||||
"tagesbest",
|
"tagesbest",
|
||||||
"dbbahnhof",
|
"dbbahnhof",
|
||||||
|
"Deutschlandticket",
|
||||||
|
"fahrverguenstigungen",
|
||||||
"cancelation"
|
"cancelation"
|
||||||
],
|
],
|
||||||
"ignorePaths": [
|
"ignorePaths": [
|
||||||
|
|
|
@ -10,7 +10,7 @@ With `opt`, you can override the default options, which look like this:
|
||||||
{
|
{
|
||||||
results: 8, // maximum number of results
|
results: 8, // maximum number of results
|
||||||
distance: null, // maximum walking distance in meters
|
distance: null, // maximum walking distance in meters
|
||||||
poi: false, // return points of interest?
|
poi: false, // not supported
|
||||||
stops: true, // return stops/stations?
|
stops: true, // return stops/stations?
|
||||||
subStops: true, // not supported
|
subStops: true, // not supported
|
||||||
entrances: true, // not supported
|
entrances: true, // not supported
|
||||||
|
|
|
@ -613,7 +613,7 @@ paths:
|
||||||
default: true
|
default: true
|
||||||
- name: linesOfStops
|
- name: linesOfStops
|
||||||
in: query
|
in: query
|
||||||
description: Parse & return lines of each stop/station?
|
description: not supported
|
||||||
schema:
|
schema:
|
||||||
type: boolean
|
type: boolean
|
||||||
default: false
|
default: false
|
||||||
|
@ -1887,11 +1887,11 @@ components:
|
||||||
default: false
|
default: false
|
||||||
type: boolean
|
type: boolean
|
||||||
subStops:
|
subStops:
|
||||||
description: parse & expose sub-stops of stations?
|
description: not supported
|
||||||
default: false
|
default: false
|
||||||
type: boolean
|
type: boolean
|
||||||
entrances:
|
entrances:
|
||||||
description: parse & expose entrances of stops/stations?
|
description: not supported
|
||||||
default: true
|
default: true
|
||||||
type: boolean
|
type: boolean
|
||||||
remarks:
|
remarks:
|
||||||
|
@ -1995,11 +1995,11 @@ components:
|
||||||
default: false
|
default: false
|
||||||
type: boolean
|
type: boolean
|
||||||
subStops:
|
subStops:
|
||||||
description: parse & expose sub-stops of stations?
|
description: not supported
|
||||||
default: true
|
default: true
|
||||||
type: boolean
|
type: boolean
|
||||||
entrances:
|
entrances:
|
||||||
description: parse & expose entrances of stops/stations?
|
description: not supported
|
||||||
default: true
|
default: true
|
||||||
type: boolean
|
type: boolean
|
||||||
remarks:
|
remarks:
|
||||||
|
@ -2034,15 +2034,15 @@ components:
|
||||||
default: true
|
default: true
|
||||||
type: boolean
|
type: boolean
|
||||||
subStops:
|
subStops:
|
||||||
description: parse & expose sub-stops of stations?
|
description: not supported
|
||||||
default: false
|
default: false
|
||||||
type: boolean
|
type: boolean
|
||||||
entrances:
|
entrances:
|
||||||
description: parse & expose entrances of stops/stations?
|
description: not supported
|
||||||
default: true
|
default: true
|
||||||
type: boolean
|
type: boolean
|
||||||
linesOfStops:
|
linesOfStops:
|
||||||
description: parse & expose lines at each stop/station?
|
description: not supported
|
||||||
default: false
|
default: false
|
||||||
type: boolean
|
type: boolean
|
||||||
language:
|
language:
|
||||||
|
@ -2061,11 +2061,11 @@ components:
|
||||||
default: false
|
default: false
|
||||||
type: boolean
|
type: boolean
|
||||||
subStops:
|
subStops:
|
||||||
description: parse & expose sub-stops of stations?
|
description: not supported
|
||||||
default: true
|
default: true
|
||||||
type: boolean
|
type: boolean
|
||||||
entrances:
|
entrances:
|
||||||
description: parse & expose entrances of stops/stations?
|
description: not supported
|
||||||
default: true
|
default: true
|
||||||
type: boolean
|
type: boolean
|
||||||
remarks:
|
remarks:
|
||||||
|
@ -2088,11 +2088,11 @@ components:
|
||||||
default: false
|
default: false
|
||||||
type: boolean
|
type: boolean
|
||||||
subStops:
|
subStops:
|
||||||
description: parse & expose sub-stops of stations?
|
description: not supported
|
||||||
default: true
|
default: true
|
||||||
type: boolean
|
type: boolean
|
||||||
entrances:
|
entrances:
|
||||||
description: parse & expose entrances of stops/stations?
|
description: not supported
|
||||||
default: true
|
default: true
|
||||||
type: boolean
|
type: boolean
|
||||||
remarks:
|
remarks:
|
||||||
|
@ -2128,11 +2128,11 @@ components:
|
||||||
default: 10
|
default: 10
|
||||||
type: number
|
type: number
|
||||||
subStops:
|
subStops:
|
||||||
description: parse & expose sub-stops of stations?
|
description: not supported
|
||||||
default: true
|
default: true
|
||||||
type: boolean
|
type: boolean
|
||||||
entrances:
|
entrances:
|
||||||
description: parse & expose entrances of stops/stations?
|
description: not supported
|
||||||
default: true
|
default: true
|
||||||
type: boolean
|
type: boolean
|
||||||
linesOfStops:
|
linesOfStops:
|
||||||
|
@ -2206,7 +2206,7 @@ components:
|
||||||
default: undefined
|
default: undefined
|
||||||
type: number
|
type: number
|
||||||
poi:
|
poi:
|
||||||
description: return points of interest?
|
description: not supported
|
||||||
default: false
|
default: false
|
||||||
type: boolean
|
type: boolean
|
||||||
stops:
|
stops:
|
||||||
|
@ -2218,15 +2218,15 @@ components:
|
||||||
description: products
|
description: products
|
||||||
default: undefined
|
default: undefined
|
||||||
subStops:
|
subStops:
|
||||||
description: parse & expose sub-stops of stations?
|
description: not supported
|
||||||
default: true
|
default: true
|
||||||
type: boolean
|
type: boolean
|
||||||
entrances:
|
entrances:
|
||||||
description: parse & expose entrances of stops/stations?
|
description: not supported
|
||||||
default: true
|
default: true
|
||||||
type: boolean
|
type: boolean
|
||||||
linesOfStops:
|
linesOfStops:
|
||||||
description: parse & expose lines at each stop/station?
|
description: not supported
|
||||||
default: false
|
default: false
|
||||||
type: boolean
|
type: boolean
|
||||||
language:
|
language:
|
||||||
|
@ -2254,11 +2254,11 @@ components:
|
||||||
description: products
|
description: products
|
||||||
default: undefined
|
default: undefined
|
||||||
subStops:
|
subStops:
|
||||||
description: parse & expose sub-stops of stations?
|
description: not supported
|
||||||
default: true
|
default: true
|
||||||
type: boolean
|
type: boolean
|
||||||
entrances:
|
entrances:
|
||||||
description: parse & expose entrances of stops/stations?
|
description: not supported
|
||||||
default: true
|
default: true
|
||||||
type: boolean
|
type: boolean
|
||||||
polylines:
|
polylines:
|
||||||
|
@ -2296,11 +2296,11 @@ components:
|
||||||
default: 20
|
default: 20
|
||||||
type: number
|
type: number
|
||||||
subStops:
|
subStops:
|
||||||
description: parse & expose sub-stops of stations?
|
description: not supported
|
||||||
default: true
|
default: true
|
||||||
type: boolean
|
type: boolean
|
||||||
entrances:
|
entrances:
|
||||||
description: parse & expose entrances of stops/stations?
|
description: not supported
|
||||||
default: true
|
default: true
|
||||||
type: boolean
|
type: boolean
|
||||||
polylines:
|
polylines:
|
||||||
|
|
4
index.js
4
index.js
|
@ -181,6 +181,8 @@ const createClient = (profile, userAgent, opt = {}) => {
|
||||||
scheduledDays: false, // parse & expose dates each journey is valid on?
|
scheduledDays: false, // parse & expose dates each journey is valid on?
|
||||||
notOnlyFastRoutes: false, // if true, also show routes that are mathematically non-optimal
|
notOnlyFastRoutes: false, // if true, also show routes that are mathematically non-optimal
|
||||||
bestprice: false, // search for lowest prices across the entire day
|
bestprice: false, // search for lowest prices across the entire day
|
||||||
|
deutschlandTicketDiscount: false,
|
||||||
|
deutschlandTicketConnectionsOnly: false,
|
||||||
}, opt);
|
}, opt);
|
||||||
|
|
||||||
if (opt.when !== undefined) {
|
if (opt.when !== undefined) {
|
||||||
|
@ -239,6 +241,8 @@ const createClient = (profile, userAgent, opt = {}) => {
|
||||||
entrances: true, // parse & expose entrances of stops/stations?
|
entrances: true, // parse & expose entrances of stops/stations?
|
||||||
remarks: true, // parse & expose hints & warnings?
|
remarks: true, // parse & expose hints & warnings?
|
||||||
scheduledDays: false, // parse & expose dates the journey is valid on?
|
scheduledDays: false, // parse & expose dates the journey is valid on?
|
||||||
|
deutschlandTicketDiscount: false,
|
||||||
|
deutschlandTicketConnectionsOnly: false,
|
||||||
}, opt);
|
}, opt);
|
||||||
|
|
||||||
const req = profile.formatRefreshJourneyReq({profile, opt}, refreshToken);
|
const req = profile.formatRefreshJourneyReq({profile, opt}, refreshToken);
|
||||||
|
|
|
@ -76,6 +76,18 @@ const mapRouteParsers = (route, parsers) => {
|
||||||
default: false,
|
default: false,
|
||||||
parse: parseBoolean,
|
parse: parseBoolean,
|
||||||
},
|
},
|
||||||
|
deutschlandTicketDiscount: {
|
||||||
|
description: 'Calculate ticket prices assuming Deutschlandticket is present',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
parse: parseBoolean,
|
||||||
|
},
|
||||||
|
deutschlandTicketConnectionsOnly: {
|
||||||
|
description: 'Only return journeys that can be used with the Deutschlandticket',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
parse: parseBoolean,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (route.includes('departures') || route.includes('arrivals')) {
|
if (route.includes('departures') || route.includes('arrivals')) {
|
||||||
|
|
|
@ -105,7 +105,6 @@ const request = async (ctx, userAgent, reqData) => {
|
||||||
if (reqOptions.query) {
|
if (reqOptions.query) {
|
||||||
url += '?' + stringify(reqOptions.query, {arrayFormat: 'brackets', encodeValuesOnly: true});
|
url += '?' + stringify(reqOptions.query, {arrayFormat: 'brackets', encodeValuesOnly: true});
|
||||||
}
|
}
|
||||||
console.log(url);
|
|
||||||
const reqId = randomBytesHexString(6);
|
const reqId = randomBytesHexString(6);
|
||||||
const fetchReq = new Request(url, reqOptions);
|
const fetchReq = new Request(url, reqOptions);
|
||||||
profile.logRequest(ctx, fetchReq, reqId);
|
profile.logRequest(ctx, fetchReq, reqId);
|
||||||
|
@ -122,6 +121,7 @@ const request = async (ctx, userAgent, reqData) => {
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
// todo [breaking]: make this a FetchError or a HafasClientError?
|
// todo [breaking]: make this a FetchError or a HafasClientError?
|
||||||
|
console.log(JSON.stringify(res), await res.text());
|
||||||
const err = new Error(res.statusText);
|
const err = new Error(res.statusText);
|
||||||
Object.assign(err, errProps);
|
Object.assign(err, errProps);
|
||||||
throw err;
|
throw err;
|
||||||
|
|
|
@ -9,6 +9,10 @@ const formatBaseJourneysReq = (ctx) => {
|
||||||
einstiegsTypList: [
|
einstiegsTypList: [
|
||||||
'STANDARD',
|
'STANDARD',
|
||||||
],
|
],
|
||||||
|
fahrverguenstigungen: {
|
||||||
|
deutschlandTicketVorhanden: ctx.opt.deutschlandTicketDiscount,
|
||||||
|
nurDeutschlandTicketVerbindungen: ctx.opt.deutschlandTicketConnectionsOnly,
|
||||||
|
},
|
||||||
klasse: travellers.klasse,
|
klasse: travellers.klasse,
|
||||||
reisendenProfil: {
|
reisendenProfil: {
|
||||||
reisende: travellers.reisende.map(t => {
|
reisende: travellers.reisende.map(t => {
|
||||||
|
|
|
@ -10,8 +10,8 @@ const formatJourneysReq = (ctx, from, to, when, outFrwd, journeysRef) => {
|
||||||
let query = {
|
let query = {
|
||||||
maxUmstiege: transfers,
|
maxUmstiege: transfers,
|
||||||
minUmstiegszeit: opt.transferTime,
|
minUmstiegszeit: opt.transferTime,
|
||||||
deutschlandTicketVorhanden: false,
|
deutschlandTicketVorhanden: opt.deutschlandTicketDiscount,
|
||||||
nurDeutschlandTicketVerbindungen: false,
|
nurDeutschlandTicketVerbindungen: opt.deutschlandTicketConnectionsOnly,
|
||||||
reservierungsKontingenteVorhanden: false,
|
reservierungsKontingenteVorhanden: false,
|
||||||
schnelleVerbindungen: !opt.notOnlyFastRoutes,
|
schnelleVerbindungen: !opt.notOnlyFastRoutes,
|
||||||
sitzplatzOnly: false,
|
sitzplatzOnly: false,
|
||||||
|
|
4
package-lock.json
generated
4
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "db-vendo-client",
|
"name": "db-vendo-client",
|
||||||
"version": "6.8.0",
|
"version": "6.8.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "db-vendo-client",
|
"name": "db-vendo-client",
|
||||||
"version": "6.8.0",
|
"version": "6.8.2",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"content-type": "^1.0.5",
|
"content-type": "^1.0.5",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "db-vendo-client",
|
"name": "db-vendo-client",
|
||||||
"description": "Client for bahn.de public transport APIs.",
|
"description": "Client for bahn.de public transport APIs.",
|
||||||
"version": "6.8.0",
|
"version": "6.8.2",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"files": [
|
"files": [
|
||||||
|
|
|
@ -127,7 +127,7 @@ if (!process.env.VCR_OFF) {
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('refreshJourney – valid tickets', async (t) => {
|
tap.test('refreshJourney – valid tickets', async (t) => {
|
||||||
const T_MOCK = 1710831600 * 1000; // 2024-03-19T08:00:00+01:00
|
const T_MOCK = 1758279600 * 1000;
|
||||||
const when = createWhen(dbProfile.timezone, dbProfile.locale, T_MOCK);
|
const when = createWhen(dbProfile.timezone, dbProfile.locale, T_MOCK);
|
||||||
|
|
||||||
const journeysRes = await client.journeys(berlinHbf, münchenHbf, {
|
const journeysRes = await client.journeys(berlinHbf, münchenHbf, {
|
||||||
|
@ -261,7 +261,7 @@ if (!process.env.VCR_MODE) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tap.test('refreshJourney', async (t) => {
|
tap.test('refreshJourney', async (t) => {
|
||||||
const T_MOCK = 1710831600 * 1000; // 2024-03-19T08:00:00+01:00
|
const T_MOCK = 1763542800 * 1000;
|
||||||
const when = createWhen(dbProfile.timezone, dbProfile.locale, T_MOCK);
|
const when = createWhen(dbProfile.timezone, dbProfile.locale, T_MOCK);
|
||||||
const validate = createValidate({...cfg, when});
|
const validate = createValidate({...cfg, when});
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ tap.test('journeys – Berlin Schwedter Str. to München Hbf', async (t) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('refreshJourney – valid tickets', async (t) => {
|
tap.test('refreshJourney – valid tickets', async (t) => {
|
||||||
const T_MOCK = 1710831600 * 1000; // 2024-03-19T08:00:00+01:00
|
const T_MOCK = 1758279600 * 1000;
|
||||||
const when = createWhen(dbProfile.timezone, dbProfile.locale, T_MOCK);
|
const when = createWhen(dbProfile.timezone, dbProfile.locale, T_MOCK);
|
||||||
|
|
||||||
const journeysRes = await client.journeys(berlinHbf, münchenHbf, {
|
const journeysRes = await client.journeys(berlinHbf, münchenHbf, {
|
||||||
|
@ -261,7 +261,7 @@ if (!process.env.VCR_OFF) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tap.test('refreshJourney', async (t) => {
|
tap.test('refreshJourney', async (t) => {
|
||||||
const T_MOCK = 1710831600 * 1000; // 2024-03-19T08:00:00+01:00
|
const T_MOCK = 1763542800 * 1000;
|
||||||
const when = createWhen(dbProfile.timezone, dbProfile.locale, T_MOCK);
|
const when = createWhen(dbProfile.timezone, dbProfile.locale, T_MOCK);
|
||||||
const validate = createValidate({...cfg, when});
|
const validate = createValidate({...cfg, when});
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -41,6 +41,10 @@ const berlinWienQuery0 = Object.freeze(
|
||||||
einstiegsTypList: [
|
einstiegsTypList: [
|
||||||
'STANDARD',
|
'STANDARD',
|
||||||
],
|
],
|
||||||
|
fahrverguenstigungen: {
|
||||||
|
deutschlandTicketVorhanden: undefined,
|
||||||
|
nurDeutschlandTicketVerbindungen: undefined,
|
||||||
|
},
|
||||||
klasse: 'KLASSE_2',
|
klasse: 'KLASSE_2',
|
||||||
reiseHin: {
|
reiseHin: {
|
||||||
wunsch: {
|
wunsch: {
|
||||||
|
|
|
@ -57,8 +57,8 @@ const berlinWienQuery0 = Object.freeze(
|
||||||
sitzplatzOnly: false,
|
sitzplatzOnly: false,
|
||||||
bikeCarriage: false,
|
bikeCarriage: false,
|
||||||
reservierungsKontingenteVorhanden: false,
|
reservierungsKontingenteVorhanden: false,
|
||||||
nurDeutschlandTicketVerbindungen: false,
|
nurDeutschlandTicketVerbindungen: undefined,
|
||||||
deutschlandTicketVorhanden: false,
|
deutschlandTicketVorhanden: undefined,
|
||||||
maxUmstiege: null,
|
maxUmstiege: null,
|
||||||
zwischenhalte: null,
|
zwischenhalte: null,
|
||||||
minUmstiegszeit: 0,
|
minUmstiegszeit: 0,
|
||||||
|
|
Loading…
Add table
Reference in a new issue