@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,9 +11,11 @@
|
|
|
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 {ListTransactionsResponse} from '../model/ListTransactionsResponse.js';
|
|
17
|
+
import {SuperagentRateLimiter} from '../../../helper/SuperagentRateLimiter.mjs';
|
|
18
|
+
import {DefaultRateLimitFetcher} from '../../../helper/DefaultRateLimitFetcher.mjs';
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* Default service.
|
|
@@ -22,6 +24,9 @@ import {ListTransactionsResponse} from '../model/ListTransactionsResponse.js';
|
|
|
22
24
|
*/
|
|
23
25
|
export class DefaultApi {
|
|
24
26
|
|
|
27
|
+
// Private memeber stores the default rate limiters
|
|
28
|
+
#defaultRateLimiterMap;
|
|
29
|
+
|
|
25
30
|
/**
|
|
26
31
|
* Constructs a new DefaultApi.
|
|
27
32
|
* @alias module:finances_2024_06_19/api/DefaultApi
|
|
@@ -31,6 +36,31 @@ export class DefaultApi {
|
|
|
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
|
+
'DefaultApi-listTransactions',
|
|
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
|
|
|
@@ -74,7 +104,7 @@ export class DefaultApi {
|
|
|
74
104
|
return this.apiClient.callApi( 'DefaultApi-listTransactions',
|
|
75
105
|
'/finances/2024-06-19/transactions', 'GET',
|
|
76
106
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
77
|
-
contentTypes, accepts, returnType
|
|
107
|
+
contentTypes, accepts, returnType, this.getRateLimiter('DefaultApi-listTransactions')
|
|
78
108
|
);
|
|
79
109
|
}
|
|
80
110
|
|
|
@@ -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 finances_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,9 +11,11 @@
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import {ApiClient} from
|
|
14
|
+
import {ApiClient} from '../ApiClient.js';
|
|
15
15
|
import {ListFinancialEventGroupsResponse} from '../model/ListFinancialEventGroupsResponse.js';
|
|
16
16
|
import {ListFinancialEventsResponse} from '../model/ListFinancialEventsResponse.js';
|
|
17
|
+
import {SuperagentRateLimiter} from '../../../helper/SuperagentRateLimiter.mjs';
|
|
18
|
+
import {DefaultRateLimitFetcher} from '../../../helper/DefaultRateLimitFetcher.mjs';
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* Default service.
|
|
@@ -22,6 +24,9 @@ import {ListFinancialEventsResponse} from '../model/ListFinancialEventsResponse.
|
|
|
22
24
|
*/
|
|
23
25
|
export class DefaultApi {
|
|
24
26
|
|
|
27
|
+
// Private memeber stores the default rate limiters
|
|
28
|
+
#defaultRateLimiterMap;
|
|
29
|
+
|
|
25
30
|
/**
|
|
26
31
|
* Constructs a new DefaultApi.
|
|
27
32
|
* @alias module:finances_v0/api/DefaultApi
|
|
@@ -31,6 +36,34 @@ export class DefaultApi {
|
|
|
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
|
+
'DefaultApi-listFinancialEventGroups',
|
|
50
|
+
'DefaultApi-listFinancialEvents',
|
|
51
|
+
'DefaultApi-listFinancialEventsByGroupId',
|
|
52
|
+
'DefaultApi-listFinancialEventsByOrderId',
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
for (const operation of operations) {
|
|
56
|
+
const config = defaultRateLimitFetcher.getLimit(operation);
|
|
57
|
+
this.#defaultRateLimiterMap.set(operation, new SuperagentRateLimiter(config));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Get rate limiter for a specific operation
|
|
63
|
+
* @param {String} operation name
|
|
64
|
+
*/
|
|
65
|
+
getRateLimiter(operation) {
|
|
66
|
+
return this.#defaultRateLimiterMap.get(operation);
|
|
34
67
|
}
|
|
35
68
|
|
|
36
69
|
|
|
@@ -69,7 +102,7 @@ export class DefaultApi {
|
|
|
69
102
|
return this.apiClient.callApi( 'DefaultApi-listFinancialEventGroups',
|
|
70
103
|
'/finances/v0/financialEventGroups', 'GET',
|
|
71
104
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
72
|
-
contentTypes, accepts, returnType
|
|
105
|
+
contentTypes, accepts, returnType, this.getRateLimiter('DefaultApi-listFinancialEventGroups')
|
|
73
106
|
);
|
|
74
107
|
}
|
|
75
108
|
|
|
@@ -124,7 +157,7 @@ export class DefaultApi {
|
|
|
124
157
|
return this.apiClient.callApi( 'DefaultApi-listFinancialEvents',
|
|
125
158
|
'/finances/v0/financialEvents', 'GET',
|
|
126
159
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
127
|
-
contentTypes, accepts, returnType
|
|
160
|
+
contentTypes, accepts, returnType, this.getRateLimiter('DefaultApi-listFinancialEvents')
|
|
128
161
|
);
|
|
129
162
|
}
|
|
130
163
|
|
|
@@ -186,7 +219,7 @@ export class DefaultApi {
|
|
|
186
219
|
return this.apiClient.callApi( 'DefaultApi-listFinancialEventsByGroupId',
|
|
187
220
|
'/finances/v0/financialEventGroups/{eventGroupId}/financialEvents', 'GET',
|
|
188
221
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
189
|
-
contentTypes, accepts, returnType
|
|
222
|
+
contentTypes, accepts, returnType, this.getRateLimiter('DefaultApi-listFinancialEventsByGroupId')
|
|
190
223
|
);
|
|
191
224
|
}
|
|
192
225
|
|
|
@@ -245,7 +278,7 @@ export class DefaultApi {
|
|
|
245
278
|
return this.apiClient.callApi( 'DefaultApi-listFinancialEventsByOrderId',
|
|
246
279
|
'/finances/v0/orders/{orderId}/financialEvents', 'GET',
|
|
247
280
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
248
|
-
contentTypes, accepts, returnType
|
|
281
|
+
contentTypes, accepts, returnType, this.getRateLimiter('DefaultApi-listFinancialEventsByOrderId')
|
|
249
282
|
);
|
|
250
283
|
}
|
|
251
284
|
|
|
@@ -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 fulfillmentinbound_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,12 +11,14 @@
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import {ApiClient} from
|
|
14
|
+
import {ApiClient} from '../ApiClient.js';
|
|
15
15
|
import {GetBillOfLadingResponse} from '../model/GetBillOfLadingResponse.js';
|
|
16
16
|
import {GetLabelsResponse} from '../model/GetLabelsResponse.js';
|
|
17
17
|
import {GetPrepInstructionsResponse} from '../model/GetPrepInstructionsResponse.js';
|
|
18
18
|
import {GetShipmentItemsResponse} from '../model/GetShipmentItemsResponse.js';
|
|
19
19
|
import {GetShipmentsResponse} from '../model/GetShipmentsResponse.js';
|
|
20
|
+
import {SuperagentRateLimiter} from '../../../helper/SuperagentRateLimiter.mjs';
|
|
21
|
+
import {DefaultRateLimitFetcher} from '../../../helper/DefaultRateLimitFetcher.mjs';
|
|
20
22
|
|
|
21
23
|
/**
|
|
22
24
|
* FbaInbound service.
|
|
@@ -25,6 +27,9 @@ import {GetShipmentsResponse} from '../model/GetShipmentsResponse.js';
|
|
|
25
27
|
*/
|
|
26
28
|
export class FbaInboundApi {
|
|
27
29
|
|
|
30
|
+
// Private memeber stores the default rate limiters
|
|
31
|
+
#defaultRateLimiterMap;
|
|
32
|
+
|
|
28
33
|
/**
|
|
29
34
|
* Constructs a new FbaInboundApi.
|
|
30
35
|
* @alias module:fulfillmentinbound_v0/api/FbaInboundApi
|
|
@@ -34,6 +39,36 @@ export class FbaInboundApi {
|
|
|
34
39
|
*/
|
|
35
40
|
constructor(apiClient) {
|
|
36
41
|
this.apiClient = apiClient || ApiClient.instance;
|
|
42
|
+
this.initializeDefaultRateLimiterMap();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Initialize rate limiters for API operations
|
|
47
|
+
*/
|
|
48
|
+
initializeDefaultRateLimiterMap() {
|
|
49
|
+
this.#defaultRateLimiterMap = new Map()
|
|
50
|
+
const defaultRateLimitFetcher = new DefaultRateLimitFetcher();
|
|
51
|
+
const operations = [
|
|
52
|
+
'FbaInboundApi-getBillOfLading',
|
|
53
|
+
'FbaInboundApi-getLabels',
|
|
54
|
+
'FbaInboundApi-getPrepInstructions',
|
|
55
|
+
'FbaInboundApi-getShipmentItems',
|
|
56
|
+
'FbaInboundApi-getShipmentItemsByShipmentId',
|
|
57
|
+
'FbaInboundApi-getShipments',
|
|
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);
|
|
37
72
|
}
|
|
38
73
|
|
|
39
74
|
|
|
@@ -69,7 +104,7 @@ export class FbaInboundApi {
|
|
|
69
104
|
return this.apiClient.callApi( 'FbaInboundApi-getBillOfLading',
|
|
70
105
|
'/fba/inbound/v0/shipments/{shipmentId}/billOfLading', 'GET',
|
|
71
106
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
72
|
-
contentTypes, accepts, returnType
|
|
107
|
+
contentTypes, accepts, returnType, this.getRateLimiter('FbaInboundApi-getBillOfLading')
|
|
73
108
|
);
|
|
74
109
|
}
|
|
75
110
|
|
|
@@ -143,7 +178,7 @@ export class FbaInboundApi {
|
|
|
143
178
|
return this.apiClient.callApi( 'FbaInboundApi-getLabels',
|
|
144
179
|
'/fba/inbound/v0/shipments/{shipmentId}/labels', 'GET',
|
|
145
180
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
146
|
-
contentTypes, accepts, returnType
|
|
181
|
+
contentTypes, accepts, returnType, this.getRateLimiter('FbaInboundApi-getLabels')
|
|
147
182
|
);
|
|
148
183
|
}
|
|
149
184
|
|
|
@@ -205,7 +240,7 @@ export class FbaInboundApi {
|
|
|
205
240
|
return this.apiClient.callApi( 'FbaInboundApi-getPrepInstructions',
|
|
206
241
|
'/fba/inbound/v0/prepInstructions', 'GET',
|
|
207
242
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
208
|
-
contentTypes, accepts, returnType
|
|
243
|
+
contentTypes, accepts, returnType, this.getRateLimiter('FbaInboundApi-getPrepInstructions')
|
|
209
244
|
);
|
|
210
245
|
}
|
|
211
246
|
|
|
@@ -271,7 +306,7 @@ export class FbaInboundApi {
|
|
|
271
306
|
return this.apiClient.callApi( 'FbaInboundApi-getShipmentItems',
|
|
272
307
|
'/fba/inbound/v0/shipmentItems', 'GET',
|
|
273
308
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
274
|
-
contentTypes, accepts, returnType
|
|
309
|
+
contentTypes, accepts, returnType, this.getRateLimiter('FbaInboundApi-getShipmentItems')
|
|
275
310
|
);
|
|
276
311
|
}
|
|
277
312
|
|
|
@@ -328,7 +363,7 @@ export class FbaInboundApi {
|
|
|
328
363
|
return this.apiClient.callApi( 'FbaInboundApi-getShipmentItemsByShipmentId',
|
|
329
364
|
'/fba/inbound/v0/shipments/{shipmentId}/items', 'GET',
|
|
330
365
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
331
|
-
contentTypes, accepts, returnType
|
|
366
|
+
contentTypes, accepts, returnType, this.getRateLimiter('FbaInboundApi-getShipmentItemsByShipmentId')
|
|
332
367
|
);
|
|
333
368
|
}
|
|
334
369
|
|
|
@@ -397,7 +432,7 @@ export class FbaInboundApi {
|
|
|
397
432
|
return this.apiClient.callApi( 'FbaInboundApi-getShipments',
|
|
398
433
|
'/fba/inbound/v0/shipments', 'GET',
|
|
399
434
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
400
|
-
contentTypes, accepts, returnType
|
|
435
|
+
contentTypes, accepts, returnType, this.getRateLimiter('FbaInboundApi-getShipments')
|
|
401
436
|
);
|
|
402
437
|
}
|
|
403
438
|
|