@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
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/${
|
|
90
|
+
return `${serviceUrl}/autocomplete/${helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(cleanedQuery))}?${queryString}`;
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
/**
|
package/src/modules/browse.js
CHANGED
|
@@ -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/${
|
|
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
|
|
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
|
/**
|
package/src/modules/search.js
CHANGED
|
@@ -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/${
|
|
127
|
+
return `${serviceUrl}/search/${helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(query))}?${queryString}`;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
/**
|
package/src/modules/tracker.js
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
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 =
|
|
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 = {};
|
package/src/utils/helpers.js
CHANGED
|
@@ -1,22 +1,9 @@
|
|
|
1
1
|
/* eslint-disable no-param-reassign */
|
|
2
|
-
const qs = require('qs');
|
|
3
|
-
|
|
4
2
|
const utils = {
|
|
5
|
-
|
|
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
|
-
|
|
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] =
|
|
17
|
+
cleanedParams[paramKey] = utils.trimNonBreakingSpaces(paramValue);
|
|
31
18
|
} else {
|
|
32
19
|
cleanedParams[paramKey] = paramValue;
|
|
33
20
|
}
|