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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/README.md +104 -0
  2. package/helper/DefaultRateLimitFetcher.mjs +2 -35
  3. package/helper/DefaultRateLimitMap.mjs +266 -0
  4. package/helper/SuperagentRateLimiter.mjs +26 -14
  5. package/package.json +1 -1
  6. package/sample-node-app/index.js +27 -13
  7. package/src/apluscontent_v2020_11_01/ApiClient.js +48 -38
  8. package/src/apluscontent_v2020_11_01/api/AplusContentApi.js +50 -11
  9. package/src/appintegrations_v2024_04_01/ApiClient.js +48 -38
  10. package/src/appintegrations_v2024_04_01/api/AppIntegrationsApi.js +36 -4
  11. package/src/applications_v2023_11_30/ApiClient.js +48 -38
  12. package/src/applications_v2023_11_30/api/ApplicationsApi.js +32 -2
  13. package/src/awd_v2024_05_09/ApiClient.js +48 -38
  14. package/src/awd_v2024_05_09/api/AwdApi.js +52 -12
  15. package/src/catalogitems_v2022_04_01/ApiClient.js +48 -38
  16. package/src/catalogitems_v2022_04_01/api/CatalogApi.js +34 -3
  17. package/src/datakiosk_v2023_11_15/ApiClient.js +48 -38
  18. package/src/datakiosk_v2023_11_15/api/QueriesApi.js +40 -6
  19. package/src/easyship_v2022_03_23/ApiClient.js +48 -38
  20. package/src/easyship_v2022_03_23/api/EasyShipApi.js +40 -6
  21. package/src/fbaeligibility_v1/ApiClient.js +48 -38
  22. package/src/fbaeligibility_v1/api/FbaInboundApi.js +32 -2
  23. package/src/fbainventory_v1/ApiClient.js +48 -38
  24. package/src/fbainventory_v1/api/FbaInventoryApi.js +38 -5
  25. package/src/feeds_v2021_06_30/ApiClient.js +48 -38
  26. package/src/feeds_v2021_06_30/api/FeedsApi.js +42 -7
  27. package/src/finances_2024_06_19/ApiClient.js +48 -38
  28. package/src/finances_2024_06_19/api/DefaultApi.js +32 -2
  29. package/src/finances_v0/ApiClient.js +48 -38
  30. package/src/finances_v0/api/DefaultApi.js +38 -5
  31. package/src/fulfillmentinbound_v0/ApiClient.js +48 -38
  32. package/src/fulfillmentinbound_v0/api/FbaInboundApi.js +42 -7
  33. package/src/fulfillmentinbound_v2024_03_20/ApiClient.js +48 -38
  34. package/src/fulfillmentinbound_v2024_03_20/api/FbaInboundApi.js +120 -46
  35. package/src/fulfillmentoutbound_v2020_07_01/ApiClient.js +48 -38
  36. package/src/fulfillmentoutbound_v2020_07_01/api/FbaOutboundApi.js +58 -15
  37. package/src/invoices_v2024_06_19/ApiClient.js +48 -38
  38. package/src/invoices_v2024_06_19/api/InvoicesApi.js +44 -8
  39. package/src/invoicing_v0/ApiClient.js +48 -38
  40. package/src/invoicing_v0/api/ShipmentInvoiceApi.js +36 -4
  41. package/src/listingsitems_v2021_08_01/ApiClient.js +48 -38
  42. package/src/listingsitems_v2021_08_01/api/ListingsApi.js +40 -6
  43. package/src/listingsrestrictions_v2021_08_01/ApiClient.js +48 -38
  44. package/src/listingsrestrictions_v2021_08_01/api/ListingsApi.js +32 -2
  45. package/src/merchantfulfillment_v0/ApiClient.js +48 -38
  46. package/src/merchantfulfillment_v0/api/MerchantFulfillmentApi.js +40 -6
  47. package/src/messaging_v1/ApiClient.js +48 -38
  48. package/src/messaging_v1/api/MessagingApi.js +56 -14
  49. package/src/notifications_v1/ApiClient.js +48 -38
  50. package/src/notifications_v1/api/NotificationsApi.js +46 -9
  51. package/src/orders_v0/ApiClient.js +48 -38
  52. package/src/orders_v0/api/OrdersV0Api.js +48 -10
  53. package/src/orders_v0/api/ShipmentApi.js +32 -2
  54. package/src/pricing_v0/ApiClient.js +48 -38
  55. package/src/pricing_v0/api/ProductPricingApi.js +42 -7
  56. package/src/pricing_v2022_05_01/ApiClient.js +48 -38
  57. package/src/pricing_v2022_05_01/api/ProductPricingApi.js +34 -3
  58. package/src/productfees_v0/ApiClient.js +48 -38
  59. package/src/productfees_v0/api/FeesApi.js +36 -4
  60. package/src/producttypedefinitions_v2020_09_01/ApiClient.js +48 -38
  61. package/src/producttypedefinitions_v2020_09_01/api/DefinitionsApi.js +34 -3
  62. package/src/replenishment_v2022_11_07/ApiClient.js +48 -38
  63. package/src/replenishment_v2022_11_07/api/OffersApi.js +34 -3
  64. package/src/replenishment_v2022_11_07/api/SellingpartnersApi.js +32 -2
  65. package/src/reports_v2021_06_30/ApiClient.js +48 -38
  66. package/src/reports_v2021_06_30/api/ReportsApi.js +48 -10
  67. package/src/sales_v1/ApiClient.js +48 -38
  68. package/src/sales_v1/api/SalesApi.js +32 -2
  69. package/src/sellers_v1/ApiClient.js +48 -38
  70. package/src/sellers_v1/api/SellersApi.js +34 -3
  71. package/src/services_v1/ApiClient.js +48 -38
  72. package/src/services_v1/api/ServiceApi.js +64 -18
  73. package/src/shipping_v2/ApiClient.js +48 -38
  74. package/src/shipping_v2/api/ShippingApi.js +70 -21
  75. package/src/solicitations_v1/ApiClient.js +48 -38
  76. package/src/solicitations_v1/api/SolicitationsApi.js +34 -3
  77. package/src/supplysources_v2020_07_01/ApiClient.js +48 -38
  78. package/src/supplysources_v2020_07_01/api/SupplySourcesApi.js +42 -7
  79. package/src/tokens_v2021_03_01/ApiClient.js +48 -38
  80. package/src/tokens_v2021_03_01/api/TokensApi.js +32 -2
  81. package/src/transfers_v2024_06_01/ApiClient.js +48 -38
  82. package/src/transfers_v2024_06_01/api/DefaultApi.js +34 -3
  83. package/src/uploads_v2020_11_01/ApiClient.js +48 -38
  84. package/src/uploads_v2020_11_01/api/UploadsApi.js +32 -2
  85. package/src/vehicles_v2024_11_01/ApiClient.js +48 -38
  86. package/src/vehicles_v2024_11_01/api/AutomotiveApi.js +32 -2
  87. package/src/vehicles_v2024_11_01/api/VehiclesApi.js +32 -2
  88. package/src/vendordfinventory_v1/ApiClient.js +48 -38
  89. package/src/vendordfinventory_v1/api/UpdateInventoryApi.js +32 -2
  90. package/src/vendordforders_v2021_12_28/ApiClient.js +48 -38
  91. package/src/vendordforders_v2021_12_28/api/VendorOrdersApi.js +36 -4
  92. package/src/vendordfpayments_v1/ApiClient.js +48 -38
  93. package/src/vendordfpayments_v1/api/VendorInvoiceApi.js +32 -2
  94. package/src/vendordfshipping_v2021_12_28/ApiClient.js +48 -38
  95. package/src/vendordfshipping_v2021_12_28/api/CreateContainerLabelApi.js +32 -2
  96. package/src/vendordfshipping_v2021_12_28/api/CustomerInvoicesApi.js +34 -3
  97. package/src/vendordfshipping_v2021_12_28/api/VendorShippingApi.js +38 -5
  98. package/src/vendordfshipping_v2021_12_28/api/VendorShippingLabelsApi.js +38 -5
  99. package/src/vendordftransactions_v2021_12_28/ApiClient.js +48 -38
  100. package/src/vendordftransactions_v2021_12_28/api/VendorTransactionApi.js +32 -2
  101. package/src/vendorinvoices_v1/ApiClient.js +48 -38
  102. package/src/vendorinvoices_v1/api/VendorPaymentsApi.js +32 -2
  103. package/src/vendororders_v1/ApiClient.js +48 -38
  104. package/src/vendororders_v1/api/VendorOrdersApi.js +38 -5
  105. package/src/vendorshipments_v1/ApiClient.js +48 -38
  106. package/src/vendorshipments_v1/api/VendorShippingApi.js +38 -5
  107. package/src/vendortransactionstatus_v1/ApiClient.js +48 -38
  108. package/src/vendortransactionstatus_v1/api/VendorTransactionApi.js +32 -2
  109. package/helper/rate-limits.yml +0 -874
package/README.md ADDED
@@ -0,0 +1,104 @@
1
+ ## JavaScript SDK for Selling Partner API
2
+ [![npm version](https://badge.fury.io/js/@amazon-sp-api-release%2Famazon-sp-api-sdk-js.svg)](https://www.npmjs.com/package/@amazon-sp-api-release/amazon-sp-api-sdk-js)
3
+
4
+ <!-- youtube video is under creating -->
5
+ <!-- [![Video Thumbnail](docs/video-thumbnail.png)](https://www.youtube.com/watch?v=OmYTAA80V_4)
6
+
7
+ *Click on the image to watch the video.* -->
8
+
9
+ The Selling Partner API SDK for JavaScript enables you to easily connect your JavaScript/Node.js application to Amazon's REST-based Selling Partner API.
10
+
11
+ * [Learn more about Selling Partner API](https://developer.amazonservices.com/)
12
+ * [Selling Partner API Documentation](https://developer-docs.amazon.com/sp-api/)
13
+
14
+ ### Getting started
15
+
16
+ #### Credentials
17
+
18
+ Before you can use the SDK, you need to be registered as a Selling Partner API developer. If you haven't done that yet, please follow the instructions in the [SP-API Registration Overview](https://developer-docs.amazon.com/sp-api/docs/sp-api-registration-overview).
19
+ You also need to register your application to get valid credentials to call SP-API. If you haven't done that yet, please follow the instructions in [Registering your Application](https://developer-docs.amazon.com/sp-api/docs/registering-your-application).
20
+ If you are already registered successfully, you can find instructions on how to view your credentials in [Viewing your Application Information and Credentials](https://developer-docs.amazon.com/sp-api/docs/viewing-your-application-information-and-credentials).
21
+
22
+ #### Minimum requirements
23
+
24
+ To run the SDK you need Node version 14 or higher.
25
+
26
+ #### Install the SDK
27
+
28
+ 1. Find the latest version number [here](https://github.com/amzn/selling-partner-api-sdk/releases).
29
+ 2. Add the dependency to your project (see instructions for [npm](#using-npm), [yarn](#using-yarn) and [Add as an package dependency](#add-as-an-package-dependency) below).
30
+
31
+
32
+ ##### Using npm:
33
+ ```bash
34
+ npm install @amazon-sp-api-release/amazon-sp-api-sdk-js
35
+ ```
36
+
37
+ ##### Using yarn:
38
+ ```bash
39
+ yarn add @amazon-sp-api-release/amazon-sp-api-sdk-js
40
+ ```
41
+
42
+ ##### Add as a package dependency
43
+ Add the following line to the `dependencies` in your `package.json` file:
44
+ ```bash
45
+ "@amazon-sp-api-release/amazon-sp-api-sdk-js": "^1.0.0"
46
+ ```
47
+
48
+ ### Use the SDK
49
+
50
+ In order to call one of the APIs included in the Selling Partner API, you need to:
51
+ 1. Configure credentials (Note: Use your individual credentials for `clientId`, `clientSecret` and `refreshToken`)
52
+ 2. Enable auto `accessToken` retrievel using our built in ApiClient function OR retrieve `accessToken` using our `LwaAuthClient` helper (Be aware for some APIs, you will need extra step to get `RDT Token`)
53
+ 2. Create an instance for a specific API and API client, then apply `accessToken` to it.
54
+ 3. Call an API operation
55
+
56
+ For an example, refer to the following sample code for connecting to Sellers API:
57
+
58
+ ```javascript
59
+ import {
60
+ SellersSpApi
61
+ } from '@amazon-sp-api-release/amazon-sp-api-sdk-js';
62
+
63
+ async function getMarketplaceParticipations() {
64
+ try {
65
+ //Configure Sellers ApiClient
66
+ const sellersApiClient = new SellersSpApi.ApiClient(AppConfig.spApiNAEndpoint);
67
+ sellersApiClient.enableAutoRetrievalAccessToken('<YOUR_CLIENT_ID>','<YOUR_CLIENT_SECRET>', '<YOUR_REFRESH_TOKEN>' null);
68
+ const sellersApi = new SellersSpApi.SellersApi(sellersApiClient);
69
+
70
+ //Call GetMarkerplaceParticipations API
71
+ const participations = await sellersApi.getMarketplaceParticipations();
72
+ console.log(
73
+ JSON.stringify(participations, null, ' ') +
74
+ '\n**********************************'
75
+ )
76
+ } catch (error) {
77
+ console.error('Exception when calling getMarketplaceParticipations API', error.message);
78
+ }
79
+ }
80
+
81
+ getMarketplaceParticipations();
82
+ ```
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 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
+
86
+ ##### Additional Note:
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:
88
+
89
+ ```javascript
90
+ import {
91
+ SellersSpApi,
92
+ } from '@amazon-sp-api-release/amazon-sp-api-sdk-js';
93
+ ```
94
+
95
+ ### Giving Feedback
96
+
97
+ We need your help in making this SDK great. Please participate in the community and contribute to this effort by submitting issues, participating in discussion forums and submitting pull requests through the following channels:
98
+
99
+ Submit [issues](https://github.com/amzn/selling-partner-api-sdk/issues/new/choose) - this is the preferred channel to interact with our team
100
+ Articulate your feature request or upvote existing ones on our [Issues][sdk-issues] page
101
+
102
+ [sdk-issues]: https://github.com/amzn/selling-partner-api-sdk/issues
103
+
104
+
@@ -1,29 +1,12 @@
1
- import { parse } from 'yaml';
2
- import { readFile } from 'fs/promises';
3
1
  import { RateLimitConfiguration } from './RateLimitConfiguration.mjs';
4
- import { fileURLToPath } from 'url';
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 = null;
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 "./RateLimitConfiguration.mjs";
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
- reservoirRefreshAmount: refreshAmount, // How many tokens to add during each refresh
26
- reservoirRefreshInterval: refreshInterval, // Refresh interval in milliseconds
27
- maxConcurrent: burstRequests // Maximum number of requests running at the same time
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
- // Add rate limiting before the request is sent
39
- request.on('request', async () => {
40
- try {
41
- // Schedule the request
42
- await this.#limiter.schedule(async () => {
43
- return Promise.resolve();
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
@@ -4,7 +4,7 @@
4
4
  "license": "Apache License 2.0",
5
5
  "main": "./index.js",
6
6
  "type": "module",
7
- "version": "1.0.0-rc7",
7
+ "version": "1.0.0",
8
8
  "scripts": {
9
9
  "test": "echo \"No test specified\" && exit 1"
10
10
  },
@@ -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 listTransactions API with a rate limiter and retry logic.
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(rateLimitPermit, waitTimeOutInMilliSeconds, burstRequests, retryCount) {
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
- // Option1: Use our default rate limiter. Our rate limiter uses the rate limit and burst values in our official document.
109
- ordersApiClient.enableDefaultRateLimiter();
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.enableCustomizedRateLimiter(rateLimitConfig);
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'