@constructor-io/constructorio-node 3.9.0 → 3.10.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-node",
3
- "version": "3.9.0",
3
+ "version": "3.10.0",
4
4
  "description": "Constructor.io Node.js client",
5
5
  "main": "src/constructorio.js",
6
6
  "scripts": {
package/src/.DS_Store ADDED
Binary file
@@ -85,8 +85,9 @@ function createAutocompleteUrl(query, parameters, userParameters, options) {
85
85
  queryParams = helpers.cleanParams(queryParams);
86
86
 
87
87
  const queryString = qs.stringify(queryParams, { indices: false });
88
+ const cleanedQuery = query.replace(/^\//, '|'); // For compatibility with backend API
88
89
 
89
- return `${serviceUrl}/autocomplete/${encodeURIComponent(query)}?${queryString}`;
90
+ return `${serviceUrl}/autocomplete/${helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(cleanedQuery))}?${queryString}`;
90
91
  }
91
92
 
92
93
  /**
@@ -135,7 +135,7 @@ function createBrowseUrlFromFilter(filterName, filterValue, parameters, userPara
135
135
  const queryParams = createQueryParams(parameters, userParameters, options);
136
136
  const queryString = qs.stringify(queryParams, { indices: false });
137
137
 
138
- return `${serviceUrl}/browse/${encodeURIComponent(filterName)}/${encodeURIComponent(filterValue)}?${queryString}`;
138
+ return `${serviceUrl}/browse/${helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(filterName))}/${helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(filterValue))}?${queryString}`;
139
139
  }
140
140
 
141
141
  // Create URL from supplied IDs and parameters
@@ -176,11 +176,13 @@ function createBrowseUrlForFacetOptions(facetName, parameters, userParameters, o
176
176
 
177
177
  const queryParams = { ...createQueryParams(parameters, userParameters, options) };
178
178
 
179
+ queryParams.facet_name = facetName;
180
+
179
181
  delete queryParams._dt;
180
182
 
181
183
  const queryString = qs.stringify(queryParams, { indices: false });
182
184
 
183
- return `${serviceUrl}/browse/facet_options?facet_name=${facetName}&${queryString}`;
185
+ return `${serviceUrl}/browse/facet_options?${queryString}`;
184
186
  }
185
187
 
186
188
  // Create request headers using supplied options and user parameters
@@ -76,7 +76,7 @@ function createRecommendationsUrl(podId, parameters, userParameters, options) {
76
76
 
77
77
  const queryString = qs.stringify(queryParams, { indices: false });
78
78
 
79
- return `${serviceUrl}/recommendations/v1/pods/${podId}?${queryString}`;
79
+ return `${serviceUrl}/recommendations/v1/pods/${helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(podId))}?${queryString}`;
80
80
  }
81
81
 
82
82
  /**
@@ -124,7 +124,7 @@ function createSearchUrl(query, parameters, userParameters, options) {
124
124
 
125
125
  const queryString = qs.stringify(queryParams, { indices: false });
126
126
 
127
- return `${serviceUrl}/search/${encodeURIComponent(query)}?${queryString}`;
127
+ return `${serviceUrl}/search/${helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(query))}?${queryString}`;
128
128
  }
129
129
 
130
130
  /**
@@ -385,7 +385,7 @@ class Tracker {
385
385
  if (term && typeof term === 'string') {
386
386
  // Ensure parameters are provided (required)
387
387
  if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) {
388
- const url = `${this.options.serviceUrl}/autocomplete/${helpers.ourEncodeURIComponent(term)}/select?`;
388
+ const url = `${this.options.serviceUrl}/autocomplete/${helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(term))}/select?`;
389
389
  const queryParams = {};
390
390
  const {
391
391
  original_query,
@@ -479,7 +479,7 @@ class Tracker {
479
479
  if (term && typeof term === 'string') {
480
480
  // Ensure parameters are provided (required)
481
481
  if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) {
482
- const url = `${this.options.serviceUrl}/autocomplete/${helpers.ourEncodeURIComponent(term)}/search?`;
482
+ const url = `${this.options.serviceUrl}/autocomplete/${helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(term))}/search?`;
483
483
  const queryParams = {};
484
484
  const { original_query, group_id, display_name } = parameters;
485
485
 
@@ -641,7 +641,7 @@ class Tracker {
641
641
  if (term && typeof term === 'string') {
642
642
  // Ensure parameters are provided (required)
643
643
  if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) {
644
- const url = `${this.options.serviceUrl}/autocomplete/${helpers.ourEncodeURIComponent(term)}/click_through?`;
644
+ const url = `${this.options.serviceUrl}/autocomplete/${helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(term))}/click_through?`;
645
645
  const queryParams = {};
646
646
  const { item_name, name, item_id, customer_id, variation_id, result_id } = parameters;
647
647
 
@@ -740,7 +740,7 @@ class Tracker {
740
740
  trackConversion(term, parameters, userParameters, networkParameters = {}) {
741
741
  // Ensure parameters are provided (required)
742
742
  if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) {
743
- const searchTerm = helpers.ourEncodeURIComponent(term) || 'TERM_UNKNOWN';
743
+ const searchTerm = term || 'TERM_UNKNOWN';
744
744
  const requestPath = `${this.options.serviceUrl}/v2/behavioral_action/conversion?`;
745
745
  const queryParams = {};
746
746
  const bodyParams = {};
@@ -1,22 +1,9 @@
1
1
  /* eslint-disable no-param-reassign */
2
- const qs = require('qs');
3
-
4
2
  const utils = {
5
- ourEncodeURIComponent: (str) => {
6
- if (str && typeof str === 'string') {
7
- const cleanedString = str
8
- .replace(/\[/g, '%5B') // Replace [
9
- .replace(/\]/g, '%5D') // Replace ]
10
- .replace(/&/g, '%26'); // Replace &
11
- const trimmedCleanedString = cleanedString.trim();
12
- const parsedStrObj = qs.parse(`s=${trimmedCleanedString}`);
13
-
14
- parsedStrObj.s = parsedStrObj.s.replace(/\s/g, ' ');
3
+ trimNonBreakingSpaces: (string) => string.replace(/\s/g, ' ').trim(),
15
4
 
16
- return qs.stringify(parsedStrObj).split('=')[1];
17
- }
18
- return null;
19
- },
5
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
6
+ encodeURIComponentRFC3986: (string) => encodeURIComponent(string).replace(/[!'()*]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`),
20
7
 
21
8
  cleanParams: (paramsObj) => {
22
9
  const cleanedParams = {};
@@ -27,7 +14,7 @@ const utils = {
27
14
  if (typeof paramValue === 'string') {
28
15
  // Replace non-breaking spaces (or any other type of spaces caught by the regex)
29
16
  // - with a regular white space
30
- cleanedParams[paramKey] = decodeURIComponent(utils.ourEncodeURIComponent(paramValue));
17
+ cleanedParams[paramKey] = utils.trimNonBreakingSpaces(paramValue);
31
18
  } else {
32
19
  cleanedParams[paramKey] = paramValue;
33
20
  }