emissions-api-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/CODE_OF_CONDUCT.md +76 -0
  2. package/CONTRIBUTING.md +68 -0
  3. package/LICENSE +201 -0
  4. package/MAINTAINERS.md +10 -0
  5. package/README.md +89 -0
  6. package/dist/Client.js +227 -0
  7. package/dist/Constants.js +19 -0
  8. package/dist/api/Calculation.js +41 -0
  9. package/dist/api/Factor.js +79 -0
  10. package/dist/api/FactorSets.js +24 -0
  11. package/dist/api/Factors.js +98 -0
  12. package/dist/api/Fugitive.js +40 -0
  13. package/dist/api/FugitiveEmission.js +40 -0
  14. package/dist/api/GenericCalculation.js +41 -0
  15. package/dist/api/Location.js +41 -0
  16. package/dist/api/LocationEmission.js +41 -0
  17. package/dist/api/Mobile.js +41 -0
  18. package/dist/api/MobileEmission.js +41 -0
  19. package/dist/api/Stationary.js +41 -0
  20. package/dist/api/StationaryEmission.js +41 -0
  21. package/dist/api/TransportationAndDistribution.js +40 -0
  22. package/dist/api/TransportationDistributionEmission.js +40 -0
  23. package/dist/coverage/clover.xml +225 -0
  24. package/dist/coverage/coverage-final.json +19 -0
  25. package/dist/coverage/lcov-report/base.css +224 -0
  26. package/dist/coverage/lcov-report/block-navigation.js +87 -0
  27. package/dist/coverage/lcov-report/favicon.png +0 -0
  28. package/dist/coverage/lcov-report/index.html +161 -0
  29. package/dist/coverage/lcov-report/prettify.css +1 -0
  30. package/dist/coverage/lcov-report/prettify.js +2 -0
  31. package/dist/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  32. package/dist/coverage/lcov-report/sorter.js +210 -0
  33. package/dist/coverage/lcov-report/src/Client.ts.html +838 -0
  34. package/dist/coverage/lcov-report/src/Constants.ts.html +130 -0
  35. package/dist/coverage/lcov-report/src/api/Calculation.ts.html +217 -0
  36. package/dist/coverage/lcov-report/src/api/Factor.ts.html +343 -0
  37. package/dist/coverage/lcov-report/src/api/FactorSets.ts.html +154 -0
  38. package/dist/coverage/lcov-report/src/api/Factors.ts.html +403 -0
  39. package/dist/coverage/lcov-report/src/api/Fugitive.ts.html +214 -0
  40. package/dist/coverage/lcov-report/src/api/FugitiveEmission.ts.html +214 -0
  41. package/dist/coverage/lcov-report/src/api/GenericCalculation.ts.html +217 -0
  42. package/dist/coverage/lcov-report/src/api/Location.ts.html +214 -0
  43. package/dist/coverage/lcov-report/src/api/LocationEmission.ts.html +214 -0
  44. package/dist/coverage/lcov-report/src/api/Mobile.ts.html +220 -0
  45. package/dist/coverage/lcov-report/src/api/MobileEmission.ts.html +220 -0
  46. package/dist/coverage/lcov-report/src/api/Stationary.ts.html +220 -0
  47. package/dist/coverage/lcov-report/src/api/StationaryEmission.ts.html +220 -0
  48. package/dist/coverage/lcov-report/src/api/TransportationAndDistribution.ts.html +211 -0
  49. package/dist/coverage/lcov-report/src/api/TransportationDistributionEmission.ts.html +211 -0
  50. package/dist/coverage/lcov-report/src/api/index.html +221 -0
  51. package/dist/coverage/lcov-report/src/index.html +161 -0
  52. package/dist/coverage/lcov-report/src/request.ts.html +235 -0
  53. package/dist/coverage/lcov-report/src/utils.ts.html +139 -0
  54. package/dist/coverage/lcov-report/test/index.html +116 -0
  55. package/dist/coverage/lcov-report/test/mocks/CommonRequest.ts.html +142 -0
  56. package/dist/coverage/lcov-report/test/mocks/FactorRequest.ts.html +133 -0
  57. package/dist/coverage/lcov-report/test/mocks/GenericCalculationRequest.ts.html +142 -0
  58. package/dist/coverage/lcov-report/test/mocks/LocationRequest.ts.html +139 -0
  59. package/dist/coverage/lcov-report/test/mocks/SearchRequest.ts.html +142 -0
  60. package/dist/coverage/lcov-report/test/mocks/index.html +176 -0
  61. package/dist/coverage/lcov-report/test/testUtils.ts.html +97 -0
  62. package/dist/coverage/lcov.info +404 -0
  63. package/dist/index.js +46 -0
  64. package/dist/interfaces/Api.js +2 -0
  65. package/dist/interfaces/Config.js +2 -0
  66. package/dist/interfaces/common.js +2 -0
  67. package/dist/request.js +51 -0
  68. package/dist/types/Client.d.ts +146 -0
  69. package/dist/types/Constants.d.ts +16 -0
  70. package/dist/types/api/Calculation.d.ts +28 -0
  71. package/dist/types/api/Factor.d.ts +57 -0
  72. package/dist/types/api/FactorSets.d.ts +11 -0
  73. package/dist/types/api/Factors.d.ts +68 -0
  74. package/dist/types/api/Fugitive.d.ts +27 -0
  75. package/dist/types/api/FugitiveEmission.d.ts +27 -0
  76. package/dist/types/api/GenericCalculation.d.ts +28 -0
  77. package/dist/types/api/Location.d.ts +28 -0
  78. package/dist/types/api/LocationEmission.d.ts +28 -0
  79. package/dist/types/api/Mobile.d.ts +28 -0
  80. package/dist/types/api/MobileEmission.d.ts +28 -0
  81. package/dist/types/api/Stationary.d.ts +28 -0
  82. package/dist/types/api/StationaryEmission.d.ts +28 -0
  83. package/dist/types/api/TransportationAndDistribution.d.ts +27 -0
  84. package/dist/types/api/TransportationDistributionEmission.d.ts +27 -0
  85. package/dist/types/index.d.ts +10 -0
  86. package/dist/types/interfaces/Api.d.ts +286 -0
  87. package/dist/types/interfaces/Config.d.ts +66 -0
  88. package/dist/types/interfaces/common.d.ts +152 -0
  89. package/dist/types/request.d.ts +25 -0
  90. package/dist/types/utils.d.ts +14 -0
  91. package/dist/utils.js +23 -0
  92. package/jest.config.js +9 -0
  93. package/package.json +50 -0
  94. package/src/Client.ts +252 -0
  95. package/src/Constants.ts +16 -0
  96. package/src/api/Calculation.ts +44 -0
  97. package/src/api/Factor.ts +86 -0
  98. package/src/api/FactorSets.ts +24 -0
  99. package/src/api/Fugitive.ts +43 -0
  100. package/src/api/Location.ts +43 -0
  101. package/src/api/Mobile.ts +45 -0
  102. package/src/api/Stationary.ts +45 -0
  103. package/src/api/TransportationAndDistribution.ts +42 -0
  104. package/src/index.ts +10 -0
  105. package/src/interfaces/Api.ts +300 -0
  106. package/src/interfaces/Config.ts +78 -0
  107. package/src/interfaces/common.ts +174 -0
  108. package/src/request.ts +50 -0
  109. package/src/utils.ts +19 -0
  110. package/test/apiTest.test.ts +168 -0
  111. package/test/client.test.ts +82 -0
  112. package/test/mocks/CommonRequest.ts +19 -0
  113. package/test/mocks/FactorRequest.ts +16 -0
  114. package/test/mocks/GenericCalculationRequest.ts +19 -0
  115. package/test/mocks/LocationRequest.ts +19 -0
  116. package/test/mocks/SearchRequest.ts +19 -0
  117. package/test/request.test.ts +111 -0
  118. package/test/testUtils.ts +5 -0
  119. package/test/tokenRefresh.test.ts +52 -0
  120. package/tsconfig.json +15 -0
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CLIENT_SOURCE_SDK = exports.CLIENT_SOURCE_EXCEL = exports.CLIENT_SOURCE_HEADER = exports.POST = exports.GET = exports.SEARCH_API_PATH = exports.FACTOR_SET_API_PATH = exports.FACTOR_API_PATH = exports.TRANSPORTATION_AND_DISTRIBUTION_API_PATH = exports.GENERIC_CALCULATION_API_PATH = exports.STATIONARY_API_PATH = exports.FUGITIVE_API_PATH = exports.LOCATION_API_PATH = exports.MOBILE_API_PATH = exports.TOKEN_GENERATION_API = exports.API_DOMAIN = void 0;
4
+ exports.API_DOMAIN = "https://api.ibm.com/ghgemissions/run";
5
+ exports.TOKEN_GENERATION_API = "https://api.ibm.com/saascore/run/authentication-retrieve/api-key";
6
+ exports.MOBILE_API_PATH = "/v3/carbon/mobile";
7
+ exports.LOCATION_API_PATH = "/v3/carbon/location";
8
+ exports.FUGITIVE_API_PATH = "/v3/carbon/fugitive";
9
+ exports.STATIONARY_API_PATH = "/v3/carbon/stationary";
10
+ exports.GENERIC_CALCULATION_API_PATH = "/v3/carbon/calculation";
11
+ exports.TRANSPORTATION_AND_DISTRIBUTION_API_PATH = "/v3/carbon/transportation-and-distribution";
12
+ exports.FACTOR_API_PATH = "/v3/carbon/factor";
13
+ exports.FACTOR_SET_API_PATH = "/v3/carbon/factorset";
14
+ exports.SEARCH_API_PATH = "/v3/carbon/factor/search";
15
+ exports.GET = "GET";
16
+ exports.POST = "POST";
17
+ exports.CLIENT_SOURCE_HEADER = "X-Client-Source";
18
+ exports.CLIENT_SOURCE_EXCEL = "excel";
19
+ exports.CLIENT_SOURCE_SDK = "node-sdk";
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculate = calculate;
4
+ const Client_1 = require("../Client");
5
+ const Constants_1 = require("../Constants");
6
+ const request_1 = require("../request");
7
+ /**
8
+ * Performs emission calculations by making a POST request to the generic calculation API endpoint.
9
+ *
10
+ * @export
11
+ * @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
13
+ * @throws {Error} May throw an error if the API request fails
14
+ *
15
+ * @example
16
+ * 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
+ };
31
+ * const result = await calculate(calculationRequest);
32
+ */
33
+ async function calculate(payload) {
34
+ const client = Client_1.Client.getInstance();
35
+ const url = client.getDomain() + Constants_1.GENERIC_CALCULATION_API_PATH;
36
+ return (0, request_1.makeApiRequest)({
37
+ method: Constants_1.POST,
38
+ url,
39
+ data: payload,
40
+ });
41
+ }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.retrieveFactor = retrieveFactor;
4
+ exports.search = search;
5
+ const Client_1 = require("../Client");
6
+ const Constants_1 = require("../Constants");
7
+ const request_1 = require("../request");
8
+ /**
9
+ * Retrieves a factor details by making a POST request to the factor API endpoint.
10
+ *
11
+ * @export
12
+ * @param {FactorRequest} payload - The factor request data to be sent to the API
13
+ * @return {Promise<string>} A promise that resolves to the factor string returned by the API
14
+ * @throws {Error} May throw an error if the API request fails
15
+ *
16
+ * @example
17
+ * const factorRequest = {
18
+
19
+ "activity": {
20
+ "factorId": 12345
21
+ }
22
+ };
23
+
24
+ or
25
+
26
+ const factorRequest = {
27
+ "time" : {
28
+ "date": "2025-01-04"
29
+ },
30
+ "location": {
31
+ "country": "usa",
32
+ "stateProvince": "new york"
33
+ },
34
+ "activity": {
35
+ "type":"natural gas"
36
+ },
37
+ "includeDetails": true
38
+ };
39
+ * const factor = await retrieveFactor(factorRequest);
40
+ */
41
+ async function retrieveFactor(payload) {
42
+ const client = Client_1.Client.getInstance();
43
+ const url = client.getDomain() + Constants_1.FACTOR_API_PATH;
44
+ return (0, request_1.makeApiRequest)({
45
+ method: Constants_1.POST,
46
+ url,
47
+ data: payload,
48
+ });
49
+ }
50
+ /**
51
+ * Performs a search operation by making a POST request to the search API endpoint.
52
+ *
53
+ * @export
54
+ * @param {SearchRequest} payload - The search request data to be sent to the API
55
+ * @return {Promise<string>} A promise that resolves to the search results string returned by the API
56
+ * @throws {Error} May throw an error if the API request fails
57
+ *
58
+ * @example
59
+ * const searchRequest = {
60
+ "time":{
61
+ "date": "2020-06-10"
62
+ },
63
+ "activity": {
64
+ "search" : "travel"},
65
+ "location": {
66
+ "country": "USA"
67
+ }
68
+ };
69
+ * const results = await search(searchRequest);
70
+ */
71
+ async function search(payload) {
72
+ const client = Client_1.Client.getInstance();
73
+ const url = client.getDomain() + Constants_1.SEARCH_API_PATH;
74
+ return (0, request_1.makeApiRequest)({
75
+ method: Constants_1.POST,
76
+ url,
77
+ data: payload,
78
+ });
79
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.get = get;
4
+ const Client_1 = require("../Client");
5
+ const Constants_1 = require("../Constants");
6
+ const request_1 = require("../request");
7
+ /**
8
+ * Retrieves factor sets by making a GET request to the factor set API endpoint.
9
+ *
10
+ * @export
11
+ * @return {Promise<string>} A promise that resolves to the factor sets string returned by the API
12
+ * @throws {Error} May throw an error if the API request fails
13
+ *
14
+ * @example
15
+ * const factorSets = await get();
16
+ */
17
+ async function get() {
18
+ const client = Client_1.Client.getInstance();
19
+ const url = client.getDomain() + Constants_1.FACTOR_SET_API_PATH;
20
+ return (0, request_1.makeApiRequest)({
21
+ method: Constants_1.GET,
22
+ url
23
+ });
24
+ }
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.retrieveFactor = retrieveFactor;
4
+ exports.getFactorSets = getFactorSets;
5
+ exports.Search = Search;
6
+ const Client_1 = require("../Client");
7
+ const Constants_1 = require("../Constants");
8
+ const request_1 = require("../request");
9
+ /**
10
+ * Retrieves a factor details by making a POST request to the factor API endpoint.
11
+ *
12
+ * @export
13
+ * @param {FactorRequest} payload - The factor request data to be sent to the API
14
+ * @return {Promise<string>} A promise that resolves to the factor string returned by the API
15
+ * @throws {Error} May throw an error if the API request fails
16
+ *
17
+ * @example
18
+ * const factorRequest = {
19
+
20
+ "activity": {
21
+ "factorId": 12345
22
+ }
23
+ };
24
+
25
+ or
26
+
27
+ const factorRequest = {
28
+ "time" : {
29
+ "date": "2025-01-04"
30
+ },
31
+ "location": {
32
+ "country": "usa",
33
+ "stateProvince": "new york"
34
+ },
35
+ "activity": {
36
+ "type":"natural gas"
37
+ },
38
+ "includeDetails": true
39
+ };
40
+ * const factor = await retrieveFactor(factorRequest);
41
+ */
42
+ async function retrieveFactor(payload) {
43
+ const client = Client_1.Client.getInstance();
44
+ const url = client.getDomain() + Constants_1.FACTOR_API_PATH;
45
+ return (0, request_1.makeApiRequest)({
46
+ method: Constants_1.POST,
47
+ url,
48
+ data: payload,
49
+ });
50
+ }
51
+ /**
52
+ * Retrieves factor sets by making a GET request to the factor set API endpoint.
53
+ *
54
+ * @export
55
+ * @return {Promise<string>} A promise that resolves to the factor sets string returned by the API
56
+ * @throws {Error} May throw an error if the API request fails
57
+ *
58
+ * @example
59
+ * const factorSets = await getFactorSets();
60
+ */
61
+ async function getFactorSets() {
62
+ const client = Client_1.Client.getInstance();
63
+ const url = client.getDomain() + Constants_1.FACTOR_SET_API_PATH;
64
+ return (0, request_1.makeApiRequest)({
65
+ method: Constants_1.GET,
66
+ url
67
+ });
68
+ }
69
+ /**
70
+ * Performs a search operation by making a POST request to the search API endpoint.
71
+ *
72
+ * @export
73
+ * @param {SearchRequest} payload - The search request data to be sent to the API
74
+ * @return {Promise<string>} A promise that resolves to the search results string returned by the API
75
+ * @throws {Error} May throw an error if the API request fails
76
+ *
77
+ * @example
78
+ * const searchRequest = {
79
+ "time":{
80
+ "date": "2020-06-10"
81
+ },
82
+ "activity": {
83
+ "search" : "travel"},
84
+ "location": {
85
+ "country": "USA"
86
+ }
87
+ };
88
+ * const results = await Search(searchRequest);
89
+ */
90
+ async function Search(payload) {
91
+ const client = Client_1.Client.getInstance();
92
+ const url = client.getDomain() + Constants_1.SEARCH_API_PATH;
93
+ return (0, request_1.makeApiRequest)({
94
+ method: Constants_1.POST,
95
+ url,
96
+ data: payload,
97
+ });
98
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculate = calculate;
4
+ const Client_1 = require("../Client");
5
+ const Constants_1 = require("../Constants");
6
+ const request_1 = require("../request");
7
+ /**
8
+ * Performs scope 1 fugitve emission calculations by making a POST request to the fugitive API endpoint.
9
+ *
10
+ * @export
11
+ * @param {CommonRequest} payload - The 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
13
+ * @throws {Error} May throw an error if the API request fails
14
+ *
15
+ * @example
16
+ * const request = {
17
+ "time": {
18
+ "date": "2025-01-04"
19
+ },
20
+ "location": {
21
+ "country": "usa"
22
+ },
23
+ "activity": {
24
+ "type": "R134A",
25
+ "value": 150,
26
+ "unit": "kg"
27
+ },
28
+ "includeDetails": false
29
+ };
30
+ * const result = await calculate(request);
31
+ */
32
+ async function calculate(payload) {
33
+ const client = Client_1.Client.getInstance();
34
+ const url = client.getDomain() + Constants_1.FUGITIVE_API_PATH;
35
+ return (0, request_1.makeApiRequest)({
36
+ method: Constants_1.POST,
37
+ url,
38
+ data: payload,
39
+ });
40
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculate = calculate;
4
+ const Client_1 = require("../Client");
5
+ const Constants_1 = require("../Constants");
6
+ const request_1 = require("../request");
7
+ /**
8
+ * Performs scope 1 fugitve emission calculations by making a POST request to the fugitive API endpoint.
9
+ *
10
+ * @export
11
+ * @param {CommonRequest} payload - The 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
13
+ * @throws {Error} May throw an error if the API request fails
14
+ *
15
+ * @example
16
+ * const request = {
17
+ "time": {
18
+ "date": "2025-01-04"
19
+ },
20
+ "location": {
21
+ "country": "usa"
22
+ },
23
+ "activity": {
24
+ "type": "R134A",
25
+ "value": 150,
26
+ "unit": "kg"
27
+ },
28
+ "includeDetails": false
29
+ };
30
+ * const result = await calculate(request);
31
+ */
32
+ async function calculate(payload) {
33
+ const client = Client_1.Client.getInstance();
34
+ const url = client.getDomain() + Constants_1.FUGITIVE_API_PATH;
35
+ return (0, request_1.makeApiRequest)({
36
+ method: Constants_1.POST,
37
+ url,
38
+ data: payload,
39
+ });
40
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculate = calculate;
4
+ const Client_1 = require("../Client");
5
+ const Constants_1 = require("../Constants");
6
+ const request_1 = require("../request");
7
+ /**
8
+ * Performs emission calculations by making a POST request to the generic calculation API endpoint.
9
+ *
10
+ * @export
11
+ * @param {GenericCalculationRequest} 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
13
+ * @throws {Error} May throw an error if the API request fails
14
+ *
15
+ * @example
16
+ * 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
+ };
31
+ * const result = await calculate(calculationRequest);
32
+ */
33
+ async function calculate(payload) {
34
+ const client = Client_1.Client.getInstance();
35
+ const url = client.getDomain() + Constants_1.GENERIC_CALCULATION_API_PATH;
36
+ return (0, request_1.makeApiRequest)({
37
+ method: Constants_1.POST,
38
+ url,
39
+ data: payload,
40
+ });
41
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculate = calculate;
4
+ const Client_1 = require("../Client");
5
+ const Constants_1 = require("../Constants");
6
+ const request_1 = require("../request");
7
+ /**
8
+ * Performs scope 2 purchased energy Emission calculations by making a POST request to the location API endpoint.
9
+ *
10
+ * @export
11
+ * @param {LocationRequest} payload - The location request data to be sent to the API
12
+ * @return {Promise<string>} A promise that resolves to the purchased energy emission result string returned by the API
13
+ * @throws {Error} May throw an error if the API request fails
14
+ *
15
+ * @example
16
+ * const calculationRequest = {
17
+ "time" : {
18
+ "date": "2025-01-04"
19
+ },
20
+ "location": {
21
+ "country": "usa",
22
+ "stateProvince": "new york"
23
+ },
24
+ "activity": {
25
+ "type":"electricity",
26
+ "unit": "kwh",
27
+ "value": 14123143
28
+ },
29
+ "includeDetails": true
30
+ };
31
+ * const result = await calculate(calculationRequest);
32
+ */
33
+ async function calculate(payload) {
34
+ const client = Client_1.Client.getInstance();
35
+ const url = client.getDomain() + Constants_1.LOCATION_API_PATH;
36
+ return (0, request_1.makeApiRequest)({
37
+ method: Constants_1.POST,
38
+ url,
39
+ data: payload,
40
+ });
41
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculate = calculate;
4
+ const Client_1 = require("../Client");
5
+ const Constants_1 = require("../Constants");
6
+ const request_1 = require("../request");
7
+ /**
8
+ * Performs scope 2 purchased energy Emission calculations by making a POST request to the location API endpoint.
9
+ *
10
+ * @export
11
+ * @param {LocationRequest} payload - The location request data to be sent to the API
12
+ * @return {Promise<string>} A promise that resolves to the purchased energy emission result string returned by the API
13
+ * @throws {Error} May throw an error if the API request fails
14
+ *
15
+ * @example
16
+ * const calculationRequest = {
17
+ "time" : {
18
+ "date": "2025-01-04"
19
+ },
20
+ "location": {
21
+ "country": "usa",
22
+ "stateProvince": "new york"
23
+ },
24
+ "activity": {
25
+ "type":"electricity",
26
+ "unit": "kwh",
27
+ "value": 14123143
28
+ },
29
+ "includeDetails": true
30
+ };
31
+ * const result = await calculate(calculationRequest);
32
+ */
33
+ async function calculate(payload) {
34
+ const client = Client_1.Client.getInstance();
35
+ const url = client.getDomain() + Constants_1.LOCATION_API_PATH;
36
+ return (0, request_1.makeApiRequest)({
37
+ method: Constants_1.POST,
38
+ url,
39
+ data: payload,
40
+ });
41
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculate = calculate;
4
+ const request_1 = require("../request");
5
+ const Constants_1 = require("../Constants");
6
+ const Client_1 = require("../Client");
7
+ /**
8
+ * Performs Scope 1 mobile emissions related calculations by making a POST request to the mobile API endpoint.
9
+ *
10
+ * @export
11
+ * @param {CommonRequest} payload - The request data to be sent to the mobile API
12
+ * @return {Promise<string>} A promise that resolves to the calculation result string returned by the API
13
+ * @throws {Error} May throw an error if the API request fails
14
+ *
15
+ * @example
16
+ * const request = {
17
+ "time": {
18
+ "date": "2022-01-01"
19
+ },
20
+ "location": {
21
+ "country": "USA",
22
+ "stateProvince": "new york"
23
+ },
24
+ "activity": {
25
+ "type": "Diesel Fuel",
26
+ "value": 1500000,
27
+ "unit": "l"
28
+ },
29
+ "includeDetails": false
30
+ };
31
+ * const result = await calculate(request);
32
+ */
33
+ async function calculate(payload) {
34
+ const client = Client_1.Client.getInstance();
35
+ const url = client.getDomain() + Constants_1.MOBILE_API_PATH;
36
+ return (0, request_1.makeApiRequest)({
37
+ method: Constants_1.POST,
38
+ url,
39
+ data: payload,
40
+ });
41
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculate = calculate;
4
+ const request_1 = require("../request");
5
+ const Constants_1 = require("../Constants");
6
+ const Client_1 = require("../Client");
7
+ /**
8
+ * Performs Scope 1 mobile emissions related calculations by making a POST request to the mobile API endpoint.
9
+ *
10
+ * @export
11
+ * @param {CommonRequest} payload - The request data to be sent to the mobile API
12
+ * @return {Promise<string>} A promise that resolves to the calculation result string returned by the API
13
+ * @throws {Error} May throw an error if the API request fails
14
+ *
15
+ * @example
16
+ * const request = {
17
+ "time": {
18
+ "date": "2022-01-01"
19
+ },
20
+ "location": {
21
+ "country": "USA",
22
+ "stateProvince": "new york"
23
+ },
24
+ "activity": {
25
+ "type": "Diesel Fuel",
26
+ "value": 1500000,
27
+ "unit": "l"
28
+ },
29
+ "includeDetails": false
30
+ };
31
+ * const result = await calculate(request);
32
+ */
33
+ async function calculate(payload) {
34
+ const client = Client_1.Client.getInstance();
35
+ const url = client.getDomain() + Constants_1.MOBILE_API_PATH;
36
+ return (0, request_1.makeApiRequest)({
37
+ method: Constants_1.POST,
38
+ url,
39
+ data: payload,
40
+ });
41
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculate = calculate;
4
+ const Client_1 = require("../Client");
5
+ const Constants_1 = require("../Constants");
6
+ const request_1 = require("../request");
7
+ /**
8
+ * Performs Scope 1 stationary calculations by making a POST request to the stationary API endpoint.
9
+ *
10
+ * @export
11
+ * @param {CommonRequest} payload - The request data to be sent to the stationary API
12
+ * @return {Promise<string>} A promise that resolves to the calculation result string returned by the API
13
+ * @throws {Error} May throw an error if the API request fails
14
+ *
15
+ * @example
16
+ * const request = {
17
+ "time" : {
18
+ "date": "2025-01-04"
19
+ },
20
+ "location": {
21
+ "country": "usa",
22
+ "stateProvince": "new york"
23
+ },
24
+ "activity": {
25
+ "type":"Coal - Lignite",
26
+ "unit": "KJ",
27
+ "value": 3
28
+ },
29
+ "includeDetails": true
30
+ };
31
+ * const result = await calculate(request);
32
+ */
33
+ async function calculate(payload) {
34
+ const client = Client_1.Client.getInstance();
35
+ const url = client.getDomain() + Constants_1.STATIONARY_API_PATH;
36
+ return (0, request_1.makeApiRequest)({
37
+ method: Constants_1.POST,
38
+ url,
39
+ data: payload,
40
+ });
41
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculate = calculate;
4
+ const Client_1 = require("../Client");
5
+ const Constants_1 = require("../Constants");
6
+ const request_1 = require("../request");
7
+ /**
8
+ * Performs Scope 1 stationary calculations by making a POST request to the stationary API endpoint.
9
+ *
10
+ * @export
11
+ * @param {CommonRequest} payload - The request data to be sent to the stationary API
12
+ * @return {Promise<string>} A promise that resolves to the calculation result string returned by the API
13
+ * @throws {Error} May throw an error if the API request fails
14
+ *
15
+ * @example
16
+ * const request = {
17
+ "time" : {
18
+ "date": "2025-01-04"
19
+ },
20
+ "location": {
21
+ "country": "usa",
22
+ "stateProvince": "new york"
23
+ },
24
+ "activity": {
25
+ "type":"Coal - Lignite",
26
+ "unit": "KJ",
27
+ "value": 3
28
+ },
29
+ "includeDetails": true
30
+ };
31
+ * const result = await calculate(request);
32
+ */
33
+ async function calculate(payload) {
34
+ const client = Client_1.Client.getInstance();
35
+ const url = client.getDomain() + Constants_1.STATIONARY_API_PATH;
36
+ return (0, request_1.makeApiRequest)({
37
+ method: Constants_1.POST,
38
+ url,
39
+ data: payload,
40
+ });
41
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculate = calculate;
4
+ const Client_1 = require("../Client");
5
+ const Constants_1 = require("../Constants");
6
+ const request_1 = require("../request");
7
+ /**
8
+ * Performs Scope 2 transportation and distribution emission calculations by making a POST request to the transportation and distribution API endpoint.
9
+ *
10
+ * @export
11
+ * @param {CalculationRequest} payload - The calculation request data for transportation and distribution operations
12
+ * @return {Promise<string>} A promise that resolves to the calculation result string returned by the API
13
+ * @throws {Error} May throw an error if the API request fails
14
+ *
15
+ * @example
16
+ * const request = {
17
+ "time" : {
18
+ "date": "2025-01-04"
19
+ },
20
+ "location": {
21
+ "country": "usa"
22
+ },
23
+ "activity": {
24
+ "type": "Freight - Cargo Ship - Bulk Carrier - 0-9999 dwt",
25
+ "unit": ["t","km"],
26
+ "value": [1.0,1.0]
27
+ },
28
+ "includeDetails": true
29
+ };
30
+ * const result = await calculate(request);
31
+ */
32
+ async function calculate(payload) {
33
+ const client = Client_1.Client.getInstance();
34
+ const url = client.getDomain() + Constants_1.TRANSPORTATION_AND_DISTRIBUTION_API_PATH;
35
+ return (0, request_1.makeApiRequest)({
36
+ method: Constants_1.POST,
37
+ url,
38
+ data: payload,
39
+ });
40
+ }