@amazon-sp-api-release/amazon-sp-api-sdk-js 1.0.0-rc7 → 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 +104 -0
- 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,11 +11,13 @@
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import {ApiClient} from
|
|
14
|
+
import {ApiClient} from '../ApiClient.js';
|
|
15
15
|
import {GetInvoiceStatusResponse} from '../model/GetInvoiceStatusResponse.js';
|
|
16
16
|
import {GetShipmentDetailsResponse} from '../model/GetShipmentDetailsResponse.js';
|
|
17
17
|
import {SubmitInvoiceRequest} from '../model/SubmitInvoiceRequest.js';
|
|
18
18
|
import {SubmitInvoiceResponse} from '../model/SubmitInvoiceResponse.js';
|
|
19
|
+
import {SuperagentRateLimiter} from '../../../helper/SuperagentRateLimiter.mjs';
|
|
20
|
+
import {DefaultRateLimitFetcher} from '../../../helper/DefaultRateLimitFetcher.mjs';
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* ShipmentInvoice service.
|
|
@@ -24,6 +26,9 @@ import {SubmitInvoiceResponse} from '../model/SubmitInvoiceResponse.js';
|
|
|
24
26
|
*/
|
|
25
27
|
export class ShipmentInvoiceApi {
|
|
26
28
|
|
|
29
|
+
// Private memeber stores the default rate limiters
|
|
30
|
+
#defaultRateLimiterMap;
|
|
31
|
+
|
|
27
32
|
/**
|
|
28
33
|
* Constructs a new ShipmentInvoiceApi.
|
|
29
34
|
* @alias module:invoicing_v0/api/ShipmentInvoiceApi
|
|
@@ -33,6 +38,33 @@ export class ShipmentInvoiceApi {
|
|
|
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
|
+
'ShipmentInvoiceApi-getInvoiceStatus',
|
|
52
|
+
'ShipmentInvoiceApi-getShipmentDetails',
|
|
53
|
+
'ShipmentInvoiceApi-submitInvoice',
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
for (const operation of operations) {
|
|
57
|
+
const config = defaultRateLimitFetcher.getLimit(operation);
|
|
58
|
+
this.#defaultRateLimiterMap.set(operation, new SuperagentRateLimiter(config));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Get rate limiter for a specific operation
|
|
64
|
+
* @param {String} operation name
|
|
65
|
+
*/
|
|
66
|
+
getRateLimiter(operation) {
|
|
67
|
+
return this.#defaultRateLimiterMap.get(operation);
|
|
36
68
|
}
|
|
37
69
|
|
|
38
70
|
|
|
@@ -68,7 +100,7 @@ export class ShipmentInvoiceApi {
|
|
|
68
100
|
return this.apiClient.callApi( 'ShipmentInvoiceApi-getInvoiceStatus',
|
|
69
101
|
'/fba/outbound/brazil/v0/shipments/{shipmentId}/invoice/status', 'GET',
|
|
70
102
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
71
|
-
contentTypes, accepts, returnType
|
|
103
|
+
contentTypes, accepts, returnType, this.getRateLimiter('ShipmentInvoiceApi-getInvoiceStatus')
|
|
72
104
|
);
|
|
73
105
|
}
|
|
74
106
|
|
|
@@ -116,7 +148,7 @@ export class ShipmentInvoiceApi {
|
|
|
116
148
|
return this.apiClient.callApi( 'ShipmentInvoiceApi-getShipmentDetails',
|
|
117
149
|
'/fba/outbound/brazil/v0/shipments/{shipmentId}', 'GET',
|
|
118
150
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
119
|
-
contentTypes, accepts, returnType
|
|
151
|
+
contentTypes, accepts, returnType, this.getRateLimiter('ShipmentInvoiceApi-getShipmentDetails')
|
|
120
152
|
);
|
|
121
153
|
}
|
|
122
154
|
|
|
@@ -170,7 +202,7 @@ export class ShipmentInvoiceApi {
|
|
|
170
202
|
return this.apiClient.callApi( 'ShipmentInvoiceApi-submitInvoice',
|
|
171
203
|
'/fba/outbound/brazil/v0/shipments/{shipmentId}/invoice', 'POST',
|
|
172
204
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
173
|
-
contentTypes, accepts, returnType
|
|
205
|
+
contentTypes, accepts, returnType, this.getRateLimiter('ShipmentInvoiceApi-submitInvoice')
|
|
174
206
|
);
|
|
175
207
|
}
|
|
176
208
|
|
|
@@ -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 listingsitems_v2021_08_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,13 +11,15 @@
|
|
|
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
18
|
import {ListingsItemPatchRequest} from '../model/ListingsItemPatchRequest.js';
|
|
19
19
|
import {ListingsItemPutRequest} from '../model/ListingsItemPutRequest.js';
|
|
20
20
|
import {ListingsItemSubmissionResponse} from '../model/ListingsItemSubmissionResponse.js';
|
|
21
|
+
import {SuperagentRateLimiter} from '../../../helper/SuperagentRateLimiter.mjs';
|
|
22
|
+
import {DefaultRateLimitFetcher} from '../../../helper/DefaultRateLimitFetcher.mjs';
|
|
21
23
|
|
|
22
24
|
/**
|
|
23
25
|
* Listings service.
|
|
@@ -26,6 +28,9 @@ import {ListingsItemSubmissionResponse} from '../model/ListingsItemSubmissionRes
|
|
|
26
28
|
*/
|
|
27
29
|
export class ListingsApi {
|
|
28
30
|
|
|
31
|
+
// Private memeber stores the default rate limiters
|
|
32
|
+
#defaultRateLimiterMap;
|
|
33
|
+
|
|
29
34
|
/**
|
|
30
35
|
* Constructs a new ListingsApi.
|
|
31
36
|
* @alias module:listingsitems_v2021_08_01/api/ListingsApi
|
|
@@ -35,6 +40,35 @@ export class ListingsApi {
|
|
|
35
40
|
*/
|
|
36
41
|
constructor(apiClient) {
|
|
37
42
|
this.apiClient = apiClient || ApiClient.instance;
|
|
43
|
+
this.initializeDefaultRateLimiterMap();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Initialize rate limiters for API operations
|
|
48
|
+
*/
|
|
49
|
+
initializeDefaultRateLimiterMap() {
|
|
50
|
+
this.#defaultRateLimiterMap = new Map()
|
|
51
|
+
const defaultRateLimitFetcher = new DefaultRateLimitFetcher();
|
|
52
|
+
const operations = [
|
|
53
|
+
'ListingsApi-deleteListingsItem',
|
|
54
|
+
'ListingsApi-getListingsItem',
|
|
55
|
+
'ListingsApi-patchListingsItem',
|
|
56
|
+
'ListingsApi-putListingsItem',
|
|
57
|
+
'ListingsApi-searchListingsItems',
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
for (const operation of operations) {
|
|
61
|
+
const config = defaultRateLimitFetcher.getLimit(operation);
|
|
62
|
+
this.#defaultRateLimiterMap.set(operation, new SuperagentRateLimiter(config));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Get rate limiter for a specific operation
|
|
68
|
+
* @param {String} operation name
|
|
69
|
+
*/
|
|
70
|
+
getRateLimiter(operation) {
|
|
71
|
+
return this.#defaultRateLimiterMap.get(operation);
|
|
38
72
|
}
|
|
39
73
|
|
|
40
74
|
|
|
@@ -88,7 +122,7 @@ export class ListingsApi {
|
|
|
88
122
|
return this.apiClient.callApi( 'ListingsApi-deleteListingsItem',
|
|
89
123
|
'/listings/2021-08-01/items/{sellerId}/{sku}', 'DELETE',
|
|
90
124
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
91
|
-
contentTypes, accepts, returnType
|
|
125
|
+
contentTypes, accepts, returnType, this.getRateLimiter('ListingsApi-deleteListingsItem')
|
|
92
126
|
);
|
|
93
127
|
}
|
|
94
128
|
|
|
@@ -160,7 +194,7 @@ export class ListingsApi {
|
|
|
160
194
|
return this.apiClient.callApi( 'ListingsApi-getListingsItem',
|
|
161
195
|
'/listings/2021-08-01/items/{sellerId}/{sku}', 'GET',
|
|
162
196
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
163
|
-
contentTypes, accepts, returnType
|
|
197
|
+
contentTypes, accepts, returnType, this.getRateLimiter('ListingsApi-getListingsItem')
|
|
164
198
|
);
|
|
165
199
|
}
|
|
166
200
|
|
|
@@ -241,7 +275,7 @@ export class ListingsApi {
|
|
|
241
275
|
return this.apiClient.callApi( 'ListingsApi-patchListingsItem',
|
|
242
276
|
'/listings/2021-08-01/items/{sellerId}/{sku}', 'PATCH',
|
|
243
277
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
244
|
-
contentTypes, accepts, returnType
|
|
278
|
+
contentTypes, accepts, returnType, this.getRateLimiter('ListingsApi-patchListingsItem')
|
|
245
279
|
);
|
|
246
280
|
}
|
|
247
281
|
|
|
@@ -324,7 +358,7 @@ export class ListingsApi {
|
|
|
324
358
|
return this.apiClient.callApi( 'ListingsApi-putListingsItem',
|
|
325
359
|
'/listings/2021-08-01/items/{sellerId}/{sku}', 'PUT',
|
|
326
360
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
327
|
-
contentTypes, accepts, returnType
|
|
361
|
+
contentTypes, accepts, returnType, this.getRateLimiter('ListingsApi-putListingsItem')
|
|
328
362
|
);
|
|
329
363
|
}
|
|
330
364
|
|
|
@@ -422,7 +456,7 @@ export class ListingsApi {
|
|
|
422
456
|
return this.apiClient.callApi( 'ListingsApi-searchListingsItems',
|
|
423
457
|
'/listings/2021-08-01/items/{sellerId}', 'GET',
|
|
424
458
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
425
|
-
contentTypes, accepts, returnType
|
|
459
|
+
contentTypes, accepts, returnType, this.getRateLimiter('ListingsApi-searchListingsItems')
|
|
426
460
|
);
|
|
427
461
|
}
|
|
428
462
|
|
|
@@ -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 listingsrestrictions_v2021_08_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,9 +11,11 @@
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import {ApiClient} from
|
|
14
|
+
import {ApiClient} from '../ApiClient.js';
|
|
15
15
|
import {Error} from '../model/Error.js';
|
|
16
16
|
import {RestrictionList} from '../model/RestrictionList.js';
|
|
17
|
+
import {SuperagentRateLimiter} from '../../../helper/SuperagentRateLimiter.mjs';
|
|
18
|
+
import {DefaultRateLimitFetcher} from '../../../helper/DefaultRateLimitFetcher.mjs';
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* Listings service.
|
|
@@ -22,6 +24,9 @@ import {RestrictionList} from '../model/RestrictionList.js';
|
|
|
22
24
|
*/
|
|
23
25
|
export class ListingsApi {
|
|
24
26
|
|
|
27
|
+
// Private memeber stores the default rate limiters
|
|
28
|
+
#defaultRateLimiterMap;
|
|
29
|
+
|
|
25
30
|
/**
|
|
26
31
|
* Constructs a new ListingsApi.
|
|
27
32
|
* @alias module:listingsrestrictions_v2021_08_01/api/ListingsApi
|
|
@@ -31,6 +36,31 @@ export class ListingsApi {
|
|
|
31
36
|
*/
|
|
32
37
|
constructor(apiClient) {
|
|
33
38
|
this.apiClient = apiClient || ApiClient.instance;
|
|
39
|
+
this.initializeDefaultRateLimiterMap();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Initialize rate limiters for API operations
|
|
44
|
+
*/
|
|
45
|
+
initializeDefaultRateLimiterMap() {
|
|
46
|
+
this.#defaultRateLimiterMap = new Map()
|
|
47
|
+
const defaultRateLimitFetcher = new DefaultRateLimitFetcher();
|
|
48
|
+
const operations = [
|
|
49
|
+
'ListingsApi-getListingsRestrictions',
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
for (const operation of operations) {
|
|
53
|
+
const config = defaultRateLimitFetcher.getLimit(operation);
|
|
54
|
+
this.#defaultRateLimiterMap.set(operation, new SuperagentRateLimiter(config));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Get rate limiter for a specific operation
|
|
60
|
+
* @param {String} operation name
|
|
61
|
+
*/
|
|
62
|
+
getRateLimiter(operation) {
|
|
63
|
+
return this.#defaultRateLimiterMap.get(operation);
|
|
34
64
|
}
|
|
35
65
|
|
|
36
66
|
|
|
@@ -86,7 +116,7 @@ export class ListingsApi {
|
|
|
86
116
|
return this.apiClient.callApi( 'ListingsApi-getListingsRestrictions',
|
|
87
117
|
'/listings/2021-08-01/restrictions', 'GET',
|
|
88
118
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
89
|
-
contentTypes, accepts, returnType
|
|
119
|
+
contentTypes, accepts, returnType, this.getRateLimiter('ListingsApi-getListingsRestrictions')
|
|
90
120
|
);
|
|
91
121
|
}
|
|
92
122
|
|