diff --git a/format/refresh-journey-req.js b/format/refresh-journey-req.js new file mode 100644 index 00000000..5504b32b --- /dev/null +++ b/format/refresh-journey-req.js @@ -0,0 +1,18 @@ +'use strict' + +const formatRefreshJourneyReq = (ctx, refreshToken) => { + const {profile, opt} = ctx + + return { + meth: 'Reconstruction', + req: { + ctxRecon: refreshToken, + getIST: true, // todo: make an option + getPasslist: !!opt.stopovers, + getPolyline: !!opt.polylines, + getTariff: !!opt.tickets + } + } +} + +module.exports = formatRefreshJourneyReq diff --git a/index.js b/index.js index c54487fd..aaf9b9f3 100644 --- a/index.js +++ b/index.js @@ -249,16 +249,9 @@ const createClient = (profile, userAgent, opt = {}) => { remarks: true // parse & expose hints & warnings? }, opt) - return profile.request({profile, opt}, userAgent, { - meth: 'Reconstruction', - req: { - ctxRecon: refreshToken, - getIST: true, // todo: make an option - getPasslist: !!opt.stopovers, - getPolyline: !!opt.polylines, - getTariff: !!opt.tickets - } - }) + const req = profile.formatRefreshJourneyReq({profile, opt}, refreshToken) + + return profile.request({profile, opt}, userAgent, req) .then(({res, common}) => { if (!Array.isArray(res.outConL) || !res.outConL[0]) { throw new Error('invalid response') diff --git a/lib/default-profile.js b/lib/default-profile.js index a1cce89e..b50ee4c9 100644 --- a/lib/default-profile.js +++ b/lib/default-profile.js @@ -9,6 +9,7 @@ const formatNearbyReq = require('../format/nearby-req') const formatTripReq = require('../format/trip-req') const formatRadarReq = require('../format/radar-req') const formatReachableFromReq = require('../format/reachable-from-req') +const formatRefreshJourneyReq = require('../format/refresh-journey-req') const parseDateTime = require('../parse/date-time') const parsePlatform = require('../parse/platform') @@ -59,6 +60,7 @@ const defaultProfile = { formatTripReq, formatRadarReq, formatReachableFromReq, + formatRefreshJourneyReq, transformJourneysQuery: id, parseDateTime, diff --git a/lib/validate-profile.js b/lib/validate-profile.js index 248be58f..80b670ec 100644 --- a/lib/validate-profile.js +++ b/lib/validate-profile.js @@ -15,6 +15,7 @@ const types = { formatTripReq: 'function', formatRadarReq: 'function', formatReachableFromReq: 'function', + formatRefreshJourneyReq: 'function', transformJourneysQuery: 'function', products: 'array', diff --git a/p/vsn/index.js b/p/vsn/index.js index f029a707..b8526946 100644 --- a/p/vsn/index.js +++ b/p/vsn/index.js @@ -11,6 +11,21 @@ const transformReqBody = (ctx, body) => { return body } +const formatRefreshJourneyReq = (ctx, refreshToken) => { + const {profile, opt} = ctx + + return { + meth: 'Reconstruction', + req: { + outReconL: [{ctx: refreshToken}], + getIST: true, // todo: make an option + getPasslist: !!opt.stopovers, + getPolyline: !!opt.polylines, + getTariff: !!opt.tickets + } + } +} + const vsnProfile = { locale: 'de-DE', timezone: 'Europe/Berlin', @@ -22,6 +37,7 @@ const vsnProfile = { addMicMac: true, transformReqBody, + formatRefreshJourneyReq, products: products,