@amazon-sp-api-release/amazon-sp-api-sdk-js 1.0.0-rc5 → 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.
- package/helper/DefaultRateLimitFetcher.mjs +59 -0
- package/helper/LwaAuthClient.mjs +56 -22
- package/helper/RateLimitConfiguration.mjs +53 -0
- package/helper/ScopeConstants.mjs +8 -0
- package/helper/SuperagentRateLimiter.mjs +51 -0
- package/helper/rate-limits.yml +874 -0
- package/index.js +51 -49
- package/package.json +6 -6
- package/sample-node-app/app.config.mjs +4 -3
- package/sample-node-app/index.js +155 -24
- package/src/apluscontent_v2020_11_01/ApiClient.js +152 -70
- package/src/apluscontent_v2020_11_01/api/AplusContentApi.js +10 -10
- package/src/appintegrations_v2024_04_01/ApiClient.js +152 -70
- package/src/appintegrations_v2024_04_01/api/AppIntegrationsApi.js +3 -3
- package/src/applications_v2023_11_30/ApiClient.js +152 -70
- package/src/applications_v2023_11_30/api/ApplicationsApi.js +1 -1
- package/src/awd_v2024_05_09/ApiClient.js +152 -70
- package/src/awd_v2024_05_09/api/AwdApi.js +11 -11
- package/src/catalogitems_v2022_04_01/ApiClient.js +152 -70
- package/src/catalogitems_v2022_04_01/api/CatalogApi.js +2 -2
- package/src/datakiosk_v2023_11_15/ApiClient.js +152 -70
- package/src/datakiosk_v2023_11_15/api/QueriesApi.js +5 -5
- package/src/easyship_v2022_03_23/ApiClient.js +152 -70
- package/src/easyship_v2022_03_23/api/EasyShipApi.js +5 -5
- package/src/fbaeligibility_v1/ApiClient.js +152 -70
- package/src/fbaeligibility_v1/api/FbaInboundApi.js +1 -1
- package/src/fbainventory_v1/ApiClient.js +152 -70
- package/src/fbainventory_v1/api/FbaInventoryApi.js +4 -4
- package/src/feeds_v2021_06_30/ApiClient.js +152 -70
- package/src/feeds_v2021_06_30/api/FeedsApi.js +6 -6
- package/src/finances_2024_06_19/ApiClient.js +152 -70
- package/src/finances_2024_06_19/api/DefaultApi.js +1 -1
- package/src/finances_v0/ApiClient.js +152 -70
- package/src/finances_v0/api/DefaultApi.js +4 -4
- package/src/fulfillmentinbound_v0/ApiClient.js +152 -70
- package/src/fulfillmentinbound_v0/api/FbaInboundApi.js +6 -6
- package/src/fulfillmentinbound_v2024_03_20/ApiClient.js +152 -70
- package/src/fulfillmentinbound_v2024_03_20/api/FbaInboundApi.js +45 -45
- package/src/fulfillmentoutbound_v2020_07_01/ApiClient.js +152 -70
- package/src/fulfillmentoutbound_v2020_07_01/api/FbaOutboundApi.js +14 -14
- package/src/invoices_v2024_06_19/ApiClient.js +152 -70
- package/src/invoices_v2024_06_19/api/InvoicesApi.js +7 -7
- package/src/invoicing_v0/ApiClient.js +152 -70
- package/src/invoicing_v0/api/ShipmentInvoiceApi.js +3 -3
- package/src/listingsitems_v2021_08_01/ApiClient.js +152 -70
- package/src/listingsitems_v2021_08_01/api/ListingsApi.js +5 -5
- package/src/listingsrestrictions_v2021_08_01/ApiClient.js +152 -70
- package/src/listingsrestrictions_v2021_08_01/api/ListingsApi.js +1 -1
- package/src/merchantfulfillment_v0/ApiClient.js +152 -70
- package/src/merchantfulfillment_v0/api/MerchantFulfillmentApi.js +5 -5
- package/src/messaging_v1/ApiClient.js +152 -70
- package/src/messaging_v1/api/MessagingApi.js +13 -13
- package/src/notifications_v1/ApiClient.js +152 -70
- package/src/notifications_v1/api/NotificationsApi.js +8 -8
- package/src/orders_v0/ApiClient.js +152 -70
- package/src/orders_v0/api/OrdersV0Api.js +9 -9
- package/src/orders_v0/api/ShipmentApi.js +1 -1
- package/src/pricing_v0/ApiClient.js +152 -70
- package/src/pricing_v0/api/ProductPricingApi.js +6 -6
- package/src/pricing_v2022_05_01/ApiClient.js +152 -70
- package/src/pricing_v2022_05_01/api/ProductPricingApi.js +2 -2
- package/src/productfees_v0/ApiClient.js +152 -70
- package/src/productfees_v0/api/FeesApi.js +3 -3
- package/src/producttypedefinitions_v2020_09_01/ApiClient.js +152 -70
- package/src/producttypedefinitions_v2020_09_01/api/DefinitionsApi.js +2 -2
- package/src/replenishment_v2022_11_07/ApiClient.js +152 -70
- package/src/replenishment_v2022_11_07/api/OffersApi.js +2 -2
- package/src/replenishment_v2022_11_07/api/SellingpartnersApi.js +1 -1
- package/src/reports_v2021_06_30/ApiClient.js +152 -70
- package/src/reports_v2021_06_30/api/ReportsApi.js +9 -9
- package/src/sales_v1/ApiClient.js +152 -70
- package/src/sales_v1/api/SalesApi.js +1 -1
- package/src/sellers_v1/ApiClient.js +152 -70
- package/src/sellers_v1/api/SellersApi.js +2 -2
- package/src/services_v1/ApiClient.js +152 -70
- package/src/services_v1/api/ServiceApi.js +17 -17
- package/src/shipping_v2/ApiClient.js +152 -70
- package/src/shipping_v2/api/ShippingApi.js +20 -20
- package/src/solicitations_v1/ApiClient.js +152 -70
- package/src/solicitations_v1/api/SolicitationsApi.js +2 -2
- package/src/supplysources_v2020_07_01/ApiClient.js +152 -70
- package/src/supplysources_v2020_07_01/api/SupplySourcesApi.js +6 -6
- package/src/tokens_v2021_03_01/ApiClient.js +152 -70
- package/src/tokens_v2021_03_01/api/TokensApi.js +1 -1
- package/src/transfers_v2024_06_01/ApiClient.js +152 -70
- package/src/transfers_v2024_06_01/api/DefaultApi.js +2 -2
- package/src/uploads_v2020_11_01/ApiClient.js +152 -70
- package/src/uploads_v2020_11_01/api/UploadsApi.js +1 -1
- package/src/vehicles_v2024_11_01/ApiClient.js +152 -70
- package/src/vehicles_v2024_11_01/api/AutomotiveApi.js +1 -1
- package/src/vehicles_v2024_11_01/api/VehiclesApi.js +1 -1
- package/src/vendordfinventory_v1/ApiClient.js +152 -70
- package/src/vendordfinventory_v1/api/UpdateInventoryApi.js +1 -1
- package/src/vendordforders_v2021_12_28/ApiClient.js +152 -70
- package/src/vendordforders_v2021_12_28/api/VendorOrdersApi.js +3 -3
- package/src/vendordfpayments_v1/ApiClient.js +152 -70
- package/src/vendordfpayments_v1/api/VendorInvoiceApi.js +1 -1
- package/src/vendordfshipping_v2021_12_28/ApiClient.js +152 -70
- package/src/vendordfshipping_v2021_12_28/api/CreateContainerLabelApi.js +1 -1
- package/src/vendordfshipping_v2021_12_28/api/CustomerInvoicesApi.js +2 -2
- package/src/vendordfshipping_v2021_12_28/api/VendorShippingApi.js +4 -4
- package/src/vendordfshipping_v2021_12_28/api/VendorShippingLabelsApi.js +4 -4
- package/src/vendordftransactions_v2021_12_28/ApiClient.js +152 -70
- package/src/vendordftransactions_v2021_12_28/api/VendorTransactionApi.js +1 -1
- package/src/vendorinvoices_v1/ApiClient.js +152 -70
- package/src/vendorinvoices_v1/api/VendorPaymentsApi.js +1 -1
- package/src/vendororders_v1/ApiClient.js +152 -70
- package/src/vendororders_v1/api/VendorOrdersApi.js +4 -4
- package/src/vendorshipments_v1/ApiClient.js +152 -70
- package/src/vendorshipments_v1/api/VendorShippingApi.js +4 -4
- package/src/vendortransactionstatus_v1/ApiClient.js +152 -70
- package/src/vendortransactionstatus_v1/api/VendorTransactionApi.js +1 -1
- 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 shipping_v2/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
|
|
30
|
-
* @type {Object
|
|
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
|
|
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
|
-
#
|
|
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
|
-
|
|
64
|
-
|
|
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.#
|
|
68
|
-
|
|
69
|
-
|
|
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(
|
|
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
|
|
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
|
|
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
|
|
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,
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
390
|
-
* @returns {Object
|
|
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
|
|
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
|
|
518
|
-
* @param {Object
|
|
519
|
-
* @param {Object
|
|
520
|
-
* @param {Object
|
|
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
|
|
523
|
-
* @param {Array
|
|
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
|
|
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
|
});
|
|
@@ -96,7 +96,7 @@ export class ShippingApi {
|
|
|
96
96
|
let accepts = ['application/json'];
|
|
97
97
|
let returnType = CancelShipmentResponse;
|
|
98
98
|
|
|
99
|
-
return this.apiClient.callApi(
|
|
99
|
+
return this.apiClient.callApi( 'ShippingApi-cancelShipment',
|
|
100
100
|
'/shipping/v2/shipments/{shipmentId}/cancel', 'PUT',
|
|
101
101
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
102
102
|
contentTypes, accepts, returnType
|
|
@@ -149,7 +149,7 @@ export class ShippingApi {
|
|
|
149
149
|
let accepts = ['application/json'];
|
|
150
150
|
let returnType = CreateClaimResponse;
|
|
151
151
|
|
|
152
|
-
return this.apiClient.callApi(
|
|
152
|
+
return this.apiClient.callApi( 'ShippingApi-createClaim',
|
|
153
153
|
'/shipping/v2/claims', 'POST',
|
|
154
154
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
155
155
|
contentTypes, accepts, returnType
|
|
@@ -206,7 +206,7 @@ export class ShippingApi {
|
|
|
206
206
|
let accepts = ['application/json'];
|
|
207
207
|
let returnType = DirectPurchaseResponse;
|
|
208
208
|
|
|
209
|
-
return this.apiClient.callApi(
|
|
209
|
+
return this.apiClient.callApi( 'ShippingApi-directPurchaseShipment',
|
|
210
210
|
'/shipping/v2/shipments/directPurchase', 'POST',
|
|
211
211
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
212
212
|
contentTypes, accepts, returnType
|
|
@@ -263,7 +263,7 @@ export class ShippingApi {
|
|
|
263
263
|
let accepts = ['application/json'];
|
|
264
264
|
let returnType = GenerateCollectionFormResponse;
|
|
265
265
|
|
|
266
|
-
return this.apiClient.callApi(
|
|
266
|
+
return this.apiClient.callApi( 'ShippingApi-generateCollectionForm',
|
|
267
267
|
'/shipping/v2/collectionForms', 'POST',
|
|
268
268
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
269
269
|
contentTypes, accepts, returnType
|
|
@@ -332,7 +332,7 @@ export class ShippingApi {
|
|
|
332
332
|
let accepts = ['application/json'];
|
|
333
333
|
let returnType = GetAccessPointsResponse;
|
|
334
334
|
|
|
335
|
-
return this.apiClient.callApi(
|
|
335
|
+
return this.apiClient.callApi( 'ShippingApi-getAccessPoints',
|
|
336
336
|
'/shipping/v2/accessPoints', 'GET',
|
|
337
337
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
338
338
|
contentTypes, accepts, returnType
|
|
@@ -395,7 +395,7 @@ export class ShippingApi {
|
|
|
395
395
|
let accepts = ['application/json'];
|
|
396
396
|
let returnType = GetAdditionalInputsResponse;
|
|
397
397
|
|
|
398
|
-
return this.apiClient.callApi(
|
|
398
|
+
return this.apiClient.callApi( 'ShippingApi-getAdditionalInputs',
|
|
399
399
|
'/shipping/v2/shipments/additionalInputs/schema', 'GET',
|
|
400
400
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
401
401
|
contentTypes, accepts, returnType
|
|
@@ -443,7 +443,7 @@ export class ShippingApi {
|
|
|
443
443
|
let accepts = ['application/json'];
|
|
444
444
|
let returnType = GetCarrierAccountFormInputsResponse;
|
|
445
445
|
|
|
446
|
-
return this.apiClient.callApi(
|
|
446
|
+
return this.apiClient.callApi( 'ShippingApi-getCarrierAccountFormInputs',
|
|
447
447
|
'/shipping/v2/carrierAccountFormInputs', 'GET',
|
|
448
448
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
449
449
|
contentTypes, accepts, returnType
|
|
@@ -495,7 +495,7 @@ export class ShippingApi {
|
|
|
495
495
|
let accepts = ['application/json'];
|
|
496
496
|
let returnType = GetCarrierAccountsResponse;
|
|
497
497
|
|
|
498
|
-
return this.apiClient.callApi(
|
|
498
|
+
return this.apiClient.callApi( 'ShippingApi-getCarrierAccounts',
|
|
499
499
|
'/shipping/v2/carrierAccounts', 'PUT',
|
|
500
500
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
501
501
|
contentTypes, accepts, returnType
|
|
@@ -549,7 +549,7 @@ export class ShippingApi {
|
|
|
549
549
|
let accepts = ['application/json'];
|
|
550
550
|
let returnType = GetCollectionFormResponse;
|
|
551
551
|
|
|
552
|
-
return this.apiClient.callApi(
|
|
552
|
+
return this.apiClient.callApi( 'ShippingApi-getCollectionForm',
|
|
553
553
|
'/shipping/v2/collectionForms/{collectionFormId}', 'GET',
|
|
554
554
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
555
555
|
contentTypes, accepts, returnType
|
|
@@ -602,7 +602,7 @@ export class ShippingApi {
|
|
|
602
602
|
let accepts = ['application/json'];
|
|
603
603
|
let returnType = GetCollectionFormHistoryResponse;
|
|
604
604
|
|
|
605
|
-
return this.apiClient.callApi(
|
|
605
|
+
return this.apiClient.callApi( 'ShippingApi-getCollectionFormHistory',
|
|
606
606
|
'/shipping/v2/collectionForms/history', 'PUT',
|
|
607
607
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
608
608
|
contentTypes, accepts, returnType
|
|
@@ -655,7 +655,7 @@ export class ShippingApi {
|
|
|
655
655
|
let accepts = ['application/json'];
|
|
656
656
|
let returnType = GetRatesResponse;
|
|
657
657
|
|
|
658
|
-
return this.apiClient.callApi(
|
|
658
|
+
return this.apiClient.callApi( 'ShippingApi-getRates',
|
|
659
659
|
'/shipping/v2/shipments/rates', 'POST',
|
|
660
660
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
661
661
|
contentTypes, accepts, returnType
|
|
@@ -720,7 +720,7 @@ export class ShippingApi {
|
|
|
720
720
|
let accepts = ['application/json'];
|
|
721
721
|
let returnType = GetShipmentDocumentsResponse;
|
|
722
722
|
|
|
723
|
-
return this.apiClient.callApi(
|
|
723
|
+
return this.apiClient.callApi( 'ShippingApi-getShipmentDocuments',
|
|
724
724
|
'/shipping/v2/shipments/{shipmentId}/documents', 'GET',
|
|
725
725
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
726
726
|
contentTypes, accepts, returnType
|
|
@@ -784,7 +784,7 @@ export class ShippingApi {
|
|
|
784
784
|
let accepts = ['application/json'];
|
|
785
785
|
let returnType = GetTrackingResponse;
|
|
786
786
|
|
|
787
|
-
return this.apiClient.callApi(
|
|
787
|
+
return this.apiClient.callApi( 'ShippingApi-getTracking',
|
|
788
788
|
'/shipping/v2/tracking', 'GET',
|
|
789
789
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
790
790
|
contentTypes, accepts, returnType
|
|
@@ -838,7 +838,7 @@ export class ShippingApi {
|
|
|
838
838
|
let accepts = ['application/json'];
|
|
839
839
|
let returnType = GetUnmanifestedShipmentsResponse;
|
|
840
840
|
|
|
841
|
-
return this.apiClient.callApi(
|
|
841
|
+
return this.apiClient.callApi( 'ShippingApi-getUnmanifestedShipments',
|
|
842
842
|
'/shipping/v2/unmanifestedShipments', 'PUT',
|
|
843
843
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
844
844
|
contentTypes, accepts, returnType
|
|
@@ -898,7 +898,7 @@ export class ShippingApi {
|
|
|
898
898
|
let accepts = ['application/json'];
|
|
899
899
|
let returnType = LinkCarrierAccountResponse;
|
|
900
900
|
|
|
901
|
-
return this.apiClient.callApi(
|
|
901
|
+
return this.apiClient.callApi( 'ShippingApi-linkCarrierAccount',
|
|
902
902
|
'/shipping/v2/carrierAccounts/{carrierId}', 'PUT',
|
|
903
903
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
904
904
|
contentTypes, accepts, returnType
|
|
@@ -959,7 +959,7 @@ export class ShippingApi {
|
|
|
959
959
|
let accepts = ['application/json'];
|
|
960
960
|
let returnType = LinkCarrierAccountResponse;
|
|
961
961
|
|
|
962
|
-
return this.apiClient.callApi(
|
|
962
|
+
return this.apiClient.callApi( 'ShippingApi-linkCarrierAccount_0',
|
|
963
963
|
'/shipping/v2/carrierAccounts/{carrierId}', 'POST',
|
|
964
964
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
965
965
|
contentTypes, accepts, returnType
|
|
@@ -1013,7 +1013,7 @@ export class ShippingApi {
|
|
|
1013
1013
|
let accepts = ['application/json'];
|
|
1014
1014
|
let returnType = OneClickShipmentResponse;
|
|
1015
1015
|
|
|
1016
|
-
return this.apiClient.callApi(
|
|
1016
|
+
return this.apiClient.callApi( 'ShippingApi-oneClickShipment',
|
|
1017
1017
|
'/shipping/v2/oneClickShipment', 'POST',
|
|
1018
1018
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
1019
1019
|
contentTypes, accepts, returnType
|
|
@@ -1068,7 +1068,7 @@ export class ShippingApi {
|
|
|
1068
1068
|
let accepts = ['application/json'];
|
|
1069
1069
|
let returnType = PurchaseShipmentResponse;
|
|
1070
1070
|
|
|
1071
|
-
return this.apiClient.callApi(
|
|
1071
|
+
return this.apiClient.callApi( 'ShippingApi-purchaseShipment',
|
|
1072
1072
|
'/shipping/v2/shipments', 'POST',
|
|
1073
1073
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
1074
1074
|
contentTypes, accepts, returnType
|
|
@@ -1122,7 +1122,7 @@ export class ShippingApi {
|
|
|
1122
1122
|
let accepts = ['application/json'];
|
|
1123
1123
|
let returnType = null;
|
|
1124
1124
|
|
|
1125
|
-
return this.apiClient.callApi(
|
|
1125
|
+
return this.apiClient.callApi( 'ShippingApi-submitNdrFeedback',
|
|
1126
1126
|
'/shipping/v2/ndrFeedback', 'POST',
|
|
1127
1127
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
1128
1128
|
contentTypes, accepts, returnType
|
|
@@ -1182,7 +1182,7 @@ export class ShippingApi {
|
|
|
1182
1182
|
let accepts = ['application/json'];
|
|
1183
1183
|
let returnType = UnlinkCarrierAccountResponse;
|
|
1184
1184
|
|
|
1185
|
-
return this.apiClient.callApi(
|
|
1185
|
+
return this.apiClient.callApi( 'ShippingApi-unlinkCarrierAccount',
|
|
1186
1186
|
'/shipping/v2/carrierAccounts/{carrierId}/unlink', 'PUT',
|
|
1187
1187
|
pathParams, queryParams, headerParams, formParams, postBody,
|
|
1188
1188
|
contentTypes, accepts, returnType
|