@flexprice/sdk 1.0.16 → 1.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/README.md +281 -200
  2. package/package.json +29 -41
  3. package/LICENSE +0 -663
  4. package/dist/ApiClient.js +0 -653
  5. package/dist/api/AuthApi.js +0 -100
  6. package/dist/api/CustomersApi.js +0 -376
  7. package/dist/api/EntitlementsApi.js +0 -267
  8. package/dist/api/EnvironmentsApi.js +0 -184
  9. package/dist/api/EventsApi.js +0 -238
  10. package/dist/api/FeaturesApi.js +0 -263
  11. package/dist/api/IntegrationsApi.js +0 -169
  12. package/dist/api/InvoicesApi.js +0 -419
  13. package/dist/api/PaymentsApi.js +0 -272
  14. package/dist/api/PlansApi.js +0 -226
  15. package/dist/api/PricesApi.js +0 -228
  16. package/dist/api/SecretsApi.js +0 -137
  17. package/dist/api/SubscriptionsApi.js +0 -353
  18. package/dist/api/TasksApi.js +0 -232
  19. package/dist/api/TenantsApi.js +0 -162
  20. package/dist/api/UsersApi.js +0 -61
  21. package/dist/api/WalletsApi.js +0 -392
  22. package/dist/index.js +0 -1102
  23. package/dist/model/DtoAddress.js +0 -132
  24. package/dist/model/DtoAggregatedEntitlement.js +0 -106
  25. package/dist/model/DtoAggregatedFeature.js +0 -109
  26. package/dist/model/DtoAuthResponse.js +0 -96
  27. package/dist/model/DtoBillingPeriodInfo.js +0 -97
  28. package/dist/model/DtoBulkIngestEventRequest.js +0 -91
  29. package/dist/model/DtoCreateAPIKeyRequest.js +0 -117
  30. package/dist/model/DtoCreateAPIKeyResponse.js +0 -86
  31. package/dist/model/DtoCreateCustomerRequest.js +0 -188
  32. package/dist/model/DtoCreateEntitlementRequest.js +0 -150
  33. package/dist/model/DtoCreateEnvironmentRequest.js +0 -96
  34. package/dist/model/DtoCreateFeatureRequest.js +0 -177
  35. package/dist/model/DtoCreateIntegrationRequest.js +0 -105
  36. package/dist/model/DtoCreateInvoiceLineItemRequest.js +0 -206
  37. package/dist/model/DtoCreateInvoiceRequest.js +0 -289
  38. package/dist/model/DtoCreateMeterRequest.js +0 -144
  39. package/dist/model/DtoCreatePaymentRequest.js +0 -172
  40. package/dist/model/DtoCreatePlanEntitlementRequest.js +0 -150
  41. package/dist/model/DtoCreatePlanPriceRequest.js +0 -279
  42. package/dist/model/DtoCreatePlanRequest.js +0 -148
  43. package/dist/model/DtoCreatePriceRequest.js +0 -279
  44. package/dist/model/DtoCreatePriceTier.js +0 -102
  45. package/dist/model/DtoCreateSubscriptionRequest.js +0 -223
  46. package/dist/model/DtoCreateTaskRequest.js +0 -137
  47. package/dist/model/DtoCreateTenantRequest.js +0 -96
  48. package/dist/model/DtoCreateWalletRequest.js +0 -205
  49. package/dist/model/DtoCustomerEntitlementsResponse.js +0 -93
  50. package/dist/model/DtoCustomerInvoiceSummary.js +0 -148
  51. package/dist/model/DtoCustomerMultiCurrencyInvoiceSummary.js +0 -105
  52. package/dist/model/DtoCustomerResponse.js +0 -283
  53. package/dist/model/DtoCustomerUsageSummaryResponse.js +0 -121
  54. package/dist/model/DtoEntitlementResponse.js +0 -259
  55. package/dist/model/DtoEntitlementSource.js +0 -144
  56. package/dist/model/DtoEnvironmentResponse.js +0 -120
  57. package/dist/model/DtoEvent.js +0 -154
  58. package/dist/model/DtoFeatureResponse.js +0 -258
  59. package/dist/model/DtoFeatureUsageSummary.js +0 -135
  60. package/dist/model/DtoGetEventsRequest.js +0 -193
  61. package/dist/model/DtoGetEventsResponse.js +0 -129
  62. package/dist/model/DtoGetPreviewInvoiceRequest.js +0 -106
  63. package/dist/model/DtoGetUsageAnalyticsRequest.js +0 -156
  64. package/dist/model/DtoGetUsageAnalyticsResponse.js +0 -101
  65. package/dist/model/DtoGetUsageByMeterRequest.js +0 -149
  66. package/dist/model/DtoGetUsageBySubscriptionRequest.js +0 -114
  67. package/dist/model/DtoGetUsageBySubscriptionResponse.js +0 -137
  68. package/dist/model/DtoGetUsageRequest.js +0 -173
  69. package/dist/model/DtoGetUsageResponse.js +0 -110
  70. package/dist/model/DtoIngestEventRequest.js +0 -156
  71. package/dist/model/DtoInvoiceLineItemResponse.js +0 -326
  72. package/dist/model/DtoInvoiceResponse.js +0 -450
  73. package/dist/model/DtoLinkedIntegrationsResponse.js +0 -72
  74. package/dist/model/DtoListCustomersResponse.js +0 -95
  75. package/dist/model/DtoListEntitlementsResponse.js +0 -95
  76. package/dist/model/DtoListEnvironmentsResponse.js +0 -105
  77. package/dist/model/DtoListFeaturesResponse.js +0 -95
  78. package/dist/model/DtoListInvoicesResponse.js +0 -95
  79. package/dist/model/DtoListPaymentsResponse.js +0 -95
  80. package/dist/model/DtoListPlansResponse.js +0 -95
  81. package/dist/model/DtoListPricesResponse.js +0 -95
  82. package/dist/model/DtoListSecretsResponse.js +0 -95
  83. package/dist/model/DtoListSubscriptionPausesResponse.js +0 -89
  84. package/dist/model/DtoListSubscriptionsResponse.js +0 -95
  85. package/dist/model/DtoListTasksResponse.js +0 -95
  86. package/dist/model/DtoListWalletTransactionsResponse.js +0 -95
  87. package/dist/model/DtoLoginRequest.js +0 -108
  88. package/dist/model/DtoMeterResponse.js +0 -188
  89. package/dist/model/DtoPauseSubscriptionRequest.js +0 -141
  90. package/dist/model/DtoPaymentAttemptResponse.js +0 -174
  91. package/dist/model/DtoPaymentResponse.js +0 -314
  92. package/dist/model/DtoPlanResponse.js +0 -231
  93. package/dist/model/DtoPriceResponse.js +0 -373
  94. package/dist/model/DtoResumeSubscriptionRequest.js +0 -97
  95. package/dist/model/DtoSecretResponse.js +0 -183
  96. package/dist/model/DtoSignUpRequest.js +0 -118
  97. package/dist/model/DtoSubscriptionPauseResponse.js +0 -283
  98. package/dist/model/DtoSubscriptionResponse.js +0 -489
  99. package/dist/model/DtoSubscriptionUsageByMetersResponse.js +0 -148
  100. package/dist/model/DtoTaskResponse.js +0 -294
  101. package/dist/model/DtoTenantBillingDetails.js +0 -110
  102. package/dist/model/DtoTenantBillingUsage.js +0 -95
  103. package/dist/model/DtoTenantResponse.js +0 -134
  104. package/dist/model/DtoTopUpWalletRequest.js +0 -148
  105. package/dist/model/DtoUpdateCustomerRequest.js +0 -178
  106. package/dist/model/DtoUpdateEntitlementRequest.js +0 -105
  107. package/dist/model/DtoUpdateEnvironmentRequest.js +0 -84
  108. package/dist/model/DtoUpdateFeatureRequest.js +0 -139
  109. package/dist/model/DtoUpdatePaymentRequest.js +0 -82
  110. package/dist/model/DtoUpdatePaymentStatusRequest.js +0 -87
  111. package/dist/model/DtoUpdatePlanEntitlementRequest.js +0 -163
  112. package/dist/model/DtoUpdatePlanPriceRequest.js +0 -292
  113. package/dist/model/DtoUpdatePlanRequest.js +0 -138
  114. package/dist/model/DtoUpdatePriceRequest.js +0 -94
  115. package/dist/model/DtoUpdateTaskStatusRequest.js +0 -79
  116. package/dist/model/DtoUpdateTenantRequest.js +0 -86
  117. package/dist/model/DtoUpdateWalletRequest.js +0 -133
  118. package/dist/model/DtoUsageAnalyticItem.js +0 -190
  119. package/dist/model/DtoUsageAnalyticPoint.js +0 -88
  120. package/dist/model/DtoUsageResult.js +0 -80
  121. package/dist/model/DtoUserResponse.js +0 -98
  122. package/dist/model/DtoWalletBalanceResponse.js +0 -336
  123. package/dist/model/DtoWalletResponse.js +0 -235
  124. package/dist/model/DtoWalletTransactionResponse.js +0 -221
  125. package/dist/model/ErrorsErrorDetail.js +0 -94
  126. package/dist/model/ErrorsErrorResponse.js +0 -82
  127. package/dist/model/GithubComFlexpriceFlexpriceInternalTypesValue.js +0 -112
  128. package/dist/model/MeterAggregation.js +0 -82
  129. package/dist/model/MeterFilter.js +0 -86
  130. package/dist/model/PriceJSONBTransformQuantity.js +0 -82
  131. package/dist/model/PricePrice.js +0 -359
  132. package/dist/model/PricePriceTier.js +0 -87
  133. package/dist/model/PriceTransformQuantity.js +0 -82
  134. package/dist/model/SubscriptionSubscriptionLineItem.js +0 -338
  135. package/dist/model/SubscriptionSubscriptionPause.js +0 -283
  136. package/dist/model/TypesAggregationType.js +0 -53
  137. package/dist/model/TypesAutoTopupTrigger.js +0 -41
  138. package/dist/model/TypesBillingCadence.js +0 -41
  139. package/dist/model/TypesBillingCycle.js +0 -41
  140. package/dist/model/TypesBillingModel.js +0 -47
  141. package/dist/model/TypesBillingPeriod.js +0 -65
  142. package/dist/model/TypesBillingTier.js +0 -41
  143. package/dist/model/TypesCustomerFilter.js +0 -230
  144. package/dist/model/TypesDataType.js +0 -53
  145. package/dist/model/TypesEntityType.js +0 -47
  146. package/dist/model/TypesFeatureFilter.js +0 -243
  147. package/dist/model/TypesFeatureType.js +0 -47
  148. package/dist/model/TypesFileType.js +0 -41
  149. package/dist/model/TypesFilterCondition.js +0 -104
  150. package/dist/model/TypesFilterOperatorType.js +0 -77
  151. package/dist/model/TypesInvoiceBillingReason.js +0 -53
  152. package/dist/model/TypesInvoiceCadence.js +0 -41
  153. package/dist/model/TypesInvoiceStatus.js +0 -47
  154. package/dist/model/TypesInvoiceType.js +0 -47
  155. package/dist/model/TypesPaginationResponse.js +0 -84
  156. package/dist/model/TypesPauseMode.js +0 -47
  157. package/dist/model/TypesPauseStatus.js +0 -59
  158. package/dist/model/TypesPaymentDestinationType.js +0 -35
  159. package/dist/model/TypesPaymentMethodType.js +0 -53
  160. package/dist/model/TypesPaymentStatus.js +0 -65
  161. package/dist/model/TypesPriceType.js +0 -41
  162. package/dist/model/TypesResetUsage.js +0 -41
  163. package/dist/model/TypesResumeMode.js +0 -47
  164. package/dist/model/TypesSecretProvider.js +0 -47
  165. package/dist/model/TypesSecretType.js +0 -47
  166. package/dist/model/TypesSortCondition.js +0 -81
  167. package/dist/model/TypesSortDirection.js +0 -41
  168. package/dist/model/TypesStatus.js +0 -47
  169. package/dist/model/TypesSubscriptionStatus.js +0 -77
  170. package/dist/model/TypesTaskStatus.js +0 -53
  171. package/dist/model/TypesTaskType.js +0 -41
  172. package/dist/model/TypesTransactionReason.js +0 -77
  173. package/dist/model/TypesTransactionStatus.js +0 -47
  174. package/dist/model/TypesTransactionType.js +0 -41
  175. package/dist/model/TypesWalletConfig.js +0 -74
  176. package/dist/model/TypesWalletConfigPriceType.js +0 -47
  177. package/dist/model/TypesWalletStatus.js +0 -47
  178. package/dist/model/TypesWalletTxReferenceType.js +0 -47
  179. package/dist/model/TypesWalletType.js +0 -41
  180. package/dist/model/TypesWindowSize.js +0 -47
package/dist/ApiClient.js DELETED
@@ -1,653 +0,0 @@
1
- /**
2
- * FlexPrice API
3
- * FlexPrice API Service
4
- *
5
- * The version of the OpenAPI document: 1.0
6
- *
7
- *
8
- * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9
- * https://openapi-generator.tech
10
- * Do not edit the class manually.
11
- *
12
- */
13
-
14
- import superagent from "superagent";
15
-
16
- /**
17
- * @module ApiClient
18
- * @version 1.0
19
- */
20
-
21
- /**
22
- * Manages low level client-server communications, parameter marshalling, etc. There should not be any need for an
23
- * application to use this class directly - the *Api and model classes provide the public API for the service. The
24
- * contents of this file should be regarded as internal but are documented for completeness.
25
- * @alias module:ApiClient
26
- * @class
27
- */
28
- class ApiClient {
29
- /**
30
- * The base URL against which to resolve every API call's (relative) path.
31
- * Overrides the default value set in spec file if present
32
- * @param {String} basePath
33
- */
34
- constructor(basePath = '/v1') {
35
- /**
36
- * The base URL against which to resolve every API call's (relative) path.
37
- * @type {String}
38
- * @default /v1
39
- */
40
- this.basePath = basePath.replace(/\/+$/, '');
41
-
42
- /**
43
- * The authentication methods to be included for all API calls.
44
- * @type {Array.<String>}
45
- */
46
- this.authentications = {
47
- 'ApiKeyAuth': {
48
- type: 'apiKey',
49
- 'in': 'header',
50
- name: 'x-api-key'
51
- }
52
- };
53
-
54
- /**
55
- * The default HTTP headers to be included for all API calls.
56
- * @type {Array.<String>}
57
- * @default {}
58
- */
59
- this.defaultHeaders = {
60
- 'User-Agent': 'OpenAPI-Generator/1.0/Javascript'
61
- };
62
-
63
- /**
64
- * The default HTTP timeout for all API calls.
65
- * @type {Number}
66
- * @default 60000
67
- */
68
- this.timeout = 60000;
69
-
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
- this.cache = true;
77
-
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
- this.enableCookies = false;
84
-
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
- if (typeof window === 'undefined') {
90
- this.agent = new superagent.agent();
91
- }
92
-
93
- /*
94
- * Allow user to override superagent agent
95
- */
96
- this.requestAgent = null;
97
-
98
- /*
99
- * Allow user to add superagent plugins
100
- */
101
- this.plugins = null;
102
- }
103
-
104
- /**
105
- * Returns a string representation for an actual parameter.
106
- * @param param The actual parameter.
107
- * @returns {String} The string representation of <code>param</code>.
108
- */
109
- paramToString(param) {
110
- if (param == undefined || param == null) {
111
- return '';
112
- }
113
- if (param instanceof Date) {
114
- return param.toJSON();
115
- }
116
- if (ApiClient.canBeJsonified(param)) {
117
- return JSON.stringify(param);
118
- }
119
- return param.toString();
120
- }
121
-
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;
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;
149
-
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;
160
- }
161
- return encodeURIComponent(value);
162
- });
163
- return url;
164
- }
165
-
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
- }
180
-
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];
190
- }
191
- }
192
- return contentTypes[0];
193
- }
194
-
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) {
208
- return true;
209
- }
210
- }
211
-
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);
248
- }
249
- }
250
- }
251
- return newParams;
252
- }
253
-
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;
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
- }
283
-
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;
313
- }
314
- if (auth['in'] === 'header') {
315
- request.set(data);
316
- } else {
317
- request.query(data);
318
- }
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);
330
- }
331
- });
332
- }
333
-
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;
346
- }
347
-
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
- }
357
-
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]);
391
- }
392
- }
393
- }
394
-
395
- // apply authentications
396
- this.applyAuthToRequest(request, authNames);
397
-
398
- // set query parameters
399
- if (httpMethod.toUpperCase() === 'GET' && this.cache === false) {
400
- queryParams['_'] = new Date().getTime();
401
- }
402
- request.query(this.normalizeParams(queryParams));
403
-
404
- // set header parameters
405
- request.set(this.defaultHeaders).set(this.normalizeParams(headerParams));
406
-
407
- // set requestAgent if it is set by user
408
- if (this.requestAgent) {
409
- request.agent(this.requestAgent);
410
- }
411
-
412
- // set request timeout
413
- request.timeout(this.timeout);
414
- 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);
419
- }
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);
439
- }
440
- }
441
- }
442
- } else if (bodyParam !== null && bodyParam !== undefined) {
443
- if (!request.header['Content-Type']) {
444
- request.type('application/json');
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
- }
457
-
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();
464
- }
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);
474
- }
475
- } catch (err) {
476
- error = err;
477
- }
478
- }
479
- callback(error, data, response);
480
- }
481
- });
482
- return request;
483
- }
484
-
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'));
493
- }
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
- }
551
- }
552
- return result;
553
- } else {
554
- // for unknown type, return the data directly
555
- return data;
556
- }
557
- }
558
- }
559
-
560
- /**
561
- * Gets an array of host settings
562
- * @returns An array of host settings
563
- */
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
- }
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']);
592
- }
593
- }
594
- return url;
595
- }
596
-
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);
606
- }
607
- } else {
608
- for (var k in data) {
609
- if (data.hasOwnProperty(k)) obj[k] = ApiClient.convertToType(data[k], itemType);
610
- }
611
- }
612
- }
613
- }
614
-
615
- /**
616
- * Enumeration of collection format separator strategies.
617
- * @enum {String}
618
- * @readonly
619
- */
620
- ApiClient.CollectionFormatEnum = {
621
- /**
622
- * Comma-separated values. Value: <code>csv</code>
623
- * @const
624
- */
625
- CSV: ',',
626
- /**
627
- * Space-separated values. Value: <code>ssv</code>
628
- * @const
629
- */
630
- SSV: ' ',
631
- /**
632
- * Tab-separated values. Value: <code>tsv</code>
633
- * @const
634
- */
635
- TSV: '\t',
636
- /**
637
- * Pipe(|)-separated values. Value: <code>pipes</code>
638
- * @const
639
- */
640
- PIPES: '|',
641
- /**
642
- * Native array. Value: <code>multi</code>
643
- * @const
644
- */
645
- MULTI: 'multi'
646
- };
647
-
648
- /**
649
- * The default API client implementation.
650
- * @type {module:ApiClient}
651
- */
652
- ApiClient.instance = new ApiClient();
653
- export default ApiClient;