@constructor-io/constructorio-client-javascript 2.27.11 → 2.28.0
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.
|
@@ -18,7 +18,9 @@ var EventDispatcher = require('../utils/event-dispatcher');
|
|
|
18
18
|
var _require = require('../utils/helpers'),
|
|
19
19
|
throwHttpErrorFromResponse = _require.throwHttpErrorFromResponse,
|
|
20
20
|
cleanParams = _require.cleanParams,
|
|
21
|
-
applyNetworkTimeout = _require.applyNetworkTimeout
|
|
21
|
+
applyNetworkTimeout = _require.applyNetworkTimeout,
|
|
22
|
+
trimNonBreakingSpaces = _require.trimNonBreakingSpaces,
|
|
23
|
+
encodeURIComponentRFC3986 = _require.encodeURIComponentRFC3986; // Create URL from supplied query (term) and parameters
|
|
22
24
|
|
|
23
25
|
|
|
24
26
|
function createAutocompleteUrl(query, parameters, options) {
|
|
@@ -97,7 +99,9 @@ function createAutocompleteUrl(query, parameters, options) {
|
|
|
97
99
|
var queryString = qs.stringify(queryParams, {
|
|
98
100
|
indices: false
|
|
99
101
|
});
|
|
100
|
-
|
|
102
|
+
var cleanedQuery = query.replace(/^\//, '|'); // For compatibility with backend API
|
|
103
|
+
|
|
104
|
+
return "".concat(serviceUrl, "/autocomplete/").concat(encodeURIComponentRFC3986(trimNonBreakingSpaces(cleanedQuery)), "?").concat(queryString);
|
|
101
105
|
}
|
|
102
106
|
/**
|
|
103
107
|
* Interface to autocomplete related API calls.
|
package/lib/modules/browse.js
CHANGED
|
@@ -146,7 +146,7 @@ function createBrowseUrlFromFilter(filterName, filterValue, parameters, options)
|
|
|
146
146
|
var queryString = qs.stringify(queryParams, {
|
|
147
147
|
indices: false
|
|
148
148
|
});
|
|
149
|
-
return "".concat(serviceUrl, "/browse/").concat(
|
|
149
|
+
return "".concat(serviceUrl, "/browse/").concat(helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(filterName)), "/").concat(helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(filterValue)), "?").concat(queryString);
|
|
150
150
|
} // Create URL from supplied id's
|
|
151
151
|
|
|
152
152
|
|
|
@@ -189,14 +189,15 @@ function createBrowseUrlForFacetOptions(facetName, parameters, options) {
|
|
|
189
189
|
throw new Error('facetName is a required parameter of type string');
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
var queryParams = _objectSpread({}, createQueryParams(parameters, options));
|
|
192
|
+
var queryParams = _objectSpread({}, createQueryParams(parameters, options));
|
|
193
193
|
|
|
194
|
+
queryParams.facet_name = facetName; // Endpoint does not accept _dt
|
|
194
195
|
|
|
195
196
|
delete queryParams._dt;
|
|
196
197
|
var queryString = qs.stringify(queryParams, {
|
|
197
198
|
indices: false
|
|
198
199
|
});
|
|
199
|
-
return "".concat(serviceUrl, "/browse/facet_options?
|
|
200
|
+
return "".concat(serviceUrl, "/browse/facet_options?").concat(queryString);
|
|
200
201
|
}
|
|
201
202
|
/**
|
|
202
203
|
* Interface to browse related API calls
|
|
@@ -226,6 +227,7 @@ var Browse = /*#__PURE__*/function () {
|
|
|
226
227
|
* @param {object} [parameters.filters] - Key / value mapping (dictionary) of filters used to refine results
|
|
227
228
|
* @param {string} [parameters.sortBy='relevance'] - The sort method for results
|
|
228
229
|
* @param {string} [parameters.sortOrder='descending'] - The sort order for results
|
|
230
|
+
* @param {string} [parameters.section='Products'] - The section name for results
|
|
229
231
|
* @param {object} [parameters.fmtOptions] - The format options used to refine result groups
|
|
230
232
|
* @param {string[]} [parameters.hiddenFields] - Hidden metadata fields to return
|
|
231
233
|
* @param {string[]} [parameters.hiddenFacets] - Hidden facets to return
|
|
@@ -305,6 +307,7 @@ var Browse = /*#__PURE__*/function () {
|
|
|
305
307
|
* @param {object} [parameters.filters] - Filters used to refine results
|
|
306
308
|
* @param {string} [parameters.sortBy='relevance'] - The sort method for results
|
|
307
309
|
* @param {string} [parameters.sortOrder='descending'] - The sort order for results
|
|
310
|
+
* @param {string} [parameters.section='Products'] - The section name for results
|
|
308
311
|
* @param {object} [parameters.fmtOptions] - The format options used to refine result groups
|
|
309
312
|
* @param {string[]} [parameters.hiddenFields] - Hidden metadata fields to return
|
|
310
313
|
* @param {string[]} [parameters.hiddenFacets] - Hidden facets to return
|
|
@@ -376,6 +379,7 @@ var Browse = /*#__PURE__*/function () {
|
|
|
376
379
|
*
|
|
377
380
|
* @function getBrowseGroups
|
|
378
381
|
* @param {object} [parameters.filters] - Filters used to refine results
|
|
382
|
+
* @param {string} [parameters.section='Products'] - The section name for results
|
|
379
383
|
* @param {object} [parameters.fmtOptions] - The format options used to refine result groups
|
|
380
384
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
381
385
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
@@ -441,6 +445,7 @@ var Browse = /*#__PURE__*/function () {
|
|
|
441
445
|
* @function getBrowseFacets
|
|
442
446
|
* @param {object} [parameters] - Additional parameters to refine result set
|
|
443
447
|
* @param {number} [parameters.page] - The page number of the results
|
|
448
|
+
* @param {string} [parameters.section='Products'] - The section name for results
|
|
444
449
|
* @param {boolean} [parameters.fmtOptions.show_hidden_facets] - Include facets configured as hidden
|
|
445
450
|
* @param {number} [parameters.resultsPerPage] - The number of results per page to return
|
|
446
451
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
@@ -504,6 +509,7 @@ var Browse = /*#__PURE__*/function () {
|
|
|
504
509
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
505
510
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
506
511
|
* @param {object} [parameters] - Additional parameters to refine result set
|
|
512
|
+
* @param {string} [parameters.section='Products'] - The section name for results
|
|
507
513
|
* @param {object} [parameters.fmtOptions] - The format options used to refine result groups
|
|
508
514
|
* @param {boolean} [parameters.fmtOptions.show_hidden_facets] - Include facets configured as hidden
|
|
509
515
|
* @param {}
|
|
@@ -83,7 +83,7 @@ function createRecommendationsUrl(podId, parameters, options) {
|
|
|
83
83
|
var queryString = qs.stringify(queryParams, {
|
|
84
84
|
indices: false
|
|
85
85
|
});
|
|
86
|
-
return "".concat(serviceUrl, "/recommendations/v1/pods/").concat(
|
|
86
|
+
return "".concat(serviceUrl, "/recommendations/v1/pods/").concat(helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(podId)), "?").concat(queryString);
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
89
|
* Interface to recommendations related API calls
|
package/lib/modules/search.js
CHANGED
|
@@ -130,7 +130,7 @@ function createSearchUrl(query, parameters, options) {
|
|
|
130
130
|
var queryString = qs.stringify(queryParams, {
|
|
131
131
|
indices: false
|
|
132
132
|
});
|
|
133
|
-
return "".concat(serviceUrl, "/search/").concat(
|
|
133
|
+
return "".concat(serviceUrl, "/search/").concat(helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(query)), "?").concat(queryString);
|
|
134
134
|
}
|
|
135
135
|
/**
|
|
136
136
|
* Interface to search related API calls
|
package/lib/modules/tracker.js
CHANGED
|
@@ -259,7 +259,7 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
259
259
|
if (term && typeof term === 'string') {
|
|
260
260
|
// Ensure parameters are provided (required)
|
|
261
261
|
if (parameters && (0, _typeof2["default"])(parameters) === 'object' && !Array.isArray(parameters)) {
|
|
262
|
-
var url = "".concat(this.options.serviceUrl, "/autocomplete/").concat(helpers.
|
|
262
|
+
var url = "".concat(this.options.serviceUrl, "/autocomplete/").concat(helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(term)), "/select?");
|
|
263
263
|
var queryParams = {};
|
|
264
264
|
var original_query = parameters.original_query,
|
|
265
265
|
section = parameters.section,
|
|
@@ -332,7 +332,7 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
332
332
|
if (term && typeof term === 'string') {
|
|
333
333
|
// Ensure parameters are provided (required)
|
|
334
334
|
if (parameters && (0, _typeof2["default"])(parameters) === 'object' && !Array.isArray(parameters)) {
|
|
335
|
-
var url = "".concat(this.options.serviceUrl, "/autocomplete/").concat(helpers.
|
|
335
|
+
var url = "".concat(this.options.serviceUrl, "/autocomplete/").concat(helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(term)), "/search?");
|
|
336
336
|
var queryParams = {};
|
|
337
337
|
var original_query = parameters.original_query,
|
|
338
338
|
group_id = parameters.group_id,
|
|
@@ -463,7 +463,7 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
463
463
|
if (term && typeof term === 'string') {
|
|
464
464
|
// Ensure parameters are provided (required)
|
|
465
465
|
if (parameters && (0, _typeof2["default"])(parameters) === 'object' && !Array.isArray(parameters)) {
|
|
466
|
-
var url = "".concat(this.options.serviceUrl, "/autocomplete/").concat(helpers.
|
|
466
|
+
var url = "".concat(this.options.serviceUrl, "/autocomplete/").concat(helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(term)), "/click_through?");
|
|
467
467
|
var queryParams = {};
|
|
468
468
|
var item_name = parameters.item_name,
|
|
469
469
|
name = parameters.name,
|
|
@@ -547,7 +547,7 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
547
547
|
|
|
548
548
|
// Ensure parameters are provided (required)
|
|
549
549
|
if (parameters && (0, _typeof2["default"])(parameters) === 'object' && !Array.isArray(parameters)) {
|
|
550
|
-
var searchTerm =
|
|
550
|
+
var searchTerm = term || 'TERM_UNKNOWN';
|
|
551
551
|
var requestPath = "".concat(this.options.serviceUrl, "/v2/behavioral_action/conversion?");
|
|
552
552
|
var queryParams = {};
|
|
553
553
|
var bodyParams = {};
|
package/lib/utils/helpers.js
CHANGED
|
@@ -5,27 +5,20 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
6
6
|
|
|
7
7
|
/* eslint-disable no-param-reassign */
|
|
8
|
-
var qs = require('qs');
|
|
9
|
-
|
|
10
8
|
var CRC32 = require('crc-32');
|
|
11
9
|
|
|
12
10
|
var store = require('./store');
|
|
13
11
|
|
|
14
12
|
var purchaseEventStorageKey = '_constructorio_purchase_order_ids';
|
|
15
13
|
var utils = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
parsedStrObj.s = parsedStrObj.s.replace(/\s/g, ' ');
|
|
25
|
-
return qs.stringify(parsedStrObj).split('=')[1];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return null;
|
|
14
|
+
trimNonBreakingSpaces: function trimNonBreakingSpaces(string) {
|
|
15
|
+
return string.replace(/\s/g, ' ').trim();
|
|
16
|
+
},
|
|
17
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
|
|
18
|
+
encodeURIComponentRFC3986: function encodeURIComponentRFC3986(string) {
|
|
19
|
+
return encodeURIComponent(string).replace(/[!'()*]/g, function (c) {
|
|
20
|
+
return "%".concat(c.charCodeAt(0).toString(16).toUpperCase());
|
|
21
|
+
});
|
|
29
22
|
},
|
|
30
23
|
cleanParams: function cleanParams(paramsObj) {
|
|
31
24
|
var cleanedParams = {};
|
|
@@ -35,7 +28,7 @@ var utils = {
|
|
|
35
28
|
if (typeof paramValue === 'string') {
|
|
36
29
|
// Replace non-breaking spaces (or any other type of spaces caught by the regex)
|
|
37
30
|
// - with a regular white space
|
|
38
|
-
cleanedParams[paramKey] =
|
|
31
|
+
cleanedParams[paramKey] = utils.trimNonBreakingSpaces(paramValue);
|
|
39
32
|
} else {
|
|
40
33
|
cleanedParams[paramKey] = paramValue;
|
|
41
34
|
}
|