@coveo/relay 0.6.7 → 0.6.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- 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.7";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};
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.get(),o=r.storage,c=o.getItem(n),a=c&&("string"==typeof(s=c)&&e.test(s))?c:r.generateUUID();var s;return o.setItem(n,a),a},clear:()=>{t.get().storage.removeItem(n)}}}const n="0.6.9";function r(e){return(e.source||[]).concat([`relay@${n}`])}function o(e,t,n,o){const{getReferrer:c,getLocation:a,getUserAgent:s}=n,i=function(e){const{trackingId:t}=e;return{trackingId:t}}(t),u=o.getClientId();return Object.freeze({type:e,config:i,ts:Date.now(),source:r(t),clientId:u,userAgent:s(),referrer:c(),location:a()})}const c="*";function a(){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===c)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 s({url:e,token:t,trackingId:n,...r}){return Object.freeze({url:e,token:t,trackingId:n,...!!r.mode&&{mode:r.mode},...!!r.source&&{source:r.source}})}const i=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 u(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 l(){return{runtime:"browser",fetch:(e,t)=>u(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=>i.getItem(e)||localStorage.getItem(e),removeItem(e){i.removeItem(e),localStorage.removeItem(e)},setItem(e,t){localStorage.setItem(e,t),i.setItem(e,t,31556952e3)}}}}function g(){return{getItem:()=>null,removeItem(){},setItem(){}}}function f(){return function(){try{return"object"==typeof window}catch(e){return!1}}()?l():{runtime:"node",fetch:(e,t)=>u(e,t),send:async(e,t,n)=>{const r={"Content-Type":"application/json",Authorization:`Bearer ${t}`};u(e,{method:"POST",body:JSON.stringify([n]),headers:r})},getReferrer:()=>null,getLocation:()=>null,getUserAgent:()=>null,generateUUID:()=>crypto.randomUUID(),storage:g()}}function d(e){return"disabled"==e.get().mode?{runtime:"null",fetch:()=>Promise.resolve(new Response(JSON.stringify(""))),send:async()=>{},getReferrer:()=>null,getLocation:()=>null,getUserAgent:()=>null,generateUUID:()=>"",storage:g()}:f()}function m(e){const r=function(e){let t=s(e);return{get:()=>t,update:e=>{t=s({...t,...e})}}}(e),c=a(),i=function(e){return{get:()=>Object.freeze(d(e))}}(r),u=t(i);return{emit:(e,t)=>{const n=r.get(),a=i.get(),s=function(e,t,n,r,c){return{...t,meta:o(e,n,r,c)}}(e,t,n,a,u);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:n,environment:a,event:s,listenerManager:c})},getMeta:e=>o(e,r.get(),i.get(),u),on:(e,t)=>c.add({type:e,callback:t}),off:(e,t)=>c.remove(e,t),updateConfig:e=>r.update(e),version:n,clearStorage:()=>{u.clear()}}}export{m as createRelay};
2
2
  //# sourceMappingURL=relay.min.js.map
@@ -1 +1 @@
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 = \"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 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 {Record<string,any>} payload - payload to include within the event.\n * @returns {Promise<void>}\n */\n emit: (type: string, payload: Record<string, any>) => 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: Record<string, any>) => {\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 { Relay, Meta, EventConfig, EventCallback, RelayConfig };\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 { RelayPayload } from \"../internal-types\";\nimport { RelayConfig } 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,EA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A,GAASjC,EACF,aAATiC,IAGhBS,EAAgBjB,KAAKzD,GACrBzD,EAAYuD,KAAKV,EAAKW,EAAOC,GAEjC,CH0Ea+E,CAAK,CACV/C,SACAzF,cACAyD,QACA0E,mBACA,EAEJQ,QAAU3E,GACRwB,EAAWxB,EAAM6D,EAAcE,MAAOK,IAAkB1C,GAC1DkD,GAAI,CAAC5E,EAAcuC,IACjB4B,EAAgBnB,IAAI,CAAEhD,OAAMuC,aAC9BsC,IAAK,CAAC7E,EAAcuC,IAClB4B,EAAgBzB,OAAO1C,EAAMuC,GAC/BuC,aAAerD,GACboC,EAAcG,OAAOvC,GACvBF,UACAwD,aAAc,KACZrD,EAAgB/E,OAAO,EAG7B","x_google_ignoreList":[0,2,6]}
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/version.ts","../../src/event/meta/meta.ts","../../src/listener/listener.ts","../../src/config/config.ts","../../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/environment/manager/manager.ts","../../src/environment/null/null.ts","../../src/relay.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 { EnvironmentManager } from \"../environment/manager/manager\";\n\nexport interface ClientIdManager {\n getClientId: () => string;\n clear: () => void;\n}\n\nexport function createClientIdManager(\n environmentManager: EnvironmentManager\n): ClientIdManager {\n const key = \"visitorId\";\n\n return {\n getClientId: () => {\n const environment = environmentManager.get();\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 environmentManager.get().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 const version = \"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 * Names and versions of the client side libraries which built and emitted this event.\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(config: RelayConfig): string[] {\n return (config.source || []).concat([`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(config),\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 /**\n * Optionally allows a Relay integration to specify the name(s) of software package(s) relay is\n * being called from. These names will be transmitted with each event, along with Relay's own\n * version. The recommendation is to specify them using a 'softwarename@softwareversion' string.\n */\n source?: string[];\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 ...(!!rest.source && { source: rest.source }),\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","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","import { ConfigManager } from \"../../config/config\";\nimport { Environment, currentEnvironment } from \"../environment\";\nimport { buildNullEnvironment } from \"../null/null\";\n\nexport interface EnvironmentManager {\n get: () => Readonly<Environment>;\n}\n\nfunction buildEnvironment(configManager: ConfigManager) {\n return configManager.get().mode == \"disabled\"\n ? buildNullEnvironment()\n : currentEnvironment();\n}\n\nexport function createEnvironmentManager(\n configManager: ConfigManager\n): Readonly<EnvironmentManager> {\n return {\n get: () => Object.freeze(buildEnvironment(configManager)),\n };\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 { emit } from \"./emit/emit\";\nimport { createClientIdManager } from \"./client-id/client-id\";\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 { createEnvironmentManager } from \"./environment/manager/manager\";\n\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 {Record<string,any>} payload - payload to include within the event.\n * @returns {Promise<void>}\n */\n emit: (type: string, payload: Record<string, any>) => 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 const environmentManager = createEnvironmentManager(configManager);\n const clientIdManager = createClientIdManager(environmentManager);\n\n return {\n emit: (type: string, payload: Record<string, any>) => {\n const config = configManager.get();\n const environment = environmentManager.get();\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(\n type,\n configManager.get(),\n environmentManager.get(),\n clientIdManager\n ),\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 { Relay, Meta, EventConfig, EventCallback, RelayConfig };\n","import { ClientIdManager } from \"../client-id/client-id\";\nimport { Environment } from \"../environment/environment\";\nimport { RelayPayload } from \"../internal-types\";\nimport { RelayConfig } 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","environmentManager","key","getClientId","environment","get","storage","existingClientId","getItem","clientId","uuid","test","generateUUID","setItem","clear","removeItem","version","getSource","config","source","concat","createMeta","type","clientIdManager","getReferrer","getLocation","getUserAgent","eventConfig","trackingId","getEventConfig","Object","freeze","ts","Date","now","userAgent","referrer","location","ANY_EVENT_TYPE","createListenerManager","listeners","getListenerIndex","callback","findIndex","listener","remove","index","splice","removeOne","length","i","removeMultiple","add","push","call","event","forEach","isMatchesType","meta","e","console","error","pick","url","token","rest","mode","cookieManager","prefix","cookiePrefix","cookieArray","document","cookie","split","prettifyCookie","replace","lastIndexOf","substring","data","expire","domain","host","parts","slice","join","getDomain","window","hostname","expireSection","getTime","toUTCString","domainSection","this","createCookieManager","async","fetchAPI","init","fetch","catch","err","Error","message","cause","buildBrowserEnvironment","runtime","send","response","navigator","sendBeacon","Blob","JSON","stringify","messenger","isBrowser","sendMessage","postMessage","createExplorerMessenger","kind","href","crypto","randomUUID","localStorage","createNullStorage","currentEnvironment","headers","Authorization","method","body","buildEnvironment","configManager","Promise","resolve","Response","createRelay","initialConfig","_config","update","updatedConfig","createConfigManager","listenerManager","createEnvironmentManager","emit","payload","createRelayEvent","getMeta","on","off","updateConfig","clearStorage"],"mappings":"AAAA,IAAAA,EAAe,sHCQT,SAAUC,EACdC,GAEA,MAAMC,EAAM,YAEZ,MAAO,CACLC,YAAa,KACX,MAAMC,EAAcH,EAAmBI,MACjCC,EAAUF,EAAYE,QAEtBC,EAAmBD,EAAQE,QAAQN,GACnCO,EACJF,ICjBiB,iBADPG,EDkBmBH,ICjBAR,EAAMY,KAAKD,IDkBpCH,EACAH,EAAYQ,eCpBxB,IAAkBF,EDsBZ,OADAJ,EAAQO,QAAQX,EAAKO,GACdA,CAAQ,EAEjBK,MAAO,KACLb,EAAmBI,MAAMC,QAAQS,WAAWb,EAAI,EAGtD,CE9BO,MAAMc,EAAU,QCiEvB,SAASC,EAAUC,GACjB,OAAQA,EAAOC,QAAU,IAAIC,OAAO,CAAC,SAASJ,KAChD,CAEM,SAAUK,EACdC,EACAJ,EACAd,EACAmB,GAEA,MAAMC,YAAEA,EAAWC,YAAEA,EAAWC,aAAEA,GAAiBtB,EAC7CuB,EAhBR,SAAwBT,GACtB,MAAMU,WAAEA,GAAeV,EACvB,MAAO,CAAEU,aACX,CAasBC,CAAeX,GAC7BT,EAAWc,EAAgBpB,cAEjC,OAAO2B,OAAOC,OAAO,CACnBT,OACAJ,OAAQS,EACRK,GAAIC,KAAKC,MACTf,OAAQF,EAAUC,GAClBT,WACA0B,UAAWT,IACXU,SAAUZ,IACVa,SAAUZ,KAEd,CCvFA,MAAMa,EAAiB,aAqBPC,IACd,MAAMC,EAAwB,GAE9B,SAASC,GAAiBnB,KAAEA,EAAIoB,SAAEA,IAChC,OAAOF,EAAUG,WACdC,G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7 +1,7 @@
1
- import { Environment } from "../environment/environment";
1
+ import { EnvironmentManager } from "../environment/manager/manager";
2
2
  export interface ClientIdManager {
3
3
  getClientId: () => string;
4
4
  clear: () => void;
5
5
  }
6
- export declare function createClientIdManager(environment: Environment): ClientIdManager;
6
+ export declare function createClientIdManager(environmentManager: EnvironmentManager): ClientIdManager;
7
7
  //# sourceMappingURL=client-id.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client-id.d.ts","sourceRoot":"","sources":["../../../src/client-id/client-id.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEzD,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,MAAM,CAAC;IAC1B,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,WAAW,GACvB,eAAe,CAkBjB"}
1
+ {"version":3,"file":"client-id.d.ts","sourceRoot":"","sources":["../../../src/client-id/client-id.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpE,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,MAAM,CAAC;IAC1B,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,wBAAgB,qBAAqB,CACnC,kBAAkB,EAAE,kBAAkB,GACrC,eAAe,CAoBjB"}
@@ -22,6 +22,12 @@ export interface RelayConfig {
22
22
  * @default emit
23
23
  */
24
24
  mode?: RelayMode;
25
+ /**
26
+ * Optionally allows a Relay integration to specify the name(s) of software package(s) relay is
27
+ * being called from. These names will be transmitted with each event, along with Relay's own
28
+ * version. The recommendation is to specify them using a 'softwarename@softwareversion' string.
29
+ */
30
+ source?: string[];
25
31
  }
26
32
  export interface ConfigManager {
27
33
  get: () => Readonly<RelayConfig>;
@@ -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,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"}
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;IAEjB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;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;AAiBD,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,WAAW,GACzB,QAAQ,CAAC,aAAa,CAAC,CASzB"}
@@ -0,0 +1,7 @@
1
+ import { ConfigManager } from "../../config/config";
2
+ import { Environment } from "../environment";
3
+ export interface EnvironmentManager {
4
+ get: () => Readonly<Environment>;
5
+ }
6
+ export declare function createEnvironmentManager(configManager: ConfigManager): Readonly<EnvironmentManager>;
7
+ //# sourceMappingURL=manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../../src/environment/manager/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAsB,MAAM,gBAAgB,CAAC;AAGjE,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,QAAQ,CAAC,WAAW,CAAC,CAAC;CAClC;AAQD,wBAAgB,wBAAwB,CACtC,aAAa,EAAE,aAAa,GAC3B,QAAQ,CAAC,kBAAkB,CAAC,CAI9B"}
@@ -27,9 +27,9 @@ export interface Meta {
27
27
  */
28
28
  ts: number;
29
29
  /**
30
- * Library and version in which the event is built and emitted.
30
+ * Names and versions of the client side libraries which built and emitted this event.
31
31
  */
32
- source: string;
32
+ source: string[];
33
33
  /**
34
34
  * Persistent unique identifier of a device.
35
35
  */
@@ -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;;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;IAC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":["../../src/relay.ts"],"names":[],"mappings":"AAIA,OAAO,EAAc,IAAI,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAyB,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAuB,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGnE,KAAK,GAAG,GAAG,MAAM,IAAI,CAAC;AAEtB;;;GAGG;AACH,UAAU,KAAK;IACb;;;;;OAKG;IACH,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpE;;;;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,CA4C7D;AAED,YAAY,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,CAAC"}
package/lib/relay.cjs CHANGED
@@ -15,10 +15,11 @@ function validate(uuid) {
15
15
  return typeof uuid === 'string' && REGEX.test(uuid);
16
16
  }
17
17
 
18
- function createClientIdManager(environment) {
18
+ function createClientIdManager(environmentManager) {
19
19
  const key = "visitorId";
20
20
  return {
21
21
  getClientId: () => {
22
+ const environment = environmentManager.get();
22
23
  const storage = environment.storage;
23
24
  const existingClientId = storage.getItem(key);
24
25
  const clientId = existingClientId && validate(existingClientId)
@@ -28,7 +29,113 @@ function createClientIdManager(environment) {
28
29
  return clientId;
29
30
  },
30
31
  clear: () => {
31
- environment.storage.removeItem(key);
32
+ environmentManager.get().storage.removeItem(key);
33
+ },
34
+ };
35
+ }
36
+
37
+ const version = "0.6.9";
38
+
39
+ function getEventConfig(config) {
40
+ const { trackingId } = config;
41
+ return { trackingId };
42
+ }
43
+ function getSource(config) {
44
+ return (config.source || []).concat([`relay@${version}`]);
45
+ }
46
+ function createMeta(type, config, environment, clientIdManager) {
47
+ const { getReferrer, getLocation, getUserAgent } = environment;
48
+ const eventConfig = getEventConfig(config);
49
+ const clientId = clientIdManager.getClientId();
50
+ return Object.freeze({
51
+ type,
52
+ config: eventConfig,
53
+ ts: Date.now(),
54
+ source: getSource(config),
55
+ clientId,
56
+ userAgent: getUserAgent(),
57
+ referrer: getReferrer(),
58
+ location: getLocation(),
59
+ });
60
+ }
61
+
62
+ function createRelayEvent(type, payload, config, environment, clientIdManager) {
63
+ return {
64
+ ...payload,
65
+ meta: createMeta(type, config, environment, clientIdManager),
66
+ };
67
+ }
68
+
69
+ const ANY_EVENT_TYPE = "*";
70
+ function createListenerManager() {
71
+ const listeners = [];
72
+ function getListenerIndex({ type, callback }) {
73
+ return listeners.findIndex((listener) => listener.type === type && listener.callback === callback);
74
+ }
75
+ function isMatchesType(listener, type) {
76
+ return listener.type === "*" || type === listener.type;
77
+ }
78
+ function add(listener) {
79
+ if (getListenerIndex(listener) < 0) {
80
+ listeners.push(listener);
81
+ }
82
+ return () => remove(listener.type, listener.callback);
83
+ }
84
+ function call(event) {
85
+ listeners.forEach((listener) => {
86
+ if (isMatchesType(listener, event.meta.type)) {
87
+ try {
88
+ listener.callback(event);
89
+ }
90
+ catch (e) {
91
+ console.error(e);
92
+ }
93
+ }
94
+ });
95
+ }
96
+ function removeMultiple(type) {
97
+ if (type === ANY_EVENT_TYPE) {
98
+ listeners.length = 0;
99
+ }
100
+ else {
101
+ for (let i = listeners.length - 1; i >= 0; i--) {
102
+ if (listeners[i].type === type) {
103
+ listeners.splice(i, 1);
104
+ }
105
+ }
106
+ }
107
+ }
108
+ function removeOne(listener) {
109
+ const index = getListenerIndex(listener);
110
+ if (index >= 0) {
111
+ listeners.splice(index, 1);
112
+ }
113
+ }
114
+ function remove(type, callback) {
115
+ !!callback ? removeOne({ type, callback }) : removeMultiple(type);
116
+ }
117
+ return {
118
+ add,
119
+ call,
120
+ remove,
121
+ };
122
+ }
123
+
124
+ function pick({ url, token, trackingId, ...rest }) {
125
+ return Object.freeze({
126
+ url,
127
+ token,
128
+ trackingId,
129
+ ...(!!rest.mode && { mode: rest.mode }),
130
+ ...(!!rest.source && { source: rest.source }),
131
+ });
132
+ }
133
+ function createConfigManager(initialConfig) {
134
+ let _config = pick(initialConfig);
135
+ return {
136
+ get: () => _config,
137
+ update: (updatedConfig) => {
138
+ _config = pick({ ..._config, ...updatedConfig });
32
139
  },
33
140
  };
34
141
  }
@@ -171,111 +278,6 @@ function isBrowser() {
171
278
  }
172
279
  }
173
280
 
174
- const version = "0.6.7";
175
-
176
- function getEventConfig(config) {
177
- const { trackingId } = config;
178
- return { trackingId };
179
- }
180
- function getSource() {
181
- return `relay@${version}`;
182
- }
183
- function createMeta(type, config, environment, clientIdManager) {
184
- const { getReferrer, getLocation, getUserAgent } = environment;
185
- const eventConfig = getEventConfig(config);
186
- const clientId = clientIdManager.getClientId();
187
- return Object.freeze({
188
- type,
189
- config: eventConfig,
190
- ts: Date.now(),
191
- source: getSource(),
192
- clientId,
193
- userAgent: getUserAgent(),
194
- referrer: getReferrer(),
195
- location: getLocation(),
196
- });
197
- }
198
-
199
- function createRelayEvent(type, payload, config, environment, clientIdManager) {
200
- return {
201
- ...payload,
202
- meta: createMeta(type, config, environment, clientIdManager),
203
- };
204
- }
205
-
206
- const ANY_EVENT_TYPE = "*";
207
- function createListenerManager() {
208
- const listeners = [];
209
- function getListenerIndex({ type, callback }) {
210
- return listeners.findIndex((listener) => listener.type === type && listener.callback === callback);
211
- }
212
- function isMatchesType(listener, type) {
213
- return listener.type === "*" || type === listener.type;
214
- }
215
- function add(listener) {
216
- if (getListenerIndex(listener) < 0) {
217
- listeners.push(listener);
218
- }
219
- return () => remove(listener.type, listener.callback);
220
- }
221
- function call(event) {
222
- listeners.forEach((listener) => {
223
- if (isMatchesType(listener, event.meta.type)) {
224
- try {
225
- listener.callback(event);
226
- }
227
- catch (e) {
228
- console.error(e);
229
- }
230
- }
231
- });
232
- }
233
- function removeMultiple(type) {
234
- if (type === ANY_EVENT_TYPE) {
235
- listeners.length = 0;
236
- }
237
- else {
238
- for (let i = listeners.length - 1; i >= 0; i--) {
239
- if (listeners[i].type === type) {
240
- listeners.splice(i, 1);
241
- }
242
- }
243
- }
244
- }
245
- function removeOne(listener) {
246
- const index = getListenerIndex(listener);
247
- if (index >= 0) {
248
- listeners.splice(index, 1);
249
- }
250
- }
251
- function remove(type, callback) {
252
- !!callback ? removeOne({ type, callback }) : removeMultiple(type);
253
- }
254
- return {
255
- add,
256
- call,
257
- remove,
258
- };
259
- }
260
-
261
- function pick({ url, token, trackingId, ...rest }) {
262
- return Object.freeze({
263
- url,
264
- token,
265
- trackingId,
266
- ...(!!rest.mode && { mode: rest.mode }),
267
- });
268
- }
269
- function createConfigManager(initialConfig) {
270
- let _config = pick(initialConfig);
271
- return {
272
- get: () => _config,
273
- update: (updatedConfig) => {
274
- _config = pick({ ..._config, ...updatedConfig });
275
- },
276
- };
277
- }
278
-
279
281
  function buildNullEnvironment() {
280
282
  return {
281
283
  runtime: "null",
@@ -289,6 +291,17 @@ function buildNullEnvironment() {
289
291
  };
290
292
  }
291
293
 
294
+ function buildEnvironment(configManager) {
295
+ return configManager.get().mode == "disabled"
296
+ ? buildNullEnvironment()
297
+ : currentEnvironment();
298
+ }
299
+ function createEnvironmentManager(configManager) {
300
+ return {
301
+ get: () => Object.freeze(buildEnvironment(configManager)),
302
+ };
303
+ }
304
+
292
305
  /**
293
306
  * Initializes the Relay library object.
294
307
  * @param {RelayConfig} initialConfig
@@ -297,14 +310,12 @@ function buildNullEnvironment() {
297
310
  function createRelay(initialConfig) {
298
311
  const configManager = createConfigManager(initialConfig);
299
312
  const listenerManager = createListenerManager();
300
- const getEnvironment = () => configManager.get().mode == "disabled"
301
- ? buildNullEnvironment()
302
- : currentEnvironment();
303
- const clientIdManager = createClientIdManager(getEnvironment());
313
+ const environmentManager = createEnvironmentManager(configManager);
314
+ const clientIdManager = createClientIdManager(environmentManager);
304
315
  return {
305
316
  emit: (type, payload) => {
306
317
  const config = configManager.get();
307
- const environment = getEnvironment();
318
+ const environment = environmentManager.get();
308
319
  const event = createRelayEvent(type, payload, config, environment, clientIdManager);
309
320
  return emit({
310
321
  config,
@@ -313,7 +324,7 @@ function createRelay(initialConfig) {
313
324
  listenerManager,
314
325
  });
315
326
  },
316
- getMeta: (type) => createMeta(type, configManager.get(), getEnvironment(), clientIdManager),
327
+ getMeta: (type) => createMeta(type, configManager.get(), environmentManager.get(), clientIdManager),
317
328
  on: (type, callback) => listenerManager.add({ type, callback }),
318
329
  off: (type, callback) => listenerManager.remove(type, callback),
319
330
  updateConfig: (config) => configManager.update(config),
package/lib/relay.js CHANGED
@@ -13,10 +13,11 @@ function validate(uuid) {
13
13
  return typeof uuid === 'string' && REGEX.test(uuid);
14
14
  }
15
15
 
16
- function createClientIdManager(environment) {
16
+ function createClientIdManager(environmentManager) {
17
17
  const key = "visitorId";
18
18
  return {
19
19
  getClientId: () => {
20
+ const environment = environmentManager.get();
20
21
  const storage = environment.storage;
21
22
  const existingClientId = storage.getItem(key);
22
23
  const clientId = existingClientId && validate(existingClientId)
@@ -26,7 +27,113 @@ function createClientIdManager(environment) {
26
27
  return clientId;
27
28
  },
28
29
  clear: () => {
29
- environment.storage.removeItem(key);
30
+ environmentManager.get().storage.removeItem(key);
31
+ },
32
+ };
33
+ }
34
+
35
+ const version = "0.6.9";
36
+
37
+ function getEventConfig(config) {
38
+ const { trackingId } = config;
39
+ return { trackingId };
40
+ }
41
+ function getSource(config) {
42
+ return (config.source || []).concat([`relay@${version}`]);
43
+ }
44
+ function createMeta(type, config, environment, clientIdManager) {
45
+ const { getReferrer, getLocation, getUserAgent } = environment;
46
+ const eventConfig = getEventConfig(config);
47
+ const clientId = clientIdManager.getClientId();
48
+ return Object.freeze({
49
+ type,
50
+ config: eventConfig,
51
+ ts: Date.now(),
52
+ source: getSource(config),
53
+ clientId,
54
+ userAgent: getUserAgent(),
55
+ referrer: getReferrer(),
56
+ location: getLocation(),
57
+ });
58
+ }
59
+
60
+ function createRelayEvent(type, payload, config, environment, clientIdManager) {
61
+ return {
62
+ ...payload,
63
+ meta: createMeta(type, config, environment, clientIdManager),
64
+ };
65
+ }
66
+
67
+ const ANY_EVENT_TYPE = "*";
68
+ function createListenerManager() {
69
+ const listeners = [];
70
+ function getListenerIndex({ type, callback }) {
71
+ return listeners.findIndex((listener) => listener.type === type && listener.callback === callback);
72
+ }
73
+ function isMatchesType(listener, type) {
74
+ return listener.type === "*" || type === listener.type;
75
+ }
76
+ function add(listener) {
77
+ if (getListenerIndex(listener) < 0) {
78
+ listeners.push(listener);
79
+ }
80
+ return () => remove(listener.type, listener.callback);
81
+ }
82
+ function call(event) {
83
+ listeners.forEach((listener) => {
84
+ if (isMatchesType(listener, event.meta.type)) {
85
+ try {
86
+ listener.callback(event);
87
+ }
88
+ catch (e) {
89
+ console.error(e);
90
+ }
91
+ }
92
+ });
93
+ }
94
+ function removeMultiple(type) {
95
+ if (type === ANY_EVENT_TYPE) {
96
+ listeners.length = 0;
97
+ }
98
+ else {
99
+ for (let i = listeners.length - 1; i >= 0; i--) {
100
+ if (listeners[i].type === type) {
101
+ listeners.splice(i, 1);
102
+ }
103
+ }
104
+ }
105
+ }
106
+ function removeOne(listener) {
107
+ const index = getListenerIndex(listener);
108
+ if (index >= 0) {
109
+ listeners.splice(index, 1);
110
+ }
111
+ }
112
+ function remove(type, callback) {
113
+ !!callback ? removeOne({ type, callback }) : removeMultiple(type);
114
+ }
115
+ return {
116
+ add,
117
+ call,
118
+ remove,
119
+ };
120
+ }
121
+
122
+ function pick({ url, token, trackingId, ...rest }) {
123
+ return Object.freeze({
124
+ url,
125
+ token,
126
+ trackingId,
127
+ ...(!!rest.mode && { mode: rest.mode }),
128
+ ...(!!rest.source && { source: rest.source }),
129
+ });
130
+ }
131
+ function createConfigManager(initialConfig) {
132
+ let _config = pick(initialConfig);
133
+ return {
134
+ get: () => _config,
135
+ update: (updatedConfig) => {
136
+ _config = pick({ ..._config, ...updatedConfig });
30
137
  },
31
138
  };
32
139
  }
@@ -169,111 +276,6 @@ function isBrowser() {
169
276
  }
170
277
  }
171
278
 
172
- const version = "0.6.7";
173
-
174
- function getEventConfig(config) {
175
- const { trackingId } = config;
176
- return { trackingId };
177
- }
178
- function getSource() {
179
- return `relay@${version}`;
180
- }
181
- function createMeta(type, config, environment, clientIdManager) {
182
- const { getReferrer, getLocation, getUserAgent } = environment;
183
- const eventConfig = getEventConfig(config);
184
- const clientId = clientIdManager.getClientId();
185
- return Object.freeze({
186
- type,
187
- config: eventConfig,
188
- ts: Date.now(),
189
- source: getSource(),
190
- clientId,
191
- userAgent: getUserAgent(),
192
- referrer: getReferrer(),
193
- location: getLocation(),
194
- });
195
- }
196
-
197
- function createRelayEvent(type, payload, config, environment, clientIdManager) {
198
- return {
199
- ...payload,
200
- meta: createMeta(type, config, environment, clientIdManager),
201
- };
202
- }
203
-
204
- const ANY_EVENT_TYPE = "*";
205
- function createListenerManager() {
206
- const listeners = [];
207
- function getListenerIndex({ type, callback }) {
208
- return listeners.findIndex((listener) => listener.type === type && listener.callback === callback);
209
- }
210
- function isMatchesType(listener, type) {
211
- return listener.type === "*" || type === listener.type;
212
- }
213
- function add(listener) {
214
- if (getListenerIndex(listener) < 0) {
215
- listeners.push(listener);
216
- }
217
- return () => remove(listener.type, listener.callback);
218
- }
219
- function call(event) {
220
- listeners.forEach((listener) => {
221
- if (isMatchesType(listener, event.meta.type)) {
222
- try {
223
- listener.callback(event);
224
- }
225
- catch (e) {
226
- console.error(e);
227
- }
228
- }
229
- });
230
- }
231
- function removeMultiple(type) {
232
- if (type === ANY_EVENT_TYPE) {
233
- listeners.length = 0;
234
- }
235
- else {
236
- for (let i = listeners.length - 1; i >= 0; i--) {
237
- if (listeners[i].type === type) {
238
- listeners.splice(i, 1);
239
- }
240
- }
241
- }
242
- }
243
- function removeOne(listener) {
244
- const index = getListenerIndex(listener);
245
- if (index >= 0) {
246
- listeners.splice(index, 1);
247
- }
248
- }
249
- function remove(type, callback) {
250
- !!callback ? removeOne({ type, callback }) : removeMultiple(type);
251
- }
252
- return {
253
- add,
254
- call,
255
- remove,
256
- };
257
- }
258
-
259
- function pick({ url, token, trackingId, ...rest }) {
260
- return Object.freeze({
261
- url,
262
- token,
263
- trackingId,
264
- ...(!!rest.mode && { mode: rest.mode }),
265
- });
266
- }
267
- function createConfigManager(initialConfig) {
268
- let _config = pick(initialConfig);
269
- return {
270
- get: () => _config,
271
- update: (updatedConfig) => {
272
- _config = pick({ ..._config, ...updatedConfig });
273
- },
274
- };
275
- }
276
-
277
279
  function buildNullEnvironment() {
278
280
  return {
279
281
  runtime: "null",
@@ -287,6 +289,17 @@ function buildNullEnvironment() {
287
289
  };
288
290
  }
289
291
 
292
+ function buildEnvironment(configManager) {
293
+ return configManager.get().mode == "disabled"
294
+ ? buildNullEnvironment()
295
+ : currentEnvironment();
296
+ }
297
+ function createEnvironmentManager(configManager) {
298
+ return {
299
+ get: () => Object.freeze(buildEnvironment(configManager)),
300
+ };
301
+ }
302
+
290
303
  /**
291
304
  * Initializes the Relay library object.
292
305
  * @param {RelayConfig} initialConfig
@@ -295,14 +308,12 @@ function buildNullEnvironment() {
295
308
  function createRelay(initialConfig) {
296
309
  const configManager = createConfigManager(initialConfig);
297
310
  const listenerManager = createListenerManager();
298
- const getEnvironment = () => configManager.get().mode == "disabled"
299
- ? buildNullEnvironment()
300
- : currentEnvironment();
301
- const clientIdManager = createClientIdManager(getEnvironment());
311
+ const environmentManager = createEnvironmentManager(configManager);
312
+ const clientIdManager = createClientIdManager(environmentManager);
302
313
  return {
303
314
  emit: (type, payload) => {
304
315
  const config = configManager.get();
305
- const environment = getEnvironment();
316
+ const environment = environmentManager.get();
306
317
  const event = createRelayEvent(type, payload, config, environment, clientIdManager);
307
318
  return emit({
308
319
  config,
@@ -311,7 +322,7 @@ function createRelay(initialConfig) {
311
322
  listenerManager,
312
323
  });
313
324
  },
314
- getMeta: (type) => createMeta(type, configManager.get(), getEnvironment(), clientIdManager),
325
+ getMeta: (type) => createMeta(type, configManager.get(), environmentManager.get(), clientIdManager),
315
326
  on: (type, callback) => listenerManager.add({ type, callback }),
316
327
  off: (type, callback) => listenerManager.remove(type, callback),
317
328
  updateConfig: (config) => configManager.update(config),
package/lib/relay.mjs CHANGED
@@ -13,10 +13,11 @@ function validate(uuid) {
13
13
  return typeof uuid === 'string' && REGEX.test(uuid);
14
14
  }
15
15
 
16
- function createClientIdManager(environment) {
16
+ function createClientIdManager(environmentManager) {
17
17
  const key = "visitorId";
18
18
  return {
19
19
  getClientId: () => {
20
+ const environment = environmentManager.get();
20
21
  const storage = environment.storage;
21
22
  const existingClientId = storage.getItem(key);
22
23
  const clientId = existingClientId && validate(existingClientId)
@@ -26,7 +27,113 @@ function createClientIdManager(environment) {
26
27
  return clientId;
27
28
  },
28
29
  clear: () => {
29
- environment.storage.removeItem(key);
30
+ environmentManager.get().storage.removeItem(key);
31
+ },
32
+ };
33
+ }
34
+
35
+ const version = "0.6.9";
36
+
37
+ function getEventConfig(config) {
38
+ const { trackingId } = config;
39
+ return { trackingId };
40
+ }
41
+ function getSource(config) {
42
+ return (config.source || []).concat([`relay@${version}`]);
43
+ }
44
+ function createMeta(type, config, environment, clientIdManager) {
45
+ const { getReferrer, getLocation, getUserAgent } = environment;
46
+ const eventConfig = getEventConfig(config);
47
+ const clientId = clientIdManager.getClientId();
48
+ return Object.freeze({
49
+ type,
50
+ config: eventConfig,
51
+ ts: Date.now(),
52
+ source: getSource(config),
53
+ clientId,
54
+ userAgent: getUserAgent(),
55
+ referrer: getReferrer(),
56
+ location: getLocation(),
57
+ });
58
+ }
59
+
60
+ function createRelayEvent(type, payload, config, environment, clientIdManager) {
61
+ return {
62
+ ...payload,
63
+ meta: createMeta(type, config, environment, clientIdManager),
64
+ };
65
+ }
66
+
67
+ const ANY_EVENT_TYPE = "*";
68
+ function createListenerManager() {
69
+ const listeners = [];
70
+ function getListenerIndex({ type, callback }) {
71
+ return listeners.findIndex((listener) => listener.type === type && listener.callback === callback);
72
+ }
73
+ function isMatchesType(listener, type) {
74
+ return listener.type === "*" || type === listener.type;
75
+ }
76
+ function add(listener) {
77
+ if (getListenerIndex(listener) < 0) {
78
+ listeners.push(listener);
79
+ }
80
+ return () => remove(listener.type, listener.callback);
81
+ }
82
+ function call(event) {
83
+ listeners.forEach((listener) => {
84
+ if (isMatchesType(listener, event.meta.type)) {
85
+ try {
86
+ listener.callback(event);
87
+ }
88
+ catch (e) {
89
+ console.error(e);
90
+ }
91
+ }
92
+ });
93
+ }
94
+ function removeMultiple(type) {
95
+ if (type === ANY_EVENT_TYPE) {
96
+ listeners.length = 0;
97
+ }
98
+ else {
99
+ for (let i = listeners.length - 1; i >= 0; i--) {
100
+ if (listeners[i].type === type) {
101
+ listeners.splice(i, 1);
102
+ }
103
+ }
104
+ }
105
+ }
106
+ function removeOne(listener) {
107
+ const index = getListenerIndex(listener);
108
+ if (index >= 0) {
109
+ listeners.splice(index, 1);
110
+ }
111
+ }
112
+ function remove(type, callback) {
113
+ !!callback ? removeOne({ type, callback }) : removeMultiple(type);
114
+ }
115
+ return {
116
+ add,
117
+ call,
118
+ remove,
119
+ };
120
+ }
121
+
122
+ function pick({ url, token, trackingId, ...rest }) {
123
+ return Object.freeze({
124
+ url,
125
+ token,
126
+ trackingId,
127
+ ...(!!rest.mode && { mode: rest.mode }),
128
+ ...(!!rest.source && { source: rest.source }),
129
+ });
130
+ }
131
+ function createConfigManager(initialConfig) {
132
+ let _config = pick(initialConfig);
133
+ return {
134
+ get: () => _config,
135
+ update: (updatedConfig) => {
136
+ _config = pick({ ..._config, ...updatedConfig });
30
137
  },
31
138
  };
32
139
  }
@@ -169,111 +276,6 @@ function isBrowser() {
169
276
  }
170
277
  }
171
278
 
172
- const version = "0.6.7";
173
-
174
- function getEventConfig(config) {
175
- const { trackingId } = config;
176
- return { trackingId };
177
- }
178
- function getSource() {
179
- return `relay@${version}`;
180
- }
181
- function createMeta(type, config, environment, clientIdManager) {
182
- const { getReferrer, getLocation, getUserAgent } = environment;
183
- const eventConfig = getEventConfig(config);
184
- const clientId = clientIdManager.getClientId();
185
- return Object.freeze({
186
- type,
187
- config: eventConfig,
188
- ts: Date.now(),
189
- source: getSource(),
190
- clientId,
191
- userAgent: getUserAgent(),
192
- referrer: getReferrer(),
193
- location: getLocation(),
194
- });
195
- }
196
-
197
- function createRelayEvent(type, payload, config, environment, clientIdManager) {
198
- return {
199
- ...payload,
200
- meta: createMeta(type, config, environment, clientIdManager),
201
- };
202
- }
203
-
204
- const ANY_EVENT_TYPE = "*";
205
- function createListenerManager() {
206
- const listeners = [];
207
- function getListenerIndex({ type, callback }) {
208
- return listeners.findIndex((listener) => listener.type === type && listener.callback === callback);
209
- }
210
- function isMatchesType(listener, type) {
211
- return listener.type === "*" || type === listener.type;
212
- }
213
- function add(listener) {
214
- if (getListenerIndex(listener) < 0) {
215
- listeners.push(listener);
216
- }
217
- return () => remove(listener.type, listener.callback);
218
- }
219
- function call(event) {
220
- listeners.forEach((listener) => {
221
- if (isMatchesType(listener, event.meta.type)) {
222
- try {
223
- listener.callback(event);
224
- }
225
- catch (e) {
226
- console.error(e);
227
- }
228
- }
229
- });
230
- }
231
- function removeMultiple(type) {
232
- if (type === ANY_EVENT_TYPE) {
233
- listeners.length = 0;
234
- }
235
- else {
236
- for (let i = listeners.length - 1; i >= 0; i--) {
237
- if (listeners[i].type === type) {
238
- listeners.splice(i, 1);
239
- }
240
- }
241
- }
242
- }
243
- function removeOne(listener) {
244
- const index = getListenerIndex(listener);
245
- if (index >= 0) {
246
- listeners.splice(index, 1);
247
- }
248
- }
249
- function remove(type, callback) {
250
- !!callback ? removeOne({ type, callback }) : removeMultiple(type);
251
- }
252
- return {
253
- add,
254
- call,
255
- remove,
256
- };
257
- }
258
-
259
- function pick({ url, token, trackingId, ...rest }) {
260
- return Object.freeze({
261
- url,
262
- token,
263
- trackingId,
264
- ...(!!rest.mode && { mode: rest.mode }),
265
- });
266
- }
267
- function createConfigManager(initialConfig) {
268
- let _config = pick(initialConfig);
269
- return {
270
- get: () => _config,
271
- update: (updatedConfig) => {
272
- _config = pick({ ..._config, ...updatedConfig });
273
- },
274
- };
275
- }
276
-
277
279
  function buildNullEnvironment() {
278
280
  return {
279
281
  runtime: "null",
@@ -287,6 +289,17 @@ function buildNullEnvironment() {
287
289
  };
288
290
  }
289
291
 
292
+ function buildEnvironment(configManager) {
293
+ return configManager.get().mode == "disabled"
294
+ ? buildNullEnvironment()
295
+ : currentEnvironment();
296
+ }
297
+ function createEnvironmentManager(configManager) {
298
+ return {
299
+ get: () => Object.freeze(buildEnvironment(configManager)),
300
+ };
301
+ }
302
+
290
303
  /**
291
304
  * Initializes the Relay library object.
292
305
  * @param {RelayConfig} initialConfig
@@ -295,14 +308,12 @@ function buildNullEnvironment() {
295
308
  function createRelay(initialConfig) {
296
309
  const configManager = createConfigManager(initialConfig);
297
310
  const listenerManager = createListenerManager();
298
- const getEnvironment = () => configManager.get().mode == "disabled"
299
- ? buildNullEnvironment()
300
- : currentEnvironment();
301
- const clientIdManager = createClientIdManager(getEnvironment());
311
+ const environmentManager = createEnvironmentManager(configManager);
312
+ const clientIdManager = createClientIdManager(environmentManager);
302
313
  return {
303
314
  emit: (type, payload) => {
304
315
  const config = configManager.get();
305
- const environment = getEnvironment();
316
+ const environment = environmentManager.get();
306
317
  const event = createRelayEvent(type, payload, config, environment, clientIdManager);
307
318
  return emit({
308
319
  config,
@@ -311,7 +322,7 @@ function createRelay(initialConfig) {
311
322
  listenerManager,
312
323
  });
313
324
  },
314
- getMeta: (type) => createMeta(type, configManager.get(), getEnvironment(), clientIdManager),
325
+ getMeta: (type) => createMeta(type, configManager.get(), environmentManager.get(), clientIdManager),
315
326
  on: (type, callback) => listenerManager.add({ type, callback }),
316
327
  off: (type, callback) => listenerManager.remove(type, callback),
317
328
  updateConfig: (config) => configManager.update(config),
@@ -1,7 +1,7 @@
1
- import { Environment } from "../environment/environment";
1
+ import { EnvironmentManager } from "../environment/manager/manager";
2
2
  export interface ClientIdManager {
3
3
  getClientId: () => string;
4
4
  clear: () => void;
5
5
  }
6
- export declare function createClientIdManager(environment: Environment): ClientIdManager;
6
+ export declare function createClientIdManager(environmentManager: EnvironmentManager): ClientIdManager;
7
7
  //# sourceMappingURL=client-id.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client-id.d.ts","sourceRoot":"","sources":["../../../src/client-id/client-id.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEzD,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,MAAM,CAAC;IAC1B,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,WAAW,GACvB,eAAe,CAkBjB"}
1
+ {"version":3,"file":"client-id.d.ts","sourceRoot":"","sources":["../../../src/client-id/client-id.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpE,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,MAAM,CAAC;IAC1B,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,wBAAgB,qBAAqB,CACnC,kBAAkB,EAAE,kBAAkB,GACrC,eAAe,CAoBjB"}
@@ -22,6 +22,12 @@ export interface RelayConfig {
22
22
  * @default emit
23
23
  */
24
24
  mode?: RelayMode;
25
+ /**
26
+ * Optionally allows a Relay integration to specify the name(s) of software package(s) relay is
27
+ * being called from. These names will be transmitted with each event, along with Relay's own
28
+ * version. The recommendation is to specify them using a 'softwarename@softwareversion' string.
29
+ */
30
+ source?: string[];
25
31
  }
26
32
  export interface ConfigManager {
27
33
  get: () => Readonly<RelayConfig>;
@@ -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,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"}
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;IAEjB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;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;AAiBD,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,WAAW,GACzB,QAAQ,CAAC,aAAa,CAAC,CASzB"}
@@ -0,0 +1,7 @@
1
+ import { ConfigManager } from "../../config/config";
2
+ import { Environment } from "../environment";
3
+ export interface EnvironmentManager {
4
+ get: () => Readonly<Environment>;
5
+ }
6
+ export declare function createEnvironmentManager(configManager: ConfigManager): Readonly<EnvironmentManager>;
7
+ //# sourceMappingURL=manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../../src/environment/manager/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAsB,MAAM,gBAAgB,CAAC;AAGjE,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,QAAQ,CAAC,WAAW,CAAC,CAAC;CAClC;AAQD,wBAAgB,wBAAwB,CACtC,aAAa,EAAE,aAAa,GAC3B,QAAQ,CAAC,kBAAkB,CAAC,CAI9B"}
@@ -27,9 +27,9 @@ export interface Meta {
27
27
  */
28
28
  ts: number;
29
29
  /**
30
- * Library and version in which the event is built and emitted.
30
+ * Names and versions of the client side libraries which built and emitted this event.
31
31
  */
32
- source: string;
32
+ source: string[];
33
33
  /**
34
34
  * Persistent unique identifier of a device.
35
35
  */
@@ -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,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,EAAE,MAAM,IAAI,CAAC;CAC1B;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,aAAa,EAAE,WAAW,GAAG,KAAK,CA4C7D;AAED,YAAY,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coveo/relay",
3
- "version": "0.6.7",
3
+ "version": "0.6.9",
4
4
  "description": "A library for sending analytics events using Coveo's Event protocol.",
5
5
  "files": [
6
6
  "lib/**/*"
@@ -52,8 +52,8 @@
52
52
  "ts-jest": "^29.1.1",
53
53
  "typedoc": "^0.25.3",
54
54
  "typescript": "^5.1.6",
55
- "eslint-config-custom": "0.0.0",
56
- "tsconfig": "0.0.0"
55
+ "tsconfig": "0.0.0",
56
+ "eslint-config-custom": "0.0.0"
57
57
  },
58
58
  "dependencies": {
59
59
  "@coveo/explorer-messenger": "^0.1.1",