diff --git a/docs/server-info.md b/docs/server-info.md index 681f311e..86db86f5 100644 --- a/docs/server-info.md +++ b/docs/server-info.md @@ -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', diff --git a/index.js b/index.js index 0b0ff1ae..075a7bb4 100644 --- a/index.js +++ b/index.js @@ -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 diff --git a/test/e2e/fixtures/ec7d38b24537d986a55c1608474cda45 b/test/e2e/fixtures/ec7d38b24537d986a55c1608474cda45 new file mode 100644 index 00000000..9818eed8 --- /dev/null +++ b/test/e2e/fixtures/ec7d38b24537d986a55c1608474cda45 @@ -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"}}]} \ No newline at end of file diff --git a/test/e2e/fixtures/ec7d38b24537d986a55c1608474cda45.headers b/test/e2e/fixtures/ec7d38b24537d986a55c1608474cda45.headers new file mode 100644 index 00000000..dbb6c87f --- /dev/null +++ b/test/e2e/fixtures/ec7d38b24537d986a55c1608474cda45.headers @@ -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" + ] + } + } +} \ No newline at end of file diff --git a/test/e2e/lib/server-info.js b/test/e2e/lib/server-info.js index 13a8b01c..6edf42bb 100644 --- a/test/e2e/lib/server-info.js +++ b/test/e2e/lib/server-info.js @@ -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')