better-auth-studio 1.1.2-beta.2 → 1.1.2-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -78
- package/data/default-geo.json +1 -1
- package/dist/adapters/astro.d.ts +1 -1
- package/dist/adapters/astro.js +13 -13
- package/dist/adapters/elysia.d.ts +2 -2
- package/dist/adapters/elysia.js +13 -13
- package/dist/adapters/express.d.ts +2 -2
- package/dist/adapters/express.js +4 -4
- package/dist/adapters/hono.d.ts +2 -2
- package/dist/adapters/hono.js +12 -12
- package/dist/adapters/nextjs.d.ts +1 -1
- package/dist/adapters/nextjs.js +10 -10
- package/dist/adapters/nuxt.d.ts +1 -1
- package/dist/adapters/nuxt.js +22 -22
- package/dist/adapters/remix.d.ts +1 -1
- package/dist/adapters/remix.js +13 -13
- package/dist/adapters/solid-start.d.ts +1 -1
- package/dist/adapters/solid-start.js +13 -13
- package/dist/adapters/svelte-kit.d.ts +2 -2
- package/dist/adapters/svelte-kit.js +13 -13
- package/dist/adapters/tanstack-start.d.ts +1 -1
- package/dist/adapters/tanstack-start.js +13 -13
- package/dist/add-svelte-kit-env-modules.js +11 -11
- package/dist/auth-adapter.d.ts +1 -1
- package/dist/auth-adapter.js +96 -96
- package/dist/cli/commands/init.js +57 -57
- package/dist/cli.js +75 -75
- package/dist/config.d.ts +5 -5
- package/dist/config.js +37 -37
- package/dist/core/handler.d.ts +1 -1
- package/dist/core/handler.js +116 -115
- package/dist/core/handler.js.map +1 -1
- package/dist/data.d.ts +2 -2
- package/dist/data.js +60 -60
- package/dist/geo-service.js +78 -78
- package/dist/get-tsconfig-info.js +4 -4
- package/dist/index.d.ts +8 -8
- package/dist/index.js +6 -6
- package/dist/providers/events/helpers.d.ts +2 -2
- package/dist/providers/events/helpers.d.ts.map +1 -1
- package/dist/providers/events/helpers.js +178 -154
- package/dist/providers/events/helpers.js.map +1 -1
- package/dist/public/assets/{main-BDJUrMKx.js → main-BeCk6LUx.js} +133 -133
- package/dist/public/assets/main-w2bJSKlF.css +1 -0
- package/dist/public/index.html +2 -2
- package/dist/routes/api-router.d.ts +3 -1
- package/dist/routes/api-router.d.ts.map +1 -1
- package/dist/routes/api-router.js +3 -3
- package/dist/routes/api-router.js.map +1 -1
- package/dist/routes.d.ts +6 -4
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +1333 -1277
- package/dist/routes.js.map +1 -1
- package/dist/studio.d.ts +3 -3
- package/dist/studio.d.ts.map +1 -1
- package/dist/studio.js +64 -65
- package/dist/studio.js.map +1 -1
- package/dist/types/events.d.ts +8 -7
- package/dist/types/events.d.ts.map +1 -1
- package/dist/types/events.js +165 -165
- package/dist/types/events.js.map +1 -1
- package/dist/types/handler.d.ts +14 -4
- package/dist/types/handler.d.ts.map +1 -1
- package/dist/types/handler.js.map +1 -1
- package/dist/utils/auth-callbacks-injector.d.ts +2 -2
- package/dist/utils/auth-callbacks-injector.js +27 -27
- package/dist/utils/auth-callbacks-wrapper.d.ts +3 -3
- package/dist/utils/auth-callbacks-wrapper.js +117 -107
- package/dist/utils/database-detection.d.ts +1 -1
- package/dist/utils/database-detection.js +44 -44
- package/dist/utils/database-hook-injector.d.ts +3 -3
- package/dist/utils/database-hook-injector.js +135 -131
- package/dist/utils/email-otp-hooks-injector.d.ts +28 -12
- package/dist/utils/email-otp-hooks-injector.js +104 -97
- package/dist/utils/event-ingestion.d.ts +5 -5
- package/dist/utils/event-ingestion.d.ts.map +1 -1
- package/dist/utils/event-ingestion.js +32 -12
- package/dist/utils/event-ingestion.js.map +1 -1
- package/dist/utils/hook-injector.d.ts +2 -2
- package/dist/utils/hook-injector.js +199 -199
- package/dist/utils/html-injector.d.ts +11 -2
- package/dist/utils/html-injector.d.ts.map +1 -1
- package/dist/utils/html-injector.js +40 -39
- package/dist/utils/html-injector.js.map +1 -1
- package/dist/utils/org-hooks-injector.d.ts +3 -3
- package/dist/utils/org-hooks-injector.js +63 -63
- package/dist/utils/org-hooks-wrapper.d.ts +41 -35
- package/dist/utils/org-hooks-wrapper.js +778 -658
- package/dist/utils/organization-hooks-wrapper.d.ts +23 -17
- package/dist/utils/organization-hooks-wrapper.js +325 -277
- package/dist/utils/package-json.js +11 -11
- package/dist/utils/paths.js +1 -1
- package/dist/utils/server-init.d.ts +1 -1
- package/dist/utils/server-init.js +25 -25
- package/dist/utils/session.d.ts +0 -1
- package/dist/utils/session.d.ts.map +1 -1
- package/dist/utils/session.js +19 -12
- package/dist/utils/session.js.map +1 -1
- package/dist/utils.js +24 -24
- package/package.json +25 -24
- package/public/assets/{main-BDJUrMKx.js → main-BeCk6LUx.js} +133 -133
- package/public/assets/main-w2bJSKlF.css +1 -0
- package/public/index.html +2 -2
- package/scripts/download-geolite2.js +8 -8
- package/scripts/generate-default-db.js +324 -324
- package/scripts/postinstall.js +25 -25
- package/dist/public/assets/main-CBA9bZ-w.css +0 -1
- package/public/assets/main-CBA9bZ-w.css +0 -1
|
@@ -1,297 +1,345 @@
|
|
|
1
|
-
import { emitEvent } from
|
|
1
|
+
import { emitEvent } from "./event-ingestion.js";
|
|
2
2
|
/**
|
|
3
3
|
* Wraps organization hooks to automatically emit events
|
|
4
4
|
* This should be used in the organization plugin's organizationHooks option
|
|
5
5
|
*/
|
|
6
6
|
export function createOrganizationHooksWithEvents(eventsConfig, userHooks) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
7
|
+
if (!eventsConfig?.enabled) {
|
|
8
|
+
return userHooks || {};
|
|
9
|
+
}
|
|
10
|
+
const capturedConfig = eventsConfig;
|
|
11
|
+
// Helper to extract request info
|
|
12
|
+
// Note: Organization hooks don't receive request directly, so we return empty info
|
|
13
|
+
// The request info will be captured by the main hook injector for endpoint-based operations
|
|
14
|
+
const getRequestInfo = () => {
|
|
15
|
+
return { headers: {}, ip: undefined };
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
// Organization hooks
|
|
19
|
+
beforeCreateOrganization: userHooks?.beforeCreateOrganization
|
|
20
|
+
? async (data) => {
|
|
21
|
+
const result = await userHooks.beforeCreateOrganization(data);
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
: undefined,
|
|
25
|
+
afterCreateOrganization: userHooks?.afterCreateOrganization
|
|
26
|
+
? async (data) => {
|
|
27
|
+
await userHooks.afterCreateOrganization(data);
|
|
28
|
+
// Emit event
|
|
29
|
+
emitEvent(
|
|
30
|
+
"organization.created",
|
|
31
|
+
{
|
|
32
|
+
status: "success",
|
|
33
|
+
organizationId: data.organization.id,
|
|
34
|
+
userId: data.user.id,
|
|
35
|
+
metadata: {
|
|
36
|
+
organizationName: data.organization.name,
|
|
37
|
+
organizationSlug: data.organization.slug,
|
|
38
|
+
email: data.user.email,
|
|
39
|
+
name: data.user.name,
|
|
40
|
+
},
|
|
41
|
+
request: getRequestInfo(),
|
|
42
|
+
},
|
|
43
|
+
capturedConfig,
|
|
44
|
+
).catch(() => {});
|
|
45
|
+
}
|
|
46
|
+
: async (data) => {
|
|
47
|
+
// Emit event even if no user hook
|
|
48
|
+
emitEvent(
|
|
49
|
+
"organization.created",
|
|
50
|
+
{
|
|
51
|
+
status: "success",
|
|
52
|
+
organizationId: data.organization.id,
|
|
53
|
+
userId: data.user.id,
|
|
54
|
+
metadata: {
|
|
55
|
+
organizationName: data.organization.name,
|
|
56
|
+
organizationSlug: data.organization.slug,
|
|
57
|
+
email: data.user.email,
|
|
58
|
+
name: data.user.name,
|
|
59
|
+
},
|
|
60
|
+
request: getRequestInfo(),
|
|
61
|
+
},
|
|
62
|
+
capturedConfig,
|
|
63
|
+
).catch(() => {});
|
|
64
|
+
},
|
|
65
|
+
beforeUpdateOrganization: userHooks?.beforeUpdateOrganization
|
|
66
|
+
? async (data) => {
|
|
67
|
+
const result = await userHooks.beforeUpdateOrganization(data);
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
: undefined,
|
|
71
|
+
afterUpdateOrganization: userHooks?.afterUpdateOrganization
|
|
72
|
+
? async (data) => {
|
|
73
|
+
await userHooks.afterUpdateOrganization?.(data);
|
|
74
|
+
// Emit event
|
|
75
|
+
if (data.organization) {
|
|
76
|
+
emitEvent(
|
|
77
|
+
"organization.updated",
|
|
78
|
+
{
|
|
79
|
+
status: "success",
|
|
80
|
+
organizationId: data.organization.id,
|
|
81
|
+
userId: data.user.id,
|
|
82
|
+
metadata: {
|
|
83
|
+
organizationName: data.organization.name,
|
|
84
|
+
organizationSlug: data.organization.slug,
|
|
85
|
+
email: data.user.email,
|
|
86
|
+
name: data.user.name,
|
|
87
|
+
},
|
|
88
|
+
request: getRequestInfo(),
|
|
89
|
+
},
|
|
90
|
+
capturedConfig,
|
|
91
|
+
).catch(() => {});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
: async (data) => {
|
|
95
|
+
// Emit event even if no user hook
|
|
96
|
+
if (data.organization) {
|
|
97
|
+
emitEvent(
|
|
98
|
+
"organization.updated",
|
|
99
|
+
{
|
|
100
|
+
status: "success",
|
|
101
|
+
organizationId: data.organization.id,
|
|
102
|
+
userId: data.user.id,
|
|
103
|
+
metadata: {
|
|
104
|
+
organizationName: data.organization.name,
|
|
105
|
+
organizationSlug: data.organization.slug,
|
|
106
|
+
email: data.user.email,
|
|
107
|
+
name: data.user.name,
|
|
108
|
+
},
|
|
109
|
+
request: getRequestInfo(),
|
|
110
|
+
},
|
|
111
|
+
capturedConfig,
|
|
112
|
+
).catch(() => {});
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
beforeDeleteOrganization: userHooks?.beforeDeleteOrganization
|
|
116
|
+
? async (data) => {
|
|
117
|
+
await userHooks.beforeDeleteOrganization(data);
|
|
118
|
+
}
|
|
119
|
+
: undefined,
|
|
120
|
+
afterDeleteOrganization: userHooks?.afterDeleteOrganization
|
|
121
|
+
? async (data) => {
|
|
122
|
+
await userHooks.afterDeleteOrganization?.(data);
|
|
123
|
+
// Emit event
|
|
124
|
+
emitEvent(
|
|
125
|
+
"organization.deleted",
|
|
126
|
+
{
|
|
127
|
+
status: "success",
|
|
128
|
+
organizationId: data.organization.id,
|
|
129
|
+
userId: data.user.id,
|
|
130
|
+
metadata: {
|
|
131
|
+
organizationName: data.organization.name,
|
|
132
|
+
organizationSlug: data.organization.slug,
|
|
133
|
+
email: data.user.email,
|
|
134
|
+
name: data.user.name,
|
|
135
|
+
},
|
|
136
|
+
request: getRequestInfo(),
|
|
137
|
+
},
|
|
138
|
+
capturedConfig,
|
|
139
|
+
).catch(() => {});
|
|
140
|
+
}
|
|
141
|
+
: async (data) => {
|
|
142
|
+
// Emit event even if no user hook
|
|
143
|
+
emitEvent(
|
|
144
|
+
"organization.deleted",
|
|
145
|
+
{
|
|
146
|
+
status: "success",
|
|
147
|
+
organizationId: data.organization.id,
|
|
148
|
+
userId: data.user.id,
|
|
149
|
+
metadata: {
|
|
150
|
+
organizationName: data.organization.name,
|
|
151
|
+
organizationSlug: data.organization.slug,
|
|
152
|
+
email: data.user.email,
|
|
153
|
+
name: data.user.name,
|
|
154
|
+
},
|
|
155
|
+
request: getRequestInfo(),
|
|
56
156
|
},
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
organizationId: data.organization.id,
|
|
88
|
-
userId: data.user.id,
|
|
89
|
-
metadata: {
|
|
90
|
-
organizationName: data.organization.name,
|
|
91
|
-
organizationSlug: data.organization.slug,
|
|
92
|
-
email: data.user.email,
|
|
93
|
-
name: data.user.name,
|
|
94
|
-
},
|
|
95
|
-
request: getRequestInfo(),
|
|
96
|
-
}, capturedConfig).catch(() => { });
|
|
97
|
-
}
|
|
157
|
+
capturedConfig,
|
|
158
|
+
).catch(() => {});
|
|
159
|
+
},
|
|
160
|
+
// Member hooks
|
|
161
|
+
beforeAddMember: userHooks?.beforeAddMember
|
|
162
|
+
? async (data) => {
|
|
163
|
+
const result = await userHooks.beforeAddMember(data);
|
|
164
|
+
return result;
|
|
165
|
+
}
|
|
166
|
+
: undefined,
|
|
167
|
+
afterAddMember: userHooks?.afterAddMember
|
|
168
|
+
? async (data) => {
|
|
169
|
+
await userHooks.afterAddMember?.(data);
|
|
170
|
+
// Emit event
|
|
171
|
+
emitEvent(
|
|
172
|
+
"member.added",
|
|
173
|
+
{
|
|
174
|
+
status: "success",
|
|
175
|
+
organizationId: data.organization.id,
|
|
176
|
+
userId: data.member.userId,
|
|
177
|
+
metadata: {
|
|
178
|
+
memberId: data.member.id,
|
|
179
|
+
role: data.member.role,
|
|
180
|
+
addedByUserId: data.user.id,
|
|
181
|
+
addedByEmail: data.user.email,
|
|
182
|
+
addedByName: data.user.name,
|
|
183
|
+
memberEmail: data.user.email,
|
|
184
|
+
memberName: data.user.name,
|
|
185
|
+
},
|
|
186
|
+
request: getRequestInfo(),
|
|
98
187
|
},
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
: async (data) => {
|
|
122
|
-
// Emit event even if no user hook
|
|
123
|
-
emitEvent('organization.deleted', {
|
|
124
|
-
status: 'success',
|
|
125
|
-
organizationId: data.organization.id,
|
|
126
|
-
userId: data.user.id,
|
|
127
|
-
metadata: {
|
|
128
|
-
organizationName: data.organization.name,
|
|
129
|
-
organizationSlug: data.organization.slug,
|
|
130
|
-
email: data.user.email,
|
|
131
|
-
name: data.user.name,
|
|
132
|
-
},
|
|
133
|
-
request: getRequestInfo(),
|
|
134
|
-
}, capturedConfig).catch(() => { });
|
|
188
|
+
capturedConfig,
|
|
189
|
+
).catch(() => {});
|
|
190
|
+
}
|
|
191
|
+
: async (data) => {
|
|
192
|
+
// Emit event even if no user hook
|
|
193
|
+
emitEvent(
|
|
194
|
+
"member.added",
|
|
195
|
+
{
|
|
196
|
+
status: "success",
|
|
197
|
+
organizationId: data.organization.id,
|
|
198
|
+
userId: data.member.userId,
|
|
199
|
+
metadata: {
|
|
200
|
+
memberId: data.member.id,
|
|
201
|
+
role: data.member.role,
|
|
202
|
+
addedByUserId: data.user.id,
|
|
203
|
+
addedByEmail: data.user.email,
|
|
204
|
+
addedByName: data.user.name,
|
|
205
|
+
memberEmail: data.user.email,
|
|
206
|
+
memberName: data.user.name,
|
|
207
|
+
},
|
|
208
|
+
request: getRequestInfo(),
|
|
135
209
|
},
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
210
|
+
capturedConfig,
|
|
211
|
+
).catch(() => {});
|
|
212
|
+
},
|
|
213
|
+
beforeRemoveMember: userHooks?.beforeRemoveMember
|
|
214
|
+
? async (data) => {
|
|
215
|
+
await userHooks.beforeRemoveMember(data);
|
|
216
|
+
}
|
|
217
|
+
: undefined,
|
|
218
|
+
afterRemoveMember: userHooks?.afterRemoveMember
|
|
219
|
+
? async (data) => {
|
|
220
|
+
await userHooks.afterRemoveMember?.(data);
|
|
221
|
+
// Emit event
|
|
222
|
+
emitEvent(
|
|
223
|
+
"member.removed",
|
|
224
|
+
{
|
|
225
|
+
status: "success",
|
|
226
|
+
organizationId: data.organization.id,
|
|
227
|
+
userId: data.member.userId,
|
|
228
|
+
metadata: {
|
|
229
|
+
memberId: data.member.id,
|
|
230
|
+
removedByUserId: data.user.id,
|
|
231
|
+
removedByEmail: data.user.email,
|
|
232
|
+
removedByName: data.user.name,
|
|
233
|
+
},
|
|
234
|
+
request: getRequestInfo(),
|
|
235
|
+
},
|
|
236
|
+
capturedConfig,
|
|
237
|
+
).catch(() => {});
|
|
238
|
+
}
|
|
239
|
+
: async (data) => {
|
|
240
|
+
// Emit event even if no user hook
|
|
241
|
+
emitEvent(
|
|
242
|
+
"member.removed",
|
|
243
|
+
{
|
|
244
|
+
status: "success",
|
|
245
|
+
organizationId: data.organization.id,
|
|
246
|
+
userId: data.member.userId,
|
|
247
|
+
metadata: {
|
|
248
|
+
memberId: data.member.id,
|
|
249
|
+
removedByUserId: data.user.id,
|
|
250
|
+
removedByEmail: data.user.email,
|
|
251
|
+
removedByName: data.user.name,
|
|
252
|
+
},
|
|
253
|
+
request: getRequestInfo(),
|
|
180
254
|
},
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
metadata: {
|
|
210
|
-
memberId: data.member.id,
|
|
211
|
-
removedByUserId: data.user.id,
|
|
212
|
-
removedByEmail: data.user.email,
|
|
213
|
-
removedByName: data.user.name,
|
|
214
|
-
},
|
|
215
|
-
request: getRequestInfo(),
|
|
216
|
-
}, capturedConfig).catch(() => { });
|
|
255
|
+
capturedConfig,
|
|
256
|
+
).catch(() => {});
|
|
257
|
+
},
|
|
258
|
+
beforeUpdateMemberRole: userHooks?.beforeUpdateMemberRole
|
|
259
|
+
? async (data) => {
|
|
260
|
+
const result = await userHooks.beforeUpdateMemberRole(data);
|
|
261
|
+
return result;
|
|
262
|
+
}
|
|
263
|
+
: undefined,
|
|
264
|
+
afterUpdateMemberRole: userHooks?.afterUpdateMemberRole
|
|
265
|
+
? async (data) => {
|
|
266
|
+
await userHooks.afterUpdateMemberRole?.(data);
|
|
267
|
+
// Emit event
|
|
268
|
+
emitEvent(
|
|
269
|
+
"member.role_changed",
|
|
270
|
+
{
|
|
271
|
+
status: "success",
|
|
272
|
+
organizationId: data.organization.id,
|
|
273
|
+
userId: data.member.userId,
|
|
274
|
+
metadata: {
|
|
275
|
+
memberId: data.member.id,
|
|
276
|
+
oldRole: data.previousRole,
|
|
277
|
+
newRole: data.member.role,
|
|
278
|
+
changedByUserId: data.user.id,
|
|
279
|
+
changedByEmail: data.user.email,
|
|
280
|
+
changedByName: data.user.name,
|
|
281
|
+
},
|
|
282
|
+
request: getRequestInfo(),
|
|
217
283
|
},
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
changedByName: data.user.name,
|
|
239
|
-
},
|
|
240
|
-
request: getRequestInfo(),
|
|
241
|
-
}, capturedConfig).catch(() => { });
|
|
242
|
-
}
|
|
243
|
-
: async (data) => {
|
|
244
|
-
// Emit event even if no user hook
|
|
245
|
-
emitEvent('member.role_changed', {
|
|
246
|
-
status: 'success',
|
|
247
|
-
organizationId: data.organization.id,
|
|
248
|
-
userId: data.member.userId,
|
|
249
|
-
metadata: {
|
|
250
|
-
memberId: data.member.id,
|
|
251
|
-
oldRole: data.previousRole,
|
|
252
|
-
newRole: data.member.role,
|
|
253
|
-
changedByUserId: data.user.id,
|
|
254
|
-
changedByEmail: data.user.email,
|
|
255
|
-
changedByName: data.user.name,
|
|
256
|
-
},
|
|
257
|
-
request: getRequestInfo(),
|
|
258
|
-
}, capturedConfig).catch(() => { });
|
|
284
|
+
capturedConfig,
|
|
285
|
+
).catch(() => {});
|
|
286
|
+
}
|
|
287
|
+
: async (data) => {
|
|
288
|
+
// Emit event even if no user hook
|
|
289
|
+
emitEvent(
|
|
290
|
+
"member.role_changed",
|
|
291
|
+
{
|
|
292
|
+
status: "success",
|
|
293
|
+
organizationId: data.organization.id,
|
|
294
|
+
userId: data.member.userId,
|
|
295
|
+
metadata: {
|
|
296
|
+
memberId: data.member.id,
|
|
297
|
+
oldRole: data.previousRole,
|
|
298
|
+
newRole: data.member.role,
|
|
299
|
+
changedByUserId: data.user.id,
|
|
300
|
+
changedByEmail: data.user.email,
|
|
301
|
+
changedByName: data.user.name,
|
|
302
|
+
},
|
|
303
|
+
request: getRequestInfo(),
|
|
259
304
|
},
|
|
260
|
-
|
|
305
|
+
capturedConfig,
|
|
306
|
+
).catch(() => {});
|
|
307
|
+
},
|
|
308
|
+
};
|
|
261
309
|
}
|
|
262
310
|
/**
|
|
263
311
|
* Automatically wraps organization plugin hooks to emit events
|
|
264
312
|
* This should be called during Better Auth initialization
|
|
265
313
|
*/
|
|
266
314
|
export function wrapOrganizationPluginHooks(auth, eventsConfig) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
// Get existing organization hooks from plugin options
|
|
278
|
-
// Better Auth may store hooks in different locations depending on version
|
|
279
|
-
const existingHooks = orgPlugin.options?.organizationHooks ||
|
|
280
|
-
orgPlugin.organizationHooks ||
|
|
281
|
-
(orgPlugin.options && orgPlugin.options.organizationHooks) ||
|
|
282
|
-
{};
|
|
283
|
-
// Wrap the hooks
|
|
284
|
-
const wrappedHooks = createOrganizationHooksWithEvents(eventsConfig, existingHooks);
|
|
285
|
-
// Update the plugin options in all possible locations
|
|
286
|
-
if (!orgPlugin.options) {
|
|
287
|
-
orgPlugin.options = {};
|
|
288
|
-
}
|
|
289
|
-
orgPlugin.options.organizationHooks = wrappedHooks;
|
|
290
|
-
// Also set directly on plugin for compatibility
|
|
291
|
-
orgPlugin.organizationHooks = wrappedHooks;
|
|
315
|
+
if (!auth || !eventsConfig?.enabled) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
try {
|
|
319
|
+
// Find the organization plugin
|
|
320
|
+
const plugins = auth.options?.plugins || [];
|
|
321
|
+
const orgPlugin = plugins.find((p) => p?.id === "organization");
|
|
322
|
+
if (!orgPlugin) {
|
|
323
|
+
return; // Organization plugin not found
|
|
292
324
|
}
|
|
293
|
-
|
|
294
|
-
|
|
325
|
+
// Get existing organization hooks from plugin options
|
|
326
|
+
// Better Auth may store hooks in different locations depending on version
|
|
327
|
+
const existingHooks =
|
|
328
|
+
orgPlugin.options?.organizationHooks ||
|
|
329
|
+
orgPlugin.organizationHooks ||
|
|
330
|
+
(orgPlugin.options && orgPlugin.options.organizationHooks) ||
|
|
331
|
+
{};
|
|
332
|
+
// Wrap the hooks
|
|
333
|
+
const wrappedHooks = createOrganizationHooksWithEvents(eventsConfig, existingHooks);
|
|
334
|
+
// Update the plugin options in all possible locations
|
|
335
|
+
if (!orgPlugin.options) {
|
|
336
|
+
orgPlugin.options = {};
|
|
295
337
|
}
|
|
338
|
+
orgPlugin.options.organizationHooks = wrappedHooks;
|
|
339
|
+
// Also set directly on plugin for compatibility
|
|
340
|
+
orgPlugin.organizationHooks = wrappedHooks;
|
|
341
|
+
} catch (error) {
|
|
342
|
+
console.error("[Organization Hooks] Failed to wrap hooks:", error);
|
|
343
|
+
}
|
|
296
344
|
}
|
|
297
|
-
//# sourceMappingURL=organization-hooks-wrapper.js.map
|
|
345
|
+
//# sourceMappingURL=organization-hooks-wrapper.js.map
|