eda-readings 1.0.0

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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Décio Fernandes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # eda-readings
2
+
3
+ An NPM package to send EDA (Electricidade dos Açores) power readings.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install eda-readings
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { createClient, type ReadingResponse, type SendReadingPayload } from 'eda-readings';
15
+
16
+ const client = createClient('<your-client-number>', '<your-contract-number>');
17
+
18
+ // Fetch current reading data
19
+ const reading: ReadingResponse = await client.getReading();
20
+ console.log(reading);
21
+
22
+ // Send meter readings
23
+ const payload: SendReadingPayload = {
24
+ cil: reading.cil,
25
+ cilToken: reading.cilToken,
26
+ cilTokenExpires: reading.cilTokenExpires,
27
+ serial: reading.serial,
28
+ material: reading.material,
29
+ valorContador1: '8900',
30
+ register1: reading.register1,
31
+ valorContador2: '5420',
32
+ register2: reading.register2,
33
+ valorContador3: '13400',
34
+ register3: reading.register3,
35
+ };
36
+ await client.sendReading(payload);
37
+ ```
38
+
39
+ ## API
40
+
41
+ ### `createClient(clientNumber, contractNumber)`
42
+
43
+ Creates an EDA readings client.
44
+
45
+ | Parameter | Type | Description |
46
+ | ---------------- | -------- | ---------------------------------- |
47
+ | `clientNumber` | `string` | Your CIL (client identification number) |
48
+ | `contractNumber` | `string` | Your contract number |
49
+
50
+ Returns an object with the following methods:
51
+
52
+ ---
53
+
54
+ #### `client.getReading()`
55
+
56
+ Fetches the current reading data from the EDA API.
57
+
58
+ - **Returns:** `Promise<ReadingResponse>` — the reading data object.
59
+
60
+ ---
61
+
62
+ #### `client.sendReading(readings)`
63
+
64
+ Sends meter readings to the EDA API.
65
+
66
+ | Field | Type | Required | Description |
67
+ | -------------------- | -------- | -------- | ---------------------------------- |
68
+ | `cil` | `string` | ✅ | CIL identifier |
69
+ | `cilToken` | `string` | ✅ | CIL token |
70
+ | `cilTokenExpires` | `number` | ✅ | CIL token expiry timestamp |
71
+ | `serial` | `string` | ✅ | Meter serial number |
72
+ | `material` | `string` | ✅ | Material identifier |
73
+ | `valorContador1` | `string` | ✅ | Reading for counter 1 |
74
+ | `register1` | `string` | ✅ | Register identifier for counter 1 |
75
+ | `valorContador2` | `string` | ❌ | Reading for counter 2 |
76
+ | `register2` | `string` | ❌ | Register identifier for counter 2 |
77
+ | `valorContador3` | `string` | ❌ | Reading for counter 3 |
78
+ | `register3` | `string` | ❌ | Register identifier for counter 3 |
79
+
80
+ - **Returns:** `Promise<unknown>` — the API response.
81
+
82
+ ## Scripts
83
+
84
+ | Script | Description |
85
+ | ----------------- | --------------------------------------------------- |
86
+ | `npm run build` | Compile TypeScript to `dist/` |
87
+ | `npm test` | Run the test suite |
88
+ | `npm run release` | Run tests, build, and publish to NPM |
89
+
90
+ ## License
91
+
92
+ [MIT](LICENSE)
@@ -0,0 +1,46 @@
1
+ export interface ReadingResponse {
2
+ cil: string;
3
+ cilToken: string;
4
+ cilTokenExpires: number;
5
+ serial: string;
6
+ material: string;
7
+ contrato: string;
8
+ data: string;
9
+ dataAconselhavelEnvio: string;
10
+ origem: string;
11
+ tarifa: string;
12
+ descContador1: string;
13
+ valorContador1: string;
14
+ valorMinContador1: string;
15
+ valorMaxContador1: string;
16
+ register1: string;
17
+ descContador2?: string;
18
+ valorContador2?: string;
19
+ valorMinContador2?: string;
20
+ valorMaxContador2?: string;
21
+ register2?: string;
22
+ descContador3?: string;
23
+ valorContador3?: string;
24
+ valorMinContador3?: string;
25
+ valorMaxContador3?: string;
26
+ register3?: string;
27
+ }
28
+ export interface SendReadingPayload {
29
+ cil: string;
30
+ cilToken: string;
31
+ cilTokenExpires: number;
32
+ serial: string;
33
+ material: string;
34
+ valorContador1: string;
35
+ register1: string;
36
+ valorContador2?: string;
37
+ register2?: string;
38
+ valorContador3?: string;
39
+ register3?: string;
40
+ }
41
+ export interface EDAClient {
42
+ getReading(): Promise<ReadingResponse>;
43
+ sendReading(readings: SendReadingPayload): Promise<unknown>;
44
+ }
45
+ export declare function createClient(clientNumber: string, contractNumber: string): EDAClient;
46
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,qBAAqB,EAAE,MAAM,CAAC;IAC9B,M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ADDED
@@ -0,0 +1,28 @@
1
+ const BASE_URL = 'https://smile.eda.pt/api/leitura';
2
+ export function createClient(clientNumber, contractNumber) {
3
+ if (!clientNumber || !contractNumber) {
4
+ throw new Error('clientNumber and contractNumber are required');
5
+ }
6
+ async function getReading() {
7
+ const url = `${BASE_URL}?cil=${encodeURIComponent(clientNumber)}&contrato=${encodeURIComponent(contractNumber)}`;
8
+ const response = await fetch(url);
9
+ if (!response.ok) {
10
+ throw new Error(`Failed to get reading: ${response.status} ${response.statusText}`);
11
+ }
12
+ return response.json();
13
+ }
14
+ async function sendReading(readings) {
15
+ const url = `${BASE_URL}?cil=${encodeURIComponent(clientNumber)}`;
16
+ const response = await fetch(url, {
17
+ method: 'PUT',
18
+ headers: { 'Content-Type': 'application/json' },
19
+ body: JSON.stringify(readings),
20
+ });
21
+ if (!response.ok) {
22
+ throw new Error(`Failed to send reading: ${response.status} ${response.statusText}`);
23
+ }
24
+ return response.json();
25
+ }
26
+ return { getReading, sendReading };
27
+ }
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,QAAQ,GAAG,kCAAkC,CAAC;AAiDpD,MAAM,UAAU,YAAY,CAAC,YAAoB,EAAE,cAAsB;IACvE,IAAI,CAAC,YAAY,IAAI,CAAC,cAAc,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IAED,KAAK,UAAU,UAAU;QACvB,MAAM,GAAG,GAAG,GAAG,QAAQ,QAAQ,kBAAkB,CAAC,YAAY,CAAC,aAAa,kBAAkB,CAAC,cAAc,CAAC,EAAE,CAAC;QACjH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,0BAA0B,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;QACtF,CAAC;QACD,OAAO,QAAQ,CAAC,IAAI,EAA8B,CAAC;IACrD,CAAC;IAED,KAAK,UAAU,WAAW,CAAC,QAA4B;QACrD,MAAM,GAAG,GAAG,GAAG,QAAQ,QAAQ,kBAAkB,CAAC,YAAY,CAAC,EAAE,CAAC;QAClE,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;YAChC,MAAM,EAAE,KAAK;YACb,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;SAC/B,CAAC,CAAC;QACH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,2BAA2B,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;QACvF,CAAC;QACD,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;AACrC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "eda-readings",
3
+ "version": "1.0.0",
4
+ "description": "An NPM package to send EDA power readings",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "test": "node --import tsx/esm --test 'test/**/*.test.ts'",
20
+ "release": "npm test && npm run build && npm publish"
21
+ },
22
+ "keywords": [
23
+ "eda",
24
+ "readings",
25
+ "energy",
26
+ "portugal"
27
+ ],
28
+ "author": "",
29
+ "license": "MIT",
30
+ "devDependencies": {
31
+ "@types/node": "^25.5.2",
32
+ "tsx": "^4.21.0",
33
+ "typescript": "^6.0.2"
34
+ }
35
+ }