use new session id format

This commit is contained in:
goenning 2023-11-03 21:21:28 +00:00
parent 53f0f40aa1
commit e6b234dca5
4 changed files with 10 additions and 19 deletions

View file

@ -1,3 +1,7 @@
## 0.3.1
- use new session id format
## 0.3.0 ## 0.3.0
- Added an option to specify `isDebug` at init time - Added an option to specify `isDebug` at init time

View file

@ -1,6 +1,6 @@
{ {
"name": "@aptabase/web", "name": "@aptabase/web",
"version": "0.3.0", "version": "0.3.1",
"type": "module", "type": "module",
"description": "JavaScript SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps", "description": "JavaScript SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps",
"main": "./dist/index.cjs", "main": "./dist/index.cjs",

View file

@ -1,18 +1,5 @@
export function newSessionId() { export function newSessionId(): string {
if (typeof crypto !== 'undefined' && crypto && crypto.randomUUID) { const epochInSeconds = BigInt(Math.floor(Date.now() / 1000));
return crypto.randomUUID(); const random = BigInt(Math.floor(Math.random() * 100000000));
} return (epochInSeconds * 100000000n + random).toString();
return [randomStr(8), randomStr(4), randomStr(4), randomStr(4), randomStr(12)].join('-');
}
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
function randomStr(len: number) {
let result = '';
for (let i = 0; i < len; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
} }

View file

@ -1,6 +1,6 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es6", "target": "es2020",
"strict": true, "strict": true,
"moduleResolution": "node", "moduleResolution": "node",
"esModuleInterop": true, "esModuleInterop": true,