purecloud-platform-client-v2 209.0.0 → 211.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/README.md +52 -3
- package/dist/node/purecloud-platform-client-v2.js +773 -155
- package/dist/web-amd/purecloud-platform-client-v2.js +773 -156
- package/dist/web-amd/purecloud-platform-client-v2.min.js +1 -1
- package/dist/web-cjs/bundle.js +295 -181
- package/dist/web-cjs/purecloud-platform-client-v2.js +6697 -534
- package/dist/web-cjs/purecloud-platform-client-v2.min.js +1 -1
- package/index.d.ts +937 -702
- package/package.json +1 -1
- package/src/purecloud-platform-client-v2/AbstractHttpClient.js +26 -0
- package/src/purecloud-platform-client-v2/ApiClient.js +136 -57
- package/src/purecloud-platform-client-v2/DefaultHttpClient.js +48 -0
- package/src/purecloud-platform-client-v2/HttpRequestOptions.js +65 -0
- package/src/purecloud-platform-client-v2/api/AgentAssistantsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/AgentCopilotApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/AgentUIApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/AlertingApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/AnalyticsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/ArchitectApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/AuditApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/AuthorizationApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/BillingApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/CarrierServicesApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/ChatApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/CoachingApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/ContentManagementApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/ConversationsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/DataExtensionsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/DataPrivacyApi.js +175 -0
- package/src/purecloud-platform-client-v2/api/DownloadsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/EmailsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/EmployeeEngagementApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/EventsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/ExternalContactsApi.js +240 -1
- package/src/purecloud-platform-client-v2/api/FaxApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/FlowsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/GamificationApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/GeneralDataProtectionRegulationApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/GeolocationApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/GreetingsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/GroupsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/IdentityProviderApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/InfrastructureAsCodeApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/IntegrationsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/JourneyApi.js +9 -9
- package/src/purecloud-platform-client-v2/api/KnowledgeApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/LanguageUnderstandingApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/LanguagesApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/LearningApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/LicenseApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/LocationsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/LogCaptureApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/MessagingApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/MobileDevicesApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/NotificationsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/OAuthApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/ObjectsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/OperationalEventsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/OrganizationApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/OrganizationAuthorizationApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/OutboundApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/PresenceApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/ProcessAutomationApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/QualityApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/RecordingApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/ResponseManagementApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/RoutingApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/SCIMApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/ScreenRecordingApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/ScriptsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/SearchApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/SettingsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/SocialMediaApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/SpeechTextAnalyticsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/StationsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/SuggestApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/TaskManagementApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/TeamsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/TelephonyApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/TelephonyProvidersEdgeApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/TextbotsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/TokensApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/UploadsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/UsageApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/UserRecordingsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/UsersApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/UtilitiesApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/VoicemailApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/WebChatApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/WebDeploymentsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/WebMessagingApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/WidgetsApi.js +1 -1
- package/src/purecloud-platform-client-v2/api/WorkforceManagementApi.js +5 -13
- package/src/purecloud-platform-client-v2/configuration.js +2 -0
- package/src/purecloud-platform-client-v2/index.js +7 -1
package/package.json
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
class AbstractHttpClient {
|
|
2
|
+
|
|
3
|
+
constructor() {
|
|
4
|
+
this.timeout = 16000;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
setTimeout(timeout) {
|
|
8
|
+
if (timeout === null || timeout === undefined || typeof timeout !== 'number') {
|
|
9
|
+
throw new Error("The 'timeout' property must be a number");
|
|
10
|
+
}
|
|
11
|
+
this.timeout = timeout;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
setHttpsAgent(httpsAgent) {
|
|
15
|
+
if (httpsAgent && typeof httpsAgent !== 'object') {
|
|
16
|
+
throw new Error("The 'httpsAgent' property must be an object");
|
|
17
|
+
}
|
|
18
|
+
this.httpsAgent = httpsAgent;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
request(httpRequestOptions) {
|
|
22
|
+
throw new Error("method must be implemented");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default AbstractHttpClient;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { default as axios } from 'axios';
|
|
2
1
|
import Configuration from './configuration.js';
|
|
2
|
+
import https from 'https';
|
|
3
|
+
import DefaultHttpClient from './DefaultHttpClient.js';
|
|
4
|
+
import AbstractHttpClient from './AbstractHttpClient.js';
|
|
5
|
+
import HttpRequestOptions from './HttpRequestOptions.js';
|
|
3
6
|
import { default as qs } from 'qs';
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* @module purecloud-platform-client-v2/ApiClient
|
|
7
|
-
* @version
|
|
10
|
+
* @version 211.0.0
|
|
8
11
|
*/
|
|
9
12
|
class ApiClient {
|
|
10
13
|
/**
|
|
@@ -109,6 +112,9 @@ class ApiClient {
|
|
|
109
112
|
// Transparently request a new access token when it expires (Code Authorization only)
|
|
110
113
|
this.refreshInProgress = false;
|
|
111
114
|
|
|
115
|
+
this.httpClient;
|
|
116
|
+
this.proxyAgent;
|
|
117
|
+
|
|
112
118
|
this.config = new Configuration();
|
|
113
119
|
|
|
114
120
|
if (typeof(window) !== 'undefined') window.ApiClient = this;
|
|
@@ -202,6 +208,87 @@ class ApiClient {
|
|
|
202
208
|
this.config.setEnvironment(environment);
|
|
203
209
|
}
|
|
204
210
|
|
|
211
|
+
/**
|
|
212
|
+
* @description Sets the dynamic HttpClient used by the client
|
|
213
|
+
* @param {object} httpClient - HttpClient to be injected
|
|
214
|
+
*/
|
|
215
|
+
setHttpClient(httpClient) {
|
|
216
|
+
if (!(httpClient instanceof AbstractHttpClient)) {
|
|
217
|
+
throw new Error("httpclient must be an instance of AbstractHttpClient. See DefaultltHttpClient for a prototype");
|
|
218
|
+
}
|
|
219
|
+
this.httpClient = httpClient;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* @description Gets the HttpClient used by the client
|
|
224
|
+
*/
|
|
225
|
+
getHttpClient() {
|
|
226
|
+
if (this.httpClient) {
|
|
227
|
+
return this.httpClient;
|
|
228
|
+
} else {
|
|
229
|
+
this.httpClient = new DefaultHttpClient(this.timeout, this.proxyAgent);
|
|
230
|
+
return this.httpClient;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* @description Sets the certificate paths if MTLS authentication is needed
|
|
236
|
+
* @param {string} certPath - path for certs
|
|
237
|
+
* @param {string} keyPath - path for key
|
|
238
|
+
* @param {string} caPath - path for public certs
|
|
239
|
+
*/
|
|
240
|
+
setMTLSCertificates(certPath, keyPath, caPath) {
|
|
241
|
+
if (typeof window === 'undefined') {
|
|
242
|
+
const agentOptions = {}
|
|
243
|
+
if (certPath) {
|
|
244
|
+
agentOptions.cert = require('fs').readFileSync(certPath);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (keyPath) {
|
|
248
|
+
agentOptions.key = require('fs').readFileSync(keyPath);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (caPath) {
|
|
252
|
+
agentOptions.ca = require('fs').readFileSync(caPath);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
agentOptions.rejectUnauthorized = true
|
|
256
|
+
|
|
257
|
+
this.proxyAgent = new https.Agent(agentOptions);
|
|
258
|
+
const httpClient = this.getHttpClient();
|
|
259
|
+
httpClient.setHttpsAgent(this.proxyAgent);
|
|
260
|
+
} else {
|
|
261
|
+
throw new Error("Custom Agent Paths/ File System Access are not supported on Browser. Use setMTLSContents instead");
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* @description Sets the certificate content if MTLS authentication is needed
|
|
267
|
+
* @param {string} certContent - content for certs
|
|
268
|
+
* @param {string} keyContent - content for key
|
|
269
|
+
* @param {string} caContent - content for public certs
|
|
270
|
+
*/
|
|
271
|
+
setMTLSContents(certContent, keyContent, caContent) {
|
|
272
|
+
const agentOptions = {}
|
|
273
|
+
if (certContent) {
|
|
274
|
+
agentOptions.cert = certContent;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (keyContent) {
|
|
278
|
+
agentOptions.key = keyContent;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (caContent) {
|
|
282
|
+
agentOptions.ca = caContent;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
agentOptions.rejectUnauthorized = true
|
|
286
|
+
|
|
287
|
+
this.proxyAgent = new https.Agent(agentOptions);
|
|
288
|
+
const httpClient = this.getHttpClient();
|
|
289
|
+
httpClient.setHttpsAgent(this.proxyAgent);
|
|
290
|
+
}
|
|
291
|
+
|
|
205
292
|
/**
|
|
206
293
|
* @description Sets the gateway used by the session
|
|
207
294
|
* @param {object} gateway - Gateway Configuration interface
|
|
@@ -292,14 +379,11 @@ class ApiClient {
|
|
|
292
379
|
const headers = {
|
|
293
380
|
'Authorization': `Basic ${authHeader}`
|
|
294
381
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
httpsAgent: this.proxyAgent
|
|
301
|
-
})
|
|
302
|
-
.then((response) => {
|
|
382
|
+
|
|
383
|
+
var requestOptions = new HttpRequestOptions(`${loginBasePath}/oauth/token`, `POST`, headers, null, 'grant_type=client_credentials', this.timeout);
|
|
384
|
+
const httpClient = this.getHttpClient();
|
|
385
|
+
httpClient.request(requestOptions)
|
|
386
|
+
.then((response) => {
|
|
303
387
|
// Logging
|
|
304
388
|
this.config.logger.log(
|
|
305
389
|
'trace',
|
|
@@ -443,20 +527,18 @@ class ApiClient {
|
|
|
443
527
|
this.clientId = clientId;
|
|
444
528
|
var loginBasePath = this.config.getConfUrl('login', `https://login.${this.config.environment}`);
|
|
445
529
|
return new Promise((resolve, reject) => {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
});
|
|
530
|
+
var headers = {
|
|
531
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
532
|
+
};
|
|
533
|
+
var data = qs.stringify({ grant_type: 'authorization_code',
|
|
534
|
+
code: authCode,
|
|
535
|
+
code_verifier: codeVerifier,
|
|
536
|
+
client_id: clientId,
|
|
537
|
+
redirect_uri: redirectUri });
|
|
538
|
+
|
|
539
|
+
var requestOptions = new HttpRequestOptions(`${loginBasePath}/oauth/token`, `POST`, headers, null, data, this.timeout);
|
|
540
|
+
const httpClient = this.getHttpClient();
|
|
458
541
|
|
|
459
|
-
request.proxy = this.proxy;
|
|
460
542
|
var bodyParam = {
|
|
461
543
|
grant_type: 'authorization_code',
|
|
462
544
|
code: authCode,
|
|
@@ -465,7 +547,7 @@ class ApiClient {
|
|
|
465
547
|
redirect_uri: redirectUri,
|
|
466
548
|
};
|
|
467
549
|
// Handle response
|
|
468
|
-
request
|
|
550
|
+
httpClient.request(requestOptions)
|
|
469
551
|
.then((response) => {
|
|
470
552
|
// Logging
|
|
471
553
|
this.config.logger.log(
|
|
@@ -473,7 +555,7 @@ class ApiClient {
|
|
|
473
555
|
response.status,
|
|
474
556
|
'POST',
|
|
475
557
|
`${loginBasePath}/oauth/token`,
|
|
476
|
-
|
|
558
|
+
requestOptions.headers,
|
|
477
559
|
response.headers,
|
|
478
560
|
bodyParam,
|
|
479
561
|
undefined
|
|
@@ -483,7 +565,7 @@ class ApiClient {
|
|
|
483
565
|
response.status,
|
|
484
566
|
'POST',
|
|
485
567
|
`${loginBasePath}/oauth/token`,
|
|
486
|
-
|
|
568
|
+
requestOptions.headers,
|
|
487
569
|
undefined,
|
|
488
570
|
bodyParam,
|
|
489
571
|
undefined
|
|
@@ -507,7 +589,7 @@ class ApiClient {
|
|
|
507
589
|
error.response.status,
|
|
508
590
|
'POST',
|
|
509
591
|
`${loginBasePath}/oauth/token`,
|
|
510
|
-
|
|
592
|
+
requestOptions.headers,
|
|
511
593
|
error.response.headers,
|
|
512
594
|
bodyParam,
|
|
513
595
|
error.response.data
|
|
@@ -647,7 +729,7 @@ class ApiClient {
|
|
|
647
729
|
this._testTokenAccess()
|
|
648
730
|
.then(() => {
|
|
649
731
|
if (!this.authData.state && query.state)
|
|
650
|
-
this.authData.state = query.state;
|
|
732
|
+
this.authData.state = query.state;
|
|
651
733
|
// remove codeVerifier from session storage
|
|
652
734
|
if (this.hasLocalStorage) {
|
|
653
735
|
sessionStorage.removeItem(`genesys_cloud_sdk_pkce_code_verifier`);
|
|
@@ -894,17 +976,13 @@ class ApiClient {
|
|
|
894
976
|
*/
|
|
895
977
|
_formAuthRequest(encodedData, data) {
|
|
896
978
|
var loginBasePath = this.config.getConfUrl('login', `https://login.${this.config.environment}`);
|
|
897
|
-
var
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
data: qs.stringify(data)
|
|
905
|
-
});
|
|
906
|
-
|
|
907
|
-
return request;
|
|
979
|
+
var headers = {
|
|
980
|
+
'Authorization': 'Basic ' + encodedData,
|
|
981
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
982
|
+
};
|
|
983
|
+
var requestOptions = new HttpRequestOptions(loginBasePath, `POST`, headers, null, qs.stringify(data), this.timeout);
|
|
984
|
+
const httpClient = this.getHttpClient();
|
|
985
|
+
return httpClient.request(requestOptions);
|
|
908
986
|
}
|
|
909
987
|
|
|
910
988
|
/**
|
|
@@ -1299,15 +1377,15 @@ class ApiClient {
|
|
|
1299
1377
|
data[auth.name] = auth.apiKey;
|
|
1300
1378
|
}
|
|
1301
1379
|
if (auth['in'] === 'header') {
|
|
1302
|
-
request.headers =
|
|
1380
|
+
request.headers = this.addHeaders(request.headers, data);
|
|
1303
1381
|
} else {
|
|
1304
|
-
request.
|
|
1382
|
+
request.setParams(this.serialize(data));
|
|
1305
1383
|
}
|
|
1306
1384
|
}
|
|
1307
1385
|
break;
|
|
1308
1386
|
case 'oauth2':
|
|
1309
1387
|
if (auth.accessToken) {
|
|
1310
|
-
request.headers =
|
|
1388
|
+
request.headers = this.addHeaders(request.headers, {'Authorization': `Bearer ${auth.accessToken}`});
|
|
1311
1389
|
}
|
|
1312
1390
|
break;
|
|
1313
1391
|
default:
|
|
@@ -1317,13 +1395,18 @@ class ApiClient {
|
|
|
1317
1395
|
}
|
|
1318
1396
|
|
|
1319
1397
|
/**
|
|
1320
|
-
* @description Sets the proxy agent axios will use for requests
|
|
1398
|
+
* @description Sets the proxy agent axios will use for requests
|
|
1321
1399
|
* @param {any} agent - The proxy agent
|
|
1322
1400
|
*/
|
|
1323
1401
|
setProxyAgent(agent) {
|
|
1324
|
-
this.proxyAgent = agent
|
|
1402
|
+
this.proxyAgent = agent;
|
|
1403
|
+
const httpClient = this.getHttpClient();
|
|
1404
|
+
httpClient.setHttpsAgent(this.proxyAgent);
|
|
1325
1405
|
}
|
|
1326
1406
|
|
|
1407
|
+
|
|
1408
|
+
|
|
1409
|
+
|
|
1327
1410
|
/**
|
|
1328
1411
|
* Invokes the REST service using the supplied settings and parameters.
|
|
1329
1412
|
* @param {String} path The base URL to invoke.
|
|
@@ -1344,13 +1427,7 @@ class ApiClient {
|
|
|
1344
1427
|
sendRequest(this);
|
|
1345
1428
|
function sendRequest(that) {
|
|
1346
1429
|
var url = that.buildUrl(path, pathParams);
|
|
1347
|
-
|
|
1348
|
-
method: httpMethod,
|
|
1349
|
-
url: url,
|
|
1350
|
-
httpsAgent: that.proxyAgent,
|
|
1351
|
-
timeout: that.timeout,
|
|
1352
|
-
params: that.serialize(queryParams)
|
|
1353
|
-
};
|
|
1430
|
+
var request = new HttpRequestOptions(url, httpMethod, null, that.serialize(queryParams), null, that.timeout);
|
|
1354
1431
|
|
|
1355
1432
|
// apply authentications
|
|
1356
1433
|
that.applyAuthToRequest(request, authNames);
|
|
@@ -1368,7 +1445,7 @@ class ApiClient {
|
|
|
1368
1445
|
}
|
|
1369
1446
|
|
|
1370
1447
|
if (contentType === 'application/x-www-form-urlencoded') {
|
|
1371
|
-
request.
|
|
1448
|
+
request.setData(that.normalizeParams(formParams));
|
|
1372
1449
|
} else if (contentType == 'multipart/form-data') {
|
|
1373
1450
|
var _formParams = that.normalizeParams(formParams);
|
|
1374
1451
|
for (var key in _formParams) {
|
|
@@ -1376,18 +1453,20 @@ class ApiClient {
|
|
|
1376
1453
|
// Looks like axios handles files and forms the same way
|
|
1377
1454
|
var formData = new FormData();
|
|
1378
1455
|
formData.set(key, _formParams[key]);
|
|
1379
|
-
request.
|
|
1456
|
+
request.setData(formData);
|
|
1380
1457
|
}
|
|
1381
1458
|
}
|
|
1382
1459
|
} else if (bodyParam) {
|
|
1383
|
-
request.
|
|
1460
|
+
request.setData(bodyParam);
|
|
1384
1461
|
}
|
|
1385
1462
|
|
|
1386
1463
|
var accept = that.jsonPreferredMime(accepts);
|
|
1387
1464
|
if (accept) {
|
|
1388
1465
|
request.headers['Accept'] = accept;
|
|
1389
1466
|
}
|
|
1390
|
-
|
|
1467
|
+
|
|
1468
|
+
const httpClient = that.getHttpClient();
|
|
1469
|
+
httpClient.request(request)
|
|
1391
1470
|
.then((response) => {
|
|
1392
1471
|
// Build response object
|
|
1393
1472
|
var data = (that.returnExtended === true) ? {
|
|
@@ -1408,8 +1487,8 @@ class ApiClient {
|
|
|
1408
1487
|
})
|
|
1409
1488
|
.catch((error) => {
|
|
1410
1489
|
var data = error
|
|
1411
|
-
if (error.response && error.response.status == 401 && that.config.refresh_access_token && that.authData.refreshToken !== "") {
|
|
1412
|
-
|
|
1490
|
+
if (error.response && error.response.status == 401 && that.config.refresh_access_token && that.authData.refreshToken && that.authData.refreshToken !== "") {
|
|
1491
|
+
that._handleExpiredAccessToken()
|
|
1413
1492
|
.then(() => {
|
|
1414
1493
|
sendRequest(that);
|
|
1415
1494
|
})
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { default as axios } from 'axios';
|
|
2
|
+
import AbstractHttpClient from './AbstractHttpClient.js';
|
|
3
|
+
import HttpRequestOptions from './HttpRequestOptions.js';
|
|
4
|
+
|
|
5
|
+
// Default client is Axios
|
|
6
|
+
class DefaultHttpClient extends AbstractHttpClient{
|
|
7
|
+
|
|
8
|
+
constructor(timeout, httpsAgent) {
|
|
9
|
+
super();
|
|
10
|
+
if (timeout !== null && timeout !== undefined) this.setTimeout(timeout);
|
|
11
|
+
else this.timeout = 16000;
|
|
12
|
+
if (httpsAgent !== null && httpsAgent !== undefined) this.setHttpsAgent(httpsAgent);
|
|
13
|
+
else this.httpsAgent;
|
|
14
|
+
this._axiosInstance = axios.create({});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
request(httpRequestOptions) {
|
|
18
|
+
if(!(httpRequestOptions instanceof HttpRequestOptions)) {
|
|
19
|
+
throw new Error(`httpRequestOptions must be instance of HttpRequestOptions `);
|
|
20
|
+
}
|
|
21
|
+
const config = this.toAxiosConfig(httpRequestOptions)
|
|
22
|
+
return this._axiosInstance.request(config);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Method to generate Axios-compatible config
|
|
26
|
+
toAxiosConfig(httpRequestOptions) {
|
|
27
|
+
if (!httpRequestOptions.url || !httpRequestOptions.method) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
"Mandatory fields 'url' and 'method' must be set before making a request"
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var config = {
|
|
34
|
+
url: httpRequestOptions.url,
|
|
35
|
+
method: httpRequestOptions.method
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
if (httpRequestOptions.params) config.params = httpRequestOptions.params;
|
|
39
|
+
if (httpRequestOptions.headers) config.headers = httpRequestOptions.headers;
|
|
40
|
+
if(httpRequestOptions.data) config.data = httpRequestOptions.data;
|
|
41
|
+
if (this.timeout != null && this.timeout != undefined) config.timeout = this.timeout;
|
|
42
|
+
if (this.httpsAgent) config.httpsAgent = this.httpsAgent
|
|
43
|
+
|
|
44
|
+
return config;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default DefaultHttpClient;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
class HttpRequestOptions {
|
|
2
|
+
|
|
3
|
+
constructor(url, method, headers, params, data, timeout) {
|
|
4
|
+
this.setUrl(url);
|
|
5
|
+
this.setMethod(method);
|
|
6
|
+
if (headers) {
|
|
7
|
+
this.setHeaders(headers);
|
|
8
|
+
}
|
|
9
|
+
if (params) {
|
|
10
|
+
this.setParams(params);
|
|
11
|
+
}
|
|
12
|
+
if (data) {
|
|
13
|
+
this.setData(data);
|
|
14
|
+
}
|
|
15
|
+
if (timeout !== null && timeout !== undefined) this.setTimeout(timeout);
|
|
16
|
+
else this.timeout = 16000;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Mandatory fields with validation
|
|
20
|
+
setUrl(url) {
|
|
21
|
+
if (!url) throw new Error("The 'url' property is required");
|
|
22
|
+
this.url = url;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
setMethod(method) {
|
|
26
|
+
const validMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'];
|
|
27
|
+
if (!method || !validMethods.includes(method.toUpperCase())) {
|
|
28
|
+
throw new Error("The 'method' property is invalid or missing");
|
|
29
|
+
}
|
|
30
|
+
this.method = method.toUpperCase();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
setData(data) {
|
|
34
|
+
if (data === undefined || data === null) {
|
|
35
|
+
throw new Error("The 'data' property is required");
|
|
36
|
+
}
|
|
37
|
+
this.data = data;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Optional fields
|
|
41
|
+
setParams(params) {
|
|
42
|
+
if (params && typeof params !== 'object') {
|
|
43
|
+
throw new Error("The 'params' property must be an object");
|
|
44
|
+
}
|
|
45
|
+
this.params = params;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Optional fields
|
|
49
|
+
setHeaders(headers) {
|
|
50
|
+
if (headers && typeof headers !== 'object') {
|
|
51
|
+
throw new Error("The 'headers' property must be an object");
|
|
52
|
+
}
|
|
53
|
+
this.headers = headers;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
setTimeout(timeout) {
|
|
57
|
+
if (timeout === undefined || timeout === null || typeof timeout !== 'number') {
|
|
58
|
+
throw new Error("The 'timeout' property must be a number");
|
|
59
|
+
}
|
|
60
|
+
this.timeout = timeout;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export default HttpRequestOptions;
|