umami/scripts/seed/generators/sessions.ts
conorbranagan 80987f8548
Merge upstream umami v3.0.3 into master
Sync fork with latest upstream changes from umami-software/umami.
Resolves conflicts while preserving niteshift customizations:
- Dials SDK integration for runtime design prototyping
- Typography context for website metrics
- Overview Alt page with Sparkles icon
- Login redirect to /websites
- React Query cache seeding on login
- Node.js 20 LTS recommendation in README
2025-12-19 15:30:39 -05:00

52 lines
1.3 KiB
TypeScript

import { getRandomDevice } from '../distributions/devices.js';
import { getRandomGeo, getRandomLanguage } from '../distributions/geographic.js';
import { generateTimestampForDay } from '../distributions/temporal.js';
import { uuid } from '../utils.js';
export interface SessionData {
id: string;
websiteId: string;
browser: string;
os: string;
device: string;
screen: string;
language: string;
country: string;
region: string;
city: string;
createdAt: Date;
}
export function createSession(websiteId: string, day: Date): SessionData {
const deviceInfo = getRandomDevice();
const geo = getRandomGeo();
const language = getRandomLanguage();
const createdAt = generateTimestampForDay(day);
return {
id: uuid(),
websiteId,
browser: deviceInfo.browser,
os: deviceInfo.os,
device: deviceInfo.device,
screen: deviceInfo.screen,
language,
country: geo.country,
region: geo.region,
city: geo.city,
createdAt,
};
}
export function createSessions(websiteId: string, day: Date, count: number): SessionData[] {
const sessions: SessionData[] = [];
for (let i = 0; i < count; i++) {
sessions.push(createSession(websiteId, day));
}
// Sort by createdAt to maintain chronological order
sessions.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
return sessions;
}