siar-client 0.1.3 → 2.2.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/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 +7 -6
- package/dist/client/data/DataService.d.ts.map +1 -1
- package/dist/client/data/DataService.js +7 -6
- package/dist/client/data/DataService.js.map +1 -1
- package/dist/client/information/InformationService.cjs +34 -19
- 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 +34 -19
- 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/information/Models.d.ts +47 -30
- package/dist/internal/information/Models.d.ts.map +1 -1
- package/dist/mappers/Mappers.cjs +15 -2
- package/dist/mappers/Mappers.d.ts +6 -2
- package/dist/mappers/Mappers.d.ts.map +1 -1
- package/dist/mappers/Mappers.js +15 -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/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;A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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
|
|
@@ -29,7 +30,7 @@ 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}`;
|
|
@@ -83,7 +84,7 @@ exports.DataPetitionService = {
|
|
|
83
84
|
*/
|
|
84
85
|
async fetchHourlyData(scope, params) {
|
|
85
86
|
const response = await this.fetchData(DataType.Hourly, scope, params);
|
|
86
|
-
const mappedData = response.
|
|
87
|
+
const mappedData = response.datos?.map(mapDatoHorarioToHourlyData) ?? [];
|
|
87
88
|
return {
|
|
88
89
|
data: mappedData,
|
|
89
90
|
message: response.MensajeRespuesta,
|
|
@@ -97,7 +98,7 @@ exports.DataPetitionService = {
|
|
|
97
98
|
*/
|
|
98
99
|
async fetchDailyData(ambito, params) {
|
|
99
100
|
const response = await this.fetchData(DataType.Daily, ambito, params);
|
|
100
|
-
const mappedData = response.
|
|
101
|
+
const mappedData = response.datos?.map(mapDatoDiarioToDailyData) ?? [];
|
|
101
102
|
return {
|
|
102
103
|
data: mappedData,
|
|
103
104
|
message: response.MensajeRespuesta,
|
|
@@ -111,7 +112,7 @@ exports.DataPetitionService = {
|
|
|
111
112
|
*/
|
|
112
113
|
async fetchWeeklyData(ambito, params) {
|
|
113
114
|
const response = await this.fetchData(DataType.Weekly, ambito, params);
|
|
114
|
-
const mappedData = response.
|
|
115
|
+
const mappedData = response.datos?.map(mapDatoSemanalToWeeklyData) ?? [];
|
|
115
116
|
return {
|
|
116
117
|
data: mappedData,
|
|
117
118
|
message: response.MensajeRespuesta,
|
|
@@ -125,7 +126,7 @@ exports.DataPetitionService = {
|
|
|
125
126
|
*/
|
|
126
127
|
async fetchMonthlyData(ambito, params) {
|
|
127
128
|
const response = await this.fetchData(DataType.Monthly, ambito, params);
|
|
128
|
-
const mappedData = response.
|
|
129
|
+
const mappedData = response.datos?.map(mapDatoMensualToMonthlyData) ?? [];
|
|
129
130
|
return {
|
|
130
131
|
data: mappedData,
|
|
131
132
|
message: response.MensajeRespuesta,
|
|
@@ -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;CAC3B;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;IA2BhB;;;;;;OAMG;YACW,SAAS;IAwCvB;;;;;OAKG;IACG,eAAe,CACnB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,eAAe,CAAC,UAAU,EAAE,CAAC,CAAC;IAezC;;;;;OAKG;IACG,cAAc,CAClB,MAAM,EAAE,KAAK,EACb,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,eAAe,CAAC,SAAS,EAAE,CAAC,CAAC;IAexC;;;;;OAKG;IACG,eAAe,CACnB,MAAM,EAAE,KAAK,EACb,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,eAAe,CAAC,UAAU,EAAE,CAAC,CAAC;IAezC;;;;;OAKG;IACG,gBAAgB,CACpB,MAAM,EAAE,KAAK,EACb,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,eAAe,CAAC,WAAW,EAAE,CAAC,CAAC;CAc3C"}
|
|
@@ -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
|
|
@@ -29,7 +30,7 @@ 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}`;
|
|
@@ -83,7 +84,7 @@ export class DataPetitionService {
|
|
|
83
84
|
*/
|
|
84
85
|
async fetchHourlyData(scope, params) {
|
|
85
86
|
const response = await this.fetchData(DataType.Hourly, scope, params);
|
|
86
|
-
const mappedData = response.
|
|
87
|
+
const mappedData = response.datos?.map(mapDatoHorarioToHourlyData) ?? [];
|
|
87
88
|
return {
|
|
88
89
|
data: mappedData,
|
|
89
90
|
message: response.MensajeRespuesta,
|
|
@@ -97,7 +98,7 @@ export class DataPetitionService {
|
|
|
97
98
|
*/
|
|
98
99
|
async fetchDailyData(ambito, params) {
|
|
99
100
|
const response = await this.fetchData(DataType.Daily, ambito, params);
|
|
100
|
-
const mappedData = response.
|
|
101
|
+
const mappedData = response.datos?.map(mapDatoDiarioToDailyData) ?? [];
|
|
101
102
|
return {
|
|
102
103
|
data: mappedData,
|
|
103
104
|
message: response.MensajeRespuesta,
|
|
@@ -111,7 +112,7 @@ export class DataPetitionService {
|
|
|
111
112
|
*/
|
|
112
113
|
async fetchWeeklyData(ambito, params) {
|
|
113
114
|
const response = await this.fetchData(DataType.Weekly, ambito, params);
|
|
114
|
-
const mappedData = response.
|
|
115
|
+
const mappedData = response.datos?.map(mapDatoSemanalToWeeklyData) ?? [];
|
|
115
116
|
return {
|
|
116
117
|
data: mappedData,
|
|
117
118
|
message: response.MensajeRespuesta,
|
|
@@ -125,7 +126,7 @@ export class DataPetitionService {
|
|
|
125
126
|
*/
|
|
126
127
|
async fetchMonthlyData(ambito, params) {
|
|
127
128
|
const response = await this.fetchData(DataType.Monthly, ambito, params);
|
|
128
|
-
const mappedData = response.
|
|
129
|
+
const mappedData = response.datos?.map(mapDatoMensualToMonthlyData) ?? [];
|
|
129
130
|
return {
|
|
130
131
|
data: mappedData,
|
|
131
132
|
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;A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AAC,KAAK,EACd,MAAM,EACN,MAAM,CACP,CAAC;QAEF,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,wBAAwB,CAAC,IAAI,EAAE,CAAC;QAEvE,OAAO;YACL,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE,QAAQ,CAAC,gBAAgB;SACnC,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,eAAe,CACnB,MAAa,EACb,MAA0B;QAE1B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,SAAS,CACnC,QAAQ,CAAC,MAAM,EACf,MAAM,EACN,MAAM,CACP,CAAC;QAEF,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,0BAA0B,CAAC,IAAI,EAAE,CAAC;QAEzE,OAAO;YACL,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE,QAAQ,CAAC,gBAAgB;SACnC,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,gBAAgB,CACpB,MAAa,EACb,MAA0B;QAE1B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,SAAS,CACnC,QAAQ,CAAC,OAAO,EAChB,MAAM,EACN,MAAM,CACP,CAAC;QAEF,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,2BAA2B,CAAC,IAAI,EAAE,CAAC;QAE1E,OAAO;YACL,IAAI,EAAE,UAAU;YAChB,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",
|
|
@@ -35,12 +37,13 @@ exports.InformationService = {
|
|
|
35
37
|
},
|
|
36
38
|
});
|
|
37
39
|
if (!response.ok) {
|
|
40
|
+
console.error(`HTTP error! status: ${response.status} - ${response.statusText}`);
|
|
38
41
|
return {
|
|
39
42
|
MensajeRespuesta: null,
|
|
40
43
|
error: {
|
|
41
44
|
type: "http",
|
|
42
45
|
statusCode: response.status,
|
|
43
|
-
details: `HTTP error! status: ${response.status}`,
|
|
46
|
+
details: `HTTP error! status: ${response.status} - ${response.statusText}`,
|
|
44
47
|
},
|
|
45
48
|
};
|
|
46
49
|
}
|
|
@@ -63,8 +66,8 @@ 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
|
-
const mappedData = response.
|
|
69
|
+
const response = await this.fetchInformation(InformationCategory.AutonomousCommunity);
|
|
70
|
+
const mappedData = response.datos?.map(mapCCAA) ?? [];
|
|
68
71
|
return {
|
|
69
72
|
data: mappedData,
|
|
70
73
|
message: response.MensajeRespuesta,
|
|
@@ -76,8 +79,8 @@ exports.InformationService = {
|
|
|
76
79
|
* @returns Promesa con la lista de provincias
|
|
77
80
|
*/
|
|
78
81
|
async fetchProvinces() {
|
|
79
|
-
const response = await this.fetchInformation(
|
|
80
|
-
const mappedData = response.
|
|
82
|
+
const response = await this.fetchInformation(InformationCategory.Province);
|
|
83
|
+
const mappedData = response.datos?.map(mapProvincia) ?? [];
|
|
81
84
|
return {
|
|
82
85
|
data: mappedData,
|
|
83
86
|
message: response.MensajeRespuesta,
|
|
@@ -89,8 +92,8 @@ exports.InformationService = {
|
|
|
89
92
|
* @returns Promesa con la lista de estaciones
|
|
90
93
|
*/
|
|
91
94
|
async fetchStations() {
|
|
92
|
-
const response = await this.fetchInformation(
|
|
93
|
-
const mappedData = response.
|
|
95
|
+
const response = await this.fetchInformation(InformationCategory.Station);
|
|
96
|
+
const mappedData = response.datos?.map(mapEstacion) ?? [];
|
|
94
97
|
return {
|
|
95
98
|
data: mappedData,
|
|
96
99
|
message: response.MensajeRespuesta,
|
|
@@ -103,9 +106,9 @@ exports.InformationService = {
|
|
|
103
106
|
* @returns Promesa con la información de accesos
|
|
104
107
|
*/
|
|
105
108
|
async fetchAccessData() {
|
|
106
|
-
const response = await this.fetchInformation(
|
|
107
|
-
const mappedData = response.
|
|
108
|
-
? mapInformacionAccesos(response.
|
|
109
|
+
const response = await this.fetchInformation(InformationCategory.Access);
|
|
110
|
+
const mappedData = response.datos
|
|
111
|
+
? mapInformacionAccesos(response.datos)
|
|
109
112
|
: {
|
|
110
113
|
accessesCurrentMinute: 0,
|
|
111
114
|
maxAccessesPerMinute: 0,
|
|
@@ -121,5 +124,17 @@ exports.InformationService = {
|
|
|
121
124
|
message: response.MensajeRespuesta,
|
|
122
125
|
};
|
|
123
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Obtiene la descripción de los códigos de validación
|
|
129
|
+
* @returns Promesa con la lista de códigos de validación
|
|
130
|
+
*/
|
|
131
|
+
async fetchValidationCodes() {
|
|
132
|
+
const response = await this.fetchInformation(InformationCategory.ValidationCode);
|
|
133
|
+
const mappedData = response.datos?.map(mapCodigoValidacion) ?? [];
|
|
134
|
+
return {
|
|
135
|
+
data: mappedData,
|
|
136
|
+
message: response.MensajeRespuesta,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
124
139
|
}
|
|
125
140
|
//# sourceMappingURL=InformationService.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AutonomousCommunity, type Province, type Station, type AccessInformation } from "../../public/information/Models.js";
|
|
1
|
+
import { type AutonomousCommunity, type Province, type Station, type AccessInformation, type ValidationCode } from "../../public/information/Models.js";
|
|
2
2
|
import type { GeneralResponse } from "../../public/Models.js";
|
|
3
3
|
/**
|
|
4
4
|
* Servicio para obtener información de permisos y accesos en la Web API SIAR
|
|
@@ -13,13 +13,13 @@ export declare class InformationService {
|
|
|
13
13
|
constructor(apiKey: string);
|
|
14
14
|
/**
|
|
15
15
|
* Construye la URL completa para una petición de información
|
|
16
|
-
* @param
|
|
16
|
+
* @param informationCategory Tipo de información a solicitar
|
|
17
17
|
* @returns URL completa para la petición
|
|
18
18
|
*/
|
|
19
19
|
private buildUrl;
|
|
20
20
|
/**
|
|
21
21
|
* Realiza una petición de información a la API
|
|
22
|
-
* @param
|
|
22
|
+
* @param informationCategory Tipo de información a solicitar
|
|
23
23
|
* @returns Promesa con la respuesta de la API
|
|
24
24
|
*/
|
|
25
25
|
private fetchInformation;
|
|
@@ -48,5 +48,10 @@ export declare class InformationService {
|
|
|
48
48
|
* @returns Promesa con la información de accesos
|
|
49
49
|
*/
|
|
50
50
|
fetchAccessData(): Promise<GeneralResponse<AccessInformation>>;
|
|
51
|
+
/**
|
|
52
|
+
* Obtiene la descripción de los códigos de validación
|
|
53
|
+
* @returns Promesa con la lista de códigos de validación
|
|
54
|
+
*/
|
|
55
|
+
fetchValidationCodes(): Promise<GeneralResponse<ValidationCode[]>>;
|
|
51
56
|
}
|
|
52
57
|
//# sourceMappingURL=InformationService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InformationService.d.ts","sourceRoot":"","sources":["../../../src/client/information/InformationService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"InformationService.d.ts","sourceRoot":"","sources":["../../../src/client/information/InformationService.ts"],"names":[],"mappings":"AAgBA,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACpB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAS;IAEvB;;;OAGG;gBACS,MAAM,EAAE,MAAM;IAK1B;;;;OAIG;IACH,OAAO,CAAC,QAAQ;IAIhB;;;;OAIG;YACW,gBAAgB;IA0C9B;;;;OAIG;IACG,0BAA0B,IAAI,OAAO,CACzC,eAAe,CAAC,mBAAmB,EAAE,CAAC,CACvC;IAaD;;;;OAIG;IACG,cAAc,IAAI,OAAO,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC,CAAC;IAa5D;;;;OAIG;IACG,aAAa,IAAI,OAAO,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC,CAAC;IAa1D;;;;;OAKG;IACG,eAAe,IAAI,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC;IAwBpE;;;OAGG;IACG,oBAAoB,IAAI,OAAO,CAAC,eAAe,CAAC,cAAc,EAAE,CAAC,CAAC;CAYzE"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { BASE_URL } from "../../internal/Consts.js";
|
|
2
|
+
import { mapCCAA, mapProvincia, mapEstacion, mapInformacionAccesos, mapCodigoValidacion, } from "../../mappers/Mappers.js";
|
|
3
|
+
import { InformationCategory, } from "../../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 @@ export class 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",
|
|
@@ -35,12 +37,13 @@ export class InformationService {
|
|
|
35
37
|
},
|
|
36
38
|
});
|
|
37
39
|
if (!response.ok) {
|
|
40
|
+
console.error(`HTTP error! status: ${response.status} - ${response.statusText}`);
|
|
38
41
|
return {
|
|
39
42
|
MensajeRespuesta: null,
|
|
40
43
|
error: {
|
|
41
44
|
type: "http",
|
|
42
45
|
statusCode: response.status,
|
|
43
|
-
details: `HTTP error! status: ${response.status}`,
|
|
46
|
+
details: `HTTP error! status: ${response.status} - ${response.statusText}`,
|
|
44
47
|
},
|
|
45
48
|
};
|
|
46
49
|
}
|
|
@@ -63,8 +66,8 @@ export class 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
|
-
const mappedData = response.
|
|
69
|
+
const response = await this.fetchInformation(InformationCategory.AutonomousCommunity);
|
|
70
|
+
const mappedData = response.datos?.map(mapCCAA) ?? [];
|
|
68
71
|
return {
|
|
69
72
|
data: mappedData,
|
|
70
73
|
message: response.MensajeRespuesta,
|
|
@@ -76,8 +79,8 @@ export class InformationService {
|
|
|
76
79
|
* @returns Promesa con la lista de provincias
|
|
77
80
|
*/
|
|
78
81
|
async fetchProvinces() {
|
|
79
|
-
const response = await this.fetchInformation(
|
|
80
|
-
const mappedData = response.
|
|
82
|
+
const response = await this.fetchInformation(InformationCategory.Province);
|
|
83
|
+
const mappedData = response.datos?.map(mapProvincia) ?? [];
|
|
81
84
|
return {
|
|
82
85
|
data: mappedData,
|
|
83
86
|
message: response.MensajeRespuesta,
|
|
@@ -89,8 +92,8 @@ export class InformationService {
|
|
|
89
92
|
* @returns Promesa con la lista de estaciones
|
|
90
93
|
*/
|
|
91
94
|
async fetchStations() {
|
|
92
|
-
const response = await this.fetchInformation(
|
|
93
|
-
const mappedData = response.
|
|
95
|
+
const response = await this.fetchInformation(InformationCategory.Station);
|
|
96
|
+
const mappedData = response.datos?.map(mapEstacion) ?? [];
|
|
94
97
|
return {
|
|
95
98
|
data: mappedData,
|
|
96
99
|
message: response.MensajeRespuesta,
|
|
@@ -103,9 +106,9 @@ export class InformationService {
|
|
|
103
106
|
* @returns Promesa con la información de accesos
|
|
104
107
|
*/
|
|
105
108
|
async fetchAccessData() {
|
|
106
|
-
const response = await this.fetchInformation(
|
|
107
|
-
const mappedData = response.
|
|
108
|
-
? mapInformacionAccesos(response.
|
|
109
|
+
const response = await this.fetchInformation(InformationCategory.Access);
|
|
110
|
+
const mappedData = response.datos
|
|
111
|
+
? mapInformacionAccesos(response.datos)
|
|
109
112
|
: {
|
|
110
113
|
accessesCurrentMinute: 0,
|
|
111
114
|
maxAccessesPerMinute: 0,
|
|
@@ -121,5 +124,17 @@ export class InformationService {
|
|
|
121
124
|
message: response.MensajeRespuesta,
|
|
122
125
|
};
|
|
123
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Obtiene la descripción de los códigos de validación
|
|
129
|
+
* @returns Promesa con la lista de códigos de validación
|
|
130
|
+
*/
|
|
131
|
+
async fetchValidationCodes() {
|
|
132
|
+
const response = await this.fetchInformation(InformationCategory.ValidationCode);
|
|
133
|
+
const mappedData = response.datos?.map(mapCodigoValidacion) ?? [];
|
|
134
|
+
return {
|
|
135
|
+
data: mappedData,
|
|
136
|
+
message: response.MensajeRespuesta,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
124
139
|
}
|
|
125
140
|
//# sourceMappingURL=InformationService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InformationService.js","sourceRoot":"","sources":["../../../src/client/information/InformationService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"InformationService.js","sourceRoot":"","sources":["../../../src/client/information/InformationService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AASpD,OAAO,EACL,OAAO,EACP,YAAY,EACZ,WAAW,EACX,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,mBAAmB,GAMpB,MAAM,oCAAoC,CAAC;AAG5C;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAI7B;;;OAGG;IACH,YAAY,MAAc;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,QAAQ,GAAG,cAAc,CAAC;IAC3C,CAAC;IAED;;;;OAIG;IACK,QAAQ,CAAC,mBAAwC;QACvD,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,mBAAmB,UAAU,IAAI,CAAC,MAAM,EAAE,CAAC;IACvE,CAAC;IAED;;;;OAIG;IACK,KAAK,CAAC,gBAAgB,CAC5B,mBAAwC;QAExC,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;QAC/C,OAAO,CAAC,GAAG,CAAC,kCAAkC,GAAG,EAAE,CAAC,CAAC;QAErD,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;gBAChC,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE;oBACP,MAAM,EAAE,kBAAkB;iBAC3B;aACF,CAAC,CAAC;YAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,OAAO,CAAC,KAAK,CACX,uBAAuB,QAAQ,CAAC,MAAM,MAAM,QAAQ,CAAC,UAAU,EAAE,CAClE,CAAC;gBACF,OAAO;oBACL,gBAAgB,EAAE,IAAI;oBACtB,KAAK,EAAE;wBACL,IAAI,EAAE,MAAM;wBACZ,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