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
|
@@ -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>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CalculationRequest } from "../interfaces/Api";
|
|
2
|
+
/**
|
|
3
|
+
* Performs Scope 2 transportation and distribution emission calculations by making a POST request to the transportation and distribution API endpoint.
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @param {CalculationRequest} payload - The calculation request data for transportation and distribution operations
|
|
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": "Freight - Cargo Ship - Bulk Carrier - 0-9999 dwt",
|
|
20
|
+
"unit": ["t","km"],
|
|
21
|
+
"value": [1.0,1.0]
|
|
22
|
+
},
|
|
23
|
+
"includeDetails": true
|
|
24
|
+
};
|
|
25
|
+
* const result = await calculate(request);
|
|
26
|
+
*/
|
|
27
|
+
export declare function calculate(payload: CalculationRequest): Promise<string>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { GenericCalculationRequest } from "../interfaces/Api";
|
|
2
|
+
/**
|
|
3
|
+
* Performs Scope 2 transportation and distribution emission calculations by making a POST request to the transportation and distribution API endpoint.
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @param {GenericCalculationRequest} payload - The calculation request data for transportation and distribution operations
|
|
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": "Freight - Cargo Ship - Bulk Carrier - 0-9999 dwt",
|
|
20
|
+
"unit": ["t","km"],
|
|
21
|
+
"value": [1.0,1.0]
|
|
22
|
+
},
|
|
23
|
+
"includeDetails": true
|
|
24
|
+
};
|
|
25
|
+
* const result = await calculate(request);
|
|
26
|
+
*/
|
|
27
|
+
export declare function calculate(payload: GenericCalculationRequest): Promise<string>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { Client } from './Client';
|
|
2
|
+
export * as Location from './api/Location';
|
|
3
|
+
export * as Fugitive from './api/Fugitive';
|
|
4
|
+
export * as Mobile from './api/Mobile';
|
|
5
|
+
export * as Stationary from './api/Stationary';
|
|
6
|
+
export * as Calculation from './api/Calculation';
|
|
7
|
+
export * as TransportationAndDistribution from './api/TransportationAndDistribution';
|
|
8
|
+
export * as Factor from './api/Factor';
|
|
9
|
+
export * as FactorSets from './api/FactorSets';
|
|
10
|
+
export { ClientConfig } from './interfaces/Config';
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { Activity, Location, Time, CombinedUnitsActivity, FactorActivity, SearchActivity, Pagination, FactorActivityWithFactorId, CombinedUnitsActivityWithFactorId, ActivityWithFactorId } from "./common";
|
|
2
|
+
/**
|
|
3
|
+
* Represents activity data associated with a location, with simplified requirements.
|
|
4
|
+
* Derived from the Activity type but makes the 'type' and 'unit' properties optional
|
|
5
|
+
* while keeping the 'value' property required.
|
|
6
|
+
*
|
|
7
|
+
* @typedef {Object} LocationActivity
|
|
8
|
+
* @property {any} value - The required activity value (e.g., quantity, amount, or measurement)
|
|
9
|
+
* @property {string} [type] - Optional activity type identifier
|
|
10
|
+
* @property {string} [unit] - Optional unit of measurement for the activity value
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Minimal valid LocationActivity with only required properties
|
|
14
|
+
* const minimalActivity: LocationActivity = {
|
|
15
|
+
* value: 100
|
|
16
|
+
* };
|
|
17
|
+
*
|
|
18
|
+
* // Complete LocationActivity with all properties
|
|
19
|
+
* const fullActivity: LocationActivity = {
|
|
20
|
+
* value: 100,
|
|
21
|
+
* type: 'electricity',
|
|
22
|
+
* unit: 'kWh'
|
|
23
|
+
* };
|
|
24
|
+
*/
|
|
25
|
+
type LocationActivity = Partial<Pick<Activity, 'type' | 'unit'>> & Pick<Activity, 'value'>;
|
|
26
|
+
/**
|
|
27
|
+
* Represents activity data associated with a location that includes a specific factor ID.
|
|
28
|
+
* Extends the Activity concept by requiring a factorId while making only the value property
|
|
29
|
+
* required and the unit property optional.
|
|
30
|
+
*
|
|
31
|
+
* @typedef {Object} LocationActivityWithFactorId
|
|
32
|
+
* @property {number} factorId - The unique identifier for the emission factor to be used
|
|
33
|
+
* @property {any} value - The required activity value (e.g., quantity, amount, or measurement)
|
|
34
|
+
* @property {string} [unit] - Optional unit of measurement for the activity value
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* // Minimal valid LocationActivityWithFactorId with only required properties
|
|
38
|
+
* const minimalActivity: LocationActivityWithFactorId = {
|
|
39
|
+
* factorId: 12345,
|
|
40
|
+
* value: 100
|
|
41
|
+
* };
|
|
42
|
+
*
|
|
43
|
+
* // Complete LocationActivityWithFactorId with all properties
|
|
44
|
+
* const fullActivity: LocationActivityWithFactorId = {
|
|
45
|
+
* factorId: 12345,
|
|
46
|
+
* value: 100,
|
|
47
|
+
* unit: 'kWh'
|
|
48
|
+
* };
|
|
49
|
+
*/
|
|
50
|
+
type LocationActivityWithFactorId = {
|
|
51
|
+
factorId: number;
|
|
52
|
+
} & Partial<Pick<Activity, 'unit'>> & Pick<Activity, 'value'>;
|
|
53
|
+
/**
|
|
54
|
+
* Request parameters for location-based calculations without specifying a factor ID.
|
|
55
|
+
* Used for calculating emissions or other metrics based on location data.
|
|
56
|
+
*
|
|
57
|
+
* @interface LocationRequestWithoutFactorId
|
|
58
|
+
*/
|
|
59
|
+
export interface LocationRequestWithoutFactorId {
|
|
60
|
+
/**
|
|
61
|
+
* The geographical location information.
|
|
62
|
+
* Contains coordinates and possibly other location-specific data.
|
|
63
|
+
*/
|
|
64
|
+
location: Location;
|
|
65
|
+
/**
|
|
66
|
+
* Optional time(YYYY-MM-DD)information for the location data.
|
|
67
|
+
* Can be used to specify when the activity occurred.
|
|
68
|
+
*/
|
|
69
|
+
time?: Time;
|
|
70
|
+
/**
|
|
71
|
+
* The activity associated with this location.
|
|
72
|
+
* Defines what type of action or event occurred at the location.
|
|
73
|
+
*/
|
|
74
|
+
activity: LocationActivity;
|
|
75
|
+
/**
|
|
76
|
+
* Whether to include additional details in the response.
|
|
77
|
+
* When true, the API will return more comprehensive information.
|
|
78
|
+
* @default false
|
|
79
|
+
*/
|
|
80
|
+
includeDetails?: boolean;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Request parameters for location-based calculations with a specific factor ID.
|
|
84
|
+
* Used when the emission factor is already known and doesn't need to be determined by location.
|
|
85
|
+
*
|
|
86
|
+
* @interface LocationRequestWithFactorId
|
|
87
|
+
*/
|
|
88
|
+
export interface LocationRequestWithFactorId {
|
|
89
|
+
/**
|
|
90
|
+
* The activity associated with this location, including the specific factor ID to use.
|
|
91
|
+
*/
|
|
92
|
+
activity: LocationActivityWithFactorId;
|
|
93
|
+
/**
|
|
94
|
+
* Whether to include additional details in the response.
|
|
95
|
+
* When true, the API will return more comprehensive information.
|
|
96
|
+
* @default false
|
|
97
|
+
*/
|
|
98
|
+
includeDetails?: boolean;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Common request parameters for calculations without specifying a factor ID.
|
|
102
|
+
* Used for general-purpose calculations based on location, time, and activity data.
|
|
103
|
+
*
|
|
104
|
+
* @interface CommonRequestWithoutFactorId
|
|
105
|
+
*/
|
|
106
|
+
export interface CommonRequestWithoutFactorId {
|
|
107
|
+
/**
|
|
108
|
+
* The geographical location information.
|
|
109
|
+
* Contains coordinates and possibly other location-specific data.
|
|
110
|
+
*/
|
|
111
|
+
location: Location;
|
|
112
|
+
/**
|
|
113
|
+
* Optional time information for the activity data.
|
|
114
|
+
* Can be used to specify when the activity occurred.
|
|
115
|
+
*/
|
|
116
|
+
time?: Time;
|
|
117
|
+
/**
|
|
118
|
+
* The activity data for the calculation.
|
|
119
|
+
* Contains complete activity information including type, value, and unit.
|
|
120
|
+
*/
|
|
121
|
+
activity: Activity;
|
|
122
|
+
/**
|
|
123
|
+
* Whether to include additional details in the response.
|
|
124
|
+
* When true, the API will return more comprehensive information.
|
|
125
|
+
* @default false
|
|
126
|
+
*/
|
|
127
|
+
includeDetails?: boolean;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Common request parameters for calculations with a specific factor ID.
|
|
131
|
+
* Used when the emission factor is already known and doesn't need to be determined by location.
|
|
132
|
+
*
|
|
133
|
+
* @interface CommonRequestWithFactorId
|
|
134
|
+
*/
|
|
135
|
+
export interface CommonRequestWithFactorId {
|
|
136
|
+
/**
|
|
137
|
+
* The activity data for the calculation, including the specific factor ID to use.
|
|
138
|
+
*/
|
|
139
|
+
activity: ActivityWithFactorId;
|
|
140
|
+
/**
|
|
141
|
+
* Whether to include additional details in the response.
|
|
142
|
+
* When true, the API will return more comprehensive information.
|
|
143
|
+
* @default false
|
|
144
|
+
*/
|
|
145
|
+
includeDetails?: boolean;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Request parameters for generic calculations without specifying a factor ID.
|
|
149
|
+
* Used for calculations that may involve multiple units or complex activity data.
|
|
150
|
+
*
|
|
151
|
+
* @interface GenericCalculationRequestWithoutFactorId
|
|
152
|
+
*/
|
|
153
|
+
export interface GenericCalculationRequestWithoutFactorId {
|
|
154
|
+
/**
|
|
155
|
+
* The geographical location information.
|
|
156
|
+
* Contains coordinates and possibly other location-specific data.
|
|
157
|
+
*/
|
|
158
|
+
location: Location;
|
|
159
|
+
/**
|
|
160
|
+
* Optional time information for the activity data.
|
|
161
|
+
* Can be used to specify when the activity occurred.
|
|
162
|
+
*/
|
|
163
|
+
time?: Time;
|
|
164
|
+
/**
|
|
165
|
+
* The combined units activity data for the calculation.
|
|
166
|
+
* Supports complex activities with multiple units or components.
|
|
167
|
+
*/
|
|
168
|
+
activity: CombinedUnitsActivity;
|
|
169
|
+
/**
|
|
170
|
+
* Whether to include additional details in the response.
|
|
171
|
+
* When true, the API will return more comprehensive information.
|
|
172
|
+
* @default false
|
|
173
|
+
*/
|
|
174
|
+
includeDetails?: boolean;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Request parameters for generic calculations with a specific factor ID.
|
|
178
|
+
* Used for complex calculations where the emission factor is already known.
|
|
179
|
+
*
|
|
180
|
+
* @interface GenericCalculationRequestWithFactorId
|
|
181
|
+
*/
|
|
182
|
+
export interface GenericCalculationRequestWithFactorId {
|
|
183
|
+
/**
|
|
184
|
+
* The combined units activity data for the calculation, including the specific factor ID to use.
|
|
185
|
+
* Supports complex activities with multiple units or components.
|
|
186
|
+
*/
|
|
187
|
+
activity: CombinedUnitsActivityWithFactorId;
|
|
188
|
+
/**
|
|
189
|
+
* Whether to include additional details in the response.
|
|
190
|
+
* When true, the API will return more comprehensive information.
|
|
191
|
+
* @default false
|
|
192
|
+
*/
|
|
193
|
+
includeDetails?: boolean;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Request parameters for retrieving factor information without specifying a factor ID.
|
|
197
|
+
* Used to look up appropriate emission factors based on location, time, and activity type.
|
|
198
|
+
*
|
|
199
|
+
* @interface FactorRequestWithoutFactorId
|
|
200
|
+
*/
|
|
201
|
+
export interface FactorRequestWithoutFactorId {
|
|
202
|
+
/**
|
|
203
|
+
* The geographical location information.
|
|
204
|
+
* Used to determine which factors are applicable for the region.
|
|
205
|
+
*/
|
|
206
|
+
location: Location;
|
|
207
|
+
/**
|
|
208
|
+
* Optional time information for the factor lookup.
|
|
209
|
+
* Can be used to find factors applicable at a specific point in time.
|
|
210
|
+
*/
|
|
211
|
+
time?: Time;
|
|
212
|
+
/**
|
|
213
|
+
* The activity information used to determine which factors to retrieve.
|
|
214
|
+
* Typically includes the activity type and possibly unit information.
|
|
215
|
+
*/
|
|
216
|
+
activity: FactorActivity;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Request parameters for retrieving specific factor information by ID.
|
|
220
|
+
* Used when the exact factor to retrieve is already known.
|
|
221
|
+
*
|
|
222
|
+
* @interface FactorRequestWithFactorId
|
|
223
|
+
*/
|
|
224
|
+
export interface FactorRequestWithFactorId {
|
|
225
|
+
/**
|
|
226
|
+
* The activity information including the specific factor ID to retrieve.
|
|
227
|
+
*/
|
|
228
|
+
activity: FactorActivityWithFactorId;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Request parameters for searching factors or activities.
|
|
232
|
+
* Used to find relevant factors or activities based on location, time, and search criteria.
|
|
233
|
+
*
|
|
234
|
+
* @interface SearchRequest
|
|
235
|
+
*/
|
|
236
|
+
export interface SearchRequest {
|
|
237
|
+
/**
|
|
238
|
+
* The geographical location information to scope the search.
|
|
239
|
+
* Used to find factors or activities relevant to a specific region.
|
|
240
|
+
*/
|
|
241
|
+
location: Location;
|
|
242
|
+
/**
|
|
243
|
+
* Optional time information to scope the search.
|
|
244
|
+
* Can be used to find factors or activities relevant at a specific point in time.
|
|
245
|
+
*/
|
|
246
|
+
time?: Time;
|
|
247
|
+
/**
|
|
248
|
+
* The search criteria and parameters.
|
|
249
|
+
* Contains information about what to search for and any filters to apply.
|
|
250
|
+
*/
|
|
251
|
+
activity: SearchActivity;
|
|
252
|
+
/**
|
|
253
|
+
* Optional pagination parameters for the search results.
|
|
254
|
+
* Used to limit the number of results and implement paging.
|
|
255
|
+
*/
|
|
256
|
+
pagination?: Pagination;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Union type representing either a factor request with or without a specific factor ID.
|
|
260
|
+
* Allows the API to handle both types of requests with a single parameter type.
|
|
261
|
+
*
|
|
262
|
+
* @typedef {FactorRequestWithoutFactorId | FactorRequestWithFactorId} FactorRequest
|
|
263
|
+
*/
|
|
264
|
+
export type FactorRequest = FactorRequestWithoutFactorId | FactorRequestWithFactorId;
|
|
265
|
+
/**
|
|
266
|
+
* Union type representing either a generic calculation request with or without a specific factor ID.
|
|
267
|
+
* Allows the API to handle both types of calculation requests with a single parameter type.
|
|
268
|
+
*
|
|
269
|
+
* @typedef {GenericCalculationRequestWithoutFactorId | GenericCalculationRequestWithFactorId} CalculationRequest
|
|
270
|
+
*/
|
|
271
|
+
export type CalculationRequest = GenericCalculationRequestWithoutFactorId | GenericCalculationRequestWithFactorId;
|
|
272
|
+
/**
|
|
273
|
+
* Union type representing either a common request with or without a specific factor ID.
|
|
274
|
+
* Allows the API to handle both types of common requests with a single parameter type.
|
|
275
|
+
*
|
|
276
|
+
* @typedef {CommonRequestWithoutFactorId | CommonRequestWithFactorId} CommonRequest
|
|
277
|
+
*/
|
|
278
|
+
export type CommonRequest = CommonRequestWithoutFactorId | CommonRequestWithFactorId;
|
|
279
|
+
/**
|
|
280
|
+
* Union type representing either a location request with or without a specific factor ID.
|
|
281
|
+
* Allows the API to handle both types of location requests with a single parameter type.
|
|
282
|
+
*
|
|
283
|
+
* @typedef {LocationRequestWithoutFactorId | LocationRequestWithFactorId} LocationRequest
|
|
284
|
+
*/
|
|
285
|
+
export type LocationRequest = LocationRequestWithoutFactorId | LocationRequestWithFactorId;
|
|
286
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Method } from "axios";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for making HTTP requests.
|
|
4
|
+
* @interface RequestConfig
|
|
5
|
+
*/
|
|
6
|
+
export interface RequestConfig {
|
|
7
|
+
/**
|
|
8
|
+
* The HTTP method to use for the request (GET, POST, PUT, DELETE, etc.).
|
|
9
|
+
*/
|
|
10
|
+
method: Method;
|
|
11
|
+
/**
|
|
12
|
+
* The URL to which the request will be sent.
|
|
13
|
+
*/
|
|
14
|
+
url: string;
|
|
15
|
+
/**
|
|
16
|
+
* Optional request body data to be sent with the request.
|
|
17
|
+
*/
|
|
18
|
+
data?: any;
|
|
19
|
+
/**
|
|
20
|
+
* Optional URL query parameters to be appended to the request URL.
|
|
21
|
+
*/
|
|
22
|
+
params?: any;
|
|
23
|
+
/**
|
|
24
|
+
* Optional HTTP headers to be included with the request.
|
|
25
|
+
*/
|
|
26
|
+
headers?: Record<string, string>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Configuration for initializing a client instance.
|
|
30
|
+
* @interface ClientConfig
|
|
31
|
+
*/
|
|
32
|
+
export interface ClientConfig {
|
|
33
|
+
/**
|
|
34
|
+
* Optional API key used for authentication.
|
|
35
|
+
*/
|
|
36
|
+
apiKey?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Unique identifier for the client application.
|
|
39
|
+
* This is required for all client instances.
|
|
40
|
+
*/
|
|
41
|
+
clientId: string;
|
|
42
|
+
/**
|
|
43
|
+
* Optional organization identifier.
|
|
44
|
+
*/
|
|
45
|
+
orgId?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Optional host URL for API requests.
|
|
48
|
+
* If not provided, a default host will be used.
|
|
49
|
+
*/
|
|
50
|
+
host?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Optional authentication URL.
|
|
53
|
+
* If not provided, a default authentication endpoint will be used.
|
|
54
|
+
*/
|
|
55
|
+
authUrl?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Optional authentication token.
|
|
58
|
+
* If provided, it will be used instead of requesting a new token.
|
|
59
|
+
*/
|
|
60
|
+
token?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Optional flag indicating whether the client is running as an Excel Add-In.
|
|
63
|
+
* This may affect certain behaviors like authentication flows.
|
|
64
|
+
*/
|
|
65
|
+
isExcelAddIn?: boolean;
|
|
66
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a geographical location.
|
|
3
|
+
* @interface Location
|
|
4
|
+
*/
|
|
5
|
+
export interface Location {
|
|
6
|
+
/**
|
|
7
|
+
* The country of the location.
|
|
8
|
+
*/
|
|
9
|
+
country: string;
|
|
10
|
+
/**
|
|
11
|
+
* Optional state or province within the country.
|
|
12
|
+
*/
|
|
13
|
+
stateProvince?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Optional power grid identifier for the location.
|
|
16
|
+
*/
|
|
17
|
+
powerGrid?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Represents a point in time with date information.
|
|
21
|
+
* @interface Time
|
|
22
|
+
*/
|
|
23
|
+
export interface Time {
|
|
24
|
+
/**
|
|
25
|
+
* The date in string format.
|
|
26
|
+
*/
|
|
27
|
+
date: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Represents an activity with type, value, and unit of measurement.
|
|
31
|
+
* @interface Activity
|
|
32
|
+
*/
|
|
33
|
+
export interface Activity {
|
|
34
|
+
/**
|
|
35
|
+
* The type or category of the activity.
|
|
36
|
+
*/
|
|
37
|
+
type: string;
|
|
38
|
+
/**
|
|
39
|
+
* The numerical value of the activity.
|
|
40
|
+
*/
|
|
41
|
+
value: number;
|
|
42
|
+
/**
|
|
43
|
+
* The unit of measurement for the activity value.
|
|
44
|
+
*/
|
|
45
|
+
unit: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Represents an activity identified by a factor ID instead of a type.
|
|
49
|
+
* @interface ActivityWithFactorId
|
|
50
|
+
*/
|
|
51
|
+
export interface ActivityWithFactorId {
|
|
52
|
+
/**
|
|
53
|
+
* The unique identifier for the activity factor.
|
|
54
|
+
*/
|
|
55
|
+
factorId: number;
|
|
56
|
+
/**
|
|
57
|
+
* The numerical value of the activity.
|
|
58
|
+
*/
|
|
59
|
+
value: number;
|
|
60
|
+
/**
|
|
61
|
+
* The unit of measurement for the activity value.
|
|
62
|
+
*/
|
|
63
|
+
unit: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Represents an activity that can have single or multiple values and units.
|
|
67
|
+
* @interface CombinedUnitsActivity
|
|
68
|
+
*/
|
|
69
|
+
export interface CombinedUnitsActivity {
|
|
70
|
+
/**
|
|
71
|
+
* The type or category of the activity.
|
|
72
|
+
*/
|
|
73
|
+
type: string;
|
|
74
|
+
/**
|
|
75
|
+
* The numerical value(s) of the activity. Can be a single number or an array of numbers.
|
|
76
|
+
*/
|
|
77
|
+
value: number | number[];
|
|
78
|
+
/**
|
|
79
|
+
* The unit(s) of measurement for the activity value(s). Can be a single string or an array of strings.
|
|
80
|
+
*/
|
|
81
|
+
unit: string | string[];
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Represents an activity with factor ID that can have single or multiple values and units.
|
|
85
|
+
* @interface CombinedUnitsActivityWithFactorId
|
|
86
|
+
*/
|
|
87
|
+
export interface CombinedUnitsActivityWithFactorId {
|
|
88
|
+
/**
|
|
89
|
+
* The unique identifier for the activity factor.
|
|
90
|
+
*/
|
|
91
|
+
factorId: number;
|
|
92
|
+
/**
|
|
93
|
+
* The numerical value(s) of the activity. Can be a single number or an array of numbers.
|
|
94
|
+
*/
|
|
95
|
+
value: number | number[];
|
|
96
|
+
/**
|
|
97
|
+
* The unit(s) of measurement for the activity value(s). Can be a single string or an array of strings.
|
|
98
|
+
*/
|
|
99
|
+
unit: string | string[];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Represents a factor activity with a type and optional unit.
|
|
103
|
+
* @interface FactorActivity
|
|
104
|
+
*/
|
|
105
|
+
export interface FactorActivity {
|
|
106
|
+
/**
|
|
107
|
+
* The type or category of the factor activity.
|
|
108
|
+
*/
|
|
109
|
+
type: string;
|
|
110
|
+
/**
|
|
111
|
+
* Optional unit of measurement for the factor activity.
|
|
112
|
+
*/
|
|
113
|
+
unit?: string;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Represents a factor activity identified by a factor ID instead of a type.
|
|
117
|
+
* @interface FactorActivityWithFactorId
|
|
118
|
+
*/
|
|
119
|
+
export interface FactorActivityWithFactorId {
|
|
120
|
+
/**
|
|
121
|
+
* The unique identifier for the factor activity.
|
|
122
|
+
*/
|
|
123
|
+
factorId: number;
|
|
124
|
+
/**
|
|
125
|
+
* Optional unit of measurement for the factor activity.
|
|
126
|
+
*/
|
|
127
|
+
unit?: string;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Represents a search query for activities.
|
|
131
|
+
* @interface SearchActivity
|
|
132
|
+
*/
|
|
133
|
+
export interface SearchActivity {
|
|
134
|
+
/**
|
|
135
|
+
* The search query string.
|
|
136
|
+
*/
|
|
137
|
+
search: string;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Represents pagination parameters for paginated results.
|
|
141
|
+
* @interface Pagination
|
|
142
|
+
*/
|
|
143
|
+
export interface Pagination {
|
|
144
|
+
/**
|
|
145
|
+
* The page number (1-based).
|
|
146
|
+
*/
|
|
147
|
+
page: number;
|
|
148
|
+
/**
|
|
149
|
+
* The number of items per page.
|
|
150
|
+
*/
|
|
151
|
+
size: number;
|
|
152
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { RequestConfig } from "./interfaces/Config";
|
|
2
|
+
/**
|
|
3
|
+
* Makes an API request with standardized headers and token refresh.
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @template T The expected response data type
|
|
7
|
+
* @param {RequestConfig} config - The request configuration including method, URL, data, params, and optional headers
|
|
8
|
+
* @return {Promise<T>} A promise that resolves to the response data of type T
|
|
9
|
+
* @throws {Error} May throw an error if the API request fails or token refresh fails
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* interface UserData {
|
|
13
|
+
* id: string;
|
|
14
|
+
* name: string;
|
|
15
|
+
* email: string;
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* const userData = await makeApiRequest<UserData>({
|
|
19
|
+
* method: 'GET',
|
|
20
|
+
* url: 'https://api.example.com/users/123',
|
|
21
|
+
* headers: { 'X-Custom-Header': 'value' }
|
|
22
|
+
* });
|
|
23
|
+
* console.log(userData.name); // Typed access to the response data
|
|
24
|
+
*/
|
|
25
|
+
export declare function makeApiRequest<T>(config: RequestConfig): Promise<T>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the expiration time from a JWT token and give the token expiry time.
|
|
3
|
+
*
|
|
4
|
+
* @export
|
|
5
|
+
* @param {string} token - The JWT token to extract the expiration time from
|
|
6
|
+
* @return {any} The expiration time value from the token's payload
|
|
7
|
+
* @throws {Error} Throws an error if the exp field is missing in the token
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const jwtToken = 'your-token';
|
|
11
|
+
* const expiryTime = findExpiryTime(jwtToken);
|
|
12
|
+
* console.log(new Date(expiryTime * 1000).toISOString()); // Convert to date if it's a Unix timestamp
|
|
13
|
+
*/
|
|
14
|
+
export declare function findExpiryTime(token: string): any;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findExpiryTime = findExpiryTime;
|
|
4
|
+
/**
|
|
5
|
+
* Extracts the expiration time from a JWT token and give the token expiry time.
|
|
6
|
+
*
|
|
7
|
+
* @export
|
|
8
|
+
* @param {string} token - The JWT token to extract the expiration time from
|
|
9
|
+
* @return {any} The expiration time value from the token's payload
|
|
10
|
+
* @throws {Error} Throws an error if the exp field is missing in the token
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const jwtToken = 'your-token';
|
|
14
|
+
* const expiryTime = findExpiryTime(jwtToken);
|
|
15
|
+
* console.log(new Date(expiryTime * 1000).toISOString()); // Convert to date if it's a Unix timestamp
|
|
16
|
+
*/
|
|
17
|
+
function findExpiryTime(token) {
|
|
18
|
+
const payload = token.split('.')[1];
|
|
19
|
+
const decoded = JSON.parse(Buffer.from(payload, 'base64').toString('utf8'));
|
|
20
|
+
if (!decoded.exp)
|
|
21
|
+
throw new Error('exp field is missing in the token');
|
|
22
|
+
return decoded.exp;
|
|
23
|
+
}
|
package/jest.config.js
ADDED