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