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
@@ -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,7 +30,30 @@ import { makeApiRequest } from "../request";
29
30
  "includeDetails": false
30
31
  };
31
32
  * const result = await calculate(request);
32
- */
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
+ };
55
+ * const resultWithAttribution = await calculate(requestWithAttribution);
56
+ */
33
57
 
34
58
  export async function calculate(
35
59
  payload: CommonRequest
@@ -5,13 +5,18 @@ 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<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 @@ import { makeApiRequest } from "../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": {
package/src/index.ts CHANGED
@@ -10,10 +10,16 @@ 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';
17
+ export * as AuditExport from './api/AuditExport';
15
18
  export { ClientConfig } from './interfaces/Config';
16
19
 
20
+ // Common interfaces
21
+ export { Attribution } from './interfaces/common';
22
+
17
23
  // Response interfaces
18
24
  export { AreaResponse, Location as LocationInfo } from './interfaces/response/AreaResponse';
19
25
  export { EmissionResponse } from './interfaces/response/EmissionResponse';
@@ -37,4 +43,12 @@ export {
37
43
  export { TypeResponse } from './interfaces/response/TypeResponse';
38
44
  export { UnitResponse } from './interfaces/response/UnitResponse';
39
45
  export { UsageResponse } from './interfaces/response/UsageResponse';
40
- export { TypeRecommenderResponse, ActivityRequest } from './interfaces/response/TypeRecommenderResponse';
46
+ export { TypeRecommenderResponse, ActivityRequest } from './interfaces/response/TypeRecommenderResponse';
47
+ export { AuditLogResponse, AuditLogRequest } from './interfaces/response/AuditLogResponse';
48
+ export {
49
+ AuditExportRequest,
50
+ AuditExportResponse,
51
+ AuditExportStatus,
52
+ AuditExportStatusResponse,
53
+ AuditExportLinks
54
+ } from './interfaces/response/AuditExportResponse';
@@ -1,4 +1,4 @@
1
- import { Activity, Location , Time, CombinedUnitsActivity, FactorActivity, SearchActivity, Pagination, FactorActivityWithFactorId, CombinedUnitsActivityWithFactorId, ActivityWithFactorId } from "./common";
1
+ import { Activity, Location , Time, CombinedUnitsActivity, FactorActivity, SearchActivity, Pagination, FactorActivityWithFactorId, CombinedUnitsActivityWithFactorId, ActivityWithFactorId, Attribution } from "./common";
2
2
 
3
3
  /**
4
4
  * Represents activity data associated with a location, with simplified requirements.
@@ -105,7 +105,7 @@ export interface LocationRequestWithFactorId {
105
105
  /**
106
106
  * Common request parameters for calculations without specifying a factor ID.
107
107
  * Used for general-purpose calculations based on location, time, and activity data.
108
- *
108
+ *
109
109
  * @interface CommonRequestWithoutFactorId
110
110
  */
111
111
  export interface CommonRequestWithoutFactorId {
@@ -124,18 +124,23 @@ export interface CommonRequestWithoutFactorId {
124
124
  * Contains complete activity information including type, value, and unit.
125
125
  */
126
126
  activity: Activity;
127
+ /**
128
+ * Optional attribution information for FE calculations.
129
+ * Contains outstanding amount, property value, and currency.
130
+ */
131
+ attribution?: Attribution;
127
132
  /**
128
133
  * Whether to include additional details in the response.
129
134
  * When true, the API will return more comprehensive information.
130
135
  * @default false
131
136
  */
132
137
  includeDetails?: boolean;
133
- }
138
+ }
134
139
 
135
140
  /**
136
141
  * Common request parameters for calculations with a specific factor ID.
137
142
  * Used when the emission factor is already known and doesn't need to be determined by location.
138
- *
143
+ *
139
144
  * @interface CommonRequestWithFactorId
140
145
  */
141
146
  export interface CommonRequestWithFactorId {
@@ -143,13 +148,18 @@ export interface CommonRequestWithFactorId {
143
148
  * The activity data for the calculation, including the specific factor ID to use.
144
149
  */
145
150
  activity: ActivityWithFactorId;
151
+ /**
152
+ * Optional attribution information for FE calculations.
153
+ * Contains outstanding amount, property value, and currency.
154
+ */
155
+ attribution?: Attribution;
146
156
  /**
147
157
  * Whether to include additional details in the response.
148
158
  * When true, the API will return more comprehensive information.
149
159
  * @default false
150
160
  */
151
161
  includeDetails?: boolean;
152
- }
162
+ }
153
163
 
154
164
  /**
155
165
  * Request parameters for generic calculations without specifying a factor ID.
@@ -264,7 +274,13 @@ export interface SearchRequest {
264
274
  * Optional pagination parameters for the search results.
265
275
  * Used to limit the number of results and implement paging.
266
276
  */
267
- pagination?: Pagination
277
+ pagination?: Pagination;
278
+ /**
279
+ * Optional reranker toggle for factor and type searches.
280
+ * Defaults to true when omitted. Set to false to use semantic similarity
281
+ * results directly without cross-encoder reranking.
282
+ */
283
+ enableReranker?: boolean;
268
284
  }
269
285
 
270
286
  /**
@@ -1,4 +1,4 @@
1
- import { Method } from "axios";
1
+ import { Method, ResponseType } from "axios";
2
2
 
3
3
  /**
4
4
  * Configuration for making HTTP requests.
@@ -29,6 +29,11 @@ export interface RequestConfig {
29
29
  * Optional HTTP headers to be included with the request.
30
30
  */
31
31
  headers?: Record<string, string>;
32
+
33
+ /**
34
+ * Optional response type expected from the API.
35
+ */
36
+ responseType?: ResponseType;
32
37
  }
33
38
 
34
39
  /**
@@ -184,3 +184,49 @@ export interface Pagination {
184
184
  */
185
185
  size: number
186
186
  }
187
+
188
+ /**
189
+ * Represents attribution information for real estate, physical activity, and economic activity calculations.
190
+ * Supports four scenarios:
191
+ * 1. Property value based (for general real estate)
192
+ * 2. Equity/Debt based (for private companies)
193
+ * 3. EVIC based (Enterprise Value Including Cash for physical activity)
194
+ * 4. Revenue based (for economic activity)
195
+ * @interface Attribution
196
+ */
197
+ export interface Attribution {
198
+ /**
199
+ * The outstanding amount for the property or activity.
200
+ */
201
+ outstandingAmount?: number;
202
+
203
+ /**
204
+ * The total property value (used in property value based scenario).
205
+ * Optional - use either propertyValue OR (totalEquity + totalDebt) OR evic OR revenue.
206
+ */
207
+ propertyValue?: number;
208
+
209
+ /**
210
+ * The total equity amount (used in equity/debt based scenario for private companies).
211
+ * Optional - use either propertyValue OR (totalEquity + totalDebt) OR evic OR revenue.
212
+ */
213
+ totalEquity?: number;
214
+
215
+ /**
216
+ * The total debt amount (used in equity/debt based scenario for private companies).
217
+ * Optional - use either propertyValue OR (totalEquity + totalDebt) OR evic OR revenue.
218
+ */
219
+ totalDebt?: number;
220
+
221
+ /**
222
+ * Enterprise Value Including Cash (EVIC) - used in EVIC based scenario for physical activity calculations.
223
+ * Optional - use either propertyValue OR (totalEquity + totalDebt) OR evic OR revenue.
224
+ */
225
+ evic?: number;
226
+
227
+ /**
228
+ * Total revenue - used in revenue based scenario for economic activity calculations.
229
+ * Optional - use either propertyValue OR (totalEquity + totalDebt) OR evic OR revenue.
230
+ */
231
+ revenue?: number;
232
+ }
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Request body used to trigger an audit data export.
3
+ *
4
+ * @interface AuditExportRequest
5
+ */
6
+ export interface AuditExportRequest {
7
+ /** Inclusive start date in yyyy-MM-dd format. */
8
+ fromDate: string;
9
+
10
+ /** Inclusive end date in yyyy-MM-dd format. */
11
+ toDate: string;
12
+
13
+ /** Optional case-insensitive endpoint filter. */
14
+ apiName?: string;
15
+ }
16
+
17
+ /**
18
+ * Processing states for an audit export.
19
+ */
20
+ export type AuditExportStatus =
21
+ | "QUEUED"
22
+ | "IN_PROGRESS"
23
+ | "COMPLETED"
24
+ | "FAILED"
25
+ | "EXPIRED";
26
+
27
+ /**
28
+ * Follow-up links returned by the audit export API.
29
+ *
30
+ * @interface AuditExportLinks
31
+ */
32
+ export interface AuditExportLinks {
33
+ /** URL for retrieving the export status. */
34
+ status?: string;
35
+
36
+ /** URL for downloading a completed export. */
37
+ download?: string;
38
+ }
39
+
40
+ /**
41
+ * Response returned when an audit export is accepted.
42
+ *
43
+ * @interface AuditExportResponse
44
+ */
45
+ export interface AuditExportResponse {
46
+ /** Unique identifier used to retrieve the export status and download. */
47
+ requestId: string;
48
+
49
+ /** Current processing state. A newly accepted export is QUEUED. */
50
+ status: AuditExportStatus;
51
+
52
+ /** Human-readable result message. */
53
+ message?: string;
54
+
55
+ /** ISO-8601 timestamp for when the export was submitted. */
56
+ submittedAt?: string;
57
+
58
+ /** Links for retrieving the export status and download. */
59
+ links?: AuditExportLinks;
60
+ }
61
+
62
+ /**
63
+ * Response returned when checking an audit export's status.
64
+ *
65
+ * @interface AuditExportStatusResponse
66
+ */
67
+ export interface AuditExportStatusResponse {
68
+ /** Unique identifier returned when the export was triggered. */
69
+ requestId: string;
70
+
71
+ /** Current processing state. */
72
+ status: AuditExportStatus;
73
+
74
+ /** ISO-8601 timestamp for when the export was submitted. */
75
+ submittedAt?: string;
76
+
77
+ /** ISO-8601 timestamp for when processing completed. */
78
+ completedAt?: string;
79
+
80
+ /** ISO-8601 timestamp after which the completed export is unavailable. */
81
+ expiresAt?: string;
82
+
83
+ /** Download link when the export is completed. */
84
+ links?: Pick<AuditExportLinks, "download">;
85
+
86
+ /** Human-readable failure or expiry message. */
87
+ message?: string;
88
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Response interface for audit log configuration.
3
+ * Contains settings for logging requests and responses.
4
+ *
5
+ * @interface AuditLogResponse
6
+ */
7
+ export interface AuditLogResponse {
8
+
9
+ /**
10
+ * Whether to log API requests.
11
+ * When true, all incoming requests will be logged.
12
+ */
13
+ logRequest: boolean;
14
+
15
+ /**
16
+ * Whether to log API responses.
17
+ * When true, all outgoing responses will be logged.
18
+ */
19
+ logResponse: boolean;
20
+
21
+ /**
22
+ * Message providing additional context about the response.
23
+ */
24
+ message: string;
25
+ }
26
+
27
+ /**
28
+ * Request interface for updating audit log configuration.
29
+ * Used to configure which parts of API interactions should be logged.
30
+ *
31
+ * @interface AuditLogRequest
32
+ */
33
+ export interface AuditLogRequest {
34
+
35
+ /**
36
+ * Whether to log API requests.
37
+ * When true, all incoming requests will be logged.
38
+ */
39
+ logRequest: boolean;
40
+
41
+ /**
42
+ * Whether to log API responses.
43
+ * When true, all outgoing responses will be logged.
44
+ */
45
+ logResponse: boolean;
46
+
47
+ }
@@ -15,4 +15,7 @@ export interface ActivityRequest {
15
15
  activityDescription: string;
16
16
 
17
17
  confidence: number;
18
+
19
+ /** Distinct GHG Protocol scopes associated with the activity type. */
20
+ scope?: string[];
18
21
  }
package/src/request.ts CHANGED
@@ -36,6 +36,7 @@ export async function makeApiRequest<T>(config: RequestConfig): Promise<T> {
36
36
  url: config.url,
37
37
  data: config.data,
38
38
  params: config.params,
39
+ responseType: config.responseType,
39
40
  headers: {
40
41
  ...client.getAuthHeader(),
41
42
  ...config.headers,
@@ -7,10 +7,12 @@ import * as GenericCalculation from "../src/api/Calculation";
7
7
  import * as TransportationDistributionApi from "../src/api/TransportationAndDistribution";
8
8
  import * as economicActivityApi from "../src/api/EconomicActivity";
9
9
  import * as realEstateApi from "../src/api/RealEstate";
10
+ import * as physicalActivityApi from "../src/api/PhysicalActivity";
10
11
  import * as UsageApi from "../src/api/Usage";
11
12
  import * as Factors from "../src/api/Factor";
12
13
  import * as FactorSets from "../src/api/FactorSets";
13
14
  import * as VectorTypeSearch from "../src/api/TypeRecommender";
15
+ import * as AuditLogApi from "../src/api/AuditLog";
14
16
 
15
17
  import {
16
18
  LOCATION_API_PATH,
@@ -25,7 +27,9 @@ import {
25
27
  USAGE_API,
26
28
  ECONOMIC_ACTIVITY_API_PATH,
27
29
  REAL_ESTATE_API_PATH,
30
+ PHYSICAL_ACTIVITY_API_PATH,
28
31
  TYPE_RECOMMENDER_API_PATH,
32
+ AUDIT_LOG_API_PATH,
29
33
  } from "../src/Constants";
30
34
  import locationPayload from "./mocks/LocationRequest";
31
35
  import commonpayload from "./mocks/CommonRequest";
@@ -33,6 +37,10 @@ import { Client } from "../src/Client";
33
37
  import GenericCalculationPayload from "./mocks/GenericCalculationRequest";
34
38
  import FactorPayload from "./mocks/FactorRequest";
35
39
  import SearchPayload from "./mocks/SearchRequest";
40
+ import physicalActivityPayload from "./mocks/PhysicalActivityRequest";
41
+ import physicalActivityEVICPayload from "./mocks/PhysicalActivityEVICRequest";
42
+ import economicActivityAttributionPayload from "./mocks/EconomicActivityAttributionRequest";
43
+ import attributionPayload from "./mocks/AttributionRequest";
36
44
 
37
45
  type ApiTestCase = {
38
46
  name: string;
@@ -41,7 +49,7 @@ type ApiTestCase = {
41
49
  payload?: any;
42
50
  pathParams?: string | string[];
43
51
  queryParams?: Record<string, string> | Record<string, boolean>;
44
- method: "GET" | "POST";
52
+ method: "GET" | "POST" | "PUT";
45
53
  };
46
54
 
47
55
  const mockResp = "mock-success-response";
@@ -103,6 +111,13 @@ const testCases: ApiTestCase[] = [
103
111
  payload: commonpayload,
104
112
  method: "POST",
105
113
  },
114
+ {
115
+ name: "Economic activity API with revenue attribution",
116
+ func: economicActivityApi.calculate,
117
+ path: ECONOMIC_ACTIVITY_API_PATH,
118
+ payload: economicActivityAttributionPayload,
119
+ method: "POST",
120
+ },
106
121
  {
107
122
  name: "Real estate API",
108
123
  func: realEstateApi.calculate,
@@ -110,6 +125,34 @@ const testCases: ApiTestCase[] = [
110
125
  payload: commonpayload,
111
126
  method: "POST",
112
127
  },
128
+ {
129
+ name: "Real estate API with attribution",
130
+ func: realEstateApi.calculate,
131
+ path: REAL_ESTATE_API_PATH,
132
+ payload: attributionPayload,
133
+ method: "POST",
134
+ },
135
+ {
136
+ name: "Physical activity API",
137
+ func: physicalActivityApi.calculate,
138
+ path: PHYSICAL_ACTIVITY_API_PATH,
139
+ payload: commonpayload,
140
+ method: "POST",
141
+ },
142
+ {
143
+ name: "Physical activity API with equity/debt attribution",
144
+ func: physicalActivityApi.calculate,
145
+ path: PHYSICAL_ACTIVITY_API_PATH,
146
+ payload: physicalActivityPayload,
147
+ method: "POST",
148
+ },
149
+ {
150
+ name: "Physical activity API with EVIC attribution",
151
+ func: physicalActivityApi.calculate,
152
+ path: PHYSICAL_ACTIVITY_API_PATH,
153
+ payload: physicalActivityEVICPayload,
154
+ method: "POST",
155
+ },
113
156
  {
114
157
  name: "FactorSet API",
115
158
  func: FactorSets.get,
@@ -150,6 +193,19 @@ const testCases: ApiTestCase[] = [
150
193
  path: TYPE_RECOMMENDER_API_PATH,
151
194
  payload: SearchPayload,
152
195
  method: "POST",
196
+ },
197
+ {
198
+ name: "AuditLog API - getAuditLogConfig",
199
+ func: AuditLogApi.getAuditConfig,
200
+ path: AUDIT_LOG_API_PATH,
201
+ method: "GET",
202
+ },
203
+ {
204
+ name: "AuditLog API - updateAuditLogConfig",
205
+ func: AuditLogApi.updateAuditConfig,
206
+ path: AUDIT_LOG_API_PATH,
207
+ payload: { logRequest: true, logResponse: false },
208
+ method: "PUT",
153
209
  }
154
210
  ];
155
211
 
@@ -186,7 +242,7 @@ describe("API Test calculate functions", () => {
186
242
  ({ func, path, payload, pathParams, queryParams, method }) => {
187
243
  it("Should call makeApiRequest with API url", async () => {
188
244
  let result;
189
- if (method === "POST") {
245
+ if (method === "POST" || method === "PUT") {
190
246
  result = await func(payload);
191
247
  } else {
192
248
  // For GET requests with queryParams
@@ -222,7 +278,7 @@ describe("API Test calculate functions", () => {
222
278
  method,
223
279
  url: expectedUrl,
224
280
  };
225
- if (method === "POST") expectedRequest.data = payload;
281
+ if (method === "POST" || method === "PUT") expectedRequest.data = payload;
226
282
  if (method === "GET" && queryParams) expectedRequest.params = queryParams;
227
283
  expect(spy).toHaveBeenCalledWith(expectedRequest);
228
284
  expect(result).toBe(mockResp);
@@ -0,0 +1,68 @@
1
+ import { Buffer } from "buffer";
2
+ import { Client } from "../src/Client";
3
+ import { download, getStatus, trigger } from "../src/api/AuditExport";
4
+ import {
5
+ AUDIT_EXPORT_API_PATH,
6
+ AUDIT_EXPORT_DOWNLOAD_API_PATH,
7
+ AUDIT_EXPORT_STATUS_API_PATH,
8
+ GET,
9
+ POST,
10
+ } from "../src/Constants";
11
+ import * as request from "../src/request";
12
+
13
+ jest.mock("../src/request");
14
+ jest.mock("../src/Client");
15
+
16
+ describe("AuditExport", () => {
17
+ const domain = "https://dev.api.ibm.com/ghgemissions/test";
18
+ const requestId = "tenant-uuid/20250101-20250331-location";
19
+
20
+ beforeEach(() => {
21
+ jest.clearAllMocks();
22
+ (Client.getInstance as jest.Mock).mockReturnValue({
23
+ getDomain: jest.fn().mockReturnValue(domain),
24
+ });
25
+ });
26
+
27
+ it("triggers an audit export", async () => {
28
+ const payload = {
29
+ fromDate: "2025-01-01",
30
+ toDate: "2025-03-31",
31
+ apiName: "location",
32
+ };
33
+ const response = { requestId, status: "QUEUED" };
34
+ (request.makeApiRequest as jest.Mock).mockResolvedValue(response);
35
+
36
+ await expect(trigger(payload)).resolves.toEqual(response);
37
+ expect(request.makeApiRequest).toHaveBeenCalledWith({
38
+ method: POST,
39
+ url: `${domain}${AUDIT_EXPORT_API_PATH}`,
40
+ data: payload,
41
+ });
42
+ });
43
+
44
+ it("gets an audit export status", async () => {
45
+ const response = { requestId, status: "COMPLETED" };
46
+ (request.makeApiRequest as jest.Mock).mockResolvedValue(response);
47
+
48
+ await expect(getStatus(requestId)).resolves.toEqual(response);
49
+ expect(request.makeApiRequest).toHaveBeenCalledWith({
50
+ method: GET,
51
+ url: `${domain}${AUDIT_EXPORT_STATUS_API_PATH}`,
52
+ params: { requestId },
53
+ });
54
+ });
55
+
56
+ it("downloads a completed audit export as binary data", async () => {
57
+ const response = Buffer.from("zip-content");
58
+ (request.makeApiRequest as jest.Mock).mockResolvedValue(response);
59
+
60
+ await expect(download(requestId)).resolves.toBe(response);
61
+ expect(request.makeApiRequest).toHaveBeenCalledWith({
62
+ method: GET,
63
+ url: `${domain}${AUDIT_EXPORT_DOWNLOAD_API_PATH}`,
64
+ params: { requestId },
65
+ responseType: "arraybuffer",
66
+ });
67
+ });
68
+ });