serverInfo: add opt.versionInfo 📝

Thanks to @alexander-albers!

see also https://github.com/alexander-albers/tripkit/issues/69#issuecomment-1048105228
This commit is contained in:
Jannis R 2022-02-22 20:23:54 +01:00
parent cbc7f63dcc
commit 2edcd49e99
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
5 changed files with 58 additions and 1 deletions

View file

@ -6,6 +6,7 @@ With `opt`, you can override the default options, which look like this:
```js
{
versionInfo: true, // query HAFAS versions?
language: 'en', // depends on the profile
}
```
@ -25,6 +26,9 @@ console.log(await client.serverInfo())
```js
{
// version of the HAFAS Connection Interface (HCI), the API that hafas-client uses
hciVersion: '1.23',
timetableStart: '20200517',
timetableEnd: '20201212',
serverTime: '2020-07-19T21:32:12+02:00',

View file

@ -731,13 +731,22 @@ const createClient = (profile, userAgent, opt = {}) => {
}
const serverInfo = async (opt = {}) => {
opt = {
versionInfo: true, // query HAFAS versions?
...opt
}
const {res, common} = await profile.request({profile, opt}, userAgent, {
meth: 'ServerInfo',
req: {}
req: {
getVersionInfo: opt.versionInfo,
},
})
const ctx = {profile, opt, common, res}
return {
// todo: what are .serverVersion & .clientVersion?
hciVersion: res.hciVersion || null,
timetableStart: res.fpB || null,
timetableEnd: res.fpE || null,
serverTime: res.sD && res.sT

View file

@ -0,0 +1 @@
{"ver":"1.34","ext":"DB.R20.12.b","lang":"eng","id":"ta2gikk4gaxhxkwg","err":"OK","cInfo":{"code":"OK","url":"","msg":""},"graph":{"id":"standard","index":0},"subGraph":{"id":"global","index":0},"view":{"id":"standard","index":0,"type":"WGS84"},"svcResL":[{"meth":"ServerInfo","err":"OK","res":{"fpB":"20211212","fpE":"20221210","sD":"20220222","sT":"202539","enc":"ISO-8859-1","planrtTS":"1645557831","serverVersion":"5.45.DB.R21.12.1.a (customer/hcudb/release/21.12.1.a.0) [Dec 17 2021]","clientVersion":"5.45.DB.R21.12.1.a (customer/hcudb/release/21.12.1.a.0) [Dec 17 2021]","hciVersion":"1.46"}}]}

View file

@ -0,0 +1,40 @@
{
"statusCode": 200,
"headers": {
"date": "Tue, 22 Feb 2022 19:25:40 GMT",
"content-type": "application/json; charset=utf-8",
"content-length": "345",
"connection": "keep-alive",
"set-cookie": [
"AWSALB=ofa5BiXycld9XQJtZ8QTD823tDszyjr2sYpdBYbJCeWk4P+8+TUzu7oywsmVX9wivfMEDtEJyBipYc+SA33F2pYyStBnxkBIWvzo5mOIS+tGZWBlyN3csusXBpFd; Expires=Tue, 01 Mar 2022 19:25:39 GMT; Path=/",
"AWSALBCORS=ofa5BiXycld9XQJtZ8QTD823tDszyjr2sYpdBYbJCeWk4P+8+TUzu7oywsmVX9wivfMEDtEJyBipYc+SA33F2pYyStBnxkBIWvzo5mOIS+tGZWBlyN3csusXBpFd; Expires=Tue, 01 Mar 2022 19:25:39 GMT; Path=/; SameSite=None; Secure"
],
"server": "Apache",
"strict-transport-security": "max-age=16070400; includeSubDomains"
},
"url": "https://reiseauskunft.bahn.de/bin/mgate.exe?checksum=ee1ddec720dddfcac82fb7f78649d72c",
"time": 304,
"request": {
"method": "POST",
"headers": {
"Content-Type": [
"application/json"
],
"Accept-Encoding": [
"gzip, br, deflate"
],
"Accept": [
"application/json"
],
"user-agent": [
"public-1dd0bdtranspor1dd0bdt/haf1dd0bdas-clien1dd0bdt:test"
],
"connection": [
"keep-alive"
],
"Content-Length": [
"252"
]
}
}
}

View file

@ -9,6 +9,9 @@ const testServerInfo = async (cfg) => {
const info = await fetchServerInfo()
t.ok(info, 'invalid info')
t.equal(typeof info.hciVersion, 'string', 'invalid info.hciVersion')
t.ok(info.hciVersion, 'invalid info.hciVersion')
t.equal(typeof info.timetableStart, 'string', 'invalid info.timetableStart')
t.ok(info.timetableStart, 'invalid info.timetableStart')
t.equal(typeof info.timetableEnd, 'string', 'invalid info.timetableEnd')