@coveo/relay 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/lib/cdn/relay.min.js +2 -0
  2. package/lib/cdn/relay.min.js.map +1 -0
  3. package/lib/cdn/types/client-id/client-id.d.ts +6 -0
  4. package/lib/cdn/types/client-id/client-id.d.ts.map +1 -0
  5. package/lib/cdn/types/config/config.d.ts +13 -0
  6. package/lib/cdn/types/config/config.d.ts.map +1 -0
  7. package/lib/cdn/types/emit/emit.d.ts +3 -0
  8. package/lib/cdn/types/emit/emit.d.ts.map +1 -0
  9. package/lib/cdn/types/environment/browser/browser.d.ts +3 -0
  10. package/lib/cdn/types/environment/browser/browser.d.ts.map +1 -0
  11. package/lib/cdn/types/environment/browser/storage/cookie.d.ts +7 -0
  12. package/lib/cdn/types/environment/browser/storage/cookie.d.ts.map +1 -0
  13. package/lib/cdn/types/environment/browser/storage/storage.d.ts +3 -0
  14. package/lib/cdn/types/environment/browser/storage/storage.d.ts.map +1 -0
  15. package/lib/cdn/types/environment/environment.d.ts +12 -0
  16. package/lib/cdn/types/environment/environment.d.ts.map +1 -0
  17. package/lib/cdn/types/environment/node/node.d.ts +3 -0
  18. package/lib/cdn/types/environment/node/node.d.ts.map +1 -0
  19. package/lib/cdn/types/environment/storage.d.ts +7 -0
  20. package/lib/cdn/types/environment/storage.d.ts.map +1 -0
  21. package/lib/cdn/types/environment/utils/fetch.d.ts +2 -0
  22. package/lib/cdn/types/environment/utils/fetch.d.ts.map +1 -0
  23. package/lib/cdn/types/event/meta/meta.d.ts +19 -0
  24. package/lib/cdn/types/event/meta/meta.d.ts.map +1 -0
  25. package/lib/cdn/types/event/relay-event.d.ts +9 -0
  26. package/lib/cdn/types/event/relay-event.d.ts.map +1 -0
  27. package/lib/cdn/types/event-api-call/event-api-caller.d.ts +10 -0
  28. package/lib/cdn/types/event-api-call/event-api-caller.d.ts.map +1 -0
  29. package/lib/cdn/types/listener/listener.d.ts +14 -0
  30. package/lib/cdn/types/listener/listener.d.ts.map +1 -0
  31. package/lib/cdn/types/relay.d.ts +17 -0
  32. package/lib/cdn/types/relay.d.ts.map +1 -0
  33. package/lib/cdn/types/validate/validate.d.ts +12 -0
  34. package/lib/cdn/types/validate/validate.d.ts.map +1 -0
  35. package/lib/cdn/types/version.d.ts +2 -0
  36. package/lib/cdn/types/version.d.ts.map +1 -0
  37. package/lib/relay.cjs +1 -1
  38. package/lib/relay.js +1 -1
  39. package/lib/relay.mjs +1 -1
  40. package/package.json +2 -1
@@ -0,0 +1,2 @@
1
+ async function e({event:e,config:t,environment:n}){const{url:r,token:o}=t,c={"Content-Type":"application/json",Authorization:`Bearer ${o}`},a=await n.fetch(`${r}${"validate"==t.mode?"/validate":""}`,{method:"POST",body:JSON.stringify([e]),headers:c}),i=await a.json();if(!a.ok)throw new Error({...i});return i}let t;const n=new Uint8Array(16);function r(){if(!t&&(t="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!t))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return t(n)}var o=/^(?:[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;const c=[];for(let e=0;e<256;++e)c.push((e+256).toString(16).slice(1));var a={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function i(e,t,n){if(a.randomUUID&&!t&&!e)return a.randomUUID();const o=(e=e||{}).random||(e.rng||r)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=o[e];return t}return function(e,t=0){return(c[e[t+0]]+c[e[t+1]]+c[e[t+2]]+c[e[t+3]]+"-"+c[e[t+4]]+c[e[t+5]]+"-"+c[e[t+6]]+c[e[t+7]]+"-"+c[e[t+8]]+c[e[t+9]]+"-"+c[e[t+10]]+c[e[t+11]]+c[e[t+12]]+c[e[t+13]]+c[e[t+14]]+c[e[t+15]]).toLowerCase()}(o)}function u(e){const t=e.storage,n="visitorId",r=t.getItem(n),c=r&&("string"==typeof(a=r)&&o.test(a))?r:e.generateUUID();var a;return t.setItem(n,c),c}const s=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 l(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 f(){return{runtime:"browser",fetch:(e,t)=>l(e,t),getReferrerUrl:()=>function(){const e=document.referrer;return""===e?null:e}(),getUrl:()=>window.location.href,getUserAgent:()=>navigator.userAgent,generateUUID:()=>i(),storage:{getItem:e=>s.getItem(e)||localStorage.getItem(e),removeItem(e){s.removeItem(e),localStorage.removeItem(e)},setItem(e,t){localStorage.setItem(e,t),s.setItem(e,t,31556952e3)}}}}function g(){return function(){try{return"object"==typeof window}catch(e){return!1}}()?f():{runtime:"node",fetch:(e,t)=>l(e,t),getReferrerUrl:()=>null,getUrl:()=>null,getUserAgent:()=>null,generateUUID:()=>i(),storage:{getItem:()=>null,removeItem(){},setItem(){}}}}const d="0.4.3";function m(e,t,n,r){const{getReferrerUrl:o,getUrl:c,getUserAgent:a}=n,i=function(e){const{trackingId:t}=e;return{trackingId:t}}(t),{clientId:u}=r;return Object.freeze({type:e,config:i,ts:Date.now(),source:`relay@${d}`,clientId:u,userAgent:a(),referrerUrl:o(),url:c()})}const p="*";function I(){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===p)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 y({url:e,token:t,trackingId:n,...r}){return Object.freeze({url:e,token:t,trackingId:n,...!!r.mode&&{mode:r.mode}})}function h(t){const n=g(),r=function(e){return{clientId:u(e)}}(n),o=function(e){let t=y(e);return{get:()=>t,update:e=>{t=y({...t,...e})}}}(t),{add:c,call:a,remove:i}=I();return{emit:(t,c)=>{const i=function(e,t,n,r,o){return{...t,meta:m(e,n,r,o)}}(t,c,o.get(),n,r);a(i);const u={config:o.get(),environment:n,event:i};return"validate"===o.get().mode?async function(t){const n=await e(t),{valid:r,errors:o}=n[0];return{valid:r,errors:o??[]}}(u):async function(t){await e(t)}(u)},getMeta:e=>m(e,o.get(),n,r),on:(e,t)=>c({type:e,callback:t}),off:(e,t)=>i(e,t),updateConfig:e=>o.update(e),version:d}}export{h as createRelay};
2
+ //# sourceMappingURL=relay.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relay.min.js","sources":["../../src/event-api-call/event-api-caller.ts","../../../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-browser/rng.js","../../../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-browser/regex.js","../../../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-browser/stringify.js","../../../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-browser/native.js","../../../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-browser/v4.js","../../src/client-id/client-id.ts","../../../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-browser/validate.js","../../src/environment/browser/storage/cookie.ts","../../src/environment/utils/fetch.ts","../../src/environment/browser/browser.ts","../../src/environment/browser/storage/storage.ts","../../src/environment/environment.ts","../../src/environment/node/node.ts","../../src/environment/storage.ts","../../src/version.ts","../../src/event/meta/meta.ts","../../src/listener/listener.ts","../../src/config/config.ts","../../src/relay.ts","../../src/event/relay-event.ts","../../src/validate/validate.ts","../../src/emit/emit.ts"],"sourcesContent":["import { Environment } from \"../environment/environment\";\nimport { RelayEvent } from \"../event/relay-event\";\nimport { RelayConfig } from \"../config/config\";\n\nexport interface EventApiCallParams {\n config: RelayConfig;\n environment: Environment;\n event: Readonly<RelayEvent>;\n}\n\nexport async function callEventApi({\n event,\n config,\n environment,\n}: EventApiCallParams): Promise<any> {\n const { url, token } = config;\n const headers = {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${token}`,\n };\n const response = await environment.fetch(\n `${url}${config.mode == \"validate\" ? \"/validate\" : \"\"}`,\n {\n method: \"POST\",\n body: JSON.stringify([event]),\n headers,\n }\n );\n\n const data = await response.json();\n\n if (!response.ok) {\n throw new Error({\n ...data,\n });\n }\n\n return data;\n}\n","// Unique ID creation requires a high quality random # generator. In the browser we therefore\n// require the crypto API and do not support built-in fallback to lower quality random number\n// generators (like Math.random()).\nlet getRandomValues;\nconst rnds8 = new Uint8Array(16);\nexport default function rng() {\n // lazy load so that environments that need to polyfill have a chance to do so\n if (!getRandomValues) {\n // getRandomValues needs to be invoked in a context where \"this\" is a Crypto implementation.\n getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);\n\n if (!getRandomValues) {\n throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');\n }\n }\n\n return getRandomValues(rnds8);\n}","export default /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;","import validate from './validate.js';\n/**\n * Convert array of 16 byte values to UUID string format of the form:\n * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\n */\n\nconst byteToHex = [];\n\nfor (let i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).slice(1));\n}\n\nexport function unsafeStringify(arr, offset = 0) {\n // Note: Be careful editing this code! It's been tuned for performance\n // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434\n return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();\n}\n\nfunction stringify(arr, offset = 0) {\n const uuid = unsafeStringify(arr, offset); // Consistency check for valid UUID. If this throws, it's likely due to one\n // of the following:\n // - One or more input array values don't map to a hex octet (leading to\n // \"undefined\" in the uuid)\n // - Invalid input values for the RFC `version` or `variant` fields\n\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n\n return uuid;\n}\n\nexport default stringify;","const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);\nexport default {\n randomUUID\n};","import native from './native.js';\nimport rng from './rng.js';\nimport { unsafeStringify } from './stringify.js';\n\nfunction v4(options, buf, offset) {\n if (native.randomUUID && !buf && !options) {\n return native.randomUUID();\n }\n\n options = options || {};\n const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`\n\n rnds[6] = rnds[6] & 0x0f | 0x40;\n rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided\n\n if (buf) {\n offset = offset || 0;\n\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n\n return buf;\n }\n\n return unsafeStringify(rnds);\n}\n\nexport default v4;","import { validate } from \"uuid\";\nimport { Environment } from \"../environment/environment\";\n\nexport interface ClientIdManager {\n clientId: string;\n}\n\nfunction getClientId(environment: Environment): string {\n const storage = environment.storage;\n const key = \"visitorId\";\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\nexport function createClientIdManager(\n environment: Environment\n): ClientIdManager {\n return {\n clientId: getClientId(environment),\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 { v4 as uuidv4 } from \"uuid\";\nimport { Environment } from \"../environment\";\nimport { createBrowserStorage } from \"./storage/storage\";\nimport { fetchAPI } from \"../utils/fetch\";\n\nfunction getReferrerUrl() {\n const referrer = document.referrer;\n\n return referrer === \"\" ? null : referrer;\n}\n\nexport function buildBrowserEnvironment(): Environment {\n return {\n runtime: \"browser\",\n fetch: (url: string, init?: RequestInit) => fetchAPI(url, init),\n getReferrerUrl: () => getReferrerUrl(),\n getUrl: () => window.location.href,\n getUserAgent: () => navigator.userAgent,\n generateUUID: () => uuidv4(),\n storage: createBrowserStorage(),\n };\n}\n","import { Storage } from \"../../storage\";\nimport { cookieManager } from \"./cookie\";\n\nexport function createBrowserStorage(): Storage {\n return {\n getItem(key: string): string | null {\n return cookieManager.getItem(key) || localStorage.getItem(key);\n },\n\n removeItem(key: string): void {\n cookieManager.removeItem(key);\n localStorage.removeItem(key);\n },\n\n setItem(key: string, data: string): void {\n const oneYear = 31556952000;\n localStorage.setItem(key, data);\n cookieManager.setItem(key, data, oneYear);\n },\n };\n}\n","import { buildBrowserEnvironment } from \"./browser/browser\";\nimport { buildNodeEnvironment } from \"./node/node\";\nimport { Storage } from \"./storage\";\n\nexport interface Environment {\n runtime: \"browser\" | \"node\";\n fetch: (url: string, init?: RequestInit) => Promise<Response>;\n getReferrerUrl: () => string | null;\n getUrl: () => string | null;\n getUserAgent: () => string | null;\n generateUUID: () => string;\n storage: Storage;\n}\n\nexport function currentEnvironment(): Environment {\n return isBrowser() ? buildBrowserEnvironment() : buildNodeEnvironment();\n}\n\nfunction isBrowser() {\n try {\n return typeof window === \"object\";\n } catch (e) {\n return false;\n }\n}\n","import { v4 as uuidv4 } from \"uuid\";\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 getReferrerUrl: () => null,\n getUrl: () => null,\n getUserAgent: () => null,\n generateUUID: () => uuidv4(),\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","export const version: string = process.env.VERSION ?? \"\";\n","import { ClientIdManager } from \"../../client-id/client-id\";\nimport { Environment } from \"../../environment/environment\";\nimport { RelayConfig } from \"../../config/config\";\nimport { version } from \"../../version\";\n\ninterface EventConfig {\n trackingId: string;\n}\n\nexport interface Meta {\n type: string;\n config: EventConfig;\n ts: number;\n source: string;\n clientId: string;\n userAgent: string | null;\n referrerUrl: string | null;\n url: string | null;\n}\n\nfunction getEventConfig(config: RelayConfig): EventConfig {\n const { trackingId } = config;\n return { trackingId };\n}\n\nfunction getSource(): string {\n return `relay@${version}`;\n}\n\nexport function createMeta(\n type: string,\n config: RelayConfig,\n environment: Environment,\n clientIdManager: ClientIdManager\n): Readonly<Meta> {\n const { getReferrerUrl, getUrl, getUserAgent } = environment;\n const eventConfig = getEventConfig(config);\n const { clientId } = clientIdManager;\n\n return Object.freeze({\n type,\n config: eventConfig,\n ts: Date.now(),\n source: getSource(),\n clientId,\n userAgent: getUserAgent(),\n referrerUrl: getReferrerUrl(),\n url: getUrl(),\n });\n}\n","import { RelayEvent } from \"../event/relay-event\";\n\nconst ANY_EVENT_TYPE = \"*\";\n\nexport type EventCallback = (event: RelayEvent) => void;\n\ninterface Listener {\n type: string;\n callback: EventCallback;\n}\n\ninterface ListenerManager {\n add: (listener: Listener) => () => void;\n call: (event: RelayEvent) => void;\n remove: (type: string, callback?: EventCallback) => void;\n}\n\nexport function createListenerManager(): ListenerManager {\n const listeners: Listener[] = [];\n\n function getListenerIndex({ type, callback }: Listener): number {\n return listeners.findIndex(\n (listener) => listener.type === type && listener.callback === callback\n );\n }\n\n function isMatchesType(listener: Listener, type: string): boolean {\n return listener.type === \"*\" || type === listener.type;\n }\n\n function add(listener: Listener): () => void {\n if (getListenerIndex(listener) < 0) {\n listeners.push(listener);\n }\n return () => remove(listener.type, listener.callback);\n }\n\n function call(event: RelayEvent) {\n listeners.forEach((listener) => {\n if (isMatchesType(listener, event.meta.type)) {\n try {\n listener.callback(event);\n } catch (e) {\n console.error(e);\n }\n }\n });\n }\n\n function removeMultiple(type: string) {\n if (type === ANY_EVENT_TYPE) {\n listeners.length = 0;\n } else {\n for (let i = listeners.length - 1; i >= 0; i--) {\n if (listeners[i].type === type) {\n listeners.splice(i, 1);\n }\n }\n }\n }\n\n function removeOne(listener: Listener) {\n const index = getListenerIndex(listener);\n if (index >= 0) {\n listeners.splice(index, 1);\n }\n }\n\n function remove(type: string, callback?: EventCallback) {\n !!callback ? removeOne({ type, callback }) : removeMultiple(type);\n }\n\n return {\n add,\n call,\n remove,\n };\n}\n","export type RelayMode = \"emit\" | \"validate\";\n\nexport interface RelayConfig {\n url: string;\n token: string;\n trackingId: string;\n mode?: RelayMode;\n}\n\nexport interface ConfigManager {\n get: () => Readonly<RelayConfig>;\n update: (updatedConfig: Partial<RelayConfig>) => void;\n}\n\nfunction pick({\n url,\n token,\n trackingId,\n ...rest\n}: RelayConfig): Readonly<RelayConfig> {\n return Object.freeze({\n url,\n token,\n trackingId,\n ...(!!rest.mode && { mode: rest.mode }),\n });\n}\n\nexport function createConfigManager(\n initialConfig: RelayConfig\n): Readonly<ConfigManager> {\n let _config: Readonly<RelayConfig> = pick(initialConfig);\n\n return {\n get: () => _config,\n update: (updatedConfig: Partial<RelayConfig>) => {\n _config = pick({ ..._config, ...updatedConfig });\n },\n };\n}\n","import { emit } from \"./emit/emit\";\nimport { createClientIdManager } from \"./client-id/client-id\";\nimport { currentEnvironment } from \"./environment/environment\";\nimport { createRelayEvent } from \"./event/relay-event\";\nimport { version } from \"./version\";\nimport { createMeta, Meta } from \"./event/meta/meta\";\nimport { createListenerManager, EventCallback } from \"./listener/listener\";\nimport { createConfigManager, RelayConfig } from \"./config/config\";\nimport {\n validate,\n ValidationError,\n ValidationResponse,\n} from \"./validate/validate\";\n\ntype RelayPayload = Record<string, unknown>;\ntype Off = () => void;\n\ninterface Relay {\n emit: (\n type: string,\n payload: RelayPayload\n ) => Promise<void | ValidationResponse>;\n getMeta: (type: string) => Meta;\n on: (type: string, callback: EventCallback) => Off;\n off: (type: string, callback?: EventCallback) => void;\n updateConfig: (config: Partial<RelayConfig>) => void;\n version: string;\n}\n\nexport function createRelay(initialConfig: RelayConfig): Relay {\n const environment = currentEnvironment();\n const clientIdManager = createClientIdManager(environment);\n const configManager = createConfigManager(initialConfig);\n const { add, call, remove } = createListenerManager();\n\n return {\n emit: (type: string, payload: RelayPayload) => {\n const event = createRelayEvent(\n type,\n payload,\n configManager.get(),\n environment,\n clientIdManager\n );\n\n call(event);\n\n const params = { config: configManager.get(), environment, event };\n\n return configManager.get().mode === \"validate\"\n ? validate(params)\n : emit(params);\n },\n getMeta: (type: string) =>\n createMeta(type, configManager.get(), environment, clientIdManager),\n on: (type: string, callback: EventCallback) => add({ type, callback }),\n off: (type: string, callback?: EventCallback) => remove(type, callback),\n updateConfig: (config: Partial<RelayConfig>) =>\n configManager.update(config),\n version,\n };\n}\n\nexport type { RelayPayload, RelayConfig, ValidationError, ValidationResponse };\n","import { ClientIdManager } from \"../client-id/client-id\";\nimport { Environment } from \"../environment/environment\";\nimport { RelayConfig, RelayPayload } from \"../relay\";\nimport { createMeta, Meta } from \"./meta/meta\";\n\nexport interface RelayEvent extends RelayPayload {\n meta: Readonly<Meta>;\n}\n\nexport function createRelayEvent(\n type: string,\n payload: RelayPayload,\n config: RelayConfig,\n environment: Environment,\n clientIdManager: ClientIdManager\n): Readonly<RelayEvent> {\n return {\n ...payload,\n meta: createMeta(type, config, environment, clientIdManager),\n };\n}\n","import {\n callEventApi,\n EventApiCallParams,\n} from \"../event-api-call/event-api-caller\";\n\nexport interface ValidationError {\n type: string;\n message: string;\n path: string;\n}\n\nexport interface ValidationResponse {\n valid: boolean;\n errors: ValidationError[];\n}\n\nexport async function validate(\n params: EventApiCallParams\n): Promise<Readonly<ValidationResponse>> {\n const data = await callEventApi(params);\n\n const { valid, errors } = data[0];\n\n return { valid, errors: errors ?? [] };\n}\n","import {\n callEventApi,\n EventApiCallParams,\n} from \"../event-api-call/event-api-caller\";\n\nexport async function emit(params: EventApiCallParams) {\n await callEventApi(params);\n}\n"],"names":["async","callEventApi","event","config","environment","url","token","headers","Authorization","response","fetch","mode","method","body","JSON","stringify","data","json","ok","Error","getRandomValues","rnds8","Uint8Array","rng","crypto","bind","REGEX","byteToHex","i","push","toString","slice","native","randomUUID","v4","options","buf","offset","rnds","random","arr","toLowerCase","unsafeStringify","getClientId","storage","key","existingClientId","getItem","clientId","uuid","test","generateUUID","setItem","cookieManager","prefix","cookiePrefix","cookieArray","document","cookie","split","prettifyCookie","replace","lastIndexOf","substring","length","expire","domain","host","parts","join","getDomain","window","location","hostname","expireSection","Date","getTime","toUTCString","domainSection","removeItem","this","createCookieManager","fetchAPI","init","catch","err","message","cause","buildBrowserEnvironment","runtime","getReferrerUrl","referrer","getUrl","href","getUserAgent","navigator","userAgent","uuidv4","localStorage","currentEnvironment","e","isBrowser","version","createMeta","type","clientIdManager","eventConfig","trackingId","getEventConfig","Object","freeze","ts","now","source","referrerUrl","ANY_EVENT_TYPE","createListenerManager","listeners","getListenerIndex","callback","findIndex","listener","remove","index","splice","removeOne","removeMultiple","add","call","forEach","isMatchesType","meta","console","error","pick","rest","createRelay","initialConfig","createClientIdManager","configManager","_config","get","update","updatedConfig","createConfigManager","emit","payload","createRelayE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ACnBnJ,EAAamJ,EACrB,CH4CUH,CAAKG,EAAO,EAElBI,QAAUhD,GACRD,EAAWC,EAAMmC,EAAcE,MAAOzI,EAAaqG,GACrDgD,GAAI,CAACjD,EAAce,IAA4BQ,EAAI,CAAEvB,OAAMe,aAC3DmC,IAAK,CAAClD,EAAce,IAA6BG,EAAOlB,EAAMe,GAC9DoC,aAAexJ,GACbwI,EAAcG,OAAO3I,GACvBmG,UAEJ","x_google_ignoreList":[1,2,3,4,5,7]}
@@ -0,0 +1,6 @@
1
+ import { Environment } from "../environment/environment";
2
+ export interface ClientIdManager {
3
+ clientId: string;
4
+ }
5
+ export declare function createClientIdManager(environment: Environment): ClientIdManager;
6
+ //# sourceMappingURL=client-id.d.ts.map
@@ -0,0 +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,QAAQ,EAAE,MAAM,CAAC;CAClB;AAeD,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,WAAW,GACvB,eAAe,CAIjB"}
@@ -0,0 +1,13 @@
1
+ export type RelayMode = "emit" | "validate";
2
+ export interface RelayConfig {
3
+ url: string;
4
+ token: string;
5
+ trackingId: string;
6
+ mode?: RelayMode;
7
+ }
8
+ export interface ConfigManager {
9
+ get: () => Readonly<RelayConfig>;
10
+ update: (updatedConfig: Partial<RelayConfig>) => void;
11
+ }
12
+ export declare function createConfigManager(initialConfig: RelayConfig): Readonly<ConfigManager>;
13
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +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,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,QAAQ,CAAC,WAAW,CAAC,CAAC;IACjC,MAAM,EAAE,CAAC,aAAa,EAAE,OAAO,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;CACvD;AAgBD,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,WAAW,GACzB,QAAQ,CAAC,aAAa,CAAC,CASzB"}
@@ -0,0 +1,3 @@
1
+ import { EventApiCallParams } from "../event-api-call/event-api-caller";
2
+ export declare function emit(params: EventApiCallParams): Promise<void>;
3
+ //# sourceMappingURL=emit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../../src/emit/emit.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EACnB,MAAM,oCAAoC,CAAC;AAE5C,wBAAsB,IAAI,CAAC,MAAM,EAAE,kBAAkB,iBAEpD"}
@@ -0,0 +1,3 @@
1
+ import { Environment } from "../environment";
2
+ export declare function buildBrowserEnvironment(): Environment;
3
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../../src/environment/browser/browser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAU7C,wBAAgB,uBAAuB,IAAI,WAAW,CAUrD"}
@@ -0,0 +1,7 @@
1
+ export interface CookieManager {
2
+ getItem: (key: string) => string | null;
3
+ removeItem: (key: string) => void;
4
+ setItem: (key: string, data: string, expire: number) => void;
5
+ }
6
+ export declare const cookieManager: CookieManager;
7
+ //# sourceMappingURL=cookie.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../../../../src/environment/browser/storage/cookie.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;IACxC,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9D;AAED,eAAO,MAAM,aAAa,EAAE,aAAqC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Storage } from "../../storage";
2
+ export declare function createBrowserStorage(): Storage;
3
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../../../src/environment/browser/storage/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAGxC,wBAAgB,oBAAoB,IAAI,OAAO,CAiB9C"}
@@ -0,0 +1,12 @@
1
+ import { Storage } from "./storage";
2
+ export interface Environment {
3
+ runtime: "browser" | "node";
4
+ fetch: (url: string, init?: RequestInit) => Promise<Response>;
5
+ getReferrerUrl: () => string | null;
6
+ getUrl: () => string | null;
7
+ getUserAgent: () => string | null;
8
+ generateUUID: () => string;
9
+ storage: Storage;
10
+ }
11
+ export declare function currentEnvironment(): Environment;
12
+ //# sourceMappingURL=environment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../../src/environment/environment.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,SAAS,GAAG,MAAM,CAAC;IAC5B,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9D,cAAc,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACpC,MAAM,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAC5B,YAAY,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAClC,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,kBAAkB,IAAI,WAAW,CAEhD"}
@@ -0,0 +1,3 @@
1
+ import { Environment } from "../environment";
2
+ export declare function buildNodeEnvironment(): Environment;
3
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../../src/environment/node/node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI7C,wBAAgB,oBAAoB,IAAI,WAAW,CAUlD"}
@@ -0,0 +1,7 @@
1
+ export interface Storage {
2
+ getItem: (key: string) => string | null;
3
+ removeItem: (key: string) => void;
4
+ setItem: (key: string, data: string) => void;
5
+ }
6
+ export declare function createNullStorage(): Storage;
7
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/environment/storage.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;IACxC,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9C;AAED,wBAAgB,iBAAiB,IAAI,OAAO,CAY3C"}
@@ -0,0 +1,2 @@
1
+ export declare function fetchAPI(url: string, init?: RequestInit): Promise<Response>;
2
+ //# sourceMappingURL=fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/environment/utils/fetch.ts"],"names":[],"mappings":"AAAA,wBAAsB,QAAQ,CAC5B,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,WAAW,GACjB,OAAO,CAAC,QAAQ,CAAC,CAOnB"}
@@ -0,0 +1,19 @@
1
+ import { ClientIdManager } from "../../client-id/client-id";
2
+ import { Environment } from "../../environment/environment";
3
+ import { RelayConfig } from "../../config/config";
4
+ interface EventConfig {
5
+ trackingId: string;
6
+ }
7
+ export interface Meta {
8
+ type: string;
9
+ config: EventConfig;
10
+ ts: number;
11
+ source: string;
12
+ clientId: string;
13
+ userAgent: string | null;
14
+ referrerUrl: string | null;
15
+ url: string | null;
16
+ }
17
+ export declare function createMeta(type: string, config: RelayConfig, environment: Environment, clientIdManager: ClientIdManager): Readonly<Meta>;
18
+ export {};
19
+ //# sourceMappingURL=meta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../../../../src/event/meta/meta.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD,UAAU,WAAW;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AAWD,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,WAAW,EACnB,WAAW,EAAE,WAAW,EACxB,eAAe,EAAE,eAAe,GAC/B,QAAQ,CAAC,IAAI,CAAC,CAehB"}
@@ -0,0 +1,9 @@
1
+ import { ClientIdManager } from "../client-id/client-id";
2
+ import { Environment } from "../environment/environment";
3
+ import { RelayConfig, RelayPayload } from "../relay";
4
+ import { Meta } from "./meta/meta";
5
+ export interface RelayEvent extends RelayPayload {
6
+ meta: Readonly<Meta>;
7
+ }
8
+ export declare function createRelayEvent(type: string, payload: RelayPayload, config: RelayConfig, environment: Environment, clientIdManager: ClientIdManager): Readonly<RelayEvent>;
9
+ //# sourceMappingURL=relay-event.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relay-event.d.ts","sourceRoot":"","sources":["../../../src/event/relay-event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAc,IAAI,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,WAAW,UAAW,SAAQ,YAAY;IAC9C,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"}
@@ -0,0 +1,10 @@
1
+ import { Environment } from "../environment/environment";
2
+ import { RelayEvent } from "../event/relay-event";
3
+ import { RelayConfig } from "../config/config";
4
+ export interface EventApiCallParams {
5
+ config: RelayConfig;
6
+ environment: Environment;
7
+ event: Readonly<RelayEvent>;
8
+ }
9
+ export declare function callEventApi({ event, config, environment, }: EventApiCallParams): Promise<any>;
10
+ //# sourceMappingURL=event-api-caller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-api-caller.d.ts","sourceRoot":"","sources":["../../../src/event-api-call/event-api-caller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,WAAW,CAAC;IACpB,WAAW,EAAE,WAAW,CAAC;IACzB,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;CAC7B;AAED,wBAAsB,YAAY,CAAC,EACjC,KAAK,EACL,MAAM,EACN,WAAW,GACZ,EAAE,kBAAkB,GAAG,OAAO,CAAC,GAAG,CAAC,CAwBnC"}
@@ -0,0 +1,14 @@
1
+ import { RelayEvent } from "../event/relay-event";
2
+ export type EventCallback = (event: RelayEvent) => void;
3
+ interface Listener {
4
+ type: string;
5
+ callback: EventCallback;
6
+ }
7
+ interface ListenerManager {
8
+ add: (listener: Listener) => () => void;
9
+ call: (event: RelayEvent) => void;
10
+ remove: (type: string, callback?: EventCallback) => void;
11
+ }
12
+ export declare function createListenerManager(): ListenerManager;
13
+ export {};
14
+ //# sourceMappingURL=listener.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../../src/listener/listener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIlD,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;AAExD,UAAU,QAAQ;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,aAAa,CAAC;CACzB;AAED,UAAU,eAAe;IACvB,GAAG,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,MAAM,IAAI,CAAC;IACxC,IAAI,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IAClC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;CAC1D;AAED,wBAAgB,qBAAqB,IAAI,eAAe,CA4DvD"}
@@ -0,0 +1,17 @@
1
+ import { Meta } from "./event/meta/meta";
2
+ import { EventCallback } from "./listener/listener";
3
+ import { RelayConfig } from "./config/config";
4
+ import { ValidationError, ValidationResponse } from "./validate/validate";
5
+ type RelayPayload = Record<string, unknown>;
6
+ type Off = () => void;
7
+ interface Relay {
8
+ emit: (type: string, payload: RelayPayload) => Promise<void | ValidationResponse>;
9
+ getMeta: (type: string) => Meta;
10
+ on: (type: string, callback: EventCallback) => Off;
11
+ off: (type: string, callback?: EventCallback) => void;
12
+ updateConfig: (config: Partial<RelayConfig>) => void;
13
+ version: string;
14
+ }
15
+ export declare function createRelay(initialConfig: RelayConfig): Relay;
16
+ export type { RelayPayload, RelayConfig, ValidationError, ValidationResponse };
17
+ //# sourceMappingURL=relay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relay.d.ts","sourceRoot":"","sources":["../../src/relay.ts"],"names":[],"mappings":"AAKA,OAAO,EAAc,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAyB,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAuB,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAEL,eAAe,EACf,kBAAkB,EACnB,MAAM,qBAAqB,CAAC;AAE7B,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC5C,KAAK,GAAG,GAAG,MAAM,IAAI,CAAC;AAEtB,UAAU,KAAK;IACb,IAAI,EAAE,CACJ,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,YAAY,KAClB,OAAO,CAAC,IAAI,GAAG,kBAAkB,CAAC,CAAC;IACxC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,EAAE,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,KAAK,GAAG,CAAC;IACnD,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IACtD,YAAY,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;IACrD,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,WAAW,CAAC,aAAa,EAAE,WAAW,GAAG,KAAK,CAgC7D;AAED,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,kBAAkB,EAAE,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { EventApiCallParams } from "../event-api-call/event-api-caller";
2
+ export interface ValidationError {
3
+ type: string;
4
+ message: string;
5
+ path: string;
6
+ }
7
+ export interface ValidationResponse {
8
+ valid: boolean;
9
+ errors: ValidationError[];
10
+ }
11
+ export declare function validate(params: EventApiCallParams): Promise<Readonly<ValidationResponse>>;
12
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../src/validate/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EACnB,MAAM,oCAAoC,CAAC;AAE5C,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,eAAe,EAAE,CAAC;CAC3B;AAED,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,CAMvC"}
@@ -0,0 +1,2 @@
1
+ export declare const version: string;
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,EAAE,MAAkC,CAAC"}
package/lib/relay.cjs CHANGED
@@ -213,7 +213,7 @@ function isBrowser() {
213
213
  }
214
214
  }
215
215
 
216
- const version = "0.4.2" ;
216
+ const version = "0.4.3" ;
217
217
 
218
218
  function getEventConfig(config) {
219
219
  const { trackingId } = config;
package/lib/relay.js CHANGED
@@ -217,7 +217,7 @@ function isBrowser() {
217
217
  }
218
218
  }
219
219
 
220
- const version = "0.4.2" ;
220
+ const version = "0.4.3" ;
221
221
 
222
222
  function getEventConfig(config) {
223
223
  const { trackingId } = config;
package/lib/relay.mjs CHANGED
@@ -211,7 +211,7 @@ function isBrowser() {
211
211
  }
212
212
  }
213
213
 
214
- const version = "0.4.2" ;
214
+ const version = "0.4.3" ;
215
215
 
216
216
  function getEventConfig(config) {
217
217
  const { trackingId } = config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coveo/relay",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "A library for sending analytics events using Coveo's Event protocol.",
5
5
  "files": [
6
6
  "lib/**/*"
@@ -40,6 +40,7 @@
40
40
  "devDependencies": {
41
41
  "@rollup/plugin-node-resolve": "^15.2.1",
42
42
  "@rollup/plugin-replace": "^5.0.2",
43
+ "@rollup/plugin-terser": "^0.4.3",
43
44
  "@rollup/plugin-typescript": "^11.1.2",
44
45
  "@types/jest": "^29.5.3",
45
46
  "@types/uuid": "^9.0.2",