emissions-api-sdk 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/dist/Constants.js +9 -1
- package/dist/api/EconomicActivity.js +100 -0
- package/dist/api/RealEstate.js +101 -0
- package/dist/coverage/clover.xml +87 -35
- package/dist/coverage/coverage-final.json +5 -3
- package/dist/coverage/lcov-report/index.html +15 -15
- package/dist/coverage/lcov-report/src/Client.ts.html +23 -23
- package/dist/coverage/lcov-report/src/Constants.ts.html +28 -4
- package/dist/coverage/lcov-report/src/api/Calculation.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/EconomicActivity.ts.html +427 -0
- package/dist/coverage/lcov-report/src/api/Factor.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/FactorSets.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/Fugitive.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/Location.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/Mobile.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/RealEstate.ts.html +430 -0
- package/dist/coverage/lcov-report/src/api/Stationary.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/TransportationAndDistribution.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/Usage.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/index.html +34 -4
- 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 +137 -57
- package/dist/index.js +3 -1
- package/dist/types/Constants.d.ts +8 -0
- package/dist/types/api/EconomicActivity.d.ts +67 -0
- package/dist/types/api/RealEstate.d.ts +68 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/interfaces/response/EmissionResponseWithDetails.d.ts +4 -0
- package/dist/types/interfaces/response/FactorResponse.d.ts +4 -4
- package/docs/_sources/index.rst.txt +8 -6
- package/docs/_sources/reference.rst.txt +16 -0
- package/docs/genindex.html +29 -1
- package/docs/index.html +2 -0
- package/docs/objects.inv +0 -0
- package/docs/reference.html +194 -0
- package/docs/searchindex.js +1 -1
- package/package.json +5 -2
- package/sphinx-build/.secrets.baseline +150 -0
- package/sphinx-build/requirements.txt +1 -2
- package/sphinx-build/source/index.rst +8 -6
- package/sphinx-build/source/reference.rst +16 -0
- package/src/Constants.ts +8 -0
- package/src/api/EconomicActivity.ts +115 -0
- package/src/api/RealEstate.ts +116 -0
- package/src/index.ts +2 -0
- package/src/interfaces/response/EmissionResponseWithDetails.ts +6 -0
- package/src/interfaces/response/FactorResponse.ts +6 -7
- package/test/apiTest.test.ts +63 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
{
|
|
2
|
+
"exclude": {
|
|
3
|
+
"files": "^.secrets.baseline$",
|
|
4
|
+
"lines": null
|
|
5
|
+
},
|
|
6
|
+
"generated_at": "2026-02-16T08:57:50Z",
|
|
7
|
+
"plugins_used": [
|
|
8
|
+
{
|
|
9
|
+
"name": "AWSKeyDetector"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"name": "ArtifactoryDetector"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "AzureStorageKeyDetector"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"base64_limit": 4.5,
|
|
19
|
+
"name": "Base64HighEntropyString"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"name": "BasicAuthDetector"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"name": "BoxDetector"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"name": "CloudantDetector"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"ghe_instance": "github.ibm.com",
|
|
32
|
+
"name": "GheDetector"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"name": "GitHubTokenDetector"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"hex_limit": 3,
|
|
39
|
+
"name": "HexHighEntropyString"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "IbmCloudIamDetector"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"name": "IbmCosHmacDetector"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"name": "JwtTokenDetector"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"keyword_exclude": null,
|
|
52
|
+
"name": "KeywordDetector"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"name": "MailchimpDetector"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"name": "NpmDetector"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"name": "PrivateKeyDetector"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"name": "SlackDetector"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"name": "SoftlayerDetector"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"name": "SquareOAuthDetector"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"name": "StripeDetector"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"name": "TwilioKeyDetector"
|
|
77
|
+
}
|
|
78
|
+
],
|
|
79
|
+
"results": {
|
|
80
|
+
"source/authentication.rst": [
|
|
81
|
+
{
|
|
82
|
+
"hashed_secret": "d92258e9826f7923e5fa45241420653a89db10b0",
|
|
83
|
+
"is_secret": false,
|
|
84
|
+
"is_verified": false,
|
|
85
|
+
"line_number": 41,
|
|
86
|
+
"type": "Secret Keyword",
|
|
87
|
+
"verified_result": null
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"hashed_secret": "9eddf3741c2ec20058940c3225b3e387cf6166dd",
|
|
91
|
+
"is_secret": false,
|
|
92
|
+
"is_verified": false,
|
|
93
|
+
"line_number": 152,
|
|
94
|
+
"type": "Secret Keyword",
|
|
95
|
+
"verified_result": null
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
"source/client.rst": [
|
|
99
|
+
{
|
|
100
|
+
"hashed_secret": "9eddf3741c2ec20058940c3225b3e387cf6166dd",
|
|
101
|
+
"is_secret": false,
|
|
102
|
+
"is_verified": false,
|
|
103
|
+
"line_number": 108,
|
|
104
|
+
"type": "Secret Keyword",
|
|
105
|
+
"verified_result": null
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
"source/getting_started.rst": [
|
|
109
|
+
{
|
|
110
|
+
"hashed_secret": "11fa7c37d697f30e6aee828b4426a10f83ab2380",
|
|
111
|
+
"is_secret": false,
|
|
112
|
+
"is_verified": false,
|
|
113
|
+
"line_number": 122,
|
|
114
|
+
"type": "Secret Keyword",
|
|
115
|
+
"verified_result": null
|
|
116
|
+
}
|
|
117
|
+
],
|
|
118
|
+
"source/troubleshooting.rst": [
|
|
119
|
+
{
|
|
120
|
+
"hashed_secret": "ade7ae7ec3dcbc8e6efab2ad366fd59b4be60bda",
|
|
121
|
+
"is_secret": false,
|
|
122
|
+
"is_verified": false,
|
|
123
|
+
"line_number": 129,
|
|
124
|
+
"type": "Secret Keyword",
|
|
125
|
+
"verified_result": null
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"hashed_secret": "24de2a83c833555a5931a357cb9a639830db7851",
|
|
129
|
+
"is_secret": false,
|
|
130
|
+
"is_verified": false,
|
|
131
|
+
"line_number": 191,
|
|
132
|
+
"type": "Secret Keyword",
|
|
133
|
+
"verified_result": null
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"hashed_secret": "11fa7c37d697f30e6aee828b4426a10f83ab2380",
|
|
137
|
+
"is_secret": false,
|
|
138
|
+
"is_verified": false,
|
|
139
|
+
"line_number": 224,
|
|
140
|
+
"type": "Secret Keyword",
|
|
141
|
+
"verified_result": null
|
|
142
|
+
}
|
|
143
|
+
]
|
|
144
|
+
},
|
|
145
|
+
"version": "0.13.1+ibm.64.dss",
|
|
146
|
+
"word_list": {
|
|
147
|
+
"file": null,
|
|
148
|
+
"hash": null
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -20,11 +20,13 @@ The **emissions-api-sdk** is a Node.js SDK for using Emissions API in your proje
|
|
|
20
20
|
Supported Emission Types
|
|
21
21
|
------------------------
|
|
22
22
|
|
|
23
|
-
* **Location** – emissions from region-specific factors
|
|
24
|
-
* **Fugitive** – emissions from leaks or fugitive sources
|
|
25
|
-
* **Mobile** – emissions from vehicles and mobile equipment
|
|
26
|
-
* **Stationary** – emissions from fixed fuel consumption
|
|
27
|
-
* **Transportation & distribution** – logistics and supply chain activities
|
|
28
|
-
* **
|
|
23
|
+
* **Location** – emissions from region-specific factors
|
|
24
|
+
* **Fugitive** – emissions from leaks or fugitive sources
|
|
25
|
+
* **Mobile** – emissions from vehicles and mobile equipment
|
|
26
|
+
* **Stationary** – emissions from fixed fuel consumption
|
|
27
|
+
* **Transportation & distribution** – logistics and supply chain activities
|
|
28
|
+
* **Real Estate** – emissions from commercial and residential properties
|
|
29
|
+
* **Economic Activity** – spend-based emissions from business activities
|
|
30
|
+
* **Generic** – custom emission calculations
|
|
29
31
|
|
|
30
32
|
The SDK is designed for embedding emission calculations in applications, building sustainability dashboards, automating large-scale datasets, and tracking carbon footprints.
|
|
@@ -27,6 +27,10 @@ API
|
|
|
27
27
|
|
|
28
28
|
.. js:autofunction:: TransportationAndDistribution.calculate
|
|
29
29
|
|
|
30
|
+
.. js:autofunction:: RealEstate.calculate
|
|
31
|
+
|
|
32
|
+
.. js:autofunction:: EconomicActivity.calculate
|
|
33
|
+
|
|
30
34
|
Metadata APIs
|
|
31
35
|
===========
|
|
32
36
|
|
|
@@ -47,6 +51,10 @@ getTypes
|
|
|
47
51
|
|
|
48
52
|
.. js:autofunction:: Fugitive.getTypes
|
|
49
53
|
|
|
54
|
+
.. js:autofunction:: RealEstate.getTypes
|
|
55
|
+
|
|
56
|
+
.. js:autofunction:: EconomicActivity.getTypes
|
|
57
|
+
|
|
50
58
|
getArea
|
|
51
59
|
-------
|
|
52
60
|
|
|
@@ -66,6 +74,10 @@ getArea
|
|
|
66
74
|
|
|
67
75
|
.. js:autofunction:: Fugitive.getArea
|
|
68
76
|
|
|
77
|
+
.. js:autofunction:: RealEstate.getArea
|
|
78
|
+
|
|
79
|
+
.. js:autofunction:: EconomicActivity.getArea
|
|
80
|
+
|
|
69
81
|
getUnits
|
|
70
82
|
--------
|
|
71
83
|
|
|
@@ -83,6 +95,10 @@ getUnits
|
|
|
83
95
|
|
|
84
96
|
.. js:autofunction:: Fugitive.getUnits
|
|
85
97
|
|
|
98
|
+
.. js:autofunction:: RealEstate.getUnits
|
|
99
|
+
|
|
100
|
+
.. js:autofunction:: EconomicActivity.getUnits
|
|
101
|
+
|
|
86
102
|
|
|
87
103
|
Usage API
|
|
88
104
|
===========
|
package/src/Constants.ts
CHANGED
|
@@ -9,6 +9,8 @@ export const TRANSPORTATION_AND_DISTRIBUTION_API_PATH = "/v3/carbon/transportati
|
|
|
9
9
|
export const FACTOR_API_PATH = "/v3/carbon/factor";
|
|
10
10
|
export const FACTOR_SET_API_PATH = "/v3/carbon/factorset";
|
|
11
11
|
export const SEARCH_API_PATH = "/v3/carbon/factor/search";
|
|
12
|
+
export const ECONOMIC_ACTIVITY_API_PATH = "/v3/carbon/economic-activity";
|
|
13
|
+
export const REAL_ESTATE_API_PATH = "/v3/carbon/real-estate";
|
|
12
14
|
|
|
13
15
|
export const CALCULATION_TYPES = "/v3/carbon/calculation/types";
|
|
14
16
|
export const LOCATION_TYPES = "/v3/carbon/location/types";
|
|
@@ -17,6 +19,8 @@ export const MOBILE_API_TYPES = "/v3/carbon/mobile/types";
|
|
|
17
19
|
export const STATIONARY_API_TYPES = "/v3/carbon/stationary/types";
|
|
18
20
|
export const FACTOR_API_TYPES = "/v3/carbon/factor/types";
|
|
19
21
|
export const TRANSPORTATION_AND_DISTRIBUTION_API_TYPES = "/v3/carbon/transportation-and-distribution/types";
|
|
22
|
+
export const REAL_ESTATE_API_TYPES = "/v3/carbon/real-estate/types";
|
|
23
|
+
export const ECONOMIC_ACTIVITY_API_TYPES = "/v3/carbon/economic-activity/types";
|
|
20
24
|
|
|
21
25
|
export const FUGITIVE_API_AREA = "/v3/carbon/fugitive/area";
|
|
22
26
|
export const GENERAL_API_AREA = "/v3/carbon/calculation/area";
|
|
@@ -26,6 +30,8 @@ export const STATIONARY_API_AREA = "/v3/carbon/stationary/area";
|
|
|
26
30
|
export const TRANSPORTATION_AND_DISTRIBUTION_API_AREA = "/v3/carbon/transportation-and-distribution/area";
|
|
27
31
|
export const SEARCH_API_AREA = "/v3/carbon/factor/search/area";
|
|
28
32
|
export const FACTOR_API_AREA = "/v3/carbon/factor/area";
|
|
33
|
+
export const REAL_ESTATE_API_AREA = "/v3/carbon/real-estate/area";
|
|
34
|
+
export const ECONOMIC_ACTIVITY_API_AREA = "/v3/carbon/economic-activity/area";
|
|
29
35
|
|
|
30
36
|
export const FUGITIVE_API_UNITS = "/v3/carbon/fugitive/units";
|
|
31
37
|
export const LOCATION_API_UNITS = "/v3/carbon/location/units";
|
|
@@ -34,6 +40,8 @@ export const STATIONARY_API_UNITS = "/v3/carbon/stationary/units";
|
|
|
34
40
|
export const GENERAL_API_UNITS = "/v3/carbon/calculation/units";
|
|
35
41
|
export const FACTOR_API_UNITS = "/v3/carbon/factor/units";
|
|
36
42
|
export const TRANSPORTATION_AND_DISTRIBUTION_API_UNITS = "/v3/carbon/transportation-and-distribution/units";
|
|
43
|
+
export const REAL_ESTATE_API_UNITS = "/v3/carbon/real-estate/units";
|
|
44
|
+
export const ECONOMIC_ACTIVITY_API_UNITS = "/v3/carbon/economic-activity/units";
|
|
37
45
|
|
|
38
46
|
export const USAGE_API = "/v3/carbon/usage";
|
|
39
47
|
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { Client } from "../Client";
|
|
2
|
+
import { ECONOMIC_ACTIVITY_API_PATH, ECONOMIC_ACTIVITY_API_AREA, ECONOMIC_ACTIVITY_API_TYPES, ECONOMIC_ACTIVITY_API_UNITS, GET, POST } from "../Constants";
|
|
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";
|
|
9
|
+
import { makeApiRequest } from "../request";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Performs scope 3 Spend based emission calculations by making a POST request to the economic activity API endpoint.
|
|
13
|
+
*
|
|
14
|
+
* @export
|
|
15
|
+
* @param {CommonRequest} payload - The request data to be sent to the API
|
|
16
|
+
* @return {Promise<EmissionResponse | EmissionResponseWithDetails>} A promise that resolves to the emission calculation result. Returns EmissionResponseWithDetails if includeDetails is true, otherwise EmissionResponse
|
|
17
|
+
* @throws {Error} May throw an error if the API request fails
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const request = {
|
|
21
|
+
"time": {
|
|
22
|
+
"date": "2025-01-04"
|
|
23
|
+
},
|
|
24
|
+
"location": {
|
|
25
|
+
"country": "usa"
|
|
26
|
+
},
|
|
27
|
+
"activity": {
|
|
28
|
+
"type": "accomodation",
|
|
29
|
+
"value": 1500.12,
|
|
30
|
+
"unit": "usd"
|
|
31
|
+
},
|
|
32
|
+
"includeDetails": false
|
|
33
|
+
};
|
|
34
|
+
* const result = await calculate(request);
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
export async function calculate(
|
|
38
|
+
payload: CommonRequest
|
|
39
|
+
): Promise<EmissionResponse | EmissionResponseWithDetails> {
|
|
40
|
+
const client = Client.getInstance();
|
|
41
|
+
const url = client.getDomain() + ECONOMIC_ACTIVITY_API_PATH;
|
|
42
|
+
|
|
43
|
+
return makeApiRequest<EmissionResponse | EmissionResponseWithDetails>({
|
|
44
|
+
method: POST,
|
|
45
|
+
url,
|
|
46
|
+
data: payload,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves available economic activity 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 economic activity 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() + ECONOMIC_ACTIVITY_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 economic activity 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() + ECONOMIC_ACTIVITY_API_AREA;
|
|
85
|
+
|
|
86
|
+
return makeApiRequest<AreaResponse>({
|
|
87
|
+
method: GET,
|
|
88
|
+
url
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Retrieves available units for a specific economic activity emission type.
|
|
94
|
+
*
|
|
95
|
+
* @export
|
|
96
|
+
* @param {string} type - The economic activity emission type to get units for (e.g., "accomodation")
|
|
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 "accomodation" emission economic activity type without subtype
|
|
102
|
+
* const units = await getUnits("accomodation");
|
|
103
|
+
*/
|
|
104
|
+
export async function getUnits(
|
|
105
|
+
type : string
|
|
106
|
+
): Promise<UnitResponse> {
|
|
107
|
+
const client = Client.getInstance();
|
|
108
|
+
const url = client.getDomain() + ECONOMIC_ACTIVITY_API_UNITS;
|
|
109
|
+
|
|
110
|
+
return makeApiRequest<UnitResponse>({
|
|
111
|
+
method: GET,
|
|
112
|
+
url,
|
|
113
|
+
params : { type }
|
|
114
|
+
});
|
|
115
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Client } from "../Client";
|
|
2
|
+
import { REAL_ESTATE_API_AREA, REAL_ESTATE_API_PATH, REAL_ESTATE_API_TYPES, REAL_ESTATE_API_UNITS, GET, POST } from "../Constants";
|
|
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";
|
|
9
|
+
import { makeApiRequest } from "../request";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Performs scope 3 Real estate emission calculations by making a POST request to the real estate API endpoint.
|
|
13
|
+
*
|
|
14
|
+
* @export
|
|
15
|
+
* @param {CommonRequest} payload - The request data to be sent to the API
|
|
16
|
+
* @return {Promise<EmissionResponse | EmissionResponseWithDetails>} A promise that resolves to the emission calculation result. Returns EmissionResponseWithDetails if includeDetails is true, otherwise EmissionResponse
|
|
17
|
+
* @throws {Error} May throw an error if the API request fails
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const request = {
|
|
21
|
+
"time": {
|
|
22
|
+
"date": "2025-01-04"
|
|
23
|
+
},
|
|
24
|
+
"location": {
|
|
25
|
+
"country": "usa"
|
|
26
|
+
},
|
|
27
|
+
"activity": {
|
|
28
|
+
"type": "Commercial Real Estate:Industrial distribution warehouse",
|
|
29
|
+
"value": 17000.123,
|
|
30
|
+
"unit": "m2"
|
|
31
|
+
},
|
|
32
|
+
"includeDetails": false
|
|
33
|
+
};
|
|
34
|
+
* const result = await calculate(request);
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
export async function calculate(
|
|
38
|
+
payload: CommonRequest
|
|
39
|
+
): Promise<EmissionResponse | EmissionResponseWithDetails> {
|
|
40
|
+
const client = Client.getInstance();
|
|
41
|
+
const url = client.getDomain() + REAL_ESTATE_API_PATH;
|
|
42
|
+
|
|
43
|
+
return makeApiRequest<EmissionResponse | EmissionResponseWithDetails>({
|
|
44
|
+
method: POST,
|
|
45
|
+
url,
|
|
46
|
+
data: payload,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves available Real estate 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 Real estate 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() + REAL_ESTATE_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 real estate 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() + REAL_ESTATE_API_AREA;
|
|
85
|
+
|
|
86
|
+
return makeApiRequest<AreaResponse>({
|
|
87
|
+
method: GET,
|
|
88
|
+
url
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Retrieves available units for a specific Real estate emission type.
|
|
94
|
+
*
|
|
95
|
+
* @export
|
|
96
|
+
* @param {string} type - The Real estate 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 "Commercial Real Estate:Industrial distribution warehouse" emission real estate type with subtype
|
|
102
|
+
* const units = await getUnits("Commercial Real Estate:Industrial distribution warehouse");
|
|
103
|
+
|
|
104
|
+
*/
|
|
105
|
+
export async function getUnits(
|
|
106
|
+
type : string
|
|
107
|
+
): Promise<UnitResponse> {
|
|
108
|
+
const client = Client.getInstance();
|
|
109
|
+
const url = client.getDomain() + REAL_ESTATE_API_UNITS;
|
|
110
|
+
|
|
111
|
+
return makeApiRequest<UnitResponse>({
|
|
112
|
+
method: GET,
|
|
113
|
+
url,
|
|
114
|
+
params : { type }
|
|
115
|
+
});
|
|
116
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,8 @@ export * as TransportationAndDistribution from './api/TransportationAndDistribut
|
|
|
8
8
|
export * as Usage from './api/Usage'
|
|
9
9
|
export * as Factor from './api/Factor';
|
|
10
10
|
export * as FactorSets from './api/FactorSets'
|
|
11
|
+
export * as EconomicActivity from './api/EconomicActivity';
|
|
12
|
+
export * as RealEstate from './api/RealEstate';
|
|
11
13
|
export { ClientConfig } from './interfaces/Config';
|
|
12
14
|
|
|
13
15
|
// Response interfaces
|
|
@@ -62,17 +62,16 @@ export interface FactorResponse {
|
|
|
62
62
|
|
|
63
63
|
/** Publication end date in ISO format (optional) */
|
|
64
64
|
publishedTo?: string;
|
|
65
|
-
|
|
66
|
-
/** Effective start date in ISO format (optional) */
|
|
67
|
-
effectiveFrom?: string;
|
|
68
|
-
|
|
69
|
-
/** Effective end date in ISO format (optional) */
|
|
70
|
-
effectiveTo?: string;
|
|
71
|
-
|
|
72
65
|
|
|
73
66
|
/** Geographic region (e.g., "Earth", "India") */
|
|
74
67
|
region: string;
|
|
75
68
|
|
|
76
69
|
/** Unique factor identifier */
|
|
77
70
|
factorId: number;
|
|
71
|
+
|
|
72
|
+
/** activity based or spend based */
|
|
73
|
+
methodology: string;
|
|
74
|
+
|
|
75
|
+
/** scopes data belongs to */
|
|
76
|
+
scope : string[];
|
|
78
77
|
}
|
package/test/apiTest.test.ts
CHANGED
|
@@ -5,6 +5,8 @@ import * as mobileApi from "../src/api/Mobile";
|
|
|
5
5
|
import * as stationaryApi from "../src/api/Stationary";
|
|
6
6
|
import * as GenericCalculation from "../src/api/Calculation";
|
|
7
7
|
import * as TransportationDistributionApi from "../src/api/TransportationAndDistribution";
|
|
8
|
+
import * as economicActivityApi from "../src/api/EconomicActivity";
|
|
9
|
+
import * as realEstateApi from "../src/api/RealEstate";
|
|
8
10
|
import * as UsageApi from "../src/api/Usage";
|
|
9
11
|
import * as Factors from "../src/api/Factor";
|
|
10
12
|
import * as FactorSets from "../src/api/FactorSets";
|
|
@@ -41,7 +43,15 @@ import {
|
|
|
41
43
|
GENERAL_API_UNITS,
|
|
42
44
|
FACTOR_API_UNITS,
|
|
43
45
|
TRANSPORTATION_AND_DISTRIBUTION_API_UNITS,
|
|
44
|
-
USAGE_API
|
|
46
|
+
USAGE_API,
|
|
47
|
+
ECONOMIC_ACTIVITY_API_PATH,
|
|
48
|
+
ECONOMIC_ACTIVITY_API_TYPES,
|
|
49
|
+
REAL_ESTATE_API_PATH,
|
|
50
|
+
REAL_ESTATE_API_TYPES,
|
|
51
|
+
ECONOMIC_ACTIVITY_API_AREA,
|
|
52
|
+
REAL_ESTATE_API_AREA,
|
|
53
|
+
ECONOMIC_ACTIVITY_API_UNITS,
|
|
54
|
+
REAL_ESTATE_API_UNITS
|
|
45
55
|
} from "../src/Constants";
|
|
46
56
|
import locationPayload from "./mocks/LocationRequest";
|
|
47
57
|
import commonpayload from "./mocks/CommonRequest";
|
|
@@ -112,6 +122,20 @@ const testCases: ApiTestCase[] = [
|
|
|
112
122
|
payload: GenericCalculationPayload,
|
|
113
123
|
method: "POST",
|
|
114
124
|
},
|
|
125
|
+
{
|
|
126
|
+
name: "Economic activity API",
|
|
127
|
+
func: economicActivityApi.calculate,
|
|
128
|
+
path: ECONOMIC_ACTIVITY_API_PATH,
|
|
129
|
+
payload: commonpayload,
|
|
130
|
+
method: "POST",
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: "Real estate API",
|
|
134
|
+
func: realEstateApi.calculate,
|
|
135
|
+
path: REAL_ESTATE_API_PATH,
|
|
136
|
+
payload: commonpayload,
|
|
137
|
+
method: "POST",
|
|
138
|
+
},
|
|
115
139
|
{
|
|
116
140
|
name: "FactorSet API",
|
|
117
141
|
func: FactorSets.get,
|
|
@@ -149,6 +173,18 @@ const testCases: ApiTestCase[] = [
|
|
|
149
173
|
path: STATIONARY_API_TYPES,
|
|
150
174
|
method: "GET",
|
|
151
175
|
},
|
|
176
|
+
{
|
|
177
|
+
name: "Economic activity API - getTypes",
|
|
178
|
+
func: economicActivityApi.getTypes,
|
|
179
|
+
path: ECONOMIC_ACTIVITY_API_TYPES,
|
|
180
|
+
method: "GET",
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
name: "Real estate API - getTypes",
|
|
184
|
+
func: realEstateApi.getTypes,
|
|
185
|
+
path: REAL_ESTATE_API_TYPES,
|
|
186
|
+
method: "GET",
|
|
187
|
+
},
|
|
152
188
|
{
|
|
153
189
|
name: "GenericCalculation API - getTypes",
|
|
154
190
|
func: GenericCalculation.getTypes,
|
|
@@ -191,6 +227,18 @@ const testCases: ApiTestCase[] = [
|
|
|
191
227
|
path: STATIONARY_API_AREA,
|
|
192
228
|
method: "GET",
|
|
193
229
|
},
|
|
230
|
+
{
|
|
231
|
+
name: "Economic activity API - getArea",
|
|
232
|
+
func: economicActivityApi.getArea,
|
|
233
|
+
path: ECONOMIC_ACTIVITY_API_AREA,
|
|
234
|
+
method: "GET",
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
name: "Real estate API - getArea",
|
|
238
|
+
func: realEstateApi.getArea,
|
|
239
|
+
path: REAL_ESTATE_API_AREA,
|
|
240
|
+
method: "GET",
|
|
241
|
+
},
|
|
194
242
|
{
|
|
195
243
|
name: "GenericCalculation API - getArea",
|
|
196
244
|
func: GenericCalculation.getArea,
|
|
@@ -243,6 +291,20 @@ const testCases: ApiTestCase[] = [
|
|
|
243
291
|
queryParams: { type: "Jet Kerosene" },
|
|
244
292
|
method: "GET",
|
|
245
293
|
},
|
|
294
|
+
{
|
|
295
|
+
name: "Economic activity API - getUnits",
|
|
296
|
+
func: economicActivityApi.getUnits,
|
|
297
|
+
path: ECONOMIC_ACTIVITY_API_UNITS,
|
|
298
|
+
queryParams: { type: "accomodation" },
|
|
299
|
+
method: "GET",
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
name: "Real estate API - getUnits",
|
|
303
|
+
func: realEstateApi.getUnits,
|
|
304
|
+
path: REAL_ESTATE_API_UNITS,
|
|
305
|
+
queryParams: { type: "Commercial Real Estate:Hotel" },
|
|
306
|
+
method: "GET",
|
|
307
|
+
},
|
|
246
308
|
{
|
|
247
309
|
name: "GenericCalculation API - getUnits",
|
|
248
310
|
func: GenericCalculation.getUnits,
|