UNPKG

mws-zodane-advanced

Version:

fixed throtal resend

285 lines (260 loc) 15.8 kB
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <base data-ice="baseUrl" href="../../"> <title data-ice="title">lib/get-lowest-priced-offers.js | mws-advanced</title> <link type="text/css" rel="stylesheet" href="css/style.css"> <link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css"> <script src="script/prettify/prettify.js"></script> <script src="script/manual.js"></script> </head> <body class="layout-container" data-ice="rootContainer"> <header> <a href="./">Home</a> <a href="identifiers.html">Reference</a> <a href="source.html">Source</a> <div class="search-box"> <span> <img src="./image/search.png"> <span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span> </span> <ul class="search-result"></ul> </div> </header> <nav class="navigation" data-ice="nav"><div> <ul> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors.js~InvalidUsage.html">InvalidUsage</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors.js~RequestCancelled.html">RequestCancelled</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors.js~ServiceError.html">ServiceError</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/lib/errors.js~ValidationError.html">ValidationError</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-callEndpoint">callEndpoint</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-init">init</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-getLowestPricedOffersForASIN">getLowestPricedOffersForASIN</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-getMarketplaces">getMarketplaces</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-getMatchingProductForId">getMatchingProductForId</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-listFinancialEvents">listFinancialEvents</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-listInventorySupply">listInventorySupply</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-listOrderItems">listOrderItems</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-listOrders">listOrders</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-getReport">getReport</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-getReportList">getReportList</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-getReportListAll">getReportListAll</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-getReportListByNextToken">getReportListByNextToken</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-getReportRequestList">getReportRequestList</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-requestAndDownloadReport">requestAndDownloadReport</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-requestReport">requestReport</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-MWS_ENDPOINTS">MWS_ENDPOINTS</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-MWS_MARKETPLACES">MWS_MARKETPLACES</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-BuyBoxPrice">BuyBoxPrice</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-DetailedShippingTime">DetailedShippingTime</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-LowestPrice">LowestPrice</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-LowestPricedOffers">LowestPricedOffers</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-Money">Money</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-Offer">Offer</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-OfferCount">OfferCount</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-OfferSummary">OfferSummary</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-SellerFeedbackRating">SellerFeedbackRating</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-ShipsFrom">ShipsFrom</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-MarketDetail">MarketDetail</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-OrderItemList">OrderItemList</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-GetReportRequestListResult">GetReportRequestListResult</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-GetReportRequestListResult">GetReportRequestListResult</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-ReportRequestInfo">ReportRequestInfo</a></span></span></li> <li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#endpoints">endpoints</a><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-REPORT_PROCESSING_STATUS_TYPES">REPORT_PROCESSING_STATUS_TYPES</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-REQUEST_REPORT_TYPES">REQUEST_REPORT_TYPES</a></span></span></li> </ul> </div> </nav> <div class="content" data-ice="content"><h1 data-ice="title">lib/get-lowest-priced-offers.js</h1> <pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content">const { callEndpoint } = require(&apos;./callEndpoint&apos;); const { forceArray } = require(&apos;./util/transformers&apos;); /** * @typedef OfferCount * @param {number} count * @param {string} condition * @param {string} fulfillmentChannel */ /** * Reformat an OfferCount. Incoming OfferCount looks like: * { * &quot;_&quot;: &quot;31&quot;, * &quot;$&quot;: { * &quot;condition&quot;: &quot;used&quot;, * &quot;fulfillmentChannel&quot;: &quot;Merchant&quot; * } * } * * @private * @param {object} offerCount OfferCount from MWS API * @param {string} offerCount._ Number of Offers that match this type * @param {object} offerCount.$ Object describing the type of Offers * @param {object} offerCount.$.condition Offer Condition (used, new, etc) * @param {object} offerCount.$.fulfillmentChannel Merchant or Amazon (FBM or FBA) * * @return {OfferCount} */ const reformatOfferCount = offerCount =&gt; ({ count: parseInt(offerCount._, 10), condition: offerCount.$.condition, fulfillmentChannel: offerCount.$.fulfillmentChannel, }); /** @typedef SellerFeedbackRating * @param {string} unknown */ /** @typedef DetailedShippingTime * @param {string} unknown */ /** @typedef Money * @param {string} unknown */ /** @typedef ShipsFrom * @param {string} unknown */ /** * @typedef Offer * @param {string} subCondition - The subcondition of the item (New, Mint, Very Good, Good, Acceptable, Poor, Club, OEM, Warranty, Refurbished Warranty, Refurbished, Open Box, or Other) * @param {SellerFeedbackRating} sellerFeedbackRating - Information about the seller&apos;s feedback * @param {DetailedShippingTime} shippingTime - Maximum time within which the item will likely be shipped * @param {Money} listingPrice - The price of the item * @param {Points} [points] - The number of Amazon Points offered with the purchase of an item * @param {Money} shipping - Cost of shipping * @param {ShipsFrom} [shipsFrom] - State and Country where item is shipped from * @param {boolean} isFulfilledByAmazon - True if FBA, False if not * @param {boolean} [isBuyBoxWinner] - True if offer has buy box, False if not * @param {boolean} [isFeaturedMerchant] - True if seller is eligible for Buy Box, False if not */ /** * Reformat an Offer * * @private * @param {object} offer Offer from MWS API * @return {Offer} */ const reformatOffer = offer =&gt; ({ subCondition: offer.SubCondition, sellerFeedbackRating: offer.SellerFeedbackRating, shippingTime: offer.ShippingTime.$, listingPrice: offer.ListingPrice, shipping: offer.Shipping, shipsFrom: offer.ShipsFrom, points: offer.Points, isFulfilledByAmazon: (offer.IsFulfilledByAmazon === &apos;true&apos;), isBuyBoxWinner: (offer.IsBuyBoxWinner === &apos;true&apos;), isFeaturedMerchant: (offer.IsFeaturedMerchant === &apos;true&apos;), }); /** * @typedef LowestPrice * @param {string} condition * @param {string} fulfillmentChannel * @param {Money} landedPrice * @param {Money} listingPrice * @param {string} shipping */ /** * Reformat a Lowest Price * * @private * @param {object} lp Lowest Price object from MWS API * returns {LowestPrice} */ const reformatLowestPrice = lp =&gt; ({ condition: lp.$.condition, fulfillmentChannel: lp.$.fulfillmentChannel, landedPrice: lp.LandedPrice, listingPrice: lp.ListingPrice, shipping: lp.Shipping, }); /** @typedef BuyBoxPrice * @param {string} condition * @param {Money} landedPrice * @param {Money} listingPrice * @param {Money} shipping */ /** * Reformat a Buy Box Price * * @private * @param {any} bb Buy Box Price object from MWS API * returns {BuyBoxPrice} */ const reformatBuyBoxPrice = bb =&gt; ({ condition: bb.$.condition, landedPrice: bb.LandedPrice, listingPrice: bb.ListingPrice, shipping: bb.Shipping, }); /** * @typedef OfferSummary * @param {number} totalOfferCount * @param {number} numberOfOffers * @param {Money} listPrice * @param {LowestPrice[]} lowestPrices * @param {Array} buyBoxPrices */ /** * reformat an Offer Summary into something a little more sane looking * * @private * @param {object} Offer Summary (has lots of keys) * @return {OfferSummary} */ const reformatSummary = (summary) =&gt; { const buyBoxPrices = forceArray(summary.BuyBoxPrices); const ret = {}; ret.totalOfferCount = parseInt(summary.TotalOfferCount, 10); ret.numberOfOffers = summary.NumberOfOffers.OfferCount.map(reformatOfferCount); ret.listPrice = summary.ListPrice; ret.lowestPrices = summary.LowestPrices.LowestPrice.map(reformatLowestPrice); ret.buyBoxPrices = buyBoxPrices &amp;&amp; buyBoxPrices.map(reformatBuyBoxPrice); ret.buyBoxEligibleOffers = summary.BuyBoxEligibleOffers.OfferCount.map(reformatOfferCount); return ret; }; /** * @typedef LowestPricedOffers * @param {string} asin - asin returned by request * @param {string} marketplace - marketplace asin is in * @param {string} itemCondition - condition of item requested * @param {OfferSummary} summary - * @param {Offers[]} offers - list of offers */ /** * getLowestPricedOffersForASIN * * Calls GetLowestPricedOffersForASIN, reformats results, and returns the data * * @param {object} options see https://docs.developer.amazonservices.com/en_UK/products/Products_GetLowestPricedOffersForASIN.html * @param {string} options.MarketplaceId Marketplace ID to search * @param {string} options.ASIN ASIN to search for * @param {string} options.ItemCondition Listing Condition: New, Used, Collectible, Refurbished, Club * * @return {LowestPricedOffers} */ const getLowestPricedOffersForASIN = async (options) =&gt; { const results = await callEndpoint(&apos;GetLowestPricedOffersForASIN&apos;, options); const identifier = results.Identifier; const summary = results.Summary; const offers = forceArray(results.Offers.Offer); const ret = {}; ret.asin = identifier.ASIN; ret.marketplace = identifier.MarketplaceId; ret.itemCondition = identifier.ItemCondition; ret.summary = reformatSummary(summary); ret.lowestOffers = offers.map(reformatOffer); return ret; }; module.exports = { getLowestPricedOffersForASIN }; </code></pre> </div> <footer class="footer"> Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(1.0.4)</span><img src="./image/esdoc-logo-mini-black.png"></a> </footer> <script src="script/search_index.js"></script> <script src="script/search.js"></script> <script src="script/pretty-print.js"></script> <script src="script/inherited-summary.js"></script> <script src="script/test-summary.js"></script> <script src="script/inner-link.js"></script> <script src="script/patch-for-local.js"></script> </body> </html>