1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { createClient as createVendoClient } from 'db-vendo-client';
import { createClient as createHafasClient } from 'hafas-client';
import { profile as dbNavProfile } from 'db-vendo-client/p/dbnav/index.js';
import { profile as bvgProfile } from 'hafas-client/p/bvg/index.js';
import { profile as nahshProfile } from 'hafas-client/p/nahsh/index.js';
import { profile as rmvProfile } from 'hafas-client/p/rmv/index.js';
import { profile as oebbProfile } from 'hafas-client/p/oebb/index.js';
import { profile as rejseplanenProfile } from 'hafas-client/p/rejseplanen/index.js'
import { vendoRequest } from './vendoRequest.js';
import { hafasRequest } from './hafasRequest.js';
const clients = {};
const vendoEndpoints = {
locationsEndpoint: '/db/vendo/locations',
stopEndpoint: '/db/vendo/location',
journeysEndpoint: '/db/vendo/journeys',
refreshJourneysEndpointTickets: '/db/vendo/journey',
boardEndpoint: '/db/vendo/departures',
tripEndpoint: '/db/vendo/trip',
};
export let client;
export const profiles = {
db: { name: "DB", backend: 'vendo', profile: { ...dbNavProfile, ...vendoEndpoints }},
bvg: { name: "BVG", backend: 'hafas', profile: bvgProfile },
nahsh: { name: "NAH.SH", backend: 'hafas', profile: nahshProfile },
rmv: { name: "RMV", backend: 'hafas', profile: rmvProfile },
oebb: { name: "ÖBB", backend: 'hafas', profile: oebbProfile },
rejseplanen: { name: "Rejseplanen", backend: 'hafas', profile: rejseplanenProfile },
}
export const getDefaultProfile = () => 'db';
export const getHafasClient = async profileName => {
if (!profiles[profileName]) throw "Unknown profile name: " + profileName;
if (!clients[profileName]) {
if (profiles[profileName].backend === 'vendo') {
clients[profileName] = createVendoClient({ ...profiles[profileName].profile, request: vendoRequest }, APP_NAME, {enrichStations: false});
if (isDevServer) console.info('initialized vendo client with profile ' + profileName);
}
if (profiles[profileName].backend === 'hafas') {
clients[profileName] = createHafasClient({ ...profiles[profileName].profile, request: hafasRequest }, APP_NAME);
if (isDevServer) console.info('initialized hafas client with profile ' + profileName);
}
}
return clients[profileName];
}
export const initHafasClient = async profileName => {
client = await getHafasClient(profileName);
};