@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
|
@@ -0,0 +1,126 @@
|
|
|
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
|
+
|
package/lib/utils/botlist.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
/* eslint-disable no-useless-escape */
|
|
4
|
-
|
|
5
4
|
/* cspell:disable */
|
|
5
|
+
|
|
6
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', 'Bytespider'];
|
|
@@ -1,54 +1,49 @@
|
|
|
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 no-unneeded-ternary */
|
|
10
7
|
var helpers = require('./helpers');
|
|
11
|
-
|
|
12
8
|
var EventDispatcher = /*#__PURE__*/function () {
|
|
13
9
|
function EventDispatcher(options) {
|
|
14
10
|
var _this = this;
|
|
15
|
-
|
|
16
11
|
(0, _classCallCheck2["default"])(this, EventDispatcher);
|
|
17
12
|
this.events = [];
|
|
18
13
|
this.enabled = options && options.enabled === false ? false : true; // Defaults to 'true'
|
|
19
|
-
|
|
20
14
|
this.waitForBeacon = options && options.waitForBeacon === false ? false : true; // Defaults to 'true'
|
|
15
|
+
|
|
21
16
|
// `enabled` is a supplied option
|
|
22
17
|
// - if false, events will never be dispatched
|
|
23
18
|
// `active` is a variable determining if events will be dispatched
|
|
24
19
|
// - if `waitForBeacon` is set to true, `active` will be false until beacon event is received
|
|
20
|
+
this.active = this.enabled;
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
// If `waitForBeacon` option is set, only enable event dispatching once event is received from beacon
|
|
28
23
|
if (this.waitForBeacon) {
|
|
29
|
-
this.active = false;
|
|
30
|
-
// - Important for the case where the beacon has loaded before client library instantiated
|
|
24
|
+
this.active = false;
|
|
31
25
|
|
|
26
|
+
// Check browser environment to determine if beacon has been loaded
|
|
27
|
+
// - Important for the case where the beacon has loaded before client library instantiated
|
|
32
28
|
if (helpers.canUseDOM() && (window.ConstructorioAutocomplete || window.ConstructorioBeacon || window.ConstructorioTracker)) {
|
|
33
29
|
if (this.enabled) {
|
|
34
30
|
this.active = true;
|
|
35
31
|
this.dispatchEvents();
|
|
36
32
|
}
|
|
37
|
-
}
|
|
38
|
-
// - Important for the case where client library instantiated before beacon has loaded
|
|
39
|
-
|
|
33
|
+
}
|
|
40
34
|
|
|
35
|
+
// Bind listener to beacon loaded event
|
|
36
|
+
// - Important for the case where client library instantiated before beacon has loaded
|
|
41
37
|
helpers.addEventListener('cio.beacon.loaded', function () {
|
|
42
38
|
if (_this.enabled) {
|
|
43
39
|
_this.active = true;
|
|
44
|
-
|
|
45
40
|
_this.dispatchEvents();
|
|
46
41
|
}
|
|
47
42
|
});
|
|
48
43
|
}
|
|
49
|
-
}
|
|
50
|
-
|
|
44
|
+
}
|
|
51
45
|
|
|
46
|
+
// Push event data to queue
|
|
52
47
|
(0, _createClass2["default"])(EventDispatcher, [{
|
|
53
48
|
key: "queue",
|
|
54
49
|
value: function queue(name, data) {
|
|
@@ -56,19 +51,19 @@ var EventDispatcher = /*#__PURE__*/function () {
|
|
|
56
51
|
name: name,
|
|
57
52
|
data: data
|
|
58
53
|
});
|
|
59
|
-
|
|
60
54
|
if (this.active) {
|
|
61
55
|
this.dispatchEvents();
|
|
62
56
|
}
|
|
63
|
-
}
|
|
57
|
+
}
|
|
64
58
|
|
|
59
|
+
// Dispatch all custom events within queue on `window` of supplied name with data
|
|
65
60
|
}, {
|
|
66
61
|
key: "dispatchEvents",
|
|
67
62
|
value: function dispatchEvents() {
|
|
68
63
|
while (this.events.length) {
|
|
69
64
|
var item = this.events.shift();
|
|
70
65
|
var name = item.name,
|
|
71
|
-
|
|
66
|
+
data = item.data;
|
|
72
67
|
var eventName = "cio.client.".concat(name);
|
|
73
68
|
helpers.dispatchEvent(helpers.createCustomEvent(eventName, data));
|
|
74
69
|
}
|
|
@@ -76,5 +71,4 @@ var EventDispatcher = /*#__PURE__*/function () {
|
|
|
76
71
|
}]);
|
|
77
72
|
return EventDispatcher;
|
|
78
73
|
}();
|
|
79
|
-
|
|
80
74
|
module.exports = EventDispatcher;
|