@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,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 merchantfulfillment_v0/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 {CancelShipmentResponse} from '../model/CancelShipmentResponse.js';
|
|
16
16
|
import {CreateShipmentRequest} from '../model/CreateShipmentRequest.js';
|
|
17
17
|
import {CreateShipmentResponse} from '../model/CreateShipmentResponse.js';
|
|
@@ -20,6 +20,8 @@ import {GetAdditionalSellerInputsResponse} from '../model/GetAdditionalSellerInp
|
|
|
20
20
|
import {GetEligibleShipmentServicesRequest} from '../model/GetEligibleShipmentServicesRequest.js';
|
|
21
21
|
import {GetEligibleShipmentServicesResponse} from '../model/GetEligibleShipmentServicesResponse.js';
|
|
22
22
|
import {GetShipmentResponse} from '../model/GetShipmentResponse.js';
|
|
23
|
+
import {SuperagentRateLimiter} from '../../../helper/SuperagentRateLimiter.mjs';
|
|
24
|
+
import {DefaultRateLimitFetcher} from '../../../helper/DefaultRateLimitFetcher.mjs';
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
27
|
* MerchantFulfillment service.
|
|
@@ -28,6 +30,9 @@ import {GetShipmentResponse} from '../model/GetShipmentResponse.js';
|
|
|
28
30
|
*/
|
|
29
31
|
export class MerchantFulfillmentApi {
|
|
30
32
|
|
|
33
|
+
// Private memeber stores the default rate limiters
|
|
34
|
+
#defaultRateLimiterMap;
|
|
35
|
+
|
|
31
36
|
/**
|
|
32
37
|
* Constructs a new MerchantFulfillmentApi.
|
|
33
38
|
* @alias module:merchantfulfillment_v0/api/MerchantFulfillmentApi
|
|
@@ -37,6 +42,35 @@ export class MerchantFulfillmentApi {
|
|
|
37
42
|
*/
|
|
38
43
|
constructor(apiClient) {
|
|
39
44
|
this.apiClient = apiClient || ApiClient.instance;
|
|
45
|
+
this.initializeDefaultRateLimiterMap();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Initialize rate limiters for API operations
|
|
50
|
+
*/
|
|
51
|
+
initializeDefaultRateLimiterMap() {
|
|
52
|
+
this.#defaultRateLimiterMap = new Map()
|
|
53
|
+
const defaultRateLimitFetcher = new DefaultRateLimitFetcher();
|
|
54
|
+
const operations = [
|
|
55
|
+
'MerchantFulfillmentApi-cancelShipment',
|
|
56
|
+
'MerchantFulfillmentApi-createShipment',
|
|
57
|
+
'MerchantFulfillmentApi-getAdditionalSellerInputs',
|
|
58
|
+
'MerchantFulfillmentApi-getEligibleShipmentServices',
|
|
59
|
+
'MerchantFulfillmentApi-getShipment',
|
|
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);
|
|
40
74
|
}
|
|
41
75
|
|
|
42
76
|
|
|
@@ -72,7 +106,7 @@ export class MerchantFulfillmentApi {
|
|
|
72
106
|
return this.apiClient.callApi( 'MerchantFulfillmentApi-cancelShipment',
|
|
73
107
|
'/mfn/v0/shipments/{shipmentId}', 'DELETE',
|
|
74
108
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
75
|
-
contentTypes, accepts, returnType
|
|
109
|
+
contentTypes, accepts, returnType, this.getRateLimiter('MerchantFulfillmentApi-cancelShipment')
|
|
76
110
|
);
|
|
77
111
|
}
|
|
78
112
|
|
|
@@ -119,7 +153,7 @@ export class MerchantFulfillmentApi {
|
|
|
119
153
|
return this.apiClient.callApi( 'MerchantFulfillmentApi-createShipment',
|
|
120
154
|
'/mfn/v0/shipments', 'POST',
|
|
121
155
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
122
|
-
contentTypes, accepts, returnType
|
|
156
|
+
contentTypes, accepts, returnType, this.getRateLimiter('MerchantFulfillmentApi-createShipment')
|
|
123
157
|
);
|
|
124
158
|
}
|
|
125
159
|
|
|
@@ -166,7 +200,7 @@ export class MerchantFulfillmentApi {
|
|
|
166
200
|
return this.apiClient.callApi( 'MerchantFulfillmentApi-getAdditionalSellerInputs',
|
|
167
201
|
'/mfn/v0/additionalSellerInputs', 'POST',
|
|
168
202
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
169
|
-
contentTypes, accepts, returnType
|
|
203
|
+
contentTypes, accepts, returnType, this.getRateLimiter('MerchantFulfillmentApi-getAdditionalSellerInputs')
|
|
170
204
|
);
|
|
171
205
|
}
|
|
172
206
|
|
|
@@ -213,7 +247,7 @@ export class MerchantFulfillmentApi {
|
|
|
213
247
|
return this.apiClient.callApi( 'MerchantFulfillmentApi-getEligibleShipmentServices',
|
|
214
248
|
'/mfn/v0/eligibleShippingServices', 'POST',
|
|
215
249
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
216
|
-
contentTypes, accepts, returnType
|
|
250
|
+
contentTypes, accepts, returnType, this.getRateLimiter('MerchantFulfillmentApi-getEligibleShipmentServices')
|
|
217
251
|
);
|
|
218
252
|
}
|
|
219
253
|
|
|
@@ -261,7 +295,7 @@ export class MerchantFulfillmentApi {
|
|
|
261
295
|
return this.apiClient.callApi( 'MerchantFulfillmentApi-getShipment',
|
|
262
296
|
'/mfn/v0/shipments/{shipmentId}', 'GET',
|
|
263
297
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
264
|
-
contentTypes, accepts, returnType
|
|
298
|
+
contentTypes, accepts, returnType, this.getRateLimiter('MerchantFulfillmentApi-getShipment')
|
|
265
299
|
);
|
|
266
300
|
}
|
|
267
301
|
|
|
@@ -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 messaging_v1/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 {CreateAmazonMotorsRequest} from '../model/CreateAmazonMotorsRequest.js';
|
|
16
16
|
import {CreateAmazonMotorsResponse} from '../model/CreateAmazonMotorsResponse.js';
|
|
17
17
|
import {CreateConfirmCustomizationDetailsRequest} from '../model/CreateConfirmCustomizationDetailsRequest.js';
|
|
@@ -35,6 +35,8 @@ import {GetAttributesResponse} from '../model/GetAttributesResponse.js';
|
|
|
35
35
|
import {GetMessagingActionsForOrderResponse} from '../model/GetMessagingActionsForOrderResponse.js';
|
|
36
36
|
import {InvoiceRequest} from '../model/InvoiceRequest.js';
|
|
37
37
|
import {InvoiceResponse} from '../model/InvoiceResponse.js';
|
|
38
|
+
import {SuperagentRateLimiter} from '../../../helper/SuperagentRateLimiter.mjs';
|
|
39
|
+
import {DefaultRateLimitFetcher} from '../../../helper/DefaultRateLimitFetcher.mjs';
|
|
38
40
|
|
|
39
41
|
/**
|
|
40
42
|
* Messaging service.
|
|
@@ -43,6 +45,9 @@ import {InvoiceResponse} from '../model/InvoiceResponse.js';
|
|
|
43
45
|
*/
|
|
44
46
|
export class MessagingApi {
|
|
45
47
|
|
|
48
|
+
// Private memeber stores the default rate limiters
|
|
49
|
+
#defaultRateLimiterMap;
|
|
50
|
+
|
|
46
51
|
/**
|
|
47
52
|
* Constructs a new MessagingApi.
|
|
48
53
|
* @alias module:messaging_v1/api/MessagingApi
|
|
@@ -52,6 +57,43 @@ export class MessagingApi {
|
|
|
52
57
|
*/
|
|
53
58
|
constructor(apiClient) {
|
|
54
59
|
this.apiClient = apiClient || ApiClient.instance;
|
|
60
|
+
this.initializeDefaultRateLimiterMap();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Initialize rate limiters for API operations
|
|
65
|
+
*/
|
|
66
|
+
initializeDefaultRateLimiterMap() {
|
|
67
|
+
this.#defaultRateLimiterMap = new Map()
|
|
68
|
+
const defaultRateLimitFetcher = new DefaultRateLimitFetcher();
|
|
69
|
+
const operations = [
|
|
70
|
+
'MessagingApi-confirmCustomizationDetails',
|
|
71
|
+
'MessagingApi-createAmazonMotors',
|
|
72
|
+
'MessagingApi-createConfirmDeliveryDetails',
|
|
73
|
+
'MessagingApi-createConfirmOrderDetails',
|
|
74
|
+
'MessagingApi-createConfirmServiceDetails',
|
|
75
|
+
'MessagingApi-createDigitalAccessKey',
|
|
76
|
+
'MessagingApi-createLegalDisclosure',
|
|
77
|
+
'MessagingApi-createNegativeFeedbackRemoval',
|
|
78
|
+
'MessagingApi-createUnexpectedProblem',
|
|
79
|
+
'MessagingApi-createWarranty',
|
|
80
|
+
'MessagingApi-getAttributes',
|
|
81
|
+
'MessagingApi-getMessagingActionsForOrder',
|
|
82
|
+
'MessagingApi-sendInvoice',
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
for (const operation of operations) {
|
|
86
|
+
const config = defaultRateLimitFetcher.getLimit(operation);
|
|
87
|
+
this.#defaultRateLimiterMap.set(operation, new SuperagentRateLimiter(config));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Get rate limiter for a specific operation
|
|
93
|
+
* @param {String} operation name
|
|
94
|
+
*/
|
|
95
|
+
getRateLimiter(operation) {
|
|
96
|
+
return this.#defaultRateLimiterMap.get(operation);
|
|
55
97
|
}
|
|
56
98
|
|
|
57
99
|
|
|
@@ -100,7 +142,7 @@ export class MessagingApi {
|
|
|
100
142
|
return this.apiClient.callApi( 'MessagingApi-confirmCustomizationDetails',
|
|
101
143
|
'/messaging/v1/orders/{amazonOrderId}/messages/confirmCustomizationDetails', 'POST',
|
|
102
144
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
103
|
-
contentTypes, accepts, returnType
|
|
145
|
+
contentTypes, accepts, returnType, this.getRateLimiter('MessagingApi-confirmCustomizationDetails')
|
|
104
146
|
);
|
|
105
147
|
}
|
|
106
148
|
|
|
@@ -163,7 +205,7 @@ export class MessagingApi {
|
|
|
163
205
|
return this.apiClient.callApi( 'MessagingApi-createAmazonMotors',
|
|
164
206
|
'/messaging/v1/orders/{amazonOrderId}/messages/amazonMotors', 'POST',
|
|
165
207
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
166
|
-
contentTypes, accepts, returnType
|
|
208
|
+
contentTypes, accepts, returnType, this.getRateLimiter('MessagingApi-createAmazonMotors')
|
|
167
209
|
);
|
|
168
210
|
}
|
|
169
211
|
|
|
@@ -226,7 +268,7 @@ export class MessagingApi {
|
|
|
226
268
|
return this.apiClient.callApi( 'MessagingApi-createConfirmDeliveryDetails',
|
|
227
269
|
'/messaging/v1/orders/{amazonOrderId}/messages/confirmDeliveryDetails', 'POST',
|
|
228
270
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
229
|
-
contentTypes, accepts, returnType
|
|
271
|
+
contentTypes, accepts, returnType, this.getRateLimiter('MessagingApi-createConfirmDeliveryDetails')
|
|
230
272
|
);
|
|
231
273
|
}
|
|
232
274
|
|
|
@@ -289,7 +331,7 @@ export class MessagingApi {
|
|
|
289
331
|
return this.apiClient.callApi( 'MessagingApi-createConfirmOrderDetails',
|
|
290
332
|
'/messaging/v1/orders/{amazonOrderId}/messages/confirmOrderDetails', 'POST',
|
|
291
333
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
292
|
-
contentTypes, accepts, returnType
|
|
334
|
+
contentTypes, accepts, returnType, this.getRateLimiter('MessagingApi-createConfirmOrderDetails')
|
|
293
335
|
);
|
|
294
336
|
}
|
|
295
337
|
|
|
@@ -352,7 +394,7 @@ export class MessagingApi {
|
|
|
352
394
|
return this.apiClient.callApi( 'MessagingApi-createConfirmServiceDetails',
|
|
353
395
|
'/messaging/v1/orders/{amazonOrderId}/messages/confirmServiceDetails', 'POST',
|
|
354
396
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
355
|
-
contentTypes, accepts, returnType
|
|
397
|
+
contentTypes, accepts, returnType, this.getRateLimiter('MessagingApi-createConfirmServiceDetails')
|
|
356
398
|
);
|
|
357
399
|
}
|
|
358
400
|
|
|
@@ -415,7 +457,7 @@ export class MessagingApi {
|
|
|
415
457
|
return this.apiClient.callApi( 'MessagingApi-createDigitalAccessKey',
|
|
416
458
|
'/messaging/v1/orders/{amazonOrderId}/messages/digitalAccessKey', 'POST',
|
|
417
459
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
418
|
-
contentTypes, accepts, returnType
|
|
460
|
+
contentTypes, accepts, returnType, this.getRateLimiter('MessagingApi-createDigitalAccessKey')
|
|
419
461
|
);
|
|
420
462
|
}
|
|
421
463
|
|
|
@@ -478,7 +520,7 @@ export class MessagingApi {
|
|
|
478
520
|
return this.apiClient.callApi( 'MessagingApi-createLegalDisclosure',
|
|
479
521
|
'/messaging/v1/orders/{amazonOrderId}/messages/legalDisclosure', 'POST',
|
|
480
522
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
481
|
-
contentTypes, accepts, returnType
|
|
523
|
+
contentTypes, accepts, returnType, this.getRateLimiter('MessagingApi-createLegalDisclosure')
|
|
482
524
|
);
|
|
483
525
|
}
|
|
484
526
|
|
|
@@ -535,7 +577,7 @@ export class MessagingApi {
|
|
|
535
577
|
return this.apiClient.callApi( 'MessagingApi-createNegativeFeedbackRemoval',
|
|
536
578
|
'/messaging/v1/orders/{amazonOrderId}/messages/negativeFeedbackRemoval', 'POST',
|
|
537
579
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
538
|
-
contentTypes, accepts, returnType
|
|
580
|
+
contentTypes, accepts, returnType, this.getRateLimiter('MessagingApi-createNegativeFeedbackRemoval')
|
|
539
581
|
);
|
|
540
582
|
}
|
|
541
583
|
|
|
@@ -597,7 +639,7 @@ export class MessagingApi {
|
|
|
597
639
|
return this.apiClient.callApi( 'MessagingApi-createUnexpectedProblem',
|
|
598
640
|
'/messaging/v1/orders/{amazonOrderId}/messages/unexpectedProblem', 'POST',
|
|
599
641
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
600
|
-
contentTypes, accepts, returnType
|
|
642
|
+
contentTypes, accepts, returnType, this.getRateLimiter('MessagingApi-createUnexpectedProblem')
|
|
601
643
|
);
|
|
602
644
|
}
|
|
603
645
|
|
|
@@ -660,7 +702,7 @@ export class MessagingApi {
|
|
|
660
702
|
return this.apiClient.callApi( 'MessagingApi-createWarranty',
|
|
661
703
|
'/messaging/v1/orders/{amazonOrderId}/messages/warranty', 'POST',
|
|
662
704
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
663
|
-
contentTypes, accepts, returnType
|
|
705
|
+
contentTypes, accepts, returnType, this.getRateLimiter('MessagingApi-createWarranty')
|
|
664
706
|
);
|
|
665
707
|
}
|
|
666
708
|
|
|
@@ -717,7 +759,7 @@ export class MessagingApi {
|
|
|
717
759
|
return this.apiClient.callApi( 'MessagingApi-getAttributes',
|
|
718
760
|
'/messaging/v1/orders/{amazonOrderId}/attributes', 'GET',
|
|
719
761
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
720
|
-
contentTypes, accepts, returnType
|
|
762
|
+
contentTypes, accepts, returnType, this.getRateLimiter('MessagingApi-getAttributes')
|
|
721
763
|
);
|
|
722
764
|
}
|
|
723
765
|
|
|
@@ -773,7 +815,7 @@ export class MessagingApi {
|
|
|
773
815
|
return this.apiClient.callApi( 'MessagingApi-getMessagingActionsForOrder',
|
|
774
816
|
'/messaging/v1/orders/{amazonOrderId}', 'GET',
|
|
775
817
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
776
|
-
contentTypes, accepts, returnType
|
|
818
|
+
contentTypes, accepts, returnType, this.getRateLimiter('MessagingApi-getMessagingActionsForOrder')
|
|
777
819
|
);
|
|
778
820
|
}
|
|
779
821
|
|
|
@@ -835,7 +877,7 @@ export class MessagingApi {
|
|
|
835
877
|
return this.apiClient.callApi( 'MessagingApi-sendInvoice',
|
|
836
878
|
'/messaging/v1/orders/{amazonOrderId}/messages/invoice', 'POST',
|
|
837
879
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
838
|
-
contentTypes, accepts, returnType
|
|
880
|
+
contentTypes, accepts, returnType, this.getRateLimiter('MessagingApi-sendInvoice')
|
|
839
881
|
);
|
|
840
882
|
}
|
|
841
883
|
|