@constructor-io/constructorio-node 4.11.0 → 4.11.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-node",
3
- "version": "4.11.0",
3
+ "version": "4.11.1",
4
4
  "description": "Constructor.io Node.js client",
5
5
  "main": "src/constructorio.js",
6
6
  "types": "src/types/constructorio.d.ts",
@@ -153,7 +153,7 @@ function createBrowseUrlFromFilter(filterName, filterValue, parameters, userPara
153
153
  const queryParams = createQueryParams(parameters, userParameters, options);
154
154
  const queryString = qs.stringify(queryParams, { indices: false });
155
155
 
156
- return `${serviceUrl}/browse/${helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(filterName))}/${helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(filterValue))}?${queryString}`;
156
+ return `${serviceUrl}/browse/${helpers.encodeURIComponentRFC3986(helpers.normalizeSpaces(filterName).trim())}/${helpers.encodeURIComponentRFC3986(helpers.normalizeSpaces(filterValue).trim())}?${queryString}`;
157
157
  }
158
158
 
159
159
  // Create URL from supplied IDs and parameters
@@ -84,7 +84,7 @@ function createRecommendationsUrl(podId, parameters, userParameters, options) {
84
84
 
85
85
  const queryString = qs.stringify(queryParams, { indices: false });
86
86
 
87
- return `${serviceUrl}/recommendations/v1/pods/${helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(podId))}?${queryString}`;
87
+ return `${serviceUrl}/recommendations/v1/pods/${helpers.encodeURIComponentRFC3986(helpers.normalizeSpaces(podId).trim())}?${queryString}`;
88
88
  }
89
89
 
90
90
  /**
@@ -418,7 +418,7 @@ class Tracker {
418
418
  if (term && typeof term === 'string') {
419
419
  // Ensure parameters are provided (required)
420
420
  if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) {
421
- const url = `${this.options.serviceUrl}/autocomplete/${helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(term))}/select?`;
421
+ const url = `${this.options.serviceUrl}/autocomplete/${helpers.encodeURIComponentRFC3986(helpers.normalizeSpaces(term))}/select?`;
422
422
  const queryParams = {};
423
423
  const {
424
424
  original_query,
@@ -516,7 +516,7 @@ class Tracker {
516
516
  if (term && typeof term === 'string') {
517
517
  // Ensure parameters are provided (required)
518
518
  if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) {
519
- const url = `${this.options.serviceUrl}/autocomplete/${helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(term))}/search?`;
519
+ const url = `${this.options.serviceUrl}/autocomplete/${helpers.encodeURIComponentRFC3986(helpers.normalizeSpaces(term))}/search?`;
520
520
  const queryParams = {};
521
521
  const {
522
522
  original_query,
@@ -700,7 +700,7 @@ class Tracker {
700
700
  if (term && typeof term === 'string') {
701
701
  // Ensure parameters are provided (required)
702
702
  if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) {
703
- const url = `${this.options.serviceUrl}/autocomplete/${helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(term))}/click_through?`;
703
+ const url = `${this.options.serviceUrl}/autocomplete/${helpers.encodeURIComponentRFC3986(helpers.normalizeSpaces(term))}/click_through?`;
704
704
  const queryParams = {};
705
705
  const {
706
706
  item_name,
@@ -7,7 +7,9 @@ const PII_REGEX = {
7
7
  };
8
8
 
9
9
  const utils = {
10
- trimNonBreakingSpaces: (string) => string.replace(/\s/g, ' ').trim(),
10
+ // Replace non-breaking spaces (or any other type of spaces caught by the regex)
11
+ // - with a regular white space
12
+ normalizeSpaces: (string) => string.replace(/\s/g, ' '),
11
13
 
12
14
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
13
15
  encodeURIComponentRFC3986: (string) => encodeURIComponent(string).replace(/[!'()*]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`),
@@ -16,12 +18,15 @@ const utils = {
16
18
  const cleanedParams = {};
17
19
 
18
20
  Object.keys(paramsObj).forEach((paramKey) => {
21
+ const excludeTrimList = ['term', 'original_query', 'search_term'];
19
22
  const paramValue = paramsObj[paramKey];
20
23
 
21
24
  if (typeof paramValue === 'string') {
22
- // Replace non-breaking spaces (or any other type of spaces caught by the regex)
23
- // - with a regular white space
24
- cleanedParams[paramKey] = utils.trimNonBreakingSpaces(paramValue);
25
+ cleanedParams[paramKey] = utils.normalizeSpaces(paramValue);
26
+
27
+ if (!excludeTrimList.includes(paramKey)) {
28
+ cleanedParams[paramKey] = cleanedParams[paramKey].trim();
29
+ }
25
30
  } else {
26
31
  cleanedParams[paramKey] = paramValue;
27
32
  }