coveo.analytics 2.28.25 → 2.29.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.
@@ -10,7 +10,5 @@ export declare class AnalyticsBeaconClient implements AnalyticsRequestClient {
10
10
  private encodeForEventType;
11
11
  private getQueryParamsForEventType;
12
12
  private isEventTypeLegacy;
13
- private encodeForLegacyType;
14
- private encodeForFormUrlEncoded;
15
- private encodeValue;
13
+ private encodeEventToJson;
16
14
  }
@@ -1 +1 @@
1
- export declare const libVersion = "2.28.25";
1
+ export declare const libVersion = "2.29.1";
package/dist/library.cjs CHANGED
@@ -731,7 +731,7 @@ function sha1(bytes) {
731
731
  const v5 = v35('v5', 0x50, sha1);
732
732
  var uuidv5 = v5;
733
733
 
734
- var libVersion = "2.28.25" ;
734
+ var libVersion = "2.29.1" ;
735
735
 
736
736
  var getFormattedLocation = function (location) {
737
737
  return "".concat(location.protocol, "//").concat(location.hostname).concat(location.pathname.indexOf('/') === 0 ? location.pathname : "/".concat(location.pathname)).concat(location.search);
@@ -1268,8 +1268,8 @@ var AnalyticsBeaconClient = (function () {
1268
1268
  };
1269
1269
  AnalyticsBeaconClient.prototype.encodeForEventType = function (eventType, payload) {
1270
1270
  return this.isEventTypeLegacy(eventType)
1271
- ? this.encodeForLegacyType(eventType, payload)
1272
- : this.encodeForFormUrlEncoded(__assign({ access_token: this.opts.token }, payload));
1271
+ ? this.encodeEventToJson(eventType, payload)
1272
+ : this.encodeEventToJson(eventType, payload, this.opts.token);
1273
1273
  };
1274
1274
  AnalyticsBeaconClient.prototype.getQueryParamsForEventType = function (eventType) {
1275
1275
  return __awaiter(this, void 0, void 0, function () {
@@ -1295,20 +1295,12 @@ var AnalyticsBeaconClient = (function () {
1295
1295
  AnalyticsBeaconClient.prototype.isEventTypeLegacy = function (eventType) {
1296
1296
  return [exports.EventType.click, exports.EventType.custom, exports.EventType.search, exports.EventType.view].indexOf(eventType) !== -1;
1297
1297
  };
1298
- AnalyticsBeaconClient.prototype.encodeForLegacyType = function (eventType, payload) {
1299
- return "".concat(eventType, "Event=").concat(encodeURIComponent(JSON.stringify(payload)));
1300
- };
1301
- AnalyticsBeaconClient.prototype.encodeForFormUrlEncoded = function (payload) {
1302
- var _this = this;
1303
- return Object.keys(payload)
1304
- .filter(function (key) { return !!payload[key]; })
1305
- .map(function (key) { return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(_this.encodeValue(payload[key]))); })
1306
- .join('&');
1307
- };
1308
- AnalyticsBeaconClient.prototype.encodeValue = function (value) {
1309
- return typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean'
1310
- ? value
1311
- : JSON.stringify(value);
1298
+ AnalyticsBeaconClient.prototype.encodeEventToJson = function (eventType, payload, access_token) {
1299
+ var encoded = "".concat(eventType, "Event=").concat(encodeURIComponent(JSON.stringify(payload)));
1300
+ if (access_token) {
1301
+ encoded = "access_token=".concat(encodeURIComponent(access_token), "&").concat(encoded);
1302
+ }
1303
+ return encoded;
1312
1304
  };
1313
1305
  return AnalyticsBeaconClient;
1314
1306
  }());
@@ -596,7 +596,7 @@ function sha1(bytes) {
596
596
  const v5 = v35('v5', 0x50, sha1);
597
597
  var uuidv5 = v5;
598
598
 
599
- const libVersion = "2.28.25" ;
599
+ const libVersion = "2.29.1" ;
600
600
 
601
601
  const getFormattedLocation = (location) => `${location.protocol}//${location.hostname}${location.pathname.indexOf('/') === 0 ? location.pathname : `/${location.pathname}`}${location.search}`;
602
602
 
@@ -1052,8 +1052,8 @@ class AnalyticsBeaconClient {
1052
1052
  }
1053
1053
  encodeForEventType(eventType, payload) {
1054
1054
  return this.isEventTypeLegacy(eventType)
1055
- ? this.encodeForLegacyType(eventType, payload)
1056
- : this.encodeForFormUrlEncoded(Object.assign({ access_token: this.opts.token }, payload));
1055
+ ? this.encodeEventToJson(eventType, payload)
1056
+ : this.encodeEventToJson(eventType, payload, this.opts.token);
1057
1057
  }
1058
1058
  getQueryParamsForEventType(eventType) {
1059
1059
  return __awaiter(this, void 0, void 0, function* () {
@@ -1071,19 +1071,12 @@ class AnalyticsBeaconClient {
1071
1071
  isEventTypeLegacy(eventType) {
1072
1072
  return [EventType.click, EventType.custom, EventType.search, EventType.view].indexOf(eventType) !== -1;
1073
1073
  }
1074
- encodeForLegacyType(eventType, payload) {
1075
- return `${eventType}Event=${encodeURIComponent(JSON.stringify(payload))}`;
1076
- }
1077
- encodeForFormUrlEncoded(payload) {
1078
- return Object.keys(payload)
1079
- .filter((key) => !!payload[key])
1080
- .map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(this.encodeValue(payload[key]))}`)
1081
- .join('&');
1082
- }
1083
- encodeValue(value) {
1084
- return typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean'
1085
- ? value
1086
- : JSON.stringify(value);
1074
+ encodeEventToJson(eventType, payload, access_token) {
1075
+ let encoded = `${eventType}Event=${encodeURIComponent(JSON.stringify(payload))}`;
1076
+ if (access_token) {
1077
+ encoded = `access_token=${encodeURIComponent(access_token)}&${encoded}`;
1078
+ }
1079
+ return encoded;
1087
1080
  }
1088
1081
  }
1089
1082
 
package/dist/library.js CHANGED
@@ -731,7 +731,7 @@ function sha1(bytes) {
731
731
  const v5 = v35('v5', 0x50, sha1);
732
732
  var uuidv5 = v5;
733
733
 
734
- var libVersion = "2.28.25" ;
734
+ var libVersion = "2.29.1" ;
735
735
 
736
736
  var getFormattedLocation = function (location) {
737
737
  return "".concat(location.protocol, "//").concat(location.hostname).concat(location.pathname.indexOf('/') === 0 ? location.pathname : "/".concat(location.pathname)).concat(location.search);
@@ -1268,8 +1268,8 @@ var AnalyticsBeaconClient = (function () {
1268
1268
  };
1269
1269
  AnalyticsBeaconClient.prototype.encodeForEventType = function (eventType, payload) {
1270
1270
  return this.isEventTypeLegacy(eventType)
1271
- ? this.encodeForLegacyType(eventType, payload)
1272
- : this.encodeForFormUrlEncoded(__assign({ access_token: this.opts.token }, payload));
1271
+ ? this.encodeEventToJson(eventType, payload)
1272
+ : this.encodeEventToJson(eventType, payload, this.opts.token);
1273
1273
  };
1274
1274
  AnalyticsBeaconClient.prototype.getQueryParamsForEventType = function (eventType) {
1275
1275
  return __awaiter(this, void 0, void 0, function () {
@@ -1295,20 +1295,12 @@ var AnalyticsBeaconClient = (function () {
1295
1295
  AnalyticsBeaconClient.prototype.isEventTypeLegacy = function (eventType) {
1296
1296
  return [exports.EventType.click, exports.EventType.custom, exports.EventType.search, exports.EventType.view].indexOf(eventType) !== -1;
1297
1297
  };
1298
- AnalyticsBeaconClient.prototype.encodeForLegacyType = function (eventType, payload) {
1299
- return "".concat(eventType, "Event=").concat(encodeURIComponent(JSON.stringify(payload)));
1300
- };
1301
- AnalyticsBeaconClient.prototype.encodeForFormUrlEncoded = function (payload) {
1302
- var _this = this;
1303
- return Object.keys(payload)
1304
- .filter(function (key) { return !!payload[key]; })
1305
- .map(function (key) { return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(_this.encodeValue(payload[key]))); })
1306
- .join('&');
1307
- };
1308
- AnalyticsBeaconClient.prototype.encodeValue = function (value) {
1309
- return typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean'
1310
- ? value
1311
- : JSON.stringify(value);
1298
+ AnalyticsBeaconClient.prototype.encodeEventToJson = function (eventType, payload, access_token) {
1299
+ var encoded = "".concat(eventType, "Event=").concat(encodeURIComponent(JSON.stringify(payload)));
1300
+ if (access_token) {
1301
+ encoded = "access_token=".concat(encodeURIComponent(access_token), "&").concat(encoded);
1302
+ }
1303
+ return encoded;
1312
1304
  };
1313
1305
  return AnalyticsBeaconClient;
1314
1306
  }());
package/dist/library.mjs CHANGED
@@ -729,7 +729,7 @@ function sha1(bytes) {
729
729
  const v5 = v35('v5', 0x50, sha1);
730
730
  var uuidv5 = v5;
731
731
 
732
- var libVersion = "2.28.25" ;
732
+ var libVersion = "2.29.1" ;
733
733
 
734
734
  var getFormattedLocation = function (location) {
735
735
  return "".concat(location.protocol, "//").concat(location.hostname).concat(location.pathname.indexOf('/') === 0 ? location.pathname : "/".concat(location.pathname)).concat(location.search);
@@ -1266,8 +1266,8 @@ var AnalyticsBeaconClient = (function () {
1266
1266
  };
1267
1267
  AnalyticsBeaconClient.prototype.encodeForEventType = function (eventType, payload) {
1268
1268
  return this.isEventTypeLegacy(eventType)
1269
- ? this.encodeForLegacyType(eventType, payload)
1270
- : this.encodeForFormUrlEncoded(__assign({ access_token: this.opts.token }, payload));
1269
+ ? this.encodeEventToJson(eventType, payload)
1270
+ : this.encodeEventToJson(eventType, payload, this.opts.token);
1271
1271
  };
1272
1272
  AnalyticsBeaconClient.prototype.getQueryParamsForEventType = function (eventType) {
1273
1273
  return __awaiter(this, void 0, void 0, function () {
@@ -1293,20 +1293,12 @@ var AnalyticsBeaconClient = (function () {
1293
1293
  AnalyticsBeaconClient.prototype.isEventTypeLegacy = function (eventType) {
1294
1294
  return [EventType.click, EventType.custom, EventType.search, EventType.view].indexOf(eventType) !== -1;
1295
1295
  };
1296
- AnalyticsBeaconClient.prototype.encodeForLegacyType = function (eventType, payload) {
1297
- return "".concat(eventType, "Event=").concat(encodeURIComponent(JSON.stringify(payload)));
1298
- };
1299
- AnalyticsBeaconClient.prototype.encodeForFormUrlEncoded = function (payload) {
1300
- var _this = this;
1301
- return Object.keys(payload)
1302
- .filter(function (key) { return !!payload[key]; })
1303
- .map(function (key) { return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(_this.encodeValue(payload[key]))); })
1304
- .join('&');
1305
- };
1306
- AnalyticsBeaconClient.prototype.encodeValue = function (value) {
1307
- return typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean'
1308
- ? value
1309
- : JSON.stringify(value);
1296
+ AnalyticsBeaconClient.prototype.encodeEventToJson = function (eventType, payload, access_token) {
1297
+ var encoded = "".concat(eventType, "Event=").concat(encodeURIComponent(JSON.stringify(payload)));
1298
+ if (access_token) {
1299
+ encoded = "access_token=".concat(encodeURIComponent(access_token), "&").concat(encoded);
1300
+ }
1301
+ return encoded;
1310
1302
  };
1311
1303
  return AnalyticsBeaconClient;
1312
1304
  }());
@@ -658,7 +658,7 @@ const addPageViewToHistory = (pageViewValue) => __awaiter(void 0, void 0, void 0
658
658
  yield store.addElementAsync(historyElement);
659
659
  });
660
660
 
661
- const libVersion = "2.28.25" ;
661
+ const libVersion = "2.29.1" ;
662
662
 
663
663
  const getFormattedLocation = (location) => `${location.protocol}//${location.hostname}${location.pathname.indexOf('/') === 0 ? location.pathname : `/${location.pathname}`}${location.search}`;
664
664
 
@@ -1114,8 +1114,8 @@ class AnalyticsBeaconClient {
1114
1114
  }
1115
1115
  encodeForEventType(eventType, payload) {
1116
1116
  return this.isEventTypeLegacy(eventType)
1117
- ? this.encodeForLegacyType(eventType, payload)
1118
- : this.encodeForFormUrlEncoded(Object.assign({ access_token: this.opts.token }, payload));
1117
+ ? this.encodeEventToJson(eventType, payload)
1118
+ : this.encodeEventToJson(eventType, payload, this.opts.token);
1119
1119
  }
1120
1120
  getQueryParamsForEventType(eventType) {
1121
1121
  return __awaiter(this, void 0, void 0, function* () {
@@ -1133,19 +1133,12 @@ class AnalyticsBeaconClient {
1133
1133
  isEventTypeLegacy(eventType) {
1134
1134
  return [EventType.click, EventType.custom, EventType.search, EventType.view].indexOf(eventType) !== -1;
1135
1135
  }
1136
- encodeForLegacyType(eventType, payload) {
1137
- return `${eventType}Event=${encodeURIComponent(JSON.stringify(payload))}`;
1138
- }
1139
- encodeForFormUrlEncoded(payload) {
1140
- return Object.keys(payload)
1141
- .filter((key) => !!payload[key])
1142
- .map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(this.encodeValue(payload[key]))}`)
1143
- .join('&');
1144
- }
1145
- encodeValue(value) {
1146
- return typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean'
1147
- ? value
1148
- : JSON.stringify(value);
1136
+ encodeEventToJson(eventType, payload, access_token) {
1137
+ let encoded = `${eventType}Event=${encodeURIComponent(JSON.stringify(payload))}`;
1138
+ if (access_token) {
1139
+ encoded = `access_token=${encodeURIComponent(access_token)}&${encoded}`;
1140
+ }
1141
+ return encoded;
1149
1142
  }
1150
1143
  }
1151
1144
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coveo.analytics",
3
- "version": "2.28.25",
3
+ "version": "2.29.1",
4
4
  "description": "📈 Coveo analytics client (node and browser compatible) ",
5
5
  "main": "dist/library.cjs",
6
6
  "module": "dist/browser.mjs",
@@ -11,8 +11,8 @@
11
11
  "lint:fix": "prettier --write .",
12
12
  "build": "rollup -c",
13
13
  "start": "rollup -c -w --environment SERVE",
14
- "test": "jest --clearCache && jest --coverage",
15
- "test:watch": "jest --clearCache && jest --watch",
14
+ "test": "jest --clearCache && jest --coverage --silent",
15
+ "test:watch": "jest --clearCache && jest --watch --silent",
16
16
  "prepare-deploy": "mkdir -p deploy && cp dist/coveoua*.js dist/coveoua*.js.map deploy",
17
17
  "clean": "rimraf -rf dist dist_test coverage"
18
18
  },
@@ -41,7 +41,7 @@ describe('AnalyticsBeaconClient', () => {
41
41
  `${baseUrl}/analytics/custom?access_token=👛&visitorId=${currentVisitorId}&discardVisitInfo=true`,
42
42
  expect.anything()
43
43
  );
44
- expect(await getSendBeaconFirstCallBlobArgument()).toBe(`customEvent=${encodeURIComponent(`{"wow":"ok"}`)}`);
44
+ expect(await getSendBeaconFirstCallBlobArgument()).toBe(`customEvent=${encodeURIComponent('{"wow":"ok"}')}`);
45
45
  });
46
46
 
47
47
  it('can send a collect event with the proper payload', async () => {
@@ -66,7 +66,9 @@ describe('AnalyticsBeaconClient', () => {
66
66
  expect.anything()
67
67
  );
68
68
  expect(await getSendBeaconFirstCallBlobArgument()).toBe(
69
- 'access_token=%F0%9F%91%9B&pr1a=value&to%20encode=to%20encode'
69
+ `access_token=${encodeURIComponent('👛')}&collectEvent=${encodeURIComponent(
70
+ '{"pr1a":"value","to encode":"to encode"}'
71
+ )}`
70
72
  );
71
73
  });
72
74
 
@@ -95,7 +97,7 @@ describe('AnalyticsBeaconClient', () => {
95
97
  expect.anything()
96
98
  );
97
99
  expect(await getSendBeaconFirstCallBlobArgument()).toBe(
98
- `access_token=%F0%9F%91%9B&value=${encodeURIComponent(JSON.stringify({subvalue: 'ok'}))}`
100
+ `access_token=${encodeURIComponent('👛')}&collectEvent=${encodeURIComponent('{"value":{"subvalue":"ok"}}')}`
99
101
  );
100
102
  });
101
103
 
@@ -131,7 +133,7 @@ describe('AnalyticsBeaconClient', () => {
131
133
 
132
134
  expect(clientOrigin!).toBe('analyticsBeacon');
133
135
  expect(sendBeaconMock).toHaveBeenCalledWith(processedRequest.url, expect.anything());
134
- expect(await getSendBeaconFirstCallBlobArgument()).toContain('test=custom');
136
+ expect(await getSendBeaconFirstCallBlobArgument()).toContain('%22test%22%3A%22custom%22');
135
137
  });
136
138
 
137
139
  it('to modify the request body as a JSON string for a collect event', async () => {
@@ -144,7 +146,9 @@ describe('AnalyticsBeaconClient', () => {
144
146
  });
145
147
 
146
148
  await client.sendEvent(EventType.collect, {foo: 'bar'});
147
- expect(await getSendBeaconFirstCallBlobArgument()).toContain(`foo=baz`);
149
+ expect(await getSendBeaconFirstCallBlobArgument()).toBe(
150
+ 'access_token=%F0%9F%91%9B&collectEvent=%7B%22foo%22%3A%22baz%22%7D'
151
+ );
148
152
  });
149
153
 
150
154
  it('to modify the request body as a JSON string for a click event', async () => {
@@ -158,7 +162,7 @@ describe('AnalyticsBeaconClient', () => {
158
162
 
159
163
  await client.sendEvent(EventType.click, {actionCause: 'foo'});
160
164
  expect(await getSendBeaconFirstCallBlobArgument()).toContain(
161
- `clickEvent=${encodeURIComponent(`{"actionCause":"bar"}`)}`
165
+ `clickEvent=${encodeURIComponent('{"actionCause":"bar"}')}`
162
166
  );
163
167
  });
164
168
 
@@ -172,7 +176,7 @@ describe('AnalyticsBeaconClient', () => {
172
176
 
173
177
  await client.sendEvent(EventType.click, {actionCause: 'foo'});
174
178
  expect(await getSendBeaconFirstCallBlobArgument()).toContain(
175
- `clickEvent=${encodeURIComponent(`{"actionCause":"foo","aNewProperty":"bar"}`)}`
179
+ `clickEvent=${encodeURIComponent('{"actionCause":"foo","aNewProperty":"bar"}')}`
176
180
  );
177
181
  });
178
182
 
@@ -68,11 +68,8 @@ export class AnalyticsBeaconClient implements AnalyticsRequestClient {
68
68
 
69
69
  private encodeForEventType(eventType: EventType, payload: IRequestPayload): string {
70
70
  return this.isEventTypeLegacy(eventType)
71
- ? this.encodeForLegacyType(eventType, payload)
72
- : this.encodeForFormUrlEncoded({
73
- access_token: this.opts.token,
74
- ...payload,
75
- });
71
+ ? this.encodeEventToJson(eventType, payload)
72
+ : this.encodeEventToJson(eventType, payload, this.opts.token);
76
73
  }
77
74
 
78
75
  private async getQueryParamsForEventType(eventType: EventType): Promise<string> {
@@ -91,20 +88,11 @@ export class AnalyticsBeaconClient implements AnalyticsRequestClient {
91
88
  return [EventType.click, EventType.custom, EventType.search, EventType.view].indexOf(eventType) !== -1;
92
89
  }
93
90
 
94
- private encodeForLegacyType(eventType: EventType, payload: IRequestPayload): string {
95
- return `${eventType}Event=${encodeURIComponent(JSON.stringify(payload))}`;
96
- }
97
-
98
- private encodeForFormUrlEncoded(payload: IRequestPayload): string {
99
- return Object.keys(payload)
100
- .filter((key) => !!payload[key])
101
- .map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(this.encodeValue(payload[key]))}`)
102
- .join('&');
103
- }
104
-
105
- private encodeValue(value: any) {
106
- return typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean'
107
- ? value
108
- : JSON.stringify(value);
91
+ private encodeEventToJson(eventType: EventType, payload: IRequestPayload, access_token?: string): string {
92
+ let encoded = `${eventType}Event=${encodeURIComponent(JSON.stringify(payload))}`;
93
+ if (access_token) {
94
+ encoded = `access_token=${encodeURIComponent(access_token)}&${encoded}`;
95
+ }
96
+ return encoded;
109
97
  }
110
98
  }