diff --git a/.jshintignore b/.jshintignore index 93a3c9f..5578b57 100644 --- a/.jshintignore +++ b/.jshintignore @@ -1,3 +1,4 @@ node_modules examples/typeScript -test/ \ No newline at end of file +test/ +examples/javaScript/sample/getMatchingProductAsyncAwait.js \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index f1802a8..093e67a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +0.0.22 + - Bug Fix Default value for XML parsing + - Add Support for the Subscription APIs, Recommendations API + - Add Example for CreateSubscription, DeleteSubscription, ListSubscriptions, RegisterDestination + - Add Example for GetLastUpdatedTimeForRecommendations, ListRecommendations + 0.0.21 - Handle for non content type responses - Bug fix for GetMyPriceForASIN and similar other products API diff --git a/README.md b/README.md index b1244a8..c07cff6 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,41 @@ amazonMws.setApiKey(accessKey, accessSecret); - Contributors can send their Pull Request to `development` branch. - Kindly validate test cases & linting before opening new PR. +#### Success or Error StatusCode can be obtained directly using StatusCode property of response. It will give you same as what Amazon MWS provides. +#### It is also sample of the error responses. +``` +{ + Type:'Sender', + Code:'InvalidRequestException', + Message:'Invalid xxxxx: ', + Headers: { + 'x-mws-quota-max': '', + 'x-mws-quota-remaining': '', + 'x-mws-quota-resetson': '', + 'x-mws-timestamp': '2018-09-05T06:13:00.276Z', + 'content-type': 'text/xml', + 'content-charset': '', + 'content-length': '', + 'content-md5': '', + 'date': '' + }, + StatusCode:400, + RequestId: 'XXXXX-XXXXXX-XXXXX' +} +``` + +#### Additionally all api returns Throttling: Limits to how often you can submit requests +Reference : http://docs.developer.amazonservices.com/en_CA/dev_guide/DG_Throttling.html +```json +{ + "x-mws-quota-max": "60.0", + "x-mws-quota-remaining": "38.0", + "x-mws-quota-resetson": "2017-12-08T08:21:00.000Z", + "x-mws-timestamp": "2017-12-08T07:52:15.567Z" +} +``` +Originally by [Bhushankumar Lilapara](https://github.com/bhushankumarl) (bhushankumar.lilapara@gmail.com). + ### Feeds #### Submit Feed @@ -300,7 +335,6 @@ amazonMws.setApiKey(accessKey, accessSecret); }); ``` - ### Orders #### List Orders @@ -432,15 +466,16 @@ amazonMws.setApiKey(accessKey, accessSecret); }); ``` -### Sellers +### Recommendations -#### List Marketplace Participations +#### Get Last Updated Time For Recommendations ```js - amazonMws.sellers.search({ - 'Version': '2011-07-01', - 'Action': 'ListMarketplaceParticipations', + amazonMws.recommendations.searchFor({ + 'Version': '2013-04-01', + 'Action': 'GetLastUpdatedTimeForRecommendations', 'SellerId': 'SELLER_ID', - 'MWSAuthToken': 'MWS_AUTH_TOKEN' + 'MWSAuthToken': 'MWS_AUTH_TOKEN', + 'MarketplaceId': 'MARKET_PLACE_ID' }, function (error, response) { if (error) { console.log('error ', error); @@ -450,14 +485,17 @@ amazonMws.setApiKey(accessKey, accessSecret); }); ``` -#### List Marketplace Participations By Next Token +#### List Recommendations ```js - amazonMws.sellers.search({ - 'Version': '2011-07-01', - 'Action': 'ListMarketplaceParticipationsByNextToken', + amazonMws.recommendations.searchFor({ + 'Version': '2013-04-01', + 'Action': 'ListRecommendations', 'SellerId': 'SELLER_ID', 'MWSAuthToken': 'MWS_AUTH_TOKEN', - 'NextToken': 'NEXT_TOKEN' + 'MarketplaceId': 'MARKET_PLACE_ID', + 'CategoryQueryList.CategoryQuery.1.FilterOptions.FilterOption.1': 'QualitySet=Defect', + 'CategoryQueryList.CategoryQuery.1.FilterOptions.FilterOption.2': 'ListingStatus=Active', + 'CategoryQueryList.CategoryQuery.1.RecommendationCategory': 'ListingQuality' }, function (error, response) { if (error) { console.log('error ', error); @@ -555,37 +593,99 @@ amazonMws.setApiKey(accessKey, accessSecret); } ``` -#### Success or Error StatusCode can be obtained directly using StatusCode property of response. It will give you same as what Amazon MWS provides. -#### It is also sample of the error responses. +### Sellers + +#### List Marketplace Participations +```js + amazonMws.sellers.search({ + 'Version': '2011-07-01', + 'Action': 'ListMarketplaceParticipations', + 'SellerId': 'SELLER_ID', + 'MWSAuthToken': 'MWS_AUTH_TOKEN' + }, function (error, response) { + if (error) { + console.log('error ', error); + return; + } + console.log('response', response); + }); ``` -{ - Type:'Sender', - Code:'InvalidRequestException', - Message:'Invalid xxxxx: ', - Headers: { - 'x-mws-quota-max': '', - 'x-mws-quota-remaining': '', - 'x-mws-quota-resetson': '', - 'x-mws-timestamp': '2018-09-05T06:13:00.276Z', - 'content-type': 'text/xml', - 'content-charset': '', - 'content-length': '', - 'content-md5': '', - 'date': '' - }, - StatusCode:400, - RequestId: 'XXXXX-XXXXXX-XXXXX' -} + +#### List Marketplace Participations By Next Token +```js + amazonMws.sellers.search({ + 'Version': '2011-07-01', + 'Action': 'ListMarketplaceParticipationsByNextToken', + 'SellerId': 'SELLER_ID', + 'MWSAuthToken': 'MWS_AUTH_TOKEN', + 'NextToken': 'NEXT_TOKEN' + }, function (error, response) { + if (error) { + console.log('error ', error); + return; + } + console.log('response', response); + }); ``` -#### Additionally all api returns Throttling: Limits to how often you can submit requests -Reference : http://docs.developer.amazonservices.com/en_CA/dev_guide/DG_Throttling.html -```json -{ - "x-mws-quota-max": "60.0", - "x-mws-quota-remaining": "38.0", - "x-mws-quota-resetson": "2017-12-08T08:21:00.000Z", - "x-mws-timestamp": "2017-12-08T07:52:15.567Z" -} +### Subscriptions + +#### Create Subscription +```js + amazonMws.subscriptions.create({ + 'Version': '2013-07-01', + 'Action': 'CreateSubscription', + 'SellerId': 'SELLER_ID', + 'MWSAuthToken': 'MWS_AUTH_TOKEN', + 'MarketplaceId': 'MARKET_PLACE_ID', + 'Subscription.Destination.AttributeList.member.1.Key': 'DESTINATION_KEY', + 'Subscription.Destination.AttributeList.member.1.Value': 'DESTINATION_VALUE', + 'Subscription.Destination.DeliveryChannel': 'DESTINATION_CHANNEL', + 'Subscription.IsEnabled': 'true', + 'Subscription.NotificationType': 'AnyOfferChanged' + }, function (error, response) { + if (error) { + console.log('error ', error); + return; + } + console.log('response', response); + }); ``` -Originally by [Bhushankumar Lilapara](https://github.com/bhushankumarl) (bhushankumar.lilapara@gmail.com). + +#### Delete Subscription +```js + amazonMws.subscriptions.remove({ + 'Version': '2013-07-01', + 'Action': 'DeleteSubscription', + 'SellerId': 'SELLER_ID', + 'MWSAuthToken': 'MWS_AUTH_TOKEN', + 'MarketplaceId': 'MARKET_PLACE_ID', + 'Destination.AttributeList.member.1.Key': 'DESTINATION_KEY', + 'Destination.AttributeList.member.1.Value': 'DESTINATION_VALUE', + 'Destination.DeliveryChannel': 'DESTINATION_CHANNEL', + 'NotificationType': 'AnyOfferChanged' + }, function (error, response) { + if (error) { + console.log('error ', error); + return; + } + console.log('response', response); + }); +``` + +#### List Subscription +```js + amazonMws.subscriptions.searchFor({ + 'Version': '2013-07-01', + 'Action': 'ListSubscriptions', + 'SellerId': 'SELLER_ID', + 'MWSAuthToken': 'MWS_AUTH_TOKEN', + 'MarketplaceId': 'MARKET_PLACE_ID' + }, function (error, response) { + if (error) { + console.log('error ', error); + return; + } + console.log('response', response); + }); +``` \ No newline at end of file diff --git a/examples/javaScript/orders/listOrders.js b/examples/javaScript/orders/listOrders.js index 375b029..7761270 100644 --- a/examples/javaScript/orders/listOrders.js +++ b/examples/javaScript/orders/listOrders.js @@ -11,7 +11,7 @@ var orderRequest = function () { 'Action': 'ListOrders', 'SellerId': 'SELLER_ID', 'MWSAuthToken': 'MWS_AUTH_TOKEN', - 'MarketplaceId.Id.1': 'MARKET_PLEACE_ID_1', + 'MarketplaceId.Id.1': 'MARKET_PLACE_ID_1', 'LastUpdatedAfter': new Date(2016, 11, 24) }, function (error, response) { if (error) { diff --git a/examples/javaScript/orders/listOrdersFilterStatus.js b/examples/javaScript/orders/listOrdersFilterStatus.js index c7bf669..d1df4e2 100644 --- a/examples/javaScript/orders/listOrdersFilterStatus.js +++ b/examples/javaScript/orders/listOrdersFilterStatus.js @@ -12,7 +12,7 @@ var orderRequest = function () { 'Action': 'ListOrders', 'SellerId': 'SELLER_ID', 'MWSAuthToken': 'MWS_AUTH_TOKEN', - 'MarketplaceId.Id.1': 'MARKET_PLEACE_ID_1', + 'MarketplaceId.Id.1': 'MARKET_PLACE_ID_1', 'LastUpdatedAfter': new Date(2016, 11, 24), 'OrderStatus.Status.1': 'Pending', 'OrderStatus.Status.2': 'Canceled' diff --git a/examples/javaScript/products/getCompetitivePricingForASIN.js b/examples/javaScript/products/getCompetitivePricingForASIN.js new file mode 100644 index 0000000..4ec85b0 --- /dev/null +++ b/examples/javaScript/products/getCompetitivePricingForASIN.js @@ -0,0 +1,25 @@ +'use strict'; + +var accessKey = process.env.AWS_ACCESS_KEY_ID || 'YOUR_KEY'; +var accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET'; + +var amazonMws = require('../../../lib/amazon-mws')(accessKey, accessSecret); + +var productRequest = function () { + amazonMws.products.searchFor({ + 'Version': '2011-10-01', + 'Action': 'GetCompetitivePricingForASIN', + 'SellerId': 'SELLER_ID', + 'MWSAuthToken': 'MWS_AUTH_TOKEN', + 'MarketplaceId': 'MARKET_PLACE_ID', + 'ASINList.ASIN.1': 'ASIN' + }, function (error, response) { + if (error) { + console.log('error products', error); + return; + } + console.log('response ', response); + }); +}; + +productRequest(); \ No newline at end of file diff --git a/examples/javaScript/products/getMatchingProductForId.js b/examples/javaScript/products/getMatchingProductForId.js new file mode 100644 index 0000000..75651b2 --- /dev/null +++ b/examples/javaScript/products/getMatchingProductForId.js @@ -0,0 +1,27 @@ +'use strict'; + +var accessKey = process.env.AWS_ACCESS_KEY_ID || 'YOUR_KEY'; +var accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET'; + +var amazonMws = require('../../../lib/amazon-mws')(accessKey, accessSecret); + +var productRequest = function () { + + amazonMws.products.search({ + 'Version': '2011-10-01', + 'Action': 'GetMatchingProductForId', + 'SellerId': 'SELLER_ID', + 'MWSAuthToken': 'MWS_AUTH_TOKEN', + 'MarketplaceId': 'MARKET_PLACE_ID', + 'IdType': 'SellerSKU', + 'IdList.Id.1': 'SKU' + }, function (error, response) { + if (error) { + console.log('error products', error); + return; + } + console.log('response', response); + }); +}; + +productRequest(); \ No newline at end of file diff --git a/examples/javaScript/recommendations/getLastUpdatedTimeForRecommendations.js b/examples/javaScript/recommendations/getLastUpdatedTimeForRecommendations.js new file mode 100644 index 0000000..1eabefc --- /dev/null +++ b/examples/javaScript/recommendations/getLastUpdatedTimeForRecommendations.js @@ -0,0 +1,27 @@ +'use strict'; + +var accessKey = process.env.AWS_ACCESS_KEY_ID || 'YOUR_KEY'; +var accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET'; + +var amazonMws = require('../../../lib/amazon-mws')(accessKey, accessSecret); + +/** + * If the response is empty than it means their is no recommendation. + */ +var recommendationRequest = function () { + amazonMws.recommendations.searchFor({ + 'Version': '2013-04-01', + 'Action': 'GetLastUpdatedTimeForRecommendations', + 'SellerId': 'SELLER_ID', + 'MWSAuthToken': 'MWS_AUTH_TOKEN', + 'MarketplaceId': 'MARKET_PLACE_ID' + }, function (error, response) { + if (error) { + console.log('error ', error); + return; + } + console.log('response', response); + }); +}; + +recommendationRequest(); \ No newline at end of file diff --git a/examples/javaScript/recommendations/listRecommendations.js b/examples/javaScript/recommendations/listRecommendations.js new file mode 100644 index 0000000..b945600 --- /dev/null +++ b/examples/javaScript/recommendations/listRecommendations.js @@ -0,0 +1,30 @@ +'use strict'; + +var accessKey = process.env.AWS_ACCESS_KEY_ID || 'YOUR_KEY'; +var accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET'; + +var amazonMws = require('../../../lib/amazon-mws')(accessKey, accessSecret); + +/** + * If the response is empty than it means their is no recommendation. + */ +var recommendationRequest = function () { + amazonMws.recommendations.searchFor({ + 'Version': '2013-04-01', + 'Action': 'ListRecommendations', + 'SellerId': 'SELLER_ID', + 'MWSAuthToken': 'MWS_AUTH_TOKEN', + 'MarketplaceId': 'MARKET_PLACE_ID', + 'CategoryQueryList.CategoryQuery.1.FilterOptions.FilterOption.1': 'QualitySet=Defect', + 'CategoryQueryList.CategoryQuery.1.FilterOptions.FilterOption.2': 'ListingStatus=Active', + 'CategoryQueryList.CategoryQuery.1.RecommendationCategory': 'ListingQuality' + }, function (error, response) { + if (error) { + console.log('error ', error); + return; + } + console.log('response', response); + }); +}; + +recommendationRequest(); \ No newline at end of file diff --git a/examples/javaScript/sample/getMatchingProductAsyncAwait.js b/examples/javaScript/sample/getMatchingProductAsyncAwait.js new file mode 100644 index 0000000..d270278 --- /dev/null +++ b/examples/javaScript/sample/getMatchingProductAsyncAwait.js @@ -0,0 +1,25 @@ +'use strict'; + +var accessKey = process.env.AWS_ACCESS_KEY_ID || 'YOUR_KEY'; +var accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET'; + +var amazonMws = require('../../../lib/amazon-mws')(accessKey, accessSecret); + +var productRequest = async function () { + + try { + var response = await amazonMws.products.search({ + 'Version': '2011-10-01', + 'Action': 'GetMatchingProduct', + 'SellerId': 'SELLER_ID', + 'MWSAuthToken': 'MWS_AUTH_TOKEN', + 'MarketplaceId': 'MARKET_PLACE_ID', + 'ASINList.ASIN.1': 'ASIN_1' + }); + console.log('response', response); + } catch (error) { + console.log('error products', error); + } +}; + +productRequest(); \ No newline at end of file diff --git a/examples/javaScript/products/promise/getMatchingProductPromise.js b/examples/javaScript/sample/getMatchingProductPromise.js similarity index 100% rename from examples/javaScript/products/promise/getMatchingProductPromise.js rename to examples/javaScript/sample/getMatchingProductPromise.js diff --git a/examples/javaScript/sample/listOrders.js b/examples/javaScript/sample/listOrders.js index 19b1ff0..23f2c54 100644 --- a/examples/javaScript/sample/listOrders.js +++ b/examples/javaScript/sample/listOrders.js @@ -21,7 +21,7 @@ var orderRequest = function () { 'Action': 'ListOrders', 'SellerId': 'SELLER_ID', 'MWSAuthToken': 'MWS_AUTH_TOKEN', - 'MarketplaceId.Id.1': 'MARKET_PLEACE_ID_1', + 'MarketplaceId.Id.1': 'MARKET_PLACE_ID_1', 'LastUpdatedAfter': new Date(2016, 11, 24) }, function (error, response) { if (error) { diff --git a/examples/javaScript/subscriptions/createSubscription.js b/examples/javaScript/subscriptions/createSubscription.js new file mode 100644 index 0000000..8f9afc9 --- /dev/null +++ b/examples/javaScript/subscriptions/createSubscription.js @@ -0,0 +1,29 @@ +'use strict'; + +var accessKey = process.env.AWS_ACCESS_KEY_ID || 'YOUR_KEY'; +var accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET'; + +var amazonMws = require('../../../lib/amazon-mws')(accessKey, accessSecret); + +var subscriptionRequest = function () { + amazonMws.subscriptions.create({ + 'Version': '2013-07-01', + 'Action': 'CreateSubscription', + 'SellerId': 'SELLER_ID', + 'MWSAuthToken': 'MWS_AUTH_TOKEN', + 'MarketplaceId': 'MARKET_PLACE_ID', + 'Subscription.Destination.AttributeList.member.1.Key': 'DESTINATION_KEY', + 'Subscription.Destination.AttributeList.member.1.Value': 'DESTINATION_VALUE', + 'Subscription.Destination.DeliveryChannel': 'DESTINATION_CHANNEL', + 'Subscription.IsEnabled': 'true', + 'Subscription.NotificationType': 'AnyOfferChanged' + }, function (error, response) { + if (error) { + console.log('error ', error); + return; + } + console.log('response', response); + }); +}; + +subscriptionRequest(); \ No newline at end of file diff --git a/examples/javaScript/subscriptions/deleteSubscription.js b/examples/javaScript/subscriptions/deleteSubscription.js new file mode 100644 index 0000000..b2c0839 --- /dev/null +++ b/examples/javaScript/subscriptions/deleteSubscription.js @@ -0,0 +1,28 @@ +'use strict'; + +var accessKey = process.env.AWS_ACCESS_KEY_ID || 'YOUR_KEY'; +var accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET'; + +var amazonMws = require('../../../lib/amazon-mws')(accessKey, accessSecret); + +var subscriptionRequest = function () { + amazonMws.subscriptions.remove({ + 'Version': '2013-07-01', + 'Action': 'DeleteSubscription', + 'SellerId': 'SELLER_ID', + 'MWSAuthToken': 'MWS_AUTH_TOKEN', + 'MarketplaceId': 'MARKET_PLACE_ID', + 'Destination.AttributeList.member.1.Key': 'DESTINATION_KEY', + 'Destination.AttributeList.member.1.Value': 'DESTINATION_VALUE', + 'Destination.DeliveryChannel': 'DESTINATION_CHANNEL', + 'NotificationType': 'AnyOfferChanged' + }, function (error, response) { + if (error) { + console.log('error ', error); + return; + } + console.log('response', response); + }); +}; + +subscriptionRequest(); \ No newline at end of file diff --git a/examples/javaScript/subscriptions/listSubscriptions.js b/examples/javaScript/subscriptions/listSubscriptions.js new file mode 100644 index 0000000..7e28990 --- /dev/null +++ b/examples/javaScript/subscriptions/listSubscriptions.js @@ -0,0 +1,24 @@ +'use strict'; + +var accessKey = process.env.AWS_ACCESS_KEY_ID || 'YOUR_KEY'; +var accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET'; + +var amazonMws = require('../../../lib/amazon-mws')(accessKey, accessSecret); + +var subscriptionRequest = function () { + amazonMws.subscriptions.searchFor({ + 'Version': '2013-07-01', + 'Action': 'ListSubscriptions', + 'SellerId': 'SELLER_ID', + 'MWSAuthToken': 'MWS_AUTH_TOKEN', + 'MarketplaceId': 'MARKET_PLACE_ID' + }, function (error, response) { + if (error) { + console.log('error ', error); + return; + } + console.log('response', response); + }); +}; + +subscriptionRequest(); \ No newline at end of file diff --git a/examples/javaScript/subscriptions/registerDestination.js b/examples/javaScript/subscriptions/registerDestination.js new file mode 100644 index 0000000..911187c --- /dev/null +++ b/examples/javaScript/subscriptions/registerDestination.js @@ -0,0 +1,27 @@ +'use strict'; + +var accessKey = process.env.AWS_ACCESS_KEY_ID || 'YOUR_KEY'; +var accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET'; + +var amazonMws = require('../../../lib/amazon-mws')(accessKey, accessSecret); + +var subscriptionRequest = function () { + amazonMws.subscriptions.create({ + 'Version': '2013-07-01', + 'Action': 'RegisterDestination', + 'SellerId': 'SELLER_ID', + 'MWSAuthToken': 'MWS_AUTH_TOKEN', + 'MarketplaceId': 'MARKET_PLACE_ID', + 'Destination.AttributeList.member.1.Key': 'DESTINATION_KEY', + 'Destination.AttributeList.member.1.Value': 'DESTINATION_VALUE', + 'Destination.DeliveryChannel': 'DESTINATION_CHANNEL' + }, function (error, response) { + if (error) { + console.log('error ', error); + return; + } + console.log('response', response); + }); +}; + +subscriptionRequest(); \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index edf1451..703769a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -52,10 +52,24 @@ declare class Reports extends BaseAmazonMWS { } +declare class Recommendations extends BaseAmazonMWS { + + searchFor(params: any): Promise; + +} + declare class Sellers extends BaseAmazonMWS { } +declare class Subscriptions extends BaseAmazonMWS { + + searchFor(params: any): Promise; + + remove(params: any): Promise; + +} + declare class AmazonMWS { constructor() diff --git a/lib/AmazonMwsResource.js b/lib/AmazonMwsResource.js index a2ffb45..7567807 100644 --- a/lib/AmazonMwsResource.js +++ b/lib/AmazonMwsResource.js @@ -151,7 +151,15 @@ AmazonMwsResource.prototype = { function parseCSVFile(res, responseString, delimiter, callback) { var data = []; - csv.fromString(responseString, {headers: true, delimiter: delimiter, ignoreEmpty: true, quote: null}) + var options = { + delimiter: delimiter, + headers: true, + discardUnmappedColumns: true, + quote: null, + ignoreEmpty: true, + trim: true + }; + csv.fromString(responseString, options) .on('data', function (value) { data.push(value); }) @@ -171,7 +179,8 @@ AmazonMwsResource.prototype = { var xmlParser = new xml2js.Parser({ mergeAttrs: true, explicitArray: false, - emptyTag: {} + emptyTag: {}, + charkey: 'Value' }); if (!res.headers['content-type']) { debug('Content type has not set, so considered it as XML response'); @@ -182,7 +191,7 @@ AmazonMwsResource.prototype = { } else if (RESPONSE_CONTENT_TYPE_XML.indexOf(res.headers['content-type'].toLowerCase()) > -1) { debug('It is XML Response'); xmlParser.parseString(responseString, function (err, response) { - // debug('response after parsing JSON %o ', response); + debug('response after parsing JSON %o ', response); return callback(null, response); }); } else if (_.includes(responseString, '?xml')) { @@ -325,7 +334,7 @@ AmazonMwsResource.prototype = { if (response[requestParamsJSONCopy.Action + 'Response']) { response = response[requestParamsJSONCopy.Action + 'Response']; } - //debug('response', response); + // debug('response', response); try { ResponseMetadata = response.ResponseMetadata; } catch (exception) { @@ -333,7 +342,8 @@ AmazonMwsResource.prototype = { ResponseMetadata = {}; } // debug('ResponseMetadata %o ', ResponseMetadata); - if (response[requestParamsJSONCopy.Action + 'Result']) { + // debug('Result %o ', response[requestParamsJSONCopy.Action + 'Result']); + if (response[requestParamsJSONCopy.Action + 'Result'] !== undefined) { response = response[requestParamsJSONCopy.Action + 'Result']; } diff --git a/lib/amazon-mws.js b/lib/amazon-mws.js index acd4f38..2112a95 100644 --- a/lib/amazon-mws.js +++ b/lib/amazon-mws.js @@ -31,11 +31,13 @@ var resources = { fulfillmentInboundShipment: require('./resources/FulfillmentInboundShipment'), fulfillmentOutboundShipment: require('./resources/FulfillmentOutboundShipment'), fulfillmentInventory: require('./resources/FulfillmentInventory'), - sellers: require('./resources/Sellers'), + merchantFulfillment: require('./resources/MerchantFulfillment'), products: require('./resources/Products'), orders: require('./resources/Orders'), + recommendations: require('./resources/Recommendations'), reports: require('./resources/Reports'), - merchantFulfillment: require('./resources/MerchantFulfillment') + subscriptions: require('./resources/Subscriptions'), + sellers: require('./resources/Sellers') }; AmazonMws.AmazonMwsResource = require('./AmazonMwsResource'); diff --git a/lib/resources/Recommendations.js b/lib/resources/Recommendations.js new file mode 100644 index 0000000..aea8e99 --- /dev/null +++ b/lib/resources/Recommendations.js @@ -0,0 +1,13 @@ +'use strict'; + +var AmazonMwsResource = require('../AmazonMwsResource'); +var amazonMwsMethod = AmazonMwsResource.method; + +module.exports = AmazonMwsResource.extend({ + + path: 'Recommendations', + searchFor: amazonMwsMethod({ + method: 'POST' + }) + +}); diff --git a/lib/resources/Subscriptions.js b/lib/resources/Subscriptions.js new file mode 100644 index 0000000..339695e --- /dev/null +++ b/lib/resources/Subscriptions.js @@ -0,0 +1,19 @@ +'use strict'; + +var AmazonMwsResource = require('../AmazonMwsResource'); +var amazonMwsMethod = AmazonMwsResource.method; + +module.exports = AmazonMwsResource.extend({ + + path: 'Subscriptions', + create: amazonMwsMethod({ + method: 'POST' + }), + remove: amazonMwsMethod({ + method: 'POST' + }), + searchFor: amazonMwsMethod({ + method: 'POST' + }) + +}); diff --git a/package.json b/package.json index a08d440..ccee075 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "amazon-mws", - "version": "0.0.21", + "version": "0.0.22", "description": "Amazon MWS API wrapper", "keywords": [ "Amazon MWS", diff --git a/test/specs/products.spec.js b/test/specs/products.spec.js index 10dbe56..459fcc6 100644 --- a/test/specs/products.spec.js +++ b/test/specs/products.spec.js @@ -100,7 +100,7 @@ describe('Products', function () { expect(response).to.have.property('Headers').to.have.property('x-mws-timestamp'); }); - it('It should NOT get my price for INVALID ASIN using getMyPriceForASIN Action', async function () { + it('It should NOT get my price for INVALID ASIN using GetMyPriceForASIN Action', async function () { var options = { 'Version': '2011-10-01', 'Action': 'GetMyPriceForASIN', @@ -115,7 +115,6 @@ describe('Products', function () { try { var response = await amazonMws.products.searchFor(options); - expect(response).to.be.a('object'); expect(response).to.have.property('ASIN').to.be.a('string'); expect(response).to.have.property('status').to.be.a('string'); @@ -127,20 +126,60 @@ describe('Products', function () { expect(response).to.have.property('Headers').to.have.property('x-mws-quota-remaining'); expect(response).to.have.property('Headers').to.have.property('x-mws-quota-resetson'); expect(response).to.have.property('Headers').to.have.property('x-mws-timestamp'); - } catch (exception) { - console.log('exception ', exception); - expect(exception).to.be.a('object'); - expect(exception).to.have.property('Type').to.be.a('string'); - expect(exception).to.have.property('Message').to.be.a('string'); - expect(exception).to.have.property('Detail').to.be.a('object'); - expect(exception).to.have.property('StatusCode').to.be.a('number'); - expect(exception).to.have.property('RequestId').to.be.a('string'); - expect(exception).to.have.property('Headers').to.be.a('object'); - expect(exception).to.have.property('Headers').to.have.property('x-mws-quota-max'); - expect(exception).to.have.property('Headers').to.have.property('x-mws-quota-remaining'); - expect(exception).to.have.property('Headers').to.have.property('x-mws-quota-resetson'); - expect(exception).to.have.property('Headers').to.have.property('x-mws-timestamp'); + } catch (error) { + console.log('error ', error); + expect(error).to.be.a('object'); + expect(error).to.have.property('Type').to.be.a('string'); + expect(error).to.have.property('Message').to.be.a('string'); + expect(error).to.have.property('Detail').to.be.a('object'); + expect(error).to.have.property('StatusCode').to.be.a('number'); + expect(error).to.have.property('RequestId').to.be.a('string'); + expect(error).to.have.property('Headers').to.be.a('object'); + expect(error).to.have.property('Headers').to.have.property('x-mws-quota-max'); + expect(error).to.have.property('Headers').to.have.property('x-mws-quota-remaining'); + expect(error).to.have.property('Headers').to.have.property('x-mws-quota-resetson'); + expect(error).to.have.property('Headers').to.have.property('x-mws-timestamp'); } }); + + + it('It should get my price for ASIN using GetCompetitivePricingForASIN Action', async function () { + var options = { + 'Version': '2011-10-01', + 'Action': 'GetCompetitivePricingForASIN', + 'SellerId': config.SellerId, + 'MWSAuthToken': config.MWSAuthToken, + 'MarketplaceId': config.MarketplaceId, + 'ASINList.ASIN.1': config.ASIN + }; + expect(options.SellerId).to.be.a('string'); + expect(options.MWSAuthToken).to.be.a('string'); + expect(options.MarketplaceId).to.be.a('string'); + expect(options['ASINList.ASIN.1']).to.be.a('string'); + + try { + var response = await amazonMws.products.searchFor(options); + expect(response).to.be.a('object'); + expect(response).to.have.property('ASIN').to.be.a('string'); + expect(response).to.have.property('status').to.be.a('string'); + expect(response).to.have.property('Product').to.be.a('object'); + expect(response).to.have.property('Product').to.have.property('CompetitivePricing'); + expect(response).to.have.property('Product').to.have.property('CompetitivePricing').to.have.property('NumberOfOfferListings'); + expect(response).to.have.property('Product').to.have.property('CompetitivePricing').to.have.property('NumberOfOfferListings').to.have.property('OfferListingCount').to.be.a('array'); + expect(response.Product.CompetitivePricing.NumberOfOfferListings.OfferListingCount[0]).to.have.property('condition'); + expect(response.Product.CompetitivePricing.NumberOfOfferListings.OfferListingCount[0]).to.have.property('Value'); + expect(response).to.have.property('ResponseMetadata').to.be.a('object'); + expect(response).to.have.property('ResponseMetadata').to.have.property('RequestId'); + expect(response).to.have.property('Headers').to.be.a('object'); + expect(response).to.have.property('Headers').to.have.property('x-mws-quota-max'); + expect(response).to.have.property('Headers').to.have.property('x-mws-quota-remaining'); + expect(response).to.have.property('Headers').to.have.property('x-mws-quota-resetson'); + expect(response).to.have.property('Headers').to.have.property('x-mws-timestamp'); + } catch (error) { + console.log('error ', error); + expect(error).to.be.undefined; + } + }); + }); \ No newline at end of file diff --git a/test/specs/recommendations.spec.js b/test/specs/recommendations.spec.js new file mode 100644 index 0000000..811f907 --- /dev/null +++ b/test/specs/recommendations.spec.js @@ -0,0 +1,49 @@ +'use strict'; +var config = require('../intialize/config'); +var accessKey = config.accessKey; +var accessSecret = config.accessSecret; + +var chai = require('chai'); +var expect = chai.expect; + +var amazonMws = require('../../lib/amazon-mws')(accessKey, accessSecret); + +describe('Recommendations', function () { + + before(function () { + expect(accessKey).to.be.a('string'); + expect(accessSecret).to.be.a('string'); + }); + + it('It should list of recommendations using ListRecommendations Action', async function () { + var options = { + 'Version': '2013-04-01', + 'Action': 'ListRecommendations', + 'SellerId': config.SellerId, + 'MWSAuthToken': config.MWSAuthToken, + 'MarketplaceId': config.MarketplaceId, + 'CategoryQueryList.CategoryQuery.1.FilterOptions.FilterOption.1': 'QualitySet=Defect', + 'CategoryQueryList.CategoryQuery.1.FilterOptions.FilterOption.2': 'ListingStatus=Active', + 'CategoryQueryList.CategoryQuery.1.RecommendationCategory': 'ListingQuality' + }; + expect(options.SellerId).to.be.a('string'); + expect(options.MWSAuthToken).to.be.a('string'); + expect(options.MarketplaceId).to.be.a('string'); + + try { + var response = await amazonMws.recommendations.searchFor(options); + expect(response).to.be.a('object'); + expect(response).to.have.property('ResponseMetadata').to.be.a('object'); + expect(response).to.have.property('ResponseMetadata').to.have.property('RequestId'); + expect(response).to.have.property('Headers').to.be.a('object'); + expect(response).to.have.property('Headers').to.have.property('x-mws-quota-max'); + expect(response).to.have.property('Headers').to.have.property('x-mws-quota-remaining'); + expect(response).to.have.property('Headers').to.have.property('x-mws-quota-resetson'); + expect(response).to.have.property('Headers').to.have.property('x-mws-timestamp'); + } catch (error) { + console.log('error ', error); + expect(error).to.be.undefined; + } + }); + +}); \ No newline at end of file diff --git a/test/specs/subscriptions.spec.js b/test/specs/subscriptions.spec.js new file mode 100644 index 0000000..59eda45 --- /dev/null +++ b/test/specs/subscriptions.spec.js @@ -0,0 +1,46 @@ +'use strict'; +var config = require('../intialize/config'); +var accessKey = config.accessKey; +var accessSecret = config.accessSecret; + +var chai = require('chai'); +var expect = chai.expect; + +var amazonMws = require('../../lib/amazon-mws')(accessKey, accessSecret); + +describe('Subscriptions', function () { + + before(function () { + expect(accessKey).to.be.a('string'); + expect(accessSecret).to.be.a('string'); + }); + + it('It should list of subscriptions using ListSubscriptions Action', async function () { + var options = { + 'Version': '2013-07-01', + 'Action': 'ListSubscriptions', + 'SellerId': config.SellerId, + 'MWSAuthToken': config.MWSAuthToken, + 'MarketplaceId': config.MarketplaceId + }; + expect(options.SellerId).to.be.a('string'); + expect(options.MWSAuthToken).to.be.a('string'); + expect(options.MarketplaceId).to.be.a('string'); + + try { + var response = await amazonMws.subscriptions.searchFor(options); + expect(response).to.be.a('object'); + expect(response).to.have.property('ResponseMetadata').to.be.a('object'); + expect(response).to.have.property('ResponseMetadata').to.have.property('RequestId'); + expect(response).to.have.property('Headers').to.be.a('object'); + expect(response).to.have.property('Headers').to.have.property('x-mws-quota-max'); + expect(response).to.have.property('Headers').to.have.property('x-mws-quota-remaining'); + expect(response).to.have.property('Headers').to.have.property('x-mws-quota-resetson'); + expect(response).to.have.property('Headers').to.have.property('x-mws-timestamp'); + } catch (error) { + console.log('error ', error); + expect(error).to.be.undefined; + } + }); + +}); \ No newline at end of file