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.
Files changed (155) hide show
  1. package/README.md +33 -2
  2. package/dist/Constants.js +23 -1
  3. package/dist/api/Calculation.js +78 -15
  4. package/dist/api/Factor.js +99 -18
  5. package/dist/api/FactorSets.js +1 -1
  6. package/dist/api/Fugitive.js +76 -13
  7. package/dist/api/Location.js +76 -15
  8. package/dist/api/Mobile.js +65 -1
  9. package/dist/api/Stationary.js +78 -15
  10. package/dist/api/TransportationAndDistribution.js +77 -14
  11. package/dist/coverage/clover.xml +191 -81
  12. package/dist/coverage/coverage-final.json +11 -11
  13. package/dist/coverage/lcov-report/index.html +16 -16
  14. package/dist/coverage/lcov-report/src/Client.ts.html +23 -23
  15. package/dist/coverage/lcov-report/src/Constants.ts.html +82 -4
  16. package/dist/coverage/lcov-report/src/api/Calculation.ts.html +245 -26
  17. package/dist/coverage/lcov-report/src/api/Factor.ts.html +313 -34
  18. package/dist/coverage/lcov-report/src/api/FactorSets.ts.html +8 -5
  19. package/dist/coverage/lcov-report/src/api/Fugitive.ts.html +246 -24
  20. package/dist/coverage/lcov-report/src/api/Location.ts.html +245 -26
  21. package/dist/coverage/lcov-report/src/api/Mobile.ts.html +240 -12
  22. package/dist/coverage/lcov-report/src/api/Stationary.ts.html +248 -26
  23. package/dist/coverage/lcov-report/src/api/TransportationAndDistribution.ts.html +250 -25
  24. package/dist/coverage/lcov-report/src/api/index.html +25 -25
  25. package/dist/coverage/lcov-report/src/index.html +7 -7
  26. package/dist/coverage/lcov-report/src/request.ts.html +1 -1
  27. package/dist/coverage/lcov-report/src/utils.ts.html +5 -5
  28. package/dist/coverage/lcov-report/test/index.html +1 -1
  29. package/dist/coverage/lcov-report/test/mocks/CommonRequest.ts.html +1 -1
  30. package/dist/coverage/lcov-report/test/mocks/FactorRequest.ts.html +1 -1
  31. package/dist/coverage/lcov-report/test/mocks/GenericCalculationRequest.ts.html +1 -1
  32. package/dist/coverage/lcov-report/test/mocks/LocationRequest.ts.html +1 -1
  33. package/dist/coverage/lcov-report/test/mocks/SearchRequest.ts.html +1 -1
  34. package/dist/coverage/lcov-report/test/mocks/index.html +1 -1
  35. package/dist/coverage/lcov-report/test/testUtils.ts.html +1 -1
  36. package/dist/coverage/lcov.info +287 -133
  37. package/dist/interfaces/response/AreaResponse.js +2 -0
  38. package/dist/interfaces/response/EmissionResponse.js +2 -0
  39. package/dist/interfaces/response/EmissionResponseWithDetails.js +2 -0
  40. package/dist/interfaces/response/FactorResponse.js +2 -0
  41. package/dist/interfaces/response/FactorSetResponse.js +2 -0
  42. package/dist/interfaces/response/SearchResponse.js +2 -0
  43. package/dist/interfaces/response/TypeResponse.js +2 -0
  44. package/dist/interfaces/response/UnitResponse.js +2 -0
  45. package/dist/types/Constants.d.ts +22 -0
  46. package/dist/types/api/Calculation.d.ts +59 -16
  47. package/dist/types/api/Factor.d.ts +73 -20
  48. package/dist/types/api/FactorSets.d.ts +3 -2
  49. package/dist/types/api/Fugitive.d.ts +57 -14
  50. package/dist/types/api/Location.d.ts +57 -16
  51. package/dist/types/api/Mobile.d.ts +46 -2
  52. package/dist/types/api/Stationary.d.ts +59 -16
  53. package/dist/types/api/TransportationAndDistribution.d.ts +58 -15
  54. package/dist/types/index.d.ts +8 -0
  55. package/dist/types/interfaces/response/AreaResponse.d.ts +20 -0
  56. package/dist/types/interfaces/response/EmissionResponse.d.ts +31 -0
  57. package/dist/types/interfaces/response/EmissionResponseWithDetails.d.ts +144 -0
  58. package/dist/types/interfaces/response/FactorResponse.d.ts +53 -0
  59. package/dist/types/interfaces/response/FactorSetResponse.d.ts +38 -0
  60. package/dist/types/interfaces/response/SearchResponse.d.ts +41 -0
  61. package/dist/types/interfaces/response/TypeResponse.d.ts +7 -0
  62. package/dist/types/interfaces/response/UnitResponse.d.ts +7 -0
  63. package/docs/.nojekyll +0 -0
  64. package/docs/_sources/authentication.rst.txt +164 -0
  65. package/docs/_sources/client.rst.txt +137 -0
  66. package/docs/_sources/getting_started.rst.txt +164 -0
  67. package/docs/_sources/index.rst.txt +30 -0
  68. package/docs/_sources/reference.rst.txt +129 -0
  69. package/docs/_sources/sdk.rst.txt +13 -0
  70. package/docs/_sources/troubleshooting.rst.txt +486 -0
  71. package/docs/_static/basic.css +914 -0
  72. package/docs/_static/custom.css +16 -0
  73. package/docs/_static/debug.css +69 -0
  74. package/docs/_static/doctools.js +149 -0
  75. package/docs/_static/documentation_options.js +13 -0
  76. package/docs/_static/file.png +0 -0
  77. package/docs/_static/language_data.js +192 -0
  78. package/docs/_static/minus.png +0 -0
  79. package/docs/_static/plus.png +0 -0
  80. package/docs/_static/pygments.css +232 -0
  81. package/docs/_static/scripts/furo-extensions.js +0 -0
  82. package/docs/_static/scripts/furo.js +3 -0
  83. package/docs/_static/scripts/furo.js.LICENSE.txt +7 -0
  84. package/docs/_static/scripts/furo.js.map +1 -0
  85. package/docs/_static/searchtools.js +632 -0
  86. package/docs/_static/skeleton.css +296 -0
  87. package/docs/_static/sphinx_highlight.js +154 -0
  88. package/docs/_static/sphinx_js.css +0 -0
  89. package/docs/_static/styles/furo-extensions.css +2 -0
  90. package/docs/_static/styles/furo-extensions.css.map +1 -0
  91. package/docs/_static/styles/furo.css +2 -0
  92. package/docs/_static/styles/furo.css.map +1 -0
  93. package/docs/authentication.html +523 -0
  94. package/docs/client.html +477 -0
  95. package/docs/genindex.html +492 -0
  96. package/docs/getting_started.html +491 -0
  97. package/docs/index.html +357 -0
  98. package/docs/objects.inv +0 -0
  99. package/docs/reference.html +1584 -0
  100. package/docs/sdk.html +334 -0
  101. package/docs/search.html +297 -0
  102. package/docs/searchindex.js +1 -0
  103. package/docs/troubleshooting.html +786 -0
  104. package/package.json +1 -1
  105. package/sphinx-build/Makefile +49 -0
  106. package/sphinx-build/requirements.txt +5 -0
  107. package/sphinx-build/source/_static/custom.css +16 -0
  108. package/sphinx-build/source/authentication.rst +164 -0
  109. package/sphinx-build/source/client.rst +137 -0
  110. package/sphinx-build/source/conf.py +56 -0
  111. package/sphinx-build/source/getting_started.rst +164 -0
  112. package/sphinx-build/source/index.rst +30 -0
  113. package/sphinx-build/source/reference.rst +129 -0
  114. package/sphinx-build/source/sdk.rst +13 -0
  115. package/sphinx-build/source/troubleshooting.rst +486 -0
  116. package/src/Constants.ts +26 -0
  117. package/src/api/Calculation.ts +94 -20
  118. package/src/api/Factor.ts +122 -28
  119. package/src/api/FactorSets.ts +4 -3
  120. package/src/api/Fugitive.ts +93 -18
  121. package/src/api/Location.ts +94 -20
  122. package/src/api/Mobile.ts +83 -6
  123. package/src/api/Stationary.ts +95 -20
  124. package/src/api/TransportationAndDistribution.ts +95 -19
  125. package/src/index.ts +33 -1
  126. package/src/interfaces/response/AreaResponse.ts +25 -0
  127. package/src/interfaces/response/EmissionResponse.ts +44 -0
  128. package/src/interfaces/response/EmissionResponseWithDetails.ts +183 -0
  129. package/src/interfaces/response/FactorResponse.ts +78 -0
  130. package/src/interfaces/response/FactorSetResponse.ts +52 -0
  131. package/src/interfaces/response/SearchResponse.ts +52 -0
  132. package/src/interfaces/response/TypeResponse.ts +7 -0
  133. package/src/interfaces/response/UnitResponse.ts +7 -0
  134. package/test/apiTest.test.ts +173 -6
  135. package/dist/api/Factors.js +0 -98
  136. package/dist/api/FugitiveEmission.js +0 -40
  137. package/dist/api/GenericCalculation.js +0 -41
  138. package/dist/api/LocationEmission.js +0 -41
  139. package/dist/api/MobileEmission.js +0 -41
  140. package/dist/api/StationaryEmission.js +0 -41
  141. package/dist/api/TransportationDistributionEmission.js +0 -40
  142. package/dist/coverage/lcov-report/src/api/Factors.ts.html +0 -403
  143. package/dist/coverage/lcov-report/src/api/FugitiveEmission.ts.html +0 -214
  144. package/dist/coverage/lcov-report/src/api/GenericCalculation.ts.html +0 -217
  145. package/dist/coverage/lcov-report/src/api/LocationEmission.ts.html +0 -214
  146. package/dist/coverage/lcov-report/src/api/MobileEmission.ts.html +0 -220
  147. package/dist/coverage/lcov-report/src/api/StationaryEmission.ts.html +0 -220
  148. package/dist/coverage/lcov-report/src/api/TransportationDistributionEmission.ts.html +0 -211
  149. package/dist/types/api/Factors.d.ts +0 -68
  150. package/dist/types/api/FugitiveEmission.d.ts +0 -27
  151. package/dist/types/api/GenericCalculation.d.ts +0 -28
  152. package/dist/types/api/LocationEmission.d.ts +0 -28
  153. package/dist/types/api/MobileEmission.d.ts +0 -28
  154. package/dist/types/api/StationaryEmission.d.ts +0 -28
  155. package/dist/types/api/TransportationDistributionEmission.d.ts +0 -27
@@ -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<string>} A promise that resolves to the calculation result string returned by the API
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
- "time" : {
18
- "date": "2025-01-04"
19
- },
20
- "location": {
21
- "country": "usa",
22
- "stateProvince": "new york"
23
- },
24
- "activity": {
25
- "type":"Waste Combusted - Steel Cans:Default factor",
26
- "unit": "kg",
27
- "value": 1223123.121
28
- },
29
- "includeDetails": true
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<string> {
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<string>({
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<string>} A promise that resolves to the factor string returned by the API
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
- "activity": {
18
- "factorId": 12345
19
- }
21
+ "activity": {
22
+ "factorId": 12345
23
+ }
20
24
  };
21
25
 
22
- or
26
+ OR
23
27
 
24
28
  const factorRequest = {
25
- "time" : {
26
- "date": "2025-01-04"
27
- },
28
- "location": {
29
- "country": "usa",
30
- "stateProvince": "new york"
31
- },
32
- "activity": {
33
- "type":"natural gas"
34
- },
35
- "includeDetails": true
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<string> {
46
+ ): Promise<FactorResponse> {
43
47
  const client = Client.getInstance();
44
48
  const url = client.getDomain() + FACTOR_API_PATH;
45
49
 
46
- return makeApiRequest<string>({
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<string>} A promise that resolves to the search results string returned by the API
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
- "location": {
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<string> {
81
+ ): Promise<SearchResponse> {
78
82
  const client = Client.getInstance();
79
83
  const url = client.getDomain() + SEARCH_API_PATH;
80
84
 
81
- return makeApiRequest<string>({
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
+ }
@@ -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<string>} A promise that resolves to the factor sets string returned by the API
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<string> {
17
+ ): Promise<FactorSetResponse> {
17
18
  const client = Client.getInstance();
18
19
  const url = client.getDomain() + FACTOR_SET_API_PATH;
19
20
 
20
- return makeApiRequest<string>({
21
+ return makeApiRequest<FactorSetResponse>({
21
22
  method: GET,
22
23
  url
23
24
  });
@@ -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<string>} A promise that resolves to the calculation result string returned by the API
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
- "time": {
17
- "date": "2025-01-04"
18
- },
19
- "location": {
20
- "country": "usa"
21
- },
22
- "activity": {
23
- "type": "R134A",
24
- "value": 150,
25
- "unit": "kg"
26
- },
27
- "includeDetails": false
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<string> {
39
+ ): Promise<EmissionResponse | EmissionResponseWithDetails> {
35
40
  const client = Client.getInstance();
36
41
  const url = client.getDomain() + FUGITIVE_API_PATH;
37
42
 
38
- return makeApiRequest<string>({
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
+ }
@@ -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<string>} A promise that resolves to the purchased energy emission result string returned by the API
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
- "time" : {
17
- "date": "2025-01-04"
18
- },
19
- "location": {
20
- "country": "usa",
21
- "stateProvince": "new york"
22
- },
23
- "activity": {
24
- "type":"electricity",
25
- "unit": "kwh",
26
- "value": 14123143
27
- },
28
- "includeDetails": true
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<string> {
39
+ ): Promise<EmissionResponse | EmissionResponseWithDetails> {
35
40
  const client = Client.getInstance();
36
41
  const url = client.getDomain() + LOCATION_API_PATH;
37
42
 
38
- return makeApiRequest<string>({
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
+ }