diff --git a/lib/feeds.js b/lib/feeds.js index e076028..8aad801 100644 --- a/lib/feeds.js +++ b/lib/feeds.js @@ -1,14 +1,14 @@ /** * Feeds API requests and definitions for Amazon's MWS web services. * For information on using, please see examples folder. - * + * * @author Robert Saunders */ var mws = require('./mws'); - + /** * Construct a Feeds API request for mws.Client.invoke() - * + * * @param {String} action Action parameter of request * @param {Object} params Schemas for all supported parameters */ @@ -35,17 +35,17 @@ function FeedsRequest(action, params, isUpload) { */ var enums = exports.enums = { - FeedProcessingStatuses: function() { - return new mws.Enum(['_SUBMITTED_', '_IN_PROGRESS_', '_CANCELLED_', '_DONE_']); + FeedProcessingStatuses: function() { + return new mws.Enum(['_SUBMITTED_', '_IN_PROGRESS_', '_CANCELLED_', '_DONE_']); }, FeedTypes: function() { return new mws.Enum([ - '_POST_PRODUCT_DATA_', '_POST_PRODUCT_RELATIONSHIP_DATA_', '_POST_ITEM_DATA_', '_POST_PRODUCT_OVERRIDES_DATA_', '_POST_PRODUCT_IMAGE_DATA_', - '_POST_PRODUCT_PRICING_DATA_', '_POST_INVENTORY_AVAILABILITY_DATA_', '_POST_ORDER_ACKNOWLEDGEMENT_DATA_', '_POST_ORDER_FULFILLMENT_DATA_', - '_POST_FULFILLMENT_ORDER_REQUEST_DATA_', '_POST_FULFILLMENT_ORDER_CANCELLATION', '_POST_PAYMENT_ADJUSTMENT_DATA_', '_POST_INVOICE_CONFIRMATION_DATA_', - '_POST_FLAT_FILE_LISTINGS_DATA_', '_POST_FLAT_FILE_ORDER_ACKNOWLEDGEMENT_DATA_', '_POST_FLAT_FILE_FULFILLMENT_DATA_', - '_POST_FLAT_FILE_FBA_CREATE_INBOUND_SHIPMENT_', '_POST_FLAT_FILE_FBA_UPDATE_INBOUND_SHIPMENT_', '_POST_FLAT_FILE_PAYMENT_ADJUSTMENT_DATA_', + '_POST_PRODUCT_DATA_', '_POST_PRODUCT_RELATIONSHIP_DATA_', '_POST_ITEM_DATA_', '_POST_PRODUCT_OVERRIDES_DATA_', '_POST_PRODUCT_IMAGE_DATA_', + '_POST_PRODUCT_PRICING_DATA_', '_POST_INVENTORY_AVAILABILITY_DATA_', '_POST_ORDER_ACKNOWLEDGEMENT_DATA_', '_POST_ORDER_FULFILLMENT_DATA_', + '_POST_FULFILLMENT_ORDER_REQUEST_DATA_', '_POST_FULFILLMENT_ORDER_CANCELLATION', '_POST_PAYMENT_ADJUSTMENT_DATA_', '_POST_INVOICE_CONFIRMATION_DATA_', + '_POST_FLAT_FILE_LISTINGS_DATA_', '_POST_FLAT_FILE_ORDER_ACKNOWLEDGEMENT_DATA_', '_POST_FLAT_FILE_FULFILLMENT_DATA_', + '_POST_FLAT_FILE_FBA_CREATE_INBOUND_SHIPMENT_', '_POST_FLAT_FILE_FBA_UPDATE_INBOUND_SHIPMENT_', '_POST_FLAT_FILE_PAYMENT_ADJUSTMENT_DATA_', '_POST_FLAT_FILE_INVOICE_CONFIRMATION_DATA_', '_POST_FLAT_FILE_INVLOADER_DATA_', '_POST_FLAT_FILE_CONVERGENCE_LISTINGS_DATA_', '_POST_FLAT_FILE_BOOKLOADER_DATA_', '_POST_FLAT_FILE_LISTINGS_DATA_', '_POST_FLAT_FILE_PRICEANDQUANTITYONLY', '_POST_UIEE_BOOKLOADER_DATA_' ]); @@ -54,7 +54,7 @@ var enums = exports.enums = { }; /** - * A collection of currently supported request constructors. Once created and + * A collection of currently supported request constructors. Once created and * configured, the returned requests can be passed to an mws client `invoke` call * @type {Object} */ @@ -102,7 +102,7 @@ var calls = exports.requests = { }, SubmitFeed: function() { - return new FeedsRequest('SubmitFeed', + return new FeedsRequest('SubmitFeed', // schema: { FeedContents: { name: '_BODY_', required: true }, diff --git a/lib/mws.js b/lib/mws.js old mode 100644 new mode 100755 index 053a1ae..e49227d --- a/lib/mws.js +++ b/lib/mws.js @@ -1,423 +1,535 @@ -var https = require('https'), - qs = require("querystring"), - crypto = require('crypto'), - xml2js = require('xml2js'); - - -var MARKETPLACE_IDS = { - -}; - -/** - * Constructor for the main MWS client interface used to make api calls and - * various data structures to encapsulate MWS requests, definitions, etc. - * - * @param {String} accessKeyId Id for your secret Access Key (required) - * @param {String} secretAccessKey Secret Access Key provided by Amazon (required) - * @param {String} merchantId Aka SellerId, provided by Amazon (required) - * @param {Object} options Additional configuration options for this instance - */ -function AmazonMwsClient(accessKeyId, secretAccessKey, merchantId, options) { - this.host = options.host || 'mws.amazonservices.com'; - this.port = options.port || 443; - this.conn = options.conn || https; - this.creds = crypto.createCredentials(options.creds || {}); - this.appName = options.appName || 'mws-js'; - this.appVersion = options.appVersion || '0.1.0'; - this.appLanguage = options.appLanguage || 'JavaScript'; - this.accessKeyId = accessKeyId || null; - this.secretAccessKey = secretAccessKey || null; - this.merchantId = merchantId || null; -} - -/** - * The method used to invoke calls against MWS Endpoints. Recommended usage is - * through the invoke wrapper method when the api call you're invoking has a - * request defined in one of the submodules. However, you can use call() manually - * when a lower level of control is necessary (custom or new requests, for example). - * - * @param {Object} api Settings object unique to each API submodule - * @param {String} action Api `Action`, such as GetServiceStatus or GetOrder - * @param {Object} query Any parameters belonging to the current action - * @param {Function} callback Callback function to send any results recieved - */ -AmazonMwsClient.prototype.call = function(api, action, query, callback) { - if (this.secretAccessKey == null || this.accessKeyId == null || this.merchantId == null) { - throw("accessKeyId, secretAccessKey, and merchantId must be set"); - } - - if(process.env.NODE_ENV === 'development') { - console.log("=================== API ==================="); - console.log(JSON.stringify(api)); - console.log("================ QUERY =============="); - console.log(JSON.stringify(query)); - console.log("=============================="); - } - - // Check if we're dealing with a file (such as a feed) upload - if (api.upload) { - var body = query._BODY_, - bformat = query._FORMAT_; - delete query._BODY_; - delete query._FORMAT_; - } - - // Add required parameters and sign the query - query['Action'] = action; - query['Version'] = api.version; - query["Timestamp"] = (new Date()).toISOString(); - query["AWSAccessKeyId"] = this.accessKeyId; - if (api.legacy) { - query['Merchant'] = this.merchantId; - } else { - query['SellerId'] = this.merchantId; - } - query = this.sign(api.path, query); - - if (!api.upload) { - var body = qs.stringify(query); - } - - // Setup our HTTP headers and connection options - var headers = { - 'Host': this.host, - 'User-Agent': this.appName + '/' + this.appVersion + ' (Language=' + this.appLanguage + ')', - 'Content-Type': bformat || 'application/x-www-form-urlencoded; charset=utf-8', - 'Content-Length': body.length - }; - if (api.upload) { - headers['Content-MD5'] = crypto.createHash('md5').update(body).digest("base64"); - } - - var pathReq = api.path + (api.upload ? '?' + qs.stringify(query) : ''); - - console.log("************ ACTUAL PATH: ***************"); - console.log(pathReq); - - var options = { - host: this.host, - port: this.port, - path: pathReq, - method: "POST", - headers: headers - }; - - // Make the initial request and define callbacks - var req = this.conn.request(options, function (res) { - var data = ''; - // Append each incoming chunk to data variable - res.addListener('data', function (chunk) { - data += chunk.toString(); - }); - // When response is complete, parse the XML and pass it to callback - res.addListener('end', function() { - var parser = new xml2js.Parser(); - parser.addListener('end', function (result) { - // Throw an error if there was a problem reported - if (result.Error != null) { - if(process.env.NODE_ENV === 'development') { - console.log("--------------------------------"); - console.log("ERROR:"); - console.log(JSON.stringify(result.Error)); - } - throw("ERROR"); - } - callback(result); - }); - if (data.slice(0, 5) == '= 0; i--) { - setValue(p.name + '.' + (i+1), value[i]); - } - } else { - for (var key in value) { - setValue(p.name + '.' + (++i), value[key]); - } - } - } - } else { - setValue(p.name, value) - } - - return this; -}; - -/** - * Builds a query object and checks for required parameters. - * - * @return {Object} KvP's of all provided parameters (used by invoke()) - */ -AmazonMwsRequest.prototype.query = function() { - var q = {}; - if(process.env.NODE_ENV === 'development') { - console.log("AMR.proto.query !!!!!!!!!!!!!!!!!!!!!!!"); - console.log(JSON.stringify(this)); - console.log(JSON.stringify(this.params)); - } - for (var param in this.params) { - var value = this.params[param].value, - name = this.params[param].name, - complex = (this.params[param].type === 'Complex'), - required = this.params[param].required; - console.log("v " + value + "\nn " + name + "\nr " + required); - if ((value !== undefined) && (value !== null)) { - if (complex) { - value.appendTo(q); - } else { - q[name] = value; - } - } else { - if (param.required === true) { - throw("ERROR: Missing required parameter, " + name + "!") - } - } - }; - if(process.env.NODE_ENV === 'development') { - console.log("query() about to return this:"); - console.log(q); - console.log("----------------------------------"); - } - return q; -}; - - -/** - * Contructor for objects used to represent enumeration states. Useful - * when you need to make programmatic updates to an enumerated data type or - * wish to encapsulate enum states in a handy, re-usable variable. - * - * @param {Array} choices An array of any possible values (choices) - */ -function EnumType(choices) { - for (var choice in choices) { - this[choices[choice]] = false; - } - this._choices = choices; -} - -/** - * Enable one or more choices (accepts a variable number of arguments) - * @return {Object} Current instance of EnumType for chaining - */ -EnumType.prototype.enable = function() { - for (var arg in arguments) { - this[arguments[arg]] = true; - } - return this; -}; - -/** - * Disable one or more choices (accepts a variable number of arguments) - * @return {Object} Current instance of EnumType for chaining - */ -EnumType.prototype.disable = function() { - for (var arg in arguments) { - this[arguments[arg]] = false; - } - return this; -}; - -/** - * Toggles one or more choices (accepts a variable number of arguments) - * @return {Object} Current instance of EnumType for chaining - */ -EnumType.prototype.toggle = function() { - for (var arg in arguments) { - this[arguments[arg]] = ! this[arguments[arg]]; - } - return this; -}; - -/** - * Return all possible values without regard to current state - * @return {Array} Choices passed to EnumType constructor - */ -EnumType.prototype.all = function() { - return this._choices; -}; - -/** - * Return all enabled choices as an array (used to set list params, usually) - * @return {Array} Choice values for each choice set to true - */ -EnumType.prototype.values = function() { - var value = []; - for (var choice in this._choices) { - if (this[this._choices[choice]] === true) { - value.push(this._choices[choice]); - } - } - return value; -}; - - -// /** -// * Takes an object and adds an appendTo function that will add -// * each kvp of object to a query. Used when dealing with complex -// * parameters that need to be built in an abnormal or unique way. -// * -// * @param {String} name Name of parameter, prefixed to each key -// * @param {Object} obj Parameters belonging to the complex type -// */ -// function ComplexType(name) { -// this.pre = name; -// var _obj = obj; -// obj.appendTo = function(query) { -// for (var k in _obj) { -// query[name + '.' k] = _obj[k]; -// } -// return query; -// } -// return obj; -// } - -// ComplexType.prototype.appendTo = function(query) { -// for (var k in value) -// } - -/** - * Complex List helper object. Once initialized, you should set - * an add(args) method which pushes a new complex object to members. - * - * @param {String} name Name of Complex Type (including .member or subtype) - */ -function ComplexListType(name) { - this.pre = name; - this.members = []; -} - -/** - * Appends each member object as a complex list item - * @param {Object} query Query object to append to - * @return {Object} query - */ -ComplexListType.prototype.appendTo = function(query) { - var members = this.members; - for (var i = 0; i < members.length; i++) { - for (var j in members[i]) { - query[this.pre + '.' + (i+1) + '.' + j] = members[i][j] - } - } - return query; -}; - -exports.Client = AmazonMwsClient; -exports.Request = AmazonMwsRequest; -exports.Enum = EnumType; -exports.ComplexList = ComplexListType; -exports.Orders = require('./orders'); -exports.Sellers = require('./sellers'); -exports.Feeds = require('./feeds'); -exports.Products = require('./products'); -exports.Reports = require('./reports'); - +var https = require('https'), + qs = require("querystring"), + crypto = require('crypto'), + tls = require('tls'); + xml2js = require('xml2js'); +var iconv = require('iconv-lite'); + + +var MARKETPLACE_IDS = { + +}; + +/** + * Constructor for the main MWS client interface used to make api calls and + * various data structures to encapsulate MWS requests, definitions, etc. + * + * @param {String} accessKeyId Id for your secret Access Key (required) + * @param {String} secretAccessKey Secret Access Key provided by Amazon (required) + * @param {String} merchantId Aka SellerId, provided by Amazon (required) + * @param {Object} options Additional configuration options for this instance + */ + function AmazonMwsClient(accessKeyId, secretAccessKey, merchantId, authToken, options) { + this.host = options.host || 'mws.amazonservices.com'; + this.port = options.port || 443; + this.conn = options.conn || https; + this.debug = options.debug || false; + if (tls.createSecureContext) { + this.creds = tls.createSecureContext(options.creds || {}); + } else { + this.creds = crypto.createCredentials(options.creds || {}); + } + this.appName = options.appName || 'mws-js'; + this.appVersion = options.appVersion || '0.1.0'; + this.appLanguage = options.appLanguage || 'JavaScript'; + this.accessKeyId = accessKeyId || null; + this.authToken = authToken || null; + this.secretAccessKey = secretAccessKey || null; + this.merchantId = merchantId || null; + } + +/** + * The method used to invoke calls against MWS Endpoints. Recommended usage is + * through the invoke wrapper method when the api call you're invoking has a + * request defined in one of the submodules. However, you can use call() manually + * when a lower level of control is necessary (custom or new requests, for example). + * + * @param {Object} api Settings object unique to each API submodule + * @param {String} action Api `Action`, such as GetServiceStatus or GetOrder + * @param {Object} query Any parameters belonging to the current action + * @param {Function} callback Callback function to send any results recieved + */ +AmazonMwsClient.prototype.call = function(api, action, query, callback) { + if (this.secretAccessKey == null || this.accessKeyId == null || this.merchantId == null) { + throw("accessKeyId, secretAccessKey, and merchantId must be set"); + } + + if(this.debug) { + console.log("=================== API ==================="); + console.log(JSON.stringify(api)); + console.log("================ QUERY =============="); + console.log(JSON.stringify(query)); + console.log("=============================="); + } + + var buffers = []; + var buffer; + var self = this; + + // Add required parameters and sign the query + query['Action'] = action; + query['Version'] = api.version; + query["Timestamp"] = (new Date()).toISOString(); + query["AWSAccessKeyId"] = self.accessKeyId; + query['MWSAuthToken'] = self.authToken; + if (api.legacy) { + query['Merchant'] = self.merchantId; + } else { + query['SellerId'] = self.merchantId; + } + if (api.upload) { + var body = query._BODY_, + bformat = query._FORMAT_; + delete query._BODY_; + delete query._FORMAT_; + } + + // Check if we're dealing with a file (such as a feed) upload + if (api.upload && body !== null && typeof body === 'object' && typeof body.pipe === 'function') { // last three conditions to validate if it's a stream. + body.on('data', function(buffer) { + buffers.push(buffer); + }); + + body.on('end', function(){ + buffer = Buffer.concat(buffers); + + if(self.debug){ + console.log('before query : '); + console.log(query); + } + query = self.sign(api.path, query); + if(self.debug){ + console.log('query : '); + console.log(query); + } + // Setup our HTTP headers and connection options + var headers = { + 'Host': self.host, + 'User-Agent': self.appName + '/' + self.appVersion + ' (Language=' + self.appLanguage + ')', + 'Content-Type': bformat || 'text/tab-separated-values; charset=iso-8859-1', + 'Content-Length': buffer.length + }; + + headers['Content-MD5'] = crypto.createHash('md5').update(buffer).digest("base64"); + + var pathReq = api.path + (api.upload ? '?' + qs.stringify(query) : ''); + + if(self.debug){ + console.log("************ ACTUAL PATH: ***************"); + console.log(pathReq); + } + + var options = { + host: self.host, + port: self.port, + path: pathReq, + method: "POST", + headers: headers + }; + + sendRequest(self, options, buffer, function(err, result) { + callback(err, result); + }); + }); + } else { + if(self.debug){ + console.log('query : '); + console.log(query); + } + query = this.sign(api.path, query); + + if (!api.upload) { + var body = qs.stringify(query); + } + + // Setup our HTTP headers and connection options + var headers = { + 'Host': this.host, + 'User-Agent': this.appName + '/' + this.appVersion + ' (Language=' + this.appLanguage + ')', + 'Content-Type': bformat || 'application/x-www-form-urlencoded; charset=utf-8', + //'Content-Type': 'text/tab-separated-values; charset=iso-8859-1', + 'Content-Length': Buffer.byteLength(body) + }; + + if (api.upload) { + headers['Content-MD5'] = crypto.createHash('md5').update(body).digest('base64'); + } + + var pathReq = api.path + (api.upload ? '?' + qs.stringify(query) : ''); + + if(self.debug){ + console.log("************ ACTUAL PATH: ***************"); + console.log(pathReq); + } + + var options = { + host: this.host, + port: this.port, + path: pathReq, + method: "POST", + headers: headers + }; + if(self.debug){ + console.log(options); + } + sendRequest(this, options, body, function(err, result) { + callback(err, result); + }); + } +}; + +function sendRequest(self, options, body, callback) { + // Make the initial request and define callbacks + var req = self.conn.request(options, function (res) { + var data = ''; + res.setEncoding('binary'); + if(self.debug){ + console.log(res.headers); + } + + // Append each incoming chunk to data variable + res.addListener('data', function (chunk) { + var utf8Chunk = iconv.decode(new Buffer(chunk), 'utf8'); + data += utf8Chunk.toString(); + if(self.debug){ + console.log('data'); + console.log(data); + } + }); + // When response is complete, parse the XML and pass it to callback + res.addListener('end', function() { + var parser = new xml2js.Parser(); + parser.addListener('end', function (result) { + // Throw an error if there was a problem reported + if (result.Error != null) { + if(self.debug) { + console.log("--------------------------------"); + console.log("ERROR:"); + console.log(JSON.stringify(result.Error)); + } + throw("ERROR"); + } + callback(null, result); + }); + if (data.slice(0, 5) == '= 0; i--) { + setValue(p.name + '.' + (i+1), value[i]); + } + } else { + for (var key in value) { + setValue(p.name + '.' + (++i), value[key]); + } + } + } + } else { + setValue(p.name, value) + } + + return this; +}; + +/** + * Builds a query object and checks for required parameters. + * + * @return {Object} KvP's of all provided parameters (used by invoke()) + */ +AmazonMwsRequest.prototype.query = function() { + var q = {}; + if(this.debug) { + console.log("AMR.proto.query !!!!!!!!!!!!!!!!!!!!!!!"); + console.log(JSON.stringify(this)); + console.log(JSON.stringify(this.params)); + } + for (var param in this.params) { + var value = this.params[param].value, + name = this.params[param].name, + complex = (this.params[param].type === 'Complex'), + required = this.params[param].required; + + if(this.debug){ + console.log("v " + value + "\nn " + name + "\nr " + required); + } + if ((value !== undefined) && (value !== null)) { + if (complex) { + value.appendTo(q); + } else if (this.params[param].list){ + for (var key in value) { + q[key] = value[key]; + } + } else { + for (key in value) { + q[key] = value[key]; + } + } + } else { + if (param.required === true) { + throw("ERROR: Missing required parameter, " + name + "!") + } + } + }; + if(this.debug) { + console.log("query() about to return this:"); + console.log(q); + console.log("----------------------------------"); + } + return q; +}; + + +/** + * Contructor for objects used to represent enumeration states. Useful + * when you need to make programmatic updates to an enumerated data type or + * wish to encapsulate enum states in a handy, re-usable variable. + * + * @param {Array} choices An array of any possible values (choices) + */ +function EnumType(choices) { + for (var choice in choices) { + this[choices[choice]] = false; + } + this._choices = choices; +} + +/** + * Enable one or more choices (accepts a variable number of arguments) + * @return {Object} Current instance of EnumType for chaining + */ +EnumType.prototype.enable = function() { + for (var arg in arguments) { + this[arguments[arg]] = true; + } + return this; +}; + +/** + * Disable one or more choices (accepts a variable number of arguments) + * @return {Object} Current instance of EnumType for chaining + */ +EnumType.prototype.disable = function() { + for (var arg in arguments) { + this[arguments[arg]] = false; + } + return this; +}; + +/** + * Toggles one or more choices (accepts a variable number of arguments) + * @return {Object} Current instance of EnumType for chaining + */ +EnumType.prototype.toggle = function() { + for (var arg in arguments) { + this[arguments[arg]] = ! this[arguments[arg]]; + } + return this; +}; + +/** + * Return all possible values without regard to current state + * @return {Array} Choices passed to EnumType constructor + */ +EnumType.prototype.all = function() { + return this._choices; +}; + +/** + * Return all enabled choices as an array (used to set list params, usually) + * @return {Array} Choice values for each choice set to true + */ +EnumType.prototype.values = function() { + var value = []; + for (var choice in this._choices) { + if (this[this._choices[choice]] === true) { + value.push(this._choices[choice]); + } + } + return value; +}; + + +// /** +// * Takes an object and adds an appendTo function that will add +// * each kvp of object to a query. Used when dealing with complex +// * parameters that need to be built in an abnormal or unique way. +// * +// * @param {String} name Name of parameter, prefixed to each key +// * @param {Object} obj Parameters belonging to the complex type +// */ +// function ComplexType(name) { +// this.pre = name; +// var _obj = obj; +// obj.appendTo = function(query) { +// for (var k in _obj) { +// query[name + '.' k] = _obj[k]; +// } +// return query; +// } +// return obj; +// } + +// ComplexType.prototype.appendTo = function(query) { +// for (var k in value) +// } + +/** + * Complex List helper object. Once initialized, you should set + * an add(args) method which pushes a new complex object to members. + * + * @param {String} name Name of Complex Type (including .member or subtype) + */ +function ComplexListType(name) { + this.pre = name; + this.members = []; +} + +/** + * Appends each member object as a complex list item + * @param {Object} query Query object to append to + * @return {Object} query + */ +ComplexListType.prototype.appendTo = function(query) { + var members = this.members; + for (var i = 0; i < members.length; i++) { + for (var j in members[i]) { + query[this.pre + '.' + (i+1) + '.' + j] = members[i][j] + } + } + return query; +}; + +exports.Client = AmazonMwsClient; +exports.Request = AmazonMwsRequest; +exports.Enum = EnumType; +exports.ComplexList = ComplexListType; +exports.Orders = require('./orders'); +exports.Sellers = require('./sellers'); +exports.Feeds = require('./feeds'); +exports.Products = require('./products'); +exports.Reports = require('./reports'); diff --git a/lib/orders.js b/lib/orders.js index 1f1f7d1..2c75aa8 100644 --- a/lib/orders.js +++ b/lib/orders.js @@ -1,14 +1,14 @@ /** * Orders API requests and definitions for Amazon's MWS web services. * For information on using, please see examples folder. - * + * * @author Robert Saunders */ var mws = require('./mws'); /** * Construct an Orders API request for mws.Client.invoke() - * + * * @param {String} action Action parameter of request * @param {Object} params Schemas for all supported parameters */ @@ -16,8 +16,8 @@ function OrdersRequest(action, params) { var opts = { name: 'Orders', group: 'Order Retrieval', - path: '/Orders/2011-01-01', - version: '2011-01-01', + path: '/Orders/2013-09-01', + version: '2013-09-01', legacy: false, action: action, params: params @@ -31,15 +31,15 @@ function OrdersRequest(action, params) { */ var enums = exports.enums = { - FulfillmentChannels: function() { - return new mws.Enum(['AFN', 'MFN']); + FulfillmentChannels: function() { + return new mws.Enum(['AFN', 'MFN']); }, - OrderStatuses: function() { + OrderStatuses: function() { return new mws.Enum(['Pending', 'Unshipped', 'PartiallyShipped', 'Shipped', 'Canceled', 'Unfulfillable']); }, - PaymentMethods: function() { + PaymentMethods: function() { return new mws.Enum(['COD', 'CVS', 'Other']); } @@ -53,14 +53,14 @@ var enums = exports.enums = { var types = exports.types = { FulfillmentChannel: { - 'AFN':'Amazon Fulfillment Network', + 'AFN':'Amazon Fulfillment Network', 'MFN':'Merchant\'s Fulfillment Network' }, OrderStatus: { - 'Pending':'Order placed but payment not yet authorized. Not ready for shipment.', - 'Unshipped':'Payment has been authorized. Order ready for shipment, but no items shipped yet. Implies PartiallyShipped.', + 'Pending':'Order placed but payment not yet authorized. Not ready for shipment.', + 'Unshipped':'Payment has been authorized. Order ready for shipment, but no items shipped yet. Implies PartiallyShipped.', 'PartiallyShipped':'One or more (but not all) items have been shipped. Implies Unshipped.', - 'Shipped':'All items in the order have been shipped.', + 'Shipped':'All items in the order have been shipped.', 'Canceled':'The order was canceled.', 'Unfulfillable':'The order cannot be fulfilled. Applies only to Amazon-fulfilled orders not placed on Amazon.' }, @@ -84,7 +84,7 @@ var types = exports.types = { }; /** - * A collection of currently supported request constructors. Once created and + * A collection of currently supported request constructors. Once created and * configured, the returned requests can be passed to an mws client `invoke` call * @type {Object} */ @@ -101,7 +101,7 @@ var calls = exports.requests = { * Returns orders created or updated during a time frame you specify. */ ListOrders: function() { - return new OrdersRequest('ListOrders', { + return new OrdersRequest('ListOrders', { CreatedAfter: { name: 'CreatedAfter', type: 'Timestamp' }, CreatedBefore: { name: 'CreatedBefore', type: 'Timestamp' }, LastUpdatedAfter: { name: 'LastUpdatedAfter', type: 'Timestamp' }, @@ -120,8 +120,8 @@ var calls = exports.requests = { * Returns the next page of orders using the NextToken parameter. */ ListOrdersByNextToken: function() { - return new OrdersRequest('ListOrdersByNextToken', { - NextToken: { name: 'NextToken', required: true } + return new OrdersRequest('ListOrdersByNextToken', { + NextToken: { name: 'NextToken', required: true } }); }, @@ -129,8 +129,8 @@ var calls = exports.requests = { * Returns orders based on the AmazonOrderId values that you specify. */ GetOrder: function() { - return new OrdersRequest('GetOrder', { - AmazonOrderId: { name: 'AmazonOrderId.Id', required: true, list: true } + return new OrdersRequest('GetOrder', { + AmazonOrderId: { name: 'AmazonOrderId.Id', required: true, list: true } }); }, @@ -138,7 +138,7 @@ var calls = exports.requests = { * Returns order items based on the AmazonOrderId that you specify. */ ListOrderItems: function() { - return new OrdersRequest('ListOrderItems', { + return new OrdersRequest('ListOrderItems', { AmazonOrderId: { name: 'AmazonOrderId', required: true } }); }, @@ -146,9 +146,9 @@ var calls = exports.requests = { * Returns the next page of order items using the NextToken parameter. */ ListOrderItemsByNextToken: function() { - return new OrdersRequest('ListOrderItemsByNextToken', { - NextToken: { name: 'NextToken', required: true } + return new OrdersRequest('ListOrderItemsByNextToken', { + NextToken: { name: 'NextToken', required: true } }); } -}; \ No newline at end of file +}; diff --git a/package.json b/package.json index 9b5351a..c7bef21 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "mws-sdk", + "name": "mws-sdk2", "description": "Amazon Marketplace Web Services client with support for all api calls.", "keywords": [ "mws", @@ -9,7 +9,7 @@ "sellers" ], "homepage": "_", - "version": "0.9.7", + "version": "0.9.13", "author": "Eibbor Srenduas (http://eibbors.net)", "contributors": [ "Adrian Sanchezdelc ", @@ -21,9 +21,10 @@ }, "repository": { "type": "git", - "url": "https://github.com/ticadia/mws-sdk.git" + "url": "https://github.com/neshte/mws-sdk.git" }, "dependencies": { + "iconv-lite": "^0.4.15", "xml2js": "^0.4.9" }, "devDependencies": {