@amazon-sp-api-release/amazon-sp-api-sdk-js 1.0.0-rc8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/helper/DefaultRateLimitFetcher.mjs +2 -35
- package/helper/DefaultRateLimitMap.mjs +266 -0
- package/helper/SuperagentRateLimiter.mjs +26 -14
- package/package.json +1 -1
- package/sample-node-app/index.js +27 -13
- package/src/apluscontent_v2020_11_01/ApiClient.js +48 -38
- package/src/apluscontent_v2020_11_01/api/AplusContentApi.js +50 -11
- package/src/appintegrations_v2024_04_01/ApiClient.js +48 -38
- package/src/appintegrations_v2024_04_01/api/AppIntegrationsApi.js +36 -4
- package/src/applications_v2023_11_30/ApiClient.js +48 -38
- package/src/applications_v2023_11_30/api/ApplicationsApi.js +32 -2
- package/src/awd_v2024_05_09/ApiClient.js +48 -38
- package/src/awd_v2024_05_09/api/AwdApi.js +52 -12
- package/src/catalogitems_v2022_04_01/ApiClient.js +48 -38
- package/src/catalogitems_v2022_04_01/api/CatalogApi.js +34 -3
- package/src/datakiosk_v2023_11_15/ApiClient.js +48 -38
- package/src/datakiosk_v2023_11_15/api/QueriesApi.js +40 -6
- package/src/easyship_v2022_03_23/ApiClient.js +48 -38
- package/src/easyship_v2022_03_23/api/EasyShipApi.js +40 -6
- package/src/fbaeligibility_v1/ApiClient.js +48 -38
- package/src/fbaeligibility_v1/api/FbaInboundApi.js +32 -2
- package/src/fbainventory_v1/ApiClient.js +48 -38
- package/src/fbainventory_v1/api/FbaInventoryApi.js +38 -5
- package/src/feeds_v2021_06_30/ApiClient.js +48 -38
- package/src/feeds_v2021_06_30/api/FeedsApi.js +42 -7
- package/src/finances_2024_06_19/ApiClient.js +48 -38
- package/src/finances_2024_06_19/api/DefaultApi.js +32 -2
- package/src/finances_v0/ApiClient.js +48 -38
- package/src/finances_v0/api/DefaultApi.js +38 -5
- package/src/fulfillmentinbound_v0/ApiClient.js +48 -38
- package/src/fulfillmentinbound_v0/api/FbaInboundApi.js +42 -7
- package/src/fulfillmentinbound_v2024_03_20/ApiClient.js +48 -38
- package/src/fulfillmentinbound_v2024_03_20/api/FbaInboundApi.js +120 -46
- package/src/fulfillmentoutbound_v2020_07_01/ApiClient.js +48 -38
- package/src/fulfillmentoutbound_v2020_07_01/api/FbaOutboundApi.js +58 -15
- package/src/invoices_v2024_06_19/ApiClient.js +48 -38
- package/src/invoices_v2024_06_19/api/InvoicesApi.js +44 -8
- package/src/invoicing_v0/ApiClient.js +48 -38
- package/src/invoicing_v0/api/ShipmentInvoiceApi.js +36 -4
- package/src/listingsitems_v2021_08_01/ApiClient.js +48 -38
- package/src/listingsitems_v2021_08_01/api/ListingsApi.js +40 -6
- package/src/listingsrestrictions_v2021_08_01/ApiClient.js +48 -38
- package/src/listingsrestrictions_v2021_08_01/api/ListingsApi.js +32 -2
- package/src/merchantfulfillment_v0/ApiClient.js +48 -38
- package/src/merchantfulfillment_v0/api/MerchantFulfillmentApi.js +40 -6
- package/src/messaging_v1/ApiClient.js +48 -38
- package/src/messaging_v1/api/MessagingApi.js +56 -14
- package/src/notifications_v1/ApiClient.js +48 -38
- package/src/notifications_v1/api/NotificationsApi.js +46 -9
- package/src/orders_v0/ApiClient.js +48 -38
- package/src/orders_v0/api/OrdersV0Api.js +48 -10
- package/src/orders_v0/api/ShipmentApi.js +32 -2
- package/src/pricing_v0/ApiClient.js +48 -38
- package/src/pricing_v0/api/ProductPricingApi.js +42 -7
- package/src/pricing_v2022_05_01/ApiClient.js +48 -38
- package/src/pricing_v2022_05_01/api/ProductPricingApi.js +34 -3
- package/src/productfees_v0/ApiClient.js +48 -38
- package/src/productfees_v0/api/FeesApi.js +36 -4
- package/src/producttypedefinitions_v2020_09_01/ApiClient.js +48 -38
- package/src/producttypedefinitions_v2020_09_01/api/DefinitionsApi.js +34 -3
- package/src/replenishment_v2022_11_07/ApiClient.js +48 -38
- package/src/replenishment_v2022_11_07/api/OffersApi.js +34 -3
- package/src/replenishment_v2022_11_07/api/SellingpartnersApi.js +32 -2
- package/src/reports_v2021_06_30/ApiClient.js +48 -38
- package/src/reports_v2021_06_30/api/ReportsApi.js +48 -10
- package/src/sales_v1/ApiClient.js +48 -38
- package/src/sales_v1/api/SalesApi.js +32 -2
- package/src/sellers_v1/ApiClient.js +48 -38
- package/src/sellers_v1/api/SellersApi.js +34 -3
- package/src/services_v1/ApiClient.js +48 -38
- package/src/services_v1/api/ServiceApi.js +64 -18
- package/src/shipping_v2/ApiClient.js +48 -38
- package/src/shipping_v2/api/ShippingApi.js +70 -21
- package/src/solicitations_v1/ApiClient.js +48 -38
- package/src/solicitations_v1/api/SolicitationsApi.js +34 -3
- package/src/supplysources_v2020_07_01/ApiClient.js +48 -38
- package/src/supplysources_v2020_07_01/api/SupplySourcesApi.js +42 -7
- package/src/tokens_v2021_03_01/ApiClient.js +48 -38
- package/src/tokens_v2021_03_01/api/TokensApi.js +32 -2
- package/src/transfers_v2024_06_01/ApiClient.js +48 -38
- package/src/transfers_v2024_06_01/api/DefaultApi.js +34 -3
- package/src/uploads_v2020_11_01/ApiClient.js +48 -38
- package/src/uploads_v2020_11_01/api/UploadsApi.js +32 -2
- package/src/vehicles_v2024_11_01/ApiClient.js +48 -38
- package/src/vehicles_v2024_11_01/api/AutomotiveApi.js +32 -2
- package/src/vehicles_v2024_11_01/api/VehiclesApi.js +32 -2
- package/src/vendordfinventory_v1/ApiClient.js +48 -38
- package/src/vendordfinventory_v1/api/UpdateInventoryApi.js +32 -2
- package/src/vendordforders_v2021_12_28/ApiClient.js +48 -38
- package/src/vendordforders_v2021_12_28/api/VendorOrdersApi.js +36 -4
- package/src/vendordfpayments_v1/ApiClient.js +48 -38
- package/src/vendordfpayments_v1/api/VendorInvoiceApi.js +32 -2
- package/src/vendordfshipping_v2021_12_28/ApiClient.js +48 -38
- package/src/vendordfshipping_v2021_12_28/api/CreateContainerLabelApi.js +32 -2
- package/src/vendordfshipping_v2021_12_28/api/CustomerInvoicesApi.js +34 -3
- package/src/vendordfshipping_v2021_12_28/api/VendorShippingApi.js +38 -5
- package/src/vendordfshipping_v2021_12_28/api/VendorShippingLabelsApi.js +38 -5
- package/src/vendordftransactions_v2021_12_28/ApiClient.js +48 -38
- package/src/vendordftransactions_v2021_12_28/api/VendorTransactionApi.js +32 -2
- package/src/vendorinvoices_v1/ApiClient.js +48 -38
- package/src/vendorinvoices_v1/api/VendorPaymentsApi.js +32 -2
- package/src/vendororders_v1/ApiClient.js +48 -38
- package/src/vendororders_v1/api/VendorOrdersApi.js +38 -5
- package/src/vendorshipments_v1/ApiClient.js +48 -38
- package/src/vendorshipments_v1/api/VendorShippingApi.js +38 -5
- package/src/vendortransactionstatus_v1/ApiClient.js +48 -38
- package/src/vendortransactionstatus_v1/api/VendorTransactionApi.js +32 -2
- package/helper/rate-limits.yml +0 -874
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import {ApiClient} from
|
|
14
|
+
import {ApiClient} from '../ApiClient.js';
|
|
15
15
|
import {CreateSupplySourceRequest} from '../model/CreateSupplySourceRequest.js';
|
|
16
16
|
import {CreateSupplySourceResponse} from '../model/CreateSupplySourceResponse.js';
|
|
17
17
|
import {ErrorList} from '../model/ErrorList.js';
|
|
@@ -19,6 +19,8 @@ import {GetSupplySourcesResponse} from '../model/GetSupplySourcesResponse.js';
|
|
|
19
19
|
import {SupplySource} from '../model/SupplySource.js';
|
|
20
20
|
import {UpdateSupplySourceRequest} from '../model/UpdateSupplySourceRequest.js';
|
|
21
21
|
import {UpdateSupplySourceStatusRequest} from '../model/UpdateSupplySourceStatusRequest.js';
|
|
22
|
+
import {SuperagentRateLimiter} from '../../../helper/SuperagentRateLimiter.mjs';
|
|
23
|
+
import {DefaultRateLimitFetcher} from '../../../helper/DefaultRateLimitFetcher.mjs';
|
|
22
24
|
|
|
23
25
|
/**
|
|
24
26
|
* SupplySources service.
|
|
@@ -27,6 +29,9 @@ import {UpdateSupplySourceStatusRequest} from '../model/UpdateSupplySourceStatus
|
|
|
27
29
|
*/
|
|
28
30
|
export class SupplySourcesApi {
|
|
29
31
|
|
|
32
|
+
// Private memeber stores the default rate limiters
|
|
33
|
+
#defaultRateLimiterMap;
|
|
34
|
+
|
|
30
35
|
/**
|
|
31
36
|
* Constructs a new SupplySourcesApi.
|
|
32
37
|
* @alias module:supplysources_v2020_07_01/api/SupplySourcesApi
|
|
@@ -36,6 +41,36 @@ export class SupplySourcesApi {
|
|
|
36
41
|
*/
|
|
37
42
|
constructor(apiClient) {
|
|
38
43
|
this.apiClient = apiClient || ApiClient.instance;
|
|
44
|
+
this.initializeDefaultRateLimiterMap();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Initialize rate limiters for API operations
|
|
49
|
+
*/
|
|
50
|
+
initializeDefaultRateLimiterMap() {
|
|
51
|
+
this.#defaultRateLimiterMap = new Map()
|
|
52
|
+
const defaultRateLimitFetcher = new DefaultRateLimitFetcher();
|
|
53
|
+
const operations = [
|
|
54
|
+
'SupplySourcesApi-archiveSupplySource',
|
|
55
|
+
'SupplySourcesApi-createSupplySource',
|
|
56
|
+
'SupplySourcesApi-getSupplySource',
|
|
57
|
+
'SupplySourcesApi-getSupplySources',
|
|
58
|
+
'SupplySourcesApi-updateSupplySource',
|
|
59
|
+
'SupplySourcesApi-updateSupplySourceStatus',
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
for (const operation of operations) {
|
|
63
|
+
const config = defaultRateLimitFetcher.getLimit(operation);
|
|
64
|
+
this.#defaultRateLimiterMap.set(operation, new SuperagentRateLimiter(config));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Get rate limiter for a specific operation
|
|
70
|
+
* @param {String} operation name
|
|
71
|
+
*/
|
|
72
|
+
getRateLimiter(operation) {
|
|
73
|
+
return this.#defaultRateLimiterMap.get(operation);
|
|
39
74
|
}
|
|
40
75
|
|
|
41
76
|
|
|
@@ -71,7 +106,7 @@ export class SupplySourcesApi {
|
|
|
71
106
|
return this.apiClient.callApi( 'SupplySourcesApi-archiveSupplySource',
|
|
72
107
|
'/supplySources/2020-07-01/supplySources/{supplySourceId}', 'DELETE',
|
|
73
108
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
74
|
-
contentTypes, accepts, returnType
|
|
109
|
+
contentTypes, accepts, returnType, this.getRateLimiter('SupplySourcesApi-archiveSupplySource')
|
|
75
110
|
);
|
|
76
111
|
}
|
|
77
112
|
|
|
@@ -118,7 +153,7 @@ export class SupplySourcesApi {
|
|
|
118
153
|
return this.apiClient.callApi( 'SupplySourcesApi-createSupplySource',
|
|
119
154
|
'/supplySources/2020-07-01/supplySources', 'POST',
|
|
120
155
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
121
|
-
contentTypes, accepts, returnType
|
|
156
|
+
contentTypes, accepts, returnType, this.getRateLimiter('SupplySourcesApi-createSupplySource')
|
|
122
157
|
);
|
|
123
158
|
}
|
|
124
159
|
|
|
@@ -166,7 +201,7 @@ export class SupplySourcesApi {
|
|
|
166
201
|
return this.apiClient.callApi( 'SupplySourcesApi-getSupplySource',
|
|
167
202
|
'/supplySources/2020-07-01/supplySources/{supplySourceId}', 'GET',
|
|
168
203
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
169
|
-
contentTypes, accepts, returnType
|
|
204
|
+
contentTypes, accepts, returnType, this.getRateLimiter('SupplySourcesApi-getSupplySource')
|
|
170
205
|
);
|
|
171
206
|
}
|
|
172
207
|
|
|
@@ -213,7 +248,7 @@ export class SupplySourcesApi {
|
|
|
213
248
|
return this.apiClient.callApi( 'SupplySourcesApi-getSupplySources',
|
|
214
249
|
'/supplySources/2020-07-01/supplySources', 'GET',
|
|
215
250
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
216
|
-
contentTypes, accepts, returnType
|
|
251
|
+
contentTypes, accepts, returnType, this.getRateLimiter('SupplySourcesApi-getSupplySources')
|
|
217
252
|
);
|
|
218
253
|
}
|
|
219
254
|
|
|
@@ -266,7 +301,7 @@ export class SupplySourcesApi {
|
|
|
266
301
|
return this.apiClient.callApi( 'SupplySourcesApi-updateSupplySource',
|
|
267
302
|
'/supplySources/2020-07-01/supplySources/{supplySourceId}', 'PUT',
|
|
268
303
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
269
|
-
contentTypes, accepts, returnType
|
|
304
|
+
contentTypes, accepts, returnType, this.getRateLimiter('SupplySourcesApi-updateSupplySource')
|
|
270
305
|
);
|
|
271
306
|
}
|
|
272
307
|
|
|
@@ -319,7 +354,7 @@ export class SupplySourcesApi {
|
|
|
319
354
|
return this.apiClient.callApi( 'SupplySourcesApi-updateSupplySourceStatus',
|
|
320
355
|
'/supplySources/2020-07-01/supplySources/{supplySourceId}/status', 'PUT',
|
|
321
356
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
322
|
-
contentTypes, accepts, returnType
|
|
357
|
+
contentTypes, accepts, returnType, this.getRateLimiter('SupplySourcesApi-updateSupplySourceStatus')
|
|
323
358
|
);
|
|
324
359
|
}
|
|
325
360
|
|
|
@@ -11,12 +11,11 @@
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import superagent from
|
|
15
|
-
import querystring from
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import { DefaultRateLimitFetcher } from "../../helper/DefaultRateLimitFetcher.mjs";
|
|
14
|
+
import superagent from 'superagent';
|
|
15
|
+
import querystring from 'querystring';
|
|
16
|
+
import {URL} from 'node:url';
|
|
17
|
+
import {RateLimitConfiguration} from '../../helper/RateLimitConfiguration.mjs';
|
|
18
|
+
import {SuperagentRateLimiter} from '../../helper/SuperagentRateLimiter.mjs';
|
|
20
19
|
|
|
21
20
|
/**
|
|
22
21
|
* @module tokens_v2021_03_01/ApiClient
|
|
@@ -193,9 +192,8 @@ export class ApiClient {
|
|
|
193
192
|
#tokenForApiCall = null;
|
|
194
193
|
#lwaClient = null;
|
|
195
194
|
#rdtClient = null;
|
|
196
|
-
#
|
|
197
|
-
#
|
|
198
|
-
#useDefaultRateLimiter = false;
|
|
195
|
+
#customizedRateLimiterMap = null;
|
|
196
|
+
#useRateLimiter = true;
|
|
199
197
|
|
|
200
198
|
/**
|
|
201
199
|
* Constructs a new ApiClient.
|
|
@@ -259,42 +257,54 @@ export class ApiClient {
|
|
|
259
257
|
* Allow user to override superagent agent
|
|
260
258
|
*/
|
|
261
259
|
this.requestAgent = null;
|
|
260
|
+
|
|
261
|
+
/*
|
|
262
|
+
* Initialize customized rate limiter map
|
|
263
|
+
*/
|
|
264
|
+
this.#customizedRateLimiterMap = new Map();
|
|
262
265
|
}
|
|
263
266
|
|
|
264
267
|
/**
|
|
265
|
-
*
|
|
268
|
+
* Set customized rate limiter for one operation
|
|
269
|
+
* For operations that customized rate limiter are not set
|
|
270
|
+
* Will use default rate limiter
|
|
271
|
+
* @param {String} operationName
|
|
272
|
+
* @param {RateLimitConfiguration} config
|
|
266
273
|
*/
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
this.#defaultRateLimitFetcher = await DefaultRateLimitFetcher.getInstance();
|
|
270
|
-
} catch (err) {
|
|
271
|
-
throw new Error('Error reading default rate limit:', err);
|
|
272
|
-
}
|
|
274
|
+
setCustomizedRateLimiterForOperation(operationName, config) {
|
|
275
|
+
this.#customizedRateLimiterMap.set(operationName, new SuperagentRateLimiter(config));
|
|
273
276
|
}
|
|
274
277
|
|
|
275
278
|
/**
|
|
276
|
-
*
|
|
279
|
+
* Disable customized rate limiter for one operation
|
|
280
|
+
* Fall back to default rate limiter
|
|
281
|
+
* @param {String} operationName
|
|
277
282
|
*/
|
|
278
|
-
|
|
279
|
-
this.#
|
|
280
|
-
this.#customizedRateLimiter = null;
|
|
283
|
+
disableCustomizedRatelimiterForOperation(operationName) {
|
|
284
|
+
this.#customizedRateLimiterMap.delete(operationName);
|
|
281
285
|
}
|
|
282
286
|
|
|
283
287
|
/**
|
|
284
|
-
*
|
|
285
|
-
*
|
|
288
|
+
* Clear customized rate limiter for all operations
|
|
289
|
+
* All operations will fall back to default rate limiter
|
|
290
|
+
* @param {String} operationName
|
|
291
|
+
*/
|
|
292
|
+
disableCustomizedRatelimiterForAll() {
|
|
293
|
+
this.#customizedRateLimiterMap.clear();
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Disable both default and customized rate limiter for all operations
|
|
286
298
|
*/
|
|
287
|
-
|
|
288
|
-
this.#
|
|
289
|
-
this.#useDefaultRateLimiter = false;
|
|
299
|
+
disableRateLimiter() {
|
|
300
|
+
this.#useRateLimiter = false;
|
|
290
301
|
}
|
|
291
302
|
|
|
292
303
|
/**
|
|
293
|
-
*
|
|
304
|
+
* Enable default or customized rate limiter for all operations
|
|
294
305
|
*/
|
|
295
|
-
|
|
296
|
-
this.#
|
|
297
|
-
this.defaultRateLimiter = false;
|
|
306
|
+
enableRateLimiter() {
|
|
307
|
+
this.#useRateLimiter = true;
|
|
298
308
|
}
|
|
299
309
|
|
|
300
310
|
/**
|
|
@@ -597,11 +607,12 @@ export class ApiClient {
|
|
|
597
607
|
* @param {Array<String>} accepts An array of acceptable response MIME types.
|
|
598
608
|
* @param {(String|Array|ObjectFunction)} returnType The required type to return; can be a string for simple types or the
|
|
599
609
|
* constructor for a complex type.
|
|
610
|
+
* @param {SuperagentRateLimiter} defaultRateLimiter The default rate limiter.
|
|
600
611
|
* @returns {Promise} A {@link https://www.promisejs.org/|Promise} object.
|
|
601
612
|
*/
|
|
602
613
|
async callApi(operation, path, httpMethod, pathParams,
|
|
603
614
|
queryParams, headerParams, formParams, bodyParam, contentTypes, accepts,
|
|
604
|
-
returnType) {
|
|
615
|
+
returnType, defaultRateLimiter) {
|
|
605
616
|
|
|
606
617
|
var url = this.buildUrl(path, pathParams);
|
|
607
618
|
var request = superagent(httpMethod, url);
|
|
@@ -609,15 +620,14 @@ export class ApiClient {
|
|
|
609
620
|
throw new Error('none of accessToken, RDT token and auto-retrieval is set.');
|
|
610
621
|
}
|
|
611
622
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
623
|
+
if (this.#useRateLimiter) {
|
|
624
|
+
//Set rate limiter
|
|
625
|
+
if (this.#customizedRateLimiterMap.get(operation)) {
|
|
626
|
+
request.use(this.#customizedRateLimiterMap.get(operation).getPlugin());
|
|
627
|
+
} else if (defaultRateLimiter) {
|
|
628
|
+
request.use(defaultRateLimiter.getPlugin());
|
|
629
|
+
}
|
|
619
630
|
}
|
|
620
|
-
|
|
621
631
|
|
|
622
632
|
// set query parameters
|
|
623
633
|
if (httpMethod.toUpperCase() === 'GET' && this.cache === false) {
|
|
@@ -11,10 +11,12 @@
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import {ApiClient} from
|
|
14
|
+
import {ApiClient} from '../ApiClient.js';
|
|
15
15
|
import {CreateRestrictedDataTokenRequest} from '../model/CreateRestrictedDataTokenRequest.js';
|
|
16
16
|
import {CreateRestrictedDataTokenResponse} from '../model/CreateRestrictedDataTokenResponse.js';
|
|
17
17
|
import {ErrorList} from '../model/ErrorList.js';
|
|
18
|
+
import {SuperagentRateLimiter} from '../../../helper/SuperagentRateLimiter.mjs';
|
|
19
|
+
import {DefaultRateLimitFetcher} from '../../../helper/DefaultRateLimitFetcher.mjs';
|
|
18
20
|
|
|
19
21
|
/**
|
|
20
22
|
* Tokens service.
|
|
@@ -23,6 +25,9 @@ import {ErrorList} from '../model/ErrorList.js';
|
|
|
23
25
|
*/
|
|
24
26
|
export class TokensApi {
|
|
25
27
|
|
|
28
|
+
// Private memeber stores the default rate limiters
|
|
29
|
+
#defaultRateLimiterMap;
|
|
30
|
+
|
|
26
31
|
/**
|
|
27
32
|
* Constructs a new TokensApi.
|
|
28
33
|
* @alias module:tokens_v2021_03_01/api/TokensApi
|
|
@@ -32,6 +37,31 @@ export class TokensApi {
|
|
|
32
37
|
*/
|
|
33
38
|
constructor(apiClient) {
|
|
34
39
|
this.apiClient = apiClient || ApiClient.instance;
|
|
40
|
+
this.initializeDefaultRateLimiterMap();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Initialize rate limiters for API operations
|
|
45
|
+
*/
|
|
46
|
+
initializeDefaultRateLimiterMap() {
|
|
47
|
+
this.#defaultRateLimiterMap = new Map()
|
|
48
|
+
const defaultRateLimitFetcher = new DefaultRateLimitFetcher();
|
|
49
|
+
const operations = [
|
|
50
|
+
'TokensApi-createRestrictedDataToken',
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
for (const operation of operations) {
|
|
54
|
+
const config = defaultRateLimitFetcher.getLimit(operation);
|
|
55
|
+
this.#defaultRateLimiterMap.set(operation, new SuperagentRateLimiter(config));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Get rate limiter for a specific operation
|
|
61
|
+
* @param {String} operation name
|
|
62
|
+
*/
|
|
63
|
+
getRateLimiter(operation) {
|
|
64
|
+
return this.#defaultRateLimiterMap.get(operation);
|
|
35
65
|
}
|
|
36
66
|
|
|
37
67
|
|
|
@@ -66,7 +96,7 @@ export class TokensApi {
|
|
|
66
96
|
return this.apiClient.callApi( 'TokensApi-createRestrictedDataToken',
|
|
67
97
|
'/tokens/2021-03-01/restrictedDataToken', 'POST',
|
|
68
98
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
69
|
-
contentTypes, accepts, returnType
|
|
99
|
+
contentTypes, accepts, returnType, this.getRateLimiter('TokensApi-createRestrictedDataToken')
|
|
70
100
|
);
|
|
71
101
|
}
|
|
72
102
|
|
|
@@ -11,12 +11,11 @@
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import superagent from
|
|
15
|
-
import querystring from
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import { DefaultRateLimitFetcher } from "../../helper/DefaultRateLimitFetcher.mjs";
|
|
14
|
+
import superagent from 'superagent';
|
|
15
|
+
import querystring from 'querystring';
|
|
16
|
+
import {URL} from 'node:url';
|
|
17
|
+
import {RateLimitConfiguration} from '../../helper/RateLimitConfiguration.mjs';
|
|
18
|
+
import {SuperagentRateLimiter} from '../../helper/SuperagentRateLimiter.mjs';
|
|
20
19
|
|
|
21
20
|
/**
|
|
22
21
|
* @module transfers_v2024_06_01/ApiClient
|
|
@@ -193,9 +192,8 @@ export class ApiClient {
|
|
|
193
192
|
#tokenForApiCall = null;
|
|
194
193
|
#lwaClient = null;
|
|
195
194
|
#rdtClient = null;
|
|
196
|
-
#
|
|
197
|
-
#
|
|
198
|
-
#useDefaultRateLimiter = false;
|
|
195
|
+
#customizedRateLimiterMap = null;
|
|
196
|
+
#useRateLimiter = true;
|
|
199
197
|
|
|
200
198
|
/**
|
|
201
199
|
* Constructs a new ApiClient.
|
|
@@ -259,42 +257,54 @@ export class ApiClient {
|
|
|
259
257
|
* Allow user to override superagent agent
|
|
260
258
|
*/
|
|
261
259
|
this.requestAgent = null;
|
|
260
|
+
|
|
261
|
+
/*
|
|
262
|
+
* Initialize customized rate limiter map
|
|
263
|
+
*/
|
|
264
|
+
this.#customizedRateLimiterMap = new Map();
|
|
262
265
|
}
|
|
263
266
|
|
|
264
267
|
/**
|
|
265
|
-
*
|
|
268
|
+
* Set customized rate limiter for one operation
|
|
269
|
+
* For operations that customized rate limiter are not set
|
|
270
|
+
* Will use default rate limiter
|
|
271
|
+
* @param {String} operationName
|
|
272
|
+
* @param {RateLimitConfiguration} config
|
|
266
273
|
*/
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
this.#defaultRateLimitFetcher = await DefaultRateLimitFetcher.getInstance();
|
|
270
|
-
} catch (err) {
|
|
271
|
-
throw new Error('Error reading default rate limit:', err);
|
|
272
|
-
}
|
|
274
|
+
setCustomizedRateLimiterForOperation(operationName, config) {
|
|
275
|
+
this.#customizedRateLimiterMap.set(operationName, new SuperagentRateLimiter(config));
|
|
273
276
|
}
|
|
274
277
|
|
|
275
278
|
/**
|
|
276
|
-
*
|
|
279
|
+
* Disable customized rate limiter for one operation
|
|
280
|
+
* Fall back to default rate limiter
|
|
281
|
+
* @param {String} operationName
|
|
277
282
|
*/
|
|
278
|
-
|
|
279
|
-
this.#
|
|
280
|
-
this.#customizedRateLimiter = null;
|
|
283
|
+
disableCustomizedRatelimiterForOperation(operationName) {
|
|
284
|
+
this.#customizedRateLimiterMap.delete(operationName);
|
|
281
285
|
}
|
|
282
286
|
|
|
283
287
|
/**
|
|
284
|
-
*
|
|
285
|
-
*
|
|
288
|
+
* Clear customized rate limiter for all operations
|
|
289
|
+
* All operations will fall back to default rate limiter
|
|
290
|
+
* @param {String} operationName
|
|
291
|
+
*/
|
|
292
|
+
disableCustomizedRatelimiterForAll() {
|
|
293
|
+
this.#customizedRateLimiterMap.clear();
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Disable both default and customized rate limiter for all operations
|
|
286
298
|
*/
|
|
287
|
-
|
|
288
|
-
this.#
|
|
289
|
-
this.#useDefaultRateLimiter = false;
|
|
299
|
+
disableRateLimiter() {
|
|
300
|
+
this.#useRateLimiter = false;
|
|
290
301
|
}
|
|
291
302
|
|
|
292
303
|
/**
|
|
293
|
-
*
|
|
304
|
+
* Enable default or customized rate limiter for all operations
|
|
294
305
|
*/
|
|
295
|
-
|
|
296
|
-
this.#
|
|
297
|
-
this.defaultRateLimiter = false;
|
|
306
|
+
enableRateLimiter() {
|
|
307
|
+
this.#useRateLimiter = true;
|
|
298
308
|
}
|
|
299
309
|
|
|
300
310
|
/**
|
|
@@ -597,11 +607,12 @@ export class ApiClient {
|
|
|
597
607
|
* @param {Array<String>} accepts An array of acceptable response MIME types.
|
|
598
608
|
* @param {(String|Array|ObjectFunction)} returnType The required type to return; can be a string for simple types or the
|
|
599
609
|
* constructor for a complex type.
|
|
610
|
+
* @param {SuperagentRateLimiter} defaultRateLimiter The default rate limiter.
|
|
600
611
|
* @returns {Promise} A {@link https://www.promisejs.org/|Promise} object.
|
|
601
612
|
*/
|
|
602
613
|
async callApi(operation, path, httpMethod, pathParams,
|
|
603
614
|
queryParams, headerParams, formParams, bodyParam, contentTypes, accepts,
|
|
604
|
-
returnType) {
|
|
615
|
+
returnType, defaultRateLimiter) {
|
|
605
616
|
|
|
606
617
|
var url = this.buildUrl(path, pathParams);
|
|
607
618
|
var request = superagent(httpMethod, url);
|
|
@@ -609,15 +620,14 @@ export class ApiClient {
|
|
|
609
620
|
throw new Error('none of accessToken, RDT token and auto-retrieval is set.');
|
|
610
621
|
}
|
|
611
622
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
623
|
+
if (this.#useRateLimiter) {
|
|
624
|
+
//Set rate limiter
|
|
625
|
+
if (this.#customizedRateLimiterMap.get(operation)) {
|
|
626
|
+
request.use(this.#customizedRateLimiterMap.get(operation).getPlugin());
|
|
627
|
+
} else if (defaultRateLimiter) {
|
|
628
|
+
request.use(defaultRateLimiter.getPlugin());
|
|
629
|
+
}
|
|
619
630
|
}
|
|
620
|
-
|
|
621
631
|
|
|
622
632
|
// set query parameters
|
|
623
633
|
if (httpMethod.toUpperCase() === 'GET' && this.cache === false) {
|
|
@@ -11,11 +11,13 @@
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import {ApiClient} from
|
|
14
|
+
import {ApiClient} from '../ApiClient.js';
|
|
15
15
|
import {ErrorList} from '../model/ErrorList.js';
|
|
16
16
|
import {GetPaymentMethodsResponse} from '../model/GetPaymentMethodsResponse.js';
|
|
17
17
|
import {InitiatePayoutRequest} from '../model/InitiatePayoutRequest.js';
|
|
18
18
|
import {InitiatePayoutResponse} from '../model/InitiatePayoutResponse.js';
|
|
19
|
+
import {SuperagentRateLimiter} from '../../../helper/SuperagentRateLimiter.mjs';
|
|
20
|
+
import {DefaultRateLimitFetcher} from '../../../helper/DefaultRateLimitFetcher.mjs';
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* Default service.
|
|
@@ -24,6 +26,9 @@ import {InitiatePayoutResponse} from '../model/InitiatePayoutResponse.js';
|
|
|
24
26
|
*/
|
|
25
27
|
export class DefaultApi {
|
|
26
28
|
|
|
29
|
+
// Private memeber stores the default rate limiters
|
|
30
|
+
#defaultRateLimiterMap;
|
|
31
|
+
|
|
27
32
|
/**
|
|
28
33
|
* Constructs a new DefaultApi.
|
|
29
34
|
* @alias module:transfers_v2024_06_01/api/DefaultApi
|
|
@@ -33,6 +38,32 @@ export class DefaultApi {
|
|
|
33
38
|
*/
|
|
34
39
|
constructor(apiClient) {
|
|
35
40
|
this.apiClient = apiClient || ApiClient.instance;
|
|
41
|
+
this.initializeDefaultRateLimiterMap();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Initialize rate limiters for API operations
|
|
46
|
+
*/
|
|
47
|
+
initializeDefaultRateLimiterMap() {
|
|
48
|
+
this.#defaultRateLimiterMap = new Map()
|
|
49
|
+
const defaultRateLimitFetcher = new DefaultRateLimitFetcher();
|
|
50
|
+
const operations = [
|
|
51
|
+
'DefaultApi-getPaymentMethods',
|
|
52
|
+
'DefaultApi-initiatePayout',
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
for (const operation of operations) {
|
|
56
|
+
const config = defaultRateLimitFetcher.getLimit(operation);
|
|
57
|
+
this.#defaultRateLimiterMap.set(operation, new SuperagentRateLimiter(config));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Get rate limiter for a specific operation
|
|
63
|
+
* @param {String} operation name
|
|
64
|
+
*/
|
|
65
|
+
getRateLimiter(operation) {
|
|
66
|
+
return this.#defaultRateLimiterMap.get(operation);
|
|
36
67
|
}
|
|
37
68
|
|
|
38
69
|
|
|
@@ -72,7 +103,7 @@ export class DefaultApi {
|
|
|
72
103
|
return this.apiClient.callApi( 'DefaultApi-getPaymentMethods',
|
|
73
104
|
'/finances/transfers/2024-06-01/paymentMethods', 'GET',
|
|
74
105
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
75
|
-
contentTypes, accepts, returnType
|
|
106
|
+
contentTypes, accepts, returnType, this.getRateLimiter('DefaultApi-getPaymentMethods')
|
|
76
107
|
);
|
|
77
108
|
}
|
|
78
109
|
|
|
@@ -121,7 +152,7 @@ export class DefaultApi {
|
|
|
121
152
|
return this.apiClient.callApi( 'DefaultApi-initiatePayout',
|
|
122
153
|
'/finances/transfers/2024-06-01/payouts', 'POST',
|
|
123
154
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
124
|
-
contentTypes, accepts, returnType
|
|
155
|
+
contentTypes, accepts, returnType, this.getRateLimiter('DefaultApi-initiatePayout')
|
|
125
156
|
);
|
|
126
157
|
}
|
|
127
158
|
|