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
@@ -1,141 +1,145 @@
1
- import { emitEvent } from './event-ingestion.js';
1
+ import { emitEvent } from "./event-ingestion.js";
2
2
  export function wrapDatabaseHooks(auth, eventsConfig) {
3
- if (!auth || !eventsConfig?.enabled) {
4
- return;
3
+ if (!auth || !eventsConfig?.enabled) {
4
+ return;
5
+ }
6
+ try {
7
+ // Ensure auth.options exists
8
+ if (!auth.options) {
9
+ auth.options = {};
10
+ }
11
+ // Only proceed if auth.options is a valid object
12
+ if (typeof auth.options !== "object" || auth.options === null) {
13
+ console.warn("[Database Hooks] auth.options is not a valid object");
14
+ return;
15
+ }
16
+ const capturedConfig = eventsConfig;
17
+ // Initialize databaseHooks if it doesn't exist
18
+ if (!auth.options.databaseHooks) {
19
+ auth.options.databaseHooks = {};
20
+ }
21
+ // Check if already wrapped
22
+ if (auth.options.databaseHooks.__studio_wrapped) {
23
+ return;
24
+ }
25
+ // Ensure databaseHooks is an object
26
+ if (typeof auth.options.databaseHooks !== "object" || auth.options.databaseHooks === null) {
27
+ console.warn("[Database Hooks] databaseHooks is not a valid object");
28
+ return;
5
29
  }
6
30
  try {
7
- // Ensure auth.options exists
8
- if (!auth.options) {
9
- auth.options = {};
10
- }
11
- // Only proceed if auth.options is a valid object
12
- if (typeof auth.options !== 'object' || auth.options === null) {
13
- console.warn('[Database Hooks] auth.options is not a valid object');
14
- return;
31
+ const existingAccountHooks = auth.options.databaseHooks.account || {};
32
+ const existingCreateHooks = existingAccountHooks.create || {};
33
+ const existingAfter = existingCreateHooks.after;
34
+ const oauthAccountAfter = async (account, context) => {
35
+ // Validate context and internalAdapter exist
36
+ if (!context || !context.internalAdapter) {
37
+ console.warn("[OAuth DB Hook] Context or internalAdapter is missing");
38
+ return;
15
39
  }
16
- const capturedConfig = eventsConfig;
17
- // Initialize databaseHooks if it doesn't exist
18
- if (!auth.options.databaseHooks) {
19
- auth.options.databaseHooks = {};
40
+ // Validate account exists
41
+ if (!account || !account.userId || !account.providerId) {
42
+ return;
20
43
  }
21
- // Check if already wrapped
22
- if (auth.options.databaseHooks.__studio_wrapped) {
23
- return;
24
- }
25
- // Ensure databaseHooks is an object
26
- if (typeof auth.options.databaseHooks !== 'object' || auth.options.databaseHooks === null) {
27
- console.warn('[Database Hooks] databaseHooks is not a valid object');
28
- return;
29
- }
30
- try {
31
- const existingAccountHooks = auth.options.databaseHooks.account || {};
32
- const existingCreateHooks = existingAccountHooks.create || {};
33
- const existingAfter = existingCreateHooks.after;
34
- const oauthAccountAfter = async (account, context) => {
35
- // Validate context and internalAdapter exist
36
- if (!context || !context.internalAdapter) {
37
- console.warn('[OAuth DB Hook] Context or internalAdapter is missing');
38
- return;
39
- }
40
- // Validate account exists
41
- if (!account || !account.userId || !account.providerId) {
42
- return;
43
- }
44
- console.log('OAuth account created', account);
45
- if (account.providerId !== 'credential') {
46
- try {
47
- // Ensure internalAdapter methods exist
48
- if (typeof context.internalAdapter.findUserById !== 'function' ||
49
- typeof context.internalAdapter.findAccounts !== 'function') {
50
- console.warn('[OAuth DB Hook] internalAdapter methods are missing');
51
- return;
52
- }
53
- const user = await context.internalAdapter.findUserById(account.userId);
54
- if (user) {
55
- const existingAccounts = await context.internalAdapter.findAccounts(account.userId);
56
- const isLinking = existingAccounts && existingAccounts.length > 1; // More than just this new account
57
- if (isLinking) {
58
- await emitEvent('oauth.linked', {
59
- status: 'success',
60
- userId: account.userId,
61
- metadata: {
62
- provider: account.providerId,
63
- providerId: account.providerId,
64
- userEmail: user.email,
65
- email: user.email,
66
- name: user.name,
67
- accountId: account.accountId,
68
- linkedAt: new Date().toISOString(),
69
- },
70
- }, capturedConfig).catch(() => { });
71
- }
72
- else {
73
- await emitEvent('oauth.sign_in', {
74
- status: 'success',
75
- userId: account.userId,
76
- metadata: {
77
- provider: account.providerId,
78
- providerId: account.providerId,
79
- userEmail: user.email,
80
- email: user.email,
81
- name: user.name,
82
- emailVerified: user.emailVerified,
83
- accountId: account.accountId,
84
- createdAt: user.createdAt
85
- ? new Date(user.createdAt).toISOString()
86
- : new Date().toISOString(),
87
- },
88
- }, capturedConfig).catch(() => { });
89
- }
90
- }
91
- }
92
- catch (error) {
93
- console.error('[OAuth DB Hook] Error:', error);
94
- }
95
- }
96
- };
97
- // Safely assign the hook - wrap in try-catch to prevent any Better Auth initialization errors
98
- try {
99
- auth.options.databaseHooks.account = {
100
- ...existingAccountHooks,
101
- create: {
102
- ...existingCreateHooks,
103
- before: existingCreateHooks.before,
104
- after: async (account, context) => {
105
- try {
106
- // Call existing hook first if it exists
107
- if (existingAfter && typeof existingAfter === 'function') {
108
- await existingAfter(account, context);
109
- }
110
- // Then call our OAuth tracking hook
111
- await oauthAccountAfter(account, context);
112
- }
113
- catch (error) {
114
- // Don't let hook errors break the flow
115
- console.error('[Database Hook] Error in after hook:', error);
116
- // Re-throw only if it's not a reloadNavigation error (Better Auth internal issue)
117
- if (error instanceof Error && !error.message.includes('reloadNavigation')) {
118
- throw error;
119
- }
120
- }
121
- },
122
- },
123
- };
124
- auth.options.databaseHooks.__studio_wrapped = true;
44
+ console.log("OAuth account created", account);
45
+ if (account.providerId !== "credential") {
46
+ try {
47
+ // Ensure internalAdapter methods exist
48
+ if (
49
+ typeof context.internalAdapter.findUserById !== "function" ||
50
+ typeof context.internalAdapter.findAccounts !== "function"
51
+ ) {
52
+ console.warn("[OAuth DB Hook] internalAdapter methods are missing");
53
+ return;
125
54
  }
126
- catch (assignError) {
127
- // If assignment fails, log but don't crash
128
- console.error('[Database Hooks] Error assigning hooks:', assignError);
129
- // Don't mark as wrapped if assignment failed
55
+ const user = await context.internalAdapter.findUserById(account.userId);
56
+ if (user) {
57
+ const existingAccounts = await context.internalAdapter.findAccounts(account.userId);
58
+ const isLinking = existingAccounts && existingAccounts.length > 1; // More than just this new account
59
+ if (isLinking) {
60
+ await emitEvent(
61
+ "oauth.linked",
62
+ {
63
+ status: "success",
64
+ userId: account.userId,
65
+ metadata: {
66
+ provider: account.providerId,
67
+ providerId: account.providerId,
68
+ userEmail: user.email,
69
+ email: user.email,
70
+ name: user.name,
71
+ accountId: account.accountId,
72
+ linkedAt: new Date().toISOString(),
73
+ },
74
+ },
75
+ capturedConfig,
76
+ ).catch(() => {});
77
+ } else {
78
+ await emitEvent(
79
+ "oauth.sign_in",
80
+ {
81
+ status: "success",
82
+ userId: account.userId,
83
+ metadata: {
84
+ provider: account.providerId,
85
+ providerId: account.providerId,
86
+ userEmail: user.email,
87
+ email: user.email,
88
+ name: user.name,
89
+ emailVerified: user.emailVerified,
90
+ accountId: account.accountId,
91
+ createdAt: user.createdAt
92
+ ? new Date(user.createdAt).toISOString()
93
+ : new Date().toISOString(),
94
+ },
95
+ },
96
+ capturedConfig,
97
+ ).catch(() => {});
98
+ }
130
99
  }
100
+ } catch (error) {
101
+ console.error("[OAuth DB Hook] Error:", error);
102
+ }
131
103
  }
132
- catch (hookError) {
133
- console.error('[Database Hooks] Error setting up hooks:', hookError);
134
- // Don't mark as wrapped if there was an error
135
- }
136
- }
137
- catch (error) {
138
- console.error('[Database Hooks] Failed to wrap:', error);
104
+ };
105
+ // Safely assign the hook - wrap in try-catch to prevent any Better Auth initialization errors
106
+ try {
107
+ auth.options.databaseHooks.account = {
108
+ ...existingAccountHooks,
109
+ create: {
110
+ ...existingCreateHooks,
111
+ before: existingCreateHooks.before,
112
+ after: async (account, context) => {
113
+ try {
114
+ // Call existing hook first if it exists
115
+ if (existingAfter && typeof existingAfter === "function") {
116
+ await existingAfter(account, context);
117
+ }
118
+ // Then call our OAuth tracking hook
119
+ await oauthAccountAfter(account, context);
120
+ } catch (error) {
121
+ // Don't let hook errors break the flow
122
+ console.error("[Database Hook] Error in after hook:", error);
123
+ // Re-throw only if it's not a reloadNavigation error (Better Auth internal issue)
124
+ if (error instanceof Error && !error.message.includes("reloadNavigation")) {
125
+ throw error;
126
+ }
127
+ }
128
+ },
129
+ },
130
+ };
131
+ auth.options.databaseHooks.__studio_wrapped = true;
132
+ } catch (assignError) {
133
+ // If assignment fails, log but don't crash
134
+ console.error("[Database Hooks] Error assigning hooks:", assignError);
135
+ // Don't mark as wrapped if assignment failed
136
+ }
137
+ } catch (hookError) {
138
+ console.error("[Database Hooks] Error setting up hooks:", hookError);
139
+ // Don't mark as wrapped if there was an error
139
140
  }
141
+ } catch (error) {
142
+ console.error("[Database Hooks] Failed to wrap:", error);
143
+ }
140
144
  }
141
- //# sourceMappingURL=database-hook-injector.js.map
145
+ //# sourceMappingURL=database-hook-injector.js.map
@@ -1,4 +1,4 @@
1
- import type { StudioConfig } from '../types/handler.js';
1
+ import type { StudioConfig } from "../types/handler.js";
2
2
  /**
3
3
  * Wraps email-otp plugin callbacks to automatically emit events
4
4
  * This wraps the sendVerificationOTP callback similar to how organization hooks work
@@ -7,15 +7,27 @@ import type { StudioConfig } from '../types/handler.js';
7
7
  * @param existingCallback - The original sendVerificationOTP callback
8
8
  * @param passwordResetMethodMap - Optional shared Map to track password reset method (OTP vs token)
9
9
  */
10
- export declare function wrapEmailOTPPluginCallbacks(eventsConfig: StudioConfig['events'], existingCallback?: (data: {
11
- email: string;
12
- otp: string;
13
- type: 'sign-in' | 'email-verification' | 'forget-password';
14
- }, ctx?: any) => Promise<void>, passwordResetMethodMap?: Map<string, 'otp' | 'token'>): ((data: {
15
- email: string;
16
- otp: string;
17
- type: 'sign-in' | 'email-verification' | 'forget-password';
18
- }, ctx?: any) => Promise<void>) | undefined;
10
+ export declare function wrapEmailOTPPluginCallbacks(
11
+ eventsConfig: StudioConfig["events"],
12
+ existingCallback?: (
13
+ data: {
14
+ email: string;
15
+ otp: string;
16
+ type: "sign-in" | "email-verification" | "forget-password";
17
+ },
18
+ ctx?: any,
19
+ ) => Promise<void>,
20
+ passwordResetMethodMap?: Map<string, "otp" | "token">,
21
+ ):
22
+ | ((
23
+ data: {
24
+ email: string;
25
+ otp: string;
26
+ type: "sign-in" | "email-verification" | "forget-password";
27
+ },
28
+ ctx?: any,
29
+ ) => Promise<void>)
30
+ | undefined;
19
31
  /**
20
32
  * Automatically wraps email-otp plugin callbacks to emit events
21
33
  * This should be called during Better Auth initialization
@@ -25,5 +37,9 @@ export declare function wrapEmailOTPPluginCallbacks(eventsConfig: StudioConfig['
25
37
  * @param eventsConfig - The events configuration
26
38
  * @param passwordResetMethodMap - Optional shared Map to track password reset method (OTP vs token)
27
39
  */
28
- export declare function wrapEmailOTPPluginHooks(auth: any, eventsConfig: StudioConfig['events'], passwordResetMethodMap?: Map<string, 'otp' | 'token'>): void;
29
- //# sourceMappingURL=email-otp-hooks-injector.d.ts.map
40
+ export declare function wrapEmailOTPPluginHooks(
41
+ auth: any,
42
+ eventsConfig: StudioConfig["events"],
43
+ passwordResetMethodMap?: Map<string, "otp" | "token">,
44
+ ): void;
45
+ //# sourceMappingURL=email-otp-hooks-injector.d.ts.map
@@ -1,40 +1,37 @@
1
- import { emitEvent } from './event-ingestion.js';
1
+ import { emitEvent } from "./event-ingestion.js";
2
2
  /**
3
3
  * Helper to extract request info from Better Auth request object
4
4
  */
5
5
  function getRequestInfo(request) {
6
- const headersObj = {};
7
- let ip;
8
- if (request) {
9
- try {
10
- if (request instanceof Request) {
11
- request.headers.forEach((value, key) => {
12
- headersObj[key] = value;
13
- });
14
- ip =
15
- request.headers.get('x-forwarded-for') || request.headers.get('x-real-ip') || undefined;
16
- }
17
- else if (request.headers) {
18
- if (typeof request.headers.get === 'function') {
19
- ip =
20
- request.headers.get('x-forwarded-for') || request.headers.get('x-real-ip') || undefined;
21
- request.headers.forEach?.((value, key) => {
22
- headersObj[key] = value;
23
- });
24
- }
25
- else {
26
- ip = request.headers['x-forwarded-for'] || request.headers['x-real-ip'] || undefined;
27
- Object.entries(request.headers).forEach(([key, value]) => {
28
- headersObj[key] = String(value);
29
- });
30
- }
31
- }
32
- }
33
- catch (e) {
34
- // Ignore errors
6
+ const headersObj = {};
7
+ let ip;
8
+ if (request) {
9
+ try {
10
+ if (request instanceof Request) {
11
+ request.headers.forEach((value, key) => {
12
+ headersObj[key] = value;
13
+ });
14
+ ip =
15
+ request.headers.get("x-forwarded-for") || request.headers.get("x-real-ip") || undefined;
16
+ } else if (request.headers) {
17
+ if (typeof request.headers.get === "function") {
18
+ ip =
19
+ request.headers.get("x-forwarded-for") || request.headers.get("x-real-ip") || undefined;
20
+ request.headers.forEach?.((value, key) => {
21
+ headersObj[key] = value;
22
+ });
23
+ } else {
24
+ ip = request.headers["x-forwarded-for"] || request.headers["x-real-ip"] || undefined;
25
+ Object.entries(request.headers).forEach(([key, value]) => {
26
+ headersObj[key] = String(value);
27
+ });
35
28
  }
29
+ }
30
+ } catch (e) {
31
+ // Ignore errors
36
32
  }
37
- return { headers: headersObj, ip };
33
+ }
34
+ return { headers: headersObj, ip };
38
35
  }
39
36
  // Share password reset method tracking with auth-callbacks-injector
40
37
  // This is used to determine if password reset was via OTP or token
@@ -50,45 +47,52 @@ function getRequestInfo(request) {
50
47
  * @param existingCallback - The original sendVerificationOTP callback
51
48
  * @param passwordResetMethodMap - Optional shared Map to track password reset method (OTP vs token)
52
49
  */
53
- export function wrapEmailOTPPluginCallbacks(eventsConfig, existingCallback, passwordResetMethodMap) {
54
- if (!eventsConfig?.enabled) {
55
- return existingCallback;
56
- }
57
- if (!existingCallback) {
58
- return undefined;
50
+ export function wrapEmailOTPPluginCallbacks(
51
+ eventsConfig,
52
+ existingCallback,
53
+ passwordResetMethodMap,
54
+ ) {
55
+ if (!eventsConfig?.enabled) {
56
+ return existingCallback;
57
+ }
58
+ if (!existingCallback) {
59
+ return undefined;
60
+ }
61
+ const capturedConfig = eventsConfig;
62
+ return async (data, ctx) => {
63
+ const requestInfo = getRequestInfo(ctx?.request || ctx);
64
+ // Call the original callback first
65
+ const originalPromise = existingCallback(data, ctx);
66
+ // Track and emit event for password reset OTP
67
+ if (data.type === "forget-password") {
68
+ const email = data.email.toLowerCase();
69
+ // Track that this is an OTP-based password reset
70
+ // This will be checked by onPasswordReset in auth-callbacks-injector
71
+ if (passwordResetMethodMap) {
72
+ passwordResetMethodMap.set(email, "otp");
73
+ }
74
+ // Emit event for password reset OTP requested
75
+ const eventPromise = emitEvent(
76
+ "password.reset_requested_otp",
77
+ {
78
+ status: "success",
79
+ metadata: {
80
+ email: data.email,
81
+ type: "forget-password",
82
+ requestedAt: new Date().toISOString(),
83
+ },
84
+ request: requestInfo,
85
+ },
86
+ capturedConfig,
87
+ ).catch(() => {});
88
+ // Wait for original callback to complete
89
+ await originalPromise;
90
+ // Don't wait for event emission to avoid blocking
91
+ eventPromise.catch(() => {});
92
+ } else {
93
+ await originalPromise;
59
94
  }
60
- const capturedConfig = eventsConfig;
61
- return async (data, ctx) => {
62
- const requestInfo = getRequestInfo(ctx?.request || ctx);
63
- // Call the original callback first
64
- const originalPromise = existingCallback(data, ctx);
65
- // Track and emit event for password reset OTP
66
- if (data.type === 'forget-password') {
67
- const email = data.email.toLowerCase();
68
- // Track that this is an OTP-based password reset
69
- // This will be checked by onPasswordReset in auth-callbacks-injector
70
- if (passwordResetMethodMap) {
71
- passwordResetMethodMap.set(email, 'otp');
72
- }
73
- // Emit event for password reset OTP requested
74
- const eventPromise = emitEvent('password.reset_requested_otp', {
75
- status: 'success',
76
- metadata: {
77
- email: data.email,
78
- type: 'forget-password',
79
- requestedAt: new Date().toISOString(),
80
- },
81
- request: requestInfo,
82
- }, capturedConfig).catch(() => { });
83
- // Wait for original callback to complete
84
- await originalPromise;
85
- // Don't wait for event emission to avoid blocking
86
- eventPromise.catch(() => { });
87
- }
88
- else {
89
- await originalPromise;
90
- }
91
- };
95
+ };
92
96
  }
93
97
  /**
94
98
  * Automatically wraps email-otp plugin callbacks to emit events
@@ -100,35 +104,38 @@ export function wrapEmailOTPPluginCallbacks(eventsConfig, existingCallback, pass
100
104
  * @param passwordResetMethodMap - Optional shared Map to track password reset method (OTP vs token)
101
105
  */
102
106
  export function wrapEmailOTPPluginHooks(auth, eventsConfig, passwordResetMethodMap) {
103
- if (!auth || !eventsConfig?.enabled) {
104
- return;
107
+ if (!auth || !eventsConfig?.enabled) {
108
+ return;
109
+ }
110
+ try {
111
+ const plugins = auth.options?.plugins || [];
112
+ const emailOtpPlugin = plugins.find((p) => p?.id === "email-otp");
113
+ if (!emailOtpPlugin) {
114
+ return;
105
115
  }
106
- try {
107
- const plugins = auth.options?.plugins || [];
108
- const emailOtpPlugin = plugins.find((p) => p?.id === 'email-otp');
109
- if (!emailOtpPlugin) {
110
- return;
111
- }
112
- // Check if already wrapped to avoid double wrapping
113
- if (emailOtpPlugin.__studio_callbacks_wrapped) {
114
- return;
115
- }
116
- // Wrap the sendVerificationOTP callback
117
- const existingSendVerificationOTP = emailOtpPlugin.options?.sendVerificationOTP;
118
- if (existingSendVerificationOTP) {
119
- const wrappedCallback = wrapEmailOTPPluginCallbacks(eventsConfig, existingSendVerificationOTP, passwordResetMethodMap);
120
- if (wrappedCallback) {
121
- if (!emailOtpPlugin.options) {
122
- emailOtpPlugin.options = {};
123
- }
124
- emailOtpPlugin.options.sendVerificationOTP = wrappedCallback;
125
- }
126
- }
127
- // Mark as wrapped to prevent double wrapping
128
- emailOtpPlugin.__studio_callbacks_wrapped = true;
116
+ // Check if already wrapped to avoid double wrapping
117
+ if (emailOtpPlugin.__studio_callbacks_wrapped) {
118
+ return;
129
119
  }
130
- catch (error) {
131
- console.error('[Email OTP Callbacks] Failed to wrap callbacks:', error);
120
+ // Wrap the sendVerificationOTP callback
121
+ const existingSendVerificationOTP = emailOtpPlugin.options?.sendVerificationOTP;
122
+ if (existingSendVerificationOTP) {
123
+ const wrappedCallback = wrapEmailOTPPluginCallbacks(
124
+ eventsConfig,
125
+ existingSendVerificationOTP,
126
+ passwordResetMethodMap,
127
+ );
128
+ if (wrappedCallback) {
129
+ if (!emailOtpPlugin.options) {
130
+ emailOtpPlugin.options = {};
131
+ }
132
+ emailOtpPlugin.options.sendVerificationOTP = wrappedCallback;
133
+ }
132
134
  }
135
+ // Mark as wrapped to prevent double wrapping
136
+ emailOtpPlugin.__studio_callbacks_wrapped = true;
137
+ } catch (error) {
138
+ console.error("[Email OTP Callbacks] Failed to wrap callbacks:", error);
139
+ }
133
140
  }
134
- //# sourceMappingURL=email-otp-hooks-injector.js.map
141
+ //# sourceMappingURL=email-otp-hooks-injector.js.map
@@ -1,14 +1,14 @@
1
- import type { AuthEventType, EventIngestionProvider } from '../types/events.js';
2
- import type { StudioConfig } from '../types/handler.js';
1
+ import type { AuthEventType, EventIngestionProvider } from "../types/events.js";
2
+ import type { StudioConfig } from "../types/handler.js";
3
3
  /**
4
4
  * Initialize event ingestion
5
5
  */
6
- export declare function initializeEventIngestion(eventsConfig: StudioConfig['events']): void;
6
+ export declare function initializeEventIngestion(eventsConfig: StudioConfig["events"]): void;
7
7
  /**
8
8
  * Emit an event
9
9
  */
10
10
  export declare function emitEvent(type: AuthEventType, data: {
11
- status: 'success' | 'failed';
11
+ status: "success" | "failed";
12
12
  userId?: string;
13
13
  sessionId?: string;
14
14
  organizationId?: string;
@@ -17,7 +17,7 @@ export declare function emitEvent(type: AuthEventType, data: {
17
17
  headers: Record<string, string>;
18
18
  ip?: string;
19
19
  };
20
- }, eventsConfig?: StudioConfig['events']): Promise<void>;
20
+ }, eventsConfig?: StudioConfig["events"]): Promise<void>;
21
21
  export declare function shutdownEventIngestion(): Promise<void>;
22
22
  /**
23
23
  * Health check
@@ -1 +1 @@
1
- {"version":3,"file":"event-ingestion.d.ts","sourceRoot":"","sources":["../../src/utils/event-ingestion.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAEV,aAAa,EACb,sBAAsB,EAGvB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AASxD;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,YAAY,EAAE,YAAY,CAAC,QAAQ,CAAC,GAAG,IAAI,CAiEnF;AAED;;GAEG;AACH,wBAAsB,SAAS,CAC7B,IAAI,EAAE,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