emissions-api-sdk 1.0.0 → 1.0.2
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/README.md +33 -2
- package/dist/Constants.js +23 -1
- package/dist/api/Calculation.js +78 -15
- package/dist/api/Factor.js +99 -18
- package/dist/api/FactorSets.js +1 -1
- package/dist/api/Fugitive.js +76 -13
- package/dist/api/Location.js +76 -15
- package/dist/api/Mobile.js +65 -1
- package/dist/api/Stationary.js +78 -15
- package/dist/api/TransportationAndDistribution.js +77 -14
- package/dist/coverage/clover.xml +191 -81
- package/dist/coverage/coverage-final.json +11 -11
- package/dist/coverage/lcov-report/index.html +16 -16
- package/dist/coverage/lcov-report/src/Client.ts.html +23 -23
- package/dist/coverage/lcov-report/src/Constants.ts.html +82 -4
- package/dist/coverage/lcov-report/src/api/Calculation.ts.html +245 -26
- package/dist/coverage/lcov-report/src/api/Factor.ts.html +313 -34
- package/dist/coverage/lcov-report/src/api/FactorSets.ts.html +8 -5
- package/dist/coverage/lcov-report/src/api/Fugitive.ts.html +246 -24
- package/dist/coverage/lcov-report/src/api/Location.ts.html +245 -26
- package/dist/coverage/lcov-report/src/api/Mobile.ts.html +240 -12
- package/dist/coverage/lcov-report/src/api/Stationary.ts.html +248 -26
- package/dist/coverage/lcov-report/src/api/TransportationAndDistribution.ts.html +250 -25
- package/dist/coverage/lcov-report/src/api/index.html +25 -25
- package/dist/coverage/lcov-report/src/index.html +7 -7
- package/dist/coverage/lcov-report/src/request.ts.html +1 -1
- package/dist/coverage/lcov-report/src/utils.ts.html +5 -5
- package/dist/coverage/lcov-report/test/index.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/CommonRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/FactorRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/GenericCalculationRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/LocationRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/SearchRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/index.html +1 -1
- package/dist/coverage/lcov-report/test/testUtils.ts.html +1 -1
- package/dist/coverage/lcov.info +287 -133
- package/dist/interfaces/response/AreaResponse.js +2 -0
- package/dist/interfaces/response/EmissionResponse.js +2 -0
- package/dist/interfaces/response/EmissionResponseWithDetails.js +2 -0
- package/dist/interfaces/response/FactorResponse.js +2 -0
- package/dist/interfaces/response/FactorSetResponse.js +2 -0
- package/dist/interfaces/response/SearchResponse.js +2 -0
- package/dist/interfaces/response/TypeResponse.js +2 -0
- package/dist/interfaces/response/UnitResponse.js +2 -0
- package/dist/types/Constants.d.ts +22 -0
- package/dist/types/api/Calculation.d.ts +59 -16
- package/dist/types/api/Factor.d.ts +73 -20
- package/dist/types/api/FactorSets.d.ts +3 -2
- package/dist/types/api/Fugitive.d.ts +57 -14
- package/dist/types/api/Location.d.ts +57 -16
- package/dist/types/api/Mobile.d.ts +46 -2
- package/dist/types/api/Stationary.d.ts +59 -16
- package/dist/types/api/TransportationAndDistribution.d.ts +58 -15
- package/dist/types/index.d.ts +8 -0
- package/dist/types/interfaces/response/AreaResponse.d.ts +20 -0
- package/dist/types/interfaces/response/EmissionResponse.d.ts +31 -0
- package/dist/types/interfaces/response/EmissionResponseWithDetails.d.ts +144 -0
- package/dist/types/interfaces/response/FactorResponse.d.ts +53 -0
- package/dist/types/interfaces/response/FactorSetResponse.d.ts +38 -0
- package/dist/types/interfaces/response/SearchResponse.d.ts +41 -0
- package/dist/types/interfaces/response/TypeResponse.d.ts +7 -0
- package/dist/types/interfaces/response/UnitResponse.d.ts +7 -0
- package/docs/.nojekyll +0 -0
- package/docs/_sources/authentication.rst.txt +164 -0
- package/docs/_sources/client.rst.txt +137 -0
- package/docs/_sources/getting_started.rst.txt +164 -0
- package/docs/_sources/index.rst.txt +30 -0
- package/docs/_sources/reference.rst.txt +129 -0
- package/docs/_sources/sdk.rst.txt +13 -0
- package/docs/_sources/troubleshooting.rst.txt +486 -0
- package/docs/_static/basic.css +914 -0
- package/docs/_static/custom.css +16 -0
- package/docs/_static/debug.css +69 -0
- package/docs/_static/doctools.js +149 -0
- package/docs/_static/documentation_options.js +13 -0
- package/docs/_static/file.png +0 -0
- package/docs/_static/language_data.js +192 -0
- package/docs/_static/minus.png +0 -0
- package/docs/_static/plus.png +0 -0
- package/docs/_static/pygments.css +232 -0
- package/docs/_static/scripts/furo-extensions.js +0 -0
- package/docs/_static/scripts/furo.js +3 -0
- package/docs/_static/scripts/furo.js.LICENSE.txt +7 -0
- package/docs/_static/scripts/furo.js.map +1 -0
- package/docs/_static/searchtools.js +632 -0
- package/docs/_static/skeleton.css +296 -0
- package/docs/_static/sphinx_highlight.js +154 -0
- package/docs/_static/sphinx_js.css +0 -0
- package/docs/_static/styles/furo-extensions.css +2 -0
- package/docs/_static/styles/furo-extensions.css.map +1 -0
- package/docs/_static/styles/furo.css +2 -0
- package/docs/_static/styles/furo.css.map +1 -0
- package/docs/authentication.html +523 -0
- package/docs/client.html +477 -0
- package/docs/genindex.html +492 -0
- package/docs/getting_started.html +491 -0
- package/docs/index.html +357 -0
- package/docs/objects.inv +0 -0
- package/docs/reference.html +1584 -0
- package/docs/sdk.html +334 -0
- package/docs/search.html +297 -0
- package/docs/searchindex.js +1 -0
- package/docs/troubleshooting.html +786 -0
- package/package.json +1 -1
- package/sphinx-build/Makefile +49 -0
- package/sphinx-build/requirements.txt +5 -0
- package/sphinx-build/source/_static/custom.css +16 -0
- package/sphinx-build/source/authentication.rst +164 -0
- package/sphinx-build/source/client.rst +137 -0
- package/sphinx-build/source/conf.py +56 -0
- package/sphinx-build/source/getting_started.rst +164 -0
- package/sphinx-build/source/index.rst +30 -0
- package/sphinx-build/source/reference.rst +129 -0
- package/sphinx-build/source/sdk.rst +13 -0
- package/sphinx-build/source/troubleshooting.rst +486 -0
- package/src/Constants.ts +26 -0
- package/src/api/Calculation.ts +94 -20
- package/src/api/Factor.ts +122 -28
- package/src/api/FactorSets.ts +4 -3
- package/src/api/Fugitive.ts +93 -18
- package/src/api/Location.ts +94 -20
- package/src/api/Mobile.ts +83 -6
- package/src/api/Stationary.ts +95 -20
- package/src/api/TransportationAndDistribution.ts +95 -19
- package/src/index.ts +33 -1
- package/src/interfaces/response/AreaResponse.ts +25 -0
- package/src/interfaces/response/EmissionResponse.ts +44 -0
- package/src/interfaces/response/EmissionResponseWithDetails.ts +183 -0
- package/src/interfaces/response/FactorResponse.ts +78 -0
- package/src/interfaces/response/FactorSetResponse.ts +52 -0
- package/src/interfaces/response/SearchResponse.ts +52 -0
- package/src/interfaces/response/TypeResponse.ts +7 -0
- package/src/interfaces/response/UnitResponse.ts +7 -0
- package/test/apiTest.test.ts +173 -6
- package/dist/api/Factors.js +0 -98
- package/dist/api/FugitiveEmission.js +0 -40
- package/dist/api/GenericCalculation.js +0 -41
- package/dist/api/LocationEmission.js +0 -41
- package/dist/api/MobileEmission.js +0 -41
- package/dist/api/StationaryEmission.js +0 -41
- package/dist/api/TransportationDistributionEmission.js +0 -40
- package/dist/coverage/lcov-report/src/api/Factors.ts.html +0 -403
- package/dist/coverage/lcov-report/src/api/FugitiveEmission.ts.html +0 -214
- package/dist/coverage/lcov-report/src/api/GenericCalculation.ts.html +0 -217
- package/dist/coverage/lcov-report/src/api/LocationEmission.ts.html +0 -214
- package/dist/coverage/lcov-report/src/api/MobileEmission.ts.html +0 -220
- package/dist/coverage/lcov-report/src/api/StationaryEmission.ts.html +0 -220
- package/dist/coverage/lcov-report/src/api/TransportationDistributionEmission.ts.html +0 -211
- package/dist/types/api/Factors.d.ts +0 -68
- package/dist/types/api/FugitiveEmission.d.ts +0 -27
- package/dist/types/api/GenericCalculation.d.ts +0 -28
- package/dist/types/api/LocationEmission.d.ts +0 -28
- package/dist/types/api/MobileEmission.d.ts +0 -28
- package/dist/types/api/StationaryEmission.d.ts +0 -28
- package/dist/types/api/TransportationDistributionEmission.d.ts +0 -27
package/src/api/Calculation.ts
CHANGED
|
@@ -1,44 +1,118 @@
|
|
|
1
1
|
import { Client } from "../Client";
|
|
2
|
-
import { GENERIC_CALCULATION_API_PATH, POST } from "../Constants";
|
|
2
|
+
import { GENERIC_CALCULATION_API_PATH,CALCULATION_TYPES, POST, GET, GENERAL_API_AREA, GENERAL_API_UNITS } from "../Constants";
|
|
3
3
|
import { CalculationRequest } from "../interfaces/Api";
|
|
4
|
+
import { AreaResponse } from "../interfaces/response/AreaResponse";
|
|
5
|
+
import { EmissionResponse } from "../interfaces/response/EmissionResponse";
|
|
6
|
+
import { EmissionResponseWithDetails } from "../interfaces/response/EmissionResponseWithDetails";
|
|
7
|
+
import { TypeResponse } from "../interfaces/response/TypeResponse";
|
|
8
|
+
import { UnitResponse } from "../interfaces/response/UnitResponse";
|
|
4
9
|
import { makeApiRequest } from "../request";
|
|
5
10
|
|
|
6
11
|
|
|
7
12
|
/**
|
|
8
13
|
* Performs emission calculations by making a POST request to the generic calculation API endpoint.
|
|
9
|
-
*
|
|
14
|
+
*
|
|
10
15
|
* @export
|
|
11
16
|
* @param {CalculationRequest} payload - The calculation request data to be sent to the API
|
|
12
|
-
* @return {Promise<
|
|
17
|
+
* @return {Promise<EmissionResponse | EmissionResponseWithDetails>} A promise that resolves to the emission calculation result. Returns EmissionResponseWithDetails if includeDetails is true, otherwise EmissionResponse
|
|
13
18
|
* @throws {Error} May throw an error if the API request fails
|
|
14
|
-
*
|
|
19
|
+
*
|
|
15
20
|
* @example
|
|
16
21
|
* const calculationRequest = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
"time" : {
|
|
23
|
+
"date": "2025-01-04"
|
|
24
|
+
},
|
|
25
|
+
"location": {
|
|
26
|
+
"country": "usa",
|
|
27
|
+
"stateProvince": "new york"
|
|
28
|
+
},
|
|
29
|
+
"activity": {
|
|
30
|
+
"type":"Waste Combusted - Steel Cans:Default factor",
|
|
31
|
+
"unit": "kg",
|
|
32
|
+
"value": 1223123.121
|
|
33
|
+
},
|
|
34
|
+
"includeDetails": true
|
|
35
|
+
};
|
|
31
36
|
* const result = await calculate(calculationRequest);
|
|
32
37
|
*/
|
|
33
38
|
export async function calculate(
|
|
34
39
|
payload: CalculationRequest
|
|
35
|
-
): Promise<
|
|
40
|
+
): Promise<EmissionResponse | EmissionResponseWithDetails> {
|
|
36
41
|
const client = Client.getInstance();
|
|
37
42
|
const url = client.getDomain() + GENERIC_CALCULATION_API_PATH;
|
|
38
43
|
|
|
39
|
-
return makeApiRequest<
|
|
44
|
+
return makeApiRequest<EmissionResponse | EmissionResponseWithDetails>({
|
|
40
45
|
method: POST,
|
|
41
46
|
url,
|
|
42
47
|
data: payload,
|
|
43
48
|
});
|
|
44
49
|
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves available calculation types by making a GET request to the calculation types API endpoint.
|
|
54
|
+
*
|
|
55
|
+
* @export
|
|
56
|
+
* @return {Promise<TypeResponse>} A promise that resolves to a TypeResponse containing the available calculation types
|
|
57
|
+
* @throws {Error} May throw an error if the API request fails
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* const types = await getTypes();
|
|
61
|
+
*/
|
|
62
|
+
export async function getTypes(): Promise<TypeResponse> {
|
|
63
|
+
const client = Client.getInstance();
|
|
64
|
+
const url = client.getDomain() + CALCULATION_TYPES;
|
|
65
|
+
|
|
66
|
+
return makeApiRequest<TypeResponse>({
|
|
67
|
+
method: GET,
|
|
68
|
+
url
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Retrieves information about geographical areas supported by the calculation API.
|
|
74
|
+
*
|
|
75
|
+
* @export
|
|
76
|
+
* @return {Promise<AreaResponse>} A promise that resolves to an AreaResponse containing the supported geographical areas
|
|
77
|
+
* @throws {Error} May throw an error if the API request fails
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* const areas = await getArea();
|
|
81
|
+
*/
|
|
82
|
+
export async function getArea(): Promise<AreaResponse> {
|
|
83
|
+
const client = Client.getInstance();
|
|
84
|
+
const url = client.getDomain() + GENERAL_API_AREA;
|
|
85
|
+
|
|
86
|
+
return makeApiRequest<AreaResponse>({
|
|
87
|
+
method: GET,
|
|
88
|
+
url
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Retrieves available units for a specific calculation type.
|
|
94
|
+
*
|
|
95
|
+
* @export
|
|
96
|
+
* @param {string} type - The calculation type to get units for
|
|
97
|
+
* @return {Promise<UnitResponse>} A promise that resolves to a UnitResponse containing the available units
|
|
98
|
+
* @throws {Error} May throw an error if the API request fails
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* // Get units for the "Natural Gas - Scope 3:AAA" emission calculation type with subtype
|
|
102
|
+
* const units = await getUnits("Natural Gas - Scope 3:AAA");
|
|
103
|
+
|
|
104
|
+
* // Get units for the "HFC-263fb" emission calculation type without subtype
|
|
105
|
+
* const units = await getUnits("HFC-263fb");
|
|
106
|
+
*/
|
|
107
|
+
export async function getUnits(
|
|
108
|
+
type: string
|
|
109
|
+
): Promise<UnitResponse> {
|
|
110
|
+
const client = Client.getInstance();
|
|
111
|
+
const url = client.getDomain() + GENERAL_API_UNITS;
|
|
112
|
+
|
|
113
|
+
return makeApiRequest<UnitResponse>({
|
|
114
|
+
method: GET,
|
|
115
|
+
url,
|
|
116
|
+
params : { type }
|
|
117
|
+
});
|
|
118
|
+
}
|
package/src/api/Factor.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { Client } from "../Client";
|
|
2
|
-
import { FACTOR_API_PATH, POST, SEARCH_API_PATH } from "../Constants";
|
|
2
|
+
import { FACTOR_API_AREA, FACTOR_API_PATH, FACTOR_API_TYPES, FACTOR_API_UNITS, GET, POST, SEARCH_API_AREA, SEARCH_API_PATH } from "../Constants";
|
|
3
3
|
import { FactorRequest, SearchRequest } from "../interfaces/Api";
|
|
4
|
+
import { AreaResponse } from "../interfaces/response/AreaResponse";
|
|
5
|
+
import { FactorResponse } from "../interfaces/response/FactorResponse";
|
|
6
|
+
import { SearchResponse } from "../interfaces/response/SearchResponse";
|
|
7
|
+
import { TypeResponse } from "../interfaces/response/TypeResponse";
|
|
8
|
+
import { UnitResponse } from "../interfaces/response/UnitResponse";
|
|
4
9
|
import { makeApiRequest } from "../request";
|
|
5
10
|
|
|
6
11
|
/**
|
|
@@ -8,42 +13,41 @@ import { makeApiRequest } from "../request";
|
|
|
8
13
|
*
|
|
9
14
|
* @export
|
|
10
15
|
* @param {FactorRequest} payload - The factor request data to be sent to the API
|
|
11
|
-
* @return {Promise<
|
|
16
|
+
* @return {Promise<FactorResponse>} A promise that resolves to the FactorResponse returned by the API
|
|
12
17
|
* @throws {Error} May throw an error if the API request fails
|
|
13
18
|
*
|
|
14
19
|
* @example
|
|
15
20
|
* const factorRequest = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
21
|
+
"activity": {
|
|
22
|
+
"factorId": 12345
|
|
23
|
+
}
|
|
20
24
|
};
|
|
21
25
|
|
|
22
|
-
|
|
26
|
+
OR
|
|
23
27
|
|
|
24
28
|
const factorRequest = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
"time" : {
|
|
30
|
+
"date": "2025-01-04"
|
|
31
|
+
},
|
|
32
|
+
"location": {
|
|
33
|
+
"country": "usa",
|
|
34
|
+
"stateProvince": "new york"
|
|
35
|
+
},
|
|
36
|
+
"activity": {
|
|
37
|
+
"type":"natural gas"
|
|
38
|
+
},
|
|
39
|
+
"includeDetails": true
|
|
40
|
+
};
|
|
37
41
|
* const factor = await retrieveFactor(factorRequest);
|
|
38
42
|
*/
|
|
39
43
|
|
|
40
44
|
export async function retrieveFactor(
|
|
41
45
|
payload: FactorRequest
|
|
42
|
-
): Promise<
|
|
46
|
+
): Promise<FactorResponse> {
|
|
43
47
|
const client = Client.getInstance();
|
|
44
48
|
const url = client.getDomain() + FACTOR_API_PATH;
|
|
45
49
|
|
|
46
|
-
return makeApiRequest<
|
|
50
|
+
return makeApiRequest<FactorResponse>({
|
|
47
51
|
method: POST,
|
|
48
52
|
url,
|
|
49
53
|
data: payload,
|
|
@@ -53,20 +57,20 @@ export async function retrieveFactor(
|
|
|
53
57
|
|
|
54
58
|
/**
|
|
55
59
|
* Performs a search operation by making a POST request to the search API endpoint.
|
|
56
|
-
*
|
|
60
|
+
*
|
|
57
61
|
* @export
|
|
58
62
|
* @param {SearchRequest} payload - The search request data to be sent to the API
|
|
59
|
-
* @return {Promise<
|
|
63
|
+
* @return {Promise<SearchResponse>} A promise that resolves to the search results returned by the API
|
|
60
64
|
* @throws {Error} May throw an error if the API request fails
|
|
61
|
-
*
|
|
65
|
+
*
|
|
62
66
|
* @example
|
|
63
|
-
* const searchRequest = {
|
|
67
|
+
* const searchRequest = {
|
|
64
68
|
"time":{
|
|
65
69
|
"date": "2020-06-10"
|
|
66
70
|
},
|
|
67
71
|
"activity": {
|
|
68
72
|
"search" : "travel"},
|
|
69
|
-
|
|
73
|
+
"location": {
|
|
70
74
|
"country": "USA"
|
|
71
75
|
}
|
|
72
76
|
};
|
|
@@ -74,13 +78,103 @@ export async function retrieveFactor(
|
|
|
74
78
|
*/
|
|
75
79
|
export async function search(
|
|
76
80
|
payload: SearchRequest
|
|
77
|
-
): Promise<
|
|
81
|
+
): Promise<SearchResponse> {
|
|
78
82
|
const client = Client.getInstance();
|
|
79
83
|
const url = client.getDomain() + SEARCH_API_PATH;
|
|
80
84
|
|
|
81
|
-
return makeApiRequest<
|
|
85
|
+
return makeApiRequest<SearchResponse>({
|
|
82
86
|
method: POST,
|
|
83
87
|
url,
|
|
84
88
|
data: payload,
|
|
85
89
|
});
|
|
86
90
|
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Retrieves available emission factor types by making a GET request to the API endpoint.
|
|
94
|
+
*
|
|
95
|
+
* @export
|
|
96
|
+
* @return {Promise<TypeResponse>} A promise that resolves to a TypeResponse containing the available emission factor types
|
|
97
|
+
* @throws {Error} May throw an error if the API request fails
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* const types = await getTypes();
|
|
101
|
+
*/
|
|
102
|
+
export async function getTypes(
|
|
103
|
+
): Promise<TypeResponse> {
|
|
104
|
+
const client = Client.getInstance();
|
|
105
|
+
const url = client.getDomain() + FACTOR_API_TYPES;
|
|
106
|
+
|
|
107
|
+
return makeApiRequest<TypeResponse>({
|
|
108
|
+
method: GET,
|
|
109
|
+
url
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Retrieves information about geographical areas supported by the factor search API.
|
|
115
|
+
*
|
|
116
|
+
* @export
|
|
117
|
+
* @return {Promise<AreaResponse>} A promise that resolves to an AreaResponse containing the supported geographical areas
|
|
118
|
+
* @throws {Error} May throw an error if the API request fails
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* const areas = await getSearchArea();
|
|
122
|
+
*/
|
|
123
|
+
export async function getSearchArea(
|
|
124
|
+
): Promise<AreaResponse> {
|
|
125
|
+
const client = Client.getInstance();
|
|
126
|
+
const url = client.getDomain() + SEARCH_API_AREA;
|
|
127
|
+
|
|
128
|
+
return makeApiRequest<AreaResponse>({
|
|
129
|
+
method: GET,
|
|
130
|
+
url
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Retrieves information about geographical areas supported by the factor API.
|
|
136
|
+
*
|
|
137
|
+
* @export
|
|
138
|
+
* @return {Promise<AreaResponse>} A promise that resolves to an AreaResponse containing the supported geographical areas
|
|
139
|
+
* @throws {Error} May throw an error if the API request fails
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* const areas = await getArea();
|
|
143
|
+
*/
|
|
144
|
+
export async function getArea(): Promise<AreaResponse> {
|
|
145
|
+
const client = Client.getInstance();
|
|
146
|
+
const url = client.getDomain() + FACTOR_API_AREA;
|
|
147
|
+
|
|
148
|
+
return makeApiRequest<AreaResponse>({
|
|
149
|
+
method: GET,
|
|
150
|
+
url
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Retrieves available units for a specific emission factor type.
|
|
156
|
+
*
|
|
157
|
+
* @export
|
|
158
|
+
* @param {string} type - The emission factor type to get units for (e.g., "Natural Gas - Scope 3:AAA")
|
|
159
|
+
* @return {Promise<UnitResponse>} A promise that resolves to a UnitResponse containing the available units
|
|
160
|
+
* @throws {Error} May throw an error if the API request fails
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* // Get units for the "Natural Gas - Scope 3:AAA" emission factor type with subtype
|
|
164
|
+
* const units = await getUnits("Natural Gas - Scope 3:AAA");
|
|
165
|
+
|
|
166
|
+
* // Get units for the "HFC-263fb" emission factor type without subtype
|
|
167
|
+
* const units = await getUnits("HFC-263fb");
|
|
168
|
+
*/
|
|
169
|
+
export async function getUnits(
|
|
170
|
+
type : string
|
|
171
|
+
): Promise<UnitResponse> {
|
|
172
|
+
const client = Client.getInstance();
|
|
173
|
+
const url = client.getDomain() + FACTOR_API_UNITS;
|
|
174
|
+
|
|
175
|
+
return makeApiRequest<UnitResponse>({
|
|
176
|
+
method: GET,
|
|
177
|
+
url,
|
|
178
|
+
params : { type }
|
|
179
|
+
});
|
|
180
|
+
}
|
package/src/api/FactorSets.ts
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import { Client } from "../Client";
|
|
2
2
|
import { FACTOR_SET_API_PATH, GET } from "../Constants";
|
|
3
|
+
import { FactorSetResponse } from "../interfaces/response/FactorSetResponse";
|
|
3
4
|
import { makeApiRequest } from "../request";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Retrieves factor sets by making a GET request to the factor set API endpoint.
|
|
7
8
|
*
|
|
8
9
|
* @export
|
|
9
|
-
* @return {Promise<
|
|
10
|
+
* @return {Promise<FactorSetResponse>} A promise that resolves to the FactorSetResponse returned by the API
|
|
10
11
|
* @throws {Error} May throw an error if the API request fails
|
|
11
12
|
*
|
|
12
13
|
* @example
|
|
13
14
|
* const factorSets = await get();
|
|
14
15
|
*/
|
|
15
16
|
export async function get(
|
|
16
|
-
): Promise<
|
|
17
|
+
): Promise<FactorSetResponse> {
|
|
17
18
|
const client = Client.getInstance();
|
|
18
19
|
const url = client.getDomain() + FACTOR_SET_API_PATH;
|
|
19
20
|
|
|
20
|
-
return makeApiRequest<
|
|
21
|
+
return makeApiRequest<FactorSetResponse>({
|
|
21
22
|
method: GET,
|
|
22
23
|
url
|
|
23
24
|
});
|
package/src/api/Fugitive.ts
CHANGED
|
@@ -1,43 +1,118 @@
|
|
|
1
1
|
import { Client } from "../Client";
|
|
2
|
-
import { FUGITIVE_API_PATH, POST } from "../Constants";
|
|
2
|
+
import { FUGITIVE_API_AREA, FUGITIVE_API_PATH, FUGITIVE_API_TYPES, FUGITIVE_API_UNITS, GET, POST } from "../Constants";
|
|
3
3
|
import { CommonRequest } from "../interfaces/Api";
|
|
4
|
+
import { AreaResponse } from "../interfaces/response/AreaResponse";
|
|
5
|
+
import { EmissionResponse } from "../interfaces/response/EmissionResponse";
|
|
6
|
+
import { EmissionResponseWithDetails } from "../interfaces/response/EmissionResponseWithDetails";
|
|
7
|
+
import { TypeResponse } from "../interfaces/response/TypeResponse";
|
|
8
|
+
import { UnitResponse } from "../interfaces/response/UnitResponse";
|
|
4
9
|
import { makeApiRequest } from "../request";
|
|
5
10
|
|
|
6
11
|
/**
|
|
7
12
|
* Performs scope 1 fugitve emission calculations by making a POST request to the fugitive API endpoint.
|
|
8
|
-
*
|
|
13
|
+
*
|
|
9
14
|
* @export
|
|
10
15
|
* @param {CommonRequest} payload - The request data to be sent to the API
|
|
11
|
-
* @return {Promise<
|
|
16
|
+
* @return {Promise<EmissionResponse | EmissionResponseWithDetails>} A promise that resolves to the emission calculation result. Returns EmissionResponseWithDetails if includeDetails is true, otherwise EmissionResponse
|
|
12
17
|
* @throws {Error} May throw an error if the API request fails
|
|
13
|
-
*
|
|
18
|
+
*
|
|
14
19
|
* @example
|
|
15
20
|
* const request = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
"time": {
|
|
22
|
+
"date": "2025-01-04"
|
|
23
|
+
},
|
|
24
|
+
"location": {
|
|
25
|
+
"country": "usa"
|
|
26
|
+
},
|
|
27
|
+
"activity": {
|
|
28
|
+
"type": "R134A",
|
|
29
|
+
"value": 150,
|
|
30
|
+
"unit": "kg"
|
|
31
|
+
},
|
|
32
|
+
"includeDetails": false
|
|
28
33
|
};
|
|
29
34
|
* const result = await calculate(request);
|
|
30
35
|
*/
|
|
31
36
|
|
|
32
37
|
export async function calculate(
|
|
33
38
|
payload: CommonRequest
|
|
34
|
-
): Promise<
|
|
39
|
+
): Promise<EmissionResponse | EmissionResponseWithDetails> {
|
|
35
40
|
const client = Client.getInstance();
|
|
36
41
|
const url = client.getDomain() + FUGITIVE_API_PATH;
|
|
37
42
|
|
|
38
|
-
return makeApiRequest<
|
|
43
|
+
return makeApiRequest<EmissionResponse | EmissionResponseWithDetails>({
|
|
39
44
|
method: POST,
|
|
40
45
|
url,
|
|
41
46
|
data: payload,
|
|
42
47
|
});
|
|
43
48
|
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves available fugitive emission calculation types by making a GET request to the API endpoint.
|
|
52
|
+
*
|
|
53
|
+
* @export
|
|
54
|
+
* @return {Promise<TypeResponse>} A promise that resolves to a TypeResponse containing the available fugitive emission types
|
|
55
|
+
* @throws {Error} May throw an error if the API request fails
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* const types = await getTypes();
|
|
59
|
+
*/
|
|
60
|
+
export async function getTypes(
|
|
61
|
+
): Promise<TypeResponse> {
|
|
62
|
+
const client = Client.getInstance();
|
|
63
|
+
const url = client.getDomain() + FUGITIVE_API_TYPES;
|
|
64
|
+
|
|
65
|
+
return makeApiRequest<TypeResponse>({
|
|
66
|
+
method: GET,
|
|
67
|
+
url
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Retrieves information about geographical areas supported by the fugitive emissions API.
|
|
73
|
+
*
|
|
74
|
+
* @export
|
|
75
|
+
* @return {Promise<AreaResponse>} A promise that resolves to an AreaResponse containing the supported geographical areas
|
|
76
|
+
* @throws {Error} May throw an error if the API request fails
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* const areas = await getArea();
|
|
80
|
+
*/
|
|
81
|
+
export async function getArea(
|
|
82
|
+
): Promise<AreaResponse> {
|
|
83
|
+
const client = Client.getInstance();
|
|
84
|
+
const url = client.getDomain() + FUGITIVE_API_AREA;
|
|
85
|
+
|
|
86
|
+
return makeApiRequest<AreaResponse>({
|
|
87
|
+
method: GET,
|
|
88
|
+
url
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Retrieves available units for a specific fugitive emission type.
|
|
94
|
+
*
|
|
95
|
+
* @export
|
|
96
|
+
* @param {string} type - The fugitive emission type to get units for (e.g., "R134A")
|
|
97
|
+
* @return {Promise<UnitResponse>} A promise that resolves to a UnitResponse containing the available units
|
|
98
|
+
* @throws {Error} May throw an error if the API request fails
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* // Get units for the "Natural Gas - Scope 3:AAA" emission fugitive type with subtype
|
|
102
|
+
* const units = await getUnits("Natural Gas - Scope 3:AAA");
|
|
103
|
+
|
|
104
|
+
* // Get units for the "R-426A" emission fugitive type without subtype
|
|
105
|
+
* const units = await getUnits("R-426A");
|
|
106
|
+
*/
|
|
107
|
+
export async function getUnits(
|
|
108
|
+
type : string
|
|
109
|
+
): Promise<UnitResponse> {
|
|
110
|
+
const client = Client.getInstance();
|
|
111
|
+
const url = client.getDomain() + FUGITIVE_API_UNITS;
|
|
112
|
+
|
|
113
|
+
return makeApiRequest<UnitResponse>({
|
|
114
|
+
method: GET,
|
|
115
|
+
url,
|
|
116
|
+
params : { type }
|
|
117
|
+
});
|
|
118
|
+
}
|
package/src/api/Location.ts
CHANGED
|
@@ -1,43 +1,117 @@
|
|
|
1
1
|
import { Client } from "../Client";
|
|
2
|
-
import { LOCATION_API_PATH, POST } from "../Constants";
|
|
2
|
+
import { GET, LOCATION_API_AREA, LOCATION_API_PATH, LOCATION_API_UNITS, LOCATION_TYPES, POST } from "../Constants";
|
|
3
3
|
import { LocationRequest } from "../interfaces/Api";
|
|
4
|
+
import { AreaResponse } from "../interfaces/response/AreaResponse";
|
|
5
|
+
import { EmissionResponse } from "../interfaces/response/EmissionResponse";
|
|
6
|
+
import { EmissionResponseWithDetails } from "../interfaces/response/EmissionResponseWithDetails";
|
|
7
|
+
import { TypeResponse } from "../interfaces/response/TypeResponse";
|
|
8
|
+
import { UnitResponse } from "../interfaces/response/UnitResponse";
|
|
4
9
|
import { makeApiRequest } from "../request";
|
|
5
10
|
|
|
6
11
|
/**
|
|
7
12
|
* Performs scope 2 purchased energy Emission calculations by making a POST request to the location API endpoint.
|
|
8
|
-
*
|
|
13
|
+
*
|
|
9
14
|
* @export
|
|
10
15
|
* @param {LocationRequest} payload - The location request data to be sent to the API
|
|
11
|
-
* @return {Promise<
|
|
16
|
+
* @return {Promise<EmissionResponse | EmissionResponseWithDetails>} A promise that resolves to the emission calculation result. Returns EmissionResponseWithDetails if includeDetails is true, otherwise EmissionResponse
|
|
12
17
|
* @throws {Error} May throw an error if the API request fails
|
|
13
|
-
*
|
|
18
|
+
*
|
|
14
19
|
* @example
|
|
15
20
|
* const calculationRequest = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
"time" : {
|
|
22
|
+
"date": "2025-01-04"
|
|
23
|
+
},
|
|
24
|
+
"location": {
|
|
25
|
+
"country": "usa",
|
|
26
|
+
"stateProvince": "new york"
|
|
27
|
+
},
|
|
28
|
+
"activity": {
|
|
29
|
+
"type":"electricity",
|
|
30
|
+
"unit": "kwh",
|
|
31
|
+
"value": 14123143
|
|
32
|
+
},
|
|
33
|
+
"includeDetails": true
|
|
34
|
+
};
|
|
30
35
|
* const result = await calculate(calculationRequest);
|
|
31
36
|
*/
|
|
32
37
|
export async function calculate(
|
|
33
38
|
payload: LocationRequest
|
|
34
|
-
): Promise<
|
|
39
|
+
): Promise<EmissionResponse | EmissionResponseWithDetails> {
|
|
35
40
|
const client = Client.getInstance();
|
|
36
41
|
const url = client.getDomain() + LOCATION_API_PATH;
|
|
37
42
|
|
|
38
|
-
return makeApiRequest<
|
|
43
|
+
return makeApiRequest<EmissionResponse | EmissionResponseWithDetails>({
|
|
39
44
|
method: POST,
|
|
40
45
|
url,
|
|
41
46
|
data: payload,
|
|
42
47
|
});
|
|
43
48
|
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Retrieves available location-based calculation types by making a GET request to the location types API endpoint.
|
|
53
|
+
*
|
|
54
|
+
* @export
|
|
55
|
+
* @return {Promise<TypeResponse>} A promise that resolves to a TypeResponse containing the available location-based calculation types
|
|
56
|
+
* @throws {Error} May throw an error if the API request fails
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
*
|
|
60
|
+
* const types = await getTypes();
|
|
61
|
+
*/
|
|
62
|
+
export async function getTypes(
|
|
63
|
+
): Promise<TypeResponse> {
|
|
64
|
+
const client = Client.getInstance();
|
|
65
|
+
const url = client.getDomain() + LOCATION_TYPES;
|
|
66
|
+
|
|
67
|
+
return makeApiRequest<TypeResponse>({
|
|
68
|
+
method: GET,
|
|
69
|
+
url
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Retrieves information about geographical areas supported by the location-based calculation API.
|
|
75
|
+
*
|
|
76
|
+
* @export
|
|
77
|
+
* @return {Promise<AreaResponse>} A promise that resolves to an AreaResponse containing the supported geographical areas
|
|
78
|
+
* @throws {Error} May throw an error if the API request fails
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* const areas = await getArea();
|
|
82
|
+
*/
|
|
83
|
+
export async function getArea(
|
|
84
|
+
): Promise<AreaResponse> {
|
|
85
|
+
const client = Client.getInstance();
|
|
86
|
+
const url = client.getDomain() + LOCATION_API_AREA;
|
|
87
|
+
|
|
88
|
+
return makeApiRequest<AreaResponse>({
|
|
89
|
+
method: GET,
|
|
90
|
+
url
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Retrieves available units for a specific location-based calculation type.
|
|
96
|
+
*
|
|
97
|
+
* @export
|
|
98
|
+
* @param {string} type - The location-based calculation type to get units for (e.g., "electricity")
|
|
99
|
+
* @return {Promise<UnitResponse>} A promise that resolves to a UnitResponse containing the available units
|
|
100
|
+
* @throws {Error} May throw an error if the API request fails
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* // Get units for the "electricity" location type
|
|
104
|
+
* const units = await getUnits("electricity");
|
|
105
|
+
*/
|
|
106
|
+
export async function getUnits(
|
|
107
|
+
type : string
|
|
108
|
+
): Promise<UnitResponse> {
|
|
109
|
+
const client = Client.getInstance();
|
|
110
|
+
const url = client.getDomain() + LOCATION_API_UNITS;
|
|
111
|
+
|
|
112
|
+
return makeApiRequest<UnitResponse>({
|
|
113
|
+
method: GET,
|
|
114
|
+
url,
|
|
115
|
+
params : { type }
|
|
116
|
+
});
|
|
117
|
+
}
|