diff --git a/README.md b/README.md index c540833..eb62c02 100644 --- a/README.md +++ b/README.md @@ -49,15 +49,35 @@ Example Response: ```javascript { ItemSearchResponse: { - $: { - xmlns: 'http://webservices.amazon.com/AWSECommerceService/2011-08-01' - }, + OperationRequest: [Object], + Items: [Object] + } +} +``` + +NOTE: In v2.0.0, we changed the default for xml2js to set explicitArray to false. Before v.2.0.0, you would get a +response like this instead (note the extra arrays you have to drill into): + +```javascript +{ + ItemSearchResponse: { OperationRequest: [ [Object] ], Items: [ [Object] ] } } ``` +You can change back to the old behavior by setting explitArray to true like this: + +```javascript +var opHelper = new OperationHelper({ + awsId: '[YOUR AWS ID HERE]', + awsSecret: '[YOUR AWS SECRET HERE]', + assocId: '[YOUR ASSOCIATE TAG HERE]', + xml2jsOptions: { explicitArray: true } +}); +``` + ## API Documentation Because we don't define any specific operations, we also don't document them. What a waste diff --git a/lib/operation-helper.js b/lib/operation-helper.js index fcad156..5523486 100644 --- a/lib/operation-helper.js +++ b/lib/operation-helper.js @@ -7,6 +7,10 @@ const locale = require('./locale') const http = require('http') const xml2js = require('xml2js') +const defaultXml2JsOptions = { + explicitArray: false +} + class OperationHelper { constructor(params) { params = params || {} @@ -28,7 +32,7 @@ class OperationHelper { this.assocId = params.assocId this.endPoint = params.endPoint || locale.getEndpointForLocale(params.locale) this.baseUri = params.baseUri || OperationHelper.defaultBaseUri - this.xml2jsOptions = params.xml2jsOptions || {} + this.xml2jsOptions = Object.assign({}, defaultXml2JsOptions, params.xml2jsOptions) this.throttler = new Throttler(params.maxRequestsPerSecond) // set version diff --git a/lib/operation-helper.specs.js b/lib/operation-helper.specs.js index 9796bab..6b134f6 100644 --- a/lib/operation-helper.specs.js +++ b/lib/operation-helper.specs.js @@ -145,6 +145,7 @@ describe('OperationHelper', function () { let requestMock, responseMock, result, outputResponseBody const responseBody = 'xml' const xml2jsOptions = {foo: 'bar'} + const expectedXml2jsOptions = Object.assign({explicitArray: false}, xml2jsOptions) context('happy path', () => { let opHelper @@ -196,15 +197,15 @@ describe('OperationHelper', function () { }) it('should pass the xml2jsOptions to xml2js', () => { - expect(xml2js.parseString.firstCall.args[1]).to.eql(xml2jsOptions) + expect(xml2js.parseString.firstCall.args[1]).to.eql(expectedXml2jsOptions) }) it('should parse XML and return result as object', () => { expect(result).to.eql({ it: { - is: [{ - some: ['xml'] - }] + is: { + some: 'xml' + } } }) })