coveo.analytics 2.18.64 → 2.19.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.
@@ -18,10 +18,12 @@ export declare class HistoryStore {
18
18
  private cropQueryElement;
19
19
  private isValidEntry;
20
20
  private stripInternalTime;
21
+ private stripEmptyQuery;
22
+ private stripEmptyQueries;
21
23
  }
22
24
  export interface HistoryElement {
23
25
  name: string;
24
- value: string;
26
+ value?: string;
25
27
  time: string;
26
28
  internalTime?: number;
27
29
  }
@@ -192,7 +192,7 @@ class HistoryStore {
192
192
  }
193
193
  addElement(elem) {
194
194
  elem.internalTime = new Date().getTime();
195
- this.cropQueryElement(elem);
195
+ elem = this.cropQueryElement(this.stripEmptyQuery(elem));
196
196
  let currentHistory = this.getHistoryWithInternalTime();
197
197
  if (currentHistory != null) {
198
198
  if (this.isValidEntry(elem)) {
@@ -206,7 +206,7 @@ class HistoryStore {
206
206
  addElementAsync(elem) {
207
207
  return __awaiter(this, void 0, void 0, function* () {
208
208
  elem.internalTime = new Date().getTime();
209
- this.cropQueryElement(elem);
209
+ elem = this.cropQueryElement(this.stripEmptyQuery(elem));
210
210
  let currentHistory = yield this.getHistoryWithInternalTimeAsync();
211
211
  if (currentHistory != null) {
212
212
  if (this.isValidEntry(elem)) {
@@ -220,12 +220,12 @@ class HistoryStore {
220
220
  }
221
221
  getHistory() {
222
222
  const history = this.getHistoryWithInternalTime();
223
- return this.stripInternalTime(history);
223
+ return this.stripEmptyQueries(this.stripInternalTime(history));
224
224
  }
225
225
  getHistoryAsync() {
226
226
  return __awaiter(this, void 0, void 0, function* () {
227
227
  const history = yield this.getHistoryWithInternalTimeAsync();
228
- return this.stripInternalTime(history);
228
+ return this.stripEmptyQueries(this.stripInternalTime(history));
229
229
  });
230
230
  }
231
231
  getHistoryWithInternalTime() {
@@ -282,10 +282,11 @@ class HistoryStore {
282
282
  }
283
283
  return null;
284
284
  }
285
- cropQueryElement(elem) {
286
- if (elem.name && elem.name.toLowerCase() == 'query' && elem.value != null) {
287
- elem.value = elem.value.slice(0, MAX_VALUE_SIZE);
285
+ cropQueryElement(part) {
286
+ if (part.name && part.value && part.name.toLowerCase() === 'query') {
287
+ part.value = part.value.slice(0, MAX_VALUE_SIZE);
288
288
  }
289
+ return part;
289
290
  }
290
291
  isValidEntry(elem) {
291
292
  let lastEntry = this.getMostRecentElement();
@@ -300,6 +301,16 @@ class HistoryStore {
300
301
  return { name, time, value };
301
302
  });
302
303
  }
304
+ stripEmptyQuery(part) {
305
+ const { name, time, value } = part;
306
+ if (name && typeof value === 'string' && name.toLowerCase() === 'query' && value.trim() === '') {
307
+ return { name, time };
308
+ }
309
+ return part;
310
+ }
311
+ stripEmptyQueries(history) {
312
+ return history.map((part) => this.stripEmptyQuery(part));
313
+ }
303
314
  }
304
315
 
305
316
  var history = /*#__PURE__*/Object.freeze({
package/dist/library.js CHANGED
@@ -475,7 +475,7 @@ var HistoryStore = (function () {
475
475
  }
476
476
  HistoryStore.prototype.addElement = function (elem) {
477
477
  elem.internalTime = new Date().getTime();
478
- this.cropQueryElement(elem);
478
+ elem = this.cropQueryElement(this.stripEmptyQuery(elem));
479
479
  var currentHistory = this.getHistoryWithInternalTime();
480
480
  if (currentHistory != null) {
481
481
  if (this.isValidEntry(elem)) {
@@ -493,7 +493,7 @@ var HistoryStore = (function () {
493
493
  switch (_a.label) {
494
494
  case 0:
495
495
  elem.internalTime = new Date().getTime();
496
- this.cropQueryElement(elem);
496
+ elem = this.cropQueryElement(this.stripEmptyQuery(elem));
497
497
  return [4, this.getHistoryWithInternalTimeAsync()];
498
498
  case 1:
499
499
  currentHistory = _a.sent();
@@ -512,7 +512,7 @@ var HistoryStore = (function () {
512
512
  };
513
513
  HistoryStore.prototype.getHistory = function () {
514
514
  var history = this.getHistoryWithInternalTime();
515
- return this.stripInternalTime(history);
515
+ return this.stripEmptyQueries(this.stripInternalTime(history));
516
516
  };
517
517
  HistoryStore.prototype.getHistoryAsync = function () {
518
518
  return tslib.exports.__awaiter(this, void 0, void 0, function () {
@@ -522,7 +522,7 @@ var HistoryStore = (function () {
522
522
  case 0: return [4, this.getHistoryWithInternalTimeAsync()];
523
523
  case 1:
524
524
  history = _a.sent();
525
- return [2, this.stripInternalTime(history)];
525
+ return [2, this.stripEmptyQueries(this.stripInternalTime(history))];
526
526
  }
527
527
  });
528
528
  });
@@ -589,10 +589,11 @@ var HistoryStore = (function () {
589
589
  }
590
590
  return null;
591
591
  };
592
- HistoryStore.prototype.cropQueryElement = function (elem) {
593
- if (elem.name && elem.name.toLowerCase() == 'query' && elem.value != null) {
594
- elem.value = elem.value.slice(0, MAX_VALUE_SIZE);
592
+ HistoryStore.prototype.cropQueryElement = function (part) {
593
+ if (part.name && part.value && part.name.toLowerCase() === 'query') {
594
+ part.value = part.value.slice(0, MAX_VALUE_SIZE);
595
595
  }
596
+ return part;
596
597
  };
597
598
  HistoryStore.prototype.isValidEntry = function (elem) {
598
599
  var lastEntry = this.getMostRecentElement();
@@ -607,6 +608,17 @@ var HistoryStore = (function () {
607
608
  return { name: name, time: time, value: value };
608
609
  });
609
610
  };
611
+ HistoryStore.prototype.stripEmptyQuery = function (part) {
612
+ var name = part.name, time = part.time, value = part.value;
613
+ if (name && typeof value === 'string' && name.toLowerCase() === 'query' && value.trim() === '') {
614
+ return { name: name, time: time };
615
+ }
616
+ return part;
617
+ };
618
+ HistoryStore.prototype.stripEmptyQueries = function (history) {
619
+ var _this = this;
620
+ return history.map(function (part) { return _this.stripEmptyQuery(part); });
621
+ };
610
622
  return HistoryStore;
611
623
  }());
612
624
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coveo.analytics",
3
- "version": "2.18.64",
3
+ "version": "2.19.1",
4
4
  "description": "📈 Coveo analytics client (node and browser compatible) ",
5
5
  "main": "dist/library.js",
6
6
  "module": "dist/library.es.js",
@@ -320,6 +320,7 @@ export class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdProvider
320
320
  }
321
321
 
322
322
  async getVisit(): Promise<VisitResponse> {
323
+ // deepcode ignore Ssrf: url is supplied by script owner
323
324
  const response = await fetch(`${this.baseUrl}/analytics/visit`);
324
325
  const visit = (await response.json()) as VisitResponse;
325
326
  this.visitorId = visit.visitorId;
@@ -327,6 +328,7 @@ export class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdProvider
327
328
  }
328
329
 
329
330
  async getHealth(): Promise<HealthResponse> {
331
+ // deepcode ignore Ssrf: url is supplied by script owner
330
332
  const response = await fetch(`${this.baseUrl}/analytics/monitoring/health`);
331
333
  return (await response.json()) as HealthResponse;
332
334
  }
@@ -115,6 +115,44 @@ describe('history', () => {
115
115
  }
116
116
  });
117
117
 
118
+ it('should strip empty query values when calling getHistoryAsync', async () => {
119
+ data.name = 'Query';
120
+ data.value = '';
121
+ const historyElements: history.HistoryElement[] = [data];
122
+ historyStore.setHistory(historyElements);
123
+
124
+ const history = await historyStore.getHistoryAsync();
125
+ expect(history[0].value).toBeUndefined();
126
+ });
127
+
128
+ it('should strip empty query values when calling getHistory', () => {
129
+ data.name = 'Query';
130
+ data.value = '';
131
+ const historyElements: history.HistoryElement[] = [data];
132
+ historyStore.setHistory(historyElements);
133
+
134
+ const history = historyStore.getHistory();
135
+ expect(history[0].value).toBeUndefined();
136
+ });
137
+
138
+ it('should strip empty query from new element (addElement)', () => {
139
+ data.name = 'Query';
140
+ data.value = '';
141
+ historyStore.addElement(data);
142
+
143
+ const [_, setData] = storageMock.setItem.mock.calls[0];
144
+ expect(setData).not.toMatch(/"value"/);
145
+ });
146
+
147
+ it('should strip empty query from new element (addElementAsync)', async () => {
148
+ data.name = 'Query';
149
+ data.value = '';
150
+ await historyStore.addElementAsync(data);
151
+
152
+ const [_, setData] = storageMock.setItem.mock.calls[0];
153
+ expect(setData).not.toMatch(/"value"/);
154
+ });
155
+
118
156
  it('should remove item when cleared', () => {
119
157
  historyStore.clear();
120
158
 
package/src/history.ts CHANGED
@@ -16,7 +16,7 @@ export class HistoryStore {
16
16
  */
17
17
  addElement(elem: HistoryElement) {
18
18
  elem.internalTime = new Date().getTime();
19
- this.cropQueryElement(elem);
19
+ elem = this.cropQueryElement(this.stripEmptyQuery(elem));
20
20
  let currentHistory = this.getHistoryWithInternalTime();
21
21
  if (currentHistory != null) {
22
22
  if (this.isValidEntry(elem)) {
@@ -29,7 +29,7 @@ export class HistoryStore {
29
29
 
30
30
  async addElementAsync(elem: HistoryElement) {
31
31
  elem.internalTime = new Date().getTime();
32
- this.cropQueryElement(elem);
32
+ elem = this.cropQueryElement(this.stripEmptyQuery(elem));
33
33
  let currentHistory = await this.getHistoryWithInternalTimeAsync();
34
34
  if (currentHistory != null) {
35
35
  if (this.isValidEntry(elem)) {
@@ -45,12 +45,12 @@ export class HistoryStore {
45
45
  */
46
46
  getHistory(): HistoryElement[] {
47
47
  const history = this.getHistoryWithInternalTime();
48
- return this.stripInternalTime(history);
48
+ return this.stripEmptyQueries(this.stripInternalTime(history));
49
49
  }
50
50
 
51
51
  async getHistoryAsync(): Promise<HistoryElement[]> {
52
52
  const history = await this.getHistoryWithInternalTimeAsync();
53
- return this.stripInternalTime(history);
53
+ return this.stripEmptyQueries(this.stripInternalTime(history));
54
54
  }
55
55
 
56
56
  private getHistoryWithInternalTime(): HistoryElement[] {
@@ -114,10 +114,12 @@ export class HistoryStore {
114
114
  return null;
115
115
  }
116
116
 
117
- private cropQueryElement(elem: HistoryElement) {
118
- if (elem.name && elem.name.toLowerCase() == 'query' && elem.value != null) {
119
- elem.value = elem.value.slice(0, MAX_VALUE_SIZE);
117
+ private cropQueryElement(part: HistoryElement) {
118
+ if (part.name && part.value && part.name.toLowerCase() === 'query') {
119
+ part.value = part.value.slice(0, MAX_VALUE_SIZE);
120
120
  }
121
+
122
+ return part;
121
123
  }
122
124
 
123
125
  private isValidEntry(elem: HistoryElement): boolean {
@@ -135,11 +137,24 @@ export class HistoryStore {
135
137
  return {name, time, value};
136
138
  });
137
139
  }
140
+
141
+ private stripEmptyQuery(part: HistoryElement) {
142
+ const {name, time, value} = part;
143
+ if (name && typeof value === 'string' && name.toLowerCase() === 'query' && value.trim() === '') {
144
+ return {name, time};
145
+ }
146
+
147
+ return part;
148
+ }
149
+
150
+ private stripEmptyQueries(history: HistoryElement[]): HistoryElement[] {
151
+ return history.map((part) => this.stripEmptyQuery(part));
152
+ }
138
153
  }
139
154
 
140
155
  export interface HistoryElement {
141
156
  name: string;
142
- value: string;
157
+ value?: string;
143
158
  time: string;
144
159
  internalTime?: number;
145
160
  }