@amazon-sp-api-release/amazon-sp-api-sdk-js 1.0.0-rc8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/helper/DefaultRateLimitFetcher.mjs +2 -35
- package/helper/DefaultRateLimitMap.mjs +266 -0
- package/helper/SuperagentRateLimiter.mjs +26 -14
- package/package.json +1 -1
- package/sample-node-app/index.js +27 -13
- package/src/apluscontent_v2020_11_01/ApiClient.js +48 -38
- package/src/apluscontent_v2020_11_01/api/AplusContentApi.js +50 -11
- package/src/appintegrations_v2024_04_01/ApiClient.js +48 -38
- package/src/appintegrations_v2024_04_01/api/AppIntegrationsApi.js +36 -4
- package/src/applications_v2023_11_30/ApiClient.js +48 -38
- package/src/applications_v2023_11_30/api/ApplicationsApi.js +32 -2
- package/src/awd_v2024_05_09/ApiClient.js +48 -38
- package/src/awd_v2024_05_09/api/AwdApi.js +52 -12
- package/src/catalogitems_v2022_04_01/ApiClient.js +48 -38
- package/src/catalogitems_v2022_04_01/api/CatalogApi.js +34 -3
- package/src/datakiosk_v2023_11_15/ApiClient.js +48 -38
- package/src/datakiosk_v2023_11_15/api/QueriesApi.js +40 -6
- package/src/easyship_v2022_03_23/ApiClient.js +48 -38
- package/src/easyship_v2022_03_23/api/EasyShipApi.js +40 -6
- package/src/fbaeligibility_v1/ApiClient.js +48 -38
- package/src/fbaeligibility_v1/api/FbaInboundApi.js +32 -2
- package/src/fbainventory_v1/ApiClient.js +48 -38
- package/src/fbainventory_v1/api/FbaInventoryApi.js +38 -5
- package/src/feeds_v2021_06_30/ApiClient.js +48 -38
- package/src/feeds_v2021_06_30/api/FeedsApi.js +42 -7
- package/src/finances_2024_06_19/ApiClient.js +48 -38
- package/src/finances_2024_06_19/api/DefaultApi.js +32 -2
- package/src/finances_v0/ApiClient.js +48 -38
- package/src/finances_v0/api/DefaultApi.js +38 -5
- package/src/fulfillmentinbound_v0/ApiClient.js +48 -38
- package/src/fulfillmentinbound_v0/api/FbaInboundApi.js +42 -7
- package/src/fulfillmentinbound_v2024_03_20/ApiClient.js +48 -38
- package/src/fulfillmentinbound_v2024_03_20/api/FbaInboundApi.js +120 -46
- package/src/fulfillmentoutbound_v2020_07_01/ApiClient.js +48 -38
- package/src/fulfillmentoutbound_v2020_07_01/api/FbaOutboundApi.js +58 -15
- package/src/invoices_v2024_06_19/ApiClient.js +48 -38
- package/src/invoices_v2024_06_19/api/InvoicesApi.js +44 -8
- package/src/invoicing_v0/ApiClient.js +48 -38
- package/src/invoicing_v0/api/ShipmentInvoiceApi.js +36 -4
- package/src/listingsitems_v2021_08_01/ApiClient.js +48 -38
- package/src/listingsitems_v2021_08_01/api/ListingsApi.js +40 -6
- package/src/listingsrestrictions_v2021_08_01/ApiClient.js +48 -38
- package/src/listingsrestrictions_v2021_08_01/api/ListingsApi.js +32 -2
- package/src/merchantfulfillment_v0/ApiClient.js +48 -38
- package/src/merchantfulfillment_v0/api/MerchantFulfillmentApi.js +40 -6
- package/src/messaging_v1/ApiClient.js +48 -38
- package/src/messaging_v1/api/MessagingApi.js +56 -14
- package/src/notifications_v1/ApiClient.js +48 -38
- package/src/notifications_v1/api/NotificationsApi.js +46 -9
- package/src/orders_v0/ApiClient.js +48 -38
- package/src/orders_v0/api/OrdersV0Api.js +48 -10
- package/src/orders_v0/api/ShipmentApi.js +32 -2
- package/src/pricing_v0/ApiClient.js +48 -38
- package/src/pricing_v0/api/ProductPricingApi.js +42 -7
- package/src/pricing_v2022_05_01/ApiClient.js +48 -38
- package/src/pricing_v2022_05_01/api/ProductPricingApi.js +34 -3
- package/src/productfees_v0/ApiClient.js +48 -38
- package/src/productfees_v0/api/FeesApi.js +36 -4
- package/src/producttypedefinitions_v2020_09_01/ApiClient.js +48 -38
- package/src/producttypedefinitions_v2020_09_01/api/DefinitionsApi.js +34 -3
- package/src/replenishment_v2022_11_07/ApiClient.js +48 -38
- package/src/replenishment_v2022_11_07/api/OffersApi.js +34 -3
- package/src/replenishment_v2022_11_07/api/SellingpartnersApi.js +32 -2
- package/src/reports_v2021_06_30/ApiClient.js +48 -38
- package/src/reports_v2021_06_30/api/ReportsApi.js +48 -10
- package/src/sales_v1/ApiClient.js +48 -38
- package/src/sales_v1/api/SalesApi.js +32 -2
- package/src/sellers_v1/ApiClient.js +48 -38
- package/src/sellers_v1/api/SellersApi.js +34 -3
- package/src/services_v1/ApiClient.js +48 -38
- package/src/services_v1/api/ServiceApi.js +64 -18
- package/src/shipping_v2/ApiClient.js +48 -38
- package/src/shipping_v2/api/ShippingApi.js +70 -21
- package/src/solicitations_v1/ApiClient.js +48 -38
- package/src/solicitations_v1/api/SolicitationsApi.js +34 -3
- package/src/supplysources_v2020_07_01/ApiClient.js +48 -38
- package/src/supplysources_v2020_07_01/api/SupplySourcesApi.js +42 -7
- package/src/tokens_v2021_03_01/ApiClient.js +48 -38
- package/src/tokens_v2021_03_01/api/TokensApi.js +32 -2
- package/src/transfers_v2024_06_01/ApiClient.js +48 -38
- package/src/transfers_v2024_06_01/api/DefaultApi.js +34 -3
- package/src/uploads_v2020_11_01/ApiClient.js +48 -38
- package/src/uploads_v2020_11_01/api/UploadsApi.js +32 -2
- package/src/vehicles_v2024_11_01/ApiClient.js +48 -38
- package/src/vehicles_v2024_11_01/api/AutomotiveApi.js +32 -2
- package/src/vehicles_v2024_11_01/api/VehiclesApi.js +32 -2
- package/src/vendordfinventory_v1/ApiClient.js +48 -38
- package/src/vendordfinventory_v1/api/UpdateInventoryApi.js +32 -2
- package/src/vendordforders_v2021_12_28/ApiClient.js +48 -38
- package/src/vendordforders_v2021_12_28/api/VendorOrdersApi.js +36 -4
- package/src/vendordfpayments_v1/ApiClient.js +48 -38
- package/src/vendordfpayments_v1/api/VendorInvoiceApi.js +32 -2
- package/src/vendordfshipping_v2021_12_28/ApiClient.js +48 -38
- package/src/vendordfshipping_v2021_12_28/api/CreateContainerLabelApi.js +32 -2
- package/src/vendordfshipping_v2021_12_28/api/CustomerInvoicesApi.js +34 -3
- package/src/vendordfshipping_v2021_12_28/api/VendorShippingApi.js +38 -5
- package/src/vendordfshipping_v2021_12_28/api/VendorShippingLabelsApi.js +38 -5
- package/src/vendordftransactions_v2021_12_28/ApiClient.js +48 -38
- package/src/vendordftransactions_v2021_12_28/api/VendorTransactionApi.js +32 -2
- package/src/vendorinvoices_v1/ApiClient.js +48 -38
- package/src/vendorinvoices_v1/api/VendorPaymentsApi.js +32 -2
- package/src/vendororders_v1/ApiClient.js +48 -38
- package/src/vendororders_v1/api/VendorOrdersApi.js +38 -5
- package/src/vendorshipments_v1/ApiClient.js +48 -38
- package/src/vendorshipments_v1/api/VendorShippingApi.js +38 -5
- package/src/vendortransactionstatus_v1/ApiClient.js +48 -38
- package/src/vendortransactionstatus_v1/api/VendorTransactionApi.js +32 -2
- package/helper/rate-limits.yml +0 -874
package/README.md
CHANGED
|
@@ -81,7 +81,7 @@ async function getMarketplaceParticipations() {
|
|
|
81
81
|
getMarketplaceParticipations();
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
Alternatively, you can go to `@amazon-sp-api-release/amazon-sp-api-sdk-js/sample-node-app` and copy over and modify `index.js` and `app.config.mjs` files and give them a try. You can see multiple API operation call
|
|
84
|
+
Alternatively, you can go to `@amazon-sp-api-release/amazon-sp-api-sdk-js/sample-node-app` and copy over and modify `index.js` and `app.config.mjs` files and give them a try. You can see multiple API operation call samples with various way of retrieving token, as well how to set up rate limiter and retry logic when making API calls. Note that the rate limiter is turned on by default to protect your API calls from 429 errors.
|
|
85
85
|
|
|
86
86
|
##### Additional Note:
|
|
87
87
|
This Amazon Selling Partner API JavaScript SDK is fully compatible with ECMAScript modules (ESM). You can use modern ES6+ import/export syntax as demonstrated in the example code:
|
|
@@ -1,29 +1,12 @@
|
|
|
1
|
-
import { parse } from 'yaml';
|
|
2
|
-
import { readFile } from 'fs/promises';
|
|
3
1
|
import { RateLimitConfiguration } from './RateLimitConfiguration.mjs';
|
|
4
|
-
import {
|
|
5
|
-
import { dirname } from 'path';
|
|
6
|
-
import { join } from 'path';
|
|
2
|
+
import { defaultRateLimitMap } from './DefaultRateLimitMap.mjs';
|
|
7
3
|
|
|
8
4
|
export class DefaultRateLimitFetcher {
|
|
9
5
|
|
|
10
6
|
#defaultRateLimitMap;
|
|
11
7
|
|
|
12
8
|
constructor() {
|
|
13
|
-
this.#defaultRateLimitMap =
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Initialize the configuration by loading the YAML file
|
|
17
|
-
async init() {
|
|
18
|
-
const fileName = fileURLToPath(import.meta.url);
|
|
19
|
-
const dirName = dirname(fileName);
|
|
20
|
-
try {
|
|
21
|
-
const fileContents = await readFile(join(dirName, 'rate-limits.yml'), 'utf8');
|
|
22
|
-
this.#defaultRateLimitMap = parse(fileContents);
|
|
23
|
-
} catch (error) {
|
|
24
|
-
this.#defaultRateLimitMap = {};
|
|
25
|
-
throw new error('Error loading rate-limits.yml:', error);
|
|
26
|
-
}
|
|
9
|
+
this.#defaultRateLimitMap = defaultRateLimitMap;
|
|
27
10
|
}
|
|
28
11
|
|
|
29
12
|
getLimit(operation) {
|
|
@@ -40,20 +23,4 @@ export class DefaultRateLimitFetcher {
|
|
|
40
23
|
}
|
|
41
24
|
return 1;
|
|
42
25
|
}
|
|
43
|
-
|
|
44
|
-
// Singleton implementation
|
|
45
|
-
static #instance = null;
|
|
46
|
-
|
|
47
|
-
static async create() {
|
|
48
|
-
const instance = new DefaultRateLimitFetcher();
|
|
49
|
-
await instance.init();
|
|
50
|
-
return instance;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
static async getInstance() {
|
|
54
|
-
if (!DefaultRateLimitFetcher.#instance) {
|
|
55
|
-
DefaultRateLimitFetcher.#instance = await DefaultRateLimitFetcher.create();
|
|
56
|
-
}
|
|
57
|
-
return DefaultRateLimitFetcher.#instance;
|
|
58
|
-
}
|
|
59
26
|
}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
export const defaultRateLimitMap = {
|
|
2
|
+
"AwdApi-getInboundShipment": [2, 2],
|
|
3
|
+
"AwdApi-listInboundShipments": [1, 1],
|
|
4
|
+
"AwdApi-listInventory": [2, 2],
|
|
5
|
+
"AwdApi-createInbound": [1, 1],
|
|
6
|
+
"AwdApi-getInbound": [2, 2],
|
|
7
|
+
"AwdApi-updateInbound": [1, 1],
|
|
8
|
+
"AwdApi-cancelInbound": [1, 1],
|
|
9
|
+
"AwdApi-confirmInbound": [1, 1],
|
|
10
|
+
"AwdApi-getInboundShipmentLabels": [1, 2],
|
|
11
|
+
"AwdApi-updateInboundShipmentTransportDetails": [1, 1],
|
|
12
|
+
"AwdApi-checkInboundEligibility": [1, 1],
|
|
13
|
+
"AplusContentApi-searchContentDocuments": [5, 5],
|
|
14
|
+
"AplusContentApi-createContentDocument": [5, 5],
|
|
15
|
+
"AplusContentApi-getContentDocument": [5, 5],
|
|
16
|
+
"AplusContentApi-updateContentDocument": [5, 5],
|
|
17
|
+
"AplusContentApi-listContentDocumentAsinRelations": [5, 5],
|
|
18
|
+
"AplusContentApi-postContentDocumentAsinRelations": [5, 5],
|
|
19
|
+
"AplusContentApi-validateContentDocumentAsinRelations": [5, 5],
|
|
20
|
+
"AplusContentApi-searchContentPublishRecords": [5, 5],
|
|
21
|
+
"AplusContentApi-postContentDocumentApprovalSubmission": [5, 5],
|
|
22
|
+
"AplusContentApi-postContentDocumentSuspendSubmission": [5, 5],
|
|
23
|
+
"AppIntegrationsApi-createNotification": [1, 5],
|
|
24
|
+
"AppIntegrationsApi-deleteNotifications": [1, 5],
|
|
25
|
+
"AppIntegrationsApi-recordActionFeedback": [1, 5],
|
|
26
|
+
"ApplicationsApi-rotateApplicationClientSecret": [1, 1, 60],
|
|
27
|
+
"CatalogApi-getCatalogItem": [2, 2],
|
|
28
|
+
"CatalogApi-searchCatalogItems": [2, 2],
|
|
29
|
+
"QueriesApi-getQueries": [1, 15, 60],
|
|
30
|
+
"QueriesApi-createQuery": [1, 15, 60],
|
|
31
|
+
"QueriesApi-getQuery": [2, 15],
|
|
32
|
+
"QueriesApi-cancelQuery": [2, 15],
|
|
33
|
+
"QueriesApi-getDocument": [1, 15, 60],
|
|
34
|
+
"EasyShip-listHandoverSlots": [1, 5],
|
|
35
|
+
"EasyShip-getScheduledPackage": [1, 5],
|
|
36
|
+
"EasyShip-createScheduledPackage": [1, 5],
|
|
37
|
+
"EasyShip-updateScheduledPackages": [1, 5],
|
|
38
|
+
"EasyShip-createScheduledPackageBulk": [1, 5],
|
|
39
|
+
"FbaInboundApi-getItemEligibilityPreview": [1, 1],
|
|
40
|
+
"FbaInventoryApi-getInventorySummaries": [2, 2],
|
|
41
|
+
"FbaInventoryApi-createInventoryItem": [2, 3],
|
|
42
|
+
"FbaInventoryApi-deleteInventoryItem": [2, 3],
|
|
43
|
+
"FbaInventoryApi-addInventory": [2, 3],
|
|
44
|
+
"FeedsApi-cancelFeed": [2, 15],
|
|
45
|
+
"FeedsApi-createFeed": [1, 15, 120],
|
|
46
|
+
"FeedsApi-createFeedDocument": [1, 15, 2],
|
|
47
|
+
"FeedsApi-getFeed": [2, 15],
|
|
48
|
+
"FeedsApi-getFeeds": [1, 10, 45],
|
|
49
|
+
"FeedsApi-getFeedDocument": [1, 10, 45],
|
|
50
|
+
"DefaultApi-listFinancialEventGroups": [1, 30, 2],
|
|
51
|
+
"DefaultApi-listFinancialEventsByGroupId": [1, 30, 2],
|
|
52
|
+
"DefaultApi-listFinancialEventsByOrderId": [1, 30, 2],
|
|
53
|
+
"DefaultApi-listFinancialEvents": [1, 30, 2],
|
|
54
|
+
"DefaultApi-initiatePayout": [1, 2, 60],
|
|
55
|
+
"DefaultApi-getPaymentMethods": [1, 30, 2],
|
|
56
|
+
"FbaInboundApi-getPrepInstructions": [2, 30],
|
|
57
|
+
"FbaInboundApi-getLabels": [2, 30],
|
|
58
|
+
"FbaInboundApi-getBillOfLading": [2, 30],
|
|
59
|
+
"FbaInboundApi-getShipments": [2, 30],
|
|
60
|
+
"FbaInboundApi-getShipmentItemsByShipmentId": [2, 30],
|
|
61
|
+
"FbaInboundApi-getShipmentItems": [2, 30],
|
|
62
|
+
"FbaInboundApi-listInboundPlans": [2, 6],
|
|
63
|
+
"FbaInboundApi-createInboundPlan": [2, 2],
|
|
64
|
+
"FbaInboundApi-getInboundPlan": [2, 6],
|
|
65
|
+
"FbaInboundApi-listInboundPlanBoxes": [2, 6],
|
|
66
|
+
"FbaInboundApi-cancelInboundPlan": [2, 2],
|
|
67
|
+
"FbaInboundApi-listInboundPlanItems": [2, 6],
|
|
68
|
+
"FbaInboundApi-updateInboundPlanName": [2, 30],
|
|
69
|
+
"FbaInboundApi-listPackingGroupBoxes": [2, 30],
|
|
70
|
+
"FbaInboundApi-listPackingGroupItems": [2, 30],
|
|
71
|
+
"FbaInboundApi-setPackingInformation": [2, 2],
|
|
72
|
+
"FbaInboundApi-listPackingOptions": [2, 6],
|
|
73
|
+
"FbaInboundApi-generatePackingOptions": [2, 2],
|
|
74
|
+
"FbaInboundApi-confirmPackingOption": [2, 2],
|
|
75
|
+
"FbaInboundApi-listInboundPlanPallets": [2, 6],
|
|
76
|
+
"FbaInboundApi-listPlacementOptions": [2, 6],
|
|
77
|
+
"FbaInboundApi-generatePlacementOptions": [2, 2],
|
|
78
|
+
"FbaInboundApi-confirmPlacementOption": [2, 2],
|
|
79
|
+
"FbaInboundApi-getShipment": [2, 6],
|
|
80
|
+
"FbaInboundApi-listShipmentBoxes": [2, 30],
|
|
81
|
+
"FbaInboundApi-listShipmentContentUpdatePreviews": [2, 30],
|
|
82
|
+
"FbaInboundApi-generateShipmentContentUpdatePreviews": [2, 30],
|
|
83
|
+
"FbaInboundApi-getShipmentContentUpdatePreview": [2, 30],
|
|
84
|
+
"FbaInboundApi-confirmShipmentContentUpdatePreview": [2, 30],
|
|
85
|
+
"FbaInboundApi-getDeliveryChallanDocument": [2, 6],
|
|
86
|
+
"FbaInboundApi-listDeliveryWindowOptions": [2, 30],
|
|
87
|
+
"FbaInboundApi-generateDeliveryWindowOptions": [2, 30],
|
|
88
|
+
"FbaInboundApi-confirmDeliveryWindowOptions": [2, 30],
|
|
89
|
+
"FbaInboundApi-listShipmentItems": [2, 30],
|
|
90
|
+
"FbaInboundApi-updateShipmentName": [2, 30],
|
|
91
|
+
"FbaInboundApi-listShipmentPallets": [2, 30],
|
|
92
|
+
"FbaInboundApi-cancelSelfShipAppointment": [2, 30],
|
|
93
|
+
"FbaInboundApi-getSelfShipAppointmentSlots": [2, 6],
|
|
94
|
+
"FbaInboundApi-generateSelfShipAppointmentSlots": [2, 2],
|
|
95
|
+
"FbaInboundApi-scheduleSelfShipAppointment": [2, 2],
|
|
96
|
+
"FbaInboundApi-updateShipmentSourceAddress": [2, 30],
|
|
97
|
+
"FbaInboundApi-updateShipmentTrackingDetails": [2, 2],
|
|
98
|
+
"FbaInboundApi-listTransportationOptions": [2, 6],
|
|
99
|
+
"FbaInboundApi-generateTransportationOptions": [2, 2],
|
|
100
|
+
"FbaInboundApi-confirmTransportationOptions": [2, 2],
|
|
101
|
+
"FbaInboundApi-listItemComplianceDetails": [2, 6],
|
|
102
|
+
"FbaInboundApi-updateItemComplianceDetails": [2, 2],
|
|
103
|
+
"FbaInboundApi-createMarketplaceItemLabels": [2, 30],
|
|
104
|
+
"FbaInboundApi-listPrepDetails": [2, 30],
|
|
105
|
+
"FbaInboundApi-setPrepDetails": [2, 30],
|
|
106
|
+
"FbaInboundApi-getInboundOperationStatus": [2, 6],
|
|
107
|
+
"FbaOutboundApi-getFulfillmentPreview": [2, 30],
|
|
108
|
+
"FbaOutboundApi-deliveryOffers": [10, 30],
|
|
109
|
+
"FbaOutboundApi-listAllFulfillmentOrders": [2, 30],
|
|
110
|
+
"FbaOutboundApi-createFulfillmentOrder": [2, 30],
|
|
111
|
+
"FbaOutboundApi-getPackageTrackingDetails": [2, 30],
|
|
112
|
+
"FbaOutboundApi-listReturnReasonCodes": [2, 30],
|
|
113
|
+
"FbaOutboundApi-createFulfillmentReturn": [2, 30],
|
|
114
|
+
"FbaOutboundApi-getFulfillmentOrder": [2, 30],
|
|
115
|
+
"FbaOutboundApi-updateFulfillmentOrder": [2, 30],
|
|
116
|
+
"FbaOutboundApi-cancelFulfillmentOrder": [2, 30],
|
|
117
|
+
"FbaOutboundApi-submitFulfillmentOrderStatusUpdate": [1, 1],
|
|
118
|
+
"FbaOutboundApi-getFeatures": [2, 30],
|
|
119
|
+
"FbaOutboundApi-getFeatureInventory": [2, 30],
|
|
120
|
+
"FbaOutboundApi-getFeatureSKU": [2, 30],
|
|
121
|
+
"InvoicesApi-getInvoicesAttributes": [1, 1],
|
|
122
|
+
"InvoicesApi-getInvoicesDocument": [1, 1, 60],
|
|
123
|
+
"InvoicesApi-createInvoicesExport": [1, 1, 60],
|
|
124
|
+
"InvoicesApi-getInvoicesExports": [1, 20, 10],
|
|
125
|
+
"InvoicesApi-getInvoicesExport": [2, 15],
|
|
126
|
+
"InvoicesApi-getInvoices": [1, 20, 10],
|
|
127
|
+
"InvoicesApi-getInvoice": [2, 15],
|
|
128
|
+
"ListingsApi-deleteListingsItem": [5, 5],
|
|
129
|
+
"ListingsApi-getListingsItem": [5, 5],
|
|
130
|
+
"ListingsApi-patchListingsItem": [5, 5],
|
|
131
|
+
"ListingsApi-putListingsItem": [5, 5],
|
|
132
|
+
"ListingsApi-searchListingsItems": [5, 5],
|
|
133
|
+
"ListingsApi-getListingsRestrictions": [5, 10],
|
|
134
|
+
"MerchantFulfillmentApi-getEligibleShipmentServices": [6, 12],
|
|
135
|
+
"MerchantFulfillmentApi-getShipment": [5, 10],
|
|
136
|
+
"MerchantFulfillmentApi-cancelShipment": [5, 10],
|
|
137
|
+
"MerchantFulfillmentApi-createShipment": [5, 10],
|
|
138
|
+
"MerchantFulfillmentApi-getAdditionalSellerInputs": [5, 10],
|
|
139
|
+
"MessagingApi-getMessagingActionsForOrder": [1, 5],
|
|
140
|
+
"MessagingApi-confirmCustomizationDetails": [1, 5],
|
|
141
|
+
"MessagingApi-createConfirmDeliveryDetails": [1, 5],
|
|
142
|
+
"MessagingApi-createLegalDisclosure": [1, 5],
|
|
143
|
+
"MessagingApi-createNegativeFeedbackRemoval": [1, 5],
|
|
144
|
+
"MessagingApi-createConfirmOrderDetails": [1, 5],
|
|
145
|
+
"MessagingApi-createConfirmServiceDetails": [1, 5],
|
|
146
|
+
"MessagingApi-CreateAmazonMotors": [1, 5],
|
|
147
|
+
"MessagingApi-CreateWarranty": [1, 5],
|
|
148
|
+
"MessagingApi-GetAttributes": [1, 5],
|
|
149
|
+
"MessagingApi-createDigitalAccessKey": [1, 5],
|
|
150
|
+
"MessagingApi-createUnexpectedProblem": [1, 5],
|
|
151
|
+
"MessagingApi-sendInvoice": [1, 5],
|
|
152
|
+
"NotificationsApi-getSubscription": [1, 5],
|
|
153
|
+
"NotificationsApi-createSubscription": [1, 5],
|
|
154
|
+
"NotificationsApi-getSubscriptionById": [1, 5],
|
|
155
|
+
"NotificationsApi-deleteSubscriptionById": [1, 5],
|
|
156
|
+
"NotificationsApi-getDestinations": [1, 5],
|
|
157
|
+
"NotificationsApi-createDestination": [1, 5],
|
|
158
|
+
"NotificationsApi-getDestination": [1, 5],
|
|
159
|
+
"NotificationsApi-deleteDestination": [1, 5],
|
|
160
|
+
"OrdersV0Api-confirmShipment": [2, 10],
|
|
161
|
+
"OrdersV0Api-getOrder": [1, 30, 2],
|
|
162
|
+
"OrdersV0Api-getOrderAddress": [1, 30, 2],
|
|
163
|
+
"OrdersV0Api-getOrderBuyerInfo": [1, 30, 2],
|
|
164
|
+
"OrdersV0Api-getOrderItems": [1, 30, 2],
|
|
165
|
+
"OrdersV0Api-getOrderItemsBuyerInfo": [1, 30, 2],
|
|
166
|
+
"OrdersV0Api-getOrderRegulatedInfo": [1, 30, 2],
|
|
167
|
+
"OrdersV0Api-getOrders": [1, 20, 60],
|
|
168
|
+
"ShipmentApi-updateShipmentStatus": [5, 15],
|
|
169
|
+
"OrdersV0Api-updateVerificationStatus": [1, 30, 2],
|
|
170
|
+
"FeesApi-getMyFeesEstimateForSKU": [1, 2],
|
|
171
|
+
"FeesApi-getMyFeesEstimateForASIN": [1, 2],
|
|
172
|
+
"FeesApi-getMyFeesEstimates": [1, 1, 2],
|
|
173
|
+
"ProductPricingApi-getFeaturedOfferExpectedPriceBatch": [1, 1, 30],
|
|
174
|
+
"ProductPricingApi-getCompetitiveSummary": [1, 1, 30],
|
|
175
|
+
"ProductPricingApi-getPricing": [1, 1, 2],
|
|
176
|
+
"ProductPricingApi-getCompetitivePricing": [1, 1, 2],
|
|
177
|
+
"ProductPricingApi-getListingOffers": [1, 2],
|
|
178
|
+
"ProductPricingApi-getItemOffers": [1, 1, 2],
|
|
179
|
+
"ProductPricingApi-getItemOffersBatch": [1, 1, 10],
|
|
180
|
+
"ProductPricingApi-getListingOffersBatch": [1, 1, 2],
|
|
181
|
+
"DefinitionsApi-getDefinitionsProductType": [5, 5],
|
|
182
|
+
"DefinitionsApi-searchDefinitionsProductTypes": [5, 5],
|
|
183
|
+
"SellingpartnersApi-getSellingPartnerMetrics": [1, 1],
|
|
184
|
+
"OffersApi-listOfferMetrics": [1, 1],
|
|
185
|
+
"OffersApi-listOffers": [1, 1],
|
|
186
|
+
"ReportsApi-getReports": [1, 10, 45],
|
|
187
|
+
"ReportsApi-createReport": [1, 15, 60],
|
|
188
|
+
"ReportsApi-cancelReport": [1, 10, 45],
|
|
189
|
+
"ReportsApi-getReport": [2, 15],
|
|
190
|
+
"ReportsApi-getReportSchedules": [1, 10, 45],
|
|
191
|
+
"ReportsApi-createReportSchedule": [1, 10, 45],
|
|
192
|
+
"ReportsApi-cancelReportSchedule": [1, 10, 45],
|
|
193
|
+
"ReportsApi-getReportSchedule": [1, 10, 45],
|
|
194
|
+
"ReportsApi-getReportDocument": [1, 15, 60],
|
|
195
|
+
"SalesApi-getOrderMetrics": [1, 15, 2],
|
|
196
|
+
"SellersApi-getMarketplaceParticipations": [1, 15, 60],
|
|
197
|
+
"SellersApi-getAccount": [1, 30, 2],
|
|
198
|
+
"ServiceApi-getServiceJobByServiceJobId": [20, 40],
|
|
199
|
+
"ServiceApi-cancelServiceJobByServiceJobId": [5, 20],
|
|
200
|
+
"ServiceApi-completeServiceJobByServiceJobId": [5, 20],
|
|
201
|
+
"ServiceApi-getServiceJobs": [10, 40],
|
|
202
|
+
"ServiceApi-addAppointmentForServiceJobByServiceJobId": [5, 20],
|
|
203
|
+
"ServiceApi-rescheduleAppointmentForServiceJobByServiceJobId": [5, 20],
|
|
204
|
+
"ServiceApi-assignAppointmentResources": [5, 20],
|
|
205
|
+
"ServiceApi-setAppointmentFulfillmentData": [5, 20],
|
|
206
|
+
"ServiceApi-getRangeSlotCapacity": [5, 20],
|
|
207
|
+
"ServiceApi-getFixedSlotCapacity": [5, 20],
|
|
208
|
+
"ServiceApi-updateSchedule": [5, 20],
|
|
209
|
+
"ServiceApi-createReservation": [5, 20],
|
|
210
|
+
"ServiceApi-updateReservation": [5, 20],
|
|
211
|
+
"ServiceApi-cancelReservation": [5, 20],
|
|
212
|
+
"ServiceApi-getAppointmmentSlotsByJobId": [5, 20],
|
|
213
|
+
"ServiceApi-getAppointmentSlots": [5, 20],
|
|
214
|
+
"ServiceApi-createServiceDocumentUploadDestination": [5, 20],
|
|
215
|
+
"ShipmentInvoiceApi-getShipmentDetails": [1.133, 25],
|
|
216
|
+
"ShipmentInvoiceApi-submitInvoice": [1.133, 25],
|
|
217
|
+
"ShipmentInvoiceApi-getInvoiceStatus": [1.133, 25],
|
|
218
|
+
"ShippingApi-createShipment": [5, 15],
|
|
219
|
+
"ShippingApi-getShipment": [5, 15],
|
|
220
|
+
"ShippingApi-cancelShipment": [5, 15],
|
|
221
|
+
"ShippingApi-purchaseLabels": [5, 15],
|
|
222
|
+
"ShippingApi-retrieveShippingLabel": [5, 15],
|
|
223
|
+
"ShippingApi-purchaseShipment": [5, 15],
|
|
224
|
+
"ShippingApi-getRates": [5, 15],
|
|
225
|
+
"ShippingApi-getAccount": [5, 15],
|
|
226
|
+
"ShippingApi-getTrackingInformation": [1, 1],
|
|
227
|
+
"SolicitationsApi-getSolicitationActionsForOrder": [1, 5],
|
|
228
|
+
"SolicitationsApi-createProductReviewAndSellerFeedbackSolicitation": [1, 5],
|
|
229
|
+
"SupplySourcesApi-getSupplySources": [10, 10],
|
|
230
|
+
"SupplySourcesApi-createSupplySource": [2, 2],
|
|
231
|
+
"SupplySourcesApi-getSupplySource": [40, 40],
|
|
232
|
+
"SupplySourcesApi-updateSupplySource": [1, 1],
|
|
233
|
+
"SupplySourcesApi-archiveSupplySource": [20, 20],
|
|
234
|
+
"SupplySourcesApi-updateSupplySourceStatus": [20, 20],
|
|
235
|
+
"TokensApi-createRestrictedDataToken": [1, 10],
|
|
236
|
+
"UploadsApi-createUploadDestinationForResource": [5, 5],
|
|
237
|
+
"AutomotiveApi-getVehicles": [20, 5],
|
|
238
|
+
"VehiclesApi-getVehicles": [20, 5],
|
|
239
|
+
"UpdateInventoryApi-submitInventoryUpdate": [10, 10],
|
|
240
|
+
"VendorOrdersApi-getOrders": [10, 10],
|
|
241
|
+
"VendorOrdersApi-getOrder": [10, 10],
|
|
242
|
+
"VendorOrdersApi-submitAcknowledgement": [10, 10],
|
|
243
|
+
"VendorInvoiceApi-submitInvoice": [10, 10],
|
|
244
|
+
"VendorShippingLabelsApi-getShippingLabels": [10, 10],
|
|
245
|
+
"VendorShippingLabelsApi-submitShippingLabelRequest": [10, 10],
|
|
246
|
+
"VendorShippingLabelsApi-getShippingLabel": [10, 10],
|
|
247
|
+
"VendorShippingLabelsApi-createShippingLabels": [10, 10],
|
|
248
|
+
"VendorShippingApi-submitShipmentConfirmations": [10, 10],
|
|
249
|
+
"VendorShippingApi-submitShipmentStatusUpdates": [10, 10],
|
|
250
|
+
"CustomerInvoicesApi-getCustomerInvoices": [10, 10],
|
|
251
|
+
"CustomerInvoicesApi-getCustomerInvoice": [10, 10],
|
|
252
|
+
"VendorShippingApi-getPackingSlips": [10, 10],
|
|
253
|
+
"VendorShippingApi-getPackingSlip": [10, 10],
|
|
254
|
+
"CreateContainerLabelApi-createContainerLabel": [10, 10],
|
|
255
|
+
"VendorTransactionsApi-getTransactionStatus": [10, 10],
|
|
256
|
+
"VendorPaymentsApi-submitInvoices": [10, 10],
|
|
257
|
+
"VendorOrdersApi-getPurchaseOrders": [10, 10],
|
|
258
|
+
"VendorOrdersApi-getPurchaseOrder": [10, 10],
|
|
259
|
+
"VendorOrdersApi-getPurchaseOrdersStatus": [10, 10],
|
|
260
|
+
"VendorShippingApi-SubmitShipmentConfirmations": [10, 10],
|
|
261
|
+
"VendorShippingApi-SubmitShipments": [10, 10],
|
|
262
|
+
"VendorShippingApi-GetShipmentDetails": [10, 10],
|
|
263
|
+
"VendorShippingApi-GetShipmentLabels": [10, 10],
|
|
264
|
+
"VendorTransactionApi-getTransaction": [10, 10]
|
|
265
|
+
}
|
|
266
|
+
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Bottleneck from 'bottleneck';
|
|
2
|
-
import { RateLimitConfiguration } from
|
|
2
|
+
import { RateLimitConfiguration } from './RateLimitConfiguration.mjs';
|
|
3
3
|
|
|
4
4
|
export class SuperagentRateLimiter {
|
|
5
5
|
/** @type {Bottleneck} */
|
|
@@ -22,9 +22,12 @@ export class SuperagentRateLimiter {
|
|
|
22
22
|
|
|
23
23
|
this.#limiter = new Bottleneck({
|
|
24
24
|
reservoir: burstRequests, // Initial capacity
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
reservoirIncreaseAmount: refreshAmount, // How many tokens to increase during each refresh
|
|
26
|
+
reservoirIncreaseInterval: refreshInterval, // increase interval in milliseconds
|
|
27
|
+
reservoirIncreaseMaximum: burstRequests, // maximum token bucket size
|
|
28
|
+
maxConcurrent: burstRequests, // Maximum number of requests running at the same time
|
|
29
|
+
highWater: 0,
|
|
30
|
+
strategy: Bottleneck.strategy.BLOCK, // Block requests when rate limit reached
|
|
28
31
|
});
|
|
29
32
|
|
|
30
33
|
}
|
|
@@ -35,17 +38,26 @@ export class SuperagentRateLimiter {
|
|
|
35
38
|
*/
|
|
36
39
|
getPlugin() {
|
|
37
40
|
return (request) => {
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
} catch (error) {
|
|
46
|
-
throw new Error(`Rate limit exceed error: ${error.message}`);
|
|
47
|
-
}
|
|
41
|
+
// Create a promise that must resolve before the request is sent
|
|
42
|
+
const rateLimitPromise = new Promise((resolve, reject) => {
|
|
43
|
+
this.#limiter.schedule(async () => {
|
|
44
|
+
resolve();
|
|
45
|
+
}).catch(error => {
|
|
46
|
+
reject(new Error(`Rate limit exceed error: ${error.message}`));
|
|
47
|
+
});
|
|
48
48
|
});
|
|
49
|
+
|
|
50
|
+
// Modify the request to wait for rate limiting
|
|
51
|
+
const originalEnd = request.end;
|
|
52
|
+
request.end = function (fn) {
|
|
53
|
+
rateLimitPromise
|
|
54
|
+
.then(() => {
|
|
55
|
+
originalEnd.call(request, fn);
|
|
56
|
+
})
|
|
57
|
+
.catch(error => {
|
|
58
|
+
fn(error);
|
|
59
|
+
});
|
|
60
|
+
};
|
|
49
61
|
};
|
|
50
62
|
}
|
|
51
63
|
}
|
package/package.json
CHANGED
package/sample-node-app/index.js
CHANGED
|
@@ -18,8 +18,9 @@ async function getMarketplaceParticipations() {
|
|
|
18
18
|
try {
|
|
19
19
|
//Configure Sellers ApiClient
|
|
20
20
|
const sellersApiClient = new SellersSpApi.ApiClient(AppConfig.spApiNAEndpoint);
|
|
21
|
-
sellersApiClient.enableAutoRetrievalAccessToken(AppConfig.lwaClientId, AppConfig.lwaClientSecret, AppConfig.lwaRefreshToken, null);
|
|
22
21
|
const sellersApi = new SellersSpApi.SellersApi(sellersApiClient);
|
|
22
|
+
|
|
23
|
+
sellersApiClient.enableAutoRetrievalAccessToken(AppConfig.lwaClientId, AppConfig.lwaClientSecret, AppConfig.lwaRefreshToken, null);
|
|
23
24
|
|
|
24
25
|
//Call GetMarkerplaceParticipations API
|
|
25
26
|
const participations = await sellersApi.getMarketplaceParticipations();
|
|
@@ -41,10 +42,11 @@ async function getMarketplaceParticipations() {
|
|
|
41
42
|
*/
|
|
42
43
|
async function createDestination() {
|
|
43
44
|
try {
|
|
44
|
-
//Configure Notifications ApiClient
|
|
45
|
+
//Configure Notifications ApiClient and notification Api
|
|
45
46
|
const notificationsApiClient = new NotificationsSpApi.ApiClient(AppConfig.spApiNAEndpoint);
|
|
46
|
-
notificationsApiClient.enableAutoRetrievalAccessToken(AppConfig.lwaClientId, AppConfig.lwaClientSecret, null, ScopeConstants.SCOPE_NOTIFICATION_API);
|
|
47
47
|
const notificationsApi = new NotificationsSpApi.NotificationsApi(notificationsApiClient);
|
|
48
|
+
|
|
49
|
+
notificationsApiClient.enableAutoRetrievalAccessToken(AppConfig.lwaClientId, AppConfig.lwaClientSecret, null, ScopeConstants.SCOPE_NOTIFICATION_API);
|
|
48
50
|
|
|
49
51
|
//Build createDestination request
|
|
50
52
|
const sqsResource = new NotificationsSpApi.SqsResource('<REPLACE_WITH_YOUR_SQS_QUEUE_ARN>');
|
|
@@ -74,12 +76,13 @@ async function getOrders() {
|
|
|
74
76
|
//Set up LwaAuthClient instance
|
|
75
77
|
const lwaAuthClient = new LwaAuthClient(AppConfig.lwaClientId, AppConfig.lwaClientSecret, AppConfig.lwaRefreshToken, null);
|
|
76
78
|
|
|
77
|
-
//Configure Orders ApiClient
|
|
79
|
+
//Configure Orders ApiClient and Order Api instance
|
|
78
80
|
const ordersApiClient = new OrdersSpApi.ApiClient(AppConfig.spApiNAEndpoint);
|
|
81
|
+
const ordersApi = new OrdersSpApi.OrdersV0Api(ordersApiClient);
|
|
82
|
+
|
|
79
83
|
ordersApiClient.applyXAmzAccessTokenToRequest(
|
|
80
84
|
await lwaAuthClient.getAccessToken()
|
|
81
85
|
);
|
|
82
|
-
const ordersApi = new OrdersSpApi.OrdersV0Api(ordersApiClient);
|
|
83
86
|
|
|
84
87
|
//Call GetOrders API
|
|
85
88
|
const marketPlaceIds = ['ATVPDKIKX0DER'];
|
|
@@ -99,23 +102,34 @@ async function getOrders() {
|
|
|
99
102
|
|
|
100
103
|
/**
|
|
101
104
|
* We support a built in rate limiter.
|
|
102
|
-
* Here is a sample SDK usage of calling Orders
|
|
105
|
+
* Here is a sample SDK usage of calling Orders getOrders API with a rate limiter and retry logic.
|
|
103
106
|
*/
|
|
104
|
-
async function getOrdersWithRateLimiterAndRetry(
|
|
107
|
+
async function getOrdersWithRateLimiterAndRetry(retryCount) {
|
|
105
108
|
const ordersApiClient = new OrdersSpApi.ApiClient(AppConfig.spApiNAEndpoint);
|
|
109
|
+
const ordersApi = new OrdersSpApi.OrdersV0Api(ordersApiClient);
|
|
110
|
+
|
|
106
111
|
ordersApiClient.enableAutoRetrievalAccessToken(AppConfig.lwaClientId, AppConfig.lwaClientSecret, AppConfig.lwaRefreshToken);
|
|
107
112
|
|
|
108
|
-
|
|
109
|
-
|
|
113
|
+
/**
|
|
114
|
+
* [Recommended] Option1: Use our default rate limiter. Our rate limiter uses the rate limit and burst values in our official document.
|
|
115
|
+
* It is turned on by default.
|
|
116
|
+
* /
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Option2: Use your customized rate limiter, you need to replace <RateLimit> and <BurstValue> with actual numbers.
|
|
120
|
+
* Then call setCustomizedRateLimiterForOperation(), please refer to helper/rate-limit.yml when specifying operation name.
|
|
121
|
+
* Note that for other operations that you did not configure customized rate limiter, they still use default rate limiter.
|
|
122
|
+
*/
|
|
110
123
|
|
|
111
|
-
// Option2: Use your customized rate limiter, you need to replace <RateLimit> and <BurstValue> with actual numbers.
|
|
112
124
|
// const rateLimitConfig = new RateLimitConfiguration(<RateLimit>, <BurstValue>);
|
|
113
|
-
// ordersApiClient.
|
|
125
|
+
// ordersApiClient.setCustomizedRateLimiterForOperation('OrdersV0Api-getOrders', rateLimitConfig);
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* [For dynamic usage plan APIs] Option3: Disable rate limiter. By calling this function, you are disabling both default and customized rate limiter.
|
|
129
|
+
*/
|
|
114
130
|
|
|
115
|
-
// Option3: Disable rate limit
|
|
116
131
|
// ordersApiClient.disableRatelimiter();
|
|
117
132
|
|
|
118
|
-
const ordersApi = new OrdersSpApi.OrdersV0Api(ordersApiClient);
|
|
119
133
|
const marketPlaceIds = ['ATVPDKIKX0DER'];
|
|
120
134
|
const opts = {
|
|
121
135
|
createdAfter: '2024-01-01'
|
|
@@ -11,12 +11,11 @@
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import superagent from
|
|
15
|
-
import querystring from
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import { DefaultRateLimitFetcher } from "../../helper/DefaultRateLimitFetcher.mjs";
|
|
14
|
+
import superagent from 'superagent';
|
|
15
|
+
import querystring from 'querystring';
|
|
16
|
+
import {URL} from 'node:url';
|
|
17
|
+
import {RateLimitConfiguration} from '../../helper/RateLimitConfiguration.mjs';
|
|
18
|
+
import {SuperagentRateLimiter} from '../../helper/SuperagentRateLimiter.mjs';
|
|
20
19
|
|
|
21
20
|
/**
|
|
22
21
|
* @module apluscontent_v2020_11_01/ApiClient
|
|
@@ -193,9 +192,8 @@ export class ApiClient {
|
|
|
193
192
|
#tokenForApiCall = null;
|
|
194
193
|
#lwaClient = null;
|
|
195
194
|
#rdtClient = null;
|
|
196
|
-
#
|
|
197
|
-
#
|
|
198
|
-
#useDefaultRateLimiter = false;
|
|
195
|
+
#customizedRateLimiterMap = null;
|
|
196
|
+
#useRateLimiter = true;
|
|
199
197
|
|
|
200
198
|
/**
|
|
201
199
|
* Constructs a new ApiClient.
|
|
@@ -259,42 +257,54 @@ export class ApiClient {
|
|
|
259
257
|
* Allow user to override superagent agent
|
|
260
258
|
*/
|
|
261
259
|
this.requestAgent = null;
|
|
260
|
+
|
|
261
|
+
/*
|
|
262
|
+
* Initialize customized rate limiter map
|
|
263
|
+
*/
|
|
264
|
+
this.#customizedRateLimiterMap = new Map();
|
|
262
265
|
}
|
|
263
266
|
|
|
264
267
|
/**
|
|
265
|
-
*
|
|
268
|
+
* Set customized rate limiter for one operation
|
|
269
|
+
* For operations that customized rate limiter are not set
|
|
270
|
+
* Will use default rate limiter
|
|
271
|
+
* @param {String} operationName
|
|
272
|
+
* @param {RateLimitConfiguration} config
|
|
266
273
|
*/
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
this.#defaultRateLimitFetcher = await DefaultRateLimitFetcher.getInstance();
|
|
270
|
-
} catch (err) {
|
|
271
|
-
throw new Error('Error reading default rate limit:', err);
|
|
272
|
-
}
|
|
274
|
+
setCustomizedRateLimiterForOperation(operationName, config) {
|
|
275
|
+
this.#customizedRateLimiterMap.set(operationName, new SuperagentRateLimiter(config));
|
|
273
276
|
}
|
|
274
277
|
|
|
275
278
|
/**
|
|
276
|
-
*
|
|
279
|
+
* Disable customized rate limiter for one operation
|
|
280
|
+
* Fall back to default rate limiter
|
|
281
|
+
* @param {String} operationName
|
|
277
282
|
*/
|
|
278
|
-
|
|
279
|
-
this.#
|
|
280
|
-
this.#customizedRateLimiter = null;
|
|
283
|
+
disableCustomizedRatelimiterForOperation(operationName) {
|
|
284
|
+
this.#customizedRateLimiterMap.delete(operationName);
|
|
281
285
|
}
|
|
282
286
|
|
|
283
287
|
/**
|
|
284
|
-
*
|
|
285
|
-
*
|
|
288
|
+
* Clear customized rate limiter for all operations
|
|
289
|
+
* All operations will fall back to default rate limiter
|
|
290
|
+
* @param {String} operationName
|
|
291
|
+
*/
|
|
292
|
+
disableCustomizedRatelimiterForAll() {
|
|
293
|
+
this.#customizedRateLimiterMap.clear();
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Disable both default and customized rate limiter for all operations
|
|
286
298
|
*/
|
|
287
|
-
|
|
288
|
-
this.#
|
|
289
|
-
this.#useDefaultRateLimiter = false;
|
|
299
|
+
disableRateLimiter() {
|
|
300
|
+
this.#useRateLimiter = false;
|
|
290
301
|
}
|
|
291
302
|
|
|
292
303
|
/**
|
|
293
|
-
*
|
|
304
|
+
* Enable default or customized rate limiter for all operations
|
|
294
305
|
*/
|
|
295
|
-
|
|
296
|
-
this.#
|
|
297
|
-
this.defaultRateLimiter = false;
|
|
306
|
+
enableRateLimiter() {
|
|
307
|
+
this.#useRateLimiter = true;
|
|
298
308
|
}
|
|
299
309
|
|
|
300
310
|
/**
|
|
@@ -597,11 +607,12 @@ export class ApiClient {
|
|
|
597
607
|
* @param {Array<String>} accepts An array of acceptable response MIME types.
|
|
598
608
|
* @param {(String|Array|ObjectFunction)} returnType The required type to return; can be a string for simple types or the
|
|
599
609
|
* constructor for a complex type.
|
|
610
|
+
* @param {SuperagentRateLimiter} defaultRateLimiter The default rate limiter.
|
|
600
611
|
* @returns {Promise} A {@link https://www.promisejs.org/|Promise} object.
|
|
601
612
|
*/
|
|
602
613
|
async callApi(operation, path, httpMethod, pathParams,
|
|
603
614
|
queryParams, headerParams, formParams, bodyParam, contentTypes, accepts,
|
|
604
|
-
returnType) {
|
|
615
|
+
returnType, defaultRateLimiter) {
|
|
605
616
|
|
|
606
617
|
var url = this.buildUrl(path, pathParams);
|
|
607
618
|
var request = superagent(httpMethod, url);
|
|
@@ -609,15 +620,14 @@ export class ApiClient {
|
|
|
609
620
|
throw new Error('none of accessToken, RDT token and auto-retrieval is set.');
|
|
610
621
|
}
|
|
611
622
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
623
|
+
if (this.#useRateLimiter) {
|
|
624
|
+
//Set rate limiter
|
|
625
|
+
if (this.#customizedRateLimiterMap.get(operation)) {
|
|
626
|
+
request.use(this.#customizedRateLimiterMap.get(operation).getPlugin());
|
|
627
|
+
} else if (defaultRateLimiter) {
|
|
628
|
+
request.use(defaultRateLimiter.getPlugin());
|
|
629
|
+
}
|
|
619
630
|
}
|
|
620
|
-
|
|
621
631
|
|
|
622
632
|
// set query parameters
|
|
623
633
|
if (httpMethod.toUpperCase() === 'GET' && this.cache === false) {
|