Skip to content

Commit 8364916

Browse files
feature/stable (#135)
* Update dependency xml2js to v0.6.2 * transform response namning * clean up method * improve tests * require startDate for dayAheadPrices * Update swc monorepo * rename `BiddingZones` const to `BiddingZonesByCountry` * documentation * misc * update `swc` config --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
1 parent 114a873 commit 8364916

23 files changed

+671
-239
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** @type {import('eslint').ESLint.ConfigData} */
12
module.exports = {
23
parserOptions: {
34
ecmaVersion: "latest",

.github/workflows/ci.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
push:
55
branches: [main]
66
pull_request:
7-
branches: [main]
7+
branches: ["**"]
88

99
jobs:
1010
code-check:
@@ -30,10 +30,7 @@ jobs:
3030
run: npm run lint:check
3131

3232
- name: Run tests
33-
run: npm run test
34-
env:
35-
API_TOKEN: ${{ secrets.ENTSOE_API_TOKEN }}
36-
TZ: Europe/London
33+
run: npm run test --verbose
3734

3835
- name: Run build
3936
run: npm run build

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ build/Release
4444
# Build / generate output
4545
dist/
4646
lib/
47+
coverage/
4748

4849
# Dependency directories
4950
node_modules/
@@ -62,10 +63,7 @@ node_modules/
6263

6364
# dotenv environment variable files
6465
.env
65-
.env.development.local
66-
.env.test.local
67-
.env.production.local
68-
.env.local
66+
.env*.local
6967

7068
# yarn v2
7169
.yarn/cache

.swcrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"jsc": {
33
"parser": {
44
"syntax": "ecmascript"
5-
},
6-
"target": "es5"
5+
}
76
},
87
"module": {
98
"type": "commonjs"

README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
### Why this wrapper
66

7-
The API responses from the [ENTSO-E Transparency Platform](https://transparency.entsoe.eu) are formatted in XML, which may not be easily consumable in JavaScript applications. This wrapper automatically converts the response into the more compatible JSON format.
7+
The API responses from the [ENTSO-E Transparency Platform](https://transparency.entsoe.eu) are formatted in XML, which may not be easily consumable in JavaScript applications. This wrapper transforms the response into the more compatible JSON format.
88

99
- [ENTSO-E Transparency Platform](https://transparency.entsoe.eu/dashboard/show)
1010
- [Transparency Platform API spec.](https://transparency.entsoe.eu/content/static_content/Static%20content/web%20api/Guide.html)
@@ -18,7 +18,7 @@ The API responses from the [ENTSO-E Transparency Platform](https://transparency.
1818
- [Public REST Endpoints](#public-rest-endpoints)
1919
- [dayAheadPrices](#day-ahead-prices)
2020
- [Miscellaneous](#miscellaneous)
21-
- [BiddingZones](#bidding-zones)
21+
- [Bidding zones](#bidding-zones)
2222

2323
### Installation
2424

@@ -29,13 +29,13 @@ The API responses from the [ENTSO-E Transparency Platform](https://transparency.
2929
To use this wrapper, you must first register with the Transparency Platform and request access to the RESTful API by sending an email to [email protected] with 'Restful API access' in the subject line. Be sure to include the email address you used during registration in the email body. Once granted access, you can then generate a security token under the account settings.
3030

3131
```js
32-
import Entsoe, { BiddingZones } from "entsoe-api-node";
32+
import Entsoe, { BiddingZonesByCountry } from "entsoe-api-node";
3333

3434
const client = Entsoe({ apiToken: "YOUR-SECURITY-TOKEN" });
3535

3636
const result = await client.dayAheadPrices({
3737
startDate: new Date().toISOString(),
38-
biddingZone: BiddingZones.SW4,
38+
biddingZone: BiddingZonesByCountry.SE4,
3939
});
4040
```
4141

@@ -81,11 +81,11 @@ console.log(
8181
);
8282
```
8383

84-
| Param | Type | Required | Default | Info |
85-
| ----------- | ------ | -------- | ---------------------- | ----------------------------- |
86-
| biddingZone | String | true | |
87-
| startDate | String | false | Current locale date | ISO 8601 formated date string |
88-
| endDate | String | false | `startDate` + next day | ISO 8601 formated date string |
84+
| Param | Type | Required | Default | Info |
85+
| ----------- | ------ | -------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
86+
| biddingZone | String | true | | Check out the utility [`BiddingZonesByCountry`](https://github.com/rabinage/entsoe-api-node#bidding-zones) for available zones/areas. |
87+
| startDate | String | true | | ISO 8601 formated date string |
88+
| endDate | String | false | `startDate` + next day | ISO 8601 formated date string |
8989

9090
- One year range limit applies
9191
- Minimum time interval between `startDate` and `endDate` is one day
@@ -158,14 +158,16 @@ console.log(
158158

159159
### Miscellaneous
160160

161-
#### BiddingZones
161+
#### Bidding zones
162162

163163
An utility bidding zone map is also being exported by the package in order for you to make readable request while using the API.
164164

165165
```js
166-
import { BiddingZones } from "entsoe-api-node";
166+
import { BiddingZonesByCountry } from "entsoe-api-node";
167167

168-
console.log(await client.dayAheadPrices({ biddingZone: BiddingZones.SW4 }));
168+
console.log(
169+
await client.dayAheadPrices({ biddingZone: BiddingZonesByCountry.SE4 }),
170+
);
169171
```
170172

171173
##### This project is based on the [node-module-swc-cjs](https://github.com/rabinage/starters/tree/main/node-module-swc-cjs) starter. Check it out for more production ready starters!

example/custom-response-transformer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { parseStringPromise } from "xml2js";
2-
import Entsoe, { BiddingZones } from "../src/index";
2+
import Entsoe, { BiddingZonesByCountry } from "../src/index";
33

44
/**
55
* Example using a custom response transformer.
@@ -15,6 +15,6 @@ const customRt = async (xmlString) => {
1515
return json;
1616
};
1717
client
18-
.dayAheadPrices({ biddingZone: BiddingZones.SW4 }, customRt)
18+
.dayAheadPrices({ biddingZone: BiddingZonesByCountry.SE4 }, customRt)
1919
// eslint-disable-next-line no-console
2020
.then((res) => console.log(res));

example/day-and-night-prices.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Entsoe, { BiddingZones } from "../src/index";
1+
import Entsoe, { BiddingZonesByCountry } from "../src/index";
22

33
/**
44
* Print the current day and night price.
@@ -12,7 +12,7 @@ const client = Entsoe({ apiToken: process.env.API_TOKEN });
1212
client
1313
.dayAheadPrices({
1414
startDate: new Date().toISOString(),
15-
biddingZone: BiddingZones.SW4,
15+
biddingZone: BiddingZonesByCountry.SE4,
1616
})
1717
.then((res) => {
1818
res.timeSeries.forEach((ts) => {

index.d.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
declare module "entsoe-api-node" {
2+
/**
3+
* Unofficial API wrapper for the ENTSO-E Transparency Platform.
4+
* @see {@link https://transparency.entsoe.eu/content/static_content/Static%20content/web%20api/Guide.html} ENTSO-E Transparency Platform RESTful API documentation.
5+
* @see {@link https://transparency.entsoe.eu/content/static_content/Static%20content/web%20api/Guide.html#_complete_parameter_list} Entsoe Transparency Platform RESTful API Appendix.
6+
* @see {@link https://github.com/rabinage/entsoe-api-node} Wrapper documentation.
7+
* @param {string} apiToken - API security token {@link https://github.com/rabinage/entsoe-api-node#getting-started}.
8+
* @param {boolean} testnet - Optional. For testing purpose only.
9+
*/
210
export default function (options?: {
311
apiToken: string;
412
testnet?: boolean;
513
}): Entsoe;
614

7-
export const enum DocumentTypes {
8-
PRICE_DOCUMENT = "A44",
9-
}
10-
11-
export const enum BiddingZones {
15+
/**
16+
* A.15. Areas divided into country codes, followed by potential zone number.
17+
*/
18+
export const enum BiddingZonesByCountry {
1219
AL = "10YAL-KESH-----5", // Albania
1320
AT = "10Y1001A1001A63L", // Austria
1421
BA = "10YBA-JPCC-----D", // Bosnia and Herzegovina
@@ -49,10 +56,10 @@ declare module "entsoe-api-node" {
4956
PT = "10YPT-REN------W", // Portugal
5057
RO = "10YRO-TEL------P", // Romania
5158
RS = "10YCS-SERBIATSOV", // Serb
52-
SW1 = "10Y1001A1001A44P", // Sweden zone 1
53-
SW2 = "10Y1001A1001A45N", // Swden zone 2
54-
SW3 = "10Y1001A1001A46L", // Swden zone 3
55-
SW4 = "10Y1001A1001A47J", // Sweden zone 4
59+
SE1 = "10Y1001A1001A44P", // Sweden zone 1
60+
SE2 = "10Y1001A1001A45N", // Swden zone 2
61+
SE3 = "10Y1001A1001A46L", // Swden zone 3
62+
SE4 = "10Y1001A1001A47J", // Sweden zone 4
5663
SL = "10YSI-ELES-----O", // Slovenia
5764
SK = "10YSK-SEPS-----K", // Slovak Republic
5865
}
@@ -103,10 +110,15 @@ declare module "entsoe-api-node" {
103110
interface DayAheadPriceResponseTransformer extends ResponseTransformer {}
104111

105112
export interface Entsoe {
106-
// Article 12.1.D
113+
/**
114+
* A.12.1.D. Day ahead prices.
115+
* @param {string} biddingZone - Bidding zone/area code.
116+
* @param {string} startDate - ISO 8601 formated date string.
117+
* @param {string} endDate - Optional. ISO 8601 formated date string.
118+
*/
107119
dayAheadPrices(
108120
payload: {
109-
biddingZone: BiddingZones;
121+
biddingZone: string;
110122
startDate?: string;
111123
endDate?: string;
112124
},

jest.config.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1+
const thresholdPercentage = 80;
2+
3+
/** @type {import('jest').Config} */
14
module.exports = {
25
transform: {
36
"^.+\\.js?$": ["@swc/jest"],
47
},
58
testEnvironment: "node",
6-
testMatch: ["<rootDir>/test/**/*"],
9+
testMatch: ["<rootDir>/test/**/?(*.)test.js"],
10+
coverageThreshold: {
11+
global: {
12+
functions: thresholdPercentage,
13+
lines: thresholdPercentage,
14+
statements: thresholdPercentage,
15+
},
16+
},
717
};

0 commit comments

Comments
 (0)