@constructor-io/constructorio-node 4.10.1 → 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 +1 -1
- package/src/modules/autocomplete.js +7 -0
- package/src/modules/browse.js +1 -1
- package/src/modules/recommendations.js +1 -1
- package/src/modules/tracker.js +3 -3
- package/src/types/autocomplete.d.ts +3 -0
- package/src/types/browse.d.ts +2 -0
- package/src/types/search.d.ts +2 -0
- package/src/utils/helpers.js +9 -4
package/package.json
CHANGED
|
@@ -53,6 +53,7 @@ function createAutocompleteUrl(query, parameters, userParameters, options) {
|
|
|
53
53
|
filtersPerSection,
|
|
54
54
|
hiddenFields,
|
|
55
55
|
variationsMap,
|
|
56
|
+
preFilterExpression,
|
|
56
57
|
resultsPerPagePerSection,
|
|
57
58
|
pagePerSection,
|
|
58
59
|
} = parameters;
|
|
@@ -104,6 +105,11 @@ function createAutocompleteUrl(query, parameters, userParameters, options) {
|
|
|
104
105
|
if (variationsMap) {
|
|
105
106
|
queryParams.variations_map = JSON.stringify(variationsMap);
|
|
106
107
|
}
|
|
108
|
+
|
|
109
|
+
// Pull filter expression from parameters
|
|
110
|
+
if (preFilterExpression) {
|
|
111
|
+
queryParams.pre_filter_expression = JSON.stringify(preFilterExpression);
|
|
112
|
+
}
|
|
107
113
|
}
|
|
108
114
|
|
|
109
115
|
queryParams._dt = Date.now();
|
|
@@ -142,6 +148,7 @@ class Autocomplete {
|
|
|
142
148
|
* @param {object} [parameters.resultsPerSection] - Number of results to return (value) per section (key)
|
|
143
149
|
* @param {string[]} [parameters.hiddenFields] - Hidden metadata fields to return
|
|
144
150
|
* @param {object} [parameters.variationsMap] - The variations map object to aggregate variations. Please refer to https://docs.constructor.io/rest_api/variations_mapping for details
|
|
151
|
+
* @param {object} [parameters.preFilterExpression] - Faceting expression to scope autocomplete results. Please refer to https://docs.constructor.io/rest_api/collections/#add-items-dynamically for details
|
|
145
152
|
* @param {object} [userParameters] - Parameters relevant to the user request
|
|
146
153
|
* @param {number} [userParameters.sessionId] - Session ID, utilized to personalize results
|
|
147
154
|
* @param {string} [userParameters.clientId] - Client ID, utilized to personalize results
|
package/src/modules/browse.js
CHANGED
|
@@ -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.
|
|
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.
|
|
87
|
+
return `${serviceUrl}/recommendations/v1/pods/${helpers.encodeURIComponentRFC3986(helpers.normalizeSpaces(podId).trim())}?${queryString}`;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
/**
|
package/src/modules/tracker.js
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
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,
|
|
@@ -18,6 +18,7 @@ export interface AutocompleteParameters {
|
|
|
18
18
|
resultsPerPagePerSection?: Record<string, number>;
|
|
19
19
|
hiddenFields?: string[];
|
|
20
20
|
variationsMap?: VariationsMap;
|
|
21
|
+
preFilterExpression?: FilterExpression;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
declare class Autocomplete {
|
|
@@ -47,6 +48,8 @@ export interface AutocompleteRequestType extends Record<string, any> {
|
|
|
47
48
|
features: Partial<RequestFeature>;
|
|
48
49
|
feature_variants: Partial<RequestFeatureVariant>;
|
|
49
50
|
searchandized_items: Record<string, any>;
|
|
51
|
+
variations_map?: VariationsMap;
|
|
52
|
+
pre_filter_expression?: FilterExpression;
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
export type Section = Partial<SectionItem>[];
|
package/src/types/browse.d.ts
CHANGED
|
@@ -142,4 +142,6 @@ export interface BrowseRequestType extends Record<string, any> {
|
|
|
142
142
|
features: Partial<RequestFeature>;
|
|
143
143
|
feature_variants: Partial<RequestFeatureVariant>;
|
|
144
144
|
searchandized_items: Record<string, any>;
|
|
145
|
+
variations_map?: VariationsMap;
|
|
146
|
+
pre_filter_expression?: FilterExpression;
|
|
145
147
|
}
|
package/src/types/search.d.ts
CHANGED
|
@@ -83,6 +83,8 @@ export interface SearchRequestType extends Record<string, any> {
|
|
|
83
83
|
features: Partial<RequestFeature>;
|
|
84
84
|
feature_variants: Partial<RequestFeatureVariant>;
|
|
85
85
|
searchandized_items: Record<string, any>;
|
|
86
|
+
variations_map?: VariationsMap;
|
|
87
|
+
pre_filter_expression?: FilterExpression;
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
export interface SearchResultType extends Record<string, any> {
|
package/src/utils/helpers.js
CHANGED
|
@@ -7,7 +7,9 @@ const PII_REGEX = {
|
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
const utils = {
|
|
10
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
}
|