siar-client 0.1.4 → 2.2.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/dist/client/authentication/AuthenticationService.cjs +75 -0
- package/dist/client/authentication/AuthenticationService.d.ts +44 -0
- package/dist/client/authentication/AuthenticationService.d.ts.map +1 -0
- package/dist/client/authentication/AuthenticationService.js +75 -0
- package/dist/client/authentication/AuthenticationService.js.map +1 -0
- package/dist/client/data/DataService.cjs +38 -9
- package/dist/client/data/DataService.d.ts +2 -0
- package/dist/client/data/DataService.d.ts.map +1 -1
- package/dist/client/data/DataService.js +38 -9
- package/dist/client/data/DataService.js.map +1 -1
- package/dist/client/information/InformationService.cjs +64 -30
- package/dist/client/information/InformationService.d.ts +8 -3
- package/dist/client/information/InformationService.d.ts.map +1 -1
- package/dist/client/information/InformationService.js +64 -30
- package/dist/client/information/InformationService.js.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/Consts.cjs +2 -0
- package/dist/internal/Consts.d.ts +2 -0
- package/dist/internal/Consts.d.ts.map +1 -0
- package/dist/internal/Consts.js +2 -0
- package/dist/internal/Consts.js.map +1 -0
- package/dist/internal/Models.d.ts +1 -1
- package/dist/internal/authentication/Models.cjs +2 -0
- package/dist/internal/authentication/Models.d.ts +15 -0
- package/dist/internal/authentication/Models.d.ts.map +1 -0
- package/dist/internal/authentication/Models.js +2 -0
- package/dist/internal/authentication/Models.js.map +1 -0
- package/dist/internal/data/Models.d.ts +8 -0
- package/dist/internal/data/Models.d.ts.map +1 -1
- package/dist/internal/information/Models.d.ts +47 -30
- package/dist/internal/information/Models.d.ts.map +1 -1
- package/dist/mappers/Mappers.cjs +19 -2
- package/dist/mappers/Mappers.d.ts +6 -2
- package/dist/mappers/Mappers.d.ts.map +1 -1
- package/dist/mappers/Mappers.js +19 -2
- package/dist/mappers/Mappers.js.map +1 -1
- package/dist/public/SIARClient.cjs +23 -0
- package/dist/public/SIARClient.d.ts +21 -0
- package/dist/public/SIARClient.d.ts.map +1 -1
- package/dist/public/SIARClient.js +23 -0
- package/dist/public/SIARClient.js.map +1 -1
- package/dist/public/data/Models.cjs +2 -2
- package/dist/public/data/Models.d.ts +10 -2
- package/dist/public/data/Models.d.ts.map +1 -1
- package/dist/public/data/Models.js +2 -2
- package/dist/public/information/Models.cjs +9 -8
- package/dist/public/information/Models.d.ts +24 -6
- package/dist/public/information/Models.d.ts.map +1 -1
- package/dist/public/information/Models.js +9 -8
- package/dist/public/information/Models.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const { BASE_URL } = require('../../internal/Consts.js');
|
|
2
|
+
/**
|
|
3
|
+
* Service for obtaining authentication tokens in the SIAR Web API
|
|
4
|
+
*/
|
|
5
|
+
exports.AuthenticationService = {
|
|
6
|
+
/**
|
|
7
|
+
* Service constructor
|
|
8
|
+
*/
|
|
9
|
+
constructor() {
|
|
10
|
+
this.baseUrl = BASE_URL;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Builds the URL to encrypt a string
|
|
14
|
+
* @param text String to encrypt
|
|
15
|
+
* @returns Full URL for the request
|
|
16
|
+
*/
|
|
17
|
+
buildEncryptUrl(text) {
|
|
18
|
+
return `${this.baseUrl}/API/V1/Autenticacion/cifrarCadena?cadena=${encodeURIComponent(text)}`;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Builds the URL to obtain a token
|
|
22
|
+
* @param encryptedUser Encrypted user
|
|
23
|
+
* @param encryptedPassword Encrypted password
|
|
24
|
+
* @returns Full URL for the request
|
|
25
|
+
*/
|
|
26
|
+
buildTokenUrl(encryptedUser, encryptedPassword) {
|
|
27
|
+
return `${this.baseUrl}/API/V1/Autenticacion/obtenerToken?Usuario=${encodeURIComponent(encryptedUser)}&Password=${encodeURIComponent(encryptedPassword)}`;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Encrypts a text string using the SIAR API encryption
|
|
31
|
+
* @param text String to encrypt (can be user identifier or password)
|
|
32
|
+
* @returns Promise that resolves with the encrypted string
|
|
33
|
+
*/
|
|
34
|
+
encryptString(text) {
|
|
35
|
+
const url = this.buildEncryptUrl(text);
|
|
36
|
+
return fetch(url).then((response) => {
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
throw new Error(`Error HTTP: ${response.status} - ${response.statusText}`);
|
|
39
|
+
}
|
|
40
|
+
return response.text();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Obtains an authentication token for accessing protected SIAR services
|
|
45
|
+
* This method performs the complete authentication process:
|
|
46
|
+
* 1. Encrypts the user identifier
|
|
47
|
+
* 2. Encrypts the password
|
|
48
|
+
* 3. Obtains the authentication token
|
|
49
|
+
*
|
|
50
|
+
* @param params Authentication parameters (userId and password)
|
|
51
|
+
* @returns Promise that resolves with the authentication token
|
|
52
|
+
*/
|
|
53
|
+
obtainToken(params) {
|
|
54
|
+
// Step 1: Encrypt the user identifier
|
|
55
|
+
return this.encryptString(params.userId)
|
|
56
|
+
.then((encryptedUser) =>
|
|
57
|
+
// Step 2: Encrypt the password
|
|
58
|
+
this.encryptString(params.password).then((encryptedPassword) => ({
|
|
59
|
+
encryptedUser,
|
|
60
|
+
encryptedPassword,
|
|
61
|
+
})))
|
|
62
|
+
.then(({ encryptedUser, encryptedPassword }) => {
|
|
63
|
+
// Step 3: Obtain the token
|
|
64
|
+
const url = this.buildTokenUrl(encryptedUser, encryptedPassword);
|
|
65
|
+
return fetch(url);
|
|
66
|
+
})
|
|
67
|
+
.then((response) => {
|
|
68
|
+
if (!response.ok) {
|
|
69
|
+
throw new Error(`Error HTTP: ${response.status} - ${response.statusText}`);
|
|
70
|
+
}
|
|
71
|
+
return response.text();
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=AuthenticationService.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service for obtaining authentication tokens in the SIAR Web API
|
|
3
|
+
*/
|
|
4
|
+
export declare class AuthenticationService {
|
|
5
|
+
private baseUrl;
|
|
6
|
+
/**
|
|
7
|
+
* Service constructor
|
|
8
|
+
*/
|
|
9
|
+
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Builds the URL to encrypt a string
|
|
12
|
+
* @param text String to encrypt
|
|
13
|
+
* @returns Full URL for the request
|
|
14
|
+
*/
|
|
15
|
+
private buildEncryptUrl;
|
|
16
|
+
/**
|
|
17
|
+
* Builds the URL to obtain a token
|
|
18
|
+
* @param encryptedUser Encrypted user
|
|
19
|
+
* @param encryptedPassword Encrypted password
|
|
20
|
+
* @returns Full URL for the request
|
|
21
|
+
*/
|
|
22
|
+
private buildTokenUrl;
|
|
23
|
+
/**
|
|
24
|
+
* Encrypts a text string using the SIAR API encryption
|
|
25
|
+
* @param text String to encrypt (can be user identifier or password)
|
|
26
|
+
* @returns Promise that resolves with the encrypted string
|
|
27
|
+
*/
|
|
28
|
+
encryptString(text: string): Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Obtains an authentication token for accessing protected SIAR services
|
|
31
|
+
* This method performs the complete authentication process:
|
|
32
|
+
* 1. Encrypts the user identifier
|
|
33
|
+
* 2. Encrypts the password
|
|
34
|
+
* 3. Obtains the authentication token
|
|
35
|
+
*
|
|
36
|
+
* @param params Authentication parameters (userId and password)
|
|
37
|
+
* @returns Promise that resolves with the authentication token
|
|
38
|
+
*/
|
|
39
|
+
obtainToken(params: {
|
|
40
|
+
userId: string;
|
|
41
|
+
password: string;
|
|
42
|
+
}): Promise<string>;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=AuthenticationService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthenticationService.d.ts","sourceRoot":"","sources":["../../../src/client/authentication/AuthenticationService.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,OAAO,CAAS;IAExB;;OAEG;;IAKH;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAIvB;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IAOrB;;;;OAIG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAY5C;;;;;;;;;OASG;IACH,WAAW,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;CAwB3E"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { BASE_URL } from "../../internal/Consts.js";
|
|
2
|
+
/**
|
|
3
|
+
* Service for obtaining authentication tokens in the SIAR Web API
|
|
4
|
+
*/
|
|
5
|
+
export class AuthenticationService {
|
|
6
|
+
/**
|
|
7
|
+
* Service constructor
|
|
8
|
+
*/
|
|
9
|
+
constructor() {
|
|
10
|
+
this.baseUrl = BASE_URL;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Builds the URL to encrypt a string
|
|
14
|
+
* @param text String to encrypt
|
|
15
|
+
* @returns Full URL for the request
|
|
16
|
+
*/
|
|
17
|
+
buildEncryptUrl(text) {
|
|
18
|
+
return `${this.baseUrl}/API/V1/Autenticacion/cifrarCadena?cadena=${encodeURIComponent(text)}`;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Builds the URL to obtain a token
|
|
22
|
+
* @param encryptedUser Encrypted user
|
|
23
|
+
* @param encryptedPassword Encrypted password
|
|
24
|
+
* @returns Full URL for the request
|
|
25
|
+
*/
|
|
26
|
+
buildTokenUrl(encryptedUser, encryptedPassword) {
|
|
27
|
+
return `${this.baseUrl}/API/V1/Autenticacion/obtenerToken?Usuario=${encodeURIComponent(encryptedUser)}&Password=${encodeURIComponent(encryptedPassword)}`;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Encrypts a text string using the SIAR API encryption
|
|
31
|
+
* @param text String to encrypt (can be user identifier or password)
|
|
32
|
+
* @returns Promise that resolves with the encrypted string
|
|
33
|
+
*/
|
|
34
|
+
encryptString(text) {
|
|
35
|
+
const url = this.buildEncryptUrl(text);
|
|
36
|
+
return fetch(url).then((response) => {
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
throw new Error(`Error HTTP: ${response.status} - ${response.statusText}`);
|
|
39
|
+
}
|
|
40
|
+
return response.text();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Obtains an authentication token for accessing protected SIAR services
|
|
45
|
+
* This method performs the complete authentication process:
|
|
46
|
+
* 1. Encrypts the user identifier
|
|
47
|
+
* 2. Encrypts the password
|
|
48
|
+
* 3. Obtains the authentication token
|
|
49
|
+
*
|
|
50
|
+
* @param params Authentication parameters (userId and password)
|
|
51
|
+
* @returns Promise that resolves with the authentication token
|
|
52
|
+
*/
|
|
53
|
+
obtainToken(params) {
|
|
54
|
+
// Step 1: Encrypt the user identifier
|
|
55
|
+
return this.encryptString(params.userId)
|
|
56
|
+
.then((encryptedUser) =>
|
|
57
|
+
// Step 2: Encrypt the password
|
|
58
|
+
this.encryptString(params.password).then((encryptedPassword) => ({
|
|
59
|
+
encryptedUser,
|
|
60
|
+
encryptedPassword,
|
|
61
|
+
})))
|
|
62
|
+
.then(({ encryptedUser, encryptedPassword }) => {
|
|
63
|
+
// Step 3: Obtain the token
|
|
64
|
+
const url = this.buildTokenUrl(encryptedUser, encryptedPassword);
|
|
65
|
+
return fetch(url);
|
|
66
|
+
})
|
|
67
|
+
.then((response) => {
|
|
68
|
+
if (!response.ok) {
|
|
69
|
+
throw new Error(`Error HTTP: ${response.status} - ${response.statusText}`);
|
|
70
|
+
}
|
|
71
|
+
return response.text();
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=AuthenticationService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthenticationService.js","sourceRoot":"","sources":["../../../src/client/authentication/AuthenticationService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAGhC;;OAEG;IACH;QACE,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACK,eAAe,CAAC,IAAY;QAClC,OAAO,GAAG,IAAI,CAAC,OAAO,6CAA6C,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;IAChG,CAAC;IAED;;;;;OAKG;IACK,aAAa,CACnB,aAAqB,EACrB,iBAAyB;QAEzB,OAAO,GAAG,IAAI,CAAC,OAAO,8CAA8C,kBAAkB,CAAC,aAAa,CAAC,aAAa,kBAAkB,CAAC,iBAAiB,CAAC,EAAE,CAAC;IAC5J,CAAC;IAED;;;;OAIG;IACH,aAAa,CAAC,IAAY;QACxB,MAAM,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QACvC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;YAClC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CACb,eAAe,QAAQ,CAAC,MAAM,MAAM,QAAQ,CAAC,UAAU,EAAE,CAC1D,CAAC;YACJ,CAAC;YACD,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;QACzB,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;OASG;IACH,WAAW,CAAC,MAA4C;QACtD,sCAAsC;QACtC,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC;aACrC,IAAI,CAAC,CAAC,aAAa,EAAE,EAAE;QACtB,+BAA+B;QAC/B,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;YAC/D,aAAa;YACb,iBAAiB;SAClB,CAAC,CAAC,CACJ;aACA,IAAI,CAAC,CAAC,EAAE,aAAa,EAAE,iBAAiB,EAAE,EAAE,EAAE;YAC7C,2BAA2B;YAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,aAAa,CAAC,aAAa,EAAE,iBAAiB,CAAC,CAAC;YACjE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC,CAAC;aACD,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;YACjB,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CACb,eAAe,QAAQ,CAAC,MAAM,MAAM,QAAQ,CAAC,UAAU,EAAE,CAC1D,CAAC;YACJ,CAAC;YACD,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;QACzB,CAAC,CAAC,CAAC;IACP,CAAC;CACF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const { BASE_URL } = require('../../internal/Consts.js');
|
|
1
2
|
const { mapDatoHorarioToHourlyData, mapDatoDiarioToDailyData, mapDatoSemanalToWeeklyData, mapDatoMensualToMonthlyData, } = require('../../mappers/Mappers.js');
|
|
2
3
|
const { Scope, DataType, } = require('../../public/data/Models.js');
|
|
3
4
|
/**
|
|
@@ -9,8 +10,8 @@ exports.DataPetitionService = {
|
|
|
9
10
|
* @param apiKey Clave de cliente API de 50 caracteres
|
|
10
11
|
*/
|
|
11
12
|
constructor(apiKey) {
|
|
12
|
-
this.baseUrl = "https://servicio.mapama.gob.es/apisiar/API/v1/Datos";
|
|
13
13
|
this.apiKey = apiKey;
|
|
14
|
+
this.baseUrl = BASE_URL + "/API/V1/Datos";
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
17
|
* Construye la URL completa para una petición de datos
|
|
@@ -20,7 +21,7 @@ exports.DataPetitionService = {
|
|
|
20
21
|
* @returns URL completa para la petición
|
|
21
22
|
*/
|
|
22
23
|
buildUrl(tipoDatos, ambito, params) {
|
|
23
|
-
const { ids, startDate, endDate, lastModifiedDate } = params;
|
|
24
|
+
const { ids, startDate, endDate, lastModifiedDate, calculatedData } = params;
|
|
24
25
|
// Construir la URL base con tipo de datos y ámbito
|
|
25
26
|
let url = `${this.baseUrl}/${tipoDatos}/${ambito}?`;
|
|
26
27
|
// Agregar los identificadores
|
|
@@ -29,11 +30,15 @@ exports.DataPetitionService = {
|
|
|
29
30
|
// Agregar fechas y clave API
|
|
30
31
|
url += `&FechaInicial=${startDate}`;
|
|
31
32
|
url += `&FechaFinal=${endDate}`;
|
|
32
|
-
url += `&
|
|
33
|
+
url += `&token=${this.apiKey}`;
|
|
33
34
|
// Agregar fecha de última modificación si está presente
|
|
34
35
|
if (lastModifiedDate) {
|
|
35
36
|
url += `&FechaUltModificacion=${lastModifiedDate}`;
|
|
36
37
|
}
|
|
38
|
+
// Agregar datos calculados si está presente
|
|
39
|
+
if (calculatedData !== undefined) {
|
|
40
|
+
url += `&DatosCalculados=${calculatedData}`;
|
|
41
|
+
}
|
|
37
42
|
return url;
|
|
38
43
|
}
|
|
39
44
|
/**
|
|
@@ -52,9 +57,10 @@ exports.DataPetitionService = {
|
|
|
52
57
|
Accept: "application/json",
|
|
53
58
|
},
|
|
54
59
|
});
|
|
60
|
+
const data = (await response.json());
|
|
55
61
|
if (!response.ok) {
|
|
56
62
|
return {
|
|
57
|
-
MensajeRespuesta:
|
|
63
|
+
MensajeRespuesta: data.MensajeRespuesta,
|
|
58
64
|
error: {
|
|
59
65
|
type: "http",
|
|
60
66
|
statusCode: response.status,
|
|
@@ -62,7 +68,6 @@ exports.DataPetitionService = {
|
|
|
62
68
|
},
|
|
63
69
|
};
|
|
64
70
|
}
|
|
65
|
-
const data = (await response.json());
|
|
66
71
|
return data;
|
|
67
72
|
}
|
|
68
73
|
catch (error) {
|
|
@@ -83,7 +88,13 @@ exports.DataPetitionService = {
|
|
|
83
88
|
*/
|
|
84
89
|
async fetchHourlyData(scope, params) {
|
|
85
90
|
const response = await this.fetchData(DataType.Hourly, scope, params);
|
|
86
|
-
|
|
91
|
+
// If there's no datos field, return only the message (error case)
|
|
92
|
+
if (!response.datos) {
|
|
93
|
+
return {
|
|
94
|
+
message: response.MensajeRespuesta,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const mappedData = response.datos.map(mapDatoHorarioToHourlyData);
|
|
87
98
|
return {
|
|
88
99
|
data: mappedData,
|
|
89
100
|
message: response.MensajeRespuesta,
|
|
@@ -97,7 +108,13 @@ exports.DataPetitionService = {
|
|
|
97
108
|
*/
|
|
98
109
|
async fetchDailyData(ambito, params) {
|
|
99
110
|
const response = await this.fetchData(DataType.Daily, ambito, params);
|
|
100
|
-
|
|
111
|
+
// If there's no datos field, return only the message (error case)
|
|
112
|
+
if (!response.datos) {
|
|
113
|
+
return {
|
|
114
|
+
message: response.MensajeRespuesta,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const mappedData = response.datos.map(mapDatoDiarioToDailyData);
|
|
101
118
|
return {
|
|
102
119
|
data: mappedData,
|
|
103
120
|
message: response.MensajeRespuesta,
|
|
@@ -111,7 +128,13 @@ exports.DataPetitionService = {
|
|
|
111
128
|
*/
|
|
112
129
|
async fetchWeeklyData(ambito, params) {
|
|
113
130
|
const response = await this.fetchData(DataType.Weekly, ambito, params);
|
|
114
|
-
|
|
131
|
+
// If there's no datos field, return only the message (error case)
|
|
132
|
+
if (!response.datos) {
|
|
133
|
+
return {
|
|
134
|
+
message: response.MensajeRespuesta,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
const mappedData = response.datos.map(mapDatoSemanalToWeeklyData);
|
|
115
138
|
return {
|
|
116
139
|
data: mappedData,
|
|
117
140
|
message: response.MensajeRespuesta,
|
|
@@ -125,7 +148,13 @@ exports.DataPetitionService = {
|
|
|
125
148
|
*/
|
|
126
149
|
async fetchMonthlyData(ambito, params) {
|
|
127
150
|
const response = await this.fetchData(DataType.Monthly, ambito, params);
|
|
128
|
-
|
|
151
|
+
// If there's no datos field, return only the message (error case)
|
|
152
|
+
if (!response.datos) {
|
|
153
|
+
return {
|
|
154
|
+
message: response.MensajeRespuesta,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const mappedData = response.datos.map(mapDatoMensualToMonthlyData);
|
|
129
158
|
return {
|
|
130
159
|
data: mappedData,
|
|
131
160
|
message: response.MensajeRespuesta,
|
|
@@ -12,6 +12,8 @@ export interface DataPetitionParams {
|
|
|
12
12
|
endDate: string;
|
|
13
13
|
/** OPCIONAL: Fecha de última modificación en formato AAAA-MM-DD */
|
|
14
14
|
lastModifiedDate?: string;
|
|
15
|
+
/** OPCIONAL: Indica si se deben mostrar las variables calculadas (solo para Diarios, Semanales y Mensuales) */
|
|
16
|
+
calculatedData?: boolean;
|
|
15
17
|
}
|
|
16
18
|
/**
|
|
17
19
|
* Servicio para realizar peticiones de datos a la Web API SIAR
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataService.d.ts","sourceRoot":"","sources":["../../../src/client/data/DataService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DataService.d.ts","sourceRoot":"","sources":["../../../src/client/data/DataService.ts"],"names":[],"mappings":"AAcA,OAAO,EACL,KAAK,EAEL,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,WAAW,EACjB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,0DAA0D;IAC1D,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,0CAA0C;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,wCAAwC;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,+GAA+G;IAC/G,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;GAEG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAS;IAEvB;;;OAGG;gBACS,MAAM,EAAE,MAAM;IAK1B;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ;IAiChB;;;;;;OAMG;YACW,SAAS;IAwCvB;;;;;OAKG;IACG,eAAe,CACnB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,eAAe,CAAC,UAAU,EAAE,CAAC,CAAC;IAsBzC;;;;;OAKG;IACG,cAAc,CAClB,MAAM,EAAE,KAAK,EACb,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,eAAe,CAAC,SAAS,EAAE,CAAC,CAAC;IAsBxC;;;;;OAKG;IACG,eAAe,CACnB,MAAM,EAAE,KAAK,EACb,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,eAAe,CAAC,UAAU,EAAE,CAAC,CAAC;IAsBzC;;;;;OAKG;IACG,gBAAgB,CACpB,MAAM,EAAE,KAAK,EACb,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,eAAe,CAAC,WAAW,EAAE,CAAC,CAAC;CAqB3C"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BASE_URL } from "../../internal/Consts.js";
|
|
1
2
|
import { mapDatoHorarioToHourlyData, mapDatoDiarioToDailyData, mapDatoSemanalToWeeklyData, mapDatoMensualToMonthlyData, } from "../../mappers/Mappers.js";
|
|
2
3
|
import { Scope, DataType, } from "../../public/data/Models.js";
|
|
3
4
|
/**
|
|
@@ -9,8 +10,8 @@ export class DataPetitionService {
|
|
|
9
10
|
* @param apiKey Clave de cliente API de 50 caracteres
|
|
10
11
|
*/
|
|
11
12
|
constructor(apiKey) {
|
|
12
|
-
this.baseUrl = "https://servicio.mapama.gob.es/apisiar/API/v1/Datos";
|
|
13
13
|
this.apiKey = apiKey;
|
|
14
|
+
this.baseUrl = BASE_URL + "/API/V1/Datos";
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
17
|
* Construye la URL completa para una petición de datos
|
|
@@ -20,7 +21,7 @@ export class DataPetitionService {
|
|
|
20
21
|
* @returns URL completa para la petición
|
|
21
22
|
*/
|
|
22
23
|
buildUrl(tipoDatos, ambito, params) {
|
|
23
|
-
const { ids, startDate, endDate, lastModifiedDate } = params;
|
|
24
|
+
const { ids, startDate, endDate, lastModifiedDate, calculatedData } = params;
|
|
24
25
|
// Construir la URL base con tipo de datos y ámbito
|
|
25
26
|
let url = `${this.baseUrl}/${tipoDatos}/${ambito}?`;
|
|
26
27
|
// Agregar los identificadores
|
|
@@ -29,11 +30,15 @@ export class DataPetitionService {
|
|
|
29
30
|
// Agregar fechas y clave API
|
|
30
31
|
url += `&FechaInicial=${startDate}`;
|
|
31
32
|
url += `&FechaFinal=${endDate}`;
|
|
32
|
-
url += `&
|
|
33
|
+
url += `&token=${this.apiKey}`;
|
|
33
34
|
// Agregar fecha de última modificación si está presente
|
|
34
35
|
if (lastModifiedDate) {
|
|
35
36
|
url += `&FechaUltModificacion=${lastModifiedDate}`;
|
|
36
37
|
}
|
|
38
|
+
// Agregar datos calculados si está presente
|
|
39
|
+
if (calculatedData !== undefined) {
|
|
40
|
+
url += `&DatosCalculados=${calculatedData}`;
|
|
41
|
+
}
|
|
37
42
|
return url;
|
|
38
43
|
}
|
|
39
44
|
/**
|
|
@@ -52,9 +57,10 @@ export class DataPetitionService {
|
|
|
52
57
|
Accept: "application/json",
|
|
53
58
|
},
|
|
54
59
|
});
|
|
60
|
+
const data = (await response.json());
|
|
55
61
|
if (!response.ok) {
|
|
56
62
|
return {
|
|
57
|
-
MensajeRespuesta:
|
|
63
|
+
MensajeRespuesta: data.MensajeRespuesta,
|
|
58
64
|
error: {
|
|
59
65
|
type: "http",
|
|
60
66
|
statusCode: response.status,
|
|
@@ -62,7 +68,6 @@ export class DataPetitionService {
|
|
|
62
68
|
},
|
|
63
69
|
};
|
|
64
70
|
}
|
|
65
|
-
const data = (await response.json());
|
|
66
71
|
return data;
|
|
67
72
|
}
|
|
68
73
|
catch (error) {
|
|
@@ -83,7 +88,13 @@ export class DataPetitionService {
|
|
|
83
88
|
*/
|
|
84
89
|
async fetchHourlyData(scope, params) {
|
|
85
90
|
const response = await this.fetchData(DataType.Hourly, scope, params);
|
|
86
|
-
|
|
91
|
+
// If there's no datos field, return only the message (error case)
|
|
92
|
+
if (!response.datos) {
|
|
93
|
+
return {
|
|
94
|
+
message: response.MensajeRespuesta,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const mappedData = response.datos.map(mapDatoHorarioToHourlyData);
|
|
87
98
|
return {
|
|
88
99
|
data: mappedData,
|
|
89
100
|
message: response.MensajeRespuesta,
|
|
@@ -97,7 +108,13 @@ export class DataPetitionService {
|
|
|
97
108
|
*/
|
|
98
109
|
async fetchDailyData(ambito, params) {
|
|
99
110
|
const response = await this.fetchData(DataType.Daily, ambito, params);
|
|
100
|
-
|
|
111
|
+
// If there's no datos field, return only the message (error case)
|
|
112
|
+
if (!response.datos) {
|
|
113
|
+
return {
|
|
114
|
+
message: response.MensajeRespuesta,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const mappedData = response.datos.map(mapDatoDiarioToDailyData);
|
|
101
118
|
return {
|
|
102
119
|
data: mappedData,
|
|
103
120
|
message: response.MensajeRespuesta,
|
|
@@ -111,7 +128,13 @@ export class DataPetitionService {
|
|
|
111
128
|
*/
|
|
112
129
|
async fetchWeeklyData(ambito, params) {
|
|
113
130
|
const response = await this.fetchData(DataType.Weekly, ambito, params);
|
|
114
|
-
|
|
131
|
+
// If there's no datos field, return only the message (error case)
|
|
132
|
+
if (!response.datos) {
|
|
133
|
+
return {
|
|
134
|
+
message: response.MensajeRespuesta,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
const mappedData = response.datos.map(mapDatoSemanalToWeeklyData);
|
|
115
138
|
return {
|
|
116
139
|
data: mappedData,
|
|
117
140
|
message: response.MensajeRespuesta,
|
|
@@ -125,7 +148,13 @@ export class DataPetitionService {
|
|
|
125
148
|
*/
|
|
126
149
|
async fetchMonthlyData(ambito, params) {
|
|
127
150
|
const response = await this.fetchData(DataType.Monthly, ambito, params);
|
|
128
|
-
|
|
151
|
+
// If there's no datos field, return only the message (error case)
|
|
152
|
+
if (!response.datos) {
|
|
153
|
+
return {
|
|
154
|
+
message: response.MensajeRespuesta,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const mappedData = response.datos.map(mapDatoMensualToMonthlyData);
|
|
129
158
|
return {
|
|
130
159
|
data: mappedData,
|
|
131
160
|
message: response.MensajeRespuesta,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataService.js","sourceRoot":"","sources":["../../../src/client/data/DataService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DataService.js","sourceRoot":"","sources":["../../../src/client/data/DataService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAQpD,OAAO,EACL,0BAA0B,EAC1B,wBAAwB,EACxB,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,KAAK,EACL,QAAQ,GAKT,MAAM,6BAA6B,CAAC;AAmBrC;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAI9B;;;OAGG;IACH,YAAY,MAAc;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,QAAQ,GAAG,eAAe,CAAC;IAC5C,CAAC;IAED;;;;;;OAMG;IACK,QAAQ,CACd,SAAmB,EACnB,MAAa,EACb,MAA0B;QAE1B,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,gBAAgB,EAAE,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ChB,OAAO,EAAE,QAAQ,CAAC,gBAAgB;SACnC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
const {
|
|
2
|
-
const {
|
|
1
|
+
const { BASE_URL } = require('../../internal/Consts.js');
|
|
2
|
+
const { mapCCAA, mapProvincia, mapEstacion, mapInformacionAccesos, mapCodigoValidacion, } = require('../../mappers/Mappers.js');
|
|
3
|
+
const { InformationCategory, } = require('../../public/information/Models.js');
|
|
3
4
|
/**
|
|
4
5
|
* Servicio para obtener información de permisos y accesos en la Web API SIAR
|
|
5
6
|
*/
|
|
@@ -9,24 +10,25 @@ exports.InformationService = {
|
|
|
9
10
|
* @param apiKey Clave de cliente API de 50 caracteres
|
|
10
11
|
*/
|
|
11
12
|
constructor(apiKey) {
|
|
12
|
-
this.baseUrl = "https://servicio.mapama.gob.es/apisiar/API/v1/Info";
|
|
13
13
|
this.apiKey = apiKey;
|
|
14
|
+
this.baseUrl = BASE_URL + "/API/V1/Info";
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
17
|
* Construye la URL completa para una petición de información
|
|
17
|
-
* @param
|
|
18
|
+
* @param informationCategory Tipo de información a solicitar
|
|
18
19
|
* @returns URL completa para la petición
|
|
19
20
|
*/
|
|
20
|
-
buildUrl(
|
|
21
|
-
return `${this.baseUrl}/${
|
|
21
|
+
buildUrl(informationCategory) {
|
|
22
|
+
return `${this.baseUrl}/${informationCategory}?token=${this.apiKey}`;
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
25
|
* Realiza una petición de información a la API
|
|
25
|
-
* @param
|
|
26
|
+
* @param informationCategory Tipo de información a solicitar
|
|
26
27
|
* @returns Promesa con la respuesta de la API
|
|
27
28
|
*/
|
|
28
|
-
async fetchInformation(
|
|
29
|
-
const url = this.buildUrl(
|
|
29
|
+
async fetchInformation(informationCategory) {
|
|
30
|
+
const url = this.buildUrl(informationCategory);
|
|
31
|
+
console.log(`Fetching information from URL: ${url}`);
|
|
30
32
|
try {
|
|
31
33
|
const response = await fetch(url, {
|
|
32
34
|
method: "GET",
|
|
@@ -34,17 +36,18 @@ exports.InformationService = {
|
|
|
34
36
|
Accept: "application/json",
|
|
35
37
|
},
|
|
36
38
|
});
|
|
39
|
+
const data = (await response.json());
|
|
37
40
|
if (!response.ok) {
|
|
41
|
+
console.error(`HTTP error! status: ${response.status} - ${response.statusText}`);
|
|
38
42
|
return {
|
|
39
|
-
MensajeRespuesta:
|
|
43
|
+
MensajeRespuesta: data.MensajeRespuesta,
|
|
40
44
|
error: {
|
|
41
45
|
type: "http",
|
|
42
46
|
statusCode: response.status,
|
|
43
|
-
details: `HTTP error! status: ${response.status}`,
|
|
47
|
+
details: `HTTP error! status: ${response.status} - ${response.statusText}`,
|
|
44
48
|
},
|
|
45
49
|
};
|
|
46
50
|
}
|
|
47
|
-
const data = (await response.json());
|
|
48
51
|
return data;
|
|
49
52
|
}
|
|
50
53
|
catch (error) {
|
|
@@ -63,8 +66,14 @@ exports.InformationService = {
|
|
|
63
66
|
* @returns Promesa con la lista de comunidades autónomas
|
|
64
67
|
*/
|
|
65
68
|
async fetchAutonomousCommunities() {
|
|
66
|
-
const response = await this.fetchInformation(
|
|
67
|
-
|
|
69
|
+
const response = await this.fetchInformation(InformationCategory.AutonomousCommunity);
|
|
70
|
+
// If there's no datos field, return only the message (error case)
|
|
71
|
+
if (!response.datos) {
|
|
72
|
+
return {
|
|
73
|
+
message: response.MensajeRespuesta,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const mappedData = response.datos.map(mapCCAA);
|
|
68
77
|
return {
|
|
69
78
|
data: mappedData,
|
|
70
79
|
message: response.MensajeRespuesta,
|
|
@@ -76,8 +85,14 @@ exports.InformationService = {
|
|
|
76
85
|
* @returns Promesa con la lista de provincias
|
|
77
86
|
*/
|
|
78
87
|
async fetchProvinces() {
|
|
79
|
-
const response = await this.fetchInformation(
|
|
80
|
-
|
|
88
|
+
const response = await this.fetchInformation(InformationCategory.Province);
|
|
89
|
+
// If there's no datos field, return only the message (error case)
|
|
90
|
+
if (!response.datos) {
|
|
91
|
+
return {
|
|
92
|
+
message: response.MensajeRespuesta,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
const mappedData = response.datos.map(mapProvincia);
|
|
81
96
|
return {
|
|
82
97
|
data: mappedData,
|
|
83
98
|
message: response.MensajeRespuesta,
|
|
@@ -89,8 +104,14 @@ exports.InformationService = {
|
|
|
89
104
|
* @returns Promesa con la lista de estaciones
|
|
90
105
|
*/
|
|
91
106
|
async fetchStations() {
|
|
92
|
-
const response = await this.fetchInformation(
|
|
93
|
-
|
|
107
|
+
const response = await this.fetchInformation(InformationCategory.Station);
|
|
108
|
+
// If there's no datos field, return only the message (error case)
|
|
109
|
+
if (!response.datos) {
|
|
110
|
+
return {
|
|
111
|
+
message: response.MensajeRespuesta,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
const mappedData = response.datos.map(mapEstacion);
|
|
94
115
|
return {
|
|
95
116
|
data: mappedData,
|
|
96
117
|
message: response.MensajeRespuesta,
|
|
@@ -103,19 +124,32 @@ exports.InformationService = {
|
|
|
103
124
|
* @returns Promesa con la información de accesos
|
|
104
125
|
*/
|
|
105
126
|
async fetchAccessData() {
|
|
106
|
-
const response = await this.fetchInformation(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
maxAccessesPerMinute: 0,
|
|
112
|
-
accessesCurrentDay: 0,
|
|
113
|
-
maxAccessesPerDay: 0,
|
|
114
|
-
recordsCurrentMinute: 0,
|
|
115
|
-
maxRecordsPerMinute: 0,
|
|
116
|
-
recordsCurrentDay: 0,
|
|
117
|
-
maxRecordsPerDay: 0,
|
|
127
|
+
const response = await this.fetchInformation(InformationCategory.Access);
|
|
128
|
+
// If there's no datos field, return only the message (error case)
|
|
129
|
+
if (!response.datos) {
|
|
130
|
+
return {
|
|
131
|
+
message: response.MensajeRespuesta,
|
|
118
132
|
};
|
|
133
|
+
}
|
|
134
|
+
const mappedData = mapInformacionAccesos(response.datos);
|
|
135
|
+
return {
|
|
136
|
+
data: mappedData,
|
|
137
|
+
message: response.MensajeRespuesta,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Obtiene la descripción de los códigos de validación
|
|
142
|
+
* @returns Promesa con la lista de códigos de validación
|
|
143
|
+
*/
|
|
144
|
+
async fetchValidationCodes() {
|
|
145
|
+
const response = await this.fetchInformation(InformationCategory.ValidationCode);
|
|
146
|
+
// If there's no datos field, return only the message (error case)
|
|
147
|
+
if (!response.datos) {
|
|
148
|
+
return {
|
|
149
|
+
message: response.MensajeRespuesta,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
const mappedData = response.datos.map(mapCodigoValidacion);
|
|
119
153
|
return {
|
|
120
154
|
data: mappedData,
|
|
121
155
|
message: response.MensajeRespuesta,
|