bcchapi 1.0.3 → 1.0.5
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 +27 -0
- package/dist/client.js +5 -9
- package/dist/types.d.ts +5 -6
- package/dist/utils.d.ts +17 -0
- package/dist/{helpers/parsers.js → utils.js} +37 -15
- package/package.json +10 -10
- package/dist/helpers/is-valid-date.d.ts +0 -1
- package/dist/helpers/is-valid-date.js +0 -12
- package/dist/helpers/parsers.d.ts +0 -3
- package/dist/helpers/reverse-date.d.ts +0 -1
- package/dist/helpers/reverse-date.js +0 -6
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [1.0.5] - 2024-04-24
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- This CHANGELOG file to document changes to the project.
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Updated the following dependencies:
|
|
19
|
+
- `@tsconfig/node20` from `20.1.2` to `20.1.4`
|
|
20
|
+
- `@types/node` from `20.11.5` to `2.12.7`
|
|
21
|
+
- `@typescript-eslint/eslint-plugin` from `6.19.0` to `6.21.0`
|
|
22
|
+
- `@typescript-eslint/parser` from `6.19.0` to `6.21.0`
|
|
23
|
+
- `@vitest/coverage-v8` from `1.2.1` to `1.5.1`
|
|
24
|
+
- `eslint` from `8.56.0` to `8.57.0`
|
|
25
|
+
- `prettier` from `3.2.4` to `3.2.5`
|
|
26
|
+
- `typescript` from `5.3.3` to `5.4.5`
|
|
27
|
+
- `vitest` from `1.2.1` to `1.5.1`
|
package/dist/client.js
CHANGED
|
@@ -22,15 +22,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
26
|
exports.Client = exports.Frequency = void 0;
|
|
30
27
|
const querystring = __importStar(require("node:querystring"));
|
|
31
28
|
const assert = __importStar(require("node:assert/strict"));
|
|
32
|
-
const
|
|
33
|
-
const is_valid_date_1 = __importDefault(require("./helpers/is-valid-date"));
|
|
29
|
+
const utils_1 = require("./utils");
|
|
34
30
|
var Frequency;
|
|
35
31
|
(function (Frequency) {
|
|
36
32
|
Frequency["Daily"] = "DAILY";
|
|
@@ -65,17 +61,17 @@ class Client {
|
|
|
65
61
|
function: 'GetSeries',
|
|
66
62
|
};
|
|
67
63
|
if (since) {
|
|
68
|
-
assert.ok((0,
|
|
64
|
+
assert.ok((0, utils_1.isValidDate)(since), '"since" is not a valid date string or Date object');
|
|
69
65
|
query.firstdate = typeof since === 'string' ? since : since.toISOString().slice(0, 10);
|
|
70
66
|
}
|
|
71
67
|
if (until) {
|
|
72
|
-
assert.ok((0,
|
|
68
|
+
assert.ok((0, utils_1.isValidDate)(until), '"until" is not a valid date string or Date object');
|
|
73
69
|
query.lastdate = typeof until === 'string' ? until : until.toISOString().slice(0, 10);
|
|
74
70
|
}
|
|
75
71
|
if (query.firstdate && query.lastdate) {
|
|
76
72
|
assert.ok(query.firstdate <= query.lastdate, 'invalid date range');
|
|
77
73
|
}
|
|
78
|
-
return this.request(query).then(
|
|
74
|
+
return this.request(query).then(utils_1.parseGetSeriesResponse);
|
|
79
75
|
}
|
|
80
76
|
/**
|
|
81
77
|
* Fetches the list of available series by frequency and their metadata.
|
|
@@ -87,7 +83,7 @@ class Client {
|
|
|
87
83
|
frequency,
|
|
88
84
|
function: 'SearchSeries',
|
|
89
85
|
};
|
|
90
|
-
return this.request(query).then(
|
|
86
|
+
return this.request(query).then(utils_1.parseSearchSeriesResponse);
|
|
91
87
|
}
|
|
92
88
|
}
|
|
93
89
|
exports.Client = Client;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
interface
|
|
1
|
+
export interface SeriesObservation {
|
|
2
2
|
/**
|
|
3
3
|
* Series observed date in DD-MM-YYYY format.
|
|
4
4
|
*/
|
|
@@ -12,7 +12,7 @@ interface SeriesValue {
|
|
|
12
12
|
*/
|
|
13
13
|
statusCode: 'OK' | 'ND';
|
|
14
14
|
}
|
|
15
|
-
interface SeriesHistory {
|
|
15
|
+
export interface SeriesHistory {
|
|
16
16
|
/**
|
|
17
17
|
* Series identifier.
|
|
18
18
|
*/
|
|
@@ -28,12 +28,12 @@ interface SeriesHistory {
|
|
|
28
28
|
/**
|
|
29
29
|
* List of series observed values.
|
|
30
30
|
*/
|
|
31
|
-
Obs:
|
|
31
|
+
Obs: SeriesObservation[];
|
|
32
32
|
}
|
|
33
|
-
type NullSeries = {
|
|
33
|
+
export type NullSeries = {
|
|
34
34
|
[key in keyof SeriesHistory]: null;
|
|
35
35
|
};
|
|
36
|
-
interface SeriesMetadata {
|
|
36
|
+
export interface SeriesMetadata {
|
|
37
37
|
/**
|
|
38
38
|
* Series identifier.
|
|
39
39
|
*/
|
|
@@ -106,4 +106,3 @@ export type SearchSeriesResponse = ReadonlyArray<{
|
|
|
106
106
|
updatedAt: string;
|
|
107
107
|
createdAt: string;
|
|
108
108
|
}>;
|
|
109
|
-
export {};
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ApiResponse, GetSeriesResponse, SearchSeriesResponse } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Determines wether a given value can be parsed to a valid date.
|
|
4
|
+
*/
|
|
5
|
+
export declare function isValidDate(date: unknown): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Reverses a date string from DD-MM-YYYY to YYYY-MM-DD format.
|
|
8
|
+
*/
|
|
9
|
+
export declare function reverseDate(date: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Parses the GetSeries function API response.
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseGetSeriesResponse<T extends ApiResponse>(response: T): GetSeriesResponse;
|
|
14
|
+
/**
|
|
15
|
+
* Parses the SearchSeries function API response.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseSearchSeriesResponse<T extends ApiResponse>(response: T): SearchSeriesResponse;
|
|
@@ -1,18 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.parseSearchSeriesResponse = exports.parseGetSeriesResponse = void 0;
|
|
7
|
-
const
|
|
8
|
-
|
|
3
|
+
exports.parseSearchSeriesResponse = exports.parseGetSeriesResponse = exports.reverseDate = exports.isValidDate = void 0;
|
|
4
|
+
const errors_1 = require("./errors");
|
|
5
|
+
/**
|
|
6
|
+
* Determines wether a given value can be parsed to a valid date.
|
|
7
|
+
*/
|
|
8
|
+
function isValidDate(date) {
|
|
9
|
+
if (typeof date === 'string') {
|
|
10
|
+
return !Number.isNaN(Date.parse(date));
|
|
11
|
+
}
|
|
12
|
+
if (date instanceof Date) {
|
|
13
|
+
return !Number.isNaN(date.getTime());
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
exports.isValidDate = isValidDate;
|
|
18
|
+
/**
|
|
19
|
+
* Reverses a date string from DD-MM-YYYY to YYYY-MM-DD format.
|
|
20
|
+
*/
|
|
21
|
+
function reverseDate(date) {
|
|
22
|
+
return date.split('-').reverse().join('-');
|
|
23
|
+
}
|
|
24
|
+
exports.reverseDate = reverseDate;
|
|
25
|
+
/**
|
|
26
|
+
* Parses the GetSeries function API response.
|
|
27
|
+
*/
|
|
9
28
|
function parseGetSeriesResponse(response) {
|
|
10
29
|
if (response.Codigo !== 0) {
|
|
11
30
|
switch (response.Codigo) {
|
|
12
31
|
case errors_1.ErrorCodes.InvalidCredentials:
|
|
13
|
-
throw new errors_1.InvalidCredentialsError();
|
|
32
|
+
throw new errors_1.InvalidCredentialsError(response);
|
|
14
33
|
case errors_1.ErrorCodes.InvalidSeries:
|
|
15
|
-
throw new errors_1.InvalidSeriesError();
|
|
34
|
+
throw new errors_1.InvalidSeriesError(response);
|
|
16
35
|
default:
|
|
17
36
|
throw new errors_1.WebServiceError(response);
|
|
18
37
|
}
|
|
@@ -21,19 +40,22 @@ function parseGetSeriesResponse(response) {
|
|
|
21
40
|
seriesId: response.Series.seriesId || '',
|
|
22
41
|
description: response.Series.descripIng || '',
|
|
23
42
|
data: (response.Series.Obs || []).map((obs) => ({
|
|
24
|
-
date: (
|
|
43
|
+
date: reverseDate(obs.indexDateString),
|
|
25
44
|
value: parseFloat(obs.value),
|
|
26
45
|
})),
|
|
27
46
|
};
|
|
28
47
|
}
|
|
29
48
|
exports.parseGetSeriesResponse = parseGetSeriesResponse;
|
|
49
|
+
/**
|
|
50
|
+
* Parses the SearchSeries function API response.
|
|
51
|
+
*/
|
|
30
52
|
function parseSearchSeriesResponse(response) {
|
|
31
53
|
if (response.Codigo !== 0) {
|
|
32
54
|
switch (response.Codigo) {
|
|
33
55
|
case errors_1.ErrorCodes.InvalidCredentials:
|
|
34
|
-
throw new errors_1.InvalidCredentialsError();
|
|
56
|
+
throw new errors_1.InvalidCredentialsError(response);
|
|
35
57
|
case errors_1.ErrorCodes.InvalidFrequency:
|
|
36
|
-
throw new errors_1.InvalidFrequencyError();
|
|
58
|
+
throw new errors_1.InvalidFrequencyError(response);
|
|
37
59
|
default:
|
|
38
60
|
throw new errors_1.WebServiceError(response);
|
|
39
61
|
}
|
|
@@ -42,10 +64,10 @@ function parseSearchSeriesResponse(response) {
|
|
|
42
64
|
seriesId: series.seriesId,
|
|
43
65
|
frequency: series.frequencyCode,
|
|
44
66
|
title: series.englishTitle,
|
|
45
|
-
firstObservedAt: (
|
|
46
|
-
lastObservedAt: (
|
|
47
|
-
updatedAt: (
|
|
48
|
-
createdAt: (
|
|
67
|
+
firstObservedAt: reverseDate(series.firstObservation),
|
|
68
|
+
lastObservedAt: reverseDate(series.lastObservation),
|
|
69
|
+
updatedAt: reverseDate(series.updatedAt),
|
|
70
|
+
createdAt: reverseDate(series.createdAt),
|
|
49
71
|
}));
|
|
50
72
|
}
|
|
51
73
|
exports.parseSearchSeriesResponse = parseSearchSeriesResponse;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bcchapi",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "API para acceder al Web Service del Banco Central de Chile.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -28,19 +28,19 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/airarrazaval/bcchapi#readme",
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@tsconfig/node20": "^20.1.
|
|
32
|
-
"@types/node": "^20.
|
|
33
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
34
|
-
"@typescript-eslint/parser": "^6.
|
|
35
|
-
"@vitest/coverage-v8": "^1.
|
|
36
|
-
"eslint": "^8.
|
|
31
|
+
"@tsconfig/node20": "^20.1.4",
|
|
32
|
+
"@types/node": "^20.12.7",
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
34
|
+
"@typescript-eslint/parser": "^6.21.0",
|
|
35
|
+
"@vitest/coverage-v8": "^1.5.1",
|
|
36
|
+
"eslint": "^8.57.0",
|
|
37
37
|
"eslint-config-prettier": "^9.1.0",
|
|
38
38
|
"eslint-plugin-import": "^2.29.1",
|
|
39
|
-
"prettier": "^3.2.
|
|
39
|
+
"prettier": "^3.2.5",
|
|
40
40
|
"rimraf": "^5.0.5",
|
|
41
41
|
"ts-node": "^10.9.2",
|
|
42
|
-
"typescript": "^5.
|
|
43
|
-
"vitest": "^1.
|
|
42
|
+
"typescript": "^5.4.5",
|
|
43
|
+
"vitest": "^1.5.1"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=18.19.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function isValidDate(date: unknown): boolean;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function isValidDate(date) {
|
|
4
|
-
if (typeof date === 'string') {
|
|
5
|
-
return !Number.isNaN(Date.parse(date));
|
|
6
|
-
}
|
|
7
|
-
if (date instanceof Date) {
|
|
8
|
-
return !Number.isNaN(date.getTime());
|
|
9
|
-
}
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
exports.default = isValidDate;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { ApiResponse, GetSeriesResponse, SearchSeriesResponse } from '../types';
|
|
2
|
-
export declare function parseGetSeriesResponse<T extends ApiResponse>(response: T): GetSeriesResponse;
|
|
3
|
-
export declare function parseSearchSeriesResponse<T extends ApiResponse>(response: T): SearchSeriesResponse;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function reverseDate(date: string): string;
|