Skip to content

Commit

Permalink
Merge pull request #25 from bhushankumarl/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Bhushankumar L committed May 25, 2018
2 parents 377562e + 80819e2 commit dc6637d
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 46 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
0.0.17
- Extend support for TypeScript typed definition : feeds, finances, fulfillmentInboundShipment, fulfillmentInventory, fulfillmentOutboundShipment, merchantFulfillment, orders, products, sellers

0.0.16
- Added example of MerchantFulfillment
- Added support for the comma delimiter report
Expand Down
27 changes: 14 additions & 13 deletions examples/typeScript/reports/getReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ amazonMws.setApiKey(accessKey, accessSecret);

const reportRequest = async () => {

let response = await amazonMws.reports.search({
'Version': '2009-01-01',
'Action': 'GetReport',
'SellerId': 'SELLER_ID',
'MWSAuthToken': 'MWS_AUTH_TOKEN',
'ReportId': 'REPORT_ID'
}).catch(error => {
if (error) {
console.log('error ', error);
return;
}
});
console.log('response', response);
try {
const response: any = await amazonMws.reports.search({
'Version': '2009-01-01',
'Action': 'GetReport',
'SellerId': 'SELLER_ID',
'MWSAuthToken': 'MWS_AUTH_TOKEN',
'ReportId': 'REPORT_ID'
});
console.log('response', response);
} catch (error: any) {
console.log('error ', error);
}


};

reportRequest();
25 changes: 13 additions & 12 deletions examples/typeScript/reports/getReportList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ amazonMws.setApiKey(accessKey, accessSecret);

const reportRequest = async () => {

let response = await amazonMws.reports.search({
'Version': '2009-01-01',
'Action': 'GetReportList',
'SellerId': 'SELLER_ID',
'MWSAuthToken': 'MWS_AUTH_TOKEN',
//'ReportTypeList.Type.1': 'REPORT_TYPE_LIST' //optional
}).catch(error => {
if (error) {
console.log('error', error);
}
});
console.log('response', response);
try {
const response: any = await amazonMws.reports.search({
'Version': '2009-01-01',
'Action': 'GetReportList',
'SellerId': 'SELLER_ID',
'MWSAuthToken': 'MWS_AUTH_TOKEN',
//'ReportTypeList.Type.1': 'REPORT_TYPE_LIST' //optional
});
console.log('response', response);
} catch (error: any) {
console.log('error ', error);
}

};

reportRequest();
69 changes: 67 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,56 @@
// Type definitions for amazon-mws

declare class AmazonMWSReports {
declare class BaseAmazonMWS {

search(params: any): Promise<any>;

}

declare class Feeds extends BaseAmazonMWS {

submit(params: any): Promise<any>;

}

declare class Finances extends BaseAmazonMWS {

}

declare class FulfillmentInboundShipment extends BaseAmazonMWS {

create(params: any): Promise<any>;

}

declare class FulfillmentInventory extends BaseAmazonMWS {

}

declare class FulfillmentOutboundShipment extends BaseAmazonMWS {

}

declare class MerchantFulfillment extends BaseAmazonMWS {

create(params: any): Promise<any>;

}

declare class Orders extends BaseAmazonMWS {

}

declare class Products extends BaseAmazonMWS {

}

declare class Reports extends BaseAmazonMWS {

}

declare class Sellers extends BaseAmazonMWS {

}

declare class AmazonMWS {

Expand All @@ -15,7 +60,27 @@ declare class AmazonMWS {

setApiKey(key: string, secret: string): void;

reports: AmazonMWSReports;
setHost(host?: string, port?: string, protocol?: string): void;

feeds: Feeds;

finances: Finances;

fulfillmentInboundShipment: FulfillmentInboundShipment;

fulfillmentInventory: FulfillmentInventory;

fulfillmentOutboundShipment: FulfillmentOutboundShipment;

merchantFulfillment: MerchantFulfillment;

orders: Orders;

products: Products;

reports: Reports;

sellers: Sellers;

}

Expand Down
30 changes: 12 additions & 18 deletions lib/AmazonMwsResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ AmazonMwsResource.prototype = {
data.push(value);
})
.on('end', function () {
debug('response after parsing tab delimited file %o ', data);
debug('response after parsing file %o ', data);
var items = {};
items.data = data;
items.Headers = {
Expand All @@ -170,45 +170,39 @@ AmazonMwsResource.prototype = {
return callback(null, items);
})
.on('error', function (error) {
debug('error ', error);
return callback(error);
});
}

function processResponseType(res, responseString, callback) {
//debug('response %o ', response);
//debug('res %o ', res);
//debug('res.headers %o ', res.headers);
if (RESPONSE_CONTENT_TYPE.indexOf(res.headers['content-type'].toLowerCase()) > -1) {
debug('It is XML Response');
var items = xml2json.toJson(responseString);
//debug('response after parsing JSON %o ', response);
//debug('res after parsing JSON %o ', res);
items = JSON.parse(items);
items.Headers = {
'x-mws-quota-max': res.headers['x-mws-quota-max'] || 'unknown',
'x-mws-quota-remaining': res.headers['x-mws-quota-remaining'] || 'unknown',
'x-mws-quota-resetson': res.headers['x-mws-quota-resetson'] || 'unknown',
'x-mws-timestamp': res.headers['x-mws-timestamp']
};
//debug('after adding header response', response);
//debug('after adding header res', res);
return callback(null, items);
} else {
debug('It is NON-XML Response');
var TAB_DELIMITER = '\t';
var COMMA_DELIMITER = ',';
try {
parseCSVFile(res, responseString, TAB_DELIMITER, callback);
} catch (Exception) {
debug('It is TAB_DELIMITER Exception ', Exception);
debug('Let us try to delimit using COMMA_DELIMITER');
try {
parseCSVFile(res, responseString, COMMA_DELIMITER, callback);
} catch (Exception) {
debug('It is COMMA_DELIMITER Exception ', Exception);
debug('Parsing using both TAB_DELIMITER & COMMA_DELIMITER Failed.');
debug('It may due to empty response or invalid request.');
return callback(new Error('Parsing fail.'));
parseCSVFile(res, responseString, TAB_DELIMITER, function (error, response) {
if (!_.isEmpty(error)) {
debug('It is TAB_DELIMITER failure.');
debug('Let us try to delimit using COMMA_DELIMITER');
return parseCSVFile(res, responseString, COMMA_DELIMITER, callback);
}
}

return callback(null, response);
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "amazon-mws",
"version": "0.0.16",
"version": "0.0.17",
"description": "Amazon MWS API wrapper",
"keywords": [
"Amazon MWS",
Expand Down

0 comments on commit dc6637d

Please sign in to comment.