@constructor-io/constructorio-client-javascript 2.27.13 → 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; // Create URL from supplied query (term) and parameters
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) {
@@ -99,7 +101,7 @@ function createAutocompleteUrl(query, parameters, options) {
99
101
  });
100
102
  var cleanedQuery = query.replace(/^\//, '|'); // For compatibility with backend API
101
103
 
102
- return "".concat(serviceUrl, "/autocomplete/").concat(encodeURIComponent(cleanedQuery), "?").concat(queryString);
104
+ return "".concat(serviceUrl, "/autocomplete/").concat(encodeURIComponentRFC3986(trimNonBreakingSpaces(cleanedQuery)), "?").concat(queryString);
103
105
  }
104
106
  /**
105
107
  * Interface to autocomplete related API calls.
@@ -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(encodeURIComponent(filterName), "/").concat(encodeURIComponent(filterValue), "?").concat(queryString);
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)); // Endpoint does not accept _dt
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?facet_name=").concat(facetName, "&").concat(queryString);
200
+ return "".concat(serviceUrl, "/browse/facet_options?").concat(queryString);
200
201
  }
201
202
  /**
202
203
  * Interface to browse related API calls
@@ -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(encodeURIComponent(podId), "?").concat(queryString);
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
@@ -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(encodeURIComponent(query), "?").concat(queryString);
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
@@ -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.ourEncodeURIComponent(term), "/select?");
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.ourEncodeURIComponent(term), "/search?");
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.ourEncodeURIComponent(term), "/click_through?");
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 = helpers.ourEncodeURIComponent(term) || 'TERM_UNKNOWN';
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 = {};
@@ -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
- ourEncodeURIComponent: function ourEncodeURIComponent(str) {
17
- if (str && typeof str === 'string') {
18
- var cleanedString = str.replace(/\[/g, '%5B') // Replace [
19
- .replace(/\]/g, '%5D') // Replace ]
20
- .replace(/&/g, '%26'); // Replace &
21
-
22
- var trimmedCleanedString = cleanedString.trim();
23
- var parsedStrObj = qs.parse("s=".concat(trimmedCleanedString));
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] = decodeURIComponent(utils.ourEncodeURIComponent(paramValue));
31
+ cleanedParams[paramKey] = utils.trimNonBreakingSpaces(paramValue);
39
32
  } else {
40
33
  cleanedParams[paramKey] = paramValue;
41
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-client-javascript",
3
- "version": "2.27.13",
3
+ "version": "2.28.0",
4
4
  "description": "Constructor.io JavaScript client",
5
5
  "main": "lib/constructorio.js",
6
6
  "scripts": {