better-auth 1.6.22 → 1.6.24
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/adapters/index.d.mts +1 -6
- package/dist/api/dispatch.d.mts +0 -1
- package/dist/api/index.d.mts +476 -478
- package/dist/api/middlewares/authorization.d.mts +12 -8
- package/dist/api/middlewares/authorization.mjs +2 -1
- package/dist/api/middlewares/index.d.mts +2 -1
- package/dist/api/middlewares/origin-check.d.mts +3 -5
- package/dist/api/routes/account.d.mts +10 -13
- package/dist/api/routes/account.mjs +35 -7
- package/dist/api/routes/callback.d.mts +1 -3
- package/dist/api/routes/callback.mjs +4 -0
- package/dist/api/routes/email-verification.d.mts +4 -8
- package/dist/api/routes/email-verification.mjs +15 -2
- package/dist/api/routes/error.d.mts +1 -3
- package/dist/api/routes/index.d.mts +2 -1
- package/dist/api/routes/ok.d.mts +1 -3
- package/dist/api/routes/password.d.mts +7 -9
- package/dist/api/routes/password.mjs +14 -1
- package/dist/api/routes/session.d.mts +22 -24
- package/dist/api/routes/session.mjs +5 -1
- package/dist/api/routes/sign-in.d.mts +3 -5
- package/dist/api/routes/sign-in.mjs +84 -2
- package/dist/api/routes/sign-out.d.mts +1 -3
- package/dist/api/routes/sign-up.d.mts +3 -4
- package/dist/api/routes/sign-up.mjs +3 -2
- package/dist/api/routes/update-session.d.mts +3 -4
- package/dist/api/routes/update-user.d.mts +13 -14
- package/dist/api/routes/update-user.mjs +26 -1
- package/dist/auth/full.d.mts +1 -1
- package/dist/auth/minimal.d.mts +1 -1
- package/dist/client/config.d.mts +12 -14
- package/dist/client/config.mjs +2 -2
- package/dist/client/equality.d.mts +0 -1
- package/dist/client/index.d.mts +6 -5
- package/dist/client/lynx/index.d.mts +4 -5
- package/dist/client/lynx/lynx-store.d.mts +1 -2
- package/dist/client/parser.d.mts +7 -3
- package/dist/client/path-to-object.d.mts +3 -4
- package/dist/client/plugins/index.d.mts +2 -1
- package/dist/client/plugins/infer-plugin.d.mts +0 -1
- package/dist/client/query.d.mts +0 -1
- package/dist/client/query.mjs +38 -20
- package/dist/client/react/index.d.mts +4 -5
- package/dist/client/react/react-store.d.mts +1 -2
- package/dist/client/session-refresh.d.mts +0 -1
- package/dist/client/solid/index.d.mts +5 -6
- package/dist/client/svelte/index.d.mts +5 -6
- package/dist/client/types.d.mts +2 -2
- package/dist/client/vanilla.d.mts +2 -3
- package/dist/client/vue/index.d.mts +5 -6
- package/dist/context/create-context.mjs +3 -3
- package/dist/context/helpers.mjs +2 -2
- package/dist/cookies/cookie-utils.d.mts +1 -1
- package/dist/cookies/index.d.mts +6 -7
- package/dist/cookies/index.mjs +4 -0
- package/dist/cookies/session-store.d.mts +1 -0
- package/dist/cookies/session-store.mjs +6 -1
- package/dist/crypto/index.d.mts +2 -9
- package/dist/crypto/jwt.d.mts +0 -1
- package/dist/crypto/password.d.mts +1 -5
- package/dist/db/adapter-base.d.mts +0 -1
- package/dist/db/adapter-kysely.d.mts +0 -1
- package/dist/db/field-converter.d.mts +0 -1
- package/dist/db/field.d.mts +9 -10
- package/dist/db/get-migration.d.mts +0 -1
- package/dist/db/get-migration.mjs +8 -4
- package/dist/db/get-schema.d.mts +0 -1
- package/dist/db/internal-adapter.d.mts +0 -1
- package/dist/db/internal-adapter.mjs +61 -1
- package/dist/db/revoke-unproven-account-access.d.mts +0 -1
- package/dist/db/schema.d.mts +2 -2
- package/dist/db/to-zod.d.mts +3 -7
- package/dist/db/with-hooks.d.mts +0 -1
- package/dist/index.d.mts +4 -3
- package/dist/integrations/next-js.d.mts +4 -7
- package/dist/integrations/node.d.mts +2 -3
- package/dist/integrations/svelte-kit.d.mts +2 -9
- package/dist/integrations/tanstack-start-solid.d.mts +2 -5
- package/dist/integrations/tanstack-start.d.mts +2 -5
- package/dist/oauth2/link-account.d.mts +1 -1
- package/dist/oauth2/state.d.mts +0 -1
- package/dist/oauth2/utils.d.mts +0 -1
- package/dist/package.mjs +1 -1
- package/dist/plugins/access/access.d.mts +0 -1
- package/dist/plugins/access/types.d.mts +4 -5
- package/dist/plugins/additional-fields/client.d.mts +0 -1
- package/dist/plugins/admin/access/statement.d.mts +1 -0
- package/dist/plugins/admin/admin.d.mts +120 -125
- package/dist/plugins/admin/client.d.mts +30 -30
- package/dist/plugins/admin/client.mjs +1 -1
- package/dist/plugins/admin/error-codes.d.mts +23 -25
- package/dist/plugins/admin/index.d.mts +1 -1
- package/dist/plugins/admin/routes.mjs +9 -0
- package/dist/plugins/admin/schema.d.mts +1 -1
- package/dist/plugins/admin/types.d.mts +3 -2
- package/dist/plugins/anonymous/client.d.mts +9 -11
- package/dist/plugins/anonymous/client.mjs +1 -1
- package/dist/plugins/anonymous/error-codes.d.mts +8 -10
- package/dist/plugins/anonymous/index.d.mts +14 -18
- package/dist/plugins/anonymous/types.d.mts +1 -1
- package/dist/plugins/bearer/index.d.mts +4 -7
- package/dist/plugins/captcha/index.d.mts +5 -8
- package/dist/plugins/captcha/types.d.mts +0 -1
- package/dist/plugins/custom-session/client.d.mts +0 -1
- package/dist/plugins/custom-session/index.d.mts +7 -12
- package/dist/plugins/device-authorization/client.d.mts +0 -1
- package/dist/plugins/device-authorization/index.d.mts +19 -22
- package/dist/plugins/email-otp/client.d.mts +4 -6
- package/dist/plugins/email-otp/client.mjs +1 -1
- package/dist/plugins/email-otp/error-codes.d.mts +3 -5
- package/dist/plugins/email-otp/index.d.mts +67 -73
- package/dist/plugins/email-otp/routes.mjs +2 -0
- package/dist/plugins/email-otp/types.d.mts +0 -1
- package/dist/plugins/generic-oauth/client.d.mts +11 -11
- package/dist/plugins/generic-oauth/client.mjs +1 -1
- package/dist/plugins/generic-oauth/error-codes.d.mts +8 -10
- package/dist/plugins/generic-oauth/index.d.mts +41 -44
- package/dist/plugins/generic-oauth/index.mjs +2 -1
- package/dist/plugins/generic-oauth/providers/auth0.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/gumroad.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/hubspot.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/index.d.mts +3 -1
- package/dist/plugins/generic-oauth/providers/keycloak.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/line.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/okta.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/patreon.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/slack.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/yandex.d.mts +28 -0
- package/dist/plugins/generic-oauth/providers/yandex.mjs +60 -0
- package/dist/plugins/generic-oauth/routes.mjs +14 -0
- package/dist/plugins/generic-oauth/types.d.mts +1 -2
- package/dist/plugins/haveibeenpwned/index.d.mts +3 -6
- package/dist/plugins/index.d.mts +5 -1
- package/dist/plugins/index.mjs +2 -1
- package/dist/plugins/jwt/client.d.mts +2 -4
- package/dist/plugins/jwt/index.d.mts +8 -11
- package/dist/plugins/jwt/sign.d.mts +2 -2
- package/dist/plugins/jwt/types.d.mts +1 -1
- package/dist/plugins/jwt/utils.d.mts +2 -4
- package/dist/plugins/jwt/verify.d.mts +0 -1
- package/dist/plugins/last-login-method/client.mjs +13 -0
- package/dist/plugins/last-login-method/index.d.mts +11 -5
- package/dist/plugins/last-login-method/index.mjs +8 -0
- package/dist/plugins/magic-link/client.d.mts +0 -1
- package/dist/plugins/magic-link/index.d.mts +4 -5
- package/dist/plugins/magic-link/index.mjs +32 -1
- package/dist/plugins/mcp/authorize.mjs +12 -0
- package/dist/plugins/mcp/client/adapters.d.mts +0 -1
- package/dist/plugins/mcp/client/index.d.mts +2 -0
- package/dist/plugins/mcp/client/index.mjs +36 -11
- package/dist/plugins/mcp/index.d.mts +10 -11
- package/dist/plugins/multi-session/client.d.mts +2 -4
- package/dist/plugins/multi-session/client.mjs +1 -1
- package/dist/plugins/multi-session/error-codes.d.mts +1 -3
- package/dist/plugins/multi-session/index.d.mts +7 -11
- package/dist/plugins/multi-session/index.mjs +45 -0
- package/dist/plugins/oauth-popup/client.d.mts +6 -12
- package/dist/plugins/oauth-popup/client.mjs +5 -3
- package/dist/plugins/oauth-popup/error-codes.d.mts +4 -6
- package/dist/plugins/oauth-popup/index.d.mts +8 -12
- package/dist/plugins/oauth-popup/index.mjs +1 -1
- package/dist/plugins/oauth-popup/types.d.mts +1 -2
- package/dist/plugins/oauth-proxy/index.d.mts +6 -9
- package/dist/plugins/oauth-proxy/index.mjs +2 -2
- package/dist/plugins/oidc-provider/authorize.mjs +9 -0
- package/dist/plugins/oidc-provider/client.d.mts +1 -2
- package/dist/plugins/oidc-provider/index.d.mts +15 -17
- package/dist/plugins/oidc-provider/index.mjs +26 -2
- package/dist/plugins/oidc-provider/schema.d.mts +0 -1
- package/dist/plugins/oidc-provider/schema.mjs +37 -0
- package/dist/plugins/oidc-provider/types.d.mts +1 -1
- package/dist/plugins/one-tap/client.d.mts +3 -6
- package/dist/plugins/one-tap/client.mjs +3 -0
- package/dist/plugins/one-tap/index.d.mts +1 -3
- package/dist/plugins/one-tap/index.mjs +5 -0
- package/dist/plugins/one-time-token/client.d.mts +1 -2
- package/dist/plugins/one-time-token/index.d.mts +5 -6
- package/dist/plugins/one-time-token/index.mjs +30 -0
- package/dist/plugins/open-api/generator.d.mts +0 -1
- package/dist/plugins/open-api/generator.mjs +81 -5
- package/dist/plugins/open-api/index.d.mts +3 -5
- package/dist/plugins/organization/access/statement.d.mts +1 -0
- package/dist/plugins/organization/adapter.d.mts +56 -82
- package/dist/plugins/organization/adapter.mjs +17 -3
- package/dist/plugins/organization/client.d.mts +106 -105
- package/dist/plugins/organization/client.mjs +7 -4
- package/dist/plugins/organization/error-codes.d.mts +59 -61
- package/dist/plugins/organization/has-permission.d.mts +0 -1
- package/dist/plugins/organization/has-permission.mjs +1 -1
- package/dist/plugins/organization/index.d.mts +1 -1
- package/dist/plugins/organization/organization.d.mts +7 -7
- package/dist/plugins/organization/organization.mjs +434 -1
- package/dist/plugins/organization/permission.d.mts +2 -2
- package/dist/plugins/organization/routes/crud-access-control.d.mts +17 -17
- package/dist/plugins/organization/routes/crud-invites.d.mts +53 -54
- package/dist/plugins/organization/routes/crud-invites.mjs +1 -1
- package/dist/plugins/organization/routes/crud-members.d.mts +44 -46
- package/dist/plugins/organization/routes/crud-members.mjs +4 -1
- package/dist/plugins/organization/routes/crud-org.d.mts +47 -48
- package/dist/plugins/organization/routes/crud-org.mjs +2 -2
- package/dist/plugins/organization/routes/crud-team.d.mts +50 -51
- package/dist/plugins/organization/schema.d.mts +4 -4
- package/dist/plugins/organization/schema.mjs +1 -1
- package/dist/plugins/organization/types.d.mts +16 -16
- package/dist/plugins/phone-number/client.d.mts +13 -15
- package/dist/plugins/phone-number/client.mjs +1 -1
- package/dist/plugins/phone-number/error-codes.d.mts +12 -14
- package/dist/plugins/phone-number/index.d.mts +41 -47
- package/dist/plugins/phone-number/routes.mjs +15 -0
- package/dist/plugins/phone-number/types.d.mts +1 -1
- package/dist/plugins/siwe/client.d.mts +0 -1
- package/dist/plugins/siwe/index.d.mts +4 -5
- package/dist/plugins/test-utils/index.d.mts +2 -4
- package/dist/plugins/test-utils/types.d.mts +1 -0
- package/dist/plugins/two-factor/backup-codes/index.d.mts +4 -6
- package/dist/plugins/two-factor/backup-codes/index.mjs +52 -1
- package/dist/plugins/two-factor/client.d.mts +12 -15
- package/dist/plugins/two-factor/client.mjs +1 -1
- package/dist/plugins/two-factor/error-code.d.mts +10 -12
- package/dist/plugins/two-factor/index.d.mts +27 -31
- package/dist/plugins/two-factor/index.mjs +30 -0
- package/dist/plugins/two-factor/otp/index.d.mts +2 -4
- package/dist/plugins/two-factor/otp/index.mjs +42 -1
- package/dist/plugins/two-factor/totp/index.d.mts +4 -6
- package/dist/plugins/two-factor/totp/index.mjs +47 -0
- package/dist/plugins/two-factor/types.d.mts +1 -1
- package/dist/plugins/username/client.d.mts +9 -11
- package/dist/plugins/username/client.mjs +1 -1
- package/dist/plugins/username/error-codes.d.mts +8 -10
- package/dist/plugins/username/index.d.mts +17 -22
- package/dist/plugins/username/schema.d.mts +3 -5
- package/dist/state.d.mts +0 -1
- package/dist/state.mjs +4 -0
- package/dist/test-utils/test-instance.d.mts +5 -3
- package/dist/test-utils/test-instance.mjs +4 -1
- package/dist/types/adapter.d.mts +1 -1
- package/dist/types/api.d.mts +1 -2
- package/dist/types/auth.d.mts +0 -1
- package/dist/types/helper.d.mts +5 -5
- package/dist/types/index.d.mts +2 -2
- package/dist/types/models.d.mts +0 -1
- package/dist/types/plugins.d.mts +2 -3
- package/dist/utils/index.d.mts +2 -1
- package/dist/utils/request.mjs +23 -0
- package/dist/utils/url.d.mts +0 -1
- package/package.json +10 -10
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { InferOptionSchema } from "../../types/plugins.mjs";
|
|
2
2
|
import { schema } from "./schema.mjs";
|
|
3
3
|
import { AuthorizationQuery, Client, CodeVerificationValue, OAuthAccessToken, OIDCMetadata, OIDCOptions, TokenBody } from "./types.mjs";
|
|
4
|
+
import "../index.mjs";
|
|
4
5
|
import { GenericEndpointContext } from "@better-auth/core";
|
|
5
|
-
import * as _better_auth_core_db0 from "@better-auth/core/db";
|
|
6
|
-
import * as better_call0 from "better-call";
|
|
7
6
|
import { OpenAPIParameter } from "better-call";
|
|
8
7
|
import * as z from "zod";
|
|
9
|
-
|
|
10
8
|
//#region src/plugins/oidc-provider/index.d.ts
|
|
11
9
|
declare module "@better-auth/core" {
|
|
12
10
|
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
@@ -41,21 +39,21 @@ declare const oidcProvider: (options: OIDCOptions) => {
|
|
|
41
39
|
hooks: {
|
|
42
40
|
after: {
|
|
43
41
|
matcher(): true;
|
|
44
|
-
handler: (inputContext:
|
|
42
|
+
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<Response | {
|
|
45
43
|
redirect: boolean;
|
|
46
44
|
url: string;
|
|
47
45
|
} | undefined>;
|
|
48
46
|
}[];
|
|
49
47
|
};
|
|
50
48
|
endpoints: {
|
|
51
|
-
getOpenIdConfig:
|
|
49
|
+
getOpenIdConfig: import("better-call").StrictEndpoint<"/.well-known/openid-configuration", {
|
|
52
50
|
method: "GET";
|
|
53
51
|
operationId: string;
|
|
54
52
|
metadata: {
|
|
55
53
|
readonly scope: "server";
|
|
56
54
|
};
|
|
57
55
|
}, OIDCMetadata>;
|
|
58
|
-
oAuth2authorize:
|
|
56
|
+
oAuth2authorize: import("better-call").StrictEndpoint<"/oauth2/authorize", {
|
|
59
57
|
method: "GET";
|
|
60
58
|
operationId: string;
|
|
61
59
|
query: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
@@ -82,14 +80,14 @@ declare const oidcProvider: (options: OIDCOptions) => {
|
|
|
82
80
|
redirect: boolean;
|
|
83
81
|
url: string;
|
|
84
82
|
}>;
|
|
85
|
-
oAuthConsent:
|
|
83
|
+
oAuthConsent: import("better-call").StrictEndpoint<"/oauth2/consent", {
|
|
86
84
|
method: "POST";
|
|
87
85
|
operationId: string;
|
|
88
86
|
body: z.ZodObject<{
|
|
89
87
|
accept: z.ZodBoolean;
|
|
90
88
|
consent_code: z.ZodOptional<z.ZodNullable<z.ZodOptional<z.ZodString>>>;
|
|
91
89
|
}, z.core.$strip>;
|
|
92
|
-
use: ((inputContext:
|
|
90
|
+
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
93
91
|
session: {
|
|
94
92
|
session: Record<string, any> & {
|
|
95
93
|
id: string;
|
|
@@ -161,7 +159,7 @@ declare const oidcProvider: (options: OIDCOptions) => {
|
|
|
161
159
|
}, {
|
|
162
160
|
redirectURI: string;
|
|
163
161
|
}>;
|
|
164
|
-
oAuth2token:
|
|
162
|
+
oAuth2token: import("better-call").StrictEndpoint<"/oauth2/token", {
|
|
165
163
|
method: "POST";
|
|
166
164
|
operationId: string;
|
|
167
165
|
body: z.ZodRecord<z.ZodAny, z.ZodAny>;
|
|
@@ -183,7 +181,7 @@ declare const oidcProvider: (options: OIDCOptions) => {
|
|
|
183
181
|
scope: string;
|
|
184
182
|
id_token: string | undefined;
|
|
185
183
|
}>;
|
|
186
|
-
oAuth2userInfo:
|
|
184
|
+
oAuth2userInfo: import("better-call").StrictEndpoint<"/oauth2/userinfo", {
|
|
187
185
|
method: "GET";
|
|
188
186
|
operationId: string;
|
|
189
187
|
metadata: {
|
|
@@ -275,7 +273,7 @@ declare const oidcProvider: (options: OIDCOptions) => {
|
|
|
275
273
|
*
|
|
276
274
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/oidc-provider#api-method-oauth2-register)
|
|
277
275
|
*/
|
|
278
|
-
registerOAuthApplication:
|
|
276
|
+
registerOAuthApplication: import("better-call").StrictEndpoint<"/oauth2/register", {
|
|
279
277
|
method: "POST";
|
|
280
278
|
body: z.ZodObject<{
|
|
281
279
|
redirect_uris: z.ZodArray<z.ZodString>;
|
|
@@ -415,9 +413,9 @@ declare const oidcProvider: (options: OIDCOptions) => {
|
|
|
415
413
|
client_secret?: string | undefined;
|
|
416
414
|
client_id: string;
|
|
417
415
|
}>;
|
|
418
|
-
getOAuthClient:
|
|
416
|
+
getOAuthClient: import("better-call").StrictEndpoint<"/oauth2/client/:id", {
|
|
419
417
|
method: "GET";
|
|
420
|
-
use: ((inputContext:
|
|
418
|
+
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
421
419
|
session: {
|
|
422
420
|
session: Record<string, any> & {
|
|
423
421
|
id: string;
|
|
@@ -488,7 +486,7 @@ declare const oidcProvider: (options: OIDCOptions) => {
|
|
|
488
486
|
*
|
|
489
487
|
* @see [OpenID Connect RP-Initiated Logout Spec](https://openid.net/specs/openid-connect-rpinitiated-1_0.html)
|
|
490
488
|
*/
|
|
491
|
-
endSession:
|
|
489
|
+
endSession: import("better-call").StrictEndpoint<"/oauth2/endsession", {
|
|
492
490
|
method: ("GET" | "POST")[];
|
|
493
491
|
query: z.ZodOptional<z.ZodObject<{
|
|
494
492
|
id_token_hint: z.ZodOptional<z.ZodString>;
|
|
@@ -514,7 +512,7 @@ declare const oidcProvider: (options: OIDCOptions) => {
|
|
|
514
512
|
scope: "server";
|
|
515
513
|
};
|
|
516
514
|
}, {
|
|
517
|
-
status: ("OK" | "CREATED" | "ACCEPTED" | "NO_CONTENT" | "MULTIPLE_CHOICES" | "MOVED_PERMANENTLY" | "FOUND" | "SEE_OTHER" | "NOT_MODIFIED" | "TEMPORARY_REDIRECT" | "BAD_REQUEST" | "UNAUTHORIZED" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "NOT_FOUND" | "METHOD_NOT_ALLOWED" | "NOT_ACCEPTABLE" | "PROXY_AUTHENTICATION_REQUIRED" | "REQUEST_TIMEOUT" | "CONFLICT" | "GONE" | "LENGTH_REQUIRED" | "PRECONDITION_FAILED" | "PAYLOAD_TOO_LARGE" | "URI_TOO_LONG" | "UNSUPPORTED_MEDIA_TYPE" | "RANGE_NOT_SATISFIABLE" | "EXPECTATION_FAILED" | "I'M_A_TEAPOT" | "MISDIRECTED_REQUEST" | "UNPROCESSABLE_ENTITY" | "LOCKED" | "FAILED_DEPENDENCY" | "TOO_EARLY" | "UPGRADE_REQUIRED" | "PRECONDITION_REQUIRED" | "TOO_MANY_REQUESTS" | "REQUEST_HEADER_FIELDS_TOO_LARGE" | "UNAVAILABLE_FOR_LEGAL_REASONS" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "HTTP_VERSION_NOT_SUPPORTED" | "VARIANT_ALSO_NEGOTIATES" | "INSUFFICIENT_STORAGE" | "LOOP_DETECTED" | "NOT_EXTENDED" | "NETWORK_AUTHENTICATION_REQUIRED") |
|
|
515
|
+
status: ("OK" | "CREATED" | "ACCEPTED" | "NO_CONTENT" | "MULTIPLE_CHOICES" | "MOVED_PERMANENTLY" | "FOUND" | "SEE_OTHER" | "NOT_MODIFIED" | "TEMPORARY_REDIRECT" | "BAD_REQUEST" | "UNAUTHORIZED" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "NOT_FOUND" | "METHOD_NOT_ALLOWED" | "NOT_ACCEPTABLE" | "PROXY_AUTHENTICATION_REQUIRED" | "REQUEST_TIMEOUT" | "CONFLICT" | "GONE" | "LENGTH_REQUIRED" | "PRECONDITION_FAILED" | "PAYLOAD_TOO_LARGE" | "URI_TOO_LONG" | "UNSUPPORTED_MEDIA_TYPE" | "RANGE_NOT_SATISFIABLE" | "EXPECTATION_FAILED" | "I'M_A_TEAPOT" | "MISDIRECTED_REQUEST" | "UNPROCESSABLE_ENTITY" | "LOCKED" | "FAILED_DEPENDENCY" | "TOO_EARLY" | "UPGRADE_REQUIRED" | "PRECONDITION_REQUIRED" | "TOO_MANY_REQUESTS" | "REQUEST_HEADER_FIELDS_TOO_LARGE" | "UNAVAILABLE_FOR_LEGAL_REASONS" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "HTTP_VERSION_NOT_SUPPORTED" | "VARIANT_ALSO_NEGOTIATES" | "INSUFFICIENT_STORAGE" | "LOOP_DETECTED" | "NOT_EXTENDED" | "NETWORK_AUTHENTICATION_REQUIRED") | import("better-call").Status;
|
|
518
516
|
body: ({
|
|
519
517
|
message?: string;
|
|
520
518
|
code?: string;
|
|
@@ -689,7 +687,7 @@ declare const oidcProvider: (options: OIDCOptions) => {
|
|
|
689
687
|
allowPlainCodeChallengeMethod: boolean;
|
|
690
688
|
generateClientId?: (() => string) | undefined;
|
|
691
689
|
generateClientSecret?: (() => string) | undefined;
|
|
692
|
-
getAdditionalUserInfoClaim?: ((user:
|
|
690
|
+
getAdditionalUserInfoClaim?: ((user: import("@better-auth/core/db").User & Record<string, any>, scopes: string[], client: Client) => Record<string, any> | Promise<Record<string, any>>) | undefined;
|
|
693
691
|
trustedClients?: Client[] | undefined;
|
|
694
692
|
storeClientSecret: "plain" | "hashed" | "encrypted" | {
|
|
695
693
|
hash: (clientSecret: string) => Promise<string>;
|
|
@@ -702,4 +700,4 @@ declare const oidcProvider: (options: OIDCOptions) => {
|
|
|
702
700
|
};
|
|
703
701
|
};
|
|
704
702
|
//#endregion
|
|
705
|
-
export { AuthorizationQuery, Client, CodeVerificationValue, OAuthAccessToken, OIDCMetadata, OIDCOptions, TokenBody, getClient, getMetadata, oidcProvider };
|
|
703
|
+
export { type AuthorizationQuery, type Client, type CodeVerificationValue, type OAuthAccessToken, type OIDCMetadata, type OIDCOptions, type TokenBody, getClient, getMetadata, oidcProvider };
|
|
@@ -414,8 +414,7 @@ const oidcProvider = (options) => {
|
|
|
414
414
|
client_id = id;
|
|
415
415
|
client_secret = secret;
|
|
416
416
|
}
|
|
417
|
-
const
|
|
418
|
-
const iat = Math.floor(now / 1e3);
|
|
417
|
+
const iat = Math.floor(Date.now() / 1e3);
|
|
419
418
|
const exp = iat + (opts.accessTokenExpiresIn ?? 3600);
|
|
420
419
|
const accessTokenExpiresAt = /* @__PURE__ */ new Date(exp * 1e3);
|
|
421
420
|
const refreshTokenExpiresAt = /* @__PURE__ */ new Date((iat + (opts.refreshTokenExpiresIn ?? 604800)) * 1e3);
|
|
@@ -765,6 +764,21 @@ const oidcProvider = (options) => {
|
|
|
765
764
|
...userClaims
|
|
766
765
|
});
|
|
767
766
|
}),
|
|
767
|
+
/**
|
|
768
|
+
* ### Endpoint
|
|
769
|
+
*
|
|
770
|
+
* POST `/oauth2/register`
|
|
771
|
+
*
|
|
772
|
+
* ### API Methods
|
|
773
|
+
*
|
|
774
|
+
* **server:**
|
|
775
|
+
* `auth.api.registerOAuthApplication`
|
|
776
|
+
*
|
|
777
|
+
* **client:**
|
|
778
|
+
* `authClient.oauth2.register`
|
|
779
|
+
*
|
|
780
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/oidc-provider#api-method-oauth2-register)
|
|
781
|
+
*/
|
|
768
782
|
registerOAuthApplication: createAuthEndpoint("/oauth2/register", {
|
|
769
783
|
method: "POST",
|
|
770
784
|
body: registerOAuthApplicationBodySchema,
|
|
@@ -965,6 +979,16 @@ const oidcProvider = (options) => {
|
|
|
965
979
|
icon: client.icon || null
|
|
966
980
|
});
|
|
967
981
|
}),
|
|
982
|
+
/**
|
|
983
|
+
* ### Endpoint
|
|
984
|
+
*
|
|
985
|
+
* GET/POST `/oauth2/endsession`
|
|
986
|
+
*
|
|
987
|
+
* Implements RP-Initiated Logout as per OpenID Connect RP-Initiated Logout 1.0.
|
|
988
|
+
* Allows relying parties to request that an OpenID Provider log out the end-user.
|
|
989
|
+
*
|
|
990
|
+
* @see [OpenID Connect RP-Initiated Logout Spec](https://openid.net/specs/openid-connect-rpinitiated-1_0.html)
|
|
991
|
+
*/
|
|
968
992
|
endSession: createAuthEndpoint("/oauth2/endsession", {
|
|
969
993
|
method: ["GET", "POST"],
|
|
970
994
|
query: z.object({
|
|
@@ -1,17 +1,54 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
2
|
//#region src/plugins/oidc-provider/schema.ts
|
|
3
3
|
z.object({
|
|
4
|
+
/**
|
|
5
|
+
* Client ID
|
|
6
|
+
*
|
|
7
|
+
* size 32
|
|
8
|
+
*
|
|
9
|
+
* as described on https://www.rfc-editor.org/rfc/rfc6749.html#section-2.2
|
|
10
|
+
*/
|
|
4
11
|
clientId: z.string(),
|
|
12
|
+
/**
|
|
13
|
+
* Client Secret
|
|
14
|
+
*
|
|
15
|
+
* A secret for the client, if required by the authorization server.
|
|
16
|
+
* Optional for public clients using PKCE.
|
|
17
|
+
*
|
|
18
|
+
* size 32
|
|
19
|
+
*/
|
|
5
20
|
clientSecret: z.string().optional(),
|
|
21
|
+
/**
|
|
22
|
+
* The client type
|
|
23
|
+
*
|
|
24
|
+
* as described on https://www.rfc-editor.org/rfc/rfc6749.html#section-2.1
|
|
25
|
+
*
|
|
26
|
+
* - web - A web application
|
|
27
|
+
* - native - A mobile application
|
|
28
|
+
* - user-agent-based - A user-agent-based application
|
|
29
|
+
* - public - A public client (PKCE-enabled, no client_secret)
|
|
30
|
+
*/
|
|
6
31
|
type: z.enum([
|
|
7
32
|
"web",
|
|
8
33
|
"native",
|
|
9
34
|
"user-agent-based",
|
|
10
35
|
"public"
|
|
11
36
|
]),
|
|
37
|
+
/**
|
|
38
|
+
* The name of the client.
|
|
39
|
+
*/
|
|
12
40
|
name: z.string(),
|
|
41
|
+
/**
|
|
42
|
+
* The icon of the client.
|
|
43
|
+
*/
|
|
13
44
|
icon: z.string().optional(),
|
|
45
|
+
/**
|
|
46
|
+
* Additional metadata about the client.
|
|
47
|
+
*/
|
|
14
48
|
metadata: z.string().optional(),
|
|
49
|
+
/**
|
|
50
|
+
* Whether the client is disabled or not.
|
|
51
|
+
*/
|
|
15
52
|
disabled: z.boolean().optional().default(false),
|
|
16
53
|
redirectUrls: z.string(),
|
|
17
54
|
userId: z.string().optional(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { User } from "../../types/models.mjs";
|
|
2
2
|
import { InferOptionSchema } from "../../types/plugins.mjs";
|
|
3
|
+
import "../../types/index.mjs";
|
|
3
4
|
import { OAuthApplication, schema } from "./schema.mjs";
|
|
4
|
-
|
|
5
5
|
//#region src/plugins/oidc-provider/types.d.ts
|
|
6
6
|
interface OIDCOptions {
|
|
7
7
|
/** @internal */
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import * as _better_auth_core0 from "@better-auth/core";
|
|
2
1
|
import { ClientFetchOption } from "@better-auth/core";
|
|
3
|
-
import * as _better_fetch_fetch0 from "@better-fetch/fetch";
|
|
4
|
-
|
|
5
2
|
//#region src/plugins/one-tap/client.d.ts
|
|
6
3
|
declare global {
|
|
7
4
|
interface Window {
|
|
@@ -162,13 +159,13 @@ declare const oneTapClient: (options: GoogleOneTapOptions) => {
|
|
|
162
159
|
id: string;
|
|
163
160
|
name: string;
|
|
164
161
|
hooks: {
|
|
165
|
-
onResponse(ctx:
|
|
162
|
+
onResponse(ctx: import("@better-fetch/fetch").ResponseContext): Promise<void>;
|
|
166
163
|
};
|
|
167
164
|
}[];
|
|
168
|
-
getActions: ($fetch:
|
|
165
|
+
getActions: ($fetch: import("@better-fetch/fetch").BetterFetch, _: import("@better-auth/core").ClientStore) => {
|
|
169
166
|
oneTap: (opts?: GoogleOneTapActionOptions | undefined, fetchOptions?: ClientFetchOption | undefined) => Promise<void>;
|
|
170
167
|
};
|
|
171
|
-
getAtoms($fetch:
|
|
168
|
+
getAtoms($fetch: import("@better-fetch/fetch").BetterFetch): {};
|
|
172
169
|
};
|
|
173
170
|
//#endregion
|
|
174
171
|
export { GoogleOneTapActionOptions, GoogleOneTapOptions, GsiButtonConfiguration, oneTapClient };
|
|
@@ -124,6 +124,9 @@ const oneTapClient = (options) => {
|
|
|
124
124
|
context: contextValue,
|
|
125
125
|
ux_mode: opts?.uxMode || "popup",
|
|
126
126
|
nonce: opts?.nonce,
|
|
127
|
+
/**
|
|
128
|
+
* @see {@link https://developers.google.com/identity/gsi/web/guides/overview}
|
|
129
|
+
*/
|
|
127
130
|
itp_support: true,
|
|
128
131
|
use_fedcm_for_prompt: useFedCM,
|
|
129
132
|
...options.additionalOptions
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import * as better_call0 from "better-call";
|
|
2
1
|
import * as z from "zod";
|
|
3
|
-
|
|
4
2
|
//#region src/plugins/one-tap/index.d.ts
|
|
5
3
|
declare module "@better-auth/core" {
|
|
6
4
|
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
@@ -28,7 +26,7 @@ declare const oneTap: (options?: OneTapOptions | undefined) => {
|
|
|
28
26
|
id: "one-tap";
|
|
29
27
|
version: string;
|
|
30
28
|
endpoints: {
|
|
31
|
-
oneTapCallback:
|
|
29
|
+
oneTapCallback: import("better-call").StrictEndpoint<"/one-tap/callback", {
|
|
32
30
|
method: "POST";
|
|
33
31
|
body: z.ZodObject<{
|
|
34
32
|
idToken: z.ZodString;
|
|
@@ -10,6 +10,11 @@ import * as z from "zod";
|
|
|
10
10
|
//#region src/plugins/one-tap/index.ts
|
|
11
11
|
const oneTapCallbackBodySchema = z.object({
|
|
12
12
|
idToken: z.string().meta({ description: "Google ID token, which the client obtains from the One Tap API" }),
|
|
13
|
+
/**
|
|
14
|
+
* Sent so the global origin-check middleware validates the post-login
|
|
15
|
+
* redirect target against `trustedOrigins`. Without it the client performs
|
|
16
|
+
* an unvalidated `window.location` redirect, which is an open redirect.
|
|
17
|
+
*/
|
|
13
18
|
callbackURL: z.string().meta({ description: "URL to redirect to after a successful sign-in" }).optional()
|
|
14
19
|
});
|
|
15
20
|
const oneTap = (options) => ({
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { OneTimeTokenOptions, oneTimeToken } from "./index.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/plugins/one-time-token/client.d.ts
|
|
4
3
|
declare const oneTimeTokenClient: () => {
|
|
5
4
|
id: "one-time-token";
|
|
@@ -7,4 +6,4 @@ declare const oneTimeTokenClient: () => {
|
|
|
7
6
|
$InferServerPlugin: ReturnType<typeof oneTimeToken>;
|
|
8
7
|
};
|
|
9
8
|
//#endregion
|
|
10
|
-
export { oneTimeTokenClient };
|
|
9
|
+
export { type OneTimeTokenOptions, oneTimeTokenClient };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Session, User } from "../../types/models.mjs";
|
|
2
|
+
import "../../types/index.mjs";
|
|
2
3
|
import { GenericEndpointContext } from "@better-auth/core";
|
|
3
|
-
import * as better_call0 from "better-call";
|
|
4
4
|
import * as z from "zod";
|
|
5
|
-
|
|
6
5
|
//#region src/plugins/one-time-token/index.d.ts
|
|
7
6
|
declare module "@better-auth/core" {
|
|
8
7
|
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
@@ -67,9 +66,9 @@ declare const oneTimeToken: (options?: OneTimeTokenOptions | undefined) => {
|
|
|
67
66
|
*
|
|
68
67
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/one-time-token#api-method-one-time-token-generate)
|
|
69
68
|
*/
|
|
70
|
-
generateOneTimeToken:
|
|
69
|
+
generateOneTimeToken: import("better-call").StrictEndpoint<"/one-time-token/generate", {
|
|
71
70
|
method: "GET";
|
|
72
|
-
use: ((inputContext:
|
|
71
|
+
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
73
72
|
session: {
|
|
74
73
|
session: Record<string, any> & {
|
|
75
74
|
id: string;
|
|
@@ -110,7 +109,7 @@ declare const oneTimeToken: (options?: OneTimeTokenOptions | undefined) => {
|
|
|
110
109
|
*
|
|
111
110
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/one-time-token#api-method-one-time-token-verify)
|
|
112
111
|
*/
|
|
113
|
-
verifyOneTimeToken:
|
|
112
|
+
verifyOneTimeToken: import("better-call").StrictEndpoint<"/one-time-token/verify", {
|
|
114
113
|
method: "POST";
|
|
115
114
|
body: z.ZodObject<{
|
|
116
115
|
token: z.ZodString;
|
|
@@ -123,7 +122,7 @@ declare const oneTimeToken: (options?: OneTimeTokenOptions | undefined) => {
|
|
|
123
122
|
hooks: {
|
|
124
123
|
after: {
|
|
125
124
|
matcher: () => true;
|
|
126
|
-
handler: (inputContext:
|
|
125
|
+
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>;
|
|
127
126
|
}[];
|
|
128
127
|
};
|
|
129
128
|
options: OneTimeTokenOptions | undefined;
|
|
@@ -32,6 +32,21 @@ const oneTimeToken = (options) => {
|
|
|
32
32
|
id: "one-time-token",
|
|
33
33
|
version: PACKAGE_VERSION,
|
|
34
34
|
endpoints: {
|
|
35
|
+
/**
|
|
36
|
+
* ### Endpoint
|
|
37
|
+
*
|
|
38
|
+
* GET `/one-time-token/generate`
|
|
39
|
+
*
|
|
40
|
+
* ### API Methods
|
|
41
|
+
*
|
|
42
|
+
* **server:**
|
|
43
|
+
* `auth.api.generateOneTimeToken`
|
|
44
|
+
*
|
|
45
|
+
* **client:**
|
|
46
|
+
* `authClient.oneTimeToken.generate`
|
|
47
|
+
*
|
|
48
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/one-time-token#api-method-one-time-token-generate)
|
|
49
|
+
*/
|
|
35
50
|
generateOneTimeToken: createAuthEndpoint("/one-time-token/generate", {
|
|
36
51
|
method: "GET",
|
|
37
52
|
use: [sessionMiddleware]
|
|
@@ -41,6 +56,21 @@ const oneTimeToken = (options) => {
|
|
|
41
56
|
const token = await generateToken(c, session);
|
|
42
57
|
return c.json({ token });
|
|
43
58
|
}),
|
|
59
|
+
/**
|
|
60
|
+
* ### Endpoint
|
|
61
|
+
*
|
|
62
|
+
* POST `/one-time-token/verify`
|
|
63
|
+
*
|
|
64
|
+
* ### API Methods
|
|
65
|
+
*
|
|
66
|
+
* **server:**
|
|
67
|
+
* `auth.api.verifyOneTimeToken`
|
|
68
|
+
*
|
|
69
|
+
* **client:**
|
|
70
|
+
* `authClient.oneTimeToken.verify`
|
|
71
|
+
*
|
|
72
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/one-time-token#api-method-one-time-token-verify)
|
|
73
|
+
*/
|
|
44
74
|
verifyOneTimeToken: createAuthEndpoint("/one-time-token/verify", {
|
|
45
75
|
method: "POST",
|
|
46
76
|
body: verifyOneTimeTokenBodySchema
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { AuthContext, BetterAuthOptions } from "@better-auth/core";
|
|
2
2
|
import { DBFieldAttributeConfig, DBFieldType } from "@better-auth/core/db";
|
|
3
3
|
import { OpenAPIParameter, OpenAPISchemaType } from "better-call";
|
|
4
|
-
|
|
5
4
|
//#region src/plugins/open-api/generator.d.ts
|
|
6
5
|
interface Path {
|
|
7
6
|
get?: OpenAPIOperation | undefined;
|
|
@@ -2,7 +2,7 @@ import { db_exports } from "../../db/index.mjs";
|
|
|
2
2
|
import { getEndpoints } from "../../api/index.mjs";
|
|
3
3
|
import * as z from "zod";
|
|
4
4
|
//#region src/plugins/open-api/generator.ts
|
|
5
|
-
const OPEN_API_SCHEMA_TYPES = new Set([
|
|
5
|
+
const OPEN_API_SCHEMA_TYPES = /* @__PURE__ */ new Set([
|
|
6
6
|
"string",
|
|
7
7
|
"number",
|
|
8
8
|
"boolean",
|
|
@@ -47,7 +47,7 @@ function withDescription(schema, zodType) {
|
|
|
47
47
|
function addNullType(schema) {
|
|
48
48
|
if (schema.type) {
|
|
49
49
|
const type = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
50
|
-
const nullableType = Array.from(new Set([...type, "null"]));
|
|
50
|
+
const nullableType = Array.from(/* @__PURE__ */ new Set([...type, "null"]));
|
|
51
51
|
return {
|
|
52
52
|
...schema,
|
|
53
53
|
type: nullableType
|
|
@@ -134,7 +134,7 @@ function mergeObjectSchemas(left, right, description) {
|
|
|
134
134
|
if (properties[key] !== void 0 && !areSchemasEqual(properties[key], value)) return;
|
|
135
135
|
properties[key] = value;
|
|
136
136
|
}
|
|
137
|
-
const required = Array.from(new Set([...left.required || [], ...right.required || []]));
|
|
137
|
+
const required = Array.from(/* @__PURE__ */ new Set([...left.required || [], ...right.required || []]));
|
|
138
138
|
const leftAdditionalProperties = left.additionalProperties;
|
|
139
139
|
const rightAdditionalProperties = right.additionalProperties;
|
|
140
140
|
if (!areSchemaMembersCompatible(leftAdditionalProperties, rightAdditionalProperties)) return;
|
|
@@ -162,6 +162,82 @@ function getRequestBody(options) {
|
|
|
162
162
|
content: { "application/json": { schema } }
|
|
163
163
|
};
|
|
164
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Paths that accept `user.additionalFields` and plugin user schema fields via
|
|
167
|
+
* `parseUserInput`. Their static OpenAPI request bodies need those fields merged in.
|
|
168
|
+
*/
|
|
169
|
+
const USER_INPUT_BODY_PATHS = /* @__PURE__ */ new Set(["/sign-up/email", "/update-user"]);
|
|
170
|
+
function dbFieldToRequestBodyProperty(field) {
|
|
171
|
+
if (field.type === "date") return {
|
|
172
|
+
type: "string",
|
|
173
|
+
format: "date-time"
|
|
174
|
+
};
|
|
175
|
+
if (field.type === "json") return {
|
|
176
|
+
type: "object",
|
|
177
|
+
additionalProperties: true
|
|
178
|
+
};
|
|
179
|
+
if (field.type === "string[]") return {
|
|
180
|
+
type: "array",
|
|
181
|
+
items: { type: "string" }
|
|
182
|
+
};
|
|
183
|
+
if (field.type === "number[]") return {
|
|
184
|
+
type: "array",
|
|
185
|
+
items: { type: "number" }
|
|
186
|
+
};
|
|
187
|
+
if (Array.isArray(field.type)) return {
|
|
188
|
+
type: "string",
|
|
189
|
+
enum: field.type
|
|
190
|
+
};
|
|
191
|
+
const schema = { type: field.type };
|
|
192
|
+
if (field.defaultValue !== void 0 && typeof field.defaultValue !== "function") schema.default = field.defaultValue;
|
|
193
|
+
return schema;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Collect client-writable user fields from `user.additionalFields` and plugin
|
|
197
|
+
* schemas. Mirrors `getFields(..., "input")` used by `parseUserInput`.
|
|
198
|
+
*/
|
|
199
|
+
function getUserInputRequestBodyFields(options) {
|
|
200
|
+
let fields = { ...options.user?.additionalFields ?? {} };
|
|
201
|
+
for (const plugin of options.plugins || []) {
|
|
202
|
+
const pluginUserFields = plugin.schema?.user?.fields;
|
|
203
|
+
if (pluginUserFields) fields = {
|
|
204
|
+
...fields,
|
|
205
|
+
...pluginUserFields
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
const properties = {};
|
|
209
|
+
const required = [];
|
|
210
|
+
for (const [key, field] of Object.entries(fields)) {
|
|
211
|
+
if (!field || field.input === false) continue;
|
|
212
|
+
properties[key] = dbFieldToRequestBodyProperty(field);
|
|
213
|
+
if (field.required === true && field.defaultValue === void 0) required.push(key);
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
properties,
|
|
217
|
+
required
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function applyUserInputFieldsToRequestBody(path, requestBody, options) {
|
|
221
|
+
if (!USER_INPUT_BODY_PATHS.has(path)) return requestBody;
|
|
222
|
+
const { properties: inputProperties, required: inputRequired } = getUserInputRequestBodyFields(options);
|
|
223
|
+
if (Object.keys(inputProperties).length === 0) return requestBody;
|
|
224
|
+
const existingSchema = requestBody?.content?.["application/json"]?.schema;
|
|
225
|
+
const properties = { ...existingSchema?.properties ?? {} };
|
|
226
|
+
for (const [key, value] of Object.entries(inputProperties)) if (properties[key] === void 0) properties[key] = value;
|
|
227
|
+
const required = new Set(existingSchema?.required ?? []);
|
|
228
|
+
if (path === "/sign-up/email") {
|
|
229
|
+
for (const key of inputRequired) if (properties[key] !== void 0) required.add(key);
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
...requestBody,
|
|
233
|
+
content: { "application/json": { schema: {
|
|
234
|
+
...existingSchema ?? {},
|
|
235
|
+
type: existingSchema?.type ?? "object",
|
|
236
|
+
properties,
|
|
237
|
+
...required.size > 0 ? { required: Array.from(required) } : {}
|
|
238
|
+
} } }
|
|
239
|
+
};
|
|
240
|
+
}
|
|
165
241
|
function toOpenApiSchema(zodType) {
|
|
166
242
|
if (zodType instanceof z.ZodOptional) return toOpenApiSchema(unwrapZodSchema(zodType));
|
|
167
243
|
if (zodType instanceof z.ZodNullable) return addNullType(toOpenApiSchema(unwrapZodSchema(zodType)));
|
|
@@ -323,7 +399,7 @@ async function generator(ctx, options) {
|
|
|
323
399
|
const components = { schemas: { ...Object.entries(tables).reduce((acc, [key, value]) => {
|
|
324
400
|
const modelName = key.charAt(0).toUpperCase() + key.slice(1);
|
|
325
401
|
const fields = value.fields;
|
|
326
|
-
const required = new Set(["id"]);
|
|
402
|
+
const required = /* @__PURE__ */ new Set(["id"]);
|
|
327
403
|
const properties = { id: {
|
|
328
404
|
type: "string",
|
|
329
405
|
readOnly: true
|
|
@@ -366,7 +442,7 @@ async function generator(ctx, options) {
|
|
|
366
442
|
}
|
|
367
443
|
};
|
|
368
444
|
for (const method of methods.filter((m) => m === "POST" || m === "PATCH" || m === "PUT")) {
|
|
369
|
-
const body = getRequestBody(options);
|
|
445
|
+
const body = applyUserInputFieldsToRequestBody(value.path, getRequestBody(options), ctx.options);
|
|
370
446
|
paths[path] = {
|
|
371
447
|
...paths[path],
|
|
372
448
|
[method.toLowerCase()]: {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { FieldSchema, OpenAPIModelSchema, OpenAPIParameter, OpenAPISchema, Path, generator } from "./generator.mjs";
|
|
2
2
|
import { LiteralString } from "@better-auth/core";
|
|
3
|
-
import * as better_call0 from "better-call";
|
|
4
|
-
|
|
5
3
|
//#region src/plugins/open-api/index.d.ts
|
|
6
4
|
declare module "@better-auth/core" {
|
|
7
5
|
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
@@ -44,7 +42,7 @@ declare const openAPI: <O extends OpenAPIOptions>(options?: O | undefined) => {
|
|
|
44
42
|
id: "open-api";
|
|
45
43
|
version: string;
|
|
46
44
|
endpoints: {
|
|
47
|
-
generateOpenAPISchema:
|
|
45
|
+
generateOpenAPISchema: import("better-call").StrictEndpoint<"/open-api/generate-schema", {
|
|
48
46
|
method: "GET";
|
|
49
47
|
}, {
|
|
50
48
|
openapi: string;
|
|
@@ -84,7 +82,7 @@ declare const openAPI: <O extends OpenAPIOptions>(options?: O | undefined) => {
|
|
|
84
82
|
}[];
|
|
85
83
|
paths: Record<string, Path>;
|
|
86
84
|
}>;
|
|
87
|
-
openAPIReference:
|
|
85
|
+
openAPIReference: import("better-call").StrictEndpoint<LiteralString | "/reference", {
|
|
88
86
|
method: "GET";
|
|
89
87
|
metadata: {
|
|
90
88
|
readonly scope: "server";
|
|
@@ -94,4 +92,4 @@ declare const openAPI: <O extends OpenAPIOptions>(options?: O | undefined) => {
|
|
|
94
92
|
options: NoInfer<O>;
|
|
95
93
|
};
|
|
96
94
|
//#endregion
|
|
97
|
-
export { type FieldSchema, type OpenAPIModelSchema, OpenAPIOptions, OpenAPIParameter, OpenAPISchema, type Path, generator, openAPI };
|
|
95
|
+
export { type FieldSchema, type OpenAPIModelSchema, OpenAPIOptions, type OpenAPIParameter, type OpenAPISchema, type Path, type generator, openAPI };
|