testit-js-commons 3.7.9 → 4.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.
Files changed (45) hide show
  1. package/lib/common/types/config.type.d.ts +8 -0
  2. package/lib/common/utils/index.d.ts +1 -0
  3. package/lib/common/utils/index.js +1 -0
  4. package/lib/common/utils/tms-load-test-run-debug.d.ts +3 -0
  5. package/lib/common/utils/tms-load-test-run-debug.js +20 -0
  6. package/lib/helpers/config/config.helper.js +14 -6
  7. package/lib/helpers/config/config.helper.test.d.ts +1 -0
  8. package/lib/helpers/config/config.helper.test.js +40 -0
  9. package/lib/services/attachments/attachments.service.js +89 -22
  10. package/lib/services/index.d.ts +1 -0
  11. package/lib/services/index.js +1 -0
  12. package/lib/services/syncstorage/index.d.ts +2 -0
  13. package/lib/services/syncstorage/index.js +18 -0
  14. package/lib/services/syncstorage/syncstorage.runner.d.ts +49 -0
  15. package/lib/services/syncstorage/syncstorage.runner.js +350 -0
  16. package/lib/services/syncstorage/syncstorage.runner.test.d.ts +1 -0
  17. package/lib/services/syncstorage/syncstorage.runner.test.js +78 -0
  18. package/lib/services/syncstorage/syncstorage.type.d.ts +21 -0
  19. package/lib/services/syncstorage/syncstorage.type.js +19 -0
  20. package/lib/services/testruns/testruns.converter.d.ts +2 -0
  21. package/lib/services/testruns/testruns.converter.js +3 -0
  22. package/lib/services/testruns/testruns.service.d.ts +2 -0
  23. package/lib/services/testruns/testruns.service.js +62 -1
  24. package/lib/services/testruns/testruns.type.d.ts +2 -0
  25. package/lib/strategy/base.strategy.d.ts +4 -0
  26. package/lib/strategy/base.strategy.js +97 -2
  27. package/lib/sync-storage/dist/ApiClient.js +655 -0
  28. package/lib/sync-storage/dist/api/CompletionApi.js +114 -0
  29. package/lib/sync-storage/dist/api/HealthApi.js +69 -0
  30. package/lib/sync-storage/dist/api/SystemApi.js +69 -0
  31. package/lib/sync-storage/dist/api/TestResultsApi.js +122 -0
  32. package/lib/sync-storage/dist/api/WorkersApi.js +113 -0
  33. package/lib/sync-storage/dist/index.js +118 -0
  34. package/lib/sync-storage/dist/model/CompletionResponse.js +86 -0
  35. package/lib/sync-storage/dist/model/HealthStatusResponse.js +86 -0
  36. package/lib/sync-storage/dist/model/InProgressPublishedResponse.js +74 -0
  37. package/lib/sync-storage/dist/model/RegisterRequest.js +114 -0
  38. package/lib/sync-storage/dist/model/RegisterResponse.js +122 -0
  39. package/lib/sync-storage/dist/model/SetWorkerStatusRequest.js +102 -0
  40. package/lib/sync-storage/dist/model/SetWorkerStatusResponse.js +90 -0
  41. package/lib/sync-storage/dist/model/ShutdownResponse.js +90 -0
  42. package/lib/sync-storage/dist/model/TestResultCutApiModel.js +122 -0
  43. package/lib/sync-storage/dist/model/TestResultSaveResponse.js +90 -0
  44. package/lib/sync-storage/index.d.ts +772 -0
  45. package/package.json +7 -4
@@ -0,0 +1,655 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _superagent = _interopRequireDefault(require("superagent"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ /**
10
+ * Sync Storage Service API
11
+ * This is a sync storage service for coordinating test workers.
12
+ *
13
+ * The version of the OpenAPI document: 1.0
14
+ *
15
+ *
16
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
17
+ * https://openapi-generator.tech
18
+ * Do not edit the class manually.
19
+ *
20
+ */
21
+
22
+ /**
23
+ * @module ApiClient
24
+ * @version 0.1.0
25
+ */
26
+
27
+ /**
28
+ * Manages low level client-server communications, parameter marshalling, etc. There should not be any need for an
29
+ * application to use this class directly - the *Api and model classes provide the public API for the service. The
30
+ * contents of this file should be regarded as internal but are documented for completeness.
31
+ * @alias module:ApiClient
32
+ * @class
33
+ */
34
+ class ApiClient {
35
+ /**
36
+ * The base URL against which to resolve every API call's (relative) path.
37
+ * Overrides the default value set in spec file if present
38
+ * @param {String} basePath
39
+ */
40
+ constructor(basePath = 'http://localhost') {
41
+ /**
42
+ * The base URL against which to resolve every API call's (relative) path.
43
+ * @type {String}
44
+ * @default http://localhost
45
+ */
46
+ this.basePath = basePath.replace(/\/+$/, '');
47
+
48
+ /**
49
+ * The authentication methods to be included for all API calls.
50
+ * @type {Array.<String>}
51
+ */
52
+ this.authentications = {};
53
+
54
+ /**
55
+ * The default HTTP headers to be included for all API calls.
56
+ * @type {Array.<String>}
57
+ * @default {}
58
+ */
59
+ this.defaultHeaders = {
60
+ 'User-Agent': 'OpenAPI-Generator/0.1.0/Javascript'
61
+ };
62
+
63
+ /**
64
+ * The default HTTP timeout for all API calls.
65
+ * @type {Number}
66
+ * @default 60000
67
+ */
68
+ this.timeout = 60000;
69
+
70
+ /**
71
+ * If set to false an additional timestamp parameter is added to all API GET calls to
72
+ * prevent browser caching
73
+ * @type {Boolean}
74
+ * @default true
75
+ */
76
+ this.cache = true;
77
+
78
+ /**
79
+ * If set to true, the client will save the cookies from each server
80
+ * response, and return them in the next request.
81
+ * @default false
82
+ */
83
+ this.enableCookies = false;
84
+
85
+ /*
86
+ * Used to save and return cookies in a node.js (non-browser) setting,
87
+ * if this.enableCookies is set to true.
88
+ */
89
+ if (typeof window === 'undefined') {
90
+ this.agent = new _superagent.default.agent();
91
+ }
92
+
93
+ /*
94
+ * Allow user to override superagent agent
95
+ */
96
+ this.requestAgent = null;
97
+
98
+ /*
99
+ * Allow user to add superagent plugins
100
+ */
101
+ this.plugins = null;
102
+ }
103
+
104
+ /**
105
+ * Returns a string representation for an actual parameter.
106
+ * @param param The actual parameter.
107
+ * @returns {String} The string representation of <code>param</code>.
108
+ */
109
+ paramToString(param) {
110
+ if (param == undefined || param == null) {
111
+ return '';
112
+ }
113
+ if (param instanceof Date) {
114
+ return param.toJSON();
115
+ }
116
+ if (ApiClient.canBeJsonified(param)) {
117
+ return JSON.stringify(param);
118
+ }
119
+ return param.toString();
120
+ }
121
+
122
+ /**
123
+ * Returns a boolean indicating if the parameter could be JSON.stringified
124
+ * @param param The actual parameter
125
+ * @returns {Boolean} Flag indicating if <code>param</code> can be JSON.stringified
126
+ */
127
+ static canBeJsonified(str) {
128
+ if (typeof str !== 'string' && typeof str !== 'object') return false;
129
+ try {
130
+ const type = str.toString();
131
+ return type === '[object Object]' || type === '[object Array]';
132
+ } catch (err) {
133
+ return false;
134
+ }
135
+ }
136
+ /**
137
+ * Builds full URL by appending the given path to the base URL and replacing path parameter place-holders with parameter values.
138
+ * NOTE: query parameters are not handled here.
139
+ * @param {String} path The path to append to the base URL.
140
+ * @param {Object} pathParams The parameter values to append.
141
+ * @param {String} apiBasePath Base path defined in the path, operation level to override the default one
142
+ * @returns {String} The encoded path with parameter values substituted.
143
+ */
144
+ buildUrl(path, pathParams, apiBasePath) {
145
+ if (!path.match(/^\//)) {
146
+ path = '/' + path;
147
+ }
148
+ var url = this.basePath + path;
149
+
150
+ // use API (operation, path) base path if defined
151
+ if (apiBasePath !== null && apiBasePath !== undefined) {
152
+ url = apiBasePath + path;
153
+ }
154
+ url = url.replace(/\{([\w-\.#]+)\}/g, (fullMatch, key) => {
155
+ var value;
156
+ if (pathParams.hasOwnProperty(key)) {
157
+ value = this.paramToString(pathParams[key]);
158
+ } else {
159
+ value = fullMatch;
160
+ }
161
+ return encodeURIComponent(value);
162
+ });
163
+ return url;
164
+ }
165
+
166
+ /**
167
+ * Checks whether the given content type represents JSON.<br>
168
+ * JSON content type examples:<br>
169
+ * <ul>
170
+ * <li>application/json</li>
171
+ * <li>application/json; charset=UTF8</li>
172
+ * <li>APPLICATION/JSON</li>
173
+ * </ul>
174
+ * @param {String} contentType The MIME content type to check.
175
+ * @returns {Boolean} <code>true</code> if <code>contentType</code> represents JSON, otherwise <code>false</code>.
176
+ */
177
+ isJsonMime(contentType) {
178
+ return Boolean(contentType != null && contentType.match(/^application\/json(;.*)?$/i));
179
+ }
180
+
181
+ /**
182
+ * Chooses a content type from the given array, with JSON preferred; i.e. return JSON if included, otherwise return the first.
183
+ * @param {Array.<String>} contentTypes
184
+ * @returns {String} The chosen content type, preferring JSON.
185
+ */
186
+ jsonPreferredMime(contentTypes) {
187
+ for (var i = 0; i < contentTypes.length; i++) {
188
+ if (this.isJsonMime(contentTypes[i])) {
189
+ return contentTypes[i];
190
+ }
191
+ }
192
+ return contentTypes[0];
193
+ }
194
+
195
+ /**
196
+ * Checks whether the given parameter value represents file-like content.
197
+ * @param param The parameter to check.
198
+ * @returns {Boolean} <code>true</code> if <code>param</code> represents a file.
199
+ */
200
+ isFileParam(param) {
201
+ // fs.ReadStream in Node.js and Electron (but not in runtime like browserify)
202
+ if (typeof require === 'function') {
203
+ let fs;
204
+ try {
205
+ fs = require('fs');
206
+ } catch (err) {}
207
+ if (fs && fs.ReadStream && param instanceof fs.ReadStream) {
208
+ return true;
209
+ }
210
+ }
211
+
212
+ // Buffer in Node.js
213
+ if (typeof Buffer === 'function' && param instanceof Buffer) {
214
+ return true;
215
+ }
216
+
217
+ // Blob in browser
218
+ if (typeof Blob === 'function' && param instanceof Blob) {
219
+ return true;
220
+ }
221
+
222
+ // File in browser (it seems File object is also instance of Blob, but keep this for safe)
223
+ if (typeof File === 'function' && param instanceof File) {
224
+ return true;
225
+ }
226
+ return false;
227
+ }
228
+
229
+ /**
230
+ * Normalizes parameter values:
231
+ * <ul>
232
+ * <li>remove nils</li>
233
+ * <li>keep files and arrays</li>
234
+ * <li>format to string with `paramToString` for other cases</li>
235
+ * </ul>
236
+ * @param {Object.<String, Object>} params The parameters as object properties.
237
+ * @returns {Object.<String, Object>} normalized parameters.
238
+ */
239
+ normalizeParams(params) {
240
+ var newParams = {};
241
+ for (var key in params) {
242
+ if (params.hasOwnProperty(key) && params[key] != undefined && params[key] != null) {
243
+ var value = params[key];
244
+ if (this.isFileParam(value) || Array.isArray(value)) {
245
+ newParams[key] = value;
246
+ } else {
247
+ newParams[key] = this.paramToString(value);
248
+ }
249
+ }
250
+ }
251
+ return newParams;
252
+ }
253
+
254
+ /**
255
+ * Builds a string representation of an array-type actual parameter, according to the given collection format.
256
+ * @param {Array} param An array parameter.
257
+ * @param {module:ApiClient.CollectionFormatEnum} collectionFormat The array element separator strategy.
258
+ * @returns {String|Array} A string representation of the supplied collection, using the specified delimiter. Returns
259
+ * <code>param</code> as is if <code>collectionFormat</code> is <code>multi</code>.
260
+ */
261
+ buildCollectionParam(param, collectionFormat) {
262
+ if (param == null) {
263
+ return null;
264
+ }
265
+ switch (collectionFormat) {
266
+ case 'csv':
267
+ return param.map(this.paramToString, this).join(',');
268
+ case 'ssv':
269
+ return param.map(this.paramToString, this).join(' ');
270
+ case 'tsv':
271
+ return param.map(this.paramToString, this).join('\t');
272
+ case 'pipes':
273
+ return param.map(this.paramToString, this).join('|');
274
+ case 'multi':
275
+ //return the array directly as SuperAgent will handle it as expected
276
+ return param.map(this.paramToString, this);
277
+ case 'passthrough':
278
+ return param;
279
+ default:
280
+ throw new Error('Unknown collection format: ' + collectionFormat);
281
+ }
282
+ }
283
+
284
+ /**
285
+ * Applies authentication headers to the request.
286
+ * @param {Object} request The request object created by a <code>superagent()</code> call.
287
+ * @param {Array.<String>} authNames An array of authentication method names.
288
+ */
289
+ applyAuthToRequest(request, authNames) {
290
+ authNames.forEach(authName => {
291
+ var auth = this.authentications[authName];
292
+ switch (auth.type) {
293
+ case 'basic':
294
+ if (auth.username || auth.password) {
295
+ request.auth(auth.username || '', auth.password || '');
296
+ }
297
+ break;
298
+ case 'bearer':
299
+ if (auth.accessToken) {
300
+ var localVarBearerToken = typeof auth.accessToken === 'function' ? auth.accessToken() : auth.accessToken;
301
+ request.set({
302
+ 'Authorization': 'Bearer ' + localVarBearerToken
303
+ });
304
+ }
305
+ break;
306
+ case 'apiKey':
307
+ if (auth.apiKey) {
308
+ var data = {};
309
+ if (auth.apiKeyPrefix) {
310
+ data[auth.name] = auth.apiKeyPrefix + ' ' + auth.apiKey;
311
+ } else {
312
+ data[auth.name] = auth.apiKey;
313
+ }
314
+ if (auth['in'] === 'header') {
315
+ request.set(data);
316
+ } else {
317
+ request.query(data);
318
+ }
319
+ }
320
+ break;
321
+ case 'oauth2':
322
+ if (auth.accessToken) {
323
+ request.set({
324
+ 'Authorization': 'Bearer ' + auth.accessToken
325
+ });
326
+ }
327
+ break;
328
+ default:
329
+ throw new Error('Unknown authentication type: ' + auth.type);
330
+ }
331
+ });
332
+ }
333
+
334
+ /**
335
+ * Deserializes an HTTP response body into a value of the specified type.
336
+ * @param {Object} response A SuperAgent response object.
337
+ * @param {(String|Array.<String>|Object.<String, Object>|Function)} returnType The type to return. Pass a string for simple types
338
+ * or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To
339
+ * return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type:
340
+ * all properties on <code>data<code> will be converted to this type.
341
+ * @returns A value of the specified type.
342
+ */
343
+ deserialize(response, returnType) {
344
+ if (response == null || returnType == null || response.status == 204) {
345
+ return null;
346
+ }
347
+
348
+ // Rely on SuperAgent for parsing response body.
349
+ // See http://visionmedia.github.io/superagent/#parsing-response-bodies
350
+ var data = response.body;
351
+ if (data == null || typeof data === 'object' && typeof data.length === 'undefined' && !Object.keys(data).length) {
352
+ // SuperAgent does not always produce a body; use the unparsed response as a fallback
353
+ data = response.text;
354
+ }
355
+ return ApiClient.convertToType(data, returnType);
356
+ }
357
+
358
+ /**
359
+ * Invokes the REST service using the supplied settings and parameters.
360
+ * @param {String} path The base URL to invoke.
361
+ * @param {String} httpMethod The HTTP method to use.
362
+ * @param {Object.<String, String>} pathParams A map of path parameters and their values.
363
+ * @param {Object.<String, Object>} queryParams A map of query parameters and their values.
364
+ * @param {Object.<String, Object>} headerParams A map of header parameters and their values.
365
+ * @param {Object.<String, Object>} formParams A map of form parameters and their values.
366
+ * @param {Object} bodyParam The value to pass as the request body.
367
+ * @param {Array.<String>} authNames An array of authentication type names.
368
+ * @param {Array.<String>} contentTypes An array of request MIME types.
369
+ * @param {Array.<String>} accepts An array of acceptable response MIME types.
370
+ * @param {(String|Array|ObjectFunction)} returnType The required type to return; can be a string for simple types or the
371
+ * constructor for a complex type.
372
+ * @param {String} apiBasePath base path defined in the operation/path level to override the default one
373
+ * @returns {Promise} A {@link https://www.promisejs.org/|Promise} object.
374
+ */
375
+ callApi(path, httpMethod, pathParams, queryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts, returnType, apiBasePath) {
376
+ var url = this.buildUrl(path, pathParams, apiBasePath);
377
+ var request = (0, _superagent.default)(httpMethod, url);
378
+ if (this.plugins !== null) {
379
+ for (var index in this.plugins) {
380
+ if (this.plugins.hasOwnProperty(index)) {
381
+ request.use(this.plugins[index]);
382
+ }
383
+ }
384
+ }
385
+
386
+ // apply authentications
387
+ this.applyAuthToRequest(request, authNames);
388
+
389
+ // set query parameters
390
+ if (httpMethod.toUpperCase() === 'GET' && this.cache === false) {
391
+ queryParams['_'] = new Date().getTime();
392
+ }
393
+ request.query(this.normalizeParams(queryParams));
394
+
395
+ // set header parameters
396
+ request.set(this.defaultHeaders).set(this.normalizeParams(headerParams));
397
+
398
+ // set requestAgent if it is set by user
399
+ if (this.requestAgent) {
400
+ request.agent(this.requestAgent);
401
+ }
402
+
403
+ // set request timeout
404
+ request.timeout(this.timeout);
405
+ var contentType = this.jsonPreferredMime(contentTypes);
406
+ if (contentType) {
407
+ // Issue with superagent and multipart/form-data (https://github.com/visionmedia/superagent/issues/746)
408
+ if (contentType != 'multipart/form-data') {
409
+ request.type(contentType);
410
+ }
411
+ }
412
+ if (contentType === 'application/x-www-form-urlencoded') {
413
+ let normalizedParams = this.normalizeParams(formParams);
414
+ let urlSearchParams = new URLSearchParams(normalizedParams);
415
+ let queryString = urlSearchParams.toString();
416
+ request.send(queryString);
417
+ } else if (contentType == 'multipart/form-data') {
418
+ var _formParams = this.normalizeParams(formParams);
419
+ for (var key in _formParams) {
420
+ if (_formParams.hasOwnProperty(key)) {
421
+ let _formParamsValue = _formParams[key];
422
+ if (this.isFileParam(_formParamsValue)) {
423
+ // file field
424
+ request.attach(key, _formParamsValue);
425
+ } else if (Array.isArray(_formParamsValue) && _formParamsValue.length && this.isFileParam(_formParamsValue[0])) {
426
+ // multiple files
427
+ _formParamsValue.forEach(file => request.attach(key, file));
428
+ } else {
429
+ request.field(key, _formParamsValue);
430
+ }
431
+ }
432
+ }
433
+ } else if (bodyParam !== null && bodyParam !== undefined) {
434
+ if (!request.header['Content-Type']) {
435
+ request.type('application/json');
436
+ }
437
+ request.send(bodyParam);
438
+ }
439
+ var accept = this.jsonPreferredMime(accepts);
440
+ if (accept) {
441
+ request.accept(accept);
442
+ }
443
+ if (returnType === 'Blob') {
444
+ request.responseType('blob');
445
+ } else if (returnType === 'String') {
446
+ request.responseType('text');
447
+ }
448
+
449
+ // Attach previously saved cookies, if enabled
450
+ if (this.enableCookies) {
451
+ if (typeof window === 'undefined') {
452
+ this.agent._attachCookies(request);
453
+ } else {
454
+ request.withCredentials();
455
+ }
456
+ }
457
+ return new Promise((resolve, reject) => {
458
+ request.end((error, response) => {
459
+ if (error) {
460
+ var err = {};
461
+ if (response) {
462
+ err.status = response.status;
463
+ err.statusText = response.statusText;
464
+ err.body = response.body;
465
+ err.response = response;
466
+ }
467
+ err.error = error;
468
+ reject(err);
469
+ } else {
470
+ try {
471
+ var data = this.deserialize(response, returnType);
472
+ if (this.enableCookies && typeof window === 'undefined') {
473
+ this.agent._saveCookies(response);
474
+ }
475
+ resolve({
476
+ data,
477
+ response
478
+ });
479
+ } catch (err) {
480
+ reject(err);
481
+ }
482
+ }
483
+ });
484
+ });
485
+ }
486
+
487
+ /**
488
+ * Parses an ISO-8601 string representation or epoch representation of a date value.
489
+ * @param {String} str The date value as a string.
490
+ * @returns {Date} The parsed date object.
491
+ */
492
+ static parseDate(str) {
493
+ if (isNaN(str)) {
494
+ return new Date(str.replace(/(\d)(T)(\d)/i, '$1 $3'));
495
+ }
496
+ return new Date(+str);
497
+ }
498
+
499
+ /**
500
+ * Converts a value to the specified type.
501
+ * @param {(String|Object)} data The data to convert, as a string or object.
502
+ * @param {(String|Array.<String>|Object.<String, Object>|Function)} type The type to return. Pass a string for simple types
503
+ * or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To
504
+ * return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type:
505
+ * all properties on <code>data<code> will be converted to this type.
506
+ * @returns An instance of the specified type or null or undefined if data is null or undefined.
507
+ */
508
+ static convertToType(data, type) {
509
+ if (data === null || data === undefined) return data;
510
+ switch (type) {
511
+ case 'Boolean':
512
+ return Boolean(data);
513
+ case 'Integer':
514
+ return parseInt(data, 10);
515
+ case 'Number':
516
+ return parseFloat(data);
517
+ case 'String':
518
+ return String(data);
519
+ case 'Date':
520
+ return ApiClient.parseDate(String(data));
521
+ case 'Blob':
522
+ return data;
523
+ default:
524
+ if (type === Object) {
525
+ // generic object, return directly
526
+ return data;
527
+ } else if (typeof type.constructFromObject === 'function') {
528
+ // for model type like User and enum class
529
+ return type.constructFromObject(data);
530
+ } else if (Array.isArray(type)) {
531
+ // for array type like: ['String']
532
+ var itemType = type[0];
533
+ return data.map(item => {
534
+ return ApiClient.convertToType(item, itemType);
535
+ });
536
+ } else if (typeof type === 'object') {
537
+ // for plain object type like: {'String': 'Integer'}
538
+ var keyType, valueType;
539
+ for (var k in type) {
540
+ if (type.hasOwnProperty(k)) {
541
+ keyType = k;
542
+ valueType = type[k];
543
+ break;
544
+ }
545
+ }
546
+ var result = {};
547
+ for (var k in data) {
548
+ if (data.hasOwnProperty(k)) {
549
+ var key = ApiClient.convertToType(k, keyType);
550
+ var value = ApiClient.convertToType(data[k], valueType);
551
+ result[key] = value;
552
+ }
553
+ }
554
+ return result;
555
+ } else {
556
+ // for unknown type, return the data directly
557
+ return data;
558
+ }
559
+ }
560
+ }
561
+
562
+ /**
563
+ * Gets an array of host settings
564
+ * @returns An array of host settings
565
+ */
566
+ hostSettings() {
567
+ return [{
568
+ 'url': "",
569
+ 'description': "Default Server URL"
570
+ }];
571
+ }
572
+ getBasePathFromSettings(index, variables = {}) {
573
+ var servers = this.hostSettings();
574
+
575
+ // check array index out of bound
576
+ if (index < 0 || index >= servers.length) {
577
+ throw new Error("Invalid index " + index + " when selecting the host settings. Must be less than " + servers.length);
578
+ }
579
+ var server = servers[index];
580
+ var url = server['url'];
581
+
582
+ // go through variable and assign a value
583
+ for (var variable_name in server['variables']) {
584
+ if (variable_name in variables) {
585
+ let variable = server['variables'][variable_name];
586
+ if (!('enum_values' in variable) || variable['enum_values'].includes(variables[variable_name])) {
587
+ url = url.replace("{" + variable_name + "}", variables[variable_name]);
588
+ } else {
589
+ throw new Error("The variable `" + variable_name + "` in the host URL has invalid value " + variables[variable_name] + ". Must be " + server['variables'][variable_name]['enum_values'] + ".");
590
+ }
591
+ } else {
592
+ // use default value
593
+ url = url.replace("{" + variable_name + "}", server['variables'][variable_name]['default_value']);
594
+ }
595
+ }
596
+ return url;
597
+ }
598
+
599
+ /**
600
+ * Constructs a new map or array model from REST data.
601
+ * @param data {Object|Array} The REST data.
602
+ * @param obj {Object|Array} The target object or array.
603
+ */
604
+ static constructFromObject(data, obj, itemType) {
605
+ if (Array.isArray(data)) {
606
+ for (var i = 0; i < data.length; i++) {
607
+ if (data.hasOwnProperty(i)) obj[i] = ApiClient.convertToType(data[i], itemType);
608
+ }
609
+ } else {
610
+ for (var k in data) {
611
+ if (data.hasOwnProperty(k)) obj[k] = ApiClient.convertToType(data[k], itemType);
612
+ }
613
+ }
614
+ }
615
+ }
616
+
617
+ /**
618
+ * Enumeration of collection format separator strategies.
619
+ * @enum {String}
620
+ * @readonly
621
+ */
622
+ ApiClient.CollectionFormatEnum = {
623
+ /**
624
+ * Comma-separated values. Value: <code>csv</code>
625
+ * @const
626
+ */
627
+ CSV: ',',
628
+ /**
629
+ * Space-separated values. Value: <code>ssv</code>
630
+ * @const
631
+ */
632
+ SSV: ' ',
633
+ /**
634
+ * Tab-separated values. Value: <code>tsv</code>
635
+ * @const
636
+ */
637
+ TSV: '\t',
638
+ /**
639
+ * Pipe(|)-separated values. Value: <code>pipes</code>
640
+ * @const
641
+ */
642
+ PIPES: '|',
643
+ /**
644
+ * Native array. Value: <code>multi</code>
645
+ * @const
646
+ */
647
+ MULTI: 'multi'
648
+ };
649
+
650
+ /**
651
+ * The default API client implementation.
652
+ * @type {module:ApiClient}
653
+ */
654
+ ApiClient.instance = new ApiClient();
655
+ var _default = exports.default = ApiClient;