amazon-creators-api 1.2.1 → 1.2.2
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 +1 -10
- package/dist/ApiClient.d.ts +107 -84
- package/dist/ApiClient.js +455 -304
- package/dist/auth/OAuth2TokenManager.d.ts +19 -0
- package/dist/auth/OAuth2TokenManager.js +55 -35
- package/package.json +3 -7
package/dist/ApiClient.js
CHANGED
|
@@ -4,18 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
-
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
7
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
9
8
|
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
10
9
|
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
11
10
|
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
12
11
|
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
13
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
14
12
|
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
15
13
|
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
16
14
|
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
17
15
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
18
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
16
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
17
|
+
/**
|
|
19
18
|
* Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
20
19
|
*
|
|
21
20
|
* Licensed under the Apache License, Version 2.0 (the "License").
|
|
@@ -29,36 +28,41 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
29
28
|
* express or implied. See the License for the specific language governing
|
|
30
29
|
* permissions and limitations under the License.
|
|
31
30
|
*/
|
|
32
|
-
var OAuth2Config = require('./auth/OAuth2Config.js');
|
|
33
|
-
var OAuth2TokenManager = require('./auth/OAuth2TokenManager.js');
|
|
34
31
|
|
|
35
32
|
/**
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
* Copyright (c) 2026 Ryan Chiang (modifications)
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
var OAuth2Config = require("./auth/OAuth2Config.js");
|
|
37
|
+
var OAuth2TokenManager = require("./auth/OAuth2TokenManager.js");
|
|
39
38
|
|
|
40
39
|
/**
|
|
41
|
-
*
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
* @module ApiClient
|
|
41
|
+
* @version 1.2.0
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Manages low level client-server communications, parameter marshalling, etc. There should not be any need for an
|
|
46
|
+
* application to use this class directly - the *Api and model classes provide the public API for the service. The
|
|
47
|
+
* contents of this file should be regarded as internal but are documented for completeness.
|
|
48
|
+
* @alias module:ApiClient
|
|
49
|
+
* @class
|
|
50
|
+
*/
|
|
47
51
|
var ApiClient = /*#__PURE__*/function () {
|
|
48
52
|
/**
|
|
49
53
|
* The base URL against which to resolve every API call's (relative) path.
|
|
50
|
-
* Overrides the default value set in spec file if present
|
|
51
|
-
* @param {String} basePath
|
|
54
|
+
* Overrides the default value set in spec file if present
|
|
55
|
+
* @param {String} basePath
|
|
52
56
|
*/
|
|
53
57
|
function ApiClient() {
|
|
54
|
-
var basePath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] :
|
|
58
|
+
var basePath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "https://creatorsapi.amazon";
|
|
55
59
|
_classCallCheck(this, ApiClient);
|
|
56
60
|
/**
|
|
57
61
|
* The base URL against which to resolve every API call's (relative) path.
|
|
58
62
|
* @type {String}
|
|
59
63
|
* @default https://creatorsapi.amazon
|
|
60
64
|
*/
|
|
61
|
-
this.basePath = basePath.replace(/\/+$/,
|
|
65
|
+
this.basePath = basePath.replace(/\/+$/, "");
|
|
62
66
|
|
|
63
67
|
/**
|
|
64
68
|
* The authentication methods to be included for all API calls.
|
|
@@ -67,12 +71,12 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
67
71
|
this.authentications = {};
|
|
68
72
|
|
|
69
73
|
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
* The default HTTP headers to be included for all API calls.
|
|
75
|
+
* @type {Array.<String>}
|
|
76
|
+
* @default {}
|
|
77
|
+
*/
|
|
74
78
|
this.defaultHeaders = {
|
|
75
|
-
|
|
79
|
+
"User-Agent": "creatorsapi-nodejs-sdk/1.2.0"
|
|
76
80
|
};
|
|
77
81
|
|
|
78
82
|
/**
|
|
@@ -91,30 +95,17 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
91
95
|
this.cache = true;
|
|
92
96
|
|
|
93
97
|
/**
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
*/
|
|
98
|
-
this.enableCookies = false;
|
|
99
|
-
|
|
100
|
-
/*
|
|
101
|
-
* Used to save and return cookies in a node.js (non-browser) setting,
|
|
102
|
-
* if this.enableCookies is set to true.
|
|
98
|
+
* If set to true, the client will save the cookies from each server
|
|
99
|
+
* response, and return them in the next request.
|
|
100
|
+
* @default false
|
|
103
101
|
*/
|
|
104
|
-
|
|
105
|
-
this.agent = new _superagent["default"].agent();
|
|
106
|
-
}
|
|
102
|
+
this.enableCookies = false;
|
|
107
103
|
|
|
108
104
|
/*
|
|
109
|
-
*
|
|
105
|
+
* Optional fetch dispatcher/agent (Node.js undici-compatible).
|
|
110
106
|
*/
|
|
111
107
|
this.requestAgent = null;
|
|
112
108
|
|
|
113
|
-
/*
|
|
114
|
-
* Allow user to add superagent plugins
|
|
115
|
-
*/
|
|
116
|
-
this.plugins = null;
|
|
117
|
-
|
|
118
109
|
/**
|
|
119
110
|
* OAuth2 credential ID
|
|
120
111
|
* @type {String}
|
|
@@ -249,15 +240,15 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
249
240
|
}
|
|
250
241
|
|
|
251
242
|
/**
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
243
|
+
* Returns a string representation for an actual parameter.
|
|
244
|
+
* @param param The actual parameter.
|
|
245
|
+
* @returns {String} The string representation of <code>param</code>.
|
|
246
|
+
*/
|
|
256
247
|
}, {
|
|
257
248
|
key: "paramToString",
|
|
258
249
|
value: function paramToString(param) {
|
|
259
250
|
if (param == undefined || param == null) {
|
|
260
|
-
return
|
|
251
|
+
return "";
|
|
261
252
|
}
|
|
262
253
|
if (param instanceof Date) {
|
|
263
254
|
return param.toJSON();
|
|
@@ -269,10 +260,10 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
269
260
|
}
|
|
270
261
|
|
|
271
262
|
/**
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
263
|
+
* Returns a boolean indicating if the parameter could be JSON.stringified
|
|
264
|
+
* @param param The actual parameter
|
|
265
|
+
* @returns {Boolean} Flag indicating if <code>param</code> can be JSON.stringified
|
|
266
|
+
*/
|
|
276
267
|
}, {
|
|
277
268
|
key: "buildUrl",
|
|
278
269
|
value:
|
|
@@ -287,7 +278,7 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
287
278
|
function buildUrl(path, pathParams, apiBasePath) {
|
|
288
279
|
var _this = this;
|
|
289
280
|
if (!path.match(/^\//)) {
|
|
290
|
-
path =
|
|
281
|
+
path = "/" + path;
|
|
291
282
|
}
|
|
292
283
|
var url = this.basePath + path;
|
|
293
284
|
|
|
@@ -308,16 +299,16 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
308
299
|
}
|
|
309
300
|
|
|
310
301
|
/**
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
302
|
+
* Checks whether the given content type represents JSON.<br>
|
|
303
|
+
* JSON content type examples:<br>
|
|
304
|
+
* <ul>
|
|
305
|
+
* <li>application/json</li>
|
|
306
|
+
* <li>application/json; charset=UTF8</li>
|
|
307
|
+
* <li>APPLICATION/JSON</li>
|
|
308
|
+
* </ul>
|
|
309
|
+
* @param {String} contentType The MIME content type to check.
|
|
310
|
+
* @returns {Boolean} <code>true</code> if <code>contentType</code> represents JSON, otherwise <code>false</code>.
|
|
311
|
+
*/
|
|
321
312
|
}, {
|
|
322
313
|
key: "isJsonMime",
|
|
323
314
|
value: function isJsonMime(contentType) {
|
|
@@ -325,10 +316,10 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
325
316
|
}
|
|
326
317
|
|
|
327
318
|
/**
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
319
|
+
* Chooses a content type from the given array, with JSON preferred; i.e. return JSON if included, otherwise return the first.
|
|
320
|
+
* @param {Array.<String>} contentTypes
|
|
321
|
+
* @returns {String} The chosen content type, preferring JSON.
|
|
322
|
+
*/
|
|
332
323
|
}, {
|
|
333
324
|
key: "jsonPreferredMime",
|
|
334
325
|
value: function jsonPreferredMime(contentTypes) {
|
|
@@ -341,18 +332,18 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
341
332
|
}
|
|
342
333
|
|
|
343
334
|
/**
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
335
|
+
* Checks whether the given parameter value represents file-like content.
|
|
336
|
+
* @param param The parameter to check.
|
|
337
|
+
* @returns {Boolean} <code>true</code> if <code>param</code> represents a file.
|
|
338
|
+
*/
|
|
348
339
|
}, {
|
|
349
340
|
key: "isFileParam",
|
|
350
341
|
value: function isFileParam(param) {
|
|
351
342
|
// fs.ReadStream in Node.js and Electron (but not in runtime like browserify)
|
|
352
|
-
if (typeof require ===
|
|
343
|
+
if (typeof require === "function") {
|
|
353
344
|
var fs;
|
|
354
345
|
try {
|
|
355
|
-
fs = require(
|
|
346
|
+
fs = require("fs");
|
|
356
347
|
} catch (err) {}
|
|
357
348
|
if (fs && fs.ReadStream && param instanceof fs.ReadStream) {
|
|
358
349
|
return true;
|
|
@@ -360,32 +351,32 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
360
351
|
}
|
|
361
352
|
|
|
362
353
|
// Buffer in Node.js
|
|
363
|
-
if (typeof Buffer ===
|
|
354
|
+
if (typeof Buffer === "function" && param instanceof Buffer) {
|
|
364
355
|
return true;
|
|
365
356
|
}
|
|
366
357
|
|
|
367
358
|
// Blob in browser
|
|
368
|
-
if (typeof Blob ===
|
|
359
|
+
if (typeof Blob === "function" && param instanceof Blob) {
|
|
369
360
|
return true;
|
|
370
361
|
}
|
|
371
362
|
|
|
372
363
|
// File in browser (it seems File object is also instance of Blob, but keep this for safe)
|
|
373
|
-
if (typeof File ===
|
|
364
|
+
if (typeof File === "function" && param instanceof File) {
|
|
374
365
|
return true;
|
|
375
366
|
}
|
|
376
367
|
return false;
|
|
377
368
|
}
|
|
378
369
|
|
|
379
370
|
/**
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
371
|
+
* Normalizes parameter values:
|
|
372
|
+
* <ul>
|
|
373
|
+
* <li>remove nils</li>
|
|
374
|
+
* <li>keep files and arrays</li>
|
|
375
|
+
* <li>format to string with `paramToString` for other cases</li>
|
|
376
|
+
* </ul>
|
|
377
|
+
* @param {Object.<String, Object>} params The parameters as object properties.
|
|
378
|
+
* @returns {Object.<String, Object>} normalized parameters.
|
|
379
|
+
*/
|
|
389
380
|
}, {
|
|
390
381
|
key: "normalizeParams",
|
|
391
382
|
value: function normalizeParams(params) {
|
|
@@ -404,12 +395,12 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
404
395
|
}
|
|
405
396
|
|
|
406
397
|
/**
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
398
|
+
* Builds a string representation of an array-type actual parameter, according to the given collection format.
|
|
399
|
+
* @param {Array} param An array parameter.
|
|
400
|
+
* @param {module:ApiClient.CollectionFormatEnum} collectionFormat The array element separator strategy.
|
|
401
|
+
* @returns {String|Array} A string representation of the supplied collection, using the specified delimiter. Returns
|
|
402
|
+
* <code>param</code> as is if <code>collectionFormat</code> is <code>multi</code>.
|
|
403
|
+
*/
|
|
413
404
|
}, {
|
|
414
405
|
key: "buildCollectionParam",
|
|
415
406
|
value: function buildCollectionParam(param, collectionFormat) {
|
|
@@ -417,77 +408,233 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
417
408
|
return null;
|
|
418
409
|
}
|
|
419
410
|
switch (collectionFormat) {
|
|
420
|
-
case
|
|
421
|
-
return param.map(this.paramToString, this).join(
|
|
422
|
-
case
|
|
423
|
-
return param.map(this.paramToString, this).join(
|
|
424
|
-
case
|
|
425
|
-
return param.map(this.paramToString, this).join(
|
|
426
|
-
case
|
|
427
|
-
return param.map(this.paramToString, this).join(
|
|
428
|
-
case
|
|
411
|
+
case "csv":
|
|
412
|
+
return param.map(this.paramToString, this).join(",");
|
|
413
|
+
case "ssv":
|
|
414
|
+
return param.map(this.paramToString, this).join(" ");
|
|
415
|
+
case "tsv":
|
|
416
|
+
return param.map(this.paramToString, this).join("\t");
|
|
417
|
+
case "pipes":
|
|
418
|
+
return param.map(this.paramToString, this).join("|");
|
|
419
|
+
case "multi":
|
|
429
420
|
//return the array directly as SuperAgent will handle it as expected
|
|
430
421
|
return param.map(this.paramToString, this);
|
|
431
|
-
case
|
|
422
|
+
case "passthrough":
|
|
432
423
|
return param;
|
|
433
424
|
default:
|
|
434
|
-
throw new Error(
|
|
425
|
+
throw new Error("Unknown collection format: " + collectionFormat);
|
|
435
426
|
}
|
|
436
427
|
}
|
|
437
428
|
|
|
438
429
|
/**
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
430
|
+
* Applies authentication values to request headers/query.
|
|
431
|
+
* @param {{headers: Object.<String, Object>, query: Object.<String, Object>}} requestContext
|
|
432
|
+
* @param {Array.<String>} authNames An array of authentication method names.
|
|
433
|
+
*/
|
|
443
434
|
}, {
|
|
444
435
|
key: "applyAuthToRequest",
|
|
445
|
-
value: function applyAuthToRequest(
|
|
436
|
+
value: function applyAuthToRequest(requestContext, authNames) {
|
|
446
437
|
var _this2 = this;
|
|
447
438
|
authNames.forEach(function (authName) {
|
|
448
439
|
var auth = _this2.authentications[authName];
|
|
440
|
+
if (!auth) {
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
449
443
|
switch (auth.type) {
|
|
450
|
-
case
|
|
444
|
+
case "basic":
|
|
451
445
|
if (auth.username || auth.password) {
|
|
452
|
-
|
|
446
|
+
var userPass = "".concat(auth.username || "", ":").concat(auth.password || "");
|
|
447
|
+
var encoded = typeof Buffer === "function" ? Buffer.from(userPass).toString("base64") : btoa(userPass);
|
|
448
|
+
requestContext.headers["Authorization"] = "Basic ".concat(encoded);
|
|
453
449
|
}
|
|
454
450
|
break;
|
|
455
|
-
case
|
|
451
|
+
case "bearer":
|
|
456
452
|
if (auth.accessToken) {
|
|
457
|
-
var localVarBearerToken = typeof auth.accessToken ===
|
|
458
|
-
|
|
459
|
-
'Authorization': 'Bearer ' + localVarBearerToken
|
|
460
|
-
});
|
|
453
|
+
var localVarBearerToken = typeof auth.accessToken === "function" ? auth.accessToken() : auth.accessToken;
|
|
454
|
+
requestContext.headers["Authorization"] = "Bearer ".concat(localVarBearerToken);
|
|
461
455
|
}
|
|
462
456
|
break;
|
|
463
|
-
case
|
|
457
|
+
case "apiKey":
|
|
464
458
|
if (auth.apiKey) {
|
|
465
|
-
var
|
|
466
|
-
if (auth
|
|
467
|
-
|
|
468
|
-
} else {
|
|
469
|
-
data[auth.name] = auth.apiKey;
|
|
470
|
-
}
|
|
471
|
-
if (auth['in'] === 'header') {
|
|
472
|
-
request.set(data);
|
|
459
|
+
var value = auth.apiKeyPrefix ? "".concat(auth.apiKeyPrefix, " ").concat(auth.apiKey) : auth.apiKey;
|
|
460
|
+
if (auth["in"] === "header") {
|
|
461
|
+
requestContext.headers[auth.name] = value;
|
|
473
462
|
} else {
|
|
474
|
-
|
|
463
|
+
requestContext.query[auth.name] = value;
|
|
475
464
|
}
|
|
476
465
|
}
|
|
477
466
|
break;
|
|
478
|
-
case
|
|
467
|
+
case "oauth2":
|
|
479
468
|
if (auth.accessToken) {
|
|
480
|
-
|
|
481
|
-
'Authorization': 'Bearer ' + auth.accessToken
|
|
482
|
-
});
|
|
469
|
+
requestContext.headers["Authorization"] = "Bearer ".concat(auth.accessToken);
|
|
483
470
|
}
|
|
484
471
|
break;
|
|
485
472
|
default:
|
|
486
|
-
throw new Error(
|
|
473
|
+
throw new Error("Unknown authentication type: " + auth.type);
|
|
487
474
|
}
|
|
488
475
|
});
|
|
489
476
|
}
|
|
490
477
|
|
|
478
|
+
/**
|
|
479
|
+
* Builds URL query string.
|
|
480
|
+
* @param {Object.<String, Object>} params
|
|
481
|
+
* @returns {String}
|
|
482
|
+
*/
|
|
483
|
+
}, {
|
|
484
|
+
key: "buildQueryString",
|
|
485
|
+
value: function buildQueryString(params) {
|
|
486
|
+
var _this3 = this;
|
|
487
|
+
var query = new URLSearchParams();
|
|
488
|
+
var _loop = function _loop(key) {
|
|
489
|
+
if (!params.hasOwnProperty(key)) {
|
|
490
|
+
return 1; // continue
|
|
491
|
+
}
|
|
492
|
+
var value = params[key];
|
|
493
|
+
if (Array.isArray(value)) {
|
|
494
|
+
value.forEach(function (entry) {
|
|
495
|
+
return query.append(key, _this3.paramToString(entry));
|
|
496
|
+
});
|
|
497
|
+
} else {
|
|
498
|
+
query.append(key, _this3.paramToString(value));
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
for (var key in params) {
|
|
502
|
+
if (_loop(key)) continue;
|
|
503
|
+
}
|
|
504
|
+
return query.toString();
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Appends form fields/files to a FormData instance.
|
|
509
|
+
* @param {FormData} form
|
|
510
|
+
* @param {Object.<String, Object>} formParams
|
|
511
|
+
*/
|
|
512
|
+
}, {
|
|
513
|
+
key: "appendFormData",
|
|
514
|
+
value: function appendFormData(form, formParams) {
|
|
515
|
+
var _loop2 = function _loop2(key) {
|
|
516
|
+
if (!formParams.hasOwnProperty(key)) {
|
|
517
|
+
return 1; // continue
|
|
518
|
+
}
|
|
519
|
+
var value = formParams[key];
|
|
520
|
+
if (Array.isArray(value)) {
|
|
521
|
+
value.forEach(function (entry) {
|
|
522
|
+
return form.append(key, entry);
|
|
523
|
+
});
|
|
524
|
+
} else {
|
|
525
|
+
form.append(key, value);
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
for (var key in formParams) {
|
|
529
|
+
if (_loop2(key)) continue;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Reads and normalizes fetch response body.
|
|
535
|
+
* @param {Response} response
|
|
536
|
+
* @param {*} returnType
|
|
537
|
+
* @returns {Promise<{body: *, text: (String|null)}>}
|
|
538
|
+
*/
|
|
539
|
+
}, {
|
|
540
|
+
key: "parseFetchResponse",
|
|
541
|
+
value: (function () {
|
|
542
|
+
var _parseFetchResponse = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(response, returnType) {
|
|
543
|
+
var blob, textValue, rawText, contentType, _t, _t2;
|
|
544
|
+
return _regenerator().w(function (_context) {
|
|
545
|
+
while (1) switch (_context.p = _context.n) {
|
|
546
|
+
case 0:
|
|
547
|
+
if (!(response.status === 204)) {
|
|
548
|
+
_context.n = 1;
|
|
549
|
+
break;
|
|
550
|
+
}
|
|
551
|
+
return _context.a(2, {
|
|
552
|
+
body: null,
|
|
553
|
+
text: null
|
|
554
|
+
});
|
|
555
|
+
case 1:
|
|
556
|
+
if (!(returnType === "Blob")) {
|
|
557
|
+
_context.n = 6;
|
|
558
|
+
break;
|
|
559
|
+
}
|
|
560
|
+
if (!(typeof response.blob === "function")) {
|
|
561
|
+
_context.n = 3;
|
|
562
|
+
break;
|
|
563
|
+
}
|
|
564
|
+
_context.n = 2;
|
|
565
|
+
return response.blob();
|
|
566
|
+
case 2:
|
|
567
|
+
_t = _context.v;
|
|
568
|
+
_context.n = 5;
|
|
569
|
+
break;
|
|
570
|
+
case 3:
|
|
571
|
+
_context.n = 4;
|
|
572
|
+
return response.arrayBuffer();
|
|
573
|
+
case 4:
|
|
574
|
+
_t = _context.v;
|
|
575
|
+
case 5:
|
|
576
|
+
blob = _t;
|
|
577
|
+
return _context.a(2, {
|
|
578
|
+
body: blob,
|
|
579
|
+
text: null
|
|
580
|
+
});
|
|
581
|
+
case 6:
|
|
582
|
+
if (!(returnType === "String")) {
|
|
583
|
+
_context.n = 8;
|
|
584
|
+
break;
|
|
585
|
+
}
|
|
586
|
+
_context.n = 7;
|
|
587
|
+
return response.text();
|
|
588
|
+
case 7:
|
|
589
|
+
textValue = _context.v;
|
|
590
|
+
return _context.a(2, {
|
|
591
|
+
body: textValue,
|
|
592
|
+
text: textValue
|
|
593
|
+
});
|
|
594
|
+
case 8:
|
|
595
|
+
_context.n = 9;
|
|
596
|
+
return response.text();
|
|
597
|
+
case 9:
|
|
598
|
+
rawText = _context.v;
|
|
599
|
+
if (rawText) {
|
|
600
|
+
_context.n = 10;
|
|
601
|
+
break;
|
|
602
|
+
}
|
|
603
|
+
return _context.a(2, {
|
|
604
|
+
body: null,
|
|
605
|
+
text: null
|
|
606
|
+
});
|
|
607
|
+
case 10:
|
|
608
|
+
contentType = response.headers.get("content-type") || "";
|
|
609
|
+
if (!(this.isJsonMime(contentType) || contentType.includes("+json"))) {
|
|
610
|
+
_context.n = 13;
|
|
611
|
+
break;
|
|
612
|
+
}
|
|
613
|
+
_context.p = 11;
|
|
614
|
+
return _context.a(2, {
|
|
615
|
+
body: JSON.parse(rawText),
|
|
616
|
+
text: rawText
|
|
617
|
+
});
|
|
618
|
+
case 12:
|
|
619
|
+
_context.p = 12;
|
|
620
|
+
_t2 = _context.v;
|
|
621
|
+
return _context.a(2, {
|
|
622
|
+
body: rawText,
|
|
623
|
+
text: rawText
|
|
624
|
+
});
|
|
625
|
+
case 13:
|
|
626
|
+
return _context.a(2, {
|
|
627
|
+
body: rawText,
|
|
628
|
+
text: rawText
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
}, _callee, this, [[11, 12]]);
|
|
632
|
+
}));
|
|
633
|
+
function parseFetchResponse(_x, _x2) {
|
|
634
|
+
return _parseFetchResponse.apply(this, arguments);
|
|
635
|
+
}
|
|
636
|
+
return parseFetchResponse;
|
|
637
|
+
}()
|
|
491
638
|
/**
|
|
492
639
|
* Deserializes an HTTP response body into a value of the specified type.
|
|
493
640
|
* @param {Object} response A SuperAgent response object.
|
|
@@ -497,6 +644,7 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
497
644
|
* all properties on <code>data<code> will be converted to this type.
|
|
498
645
|
* @returns A value of the specified type.
|
|
499
646
|
*/
|
|
647
|
+
)
|
|
500
648
|
}, {
|
|
501
649
|
key: "deserialize",
|
|
502
650
|
value: function deserialize(response, returnType) {
|
|
@@ -504,11 +652,10 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
504
652
|
return null;
|
|
505
653
|
}
|
|
506
654
|
|
|
507
|
-
//
|
|
508
|
-
// See http://visionmedia.github.io/superagent/#parsing-response-bodies
|
|
655
|
+
// Use parsed fetch response body when available.
|
|
509
656
|
var data = response.body;
|
|
510
|
-
if (data == null || _typeof(data) ===
|
|
511
|
-
//
|
|
657
|
+
if (data == null || _typeof(data) === "object" && typeof data.length === "undefined" && !Object.keys(data).length) {
|
|
658
|
+
// Use raw response text as fallback when no structured body exists.
|
|
512
659
|
data = response.text;
|
|
513
660
|
}
|
|
514
661
|
return ApiClient.convertToType(data, returnType);
|
|
@@ -534,190 +681,194 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
534
681
|
}, {
|
|
535
682
|
key: "callApi",
|
|
536
683
|
value: (function () {
|
|
537
|
-
var _callApi = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
538
|
-
var
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
while (1) switch (_context.p = _context.n) {
|
|
684
|
+
var _callApi = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(path, httpMethod, pathParams, queryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts, returnType, apiBasePath) {
|
|
685
|
+
var method, normalizedQueryParams, normalizedHeaderParams, normalizedFormParams, config, token, requestContext, mergedQuery, url, queryString, headers, contentType, accept, requestBody, formData, fetchOptions, abortController, timeoutHandle, fetchFn, fetchResponse, err, parsedPayload, response, _err, data, _t3;
|
|
686
|
+
return _regenerator().w(function (_context2) {
|
|
687
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
542
688
|
case 0:
|
|
543
689
|
if (!(!this.credentialId || !this.credentialSecret || !this.version)) {
|
|
544
|
-
|
|
690
|
+
_context2.n = 1;
|
|
545
691
|
break;
|
|
546
692
|
}
|
|
547
693
|
throw new Error("Missing configuration. Please specify credentialId, credentialSecret, and version in client object.");
|
|
548
694
|
case 1:
|
|
549
|
-
|
|
550
|
-
|
|
695
|
+
method = httpMethod.toUpperCase();
|
|
696
|
+
normalizedQueryParams = this.normalizeParams(queryParams || {});
|
|
697
|
+
normalizedHeaderParams = this.normalizeParams(headerParams || {});
|
|
698
|
+
normalizedFormParams = this.normalizeParams(formParams || {}); // Handle POST requests with null/undefined body - convert to empty object
|
|
699
|
+
if (method === "POST" && (bodyParam === null || bodyParam === undefined)) {
|
|
551
700
|
bodyParam = {};
|
|
552
701
|
}
|
|
553
702
|
|
|
554
|
-
// Initialize headers
|
|
555
|
-
if (!headerParams) {
|
|
556
|
-
headerParams = {};
|
|
557
|
-
}
|
|
558
|
-
|
|
559
703
|
// Add Content-Type if not present
|
|
560
|
-
if (!
|
|
561
|
-
|
|
704
|
+
if (!normalizedHeaderParams["Content-Type"]) {
|
|
705
|
+
normalizedHeaderParams["Content-Type"] = "application/json; charset=utf-8";
|
|
562
706
|
}
|
|
563
707
|
|
|
564
708
|
// Get OAuth2 token and add Authorization header
|
|
565
|
-
_context.p = 2;
|
|
566
|
-
// Initialize OAuth2TokenManager
|
|
567
709
|
if (!this.tokenManager) {
|
|
568
710
|
config = new OAuth2Config(this.credentialId, this.credentialSecret, this.version, this.authEndpoint);
|
|
569
711
|
this.tokenManager = new OAuth2TokenManager(config);
|
|
570
712
|
}
|
|
571
|
-
|
|
713
|
+
_context2.n = 2;
|
|
572
714
|
return this.tokenManager.getToken();
|
|
573
|
-
case
|
|
574
|
-
token =
|
|
575
|
-
// Add Authorization headers - Version only for v2.x
|
|
715
|
+
case 2:
|
|
716
|
+
token = _context2.v;
|
|
576
717
|
if (this.version.startsWith("3.")) {
|
|
577
|
-
|
|
718
|
+
normalizedHeaderParams["Authorization"] = "Bearer ".concat(token);
|
|
578
719
|
} else {
|
|
579
|
-
|
|
580
|
-
}
|
|
581
|
-
_context.n = 5;
|
|
582
|
-
break;
|
|
583
|
-
case 4:
|
|
584
|
-
_context.p = 4;
|
|
585
|
-
_t = _context.v;
|
|
586
|
-
throw _t;
|
|
587
|
-
case 5:
|
|
588
|
-
url = this.buildUrl(path, pathParams, apiBasePath);
|
|
589
|
-
request = (0, _superagent["default"])(httpMethod, url);
|
|
590
|
-
if (this.plugins !== null) {
|
|
591
|
-
for (index in this.plugins) {
|
|
592
|
-
if (this.plugins.hasOwnProperty(index)) {
|
|
593
|
-
request.use(this.plugins[index]);
|
|
594
|
-
}
|
|
595
|
-
}
|
|
720
|
+
normalizedHeaderParams["Authorization"] = "Bearer ".concat(token, ", Version ").concat(this.version);
|
|
596
721
|
}
|
|
597
722
|
|
|
598
723
|
// apply authentications
|
|
599
|
-
|
|
724
|
+
requestContext = {
|
|
725
|
+
headers: {},
|
|
726
|
+
query: {}
|
|
727
|
+
};
|
|
728
|
+
this.applyAuthToRequest(requestContext, authNames || []);
|
|
600
729
|
|
|
601
730
|
// set query parameters
|
|
602
|
-
if (
|
|
603
|
-
|
|
731
|
+
if (method === "GET" && this.cache === false) {
|
|
732
|
+
normalizedQueryParams["_"] = new Date().getTime();
|
|
604
733
|
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
// set requestAgent if it is set by user
|
|
611
|
-
if (this.requestAgent) {
|
|
612
|
-
request.agent(this.requestAgent);
|
|
734
|
+
mergedQuery = Object.assign({}, normalizedQueryParams, requestContext.query);
|
|
735
|
+
url = this.buildUrl(path, pathParams || {}, apiBasePath);
|
|
736
|
+
queryString = this.buildQueryString(mergedQuery);
|
|
737
|
+
if (queryString) {
|
|
738
|
+
url += (url.includes("?") ? "&" : "?") + queryString;
|
|
613
739
|
}
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
if (contentType) {
|
|
619
|
-
|
|
620
|
-
if (contentType != 'multipart/form-data') {
|
|
621
|
-
request.type(contentType);
|
|
622
|
-
}
|
|
740
|
+
headers = Object.assign({}, this.defaultHeaders, normalizedHeaderParams, requestContext.headers);
|
|
741
|
+
contentType = this.jsonPreferredMime(contentTypes || []);
|
|
742
|
+
if (contentType && contentType !== "multipart/form-data") {
|
|
743
|
+
headers["Content-Type"] = contentType;
|
|
744
|
+
} else if (contentType === "multipart/form-data") {
|
|
745
|
+
delete headers["Content-Type"];
|
|
623
746
|
}
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
}
|
|
747
|
+
accept = this.jsonPreferredMime(accepts || []);
|
|
748
|
+
if (accept) {
|
|
749
|
+
headers["Accept"] = accept;
|
|
750
|
+
}
|
|
751
|
+
if (contentType === "application/x-www-form-urlencoded") {
|
|
752
|
+
requestBody = new URLSearchParams(normalizedFormParams).toString();
|
|
753
|
+
} else if (contentType === "multipart/form-data") {
|
|
754
|
+
formData = new FormData();
|
|
755
|
+
this.appendFormData(formData, normalizedFormParams);
|
|
756
|
+
requestBody = formData;
|
|
757
|
+
} else if (bodyParam !== null && bodyParam !== undefined && method !== "GET" && method !== "HEAD") {
|
|
758
|
+
if (typeof bodyParam === "string" || this.isFileParam(bodyParam)) {
|
|
759
|
+
requestBody = bodyParam;
|
|
760
|
+
} else {
|
|
761
|
+
requestBody = JSON.stringify(bodyParam);
|
|
762
|
+
if (!headers["Content-Type"]) {
|
|
763
|
+
headers["Content-Type"] = "application/json";
|
|
642
764
|
}
|
|
643
765
|
}
|
|
644
|
-
} else if (bodyParam !== null && bodyParam !== undefined) {
|
|
645
|
-
if (!request.header['Content-Type']) {
|
|
646
|
-
request.type('application/json');
|
|
647
|
-
}
|
|
648
|
-
request.send(bodyParam);
|
|
649
766
|
}
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
767
|
+
fetchOptions = {
|
|
768
|
+
method: method,
|
|
769
|
+
headers: headers,
|
|
770
|
+
body: requestBody
|
|
771
|
+
}; // credentials are only meaningful in browser fetch implementations
|
|
772
|
+
if (this.enableCookies && typeof window !== "undefined") {
|
|
773
|
+
fetchOptions.credentials = "include";
|
|
653
774
|
}
|
|
654
|
-
if (
|
|
655
|
-
|
|
656
|
-
} else if (returnType === 'String') {
|
|
657
|
-
request.responseType('text');
|
|
775
|
+
if (this.requestAgent) {
|
|
776
|
+
fetchOptions.dispatcher = this.requestAgent;
|
|
658
777
|
}
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
if (
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
778
|
+
abortController = typeof AbortController !== "undefined" ? new AbortController() : null;
|
|
779
|
+
timeoutHandle = null;
|
|
780
|
+
if (abortController) {
|
|
781
|
+
fetchOptions.signal = abortController.signal;
|
|
782
|
+
if (this.timeout > 0) {
|
|
783
|
+
timeoutHandle = setTimeout(function () {
|
|
784
|
+
return abortController.abort();
|
|
785
|
+
}, this.timeout);
|
|
666
786
|
}
|
|
667
787
|
}
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
788
|
+
fetchFn = typeof fetch === "function" ? fetch : null;
|
|
789
|
+
if (fetchFn) {
|
|
790
|
+
_context2.n = 3;
|
|
791
|
+
break;
|
|
792
|
+
}
|
|
793
|
+
throw new Error("Global fetch is not available in this runtime.");
|
|
794
|
+
case 3:
|
|
795
|
+
_context2.p = 3;
|
|
796
|
+
_context2.n = 4;
|
|
797
|
+
return fetchFn(url, fetchOptions);
|
|
798
|
+
case 4:
|
|
799
|
+
fetchResponse = _context2.v;
|
|
800
|
+
_context2.n = 6;
|
|
801
|
+
break;
|
|
802
|
+
case 5:
|
|
803
|
+
_context2.p = 5;
|
|
804
|
+
_t3 = _context2.v;
|
|
805
|
+
if (timeoutHandle) {
|
|
806
|
+
clearTimeout(timeoutHandle);
|
|
807
|
+
}
|
|
808
|
+
err = {
|
|
809
|
+
error: _t3
|
|
810
|
+
};
|
|
811
|
+
if (abortController && abortController.signal.aborted) {
|
|
812
|
+
err.statusText = "Request timeout";
|
|
813
|
+
}
|
|
814
|
+
throw err;
|
|
815
|
+
case 6:
|
|
816
|
+
if (timeoutHandle) {
|
|
817
|
+
clearTimeout(timeoutHandle);
|
|
818
|
+
}
|
|
819
|
+
_context2.n = 7;
|
|
820
|
+
return this.parseFetchResponse(fetchResponse, returnType);
|
|
821
|
+
case 7:
|
|
822
|
+
parsedPayload = _context2.v;
|
|
823
|
+
response = {
|
|
824
|
+
status: fetchResponse.status,
|
|
825
|
+
statusText: fetchResponse.statusText,
|
|
826
|
+
headers: fetchResponse.headers,
|
|
827
|
+
body: parsedPayload.body,
|
|
828
|
+
text: parsedPayload.text
|
|
829
|
+
};
|
|
830
|
+
if (fetchResponse.ok) {
|
|
831
|
+
_context2.n = 8;
|
|
832
|
+
break;
|
|
833
|
+
}
|
|
834
|
+
_err = {
|
|
835
|
+
status: response.status,
|
|
836
|
+
statusText: response.statusText,
|
|
837
|
+
body: response.body,
|
|
838
|
+
response: response
|
|
839
|
+
};
|
|
840
|
+
throw _err;
|
|
841
|
+
case 8:
|
|
842
|
+
data = this.deserialize(response, returnType);
|
|
843
|
+
return _context2.a(2, {
|
|
844
|
+
data: data,
|
|
845
|
+
response: response
|
|
846
|
+
});
|
|
696
847
|
}
|
|
697
|
-
},
|
|
848
|
+
}, _callee2, this, [[3, 5]]);
|
|
698
849
|
}));
|
|
699
|
-
function callApi(
|
|
850
|
+
function callApi(_x3, _x4, _x5, _x6, _x7, _x8, _x9, _x0, _x1, _x10, _x11, _x12) {
|
|
700
851
|
return _callApi.apply(this, arguments);
|
|
701
852
|
}
|
|
702
853
|
return callApi;
|
|
703
854
|
}()
|
|
704
855
|
/**
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
856
|
+
* Parses an ISO-8601 string representation or epoch representation of a date value.
|
|
857
|
+
* @param {String} str The date value as a string.
|
|
858
|
+
* @returns {Date} The parsed date object.
|
|
859
|
+
*/
|
|
709
860
|
)
|
|
710
861
|
}, {
|
|
711
862
|
key: "hostSettings",
|
|
712
863
|
value:
|
|
713
864
|
/**
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
865
|
+
* Gets an array of host settings
|
|
866
|
+
* @returns An array of host settings
|
|
867
|
+
*/
|
|
717
868
|
function hostSettings() {
|
|
718
869
|
return [{
|
|
719
|
-
|
|
720
|
-
|
|
870
|
+
url: "",
|
|
871
|
+
description: "No description provided"
|
|
721
872
|
}];
|
|
722
873
|
}
|
|
723
874
|
}, {
|
|
@@ -731,37 +882,37 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
731
882
|
throw new Error("Invalid index " + index + " when selecting the host settings. Must be less than " + servers.length);
|
|
732
883
|
}
|
|
733
884
|
var server = servers[index];
|
|
734
|
-
var url = server[
|
|
885
|
+
var url = server["url"];
|
|
735
886
|
|
|
736
887
|
// go through variable and assign a value
|
|
737
|
-
for (var variable_name in server[
|
|
888
|
+
for (var variable_name in server["variables"]) {
|
|
738
889
|
if (variable_name in variables) {
|
|
739
|
-
var variable = server[
|
|
740
|
-
if (!(
|
|
890
|
+
var variable = server["variables"][variable_name];
|
|
891
|
+
if (!("enum_values" in variable) || variable["enum_values"].includes(variables[variable_name])) {
|
|
741
892
|
url = url.replace("{" + variable_name + "}", variables[variable_name]);
|
|
742
893
|
} else {
|
|
743
|
-
throw new Error("The variable `" + variable_name + "` in the host URL has invalid value " + variables[variable_name] + ". Must be " + server[
|
|
894
|
+
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"] + ".");
|
|
744
895
|
}
|
|
745
896
|
} else {
|
|
746
897
|
// use default value
|
|
747
|
-
url = url.replace("{" + variable_name + "}", server[
|
|
898
|
+
url = url.replace("{" + variable_name + "}", server["variables"][variable_name]["default_value"]);
|
|
748
899
|
}
|
|
749
900
|
}
|
|
750
901
|
return url;
|
|
751
902
|
}
|
|
752
903
|
|
|
753
904
|
/**
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
905
|
+
* Constructs a new map or array model from REST data.
|
|
906
|
+
* @param data {Object|Array} The REST data.
|
|
907
|
+
* @param obj {Object|Array} The target object or array.
|
|
908
|
+
*/
|
|
758
909
|
}], [{
|
|
759
910
|
key: "canBeJsonified",
|
|
760
911
|
value: function canBeJsonified(str) {
|
|
761
|
-
if (typeof str !==
|
|
912
|
+
if (typeof str !== "string" && _typeof(str) !== "object") return false;
|
|
762
913
|
try {
|
|
763
914
|
var type = str.toString();
|
|
764
|
-
return type ===
|
|
915
|
+
return type === "[object Object]" || type === "[object Array]";
|
|
765
916
|
} catch (err) {
|
|
766
917
|
return false;
|
|
767
918
|
}
|
|
@@ -770,42 +921,42 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
770
921
|
key: "parseDate",
|
|
771
922
|
value: function parseDate(str) {
|
|
772
923
|
if (isNaN(str)) {
|
|
773
|
-
return new Date(str.replace(/(\d)(T)(\d)/i,
|
|
924
|
+
return new Date(str.replace(/(\d)(T)(\d)/i, "$1 $3"));
|
|
774
925
|
}
|
|
775
926
|
return new Date(+str);
|
|
776
927
|
}
|
|
777
928
|
|
|
778
929
|
/**
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
930
|
+
* Converts a value to the specified type.
|
|
931
|
+
* @param {(String|Object)} data The data to convert, as a string or object.
|
|
932
|
+
* @param {(String|Array.<String>|Object.<String, Object>|Function)} type The type to return. Pass a string for simple types
|
|
933
|
+
* or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To
|
|
934
|
+
* return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type:
|
|
935
|
+
* all properties on <code>data<code> will be converted to this type.
|
|
936
|
+
* @returns An instance of the specified type or null or undefined if data is null or undefined.
|
|
937
|
+
*/
|
|
787
938
|
}, {
|
|
788
939
|
key: "convertToType",
|
|
789
940
|
value: function convertToType(data, type) {
|
|
790
941
|
if (data === null || data === undefined) return data;
|
|
791
942
|
switch (type) {
|
|
792
|
-
case
|
|
943
|
+
case "Boolean":
|
|
793
944
|
return Boolean(data);
|
|
794
|
-
case
|
|
945
|
+
case "Integer":
|
|
795
946
|
return parseInt(data, 10);
|
|
796
|
-
case
|
|
947
|
+
case "Number":
|
|
797
948
|
return parseFloat(data);
|
|
798
|
-
case
|
|
949
|
+
case "String":
|
|
799
950
|
return String(data);
|
|
800
|
-
case
|
|
951
|
+
case "Date":
|
|
801
952
|
return ApiClient.parseDate(String(data));
|
|
802
|
-
case
|
|
953
|
+
case "Blob":
|
|
803
954
|
return data;
|
|
804
955
|
default:
|
|
805
956
|
if (type === Object) {
|
|
806
957
|
// generic object, return directly
|
|
807
958
|
return data;
|
|
808
|
-
} else if (typeof type.constructFromObject ===
|
|
959
|
+
} else if (typeof type.constructFromObject === "function") {
|
|
809
960
|
// for model type like User and enum class
|
|
810
961
|
return type.constructFromObject(data);
|
|
811
962
|
} else if (Array.isArray(type)) {
|
|
@@ -814,7 +965,7 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
814
965
|
return data.map(function (item) {
|
|
815
966
|
return ApiClient.convertToType(item, itemType);
|
|
816
967
|
});
|
|
817
|
-
} else if (_typeof(type) ===
|
|
968
|
+
} else if (_typeof(type) === "object") {
|
|
818
969
|
// for plain object type like: {'String': 'Integer'}
|
|
819
970
|
var keyType, valueType;
|
|
820
971
|
for (var k in type) {
|
|
@@ -864,32 +1015,32 @@ ApiClient.CollectionFormatEnum = {
|
|
|
864
1015
|
* Comma-separated values. Value: <code>csv</code>
|
|
865
1016
|
* @const
|
|
866
1017
|
*/
|
|
867
|
-
CSV:
|
|
1018
|
+
CSV: ",",
|
|
868
1019
|
/**
|
|
869
1020
|
* Space-separated values. Value: <code>ssv</code>
|
|
870
1021
|
* @const
|
|
871
1022
|
*/
|
|
872
|
-
SSV:
|
|
1023
|
+
SSV: " ",
|
|
873
1024
|
/**
|
|
874
1025
|
* Tab-separated values. Value: <code>tsv</code>
|
|
875
1026
|
* @const
|
|
876
1027
|
*/
|
|
877
|
-
TSV:
|
|
1028
|
+
TSV: "\t",
|
|
878
1029
|
/**
|
|
879
1030
|
* Pipe(|)-separated values. Value: <code>pipes</code>
|
|
880
1031
|
* @const
|
|
881
1032
|
*/
|
|
882
|
-
PIPES:
|
|
1033
|
+
PIPES: "|",
|
|
883
1034
|
/**
|
|
884
1035
|
* Native array. Value: <code>multi</code>
|
|
885
1036
|
* @const
|
|
886
1037
|
*/
|
|
887
|
-
MULTI:
|
|
1038
|
+
MULTI: "multi"
|
|
888
1039
|
};
|
|
889
1040
|
|
|
890
1041
|
/**
|
|
891
|
-
* The default API client implementation.
|
|
892
|
-
* @type {module:ApiClient}
|
|
893
|
-
*/
|
|
1042
|
+
* The default API client implementation.
|
|
1043
|
+
* @type {module:ApiClient}
|
|
1044
|
+
*/
|
|
894
1045
|
ApiClient.instance = new ApiClient();
|
|
895
1046
|
var _default = exports["default"] = ApiClient;
|