better-auth-studio 1.1.3-beta.9 → 1.1.3

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 (196) hide show
  1. package/README.md +145 -16
  2. package/dist/adapters/astro.d.ts +0 -1
  3. package/dist/adapters/astro.js +5 -2
  4. package/dist/adapters/cloudflare-workers.d.ts +101 -0
  5. package/dist/adapters/cloudflare-workers.js +494 -0
  6. package/dist/adapters/elysia.d.ts +0 -1
  7. package/dist/adapters/elysia.js +7 -33
  8. package/dist/adapters/express.d.ts +0 -1
  9. package/dist/adapters/express.js +4 -1
  10. package/dist/adapters/hono.d.ts +0 -1
  11. package/dist/adapters/hono.js +7 -27
  12. package/dist/adapters/nextjs.d.ts +0 -1
  13. package/dist/adapters/nextjs.js +5 -2
  14. package/dist/adapters/nuxt.d.ts +0 -1
  15. package/dist/adapters/nuxt.js +5 -2
  16. package/dist/adapters/remix.d.ts +0 -1
  17. package/dist/adapters/remix.js +5 -2
  18. package/dist/adapters/solid-start.d.ts +0 -1
  19. package/dist/adapters/solid-start.js +5 -2
  20. package/dist/adapters/svelte-kit.d.ts +0 -1
  21. package/dist/adapters/svelte-kit.js +5 -2
  22. package/dist/adapters/tanstack-start.d.ts +0 -1
  23. package/dist/adapters/tanstack-start.js +36 -8
  24. package/dist/add-svelte-kit-env-modules.d.ts +0 -1
  25. package/dist/add-svelte-kit-env-modules.js +0 -1
  26. package/dist/auth-adapter.d.ts +5 -2
  27. package/dist/auth-adapter.js +39 -4
  28. package/dist/cli/commands/init.d.ts +0 -1
  29. package/dist/cli/commands/init.js +0 -1
  30. package/dist/cli.d.ts +0 -1
  31. package/dist/cli.js +6 -1
  32. package/dist/config.d.ts +0 -1
  33. package/dist/config.js +0 -1
  34. package/dist/core/handler.d.ts +0 -1
  35. package/dist/core/handler.js +36 -5
  36. package/dist/data.d.ts +10 -4
  37. package/dist/data.js +40 -6
  38. package/dist/geo-service.d.ts +0 -1
  39. package/dist/geo-service.js +0 -1
  40. package/dist/get-tsconfig-info.d.ts +0 -1
  41. package/dist/get-tsconfig-info.js +0 -1
  42. package/dist/index.d.ts +0 -1
  43. package/dist/index.js +0 -1
  44. package/dist/providers/events/helpers.d.ts +3 -2
  45. package/dist/providers/events/helpers.js +303 -93
  46. package/dist/public/assets/main-C-R_HO98.css +1 -0
  47. package/dist/public/assets/main-DDypFItU.js +1302 -0
  48. package/dist/public/index.html +2 -2
  49. package/dist/public/shaders.png +0 -0
  50. package/dist/routes/api-router.d.ts +2 -3
  51. package/dist/routes/api-router.js +0 -1
  52. package/dist/routes.d.ts +2 -3
  53. package/dist/routes.js +813 -172
  54. package/dist/studio.d.ts +0 -1
  55. package/dist/studio.js +6 -4
  56. package/dist/types/events.d.ts +0 -1
  57. package/dist/types/events.js +0 -1
  58. package/dist/types/handler.d.ts +13 -3
  59. package/dist/types/handler.js +0 -1
  60. package/dist/types/index.d.ts +0 -1
  61. package/dist/types/index.js +0 -1
  62. package/dist/utils/access-rules.d.ts +19 -0
  63. package/dist/utils/access-rules.js +126 -0
  64. package/dist/utils/auth-callbacks-injector.d.ts +0 -1
  65. package/dist/utils/auth-callbacks-injector.js +0 -1
  66. package/dist/utils/database-detection.d.ts +0 -1
  67. package/dist/utils/database-detection.js +33 -4
  68. package/dist/utils/event-ingestion.d.ts +0 -1
  69. package/dist/utils/event-ingestion.js +1 -1
  70. package/dist/utils/hook-injector.d.ts +0 -1
  71. package/dist/utils/hook-injector.js +2 -2
  72. package/dist/utils/html-injector.d.ts +1 -7
  73. package/dist/utils/html-injector.js +15 -1
  74. package/dist/utils/org-hooks-injector.d.ts +0 -1
  75. package/dist/utils/org-hooks-injector.js +0 -1
  76. package/dist/utils/package-json.d.ts +1 -1
  77. package/dist/utils/package-json.js +21 -1
  78. package/dist/utils/paths.d.ts +0 -1
  79. package/dist/utils/paths.js +0 -1
  80. package/dist/utils/reason-messages.d.ts +0 -1
  81. package/dist/utils/reason-messages.js +0 -1
  82. package/dist/utils/session.d.ts +0 -1
  83. package/dist/utils/session.js +0 -1
  84. package/dist/utils.d.ts +0 -1
  85. package/dist/utils.js +0 -1
  86. package/package.json +30 -39
  87. package/dist/adapters/astro.d.ts.map +0 -1
  88. package/dist/adapters/astro.js.map +0 -1
  89. package/dist/adapters/elysia.d.ts.map +0 -1
  90. package/dist/adapters/elysia.js.map +0 -1
  91. package/dist/adapters/express.d.ts.map +0 -1
  92. package/dist/adapters/express.js.map +0 -1
  93. package/dist/adapters/hono.d.ts.map +0 -1
  94. package/dist/adapters/hono.js.map +0 -1
  95. package/dist/adapters/nextjs.d.ts.map +0 -1
  96. package/dist/adapters/nextjs.js.map +0 -1
  97. package/dist/adapters/nuxt.d.ts.map +0 -1
  98. package/dist/adapters/nuxt.js.map +0 -1
  99. package/dist/adapters/remix.d.ts.map +0 -1
  100. package/dist/adapters/remix.js.map +0 -1
  101. package/dist/adapters/solid-start.d.ts.map +0 -1
  102. package/dist/adapters/solid-start.js.map +0 -1
  103. package/dist/adapters/svelte-kit.d.ts.map +0 -1
  104. package/dist/adapters/svelte-kit.js.map +0 -1
  105. package/dist/adapters/tanstack-start.d.ts.map +0 -1
  106. package/dist/adapters/tanstack-start.js.map +0 -1
  107. package/dist/add-svelte-kit-env-modules.d.ts.map +0 -1
  108. package/dist/add-svelte-kit-env-modules.js.map +0 -1
  109. package/dist/auth-adapter.d.ts.map +0 -1
  110. package/dist/auth-adapter.js.map +0 -1
  111. package/dist/cli/commands/init.d.ts.map +0 -1
  112. package/dist/cli/commands/init.js.map +0 -1
  113. package/dist/cli.d.ts.map +0 -1
  114. package/dist/cli.js.map +0 -1
  115. package/dist/config.d.ts.map +0 -1
  116. package/dist/config.js.map +0 -1
  117. package/dist/core/handler.d.ts.map +0 -1
  118. package/dist/core/handler.js.map +0 -1
  119. package/dist/data.d.ts.map +0 -1
  120. package/dist/data.js.map +0 -1
  121. package/dist/geo-service.d.ts.map +0 -1
  122. package/dist/geo-service.js.map +0 -1
  123. package/dist/get-tsconfig-info.d.ts.map +0 -1
  124. package/dist/get-tsconfig-info.js.map +0 -1
  125. package/dist/index.d.ts.map +0 -1
  126. package/dist/index.js.map +0 -1
  127. package/dist/providers/events/helpers.d.ts.map +0 -1
  128. package/dist/providers/events/helpers.js.map +0 -1
  129. package/dist/public/assets/main-D7_GjGqW.js +0 -1216
  130. package/dist/public/assets/main-Ru3ybjQp.css +0 -1
  131. package/dist/routes/api-router.d.ts.map +0 -1
  132. package/dist/routes/api-router.js.map +0 -1
  133. package/dist/routes.d.ts.map +0 -1
  134. package/dist/routes.js.map +0 -1
  135. package/dist/studio.d.ts.map +0 -1
  136. package/dist/studio.js.map +0 -1
  137. package/dist/types/events.d.ts.map +0 -1
  138. package/dist/types/events.js.map +0 -1
  139. package/dist/types/handler.d.ts.map +0 -1
  140. package/dist/types/handler.js.map +0 -1
  141. package/dist/types/index.d.ts.map +0 -1
  142. package/dist/types/index.js.map +0 -1
  143. package/dist/utils/auth-callbacks-injector.d.ts.map +0 -1
  144. package/dist/utils/auth-callbacks-injector.js.map +0 -1
  145. package/dist/utils/auth-callbacks-wrapper.d.ts +0 -7
  146. package/dist/utils/auth-callbacks-wrapper.d.ts.map +0 -1
  147. package/dist/utils/auth-callbacks-wrapper.js +0 -133
  148. package/dist/utils/auth-callbacks-wrapper.js.map +0 -1
  149. package/dist/utils/database-detection.d.ts.map +0 -1
  150. package/dist/utils/database-detection.js.map +0 -1
  151. package/dist/utils/database-hook-injector.d.ts +0 -3
  152. package/dist/utils/database-hook-injector.d.ts.map +0 -1
  153. package/dist/utils/database-hook-injector.js +0 -145
  154. package/dist/utils/database-hook-injector.js.map +0 -1
  155. package/dist/utils/email-otp-hooks-injector.d.ts +0 -45
  156. package/dist/utils/email-otp-hooks-injector.d.ts.map +0 -1
  157. package/dist/utils/email-otp-hooks-injector.js +0 -141
  158. package/dist/utils/email-otp-hooks-injector.js.map +0 -1
  159. package/dist/utils/event-ingestion.d.ts.map +0 -1
  160. package/dist/utils/event-ingestion.js.map +0 -1
  161. package/dist/utils/hook-injector.d.ts.map +0 -1
  162. package/dist/utils/hook-injector.js.map +0 -1
  163. package/dist/utils/html-injector.d.ts.map +0 -1
  164. package/dist/utils/html-injector.js.map +0 -1
  165. package/dist/utils/org-hooks-injector.d.ts.map +0 -1
  166. package/dist/utils/org-hooks-injector.js.map +0 -1
  167. package/dist/utils/org-hooks-wrapper.d.ts +0 -80
  168. package/dist/utils/org-hooks-wrapper.d.ts.map +0 -1
  169. package/dist/utils/org-hooks-wrapper.js +0 -807
  170. package/dist/utils/org-hooks-wrapper.js.map +0 -1
  171. package/dist/utils/organization-hooks-wrapper.d.ts +0 -44
  172. package/dist/utils/organization-hooks-wrapper.d.ts.map +0 -1
  173. package/dist/utils/organization-hooks-wrapper.js +0 -345
  174. package/dist/utils/organization-hooks-wrapper.js.map +0 -1
  175. package/dist/utils/package-json.d.ts.map +0 -1
  176. package/dist/utils/package-json.js.map +0 -1
  177. package/dist/utils/paths.d.ts.map +0 -1
  178. package/dist/utils/paths.js.map +0 -1
  179. package/dist/utils/reason-messages.d.ts.map +0 -1
  180. package/dist/utils/reason-messages.js.map +0 -1
  181. package/dist/utils/server-init.d.ts +0 -10
  182. package/dist/utils/server-init.d.ts.map +0 -1
  183. package/dist/utils/server-init.js +0 -40
  184. package/dist/utils/server-init.js.map +0 -1
  185. package/dist/utils/session.d.ts.map +0 -1
  186. package/dist/utils/session.js.map +0 -1
  187. package/dist/utils.d.ts.map +0 -1
  188. package/dist/utils.js.map +0 -1
  189. package/public/assets/main-D7_GjGqW.js +0 -1216
  190. package/public/assets/main-Ru3ybjQp.css +0 -1
  191. package/public/favicon.svg +0 -6
  192. package/public/index.html +0 -14
  193. package/public/logo.png +0 -0
  194. package/public/vite.svg +0 -5
  195. package/scripts/download-geolite2.js +0 -42
  196. package/scripts/generate-default-db.js +0 -462
@@ -27,4 +27,3 @@ type ApiEvent = {
27
27
  */
28
28
  export declare function betterAuthStudio(config: StudioConfig): (event: ApiEvent) => Promise<Response>;
29
29
  export {};
30
- //# sourceMappingURL=solid-start.d.ts.map
@@ -94,9 +94,12 @@ async function convertSolidStartToUniversal(event, config) {
94
94
  };
95
95
  }
96
96
  function universalToResponse(res) {
97
+ const headers = new Headers(res.headers);
98
+ res.setCookies?.forEach((cookie) => {
99
+ headers.append("Set-Cookie", cookie);
100
+ });
97
101
  return new Response(res.body, {
98
102
  status: res.status,
99
- headers: res.headers,
103
+ headers,
100
104
  });
101
105
  }
102
- //# sourceMappingURL=solid-start.js.map
@@ -33,4 +33,3 @@ import type { StudioConfig } from "../types/handler.js";
33
33
  * ```
34
34
  */
35
35
  export declare function betterAuthStudio(config: StudioConfig): (event: RequestEvent) => Promise<Response>;
36
- //# sourceMappingURL=svelte-kit.d.ts.map
@@ -106,9 +106,12 @@ async function convertSvelteKitToUniversal(event, config) {
106
106
  };
107
107
  }
108
108
  function universalToResponse(res) {
109
+ const headers = new Headers(res.headers);
110
+ res.setCookies?.forEach((cookie) => {
111
+ headers.append("Set-Cookie", cookie);
112
+ });
109
113
  return new Response(res.body, {
110
114
  status: res.status,
111
- headers: res.headers,
115
+ headers,
112
116
  });
113
117
  }
114
- //# sourceMappingURL=svelte-kit.js.map
@@ -29,4 +29,3 @@ type TanStackStartHandlerContext = {
29
29
  */
30
30
  export declare function betterAuthStudio(config: StudioConfig): ({ request }: TanStackStartHandlerContext) => Promise<Response>;
31
31
  export {};
32
- //# sourceMappingURL=tanstack-start.d.ts.map
@@ -1,5 +1,7 @@
1
1
  import { handleStudioRequest } from "../core/handler.js";
2
2
  import { injectEventHooks, injectLastSeenAtHooks } from "../utils/hook-injector.js";
3
+ const STATIC_ASSET_QUERY_PARAM = "__better_auth_studio_asset";
4
+ const STATIC_ASSET_PATH_PATTERN = /^\/(?:assets\/[^/?#]+|vite\.svg|favicon\.svg|logo\.png)$/;
3
5
  /**
4
6
  * TanStack Start adapter for Better Auth Studio
5
7
  *
@@ -35,7 +37,7 @@ export function betterAuthStudio(config) {
35
37
  try {
36
38
  const universalReq = await convertTanStackStartToUniversal(request, config);
37
39
  const universalRes = await handleStudioRequest(universalReq, config);
38
- return universalToResponse(universalRes);
40
+ return universalToResponse(universalRes, config);
39
41
  }
40
42
  catch (error) {
41
43
  console.error("Studio handler error:", error);
@@ -87,11 +89,15 @@ async function convertTanStackStartToUniversal(request, config) {
87
89
  const basePath = config.basePath || "/api/studio";
88
90
  const normalizedBasePath = basePath.endsWith("/") ? basePath.slice(0, -1) : basePath;
89
91
  const url = new URL(request.url);
90
- let path = url.pathname;
91
- if (path.startsWith(normalizedBasePath)) {
92
+ const queryAssetPath = url.searchParams.get(STATIC_ASSET_QUERY_PARAM);
93
+ const acceptedQueryAssetPath = queryAssetPath && STATIC_ASSET_PATH_PATTERN.test(queryAssetPath) ? queryAssetPath : null;
94
+ let path = acceptedQueryAssetPath || url.pathname;
95
+ if (!acceptedQueryAssetPath && path.startsWith(normalizedBasePath)) {
92
96
  path = path.slice(normalizedBasePath.length) || "/";
93
97
  }
94
- const pathWithQuery = path + url.search;
98
+ url.searchParams.delete(STATIC_ASSET_QUERY_PARAM);
99
+ const query = url.searchParams.toString();
100
+ const pathWithQuery = path + (query ? `?${query}` : "");
95
101
  return {
96
102
  url: pathWithQuery,
97
103
  method: method,
@@ -99,10 +105,32 @@ async function convertTanStackStartToUniversal(request, config) {
99
105
  body,
100
106
  };
101
107
  }
102
- function universalToResponse(res) {
103
- return new Response(res.body, {
108
+ function universalToResponse(res, config) {
109
+ const headers = new Headers(res.headers);
110
+ res.setCookies?.forEach((cookie) => {
111
+ headers.append("Set-Cookie", cookie);
112
+ });
113
+ let body = res.body;
114
+ if (typeof body === "string" &&
115
+ headers.get("Content-Type")?.toLowerCase().includes("text/html")) {
116
+ body = rewriteStaticAssetUrls(body, config.basePath || "/api/studio");
117
+ }
118
+ return new Response(body, {
104
119
  status: res.status,
105
- headers: res.headers,
120
+ headers,
121
+ });
122
+ }
123
+ /**
124
+ * Nitro can treat nested URLs ending in .js/.css as public files before a
125
+ * TanStack Start splat route gets a chance to handle them. Keep Studio assets
126
+ * on the exact server-route URL and carry the requested file in the query.
127
+ */
128
+ function rewriteStaticAssetUrls(html, basePath) {
129
+ const normalizedBasePath = basePath.endsWith("/") ? basePath.slice(0, -1) : basePath;
130
+ const escapedBasePath = normalizedBasePath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
131
+ const assetUrlPattern = new RegExp(`((?:href|src)=["'])${escapedBasePath}(/(?:assets/[^"'?#]+|vite\\.svg|favicon\\.svg|logo\\.png))(["'])`, "g");
132
+ return html.replace(assetUrlPattern, (_match, prefix, assetPath, suffix) => {
133
+ const query = new URLSearchParams({ [STATIC_ASSET_QUERY_PARAM]: assetPath });
134
+ return `${prefix}${normalizedBasePath}?${query.toString()}${suffix}`;
106
135
  });
107
136
  }
108
- //# sourceMappingURL=tanstack-start.js.map
@@ -1,2 +1 @@
1
1
  export declare function addSvelteKitEnvModules(alias: Record<string, string>): void;
2
- //# sourceMappingURL=add-svelte-kit-env-modules.d.ts.map
@@ -12,4 +12,3 @@ export function addSvelteKitEnvModules(alias) {
12
12
  alias["$app/types"] = "@sveltejs/kit";
13
13
  alias["$app/*"] = "@sveltejs/kit";
14
14
  }
15
- //# sourceMappingURL=add-svelte-kit-env-modules.js.map
@@ -1,4 +1,4 @@
1
- import type { InternalAdapter } from "better-auth";
1
+ import { type InternalAdapter } from "better-auth";
2
2
  type OptionalFields<T> = {
3
3
  [K in keyof T]?: T[K];
4
4
  };
@@ -8,6 +8,10 @@ export interface AuthAdapter extends UserInternalAdapter {
8
8
  createAccount: (data: any) => Promise<any>;
9
9
  createVerification: (data: any) => Promise<any>;
10
10
  createOrganization: (data: any) => Promise<any>;
11
+ count?: (options: {
12
+ model: string;
13
+ where?: any;
14
+ }) => Promise<number>;
11
15
  create?: (...args: any[]) => Promise<any>;
12
16
  update?: (...args: any[]) => Promise<any>;
13
17
  delete?: (...args: any[]) => Promise<any>;
@@ -34,4 +38,3 @@ export declare function createMockSession(adapter: AuthAdapter, userId: string,
34
38
  export declare function createMockAccount(adapter: AuthAdapter, userId: string, index: number, providerId?: string): Promise<any>;
35
39
  export declare function createMockVerification(adapter: AuthAdapter, _userId: string, index: number): Promise<any>;
36
40
  export {};
37
- //# sourceMappingURL=auth-adapter.d.ts.map
@@ -102,8 +102,14 @@ export async function getAuthAdapter(configPath) {
102
102
  image: data.image || `https://api.dicebear.com/7.x/avataaars/svg?seed=${data.email}`,
103
103
  },
104
104
  });
105
- const hashedPassword = await hashPassword(data.password);
106
105
  if (data.password) {
106
+ let hashedPassword = data.password;
107
+ try {
108
+ hashedPassword = await hashPassword(data.password);
109
+ }
110
+ catch (err) {
111
+ console.log({ err });
112
+ }
107
113
  try {
108
114
  await adapter.create({
109
115
  model: "account",
@@ -117,7 +123,9 @@ export async function getAuthAdapter(configPath) {
117
123
  },
118
124
  });
119
125
  }
120
- catch (_accountError) { }
126
+ catch (_accountError) {
127
+ console.log({ _accountError });
128
+ }
121
129
  }
122
130
  return user;
123
131
  },
@@ -193,6 +201,25 @@ export async function getAuthAdapter(configPath) {
193
201
  return [];
194
202
  }
195
203
  },
204
+ count: async (options) => {
205
+ try {
206
+ if (typeof adapter.count === "function") {
207
+ return await adapter.count(options);
208
+ }
209
+ if (typeof adapter.findMany === "function") {
210
+ const rows = await adapter.findMany({
211
+ model: options.model,
212
+ where: options.where,
213
+ limit: 100000,
214
+ });
215
+ return Array.isArray(rows) ? rows.length : 0;
216
+ }
217
+ return 0;
218
+ }
219
+ catch (_error) {
220
+ return 0;
221
+ }
222
+ },
196
223
  findMany: async (options) => {
197
224
  try {
198
225
  if (typeof adapter.findMany === "function") {
@@ -416,15 +443,24 @@ function generateRandomIP() {
416
443
  const fourthOctet = Math.floor(Math.random() * 255) + 1;
417
444
  return `${range.min.split(".")[0]}.${secondOctet}.${thirdOctet}.${fourthOctet}`;
418
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
+ ];
419
454
  export async function createMockSession(adapter, userId, index) {
420
455
  // Generate a random IP address
421
456
  const ipAddress = generateRandomIP();
457
+ const userAgent = SESSION_SEED_USER_AGENTS[(index - 1) % SESSION_SEED_USER_AGENTS.length];
422
458
  const sessionData = {
423
459
  userId: userId,
424
460
  expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000), // 7 days from now
425
461
  token: `session_token_${index}_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`,
426
462
  ipAddress: ipAddress,
427
- 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,
428
464
  createdAt: new Date(),
429
465
  updatedAt: new Date(),
430
466
  };
@@ -488,4 +524,3 @@ export async function createMockVerification(adapter, _userId, index) {
488
524
  };
489
525
  return await adapter.createVerification(verificationData);
490
526
  }
491
- //# sourceMappingURL=auth-adapter.js.map
@@ -1,4 +1,3 @@
1
1
  export declare function initCommand(options?: {
2
2
  apiDir?: string;
3
3
  }): Promise<void>;
4
- //# sourceMappingURL=init.d.ts.map
@@ -252,4 +252,3 @@ function detectFramework() {
252
252
  catch { }
253
253
  return "unknown";
254
254
  }
255
- //# sourceMappingURL=init.js.map
package/dist/cli.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  #!/usr/bin/env node
2
2
  export {};
3
- //# sourceMappingURL=cli.d.ts.map
package/dist/cli.js CHANGED
@@ -281,6 +281,12 @@ program
281
281
  else if (content.includes("prismaAdapter")) {
282
282
  databaseInfo = "Prisma";
283
283
  }
284
+ else if (content.includes("kyselyAdapter") ||
285
+ content.includes("Kysely") ||
286
+ content.includes('from "kysely"') ||
287
+ content.includes("from 'kysely'")) {
288
+ databaseInfo = "Kysely";
289
+ }
284
290
  else if (authConfig.database.adapter && authConfig.database.provider) {
285
291
  const adapter = authConfig.database.adapter;
286
292
  const adapterName = adapter.charAt(0).toUpperCase() + adapter.slice(1);
@@ -364,4 +370,3 @@ program
364
370
  }
365
371
  });
366
372
  program.parse();
367
- //# sourceMappingURL=cli.js.map
package/dist/config.d.ts CHANGED
@@ -50,4 +50,3 @@ export declare function getConfig({ cwd, configPath, shouldThrowOnError, noCache
50
50
  }): Promise<any>;
51
51
  export { possiblePaths };
52
52
  export declare function findAuthConfig(configPath?: string): Promise<AuthConfig | null>;
53
- //# sourceMappingURL=config.d.ts.map
package/dist/config.js CHANGED
@@ -298,4 +298,3 @@ export async function findAuthConfig(configPath) {
298
298
  return null;
299
299
  }
300
300
  }
301
- //# sourceMappingURL=config.js.map
@@ -9,4 +9,3 @@ export declare function initializeEventIngestionAndHooks(config: StudioConfig):
9
9
  */
10
10
  export declare function handleStudioRequest(request: UniversalRequest, config: StudioConfig): Promise<UniversalResponse>;
11
11
  export declare function getAuthAdapter(auth: any): Promise<any>;
12
- //# sourceMappingURL=handler.d.ts.map
@@ -5,6 +5,7 @@ import { createClickHouseProvider, createHttpProvider, createNodeSqliteProvider,
5
5
  import { initializeEventIngestion, isEventIngestionInitialized } from "../utils/event-ingestion.js";
6
6
  import { injectEventHooks, injectLastSeenAtHooks } from "../utils/hook-injector.js";
7
7
  import { serveIndexHtml as getIndexHtml } from "../utils/html-injector.js";
8
+ import { evaluateRequestAccess } from "../utils/access-rules.js";
8
9
  import { decryptSession, isSessionValid, STUDIO_COOKIE_NAME } from "../utils/session.js";
9
10
  const __filename = fileURLToPath(import.meta.url);
10
11
  const __dirname = dirname(__filename);
@@ -32,6 +33,7 @@ export async function initializeEventIngestionAndHooks(config) {
32
33
  case "postgres":
33
34
  case "prisma":
34
35
  case "drizzle":
36
+ case "kysely":
35
37
  try {
36
38
  provider = createPostgresProvider({
37
39
  client: config.events.client,
@@ -132,10 +134,28 @@ export async function handleStudioRequest(request, config) {
132
134
  if (path === "" || path === "/") {
133
135
  path = "/";
134
136
  }
137
+ if (isSelfHosted) {
138
+ const accessDecision = evaluateRequestAccess({
139
+ accessConfig: config.access,
140
+ path,
141
+ method: request.method,
142
+ headers: request.headers,
143
+ ip: request.ip,
144
+ });
145
+ if (!accessDecision.allowed) {
146
+ return jsonResponse(403, {
147
+ success: false,
148
+ message: accessDecision.message,
149
+ reason: accessDecision.reason,
150
+ ...(accessDecision.ipAddress ? { ipAddress: accessDecision.ipAddress } : {}),
151
+ });
152
+ }
153
+ }
135
154
  if (path.startsWith("/assets/") ||
136
155
  path === "/vite.svg" ||
137
156
  path === "/favicon.svg" ||
138
- path === "/logo.png") {
157
+ path === "/logo.png" ||
158
+ path === "/shaders.png") {
139
159
  return handleStaticFile(path, config);
140
160
  }
141
161
  if (path === "/") {
@@ -154,6 +174,16 @@ export async function handleStudioRequest(request, config) {
154
174
  }
155
175
  return await handleApiRoute(request, path, config);
156
176
  }
177
+ if (isSelfHosted && (path === "/auth" || path.startsWith("/auth/"))) {
178
+ const apiPath = "/api" + path;
179
+ if (isProtectedApiPath(apiPath)) {
180
+ const sessionResult = verifyStudioSession(request, config);
181
+ if (!sessionResult.valid) {
182
+ return jsonResponse(401, { error: "Unauthorized", message: sessionResult.error });
183
+ }
184
+ }
185
+ return await handleApiRoute(request, apiPath, config);
186
+ }
157
187
  if (isSelfHosted) {
158
188
  const acceptHeader = request.headers["accept"] || request.headers["Accept"] || "";
159
189
  const wantsJson = acceptHeader.includes("application/json") ||
@@ -251,6 +281,7 @@ async function handleApiRoute(request, path, config) {
251
281
  path: path,
252
282
  method: request.method,
253
283
  headers: request.headers,
284
+ ip: request.ip,
254
285
  body: request.body,
255
286
  auth: config.auth,
256
287
  basePath: config.basePath || "/api/studio",
@@ -258,8 +289,9 @@ async function handleApiRoute(request, path, config) {
258
289
  studioConfig: config,
259
290
  });
260
291
  const headers = { "Content-Type": "application/json" };
292
+ const setCookies = [];
261
293
  if (result.cookies && result.cookies.length > 0) {
262
- const cookieStrings = result.cookies.map((c) => {
294
+ setCookies.push(...result.cookies.map((c) => {
263
295
  let cookie = `${c.name}=${c.value}`;
264
296
  if (c.options.httpOnly)
265
297
  cookie += "; HttpOnly";
@@ -272,12 +304,12 @@ async function handleApiRoute(request, path, config) {
272
304
  if (c.options.path)
273
305
  cookie += `; Path=${c.options.path}`;
274
306
  return cookie;
275
- });
276
- headers["Set-Cookie"] = cookieStrings.join(", ");
307
+ }));
277
308
  }
278
309
  return {
279
310
  status: result.status,
280
311
  headers,
312
+ ...(setCookies.length > 0 ? { setCookies } : {}),
281
313
  body: JSON.stringify(result.data),
282
314
  };
283
315
  }
@@ -600,4 +632,3 @@ function getCacheControl(path) {
600
632
  }
601
633
  return "no-cache";
602
634
  }
603
- //# sourceMappingURL=handler.js.map
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;
@@ -35,4 +42,3 @@ export interface PaginatedResult<T> {
35
42
  totalPages: number;
36
43
  }
37
44
  export declare function getAuthData(_authConfig: AuthConfig, type?: "stats" | "users" | "sessions" | "providers" | "deleteUser" | "updateUser" | "analytics", options?: any, configPath?: string, preloadedAdapter?: any): Promise<any>;
38
- //# sourceMappingURL=data.d.ts.map
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 [
@@ -594,4 +629,3 @@ async function getRealAnalytics(adapter, options) {
594
629
  };
595
630
  }
596
631
  }
597
- //# sourceMappingURL=data.js.map
@@ -26,4 +26,3 @@ export declare function initializeGeoService(): Promise<void>;
26
26
  */
27
27
  export declare function resolveIPLocationAsync(ipAddress: string, ipConfig?: IpAddressProviderConfig | null): Promise<LocationData | null>;
28
28
  export declare function resolveIPLocation(ipAddress: string): LocationData | null;
29
- //# sourceMappingURL=geo-service.d.ts.map
@@ -321,4 +321,3 @@ function isIPInRange(ip, minIP, maxIP) {
321
321
  const maxNum = ipToNumber(maxIP);
322
322
  return ipNum >= minNum && ipNum <= maxNum;
323
323
  }
324
- //# sourceMappingURL=geo-service.js.map
@@ -10,4 +10,3 @@ export interface TsConfig {
10
10
  [key: string]: any;
11
11
  }
12
12
  export declare function getTsconfigInfo(cwd?: string, tsconfigPath?: string): TsConfig;
13
- //# sourceMappingURL=get-tsconfig-info.d.ts.map
@@ -13,4 +13,3 @@ export function getTsconfigInfo(cwd, tsconfigPath) {
13
13
  return {};
14
14
  }
15
15
  }
16
- //# sourceMappingURL=get-tsconfig-info.js.map
package/dist/index.d.ts CHANGED
@@ -7,4 +7,3 @@ export { defineStudioConfig, STUDIO_TOOL_IDS } from "./types/handler.js";
7
7
  export { injectLastSeenAtHooks } from "./utils/hook-injector.js";
8
8
  export { checkEventIngestionHealth, emitEvent, getEventIngestionProvider, getEventQueueSize, initializeEventIngestion, isEventIngestionInitialized, shutdownEventIngestion, } from "./utils/event-ingestion.js";
9
9
  import "./utils/server-init.js";
10
- //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -5,4 +5,3 @@ export { defineStudioConfig, STUDIO_TOOL_IDS } from "./types/handler.js";
5
5
  export { injectLastSeenAtHooks } from "./utils/hook-injector.js";
6
6
  export { checkEventIngestionHealth, emitEvent, getEventIngestionProvider, getEventQueueSize, initializeEventIngestion, isEventIngestionInitialized, shutdownEventIngestion, } from "./utils/event-ingestion.js";
7
7
  import "./utils/server-init.js";
8
- //# sourceMappingURL=index.js.map
@@ -1,9 +1,10 @@
1
1
  import type { AuthEvent, EventIngestionProvider } from "../../types/events.js";
2
+ type PostgresProviderClientType = "postgres" | "prisma" | "drizzle" | "kysely";
2
3
  export declare function createPostgresProvider(options: {
3
4
  client: any;
4
5
  tableName?: string;
5
6
  schema?: string;
6
- clientType?: "postgres" | "prisma" | "drizzle";
7
+ clientType?: PostgresProviderClientType;
7
8
  }): EventIngestionProvider;
8
9
  export declare function createSqliteProvider(options: {
9
10
  client: any;
@@ -33,4 +34,4 @@ export declare function createStorageProvider(options: {
33
34
  adapter: any;
34
35
  tableName?: string;
35
36
  }): EventIngestionProvider;
36
- //# sourceMappingURL=helpers.d.ts.map
37
+ export {};