This commit is contained in:
Traines 2024-12-08 21:42:57 +00:00
parent 65aae69481
commit f8a79834b3
31 changed files with 766 additions and 875 deletions

35
api.js
View file

@ -1,26 +1,31 @@
import {createClient} from './index.js'
import {profile as dbProfile} from './p/db/index.js'
import {createHafasRestApi as createApi} from 'hafas-rest-api'
import {createClient} from './index.js';
import {profile as dbProfile} from './p/db/index.js';
import {createHafasRestApi as createApi} from 'hafas-rest-api';
const config = {
hostname: process.env.HOSTNAME || 'localhost',
port: process.env.PORT ? parseInt(process.env.PORT) : 3000,
name: "db-vendo-client",
description: "db-vendo-client",
homepage: "https://github.com/public-transport/db-vendo-client",
version: "6.0.0",
name: 'db-vendo-client',
description: 'db-vendo-client',
homepage: 'https://github.com/public-transport/db-vendo-client',
version: '6.0.0',
docsLink: 'https://github.com/public-transport/db-vendo-client',
openapiSpec: true,
logging: true,
aboutPage: true,
etags: 'strong',
csp: `default-src 'none' style-src 'self' 'unsafe-inline' img-src https:`,
csp: 'default-src \'none\' style-src \'self\' \'unsafe-inline\' img-src https:',
};
const start = async () => {
const vendo = createClient(dbProfile, 'my-hafas-rest-api');
const api = await createApi(vendo, config);
api.listen(config.port, (err) => {
if (err) {
console.error(err);
}
});
};
const vendo = createClient(dbProfile, 'my-hafas-rest-api')
const api = await createApi(vendo, config)
api.listen(3000, (err) => {
if (err) console.error(err)
})
start();

View file

@ -8,7 +8,7 @@ const formatLocationsReq = (ctx, query) => {
suchbegriff: query,
limit: opt.results,
},
method: 'get'
method: 'get',
};
};

View file

@ -12,7 +12,7 @@ const formatNearbyReq = (ctx, location) => {
// TODO getStops: Boolean(opt.stops),
maxNo: opt.results,
},
method: 'get'
method: 'get',
};
};

View file

@ -13,14 +13,14 @@ const formatStationBoardReq = (ctx, station, type) => {
includeStationGroup: opt.includeRelatedStations,
maxTransportsPerType: opt.results === Infinity ? undefined : opt.results,
includeMessagesDisruptions: opt.remarks,
sortBy: 'TIME_SCHEDULE'
sortBy: 'TIME_SCHEDULE',
},
method: 'get',
headers: {
'Db-Client-Id': process.env.DB_CLIENT_ID,
'Db-Api-Key': process.env.DB_API_KEY,
'Accept': 'application/vnd.de.db.ris+json'
}
'Accept': 'application/vnd.de.db.ris+json',
},
};
};

View file

@ -17,7 +17,7 @@ const formatTime = (profile, when, includeOffset = false) => {
zone: timezone,
})
.startOf('second')
.toISO({ includeOffset: includeOffset, suppressMilliseconds: true })
.toISO({includeOffset: includeOffset, suppressMilliseconds: true});
};
export {

View file

@ -200,7 +200,7 @@ const createClient = (profile, userAgent, opt = {}) => {
// see rest.exe docs
// ushrp: Boolean(opt.startWithWalking),
};
if (journeysRef) { TODO
if (journeysRef) {
query.pagingReference = journeysRef;
} else {
query.anfrageZeitpunkt = profile.formatTime(profile, when);
@ -219,7 +219,7 @@ const createClient = (profile, userAgent, opt = {}) => {
earlierRef: res.verbindungReference?.earlier || null,
laterRef: res.verbindungReference?.later || null,
journeys,
realtimeDataUpdatedAt: null // TODO
realtimeDataUpdatedAt: null, // TODO
};
};

View file

@ -3,12 +3,10 @@ import {isIP} from 'net';
import {Agent as HttpsAgent} from 'https';
import roundRobin from '@derhuerst/round-robin-scheduler';
import {randomBytes} from 'crypto';
import createHash from 'create-hash';
import {Buffer} from 'node:buffer';
import {stringify} from 'qs';
import {Request, fetch} from 'cross-fetch';
import {parse as parseContentType} from 'content-type';
import {HafasError, byErrorCode} from './errors.js';
import {HafasError} from './errors.js';
const proxyAddress = process.env.HTTPS_PROXY || process.env.HTTP_PROXY || null;
const localAddresses = process.env.LOCAL_ADDRESS || null;
@ -97,7 +95,7 @@ const checkIfResponseIsOk = (_) => {
};
const request = async (ctx, userAgent, reqData) => {
const {profile, opt} = ctx;
const {profile} = ctx;
const endpoint = reqData.endpoint;
delete reqData.endpoint;

View file

@ -14,11 +14,11 @@ const ageGroup = {
};
const ageGroupLabel = {
'B': 'KLEINKIND',
'K': 'FAMILIENKIND',
'Y': 'JUGENDLICHER',
'E': 'ERWACHSENER',
'S': 'SENIOR',
B: 'KLEINKIND',
K: 'FAMILIENKIND',
Y: 'JUGENDLICHER',
E: 'ERWACHSENER',
S: 'SENIOR',
};
const ageGroupFromAge = (age) => {

View file

@ -3,7 +3,6 @@
import {createRequire} from 'module';
const require = createRequire(import.meta.url);
import trim from 'lodash/trim.js';
import uniqBy from 'lodash/uniqBy.js';
import slugg from 'slugg';
import without from 'lodash/without.js';
@ -17,13 +16,11 @@ import {parseDeparture as _parseDeparture} from '../../parse/departure.js';
import {parseLocation as _parseLocation} from '../../parse/location.js';
import {formatStation as _formatStation} from '../../format/station.js';
import {parseDateTime} from '../../parse/date-time.js';
import {bike} from '../../format/filters.js';
const baseProfile = require('./base.json');
import {products} from './products.js';
import {formatLoyaltyCard} from './loyalty-cards.js';
import {ageGroup, ageGroupFromAge, ageGroupLabel} from './ageGroup.js';
import {routingModes} from './routing-modes.js';
const transformReqBody = (ctx, body) => {
return body;
@ -162,6 +159,7 @@ const parseLoadFactor = (opt, auslastung) => {
};
const parseArrOrDepWithLoadFactor = ({parsed, res, opt}, d) => {
/* const load = parseLoadFactor(opt, d);
if (load) {
parsed.loadFactor = load;
@ -187,10 +185,10 @@ Pass in just opt.age, and the age group will calculated automatically.`);
typ: ageGroupLabel[tvlrAgeGroup || ageGroup.ADULT],
anzahl: 1,
alter: 'age' in opt
? [opt.age+'']
? [String(opt.age)]
: [],
ermaessigungen: [formatLoyaltyCard(opt.loyaltyCard)]
}]
ermaessigungen: [formatLoyaltyCard(opt.loyaltyCard)],
}],
};
return basicCtrfReq;
};
@ -200,7 +198,7 @@ const transformJourneysQuery = ({profile, opt}, query) => {
return {
endpoint: profile.journeysEndpoint,
body: query,
method: 'post'
method: 'post',
};
};
@ -225,55 +223,6 @@ const formatRefreshJourneyReq = (ctx, refreshToken) => {
};
};
const parseShpCtx = (addDataTicketInfo) => {
try {
return JSON.parse(atob(addDataTicketInfo)).shpCtx;
} catch (e) {
// in case addDataTicketInfo is not a valid base64 string
return null;
}
};
const addDbOfferSelectionUrl = (journey, opt) => {
// if no ticket contains addData, we can't get the offer selection URL
if (journey.tickets.some((t) => t.addDataTicketInfo)) {
const queryParams = new URLSearchParams();
// Add individual parameters
queryParams.append('A.1', opt.age);
queryParams.append('E', 'F');
queryParams.append('E.1', opt.loyaltyCard ? formatLoyaltyCard(opt.loyaltyCard) : '0');
queryParams.append('K', opt.firstClass ? '1' : '2');
queryParams.append('M', 'D');
queryParams.append('RT.1', 'E');
queryParams.append('SS', journey.legs[0].origin.id);
queryParams.append('T', journey.legs[0].departure);
queryParams.append('VH', journey.refreshToken);
queryParams.append('ZS', journey.legs[journey.legs.length - 1].destination.id);
queryParams.append('journeyOptions', '0');
queryParams.append('journeyProducts', '1023');
queryParams.append('optimize', '1');
queryParams.append('returnurl', 'dbnavigator://');
const endpoint = opt.language === 'de' ? 'dox' : 'eox';
journey.tickets.forEach((t) => {
const shpCtx = parseShpCtx(t.addDataTicketInfo);
if (shpCtx) {
const url = new URL(`https://mobile.bahn.de/bin/mobil/query.exe/${endpoint}`);
url.searchParams = new URLSearchParams(queryParams);
url.searchParams.append('shpCtx', shpCtx);
t.url = url.href;
} else {
t.url = null;
}
});
}
};
// todo: fix this
// line: {
// type: 'line',
@ -311,63 +260,6 @@ const mutateToAddPrice = (parsed, raw) => {
return parsed;
};
const isFirstClassTicket = (addData, opt) => {
// if addData is undefined, it is assumed that the ticket is not first class
// (this is the case for S-Bahn tickets)
if (!addData) {
return false;
}
try {
const addDataJson = JSON.parse(atob(addData));
return Boolean(addDataJson.Upsell === 'S1' || opt.firstClass);
} catch (err) {
return false;
}
};
const mutateToAddTickets = (parsed, opt, j) => {
if (
j.trfRes
&& Array.isArray(j.trfRes.fareSetL)
) {
const addData = j.trfRes.fareSetL[0].addData;
parsed.tickets = j.trfRes.fareSetL
.filter(s => Array.isArray(s.fareL) && s.fareL.length > 0)
.map((s) => {
const fare = s.fareL[0];
if (!fare.ticketL) { // if journeys()
return {
name: fare.buttonText,
priceObj: {amount: fare.price.amount},
};
} else { // if refreshJourney()
return {
name: fare.name || fare.ticketL[0].name,
priceObj: fare.ticketL[0].price,
addData: addData,
addDataTicketInfo: s.addData,
addDataTicketDetails: fare.addData,
addDataTravelInfo: fare.ticketL[0].addData,
firstClass: isFirstClassTicket(s.addData, opt),
};
}
});
// add price info, to avoid breaking changes
// todo [breaking]: remove this format
if (parsed.tickets.length > 0 && !parsed.price) {
parsed.price = {
...parsed.tickets[0].priceObj,
amount: parsed.tickets[0].priceObj.amount / 100,
currency: 'EUR',
};
}
if (opt.generateUnreliableTicketUrls) {
addDbOfferSelectionUrl(parsed, opt);
}
}
};
const parseJourneyWithPriceAndTickets = ({parsed, opt}, raw) => {
mutateToAddPrice(parsed, raw);
// mutateToAddTickets(parsed, opt, raw); TODO
@ -574,17 +466,9 @@ const hintsByCode = Object.assign(Object.create(null), {
},
});
const codesByText = Object.assign(Object.create(null), {
'journey cancelled': 'journey-cancelled', // todo: German variant
'stop cancelled': 'stop-cancelled', // todo: change to `stopover-cancelled`, German variant
'signal failure': 'signal-failure',
'signalstörung': 'signal-failure',
'additional stop': 'additional-stopover', // todo: German variant
'platform change': 'changed platform', // todo: use dash, German variant
});
const parseHintByCode = (raw) => {
const hint = hintsByCode[raw.key.trim().toLowerCase()];
const hint = hintsByCode[raw.key.trim()
.toLowerCase()];
if (hint) {
return Object.assign({text: raw.value}, hint);
}

View file

@ -1,6 +1,3 @@
import {deepStrictEqual as eql} from 'node:assert';
// todo: generate from https://reiseauskunft.bahn.de/addons/fachkonfig-utf8.cfg ?
const c = {
NONE: Symbol('no loyalty card'),
BAHNCARD: Symbol('Bahncard'),
@ -15,42 +12,42 @@ const c = {
const formatLoyaltyCard = (data) => {
if (!data) {
return {
"art": "KEINE_ERMAESSIGUNG",
"klasse": "KLASSENLOS"
}
art: 'KEINE_ERMAESSIGUNG',
klasse: 'KLASSENLOS',
};
}
const cls = data.class === 1 ? 'KLASSE_1' : 'KLASSE_2';
if (data.type === c.BAHNCARD) {
return {
art: 'BAHNCARD' + data.discount,
klasse: cls
}
klasse: cls,
};
}
if (data.type === c.VORTEILSCARD) {
return {
art: 'A-VORTEILSCARD',
klasse: 'KLASSENLOS'
}
klasse: 'KLASSENLOS',
};
}
if (data.type === c.HALBTAXABO) {
return {
art: 'CH-HALBTAXABO_OHNE_RAILPLUS',
klasse: 'KLASSENLOS'
}
klasse: 'KLASSENLOS',
};
}
// TODO Rest
if (data.type === c.GENERALABONNEMENT) {
return {
art: 'CH-GENERAL-ABONNEMENT',
klasse: cls
}
klasse: cls,
};
}
return {
"art": "KEINE_ERMAESSIGUNG",
"klasse": "KLASSENLOS"
}
art: 'KEINE_ERMAESSIGUNG',
klasse: 'KLASSENLOS',
};
};
export {
c as data,
formatLoyaltyCard
formatLoyaltyCard,
};

View file

@ -5,8 +5,8 @@ const locationFallback = (id, name) => {
type: 'stop',
id: id,
name: name,
location: null
}
location: null,
};
};
const parseJourneyLeg = (ctx, pt, date) => { // pt = raw leg

View file

@ -12,7 +12,7 @@ const parseLine = (ctx, p) => {
// TODO res.adminCode
res.productName = p.verkehrsmittel?.kurzText || p.transport?.category;
const foundProduct = profile.products.find(pp => pp.vendo == p.verkehrsmittel?.produktGattung || pp.ris == p.transport?.type)
const foundProduct = profile.products.find(pp => pp.vendo == p.verkehrsmittel?.produktGattung || pp.ris == p.transport?.type);
res.mode = foundProduct?.mode;
res.product = foundProduct?.id;

View file

@ -7,7 +7,7 @@ const ADDRESS = 'ADR';
const leadingZeros = /^0+/;
const parseLocation = (ctx, l) => {
const {profile, opt} = ctx;
const {profile} = ctx;
if (!l) {
return null;

View file

@ -1,7 +1,7 @@
const parseBitmask = ({profile}, bitmask) => {
const res = {};
for (let product of profile.products) {
res[product.id] = !!bitmask.find(p => p == product.vendo);
res[product.id] = Boolean(bitmask.find(p => p == product.vendo));
}
return res;
};

View file

@ -10,18 +10,27 @@ const parseRemarks = (ctx, ref) => {
ref.messages || [],
ref.attributes || [],
ref.disruptions || [],
]).map(remark => {
])
.map(remark => {
if (remark.kategorie) {
const res = ctx.profile.parseHintByCode(remark);
if (res) return res;
if (res) {
return res;
}
}
let type = 'hint';
if (remark.prioritaet || remark.type) type = 'status';
if (!remark.kategorie && remark.key || remark.disruptionID || remark.prioritaet && remark.prioritaet == 'HOCH') type = 'warning';
if (remark.prioritaet || remark.type) {
type = 'status';
}
if (!remark.kategorie && remark.key || remark.disruptionID || remark.prioritaet && remark.prioritaet == 'HOCH') {
type = 'warning';
}
let res = {
code: remark.code || remark.key,
summary: remark.nachrichtKurz || remark.value || remark.ueberschrift || remark.text || Object.values(remark.descriptions || {}).shift()?.textShort,
text: remark.nachrichtLang || remark.value || remark.text || Object.values(remark.descriptions || {}).shift()?.text,
summary: remark.nachrichtKurz || remark.value || remark.ueberschrift || remark.text || Object.values(remark.descriptions || {})
.shift()?.textShort,
text: remark.nachrichtLang || remark.value || remark.text || Object.values(remark.descriptions || {})
.shift()?.text,
type: type,
};
if (remark.modDateTime) {
@ -30,7 +39,8 @@ const parseRemarks = (ctx, ref) => {
// TODO fromStops, toStops = routeIdxFrom ??
// TODO prio
return res;
}).filter(remark => remark.code != 'BEF');
})
.filter(remark => remark.code != 'BEF');
};
/*
@ -180,10 +190,10 @@ const parseRemarks = (ctx, ref) => {
*/
const isStopCancelled = (ref) => {
return !!ref.risNotizen.find(r => r.key == 'text.realtime.stop.cancelled' || r.type == 'HALT_AUSFALL');
}
return Boolean(ref.risNotizen.find(r => r.key == 'text.realtime.stop.cancelled' || r.type == 'HALT_AUSFALL'));
};
export {
parseRemarks,
isStopCancelled
isStopCancelled,
};

View file

@ -3,7 +3,7 @@ import maxBy from 'lodash/maxBy.js';
import last from 'lodash/last.js';
const parseTrip = (ctx, t) => { // t = raw trip
const {profile, opt} = ctx;
const {profile} = ctx;
// pretend the trip is a leg in a journey
const fakeLeg = {

View file

@ -1,322 +1,322 @@
const dbArrivals = [
{
"tripId": "20241208-c33bba6c-a73a-3eec-8a64-76356c922ece",
"stop": {
"type": "stop",
"id": "8089100",
"name": "Berlin Jungfernheide (S)",
"location": null
tripId: '20241208-c33bba6c-a73a-3eec-8a64-76356c922ece',
stop: {
type: 'stop',
id: '8089100',
name: 'Berlin Jungfernheide (S)',
location: null,
},
"when": "2024-12-08T01:00:00+01:00",
"plannedWhen": "2024-12-08T01:00:00+01:00",
"delay": 0,
"platform": "6",
"plannedPlatform": "6",
"direction": null,
"provenance": "Berlin Beusselstraße",
"line": {
"type": "line",
"id": "s-42-42323",
"fahrtNr": 42323,
"name": "S 42 (42323)",
"public": true,
"productName": "S",
"mode": "train",
"product": "suburban",
"operator": null
when: '2024-12-08T01:00:00+01:00',
plannedWhen: '2024-12-08T01:00:00+01:00',
delay: 0,
platform: '6',
plannedPlatform: '6',
direction: null,
provenance: 'Berlin Beusselstraße',
line: {
type: 'line',
id: 's-42-42323',
fahrtNr: 42323,
name: 'S 42 (42323)',
public: true,
productName: 'S',
mode: 'train',
product: 'suburban',
operator: null,
},
"remarks": [
remarks: [
{
"code": "FB",
"summary": "Fahrradmitnahme begrenzt möglich",
"text": "Fahrradmitnahme begrenzt möglich",
"type": "hint"
}
code: 'FB',
summary: 'Fahrradmitnahme begrenzt möglich',
text: 'Fahrradmitnahme begrenzt möglich',
type: 'hint',
},
],
"origin": {
"type": "stop",
"id": "8089118",
"name": "Berlin Beusselstraße",
"location": null
origin: {
type: 'stop',
id: '8089118',
name: 'Berlin Beusselstraße',
location: null,
},
"destination": null
destination: null,
},
{
"tripId": "20241208-89eeca5a-1768-3713-894a-dd088977f42b",
"stop": {
"type": "stop",
"id": "730985",
"name": "Jungfernheide Bahnhof (S+U), Berlin",
"location": null
tripId: '20241208-89eeca5a-1768-3713-894a-dd088977f42b',
stop: {
type: 'stop',
id: '730985',
name: 'Jungfernheide Bahnhof (S+U), Berlin',
location: null,
},
"when": "2024-12-08T01:00:00+01:00",
"plannedWhen": "2024-12-08T01:00:00+01:00",
"delay": 0,
"platform": null,
"plannedPlatform": null,
"direction": null,
"provenance": "Rudow (U), Berlin",
"line": {
"type": "line",
"id": "u-7-15421",
"fahrtNr": 15421,
"name": "U 7 (15421)",
"public": true,
"productName": "U",
"mode": "train",
"product": "subway",
"operator": null
when: '2024-12-08T01:00:00+01:00',
plannedWhen: '2024-12-08T01:00:00+01:00',
delay: 0,
platform: null,
plannedPlatform: null,
direction: null,
provenance: 'Rudow (U), Berlin',
line: {
type: 'line',
id: 'u-7-15421',
fahrtNr: 15421,
name: 'U 7 (15421)',
public: true,
productName: 'U',
mode: 'train',
product: 'subway',
operator: null,
},
"remarks": [
remarks: [
{
"code": "FB",
"summary": "Fahrradmitnahme begrenzt möglich",
"text": "Fahrradmitnahme begrenzt möglich",
"type": "hint"
code: 'FB',
summary: 'Fahrradmitnahme begrenzt möglich',
text: 'Fahrradmitnahme begrenzt möglich',
type: 'hint',
},
{
"code": "RG",
"summary": "Behindertengerechtes Fahrzeug",
"text": "Behindertengerechtes Fahrzeug",
"type": "hint"
}
code: 'RG',
summary: 'Behindertengerechtes Fahrzeug',
text: 'Behindertengerechtes Fahrzeug',
type: 'hint',
},
],
"origin": {
"type": "stop",
"id": "732218",
"name": "Rudow (U), Berlin",
"location": null
origin: {
type: 'stop',
id: '732218',
name: 'Rudow (U), Berlin',
location: null,
},
"destination": null
destination: null,
},
{
"tripId": "20241208-2dc4f2d4-a1e1-3bbf-a607-98ff71c927d0",
"stop": {
"type": "stop",
"id": "730985",
"name": "Jungfernheide Bahnhof (S+U), Berlin",
"location": null
tripId: '20241208-2dc4f2d4-a1e1-3bbf-a607-98ff71c927d0',
stop: {
type: 'stop',
id: '730985',
name: 'Jungfernheide Bahnhof (S+U), Berlin',
location: null,
},
"when": "2024-12-08T01:03:00+01:00",
"plannedWhen": "2024-12-08T01:03:00+01:00",
"delay": 0,
"platform": null,
"plannedPlatform": null,
"direction": null,
"provenance": "Goerdelersteg, Berlin",
"line": {
"type": "line",
"id": "bus-m21-93424",
"fahrtNr": 93424,
"name": "Bus M21 (93424)",
"public": true,
"productName": "Bus",
"mode": "bus",
"product": "bus",
"operator": null
when: '2024-12-08T01:03:00+01:00',
plannedWhen: '2024-12-08T01:03:00+01:00',
delay: 0,
platform: null,
plannedPlatform: null,
direction: null,
provenance: 'Goerdelersteg, Berlin',
line: {
type: 'line',
id: 'bus-m21-93424',
fahrtNr: 93424,
name: 'Bus M21 (93424)',
public: true,
productName: 'Bus',
mode: 'bus',
product: 'bus',
operator: null,
},
"remarks": [
remarks: [
{
"code": "NF",
"summary": "keine Fahrradbeförderung möglich",
"text": "keine Fahrradbeförderung möglich",
"type": "hint"
code: 'NF',
summary: 'keine Fahrradbeförderung möglich',
text: 'keine Fahrradbeförderung möglich',
type: 'hint',
},
{
"code": "RG",
"summary": "Behindertengerechtes Fahrzeug",
"text": "Behindertengerechtes Fahrzeug",
"type": "hint"
}
code: 'RG',
summary: 'Behindertengerechtes Fahrzeug',
text: 'Behindertengerechtes Fahrzeug',
type: 'hint',
},
],
"origin": {
"type": "stop",
"id": "730993",
"name": "Goerdelersteg, Berlin",
"location": null
origin: {
type: 'stop',
id: '730993',
name: 'Goerdelersteg, Berlin',
location: null,
},
"destination": null
destination: null,
},
{
"tripId": "20241208-6fa6d37c-a1c0-3f84-bdac-0424705bffaf",
"stop": {
"type": "stop",
"id": "8089100",
"name": "Berlin Jungfernheide (S)",
"location": null
tripId: '20241208-6fa6d37c-a1c0-3f84-bdac-0424705bffaf',
stop: {
type: 'stop',
id: '8089100',
name: 'Berlin Jungfernheide (S)',
location: null,
},
"when": "2024-12-08T01:05:00+01:00",
"plannedWhen": "2024-12-08T01:05:00+01:00",
"delay": 0,
"platform": "5",
"plannedPlatform": "5",
"direction": null,
"provenance": "Berlin Beusselstraße",
"line": {
"type": "line",
"id": "s-41-41254",
"fahrtNr": 41254,
"name": "S 41 (41254)",
"public": true,
"productName": "S",
"mode": "train",
"product": "suburban",
"operator": null
when: '2024-12-08T01:05:00+01:00',
plannedWhen: '2024-12-08T01:05:00+01:00',
delay: 0,
platform: '5',
plannedPlatform: '5',
direction: null,
provenance: 'Berlin Beusselstraße',
line: {
type: 'line',
id: 's-41-41254',
fahrtNr: 41254,
name: 'S 41 (41254)',
public: true,
productName: 'S',
mode: 'train',
product: 'suburban',
operator: null,
},
"remarks": [
remarks: [
{
"code": "FB",
"summary": "Fahrradmitnahme begrenzt möglich",
"text": "Fahrradmitnahme begrenzt möglich",
"type": "hint"
}
code: 'FB',
summary: 'Fahrradmitnahme begrenzt möglich',
text: 'Fahrradmitnahme begrenzt möglich',
type: 'hint',
},
],
"origin": {
"type": "stop",
"id": "8089118",
"name": "Berlin Beusselstraße",
"location": null
origin: {
type: 'stop',
id: '8089118',
name: 'Berlin Beusselstraße',
location: null,
},
"destination": null
destination: null,
},
{
"tripId": "20241208-c4abf007-d667-3bf1-87a8-2d1b153c014d",
"stop": {
"type": "stop",
"id": "730985",
"name": "Jungfernheide Bahnhof (S+U), Berlin",
"location": null
tripId: '20241208-c4abf007-d667-3bf1-87a8-2d1b153c014d',
stop: {
type: 'stop',
id: '730985',
name: 'Jungfernheide Bahnhof (S+U), Berlin',
location: null,
},
"when": "2024-12-08T01:10:00+01:00",
"plannedWhen": "2024-12-08T01:10:00+01:00",
"delay": 0,
"platform": null,
"plannedPlatform": null,
"direction": null,
"provenance": "Rudow (U), Berlin",
"line": {
"type": "line",
"id": "u-7-15422",
"fahrtNr": 15422,
"name": "U 7 (15422)",
"public": true,
"productName": "U",
"mode": "train",
"product": "subway",
"operator": null
when: '2024-12-08T01:10:00+01:00',
plannedWhen: '2024-12-08T01:10:00+01:00',
delay: 0,
platform: null,
plannedPlatform: null,
direction: null,
provenance: 'Rudow (U), Berlin',
line: {
type: 'line',
id: 'u-7-15422',
fahrtNr: 15422,
name: 'U 7 (15422)',
public: true,
productName: 'U',
mode: 'train',
product: 'subway',
operator: null,
},
"remarks": [
remarks: [
{
"code": "FB",
"summary": "Fahrradmitnahme begrenzt möglich",
"text": "Fahrradmitnahme begrenzt möglich",
"type": "hint"
code: 'FB',
summary: 'Fahrradmitnahme begrenzt möglich',
text: 'Fahrradmitnahme begrenzt möglich',
type: 'hint',
},
{
"code": "RG",
"summary": "Behindertengerechtes Fahrzeug",
"text": "Behindertengerechtes Fahrzeug",
"type": "hint"
}
code: 'RG',
summary: 'Behindertengerechtes Fahrzeug',
text: 'Behindertengerechtes Fahrzeug',
type: 'hint',
},
],
"origin": {
"type": "stop",
"id": "732218",
"name": "Rudow (U), Berlin",
"location": null
origin: {
type: 'stop',
id: '732218',
name: 'Rudow (U), Berlin',
location: null,
},
"destination": null
destination: null,
},
{
"tripId": "20241208-c8b6e3e4-6acb-3237-b89e-1fca72497555",
"stop": {
"type": "stop",
"id": "8089100",
"name": "Berlin Jungfernheide (S)",
"location": null
tripId: '20241208-c8b6e3e4-6acb-3237-b89e-1fca72497555',
stop: {
type: 'stop',
id: '8089100',
name: 'Berlin Jungfernheide (S)',
location: null,
},
"when": "2024-12-08T01:10:00+01:00",
"plannedWhen": "2024-12-08T01:10:00+01:00",
"delay": 0,
"platform": "6",
"plannedPlatform": "6",
"direction": null,
"provenance": "Berlin Beusselstraße",
"line": {
"type": "line",
"id": "s-42-42325",
"fahrtNr": 42325,
"name": "S 42 (42325)",
"public": true,
"productName": "S",
"mode": "train",
"product": "suburban",
"operator": null
when: '2024-12-08T01:10:00+01:00',
plannedWhen: '2024-12-08T01:10:00+01:00',
delay: 0,
platform: '6',
plannedPlatform: '6',
direction: null,
provenance: 'Berlin Beusselstraße',
line: {
type: 'line',
id: 's-42-42325',
fahrtNr: 42325,
name: 'S 42 (42325)',
public: true,
productName: 'S',
mode: 'train',
product: 'suburban',
operator: null,
},
"remarks": [
remarks: [
{
"code": "FB",
"summary": "Fahrradmitnahme begrenzt möglich",
"text": "Fahrradmitnahme begrenzt möglich",
"type": "hint"
}
code: 'FB',
summary: 'Fahrradmitnahme begrenzt möglich',
text: 'Fahrradmitnahme begrenzt möglich',
type: 'hint',
},
],
"origin": {
"type": "stop",
"id": "8089118",
"name": "Berlin Beusselstraße",
"location": null
origin: {
type: 'stop',
id: '8089118',
name: 'Berlin Beusselstraße',
location: null,
},
"destination": null
destination: null,
},
{
"tripId": "20241208-f9d83ab7-d603-3344-87c0-a65ecf0f8524",
"stop": {
"type": "stop",
"id": "730985",
"name": "Jungfernheide Bahnhof (S+U), Berlin",
"location": null
tripId: '20241208-f9d83ab7-d603-3344-87c0-a65ecf0f8524',
stop: {
type: 'stop',
id: '730985',
name: 'Jungfernheide Bahnhof (S+U), Berlin',
location: null,
},
"when": "2024-12-08T01:10:00+01:00",
"plannedWhen": "2024-12-08T01:10:00+01:00",
"delay": 0,
"platform": null,
"plannedPlatform": null,
"direction": null,
"provenance": "Rathaus Spandau (S+U), Berlin",
"line": {
"type": "line",
"id": "u-7-15752",
"fahrtNr": 15752,
"name": "U 7 (15752)",
"public": true,
"productName": "U",
"mode": "train",
"product": "subway",
"operator": null
when: '2024-12-08T01:10:00+01:00',
plannedWhen: '2024-12-08T01:10:00+01:00',
delay: 0,
platform: null,
plannedPlatform: null,
direction: null,
provenance: 'Rathaus Spandau (S+U), Berlin',
line: {
type: 'line',
id: 'u-7-15752',
fahrtNr: 15752,
name: 'U 7 (15752)',
public: true,
productName: 'U',
mode: 'train',
product: 'subway',
operator: null,
},
"remarks": [
remarks: [
{
"code": "FB",
"summary": "Fahrradmitnahme begrenzt möglich",
"text": "Fahrradmitnahme begrenzt möglich",
"type": "hint"
code: 'FB',
summary: 'Fahrradmitnahme begrenzt möglich',
text: 'Fahrradmitnahme begrenzt möglich',
type: 'hint',
},
{
"code": "RG",
"summary": "Behindertengerechtes Fahrzeug",
"text": "Behindertengerechtes Fahrzeug",
"type": "hint"
}
code: 'RG',
summary: 'Behindertengerechtes Fahrzeug',
text: 'Behindertengerechtes Fahrzeug',
type: 'hint',
},
],
"origin": {
"type": "stop",
"id": "731176",
"name": "Rathaus Spandau (S+U), Berlin",
"location": null
origin: {
type: 'stop',
id: '731176',
name: 'Rathaus Spandau (S+U), Berlin',
location: null,
},
destination: null,
},
"destination": null
}
];
export {

View file

@ -30,133 +30,133 @@ const dbJourney = {
departure: '2025-04-11T05:11:00+02:00',
plannedDeparture: '2025-04-11T05:11:00+02:00',
departureDelay: null,
direction: "Hennef(Sieg)",
arrivalPlatform: "9",
plannedArrivalPlatform: "9",
departurePlatform: "10 A-B",
plannedDeparturePlatform: "10 A-B",
tripId: "2|#VN#1#ST#1733173731#PI#1#ZI#161473#TA#1#DA#110425#1S#8000208#1T#504#LS#8002753#LT#545#PU#81#RT#1#CA#s#ZE#12#ZB#S 12#PC#4#FR#8000208#FT#504#TO#8002753#TT#545#",
direction: 'Hennef(Sieg)',
arrivalPlatform: '9',
plannedArrivalPlatform: '9',
departurePlatform: '10 A-B',
plannedDeparturePlatform: '10 A-B',
tripId: '2|#VN#1#ST#1733173731#PI#1#ZI#161473#TA#1#DA#110425#1S#8000208#1T#504#LS#8002753#LT#545#PU#81#RT#1#CA#s#ZE#12#ZB#S 12#PC#4#FR#8000208#FT#504#TO#8002753#TT#545#',
line: {
type: "line",
id: "s-12",
fahrtNr: "12",
name: "S 12",
type: 'line',
id: 's-12',
fahrtNr: '12',
name: 'S 12',
public: true,
productName: "S",
mode: "train",
product: "suburban",
productName: 'S',
mode: 'train',
product: 'suburban',
operator: {
"type": "operator",
"id": "db-regio-ag-nrw",
"name": "DB Regio AG NRW",
type: 'operator',
id: 'db-regio-ag-nrw',
name: 'DB Regio AG NRW',
},
},
remarks: [
{
"text": "Fahrradmitnahme begrenzt möglich",
"type": "hint",
"code": "bicycle-conveyance",
"summary": "bicycles conveyed",
text: 'Fahrradmitnahme begrenzt möglich',
type: 'hint',
code: 'bicycle-conveyance',
summary: 'bicycles conveyed',
},
{
"text": "nur 2. Klasse",
"type": "hint",
"code": "2nd-class-only",
"summary": "2. class only",
text: 'nur 2. Klasse',
type: 'hint',
code: '2nd-class-only',
summary: '2. class only',
},
{
"text": "Fahrzeuggebundene Einstiegshilfe vorhanden",
"type": "hint",
"code": "boarding-ramp",
"summary": "vehicle-mounted boarding ramp available",
}
text: 'Fahrzeuggebundene Einstiegshilfe vorhanden',
type: 'hint',
code: 'boarding-ramp',
summary: 'vehicle-mounted boarding ramp available',
},
],
"polyline": {
"type": "FeatureCollection",
"features": [
polyline: {
type: 'FeatureCollection',
features: [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
type: 'Feature',
properties: {},
geometry: {
type: 'Point',
coordinates: [
6.9597,
50.943038,
],
},
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
type: 'Feature',
properties: {},
geometry: {
type: 'Point',
coordinates: [
6.9597,
50.943038,
],
},
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
type: 'Feature',
properties: {},
geometry: {
type: 'Point',
coordinates: [
6.960033,
50.942724,
],
},
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
type: 'Feature',
properties: {},
geometry: {
type: 'Point',
coordinates: [
6.960491,
50.942301,
],
},
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
type: 'Feature',
properties: {},
geometry: {
type: 'Point',
coordinates: [
6.961282,
50.941825,
],
},
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
type: 'Feature',
properties: {},
geometry: {
type: 'Point',
coordinates: [
6.962253,
50.941582,
],
},
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
type: 'Feature',
properties: {},
geometry: {
type: 'Point',
coordinates: [
6.971467,
50.941492,
],
},
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
type: 'Feature',
properties: {},
geometry: {
type: 'Point',
coordinates: [
6.974658,
50.941285,
],
@ -198,7 +198,7 @@ const dbJourney = {
id: '8073368',
latitude: 50.941717,
longitude: 6.974065,
}
},
},
destination: {
type: 'stop',
@ -240,10 +240,10 @@ const dbJourney = {
plannedDeparturePlatform: '11',
remarks: [
{
"text": "Bordrestaurant",
"type": "hint",
"code": "on-board-restaurant",
"summary": "Bordrestaurant available",
text: 'Bordrestaurant',
type: 'hint',
code: 'on-board-restaurant',
summary: 'Bordrestaurant available',
},
{
text: 'Komfort Check-in verfügbar - wenn möglich bitte einchecken',
@ -252,26 +252,26 @@ const dbJourney = {
summary: 'Komfort-Checkin available',
},
],
"polyline": {
"type": "FeatureCollection",
"features": [
polyline: {
type: 'FeatureCollection',
features: [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
type: 'Feature',
properties: {},
geometry: {
type: 'Point',
coordinates: [
11.082144,
49.445678,
],
},
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
type: 'Feature',
properties: {},
geometry: {
type: 'Point',
coordinates: [
11.08227,
49.445435,
],
@ -283,7 +283,7 @@ const dbJourney = {
],
refreshToken: '¶HKI¶T$A=1@O=Köln Hbf@X=6958730@Y=50943029@L=8000207@a=128@$A=1@O=Köln Messe/Deutz@X=6975000@Y=50940872@L=8003368@a=128@$202504110511$202504110512$S 12$$1$$$$$$§W$A=1@O=Köln Messe/Deutz@X=6975000@Y=50940872@L=8003368@a=128@$A=1@O=Köln Messe/Deutz Gl.11-12@X=6974065@Y=50941717@L=8073368@a=128@$202504110512$202504110519$$$1$$$$$$§T$A=1@O=Köln Messe/Deutz Gl.11-12@X=6974065@Y=50941717@L=8073368@a=128@$A=1@O=Nürnberg Hbf@X=11082989@Y=49445615@L=8000284@a=128@$202504110520$202504110858$ICE 523$$1$$$$$$¶KC¶#VE#2#CF#100#CA#0#CM#0#SICT#0#AM#81#AM2#0#RT#7#¶KCC¶I1ZFIzEjRVJHIzMjSElOIzAjRUNLIzcwNTkxMXw3MDU5MTF8NzA2MTM4fDcwNjEzOHwwfDB8NDg1fDcwNTg5N3wxfDB8MTh8MHwwfC0yMTQ3NDgzNjQ4I0dBTSMxMTA0MjUwNTExIwpaI1ZOIzEjU1QjMTczMzE3MzczMSNQSSMxI1pJIzE2MTQ3MyNUQSMxI0RBIzExMDQyNSMxUyM4MDAwMjA4IzFUIzUwNCNMUyM4MDAyNzUzI0xUIzU0NSNQVSM4MSNSVCMxI0NBI3MjWkUjMTIjWkIjUyAgICAgMTIjUEMjNCNGUiM4MDAwMjA3I0ZUIzUxMSNUTyM4MDAzMzY4I1RUIzUxMiMKRiNWTiMwI1NUIzE3MzMxNzM3MzEjUEkjMSNQVSM4MSNaSSMyMjgzODI4ODkzI0RBIzExMDQyNSNGUiM4MDAzMzY4I1RPIzgwNzMzNjgjRlQjNTEyI1RUIzUxOSNUUyMwI0ZGIyNGViMwIwpaI1ZOIzEjU1QjMTczMzE3MzczMSNQSSMxI1pJIzE1NTA2MyNUQSMwI0RBIzExMDQyNSMxUyM4MDAwMDgwIzFUIzM1OCNMUyM4MDAwMjYxI0xUIzEwMDYjUFUjODEjUlQjMSNDQSNJQ0UjWkUjNTIzI1pCI0lDRSAgNTIzI1BDIzAjRlIjODA3MzM2OCNGVCM1MjAjVE8jODAwMDI4NCNUVCM4NTgj¶KRCC¶#VE#1#¶SC¶1_H4sIAAAAAAACA32P306DMBjFX8X0GpevhUIhIUFGFv8sGzHOaIwXbHQTU2CWskgIz+GbeOXdXswCemE09qLpOT09v68tOnCJPIQnDkMG4q9Kiyic3EYTV2vJX5DXoqLOZ8ijRn8IkQcGKmsVJYrrMAFCwcIYDeZNlvcmUNBLW9uh4RQb6LloZkLJOfIeWqSafR+Lr5eRDuVl2quLxVSLQyLqXmEgJuoeh5mmT7uxWJNTvp+Xm7FGZKlOnvk4WPpXx3dRnJyvt8Gdb7uUOSYE9z4F1zKBuMHKZxDM9QZAwAlC/WbvY8c0scNsmwSZvzq+ATDA1KIs0INUavzgbJgikfJP7OL4IYs1l7svNMbAiMtczbZcy6I2pj/YzPqHTQh2zd/sHVdxKRqRFdpTsuaDdVnWsuBNWNZFWiFvm4hqvIiTqhJZpb6zfFPGiUxyHWq7rvsE0LytQvMBAAA=',
price: {amount: 31.49, currency: 'EUR', hint: null},
remarks: []
remarks: [],
};
export {

View file

@ -36,29 +36,29 @@ const opt = {
const berlinWienQuery0 = Object.freeze(
{
"abfahrtsHalt": "A=1@L=8098160@",
"anfrageZeitpunkt": "2024-12-07T23:50:12",
"ankunftsHalt": "A=1@L=8000284@",
"ankunftSuche": "ABFAHRT",
"klasse": "KLASSE_2",
"produktgattungen": [
"ICE",
"EC_IC",
"IR",
"REGIONAL",
"SBAHN",
"BUS",
"SCHIFF",
"UBAHN",
"TRAM",
"ANRUFPFLICHTIG"
abfahrtsHalt: 'A=1@L=8098160@',
anfrageZeitpunkt: '2024-12-07T23:50:12',
ankunftsHalt: 'A=1@L=8000284@',
ankunftSuche: 'ABFAHRT',
klasse: 'KLASSE_2',
produktgattungen: [
'ICE',
'EC_IC',
'IR',
'REGIONAL',
'SBAHN',
'BUS',
'SCHIFF',
'UBAHN',
'TRAM',
'ANRUFPFLICHTIG',
],
"schnelleVerbindungen": true,
"sitzplatzOnly": false,
"bikeCarriage": false,
"reservierungsKontingenteVorhanden": false,
"nurDeutschlandTicketVerbindungen": false,
"deutschlandTicketVorhanden": false
schnelleVerbindungen: true,
sitzplatzOnly: false,
bikeCarriage: false,
reservierungsKontingenteVorhanden: false,
nurDeutschlandTicketVerbindungen: false,
deutschlandTicketVorhanden: false,
});
tap.test('formats a journeys() request correctly (DB)', (t) => {
@ -75,17 +75,17 @@ tap.test('formats a journeys() request correctly (DB)', (t) => {
...berlinWienQuery0,
reisende: [
{
"typ": "ERWACHSENER",
"ermaessigungen": [
typ: 'ERWACHSENER',
ermaessigungen: [
{
"art": "KEINE_ERMAESSIGUNG",
"klasse": "KLASSENLOS"
}
art: 'KEINE_ERMAESSIGUNG',
klasse: 'KLASSENLOS',
},
],
alter: [],
anzahl: 1,
},
],
"alter": [],
"anzahl": 1
}
]
});
t.end();
});
@ -102,17 +102,17 @@ tap.test('formats a journeys() request with BC correctly (DB)', (t) => {
...berlinWienQuery0,
reisende: [
{
"typ": "JUGENDLICHER",
"ermaessigungen": [
typ: 'JUGENDLICHER',
ermaessigungen: [
{
"art": "BAHNCARD25",
"klasse": "KLASSE_2"
}
art: 'BAHNCARD25',
klasse: 'KLASSE_2',
},
],
alter: ['24'],
anzahl: 1,
},
],
"alter": ["24"],
"anzahl": 1
}
]
});
t.end();
});

View file

@ -18,7 +18,7 @@ import {
} from '../../lib/errors.js';
import {formatTripReq} from '../../format/trip-req.js';
const resNoMatch = {"verbindungen":[],"verbindungReference":{},"fehlerNachricht":{"code":"MDA-AK-MSG-1001","ueberschrift":"Datum liegt außerhalb der Fahrplanperiode.","text":"Das Datum liegt außerhalb der Fahrplanperiode."}};
const resNoMatch = {verbindungen: [], verbindungReference: {}, fehlerNachricht: {code: 'MDA-AK-MSG-1001', ueberschrift: 'Datum liegt außerhalb der Fahrplanperiode.', text: 'Das Datum liegt außerhalb der Fahrplanperiode.'}};
const USER_AGENT = 'public-transport/hafas-client:test';

View file

@ -22,7 +22,7 @@ const profile = {
default: true,
},
],
parseOperator: _ => null
parseOperator: _ => null,
};
const ctx = {
data: {},
@ -32,28 +32,28 @@ const ctx = {
tap.test('parses ICE leg correctly', (t) => {
const input = {
"journeyId": "foo",
"verkehrsmittel": {
"produktGattung": "ICE",
"kategorie": "ICE",
"name": "ICE 229",
"nummer": "229",
"richtung": "Wien Hbf",
"typ": "PUBLICTRANSPORT",
"zugattribute": [{
"kategorie": "BEFÖRDERER",
"key": "BEF",
"value": "DB Fernverkehr AG, Österreichische Bundesbahnen"
journeyId: 'foo',
verkehrsmittel: {
produktGattung: 'ICE',
kategorie: 'ICE',
name: 'ICE 229',
nummer: '229',
richtung: 'Wien Hbf',
typ: 'PUBLICTRANSPORT',
zugattribute: [{
kategorie: 'BEFÖRDERER',
key: 'BEF',
value: 'DB Fernverkehr AG, Österreichische Bundesbahnen',
}, {
"kategorie": "FAHRRADMITNAHME",
"key": "FR",
"value": "Bicycles conveyed - subject to reservation",
"teilstreckenHinweis": "(Mainz Hbf - Wien Meidling)"
kategorie: 'FAHRRADMITNAHME',
key: 'FR',
value: 'Bicycles conveyed - subject to reservation',
teilstreckenHinweis: '(Mainz Hbf - Wien Meidling)',
}],
"kurzText": "ICE",
"mittelText": "ICE 229",
"langText": "ICE 229"
}
kurzText: 'ICE',
mittelText: 'ICE 229',
langText: 'ICE 229',
},
};
const expected = {
type: 'line',
@ -73,18 +73,18 @@ tap.test('parses ICE leg correctly', (t) => {
tap.test('parses Bus trip correctly', (t) => {
const input = {
"reisetag": "2024-12-07",
"regulaereVerkehrstage": "not every day",
"irregulaereVerkehrstage": "7., 14. Dec 2024",
"zugName": "Bus 807",
"zugattribute": [
reisetag: '2024-12-07',
regulaereVerkehrstage: 'not every day',
irregulaereVerkehrstage: '7., 14. Dec 2024',
zugName: 'Bus 807',
zugattribute: [
{
"kategorie": "INFORMATION",
"key": "cB",
"value": "Tel. 0981-9714925, Anmeldung bis 90 Min. vor Abfahrt (Mo-So: 9-15 Uhr)"
}
kategorie: 'INFORMATION',
key: 'cB',
value: 'Tel. 0981-9714925, Anmeldung bis 90 Min. vor Abfahrt (Mo-So: 9-15 Uhr)',
},
],
"cancelled": false,
cancelled: false,
};
const expected = {
type: 'line',
@ -95,7 +95,7 @@ tap.test('parses Bus trip correctly', (t) => {
product: undefined,
productName: undefined,
mode: undefined,
operator: null
operator: null,
};
t.same(parse(ctx, input), expected);
@ -103,29 +103,28 @@ tap.test('parses Bus trip correctly', (t) => {
});
tap.test('parses Bus leg correctly', (t) => {
const input = {
"journeyId": "foo",
"verkehrsmittel": {
"produktGattung": "BUS",
"kategorie": "Bus",
"linienNummer": "807",
"name": "Bus 807",
"nummer": "807",
"richtung": "Bahnhof, Dombühl",
"typ": "PUBLICTRANSPORT",
"zugattribute": [
journeyId: 'foo',
verkehrsmittel: {
produktGattung: 'BUS',
kategorie: 'Bus',
linienNummer: '807',
name: 'Bus 807',
nummer: '807',
richtung: 'Bahnhof, Dombühl',
typ: 'PUBLICTRANSPORT',
zugattribute: [
{
"kategorie": "INFORMATION",
"key": "cB",
"value": "Tel. 0981-9714925, Anmeldung bis 90 Min. vor Abfahrt (Mo-So: 9-15 Uhr)"
}
kategorie: 'INFORMATION',
key: 'cB',
value: 'Tel. 0981-9714925, Anmeldung bis 90 Min. vor Abfahrt (Mo-So: 9-15 Uhr)',
},
],
"kurzText": "Bus",
"mittelText": "Bus 807",
"langText": "Bus 807"
}
kurzText: 'Bus',
mittelText: 'Bus 807',
langText: 'Bus 807',
},
};
const expected = {
type: 'line',
@ -136,7 +135,7 @@ tap.test('parses Bus leg correctly', (t) => {
product: 'bus',
productName: 'Bus',
mode: 'bus',
operator: null
operator: null,
};
t.same(parse(ctx, input), expected);
@ -144,20 +143,19 @@ tap.test('parses Bus leg correctly', (t) => {
});
tap.test('parses ris entry correctly', (t) => {
const input = {
"journeyID": "20241207-79693bf3-2ed5-325f-8a99-154bad5f5cf3",
"transport": {
"type": "HIGH_SPEED_TRAIN",
"journeyDescription": "RB 51 (15538)",
"label": "",
"category": "RB",
"categoryInternal": "RB",
"number": 15538,
"line": "51",
"replacementTransport": null,
}
journeyID: '20241207-79693bf3-2ed5-325f-8a99-154bad5f5cf3',
transport: {
type: 'HIGH_SPEED_TRAIN',
journeyDescription: 'RB 51 (15538)',
label: '',
category: 'RB',
categoryInternal: 'RB',
number: 15538,
line: '51',
replacementTransport: null,
},
};
const expected = {
type: 'line',
@ -168,7 +166,7 @@ tap.test('parses ris entry correctly', (t) => {
product: 'nationalExpress',
productName: 'RB',
mode: 'train',
operator: null
operator: null,
};
t.same(parse(ctx, input), expected);

View file

@ -1,7 +1,6 @@
import tap from 'tap';
import omit from 'lodash/omit.js';
import {parseLocation as parse} from '../../parse/location.js';
import {parseBitmask as parseProductsBitmask} from '../../parse/products-bitmask.js'
import {parseBitmask as parseProductsBitmask} from '../../parse/products-bitmask.js';
const profile = {
parseLocation: parse,
@ -26,7 +25,7 @@ const profile = {
{
id: 'taxi',
vendo: 'ANRUFPFLICHTIG',
}]
}],
};
const ctx = {
@ -41,12 +40,12 @@ const ctx = {
tap.test('parses an address correctly', (t) => {
const input = {
"id": "A=2@O=Würzburg - Heuchelhof, Pergamonweg@X=9952209@Y=49736794@U=92@b=981423354@B=1@p=1706613073@",
"lat": 49.736794,
"lon": 9.952209,
"name": "Würzburg - Heuchelhof, Pergamonweg",
"products": [],
"type": "ADR"
id: 'A=2@O=Würzburg - Heuchelhof, Pergamonweg@X=9952209@Y=49736794@U=92@b=981423354@B=1@p=1706613073@',
lat: 49.736794,
lon: 9.952209,
name: 'Würzburg - Heuchelhof, Pergamonweg',
products: [],
type: 'ADR',
};
const address = parse(ctx, input);
@ -63,12 +62,12 @@ tap.test('parses an address correctly', (t) => {
tap.test('parses a POI correctly', (t) => {
const input = {
"id": "A=4@O=Berlin, Pergamonkeller (Gastronomie)@X=13395473@Y=52520223@U=91@L=991526508@B=1@p=1732715706@",
"lat": 52.52022,
"lon": 13.395473,
"name": "Berlin, Pergamonkeller (Gastronomie)",
"products": [],
"type": "POI"
id: 'A=4@O=Berlin, Pergamonkeller (Gastronomie)@X=13395473@Y=52520223@U=91@L=991526508@B=1@p=1732715706@',
lat: 52.52022,
lon: 13.395473,
name: 'Berlin, Pergamonkeller (Gastronomie)',
products: [],
type: 'POI',
};
const poi = parse(ctx, input);
@ -85,17 +84,17 @@ tap.test('parses a POI correctly', (t) => {
tap.test('parses a stop correctly', (t) => {
const input = {
"extId": "8012622",
"id": "A=1@O=Perleberg@X=11852322@Y=53071252@U=81@L=8012622@B=1@p=1733173731@i=U×008027183@",
"lat": 53.07068,
"lon": 11.85039,
"name": "Perleberg",
"products": [
"REGIONAL",
"BUS",
"ANRUFPFLICHTIG"
extId: '8012622',
id: 'A=1@O=Perleberg@X=11852322@Y=53071252@U=81@L=8012622@B=1@p=1733173731@i=U×008027183@',
lat: 53.07068,
lon: 11.85039,
name: 'Perleberg',
products: [
'REGIONAL',
'BUS',
'ANRUFPFLICHTIG',
],
"type": "ST"
type: 'ST',
};
const stop = parse(ctx, input);
@ -110,25 +109,25 @@ tap.test('parses a stop correctly', (t) => {
longitude: 11.85039,
},
products: {
"nationalExpress": false,
"national": false,
"regional": true,
"bus": true,
"taxi": true
}
nationalExpress: false,
national: false,
regional: true,
bus: true,
taxi: true,
},
});
t.end();
});
tap.test('falls back to coordinates from `lid', (t) => {
const input = {
"id": "A=1@O=Bahnhof, Rothenburg ob der Tauber@X=10190711@Y=49377180@U=80@L=683407@",
"name": "Bahnhof, Rothenburg ob der Tauber",
"bahnhofsInfoId": "5393",
"extId": "683407",
"adminID": "vgn063",
"kategorie": "Bus",
"nummer": "2524"
id: 'A=1@O=Bahnhof, Rothenburg ob der Tauber@X=10190711@Y=49377180@U=80@L=683407@',
name: 'Bahnhof, Rothenburg ob der Tauber',
bahnhofsInfoId: '5393',
extId: '683407',
adminID: 'vgn063',
kategorie: 'Bus',
nummer: '2524',
};
const stop = parse(ctx, input);
@ -141,7 +140,7 @@ tap.test('falls back to coordinates from `lid', (t) => {
id: '683407',
latitude: 49.377180,
longitude: 10.190711,
}
},
});
t.end();
});

View file

@ -9,13 +9,13 @@ const ctx = {
tap.test('parses an operator correctly', (t) => {
const op = [{
"kategorie": "BEFÖRDERER",
"key": "BEF",
"value": "DB Fernverkehr AG"
kategorie: 'BEFÖRDERER',
key: 'BEF',
value: 'DB Fernverkehr AG',
}, {
"kategorie": "FAHRRADMITNAHME",
"key": "FR",
"value": "Bicycles conveyed - subject to reservation"
kategorie: 'FAHRRADMITNAHME',
key: 'FR',
value: 'Bicycles conveyed - subject to reservation',
}];
t.same(parse(ctx, op), {
@ -29,9 +29,9 @@ tap.test('parses an operator correctly', (t) => {
tap.test('parses nothing', (t) => {
const op = [{
"kategorie": "INFORMATION",
"key": "cB",
"value": "Tel. 0981-9714925, Anmeldung bis 90 Min. vor Abfahrt (Mo-So: 9-15 Uhr)"
kategorie: 'INFORMATION',
key: 'cB',
value: 'Tel. 0981-9714925, Anmeldung bis 90 Min. vor Abfahrt (Mo-So: 9-15 Uhr)',
}];
t.same(parse(ctx, op), null);

View file

@ -16,16 +16,16 @@ const ctx = {
tap.test('parses meldungenAsObject correctly', (t) => {
const input = {meldungenAsObject: [{
"code": "MDA-AK-MSG-1000",
"nachrichtKurz": "Connection is in the past.",
"nachrichtLang": "Selected connection is in the past.",
"fahrtRichtungKennzeichen": "HINFAHRT"
code: 'MDA-AK-MSG-1000',
nachrichtKurz: 'Connection is in the past.',
nachrichtLang: 'Selected connection is in the past.',
fahrtRichtungKennzeichen: 'HINFAHRT',
}]};
const expected = [{
"code": "MDA-AK-MSG-1000",
"summary": "Connection is in the past.",
"text": "Selected connection is in the past.",
"type": "hint"
code: 'MDA-AK-MSG-1000',
summary: 'Connection is in the past.',
text: 'Selected connection is in the past.',
type: 'hint',
}];
t.same(parse(ctx, input), expected);
@ -33,12 +33,12 @@ tap.test('parses meldungenAsObject correctly', (t) => {
});
tap.test('parses risNotizen correctly', (t) => {
const input = {risNotizen: [{key: "FT", value: "Staff delayed due to earlier journey", routeIdxFrom: 0, routeIdxTo: 12}]};
const input = {risNotizen: [{key: 'FT', value: 'Staff delayed due to earlier journey', routeIdxFrom: 0, routeIdxTo: 12}]};
const expected = [{
"code": "FT",
"summary": "Staff delayed due to earlier journey",
"text": "Staff delayed due to earlier journey",
"type": "warning"
code: 'FT',
summary: 'Staff delayed due to earlier journey',
text: 'Staff delayed due to earlier journey',
type: 'warning',
}];
t.same(parse(ctx, input), expected);
@ -47,17 +47,17 @@ tap.test('parses risNotizen correctly', (t) => {
tap.test('parses low Prio him himMeldungen correctly', (t) => {
const input = {himMeldungen: [{
"ueberschrift": "Construction work.",
"text": "Advance notice! In the period from 15.12.24 to 17.01.25, construction work will take place",
"prioritaet": "NIEDRIG",
"modDateTime": "2024-12-03T12:52:29"
ueberschrift: 'Construction work.',
text: 'Advance notice! In the period from 15.12.24 to 17.01.25, construction work will take place',
prioritaet: 'NIEDRIG',
modDateTime: '2024-12-03T12:52:29',
}]};
const expected = [{
"code": undefined,
"summary": "Construction work.",
"text": "Advance notice! In the period from 15.12.24 to 17.01.25, construction work will take place",
"type": "status",
"modified": "2024-12-03T12:52:29+01:00"
code: undefined,
summary: 'Construction work.',
text: 'Advance notice! In the period from 15.12.24 to 17.01.25, construction work will take place',
type: 'status',
modified: '2024-12-03T12:52:29+01:00',
}];
t.same(parse(ctx, input), expected);
@ -66,17 +66,17 @@ tap.test('parses low Prio him himMeldungen correctly', (t) => {
tap.test('parses high Prio him himMeldungen correctly', (t) => {
const input = {himMeldungen: [{
"ueberschrift": "Disruption.",
"text": "Switch repairs between Frankfurt(Main)Hbf and Mannheim Hbf delays rail transport.",
"prioritaet": "HOCH",
"modDateTime": "2024-12-05T19:01:48"
ueberschrift: 'Disruption.',
text: 'Switch repairs between Frankfurt(Main)Hbf and Mannheim Hbf delays rail transport.',
prioritaet: 'HOCH',
modDateTime: '2024-12-05T19:01:48',
}]};
const expected = [{
"code": undefined,
"summary": "Disruption.",
"text": "Switch repairs between Frankfurt(Main)Hbf and Mannheim Hbf delays rail transport.",
"type": "warning",
"modified": "2024-12-05T19:01:48+01:00"
code: undefined,
summary: 'Disruption.',
text: 'Switch repairs between Frankfurt(Main)Hbf and Mannheim Hbf delays rail transport.',
type: 'warning',
modified: '2024-12-05T19:01:48+01:00',
}];
t.same(parse(ctx, input), expected);
@ -85,34 +85,34 @@ tap.test('parses high Prio him himMeldungen correctly', (t) => {
tap.test('parses zugattribute correctly', (t) => {
const input = {verkehrsmittel: {zugattribute: [{
"kategorie": "BEFÖRDERER",
"key": "BEF",
"value": "DB Fernverkehr AG"
kategorie: 'BEFÖRDERER',
key: 'BEF',
value: 'DB Fernverkehr AG',
}, {
"kategorie": "FAHRRADMITNAHME",
"key": "FR",
"value": "Bicycles conveyed - subject to reservation",
"teilstreckenHinweis": "(Mainz Hbf - Mannheim Hbf)"
kategorie: 'FAHRRADMITNAHME',
key: 'FR',
value: 'Bicycles conveyed - subject to reservation',
teilstreckenHinweis: '(Mainz Hbf - Mannheim Hbf)',
}, {
"kategorie": "INFORMATION",
"key": "CK",
"value": "Komfort Check-in possible (visit bahn.de/kci for more information)",
"teilstreckenHinweis": "(Mainz Hbf - Mannheim Hbf)"
kategorie: 'INFORMATION',
key: 'CK',
value: 'Komfort Check-in possible (visit bahn.de/kci for more information)',
teilstreckenHinweis: '(Mainz Hbf - Mannheim Hbf)',
}]}};
const expected = [{
// "code": "bicycle-conveyance-reservation",
"code": "FR",
code: 'FR',
// "summary": "bicycles conveyed, subject to reservation",
"summary": "Bicycles conveyed - subject to reservation",
"text": "Bicycles conveyed - subject to reservation",
"type": "hint",
summary: 'Bicycles conveyed - subject to reservation',
text: 'Bicycles conveyed - subject to reservation',
type: 'hint',
}, {
// "code": "komfort-checkin",
"code": "CK",
code: 'CK',
// "summary": "Komfort-Checkin available",
"summary": "Komfort Check-in possible (visit bahn.de/kci for more information)",
"text": "Komfort Check-in possible (visit bahn.de/kci for more information)",
"type": "hint",
summary: 'Komfort Check-in possible (visit bahn.de/kci for more information)',
text: 'Komfort Check-in possible (visit bahn.de/kci for more information)',
type: 'hint',
}];
t.same(parse(ctx, input), expected);
@ -123,22 +123,22 @@ tap.test('parses zugattribute correctly', (t) => {
tap.test('parses board disruptions correctly', (t) => {
const input = {disruptions: [
{
"disruptionID": "9aee61d6-700e-3c19-aaa0-019f5612df4c",
"disruptionCommunicationID": null,
"displayPriority": 25,
"descriptions": {
"DE": {
"text": "Eine Reparatur an einem Signal verzögert den Zugverkehr",
"textShort": "Verzögerungen durch Reparatur an einem Signal"
}
}
}
disruptionID: '9aee61d6-700e-3c19-aaa0-019f5612df4c',
disruptionCommunicationID: null,
displayPriority: 25,
descriptions: {
DE: {
text: 'Eine Reparatur an einem Signal verzögert den Zugverkehr',
textShort: 'Verzögerungen durch Reparatur an einem Signal',
},
},
},
]};
const expected = [{
"code": undefined,
"summary": "Verzögerungen durch Reparatur an einem Signal",
"text": "Eine Reparatur an einem Signal verzögert den Zugverkehr",
"type": "warning",
code: undefined,
summary: 'Verzögerungen durch Reparatur an einem Signal',
text: 'Eine Reparatur an einem Signal verzögert den Zugverkehr',
type: 'warning',
}];
t.same(parse(ctx, input), expected);
@ -149,19 +149,19 @@ tap.test('parses board disruptions correctly', (t) => {
tap.test('parses board messages correctly', (t) => {
const input = {messages: [
{
"code": "80",
"type": "QUALITY_VARIATION",
"displayPriority": null,
"category": null,
"text": "Andere Reihenfolge der Wagen",
"textShort": null
}
code: '80',
type: 'QUALITY_VARIATION',
displayPriority: null,
category: null,
text: 'Andere Reihenfolge der Wagen',
textShort: null,
},
]};
const expected = [{
"code": 80,
"summary": "Andere Reihenfolge der Wagen",
"text": "Andere Reihenfolge der Wagen",
"type": "status",
code: 80,
summary: 'Andere Reihenfolge der Wagen',
text: 'Andere Reihenfolge der Wagen',
type: 'status',
}];
t.same(parse(ctx, input), expected);
@ -171,20 +171,20 @@ tap.test('parses board messages correctly', (t) => {
tap.test('parses ris attributes correctly', (t) => {
const input = {attributes: [
{
"displayPriority": null,
"displayPriorityDetail": null,
"code": "CK",
"text": "Komfort Check-in verfügbar - wenn möglich bitte einchecken",
"textShort": null
}
displayPriority: null,
displayPriorityDetail: null,
code: 'CK',
text: 'Komfort Check-in verfügbar - wenn möglich bitte einchecken',
textShort: null,
},
]};
const expected = [{
// "code": "komfort-checkin",
"code": "CK",
code: 'CK',
// "summary": "Komfort-Checkin available",
"summary": "Komfort Check-in verfügbar - wenn möglich bitte einchecken",
"text": "Komfort Check-in verfügbar - wenn möglich bitte einchecken",
"type": "hint",
summary: 'Komfort Check-in verfügbar - wenn möglich bitte einchecken',
text: 'Komfort Check-in verfügbar - wenn möglich bitte einchecken',
type: 'hint',
}];
t.same(parse(ctx, input), expected);