coveo.analytics 2.32.0 → 2.33.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.
@@ -93,20 +93,12 @@ const addDefaultValues = (eventType, payload) => {
93
93
 
94
94
  class Cookie {
95
95
  static set(name, value, expire) {
96
- var domain, expirationDate, domainParts, host;
96
+ let expirationDate;
97
97
  if (expire) {
98
98
  expirationDate = new Date();
99
99
  expirationDate.setTime(expirationDate.getTime() + expire);
100
100
  }
101
- host = window.location.hostname;
102
- if (host.indexOf('.') === -1) {
103
- writeCookie(name, value, expirationDate);
104
- }
105
- else {
106
- domainParts = host.split('.');
107
- domain = domainParts[domainParts.length - 2] + '.' + domainParts[domainParts.length - 1];
108
- writeCookie(name, value, expirationDate, domain);
109
- }
101
+ writeCookie(name, value, expirationDate, getCookieDomain(window.location.hostname));
110
102
  }
111
103
  static get(name) {
112
104
  var cookiePrefix = name + '=';
@@ -124,6 +116,35 @@ class Cookie {
124
116
  Cookie.set(name, '', -1);
125
117
  }
126
118
  }
119
+ function getCookieDomain(host) {
120
+ if (host.indexOf('.') === -1) {
121
+ return undefined;
122
+ }
123
+ const domainParts = host.split('.');
124
+ for (let domainLength = 2; domainLength <= domainParts.length; domainLength++) {
125
+ const domain = domainParts.slice(-domainLength).join('.');
126
+ if (supportsCookieDomain(domain)) {
127
+ return domain;
128
+ }
129
+ }
130
+ return undefined;
131
+ }
132
+ function supportsCookieDomain(domain) {
133
+ const name = `__coveo_cookie_domain_test_${Math.random().toString(36).substring(2)}`;
134
+ try {
135
+ writeCookie(name, '1', undefined, domain);
136
+ return Cookie.get(name) === '1';
137
+ }
138
+ catch (_a) {
139
+ return false;
140
+ }
141
+ finally {
142
+ try {
143
+ writeCookie(name, '', new Date(0), domain);
144
+ }
145
+ catch (_b) { }
146
+ }
147
+ }
127
148
  function writeCookie(name, value, expirationDate, domain) {
128
149
  document.cookie =
129
150
  `${name}=${value}` +
@@ -524,7 +545,7 @@ function v5(value, namespace, buf, offset) {
524
545
  v5.DNS = DNS;
525
546
  v5.URL = URL$1;
526
547
 
527
- const libVersion = "2.32.0";
548
+ const libVersion = "2.33.1";
528
549
 
529
550
  const getFormattedLocation = (location) => `${location.protocol}//${location.hostname}${location.pathname.indexOf('/') === 0 ? location.pathname : `/${location.pathname}`}${location.search}`;
530
551