@polyguard/sdk 1.4.2 → 1.5.1

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