hk-bus-eta 1.4.0 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Gmb.js ADDED
@@ -0,0 +1,27 @@
1
+ const utils = require('./utils');
2
+
3
+ module.exports = {
4
+ co: 'gmb',
5
+ fetchEtas: ({gtfsId, stopId, bound,seq}) => (
6
+ fetch(`https://data.etagmb.gov.hk/eta/route-stop/${gtfsId}/${stopId}`, {
7
+ cache: utils.isSafari ? 'default' : 'no-store'
8
+ }).then( response => response.json() )
9
+ .then(({data}) => (
10
+ data
11
+ .filter(({route_seq}) => ( bound === 'O' && route_seq === 1 ) || ( bound === 'I' && route_seq === 2 ) )
12
+ .filter(({stop_seq}) => stop_seq === seq + 1)
13
+ .reduce( (acc, {eta}) => [
14
+ ...acc,
15
+ ...eta.map( data => ({
16
+ eta: data.timestamp,
17
+ remark: {
18
+ zh: data.remarks_tc,
19
+ en: data.remarks_en
20
+ },
21
+ co: 'gmb'
22
+ }))
23
+ ], [] )
24
+ ))
25
+ ),
26
+ fetchStopEtas: ( stopId ) => []
27
+ }
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type Company = "kmb" | "nlb" | "ctb" | "nwfb" | 'lrtfeeder'
1
+ export type Company = "kmb" | "nlb" | "ctb" | "nwfb" | 'lrtfeeder' | 'gmb'
2
2
 
3
3
  export type Terminal = {
4
4
  en: string,
@@ -30,6 +30,7 @@ export type RouteListEntry = {
30
30
  readonly bound: {
31
31
  [co in Company]: "O" | "I"
32
32
  },
33
+ readonly gtfsId: string,
33
34
  readonly nlbId: string
34
35
  }
35
36
 
package/index.js CHANGED
@@ -3,10 +3,11 @@ const NwfbApi = require('./Nwfb')
3
3
  const CtbApi = require('./Ctb')
4
4
  const NlbApi = require('./Nlb')
5
5
  const LrtfeederApi = require('./Lrtfeeder')
6
+ const GmbApi = require('./Gmb')
6
7
 
7
8
  module.exports = {
8
9
  // seq is 0-based here
9
- fetchEtas: async ( {route, stops, bound, seq, serviceType, co, nlbId, language }) => {
10
+ fetchEtas: async ( {route, stops, bound, seq, serviceType, co, nlbId, gtfsId, language }) => {
10
11
  let _etas = []
11
12
  for ( const company_id of co ) {
12
13
  if (company_id === 'kmb' && stops.kmb ){
@@ -24,6 +25,8 @@ module.exports = {
24
25
  _etas = _etas.concat( await NlbApi.fetchEtas({stopId: stops.nlb[seq], nlbId}) )
25
26
  } else if ( company_id === 'lrtfeeder' && stops.lrtfeeder ) {
26
27
  _etas = _etas.concat( await LrtfeederApi.fetchEtas({stopId: stops.lrtfeeder[seq], route, language}))
28
+ } else if ( company_id === 'gmb' && stops.gmb ) {
29
+ _etas = _etas.concat( await GmbApi.fetchEtas({stopId: stops.gmb[seq], gtfsId, seq, bound: bound[company_id]}) )
27
30
  }
28
31
  }
29
32
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hk-bus-eta",
3
- "version": "1.4.0",
3
+ "version": "1.5.2",
4
4
  "description": "Query the ETA (Estimated Time of Arrival) of HK Bus",
5
5
  "main": "index.js",
6
6
  "scripts": {