@coveo/relay 0.6.2 → 0.6.4

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.
@@ -1,2 +1,2 @@
1
- async function e(e){const{listenerManager:t,event:n,config:r}=e;return"disabled"!==r.mode&&t.call(n),"validate"===r.mode?async function({config:e,environment:t,event:n}){const{url:r,token:o}=e,a={"Content-Type":"application/json",Authorization:`Bearer ${o}`},c=await t.fetch(`${r}/validate`,{method:"POST",body:JSON.stringify([n]),headers:a}),i=await c.json();if(!c.ok)throw new Error({...i});if(!i)return{valid:!1,errors:[{type:"",message:"disabled",path:""}]};const{valid:s,errors:l}=i[0];return{valid:s,errors:l??[]}}(e):async function({event:e,config:t,environment:n}){const{url:r,token:o}=t;return n.send(r,o,JSON.stringify([e]))}(e)}var t=/^(?:[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;function n(e){const n="visitorId";return{getClientId:()=>{const r=e.storage,o=r.getItem(n),a=o&&("string"==typeof(c=o)&&t.test(c))?o:e.generateUUID();var c;return r.setItem(n,a),a},clear:()=>{e.storage.removeItem(n)}}}const r=function(){const e="coveo_";return{getItem(t){const n=`${e}${t}=`,r=document.cookie.split(";");for(const e of r){const t=e.replace(/^\s+/,"");if(0===t.lastIndexOf(n,0))return t.substring(n.length,t.length)}return null},setItem(t,n,r){const o=(e=>{const t=e.split(".").slice(-2);return 2==t.length?t.join("."):""})(window.location.hostname),a=`;expires=${new Date((new Date).getTime()+r).toUTCString()}`,c=o?`;domain=${o}`:"";document.cookie=`${e}${t}=${n}${a}${c};path=/;SameSite=Lax`},removeItem(e){this.setItem(e,"",-1)}}}();async function o(e,t){return fetch(e,t).catch((e=>{throw new Error(`${e.message}: The "host" value is invalid or a network error occured, according to the FetchAPI's response.`,{cause:e})}))}function a(){return{runtime:"browser",fetch:(e,t)=>o(e,t),send:async(e,t,n)=>{if(!navigator.sendBeacon(`${e}?access_token=${t}`,new Blob([n],{type:"application/json"})))throw new Error("Failed to send the event(s) because the payload size exceeded the maximum allowed size (32 KB). Please contact support if the problem persists.");return null},getReferrerUrl:()=>function(){const e=document.referrer;return""===e?null:e}(),getUrl:()=>window.location.href,getUserAgent:()=>navigator.userAgent,generateUUID:()=>crypto.randomUUID(),storage:{getItem:e=>r.getItem(e)||localStorage.getItem(e),removeItem(e){r.removeItem(e),localStorage.removeItem(e)},setItem(e,t){localStorage.setItem(e,t),r.setItem(e,t,31556952e3)}}}}function c(){return{getItem:()=>null,removeItem(){},setItem(){}}}function i(){return function(){try{return"object"==typeof window}catch(e){return!1}}()?a():{runtime:"node",fetch:(e,t)=>o(e,t),send:async(e,t,n)=>(o(e,{method:"POST",body:n,headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`}}),null),getReferrerUrl:()=>null,getUrl:()=>null,getUserAgent:()=>null,generateUUID:()=>crypto.randomUUID(),storage:c()}}const s="0.6.2";function l(e,t,n,r){const{getReferrerUrl:o,getUrl:a,getUserAgent:c}=n,i=function(e){const{trackingId:t}=e;return{trackingId:t}}(t),l=r.getClientId();return Object.freeze({type:e,config:i,ts:Date.now(),source:`relay@${s}`,clientId:l,userAgent:c(),referrerUrl:o(),url:a()})}const u="*";function g(){const e=[];function t({type:t,callback:n}){return e.findIndex((e=>e.type===t&&e.callback===n))}function n(n,r){r?function(n){const r=t(n);r>=0&&e.splice(r,1)}({type:n,callback:r}):function(t){if(t===u)e.length=0;else for(let n=e.length-1;n>=0;n--)e[n].type===t&&e.splice(n,1)}(n)}return{add:function(r){return t(r)<0&&e.push(r),()=>n(r.type,r.callback)},call:function(t){e.forEach((e=>{if(function(e,t){return"*"===e.type||t===e.type}(e,t.meta.type))try{e.callback(t)}catch(e){console.error(e)}}))},remove:n}}function f({url:e,token:t,trackingId:n,...r}){return Object.freeze({url:e,token:t,trackingId:n,...!!r.mode&&{mode:r.mode}})}function d(t){const r=function(e){let t=f(e);return{get:()=>t,update:e=>{t=f({...t,...e})}}}(t),o=g(),a=()=>"disabled"==r.get().mode?{runtime:"null",fetch:()=>Promise.resolve(new Response(JSON.stringify(""))),send:async()=>null,getReferrerUrl:()=>null,getUrl:()=>null,getUserAgent:()=>null,generateUUID:()=>"",storage:c()}:i(),u=n(a());return{emit:(t,n)=>{const c=r.get(),i=a(),s=function(e,t,n,r,o){return{...t,meta:l(e,n,r,o)}}(t,n,c,i,u);return e({config:c,environment:i,event:s,listenerManager:o})},getMeta:e=>l(e,r.get(),a(),u),on:(e,t)=>o.add({type:e,callback:t}),off:(e,t)=>o.remove(e,t),updateConfig:e=>r.update(e),version:s,clearStorage:()=>{u.clear()}}}export{d as createRelay};
1
+ async function e(e){const{listenerManager:t,event:n,config:r}=e;return"disabled"!==r.mode&&t.call(n),"validate"===r.mode?async function({config:e,environment:t,event:n}){const{url:r,token:o}=e,a={"Content-Type":"application/json",Authorization:`Bearer ${o}`},c=await t.fetch(`${r}/validate`,{method:"POST",body:JSON.stringify([n]),headers:a}),i=await c.json();if(!c.ok)throw new Error({...i});if(!i)return{valid:!1,errors:[{type:"",message:"disabled",path:""}]};const{valid:s,errors:l}=i[0];return{valid:s,errors:l??[]}}(e):async function({event:e,config:t,environment:n}){const{url:r,token:o}=t;return n.send(r,o,JSON.stringify([e]))}(e)}var t=/^(?:[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;function n(e){const n="visitorId";return{getClientId:()=>{const r=e.storage,o=r.getItem(n),a=o&&("string"==typeof(c=o)&&t.test(c))?o:e.generateUUID();var c;return r.setItem(n,a),a},clear:()=>{e.storage.removeItem(n)}}}const r=function(){const e="coveo_";return{getItem(t){const n=`${e}${t}=`,r=document.cookie.split(";");for(const e of r){const t=e.replace(/^\s+/,"");if(0===t.lastIndexOf(n,0))return t.substring(n.length,t.length)}return null},setItem(t,n,r){const o=(e=>{const t=e.split(".").slice(-2);return 2==t.length?t.join("."):""})(window.location.hostname),a=`;expires=${new Date((new Date).getTime()+r).toUTCString()}`,c=o?`;domain=${o}`:"";document.cookie=`${e}${t}=${n}${a}${c};path=/;SameSite=Lax`},removeItem(e){this.setItem(e,"",-1)}}}();async function o(e,t){return fetch(e,t).catch((e=>{throw new Error(`${e.message}: The "host" value is invalid or a network error occured, according to the FetchAPI's response.`,{cause:e})}))}function a(){return{runtime:"browser",fetch:(e,t)=>o(e,t),send:async(e,t,n)=>{if(!navigator.sendBeacon(`${e}?access_token=${t}`,new Blob([n],{type:"application/json"})))throw new Error("Failed to send the event(s) because the payload size exceeded the maximum allowed size (32 KB). Please contact support if the problem persists.");return null},getReferrer:()=>function(){const e=document.referrer;return""===e?null:e}(),getLocation:()=>window.location.href,getUserAgent:()=>navigator.userAgent,generateUUID:()=>crypto.randomUUID(),storage:{getItem:e=>r.getItem(e)||localStorage.getItem(e),removeItem(e){r.removeItem(e),localStorage.removeItem(e)},setItem(e,t){localStorage.setItem(e,t),r.setItem(e,t,31556952e3)}}}}function c(){return{getItem:()=>null,removeItem(){},setItem(){}}}function i(){return function(){try{return"object"==typeof window}catch(e){return!1}}()?a():{runtime:"node",fetch:(e,t)=>o(e,t),send:async(e,t,n)=>(o(e,{method:"POST",body:n,headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`}}),null),getReferrer:()=>null,getLocation:()=>null,getUserAgent:()=>null,generateUUID:()=>crypto.randomUUID(),storage:c()}}const s="0.6.4";function l(e,t,n,r){const{getReferrer:o,getLocation:a,getUserAgent:c}=n,i=function(e){const{trackingId:t}=e;return{trackingId:t}}(t),l=r.getClientId();return Object.freeze({type:e,config:i,ts:Date.now(),source:`relay@${s}`,clientId:l,userAgent:c(),referrer:o(),location:a()})}const u="*";function g(){const e=[];function t({type:t,callback:n}){return e.findIndex((e=>e.type===t&&e.callback===n))}function n(n,r){r?function(n){const r=t(n);r>=0&&e.splice(r,1)}({type:n,callback:r}):function(t){if(t===u)e.length=0;else for(let n=e.length-1;n>=0;n--)e[n].type===t&&e.splice(n,1)}(n)}return{add:function(r){return t(r)<0&&e.push(r),()=>n(r.type,r.callback)},call:function(t){e.forEach((e=>{if(function(e,t){return"*"===e.type||t===e.type}(e,t.meta.type))try{e.callback(t)}catch(e){console.error(e)}}))},remove:n}}function f({url:e,token:t,trackingId:n,...r}){return Object.freeze({url:e,token:t,trackingId:n,...!!r.mode&&{mode:r.mode}})}function d(t){const r=function(e){let t=f(e);return{get:()=>t,update:e=>{t=f({...t,...e})}}}(t),o=g(),a=()=>"disabled"==r.get().mode?{runtime:"null",fetch:()=>Promise.resolve(new Response(JSON.stringify(""))),send:async()=>null,getReferrer:()=>null,getLocation:()=>null,getUserAgent:()=>null,generateUUID:()=>"",storage:c()}:i(),u=n(a());return{emit:(t,n)=>{const c=r.get(),i=a(),s=function(e,t,n,r,o){return{...t,meta:l(e,n,r,o)}}(t,n,c,i,u);return e({config:c,environment:i,event:s,listenerManager:o})},getMeta:e=>l(e,r.get(),a(),u),on:(e,t)=>o.add({type:e,callback:t}),off:(e,t)=>o.remove(e,t),updateConfig:e=>r.update(e),version:s,clearStorage:()=>{u.clear()}}}export{d as createRelay};
2
2
  //# sourceMappingURL=relay.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"relay.min.js","sources":["../../src/emit/emit.ts","../../src/validate/validate.ts","../../../../node_modules/.pnpm/uuid@9.0.1/node_modules/uuid/dist/esm-browser/regex.js","../../src/client-id/client-id.ts","../../../../node_modules/.pnpm/uuid@9.0.1/node_modules/uuid/dist/esm-browser/validate.js","../../src/environment/browser/storage/cookie.ts","../../src/environment/utils/fetch.ts","../../src/environment/browser/browser.ts","../../src/environment/browser/storage/storage.ts","../../src/environment/storage.ts","../../src/environment/environment.ts","../../src/environment/node/node.ts","../../src/version.ts","../../src/event/meta/meta.ts","../../src/listener/listener.ts","../../src/config/config.ts","../../src/relay.ts","../../src/environment/null/null.ts","../../src/event/relay-event.ts"],"sourcesContent":["import { Environment } from \"../environment/environment\";\nimport { ListenerManager } from \"../listener/listener\";\nimport { validate } from \"../validate/validate\";\nimport { RelayEvent } from \"../event/relay-event\";\nimport { RelayConfig } from \"../relay\";\n\nexport interface EmitParams {\n config: RelayConfig;\n environment: Environment;\n event: RelayEvent;\n listenerManager: ListenerManager;\n}\n\nexport async function emit(params: EmitParams) {\n const { listenerManager, event, config } = params;\n const isEnabled = config.mode !== \"disabled\";\n\n isEnabled && listenerManager.call(event);\n return config.mode === \"validate\" ? validate(params) : emitEvent(params);\n}\n\nexport async function emitEvent({\n event,\n config,\n environment,\n}: EmitParams): Promise<null> {\n const { url, token } = config;\n\n return environment.send(url, token, JSON.stringify([event]));\n}\n","import { Environment } from \"../environment/environment\";\nimport { RelayEvent } from \"../event/relay-event\";\nimport { RelayConfig } from \"../relay\";\n\nexport interface ValidateParams {\n config: RelayConfig;\n environment: Environment;\n event: Readonly<RelayEvent>;\n}\n\nexport interface ValidationError {\n type: string;\n message: string;\n path: string;\n}\n\nexport interface ValidationResponse {\n valid: boolean;\n errors: ValidationError[];\n}\n\nexport async function validate({\n config,\n environment,\n event,\n}: ValidateParams): Promise<Readonly<ValidationResponse>> {\n const { url, token } = config;\n const headers = {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${token}`,\n };\n\n const response = await environment.fetch(`${url}/validate`, {\n method: \"POST\",\n body: JSON.stringify([event]),\n headers,\n });\n const data = await response.json();\n\n if (!response.ok) {\n throw new Error({\n ...data,\n });\n }\n\n if (!data) {\n return {\n valid: false,\n errors: [{ type: \"\", message: \"disabled\", path: \"\" }],\n };\n }\n\n const { valid, errors } = data[0];\n\n return { valid, errors: errors ?? [] };\n}\n","export default /^(?:[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;","import { validate } from \"uuid\";\nimport { Environment } from \"../environment/environment\";\n\nexport interface ClientIdManager {\n getClientId: () => string;\n clear: () => void;\n}\n\nexport function createClientIdManager(\n environment: Environment\n): ClientIdManager {\n const key = \"visitorId\";\n return {\n getClientId: () => {\n const storage = environment.storage;\n\n const existingClientId = storage.getItem(key);\n const clientId =\n existingClientId && validate(existingClientId)\n ? existingClientId\n : environment.generateUUID();\n storage.setItem(key, clientId);\n return clientId;\n },\n clear: () => {\n environment.storage.removeItem(key);\n },\n };\n}\n","import REGEX from './regex.js';\n\nfunction validate(uuid) {\n return typeof uuid === 'string' && REGEX.test(uuid);\n}\n\nexport default validate;","export interface CookieManager {\n getItem: (key: string) => string | null;\n removeItem: (key: string) => void;\n setItem: (key: string, data: string, expire: number) => void;\n}\n\nexport const cookieManager: CookieManager = createCookieManager();\n\nfunction createCookieManager(): CookieManager {\n const prefix = \"coveo_\";\n const getDomain = (host: string) => {\n const parts = host.split(\".\").slice(-2);\n return parts.length == 2 ? parts.join(\".\") : \"\";\n };\n\n return {\n getItem(key: string): string | null {\n const cookiePrefix = `${prefix}${key}=`;\n const cookieArray = document.cookie.split(\";\");\n for (const cookie of cookieArray) {\n const prettifyCookie = cookie.replace(/^\\s+/, \"\");\n if (prettifyCookie.lastIndexOf(cookiePrefix, 0) === 0) {\n return prettifyCookie.substring(\n cookiePrefix.length,\n prettifyCookie.length\n );\n }\n }\n return null;\n },\n setItem(key: string, data: string, expire: number): void {\n const domain = getDomain(window.location.hostname);\n const expireSection = `;expires=${new Date(\n new Date().getTime() + expire\n ).toUTCString()}`;\n const domainSection = domain ? `;domain=${domain}` : \"\";\n document.cookie = `${prefix}${key}=${data}${expireSection}${domainSection};path=/;SameSite=Lax`;\n },\n\n removeItem(key: string): void {\n this.setItem(key, \"\", -1);\n },\n };\n}\n","export async function fetchAPI(\n url: string,\n init?: RequestInit\n): Promise<Response> {\n return fetch(url, init).catch((err: Error) => {\n throw new Error(\n `${err.message}: The \"host\" value is invalid or a network error occured, according to the FetchAPI's response.`,\n { cause: err }\n );\n });\n}\n","import { Environment } from \"../environment\";\nimport { createBrowserStorage } from \"./storage/storage\";\nimport { fetchAPI } from \"../utils/fetch\";\n\nfunction getReferrerUrl() {\n const referrer = document.referrer;\n\n return referrer === \"\" ? null : referrer;\n}\n\nexport function buildBrowserEnvironment(): Environment {\n return {\n runtime: \"browser\",\n fetch: (url: string, init?: RequestInit) => fetchAPI(url, init),\n send: async (url: string, token: string, body: string) => {\n const response = navigator.sendBeacon(\n `${url}?access_token=${token}`,\n new Blob([body], {\n type: \"application/json\",\n })\n );\n\n if (!response) {\n throw new Error(\n `Failed to send the event(s) because the payload size exceeded the maximum allowed size (32 KB). Please contact support if the problem persists.`\n );\n }\n\n return null;\n },\n getReferrerUrl: () => getReferrerUrl(),\n getUrl: () => window.location.href,\n getUserAgent: () => navigator.userAgent,\n generateUUID: () => crypto.randomUUID(),\n storage: createBrowserStorage(),\n };\n}\n","import { Storage } from \"../../storage\";\nimport { cookieManager } from \"./cookie\";\n\nexport function createBrowserStorage(): Storage {\n return {\n getItem(key: string): string | null {\n return cookieManager.getItem(key) || localStorage.getItem(key);\n },\n\n removeItem(key: string): void {\n cookieManager.removeItem(key);\n localStorage.removeItem(key);\n },\n\n setItem(key: string, data: string): void {\n const oneYear = 31556952000;\n localStorage.setItem(key, data);\n cookieManager.setItem(key, data, oneYear);\n },\n };\n}\n","export interface Storage {\n getItem: (key: string) => string | null;\n removeItem: (key: string) => void;\n setItem: (key: string, data: string) => void;\n}\n\nexport function createNullStorage(): Storage {\n return {\n getItem(): string | null {\n return null;\n },\n removeItem(): void {\n return;\n },\n setItem(): void {\n return;\n },\n };\n}\n","import { buildBrowserEnvironment } from \"./browser/browser\";\nimport { buildNodeEnvironment } from \"./node/node\";\nimport { Storage } from \"./storage\";\n\nexport interface Environment {\n runtime: \"browser\" | \"node\" | \"null\";\n fetch: (url: string, init?: RequestInit) => Promise<Response>;\n send: (url: string, token: string, body: string) => Promise<null>;\n getReferrerUrl: () => string | null;\n getUrl: () => string | null;\n getUserAgent: () => string | null;\n generateUUID: () => string;\n storage: Storage;\n}\n\nexport function currentEnvironment(): Environment {\n return isBrowser() ? buildBrowserEnvironment() : buildNodeEnvironment();\n}\n\nfunction isBrowser() {\n try {\n return typeof window === \"object\";\n } catch (e) {\n return false;\n }\n}\n","import { Environment } from \"../environment\";\nimport { createNullStorage } from \"../storage\";\nimport { fetchAPI } from \"../utils/fetch\";\n\nexport function buildNodeEnvironment(): Environment {\n return {\n runtime: \"node\",\n fetch: (url: string, init?: RequestInit) => fetchAPI(url, init),\n send: async (url: string, token: string, body: string) => {\n const headers = {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${token}`,\n };\n fetchAPI(url, {\n method: \"POST\",\n body,\n headers,\n });\n return null;\n },\n getReferrerUrl: () => null,\n getUrl: () => null,\n getUserAgent: () => null,\n generateUUID: () => crypto.randomUUID(),\n storage: createNullStorage(),\n };\n}\n","export const version: string = process.env.VERSION ?? \"\";\n","import { ClientIdManager } from \"../../client-id/client-id\";\nimport { Environment } from \"../../environment/environment\";\nimport { RelayConfig } from \"../../config/config\";\nimport { version } from \"../../version\";\n\ninterface EventConfig {\n trackingId: string;\n}\n\nexport interface Meta {\n type: string;\n config: EventConfig;\n ts: number;\n source: string;\n clientId: string;\n userAgent: string | null;\n referrerUrl: string | null;\n url: string | null;\n}\n\nfunction getEventConfig(config: RelayConfig): EventConfig {\n const { trackingId } = config;\n return { trackingId };\n}\n\nfunction getSource(): string {\n return `relay@${version}`;\n}\n\nexport function createMeta(\n type: string,\n config: RelayConfig,\n environment: Environment,\n clientIdManager: ClientIdManager\n): Readonly<Meta> {\n const { getReferrerUrl, getUrl, getUserAgent } = environment;\n const eventConfig = getEventConfig(config);\n const clientId = clientIdManager.getClientId();\n\n return Object.freeze({\n type,\n config: eventConfig,\n ts: Date.now(),\n source: getSource(),\n clientId,\n userAgent: getUserAgent(),\n referrerUrl: getReferrerUrl(),\n url: getUrl(),\n });\n}\n","import { RelayEvent } from \"../event/relay-event\";\n\nconst ANY_EVENT_TYPE = \"*\";\n\nexport type EventCallback = (event: RelayEvent) => void;\n\ninterface Listener {\n type: string;\n callback: EventCallback;\n}\n\nexport interface ListenerManager {\n add: (listener: Listener) => () => void;\n call: (event: RelayEvent) => void;\n remove: (type: string, callback?: EventCallback) => void;\n}\n\nexport function createListenerManager(): ListenerManager {\n const listeners: Listener[] = [];\n\n function getListenerIndex({ type, callback }: Listener): number {\n return listeners.findIndex(\n (listener) => listener.type === type && listener.callback === callback\n );\n }\n\n function isMatchesType(listener: Listener, type: string): boolean {\n return listener.type === \"*\" || type === listener.type;\n }\n\n function add(listener: Listener): () => void {\n if (getListenerIndex(listener) < 0) {\n listeners.push(listener);\n }\n return () => remove(listener.type, listener.callback);\n }\n\n function call(event: RelayEvent) {\n listeners.forEach((listener) => {\n if (isMatchesType(listener, event.meta.type)) {\n try {\n listener.callback(event);\n } catch (e) {\n console.error(e);\n }\n }\n });\n }\n\n function removeMultiple(type: string) {\n if (type === ANY_EVENT_TYPE) {\n listeners.length = 0;\n } else {\n for (let i = listeners.length - 1; i >= 0; i--) {\n if (listeners[i].type === type) {\n listeners.splice(i, 1);\n }\n }\n }\n }\n\n function removeOne(listener: Listener) {\n const index = getListenerIndex(listener);\n if (index >= 0) {\n listeners.splice(index, 1);\n }\n }\n\n function remove(type: string, callback?: EventCallback) {\n !!callback ? removeOne({ type, callback }) : removeMultiple(type);\n }\n\n return {\n add,\n call,\n remove,\n };\n}\n","export type RelayMode = \"emit\" | \"validate\" | \"disabled\";\n\nexport interface RelayConfig {\n url: string;\n token: string;\n trackingId: string;\n mode?: RelayMode;\n}\n\nexport interface ConfigManager {\n get: () => Readonly<RelayConfig>;\n update: (updatedConfig: Partial<RelayConfig>) => void;\n}\n\nfunction pick({\n url,\n token,\n trackingId,\n ...rest\n}: RelayConfig): Readonly<RelayConfig> {\n return Object.freeze({\n url,\n token,\n trackingId,\n ...(!!rest.mode && { mode: rest.mode }),\n });\n}\n\nexport function createConfigManager(\n initialConfig: RelayConfig\n): Readonly<ConfigManager> {\n let _config: Readonly<RelayConfig> = pick(initialConfig);\n\n return {\n get: () => _config,\n update: (updatedConfig: Partial<RelayConfig>) => {\n _config = pick({ ..._config, ...updatedConfig });\n },\n };\n}\n","import { emit } from \"./emit/emit\";\nimport { createClientIdManager } from \"./client-id/client-id\";\nimport { currentEnvironment } from \"./environment/environment\";\nimport { createRelayEvent } from \"./event/relay-event\";\nimport { version } from \"./version\";\nimport { createMeta, Meta } from \"./event/meta/meta\";\nimport { createListenerManager, EventCallback } from \"./listener/listener\";\nimport { createConfigManager, RelayConfig } from \"./config/config\";\nimport { ValidationError, ValidationResponse } from \"./validate/validate\";\nimport { buildNullEnvironment } from \"./environment/null/null\";\n\ntype RelayPayload = Record<string, unknown>;\ntype Off = () => void;\n\ninterface Relay {\n emit: (\n type: string,\n payload: RelayPayload\n ) => Promise<ValidationResponse | null>;\n getMeta: (type: string) => Meta;\n on: (type: string, callback: EventCallback) => Off;\n off: (type: string, callback?: EventCallback) => void;\n updateConfig: (config: Partial<RelayConfig>) => void;\n version: string;\n clearStorage: () => void;\n}\n\nexport function createRelay(initialConfig: RelayConfig): Relay {\n const configManager = createConfigManager(initialConfig);\n const listenerManager = createListenerManager();\n\n const getEnvironment = () =>\n configManager.get().mode == \"disabled\"\n ? buildNullEnvironment()\n : currentEnvironment();\n const clientIdManager = createClientIdManager(getEnvironment());\n\n return {\n emit: (type: string, payload: RelayPayload) => {\n const config = configManager.get();\n const environment = getEnvironment();\n\n const event = createRelayEvent(\n type,\n payload,\n config,\n environment,\n clientIdManager\n );\n\n return emit({\n config,\n environment,\n event,\n listenerManager,\n });\n },\n getMeta: (type: string) =>\n createMeta(type, configManager.get(), getEnvironment(), clientIdManager),\n on: (type: string, callback: EventCallback) =>\n listenerManager.add({ type, callback }),\n off: (type: string, callback?: EventCallback) =>\n listenerManager.remove(type, callback),\n updateConfig: (config: Partial<RelayConfig>) =>\n configManager.update(config),\n version,\n clearStorage: () => {\n clientIdManager.clear();\n },\n };\n}\n\nexport type { RelayPayload, RelayConfig, ValidationError, ValidationResponse };\n","import { Environment } from \"../environment\";\nimport { createNullStorage } from \"../storage\";\n\nexport function buildNullEnvironment(): Environment {\n return {\n runtime: \"null\",\n fetch: () => Promise.resolve(new Response(JSON.stringify(\"\"))),\n send: async () => null,\n getReferrerUrl: () => null,\n getUrl: () => null,\n getUserAgent: () => null,\n generateUUID: () => \"\",\n storage: createNullStorage(),\n };\n}\n","import { ClientIdManager } from \"../client-id/client-id\";\nimport { Environment } from \"../environment/environment\";\nimport { RelayConfig, RelayPayload } from \"../relay\";\nimport { createMeta, Meta } from \"./meta/meta\";\n\nexport interface RelayEvent extends RelayPayload {\n meta: Readonly<Meta>;\n}\n\nexport function createRelayEvent(\n type: string,\n payload: RelayPayload,\n config: RelayConfig,\n environment: Environment,\n clientIdManager: ClientIdManager\n): Readonly<RelayEvent> {\n return {\n ...payload,\n meta: createMeta(type, config, environment, clientIdManager),\n };\n}\n"],"names":["async","emit","params","listenerManager","event","config","mode","call","environment","url","token","headers","Authorization","response","fetch","method","body","JSON","stringify","data","json","ok","Error","valid","errors","type","message","path","validate","send","emitEvent","REGEX","createClientIdManager","key","getClientId","storage","existingClientId","getItem","clientId","uuid","test","generateUUID","setItem","clear","removeItem","cookieManager","prefix","cookiePrefix","cookieArray","document","cookie","split","prettifyCookie","replace","lastIndexOf","substring","length","expire","domain","host","parts","slice","join","getDomain","window","location","hostname","expireSection","Date","getTime","toUTCString","domainSection","this","createCookieManager","fetchAPI","init","catch","err","cause","buildBrowserEnvironment","runtime","navigator","sendBeacon","Blob","getReferrerUrl","referrer","getUrl","href","getUserAgent","userAgent","crypto","randomUUID","localStorage","createNullStorage","currentEnvironment","e","isBrowser","version","createMeta","clientIdManager","eventConfig","trackingId","getEventConfig","Object","freeze","ts","now","source","referrerUrl","ANY_EVENT_TYPE","createListenerManager","listeners","getListenerIndex","callback","findIndex","listener","remove","index","splice","removeOne","i","removeMultiple","add","push","forEach","isMatchesType","meta","console","error","pick","rest","createRelay","initialConfig","configManager","_config","get","update","updatedConfig","createConfigManager","getEnvironment","Promise","resolve","Response","payload","createRelayEvent","getMeta","on","off","updateConfig","clearStorage"],"mappings":"AAaOA,eAAeC,EAAKC,GACzB,MAAMC,gBAAEA,EAAeC,MAAEA,EAAKC,OAAEA,GAAWH,EAI3C,MAHkC,aAAhBG,EAAOC,MAEZH,EAAgBI,KAAKH,GACX,aAAhBC,EAAOC,KCGTN,gBAAwBK,OAC7BA,EAAMG,YACNA,EAAWJ,MACXA,IAEA,MAAMK,IAAEA,EAAGC,MAAEA,GAAUL,EACjBM,EAAU,CACd,eAAgB,mBAChBC,cAAe,UAAUF,KAGrBG,QAAiBL,EAAYM,MAAM,GAAGL,aAAgB,CAC1DM,OAAQ,OACRC,KAAMC,KAAKC,UAAU,CAACd,IACtBO,YAEIQ,QAAaN,EAASO,OAE5B,IAAKP,EAASQ,GACZ,MAAM,IAAIC,MAAM,IACXH,IAIP,IAAKA,EACH,MAAO,CACLI,OAAO,EACPC,OAAQ,CAAC,CAAEC,KAAM,GAAIC,QAAS,WAAYC,KAAM,MAIpD,MAAMJ,MAAEA,EAAKC,OAAEA,GAAWL,EAAK,GAE/B,MAAO,CAAEI,QAAOC,OAAQA,GAAU,GACpC,CDrCsCI,CAAS1B,GAGxCF,gBAAyBI,MAC9BA,EAAKC,OACLA,EAAMG,YACNA,IAEA,MAAMC,IAAEA,EAAGC,MAAEA,GAAUL,EAEvB,OAAOG,EAAYqB,KAAKpB,EAAKC,EAAOO,KAAKC,UAAU,CAACd,IACtD,CAXyD0B,CAAU5B,EACnE,CEnBA,IAAA6B,EAAe,sHCQT,SAAUC,EACdxB,GAEA,MAAMyB,EAAM,YACZ,MAAO,CACLC,YAAa,KACX,MAAMC,EAAU3B,EAAY2B,QAEtBC,EAAmBD,EAAQE,QAAQJ,GACnCK,EACJF,ICfiB,iBADPG,EDgBmBH,ICfAL,EAAMS,KAAKD,IDgBpCH,EACA5B,EAAYiC,eClBxB,IAAk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../src/emit/emit.ts","../../src/validate/validate.ts","../../../../node_modules/.pnpm/uuid@9.0.1/node_modules/uuid/dist/esm-browser/regex.js","../../src/client-id/client-id.ts","../../../../node_modules/.pnpm/uuid@9.0.1/node_modules/uuid/dist/esm-browser/validate.js","../../src/environment/browser/storage/cookie.ts","../../src/environment/utils/fetch.ts","../../src/environment/browser/browser.ts","../../src/environment/browser/storage/storage.ts","../../src/environment/storage.ts","../../src/environment/environment.ts","../../src/environment/node/node.ts","../../src/version.ts","../../src/event/meta/meta.ts","../../src/listener/listener.ts","../../src/config/config.ts","../../src/relay.ts","../../src/environment/null/null.ts","../../src/event/relay-event.ts"],"sourcesContent":["import { Environment } from \"../environment/environment\";\nimport { ListenerManager } from \"../listener/listener\";\nimport { validate } from \"../validate/validate\";\nimport { RelayEvent } from \"../event/relay-event\";\nimport { RelayConfig } from \"../relay\";\n\nexport interface EmitParams {\n config: RelayConfig;\n environment: Environment;\n event: RelayEvent;\n listenerManager: ListenerManager;\n}\n\nexport async function emit(params: EmitParams) {\n const { listenerManager, event, config } = params;\n const isEnabled = config.mode !== \"disabled\";\n\n isEnabled && listenerManager.call(event);\n return config.mode === \"validate\" ? validate(params) : emitEvent(params);\n}\n\nexport async function emitEvent({\n event,\n config,\n environment,\n}: EmitParams): Promise<null> {\n const { url, token } = config;\n\n return environment.send(url, token, JSON.stringify([event]));\n}\n","import { Environment } from \"../environment/environment\";\nimport { RelayEvent } from \"../event/relay-event\";\nimport { RelayConfig } from \"../relay\";\n\nexport interface ValidateParams {\n config: RelayConfig;\n environment: Environment;\n event: Readonly<RelayEvent>;\n}\n\nexport interface ValidationError {\n /**\n * Type of syntax error of an event's property.\n */\n type: string;\n\n /**\n * Message describing the syntax error of an event's property.\n */\n message: string;\n\n /**\n * Path of the property with a syntax error in the event's payload.\n */\n path: string;\n}\n\nexport interface ValidationResponse {\n /**\n * Indicates whether the payload is valid.\n */\n valid: boolean;\n\n /**\n * List of syntax errors found in the emitted event(s).\n * Each syntax error for a given property in a given event will be represented as a single ValidationError object.\n */\n errors: ValidationError[];\n}\n\nexport async function validate({\n config,\n environment,\n event,\n}: ValidateParams): Promise<Readonly<ValidationResponse>> {\n const { url, token } = config;\n const headers = {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${token}`,\n };\n\n const response = await environment.fetch(`${url}/validate`, {\n method: \"POST\",\n body: JSON.stringify([event]),\n headers,\n });\n const data = await response.json();\n\n if (!response.ok) {\n throw new Error({\n ...data,\n });\n }\n\n if (!data) {\n return {\n valid: false,\n errors: [{ type: \"\", message: \"disabled\", path: \"\" }],\n };\n }\n\n const { valid, errors } = data[0];\n\n return { valid, errors: errors ?? [] };\n}\n","export default /^(?:[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;","import { validate } from \"uuid\";\nimport { Environment } from \"../environment/environment\";\n\nexport interface ClientIdManager {\n getClientId: () => string;\n clear: () => void;\n}\n\nexport function createClientIdManager(\n environment: Environment\n): ClientIdManager {\n const key = \"visitorId\";\n return {\n getClientId: () => {\n const storage = environment.storage;\n\n const existingClientId = storage.getItem(key);\n const clientId =\n existingClientId && validate(existingClientId)\n ? existingClientId\n : environment.generateUUID();\n storage.setItem(key, clientId);\n return clientId;\n },\n clear: () => {\n environment.storage.removeItem(key);\n },\n };\n}\n","import REGEX from './regex.js';\n\nfunction validate(uuid) {\n return typeof uuid === 'string' && REGEX.test(uuid);\n}\n\nexport default validate;","export interface CookieManager {\n getItem: (key: string) => string | null;\n removeItem: (key: string) => void;\n setItem: (key: string, data: string, expire: number) => void;\n}\n\nexport const cookieManager: CookieManager = createCookieManager();\n\nfunction createCookieManager(): CookieManager {\n const prefix = \"coveo_\";\n const getDomain = (host: string) => {\n const parts = host.split(\".\").slice(-2);\n return parts.length == 2 ? parts.join(\".\") : \"\";\n };\n\n return {\n getItem(key: string): string | null {\n const cookiePrefix = `${prefix}${key}=`;\n const cookieArray = document.cookie.split(\";\");\n for (const cookie of cookieArray) {\n const prettifyCookie = cookie.replace(/^\\s+/, \"\");\n if (prettifyCookie.lastIndexOf(cookiePrefix, 0) === 0) {\n return prettifyCookie.substring(\n cookiePrefix.length,\n prettifyCookie.length\n );\n }\n }\n return null;\n },\n setItem(key: string, data: string, expire: number): void {\n const domain = getDomain(window.location.hostname);\n const expireSection = `;expires=${new Date(\n new Date().getTime() + expire\n ).toUTCString()}`;\n const domainSection = domain ? `;domain=${domain}` : \"\";\n document.cookie = `${prefix}${key}=${data}${expireSection}${domainSection};path=/;SameSite=Lax`;\n },\n\n removeItem(key: string): void {\n this.setItem(key, \"\", -1);\n },\n };\n}\n","export async function fetchAPI(\n url: string,\n init?: RequestInit\n): Promise<Response> {\n return fetch(url, init).catch((err: Error) => {\n throw new Error(\n `${err.message}: The \"host\" value is invalid or a network error occured, according to the FetchAPI's response.`,\n { cause: err }\n );\n });\n}\n","import { Environment } from \"../environment\";\nimport { createBrowserStorage } from \"./storage/storage\";\nimport { fetchAPI } from \"../utils/fetch\";\n\nfunction getReferrer() {\n const referrer = document.referrer;\n\n return referrer === \"\" ? null : referrer;\n}\n\nexport function buildBrowserEnvironment(): Environment {\n return {\n runtime: \"browser\",\n fetch: (url: string, init?: RequestInit) => fetchAPI(url, init),\n send: async (url: string, token: string, body: string) => {\n const response = navigator.sendBeacon(\n `${url}?access_token=${token}`,\n new Blob([body], {\n type: \"application/json\",\n })\n );\n\n if (!response) {\n throw new Error(\n `Failed to send the event(s) because the payload size exceeded the maximum allowed size (32 KB). Please contact support if the problem persists.`\n );\n }\n\n return null;\n },\n getReferrer: () => getReferrer(),\n getLocation: () => window.location.href,\n getUserAgent: () => navigator.userAgent,\n generateUUID: () => crypto.randomUUID(),\n storage: createBrowserStorage(),\n };\n}\n","import { Storage } from \"../../storage\";\nimport { cookieManager } from \"./cookie\";\n\nexport function createBrowserStorage(): Storage {\n return {\n getItem(key: string): string | null {\n return cookieManager.getItem(key) || localStorage.getItem(key);\n },\n\n removeItem(key: string): void {\n cookieManager.removeItem(key);\n localStorage.removeItem(key);\n },\n\n setItem(key: string, data: string): void {\n const oneYear = 31556952000;\n localStorage.setItem(key, data);\n cookieManager.setItem(key, data, oneYear);\n },\n };\n}\n","export interface Storage {\n getItem: (key: string) => string | null;\n removeItem: (key: string) => void;\n setItem: (key: string, data: string) => void;\n}\n\nexport function createNullStorage(): Storage {\n return {\n getItem(): string | null {\n return null;\n },\n removeItem(): void {\n return;\n },\n setItem(): void {\n return;\n },\n };\n}\n","import { buildBrowserEnvironment } from \"./browser/browser\";\nimport { buildNodeEnvironment } from \"./node/node\";\nimport { Storage } from \"./storage\";\n\nexport interface Environment {\n runtime: \"browser\" | \"node\" | \"null\";\n fetch: (url: string, init?: RequestInit) => Promise<Response>;\n send: (url: string, token: string, body: string) => Promise<null>;\n getReferrer: () => string | null;\n getLocation: () => string | null;\n getUserAgent: () => string | null;\n generateUUID: () => string;\n storage: Storage;\n}\n\nexport function currentEnvironment(): Environment {\n return isBrowser() ? buildBrowserEnvironment() : buildNodeEnvironment();\n}\n\nfunction isBrowser() {\n try {\n return typeof window === \"object\";\n } catch (e) {\n return false;\n }\n}\n","import { Environment } from \"../environment\";\nimport { createNullStorage } from \"../storage\";\nimport { fetchAPI } from \"../utils/fetch\";\n\nexport function buildNodeEnvironment(): Environment {\n return {\n runtime: \"node\",\n fetch: (url: string, init?: RequestInit) => fetchAPI(url, init),\n send: async (url: string, token: string, body: string) => {\n const headers = {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${token}`,\n };\n fetchAPI(url, {\n method: \"POST\",\n body,\n headers,\n });\n return null;\n },\n getReferrer: () => null,\n getLocation: () => null,\n getUserAgent: () => null,\n generateUUID: () => crypto.randomUUID(),\n storage: createNullStorage(),\n };\n}\n","export const version: string = process.env.VERSION ?? \"\";\n","import { ClientIdManager } from \"../../client-id/client-id\";\nimport { Environment } from \"../../environment/environment\";\nimport { RelayConfig } from \"../../config/config\";\nimport { version } from \"../../version\";\n\ninterface EventConfig {\n /**\n * The unique identifier of a web property. See [Tracking ID](https://docs.coveo.com/en/n8tg0567/).\n */\n trackingId: string;\n}\n\nexport interface Meta {\n /**\n * Event's type that was emitted.\n */\n type: string;\n config: EventConfig;\n\n /**\n * Timestamp when the event was emitted.\n */\n ts: number;\n\n /**\n * Library and version in which the event is built and emitted.\n */\n source: string;\n\n /**\n * Persistent unique identifier of a device.\n */\n clientId: string;\n\n /**\n * Browser Navigator's [user agent](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/userAgent) property if set.\n */\n userAgent: string | null;\n\n /**\n * Browser Document's [referrer](https://developer.mozilla.org/en-US/docs/Web/API/Document/referrer) property if set.\n */\n referrer: string | null;\n\n /**\n * Browser Location's [href](https://developer.mozilla.org/en-US/docs/Web/API/Location/href) property if set.\n */\n location: string | null;\n}\n\nfunction getEventConfig(config: RelayConfig): EventConfig {\n const { trackingId } = config;\n return { trackingId };\n}\n\nfunction getSource(): string {\n return `relay@${version}`;\n}\n\nexport function createMeta(\n type: string,\n config: RelayConfig,\n environment: Environment,\n clientIdManager: ClientIdManager\n): Readonly<Meta> {\n const { getReferrer, getLocation, getUserAgent } = environment;\n const eventConfig = getEventConfig(config);\n const clientId = clientIdManager.getClientId();\n\n return Object.freeze({\n type,\n config: eventConfig,\n ts: Date.now(),\n source: getSource(),\n clientId,\n userAgent: getUserAgent(),\n referrer: getReferrer(),\n location: getLocation(),\n });\n}\n","import { RelayEvent } from \"../event/relay-event\";\n\nconst ANY_EVENT_TYPE = \"*\";\n\n/**\n * Callback to perform an action when a specified event is emitted.\n * @typedef {function} EventCallback\n * @param {RelayEvent} event\n * @returns {void}\n */\nexport type EventCallback = (event: RelayEvent) => void;\n\ninterface Listener {\n type: string;\n callback: EventCallback;\n}\n\nexport interface ListenerManager {\n add: (listener: Listener) => () => void;\n call: (event: RelayEvent) => void;\n remove: (type: string, callback?: EventCallback) => void;\n}\n\nexport function createListenerManager(): ListenerManager {\n const listeners: Listener[] = [];\n\n function getListenerIndex({ type, callback }: Listener): number {\n return listeners.findIndex(\n (listener) => listener.type === type && listener.callback === callback\n );\n }\n\n function isMatchesType(listener: Listener, type: string): boolean {\n return listener.type === \"*\" || type === listener.type;\n }\n\n function add(listener: Listener): () => void {\n if (getListenerIndex(listener) < 0) {\n listeners.push(listener);\n }\n return () => remove(listener.type, listener.callback);\n }\n\n function call(event: RelayEvent) {\n listeners.forEach((listener) => {\n if (isMatchesType(listener, event.meta.type)) {\n try {\n listener.callback(event);\n } catch (e) {\n console.error(e);\n }\n }\n });\n }\n\n function removeMultiple(type: string) {\n if (type === ANY_EVENT_TYPE) {\n listeners.length = 0;\n } else {\n for (let i = listeners.length - 1; i >= 0; i--) {\n if (listeners[i].type === type) {\n listeners.splice(i, 1);\n }\n }\n }\n }\n\n function removeOne(listener: Listener) {\n const index = getListenerIndex(listener);\n if (index >= 0) {\n listeners.splice(index, 1);\n }\n }\n\n function remove(type: string, callback?: EventCallback) {\n !!callback ? removeOne({ type, callback }) : removeMultiple(type);\n }\n\n return {\n add,\n call,\n remove,\n };\n}\n","export type RelayMode = \"emit\" | \"validate\" | \"disabled\";\n\nexport interface RelayConfig {\n /**\n * Endpoint defined to communicate with the Event API.\n */\n url: string;\n\n /**\n * Token to authorize the access to the Event API endpoint.\n */\n token: string;\n\n /**\n * The unique identifier of a web property. See [Tracking ID](https://docs.coveo.com/en/n8tg0567/).\n */\n trackingId: string;\n\n /**\n * Defines the library mode. The possible values are:\n * \"emit\": Sends analytics events to Coveo to be stored.\n * \"validate\": Validates events without storing them. This mode is for debugging and development purposes only and should not be used in production.\n * \"disabled\": Prevents the emission of events and does not trigger callbacks.\n * @default emit\n */\n mode?: RelayMode;\n}\n\nexport interface ConfigManager {\n get: () => Readonly<RelayConfig>;\n update: (updatedConfig: Partial<RelayConfig>) => void;\n}\n\nfunction pick({\n url,\n token,\n trackingId,\n ...rest\n}: RelayConfig): Readonly<RelayConfig> {\n return Object.freeze({\n url,\n token,\n trackingId,\n ...(!!rest.mode && { mode: rest.mode }),\n });\n}\n\nexport function createConfigManager(\n initialConfig: RelayConfig\n): Readonly<ConfigManager> {\n let _config: Readonly<RelayConfig> = pick(initialConfig);\n\n return {\n get: () => _config,\n update: (updatedConfig: Partial<RelayConfig>) => {\n _config = pick({ ..._config, ...updatedConfig });\n },\n };\n}\n","import { emit } from \"./emit/emit\";\nimport { createClientIdManager } from \"./client-id/client-id\";\nimport { currentEnvironment } from \"./environment/environment\";\nimport { createRelayEvent } from \"./event/relay-event\";\nimport { version } from \"./version\";\nimport { createMeta, Meta } from \"./event/meta/meta\";\nimport { createListenerManager, EventCallback } from \"./listener/listener\";\nimport { createConfigManager, RelayConfig } from \"./config/config\";\nimport { ValidationError, ValidationResponse } from \"./validate/validate\";\nimport { buildNullEnvironment } from \"./environment/null/null\";\n\ntype RelayPayload = Record<string, unknown>;\ntype Off = () => void;\n\ninterface Relay {\n /**\n * Sends an event to the Event API.\n * @param {string} type - event's type to be emitted.\n * @param {RelayPayload} payload - payload to include within the event.\n * @returns {Promise<ValidationResponse | null>} the return value is typed ValidationResponse if the library configuration's mode is validate.\n */\n emit: (\n type: string,\n payload: RelayPayload\n ) => Promise<ValidationResponse | null>;\n\n /**\n * Gets the client-side generated meta object.\n * @param {string} type - event's type that will be included in the meta object.\n * @returns {Meta}\n */\n getMeta: (type: string) => Meta;\n\n /**\n * Attaches an event callback to either all event types or a specific one.\n * The callback set will be called when an event with the specified type is emitted.\n * Setting type as \"*\" will trigger the callback for all event types.\n * Returns the \"off\" function to detach the event callback.\n * @param {string} type - event's type.\n * @param {EventCallback} callback\n * @returns {Off}\n */\n on: (type: string, callback: EventCallback) => Off;\n\n /**\n * Detach callback(s) from events.\n * If only the \"type\" parameter is set, all callbacks for the specified type will be removed.\n * @param {string} type - event's type.\n * @param {EventCallback} callback - callback that should be removed.\n * @returns {void}\n */\n off: (type: string, callback?: EventCallback) => void;\n\n /**\n * Updates Relay's configuration after its initialization.\n * @param {Partial<RelayConfig>} config - configuration that should be updated.\n * @returns {void}\n */\n updateConfig: (config: Partial<RelayConfig>) => void;\n\n /**\n * Current version of the Relay library.\n */\n version: string;\n\n /**\n * Removes the visitorId cookie and localStorage key.\n * @returns {void}\n */\n clearStorage: () => void;\n}\n\n/**\n * Initializes the Relay library object.\n * @param {RelayConfig} initialConfig\n * @returns {Relay}\n */\nexport function createRelay(initialConfig: RelayConfig): Relay {\n const configManager = createConfigManager(initialConfig);\n const listenerManager = createListenerManager();\n\n const getEnvironment = () =>\n configManager.get().mode == \"disabled\"\n ? buildNullEnvironment()\n : currentEnvironment();\n const clientIdManager = createClientIdManager(getEnvironment());\n\n return {\n emit: (type: string, payload: RelayPayload) => {\n const config = configManager.get();\n const environment = getEnvironment();\n\n const event = createRelayEvent(\n type,\n payload,\n config,\n environment,\n clientIdManager\n );\n\n return emit({\n config,\n environment,\n event,\n listenerManager,\n });\n },\n getMeta: (type: string) =>\n createMeta(type, configManager.get(), getEnvironment(), clientIdManager),\n on: (type: string, callback: EventCallback) =>\n listenerManager.add({ type, callback }),\n off: (type: string, callback?: EventCallback) =>\n listenerManager.remove(type, callback),\n updateConfig: (config: Partial<RelayConfig>) =>\n configManager.update(config),\n version,\n clearStorage: () => {\n clientIdManager.clear();\n },\n };\n}\n\nexport type { RelayPayload, RelayConfig, ValidationError, ValidationResponse };\n","import { Environment } from \"../environment\";\nimport { createNullStorage } from \"../storage\";\n\nexport function buildNullEnvironment(): Environment {\n return {\n runtime: \"null\",\n fetch: () => Promise.resolve(new Response(JSON.stringify(\"\"))),\n send: async () => null,\n getReferrer: () => null,\n getLocation: () => null,\n getUserAgent: () => null,\n generateUUID: () => \"\",\n storage: createNullStorage(),\n };\n}\n","import { ClientIdManager } from \"../client-id/client-id\";\nimport { Environment } from \"../environment/environment\";\nimport { RelayConfig, RelayPayload } from \"../relay\";\nimport { createMeta, Meta } from \"./meta/meta\";\n\nexport interface RelayEvent extends RelayPayload {\n meta: Readonly<Meta>;\n}\n\nexport function createRelayEvent(\n type: string,\n payload: RelayPayload,\n config: RelayConfig,\n environment: Environment,\n clientIdManager: ClientIdManager\n): Readonly<RelayEvent> {\n return {\n ...payload,\n meta: createMeta(type, config, environment, clientIdManager),\n };\n}\n"],"names":["async","emit","params","listenerManager","event","config","mode","call","environment","url","token","headers","Authorization","response","fetch","method","body","JSON","stringify","data","json","ok","Error","valid","errors","type","message","path","validate","send","emitEvent","REGEX","createClientIdManager","key","getClientId","storage","existingClientId","getItem","clientId","uuid","test","generateUUID","setItem","clear","removeItem","cookieManager","prefix","cookiePrefix","cookieArray","document","cookie","split","prettifyCookie","replace","lastIndexOf","substring","length","expire","domain","host","parts","slice","join","getDomain","window","location","hostname","expireSection","Date","getTime","toUTCString","domainSection","this","createCookieManager","fetchAPI","init","catch","err","cause","buildBrowserEnvironment","runtime","navigator","sendBeacon","Blob","getReferrer","referrer","getLocation","href","getUserAgent","userAgent","crypto","randomUUID","localStorage","createNullStorage","currentEnvironment","e","isBrowser","version","createMeta","clientIdManager","eventConfig","trackingId","getEventConfig","Object","freeze","ts","now","source","ANY_EVENT_TYPE","createListenerManager","listeners","getListenerIndex","callback","findIndex","listener","remove","index","splice","removeOne","i","removeMultiple","add","push","forEach","isMatchesType","meta","console","error","pick","rest","createRelay","initialConfig","configManager","_config","get","update","updatedConfig","createConfigManager","getEnvironment","Promise","resolve","Response","payload","createRelayEvent","getMeta","on","off","updateConfig","clearStorage"],"mappings":"AAaOA,eAAeC,EAAKC,GACzB,MAAMC,gBAAEA,EAAeC,MAAEA,EAAKC,OAAEA,GAAWH,EAI3C,MAHkC,aAAhBG,EAAOC,MAEZH,EAAgBI,KAAKH,GACX,aAAhBC,EAAOC,KCsBTN,gBAAwBK,OAC7BA,EAAMG,YACNA,EAAWJ,MACXA,IAEA,MAAMK,IAAEA,EAAGC,MAAEA,GAAUL,EACjBM,EAAU,CACd,eAAgB,mBAChBC,cAAe,UAAUF,KAGrBG,QAAiBL,EAAYM,MAAM,GAAGL,a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AM,KACnBE,YAAa,IAAM,KACnBE,aAAc,IAAM,KACpB/C,aAAc,IAAM,GACpBN,QAAS0D,KDwELC,IACAK,EAAkBnE,EAAsB0G,KAE9C,MAAO,CACLzI,KAAM,CAACwB,EAAcqH,KACnB,MAAMzI,EAAS+H,EAAcE,MACvB9H,EAAckI,IAEdtI,EEnFN,SACJqB,EACAqH,EACAzI,EACAG,EACA2F,GAEA,MAAO,IACF2C,EACHjB,KAAM3B,EAAWzE,EAAMpB,EAAQG,EAAa2F,GAEhD,CFwEoB4C,CACZtH,EACAqH,EACAzI,EACAG,EACA2F,GAGF,OAAOlG,EAAK,CACVI,SACAG,cACAJ,QACAD,mBACA,EAEJ6I,QAAUvH,GACRyE,EAAWzE,EAAM2G,EAAcE,MAAOI,IAAkBvC,GAC1D8C,GAAI,CAACxH,EAAcuF,IACjB7G,EAAgBsH,IAAI,CAAEhG,OAAMuF,aAC9BkC,IAAK,CAACzH,EAAcuF,IAClB7G,EAAgBgH,OAAO1F,EAAMuF,GAC/BmC,aAAe9I,GACb+H,EAAcG,OAAOlI,GACvB4F,UACAmD,aAAc,KACZjD,EAAgBxD,OAAO,EAG7B","x_google_ignoreList":[2,4]}
@@ -1,8 +1,24 @@
1
1
  export type RelayMode = "emit" | "validate" | "disabled";
2
2
  export interface RelayConfig {
3
+ /**
4
+ * Endpoint defined to communicate with the Event API.
5
+ */
3
6
  url: string;
7
+ /**
8
+ * Token to authorize the access to the Event API endpoint.
9
+ */
4
10
  token: string;
11
+ /**
12
+ * The unique identifier of a web property. See [Tracking ID](https://docs.coveo.com/en/n8tg0567/).
13
+ */
5
14
  trackingId: string;
15
+ /**
16
+ * Defines the library mode. The possible values are:
17
+ * "emit": Sends analytics events to Coveo to be stored.
18
+ * "validate": Validates events without storing them. This mode is for debugging and development purposes only and should not be used in production.
19
+ * "disabled": Prevents the emission of events and does not trigger callbacks.
20
+ * @default emit
21
+ */
6
22
  mode?: RelayMode;
7
23
  }
8
24
  export interface ConfigManager {
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config/config.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,UAAU,GAAG,UAAU,CAAC;AAEzD,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,QAAQ,CAAC,WAAW,CAAC,CAAC;IACjC,MAAM,EAAE,CAAC,aAAa,EAAE,OAAO,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;CACvD;AAgBD,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,WAAW,GACzB,QAAQ,CAAC,aAAa,CAAC,CASzB"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config/config.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,UAAU,GAAG,UAAU,CAAC;AAEzD,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,QAAQ,CAAC,WAAW,CAAC,CAAC;IACjC,MAAM,EAAE,CAAC,aAAa,EAAE,OAAO,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;CACvD;AAgBD,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,WAAW,GACzB,QAAQ,CAAC,aAAa,CAAC,CASzB"}
@@ -3,8 +3,8 @@ export interface Environment {
3
3
  runtime: "browser" | "node" | "null";
4
4
  fetch: (url: string, init?: RequestInit) => Promise<Response>;
5
5
  send: (url: string, token: string, body: string) => Promise<null>;
6
- getReferrerUrl: () => string | null;
7
- getUrl: () => string | null;
6
+ getReferrer: () => string | null;
7
+ getLocation: () => string | null;
8
8
  getUserAgent: () => string | null;
9
9
  generateUUID: () => string;
10
10
  storage: Storage;
@@ -1 +1 @@
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,GAAG,MAAM,CAAC;IACrC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9D,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAClE,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
+ {"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,GAAG,MAAM,CAAC;IACrC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9D,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAClE,WAAW,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACjC,WAAW,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACjC,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"}
@@ -2,17 +2,41 @@ import { ClientIdManager } from "../../client-id/client-id";
2
2
  import { Environment } from "../../environment/environment";
3
3
  import { RelayConfig } from "../../config/config";
4
4
  interface EventConfig {
5
+ /**
6
+ * The unique identifier of a web property. See [Tracking ID](https://docs.coveo.com/en/n8tg0567/).
7
+ */
5
8
  trackingId: string;
6
9
  }
7
10
  export interface Meta {
11
+ /**
12
+ * Event's type that was emitted.
13
+ */
8
14
  type: string;
9
15
  config: EventConfig;
16
+ /**
17
+ * Timestamp when the event was emitted.
18
+ */
10
19
  ts: number;
20
+ /**
21
+ * Library and version in which the event is built and emitted.
22
+ */
11
23
  source: string;
24
+ /**
25
+ * Persistent unique identifier of a device.
26
+ */
12
27
  clientId: string;
28
+ /**
29
+ * Browser Navigator's [user agent](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/userAgent) property if set.
30
+ */
13
31
  userAgent: string | null;
14
- referrerUrl: string | null;
15
- url: string | null;
32
+ /**
33
+ * Browser Document's [referrer](https://developer.mozilla.org/en-US/docs/Web/API/Document/referrer) property if set.
34
+ */
35
+ referrer: string | null;
36
+ /**
37
+ * Browser Location's [href](https://developer.mozilla.org/en-US/docs/Web/API/Location/href) property if set.
38
+ */
39
+ location: string | null;
16
40
  }
17
41
  export declare function createMeta(type: string, config: RelayConfig, environment: Environment, clientIdManager: ClientIdManager): Readonly<Meta>;
18
42
  export {};
@@ -1 +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,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD,UAAU,WAAW;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC;IACpB,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,MAAM,EAAE,WAAW,EACnB,WAAW,EAAE,WAAW,EACxB,eAAe,EAAE,eAAe,GAC/B,QAAQ,CAAC,IAAI,CAAC,CAehB"}
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,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD,UAAU,WAAW;IACnB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,IAAI;IACnB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC;IAEpB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAEzB;;OAEG;IACH,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAExB;;OAEG;IACH,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAWD,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,WAAW,EACnB,WAAW,EAAE,WAAW,EACxB,eAAe,EAAE,eAAe,GAC/B,QAAQ,CAAC,IAAI,CAAC,CAehB"}
@@ -1,4 +1,10 @@
1
1
  import { RelayEvent } from "../event/relay-event";
2
+ /**
3
+ * Callback to perform an action when a specified event is emitted.
4
+ * @typedef {function} EventCallback
5
+ * @param {RelayEvent} event
6
+ * @returns {void}
7
+ */
2
8
  export type EventCallback = (event: RelayEvent) => void;
3
9
  interface Listener {
4
10
  type: string;
@@ -1 +1 @@
1
- {"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../../src/listener/listener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIlD,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;AAExD,UAAU,QAAQ;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,aAAa,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,MAAM,IAAI,CAAC;IACxC,IAAI,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IAClC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;CAC1D;AAED,wBAAgB,qBAAqB,IAAI,eAAe,CA4DvD"}
1
+ {"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../../src/listener/listener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIlD;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;AAExD,UAAU,QAAQ;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,aAAa,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,MAAM,IAAI,CAAC;IACxC,IAAI,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IAClC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;CAC1D;AAED,wBAAgB,qBAAqB,IAAI,eAAe,CA4DvD"}
@@ -5,14 +5,58 @@ import { ValidationError, ValidationResponse } from "./validate/validate";
5
5
  type RelayPayload = Record<string, unknown>;
6
6
  type Off = () => void;
7
7
  interface Relay {
8
+ /**
9
+ * Sends an event to the Event API.
10
+ * @param {string} type - event's type to be emitted.
11
+ * @param {RelayPayload} payload - payload to include within the event.
12
+ * @returns {Promise<ValidationResponse | null>} the return value is typed ValidationResponse if the library configuration's mode is validate.
13
+ */
8
14
  emit: (type: string, payload: RelayPayload) => Promise<ValidationResponse | null>;
15
+ /**
16
+ * Gets the client-side generated meta object.
17
+ * @param {string} type - event's type that will be included in the meta object.
18
+ * @returns {Meta}
19
+ */
9
20
  getMeta: (type: string) => Meta;
21
+ /**
22
+ * Attaches an event callback to either all event types or a specific one.
23
+ * The callback set will be called when an event with the specified type is emitted.
24
+ * Setting type as "*" will trigger the callback for all event types.
25
+ * Returns the "off" function to detach the event callback.
26
+ * @param {string} type - event's type.
27
+ * @param {EventCallback} callback
28
+ * @returns {Off}
29
+ */
10
30
  on: (type: string, callback: EventCallback) => Off;
31
+ /**
32
+ * Detach callback(s) from events.
33
+ * If only the "type" parameter is set, all callbacks for the specified type will be removed.
34
+ * @param {string} type - event's type.
35
+ * @param {EventCallback} callback - callback that should be removed.
36
+ * @returns {void}
37
+ */
11
38
  off: (type: string, callback?: EventCallback) => void;
39
+ /**
40
+ * Updates Relay's configuration after its initialization.
41
+ * @param {Partial<RelayConfig>} config - configuration that should be updated.
42
+ * @returns {void}
43
+ */
12
44
  updateConfig: (config: Partial<RelayConfig>) => void;
45
+ /**
46
+ * Current version of the Relay library.
47
+ */
13
48
  version: string;
49
+ /**
50
+ * Removes the visitorId cookie and localStorage key.
51
+ * @returns {void}
52
+ */
14
53
  clearStorage: () => void;
15
54
  }
55
+ /**
56
+ * Initializes the Relay library object.
57
+ * @param {RelayConfig} initialConfig
58
+ * @returns {Relay}
59
+ */
16
60
  export declare function createRelay(initialConfig: RelayConfig): Relay;
17
61
  export type { RelayPayload, RelayConfig, ValidationError, ValidationResponse };
18
62
  //# sourceMappingURL=relay.d.ts.map
@@ -1 +1 @@
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,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAG1E,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,kBAAkB,GAAG,IAAI,CAAC,CAAC;IACxC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,EAAE,EAAE,CAAC,IAAI,E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,QAAQ,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IAEtD;;;;OAIG;IACH,YAAY,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;IAErD;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,YAAY,EAAE,MAAM,IAAI,CAAC;CAC1B;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,aAAa,EAAE,WAAW,GAAG,KAAK,CA2C7D;AAED,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,kBAAkB,EAAE,CAAC"}
@@ -7,12 +7,28 @@ export interface ValidateParams {
7
7
  event: Readonly<RelayEvent>;
8
8
  }
9
9
  export interface ValidationError {
10
+ /**
11
+ * Type of syntax error of an event's property.
12
+ */
10
13
  type: string;
14
+ /**
15
+ * Message describing the syntax error of an event's property.
16
+ */
11
17
  message: string;
18
+ /**
19
+ * Path of the property with a syntax error in the event's payload.
20
+ */
12
21
  path: string;
13
22
  }
14
23
  export interface ValidationResponse {
24
+ /**
25
+ * Indicates whether the payload is valid.
26
+ */
15
27
  valid: boolean;
28
+ /**
29
+ * List of syntax errors found in the emitted event(s).
30
+ * Each syntax error for a given property in a given event will be represented as a single ValidationError object.
31
+ */
16
32
  errors: ValidationError[];
17
33
  }
18
34
  export declare function validate({ config, environment, event, }: ValidateParams): Promise<Readonly<ValidationResponse>>;
@@ -1 +1 @@
1
- {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../src/validate/validate.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,UAAU,CAAC;AAEvC,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,WAAW,CAAC;IACpB,WAAW,EAAE,WAAW,CAAC;IACzB,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;CAC7B;AAED,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,CAAC,EAC7B,MAAM,EACN,WAAW,EACX,KAAK,GACN,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,CA8BxD"}
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../src/validate/validate.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,UAAU,CAAC;AAEvC,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,WAAW,CAAC;IACpB,WAAW,EAAE,WAAW,CAAC;IACzB,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;CAC7B;AAED,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,KAAK,EAAE,OAAO,CAAC;IAEf;;;OAGG;IACH,MAAM,EAAE,eAAe,EAAE,CAAC;CAC3B;AAED,wBAAsB,QAAQ,CAAC,EAC7B,MAAM,EACN,WAAW,EACX,KAAK,GACN,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,CA8BxD"}
package/lib/relay.cjs CHANGED
@@ -116,7 +116,7 @@ async function fetchAPI(url, init) {
116
116
  });
117
117
  }
118
118
 
119
- function getReferrerUrl() {
119
+ function getReferrer() {
120
120
  const referrer = document.referrer;
121
121
  return referrer === "" ? null : referrer;
122
122
  }
@@ -133,8 +133,8 @@ function buildBrowserEnvironment() {
133
133
  }
134
134
  return null;
135
135
  },
136
- getReferrerUrl: () => getReferrerUrl(),
137
- getUrl: () => window.location.href,
136
+ getReferrer: () => getReferrer(),
137
+ getLocation: () => window.location.href,
138
138
  getUserAgent: () => navigator.userAgent,
139
139
  generateUUID: () => crypto.randomUUID(),
140
140
  storage: createBrowserStorage(),
@@ -171,8 +171,8 @@ function buildNodeEnvironment() {
171
171
  });
172
172
  return null;
173
173
  },
174
- getReferrerUrl: () => null,
175
- getUrl: () => null,
174
+ getReferrer: () => null,
175
+ getLocation: () => null,
176
176
  getUserAgent: () => null,
177
177
  generateUUID: () => crypto.randomUUID(),
178
178
  storage: createNullStorage(),
@@ -191,7 +191,7 @@ function isBrowser() {
191
191
  }
192
192
  }
193
193
 
194
- const version = "0.6.2" ;
194
+ const version = "0.6.4" ;
195
195
 
196
196
  function getEventConfig(config) {
197
197
  const { trackingId } = config;
@@ -201,7 +201,7 @@ function getSource() {
201
201
  return `relay@${version}`;
202
202
  }
203
203
  function createMeta(type, config, environment, clientIdManager) {
204
- const { getReferrerUrl, getUrl, getUserAgent } = environment;
204
+ const { getReferrer, getLocation, getUserAgent } = environment;
205
205
  const eventConfig = getEventConfig(config);
206
206
  const clientId = clientIdManager.getClientId();
207
207
  return Object.freeze({
@@ -211,8 +211,8 @@ function createMeta(type, config, environment, clientIdManager) {
211
211
  source: getSource(),
212
212
  clientId,
213
213
  userAgent: getUserAgent(),
214
- referrerUrl: getReferrerUrl(),
215
- url: getUrl(),
214
+ referrer: getReferrer(),
215
+ location: getLocation(),
216
216
  });
217
217
  }
218
218
 
@@ -301,14 +301,19 @@ function buildNullEnvironment() {
301
301
  runtime: "null",
302
302
  fetch: () => Promise.resolve(new Response(JSON.stringify(""))),
303
303
  send: async () => null,
304
- getReferrerUrl: () => null,
305
- getUrl: () => null,
304
+ getReferrer: () => null,
305
+ getLocation: () => null,
306
306
  getUserAgent: () => null,
307
307
  generateUUID: () => "",
308
308
  storage: createNullStorage(),
309
309
  };
310
310
  }
311
311
 
312
+ /**
313
+ * Initializes the Relay library object.
314
+ * @param {RelayConfig} initialConfig
315
+ * @returns {Relay}
316
+ */
312
317
  function createRelay(initialConfig) {
313
318
  const configManager = createConfigManager(initialConfig);
314
319
  const listenerManager = createListenerManager();
package/lib/relay.js CHANGED
@@ -114,7 +114,7 @@ async function fetchAPI(url, init) {
114
114
  });
115
115
  }
116
116
 
117
- function getReferrerUrl() {
117
+ function getReferrer() {
118
118
  const referrer = document.referrer;
119
119
  return referrer === "" ? null : referrer;
120
120
  }
@@ -131,8 +131,8 @@ function buildBrowserEnvironment() {
131
131
  }
132
132
  return null;
133
133
  },
134
- getReferrerUrl: () => getReferrerUrl(),
135
- getUrl: () => window.location.href,
134
+ getReferrer: () => getReferrer(),
135
+ getLocation: () => window.location.href,
136
136
  getUserAgent: () => navigator.userAgent,
137
137
  generateUUID: () => crypto.randomUUID(),
138
138
  storage: createBrowserStorage(),
@@ -169,8 +169,8 @@ function buildNodeEnvironment() {
169
169
  });
170
170
  return null;
171
171
  },
172
- getReferrerUrl: () => null,
173
- getUrl: () => null,
172
+ getReferrer: () => null,
173
+ getLocation: () => null,
174
174
  getUserAgent: () => null,
175
175
  generateUUID: () => crypto.randomUUID(),
176
176
  storage: createNullStorage(),
@@ -189,7 +189,7 @@ function isBrowser() {
189
189
  }
190
190
  }
191
191
 
192
- const version = "0.6.2" ;
192
+ const version = "0.6.4" ;
193
193
 
194
194
  function getEventConfig(config) {
195
195
  const { trackingId } = config;
@@ -199,7 +199,7 @@ function getSource() {
199
199
  return `relay@${version}`;
200
200
  }
201
201
  function createMeta(type, config, environment, clientIdManager) {
202
- const { getReferrerUrl, getUrl, getUserAgent } = environment;
202
+ const { getReferrer, getLocation, getUserAgent } = environment;
203
203
  const eventConfig = getEventConfig(config);
204
204
  const clientId = clientIdManager.getClientId();
205
205
  return Object.freeze({
@@ -209,8 +209,8 @@ function createMeta(type, config, environment, clientIdManager) {
209
209
  source: getSource(),
210
210
  clientId,
211
211
  userAgent: getUserAgent(),
212
- referrerUrl: getReferrerUrl(),
213
- url: getUrl(),
212
+ referrer: getReferrer(),
213
+ location: getLocation(),
214
214
  });
215
215
  }
216
216
 
@@ -299,14 +299,19 @@ function buildNullEnvironment() {
299
299
  runtime: "null",
300
300
  fetch: () => Promise.resolve(new Response(JSON.stringify(""))),
301
301
  send: async () => null,
302
- getReferrerUrl: () => null,
303
- getUrl: () => null,
302
+ getReferrer: () => null,
303
+ getLocation: () => null,
304
304
  getUserAgent: () => null,
305
305
  generateUUID: () => "",
306
306
  storage: createNullStorage(),
307
307
  };
308
308
  }
309
309
 
310
+ /**
311
+ * Initializes the Relay library object.
312
+ * @param {RelayConfig} initialConfig
313
+ * @returns {Relay}
314
+ */
310
315
  function createRelay(initialConfig) {
311
316
  const configManager = createConfigManager(initialConfig);
312
317
  const listenerManager = createListenerManager();
package/lib/relay.mjs CHANGED
@@ -114,7 +114,7 @@ async function fetchAPI(url, init) {
114
114
  });
115
115
  }
116
116
 
117
- function getReferrerUrl() {
117
+ function getReferrer() {
118
118
  const referrer = document.referrer;
119
119
  return referrer === "" ? null : referrer;
120
120
  }
@@ -131,8 +131,8 @@ function buildBrowserEnvironment() {
131
131
  }
132
132
  return null;
133
133
  },
134
- getReferrerUrl: () => getReferrerUrl(),
135
- getUrl: () => window.location.href,
134
+ getReferrer: () => getReferrer(),
135
+ getLocation: () => window.location.href,
136
136
  getUserAgent: () => navigator.userAgent,
137
137
  generateUUID: () => crypto.randomUUID(),
138
138
  storage: createBrowserStorage(),
@@ -169,8 +169,8 @@ function buildNodeEnvironment() {
169
169
  });
170
170
  return null;
171
171
  },
172
- getReferrerUrl: () => null,
173
- getUrl: () => null,
172
+ getReferrer: () => null,
173
+ getLocation: () => null,
174
174
  getUserAgent: () => null,
175
175
  generateUUID: () => crypto.randomUUID(),
176
176
  storage: createNullStorage(),
@@ -189,7 +189,7 @@ function isBrowser() {
189
189
  }
190
190
  }
191
191
 
192
- const version = "0.6.2" ;
192
+ const version = "0.6.4" ;
193
193
 
194
194
  function getEventConfig(config) {
195
195
  const { trackingId } = config;
@@ -199,7 +199,7 @@ function getSource() {
199
199
  return `relay@${version}`;
200
200
  }
201
201
  function createMeta(type, config, environment, clientIdManager) {
202
- const { getReferrerUrl, getUrl, getUserAgent } = environment;
202
+ const { getReferrer, getLocation, getUserAgent } = environment;
203
203
  const eventConfig = getEventConfig(config);
204
204
  const clientId = clientIdManager.getClientId();
205
205
  return Object.freeze({
@@ -209,8 +209,8 @@ function createMeta(type, config, environment, clientIdManager) {
209
209
  source: getSource(),
210
210
  clientId,
211
211
  userAgent: getUserAgent(),
212
- referrerUrl: getReferrerUrl(),
213
- url: getUrl(),
212
+ referrer: getReferrer(),
213
+ location: getLocation(),
214
214
  });
215
215
  }
216
216
 
@@ -299,14 +299,19 @@ function buildNullEnvironment() {
299
299
  runtime: "null",
300
300
  fetch: () => Promise.resolve(new Response(JSON.stringify(""))),
301
301
  send: async () => null,
302
- getReferrerUrl: () => null,
303
- getUrl: () => null,
302
+ getReferrer: () => null,
303
+ getLocation: () => null,
304
304
  getUserAgent: () => null,
305
305
  generateUUID: () => "",
306
306
  storage: createNullStorage(),
307
307
  };
308
308
  }
309
309
 
310
+ /**
311
+ * Initializes the Relay library object.
312
+ * @param {RelayConfig} initialConfig
313
+ * @returns {Relay}
314
+ */
310
315
  function createRelay(initialConfig) {
311
316
  const configManager = createConfigManager(initialConfig);
312
317
  const listenerManager = createListenerManager();
@@ -1,8 +1,24 @@
1
1
  export type RelayMode = "emit" | "validate" | "disabled";
2
2
  export interface RelayConfig {
3
+ /**
4
+ * Endpoint defined to communicate with the Event API.
5
+ */
3
6
  url: string;
7
+ /**
8
+ * Token to authorize the access to the Event API endpoint.
9
+ */
4
10
  token: string;
11
+ /**
12
+ * The unique identifier of a web property. See [Tracking ID](https://docs.coveo.com/en/n8tg0567/).
13
+ */
5
14
  trackingId: string;
15
+ /**
16
+ * Defines the library mode. The possible values are:
17
+ * "emit": Sends analytics events to Coveo to be stored.
18
+ * "validate": Validates events without storing them. This mode is for debugging and development purposes only and should not be used in production.
19
+ * "disabled": Prevents the emission of events and does not trigger callbacks.
20
+ * @default emit
21
+ */
6
22
  mode?: RelayMode;
7
23
  }
8
24
  export interface ConfigManager {
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config/config.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,UAAU,GAAG,UAAU,CAAC;AAEzD,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,QAAQ,CAAC,WAAW,CAAC,CAAC;IACjC,MAAM,EAAE,CAAC,aAAa,EAAE,OAAO,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;CACvD;AAgBD,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,WAAW,GACzB,QAAQ,CAAC,aAAa,CAAC,CASzB"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config/config.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,UAAU,GAAG,UAAU,CAAC;AAEzD,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,QAAQ,CAAC,WAAW,CAAC,CAAC;IACjC,MAAM,EAAE,CAAC,aAAa,EAAE,OAAO,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;CACvD;AAgBD,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,WAAW,GACzB,QAAQ,CAAC,aAAa,CAAC,CASzB"}
@@ -3,8 +3,8 @@ export interface Environment {
3
3
  runtime: "browser" | "node" | "null";
4
4
  fetch: (url: string, init?: RequestInit) => Promise<Response>;
5
5
  send: (url: string, token: string, body: string) => Promise<null>;
6
- getReferrerUrl: () => string | null;
7
- getUrl: () => string | null;
6
+ getReferrer: () => string | null;
7
+ getLocation: () => string | null;
8
8
  getUserAgent: () => string | null;
9
9
  generateUUID: () => string;
10
10
  storage: Storage;
@@ -1 +1 @@
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,GAAG,MAAM,CAAC;IACrC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9D,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAClE,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
+ {"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,GAAG,MAAM,CAAC;IACrC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9D,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAClE,WAAW,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACjC,WAAW,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACjC,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"}
@@ -2,17 +2,41 @@ import { ClientIdManager } from "../../client-id/client-id";
2
2
  import { Environment } from "../../environment/environment";
3
3
  import { RelayConfig } from "../../config/config";
4
4
  interface EventConfig {
5
+ /**
6
+ * The unique identifier of a web property. See [Tracking ID](https://docs.coveo.com/en/n8tg0567/).
7
+ */
5
8
  trackingId: string;
6
9
  }
7
10
  export interface Meta {
11
+ /**
12
+ * Event's type that was emitted.
13
+ */
8
14
  type: string;
9
15
  config: EventConfig;
16
+ /**
17
+ * Timestamp when the event was emitted.
18
+ */
10
19
  ts: number;
20
+ /**
21
+ * Library and version in which the event is built and emitted.
22
+ */
11
23
  source: string;
24
+ /**
25
+ * Persistent unique identifier of a device.
26
+ */
12
27
  clientId: string;
28
+ /**
29
+ * Browser Navigator's [user agent](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/userAgent) property if set.
30
+ */
13
31
  userAgent: string | null;
14
- referrerUrl: string | null;
15
- url: string | null;
32
+ /**
33
+ * Browser Document's [referrer](https://developer.mozilla.org/en-US/docs/Web/API/Document/referrer) property if set.
34
+ */
35
+ referrer: string | null;
36
+ /**
37
+ * Browser Location's [href](https://developer.mozilla.org/en-US/docs/Web/API/Location/href) property if set.
38
+ */
39
+ location: string | null;
16
40
  }
17
41
  export declare function createMeta(type: string, config: RelayConfig, environment: Environment, clientIdManager: ClientIdManager): Readonly<Meta>;
18
42
  export {};
@@ -1 +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,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD,UAAU,WAAW;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC;IACpB,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,MAAM,EAAE,WAAW,EACnB,WAAW,EAAE,WAAW,EACxB,eAAe,EAAE,eAAe,GAC/B,QAAQ,CAAC,IAAI,CAAC,CAehB"}
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,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD,UAAU,WAAW;IACnB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,IAAI;IACnB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC;IAEpB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAEzB;;OAEG;IACH,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAExB;;OAEG;IACH,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAWD,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,WAAW,EACnB,WAAW,EAAE,WAAW,EACxB,eAAe,EAAE,eAAe,GAC/B,QAAQ,CAAC,IAAI,CAAC,CAehB"}
@@ -1,4 +1,10 @@
1
1
  import { RelayEvent } from "../event/relay-event";
2
+ /**
3
+ * Callback to perform an action when a specified event is emitted.
4
+ * @typedef {function} EventCallback
5
+ * @param {RelayEvent} event
6
+ * @returns {void}
7
+ */
2
8
  export type EventCallback = (event: RelayEvent) => void;
3
9
  interface Listener {
4
10
  type: string;
@@ -1 +1 @@
1
- {"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../../src/listener/listener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIlD,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;AAExD,UAAU,QAAQ;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,aAAa,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,MAAM,IAAI,CAAC;IACxC,IAAI,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IAClC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;CAC1D;AAED,wBAAgB,qBAAqB,IAAI,eAAe,CA4DvD"}
1
+ {"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../../src/listener/listener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIlD;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;AAExD,UAAU,QAAQ;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,aAAa,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,MAAM,IAAI,CAAC;IACxC,IAAI,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IAClC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;CAC1D;AAED,wBAAgB,qBAAqB,IAAI,eAAe,CA4DvD"}
@@ -5,14 +5,58 @@ import { ValidationError, ValidationResponse } from "./validate/validate";
5
5
  type RelayPayload = Record<string, unknown>;
6
6
  type Off = () => void;
7
7
  interface Relay {
8
+ /**
9
+ * Sends an event to the Event API.
10
+ * @param {string} type - event's type to be emitted.
11
+ * @param {RelayPayload} payload - payload to include within the event.
12
+ * @returns {Promise<ValidationResponse | null>} the return value is typed ValidationResponse if the library configuration's mode is validate.
13
+ */
8
14
  emit: (type: string, payload: RelayPayload) => Promise<ValidationResponse | null>;
15
+ /**
16
+ * Gets the client-side generated meta object.
17
+ * @param {string} type - event's type that will be included in the meta object.
18
+ * @returns {Meta}
19
+ */
9
20
  getMeta: (type: string) => Meta;
21
+ /**
22
+ * Attaches an event callback to either all event types or a specific one.
23
+ * The callback set will be called when an event with the specified type is emitted.
24
+ * Setting type as "*" will trigger the callback for all event types.
25
+ * Returns the "off" function to detach the event callback.
26
+ * @param {string} type - event's type.
27
+ * @param {EventCallback} callback
28
+ * @returns {Off}
29
+ */
10
30
  on: (type: string, callback: EventCallback) => Off;
31
+ /**
32
+ * Detach callback(s) from events.
33
+ * If only the "type" parameter is set, all callbacks for the specified type will be removed.
34
+ * @param {string} type - event's type.
35
+ * @param {EventCallback} callback - callback that should be removed.
36
+ * @returns {void}
37
+ */
11
38
  off: (type: string, callback?: EventCallback) => void;
39
+ /**
40
+ * Updates Relay's configuration after its initialization.
41
+ * @param {Partial<RelayConfig>} config - configuration that should be updated.
42
+ * @returns {void}
43
+ */
12
44
  updateConfig: (config: Partial<RelayConfig>) => void;
45
+ /**
46
+ * Current version of the Relay library.
47
+ */
13
48
  version: string;
49
+ /**
50
+ * Removes the visitorId cookie and localStorage key.
51
+ * @returns {void}
52
+ */
14
53
  clearStorage: () => void;
15
54
  }
55
+ /**
56
+ * Initializes the Relay library object.
57
+ * @param {RelayConfig} initialConfig
58
+ * @returns {Relay}
59
+ */
16
60
  export declare function createRelay(initialConfig: RelayConfig): Relay;
17
61
  export type { RelayPayload, RelayConfig, ValidationError, ValidationResponse };
18
62
  //# sourceMappingURL=relay.d.ts.map
@@ -1 +1 @@
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,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAG1E,KAAK,YAAY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ACZ,OAAO,EAAE,YAAY,KAClB,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAAC;IAExC;;;;OAIG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAEhC;;;;;;;;OAQG;IACH,EAAE,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,KAAK,GAAG,CAAC;IAEnD;;;;;;OAMG;IACH,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IAEtD;;;;OAIG;IACH,YAAY,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;IAErD;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,YAAY,EAAE,MAAM,IAAI,CAAC;CAC1B;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,aAAa,EAAE,WAAW,GAAG,KAAK,CA2C7D;AAED,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,kBAAkB,EAAE,CAAC"}
@@ -7,12 +7,28 @@ export interface ValidateParams {
7
7
  event: Readonly<RelayEvent>;
8
8
  }
9
9
  export interface ValidationError {
10
+ /**
11
+ * Type of syntax error of an event's property.
12
+ */
10
13
  type: string;
14
+ /**
15
+ * Message describing the syntax error of an event's property.
16
+ */
11
17
  message: string;
18
+ /**
19
+ * Path of the property with a syntax error in the event's payload.
20
+ */
12
21
  path: string;
13
22
  }
14
23
  export interface ValidationResponse {
24
+ /**
25
+ * Indicates whether the payload is valid.
26
+ */
15
27
  valid: boolean;
28
+ /**
29
+ * List of syntax errors found in the emitted event(s).
30
+ * Each syntax error for a given property in a given event will be represented as a single ValidationError object.
31
+ */
16
32
  errors: ValidationError[];
17
33
  }
18
34
  export declare function validate({ config, environment, event, }: ValidateParams): Promise<Readonly<ValidationResponse>>;
@@ -1 +1 @@
1
- {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../src/validate/validate.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,UAAU,CAAC;AAEvC,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,WAAW,CAAC;IACpB,WAAW,EAAE,WAAW,CAAC;IACzB,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;CAC7B;AAED,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,CAAC,EAC7B,MAAM,EACN,WAAW,EACX,KAAK,GACN,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,CA8BxD"}
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../src/validate/validate.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,UAAU,CAAC;AAEvC,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,WAAW,CAAC;IACpB,WAAW,EAAE,WAAW,CAAC;IACzB,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;CAC7B;AAED,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,KAAK,EAAE,OAAO,CAAC;IAEf;;;OAGG;IACH,MAAM,EAAE,eAAe,EAAE,CAAC;CAC3B;AAED,wBAAsB,QAAQ,CAAC,EAC7B,MAAM,EACN,WAAW,EACX,KAAK,GACN,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,CA8BxD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coveo/relay",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "description": "A library for sending analytics events using Coveo's Event protocol.",
5
5
  "files": [
6
6
  "lib/**/*"