better-auth-studio 1.1.3-beta.53 → 1.1.3-beta.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -443,15 +443,24 @@ function generateRandomIP() {
443
443
  const fourthOctet = Math.floor(Math.random() * 255) + 1;
444
444
  return `${range.min.split(".")[0]}.${secondOctet}.${thirdOctet}.${fourthOctet}`;
445
445
  }
446
+ const SESSION_SEED_USER_AGENTS = [
447
+ "Mozilla/5.0 (iPhone; CPU iPhone OS 18_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Mobile/15E148 Safari/604.1",
448
+ "Mozilla/5.0 (Linux; Android 15; Pixel 9 Pro Build/AP3A.241205.015) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Mobile Safari/537.36",
449
+ "Mozilla/5.0 (iPad; CPU OS 18_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Mobile/15E148 Safari/604.1",
450
+ "Mozilla/5.0 (Linux; Android 14; SM-X910 Build/UP1A.231005.007) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36",
451
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0",
452
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36",
453
+ ];
446
454
  export async function createMockSession(adapter, userId, index) {
447
455
  // Generate a random IP address
448
456
  const ipAddress = generateRandomIP();
457
+ const userAgent = SESSION_SEED_USER_AGENTS[(index - 1) % SESSION_SEED_USER_AGENTS.length];
449
458
  const sessionData = {
450
459
  userId: userId,
451
460
  expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000), // 7 days from now
452
461
  token: `session_token_${index}_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`,
453
462
  ipAddress: ipAddress,
454
- userAgent: `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36`,
463
+ userAgent,
455
464
  createdAt: new Date(),
456
465
  updatedAt: new Date(),
457
466
  };
package/dist/data.d.ts CHANGED
@@ -13,10 +13,17 @@ export interface User {
13
13
  export interface Session {
14
14
  id: string;
15
15
  userId: string;
16
- expires: Date;
17
- createdAt: Date;
18
- userAgent?: string;
16
+ token?: string;
17
+ expiresAt?: Date | string;
18
+ expires?: Date | string;
19
+ createdAt: Date | string;
20
+ updatedAt?: Date | string;
21
+ userAgent?: string | null;
22
+ ipAddress?: string | null;
19
23
  ip?: string;
24
+ activeOrganizationId?: string;
25
+ activeTeamId?: string;
26
+ [key: string]: unknown;
20
27
  }
21
28
  export interface AuthStats {
22
29
  totalUsers: number;
package/dist/data.js CHANGED
@@ -126,17 +126,36 @@ async function getRealUsers(adapter, options) {
126
126
  async function getRealSessions(adapter, options) {
127
127
  const { page, limit } = options;
128
128
  try {
129
- if (adapter.getSessions) {
130
- const allSessions = await adapter.getSessions();
129
+ let allSessions = null;
130
+ let getSessionsError;
131
+ if (typeof adapter?.getSessions === "function") {
132
+ try {
133
+ const result = await adapter.getSessions();
134
+ if (Array.isArray(result)) {
135
+ allSessions = result;
136
+ }
137
+ }
138
+ catch (error) {
139
+ getSessionsError = error;
140
+ }
141
+ }
142
+ if (allSessions === null && typeof adapter?.findMany === "function") {
143
+ allSessions = await adapter.findMany({ model: "session", limit: 100000 });
144
+ }
145
+ if (allSessions === null && getSessionsError) {
146
+ throw getSessionsError;
147
+ }
148
+ if (Array.isArray(allSessions)) {
149
+ const normalizedSessions = allSessions.map(normalizeSession);
131
150
  const startIndex = (page - 1) * limit;
132
151
  const endIndex = startIndex + limit;
133
- const paginatedSessions = allSessions.slice(startIndex, endIndex);
152
+ const paginatedSessions = normalizedSessions.slice(startIndex, endIndex);
134
153
  return {
135
154
  data: paginatedSessions,
136
- total: allSessions.length,
155
+ total: normalizedSessions.length,
137
156
  page,
138
157
  limit,
139
- totalPages: Math.ceil(allSessions.length / limit),
158
+ totalPages: Math.ceil(normalizedSessions.length / limit),
140
159
  };
141
160
  }
142
161
  return {
@@ -151,6 +170,22 @@ async function getRealSessions(adapter, options) {
151
170
  throw new Error(`Failed to get auth data: ${_error}`);
152
171
  }
153
172
  }
173
+ function normalizeSession(rawSession) {
174
+ const session = rawSession && typeof rawSession === "object" ? rawSession : {};
175
+ return {
176
+ ...session,
177
+ id: session.id ?? session.session_id,
178
+ userId: session.userId ?? session.user_id,
179
+ token: session.token ?? session.session_token,
180
+ expiresAt: session.expiresAt ?? session.expires_at ?? session.expires,
181
+ createdAt: session.createdAt ?? session.created_at,
182
+ updatedAt: session.updatedAt ?? session.updated_at,
183
+ userAgent: session.userAgent ?? session.user_agent,
184
+ ipAddress: session.ipAddress ?? session.ip_address ?? session.ip,
185
+ activeOrganizationId: session.activeOrganizationId ?? session.active_organization_id ?? session.active_organization,
186
+ activeTeamId: session.activeTeamId ?? session.active_team_id ?? session.active_team,
187
+ };
188
+ }
154
189
  async function getRealProviderStats(_adapter) {
155
190
  try {
156
191
  return [