Skip to content

Commit dc6637d

Browse files
author
Bhushankumar L
authored
Merge pull request #25 from bhushankumarl/development
Development
2 parents 377562e + 80819e2 commit dc6637d

File tree

6 files changed

+110
-46
lines changed

6 files changed

+110
-46
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
0.0.17
2+
- Extend support for TypeScript typed definition : feeds, finances, fulfillmentInboundShipment, fulfillmentInventory, fulfillmentOutboundShipment, merchantFulfillment, orders, products, sellers
3+
14
0.0.16
25
- Added example of MerchantFulfillment
36
- Added support for the comma delimiter report

examples/typeScript/reports/getReport.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@ amazonMws.setApiKey(accessKey, accessSecret);
88

99
const reportRequest = async () => {
1010

11-
let response = await amazonMws.reports.search({
12-
'Version': '2009-01-01',
13-
'Action': 'GetReport',
14-
'SellerId': 'SELLER_ID',
15-
'MWSAuthToken': 'MWS_AUTH_TOKEN',
16-
'ReportId': 'REPORT_ID'
17-
}).catch(error => {
18-
if (error) {
19-
console.log('error ', error);
20-
return;
21-
}
22-
});
23-
console.log('response', response);
11+
try {
12+
const response: any = await amazonMws.reports.search({
13+
'Version': '2009-01-01',
14+
'Action': 'GetReport',
15+
'SellerId': 'SELLER_ID',
16+
'MWSAuthToken': 'MWS_AUTH_TOKEN',
17+
'ReportId': 'REPORT_ID'
18+
});
19+
console.log('response', response);
20+
} catch (error: any) {
21+
console.log('error ', error);
22+
}
23+
24+
2425
};
2526

2627
reportRequest();

examples/typeScript/reports/getReportList.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ amazonMws.setApiKey(accessKey, accessSecret);
88

99
const reportRequest = async () => {
1010

11-
let response = await amazonMws.reports.search({
12-
'Version': '2009-01-01',
13-
'Action': 'GetReportList',
14-
'SellerId': 'SELLER_ID',
15-
'MWSAuthToken': 'MWS_AUTH_TOKEN',
16-
//'ReportTypeList.Type.1': 'REPORT_TYPE_LIST' //optional
17-
}).catch(error => {
18-
if (error) {
19-
console.log('error', error);
20-
}
21-
});
22-
console.log('response', response);
11+
try {
12+
const response: any = await amazonMws.reports.search({
13+
'Version': '2009-01-01',
14+
'Action': 'GetReportList',
15+
'SellerId': 'SELLER_ID',
16+
'MWSAuthToken': 'MWS_AUTH_TOKEN',
17+
//'ReportTypeList.Type.1': 'REPORT_TYPE_LIST' //optional
18+
});
19+
console.log('response', response);
20+
} catch (error: any) {
21+
console.log('error ', error);
22+
}
23+
2324
};
2425

2526
reportRequest();

index.d.ts

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,56 @@
11
// Type definitions for amazon-mws
22

3-
declare class AmazonMWSReports {
3+
declare class BaseAmazonMWS {
44

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

77
}
88

9+
declare class Feeds extends BaseAmazonMWS {
10+
11+
submit(params: any): Promise<any>;
12+
13+
}
14+
15+
declare class Finances extends BaseAmazonMWS {
16+
17+
}
18+
19+
declare class FulfillmentInboundShipment extends BaseAmazonMWS {
20+
21+
create(params: any): Promise<any>;
22+
23+
}
24+
25+
declare class FulfillmentInventory extends BaseAmazonMWS {
26+
27+
}
28+
29+
declare class FulfillmentOutboundShipment extends BaseAmazonMWS {
30+
31+
}
32+
33+
declare class MerchantFulfillment extends BaseAmazonMWS {
34+
35+
create(params: any): Promise<any>;
36+
37+
}
38+
39+
declare class Orders extends BaseAmazonMWS {
40+
41+
}
42+
43+
declare class Products extends BaseAmazonMWS {
44+
45+
}
46+
47+
declare class Reports extends BaseAmazonMWS {
48+
49+
}
50+
51+
declare class Sellers extends BaseAmazonMWS {
52+
53+
}
954

1055
declare class AmazonMWS {
1156

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

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

18-
reports: AmazonMWSReports;
63+
setHost(host?: string, port?: string, protocol?: string): void;
64+
65+
feeds: Feeds;
66+
67+
finances: Finances;
68+
69+
fulfillmentInboundShipment: FulfillmentInboundShipment;
70+
71+
fulfillmentInventory: FulfillmentInventory;
72+
73+
fulfillmentOutboundShipment: FulfillmentOutboundShipment;
74+
75+
merchantFulfillment: MerchantFulfillment;
76+
77+
orders: Orders;
78+
79+
products: Products;
80+
81+
reports: Reports;
82+
83+
sellers: Sellers;
1984

2085
}
2186

lib/AmazonMwsResource.js

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ AmazonMwsResource.prototype = {
158158
data.push(value);
159159
})
160160
.on('end', function () {
161-
debug('response after parsing tab delimited file %o ', data);
161+
debug('response after parsing file %o ', data);
162162
var items = {};
163163
items.data = data;
164164
items.Headers = {
@@ -170,45 +170,39 @@ AmazonMwsResource.prototype = {
170170
return callback(null, items);
171171
})
172172
.on('error', function (error) {
173+
debug('error ', error);
173174
return callback(error);
174175
});
175176
}
176177

177178
function processResponseType(res, responseString, callback) {
178-
//debug('response %o ', response);
179+
//debug('res %o ', res);
179180
//debug('res.headers %o ', res.headers);
180181
if (RESPONSE_CONTENT_TYPE.indexOf(res.headers['content-type'].toLowerCase()) > -1) {
181182
debug('It is XML Response');
182183
var items = xml2json.toJson(responseString);
183-
//debug('response after parsing JSON %o ', response);
184+
//debug('res after parsing JSON %o ', res);
184185
items = JSON.parse(items);
185186
items.Headers = {
186187
'x-mws-quota-max': res.headers['x-mws-quota-max'] || 'unknown',
187188
'x-mws-quota-remaining': res.headers['x-mws-quota-remaining'] || 'unknown',
188189
'x-mws-quota-resetson': res.headers['x-mws-quota-resetson'] || 'unknown',
189190
'x-mws-timestamp': res.headers['x-mws-timestamp']
190191
};
191-
//debug('after adding header response', response);
192+
//debug('after adding header res', res);
192193
return callback(null, items);
193194
} else {
194195
debug('It is NON-XML Response');
195196
var TAB_DELIMITER = '\t';
196197
var COMMA_DELIMITER = ',';
197-
try {
198-
parseCSVFile(res, responseString, TAB_DELIMITER, callback);
199-
} catch (Exception) {
200-
debug('It is TAB_DELIMITER Exception ', Exception);
201-
debug('Let us try to delimit using COMMA_DELIMITER');
202-
try {
203-
parseCSVFile(res, responseString, COMMA_DELIMITER, callback);
204-
} catch (Exception) {
205-
debug('It is COMMA_DELIMITER Exception ', Exception);
206-
debug('Parsing using both TAB_DELIMITER & COMMA_DELIMITER Failed.');
207-
debug('It may due to empty response or invalid request.');
208-
return callback(new Error('Parsing fail.'));
198+
parseCSVFile(res, responseString, TAB_DELIMITER, function (error, response) {
199+
if (!_.isEmpty(error)) {
200+
debug('It is TAB_DELIMITER failure.');
201+
debug('Let us try to delimit using COMMA_DELIMITER');
202+
return parseCSVFile(res, responseString, COMMA_DELIMITER, callback);
209203
}
210-
}
211-
204+
return callback(null, response);
205+
});
212206
}
213207
}
214208

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "amazon-mws",
3-
"version": "0.0.16",
3+
"version": "0.0.17",
44
"description": "Amazon MWS API wrapper",
55
"keywords": [
66
"Amazon MWS",

0 commit comments

Comments
 (0)