@blotoutio/edgetag-sdk-js
Advanced tools
Comparing version 0.6.4 to 0.6.5
// TODO this all located in '@blotoutio/shared/utility-sdk' | ||
type PersistType = 'local' | 'session' | ||
type PersistType = 'local' | 'session' | 'edge' | ||
@@ -5,0 +5,0 @@ type EventOptions = { |
124
index.esm.js
@@ -103,20 +103,52 @@ import { v4 } from 'uuid'; | ||
const saveLocal = (value, key) => { | ||
localStorage.setItem(key, JSON.stringify(value)); | ||
try { | ||
if (!localStorage) { | ||
return; | ||
} | ||
localStorage.setItem(key, JSON.stringify(value)); | ||
} | ||
catch (_a) { | ||
console.log('Local storage not supported'); | ||
} | ||
}; | ||
const getLocal = (key) => { | ||
const data = localStorage.getItem(key); | ||
if (!data) { | ||
try { | ||
if (!localStorage) { | ||
return {}; | ||
} | ||
const data = localStorage.getItem(key); | ||
if (!data) { | ||
return {}; | ||
} | ||
return JSON.parse(data) || {}; | ||
} | ||
catch (_a) { | ||
return {}; | ||
} | ||
return JSON.parse(data) || {}; | ||
}; | ||
const saveSession = (value, key) => { | ||
sessionStorage.setItem(key, JSON.stringify(value)); | ||
try { | ||
if (!sessionStorage) { | ||
return; | ||
} | ||
sessionStorage.setItem(key, JSON.stringify(value)); | ||
} | ||
catch (_a) { | ||
console.log('Session storage not supported'); | ||
} | ||
}; | ||
const getSession = (key) => { | ||
const data = sessionStorage.getItem(key); | ||
if (!data) { | ||
try { | ||
if (!sessionStorage) { | ||
return {}; | ||
} | ||
const data = sessionStorage.getItem(key); | ||
if (!data) { | ||
return {}; | ||
} | ||
return JSON.parse(data) || {}; | ||
} | ||
catch (_a) { | ||
return {}; | ||
} | ||
return JSON.parse(data) || {}; | ||
}; | ||
@@ -385,17 +417,15 @@ | ||
Object.values(providerPackages).forEach((pkg) => { | ||
if (!allowProvider(providers, pkg.name)) { | ||
if (!pkg || !pkg.tag || !allowProvider(providers, pkg.name)) { | ||
return; | ||
} | ||
if (pkg && pkg.tag) { | ||
const result = pkg.tag({ | ||
userId, | ||
eventName, | ||
eventId, | ||
data, | ||
sendTag, | ||
manifestVariables: getProviderVariables(pkg.name), | ||
}); | ||
if (result) { | ||
providerData[pkg.name] = result; | ||
} | ||
const result = pkg.tag({ | ||
userId, | ||
eventName, | ||
eventId, | ||
data, | ||
sendTag, | ||
manifestVariables: getProviderVariables(pkg.name), | ||
}); | ||
if (result) { | ||
providerData[pkg.name] = result; | ||
} | ||
@@ -414,2 +444,26 @@ }); | ||
const handleData = (data, options) => { | ||
if (!data || Object.keys(data).length === 0) { | ||
console.error('Provide data for data API.'); | ||
return; | ||
} | ||
saveKV(data); | ||
postRequest(getDataURL(), { data }, options).catch(info); | ||
}; | ||
const saveDataToEdge = (key, value, provider) => { | ||
if (!value) { | ||
return; | ||
} | ||
if (typeof value !== 'string') { | ||
try { | ||
value = JSON.stringify(value); | ||
} | ||
catch (_a) { | ||
console.log('Error stringify value'); | ||
return; | ||
} | ||
} | ||
handleData({ [`${provider}::${key}`]: value }); | ||
}; | ||
const handleCaptureQuery = (provider, key, persistType) => { | ||
@@ -423,3 +477,11 @@ if (!window) { | ||
} | ||
saveDataPerKey(persistType, provider, params.get(key), key); | ||
const data = params.get(key); | ||
if (!data) { | ||
return; | ||
} | ||
if (persistType === 'edge') { | ||
saveDataToEdge(key, data, provider); | ||
return; | ||
} | ||
saveDataPerKey(persistType, provider, data, key); | ||
}; | ||
@@ -434,8 +496,7 @@ const handleCaptureStorage = (provider, key, persistType, location) => { | ||
case 'local': { | ||
data = sessionStorage && sessionStorage.getItem(key); | ||
data = getData$1('local', key); | ||
break; | ||
} | ||
case 'session': { | ||
data = localStorage && localStorage.getItem(key); | ||
break; | ||
data = getData$1('session', key); | ||
} | ||
@@ -446,2 +507,6 @@ } | ||
} | ||
if (persistType === 'edge') { | ||
saveDataToEdge(key, data, provider); | ||
return; | ||
} | ||
saveDataPerKey(persistType, provider, data, key); | ||
@@ -529,11 +594,2 @@ }; | ||
const handleData = (data, options) => { | ||
if (!data || Object.keys(data).length === 0) { | ||
console.error('Provide data for data API.'); | ||
return; | ||
} | ||
saveKV(data); | ||
postRequest(getDataURL(), { data }, options).catch(info); | ||
}; | ||
const handleGetData = (keys, callback) => { | ||
@@ -540,0 +596,0 @@ if (!keys || keys.length === 0) { |
{ | ||
"name": "@blotoutio/edgetag-sdk-js", | ||
"version": "0.6.4", | ||
"version": "0.6.5", | ||
"description": "JS SDK for EdgeTag", | ||
@@ -11,5 +11,5 @@ "author": "Blotout", | ||
}, | ||
"main": "./index.esm.js", | ||
"peerDependencies": { | ||
"uuid": "*" | ||
"main": "./index.cjs", | ||
"dependencies": { | ||
"uuid": "^9.0.0" | ||
}, | ||
@@ -16,0 +16,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
39058
1332
+ Addeduuid@^9.0.0
+ Addeduuid@9.0.1(transitive)
- Removeduuid@11.0.5(transitive)