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.
- package/README.md +65 -2
- package/dist/Constants.js +7 -1
- package/dist/api/AuditExport.js +73 -0
- package/dist/api/AuditLog.js +99 -0
- package/dist/api/EconomicActivity.js +69 -0
- package/dist/api/Factor.js +16 -0
- package/dist/api/PhysicalActivity.js +87 -0
- package/dist/api/RealEstate.js +25 -1
- package/dist/api/TypeRecommender.js +19 -2
- package/dist/coverage/clover.xml +172 -89
- package/dist/coverage/coverage-final.json +15 -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 +45 -27
- package/dist/coverage/lcov-report/src/api/AuditExport.ts.html +355 -0
- 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 +212 -5
- package/dist/coverage/lcov-report/src/api/Factor.ts.html +54 -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 +78 -6
- 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 +51 -6
- package/dist/coverage/lcov-report/src/index.html +7 -7
- package/dist/coverage/lcov-report/src/request.ts.html +8 -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 +284 -124
- package/dist/index.js +4 -1
- package/dist/interfaces/response/AuditExportResponse.js +2 -0
- package/dist/interfaces/response/AuditLogResponse.js +2 -0
- package/dist/request.js +1 -0
- package/dist/types/Constants.d.ts +6 -0
- package/dist/types/api/AuditExport.d.ts +42 -0
- package/dist/types/api/AuditLog.d.ts +37 -0
- package/dist/types/api/EconomicActivity.d.ts +69 -0
- package/dist/types/api/Factor.d.ts +16 -0
- package/dist/types/api/PhysicalActivity.d.ts +76 -0
- package/dist/types/api/RealEstate.d.ts +25 -1
- package/dist/types/api/TypeRecommender.d.ts +19 -2
- package/dist/types/index.d.ts +6 -0
- package/dist/types/interfaces/Api.d.ts +17 -1
- package/dist/types/interfaces/Config.d.ts +5 -1
- package/dist/types/interfaces/common.d.ts +40 -0
- package/dist/types/interfaces/response/AuditExportResponse.d.ts +66 -0
- package/dist/types/interfaces/response/AuditLogResponse.d.ts +40 -0
- package/dist/types/interfaces/response/TypeRecommenderResponse.d.ts +2 -0
- package/docs/_sources/authentication.rst.txt +26 -4
- package/docs/_sources/getting_started.rst.txt +762 -74
- package/docs/_sources/index.rst.txt +13 -0
- package/docs/_sources/reference.rst.txt +48 -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 +77 -24
- package/docs/getting_started.html +969 -103
- package/docs/index.html +69 -21
- package/docs/reference.html +747 -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 +8 -3
- package/sphinx-build/source/authentication.rst +26 -4
- package/sphinx-build/source/getting_started.rst +762 -74
- package/sphinx-build/source/index.rst +13 -0
- package/sphinx-build/source/reference.rst +48 -0
- package/sphinx-build/source/troubleshooting.rst +77 -12
- package/src/Constants.ts +6 -0
- package/src/api/AuditExport.ts +90 -0
- package/src/api/AuditLog.ts +102 -0
- package/src/api/EconomicActivity.ts +69 -0
- package/src/api/Factor.ts +17 -1
- package/src/api/PhysicalActivity.ts +92 -0
- package/src/api/RealEstate.ts +25 -1
- package/src/api/TypeRecommender.ts +19 -2
- package/src/index.ts +15 -1
- package/src/interfaces/Api.ts +22 -6
- package/src/interfaces/Config.ts +6 -1
- package/src/interfaces/common.ts +46 -0
- package/src/interfaces/response/AuditExportResponse.ts +88 -0
- package/src/interfaces/response/AuditLogResponse.ts +47 -0
- package/src/interfaces/response/TypeRecommenderResponse.ts +3 -0
- package/src/request.ts +1 -0
- package/test/apiTest.test.ts +59 -3
- package/test/auditExport.test.ts +68 -0
- 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/docs/_static/base-stemmer.js +0 -476
- package/docs/_static/english-stemmer.js +0 -1066
|
@@ -7,6 +7,8 @@ IBM Envizi - Emissions API Node.js SDK
|
|
|
7
7
|
|
|
8
8
|
getting_started
|
|
9
9
|
sdk
|
|
10
|
+
authentication
|
|
11
|
+
client
|
|
10
12
|
reference
|
|
11
13
|
troubleshooting
|
|
12
14
|
|
|
@@ -27,6 +29,17 @@ Supported Emission Types
|
|
|
27
29
|
* **Transportation & distribution** – logistics and supply chain activities
|
|
28
30
|
* **Real Estate** – emissions from commercial and residential properties
|
|
29
31
|
* **Economic Activity** – spend-based emissions from business activities
|
|
32
|
+
* **Physical Activity** – scope 3 emissions from physical activities with attribution for private companies (equity/debt or EVIC-based)
|
|
30
33
|
* **Generic** – custom emission calculations
|
|
31
34
|
|
|
32
35
|
The SDK is designed for embedding emission calculations in applications, building sustainability dashboards, automating large-scale datasets, and tracking carbon footprints.
|
|
36
|
+
|
|
37
|
+
Additional capabilities
|
|
38
|
+
-----------------------
|
|
39
|
+
|
|
40
|
+
* **Metadata API** – query supported types, areas, and units across endpoints
|
|
41
|
+
* **Type Recommender API** – semantic search to identify likely activity types, with optional reranker control and scope in results
|
|
42
|
+
* **Factor Search API** – search for emission factors with unit and scope filtering, with optional reranker control
|
|
43
|
+
* **Usage API** – retrieve organization billing-period or historical usage
|
|
44
|
+
* **Audit Log API** – manage whether API requests and responses are stored for auditing
|
|
45
|
+
* **Audit Export API** – export, monitor, and download organization audit data
|
|
@@ -15,6 +15,8 @@ API
|
|
|
15
15
|
|
|
16
16
|
.. js:autofunction:: Factor.retrieveFactor
|
|
17
17
|
|
|
18
|
+
.. js:autofunction:: Factor.search
|
|
19
|
+
|
|
18
20
|
.. js:autofunction:: Fugitive.calculate
|
|
19
21
|
|
|
20
22
|
.. js:autofunction:: Calculation.calculate
|
|
@@ -30,6 +32,36 @@ API
|
|
|
30
32
|
.. js:autofunction:: RealEstate.calculate
|
|
31
33
|
|
|
32
34
|
.. js:autofunction:: EconomicActivity.calculate
|
|
35
|
+
|
|
36
|
+
.. js:autofunction:: PhysicalActivity.calculate
|
|
37
|
+
|
|
38
|
+
Type Recommender API
|
|
39
|
+
====================
|
|
40
|
+
|
|
41
|
+
.. js:autofunction:: TypeRecommender.search
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
Audit Log API
|
|
45
|
+
=============
|
|
46
|
+
|
|
47
|
+
Controls whether the organization's API requests and responses are stored for auditing.
|
|
48
|
+
Organizations can disable storage if they don't need their API calls to be audited.
|
|
49
|
+
|
|
50
|
+
.. js:autofunction:: AuditLog.getAuditConfig
|
|
51
|
+
|
|
52
|
+
.. js:autofunction:: AuditLog.updateAuditConfig
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
Audit Export API
|
|
56
|
+
================
|
|
57
|
+
|
|
58
|
+
The Audit Export API asynchronously generates an audit-data ZIP archive for an admin user. Call ``trigger`` to create an export, ``getStatus`` until it is complete, and ``download`` to retrieve the archive.
|
|
59
|
+
|
|
60
|
+
.. js:autofunction:: AuditExport.trigger
|
|
61
|
+
|
|
62
|
+
.. js:autofunction:: AuditExport.getStatus
|
|
63
|
+
|
|
64
|
+
.. js:autofunction:: AuditExport.download
|
|
33
65
|
|
|
34
66
|
|
|
35
67
|
Global Metadata API
|
|
@@ -113,3 +145,19 @@ Interfaces
|
|
|
113
145
|
.. js:autoclass:: Config.RequestConfig
|
|
114
146
|
|
|
115
147
|
.. js:autoclass:: Config.ClientConfig
|
|
148
|
+
|
|
149
|
+
.. js:autoclass:: AuditLogResponse.AuditLogResponse
|
|
150
|
+
|
|
151
|
+
.. js:autoclass:: AuditLogResponse.AuditLogRequest
|
|
152
|
+
|
|
153
|
+
.. js:autoclass:: TypeRecommenderResponse.TypeRecommenderResponse
|
|
154
|
+
|
|
155
|
+
.. js:autoclass:: TypeRecommenderResponse.ActivityRequest
|
|
156
|
+
|
|
157
|
+
.. js:autoclass:: AuditExportResponse.AuditExportRequest
|
|
158
|
+
|
|
159
|
+
.. js:autoclass:: AuditExportResponse.AuditExportResponse
|
|
160
|
+
|
|
161
|
+
.. js:autoclass:: AuditExportResponse.AuditExportStatusResponse
|
|
162
|
+
|
|
163
|
+
.. js:autoclass:: AuditExportResponse.AuditExportLinks
|
|
@@ -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,11 @@ 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";
|
|
17
|
+
export const AUDIT_EXPORT_API_PATH = "/v3/carbon/audit";
|
|
18
|
+
export const AUDIT_EXPORT_STATUS_API_PATH = "/v3/carbon/audit/status";
|
|
19
|
+
export const AUDIT_EXPORT_DOWNLOAD_API_PATH = "/v3/carbon/audit/download";
|
|
15
20
|
|
|
16
21
|
export const TYPE_RECOMMENDER_API_PATH = "/v3/carbon/recommender/type/search";
|
|
17
22
|
|
|
@@ -23,6 +28,7 @@ export const METADATA_UNITS_ENDPOINT = "/v3/carbon/metadata/units";
|
|
|
23
28
|
|
|
24
29
|
export const GET = "GET";
|
|
25
30
|
export const POST = "POST";
|
|
31
|
+
export const PUT = "PUT";
|
|
26
32
|
export const CLIENT_SOURCE_HEADER = "X-Client-Source";
|
|
27
33
|
export const CLIENT_SOURCE_EXCEL = "excel";
|
|
28
34
|
export const CLIENT_SOURCE_SDK = "node-sdk";
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import { Client } from "../Client";
|
|
3
|
+
import {
|
|
4
|
+
AUDIT_EXPORT_API_PATH,
|
|
5
|
+
AUDIT_EXPORT_DOWNLOAD_API_PATH,
|
|
6
|
+
AUDIT_EXPORT_STATUS_API_PATH,
|
|
7
|
+
GET,
|
|
8
|
+
POST,
|
|
9
|
+
} from "../Constants";
|
|
10
|
+
import {
|
|
11
|
+
AuditExportRequest,
|
|
12
|
+
AuditExportResponse,
|
|
13
|
+
AuditExportStatusResponse,
|
|
14
|
+
} from "../interfaces/response/AuditExportResponse";
|
|
15
|
+
import { makeApiRequest } from "../request";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Triggers an asynchronous audit data export.
|
|
19
|
+
*
|
|
20
|
+
* @export
|
|
21
|
+
* @param {AuditExportRequest} payload - Date range and optional API-name filter for the export
|
|
22
|
+
* @return {Promise<AuditExportResponse>} The accepted export request, including its request ID
|
|
23
|
+
* @throws {Error} Throws if the request is invalid, the caller is not an admin, or a matching export already exists
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* const auditExport = await trigger({
|
|
27
|
+
* fromDate: "2025-01-01",
|
|
28
|
+
* toDate: "2025-03-31",
|
|
29
|
+
* apiName: "location"
|
|
30
|
+
* });
|
|
31
|
+
*/
|
|
32
|
+
export async function trigger(
|
|
33
|
+
payload: AuditExportRequest
|
|
34
|
+
): Promise<AuditExportResponse> {
|
|
35
|
+
const client = Client.getInstance();
|
|
36
|
+
const url = client.getDomain() + AUDIT_EXPORT_API_PATH;
|
|
37
|
+
|
|
38
|
+
return makeApiRequest<AuditExportResponse>({
|
|
39
|
+
method: POST,
|
|
40
|
+
url,
|
|
41
|
+
data: payload,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Retrieves the processing status of an audit export.
|
|
47
|
+
*
|
|
48
|
+
* @export
|
|
49
|
+
* @param {string} requestId - Request ID returned by trigger
|
|
50
|
+
* @return {Promise<AuditExportStatusResponse>} Current export status and, when complete, download details
|
|
51
|
+
* @throws {Error} Throws if the request ID is invalid or the caller is not an admin
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* const status = await getStatus(auditExport.requestId);
|
|
55
|
+
*/
|
|
56
|
+
export async function getStatus(
|
|
57
|
+
requestId: string
|
|
58
|
+
): Promise<AuditExportStatusResponse> {
|
|
59
|
+
const client = Client.getInstance();
|
|
60
|
+
const url = client.getDomain() + AUDIT_EXPORT_STATUS_API_PATH;
|
|
61
|
+
|
|
62
|
+
return makeApiRequest<AuditExportStatusResponse>({
|
|
63
|
+
method: GET,
|
|
64
|
+
url,
|
|
65
|
+
params: { requestId },
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Downloads a completed audit export as a ZIP archive.
|
|
71
|
+
*
|
|
72
|
+
* @export
|
|
73
|
+
* @param {string} requestId - Request ID returned by trigger
|
|
74
|
+
* @return {Promise<Buffer>} ZIP archive containing audit-export.csv
|
|
75
|
+
* @throws {Error} Throws while processing, when the export failed or expired, or if the caller is not an admin
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* const auditExportZip = await download(auditExport.requestId);
|
|
79
|
+
*/
|
|
80
|
+
export async function download(requestId: string): Promise<Buffer> {
|
|
81
|
+
const client = Client.getInstance();
|
|
82
|
+
const url = client.getDomain() + AUDIT_EXPORT_DOWNLOAD_API_PATH;
|
|
83
|
+
|
|
84
|
+
return makeApiRequest<Buffer>({
|
|
85
|
+
method: GET,
|
|
86
|
+
url,
|
|
87
|
+
params: { requestId },
|
|
88
|
+
responseType: "arraybuffer",
|
|
89
|
+
});
|
|
90
|
+
}
|
|
@@ -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,73 @@ 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);
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* // Economic activity request with attribution (equity/debt based for private companies)
|
|
59
|
+
* const requestWithEquityDebt = {
|
|
60
|
+
"time": {
|
|
61
|
+
"date": "2025-01-04"
|
|
62
|
+
},
|
|
63
|
+
"location": {
|
|
64
|
+
"country": "usa"
|
|
65
|
+
},
|
|
66
|
+
"activity": {
|
|
67
|
+
"type": "accomodation",
|
|
68
|
+
"value": 1500.12,
|
|
69
|
+
"unit": "usd"
|
|
70
|
+
},
|
|
71
|
+
"attribution": {
|
|
72
|
+
"outstandingAmount": 500000.0,
|
|
73
|
+
"totalEquity": 3000000.0,
|
|
74
|
+
"totalDebt": 2000000.0
|
|
75
|
+
},
|
|
76
|
+
"includeDetails": true
|
|
77
|
+
};
|
|
78
|
+
* const resultWithEquityDebt = await calculate(requestWithEquityDebt);
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* // Economic activity request with attribution (EVIC based for listed companies)
|
|
82
|
+
* const requestWithEvic = {
|
|
83
|
+
"time": {
|
|
84
|
+
"date": "2025-01-04"
|
|
85
|
+
},
|
|
86
|
+
"location": {
|
|
87
|
+
"country": "usa"
|
|
88
|
+
},
|
|
89
|
+
"activity": {
|
|
90
|
+
"type": "accomodation",
|
|
91
|
+
"value": 1500.12,
|
|
92
|
+
"unit": "usd"
|
|
93
|
+
},
|
|
94
|
+
"attribution": {
|
|
95
|
+
"outstandingAmount": 500000.0,
|
|
96
|
+
"evic": 10000000.0
|
|
97
|
+
},
|
|
98
|
+
"includeDetails": true
|
|
99
|
+
};
|
|
100
|
+
* const resultWithEvic = await calculate(requestWithEvic);
|
|
32
101
|
*/
|
|
33
102
|
|
|
34
103
|
export async function calculate(
|
package/src/api/Factor.ts
CHANGED
|
@@ -60,6 +60,9 @@ 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
|
|
64
67
|
* // Basic search
|
|
65
68
|
* const searchRequest = {
|
|
@@ -76,6 +79,19 @@ export async function retrieveFactor(
|
|
|
76
79
|
* const results = await search(searchRequest);
|
|
77
80
|
*
|
|
78
81
|
* @example
|
|
82
|
+
* // Search without cross-encoder reranking
|
|
83
|
+
* const searchWithoutReranker = {
|
|
84
|
+
"activity": {
|
|
85
|
+
"search": "travel"
|
|
86
|
+
},
|
|
87
|
+
"location": {
|
|
88
|
+
"country": "USA"
|
|
89
|
+
},
|
|
90
|
+
"enableReranker": false
|
|
91
|
+
};
|
|
92
|
+
* const results = await search(searchWithoutReranker);
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
79
95
|
* // Search with optional unit parameter
|
|
80
96
|
* const searchWithUnit = {
|
|
81
97
|
"time":{
|
|
@@ -136,4 +152,4 @@ export async function search(
|
|
|
136
152
|
url,
|
|
137
153
|
data: payload,
|
|
138
154
|
});
|
|
139
|
-
}
|
|
155
|
+
}
|
|
@@ -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
|
+
}
|