@constructor-io/constructorio-client-javascript 2.39.1 → 2.41.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/lib/modules/autocomplete.js +9 -0
- package/lib/types/autocomplete.d.ts +1 -0
- package/lib/utils/store.js +140 -6
- package/package.json +3 -4
- package/lib/types/types.d.ts +0 -126
- package/lib/utils/store.overflow.js +0 -86
- package/lib/utils/store_old.js +0 -9
|
@@ -55,6 +55,7 @@ function createAutocompleteUrl(query, parameters, options) {
|
|
|
55
55
|
var numResults = parameters.numResults,
|
|
56
56
|
resultsPerSection = parameters.resultsPerSection,
|
|
57
57
|
filters = parameters.filters,
|
|
58
|
+
filtersPerSection = parameters.filtersPerSection,
|
|
58
59
|
hiddenFields = parameters.hiddenFields,
|
|
59
60
|
variationsMap = parameters.variationsMap;
|
|
60
61
|
|
|
@@ -75,6 +76,13 @@ function createAutocompleteUrl(query, parameters, options) {
|
|
|
75
76
|
queryParams.filters = filters;
|
|
76
77
|
}
|
|
77
78
|
|
|
79
|
+
// Pull filtersPerSection from parameters
|
|
80
|
+
if (filtersPerSection) {
|
|
81
|
+
Object.keys(filtersPerSection).forEach(function (section) {
|
|
82
|
+
queryParams["filters[".concat(section, "]")] = filtersPerSection[section];
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
78
86
|
// Pull hidden fields from parameters
|
|
79
87
|
if (hiddenFields) {
|
|
80
88
|
if (queryParams.fmt_options) {
|
|
@@ -122,6 +130,7 @@ var Autocomplete = /*#__PURE__*/function () {
|
|
|
122
130
|
* @param {object} [parameters] - Additional parameters to refine result set
|
|
123
131
|
* @param {number} [parameters.numResults] - The total number of results to return
|
|
124
132
|
* @param {object} [parameters.filters] - Key / value mapping (dictionary) of filters used to refine results
|
|
133
|
+
* @param {object} [parameters.filtersPerSection] - Filters used to refine results per section
|
|
125
134
|
* @param {object} [parameters.resultsPerSection] - Number of results to return (value) per section (key)
|
|
126
135
|
* @param {string[]} [parameters.hiddenFields] - Hidden metadata fields to return
|
|
127
136
|
* @param {object} [parameters.variationsMap] - The variations map object to aggregate variations. Please refer to https://docs.constructor.io/rest_api/variations_mapping for details
|
|
@@ -13,6 +13,7 @@ export default Autocomplete;
|
|
|
13
13
|
export interface IAutocompleteParameters {
|
|
14
14
|
numResults?: number;
|
|
15
15
|
filters?: Record<string, any>;
|
|
16
|
+
filtersPerSection?: Record<string, Record<string, any>>;
|
|
16
17
|
resultsPerSection?: Record<string, number>;
|
|
17
18
|
hiddenFields?: string[];
|
|
18
19
|
variationsMap?: VariationsMap;
|
package/lib/utils/store.js
CHANGED
|
@@ -1,9 +1,143 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
var session = {
|
|
4
|
+
overflow: {},
|
|
5
|
+
get: function get(key) {
|
|
6
|
+
// Overflow
|
|
7
|
+
var valueFromOverflow = this.overflow[key];
|
|
8
|
+
if (valueFromOverflow) {
|
|
9
|
+
return valueFromOverflow;
|
|
10
|
+
}
|
|
11
|
+
if (typeof sessionStorage === 'undefined') {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
var valueFromSession = sessionStorage.getItem(key);
|
|
15
|
+
if (valueFromSession) {
|
|
16
|
+
try {
|
|
17
|
+
// Try to parse the value and return
|
|
18
|
+
return JSON.parse(valueFromSession);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
// If value exists but it's not valid JSON, still return the original value
|
|
21
|
+
return valueFromSession;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
},
|
|
26
|
+
set: function set(key, value) {
|
|
27
|
+
try {
|
|
28
|
+
sessionStorage.setItem(key, JSON.stringify(value));
|
|
29
|
+
} catch (e) {
|
|
30
|
+
this.overflow[key] = value;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
remove: function remove(key) {
|
|
34
|
+
var _this$overflow;
|
|
35
|
+
if ((_this$overflow = this.overflow) !== null && _this$overflow !== void 0 && _this$overflow[key]) {
|
|
36
|
+
delete this.overflow[key];
|
|
37
|
+
}
|
|
38
|
+
if (typeof sessionStorage !== 'undefined') {
|
|
39
|
+
sessionStorage.removeItem(key);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
key: function key(i) {
|
|
43
|
+
var _sessionStorage, _sessionStorage2;
|
|
44
|
+
if (typeof sessionStorage === 'undefined') {
|
|
45
|
+
var _Object$keys;
|
|
46
|
+
return (_Object$keys = Object.keys(this.overflow)) === null || _Object$keys === void 0 ? void 0 : _Object$keys[i];
|
|
47
|
+
}
|
|
48
|
+
var keyFromSessionStorage = (_sessionStorage = sessionStorage) === null || _sessionStorage === void 0 ? void 0 : _sessionStorage.key(i);
|
|
49
|
+
var sessionStorageLength = ((_sessionStorage2 = sessionStorage) === null || _sessionStorage2 === void 0 ? void 0 : _sessionStorage2.length) || 0;
|
|
50
|
+
if (i >= sessionStorageLength) {
|
|
51
|
+
var _Object$keys2;
|
|
52
|
+
var overflowIndex = i - sessionStorageLength;
|
|
53
|
+
return (_Object$keys2 = Object.keys(this.overflow)) === null || _Object$keys2 === void 0 ? void 0 : _Object$keys2[overflowIndex];
|
|
54
|
+
}
|
|
55
|
+
return keyFromSessionStorage;
|
|
56
|
+
},
|
|
57
|
+
length: function length() {
|
|
58
|
+
var overflowLength = Object.keys(this.overflow).length;
|
|
59
|
+
if (typeof sessionStorage === 'undefined') {
|
|
60
|
+
return overflowLength;
|
|
61
|
+
}
|
|
62
|
+
return sessionStorage.length + overflowLength;
|
|
63
|
+
},
|
|
64
|
+
clear: function clear() {
|
|
65
|
+
this.overflow = {};
|
|
66
|
+
if (typeof sessionStorage !== 'undefined') {
|
|
67
|
+
sessionStorage.clear();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var local = {
|
|
72
|
+
overflow: {},
|
|
73
|
+
get: function get(key) {
|
|
74
|
+
// Overflow
|
|
75
|
+
var valueFromOverflow = this.overflow[key];
|
|
76
|
+
if (valueFromOverflow) {
|
|
77
|
+
return valueFromOverflow;
|
|
78
|
+
}
|
|
79
|
+
if (typeof localStorage === 'undefined') {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
var valueFromLocal = localStorage.getItem(key);
|
|
83
|
+
if (valueFromLocal) {
|
|
84
|
+
try {
|
|
85
|
+
// Try to parse the value and return
|
|
86
|
+
return JSON.parse(valueFromLocal);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
// If value exists but it's not valid JSON, still return the original value
|
|
89
|
+
return valueFromLocal;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
},
|
|
94
|
+
set: function set(key, value) {
|
|
95
|
+
try {
|
|
96
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
97
|
+
} catch (e) {
|
|
98
|
+
this.overflow[key] = value;
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
remove: function remove(key) {
|
|
102
|
+
var _this$overflow2;
|
|
103
|
+
if ((_this$overflow2 = this.overflow) !== null && _this$overflow2 !== void 0 && _this$overflow2[key]) {
|
|
104
|
+
delete this.overflow[key];
|
|
105
|
+
}
|
|
106
|
+
if (typeof localStorage !== 'undefined') {
|
|
107
|
+
localStorage.removeItem(key);
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
key: function key(i) {
|
|
111
|
+
var _localStorage, _localStorage2;
|
|
112
|
+
if (typeof localStorage === 'undefined') {
|
|
113
|
+
var _Object$keys3;
|
|
114
|
+
return (_Object$keys3 = Object.keys(this.overflow)) === null || _Object$keys3 === void 0 ? void 0 : _Object$keys3[i];
|
|
115
|
+
}
|
|
116
|
+
var keyFromLocalStorage = (_localStorage = localStorage) === null || _localStorage === void 0 ? void 0 : _localStorage.key(i);
|
|
117
|
+
var localStorageLength = ((_localStorage2 = localStorage) === null || _localStorage2 === void 0 ? void 0 : _localStorage2.length) || 0;
|
|
118
|
+
if (i >= localStorageLength) {
|
|
119
|
+
var _Object$keys4;
|
|
120
|
+
var overflowIndex = i - localStorageLength;
|
|
121
|
+
return (_Object$keys4 = Object.keys(this.overflow)) === null || _Object$keys4 === void 0 ? void 0 : _Object$keys4[overflowIndex];
|
|
122
|
+
}
|
|
123
|
+
return keyFromLocalStorage;
|
|
124
|
+
},
|
|
125
|
+
length: function length() {
|
|
126
|
+
var overflowLength = Object.keys(this.overflow).length;
|
|
127
|
+
if (typeof localStorage === 'undefined') {
|
|
128
|
+
return overflowLength;
|
|
129
|
+
}
|
|
130
|
+
return localStorage.length + overflowLength;
|
|
131
|
+
},
|
|
132
|
+
clear: function clear() {
|
|
133
|
+
this.overflow = {};
|
|
134
|
+
if (typeof localStorage !== 'undefined') {
|
|
135
|
+
localStorage.clear();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
var store = {
|
|
140
|
+
local: local,
|
|
141
|
+
session: session
|
|
142
|
+
};
|
|
9
143
|
module.exports = store;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructor-io/constructorio-client-javascript",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.41.0",
|
|
4
4
|
"description": "Constructor.io JavaScript client",
|
|
5
5
|
"main": "lib/constructorio.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"coverage": "nyc --all --reporter=html npm run test:src",
|
|
24
24
|
"postcoverage": "open coverage/index.html && rm -rf test",
|
|
25
25
|
"docs": "jsdoc --configure ./.jsdoc.json ./README.md --recurse ./src --destination ./docs",
|
|
26
|
-
"compile": "babel src/ -d lib/ --copy-files && rm -rf lib/types/tests",
|
|
26
|
+
"compile": "rm -rf ./lib/* && babel src/ -d lib/ --copy-files && rm -rf ./lib/types/tests",
|
|
27
27
|
"prepublish": "npm run compile",
|
|
28
28
|
"bundle": "rm -rf ./dist/* && npm run compile && node bundle.js",
|
|
29
29
|
"prepare": "husky install"
|
|
@@ -73,8 +73,7 @@
|
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"@constructor-io/constructorio-id": "^2.4.17",
|
|
75
75
|
"crc-32": "^1.2.2",
|
|
76
|
-
"fetch-ponyfill": "^7.1.0"
|
|
77
|
-
"store2": "^2.14.2"
|
|
76
|
+
"fetch-ponyfill": "^7.1.0"
|
|
78
77
|
},
|
|
79
78
|
"peerDependencies": {
|
|
80
79
|
"@babel/runtime": "^7.19.0"
|
package/lib/types/types.d.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import EventDispatcher from './event-dispatcher';
|
|
2
|
-
|
|
3
|
-
export interface ConstructorClientOptions {
|
|
4
|
-
apiKey: string;
|
|
5
|
-
version?: string;
|
|
6
|
-
serviceUrl?: string;
|
|
7
|
-
// session id is of type string in jsdocs but of type number in code usage
|
|
8
|
-
sessionId?: string;
|
|
9
|
-
clientId?: string;
|
|
10
|
-
userId?: string;
|
|
11
|
-
segments?: string[];
|
|
12
|
-
testCells?: Record<string, string>;
|
|
13
|
-
fetch?: any;
|
|
14
|
-
trackingSendDelay?: number;
|
|
15
|
-
sendTrackingEvents?: boolean;
|
|
16
|
-
sendReferrerWithTrackingEvents?: boolean;
|
|
17
|
-
eventDispatcher?: EventDispatcher;
|
|
18
|
-
beaconMode?: boolean;
|
|
19
|
-
networkParameters?: {
|
|
20
|
-
timeout: number;
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface RequestFeature extends Record<string, any> {
|
|
25
|
-
query_items: boolean;
|
|
26
|
-
auto_generated_refined_query_rules: boolean;
|
|
27
|
-
manual_searchandizing: boolean;
|
|
28
|
-
personalization: boolean;
|
|
29
|
-
filter_items: boolean;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface RequestFeatureVariant extends Record<string, any> {
|
|
33
|
-
query_items: string;
|
|
34
|
-
auto_generated_refined_query_rules: string;
|
|
35
|
-
manual_searchandizing: string | null;
|
|
36
|
-
personalization: string;
|
|
37
|
-
filter_items: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export type ErrorData = {
|
|
41
|
-
message: string;
|
|
42
|
-
[key: string]: any;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export interface ResultSources extends Record<string, any> {
|
|
46
|
-
token_match: { count: number; [key: string]: any };
|
|
47
|
-
embeddings_match: { count: number; [key: string]: any };
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface SortOption extends Record<string, any> {
|
|
51
|
-
sort_by: string;
|
|
52
|
-
display_name: string;
|
|
53
|
-
sort_order: string;
|
|
54
|
-
status: string;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface Feature extends Record<string, any> {
|
|
58
|
-
feature_name: string;
|
|
59
|
-
display_name: string;
|
|
60
|
-
enabled: boolean;
|
|
61
|
-
variant: {
|
|
62
|
-
name: string;
|
|
63
|
-
display_name: string;
|
|
64
|
-
[key: string]: any;
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export interface FmtOption extends Record<string, any> {
|
|
69
|
-
groups_start: string;
|
|
70
|
-
groups_max_depth: number;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
type Facet = RangeFacet | OptionFacet;
|
|
74
|
-
|
|
75
|
-
export interface BaseFacet extends Record<string, any> {
|
|
76
|
-
data: Record<string, any>;
|
|
77
|
-
status: Record<string, any>;
|
|
78
|
-
display_name: string;
|
|
79
|
-
name: string;
|
|
80
|
-
hidden: boolean;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export interface RangeFacet extends BaseFacet, Record<string, any> {
|
|
84
|
-
max: number;
|
|
85
|
-
min: number;
|
|
86
|
-
type: "range";
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export interface OptionFacet extends BaseFacet, Record<string, any> {
|
|
90
|
-
options: FacetOption[];
|
|
91
|
-
type: "multiple" | "single" | "hierarchical";
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export interface FacetOption extends Record<string, any> {
|
|
95
|
-
count: number;
|
|
96
|
-
display_name: string;
|
|
97
|
-
value: string;
|
|
98
|
-
options?: FacetOption[];
|
|
99
|
-
range?: ["-inf" | number, "inf" | number];
|
|
100
|
-
status: string;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export interface Group extends BaseGroup, Record<string, any> {
|
|
104
|
-
count: number;
|
|
105
|
-
data: Record<string, any>;
|
|
106
|
-
parents: BaseGroup[];
|
|
107
|
-
children: Group[];
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export interface Collection extends Record<string, any> {
|
|
111
|
-
collection_id: string,
|
|
112
|
-
display_name: string,
|
|
113
|
-
data: Record<string, any>
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export interface BaseGroup extends Record<string, any> {
|
|
117
|
-
display_name: string;
|
|
118
|
-
group_id: string;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export interface FmtOptions extends Record<string, any> {
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export type Nullable<T> = T | null;
|
|
126
|
-
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/* eslint-disable */
|
|
4
|
-
/**
|
|
5
|
-
* Copyright (c) 2013 ESHA Research
|
|
6
|
-
* Dual licensed under the MIT and GPL licenses:
|
|
7
|
-
* http://www.opensource.org/licenses/mit-license.php
|
|
8
|
-
* http://www.gnu.org/licenses/gpl.html
|
|
9
|
-
*
|
|
10
|
-
* When quota is reached on a storage area, this shifts incoming values to
|
|
11
|
-
* fake storage, so they last only as long as the page does. This is useful
|
|
12
|
-
* because it is more burdensome for localStorage to recover from quota errors
|
|
13
|
-
* than incomplete caches. In other words, it is wiser to rely on store.js
|
|
14
|
-
* never complaining than never missing data. You should already be checking
|
|
15
|
-
* the integrity of cached data on every page load.
|
|
16
|
-
*
|
|
17
|
-
* Status: BETA
|
|
18
|
-
*/
|
|
19
|
-
module.exports = function (store, _) {
|
|
20
|
-
var _set = _.set,
|
|
21
|
-
_get = _.get,
|
|
22
|
-
_remove = _.remove,
|
|
23
|
-
_key = _.key,
|
|
24
|
-
_length = _.length,
|
|
25
|
-
_clear = _.clear;
|
|
26
|
-
_.overflow = function (area, create) {
|
|
27
|
-
var name = area === _.areas.local ? '+local+' : area === _.areas.session ? '+session+' : false;
|
|
28
|
-
if (name) {
|
|
29
|
-
var overflow = _.areas[name];
|
|
30
|
-
if (create && !overflow) {
|
|
31
|
-
overflow = store.area(name)._area; // area() copies to _.areas
|
|
32
|
-
} else if (create === false) {
|
|
33
|
-
delete _.areas[name];
|
|
34
|
-
delete store[name];
|
|
35
|
-
}
|
|
36
|
-
return overflow;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
_.set = function (area, key, string) {
|
|
40
|
-
try {
|
|
41
|
-
_set.apply(this, arguments);
|
|
42
|
-
} catch (e) {
|
|
43
|
-
if (e.name === 'QUOTA_EXCEEDED_ERR' || e.name === 'NS_ERROR_DOM_QUOTA_REACHED' || e.toString().indexOf("QUOTA_EXCEEDED_ERR") !== -1 || e.toString().indexOf("QuotaExceededError") !== -1) {
|
|
44
|
-
// the e.toString is needed for IE9 / IE10, cos name is empty there
|
|
45
|
-
return _.set(_.overflow(area, true), key, string);
|
|
46
|
-
}
|
|
47
|
-
throw e;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
_.get = function (area, key) {
|
|
51
|
-
var overflow = _.overflow(area);
|
|
52
|
-
return overflow && _get.call(this, overflow, key) || _get.apply(this, arguments);
|
|
53
|
-
};
|
|
54
|
-
_.remove = function (area, key) {
|
|
55
|
-
var overflow = _.overflow(area);
|
|
56
|
-
if (overflow) {
|
|
57
|
-
_remove.call(this, overflow, key);
|
|
58
|
-
}
|
|
59
|
-
_remove.apply(this, arguments);
|
|
60
|
-
};
|
|
61
|
-
_.key = function (area, i) {
|
|
62
|
-
var overflow = _.overflow(area);
|
|
63
|
-
if (overflow) {
|
|
64
|
-
var l = _length.call(this, area);
|
|
65
|
-
if (i >= l) {
|
|
66
|
-
i = i - l; // make i overflow-relative
|
|
67
|
-
for (var j = 0, m = _length.call(this, overflow); j < m; j++) {
|
|
68
|
-
if (j === i) {
|
|
69
|
-
// j is overflow index
|
|
70
|
-
return _key.call(this, overflow, j);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return _key.apply(this, arguments);
|
|
76
|
-
};
|
|
77
|
-
_.length = function (area) {
|
|
78
|
-
var length = _length(area),
|
|
79
|
-
overflow = _.overflow(area);
|
|
80
|
-
return overflow ? length + _length(overflow) : length;
|
|
81
|
-
};
|
|
82
|
-
_.clear = function (area) {
|
|
83
|
-
_.overflow(area, false);
|
|
84
|
-
_clear.apply(this, arguments);
|
|
85
|
-
};
|
|
86
|
-
};
|
package/lib/utils/store_old.js
DELETED