Skip to content

Commit 48d14d7

Browse files
committed
use commonjs module for now as the tooling support for ES6 modules is not mature yet
1 parent 374f892 commit 48d14d7

22 files changed

+311
-105
lines changed

.eslintrc

+4-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
"@typescript-eslint"
66
],
77
"parserOptions" : {
8-
"project" : ["./tsconfig.json"]
8+
"project" : ["./tsconfig.eslint.json"]
9+
},
10+
"env" : {
11+
"node" : true
912
},
1013
"extends" : [
1114
"eslint:recommended",
@@ -14,12 +17,6 @@
1417
"plugin:@typescript-eslint/recommended-requiring-type-checking"
1518
],
1619
"overrides" : [
17-
{
18-
"rules" : {
19-
"no-debugger" : "off"
20-
},
21-
"files" : "**"
22-
},
2320
{
2421
"files" : "*.js",
2522
"rules": {

.github/workflows/node.js.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ jobs:
1111
build:
1212
runs-on: ubuntu-latest
1313

14+
strategy:
15+
matrix:
16+
node-version: [ 10.x, 12.x, 14.x ]
17+
1418
steps:
1519
- uses: actions/checkout@v2
16-
- uses: actions/setup-node@v1
20+
- name: Use Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v1
1722
with:
18-
node-version: 14.x
23+
node-version: ${{ matrix.node-version }}
1924
- run: yarn
2025
- run: yarn prepack

.idea/inspectionProfiles/Project_Default.xml

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+36-19
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,56 @@ This is a library for getting KMB data. It can get routes, stops, variants, and
44
## Example Usage
55
### Loading the library
66
```js
7-
// load the main API class
8-
import Kmb from "js-kmb-api";
9-
// load the type definitions
10-
import {Language, Stop, Stop, Route, Variant, StopRoute, Eta} from "js-kmb-api"
11-
```
7+
// import the library class
8+
const Kmb = require('js-kmb-api').default;
129

13-
### Using the library
14-
```js
15-
// create an API instance
10+
// create an API instance using the default setting
11+
const kmb = new Kmb;
12+
13+
// create an API instance with caching in the browser
1614
// It's recommended to use localStorage to cache stops, and sessionStorage to cache stop routes
1715
// because stop names do not change often and are reloaded automatically
1816
const kmb = new Kmb('en', localStorage, sessionStorage);
17+
```
1918

20-
// create an API instance without caching
21-
const kmb_no_cache = new Kmb('zh-hans');
22-
23-
// Load the routes (directions) named '104'
24-
const routes = await kmb.getRoutes('104');
25-
26-
// Load the main variant of the forward direction
27-
const variants = await routes.filter(route => route.bound === 1).getVariants();
28-
const variant = await variants.sort((a, b) => a.serviceType - b.serviceType)[0];
19+
### Using the library
20+
Refer to the `example-javascript.js` or `example-typescript.ts` files for the following example in a runnable form.
21+
```js
22+
// Load the forward route of 104
23+
const route = (await kmb.getRoutes('104')).find(route => route.bound === 1);
24+
if (route === undefined) {
25+
throw new Error('route is not found');
26+
}
27+
28+
// load the main variant
29+
const variant = (await route.getVariants()).sort((a, b) => a.serviceType - b.serviceType)[0];
30+
if (variant === undefined) {
31+
throw new Error('No variants are found');
32+
}
2933

3034
// Load the stop list of the main variant
3135
const stoppings = await variant.getStoppings();
3236

3337
// Find a stop called "Immigration Tower"
3438
const stopping = stoppings.find(stopping => stopping.stop.name === 'Immigration Tower');
39+
if (stopping === undefined) {
40+
throw new Error('Stop is not found');
41+
}
3542

3643
// Get the ETA there
37-
const etas = await stopping.getEtas();
44+
const etas = await stopping.getEtas();
45+
console.log(etas);
3846

39-
````
47+
// Get the stoppings of all other routes for that stop
48+
const stoppings_at_immigration_tower = await stopping.stop.getStoppings();
49+
console.log(stoppings_at_immigration_tower);
50+
```
51+
52+
To run the example, use
53+
```shell script
54+
node example-javascript.js # Javascript example
55+
ts-node example-typescript.ts # Typescript example
56+
```
4057

4158
## Classes
4259
All the classes below are inside the kmb object tying them to the API instance

cert.pem

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
Certificate:
2+
Data:
3+
Version: 3 (0x2)
4+
Serial Number: 7 (0x7)
5+
Signature Algorithm: sha256WithRSAEncryption
6+
Issuer: C = US, ST = Arizona, L = Scottsdale, O = "GoDaddy.com, Inc.", CN = Go Daddy Root Certificate Authority - G2
7+
Validity
8+
Not Before: May 3 07:00:00 2011 GMT
9+
Not After : May 3 07:00:00 2031 GMT
10+
Subject: C = US, ST = Arizona, L = Scottsdale, O = "GoDaddy.com, Inc.", OU = http://certs.godaddy.com/repository/, CN = Go Daddy Secure Certificate Authority - G2
11+
Subject Public Key Info:
12+
Public Key Algorithm: rsaEncryption
13+
RSA Public-Key: (2048 bit)
14+
Modulus:
15+
00:b9:e0:cb:10:d4:af:76:bd:d4:93:62:eb:30:64:
16+
b8:81:08:6c:c3:04:d9:62:17:8e:2f:ff:3e:65:cf:
17+
8f:ce:62:e6:3c:52:1c:da:16:45:4b:55:ab:78:6b:
18+
63:83:62:90:ce:0f:69:6c:99:c8:1a:14:8b:4c:cc:
19+
45:33:ea:88:dc:9e:a3:af:2b:fe:80:61:9d:79:57:
20+
c4:cf:2e:f4:3f:30:3c:5d:47:fc:9a:16:bc:c3:37:
21+
96:41:51:8e:11:4b:54:f8:28:be:d0:8c:be:f0:30:
22+
38:1e:f3:b0:26:f8:66:47:63:6d:de:71:26:47:8f:
23+
38:47:53:d1:46:1d:b4:e3:dc:00:ea:45:ac:bd:bc:
24+
71:d9:aa:6f:00:db:db:cd:30:3a:79:4f:5f:4c:47:
25+
f8:1d:ef:5b:c2:c4:9d:60:3b:b1:b2:43:91:d8:a4:
26+
33:4e:ea:b3:d6:27:4f:ad:25:8a:a5:c6:f4:d5:d0:
27+
a6:ae:74:05:64:57:88:b5:44:55:d4:2d:2a:3a:3e:
28+
f8:b8:bd:e9:32:0a:02:94:64:c4:16:3a:50:f1:4a:
29+
ae:e7:79:33:af:0c:20:07:7f:e8:df:04:39:c2:69:
30+
02:6c:63:52:fa:77:c1:1b:c8:74:87:c8:b9:93:18:
31+
50:54:35:4b:69:4e:bc:3b:d3:49:2e:1f:dc:c1:d2:
32+
52:fb
33+
Exponent: 65537 (0x10001)
34+
X509v3 extensions:
35+
X509v3 Basic Constraints: critical
36+
CA:TRUE
37+
X509v3 Key Usage: critical
38+
Certificate Sign, CRL Sign
39+
X509v3 Subject Key Identifier:
40+
40:C2:BD:27:8E:CC:34:83:30:A2:33:D7:FB:6C:B3:F0:B4:2C:80:CE
41+
X509v3 Authority Key Identifier:
42+
keyid:3A:9A:85:07:10:67:28:B6:EF:F6:BD:05:41:6E:20:C1:94:DA:0F:DE
43+
44+
Authority Information Access:
45+
OCSP - URI:http://ocsp.godaddy.com/
46+
47+
X509v3 CRL Distribution Points:
48+
49+
Full Name:
50+
URI:http://crl.godaddy.com/gdroot-g2.crl
51+
52+
X509v3 Certificate Policies:
53+
Policy: X509v3 Any Policy
54+
CPS: https://certs.godaddy.com/repository/
55+
56+
Signature Algorithm: sha256WithRSAEncryption
57+
08:7e:6c:93:10:c8:38:b8:96:a9:90:4b:ff:a1:5f:4f:04:ef:
58+
6c:3e:9c:88:06:c9:50:8f:a6:73:f7:57:31:1b:be:bc:e4:2f:
59+
db:f8:ba:d3:5b:e0:b4:e7:e6:79:62:0e:0c:a2:d7:6a:63:73:
60+
31:b5:f5:a8:48:a4:3b:08:2d:a2:5d:90:d7:b4:7c:25:4f:11:
61+
56:30:c4:b6:44:9d:7b:2c:9d:e5:5e:e6:ef:0c:61:aa:bf:e4:
62+
2a:1b:ee:84:9e:b8:83:7d:c1:43:ce:44:a7:13:70:0d:91:1f:
63+
f4:c8:13:ad:83:60:d9:d8:72:a8:73:24:1e:b5:ac:22:0e:ca:
64+
17:89:62:58:44:1b:ab:89:25:01:00:0f:cd:c4:1b:62:db:51:
65+
b4:d3:0f:51:2a:9b:f4:bc:73:fc:76:ce:36:a4:cd:d9:d8:2c:
66+
ea:ae:9b:f5:2a:b2:90:d1:4d:75:18:8a:3f:8a:41:90:23:7d:
67+
5b:4b:fe:a4:03:58:9b:46:b2:c3:60:60:83:f8:7d:50:41:ce:
68+
c2:a1:90:c3:bb:ef:02:2f:d2:15:54:ee:44:15:d9:0a:ae:a7:
69+
8a:33:ed:b1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H9zB0lL7AgMB
87+
AAGjggEaMIIBFjAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjAdBgNV
88+
HQ4EFgQUQMK9J47MNIMwojPX+2yz8LQsgM4wHwYDVR0jBBgwFoAUOpqFBxBnKLbv
89+
9r0FQW4gwZTaD94wNAYIKwYBBQUHAQEEKDAmMCQGCCsGAQUFBzABhhhodHRwOi8v
90+
b2NzcC5nb2RhZGR5LmNvbS8wNQYDVR0fBC4wLDAqoCigJoYkaHR0cDovL2NybC5n
91+
b2RhZGR5LmNvbS9nZHJvb3QtZzIuY3JsMEYGA1UdIAQ/MD0wOwYEVR0gADAzMDEG
92+
CCsGAQUFBwIBFiVodHRwczovL2NlcnRzLmdvZGFkZHkuY29tL3JlcG9zaXRvcnkv
93+
MA0GCSqGSIb3DQEBCwUAA4IBAQAIfmyTEMg4uJapkEv/oV9PBO9sPpyIBslQj6Zz
94+
91cxG7685C/b+LrTW+C05+Z5Yg4MotdqY3MxtfWoSKQ7CC2iXZDXtHwlTxFWMMS2
95+
RJ17LJ3lXubvDGGqv+QqG+6EnriDfcFDzkSnE3ANkR/0yBOtg2DZ2HKocyQetawi
96+
DsoXiWJYRBuriSUBAA/NxBti21G00w9RKpv0vHP8ds42pM3Z2Czqrpv1KrKQ0U11
97+
GIo/ikGQI31bS/6kA1ibRrLDYGCD+H1QQc7CoZDDu+8CL9IVVO5EFdkKrqeKM+2x
98+
LXY2JtwE65/3YR8V3Idv7kaWKK2hJn0KCacuBKONvPi8BDAB
99+
-----END CERTIFICATE-----

example-javascript.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//const Kmb = require('js-kmb-api').default;
2+
const Kmb = require('./dist/src').default;
3+
4+
const kmb = new Kmb;
5+
6+
async function example() {
7+
// Load the forward route of 104
8+
const route = (await kmb.getRoutes('104')).find(route => route.bound === 1);
9+
if (route === undefined) {
10+
throw new Error('route is not found');
11+
}
12+
13+
// load the main variant
14+
const variant = (await route.getVariants()).sort((a, b) => a.serviceType - b.serviceType)[0];
15+
if (variant === undefined) {
16+
throw new Error('No variants are found');
17+
}
18+
19+
// Load the stop list of the main variant
20+
const stoppings = await variant.getStoppings();
21+
22+
// Find a stop called "Immigration Tower"
23+
const stopping = stoppings.find(stopping => stopping.stop.name === 'Immigration Tower');
24+
if (stopping === undefined) {
25+
throw new Error('Stop is not found');
26+
}
27+
28+
// Get the ETA there
29+
const etas = await stopping.getEtas();
30+
console.log(etas);
31+
32+
// Get the stoppings of all other routes for that stop
33+
const stoppings_at_immigration_tower = await stopping.stop.getStoppings();
34+
console.log(stoppings_at_immigration_tower);
35+
}
36+
37+
void example();

example-typescript.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// import Kmb from "js-kmb-api"
2+
import Kmb from "./src";
3+
4+
const kmb = new Kmb;
5+
6+
async function example() {
7+
// Load the forward route of 104
8+
const route = (await kmb.getRoutes('104')).find(route => route.bound === 1);
9+
if (route === undefined) {
10+
throw new Error('route is not found');
11+
}
12+
13+
// load the main variant
14+
const variant = (await route.getVariants()).sort((a, b) => a.serviceType - b.serviceType)[0];
15+
if (variant === undefined) {
16+
throw new Error('No variants are found');
17+
}
18+
19+
// Load the stop list of the main variant
20+
const stoppings = await variant.getStoppings();
21+
22+
// Find a stop called "Immigration Tower"
23+
const stopping = stoppings.find(stopping => stopping.stop.name === 'Immigration Tower');
24+
if (stopping === undefined) {
25+
throw new Error('Stop is not found');
26+
}
27+
28+
// Get the ETA there
29+
const etas = await stopping.getEtas();
30+
console.log(etas);
31+
32+
// Get the stoppings of all other routes for that stop
33+
const stoppings_at_immigration_tower = await stopping.stop.getStoppings();
34+
console.log(stoppings_at_immigration_tower);
35+
}
36+
37+
void example();

modules.d.ts

-5
This file was deleted.

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,21 @@
2323
"chai-as-promised": "^7.1.1",
2424
"eslint": "^7.11.0",
2525
"mocha": "^8.1.3",
26-
"mock-local-storage": "^1.1.15",
2726
"nock": "^13.0.4",
2827
"sinon": "^9.2.0",
2928
"source-map-support": "^0.5.19",
3029
"ts-node": "^9.0.0",
3130
"typescript": "^4.0.3"
3231
},
3332
"dependencies": {
33+
"@types/node": "^14.14.2",
3434
"aes-js": "^3.1.2",
35-
"axios": "^0.20.0"
35+
"axios": "^0.20.0",
36+
"node-storage-shim": "^2.0.1",
37+
"ssl-root-cas": "^1.3.1"
3638
},
3739
"scripts": {
38-
"build": "tsc",
40+
"build": "tsc && cp cert.pem dist",
3941
"lint": "eslint .",
4042
"test": "mocha",
4143
"clean": "rm -fr dist",

register-mocha-requires.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
import Axios from 'axios';
2-
import httpAdapter from "axios/lib/adapters/http.js";
3-
import Chai from "chai";
4-
import ChaiAsPromised from "chai-as-promised";
5-
import TsNode from 'ts-node';
6-
import SourceMapSupport from 'source-map-support';
7-
8-
SourceMapSupport.install();
9-
TsNode.register();
10-
import 'mock-local-storage';
11-
Axios.defaults.adapter = httpAdapter;
12-
Chai.use(ChaiAsPromised);
1+
require('source-map-support/register');
2+
require('ts-node/register');
3+
require('axios').default.defaults.adapter = require("axios/lib/adapters/http");
4+
require('chai').use(require('chai-as-promised'));

src/Secret.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import aesjs from "aes-js";
1+
import aesjs = require("aes-js");
22

33
export default class Secret {
44
constructor(public readonly apiKey : string, public readonly ctr : number) {

0 commit comments

Comments
 (0)