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.
package/dist/library.js CHANGED
@@ -174,29 +174,20 @@ var addDefaultValues = function (eventType, payload) {
174
174
  var Cookie = (function () {
175
175
  function Cookie() {
176
176
  }
177
- Cookie.set = function (name, value, expiration) {
178
- var domain, domainParts, date, expires, host;
179
- if (expiration) {
180
- date = new Date();
181
- date.setTime(date.getTime() + expiration);
182
- expires = '; expires=' + date.toGMTString();
183
- }
184
- else {
185
- expires = '';
177
+ Cookie.set = function (name, value, expire) {
178
+ var domain, expirationDate, domainParts, host;
179
+ if (expire) {
180
+ expirationDate = new Date();
181
+ expirationDate.setTime(expirationDate.getTime() + expire);
186
182
  }
187
183
  host = window.location.hostname;
188
184
  if (host.indexOf('.') === -1) {
189
- document.cookie = name + '=' + value + expires + '; path=/';
185
+ writeCookie(name, value, expirationDate);
190
186
  }
191
187
  else {
192
188
  domainParts = host.split('.');
193
- domainParts.shift();
194
- domain = '.' + domainParts.join('.');
195
- writeCookie({ name: name, value: value, expires: expires, domain: domain });
196
- if (Cookie.get(name) == null || Cookie.get(name) != value) {
197
- domain = '.' + host;
198
- writeCookie({ name: name, value: value, expires: expires, domain: domain });
199
- }
189
+ domain = domainParts[domainParts.length - 2] + '.' + domainParts[domainParts.length - 1];
190
+ writeCookie(name, value, expirationDate, domain);
200
191
  }
201
192
  };
202
193
  Cookie.get = function (name) {
@@ -205,7 +196,7 @@ var Cookie = (function () {
205
196
  for (var i = 0; i < cookieArray.length; i++) {
206
197
  var cookie = cookieArray[i];
207
198
  cookie = cookie.replace(/^\s+/, '');
208
- if (cookie.indexOf(cookiePrefix) == 0) {
199
+ if (cookie.lastIndexOf(cookiePrefix, 0) === 0) {
209
200
  return cookie.substring(cookiePrefix.length, cookie.length);
210
201
  }
211
202
  }
@@ -216,9 +207,12 @@ var Cookie = (function () {
216
207
  };
217
208
  return Cookie;
218
209
  }());
219
- function writeCookie(details) {
220
- var name = details.name, value = details.value, expires = details.expires, domain = details.domain;
221
- document.cookie = name + "=" + value + expires + "; path=/; domain=" + domain + "; SameSite=Lax";
210
+ function writeCookie(name, value, expirationDate, domain) {
211
+ document.cookie =
212
+ name + "=" + value +
213
+ (expirationDate ? ";expires=" + expirationDate.toUTCString() : '') +
214
+ (domain ? ";domain=" + domain : '') +
215
+ ';SameSite=Lax';
222
216
  }
223
217
 
224
218
  var preferredStorage = null;
@@ -243,8 +237,8 @@ var CookieStorage = (function () {
243
237
  CookieStorage.prototype.removeItem = function (key) {
244
238
  Cookie.erase("" + CookieStorage.prefix + key);
245
239
  };
246
- CookieStorage.prototype.setItem = function (key, data) {
247
- Cookie.set("" + CookieStorage.prefix + key, data);
240
+ CookieStorage.prototype.setItem = function (key, data, expire) {
241
+ Cookie.set("" + CookieStorage.prefix + key, data, expire);
248
242
  };
249
243
  CookieStorage.prefix = 'coveo_';
250
244
  return CookieStorage;
@@ -262,7 +256,7 @@ var CookieAndLocalStorage = (function () {
262
256
  };
263
257
  CookieAndLocalStorage.prototype.setItem = function (key, data) {
264
258
  localStorage.setItem(key, data);
265
- this.cookieStorage.setItem(key, data);
259
+ this.cookieStorage.setItem(key, data, 31556926000);
266
260
  };
267
261
  return CookieAndLocalStorage;
268
262
  }());
@@ -506,6 +500,225 @@ var getRandomValues = function (rnds) {
506
500
  return rnds;
507
501
  };
508
502
 
503
+ 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;
504
+
505
+ function validate(uuid) {
506
+ return typeof uuid === 'string' && REGEX.test(uuid);
507
+ }
508
+
509
+ /**
510
+ * Convert array of 16 byte values to UUID string format of the form:
511
+ * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
512
+ */
513
+
514
+ const byteToHex = [];
515
+
516
+ for (let i = 0; i < 256; ++i) {
517
+ byteToHex.push((i + 0x100).toString(16).slice(1));
518
+ }
519
+
520
+ function unsafeStringify(arr, offset = 0) {
521
+ // Note: Be careful editing this code! It's been tuned for performance
522
+ // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
523
+ 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();
524
+ }
525
+
526
+ function parse(uuid) {
527
+ if (!validate(uuid)) {
528
+ throw TypeError('Invalid UUID');
529
+ }
530
+
531
+ let v;
532
+ const arr = new Uint8Array(16); // Parse ########-....-....-....-............
533
+
534
+ arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;
535
+ arr[1] = v >>> 16 & 0xff;
536
+ arr[2] = v >>> 8 & 0xff;
537
+ arr[3] = v & 0xff; // Parse ........-####-....-....-............
538
+
539
+ arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8;
540
+ arr[5] = v & 0xff; // Parse ........-....-####-....-............
541
+
542
+ arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8;
543
+ arr[7] = v & 0xff; // Parse ........-....-....-####-............
544
+
545
+ arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8;
546
+ arr[9] = v & 0xff; // Parse ........-....-....-....-############
547
+ // (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
548
+
549
+ arr[10] = (v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000 & 0xff;
550
+ arr[11] = v / 0x100000000 & 0xff;
551
+ arr[12] = v >>> 24 & 0xff;
552
+ arr[13] = v >>> 16 & 0xff;
553
+ arr[14] = v >>> 8 & 0xff;
554
+ arr[15] = v & 0xff;
555
+ return arr;
556
+ }
557
+
558
+ function stringToBytes(str) {
559
+ str = unescape(encodeURIComponent(str)); // UTF8 escape
560
+
561
+ const bytes = [];
562
+
563
+ for (let i = 0; i < str.length; ++i) {
564
+ bytes.push(str.charCodeAt(i));
565
+ }
566
+
567
+ return bytes;
568
+ }
569
+
570
+ const DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
571
+ const URL$1 = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
572
+ function v35(name, version, hashfunc) {
573
+ function generateUUID(value, namespace, buf, offset) {
574
+ var _namespace;
575
+
576
+ if (typeof value === 'string') {
577
+ value = stringToBytes(value);
578
+ }
579
+
580
+ if (typeof namespace === 'string') {
581
+ namespace = parse(namespace);
582
+ }
583
+
584
+ if (((_namespace = namespace) === null || _namespace === void 0 ? void 0 : _namespace.length) !== 16) {
585
+ throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');
586
+ } // Compute hash of namespace and value, Per 4.3
587
+ // Future: Use spread syntax when supported on all platforms, e.g. `bytes =
588
+ // hashfunc([...namespace, ... value])`
589
+
590
+
591
+ let bytes = new Uint8Array(16 + value.length);
592
+ bytes.set(namespace);
593
+ bytes.set(value, namespace.length);
594
+ bytes = hashfunc(bytes);
595
+ bytes[6] = bytes[6] & 0x0f | version;
596
+ bytes[8] = bytes[8] & 0x3f | 0x80;
597
+
598
+ if (buf) {
599
+ offset = offset || 0;
600
+
601
+ for (let i = 0; i < 16; ++i) {
602
+ buf[offset + i] = bytes[i];
603
+ }
604
+
605
+ return buf;
606
+ }
607
+
608
+ return unsafeStringify(bytes);
609
+ } // Function#name is not settable on some platforms (#270)
610
+
611
+
612
+ try {
613
+ generateUUID.name = name; // eslint-disable-next-line no-empty
614
+ } catch (err) {} // For CommonJS default export support
615
+
616
+
617
+ generateUUID.DNS = DNS;
618
+ generateUUID.URL = URL$1;
619
+ return generateUUID;
620
+ }
621
+
622
+ // Adapted from Chris Veness' SHA1 code at
623
+ // http://www.movable-type.co.uk/scripts/sha1.html
624
+ function f(s, x, y, z) {
625
+ switch (s) {
626
+ case 0:
627
+ return x & y ^ ~x & z;
628
+
629
+ case 1:
630
+ return x ^ y ^ z;
631
+
632
+ case 2:
633
+ return x & y ^ x & z ^ y & z;
634
+
635
+ case 3:
636
+ return x ^ y ^ z;
637
+ }
638
+ }
639
+
640
+ function ROTL(x, n) {
641
+ return x << n | x >>> 32 - n;
642
+ }
643
+
644
+ function sha1(bytes) {
645
+ const K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
646
+ const H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
647
+
648
+ if (typeof bytes === 'string') {
649
+ const msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
650
+
651
+ bytes = [];
652
+
653
+ for (let i = 0; i < msg.length; ++i) {
654
+ bytes.push(msg.charCodeAt(i));
655
+ }
656
+ } else if (!Array.isArray(bytes)) {
657
+ // Convert Array-like to Array
658
+ bytes = Array.prototype.slice.call(bytes);
659
+ }
660
+
661
+ bytes.push(0x80);
662
+ const l = bytes.length / 4 + 2;
663
+ const N = Math.ceil(l / 16);
664
+ const M = new Array(N);
665
+
666
+ for (let i = 0; i < N; ++i) {
667
+ const arr = new Uint32Array(16);
668
+
669
+ for (let j = 0; j < 16; ++j) {
670
+ 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];
671
+ }
672
+
673
+ M[i] = arr;
674
+ }
675
+
676
+ M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32);
677
+ M[N - 1][14] = Math.floor(M[N - 1][14]);
678
+ M[N - 1][15] = (bytes.length - 1) * 8 & 0xffffffff;
679
+
680
+ for (let i = 0; i < N; ++i) {
681
+ const W = new Uint32Array(80);
682
+
683
+ for (let t = 0; t < 16; ++t) {
684
+ W[t] = M[i][t];
685
+ }
686
+
687
+ for (let t = 16; t < 80; ++t) {
688
+ W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
689
+ }
690
+
691
+ let a = H[0];
692
+ let b = H[1];
693
+ let c = H[2];
694
+ let d = H[3];
695
+ let e = H[4];
696
+
697
+ for (let t = 0; t < 80; ++t) {
698
+ const s = Math.floor(t / 20);
699
+ const T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t] >>> 0;
700
+ e = d;
701
+ d = c;
702
+ c = ROTL(b, 30) >>> 0;
703
+ b = a;
704
+ a = T;
705
+ }
706
+
707
+ H[0] = H[0] + a >>> 0;
708
+ H[1] = H[1] + b >>> 0;
709
+ H[2] = H[2] + c >>> 0;
710
+ H[3] = H[3] + d >>> 0;
711
+ H[4] = H[4] + e >>> 0;
712
+ }
713
+
714
+ 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];
715
+ }
716
+
717
+ const v5 = v35('v5', 0x50, sha1);
718
+ var uuidv5 = v5;
719
+
720
+ var libVersion = "2.24.1" ;
721
+
509
722
  var keysOf = Object.keys;
510
723
  function isObject(o) {
511
724
  return o !== null && typeof o === 'object' && !Array.isArray(o);
@@ -82545,6 +82758,7 @@ function buildBaseUrl(endpoint, apiVersion) {
82545
82758
  var endpointIsCoveoProxy = endpoint.indexOf('.cloud.coveo.com') !== -1;
82546
82759
  return "" + endpoint + (endpointIsCoveoProxy ? '' : '/rest') + "/" + apiVersion;
82547
82760
  }
82761
+ var COVEO_NAMESPACE = '38824e1f-37f5-42d3-8372-a4b8fa9df946';
82548
82762
  var CoveoAnalyticsClient = (function () {
82549
82763
  function CoveoAnalyticsClient(opts) {
82550
82764
  if (!opts) {
@@ -82581,6 +82795,13 @@ var CoveoAnalyticsClient = (function () {
82581
82795
  enumerable: false,
82582
82796
  configurable: true
82583
82797
  });
82798
+ Object.defineProperty(CoveoAnalyticsClient.prototype, "version", {
82799
+ get: function () {
82800
+ return libVersion;
82801
+ },
82802
+ enumerable: false,
82803
+ configurable: true
82804
+ });
82584
82805
  CoveoAnalyticsClient.prototype.initRuntime = function (clientsOptions) {
82585
82806
  var _this = this;
82586
82807
  if (hasWindow() && hasDocument()) {
@@ -82653,6 +82874,22 @@ var CoveoAnalyticsClient = (function () {
82653
82874
  });
82654
82875
  });
82655
82876
  };
82877
+ CoveoAnalyticsClient.prototype.setClientId = function (value, namespace) {
82878
+ return __awaiter(this, void 0, void 0, function () {
82879
+ return __generator(this, function (_a) {
82880
+ if (validate(value)) {
82881
+ this.setCurrentVisitorId(value);
82882
+ }
82883
+ else {
82884
+ if (!namespace) {
82885
+ throw Error('Cannot generate uuid client id without a specific namespace string.');
82886
+ }
82887
+ this.setCurrentVisitorId(uuidv5(value, uuidv5(namespace, COVEO_NAMESPACE)));
82888
+ }
82889
+ return [2];
82890
+ });
82891
+ });
82892
+ };
82656
82893
  CoveoAnalyticsClient.prototype.getParameters = function (eventType) {
82657
82894
  var payload = [];
82658
82895
  for (var _i = 1; _i < arguments.length; _i++) {
@@ -83595,6 +83832,9 @@ var CoveoUA = (function () {
83595
83832
  this.plugins = new Plugins();
83596
83833
  this.params = {};
83597
83834
  };
83835
+ CoveoUA.prototype.version = function () {
83836
+ return libVersion;
83837
+ };
83598
83838
  return CoveoUA;
83599
83839
  }());
83600
83840
  var coveoua = new CoveoUA();
@@ -83622,6 +83862,7 @@ var handleOneAnalyticsEvent = function (command) {
83622
83862
  'reset',
83623
83863
  'require',
83624
83864
  'provide',
83865
+ 'version',
83625
83866
  ];
83626
83867
  throw new Error("The action \"" + command + "\" does not exist. Available actions: " + actions.join(', ') + ".");
83627
83868
  }
@@ -83813,6 +84054,13 @@ var NoopAnalytics = (function () {
83813
84054
  NoopAnalytics.prototype.registerBeforeSendEventHook = function () { };
83814
84055
  NoopAnalytics.prototype.registerAfterSendEventHook = function () { };
83815
84056
  NoopAnalytics.prototype.addEventTypeMapping = function () { };
84057
+ Object.defineProperty(NoopAnalytics.prototype, "version", {
84058
+ get: function () {
84059
+ return libVersion;
84060
+ },
84061
+ enumerable: false,
84062
+ configurable: true
84063
+ });
83816
84064
  return NoopAnalytics;
83817
84065
  }());
83818
84066