bcchapi 1.0.8 → 2.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/CHANGELOG.md +10 -42
- package/LICENSE +18 -4
- package/README.md +83 -91
- package/dist/client/client.d.ts +60 -0
- package/dist/client/client.d.ts.map +1 -0
- package/dist/client/client.js +126 -0
- package/dist/client/client.js.map +1 -0
- package/dist/client/index.d.ts +4 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +3 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/types.d.ts +136 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +53 -0
- package/dist/client/types.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/series/index.d.ts +2 -0
- package/dist/series/index.d.ts.map +1 -0
- package/dist/series/index.js +2 -0
- package/dist/series/index.js.map +1 -0
- package/dist/series/series.d.ts +213 -0
- package/dist/series/series.d.ts.map +1 -0
- package/dist/series/series.js +213 -0
- package/dist/series/series.js.map +1 -0
- package/dist/utils/dates.d.ts +30 -0
- package/dist/utils/dates.d.ts.map +1 -0
- package/dist/utils/dates.js +67 -0
- package/dist/utils/dates.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/stats.d.ts +112 -0
- package/dist/utils/stats.d.ts.map +1 -0
- package/dist/utils/stats.js +185 -0
- package/dist/utils/stats.js.map +1 -0
- package/dist/utils/transform.d.ts +79 -0
- package/dist/utils/transform.d.ts.map +1 -0
- package/dist/utils/transform.js +101 -0
- package/dist/utils/transform.js.map +1 -0
- package/package.json +62 -40
- package/.eslintignore +0 -3
- package/.eslintrc.json +0 -21
- package/.github/workflows/npm-publish.yml +0 -38
- package/.prettierrc.json +0 -17
- package/.vscode/extensions.json +0 -3
- package/.vscode/settings.json +0 -4
- package/src/client.ts +0 -109
- package/src/errors.ts +0 -36
- package/src/handlers.ts +0 -69
- package/src/index.ts +0 -8
- package/src/types.ts +0 -115
- package/src/utils.ts +0 -37
- package/test/client.test.ts +0 -226
- package/test/fixtures/index.ts +0 -15
- package/test/fixtures/responses/credentials.invalid.json +0 -11
- package/test/fixtures/responses/getseries.invalid.json +0 -11
- package/test/fixtures/responses/getseries.success.json +0 -87
- package/test/fixtures/responses/searchseries.invalid.json +0 -11
- package/test/fixtures/responses/searchseries.success.json +0 -22
- package/test/handlers/handle-get-series.test.ts +0 -45
- package/test/handlers/handle-search-series.test.ts +0 -48
- package/test/mocks/fetch.mock.ts +0 -76
- package/test/utils/is-valid-date.test.ts +0 -17
- package/test/utils/reverse-date.test.ts +0 -11
- package/tsconfig.eslint.json +0 -5
- package/tsconfig.json +0 -9
- package/vitest.config.mts +0 -9
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"Codigo": 0,
|
|
3
|
-
"Descripcion": "Success",
|
|
4
|
-
"Series": {
|
|
5
|
-
"seriesId": "TEST",
|
|
6
|
-
"descripEsp": "Test",
|
|
7
|
-
"descripIng": "Test",
|
|
8
|
-
"Obs": [
|
|
9
|
-
{
|
|
10
|
-
"indexDateString": "01-12-2020",
|
|
11
|
-
"value": "12.01",
|
|
12
|
-
"statusCode": "OK"
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
"indexDateString": "02-12-2020",
|
|
16
|
-
"value": "12.02",
|
|
17
|
-
"statusCode": "OK"
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
"indexDateString": "03-12-2020",
|
|
21
|
-
"value": "12.03",
|
|
22
|
-
"statusCode": "OK"
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
"indexDateString": "04-12-2020",
|
|
26
|
-
"value": "12.04",
|
|
27
|
-
"statusCode": "OK"
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
"indexDateString": "05-12-2020",
|
|
31
|
-
"value": "NaN",
|
|
32
|
-
"statusCode": "ND"
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
"indexDateString": "06-12-2020",
|
|
36
|
-
"value": "NaN",
|
|
37
|
-
"statusCode": "ND"
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
"indexDateString": "07-12-2020",
|
|
41
|
-
"value": "12.07",
|
|
42
|
-
"statusCode": "OK"
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
"indexDateString": "08-12-2020",
|
|
46
|
-
"value": "NaN",
|
|
47
|
-
"statusCode": "ND"
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
"indexDateString": "09-12-2020",
|
|
51
|
-
"value": "12.09",
|
|
52
|
-
"statusCode": "OK"
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
"indexDateString": "10-12-2020",
|
|
56
|
-
"value": "12.10",
|
|
57
|
-
"statusCode": "OK"
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
"indexDateString": "11-12-2020",
|
|
61
|
-
"value": "12.11",
|
|
62
|
-
"statusCode": "OK"
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
"indexDateString": "12-12-2020",
|
|
66
|
-
"value": "NaN",
|
|
67
|
-
"statusCode": "ND"
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
"indexDateString": "13-12-2020",
|
|
71
|
-
"value": "NaN",
|
|
72
|
-
"statusCode": "ND"
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
"indexDateString": "14-12-2020",
|
|
76
|
-
"value": "12.14",
|
|
77
|
-
"statusCode": "OK"
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
"indexDateString": "15-12-2020",
|
|
81
|
-
"value": "12.15",
|
|
82
|
-
"statusCode": "OK"
|
|
83
|
-
}
|
|
84
|
-
]
|
|
85
|
-
},
|
|
86
|
-
"SeriesInfo": []
|
|
87
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"Codigo": 0,
|
|
3
|
-
"Descripcion": "Success",
|
|
4
|
-
"Series": {
|
|
5
|
-
"descripEsp": null,
|
|
6
|
-
"descripIng": null,
|
|
7
|
-
"seriesId": null,
|
|
8
|
-
"Obs": null
|
|
9
|
-
},
|
|
10
|
-
"SeriesInfos": [
|
|
11
|
-
{
|
|
12
|
-
"seriesId": "TEST",
|
|
13
|
-
"frequencyCode": "DAILY",
|
|
14
|
-
"spanishTitle": "Test",
|
|
15
|
-
"englishTitle": "Test",
|
|
16
|
-
"firstObservation": "01-12-2020",
|
|
17
|
-
"lastObservation": "15-12-2020",
|
|
18
|
-
"updatedAt": "19-01-2024",
|
|
19
|
-
"createdAt": "19-01-2024"
|
|
20
|
-
}
|
|
21
|
-
]
|
|
22
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import * as Errors from '../../src/errors';
|
|
3
|
-
import { handleGetSeriesResponse } from '../../src/handlers';
|
|
4
|
-
import { ApiResponse } from '../../src/types';
|
|
5
|
-
import fixtures from '../fixtures';
|
|
6
|
-
|
|
7
|
-
describe('handleGetSeriesResponse', () => {
|
|
8
|
-
it('should parse correctly a valid response', () => {
|
|
9
|
-
const parsed = handleGetSeriesResponse(
|
|
10
|
-
fixtures.response.getSeriesSuccess as unknown as ApiResponse,
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
expect(parsed).toBeDefined();
|
|
14
|
-
expect(parsed.seriesId).toBe(fixtures.response.getSeriesSuccess.Series.seriesId);
|
|
15
|
-
expect(parsed.description).toBe(fixtures.response.getSeriesSuccess.Series.descripIng);
|
|
16
|
-
expect(parsed.data).toHaveLength(fixtures.response.getSeriesSuccess.Series.Obs.length);
|
|
17
|
-
|
|
18
|
-
for (let i = 0; i < parsed.data.length; i += 1) {
|
|
19
|
-
expect(parsed.data[i].date).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
|
20
|
-
expect(parsed.data[i].value.toFixed(2)).toBe(
|
|
21
|
-
fixtures.response.getSeriesSuccess.Series.Obs[i].value,
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
if (Number.isNaN(parsed.data[i].value)) {
|
|
25
|
-
expect(fixtures.response.getSeriesSuccess.Series.Obs[i].statusCode).toBe('ND');
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('should throw an InvalidCredentialsError if the response code is -5', () => {
|
|
31
|
-
expect(() =>
|
|
32
|
-
handleGetSeriesResponse(fixtures.response.credentialsInvalid as unknown as ApiResponse),
|
|
33
|
-
).toThrow(Errors.InvalidCredentialsError);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should throw an InvalidSeriesError if the response code is -50', () => {
|
|
37
|
-
expect(() =>
|
|
38
|
-
handleGetSeriesResponse(fixtures.response.getSeriesInvalid as unknown as ApiResponse),
|
|
39
|
-
).toThrow(Errors.InvalidSeriesError);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should throw a ResponseError if the response code is unknown', () => {
|
|
43
|
-
expect(() => handleGetSeriesResponse({} as ApiResponse)).toThrow(Errors.WebServiceError);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import * as Errors from '../../src/errors';
|
|
3
|
-
import { ApiResponse } from '../../src/types';
|
|
4
|
-
import { handleSearchSeriesResponse } from '../../src/handlers';
|
|
5
|
-
import fixtures from '../fixtures';
|
|
6
|
-
|
|
7
|
-
describe('handleSearchSeriesResponse', () => {
|
|
8
|
-
it('should parse correctly a valid response', () => {
|
|
9
|
-
const parsed = handleSearchSeriesResponse(
|
|
10
|
-
fixtures.response.searchSeriesSuccess as unknown as ApiResponse,
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
expect(parsed).toBeInstanceOf(Array);
|
|
14
|
-
expect(parsed).toHaveLength(fixtures.response.searchSeriesSuccess.SeriesInfos.length);
|
|
15
|
-
|
|
16
|
-
for (let i = 0; i < parsed.length; i += 1) {
|
|
17
|
-
expect(parsed[i].seriesId).toBe(
|
|
18
|
-
fixtures.response.searchSeriesSuccess.SeriesInfos[i].seriesId,
|
|
19
|
-
);
|
|
20
|
-
expect(parsed[i].frequency).toBe(
|
|
21
|
-
fixtures.response.searchSeriesSuccess.SeriesInfos[i].frequencyCode,
|
|
22
|
-
);
|
|
23
|
-
expect(parsed[i].title).toBe(
|
|
24
|
-
fixtures.response.searchSeriesSuccess.SeriesInfos[i].englishTitle,
|
|
25
|
-
);
|
|
26
|
-
expect(parsed[i].firstObservedAt).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
|
27
|
-
expect(parsed[i].lastObservedAt).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
|
28
|
-
expect(parsed[i].updatedAt).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
|
29
|
-
expect(parsed[i].createdAt).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('should throw an InvalidCredentialsError if the response code is -5', () => {
|
|
34
|
-
expect(() =>
|
|
35
|
-
handleSearchSeriesResponse(fixtures.response.credentialsInvalid as unknown as ApiResponse),
|
|
36
|
-
).toThrow(Errors.InvalidCredentialsError);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('should throw an InvalidFrequencyError if the response code is -1', () => {
|
|
40
|
-
expect(() =>
|
|
41
|
-
handleSearchSeriesResponse(fixtures.response.searchSeriesInvalid as unknown as ApiResponse),
|
|
42
|
-
).toThrow(Errors.InvalidFrequencyError);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('should throw a ResponseError if the response code is unknown', () => {
|
|
46
|
-
expect(() => handleSearchSeriesResponse({} as ApiResponse)).toThrow(Errors.WebServiceError);
|
|
47
|
-
});
|
|
48
|
-
});
|
package/test/mocks/fetch.mock.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { Frequency } from '../../src/client';
|
|
2
|
-
import { reverseDate } from '../../src/utils';
|
|
3
|
-
import fixtures from '../fixtures';
|
|
4
|
-
|
|
5
|
-
export default (input: string | URL | Request) => {
|
|
6
|
-
const params = new URL(input.toString()).searchParams;
|
|
7
|
-
const func = params.get('function') || 'GetSeries';
|
|
8
|
-
|
|
9
|
-
if (params.get('user') !== 'test' || params.get('pass') !== 'test') {
|
|
10
|
-
return Promise.resolve({
|
|
11
|
-
json: () => Promise.resolve(fixtures.response.credentialsInvalid),
|
|
12
|
-
} as Response);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (func === 'GetSeries') {
|
|
16
|
-
if (fixtures.response.getSeriesSuccess.Series.seriesId !== params.get('timeseries')) {
|
|
17
|
-
return Promise.resolve({
|
|
18
|
-
json: () => Promise.resolve(fixtures.response.getSeriesInvalid),
|
|
19
|
-
} as Response);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const firstDate = params.get('firstdate');
|
|
23
|
-
const lastDate = params.get('lastdate');
|
|
24
|
-
const obs = fixtures.response.getSeriesSuccess.Series.Obs.filter((o) => {
|
|
25
|
-
if (firstDate && lastDate) {
|
|
26
|
-
return (
|
|
27
|
-
reverseDate(o.indexDateString) >= firstDate && reverseDate(o.indexDateString) <= lastDate
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
if (firstDate) {
|
|
31
|
-
return reverseDate(o.indexDateString) >= firstDate;
|
|
32
|
-
}
|
|
33
|
-
if (lastDate) {
|
|
34
|
-
return reverseDate(o.indexDateString) <= lastDate;
|
|
35
|
-
}
|
|
36
|
-
return true;
|
|
37
|
-
});
|
|
38
|
-
const series = {
|
|
39
|
-
...fixtures.response.getSeriesSuccess.Series,
|
|
40
|
-
Obs: obs,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return Promise.resolve({
|
|
44
|
-
json: () =>
|
|
45
|
-
Promise.resolve({
|
|
46
|
-
...fixtures.response.getSeriesSuccess,
|
|
47
|
-
Series: series,
|
|
48
|
-
}),
|
|
49
|
-
} as Response);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (func === 'SearchSeries') {
|
|
53
|
-
const frequency = params.get('frequency');
|
|
54
|
-
|
|
55
|
-
if (!Object.values(Frequency).includes(frequency as Frequency)) {
|
|
56
|
-
return Promise.resolve({
|
|
57
|
-
json: () => Promise.resolve(fixtures.response.searchSeriesInvalid),
|
|
58
|
-
} as Response);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const response = {
|
|
62
|
-
...fixtures.response.searchSeriesSuccess,
|
|
63
|
-
SeriesInfo: fixtures.response.searchSeriesSuccess.SeriesInfos.filter(
|
|
64
|
-
(series) => series.frequencyCode === frequency,
|
|
65
|
-
),
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
return Promise.resolve({
|
|
69
|
-
json: () => Promise.resolve(response),
|
|
70
|
-
} as Response);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return Promise.resolve({
|
|
74
|
-
json: () => Promise.resolve({}),
|
|
75
|
-
} as Response);
|
|
76
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { isValidDate } from '../../src/utils';
|
|
3
|
-
|
|
4
|
-
describe('isValidDate', () => {
|
|
5
|
-
it('should return true if the date is valid', () => {
|
|
6
|
-
expect(isValidDate('2020-01-01')).toBe(true);
|
|
7
|
-
expect(isValidDate(new Date())).toBe(true);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('should return false if the date is invalid', () => {
|
|
11
|
-
expect(isValidDate('invalid')).toBe(false);
|
|
12
|
-
expect(isValidDate({})).toBe(false);
|
|
13
|
-
expect(isValidDate(undefined)).toBe(false);
|
|
14
|
-
expect(isValidDate(null)).toBe(false);
|
|
15
|
-
expect(isValidDate(new Date('invalid'))).toBe(false);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { reverseDate } from '../../src/utils';
|
|
3
|
-
|
|
4
|
-
describe('reverseDate', () => {
|
|
5
|
-
it('should reverse correctly a date in DD-MM-YYYY format', () => {
|
|
6
|
-
const date = '01-02-2020';
|
|
7
|
-
const reversed = reverseDate(date);
|
|
8
|
-
|
|
9
|
-
expect(reversed).toBe('2020-02-01');
|
|
10
|
-
});
|
|
11
|
-
});
|
package/tsconfig.eslint.json
DELETED
package/tsconfig.json
DELETED