better-auth-studio 1.1.2-beta.2 → 1.1.2-beta.21

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 (109) hide show
  1. package/README.md +48 -78
  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 +116 -115
  32. package/dist/core/handler.js.map +1 -1
  33. package/dist/data.d.ts +2 -2
  34. package/dist/data.js +60 -60
  35. package/dist/geo-service.js +78 -78
  36. package/dist/get-tsconfig-info.js +4 -4
  37. package/dist/index.d.ts +8 -8
  38. package/dist/index.js +6 -6
  39. package/dist/providers/events/helpers.d.ts +2 -2
  40. package/dist/providers/events/helpers.d.ts.map +1 -1
  41. package/dist/providers/events/helpers.js +178 -154
  42. package/dist/providers/events/helpers.js.map +1 -1
  43. package/dist/public/assets/{main-BDJUrMKx.js → main-BeCk6LUx.js} +133 -133
  44. package/dist/public/assets/main-w2bJSKlF.css +1 -0
  45. package/dist/public/index.html +2 -2
  46. package/dist/routes/api-router.d.ts +3 -1
  47. package/dist/routes/api-router.d.ts.map +1 -1
  48. package/dist/routes/api-router.js +3 -3
  49. package/dist/routes/api-router.js.map +1 -1
  50. package/dist/routes.d.ts +6 -4
  51. package/dist/routes.d.ts.map +1 -1
  52. package/dist/routes.js +1333 -1277
  53. package/dist/routes.js.map +1 -1
  54. package/dist/studio.d.ts +3 -3
  55. package/dist/studio.d.ts.map +1 -1
  56. package/dist/studio.js +64 -65
  57. package/dist/studio.js.map +1 -1
  58. package/dist/types/events.d.ts +8 -7
  59. package/dist/types/events.d.ts.map +1 -1
  60. package/dist/types/events.js +165 -165
  61. package/dist/types/events.js.map +1 -1
  62. package/dist/types/handler.d.ts +14 -4
  63. package/dist/types/handler.d.ts.map +1 -1
  64. package/dist/types/handler.js.map +1 -1
  65. package/dist/utils/auth-callbacks-injector.d.ts +2 -2
  66. package/dist/utils/auth-callbacks-injector.js +27 -27
  67. package/dist/utils/auth-callbacks-wrapper.d.ts +3 -3
  68. package/dist/utils/auth-callbacks-wrapper.js +117 -107
  69. package/dist/utils/database-detection.d.ts +1 -1
  70. package/dist/utils/database-detection.js +44 -44
  71. package/dist/utils/database-hook-injector.d.ts +3 -3
  72. package/dist/utils/database-hook-injector.js +135 -131
  73. package/dist/utils/email-otp-hooks-injector.d.ts +28 -12
  74. package/dist/utils/email-otp-hooks-injector.js +104 -97
  75. package/dist/utils/event-ingestion.d.ts +5 -5
  76. package/dist/utils/event-ingestion.d.ts.map +1 -1
  77. package/dist/utils/event-ingestion.js +32 -12
  78. package/dist/utils/event-ingestion.js.map +1 -1
  79. package/dist/utils/hook-injector.d.ts +2 -2
  80. package/dist/utils/hook-injector.js +199 -199
  81. package/dist/utils/hook-injector.js.map +1 -1
  82. package/dist/utils/html-injector.d.ts +11 -2
  83. package/dist/utils/html-injector.d.ts.map +1 -1
  84. package/dist/utils/html-injector.js +40 -39
  85. package/dist/utils/html-injector.js.map +1 -1
  86. package/dist/utils/org-hooks-injector.d.ts +3 -3
  87. package/dist/utils/org-hooks-injector.js +63 -63
  88. package/dist/utils/org-hooks-wrapper.d.ts +41 -35
  89. package/dist/utils/org-hooks-wrapper.js +778 -658
  90. package/dist/utils/organization-hooks-wrapper.d.ts +23 -17
  91. package/dist/utils/organization-hooks-wrapper.js +325 -277
  92. package/dist/utils/package-json.js +11 -11
  93. package/dist/utils/paths.js +1 -1
  94. package/dist/utils/server-init.d.ts +1 -1
  95. package/dist/utils/server-init.js +25 -25
  96. package/dist/utils/session.d.ts +0 -1
  97. package/dist/utils/session.d.ts.map +1 -1
  98. package/dist/utils/session.js +19 -12
  99. package/dist/utils/session.js.map +1 -1
  100. package/dist/utils.js +24 -24
  101. package/package.json +56 -47
  102. package/public/assets/{main-BDJUrMKx.js → main-BeCk6LUx.js} +133 -133
  103. package/public/assets/main-w2bJSKlF.css +1 -0
  104. package/public/index.html +2 -2
  105. package/scripts/download-geolite2.js +8 -8
  106. package/scripts/generate-default-db.js +324 -324
  107. package/scripts/postinstall.js +25 -25
  108. package/dist/public/assets/main-CBA9bZ-w.css +0 -1
  109. package/public/assets/main-CBA9bZ-w.css +0 -1
@@ -1,9 +1,9 @@
1
- import { createAuthMiddleware } from 'better-auth/plugins';
2
- import { createClickHouseProvider, createHttpProvider, createPostgresProvider, createSqliteProvider, } from '../providers/events/helpers.js';
3
- import { wrapAuthCallbacks } from './auth-callbacks-injector.js';
4
- import { emitEvent, isEventIngestionInitialized, } from './event-ingestion.js';
5
- import { wrapOrganizationPluginHooks } from './org-hooks-injector.js';
6
- const INJECTED_HOOKS_MARKER = '__better_auth_studio_events_injected__';
1
+ import { createAuthMiddleware } from "better-auth/plugins";
2
+ import { createClickHouseProvider, createHttpProvider, createPostgresProvider, createSqliteProvider, } from "../providers/events/helpers.js";
3
+ import { wrapAuthCallbacks } from "./auth-callbacks-injector.js";
4
+ import { emitEvent, isEventIngestionInitialized, } from "./event-ingestion.js";
5
+ import { wrapOrganizationPluginHooks } from "./org-hooks-injector.js";
6
+ const INJECTED_HOOKS_MARKER = "__better_auth_studio_events_injected__";
7
7
  /**
8
8
  * Create a Better Auth plugin for event ingestion
9
9
  */
@@ -16,13 +16,13 @@ function createEventIngestionPlugin(eventsConfig) {
16
16
  }
17
17
  setTimeout(() => {
18
18
  try {
19
- const path = ctx?.path || ctx?.context?.path || '';
19
+ const path = ctx?.path || ctx?.context?.path || "";
20
20
  if (!path)
21
21
  return;
22
22
  const returned = ctx?.context?.returned;
23
23
  if (!returned)
24
24
  return;
25
- if (typeof returned === 'object' && returned !== null) {
25
+ if (typeof returned === "object" && returned !== null) {
26
26
  try {
27
27
  const _ = returned.statusCode;
28
28
  }
@@ -35,30 +35,30 @@ function createEventIngestionPlugin(eventsConfig) {
35
35
  let ip = null;
36
36
  const headersObj = {};
37
37
  try {
38
- if (ctx.headers && typeof ctx.headers === 'object') {
39
- if (typeof ctx.headers.get === 'function') {
38
+ if (ctx.headers && typeof ctx.headers === "object") {
39
+ if (typeof ctx.headers.get === "function") {
40
40
  try {
41
- ip = ctx.headers.get('x-forwarded-for') || ctx.headers.get('x-real-ip') || null;
41
+ ip = ctx.headers.get("x-forwarded-for") || ctx.headers.get("x-real-ip") || null;
42
42
  }
43
43
  catch (e) { }
44
44
  }
45
45
  else {
46
- ip = ctx.headers['x-forwarded-for'] || ctx.headers['x-real-ip'] || null;
46
+ ip = ctx.headers["x-forwarded-for"] || ctx.headers["x-real-ip"] || null;
47
47
  }
48
48
  }
49
49
  }
50
50
  catch (e) { }
51
- if (path === '/sign-up' || path === '/sign-up/email') {
51
+ if (path === "/sign-up" || path === "/sign-up/email") {
52
52
  const body = ctx.body || {};
53
53
  const user = returned || ctx.context.returned;
54
54
  if (!isError) {
55
- emitEvent('user.joined', {
56
- status: 'success',
55
+ emitEvent("user.joined", {
56
+ status: "success",
57
57
  userId: returned.user.id,
58
- sessionId: '',
58
+ sessionId: "",
59
59
  metadata: {
60
- email: body.email || returned.user.email || '',
61
- name: body.name || returned.user.name || '',
60
+ email: body.email || returned.user.email || "",
61
+ name: body.name || returned.user.name || "",
62
62
  },
63
63
  request: {
64
64
  headers: headersObj,
@@ -67,16 +67,16 @@ function createEventIngestionPlugin(eventsConfig) {
67
67
  }, capturedConfig).catch(() => { });
68
68
  }
69
69
  else if (isError) {
70
- emitEvent('user.joined', {
71
- status: 'failed',
70
+ emitEvent("user.joined", {
71
+ status: "failed",
72
72
  metadata: {
73
73
  email: body.email,
74
74
  name: body.name,
75
75
  reason: returned.statusCode === 400
76
- ? 'validation_failed'
76
+ ? "validation_failed"
77
77
  : returned.statusCode === 409
78
- ? 'user_already_exists'
79
- : returned.body?.code || returned.body?.message || 'unknown',
78
+ ? "user_already_exists"
79
+ : returned.body?.code || returned.body?.message || "unknown",
80
80
  },
81
81
  request: {
82
82
  headers: headersObj,
@@ -85,13 +85,13 @@ function createEventIngestionPlugin(eventsConfig) {
85
85
  }, capturedConfig).catch(() => { });
86
86
  }
87
87
  }
88
- if (path === '/sign-in' || path === '/sign-in/email') {
88
+ if (path === "/sign-in" || path === "/sign-in/email") {
89
89
  const body = ctx.body || {};
90
90
  const user = returned.user || ctx.context?.returned;
91
91
  const session = returned.newSession || ctx.context?.newSession;
92
92
  if (!isError) {
93
- emitEvent('user.logged_in', {
94
- status: 'success',
93
+ emitEvent("user.logged_in", {
94
+ status: "success",
95
95
  userId: user.id,
96
96
  sessionId: session?.id,
97
97
  metadata: {
@@ -105,8 +105,8 @@ function createEventIngestionPlugin(eventsConfig) {
105
105
  }, capturedConfig).catch(() => { });
106
106
  // Also emit session.created
107
107
  if (session) {
108
- emitEvent('session.created', {
109
- status: 'success',
108
+ emitEvent("session.created", {
109
+ status: "success",
110
110
  userId: user.id,
111
111
  sessionId: session.id,
112
112
  metadata: {
@@ -122,13 +122,13 @@ function createEventIngestionPlugin(eventsConfig) {
122
122
  }
123
123
  }
124
124
  else if (isError) {
125
- emitEvent('user.logged_in', {
126
- status: 'failed',
125
+ emitEvent("user.logged_in", {
126
+ status: "failed",
127
127
  metadata: {
128
128
  email: body.email,
129
129
  reason: returned.statusCode === 401
130
- ? 'invalid_credentials'
131
- : returned.body?.code || 'unknown',
130
+ ? "invalid_credentials"
131
+ : returned.body?.code || "unknown",
132
132
  },
133
133
  request: {
134
134
  headers: headersObj,
@@ -137,12 +137,12 @@ function createEventIngestionPlugin(eventsConfig) {
137
137
  }, capturedConfig).catch(() => { });
138
138
  }
139
139
  }
140
- if (path === '/sign-out') {
140
+ if (path === "/sign-out") {
141
141
  const session = beforeSession;
142
142
  const { user, session: sessionData } = session || {};
143
143
  if (!isError && user) {
144
- emitEvent('user.logged_out', {
145
- status: 'success',
144
+ emitEvent("user.logged_out", {
145
+ status: "success",
146
146
  userId: user.id,
147
147
  sessionId: sessionData?.id,
148
148
  metadata: {
@@ -157,17 +157,17 @@ function createEventIngestionPlugin(eventsConfig) {
157
157
  }
158
158
  }
159
159
  // OAuth unlinked
160
- if (path === '/unlink-account') {
160
+ if (path === "/unlink-account") {
161
161
  const session = ctx.context?.session;
162
162
  const unlinkReturned = ctx.context?.returned || returned;
163
163
  const body = ctx.body || {};
164
164
  if (!isError &&
165
165
  session &&
166
166
  unlinkReturned &&
167
- typeof unlinkReturned === 'object' &&
168
- 'status' in unlinkReturned) {
169
- emitEvent('oauth.unlinked', {
170
- status: 'success',
167
+ typeof unlinkReturned === "object" &&
168
+ "status" in unlinkReturned) {
169
+ emitEvent("oauth.unlinked", {
170
+ status: "success",
171
171
  userId: session.user.id,
172
172
  metadata: {
173
173
  provider: body.providerId || body.provider,
@@ -181,13 +181,13 @@ function createEventIngestionPlugin(eventsConfig) {
181
181
  }, capturedConfig).catch(() => { });
182
182
  }
183
183
  else if (isError) {
184
- emitEvent('oauth.unlinked', {
185
- status: 'failed',
184
+ emitEvent("oauth.unlinked", {
185
+ status: "failed",
186
186
  metadata: {
187
187
  provider: body.providerId || body.provider,
188
188
  reason: returned.statusCode === 400
189
- ? 'invalid_request'
190
- : returned.body?.code || returned.body?.message || 'unknown',
189
+ ? "invalid_request"
190
+ : returned.body?.code || returned.body?.message || "unknown",
191
191
  },
192
192
  request: {
193
193
  headers: headersObj,
@@ -196,10 +196,10 @@ function createEventIngestionPlugin(eventsConfig) {
196
196
  }, capturedConfig).catch(() => { });
197
197
  }
198
198
  }
199
- const isCallbackPath = path.startsWith('/callback/') ||
200
- path.startsWith('/callback') ||
201
- path.startsWith('/oauth2/callback/') ||
202
- path.startsWith('/oauth2/callback');
199
+ const isCallbackPath = path.startsWith("/callback/") ||
200
+ path.startsWith("/callback") ||
201
+ path.startsWith("/oauth2/callback/") ||
202
+ path.startsWith("/oauth2/callback");
203
203
  if (isCallbackPath) {
204
204
  try {
205
205
  const newSession = ctx.context?.newSession || returned?.newSession;
@@ -208,23 +208,23 @@ function createEventIngestionPlugin(eventsConfig) {
208
208
  returned?.data?.user ||
209
209
  ctx.context?.user ||
210
210
  ctx.user ||
211
- (returned?.data && typeof returned.data === 'object' && 'user' in returned.data
211
+ (returned?.data && typeof returned.data === "object" && "user" in returned.data
212
212
  ? returned.data.user
213
213
  : null);
214
214
  const existingUser = ctx.context?.existingUser;
215
215
  const params = ctx.params;
216
216
  if (user) {
217
- const provider = path.includes('/callback/')
218
- ? path.split('/callback/')[1]?.split('/')[0]
219
- : path.includes('/oauth2/callback/')
220
- ? path.split('/oauth2/callback/')[1]?.split('/')[0]
221
- : path.includes('/callback')
222
- ? path.split('/callback')[1]?.split('/')[1] ||
223
- path.split('/callback')[1]?.split('?')[0]
217
+ const provider = path.includes("/callback/")
218
+ ? path.split("/callback/")[1]?.split("/")[0]
219
+ : path.includes("/oauth2/callback/")
220
+ ? path.split("/oauth2/callback/")[1]?.split("/")[0]
221
+ : path.includes("/callback")
222
+ ? path.split("/callback")[1]?.split("/")[1] ||
223
+ path.split("/callback")[1]?.split("?")[0]
224
224
  : undefined;
225
225
  if (existingUser) {
226
- emitEvent('oauth.linked', {
227
- status: 'success',
226
+ emitEvent("oauth.linked", {
227
+ status: "success",
228
228
  userId: user.id,
229
229
  metadata: {
230
230
  provider: params.id,
@@ -239,8 +239,8 @@ function createEventIngestionPlugin(eventsConfig) {
239
239
  }
240
240
  else {
241
241
  // New user signing in via OAuth
242
- emitEvent('oauth.sign_in', {
243
- status: 'success',
242
+ emitEvent("oauth.sign_in", {
243
+ status: "success",
244
244
  userId: user.id,
245
245
  sessionId: newSession?.session?.id || newSession?.id,
246
246
  metadata: {
@@ -258,8 +258,8 @@ function createEventIngestionPlugin(eventsConfig) {
258
258
  }, capturedConfig)
259
259
  .then(() => {
260
260
  if (!isError && newSession && user) {
261
- emitEvent('session.created', {
262
- status: 'success',
261
+ emitEvent("session.created", {
262
+ status: "success",
263
263
  userId: user.id,
264
264
  sessionId: newSession.session?.id || newSession.id,
265
265
  metadata: {
@@ -274,14 +274,14 @@ function createEventIngestionPlugin(eventsConfig) {
274
274
  }, capturedConfig).catch(() => { });
275
275
  }
276
276
  else if (isError) {
277
- emitEvent('session.created', {
278
- status: 'failed',
277
+ emitEvent("session.created", {
278
+ status: "failed",
279
279
  metadata: {
280
280
  reason: returned.statusCode === 401
281
- ? 'authentication_failed'
282
- : returned.body?.code || 'unknown',
283
- provider: path.includes('/callback/')
284
- ? path.split('/callback/')[1]?.split('/')[0]
281
+ ? "authentication_failed"
282
+ : returned.body?.code || "unknown",
283
+ provider: path.includes("/callback/")
284
+ ? path.split("/callback/")[1]?.split("/")[0]
285
285
  : undefined,
286
286
  },
287
287
  request: {
@@ -296,19 +296,19 @@ function createEventIngestionPlugin(eventsConfig) {
296
296
  }
297
297
  }
298
298
  catch (callbackError) {
299
- const errorMessage = callbackError?.message || String(callbackError || '');
300
- if (!errorMessage.includes('reloadNavigation') &&
301
- !errorMessage.includes('Cannot read properties of undefined')) {
302
- console.error('[OAuth Callback] Error:', errorMessage);
299
+ const errorMessage = callbackError?.message || String(callbackError || "");
300
+ if (!errorMessage.includes("reloadNavigation") &&
301
+ !errorMessage.includes("Cannot read properties of undefined")) {
302
+ console.error("[OAuth Callback] Error:", errorMessage);
303
303
  }
304
304
  }
305
305
  }
306
- if (path === '/admin/ban-user') {
306
+ if (path === "/admin/ban-user") {
307
307
  const body = ctx.body || {};
308
308
  const user = returned?.user || ctx.context?.returned?.user || ctx.context?.user;
309
309
  if (!isError && user) {
310
- emitEvent('user.banned', {
311
- status: 'success',
310
+ emitEvent("user.banned", {
311
+ status: "success",
312
312
  userId: user.id,
313
313
  metadata: {
314
314
  email: user.email,
@@ -321,10 +321,10 @@ function createEventIngestionPlugin(eventsConfig) {
321
321
  }, capturedConfig).catch(() => { });
322
322
  }
323
323
  else if (isError) {
324
- emitEvent('user.banned', {
325
- status: 'failed',
324
+ emitEvent("user.banned", {
325
+ status: "failed",
326
326
  metadata: {
327
- reason: returned.body?.code || returned.body?.message || 'unknown',
327
+ reason: returned.body?.code || returned.body?.message || "unknown",
328
328
  },
329
329
  request: {
330
330
  headers: headersObj,
@@ -333,12 +333,12 @@ function createEventIngestionPlugin(eventsConfig) {
333
333
  }, capturedConfig).catch(() => { });
334
334
  }
335
335
  }
336
- if (path === '/admin/unban-user') {
336
+ if (path === "/admin/unban-user") {
337
337
  const body = ctx.body || {};
338
338
  const user = returned?.user || ctx.context?.returned?.user || ctx.context?.user;
339
339
  if (!isError && user) {
340
- emitEvent('user.unbanned', {
341
- status: 'success',
340
+ emitEvent("user.unbanned", {
341
+ status: "success",
342
342
  userId: user.id,
343
343
  metadata: {
344
344
  email: user.email,
@@ -351,10 +351,10 @@ function createEventIngestionPlugin(eventsConfig) {
351
351
  }, capturedConfig).catch(() => { });
352
352
  }
353
353
  else if (isError) {
354
- emitEvent('user.unbanned', {
355
- status: 'failed',
354
+ emitEvent("user.unbanned", {
355
+ status: "failed",
356
356
  metadata: {
357
- reason: returned.body?.code || returned.body?.message || 'unknown',
357
+ reason: returned.body?.code || returned.body?.message || "unknown",
358
358
  },
359
359
  request: {
360
360
  headers: headersObj,
@@ -363,7 +363,7 @@ function createEventIngestionPlugin(eventsConfig) {
363
363
  }, capturedConfig).catch(() => { });
364
364
  }
365
365
  }
366
- if (path === '/update-user') {
366
+ if (path === "/update-user") {
367
367
  const updateReturned = ctx.context?.returned || returned;
368
368
  const session = ctx.context?.session;
369
369
  const oldData = ctx.context?._oldUserData;
@@ -384,8 +384,8 @@ function createEventIngestionPlugin(eventsConfig) {
384
384
  oldValues.email = oldData?.email;
385
385
  }
386
386
  if (Object.keys(updatedFields).length > 0) {
387
- emitEvent('user.updated', {
388
- status: 'success',
387
+ emitEvent("user.updated", {
388
+ status: "success",
389
389
  userId: session.user.id,
390
390
  metadata: {
391
391
  email: session.user.email,
@@ -402,16 +402,16 @@ function createEventIngestionPlugin(eventsConfig) {
402
402
  }
403
403
  }
404
404
  else if (isError) {
405
- emitEvent('user.updated', {
406
- status: 'failed',
405
+ emitEvent("user.updated", {
406
+ status: "failed",
407
407
  metadata: {
408
408
  reason: returned.statusCode === 400
409
- ? 'validation_failed'
409
+ ? "validation_failed"
410
410
  : returned.statusCode === 401
411
- ? 'unauthorized'
411
+ ? "unauthorized"
412
412
  : returned.statusCode === 403
413
- ? 'forbidden'
414
- : returned.body?.code || returned.body?.message || 'unknown',
413
+ ? "forbidden"
414
+ : returned.body?.code || returned.body?.message || "unknown",
415
415
  },
416
416
  request: {
417
417
  headers: headersObj,
@@ -421,18 +421,18 @@ function createEventIngestionPlugin(eventsConfig) {
421
421
  }
422
422
  }
423
423
  // Organization operation
424
- if (path === '/organization/create') {
424
+ if (path === "/organization/create") {
425
425
  const body = ctx.body || {};
426
426
  const organization = returned?.organization || ctx.context?.returned?.organization;
427
427
  const session = ctx.context?.session;
428
428
  if (!isError && organization && session) {
429
429
  }
430
430
  else if (isError) {
431
- emitEvent('organization.created', {
432
- status: 'failed',
431
+ emitEvent("organization.created", {
432
+ status: "failed",
433
433
  userId: session?.user?.id,
434
434
  metadata: {
435
- organizationName: body.name || organization?.name || 'Unknown',
435
+ organizationName: body.name || organization?.name || "Unknown",
436
436
  reason: returned.body?.message || returned.body.code,
437
437
  },
438
438
  request: {
@@ -442,7 +442,7 @@ function createEventIngestionPlugin(eventsConfig) {
442
442
  }, capturedConfig).catch(() => { });
443
443
  }
444
444
  }
445
- if (path === '/organization/update') {
445
+ if (path === "/organization/update") {
446
446
  const body = ctx.body || {};
447
447
  const organization = returned?.organization || ctx.context?.returned?.organization;
448
448
  const session = ctx.context?.session;
@@ -450,12 +450,12 @@ function createEventIngestionPlugin(eventsConfig) {
450
450
  // Success is handled by hooks
451
451
  }
452
452
  else if (isError) {
453
- emitEvent('organization.updated', {
454
- status: 'failed',
453
+ emitEvent("organization.updated", {
454
+ status: "failed",
455
455
  organizationId: body.id || body.organizationId,
456
456
  userId: session?.user?.id,
457
457
  metadata: {
458
- organizationName: body.name || organization?.name || 'Unknown',
458
+ organizationName: body.name || organization?.name || "Unknown",
459
459
  reason: returned.body?.message || returned.body.code,
460
460
  },
461
461
  request: {
@@ -465,7 +465,7 @@ function createEventIngestionPlugin(eventsConfig) {
465
465
  }, capturedConfig).catch(() => { });
466
466
  }
467
467
  }
468
- if (path === '/organization/delete') {
468
+ if (path === "/organization/delete") {
469
469
  const body = ctx.body || {};
470
470
  const organization = returned?.organization || ctx.context?.returned?.organization;
471
471
  const session = ctx.context?.session;
@@ -473,12 +473,12 @@ function createEventIngestionPlugin(eventsConfig) {
473
473
  // Success is handled by hooks
474
474
  }
475
475
  else if (isError) {
476
- emitEvent('organization.deleted', {
477
- status: 'failed',
476
+ emitEvent("organization.deleted", {
477
+ status: "failed",
478
478
  organizationId: body.id || body.organizationId,
479
479
  userId: session?.user?.id,
480
480
  metadata: {
481
- organizationName: organization?.name || 'Unknown',
481
+ organizationName: organization?.name || "Unknown",
482
482
  reason: returned.body?.message || returned.body.code,
483
483
  },
484
484
  request: {
@@ -489,15 +489,15 @@ function createEventIngestionPlugin(eventsConfig) {
489
489
  }
490
490
  }
491
491
  // Member operations
492
- if (path === '/organization/add-member' || path === '/member/add') {
492
+ if (path === "/organization/add-member" || path === "/member/add") {
493
493
  const body = ctx.body || {};
494
494
  const member = returned?.member || ctx.context?.returned?.member;
495
495
  const session = ctx.context?.session;
496
496
  if (!isError && member && session) {
497
497
  }
498
498
  else if (isError) {
499
- emitEvent('member.added', {
500
- status: 'failed',
499
+ emitEvent("member.added", {
500
+ status: "failed",
501
501
  organizationId: body.organizationId,
502
502
  userId: body.userId || member?.userId,
503
503
  metadata: {
@@ -510,20 +510,20 @@ function createEventIngestionPlugin(eventsConfig) {
510
510
  }, capturedConfig).catch(() => { });
511
511
  }
512
512
  }
513
- if (path === '/organization/remove-member' || path === '/member/remove') {
513
+ if (path === "/organization/remove-member" || path === "/member/remove") {
514
514
  const body = ctx.body || {};
515
515
  const session = ctx.context?.session;
516
516
  if (!isError && session) {
517
517
  }
518
518
  else if (isError) {
519
- emitEvent('member.removed', {
520
- status: 'failed',
519
+ emitEvent("member.removed", {
520
+ status: "failed",
521
521
  organizationId: body.organizationId,
522
522
  userId: body.userId,
523
523
  metadata: {
524
524
  reason: returned.statusCode === 404
525
- ? 'member_not_found'
526
- : returned.body?.code || returned.body?.message || 'unknown',
525
+ ? "member_not_found"
526
+ : returned.body?.code || returned.body?.message || "unknown",
527
527
  },
528
528
  request: {
529
529
  headers: headersObj,
@@ -532,7 +532,7 @@ function createEventIngestionPlugin(eventsConfig) {
532
532
  }, capturedConfig).catch(() => { });
533
533
  }
534
534
  }
535
- if (path === '/organization/update-member-role' || path === '/member/update-role') {
535
+ if (path === "/organization/update-member-role" || path === "/member/update-role") {
536
536
  const body = ctx.body || {};
537
537
  const member = returned?.member || ctx.context?.returned?.member;
538
538
  const session = ctx.context?.session;
@@ -540,16 +540,16 @@ function createEventIngestionPlugin(eventsConfig) {
540
540
  // Success is handled by hooks
541
541
  }
542
542
  else if (isError) {
543
- emitEvent('member.role_changed', {
544
- status: 'failed',
543
+ emitEvent("member.role_changed", {
544
+ status: "failed",
545
545
  organizationId: body.organizationId,
546
546
  userId: body.userId || member?.userId,
547
547
  metadata: {
548
548
  oldRole: body.oldRole,
549
549
  newRole: body.role || body.newRole,
550
550
  reason: returned.statusCode === 404
551
- ? 'member_not_found'
552
- : returned.body?.code || returned.body?.message || 'unknown',
551
+ ? "member_not_found"
552
+ : returned.body?.code || returned.body?.message || "unknown",
553
553
  },
554
554
  request: {
555
555
  headers: headersObj,
@@ -559,7 +559,7 @@ function createEventIngestionPlugin(eventsConfig) {
559
559
  }
560
560
  }
561
561
  // Team operations
562
- if (path === '/team/create' || path.startsWith('/team/create')) {
562
+ if (path === "/team/create" || path.startsWith("/team/create")) {
563
563
  const body = ctx.body || {};
564
564
  const team = returned?.team || ctx.context?.returned?.team;
565
565
  const session = ctx.context?.session;
@@ -567,15 +567,15 @@ function createEventIngestionPlugin(eventsConfig) {
567
567
  // Success is handled by hooks
568
568
  }
569
569
  else if (isError) {
570
- emitEvent('team.created', {
571
- status: 'failed',
570
+ emitEvent("team.created", {
571
+ status: "failed",
572
572
  organizationId: body.organizationId,
573
573
  userId: session?.user?.id,
574
574
  metadata: {
575
- teamName: body.name || 'Unknown',
575
+ teamName: body.name || "Unknown",
576
576
  reason: returned.statusCode === 400
577
- ? 'validation_failed'
578
- : returned.body?.code || returned.body?.message || 'unknown',
577
+ ? "validation_failed"
578
+ : returned.body?.code || returned.body?.message || "unknown",
579
579
  },
580
580
  request: {
581
581
  headers: headersObj,
@@ -584,7 +584,7 @@ function createEventIngestionPlugin(eventsConfig) {
584
584
  }, capturedConfig).catch(() => { });
585
585
  }
586
586
  }
587
- if (path === '/team/update' || path.startsWith('/team/update')) {
587
+ if (path === "/team/update" || path.startsWith("/team/update")) {
588
588
  const body = ctx.body || {};
589
589
  const team = returned?.team || ctx.context?.returned?.team;
590
590
  const session = ctx.context?.session;
@@ -592,13 +592,13 @@ function createEventIngestionPlugin(eventsConfig) {
592
592
  // Success is handled by hooks
593
593
  }
594
594
  else if (isError) {
595
- emitEvent('team.updated', {
596
- status: 'failed',
595
+ emitEvent("team.updated", {
596
+ status: "failed",
597
597
  organizationId: body.organizationId || team?.organizationId,
598
598
  userId: session?.user?.id,
599
599
  metadata: {
600
600
  teamId: body.id || body.teamId,
601
- teamName: body.name || team?.name || 'Unknown',
601
+ teamName: body.name || team?.name || "Unknown",
602
602
  reason: returned.body?.message || returned.body.code,
603
603
  },
604
604
  request: {
@@ -608,15 +608,15 @@ function createEventIngestionPlugin(eventsConfig) {
608
608
  }, capturedConfig).catch(() => { });
609
609
  }
610
610
  }
611
- if (path === '/team/delete' || path.startsWith('/team/delete')) {
611
+ if (path === "/team/delete" || path.startsWith("/team/delete")) {
612
612
  const body = ctx.body || {};
613
613
  const session = ctx.context?.session;
614
614
  if (!isError && session) {
615
615
  // Success is handled by hooks
616
616
  }
617
617
  else if (isError) {
618
- emitEvent('team.deleted', {
619
- status: 'failed',
618
+ emitEvent("team.deleted", {
619
+ status: "failed",
620
620
  organizationId: body.organizationId,
621
621
  userId: session?.user?.id,
622
622
  metadata: {
@@ -630,7 +630,7 @@ function createEventIngestionPlugin(eventsConfig) {
630
630
  }, capturedConfig).catch(() => { });
631
631
  }
632
632
  }
633
- if (path === '/team/add-member' || path.startsWith('/team/add-member')) {
633
+ if (path === "/team/add-member" || path.startsWith("/team/add-member")) {
634
634
  const body = ctx.body || {};
635
635
  const teamMember = returned?.teamMember || ctx.context?.returned?.teamMember;
636
636
  const session = ctx.context?.session;
@@ -638,8 +638,8 @@ function createEventIngestionPlugin(eventsConfig) {
638
638
  // Success is handled by hooks
639
639
  }
640
640
  else if (isError) {
641
- emitEvent('team.member.added', {
642
- status: 'failed',
641
+ emitEvent("team.member.added", {
642
+ status: "failed",
643
643
  organizationId: body.organizationId,
644
644
  userId: body.userId || teamMember?.userId,
645
645
  metadata: {
@@ -653,15 +653,15 @@ function createEventIngestionPlugin(eventsConfig) {
653
653
  }, capturedConfig).catch(() => { });
654
654
  }
655
655
  }
656
- if (path === '/team/remove-member' || path.startsWith('/team/remove-member')) {
656
+ if (path === "/team/remove-member" || path.startsWith("/team/remove-member")) {
657
657
  const body = ctx.body || {};
658
658
  const session = ctx.context?.session;
659
659
  if (!isError && session) {
660
660
  // Success is handled by hooks
661
661
  }
662
662
  else if (isError) {
663
- emitEvent('team.member.removed', {
664
- status: 'failed',
663
+ emitEvent("team.member.removed", {
664
+ status: "failed",
665
665
  organizationId: body.organizationId,
666
666
  userId: body.userId,
667
667
  metadata: {
@@ -676,7 +676,7 @@ function createEventIngestionPlugin(eventsConfig) {
676
676
  }
677
677
  }
678
678
  // Invitation operations
679
- if (path === '/invitation/create' || path.startsWith('/invitation/create')) {
679
+ if (path === "/invitation/create" || path.startsWith("/invitation/create")) {
680
680
  const body = ctx.body || {};
681
681
  const invitation = returned?.invitation || ctx.context?.returned?.invitation;
682
682
  const session = ctx.context?.session;
@@ -684,12 +684,12 @@ function createEventIngestionPlugin(eventsConfig) {
684
684
  // Success is handled by hooks
685
685
  }
686
686
  else if (isError) {
687
- emitEvent('invitation.created', {
688
- status: 'failed',
687
+ emitEvent("invitation.created", {
688
+ status: "failed",
689
689
  organizationId: body.organizationId,
690
690
  metadata: {
691
- email: body.email || 'Unknown',
692
- role: body.role || 'member',
691
+ email: body.email || "Unknown",
692
+ role: body.role || "member",
693
693
  reason: returned.body?.message || returned.body.code,
694
694
  },
695
695
  request: {
@@ -699,7 +699,7 @@ function createEventIngestionPlugin(eventsConfig) {
699
699
  }, capturedConfig).catch(() => { });
700
700
  }
701
701
  }
702
- if (path === '/invitation/accept' || path.startsWith('/invitation/accept')) {
702
+ if (path === "/invitation/accept" || path.startsWith("/invitation/accept")) {
703
703
  const body = ctx.body || {};
704
704
  const invitation = returned?.invitation || ctx.context?.returned?.invitation;
705
705
  const session = ctx.context?.session;
@@ -707,13 +707,13 @@ function createEventIngestionPlugin(eventsConfig) {
707
707
  // Success is handled by hooks
708
708
  }
709
709
  else if (isError) {
710
- emitEvent('invitation.accepted', {
711
- status: 'failed',
710
+ emitEvent("invitation.accepted", {
711
+ status: "failed",
712
712
  organizationId: invitation?.organizationId || body.organizationId,
713
713
  userId: session?.user?.id || body.userId,
714
714
  metadata: {
715
715
  invitationId: body.id || body.invitationId,
716
- email: invitation?.email || body.email || 'Unknown',
716
+ email: invitation?.email || body.email || "Unknown",
717
717
  reason: returned.body?.message || returned.body.code,
718
718
  },
719
719
  request: {
@@ -723,7 +723,7 @@ function createEventIngestionPlugin(eventsConfig) {
723
723
  }, capturedConfig).catch(() => { });
724
724
  }
725
725
  }
726
- if (path === '/invitation/reject' || path.startsWith('/invitation/reject')) {
726
+ if (path === "/invitation/reject" || path.startsWith("/invitation/reject")) {
727
727
  const body = ctx.body || {};
728
728
  const invitation = returned?.invitation || ctx.context?.returned?.invitation;
729
729
  const session = ctx.context?.session;
@@ -731,13 +731,13 @@ function createEventIngestionPlugin(eventsConfig) {
731
731
  // Success is handled by hooks
732
732
  }
733
733
  else if (isError) {
734
- emitEvent('invitation.rejected', {
735
- status: 'failed',
734
+ emitEvent("invitation.rejected", {
735
+ status: "failed",
736
736
  organizationId: invitation?.organizationId || body.organizationId,
737
737
  userId: session?.user?.id || body.userId,
738
738
  metadata: {
739
739
  invitationId: body.id || body.invitationId,
740
- email: invitation?.email || body.email || 'Unknown',
740
+ email: invitation?.email || body.email || "Unknown",
741
741
  reason: returned.body?.message || returned.body.code,
742
742
  },
743
743
  request: {
@@ -747,7 +747,7 @@ function createEventIngestionPlugin(eventsConfig) {
747
747
  }, capturedConfig).catch(() => { });
748
748
  }
749
749
  }
750
- if (path === '/invitation/cancel' || path.startsWith('/invitation/cancel')) {
750
+ if (path === "/invitation/cancel" || path.startsWith("/invitation/cancel")) {
751
751
  const body = ctx.body || {};
752
752
  const invitation = returned?.invitation || ctx.context?.returned?.invitation;
753
753
  const session = ctx.context?.session;
@@ -755,13 +755,13 @@ function createEventIngestionPlugin(eventsConfig) {
755
755
  // Success is handled by hooks
756
756
  }
757
757
  else if (isError) {
758
- emitEvent('invitation.cancelled', {
759
- status: 'failed',
758
+ emitEvent("invitation.cancelled", {
759
+ status: "failed",
760
760
  organizationId: invitation?.organizationId || body.organizationId,
761
761
  userId: session?.user?.id || body.userId,
762
762
  metadata: {
763
763
  invitationId: body.id || body.invitationId,
764
- email: invitation?.email || body.email || 'Unknown',
764
+ email: invitation?.email || body.email || "Unknown",
765
765
  reason: returned.body?.message || returned.body.code,
766
766
  },
767
767
  request: {
@@ -773,12 +773,12 @@ function createEventIngestionPlugin(eventsConfig) {
773
773
  }
774
774
  }
775
775
  catch (error) {
776
- const errorMessage = error?.message || String(error || '');
777
- if (errorMessage.includes('reloadNavigation') ||
778
- errorMessage.includes('Cannot read properties of undefined')) {
776
+ const errorMessage = error?.message || String(error || "");
777
+ if (errorMessage.includes("reloadNavigation") ||
778
+ errorMessage.includes("Cannot read properties of undefined")) {
779
779
  return;
780
780
  }
781
- console.error('[Event Hook] Error:', errorMessage);
781
+ console.error("[Event Hook] Error:", errorMessage);
782
782
  }
783
783
  }, 0);
784
784
  });
@@ -789,10 +789,10 @@ function createEventIngestionPlugin(eventsConfig) {
789
789
  if (!account || !account.userId || !account.providerId) {
790
790
  return;
791
791
  }
792
- if (account.providerId !== 'credential') {
792
+ if (account.providerId !== "credential") {
793
793
  try {
794
- if (typeof context.internalAdapter.findUserById !== 'function' ||
795
- typeof context.internalAdapter.findAccounts !== 'function') {
794
+ if (typeof context.internalAdapter.findUserById !== "function" ||
795
+ typeof context.internalAdapter.findAccounts !== "function") {
796
796
  return;
797
797
  }
798
798
  const user = await context.internalAdapter.findUserById(account.userId);
@@ -800,8 +800,8 @@ function createEventIngestionPlugin(eventsConfig) {
800
800
  const existingAccounts = await context.internalAdapter.findAccounts(account.userId);
801
801
  const isLinking = existingAccounts && existingAccounts.length > 1; // More than just this new account
802
802
  if (isLinking) {
803
- await emitEvent('oauth.linked', {
804
- status: 'success',
803
+ await emitEvent("oauth.linked", {
804
+ status: "success",
805
805
  userId: account.userId,
806
806
  metadata: {
807
807
  provider: account.providerId,
@@ -815,8 +815,8 @@ function createEventIngestionPlugin(eventsConfig) {
815
815
  }, capturedConfig).catch(() => { });
816
816
  }
817
817
  else {
818
- await emitEvent('oauth.sign_in', {
819
- status: 'success',
818
+ await emitEvent("oauth.sign_in", {
819
+ status: "success",
820
820
  userId: account.userId,
821
821
  metadata: {
822
822
  provider: account.providerId,
@@ -835,7 +835,7 @@ function createEventIngestionPlugin(eventsConfig) {
835
835
  }
836
836
  }
837
837
  catch (error) {
838
- console.error('[OAuth DB Hook] Error:', error);
838
+ console.error("[OAuth DB Hook] Error:", error);
839
839
  }
840
840
  }
841
841
  };
@@ -844,35 +844,35 @@ function createEventIngestionPlugin(eventsConfig) {
844
844
  if (!isEventIngestionInitialized() && capturedConfig?.enabled) {
845
845
  let provider;
846
846
  if (capturedConfig.provider &&
847
- typeof capturedConfig.provider === 'object' &&
848
- typeof capturedConfig.provider.ingest === 'function') {
847
+ typeof capturedConfig.provider === "object" &&
848
+ typeof capturedConfig.provider.ingest === "function") {
849
849
  provider = capturedConfig.provider;
850
850
  }
851
851
  else if (capturedConfig.client && capturedConfig.clientType) {
852
852
  try {
853
853
  switch (capturedConfig.clientType) {
854
- case 'postgres':
855
- case 'prisma':
856
- case 'drizzle':
854
+ case "postgres":
855
+ case "prisma":
856
+ case "drizzle":
857
857
  provider = createPostgresProvider({
858
858
  client: capturedConfig.client,
859
859
  tableName: capturedConfig.tableName,
860
860
  clientType: capturedConfig.clientType,
861
861
  });
862
862
  break;
863
- case 'sqlite':
863
+ case "sqlite":
864
864
  provider = createSqliteProvider({
865
865
  client: capturedConfig.client,
866
866
  tableName: capturedConfig.tableName,
867
867
  });
868
868
  break;
869
- case 'clickhouse':
869
+ case "clickhouse":
870
870
  provider = createClickHouseProvider({
871
871
  client: capturedConfig.client,
872
872
  table: capturedConfig.tableName,
873
873
  });
874
874
  break;
875
- case 'http':
875
+ case "https":
876
876
  provider = createHttpProvider({
877
877
  url: capturedConfig.client,
878
878
  headers: capturedConfig.headers || {},
@@ -899,7 +899,7 @@ function createEventIngestionPlugin(eventsConfig) {
899
899
  },
900
900
  };
901
901
  return {
902
- id: 'better-auth-studio-events',
902
+ id: "better-auth-studio-events",
903
903
  init: async (ctx) => {
904
904
  initializeEventIngestion(ctx);
905
905
  },
@@ -908,7 +908,7 @@ function createEventIngestionPlugin(eventsConfig) {
908
908
  initBeforeHook,
909
909
  {
910
910
  matcher: (context) => {
911
- return context.path === '/sign-out';
911
+ return context.path === "/sign-out";
912
912
  },
913
913
  handler: async (context) => {
914
914
  const body = context.body || {};
@@ -917,7 +917,7 @@ function createEventIngestionPlugin(eventsConfig) {
917
917
  },
918
918
  {
919
919
  matcher: (context) => {
920
- return context.path === '/update-user';
920
+ return context.path === "/update-user";
921
921
  },
922
922
  handler: async (context) => {
923
923
  const session = context.context?.session;
@@ -935,26 +935,26 @@ function createEventIngestionPlugin(eventsConfig) {
935
935
  after: [
936
936
  {
937
937
  matcher: (context) => {
938
- const path = context?.path || context?.context?.path || '';
939
- const shouldMatch = path === '/sign-up' ||
940
- path === '/sign-up/email' ||
941
- path === '/sign-in' ||
942
- path === '/sign-in/email' ||
943
- path.startsWith('/sign-in/social') ||
944
- path === '/sign-out' ||
945
- path === '/update-password' ||
946
- path === '/change-password' ||
947
- path === '/verify-email' ||
948
- path === '/forget-password' ||
949
- path === '/delete-user' ||
950
- path === '/unlink-account' ||
951
- path.startsWith('/callback') ||
952
- path.startsWith('/oauth2/callback') ||
953
- path === '/organization/create' ||
954
- path === '/organization/update' ||
955
- path === '/organization/delete' ||
956
- path === '/update-user' ||
957
- path.startsWith('/admin/');
938
+ const path = context?.path || context?.context?.path || "";
939
+ const shouldMatch = path === "/sign-up" ||
940
+ path === "/sign-up/email" ||
941
+ path === "/sign-in" ||
942
+ path === "/sign-in/email" ||
943
+ path.startsWith("/sign-in/social") ||
944
+ path === "/sign-out" ||
945
+ path === "/update-password" ||
946
+ path === "/change-password" ||
947
+ path === "/verify-email" ||
948
+ path === "/forget-password" ||
949
+ path === "/delete-user" ||
950
+ path === "/unlink-account" ||
951
+ path.startsWith("/callback") ||
952
+ path.startsWith("/oauth2/callback") ||
953
+ path === "/organization/create" ||
954
+ path === "/organization/update" ||
955
+ path === "/organization/delete" ||
956
+ path === "/update-user" ||
957
+ path.startsWith("/admin/");
958
958
  return shouldMatch;
959
959
  },
960
960
  handler: eventMiddleware,
@@ -989,7 +989,7 @@ export function injectEventHooks(auth, eventsConfig) {
989
989
  if (!auth.options.plugins) {
990
990
  auth.options.plugins = [];
991
991
  }
992
- const existingPlugin = auth.options.plugins.find((p) => p?.id === 'better-auth-studio-events');
992
+ const existingPlugin = auth.options.plugins.find((p) => p?.id === "better-auth-studio-events");
993
993
  if (!existingPlugin) {
994
994
  auth.options.plugins.push(eventPlugin);
995
995
  }
@@ -998,7 +998,7 @@ export function injectEventHooks(auth, eventsConfig) {
998
998
  wrapAuthCallbacks(auth, eventsConfig);
999
999
  }
1000
1000
  catch (error) {
1001
- console.error('[Event Hooks] Failed to inject:', error);
1001
+ console.error("[Event Hooks] Failed to inject:", error);
1002
1002
  }
1003
1003
  }
1004
1004
  //# sourceMappingURL=hook-injector.js.map