@better-auth/core 1.6.27 → 1.6.28
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/api/index.d.mts +26 -26
- package/dist/async_hooks/index.d.mts +1 -0
- package/dist/async_hooks/pure.index.d.mts +1 -0
- package/dist/context/endpoint-context.d.mts +1 -1
- package/dist/context/global.d.mts +1 -0
- package/dist/context/global.mjs +1 -1
- package/dist/context/request-state.d.mts +1 -0
- package/dist/context/transaction.d.mts +1 -1
- package/dist/db/adapter/factory.d.mts +5 -3
- package/dist/db/adapter/factory.mjs +2 -2
- package/dist/db/adapter/get-default-field-name.d.mts +9 -2
- package/dist/db/adapter/get-default-model-name.d.mts +5 -1
- package/dist/db/adapter/get-field-attributes.d.mts +11 -4
- package/dist/db/adapter/get-field-name.d.mts +9 -2
- package/dist/db/adapter/get-id-field.d.mts +12 -4
- package/dist/db/adapter/get-model-name.d.mts +5 -1
- package/dist/db/adapter/index.d.mts +32 -7
- package/dist/db/adapter/types.d.mts +17 -5
- package/dist/db/adapter/utils.d.mts +1 -0
- package/dist/db/get-tables.d.mts +0 -1
- package/dist/db/plugin.d.mts +2 -1
- package/dist/db/schema/account.d.mts +1 -1
- package/dist/db/schema/rate-limit.d.mts +1 -1
- package/dist/db/schema/session.d.mts +1 -1
- package/dist/db/schema/shared.d.mts +1 -0
- package/dist/db/schema/user.d.mts +1 -1
- package/dist/db/schema/verification.d.mts +1 -1
- package/dist/db/type.d.mts +10 -6
- package/dist/env/logger.d.mts +25 -25
- package/dist/error/codes.d.mts +1 -0
- package/dist/error/index.d.mts +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/instrumentation/attributes.d.mts +1 -0
- package/dist/instrumentation/pure.index.d.mts +1 -0
- package/dist/instrumentation/tracer.mjs +1 -1
- package/dist/oauth2/client-credentials-token.d.mts +20 -4
- package/dist/oauth2/create-authorization-url.d.mts +20 -3
- package/dist/oauth2/oauth-provider.d.mts +0 -1
- package/dist/oauth2/refresh-access-token.d.mts +22 -4
- package/dist/oauth2/reject-redirects.mjs +1 -1
- package/dist/oauth2/utils.d.mts +1 -0
- package/dist/oauth2/validate-authorization-code.d.mts +37 -6
- package/dist/oauth2/verify.d.mts +10 -12
- package/dist/oauth2/verify.mjs +2 -2
- package/dist/social-providers/apple.d.mts +11 -4
- package/dist/social-providers/atlassian.d.mts +11 -3
- package/dist/social-providers/cognito.d.mts +11 -4
- package/dist/social-providers/discord.d.mts +9 -3
- package/dist/social-providers/dropbox.d.mts +11 -3
- package/dist/social-providers/facebook.d.mts +10 -4
- package/dist/social-providers/figma.d.mts +11 -3
- package/dist/social-providers/github.d.mts +12 -3
- package/dist/social-providers/gitlab.d.mts +12 -3
- package/dist/social-providers/google.d.mts +19 -5
- package/dist/social-providers/huggingface.d.mts +11 -3
- package/dist/social-providers/index.d.mts +364 -78
- package/dist/social-providers/kakao.d.mts +9 -3
- package/dist/social-providers/kick.d.mts +11 -3
- package/dist/social-providers/line.d.mts +12 -4
- package/dist/social-providers/linear.d.mts +10 -3
- package/dist/social-providers/linkedin.d.mts +10 -3
- package/dist/social-providers/microsoft-entra-id.d.mts +5 -3
- package/dist/social-providers/microsoft-entra-id.mjs +1 -2
- package/dist/social-providers/naver.d.mts +18 -22
- package/dist/social-providers/notion.d.mts +10 -3
- package/dist/social-providers/paybin.d.mts +12 -3
- package/dist/social-providers/paypal.d.mts +9 -4
- package/dist/social-providers/polar.d.mts +11 -3
- package/dist/social-providers/railway.d.mts +11 -3
- package/dist/social-providers/reddit.d.mts +9 -3
- package/dist/social-providers/roblox.d.mts +9 -3
- package/dist/social-providers/salesforce.d.mts +11 -3
- package/dist/social-providers/slack.d.mts +9 -3
- package/dist/social-providers/spotify.d.mts +11 -3
- package/dist/social-providers/tiktok.d.mts +10 -5
- package/dist/social-providers/twitch.d.mts +9 -3
- package/dist/social-providers/twitter.d.mts +16 -25
- package/dist/social-providers/vercel.d.mts +11 -3
- package/dist/social-providers/vk.d.mts +12 -3
- package/dist/social-providers/wechat.d.mts +8 -3
- package/dist/social-providers/zoom.d.mts +14 -5
- package/dist/types/context.d.mts +1 -2
- package/dist/types/cookie.d.mts +1 -0
- package/dist/types/helper.d.mts +1 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/types/init-options.d.mts +7 -10
- package/dist/types/plugin-client.d.mts +3 -1
- package/dist/types/plugin.d.mts +2 -2
- package/dist/utils/async.d.mts +1 -0
- package/dist/utils/db.d.mts +0 -1
- package/dist/utils/deprecate.d.mts +1 -0
- package/dist/utils/email.d.mts +4 -1
- package/dist/utils/error-codes.d.mts +2 -2
- package/dist/utils/host.d.mts +1 -27
- package/dist/utils/host.mjs +1 -1
- package/dist/utils/ip.d.mts +0 -1
- package/dist/utils/ip.mjs +1 -1
- package/dist/utils/is-api-error.d.mts +1 -0
- package/dist/utils/redirect-uri.d.mts +1 -0
- package/package.json +2 -2
- package/src/db/type.ts +2 -1
package/dist/api/index.d.mts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { BetterAuthDBSchema, ModelNames, SecondaryStorage } from "../db/type.mjs";
|
|
2
2
|
import { DBAdapter } from "../db/adapter/index.mjs";
|
|
3
3
|
import { createLogger } from "../env/logger.mjs";
|
|
4
|
-
import "../db/index.mjs";
|
|
5
4
|
import { AuthContext } from "../types/context.mjs";
|
|
6
|
-
import "../types/index.mjs";
|
|
7
5
|
import { OAuthProvider } from "../oauth2/oauth-provider.mjs";
|
|
8
|
-
import "
|
|
6
|
+
import * as _$better_call0 from "better-call";
|
|
9
7
|
import { EndpointHandler, EndpointOptions, MiddlewareHandler, StrictEndpoint } from "better-call";
|
|
8
|
+
import * as _$_better_auth_core0 from "@better-auth/core";
|
|
9
|
+
|
|
10
10
|
//#region src/api/index.d.ts
|
|
11
|
-
declare const optionsMiddleware:
|
|
11
|
+
declare const optionsMiddleware: _$better_call0.Middleware<_$better_call0.MiddlewareOptions, <InputCtx extends _$better_call0.MiddlewareInputContext<_$better_call0.MiddlewareOptions>>(inputContext: InputCtx) => Promise<AuthContext>>;
|
|
12
12
|
declare const createAuthMiddleware: {
|
|
13
|
-
<Options extends
|
|
14
|
-
options:
|
|
13
|
+
<Options extends _$better_call0.MiddlewareOptions, R>(options: Options, handler: (ctx: _$better_call0.MiddlewareContext<Options, _$_better_auth_core0.PluginContext<_$_better_auth_core0.BetterAuthOptions> & _$_better_auth_core0.InfoContext & {
|
|
14
|
+
options: _$_better_auth_core0.BetterAuthOptions;
|
|
15
15
|
trustedOrigins: string[];
|
|
16
16
|
trustedProviders: string[];
|
|
17
17
|
isTrustedOrigin: (url: string, settings?: {
|
|
@@ -85,19 +85,19 @@ declare const createAuthMiddleware: {
|
|
|
85
85
|
} & Record<string, any>;
|
|
86
86
|
} | null) => void;
|
|
87
87
|
socialProviders: OAuthProvider[];
|
|
88
|
-
authCookies:
|
|
88
|
+
authCookies: _$_better_auth_core0.BetterAuthCookies;
|
|
89
89
|
logger: ReturnType<typeof createLogger>;
|
|
90
90
|
rateLimit: {
|
|
91
91
|
enabled: boolean;
|
|
92
92
|
window: number;
|
|
93
93
|
max: number;
|
|
94
94
|
storage: "memory" | "database" | "secondary-storage";
|
|
95
|
-
} & Omit<
|
|
96
|
-
adapter: DBAdapter<
|
|
97
|
-
internalAdapter:
|
|
98
|
-
createAuthCookie: (cookieName: string, overrideAttributes?: Partial<
|
|
95
|
+
} & Omit<_$_better_auth_core0.BetterAuthRateLimitOptions, "enabled" | "window" | "max" | "storage">;
|
|
96
|
+
adapter: DBAdapter<_$_better_auth_core0.BetterAuthOptions>;
|
|
97
|
+
internalAdapter: _$_better_auth_core0.InternalAdapter<_$_better_auth_core0.BetterAuthOptions>;
|
|
98
|
+
createAuthCookie: (cookieName: string, overrideAttributes?: Partial<_$better_call0.CookieOptions> | undefined) => _$_better_auth_core0.BetterAuthCookie;
|
|
99
99
|
secret: string;
|
|
100
|
-
secretConfig: string |
|
|
100
|
+
secretConfig: string | _$_better_auth_core0.SecretConfig;
|
|
101
101
|
sessionConfig: {
|
|
102
102
|
updateAge: number;
|
|
103
103
|
expiresIn: number;
|
|
@@ -122,7 +122,7 @@ declare const createAuthMiddleware: {
|
|
|
122
122
|
minPasswordLength: number;
|
|
123
123
|
maxPasswordLength: number;
|
|
124
124
|
};
|
|
125
|
-
checkPassword: (userId: string, ctx:
|
|
125
|
+
checkPassword: (userId: string, ctx: _$_better_auth_core0.GenericEndpointContext<_$_better_auth_core0.BetterAuthOptions>) => Promise<boolean>;
|
|
126
126
|
};
|
|
127
127
|
tables: BetterAuthDBSchema;
|
|
128
128
|
runMigrations: () => Promise<void>;
|
|
@@ -134,13 +134,13 @@ declare const createAuthMiddleware: {
|
|
|
134
134
|
skipOriginCheck: boolean | string[];
|
|
135
135
|
skipCSRFCheck: boolean;
|
|
136
136
|
runInBackground: (promise: Promise<unknown>) => void;
|
|
137
|
-
runInBackgroundOrAwait: (promise: Promise<unknown> | void) =>
|
|
137
|
+
runInBackgroundOrAwait: (promise: Promise<unknown> | void) => _$_better_auth_core0.Awaitable<unknown>;
|
|
138
138
|
} & {
|
|
139
139
|
returned?: unknown | undefined;
|
|
140
140
|
responseHeaders?: Headers | undefined;
|
|
141
|
-
}>) => Promise<R>):
|
|
142
|
-
<Options extends
|
|
143
|
-
options:
|
|
141
|
+
}>) => Promise<R>): _$better_call0.Middleware<Options, (inputContext: _$better_call0.MiddlewareInputContext<Options>) => Promise<R>>;
|
|
142
|
+
<Options extends _$better_call0.MiddlewareOptions, R_1>(handler: (ctx: _$better_call0.MiddlewareContext<Options, _$_better_auth_core0.PluginContext<_$_better_auth_core0.BetterAuthOptions> & _$_better_auth_core0.InfoContext & {
|
|
143
|
+
options: _$_better_auth_core0.BetterAuthOptions;
|
|
144
144
|
trustedOrigins: string[];
|
|
145
145
|
trustedProviders: string[];
|
|
146
146
|
isTrustedOrigin: (url: string, settings?: {
|
|
@@ -214,19 +214,19 @@ declare const createAuthMiddleware: {
|
|
|
214
214
|
} & Record<string, any>;
|
|
215
215
|
} | null) => void;
|
|
216
216
|
socialProviders: OAuthProvider[];
|
|
217
|
-
authCookies:
|
|
217
|
+
authCookies: _$_better_auth_core0.BetterAuthCookies;
|
|
218
218
|
logger: ReturnType<typeof createLogger>;
|
|
219
219
|
rateLimit: {
|
|
220
220
|
enabled: boolean;
|
|
221
221
|
window: number;
|
|
222
222
|
max: number;
|
|
223
223
|
storage: "memory" | "database" | "secondary-storage";
|
|
224
|
-
} & Omit<
|
|
225
|
-
adapter: DBAdapter<
|
|
226
|
-
internalAdapter:
|
|
227
|
-
createAuthCookie: (cookieName: string, overrideAttributes?: Partial<
|
|
224
|
+
} & Omit<_$_better_auth_core0.BetterAuthRateLimitOptions, "enabled" | "window" | "max" | "storage">;
|
|
225
|
+
adapter: DBAdapter<_$_better_auth_core0.BetterAuthOptions>;
|
|
226
|
+
internalAdapter: _$_better_auth_core0.InternalAdapter<_$_better_auth_core0.BetterAuthOptions>;
|
|
227
|
+
createAuthCookie: (cookieName: string, overrideAttributes?: Partial<_$better_call0.CookieOptions> | undefined) => _$_better_auth_core0.BetterAuthCookie;
|
|
228
228
|
secret: string;
|
|
229
|
-
secretConfig: string |
|
|
229
|
+
secretConfig: string | _$_better_auth_core0.SecretConfig;
|
|
230
230
|
sessionConfig: {
|
|
231
231
|
updateAge: number;
|
|
232
232
|
expiresIn: number;
|
|
@@ -251,7 +251,7 @@ declare const createAuthMiddleware: {
|
|
|
251
251
|
minPasswordLength: number;
|
|
252
252
|
maxPasswordLength: number;
|
|
253
253
|
};
|
|
254
|
-
checkPassword: (userId: string, ctx:
|
|
254
|
+
checkPassword: (userId: string, ctx: _$_better_auth_core0.GenericEndpointContext<_$_better_auth_core0.BetterAuthOptions>) => Promise<boolean>;
|
|
255
255
|
};
|
|
256
256
|
tables: BetterAuthDBSchema;
|
|
257
257
|
runMigrations: () => Promise<void>;
|
|
@@ -263,11 +263,11 @@ declare const createAuthMiddleware: {
|
|
|
263
263
|
skipOriginCheck: boolean | string[];
|
|
264
264
|
skipCSRFCheck: boolean;
|
|
265
265
|
runInBackground: (promise: Promise<unknown>) => void;
|
|
266
|
-
runInBackgroundOrAwait: (promise: Promise<unknown> | void) =>
|
|
266
|
+
runInBackgroundOrAwait: (promise: Promise<unknown> | void) => _$_better_auth_core0.Awaitable<unknown>;
|
|
267
267
|
} & {
|
|
268
268
|
returned?: unknown | undefined;
|
|
269
269
|
responseHeaders?: Headers | undefined;
|
|
270
|
-
}>) => Promise<R_1>):
|
|
270
|
+
}>) => Promise<R_1>): _$better_call0.Middleware<Options, (inputContext: _$better_call0.MiddlewareInputContext<Options>) => Promise<R_1>>;
|
|
271
271
|
};
|
|
272
272
|
type AuthEndpointHandler<Path extends string, Options extends EndpointOptions, R> = EndpointHandler<Path, Options, R, AuthContext>;
|
|
273
273
|
type PathlessAuthEndpointHandler<Options extends EndpointOptions, R> = AuthEndpointHandler<string, Options, R>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AuthContext } from "../types/context.mjs";
|
|
2
|
-
import "../types/index.mjs";
|
|
3
2
|
import { EndpointContext, InputContext } from "better-call";
|
|
4
3
|
import { AsyncLocalStorage } from "@better-auth/core/async_hooks";
|
|
4
|
+
|
|
5
5
|
//#region src/context/endpoint-context.d.ts
|
|
6
6
|
type AuthEndpointContext = Partial<InputContext<string, any> & EndpointContext<string, any>> & {
|
|
7
7
|
context: AuthContext;
|
package/dist/context/global.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DBAdapter, DBTransactionAdapter } from "../db/adapter/index.mjs";
|
|
2
2
|
import { BetterAuthOptions } from "../types/init-options.mjs";
|
|
3
|
-
import "../types/index.mjs";
|
|
4
3
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
|
+
|
|
5
5
|
//#region src/context/transaction.d.ts
|
|
6
6
|
type StoredAdapter = DBTransactionAdapter<BetterAuthOptions>;
|
|
7
7
|
type HookContext = {
|
|
@@ -7,9 +7,11 @@ import { initGetModelName } from "./get-model-name.mjs";
|
|
|
7
7
|
import { AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFactoryOptions, AdapterTestDebugLogs } from "./types.mjs";
|
|
8
8
|
import { DBAdapter } from "./index.mjs";
|
|
9
9
|
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
10
|
-
import "../../types/index.mjs";
|
|
11
10
|
//#region src/db/adapter/factory.d.ts
|
|
12
11
|
type AdapterFactory<Options extends BetterAuthOptions> = (options: Options) => DBAdapter<Options>;
|
|
13
|
-
declare const createAdapterFactory: <Options extends BetterAuthOptions>({
|
|
12
|
+
declare const createAdapterFactory: <Options extends BetterAuthOptions>({
|
|
13
|
+
adapter: customAdapter,
|
|
14
|
+
config: cfg
|
|
15
|
+
}: AdapterFactoryOptions) => AdapterFactory<Options>;
|
|
14
16
|
//#endregion
|
|
15
|
-
export { AdapterFactory,
|
|
17
|
+
export { AdapterFactory, createAdapterFactory };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { getCurrentAdapter, runWithTransaction } from "../../context/transaction.mjs";
|
|
2
2
|
import { BetterAuthError } from "../../error/index.mjs";
|
|
3
|
-
import { getAuthTables } from "../get-tables.mjs";
|
|
4
3
|
import { getColorDepth } from "../../env/color-depth.mjs";
|
|
5
4
|
import { TTY_COLORS, createLogger } from "../../env/logger.mjs";
|
|
5
|
+
import { getAuthTables } from "../get-tables.mjs";
|
|
6
6
|
import { safeJSONParse } from "../../utils/json.mjs";
|
|
7
7
|
import { initGetDefaultModelName } from "./get-default-model-name.mjs";
|
|
8
8
|
import { initGetDefaultFieldName } from "./get-default-field-name.mjs";
|
|
@@ -902,4 +902,4 @@ function formatAction(action) {
|
|
|
902
902
|
return `${TTY_COLORS.dim}(${action})${TTY_COLORS.reset}`;
|
|
903
903
|
}
|
|
904
904
|
//#endregion
|
|
905
|
-
export { createAdapterFactory
|
|
905
|
+
export { createAdapterFactory };
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { BetterAuthDBSchema } from "../type.mjs";
|
|
2
|
+
|
|
2
3
|
//#region src/db/adapter/get-default-field-name.d.ts
|
|
3
|
-
declare const initGetDefaultFieldName: ({
|
|
4
|
+
declare const initGetDefaultFieldName: ({
|
|
5
|
+
schema,
|
|
6
|
+
usePlural
|
|
7
|
+
}: {
|
|
4
8
|
schema: BetterAuthDBSchema;
|
|
5
9
|
usePlural: boolean | undefined;
|
|
6
|
-
}) => ({
|
|
10
|
+
}) => ({
|
|
11
|
+
field,
|
|
12
|
+
model: unsafeModel
|
|
13
|
+
}: {
|
|
7
14
|
model: string;
|
|
8
15
|
field: string;
|
|
9
16
|
}) => string;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { BetterAuthDBSchema } from "../type.mjs";
|
|
2
|
+
|
|
2
3
|
//#region src/db/adapter/get-default-model-name.d.ts
|
|
3
|
-
declare const initGetDefaultModelName: ({
|
|
4
|
+
declare const initGetDefaultModelName: ({
|
|
5
|
+
usePlural,
|
|
6
|
+
schema
|
|
7
|
+
}: {
|
|
4
8
|
usePlural: boolean | undefined;
|
|
5
9
|
schema: BetterAuthDBSchema;
|
|
6
10
|
}) => (model: string) => string;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { BetterAuthDBSchema, DBFieldAttribute, DBFieldType } from "../type.mjs";
|
|
2
2
|
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
3
|
-
import "../index.mjs";
|
|
4
|
-
import "../../types/index.mjs";
|
|
5
3
|
//#region src/db/adapter/get-field-attributes.d.ts
|
|
6
|
-
declare const initGetFieldAttributes: ({
|
|
4
|
+
declare const initGetFieldAttributes: ({
|
|
5
|
+
usePlural,
|
|
6
|
+
schema,
|
|
7
|
+
options,
|
|
8
|
+
customIdGenerator,
|
|
9
|
+
disableIdGeneration
|
|
10
|
+
}: {
|
|
7
11
|
usePlural?: boolean;
|
|
8
12
|
schema: BetterAuthDBSchema;
|
|
9
13
|
options: BetterAuthOptions;
|
|
@@ -11,7 +15,10 @@ declare const initGetFieldAttributes: ({ usePlural, schema, options, customIdGen
|
|
|
11
15
|
customIdGenerator?: ((props: {
|
|
12
16
|
model: string;
|
|
13
17
|
}) => string) | undefined;
|
|
14
|
-
}) => ({
|
|
18
|
+
}) => ({
|
|
19
|
+
model,
|
|
20
|
+
field
|
|
21
|
+
}: {
|
|
15
22
|
model: string;
|
|
16
23
|
field: string;
|
|
17
24
|
}) => DBFieldAttribute<DBFieldType>;
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { BetterAuthDBSchema } from "../type.mjs";
|
|
2
|
+
|
|
2
3
|
//#region src/db/adapter/get-field-name.d.ts
|
|
3
|
-
declare const initGetFieldName: ({
|
|
4
|
+
declare const initGetFieldName: ({
|
|
5
|
+
schema,
|
|
6
|
+
usePlural
|
|
7
|
+
}: {
|
|
4
8
|
schema: BetterAuthDBSchema;
|
|
5
9
|
usePlural: boolean | undefined;
|
|
6
|
-
}) => ({
|
|
10
|
+
}) => ({
|
|
11
|
+
model: modelName,
|
|
12
|
+
field: fieldName
|
|
13
|
+
}: {
|
|
7
14
|
model: string;
|
|
8
15
|
field: string;
|
|
9
16
|
}) => string;
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { BetterAuthDBSchema, DBPrimitive } from "../type.mjs";
|
|
2
2
|
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
3
|
-
import "../index.mjs";
|
|
4
|
-
import "../../types/index.mjs";
|
|
5
3
|
//#region src/db/adapter/get-id-field.d.ts
|
|
6
|
-
declare const initGetIdField: ({
|
|
4
|
+
declare const initGetIdField: ({
|
|
5
|
+
usePlural,
|
|
6
|
+
schema,
|
|
7
|
+
disableIdGeneration,
|
|
8
|
+
options,
|
|
9
|
+
customIdGenerator,
|
|
10
|
+
supportsUUIDs
|
|
11
|
+
}: {
|
|
7
12
|
usePlural?: boolean;
|
|
8
13
|
schema: BetterAuthDBSchema;
|
|
9
14
|
options: BetterAuthOptions;
|
|
@@ -12,7 +17,10 @@ declare const initGetIdField: ({ usePlural, schema, disableIdGeneration, options
|
|
|
12
17
|
model: string;
|
|
13
18
|
}) => string) | undefined;
|
|
14
19
|
supportsUUIDs?: boolean;
|
|
15
|
-
}) => ({
|
|
20
|
+
}) => ({
|
|
21
|
+
customModelName,
|
|
22
|
+
forceAllowId
|
|
23
|
+
}: {
|
|
16
24
|
customModelName?: string;
|
|
17
25
|
forceAllowId?: boolean;
|
|
18
26
|
}) => {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { BetterAuthDBSchema } from "../type.mjs";
|
|
2
|
+
|
|
2
3
|
//#region src/db/adapter/get-model-name.d.ts
|
|
3
|
-
declare const initGetModelName: ({
|
|
4
|
+
declare const initGetModelName: ({
|
|
5
|
+
usePlural,
|
|
6
|
+
schema
|
|
7
|
+
}: {
|
|
4
8
|
usePlural: boolean | undefined;
|
|
5
9
|
schema: BetterAuthDBSchema;
|
|
6
10
|
}) => (model: string) => string;
|
|
@@ -9,7 +9,6 @@ import { AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFac
|
|
|
9
9
|
import { AdapterFactory, createAdapterFactory } from "./factory.mjs";
|
|
10
10
|
import { deepmerge, withApplyDefault } from "./utils.mjs";
|
|
11
11
|
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
12
|
-
import "../../types/index.mjs";
|
|
13
12
|
//#region src/db/adapter/index.d.ts
|
|
14
13
|
type DBAdapterDebugLogOption = boolean | {
|
|
15
14
|
/**
|
|
@@ -491,7 +490,11 @@ type DBAdapter<Options extends BetterAuthOptions = BetterAuthOptions> = {
|
|
|
491
490
|
};
|
|
492
491
|
type CleanedWhere = Required<Where>;
|
|
493
492
|
interface CustomAdapter {
|
|
494
|
-
create: <T extends Record<string, any>>({
|
|
493
|
+
create: <T extends Record<string, any>>({
|
|
494
|
+
data,
|
|
495
|
+
model,
|
|
496
|
+
select
|
|
497
|
+
}: {
|
|
495
498
|
model: string;
|
|
496
499
|
data: T;
|
|
497
500
|
select?: string[] | undefined;
|
|
@@ -506,13 +509,26 @@ interface CustomAdapter {
|
|
|
506
509
|
where: CleanedWhere[];
|
|
507
510
|
update: Record<string, any>;
|
|
508
511
|
}) => Promise<number>;
|
|
509
|
-
findOne: <T>({
|
|
512
|
+
findOne: <T>({
|
|
513
|
+
model,
|
|
514
|
+
where,
|
|
515
|
+
select,
|
|
516
|
+
join
|
|
517
|
+
}: {
|
|
510
518
|
model: string;
|
|
511
519
|
where: CleanedWhere[];
|
|
512
520
|
select?: string[] | undefined;
|
|
513
521
|
join?: JoinConfig | undefined;
|
|
514
522
|
}) => Promise<T | null>;
|
|
515
|
-
findMany: <T>({
|
|
523
|
+
findMany: <T>({
|
|
524
|
+
model,
|
|
525
|
+
where,
|
|
526
|
+
limit,
|
|
527
|
+
select,
|
|
528
|
+
sortBy,
|
|
529
|
+
offset,
|
|
530
|
+
join
|
|
531
|
+
}: {
|
|
516
532
|
model: string;
|
|
517
533
|
where?: CleanedWhere[] | undefined;
|
|
518
534
|
limit: number;
|
|
@@ -524,11 +540,17 @@ interface CustomAdapter {
|
|
|
524
540
|
offset?: number | undefined;
|
|
525
541
|
join?: JoinConfig | undefined;
|
|
526
542
|
}) => Promise<T[]>;
|
|
527
|
-
delete: ({
|
|
543
|
+
delete: ({
|
|
544
|
+
model,
|
|
545
|
+
where
|
|
546
|
+
}: {
|
|
528
547
|
model: string;
|
|
529
548
|
where: CleanedWhere[];
|
|
530
549
|
}) => Promise<void>;
|
|
531
|
-
deleteMany: ({
|
|
550
|
+
deleteMany: ({
|
|
551
|
+
model,
|
|
552
|
+
where
|
|
553
|
+
}: {
|
|
532
554
|
model: string;
|
|
533
555
|
where: CleanedWhere[];
|
|
534
556
|
}) => Promise<number>;
|
|
@@ -564,7 +586,10 @@ interface CustomAdapter {
|
|
|
564
586
|
increment: Record<string, number>;
|
|
565
587
|
set?: Record<string, unknown> | undefined;
|
|
566
588
|
}) => Promise<T | null>;
|
|
567
|
-
count: ({
|
|
589
|
+
count: ({
|
|
590
|
+
model,
|
|
591
|
+
where
|
|
592
|
+
}: {
|
|
568
593
|
model: string;
|
|
569
594
|
where?: CleanedWhere[] | undefined;
|
|
570
595
|
}) => Promise<number>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { BetterAuthDBSchema, DBFieldAttribute } from "../type.mjs";
|
|
2
2
|
import { CleanedWhere, CustomAdapter, DBAdapterFactoryConfig, DBTransactionAdapter, JoinConfig, Where } from "./index.mjs";
|
|
3
3
|
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
4
|
-
import "../../types/index.mjs";
|
|
5
4
|
//#region src/db/adapter/types.d.ts
|
|
6
5
|
type AdapterFactoryOptions = {
|
|
7
6
|
config: AdapterFactoryConfig;
|
|
@@ -36,7 +35,10 @@ type AdapterFactoryCustomizeAdapterCreator = (config: {
|
|
|
36
35
|
/**
|
|
37
36
|
* Get the field name which is expected to be saved in the database based on the user's schema.
|
|
38
37
|
*/
|
|
39
|
-
getFieldName: ({
|
|
38
|
+
getFieldName: ({
|
|
39
|
+
model,
|
|
40
|
+
field
|
|
41
|
+
}: {
|
|
40
42
|
model: string;
|
|
41
43
|
field: string;
|
|
42
44
|
}) => string;
|
|
@@ -64,7 +66,10 @@ type AdapterFactoryCustomizeAdapterCreator = (config: {
|
|
|
64
66
|
* 2. When using a custom fieldName, doing something like `schema[model].fields[field]` will not work.
|
|
65
67
|
*
|
|
66
68
|
*/
|
|
67
|
-
getDefaultFieldName: ({
|
|
69
|
+
getDefaultFieldName: ({
|
|
70
|
+
model,
|
|
71
|
+
field
|
|
72
|
+
}: {
|
|
68
73
|
model: string;
|
|
69
74
|
field: string;
|
|
70
75
|
}) => string;
|
|
@@ -73,13 +78,20 @@ type AdapterFactoryCustomizeAdapterCreator = (config: {
|
|
|
73
78
|
*
|
|
74
79
|
* Note: any model name or field name is allowed, whether default to schema or not.
|
|
75
80
|
*/
|
|
76
|
-
getFieldAttributes: ({
|
|
81
|
+
getFieldAttributes: ({
|
|
82
|
+
model,
|
|
83
|
+
field
|
|
84
|
+
}: {
|
|
77
85
|
model: string;
|
|
78
86
|
field: string;
|
|
79
87
|
}) => DBFieldAttribute;
|
|
80
88
|
transformInput: (data: Record<string, unknown>, defaultModelName: string, action: "create" | "update", forceAllowId?: boolean | undefined) => Promise<Record<string, unknown>>;
|
|
81
89
|
transformOutput: (data: Record<string, unknown>, defaultModelName: string, select?: string[] | undefined, joinConfig?: JoinConfig | undefined) => Promise<Record<string, unknown>>;
|
|
82
|
-
transformWhereClause: <W extends Where[] | undefined>({
|
|
90
|
+
transformWhereClause: <W extends Where[] | undefined>({
|
|
91
|
+
model,
|
|
92
|
+
where,
|
|
93
|
+
action
|
|
94
|
+
}: {
|
|
83
95
|
where: W;
|
|
84
96
|
model: string;
|
|
85
97
|
action: "create" | "update" | "findOne" | "findMany" | "updateMany" | "delete" | "deleteMany" | "consumeOne" | "incrementOne" | "count";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DBFieldAttribute } from "../type.mjs";
|
|
2
|
+
|
|
2
3
|
//#region src/db/adapter/utils.d.ts
|
|
3
4
|
declare function withApplyDefault(value: any, field: DBFieldAttribute, action: "create" | "update" | "findOne" | "findMany"): any;
|
|
4
5
|
declare function deepmerge<T>(target: T, source: Partial<T>): T;
|
package/dist/db/get-tables.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BetterAuthDBSchema } from "./type.mjs";
|
|
2
2
|
import { BetterAuthOptions } from "../types/init-options.mjs";
|
|
3
|
-
import "../types/index.mjs";
|
|
4
3
|
//#region src/db/get-tables.d.ts
|
|
5
4
|
declare const getAuthTables: (options: BetterAuthOptions) => BetterAuthDBSchema;
|
|
6
5
|
//#endregion
|
package/dist/db/plugin.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DBFieldAttribute } from "./type.mjs";
|
|
2
|
+
|
|
2
3
|
//#region src/db/plugin.d.ts
|
|
3
4
|
type BetterAuthPluginDBSchema = { [table in string]: {
|
|
4
5
|
fields: {
|
|
@@ -6,6 +7,6 @@ type BetterAuthPluginDBSchema = { [table in string]: {
|
|
|
6
7
|
};
|
|
7
8
|
disableMigration?: boolean | undefined;
|
|
8
9
|
modelName?: string | undefined;
|
|
9
|
-
}
|
|
10
|
+
} };
|
|
10
11
|
//#endregion
|
|
11
12
|
export { BetterAuthPluginDBSchema };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { InferDBFieldsFromOptions, InferDBFieldsFromPlugins } from "../type.mjs";
|
|
2
2
|
import { Prettify } from "../../types/helper.mjs";
|
|
3
3
|
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
4
|
-
import "../../types/index.mjs";
|
|
5
4
|
import * as z from "zod";
|
|
5
|
+
|
|
6
6
|
//#region src/db/schema/account.d.ts
|
|
7
7
|
declare const accountSchema: z.ZodObject<{
|
|
8
8
|
id: z.ZodString;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { InferDBFieldsFromOptions, InferDBFieldsFromPlugins } from "../type.mjs";
|
|
2
2
|
import { Prettify } from "../../types/helper.mjs";
|
|
3
3
|
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
4
|
-
import "../../types/index.mjs";
|
|
5
4
|
import * as z from "zod";
|
|
5
|
+
|
|
6
6
|
//#region src/db/schema/rate-limit.d.ts
|
|
7
7
|
declare const rateLimitSchema: z.ZodObject<{
|
|
8
8
|
key: z.ZodString;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { InferDBFieldsFromOptions, InferDBFieldsFromPlugins } from "../type.mjs";
|
|
2
2
|
import { Prettify } from "../../types/helper.mjs";
|
|
3
3
|
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
4
|
-
import "../../types/index.mjs";
|
|
5
4
|
import * as z from "zod";
|
|
5
|
+
|
|
6
6
|
//#region src/db/schema/session.d.ts
|
|
7
7
|
declare const sessionSchema: z.ZodObject<{
|
|
8
8
|
id: z.ZodString;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { InferDBFieldsFromOptions, InferDBFieldsFromPlugins } from "../type.mjs";
|
|
2
2
|
import { Prettify } from "../../types/helper.mjs";
|
|
3
3
|
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
4
|
-
import "../../types/index.mjs";
|
|
5
4
|
import * as z from "zod";
|
|
5
|
+
|
|
6
6
|
//#region src/db/schema/user.d.ts
|
|
7
7
|
declare const userSchema: z.ZodObject<{
|
|
8
8
|
id: z.ZodString;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { InferDBFieldsFromOptions, InferDBFieldsFromPlugins } from "../type.mjs";
|
|
2
2
|
import { Prettify } from "../../types/helper.mjs";
|
|
3
3
|
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
4
|
-
import "../../types/index.mjs";
|
|
5
4
|
import * as z from "zod";
|
|
5
|
+
|
|
6
6
|
//#region src/db/schema/verification.d.ts
|
|
7
7
|
declare const verificationSchema: z.ZodObject<{
|
|
8
8
|
id: z.ZodString;
|
package/dist/db/type.d.mts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Awaitable, LiteralString, UnionToIntersection } from "../types/helper.mjs";
|
|
2
2
|
import { BetterAuthOptions } from "../types/init-options.mjs";
|
|
3
|
-
import "../types/index.mjs";
|
|
4
3
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
4
|
+
|
|
5
5
|
//#region src/db/type.d.ts
|
|
6
6
|
type BaseModelNames = "user" | "account" | "session" | "verification";
|
|
7
7
|
type ModelNames<T extends string = LiteralString> = BaseModelNames | T | "rate-limit";
|
|
8
8
|
type InferDBValueType<T extends DBFieldType> = T extends "string" ? string : T extends "number" ? number : T extends "boolean" ? boolean : T extends "date" ? Date : T extends "json" ? Record<string, any> : T extends `${infer U}[]` ? U extends "string" ? string[] : number[] : T extends Array<any> ? T[number] : never;
|
|
9
9
|
type InferDBFieldOutput<T extends DBFieldAttribute> = T["returned"] extends false ? never : T["required"] extends false ? InferDBValueType<T["type"]> | undefined | null : InferDBValueType<T["type"]>;
|
|
10
10
|
type InferDBFieldInput<T extends DBFieldAttribute> = InferDBValueType<T["type"]>;
|
|
11
|
-
type InferDBFieldsInput<Field> = Field extends Record<infer Key, DBFieldAttribute> ? { [key in Key as Field[key]["required"] extends false ? never : Field[key]["defaultValue"] extends string | number | boolean | Date ? never : Field[key]["input"] extends false ? never : key]: InferDBFieldInput<Field[key]
|
|
12
|
-
type InferDBFieldsOutput<Fields extends Record<string, DBFieldAttribute>> = Fields extends Record<infer Key, DBFieldAttribute> ? { [key in Key as Fields[key]["returned"] extends false ? never : Fields[key]["required"] extends false ? Fields[key]["defaultValue"] extends boolean | string | number | Date ? key : never : key]: InferDBFieldOutput<Fields[key]
|
|
11
|
+
type InferDBFieldsInput<Field> = Field extends Record<infer Key, DBFieldAttribute> ? { [key in Key as Field[key]["required"] extends false ? never : Field[key]["defaultValue"] extends string | number | boolean | Date ? never : Field[key]["input"] extends false ? never : key]: InferDBFieldInput<Field[key]> } & { [key in Key as Field[key]["input"] extends false ? never : key]?: InferDBFieldInput<Field[key]> | undefined | null } : {};
|
|
12
|
+
type InferDBFieldsOutput<Fields extends Record<string, DBFieldAttribute>> = Fields extends Record<infer Key, DBFieldAttribute> ? { [key in Key as Fields[key]["returned"] extends false ? never : Fields[key]["required"] extends false ? Fields[key]["defaultValue"] extends boolean | string | number | Date ? key : never : key]: InferDBFieldOutput<Fields[key]> } & { [key in Key as Fields[key]["returned"] extends false ? never : Fields[key]["required"] extends false ? Fields[key]["defaultValue"] extends boolean | string | number | Date ? never : key : never]?: InferDBFieldOutput<Fields[key]> | null } : never;
|
|
13
13
|
type InferDBFieldsFromOptionsInput<DBOptions extends BetterAuthOptions["session"] | BetterAuthOptions["user"] | BetterAuthOptions["verification"] | BetterAuthOptions["account"] | BetterAuthOptions["rateLimit"]> = DBOptions extends {
|
|
14
14
|
additionalFields: Record<string, DBFieldAttribute>;
|
|
15
15
|
} ? InferDBFieldsInput<DBOptions["additionalFields"]> : {};
|
|
@@ -19,12 +19,12 @@ type InferDBFieldsFromOptions<DBOptions extends BetterAuthOptions["session"] | B
|
|
|
19
19
|
type InferDBFieldsFromPluginsInput<ModelName extends string, Plugins extends unknown[] | undefined> = Plugins extends [] ? {} : Plugins extends [infer P, ...infer Rest] ? P extends {
|
|
20
20
|
schema: { [key in ModelName]: {
|
|
21
21
|
fields: infer Fields;
|
|
22
|
-
}
|
|
22
|
+
} };
|
|
23
23
|
} ? Fields extends Record<string, DBFieldAttribute> ? UnionToIntersection<InferDBFieldsInput<Fields> & InferDBFieldsFromPluginsInput<ModelName, Rest>> : InferDBFieldsFromPluginsInput<ModelName, Rest> : InferDBFieldsFromPluginsInput<ModelName, Rest> : {};
|
|
24
24
|
type InferDBFieldsFromPlugins<ModelName extends string, Plugins extends unknown[] | undefined> = Plugins extends [] ? {} : Plugins extends [infer P, ...infer Rest] ? P extends {
|
|
25
25
|
schema: { [key in ModelName]: {
|
|
26
26
|
fields: infer Fields;
|
|
27
|
-
}
|
|
27
|
+
} };
|
|
28
28
|
} ? Fields extends Record<string, DBFieldAttribute> ? UnionToIntersection<InferDBFieldsOutput<Fields> & InferDBFieldsFromPlugins<ModelName, Rest>> : InferDBFieldsFromPlugins<ModelName, Rest> : InferDBFieldsFromPlugins<ModelName, Rest> : {};
|
|
29
29
|
type DBFieldType = "string" | "number" | "boolean" | "date" | "json" | `${"string" | "number"}[]` | Array<LiteralString>;
|
|
30
30
|
type DBPrimitive = string | number | boolean | Date | null | undefined | string[] | number[] | (Record<string, unknown> | unknown[]);
|
|
@@ -89,7 +89,8 @@ type DBFieldAttributeConfig = {
|
|
|
89
89
|
*/
|
|
90
90
|
bigint?: boolean | undefined;
|
|
91
91
|
/**
|
|
92
|
-
* A
|
|
92
|
+
* A Standard Schema to validate the value. Works with any Standard Schema
|
|
93
|
+
* library, such as Zod, Valibot or ArkType.
|
|
93
94
|
*/
|
|
94
95
|
validator?: {
|
|
95
96
|
input?: StandardSchemaV1;
|
|
@@ -172,14 +173,17 @@ interface SecondaryStorage {
|
|
|
172
173
|
/**
|
|
173
174
|
* Key to store
|
|
174
175
|
*/
|
|
176
|
+
|
|
175
177
|
key: string,
|
|
176
178
|
/**
|
|
177
179
|
* Value to store
|
|
178
180
|
*/
|
|
181
|
+
|
|
179
182
|
value: string,
|
|
180
183
|
/**
|
|
181
184
|
* Time to live in seconds
|
|
182
185
|
*/
|
|
186
|
+
|
|
183
187
|
ttl?: number | undefined) => Awaitable<void | null | unknown>;
|
|
184
188
|
/**
|
|
185
189
|
*
|