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.
- package/README.md +157 -0
- 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 +72 -1
- package/dist/api/PhysicalActivity.js +87 -0
- package/dist/api/RealEstate.js +23 -0
- package/dist/api/TypeRecommender.js +67 -2
- package/dist/coverage/clover.xml +154 -89
- package/dist/coverage/coverage-final.json +15 -9
- 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 +216 -3
- 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 +199 -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 +148 -4
- package/dist/coverage/lcov-report/test/mocks/index.html +64 -4
- package/dist/coverage/lcov-report/test/testUtils.ts.html +1 -1
- package/dist/coverage/lcov.info +254 -124
- 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 +72 -1
- 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 +67 -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 +48 -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/base-stemmer.js +476 -0
- package/docs/_static/english-stemmer.js +1066 -0
- package/docs/authentication.html +31 -5
- package/docs/client.html +3 -1
- package/docs/genindex.html +22 -2
- package/docs/getting_started.html +715 -82
- package/docs/index.html +35 -0
- package/docs/reference.html +412 -3
- package/docs/sdk.html +2 -0
- package/docs/search.html +2 -0
- package/docs/searchindex.js +1 -1
- package/docs/troubleshooting.html +75 -17
- 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 +72 -1
- package/src/api/PhysicalActivity.ts +92 -0
- package/src/api/RealEstate.ts +23 -0
- package/src/api/TypeRecommender.ts +67 -2
- package/src/index.ts +7 -1
- package/src/interfaces/Api.ts +22 -6
- package/src/interfaces/common.ts +58 -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/test/mocks/SearchRequest.ts +48 -0
|
@@ -99,12 +99,61 @@ These errors occur when ``Client.getClient()`` is called with invalid or missing
|
|
|
99
99
|
|
|
100
100
|
----
|
|
101
101
|
|
|
102
|
+
4. Missing Client ID with PAT Token
|
|
103
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
104
|
+
|
|
105
|
+
**Error Message:**
|
|
106
|
+
|
|
107
|
+
.. code-block:: text
|
|
108
|
+
|
|
109
|
+
Error: If patToken is provided, "clientId" must also be provided.
|
|
110
|
+
|
|
111
|
+
**Cause:** Personal Access Token (PAT) provided without client ID
|
|
112
|
+
|
|
113
|
+
**Solution:** Provide ``clientId`` parameter when using a PAT token
|
|
114
|
+
|
|
115
|
+
**Sample Function Call That Causes This Error:**
|
|
116
|
+
|
|
117
|
+
.. code-block:: typescript
|
|
118
|
+
|
|
119
|
+
await Client.getClient({
|
|
120
|
+
patToken: 'your-pat-token'
|
|
121
|
+
// Missing clientId parameter
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
----
|
|
125
|
+
|
|
126
|
+
5. Organization ID Provided with PAT Token
|
|
127
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
128
|
+
|
|
129
|
+
**Error Message:**
|
|
130
|
+
|
|
131
|
+
.. code-block:: text
|
|
132
|
+
|
|
133
|
+
Error: orgId should not be provided when using patToken.
|
|
134
|
+
|
|
135
|
+
**Cause:** Organization ID should not be used with Personal Access Token authentication
|
|
136
|
+
|
|
137
|
+
**Solution:** Remove ``orgId`` parameter when using PAT token authentication
|
|
138
|
+
|
|
139
|
+
**Sample Function Call That Causes This Error:**
|
|
140
|
+
|
|
141
|
+
.. code-block:: typescript
|
|
142
|
+
|
|
143
|
+
await Client.getClient({
|
|
144
|
+
patToken: 'your-pat-token',
|
|
145
|
+
clientId: 'client123',
|
|
146
|
+
orgId: 'org456' // This should not be provided with PAT token
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
----
|
|
150
|
+
|
|
102
151
|
Authentication Errors (HTTP 401)
|
|
103
152
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
104
153
|
|
|
105
154
|
These errors occur when authentication credentials are invalid or expired.
|
|
106
155
|
|
|
107
|
-
|
|
156
|
+
6. Invalid API Key
|
|
108
157
|
^^^^^^^^^^^^^^^^^^
|
|
109
158
|
|
|
110
159
|
**Error Response:**
|
|
@@ -135,7 +184,7 @@ These errors occur when authentication credentials are invalid or expired.
|
|
|
135
184
|
|
|
136
185
|
----
|
|
137
186
|
|
|
138
|
-
|
|
187
|
+
7. Invalid Organization ID
|
|
139
188
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
140
189
|
|
|
141
190
|
**Error Response:**
|
|
@@ -166,7 +215,7 @@ These errors occur when authentication credentials are invalid or expired.
|
|
|
166
215
|
|
|
167
216
|
----
|
|
168
217
|
|
|
169
|
-
|
|
218
|
+
8. Invalid Client ID
|
|
170
219
|
^^^^^^^^^^^^^^^^^^^^^
|
|
171
220
|
|
|
172
221
|
**Error Response:**
|
|
@@ -197,7 +246,7 @@ These errors occur when authentication credentials are invalid or expired.
|
|
|
197
246
|
|
|
198
247
|
----
|
|
199
248
|
|
|
200
|
-
|
|
249
|
+
9. Empty Token Response
|
|
201
250
|
^^^^^^^^^^^^^^^^^^^^^^^^
|
|
202
251
|
|
|
203
252
|
**Error Message:**
|
|
@@ -233,8 +282,8 @@ These errors occur when authentication credentials are invalid or expired.
|
|
|
233
282
|
|
|
234
283
|
----
|
|
235
284
|
|
|
236
|
-
|
|
237
|
-
|
|
285
|
+
10. Missing Expiry Field in Token
|
|
286
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
238
287
|
|
|
239
288
|
**Error Message:**
|
|
240
289
|
|
|
@@ -341,6 +390,14 @@ Error Summary Table
|
|
|
341
390
|
- ``If apiKey is provided , "clientId" and "OrgId" must also be provided.``
|
|
342
391
|
- N/A
|
|
343
392
|
- Provide all three parameters
|
|
393
|
+
* - Configuration
|
|
394
|
+
- ``If patToken is provided, "clientId" must also be provided.``
|
|
395
|
+
- N/A
|
|
396
|
+
- Provide clientId with PAT token
|
|
397
|
+
* - Configuration
|
|
398
|
+
- ``orgId should not be provided when using patToken.``
|
|
399
|
+
- N/A
|
|
400
|
+
- Remove orgId when using PAT token
|
|
344
401
|
* - Authentication
|
|
345
402
|
- ``Cannot pass the security checks...``
|
|
346
403
|
- 401
|
|
@@ -369,14 +426,22 @@ Required Configuration Parameters
|
|
|
369
426
|
|
|
370
427
|
When calling ``Client.getClient()``, the following parameters are required based on authentication method:
|
|
371
428
|
|
|
372
|
-
|
|
373
|
-
|
|
429
|
+
Personal Access Token (PAT) Authentication (Recommended)
|
|
430
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
431
|
+
|
|
432
|
+
- ``patToken`` - Your Personal Access Token
|
|
433
|
+
- ``clientId`` - Your client ID
|
|
434
|
+
|
|
435
|
+
**Note:** Do not provide ``orgId`` when using PAT token authentication.
|
|
436
|
+
|
|
437
|
+
API Key Authentication
|
|
438
|
+
~~~~~~~~~~~~~~~~~~~~~~
|
|
374
439
|
|
|
375
440
|
- ``apiKey`` - Your IBM Cloud API key
|
|
376
441
|
- ``clientId`` - Your client ID
|
|
377
442
|
- ``orgId`` - Your organization ID
|
|
378
|
-
- ``host`` - API host URL
|
|
379
|
-
- ``authUrl`` - Authentication URL
|
|
443
|
+
- ``host`` - API host URL (optional, uses default if not provided)
|
|
444
|
+
- ``authUrl`` - Authentication URL (optional, uses default if not provided)
|
|
380
445
|
|
|
381
446
|
Token Authentication
|
|
382
447
|
~~~~~~~~~~~~~~~~~~~~
|
|
@@ -479,8 +544,8 @@ For issues not covered in this guide:
|
|
|
479
544
|
|
|
480
545
|
----
|
|
481
546
|
|
|
482
|
-
**Last Updated:**
|
|
547
|
+
**Last Updated:** 2026-05-31
|
|
483
548
|
|
|
484
|
-
**SDK Version:** 1.0.
|
|
549
|
+
**SDK Version:** 1.0.2
|
|
485
550
|
|
|
486
551
|
**Coverage:** SDK initialization, client instance, and authentication errors
|
package/src/Constants.ts
CHANGED
|
@@ -12,6 +12,8 @@ export const FACTOR_SET_API_PATH = "/v3/carbon/factorset";
|
|
|
12
12
|
export const SEARCH_API_PATH = "/v3/carbon/factor/search";
|
|
13
13
|
export const ECONOMIC_ACTIVITY_API_PATH = "/v3/carbon/economic-activity";
|
|
14
14
|
export const REAL_ESTATE_API_PATH = "/v3/carbon/real-estate";
|
|
15
|
+
export const PHYSICAL_ACTIVITY_API_PATH = "/v3/carbon/physical-activity";
|
|
16
|
+
export const AUDIT_LOG_API_PATH = "/v3/carbon/admin/audit-log";
|
|
15
17
|
|
|
16
18
|
export const TYPE_RECOMMENDER_API_PATH = "/v3/carbon/recommender/type/search";
|
|
17
19
|
|
|
@@ -23,6 +25,7 @@ export const METADATA_UNITS_ENDPOINT = "/v3/carbon/metadata/units";
|
|
|
23
25
|
|
|
24
26
|
export const GET = "GET";
|
|
25
27
|
export const POST = "POST";
|
|
28
|
+
export const PUT = "PUT";
|
|
26
29
|
export const CLIENT_SOURCE_HEADER = "X-Client-Source";
|
|
27
30
|
export const CLIENT_SOURCE_EXCEL = "excel";
|
|
28
31
|
export const CLIENT_SOURCE_SDK = "node-sdk";
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { makeApiRequest } from "../request";
|
|
3
|
+
import { AUDIT_LOG_API_PATH, GET, PUT } from "../Constants";
|
|
4
|
+
import { AuditLogRequest, AuditLogResponse } from "../interfaces/response/AuditLogResponse";
|
|
5
|
+
import { Client } from "../Client";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Handles common error responses for audit log API calls.
|
|
9
|
+
*
|
|
10
|
+
* @param {unknown} error - The error to handle
|
|
11
|
+
* @param {boolean} handle409 - Whether to handle 409 Conflict status (returns data instead of throwing)
|
|
12
|
+
* @return {AuditLogResponse | never} Returns response data for 409, otherwise throws error
|
|
13
|
+
*/
|
|
14
|
+
function handleAuditLogError(error: unknown, handle409: boolean = false): AuditLogResponse | never {
|
|
15
|
+
if (axios.isAxiosError(error) && error.response) {
|
|
16
|
+
const status = error.response.status;
|
|
17
|
+
const responseData = error.response.data;
|
|
18
|
+
|
|
19
|
+
// Handle 409 Conflict - configuration is already set to the requested values
|
|
20
|
+
if (status === 409 && handle409) {
|
|
21
|
+
return responseData as AuditLogResponse;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Handle 400 Bad Request - invalid payload
|
|
25
|
+
if (status === 400) {
|
|
26
|
+
throw new Error(responseData?.message);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Handle 403 Forbidden - insufficient permissions
|
|
30
|
+
if (status === 403) {
|
|
31
|
+
throw new Error(responseData?.message);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Re-throw any other errors
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
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
|
+
export async function getAuditConfig(): Promise<AuditLogResponse> {
|
|
54
|
+
const client = Client.getInstance();
|
|
55
|
+
const url = client.getDomain() + AUDIT_LOG_API_PATH;
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
return await makeApiRequest<AuditLogResponse>({
|
|
59
|
+
method: GET,
|
|
60
|
+
url,
|
|
61
|
+
});
|
|
62
|
+
} catch (error) {
|
|
63
|
+
return handleAuditLogError(error);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Updates the audit log configuration for the organization.
|
|
69
|
+
*
|
|
70
|
+
* Controls whether the organization's API requests and responses are stored for auditing.
|
|
71
|
+
* Organizations can disable this if they don't need their API calls to be audited.
|
|
72
|
+
*
|
|
73
|
+
* Note: If the configuration is already set to the requested values, the API will return
|
|
74
|
+
* a 409 Conflict status with a message indicating no change was made. This is handled
|
|
75
|
+
* gracefully and the current configuration is returned.
|
|
76
|
+
*
|
|
77
|
+
* @export
|
|
78
|
+
* @param {AuditLogRequest} payload - Audit log configuration
|
|
79
|
+
* @return {Promise<AuditLogResponse>} Updated configuration or current configuration if no change
|
|
80
|
+
* @throws {Error} Throws error for 400 (Bad Request), 403 (Forbidden), or other failures
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* const result = await update({ logRequest: false, logResponse: false });
|
|
84
|
+
* // If already set to these values:
|
|
85
|
+
* // { logRequest: false, logResponse: false, message: "No change in audit log configuration" }
|
|
86
|
+
*/
|
|
87
|
+
export async function updateAuditConfig(
|
|
88
|
+
payload: AuditLogRequest
|
|
89
|
+
): Promise<AuditLogResponse> {
|
|
90
|
+
const client = Client.getInstance();
|
|
91
|
+
const url = client.getDomain() + AUDIT_LOG_API_PATH;
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
return await makeApiRequest<AuditLogResponse>({
|
|
95
|
+
method: PUT,
|
|
96
|
+
url,
|
|
97
|
+
data: payload,
|
|
98
|
+
});
|
|
99
|
+
} catch (error) {
|
|
100
|
+
return handleAuditLogError(error, true);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -7,6 +7,7 @@ import { makeApiRequest } from "../request";
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Performs scope 3 Spend based emission calculations by making a POST request to the economic activity API endpoint.
|
|
10
|
+
* Supports optional attribution with revenue for proportional allocation.
|
|
10
11
|
*
|
|
11
12
|
* @export
|
|
12
13
|
* @param {CommonRequest} payload - The request data to be sent to the API
|
|
@@ -14,6 +15,7 @@ import { makeApiRequest } from "../request";
|
|
|
14
15
|
* @throws {Error} May throw an error if the API request fails
|
|
15
16
|
*
|
|
16
17
|
* @example
|
|
18
|
+
* // Basic economic activity request
|
|
17
19
|
* const request = {
|
|
18
20
|
"time": {
|
|
19
21
|
"date": "2025-01-04"
|
|
@@ -29,6 +31,28 @@ import { makeApiRequest } from "../request";
|
|
|
29
31
|
"includeDetails": false
|
|
30
32
|
};
|
|
31
33
|
* const result = await calculate(request);
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* // Economic activity request with revenue attribution
|
|
37
|
+
* const requestWithAttribution = {
|
|
38
|
+
"time": {
|
|
39
|
+
"date": "2025-01-04"
|
|
40
|
+
},
|
|
41
|
+
"location": {
|
|
42
|
+
"country": "usa"
|
|
43
|
+
},
|
|
44
|
+
"activity": {
|
|
45
|
+
"type": "accomodation",
|
|
46
|
+
"value": 1500.12,
|
|
47
|
+
"unit": "usd"
|
|
48
|
+
},
|
|
49
|
+
"attribution": {
|
|
50
|
+
"outstandingAmount": 500000.0,
|
|
51
|
+
"revenue": 2000000.0
|
|
52
|
+
},
|
|
53
|
+
"includeDetails": true
|
|
54
|
+
};
|
|
55
|
+
* const resultWithAttribution = await calculate(requestWithAttribution);
|
|
32
56
|
*/
|
|
33
57
|
|
|
34
58
|
export async function calculate(
|
package/src/api/Factor.ts
CHANGED
|
@@ -60,18 +60,89 @@ export async function retrieveFactor(
|
|
|
60
60
|
* @return {Promise<SearchResponse>} A promise that resolves to the search results returned by the API
|
|
61
61
|
* @throws {Error} May throw an error if the API request fails
|
|
62
62
|
*
|
|
63
|
+
* The API applies cross-encoder reranking by default. Set `enableReranker` to
|
|
64
|
+
* `false` to keep semantic similarity ordering without reranking.
|
|
65
|
+
*
|
|
63
66
|
* @example
|
|
67
|
+
* // Basic search
|
|
64
68
|
* const searchRequest = {
|
|
65
69
|
"time":{
|
|
66
70
|
"date": "2020-06-10"
|
|
67
71
|
},
|
|
68
72
|
"activity": {
|
|
69
|
-
"search" : "travel"
|
|
73
|
+
"search" : "travel"
|
|
74
|
+
},
|
|
70
75
|
"location": {
|
|
71
76
|
"country": "USA"
|
|
72
77
|
}
|
|
73
78
|
};
|
|
74
79
|
* const results = await search(searchRequest);
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* // Search without cross-encoder reranking
|
|
83
|
+
* const searchWithoutReranker = {
|
|
84
|
+
"time":{
|
|
85
|
+
"date": "2020-06-10"
|
|
86
|
+
},
|
|
87
|
+
"activity": {
|
|
88
|
+
"search" : "travel"
|
|
89
|
+
},
|
|
90
|
+
"location": {
|
|
91
|
+
"country": "USA"
|
|
92
|
+
},
|
|
93
|
+
"enableReranker": false
|
|
94
|
+
};
|
|
95
|
+
* const results = await search(searchWithoutReranker);
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* // Search with optional unit parameter
|
|
99
|
+
* const searchWithUnit = {
|
|
100
|
+
"time":{
|
|
101
|
+
"date": "2020-06-10"
|
|
102
|
+
},
|
|
103
|
+
"activity": {
|
|
104
|
+
"search": "electricity",
|
|
105
|
+
"unit": "kWh"
|
|
106
|
+
},
|
|
107
|
+
"location": {
|
|
108
|
+
"country": "USA"
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
* const results = await search(searchWithUnit);
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* // Search with optional scope parameter
|
|
115
|
+
* const searchWithScope = {
|
|
116
|
+
"time":{
|
|
117
|
+
"date": "2020-06-10"
|
|
118
|
+
},
|
|
119
|
+
"activity": {
|
|
120
|
+
"search": "natural gas",
|
|
121
|
+
"scope": "1"
|
|
122
|
+
},
|
|
123
|
+
"location": {
|
|
124
|
+
"country": "USA"
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
* const results = await search(searchWithScope);
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* // Search with both unit and scope parameters
|
|
131
|
+
* const searchWithBoth = {
|
|
132
|
+
"time":{
|
|
133
|
+
"date": "2020-06-10"
|
|
134
|
+
},
|
|
135
|
+
"activity": {
|
|
136
|
+
"search": "electricity",
|
|
137
|
+
"unit": "MWh",
|
|
138
|
+
"scope": "2"
|
|
139
|
+
},
|
|
140
|
+
"location": {
|
|
141
|
+
"country": "USA",
|
|
142
|
+
"stateProvince": "california"
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
* const results = await search(searchWithBoth);
|
|
75
146
|
*/
|
|
76
147
|
export async function search(
|
|
77
148
|
payload: SearchRequest
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Client } from "../Client";
|
|
2
|
+
import { PHYSICAL_ACTIVITY_API_PATH, POST } from "../Constants";
|
|
3
|
+
import { CommonRequest } from "../interfaces/Api";
|
|
4
|
+
import { EmissionResponse } from "../interfaces/response/EmissionResponse";
|
|
5
|
+
import { EmissionResponseWithDetails } from "../interfaces/response/EmissionResponseWithDetails";
|
|
6
|
+
import { makeApiRequest } from "../request";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Performs scope 3 Physical activity emission calculations by making a POST request to the physical activity API endpoint.
|
|
10
|
+
* Supports attribution for private companies using equity/debt based calculations or EVIC (Enterprise Value Including Cash).
|
|
11
|
+
*
|
|
12
|
+
* @export
|
|
13
|
+
* @param {CommonRequest} payload - The request data to be sent to the API
|
|
14
|
+
* @return {Promise<EmissionResponse | EmissionResponseWithDetails>} A promise that resolves to the emission calculation result. Returns EmissionResponseWithDetails if includeDetails is true, otherwise EmissionResponse
|
|
15
|
+
* @throws {Error} May throw an error if the API request fails
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // Basic physical activity request
|
|
19
|
+
* const request = {
|
|
20
|
+
"time": {
|
|
21
|
+
"date": "2025-01-23"
|
|
22
|
+
},
|
|
23
|
+
"location": {
|
|
24
|
+
"country": "usa"
|
|
25
|
+
},
|
|
26
|
+
"activity": {
|
|
27
|
+
"type": "commercial real estate",
|
|
28
|
+
"value": 0.1,
|
|
29
|
+
"unit": "km2"
|
|
30
|
+
},
|
|
31
|
+
"includeDetails": true
|
|
32
|
+
};
|
|
33
|
+
* const result = await calculate(request);
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* // Physical activity request with attribution (equity/debt based for private companies)
|
|
37
|
+
* const requestWithEquityDebt = {
|
|
38
|
+
"time": {
|
|
39
|
+
"date": "2025-01-23"
|
|
40
|
+
},
|
|
41
|
+
"location": {
|
|
42
|
+
"country": "usa"
|
|
43
|
+
},
|
|
44
|
+
"activity": {
|
|
45
|
+
"type": "commercial real estate",
|
|
46
|
+
"value": 0.1,
|
|
47
|
+
"unit": "km2"
|
|
48
|
+
},
|
|
49
|
+
"attribution": {
|
|
50
|
+
"outstandingAmount": 1000000,
|
|
51
|
+
"totalEquity": 3000000,
|
|
52
|
+
"totalDebt": 2000000
|
|
53
|
+
},
|
|
54
|
+
"includeDetails": true
|
|
55
|
+
};
|
|
56
|
+
* const resultWithEquityDebt = await calculate(requestWithEquityDebt);
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* // Physical activity request with attribution (EVIC based)
|
|
60
|
+
* const requestWithEVIC = {
|
|
61
|
+
"time": {
|
|
62
|
+
"date": "2025-01-23"
|
|
63
|
+
},
|
|
64
|
+
"location": {
|
|
65
|
+
"country": "usa"
|
|
66
|
+
},
|
|
67
|
+
"activity": {
|
|
68
|
+
"type": "commercial real estate",
|
|
69
|
+
"value": 0.1,
|
|
70
|
+
"unit": "km2"
|
|
71
|
+
},
|
|
72
|
+
"attribution": {
|
|
73
|
+
"outstandingAmount": 1000000.0,
|
|
74
|
+
"evic": 10000000.0
|
|
75
|
+
},
|
|
76
|
+
"includeDetails": true
|
|
77
|
+
};
|
|
78
|
+
* const resultWithEVIC = await calculate(requestWithEVIC);
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
export async function calculate(
|
|
82
|
+
payload: CommonRequest
|
|
83
|
+
): Promise<EmissionResponse | EmissionResponseWithDetails> {
|
|
84
|
+
const client = Client.getInstance();
|
|
85
|
+
const url = client.getDomain() + PHYSICAL_ACTIVITY_API_PATH;
|
|
86
|
+
|
|
87
|
+
return makeApiRequest<EmissionResponse | EmissionResponseWithDetails>({
|
|
88
|
+
method: POST,
|
|
89
|
+
url,
|
|
90
|
+
data: payload,
|
|
91
|
+
});
|
|
92
|
+
}
|
package/src/api/RealEstate.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { makeApiRequest } from "../request";
|
|
|
14
14
|
* @throws {Error} May throw an error if the API request fails
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
|
+
* // Basic request without attribution
|
|
17
18
|
* const request = {
|
|
18
19
|
"time": {
|
|
19
20
|
"date": "2025-01-04"
|
|
@@ -29,6 +30,28 @@ import { makeApiRequest } from "../request";
|
|
|
29
30
|
"includeDetails": false
|
|
30
31
|
};
|
|
31
32
|
* const result = await calculate(request);
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* // Request with attribution (property value based)
|
|
36
|
+
* const requestWithAttribution = {
|
|
37
|
+
"time": {
|
|
38
|
+
"date": "2022-01-01"
|
|
39
|
+
},
|
|
40
|
+
"location": {
|
|
41
|
+
"country": "usa",
|
|
42
|
+
"stateProvince": "new york"
|
|
43
|
+
},
|
|
44
|
+
"activity": {
|
|
45
|
+
"type": "Commercial Real Estate:Office",
|
|
46
|
+
"value": 123456.0,
|
|
47
|
+
"unit": "m2"
|
|
48
|
+
},
|
|
49
|
+
"attribution": {
|
|
50
|
+
"outstandingAmount": 1000000.0,
|
|
51
|
+
"propertyValue": 5000000.0
|
|
52
|
+
},
|
|
53
|
+
"includeDetails": true
|
|
54
|
+
};
|
|
32
55
|
*/
|
|
33
56
|
|
|
34
57
|
export async function calculate(
|
|
@@ -5,14 +5,20 @@ import { TypeRecommenderResponse } from "../interfaces/response/TypeRecommenderR
|
|
|
5
5
|
import { makeApiRequest } from "../request";
|
|
6
6
|
|
|
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
|
|
21
|
+
* // Basic search
|
|
16
22
|
* const result = await search({
|
|
17
23
|
"location": {
|
|
18
24
|
"country": "usa"
|
|
@@ -23,6 +29,7 @@ import { makeApiRequest } from "../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 @@ import { makeApiRequest } from "../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 @@ import { makeApiRequest } from "../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
|
export async function search(
|
|
55
120
|
payload: SearchRequest
|
package/src/index.ts
CHANGED
|
@@ -10,10 +10,15 @@ export * as Factor from './api/Factor';
|
|
|
10
10
|
export * as FactorSets from './api/FactorSets'
|
|
11
11
|
export * as EconomicActivity from './api/EconomicActivity';
|
|
12
12
|
export * as RealEstate from './api/RealEstate';
|
|
13
|
+
export * as PhysicalActivity from './api/PhysicalActivity';
|
|
13
14
|
export * as Metadata from './api/Metadata';
|
|
14
15
|
export * as TypeRecommender from './api/TypeRecommender';
|
|
16
|
+
export * as AuditLog from './api/AuditLog';
|
|
15
17
|
export { ClientConfig } from './interfaces/Config';
|
|
16
18
|
|
|
19
|
+
// Common interfaces
|
|
20
|
+
export { Attribution } from './interfaces/common';
|
|
21
|
+
|
|
17
22
|
// Response interfaces
|
|
18
23
|
export { AreaResponse, Location as LocationInfo } from './interfaces/response/AreaResponse';
|
|
19
24
|
export { EmissionResponse } from './interfaces/response/EmissionResponse';
|
|
@@ -37,4 +42,5 @@ export {
|
|
|
37
42
|
export { TypeResponse } from './interfaces/response/TypeResponse';
|
|
38
43
|
export { UnitResponse } from './interfaces/response/UnitResponse';
|
|
39
44
|
export { UsageResponse } from './interfaces/response/UsageResponse';
|
|
40
|
-
export { TypeRecommenderResponse, ActivityRequest } from './interfaces/response/TypeRecommenderResponse';
|
|
45
|
+
export { TypeRecommenderResponse, ActivityRequest } from './interfaces/response/TypeRecommenderResponse';
|
|
46
|
+
export { AuditLogResponse, AuditLogRequest } from './interfaces/response/AuditLogResponse';
|