coveo.analytics 2.27.9 → 2.27.11

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,6 +10,7 @@ export declare const Endpoints: {
10
10
  export interface ClientOptions {
11
11
  token?: string;
12
12
  endpoint: string;
13
+ isCustomEndpoint?: boolean;
13
14
  version: string;
14
15
  runtimeEnvironment?: IRuntimeEnvironment;
15
16
  beforeSendHooks: AnalyticsClientSendEventHook[];
@@ -55,7 +56,7 @@ export interface BufferedRequest {
55
56
  eventType: EventType;
56
57
  payload: any;
57
58
  }
58
- export declare function buildBaseUrl(endpoint?: string, apiVersion?: string): string;
59
+ export declare function buildBaseUrl(endpoint?: string, apiVersion?: string, isCustomEndpoint?: boolean): string;
59
60
  export declare class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdProvider {
60
61
  private get defaultOptions();
61
62
  runtime: IRuntimeEnvironment;
@@ -5,6 +5,7 @@ import { PluginClass } from '../plugins/BasePlugin';
5
5
  export type AvailableActions = keyof CoveoUA;
6
6
  export interface CoveoUAOptions {
7
7
  endpoint?: string;
8
+ isCustomEndpoint?: boolean;
8
9
  plugins?: string[];
9
10
  }
10
11
  export declare class CoveoUA {
@@ -15,7 +16,8 @@ export declare class CoveoUA {
15
16
  private isAnalyticsClient;
16
17
  private getPluginKeys;
17
18
  private getEndpoint;
18
- initForProxy(endpoint: string): void;
19
+ private getIsCustomEndpoint;
20
+ initForProxy(endpoint: string, isCustomEndpoint?: boolean): void;
19
21
  set(keyOrObject: string | any, value: string): void;
20
22
  send(...[event, ...payload]: SendEventArguments): Promise<AnyEventResponse | void>;
21
23
  onLoad(callback: Function): void;
@@ -5,6 +5,7 @@ import { PluginClass } from '../plugins/BasePlugin';
5
5
  export type AvailableActions = keyof CoveoUA;
6
6
  export interface CoveoUAOptions {
7
7
  endpoint?: string;
8
+ isCustomEndpoint?: boolean;
8
9
  plugins?: string[];
9
10
  }
10
11
  export declare class CoveoUA {
@@ -15,7 +16,8 @@ export declare class CoveoUA {
15
16
  private isAnalyticsClient;
16
17
  private getPluginKeys;
17
18
  private getEndpoint;
18
- initForProxy(endpoint: string): void;
19
+ private getIsCustomEndpoint;
20
+ initForProxy(endpoint: string, isCustomEndpoint?: boolean): void;
19
21
  set(keyOrObject: string | any, value: string): void;
20
22
  send(...[event, ...payload]: SendEventArguments): Promise<AnyEventResponse | void>;
21
23
  onLoad(callback: Function): void;
@@ -1 +1 @@
1
- export declare const libVersion = "2.27.9";
1
+ export declare const libVersion = "2.27.11";
@@ -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.27.9" ;
599
+ const libVersion = "2.27.11" ;
600
600
 
601
601
  const getFormattedLocation = (location) => `${location.protocol}//${location.hostname}${location.pathname.indexOf('/') === 0 ? location.pathname : `/${location.pathname}`}${location.search}`;
602
602
 
@@ -1204,15 +1204,20 @@ const Endpoints = {
1204
1204
  production: 'https://analytics.cloud.coveo.com/rest/ua',
1205
1205
  hipaa: 'https://analyticshipaa.cloud.coveo.com/rest/ua',
1206
1206
  };
1207
- function buildBaseUrl(endpoint = Endpoints.default, apiVersion = Version) {
1208
- const endpointIsCoveoProxy = endpoint.indexOf('.cloud.coveo.com') !== -1;
1209
- return `${endpoint}${endpointIsCoveoProxy ? '' : '/rest'}/${apiVersion}`;
1207
+ function buildBaseUrl(endpoint = Endpoints.default, apiVersion = Version, isCustomEndpoint = false) {
1208
+ endpoint = endpoint.replace(/\/$/, '');
1209
+ if (isCustomEndpoint) {
1210
+ return `${endpoint}/${apiVersion}`;
1211
+ }
1212
+ const hasUARestEndpoint = endpoint.endsWith('/rest') || endpoint.endsWith('/rest/ua');
1213
+ return `${endpoint}${hasUARestEndpoint ? '' : '/rest'}/${apiVersion}`;
1210
1214
  }
1211
1215
  const COVEO_NAMESPACE = '38824e1f-37f5-42d3-8372-a4b8fa9df946';
1212
1216
  class CoveoAnalyticsClient {
1213
1217
  get defaultOptions() {
1214
1218
  return {
1215
1219
  endpoint: Endpoints.default,
1220
+ isCustomEndpoint: false,
1216
1221
  token: '',
1217
1222
  version: Version,
1218
1223
  beforeSendHooks: [],
@@ -1622,7 +1627,7 @@ class CoveoAnalyticsClient {
1622
1627
  return input.substring(0, length);
1623
1628
  }
1624
1629
  get baseUrl() {
1625
- return buildBaseUrl(this.options.endpoint, this.options.version);
1630
+ return buildBaseUrl(this.options.endpoint, this.options.version, this.options.isCustomEndpoint);
1626
1631
  }
1627
1632
  }
1628
1633
 
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.27.9" ;
734
+ var libVersion = "2.27.11" ;
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);
@@ -82996,11 +82996,16 @@ var Endpoints = {
82996
82996
  production: 'https://analytics.cloud.coveo.com/rest/ua',
82997
82997
  hipaa: 'https://analyticshipaa.cloud.coveo.com/rest/ua',
82998
82998
  };
82999
- function buildBaseUrl(endpoint, apiVersion) {
82999
+ function buildBaseUrl(endpoint, apiVersion, isCustomEndpoint) {
83000
83000
  if (endpoint === void 0) { endpoint = Endpoints.default; }
83001
83001
  if (apiVersion === void 0) { apiVersion = Version; }
83002
- var endpointIsCoveoProxy = endpoint.indexOf('.cloud.coveo.com') !== -1;
83003
- return "".concat(endpoint).concat(endpointIsCoveoProxy ? '' : '/rest', "/").concat(apiVersion);
83002
+ if (isCustomEndpoint === void 0) { isCustomEndpoint = false; }
83003
+ endpoint = endpoint.replace(/\/$/, '');
83004
+ if (isCustomEndpoint) {
83005
+ return "".concat(endpoint, "/").concat(apiVersion);
83006
+ }
83007
+ var hasUARestEndpoint = endpoint.endsWith('/rest') || endpoint.endsWith('/rest/ua');
83008
+ return "".concat(endpoint).concat(hasUARestEndpoint ? '' : '/rest', "/").concat(apiVersion);
83004
83009
  }
83005
83010
  var COVEO_NAMESPACE = '38824e1f-37f5-42d3-8372-a4b8fa9df946';
83006
83011
  var CoveoAnalyticsClient = (function () {
@@ -83031,6 +83036,7 @@ var CoveoAnalyticsClient = (function () {
83031
83036
  get: function () {
83032
83037
  return {
83033
83038
  endpoint: Endpoints.default,
83039
+ isCustomEndpoint: false,
83034
83040
  token: '',
83035
83041
  version: Version,
83036
83042
  beforeSendHooks: [],
@@ -83664,7 +83670,7 @@ var CoveoAnalyticsClient = (function () {
83664
83670
  };
83665
83671
  Object.defineProperty(CoveoAnalyticsClient.prototype, "baseUrl", {
83666
83672
  get: function () {
83667
- return buildBaseUrl(this.options.endpoint, this.options.version);
83673
+ return buildBaseUrl(this.options.endpoint, this.options.version, this.options.isCustomEndpoint);
83668
83674
  },
83669
83675
  enumerable: false,
83670
83676
  configurable: true
@@ -83976,6 +83982,7 @@ var CoveoUA = (function () {
83976
83982
  this.client = new CoveoAnalyticsClient({
83977
83983
  token: token,
83978
83984
  endpoint: this.getEndpoint(optionsOrEndpoint),
83985
+ isCustomEndpoint: this.getIsCustomEndpoint(optionsOrEndpoint),
83979
83986
  });
83980
83987
  }
83981
83988
  else if (this.isAnalyticsClient(token)) {
@@ -84012,7 +84019,17 @@ var CoveoUA = (function () {
84012
84019
  }
84013
84020
  return Endpoints.default;
84014
84021
  };
84015
- CoveoUA.prototype.initForProxy = function (endpoint) {
84022
+ CoveoUA.prototype.getIsCustomEndpoint = function (optionsOrEndpoint) {
84023
+ if (typeof optionsOrEndpoint === 'string') {
84024
+ return false;
84025
+ }
84026
+ else if (optionsOrEndpoint === null || optionsOrEndpoint === void 0 ? void 0 : optionsOrEndpoint.isCustomEndpoint) {
84027
+ return optionsOrEndpoint.isCustomEndpoint;
84028
+ }
84029
+ return false;
84030
+ };
84031
+ CoveoUA.prototype.initForProxy = function (endpoint, isCustomEndpoint) {
84032
+ if (isCustomEndpoint === void 0) { isCustomEndpoint = false; }
84016
84033
  if (!endpoint) {
84017
84034
  throw new Error("You must pass your endpoint when you call 'initForProxy'");
84018
84035
  }
@@ -84021,6 +84038,7 @@ var CoveoUA = (function () {
84021
84038
  }
84022
84039
  this.client = new CoveoAnalyticsClient({
84023
84040
  endpoint: endpoint,
84041
+ isCustomEndpoint: isCustomEndpoint,
84024
84042
  });
84025
84043
  };
84026
84044
  CoveoUA.prototype.set = function (keyOrObject, value) {
@@ -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.27.9" ;
661
+ const libVersion = "2.27.11" ;
662
662
 
663
663
  const getFormattedLocation = (location) => `${location.protocol}//${location.hostname}${location.pathname.indexOf('/') === 0 ? location.pathname : `/${location.pathname}`}${location.search}`;
664
664
 
@@ -1205,15 +1205,20 @@ const Endpoints = {
1205
1205
  production: 'https://analytics.cloud.coveo.com/rest/ua',
1206
1206
  hipaa: 'https://analyticshipaa.cloud.coveo.com/rest/ua',
1207
1207
  };
1208
- function buildBaseUrl(endpoint = Endpoints.default, apiVersion = Version) {
1209
- const endpointIsCoveoProxy = endpoint.indexOf('.cloud.coveo.com') !== -1;
1210
- return `${endpoint}${endpointIsCoveoProxy ? '' : '/rest'}/${apiVersion}`;
1208
+ function buildBaseUrl(endpoint = Endpoints.default, apiVersion = Version, isCustomEndpoint = false) {
1209
+ endpoint = endpoint.replace(/\/$/, '');
1210
+ if (isCustomEndpoint) {
1211
+ return `${endpoint}/${apiVersion}`;
1212
+ }
1213
+ const hasUARestEndpoint = endpoint.endsWith('/rest') || endpoint.endsWith('/rest/ua');
1214
+ return `${endpoint}${hasUARestEndpoint ? '' : '/rest'}/${apiVersion}`;
1211
1215
  }
1212
1216
  const COVEO_NAMESPACE = '38824e1f-37f5-42d3-8372-a4b8fa9df946';
1213
1217
  class CoveoAnalyticsClient {
1214
1218
  get defaultOptions() {
1215
1219
  return {
1216
1220
  endpoint: Endpoints.default,
1221
+ isCustomEndpoint: false,
1217
1222
  token: '',
1218
1223
  version: Version,
1219
1224
  beforeSendHooks: [],
@@ -1623,7 +1628,7 @@ class CoveoAnalyticsClient {
1623
1628
  return input.substring(0, length);
1624
1629
  }
1625
1630
  get baseUrl() {
1626
- return buildBaseUrl(this.options.endpoint, this.options.version);
1631
+ return buildBaseUrl(this.options.endpoint, this.options.version, this.options.isCustomEndpoint);
1627
1632
  }
1628
1633
  }
1629
1634
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coveo.analytics",
3
- "version": "2.27.9",
3
+ "version": "2.27.11",
4
4
  "description": "📈 Coveo analytics client (node and browser compatible) ",
5
5
  "main": "dist/library.js",
6
6
  "module": "dist/library.es.js",
@@ -1,4 +1,4 @@
1
- import {EventType, ViewEventRequest, DefaultEventResponse} from '../events';
1
+ import {DefaultEventResponse, EventType, ViewEventRequest} from '../events';
2
2
  import {CoveoAnalyticsClient} from './analytics';
3
3
  import {IAnalyticsRequestOptions} from './analyticsRequestClient';
4
4
  import {CookieAndLocalStorage, CookieStorage, NullStorage} from '../storage';
@@ -58,6 +58,77 @@ describe('Analytics', () => {
58
58
  });
59
59
  });
60
60
 
61
+ it('should add /rest if not present in endpoint', async () => {
62
+ const legacyEndpoint = 'https://usageanalytics.com';
63
+
64
+ client = new CoveoAnalyticsClient({
65
+ token: aToken,
66
+ endpoint: legacyEndpoint,
67
+ version: A_VERSION,
68
+ });
69
+
70
+ fetchMock.post(endpointForEventType(EventType.custom, `${legacyEndpoint}/rest`), eventResponse);
71
+ const response = await client.sendEvent(EventType.custom);
72
+ expect(response).toEqual(eventResponse);
73
+ });
74
+
75
+ it('should not add /rest if /rest present in endpoint', async () => {
76
+ const legacyEndpoint = 'https://usageanalytics.com/rest';
77
+
78
+ client = new CoveoAnalyticsClient({
79
+ token: aToken,
80
+ endpoint: legacyEndpoint,
81
+ version: A_VERSION,
82
+ });
83
+
84
+ fetchMock.post(endpointForEventType(EventType.custom, legacyEndpoint), eventResponse);
85
+ const response = await client.sendEvent(EventType.custom);
86
+ expect(response).toEqual(eventResponse);
87
+ });
88
+
89
+ it('should not add /rest if /rest/ua present in endpoint', async () => {
90
+ const legacyEndpoint = 'https://usageanalytics.com/rest/ua';
91
+
92
+ client = new CoveoAnalyticsClient({
93
+ token: aToken,
94
+ endpoint: legacyEndpoint,
95
+ version: A_VERSION,
96
+ });
97
+
98
+ fetchMock.post(endpointForEventType(EventType.custom, legacyEndpoint), eventResponse);
99
+ const response = await client.sendEvent(EventType.custom);
100
+ expect(response).toEqual(eventResponse);
101
+ });
102
+
103
+ it('should remove trailing slash in endpoint', async () => {
104
+ const legacyEndpoint = 'https://usageanalytics.com';
105
+
106
+ client = new CoveoAnalyticsClient({
107
+ token: aToken,
108
+ endpoint: legacyEndpoint + '/',
109
+ version: A_VERSION,
110
+ });
111
+
112
+ fetchMock.post(endpointForEventType(EventType.custom, `${legacyEndpoint}/rest`), eventResponse);
113
+ const response = await client.sendEvent(EventType.custom);
114
+ expect(response).toEqual(eventResponse);
115
+ });
116
+
117
+ it('should allow reverse-proxy endpoint', async () => {
118
+ const aReverseProxyEndpoint = 'https://12364734.cloudfront.net/analytics';
119
+
120
+ client = new CoveoAnalyticsClient({
121
+ token: aToken,
122
+ endpoint: aReverseProxyEndpoint,
123
+ isCustomEndpoint: true,
124
+ version: A_VERSION,
125
+ });
126
+
127
+ fetchMock.post(endpointForEventType(EventType.custom, aReverseProxyEndpoint), eventResponse);
128
+ const response = await client.sendEvent(EventType.custom);
129
+ expect(response).toEqual(eventResponse);
130
+ });
131
+
61
132
  it('should call fetch with the parameters', async () => {
62
133
  mockFetchRequestForEventType(EventType.view);
63
134
 
@@ -49,6 +49,7 @@ export const Endpoints = {
49
49
  export interface ClientOptions {
50
50
  token?: string;
51
51
  endpoint: string;
52
+ isCustomEndpoint?: boolean;
52
53
  version: string;
53
54
  runtimeEnvironment?: IRuntimeEnvironment;
54
55
  beforeSendHooks: AnalyticsClientSendEventHook[];
@@ -117,9 +118,16 @@ export interface BufferedRequest {
117
118
  type ProcessPayloadStep = (currentPayload: any) => any;
118
119
  type AsyncProcessPayloadStep = (currentPayload: any) => Promise<any>;
119
120
 
120
- export function buildBaseUrl(endpoint = Endpoints.default, apiVersion = Version) {
121
- const endpointIsCoveoProxy = endpoint.indexOf('.cloud.coveo.com') !== -1;
122
- return `${endpoint}${endpointIsCoveoProxy ? '' : '/rest'}/${apiVersion}`;
121
+ export function buildBaseUrl(endpoint = Endpoints.default, apiVersion = Version, isCustomEndpoint = false) {
122
+ endpoint = endpoint.replace(/\/$/, ''); // Remove trailing slash in endpoint.
123
+
124
+ if (isCustomEndpoint) {
125
+ return `${endpoint}/${apiVersion}`;
126
+ }
127
+
128
+ const hasUARestEndpoint = endpoint.endsWith('/rest') || endpoint.endsWith('/rest/ua');
129
+
130
+ return `${endpoint}${hasUARestEndpoint ? '' : '/rest'}/${apiVersion}`;
123
131
  }
124
132
 
125
133
  // Note: Changing this value will destroy the mapping from tracking string to clientId for all customers
@@ -131,6 +139,7 @@ export class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdProvider
131
139
  private get defaultOptions(): ClientOptions {
132
140
  return {
133
141
  endpoint: Endpoints.default,
142
+ isCustomEndpoint: false,
134
143
  token: '',
135
144
  version: Version,
136
145
  beforeSendHooks: [],
@@ -622,7 +631,7 @@ export class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdProvider
622
631
  }
623
632
 
624
633
  private get baseUrl(): string {
625
- return buildBaseUrl(this.options.endpoint, this.options.version);
634
+ return buildBaseUrl(this.options.endpoint, this.options.version, this.options.isCustomEndpoint);
626
635
  }
627
636
  }
628
637
 
@@ -9,6 +9,7 @@ export type AvailableActions = keyof CoveoUA;
9
9
 
10
10
  export interface CoveoUAOptions {
11
11
  endpoint?: string;
12
+ isCustomEndpoint?: boolean;
12
13
  plugins?: string[];
13
14
  }
14
15
 
@@ -31,6 +32,7 @@ export class CoveoUA {
31
32
  this.client = new CoveoAnalyticsClient({
32
33
  token: token,
33
34
  endpoint: this.getEndpoint(optionsOrEndpoint),
35
+ isCustomEndpoint: this.getIsCustomEndpoint(optionsOrEndpoint),
34
36
  });
35
37
  } else if (this.isAnalyticsClient(token)) {
36
38
  this.client = token;
@@ -72,9 +74,18 @@ export class CoveoUA {
72
74
  return Endpoints.default;
73
75
  }
74
76
 
77
+ private getIsCustomEndpoint(optionsOrEndpoint: string | CoveoUAOptions) {
78
+ if (typeof optionsOrEndpoint === 'string') {
79
+ return false;
80
+ } else if (optionsOrEndpoint?.isCustomEndpoint) {
81
+ return optionsOrEndpoint.isCustomEndpoint;
82
+ }
83
+ return false;
84
+ }
85
+
75
86
  // init initializes a new client intended to be used with a proxy that injects the access token.
76
87
  // @param endpoint is the endpoint of your proxy.
77
- initForProxy(endpoint: string): void {
88
+ initForProxy(endpoint: string, isCustomEndpoint = false): void {
78
89
  if (!endpoint) {
79
90
  throw new Error(`You must pass your endpoint when you call 'initForProxy'`);
80
91
  }
@@ -85,6 +96,7 @@ export class CoveoUA {
85
96
 
86
97
  this.client = new CoveoAnalyticsClient({
87
98
  endpoint: endpoint,
99
+ isCustomEndpoint: isCustomEndpoint,
88
100
  });
89
101
  }
90
102