better-auth-studio 1.1.2-beta.15 → 1.1.2-beta.16

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.
Files changed (84) hide show
  1. package/README.md +36 -23
  2. package/data/default-geo.json +1 -1
  3. package/dist/adapters/astro.d.ts +1 -1
  4. package/dist/adapters/astro.js +13 -13
  5. package/dist/adapters/elysia.d.ts +2 -2
  6. package/dist/adapters/elysia.js +13 -13
  7. package/dist/adapters/express.d.ts +2 -2
  8. package/dist/adapters/express.js +4 -4
  9. package/dist/adapters/hono.d.ts +2 -2
  10. package/dist/adapters/hono.js +12 -12
  11. package/dist/adapters/nextjs.d.ts +1 -1
  12. package/dist/adapters/nextjs.js +10 -10
  13. package/dist/adapters/nuxt.d.ts +1 -1
  14. package/dist/adapters/nuxt.js +22 -22
  15. package/dist/adapters/remix.d.ts +1 -1
  16. package/dist/adapters/remix.js +13 -13
  17. package/dist/adapters/solid-start.d.ts +1 -1
  18. package/dist/adapters/solid-start.js +13 -13
  19. package/dist/adapters/svelte-kit.d.ts +2 -2
  20. package/dist/adapters/svelte-kit.js +13 -13
  21. package/dist/adapters/tanstack-start.d.ts +1 -1
  22. package/dist/adapters/tanstack-start.js +13 -13
  23. package/dist/add-svelte-kit-env-modules.js +11 -11
  24. package/dist/auth-adapter.d.ts +1 -1
  25. package/dist/auth-adapter.js +96 -96
  26. package/dist/cli/commands/init.js +57 -57
  27. package/dist/cli.js +75 -75
  28. package/dist/config.d.ts +5 -5
  29. package/dist/config.js +37 -37
  30. package/dist/core/handler.d.ts +1 -1
  31. package/dist/core/handler.js +115 -115
  32. package/dist/data.d.ts +2 -2
  33. package/dist/data.js +60 -60
  34. package/dist/geo-service.js +78 -78
  35. package/dist/get-tsconfig-info.js +4 -4
  36. package/dist/index.d.ts +8 -8
  37. package/dist/index.js +6 -6
  38. package/dist/providers/events/helpers.d.ts +2 -2
  39. package/dist/providers/events/helpers.js +156 -156
  40. package/dist/routes/api-router.d.ts +2 -2
  41. package/dist/routes/api-router.js +3 -3
  42. package/dist/routes.d.ts +4 -4
  43. package/dist/routes.d.ts.map +1 -1
  44. package/dist/routes.js +1272 -1272
  45. package/dist/routes.js.map +1 -1
  46. package/dist/studio.d.ts +3 -3
  47. package/dist/studio.js +64 -64
  48. package/dist/types/events.d.ts +7 -7
  49. package/dist/types/events.js +165 -165
  50. package/dist/types/handler.d.ts +5 -5
  51. package/dist/utils/auth-callbacks-injector.d.ts +2 -2
  52. package/dist/utils/auth-callbacks-injector.js +27 -27
  53. package/dist/utils/auth-callbacks-wrapper.d.ts +3 -3
  54. package/dist/utils/auth-callbacks-wrapper.js +117 -107
  55. package/dist/utils/database-detection.d.ts +1 -1
  56. package/dist/utils/database-detection.js +44 -44
  57. package/dist/utils/database-hook-injector.d.ts +3 -3
  58. package/dist/utils/database-hook-injector.js +135 -131
  59. package/dist/utils/email-otp-hooks-injector.d.ts +28 -12
  60. package/dist/utils/email-otp-hooks-injector.js +104 -97
  61. package/dist/utils/event-ingestion.d.ts +5 -5
  62. package/dist/utils/event-ingestion.d.ts.map +1 -1
  63. package/dist/utils/event-ingestion.js +14 -16
  64. package/dist/utils/event-ingestion.js.map +1 -1
  65. package/dist/utils/hook-injector.d.ts +2 -2
  66. package/dist/utils/hook-injector.js +199 -199
  67. package/dist/utils/html-injector.d.ts +3 -3
  68. package/dist/utils/html-injector.js +37 -37
  69. package/dist/utils/org-hooks-injector.d.ts +3 -3
  70. package/dist/utils/org-hooks-injector.js +63 -63
  71. package/dist/utils/org-hooks-wrapper.d.ts +41 -35
  72. package/dist/utils/org-hooks-wrapper.js +778 -658
  73. package/dist/utils/organization-hooks-wrapper.d.ts +23 -17
  74. package/dist/utils/organization-hooks-wrapper.js +325 -277
  75. package/dist/utils/package-json.js +11 -11
  76. package/dist/utils/paths.js +1 -1
  77. package/dist/utils/server-init.d.ts +1 -1
  78. package/dist/utils/server-init.js +25 -25
  79. package/dist/utils/session.js +12 -12
  80. package/dist/utils.js +24 -24
  81. package/package.json +26 -26
  82. package/scripts/download-geolite2.js +8 -8
  83. package/scripts/generate-default-db.js +324 -324
  84. package/scripts/postinstall.js +25 -25
package/dist/data.js CHANGED
@@ -1,28 +1,28 @@
1
- import { getAuthAdapter } from './auth-adapter.js';
2
- export async function getAuthData(_authConfig, type = 'stats', options, configPath, preloadedAdapter) {
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 = 'https://github.com/Kinfe123/better-auth-studio/issues';
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 'stats':
13
+ case "stats":
14
14
  return await getRealStats(adapter);
15
- case 'users':
15
+ case "users":
16
16
  return await getRealUsers(adapter, options);
17
- case 'sessions':
17
+ case "sessions":
18
18
  return await getRealSessions(adapter, options);
19
- case 'providers':
19
+ case "providers":
20
20
  return await getRealProviderStats(adapter);
21
- case 'deleteUser':
21
+ case "deleteUser":
22
22
  return await deleteRealUser(adapter, options.id);
23
- case 'updateUser':
23
+ case "updateUser":
24
24
  return await updateRealUser(adapter, options.id, options.userData);
25
- case 'analytics':
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: 'user', limit: 100000 }).catch(() => []);
41
- sessions = await adapter.findMany({ model: 'session', limit: 100000 }).catch(() => []);
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: 'email',
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: 'email', users: 0, active: 0 },
158
- { type: 'github', users: 0, active: 0 },
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: 'user', where: [{ field: 'id', value: userId }] });
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: 'user',
174
+ model: "user",
175
175
  where: [
176
176
  {
177
- field: 'id',
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 'stats':
187
+ case "stats":
188
188
  return getMockStats();
189
- case 'users':
189
+ case "users":
190
190
  return getMockUsers(options);
191
- case 'sessions':
191
+ case "sessions":
192
192
  return getMockSessions(options);
193
- case 'providers':
193
+ case "providers":
194
194
  return getMockProviderStats();
195
- case 'deleteUser':
195
+ case "deleteUser":
196
196
  return Promise.resolve();
197
- case 'updateUser':
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: 'google', users: 456, active: 234 },
254
- { type: 'github', users: 234, active: 123 },
255
- { type: 'email', users: 557, active: 345 },
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 = ['google', 'github', 'email'];
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: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36',
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: 'user', limit: 100000 }).catch(() => []);
298
- sessions = await adapter.findMany({ model: 'session', limit: 100000 }).catch(() => []);
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: 'organization', limit: 100000 }).catch(() => [])
305
+ ? await adapter.findMany({ model: "organization", limit: 100000 }).catch(() => [])
306
306
  : [];
307
307
  const teams = adapter.findMany
308
- ? await adapter.findMany({ model: 'team', limit: 100000 }).catch(() => [])
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 '1D':
318
+ case "1D":
319
319
  startDate = new Date(now.getTime() - 24 * 60 * 60 * 1000);
320
320
  break;
321
- case '1W':
321
+ case "1W":
322
322
  startDate = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
323
323
  break;
324
- case '1M':
324
+ case "1M":
325
325
  startDate = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000);
326
326
  break;
327
- case '3M':
327
+ case "3M":
328
328
  startDate = new Date(now.getTime() - 90 * 24 * 60 * 60 * 1000);
329
329
  break;
330
- case '6M':
330
+ case "6M":
331
331
  startDate = new Date(now.getTime() - 180 * 24 * 60 * 60 * 1000);
332
332
  break;
333
- case '1Y':
333
+ case "1Y":
334
334
  startDate = new Date(now.getTime() - 365 * 24 * 60 * 60 * 1000);
335
335
  break;
336
- case 'Custom':
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 === '1D') {
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 === '1W') {
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('en-US', { weekday: 'short' });
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 === '1M') {
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('en-US', { month: 'short' });
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 === '3M') {
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('en-US', { month: 'short' });
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 === '6M') {
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('en-US', { month: 'short' });
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 === '1Y') {
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('en-US', { month: 'short' });
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 === 'Custom' || period === 'ALL') {
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('en-US', { weekday: 'short' });
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('en-US', { month: 'short', day: 'numeric' });
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('en-US', { month: 'short' });
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 === 'users') {
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 === 'newUsers') {
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 === 'activeUsers') {
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 === 'organizations') {
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 === 'teams') {
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) => {
@@ -1,7 +1,7 @@
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';
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, '../data/default-geo.json');
15
+ const defaultDbPath = join(__dirname, "../data/default-geo.json");
16
16
  if (existsSync(defaultDbPath)) {
17
- const dbContent = readFileSync(defaultDbPath, 'utf-8');
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 || './data/GeoLite2-City.mmdb';
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 || 'Unknown',
42
- countryCode: result.country?.iso_code || '',
43
- city: result.city?.names?.en || 'Unknown',
44
- region: result.subdivisions?.[0]?.names?.en || 'Unknown',
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('.').reduce((acc, part) => (acc << 8) + parseInt(part, 10), 0) >>> 0;
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: 'United States',
89
- countryCode: 'US',
90
- city: 'New York',
91
- region: 'New York',
88
+ country: "United States",
89
+ countryCode: "US",
90
+ city: "New York",
91
+ region: "New York",
92
92
  ranges: [
93
- { min: '8.0.0.0', max: '8.255.255.255' },
94
- { min: '24.0.0.0', max: '24.255.255.255' },
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: 'United Kingdom',
99
- countryCode: 'GB',
100
- city: 'London',
101
- region: 'England',
98
+ country: "United Kingdom",
99
+ countryCode: "GB",
100
+ city: "London",
101
+ region: "England",
102
102
  ranges: [
103
- { min: '2.0.0.0', max: '2.255.255.255' },
104
- { min: '5.0.0.0', max: '5.255.255.255' },
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: 'Germany',
109
- countryCode: 'DE',
110
- city: 'Berlin',
111
- region: 'Berlin',
108
+ country: "Germany",
109
+ countryCode: "DE",
110
+ city: "Berlin",
111
+ region: "Berlin",
112
112
  ranges: [
113
- { min: '46.0.0.0', max: '46.255.255.255' },
114
- { min: '62.0.0.0', max: '62.255.255.255' },
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: 'France',
119
- countryCode: 'FR',
120
- city: 'Paris',
121
- region: 'Île-de-France',
118
+ country: "France",
119
+ countryCode: "FR",
120
+ city: "Paris",
121
+ region: "Île-de-France",
122
122
  ranges: [
123
- { min: '37.0.0.0', max: '37.255.255.255' },
124
- { min: '62.0.0.0', max: '62.255.255.255' },
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: 'Japan',
129
- countryCode: 'JP',
130
- city: 'Tokyo',
131
- region: 'Tokyo',
128
+ country: "Japan",
129
+ countryCode: "JP",
130
+ city: "Tokyo",
131
+ region: "Tokyo",
132
132
  ranges: [
133
- { min: '126.0.0.0', max: '126.255.255.255' },
134
- { min: '210.0.0.0', max: '210.255.255.255' },
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: 'Canada',
139
- countryCode: 'CA',
140
- city: 'Toronto',
141
- region: 'Ontario',
138
+ country: "Canada",
139
+ countryCode: "CA",
140
+ city: "Toronto",
141
+ region: "Ontario",
142
142
  ranges: [
143
- { min: '24.0.0.0', max: '24.255.255.255' },
144
- { min: '70.0.0.0', max: '70.255.255.255' },
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: 'Australia',
149
- countryCode: 'AU',
150
- city: 'Sydney',
151
- region: 'New South Wales',
148
+ country: "Australia",
149
+ countryCode: "AU",
150
+ city: "Sydney",
151
+ region: "New South Wales",
152
152
  ranges: [
153
- { min: '1.0.0.0', max: '1.255.255.255' },
154
- { min: '27.0.0.0', max: '27.255.255.255' },
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: 'Brazil',
159
- countryCode: 'BR',
160
- city: 'São Paulo',
161
- region: 'São Paulo',
158
+ country: "Brazil",
159
+ countryCode: "BR",
160
+ city: "São Paulo",
161
+ region: "São Paulo",
162
162
  ranges: [
163
- { min: '177.0.0.0', max: '177.255.255.255' },
164
- { min: '201.0.0.0', max: '201.255.255.255' },
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: 'India',
169
- countryCode: 'IN',
170
- city: 'Mumbai',
171
- region: 'Maharashtra',
168
+ country: "India",
169
+ countryCode: "IN",
170
+ city: "Mumbai",
171
+ region: "Maharashtra",
172
172
  ranges: [
173
- { min: '103.0.0.0', max: '103.255.255.255' },
174
- { min: '117.0.0.0', max: '117.255.255.255' },
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: 'China',
179
- countryCode: 'CN',
180
- city: 'Beijing',
181
- region: 'Beijing',
178
+ country: "China",
179
+ countryCode: "CN",
180
+ city: "Beijing",
181
+ region: "Beijing",
182
182
  ranges: [
183
- { min: '1.0.0.0', max: '1.255.255.255' },
184
- { min: '14.0.0.0', max: '14.255.255.255' },
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('.').map(Number);
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: 'Unknown',
207
- countryCode: '',
208
- city: 'Unknown',
209
- region: 'Unknown',
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('.').reduce((acc, part) => (acc << 8) + parseInt(part, 10), 0) >>> 0;
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 'node:fs';
2
- import path from 'node:path';
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(), 'tsconfig.json');
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, 'utf-8');
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 './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';
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 './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';
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