coveo.analytics 2.23.10 → 2.24.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.
@@ -4,7 +4,7 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.coveoua = factory());
5
5
  })(this, (function () { 'use strict';
6
6
 
7
- /*! *****************************************************************************
7
+ /******************************************************************************
8
8
  Copyright (c) Microsoft Corporation.
9
9
 
10
10
  Permission to use, copy, modify, and/or distribute this software for any
@@ -28,6 +28,8 @@
28
28
  };
29
29
 
30
30
  function __extends(d, b) {
31
+ if (typeof b !== "function" && b !== null)
32
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
31
33
  extendStatics(d, b);
32
34
  function __() { this.constructor = d; }
33
35
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -94,6 +96,7 @@
94
96
  }
95
97
  }
96
98
 
99
+ /** @deprecated */
97
100
  function __spreadArrays() {
98
101
  for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
99
102
  for (var r = Array(s), k = 0, i = 0; i < il; i++)
@@ -155,29 +158,20 @@
155
158
  var Cookie = (function () {
156
159
  function Cookie() {
157
160
  }
158
- Cookie.set = function (name, value, expiration) {
159
- var domain, domainParts, date, expires, host;
160
- if (expiration) {
161
- date = new Date();
162
- date.setTime(date.getTime() + expiration);
163
- expires = '; expires=' + date.toGMTString();
164
- }
165
- else {
166
- expires = '';
161
+ Cookie.set = function (name, value, expire) {
162
+ var domain, expirationDate, domainParts, host;
163
+ if (expire) {
164
+ expirationDate = new Date();
165
+ expirationDate.setTime(expirationDate.getTime() + expire);
167
166
  }
168
167
  host = window.location.hostname;
169
168
  if (host.indexOf('.') === -1) {
170
- document.cookie = name + '=' + value + expires + '; path=/';
169
+ writeCookie(name, value, expirationDate);
171
170
  }
172
171
  else {
173
172
  domainParts = host.split('.');
174
- domainParts.shift();
175
- domain = '.' + domainParts.join('.');
176
- writeCookie({ name: name, value: value, expires: expires, domain: domain });
177
- if (Cookie.get(name) == null || Cookie.get(name) != value) {
178
- domain = '.' + host;
179
- writeCookie({ name: name, value: value, expires: expires, domain: domain });
180
- }
173
+ domain = domainParts[domainParts.length - 2] + '.' + domainParts[domainParts.length - 1];
174
+ writeCookie(name, value, expirationDate, domain);
181
175
  }
182
176
  };
183
177
  Cookie.get = function (name) {
@@ -186,7 +180,7 @@
186
180
  for (var i = 0; i < cookieArray.length; i++) {
187
181
  var cookie = cookieArray[i];
188
182
  cookie = cookie.replace(/^\s+/, '');
189
- if (cookie.indexOf(cookiePrefix) == 0) {
183
+ if (cookie.lastIndexOf(cookiePrefix, 0) === 0) {
190
184
  return cookie.substring(cookiePrefix.length, cookie.length);
191
185
  }
192
186
  }
@@ -197,9 +191,12 @@
197
191
  };
198
192
  return Cookie;
199
193
  }());
200
- function writeCookie(details) {
201
- var name = details.name, value = details.value, expires = details.expires, domain = details.domain;
202
- document.cookie = name + "=" + value + expires + "; path=/; domain=" + domain + "; SameSite=Lax";
194
+ function writeCookie(name, value, expirationDate, domain) {
195
+ document.cookie =
196
+ name + "=" + value +
197
+ (expirationDate ? ";expires=" + expirationDate.toUTCString() : '') +
198
+ (domain ? ";domain=" + domain : '') +
199
+ ';SameSite=Lax';
203
200
  }
204
201
 
205
202
  var preferredStorage = null;
@@ -224,8 +221,8 @@
224
221
  CookieStorage.prototype.removeItem = function (key) {
225
222
  Cookie.erase("" + CookieStorage.prefix + key);
226
223
  };
227
- CookieStorage.prototype.setItem = function (key, data) {
228
- Cookie.set("" + CookieStorage.prefix + key, data);
224
+ CookieStorage.prototype.setItem = function (key, data, expire) {
225
+ Cookie.set("" + CookieStorage.prefix + key, data, expire);
229
226
  };
230
227
  CookieStorage.prefix = 'coveo_';
231
228
  return CookieStorage;
@@ -243,7 +240,7 @@
243
240
  };
244
241
  CookieAndLocalStorage.prototype.setItem = function (key, data) {
245
242
  localStorage.setItem(key, data);
246
- this.cookieStorage.setItem(key, data);
243
+ this.cookieStorage.setItem(key, data, 31556926000);
247
244
  };
248
245
  return CookieAndLocalStorage;
249
246
  }());
@@ -487,6 +484,225 @@
487
484
  return rnds;
488
485
  };
489
486
 
487
+ var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
488
+
489
+ function validate(uuid) {
490
+ return typeof uuid === 'string' && REGEX.test(uuid);
491
+ }
492
+
493
+ /**
494
+ * Convert array of 16 byte values to UUID string format of the form:
495
+ * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
496
+ */
497
+
498
+ const byteToHex = [];
499
+
500
+ for (let i = 0; i < 256; ++i) {
501
+ byteToHex.push((i + 0x100).toString(16).slice(1));
502
+ }
503
+
504
+ function unsafeStringify(arr, offset = 0) {
505
+ // Note: Be careful editing this code! It's been tuned for performance
506
+ // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
507
+ return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
508
+ }
509
+
510
+ function parse(uuid) {
511
+ if (!validate(uuid)) {
512
+ throw TypeError('Invalid UUID');
513
+ }
514
+
515
+ let v;
516
+ const arr = new Uint8Array(16); // Parse ########-....-....-....-............
517
+
518
+ arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;
519
+ arr[1] = v >>> 16 & 0xff;
520
+ arr[2] = v >>> 8 & 0xff;
521
+ arr[3] = v & 0xff; // Parse ........-####-....-....-............
522
+
523
+ arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8;
524
+ arr[5] = v & 0xff; // Parse ........-....-####-....-............
525
+
526
+ arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8;
527
+ arr[7] = v & 0xff; // Parse ........-....-....-####-............
528
+
529
+ arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8;
530
+ arr[9] = v & 0xff; // Parse ........-....-....-....-############
531
+ // (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
532
+
533
+ arr[10] = (v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000 & 0xff;
534
+ arr[11] = v / 0x100000000 & 0xff;
535
+ arr[12] = v >>> 24 & 0xff;
536
+ arr[13] = v >>> 16 & 0xff;
537
+ arr[14] = v >>> 8 & 0xff;
538
+ arr[15] = v & 0xff;
539
+ return arr;
540
+ }
541
+
542
+ function stringToBytes(str) {
543
+ str = unescape(encodeURIComponent(str)); // UTF8 escape
544
+
545
+ const bytes = [];
546
+
547
+ for (let i = 0; i < str.length; ++i) {
548
+ bytes.push(str.charCodeAt(i));
549
+ }
550
+
551
+ return bytes;
552
+ }
553
+
554
+ const DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
555
+ const URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
556
+ function v35(name, version, hashfunc) {
557
+ function generateUUID(value, namespace, buf, offset) {
558
+ var _namespace;
559
+
560
+ if (typeof value === 'string') {
561
+ value = stringToBytes(value);
562
+ }
563
+
564
+ if (typeof namespace === 'string') {
565
+ namespace = parse(namespace);
566
+ }
567
+
568
+ if (((_namespace = namespace) === null || _namespace === void 0 ? void 0 : _namespace.length) !== 16) {
569
+ throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');
570
+ } // Compute hash of namespace and value, Per 4.3
571
+ // Future: Use spread syntax when supported on all platforms, e.g. `bytes =
572
+ // hashfunc([...namespace, ... value])`
573
+
574
+
575
+ let bytes = new Uint8Array(16 + value.length);
576
+ bytes.set(namespace);
577
+ bytes.set(value, namespace.length);
578
+ bytes = hashfunc(bytes);
579
+ bytes[6] = bytes[6] & 0x0f | version;
580
+ bytes[8] = bytes[8] & 0x3f | 0x80;
581
+
582
+ if (buf) {
583
+ offset = offset || 0;
584
+
585
+ for (let i = 0; i < 16; ++i) {
586
+ buf[offset + i] = bytes[i];
587
+ }
588
+
589
+ return buf;
590
+ }
591
+
592
+ return unsafeStringify(bytes);
593
+ } // Function#name is not settable on some platforms (#270)
594
+
595
+
596
+ try {
597
+ generateUUID.name = name; // eslint-disable-next-line no-empty
598
+ } catch (err) {} // For CommonJS default export support
599
+
600
+
601
+ generateUUID.DNS = DNS;
602
+ generateUUID.URL = URL;
603
+ return generateUUID;
604
+ }
605
+
606
+ // Adapted from Chris Veness' SHA1 code at
607
+ // http://www.movable-type.co.uk/scripts/sha1.html
608
+ function f(s, x, y, z) {
609
+ switch (s) {
610
+ case 0:
611
+ return x & y ^ ~x & z;
612
+
613
+ case 1:
614
+ return x ^ y ^ z;
615
+
616
+ case 2:
617
+ return x & y ^ x & z ^ y & z;
618
+
619
+ case 3:
620
+ return x ^ y ^ z;
621
+ }
622
+ }
623
+
624
+ function ROTL(x, n) {
625
+ return x << n | x >>> 32 - n;
626
+ }
627
+
628
+ function sha1(bytes) {
629
+ const K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
630
+ const H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
631
+
632
+ if (typeof bytes === 'string') {
633
+ const msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
634
+
635
+ bytes = [];
636
+
637
+ for (let i = 0; i < msg.length; ++i) {
638
+ bytes.push(msg.charCodeAt(i));
639
+ }
640
+ } else if (!Array.isArray(bytes)) {
641
+ // Convert Array-like to Array
642
+ bytes = Array.prototype.slice.call(bytes);
643
+ }
644
+
645
+ bytes.push(0x80);
646
+ const l = bytes.length / 4 + 2;
647
+ const N = Math.ceil(l / 16);
648
+ const M = new Array(N);
649
+
650
+ for (let i = 0; i < N; ++i) {
651
+ const arr = new Uint32Array(16);
652
+
653
+ for (let j = 0; j < 16; ++j) {
654
+ arr[j] = bytes[i * 64 + j * 4] << 24 | bytes[i * 64 + j * 4 + 1] << 16 | bytes[i * 64 + j * 4 + 2] << 8 | bytes[i * 64 + j * 4 + 3];
655
+ }
656
+
657
+ M[i] = arr;
658
+ }
659
+
660
+ M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32);
661
+ M[N - 1][14] = Math.floor(M[N - 1][14]);
662
+ M[N - 1][15] = (bytes.length - 1) * 8 & 0xffffffff;
663
+
664
+ for (let i = 0; i < N; ++i) {
665
+ const W = new Uint32Array(80);
666
+
667
+ for (let t = 0; t < 16; ++t) {
668
+ W[t] = M[i][t];
669
+ }
670
+
671
+ for (let t = 16; t < 80; ++t) {
672
+ W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
673
+ }
674
+
675
+ let a = H[0];
676
+ let b = H[1];
677
+ let c = H[2];
678
+ let d = H[3];
679
+ let e = H[4];
680
+
681
+ for (let t = 0; t < 80; ++t) {
682
+ const s = Math.floor(t / 20);
683
+ const T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t] >>> 0;
684
+ e = d;
685
+ d = c;
686
+ c = ROTL(b, 30) >>> 0;
687
+ b = a;
688
+ a = T;
689
+ }
690
+
691
+ H[0] = H[0] + a >>> 0;
692
+ H[1] = H[1] + b >>> 0;
693
+ H[2] = H[2] + c >>> 0;
694
+ H[3] = H[3] + d >>> 0;
695
+ H[4] = H[4] + e >>> 0;
696
+ }
697
+
698
+ return [H[0] >> 24 & 0xff, H[0] >> 16 & 0xff, H[0] >> 8 & 0xff, H[0] & 0xff, H[1] >> 24 & 0xff, H[1] >> 16 & 0xff, H[1] >> 8 & 0xff, H[1] & 0xff, H[2] >> 24 & 0xff, H[2] >> 16 & 0xff, H[2] >> 8 & 0xff, H[2] & 0xff, H[3] >> 24 & 0xff, H[3] >> 16 & 0xff, H[3] >> 8 & 0xff, H[3] & 0xff, H[4] >> 24 & 0xff, H[4] >> 16 & 0xff, H[4] >> 8 & 0xff, H[4] & 0xff];
699
+ }
700
+
701
+ const v5 = v35('v5', 0x50, sha1);
702
+ var uuidv5 = v5;
703
+
704
+ var libVersion = "2.24.1" ;
705
+
490
706
  var keysOf = Object.keys;
491
707
  function isObject(o) {
492
708
  return o !== null && typeof o === 'object' && !Array.isArray(o);
@@ -1029,6 +1245,7 @@
1029
1245
  var endpointIsCoveoProxy = endpoint.indexOf('.cloud.coveo.com') !== -1;
1030
1246
  return "" + endpoint + (endpointIsCoveoProxy ? '' : '/rest') + "/" + apiVersion;
1031
1247
  }
1248
+ var COVEO_NAMESPACE = '38824e1f-37f5-42d3-8372-a4b8fa9df946';
1032
1249
  var CoveoAnalyticsClient = (function () {
1033
1250
  function CoveoAnalyticsClient(opts) {
1034
1251
  if (!opts) {
@@ -1065,6 +1282,13 @@
1065
1282
  enumerable: false,
1066
1283
  configurable: true
1067
1284
  });
1285
+ Object.defineProperty(CoveoAnalyticsClient.prototype, "version", {
1286
+ get: function () {
1287
+ return libVersion;
1288
+ },
1289
+ enumerable: false,
1290
+ configurable: true
1291
+ });
1068
1292
  CoveoAnalyticsClient.prototype.initRuntime = function (clientsOptions) {
1069
1293
  var _this = this;
1070
1294
  if (hasWindow() && hasDocument()) {
@@ -1137,6 +1361,22 @@
1137
1361
  });
1138
1362
  });
1139
1363
  };
1364
+ CoveoAnalyticsClient.prototype.setClientId = function (value, namespace) {
1365
+ return __awaiter(this, void 0, void 0, function () {
1366
+ return __generator(this, function (_a) {
1367
+ if (validate(value)) {
1368
+ this.setCurrentVisitorId(value);
1369
+ }
1370
+ else {
1371
+ if (!namespace) {
1372
+ throw Error('Cannot generate uuid client id without a specific namespace string.');
1373
+ }
1374
+ this.setCurrentVisitorId(uuidv5(value, uuidv5(namespace, COVEO_NAMESPACE)));
1375
+ }
1376
+ return [2];
1377
+ });
1378
+ });
1379
+ };
1140
1380
  CoveoAnalyticsClient.prototype.getParameters = function (eventType) {
1141
1381
  var payload = [];
1142
1382
  for (var _i = 1; _i < arguments.length; _i++) {
@@ -2079,6 +2319,9 @@
2079
2319
  this.plugins = new Plugins();
2080
2320
  this.params = {};
2081
2321
  };
2322
+ CoveoUA.prototype.version = function () {
2323
+ return libVersion;
2324
+ };
2082
2325
  return CoveoUA;
2083
2326
  }());
2084
2327
  var coveoua$1 = new CoveoUA();
@@ -2106,6 +2349,7 @@
2106
2349
  'reset',
2107
2350
  'require',
2108
2351
  'provide',
2352
+ 'version',
2109
2353
  ];
2110
2354
  throw new Error("The action \"" + command + "\" does not exist. Available actions: " + actions.join(', ') + ".");
2111
2355
  }
@@ -2297,6 +2541,13 @@
2297
2541
  NoopAnalytics.prototype.registerBeforeSendEventHook = function () { };
2298
2542
  NoopAnalytics.prototype.registerAfterSendEventHook = function () { };
2299
2543
  NoopAnalytics.prototype.addEventTypeMapping = function () { };
2544
+ Object.defineProperty(NoopAnalytics.prototype, "version", {
2545
+ get: function () {
2546
+ return libVersion;
2547
+ },
2548
+ enumerable: false,
2549
+ configurable: true
2550
+ });
2300
2551
  return NoopAnalytics;
2301
2552
  }());
2302
2553
 
@@ -3943,11 +4194,11 @@
3943
4194
  });
3944
4195
 
3945
4196
  var promise = window['Promise'];
3946
- if (!(promise instanceof Function)) {
4197
+ if (!(promise instanceof Function) && !global) {
3947
4198
  console.error("This script uses window.Promise which is not supported in your browser. Consider adding a polyfill like \"es6-promise\".");
3948
4199
  }
3949
4200
  var fetch$1 = window['fetch'];
3950
- if (!(fetch$1 instanceof Function)) {
4201
+ if (!(fetch$1 instanceof Function) && !global) {
3951
4202
  console.error("This script uses window.fetch which is not supported in your browser. Consider adding a polyfill like \"fetch\".");
3952
4203
  }
3953
4204
  var coveoua = self.coveoua || handleOneAnalyticsEvent;