emissions-api-sdk 1.0.12 → 1.0.14

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/README.md +65 -2
  2. package/dist/Constants.js +7 -1
  3. package/dist/api/AuditExport.js +73 -0
  4. package/dist/api/AuditLog.js +99 -0
  5. package/dist/api/EconomicActivity.js +69 -0
  6. package/dist/api/Factor.js +16 -0
  7. package/dist/api/PhysicalActivity.js +87 -0
  8. package/dist/api/RealEstate.js +25 -1
  9. package/dist/api/TypeRecommender.js +19 -2
  10. package/dist/coverage/clover.xml +172 -89
  11. package/dist/coverage/coverage-final.json +15 -8
  12. package/dist/coverage/lcov-report/index.html +21 -21
  13. package/dist/coverage/lcov-report/src/Client.ts.html +32 -32
  14. package/dist/coverage/lcov-report/src/Constants.ts.html +45 -27
  15. package/dist/coverage/lcov-report/src/api/AuditExport.ts.html +355 -0
  16. package/dist/coverage/lcov-report/src/api/AuditLog.ts.html +388 -0
  17. package/dist/coverage/lcov-report/src/api/Calculation.ts.html +1 -1
  18. package/dist/coverage/lcov-report/src/api/EconomicActivity.ts.html +212 -5
  19. package/dist/coverage/lcov-report/src/api/Factor.ts.html +54 -3
  20. package/dist/coverage/lcov-report/src/api/FactorSets.ts.html +1 -1
  21. package/dist/coverage/lcov-report/src/api/Fugitive.ts.html +1 -1
  22. package/dist/coverage/lcov-report/src/api/Location.ts.html +1 -1
  23. package/dist/coverage/lcov-report/src/api/Metadata.ts.html +1 -1
  24. package/dist/coverage/lcov-report/src/api/Mobile.ts.html +1 -1
  25. package/dist/coverage/lcov-report/src/api/PhysicalActivity.ts.html +361 -0
  26. package/dist/coverage/lcov-report/src/api/RealEstate.ts.html +78 -6
  27. package/dist/coverage/lcov-report/src/api/Stationary.ts.html +1 -1
  28. package/dist/coverage/lcov-report/src/api/TransportationAndDistribution.ts.html +1 -1
  29. package/dist/coverage/lcov-report/src/api/TypeRecommender.ts.html +55 -4
  30. package/dist/coverage/lcov-report/src/api/Usage.ts.html +1 -1
  31. package/dist/coverage/lcov-report/src/api/index.html +51 -6
  32. package/dist/coverage/lcov-report/src/index.html +7 -7
  33. package/dist/coverage/lcov-report/src/request.ts.html +8 -5
  34. package/dist/coverage/lcov-report/src/utils.ts.html +6 -6
  35. package/dist/coverage/lcov-report/test/index.html +1 -1
  36. package/dist/coverage/lcov-report/test/mocks/AttributionRequest.ts.html +151 -0
  37. package/dist/coverage/lcov-report/test/mocks/CommonRequest.ts.html +1 -1
  38. package/dist/coverage/lcov-report/test/mocks/EconomicActivityAttributionRequest.ts.html +148 -0
  39. package/dist/coverage/lcov-report/test/mocks/FactorRequest.ts.html +1 -1
  40. package/dist/coverage/lcov-report/test/mocks/GenericCalculationRequest.ts.html +1 -1
  41. package/dist/coverage/lcov-report/test/mocks/LocationRequest.ts.html +1 -1
  42. package/dist/coverage/lcov-report/test/mocks/PhysicalActivityEVICRequest.ts.html +148 -0
  43. package/dist/coverage/lcov-report/test/mocks/PhysicalActivityRequest.ts.html +151 -0
  44. package/dist/coverage/lcov-report/test/mocks/SearchRequest.ts.html +1 -1
  45. package/dist/coverage/lcov-report/test/mocks/index.html +63 -3
  46. package/dist/coverage/lcov-report/test/testUtils.ts.html +1 -1
  47. package/dist/coverage/lcov.info +284 -124
  48. package/dist/index.js +4 -1
  49. package/dist/interfaces/response/AuditExportResponse.js +2 -0
  50. package/dist/interfaces/response/AuditLogResponse.js +2 -0
  51. package/dist/request.js +1 -0
  52. package/dist/types/Constants.d.ts +6 -0
  53. package/dist/types/api/AuditExport.d.ts +42 -0
  54. package/dist/types/api/AuditLog.d.ts +37 -0
  55. package/dist/types/api/EconomicActivity.d.ts +69 -0
  56. package/dist/types/api/Factor.d.ts +16 -0
  57. package/dist/types/api/PhysicalActivity.d.ts +76 -0
  58. package/dist/types/api/RealEstate.d.ts +25 -1
  59. package/dist/types/api/TypeRecommender.d.ts +19 -2
  60. package/dist/types/index.d.ts +6 -0
  61. package/dist/types/interfaces/Api.d.ts +17 -1
  62. package/dist/types/interfaces/Config.d.ts +5 -1
  63. package/dist/types/interfaces/common.d.ts +40 -0
  64. package/dist/types/interfaces/response/AuditExportResponse.d.ts +66 -0
  65. package/dist/types/interfaces/response/AuditLogResponse.d.ts +40 -0
  66. package/dist/types/interfaces/response/TypeRecommenderResponse.d.ts +2 -0
  67. package/docs/_sources/authentication.rst.txt +26 -4
  68. package/docs/_sources/getting_started.rst.txt +762 -74
  69. package/docs/_sources/index.rst.txt +13 -0
  70. package/docs/_sources/reference.rst.txt +48 -0
  71. package/docs/_sources/troubleshooting.rst.txt +77 -12
  72. package/docs/_static/basic.css +8 -0
  73. package/docs/_static/doctools.js +5 -6
  74. package/docs/_static/language_data.js +186 -7
  75. package/docs/_static/pygments.css +146 -164
  76. package/docs/_static/searchtools.js +60 -121
  77. package/docs/_static/sphinx_highlight.js +31 -36
  78. package/docs/_static/styles/furo.css +1 -1
  79. package/docs/_static/styles/furo.css.map +1 -1
  80. package/docs/authentication.html +61 -26
  81. package/docs/client.html +33 -22
  82. package/docs/genindex.html +77 -24
  83. package/docs/getting_started.html +969 -103
  84. package/docs/index.html +69 -21
  85. package/docs/reference.html +747 -66
  86. package/docs/sdk.html +32 -21
  87. package/docs/search.html +32 -21
  88. package/docs/searchindex.js +1 -1
  89. package/docs/troubleshooting.html +105 -38
  90. package/package.json +8 -3
  91. package/sphinx-build/source/authentication.rst +26 -4
  92. package/sphinx-build/source/getting_started.rst +762 -74
  93. package/sphinx-build/source/index.rst +13 -0
  94. package/sphinx-build/source/reference.rst +48 -0
  95. package/sphinx-build/source/troubleshooting.rst +77 -12
  96. package/src/Constants.ts +6 -0
  97. package/src/api/AuditExport.ts +90 -0
  98. package/src/api/AuditLog.ts +102 -0
  99. package/src/api/EconomicActivity.ts +69 -0
  100. package/src/api/Factor.ts +17 -1
  101. package/src/api/PhysicalActivity.ts +92 -0
  102. package/src/api/RealEstate.ts +25 -1
  103. package/src/api/TypeRecommender.ts +19 -2
  104. package/src/index.ts +15 -1
  105. package/src/interfaces/Api.ts +22 -6
  106. package/src/interfaces/Config.ts +6 -1
  107. package/src/interfaces/common.ts +46 -0
  108. package/src/interfaces/response/AuditExportResponse.ts +88 -0
  109. package/src/interfaces/response/AuditLogResponse.ts +47 -0
  110. package/src/interfaces/response/TypeRecommenderResponse.ts +3 -0
  111. package/src/request.ts +1 -0
  112. package/test/apiTest.test.ts +59 -3
  113. package/test/auditExport.test.ts +68 -0
  114. package/test/auditLog.test.ts +216 -0
  115. package/test/mocks/AttributionRequest.ts +23 -0
  116. package/test/mocks/EconomicActivityAttributionRequest.ts +22 -0
  117. package/test/mocks/PhysicalActivityEVICRequest.ts +22 -0
  118. package/test/mocks/PhysicalActivityRequest.ts +23 -0
  119. package/docs/_static/base-stemmer.js +0 -476
  120. package/docs/_static/english-stemmer.js +0 -1066
package/README.md CHANGED
@@ -72,7 +72,7 @@ const typeUnits = await Metadata.getUnits('Natural Gas'); // Units for specific
72
72
 
73
73
  ## Type Recommender API
74
74
 
75
- Search for activity types using semantic search with optional unit and scope filtering:
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
76
 
77
77
  ```javascript
78
78
  import { TypeRecommender } from 'emissions-api-sdk';
@@ -98,6 +98,17 @@ const typesWithUnit = await TypeRecommender.search({
98
98
  }
99
99
  });
100
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
+
101
112
  // Search with scope filter
102
113
  const typesWithScope = await TypeRecommender.search({
103
114
  "location": {
@@ -132,7 +143,7 @@ const typesWithAll = await TypeRecommender.search({
132
143
 
133
144
  ## Factor Search API
134
145
 
135
- Search for emission factors with optional unit and scope filtering:
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.
136
147
 
137
148
  ```javascript
138
149
  import { Factor } from 'emissions-api-sdk';
@@ -161,6 +172,17 @@ const resultsWithUnit = await Factor.search({
161
172
  }
162
173
  });
163
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
+
164
186
  // Search with scope filter
165
187
  const resultsWithScope = await Factor.search({
166
188
  "activity": {
@@ -195,6 +217,47 @@ import { Usage } from 'emissions-api-sdk';
195
217
  const usage = await Usage.getUsage(true);
196
218
  ```
197
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
+
238
+ ## Audit Export API
239
+
240
+ Admin users can export audit data for a date range. The export is asynchronous: submit the request, poll until it is complete, then download the ZIP archive. All three endpoints require an admin JWT token.
241
+
242
+ ```javascript
243
+ import { AuditExport } from 'emissions-api-sdk';
244
+
245
+ const auditExport = await AuditExport.trigger({
246
+ fromDate: '2025-01-01',
247
+ toDate: '2025-03-31',
248
+ apiName: 'location'
249
+ });
250
+
251
+ // Repeat this request until status is COMPLETED.
252
+ const status = await AuditExport.getStatus(auditExport.requestId);
253
+
254
+ if (status.status === 'COMPLETED') {
255
+ const auditExportZip = await AuditExport.download(auditExport.requestId);
256
+ }
257
+ ```
258
+
259
+ The request dates use `yyyy-MM-dd`. `fromDate` must be on or after `2025-01-01`, `toDate` must be no later than the previous calendar day, and `apiName` is an optional case-insensitive endpoint filter. A completed export is available for seven days. See the [Audit Export API reference](https://ibm.github.io/ibm-envizi-emissions-api-nodejs-sdk/reference.html#audit-export-api) for the request and response details.
260
+
198
261
  ## Authentication
199
262
 
200
263
  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_EXPORT_DOWNLOAD_API_PATH = exports.AUDIT_EXPORT_STATUS_API_PATH = exports.AUDIT_EXPORT_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,11 @@ 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";
20
+ exports.AUDIT_EXPORT_API_PATH = "/v3/carbon/audit";
21
+ exports.AUDIT_EXPORT_STATUS_API_PATH = "/v3/carbon/audit/status";
22
+ exports.AUDIT_EXPORT_DOWNLOAD_API_PATH = "/v3/carbon/audit/download";
18
23
  exports.TYPE_RECOMMENDER_API_PATH = "/v3/carbon/recommender/type/search";
19
24
  exports.USAGE_API = "/v3/carbon/usage";
20
25
  exports.METADATA_TYPES_ENDPOINT = "/v3/carbon/metadata/types";
@@ -22,6 +27,7 @@ exports.METADATA_AREA_ENDPOINT = "/v3/carbon/metadata/area";
22
27
  exports.METADATA_UNITS_ENDPOINT = "/v3/carbon/metadata/units";
23
28
  exports.GET = "GET";
24
29
  exports.POST = "POST";
30
+ exports.PUT = "PUT";
25
31
  exports.CLIENT_SOURCE_HEADER = "X-Client-Source";
26
32
  exports.CLIENT_SOURCE_EXCEL = "excel";
27
33
  exports.CLIENT_SOURCE_SDK = "node-sdk";
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.trigger = trigger;
4
+ exports.getStatus = getStatus;
5
+ exports.download = download;
6
+ const Client_1 = require("../Client");
7
+ const Constants_1 = require("../Constants");
8
+ const request_1 = require("../request");
9
+ /**
10
+ * Triggers an asynchronous audit data export.
11
+ *
12
+ * @export
13
+ * @param {AuditExportRequest} payload - Date range and optional API-name filter for the export
14
+ * @return {Promise<AuditExportResponse>} The accepted export request, including its request ID
15
+ * @throws {Error} Throws if the request is invalid, the caller is not an admin, or a matching export already exists
16
+ *
17
+ * @example
18
+ * const auditExport = await trigger({
19
+ * fromDate: "2025-01-01",
20
+ * toDate: "2025-03-31",
21
+ * apiName: "location"
22
+ * });
23
+ */
24
+ async function trigger(payload) {
25
+ const client = Client_1.Client.getInstance();
26
+ const url = client.getDomain() + Constants_1.AUDIT_EXPORT_API_PATH;
27
+ return (0, request_1.makeApiRequest)({
28
+ method: Constants_1.POST,
29
+ url,
30
+ data: payload,
31
+ });
32
+ }
33
+ /**
34
+ * Retrieves the processing status of an audit export.
35
+ *
36
+ * @export
37
+ * @param {string} requestId - Request ID returned by trigger
38
+ * @return {Promise<AuditExportStatusResponse>} Current export status and, when complete, download details
39
+ * @throws {Error} Throws if the request ID is invalid or the caller is not an admin
40
+ *
41
+ * @example
42
+ * const status = await getStatus(auditExport.requestId);
43
+ */
44
+ async function getStatus(requestId) {
45
+ const client = Client_1.Client.getInstance();
46
+ const url = client.getDomain() + Constants_1.AUDIT_EXPORT_STATUS_API_PATH;
47
+ return (0, request_1.makeApiRequest)({
48
+ method: Constants_1.GET,
49
+ url,
50
+ params: { requestId },
51
+ });
52
+ }
53
+ /**
54
+ * Downloads a completed audit export as a ZIP archive.
55
+ *
56
+ * @export
57
+ * @param {string} requestId - Request ID returned by trigger
58
+ * @return {Promise<Buffer>} ZIP archive containing audit-export.csv
59
+ * @throws {Error} Throws while processing, when the export failed or expired, or if the caller is not an admin
60
+ *
61
+ * @example
62
+ * const auditExportZip = await download(auditExport.requestId);
63
+ */
64
+ async function download(requestId) {
65
+ const client = Client_1.Client.getInstance();
66
+ const url = client.getDomain() + Constants_1.AUDIT_EXPORT_DOWNLOAD_API_PATH;
67
+ return (0, request_1.makeApiRequest)({
68
+ method: Constants_1.GET,
69
+ url,
70
+ params: { requestId },
71
+ responseType: "arraybuffer",
72
+ });
73
+ }
@@ -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,73 @@ 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);
55
+ *
56
+ * @example
57
+ * // Economic activity request with attribution (equity/debt based for private companies)
58
+ * const requestWithEquityDebt = {
59
+ "time": {
60
+ "date": "2025-01-04"
61
+ },
62
+ "location": {
63
+ "country": "usa"
64
+ },
65
+ "activity": {
66
+ "type": "accomodation",
67
+ "value": 1500.12,
68
+ "unit": "usd"
69
+ },
70
+ "attribution": {
71
+ "outstandingAmount": 500000.0,
72
+ "totalEquity": 3000000.0,
73
+ "totalDebt": 2000000.0
74
+ },
75
+ "includeDetails": true
76
+ };
77
+ * const resultWithEquityDebt = await calculate(requestWithEquityDebt);
78
+ *
79
+ * @example
80
+ * // Economic activity request with attribution (EVIC based for listed companies)
81
+ * const requestWithEvic = {
82
+ "time": {
83
+ "date": "2025-01-04"
84
+ },
85
+ "location": {
86
+ "country": "usa"
87
+ },
88
+ "activity": {
89
+ "type": "accomodation",
90
+ "value": 1500.12,
91
+ "unit": "usd"
92
+ },
93
+ "attribution": {
94
+ "outstandingAmount": 500000.0,
95
+ "evic": 10000000.0
96
+ },
97
+ "includeDetails": true
98
+ };
99
+ * const resultWithEvic = await calculate(requestWithEvic);
31
100
  */
32
101
  async function calculate(payload) {
33
102
  const client = Client_1.Client.getInstance();
@@ -54,6 +54,9 @@ 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
58
61
  * // Basic search
59
62
  * const searchRequest = {
@@ -70,6 +73,19 @@ async function retrieveFactor(payload) {
70
73
  * const results = await search(searchRequest);
71
74
  *
72
75
  * @example
76
+ * // Search without cross-encoder reranking
77
+ * const searchWithoutReranker = {
78
+ "activity": {
79
+ "search": "travel"
80
+ },
81
+ "location": {
82
+ "country": "USA"
83
+ },
84
+ "enableReranker": false
85
+ };
86
+ * const results = await search(searchWithoutReranker);
87
+ *
88
+ * @example
73
89
  * // Search with optional unit parameter
74
90
  * const searchWithUnit = {
75
91
  "time":{
@@ -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,7 +29,30 @@ const request_1 = require("../request");
28
29
  "includeDetails": false
29
30
  };
30
31
  * const result = await calculate(request);
31
- */
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
+ };
54
+ * const resultWithAttribution = await calculate(requestWithAttribution);
55
+ */
32
56
  async function calculate(payload) {
33
57
  const client = Client_1.Client.getInstance();
34
58
  const url = client.getDomain() + Constants_1.REAL_ESTATE_API_PATH;
@@ -5,13 +5,18 @@ 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
16
21
  * // Basic search
17
22
  * const result = await search({
@@ -55,6 +60,18 @@ const request_1 = require("../request");
55
60
  });
56
61
  *
57
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
58
75
  * // Search with optional unit parameter
59
76
  * const result = await search({
60
77
  "location": {