@stltio/stealth
Advanced tools
Comparing version 0.1.4 to 0.2.0
52
index.js
@@ -1,2 +0,2 @@ | ||
// import axios from 'axios' | ||
import axios from 'axios' | ||
import jsSHA from 'jssha' | ||
@@ -15,3 +15,3 @@ | ||
export default async function stealth() { | ||
export default async function stealth({ apiKey }) { | ||
let start = window.performance.now() | ||
@@ -53,11 +53,45 @@ return Promise.all([ | ||
return { | ||
id: new jsSHA('SHA-256', 'TEXT', { encoding: 'UTF8' }) | ||
.update(JSON.stringify(local)) | ||
.getHash('HEX'), | ||
local, | ||
ms: parseInt(window.performance.now() - start), | ||
remote: {} | ||
const payload = { | ||
local: { | ||
...local, | ||
hash: new jsSHA('SHA-256', 'TEXT', { encoding: 'UTF8' }) | ||
.update(JSON.stringify(local)) | ||
.getHash('HEX') | ||
} | ||
} | ||
// If apiKey is provided, send the payload to the server (more accurate results) | ||
// Want an API_KEY? Contact us at hello@stlt.io | ||
if (apiKey) { | ||
const axiosInstance = axios.create() | ||
axiosInstance.defaults.withCredentials = true | ||
axiosInstance.defaults.headers.common['x-api-key'] = apiKey | ||
return axiosInstance | ||
.get(`https://api.stlt.io/${payload.local.hash}`) | ||
.then((response) => { | ||
return { | ||
visitorId: response.data.visitorId, | ||
local: payload.local, | ||
ms: parseInt(window.performance.now() - start), | ||
remote: response.data | ||
} | ||
}) | ||
.catch((error) => { | ||
console.log(error.message) | ||
return { | ||
visitorId: payload.local.hash, | ||
local: payload.local, | ||
ms: parseInt(window.performance.now() - start), | ||
remote: {} | ||
} | ||
}) | ||
} else { | ||
return { | ||
visitorId: payload.local.hash, | ||
local: payload.local, | ||
ms: parseInt(window.performance.now() - start), | ||
remote: {} | ||
} | ||
} | ||
}) | ||
} |
{ | ||
"name": "@stltio/stealth", | ||
"version": "0.1.4", | ||
"version": "0.2.0", | ||
"description": "", | ||
@@ -34,3 +34,3 @@ "main": "index", | ||
"author": "Stlt.io", | ||
"license": "ISC", | ||
"license": "MIT", | ||
"dependencies": { | ||
@@ -37,0 +37,0 @@ "axios": "^1.6.8", |
@@ -15,3 +15,3 @@ # Stlt - Stealth | ||
remote: {}, | ||
id: 'abc...xyz', | ||
visitorId: 'abc...xyz', | ||
ms: 491 | ||
@@ -26,3 +26,3 @@ } = result | ||
const [data, setData] = useState({ local: {}, remote: {}, id: '', ms: 0 }) | ||
const [data, setData] = useState({ local: {}, remote: {}, visitorId: '', ms: 0 }) | ||
@@ -29,0 +29,0 @@ useEffect(() => { |
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
89346
0
4092