@constructor-io/constructorio-client-javascript 2.36.4 → 2.37.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/lib/constructorio.js +36 -60
- package/lib/modules/autocomplete.js +40 -55
- package/lib/modules/browse.js +86 -130
- package/lib/modules/quizzes.js +39 -60
- package/lib/modules/recommendations.js +38 -52
- package/lib/modules/search.js +66 -91
- package/lib/modules/tracker.js +430 -656
- package/lib/types/types.d.ts +126 -0
- package/lib/utils/botlist.js +1 -1
- package/lib/utils/event-dispatcher.js +14 -20
- package/lib/utils/events.js +29 -95
- package/lib/utils/helpers.js +42 -22
- package/lib/utils/humanity-check.js +10 -19
- package/lib/utils/request-queue.js +32 -45
- package/lib/utils/store.js +2 -3
- package/lib/utils/store.overflow.js +6 -27
- package/package.json +1 -1
|
@@ -1,72 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
6
|
-
|
|
7
5
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
8
|
-
|
|
9
6
|
/* eslint-disable class-methods-use-this */
|
|
10
7
|
var store = require('./store');
|
|
11
|
-
|
|
12
8
|
var botList = require('./botlist');
|
|
13
|
-
|
|
14
9
|
var helpers = require('./helpers');
|
|
15
|
-
|
|
16
10
|
var storageKey = '_constructorio_is_human';
|
|
17
11
|
var humanEvents = ['scroll', 'resize', 'touchmove', 'mouseover', 'mousemove', 'keydown', 'keypress', 'keyup', 'focus'];
|
|
18
|
-
|
|
19
12
|
var HumanityCheck = /*#__PURE__*/function () {
|
|
20
13
|
function HumanityCheck() {
|
|
21
14
|
var _this = this;
|
|
22
|
-
|
|
23
15
|
(0, _classCallCheck2["default"])(this, HumanityCheck);
|
|
24
|
-
this.isHumanBoolean = this.getIsHumanFromSessionStorage();
|
|
16
|
+
this.isHumanBoolean = this.getIsHumanFromSessionStorage();
|
|
25
17
|
|
|
18
|
+
// Humanity proved, remove handlers to prove humanity
|
|
26
19
|
var remove = function remove() {
|
|
27
20
|
_this.isHumanBoolean = true;
|
|
28
21
|
store.session.set(storageKey, true);
|
|
29
22
|
humanEvents.forEach(function (eventType) {
|
|
30
23
|
helpers.removeEventListener(eventType, remove, true);
|
|
31
24
|
});
|
|
32
|
-
};
|
|
33
|
-
|
|
25
|
+
};
|
|
34
26
|
|
|
27
|
+
// Add handlers to prove humanity
|
|
35
28
|
if (!this.isHumanBoolean) {
|
|
36
29
|
humanEvents.forEach(function (eventType) {
|
|
37
30
|
helpers.addEventListener(eventType, remove, true);
|
|
38
31
|
});
|
|
39
32
|
}
|
|
40
33
|
}
|
|
41
|
-
|
|
42
34
|
(0, _createClass2["default"])(HumanityCheck, [{
|
|
43
35
|
key: "getIsHumanFromSessionStorage",
|
|
44
36
|
value: function getIsHumanFromSessionStorage() {
|
|
45
37
|
return !!store.session.get(storageKey) || false;
|
|
46
|
-
}
|
|
38
|
+
}
|
|
47
39
|
|
|
40
|
+
// Return boolean indicating if is human
|
|
48
41
|
}, {
|
|
49
42
|
key: "isHuman",
|
|
50
43
|
value: function isHuman() {
|
|
51
44
|
return this.isHumanBoolean || !!store.session.get(storageKey);
|
|
52
|
-
}
|
|
45
|
+
}
|
|
53
46
|
|
|
47
|
+
// Return boolean indicating if useragent matches botlist
|
|
54
48
|
}, {
|
|
55
49
|
key: "isBot",
|
|
56
50
|
value: function isBot() {
|
|
57
51
|
if (this.getIsHumanFromSessionStorage()) {
|
|
58
52
|
return false;
|
|
59
53
|
}
|
|
60
|
-
|
|
61
54
|
var _helpers$getNavigator = helpers.getNavigator(),
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
userAgent = _helpers$getNavigator.userAgent,
|
|
56
|
+
webdriver = _helpers$getNavigator.webdriver;
|
|
65
57
|
var botRegex = new RegExp("(".concat(botList.join('|'), ")"));
|
|
66
58
|
return Boolean(userAgent.match(botRegex)) || Boolean(webdriver);
|
|
67
59
|
}
|
|
68
60
|
}]);
|
|
69
61
|
return HumanityCheck;
|
|
70
62
|
}();
|
|
71
|
-
|
|
72
63
|
module.exports = HumanityCheck;
|
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
6
|
-
|
|
7
5
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
8
|
-
|
|
9
6
|
/* eslint-disable brace-style, no-unneeded-ternary */
|
|
10
7
|
var store = require('./store');
|
|
11
|
-
|
|
12
8
|
var HumanityCheck = require('./humanity-check');
|
|
13
|
-
|
|
14
9
|
var helpers = require('./helpers');
|
|
15
|
-
|
|
10
|
+
var _require = require('./helpers'),
|
|
11
|
+
requestContainsPii = _require.requestContainsPii;
|
|
16
12
|
var storageKey = '_constructorio_requests';
|
|
17
13
|
var requestTTL = 180000; // 3 minutes in milliseconds
|
|
18
|
-
|
|
19
14
|
var RequestQueue = /*#__PURE__*/function () {
|
|
20
15
|
function RequestQueue(options, eventemitter) {
|
|
21
16
|
var _this = this;
|
|
22
|
-
|
|
23
17
|
(0, _classCallCheck2["default"])(this, RequestQueue);
|
|
24
18
|
this.options = options;
|
|
25
19
|
this.eventemitter = eventemitter;
|
|
@@ -27,26 +21,27 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
27
21
|
this.requestPending = false;
|
|
28
22
|
this.pageUnloading = false;
|
|
29
23
|
this.sendTrackingEvents = options && options.sendTrackingEvents === true ? true : false; // Defaults to 'false'
|
|
30
|
-
// Mark if page environment is unloading
|
|
31
24
|
|
|
25
|
+
// Mark if page environment is unloading
|
|
32
26
|
helpers.addEventListener('beforeunload', function () {
|
|
33
27
|
_this.pageUnloading = true;
|
|
34
28
|
});
|
|
35
|
-
|
|
36
29
|
if (this.sendTrackingEvents) {
|
|
37
30
|
this.send();
|
|
38
31
|
}
|
|
39
|
-
}
|
|
40
|
-
|
|
32
|
+
}
|
|
41
33
|
|
|
34
|
+
// Add request to queue to be dispatched
|
|
42
35
|
(0, _createClass2["default"])(RequestQueue, [{
|
|
43
36
|
key: "queue",
|
|
44
37
|
value: function queue(url) {
|
|
45
38
|
var method = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'GET';
|
|
46
39
|
var body = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
47
40
|
var networkParameters = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
48
|
-
|
|
49
41
|
if (this.sendTrackingEvents && !this.humanity.isBot()) {
|
|
42
|
+
if (requestContainsPii(url, body)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
50
45
|
var queue = RequestQueue.get();
|
|
51
46
|
queue.push({
|
|
52
47
|
url: url,
|
|
@@ -56,63 +51,59 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
56
51
|
});
|
|
57
52
|
RequestQueue.set(queue);
|
|
58
53
|
}
|
|
59
|
-
}
|
|
54
|
+
}
|
|
60
55
|
|
|
56
|
+
// Read from queue and send events to server
|
|
61
57
|
}, {
|
|
62
58
|
key: "sendEvents",
|
|
63
59
|
value: function sendEvents() {
|
|
64
60
|
var _this2 = this;
|
|
65
|
-
|
|
66
61
|
var fetch = this.options.fetch;
|
|
67
62
|
var queue = RequestQueue.get();
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
if (
|
|
64
|
+
// Consider user "human" if no DOM context is available
|
|
70
65
|
(!helpers.canUseDOM() || this.humanity.isHuman()) && !this.requestPending && !this.pageUnloading && queue.length) {
|
|
71
66
|
var request;
|
|
72
67
|
var nextInQueue = queue.shift();
|
|
73
68
|
var _nextInQueue = nextInQueue,
|
|
74
|
-
|
|
69
|
+
networkParameters = _nextInQueue.networkParameters;
|
|
75
70
|
var signal;
|
|
76
71
|
var instance = this;
|
|
77
72
|
RequestQueue.set(queue);
|
|
78
|
-
|
|
79
73
|
if (networkParameters && typeof AbortController === 'function') {
|
|
80
74
|
var controller = new AbortController();
|
|
81
75
|
signal = controller.signal;
|
|
82
76
|
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
83
|
-
}
|
|
84
|
-
// - Request queue entries used to be strings with 'GET' method assumed
|
|
85
|
-
|
|
77
|
+
}
|
|
86
78
|
|
|
79
|
+
// Backwards compatibility with versions <= 2.0.0, can be removed in future
|
|
80
|
+
// - Request queue entries used to be strings with 'GET' method assumed
|
|
87
81
|
if (typeof nextInQueue === 'string') {
|
|
88
82
|
nextInQueue = {
|
|
89
83
|
url: nextInQueue,
|
|
90
84
|
method: 'GET'
|
|
91
85
|
};
|
|
92
|
-
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// If events older than `requestTTL` exist in queue, clear request queue
|
|
93
89
|
// - Prevents issue where stale items are sent in perpetuity
|
|
94
90
|
// - No request should go unsent for longer than `requestTTL`
|
|
95
|
-
|
|
96
|
-
|
|
97
91
|
if (nextInQueue.url) {
|
|
98
92
|
// Pull `dt` parameter from URL, indicating origin time of request
|
|
99
93
|
var dtMatch = nextInQueue.url.match(/\?.*_dt=([^&]+)/);
|
|
100
94
|
var requestOriginTime = parseInt(dtMatch && dtMatch[1], 10);
|
|
101
95
|
var now = +new Date();
|
|
102
|
-
|
|
103
96
|
if (requestOriginTime && Number.isInteger(requestOriginTime) && now - requestOriginTime > requestTTL) {
|
|
104
97
|
this.sendTrackingEvents = false;
|
|
105
98
|
RequestQueue.remove();
|
|
106
99
|
return;
|
|
107
100
|
}
|
|
108
101
|
}
|
|
109
|
-
|
|
110
102
|
if (nextInQueue.method === 'GET') {
|
|
111
103
|
request = fetch(nextInQueue.url, {
|
|
112
104
|
signal: signal
|
|
113
105
|
});
|
|
114
106
|
}
|
|
115
|
-
|
|
116
107
|
if (nextInQueue.method === 'POST') {
|
|
117
108
|
request = fetch(nextInQueue.url, {
|
|
118
109
|
method: nextInQueue.method,
|
|
@@ -124,7 +115,6 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
124
115
|
signal: signal
|
|
125
116
|
});
|
|
126
117
|
}
|
|
127
|
-
|
|
128
118
|
if (request) {
|
|
129
119
|
this.requestPending = true;
|
|
130
120
|
request.then(function (response) {
|
|
@@ -137,11 +127,11 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
137
127
|
message: 'ok'
|
|
138
128
|
});
|
|
139
129
|
}
|
|
140
|
-
|
|
141
130
|
_this2.requestPending = false;
|
|
142
|
-
|
|
143
131
|
_this2.send();
|
|
144
|
-
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Request was successful, but returned a non-2XX status code
|
|
145
135
|
else {
|
|
146
136
|
response.json().then(function (json) {
|
|
147
137
|
if (instance.eventemitter) {
|
|
@@ -151,9 +141,7 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
151
141
|
message: json && json.message
|
|
152
142
|
});
|
|
153
143
|
}
|
|
154
|
-
|
|
155
144
|
_this2.requestPending = false;
|
|
156
|
-
|
|
157
145
|
_this2.send();
|
|
158
146
|
})["catch"](function (error) {
|
|
159
147
|
if (instance.eventemitter) {
|
|
@@ -163,9 +151,7 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
163
151
|
message: error.type
|
|
164
152
|
});
|
|
165
153
|
}
|
|
166
|
-
|
|
167
154
|
_this2.requestPending = false;
|
|
168
|
-
|
|
169
155
|
_this2.send();
|
|
170
156
|
});
|
|
171
157
|
}
|
|
@@ -177,15 +163,14 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
177
163
|
message: error && error.toString && error.toString()
|
|
178
164
|
});
|
|
179
165
|
}
|
|
180
|
-
|
|
181
166
|
_this2.requestPending = false;
|
|
182
|
-
|
|
183
167
|
_this2.send();
|
|
184
168
|
});
|
|
185
169
|
}
|
|
186
170
|
}
|
|
187
|
-
}
|
|
171
|
+
}
|
|
188
172
|
|
|
173
|
+
// Read from queue and send requests to server
|
|
189
174
|
}, {
|
|
190
175
|
key: "send",
|
|
191
176
|
value: function send() {
|
|
@@ -197,14 +182,16 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
197
182
|
setTimeout(this.sendEvents.bind(this), this.options && this.options.trackingSendDelay || 250);
|
|
198
183
|
}
|
|
199
184
|
}
|
|
200
|
-
}
|
|
185
|
+
}
|
|
201
186
|
|
|
187
|
+
// Return current request queue
|
|
202
188
|
}], [{
|
|
203
189
|
key: "get",
|
|
204
190
|
value: function get() {
|
|
205
191
|
return store.local.get(storageKey) || [];
|
|
206
|
-
}
|
|
192
|
+
}
|
|
207
193
|
|
|
194
|
+
// Update current request queue
|
|
208
195
|
}, {
|
|
209
196
|
key: "set",
|
|
210
197
|
value: function set(queue) {
|
|
@@ -214,17 +201,18 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
214
201
|
} else {
|
|
215
202
|
store.local.set(storageKey, queue);
|
|
216
203
|
}
|
|
204
|
+
var localStorageQueue = RequestQueue.get();
|
|
217
205
|
|
|
218
|
-
|
|
206
|
+
// Ensure storage queue was set correctly in storage by checking length
|
|
219
207
|
// - Otherwise remove all pending requests as preventative measure
|
|
220
208
|
// - Firefox seeing identical events being transmitted multiple times
|
|
221
|
-
|
|
222
209
|
if (Array.isArray(localStorageQueue) && localStorageQueue.length !== queue.length) {
|
|
223
210
|
this.sendTrackingEvents = false;
|
|
224
211
|
RequestQueue.remove();
|
|
225
212
|
}
|
|
226
|
-
}
|
|
213
|
+
}
|
|
227
214
|
|
|
215
|
+
// Remove current request queue key
|
|
228
216
|
}, {
|
|
229
217
|
key: "remove",
|
|
230
218
|
value: function remove() {
|
|
@@ -233,5 +221,4 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
233
221
|
}]);
|
|
234
222
|
return RequestQueue;
|
|
235
223
|
}();
|
|
236
|
-
|
|
237
224
|
module.exports = RequestQueue;
|
package/lib/utils/store.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var store = require('store2');
|
|
4
|
+
var overflow = require('./store.overflow');
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
// Inject overflow into store
|
|
6
7
|
// https://raw.githubusercontent.com/nbubna/store/master/src/store.overflow.js
|
|
7
|
-
|
|
8
|
-
|
|
9
8
|
overflow(store, store._);
|
|
10
9
|
module.exports = store;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
/* eslint-disable */
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* Copyright (c) 2013 ESHA Research
|
|
7
6
|
* Dual licensed under the MIT and GPL licenses:
|
|
@@ -19,29 +18,24 @@
|
|
|
19
18
|
*/
|
|
20
19
|
module.exports = function (store, _) {
|
|
21
20
|
var _set = _.set,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
_get = _.get,
|
|
22
|
+
_remove = _.remove,
|
|
23
|
+
_key = _.key,
|
|
24
|
+
_length = _.length,
|
|
25
|
+
_clear = _.clear;
|
|
28
26
|
_.overflow = function (area, create) {
|
|
29
27
|
var name = area === _.areas.local ? '+local+' : area === _.areas.session ? '+session+' : false;
|
|
30
|
-
|
|
31
28
|
if (name) {
|
|
32
29
|
var overflow = _.areas[name];
|
|
33
|
-
|
|
34
30
|
if (create && !overflow) {
|
|
35
31
|
overflow = store.area(name)._area; // area() copies to _.areas
|
|
36
32
|
} else if (create === false) {
|
|
37
33
|
delete _.areas[name];
|
|
38
34
|
delete store[name];
|
|
39
35
|
}
|
|
40
|
-
|
|
41
36
|
return overflow;
|
|
42
37
|
}
|
|
43
38
|
};
|
|
44
|
-
|
|
45
39
|
_.set = function (area, key, string) {
|
|
46
40
|
try {
|
|
47
41
|
_set.apply(this, arguments);
|
|
@@ -50,36 +44,26 @@ module.exports = function (store, _) {
|
|
|
50
44
|
// the e.toString is needed for IE9 / IE10, cos name is empty there
|
|
51
45
|
return _.set(_.overflow(area, true), key, string);
|
|
52
46
|
}
|
|
53
|
-
|
|
54
47
|
throw e;
|
|
55
48
|
}
|
|
56
49
|
};
|
|
57
|
-
|
|
58
50
|
_.get = function (area, key) {
|
|
59
51
|
var overflow = _.overflow(area);
|
|
60
|
-
|
|
61
52
|
return overflow && _get.call(this, overflow, key) || _get.apply(this, arguments);
|
|
62
53
|
};
|
|
63
|
-
|
|
64
54
|
_.remove = function (area, key) {
|
|
65
55
|
var overflow = _.overflow(area);
|
|
66
|
-
|
|
67
56
|
if (overflow) {
|
|
68
57
|
_remove.call(this, overflow, key);
|
|
69
58
|
}
|
|
70
|
-
|
|
71
59
|
_remove.apply(this, arguments);
|
|
72
60
|
};
|
|
73
|
-
|
|
74
61
|
_.key = function (area, i) {
|
|
75
62
|
var overflow = _.overflow(area);
|
|
76
|
-
|
|
77
63
|
if (overflow) {
|
|
78
64
|
var l = _length.call(this, area);
|
|
79
|
-
|
|
80
65
|
if (i >= l) {
|
|
81
66
|
i = i - l; // make i overflow-relative
|
|
82
|
-
|
|
83
67
|
for (var j = 0, m = _length.call(this, overflow); j < m; j++) {
|
|
84
68
|
if (j === i) {
|
|
85
69
|
// j is overflow index
|
|
@@ -88,20 +72,15 @@ module.exports = function (store, _) {
|
|
|
88
72
|
}
|
|
89
73
|
}
|
|
90
74
|
}
|
|
91
|
-
|
|
92
75
|
return _key.apply(this, arguments);
|
|
93
76
|
};
|
|
94
|
-
|
|
95
77
|
_.length = function (area) {
|
|
96
78
|
var length = _length(area),
|
|
97
|
-
|
|
98
|
-
|
|
79
|
+
overflow = _.overflow(area);
|
|
99
80
|
return overflow ? length + _length(overflow) : length;
|
|
100
81
|
};
|
|
101
|
-
|
|
102
82
|
_.clear = function (area) {
|
|
103
83
|
_.overflow(area, false);
|
|
104
|
-
|
|
105
84
|
_clear.apply(this, arguments);
|
|
106
85
|
};
|
|
107
86
|
};
|