coveo.analytics 2.27.3 → 2.27.5

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.
@@ -73,6 +73,8 @@ export declare class CoveoInsightClient {
73
73
  logCustomEvent(event: SearchPageEvents | InsightEvents, metadata?: Record<string, any>): Promise<void | import("../events").CustomEventResponse>;
74
74
  logSearchEvent(event: SearchPageEvents | InsightEvents, metadata?: Record<string, any>): Promise<void | import("../events").SearchEventResponse>;
75
75
  logClickEvent(event: SearchPageEvents, info: PartialDocumentInformation, identifier: DocumentIdentifier, metadata?: Record<string, any>): Promise<void | import("../events").ClickEventResponse>;
76
+ logShowMoreFoldedResults(info: PartialDocumentInformation, identifier: DocumentIdentifier, metadata?: CaseMetadata): Promise<void | import("../events").ClickEventResponse>;
77
+ logShowLessFoldedResults(metadata?: CaseMetadata): Promise<void | import("../events").CustomEventResponse>;
76
78
  private getBaseCustomEventRequest;
77
79
  private getBaseSearchEventRequest;
78
80
  private getBaseEventRequest;
@@ -1 +1 @@
1
- export declare const libVersion = "2.27.3";
1
+ export declare const libVersion = "2.27.5";
@@ -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.3" ;
599
+ const libVersion = "2.27.5" ;
597
600
 
598
601
  const getFormattedLocation = (location) => `${location.protocol}//${location.hostname}${location.pathname.indexOf('/') === 0 ? location.pathname : `/${location.pathname}`}${location.search}`;
599
602
 
@@ -2976,6 +2979,16 @@ class CoveoInsightClient {
2976
2979
  return this.coveoAnalyticsClient.sendClickEvent(payload);
2977
2980
  });
2978
2981
  }
2982
+ logShowMoreFoldedResults(info, identifier, metadata) {
2983
+ return __awaiter(this, void 0, void 0, function* () {
2984
+ return this.logClickEvent(SearchPageEvents.showMoreFoldedResults, info, identifier, metadata ? generateMetadataToSend(metadata, false) : undefined);
2985
+ });
2986
+ }
2987
+ logShowLessFoldedResults(metadata) {
2988
+ return __awaiter(this, void 0, void 0, function* () {
2989
+ return this.logCustomEvent(SearchPageEvents.showLessFoldedResults, metadata ? generateMetadataToSend(metadata, false) : undefined);
2990
+ });
2991
+ }
2979
2992
  getBaseCustomEventRequest(metadata) {
2980
2993
  return __awaiter(this, void 0, void 0, function* () {
2981
2994
  return Object.assign(Object.assign({}, (yield this.getBaseEventRequest(metadata))), { lastSearchQueryUid: this.provider.getSearchUID() });
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.3" ;
734
+ var libVersion = "2.27.5" ;
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);
@@ -85920,6 +85923,20 @@ var CoveoInsightClient = (function () {
85920
85923
  });
85921
85924
  });
85922
85925
  };
85926
+ CoveoInsightClient.prototype.logShowMoreFoldedResults = function (info, identifier, metadata) {
85927
+ return __awaiter(this, void 0, void 0, function () {
85928
+ return __generator(this, function (_a) {
85929
+ return [2, this.logClickEvent(exports.SearchPageEvents.showMoreFoldedResults, info, identifier, metadata ? generateMetadataToSend(metadata, false) : undefined)];
85930
+ });
85931
+ });
85932
+ };
85933
+ CoveoInsightClient.prototype.logShowLessFoldedResults = function (metadata) {
85934
+ return __awaiter(this, void 0, void 0, function () {
85935
+ return __generator(this, function (_a) {
85936
+ return [2, this.logCustomEvent(exports.SearchPageEvents.showLessFoldedResults, metadata ? generateMetadataToSend(metadata, false) : undefined)];
85937
+ });
85938
+ });
85939
+ };
85923
85940
  CoveoInsightClient.prototype.getBaseCustomEventRequest = function (metadata) {
85924
85941
  return __awaiter(this, void 0, void 0, function () {
85925
85942
  var _a;
@@ -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.3" ;
661
+ const libVersion = "2.27.5" ;
659
662
 
660
663
  const getFormattedLocation = (location) => `${location.protocol}//${location.hostname}${location.pathname.indexOf('/') === 0 ? location.pathname : `/${location.pathname}`}${location.search}`;
661
664
 
@@ -2994,6 +2997,16 @@ class CoveoInsightClient {
2994
2997
  return this.coveoAnalyticsClient.sendClickEvent(payload);
2995
2998
  });
2996
2999
  }
3000
+ logShowMoreFoldedResults(info, identifier, metadata) {
3001
+ return __awaiter(this, void 0, void 0, function* () {
3002
+ return this.logClickEvent(SearchPageEvents.showMoreFoldedResults, info, identifier, metadata ? generateMetadataToSend(metadata, false) : undefined);
3003
+ });
3004
+ }
3005
+ logShowLessFoldedResults(metadata) {
3006
+ return __awaiter(this, void 0, void 0, function* () {
3007
+ return this.logCustomEvent(SearchPageEvents.showLessFoldedResults, metadata ? generateMetadataToSend(metadata, false) : undefined);
3008
+ });
3009
+ }
2997
3010
  getBaseCustomEventRequest(metadata) {
2998
3011
  return __awaiter(this, void 0, void 0, function* () {
2999
3012
  return Object.assign(Object.assign({}, (yield this.getBaseEventRequest(metadata))), { lastSearchQueryUid: this.provider.getSearchUID() });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coveo.analytics",
3
- "version": "2.27.3",
3
+ "version": "2.27.5",
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) {
@@ -478,6 +478,15 @@ describe('InsightClient', () => {
478
478
  expectedMetadata
479
479
  );
480
480
  });
481
+ it('should send proper payload for #showMoreFoldedResults', async () => {
482
+ await client.logShowMoreFoldedResults(fakeDocInfo, fakeDocID);
483
+ expectMatchDocumentPayload(SearchPageEvents.showMoreFoldedResults, fakeDocInfo, fakeDocID);
484
+ });
485
+
486
+ it('should send proper payload for #showLessFoldedResults', async () => {
487
+ await client.logShowLessFoldedResults();
488
+ expectMatchCustomEventPayload(SearchPageEvents.showLessFoldedResults);
489
+ });
481
490
  });
482
491
 
483
492
  describe('when the case metadata is included', () => {
@@ -1026,6 +1035,23 @@ describe('InsightClient', () => {
1026
1035
  expectedMetadata
1027
1036
  );
1028
1037
  });
1038
+
1039
+ it('should send proper payload for #showMoreFoldedResults', async () => {
1040
+ const expectedMetadata = {
1041
+ ...fakeDocID,
1042
+ ...expectedBaseCaseMetadata,
1043
+ };
1044
+ await client.logShowMoreFoldedResults(fakeDocInfo, fakeDocID, baseCaseMetadata);
1045
+ expectMatchDocumentPayload(SearchPageEvents.showMoreFoldedResults, fakeDocInfo, expectedMetadata);
1046
+ });
1047
+
1048
+ it('should send proper payload for #showLessFoldedResults', async () => {
1049
+ const expectedMetadata = {
1050
+ ...expectedBaseCaseMetadata,
1051
+ };
1052
+ await client.logShowLessFoldedResults(baseCaseMetadata);
1053
+ expectMatchCustomEventPayload(SearchPageEvents.showLessFoldedResults, expectedMetadata);
1054
+ });
1029
1055
  });
1030
1056
 
1031
1057
  it('should enable analytics tracking by default', () => {
@@ -482,6 +482,26 @@ export class CoveoInsightClient {
482
482
  return this.coveoAnalyticsClient.sendClickEvent(payload);
483
483
  }
484
484
 
485
+ public async logShowMoreFoldedResults(
486
+ info: PartialDocumentInformation,
487
+ identifier: DocumentIdentifier,
488
+ metadata?: CaseMetadata
489
+ ) {
490
+ return this.logClickEvent(
491
+ SearchPageEvents.showMoreFoldedResults,
492
+ info,
493
+ identifier,
494
+ metadata ? generateMetadataToSend(metadata, false) : undefined
495
+ );
496
+ }
497
+
498
+ public async logShowLessFoldedResults(metadata?: CaseMetadata) {
499
+ return this.logCustomEvent(
500
+ SearchPageEvents.showLessFoldedResults,
501
+ metadata ? generateMetadataToSend(metadata, false) : undefined
502
+ );
503
+ }
504
+
485
505
  private async getBaseCustomEventRequest(metadata?: Record<string, any>) {
486
506
  return {
487
507
  ...(await this.getBaseEventRequest(metadata)),