@flexprice/sdk 1.0.1 → 1.0.14
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/LICENSE +663 -0
- package/dist/ApiClient.js +455 -505
- package/dist/api/AuthApi.js +56 -72
- package/dist/api/CustomersApi.js +273 -301
- package/dist/api/EntitlementsApi.js +200 -224
- package/dist/api/EnvironmentsApi.js +129 -149
- package/dist/api/EventsApi.js +151 -184
- package/dist/api/FeaturesApi.js +167 -189
- package/dist/api/IntegrationsApi.js +121 -141
- package/dist/api/InvoicesApi.js +352 -377
- package/dist/api/PaymentsApi.js +202 -226
- package/dist/api/PlansApi.js +165 -187
- package/dist/api/PricesApi.js +166 -188
- package/dist/api/SecretsApi.js +88 -106
- package/dist/api/SubscriptionsApi.js +277 -307
- package/dist/api/TasksApi.js +168 -190
- package/dist/api/TenantsApi.js +114 -134
- package/dist/api/UsersApi.js +22 -36
- package/dist/api/WalletsApi.js +330 -322
- package/dist/index.js +1029 -1153
- package/dist/model/DtoAddress.js +67 -84
- package/dist/model/DtoAggregatedEntitlement.js +48 -65
- package/dist/model/DtoAggregatedFeature.js +60 -89
- package/dist/model/DtoAuthResponse.js +49 -66
- package/dist/model/DtoBillingPeriodInfo.js +49 -66
- package/dist/model/DtoBulkIngestEventRequest.js +49 -88
- package/dist/model/DtoCreateAPIKeyRequest.js +59 -89
- package/dist/model/DtoCreateAPIKeyResponse.js +44 -61
- package/dist/model/DtoCreateCustomerRequest.js +95 -125
- package/dist/model/DtoCreateEntitlementRequest.js +72 -102
- package/dist/model/DtoCreateEnvironmentRequest.js +49 -79
- package/dist/model/DtoCreateFeatureRequest.js +96 -112
- package/dist/model/DtoCreateIntegrationRequest.js +52 -82
- package/dist/model/DtoCreateInvoiceLineItemRequest.js +104 -136
- package/dist/model/DtoCreateInvoiceRequest.js +152 -179
- package/dist/model/DtoCreateMeterRequest.js +78 -117
- package/dist/model/DtoCreatePaymentRequest.js +84 -114
- package/dist/model/DtoCreatePlanEntitlementRequest.js +72 -102
- package/dist/model/DtoCreatePlanPriceRequest.js +141 -180
- package/dist/model/DtoCreatePlanRequest.js +83 -131
- package/dist/model/DtoCreatePriceRequest.js +141 -180
- package/dist/model/DtoCreatePriceTier.js +51 -81
- package/dist/model/DtoCreateSubscriptionRequest.js +115 -136
- package/dist/model/DtoCreateTaskRequest.js +68 -98
- package/dist/model/DtoCreateTenantRequest.js +50 -80
- package/dist/model/DtoCreateWalletRequest.js +110 -121
- package/dist/model/DtoCustomerEntitlementsResponse.js +49 -78
- package/dist/model/DtoCustomerInvoiceSummary.js +66 -83
- package/dist/model/DtoCustomerMultiCurrencyInvoiceSummary.js +56 -85
- package/dist/model/DtoCustomerResponse.js +135 -152
- package/dist/model/DtoCustomerUsageSummaryResponse.js +67 -96
- package/dist/model/DtoEntitlementResponse.js +127 -144
- package/dist/model/DtoEntitlementSource.js +69 -86
- package/dist/model/DtoEnvironmentResponse.js +61 -78
- package/dist/model/DtoEvent.js +83 -88
- package/dist/model/DtoFeatureResponse.js +129 -146
- package/dist/model/DtoFeatureUsageSummary.js +66 -95
- package/dist/model/DtoGetEventsRequest.js +193 -0
- package/dist/model/DtoGetEventsResponse.js +75 -88
- package/dist/model/DtoGetPreviewInvoiceRequest.js +55 -85
- package/dist/model/DtoGetUsageByMeterRequest.js +75 -105
- package/dist/model/DtoGetUsageBySubscriptionRequest.js +57 -87
- package/dist/model/DtoGetUsageBySubscriptionResponse.js +72 -101
- package/dist/model/DtoGetUsageRequest.js +86 -116
- package/dist/model/DtoGetUsageResponse.js +56 -85
- package/dist/model/DtoIngestEventRequest.js +78 -108
- package/dist/model/DtoInvoiceLineItemResponse.js +161 -178
- package/dist/model/DtoInvoiceResponse.js +250 -279
- package/dist/model/DtoLinkedIntegrationsResponse.js +35 -52
- package/dist/model/DtoListCustomersResponse.js +51 -80
- package/dist/model/DtoListEntitlementsResponse.js +51 -80
- package/dist/model/DtoListEnvironmentsResponse.js +52 -81
- package/dist/model/DtoListFeaturesResponse.js +51 -80
- package/dist/model/DtoListInvoicesResponse.js +51 -80
- package/dist/model/DtoListPaymentsResponse.js +51 -80
- package/dist/model/DtoListPlansResponse.js +51 -80
- package/dist/model/DtoListPricesResponse.js +51 -80
- package/dist/model/DtoListSecretsResponse.js +51 -80
- package/dist/model/DtoListSubscriptionPausesResponse.js +46 -75
- package/dist/model/DtoListSubscriptionsResponse.js +51 -80
- package/dist/model/DtoListTasksResponse.js +51 -80
- package/dist/model/DtoListWalletTransactionsResponse.js +51 -80
- package/dist/model/DtoLoginRequest.js +56 -86
- package/dist/model/DtoMeterResponse.js +99 -128
- package/dist/model/DtoPauseSubscriptionRequest.js +69 -99
- package/dist/model/DtoPaymentAttemptResponse.js +86 -103
- package/dist/model/DtoPaymentResponse.js +164 -181
- package/dist/model/DtoPlanResponse.js +124 -162
- package/dist/model/DtoPriceResponse.js +182 -221
- package/dist/model/DtoResumeSubscriptionRequest.js +46 -76
- package/dist/model/DtoSecretResponse.js +91 -108
- package/dist/model/DtoSignUpRequest.js +61 -91
- package/dist/model/DtoSubscriptionPauseResponse.js +135 -152
- package/dist/model/DtoSubscriptionResponse.js +270 -299
- package/dist/model/DtoSubscriptionUsageByMetersResponse.js +73 -90
- package/dist/model/DtoTaskResponse.js +141 -158
- package/dist/model/DtoTenantBillingDetails.js +57 -74
- package/dist/model/DtoTenantBillingUsage.js +51 -80
- package/dist/model/DtoTenantResponse.js +69 -86
- package/dist/model/DtoTopUpWalletRequest.js +89 -126
- package/dist/model/DtoUpdateCustomerRequest.js +89 -106
- package/dist/model/DtoUpdateEntitlementRequest.js +48 -65
- package/dist/model/DtoUpdateEnvironmentRequest.js +42 -59
- package/dist/model/DtoUpdateFeatureRequest.js +80 -76
- package/dist/model/DtoUpdatePaymentRequest.js +40 -57
- package/dist/model/DtoUpdatePaymentStatusRequest.js +41 -71
- package/dist/model/DtoUpdatePlanEntitlementRequest.js +78 -108
- package/dist/model/DtoUpdatePlanPriceRequest.js +147 -186
- package/dist/model/DtoUpdatePlanRequest.js +77 -115
- package/dist/model/DtoUpdatePriceRequest.js +47 -64
- package/dist/model/DtoUpdateTaskStatusRequest.js +38 -68
- package/dist/model/DtoUpdateTenantRequest.js +49 -54
- package/dist/model/DtoUpdateWalletRequest.js +65 -82
- package/dist/model/DtoUsageResult.js +38 -55
- package/dist/model/DtoUserResponse.js +51 -68
- package/dist/model/DtoWalletBalanceResponse.js +159 -176
- package/dist/model/DtoWalletResponse.js +120 -137
- package/dist/model/DtoWalletTransactionResponse.js +111 -128
- package/dist/model/ErrorsErrorDetail.js +47 -64
- package/dist/model/ErrorsErrorResponse.js +40 -57
- package/dist/model/MeterAggregation.js +39 -56
- package/dist/model/MeterFilter.js +42 -59
- package/dist/model/PriceJSONBTransformQuantity.js +38 -55
- package/dist/model/PricePrice.js +173 -212
- package/dist/model/PricePriceTier.js +38 -55
- package/dist/model/PriceTransformQuantity.js +38 -55
- package/dist/model/SubscriptionSubscriptionLineItem.js +165 -182
- package/dist/model/SubscriptionSubscriptionPause.js +135 -152
- package/dist/model/TypesAggregationType.js +36 -51
- package/dist/model/TypesAutoTopupTrigger.js +24 -41
- package/dist/model/TypesBillingCadence.js +24 -41
- package/dist/model/TypesBillingCycle.js +41 -0
- package/dist/model/TypesBillingModel.js +30 -46
- package/dist/model/TypesBillingPeriod.js +48 -61
- package/dist/model/TypesBillingTier.js +24 -41
- package/dist/model/TypesEntityType.js +30 -46
- package/dist/model/TypesFeatureType.js +30 -46
- package/dist/model/TypesFileType.js +24 -41
- package/dist/model/TypesInvoiceBillingReason.js +36 -51
- package/dist/model/TypesInvoiceCadence.js +24 -41
- package/dist/model/TypesInvoiceStatus.js +30 -46
- package/dist/model/TypesInvoiceType.js +30 -46
- package/dist/model/TypesPaginationResponse.js +38 -55
- package/dist/model/TypesPauseMode.js +30 -46
- package/dist/model/TypesPauseStatus.js +42 -56
- package/dist/model/TypesPaymentDestinationType.js +18 -36
- package/dist/model/TypesPaymentMethodType.js +36 -51
- package/dist/model/TypesPaymentStatus.js +48 -61
- package/dist/model/TypesPriceType.js +24 -41
- package/dist/model/TypesResetUsage.js +24 -41
- package/dist/model/TypesResumeMode.js +30 -46
- package/dist/model/TypesSecretProvider.js +30 -46
- package/dist/model/TypesSecretType.js +30 -46
- package/dist/model/TypesStatus.js +30 -46
- package/dist/model/TypesSubscriptionStatus.js +60 -71
- package/dist/model/TypesTaskStatus.js +36 -51
- package/dist/model/TypesTaskType.js +24 -41
- package/dist/model/TypesTransactionReason.js +60 -71
- package/dist/model/TypesTransactionStatus.js +30 -46
- package/dist/model/TypesTransactionType.js +24 -41
- package/dist/model/TypesWalletConfig.js +36 -53
- package/dist/model/TypesWalletConfigPriceType.js +30 -46
- package/dist/model/TypesWalletStatus.js +30 -46
- package/dist/model/TypesWalletTxReferenceType.js +30 -51
- package/dist/model/TypesWalletType.js +24 -41
- package/dist/model/TypesWindowSize.js +30 -46
- package/package.json +1 -1
- package/dist/api/MetersApi.js +0 -287
- package/dist/model/DtoUpdateMeterRequest.js +0 -110
package/dist/ApiClient.js
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
|
|
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
|
-
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); }
|
|
10
|
-
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
11
|
-
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); } }
|
|
12
|
-
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
13
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
14
|
-
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); } /**
|
|
1
|
+
/**
|
|
15
2
|
* FlexPrice API
|
|
16
3
|
* FlexPrice API Service
|
|
17
4
|
*
|
|
@@ -23,10 +10,14 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
23
10
|
* Do not edit the class manually.
|
|
24
11
|
*
|
|
25
12
|
*/
|
|
13
|
+
|
|
14
|
+
import superagent from "superagent";
|
|
15
|
+
|
|
26
16
|
/**
|
|
27
17
|
* @module ApiClient
|
|
28
18
|
* @version 1.0
|
|
29
19
|
*/
|
|
20
|
+
|
|
30
21
|
/**
|
|
31
22
|
* Manages low level client-server communications, parameter marshalling, etc. There should not be any need for an
|
|
32
23
|
* application to use this class directly - the *Api and model classes provide the public API for the service. The
|
|
@@ -34,15 +25,13 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
34
25
|
* @alias module:ApiClient
|
|
35
26
|
* @class
|
|
36
27
|
*/
|
|
37
|
-
|
|
28
|
+
class ApiClient {
|
|
38
29
|
/**
|
|
39
30
|
* The base URL against which to resolve every API call's (relative) path.
|
|
40
31
|
* Overrides the default value set in spec file if present
|
|
41
32
|
* @param {String} basePath
|
|
42
33
|
*/
|
|
43
|
-
|
|
44
|
-
var basePath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '/v1';
|
|
45
|
-
_classCallCheck(this, ApiClient);
|
|
34
|
+
constructor(basePath = '/v1') {
|
|
46
35
|
/**
|
|
47
36
|
* The base URL against which to resolve every API call's (relative) path.
|
|
48
37
|
* @type {String}
|
|
@@ -98,7 +87,7 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
98
87
|
* if this.enableCookies is set to true.
|
|
99
88
|
*/
|
|
100
89
|
if (typeof window === 'undefined') {
|
|
101
|
-
this.agent = new
|
|
90
|
+
this.agent = new superagent.agent();
|
|
102
91
|
}
|
|
103
92
|
|
|
104
93
|
/*
|
|
@@ -117,551 +106,512 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
117
106
|
* @param param The actual parameter.
|
|
118
107
|
* @returns {String} The string representation of <code>param</code>.
|
|
119
108
|
*/
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (param == undefined || param == null) {
|
|
124
|
-
return '';
|
|
125
|
-
}
|
|
126
|
-
if (param instanceof Date) {
|
|
127
|
-
return param.toJSON();
|
|
128
|
-
}
|
|
129
|
-
if (ApiClient.canBeJsonified(param)) {
|
|
130
|
-
return JSON.stringify(param);
|
|
131
|
-
}
|
|
132
|
-
return param.toString();
|
|
109
|
+
paramToString(param) {
|
|
110
|
+
if (param == undefined || param == null) {
|
|
111
|
+
return '';
|
|
133
112
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
* Returns a boolean indicating if the parameter could be JSON.stringified
|
|
137
|
-
* @param param The actual parameter
|
|
138
|
-
* @returns {Boolean} Flag indicating if <code>param</code> can be JSON.stringified
|
|
139
|
-
*/
|
|
140
|
-
}, {
|
|
141
|
-
key: "buildUrl",
|
|
142
|
-
value:
|
|
143
|
-
/**
|
|
144
|
-
* Builds full URL by appending the given path to the base URL and replacing path parameter place-holders with parameter values.
|
|
145
|
-
* NOTE: query parameters are not handled here.
|
|
146
|
-
* @param {String} path The path to append to the base URL.
|
|
147
|
-
* @param {Object} pathParams The parameter values to append.
|
|
148
|
-
* @param {String} apiBasePath Base path defined in the path, operation level to override the default one
|
|
149
|
-
* @returns {String} The encoded path with parameter values substituted.
|
|
150
|
-
*/
|
|
151
|
-
function buildUrl(path, pathParams, apiBasePath) {
|
|
152
|
-
var _this = this;
|
|
153
|
-
if (!path.match(/^\//)) {
|
|
154
|
-
path = '/' + path;
|
|
155
|
-
}
|
|
156
|
-
var url = this.basePath + path;
|
|
157
|
-
|
|
158
|
-
// use API (operation, path) base path if defined
|
|
159
|
-
if (apiBasePath !== null && apiBasePath !== undefined) {
|
|
160
|
-
url = apiBasePath + path;
|
|
161
|
-
}
|
|
162
|
-
url = url.replace(/\{([\w-\.#]+)\}/g, function (fullMatch, key) {
|
|
163
|
-
var value;
|
|
164
|
-
if (pathParams.hasOwnProperty(key)) {
|
|
165
|
-
value = _this.paramToString(pathParams[key]);
|
|
166
|
-
} else {
|
|
167
|
-
value = fullMatch;
|
|
168
|
-
}
|
|
169
|
-
return encodeURIComponent(value);
|
|
170
|
-
});
|
|
171
|
-
return url;
|
|
113
|
+
if (param instanceof Date) {
|
|
114
|
+
return param.toJSON();
|
|
172
115
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
* Checks whether the given content type represents JSON.<br>
|
|
176
|
-
* JSON content type examples:<br>
|
|
177
|
-
* <ul>
|
|
178
|
-
* <li>application/json</li>
|
|
179
|
-
* <li>application/json; charset=UTF8</li>
|
|
180
|
-
* <li>APPLICATION/JSON</li>
|
|
181
|
-
* </ul>
|
|
182
|
-
* @param {String} contentType The MIME content type to check.
|
|
183
|
-
* @returns {Boolean} <code>true</code> if <code>contentType</code> represents JSON, otherwise <code>false</code>.
|
|
184
|
-
*/
|
|
185
|
-
}, {
|
|
186
|
-
key: "isJsonMime",
|
|
187
|
-
value: function isJsonMime(contentType) {
|
|
188
|
-
return Boolean(contentType != null && contentType.match(/^application\/json(;.*)?$/i));
|
|
116
|
+
if (ApiClient.canBeJsonified(param)) {
|
|
117
|
+
return JSON.stringify(param);
|
|
189
118
|
}
|
|
119
|
+
return param.toString();
|
|
120
|
+
}
|
|
190
121
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
return contentTypes[0];
|
|
122
|
+
/**
|
|
123
|
+
* Returns a boolean indicating if the parameter could be JSON.stringified
|
|
124
|
+
* @param param The actual parameter
|
|
125
|
+
* @returns {Boolean} Flag indicating if <code>param</code> can be JSON.stringified
|
|
126
|
+
*/
|
|
127
|
+
static canBeJsonified(str) {
|
|
128
|
+
if (typeof str !== 'string' && typeof str !== 'object') return false;
|
|
129
|
+
try {
|
|
130
|
+
const type = str.toString();
|
|
131
|
+
return type === '[object Object]' || type === '[object Array]';
|
|
132
|
+
} catch (err) {
|
|
133
|
+
return false;
|
|
205
134
|
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Builds full URL by appending the given path to the base URL and replacing path parameter place-holders with parameter values.
|
|
138
|
+
* NOTE: query parameters are not handled here.
|
|
139
|
+
* @param {String} path The path to append to the base URL.
|
|
140
|
+
* @param {Object} pathParams The parameter values to append.
|
|
141
|
+
* @param {String} apiBasePath Base path defined in the path, operation level to override the default one
|
|
142
|
+
* @returns {String} The encoded path with parameter values substituted.
|
|
143
|
+
*/
|
|
144
|
+
buildUrl(path, pathParams, apiBasePath) {
|
|
145
|
+
if (!path.match(/^\//)) {
|
|
146
|
+
path = '/' + path;
|
|
147
|
+
}
|
|
148
|
+
var url = this.basePath + path;
|
|
206
149
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
var fs;
|
|
218
|
-
try {
|
|
219
|
-
fs = require('fs');
|
|
220
|
-
} catch (err) {}
|
|
221
|
-
if (fs && fs.ReadStream && param instanceof fs.ReadStream) {
|
|
222
|
-
return true;
|
|
223
|
-
}
|
|
150
|
+
// use API (operation, path) base path if defined
|
|
151
|
+
if (apiBasePath !== null && apiBasePath !== undefined) {
|
|
152
|
+
url = apiBasePath + path;
|
|
153
|
+
}
|
|
154
|
+
url = url.replace(/\{([\w-\.#]+)\}/g, (fullMatch, key) => {
|
|
155
|
+
var value;
|
|
156
|
+
if (pathParams.hasOwnProperty(key)) {
|
|
157
|
+
value = this.paramToString(pathParams[key]);
|
|
158
|
+
} else {
|
|
159
|
+
value = fullMatch;
|
|
224
160
|
}
|
|
161
|
+
return encodeURIComponent(value);
|
|
162
|
+
});
|
|
163
|
+
return url;
|
|
164
|
+
}
|
|
225
165
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
166
|
+
/**
|
|
167
|
+
* Checks whether the given content type represents JSON.<br>
|
|
168
|
+
* JSON content type examples:<br>
|
|
169
|
+
* <ul>
|
|
170
|
+
* <li>application/json</li>
|
|
171
|
+
* <li>application/json; charset=UTF8</li>
|
|
172
|
+
* <li>APPLICATION/JSON</li>
|
|
173
|
+
* </ul>
|
|
174
|
+
* @param {String} contentType The MIME content type to check.
|
|
175
|
+
* @returns {Boolean} <code>true</code> if <code>contentType</code> represents JSON, otherwise <code>false</code>.
|
|
176
|
+
*/
|
|
177
|
+
isJsonMime(contentType) {
|
|
178
|
+
return Boolean(contentType != null && contentType.match(/^application\/json(;.*)?$/i));
|
|
179
|
+
}
|
|
230
180
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
181
|
+
/**
|
|
182
|
+
* Chooses a content type from the given array, with JSON preferred; i.e. return JSON if included, otherwise return the first.
|
|
183
|
+
* @param {Array.<String>} contentTypes
|
|
184
|
+
* @returns {String} The chosen content type, preferring JSON.
|
|
185
|
+
*/
|
|
186
|
+
jsonPreferredMime(contentTypes) {
|
|
187
|
+
for (var i = 0; i < contentTypes.length; i++) {
|
|
188
|
+
if (this.isJsonMime(contentTypes[i])) {
|
|
189
|
+
return contentTypes[i];
|
|
234
190
|
}
|
|
191
|
+
}
|
|
192
|
+
return contentTypes[0];
|
|
193
|
+
}
|
|
235
194
|
|
|
236
|
-
|
|
237
|
-
|
|
195
|
+
/**
|
|
196
|
+
* Checks whether the given parameter value represents file-like content.
|
|
197
|
+
* @param param The parameter to check.
|
|
198
|
+
* @returns {Boolean} <code>true</code> if <code>param</code> represents a file.
|
|
199
|
+
*/
|
|
200
|
+
isFileParam(param) {
|
|
201
|
+
// fs.ReadStream in Node.js and Electron (but not in runtime like browserify)
|
|
202
|
+
if (typeof require === 'function') {
|
|
203
|
+
let fs;
|
|
204
|
+
try {
|
|
205
|
+
fs = require('fs');
|
|
206
|
+
} catch (err) {}
|
|
207
|
+
if (fs && fs.ReadStream && param instanceof fs.ReadStream) {
|
|
238
208
|
return true;
|
|
239
209
|
}
|
|
240
|
-
return false;
|
|
241
210
|
}
|
|
242
211
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
212
|
+
// Buffer in Node.js
|
|
213
|
+
if (typeof Buffer === 'function' && param instanceof Buffer) {
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Blob in browser
|
|
218
|
+
if (typeof Blob === 'function' && param instanceof Blob) {
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// File in browser (it seems File object is also instance of Blob, but keep this for safe)
|
|
223
|
+
if (typeof File === 'function' && param instanceof File) {
|
|
224
|
+
return true;
|
|
225
|
+
}
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Normalizes parameter values:
|
|
231
|
+
* <ul>
|
|
232
|
+
* <li>remove nils</li>
|
|
233
|
+
* <li>keep files and arrays</li>
|
|
234
|
+
* <li>format to string with `paramToString` for other cases</li>
|
|
235
|
+
* </ul>
|
|
236
|
+
* @param {Object.<String, Object>} params The parameters as object properties.
|
|
237
|
+
* @returns {Object.<String, Object>} normalized parameters.
|
|
238
|
+
*/
|
|
239
|
+
normalizeParams(params) {
|
|
240
|
+
var newParams = {};
|
|
241
|
+
for (var key in params) {
|
|
242
|
+
if (params.hasOwnProperty(key) && params[key] != undefined && params[key] != null) {
|
|
243
|
+
var value = params[key];
|
|
244
|
+
if (this.isFileParam(value) || Array.isArray(value)) {
|
|
245
|
+
newParams[key] = value;
|
|
246
|
+
} else {
|
|
247
|
+
newParams[key] = this.paramToString(value);
|
|
265
248
|
}
|
|
266
249
|
}
|
|
267
|
-
return newParams;
|
|
268
250
|
}
|
|
251
|
+
return newParams;
|
|
252
|
+
}
|
|
269
253
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
if (param == null) {
|
|
281
|
-
return null;
|
|
282
|
-
}
|
|
283
|
-
switch (collectionFormat) {
|
|
284
|
-
case 'csv':
|
|
285
|
-
return param.map(this.paramToString, this).join(',');
|
|
286
|
-
case 'ssv':
|
|
287
|
-
return param.map(this.paramToString, this).join(' ');
|
|
288
|
-
case 'tsv':
|
|
289
|
-
return param.map(this.paramToString, this).join('\t');
|
|
290
|
-
case 'pipes':
|
|
291
|
-
return param.map(this.paramToString, this).join('|');
|
|
292
|
-
case 'multi':
|
|
293
|
-
//return the array directly as SuperAgent will handle it as expected
|
|
294
|
-
return param.map(this.paramToString, this);
|
|
295
|
-
case 'passthrough':
|
|
296
|
-
return param;
|
|
297
|
-
default:
|
|
298
|
-
throw new Error('Unknown collection format: ' + collectionFormat);
|
|
299
|
-
}
|
|
254
|
+
/**
|
|
255
|
+
* Builds a string representation of an array-type actual parameter, according to the given collection format.
|
|
256
|
+
* @param {Array} param An array parameter.
|
|
257
|
+
* @param {module:ApiClient.CollectionFormatEnum} collectionFormat The array element separator strategy.
|
|
258
|
+
* @returns {String|Array} A string representation of the supplied collection, using the specified delimiter. Returns
|
|
259
|
+
* <code>param</code> as is if <code>collectionFormat</code> is <code>multi</code>.
|
|
260
|
+
*/
|
|
261
|
+
buildCollectionParam(param, collectionFormat) {
|
|
262
|
+
if (param == null) {
|
|
263
|
+
return null;
|
|
300
264
|
}
|
|
265
|
+
switch (collectionFormat) {
|
|
266
|
+
case 'csv':
|
|
267
|
+
return param.map(this.paramToString, this).join(',');
|
|
268
|
+
case 'ssv':
|
|
269
|
+
return param.map(this.paramToString, this).join(' ');
|
|
270
|
+
case 'tsv':
|
|
271
|
+
return param.map(this.paramToString, this).join('\t');
|
|
272
|
+
case 'pipes':
|
|
273
|
+
return param.map(this.paramToString, this).join('|');
|
|
274
|
+
case 'multi':
|
|
275
|
+
//return the array directly as SuperAgent will handle it as expected
|
|
276
|
+
return param.map(this.paramToString, this);
|
|
277
|
+
case 'passthrough':
|
|
278
|
+
return param;
|
|
279
|
+
default:
|
|
280
|
+
throw new Error('Unknown collection format: ' + collectionFormat);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
301
283
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
data[auth.name] = auth.apiKeyPrefix + ' ' + auth.apiKey;
|
|
332
|
-
} else {
|
|
333
|
-
data[auth.name] = auth.apiKey;
|
|
334
|
-
}
|
|
335
|
-
if (auth['in'] === 'header') {
|
|
336
|
-
request.set(data);
|
|
337
|
-
} else {
|
|
338
|
-
request.query(data);
|
|
339
|
-
}
|
|
284
|
+
/**
|
|
285
|
+
* Applies authentication headers to the request.
|
|
286
|
+
* @param {Object} request The request object created by a <code>superagent()</code> call.
|
|
287
|
+
* @param {Array.<String>} authNames An array of authentication method names.
|
|
288
|
+
*/
|
|
289
|
+
applyAuthToRequest(request, authNames) {
|
|
290
|
+
authNames.forEach(authName => {
|
|
291
|
+
var auth = this.authentications[authName];
|
|
292
|
+
switch (auth.type) {
|
|
293
|
+
case 'basic':
|
|
294
|
+
if (auth.username || auth.password) {
|
|
295
|
+
request.auth(auth.username || '', auth.password || '');
|
|
296
|
+
}
|
|
297
|
+
break;
|
|
298
|
+
case 'bearer':
|
|
299
|
+
if (auth.accessToken) {
|
|
300
|
+
var localVarBearerToken = typeof auth.accessToken === 'function' ? auth.accessToken() : auth.accessToken;
|
|
301
|
+
request.set({
|
|
302
|
+
'Authorization': 'Bearer ' + localVarBearerToken
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
break;
|
|
306
|
+
case 'apiKey':
|
|
307
|
+
if (auth.apiKey) {
|
|
308
|
+
var data = {};
|
|
309
|
+
if (auth.apiKeyPrefix) {
|
|
310
|
+
data[auth.name] = auth.apiKeyPrefix + ' ' + auth.apiKey;
|
|
311
|
+
} else {
|
|
312
|
+
data[auth.name] = auth.apiKey;
|
|
340
313
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
request.
|
|
345
|
-
'Authorization': 'Bearer ' + auth.accessToken
|
|
346
|
-
});
|
|
314
|
+
if (auth['in'] === 'header') {
|
|
315
|
+
request.set(data);
|
|
316
|
+
} else {
|
|
317
|
+
request.query(data);
|
|
347
318
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
* or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To
|
|
360
|
-
* return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type:
|
|
361
|
-
* all properties on <code>data<code> will be converted to this type.
|
|
362
|
-
* @returns A value of the specified type.
|
|
363
|
-
*/
|
|
364
|
-
}, {
|
|
365
|
-
key: "deserialize",
|
|
366
|
-
value: function deserialize(response, returnType) {
|
|
367
|
-
if (response == null || returnType == null || response.status == 204) {
|
|
368
|
-
return null;
|
|
319
|
+
}
|
|
320
|
+
break;
|
|
321
|
+
case 'oauth2':
|
|
322
|
+
if (auth.accessToken) {
|
|
323
|
+
request.set({
|
|
324
|
+
'Authorization': 'Bearer ' + auth.accessToken
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
break;
|
|
328
|
+
default:
|
|
329
|
+
throw new Error('Unknown authentication type: ' + auth.type);
|
|
369
330
|
}
|
|
331
|
+
});
|
|
332
|
+
}
|
|
370
333
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
334
|
+
/**
|
|
335
|
+
* Deserializes an HTTP response body into a value of the specified type.
|
|
336
|
+
* @param {Object} response A SuperAgent response object.
|
|
337
|
+
* @param {(String|Array.<String>|Object.<String, Object>|Function)} returnType The type to return. Pass a string for simple types
|
|
338
|
+
* or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To
|
|
339
|
+
* return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type:
|
|
340
|
+
* all properties on <code>data<code> will be converted to this type.
|
|
341
|
+
* @returns A value of the specified type.
|
|
342
|
+
*/
|
|
343
|
+
deserialize(response, returnType) {
|
|
344
|
+
if (response == null || returnType == null || response.status == 204) {
|
|
345
|
+
return null;
|
|
379
346
|
}
|
|
380
347
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
348
|
+
// Rely on SuperAgent for parsing response body.
|
|
349
|
+
// See http://visionmedia.github.io/superagent/#parsing-response-bodies
|
|
350
|
+
var data = response.body;
|
|
351
|
+
if (data == null || typeof data === 'object' && typeof data.length === 'undefined' && !Object.keys(data).length) {
|
|
352
|
+
// SuperAgent does not always produce a body; use the unparsed response as a fallback
|
|
353
|
+
data = response.text;
|
|
354
|
+
}
|
|
355
|
+
return ApiClient.convertToType(data, returnType);
|
|
356
|
+
}
|
|
388
357
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
358
|
+
/**
|
|
359
|
+
* Callback function to receive the result of the operation.
|
|
360
|
+
* @callback module:ApiClient~callApiCallback
|
|
361
|
+
* @param {String} error Error message, if any.
|
|
362
|
+
* @param data The data returned by the service call.
|
|
363
|
+
* @param {String} response The complete HTTP response.
|
|
364
|
+
*/
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Invokes the REST service using the supplied settings and parameters.
|
|
368
|
+
* @param {String} path The base URL to invoke.
|
|
369
|
+
* @param {String} httpMethod The HTTP method to use.
|
|
370
|
+
* @param {Object.<String, String>} pathParams A map of path parameters and their values.
|
|
371
|
+
* @param {Object.<String, Object>} queryParams A map of query parameters and their values.
|
|
372
|
+
* @param {Object.<String, Object>} headerParams A map of header parameters and their values.
|
|
373
|
+
* @param {Object.<String, Object>} formParams A map of form parameters and their values.
|
|
374
|
+
* @param {Object} bodyParam The value to pass as the request body.
|
|
375
|
+
* @param {Array.<String>} authNames An array of authentication type names.
|
|
376
|
+
* @param {Array.<String>} contentTypes An array of request MIME types.
|
|
377
|
+
* @param {Array.<String>} accepts An array of acceptable response MIME types.
|
|
378
|
+
* @param {(String|Array|ObjectFunction)} returnType The required type to return; can be a string for simple types or the
|
|
379
|
+
* constructor for a complex type.
|
|
380
|
+
* @param {String} apiBasePath base path defined in the operation/path level to override the default one
|
|
381
|
+
* @param {module:ApiClient~callApiCallback} callback The callback function.
|
|
382
|
+
* @returns {Object} The SuperAgent request object.
|
|
383
|
+
*/
|
|
384
|
+
callApi(path, httpMethod, pathParams, queryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts, returnType, apiBasePath, callback) {
|
|
385
|
+
var url = this.buildUrl(path, pathParams, apiBasePath);
|
|
386
|
+
var request = superagent(httpMethod, url);
|
|
387
|
+
if (this.plugins !== null) {
|
|
388
|
+
for (var index in this.plugins) {
|
|
389
|
+
if (this.plugins.hasOwnProperty(index)) {
|
|
390
|
+
request.use(this.plugins[index]);
|
|
418
391
|
}
|
|
419
392
|
}
|
|
393
|
+
}
|
|
420
394
|
|
|
421
|
-
|
|
422
|
-
|
|
395
|
+
// apply authentications
|
|
396
|
+
this.applyAuthToRequest(request, authNames);
|
|
423
397
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
398
|
+
// set query parameters
|
|
399
|
+
if (httpMethod.toUpperCase() === 'GET' && this.cache === false) {
|
|
400
|
+
queryParams['_'] = new Date().getTime();
|
|
401
|
+
}
|
|
402
|
+
request.query(this.normalizeParams(queryParams));
|
|
429
403
|
|
|
430
|
-
|
|
431
|
-
|
|
404
|
+
// set header parameters
|
|
405
|
+
request.set(this.defaultHeaders).set(this.normalizeParams(headerParams));
|
|
432
406
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
407
|
+
// set requestAgent if it is set by user
|
|
408
|
+
if (this.requestAgent) {
|
|
409
|
+
request.agent(this.requestAgent);
|
|
410
|
+
}
|
|
437
411
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
}
|
|
412
|
+
// set request timeout
|
|
413
|
+
request.timeout(this.timeout);
|
|
414
|
+
var contentType = this.jsonPreferredMime(contentTypes);
|
|
415
|
+
if (contentType) {
|
|
416
|
+
// Issue with superagent and multipart/form-data (https://github.com/visionmedia/superagent/issues/746)
|
|
417
|
+
if (contentType != 'multipart/form-data') {
|
|
418
|
+
request.type(contentType);
|
|
446
419
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
request.field(key, _formParamsValue);
|
|
467
|
-
}
|
|
420
|
+
}
|
|
421
|
+
if (contentType === 'application/x-www-form-urlencoded') {
|
|
422
|
+
let normalizedParams = this.normalizeParams(formParams);
|
|
423
|
+
let urlSearchParams = new URLSearchParams(normalizedParams);
|
|
424
|
+
let queryString = urlSearchParams.toString();
|
|
425
|
+
request.send(queryString);
|
|
426
|
+
} else if (contentType == 'multipart/form-data') {
|
|
427
|
+
var _formParams = this.normalizeParams(formParams);
|
|
428
|
+
for (var key in _formParams) {
|
|
429
|
+
if (_formParams.hasOwnProperty(key)) {
|
|
430
|
+
let _formParamsValue = _formParams[key];
|
|
431
|
+
if (this.isFileParam(_formParamsValue)) {
|
|
432
|
+
// file field
|
|
433
|
+
request.attach(key, _formParamsValue);
|
|
434
|
+
} else if (Array.isArray(_formParamsValue) && _formParamsValue.length && this.isFileParam(_formParamsValue[0])) {
|
|
435
|
+
// multiple files
|
|
436
|
+
_formParamsValue.forEach(file => request.attach(key, file));
|
|
437
|
+
} else {
|
|
438
|
+
request.field(key, _formParamsValue);
|
|
468
439
|
}
|
|
469
440
|
}
|
|
470
|
-
} else if (bodyParam !== null && bodyParam !== undefined) {
|
|
471
|
-
if (!request.header['Content-Type']) {
|
|
472
|
-
request.type('application/json');
|
|
473
|
-
}
|
|
474
|
-
request.send(bodyParam);
|
|
475
|
-
}
|
|
476
|
-
var accept = this.jsonPreferredMime(accepts);
|
|
477
|
-
if (accept) {
|
|
478
|
-
request.accept(accept);
|
|
479
441
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
request.responseType('text');
|
|
442
|
+
} else if (bodyParam !== null && bodyParam !== undefined) {
|
|
443
|
+
if (!request.header['Content-Type']) {
|
|
444
|
+
request.type('application/json');
|
|
484
445
|
}
|
|
446
|
+
request.send(bodyParam);
|
|
447
|
+
}
|
|
448
|
+
var accept = this.jsonPreferredMime(accepts);
|
|
449
|
+
if (accept) {
|
|
450
|
+
request.accept(accept);
|
|
451
|
+
}
|
|
452
|
+
if (returnType === 'Blob') {
|
|
453
|
+
request.responseType('blob');
|
|
454
|
+
} else if (returnType === 'String') {
|
|
455
|
+
request.responseType('text');
|
|
456
|
+
}
|
|
485
457
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
}
|
|
458
|
+
// Attach previously saved cookies, if enabled
|
|
459
|
+
if (this.enableCookies) {
|
|
460
|
+
if (typeof window === 'undefined') {
|
|
461
|
+
this.agent._attachCookies(request);
|
|
462
|
+
} else {
|
|
463
|
+
request.withCredentials();
|
|
493
464
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
} catch (err) {
|
|
504
|
-
error = err;
|
|
465
|
+
}
|
|
466
|
+
request.end((error, response) => {
|
|
467
|
+
if (callback) {
|
|
468
|
+
var data = null;
|
|
469
|
+
if (!error) {
|
|
470
|
+
try {
|
|
471
|
+
data = this.deserialize(response, returnType);
|
|
472
|
+
if (this.enableCookies && typeof window === 'undefined') {
|
|
473
|
+
this.agent._saveCookies(response);
|
|
505
474
|
}
|
|
475
|
+
} catch (err) {
|
|
476
|
+
error = err;
|
|
506
477
|
}
|
|
507
|
-
callback(error, data, response);
|
|
508
478
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
}
|
|
479
|
+
callback(error, data, response);
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
return request;
|
|
483
|
+
}
|
|
512
484
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
/**
|
|
522
|
-
* Gets an array of host settings
|
|
523
|
-
* @returns An array of host settings
|
|
524
|
-
*/
|
|
525
|
-
function hostSettings() {
|
|
526
|
-
return [{
|
|
527
|
-
'url': "/v1",
|
|
528
|
-
'description': "No description provided"
|
|
529
|
-
}];
|
|
485
|
+
/**
|
|
486
|
+
* Parses an ISO-8601 string representation or epoch representation of a date value.
|
|
487
|
+
* @param {String} str The date value as a string.
|
|
488
|
+
* @returns {Date} The parsed date object.
|
|
489
|
+
*/
|
|
490
|
+
static parseDate(str) {
|
|
491
|
+
if (isNaN(str)) {
|
|
492
|
+
return new Date(str.replace(/(\d)(T)(\d)/i, '$1 $3'));
|
|
530
493
|
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
494
|
+
return new Date(+str);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Converts a value to the specified type.
|
|
499
|
+
* @param {(String|Object)} data The data to convert, as a string or object.
|
|
500
|
+
* @param {(String|Array.<String>|Object.<String, Object>|Function)} type The type to return. Pass a string for simple types
|
|
501
|
+
* or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To
|
|
502
|
+
* return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type:
|
|
503
|
+
* all properties on <code>data<code> will be converted to this type.
|
|
504
|
+
* @returns An instance of the specified type or null or undefined if data is null or undefined.
|
|
505
|
+
*/
|
|
506
|
+
static convertToType(data, type) {
|
|
507
|
+
if (data === null || data === undefined) return data;
|
|
508
|
+
switch (type) {
|
|
509
|
+
case 'Boolean':
|
|
510
|
+
return Boolean(data);
|
|
511
|
+
case 'Integer':
|
|
512
|
+
return parseInt(data, 10);
|
|
513
|
+
case 'Number':
|
|
514
|
+
return parseFloat(data);
|
|
515
|
+
case 'String':
|
|
516
|
+
return String(data);
|
|
517
|
+
case 'Date':
|
|
518
|
+
return ApiClient.parseDate(String(data));
|
|
519
|
+
case 'Blob':
|
|
520
|
+
return data;
|
|
521
|
+
default:
|
|
522
|
+
if (type === Object) {
|
|
523
|
+
// generic object, return directly
|
|
524
|
+
return data;
|
|
525
|
+
} else if (typeof type.constructFromObject === 'function') {
|
|
526
|
+
// for model type like User and enum class
|
|
527
|
+
return type.constructFromObject(data);
|
|
528
|
+
} else if (Array.isArray(type)) {
|
|
529
|
+
// for array type like: ['String']
|
|
530
|
+
var itemType = type[0];
|
|
531
|
+
return data.map(item => {
|
|
532
|
+
return ApiClient.convertToType(item, itemType);
|
|
533
|
+
});
|
|
534
|
+
} else if (typeof type === 'object') {
|
|
535
|
+
// for plain object type like: {'String': 'Integer'}
|
|
536
|
+
var keyType, valueType;
|
|
537
|
+
for (var k in type) {
|
|
538
|
+
if (type.hasOwnProperty(k)) {
|
|
539
|
+
keyType = k;
|
|
540
|
+
valueType = type[k];
|
|
541
|
+
break;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
var result = {};
|
|
545
|
+
for (var k in data) {
|
|
546
|
+
if (data.hasOwnProperty(k)) {
|
|
547
|
+
var key = ApiClient.convertToType(k, keyType);
|
|
548
|
+
var value = ApiClient.convertToType(data[k], valueType);
|
|
549
|
+
result[key] = value;
|
|
550
|
+
}
|
|
552
551
|
}
|
|
552
|
+
return result;
|
|
553
553
|
} else {
|
|
554
|
-
//
|
|
555
|
-
|
|
554
|
+
// for unknown type, return the data directly
|
|
555
|
+
return data;
|
|
556
556
|
}
|
|
557
|
-
}
|
|
558
|
-
return url;
|
|
559
557
|
}
|
|
558
|
+
}
|
|
560
559
|
|
|
561
|
-
|
|
562
|
-
*
|
|
563
|
-
* @
|
|
564
|
-
* @param obj {Object|Array} The target object or array.
|
|
560
|
+
/**
|
|
561
|
+
* Gets an array of host settings
|
|
562
|
+
* @returns An array of host settings
|
|
565
563
|
*/
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
564
|
+
hostSettings() {
|
|
565
|
+
return [{
|
|
566
|
+
'url': "/v1",
|
|
567
|
+
'description': "No description provided"
|
|
568
|
+
}];
|
|
569
|
+
}
|
|
570
|
+
getBasePathFromSettings(index, variables = {}) {
|
|
571
|
+
var servers = this.hostSettings();
|
|
572
|
+
|
|
573
|
+
// check array index out of bound
|
|
574
|
+
if (index < 0 || index >= servers.length) {
|
|
575
|
+
throw new Error("Invalid index " + index + " when selecting the host settings. Must be less than " + servers.length);
|
|
576
576
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
577
|
+
var server = servers[index];
|
|
578
|
+
var url = server['url'];
|
|
579
|
+
|
|
580
|
+
// go through variable and assign a value
|
|
581
|
+
for (var variable_name in server['variables']) {
|
|
582
|
+
if (variable_name in variables) {
|
|
583
|
+
let variable = server['variables'][variable_name];
|
|
584
|
+
if (!('enum_values' in variable) || variable['enum_values'].includes(variables[variable_name])) {
|
|
585
|
+
url = url.replace("{" + variable_name + "}", variables[variable_name]);
|
|
586
|
+
} else {
|
|
587
|
+
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'] + ".");
|
|
588
|
+
}
|
|
589
|
+
} else {
|
|
590
|
+
// use default value
|
|
591
|
+
url = url.replace("{" + variable_name + "}", server['variables'][variable_name]['default_value']);
|
|
582
592
|
}
|
|
583
|
-
return new Date(+str);
|
|
584
593
|
}
|
|
594
|
+
return url;
|
|
595
|
+
}
|
|
585
596
|
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
}, {
|
|
596
|
-
key: "convertToType",
|
|
597
|
-
value: function convertToType(data, type) {
|
|
598
|
-
if (data === null || data === undefined) return data;
|
|
599
|
-
switch (type) {
|
|
600
|
-
case 'Boolean':
|
|
601
|
-
return Boolean(data);
|
|
602
|
-
case 'Integer':
|
|
603
|
-
return parseInt(data, 10);
|
|
604
|
-
case 'Number':
|
|
605
|
-
return parseFloat(data);
|
|
606
|
-
case 'String':
|
|
607
|
-
return String(data);
|
|
608
|
-
case 'Date':
|
|
609
|
-
return ApiClient.parseDate(String(data));
|
|
610
|
-
case 'Blob':
|
|
611
|
-
return data;
|
|
612
|
-
default:
|
|
613
|
-
if (type === Object) {
|
|
614
|
-
// generic object, return directly
|
|
615
|
-
return data;
|
|
616
|
-
} else if (typeof type.constructFromObject === 'function') {
|
|
617
|
-
// for model type like User and enum class
|
|
618
|
-
return type.constructFromObject(data);
|
|
619
|
-
} else if (Array.isArray(type)) {
|
|
620
|
-
// for array type like: ['String']
|
|
621
|
-
var itemType = type[0];
|
|
622
|
-
return data.map(function (item) {
|
|
623
|
-
return ApiClient.convertToType(item, itemType);
|
|
624
|
-
});
|
|
625
|
-
} else if (_typeof(type) === 'object') {
|
|
626
|
-
// for plain object type like: {'String': 'Integer'}
|
|
627
|
-
var keyType, valueType;
|
|
628
|
-
for (var k in type) {
|
|
629
|
-
if (type.hasOwnProperty(k)) {
|
|
630
|
-
keyType = k;
|
|
631
|
-
valueType = type[k];
|
|
632
|
-
break;
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
var result = {};
|
|
636
|
-
for (var k in data) {
|
|
637
|
-
if (data.hasOwnProperty(k)) {
|
|
638
|
-
var key = ApiClient.convertToType(k, keyType);
|
|
639
|
-
var value = ApiClient.convertToType(data[k], valueType);
|
|
640
|
-
result[key] = value;
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
return result;
|
|
644
|
-
} else {
|
|
645
|
-
// for unknown type, return the data directly
|
|
646
|
-
return data;
|
|
647
|
-
}
|
|
597
|
+
/**
|
|
598
|
+
* Constructs a new map or array model from REST data.
|
|
599
|
+
* @param data {Object|Array} The REST data.
|
|
600
|
+
* @param obj {Object|Array} The target object or array.
|
|
601
|
+
*/
|
|
602
|
+
static constructFromObject(data, obj, itemType) {
|
|
603
|
+
if (Array.isArray(data)) {
|
|
604
|
+
for (var i = 0; i < data.length; i++) {
|
|
605
|
+
if (data.hasOwnProperty(i)) obj[i] = ApiClient.convertToType(data[i], itemType);
|
|
648
606
|
}
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
value: function constructFromObject(data, obj, itemType) {
|
|
653
|
-
if (Array.isArray(data)) {
|
|
654
|
-
for (var i = 0; i < data.length; i++) {
|
|
655
|
-
if (data.hasOwnProperty(i)) obj[i] = ApiClient.convertToType(data[i], itemType);
|
|
656
|
-
}
|
|
657
|
-
} else {
|
|
658
|
-
for (var k in data) {
|
|
659
|
-
if (data.hasOwnProperty(k)) obj[k] = ApiClient.convertToType(data[k], itemType);
|
|
660
|
-
}
|
|
607
|
+
} else {
|
|
608
|
+
for (var k in data) {
|
|
609
|
+
if (data.hasOwnProperty(k)) obj[k] = ApiClient.convertToType(data[k], itemType);
|
|
661
610
|
}
|
|
662
611
|
}
|
|
663
|
-
}
|
|
664
|
-
}
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
665
615
|
/**
|
|
666
616
|
* Enumeration of collection format separator strategies.
|
|
667
617
|
* @enum {String}
|
|
@@ -700,4 +650,4 @@ ApiClient.CollectionFormatEnum = {
|
|
|
700
650
|
* @type {module:ApiClient}
|
|
701
651
|
*/
|
|
702
652
|
ApiClient.instance = new ApiClient();
|
|
703
|
-
|
|
653
|
+
export default ApiClient;
|