@constructor-io/constructorio-client-javascript 2.27.4 → 2.27.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/modules/autocomplete.js +7 -1
- package/lib/modules/browse.js +82 -3
- package/package.json +1 -1
|
@@ -82,7 +82,13 @@ function createAutocompleteUrl(query, parameters, options) {
|
|
|
82
82
|
|
|
83
83
|
|
|
84
84
|
if (hiddenFields) {
|
|
85
|
-
queryParams.
|
|
85
|
+
if (queryParams.fmt_options) {
|
|
86
|
+
queryParams.fmt_options.hidden_fields = hiddenFields;
|
|
87
|
+
} else {
|
|
88
|
+
queryParams.fmt_options = {
|
|
89
|
+
hidden_fields: hiddenFields
|
|
90
|
+
};
|
|
91
|
+
}
|
|
86
92
|
}
|
|
87
93
|
}
|
|
88
94
|
|
package/lib/modules/browse.js
CHANGED
|
@@ -174,13 +174,29 @@ function createBrowseUrlForFacets(parameters, options) {
|
|
|
174
174
|
var queryParams = _objectSpread({}, createQueryParams(parameters, options)); // Endpoint does not accept _dt
|
|
175
175
|
|
|
176
176
|
|
|
177
|
-
delete queryParams._dt;
|
|
178
|
-
|
|
179
|
-
delete queryParams.fmt_options;
|
|
177
|
+
delete queryParams._dt;
|
|
180
178
|
var queryString = qs.stringify(queryParams, {
|
|
181
179
|
indices: false
|
|
182
180
|
});
|
|
183
181
|
return "".concat(serviceUrl, "/browse/facets?").concat(queryString);
|
|
182
|
+
} // Create URL from supplied facet name and parameters
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
function createBrowseUrlForFacetOptions(facetName, parameters, options) {
|
|
186
|
+
var serviceUrl = options.serviceUrl; // Validate facet name is provided
|
|
187
|
+
|
|
188
|
+
if (!facetName || typeof facetName !== 'string') {
|
|
189
|
+
throw new Error('facetName is a required parameter of type string');
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
var queryParams = _objectSpread({}, createQueryParams(parameters, options)); // Endpoint does not accept _dt
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
delete queryParams._dt;
|
|
196
|
+
var queryString = qs.stringify(queryParams, {
|
|
197
|
+
indices: false
|
|
198
|
+
});
|
|
199
|
+
return "".concat(serviceUrl, "/browse/facet_options?facet_name=").concat(facetName, "&").concat(queryString);
|
|
184
200
|
}
|
|
185
201
|
/**
|
|
186
202
|
* Interface to browse related API calls
|
|
@@ -425,6 +441,7 @@ var Browse = /*#__PURE__*/function () {
|
|
|
425
441
|
* @function getBrowseFacets
|
|
426
442
|
* @param {object} [parameters] - Additional parameters to refine result set
|
|
427
443
|
* @param {number} [parameters.page] - The page number of the results
|
|
444
|
+
* @param {boolean} [parameters.fmtOptions.show_hidden_facets] - Include facets configured as hidden
|
|
428
445
|
* @param {number} [parameters.resultsPerPage] - The number of results per page to return
|
|
429
446
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
430
447
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
@@ -479,6 +496,68 @@ var Browse = /*#__PURE__*/function () {
|
|
|
479
496
|
throw new Error('getBrowseFacets response data is malformed');
|
|
480
497
|
});
|
|
481
498
|
}
|
|
499
|
+
/**
|
|
500
|
+
* Retrieve facet options from API
|
|
501
|
+
*
|
|
502
|
+
* @function getBrowseFacetOptions
|
|
503
|
+
* @param {string} facetName - Name of the facet whose options to return
|
|
504
|
+
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
505
|
+
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
506
|
+
* @param {object} [parameters] - Additional parameters to refine result set
|
|
507
|
+
* @param {object} [parameters.fmtOptions] - The format options used to refine result groups
|
|
508
|
+
* @param {boolean} [parameters.fmtOptions.show_hidden_facets] - Include facets configured as hidden
|
|
509
|
+
* @param {}
|
|
510
|
+
* @returns {Promise}
|
|
511
|
+
* @see https://docs.constructor.io/rest_api/browse/facet_options/
|
|
512
|
+
* @example
|
|
513
|
+
* constructorio.browse.getBrowseFacetOptions('price', {
|
|
514
|
+
* });
|
|
515
|
+
*/
|
|
516
|
+
|
|
517
|
+
}, {
|
|
518
|
+
key: "getBrowseFacetOptions",
|
|
519
|
+
value: function getBrowseFacetOptions(facetName) {
|
|
520
|
+
var _this5 = this;
|
|
521
|
+
|
|
522
|
+
var parameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
523
|
+
var networkParameters = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
524
|
+
var requestUrl;
|
|
525
|
+
var fetch = this.options && this.options.fetch || fetchPonyfill({
|
|
526
|
+
Promise: Promise
|
|
527
|
+
}).fetch;
|
|
528
|
+
var signal;
|
|
529
|
+
|
|
530
|
+
if (typeof AbortController === 'function') {
|
|
531
|
+
var controller = new AbortController();
|
|
532
|
+
signal = controller && controller.signal; // Handle network timeout if specified
|
|
533
|
+
|
|
534
|
+
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
try {
|
|
538
|
+
requestUrl = createBrowseUrlForFacetOptions(facetName, parameters, this.options);
|
|
539
|
+
} catch (e) {
|
|
540
|
+
return Promise.reject(e);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
return fetch(requestUrl, {
|
|
544
|
+
signal: signal
|
|
545
|
+
}).then(function (response) {
|
|
546
|
+
if (response.ok) {
|
|
547
|
+
return response.json();
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
551
|
+
}).then(function (json) {
|
|
552
|
+
if (json.response && json.response.facets) {
|
|
553
|
+
_this5.eventDispatcher.queue('browse.getBrowseFacetOptions.completed', json);
|
|
554
|
+
|
|
555
|
+
return json;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
throw new Error('getBrowseFacetOptions response data is malformed');
|
|
559
|
+
});
|
|
560
|
+
}
|
|
482
561
|
}]);
|
|
483
562
|
return Browse;
|
|
484
563
|
}();
|