@coveo/relay 0.7.3 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cdn/relay.min.js +1 -1
- package/lib/cdn/relay.min.js.map +1 -1
- package/lib/cdn/types/config/config.d.ts +15 -7
- package/lib/cdn/types/config/config.d.ts.map +1 -1
- package/lib/cdn/types/event/meta/meta.d.ts +2 -1
- package/lib/cdn/types/event/meta/meta.d.ts.map +1 -1
- package/lib/cdn/types/event/relay-event.d.ts +7 -1
- package/lib/cdn/types/event/relay-event.d.ts.map +1 -1
- package/lib/cdn/types/listener/listener.d.ts +1 -1
- package/lib/cdn/types/relay-payload.d.ts +6 -0
- package/lib/cdn/types/relay-payload.d.ts.map +1 -0
- package/lib/cdn/types/relay.d.ts +12 -4
- package/lib/cdn/types/relay.d.ts.map +1 -1
- package/lib/docs/relay-docs.json +614 -241
- package/lib/relay.cjs +5 -4
- package/lib/relay.js +5 -4
- package/lib/relay.mjs +5 -4
- package/lib/types/config/config.d.ts +15 -7
- package/lib/types/config/config.d.ts.map +1 -1
- package/lib/types/event/meta/meta.d.ts +2 -1
- package/lib/types/event/meta/meta.d.ts.map +1 -1
- package/lib/types/event/relay-event.d.ts +7 -1
- package/lib/types/event/relay-event.d.ts.map +1 -1
- package/lib/types/listener/listener.d.ts +1 -1
- package/lib/types/relay-payload.d.ts +6 -0
- package/lib/types/relay-payload.d.ts.map +1 -0
- package/lib/types/relay.d.ts +12 -4
- package/lib/types/relay.d.ts.map +1 -1
- package/package.json +3 -2
- package/lib/cdn/types/internal-types.d.ts +0 -2
- package/lib/cdn/types/internal-types.d.ts.map +0 -1
- package/lib/types/internal-types.d.ts +0 -2
- package/lib/types/internal-types.d.ts.map +0 -1
package/lib/cdn/relay.min.js
CHANGED
|
@@ -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.get(),o=r.storage,c=o.getItem(n),
|
|
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),s=c&&("string"==typeof(a=c)&&e.test(a))?c:r.generateUUID();var a;return o.setItem(n,s),s},clear:()=>{t.get().storage.removeItem(n)}}}const n="0.7.5";function r(e){return(e.source||[]).concat([`relay@${n}`])}function o(e,t,n,o){const{getReferrer:c,getLocation:s,getUserAgent:a}=n,i=function(e){const{trackingId:t,user:n}=e;return{trackingId:t,user:n||{id:null}}}(t),u=o.getClientId();return Object.freeze({type:e,config:i,ts:Date.now(),source:r(t),clientId:u,userAgent:a(),referrer:c(),location:s()})}const c="*";function s(){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 a({url:e,token:t,trackingId:n,...r}){return Object.freeze({url:e,token:t,trackingId:n,...!!r.user&&{user:r.user},...!!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()}`,s=o?`;domain=${o}`:"";document.cookie=`${e}${t}=${n}${c}${s};path=/;SameSite=Lax`},removeItem(e){this.setItem(e,"",-1)}}}();function u(){return{runtime:"browser",send:(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 l(e){return"disabled"!==e.get().mode&&function(){try{return"object"==typeof window}catch(e){return!1}}()?u():{runtime:"null",send:()=>{},getReferrer:()=>null,getLocation:()=>null,getUserAgent:()=>null,generateUUID:()=>"",storage:{getItem:()=>null,removeItem(){},setItem(){}}}}function g(e){const r=function(e){let t=a(e);return{get:()=>t,update:e=>{t=a({...t,...e})}}}(e),c=s(),i=function(e){return{get:()=>Object.freeze(l(e))}}(r),u=t(i);return{emit:(e,t)=>{const n=r.get(),s=i.get(),a=function(e,t,n,r,c){return{...t,meta:o(e,n,r,c)}}(e,t,n,s,u);return function({config:e,environment:t,event:n,listenerManager:r}){const{url:o,token:c,mode:s}=e;"disabled"!==s&&(r.call(n),t.send(o,c,n))}({config:n,environment:s,event:a,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{g as createRelay};
|
|
2
2
|
//# sourceMappingURL=relay.min.js.map
|
package/lib/cdn/relay.min.js.map
CHANGED
|
@@ -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/version.ts","../../src/event/meta/meta.ts","../../src/listener/listener.ts","../../src/config/config.ts","../../src/environment/browser/storage/cookie.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/manager/manager.ts","../../src/environment/null/null.ts","../../src/environment/storage.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, User } 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 * Named user identity which logged this event.\n */\n user: User | null;\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, user: null };\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<Meta>({\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 User {\n /**\n * The application's user identifier.\n */\n id: 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","import { createExplorerMessenger } from \"@coveo/explorer-messenger\";\nimport { Environment } from \"../environment\";\nimport { createBrowserStorage } from \"./storage/storage\";\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 send: (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","import { ConfigManager } from \"../../config/config\";\nimport { buildBrowserEnvironment } from \"../browser/browser\";\nimport { Environment } from \"../environment\";\nimport { buildNullEnvironment } from \"../null/null\";\n\nexport interface EnvironmentManager {\n get: () => Readonly<Environment>;\n}\n\nfunction buildEnvironment(configManager: ConfigManager) {\n const active = configManager.get().mode !== \"disabled\";\n\n if (active && isBrowser()) {\n return buildBrowserEnvironment();\n }\n\n return buildNullEnvironment();\n}\n\nfunction isBrowser() {\n try {\n return typeof window === \"object\";\n } catch (e) {\n return false;\n }\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 send: () => undefined,\n getReferrer: () => null,\n getLocation: () => null,\n getUserAgent: () => null,\n generateUUID: () => \"\",\n storage: createNullStorage(),\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 { 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 {void}\n */\n emit: (type: string, payload: Record<string, any>) => 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 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","user","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","buildBrowserEnvironment","runtime","send","response","navigator","sendBeacon","Blob","JSON","stringify","messenger","isBrowser","sendMessage","message","postMessage","createExplorerMessenger","kind","Error","href","crypto","randomUUID","localStorage","buildEnvironment","configManager","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,QCsEvB,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,aAAYC,KAAM,KAC7B,CAasBC,CAAeZ,GAC7BT,EAAWc,EAAgBpB,cAEjC,OAAO4B,OAAOC,OAAa,CACzBV,OACAJ,OAAQS,EACRM,GAAIC,KAAKC,MACThB,OAAQF,EAAUC,GAClBT,WACA2B,UAAWV,IACXW,SAAUb,IACVc,SAAUb,KAEd,CC5FA,MAAMc,EAAiB,aAqBPC,IACd,MAAMC,EAAwB,GAE9B,SAASC,GAAiBpB,KAAEA,EAAIqB,SAAEA,IAChC,OAAOF,EAAUG,WACdC,GAAaA,EAASvB,OAASA,GAAQuB,EAASF,WAAaA,GAEjE,CA4CD,SAASG,EAAOxB,EAAcqB,GAC1BA,EARJ,SAAmBE,GACjB,MAAME,EAAQL,EAAiBG,GAC3BE,GAAS,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AAKC,EAAOT,GAEjC,CFqEasE,CAAK,CACV5G,SACAd,cACAoD,QACAoE,mBACA,EAEJK,QAAU3G,GACRD,EACEC,EACA+F,EAAchH,MACdJ,EAAmBI,MACnBkB,GAEJ2G,GAAI,CAAC5G,EAAcqB,IACjBiF,EAAgBvE,IAAI,CAAE/B,OAAMqB,aAC9BwF,IAAK,CAAC7G,EAAcqB,IAClBiF,EAAgB9E,OAAOxB,EAAMqB,GAC/ByF,aAAelH,GACbmG,EAAcI,OAAOvG,GACvBF,UACAqH,aAAc,KACZ9G,EAAgBT,OAAO,EAG7B","x_google_ignoreList":[0,2,9]}
|
|
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/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/manager/manager.ts","../../src/environment/null/null.ts","../../src/environment/storage.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, User } 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 * Named user identity which logged this event.\n */\n user: User;\n}\n\n/**\n * The `Meta` object provides a structured representation of metadata associated with an emitted event.\n * This object is auto-populated by Relay.\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, user } = config;\n return { trackingId, user: user || { id: null } };\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<Meta>({\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 - the Relay event payload that triggered the callback.\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","/**\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 * The application's user identity. If not set in the config, Relay will assume the identity matches\n * the identity in the authentication or anonymous otherwise.\n */\n user?: User;\n\n /**\n * Defines the library mode. The available modes are `emit` and `disabled`.\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?: \"emit\" | \"disabled\";\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\n/**\n * User which logged the event.\n */\nexport interface User {\n /**\n * The application's user identifier. An id of 'anonymous' assumes the user is explicitly anonymous. An id of null indicates\n * the identity is equal to the identity in the authentication or anonymous.\n */\n id: string | null;\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.user && { user: rest.user }),\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","import { createExplorerMessenger } from \"@coveo/explorer-messenger\";\nimport { Environment } from \"../environment\";\nimport { createBrowserStorage } from \"./storage/storage\";\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 send: (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","import { ConfigManager } from \"../../config/config\";\nimport { buildBrowserEnvironment } from \"../browser/browser\";\nimport { Environment } from \"../environment\";\nimport { buildNullEnvironment } from \"../null/null\";\n\nexport interface EnvironmentManager {\n get: () => Readonly<Environment>;\n}\n\nfunction buildEnvironment(configManager: ConfigManager) {\n const active = configManager.get().mode !== \"disabled\";\n\n if (active && isBrowser()) {\n return buildBrowserEnvironment();\n }\n\n return buildNullEnvironment();\n}\n\nfunction isBrowser() {\n try {\n return typeof window === \"object\";\n } catch (e) {\n return false;\n }\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 send: () => undefined,\n getReferrer: () => null,\n getLocation: () => null,\n getUserAgent: () => null,\n generateUUID: () => \"\",\n storage: createNullStorage(),\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 { emit } from \"./emit/emit\";\nimport { createClientIdManager } from \"./client-id/client-id\";\nimport { createRelayEvent, RelayEvent } 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, User } from \"./config/config\";\nimport { createEnvironmentManager } from \"./environment/manager/manager\";\nimport { RelayPayload } from \"./relay-payload\";\n\n/**\n * Function that detaches an event callback.\n * @typedef {function} Off\n * @returns {void}\n */\nexport type 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 {void}\n */\n emit: (type: string, payload: Record<string, any>) => 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 * It’s not possible to modify the payload of the event sent to Coveo using this listener.\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 - callback that should be called when the event is emitted.\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 {\n Relay,\n Meta,\n EventConfig,\n EventCallback,\n RelayConfig,\n User,\n RelayPayload,\n RelayEvent,\n};\n","import { ClientIdManager } from \"../client-id/client-id\";\nimport { Environment } from \"../environment/environment\";\nimport { RelayPayload } from \"../relay-payload\";\nimport { RelayConfig } from \"../relay\";\nimport { createMeta, Meta } from \"./meta/meta\";\n\n/**\n * Defines the structure of a RelayEvent, extending the RelayPayload.\n */\nexport interface RelayEvent extends RelayPayload {\n /**\n * Read-only `meta` property of Meta type.\n */\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 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","user","id","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","buildBrowserEnvironment","runtime","send","response","navigator","sendBeacon","Blob","JSON","stringify","messenger","isBrowser","sendMessage","message","postMessage","createExplorerMessenger","kind","Error","href","crypto","randomUUID","localStorage","buildEnvironment","configManager","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,E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]}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export type RelayMode = "emit" | "disabled";
|
|
2
1
|
/**
|
|
3
2
|
* The `RelayConfig` object defines the configuration options for initializing a Relay instance.
|
|
4
3
|
*/
|
|
@@ -16,12 +15,17 @@ export interface RelayConfig {
|
|
|
16
15
|
*/
|
|
17
16
|
trackingId: string;
|
|
18
17
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
|
|
18
|
+
* The application's user identity. If not set in the config, Relay will assume the identity matches
|
|
19
|
+
* the identity in the authentication or anonymous otherwise.
|
|
20
|
+
*/
|
|
21
|
+
user?: User;
|
|
22
|
+
/**
|
|
23
|
+
* Defines the library mode. The available modes are `emit` and `disabled`.
|
|
24
|
+
* `emit` sends analytics events to Coveo to be stored.
|
|
25
|
+
* `disabled` prevents the emission of events and does not trigger callbacks.
|
|
22
26
|
* @default emit
|
|
23
27
|
*/
|
|
24
|
-
mode?:
|
|
28
|
+
mode?: "emit" | "disabled";
|
|
25
29
|
/**
|
|
26
30
|
* Optionally allows a Relay integration to specify the name(s) of software package(s) relay is
|
|
27
31
|
* being called from. These names will be transmitted with each event, along with Relay's own
|
|
@@ -29,11 +33,15 @@ export interface RelayConfig {
|
|
|
29
33
|
*/
|
|
30
34
|
source?: string[];
|
|
31
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* User which logged the event.
|
|
38
|
+
*/
|
|
32
39
|
export interface User {
|
|
33
40
|
/**
|
|
34
|
-
* The application's user identifier.
|
|
41
|
+
* The application's user identifier. An id of 'anonymous' assumes the user is explicitly anonymous. An id of null indicates
|
|
42
|
+
* the identity is equal to the identity in the authentication or anonymous.
|
|
35
43
|
*/
|
|
36
|
-
id: string;
|
|
44
|
+
id: string | null;
|
|
37
45
|
}
|
|
38
46
|
export interface ConfigManager {
|
|
39
47
|
get: () => Readonly<RelayConfig>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config/config.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config/config.ts"],"names":[],"mappings":"AAAA;;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;;;OAGG;IACH,IAAI,CAAC,EAAE,IAAI,CAAC;IAEZ;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IAE3B;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,IAAI;IACnB;;;OAGG;IACH,EAAE,EAAE,MAAM,GAAG,IAAI,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;AAkBD,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,WAAW,GACzB,QAAQ,CAAC,aAAa,CAAC,CASzB"}
|
|
@@ -12,10 +12,11 @@ export interface EventConfig {
|
|
|
12
12
|
/**
|
|
13
13
|
* Named user identity which logged this event.
|
|
14
14
|
*/
|
|
15
|
-
user: User
|
|
15
|
+
user: User;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* The `Meta` object provides a structured representation of metadata associated with an emitted event.
|
|
19
|
+
* This object is auto-populated by Relay.
|
|
19
20
|
*/
|
|
20
21
|
export interface Meta {
|
|
21
22
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../../../../src/event/meta/meta.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM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+1,15 @@
|
|
|
1
1
|
import { ClientIdManager } from "../client-id/client-id";
|
|
2
2
|
import { Environment } from "../environment/environment";
|
|
3
|
-
import { RelayPayload } from "../
|
|
3
|
+
import { RelayPayload } from "../relay-payload";
|
|
4
4
|
import { RelayConfig } from "../relay";
|
|
5
5
|
import { Meta } from "./meta/meta";
|
|
6
|
+
/**
|
|
7
|
+
* Defines the structure of a RelayEvent, extending the RelayPayload.
|
|
8
|
+
*/
|
|
6
9
|
export interface RelayEvent extends RelayPayload {
|
|
10
|
+
/**
|
|
11
|
+
* Read-only `meta` property of Meta type.
|
|
12
|
+
*/
|
|
7
13
|
meta: Readonly<Meta>;
|
|
8
14
|
}
|
|
9
15
|
export declare function createRelayEvent(type: string, payload: RelayPayload, config: RelayConfig, environment: Environment, clientIdManager: ClientIdManager): Readonly<RelayEvent>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relay-event.d.ts","sourceRoot":"","sources":["../../../src/event/relay-event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"relay-event.d.ts","sourceRoot":"","sources":["../../../src/event/relay-event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAc,IAAI,EAAE,MAAM,aAAa,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,UAAW,SAAQ,YAAY;IAC9C;;OAEG;IACH,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;CACtB;AAED,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,WAAW,EACnB,WAAW,EAAE,WAAW,EACxB,eAAe,EAAE,eAAe,GAC/B,QAAQ,CAAC,UAAU,CAAC,CAKtB"}
|
|
@@ -2,7 +2,7 @@ import { RelayEvent } from "../event/relay-event";
|
|
|
2
2
|
/**
|
|
3
3
|
* Callback to perform an action when a specified event is emitted.
|
|
4
4
|
* @typedef {function} EventCallback
|
|
5
|
-
* @param {RelayEvent} event
|
|
5
|
+
* @param {RelayEvent} event - the Relay event payload that triggered the callback.
|
|
6
6
|
* @returns {void}
|
|
7
7
|
*/
|
|
8
8
|
export type EventCallback = (event: RelayEvent) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relay-payload.d.ts","sourceRoot":"","sources":["../../src/relay-payload.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC"}
|
package/lib/cdn/types/relay.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
import { RelayEvent } from "./event/relay-event";
|
|
1
2
|
import { Meta, EventConfig } from "./event/meta/meta";
|
|
2
3
|
import { EventCallback } from "./listener/listener";
|
|
3
|
-
import { RelayConfig } from "./config/config";
|
|
4
|
-
|
|
4
|
+
import { RelayConfig, User } from "./config/config";
|
|
5
|
+
import { RelayPayload } from "./relay-payload";
|
|
6
|
+
/**
|
|
7
|
+
* Function that detaches an event callback.
|
|
8
|
+
* @typedef {function} Off
|
|
9
|
+
* @returns {void}
|
|
10
|
+
*/
|
|
11
|
+
export type Off = () => void;
|
|
5
12
|
/**
|
|
6
13
|
* Relay instance.
|
|
7
14
|
* This object provides a comprehensive set of variables and methods for interacting with the Event API.
|
|
@@ -23,10 +30,11 @@ interface Relay {
|
|
|
23
30
|
/**
|
|
24
31
|
* Attaches an event callback to either all event types or a specific one.
|
|
25
32
|
* The callback set will be called when an event with the specified type is emitted.
|
|
33
|
+
* It’s not possible to modify the payload of the event sent to Coveo using this listener.
|
|
26
34
|
* Setting type as "*" will trigger the callback for all event types.
|
|
27
35
|
* Returns the "off" function to detach the event callback.
|
|
28
36
|
* @param {string} type - event's type.
|
|
29
|
-
* @param {EventCallback} callback
|
|
37
|
+
* @param {EventCallback} callback - callback that should be called when the event is emitted.
|
|
30
38
|
* @returns {Off}
|
|
31
39
|
*/
|
|
32
40
|
on: (type: string, callback: EventCallback) => Off;
|
|
@@ -60,5 +68,5 @@ interface Relay {
|
|
|
60
68
|
* @returns {Relay}
|
|
61
69
|
*/
|
|
62
70
|
export declare function createRelay(initialConfig: RelayConfig): Relay;
|
|
63
|
-
export type { Relay, Meta, EventConfig, EventCallback, RelayConfig };
|
|
71
|
+
export type { Relay, Meta, EventConfig, EventCallback, RelayConfig, User, RelayPayload, RelayEvent, };
|
|
64
72
|
//# sourceMappingURL=relay.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relay.d.ts","sourceRoot":"","sources":["../../src/relay.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"relay.d.ts","sourceRoot":"","sources":["../../src/relay.ts"],"names":[],"mappings":"AAEA,OAAO,EAAoB,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEnE,OAAO,EAAc,IAAI,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAyB,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAuB,WAAW,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEzE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C;;;;GAIG;AACH,MAAM,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC;AAE7B;;;GAGG;AACH,UAAU,KAAK;IACb;;;;;OAKG;IACH,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,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