emissions-api-sdk 1.0.2 → 1.0.4
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 +9 -0
- package/dist/Constants.js +2 -1
- package/dist/api/Usage.js +26 -0
- package/dist/coverage/clover.xml +44 -33
- package/dist/coverage/coverage-final.json +4 -3
- package/dist/coverage/lcov-report/index.html +19 -19
- package/dist/coverage/lcov-report/src/Client.ts.html +23 -23
- package/dist/coverage/lcov-report/src/Constants.ts.html +10 -4
- package/dist/coverage/lcov-report/src/api/Calculation.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/Factor.ts.html +1 -1
- 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/Mobile.ts.html +1 -1
- 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/Usage.ts.html +160 -0
- package/dist/coverage/lcov-report/src/api/index.html +21 -6
- package/dist/coverage/lcov-report/src/index.html +7 -7
- package/dist/coverage/lcov-report/src/request.ts.html +1 -1
- package/dist/coverage/lcov-report/src/utils.ts.html +5 -5
- package/dist/coverage/lcov-report/test/index.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/CommonRequest.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/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 +75 -55
- package/dist/index.js +2 -1
- package/dist/interfaces/response/UsageResponse.js +5 -0
- package/dist/types/Constants.d.ts +1 -0
- package/dist/types/api/Usage.d.ts +13 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/interfaces/response/EmissionResponseWithDetails.d.ts +4 -0
- package/dist/types/interfaces/response/FactorResponse.d.ts +4 -0
- package/dist/types/interfaces/response/UnitResponse.d.ts +11 -2
- package/dist/types/interfaces/response/UsageResponse.d.ts +17 -0
- package/docs/_sources/reference.rst.txt +6 -0
- package/docs/_static/basic.css +0 -8
- package/docs/_static/pygments.css +164 -146
- package/docs/_static/searchtools.js +8 -5
- package/docs/_static/styles/furo.css +1 -1
- package/docs/_static/styles/furo.css.map +1 -1
- package/docs/authentication.html +19 -28
- package/docs/client.html +19 -28
- package/docs/genindex.html +23 -28
- package/docs/getting_started.html +19 -28
- package/docs/index.html +20 -28
- package/docs/objects.inv +0 -0
- package/docs/reference.html +48 -28
- package/docs/sdk.html +19 -28
- package/docs/search.html +19 -28
- package/docs/searchindex.js +1 -1
- package/docs/troubleshooting.html +19 -28
- package/package.json +1 -1
- package/sphinx-build/requirements.txt +1 -2
- package/sphinx-build/source/reference.rst +6 -0
- package/src/Constants.ts +2 -0
- package/src/api/Usage.ts +26 -0
- package/src/index.ts +3 -1
- package/src/interfaces/response/EmissionResponseWithDetails.ts +6 -0
- package/src/interfaces/response/FactorResponse.ts +6 -0
- package/src/interfaces/response/UnitResponse.ts +12 -2
- package/src/interfaces/response/UsageResponse.ts +23 -0
- package/test/apiTest.test.ts +34 -3
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
<!doctype html>
|
|
2
2
|
<html class="no-js" lang="en" data-content_root="./">
|
|
3
|
-
<head><meta charset="utf-8"
|
|
4
|
-
<meta name="viewport" content="width=device-width,initial-scale=1"
|
|
3
|
+
<head><meta charset="utf-8">
|
|
4
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
5
5
|
<meta name="color-scheme" content="light dark"><meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
-
<link rel="index" title="Index" href="genindex.html"
|
|
6
|
+
<link rel="index" title="Index" href="genindex.html"><link rel="search" title="Search" href="search.html"><link rel="prev" title="Reference" href="reference.html">
|
|
7
7
|
|
|
8
|
-
<!-- Generated with Sphinx 8.
|
|
8
|
+
<!-- Generated with Sphinx 8.2.3 and Furo 2025.09.25 -->
|
|
9
9
|
<title>Troubleshooting Guide - IBM Envizi - Emissions API Node.js SDK documentation</title>
|
|
10
10
|
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=d111a655" />
|
|
11
|
-
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?v=
|
|
11
|
+
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?v=580074bf" />
|
|
12
12
|
<link rel="stylesheet" type="text/css" href="_static/sphinx_js.css" />
|
|
13
13
|
<link rel="stylesheet" type="text/css" href="_static/styles/furo-extensions.css?v=8dab3a3b" />
|
|
14
14
|
<link rel="stylesheet" type="text/css" href="_static/custom.css?v=8d04aa46" />
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
}
|
|
25
25
|
@media not print {
|
|
26
26
|
body[data-theme="dark"] {
|
|
27
|
-
--color-code-background: #
|
|
28
|
-
--color-code-foreground: #
|
|
27
|
+
--color-code-background: #202020;
|
|
28
|
+
--color-code-foreground: #d0d0d0;
|
|
29
29
|
|
|
30
30
|
}
|
|
31
31
|
@media (prefers-color-scheme: dark) {
|
|
32
32
|
body:not([data-theme="light"]) {
|
|
33
|
-
--color-code-background: #
|
|
34
|
-
--color-code-foreground: #
|
|
33
|
+
--color-code-background: #202020;
|
|
34
|
+
--color-code-foreground: #d0d0d0;
|
|
35
35
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -146,14 +146,10 @@
|
|
|
146
146
|
</symbol>
|
|
147
147
|
</svg>
|
|
148
148
|
|
|
149
|
-
<input type="checkbox" class="sidebar-toggle" name="__navigation" id="__navigation">
|
|
150
|
-
<input type="checkbox" class="sidebar-toggle" name="__toc" id="__toc">
|
|
151
|
-
<label class="overlay sidebar-overlay" for="__navigation">
|
|
152
|
-
|
|
153
|
-
</label>
|
|
154
|
-
<label class="overlay toc-overlay" for="__toc">
|
|
155
|
-
<div class="visually-hidden">Hide table of contents sidebar</div>
|
|
156
|
-
</label>
|
|
149
|
+
<input type="checkbox" class="sidebar-toggle" name="__navigation" id="__navigation" aria-label="Toggle site navigation sidebar">
|
|
150
|
+
<input type="checkbox" class="sidebar-toggle" name="__toc" id="__toc" aria-label="Toggle table of contents sidebar">
|
|
151
|
+
<label class="overlay sidebar-overlay" for="__navigation"></label>
|
|
152
|
+
<label class="overlay toc-overlay" for="__toc"></label>
|
|
157
153
|
|
|
158
154
|
<a class="skip-to-content muted-link" href="#furo-main-content">Skip to content</a>
|
|
159
155
|
|
|
@@ -163,8 +159,7 @@
|
|
|
163
159
|
<header class="mobile-header">
|
|
164
160
|
<div class="header-left">
|
|
165
161
|
<label class="nav-overlay-icon" for="__navigation">
|
|
166
|
-
<
|
|
167
|
-
<i class="icon"><svg><use href="#svg-menu"></use></svg></i>
|
|
162
|
+
<span class="icon"><svg><use href="#svg-menu"></use></svg></span>
|
|
168
163
|
</label>
|
|
169
164
|
</div>
|
|
170
165
|
<div class="header-center">
|
|
@@ -172,8 +167,7 @@
|
|
|
172
167
|
</div>
|
|
173
168
|
<div class="header-right">
|
|
174
169
|
<div class="theme-toggle-container theme-toggle-header">
|
|
175
|
-
<button class="theme-toggle">
|
|
176
|
-
<div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
|
|
170
|
+
<button class="theme-toggle" aria-label="Toggle Light / Dark / Auto color theme">
|
|
177
171
|
<svg class="theme-icon-when-auto-light"><use href="#svg-sun-with-moon"></use></svg>
|
|
178
172
|
<svg class="theme-icon-when-auto-dark"><use href="#svg-moon-with-sun"></use></svg>
|
|
179
173
|
<svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
|
|
@@ -181,8 +175,7 @@
|
|
|
181
175
|
</button>
|
|
182
176
|
</div>
|
|
183
177
|
<label class="toc-overlay-icon toc-header-icon" for="__toc">
|
|
184
|
-
<
|
|
185
|
-
<i class="icon"><svg><use href="#svg-toc"></use></svg></i>
|
|
178
|
+
<span class="icon"><svg><use href="#svg-toc"></use></svg></span>
|
|
186
179
|
</label>
|
|
187
180
|
</div>
|
|
188
181
|
</header>
|
|
@@ -202,7 +195,7 @@
|
|
|
202
195
|
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
|
|
203
196
|
<ul class="current">
|
|
204
197
|
<li class="toctree-l1"><a class="reference internal" href="getting_started.html">Getting Started</a></li>
|
|
205
|
-
<li class="toctree-l1 has-children"><a class="reference internal" href="sdk.html">SDK</a><input class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" role="switch" type="checkbox"/><label for="toctree-checkbox-1"><
|
|
198
|
+
<li class="toctree-l1 has-children"><a class="reference internal" href="sdk.html">SDK</a><input aria-label="Toggle navigation of SDK" class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" role="switch" type="checkbox"/><label for="toctree-checkbox-1"><span class="icon"><svg><use href="#svg-arrow-right"></use></svg></span></label><ul>
|
|
206
199
|
<li class="toctree-l2"><a class="reference internal" href="client.html">Client</a></li>
|
|
207
200
|
<li class="toctree-l2"><a class="reference internal" href="authentication.html">Authentication</a></li>
|
|
208
201
|
</ul>
|
|
@@ -235,8 +228,7 @@
|
|
|
235
228
|
</a>
|
|
236
229
|
</div>
|
|
237
230
|
<div class="theme-toggle-container theme-toggle-content">
|
|
238
|
-
<button class="theme-toggle">
|
|
239
|
-
<div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
|
|
231
|
+
<button class="theme-toggle" aria-label="Toggle Light / Dark / Auto color theme">
|
|
240
232
|
<svg class="theme-icon-when-auto-light"><use href="#svg-sun-with-moon"></use></svg>
|
|
241
233
|
<svg class="theme-icon-when-auto-dark"><use href="#svg-moon-with-sun"></use></svg>
|
|
242
234
|
<svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
|
|
@@ -244,8 +236,7 @@
|
|
|
244
236
|
</button>
|
|
245
237
|
</div>
|
|
246
238
|
<label class="toc-overlay-icon toc-content-icon" for="__toc">
|
|
247
|
-
<
|
|
248
|
-
<i class="icon"><svg><use href="#svg-toc"></use></svg></i>
|
|
239
|
+
<span class="icon"><svg><use href="#svg-toc"></use></svg></span>
|
|
249
240
|
</label>
|
|
250
241
|
</div>
|
|
251
242
|
<article role="main" id="furo-main-content">
|
package/package.json
CHANGED
package/src/Constants.ts
CHANGED
|
@@ -35,6 +35,8 @@ export const GENERAL_API_UNITS = "/v3/carbon/calculation/units";
|
|
|
35
35
|
export const FACTOR_API_UNITS = "/v3/carbon/factor/units";
|
|
36
36
|
export const TRANSPORTATION_AND_DISTRIBUTION_API_UNITS = "/v3/carbon/transportation-and-distribution/units";
|
|
37
37
|
|
|
38
|
+
export const USAGE_API = "/v3/carbon/usage";
|
|
39
|
+
|
|
38
40
|
export const GET = "GET";
|
|
39
41
|
export const POST = "POST";
|
|
40
42
|
export const CLIENT_SOURCE_HEADER = "X-Client-Source";
|
package/src/api/Usage.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Client } from "../Client";
|
|
2
|
+
import { GET, USAGE_API } from "../Constants";
|
|
3
|
+
import { UsageResponse } from "../interfaces/response/UsageResponse";
|
|
4
|
+
import { makeApiRequest } from "../request";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Retrieves current billing period or historical usage data for the user by making a GET request to the API endpoint.
|
|
8
|
+
*
|
|
9
|
+
* @export
|
|
10
|
+
* @param {boolean} history - Flag to retrieve current billing or historical usage data.
|
|
11
|
+
* @return {Promise<UsageResponse>} A promise that resolves to a UsageResponse containing the organization's usage data
|
|
12
|
+
* @throws {Error} May throw an error if the API request fails
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const usage = await getUsage();
|
|
16
|
+
*/
|
|
17
|
+
export async function getUsage(history : boolean = false): Promise<UsageResponse> {
|
|
18
|
+
const client = Client.getInstance();
|
|
19
|
+
const url = client.getDomain() + USAGE_API;
|
|
20
|
+
|
|
21
|
+
return makeApiRequest<UsageResponse>({
|
|
22
|
+
method: GET,
|
|
23
|
+
url,
|
|
24
|
+
params : { history }
|
|
25
|
+
});
|
|
26
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * as Mobile from './api/Mobile';
|
|
|
5
5
|
export * as Stationary from './api/Stationary';
|
|
6
6
|
export * as Calculation from './api/Calculation';
|
|
7
7
|
export * as TransportationAndDistribution from './api/TransportationAndDistribution';
|
|
8
|
+
export * as Usage from './api/Usage'
|
|
8
9
|
export * as Factor from './api/Factor';
|
|
9
10
|
export * as FactorSets from './api/FactorSets'
|
|
10
11
|
export { ClientConfig } from './interfaces/Config';
|
|
@@ -39,4 +40,5 @@ export {
|
|
|
39
40
|
SearchLink
|
|
40
41
|
} from './interfaces/response/SearchResponse';
|
|
41
42
|
export { TypeResponse } from './interfaces/response/TypeResponse';
|
|
42
|
-
export { UnitResponse } from './interfaces/response/UnitResponse';
|
|
43
|
+
export { UnitResponse } from './interfaces/response/UnitResponse';
|
|
44
|
+
export { UsageResponse } from './interfaces/response/UsageResponse';
|
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for unit object
|
|
3
|
+
*/
|
|
4
|
+
export interface Unit {
|
|
5
|
+
/** Unit symbol */
|
|
6
|
+
unit: string;
|
|
7
|
+
/** Unit name */
|
|
8
|
+
unitName: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
1
11
|
/**
|
|
2
12
|
* Interface for /units metadata API
|
|
3
13
|
*/
|
|
4
14
|
export interface UnitResponse {
|
|
5
|
-
/** Array of
|
|
6
|
-
units:
|
|
15
|
+
/** Array of Unit objects */
|
|
16
|
+
units: Unit[];
|
|
7
17
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface representing the GHG Metrics Usage Response
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface UsageResponse {
|
|
6
|
+
/** Organization ID for the API request */
|
|
7
|
+
orgId ?: string;
|
|
8
|
+
|
|
9
|
+
/** Array of entitlement belonging to the Org */
|
|
10
|
+
entitlement ?: Entitlement[]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export interface Entitlement {
|
|
15
|
+
/** Organization's billing start date*/
|
|
16
|
+
startDate ?: string;
|
|
17
|
+
|
|
18
|
+
/** Organization's billing end date */
|
|
19
|
+
endDate ?: string;
|
|
20
|
+
|
|
21
|
+
/** Total api calls made by the Organization in the billing cycle */
|
|
22
|
+
totalApiCalls ?: number;
|
|
23
|
+
}
|
package/test/apiTest.test.ts
CHANGED
|
@@ -5,6 +5,7 @@ import * as mobileApi from "../src/api/Mobile";
|
|
|
5
5
|
import * as stationaryApi from "../src/api/Stationary";
|
|
6
6
|
import * as GenericCalculation from "../src/api/Calculation";
|
|
7
7
|
import * as TransportationDistributionApi from "../src/api/TransportationAndDistribution";
|
|
8
|
+
import * as UsageApi from "../src/api/Usage";
|
|
8
9
|
import * as Factors from "../src/api/Factor";
|
|
9
10
|
import * as FactorSets from "../src/api/FactorSets";
|
|
10
11
|
|
|
@@ -40,6 +41,7 @@ import {
|
|
|
40
41
|
GENERAL_API_UNITS,
|
|
41
42
|
FACTOR_API_UNITS,
|
|
42
43
|
TRANSPORTATION_AND_DISTRIBUTION_API_UNITS,
|
|
44
|
+
USAGE_API
|
|
43
45
|
} from "../src/Constants";
|
|
44
46
|
import locationPayload from "./mocks/LocationRequest";
|
|
45
47
|
import commonpayload from "./mocks/CommonRequest";
|
|
@@ -54,7 +56,7 @@ type ApiTestCase = {
|
|
|
54
56
|
path: string;
|
|
55
57
|
payload?: any;
|
|
56
58
|
pathParams?: string | string[];
|
|
57
|
-
queryParams?: Record<string, string>;
|
|
59
|
+
queryParams?: Record<string, string> | Record<string, boolean>;
|
|
58
60
|
method: "GET" | "POST";
|
|
59
61
|
};
|
|
60
62
|
|
|
@@ -262,6 +264,27 @@ const testCases: ApiTestCase[] = [
|
|
|
262
264
|
queryParams: { type: "Business Travel - Cars:Diesel - Small" },
|
|
263
265
|
method: "GET",
|
|
264
266
|
},
|
|
267
|
+
{
|
|
268
|
+
name: "Usage API - getUsage with history false",
|
|
269
|
+
func: UsageApi.getUsage,
|
|
270
|
+
path: USAGE_API,
|
|
271
|
+
queryParams: { history: false },
|
|
272
|
+
method: "GET",
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
name: "Usage API - getUsage with history true",
|
|
276
|
+
func: UsageApi.getUsage,
|
|
277
|
+
path: USAGE_API,
|
|
278
|
+
queryParams: { history: true },
|
|
279
|
+
method: "GET",
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
name: "Usage API - getUsage default",
|
|
283
|
+
func: UsageApi.getUsage,
|
|
284
|
+
path: USAGE_API,
|
|
285
|
+
queryParams: { history: false },
|
|
286
|
+
method: "GET",
|
|
287
|
+
}
|
|
265
288
|
];
|
|
266
289
|
|
|
267
290
|
describe("API Test calculate functions", () => {
|
|
@@ -300,9 +323,17 @@ describe("API Test calculate functions", () => {
|
|
|
300
323
|
if (method === "POST") {
|
|
301
324
|
result = await func(payload);
|
|
302
325
|
} else {
|
|
303
|
-
// For GET requests with queryParams
|
|
326
|
+
// For GET requests with queryParams
|
|
304
327
|
if (queryParams) {
|
|
305
|
-
|
|
328
|
+
// Check if it's a Usage API call with history parameter
|
|
329
|
+
if (queryParams.hasOwnProperty('history')) {
|
|
330
|
+
result = await func(queryParams.history);
|
|
331
|
+
} else if (queryParams.type) {
|
|
332
|
+
// For other APIs that use type parameter
|
|
333
|
+
result = await func(queryParams.type);
|
|
334
|
+
} else {
|
|
335
|
+
result = await func();
|
|
336
|
+
}
|
|
306
337
|
} else if (pathParams !== undefined) {
|
|
307
338
|
result = await func(pathParams);
|
|
308
339
|
} else {
|