@amazon-sp-api-release/amazon-sp-api-sdk-js 1.0.0-rc6 → 1.0.0-rc7

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 (113) hide show
  1. package/helper/DefaultRateLimitFetcher.mjs +59 -0
  2. package/helper/LwaAuthClient.mjs +56 -22
  3. package/helper/RateLimitConfiguration.mjs +53 -0
  4. package/helper/ScopeConstants.mjs +8 -0
  5. package/helper/SuperagentRateLimiter.mjs +51 -0
  6. package/helper/rate-limits.yml +874 -0
  7. package/index.js +51 -49
  8. package/package.json +6 -6
  9. package/sample-node-app/app.config.mjs +4 -3
  10. package/sample-node-app/index.js +155 -24
  11. package/src/apluscontent_v2020_11_01/ApiClient.js +152 -70
  12. package/src/apluscontent_v2020_11_01/api/AplusContentApi.js +10 -10
  13. package/src/appintegrations_v2024_04_01/ApiClient.js +152 -70
  14. package/src/appintegrations_v2024_04_01/api/AppIntegrationsApi.js +3 -3
  15. package/src/applications_v2023_11_30/ApiClient.js +152 -70
  16. package/src/applications_v2023_11_30/api/ApplicationsApi.js +1 -1
  17. package/src/awd_v2024_05_09/ApiClient.js +152 -70
  18. package/src/awd_v2024_05_09/api/AwdApi.js +11 -11
  19. package/src/catalogitems_v2022_04_01/ApiClient.js +152 -70
  20. package/src/catalogitems_v2022_04_01/api/CatalogApi.js +2 -2
  21. package/src/datakiosk_v2023_11_15/ApiClient.js +152 -70
  22. package/src/datakiosk_v2023_11_15/api/QueriesApi.js +5 -5
  23. package/src/easyship_v2022_03_23/ApiClient.js +152 -70
  24. package/src/easyship_v2022_03_23/api/EasyShipApi.js +5 -5
  25. package/src/fbaeligibility_v1/ApiClient.js +152 -70
  26. package/src/fbaeligibility_v1/api/FbaInboundApi.js +1 -1
  27. package/src/fbainventory_v1/ApiClient.js +152 -70
  28. package/src/fbainventory_v1/api/FbaInventoryApi.js +4 -4
  29. package/src/feeds_v2021_06_30/ApiClient.js +152 -70
  30. package/src/feeds_v2021_06_30/api/FeedsApi.js +6 -6
  31. package/src/finances_2024_06_19/ApiClient.js +152 -70
  32. package/src/finances_2024_06_19/api/DefaultApi.js +1 -1
  33. package/src/finances_v0/ApiClient.js +152 -70
  34. package/src/finances_v0/api/DefaultApi.js +4 -4
  35. package/src/fulfillmentinbound_v0/ApiClient.js +152 -70
  36. package/src/fulfillmentinbound_v0/api/FbaInboundApi.js +6 -6
  37. package/src/fulfillmentinbound_v2024_03_20/ApiClient.js +152 -70
  38. package/src/fulfillmentinbound_v2024_03_20/api/FbaInboundApi.js +45 -45
  39. package/src/fulfillmentoutbound_v2020_07_01/ApiClient.js +152 -70
  40. package/src/fulfillmentoutbound_v2020_07_01/api/FbaOutboundApi.js +14 -14
  41. package/src/invoices_v2024_06_19/ApiClient.js +152 -70
  42. package/src/invoices_v2024_06_19/api/InvoicesApi.js +7 -7
  43. package/src/invoicing_v0/ApiClient.js +152 -70
  44. package/src/invoicing_v0/api/ShipmentInvoiceApi.js +3 -3
  45. package/src/listingsitems_v2021_08_01/ApiClient.js +152 -70
  46. package/src/listingsitems_v2021_08_01/api/ListingsApi.js +5 -5
  47. package/src/listingsrestrictions_v2021_08_01/ApiClient.js +152 -70
  48. package/src/listingsrestrictions_v2021_08_01/api/ListingsApi.js +1 -1
  49. package/src/merchantfulfillment_v0/ApiClient.js +152 -70
  50. package/src/merchantfulfillment_v0/api/MerchantFulfillmentApi.js +5 -5
  51. package/src/messaging_v1/ApiClient.js +152 -70
  52. package/src/messaging_v1/api/MessagingApi.js +13 -13
  53. package/src/notifications_v1/ApiClient.js +152 -70
  54. package/src/notifications_v1/api/NotificationsApi.js +8 -8
  55. package/src/orders_v0/ApiClient.js +152 -70
  56. package/src/orders_v0/api/OrdersV0Api.js +9 -9
  57. package/src/orders_v0/api/ShipmentApi.js +1 -1
  58. package/src/pricing_v0/ApiClient.js +152 -70
  59. package/src/pricing_v0/api/ProductPricingApi.js +6 -6
  60. package/src/pricing_v2022_05_01/ApiClient.js +152 -70
  61. package/src/pricing_v2022_05_01/api/ProductPricingApi.js +2 -2
  62. package/src/productfees_v0/ApiClient.js +152 -70
  63. package/src/productfees_v0/api/FeesApi.js +3 -3
  64. package/src/producttypedefinitions_v2020_09_01/ApiClient.js +152 -70
  65. package/src/producttypedefinitions_v2020_09_01/api/DefinitionsApi.js +2 -2
  66. package/src/replenishment_v2022_11_07/ApiClient.js +152 -70
  67. package/src/replenishment_v2022_11_07/api/OffersApi.js +2 -2
  68. package/src/replenishment_v2022_11_07/api/SellingpartnersApi.js +1 -1
  69. package/src/reports_v2021_06_30/ApiClient.js +152 -70
  70. package/src/reports_v2021_06_30/api/ReportsApi.js +9 -9
  71. package/src/sales_v1/ApiClient.js +152 -70
  72. package/src/sales_v1/api/SalesApi.js +1 -1
  73. package/src/sellers_v1/ApiClient.js +152 -70
  74. package/src/sellers_v1/api/SellersApi.js +2 -2
  75. package/src/services_v1/ApiClient.js +152 -70
  76. package/src/services_v1/api/ServiceApi.js +17 -17
  77. package/src/shipping_v2/ApiClient.js +152 -70
  78. package/src/shipping_v2/api/ShippingApi.js +20 -20
  79. package/src/solicitations_v1/ApiClient.js +152 -70
  80. package/src/solicitations_v1/api/SolicitationsApi.js +2 -2
  81. package/src/supplysources_v2020_07_01/ApiClient.js +152 -70
  82. package/src/supplysources_v2020_07_01/api/SupplySourcesApi.js +6 -6
  83. package/src/tokens_v2021_03_01/ApiClient.js +152 -70
  84. package/src/tokens_v2021_03_01/api/TokensApi.js +1 -1
  85. package/src/transfers_v2024_06_01/ApiClient.js +152 -70
  86. package/src/transfers_v2024_06_01/api/DefaultApi.js +2 -2
  87. package/src/uploads_v2020_11_01/ApiClient.js +152 -70
  88. package/src/uploads_v2020_11_01/api/UploadsApi.js +1 -1
  89. package/src/vehicles_v2024_11_01/ApiClient.js +152 -70
  90. package/src/vehicles_v2024_11_01/api/AutomotiveApi.js +1 -1
  91. package/src/vehicles_v2024_11_01/api/VehiclesApi.js +1 -1
  92. package/src/vendordfinventory_v1/ApiClient.js +152 -70
  93. package/src/vendordfinventory_v1/api/UpdateInventoryApi.js +1 -1
  94. package/src/vendordforders_v2021_12_28/ApiClient.js +152 -70
  95. package/src/vendordforders_v2021_12_28/api/VendorOrdersApi.js +3 -3
  96. package/src/vendordfpayments_v1/ApiClient.js +152 -70
  97. package/src/vendordfpayments_v1/api/VendorInvoiceApi.js +1 -1
  98. package/src/vendordfshipping_v2021_12_28/ApiClient.js +152 -70
  99. package/src/vendordfshipping_v2021_12_28/api/CreateContainerLabelApi.js +1 -1
  100. package/src/vendordfshipping_v2021_12_28/api/CustomerInvoicesApi.js +2 -2
  101. package/src/vendordfshipping_v2021_12_28/api/VendorShippingApi.js +4 -4
  102. package/src/vendordfshipping_v2021_12_28/api/VendorShippingLabelsApi.js +4 -4
  103. package/src/vendordftransactions_v2021_12_28/ApiClient.js +152 -70
  104. package/src/vendordftransactions_v2021_12_28/api/VendorTransactionApi.js +1 -1
  105. package/src/vendorinvoices_v1/ApiClient.js +152 -70
  106. package/src/vendorinvoices_v1/api/VendorPaymentsApi.js +1 -1
  107. package/src/vendororders_v1/ApiClient.js +152 -70
  108. package/src/vendororders_v1/api/VendorOrdersApi.js +4 -4
  109. package/src/vendorshipments_v1/ApiClient.js +152 -70
  110. package/src/vendorshipments_v1/api/VendorShippingApi.js +4 -4
  111. package/src/vendortransactionstatus_v1/ApiClient.js +152 -70
  112. package/src/vendortransactionstatus_v1/api/VendorTransactionApi.js +1 -1
  113. package/README.md +0 -107
@@ -14,6 +14,9 @@
14
14
  import superagent from "superagent";
15
15
  import querystring from "querystring";
16
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";
17
20
 
18
21
  /**
19
22
  * @module tokens_v2021_03_01/ApiClient
@@ -26,32 +29,27 @@ import { URL } from 'node:url';
26
29
  */
27
30
  class LwaOAuthClient {
28
31
  /**
29
- * Private member to store LWA credential and refresh token.
30
- * @type {Object.<String, String>}
32
+ * Private member to store LWA credential, refresh token or scope.
33
+ * @type {Object<String, String>}
31
34
  */
32
35
  #lwaClientInfo = {};
33
36
 
34
37
  /**
35
- * Private member to cache one access token that is retrieved by auto-retrieval.
36
- * @type {String | null}
38
+ * Private member to cache access token that is retrieved by auto-retrieval.
39
+ * @type {Map<String, {String, Number}> | null}
37
40
  */
38
- #cachedToken = null;
39
-
40
- /**
41
- * Private member to cache one access token that is retrieved by auto-retrieval.
42
- * @type {Number | null}
43
- */
44
- #cachedTokenExpiration = null;
41
+ #cachedTokenMap = null;
45
42
 
46
43
  /**
47
44
  * Constructs a new LwaOAuthClient.
48
45
  * @param {String} clientId LWA Client ID.
49
46
  * @param {String} clientSecret LWA Client Secret.
50
- * @param {String} refreshToken LWA Refresh token.
47
+ * @param {String|null} refreshToken LWA Refresh token.
48
+ * @param {String|null} scope LWA scope(s) for grantless operations.
51
49
  */
52
- constructor(clientId, clientSecret, refreshToken) {
50
+ constructor(clientId, clientSecret, refreshToken = null, scope = null) {
53
51
  this.#lwaClientInfo = {
54
- clientId, clientSecret, refreshToken,
52
+ clientId, clientSecret, refreshToken, scope
55
53
  };
56
54
  }
57
55
 
@@ -60,13 +58,30 @@ class LwaOAuthClient {
60
58
  * @returns {Promise<String>} LWA access token.
61
59
  */
62
60
  retrieveAccessToken = async () => {
63
- if (this.#cachedToken && this.#cachedTokenExpiration && this.#cachedTokenExpiration > Date.now()) {
64
- return Promise.resolve(this.#cachedToken);
61
+ const key = JSON.stringify(this.#lwaClientInfo);
62
+
63
+ if (this.#cachedTokenMap) {
64
+ const cachedTokenItem = this.#cachedTokenMap.get(key);
65
+
66
+ if (cachedTokenItem) {
67
+ const cachedToken = cachedTokenItem.cachedToken;
68
+ const cachedTokenExpiration = cachedTokenItem.cachedTokenExpiration;
69
+ //Adjustment in milliseconds (60s) to avoid using nearly expired tokens
70
+ const adjustedExpiryTime = cachedTokenExpiration - 60000;
71
+ if (adjustedExpiryTime > Date.now()) {
72
+ return Promise.resolve(cachedToken);
73
+ } else {
74
+ this.#cachedTokenMap.delete(key);
75
+ }
76
+ }
65
77
  }
78
+
66
79
  const res = await this.#doRefresh();
67
- this.#cachedToken = res.access_token;
68
- this.#cachedTokenExpiration = Date.now() + res.expires_in * 1000;
69
- return this.#cachedToken;
80
+ if (!this.#cachedTokenMap) {
81
+ this.#cachedTokenMap = new Map();
82
+ }
83
+ this.#cachedTokenMap.set(key, {cachedToken: res.access_token, cachedTokenExpiration: Date.now() + res.expires_in * 1000});
84
+ return res.access_token;
70
85
  }
71
86
 
72
87
  /**
@@ -74,11 +89,24 @@ class LwaOAuthClient {
74
89
  * @returns {Promise<Object>} LWA token response.
75
90
  */
76
91
  #doRefresh = async () => {
92
+ let requestBody = null;
93
+ if (this.#lwaClientInfo.scope) {
94
+ //grantless operations
95
+ requestBody = `grant_type=client_credentials&client_id=${this.#lwaClientInfo.clientId}&client_secret=${this.#lwaClientInfo.clientSecret}&scope=${this.#lwaClientInfo.scope}`;
96
+ } else {
97
+ requestBody = `grant_type=refresh_token&refresh_token=${this.#lwaClientInfo.refreshToken}&client_id=${this.#lwaClientInfo.clientId}&client_secret=${this.#lwaClientInfo.clientSecret}`;
98
+ }
77
99
  const res = await superagent.post('https://api.amazon.com/auth/o2/token')
78
- .send(`grant_type=refresh_token&refresh_token=${this.#lwaClientInfo.refreshToken}&client_id=${this.#lwaClientInfo.clientId}&client_secret=${this.#lwaClientInfo.clientSecret}`)
100
+ .send(requestBody)
79
101
  .set("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
80
102
  return res.body;
81
103
  }
104
+
105
+ clearCachedTokenMap() {
106
+ if (this.#cachedTokenMap) {
107
+ this.#cachedTokenMap.clear();
108
+ }
109
+ }
82
110
  }
83
111
 
84
112
  /**
@@ -88,13 +116,13 @@ class LwaOAuthClient {
88
116
  class TokensApiClient {
89
117
  /**
90
118
  * Private member to execute LWA refresh token flow.
91
- * @type {Object.<LwaOAuthClient>}
119
+ * @type {Object<LwaOAuthClient>}
92
120
  */
93
121
  #lwaClient = null;
94
122
 
95
123
  /**
96
124
  * Private member to store 'dataElements' parameter for Tokens API call.
97
- * @type {Array.<String>}
125
+ * @type {Array<String>}
98
126
  */
99
127
  #dataElements = null;
100
128
 
@@ -103,10 +131,10 @@ class TokensApiClient {
103
131
  * @param {String} clientId LWA Client ID.
104
132
  * @param {String} clientSecret LWA Client Secret.
105
133
  * @param {String} refreshToken LWA Refresh token.
106
- * @param {Array.<String>} dataElements Optional specifiers for PII data elements tp retrieve.
134
+ * @param {Array<String>} dataElements Optional specifiers for PII data elements tp retrieve.
107
135
  */
108
136
  constructor(clientId, clientSecret, refreshToken, dataElements) {
109
- this.#lwaClient = new LwaOAuthClient(clientId, clientSecret, refreshToken, dataElements);
137
+ this.#lwaClient = new LwaOAuthClient(clientId, clientSecret, refreshToken, null);
110
138
  if (dataElements && !Array.isArray(dataElements)) {
111
139
  throw new Error(`dataElements parameter to TokensApiClient constructor must be array of string. Illegal parameter:${dataElements}`);
112
140
  }
@@ -117,7 +145,7 @@ class TokensApiClient {
117
145
  * Execute createRestrictedDataToken to retrieve RDT to be used for PII-handling SP-API calls.
118
146
  * @param {String} method method for SP-API request.
119
147
  * @param {String} url URL for SP-API call to be made.
120
- * @param {Array.<String>} dataElements specify PII information to get from "buyerInfo", "shippingAddress" and "buyerTaxInformation".
148
+ * @param {Array<String>} dataElements specify PII information to get from "buyerInfo", "shippingAddress" and "buyerTaxInformation".
121
149
  * @returns {Promise<String>} Restricted Data Token (RDT).
122
150
  */
123
151
  retrieveRestrictedDataToken = async (method, url) => {
@@ -127,11 +155,11 @@ class TokensApiClient {
127
155
  return res.restrictedDataToken;
128
156
  }
129
157
 
130
- /**
158
+ /**
131
159
  * Private method to execute createRestrictedDataToken
132
160
  * @param {String} accessToken Access token to call RDT request.
133
161
  * @param {URL} url URL object for URL string manipulation.
134
- * @param {Array.<String>} dataElements specify PII information to get from "buyerInfo", "shippingAddress" and "buyerTaxInformation".
162
+ * @param {Array<String>} dataElements specify PII information to get from "buyerInfo", "shippingAddress" and "buyerTaxInformation".
135
163
  * @returns {Promise<Object>} createRestrictedDataToken response.
136
164
  */
137
165
  #doCreateRestrictedDataToken = async (accessToken, method, url) => {
@@ -165,6 +193,9 @@ export class ApiClient {
165
193
  #tokenForApiCall = null;
166
194
  #lwaClient = null;
167
195
  #rdtClient = null;
196
+ #defaultRateLimitFetcher = null;
197
+ #customizedRateLimiter = null;
198
+ #useDefaultRateLimiter = false;
168
199
 
169
200
  /**
170
201
  * Constructs a new ApiClient.
@@ -180,17 +211,19 @@ export class ApiClient {
180
211
 
181
212
  /**
182
213
  * The authentication methods to be included for all API calls.
183
- * @type {Array.<String>}
214
+ * @type {Array<String>}
184
215
  */
185
216
  this.authentications = {
186
217
  }
187
218
 
188
219
  /**
189
220
  * The default HTTP headers to be included for all API calls.
190
- * @type {Array.<String>}
221
+ * @type {Array<String>}
191
222
  * @default {}
192
223
  */
193
- this.defaultHeaders = {};
224
+ this.defaultHeaders = {
225
+ 'User-Agent': 'amazon-selling-partner-api-sdk/1.0.0/JavaScript'
226
+ };
194
227
 
195
228
  /**
196
229
  * The default HTTP timeout for all API calls.
@@ -228,16 +261,51 @@ export class ApiClient {
228
261
  this.requestAgent = null;
229
262
  }
230
263
 
264
+ /**
265
+ * Initialize #defaultRateLimitFetcher
266
+ */
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
+ }
273
+ }
274
+
275
+ /**
276
+ * Enable default rate limiter
277
+ */
278
+ enableDefaultRateLimiter() {
279
+ this.#useDefaultRateLimiter = true;
280
+ this.#customizedRateLimiter = null;
281
+ }
282
+
283
+ /**
284
+ * Set customized rate limiter
285
+ * @param {RateLimitConfiguration} config
286
+ */
287
+ enableCustomizedRateLimiter(config) {
288
+ this.#customizedRateLimiter = new SuperagentRateLimiter(config);
289
+ this.#useDefaultRateLimiter = false;
290
+ }
291
+
292
+ /**
293
+ * Disable both customized and default rate limiter
294
+ */
295
+ disableRatelimiter() {
296
+ this.#customizedRateLimiter = null;
297
+ this.defaultRateLimiter = false;
298
+ }
299
+
231
300
  /**
232
301
  * Returns this ApiClient so that you can chain the methods.
233
302
  * @param {String} clientId LWA client ID.
234
303
  * @param {String} clientSecret LWA client secret.
235
304
  * @param {String} refreshToken LWA refresh token.
236
- * @param {Array.<String>} dataElementsOption specify PII information to get from "buyerInfo", "shippingAddress" and "buyerTaxInformation".
305
+ * @param {Array<String>} dataElementsOption specify PII information to get from "buyerInfo", "shippingAddress" and "buyerTaxInformation".
237
306
  * @returns {ApiClient} This ApiClient, which is going to use give accessToken for all API calls.
238
307
  */
239
308
  enableAutoRetrievalRestrictedDataToken(clientId, clientSecret, refreshToken, dataElementsOption) {
240
- // TODO
241
309
  if (!clientId || !clientSecret || !refreshToken) {
242
310
  throw new Error('invalid parameter(s) to enableAutoRetrievalRestrictedDataToken.');
243
311
  }
@@ -249,17 +317,28 @@ export class ApiClient {
249
317
  * Returns this ApiClient so that you can chain the methods.
250
318
  * @param {String} clientId LWA client ID.
251
319
  * @param {String} clientSecret LWA client secret.
252
- * @param {String} refreshToken LWA refresh token.
320
+ * @param {String|null} refreshToken LWA refresh token.
321
+ * @param {String|null} scope LWA scope(s) for grantless operations.
253
322
  * @returns {ApiClient} This ApiClient, which is going to use give accessToken for all API calls.
254
323
  */
255
- enableAutoRetrievalAccessToken(clientId, clientSecret, refreshToken) {
256
- if (!clientId || !clientSecret || !refreshToken) {
257
- throw new Error('invalid parameter(s) to enableAutoRetrievalAccessToken.');
324
+ enableAutoRetrievalAccessToken(clientId, clientSecret, refreshToken = null, scope = null) {
325
+ if (!clientId || !clientSecret) {
326
+ throw new Error('invalid parameter(s) to enableAutoRetrievalAccessToken: clientId or clientSecret is null or undefined.');
327
+ } else if ((!refreshToken && !scope) || (refreshToken && scope)) {
328
+ throw new Error('invalid parameter(s) to enableAutoRetrievalAccessToken: either refreshToken or scope must be defined.');
258
329
  }
259
- this.#lwaClient = new LwaOAuthClient(clientId, clientSecret, refreshToken);
330
+ this.#lwaClient = new LwaOAuthClient(clientId, clientSecret, refreshToken, scope);
260
331
  return this;
261
332
  }
262
333
 
334
+ /**
335
+ * Clear Token Cache
336
+ */
337
+ clearAccessTokenCache() {
338
+ if (this.#lwaClient) {
339
+ this.#lwaClient.clearCachedTokenMap();
340
+ }
341
+ }
263
342
 
264
343
  /**
265
344
  * Returns this ApiClient so that you can chain the methods.
@@ -271,6 +350,19 @@ export class ApiClient {
271
350
  return this;
272
351
  }
273
352
 
353
+ /**
354
+ * Applies authentication headers to the request.
355
+ * @param {String} accessOrRdtToken Either Access Token or Restricted Data Token to add as 'x-amz-access-token'.
356
+ * @returns {ApiClient} This ApiClient, which is going to use give RDT for all API calls.
357
+ */
358
+ applyXAmzAccessTokenToRequest(accessOrRdtToken) {
359
+ if (!accessOrRdtToken) {
360
+ throw new Error('empty string, null or undefined passed to applyXAmzAccessTokenToRequest');
361
+ }
362
+ this.#tokenForApiCall = accessOrRdtToken;
363
+ return this;
364
+ }
365
+
274
366
  /**
275
367
  * Returns a string representation for an actual parameter.
276
368
  * @param param The actual parameter.
@@ -283,7 +375,6 @@ export class ApiClient {
283
375
  if (param instanceof Date) {
284
376
  return param.toJSON();
285
377
  }
286
-
287
378
  return param.toString();
288
379
  }
289
380
 
@@ -298,7 +389,6 @@ export class ApiClient {
298
389
  if (!path.match(/^\//)) {
299
390
  path = '/' + path;
300
391
  }
301
-
302
392
  var url = this.basePath + path;
303
393
  url = url.replace(/\{([\w-]+)\}/g, (fullMatch, key) => {
304
394
  var value;
@@ -307,10 +397,8 @@ export class ApiClient {
307
397
  } else {
308
398
  value = fullMatch;
309
399
  }
310
-
311
400
  return encodeURIComponent(value);
312
401
  });
313
-
314
402
  return url;
315
403
  }
316
404
 
@@ -331,7 +419,7 @@ export class ApiClient {
331
419
 
332
420
  /**
333
421
  * Chooses a content type from the given array, with JSON preferred; i.e. return JSON if included, otherwise return the first.
334
- * @param {Array.<String>} contentTypes
422
+ * @param {Array<String>} contentTypes
335
423
  * @returns {String} The chosen content type, preferring JSON.
336
424
  */
337
425
  jsonPreferredMime(contentTypes) {
@@ -340,7 +428,6 @@ export class ApiClient {
340
428
  return contentTypes[i];
341
429
  }
342
430
  }
343
-
344
431
  return contentTypes[0];
345
432
  }
346
433
 
@@ -386,8 +473,8 @@ export class ApiClient {
386
473
  * <li>keep files and arrays</li>
387
474
  * <li>format to string with `paramToString` for other cases</li>
388
475
  * </ul>
389
- * @param {Object.<String, Object>} params The parameters as object properties.
390
- * @returns {Object.<String, Object>} normalized parameters.
476
+ * @param {Object<String, Object>} params The parameters as object properties.
477
+ * @returns {Object<String, Object>} normalized parameters.
391
478
  */
392
479
  normalizeParams(params) {
393
480
  var newParams = {};
@@ -401,7 +488,6 @@ export class ApiClient {
401
488
  }
402
489
  }
403
490
  }
404
-
405
491
  return newParams;
406
492
  }
407
493
 
@@ -470,23 +556,10 @@ export class ApiClient {
470
556
  }
471
557
  }
472
558
 
473
- /**
474
- * Applies authentication headers to the request.
475
- * @param {String} accessOrRdtToken Either Access Token or Restricted Data Token to add as 'x-amz-access-token'.
476
- * @returns {ApiClient} This ApiClient, which is going to use give RDT for all API calls.
477
- */
478
- applyXAmzAccessTokenToRequest(accessOrRdtToken) {
479
- if (!accessOrRdtToken) {
480
- throw new Error('empty string, null or undefined passed to applyXAmzAccessTokenToRequest');
481
- }
482
- this.#tokenForApiCall = accessOrRdtToken;
483
- return this;
484
- }
485
-
486
559
  /**
487
560
  * Deserializes an HTTP response body into a value of the specified type.
488
561
  * @param {Object} response A SuperAgent response object.
489
- * @param {(String|Array.<String>|Object.<String, Object>|Function)} returnType The type to return. Pass a string for simple types
562
+ * @param {(String|Array<String>|Object<String, Object>|Function)} returnType The type to return. Pass a string for simple types
490
563
  * or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To
491
564
  * return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type:
492
565
  * all properties on <code>data<code> will be converted to this type.
@@ -512,20 +585,21 @@ export class ApiClient {
512
585
 
513
586
  /**
514
587
  * Invokes the REST service using the supplied settings and parameters.
588
+ * @param {String} operation operation name.
515
589
  * @param {String} path The base URL to invoke.
516
590
  * @param {String} httpMethod The HTTP method to use.
517
- * @param {Object.<String, String>} pathParams A map of path parameters and their values.
518
- * @param {Object.<String, Object>} queryParams A map of query parameters and their values.
519
- * @param {Object.<String, Object>} headerParams A map of header parameters and their values.
520
- * @param {Object.<String, Object>} formParams A map of form parameters and their values.
591
+ * @param {Object<String, String>} pathParams A map of path parameters and their values.
592
+ * @param {Object<String, Object>} queryParams A map of query parameters and their values.
593
+ * @param {Object<String, Object>} headerParams A map of header parameters and their values.
594
+ * @param {Object<String, Object>} formParams A map of form parameters and their values.
521
595
  * @param {Object} bodyParam The value to pass as the request body.
522
- * @param {Array.<String>} contentTypes An array of request MIME types.
523
- * @param {Array.<String>} accepts An array of acceptable response MIME types.
596
+ * @param {Array<String>} contentTypes An array of request MIME types.
597
+ * @param {Array<String>} accepts An array of acceptable response MIME types.
524
598
  * @param {(String|Array|ObjectFunction)} returnType The required type to return; can be a string for simple types or the
525
599
  * constructor for a complex type.
526
600
  * @returns {Promise} A {@link https://www.promisejs.org/|Promise} object.
527
601
  */
528
- async callApi(path, httpMethod, pathParams,
602
+ async callApi(operation, path, httpMethod, pathParams,
529
603
  queryParams, headerParams, formParams, bodyParam, contentTypes, accepts,
530
604
  returnType) {
531
605
 
@@ -535,6 +609,16 @@ export class ApiClient {
535
609
  throw new Error('none of accessToken, RDT token and auto-retrieval is set.');
536
610
  }
537
611
 
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());
619
+ }
620
+
621
+
538
622
  // set query parameters
539
623
  if (httpMethod.toUpperCase() === 'GET' && this.cache === false) {
540
624
  queryParams['_'] = new Date().getTime();
@@ -625,7 +709,6 @@ export class ApiClient {
625
709
  if (this.enableCookies && typeof window === 'undefined'){
626
710
  this.agent.saveCookies(response);
627
711
  }
628
-
629
712
  resolve({data, response});
630
713
  } catch (err) {
631
714
  reject(err);
@@ -649,7 +732,7 @@ export class ApiClient {
649
732
  /**
650
733
  * Converts a value to the specified type.
651
734
  * @param {(String|Object)} data The data to convert, as a string or object.
652
- * @param {(String|Array.<String>|Object.<String, Object>|Function)} type The type to return. Pass a string for simple types
735
+ * @param {(String|Array<String>|Object<String, Object>|Function)} type The type to return. Pass a string for simple types
653
736
  * or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To
654
737
  * return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type:
655
738
  * all properties on <code>data<code> will be converted to this type.
@@ -682,7 +765,6 @@ export class ApiClient {
682
765
  } else if (Array.isArray(type)) {
683
766
  // for array type like: ['String']
684
767
  var itemType = type[0];
685
-
686
768
  return data.map((item) => {
687
769
  return ApiClient.convertToType(item, itemType);
688
770
  });
@@ -63,7 +63,7 @@ export class TokensApi {
63
63
  let accepts = ['application/json'];
64
64
  let returnType = CreateRestrictedDataTokenResponse;
65
65
 
66
- return this.apiClient.callApi(
66
+ return this.apiClient.callApi( 'TokensApi-createRestrictedDataToken',
67
67
  '/tokens/2021-03-01/restrictedDataToken', 'POST',
68
68
  pathParams, queryParams, headerParams, formParams, postBody,
69
69
  contentTypes, accepts, returnType