emissions-api-sdk 1.0.12 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -2
- package/dist/Constants.js +7 -1
- package/dist/api/AuditExport.js +73 -0
- package/dist/api/AuditLog.js +99 -0
- package/dist/api/EconomicActivity.js +69 -0
- package/dist/api/Factor.js +16 -0
- package/dist/api/PhysicalActivity.js +87 -0
- package/dist/api/RealEstate.js +25 -1
- package/dist/api/TypeRecommender.js +19 -2
- package/dist/coverage/clover.xml +172 -89
- package/dist/coverage/coverage-final.json +15 -8
- package/dist/coverage/lcov-report/index.html +21 -21
- package/dist/coverage/lcov-report/src/Client.ts.html +32 -32
- package/dist/coverage/lcov-report/src/Constants.ts.html +45 -27
- package/dist/coverage/lcov-report/src/api/AuditExport.ts.html +355 -0
- package/dist/coverage/lcov-report/src/api/AuditLog.ts.html +388 -0
- package/dist/coverage/lcov-report/src/api/Calculation.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/EconomicActivity.ts.html +212 -5
- package/dist/coverage/lcov-report/src/api/Factor.ts.html +54 -3
- 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 +361 -0
- package/dist/coverage/lcov-report/src/api/RealEstate.ts.html +78 -6
- 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 +55 -4
- package/dist/coverage/lcov-report/src/api/Usage.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/index.html +51 -6
- 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 +6 -6
- package/dist/coverage/lcov-report/test/index.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/AttributionRequest.ts.html +151 -0
- package/dist/coverage/lcov-report/test/mocks/CommonRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/EconomicActivityAttributionRequest.ts.html +148 -0
- 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 +148 -0
- package/dist/coverage/lcov-report/test/mocks/PhysicalActivityRequest.ts.html +151 -0
- package/dist/coverage/lcov-report/test/mocks/SearchRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/index.html +63 -3
- package/dist/coverage/lcov-report/test/testUtils.ts.html +1 -1
- package/dist/coverage/lcov.info +284 -124
- package/dist/index.js +4 -1
- package/dist/interfaces/response/AuditExportResponse.js +2 -0
- package/dist/interfaces/response/AuditLogResponse.js +2 -0
- package/dist/request.js +1 -0
- package/dist/types/Constants.d.ts +6 -0
- package/dist/types/api/AuditExport.d.ts +42 -0
- package/dist/types/api/AuditLog.d.ts +37 -0
- package/dist/types/api/EconomicActivity.d.ts +69 -0
- package/dist/types/api/Factor.d.ts +16 -0
- package/dist/types/api/PhysicalActivity.d.ts +76 -0
- package/dist/types/api/RealEstate.d.ts +25 -1
- package/dist/types/api/TypeRecommender.d.ts +19 -2
- package/dist/types/index.d.ts +6 -0
- package/dist/types/interfaces/Api.d.ts +17 -1
- package/dist/types/interfaces/Config.d.ts +5 -1
- package/dist/types/interfaces/common.d.ts +40 -0
- package/dist/types/interfaces/response/AuditExportResponse.d.ts +66 -0
- package/dist/types/interfaces/response/AuditLogResponse.d.ts +40 -0
- package/dist/types/interfaces/response/TypeRecommenderResponse.d.ts +2 -0
- package/docs/_sources/authentication.rst.txt +26 -4
- package/docs/_sources/getting_started.rst.txt +762 -74
- package/docs/_sources/index.rst.txt +13 -0
- package/docs/_sources/reference.rst.txt +48 -0
- package/docs/_sources/troubleshooting.rst.txt +77 -12
- package/docs/_static/basic.css +8 -0
- package/docs/_static/doctools.js +5 -6
- package/docs/_static/language_data.js +186 -7
- package/docs/_static/pygments.css +146 -164
- package/docs/_static/searchtools.js +60 -121
- package/docs/_static/sphinx_highlight.js +31 -36
- package/docs/_static/styles/furo.css +1 -1
- package/docs/_static/styles/furo.css.map +1 -1
- package/docs/authentication.html +61 -26
- package/docs/client.html +33 -22
- package/docs/genindex.html +77 -24
- package/docs/getting_started.html +969 -103
- package/docs/index.html +69 -21
- package/docs/reference.html +747 -66
- package/docs/sdk.html +32 -21
- package/docs/search.html +32 -21
- package/docs/searchindex.js +1 -1
- package/docs/troubleshooting.html +105 -38
- package/package.json +8 -3
- package/sphinx-build/source/authentication.rst +26 -4
- package/sphinx-build/source/getting_started.rst +762 -74
- package/sphinx-build/source/index.rst +13 -0
- package/sphinx-build/source/reference.rst +48 -0
- package/sphinx-build/source/troubleshooting.rst +77 -12
- package/src/Constants.ts +6 -0
- package/src/api/AuditExport.ts +90 -0
- package/src/api/AuditLog.ts +102 -0
- package/src/api/EconomicActivity.ts +69 -0
- package/src/api/Factor.ts +17 -1
- package/src/api/PhysicalActivity.ts +92 -0
- package/src/api/RealEstate.ts +25 -1
- package/src/api/TypeRecommender.ts +19 -2
- package/src/index.ts +15 -1
- package/src/interfaces/Api.ts +22 -6
- package/src/interfaces/Config.ts +6 -1
- package/src/interfaces/common.ts +46 -0
- package/src/interfaces/response/AuditExportResponse.ts +88 -0
- package/src/interfaces/response/AuditLogResponse.ts +47 -0
- package/src/interfaces/response/TypeRecommenderResponse.ts +3 -0
- package/src/request.ts +1 -0
- package/test/apiTest.test.ts +59 -3
- package/test/auditExport.test.ts +68 -0
- package/test/auditLog.test.ts +216 -0
- package/test/mocks/AttributionRequest.ts +23 -0
- package/test/mocks/EconomicActivityAttributionRequest.ts +22 -0
- package/test/mocks/PhysicalActivityEVICRequest.ts +22 -0
- package/test/mocks/PhysicalActivityRequest.ts +23 -0
- package/docs/_static/base-stemmer.js +0 -476
- package/docs/_static/english-stemmer.js +0 -1066
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { getAuditConfig, updateAuditConfig } from '../src/api/AuditLog';
|
|
3
|
+
import { Client } from '../src/Client';
|
|
4
|
+
import * as request from '../src/request';
|
|
5
|
+
|
|
6
|
+
jest.mock('../src/request');
|
|
7
|
+
jest.mock('../src/Client');
|
|
8
|
+
|
|
9
|
+
describe('AuditLog - Error Handling', () => {
|
|
10
|
+
let mockClient: jest.Mocked<Client>;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
jest.clearAllMocks();
|
|
14
|
+
|
|
15
|
+
mockClient = {
|
|
16
|
+
getDomain: jest.fn().mockReturnValue('https://dev.api.ibm.com/ghgemissions/test/'),
|
|
17
|
+
refreshToken: jest.fn().mockResolvedValue(undefined),
|
|
18
|
+
getAuthHeader: jest.fn().mockReturnValue({ Authorization: 'Bearer mock-token' }),
|
|
19
|
+
getClientId: jest.fn().mockReturnValue('test-client-id'),
|
|
20
|
+
getClientSource: jest.fn().mockReturnValue('node-sdk'),
|
|
21
|
+
} as any;
|
|
22
|
+
|
|
23
|
+
(Client.getInstance as jest.Mock).mockReturnValue(mockClient);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should handle 409 Conflict gracefully when configuration is unchanged', async () => {
|
|
27
|
+
const mockError = {
|
|
28
|
+
isAxiosError: true,
|
|
29
|
+
response: {
|
|
30
|
+
status: 409,
|
|
31
|
+
statusText: 'Conflict',
|
|
32
|
+
data: {
|
|
33
|
+
logRequest: true,
|
|
34
|
+
logResponse: false,
|
|
35
|
+
message: 'No change in audit log configuration'
|
|
36
|
+
},
|
|
37
|
+
headers: {},
|
|
38
|
+
config: {}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Mock makeApiRequest to throw a 409 error
|
|
43
|
+
(request.makeApiRequest as jest.Mock).mockRejectedValue(mockError);
|
|
44
|
+
|
|
45
|
+
const payload = { logRequest: true, logResponse: false };
|
|
46
|
+
const result = await updateAuditConfig(payload);
|
|
47
|
+
|
|
48
|
+
expect(result).toEqual({
|
|
49
|
+
logRequest: true,
|
|
50
|
+
logResponse: false,
|
|
51
|
+
message: 'No change in audit log configuration'
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should throw error for non-409 status codes', async () => {
|
|
56
|
+
const mockError = {
|
|
57
|
+
isAxiosError: true,
|
|
58
|
+
response: {
|
|
59
|
+
status: 500,
|
|
60
|
+
statusText: 'Internal Server Error',
|
|
61
|
+
data: { message: 'Server error' },
|
|
62
|
+
headers: {},
|
|
63
|
+
config: {}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
(request.makeApiRequest as jest.Mock).mockRejectedValue(mockError);
|
|
68
|
+
|
|
69
|
+
const payload = { logRequest: true, logResponse: false };
|
|
70
|
+
|
|
71
|
+
await expect(updateAuditConfig(payload)).rejects.toEqual(mockError);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should return updated configuration on successful update', async () => {
|
|
75
|
+
const mockResponse = {
|
|
76
|
+
logRequest: false,
|
|
77
|
+
logResponse: true,
|
|
78
|
+
message: 'Audit log configuration updated successfully'
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
(request.makeApiRequest as jest.Mock).mockResolvedValue(mockResponse);
|
|
82
|
+
|
|
83
|
+
const payload = { logRequest: false, logResponse: true };
|
|
84
|
+
const result = await updateAuditConfig(payload);
|
|
85
|
+
|
|
86
|
+
expect(result).toEqual(mockResponse);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should throw error for non-Axios errors', async () => {
|
|
90
|
+
const mockError = new Error('Network error');
|
|
91
|
+
|
|
92
|
+
(request.makeApiRequest as jest.Mock).mockRejectedValue(mockError);
|
|
93
|
+
|
|
94
|
+
const payload = { logRequest: true, logResponse: false };
|
|
95
|
+
|
|
96
|
+
await expect(updateAuditConfig(payload)).rejects.toThrow('Network error');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('should handle 400 Bad Request with error message from API', async () => {
|
|
100
|
+
const mockError = {
|
|
101
|
+
isAxiosError: true,
|
|
102
|
+
response: {
|
|
103
|
+
status: 400,
|
|
104
|
+
statusText: 'Bad Request',
|
|
105
|
+
data: {
|
|
106
|
+
message: 'Invalid payload: logRequest must be a boolean'
|
|
107
|
+
},
|
|
108
|
+
headers: {},
|
|
109
|
+
config: {}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
(request.makeApiRequest as jest.Mock).mockRejectedValue(mockError);
|
|
114
|
+
|
|
115
|
+
const payload = { logRequest: true, logResponse: false };
|
|
116
|
+
|
|
117
|
+
await expect(updateAuditConfig(payload)).rejects.toThrow('Invalid payload: logRequest must be a boolean');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should handle 403 Forbidden with error message from API', async () => {
|
|
121
|
+
const mockError = {
|
|
122
|
+
isAxiosError: true,
|
|
123
|
+
response: {
|
|
124
|
+
status: 403,
|
|
125
|
+
statusText: 'Forbidden',
|
|
126
|
+
data: {
|
|
127
|
+
message: 'User not authorized to make the request. Please contact the organisation administrator.'
|
|
128
|
+
},
|
|
129
|
+
headers: {},
|
|
130
|
+
config: {}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
(request.makeApiRequest as jest.Mock).mockRejectedValue(mockError);
|
|
135
|
+
|
|
136
|
+
const payload = { logRequest: true, logResponse: false };
|
|
137
|
+
|
|
138
|
+
await expect(updateAuditConfig(payload)).rejects.toThrow('User not authorized to make the request. Please contact the organisation administrator.');
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
describe('AuditLog - getAuditConfig Error Handling', () => {
|
|
143
|
+
let mockClient: jest.Mocked<Client>;
|
|
144
|
+
|
|
145
|
+
beforeEach(() => {
|
|
146
|
+
jest.clearAllMocks();
|
|
147
|
+
|
|
148
|
+
mockClient = {
|
|
149
|
+
getDomain: jest.fn().mockReturnValue('https://dev.api.ibm.com/ghgemissions/test/'),
|
|
150
|
+
refreshToken: jest.fn().mockResolvedValue(undefined),
|
|
151
|
+
getAuthHeader: jest.fn().mockReturnValue({ Authorization: 'Bearer mock-token' }),
|
|
152
|
+
getClientId: jest.fn().mockReturnValue('test-client-id'),
|
|
153
|
+
getClientSource: jest.fn().mockReturnValue('node-sdk'),
|
|
154
|
+
} as any;
|
|
155
|
+
|
|
156
|
+
(Client.getInstance as jest.Mock).mockReturnValue(mockClient);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('should return audit config on successful request', async () => {
|
|
160
|
+
const mockResponse = {
|
|
161
|
+
logRequest: true,
|
|
162
|
+
logResponse: false,
|
|
163
|
+
message: 'Current audit log configuration'
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
(request.makeApiRequest as jest.Mock).mockResolvedValue(mockResponse);
|
|
167
|
+
|
|
168
|
+
const result = await getAuditConfig();
|
|
169
|
+
|
|
170
|
+
expect(result).toEqual(mockResponse);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('should handle 403 Forbidden with error message from API', async () => {
|
|
174
|
+
const mockError = {
|
|
175
|
+
isAxiosError: true,
|
|
176
|
+
response: {
|
|
177
|
+
status: 403,
|
|
178
|
+
statusText: 'Forbidden',
|
|
179
|
+
data: {
|
|
180
|
+
message: 'User not authorized to make the request. Please contact the organisation administrator.'
|
|
181
|
+
},
|
|
182
|
+
headers: {},
|
|
183
|
+
config: {}
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
(request.makeApiRequest as jest.Mock).mockRejectedValue(mockError);
|
|
188
|
+
|
|
189
|
+
await expect(getAuditConfig()).rejects.toThrow('User not authorized to make the request. Please contact the organisation administrator.');
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('should throw error for other status codes', async () => {
|
|
193
|
+
const mockError = {
|
|
194
|
+
isAxiosError: true,
|
|
195
|
+
response: {
|
|
196
|
+
status: 500,
|
|
197
|
+
statusText: 'Internal Server Error',
|
|
198
|
+
data: { message: 'Server error' },
|
|
199
|
+
headers: {},
|
|
200
|
+
config: {}
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
(request.makeApiRequest as jest.Mock).mockRejectedValue(mockError);
|
|
205
|
+
|
|
206
|
+
await expect(getAuditConfig()).rejects.toEqual(mockError);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('should throw error for non-Axios errors', async () => {
|
|
210
|
+
const mockError = new Error('Network error');
|
|
211
|
+
|
|
212
|
+
(request.makeApiRequest as jest.Mock).mockRejectedValue(mockError);
|
|
213
|
+
|
|
214
|
+
await expect(getAuditConfig()).rejects.toThrow('Network error');
|
|
215
|
+
});
|
|
216
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CommonRequest } from '../../src/interfaces/Api';
|
|
2
|
+
|
|
3
|
+
const attributionPayload: CommonRequest = {
|
|
4
|
+
time: {
|
|
5
|
+
date: '2022-01-01',
|
|
6
|
+
},
|
|
7
|
+
location: {
|
|
8
|
+
country: 'usa',
|
|
9
|
+
stateProvince: 'new york',
|
|
10
|
+
},
|
|
11
|
+
activity: {
|
|
12
|
+
type: 'Commercial Real Estate:Office',
|
|
13
|
+
value: 123456.0,
|
|
14
|
+
unit: 'm2',
|
|
15
|
+
},
|
|
16
|
+
attribution: {
|
|
17
|
+
outstandingAmount: 1000000.0,
|
|
18
|
+
propertyValue: 5000000.0,
|
|
19
|
+
},
|
|
20
|
+
includeDetails: true,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default attributionPayload;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CommonRequest } from '../../src/interfaces/Api';
|
|
2
|
+
|
|
3
|
+
const economicActivityAttributionPayload: CommonRequest = {
|
|
4
|
+
time: {
|
|
5
|
+
date: '2025-01-04',
|
|
6
|
+
},
|
|
7
|
+
location: {
|
|
8
|
+
country: 'usa',
|
|
9
|
+
},
|
|
10
|
+
activity: {
|
|
11
|
+
type: 'accomodation',
|
|
12
|
+
value: 1500.12,
|
|
13
|
+
unit: 'usd',
|
|
14
|
+
},
|
|
15
|
+
attribution: {
|
|
16
|
+
outstandingAmount: 500000.0,
|
|
17
|
+
revenue: 2000000.0,
|
|
18
|
+
},
|
|
19
|
+
includeDetails: true,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default economicActivityAttributionPayload;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CommonRequest } from '../../src/interfaces/Api';
|
|
2
|
+
|
|
3
|
+
const physicalActivityEVICPayload: CommonRequest = {
|
|
4
|
+
time: {
|
|
5
|
+
date: '2025-01-23',
|
|
6
|
+
},
|
|
7
|
+
location: {
|
|
8
|
+
country: 'usa',
|
|
9
|
+
},
|
|
10
|
+
activity: {
|
|
11
|
+
type: 'commercial real estate',
|
|
12
|
+
value: 0.1,
|
|
13
|
+
unit: 'km2',
|
|
14
|
+
},
|
|
15
|
+
attribution: {
|
|
16
|
+
outstandingAmount: 1000000.0,
|
|
17
|
+
evic: 10000000.0,
|
|
18
|
+
},
|
|
19
|
+
includeDetails: true,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default physicalActivityEVICPayload;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CommonRequest } from '../../src/interfaces/Api';
|
|
2
|
+
|
|
3
|
+
const physicalActivityPayload: CommonRequest = {
|
|
4
|
+
time: {
|
|
5
|
+
date: '2025-01-23',
|
|
6
|
+
},
|
|
7
|
+
location: {
|
|
8
|
+
country: 'usa',
|
|
9
|
+
},
|
|
10
|
+
activity: {
|
|
11
|
+
type: 'commercial real estate',
|
|
12
|
+
value: 0.1,
|
|
13
|
+
unit: 'km2',
|
|
14
|
+
},
|
|
15
|
+
attribution: {
|
|
16
|
+
outstandingAmount: 1000000,
|
|
17
|
+
totalEquity: 3000000,
|
|
18
|
+
totalDebt: 2000000,
|
|
19
|
+
},
|
|
20
|
+
includeDetails: true,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default physicalActivityPayload;
|