better-auth-studio 1.1.2-beta.7 → 1.1.2-beta.8
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/dist/core/handler.js +1 -0
- package/dist/core/handler.js.map +1 -1
- package/dist/public/assets/{main-D2k7jV-x.js → main-CeN9M3ie.js} +27 -27
- package/dist/public/index.html +1 -1
- package/dist/routes/api-router.d.ts +2 -0
- package/dist/routes/api-router.d.ts.map +1 -1
- package/dist/routes/api-router.js.map +1 -1
- package/dist/routes.d.ts +3 -1
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +48 -37
- package/dist/routes.js.map +1 -1
- package/package.json +1 -1
- package/public/assets/{main-D2k7jV-x.js → main-CeN9M3ie.js} +27 -27
- package/public/index.html +1 -1
package/dist/public/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<link rel="icon" type="image/png" href="/logo.png" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>Better Auth Studio</title>
|
|
8
|
-
<script type="module" crossorigin src="/assets/main-
|
|
8
|
+
<script type="module" crossorigin src="/assets/main-CeN9M3ie.js"></script>
|
|
9
9
|
<link rel="stylesheet" crossorigin href="/assets/main-GcANPjqc.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { StudioConfig } from '../types/handler.js';
|
|
1
2
|
import type { StudioAccessConfig } from '../utils/html-injector.js';
|
|
2
3
|
export type ApiContext = {
|
|
3
4
|
path: string;
|
|
@@ -7,6 +8,7 @@ export type ApiContext = {
|
|
|
7
8
|
auth: any;
|
|
8
9
|
basePath?: string;
|
|
9
10
|
accessConfig?: StudioAccessConfig;
|
|
11
|
+
studioConfig?: StudioConfig;
|
|
10
12
|
};
|
|
11
13
|
export type ApiResponse = {
|
|
12
14
|
status: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-router.d.ts","sourceRoot":"","sources":["../../src/routes/api-router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,IAAI,EAAE,GAAG,CAAC;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"api-router.d.ts","sourceRoot":"","sources":["../../src/routes/api-router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,IAAI,EAAE,GAAG,CAAC;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAClC,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,GAAG,CAAC;IACV,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,GAAG,CAAA;KAAE,CAAC,CAAC;CAChE,CAAC;AAEF,wBAAsB,eAAe,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,CAY3E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-router.js","sourceRoot":"","sources":["../../src/routes/api-router.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api-router.js","sourceRoot":"","sources":["../../src/routes/api-router.ts"],"names":[],"mappings":"AAoBA,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,GAAe;IACnD,MAAM,EAAE,sBAAsB,EAAE,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC;IAEhE,IAAI,CAAC;QACH,OAAO,MAAM,sBAAsB,CAAC,GAAG,CAAC,CAAC;IAC3C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;QAC3C,OAAO;YACL,MAAM,EAAE,GAAG;YACX,IAAI,EAAE,EAAE,KAAK,EAAE,uBAAuB,EAAE;SACzC,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/dist/routes.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
import type { AuthConfig } from './config.js';
|
|
3
|
+
import type { StudioConfig } from './types/handler.js';
|
|
3
4
|
import type { StudioAccessConfig } from './utils/html-injector.js';
|
|
4
5
|
export declare function safeImportAuthConfig(authConfigPath: string, noCache?: boolean): Promise<any>;
|
|
5
|
-
export declare function createRoutes(authConfig: AuthConfig, configPath?: string, geoDbPath?: string, preloadedAdapter?: any, preloadedAuthOptions?: any, accessConfig?: StudioAccessConfig, authInstance?: any): Router;
|
|
6
|
+
export declare function createRoutes(authConfig: AuthConfig, configPath?: string, geoDbPath?: string, preloadedAdapter?: any, preloadedAuthOptions?: any, accessConfig?: StudioAccessConfig, authInstance?: any, studioConfig?: StudioConfig): Router;
|
|
6
7
|
export declare function handleStudioApiRequest(ctx: {
|
|
7
8
|
path: string;
|
|
8
9
|
method: string;
|
|
@@ -12,6 +13,7 @@ export declare function handleStudioApiRequest(ctx: {
|
|
|
12
13
|
basePath?: string;
|
|
13
14
|
configPath?: string;
|
|
14
15
|
accessConfig?: StudioAccessConfig;
|
|
16
|
+
studioConfig?: StudioConfig;
|
|
15
17
|
}): Promise<{
|
|
16
18
|
status: number;
|
|
17
19
|
data: any;
|
package/dist/routes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAqBA,OAAO,EAA+B,MAAM,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAqBA,OAAO,EAA+B,MAAM,EAAE,MAAM,SAAS,CAAC;AAW9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAK9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AA0GnE,wBAAsB,oBAAoB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,UAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAqLhG;AAeD,wBAAgB,YAAY,CAC1B,UAAU,EAAE,UAAU,EACtB,UAAU,CAAC,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,EAClB,gBAAgB,CAAC,EAAE,GAAG,EACtB,oBAAoB,CAAC,EAAE,GAAG,EAC1B,YAAY,CAAC,EAAE,kBAAkB,EACjC,YAAY,CAAC,EAAE,GAAG,EAClB,YAAY,CAAC,EAAE,YAAY,GAC1B,MAAM,CAs0NR;AAED,wBAAsB,sBAAsB,CAAC,GAAG,EAAE;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,IAAI,EAAE,GAAG,CAAC;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAClC,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,GAAG,OAAO,CAAC;IACV,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,GAAG,CAAC;IACV,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,GAAG,CAAA;KAAE,CAAC,CAAC;CAChE,CAAC,CAgGD"}
|
package/dist/routes.js
CHANGED
|
@@ -9,6 +9,7 @@ import babelPresetTypeScript from '@babel/preset-typescript';
|
|
|
9
9
|
// @ts-expect-error
|
|
10
10
|
import { hex } from '@better-auth/utils/hex';
|
|
11
11
|
import { scryptAsync } from '@noble/hashes/scrypt.js';
|
|
12
|
+
import { loadConfig } from 'c12';
|
|
12
13
|
import { Router } from 'express';
|
|
13
14
|
import { createJiti } from 'jiti';
|
|
14
15
|
import { createRequire } from 'module';
|
|
@@ -18,7 +19,6 @@ import { getAuthData } from './data.js';
|
|
|
18
19
|
import { initializeGeoService, resolveIPLocation, setGeoDbPath } from './geo-service.js';
|
|
19
20
|
import { detectDatabaseWithDialect } from './utils/database-detection.js';
|
|
20
21
|
import { createStudioSession, decryptSession, encryptSession, isSessionValid, STUDIO_COOKIE_NAME, } from './utils/session.js';
|
|
21
|
-
import { loadConfig } from 'c12';
|
|
22
22
|
const config = {
|
|
23
23
|
N: 16384,
|
|
24
24
|
r: 16,
|
|
@@ -269,7 +269,7 @@ async function findAuthConfigPath() {
|
|
|
269
269
|
}
|
|
270
270
|
return null;
|
|
271
271
|
}
|
|
272
|
-
export function createRoutes(authConfig, configPath, geoDbPath, preloadedAdapter, preloadedAuthOptions, accessConfig, authInstance) {
|
|
272
|
+
export function createRoutes(authConfig, configPath, geoDbPath, preloadedAdapter, preloadedAuthOptions, accessConfig, authInstance, studioConfig) {
|
|
273
273
|
const isSelfHosted = !!preloadedAdapter;
|
|
274
274
|
const getAuthConfigSafe = async () => {
|
|
275
275
|
if (isSelfHosted) {
|
|
@@ -938,7 +938,8 @@ export function createRoutes(authConfig, configPath, geoDbPath, preloadedAdapter
|
|
|
938
938
|
const { isEventIngestionInitialized, getEventIngestionProvider } = await import('./utils/event-ingestion.js');
|
|
939
939
|
const initialized = isEventIngestionInitialized();
|
|
940
940
|
const provider = getEventIngestionProvider();
|
|
941
|
-
|
|
941
|
+
let configToUse = studioConfig || null;
|
|
942
|
+
if (!initialized && !configToUse) {
|
|
942
943
|
try {
|
|
943
944
|
const { initializeEventIngestionAndHooks } = await import('./core/handler.js');
|
|
944
945
|
const { existsSync } = await import('node:fs');
|
|
@@ -957,34 +958,7 @@ export function createRoutes(authConfig, configPath, geoDbPath, preloadedAdapter
|
|
|
957
958
|
break;
|
|
958
959
|
}
|
|
959
960
|
}
|
|
960
|
-
|
|
961
|
-
const jitiOptions = {
|
|
962
|
-
debug: false,
|
|
963
|
-
transformOptions: {
|
|
964
|
-
babel: {
|
|
965
|
-
presets: [
|
|
966
|
-
[
|
|
967
|
-
babelPresetTypeScript,
|
|
968
|
-
{
|
|
969
|
-
isTSX: true,
|
|
970
|
-
allExtensions: true,
|
|
971
|
-
},
|
|
972
|
-
],
|
|
973
|
-
[babelPresetReact, { runtime: 'automatic' }],
|
|
974
|
-
],
|
|
975
|
-
},
|
|
976
|
-
},
|
|
977
|
-
extensions: ['.ts', '.js', '.tsx', '.jsx'],
|
|
978
|
-
alias,
|
|
979
|
-
interopDefault: true,
|
|
980
|
-
};
|
|
981
|
-
const { config } = await loadConfig({
|
|
982
|
-
configFile: studioConfigPath || undefined,
|
|
983
|
-
cwd: process.cwd(),
|
|
984
|
-
dotenv: true,
|
|
985
|
-
jitiOptions,
|
|
986
|
-
});
|
|
987
|
-
if (!config) {
|
|
961
|
+
if (!studioConfigPath && configPath) {
|
|
988
962
|
const configDir = require('node:path').dirname(configPath);
|
|
989
963
|
for (const file of possibleFiles) {
|
|
990
964
|
const path = require('node:path').join(configDir, file);
|
|
@@ -994,18 +968,55 @@ export function createRoutes(authConfig, configPath, geoDbPath, preloadedAdapter
|
|
|
994
968
|
}
|
|
995
969
|
}
|
|
996
970
|
}
|
|
997
|
-
if (
|
|
998
|
-
const
|
|
999
|
-
|
|
1000
|
-
|
|
971
|
+
if (studioConfigPath) {
|
|
972
|
+
const alias = getPathAliases(process.cwd()) || {};
|
|
973
|
+
const jitiOptions = {
|
|
974
|
+
debug: false,
|
|
975
|
+
transformOptions: {
|
|
976
|
+
babel: {
|
|
977
|
+
presets: [
|
|
978
|
+
[
|
|
979
|
+
babelPresetTypeScript,
|
|
980
|
+
{
|
|
981
|
+
isTSX: true,
|
|
982
|
+
allExtensions: true,
|
|
983
|
+
},
|
|
984
|
+
],
|
|
985
|
+
[babelPresetReact, { runtime: 'automatic' }],
|
|
986
|
+
],
|
|
987
|
+
},
|
|
988
|
+
},
|
|
989
|
+
extensions: ['.ts', '.js', '.tsx', '.jsx'],
|
|
990
|
+
alias,
|
|
991
|
+
interopDefault: true,
|
|
992
|
+
};
|
|
993
|
+
const { config } = await loadConfig({
|
|
994
|
+
configFile: studioConfigPath || undefined,
|
|
995
|
+
cwd: process.cwd(),
|
|
996
|
+
dotenv: true,
|
|
997
|
+
jitiOptions,
|
|
998
|
+
});
|
|
999
|
+
if (config) {
|
|
1000
|
+
configToUse = config?.default || config?.config || config;
|
|
1001
1001
|
}
|
|
1002
1002
|
}
|
|
1003
1003
|
}
|
|
1004
|
+
catch (initError) {
|
|
1005
|
+
console.warn('Failed to load studio config:', initError?.message || initError);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
if (!initialized && configToUse?.events?.enabled) {
|
|
1009
|
+
try {
|
|
1010
|
+
const { initializeEventIngestionAndHooks } = await import('./core/handler.js');
|
|
1011
|
+
await initializeEventIngestionAndHooks(configToUse);
|
|
1012
|
+
}
|
|
1004
1013
|
catch (initError) {
|
|
1005
1014
|
console.warn('Failed to initialize event ingestion:', initError?.message || initError);
|
|
1006
1015
|
}
|
|
1007
1016
|
}
|
|
1008
|
-
const isEnabled =
|
|
1017
|
+
const isEnabled = configToUse?.events?.enabled === true &&
|
|
1018
|
+
isEventIngestionInitialized() &&
|
|
1019
|
+
!!getEventIngestionProvider();
|
|
1009
1020
|
res.json({
|
|
1010
1021
|
enabled: isEnabled,
|
|
1011
1022
|
initialized: isEventIngestionInitialized(),
|
|
@@ -6391,7 +6402,7 @@ export async function handleStudioApiRequest(ctx) {
|
|
|
6391
6402
|
catch { }
|
|
6392
6403
|
}
|
|
6393
6404
|
const authOptions = ctx.auth?.options || null;
|
|
6394
|
-
const router = createRoutes(ctx.auth, ctx.configPath || '', undefined, preloadedAdapter, authOptions, ctx.accessConfig, ctx.auth);
|
|
6405
|
+
const router = createRoutes(ctx.auth, ctx.configPath || '', undefined, preloadedAdapter, authOptions, ctx.accessConfig, ctx.auth, ctx.studioConfig);
|
|
6395
6406
|
const [pathname, queryString] = ctx.path.split('?');
|
|
6396
6407
|
const query = {};
|
|
6397
6408
|
if (queryString) {
|