@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,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 awd_v2024_05_09/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,7 +11,7 @@
|
|
|
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 {InboundEligibility} from '../model/InboundEligibility.js';
|
|
17
17
|
import {InboundOrder} from '../model/InboundOrder.js';
|
|
@@ -23,6 +23,8 @@ import {InventoryListing} from '../model/InventoryListing.js';
|
|
|
23
23
|
import {ShipmentLabels} from '../model/ShipmentLabels.js';
|
|
24
24
|
import {ShipmentListing} from '../model/ShipmentListing.js';
|
|
25
25
|
import {TransportationDetails} from '../model/TransportationDetails.js';
|
|
26
|
+
import {SuperagentRateLimiter} from '../../../helper/SuperagentRateLimiter.mjs';
|
|
27
|
+
import {DefaultRateLimitFetcher} from '../../../helper/DefaultRateLimitFetcher.mjs';
|
|
26
28
|
|
|
27
29
|
/**
|
|
28
30
|
* Awd service.
|
|
@@ -31,6 +33,9 @@ import {TransportationDetails} from '../model/TransportationDetails.js';
|
|
|
31
33
|
*/
|
|
32
34
|
export class AwdApi {
|
|
33
35
|
|
|
36
|
+
// Private memeber stores the default rate limiters
|
|
37
|
+
#defaultRateLimiterMap;
|
|
38
|
+
|
|
34
39
|
/**
|
|
35
40
|
* Constructs a new AwdApi.
|
|
36
41
|
* @alias module:awd_v2024_05_09/api/AwdApi
|
|
@@ -40,6 +45,41 @@ export class AwdApi {
|
|
|
40
45
|
*/
|
|
41
46
|
constructor(apiClient) {
|
|
42
47
|
this.apiClient = apiClient || ApiClient.instance;
|
|
48
|
+
this.initializeDefaultRateLimiterMap();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Initialize rate limiters for API operations
|
|
53
|
+
*/
|
|
54
|
+
initializeDefaultRateLimiterMap() {
|
|
55
|
+
this.#defaultRateLimiterMap = new Map()
|
|
56
|
+
const defaultRateLimitFetcher = new DefaultRateLimitFetcher();
|
|
57
|
+
const operations = [
|
|
58
|
+
'AwdApi-cancelInbound',
|
|
59
|
+
'AwdApi-checkInboundEligibility',
|
|
60
|
+
'AwdApi-confirmInbound',
|
|
61
|
+
'AwdApi-createInbound',
|
|
62
|
+
'AwdApi-getInbound',
|
|
63
|
+
'AwdApi-getInboundShipment',
|
|
64
|
+
'AwdApi-getInboundShipmentLabels',
|
|
65
|
+
'AwdApi-listInboundShipments',
|
|
66
|
+
'AwdApi-listInventory',
|
|
67
|
+
'AwdApi-updateInbound',
|
|
68
|
+
'AwdApi-updateInboundShipmentTransportDetails',
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
for (const operation of operations) {
|
|
72
|
+
const config = defaultRateLimitFetcher.getLimit(operation);
|
|
73
|
+
this.#defaultRateLimiterMap.set(operation, new SuperagentRateLimiter(config));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Get rate limiter for a specific operation
|
|
79
|
+
* @param {String} operation name
|
|
80
|
+
*/
|
|
81
|
+
getRateLimiter(operation) {
|
|
82
|
+
return this.#defaultRateLimiterMap.get(operation);
|
|
43
83
|
}
|
|
44
84
|
|
|
45
85
|
|
|
@@ -75,7 +115,7 @@ export class AwdApi {
|
|
|
75
115
|
return this.apiClient.callApi( 'AwdApi-cancelInbound',
|
|
76
116
|
'/awd/2024-05-09/inboundOrders/{orderId}/cancellation', 'POST',
|
|
77
117
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
78
|
-
contentTypes, accepts, returnType
|
|
118
|
+
contentTypes, accepts, returnType, this.getRateLimiter('AwdApi-cancelInbound')
|
|
79
119
|
);
|
|
80
120
|
}
|
|
81
121
|
|
|
@@ -122,7 +162,7 @@ export class AwdApi {
|
|
|
122
162
|
return this.apiClient.callApi( 'AwdApi-checkInboundEligibility',
|
|
123
163
|
'/awd/2024-05-09/inboundEligibility', 'POST',
|
|
124
164
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
125
|
-
contentTypes, accepts, returnType
|
|
165
|
+
contentTypes, accepts, returnType, this.getRateLimiter('AwdApi-checkInboundEligibility')
|
|
126
166
|
);
|
|
127
167
|
}
|
|
128
168
|
|
|
@@ -170,7 +210,7 @@ export class AwdApi {
|
|
|
170
210
|
return this.apiClient.callApi( 'AwdApi-confirmInbound',
|
|
171
211
|
'/awd/2024-05-09/inboundOrders/{orderId}/confirmation', 'POST',
|
|
172
212
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
173
|
-
contentTypes, accepts, returnType
|
|
213
|
+
contentTypes, accepts, returnType, this.getRateLimiter('AwdApi-confirmInbound')
|
|
174
214
|
);
|
|
175
215
|
}
|
|
176
216
|
|
|
@@ -217,7 +257,7 @@ export class AwdApi {
|
|
|
217
257
|
return this.apiClient.callApi( 'AwdApi-createInbound',
|
|
218
258
|
'/awd/2024-05-09/inboundOrders', 'POST',
|
|
219
259
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
220
|
-
contentTypes, accepts, returnType
|
|
260
|
+
contentTypes, accepts, returnType, this.getRateLimiter('AwdApi-createInbound')
|
|
221
261
|
);
|
|
222
262
|
}
|
|
223
263
|
|
|
@@ -265,7 +305,7 @@ export class AwdApi {
|
|
|
265
305
|
return this.apiClient.callApi( 'AwdApi-getInbound',
|
|
266
306
|
'/awd/2024-05-09/inboundOrders/{orderId}', 'GET',
|
|
267
307
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
268
|
-
contentTypes, accepts, returnType
|
|
308
|
+
contentTypes, accepts, returnType, this.getRateLimiter('AwdApi-getInbound')
|
|
269
309
|
);
|
|
270
310
|
}
|
|
271
311
|
|
|
@@ -317,7 +357,7 @@ export class AwdApi {
|
|
|
317
357
|
return this.apiClient.callApi( 'AwdApi-getInboundShipment',
|
|
318
358
|
'/awd/2024-05-09/inboundShipments/{shipmentId}', 'GET',
|
|
319
359
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
320
|
-
contentTypes, accepts, returnType
|
|
360
|
+
contentTypes, accepts, returnType, this.getRateLimiter('AwdApi-getInboundShipment')
|
|
321
361
|
);
|
|
322
362
|
}
|
|
323
363
|
|
|
@@ -373,7 +413,7 @@ export class AwdApi {
|
|
|
373
413
|
return this.apiClient.callApi( 'AwdApi-getInboundShipmentLabels',
|
|
374
414
|
'/awd/2024-05-09/inboundShipments/{shipmentId}/labels', 'GET',
|
|
375
415
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
376
|
-
contentTypes, accepts, returnType
|
|
416
|
+
contentTypes, accepts, returnType, this.getRateLimiter('AwdApi-getInboundShipmentLabels')
|
|
377
417
|
);
|
|
378
418
|
}
|
|
379
419
|
|
|
@@ -433,7 +473,7 @@ export class AwdApi {
|
|
|
433
473
|
return this.apiClient.callApi( 'AwdApi-listInboundShipments',
|
|
434
474
|
'/awd/2024-05-09/inboundShipments', 'GET',
|
|
435
475
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
436
|
-
contentTypes, accepts, returnType
|
|
476
|
+
contentTypes, accepts, returnType, this.getRateLimiter('AwdApi-listInboundShipments')
|
|
437
477
|
);
|
|
438
478
|
}
|
|
439
479
|
|
|
@@ -493,7 +533,7 @@ export class AwdApi {
|
|
|
493
533
|
return this.apiClient.callApi( 'AwdApi-listInventory',
|
|
494
534
|
'/awd/2024-05-09/inventory', 'GET',
|
|
495
535
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
496
|
-
contentTypes, accepts, returnType
|
|
536
|
+
contentTypes, accepts, returnType, this.getRateLimiter('AwdApi-listInventory')
|
|
497
537
|
);
|
|
498
538
|
}
|
|
499
539
|
|
|
@@ -552,7 +592,7 @@ export class AwdApi {
|
|
|
552
592
|
return this.apiClient.callApi( 'AwdApi-updateInbound',
|
|
553
593
|
'/awd/2024-05-09/inboundOrders/{orderId}', 'PUT',
|
|
554
594
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
555
|
-
contentTypes, accepts, returnType
|
|
595
|
+
contentTypes, accepts, returnType, this.getRateLimiter('AwdApi-updateInbound')
|
|
556
596
|
);
|
|
557
597
|
}
|
|
558
598
|
|
|
@@ -607,7 +647,7 @@ export class AwdApi {
|
|
|
607
647
|
return this.apiClient.callApi( 'AwdApi-updateInboundShipmentTransportDetails',
|
|
608
648
|
'/awd/2024-05-09/inboundShipments/{shipmentId}/transport', 'PUT',
|
|
609
649
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
610
|
-
contentTypes, accepts, returnType
|
|
650
|
+
contentTypes, accepts, returnType, this.getRateLimiter('AwdApi-updateInboundShipmentTransportDetails')
|
|
611
651
|
);
|
|
612
652
|
}
|
|
613
653
|
|
|
@@ -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 catalogitems_v2022_04_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 {ErrorList} from '../model/ErrorList.js';
|
|
16
16
|
import {Item} from '../model/Item.js';
|
|
17
17
|
import {ItemSearchResults} from '../model/ItemSearchResults.js';
|
|
18
|
+
import {SuperagentRateLimiter} from '../../../helper/SuperagentRateLimiter.mjs';
|
|
19
|
+
import {DefaultRateLimitFetcher} from '../../../helper/DefaultRateLimitFetcher.mjs';
|
|
18
20
|
|
|
19
21
|
/**
|
|
20
22
|
* Catalog service.
|
|
@@ -23,6 +25,9 @@ import {ItemSearchResults} from '../model/ItemSearchResults.js';
|
|
|
23
25
|
*/
|
|
24
26
|
export class CatalogApi {
|
|
25
27
|
|
|
28
|
+
// Private memeber stores the default rate limiters
|
|
29
|
+
#defaultRateLimiterMap;
|
|
30
|
+
|
|
26
31
|
/**
|
|
27
32
|
* Constructs a new CatalogApi.
|
|
28
33
|
* @alias module:catalogitems_v2022_04_01/api/CatalogApi
|
|
@@ -32,6 +37,32 @@ export class CatalogApi {
|
|
|
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
|
+
'CatalogApi-getCatalogItem',
|
|
51
|
+
'CatalogApi-searchCatalogItems',
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
for (const operation of operations) {
|
|
55
|
+
const config = defaultRateLimitFetcher.getLimit(operation);
|
|
56
|
+
this.#defaultRateLimiterMap.set(operation, new SuperagentRateLimiter(config));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Get rate limiter for a specific operation
|
|
62
|
+
* @param {String} operation name
|
|
63
|
+
*/
|
|
64
|
+
getRateLimiter(operation) {
|
|
65
|
+
return this.#defaultRateLimiterMap.get(operation);
|
|
35
66
|
}
|
|
36
67
|
|
|
37
68
|
|
|
@@ -80,7 +111,7 @@ export class CatalogApi {
|
|
|
80
111
|
return this.apiClient.callApi( 'CatalogApi-getCatalogItem',
|
|
81
112
|
'/catalog/2022-04-01/items/{asin}', 'GET',
|
|
82
113
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
83
|
-
contentTypes, accepts, returnType
|
|
114
|
+
contentTypes, accepts, returnType, this.getRateLimiter('CatalogApi-getCatalogItem')
|
|
84
115
|
);
|
|
85
116
|
}
|
|
86
117
|
|
|
@@ -156,7 +187,7 @@ export class CatalogApi {
|
|
|
156
187
|
return this.apiClient.callApi( 'CatalogApi-searchCatalogItems',
|
|
157
188
|
'/catalog/2022-04-01/items', 'GET',
|
|
158
189
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
159
|
-
contentTypes, accepts, returnType
|
|
190
|
+
contentTypes, accepts, returnType, this.getRateLimiter('CatalogApi-searchCatalogItems')
|
|
160
191
|
);
|
|
161
192
|
}
|
|
162
193
|
|
|
@@ -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 datakiosk_v2023_11_15/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) {
|