@rio.js/enterprise 1.4.0

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 (41) hide show
  1. package/README.md +89 -0
  2. package/dist/adapter-factory-BTRALCLD-kJBwe70v.mjs +836 -0
  3. package/dist/better-auth-CStoaWiq.d.mts +10 -0
  4. package/dist/better-auth-CqfhQJYE.mjs +558 -0
  5. package/dist/better-auth.d.mts +2 -0
  6. package/dist/better-auth.mjs +17 -0
  7. package/dist/bun-sqlite-dialect-2R9nCsVF-DFs6tpGr.mjs +155 -0
  8. package/dist/client--1_AEBPu-8Ae9icC9.mjs +125 -0
  9. package/dist/client.d.mts +17 -0
  10. package/dist/client.mjs +381 -0
  11. package/dist/db-BVXTgOd3.mjs +681 -0
  12. package/dist/db-BadqSwVl.d.mts +9542 -0
  13. package/dist/db-schema.final-DWleoQm0.mjs +785 -0
  14. package/dist/db.d.mts +2 -0
  15. package/dist/db.mjs +3 -0
  16. package/dist/dialect-C6_pK3V9-CPJHWkYR.mjs +72 -0
  17. package/dist/dist-CygcgJYk.mjs +422 -0
  18. package/dist/env-DwlNAN_D-C1zHd0cf-Cdlw8sNp.mjs +289 -0
  19. package/dist/esm-C5TuvtGn.mjs +15816 -0
  20. package/dist/index.d.mts +6 -0
  21. package/dist/index.mjs +17 -0
  22. package/dist/init-D8lwWc90.mjs +27 -0
  23. package/dist/json-oFuWgANh-O1U6k3bL.mjs +3811 -0
  24. package/dist/kysely-adapter-D_seG51p.mjs +297 -0
  25. package/dist/memory-adapter-CY-oDozb.mjs +215 -0
  26. package/dist/misc-CbURQDlR-sLtUwwQY.mjs +7 -0
  27. package/dist/node-sqlite-dialect-CdC7L-ji-QLbJGmDc.mjs +155 -0
  28. package/dist/parser-bL7W2mQ0-YdTgjtji.mjs +140 -0
  29. package/dist/plugins-BNFht2HW.mjs +23358 -0
  30. package/dist/plugins.d.mts +1 -0
  31. package/dist/plugins.mjs +13 -0
  32. package/dist/react--VZQu7s1.mjs +560 -0
  33. package/dist/react.d.mts +1 -0
  34. package/dist/react.mjs +6 -0
  35. package/dist/server.d.mts +10 -0
  36. package/dist/server.mjs +45 -0
  37. package/dist/social-providers-DNfE9Ak7-Be5zMAEe.mjs +2920 -0
  38. package/dist/social-providers.d.mts +1 -0
  39. package/dist/social-providers.mjs +6 -0
  40. package/dist/verify-CN5Qc0e-.mjs +1183 -0
  41. package/package.json +98 -0
@@ -0,0 +1,785 @@
1
+ import { $ as teamRole, A as oauthAccessTokenRelations, B as organizationRoleRelations, C as memberAssetRoleRelations, D as memberTeamRole, E as memberRelations, F as object, G as schemaDefinition, H as platformRole, I as objectRelations, J as sessionRelations, K as schemaDefinitionRelations, L as organization, M as oauthApplicationRelations, N as oauthConsent, O as memberTeamRoleRelations, P as oauthConsentRelations, Q as teamRelations, R as organizationRelations, S as memberAssetRole, T as memberOrganizationRoleRelations, U as relationship, V as person, W as relationshipRelations, X as teamMember, Y as team, Z as teamMemberRelations, _ as assetType, a as agent, at as verification, b as invitationRelations, c as apikeyRelations, d as assetRole, et as teamRoleRelations, f as assetRoleRelations, g as assetShareRelations, h as assetShareLinkRelations, i as accountRelations, it as userRelations, j as oauthApplication, k as oauthAccessToken, l as asset, m as assetShareLink, nt as twoFactorRelations, o as agentRelations, ot as enterpriseSchema, p as assetShare, q as session, r as account, rt as user, s as apikey, st as __export, tt as twoFactor, u as assetRelations, v as assetTypeRelations, w as memberOrganizationRole, x as member, y as invitation, z as organizationRole } from "./db-BVXTgOd3.mjs";
2
+ import { c as generateId, f as createHash, h as hashPassword, n as getAuthTables, p as createRandomStringGenerator, q as runWithAdapter, v as verifyPassword } from "./json-oFuWgANh-O1U6k3bL.mjs";
3
+ import { a as getBooleanEnvVar, f as logger, g as BetterAuthError, h as BASE_ERROR_CODES, i as env, l as isProduction, r as createLogger, s as getEnvVar, t as ENV, u as isTest } from "./env-DwlNAN_D-C1zHd0cf-Cdlw8sNp.mjs";
4
+ import { H as base64 } from "./verify-CN5Qc0e-.mjs";
5
+ import { z as socialProviders } from "./social-providers-DNfE9Ak7-Be5zMAEe.mjs";
6
+ import { N as createGraphAdapter, _t as createInternalAdapter, at as checkEndpointConflicts, ct as defu, lt as createCookieGetter, nt as checkPassword, ot as getEndpoints, st as router, ut as getCookies, vt as getAdapter, yt as getMigrations } from "./plugins-BNFht2HW.mjs";
7
+ import { n as getKyselyDatabaseType } from "./dialect-C6_pK3V9-CPJHWkYR.mjs";
8
+ import { t as betterFetch } from "./dist-CygcgJYk.mjs";
9
+ import { a as getOrigin, r as getBaseURL } from "./parser-bL7W2mQ0-YdTgjtji.mjs";
10
+
11
+ //#region ../better-auth/dist/base-B1roRIPC.mjs
12
+ function getTelemetryAuthConfig(options, context) {
13
+ return {
14
+ database: context?.database,
15
+ adapter: context?.adapter,
16
+ emailVerification: {
17
+ sendVerificationEmail: !!options.emailVerification?.sendVerificationEmail,
18
+ sendOnSignUp: !!options.emailVerification?.sendOnSignUp,
19
+ sendOnSignIn: !!options.emailVerification?.sendOnSignIn,
20
+ autoSignInAfterVerification: !!options.emailVerification?.autoSignInAfterVerification,
21
+ expiresIn: options.emailVerification?.expiresIn,
22
+ onEmailVerification: !!options.emailVerification?.onEmailVerification,
23
+ afterEmailVerification: !!options.emailVerification?.afterEmailVerification
24
+ },
25
+ emailAndPassword: {
26
+ enabled: !!options.emailAndPassword?.enabled,
27
+ disableSignUp: !!options.emailAndPassword?.disableSignUp,
28
+ requireEmailVerification: !!options.emailAndPassword?.requireEmailVerification,
29
+ maxPasswordLength: options.emailAndPassword?.maxPasswordLength,
30
+ minPasswordLength: options.emailAndPassword?.minPasswordLength,
31
+ sendResetPassword: !!options.emailAndPassword?.sendResetPassword,
32
+ resetPasswordTokenExpiresIn: options.emailAndPassword?.resetPasswordTokenExpiresIn,
33
+ onPasswordReset: !!options.emailAndPassword?.onPasswordReset,
34
+ password: {
35
+ hash: !!options.emailAndPassword?.password?.hash,
36
+ verify: !!options.emailAndPassword?.password?.verify
37
+ },
38
+ autoSignIn: !!options.emailAndPassword?.autoSignIn,
39
+ revokeSessionsOnPasswordReset: !!options.emailAndPassword?.revokeSessionsOnPasswordReset
40
+ },
41
+ socialProviders: Object.keys(options.socialProviders || {}).map((p) => {
42
+ const provider = options.socialProviders?.[p];
43
+ if (!provider) return {};
44
+ return {
45
+ id: p,
46
+ mapProfileToUser: !!provider.mapProfileToUser,
47
+ disableDefaultScope: !!provider.disableDefaultScope,
48
+ disableIdTokenSignIn: !!provider.disableIdTokenSignIn,
49
+ disableImplicitSignUp: provider.disableImplicitSignUp,
50
+ disableSignUp: provider.disableSignUp,
51
+ getUserInfo: !!provider.getUserInfo,
52
+ overrideUserInfoOnSignIn: !!provider.overrideUserInfoOnSignIn,
53
+ prompt: provider.prompt,
54
+ verifyIdToken: !!provider.verifyIdToken,
55
+ scope: provider.scope,
56
+ refreshAccessToken: !!provider.refreshAccessToken
57
+ };
58
+ }),
59
+ plugins: options.plugins?.map((p) => p.id.toString()),
60
+ user: {
61
+ modelName: options.user?.modelName,
62
+ fields: options.user?.fields,
63
+ additionalFields: options.user?.additionalFields,
64
+ changeEmail: {
65
+ enabled: options.user?.changeEmail?.enabled,
66
+ sendChangeEmailVerification: !!options.user?.changeEmail?.sendChangeEmailVerification
67
+ }
68
+ },
69
+ verification: {
70
+ modelName: options.verification?.modelName,
71
+ disableCleanup: options.verification?.disableCleanup,
72
+ fields: options.verification?.fields
73
+ },
74
+ session: {
75
+ modelName: options.session?.modelName,
76
+ additionalFields: options.session?.additionalFields,
77
+ cookieCache: {
78
+ enabled: options.session?.cookieCache?.enabled,
79
+ maxAge: options.session?.cookieCache?.maxAge,
80
+ strategy: options.session?.cookieCache?.strategy
81
+ },
82
+ disableSessionRefresh: options.session?.disableSessionRefresh,
83
+ expiresIn: options.session?.expiresIn,
84
+ fields: options.session?.fields,
85
+ freshAge: options.session?.freshAge,
86
+ preserveSessionInDatabase: options.session?.preserveSessionInDatabase,
87
+ storeSessionInDatabase: options.session?.storeSessionInDatabase,
88
+ updateAge: options.session?.updateAge
89
+ },
90
+ account: {
91
+ modelName: options.account?.modelName,
92
+ fields: options.account?.fields,
93
+ encryptOAuthTokens: options.account?.encryptOAuthTokens,
94
+ updateAccountOnSignIn: options.account?.updateAccountOnSignIn,
95
+ accountLinking: {
96
+ enabled: options.account?.accountLinking?.enabled,
97
+ trustedProviders: options.account?.accountLinking?.trustedProviders,
98
+ updateUserInfoOnLink: options.account?.accountLinking?.updateUserInfoOnLink,
99
+ allowUnlinkingAll: options.account?.accountLinking?.allowUnlinkingAll
100
+ }
101
+ },
102
+ hooks: {
103
+ after: !!options.hooks?.after,
104
+ before: !!options.hooks?.before
105
+ },
106
+ secondaryStorage: !!options.secondaryStorage,
107
+ advanced: {
108
+ cookiePrefix: !!options.advanced?.cookiePrefix,
109
+ cookies: !!options.advanced?.cookies,
110
+ crossSubDomainCookies: {
111
+ domain: !!options.advanced?.crossSubDomainCookies?.domain,
112
+ enabled: options.advanced?.crossSubDomainCookies?.enabled,
113
+ additionalCookies: options.advanced?.crossSubDomainCookies?.additionalCookies
114
+ },
115
+ database: {
116
+ useNumberId: !!options.advanced?.database?.useNumberId || options.advanced?.database?.generateId === "serial",
117
+ generateId: options.advanced?.database?.generateId,
118
+ defaultFindManyLimit: options.advanced?.database?.defaultFindManyLimit
119
+ },
120
+ useSecureCookies: options.advanced?.useSecureCookies,
121
+ ipAddress: {
122
+ disableIpTracking: options.advanced?.ipAddress?.disableIpTracking,
123
+ ipAddressHeaders: options.advanced?.ipAddress?.ipAddressHeaders
124
+ },
125
+ disableCSRFCheck: options.advanced?.disableCSRFCheck,
126
+ cookieAttributes: {
127
+ expires: options.advanced?.defaultCookieAttributes?.expires,
128
+ secure: options.advanced?.defaultCookieAttributes?.secure,
129
+ sameSite: options.advanced?.defaultCookieAttributes?.sameSite,
130
+ domain: !!options.advanced?.defaultCookieAttributes?.domain,
131
+ path: options.advanced?.defaultCookieAttributes?.path,
132
+ httpOnly: options.advanced?.defaultCookieAttributes?.httpOnly
133
+ }
134
+ },
135
+ trustedOrigins: options.trustedOrigins?.length,
136
+ rateLimit: {
137
+ storage: options.rateLimit?.storage,
138
+ modelName: options.rateLimit?.modelName,
139
+ window: options.rateLimit?.window,
140
+ customStorage: !!options.rateLimit?.customStorage,
141
+ enabled: options.rateLimit?.enabled,
142
+ max: options.rateLimit?.max
143
+ },
144
+ onAPIError: {
145
+ errorURL: options.onAPIError?.errorURL,
146
+ onError: !!options.onAPIError?.onError,
147
+ throw: options.onAPIError?.throw
148
+ },
149
+ logger: {
150
+ disabled: options.logger?.disabled,
151
+ level: options.logger?.level,
152
+ log: !!options.logger?.log
153
+ },
154
+ databaseHooks: {
155
+ user: {
156
+ create: {
157
+ after: !!options.databaseHooks?.user?.create?.after,
158
+ before: !!options.databaseHooks?.user?.create?.before
159
+ },
160
+ update: {
161
+ after: !!options.databaseHooks?.user?.update?.after,
162
+ before: !!options.databaseHooks?.user?.update?.before
163
+ }
164
+ },
165
+ session: {
166
+ create: {
167
+ after: !!options.databaseHooks?.session?.create?.after,
168
+ before: !!options.databaseHooks?.session?.create?.before
169
+ },
170
+ update: {
171
+ after: !!options.databaseHooks?.session?.update?.after,
172
+ before: !!options.databaseHooks?.session?.update?.before
173
+ }
174
+ },
175
+ account: {
176
+ create: {
177
+ after: !!options.databaseHooks?.account?.create?.after,
178
+ before: !!options.databaseHooks?.account?.create?.before
179
+ },
180
+ update: {
181
+ after: !!options.databaseHooks?.account?.update?.after,
182
+ before: !!options.databaseHooks?.account?.update?.before
183
+ }
184
+ },
185
+ verification: {
186
+ create: {
187
+ after: !!options.databaseHooks?.verification?.create?.after,
188
+ before: !!options.databaseHooks?.verification?.create?.before
189
+ },
190
+ update: {
191
+ after: !!options.databaseHooks?.verification?.update?.after,
192
+ before: !!options.databaseHooks?.verification?.update?.before
193
+ }
194
+ }
195
+ }
196
+ };
197
+ }
198
+ let packageJSONCache;
199
+ async function readRootPackageJson() {
200
+ if (packageJSONCache) return packageJSONCache;
201
+ try {
202
+ const cwd = typeof process !== "undefined" && typeof process.cwd === "function" ? process.cwd() : "";
203
+ if (!cwd) return void 0;
204
+ const importRuntime$1 = (m) => Function("mm", "return import(mm)")(m);
205
+ const [{ default: fs }, { default: path }] = await Promise.all([importRuntime$1("fs/promises"), importRuntime$1("path")]);
206
+ const raw = await fs.readFile(path.join(cwd, "package.json"), "utf-8");
207
+ packageJSONCache = JSON.parse(raw);
208
+ return packageJSONCache;
209
+ } catch {}
210
+ }
211
+ async function getPackageVersion(pkg) {
212
+ if (packageJSONCache) return packageJSONCache.dependencies?.[pkg] || packageJSONCache.devDependencies?.[pkg] || packageJSONCache.peerDependencies?.[pkg];
213
+ try {
214
+ const cwd = typeof process !== "undefined" && typeof process.cwd === "function" ? process.cwd() : "";
215
+ if (!cwd) throw new Error("no-cwd");
216
+ const importRuntime$1 = (m) => Function("mm", "return import(mm)")(m);
217
+ const [{ default: fs }, { default: path }] = await Promise.all([importRuntime$1("fs/promises"), importRuntime$1("path")]);
218
+ const pkgJsonPath = path.join(cwd, "node_modules", pkg, "package.json");
219
+ const raw = await fs.readFile(pkgJsonPath, "utf-8");
220
+ return JSON.parse(raw).version || await getVersionFromLocalPackageJson(pkg) || void 0;
221
+ } catch {}
222
+ return await getVersionFromLocalPackageJson(pkg);
223
+ }
224
+ async function getVersionFromLocalPackageJson(pkg) {
225
+ const json = await readRootPackageJson();
226
+ if (!json) return void 0;
227
+ return {
228
+ ...json.dependencies,
229
+ ...json.devDependencies,
230
+ ...json.peerDependencies
231
+ }[pkg];
232
+ }
233
+ async function getNameFromLocalPackageJson() {
234
+ return (await readRootPackageJson())?.name;
235
+ }
236
+ const DATABASES = {
237
+ pg: "postgresql",
238
+ mysql: "mysql",
239
+ mariadb: "mariadb",
240
+ sqlite3: "sqlite",
241
+ "better-sqlite3": "sqlite",
242
+ "@prisma/client": "prisma",
243
+ mongoose: "mongodb",
244
+ mongodb: "mongodb",
245
+ "drizzle-orm": "drizzle"
246
+ };
247
+ async function detectDatabase() {
248
+ for (const [pkg, name] of Object.entries(DATABASES)) {
249
+ const version = await getPackageVersion(pkg);
250
+ if (version) return {
251
+ name,
252
+ version
253
+ };
254
+ }
255
+ }
256
+ const FRAMEWORKS = {
257
+ next: "next",
258
+ nuxt: "nuxt",
259
+ "@remix-run/server-runtime": "remix",
260
+ astro: "astro",
261
+ "@sveltejs/kit": "sveltekit",
262
+ "solid-start": "solid-start",
263
+ "tanstack-start": "tanstack-start",
264
+ hono: "hono",
265
+ express: "express",
266
+ elysia: "elysia",
267
+ expo: "expo"
268
+ };
269
+ async function detectFramework() {
270
+ for (const [pkg, name] of Object.entries(FRAMEWORKS)) {
271
+ const version = await getPackageVersion(pkg);
272
+ if (version) return {
273
+ name,
274
+ version
275
+ };
276
+ }
277
+ }
278
+ function detectPackageManager() {
279
+ const userAgent = env.npm_config_user_agent;
280
+ if (!userAgent) return;
281
+ const pmSpec = userAgent.split(" ")[0];
282
+ const separatorPos = pmSpec.lastIndexOf("/");
283
+ const name = pmSpec.substring(0, separatorPos);
284
+ return {
285
+ name: name === "npminstall" ? "cnpm" : name,
286
+ version: pmSpec.substring(separatorPos + 1)
287
+ };
288
+ }
289
+ const importRuntime = (m) => {
290
+ return Function("mm", "return import(mm)")(m);
291
+ };
292
+ function getVendor() {
293
+ const hasAny = (...keys) => keys.some((k) => Boolean(env[k]));
294
+ if (hasAny("CF_PAGES", "CF_PAGES_URL", "CF_ACCOUNT_ID") || typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers") return "cloudflare";
295
+ if (hasAny("VERCEL", "VERCEL_URL", "VERCEL_ENV")) return "vercel";
296
+ if (hasAny("NETLIFY", "NETLIFY_URL")) return "netlify";
297
+ if (hasAny("RENDER", "RENDER_URL", "RENDER_INTERNAL_HOSTNAME", "RENDER_SERVICE_ID")) return "render";
298
+ if (hasAny("AWS_LAMBDA_FUNCTION_NAME", "AWS_EXECUTION_ENV", "LAMBDA_TASK_ROOT")) return "aws";
299
+ if (hasAny("GOOGLE_CLOUD_FUNCTION_NAME", "GOOGLE_CLOUD_PROJECT", "GCP_PROJECT", "K_SERVICE")) return "gcp";
300
+ if (hasAny("AZURE_FUNCTION_NAME", "FUNCTIONS_WORKER_RUNTIME", "WEBSITE_INSTANCE_ID", "WEBSITE_SITE_NAME")) return "azure";
301
+ if (hasAny("DENO_DEPLOYMENT_ID", "DENO_REGION")) return "deno-deploy";
302
+ if (hasAny("FLY_APP_NAME", "FLY_REGION", "FLY_ALLOC_ID")) return "fly-io";
303
+ if (hasAny("RAILWAY_STATIC_URL", "RAILWAY_ENVIRONMENT_NAME")) return "railway";
304
+ if (hasAny("DYNO", "HEROKU_APP_NAME")) return "heroku";
305
+ if (hasAny("DO_DEPLOYMENT_ID", "DO_APP_NAME", "DIGITALOCEAN")) return "digitalocean";
306
+ if (hasAny("KOYEB", "KOYEB_DEPLOYMENT_ID", "KOYEB_APP_NAME")) return "koyeb";
307
+ return null;
308
+ }
309
+ async function detectSystemInfo() {
310
+ try {
311
+ if (getVendor() === "cloudflare") return "cloudflare";
312
+ const os = await importRuntime("os");
313
+ const cpus = os.cpus();
314
+ return {
315
+ deploymentVendor: getVendor(),
316
+ systemPlatform: os.platform(),
317
+ systemRelease: os.release(),
318
+ systemArchitecture: os.arch(),
319
+ cpuCount: cpus.length,
320
+ cpuModel: cpus.length ? cpus[0].model : null,
321
+ cpuSpeed: cpus.length ? cpus[0].speed : null,
322
+ memory: os.totalmem(),
323
+ isWSL: await isWsl(),
324
+ isDocker: await isDocker(),
325
+ isTTY: typeof process !== "undefined" && process.stdout ? process.stdout.isTTY : null
326
+ };
327
+ } catch (e) {
328
+ return {
329
+ systemPlatform: null,
330
+ systemRelease: null,
331
+ systemArchitecture: null,
332
+ cpuCount: null,
333
+ cpuModel: null,
334
+ cpuSpeed: null,
335
+ memory: null,
336
+ isWSL: null,
337
+ isDocker: null,
338
+ isTTY: null
339
+ };
340
+ }
341
+ }
342
+ let isDockerCached;
343
+ async function hasDockerEnv() {
344
+ if (getVendor() === "cloudflare") return false;
345
+ try {
346
+ (await importRuntime("fs")).statSync("/.dockerenv");
347
+ return true;
348
+ } catch {
349
+ return false;
350
+ }
351
+ }
352
+ async function hasDockerCGroup() {
353
+ if (getVendor() === "cloudflare") return false;
354
+ try {
355
+ return (await importRuntime("fs")).readFileSync("/proc/self/cgroup", "utf8").includes("docker");
356
+ } catch {
357
+ return false;
358
+ }
359
+ }
360
+ async function isDocker() {
361
+ if (getVendor() === "cloudflare") return false;
362
+ if (isDockerCached === void 0) isDockerCached = await hasDockerEnv() || await hasDockerCGroup();
363
+ return isDockerCached;
364
+ }
365
+ async function isWsl() {
366
+ try {
367
+ if (getVendor() === "cloudflare") return false;
368
+ if (typeof process === "undefined" || process?.platform !== "linux") return false;
369
+ const fs = await importRuntime("fs");
370
+ if ((await importRuntime("os")).release().toLowerCase().includes("microsoft")) {
371
+ if (await isInsideContainer()) return false;
372
+ return true;
373
+ }
374
+ return fs.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft") ? !await isInsideContainer() : false;
375
+ } catch {
376
+ return false;
377
+ }
378
+ }
379
+ let isInsideContainerCached;
380
+ const hasContainerEnv = async () => {
381
+ if (getVendor() === "cloudflare") return false;
382
+ try {
383
+ (await importRuntime("fs")).statSync("/run/.containerenv");
384
+ return true;
385
+ } catch {
386
+ return false;
387
+ }
388
+ };
389
+ async function isInsideContainer() {
390
+ if (isInsideContainerCached === void 0) isInsideContainerCached = await hasContainerEnv() || await isDocker();
391
+ return isInsideContainerCached;
392
+ }
393
+ function isCI() {
394
+ return env.CI !== "false" && ("BUILD_ID" in env || "BUILD_NUMBER" in env || "CI" in env || "CI_APP_ID" in env || "CI_BUILD_ID" in env || "CI_BUILD_NUMBER" in env || "CI_NAME" in env || "CONTINUOUS_INTEGRATION" in env || "RUN_ID" in env);
395
+ }
396
+ function detectRuntime() {
397
+ if (typeof Deno !== "undefined") return {
398
+ name: "deno",
399
+ version: Deno?.version?.deno ?? null
400
+ };
401
+ if (typeof Bun !== "undefined") return {
402
+ name: "bun",
403
+ version: Bun?.version ?? null
404
+ };
405
+ if (typeof process !== "undefined" && process?.versions?.node) return {
406
+ name: "node",
407
+ version: process.versions.node ?? null
408
+ };
409
+ return {
410
+ name: "edge",
411
+ version: null
412
+ };
413
+ }
414
+ function detectEnvironment() {
415
+ return getEnvVar("NODE_ENV") === "production" ? "production" : isCI() ? "ci" : isTest() ? "test" : "development";
416
+ }
417
+ async function hashToBase64(data) {
418
+ const buffer = await createHash("SHA-256").digest(data);
419
+ return base64.encode(buffer);
420
+ }
421
+ const generateId$1 = (size) => {
422
+ return createRandomStringGenerator("a-z", "A-Z", "0-9")(size || 32);
423
+ };
424
+ let projectIdCached = null;
425
+ async function getProjectId(baseUrl) {
426
+ if (projectIdCached) return projectIdCached;
427
+ const projectName = await getNameFromLocalPackageJson();
428
+ if (projectName) {
429
+ projectIdCached = await hashToBase64(baseUrl ? baseUrl + projectName : projectName);
430
+ return projectIdCached;
431
+ }
432
+ if (baseUrl) {
433
+ projectIdCached = await hashToBase64(baseUrl);
434
+ return projectIdCached;
435
+ }
436
+ projectIdCached = generateId$1(32);
437
+ return projectIdCached;
438
+ }
439
+ async function createTelemetry(options, context) {
440
+ const debugEnabled = options.telemetry?.debug || getBooleanEnvVar("BETTER_AUTH_TELEMETRY_DEBUG", false);
441
+ const TELEMETRY_ENDPOINT = ENV.BETTER_AUTH_TELEMETRY_ENDPOINT;
442
+ const track = async (event) => {
443
+ if (context?.customTrack) await context.customTrack(event).catch(logger.error);
444
+ else if (debugEnabled) logger.info("telemetry event", JSON.stringify(event, null, 2));
445
+ else await betterFetch(TELEMETRY_ENDPOINT, {
446
+ method: "POST",
447
+ body: event
448
+ }).catch(logger.error);
449
+ };
450
+ const isEnabled = async () => {
451
+ const telemetryEnabled = options.telemetry?.enabled !== void 0 ? options.telemetry.enabled : false;
452
+ return (getBooleanEnvVar("BETTER_AUTH_TELEMETRY", false) || telemetryEnabled) && (context?.skipTestCheck || !isTest());
453
+ };
454
+ const enabled = await isEnabled();
455
+ let anonymousId;
456
+ if (enabled) {
457
+ anonymousId = await getProjectId(options.baseURL);
458
+ track({
459
+ type: "init",
460
+ payload: {
461
+ config: getTelemetryAuthConfig(options, context),
462
+ runtime: detectRuntime(),
463
+ database: await detectDatabase(),
464
+ framework: await detectFramework(),
465
+ environment: detectEnvironment(),
466
+ systemInfo: await detectSystemInfo(),
467
+ packageManager: detectPackageManager()
468
+ },
469
+ anonymousId
470
+ });
471
+ }
472
+ return { publish: async (event) => {
473
+ if (!enabled) return;
474
+ if (!anonymousId) anonymousId = await getProjectId(options.baseURL);
475
+ await track({
476
+ type: event.type,
477
+ payload: event.payload,
478
+ anonymousId
479
+ });
480
+ } };
481
+ }
482
+ const DEFAULT_SECRET = "better-auth-secret-123456789";
483
+ function isPromise(obj) {
484
+ return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
485
+ }
486
+ async function runPluginInit(ctx) {
487
+ let options = ctx.options;
488
+ const plugins = options.plugins || [];
489
+ let context = ctx;
490
+ const dbHooks = [];
491
+ for (const plugin of plugins) if (plugin.init) {
492
+ let initPromise = plugin.init(context);
493
+ let result;
494
+ if (isPromise(initPromise)) result = await initPromise;
495
+ else result = initPromise;
496
+ if (typeof result === "object") {
497
+ if (result.options) {
498
+ const { databaseHooks, ...restOpts } = result.options;
499
+ if (databaseHooks) dbHooks.push(databaseHooks);
500
+ options = defu(options, restOpts);
501
+ }
502
+ if (result.context) context = {
503
+ ...context,
504
+ ...result.context
505
+ };
506
+ }
507
+ }
508
+ dbHooks.push(options.databaseHooks);
509
+ context.internalAdapter = createInternalAdapter(context.adapter, {
510
+ options,
511
+ logger: context.logger,
512
+ hooks: dbHooks.filter((u) => u !== void 0),
513
+ generateId: context.generateId,
514
+ graphAdapter: context.graphAdapter
515
+ });
516
+ context.options = options;
517
+ return { context };
518
+ }
519
+ function getInternalPlugins(options) {
520
+ const plugins = [];
521
+ if (options.advanced?.crossSubDomainCookies?.enabled) {}
522
+ return plugins;
523
+ }
524
+ function getTrustedOrigins(options) {
525
+ const baseURL = getBaseURL(options.baseURL, options.basePath);
526
+ if (!baseURL) return [];
527
+ const trustedOrigins = [new URL(baseURL).origin];
528
+ if (options.trustedOrigins && Array.isArray(options.trustedOrigins)) trustedOrigins.push(...options.trustedOrigins);
529
+ const envTrustedOrigins = env.BETTER_AUTH_TRUSTED_ORIGINS;
530
+ if (envTrustedOrigins) trustedOrigins.push(...envTrustedOrigins.split(","));
531
+ if (trustedOrigins.filter((x) => !x).length) throw new BetterAuthError("A provided trusted origin is invalid, make sure your trusted origins list is properly defined.");
532
+ return trustedOrigins;
533
+ }
534
+ async function createAuthContext(adapter, options, getDatabaseType) {
535
+ if (!options.database) options = defu(options, {
536
+ session: { cookieCache: {
537
+ enabled: true,
538
+ strategy: "jwe",
539
+ refreshCache: true
540
+ } },
541
+ account: {
542
+ storeStateStrategy: "cookie",
543
+ storeAccountCookie: true
544
+ }
545
+ });
546
+ const plugins = options.plugins || [];
547
+ const internalPlugins = getInternalPlugins(options);
548
+ const logger$1 = createLogger(options.logger);
549
+ const baseURL = getBaseURL(options.baseURL, options.basePath);
550
+ const secret = options.secret || env.BETTER_AUTH_SECRET || env.AUTH_SECRET || DEFAULT_SECRET;
551
+ if (secret === DEFAULT_SECRET) {
552
+ if (isProduction) logger$1.error("You are using the default secret. Please set `BETTER_AUTH_SECRET` in your environment variables or pass `secret` in your auth config.");
553
+ }
554
+ options = {
555
+ ...options,
556
+ secret,
557
+ baseURL: baseURL ? new URL(baseURL).origin : "",
558
+ basePath: options.basePath || "/api/auth",
559
+ plugins: plugins.concat(internalPlugins)
560
+ };
561
+ checkEndpointConflicts(options, logger$1);
562
+ const cookies = getCookies(options);
563
+ const tables = getAuthTables(options);
564
+ const providers = Object.entries(options.socialProviders || {}).map(([key, config]) => {
565
+ if (config == null) return null;
566
+ if (config.enabled === false) return null;
567
+ if (!config.clientId) logger$1.warn(`Social provider ${key} is missing clientId or clientSecret`);
568
+ const provider = socialProviders[key](config);
569
+ provider.disableImplicitSignUp = config.disableImplicitSignUp;
570
+ return provider;
571
+ }).filter((x) => x !== null);
572
+ const generateIdFunc = ({ model, size }) => {
573
+ if (typeof options.advanced?.generateId === "function") return options.advanced.generateId({
574
+ model,
575
+ size
576
+ });
577
+ if (typeof options?.advanced?.database?.generateId === "function") return options.advanced.database.generateId({
578
+ model,
579
+ size
580
+ });
581
+ return generateId(size);
582
+ };
583
+ const { publish } = await createTelemetry(options, {
584
+ adapter: adapter.id,
585
+ database: typeof options.database === "function" ? "adapter" : getDatabaseType(options.database)
586
+ });
587
+ const graphAdapter = createGraphAdapter(adapter, options);
588
+ const initOrPromise = runPluginInit({
589
+ appName: options.appName || "Better Auth",
590
+ socialProviders: providers,
591
+ options,
592
+ oauthConfig: {
593
+ storeStateStrategy: options.account?.storeStateStrategy || "database",
594
+ skipStateCookieCheck: !!options.account?.skipStateCookieCheck
595
+ },
596
+ tables,
597
+ trustedOrigins: getTrustedOrigins(options),
598
+ baseURL: baseURL || "",
599
+ sessionConfig: {
600
+ updateAge: options.session?.updateAge !== void 0 ? options.session.updateAge : 1440 * 60,
601
+ expiresIn: options.session?.expiresIn || 3600 * 24 * 7,
602
+ freshAge: options.session?.freshAge === void 0 ? 3600 * 24 : options.session.freshAge,
603
+ cookieRefreshCache: (() => {
604
+ const refreshCache = options.session?.cookieCache?.refreshCache;
605
+ const maxAge = options.session?.cookieCache?.maxAge || 300;
606
+ if (refreshCache === false || refreshCache === void 0) return false;
607
+ if (refreshCache === true) return {
608
+ enabled: true,
609
+ updateAge: Math.floor(maxAge * .2)
610
+ };
611
+ return {
612
+ enabled: true,
613
+ updateAge: refreshCache.updateAge !== void 0 ? refreshCache.updateAge : Math.floor(maxAge * .2)
614
+ };
615
+ })()
616
+ },
617
+ secret,
618
+ rateLimit: {
619
+ ...options.rateLimit,
620
+ enabled: options.rateLimit?.enabled ?? isProduction,
621
+ window: options.rateLimit?.window || 10,
622
+ max: options.rateLimit?.max || 100,
623
+ storage: options.rateLimit?.storage || (options.secondaryStorage ? "secondary-storage" : "memory")
624
+ },
625
+ authCookies: cookies,
626
+ logger: logger$1,
627
+ generateId: generateIdFunc,
628
+ session: null,
629
+ secondaryStorage: options.secondaryStorage,
630
+ password: {
631
+ hash: options.emailAndPassword?.password?.hash || hashPassword,
632
+ verify: options.emailAndPassword?.password?.verify || verifyPassword,
633
+ config: {
634
+ minPasswordLength: options.emailAndPassword?.minPasswordLength || 8,
635
+ maxPasswordLength: options.emailAndPassword?.maxPasswordLength || 128
636
+ },
637
+ checkPassword
638
+ },
639
+ setNewSession(session$1) {
640
+ this.newSession = session$1;
641
+ },
642
+ newSession: null,
643
+ adapter,
644
+ internalAdapter: createInternalAdapter(adapter, {
645
+ options,
646
+ logger: logger$1,
647
+ hooks: options.databaseHooks ? [options.databaseHooks] : [],
648
+ generateId: generateIdFunc,
649
+ graphAdapter
650
+ }),
651
+ graphAdapter,
652
+ createAuthCookie: createCookieGetter(options),
653
+ async runMigrations() {
654
+ throw new BetterAuthError("runMigrations will be set by the specific init implementation");
655
+ },
656
+ publishTelemetry: publish,
657
+ skipCSRFCheck: !!options.advanced?.disableCSRFCheck,
658
+ skipOriginCheck: options.advanced?.disableOriginCheck !== void 0 ? options.advanced.disableOriginCheck : isTest() ? true : false
659
+ });
660
+ let context;
661
+ if (isPromise(initOrPromise)) ({context} = await initOrPromise);
662
+ else ({context} = initOrPromise);
663
+ return context;
664
+ }
665
+ const createBetterAuth = (options, initFn) => {
666
+ const authContext = initFn(options);
667
+ const { api } = getEndpoints(authContext, options);
668
+ return {
669
+ handler: async (request) => {
670
+ const ctx = await authContext;
671
+ const basePath = ctx.options.basePath || "/api/auth";
672
+ if (!ctx.options.baseURL) {
673
+ const baseURL = getBaseURL(void 0, basePath, request);
674
+ if (baseURL) {
675
+ ctx.baseURL = baseURL;
676
+ ctx.options.baseURL = getOrigin(ctx.baseURL) || void 0;
677
+ } else throw new BetterAuthError("Could not get base URL from request. Please provide a valid base URL.");
678
+ }
679
+ ctx.trustedOrigins = [...options.trustedOrigins ? Array.isArray(options.trustedOrigins) ? options.trustedOrigins : await options.trustedOrigins(request) : [], ctx.options.baseURL];
680
+ const { handler } = router(ctx, options);
681
+ return runWithAdapter(ctx.adapter, () => handler(request));
682
+ },
683
+ api,
684
+ options,
685
+ $context: authContext,
686
+ $ERROR_CODES: {
687
+ ...options.plugins?.reduce((acc, plugin) => {
688
+ if (plugin.$ERROR_CODES) return {
689
+ ...acc,
690
+ ...plugin.$ERROR_CODES
691
+ };
692
+ return acc;
693
+ }, {}),
694
+ ...BASE_ERROR_CODES
695
+ }
696
+ };
697
+ };
698
+
699
+ //#endregion
700
+ //#region ../better-auth/dist/auth-CLjxs1D8.mjs
701
+ const init = async (options) => {
702
+ const adapter = await getAdapter(options);
703
+ const getDatabaseType = (database) => getKyselyDatabaseType(database) || "unknown";
704
+ const ctx = await createAuthContext(adapter, options, getDatabaseType);
705
+ ctx.runMigrations = async function() {
706
+ if (!options.database || "updateMany" in options.database) throw new BetterAuthError("Database is not provided or it's an adapter. Migrations are only supported with a database instance.");
707
+ const { runMigrations } = await getMigrations(options);
708
+ await runMigrations();
709
+ };
710
+ return ctx;
711
+ };
712
+ /**
713
+ * Better Auth initializer for full mode (with Kysely)
714
+ *
715
+ * Check `minimal.ts` for minimal mode (without Kysely)
716
+ */
717
+ const betterAuth = (options) => {
718
+ return createBetterAuth(options, init);
719
+ };
720
+
721
+ //#endregion
722
+ //#region src/db-schema.final.ts
723
+ var db_schema_final_exports = /* @__PURE__ */ __export({
724
+ account: () => account,
725
+ accountRelations: () => accountRelations,
726
+ agent: () => agent,
727
+ agentRelations: () => agentRelations,
728
+ apikey: () => apikey,
729
+ apikeyRelations: () => apikeyRelations,
730
+ asset: () => asset,
731
+ assetRelations: () => assetRelations,
732
+ assetRole: () => assetRole,
733
+ assetRoleRelations: () => assetRoleRelations,
734
+ assetShare: () => assetShare,
735
+ assetShareLink: () => assetShareLink,
736
+ assetShareLinkRelations: () => assetShareLinkRelations,
737
+ assetShareRelations: () => assetShareRelations,
738
+ assetType: () => assetType,
739
+ assetTypeRelations: () => assetTypeRelations,
740
+ enterpriseSchema: () => enterpriseSchema,
741
+ invitation: () => invitation,
742
+ invitationRelations: () => invitationRelations,
743
+ member: () => member,
744
+ memberAssetRole: () => memberAssetRole,
745
+ memberAssetRoleRelations: () => memberAssetRoleRelations,
746
+ memberOrganizationRole: () => memberOrganizationRole,
747
+ memberOrganizationRoleRelations: () => memberOrganizationRoleRelations,
748
+ memberRelations: () => memberRelations,
749
+ memberTeamRole: () => memberTeamRole,
750
+ memberTeamRoleRelations: () => memberTeamRoleRelations,
751
+ oauthAccessToken: () => oauthAccessToken,
752
+ oauthAccessTokenRelations: () => oauthAccessTokenRelations,
753
+ oauthApplication: () => oauthApplication,
754
+ oauthApplicationRelations: () => oauthApplicationRelations,
755
+ oauthConsent: () => oauthConsent,
756
+ oauthConsentRelations: () => oauthConsentRelations,
757
+ object: () => object,
758
+ objectRelations: () => objectRelations,
759
+ organization: () => organization,
760
+ organizationRelations: () => organizationRelations,
761
+ organizationRole: () => organizationRole,
762
+ organizationRoleRelations: () => organizationRoleRelations,
763
+ person: () => person,
764
+ platformRole: () => platformRole,
765
+ relationship: () => relationship,
766
+ relationshipRelations: () => relationshipRelations,
767
+ schemaDefinition: () => schemaDefinition,
768
+ schemaDefinitionRelations: () => schemaDefinitionRelations,
769
+ session: () => session,
770
+ sessionRelations: () => sessionRelations,
771
+ team: () => team,
772
+ teamMember: () => teamMember,
773
+ teamMemberRelations: () => teamMemberRelations,
774
+ teamRelations: () => teamRelations,
775
+ teamRole: () => teamRole,
776
+ teamRoleRelations: () => teamRoleRelations,
777
+ twoFactor: () => twoFactor,
778
+ twoFactorRelations: () => twoFactorRelations,
779
+ user: () => user,
780
+ userRelations: () => userRelations,
781
+ verification: () => verification
782
+ });
783
+
784
+ //#endregion
785
+ export { getTelemetryAuthConfig as i, betterAuth as n, createTelemetry as r, db_schema_final_exports as t };