coveo.analytics 2.27.4 → 2.27.6

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.
@@ -1 +1 @@
1
- export declare const libVersion = "2.27.4";
1
+ export declare const libVersion = "2.27.6";
@@ -262,7 +262,7 @@ class HistoryStore {
262
262
  }
263
263
  getMostRecentElement() {
264
264
  let currentHistory = this.getHistoryWithInternalTime();
265
- if (currentHistory != null) {
265
+ if (Array.isArray(currentHistory)) {
266
266
  const sorted = currentHistory.sort((first, second) => {
267
267
  return (second.internalTime || 0) - (first.internalTime || 0);
268
268
  });
@@ -284,10 +284,13 @@ class HistoryStore {
284
284
  return true;
285
285
  }
286
286
  stripInternalTime(history) {
287
- return history.map((part) => {
288
- const { name, time, value } = part;
289
- return { name, time, value };
290
- });
287
+ if (Array.isArray(history)) {
288
+ return history.map((part) => {
289
+ const { name, time, value } = part;
290
+ return { name, time, value };
291
+ });
292
+ }
293
+ return [];
291
294
  }
292
295
  stripEmptyQuery(part) {
293
296
  const { name, time, value } = part;
@@ -593,7 +596,7 @@ function sha1(bytes) {
593
596
  const v5 = v35('v5', 0x50, sha1);
594
597
  var uuidv5 = v5;
595
598
 
596
- const libVersion = "2.27.4" ;
599
+ const libVersion = "2.27.6" ;
597
600
 
598
601
  const getFormattedLocation = (location) => `${location.protocol}//${location.hostname}${location.pathname.indexOf('/') === 0 ? location.pathname : `/${location.pathname}`}${location.search}`;
599
602
 
package/dist/library.js CHANGED
@@ -380,7 +380,7 @@ var HistoryStore = (function () {
380
380
  };
381
381
  HistoryStore.prototype.getMostRecentElement = function () {
382
382
  var currentHistory = this.getHistoryWithInternalTime();
383
- if (currentHistory != null) {
383
+ if (Array.isArray(currentHistory)) {
384
384
  var sorted = currentHistory.sort(function (first, second) {
385
385
  return (second.internalTime || 0) - (first.internalTime || 0);
386
386
  });
@@ -402,10 +402,13 @@ var HistoryStore = (function () {
402
402
  return true;
403
403
  };
404
404
  HistoryStore.prototype.stripInternalTime = function (history) {
405
- return history.map(function (part) {
406
- var name = part.name, time = part.time, value = part.value;
407
- return { name: name, time: time, value: value };
408
- });
405
+ if (Array.isArray(history)) {
406
+ return history.map(function (part) {
407
+ var name = part.name, time = part.time, value = part.value;
408
+ return { name: name, time: time, value: value };
409
+ });
410
+ }
411
+ return [];
409
412
  };
410
413
  HistoryStore.prototype.stripEmptyQuery = function (part) {
411
414
  var name = part.name, time = part.time, value = part.value;
@@ -728,7 +731,7 @@ function sha1(bytes) {
728
731
  const v5 = v35('v5', 0x50, sha1);
729
732
  var uuidv5 = v5;
730
733
 
731
- var libVersion = "2.27.4" ;
734
+ var libVersion = "2.27.6" ;
732
735
 
733
736
  var getFormattedLocation = function (location) {
734
737
  return "".concat(location.protocol, "//").concat(location.hostname).concat(location.pathname.indexOf('/') === 0 ? location.pathname : "/".concat(location.pathname)).concat(location.search);
@@ -589,7 +589,7 @@ class HistoryStore {
589
589
  }
590
590
  getMostRecentElement() {
591
591
  let currentHistory = this.getHistoryWithInternalTime();
592
- if (currentHistory != null) {
592
+ if (Array.isArray(currentHistory)) {
593
593
  const sorted = currentHistory.sort((first, second) => {
594
594
  return (second.internalTime || 0) - (first.internalTime || 0);
595
595
  });
@@ -611,10 +611,13 @@ class HistoryStore {
611
611
  return true;
612
612
  }
613
613
  stripInternalTime(history) {
614
- return history.map((part) => {
615
- const { name, time, value } = part;
616
- return { name, time, value };
617
- });
614
+ if (Array.isArray(history)) {
615
+ return history.map((part) => {
616
+ const { name, time, value } = part;
617
+ return { name, time, value };
618
+ });
619
+ }
620
+ return [];
618
621
  }
619
622
  stripEmptyQuery(part) {
620
623
  const { name, time, value } = part;
@@ -655,7 +658,7 @@ const addPageViewToHistory = (pageViewValue) => __awaiter(void 0, void 0, void 0
655
658
  yield store.addElementAsync(historyElement);
656
659
  });
657
660
 
658
- const libVersion = "2.27.4" ;
661
+ const libVersion = "2.27.6" ;
659
662
 
660
663
  const getFormattedLocation = (location) => `${location.protocol}//${location.hostname}${location.pathname.indexOf('/') === 0 ? location.pathname : `/${location.pathname}`}${location.search}`;
661
664
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coveo.analytics",
3
- "version": "2.27.4",
3
+ "version": "2.27.6",
4
4
  "description": "📈 Coveo analytics client (node and browser compatible) ",
5
5
  "main": "dist/library.js",
6
6
  "module": "dist/library.es.js",
@@ -184,4 +184,18 @@ describe('history', () => {
184
184
 
185
185
  expect(storageMock.setItem).toHaveBeenCalledTimes(2);
186
186
  });
187
+
188
+ it('should not throw when the content of localStorage is not an array', async () => {
189
+ storageMock.setItem(history.STORE_KEY, '{"foo":"bar"}');
190
+ let ex: any;
191
+ try {
192
+ const mostRecentElement = await historyStore.getMostRecentElement();
193
+ expect(mostRecentElement).toBeNull();
194
+ const localHistory = await historyStore.getHistoryAsync();
195
+ expect(localHistory).toStrictEqual([]);
196
+ } catch (err) {
197
+ ex = err;
198
+ }
199
+ expect(ex).toBeUndefined();
200
+ });
187
201
  });
package/src/history.ts CHANGED
@@ -103,7 +103,7 @@ export class HistoryStore {
103
103
 
104
104
  getMostRecentElement(): HistoryElement | null {
105
105
  let currentHistory = this.getHistoryWithInternalTime();
106
- if (currentHistory != null) {
106
+ if (Array.isArray(currentHistory)) {
107
107
  const sorted = currentHistory.sort((first: HistoryElement, second: HistoryElement) => {
108
108
  // Internal time might not be set for all history element (on upgrade).
109
109
  // Ensure to return the most recent element for which we have a value for internalTime.
@@ -132,10 +132,13 @@ export class HistoryStore {
132
132
  }
133
133
 
134
134
  private stripInternalTime(history: HistoryElement[]): HistoryElement[] {
135
- return history.map((part) => {
136
- const {name, time, value} = part;
137
- return {name, time, value};
138
- });
135
+ if (Array.isArray(history)) {
136
+ return history.map((part) => {
137
+ const {name, time, value} = part;
138
+ return {name, time, value};
139
+ });
140
+ }
141
+ return [];
139
142
  }
140
143
 
141
144
  private stripEmptyQuery(part: HistoryElement) {