@blotoutio/edgetag-sdk-js
Advanced tools
Comparing version 0.52.0 to 0.52.1
157
index.cjs.js
@@ -278,2 +278,3 @@ 'use strict'; | ||
const keyPrefix = `_worker`; | ||
const cookieKey = 'tag_user_id'; | ||
@@ -424,4 +425,76 @@ const getMessage = (error) => { | ||
const encodeString = (name) => { | ||
if (typeof btoa === 'undefined') { | ||
return Buffer.from(name).toString('base64'); | ||
} | ||
return btoa(name); | ||
}; | ||
const getBasicRandomNumber = () => { | ||
return parseInt((Math.random() * 10000000000).toString(), 10); | ||
}; | ||
const generateUUID = () => { | ||
let id = ''; | ||
try { | ||
id = crypto.randomUUID(); | ||
if (!id) { | ||
const array = new Uint32Array(20); | ||
const numbers = crypto.getRandomValues(array); | ||
for (let i = 0; i < 5; i++) { | ||
const y = i * 3; | ||
if (i !== 0) { | ||
id += '-'; | ||
} | ||
const sum = numbers[y + 1] + numbers[y + 2] + numbers[y + 3]; | ||
id += sum.toString(); | ||
} | ||
} | ||
} | ||
catch { | ||
id = `${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}`; | ||
console.log('[EdgeTag] Crypto module not found'); | ||
} | ||
return id; | ||
}; | ||
const generateEventId = (name) => { | ||
let time = Date.now().toString(); | ||
if (typeof performance !== 'undefined' && | ||
typeof performance.now === 'function') { | ||
const perf = performance.now(); | ||
if (perf) { | ||
time = perf.toFixed(4); | ||
} | ||
} | ||
return `${encodeString(name)}-${generateUUID()}-${time}`; | ||
}; | ||
const getCookieValue = (key) => { | ||
try { | ||
if (!document || !document.cookie) { | ||
return ''; | ||
} | ||
const name = `${key}=`; | ||
const decodedCookie = decodeURIComponent(document.cookie); | ||
const ca = decodedCookie.split(';'); | ||
for (let i = 0; i < ca.length; i++) { | ||
let c = ca[i]; | ||
while (c.charAt(0) === ' ') { | ||
c = c.substring(1); | ||
} | ||
if (c.indexOf(name) === 0) { | ||
return c.substring(name.length, c.length); | ||
} | ||
} | ||
return ''; | ||
} | ||
catch { | ||
return ''; | ||
} | ||
}; | ||
const getUserId$1 = (destination) => { | ||
return getSetting(destination, 'userId'); | ||
const userId = getSetting(destination, 'userId'); | ||
if (userId) { | ||
return userId; | ||
} | ||
return getCookieValue(cookieKey); | ||
}; | ||
@@ -435,3 +508,3 @@ const handleGetUserId = (options) => { | ||
error('Multiple instances detected! Please provide a destination.'); | ||
return null; | ||
return ''; | ||
} | ||
@@ -480,3 +553,3 @@ return getUserId$1(instances[0]); | ||
locale: getLocale(), | ||
sdkVersion: "0.52.0" , | ||
sdkVersion: "0.52.1" , | ||
...(payload || {}), | ||
@@ -608,70 +681,2 @@ }; | ||
const encodeString = (name) => { | ||
if (typeof btoa === 'undefined') { | ||
return Buffer.from(name).toString('base64'); | ||
} | ||
return btoa(name); | ||
}; | ||
const getBasicRandomNumber = () => { | ||
return parseInt((Math.random() * 10000000000).toString(), 10); | ||
}; | ||
const generateUUID = () => { | ||
let id = ''; | ||
try { | ||
id = crypto.randomUUID(); | ||
if (!id) { | ||
const array = new Uint32Array(20); | ||
const numbers = crypto.getRandomValues(array); | ||
for (let i = 0; i < 5; i++) { | ||
const y = i * 3; | ||
if (i !== 0) { | ||
id += '-'; | ||
} | ||
const sum = numbers[y + 1] + numbers[y + 2] + numbers[y + 3]; | ||
id += sum.toString(); | ||
} | ||
} | ||
} | ||
catch { | ||
id = `${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}`; | ||
console.log('[EdgeTag] Crypto module not found'); | ||
} | ||
return id; | ||
}; | ||
const generateEventId = (name) => { | ||
let time = Date.now().toString(); | ||
if (typeof performance !== 'undefined' && | ||
typeof performance.now === 'function') { | ||
const perf = performance.now(); | ||
if (perf) { | ||
time = perf.toFixed(4); | ||
} | ||
} | ||
return `${encodeString(name)}-${generateUUID()}-${time}`; | ||
}; | ||
const getCookieValue = (key) => { | ||
try { | ||
if (!document || !document.cookie) { | ||
return ''; | ||
} | ||
const name = `${key}=`; | ||
const decodedCookie = decodeURIComponent(document.cookie); | ||
const ca = decodedCookie.split(';'); | ||
for (let i = 0; i < ca.length; i++) { | ||
let c = ca[i]; | ||
while (c.charAt(0) === ' ') { | ||
c = c.substring(1); | ||
} | ||
if (c.indexOf(name) === 0) { | ||
return c.substring(name.length, c.length); | ||
} | ||
} | ||
return ''; | ||
} | ||
catch { | ||
return ''; | ||
} | ||
}; | ||
const getConsent$1 = (destination) => { | ||
@@ -736,3 +741,3 @@ const storageConsent = getDataPerKey(destination, 'local', tagStorage, consentKey); | ||
const consent = getConsent$1(destination); | ||
for (const pkg of Object.values(providerPackages)) { | ||
for (const pkg of providerPackages) { | ||
if (!pkg || !pkg.name || !pkg.tag) { | ||
@@ -833,3 +838,3 @@ continue; | ||
const consent = getConsent$1(destination); | ||
for (const pkg of Object.values(providerPackages)) { | ||
for (const pkg of providerPackages) { | ||
if (!pkg || !pkg.user || !pkg.name) { | ||
@@ -906,3 +911,3 @@ continue; | ||
/* Calling Init for all provider instances based on consent check */ | ||
for (const pkg of Object.values(providerPackages)) { | ||
for (const pkg of providerPackages) { | ||
if (!pkg || !pkg.name || !pkg.init) { | ||
@@ -1072,3 +1077,3 @@ continue; | ||
addChannel(destination, provider.package, provider.tagName); | ||
const pkg = providerPackages[provider.package]; | ||
const pkg = providerPackages.find((pkg) => pkg.name === provider.package); | ||
if (provider.rules) { | ||
@@ -1168,3 +1173,3 @@ Object.entries(provider.rules).forEach(([name, recipe]) => { | ||
const userId = getUserId$1(destination); | ||
for (const pkg of Object.values(providerPackages)) { | ||
for (const pkg of providerPackages) { | ||
if (!pkg || !pkg.name || !pkg.user) { | ||
@@ -1171,0 +1176,0 @@ continue; |
{ | ||
"name": "@blotoutio/edgetag-sdk-js", | ||
"version": "0.52.0", | ||
"version": "0.52.1", | ||
"description": "JS SDK for EdgeTag", | ||
@@ -5,0 +5,0 @@ "author": "Blotout", |
Sorry, the diff of this file is not supported yet
88647
2736