@coveo/relay 0.0.6 → 0.1.2
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 +194 -0
- package/lib/relay.js +198 -0
- package/lib/relay.mjs +192 -0
- package/lib/types/client-id/client-id.d.ts +6 -0
- package/lib/types/client-id/client-id.d.ts.map +1 -0
- package/lib/types/emit/emit.d.ts +3 -0
- package/lib/types/emit/emit.d.ts.map +1 -0
- package/lib/types/environment/browser/browser.d.ts +3 -0
- package/lib/types/environment/browser/browser.d.ts.map +1 -0
- package/lib/types/environment/environment.d.ts +10 -0
- package/lib/types/environment/environment.d.ts.map +1 -0
- package/lib/types/environment/node/node.d.ts +3 -0
- package/lib/types/environment/node/node.d.ts.map +1 -0
- package/lib/types/event/meta/meta.d.ts +19 -0
- package/lib/types/event/meta/meta.d.ts.map +1 -0
- package/lib/types/event/relay-event.d.ts +9 -0
- package/lib/types/event/relay-event.d.ts.map +1 -0
- package/lib/types/event-api-call/event-api-caller.d.ts +11 -0
- package/lib/types/event-api-call/event-api-caller.d.ts.map +1 -0
- package/lib/types/relay.d.ts +16 -0
- package/lib/types/relay.d.ts.map +1 -0
- package/lib/types/validate/validate.d.ts +13 -0
- package/lib/types/validate/validate.d.ts.map +1 -0
- package/lib/types/version.d.ts +2 -0
- package/lib/types/version.d.ts.map +1 -0
- package/package.json +33 -3
- package/.turbo/turbo-publish:npm.log +0 -0
- package/CHANGELOG.md +0 -4
- package/jest.config.js +0 -5
- package/scripts/publish.mjs +0 -28
- package/src/environment/browser/browser.test.ts +0 -16
- package/src/environment/browser/browser.ts +0 -7
- package/src/environment/environment.ts +0 -3
- package/src/environment/node/node.test.ts +0 -7
- package/src/environment/node/node.ts +0 -7
- package/tsconfig.json +0 -5
package/lib/relay.cjs
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var crypto = require('crypto');
|
|
4
|
+
|
|
5
|
+
async function callEventApi({ event, options, environment, validate, }) {
|
|
6
|
+
const { token, host, organizationId } = options;
|
|
7
|
+
const headers = {
|
|
8
|
+
"Content-Type": "application/json",
|
|
9
|
+
Authorization: `Bearer ${token}`,
|
|
10
|
+
};
|
|
11
|
+
const response = await environment.fetch(`${host}/rest/organizations/${organizationId}/events/v1${validate ? "/validate" : ""}`, {
|
|
12
|
+
method: "POST",
|
|
13
|
+
body: JSON.stringify([event]),
|
|
14
|
+
headers,
|
|
15
|
+
});
|
|
16
|
+
const data = await response.json();
|
|
17
|
+
if (!response.ok) {
|
|
18
|
+
throw new Error({
|
|
19
|
+
responseType: "serviceError",
|
|
20
|
+
...data,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return data;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function emit(params) {
|
|
27
|
+
await callEventApi(params);
|
|
28
|
+
}
|
|
29
|
+
|
|
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
|
+
const rnds8Pool = new Uint8Array(256); // # of random values to pre-allocate
|
|
43
|
+
|
|
44
|
+
let poolPtr = rnds8Pool.length;
|
|
45
|
+
function rng() {
|
|
46
|
+
if (poolPtr > rnds8Pool.length - 16) {
|
|
47
|
+
crypto.randomFillSync(rnds8Pool);
|
|
48
|
+
poolPtr = 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Convert array of 16 byte values to UUID string format of the form:
|
|
56
|
+
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
const byteToHex = [];
|
|
60
|
+
|
|
61
|
+
for (let i = 0; i < 256; ++i) {
|
|
62
|
+
byteToHex.push((i + 0x100).toString(16).slice(1));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function unsafeStringify(arr, offset = 0) {
|
|
66
|
+
// Note: Be careful editing this code! It's been tuned for performance
|
|
67
|
+
// and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
|
|
68
|
+
return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
var native = {
|
|
72
|
+
randomUUID: crypto.randomUUID
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
function v4(options, buf, offset) {
|
|
76
|
+
if (native.randomUUID && !buf && !options) {
|
|
77
|
+
return native.randomUUID();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
options = options || {};
|
|
81
|
+
const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
82
|
+
|
|
83
|
+
rnds[6] = rnds[6] & 0x0f | 0x40;
|
|
84
|
+
rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
|
|
85
|
+
|
|
86
|
+
if (buf) {
|
|
87
|
+
offset = offset || 0;
|
|
88
|
+
|
|
89
|
+
for (let i = 0; i < 16; ++i) {
|
|
90
|
+
buf[offset + i] = rnds[i];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return buf;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return unsafeStringify(rnds);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function getReferrerUrl() {
|
|
100
|
+
const referrer = document.referrer;
|
|
101
|
+
return referrer === "" ? null : referrer;
|
|
102
|
+
}
|
|
103
|
+
function buildBrowserEnvironment() {
|
|
104
|
+
return {
|
|
105
|
+
runtime: "browser",
|
|
106
|
+
fetch: (url, init) => fetch(url, init),
|
|
107
|
+
getReferrerUrl: () => getReferrerUrl(),
|
|
108
|
+
getUrl: () => window.location.href,
|
|
109
|
+
getUserAgent: () => navigator.userAgent,
|
|
110
|
+
generateUUID: () => v4(),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function buildNodeEnvironment() {
|
|
115
|
+
return {
|
|
116
|
+
runtime: "node",
|
|
117
|
+
fetch: (url, init) => fetch(url, init),
|
|
118
|
+
getReferrerUrl: () => null,
|
|
119
|
+
getUrl: () => null,
|
|
120
|
+
getUserAgent: () => null,
|
|
121
|
+
generateUUID: () => v4(),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function currentEnvironment() {
|
|
126
|
+
return isBrowser() ? buildBrowserEnvironment() : buildNodeEnvironment();
|
|
127
|
+
}
|
|
128
|
+
function isBrowser() {
|
|
129
|
+
try {
|
|
130
|
+
return typeof window === "object";
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const version = "0.1.2" ;
|
|
138
|
+
|
|
139
|
+
function getConfig(options) {
|
|
140
|
+
const { trackingId } = options;
|
|
141
|
+
return { trackingId };
|
|
142
|
+
}
|
|
143
|
+
function getSource() {
|
|
144
|
+
return `relay@${version}`;
|
|
145
|
+
}
|
|
146
|
+
function createMeta(type, options, environment, clientIdManager) {
|
|
147
|
+
const { getReferrerUrl, getUrl, getUserAgent } = environment;
|
|
148
|
+
const config = getConfig(options);
|
|
149
|
+
const { clientId } = clientIdManager;
|
|
150
|
+
return {
|
|
151
|
+
type,
|
|
152
|
+
config,
|
|
153
|
+
ts: Date.now(),
|
|
154
|
+
source: getSource(),
|
|
155
|
+
clientId,
|
|
156
|
+
userAgent: getUserAgent(),
|
|
157
|
+
referrerUrl: getReferrerUrl(),
|
|
158
|
+
url: getUrl(),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function createRelayEvent(type, payload, options, environment, clientIdManager) {
|
|
163
|
+
return {
|
|
164
|
+
...payload,
|
|
165
|
+
meta: createMeta(type, options, environment, clientIdManager),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function validate(params) {
|
|
170
|
+
params.validate = true;
|
|
171
|
+
const data = await callEventApi(params);
|
|
172
|
+
const { valid, errors } = data[0];
|
|
173
|
+
return { valid, errors: errors ?? [], responseType: "validation" };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function createRelay(options) {
|
|
177
|
+
const environment = currentEnvironment();
|
|
178
|
+
const clientIdManager = createClientIdManager(environment);
|
|
179
|
+
return {
|
|
180
|
+
validate: (type, payload) => validate({
|
|
181
|
+
options,
|
|
182
|
+
environment,
|
|
183
|
+
event: createRelayEvent(type, payload, options, environment, clientIdManager),
|
|
184
|
+
}),
|
|
185
|
+
emit: (type, payload) => emit({
|
|
186
|
+
options,
|
|
187
|
+
environment,
|
|
188
|
+
event: createRelayEvent(type, payload, options, environment, clientIdManager),
|
|
189
|
+
}),
|
|
190
|
+
version,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
exports.createRelay = createRelay;
|
package/lib/relay.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
async function callEventApi({ event, options, environment, validate, }) {
|
|
2
|
+
const { token, host, organizationId } = options;
|
|
3
|
+
const headers = {
|
|
4
|
+
"Content-Type": "application/json",
|
|
5
|
+
Authorization: `Bearer ${token}`,
|
|
6
|
+
};
|
|
7
|
+
const response = await environment.fetch(`${host}/rest/organizations/${organizationId}/events/v1${validate ? "/validate" : ""}`, {
|
|
8
|
+
method: "POST",
|
|
9
|
+
body: JSON.stringify([event]),
|
|
10
|
+
headers,
|
|
11
|
+
});
|
|
12
|
+
const data = await response.json();
|
|
13
|
+
if (!response.ok) {
|
|
14
|
+
throw new Error({
|
|
15
|
+
responseType: "serviceError",
|
|
16
|
+
...data,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function emit(params) {
|
|
23
|
+
await callEventApi(params);
|
|
24
|
+
}
|
|
25
|
+
|
|
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
|
+
// Unique ID creation requires a high quality random # generator. In the browser we therefore
|
|
39
|
+
// require the crypto API and do not support built-in fallback to lower quality random number
|
|
40
|
+
// generators (like Math.random()).
|
|
41
|
+
let getRandomValues;
|
|
42
|
+
const rnds8 = new Uint8Array(16);
|
|
43
|
+
function rng() {
|
|
44
|
+
// lazy load so that environments that need to polyfill have a chance to do so
|
|
45
|
+
if (!getRandomValues) {
|
|
46
|
+
// getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
|
|
47
|
+
getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
|
|
48
|
+
|
|
49
|
+
if (!getRandomValues) {
|
|
50
|
+
throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return getRandomValues(rnds8);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Convert array of 16 byte values to UUID string format of the form:
|
|
59
|
+
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
const byteToHex = [];
|
|
63
|
+
|
|
64
|
+
for (let i = 0; i < 256; ++i) {
|
|
65
|
+
byteToHex.push((i + 0x100).toString(16).slice(1));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function unsafeStringify(arr, offset = 0) {
|
|
69
|
+
// Note: Be careful editing this code! It's been tuned for performance
|
|
70
|
+
// and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
|
|
71
|
+
return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
75
|
+
var native = {
|
|
76
|
+
randomUUID
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
function v4(options, buf, offset) {
|
|
80
|
+
if (native.randomUUID && !buf && !options) {
|
|
81
|
+
return native.randomUUID();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
options = options || {};
|
|
85
|
+
const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
86
|
+
|
|
87
|
+
rnds[6] = rnds[6] & 0x0f | 0x40;
|
|
88
|
+
rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
|
|
89
|
+
|
|
90
|
+
if (buf) {
|
|
91
|
+
offset = offset || 0;
|
|
92
|
+
|
|
93
|
+
for (let i = 0; i < 16; ++i) {
|
|
94
|
+
buf[offset + i] = rnds[i];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return buf;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return unsafeStringify(rnds);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function getReferrerUrl() {
|
|
104
|
+
const referrer = document.referrer;
|
|
105
|
+
return referrer === "" ? null : referrer;
|
|
106
|
+
}
|
|
107
|
+
function buildBrowserEnvironment() {
|
|
108
|
+
return {
|
|
109
|
+
runtime: "browser",
|
|
110
|
+
fetch: (url, init) => fetch(url, init),
|
|
111
|
+
getReferrerUrl: () => getReferrerUrl(),
|
|
112
|
+
getUrl: () => window.location.href,
|
|
113
|
+
getUserAgent: () => navigator.userAgent,
|
|
114
|
+
generateUUID: () => v4(),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function buildNodeEnvironment() {
|
|
119
|
+
return {
|
|
120
|
+
runtime: "node",
|
|
121
|
+
fetch: (url, init) => fetch(url, init),
|
|
122
|
+
getReferrerUrl: () => null,
|
|
123
|
+
getUrl: () => null,
|
|
124
|
+
getUserAgent: () => null,
|
|
125
|
+
generateUUID: () => v4(),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function currentEnvironment() {
|
|
130
|
+
return isBrowser() ? buildBrowserEnvironment() : buildNodeEnvironment();
|
|
131
|
+
}
|
|
132
|
+
function isBrowser() {
|
|
133
|
+
try {
|
|
134
|
+
return typeof window === "object";
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const version = "0.1.2" ;
|
|
142
|
+
|
|
143
|
+
function getConfig(options) {
|
|
144
|
+
const { trackingId } = options;
|
|
145
|
+
return { trackingId };
|
|
146
|
+
}
|
|
147
|
+
function getSource() {
|
|
148
|
+
return `relay@${version}`;
|
|
149
|
+
}
|
|
150
|
+
function createMeta(type, options, environment, clientIdManager) {
|
|
151
|
+
const { getReferrerUrl, getUrl, getUserAgent } = environment;
|
|
152
|
+
const config = getConfig(options);
|
|
153
|
+
const { clientId } = clientIdManager;
|
|
154
|
+
return {
|
|
155
|
+
type,
|
|
156
|
+
config,
|
|
157
|
+
ts: Date.now(),
|
|
158
|
+
source: getSource(),
|
|
159
|
+
clientId,
|
|
160
|
+
userAgent: getUserAgent(),
|
|
161
|
+
referrerUrl: getReferrerUrl(),
|
|
162
|
+
url: getUrl(),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function createRelayEvent(type, payload, options, environment, clientIdManager) {
|
|
167
|
+
return {
|
|
168
|
+
...payload,
|
|
169
|
+
meta: createMeta(type, options, environment, clientIdManager),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function validate(params) {
|
|
174
|
+
params.validate = true;
|
|
175
|
+
const data = await callEventApi(params);
|
|
176
|
+
const { valid, errors } = data[0];
|
|
177
|
+
return { valid, errors: errors ?? [], responseType: "validation" };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function createRelay(options) {
|
|
181
|
+
const environment = currentEnvironment();
|
|
182
|
+
const clientIdManager = createClientIdManager(environment);
|
|
183
|
+
return {
|
|
184
|
+
validate: (type, payload) => validate({
|
|
185
|
+
options,
|
|
186
|
+
environment,
|
|
187
|
+
event: createRelayEvent(type, payload, options, environment, clientIdManager),
|
|
188
|
+
}),
|
|
189
|
+
emit: (type, payload) => emit({
|
|
190
|
+
options,
|
|
191
|
+
environment,
|
|
192
|
+
event: createRelayEvent(type, payload, options, environment, clientIdManager),
|
|
193
|
+
}),
|
|
194
|
+
version,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export { createRelay };
|
package/lib/relay.mjs
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
|
|
3
|
+
async function callEventApi({ event, options, environment, validate, }) {
|
|
4
|
+
const { token, host, organizationId } = options;
|
|
5
|
+
const headers = {
|
|
6
|
+
"Content-Type": "application/json",
|
|
7
|
+
Authorization: `Bearer ${token}`,
|
|
8
|
+
};
|
|
9
|
+
const response = await environment.fetch(`${host}/rest/organizations/${organizationId}/events/v1${validate ? "/validate" : ""}`, {
|
|
10
|
+
method: "POST",
|
|
11
|
+
body: JSON.stringify([event]),
|
|
12
|
+
headers,
|
|
13
|
+
});
|
|
14
|
+
const data = await response.json();
|
|
15
|
+
if (!response.ok) {
|
|
16
|
+
throw new Error({
|
|
17
|
+
responseType: "serviceError",
|
|
18
|
+
...data,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return data;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function emit(params) {
|
|
25
|
+
await callEventApi(params);
|
|
26
|
+
}
|
|
27
|
+
|
|
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
|
+
const rnds8Pool = new Uint8Array(256); // # of random values to pre-allocate
|
|
41
|
+
|
|
42
|
+
let poolPtr = rnds8Pool.length;
|
|
43
|
+
function rng() {
|
|
44
|
+
if (poolPtr > rnds8Pool.length - 16) {
|
|
45
|
+
crypto.randomFillSync(rnds8Pool);
|
|
46
|
+
poolPtr = 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Convert array of 16 byte values to UUID string format of the form:
|
|
54
|
+
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
const byteToHex = [];
|
|
58
|
+
|
|
59
|
+
for (let i = 0; i < 256; ++i) {
|
|
60
|
+
byteToHex.push((i + 0x100).toString(16).slice(1));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function unsafeStringify(arr, offset = 0) {
|
|
64
|
+
// Note: Be careful editing this code! It's been tuned for performance
|
|
65
|
+
// and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
|
|
66
|
+
return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
var native = {
|
|
70
|
+
randomUUID: crypto.randomUUID
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
function v4(options, buf, offset) {
|
|
74
|
+
if (native.randomUUID && !buf && !options) {
|
|
75
|
+
return native.randomUUID();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
options = options || {};
|
|
79
|
+
const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
80
|
+
|
|
81
|
+
rnds[6] = rnds[6] & 0x0f | 0x40;
|
|
82
|
+
rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
|
|
83
|
+
|
|
84
|
+
if (buf) {
|
|
85
|
+
offset = offset || 0;
|
|
86
|
+
|
|
87
|
+
for (let i = 0; i < 16; ++i) {
|
|
88
|
+
buf[offset + i] = rnds[i];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return buf;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return unsafeStringify(rnds);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function getReferrerUrl() {
|
|
98
|
+
const referrer = document.referrer;
|
|
99
|
+
return referrer === "" ? null : referrer;
|
|
100
|
+
}
|
|
101
|
+
function buildBrowserEnvironment() {
|
|
102
|
+
return {
|
|
103
|
+
runtime: "browser",
|
|
104
|
+
fetch: (url, init) => fetch(url, init),
|
|
105
|
+
getReferrerUrl: () => getReferrerUrl(),
|
|
106
|
+
getUrl: () => window.location.href,
|
|
107
|
+
getUserAgent: () => navigator.userAgent,
|
|
108
|
+
generateUUID: () => v4(),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function buildNodeEnvironment() {
|
|
113
|
+
return {
|
|
114
|
+
runtime: "node",
|
|
115
|
+
fetch: (url, init) => fetch(url, init),
|
|
116
|
+
getReferrerUrl: () => null,
|
|
117
|
+
getUrl: () => null,
|
|
118
|
+
getUserAgent: () => null,
|
|
119
|
+
generateUUID: () => v4(),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function currentEnvironment() {
|
|
124
|
+
return isBrowser() ? buildBrowserEnvironment() : buildNodeEnvironment();
|
|
125
|
+
}
|
|
126
|
+
function isBrowser() {
|
|
127
|
+
try {
|
|
128
|
+
return typeof window === "object";
|
|
129
|
+
}
|
|
130
|
+
catch (e) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const version = "0.1.2" ;
|
|
136
|
+
|
|
137
|
+
function getConfig(options) {
|
|
138
|
+
const { trackingId } = options;
|
|
139
|
+
return { trackingId };
|
|
140
|
+
}
|
|
141
|
+
function getSource() {
|
|
142
|
+
return `relay@${version}`;
|
|
143
|
+
}
|
|
144
|
+
function createMeta(type, options, environment, clientIdManager) {
|
|
145
|
+
const { getReferrerUrl, getUrl, getUserAgent } = environment;
|
|
146
|
+
const config = getConfig(options);
|
|
147
|
+
const { clientId } = clientIdManager;
|
|
148
|
+
return {
|
|
149
|
+
type,
|
|
150
|
+
config,
|
|
151
|
+
ts: Date.now(),
|
|
152
|
+
source: getSource(),
|
|
153
|
+
clientId,
|
|
154
|
+
userAgent: getUserAgent(),
|
|
155
|
+
referrerUrl: getReferrerUrl(),
|
|
156
|
+
url: getUrl(),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function createRelayEvent(type, payload, options, environment, clientIdManager) {
|
|
161
|
+
return {
|
|
162
|
+
...payload,
|
|
163
|
+
meta: createMeta(type, options, environment, clientIdManager),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async function validate(params) {
|
|
168
|
+
params.validate = true;
|
|
169
|
+
const data = await callEventApi(params);
|
|
170
|
+
const { valid, errors } = data[0];
|
|
171
|
+
return { valid, errors: errors ?? [], responseType: "validation" };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function createRelay(options) {
|
|
175
|
+
const environment = currentEnvironment();
|
|
176
|
+
const clientIdManager = createClientIdManager(environment);
|
|
177
|
+
return {
|
|
178
|
+
validate: (type, payload) => validate({
|
|
179
|
+
options,
|
|
180
|
+
environment,
|
|
181
|
+
event: createRelayEvent(type, payload, options, environment, clientIdManager),
|
|
182
|
+
}),
|
|
183
|
+
emit: (type, payload) => emit({
|
|
184
|
+
options,
|
|
185
|
+
environment,
|
|
186
|
+
event: createRelayEvent(type, payload, options, environment, clientIdManager),
|
|
187
|
+
}),
|
|
188
|
+
version,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export { createRelay };
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../../src/emit/emit.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EACnB,MAAM,oCAAoC,CAAC;AAE5C,wBAAsB,IAAI,CAAC,MAAM,EAAE,kBAAkB,iBAEpD"}
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface Environment {
|
|
2
|
+
runtime: "browser" | "node";
|
|
3
|
+
fetch: (url: string, init?: RequestInit) => Promise<Response>;
|
|
4
|
+
getReferrerUrl: () => string | null;
|
|
5
|
+
getUrl: () => string | null;
|
|
6
|
+
getUserAgent: () => string | null;
|
|
7
|
+
generateUUID: () => string;
|
|
8
|
+
}
|
|
9
|
+
export declare function currentEnvironment(): Environment;
|
|
10
|
+
//# sourceMappingURL=environment.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ClientIdManager } from "../../client-id/client-id";
|
|
2
|
+
import { Environment } from "../../environment/environment";
|
|
3
|
+
import { RelayOptions } from "../../relay";
|
|
4
|
+
interface Config {
|
|
5
|
+
trackingId: string;
|
|
6
|
+
}
|
|
7
|
+
export interface Meta {
|
|
8
|
+
type: string;
|
|
9
|
+
config: Config;
|
|
10
|
+
ts: number;
|
|
11
|
+
source: string;
|
|
12
|
+
clientId: string;
|
|
13
|
+
userAgent: string | null;
|
|
14
|
+
referrerUrl: string | null;
|
|
15
|
+
url: string | null;
|
|
16
|
+
}
|
|
17
|
+
export declare function createMeta(type: string, options: RelayOptions, environment: Environment, clientIdManager: ClientIdManager): Readonly<Meta>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=meta.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../../../../src/event/meta/meta.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,UAAU,MAAM;IACd,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AAWD,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,YAAY,EACrB,WAAW,EAAE,WAAW,EACxB,eAAe,EAAE,eAAe,GAC/B,QAAQ,CAAC,IAAI,CAAC,CAehB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ClientIdManager } from "../client-id/client-id";
|
|
2
|
+
import { Environment } from "../environment/environment";
|
|
3
|
+
import { RelayOptions, RelayPayload } from "../relay";
|
|
4
|
+
import { Meta } from "./meta/meta";
|
|
5
|
+
export interface RelayEvent extends RelayPayload {
|
|
6
|
+
meta: Meta;
|
|
7
|
+
}
|
|
8
|
+
export declare function createRelayEvent(type: string, payload: RelayPayload, options: RelayOptions, environment: Environment, clientIdManager: ClientIdManager): Readonly<RelayEvent>;
|
|
9
|
+
//# sourceMappingURL=relay-event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relay-event.d.ts","sourceRoot":"","sources":["../../../src/event/relay-event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAc,IAAI,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,WAAW,UAAW,SAAQ,YAAY;IAC9C,IAAI,EAAE,IAAI,CAAC;CACZ;AAED,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,YAAY,EACrB,WAAW,EAAE,WAAW,EACxB,eAAe,EAAE,eAAe,GAC/B,QAAQ,CAAC,UAAU,CAAC,CAKtB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Environment } from "../environment/environment";
|
|
2
|
+
import { RelayOptions } from "../relay";
|
|
3
|
+
import { RelayEvent } from "../event/relay-event";
|
|
4
|
+
export interface EventApiCallParams {
|
|
5
|
+
event: Readonly<RelayEvent>;
|
|
6
|
+
options: RelayOptions;
|
|
7
|
+
environment: Environment;
|
|
8
|
+
validate?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function callEventApi({ event, options, environment, validate, }: EventApiCallParams): Promise<any>;
|
|
11
|
+
//# sourceMappingURL=event-api-caller.d.ts.map
|
|
@@ -0,0 +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,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC5B,OAAO,EAAE,YAAY,CAAC;IACtB,WAAW,EAAE,WAAW,CAAC;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAsB,YAAY,CAAC,EACjC,KAAK,EACL,OAAO,EACP,WAAW,EACX,QAAQ,GACT,EAAE,kBAAkB,GAAG,OAAO,CAAC,GAAG,CAAC,CA2BnC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ValidationError, ValidationResponse } from "./validate/validate";
|
|
2
|
+
type RelayPayload = Record<string, unknown>;
|
|
3
|
+
interface RelayOptions {
|
|
4
|
+
host: string;
|
|
5
|
+
organizationId: string;
|
|
6
|
+
token: string;
|
|
7
|
+
trackingId: string;
|
|
8
|
+
}
|
|
9
|
+
interface Relay {
|
|
10
|
+
validate: (type: string, payload: RelayPayload) => Promise<ValidationResponse>;
|
|
11
|
+
emit: (type: string, payload: RelayPayload) => Promise<void>;
|
|
12
|
+
version: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function createRelay(options: RelayOptions): Relay;
|
|
15
|
+
export type { RelayPayload, RelayOptions, ValidationError, ValidationResponse };
|
|
16
|
+
//# sourceMappingURL=relay.d.ts.map
|
|
@@ -0,0 +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;AAG7B,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE5C,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,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,MAAM,CAAC;CACjB;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,KAAK,CA+BxD;AAED,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EventApiCallParams } from "../event-api-call/event-api-caller";
|
|
2
|
+
export interface ValidationError {
|
|
3
|
+
type: string;
|
|
4
|
+
message: string;
|
|
5
|
+
path: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ValidationResponse {
|
|
8
|
+
valid: boolean;
|
|
9
|
+
responseType: "validation";
|
|
10
|
+
errors: ValidationError[];
|
|
11
|
+
}
|
|
12
|
+
export declare function validate(params: EventApiCallParams): Promise<Readonly<ValidationResponse>>;
|
|
13
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +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,CAOvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,EAAE,MAAkC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coveo/relay",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "A library for sending analytics events using Coveo's Event protocol.",
|
|
5
|
+
"files": [
|
|
6
|
+
"lib/**/*"
|
|
7
|
+
],
|
|
8
|
+
"types": "./lib/types/relay.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
"node": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./lib/types/relay.d.ts",
|
|
13
|
+
"default": "./lib/relay.mjs"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./lib/types/relay.d.ts",
|
|
17
|
+
"default": "./lib/relay.cjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"default": {
|
|
21
|
+
"types": "./lib/types/relay.d.ts",
|
|
22
|
+
"default": "./lib/relay.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
5
25
|
"repository": {
|
|
6
26
|
"type": "git",
|
|
7
27
|
"url": "git+https://github.com/coveo/relay.git"
|
|
@@ -18,17 +38,27 @@
|
|
|
18
38
|
},
|
|
19
39
|
"homepage": "https://github.com/coveo/relay#readme",
|
|
20
40
|
"devDependencies": {
|
|
41
|
+
"@rollup/plugin-node-resolve": "^15.2.1",
|
|
42
|
+
"@rollup/plugin-replace": "^5.0.2",
|
|
43
|
+
"@rollup/plugin-typescript": "^11.1.2",
|
|
21
44
|
"@types/jest": "^29.5.3",
|
|
45
|
+
"@types/uuid": "^9.0.2",
|
|
22
46
|
"jest": "^29.6.2",
|
|
23
47
|
"jest-environment-jsdom": "^29.6.2",
|
|
48
|
+
"rollup": "^3.28.0",
|
|
24
49
|
"ts-jest": "^29.1.1",
|
|
25
50
|
"typescript": "^5.1.6",
|
|
26
|
-
"eslint-config-custom": "0.0.
|
|
51
|
+
"eslint-config-custom": "0.0.0",
|
|
27
52
|
"tsconfig": "0.0.0"
|
|
28
53
|
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"uuid": "^9.0.0"
|
|
56
|
+
},
|
|
29
57
|
"scripts": {
|
|
58
|
+
"build": "npm run clean && rollup --config ./config/rollup.config.mjs",
|
|
59
|
+
"clean": "rm -rf ./lib",
|
|
30
60
|
"test": "jest",
|
|
31
61
|
"test:watch": "jest --watch",
|
|
32
|
-
"
|
|
62
|
+
"npm:tag": "node ./scripts/update-npm-tag.mjs"
|
|
33
63
|
}
|
|
34
64
|
}
|
|
File without changes
|
package/CHANGELOG.md
DELETED
package/jest.config.js
DELETED
package/scripts/publish.mjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {context} from '@actions/github';
|
|
2
|
-
import {
|
|
3
|
-
describeNpmTag,
|
|
4
|
-
getLastTag,
|
|
5
|
-
pnpmPublish,
|
|
6
|
-
} from "@coveo/semantic-monorepo-tools";
|
|
7
|
-
|
|
8
|
-
const VERSION_PREFIX = "@coveo/relay/v";
|
|
9
|
-
|
|
10
|
-
const publishNpm = async () => {
|
|
11
|
-
try {
|
|
12
|
-
const refBranchName = context.payload.pull_request.head.ref;
|
|
13
|
-
const lastTag = await getLastTag(VERSION_PREFIX);
|
|
14
|
-
const version = lastTag.replace(VERSION_PREFIX, "");
|
|
15
|
-
const currentAlphaVersion = await describeNpmTag("@coveo/relay", "alpha");
|
|
16
|
-
console.info("The current version of the package is %s", version);
|
|
17
|
-
console.info("the describe npm tag is %s", currentAlphaVersion);
|
|
18
|
-
|
|
19
|
-
if (version > currentAlphaVersion) {
|
|
20
|
-
console.info("needs to publish");
|
|
21
|
-
await pnpmPublish(undefined, "alpha", refBranchName);
|
|
22
|
-
}
|
|
23
|
-
} catch (e) {
|
|
24
|
-
console.log(e);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
publishNpm();
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jest-environment jsdom
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { buildBrowserEnvironment } from "./browser";
|
|
6
|
-
|
|
7
|
-
describe("buildBrowserEnvironment", () => {
|
|
8
|
-
it("retrieves the referrer", () => {
|
|
9
|
-
Object.defineProperty(window.document, "referrer", {
|
|
10
|
-
value: "https://www.coveo.com/",
|
|
11
|
-
});
|
|
12
|
-
expect(buildBrowserEnvironment().getReferrer()).toBe(
|
|
13
|
-
"https://www.coveo.com/"
|
|
14
|
-
);
|
|
15
|
-
});
|
|
16
|
-
});
|