@coveo/relay 0.6.4 → 0.6.6

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.
Files changed (34) hide show
  1. package/lib/cdn/relay.min.js +1 -1
  2. package/lib/cdn/relay.min.js.map +1 -1
  3. package/lib/cdn/types/config/config.d.ts +4 -2
  4. package/lib/cdn/types/config/config.d.ts.map +1 -1
  5. package/lib/cdn/types/emit/emit.d.ts +1 -2
  6. package/lib/cdn/types/emit/emit.d.ts.map +1 -1
  7. package/lib/cdn/types/environment/browser/browser.d.ts.map +1 -1
  8. package/lib/cdn/types/environment/environment.d.ts +2 -1
  9. package/lib/cdn/types/environment/environment.d.ts.map +1 -1
  10. package/lib/cdn/types/environment/node/node.d.ts.map +1 -1
  11. package/lib/cdn/types/event/meta/meta.d.ts +10 -2
  12. package/lib/cdn/types/event/meta/meta.d.ts.map +1 -1
  13. package/lib/cdn/types/relay.d.ts +8 -5
  14. package/lib/cdn/types/relay.d.ts.map +1 -1
  15. package/lib/relay.cjs +23 -43
  16. package/lib/relay.js +23 -43
  17. package/lib/relay.mjs +23 -43
  18. package/lib/types/config/config.d.ts +4 -2
  19. package/lib/types/config/config.d.ts.map +1 -1
  20. package/lib/types/emit/emit.d.ts +1 -2
  21. package/lib/types/emit/emit.d.ts.map +1 -1
  22. package/lib/types/environment/browser/browser.d.ts.map +1 -1
  23. package/lib/types/environment/environment.d.ts +2 -1
  24. package/lib/types/environment/environment.d.ts.map +1 -1
  25. package/lib/types/environment/node/node.d.ts.map +1 -1
  26. package/lib/types/event/meta/meta.d.ts +10 -2
  27. package/lib/types/event/meta/meta.d.ts.map +1 -1
  28. package/lib/types/relay.d.ts +8 -5
  29. package/lib/types/relay.d.ts.map +1 -1
  30. package/package.json +8 -4
  31. package/lib/cdn/types/validate/validate.d.ts +0 -35
  32. package/lib/cdn/types/validate/validate.d.ts.map +0 -1
  33. package/lib/types/validate/validate.d.ts +0 -35
  34. package/lib/types/validate/validate.d.ts.map +0 -1
@@ -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},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};
1
+ var e=/^(?:[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 t(t){const n="visitorId";return{getClientId:()=>{const r=t.storage,o=r.getItem(n),c=o&&("string"==typeof(a=o)&&e.test(a))?o:t.generateUUID();var a;return r.setItem(n,c),c},clear:()=>{t.storage.removeItem(n)}}}const n=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),c=`;expires=${new Date((new Date).getTime()+r).toUTCString()}`,a=o?`;domain=${o}`:"";document.cookie=`${e}${t}=${n}${c}${a};path=/;SameSite=Lax`},removeItem(e){this.setItem(e,"",-1)}}}();async function r(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 o(){return{runtime:"browser",fetch:(e,t)=>r(e,t),send:async(e,t,n)=>{const r=navigator.sendBeacon(`${e}?access_token=${t}`,new Blob([JSON.stringify([n])],{type:"application/json"})),o=function(){const e="undefined"!=typeof window;return{sendMessage(t){e&&window.postMessage(t,"*")}}}();if(o.sendMessage({kind:"EVENT_PROTOCOL",event:n,url:e,token:t}),!r)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.")},getReferrer:()=>function(){const e=document.referrer;return""===e?null:e}(),getLocation:()=>window.location.href,getUserAgent:()=>navigator.userAgent,generateUUID:()=>crypto.randomUUID(),storage:{getItem:e=>n.getItem(e)||localStorage.getItem(e),removeItem(e){n.removeItem(e),localStorage.removeItem(e)},setItem(e,t){localStorage.setItem(e,t),n.setItem(e,t,31556952e3)}}}}function c(){return{getItem:()=>null,removeItem(){},setItem(){}}}function a(){return function(){try{return"object"==typeof window}catch(e){return!1}}()?o():{runtime:"node",fetch:(e,t)=>r(e,t),send:async(e,t,n)=>{const o={"Content-Type":"application/json",Authorization:`Bearer ${t}`};r(e,{method:"POST",body:JSON.stringify([n]),headers:o})},getReferrer:()=>null,getLocation:()=>null,getUserAgent:()=>null,generateUUID:()=>crypto.randomUUID(),storage:c()}}const s="0.6.6";function i(e,t,n,r){const{getReferrer:o,getLocation:c,getUserAgent:a}=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:a(),referrer:o(),location:c()})}const l="*";function u(){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===l)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 g({url:e,token:t,trackingId:n,...r}){return Object.freeze({url:e,token:t,trackingId:n,...!!r.mode&&{mode:r.mode}})}function f(e){const n=function(e){let t=g(e);return{get:()=>t,update:e=>{t=g({...t,...e})}}}(e),r=u(),o=()=>"disabled"==n.get().mode?{runtime:"null",fetch:()=>Promise.resolve(new Response(JSON.stringify(""))),send:async()=>{},getReferrer:()=>null,getLocation:()=>null,getUserAgent:()=>null,generateUUID:()=>"",storage:c()}:a(),l=t(o());return{emit:(e,t)=>{const c=n.get(),a=o(),s=function(e,t,n,r,o){return{...t,meta:i(e,n,r,o)}}(e,t,c,a,l);return async function({config:e,environment:t,event:n,listenerManager:r}){const{url:o,token:c,mode:a}=e;"disabled"!==a&&(r.call(n),t.send(o,c,n))}({config:c,environment:a,event:s,listenerManager:r})},getMeta:e=>i(e,n.get(),o(),l),on:(e,t)=>r.add({type:e,callback:t}),off:(e,t)=>r.remove(e,t),updateConfig:e=>n.update(e),version:s,clearStorage:()=>{l.clear()}}}export{f 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 /**\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,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,CDxDsCI,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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ACAmD,aAAc,KACZjD,EAAgBxD,OAAO,EAG7B","x_google_ignoreList":[2,4]}
1
+ {"version":3,"file":"relay.min.js","sources":["../../../../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","../../../../node_modules/.pnpm/@coveo+explorer-messenger@0.1.1/node_modules/@coveo/explorer-messenger/dist/messenger.js","../../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","../../src/emit/emit.ts"],"sourcesContent":["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 { createExplorerMessenger } from \"@coveo/explorer-messenger\";\nimport { Environment } from \"../environment\";\nimport { createBrowserStorage } from \"./storage/storage\";\nimport { fetchAPI } from \"../utils/fetch\";\nimport { RelayEvent } from \"../../event/relay-event\";\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, event: RelayEvent) => {\n const response = navigator.sendBeacon(\n `${url}?access_token=${token}`,\n new Blob([JSON.stringify([event])], {\n type: \"application/json\",\n })\n );\n\n const messenger = createExplorerMessenger();\n messenger.sendMessage({ kind: \"EVENT_PROTOCOL\", event, url, token });\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 getReferrer: () => getReferrer(),\n getLocation: () => window.location.href,\n getUserAgent: () => navigator.userAgent,\n generateUUID: () => crypto.randomUUID(),\n storage: createBrowserStorage(),\n };\n}\n","function createExplorerMessenger() {\n const isBrowser = typeof window !== \"undefined\";\n return {\n sendMessage(message) {\n isBrowser && window.postMessage(message, \"*\");\n }\n };\n}\nexport {\n createExplorerMessenger\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 { RelayEvent } from \"../event/relay-event\";\nimport { 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, event: RelayEvent) => Promise<void>;\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 { RelayEvent } from \"../../event/relay-event\";\nimport { 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, event: RelayEvent) => {\n const headers = {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${token}`,\n };\n fetchAPI(url, {\n method: \"POST\",\n body: JSON.stringify([event]),\n headers,\n });\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\n/**\n * The `EventConfig` object provides additonal information for the configuration associated with the event.\n */\nexport interface 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\n/**\n * The `Meta` object provides a structured representation of metadata associated with an emitted event.\n */\nexport interface Meta {\n /**\n * Event's type that was emitted.\n */\n type: string;\n\n /**\n * Configuration associated with the event.\n */\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\" | \"disabled\";\n\n/**\n * The `RelayConfig` object defines the configuration options for initializing a Relay instance.\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 * \"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, EventConfig } from \"./event/meta/meta\";\nimport { createListenerManager, EventCallback } from \"./listener/listener\";\nimport { createConfigManager, RelayConfig } from \"./config/config\";\nimport { buildNullEnvironment } from \"./environment/null/null\";\n\ntype RelayPayload = Record<string, unknown>;\ntype Off = () => void;\n\n/**\n * Relay instance.\n * This object provides a comprehensive set of variables and methods for interacting with the Event API.\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<void>}\n */\n emit: (type: string, payload: RelayPayload) => Promise<void>;\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 {\n Relay,\n Meta,\n EventConfig,\n EventCallback,\n RelayPayload,\n RelayConfig,\n};\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 () => undefined,\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","import { Environment } from \"../environment/environment\";\nimport { ListenerManager } from \"../listener/listener\";\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({\n config,\n environment,\n event,\n listenerManager,\n}: EmitParams) {\n const { url, token, mode } = config;\n const isEnabled = mode !== \"disabled\";\n\n if (isEnabled) {\n listenerManager.call(event);\n environment.send(url, token, event);\n }\n}\n"],"names":["REGEX","createClientIdManager","environment","key","getClientId","storage","existingClientId","getItem","clientId","uuid","test","generateUUID","setItem","clear","removeItem","cookieManager","prefix","cookiePrefix","cookieArray","document","cookie","split","prettifyCookie","replace","lastIndexOf","substring","length","data","expire","domain","host","parts","slice","join","getDomain","window","location","hostname","expireSection","Date","getTime","toUTCString","domainSection","this","createCookieManager","async","fetchAPI","url","init","fetch","catch","err","Error","message","cause","buildBrowserEnvironment","runtime","send","token","event","response","navigator","sendBeacon","Blob","JSON","stringify","type","messenger","isBrowser","sendMessage","postMessage","createExplorerMessenger","kind","getReferrer","referrer","getLocation","href","getUserAgent","userAgent","crypto","randomUUID","localStorage","createNullStorage","currentEnvironment","e","headers","Authorization","method","body","version","createMeta","config","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","call","forEach","isMatchesType","meta","console","error","pick","rest","mode","createRelay","initialConfig","configManager","_config","get","update","updatedConfig","createConfigManager","listenerManager","getEnvironment","Promise","resolve","Response","emit","payload","createRelayEvent","getMeta","on","off","updateConfig","clearStorage"],"mappings":"AAAA,IAAAA,EAAe,sHCQT,SAAUC,EACdC,GAEA,MAAMC,EAAM,YACZ,MAAO,CACLC,YAAa,KACX,MAAMC,EAAUH,EAAYG,QAEtBC,EAAmBD,EAAQE,QAAQJ,GACnCK,EACJF,ICfiB,iBADPG,EDgBmBH,ICfAN,EAAMU,KAAKD,IDgBpCH,EACAJ,EAAYS,eClBxB,IAAkBF,EDoBZ,OADAJ,EAAQO,QAAQT,EAAKK,GACdA,CAAQ,EAEjBK,MAAO,KACLX,EAAYG,QAAQS,WAAWX,EAAI,EAGzC,CEtBO,MAAMY,EAEb,WACE,MAAMC,EAAS,SAMf,MAAO,CACL,OAAAT,CAAQJ,GACN,MAAMc,EAAe,GAAGD,IAASb,KAC3Be,EAAcC,SAASC,OAAOC,MAAM,KAC1C,IAAK,MAAMD,KAAUF,EAAa,CAChC,MAAMI,EAAiBF,EAAOG,QAAQ,OAAQ,IAC9C,GAAoD,IAAhDD,EAAeE,YAAYP,EAAc,GAC3C,OAAOK,EAAeG,UACpBR,EAAaS,OACbJ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2,6]}
@@ -1,4 +1,7 @@
1
- export type RelayMode = "emit" | "validate" | "disabled";
1
+ export type RelayMode = "emit" | "disabled";
2
+ /**
3
+ * The `RelayConfig` object defines the configuration options for initializing a Relay instance.
4
+ */
2
5
  export interface RelayConfig {
3
6
  /**
4
7
  * Endpoint defined to communicate with the Event API.
@@ -15,7 +18,6 @@ export interface RelayConfig {
15
18
  /**
16
19
  * Defines the library mode. The possible values are:
17
20
  * "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
21
  * "disabled": Prevents the emission of events and does not trigger callbacks.
20
22
  * @default emit
21
23
  */
@@ -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;;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"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config/config.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,UAAU,CAAC;AAE5C;;GAEG;AACH,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;;;;;OAKG;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"}
@@ -8,6 +8,5 @@ export interface EmitParams {
8
8
  event: RelayEvent;
9
9
  listenerManager: ListenerManager;
10
10
  }
11
- export declare function emit(params: EmitParams): Promise<Readonly<import("../relay").ValidationResponse> | null>;
12
- export declare function emitEvent({ event, config, environment, }: EmitParams): Promise<null>;
11
+ export declare function emit({ config, environment, event, listenerManager, }: EmitParams): Promise<void>;
13
12
  //# sourceMappingURL=emit.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../../src/emit/emit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,WAAW,CAAC;IACpB,WAAW,EAAE,WAAW,CAAC;IACzB,KAAK,EAAE,UAAU,CAAC;IAClB,eAAe,EAAE,eAAe,CAAC;CAClC;AAED,wBAAsB,IAAI,CAAC,MAAM,EAAE,UAAU,mEAM5C;AAED,wBAAsB,SAAS,CAAC,EAC9B,KAAK,EACL,MAAM,EACN,WAAW,GACZ,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAI5B"}
1
+ {"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../../src/emit/emit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,WAAW,CAAC;IACpB,WAAW,EAAE,WAAW,CAAC;IACzB,KAAK,EAAE,UAAU,CAAC;IAClB,eAAe,EAAE,eAAe,CAAC;CAClC;AAED,wBAAsB,IAAI,CAAC,EACzB,MAAM,EACN,WAAW,EACX,KAAK,EACL,eAAe,GAChB,EAAE,UAAU,iBAQZ"}
@@ -1 +1 @@
1
- {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../../src/environment/browser/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAU7C,wBAAgB,uBAAuB,IAAI,WAAW,CA0BrD"}
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../../src/environment/browser/browser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAW7C,wBAAgB,uBAAuB,IAAI,WAAW,CA2BrD"}
@@ -1,8 +1,9 @@
1
+ import { RelayEvent } from "../event/relay-event";
1
2
  import { Storage } from "./storage";
2
3
  export interface Environment {
3
4
  runtime: "browser" | "node" | "null";
4
5
  fetch: (url: string, init?: RequestInit) => Promise<Response>;
5
- send: (url: string, token: string, body: string) => Promise<null>;
6
+ send: (url: string, token: string, event: RelayEvent) => Promise<void>;
6
7
  getReferrer: () => string | null;
7
8
  getLocation: () => string | null;
8
9
  getUserAgent: () => string | null;
@@ -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,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"}
1
+ {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../../src/environment/environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGlD,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,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACvE,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"}
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../../src/environment/node/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI7C,wBAAgB,oBAAoB,IAAI,WAAW,CAsBlD"}
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../../src/environment/node/node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI7C,wBAAgB,oBAAoB,IAAI,WAAW,CAqBlD"}
@@ -1,17 +1,26 @@
1
1
  import { ClientIdManager } from "../../client-id/client-id";
2
2
  import { Environment } from "../../environment/environment";
3
3
  import { RelayConfig } from "../../config/config";
4
- interface EventConfig {
4
+ /**
5
+ * The `EventConfig` object provides additonal information for the configuration associated with the event.
6
+ */
7
+ export interface EventConfig {
5
8
  /**
6
9
  * The unique identifier of a web property. See [Tracking ID](https://docs.coveo.com/en/n8tg0567/).
7
10
  */
8
11
  trackingId: string;
9
12
  }
13
+ /**
14
+ * The `Meta` object provides a structured representation of metadata associated with an emitted event.
15
+ */
10
16
  export interface Meta {
11
17
  /**
12
18
  * Event's type that was emitted.
13
19
  */
14
20
  type: string;
21
+ /**
22
+ * Configuration associated with the event.
23
+ */
15
24
  config: EventConfig;
16
25
  /**
17
26
  * Timestamp when the event was emitted.
@@ -39,5 +48,4 @@ export interface Meta {
39
48
  location: string | null;
40
49
  }
41
50
  export declare function createMeta(type: string, config: RelayConfig, environment: Environment, clientIdManager: ClientIdManager): Readonly<Meta>;
42
- export {};
43
51
  //# sourceMappingURL=meta.d.ts.map
@@ -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;;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
+ {"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;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,IAAI;IACnB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,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,17 +1,20 @@
1
- import { Meta } from "./event/meta/meta";
1
+ import { Meta, EventConfig } from "./event/meta/meta";
2
2
  import { EventCallback } from "./listener/listener";
3
3
  import { RelayConfig } from "./config/config";
4
- import { ValidationError, ValidationResponse } from "./validate/validate";
5
4
  type RelayPayload = Record<string, unknown>;
6
5
  type Off = () => void;
6
+ /**
7
+ * Relay instance.
8
+ * This object provides a comprehensive set of variables and methods for interacting with the Event API.
9
+ */
7
10
  interface Relay {
8
11
  /**
9
12
  * Sends an event to the Event API.
10
13
  * @param {string} type - event's type to be emitted.
11
14
  * @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.
15
+ * @returns {Promise<void>}
13
16
  */
14
- emit: (type: string, payload: RelayPayload) => Promise<ValidationResponse | null>;
17
+ emit: (type: string, payload: RelayPayload) => Promise<void>;
15
18
  /**
16
19
  * Gets the client-side generated meta object.
17
20
  * @param {string} type - event's type that will be included in the meta object.
@@ -58,5 +61,5 @@ interface Relay {
58
61
  * @returns {Relay}
59
62
  */
60
63
  export declare function createRelay(initialConfig: RelayConfig): Relay;
61
- export type { RelayPayload, RelayConfig, ValidationError, ValidationResponse };
64
+ export type { Relay, Meta, EventConfig, EventCallback, RelayPayload, RelayConfig, };
62
65
  //# 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;;;;;OAKG;IACH,IAAI,EAAE,CACJ,IAAI,EAAE,MAAM,EACZ,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,E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EACZ,WAAW,GACZ,CAAC"}
package/lib/relay.cjs CHANGED
@@ -1,41 +1,12 @@
1
1
  'use strict';
2
2
 
3
- async function validate$1({ config, environment, event, }) {
4
- const { url, token } = config;
5
- const headers = {
6
- "Content-Type": "application/json",
7
- Authorization: `Bearer ${token}`,
8
- };
9
- const response = await environment.fetch(`${url}/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
- ...data,
18
- });
3
+ async function emit({ config, environment, event, listenerManager, }) {
4
+ const { url, token, mode } = config;
5
+ const isEnabled = mode !== "disabled";
6
+ if (isEnabled) {
7
+ listenerManager.call(event);
8
+ environment.send(url, token, event);
19
9
  }
20
- if (!data) {
21
- return {
22
- valid: false,
23
- errors: [{ type: "", message: "disabled", path: "" }],
24
- };
25
- }
26
- const { valid, errors } = data[0];
27
- return { valid, errors: errors ?? [] };
28
- }
29
-
30
- async function emit(params) {
31
- const { listenerManager, event, config } = params;
32
- const isEnabled = config.mode !== "disabled";
33
- isEnabled && listenerManager.call(event);
34
- return config.mode === "validate" ? validate$1(params) : emitEvent(params);
35
- }
36
- async function emitEvent({ event, config, environment, }) {
37
- const { url, token } = config;
38
- return environment.send(url, token, JSON.stringify([event]));
39
10
  }
40
11
 
41
12
  var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
@@ -62,6 +33,15 @@ function createClientIdManager(environment) {
62
33
  };
63
34
  }
64
35
 
36
+ function createExplorerMessenger() {
37
+ const isBrowser = typeof window !== "undefined";
38
+ return {
39
+ sendMessage(message) {
40
+ isBrowser && window.postMessage(message, "*");
41
+ }
42
+ };
43
+ }
44
+
65
45
  const cookieManager = createCookieManager();
66
46
  function createCookieManager() {
67
47
  const prefix = "coveo_";
@@ -124,14 +104,15 @@ function buildBrowserEnvironment() {
124
104
  return {
125
105
  runtime: "browser",
126
106
  fetch: (url, init) => fetchAPI(url, init),
127
- send: async (url, token, body) => {
128
- const response = navigator.sendBeacon(`${url}?access_token=${token}`, new Blob([body], {
107
+ send: async (url, token, event) => {
108
+ const response = navigator.sendBeacon(`${url}?access_token=${token}`, new Blob([JSON.stringify([event])], {
129
109
  type: "application/json",
130
110
  }));
111
+ const messenger = createExplorerMessenger();
112
+ messenger.sendMessage({ kind: "EVENT_PROTOCOL", event, url, token });
131
113
  if (!response) {
132
114
  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.`);
133
115
  }
134
- return null;
135
116
  },
136
117
  getReferrer: () => getReferrer(),
137
118
  getLocation: () => window.location.href,
@@ -159,17 +140,16 @@ function buildNodeEnvironment() {
159
140
  return {
160
141
  runtime: "node",
161
142
  fetch: (url, init) => fetchAPI(url, init),
162
- send: async (url, token, body) => {
143
+ send: async (url, token, event) => {
163
144
  const headers = {
164
145
  "Content-Type": "application/json",
165
146
  Authorization: `Bearer ${token}`,
166
147
  };
167
148
  fetchAPI(url, {
168
149
  method: "POST",
169
- body,
150
+ body: JSON.stringify([event]),
170
151
  headers,
171
152
  });
172
- return null;
173
153
  },
174
154
  getReferrer: () => null,
175
155
  getLocation: () => null,
@@ -191,7 +171,7 @@ function isBrowser() {
191
171
  }
192
172
  }
193
173
 
194
- const version = "0.6.4" ;
174
+ const version = "0.6.6" ;
195
175
 
196
176
  function getEventConfig(config) {
197
177
  const { trackingId } = config;
@@ -300,7 +280,7 @@ function buildNullEnvironment() {
300
280
  return {
301
281
  runtime: "null",
302
282
  fetch: () => Promise.resolve(new Response(JSON.stringify(""))),
303
- send: async () => null,
283
+ send: async () => undefined,
304
284
  getReferrer: () => null,
305
285
  getLocation: () => null,
306
286
  getUserAgent: () => null,
package/lib/relay.js CHANGED
@@ -1,39 +1,10 @@
1
- async function validate$1({ config, environment, event, }) {
2
- const { url, token } = config;
3
- const headers = {
4
- "Content-Type": "application/json",
5
- Authorization: `Bearer ${token}`,
6
- };
7
- const response = await environment.fetch(`${url}/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
- ...data,
16
- });
1
+ async function emit({ config, environment, event, listenerManager, }) {
2
+ const { url, token, mode } = config;
3
+ const isEnabled = mode !== "disabled";
4
+ if (isEnabled) {
5
+ listenerManager.call(event);
6
+ environment.send(url, token, event);
17
7
  }
18
- if (!data) {
19
- return {
20
- valid: false,
21
- errors: [{ type: "", message: "disabled", path: "" }],
22
- };
23
- }
24
- const { valid, errors } = data[0];
25
- return { valid, errors: errors ?? [] };
26
- }
27
-
28
- async function emit(params) {
29
- const { listenerManager, event, config } = params;
30
- const isEnabled = config.mode !== "disabled";
31
- isEnabled && listenerManager.call(event);
32
- return config.mode === "validate" ? validate$1(params) : emitEvent(params);
33
- }
34
- async function emitEvent({ event, config, environment, }) {
35
- const { url, token } = config;
36
- return environment.send(url, token, JSON.stringify([event]));
37
8
  }
38
9
 
39
10
  var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
@@ -60,6 +31,15 @@ function createClientIdManager(environment) {
60
31
  };
61
32
  }
62
33
 
34
+ function createExplorerMessenger() {
35
+ const isBrowser = typeof window !== "undefined";
36
+ return {
37
+ sendMessage(message) {
38
+ isBrowser && window.postMessage(message, "*");
39
+ }
40
+ };
41
+ }
42
+
63
43
  const cookieManager = createCookieManager();
64
44
  function createCookieManager() {
65
45
  const prefix = "coveo_";
@@ -122,14 +102,15 @@ function buildBrowserEnvironment() {
122
102
  return {
123
103
  runtime: "browser",
124
104
  fetch: (url, init) => fetchAPI(url, init),
125
- send: async (url, token, body) => {
126
- const response = navigator.sendBeacon(`${url}?access_token=${token}`, new Blob([body], {
105
+ send: async (url, token, event) => {
106
+ const response = navigator.sendBeacon(`${url}?access_token=${token}`, new Blob([JSON.stringify([event])], {
127
107
  type: "application/json",
128
108
  }));
109
+ const messenger = createExplorerMessenger();
110
+ messenger.sendMessage({ kind: "EVENT_PROTOCOL", event, url, token });
129
111
  if (!response) {
130
112
  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.`);
131
113
  }
132
- return null;
133
114
  },
134
115
  getReferrer: () => getReferrer(),
135
116
  getLocation: () => window.location.href,
@@ -157,17 +138,16 @@ function buildNodeEnvironment() {
157
138
  return {
158
139
  runtime: "node",
159
140
  fetch: (url, init) => fetchAPI(url, init),
160
- send: async (url, token, body) => {
141
+ send: async (url, token, event) => {
161
142
  const headers = {
162
143
  "Content-Type": "application/json",
163
144
  Authorization: `Bearer ${token}`,
164
145
  };
165
146
  fetchAPI(url, {
166
147
  method: "POST",
167
- body,
148
+ body: JSON.stringify([event]),
168
149
  headers,
169
150
  });
170
- return null;
171
151
  },
172
152
  getReferrer: () => null,
173
153
  getLocation: () => null,
@@ -189,7 +169,7 @@ function isBrowser() {
189
169
  }
190
170
  }
191
171
 
192
- const version = "0.6.4" ;
172
+ const version = "0.6.6" ;
193
173
 
194
174
  function getEventConfig(config) {
195
175
  const { trackingId } = config;
@@ -298,7 +278,7 @@ function buildNullEnvironment() {
298
278
  return {
299
279
  runtime: "null",
300
280
  fetch: () => Promise.resolve(new Response(JSON.stringify(""))),
301
- send: async () => null,
281
+ send: async () => undefined,
302
282
  getReferrer: () => null,
303
283
  getLocation: () => null,
304
284
  getUserAgent: () => null,
package/lib/relay.mjs CHANGED
@@ -1,39 +1,10 @@
1
- async function validate$1({ config, environment, event, }) {
2
- const { url, token } = config;
3
- const headers = {
4
- "Content-Type": "application/json",
5
- Authorization: `Bearer ${token}`,
6
- };
7
- const response = await environment.fetch(`${url}/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
- ...data,
16
- });
1
+ async function emit({ config, environment, event, listenerManager, }) {
2
+ const { url, token, mode } = config;
3
+ const isEnabled = mode !== "disabled";
4
+ if (isEnabled) {
5
+ listenerManager.call(event);
6
+ environment.send(url, token, event);
17
7
  }
18
- if (!data) {
19
- return {
20
- valid: false,
21
- errors: [{ type: "", message: "disabled", path: "" }],
22
- };
23
- }
24
- const { valid, errors } = data[0];
25
- return { valid, errors: errors ?? [] };
26
- }
27
-
28
- async function emit(params) {
29
- const { listenerManager, event, config } = params;
30
- const isEnabled = config.mode !== "disabled";
31
- isEnabled && listenerManager.call(event);
32
- return config.mode === "validate" ? validate$1(params) : emitEvent(params);
33
- }
34
- async function emitEvent({ event, config, environment, }) {
35
- const { url, token } = config;
36
- return environment.send(url, token, JSON.stringify([event]));
37
8
  }
38
9
 
39
10
  var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
@@ -60,6 +31,15 @@ function createClientIdManager(environment) {
60
31
  };
61
32
  }
62
33
 
34
+ function createExplorerMessenger() {
35
+ const isBrowser = typeof window !== "undefined";
36
+ return {
37
+ sendMessage(message) {
38
+ isBrowser && window.postMessage(message, "*");
39
+ }
40
+ };
41
+ }
42
+
63
43
  const cookieManager = createCookieManager();
64
44
  function createCookieManager() {
65
45
  const prefix = "coveo_";
@@ -122,14 +102,15 @@ function buildBrowserEnvironment() {
122
102
  return {
123
103
  runtime: "browser",
124
104
  fetch: (url, init) => fetchAPI(url, init),
125
- send: async (url, token, body) => {
126
- const response = navigator.sendBeacon(`${url}?access_token=${token}`, new Blob([body], {
105
+ send: async (url, token, event) => {
106
+ const response = navigator.sendBeacon(`${url}?access_token=${token}`, new Blob([JSON.stringify([event])], {
127
107
  type: "application/json",
128
108
  }));
109
+ const messenger = createExplorerMessenger();
110
+ messenger.sendMessage({ kind: "EVENT_PROTOCOL", event, url, token });
129
111
  if (!response) {
130
112
  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.`);
131
113
  }
132
- return null;
133
114
  },
134
115
  getReferrer: () => getReferrer(),
135
116
  getLocation: () => window.location.href,
@@ -157,17 +138,16 @@ function buildNodeEnvironment() {
157
138
  return {
158
139
  runtime: "node",
159
140
  fetch: (url, init) => fetchAPI(url, init),
160
- send: async (url, token, body) => {
141
+ send: async (url, token, event) => {
161
142
  const headers = {
162
143
  "Content-Type": "application/json",
163
144
  Authorization: `Bearer ${token}`,
164
145
  };
165
146
  fetchAPI(url, {
166
147
  method: "POST",
167
- body,
148
+ body: JSON.stringify([event]),
168
149
  headers,
169
150
  });
170
- return null;
171
151
  },
172
152
  getReferrer: () => null,
173
153
  getLocation: () => null,
@@ -189,7 +169,7 @@ function isBrowser() {
189
169
  }
190
170
  }
191
171
 
192
- const version = "0.6.4" ;
172
+ const version = "0.6.6" ;
193
173
 
194
174
  function getEventConfig(config) {
195
175
  const { trackingId } = config;
@@ -298,7 +278,7 @@ function buildNullEnvironment() {
298
278
  return {
299
279
  runtime: "null",
300
280
  fetch: () => Promise.resolve(new Response(JSON.stringify(""))),
301
- send: async () => null,
281
+ send: async () => undefined,
302
282
  getReferrer: () => null,
303
283
  getLocation: () => null,
304
284
  getUserAgent: () => null,
@@ -1,4 +1,7 @@
1
- export type RelayMode = "emit" | "validate" | "disabled";
1
+ export type RelayMode = "emit" | "disabled";
2
+ /**
3
+ * The `RelayConfig` object defines the configuration options for initializing a Relay instance.
4
+ */
2
5
  export interface RelayConfig {
3
6
  /**
4
7
  * Endpoint defined to communicate with the Event API.
@@ -15,7 +18,6 @@ export interface RelayConfig {
15
18
  /**
16
19
  * Defines the library mode. The possible values are:
17
20
  * "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
21
  * "disabled": Prevents the emission of events and does not trigger callbacks.
20
22
  * @default emit
21
23
  */
@@ -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;;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"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config/config.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,UAAU,CAAC;AAE5C;;GAEG;AACH,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;;;;;OAKG;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"}
@@ -8,6 +8,5 @@ export interface EmitParams {
8
8
  event: RelayEvent;
9
9
  listenerManager: ListenerManager;
10
10
  }
11
- export declare function emit(params: EmitParams): Promise<Readonly<import("../relay").ValidationResponse> | null>;
12
- export declare function emitEvent({ event, config, environment, }: EmitParams): Promise<null>;
11
+ export declare function emit({ config, environment, event, listenerManager, }: EmitParams): Promise<void>;
13
12
  //# sourceMappingURL=emit.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../../src/emit/emit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,WAAW,CAAC;IACpB,WAAW,EAAE,WAAW,CAAC;IACzB,KAAK,EAAE,UAAU,CAAC;IAClB,eAAe,EAAE,eAAe,CAAC;CAClC;AAED,wBAAsB,IAAI,CAAC,MAAM,EAAE,UAAU,mEAM5C;AAED,wBAAsB,SAAS,CAAC,EAC9B,KAAK,EACL,MAAM,EACN,WAAW,GACZ,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAI5B"}
1
+ {"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../../src/emit/emit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,WAAW,CAAC;IACpB,WAAW,EAAE,WAAW,CAAC;IACzB,KAAK,EAAE,UAAU,CAAC;IAClB,eAAe,EAAE,eAAe,CAAC;CAClC;AAED,wBAAsB,IAAI,CAAC,EACzB,MAAM,EACN,WAAW,EACX,KAAK,EACL,eAAe,GAChB,EAAE,UAAU,iBAQZ"}
@@ -1 +1 @@
1
- {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../../src/environment/browser/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAU7C,wBAAgB,uBAAuB,IAAI,WAAW,CA0BrD"}
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../../src/environment/browser/browser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAW7C,wBAAgB,uBAAuB,IAAI,WAAW,CA2BrD"}
@@ -1,8 +1,9 @@
1
+ import { RelayEvent } from "../event/relay-event";
1
2
  import { Storage } from "./storage";
2
3
  export interface Environment {
3
4
  runtime: "browser" | "node" | "null";
4
5
  fetch: (url: string, init?: RequestInit) => Promise<Response>;
5
- send: (url: string, token: string, body: string) => Promise<null>;
6
+ send: (url: string, token: string, event: RelayEvent) => Promise<void>;
6
7
  getReferrer: () => string | null;
7
8
  getLocation: () => string | null;
8
9
  getUserAgent: () => string | null;
@@ -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,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"}
1
+ {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../../src/environment/environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGlD,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,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACvE,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"}
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../../src/environment/node/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI7C,wBAAgB,oBAAoB,IAAI,WAAW,CAsBlD"}
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../../src/environment/node/node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI7C,wBAAgB,oBAAoB,IAAI,WAAW,CAqBlD"}
@@ -1,17 +1,26 @@
1
1
  import { ClientIdManager } from "../../client-id/client-id";
2
2
  import { Environment } from "../../environment/environment";
3
3
  import { RelayConfig } from "../../config/config";
4
- interface EventConfig {
4
+ /**
5
+ * The `EventConfig` object provides additonal information for the configuration associated with the event.
6
+ */
7
+ export interface EventConfig {
5
8
  /**
6
9
  * The unique identifier of a web property. See [Tracking ID](https://docs.coveo.com/en/n8tg0567/).
7
10
  */
8
11
  trackingId: string;
9
12
  }
13
+ /**
14
+ * The `Meta` object provides a structured representation of metadata associated with an emitted event.
15
+ */
10
16
  export interface Meta {
11
17
  /**
12
18
  * Event's type that was emitted.
13
19
  */
14
20
  type: string;
21
+ /**
22
+ * Configuration associated with the event.
23
+ */
15
24
  config: EventConfig;
16
25
  /**
17
26
  * Timestamp when the event was emitted.
@@ -39,5 +48,4 @@ export interface Meta {
39
48
  location: string | null;
40
49
  }
41
50
  export declare function createMeta(type: string, config: RelayConfig, environment: Environment, clientIdManager: ClientIdManager): Readonly<Meta>;
42
- export {};
43
51
  //# sourceMappingURL=meta.d.ts.map
@@ -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;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,IAAI;IACnB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC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EAAE,MAAM,EACZ,MAAM,EAAE,WAAW,EACnB,WAAW,EAAE,WAAW,EACxB,eAAe,EAAE,eAAe,GAC/B,QAAQ,CAAC,IAAI,CAAC,CAehB"}
@@ -1,17 +1,20 @@
1
- import { Meta } from "./event/meta/meta";
1
+ import { Meta, EventConfig } from "./event/meta/meta";
2
2
  import { EventCallback } from "./listener/listener";
3
3
  import { RelayConfig } from "./config/config";
4
- import { ValidationError, ValidationResponse } from "./validate/validate";
5
4
  type RelayPayload = Record<string, unknown>;
6
5
  type Off = () => void;
6
+ /**
7
+ * Relay instance.
8
+ * This object provides a comprehensive set of variables and methods for interacting with the Event API.
9
+ */
7
10
  interface Relay {
8
11
  /**
9
12
  * Sends an event to the Event API.
10
13
  * @param {string} type - event's type to be emitted.
11
14
  * @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.
15
+ * @returns {Promise<void>}
13
16
  */
14
- emit: (type: string, payload: RelayPayload) => Promise<ValidationResponse | null>;
17
+ emit: (type: string, payload: RelayPayload) => Promise<void>;
15
18
  /**
16
19
  * Gets the client-side generated meta object.
17
20
  * @param {string} type - event's type that will be included in the meta object.
@@ -58,5 +61,5 @@ interface Relay {
58
61
  * @returns {Relay}
59
62
  */
60
63
  export declare function createRelay(initialConfig: RelayConfig): Relay;
61
- export type { RelayPayload, RelayConfig, ValidationError, ValidationResponse };
64
+ export type { Relay, Meta, EventConfig, EventCallback, RelayPayload, RelayConfig, };
62
65
  //# 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,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AAC,CAAC;AAC5C,KAAK,GAAG,GAAG,MAAM,IAAI,CAAC;AAEtB;;;GAGG;AACH,UAAU,KAAK;IACb;;;;;OAKG;IACH,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7D;;;;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,EACV,KAAK,EACL,IAAI,EACJ,WAAW,EACX,aAAa,EACb,YAAY,EACZ,WAAW,GACZ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coveo/relay",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
4
4
  "description": "A library for sending analytics events using Coveo's Event protocol.",
5
5
  "files": [
6
6
  "lib/**/*"
@@ -43,17 +43,20 @@
43
43
  "@rollup/plugin-terser": "^0.4.3",
44
44
  "@rollup/plugin-typescript": "^11.1.2",
45
45
  "@types/jest": "^29.5.3",
46
+ "@types/node": "^17.0.12",
46
47
  "@types/uuid": "^9.0.4",
47
48
  "jest": "^29.7.0",
48
49
  "jest-environment-jsdom": "^29.7.0",
49
50
  "rimraf": "5.0.5",
50
51
  "rollup": "^3.28.0",
51
52
  "ts-jest": "^29.1.1",
53
+ "typedoc": "^0.25.3",
52
54
  "typescript": "^5.1.6",
53
- "tsconfig": "0.0.0",
54
- "eslint-config-custom": "0.0.0"
55
+ "eslint-config-custom": "0.0.0",
56
+ "tsconfig": "0.0.0"
55
57
  },
56
58
  "dependencies": {
59
+ "@coveo/explorer-messenger": "^0.1.1",
57
60
  "uuid": "^9.0.1"
58
61
  },
59
62
  "engines": {
@@ -64,6 +67,7 @@
64
67
  "clean": "rimraf -rf ./lib",
65
68
  "test": "jest",
66
69
  "test:watch": "jest --watch",
67
- "npm:tag": "node ./scripts/update-npm-tag.mjs"
70
+ "npm:tag": "node ./scripts/update-npm-tag.mjs",
71
+ "typedoc": "typedoc"
68
72
  }
69
73
  }
@@ -1,35 +0,0 @@
1
- import { Environment } from "../environment/environment";
2
- import { RelayEvent } from "../event/relay-event";
3
- import { RelayConfig } from "../relay";
4
- export interface ValidateParams {
5
- config: RelayConfig;
6
- environment: Environment;
7
- event: Readonly<RelayEvent>;
8
- }
9
- export interface ValidationError {
10
- /**
11
- * Type of syntax error of an event's property.
12
- */
13
- type: string;
14
- /**
15
- * Message describing the syntax error of an event's property.
16
- */
17
- message: string;
18
- /**
19
- * Path of the property with a syntax error in the event's payload.
20
- */
21
- path: string;
22
- }
23
- export interface ValidationResponse {
24
- /**
25
- * Indicates whether the payload is valid.
26
- */
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
- */
32
- errors: ValidationError[];
33
- }
34
- export declare function validate({ config, environment, event, }: ValidateParams): Promise<Readonly<ValidationResponse>>;
35
- //# sourceMappingURL=validate.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,35 +0,0 @@
1
- import { Environment } from "../environment/environment";
2
- import { RelayEvent } from "../event/relay-event";
3
- import { RelayConfig } from "../relay";
4
- export interface ValidateParams {
5
- config: RelayConfig;
6
- environment: Environment;
7
- event: Readonly<RelayEvent>;
8
- }
9
- export interface ValidationError {
10
- /**
11
- * Type of syntax error of an event's property.
12
- */
13
- type: string;
14
- /**
15
- * Message describing the syntax error of an event's property.
16
- */
17
- message: string;
18
- /**
19
- * Path of the property with a syntax error in the event's payload.
20
- */
21
- path: string;
22
- }
23
- export interface ValidationResponse {
24
- /**
25
- * Indicates whether the payload is valid.
26
- */
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
- */
32
- errors: ValidationError[];
33
- }
34
- export declare function validate({ config, environment, event, }: ValidateParams): Promise<Readonly<ValidationResponse>>;
35
- //# sourceMappingURL=validate.d.ts.map
@@ -1 +0,0 @@
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"}