emissions-api-sdk 1.0.0
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/CODE_OF_CONDUCT.md +76 -0
- package/CONTRIBUTING.md +68 -0
- package/LICENSE +201 -0
- package/MAINTAINERS.md +10 -0
- package/README.md +89 -0
- package/dist/Client.js +227 -0
- package/dist/Constants.js +19 -0
- package/dist/api/Calculation.js +41 -0
- package/dist/api/Factor.js +79 -0
- package/dist/api/FactorSets.js +24 -0
- package/dist/api/Factors.js +98 -0
- package/dist/api/Fugitive.js +40 -0
- package/dist/api/FugitiveEmission.js +40 -0
- package/dist/api/GenericCalculation.js +41 -0
- package/dist/api/Location.js +41 -0
- package/dist/api/LocationEmission.js +41 -0
- package/dist/api/Mobile.js +41 -0
- package/dist/api/MobileEmission.js +41 -0
- package/dist/api/Stationary.js +41 -0
- package/dist/api/StationaryEmission.js +41 -0
- package/dist/api/TransportationAndDistribution.js +40 -0
- package/dist/api/TransportationDistributionEmission.js +40 -0
- package/dist/coverage/clover.xml +225 -0
- package/dist/coverage/coverage-final.json +19 -0
- package/dist/coverage/lcov-report/base.css +224 -0
- package/dist/coverage/lcov-report/block-navigation.js +87 -0
- package/dist/coverage/lcov-report/favicon.png +0 -0
- package/dist/coverage/lcov-report/index.html +161 -0
- package/dist/coverage/lcov-report/prettify.css +1 -0
- package/dist/coverage/lcov-report/prettify.js +2 -0
- package/dist/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/dist/coverage/lcov-report/sorter.js +210 -0
- package/dist/coverage/lcov-report/src/Client.ts.html +838 -0
- package/dist/coverage/lcov-report/src/Constants.ts.html +130 -0
- package/dist/coverage/lcov-report/src/api/Calculation.ts.html +217 -0
- package/dist/coverage/lcov-report/src/api/Factor.ts.html +343 -0
- package/dist/coverage/lcov-report/src/api/FactorSets.ts.html +154 -0
- package/dist/coverage/lcov-report/src/api/Factors.ts.html +403 -0
- package/dist/coverage/lcov-report/src/api/Fugitive.ts.html +214 -0
- package/dist/coverage/lcov-report/src/api/FugitiveEmission.ts.html +214 -0
- package/dist/coverage/lcov-report/src/api/GenericCalculation.ts.html +217 -0
- package/dist/coverage/lcov-report/src/api/Location.ts.html +214 -0
- package/dist/coverage/lcov-report/src/api/LocationEmission.ts.html +214 -0
- package/dist/coverage/lcov-report/src/api/Mobile.ts.html +220 -0
- package/dist/coverage/lcov-report/src/api/MobileEmission.ts.html +220 -0
- package/dist/coverage/lcov-report/src/api/Stationary.ts.html +220 -0
- package/dist/coverage/lcov-report/src/api/StationaryEmission.ts.html +220 -0
- package/dist/coverage/lcov-report/src/api/TransportationAndDistribution.ts.html +211 -0
- package/dist/coverage/lcov-report/src/api/TransportationDistributionEmission.ts.html +211 -0
- package/dist/coverage/lcov-report/src/api/index.html +221 -0
- package/dist/coverage/lcov-report/src/index.html +161 -0
- package/dist/coverage/lcov-report/src/request.ts.html +235 -0
- package/dist/coverage/lcov-report/src/utils.ts.html +139 -0
- package/dist/coverage/lcov-report/test/index.html +116 -0
- package/dist/coverage/lcov-report/test/mocks/CommonRequest.ts.html +142 -0
- package/dist/coverage/lcov-report/test/mocks/FactorRequest.ts.html +133 -0
- package/dist/coverage/lcov-report/test/mocks/GenericCalculationRequest.ts.html +142 -0
- package/dist/coverage/lcov-report/test/mocks/LocationRequest.ts.html +139 -0
- package/dist/coverage/lcov-report/test/mocks/SearchRequest.ts.html +142 -0
- package/dist/coverage/lcov-report/test/mocks/index.html +176 -0
- package/dist/coverage/lcov-report/test/testUtils.ts.html +97 -0
- package/dist/coverage/lcov.info +404 -0
- package/dist/index.js +46 -0
- package/dist/interfaces/Api.js +2 -0
- package/dist/interfaces/Config.js +2 -0
- package/dist/interfaces/common.js +2 -0
- package/dist/request.js +51 -0
- package/dist/types/Client.d.ts +146 -0
- package/dist/types/Constants.d.ts +16 -0
- package/dist/types/api/Calculation.d.ts +28 -0
- package/dist/types/api/Factor.d.ts +57 -0
- package/dist/types/api/FactorSets.d.ts +11 -0
- package/dist/types/api/Factors.d.ts +68 -0
- package/dist/types/api/Fugitive.d.ts +27 -0
- package/dist/types/api/FugitiveEmission.d.ts +27 -0
- package/dist/types/api/GenericCalculation.d.ts +28 -0
- package/dist/types/api/Location.d.ts +28 -0
- package/dist/types/api/LocationEmission.d.ts +28 -0
- package/dist/types/api/Mobile.d.ts +28 -0
- package/dist/types/api/MobileEmission.d.ts +28 -0
- package/dist/types/api/Stationary.d.ts +28 -0
- package/dist/types/api/StationaryEmission.d.ts +28 -0
- package/dist/types/api/TransportationAndDistribution.d.ts +27 -0
- package/dist/types/api/TransportationDistributionEmission.d.ts +27 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/interfaces/Api.d.ts +286 -0
- package/dist/types/interfaces/Config.d.ts +66 -0
- package/dist/types/interfaces/common.d.ts +152 -0
- package/dist/types/request.d.ts +25 -0
- package/dist/types/utils.d.ts +14 -0
- package/dist/utils.js +23 -0
- package/jest.config.js +9 -0
- package/package.json +50 -0
- package/src/Client.ts +252 -0
- package/src/Constants.ts +16 -0
- package/src/api/Calculation.ts +44 -0
- package/src/api/Factor.ts +86 -0
- package/src/api/FactorSets.ts +24 -0
- package/src/api/Fugitive.ts +43 -0
- package/src/api/Location.ts +43 -0
- package/src/api/Mobile.ts +45 -0
- package/src/api/Stationary.ts +45 -0
- package/src/api/TransportationAndDistribution.ts +42 -0
- package/src/index.ts +10 -0
- package/src/interfaces/Api.ts +300 -0
- package/src/interfaces/Config.ts +78 -0
- package/src/interfaces/common.ts +174 -0
- package/src/request.ts +50 -0
- package/src/utils.ts +19 -0
- package/test/apiTest.test.ts +168 -0
- package/test/client.test.ts +82 -0
- package/test/mocks/CommonRequest.ts +19 -0
- package/test/mocks/FactorRequest.ts +16 -0
- package/test/mocks/GenericCalculationRequest.ts +19 -0
- package/test/mocks/LocationRequest.ts +19 -0
- package/test/mocks/SearchRequest.ts +19 -0
- package/test/request.test.ts +111 -0
- package/test/testUtils.ts +5 -0
- package/test/tokenRefresh.test.ts +52 -0
- package/tsconfig.json +15 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.FactorSets = exports.Factor = exports.TransportationAndDistribution = exports.Calculation = exports.Stationary = exports.Mobile = exports.Fugitive = exports.Location = exports.Client = void 0;
|
|
37
|
+
var Client_1 = require("./Client");
|
|
38
|
+
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return Client_1.Client; } });
|
|
39
|
+
exports.Location = __importStar(require("./api/Location"));
|
|
40
|
+
exports.Fugitive = __importStar(require("./api/Fugitive"));
|
|
41
|
+
exports.Mobile = __importStar(require("./api/Mobile"));
|
|
42
|
+
exports.Stationary = __importStar(require("./api/Stationary"));
|
|
43
|
+
exports.Calculation = __importStar(require("./api/Calculation"));
|
|
44
|
+
exports.TransportationAndDistribution = __importStar(require("./api/TransportationAndDistribution"));
|
|
45
|
+
exports.Factor = __importStar(require("./api/Factor"));
|
|
46
|
+
exports.FactorSets = __importStar(require("./api/FactorSets"));
|
package/dist/request.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.makeApiRequest = makeApiRequest;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const Client_1 = require("./Client");
|
|
9
|
+
const Constants_1 = require("./Constants");
|
|
10
|
+
/**
|
|
11
|
+
* Makes an API request with standardized headers and token refresh.
|
|
12
|
+
*
|
|
13
|
+
* @export
|
|
14
|
+
* @template T The expected response data type
|
|
15
|
+
* @param {RequestConfig} config - The request configuration including method, URL, data, params, and optional headers
|
|
16
|
+
* @return {Promise<T>} A promise that resolves to the response data of type T
|
|
17
|
+
* @throws {Error} May throw an error if the API request fails or token refresh fails
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* interface UserData {
|
|
21
|
+
* id: string;
|
|
22
|
+
* name: string;
|
|
23
|
+
* email: string;
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* const userData = await makeApiRequest<UserData>({
|
|
27
|
+
* method: 'GET',
|
|
28
|
+
* url: 'https://api.example.com/users/123',
|
|
29
|
+
* headers: { 'X-Custom-Header': 'value' }
|
|
30
|
+
* });
|
|
31
|
+
* console.log(userData.name); // Typed access to the response data
|
|
32
|
+
*/
|
|
33
|
+
async function makeApiRequest(config) {
|
|
34
|
+
const client = Client_1.Client.getInstance();
|
|
35
|
+
await client.refreshToken();
|
|
36
|
+
const axiosConfig = {
|
|
37
|
+
method: config.method,
|
|
38
|
+
url: config.url,
|
|
39
|
+
data: config.data,
|
|
40
|
+
params: config.params,
|
|
41
|
+
headers: {
|
|
42
|
+
...client.getAuthHeader(),
|
|
43
|
+
...config.headers,
|
|
44
|
+
'Content-Type': 'application/json',
|
|
45
|
+
'X-IBM-Client-Id': `ghgemissions-${client.getClientId()}`,
|
|
46
|
+
[Constants_1.CLIENT_SOURCE_HEADER]: client.getClientSource()
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
const response = await axios_1.default.request(axiosConfig);
|
|
50
|
+
return response.data;
|
|
51
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { ClientConfig } from "./interfaces/Config";
|
|
2
|
+
export declare class Client {
|
|
3
|
+
private static instance;
|
|
4
|
+
private token;
|
|
5
|
+
private readonly apiKey;
|
|
6
|
+
private readonly clientId;
|
|
7
|
+
private readonly orgId;
|
|
8
|
+
private expiresAt;
|
|
9
|
+
private readonly domain;
|
|
10
|
+
private readonly tokenDomain;
|
|
11
|
+
private readonly isUserProvidedToken;
|
|
12
|
+
private readonly clientSource;
|
|
13
|
+
private constructor();
|
|
14
|
+
/**
|
|
15
|
+
* Initializes and returns a Client instance with the provided configuration.
|
|
16
|
+
*
|
|
17
|
+
* @static
|
|
18
|
+
* @param {ClientConfig} config - The client configuration object
|
|
19
|
+
* @return {Promise<void>} A promise that resolves when the client is initialized
|
|
20
|
+
* @throws {Error} Throws an error if:
|
|
21
|
+
* - custom "host" is provided without "authUrl"
|
|
22
|
+
* - token is provided without "clientId"
|
|
23
|
+
* - apiKey is provided without "clientId" or "orgId"
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Initialize with authentication URL
|
|
27
|
+
* await Client.getClient({
|
|
28
|
+
* host: 'https://api.example.com',
|
|
29
|
+
* authUrl: 'https://auth.example.com',
|
|
30
|
+
* clientId: 'client123',
|
|
31
|
+
* orgId: 'org456'
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* // Initialize with existing token
|
|
35
|
+
* await Client.getClient({
|
|
36
|
+
* token: 'existing-jwt-token',
|
|
37
|
+
* clientId: 'client123'
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // Initialize with API key
|
|
41
|
+
* await Client.getClient({
|
|
42
|
+
* apiKey: 'your-api-key',
|
|
43
|
+
* clientId: 'client123',
|
|
44
|
+
* orgId: 'org456'
|
|
45
|
+
* });
|
|
46
|
+
*/
|
|
47
|
+
static getClient(config: ClientConfig): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Returns the domain URL configured for the client.
|
|
50
|
+
*
|
|
51
|
+
* @return {string} The domain URL string
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* const client = Client.getInstance();
|
|
55
|
+
* const apiDomain = client.getDomain();
|
|
56
|
+
* console.log(apiDomain); // e.g., 'https://api.example.com'
|
|
57
|
+
*/
|
|
58
|
+
getDomain(): string;
|
|
59
|
+
/**
|
|
60
|
+
* Returns the singleton instance of the Client.
|
|
61
|
+
*
|
|
62
|
+
* @static
|
|
63
|
+
* @return {Client} The singleton Client instance
|
|
64
|
+
* @throws {Error} Throws an error if the Client has not been initialized with getClient()
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* // First initialize the client
|
|
68
|
+
* await Client.getClient({
|
|
69
|
+
* clientId: 'client123',
|
|
70
|
+
* orgId: 'org456'
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* // Then get the instance
|
|
74
|
+
* const client = Client.getInstance();
|
|
75
|
+
* // Use the client...
|
|
76
|
+
*/
|
|
77
|
+
static getInstance(): Client;
|
|
78
|
+
/**
|
|
79
|
+
* Refreshes the authentication token if it's about to expire.
|
|
80
|
+
* Only refreshes if the token was not provided by the user and is expiring within 60 seconds.
|
|
81
|
+
*
|
|
82
|
+
* @return {Promise<void>} A promise that resolves when the token refresh is complete
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* const client = Client.getInstance();
|
|
86
|
+
* // Ensure token is fresh before making API requests
|
|
87
|
+
* await client.refreshToken();
|
|
88
|
+
* // Proceed with API requests...
|
|
89
|
+
*/
|
|
90
|
+
refreshToken(): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Returns the authorization header object with the Bearer token.
|
|
93
|
+
*
|
|
94
|
+
* @return {Record<string, string>} An object containing the Authorization header with the Bearer token
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* const client = Client.getInstance();
|
|
98
|
+
* const headers = {
|
|
99
|
+
* 'Content-Type': 'application/json',
|
|
100
|
+
* ...client.getAuthHeader()
|
|
101
|
+
* };
|
|
102
|
+
* // headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer token...' }
|
|
103
|
+
*/
|
|
104
|
+
getAuthHeader(): Record<string, string>;
|
|
105
|
+
/**
|
|
106
|
+
* Returns the client ID configured for this client instance.
|
|
107
|
+
*
|
|
108
|
+
* @return {string} The client ID string
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* const client = Client.getInstance();
|
|
112
|
+
* const clientId = client.getClientId();
|
|
113
|
+
* console.log(clientId); // e.g., 'client123'
|
|
114
|
+
*/
|
|
115
|
+
getClientId(): string;
|
|
116
|
+
/**
|
|
117
|
+
* Returns the client source identifier for this client instance.
|
|
118
|
+
*
|
|
119
|
+
* @return {string} The client source string
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* const client = Client.getInstance();
|
|
123
|
+
* const source = client.getClientSource();
|
|
124
|
+
* console.log(source); // e.g., 'web', 'mobile', 'sdk'
|
|
125
|
+
*/
|
|
126
|
+
getClientSource(): string;
|
|
127
|
+
/**
|
|
128
|
+
* Requests an authentication token from the token generation API.
|
|
129
|
+
*
|
|
130
|
+
* @private
|
|
131
|
+
* @static
|
|
132
|
+
* @param {ClientConfig} config - The client configuration containing authentication details
|
|
133
|
+
* @return {Promise<string>} A promise that resolves to the authentication token string
|
|
134
|
+
* @throws {Error} Throws an error if the token response is empty
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* // Internal usage within the Client class
|
|
138
|
+
* const token = await Client.requestToken({
|
|
139
|
+
* apiKey: 'your-api-key',
|
|
140
|
+
* clientId: 'client123',
|
|
141
|
+
* orgId: 'org456',
|
|
142
|
+
* authUrl: 'https://custom-auth.example.com/token'
|
|
143
|
+
* });
|
|
144
|
+
*/
|
|
145
|
+
private static requestToken;
|
|
146
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const API_DOMAIN = "https://api.ibm.com/ghgemissions/run";
|
|
2
|
+
export declare const TOKEN_GENERATION_API = "https://api.ibm.com/saascore/run/authentication-retrieve/api-key";
|
|
3
|
+
export declare const MOBILE_API_PATH = "/v3/carbon/mobile";
|
|
4
|
+
export declare const LOCATION_API_PATH = "/v3/carbon/location";
|
|
5
|
+
export declare const FUGITIVE_API_PATH = "/v3/carbon/fugitive";
|
|
6
|
+
export declare const STATIONARY_API_PATH = "/v3/carbon/stationary";
|
|
7
|
+
export declare const GENERIC_CALCULATION_API_PATH = "/v3/carbon/calculation";
|
|
8
|
+
export declare const TRANSPORTATION_AND_DISTRIBUTION_API_PATH = "/v3/carbon/transportation-and-distribution";
|
|
9
|
+
export declare const FACTOR_API_PATH = "/v3/carbon/factor";
|
|
10
|
+
export declare const FACTOR_SET_API_PATH = "/v3/carbon/factorset";
|
|
11
|
+
export declare const SEARCH_API_PATH = "/v3/carbon/factor/search";
|
|
12
|
+
export declare const GET = "GET";
|
|
13
|
+
export declare const POST = "POST";
|
|
14
|
+
export declare const CLIENT_SOURCE_HEADER = "X-Client-Source";
|
|
15
|
+
export declare const CLIENT_SOURCE_EXCEL = "excel";
|
|
16
|
+
export declare const CLIENT_SOURCE_SDK = "node-sdk";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CalculationRequest } from "../interfaces/Api";
|
|
2
|
+
/**
|
|
3
|
+
* Performs emission calculations by making a POST request to the generic calculation API endpoint.
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @param {CalculationRequest} payload - The calculation request data to be sent to the API
|
|
7
|
+
* @return {Promise<string>} A promise that resolves to the calculation result string returned by the API
|
|
8
|
+
* @throws {Error} May throw an error if the API request fails
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const calculationRequest = {
|
|
12
|
+
"time" : {
|
|
13
|
+
"date": "2025-01-04"
|
|
14
|
+
},
|
|
15
|
+
"location": {
|
|
16
|
+
"country": "usa",
|
|
17
|
+
"stateProvince": "new york"
|
|
18
|
+
},
|
|
19
|
+
"activity": {
|
|
20
|
+
"type":"Waste Combusted - Steel Cans:Default factor",
|
|
21
|
+
"unit": "kg",
|
|
22
|
+
"value": 1223123.121
|
|
23
|
+
},
|
|
24
|
+
"includeDetails": true
|
|
25
|
+
};
|
|
26
|
+
* const result = await calculate(calculationRequest);
|
|
27
|
+
*/
|
|
28
|
+
export declare function calculate(payload: CalculationRequest): Promise<string>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { FactorRequest, SearchRequest } from "../interfaces/Api";
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves a factor details by making a POST request to the factor API endpoint.
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @param {FactorRequest} payload - The factor request data to be sent to the API
|
|
7
|
+
* @return {Promise<string>} A promise that resolves to the factor string returned by the API
|
|
8
|
+
* @throws {Error} May throw an error if the API request fails
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const factorRequest = {
|
|
12
|
+
|
|
13
|
+
"activity": {
|
|
14
|
+
"factorId": 12345
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
or
|
|
19
|
+
|
|
20
|
+
const factorRequest = {
|
|
21
|
+
"time" : {
|
|
22
|
+
"date": "2025-01-04"
|
|
23
|
+
},
|
|
24
|
+
"location": {
|
|
25
|
+
"country": "usa",
|
|
26
|
+
"stateProvince": "new york"
|
|
27
|
+
},
|
|
28
|
+
"activity": {
|
|
29
|
+
"type":"natural gas"
|
|
30
|
+
},
|
|
31
|
+
"includeDetails": true
|
|
32
|
+
};
|
|
33
|
+
* const factor = await retrieveFactor(factorRequest);
|
|
34
|
+
*/
|
|
35
|
+
export declare function retrieveFactor(payload: FactorRequest): Promise<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Performs a search operation by making a POST request to the search API endpoint.
|
|
38
|
+
*
|
|
39
|
+
* @export
|
|
40
|
+
* @param {SearchRequest} payload - The search request data to be sent to the API
|
|
41
|
+
* @return {Promise<string>} A promise that resolves to the search results string returned by the API
|
|
42
|
+
* @throws {Error} May throw an error if the API request fails
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* const searchRequest = {
|
|
46
|
+
"time":{
|
|
47
|
+
"date": "2020-06-10"
|
|
48
|
+
},
|
|
49
|
+
"activity": {
|
|
50
|
+
"search" : "travel"},
|
|
51
|
+
"location": {
|
|
52
|
+
"country": "USA"
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
* const results = await search(searchRequest);
|
|
56
|
+
*/
|
|
57
|
+
export declare function search(payload: SearchRequest): Promise<string>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieves factor sets by making a GET request to the factor set API endpoint.
|
|
3
|
+
*
|
|
4
|
+
* @export
|
|
5
|
+
* @return {Promise<string>} A promise that resolves to the factor sets string returned by the API
|
|
6
|
+
* @throws {Error} May throw an error if the API request fails
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const factorSets = await get();
|
|
10
|
+
*/
|
|
11
|
+
export declare function get(): Promise<string>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { FactorRequest, SearchRequest } from "../interfaces/Api";
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves a factor details by making a POST request to the factor API endpoint.
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @param {FactorRequest} payload - The factor request data to be sent to the API
|
|
7
|
+
* @return {Promise<string>} A promise that resolves to the factor string returned by the API
|
|
8
|
+
* @throws {Error} May throw an error if the API request fails
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const factorRequest = {
|
|
12
|
+
|
|
13
|
+
"activity": {
|
|
14
|
+
"factorId": 12345
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
or
|
|
19
|
+
|
|
20
|
+
const factorRequest = {
|
|
21
|
+
"time" : {
|
|
22
|
+
"date": "2025-01-04"
|
|
23
|
+
},
|
|
24
|
+
"location": {
|
|
25
|
+
"country": "usa",
|
|
26
|
+
"stateProvince": "new york"
|
|
27
|
+
},
|
|
28
|
+
"activity": {
|
|
29
|
+
"type":"natural gas"
|
|
30
|
+
},
|
|
31
|
+
"includeDetails": true
|
|
32
|
+
};
|
|
33
|
+
* const factor = await retrieveFactor(factorRequest);
|
|
34
|
+
*/
|
|
35
|
+
export declare function retrieveFactor(payload: FactorRequest): Promise<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Retrieves factor sets by making a GET request to the factor set API endpoint.
|
|
38
|
+
*
|
|
39
|
+
* @export
|
|
40
|
+
* @return {Promise<string>} A promise that resolves to the factor sets string returned by the API
|
|
41
|
+
* @throws {Error} May throw an error if the API request fails
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* const factorSets = await getFactorSets();
|
|
45
|
+
*/
|
|
46
|
+
export declare function getFactorSets(): Promise<string>;
|
|
47
|
+
/**
|
|
48
|
+
* Performs a search operation by making a POST request to the search API endpoint.
|
|
49
|
+
*
|
|
50
|
+
* @export
|
|
51
|
+
* @param {SearchRequest} payload - The search request data to be sent to the API
|
|
52
|
+
* @return {Promise<string>} A promise that resolves to the search results string returned by the API
|
|
53
|
+
* @throws {Error} May throw an error if the API request fails
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* const searchRequest = {
|
|
57
|
+
"time":{
|
|
58
|
+
"date": "2020-06-10"
|
|
59
|
+
},
|
|
60
|
+
"activity": {
|
|
61
|
+
"search" : "travel"},
|
|
62
|
+
"location": {
|
|
63
|
+
"country": "USA"
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
* const results = await Search(searchRequest);
|
|
67
|
+
*/
|
|
68
|
+
export declare function Search(payload: SearchRequest): Promise<string>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CommonRequest } from "../interfaces/Api";
|
|
2
|
+
/**
|
|
3
|
+
* Performs scope 1 fugitve emission calculations by making a POST request to the fugitive API endpoint.
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @param {CommonRequest} payload - The request data to be sent to the API
|
|
7
|
+
* @return {Promise<string>} A promise that resolves to the calculation result string returned by the API
|
|
8
|
+
* @throws {Error} May throw an error if the API request fails
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const request = {
|
|
12
|
+
"time": {
|
|
13
|
+
"date": "2025-01-04"
|
|
14
|
+
},
|
|
15
|
+
"location": {
|
|
16
|
+
"country": "usa"
|
|
17
|
+
},
|
|
18
|
+
"activity": {
|
|
19
|
+
"type": "R134A",
|
|
20
|
+
"value": 150,
|
|
21
|
+
"unit": "kg"
|
|
22
|
+
},
|
|
23
|
+
"includeDetails": false
|
|
24
|
+
};
|
|
25
|
+
* const result = await calculate(request);
|
|
26
|
+
*/
|
|
27
|
+
export declare function calculate(payload: CommonRequest): Promise<string>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CommonRequest } from "../interfaces/Api";
|
|
2
|
+
/**
|
|
3
|
+
* Performs scope 1 fugitve emission calculations by making a POST request to the fugitive API endpoint.
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @param {CommonRequest} payload - The request data to be sent to the API
|
|
7
|
+
* @return {Promise<string>} A promise that resolves to the calculation result string returned by the API
|
|
8
|
+
* @throws {Error} May throw an error if the API request fails
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const request = {
|
|
12
|
+
"time": {
|
|
13
|
+
"date": "2025-01-04"
|
|
14
|
+
},
|
|
15
|
+
"location": {
|
|
16
|
+
"country": "usa"
|
|
17
|
+
},
|
|
18
|
+
"activity": {
|
|
19
|
+
"type": "R134A",
|
|
20
|
+
"value": 150,
|
|
21
|
+
"unit": "kg"
|
|
22
|
+
},
|
|
23
|
+
"includeDetails": false
|
|
24
|
+
};
|
|
25
|
+
* const result = await calculate(request);
|
|
26
|
+
*/
|
|
27
|
+
export declare function calculate(payload: CommonRequest): Promise<string>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { GenericCalculationRequest } from "../interfaces/Api";
|
|
2
|
+
/**
|
|
3
|
+
* Performs emission calculations by making a POST request to the generic calculation API endpoint.
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @param {GenericCalculationRequest} payload - The calculation request data to be sent to the API
|
|
7
|
+
* @return {Promise<string>} A promise that resolves to the calculation result string returned by the API
|
|
8
|
+
* @throws {Error} May throw an error if the API request fails
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const calculationRequest = {
|
|
12
|
+
"time" : {
|
|
13
|
+
"date": "2025-01-04"
|
|
14
|
+
},
|
|
15
|
+
"location": {
|
|
16
|
+
"country": "usa",
|
|
17
|
+
"stateProvince": "new york"
|
|
18
|
+
},
|
|
19
|
+
"activity": {
|
|
20
|
+
"type":"Waste Combusted - Steel Cans:Default factor",
|
|
21
|
+
"unit": "kg",
|
|
22
|
+
"value": 1223123.121
|
|
23
|
+
},
|
|
24
|
+
"includeDetails": true
|
|
25
|
+
};
|
|
26
|
+
* const result = await calculate(calculationRequest);
|
|
27
|
+
*/
|
|
28
|
+
export declare function calculate(payload: GenericCalculationRequest): Promise<string>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { LocationRequest } from "../interfaces/Api";
|
|
2
|
+
/**
|
|
3
|
+
* Performs scope 2 purchased energy Emission calculations by making a POST request to the location API endpoint.
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @param {LocationRequest} payload - The location request data to be sent to the API
|
|
7
|
+
* @return {Promise<string>} A promise that resolves to the purchased energy emission result string returned by the API
|
|
8
|
+
* @throws {Error} May throw an error if the API request fails
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const calculationRequest = {
|
|
12
|
+
"time" : {
|
|
13
|
+
"date": "2025-01-04"
|
|
14
|
+
},
|
|
15
|
+
"location": {
|
|
16
|
+
"country": "usa",
|
|
17
|
+
"stateProvince": "new york"
|
|
18
|
+
},
|
|
19
|
+
"activity": {
|
|
20
|
+
"type":"electricity",
|
|
21
|
+
"unit": "kwh",
|
|
22
|
+
"value": 14123143
|
|
23
|
+
},
|
|
24
|
+
"includeDetails": true
|
|
25
|
+
};
|
|
26
|
+
* const result = await calculate(calculationRequest);
|
|
27
|
+
*/
|
|
28
|
+
export declare function calculate(payload: LocationRequest): Promise<string>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { LocationRequest } from "../interfaces/Api";
|
|
2
|
+
/**
|
|
3
|
+
* Performs scope 2 purchased energy Emission calculations by making a POST request to the location API endpoint.
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @param {LocationRequest} payload - The location request data to be sent to the API
|
|
7
|
+
* @return {Promise<string>} A promise that resolves to the purchased energy emission result string returned by the API
|
|
8
|
+
* @throws {Error} May throw an error if the API request fails
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const calculationRequest = {
|
|
12
|
+
"time" : {
|
|
13
|
+
"date": "2025-01-04"
|
|
14
|
+
},
|
|
15
|
+
"location": {
|
|
16
|
+
"country": "usa",
|
|
17
|
+
"stateProvince": "new york"
|
|
18
|
+
},
|
|
19
|
+
"activity": {
|
|
20
|
+
"type":"electricity",
|
|
21
|
+
"unit": "kwh",
|
|
22
|
+
"value": 14123143
|
|
23
|
+
},
|
|
24
|
+
"includeDetails": true
|
|
25
|
+
};
|
|
26
|
+
* const result = await calculate(calculationRequest);
|
|
27
|
+
*/
|
|
28
|
+
export declare function calculate(payload: LocationRequest): Promise<string>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CommonRequest } from "../interfaces/Api";
|
|
2
|
+
/**
|
|
3
|
+
* Performs Scope 1 mobile emissions related calculations by making a POST request to the mobile API endpoint.
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @param {CommonRequest} payload - The request data to be sent to the mobile API
|
|
7
|
+
* @return {Promise<string>} A promise that resolves to the calculation result string returned by the API
|
|
8
|
+
* @throws {Error} May throw an error if the API request fails
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const request = {
|
|
12
|
+
"time": {
|
|
13
|
+
"date": "2022-01-01"
|
|
14
|
+
},
|
|
15
|
+
"location": {
|
|
16
|
+
"country": "USA",
|
|
17
|
+
"stateProvince": "new york"
|
|
18
|
+
},
|
|
19
|
+
"activity": {
|
|
20
|
+
"type": "Diesel Fuel",
|
|
21
|
+
"value": 1500000,
|
|
22
|
+
"unit": "l"
|
|
23
|
+
},
|
|
24
|
+
"includeDetails": false
|
|
25
|
+
};
|
|
26
|
+
* const result = await calculate(request);
|
|
27
|
+
*/
|
|
28
|
+
export declare function calculate(payload: CommonRequest): Promise<string>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CommonRequest } from "../interfaces/Api";
|
|
2
|
+
/**
|
|
3
|
+
* Performs Scope 1 mobile emissions related calculations by making a POST request to the mobile API endpoint.
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @param {CommonRequest} payload - The request data to be sent to the mobile API
|
|
7
|
+
* @return {Promise<string>} A promise that resolves to the calculation result string returned by the API
|
|
8
|
+
* @throws {Error} May throw an error if the API request fails
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const request = {
|
|
12
|
+
"time": {
|
|
13
|
+
"date": "2022-01-01"
|
|
14
|
+
},
|
|
15
|
+
"location": {
|
|
16
|
+
"country": "USA",
|
|
17
|
+
"stateProvince": "new york"
|
|
18
|
+
},
|
|
19
|
+
"activity": {
|
|
20
|
+
"type": "Diesel Fuel",
|
|
21
|
+
"value": 1500000,
|
|
22
|
+
"unit": "l"
|
|
23
|
+
},
|
|
24
|
+
"includeDetails": false
|
|
25
|
+
};
|
|
26
|
+
* const result = await calculate(request);
|
|
27
|
+
*/
|
|
28
|
+
export declare function calculate(payload: CommonRequest): Promise<string>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CommonRequest } from "../interfaces/Api";
|
|
2
|
+
/**
|
|
3
|
+
* Performs Scope 1 stationary calculations by making a POST request to the stationary API endpoint.
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @param {CommonRequest} payload - The request data to be sent to the stationary API
|
|
7
|
+
* @return {Promise<string>} A promise that resolves to the calculation result string returned by the API
|
|
8
|
+
* @throws {Error} May throw an error if the API request fails
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const request = {
|
|
12
|
+
"time" : {
|
|
13
|
+
"date": "2025-01-04"
|
|
14
|
+
},
|
|
15
|
+
"location": {
|
|
16
|
+
"country": "usa",
|
|
17
|
+
"stateProvince": "new york"
|
|
18
|
+
},
|
|
19
|
+
"activity": {
|
|
20
|
+
"type":"Coal - Lignite",
|
|
21
|
+
"unit": "KJ",
|
|
22
|
+
"value": 3
|
|
23
|
+
},
|
|
24
|
+
"includeDetails": true
|
|
25
|
+
};
|
|
26
|
+
* const result = await calculate(request);
|
|
27
|
+
*/
|
|
28
|
+
export declare function calculate(payload: CommonRequest): Promise<string>;
|