overcentric
Version:
A lightweight, privacy-focused toolkit for modern SaaS web applications
32 lines (31 loc) • 1.02 kB
JavaScript
import { v4 as uuidv4 } from 'uuid';
const isBrowser = () => typeof window !== 'undefined';
export function generateUuid() {
return uuidv4();
}
export function storeDeviceId(deviceId) {
if (!isBrowser())
return;
try {
const domain = window.location.hostname.split('.').slice(-2).join('.');
document.cookie = `overcentric_device_id=${deviceId}; domain=.${domain}; path=/; max-age=31536000; SameSite=Strict; Secure`;
}
catch (e) {
console.warn('Failed to store device ID:', e);
}
}
export function getDeviceId() {
var _a, _b;
if (!isBrowser())
return null;
try {
const deviceId = (_b = (_a = document.cookie
.split('; ')
.find(row => row.startsWith('overcentric_device_id='))) === null || _a === void 0 ? void 0 : _a.split('=')) === null || _b === void 0 ? void 0 : _b[1];
return deviceId || null;
}
catch (e) {
console.warn('Failed to get device ID:', e);
return null;
}
}