better-auth-studio 1.1.2-beta.2 → 1.1.2-beta.20
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.
- package/README.md +48 -78
- package/data/default-geo.json +1 -1
- package/dist/adapters/astro.d.ts +1 -1
- package/dist/adapters/astro.js +13 -13
- package/dist/adapters/elysia.d.ts +2 -2
- package/dist/adapters/elysia.js +13 -13
- package/dist/adapters/express.d.ts +2 -2
- package/dist/adapters/express.js +4 -4
- package/dist/adapters/hono.d.ts +2 -2
- package/dist/adapters/hono.js +12 -12
- package/dist/adapters/nextjs.d.ts +1 -1
- package/dist/adapters/nextjs.js +10 -10
- package/dist/adapters/nuxt.d.ts +1 -1
- package/dist/adapters/nuxt.js +22 -22
- package/dist/adapters/remix.d.ts +1 -1
- package/dist/adapters/remix.js +13 -13
- package/dist/adapters/solid-start.d.ts +1 -1
- package/dist/adapters/solid-start.js +13 -13
- package/dist/adapters/svelte-kit.d.ts +2 -2
- package/dist/adapters/svelte-kit.js +13 -13
- package/dist/adapters/tanstack-start.d.ts +1 -1
- package/dist/adapters/tanstack-start.js +13 -13
- package/dist/add-svelte-kit-env-modules.js +11 -11
- package/dist/auth-adapter.d.ts +1 -1
- package/dist/auth-adapter.js +96 -96
- package/dist/cli/commands/init.js +57 -57
- package/dist/cli.js +75 -75
- package/dist/config.d.ts +5 -5
- package/dist/config.js +37 -37
- package/dist/core/handler.d.ts +1 -1
- package/dist/core/handler.js +116 -115
- package/dist/core/handler.js.map +1 -1
- package/dist/data.d.ts +2 -2
- package/dist/data.js +60 -60
- package/dist/geo-service.js +78 -78
- package/dist/get-tsconfig-info.js +4 -4
- package/dist/index.d.ts +8 -8
- package/dist/index.js +6 -6
- package/dist/providers/events/helpers.d.ts +2 -2
- package/dist/providers/events/helpers.d.ts.map +1 -1
- package/dist/providers/events/helpers.js +178 -154
- package/dist/providers/events/helpers.js.map +1 -1
- package/dist/public/assets/{main-BDJUrMKx.js → main-BeCk6LUx.js} +133 -133
- package/dist/public/assets/main-w2bJSKlF.css +1 -0
- package/dist/public/index.html +2 -2
- package/dist/routes/api-router.d.ts +3 -1
- package/dist/routes/api-router.d.ts.map +1 -1
- package/dist/routes/api-router.js +3 -3
- package/dist/routes/api-router.js.map +1 -1
- package/dist/routes.d.ts +6 -4
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +1333 -1277
- package/dist/routes.js.map +1 -1
- package/dist/studio.d.ts +3 -3
- package/dist/studio.d.ts.map +1 -1
- package/dist/studio.js +64 -65
- package/dist/studio.js.map +1 -1
- package/dist/types/events.d.ts +8 -7
- package/dist/types/events.d.ts.map +1 -1
- package/dist/types/events.js +165 -165
- package/dist/types/events.js.map +1 -1
- package/dist/types/handler.d.ts +14 -4
- package/dist/types/handler.d.ts.map +1 -1
- package/dist/types/handler.js.map +1 -1
- package/dist/utils/auth-callbacks-injector.d.ts +2 -2
- package/dist/utils/auth-callbacks-injector.js +27 -27
- package/dist/utils/auth-callbacks-wrapper.d.ts +3 -3
- package/dist/utils/auth-callbacks-wrapper.js +117 -107
- package/dist/utils/database-detection.d.ts +1 -1
- package/dist/utils/database-detection.js +44 -44
- package/dist/utils/database-hook-injector.d.ts +3 -3
- package/dist/utils/database-hook-injector.js +135 -131
- package/dist/utils/email-otp-hooks-injector.d.ts +28 -12
- package/dist/utils/email-otp-hooks-injector.js +104 -97
- package/dist/utils/event-ingestion.d.ts +5 -5
- package/dist/utils/event-ingestion.d.ts.map +1 -1
- package/dist/utils/event-ingestion.js +32 -12
- package/dist/utils/event-ingestion.js.map +1 -1
- package/dist/utils/hook-injector.d.ts +2 -2
- package/dist/utils/hook-injector.js +199 -199
- package/dist/utils/html-injector.d.ts +11 -2
- package/dist/utils/html-injector.d.ts.map +1 -1
- package/dist/utils/html-injector.js +40 -39
- package/dist/utils/html-injector.js.map +1 -1
- package/dist/utils/org-hooks-injector.d.ts +3 -3
- package/dist/utils/org-hooks-injector.js +63 -63
- package/dist/utils/org-hooks-wrapper.d.ts +41 -35
- package/dist/utils/org-hooks-wrapper.js +778 -658
- package/dist/utils/organization-hooks-wrapper.d.ts +23 -17
- package/dist/utils/organization-hooks-wrapper.js +325 -277
- package/dist/utils/package-json.js +11 -11
- package/dist/utils/paths.js +1 -1
- package/dist/utils/server-init.d.ts +1 -1
- package/dist/utils/server-init.js +25 -25
- package/dist/utils/session.d.ts +0 -1
- package/dist/utils/session.d.ts.map +1 -1
- package/dist/utils/session.js +19 -12
- package/dist/utils/session.js.map +1 -1
- package/dist/utils.js +24 -24
- package/package.json +25 -24
- package/public/assets/{main-BDJUrMKx.js → main-BeCk6LUx.js} +133 -133
- package/public/assets/main-w2bJSKlF.css +1 -0
- package/public/index.html +2 -2
- package/scripts/download-geolite2.js +8 -8
- package/scripts/generate-default-db.js +324 -324
- package/scripts/postinstall.js +25 -25
- package/dist/public/assets/main-CBA9bZ-w.css +0 -1
- package/public/assets/main-CBA9bZ-w.css +0 -1
package/dist/data.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { getAuthAdapter } from
|
|
2
|
-
export async function getAuthData(_authConfig, type =
|
|
1
|
+
import { getAuthAdapter } from "./auth-adapter.js";
|
|
2
|
+
export async function getAuthData(_authConfig, type = "stats", options, configPath, preloadedAdapter) {
|
|
3
3
|
try {
|
|
4
4
|
// Use preloaded adapter if available (self-hosted mode), otherwise load from config
|
|
5
5
|
const adapter = preloadedAdapter || (await getAuthAdapter(configPath));
|
|
6
6
|
setTimeout(() => {
|
|
7
7
|
if (adapter === null) {
|
|
8
|
-
const githubUrl =
|
|
8
|
+
const githubUrl = "https://github.com/Kinfe123/better-auth-studio/issues";
|
|
9
9
|
console.log(`No adapter found. if you think this is an issue from our side. please file a github issue at \x1b]8;;${githubUrl}\x1b\\${githubUrl}\x1b]8;;\x1b\\`);
|
|
10
10
|
}
|
|
11
11
|
}, 2000);
|
|
12
12
|
switch (type) {
|
|
13
|
-
case
|
|
13
|
+
case "stats":
|
|
14
14
|
return await getRealStats(adapter);
|
|
15
|
-
case
|
|
15
|
+
case "users":
|
|
16
16
|
return await getRealUsers(adapter, options);
|
|
17
|
-
case
|
|
17
|
+
case "sessions":
|
|
18
18
|
return await getRealSessions(adapter, options);
|
|
19
|
-
case
|
|
19
|
+
case "providers":
|
|
20
20
|
return await getRealProviderStats(adapter);
|
|
21
|
-
case
|
|
21
|
+
case "deleteUser":
|
|
22
22
|
return await deleteRealUser(adapter, options.id);
|
|
23
|
-
case
|
|
23
|
+
case "updateUser":
|
|
24
24
|
return await updateRealUser(adapter, options.id, options.userData);
|
|
25
|
-
case
|
|
25
|
+
case "analytics":
|
|
26
26
|
return await getRealAnalytics(adapter, options);
|
|
27
27
|
default:
|
|
28
28
|
throw new Error(`Unknown data type: ${type}`);
|
|
@@ -37,8 +37,8 @@ async function getRealStats(adapter) {
|
|
|
37
37
|
let users = [];
|
|
38
38
|
let sessions = [];
|
|
39
39
|
if (adapter.findMany) {
|
|
40
|
-
users = await adapter.findMany({ model:
|
|
41
|
-
sessions = await adapter.findMany({ model:
|
|
40
|
+
users = await adapter.findMany({ model: "user", limit: 100000 }).catch(() => []);
|
|
41
|
+
sessions = await adapter.findMany({ model: "session", limit: 100000 }).catch(() => []);
|
|
42
42
|
}
|
|
43
43
|
else {
|
|
44
44
|
users = adapter.getUsers ? await adapter.getUsers() : [];
|
|
@@ -71,7 +71,7 @@ async function getRealStats(adapter) {
|
|
|
71
71
|
.slice(0, 5)
|
|
72
72
|
.map((user) => ({
|
|
73
73
|
...user,
|
|
74
|
-
provider:
|
|
74
|
+
provider: "email",
|
|
75
75
|
}));
|
|
76
76
|
const recentLogins = activeSessions
|
|
77
77
|
.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime())
|
|
@@ -154,8 +154,8 @@ async function getRealSessions(adapter, options) {
|
|
|
154
154
|
async function getRealProviderStats(_adapter) {
|
|
155
155
|
try {
|
|
156
156
|
return [
|
|
157
|
-
{ type:
|
|
158
|
-
{ type:
|
|
157
|
+
{ type: "email", users: 0, active: 0 },
|
|
158
|
+
{ type: "github", users: 0, active: 0 },
|
|
159
159
|
];
|
|
160
160
|
}
|
|
161
161
|
catch (_error) {
|
|
@@ -164,17 +164,17 @@ async function getRealProviderStats(_adapter) {
|
|
|
164
164
|
}
|
|
165
165
|
async function deleteRealUser(adapter, userId) {
|
|
166
166
|
if (adapter.delete) {
|
|
167
|
-
await adapter.delete({ model:
|
|
167
|
+
await adapter.delete({ model: "user", where: [{ field: "id", value: userId }] });
|
|
168
168
|
}
|
|
169
169
|
else {
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
async function updateRealUser(adapter, userId, userData) {
|
|
173
173
|
const updatedUser = await adapter.update({
|
|
174
|
-
model:
|
|
174
|
+
model: "user",
|
|
175
175
|
where: [
|
|
176
176
|
{
|
|
177
|
-
field:
|
|
177
|
+
field: "id",
|
|
178
178
|
value: userId,
|
|
179
179
|
},
|
|
180
180
|
],
|
|
@@ -184,17 +184,17 @@ async function updateRealUser(adapter, userId, userData) {
|
|
|
184
184
|
}
|
|
185
185
|
function getMockData(type, options) {
|
|
186
186
|
switch (type) {
|
|
187
|
-
case
|
|
187
|
+
case "stats":
|
|
188
188
|
return getMockStats();
|
|
189
|
-
case
|
|
189
|
+
case "users":
|
|
190
190
|
return getMockUsers(options);
|
|
191
|
-
case
|
|
191
|
+
case "sessions":
|
|
192
192
|
return getMockSessions(options);
|
|
193
|
-
case
|
|
193
|
+
case "providers":
|
|
194
194
|
return getMockProviderStats();
|
|
195
|
-
case
|
|
195
|
+
case "deleteUser":
|
|
196
196
|
return Promise.resolve();
|
|
197
|
-
case
|
|
197
|
+
case "updateUser":
|
|
198
198
|
return Promise.resolve(generateMockUsers(1)[0]);
|
|
199
199
|
default:
|
|
200
200
|
throw new Error(`Unknown data type: ${type}`);
|
|
@@ -250,14 +250,14 @@ function getMockSessions(options) {
|
|
|
250
250
|
}
|
|
251
251
|
function getMockProviderStats() {
|
|
252
252
|
return [
|
|
253
|
-
{ type:
|
|
254
|
-
{ type:
|
|
255
|
-
{ type:
|
|
253
|
+
{ type: "google", users: 456, active: 234 },
|
|
254
|
+
{ type: "github", users: 234, active: 123 },
|
|
255
|
+
{ type: "email", users: 557, active: 345 },
|
|
256
256
|
];
|
|
257
257
|
}
|
|
258
258
|
function generateMockUsers(count) {
|
|
259
259
|
const users = [];
|
|
260
|
-
const providers = [
|
|
260
|
+
const providers = ["google", "github", "email"];
|
|
261
261
|
for (let i = 0; i < count; i++) {
|
|
262
262
|
const provider = providers[Math.floor(Math.random() * providers.length)];
|
|
263
263
|
users.push({
|
|
@@ -282,7 +282,7 @@ function generateMockSessions(count) {
|
|
|
282
282
|
userId: `user_${Math.floor(Math.random() * 100) + 1}`,
|
|
283
283
|
expires: new Date(Date.now() + Math.random() * 24 * 60 * 60 * 1000),
|
|
284
284
|
createdAt: new Date(Date.now() - Math.random() * 7 * 24 * 60 * 60 * 1000),
|
|
285
|
-
userAgent:
|
|
285
|
+
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36",
|
|
286
286
|
ip: `192.168.1.${Math.floor(Math.random() * 255)}`,
|
|
287
287
|
});
|
|
288
288
|
}
|
|
@@ -294,18 +294,18 @@ async function getRealAnalytics(adapter, options) {
|
|
|
294
294
|
let users = [];
|
|
295
295
|
let sessions = [];
|
|
296
296
|
if (adapter.findMany) {
|
|
297
|
-
users = await adapter.findMany({ model:
|
|
298
|
-
sessions = await adapter.findMany({ model:
|
|
297
|
+
users = await adapter.findMany({ model: "user", limit: 100000 }).catch(() => []);
|
|
298
|
+
sessions = await adapter.findMany({ model: "session", limit: 100000 }).catch(() => []);
|
|
299
299
|
}
|
|
300
300
|
else {
|
|
301
301
|
users = adapter.getUsers ? await adapter.getUsers() : [];
|
|
302
302
|
sessions = adapter.getSessions ? await adapter.getSessions() : [];
|
|
303
303
|
}
|
|
304
304
|
const organizations = adapter.findMany
|
|
305
|
-
? await adapter.findMany({ model:
|
|
305
|
+
? await adapter.findMany({ model: "organization", limit: 100000 }).catch(() => [])
|
|
306
306
|
: [];
|
|
307
307
|
const teams = adapter.findMany
|
|
308
|
-
? await adapter.findMany({ model:
|
|
308
|
+
? await adapter.findMany({ model: "team", limit: 100000 }).catch(() => [])
|
|
309
309
|
: [];
|
|
310
310
|
const now = new Date();
|
|
311
311
|
let startDate;
|
|
@@ -315,25 +315,25 @@ async function getRealAnalytics(adapter, options) {
|
|
|
315
315
|
}
|
|
316
316
|
else {
|
|
317
317
|
switch (period) {
|
|
318
|
-
case
|
|
318
|
+
case "1D":
|
|
319
319
|
startDate = new Date(now.getTime() - 24 * 60 * 60 * 1000);
|
|
320
320
|
break;
|
|
321
|
-
case
|
|
321
|
+
case "1W":
|
|
322
322
|
startDate = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
|
|
323
323
|
break;
|
|
324
|
-
case
|
|
324
|
+
case "1M":
|
|
325
325
|
startDate = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000);
|
|
326
326
|
break;
|
|
327
|
-
case
|
|
327
|
+
case "3M":
|
|
328
328
|
startDate = new Date(now.getTime() - 90 * 24 * 60 * 60 * 1000);
|
|
329
329
|
break;
|
|
330
|
-
case
|
|
330
|
+
case "6M":
|
|
331
331
|
startDate = new Date(now.getTime() - 180 * 24 * 60 * 60 * 1000);
|
|
332
332
|
break;
|
|
333
|
-
case
|
|
333
|
+
case "1Y":
|
|
334
334
|
startDate = new Date(now.getTime() - 365 * 24 * 60 * 60 * 1000);
|
|
335
335
|
break;
|
|
336
|
-
case
|
|
336
|
+
case "Custom":
|
|
337
337
|
// For Custom, use from date if provided, otherwise default to 30 days
|
|
338
338
|
startDate = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000);
|
|
339
339
|
break;
|
|
@@ -352,7 +352,7 @@ async function getRealAnalytics(adapter, options) {
|
|
|
352
352
|
}
|
|
353
353
|
// Generate time buckets based on period
|
|
354
354
|
const buckets = [];
|
|
355
|
-
if (period ===
|
|
355
|
+
if (period === "1D") {
|
|
356
356
|
// 24 hours - last 24 hours from now
|
|
357
357
|
for (let i = 0; i < 24; i++) {
|
|
358
358
|
const bucketDate = new Date(endDate.getTime() - (23 - i) * 60 * 60 * 1000);
|
|
@@ -364,7 +364,7 @@ async function getRealAnalytics(adapter, options) {
|
|
|
364
364
|
buckets.push({ start: bucketStart, end: bucketEnd, label: `${hour}h` });
|
|
365
365
|
}
|
|
366
366
|
}
|
|
367
|
-
else if (period ===
|
|
367
|
+
else if (period === "1W") {
|
|
368
368
|
// 7 days - last 7 days from today
|
|
369
369
|
for (let i = 0; i < 7; i++) {
|
|
370
370
|
const bucketDate = new Date(endDate.getTime() - (6 - i) * 24 * 60 * 60 * 1000);
|
|
@@ -372,11 +372,11 @@ async function getRealAnalytics(adapter, options) {
|
|
|
372
372
|
bucketStart.setHours(0, 0, 0, 0);
|
|
373
373
|
const bucketEnd = new Date(bucketStart);
|
|
374
374
|
bucketEnd.setHours(23, 59, 59, 999);
|
|
375
|
-
const dayName = bucketDate.toLocaleDateString(
|
|
375
|
+
const dayName = bucketDate.toLocaleDateString("en-US", { weekday: "short" });
|
|
376
376
|
buckets.push({ start: bucketStart, end: bucketEnd, label: dayName });
|
|
377
377
|
}
|
|
378
378
|
}
|
|
379
|
-
else if (period ===
|
|
379
|
+
else if (period === "1M") {
|
|
380
380
|
// 30 days - last 30 days from today
|
|
381
381
|
for (let i = 0; i < 30; i++) {
|
|
382
382
|
const bucketDate = new Date(endDate.getTime() - (29 - i) * 24 * 60 * 60 * 1000);
|
|
@@ -385,13 +385,13 @@ async function getRealAnalytics(adapter, options) {
|
|
|
385
385
|
const bucketEnd = new Date(bucketStart);
|
|
386
386
|
bucketEnd.setHours(23, 59, 59, 999);
|
|
387
387
|
// Format as "Nov 5" or just the day number
|
|
388
|
-
const monthName = bucketDate.toLocaleDateString(
|
|
388
|
+
const monthName = bucketDate.toLocaleDateString("en-US", { month: "short" });
|
|
389
389
|
const dayNum = bucketDate.getDate();
|
|
390
390
|
const dayLabel = `${monthName} ${dayNum}`;
|
|
391
391
|
buckets.push({ start: bucketStart, end: bucketEnd, label: dayLabel });
|
|
392
392
|
}
|
|
393
393
|
}
|
|
394
|
-
else if (period ===
|
|
394
|
+
else if (period === "3M") {
|
|
395
395
|
// 3 months - last 3 months starting from current month
|
|
396
396
|
const currentMonth = endDate.getMonth();
|
|
397
397
|
const currentYear = endDate.getFullYear();
|
|
@@ -401,11 +401,11 @@ async function getRealAnalytics(adapter, options) {
|
|
|
401
401
|
bucketStart.setHours(0, 0, 0, 0);
|
|
402
402
|
const bucketEnd = new Date(monthDate.getFullYear(), monthDate.getMonth() + 1, 0);
|
|
403
403
|
bucketEnd.setHours(23, 59, 59, 999);
|
|
404
|
-
const monthName = monthDate.toLocaleDateString(
|
|
404
|
+
const monthName = monthDate.toLocaleDateString("en-US", { month: "short" });
|
|
405
405
|
buckets.push({ start: bucketStart, end: bucketEnd, label: monthName });
|
|
406
406
|
}
|
|
407
407
|
}
|
|
408
|
-
else if (period ===
|
|
408
|
+
else if (period === "6M") {
|
|
409
409
|
// 6 months - last 6 months starting from current month
|
|
410
410
|
const currentMonth = endDate.getMonth();
|
|
411
411
|
const currentYear = endDate.getFullYear();
|
|
@@ -415,11 +415,11 @@ async function getRealAnalytics(adapter, options) {
|
|
|
415
415
|
bucketStart.setHours(0, 0, 0, 0);
|
|
416
416
|
const bucketEnd = new Date(monthDate.getFullYear(), monthDate.getMonth() + 1, 0);
|
|
417
417
|
bucketEnd.setHours(23, 59, 59, 999);
|
|
418
|
-
const monthName = monthDate.toLocaleDateString(
|
|
418
|
+
const monthName = monthDate.toLocaleDateString("en-US", { month: "short" });
|
|
419
419
|
buckets.push({ start: bucketStart, end: bucketEnd, label: monthName });
|
|
420
420
|
}
|
|
421
421
|
}
|
|
422
|
-
else if (period ===
|
|
422
|
+
else if (period === "1Y") {
|
|
423
423
|
// 12 months - last 12 months starting from current month
|
|
424
424
|
const currentMonth = endDate.getMonth();
|
|
425
425
|
const currentYear = endDate.getFullYear();
|
|
@@ -429,11 +429,11 @@ async function getRealAnalytics(adapter, options) {
|
|
|
429
429
|
bucketStart.setHours(0, 0, 0, 0);
|
|
430
430
|
const bucketEnd = new Date(monthDate.getFullYear(), monthDate.getMonth() + 1, 0);
|
|
431
431
|
bucketEnd.setHours(23, 59, 59, 999);
|
|
432
|
-
const monthName = monthDate.toLocaleDateString(
|
|
432
|
+
const monthName = monthDate.toLocaleDateString("en-US", { month: "short" });
|
|
433
433
|
buckets.push({ start: bucketStart, end: bucketEnd, label: monthName });
|
|
434
434
|
}
|
|
435
435
|
}
|
|
436
|
-
else if (period ===
|
|
436
|
+
else if (period === "Custom" || period === "ALL") {
|
|
437
437
|
// Custom or ALL - divide into equal buckets
|
|
438
438
|
const totalDays = Math.ceil((endDate.getTime() - startDate.getTime()) / (24 * 60 * 60 * 1000));
|
|
439
439
|
const bucketCount = Math.min(Math.max(totalDays, 1), 30); // Max 30 buckets, min 1
|
|
@@ -447,21 +447,21 @@ async function getRealAnalytics(adapter, options) {
|
|
|
447
447
|
let label;
|
|
448
448
|
if (totalDays <= 7) {
|
|
449
449
|
// For short ranges, show day names
|
|
450
|
-
label = bucketStart.toLocaleDateString(
|
|
450
|
+
label = bucketStart.toLocaleDateString("en-US", { weekday: "short" });
|
|
451
451
|
}
|
|
452
452
|
else if (totalDays <= 30) {
|
|
453
453
|
// For medium ranges, show month and day
|
|
454
|
-
label = bucketStart.toLocaleDateString(
|
|
454
|
+
label = bucketStart.toLocaleDateString("en-US", { month: "short", day: "numeric" });
|
|
455
455
|
}
|
|
456
456
|
else {
|
|
457
457
|
// For long ranges, show month only
|
|
458
|
-
label = bucketStart.toLocaleDateString(
|
|
458
|
+
label = bucketStart.toLocaleDateString("en-US", { month: "short" });
|
|
459
459
|
}
|
|
460
460
|
buckets.push({ start: bucketStart, end: bucketEnd, label });
|
|
461
461
|
}
|
|
462
462
|
}
|
|
463
463
|
let data = [];
|
|
464
|
-
if (type ===
|
|
464
|
+
if (type === "users") {
|
|
465
465
|
// For users, count users created within each bucket (non-cumulative)
|
|
466
466
|
data = buckets.map((bucket) => {
|
|
467
467
|
return users.filter((user) => {
|
|
@@ -470,7 +470,7 @@ async function getRealAnalytics(adapter, options) {
|
|
|
470
470
|
}).length;
|
|
471
471
|
});
|
|
472
472
|
}
|
|
473
|
-
else if (type ===
|
|
473
|
+
else if (type === "newUsers") {
|
|
474
474
|
// For new users, count users created within each bucket
|
|
475
475
|
data = buckets.map((bucket) => {
|
|
476
476
|
return users.filter((user) => {
|
|
@@ -479,7 +479,7 @@ async function getRealAnalytics(adapter, options) {
|
|
|
479
479
|
}).length;
|
|
480
480
|
});
|
|
481
481
|
}
|
|
482
|
-
else if (type ===
|
|
482
|
+
else if (type === "activeUsers") {
|
|
483
483
|
// Active users = users with active sessions in that period
|
|
484
484
|
data = buckets.map((bucket) => {
|
|
485
485
|
const activeSessions = sessions.filter((session) => {
|
|
@@ -492,7 +492,7 @@ async function getRealAnalytics(adapter, options) {
|
|
|
492
492
|
return new Set(activeSessions.map((s) => s.userId)).size;
|
|
493
493
|
});
|
|
494
494
|
}
|
|
495
|
-
else if (type ===
|
|
495
|
+
else if (type === "organizations") {
|
|
496
496
|
// For organizations, count orgs created within each bucket (non-cumulative)
|
|
497
497
|
data = buckets.map((bucket) => {
|
|
498
498
|
return organizations.filter((org) => {
|
|
@@ -501,7 +501,7 @@ async function getRealAnalytics(adapter, options) {
|
|
|
501
501
|
}).length;
|
|
502
502
|
});
|
|
503
503
|
}
|
|
504
|
-
else if (type ===
|
|
504
|
+
else if (type === "teams") {
|
|
505
505
|
// For teams, count teams created within each bucket (non-cumulative)
|
|
506
506
|
data = buckets.map((bucket) => {
|
|
507
507
|
return teams.filter((team) => {
|
package/dist/geo-service.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from
|
|
2
|
-
import { dirname, join } from
|
|
3
|
-
import { fileURLToPath } from
|
|
4
|
-
import maxmind from
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import maxmind from "maxmind";
|
|
5
5
|
const __filename = fileURLToPath(import.meta.url);
|
|
6
6
|
const __dirname = dirname(__filename);
|
|
7
7
|
let lookup = null;
|
|
@@ -12,9 +12,9 @@ export function setGeoDbPath(path) {
|
|
|
12
12
|
}
|
|
13
13
|
function loadDefaultDatabase() {
|
|
14
14
|
try {
|
|
15
|
-
const defaultDbPath = join(__dirname,
|
|
15
|
+
const defaultDbPath = join(__dirname, "../data/default-geo.json");
|
|
16
16
|
if (existsSync(defaultDbPath)) {
|
|
17
|
-
const dbContent = readFileSync(defaultDbPath,
|
|
17
|
+
const dbContent = readFileSync(defaultDbPath, "utf-8");
|
|
18
18
|
defaultDatabase = JSON.parse(dbContent);
|
|
19
19
|
}
|
|
20
20
|
else {
|
|
@@ -24,7 +24,7 @@ function loadDefaultDatabase() {
|
|
|
24
24
|
}
|
|
25
25
|
export async function initializeGeoService() {
|
|
26
26
|
try {
|
|
27
|
-
const dbPath = geoDbPath ||
|
|
27
|
+
const dbPath = geoDbPath || "./data/GeoLite2-City.mmdb";
|
|
28
28
|
lookup = await maxmind.open(dbPath);
|
|
29
29
|
}
|
|
30
30
|
catch (_error) {
|
|
@@ -38,10 +38,10 @@ export function resolveIPLocation(ipAddress) {
|
|
|
38
38
|
const result = lookup.get(ipAddress);
|
|
39
39
|
if (result) {
|
|
40
40
|
return {
|
|
41
|
-
country: result.country?.names?.en ||
|
|
42
|
-
countryCode: result.country?.iso_code ||
|
|
43
|
-
city: result.city?.names?.en ||
|
|
44
|
-
region: result.subdivisions?.[0]?.names?.en ||
|
|
41
|
+
country: result.country?.names?.en || "Unknown",
|
|
42
|
+
countryCode: result.country?.iso_code || "",
|
|
43
|
+
city: result.city?.names?.en || "Unknown",
|
|
44
|
+
region: result.subdivisions?.[0]?.names?.en || "Unknown",
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -60,7 +60,7 @@ function findLocationInDefaultDatabase(ipAddress) {
|
|
|
60
60
|
if (!defaultDatabase)
|
|
61
61
|
return null;
|
|
62
62
|
const ipToNumber = (ip) => {
|
|
63
|
-
return ip.split(
|
|
63
|
+
return ip.split(".").reduce((acc, part) => (acc << 8) + parseInt(part, 10), 0) >>> 0;
|
|
64
64
|
};
|
|
65
65
|
const isIPInRange = (ip, minIP, maxIP) => {
|
|
66
66
|
const ipNum = ipToNumber(ip);
|
|
@@ -85,107 +85,107 @@ function findLocationInDefaultDatabase(ipAddress) {
|
|
|
85
85
|
function resolveIPFromRanges(ipAddress) {
|
|
86
86
|
const countryIPRanges = [
|
|
87
87
|
{
|
|
88
|
-
country:
|
|
89
|
-
countryCode:
|
|
90
|
-
city:
|
|
91
|
-
region:
|
|
88
|
+
country: "United States",
|
|
89
|
+
countryCode: "US",
|
|
90
|
+
city: "New York",
|
|
91
|
+
region: "New York",
|
|
92
92
|
ranges: [
|
|
93
|
-
{ min:
|
|
94
|
-
{ min:
|
|
93
|
+
{ min: "8.0.0.0", max: "8.255.255.255" },
|
|
94
|
+
{ min: "24.0.0.0", max: "24.255.255.255" },
|
|
95
95
|
],
|
|
96
96
|
},
|
|
97
97
|
{
|
|
98
|
-
country:
|
|
99
|
-
countryCode:
|
|
100
|
-
city:
|
|
101
|
-
region:
|
|
98
|
+
country: "United Kingdom",
|
|
99
|
+
countryCode: "GB",
|
|
100
|
+
city: "London",
|
|
101
|
+
region: "England",
|
|
102
102
|
ranges: [
|
|
103
|
-
{ min:
|
|
104
|
-
{ min:
|
|
103
|
+
{ min: "2.0.0.0", max: "2.255.255.255" },
|
|
104
|
+
{ min: "5.0.0.0", max: "5.255.255.255" },
|
|
105
105
|
],
|
|
106
106
|
},
|
|
107
107
|
{
|
|
108
|
-
country:
|
|
109
|
-
countryCode:
|
|
110
|
-
city:
|
|
111
|
-
region:
|
|
108
|
+
country: "Germany",
|
|
109
|
+
countryCode: "DE",
|
|
110
|
+
city: "Berlin",
|
|
111
|
+
region: "Berlin",
|
|
112
112
|
ranges: [
|
|
113
|
-
{ min:
|
|
114
|
-
{ min:
|
|
113
|
+
{ min: "46.0.0.0", max: "46.255.255.255" },
|
|
114
|
+
{ min: "62.0.0.0", max: "62.255.255.255" },
|
|
115
115
|
],
|
|
116
116
|
},
|
|
117
117
|
{
|
|
118
|
-
country:
|
|
119
|
-
countryCode:
|
|
120
|
-
city:
|
|
121
|
-
region:
|
|
118
|
+
country: "France",
|
|
119
|
+
countryCode: "FR",
|
|
120
|
+
city: "Paris",
|
|
121
|
+
region: "Île-de-France",
|
|
122
122
|
ranges: [
|
|
123
|
-
{ min:
|
|
124
|
-
{ min:
|
|
123
|
+
{ min: "37.0.0.0", max: "37.255.255.255" },
|
|
124
|
+
{ min: "62.0.0.0", max: "62.255.255.255" },
|
|
125
125
|
],
|
|
126
126
|
},
|
|
127
127
|
{
|
|
128
|
-
country:
|
|
129
|
-
countryCode:
|
|
130
|
-
city:
|
|
131
|
-
region:
|
|
128
|
+
country: "Japan",
|
|
129
|
+
countryCode: "JP",
|
|
130
|
+
city: "Tokyo",
|
|
131
|
+
region: "Tokyo",
|
|
132
132
|
ranges: [
|
|
133
|
-
{ min:
|
|
134
|
-
{ min:
|
|
133
|
+
{ min: "126.0.0.0", max: "126.255.255.255" },
|
|
134
|
+
{ min: "210.0.0.0", max: "210.255.255.255" },
|
|
135
135
|
],
|
|
136
136
|
},
|
|
137
137
|
{
|
|
138
|
-
country:
|
|
139
|
-
countryCode:
|
|
140
|
-
city:
|
|
141
|
-
region:
|
|
138
|
+
country: "Canada",
|
|
139
|
+
countryCode: "CA",
|
|
140
|
+
city: "Toronto",
|
|
141
|
+
region: "Ontario",
|
|
142
142
|
ranges: [
|
|
143
|
-
{ min:
|
|
144
|
-
{ min:
|
|
143
|
+
{ min: "24.0.0.0", max: "24.255.255.255" },
|
|
144
|
+
{ min: "70.0.0.0", max: "70.255.255.255" },
|
|
145
145
|
],
|
|
146
146
|
},
|
|
147
147
|
{
|
|
148
|
-
country:
|
|
149
|
-
countryCode:
|
|
150
|
-
city:
|
|
151
|
-
region:
|
|
148
|
+
country: "Australia",
|
|
149
|
+
countryCode: "AU",
|
|
150
|
+
city: "Sydney",
|
|
151
|
+
region: "New South Wales",
|
|
152
152
|
ranges: [
|
|
153
|
-
{ min:
|
|
154
|
-
{ min:
|
|
153
|
+
{ min: "1.0.0.0", max: "1.255.255.255" },
|
|
154
|
+
{ min: "27.0.0.0", max: "27.255.255.255" },
|
|
155
155
|
],
|
|
156
156
|
},
|
|
157
157
|
{
|
|
158
|
-
country:
|
|
159
|
-
countryCode:
|
|
160
|
-
city:
|
|
161
|
-
region:
|
|
158
|
+
country: "Brazil",
|
|
159
|
+
countryCode: "BR",
|
|
160
|
+
city: "São Paulo",
|
|
161
|
+
region: "São Paulo",
|
|
162
162
|
ranges: [
|
|
163
|
-
{ min:
|
|
164
|
-
{ min:
|
|
163
|
+
{ min: "177.0.0.0", max: "177.255.255.255" },
|
|
164
|
+
{ min: "201.0.0.0", max: "201.255.255.255" },
|
|
165
165
|
],
|
|
166
166
|
},
|
|
167
167
|
{
|
|
168
|
-
country:
|
|
169
|
-
countryCode:
|
|
170
|
-
city:
|
|
171
|
-
region:
|
|
168
|
+
country: "India",
|
|
169
|
+
countryCode: "IN",
|
|
170
|
+
city: "Mumbai",
|
|
171
|
+
region: "Maharashtra",
|
|
172
172
|
ranges: [
|
|
173
|
-
{ min:
|
|
174
|
-
{ min:
|
|
173
|
+
{ min: "103.0.0.0", max: "103.255.255.255" },
|
|
174
|
+
{ min: "117.0.0.0", max: "117.255.255.255" },
|
|
175
175
|
],
|
|
176
176
|
},
|
|
177
177
|
{
|
|
178
|
-
country:
|
|
179
|
-
countryCode:
|
|
180
|
-
city:
|
|
181
|
-
region:
|
|
178
|
+
country: "China",
|
|
179
|
+
countryCode: "CN",
|
|
180
|
+
city: "Beijing",
|
|
181
|
+
region: "Beijing",
|
|
182
182
|
ranges: [
|
|
183
|
-
{ min:
|
|
184
|
-
{ min:
|
|
183
|
+
{ min: "1.0.0.0", max: "1.255.255.255" },
|
|
184
|
+
{ min: "14.0.0.0", max: "14.255.255.255" },
|
|
185
185
|
],
|
|
186
186
|
},
|
|
187
187
|
];
|
|
188
|
-
const ipParts = ipAddress.split(
|
|
188
|
+
const ipParts = ipAddress.split(".").map(Number);
|
|
189
189
|
if (ipParts.length !== 4 ||
|
|
190
190
|
ipParts.some((part) => Number.isNaN(part) || part < 0 || part > 255)) {
|
|
191
191
|
return null;
|
|
@@ -203,15 +203,15 @@ function resolveIPFromRanges(ipAddress) {
|
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
return {
|
|
206
|
-
country:
|
|
207
|
-
countryCode:
|
|
208
|
-
city:
|
|
209
|
-
region:
|
|
206
|
+
country: "Unknown",
|
|
207
|
+
countryCode: "",
|
|
208
|
+
city: "Unknown",
|
|
209
|
+
region: "Unknown",
|
|
210
210
|
};
|
|
211
211
|
}
|
|
212
212
|
function isIPInRange(ip, minIP, maxIP) {
|
|
213
213
|
const ipToNumber = (ip) => {
|
|
214
|
-
return ip.split(
|
|
214
|
+
return ip.split(".").reduce((acc, part) => (acc << 8) + parseInt(part, 10), 0) >>> 0;
|
|
215
215
|
};
|
|
216
216
|
const ipNum = ipToNumber(ip);
|
|
217
217
|
const minNum = ipToNumber(minIP);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import path from
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
3
|
export function getTsconfigInfo(cwd, tsconfigPath) {
|
|
4
|
-
const configPath = tsconfigPath || path.join(cwd || process.cwd(),
|
|
4
|
+
const configPath = tsconfigPath || path.join(cwd || process.cwd(), "tsconfig.json");
|
|
5
5
|
if (!fs.existsSync(configPath)) {
|
|
6
6
|
return {};
|
|
7
7
|
}
|
|
8
8
|
try {
|
|
9
|
-
const content = fs.readFileSync(configPath,
|
|
9
|
+
const content = fs.readFileSync(configPath, "utf-8");
|
|
10
10
|
return JSON.parse(content);
|
|
11
11
|
}
|
|
12
12
|
catch (_error) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { handleStudioRequest } from
|
|
2
|
-
export { createClickHouseProvider, createHttpProvider, createPostgresProvider, createStorageProvider, } from
|
|
3
|
-
export type { AuthEvent, AuthEventType, EventIngestionProvider } from
|
|
4
|
-
export { EVENT_TEMPLATES, getEventSeverity } from
|
|
5
|
-
export type { StudioConfig, StudioMetadata, WindowStudioConfig } from
|
|
6
|
-
export { defineStudioConfig } from
|
|
7
|
-
export { checkEventIngestionHealth, emitEvent, getEventIngestionProvider, getEventQueueSize, initializeEventIngestion, isEventIngestionInitialized, shutdownEventIngestion, } from
|
|
8
|
-
import
|
|
1
|
+
export { handleStudioRequest } from "./core/handler.js";
|
|
2
|
+
export { createClickHouseProvider, createHttpProvider, createPostgresProvider, createStorageProvider, } from "./providers/events/helpers.js";
|
|
3
|
+
export type { AuthEvent, AuthEventType, EventIngestionProvider } from "./types/events.js";
|
|
4
|
+
export { EVENT_TEMPLATES, getEventSeverity } from "./types/events.js";
|
|
5
|
+
export type { StudioConfig, StudioMetadata, WindowStudioConfig } from "./types/handler.js";
|
|
6
|
+
export { defineStudioConfig } from "./types/handler.js";
|
|
7
|
+
export { checkEventIngestionHealth, emitEvent, getEventIngestionProvider, getEventQueueSize, initializeEventIngestion, isEventIngestionInitialized, shutdownEventIngestion, } from "./utils/event-ingestion.js";
|
|
8
|
+
import "./utils/server-init.js";
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { handleStudioRequest } from
|
|
2
|
-
export { createClickHouseProvider, createHttpProvider, createPostgresProvider, createStorageProvider, } from
|
|
3
|
-
export { EVENT_TEMPLATES, getEventSeverity } from
|
|
4
|
-
export { defineStudioConfig } from
|
|
5
|
-
export { checkEventIngestionHealth, emitEvent, getEventIngestionProvider, getEventQueueSize, initializeEventIngestion, isEventIngestionInitialized, shutdownEventIngestion, } from
|
|
6
|
-
import
|
|
1
|
+
export { handleStudioRequest } from "./core/handler.js";
|
|
2
|
+
export { createClickHouseProvider, createHttpProvider, createPostgresProvider, createStorageProvider, } from "./providers/events/helpers.js";
|
|
3
|
+
export { EVENT_TEMPLATES, getEventSeverity } from "./types/events.js";
|
|
4
|
+
export { defineStudioConfig } from "./types/handler.js";
|
|
5
|
+
export { checkEventIngestionHealth, emitEvent, getEventIngestionProvider, getEventQueueSize, initializeEventIngestion, isEventIngestionInitialized, shutdownEventIngestion, } from "./utils/event-ingestion.js";
|
|
6
|
+
import "./utils/server-init.js";
|
|
7
7
|
//# sourceMappingURL=index.js.map
|