emissions-api-sdk 1.0.11 → 1.0.13

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 (101) hide show
  1. package/README.md +157 -0
  2. package/dist/Constants.js +4 -1
  3. package/dist/api/AuditLog.js +99 -0
  4. package/dist/api/EconomicActivity.js +24 -0
  5. package/dist/api/Factor.js +72 -1
  6. package/dist/api/PhysicalActivity.js +87 -0
  7. package/dist/api/RealEstate.js +23 -0
  8. package/dist/api/TypeRecommender.js +67 -2
  9. package/dist/coverage/clover.xml +154 -89
  10. package/dist/coverage/coverage-final.json +15 -9
  11. package/dist/coverage/lcov-report/index.html +21 -21
  12. package/dist/coverage/lcov-report/src/Client.ts.html +32 -32
  13. package/dist/coverage/lcov-report/src/Constants.ts.html +36 -27
  14. package/dist/coverage/lcov-report/src/api/AuditLog.ts.html +388 -0
  15. package/dist/coverage/lcov-report/src/api/Calculation.ts.html +1 -1
  16. package/dist/coverage/lcov-report/src/api/EconomicActivity.ts.html +77 -5
  17. package/dist/coverage/lcov-report/src/api/Factor.ts.html +216 -3
  18. package/dist/coverage/lcov-report/src/api/FactorSets.ts.html +1 -1
  19. package/dist/coverage/lcov-report/src/api/Fugitive.ts.html +1 -1
  20. package/dist/coverage/lcov-report/src/api/Location.ts.html +1 -1
  21. package/dist/coverage/lcov-report/src/api/Metadata.ts.html +1 -1
  22. package/dist/coverage/lcov-report/src/api/Mobile.ts.html +1 -1
  23. package/dist/coverage/lcov-report/src/api/PhysicalActivity.ts.html +361 -0
  24. package/dist/coverage/lcov-report/src/api/RealEstate.ts.html +74 -5
  25. package/dist/coverage/lcov-report/src/api/Stationary.ts.html +1 -1
  26. package/dist/coverage/lcov-report/src/api/TransportationAndDistribution.ts.html +1 -1
  27. package/dist/coverage/lcov-report/src/api/TypeRecommender.ts.html +199 -4
  28. package/dist/coverage/lcov-report/src/api/Usage.ts.html +1 -1
  29. package/dist/coverage/lcov-report/src/api/index.html +36 -6
  30. package/dist/coverage/lcov-report/src/index.html +7 -7
  31. package/dist/coverage/lcov-report/src/request.ts.html +5 -5
  32. package/dist/coverage/lcov-report/src/utils.ts.html +6 -6
  33. package/dist/coverage/lcov-report/test/index.html +1 -1
  34. package/dist/coverage/lcov-report/test/mocks/AttributionRequest.ts.html +151 -0
  35. package/dist/coverage/lcov-report/test/mocks/CommonRequest.ts.html +1 -1
  36. package/dist/coverage/lcov-report/test/mocks/EconomicActivityAttributionRequest.ts.html +148 -0
  37. package/dist/coverage/lcov-report/test/mocks/FactorRequest.ts.html +1 -1
  38. package/dist/coverage/lcov-report/test/mocks/GenericCalculationRequest.ts.html +1 -1
  39. package/dist/coverage/lcov-report/test/mocks/LocationRequest.ts.html +1 -1
  40. package/dist/coverage/lcov-report/test/mocks/PhysicalActivityEVICRequest.ts.html +148 -0
  41. package/dist/coverage/lcov-report/test/mocks/PhysicalActivityRequest.ts.html +151 -0
  42. package/dist/coverage/lcov-report/test/mocks/SearchRequest.ts.html +148 -4
  43. package/dist/coverage/lcov-report/test/mocks/index.html +64 -4
  44. package/dist/coverage/lcov-report/test/testUtils.ts.html +1 -1
  45. package/dist/coverage/lcov.info +254 -124
  46. package/dist/index.js +3 -1
  47. package/dist/interfaces/response/AuditLogResponse.js +2 -0
  48. package/dist/types/Constants.d.ts +3 -0
  49. package/dist/types/api/AuditLog.d.ts +37 -0
  50. package/dist/types/api/EconomicActivity.d.ts +24 -0
  51. package/dist/types/api/Factor.d.ts +72 -1
  52. package/dist/types/api/PhysicalActivity.d.ts +76 -0
  53. package/dist/types/api/RealEstate.d.ts +23 -0
  54. package/dist/types/api/TypeRecommender.d.ts +67 -2
  55. package/dist/types/index.d.ts +4 -0
  56. package/dist/types/interfaces/Api.d.ts +17 -1
  57. package/dist/types/interfaces/common.d.ts +48 -0
  58. package/dist/types/interfaces/response/AuditLogResponse.d.ts +40 -0
  59. package/dist/types/interfaces/response/TypeRecommenderResponse.d.ts +1 -0
  60. package/docs/_sources/authentication.rst.txt +26 -4
  61. package/docs/_sources/getting_started.rst.txt +538 -74
  62. package/docs/_sources/index.rst.txt +11 -0
  63. package/docs/_sources/reference.rst.txt +26 -0
  64. package/docs/_sources/troubleshooting.rst.txt +77 -12
  65. package/docs/_static/base-stemmer.js +476 -0
  66. package/docs/_static/english-stemmer.js +1066 -0
  67. package/docs/authentication.html +31 -5
  68. package/docs/client.html +3 -1
  69. package/docs/genindex.html +22 -2
  70. package/docs/getting_started.html +715 -82
  71. package/docs/index.html +35 -0
  72. package/docs/reference.html +412 -3
  73. package/docs/sdk.html +2 -0
  74. package/docs/search.html +2 -0
  75. package/docs/searchindex.js +1 -1
  76. package/docs/troubleshooting.html +75 -17
  77. package/package.json +7 -3
  78. package/sphinx-build/source/authentication.rst +26 -4
  79. package/sphinx-build/source/getting_started.rst +538 -74
  80. package/sphinx-build/source/index.rst +11 -0
  81. package/sphinx-build/source/reference.rst +26 -0
  82. package/sphinx-build/source/troubleshooting.rst +77 -12
  83. package/src/Constants.ts +3 -0
  84. package/src/api/AuditLog.ts +102 -0
  85. package/src/api/EconomicActivity.ts +24 -0
  86. package/src/api/Factor.ts +72 -1
  87. package/src/api/PhysicalActivity.ts +92 -0
  88. package/src/api/RealEstate.ts +23 -0
  89. package/src/api/TypeRecommender.ts +67 -2
  90. package/src/index.ts +7 -1
  91. package/src/interfaces/Api.ts +22 -6
  92. package/src/interfaces/common.ts +58 -0
  93. package/src/interfaces/response/AuditLogResponse.ts +47 -0
  94. package/src/interfaces/response/TypeRecommenderResponse.ts +2 -0
  95. package/test/apiTest.test.ts +59 -3
  96. package/test/auditLog.test.ts +216 -0
  97. package/test/mocks/AttributionRequest.ts +23 -0
  98. package/test/mocks/EconomicActivityAttributionRequest.ts +22 -0
  99. package/test/mocks/PhysicalActivityEVICRequest.ts +22 -0
  100. package/test/mocks/PhysicalActivityRequest.ts +23 -0
  101. package/test/mocks/SearchRequest.ts +48 -0
package/README.md CHANGED
@@ -69,6 +69,145 @@ const typeUnits = await Metadata.getUnits('Natural Gas'); // Units for specific
69
69
 
70
70
  **Supported endpoints**: `calculation`, `location`, `stationary`, `mobile`, `fugitive`, `factor`, `search`, `transportation-and-distribution`, `economic-activity`, `real-estate`
71
71
 
72
+
73
+ ## Type Recommender API
74
+
75
+ Search for activity types using semantic search with optional unit and scope filtering. Reranking is enabled by default; set `enableReranker` to `false` to use semantic similarity ordering without cross-encoder reranking. Type results can include `scope`, the distinct GHG Protocol scopes associated with each activity type.
76
+
77
+ ```javascript
78
+ import { TypeRecommender } from 'emissions-api-sdk';
79
+
80
+ // Basic search with natural language
81
+ const types = await TypeRecommender.search({
82
+ "location": {
83
+ "country": "usa"
84
+ },
85
+ "activity": {
86
+ "search": "employee travelled by electric vehicle"
87
+ }
88
+ });
89
+
90
+ // Search with unit filter
91
+ const typesWithUnit = await TypeRecommender.search({
92
+ "location": {
93
+ "country": "usa"
94
+ },
95
+ "activity": {
96
+ "search": "office consumed electricity",
97
+ "unit": "kWh"
98
+ }
99
+ });
100
+
101
+ // Search without cross-encoder reranking
102
+ const typesWithoutReranker = await TypeRecommender.search({
103
+ "location": {
104
+ "country": "usa"
105
+ },
106
+ "activity": {
107
+ "search": "office consumed electricity"
108
+ },
109
+ "enableReranker": false
110
+ });
111
+
112
+ // Search with scope filter
113
+ const typesWithScope = await TypeRecommender.search({
114
+ "location": {
115
+ "country": "usa"
116
+ },
117
+ "activity": {
118
+ "search": "heating with natural gas",
119
+ "scope": "1"
120
+ }
121
+ });
122
+
123
+ // Search with pagination and filters
124
+ const typesWithAll = await TypeRecommender.search({
125
+ "location": {
126
+ "country": "usa",
127
+ "stateProvince": "california"
128
+ },
129
+ "time": {
130
+ "date": "2025-06-10"
131
+ },
132
+ "activity": {
133
+ "search": "purchased electricity for data center",
134
+ "unit": "MWh",
135
+ "scope": "2"
136
+ },
137
+ "pagination": {
138
+ "page": 1,
139
+ "size": 10
140
+ }
141
+ });
142
+ ```
143
+
144
+ ## Factor Search API
145
+
146
+ Search for emission factors with optional unit and scope filtering. Reranking is enabled by default; set `enableReranker` to `false` to use semantic similarity ordering without cross-encoder reranking.
147
+
148
+ ```javascript
149
+ import { Factor } from 'emissions-api-sdk';
150
+
151
+ // Basic search with natural language
152
+ const results = await Factor.search({
153
+ "time": {
154
+ "date": "2020-06-10"
155
+ },
156
+ "activity": {
157
+ "search": "employee business travel by air"
158
+ },
159
+ "location": {
160
+ "country": "USA"
161
+ }
162
+ });
163
+
164
+ // Search with unit filter
165
+ const resultsWithUnit = await Factor.search({
166
+ "activity": {
167
+ "search": "office electricity consumption",
168
+ "unit": "kWh"
169
+ },
170
+ "location": {
171
+ "country": "USA"
172
+ }
173
+ });
174
+
175
+ // Search without cross-encoder reranking
176
+ const resultsWithoutReranker = await Factor.search({
177
+ "activity": {
178
+ "search": "employee business travel by air"
179
+ },
180
+ "location": {
181
+ "country": "USA"
182
+ },
183
+ "enableReranker": false
184
+ });
185
+
186
+ // Search with scope filter
187
+ const resultsWithScope = await Factor.search({
188
+ "activity": {
189
+ "search": "facility heating with natural gas",
190
+ "scope": "1"
191
+ },
192
+ "location": {
193
+ "country": "USA"
194
+ }
195
+ });
196
+
197
+ // Search with both unit and scope
198
+ const resultsWithBoth = await Factor.search({
199
+ "activity": {
200
+ "search": "purchased electricity for manufacturing",
201
+ "unit": "MWh",
202
+ "scope": "2"
203
+ },
204
+ "location": {
205
+ "country": "USA",
206
+ "stateProvince": "california"
207
+ }
208
+ });
209
+ ```
210
+
72
211
  ### Get Organization Usage
73
212
  ```javascript
74
213
  import { Usage } from 'emissions-api-sdk';
@@ -78,6 +217,24 @@ import { Usage } from 'emissions-api-sdk';
78
217
  const usage = await Usage.getUsage(true);
79
218
  ```
80
219
 
220
+ ## Audit Log API
221
+
222
+ Controls whether the organization's API requests and responses are stored for auditing. Organizations can disable storage if they don't need their API calls to be audited.
223
+
224
+ ```javascript
225
+ import { AuditLog } from 'emissions-api-sdk';
226
+
227
+ // Get current configuration
228
+ const config = await AuditLog.getConfig();
229
+ console.log(config); // { logRequest: true, logResponse: true }
230
+
231
+ // Disable storage
232
+ await AuditLog.update({ logRequest: false, logResponse: false });
233
+
234
+ // Enable only request storage
235
+ await AuditLog.update({ logRequest: true, logResponse: false });
236
+ ```
237
+
81
238
  ## Authentication
82
239
 
83
240
  The SDK supports three authentication methods:
package/dist/Constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
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.METADATA_UNITS_ENDPOINT = exports.METADATA_AREA_ENDPOINT = exports.METADATA_TYPES_ENDPOINT = exports.USAGE_API = exports.TYPE_RECOMMENDER_API_PATH = exports.REAL_ESTATE_API_PATH = exports.ECONOMIC_ACTIVITY_API_PATH = 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.PAT_TOKEN_EXCHANGE_API = exports.TOKEN_GENERATION_API = exports.API_DOMAIN = void 0;
3
+ exports.CLIENT_SOURCE_SDK = exports.CLIENT_SOURCE_EXCEL = exports.CLIENT_SOURCE_HEADER = exports.PUT = exports.POST = exports.GET = exports.METADATA_UNITS_ENDPOINT = exports.METADATA_AREA_ENDPOINT = exports.METADATA_TYPES_ENDPOINT = exports.USAGE_API = exports.TYPE_RECOMMENDER_API_PATH = exports.AUDIT_LOG_API_PATH = exports.PHYSICAL_ACTIVITY_API_PATH = exports.REAL_ESTATE_API_PATH = exports.ECONOMIC_ACTIVITY_API_PATH = 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.PAT_TOKEN_EXCHANGE_API = exports.TOKEN_GENERATION_API = exports.API_DOMAIN = void 0;
4
4
  exports.API_DOMAIN = "https://api.envizi.ibm.com/ghgemissions/run";
5
5
  exports.TOKEN_GENERATION_API = "https://api.ibm.com/saascore/run/authentication-retrieve/api-key";
6
6
  exports.PAT_TOKEN_EXCHANGE_API = "https://api.ibm.com/saascore/run/envizi-auth/exchange";
@@ -15,6 +15,8 @@ exports.FACTOR_SET_API_PATH = "/v3/carbon/factorset";
15
15
  exports.SEARCH_API_PATH = "/v3/carbon/factor/search";
16
16
  exports.ECONOMIC_ACTIVITY_API_PATH = "/v3/carbon/economic-activity";
17
17
  exports.REAL_ESTATE_API_PATH = "/v3/carbon/real-estate";
18
+ exports.PHYSICAL_ACTIVITY_API_PATH = "/v3/carbon/physical-activity";
19
+ exports.AUDIT_LOG_API_PATH = "/v3/carbon/admin/audit-log";
18
20
  exports.TYPE_RECOMMENDER_API_PATH = "/v3/carbon/recommender/type/search";
19
21
  exports.USAGE_API = "/v3/carbon/usage";
20
22
  exports.METADATA_TYPES_ENDPOINT = "/v3/carbon/metadata/types";
@@ -22,6 +24,7 @@ exports.METADATA_AREA_ENDPOINT = "/v3/carbon/metadata/area";
22
24
  exports.METADATA_UNITS_ENDPOINT = "/v3/carbon/metadata/units";
23
25
  exports.GET = "GET";
24
26
  exports.POST = "POST";
27
+ exports.PUT = "PUT";
25
28
  exports.CLIENT_SOURCE_HEADER = "X-Client-Source";
26
29
  exports.CLIENT_SOURCE_EXCEL = "excel";
27
30
  exports.CLIENT_SOURCE_SDK = "node-sdk";
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getAuditConfig = getAuditConfig;
7
+ exports.updateAuditConfig = updateAuditConfig;
8
+ const axios_1 = __importDefault(require("axios"));
9
+ const request_1 = require("../request");
10
+ const Constants_1 = require("../Constants");
11
+ const Client_1 = require("../Client");
12
+ /**
13
+ * Handles common error responses for audit log API calls.
14
+ *
15
+ * @param {unknown} error - The error to handle
16
+ * @param {boolean} handle409 - Whether to handle 409 Conflict status (returns data instead of throwing)
17
+ * @return {AuditLogResponse | never} Returns response data for 409, otherwise throws error
18
+ */
19
+ function handleAuditLogError(error, handle409 = false) {
20
+ if (axios_1.default.isAxiosError(error) && error.response) {
21
+ const status = error.response.status;
22
+ const responseData = error.response.data;
23
+ // Handle 409 Conflict - configuration is already set to the requested values
24
+ if (status === 409 && handle409) {
25
+ return responseData;
26
+ }
27
+ // Handle 400 Bad Request - invalid payload
28
+ if (status === 400) {
29
+ throw new Error(responseData === null || responseData === void 0 ? void 0 : responseData.message);
30
+ }
31
+ // Handle 403 Forbidden - insufficient permissions
32
+ if (status === 403) {
33
+ throw new Error(responseData === null || responseData === void 0 ? void 0 : responseData.message);
34
+ }
35
+ }
36
+ // Re-throw any other errors
37
+ throw error;
38
+ }
39
+ /**
40
+ * Retrieves the audit log configuration for the organization.
41
+ *
42
+ * Controls whether the organization's API requests and responses are stored for auditing.
43
+ * Organizations can disable this if they don't need their API calls to be audited.
44
+ *
45
+ * @export
46
+ * @return {Promise<AuditLogResponse>} Current audit log configuration
47
+ * @throws {Error} Throws error for 403 (Forbidden) or other failures
48
+ *
49
+ * @example
50
+ * const config = await getConfig();
51
+ * // Output: { logRequest: true, logResponse: false }
52
+ */
53
+ async function getAuditConfig() {
54
+ const client = Client_1.Client.getInstance();
55
+ const url = client.getDomain() + Constants_1.AUDIT_LOG_API_PATH;
56
+ try {
57
+ return await (0, request_1.makeApiRequest)({
58
+ method: Constants_1.GET,
59
+ url,
60
+ });
61
+ }
62
+ catch (error) {
63
+ return handleAuditLogError(error);
64
+ }
65
+ }
66
+ /**
67
+ * Updates the audit log configuration for the organization.
68
+ *
69
+ * Controls whether the organization's API requests and responses are stored for auditing.
70
+ * Organizations can disable this if they don't need their API calls to be audited.
71
+ *
72
+ * Note: If the configuration is already set to the requested values, the API will return
73
+ * a 409 Conflict status with a message indicating no change was made. This is handled
74
+ * gracefully and the current configuration is returned.
75
+ *
76
+ * @export
77
+ * @param {AuditLogRequest} payload - Audit log configuration
78
+ * @return {Promise<AuditLogResponse>} Updated configuration or current configuration if no change
79
+ * @throws {Error} Throws error for 400 (Bad Request), 403 (Forbidden), or other failures
80
+ *
81
+ * @example
82
+ * const result = await update({ logRequest: false, logResponse: false });
83
+ * // If already set to these values:
84
+ * // { logRequest: false, logResponse: false, message: "No change in audit log configuration" }
85
+ */
86
+ async function updateAuditConfig(payload) {
87
+ const client = Client_1.Client.getInstance();
88
+ const url = client.getDomain() + Constants_1.AUDIT_LOG_API_PATH;
89
+ try {
90
+ return await (0, request_1.makeApiRequest)({
91
+ method: Constants_1.PUT,
92
+ url,
93
+ data: payload,
94
+ });
95
+ }
96
+ catch (error) {
97
+ return handleAuditLogError(error, true);
98
+ }
99
+ }
@@ -6,6 +6,7 @@ const Constants_1 = require("../Constants");
6
6
  const request_1 = require("../request");
7
7
  /**
8
8
  * Performs scope 3 Spend based emission calculations by making a POST request to the economic activity API endpoint.
9
+ * Supports optional attribution with revenue for proportional allocation.
9
10
  *
10
11
  * @export
11
12
  * @param {CommonRequest} payload - The request data to be sent to the API
@@ -13,6 +14,7 @@ const request_1 = require("../request");
13
14
  * @throws {Error} May throw an error if the API request fails
14
15
  *
15
16
  * @example
17
+ * // Basic economic activity request
16
18
  * const request = {
17
19
  "time": {
18
20
  "date": "2025-01-04"
@@ -28,6 +30,28 @@ const request_1 = require("../request");
28
30
  "includeDetails": false
29
31
  };
30
32
  * const result = await calculate(request);
33
+ *
34
+ * @example
35
+ * // Economic activity request with revenue attribution
36
+ * const requestWithAttribution = {
37
+ "time": {
38
+ "date": "2025-01-04"
39
+ },
40
+ "location": {
41
+ "country": "usa"
42
+ },
43
+ "activity": {
44
+ "type": "accomodation",
45
+ "value": 1500.12,
46
+ "unit": "usd"
47
+ },
48
+ "attribution": {
49
+ "outstandingAmount": 500000.0,
50
+ "revenue": 2000000.0
51
+ },
52
+ "includeDetails": true
53
+ };
54
+ * const resultWithAttribution = await calculate(requestWithAttribution);
31
55
  */
32
56
  async function calculate(payload) {
33
57
  const client = Client_1.Client.getInstance();
@@ -54,18 +54,89 @@ async function retrieveFactor(payload) {
54
54
  * @return {Promise<SearchResponse>} A promise that resolves to the search results returned by the API
55
55
  * @throws {Error} May throw an error if the API request fails
56
56
  *
57
+ * The API applies cross-encoder reranking by default. Set `enableReranker` to
58
+ * `false` to keep semantic similarity ordering without reranking.
59
+ *
57
60
  * @example
61
+ * // Basic search
58
62
  * const searchRequest = {
59
63
  "time":{
60
64
  "date": "2020-06-10"
61
65
  },
62
66
  "activity": {
63
- "search" : "travel"},
67
+ "search" : "travel"
68
+ },
64
69
  "location": {
65
70
  "country": "USA"
66
71
  }
67
72
  };
68
73
  * const results = await search(searchRequest);
74
+ *
75
+ * @example
76
+ * // Search without cross-encoder reranking
77
+ * const searchWithoutReranker = {
78
+ "time":{
79
+ "date": "2020-06-10"
80
+ },
81
+ "activity": {
82
+ "search" : "travel"
83
+ },
84
+ "location": {
85
+ "country": "USA"
86
+ },
87
+ "enableReranker": false
88
+ };
89
+ * const results = await search(searchWithoutReranker);
90
+ *
91
+ * @example
92
+ * // Search with optional unit parameter
93
+ * const searchWithUnit = {
94
+ "time":{
95
+ "date": "2020-06-10"
96
+ },
97
+ "activity": {
98
+ "search": "electricity",
99
+ "unit": "kWh"
100
+ },
101
+ "location": {
102
+ "country": "USA"
103
+ }
104
+ };
105
+ * const results = await search(searchWithUnit);
106
+ *
107
+ * @example
108
+ * // Search with optional scope parameter
109
+ * const searchWithScope = {
110
+ "time":{
111
+ "date": "2020-06-10"
112
+ },
113
+ "activity": {
114
+ "search": "natural gas",
115
+ "scope": "1"
116
+ },
117
+ "location": {
118
+ "country": "USA"
119
+ }
120
+ };
121
+ * const results = await search(searchWithScope);
122
+ *
123
+ * @example
124
+ * // Search with both unit and scope parameters
125
+ * const searchWithBoth = {
126
+ "time":{
127
+ "date": "2020-06-10"
128
+ },
129
+ "activity": {
130
+ "search": "electricity",
131
+ "unit": "MWh",
132
+ "scope": "2"
133
+ },
134
+ "location": {
135
+ "country": "USA",
136
+ "stateProvince": "california"
137
+ }
138
+ };
139
+ * const results = await search(searchWithBoth);
69
140
  */
70
141
  async function search(payload) {
71
142
  const client = Client_1.Client.getInstance();
@@ -0,0 +1,87 @@
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 3 Physical activity emission calculations by making a POST request to the physical activity API endpoint.
9
+ * Supports attribution for private companies using equity/debt based calculations or EVIC (Enterprise Value Including Cash).
10
+ *
11
+ * @export
12
+ * @param {CommonRequest} payload - The request data to be sent to the API
13
+ * @return {Promise<EmissionResponse | EmissionResponseWithDetails>} A promise that resolves to the emission calculation result. Returns EmissionResponseWithDetails if includeDetails is true, otherwise EmissionResponse
14
+ * @throws {Error} May throw an error if the API request fails
15
+ *
16
+ * @example
17
+ * // Basic physical activity request
18
+ * const request = {
19
+ "time": {
20
+ "date": "2025-01-23"
21
+ },
22
+ "location": {
23
+ "country": "usa"
24
+ },
25
+ "activity": {
26
+ "type": "commercial real estate",
27
+ "value": 0.1,
28
+ "unit": "km2"
29
+ },
30
+ "includeDetails": true
31
+ };
32
+ * const result = await calculate(request);
33
+ *
34
+ * @example
35
+ * // Physical activity request with attribution (equity/debt based for private companies)
36
+ * const requestWithEquityDebt = {
37
+ "time": {
38
+ "date": "2025-01-23"
39
+ },
40
+ "location": {
41
+ "country": "usa"
42
+ },
43
+ "activity": {
44
+ "type": "commercial real estate",
45
+ "value": 0.1,
46
+ "unit": "km2"
47
+ },
48
+ "attribution": {
49
+ "outstandingAmount": 1000000,
50
+ "totalEquity": 3000000,
51
+ "totalDebt": 2000000
52
+ },
53
+ "includeDetails": true
54
+ };
55
+ * const resultWithEquityDebt = await calculate(requestWithEquityDebt);
56
+ *
57
+ * @example
58
+ * // Physical activity request with attribution (EVIC based)
59
+ * const requestWithEVIC = {
60
+ "time": {
61
+ "date": "2025-01-23"
62
+ },
63
+ "location": {
64
+ "country": "usa"
65
+ },
66
+ "activity": {
67
+ "type": "commercial real estate",
68
+ "value": 0.1,
69
+ "unit": "km2"
70
+ },
71
+ "attribution": {
72
+ "outstandingAmount": 1000000.0,
73
+ "evic": 10000000.0
74
+ },
75
+ "includeDetails": true
76
+ };
77
+ * const resultWithEVIC = await calculate(requestWithEVIC);
78
+ */
79
+ async function calculate(payload) {
80
+ const client = Client_1.Client.getInstance();
81
+ const url = client.getDomain() + Constants_1.PHYSICAL_ACTIVITY_API_PATH;
82
+ return (0, request_1.makeApiRequest)({
83
+ method: Constants_1.POST,
84
+ url,
85
+ data: payload,
86
+ });
87
+ }
@@ -13,6 +13,7 @@ const request_1 = require("../request");
13
13
  * @throws {Error} May throw an error if the API request fails
14
14
  *
15
15
  * @example
16
+ * // Basic request without attribution
16
17
  * const request = {
17
18
  "time": {
18
19
  "date": "2025-01-04"
@@ -28,6 +29,28 @@ const request_1 = require("../request");
28
29
  "includeDetails": false
29
30
  };
30
31
  * const result = await calculate(request);
32
+ *
33
+ * @example
34
+ * // Request with attribution (property value based)
35
+ * const requestWithAttribution = {
36
+ "time": {
37
+ "date": "2022-01-01"
38
+ },
39
+ "location": {
40
+ "country": "usa",
41
+ "stateProvince": "new york"
42
+ },
43
+ "activity": {
44
+ "type": "Commercial Real Estate:Office",
45
+ "value": 123456.0,
46
+ "unit": "m2"
47
+ },
48
+ "attribution": {
49
+ "outstandingAmount": 1000000.0,
50
+ "propertyValue": 5000000.0
51
+ },
52
+ "includeDetails": true
53
+ };
31
54
  */
32
55
  async function calculate(payload) {
33
56
  const client = Client_1.Client.getInstance();
@@ -5,14 +5,20 @@ const Client_1 = require("../Client");
5
5
  const Constants_1 = require("../Constants");
6
6
  const request_1 = require("../request");
7
7
  /**
8
- * Search for activity types using semantic search with location, time, and license context. Supports pagination.
8
+ * Search for activity types using semantic search with location, time, and license context. Supports pagination and optional reranker control.
9
9
  *
10
10
  * @export
11
11
  * @param {SearchRequest} payload - The search request data to be sent to the API
12
- * @return {Promise<TypeResponse>} A promise that resolves to the activity types returned by the API
12
+ * @return {Promise<TypeRecommenderResponse>} A promise that resolves to the activity types returned by the API
13
13
  * @throws {Error} May throw an error if the API request fails
14
14
  *
15
+ * The API applies cross-encoder reranking by default. Set `enableReranker` to
16
+ * `false` to keep semantic similarity ordering without reranking. Returned
17
+ * activity type items can include `scope`, a list of distinct GHG Protocol
18
+ * scopes associated with the activity type.
19
+ *
15
20
  * @example
21
+ * // Basic search
16
22
  * const result = await search({
17
23
  "location": {
18
24
  "country": "usa"
@@ -23,6 +29,7 @@ const request_1 = require("../request");
23
29
  });
24
30
 
25
31
  * @example
32
+ * // Search with time and pagination
26
33
  * const result = await search({
27
34
  "location": {
28
35
  "country": "usa",
@@ -41,6 +48,7 @@ const request_1 = require("../request");
41
48
  });
42
49
 
43
50
  * @example
51
+ * // Search with power grid
44
52
  * const result = await search({
45
53
  "location": {
46
54
  "country": "usa",
@@ -50,6 +58,63 @@ const request_1 = require("../request");
50
58
  "search": "renewable energy"
51
59
  }
52
60
  });
61
+ *
62
+ * @example
63
+ * // Search without cross-encoder reranking
64
+ * const result = await search({
65
+ "location": {
66
+ "country": "usa"
67
+ },
68
+ "activity": {
69
+ "search": "electricity"
70
+ },
71
+ "enableReranker": false
72
+ });
73
+ *
74
+ * @example
75
+ * // Search with optional unit parameter
76
+ * const result = await search({
77
+ "location": {
78
+ "country": "usa"
79
+ },
80
+ "activity": {
81
+ "search": "electricity",
82
+ "unit": "kWh"
83
+ }
84
+ });
85
+ *
86
+ * @example
87
+ * // Search with optional scope parameter
88
+ * const result = await search({
89
+ "location": {
90
+ "country": "usa"
91
+ },
92
+ "activity": {
93
+ "search": "natural gas",
94
+ "scope": "1"
95
+ }
96
+ });
97
+ *
98
+ * @example
99
+ * // Search with both unit and scope parameters
100
+ * const result = await search({
101
+ "location": {
102
+ "country": "usa",
103
+ "stateProvince": "california"
104
+ },
105
+ "time": {
106
+ "date": "2025-06-10"
107
+ },
108
+ "activity": {
109
+ "search": "electricity",
110
+ "unit": "MWh",
111
+ "scope": "2"
112
+ },
113
+ "pagination": {
114
+ "page": 1,
115
+ "size": 10
116
+ }
117
+ });
53
118
  */
54
119
  async function search(payload) {
55
120
  const client = Client_1.Client.getInstance();