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