@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.
Files changed (109) hide show
  1. package/README.md +1 -1
  2. package/helper/DefaultRateLimitFetcher.mjs +2 -35
  3. package/helper/DefaultRateLimitMap.mjs +266 -0
  4. package/helper/SuperagentRateLimiter.mjs +26 -14
  5. package/package.json +1 -1
  6. package/sample-node-app/index.js +27 -13
  7. package/src/apluscontent_v2020_11_01/ApiClient.js +48 -38
  8. package/src/apluscontent_v2020_11_01/api/AplusContentApi.js +50 -11
  9. package/src/appintegrations_v2024_04_01/ApiClient.js +48 -38
  10. package/src/appintegrations_v2024_04_01/api/AppIntegrationsApi.js +36 -4
  11. package/src/applications_v2023_11_30/ApiClient.js +48 -38
  12. package/src/applications_v2023_11_30/api/ApplicationsApi.js +32 -2
  13. package/src/awd_v2024_05_09/ApiClient.js +48 -38
  14. package/src/awd_v2024_05_09/api/AwdApi.js +52 -12
  15. package/src/catalogitems_v2022_04_01/ApiClient.js +48 -38
  16. package/src/catalogitems_v2022_04_01/api/CatalogApi.js +34 -3
  17. package/src/datakiosk_v2023_11_15/ApiClient.js +48 -38
  18. package/src/datakiosk_v2023_11_15/api/QueriesApi.js +40 -6
  19. package/src/easyship_v2022_03_23/ApiClient.js +48 -38
  20. package/src/easyship_v2022_03_23/api/EasyShipApi.js +40 -6
  21. package/src/fbaeligibility_v1/ApiClient.js +48 -38
  22. package/src/fbaeligibility_v1/api/FbaInboundApi.js +32 -2
  23. package/src/fbainventory_v1/ApiClient.js +48 -38
  24. package/src/fbainventory_v1/api/FbaInventoryApi.js +38 -5
  25. package/src/feeds_v2021_06_30/ApiClient.js +48 -38
  26. package/src/feeds_v2021_06_30/api/FeedsApi.js +42 -7
  27. package/src/finances_2024_06_19/ApiClient.js +48 -38
  28. package/src/finances_2024_06_19/api/DefaultApi.js +32 -2
  29. package/src/finances_v0/ApiClient.js +48 -38
  30. package/src/finances_v0/api/DefaultApi.js +38 -5
  31. package/src/fulfillmentinbound_v0/ApiClient.js +48 -38
  32. package/src/fulfillmentinbound_v0/api/FbaInboundApi.js +42 -7
  33. package/src/fulfillmentinbound_v2024_03_20/ApiClient.js +48 -38
  34. package/src/fulfillmentinbound_v2024_03_20/api/FbaInboundApi.js +120 -46
  35. package/src/fulfillmentoutbound_v2020_07_01/ApiClient.js +48 -38
  36. package/src/fulfillmentoutbound_v2020_07_01/api/FbaOutboundApi.js +58 -15
  37. package/src/invoices_v2024_06_19/ApiClient.js +48 -38
  38. package/src/invoices_v2024_06_19/api/InvoicesApi.js +44 -8
  39. package/src/invoicing_v0/ApiClient.js +48 -38
  40. package/src/invoicing_v0/api/ShipmentInvoiceApi.js +36 -4
  41. package/src/listingsitems_v2021_08_01/ApiClient.js +48 -38
  42. package/src/listingsitems_v2021_08_01/api/ListingsApi.js +40 -6
  43. package/src/listingsrestrictions_v2021_08_01/ApiClient.js +48 -38
  44. package/src/listingsrestrictions_v2021_08_01/api/ListingsApi.js +32 -2
  45. package/src/merchantfulfillment_v0/ApiClient.js +48 -38
  46. package/src/merchantfulfillment_v0/api/MerchantFulfillmentApi.js +40 -6
  47. package/src/messaging_v1/ApiClient.js +48 -38
  48. package/src/messaging_v1/api/MessagingApi.js +56 -14
  49. package/src/notifications_v1/ApiClient.js +48 -38
  50. package/src/notifications_v1/api/NotificationsApi.js +46 -9
  51. package/src/orders_v0/ApiClient.js +48 -38
  52. package/src/orders_v0/api/OrdersV0Api.js +48 -10
  53. package/src/orders_v0/api/ShipmentApi.js +32 -2
  54. package/src/pricing_v0/ApiClient.js +48 -38
  55. package/src/pricing_v0/api/ProductPricingApi.js +42 -7
  56. package/src/pricing_v2022_05_01/ApiClient.js +48 -38
  57. package/src/pricing_v2022_05_01/api/ProductPricingApi.js +34 -3
  58. package/src/productfees_v0/ApiClient.js +48 -38
  59. package/src/productfees_v0/api/FeesApi.js +36 -4
  60. package/src/producttypedefinitions_v2020_09_01/ApiClient.js +48 -38
  61. package/src/producttypedefinitions_v2020_09_01/api/DefinitionsApi.js +34 -3
  62. package/src/replenishment_v2022_11_07/ApiClient.js +48 -38
  63. package/src/replenishment_v2022_11_07/api/OffersApi.js +34 -3
  64. package/src/replenishment_v2022_11_07/api/SellingpartnersApi.js +32 -2
  65. package/src/reports_v2021_06_30/ApiClient.js +48 -38
  66. package/src/reports_v2021_06_30/api/ReportsApi.js +48 -10
  67. package/src/sales_v1/ApiClient.js +48 -38
  68. package/src/sales_v1/api/SalesApi.js +32 -2
  69. package/src/sellers_v1/ApiClient.js +48 -38
  70. package/src/sellers_v1/api/SellersApi.js +34 -3
  71. package/src/services_v1/ApiClient.js +48 -38
  72. package/src/services_v1/api/ServiceApi.js +64 -18
  73. package/src/shipping_v2/ApiClient.js +48 -38
  74. package/src/shipping_v2/api/ShippingApi.js +70 -21
  75. package/src/solicitations_v1/ApiClient.js +48 -38
  76. package/src/solicitations_v1/api/SolicitationsApi.js +34 -3
  77. package/src/supplysources_v2020_07_01/ApiClient.js +48 -38
  78. package/src/supplysources_v2020_07_01/api/SupplySourcesApi.js +42 -7
  79. package/src/tokens_v2021_03_01/ApiClient.js +48 -38
  80. package/src/tokens_v2021_03_01/api/TokensApi.js +32 -2
  81. package/src/transfers_v2024_06_01/ApiClient.js +48 -38
  82. package/src/transfers_v2024_06_01/api/DefaultApi.js +34 -3
  83. package/src/uploads_v2020_11_01/ApiClient.js +48 -38
  84. package/src/uploads_v2020_11_01/api/UploadsApi.js +32 -2
  85. package/src/vehicles_v2024_11_01/ApiClient.js +48 -38
  86. package/src/vehicles_v2024_11_01/api/AutomotiveApi.js +32 -2
  87. package/src/vehicles_v2024_11_01/api/VehiclesApi.js +32 -2
  88. package/src/vendordfinventory_v1/ApiClient.js +48 -38
  89. package/src/vendordfinventory_v1/api/UpdateInventoryApi.js +32 -2
  90. package/src/vendordforders_v2021_12_28/ApiClient.js +48 -38
  91. package/src/vendordforders_v2021_12_28/api/VendorOrdersApi.js +36 -4
  92. package/src/vendordfpayments_v1/ApiClient.js +48 -38
  93. package/src/vendordfpayments_v1/api/VendorInvoiceApi.js +32 -2
  94. package/src/vendordfshipping_v2021_12_28/ApiClient.js +48 -38
  95. package/src/vendordfshipping_v2021_12_28/api/CreateContainerLabelApi.js +32 -2
  96. package/src/vendordfshipping_v2021_12_28/api/CustomerInvoicesApi.js +34 -3
  97. package/src/vendordfshipping_v2021_12_28/api/VendorShippingApi.js +38 -5
  98. package/src/vendordfshipping_v2021_12_28/api/VendorShippingLabelsApi.js +38 -5
  99. package/src/vendordftransactions_v2021_12_28/ApiClient.js +48 -38
  100. package/src/vendordftransactions_v2021_12_28/api/VendorTransactionApi.js +32 -2
  101. package/src/vendorinvoices_v1/ApiClient.js +48 -38
  102. package/src/vendorinvoices_v1/api/VendorPaymentsApi.js +32 -2
  103. package/src/vendororders_v1/ApiClient.js +48 -38
  104. package/src/vendororders_v1/api/VendorOrdersApi.js +38 -5
  105. package/src/vendorshipments_v1/ApiClient.js +48 -38
  106. package/src/vendorshipments_v1/api/VendorShippingApi.js +38 -5
  107. package/src/vendortransactionstatus_v1/ApiClient.js +48 -38
  108. package/src/vendortransactionstatus_v1/api/VendorTransactionApi.js +32 -2
  109. package/helper/rate-limits.yml +0 -874
@@ -11,12 +11,11 @@
11
11
  *
12
12
  */
13
13
 
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";
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 fulfillmentoutbound_v2020_07_01/ApiClient
@@ -193,9 +192,8 @@ export class ApiClient {
193
192
  #tokenForApiCall = null;
194
193
  #lwaClient = null;
195
194
  #rdtClient = null;
196
- #defaultRateLimitFetcher = null;
197
- #customizedRateLimiter = null;
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
- * Initialize #defaultRateLimitFetcher
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
- async initializeDefaultRateLimit() {
268
- try {
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
- * Enable default rate limiter
279
+ * Disable customized rate limiter for one operation
280
+ * Fall back to default rate limiter
281
+ * @param {String} operationName
277
282
  */
278
- enableDefaultRateLimiter() {
279
- this.#useDefaultRateLimiter = true;
280
- this.#customizedRateLimiter = null;
283
+ disableCustomizedRatelimiterForOperation(operationName) {
284
+ this.#customizedRateLimiterMap.delete(operationName);
281
285
  }
282
286
 
283
287
  /**
284
- * Set customized rate limiter
285
- * @param {RateLimitConfiguration} config
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
- enableCustomizedRateLimiter(config) {
288
- this.#customizedRateLimiter = new SuperagentRateLimiter(config);
289
- this.#useDefaultRateLimiter = false;
299
+ disableRateLimiter() {
300
+ this.#useRateLimiter = false;
290
301
  }
291
302
 
292
303
  /**
293
- * Disable both customized and default rate limiter
304
+ * Enable default or customized rate limiter for all operations
294
305
  */
295
- disableRatelimiter() {
296
- this.#customizedRateLimiter = null;
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
- //Set rate limiter
613
- if (this.#useDefaultRateLimiter) {
614
- await this.initializeDefaultRateLimit();
615
- const defaultRateLimiter = new SuperagentRateLimiter(this.#defaultRateLimitFetcher.getLimit(operation));
616
- request.use(defaultRateLimiter.getPlugin());
617
- } else if (this.#customizedRateLimiter) {
618
- request.use(this.#customizedRateLimiter.getPlugin());
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 "../ApiClient.js";
14
+ import {ApiClient} from '../ApiClient.js';
15
15
  import {CancelFulfillmentOrderResponse} from '../model/CancelFulfillmentOrderResponse.js';
16
16
  import {CreateFulfillmentOrderRequest} from '../model/CreateFulfillmentOrderRequest.js';
17
17
  import {CreateFulfillmentOrderResponse} from '../model/CreateFulfillmentOrderResponse.js';
@@ -32,6 +32,8 @@ import {SubmitFulfillmentOrderStatusUpdateRequest} from '../model/SubmitFulfillm
32
32
  import {SubmitFulfillmentOrderStatusUpdateResponse} from '../model/SubmitFulfillmentOrderStatusUpdateResponse.js';
33
33
  import {UpdateFulfillmentOrderRequest} from '../model/UpdateFulfillmentOrderRequest.js';
34
34
  import {UpdateFulfillmentOrderResponse} from '../model/UpdateFulfillmentOrderResponse.js';
35
+ import {SuperagentRateLimiter} from '../../../helper/SuperagentRateLimiter.mjs';
36
+ import {DefaultRateLimitFetcher} from '../../../helper/DefaultRateLimitFetcher.mjs';
35
37
 
36
38
  /**
37
39
  * FbaOutbound service.
@@ -40,6 +42,9 @@ import {UpdateFulfillmentOrderResponse} from '../model/UpdateFulfillmentOrderRes
40
42
  */
41
43
  export class FbaOutboundApi {
42
44
 
45
+ // Private memeber stores the default rate limiters
46
+ #defaultRateLimiterMap;
47
+
43
48
  /**
44
49
  * Constructs a new FbaOutboundApi.
45
50
  * @alias module:fulfillmentoutbound_v2020_07_01/api/FbaOutboundApi
@@ -49,6 +54,44 @@ export class FbaOutboundApi {
49
54
  */
50
55
  constructor(apiClient) {
51
56
  this.apiClient = apiClient || ApiClient.instance;
57
+ this.initializeDefaultRateLimiterMap();
58
+ }
59
+
60
+ /**
61
+ * Initialize rate limiters for API operations
62
+ */
63
+ initializeDefaultRateLimiterMap() {
64
+ this.#defaultRateLimiterMap = new Map()
65
+ const defaultRateLimitFetcher = new DefaultRateLimitFetcher();
66
+ const operations = [
67
+ 'FbaOutboundApi-cancelFulfillmentOrder',
68
+ 'FbaOutboundApi-createFulfillmentOrder',
69
+ 'FbaOutboundApi-createFulfillmentReturn',
70
+ 'FbaOutboundApi-deliveryOffers',
71
+ 'FbaOutboundApi-getFeatureInventory',
72
+ 'FbaOutboundApi-getFeatureSKU',
73
+ 'FbaOutboundApi-getFeatures',
74
+ 'FbaOutboundApi-getFulfillmentOrder',
75
+ 'FbaOutboundApi-getFulfillmentPreview',
76
+ 'FbaOutboundApi-getPackageTrackingDetails',
77
+ 'FbaOutboundApi-listAllFulfillmentOrders',
78
+ 'FbaOutboundApi-listReturnReasonCodes',
79
+ 'FbaOutboundApi-submitFulfillmentOrderStatusUpdate',
80
+ 'FbaOutboundApi-updateFulfillmentOrder',
81
+ ];
82
+
83
+ for (const operation of operations) {
84
+ const config = defaultRateLimitFetcher.getLimit(operation);
85
+ this.#defaultRateLimiterMap.set(operation, new SuperagentRateLimiter(config));
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Get rate limiter for a specific operation
91
+ * @param {String} operation name
92
+ */
93
+ getRateLimiter(operation) {
94
+ return this.#defaultRateLimiterMap.get(operation);
52
95
  }
53
96
 
54
97
 
@@ -84,7 +127,7 @@ export class FbaOutboundApi {
84
127
  return this.apiClient.callApi( 'FbaOutboundApi-cancelFulfillmentOrder',
85
128
  '/fba/outbound/2020-07-01/fulfillmentOrders/{sellerFulfillmentOrderId}/cancel', 'PUT',
86
129
  pathParams, queryParams, headerParams, formParams, postBody,
87
- contentTypes, accepts, returnType
130
+ contentTypes, accepts, returnType, this.getRateLimiter('FbaOutboundApi-cancelFulfillmentOrder')
88
131
  );
89
132
  }
90
133
 
@@ -131,7 +174,7 @@ export class FbaOutboundApi {
131
174
  return this.apiClient.callApi( 'FbaOutboundApi-createFulfillmentOrder',
132
175
  '/fba/outbound/2020-07-01/fulfillmentOrders', 'POST',
133
176
  pathParams, queryParams, headerParams, formParams, postBody,
134
- contentTypes, accepts, returnType
177
+ contentTypes, accepts, returnType, this.getRateLimiter('FbaOutboundApi-createFulfillmentOrder')
135
178
  );
136
179
  }
137
180
 
@@ -185,7 +228,7 @@ export class FbaOutboundApi {
185
228
  return this.apiClient.callApi( 'FbaOutboundApi-createFulfillmentReturn',
186
229
  '/fba/outbound/2020-07-01/fulfillmentOrders/{sellerFulfillmentOrderId}/return', 'PUT',
187
230
  pathParams, queryParams, headerParams, formParams, postBody,
188
- contentTypes, accepts, returnType
231
+ contentTypes, accepts, returnType, this.getRateLimiter('FbaOutboundApi-createFulfillmentReturn')
189
232
  );
190
233
  }
191
234
 
@@ -233,7 +276,7 @@ export class FbaOutboundApi {
233
276
  return this.apiClient.callApi( 'FbaOutboundApi-deliveryOffers',
234
277
  '/fba/outbound/2020-07-01/deliveryOffers', 'POST',
235
278
  pathParams, queryParams, headerParams, formParams, postBody,
236
- contentTypes, accepts, returnType
279
+ contentTypes, accepts, returnType, this.getRateLimiter('FbaOutboundApi-deliveryOffers')
237
280
  );
238
281
  }
239
282
 
@@ -294,7 +337,7 @@ export class FbaOutboundApi {
294
337
  return this.apiClient.callApi( 'FbaOutboundApi-getFeatureInventory',
295
338
  '/fba/outbound/2020-07-01/features/inventory/{featureName}', 'GET',
296
339
  pathParams, queryParams, headerParams, formParams, postBody,
297
- contentTypes, accepts, returnType
340
+ contentTypes, accepts, returnType, this.getRateLimiter('FbaOutboundApi-getFeatureInventory')
298
341
  );
299
342
  }
300
343
 
@@ -360,7 +403,7 @@ export class FbaOutboundApi {
360
403
  return this.apiClient.callApi( 'FbaOutboundApi-getFeatureSKU',
361
404
  '/fba/outbound/2020-07-01/features/inventory/{featureName}/{sellerSku}', 'GET',
362
405
  pathParams, queryParams, headerParams, formParams, postBody,
363
- contentTypes, accepts, returnType
406
+ contentTypes, accepts, returnType, this.getRateLimiter('FbaOutboundApi-getFeatureSKU')
364
407
  );
365
408
  }
366
409
 
@@ -410,7 +453,7 @@ export class FbaOutboundApi {
410
453
  return this.apiClient.callApi( 'FbaOutboundApi-getFeatures',
411
454
  '/fba/outbound/2020-07-01/features', 'GET',
412
455
  pathParams, queryParams, headerParams, formParams, postBody,
413
- contentTypes, accepts, returnType
456
+ contentTypes, accepts, returnType, this.getRateLimiter('FbaOutboundApi-getFeatures')
414
457
  );
415
458
  }
416
459
 
@@ -458,7 +501,7 @@ export class FbaOutboundApi {
458
501
  return this.apiClient.callApi( 'FbaOutboundApi-getFulfillmentOrder',
459
502
  '/fba/outbound/2020-07-01/fulfillmentOrders/{sellerFulfillmentOrderId}', 'GET',
460
503
  pathParams, queryParams, headerParams, formParams, postBody,
461
- contentTypes, accepts, returnType
504
+ contentTypes, accepts, returnType, this.getRateLimiter('FbaOutboundApi-getFulfillmentOrder')
462
505
  );
463
506
  }
464
507
 
@@ -505,7 +548,7 @@ export class FbaOutboundApi {
505
548
  return this.apiClient.callApi( 'FbaOutboundApi-getFulfillmentPreview',
506
549
  '/fba/outbound/2020-07-01/fulfillmentOrders/preview', 'POST',
507
550
  pathParams, queryParams, headerParams, formParams, postBody,
508
- contentTypes, accepts, returnType
551
+ contentTypes, accepts, returnType, this.getRateLimiter('FbaOutboundApi-getFulfillmentPreview')
509
552
  );
510
553
  }
511
554
 
@@ -553,7 +596,7 @@ export class FbaOutboundApi {
553
596
  return this.apiClient.callApi( 'FbaOutboundApi-getPackageTrackingDetails',
554
597
  '/fba/outbound/2020-07-01/tracking', 'GET',
555
598
  pathParams, queryParams, headerParams, formParams, postBody,
556
- contentTypes, accepts, returnType
599
+ contentTypes, accepts, returnType, this.getRateLimiter('FbaOutboundApi-getPackageTrackingDetails')
557
600
  );
558
601
  }
559
602
 
@@ -600,7 +643,7 @@ export class FbaOutboundApi {
600
643
  return this.apiClient.callApi( 'FbaOutboundApi-listAllFulfillmentOrders',
601
644
  '/fba/outbound/2020-07-01/fulfillmentOrders', 'GET',
602
645
  pathParams, queryParams, headerParams, formParams, postBody,
603
- contentTypes, accepts, returnType
646
+ contentTypes, accepts, returnType, this.getRateLimiter('FbaOutboundApi-listAllFulfillmentOrders')
604
647
  );
605
648
  }
606
649
 
@@ -658,7 +701,7 @@ export class FbaOutboundApi {
658
701
  return this.apiClient.callApi( 'FbaOutboundApi-listReturnReasonCodes',
659
702
  '/fba/outbound/2020-07-01/returnReasonCodes', 'GET',
660
703
  pathParams, queryParams, headerParams, formParams, postBody,
661
- contentTypes, accepts, returnType
704
+ contentTypes, accepts, returnType, this.getRateLimiter('FbaOutboundApi-listReturnReasonCodes')
662
705
  );
663
706
  }
664
707
 
@@ -716,7 +759,7 @@ export class FbaOutboundApi {
716
759
  return this.apiClient.callApi( 'FbaOutboundApi-submitFulfillmentOrderStatusUpdate',
717
760
  '/fba/outbound/2020-07-01/fulfillmentOrders/{sellerFulfillmentOrderId}/status', 'PUT',
718
761
  pathParams, queryParams, headerParams, formParams, postBody,
719
- contentTypes, accepts, returnType
762
+ contentTypes, accepts, returnType, this.getRateLimiter('FbaOutboundApi-submitFulfillmentOrderStatusUpdate')
720
763
  );
721
764
  }
722
765
 
@@ -771,7 +814,7 @@ export class FbaOutboundApi {
771
814
  return this.apiClient.callApi( 'FbaOutboundApi-updateFulfillmentOrder',
772
815
  '/fba/outbound/2020-07-01/fulfillmentOrders/{sellerFulfillmentOrderId}', 'PUT',
773
816
  pathParams, queryParams, headerParams, formParams, postBody,
774
- contentTypes, accepts, returnType
817
+ contentTypes, accepts, returnType, this.getRateLimiter('FbaOutboundApi-updateFulfillmentOrder')
775
818
  );
776
819
  }
777
820
 
@@ -11,12 +11,11 @@
11
11
  *
12
12
  */
13
13
 
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";
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 invoices_v2024_06_19/ApiClient
@@ -193,9 +192,8 @@ export class ApiClient {
193
192
  #tokenForApiCall = null;
194
193
  #lwaClient = null;
195
194
  #rdtClient = null;
196
- #defaultRateLimitFetcher = null;
197
- #customizedRateLimiter = null;
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
- * Initialize #defaultRateLimitFetcher
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
- async initializeDefaultRateLimit() {
268
- try {
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
- * Enable default rate limiter
279
+ * Disable customized rate limiter for one operation
280
+ * Fall back to default rate limiter
281
+ * @param {String} operationName
277
282
  */
278
- enableDefaultRateLimiter() {
279
- this.#useDefaultRateLimiter = true;
280
- this.#customizedRateLimiter = null;
283
+ disableCustomizedRatelimiterForOperation(operationName) {
284
+ this.#customizedRateLimiterMap.delete(operationName);
281
285
  }
282
286
 
283
287
  /**
284
- * Set customized rate limiter
285
- * @param {RateLimitConfiguration} config
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
- enableCustomizedRateLimiter(config) {
288
- this.#customizedRateLimiter = new SuperagentRateLimiter(config);
289
- this.#useDefaultRateLimiter = false;
299
+ disableRateLimiter() {
300
+ this.#useRateLimiter = false;
290
301
  }
291
302
 
292
303
  /**
293
- * Disable both customized and default rate limiter
304
+ * Enable default or customized rate limiter for all operations
294
305
  */
295
- disableRatelimiter() {
296
- this.#customizedRateLimiter = null;
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
- //Set rate limiter
613
- if (this.#useDefaultRateLimiter) {
614
- await this.initializeDefaultRateLimit();
615
- const defaultRateLimiter = new SuperagentRateLimiter(this.#defaultRateLimitFetcher.getLimit(operation));
616
- request.use(defaultRateLimiter.getPlugin());
617
- } else if (this.#customizedRateLimiter) {
618
- request.use(this.#customizedRateLimiter.getPlugin());
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 "../ApiClient.js";
14
+ import {ApiClient} from '../ApiClient.js';
15
15
  import {ErrorList} from '../model/ErrorList.js';
16
16
  import {ExportInvoicesRequest} from '../model/ExportInvoicesRequest.js';
17
17
  import {ExportInvoicesResponse} from '../model/ExportInvoicesResponse.js';
@@ -21,6 +21,8 @@ import {GetInvoicesDocumentResponse} from '../model/GetInvoicesDocumentResponse.
21
21
  import {GetInvoicesExportResponse} from '../model/GetInvoicesExportResponse.js';
22
22
  import {GetInvoicesExportsResponse} from '../model/GetInvoicesExportsResponse.js';
23
23
  import {GetInvoicesResponse} from '../model/GetInvoicesResponse.js';
24
+ import {SuperagentRateLimiter} from '../../../helper/SuperagentRateLimiter.mjs';
25
+ import {DefaultRateLimitFetcher} from '../../../helper/DefaultRateLimitFetcher.mjs';
24
26
 
25
27
  /**
26
28
  * Invoices service.
@@ -29,6 +31,9 @@ import {GetInvoicesResponse} from '../model/GetInvoicesResponse.js';
29
31
  */
30
32
  export class InvoicesApi {
31
33
 
34
+ // Private memeber stores the default rate limiters
35
+ #defaultRateLimiterMap;
36
+
32
37
  /**
33
38
  * Constructs a new InvoicesApi.
34
39
  * @alias module:invoices_v2024_06_19/api/InvoicesApi
@@ -38,6 +43,37 @@ export class InvoicesApi {
38
43
  */
39
44
  constructor(apiClient) {
40
45
  this.apiClient = apiClient || ApiClient.instance;
46
+ this.initializeDefaultRateLimiterMap();
47
+ }
48
+
49
+ /**
50
+ * Initialize rate limiters for API operations
51
+ */
52
+ initializeDefaultRateLimiterMap() {
53
+ this.#defaultRateLimiterMap = new Map()
54
+ const defaultRateLimitFetcher = new DefaultRateLimitFetcher();
55
+ const operations = [
56
+ 'InvoicesApi-createInvoicesExport',
57
+ 'InvoicesApi-getInvoice',
58
+ 'InvoicesApi-getInvoices',
59
+ 'InvoicesApi-getInvoicesAttributes',
60
+ 'InvoicesApi-getInvoicesDocument',
61
+ 'InvoicesApi-getInvoicesExport',
62
+ 'InvoicesApi-getInvoicesExports',
63
+ ];
64
+
65
+ for (const operation of operations) {
66
+ const config = defaultRateLimitFetcher.getLimit(operation);
67
+ this.#defaultRateLimiterMap.set(operation, new SuperagentRateLimiter(config));
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Get rate limiter for a specific operation
73
+ * @param {String} operation name
74
+ */
75
+ getRateLimiter(operation) {
76
+ return this.#defaultRateLimiterMap.get(operation);
41
77
  }
42
78
 
43
79
 
@@ -72,7 +108,7 @@ export class InvoicesApi {
72
108
  return this.apiClient.callApi( 'InvoicesApi-createInvoicesExport',
73
109
  '/tax/invoices/2024-06-19/exports', 'POST',
74
110
  pathParams, queryParams, headerParams, formParams, postBody,
75
- contentTypes, accepts, returnType
111
+ contentTypes, accepts, returnType, this.getRateLimiter('InvoicesApi-createInvoicesExport')
76
112
  );
77
113
  }
78
114
 
@@ -127,7 +163,7 @@ export class InvoicesApi {
127
163
  return this.apiClient.callApi( 'InvoicesApi-getInvoice',
128
164
  '/tax/invoices/2024-06-19/invoices/{invoiceId}', 'GET',
129
165
  pathParams, queryParams, headerParams, formParams, postBody,
130
- contentTypes, accepts, returnType
166
+ contentTypes, accepts, returnType, this.getRateLimiter('InvoicesApi-getInvoice')
131
167
  );
132
168
  }
133
169
 
@@ -204,7 +240,7 @@ export class InvoicesApi {
204
240
  return this.apiClient.callApi( 'InvoicesApi-getInvoices',
205
241
  '/tax/invoices/2024-06-19/invoices', 'GET',
206
242
  pathParams, queryParams, headerParams, formParams, postBody,
207
- contentTypes, accepts, returnType
243
+ contentTypes, accepts, returnType, this.getRateLimiter('InvoicesApi-getInvoices')
208
244
  );
209
245
  }
210
246
 
@@ -266,7 +302,7 @@ export class InvoicesApi {
266
302
  return this.apiClient.callApi( 'InvoicesApi-getInvoicesAttributes',
267
303
  '/tax/invoices/2024-06-19/attributes', 'GET',
268
304
  pathParams, queryParams, headerParams, formParams, postBody,
269
- contentTypes, accepts, returnType
305
+ contentTypes, accepts, returnType, this.getRateLimiter('InvoicesApi-getInvoicesAttributes')
270
306
  );
271
307
  }
272
308
 
@@ -314,7 +350,7 @@ export class InvoicesApi {
314
350
  return this.apiClient.callApi( 'InvoicesApi-getInvoicesDocument',
315
351
  '/tax/invoices/2024-06-19/documents/{invoicesDocumentId}', 'GET',
316
352
  pathParams, queryParams, headerParams, formParams, postBody,
317
- contentTypes, accepts, returnType
353
+ contentTypes, accepts, returnType, this.getRateLimiter('InvoicesApi-getInvoicesDocument')
318
354
  );
319
355
  }
320
356
 
@@ -362,7 +398,7 @@ export class InvoicesApi {
362
398
  return this.apiClient.callApi( 'InvoicesApi-getInvoicesExport',
363
399
  '/tax/invoices/2024-06-19/exports/{exportId}', 'GET',
364
400
  pathParams, queryParams, headerParams, formParams, postBody,
365
- contentTypes, accepts, returnType
401
+ contentTypes, accepts, returnType, this.getRateLimiter('InvoicesApi-getInvoicesExport')
366
402
  );
367
403
  }
368
404
 
@@ -422,7 +458,7 @@ export class InvoicesApi {
422
458
  return this.apiClient.callApi( 'InvoicesApi-getInvoicesExports',
423
459
  '/tax/invoices/2024-06-19/exports', 'GET',
424
460
  pathParams, queryParams, headerParams, formParams, postBody,
425
- contentTypes, accepts, returnType
461
+ contentTypes, accepts, returnType, this.getRateLimiter('InvoicesApi-getInvoicesExports')
426
462
  );
427
463
  }
428
464