testit-js-commons 4.2.0-TMS-5.8 → 5.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 (157) hide show
  1. package/lib/adapters-api/dist/ApiClient.js +683 -0
  2. package/lib/adapters-api/dist/api/AttachmentsApi.js +165 -0
  3. package/lib/adapters-api/dist/api/AutoTestsApi.js +536 -0
  4. package/lib/adapters-api/dist/api/ConfigurationsApi.js +91 -0
  5. package/lib/adapters-api/dist/api/ParametersApi.js +159 -0
  6. package/lib/adapters-api/dist/api/ProjectAttributesApi.js +140 -0
  7. package/lib/adapters-api/dist/api/ProjectSectionsApi.js +96 -0
  8. package/lib/adapters-api/dist/api/ProjectWorkItemsApi.js +99 -0
  9. package/lib/adapters-api/dist/api/ProjectsApi.js +200 -0
  10. package/lib/adapters-api/dist/api/SectionsApi.js +118 -0
  11. package/lib/adapters-api/dist/api/TestResultsApi.js +168 -0
  12. package/lib/adapters-api/dist/api/TestRunsApi.js +331 -0
  13. package/lib/adapters-api/dist/api/WorkItemsApi.js +170 -0
  14. package/lib/adapters-api/dist/api/WorkflowsApi.js +75 -0
  15. package/lib/adapters-api/dist/index.js +951 -0
  16. package/lib/adapters-api/dist/model/AssignAttachmentApiModel.js +89 -0
  17. package/lib/adapters-api/dist/model/AssignAutoTestCaseIdApiModel.js +89 -0
  18. package/lib/adapters-api/dist/model/AssignIterationApiModel.js +112 -0
  19. package/lib/adapters-api/dist/model/AttachmentApiResult.js +145 -0
  20. package/lib/adapters-api/dist/model/AttachmentModel.js +193 -0
  21. package/lib/adapters-api/dist/model/AttachmentPutModel.js +89 -0
  22. package/lib/adapters-api/dist/model/AttachmentPutModelAutoTestStepResultsModel.js +196 -0
  23. package/lib/adapters-api/dist/model/AttachmentUpdateRequest.js +89 -0
  24. package/lib/adapters-api/dist/model/AutoTest.js +327 -0
  25. package/lib/adapters-api/dist/model/AutoTestApiResult.js +323 -0
  26. package/lib/adapters-api/dist/model/AutoTestCaseApiModel.js +89 -0
  27. package/lib/adapters-api/dist/model/AutoTestCreateApiModel.js +323 -0
  28. package/lib/adapters-api/dist/model/AutoTestFilterApiModel.js +201 -0
  29. package/lib/adapters-api/dist/model/AutoTestIdModel.js +88 -0
  30. package/lib/adapters-api/dist/model/AutoTestModel.js +488 -0
  31. package/lib/adapters-api/dist/model/AutoTestResultReasonShort.js +99 -0
  32. package/lib/adapters-api/dist/model/AutoTestResultsForTestRunModel.js +334 -0
  33. package/lib/adapters-api/dist/model/AutoTestSearchApiModel.js +96 -0
  34. package/lib/adapters-api/dist/model/AutoTestSearchIncludeApiModel.js +93 -0
  35. package/lib/adapters-api/dist/model/AutoTestStep.js +123 -0
  36. package/lib/adapters-api/dist/model/AutoTestStepApiModel.js +123 -0
  37. package/lib/adapters-api/dist/model/AutoTestStepApiResult.js +123 -0
  38. package/lib/adapters-api/dist/model/AutoTestStepModel.js +123 -0
  39. package/lib/adapters-api/dist/model/AutoTestStepResult.js +196 -0
  40. package/lib/adapters-api/dist/model/AutoTestStepResultUpdateRequest.js +196 -0
  41. package/lib/adapters-api/dist/model/AutoTestUpdateApiModel.js +327 -0
  42. package/lib/adapters-api/dist/model/AutoTestWorkItemIdentifierApiResult.js +100 -0
  43. package/lib/adapters-api/dist/model/AvailableTestResultOutcome.js +67 -0
  44. package/lib/adapters-api/dist/model/ConfigurationFilterModel.js +114 -0
  45. package/lib/adapters-api/dist/model/ConfigurationModel.js +213 -0
  46. package/lib/adapters-api/dist/model/ConfigurationShortModel.js +102 -0
  47. package/lib/adapters-api/dist/model/CreateEmptyTestRunApiModel.js +185 -0
  48. package/lib/adapters-api/dist/model/CreateLinkApiModel.js +127 -0
  49. package/lib/adapters-api/dist/model/CreateParameterApiModel.js +117 -0
  50. package/lib/adapters-api/dist/model/CreateProjectApiModel.js +124 -0
  51. package/lib/adapters-api/dist/model/CreateStepApiModel.js +131 -0
  52. package/lib/adapters-api/dist/model/CreateWorkItemApiModel.js +384 -0
  53. package/lib/adapters-api/dist/model/CustomAttributeApiResult.js +184 -0
  54. package/lib/adapters-api/dist/model/CustomAttributeGetModel.js +184 -0
  55. package/lib/adapters-api/dist/model/CustomAttributeOptionApiResult.js +124 -0
  56. package/lib/adapters-api/dist/model/CustomAttributeOptionModel.js +124 -0
  57. package/lib/adapters-api/dist/model/CustomAttributePutModel.js +182 -0
  58. package/lib/adapters-api/dist/model/CustomAttributeType.js +73 -0
  59. package/lib/adapters-api/dist/model/CustomAttributeTypesEnum.js +73 -0
  60. package/lib/adapters-api/dist/model/DateTimeRangeSelectorModel.js +82 -0
  61. package/lib/adapters-api/dist/model/DeletionState.js +55 -0
  62. package/lib/adapters-api/dist/model/DetailedProjectApiResult.js +204 -0
  63. package/lib/adapters-api/dist/model/FailureCategoryModel.js +67 -0
  64. package/lib/adapters-api/dist/model/GuidExtractionModel.js +90 -0
  65. package/lib/adapters-api/dist/model/ImageResizeType.js +49 -0
  66. package/lib/adapters-api/dist/model/Int32RangeSelectorModel.js +82 -0
  67. package/lib/adapters-api/dist/model/Int64RangeSelectorModel.js +82 -0
  68. package/lib/adapters-api/dist/model/IterationApiResult.js +109 -0
  69. package/lib/adapters-api/dist/model/IterationModel.js +109 -0
  70. package/lib/adapters-api/dist/model/LabelApiModel.js +100 -0
  71. package/lib/adapters-api/dist/model/LabelApiResult.js +100 -0
  72. package/lib/adapters-api/dist/model/LabelShortModel.js +100 -0
  73. package/lib/adapters-api/dist/model/LinkApiResult.js +140 -0
  74. package/lib/adapters-api/dist/model/LinkCreateApiModel.js +127 -0
  75. package/lib/adapters-api/dist/model/LinkModel.js +149 -0
  76. package/lib/adapters-api/dist/model/LinkPostModel.js +137 -0
  77. package/lib/adapters-api/dist/model/LinkPutModel.js +149 -0
  78. package/lib/adapters-api/dist/model/LinkShortApiResult.js +126 -0
  79. package/lib/adapters-api/dist/model/LinkType.js +73 -0
  80. package/lib/adapters-api/dist/model/LinkUpdateApiModel.js +140 -0
  81. package/lib/adapters-api/dist/model/ManualRerunApiResult.js +84 -0
  82. package/lib/adapters-api/dist/model/ManualRerunSelectTestResultsApiModel.js +109 -0
  83. package/lib/adapters-api/dist/model/ManualRerunTestResultApiModel.js +81 -0
  84. package/lib/adapters-api/dist/model/Operation.js +110 -0
  85. package/lib/adapters-api/dist/model/ParameterApiResult.js +154 -0
  86. package/lib/adapters-api/dist/model/ParameterIterationModel.js +100 -0
  87. package/lib/adapters-api/dist/model/ParameterShortApiResult.js +132 -0
  88. package/lib/adapters-api/dist/model/ParameterShortModel.js +158 -0
  89. package/lib/adapters-api/dist/model/ParametersFilterApiModel.js +98 -0
  90. package/lib/adapters-api/dist/model/ProblemDetails.js +124 -0
  91. package/lib/adapters-api/dist/model/ProjectApiResult.js +165 -0
  92. package/lib/adapters-api/dist/model/ProjectAttributesFilterModel.js +132 -0
  93. package/lib/adapters-api/dist/model/ProjectTypeModel.js +49 -0
  94. package/lib/adapters-api/dist/model/ProjectsFilterModel.js +209 -0
  95. package/lib/adapters-api/dist/model/SectionModel.js +180 -0
  96. package/lib/adapters-api/dist/model/SectionPostModel.js +178 -0
  97. package/lib/adapters-api/dist/model/SectionWithStepsModel.js +242 -0
  98. package/lib/adapters-api/dist/model/SharedStepModel.js +145 -0
  99. package/lib/adapters-api/dist/model/SharedStepResultApiModel.js +102 -0
  100. package/lib/adapters-api/dist/model/StepCommentApiModel.js +207 -0
  101. package/lib/adapters-api/dist/model/StepModel.js +163 -0
  102. package/lib/adapters-api/dist/model/StepPostModel.js +126 -0
  103. package/lib/adapters-api/dist/model/StepResultApiModel.js +149 -0
  104. package/lib/adapters-api/dist/model/TagModel.js +88 -0
  105. package/lib/adapters-api/dist/model/TestResultLinkApiResult.js +153 -0
  106. package/lib/adapters-api/dist/model/TestResultOutcome.js +67 -0
  107. package/lib/adapters-api/dist/model/TestResultResponse.js +400 -0
  108. package/lib/adapters-api/dist/model/TestResultShortResponse.js +311 -0
  109. package/lib/adapters-api/dist/model/TestResultStepCommentUpdateRequest.js +152 -0
  110. package/lib/adapters-api/dist/model/TestResultUpdateRequest.js +285 -0
  111. package/lib/adapters-api/dist/model/TestResultsFilterApiModel.js +226 -0
  112. package/lib/adapters-api/dist/model/TestRunApiResult.js +196 -0
  113. package/lib/adapters-api/dist/model/TestRunState.js +61 -0
  114. package/lib/adapters-api/dist/model/TestStatusApiResult.js +114 -0
  115. package/lib/adapters-api/dist/model/TestStatusApiType.js +67 -0
  116. package/lib/adapters-api/dist/model/TestStatusModel.js +149 -0
  117. package/lib/adapters-api/dist/model/TestStatusType.js +67 -0
  118. package/lib/adapters-api/dist/model/UpdateEmptyTestRunApiModel.js +187 -0
  119. package/lib/adapters-api/dist/model/UpdateLinkApiModel.js +140 -0
  120. package/lib/adapters-api/dist/model/ValidationProblemDetails.js +144 -0
  121. package/lib/adapters-api/dist/model/WorkItemApiResult.js +499 -0
  122. package/lib/adapters-api/dist/model/WorkItemEntityTypeApiModel.js +55 -0
  123. package/lib/adapters-api/dist/model/WorkItemFilterApiModel.js +309 -0
  124. package/lib/adapters-api/dist/model/WorkItemIdApiModel.js +89 -0
  125. package/lib/adapters-api/dist/model/WorkItemParameterKeyApiModel.js +89 -0
  126. package/lib/adapters-api/dist/model/WorkItemParameterKeyApiResult.js +88 -0
  127. package/lib/adapters-api/dist/model/WorkItemPriorityApiModel.js +67 -0
  128. package/lib/adapters-api/dist/model/WorkItemPriorityModel.js +67 -0
  129. package/lib/adapters-api/dist/model/WorkItemSelectApiModel.js +90 -0
  130. package/lib/adapters-api/dist/model/WorkItemShortApiResult.js +316 -0
  131. package/lib/adapters-api/dist/model/WorkItemSourceTypeModel.js +49 -0
  132. package/lib/adapters-api/dist/model/WorkItemStateApiModel.js +55 -0
  133. package/lib/adapters-api/dist/model/WorkItemStates.js +55 -0
  134. package/lib/adapters-api/dist/model/WorkItemTypeModel.js +55 -0
  135. package/lib/adapters-api/dist/model/WorkflowApiResult.js +111 -0
  136. package/lib/adapters-api/dist/model/WorkflowStatusApiResult.js +114 -0
  137. package/lib/adapters-api/index.d.ts +8862 -0
  138. package/lib/common/base.converter.d.ts +16 -17
  139. package/lib/common/base.converter.js +12 -14
  140. package/lib/common/base.service.d.ts +1 -1
  141. package/lib/common/base.service.js +6 -36
  142. package/lib/services/attachments/attachments.service.d.ts +1 -2
  143. package/lib/services/attachments/attachments.service.js +7 -7
  144. package/lib/services/autotests/autotests.converter.d.ts +2 -3
  145. package/lib/services/autotests/autotests.converter.js +0 -5
  146. package/lib/services/autotests/autotests.service.d.ts +1 -2
  147. package/lib/services/autotests/autotests.service.js +11 -44
  148. package/lib/services/testresults/testresults.converter.d.ts +4 -5
  149. package/lib/services/testresults/testresults.converter.js +0 -15
  150. package/lib/services/testresults/testresults.service.d.ts +2 -3
  151. package/lib/services/testresults/testresults.service.js +16 -44
  152. package/lib/services/testresults/testresults.type.d.ts +1 -1
  153. package/lib/services/testruns/testruns.converter.d.ts +12 -13
  154. package/lib/services/testruns/testruns.converter.js +19 -8
  155. package/lib/services/testruns/testruns.service.d.ts +1 -2
  156. package/lib/services/testruns/testruns.service.js +13 -46
  157. package/package.json +7 -5
@@ -0,0 +1,683 @@
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
+ * API
11
+ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
12
+ *
13
+ * The version of the OpenAPI document: v2.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 ^7.0.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
+ 'PrivateToken': {
54
+ type: 'apiKey',
55
+ 'in': 'header',
56
+ name: 'Authorization'
57
+ },
58
+ 'Cookies': {
59
+ type: 'apiKey',
60
+ 'in': 'query',
61
+ name: 'session'
62
+ }
63
+ };
64
+
65
+ /**
66
+ * The default HTTP headers to be included for all API calls.
67
+ * @type {Array.<String>}
68
+ * @default {}
69
+ */
70
+ this.defaultHeaders = {
71
+ 'User-Agent': 'OpenAPI-Generator/^7.0.0/Javascript'
72
+ };
73
+
74
+ /**
75
+ * The default HTTP timeout for all API calls.
76
+ * @type {Number}
77
+ * @default 60000
78
+ */
79
+ this.timeout = 60000;
80
+
81
+ /**
82
+ * If set to false an additional timestamp parameter is added to all API GET calls to
83
+ * prevent browser caching
84
+ * @type {Boolean}
85
+ * @default true
86
+ */
87
+ this.cache = true;
88
+
89
+ /**
90
+ * If set to true, the client will save the cookies from each server
91
+ * response, and return them in the next request.
92
+ * @default false
93
+ */
94
+ this.enableCookies = false;
95
+
96
+ /*
97
+ * Used to save and return cookies in a node.js (non-browser) setting,
98
+ * if this.enableCookies is set to true.
99
+ */
100
+ if (typeof window === 'undefined') {
101
+ this.agent = new _superagent.default.agent();
102
+ }
103
+
104
+ /*
105
+ * Allow user to override superagent agent
106
+ */
107
+ this.requestAgent = null;
108
+
109
+ /*
110
+ * Allow user to add superagent plugins
111
+ */
112
+ this.plugins = null;
113
+ this.rejectUnauthorized = true;
114
+ }
115
+
116
+ /**
117
+ * Set SSL validation true / false
118
+ * @param value true by default
119
+ */
120
+ setUnauthorized(value) {
121
+ this.rejectUnauthorized = value;
122
+ }
123
+
124
+ /**
125
+ * Returns a string representation for an actual parameter.
126
+ * @param param The actual parameter.
127
+ * @returns {String} The string representation of <code>param</code>.
128
+ */
129
+ paramToString(param) {
130
+ if (param == undefined || param == null) {
131
+ return '';
132
+ }
133
+ if (param instanceof Date) {
134
+ return param.toJSON();
135
+ }
136
+ if (ApiClient.canBeJsonified(param)) {
137
+ return JSON.stringify(param);
138
+ }
139
+ return param.toString();
140
+ }
141
+
142
+ /**
143
+ * Returns a boolean indicating if the parameter could be JSON.stringified
144
+ * @param param The actual parameter
145
+ * @returns {Boolean} Flag indicating if <code>param</code> can be JSON.stringified
146
+ */
147
+ static canBeJsonified(str) {
148
+ if (typeof str !== 'string' && typeof str !== 'object') return false;
149
+ try {
150
+ const type = str.toString();
151
+ return type === '[object Object]' || type === '[object Array]';
152
+ } catch (err) {
153
+ return false;
154
+ }
155
+ }
156
+ /**
157
+ * Builds full URL by appending the given path to the base URL and replacing path parameter place-holders with parameter values.
158
+ * NOTE: query parameters are not handled here.
159
+ * @param {String} path The path to append to the base URL.
160
+ * @param {Object} pathParams The parameter values to append.
161
+ * @param {String} apiBasePath Base path defined in the path, operation level to override the default one
162
+ * @returns {String} The encoded path with parameter values substituted.
163
+ */
164
+ buildUrl(path, pathParams, apiBasePath) {
165
+ if (!path.match(/^\//)) {
166
+ path = '/' + path;
167
+ }
168
+ var url = this.basePath + path;
169
+
170
+ // use API (operation, path) base path if defined
171
+ if (apiBasePath !== null && apiBasePath !== undefined) {
172
+ url = apiBasePath + path;
173
+ }
174
+ url = url.replace(/\{([\w-\.#]+)\}/g, (fullMatch, key) => {
175
+ var value;
176
+ if (pathParams.hasOwnProperty(key)) {
177
+ value = this.paramToString(pathParams[key]);
178
+ } else {
179
+ value = fullMatch;
180
+ }
181
+ return encodeURIComponent(value);
182
+ });
183
+ return url;
184
+ }
185
+
186
+ /**
187
+ * Checks whether the given content type represents JSON.<br>
188
+ * JSON content type examples:<br>
189
+ * <ul>
190
+ * <li>application/json</li>
191
+ * <li>application/json; charset=UTF8</li>
192
+ * <li>APPLICATION/JSON</li>
193
+ * </ul>
194
+ * @param {String} contentType The MIME content type to check.
195
+ * @returns {Boolean} <code>true</code> if <code>contentType</code> represents JSON, otherwise <code>false</code>.
196
+ */
197
+ isJsonMime(contentType) {
198
+ return Boolean(contentType != null && contentType.match(/^application\/json(;.*)?$/i));
199
+ }
200
+
201
+ /**
202
+ * Chooses a content type from the given array, with JSON preferred; i.e. return JSON if included, otherwise return the first.
203
+ * @param {Array.<String>} contentTypes
204
+ * @returns {String} The chosen content type, preferring JSON.
205
+ */
206
+ jsonPreferredMime(contentTypes) {
207
+ for (var i = 0; i < contentTypes.length; i++) {
208
+ if (this.isJsonMime(contentTypes[i])) {
209
+ return contentTypes[i];
210
+ }
211
+ }
212
+ return contentTypes[0];
213
+ }
214
+
215
+ /**
216
+ * Checks whether the given parameter value represents file-like content.
217
+ * @param param The parameter to check.
218
+ * @returns {Boolean} <code>true</code> if <code>param</code> represents a file.
219
+ */
220
+ isFileParam(param) {
221
+ // fs.ReadStream in Node.js and Electron (but not in runtime like browserify)
222
+ if (typeof require === 'function') {
223
+ let fs;
224
+ try {
225
+ fs = require('fs');
226
+ } catch (err) {}
227
+ if (fs && fs.ReadStream && param instanceof fs.ReadStream) {
228
+ return true;
229
+ }
230
+ }
231
+
232
+ // Buffer in Node.js
233
+ if (typeof Buffer === 'function' && param instanceof Buffer) {
234
+ return true;
235
+ }
236
+
237
+ // Blob in browser
238
+ if (typeof Blob === 'function' && param instanceof Blob) {
239
+ return true;
240
+ }
241
+
242
+ // File in browser (it seems File object is also instance of Blob, but keep this for safe)
243
+ if (typeof File === 'function' && param instanceof File) {
244
+ return true;
245
+ }
246
+ return false;
247
+ }
248
+
249
+ /**
250
+ * Normalizes parameter values:
251
+ * <ul>
252
+ * <li>remove nils</li>
253
+ * <li>keep files and arrays</li>
254
+ * <li>format to string with `paramToString` for other cases</li>
255
+ * </ul>
256
+ * @param {Object.<String, Object>} params The parameters as object properties.
257
+ * @returns {Object.<String, Object>} normalized parameters.
258
+ */
259
+ normalizeParams(params) {
260
+ var newParams = {};
261
+ for (var key in params) {
262
+ if (params.hasOwnProperty(key) && params[key] != undefined && params[key] != null) {
263
+ var value = params[key];
264
+ if (this.isFileParam(value) || Array.isArray(value)) {
265
+ newParams[key] = value;
266
+ } else {
267
+ newParams[key] = this.paramToString(value);
268
+ }
269
+ }
270
+ }
271
+ return newParams;
272
+ }
273
+
274
+ /**
275
+ * Builds a string representation of an array-type actual parameter, according to the given collection format.
276
+ * @param {Array} param An array parameter.
277
+ * @param {module:ApiClient.CollectionFormatEnum} collectionFormat The array element separator strategy.
278
+ * @returns {String|Array} A string representation of the supplied collection, using the specified delimiter. Returns
279
+ * <code>param</code> as is if <code>collectionFormat</code> is <code>multi</code>.
280
+ */
281
+ buildCollectionParam(param, collectionFormat) {
282
+ if (param == null) {
283
+ return null;
284
+ }
285
+ switch (collectionFormat) {
286
+ case 'csv':
287
+ return param.map(this.paramToString, this).join(',');
288
+ case 'ssv':
289
+ return param.map(this.paramToString, this).join(' ');
290
+ case 'tsv':
291
+ return param.map(this.paramToString, this).join('\t');
292
+ case 'pipes':
293
+ return param.map(this.paramToString, this).join('|');
294
+ case 'multi':
295
+ //return the array directly as SuperAgent will handle it as expected
296
+ return param.map(this.paramToString, this);
297
+ case 'passthrough':
298
+ return param;
299
+ default:
300
+ throw new Error('Unknown collection format: ' + collectionFormat);
301
+ }
302
+ }
303
+
304
+ /**
305
+ * Applies authentication headers to the request.
306
+ * @param {Object} request The request object created by a <code>superagent()</code> call.
307
+ * @param {Array.<String>} authNames An array of authentication method names.
308
+ */
309
+ applyAuthToRequest(request, authNames) {
310
+ authNames.forEach(authName => {
311
+ var auth = this.authentications[authName];
312
+ switch (auth.type) {
313
+ case 'basic':
314
+ if (auth.username || auth.password) {
315
+ request.auth(auth.username || '', auth.password || '');
316
+ }
317
+ break;
318
+ case 'bearer':
319
+ if (auth.accessToken) {
320
+ var localVarBearerToken = typeof auth.accessToken === 'function' ? auth.accessToken() : auth.accessToken;
321
+ request.set({
322
+ 'Authorization': 'Bearer ' + localVarBearerToken
323
+ });
324
+ }
325
+ break;
326
+ case 'apiKey':
327
+ if (auth.apiKey) {
328
+ var data = {};
329
+ if (auth.apiKeyPrefix) {
330
+ data[auth.name] = auth.apiKeyPrefix + ' ' + auth.apiKey;
331
+ } else {
332
+ data[auth.name] = auth.apiKey;
333
+ }
334
+ if (auth['in'] === 'header') {
335
+ request.set(data);
336
+ } else {
337
+ request.query(data);
338
+ }
339
+ }
340
+ break;
341
+ case 'oauth2':
342
+ if (auth.accessToken) {
343
+ request.set({
344
+ 'Authorization': 'Bearer ' + auth.accessToken
345
+ });
346
+ }
347
+ break;
348
+ default:
349
+ throw new Error('Unknown authentication type: ' + auth.type);
350
+ }
351
+ });
352
+ }
353
+
354
+ /**
355
+ * Deserializes an HTTP response body into a value of the specified type.
356
+ * @param {Object} response A SuperAgent response object.
357
+ * @param {(String|Array.<String>|Object.<String, Object>|Function)} returnType The type to return. Pass a string for simple types
358
+ * or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To
359
+ * return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type:
360
+ * all properties on <code>data<code> will be converted to this type.
361
+ * @returns A value of the specified type.
362
+ */
363
+ deserialize(response, returnType) {
364
+ if (response == null || returnType == null || response.status == 204) {
365
+ return null;
366
+ }
367
+
368
+ // Rely on SuperAgent for parsing response body.
369
+ // See http://visionmedia.github.io/superagent/#parsing-response-bodies
370
+ var data = response.body;
371
+ if (data == null || typeof data === 'object' && typeof data.length === 'undefined' && !Object.keys(data).length) {
372
+ // SuperAgent does not always produce a body; use the unparsed response as a fallback
373
+ data = response.text;
374
+ }
375
+ return ApiClient.convertToType(data, returnType);
376
+ }
377
+
378
+ /**
379
+ * Invokes the REST service using the supplied settings and parameters.
380
+ * @param {String} path The base URL to invoke.
381
+ * @param {String} httpMethod The HTTP method to use.
382
+ * @param {Object.<String, String>} pathParams A map of path parameters and their values.
383
+ * @param {Object.<String, Object>} queryParams A map of query parameters and their values.
384
+ * @param {Object.<String, Object>} headerParams A map of header parameters and their values.
385
+ * @param {Object.<String, Object>} formParams A map of form parameters and their values.
386
+ * @param {Object} bodyParam The value to pass as the request body.
387
+ * @param {Array.<String>} authNames An array of authentication type names.
388
+ * @param {Array.<String>} contentTypes An array of request MIME types.
389
+ * @param {Array.<String>} accepts An array of acceptable response MIME types.
390
+ * @param {(String|Array|ObjectFunction)} returnType The required type to return; can be a string for simple types or the
391
+ * constructor for a complex type.
392
+ * @param {String} apiBasePath base path defined in the operation/path level to override the default one
393
+ * @returns {Promise} A {@link https://www.promisejs.org/|Promise} object.
394
+ */
395
+ callApi(path, httpMethod, pathParams, queryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts, returnType, apiBasePath) {
396
+ var url = this.buildUrl(path, pathParams, apiBasePath);
397
+ var request = (0, _superagent.default)(httpMethod, url);
398
+ if (this.plugins !== null) {
399
+ for (var index in this.plugins) {
400
+ if (this.plugins.hasOwnProperty(index)) {
401
+ request.use(this.plugins[index]);
402
+ }
403
+ }
404
+ }
405
+
406
+ // apply authentications
407
+ this.applyAuthToRequest(request, authNames);
408
+
409
+ // set query parameters
410
+ if (httpMethod.toUpperCase() === 'GET' && this.cache === false) {
411
+ queryParams['_'] = new Date().getTime();
412
+ }
413
+ request.query(this.normalizeParams(queryParams));
414
+
415
+ // set header parameters
416
+ request.set(this.defaultHeaders).set(this.normalizeParams(headerParams));
417
+
418
+ // set requestAgent if it is set by user
419
+ if (this.requestAgent) {
420
+ request.agent(this.requestAgent);
421
+ }
422
+
423
+ // set request timeout
424
+ request.timeout(this.timeout);
425
+ var contentType = this.jsonPreferredMime(contentTypes);
426
+ if (contentType) {
427
+ // Issue with superagent and multipart/form-data (https://github.com/visionmedia/superagent/issues/746)
428
+ if (contentType != 'multipart/form-data') {
429
+ request.type(contentType);
430
+ }
431
+ }
432
+ if (contentType === 'application/x-www-form-urlencoded') {
433
+ let normalizedParams = this.normalizeParams(formParams);
434
+ let urlSearchParams = new URLSearchParams(normalizedParams);
435
+ let queryString = urlSearchParams.toString();
436
+ if (this.rejectUnauthorized) {
437
+ request.disableTLSCerts().send(queryString);
438
+ } else {
439
+ request.send(queryString);
440
+ }
441
+ } else if (contentType == 'multipart/form-data') {
442
+ var _formParams = this.normalizeParams(formParams);
443
+ for (var key in _formParams) {
444
+ if (_formParams.hasOwnProperty(key)) {
445
+ let _formParamsValue = _formParams[key];
446
+ if (this.isFileParam(_formParamsValue)) {
447
+ // file field
448
+ request.attach(key, _formParamsValue);
449
+ } else if (Array.isArray(_formParamsValue) && _formParamsValue.length && this.isFileParam(_formParamsValue[0])) {
450
+ // multiple files
451
+ _formParamsValue.forEach(file => request.attach(key, file));
452
+ } else {
453
+ request.field(key, _formParamsValue);
454
+ }
455
+ }
456
+ }
457
+ } else if (bodyParam !== null && bodyParam !== undefined) {
458
+ if (!request.header['Content-Type']) {
459
+ request.type('application/json');
460
+ }
461
+ if (this.rejectUnauthorized) {
462
+ request.disableTLSCerts().send(bodyParam);
463
+ } else {
464
+ request.send(bodyParam);
465
+ }
466
+ }
467
+ var accept = this.jsonPreferredMime(accepts);
468
+ if (accept) {
469
+ request.accept(accept);
470
+ }
471
+ if (returnType === 'Blob') {
472
+ request.responseType('blob');
473
+ } else if (returnType === 'String') {
474
+ request.responseType('text');
475
+ }
476
+
477
+ // Attach previously saved cookies, if enabled
478
+ if (this.enableCookies) {
479
+ if (typeof window === 'undefined') {
480
+ this.agent._attachCookies(request);
481
+ } else {
482
+ request.withCredentials();
483
+ }
484
+ }
485
+ return new Promise((resolve, reject) => {
486
+ request.end((error, response) => {
487
+ if (error) {
488
+ var err = {};
489
+ if (response) {
490
+ err.status = response.status;
491
+ err.statusText = response.statusText;
492
+ err.body = response.body;
493
+ err.response = response;
494
+ }
495
+ err.error = error;
496
+ reject(err);
497
+ } else {
498
+ try {
499
+ var data = this.deserialize(response, returnType);
500
+ if (this.enableCookies && typeof window === 'undefined') {
501
+ this.agent._saveCookies(response);
502
+ }
503
+ resolve({
504
+ data,
505
+ response
506
+ });
507
+ } catch (err) {
508
+ reject(err);
509
+ }
510
+ }
511
+ });
512
+ });
513
+ }
514
+
515
+ /**
516
+ * Parses an ISO-8601 string representation or epoch representation of a date value.
517
+ * @param {String} str The date value as a string.
518
+ * @returns {Date} The parsed date object.
519
+ */
520
+ static parseDate(str) {
521
+ if (isNaN(str)) {
522
+ return new Date(str.replace(/(\d)(T)(\d)/i, '$1 $3'));
523
+ }
524
+ return new Date(+str);
525
+ }
526
+
527
+ /**
528
+ * Converts a value to the specified type.
529
+ * @param {(String|Object)} data The data to convert, as a string or object.
530
+ * @param {(String|Array.<String>|Object.<String, Object>|Function)} type The type to return. Pass a string for simple types
531
+ * or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To
532
+ * return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type:
533
+ * all properties on <code>data<code> will be converted to this type.
534
+ * @returns An instance of the specified type or null or undefined if data is null or undefined.
535
+ */
536
+ static convertToType(data, type) {
537
+ if (data === null || data === undefined) return data;
538
+ switch (type) {
539
+ case 'Boolean':
540
+ return Boolean(data);
541
+ case 'Integer':
542
+ return parseInt(data, 10);
543
+ case 'Number':
544
+ return parseFloat(data);
545
+ case 'String':
546
+ return String(data);
547
+ case 'Date':
548
+ return ApiClient.parseDate(String(data));
549
+ case 'Blob':
550
+ return data;
551
+ default:
552
+ if (type === Object) {
553
+ // generic object, return directly
554
+ return data;
555
+ } else if (typeof type.constructFromObject === 'function') {
556
+ // for model type like User and enum class
557
+ return type.constructFromObject(data);
558
+ } else if (Array.isArray(type)) {
559
+ // for array type like: ['String']
560
+ var itemType = type[0];
561
+ return data.map(item => {
562
+ return ApiClient.convertToType(item, itemType);
563
+ });
564
+ } else if (typeof type === 'object') {
565
+ // for plain object type like: {'String': 'Integer'}
566
+ var keyType, valueType;
567
+ for (var k in type) {
568
+ if (type.hasOwnProperty(k)) {
569
+ keyType = k;
570
+ valueType = type[k];
571
+ break;
572
+ }
573
+ }
574
+ var result = {};
575
+ for (var k in data) {
576
+ if (data.hasOwnProperty(k)) {
577
+ var key = ApiClient.convertToType(k, keyType);
578
+ var value = ApiClient.convertToType(data[k], valueType);
579
+ result[key] = value;
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
+ 'url': "",
597
+ 'description': "No description provided"
598
+ }];
599
+ }
600
+ getBasePathFromSettings(index, variables = {}) {
601
+ var servers = this.hostSettings();
602
+
603
+ // check array index out of bound
604
+ if (index < 0 || index >= servers.length) {
605
+ throw new Error("Invalid index " + index + " when selecting the host settings. Must be less than " + servers.length);
606
+ }
607
+ var server = servers[index];
608
+ var url = server['url'];
609
+
610
+ // go through variable and assign a value
611
+ for (var variable_name in server['variables']) {
612
+ if (variable_name in variables) {
613
+ let variable = server['variables'][variable_name];
614
+ if (!('enum_values' in variable) || variable['enum_values'].includes(variables[variable_name])) {
615
+ url = url.replace("{" + variable_name + "}", variables[variable_name]);
616
+ } else {
617
+ 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'] + ".");
618
+ }
619
+ } else {
620
+ // use default value
621
+ url = url.replace("{" + variable_name + "}", server['variables'][variable_name]['default_value']);
622
+ }
623
+ }
624
+ return url;
625
+ }
626
+
627
+ /**
628
+ * Constructs a new map or array model from REST data.
629
+ * @param data {Object|Array} The REST data.
630
+ * @param obj {Object|Array} The target object or array.
631
+ */
632
+ static constructFromObject(data, obj, itemType) {
633
+ if (Array.isArray(data)) {
634
+ for (var i = 0; i < data.length; i++) {
635
+ if (data.hasOwnProperty(i)) obj[i] = ApiClient.convertToType(data[i], itemType);
636
+ }
637
+ } else {
638
+ for (var k in data) {
639
+ if (data.hasOwnProperty(k)) obj[k] = ApiClient.convertToType(data[k], itemType);
640
+ }
641
+ }
642
+ }
643
+ }
644
+
645
+ /**
646
+ * Enumeration of collection format separator strategies.
647
+ * @enum {String}
648
+ * @readonly
649
+ */
650
+ ApiClient.CollectionFormatEnum = {
651
+ /**
652
+ * Comma-separated values. Value: <code>csv</code>
653
+ * @const
654
+ */
655
+ CSV: ',',
656
+ /**
657
+ * Space-separated values. Value: <code>ssv</code>
658
+ * @const
659
+ */
660
+ SSV: ' ',
661
+ /**
662
+ * Tab-separated values. Value: <code>tsv</code>
663
+ * @const
664
+ */
665
+ TSV: '\t',
666
+ /**
667
+ * Pipe(|)-separated values. Value: <code>pipes</code>
668
+ * @const
669
+ */
670
+ PIPES: '|',
671
+ /**
672
+ * Native array. Value: <code>multi</code>
673
+ * @const
674
+ */
675
+ MULTI: 'multi'
676
+ };
677
+
678
+ /**
679
+ * The default API client implementation.
680
+ * @type {module:ApiClient}
681
+ */
682
+ ApiClient.instance = new ApiClient();
683
+ var _default = exports.default = ApiClient;