wili 0.5.1 → 0.6.1

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/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2018-present Jan T. Sott
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.de.md CHANGED
@@ -6,15 +6,11 @@
6
6
 
7
7
  [English](README.md) | **Deutsch**
8
8
 
9
- Node Wrapper für das Echtzeitdaten API der Wiener Linien
9
+ Node Wrapper für die Echtzeitdaten-API der Wiener Linien
10
10
 
11
11
  ## Installation
12
12
 
13
- `yarn add wili || npm install wili`
14
-
15
- ## Voraussetzungen
16
-
17
- **Hinweis:** Seit November 2019 wird kein gültiger API Key mehr für die Verwendung benötigt. Zuvor erworbene Keys können weiterhin verwendet werden.
13
+ `npm install wili`
18
14
 
19
15
  ## Anwendung
20
16
 
@@ -40,13 +36,24 @@ wili.trafficInfoList(options)
40
36
 
41
37
  // async/await
42
38
  try {
43
- let data = await wili.trafficInfoList(options);
39
+ const data = await wili.trafficInfoList(options);
44
40
  console.log(data.trafficInfos);
45
41
  } catch (output) {
46
42
  console.error(error);
47
43
  }
48
44
  ```
49
45
 
46
+ :warning: Für NodeJS-Versionen unterhalb v18, muss die Klasse mit einer `fetch`-Implementierung instanziert werden.
47
+
48
+ **Beispiel**
49
+
50
+ ```js
51
+ import { WienerLinien } from 'wili';
52
+ import fetch from 'isomorphic-fetch';
53
+
54
+ const wili = new WienerLinien(fetch);
55
+ ```
56
+
50
57
  ## API
51
58
 
52
59
  ### monitor
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![npm](https://flat.badgen.net/npm/license/wili)](https://www.npmjs.org/package/wili)
4
4
  [![npm](https://flat.badgen.net/npm/v/wili)](https://www.npmjs.org/package/wili)
5
- [![CI](https://img.shields.io/github/workflow/status/idleberg/node-wili/CI?style=flat-square)](https://github.com/idleberg/node-wili/actions)
5
+ [![CI](https://img.shields.io/github/actions/workflow/status/idleberg/node-wili/default.yml?style=flat-square)](https://github.com/idleberg/node-wili/actions)
6
6
 
7
7
  **English** | [Deutsch](README.de.md)
8
8
 
@@ -10,11 +10,7 @@ A Node wrapper for the Wiener Linien public transport API
10
10
 
11
11
  ## Installation
12
12
 
13
- `yarn add wili || npm install wili`
14
-
15
- ## Prerequisites
16
-
17
- **Note:** As of November 2019, a valid API key to access Wiener Linien's real-time data is no longer required. However, if you obtained a key before, you can continue using it.
13
+ `npm install wili`
18
14
 
19
15
  ## Usage
20
16
 
@@ -40,13 +36,24 @@ wili.trafficInfoList(options)
40
36
 
41
37
  // async/await
42
38
  try {
43
- let data = await wili.trafficInfoList(options);
39
+ const data = await wili.trafficInfoList(options);
44
40
  console.log(data.trafficInfos);
45
41
  } catch (output) {
46
42
  console.error(error);
47
43
  }
48
44
  ```
49
45
 
46
+ :warning: For NodeJS versions lower than v18, the class needs to be instantiated with a `fetch`-implementation
47
+
48
+ **Example**
49
+
50
+ ```js
51
+ import { WienerLinien } from 'wili';
52
+ import fetch from 'isomorphic-fetch';
53
+
54
+ const wili = new WienerLinien(fetch);
55
+ ```
56
+
50
57
  ## API
51
58
 
52
59
  ### monitor
package/lib/wili.mjs CHANGED
@@ -1,97 +1,66 @@
1
- import fetch from 'isomorphic-fetch';
2
- import queryString from 'query-string';
3
-
4
- var WienerLinien = /** @class */ (function () {
5
- function WienerLinien(API_KEY) {
6
- if (API_KEY === void 0) { API_KEY = undefined; }
7
- this.API_KEY = (API_KEY && API_KEY.length)
8
- ? String(API_KEY)
9
- : String(process.env.WIENER_LINIEN_API_KEY) || 'undefined';
1
+ // src/index.ts
2
+ var WienerLinien = class {
3
+ #fetch;
4
+ constructor(fetchParam = globalThis.fetch) {
5
+ if (typeof fetch !== "function") {
6
+ throw new TypeError("The supplied fetch parameter is not a function");
10
7
  }
11
- /**
12
- * Returns real-time data for a station
13
- * @param rbl - RBL number
14
- * @param options optional arguments
15
- * @returns - JSON
16
- */
17
- WienerLinien.prototype.monitor = function (rbl, options) {
18
- if (options === void 0) { options = {}; }
19
- var urlParams = {
20
- rbl: rbl
21
- };
22
- if (typeof options.activateTrafficInfo !== 'undefined' && options.activateTrafficInfo) {
23
- urlParams['activateTrafficInfo'] = options.activateTrafficInfo;
24
- }
25
- if (this.API_KEY && this.API_KEY.trim().length) {
26
- urlParams['sender'] = this.API_KEY;
27
- }
28
- return this.apiCall('/monitor', urlParams);
29
- };
30
- /**
31
- * Returns news, elevator maintenance and other information
32
- * @param options optional arguments
33
- * @returns JSON
34
- */
35
- WienerLinien.prototype.newsList = function (options) {
36
- if (options === void 0) { options = {}; }
37
- var urlParams = {};
38
- if (typeof options.relatedLine !== 'undefined' && options.relatedLine) {
39
- urlParams['relatedLine'] = options.relatedLine;
40
- }
41
- if (typeof options.relatedStop !== 'undefined' && options.relatedStop) {
42
- urlParams['relatedStop'] = options.relatedStop;
43
- }
44
- if (typeof options.name !== 'undefined' && options.name) {
45
- urlParams['name'] = options.name;
46
- }
47
- if (this.API_KEY && this.API_KEY.trim().length) {
48
- urlParams['sender'] = this.API_KEY;
49
- }
50
- return this.apiCall('newsList', urlParams);
51
- };
52
- /**
53
- * Returns interruption of operations and elevator outage
54
- * @param options optional arguments
55
- * @returns JSON
56
- */
57
- WienerLinien.prototype.trafficInfoList = function (options) {
58
- if (options === void 0) { options = {}; }
59
- var urlParams = {};
60
- if (typeof options.relatedLine !== 'undefined' && options.relatedLine) {
61
- urlParams['relatedLine'] = options.relatedLine;
62
- }
63
- if (typeof options.relatedStop !== 'undefined' && options.relatedStop) {
64
- urlParams['relatedStop'] = options.relatedStop;
65
- }
66
- if (typeof options.name !== 'undefined' && options.name) {
67
- urlParams['name'] = options.name;
68
- }
69
- if (this.API_KEY && this.API_KEY.trim().length) {
70
- urlParams['sender'] = this.API_KEY;
71
- }
72
- return this.apiCall('trafficInfoList', urlParams);
8
+ this.#fetch = fetchParam;
9
+ }
10
+ /**
11
+ * Returns real-time data for a station
12
+ * @param {StringNumbers} rbl - RBL number
13
+ * @param {MonitorOptions} options
14
+ * @returns {object}
15
+ */
16
+ monitor(rbl, options = {}) {
17
+ const urlParams = {
18
+ ...options,
19
+ rbl
73
20
  };
74
- WienerLinien.prototype.checkStatus = function (response) {
75
- if (response.status >= 200 && response.status < 300) {
76
- return Promise.resolve(response);
21
+ return this.#apiCall("/monitor", urlParams);
22
+ }
23
+ /**
24
+ * Returns news, elevator maintenance and other information
25
+ * @param {NewsListOptions} options
26
+ * @returns {object}
27
+ */
28
+ newsList(options = {}) {
29
+ return this.#apiCall("newsList", options);
30
+ }
31
+ /**
32
+ * Returns interruption of operations and elevator outage
33
+ * @param {TrafficInfoOptions} options
34
+ * @returns {object}
35
+ */
36
+ trafficInfoList(options = {}) {
37
+ return this.#apiCall("trafficInfoList", options);
38
+ }
39
+ #buildUrl(urlPath, urlParams) {
40
+ const searchParams = new URLSearchParams();
41
+ for (const [key, value] of Object.entries(urlParams)) {
42
+ if (Array.isArray(value)) {
43
+ for (const item of value) {
44
+ searchParams.append(key, String(item));
77
45
  }
78
- else {
79
- return Promise.reject(new Error(response.statusText));
80
- }
81
- };
82
- WienerLinien.prototype.parseJson = function (response) {
83
- return response.json();
84
- };
85
- WienerLinien.prototype.apiCall = function (urlPath, urlParams) {
86
- var url = new URL('https://www.wienerlinien.at');
87
- url.pathname = "/ogd_realtime/" + urlPath;
88
- url.search = queryString.stringify(urlParams);
89
- return fetch(url.href)
90
- .then(this.checkStatus)
91
- .then(this.parseJson)
92
- .then(function (response) { return response.data; })["catch"](console.error);
93
- };
94
- return WienerLinien;
95
- }());
96
-
97
- export { WienerLinien };
46
+ } else {
47
+ searchParams.set(key, String(value));
48
+ }
49
+ }
50
+ return new URL(`https://www.wienerlinien.at/ogd_realtime/${urlPath}?${searchParams.toString()}`);
51
+ }
52
+ #checkStatus(response) {
53
+ if (response.ok) {
54
+ return Promise.resolve(response);
55
+ } else {
56
+ return Promise.reject(new Error(response.statusText));
57
+ }
58
+ }
59
+ #apiCall(urlPath, urlParams) {
60
+ const url = this.#buildUrl(urlPath, urlParams);
61
+ return this.#fetch(url.href).then(this.#checkStatus).then((response) => response.json()).then((json) => json.data).catch(console.error);
62
+ }
63
+ };
64
+ export {
65
+ WienerLinien
66
+ };
package/package.json CHANGED
@@ -1,27 +1,34 @@
1
1
  {
2
2
  "name": "wili",
3
- "version": "0.5.1",
3
+ "version": "0.6.1",
4
4
  "description": "A Node client for the Wiener Linien public transport API",
5
5
  "author": "Jan T. Sott",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
- "exports": {
9
- "import": "./lib/wili.mjs",
10
- "require": "./lib/wili.cjs"
11
- },
8
+ "exports": "./lib/wili.mjs",
12
9
  "typings": "types/",
10
+ "engines": {
11
+ "node": ">=16.13 || >=18"
12
+ },
13
+ "files": [
14
+ "lib/",
15
+ "types/",
16
+ "LICENSE",
17
+ "README.md"
18
+ ],
13
19
  "repository": {
14
20
  "type": "git",
15
21
  "url": "https://github.com/idleberg/node-wili.git"
16
22
  },
17
23
  "scripts": {
18
- "build": "rollup -c",
24
+ "build": "esbuild src/index.ts --bundle --platform=node --outfile=lib/wili.mjs --format=esm --external:isomorphic-fetch --external:query-string",
19
25
  "dev": "npm run start",
20
- "lint": "eslint ./src",
21
26
  "lint:fix": "eslint --fix ./src",
22
- "start": "rollup -w -c",
23
- "test": "ava ./test/test.*js --verbose --fail-fast",
24
- "prepare": "husky install"
27
+ "lint": "eslint ./src",
28
+ "prepack": "npm run build",
29
+ "prepare": "husky install",
30
+ "start": "npm run build -- --watch",
31
+ "test": "uvu tests"
25
32
  },
26
33
  "keywords": [
27
34
  "wiener linien",
@@ -30,26 +37,19 @@
30
37
  "öpvn",
31
38
  "public transport"
32
39
  ],
33
- "dependencies": {
34
- "isomorphic-fetch": "^3.0.0",
35
- "query-string": "^7.1.1"
36
- },
40
+ "dependencies": {},
37
41
  "devDependencies": {
38
- "@rollup/plugin-commonjs": "^22.0.1",
39
- "@rollup/plugin-json": "^4.1.0",
40
- "@rollup/plugin-node-resolve": "^13.3.0",
41
- "@rollup/plugin-typescript": "^8.3.3",
42
- "@types/node": "^16.11.45",
43
- "@typescript-eslint/eslint-plugin": "^5.31.0",
44
- "@typescript-eslint/parser": "^5.31.0",
45
- "ava": "^4.3.1",
46
- "encoding": "^0.1.13",
47
- "eslint": "^8.20.0",
48
- "husky": "^8.0.1",
49
- "lint-staged": "^13.0.3",
50
- "rollup": "^2.77.2",
51
- "tslib": "^2.4.0",
52
- "typescript": "^4.7.4"
42
+ "@types/isomorphic-fetch": "^0.0.36",
43
+ "@types/node": "^18.15.5",
44
+ "@typescript-eslint/eslint-plugin": "^5.56.0",
45
+ "@typescript-eslint/parser": "^5.56.0",
46
+ "esbuild": "^0.17.12",
47
+ "eslint": "^8.36.0",
48
+ "husky": "^8.0.3",
49
+ "lint-staged": "^13.2.0",
50
+ "tslib": "^2.5.0",
51
+ "typescript": "^5.0.2",
52
+ "uvu": "^0.5.6"
53
53
  },
54
54
  "lint-staged": {
55
55
  "*.ts": "eslint --cache --fix"
@@ -0,0 +1,34 @@
1
+ type StringNumbers = number | string | number[] | string[];
2
+
3
+ declare class WienerLinien {
4
+ constructor(API_KEY?: string);
5
+
6
+ monitor(rbl: StringNumbers, options: MonitorOptions): Promise<Record<string, unknown>>;
7
+ newsList(options: NewsListOptions): Promise<Record<string, unknown>>;
8
+ trafficInfoList(options: TrafficInfoOptions): Promise<Record<string, unknown>>;
9
+
10
+ baseUrl?: string;
11
+ reqUrl?: string;
12
+ }
13
+
14
+ type MonitorOptions = {
15
+ activateTrafficInfo?: string | string[];
16
+ }
17
+
18
+ interface MonitorParams extends MonitorOptions {
19
+ rbl?: StringNumbers;
20
+ }
21
+
22
+ type NewsListOptions = {
23
+ name?: string | string[];
24
+ relatedLine?: StringNumbers;
25
+ relatedStop?: StringNumbers;
26
+ }
27
+
28
+ type TrafficInfoOptions = {
29
+ name?: string | string[];
30
+ relatedLine?: StringNumbers;
31
+ relatedStop?: StringNumbers;
32
+ }
33
+
34
+ type UrlParams = MonitorOptions | NewsListOptions | TrafficInfoOptions;
package/.eslintrc.cjs DELETED
@@ -1,16 +0,0 @@
1
- /* eslint-disable */
2
- module.exports = {
3
- root: true,
4
- parser: '@typescript-eslint/parser',
5
- plugins: [
6
- '@typescript-eslint',
7
- ],
8
- extends: [
9
- 'eslint:recommended',
10
- 'plugin:@typescript-eslint/recommended',
11
- ],
12
- rules: {
13
- // temporary
14
- "@typescript-eslint/no-explicit-any": "off"
15
- }
16
- };
@@ -1,44 +0,0 @@
1
- name: CI
2
-
3
- on: [push]
4
-
5
- jobs:
6
- default:
7
- runs-on: ${{ matrix.os }}
8
- strategy:
9
- matrix:
10
- node-version: ['lts/*', '*']
11
- os: [ubuntu-latest]
12
-
13
- steps:
14
- - uses: actions/checkout@v3
15
- with:
16
- fetch-depth: 1
17
-
18
- - uses: actions/setup-node@v3
19
- with:
20
- node-version: ${{ matrix.node-version }}
21
-
22
- - name: Cache pnpm modules
23
- uses: actions/cache@v3
24
- with:
25
- path: ~/.pnpm-store
26
- key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
27
- restore-keys: |
28
- ${{ runner.os }}-
29
-
30
- - uses: pnpm/action-setup@v2
31
- with:
32
- version: 6
33
- run_install: |
34
- - recursive: true
35
- - args: [--frozen-lockfile, --strict-peer-dependencies]
36
-
37
- - name: Lint Source
38
- run: pnpm run lint --if-present
39
-
40
- - name: Build Source
41
- run: pnpm run build --if-present
42
-
43
- - name: Run Tests
44
- run: pnpm run test --if-present
@@ -1,21 +0,0 @@
1
- name: 'Stale issues and PR'
2
- on:
3
- schedule:
4
- - cron: '30 1 * * *'
5
-
6
- jobs:
7
- stale:
8
- runs-on: ubuntu-latest
9
- steps:
10
- - uses: actions/stale@v4
11
- with:
12
- stale-issue-label: stale
13
- stale-pr-label: stale
14
- stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 14 days.'
15
- stale-pr-message: 'This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 14 days.'
16
- close-issue-message: 'This issue was closed because it has been stalled for 14 days with no activity.'
17
- close-pr-message: 'This PR was closed because it has been stalled for 14 days with no activity.'
18
- days-before-issue-stale: 90
19
- days-before-pr-stale: 90
20
- days-before-issue-close: 30
21
- days-before-pr-close: 30
@@ -1,19 +0,0 @@
1
- {
2
- "version": "2.0.0",
3
- "tasks": [
4
- {
5
- "label": "Development",
6
- "type": "npm",
7
- "script": "start",
8
- "presentation": {
9
- "clear": true,
10
- "focus": false,
11
- "panel": "shared",
12
- "showReuseMessage": true
13
- },
14
- "runOptions": {
15
- "runOn": "folderOpen"
16
- }
17
- }
18
- ]
19
- }
package/lib/wili.cjs DELETED
@@ -1,106 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var fetch = require('isomorphic-fetch');
6
- var queryString = require('query-string');
7
-
8
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
-
10
- var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
11
- var queryString__default = /*#__PURE__*/_interopDefaultLegacy(queryString);
12
-
13
- var WienerLinien = /** @class */ (function () {
14
- function WienerLinien(API_KEY) {
15
- if (API_KEY === void 0) { API_KEY = undefined; }
16
- this.API_KEY = (API_KEY && API_KEY.length)
17
- ? String(API_KEY)
18
- : String(process.env.WIENER_LINIEN_API_KEY) || 'undefined';
19
- }
20
- /**
21
- * Returns real-time data for a station
22
- * @param rbl - RBL number
23
- * @param options optional arguments
24
- * @returns - JSON
25
- */
26
- WienerLinien.prototype.monitor = function (rbl, options) {
27
- if (options === void 0) { options = {}; }
28
- var urlParams = {
29
- rbl: rbl
30
- };
31
- if (typeof options.activateTrafficInfo !== 'undefined' && options.activateTrafficInfo) {
32
- urlParams['activateTrafficInfo'] = options.activateTrafficInfo;
33
- }
34
- if (this.API_KEY && this.API_KEY.trim().length) {
35
- urlParams['sender'] = this.API_KEY;
36
- }
37
- return this.apiCall('/monitor', urlParams);
38
- };
39
- /**
40
- * Returns news, elevator maintenance and other information
41
- * @param options optional arguments
42
- * @returns JSON
43
- */
44
- WienerLinien.prototype.newsList = function (options) {
45
- if (options === void 0) { options = {}; }
46
- var urlParams = {};
47
- if (typeof options.relatedLine !== 'undefined' && options.relatedLine) {
48
- urlParams['relatedLine'] = options.relatedLine;
49
- }
50
- if (typeof options.relatedStop !== 'undefined' && options.relatedStop) {
51
- urlParams['relatedStop'] = options.relatedStop;
52
- }
53
- if (typeof options.name !== 'undefined' && options.name) {
54
- urlParams['name'] = options.name;
55
- }
56
- if (this.API_KEY && this.API_KEY.trim().length) {
57
- urlParams['sender'] = this.API_KEY;
58
- }
59
- return this.apiCall('newsList', urlParams);
60
- };
61
- /**
62
- * Returns interruption of operations and elevator outage
63
- * @param options optional arguments
64
- * @returns JSON
65
- */
66
- WienerLinien.prototype.trafficInfoList = function (options) {
67
- if (options === void 0) { options = {}; }
68
- var urlParams = {};
69
- if (typeof options.relatedLine !== 'undefined' && options.relatedLine) {
70
- urlParams['relatedLine'] = options.relatedLine;
71
- }
72
- if (typeof options.relatedStop !== 'undefined' && options.relatedStop) {
73
- urlParams['relatedStop'] = options.relatedStop;
74
- }
75
- if (typeof options.name !== 'undefined' && options.name) {
76
- urlParams['name'] = options.name;
77
- }
78
- if (this.API_KEY && this.API_KEY.trim().length) {
79
- urlParams['sender'] = this.API_KEY;
80
- }
81
- return this.apiCall('trafficInfoList', urlParams);
82
- };
83
- WienerLinien.prototype.checkStatus = function (response) {
84
- if (response.status >= 200 && response.status < 300) {
85
- return Promise.resolve(response);
86
- }
87
- else {
88
- return Promise.reject(new Error(response.statusText));
89
- }
90
- };
91
- WienerLinien.prototype.parseJson = function (response) {
92
- return response.json();
93
- };
94
- WienerLinien.prototype.apiCall = function (urlPath, urlParams) {
95
- var url = new URL('https://www.wienerlinien.at');
96
- url.pathname = "/ogd_realtime/" + urlPath;
97
- url.search = queryString__default['default'].stringify(urlParams);
98
- return fetch__default['default'](url.href)
99
- .then(this.checkStatus)
100
- .then(this.parseJson)
101
- .then(function (response) { return response.data; })["catch"](console.error);
102
- };
103
- return WienerLinien;
104
- }());
105
-
106
- exports.WienerLinien = WienerLinien;