@constructor-io/constructorio-client-javascript 2.29.11 → 2.29.13
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/.DS_Store +0 -0
- package/lib/modules/quizzes.js +232 -0
- package/lib/modules/recommendations.js +1 -1
- package/lib/utils/botlist.js +2 -0
- package/lib/utils/request-queue.js +1 -1
- package/package.json +5 -1
package/lib/.DS_Store
ADDED
|
Binary file
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
6
|
+
|
|
7
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
8
|
+
|
|
9
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
10
|
+
|
|
11
|
+
/* eslint-disable object-curly-newline, no-underscore-dangle */
|
|
12
|
+
var qs = require('qs');
|
|
13
|
+
|
|
14
|
+
var fetchPonyfill = require('fetch-ponyfill');
|
|
15
|
+
|
|
16
|
+
var Promise = require('es6-promise');
|
|
17
|
+
|
|
18
|
+
var EventDispatcher = require('../utils/event-dispatcher');
|
|
19
|
+
|
|
20
|
+
var helpers = require('../utils/helpers'); // Create URL from supplied quizId and parameters
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
function createQuizUrl(quizId, parameters, options, path) {
|
|
24
|
+
var apiKey = options.apiKey,
|
|
25
|
+
clientId = options.clientId,
|
|
26
|
+
sessionId = options.sessionId,
|
|
27
|
+
segments = options.segments,
|
|
28
|
+
userId = options.userId,
|
|
29
|
+
version = options.version;
|
|
30
|
+
var serviceUrl = 'https://quizzes.cnstrc.com';
|
|
31
|
+
var queryParams = {
|
|
32
|
+
c: version
|
|
33
|
+
};
|
|
34
|
+
var answersParamString = '';
|
|
35
|
+
queryParams.key = apiKey;
|
|
36
|
+
queryParams.i = clientId;
|
|
37
|
+
queryParams.s = sessionId; // Pull user segments from options
|
|
38
|
+
|
|
39
|
+
if (segments && segments.length) {
|
|
40
|
+
queryParams.us = segments;
|
|
41
|
+
} // Pull user id from options
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
if (userId) {
|
|
45
|
+
queryParams.ui = userId;
|
|
46
|
+
} // Validate quiz id is provided
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
if (!quizId || typeof quizId !== 'string') {
|
|
50
|
+
throw new Error('quizId is a required parameter of type string');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (path === 'finalize' && ((0, _typeof2["default"])(parameters.a) !== 'object' || !Array.isArray(parameters.a) || parameters.a.length === 0)) {
|
|
54
|
+
throw new Error('a is a required parameter of type array');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (parameters) {
|
|
58
|
+
var section = parameters.section,
|
|
59
|
+
a = parameters.a,
|
|
60
|
+
versionId = parameters.versionId; // Pull section from parameters
|
|
61
|
+
|
|
62
|
+
if (section) {
|
|
63
|
+
queryParams.section = section;
|
|
64
|
+
} // Pull version_id from parameters
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
if (versionId) {
|
|
68
|
+
queryParams.version_id = versionId;
|
|
69
|
+
} // Pull a from parameters and transform
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
if (a) {
|
|
73
|
+
a.forEach(function (ans) {
|
|
74
|
+
answersParamString += "&".concat(qs.stringify({
|
|
75
|
+
a: ans
|
|
76
|
+
}, {
|
|
77
|
+
arrayFormat: 'comma'
|
|
78
|
+
}));
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
queryParams._dt = Date.now();
|
|
84
|
+
queryParams = helpers.cleanParams(queryParams);
|
|
85
|
+
var queryString = qs.stringify(queryParams, {
|
|
86
|
+
indices: false
|
|
87
|
+
});
|
|
88
|
+
return "".concat(serviceUrl, "/v1/quizzes/").concat(encodeURIComponent(quizId), "/").concat(encodeURIComponent(path), "/?").concat(queryString).concat(answersParamString);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Interface to quiz related API calls
|
|
92
|
+
*
|
|
93
|
+
* @module quizzes
|
|
94
|
+
* @inner
|
|
95
|
+
* @returns {object}
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
var Quizzes = /*#__PURE__*/function () {
|
|
100
|
+
function Quizzes(options) {
|
|
101
|
+
(0, _classCallCheck2["default"])(this, Quizzes);
|
|
102
|
+
this.options = options || {};
|
|
103
|
+
this.eventDispatcher = new EventDispatcher(options.eventDispatcher);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Retrieve next quiz from api
|
|
107
|
+
*
|
|
108
|
+
* @function getNextQuiz
|
|
109
|
+
* @description Retrieve next quiz from Constructor.io API
|
|
110
|
+
* @param {string} id - The id of the quiz
|
|
111
|
+
* @param {string} [parameters] - Additional parameters to refine result set
|
|
112
|
+
* @param {string} [parameters.section] - Section for customer's product catalog (optional)
|
|
113
|
+
* @param {array} [parameters.a] - An array for answers in the format [[1,2],[1]]
|
|
114
|
+
* @param {string} [parameters.version_id] - Specific version id for the quiz.
|
|
115
|
+
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
116
|
+
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
117
|
+
* @returns {Promise}
|
|
118
|
+
* @see https://quizzes.cnstrc.com/api/#/quizzes/QuizzesController_getNextQuestion
|
|
119
|
+
* @example
|
|
120
|
+
* constructorio.search.getNextQuiz('quizId', {
|
|
121
|
+
* a: [[1,2],[1]],
|
|
122
|
+
* section: "123",
|
|
123
|
+
* version_id: "123"
|
|
124
|
+
* });
|
|
125
|
+
*/
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
(0, _createClass2["default"])(Quizzes, [{
|
|
129
|
+
key: "getNextQuiz",
|
|
130
|
+
value: function getNextQuiz(quizId, parameters) {
|
|
131
|
+
var _this = this;
|
|
132
|
+
|
|
133
|
+
var networkParameters = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
134
|
+
var requestUrl;
|
|
135
|
+
var fetch = this.options && this.options.fetch || fetchPonyfill({
|
|
136
|
+
Promise: Promise
|
|
137
|
+
}).fetch;
|
|
138
|
+
var controller = new AbortController();
|
|
139
|
+
var signal = controller.signal;
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
requestUrl = createQuizUrl(quizId, parameters, this.options, 'next');
|
|
143
|
+
} catch (e) {
|
|
144
|
+
return Promise.reject(e);
|
|
145
|
+
} // Handle network timeout if specified
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
149
|
+
return fetch(requestUrl, {
|
|
150
|
+
signal: signal
|
|
151
|
+
}).then(function (response) {
|
|
152
|
+
if (response.ok) {
|
|
153
|
+
return response.json();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
157
|
+
}).then(function (json) {
|
|
158
|
+
if (json.version_id) {
|
|
159
|
+
_this.eventDispatcher.queue('quizzes.getNextQuiz.completed', json);
|
|
160
|
+
|
|
161
|
+
return json;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
throw new Error('getNextQuiz response data is malformed');
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Retrieves filter expression and recommendation URL from given answers.
|
|
169
|
+
*
|
|
170
|
+
* @function getFinalizeQuiz
|
|
171
|
+
* @description Retrieve quiz recommendation and filter expression from Constructor.io API
|
|
172
|
+
* @param {string} id - The id of the quiz
|
|
173
|
+
* @param {string} [parameters] - Additional parameters to refine result set
|
|
174
|
+
* @param {string} [parameters.section] - Section for customer's product catalog (optional)
|
|
175
|
+
* @param {array} [parameters.a] - An array for answers in the format [[1,2],[1]]
|
|
176
|
+
* @param {string} [parameters.version_id] - Specific version id for the quiz.
|
|
177
|
+
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
178
|
+
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
179
|
+
* @returns {Promise}
|
|
180
|
+
* @see https://quizzes.cnstrc.com/api/#/quizzes/QuizzesController_getQuizResult
|
|
181
|
+
* @example
|
|
182
|
+
* constructorio.search.getFinalizeQuiz('quizId', {
|
|
183
|
+
* a: [[1,2],[1]],
|
|
184
|
+
* section: "123",
|
|
185
|
+
* version_id: "123"
|
|
186
|
+
* });
|
|
187
|
+
*/
|
|
188
|
+
|
|
189
|
+
}, {
|
|
190
|
+
key: "getFinalizeQuiz",
|
|
191
|
+
value: function getFinalizeQuiz(quizId, parameters) {
|
|
192
|
+
var _this2 = this;
|
|
193
|
+
|
|
194
|
+
var networkParameters = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
195
|
+
var requestUrl;
|
|
196
|
+
var fetch = this.options && this.options.fetch || fetchPonyfill({
|
|
197
|
+
Promise: Promise
|
|
198
|
+
}).fetch;
|
|
199
|
+
var controller = new AbortController();
|
|
200
|
+
var signal = controller.signal;
|
|
201
|
+
|
|
202
|
+
try {
|
|
203
|
+
requestUrl = createQuizUrl(quizId, parameters, this.options, 'finalize');
|
|
204
|
+
} catch (e) {
|
|
205
|
+
return Promise.reject(e);
|
|
206
|
+
} // Handle network timeout if specified
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
210
|
+
return fetch(requestUrl, {
|
|
211
|
+
signal: signal
|
|
212
|
+
}).then(function (response) {
|
|
213
|
+
if (response.ok) {
|
|
214
|
+
return response.json();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
218
|
+
}).then(function (json) {
|
|
219
|
+
if (json.version_id) {
|
|
220
|
+
_this2.eventDispatcher.queue('quizzes.getFinalizeQuiz.completed', json);
|
|
221
|
+
|
|
222
|
+
return json;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
throw new Error('getFinalizeQuiz response data is malformed');
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}]);
|
|
229
|
+
return Quizzes;
|
|
230
|
+
}();
|
|
231
|
+
|
|
232
|
+
module.exports = Quizzes;
|
|
@@ -117,7 +117,7 @@ var Recommendations = /*#__PURE__*/function () {
|
|
|
117
117
|
* @param {number} [parameters.numResults] - The number of results to return
|
|
118
118
|
* @param {string} [parameters.section] - The section to return results from
|
|
119
119
|
* @param {string} [parameters.term] - The term to use to refine results (strategy specific)
|
|
120
|
-
* @param {object} [parameters.filters] - Key / value mapping of filters used to refine results
|
|
120
|
+
* @param {object} [parameters.filters] - Key / value mapping of filters used to refine results
|
|
121
121
|
* @param {object} [parameters.variationsMap] - The variations map object to aggregate variations. Please refer to https://docs.constructor.io/rest_api/variations_mapping for details
|
|
122
122
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
123
123
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
package/lib/utils/botlist.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
/* eslint-disable no-useless-escape */
|
|
4
|
+
|
|
5
|
+
/* cspell:disable */
|
|
4
6
|
module.exports = ['Googlebot\/', 'Googlebot-Mobile', 'Googlebot-Image', 'Googlebot-News', 'Googlebot-Video', 'AdsBot-Google([^-]|$)', 'AdsBot-Google-Mobile', 'Feedfetcher-Google', 'Mediapartners-Google', 'Mediapartners \\(Googlebot\\)', 'APIs-Google', 'bingbot', 'Slurp', '[wW]get', 'curl', 'LinkedInBot', 'Python-urllib', 'python-requests', 'libwww', 'httpunit', 'nutch', 'Go-http-client', 'phpcrawl', 'msnbot', 'jyxobot', 'FAST-WebCrawler', 'FAST Enterprise Crawler', 'BIGLOTRON', 'Teoma', 'convera', 'seekbot', 'Gigabot', 'Gigablast', 'exabot', 'ia_archiver', 'GingerCrawler', 'webmon ', 'HTTrack', 'grub\\.org', 'UsineNouvelleCrawler', 'antibot', 'netresearchserver', 'speedy', 'fluffy', 'bibnum\\.bnf', 'findlink', 'msrbot', 'panscient', 'yacybot', 'AISearchBot', 'ips-agent', 'tagoobot', 'MJ12bot', 'woriobot', 'yanga', 'buzzbot', 'mlbot', 'YandexBot', 'yandex\\.com\/bots', 'purebot', 'Linguee Bot', 'CyberPatrol', 'voilabot', 'Baiduspider', 'citeseerxbot', 'spbot', 'twengabot', 'postrank', 'turnitinbot', 'scribdbot', 'page2rss', 'sitebot', 'linkdex', 'Adidxbot', 'blekkobot', 'ezooms', 'dotbot', 'Mail\\.RU_Bot', 'discobot', 'heritrix', 'findthatfile', 'europarchive\\.org', 'NerdByNature\\.Bot', 'sistrix crawler', 'Ahrefs(Bot|SiteAudit)', 'fuelbot', 'CrunchBot', 'centurybot9', 'IndeedBot', 'mappydata', 'woobot', 'ZoominfoBot', 'PrivacyAwareBot', 'Multiviewbot', 'SWIMGBot', 'Grobbot', 'eright', 'Apercite', 'semanticbot', 'Aboundex', 'domaincrawler', 'wbsearchbot', 'summify', 'CCBot', 'edisterbot', 'seznambot', 'ec2linkfinder', 'gslfbot', 'aiHitBot', 'intelium_bot', 'facebookexternalhit', 'Yeti', 'RetrevoPageAnalyzer', 'lb-spider', 'Sogou', 'lssbot', 'careerbot', 'wotbox', 'wocbot', 'ichiro', 'DuckDuckBot', 'lssrocketcrawler', 'drupact', 'webcompanycrawler', 'acoonbot', 'openindexspider', 'gnam gnam spider', 'web-archive-net\\.com\\.bot', 'backlinkcrawler', 'coccoc', 'integromedb', 'content crawler spider', 'toplistbot', 'it2media-domain-crawler', 'ip-web-crawler\\.com', 'siteexplorer\\.info', 'elisabot', 'proximic', 'changedetection', 'arabot', 'WeSEE:Search', 'niki-bot', 'CrystalSemanticsBot', 'rogerbot', '360Spider', 'psbot', 'InterfaxScanBot', 'CC Metadata Scaper', 'g00g1e\\.net', 'GrapeshotCrawler', 'urlappendbot', 'brainobot', 'fr-crawler', 'binlar', 'SimpleCrawler', 'Twitterbot', 'cXensebot', 'smtbot', 'bnf\\.fr_bot', 'A6-Indexer', 'ADmantX', 'Facebot', 'OrangeBot\/', 'memorybot', 'AdvBot', 'MegaIndex', 'SemanticScholarBot', 'ltx71', 'nerdybot', 'xovibot', 'BUbiNG', 'Qwantify', 'archive\\.org_bot', 'Applebot', 'TweetmemeBot', 'crawler4j', 'findxbot', 'S[eE][mM]rushBot', 'yoozBot', 'lipperhey', 'Y!J', 'Domain Re-Animator Bot', 'AddThis', 'Screaming Frog SEO Spider', 'MetaURI', 'Scrapy', 'Livelap[bB]ot', 'OpenHoseBot', 'CapsuleChecker', 'collection@infegy\\.com', 'IstellaBot', 'DeuSu\/', 'betaBot', 'Cliqzbot\/', 'MojeekBot\/', 'netEstate NE Crawler', 'SafeSearch microdata crawler', 'Gluten Free Crawler\/', 'Sonic', 'Sysomos', 'Trove', 'deadlinkchecker', 'Slack-ImgProxy', 'Embedly', 'RankActiveLinkBot', 'iskanie', 'SafeDNSBot', 'SkypeUriPreview', 'Veoozbot', 'Slackbot', 'redditbot', 'datagnionbot', 'Google-Adwords-Instant', 'adbeat_bot', 'WhatsApp', 'contxbot', 'pinterest', 'electricmonk', 'GarlikCrawler', 'BingPreview\/', 'vebidoobot', 'FemtosearchBot', 'Yahoo Link Preview', 'MetaJobBot', 'DomainStatsBot', 'mindUpBot', 'Daum\/', 'Jugendschutzprogramm-Crawler', 'Xenu Link Sleuth', 'Pcore-HTTP', 'moatbot', 'KosmioBot', 'pingdom', 'PhantomJS', 'Gowikibot', 'PiplBot', 'Discordbot', 'TelegramBot', 'Jetslide', 'newsharecounts', 'James BOT', 'Barkrowler', 'TinEye', 'SocialRankIOBot', 'trendictionbot', 'Ocarinabot', 'epicbot', 'Primalbot', 'DuckDuckGo-Favicons-Bot', 'GnowitNewsbot', 'Leikibot', 'LinkArchiver', 'YaK\/', 'PaperLiBot', 'Digg Deeper', 'dcrawl', 'Snacktory', 'AndersPinkBot', 'Fyrebot', 'EveryoneSocialBot', 'Mediatoolkitbot', 'Luminator-robots', 'ExtLinksBot', 'SurveyBot', 'NING\/', 'okhttp', 'Nuzzel', 'omgili', 'PocketParser', 'YisouSpider', 'um-LN', 'ToutiaoSpider', 'MuckRack', "Jamie's Spider", 'AHC\/', 'NetcraftSurveyAgent', 'Laserlikebot', 'Apache-HttpClient', 'AppEngine-Google', 'Jetty', 'Upflow', 'Thinklab', 'Traackr\\.com', 'Twurly', 'Mastodon', 'http_get', 'DnyzBot', 'botify', '007ac9 Crawler', 'BehloolBot', 'BrandVerity', 'check_http', 'BDCbot', 'ZumBot', 'EZID', 'ICC-Crawler', 'ArchiveBot', '^LCC ', 'filterdb\\.iss\\.net\/crawler', 'BLP_bbot', 'BomboraBot', 'Buck\/', 'Companybook-Crawler', 'Genieo', 'magpie-crawler', 'MeltwaterNews', 'Moreover', 'newspaper\/', 'ScoutJet', '(^| )sentry\/', 'StorygizeBot', 'UptimeRobot', 'OutclicksBot', 'seoscanners', 'Hatena', 'Google Web Preview', 'MauiBot', 'AlphaBot', 'SBL-BOT', 'IAS crawler', 'adscanner', 'Netvibes', 'acapbot', 'Baidu-YunGuanCe', 'bitlybot', 'blogmuraBot', 'Bot\\.AraTurka\\.com', 'bot-pge\\.chlooe\\.com', 'BoxcarBot', 'BTWebClient', 'ContextAd Bot', 'Digincore bot', 'Disqus', 'Feedly', 'Fetch\/', 'Fever', 'Flamingo_SearchEngine', 'FlipboardProxy', 'g2reader-bot', 'imrbot', 'K7MLWCBot', 'Kemvibot', 'Landau-Media-Spider', 'linkapediabot', 'vkShare', 'Siteimprove\\.com', 'BLEXBot\/', 'DareBoost', 'ZuperlistBot\/', 'Miniflux\/', 'Feedspotbot\/', 'Diffbot\/', 'SEOkicks', 'tracemyfile', 'Nimbostratus-Bot'];
|
|
@@ -96,7 +96,7 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
96
96
|
method: 'GET'
|
|
97
97
|
};
|
|
98
98
|
} // If events older than `requestTTL` exist in queue, clear request queue
|
|
99
|
-
// - Prevents issue where stale items are sent in
|
|
99
|
+
// - Prevents issue where stale items are sent in perpetuity
|
|
100
100
|
// - No request should go unsent for longer than `requestTTL`
|
|
101
101
|
|
|
102
102
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructor-io/constructorio-client-javascript",
|
|
3
|
-
"version": "2.29.
|
|
3
|
+
"version": "2.29.13",
|
|
4
4
|
"description": "Constructor.io JavaScript client",
|
|
5
5
|
"main": "lib/constructorio.js",
|
|
6
6
|
"scripts": {
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
41
41
|
"@babel/preset-env": "^7.15.8",
|
|
42
42
|
"@babel/register": "^7.15.3",
|
|
43
|
+
"@cspell/eslint-plugin": "^6.8.2",
|
|
43
44
|
"chai": "^4.2.0",
|
|
44
45
|
"chai-as-promised": "^7.1.1",
|
|
45
46
|
"dotenv": "^8.6.0",
|
|
@@ -67,5 +68,8 @@
|
|
|
67
68
|
"fetch-ponyfill": "^7.1.0",
|
|
68
69
|
"qs": "6.7.2",
|
|
69
70
|
"store2": "^2.9.0"
|
|
71
|
+
},
|
|
72
|
+
"peerDependencies": {
|
|
73
|
+
"@babel/runtime": "^7.19.0"
|
|
70
74
|
}
|
|
71
75
|
}
|