@coveo/relay 0.3.2 → 0.4.0

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.
package/lib/relay.cjs CHANGED
@@ -16,7 +16,6 @@ async function callEventApi({ event, config, environment, }) {
16
16
  const data = await response.json();
17
17
  if (!response.ok) {
18
18
  throw new Error({
19
- responseType: "serviceError",
20
19
  ...data,
21
20
  });
22
21
  }
@@ -27,18 +26,6 @@ async function emit(params) {
27
26
  await callEventApi(params);
28
27
  }
29
28
 
30
- /**
31
- * @todo LENS-1059: The clientId should be a value that is persisted over time on a device.
32
- */
33
- function getClientId(environment) {
34
- return environment.generateUUID();
35
- }
36
- function createClientIdManager(environment) {
37
- return {
38
- clientId: getClientId(environment),
39
- };
40
- }
41
-
42
29
  const rnds8Pool = new Uint8Array(256); // # of random values to pre-allocate
43
30
 
44
31
  let poolPtr = rnds8Pool.length;
@@ -51,6 +38,12 @@ function rng() {
51
38
  return rnds8Pool.slice(poolPtr, poolPtr += 16);
52
39
  }
53
40
 
41
+ var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
42
+
43
+ function validate$1(uuid) {
44
+ return typeof uuid === 'string' && REGEX.test(uuid);
45
+ }
46
+
54
47
  /**
55
48
  * Convert array of 16 byte values to UUID string format of the form:
56
49
  * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
@@ -96,6 +89,70 @@ function v4(options, buf, offset) {
96
89
  return unsafeStringify(rnds);
97
90
  }
98
91
 
92
+ function getClientId(environment) {
93
+ const storage = environment.storage;
94
+ const key = "visitorId";
95
+ const existingClientId = storage.getItem(key);
96
+ const clientId = existingClientId && validate$1(existingClientId)
97
+ ? existingClientId
98
+ : environment.generateUUID();
99
+ storage.setItem(key, clientId);
100
+ return clientId;
101
+ }
102
+ function createClientIdManager(environment) {
103
+ return {
104
+ clientId: getClientId(environment),
105
+ };
106
+ }
107
+
108
+ const cookieManager = createCookieManager();
109
+ function createCookieManager() {
110
+ const prefix = "coveo_";
111
+ const getDomain = (host) => {
112
+ const parts = host.split(".").slice(-2);
113
+ return parts.length == 2 ? parts.join(".") : "";
114
+ };
115
+ return {
116
+ getItem(key) {
117
+ const cookiePrefix = `${prefix}${key}=`;
118
+ const cookieArray = document.cookie.split(";");
119
+ for (const cookie of cookieArray) {
120
+ const prettifyCookie = cookie.replace(/^\s+/, "");
121
+ if (prettifyCookie.lastIndexOf(cookiePrefix, 0) === 0) {
122
+ return prettifyCookie.substring(cookiePrefix.length, prettifyCookie.length);
123
+ }
124
+ }
125
+ return null;
126
+ },
127
+ setItem(key, data, expire) {
128
+ const domain = getDomain(window.location.hostname);
129
+ const expireSection = `;expires=${new Date(new Date().getTime() + expire).toUTCString()}`;
130
+ const domainSection = domain ? `;domain=${domain}` : "";
131
+ document.cookie = `${prefix}${key}=${data}${expireSection}${domainSection};path=/;SameSite=Lax`;
132
+ },
133
+ removeItem(key) {
134
+ this.setItem(key, "", -1);
135
+ },
136
+ };
137
+ }
138
+
139
+ function createBrowserStorage() {
140
+ return {
141
+ getItem(key) {
142
+ return cookieManager.getItem(key) || localStorage.getItem(key);
143
+ },
144
+ removeItem(key) {
145
+ cookieManager.removeItem(key);
146
+ localStorage.removeItem(key);
147
+ },
148
+ setItem(key, data) {
149
+ const oneYear = 31556952000;
150
+ localStorage.setItem(key, data);
151
+ cookieManager.setItem(key, data, oneYear);
152
+ },
153
+ };
154
+ }
155
+
99
156
  function getReferrerUrl() {
100
157
  const referrer = document.referrer;
101
158
  return referrer === "" ? null : referrer;
@@ -108,6 +165,21 @@ function buildBrowserEnvironment() {
108
165
  getUrl: () => window.location.href,
109
166
  getUserAgent: () => navigator.userAgent,
110
167
  generateUUID: () => v4(),
168
+ storage: createBrowserStorage(),
169
+ };
170
+ }
171
+
172
+ function createNullStorage() {
173
+ return {
174
+ getItem() {
175
+ return null;
176
+ },
177
+ removeItem() {
178
+ return;
179
+ },
180
+ setItem() {
181
+ return;
182
+ },
111
183
  };
112
184
  }
113
185
 
@@ -119,6 +191,7 @@ function buildNodeEnvironment() {
119
191
  getUrl: () => null,
120
192
  getUserAgent: () => null,
121
193
  generateUUID: () => v4(),
194
+ storage: createNullStorage(),
122
195
  };
123
196
  }
124
197
 
@@ -134,7 +207,7 @@ function isBrowser() {
134
207
  }
135
208
  }
136
209
 
137
- const version = "0.3.2" ;
210
+ const version = "0.4.0" ;
138
211
 
139
212
  function getEventConfig(config) {
140
213
  const { trackingId } = config;
@@ -166,12 +239,6 @@ function createRelayEvent(type, payload, config, environment, clientIdManager) {
166
239
  };
167
240
  }
168
241
 
169
- async function validate(params) {
170
- const data = await callEventApi(params);
171
- const { valid, errors } = data[0];
172
- return { valid, errors: errors ?? [], responseType: "validation" };
173
- }
174
-
175
242
  const ANY_EVENT_TYPE = "*";
176
243
  function createListenerManager() {
177
244
  const listeners = [];
@@ -246,29 +313,25 @@ function createConfigManager(initialConfig) {
246
313
  };
247
314
  }
248
315
 
316
+ async function validate(params) {
317
+ const data = await callEventApi(params);
318
+ const { valid, errors } = data[0];
319
+ return { valid, errors: errors ?? [] };
320
+ }
321
+
249
322
  function createRelay(initialConfig) {
250
323
  const environment = currentEnvironment();
251
324
  const clientIdManager = createClientIdManager(environment);
252
325
  const configManager = createConfigManager(initialConfig);
253
326
  const { add, call, remove } = createListenerManager();
254
327
  return {
255
- validate: (type, payload) => {
256
- const event = createRelayEvent(type, payload, configManager.get(), environment, clientIdManager);
257
- call(event);
258
- return validate({
259
- config: configManager.get(),
260
- environment,
261
- event,
262
- });
263
- },
264
328
  emit: (type, payload) => {
265
329
  const event = createRelayEvent(type, payload, configManager.get(), environment, clientIdManager);
266
330
  call(event);
267
- return emit({
268
- config: configManager.get(),
269
- environment,
270
- event,
271
- });
331
+ const params = { config: configManager.get(), environment, event };
332
+ return configManager.get().mode === "validate"
333
+ ? validate(params)
334
+ : emit(params);
272
335
  },
273
336
  getMeta: (type) => createMeta(type, configManager.get(), environment, clientIdManager),
274
337
  on: (type, callback) => add({ type, callback }),
package/lib/relay.js CHANGED
@@ -12,7 +12,6 @@ async function callEventApi({ event, config, environment, }) {
12
12
  const data = await response.json();
13
13
  if (!response.ok) {
14
14
  throw new Error({
15
- responseType: "serviceError",
16
15
  ...data,
17
16
  });
18
17
  }
@@ -23,18 +22,6 @@ async function emit(params) {
23
22
  await callEventApi(params);
24
23
  }
25
24
 
26
- /**
27
- * @todo LENS-1059: The clientId should be a value that is persisted over time on a device.
28
- */
29
- function getClientId(environment) {
30
- return environment.generateUUID();
31
- }
32
- function createClientIdManager(environment) {
33
- return {
34
- clientId: getClientId(environment),
35
- };
36
- }
37
-
38
25
  // Unique ID creation requires a high quality random # generator. In the browser we therefore
39
26
  // require the crypto API and do not support built-in fallback to lower quality random number
40
27
  // generators (like Math.random()).
@@ -54,6 +41,12 @@ function rng() {
54
41
  return getRandomValues(rnds8);
55
42
  }
56
43
 
44
+ var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
45
+
46
+ function validate$1(uuid) {
47
+ return typeof uuid === 'string' && REGEX.test(uuid);
48
+ }
49
+
57
50
  /**
58
51
  * Convert array of 16 byte values to UUID string format of the form:
59
52
  * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
@@ -100,6 +93,70 @@ function v4(options, buf, offset) {
100
93
  return unsafeStringify(rnds);
101
94
  }
102
95
 
96
+ function getClientId(environment) {
97
+ const storage = environment.storage;
98
+ const key = "visitorId";
99
+ const existingClientId = storage.getItem(key);
100
+ const clientId = existingClientId && validate$1(existingClientId)
101
+ ? existingClientId
102
+ : environment.generateUUID();
103
+ storage.setItem(key, clientId);
104
+ return clientId;
105
+ }
106
+ function createClientIdManager(environment) {
107
+ return {
108
+ clientId: getClientId(environment),
109
+ };
110
+ }
111
+
112
+ const cookieManager = createCookieManager();
113
+ function createCookieManager() {
114
+ const prefix = "coveo_";
115
+ const getDomain = (host) => {
116
+ const parts = host.split(".").slice(-2);
117
+ return parts.length == 2 ? parts.join(".") : "";
118
+ };
119
+ return {
120
+ getItem(key) {
121
+ const cookiePrefix = `${prefix}${key}=`;
122
+ const cookieArray = document.cookie.split(";");
123
+ for (const cookie of cookieArray) {
124
+ const prettifyCookie = cookie.replace(/^\s+/, "");
125
+ if (prettifyCookie.lastIndexOf(cookiePrefix, 0) === 0) {
126
+ return prettifyCookie.substring(cookiePrefix.length, prettifyCookie.length);
127
+ }
128
+ }
129
+ return null;
130
+ },
131
+ setItem(key, data, expire) {
132
+ const domain = getDomain(window.location.hostname);
133
+ const expireSection = `;expires=${new Date(new Date().getTime() + expire).toUTCString()}`;
134
+ const domainSection = domain ? `;domain=${domain}` : "";
135
+ document.cookie = `${prefix}${key}=${data}${expireSection}${domainSection};path=/;SameSite=Lax`;
136
+ },
137
+ removeItem(key) {
138
+ this.setItem(key, "", -1);
139
+ },
140
+ };
141
+ }
142
+
143
+ function createBrowserStorage() {
144
+ return {
145
+ getItem(key) {
146
+ return cookieManager.getItem(key) || localStorage.getItem(key);
147
+ },
148
+ removeItem(key) {
149
+ cookieManager.removeItem(key);
150
+ localStorage.removeItem(key);
151
+ },
152
+ setItem(key, data) {
153
+ const oneYear = 31556952000;
154
+ localStorage.setItem(key, data);
155
+ cookieManager.setItem(key, data, oneYear);
156
+ },
157
+ };
158
+ }
159
+
103
160
  function getReferrerUrl() {
104
161
  const referrer = document.referrer;
105
162
  return referrer === "" ? null : referrer;
@@ -112,6 +169,21 @@ function buildBrowserEnvironment() {
112
169
  getUrl: () => window.location.href,
113
170
  getUserAgent: () => navigator.userAgent,
114
171
  generateUUID: () => v4(),
172
+ storage: createBrowserStorage(),
173
+ };
174
+ }
175
+
176
+ function createNullStorage() {
177
+ return {
178
+ getItem() {
179
+ return null;
180
+ },
181
+ removeItem() {
182
+ return;
183
+ },
184
+ setItem() {
185
+ return;
186
+ },
115
187
  };
116
188
  }
117
189
 
@@ -123,6 +195,7 @@ function buildNodeEnvironment() {
123
195
  getUrl: () => null,
124
196
  getUserAgent: () => null,
125
197
  generateUUID: () => v4(),
198
+ storage: createNullStorage(),
126
199
  };
127
200
  }
128
201
 
@@ -138,7 +211,7 @@ function isBrowser() {
138
211
  }
139
212
  }
140
213
 
141
- const version = "0.3.2" ;
214
+ const version = "0.4.0" ;
142
215
 
143
216
  function getEventConfig(config) {
144
217
  const { trackingId } = config;
@@ -170,12 +243,6 @@ function createRelayEvent(type, payload, config, environment, clientIdManager) {
170
243
  };
171
244
  }
172
245
 
173
- async function validate(params) {
174
- const data = await callEventApi(params);
175
- const { valid, errors } = data[0];
176
- return { valid, errors: errors ?? [], responseType: "validation" };
177
- }
178
-
179
246
  const ANY_EVENT_TYPE = "*";
180
247
  function createListenerManager() {
181
248
  const listeners = [];
@@ -250,29 +317,25 @@ function createConfigManager(initialConfig) {
250
317
  };
251
318
  }
252
319
 
320
+ async function validate(params) {
321
+ const data = await callEventApi(params);
322
+ const { valid, errors } = data[0];
323
+ return { valid, errors: errors ?? [] };
324
+ }
325
+
253
326
  function createRelay(initialConfig) {
254
327
  const environment = currentEnvironment();
255
328
  const clientIdManager = createClientIdManager(environment);
256
329
  const configManager = createConfigManager(initialConfig);
257
330
  const { add, call, remove } = createListenerManager();
258
331
  return {
259
- validate: (type, payload) => {
260
- const event = createRelayEvent(type, payload, configManager.get(), environment, clientIdManager);
261
- call(event);
262
- return validate({
263
- config: configManager.get(),
264
- environment,
265
- event,
266
- });
267
- },
268
332
  emit: (type, payload) => {
269
333
  const event = createRelayEvent(type, payload, configManager.get(), environment, clientIdManager);
270
334
  call(event);
271
- return emit({
272
- config: configManager.get(),
273
- environment,
274
- event,
275
- });
335
+ const params = { config: configManager.get(), environment, event };
336
+ return configManager.get().mode === "validate"
337
+ ? validate(params)
338
+ : emit(params);
276
339
  },
277
340
  getMeta: (type) => createMeta(type, configManager.get(), environment, clientIdManager),
278
341
  on: (type, callback) => add({ type, callback }),
package/lib/relay.mjs CHANGED
@@ -14,7 +14,6 @@ async function callEventApi({ event, config, environment, }) {
14
14
  const data = await response.json();
15
15
  if (!response.ok) {
16
16
  throw new Error({
17
- responseType: "serviceError",
18
17
  ...data,
19
18
  });
20
19
  }
@@ -25,18 +24,6 @@ async function emit(params) {
25
24
  await callEventApi(params);
26
25
  }
27
26
 
28
- /**
29
- * @todo LENS-1059: The clientId should be a value that is persisted over time on a device.
30
- */
31
- function getClientId(environment) {
32
- return environment.generateUUID();
33
- }
34
- function createClientIdManager(environment) {
35
- return {
36
- clientId: getClientId(environment),
37
- };
38
- }
39
-
40
27
  const rnds8Pool = new Uint8Array(256); // # of random values to pre-allocate
41
28
 
42
29
  let poolPtr = rnds8Pool.length;
@@ -49,6 +36,12 @@ function rng() {
49
36
  return rnds8Pool.slice(poolPtr, poolPtr += 16);
50
37
  }
51
38
 
39
+ var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
40
+
41
+ function validate$1(uuid) {
42
+ return typeof uuid === 'string' && REGEX.test(uuid);
43
+ }
44
+
52
45
  /**
53
46
  * Convert array of 16 byte values to UUID string format of the form:
54
47
  * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
@@ -94,6 +87,70 @@ function v4(options, buf, offset) {
94
87
  return unsafeStringify(rnds);
95
88
  }
96
89
 
90
+ function getClientId(environment) {
91
+ const storage = environment.storage;
92
+ const key = "visitorId";
93
+ const existingClientId = storage.getItem(key);
94
+ const clientId = existingClientId && validate$1(existingClientId)
95
+ ? existingClientId
96
+ : environment.generateUUID();
97
+ storage.setItem(key, clientId);
98
+ return clientId;
99
+ }
100
+ function createClientIdManager(environment) {
101
+ return {
102
+ clientId: getClientId(environment),
103
+ };
104
+ }
105
+
106
+ const cookieManager = createCookieManager();
107
+ function createCookieManager() {
108
+ const prefix = "coveo_";
109
+ const getDomain = (host) => {
110
+ const parts = host.split(".").slice(-2);
111
+ return parts.length == 2 ? parts.join(".") : "";
112
+ };
113
+ return {
114
+ getItem(key) {
115
+ const cookiePrefix = `${prefix}${key}=`;
116
+ const cookieArray = document.cookie.split(";");
117
+ for (const cookie of cookieArray) {
118
+ const prettifyCookie = cookie.replace(/^\s+/, "");
119
+ if (prettifyCookie.lastIndexOf(cookiePrefix, 0) === 0) {
120
+ return prettifyCookie.substring(cookiePrefix.length, prettifyCookie.length);
121
+ }
122
+ }
123
+ return null;
124
+ },
125
+ setItem(key, data, expire) {
126
+ const domain = getDomain(window.location.hostname);
127
+ const expireSection = `;expires=${new Date(new Date().getTime() + expire).toUTCString()}`;
128
+ const domainSection = domain ? `;domain=${domain}` : "";
129
+ document.cookie = `${prefix}${key}=${data}${expireSection}${domainSection};path=/;SameSite=Lax`;
130
+ },
131
+ removeItem(key) {
132
+ this.setItem(key, "", -1);
133
+ },
134
+ };
135
+ }
136
+
137
+ function createBrowserStorage() {
138
+ return {
139
+ getItem(key) {
140
+ return cookieManager.getItem(key) || localStorage.getItem(key);
141
+ },
142
+ removeItem(key) {
143
+ cookieManager.removeItem(key);
144
+ localStorage.removeItem(key);
145
+ },
146
+ setItem(key, data) {
147
+ const oneYear = 31556952000;
148
+ localStorage.setItem(key, data);
149
+ cookieManager.setItem(key, data, oneYear);
150
+ },
151
+ };
152
+ }
153
+
97
154
  function getReferrerUrl() {
98
155
  const referrer = document.referrer;
99
156
  return referrer === "" ? null : referrer;
@@ -106,6 +163,21 @@ function buildBrowserEnvironment() {
106
163
  getUrl: () => window.location.href,
107
164
  getUserAgent: () => navigator.userAgent,
108
165
  generateUUID: () => v4(),
166
+ storage: createBrowserStorage(),
167
+ };
168
+ }
169
+
170
+ function createNullStorage() {
171
+ return {
172
+ getItem() {
173
+ return null;
174
+ },
175
+ removeItem() {
176
+ return;
177
+ },
178
+ setItem() {
179
+ return;
180
+ },
109
181
  };
110
182
  }
111
183
 
@@ -117,6 +189,7 @@ function buildNodeEnvironment() {
117
189
  getUrl: () => null,
118
190
  getUserAgent: () => null,
119
191
  generateUUID: () => v4(),
192
+ storage: createNullStorage(),
120
193
  };
121
194
  }
122
195
 
@@ -132,7 +205,7 @@ function isBrowser() {
132
205
  }
133
206
  }
134
207
 
135
- const version = "0.3.2" ;
208
+ const version = "0.4.0" ;
136
209
 
137
210
  function getEventConfig(config) {
138
211
  const { trackingId } = config;
@@ -164,12 +237,6 @@ function createRelayEvent(type, payload, config, environment, clientIdManager) {
164
237
  };
165
238
  }
166
239
 
167
- async function validate(params) {
168
- const data = await callEventApi(params);
169
- const { valid, errors } = data[0];
170
- return { valid, errors: errors ?? [], responseType: "validation" };
171
- }
172
-
173
240
  const ANY_EVENT_TYPE = "*";
174
241
  function createListenerManager() {
175
242
  const listeners = [];
@@ -244,29 +311,25 @@ function createConfigManager(initialConfig) {
244
311
  };
245
312
  }
246
313
 
314
+ async function validate(params) {
315
+ const data = await callEventApi(params);
316
+ const { valid, errors } = data[0];
317
+ return { valid, errors: errors ?? [] };
318
+ }
319
+
247
320
  function createRelay(initialConfig) {
248
321
  const environment = currentEnvironment();
249
322
  const clientIdManager = createClientIdManager(environment);
250
323
  const configManager = createConfigManager(initialConfig);
251
324
  const { add, call, remove } = createListenerManager();
252
325
  return {
253
- validate: (type, payload) => {
254
- const event = createRelayEvent(type, payload, configManager.get(), environment, clientIdManager);
255
- call(event);
256
- return validate({
257
- config: configManager.get(),
258
- environment,
259
- event,
260
- });
261
- },
262
326
  emit: (type, payload) => {
263
327
  const event = createRelayEvent(type, payload, configManager.get(), environment, clientIdManager);
264
328
  call(event);
265
- return emit({
266
- config: configManager.get(),
267
- environment,
268
- event,
269
- });
329
+ const params = { config: configManager.get(), environment, event };
330
+ return configManager.get().mode === "validate"
331
+ ? validate(params)
332
+ : emit(params);
270
333
  },
271
334
  getMeta: (type) => createMeta(type, configManager.get(), environment, clientIdManager),
272
335
  on: (type, callback) => add({ type, callback }),
@@ -1 +1 @@
1
- {"version":3,"file":"client-id.d.ts","sourceRoot":"","sources":["../../../src/client-id/client-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEzD,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;CAClB;AASD,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,WAAW,GACvB,eAAe,CAIjB"}
1
+ {"version":3,"file":"client-id.d.ts","sourceRoot":"","sources":["../../../src/client-id/client-id.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEzD,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAeD,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,WAAW,GACvB,eAAe,CAIjB"}
@@ -1 +1 @@
1
- {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../../src/environment/browser/browser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAQ7C,wBAAgB,uBAAuB,IAAI,WAAW,CASrD"}
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../../src/environment/browser/browser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAS7C,wBAAgB,uBAAuB,IAAI,WAAW,CAUrD"}
@@ -0,0 +1,7 @@
1
+ export interface CookieManager {
2
+ getItem: (key: string) => string | null;
3
+ removeItem: (key: string) => void;
4
+ setItem: (key: string, data: string, expire: number) => void;
5
+ }
6
+ export declare const cookieManager: CookieManager;
7
+ //# sourceMappingURL=cookie.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../../../../src/environment/browser/storage/cookie.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;IACxC,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9D;AAED,eAAO,MAAM,aAAa,EAAE,aAAqC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Storage } from "../../storage";
2
+ export declare function createBrowserStorage(): Storage;
3
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../../../src/environment/browser/storage/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAGxC,wBAAgB,oBAAoB,IAAI,OAAO,CAiB9C"}
@@ -1,3 +1,4 @@
1
+ import { Storage } from "./storage";
1
2
  export interface Environment {
2
3
  runtime: "browser" | "node";
3
4
  fetch: (url: string, init?: RequestInit) => Promise<Response>;
@@ -5,6 +6,7 @@ export interface Environment {
5
6
  getUrl: () => string | null;
6
7
  getUserAgent: () => string | null;
7
8
  generateUUID: () => string;
9
+ storage: Storage;
8
10
  }
9
11
  export declare function currentEnvironment(): Environment;
10
12
  //# sourceMappingURL=environment.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../../src/environment/environment.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,SAAS,GAAG,MAAM,CAAC;IAC5B,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9D,cAAc,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACpC,MAAM,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAC5B,YAAY,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAClC,YAAY,EAAE,MAAM,MAAM,CAAC;CAC5B;AAED,wBAAgB,kBAAkB,IAAI,WAAW,CAEhD"}
1
+ {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../../src/environment/environment.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,SAAS,GAAG,MAAM,CAAC;IAC5B,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9D,cAAc,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACpC,MAAM,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAC5B,YAAY,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAClC,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,kBAAkB,IAAI,WAAW,CAEhD"}
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../../src/environment/node/node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,wBAAgB,oBAAoB,IAAI,WAAW,CASlD"}
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../../src/environment/node/node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C,wBAAgB,oBAAoB,IAAI,WAAW,CAUlD"}
@@ -0,0 +1,7 @@
1
+ export interface Storage {
2
+ getItem: (key: string) => string | null;
3
+ removeItem: (key: string) => void;
4
+ setItem: (key: string, data: string) => void;
5
+ }
6
+ export declare function createNullStorage(): Storage;
7
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/environment/storage.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;IACxC,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9C;AAED,wBAAgB,iBAAiB,IAAI,OAAO,CAY3C"}
@@ -1 +1 @@
1
- {"version":3,"file":"event-api-caller.d.ts","sourceRoot":"","sources":["../../../src/event-api-call/event-api-caller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,WAAW,CAAC;IACpB,WAAW,EAAE,WAAW,CAAC;IACzB,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;CAC7B;AAED,wBAAsB,YAAY,CAAC,EACjC,KAAK,EACL,MAAM,EACN,WAAW,GACZ,EAAE,kBAAkB,GAAG,OAAO,CAAC,GAAG,CAAC,CA2BnC"}
1
+ {"version":3,"file":"event-api-caller.d.ts","sourceRoot":"","sources":["../../../src/event-api-call/event-api-caller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,WAAW,CAAC;IACpB,WAAW,EAAE,WAAW,CAAC;IACzB,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;CAC7B;AAED,wBAAsB,YAAY,CAAC,EACjC,KAAK,EACL,MAAM,EACN,WAAW,GACZ,EAAE,kBAAkB,GAAG,OAAO,CAAC,GAAG,CAAC,CA0BnC"}
@@ -1,12 +1,11 @@
1
- import { ValidationError, ValidationResponse } from "./validate/validate";
2
1
  import { Meta } from "./event/meta/meta";
3
2
  import { EventCallback } from "./listener/listener";
4
3
  import { RelayConfig } from "./config/config";
4
+ import { ValidationError, ValidationResponse } from "./validate/validate";
5
5
  type RelayPayload = Record<string, unknown>;
6
6
  type Off = () => void;
7
7
  interface Relay {
8
- validate: (type: string, payload: RelayPayload) => Promise<ValidationResponse>;
9
- emit: (type: string, payload: RelayPayload) => Promise<void>;
8
+ emit: (type: string, payload: RelayPayload) => Promise<void | ValidationResponse>;
10
9
  getMeta: (type: string) => Meta;
11
10
  on: (type: string, callback: EventCallback) => Off;
12
11
  off: (type: string, callback?: EventCallback) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"relay.d.ts","sourceRoot":"","sources":["../../src/relay.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,eAAe,EACf,kBAAkB,EACnB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAc,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAyB,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAuB,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnE,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC5C,KAAK,GAAG,GAAG,MAAM,IAAI,CAAC;AAEtB,UAAU,KAAK;IACb,QAAQ,EAAE,CACR,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,YAAY,KAClB,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACjC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7D,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,EAAE,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,KAAK,GAAG,CAAC;IACnD,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IACtD,YAAY,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;IACrD,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,WAAW,CAAC,aAAa,EAAE,WAAW,GAAG,KAAK,CAiD7D;AAED,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,kBAAkB,EAAE,CAAC"}
1
+ {"version":3,"file":"relay.d.ts","sourceRoot":"","sources":["../../src/relay.ts"],"names":[],"mappings":"AAKA,OAAO,EAAc,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAyB,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAuB,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAEL,eAAe,EACf,kBAAkB,EACnB,MAAM,qBAAqB,CAAC;AAE7B,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC5C,KAAK,GAAG,GAAG,MAAM,IAAI,CAAC;AAEtB,UAAU,KAAK;IACb,IAAI,EAAE,CACJ,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,YAAY,KAClB,OAAO,CAAC,IAAI,GAAG,kBAAkB,CAAC,CAAC;IACxC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,EAAE,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,KAAK,GAAG,CAAC;IACnD,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IACtD,YAAY,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;IACrD,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,WAAW,CAAC,aAAa,EAAE,WAAW,GAAG,KAAK,CAgC7D;AAED,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,kBAAkB,EAAE,CAAC"}
@@ -6,7 +6,6 @@ export interface ValidationError {
6
6
  }
7
7
  export interface ValidationResponse {
8
8
  valid: boolean;
9
- responseType: "validation";
10
9
  errors: ValidationError[];
11
10
  }
12
11
  export declare function validate(params: EventApiCallParams): Promise<Readonly<ValidationResponse>>;
@@ -1 +1 @@
1
- {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../src/validate/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EACnB,MAAM,oCAAoC,CAAC;AAE5C,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,OAAO,CAAC;IACf,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,EAAE,eAAe,EAAE,CAAC;CAC3B;AAED,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,CAMvC"}
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../src/validate/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EACnB,MAAM,oCAAoC,CAAC;AAE5C,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,eAAe,EAAE,CAAC;CAC3B;AAED,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,CAMvC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coveo/relay",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "description": "A library for sending analytics events using Coveo's Event protocol.",
5
5
  "files": [
6
6
  "lib/**/*"