@constructor-io/constructorio-client-javascript 2.21.0 → 2.25.2
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/README.md +6 -1
- package/lib/constructorio.js +38 -33
- package/lib/modules/autocomplete.js +5 -7
- package/lib/modules/browse.js +23 -17
- package/lib/modules/recommendations.js +5 -7
- package/lib/modules/search.js +6 -7
- package/lib/modules/tracker.js +154 -121
- package/lib/utils/event-dispatcher.js +5 -7
- package/lib/utils/helpers.js +21 -6
- package/lib/utils/humanity-check.js +16 -9
- package/lib/utils/request-queue.js +98 -92
- package/package.json +20 -15
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
8
8
|
|
|
9
9
|
/* eslint-disable class-methods-use-this */
|
|
10
10
|
var store = require('../utils/store');
|
|
@@ -20,9 +20,8 @@ var HumanityCheck = /*#__PURE__*/function () {
|
|
|
20
20
|
function HumanityCheck() {
|
|
21
21
|
var _this = this;
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
this.isHumanBoolean = !!store.session.get(storageKey) || false; // Humanity proved, remove handlers to prove humanity
|
|
23
|
+
(0, _classCallCheck2["default"])(this, HumanityCheck);
|
|
24
|
+
this.isHumanBoolean = this.getIsHumanFromSessionStorage(); // Humanity proved, remove handlers to prove humanity
|
|
26
25
|
|
|
27
26
|
var remove = function remove() {
|
|
28
27
|
_this.isHumanBoolean = true;
|
|
@@ -38,10 +37,15 @@ var HumanityCheck = /*#__PURE__*/function () {
|
|
|
38
37
|
helpers.addEventListener(eventType, remove, true);
|
|
39
38
|
});
|
|
40
39
|
}
|
|
41
|
-
}
|
|
40
|
+
}
|
|
42
41
|
|
|
42
|
+
(0, _createClass2["default"])(HumanityCheck, [{
|
|
43
|
+
key: "getIsHumanFromSessionStorage",
|
|
44
|
+
value: function getIsHumanFromSessionStorage() {
|
|
45
|
+
return !!store.session.get(storageKey) || false;
|
|
46
|
+
} // Return boolean indicating if is human
|
|
43
47
|
|
|
44
|
-
|
|
48
|
+
}, {
|
|
45
49
|
key: "isHuman",
|
|
46
50
|
value: function isHuman() {
|
|
47
51
|
return this.isHumanBoolean || !!store.session.get(storageKey);
|
|
@@ -50,6 +54,10 @@ var HumanityCheck = /*#__PURE__*/function () {
|
|
|
50
54
|
}, {
|
|
51
55
|
key: "isBot",
|
|
52
56
|
value: function isBot() {
|
|
57
|
+
if (this.getIsHumanFromSessionStorage()) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
53
61
|
var _helpers$getNavigator = helpers.getNavigator(),
|
|
54
62
|
userAgent = _helpers$getNavigator.userAgent,
|
|
55
63
|
webdriver = _helpers$getNavigator.webdriver;
|
|
@@ -58,7 +66,6 @@ var HumanityCheck = /*#__PURE__*/function () {
|
|
|
58
66
|
return Boolean(userAgent.match(botRegex)) || Boolean(webdriver);
|
|
59
67
|
}
|
|
60
68
|
}]);
|
|
61
|
-
|
|
62
69
|
return HumanityCheck;
|
|
63
70
|
}();
|
|
64
71
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
8
8
|
|
|
9
9
|
/* eslint-disable brace-style, no-unneeded-ternary */
|
|
10
10
|
var fetchPonyfill = require('fetch-ponyfill');
|
|
@@ -23,8 +23,7 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
23
23
|
function RequestQueue(options, eventemitter) {
|
|
24
24
|
var _this = this;
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
(0, _classCallCheck2["default"])(this, RequestQueue);
|
|
28
27
|
this.options = options;
|
|
29
28
|
this.eventemitter = eventemitter;
|
|
30
29
|
this.humanity = new HumanityCheck();
|
|
@@ -43,7 +42,7 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
43
42
|
} // Add request to queue to be dispatched
|
|
44
43
|
|
|
45
44
|
|
|
46
|
-
|
|
45
|
+
(0, _createClass2["default"])(RequestQueue, [{
|
|
47
46
|
key: "queue",
|
|
48
47
|
value: function queue(url) {
|
|
49
48
|
var method = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'GET';
|
|
@@ -60,104 +59,112 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
60
59
|
});
|
|
61
60
|
RequestQueue.set(queue);
|
|
62
61
|
}
|
|
63
|
-
} // Read from queue and send
|
|
62
|
+
} // Read from queue and send events to server
|
|
64
63
|
|
|
65
64
|
}, {
|
|
66
|
-
key: "
|
|
67
|
-
value: function
|
|
65
|
+
key: "sendEvents",
|
|
66
|
+
value: function sendEvents() {
|
|
68
67
|
var _this2 = this;
|
|
69
68
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
69
|
+
var fetch = this.options && this.options.fetch || fetchPonyfill({
|
|
70
|
+
Promise: Promise
|
|
71
|
+
}).fetch;
|
|
72
|
+
var queue = RequestQueue.get();
|
|
73
|
+
|
|
74
|
+
if ( // Consider user "human" if no DOM context is available
|
|
75
|
+
(!helpers.canUseDOM() || this.humanity.isHuman()) && !this.requestPending && !this.pageUnloading && queue.length) {
|
|
76
|
+
var request;
|
|
77
|
+
var nextInQueue = queue.shift();
|
|
78
|
+
var _nextInQueue = nextInQueue,
|
|
79
|
+
networkParameters = _nextInQueue.networkParameters;
|
|
80
|
+
var signal;
|
|
81
|
+
|
|
82
|
+
if (networkParameters) {
|
|
83
|
+
var controller = new AbortController();
|
|
84
|
+
signal = controller.signal;
|
|
85
|
+
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
RequestQueue.set(queue); // Backwards compatibility with versions <= 2.0.0, can be removed in future
|
|
89
|
+
// - Request queue entries used to be strings with 'GET' method assumed
|
|
90
|
+
|
|
91
|
+
if (typeof nextInQueue === 'string') {
|
|
92
|
+
nextInQueue = {
|
|
93
|
+
url: nextInQueue,
|
|
94
|
+
method: 'GET'
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (nextInQueue.method === 'GET') {
|
|
99
|
+
request = fetch(nextInQueue.url, {
|
|
100
|
+
signal: signal
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (nextInQueue.method === 'POST') {
|
|
105
|
+
request = fetch(nextInQueue.url, {
|
|
106
|
+
method: nextInQueue.method,
|
|
107
|
+
body: JSON.stringify(nextInQueue.body),
|
|
108
|
+
mode: 'cors',
|
|
109
|
+
headers: {
|
|
110
|
+
'Content-Type': 'text/plain'
|
|
111
|
+
},
|
|
112
|
+
signal: signal
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (request) {
|
|
117
|
+
this.requestPending = true;
|
|
118
|
+
var instance = this;
|
|
119
|
+
request.then(function (response) {
|
|
120
|
+
// Request was successful, and returned a 2XX status code
|
|
121
|
+
if (response.ok) {
|
|
122
|
+
instance.eventemitter.emit('success', {
|
|
123
|
+
url: nextInQueue.url,
|
|
110
124
|
method: nextInQueue.method,
|
|
111
|
-
|
|
112
|
-
mode: 'cors',
|
|
113
|
-
headers: {
|
|
114
|
-
'Content-Type': 'text/plain'
|
|
115
|
-
},
|
|
116
|
-
signal: signal
|
|
125
|
+
message: 'ok'
|
|
117
126
|
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
instance.eventemitter.emit('success', {
|
|
127
|
-
url: nextInQueue.url,
|
|
128
|
-
method: nextInQueue.method,
|
|
129
|
-
message: 'ok'
|
|
130
|
-
});
|
|
131
|
-
} // Request was successful, but returned a non-2XX status code
|
|
132
|
-
else {
|
|
133
|
-
response.json().then(function (json) {
|
|
134
|
-
instance.eventemitter.emit('error', {
|
|
135
|
-
url: nextInQueue.url,
|
|
136
|
-
method: nextInQueue.method,
|
|
137
|
-
message: json && json.message
|
|
138
|
-
});
|
|
139
|
-
})["catch"](function (error) {
|
|
140
|
-
instance.eventemitter.emit('error', {
|
|
141
|
-
url: nextInQueue.url,
|
|
142
|
-
method: nextInQueue.method,
|
|
143
|
-
message: error.type
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
}
|
|
127
|
+
} // Request was successful, but returned a non-2XX status code
|
|
128
|
+
else {
|
|
129
|
+
response.json().then(function (json) {
|
|
130
|
+
instance.eventemitter.emit('error', {
|
|
131
|
+
url: nextInQueue.url,
|
|
132
|
+
method: nextInQueue.method,
|
|
133
|
+
message: json && json.message
|
|
134
|
+
});
|
|
147
135
|
})["catch"](function (error) {
|
|
148
136
|
instance.eventemitter.emit('error', {
|
|
149
137
|
url: nextInQueue.url,
|
|
150
138
|
method: nextInQueue.method,
|
|
151
|
-
message: error.
|
|
139
|
+
message: error.type
|
|
152
140
|
});
|
|
153
|
-
})["finally"](function () {
|
|
154
|
-
_this2.requestPending = false;
|
|
155
|
-
|
|
156
|
-
_this2.send();
|
|
157
141
|
});
|
|
158
142
|
}
|
|
159
|
-
}
|
|
160
|
-
|
|
143
|
+
})["catch"](function (error) {
|
|
144
|
+
instance.eventemitter.emit('error', {
|
|
145
|
+
url: nextInQueue.url,
|
|
146
|
+
method: nextInQueue.method,
|
|
147
|
+
message: error.toString()
|
|
148
|
+
});
|
|
149
|
+
})["finally"](function () {
|
|
150
|
+
_this2.requestPending = false;
|
|
151
|
+
|
|
152
|
+
_this2.send();
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
} // Read from queue and send requests to server
|
|
157
|
+
|
|
158
|
+
}, {
|
|
159
|
+
key: "send",
|
|
160
|
+
value: function send() {
|
|
161
|
+
if (this.sendTrackingEvents) {
|
|
162
|
+
if (this.options && this.options.trackingSendDelay === 0) {
|
|
163
|
+
this.sendEvents();
|
|
164
|
+
} else {
|
|
165
|
+
// Defer sending of events to give beforeunload time to register (avoids race condition)
|
|
166
|
+
setTimeout(this.sendEvents.bind(this), this.options && this.options.trackingSendDelay || 250);
|
|
167
|
+
}
|
|
161
168
|
}
|
|
162
169
|
} // Return current request queue
|
|
163
170
|
|
|
@@ -173,7 +180,6 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
173
180
|
store.local.set(storageKey, queue);
|
|
174
181
|
}
|
|
175
182
|
}]);
|
|
176
|
-
|
|
177
183
|
return RequestQueue;
|
|
178
184
|
}();
|
|
179
185
|
|
package/package.json
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructor-io/constructorio-client-javascript",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.25.2",
|
|
4
4
|
"description": "Constructor.io JavaScript client",
|
|
5
5
|
"main": "lib/constructorio.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"clean": "sudo rm -rf node_modules package-lock.json",
|
|
8
|
-
"version": "chmod +x ./scripts/verify-node-version.sh && ./scripts/verify-node-version.sh && npm run docs && git add ./docs/*",
|
|
8
|
+
"version": "chmod +x ./scripts/verify-node-version.sh && ./scripts/verify-node-version.sh && npm run docs && git add ./docs/* && npm run bundle && git add -A ./dist",
|
|
9
9
|
"check-lisc": "license-checker --production --onlyAllow 'Apache-2.0;BSD-3-Clause;MIT'",
|
|
10
10
|
"lint": "eslint 'src/**/*.js' 'spec/**/*.js'",
|
|
11
|
-
"test": "npm run compile && mkdir -p test && cp -rf lib/* test && mocha ./spec/*
|
|
12
|
-
"test:src": "mkdir -p test && cp -rf src/* test && mocha ./spec/*
|
|
11
|
+
"test": "npm run compile && mkdir -p test && cp -rf lib/* test && mocha ./spec/*",
|
|
12
|
+
"test:src": "mkdir -p test && cp -rf src/* test && mocha ./spec/*",
|
|
13
|
+
"test:bundled": "npm run bundle && BUNDLED=true PACKAGE_VERSION=$(echo $npm_package_version) mocha ./spec/*",
|
|
14
|
+
"test:all": "npm run test && npm run test:bundled",
|
|
13
15
|
"precoverage": "rm -rf ./coverage && rm -rf ./.nyc_output",
|
|
14
16
|
"coverage": "nyc --all --reporter=html npm run test:src",
|
|
15
17
|
"postcoverage": "serve --listen 8080 --config ./serve.json && rm -rf test",
|
|
16
18
|
"docs": "jsdoc --configure ./.jsdoc.json ./README.md --recurse ./src --destination ./docs",
|
|
17
|
-
"compile": "babel -d lib/
|
|
18
|
-
"prepublish": "npm run compile"
|
|
19
|
+
"compile": "babel src/ -d lib/",
|
|
20
|
+
"prepublish": "npm run compile",
|
|
21
|
+
"bundle": "rm -rf ./dist/* && npm run compile && node bundle.js"
|
|
19
22
|
},
|
|
20
23
|
"repository": {
|
|
21
24
|
"type": "git",
|
|
@@ -34,26 +37,28 @@
|
|
|
34
37
|
"lib/**/*"
|
|
35
38
|
],
|
|
36
39
|
"devDependencies": {
|
|
37
|
-
"@babel/cli": "^7.
|
|
38
|
-
"@babel/core": "^7.
|
|
39
|
-
"@babel/
|
|
40
|
-
"@babel/
|
|
40
|
+
"@babel/cli": "^7.15.7",
|
|
41
|
+
"@babel/core": "^7.15.8",
|
|
42
|
+
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
43
|
+
"@babel/preset-env": "^7.15.8",
|
|
44
|
+
"@babel/register": "^7.15.3",
|
|
41
45
|
"chai": "^4.2.0",
|
|
42
46
|
"chai-as-promised": "^7.1.1",
|
|
43
47
|
"dotenv": "^8.6.0",
|
|
44
|
-
"
|
|
48
|
+
"esbuild": "^0.12.28",
|
|
49
|
+
"eslint": "^8.0.1",
|
|
45
50
|
"eslint-config-airbnb-base": "^13.1.0",
|
|
46
|
-
"eslint-plugin-import": "^2.
|
|
51
|
+
"eslint-plugin-import": "^2.25.2",
|
|
47
52
|
"jsdoc": "^3.6.7",
|
|
48
53
|
"jsdom": "^15.1.1",
|
|
49
54
|
"license-checker": "^25.0.1",
|
|
50
55
|
"lodash.clonedeep": "^4.5.0",
|
|
51
56
|
"minami": "^1.2.3",
|
|
52
|
-
"mocha": "^
|
|
57
|
+
"mocha": "^9.1.3",
|
|
53
58
|
"mocha-jsdom": "^2.0.0",
|
|
54
|
-
"nyc": "^
|
|
59
|
+
"nyc": "^15.1.0",
|
|
55
60
|
"pre-push": "^0.1.1",
|
|
56
|
-
"serve": "^
|
|
61
|
+
"serve": "^13.0.2",
|
|
57
62
|
"sinon": "^7.5.0",
|
|
58
63
|
"sinon-chai": "^3.7.0"
|
|
59
64
|
},
|