emissions-api-sdk 1.0.12 → 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.
- package/README.md +42 -2
- package/dist/Constants.js +4 -1
- package/dist/api/AuditLog.js +99 -0
- package/dist/api/EconomicActivity.js +24 -0
- package/dist/api/Factor.js +19 -0
- package/dist/api/PhysicalActivity.js +87 -0
- package/dist/api/RealEstate.js +23 -0
- package/dist/api/TypeRecommender.js +19 -2
- package/dist/coverage/clover.xml +149 -87
- package/dist/coverage/coverage-final.json +14 -8
- package/dist/coverage/lcov-report/index.html +21 -21
- package/dist/coverage/lcov-report/src/Client.ts.html +32 -32
- package/dist/coverage/lcov-report/src/Constants.ts.html +36 -27
- package/dist/coverage/lcov-report/src/api/AuditLog.ts.html +388 -0
- package/dist/coverage/lcov-report/src/api/Calculation.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/EconomicActivity.ts.html +77 -5
- package/dist/coverage/lcov-report/src/api/Factor.ts.html +59 -2
- package/dist/coverage/lcov-report/src/api/FactorSets.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/Fugitive.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/Location.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/Metadata.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/Mobile.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/PhysicalActivity.ts.html +361 -0
- package/dist/coverage/lcov-report/src/api/RealEstate.ts.html +74 -5
- package/dist/coverage/lcov-report/src/api/Stationary.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/TransportationAndDistribution.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/TypeRecommender.ts.html +55 -4
- package/dist/coverage/lcov-report/src/api/Usage.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/index.html +36 -6
- package/dist/coverage/lcov-report/src/index.html +7 -7
- package/dist/coverage/lcov-report/src/request.ts.html +5 -5
- package/dist/coverage/lcov-report/src/utils.ts.html +6 -6
- package/dist/coverage/lcov-report/test/index.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/AttributionRequest.ts.html +151 -0
- package/dist/coverage/lcov-report/test/mocks/CommonRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/EconomicActivityAttributionRequest.ts.html +148 -0
- package/dist/coverage/lcov-report/test/mocks/FactorRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/GenericCalculationRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/LocationRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/PhysicalActivityEVICRequest.ts.html +148 -0
- package/dist/coverage/lcov-report/test/mocks/PhysicalActivityRequest.ts.html +151 -0
- package/dist/coverage/lcov-report/test/mocks/SearchRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/index.html +63 -3
- package/dist/coverage/lcov-report/test/testUtils.ts.html +1 -1
- package/dist/coverage/lcov.info +249 -122
- package/dist/index.js +3 -1
- package/dist/interfaces/response/AuditLogResponse.js +2 -0
- package/dist/types/Constants.d.ts +3 -0
- package/dist/types/api/AuditLog.d.ts +37 -0
- package/dist/types/api/EconomicActivity.d.ts +24 -0
- package/dist/types/api/Factor.d.ts +19 -0
- package/dist/types/api/PhysicalActivity.d.ts +76 -0
- package/dist/types/api/RealEstate.d.ts +23 -0
- package/dist/types/api/TypeRecommender.d.ts +19 -2
- package/dist/types/index.d.ts +4 -0
- package/dist/types/interfaces/Api.d.ts +17 -1
- package/dist/types/interfaces/common.d.ts +40 -0
- package/dist/types/interfaces/response/AuditLogResponse.d.ts +40 -0
- package/dist/types/interfaces/response/TypeRecommenderResponse.d.ts +1 -0
- package/docs/_sources/authentication.rst.txt +26 -4
- package/docs/_sources/getting_started.rst.txt +538 -74
- package/docs/_sources/index.rst.txt +11 -0
- package/docs/_sources/reference.rst.txt +26 -0
- package/docs/_sources/troubleshooting.rst.txt +77 -12
- package/docs/_static/basic.css +8 -0
- package/docs/_static/doctools.js +5 -6
- package/docs/_static/language_data.js +186 -7
- package/docs/_static/pygments.css +146 -164
- package/docs/_static/searchtools.js +60 -121
- package/docs/_static/sphinx_highlight.js +31 -36
- package/docs/_static/styles/furo.css +1 -1
- package/docs/_static/styles/furo.css.map +1 -1
- package/docs/authentication.html +61 -26
- package/docs/client.html +33 -22
- package/docs/genindex.html +52 -23
- package/docs/getting_started.html +745 -103
- package/docs/index.html +65 -21
- package/docs/reference.html +484 -66
- package/docs/sdk.html +32 -21
- package/docs/search.html +32 -21
- package/docs/searchindex.js +1 -1
- package/docs/troubleshooting.html +105 -38
- package/package.json +7 -3
- package/sphinx-build/source/authentication.rst +26 -4
- package/sphinx-build/source/getting_started.rst +538 -74
- package/sphinx-build/source/index.rst +11 -0
- package/sphinx-build/source/reference.rst +26 -0
- package/sphinx-build/source/troubleshooting.rst +77 -12
- package/src/Constants.ts +3 -0
- package/src/api/AuditLog.ts +102 -0
- package/src/api/EconomicActivity.ts +24 -0
- package/src/api/Factor.ts +19 -0
- package/src/api/PhysicalActivity.ts +92 -0
- package/src/api/RealEstate.ts +23 -0
- package/src/api/TypeRecommender.ts +19 -2
- package/src/index.ts +7 -1
- package/src/interfaces/Api.ts +22 -6
- package/src/interfaces/common.ts +46 -0
- package/src/interfaces/response/AuditLogResponse.ts +47 -0
- package/src/interfaces/response/TypeRecommenderResponse.ts +2 -0
- package/test/apiTest.test.ts +59 -3
- package/test/auditLog.test.ts +216 -0
- package/test/mocks/AttributionRequest.ts +23 -0
- package/test/mocks/EconomicActivityAttributionRequest.ts +22 -0
- package/test/mocks/PhysicalActivityEVICRequest.ts +22 -0
- package/test/mocks/PhysicalActivityRequest.ts +23 -0
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,24 @@ 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
|
+
|
|
198
238
|
## Authentication
|
|
199
239
|
|
|
200
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();
|
package/dist/api/Factor.js
CHANGED
|
@@ -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,22 @@ 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
|
+
"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
|
|
73
92
|
* // Search with optional unit parameter
|
|
74
93
|
* const searchWithUnit = {
|
|
75
94
|
"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
|
+
}
|
package/dist/api/RealEstate.js
CHANGED
|
@@ -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,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<
|
|
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": {
|