emissions-api-sdk 1.0.13 → 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 +23 -0
- package/dist/Constants.js +4 -1
- package/dist/api/AuditExport.js +73 -0
- package/dist/api/EconomicActivity.js +45 -0
- package/dist/api/Factor.js +1 -4
- package/dist/api/RealEstate.js +2 -1
- package/dist/coverage/clover.xml +75 -54
- package/dist/coverage/coverage-final.json +8 -7
- package/dist/coverage/lcov-report/index.html +15 -15
- package/dist/coverage/lcov-report/src/Client.ts.html +6 -6
- package/dist/coverage/lcov-report/src/Constants.ts.html +39 -30
- package/dist/coverage/lcov-report/src/api/AuditExport.ts.html +355 -0
- package/dist/coverage/lcov-report/src/api/AuditLog.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/Calculation.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/EconomicActivity.ts.html +137 -2
- package/dist/coverage/lcov-report/src/api/Factor.ts.html +6 -12
- 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 +1 -1
- package/dist/coverage/lcov-report/src/api/RealEstate.ts.html +6 -3
- 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 +1 -1
- package/dist/coverage/lcov-report/src/api/Usage.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/index.html +19 -4
- 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 +2 -2
- package/dist/coverage/lcov-report/test/index.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/AttributionRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/CommonRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/EconomicActivityAttributionRequest.ts.html +1 -1
- 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 +1 -1
- package/dist/coverage/lcov-report/test/mocks/PhysicalActivityRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/SearchRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/index.html +1 -1
- package/dist/coverage/lcov-report/test/testUtils.ts.html +1 -1
- package/dist/coverage/lcov.info +86 -53
- package/dist/index.js +2 -1
- package/dist/interfaces/response/AuditExportResponse.js +2 -0
- package/dist/request.js +1 -0
- package/dist/types/Constants.d.ts +3 -0
- package/dist/types/api/AuditExport.d.ts +42 -0
- package/dist/types/api/EconomicActivity.d.ts +45 -0
- package/dist/types/api/Factor.d.ts +1 -4
- package/dist/types/api/RealEstate.d.ts +2 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/interfaces/Config.d.ts +5 -1
- package/dist/types/interfaces/response/AuditExportResponse.d.ts +66 -0
- package/dist/types/interfaces/response/TypeRecommenderResponse.d.ts +1 -0
- package/docs/_sources/getting_started.rst.txt +226 -2
- package/docs/_sources/index.rst.txt +2 -0
- package/docs/_sources/reference.rst.txt +22 -0
- package/docs/genindex.html +27 -3
- package/docs/getting_started.html +226 -2
- package/docs/index.html +4 -0
- package/docs/reference.html +267 -4
- package/docs/searchindex.js +1 -1
- package/package.json +6 -5
- package/sphinx-build/source/getting_started.rst +226 -2
- package/sphinx-build/source/index.rst +2 -0
- package/sphinx-build/source/reference.rst +22 -0
- package/src/Constants.ts +3 -0
- package/src/api/AuditExport.ts +90 -0
- package/src/api/EconomicActivity.ts +45 -0
- package/src/api/Factor.ts +2 -5
- package/src/api/RealEstate.ts +2 -1
- package/src/index.ts +9 -1
- package/src/interfaces/Config.ts +6 -1
- package/src/interfaces/response/AuditExportResponse.ts +88 -0
- package/src/interfaces/response/TypeRecommenderResponse.ts +1 -0
- package/src/request.ts +1 -0
- package/test/auditExport.test.ts +68 -0
- package/docs/_static/base-stemmer.js +0 -476
- package/docs/_static/english-stemmer.js +0 -1066
|
@@ -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
|
+
}
|
|
@@ -53,6 +53,51 @@ import { makeApiRequest } from "../request";
|
|
|
53
53
|
"includeDetails": true
|
|
54
54
|
};
|
|
55
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);
|
|
56
101
|
*/
|
|
57
102
|
|
|
58
103
|
export async function calculate(
|
package/src/api/Factor.ts
CHANGED
|
@@ -81,11 +81,8 @@ export async function retrieveFactor(
|
|
|
81
81
|
* @example
|
|
82
82
|
* // Search without cross-encoder reranking
|
|
83
83
|
* const searchWithoutReranker = {
|
|
84
|
-
"time":{
|
|
85
|
-
"date": "2020-06-10"
|
|
86
|
-
},
|
|
87
84
|
"activity": {
|
|
88
|
-
"search"
|
|
85
|
+
"search": "travel"
|
|
89
86
|
},
|
|
90
87
|
"location": {
|
|
91
88
|
"country": "USA"
|
|
@@ -155,4 +152,4 @@ export async function search(
|
|
|
155
152
|
url,
|
|
156
153
|
data: payload,
|
|
157
154
|
});
|
|
158
|
-
}
|
|
155
|
+
}
|
package/src/api/RealEstate.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ export * as PhysicalActivity from './api/PhysicalActivity';
|
|
|
14
14
|
export * as Metadata from './api/Metadata';
|
|
15
15
|
export * as TypeRecommender from './api/TypeRecommender';
|
|
16
16
|
export * as AuditLog from './api/AuditLog';
|
|
17
|
+
export * as AuditExport from './api/AuditExport';
|
|
17
18
|
export { ClientConfig } from './interfaces/Config';
|
|
18
19
|
|
|
19
20
|
// Common interfaces
|
|
@@ -43,4 +44,11 @@ export { TypeResponse } from './interfaces/response/TypeResponse';
|
|
|
43
44
|
export { UnitResponse } from './interfaces/response/UnitResponse';
|
|
44
45
|
export { UsageResponse } from './interfaces/response/UsageResponse';
|
|
45
46
|
export { TypeRecommenderResponse, ActivityRequest } from './interfaces/response/TypeRecommenderResponse';
|
|
46
|
-
export { AuditLogResponse, AuditLogRequest } from './interfaces/response/AuditLogResponse';
|
|
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';
|
package/src/interfaces/Config.ts
CHANGED
|
@@ -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
|
/**
|
|
@@ -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
|
+
}
|
package/src/request.ts
CHANGED
|
@@ -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
|
+
});
|