From 09759dc4379a392d1ea2e4663c4774718e0fc56d Mon Sep 17 00:00:00 2001 From: BL Date: Fri, 25 May 2018 14:10:42 +0530 Subject: [PATCH 1/2] Extend support for TypeScript typed definition : feeds, finances, fulfillmentInboundShipment, fulfillmentInventory, fulfillmentOutboundShipment, merchantFulfillment, orders, products, sellers --- CHANGELOG.md | 3 + examples/typeScript/reports/getReport.ts | 27 ++++---- examples/typeScript/reports/getReportList.ts | 25 +++---- index.d.ts | 69 +++++++++++++++++++- package.json | 2 +- 5 files changed, 98 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd390b1..fb61c77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/examples/typeScript/reports/getReport.ts b/examples/typeScript/reports/getReport.ts index a776d9e..b6ace4f 100644 --- a/examples/typeScript/reports/getReport.ts +++ b/examples/typeScript/reports/getReport.ts @@ -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(); \ No newline at end of file diff --git a/examples/typeScript/reports/getReportList.ts b/examples/typeScript/reports/getReportList.ts index 0fbaaa0..de27643 100644 --- a/examples/typeScript/reports/getReportList.ts +++ b/examples/typeScript/reports/getReportList.ts @@ -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(); \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index 674862e..4c6035d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,11 +1,56 @@ // Type definitions for amazon-mws -declare class AmazonMWSReports { +declare class BaseAmazonMWS { search(params: any): Promise; } +declare class Feeds extends BaseAmazonMWS { + + submit(params: any): Promise; + +} + +declare class Finances extends BaseAmazonMWS { + +} + +declare class FulfillmentInboundShipment extends BaseAmazonMWS { + + create(params: any): Promise; + +} + +declare class FulfillmentInventory extends BaseAmazonMWS { + +} + +declare class FulfillmentOutboundShipment extends BaseAmazonMWS { + +} + +declare class MerchantFulfillment extends BaseAmazonMWS { + + create(params: any): Promise; + +} + +declare class Orders extends BaseAmazonMWS { + +} + +declare class Products extends BaseAmazonMWS { + +} + +declare class Reports extends BaseAmazonMWS { + +} + +declare class Sellers extends BaseAmazonMWS { + +} declare class AmazonMWS { @@ -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; } diff --git a/package.json b/package.json index bd36cbc..d714e54 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "amazon-mws", - "version": "0.0.16", + "version": "0.0.17", "description": "Amazon MWS API wrapper", "keywords": [ "Amazon MWS", From 80819e25abad188900be83d38e962d5d35f71967 Mon Sep 17 00:00:00 2001 From: BL Date: Fri, 25 May 2018 14:38:56 +0530 Subject: [PATCH 2/2] correct the callback for COMMA_DELIMITER parsing --- lib/AmazonMwsResource.js | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/lib/AmazonMwsResource.js b/lib/AmazonMwsResource.js index c921b20..fb8bf2e 100644 --- a/lib/AmazonMwsResource.js +++ b/lib/AmazonMwsResource.js @@ -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 = { @@ -170,17 +170,18 @@ 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', @@ -188,27 +189,20 @@ AmazonMwsResource.prototype = { '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); + }); } }