@better-auth/core 1.7.0-rc.4 → 1.7.0-rc.6
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 +39 -60
- package/dist/api/index.mjs +39 -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 +2 -3
- package/dist/db/adapter/factory.d.mts +5 -3
- package/dist/db/adapter/factory.mjs +1 -1
- 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/database-index.d.mts +12 -2
- package/dist/db/get-tables.d.mts +0 -1
- package/dist/db/plugin.d.mts +3 -3
- 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 +11 -8
- 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/authorization-params.d.mts +1 -0
- package/dist/oauth2/client-assertion.d.mts +13 -3
- package/dist/oauth2/client-credentials-token.d.mts +17 -3
- package/dist/oauth2/create-authorization-url.d.mts +21 -3
- package/dist/oauth2/dpop.d.mts +23 -2
- package/dist/oauth2/dpop.mjs +1 -1
- package/dist/oauth2/oauth-provider.d.mts +7 -13
- package/dist/oauth2/refresh-access-token.d.mts +19 -3
- package/dist/oauth2/refresh-access-token.mjs +1 -1
- package/dist/oauth2/reject-redirects.mjs +1 -1
- package/dist/oauth2/token-endpoint-auth.d.mts +1 -0
- package/dist/oauth2/utils.d.mts +1 -0
- package/dist/oauth2/utils.mjs +1 -1
- package/dist/oauth2/validate-authorization-code.d.mts +29 -5
- package/dist/oauth2/verify-id-token.d.mts +1 -1
- package/dist/oauth2/verify.d.mts +7 -5
- package/dist/oauth2/verify.mjs +2 -2
- package/dist/social-providers/apple.d.mts +18 -5
- package/dist/social-providers/atlassian.d.mts +15 -4
- package/dist/social-providers/cognito.d.mts +18 -5
- package/dist/social-providers/discord.d.mts +13 -4
- package/dist/social-providers/dropbox.d.mts +15 -4
- package/dist/social-providers/facebook.d.mts +18 -6
- package/dist/social-providers/figma.d.mts +15 -4
- package/dist/social-providers/github.d.mts +16 -4
- package/dist/social-providers/gitlab.d.mts +16 -4
- package/dist/social-providers/google.d.mts +25 -6
- package/dist/social-providers/huggingface.d.mts +15 -4
- package/dist/social-providers/index.d.mts +504 -113
- package/dist/social-providers/kakao.d.mts +13 -4
- package/dist/social-providers/kick.d.mts +15 -4
- package/dist/social-providers/line.d.mts +16 -4
- package/dist/social-providers/linear.d.mts +14 -4
- package/dist/social-providers/linkedin.d.mts +14 -4
- package/dist/social-providers/microsoft-entra-id.d.mts +14 -5
- package/dist/social-providers/microsoft-entra-id.mjs +1 -2
- package/dist/social-providers/naver.d.mts +22 -23
- package/dist/social-providers/notion.d.mts +14 -4
- package/dist/social-providers/paybin.d.mts +16 -4
- package/dist/social-providers/paypal.d.mts +13 -4
- package/dist/social-providers/polar.d.mts +15 -4
- package/dist/social-providers/railway.d.mts +15 -4
- package/dist/social-providers/reddit.d.mts +13 -4
- package/dist/social-providers/roblox.d.mts +13 -4
- package/dist/social-providers/salesforce.d.mts +15 -4
- package/dist/social-providers/slack.d.mts +13 -4
- package/dist/social-providers/spotify.d.mts +15 -4
- package/dist/social-providers/tiktok.d.mts +14 -6
- package/dist/social-providers/twitch.d.mts +13 -4
- package/dist/social-providers/twitter.d.mts +19 -26
- package/dist/social-providers/vercel.d.mts +15 -4
- package/dist/social-providers/vk.d.mts +16 -4
- package/dist/social-providers/wechat.d.mts +12 -4
- package/dist/social-providers/zoom.d.mts +18 -6
- package/dist/types/context.d.mts +2 -2
- package/dist/types/cookie.d.mts +1 -1
- package/dist/types/helper.d.mts +1 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/types/init-options.d.mts +18 -26
- 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 +4 -4
- package/src/api/index.ts +96 -95
- package/src/db/type.ts +2 -1
- package/src/types/init-options.ts +6 -4
package/dist/api/index.d.mts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
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 "
|
|
9
|
-
import {
|
|
6
|
+
import * as _$better_call0 from "better-call";
|
|
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
11
|
/**
|
|
12
12
|
* Response headers that forbid any intermediary (proxy, CDN, browser) from
|
|
@@ -26,13 +26,10 @@ declare const NO_STORE_HEADERS: {
|
|
|
26
26
|
readonly "Cache-Control": "no-store";
|
|
27
27
|
readonly Pragma: "no-cache";
|
|
28
28
|
};
|
|
29
|
-
declare const optionsMiddleware: <InputCtx extends
|
|
29
|
+
declare const optionsMiddleware: _$better_call0.Middleware<_$better_call0.MiddlewareOptions, <InputCtx extends _$better_call0.MiddlewareInputContext<_$better_call0.MiddlewareOptions>>(inputContext: InputCtx) => Promise<AuthContext>>;
|
|
30
30
|
declare const createAuthMiddleware: {
|
|
31
|
-
<Options extends
|
|
32
|
-
|
|
33
|
-
responseHeaders?: Headers | undefined;
|
|
34
|
-
} & import("@better-auth/core").PluginContext<import("@better-auth/core").BetterAuthOptions> & import("@better-auth/core").InfoContext & {
|
|
35
|
-
options: import("@better-auth/core").BetterAuthOptions;
|
|
31
|
+
<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 & {
|
|
32
|
+
options: _$_better_auth_core0.BetterAuthOptions;
|
|
36
33
|
trustedOrigins: string[];
|
|
37
34
|
trustedProviders: string[];
|
|
38
35
|
isTrustedOrigin: (url: string, settings?: {
|
|
@@ -106,24 +103,24 @@ declare const createAuthMiddleware: {
|
|
|
106
103
|
} & Record<string, any>;
|
|
107
104
|
} | null) => void;
|
|
108
105
|
socialProviders: OAuthProvider[];
|
|
109
|
-
authCookies:
|
|
106
|
+
authCookies: _$_better_auth_core0.BetterAuthCookies;
|
|
110
107
|
logger: ReturnType<typeof createLogger>;
|
|
111
108
|
rateLimit: {
|
|
112
109
|
enabled: boolean;
|
|
113
110
|
window: number;
|
|
114
111
|
max: number;
|
|
115
112
|
storage: "memory" | "database" | "secondary-storage";
|
|
116
|
-
} & Omit<
|
|
117
|
-
adapter: DBAdapter<
|
|
118
|
-
internalAdapter:
|
|
119
|
-
createAuthCookie: (cookieName: string, overrideAttributes?: Partial<
|
|
113
|
+
} & Omit<_$_better_auth_core0.BetterAuthRateLimitOptions, "enabled" | "window" | "max" | "storage">;
|
|
114
|
+
adapter: DBAdapter<_$_better_auth_core0.BetterAuthOptions>;
|
|
115
|
+
internalAdapter: _$_better_auth_core0.InternalAdapter<_$_better_auth_core0.BetterAuthOptions>;
|
|
116
|
+
createAuthCookie: (cookieName: string, overrideAttributes?: Partial<_$better_call0.CookieOptions> | undefined) => _$_better_auth_core0.BetterAuthCookie;
|
|
120
117
|
secret: string;
|
|
121
|
-
secretConfig: string |
|
|
118
|
+
secretConfig: string | _$_better_auth_core0.SecretConfig;
|
|
122
119
|
sessionConfig: {
|
|
123
120
|
updateAge: number;
|
|
124
121
|
expiresIn: number;
|
|
125
122
|
freshAge: number;
|
|
126
|
-
cookieCacheSigner?:
|
|
123
|
+
cookieCacheSigner?: _$_better_auth_core0.CookieCacheSigner | undefined;
|
|
127
124
|
cookieRefreshCache: false | {
|
|
128
125
|
enabled: true;
|
|
129
126
|
updateAge: number;
|
|
@@ -144,7 +141,7 @@ declare const createAuthMiddleware: {
|
|
|
144
141
|
minPasswordLength: number;
|
|
145
142
|
maxPasswordLength: number;
|
|
146
143
|
};
|
|
147
|
-
checkPassword: (userId: string, ctx:
|
|
144
|
+
checkPassword: (userId: string, ctx: _$_better_auth_core0.GenericEndpointContext<_$_better_auth_core0.BetterAuthOptions>) => Promise<boolean>;
|
|
148
145
|
};
|
|
149
146
|
tables: BetterAuthDBSchema;
|
|
150
147
|
runMigrations: () => Promise<void>;
|
|
@@ -156,13 +153,13 @@ declare const createAuthMiddleware: {
|
|
|
156
153
|
skipOriginCheck: boolean | string[];
|
|
157
154
|
skipCSRFCheck: boolean;
|
|
158
155
|
runInBackground: (promise: Promise<unknown>) => void;
|
|
159
|
-
runInBackgroundOrAwait: (promise: Promise<unknown> | void) =>
|
|
160
|
-
}
|
|
161
|
-
<Options extends import("better-call").MiddlewareOptions, R_1>(handler: (ctx: import("better-call").MiddlewareContext<Options, {
|
|
156
|
+
runInBackgroundOrAwait: (promise: Promise<unknown> | void) => _$_better_auth_core0.Awaitable<unknown>;
|
|
157
|
+
} & {
|
|
162
158
|
returned?: unknown | undefined;
|
|
163
159
|
responseHeaders?: Headers | undefined;
|
|
164
|
-
}
|
|
165
|
-
|
|
160
|
+
}>) => Promise<R>): _$better_call0.Middleware<Options, (inputContext: _$better_call0.MiddlewareInputContext<Options>) => Promise<R>>;
|
|
161
|
+
<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 & {
|
|
162
|
+
options: _$_better_auth_core0.BetterAuthOptions;
|
|
166
163
|
trustedOrigins: string[];
|
|
167
164
|
trustedProviders: string[];
|
|
168
165
|
isTrustedOrigin: (url: string, settings?: {
|
|
@@ -236,24 +233,24 @@ declare const createAuthMiddleware: {
|
|
|
236
233
|
} & Record<string, any>;
|
|
237
234
|
} | null) => void;
|
|
238
235
|
socialProviders: OAuthProvider[];
|
|
239
|
-
authCookies:
|
|
236
|
+
authCookies: _$_better_auth_core0.BetterAuthCookies;
|
|
240
237
|
logger: ReturnType<typeof createLogger>;
|
|
241
238
|
rateLimit: {
|
|
242
239
|
enabled: boolean;
|
|
243
240
|
window: number;
|
|
244
241
|
max: number;
|
|
245
242
|
storage: "memory" | "database" | "secondary-storage";
|
|
246
|
-
} & Omit<
|
|
247
|
-
adapter: DBAdapter<
|
|
248
|
-
internalAdapter:
|
|
249
|
-
createAuthCookie: (cookieName: string, overrideAttributes?: Partial<
|
|
243
|
+
} & Omit<_$_better_auth_core0.BetterAuthRateLimitOptions, "enabled" | "window" | "max" | "storage">;
|
|
244
|
+
adapter: DBAdapter<_$_better_auth_core0.BetterAuthOptions>;
|
|
245
|
+
internalAdapter: _$_better_auth_core0.InternalAdapter<_$_better_auth_core0.BetterAuthOptions>;
|
|
246
|
+
createAuthCookie: (cookieName: string, overrideAttributes?: Partial<_$better_call0.CookieOptions> | undefined) => _$_better_auth_core0.BetterAuthCookie;
|
|
250
247
|
secret: string;
|
|
251
|
-
secretConfig: string |
|
|
248
|
+
secretConfig: string | _$_better_auth_core0.SecretConfig;
|
|
252
249
|
sessionConfig: {
|
|
253
250
|
updateAge: number;
|
|
254
251
|
expiresIn: number;
|
|
255
252
|
freshAge: number;
|
|
256
|
-
cookieCacheSigner?:
|
|
253
|
+
cookieCacheSigner?: _$_better_auth_core0.CookieCacheSigner | undefined;
|
|
257
254
|
cookieRefreshCache: false | {
|
|
258
255
|
enabled: true;
|
|
259
256
|
updateAge: number;
|
|
@@ -274,7 +271,7 @@ declare const createAuthMiddleware: {
|
|
|
274
271
|
minPasswordLength: number;
|
|
275
272
|
maxPasswordLength: number;
|
|
276
273
|
};
|
|
277
|
-
checkPassword: (userId: string, ctx:
|
|
274
|
+
checkPassword: (userId: string, ctx: _$_better_auth_core0.GenericEndpointContext<_$_better_auth_core0.BetterAuthOptions>) => Promise<boolean>;
|
|
278
275
|
};
|
|
279
276
|
tables: BetterAuthDBSchema;
|
|
280
277
|
runMigrations: () => Promise<void>;
|
|
@@ -286,38 +283,20 @@ declare const createAuthMiddleware: {
|
|
|
286
283
|
skipOriginCheck: boolean | string[];
|
|
287
284
|
skipCSRFCheck: boolean;
|
|
288
285
|
runInBackground: (promise: Promise<unknown>) => void;
|
|
289
|
-
runInBackgroundOrAwait: (promise: Promise<unknown> | void) =>
|
|
290
|
-
}
|
|
286
|
+
runInBackgroundOrAwait: (promise: Promise<unknown> | void) => _$_better_auth_core0.Awaitable<unknown>;
|
|
287
|
+
} & {
|
|
288
|
+
returned?: unknown | undefined;
|
|
289
|
+
responseHeaders?: Headers | undefined;
|
|
290
|
+
}>) => Promise<R_1>): _$better_call0.Middleware<Options, (inputContext: _$better_call0.MiddlewareInputContext<Options>) => Promise<R_1>>;
|
|
291
291
|
};
|
|
292
|
-
type
|
|
293
|
-
|
|
294
|
-
declare function createAuthEndpoint<Path extends string, Options extends EndpointOptions, R>(options: Options, handler:
|
|
292
|
+
type AuthEndpointHandler<Path extends string, Options extends EndpointOptions, R> = EndpointHandler<Path, Options, R, AuthContext>;
|
|
293
|
+
type PathlessAuthEndpointHandler<Options extends EndpointOptions, R> = AuthEndpointHandler<string, Options, R>;
|
|
294
|
+
declare function createAuthEndpoint<Path extends string, Options extends EndpointOptions, R>(path: Path, options: Options, handler: AuthEndpointHandler<Path, Options, R>): StrictEndpoint<Path, Options, R>;
|
|
295
|
+
declare function createAuthEndpoint<InferredPath extends string, Options extends EndpointOptions, R>(options: Options, handler: PathlessAuthEndpointHandler<Options, R>): StrictEndpoint<InferredPath, Options, R>;
|
|
295
296
|
declare namespace createAuthEndpoint {
|
|
296
|
-
|
|
297
|
-
* Declare a **server-only** endpoint.
|
|
298
|
-
*
|
|
299
|
-
* The endpoint is callable through `auth.api.*` from trusted server code but is
|
|
300
|
-
* never registered on the HTTP router and never emitted into the OpenAPI
|
|
301
|
-
* schema. It takes no path because it has no URL to be reached at.
|
|
302
|
-
*
|
|
303
|
-
* Prefer this over the path-less `createAuthEndpoint({ ... }, handler)` form.
|
|
304
|
-
* Setting `metadata.SERVER_ONLY` makes the intent explicit at the call site and
|
|
305
|
-
* keeps the endpoint off the HTTP surface even if a path is later added by
|
|
306
|
-
* mistake: better-call's router skips an endpoint when its path is missing *or*
|
|
307
|
-
* when `SERVER_ONLY` is set, so the two together are defense in depth. Relying
|
|
308
|
-
* on path omission alone is invisible and one keystroke away from exposure.
|
|
309
|
-
*
|
|
310
|
-
* @example
|
|
311
|
-
* ```ts
|
|
312
|
-
* viewBackupCodes: createAuthEndpoint.serverOnly(
|
|
313
|
-
* { method: "POST", body: schema },
|
|
314
|
-
* async (ctx) => { ... },
|
|
315
|
-
* )
|
|
316
|
-
* ```
|
|
317
|
-
*/
|
|
318
|
-
function serverOnly<Path extends string, Options extends EndpointOptions, R>(options: Options, handler: EndpointHandler<Path, Options, R>): StrictEndpoint<Path, Options, R>;
|
|
297
|
+
var serverOnly: <InferredPath extends string, Options extends EndpointOptions, R>(options: Options, handler: PathlessAuthEndpointHandler<Options, R>) => StrictEndpoint<InferredPath, Options, R>;
|
|
319
298
|
}
|
|
320
299
|
type AuthEndpoint<Path extends string, Opts extends EndpointOptions, R> = ReturnType<typeof createAuthEndpoint<Path, Opts, R>>;
|
|
321
|
-
type AuthMiddleware =
|
|
300
|
+
type AuthMiddleware = MiddlewareHandler;
|
|
322
301
|
//#endregion
|
|
323
302
|
export { AuthEndpoint, AuthMiddleware, NO_STORE_HEADERS, createAuthEndpoint, createAuthMiddleware, optionsMiddleware };
|
package/dist/api/index.mjs
CHANGED
|
@@ -47,30 +47,26 @@ const optionsMiddleware = createMiddleware(async () => {
|
|
|
47
47
|
const createAuthMiddleware = createMiddleware.create({ use: [optionsMiddleware, createMiddleware(async () => {
|
|
48
48
|
return {};
|
|
49
49
|
})] });
|
|
50
|
-
const
|
|
51
|
-
function
|
|
52
|
-
const path = typeof pathOrOptions === "string" ? pathOrOptions : void 0;
|
|
53
|
-
const options = typeof handlerOrOptions === "object" ? handlerOrOptions : pathOrOptions;
|
|
54
|
-
const handler = typeof handlerOrOptions === "function" ? handlerOrOptions : handlerOrNever;
|
|
50
|
+
const createEndpointWithAuthContext = createEndpoint.create({ use: [optionsMiddleware] });
|
|
51
|
+
function wrapEndpointHandler(handler, options) {
|
|
55
52
|
const noStore = options.metadata?.noStore === true;
|
|
56
|
-
|
|
57
|
-
if (noStore) for (const [name, value] of Object.entries(NO_STORE_HEADERS))
|
|
58
|
-
const runtimeCtx = ctx;
|
|
53
|
+
return async (context) => {
|
|
54
|
+
if (noStore) for (const [name, value] of Object.entries(NO_STORE_HEADERS)) context.setHeader(name, value);
|
|
59
55
|
try {
|
|
60
|
-
return await runWithEndpointContext(
|
|
61
|
-
} catch (
|
|
62
|
-
attachResponseHeadersToAPIError(
|
|
63
|
-
throw
|
|
56
|
+
return await runWithEndpointContext(context, () => handler(context));
|
|
57
|
+
} catch (error) {
|
|
58
|
+
attachResponseHeadersToAPIError(context.responseHeaders, error);
|
|
59
|
+
throw error;
|
|
64
60
|
}
|
|
65
61
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
62
|
+
}
|
|
63
|
+
function createAuthEndpoint(...args) {
|
|
64
|
+
if (args.length === 3) {
|
|
65
|
+
const [path, options, handler] = args;
|
|
66
|
+
return createEndpointWithAuthContext(path, options, wrapEndpointHandler(handler, options));
|
|
67
|
+
}
|
|
68
|
+
const [options, handler] = args;
|
|
69
|
+
return createEndpointWithAuthContext(options, wrapEndpointHandler(handler, options));
|
|
74
70
|
}
|
|
75
71
|
/**
|
|
76
72
|
* Set `metadata.SERVER_ONLY` while preserving any existing metadata
|
|
@@ -85,11 +81,28 @@ function withServerOnly(options) {
|
|
|
85
81
|
}
|
|
86
82
|
};
|
|
87
83
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Declare a **server-only** endpoint.
|
|
86
|
+
*
|
|
87
|
+
* The endpoint is callable through `auth.api.*` from trusted server code but is
|
|
88
|
+
* never registered on the HTTP router and never emitted into the OpenAPI
|
|
89
|
+
* schema. It takes no path because it has no URL to be reached at.
|
|
90
|
+
*
|
|
91
|
+
* Prefer this over the path-less `createAuthEndpoint({ ... }, handler)` form.
|
|
92
|
+
* Setting `metadata.SERVER_ONLY` makes the intent explicit at the call site and
|
|
93
|
+
* keeps the endpoint off the HTTP surface even if a path is later added by
|
|
94
|
+
* mistake: better-call's router skips an endpoint when its path is missing *or*
|
|
95
|
+
* when `SERVER_ONLY` is set, so the two together are defense in depth. Relying
|
|
96
|
+
* on path omission alone is invisible and one keystroke away from exposure.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* viewBackupCodes: createAuthEndpoint.serverOnly(
|
|
101
|
+
* { method: "POST", body: schema },
|
|
102
|
+
* async (ctx) => { ... },
|
|
103
|
+
* )
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
createAuthEndpoint.serverOnly = (options, handler) => createAuthEndpoint(withServerOnly(options), handler);
|
|
94
107
|
//#endregion
|
|
95
108
|
export { NO_STORE_HEADERS, createAuthEndpoint, createAuthMiddleware, optionsMiddleware };
|
|
@@ -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 = {
|
|
@@ -25,8 +25,7 @@ declare const runWithTransaction: <R, Options extends BetterAuthOptions = Better
|
|
|
25
25
|
* If not in a transaction, the hook will execute immediately.
|
|
26
26
|
*/
|
|
27
27
|
declare const queueAfterTransactionHook: (hook: () => Promise<void>, options?: {
|
|
28
|
-
/** Handles a queued hook failure after the surrounding work has committed. */
|
|
29
|
-
onError?: (error: unknown) => void | Promise<void>;
|
|
28
|
+
/** Handles a queued hook failure after the surrounding work has committed. */onError?: (error: unknown) => void | Promise<void>;
|
|
30
29
|
}) => Promise<void>;
|
|
31
30
|
//#endregion
|
|
32
31
|
export { getCurrentAdapter, getCurrentDBAdapterAsyncLocalStorage, queueAfterTransactionHook, runWithAdapter, runWithTransaction };
|
|
@@ -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 };
|
|
@@ -841,4 +841,4 @@ function formatAction(action) {
|
|
|
841
841
|
return `${TTY_COLORS.dim}(${action})${TTY_COLORS.reset}`;
|
|
842
842
|
}
|
|
843
843
|
//#endregion
|
|
844
|
-
export { createAdapterFactory
|
|
844
|
+
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
|
/**
|
|
@@ -489,7 +488,11 @@ type DBAdapter<Options extends BetterAuthOptions = BetterAuthOptions> = {
|
|
|
489
488
|
};
|
|
490
489
|
type CleanedWhere = Required<Where>;
|
|
491
490
|
interface CustomAdapter {
|
|
492
|
-
create: <T extends Record<string, any>>({
|
|
491
|
+
create: <T extends Record<string, any>>({
|
|
492
|
+
data,
|
|
493
|
+
model,
|
|
494
|
+
select
|
|
495
|
+
}: {
|
|
493
496
|
model: string;
|
|
494
497
|
data: T;
|
|
495
498
|
select?: string[] | undefined;
|
|
@@ -504,13 +507,26 @@ interface CustomAdapter {
|
|
|
504
507
|
where: CleanedWhere[];
|
|
505
508
|
update: Record<string, any>;
|
|
506
509
|
}) => Promise<number>;
|
|
507
|
-
findOne: <T>({
|
|
510
|
+
findOne: <T>({
|
|
511
|
+
model,
|
|
512
|
+
where,
|
|
513
|
+
select,
|
|
514
|
+
join
|
|
515
|
+
}: {
|
|
508
516
|
model: string;
|
|
509
517
|
where: CleanedWhere[];
|
|
510
518
|
select?: string[] | undefined;
|
|
511
519
|
join?: JoinConfig | undefined;
|
|
512
520
|
}) => Promise<T | null>;
|
|
513
|
-
findMany: <T>({
|
|
521
|
+
findMany: <T>({
|
|
522
|
+
model,
|
|
523
|
+
where,
|
|
524
|
+
limit,
|
|
525
|
+
select,
|
|
526
|
+
sortBy,
|
|
527
|
+
offset,
|
|
528
|
+
join
|
|
529
|
+
}: {
|
|
514
530
|
model: string;
|
|
515
531
|
where?: CleanedWhere[] | undefined;
|
|
516
532
|
limit: number;
|
|
@@ -522,11 +538,17 @@ interface CustomAdapter {
|
|
|
522
538
|
offset?: number | undefined;
|
|
523
539
|
join?: JoinConfig | undefined;
|
|
524
540
|
}) => Promise<T[]>;
|
|
525
|
-
delete: ({
|
|
541
|
+
delete: ({
|
|
542
|
+
model,
|
|
543
|
+
where
|
|
544
|
+
}: {
|
|
526
545
|
model: string;
|
|
527
546
|
where: CleanedWhere[];
|
|
528
547
|
}) => Promise<void>;
|
|
529
|
-
deleteMany: ({
|
|
548
|
+
deleteMany: ({
|
|
549
|
+
model,
|
|
550
|
+
where
|
|
551
|
+
}: {
|
|
530
552
|
model: string;
|
|
531
553
|
where: CleanedWhere[];
|
|
532
554
|
}) => Promise<number>;
|
|
@@ -558,7 +580,10 @@ interface CustomAdapter {
|
|
|
558
580
|
increment: Record<string, number>;
|
|
559
581
|
set?: Record<string, unknown> | undefined;
|
|
560
582
|
}) => Promise<T | null>;
|
|
561
|
-
count: ({
|
|
583
|
+
count: ({
|
|
584
|
+
model,
|
|
585
|
+
where
|
|
586
|
+
}: {
|
|
562
587
|
model: string;
|
|
563
588
|
where?: CleanedWhere[] | undefined;
|
|
564
589
|
}) => 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;
|