use new session id format
This commit is contained in:
parent
53f0f40aa1
commit
e6b234dca5
4 changed files with 10 additions and 19 deletions
|
@ -1,3 +1,7 @@
|
|||
## 0.3.1
|
||||
|
||||
- use new session id format
|
||||
|
||||
## 0.3.0
|
||||
|
||||
- Added an option to specify `isDebug` at init time
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@aptabase/web",
|
||||
"version": "0.3.0",
|
||||
"version": "0.3.1",
|
||||
"type": "module",
|
||||
"description": "JavaScript SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps",
|
||||
"main": "./dist/index.cjs",
|
||||
|
|
|
@ -1,18 +1,5 @@
|
|||
export function newSessionId() {
|
||||
if (typeof crypto !== 'undefined' && crypto && crypto.randomUUID) {
|
||||
return crypto.randomUUID();
|
||||
}
|
||||
|
||||
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;
|
||||
export function newSessionId(): string {
|
||||
const epochInSeconds = BigInt(Math.floor(Date.now() / 1000));
|
||||
const random = BigInt(Math.floor(Math.random() * 100000000));
|
||||
return (epochInSeconds * 100000000n + random).toString();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"target": "es2020",
|
||||
"strict": true,
|
||||
"moduleResolution": "node",
|
||||
"esModuleInterop": true,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue