Skip to content

Commit

Permalink
Merge pull request #99 from bhushankumarl/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Bhushankumar L authored Dec 31, 2019
2 parents e531635 + f330cee commit e58d2e3
Show file tree
Hide file tree
Showing 27 changed files with 1,022 additions and 667 deletions.
26 changes: 26 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[vcbuild.bat]
end_of_line = crlf

[Makefile]
indent_size = 8
indent_style = tab

[{deps}/**]
charset = unset
end_of_line = unset
indent_size = unset
indent_style = unset
trim_trailing_whitespace = unset

[{test/fixtures,deps,tools/node_modules,tools/gyp,tools/icu,tools/msvs}/**]
insert_final_newline = false
48 changes: 46 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export DEBUG=MWS:*
```bash
export AWS_ACCESS_KEY_ID=KEY
export AWS_SECRET_ACCESS_KEY=SECRET

#optional MWS Token
export MWS_AUTH_TOKEN=TOKEN

#optional proxy
export MARKETPLACE_PROXY=http://your.proxy.domain
```

## Configuration Using JavaScript
Expand Down Expand Up @@ -174,9 +180,47 @@ Originally by [Bhushankumar L](mailto:[email protected]).
});
```

#### Submit Feed
#### Get Feed Submission Result as Stream
```
/**
* Use __STREAM__ to get the request in response;
*/
var FeedSubmissionId = '10101010XXX';
amazonMws.feeds.search({
'Version': '2009-01-01',
'Action': 'GetFeedSubmissionResult',
'SellerId': 'SELLER_ID',
'MWSAuthToken': 'MWS_AUTH_TOKEN',
'FeedSubmissionId': FeedSubmissionId,
__STREAM__: true
}, function (error, response) {
if (error) {
console.log('error ', error);
return;
}
response
.pipe(iconv.decodeStream('ISO-8859-1'))
.pipe(
csv.parse({
delimiter: '\t',
headers: true,
discardUnmappedColumns: true,
quote: null,
ignoreEmpty: true,
trim: true
})
)
.on('data', row => {
processRow(row);
})
.on('error', error => { console.error(error); })
.on('end', rowCount => { console.log(`Processed rows ${rowCount}`); });
});
```

#### Submit Feed [more feed xml demo](https://github.com/bhushankumarl/amazon-mws/tree/master/examples/javascript/feeds). or see https://images-cn.ssl-images-amazon.com/images/G/28/rainier/help/XML_Documentation_Intl._V158771171_.pdf
```
var FeedContent = fse.readFileSync('./file.txt', 'UTF-8');
var FeedContent = fse.readFileSync('./good.xml', 'UTF-8');
console.log('FeedContent ', FeedContent);
amazonMws.feeds.submit({
Expand Down
17 changes: 0 additions & 17 deletions examples/javaScript/feeds/file.txt

This file was deleted.

43 changes: 43 additions & 0 deletions examples/javaScript/feeds/good.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8" ?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amznenvelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>SellerID</MerchantIdentifier>
</Header>
<MessageType>Product</MessageType>
<PurgeAndReplace>false</PurgeAndReplace>
<Message>
<MessageID>1</MessageID>
<OperationType>Update</OperationType>
<Product>
<SKU>xxx-9527</SKU>
<StandardProductID>
<Type>EAN</Type>
<Value>xxxxx</Value>
</StandardProductID>
<ProductTaxCode>A_GEN_NOTAX</ProductTaxCode>
<DescriptionData>
<Title>Example Product Title</Title>
<Brand>Example Product Brand</Brand>
<Description>This is an example product description.</Description>
<BulletPoint>Example Bullet Point 1</BulletPoint>
<BulletPoint>Example Bullet Point 2</BulletPoint>
<MSRP currency="JPY">55.55</MSRP>
<Manufacturer>Example Product Manufacturer</Manufacturer>
<SearchTerms>yaodian1</SearchTerms>
<SearchTerms>yaodian2</SearchTerms>
<ItemType>example-item-type</ItemType>
</DescriptionData>
<ProductData>
<Health>
<ProductType>
<HealthMisc>
<Ingredients>Example Ingredients</Ingredients>
<Directions>Example Directions</Directions>
</HealthMisc>
</ProductType>
</Health>
</ProductData>
</Product>
</Message>
</AmazonEnvelope>
17 changes: 17 additions & 0 deletions examples/javaScript/feeds/image.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amznenvelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>SellerID</MerchantIdentifier>
</Header>
<MessageType>ProductImage</MessageType>
<Message>
<MessageID>1</MessageID>
<OperationType>Update</OperationType>
<ProductImage>
<SKU>sku</SKU>
<ImageType>Swatch</ImageType>
<ImageLocation>http://images.pexels.com/photos/104827/cat-pet-animal-domestic-104827.jpeg</ImageLocation>
</ProductImage>
</Message>
</AmazonEnvelope>
17 changes: 17 additions & 0 deletions examples/javaScript/feeds/inventory.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amznenvelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>SellerID</MerchantIdentifier>
</Header>
<MessageType>Inventory</MessageType>
<Message>
<MessageID>1</MessageID>
<OperationType>Update</OperationType>
<Inventory>
<SKU>SKU</SKU>
<Quantity>9527</Quantity>
<FulfillmentLatency>1</FulfillmentLatency>
</Inventory>
</Message>
</AmazonEnvelope>
15 changes: 15 additions & 0 deletions examples/javaScript/feeds/price.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amznenvelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>SellerID</MerchantIdentifier>
</Header>
<MessageType>Price</MessageType>
<Message>
<MessageID>1</MessageID>
<Price>
<SKU>SKU</SKU>
<StandardPrice currency="DEFAULT">99.99</StandardPrice>
</Price>
</Message>
</AmazonEnvelope>
19 changes: 19 additions & 0 deletions examples/javaScript/feeds/relation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amznenvelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>SellerID</MerchantIdentifier>
</Header>
<MessageType>Relationship</MessageType>
<Message>
<MessageID>1</MessageID>
<OperationType>Update</OperationType>
<Relationship>
<ParentSKU>paret-sku</ParentSKU>
<Relation>
<SKU>child-sku</SKU>
<Type>Variation</Type>
</Relation>
</Relationship>
</Message>
</AmazonEnvelope>
4 changes: 2 additions & 2 deletions examples/javaScript/feeds/submitFeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var amazonMws = require('../../../lib/amazon-mws')(accessKey, accessSecret);
var fse = require('fs-extra');

var feedRequest = function () {
var FeedContent = fse.readFileSync('./file.txt', 'UTF-8');
var FeedContent = fse.readFileSync('./good.xml', 'UTF-8');
console.log('FeedContent ', FeedContent);

amazonMws.feeds.submit({
Expand All @@ -26,4 +26,4 @@ var feedRequest = function () {
});
};

feedRequest();
feedRequest();
50 changes: 50 additions & 0 deletions examples/javaScript/feeds/variation-good.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>SellerID</MerchantIdentifier>
</Header>
<MessageType>Product</MessageType>
<PurgeAndReplace>false</PurgeAndReplace>
<Message>
<MessageID>1</MessageID>
<OperationType>Update</OperationType>
<Product>
<SKU>SKU</SKU>
<StandardProductID>
<Type>EAN</Type>
<Value>XXX</Value>
</StandardProductID>
<ProductTaxCode>A_GEN_NOTAX</ProductTaxCode>
<DescriptionData>
<Title>Example Parent</Title>
<Brand>Example Product Brand</Brand>
<Description>This is an example product description.</Description>
<BulletPoint>Example Bullet Point 1</BulletPoint>
<BulletPoint>Example Bullet Point 2</BulletPoint>
<MSRP currency="JPY">55.55</MSRP>
<Manufacturer>Example Product Manufacturer</Manufacturer>
<SearchTerms>yaodian1</SearchTerms>
<SearchTerms>yaodian2</SearchTerms>
<ItemType>example-item-type</ItemType>
<RecommendedBrowseNode>4284945031</RecommendedBrowseNode>
</DescriptionData>
<ProductData>
<Home>
<ProductType>
<OutdoorLiving></OutdoorLiving>
</ProductType>
<Parentage>variation-parent</Parentage>
<VariationData>
<VariationTheme>Size-Color</VariationTheme>
<Size>XXL</Size>
<Color>RED</Color>
</VariationData>
<Material>cotton</Material>
<ThreadCount>500</ThreadCount>
</Home>
</ProductData>
</Product>
</Message>
</AmazonEnvelope>
75 changes: 75 additions & 0 deletions examples/javaScript/sample/getReportAsReadableStram.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
'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 csv = require('fast-csv');
var iconv = require('iconv-lite');

var reportRequest = function () {
/**
* This will not provide you Throttling details in Header.
* Amazon MWS itself not providing Throttling detail in GetReport call.
*/
amazonMws.setHost('YOUR HOST');
amazonMws.reports.search({
'Version': '2009-01-01',
'Action': 'GetReport',
'SellerId': 'SELLER_ID',
'MWSAuthToken': 'MWS_AUTH_TOKEN',
'ReportId': 'REPORT_ID',
'__STREAM__': true
}, function (error, response) {
if (error) {
console.log('error ', error);
return;
}

var rows = [];
function processRowsInBatches(row, end, callback) {
if (typeof end === 'undefined') {
end = false;
}
if (row) {
rows.push(row);
}
if (rows.length >= 5000 || (end && rows.length)) {
sendToDB(rows.splice(0, 0), callback);
rows = [];
}
}

function sendToDB(data, callback) {
// Send your data to the db
console.log(data.length);
callback();
}

var decodeStream = iconv.decodeStream('ISO-8859-1');
response.pipe(decodeStream);
var csvStream = csv.parse({
delimiter: '\t',
headers: true,
discardUnmappedColumns: true,
ignoreEmpty: true,
trim: true
});
decodeStream.pipe(csvStream);
csvStream.transform(function (data, cb) {
processRowsInBatches(data, false, cb);
});
csvStream
.on('error', function (error) { console.error(error); })
.on('finish', function () {
console.log('Finished proccessing stream');
// Call processRowsInBatches to proccess remaining rows
processRowsInBatches(undefined, true, function () {
console.log('Saved last rows in the db');
});
});
});
};

reportRequest();
7 changes: 6 additions & 1 deletion lib/AmazonMwsMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ function amazonMwsMethod(spec) {

function requestCallback(err, response) {
if (err) {
reject(err);
//Sometimes errors coming back are not true errors, just objects.
if(!(err instanceof Error)){
reject(new Error(err));
}else{
reject(err);
}
} else {
resolve(
spec.transformResponseData ?
Expand Down
Loading

0 comments on commit e58d2e3

Please sign in to comment.