diff --git a/CHANGELOG.md b/CHANGELOG.md index b3fb143..34fc940 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## To be released +- Fix refine option processing to include refine_1 ... refine_n alternatives +- Fix rollup format 'cjs' --> 'es' + ## v0.1.0 (November 6, 2017) - Module name change - Add ASCII art diff --git a/docs/ApiClient.js.html b/docs/ApiClient.js.html index b5f0b5c..3ac13b8 100644 --- a/docs/ApiClient.js.html +++ b/docs/ApiClient.js.html @@ -346,6 +346,32 @@

Source: ApiClient.js

} } + /** + * Builds an object with refinement keys 1..n given a options object.. + * @param {Object} opts Optional parameters + * @returns {Object} An object with refinement keys numbered 1 ... n with their + * string representation value. + */ + buildRefineParams(opts) { + const refinements = Object.keys(opts).filter((key) => /^refine/.test(key)) + const queryParams = {} + + if (refinements.length > 0) { + const useSuffix = refinements.length > 1 + + refinements.forEach((key, idx) => { + if (!opts[key]) { + return + } + + queryParams[`refine${useSuffix ? `_${idx + 1}` : ''}`] = + this.buildCollectionParam(opts[key], 'csv') + }) + } + + return queryParams + } + /** * Applies authentication headers to the request. * @param {Object} request The request object created by a <code>superagent()</code> call. diff --git a/docs/api_ContentSearchApi.js.html b/docs/api_ContentSearchApi.js.html index 91e96da..7bdc4f1 100644 --- a/docs/api_ContentSearchApi.js.html +++ b/docs/api_ContentSearchApi.js.html @@ -93,12 +93,14 @@

Source: api/ContentSearchApi.js

const pathParams = {} const queryParams = { q: opts.q, - refine: this.apiClient.buildCollectionParam(opts.refine, 'csv'), sort: this.apiClient.buildCollectionParam(opts.sort, 'csv'), start: opts.start, count: opts.count, locale: opts.locale } + + Object.assign(queryParams, this.apiClient.buildRefineParams(opts)) + const headerParams = {} const formParams = {} diff --git a/docs/api_ProductSearchApi.js.html b/docs/api_ProductSearchApi.js.html index ca0527a..1003843 100644 --- a/docs/api_ProductSearchApi.js.html +++ b/docs/api_ProductSearchApi.js.html @@ -95,7 +95,6 @@

Source: api/ProductSearchApi.js

const pathParams = {} const queryParams = { q: opts.q, - refine: this.apiClient.buildCollectionParam(opts.refine, 'csv'), sort: opts.sort, start: opts.start, count: opts.count, @@ -103,6 +102,9 @@

Source: api/ProductSearchApi.js

currency: opts.currency, locale: opts.locale } + + Object.assign(queryParams, this.apiClient.buildRefineParams(opts)) + const headerParams = {} const formParams = {} @@ -183,12 +185,14 @@

Source: api/ProductSearchApi.js

const pathParams = {} const queryParams = { q: opts.q, - refine: this.apiClient.buildCollectionParam(opts.refine, 'csv'), sort: opts.sort, start: opts.start, count: opts.count, locale: opts.locale } + + Object.assign(queryParams, this.apiClient.buildRefineParams(opts)) + const headerParams = {} const formParams = {} @@ -264,12 +268,14 @@

Source: api/ProductSearchApi.js

const pathParams = {} const queryParams = { q: opts.q, - refine: this.apiClient.buildCollectionParam(opts.refine, 'csv'), sort: opts.sort, start: opts.start, count: opts.count, locale: opts.locale } + + Object.assign(queryParams, this.apiClient.buildRefineParams(opts)) + const headerParams = {} const formParams = {} @@ -346,13 +352,15 @@

Source: api/ProductSearchApi.js

const pathParams = {} const queryParams = { q: opts.q, - refine: this.apiClient.buildCollectionParam(opts.refine, 'csv'), sort: opts.sort, start: opts.start, count: opts.count, currency: opts.currency, locale: opts.locale } + + Object.assign(queryParams, this.apiClient.buildRefineParams(opts)) + const headerParams = {} const formParams = {} @@ -427,12 +435,14 @@

Source: api/ProductSearchApi.js

const pathParams = {} const queryParams = { q: opts.q, - refine: this.apiClient.buildCollectionParam(opts.refine, 'csv'), sort: opts.sort, start: opts.start, count: opts.count, locale: opts.locale } + + Object.assign(queryParams, this.apiClient.buildRefineParams(opts)) + const headerParams = {} const formParams = {} diff --git a/docs/index.html b/docs/index.html index 76a4650..4ad50c1 100644 --- a/docs/index.html +++ b/docs/index.html @@ -52,7 +52,7 @@

/ /

NPM

CircleCI

-

Introduction

ShopApi - JavaScript client for Salesforce Commerce Cloud OCAPI Shop API.

+

Introduction

ShopApi - ES6 JavaScript client for Salesforce Commerce Cloud OCAPI Shop API.

diff --git a/docs/module-ApiClient.html b/docs/module-ApiClient.html index 8bd483b..8f67073 100644 --- a/docs/module-ApiClient.html +++ b/docs/module-ApiClient.html @@ -732,7 +732,7 @@
Parameters:
Source:
@@ -905,7 +905,7 @@
Parameters:
Source:
@@ -1050,7 +1050,7 @@
Parameters:
Source:
@@ -1230,7 +1230,7 @@
Parameters:
Source:
@@ -1448,6 +1448,164 @@
Returns:
+

buildRefineParams(opts) → {Object}

+ + + + + + +
+

Builds an object with refinement keys 1..n given a options object..

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
opts + + +Object + + + +

Optional parameters

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

An object with refinement keys numbered 1 ... n with their +string representation value.

+
+ + + +
+
+ Type +
+
+ +Object + + +
+
+ + + + + + + + + + + + +

buildUrl(path, pathParams) → {String}

@@ -1967,7 +2125,7 @@
Parameters:
Source:
@@ -2159,7 +2317,7 @@
Parameters:
Source:
diff --git a/docs/module-api_ContentSearchApi.html b/docs/module-api_ContentSearchApi.html index 03981f2..dc8bde8 100644 --- a/docs/module-api_ContentSearchApi.html +++ b/docs/module-api_ContentSearchApi.html @@ -473,7 +473,7 @@
Properties
Source:
diff --git a/docs/module-api_ProductSearchApi.html b/docs/module-api_ProductSearchApi.html index bfdd94b..3af3154 100644 --- a/docs/module-api_ProductSearchApi.html +++ b/docs/module-api_ProductSearchApi.html @@ -523,7 +523,7 @@
Properties
Source:
@@ -856,7 +856,7 @@
Properties
Source:
@@ -1189,7 +1189,7 @@
Properties
Source:
@@ -1522,7 +1522,7 @@
Properties
Source:
@@ -1855,7 +1855,7 @@
Properties
Source:
@@ -2210,7 +2210,7 @@
Properties
Source:
@@ -2566,7 +2566,7 @@
Properties
Source:
@@ -2898,7 +2898,7 @@
Properties
Source:
@@ -3230,7 +3230,7 @@
Properties
Source:
diff --git a/rollup.config.js b/rollup.config.js index 886b5ec..b5862ed 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -2,7 +2,7 @@ export default { input: 'src/index.js', output: { file: 'lib/index.js', - format: 'cjs' + format: 'es' }, external: ['superagent', 'querystring'], } diff --git a/src/ApiClient.js b/src/ApiClient.js index b670753..7d95951 100644 --- a/src/ApiClient.js +++ b/src/ApiClient.js @@ -318,6 +318,32 @@ export default class ApiClient { } } + /** + * Builds an object with refinement keys 1..n given a options object.. + * @param {Object} opts Optional parameters + * @returns {Object} An object with refinement keys numbered 1 ... n with their + * string representation value. + */ + buildRefineParams(opts) { + const refinements = Object.keys(opts).filter((key) => /^refine/.test(key)) + const queryParams = {} + + if (refinements.length > 0) { + const useSuffix = refinements.length > 1 + + refinements.forEach((key, idx) => { + if (!opts[key]) { + return + } + + queryParams[`refine${useSuffix ? `_${idx + 1}` : ''}`] = + this.buildCollectionParam(opts[key], 'csv') + }) + } + + return queryParams + } + /** * Applies authentication headers to the request. * @param {Object} request The request object created by a superagent() call. diff --git a/src/api/ContentSearchApi.js b/src/api/ContentSearchApi.js index 83525fc..490196b 100644 --- a/src/api/ContentSearchApi.js +++ b/src/api/ContentSearchApi.js @@ -65,12 +65,14 @@ export default class ContentSearchApi { const pathParams = {} const queryParams = { q: opts.q, - refine: this.apiClient.buildCollectionParam(opts.refine, 'csv'), sort: this.apiClient.buildCollectionParam(opts.sort, 'csv'), start: opts.start, count: opts.count, locale: opts.locale } + + Object.assign(queryParams, this.apiClient.buildRefineParams(opts)) + const headerParams = {} const formParams = {} diff --git a/src/api/ProductSearchApi.js b/src/api/ProductSearchApi.js index 906606e..9da812e 100644 --- a/src/api/ProductSearchApi.js +++ b/src/api/ProductSearchApi.js @@ -67,7 +67,6 @@ export default class ProductSearchApi { const pathParams = {} const queryParams = { q: opts.q, - refine: this.apiClient.buildCollectionParam(opts.refine, 'csv'), sort: opts.sort, start: opts.start, count: opts.count, @@ -75,6 +74,9 @@ export default class ProductSearchApi { currency: opts.currency, locale: opts.locale } + + Object.assign(queryParams, this.apiClient.buildRefineParams(opts)) + const headerParams = {} const formParams = {} @@ -155,12 +157,14 @@ export default class ProductSearchApi { const pathParams = {} const queryParams = { q: opts.q, - refine: this.apiClient.buildCollectionParam(opts.refine, 'csv'), sort: opts.sort, start: opts.start, count: opts.count, locale: opts.locale } + + Object.assign(queryParams, this.apiClient.buildRefineParams(opts)) + const headerParams = {} const formParams = {} @@ -236,12 +240,14 @@ export default class ProductSearchApi { const pathParams = {} const queryParams = { q: opts.q, - refine: this.apiClient.buildCollectionParam(opts.refine, 'csv'), sort: opts.sort, start: opts.start, count: opts.count, locale: opts.locale } + + Object.assign(queryParams, this.apiClient.buildRefineParams(opts)) + const headerParams = {} const formParams = {} @@ -318,13 +324,15 @@ export default class ProductSearchApi { const pathParams = {} const queryParams = { q: opts.q, - refine: this.apiClient.buildCollectionParam(opts.refine, 'csv'), sort: opts.sort, start: opts.start, count: opts.count, currency: opts.currency, locale: opts.locale } + + Object.assign(queryParams, this.apiClient.buildRefineParams(opts)) + const headerParams = {} const formParams = {} @@ -399,12 +407,14 @@ export default class ProductSearchApi { const pathParams = {} const queryParams = { q: opts.q, - refine: this.apiClient.buildCollectionParam(opts.refine, 'csv'), sort: opts.sort, start: opts.start, count: opts.count, locale: opts.locale } + + Object.assign(queryParams, this.apiClient.buildRefineParams(opts)) + const headerParams = {} const formParams = {} diff --git a/test/api/PriceAdjustmentLimitsApi.spec.js b/test/api/PriceAdjustmentLimitsApi.spec.js index c492cc8..216bb67 100644 --- a/test/api/PriceAdjustmentLimitsApi.spec.js +++ b/test/api/PriceAdjustmentLimitsApi.spec.js @@ -59,14 +59,6 @@ describe('PriceAdjustmentLimitsApi', () => { // if (error) throw error; // expect().to.be(); // }); - instance.getPriceAdjustmentLimits() - .then((thing) => { - console.log('thing: ', thing) - }) - .catch((fault) => { - console.log('fault: ', fault) - }) - return Promise.resolve() }) }) }) diff --git a/test/api/ProductSearchApi.spec.js b/test/api/ProductSearchApi.spec.js index 85459d2..5b9012d 100644 --- a/test/api/ProductSearchApi.spec.js +++ b/test/api/ProductSearchApi.spec.js @@ -61,6 +61,17 @@ describe('ProductSearchApi', () => { expect(productSearchResult.count).to.above(0) }) ) + + it('should call getProductSearch with multiple refinments successfully', () => + instance.getProductSearch({ + refine_1: ['cgid=root'], + refine_2: ['c_refinementColor=Navy'] + }) + .then((productSearchResult) => { + expect(productSearchResult.selected_refinements.cgid).to.be('root') + expect(productSearchResult.selected_refinements.c_refinementColor).to.be('Navy') + }) + ) }) describe('getProductSearchAvailability', () => {