better-auth 1.6.17 → 1.6.18
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/client/lynx/index.d.mts +4 -2
- package/dist/client/react/index.d.mts +4 -2
- package/dist/client/solid/index.d.mts +4 -2
- package/dist/client/svelte/index.d.mts +4 -2
- package/dist/client/types.d.mts +27 -16
- package/dist/client/vanilla.d.mts +4 -2
- package/dist/client/vue/index.d.mts +4 -2
- package/dist/package.mjs +1 -1
- package/dist/plugins/index.d.mts +2 -2
- package/dist/plugins/open-api/generator.d.mts +66 -57
- package/dist/plugins/open-api/generator.mjs +178 -63
- package/dist/plugins/open-api/index.d.mts +2 -2
- package/dist/test-utils/test-instance.d.mts +26 -23
- package/package.json +8 -8
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ExtractPluginField, HasRequiredKeys, InferPluginFieldFromTuple, IsAny, OverrideMerge, Prettify, PrettifyDeep, RequiredKeysOf, StripEmptyObjects, UnionToIntersection } from "../../types/helper.mjs";
|
|
2
2
|
import { InferActions, InferClientAPI, InferErrorCodes, IsSignal, SessionQueryParams } from "../types.mjs";
|
|
3
3
|
import { useStore } from "./lynx-store.mjs";
|
|
4
|
-
import { BetterAuthClientOptions
|
|
4
|
+
import { BetterAuthClientOptions } from "@better-auth/core";
|
|
5
5
|
import { BASE_ERROR_CODES } from "@better-auth/core/error";
|
|
6
6
|
import * as nanostores from "nanostores";
|
|
7
7
|
import * as _better_fetch_fetch0 from "@better-fetch/fetch";
|
|
@@ -12,7 +12,9 @@ export * from "@better-fetch/fetch";
|
|
|
12
12
|
//#region src/client/lynx/index.d.ts
|
|
13
13
|
type InferResolvedHooks<O extends BetterAuthClientOptions> = O extends {
|
|
14
14
|
plugins: Array<infer Plugin>;
|
|
15
|
-
} ? UnionToIntersection<Plugin extends
|
|
15
|
+
} ? UnionToIntersection<Plugin extends {
|
|
16
|
+
getAtoms?: infer GetAtoms;
|
|
17
|
+
} ? GetAtoms extends ((fetch: any) => infer Atoms) ? Atoms extends Record<string, any> ? { [key in keyof Atoms as IsSignal<key> extends true ? never : key extends string ? `use${Capitalize<key>}` : never]: () => ReturnType<Atoms[key]["get"]> } : {} : {} : {}> : {};
|
|
16
18
|
declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
|
|
17
19
|
useSession: () => {
|
|
18
20
|
data: InferClientAPI<Option> extends {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ExtractPluginField, HasRequiredKeys, InferPluginFieldFromTuple, IsAny, OverrideMerge, Prettify, PrettifyDeep, RequiredKeysOf, StripEmptyObjects, UnionToIntersection } from "../../types/helper.mjs";
|
|
2
2
|
import { InferActions, InferClientAPI, InferErrorCodes, IsSignal, SessionQueryParams } from "../types.mjs";
|
|
3
3
|
import { useStore } from "./react-store.mjs";
|
|
4
|
-
import { BetterAuthClientOptions
|
|
4
|
+
import { BetterAuthClientOptions } from "@better-auth/core";
|
|
5
5
|
import { BASE_ERROR_CODES } from "@better-auth/core/error";
|
|
6
6
|
import * as nanostores from "nanostores";
|
|
7
7
|
import * as _better_fetch_fetch0 from "@better-fetch/fetch";
|
|
@@ -12,7 +12,9 @@ export * from "@better-fetch/fetch";
|
|
|
12
12
|
//#region src/client/react/index.d.ts
|
|
13
13
|
type InferResolvedHooks<O extends BetterAuthClientOptions> = O extends {
|
|
14
14
|
plugins: Array<infer Plugin>;
|
|
15
|
-
} ? UnionToIntersection<Plugin extends
|
|
15
|
+
} ? UnionToIntersection<Plugin extends {
|
|
16
|
+
getAtoms?: infer GetAtoms;
|
|
17
|
+
} ? GetAtoms extends ((fetch: any) => infer Atoms) ? Atoms extends Record<string, any> ? { [key in keyof Atoms as IsSignal<key> extends true ? never : key extends string ? `use${Capitalize<key>}` : never]: () => ReturnType<Atoms[key]["get"]> } : {} : {} : {}> : {};
|
|
16
18
|
declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
|
|
17
19
|
useSession: () => {
|
|
18
20
|
data: InferClientAPI<Option> extends {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ExtractPluginField, HasRequiredKeys, InferPluginFieldFromTuple, IsAny, OverrideMerge, Prettify, PrettifyDeep, RequiredKeysOf, StripEmptyObjects, UnionToIntersection } from "../../types/helper.mjs";
|
|
2
2
|
import { InferActions, InferClientAPI, InferErrorCodes, IsSignal, SessionQueryParams } from "../types.mjs";
|
|
3
|
-
import { BetterAuthClientOptions
|
|
3
|
+
import { BetterAuthClientOptions } from "@better-auth/core";
|
|
4
4
|
import { BASE_ERROR_CODES } from "@better-auth/core/error";
|
|
5
5
|
import * as _better_fetch_fetch0 from "@better-fetch/fetch";
|
|
6
6
|
import { BetterFetchError } from "@better-fetch/fetch";
|
|
@@ -11,7 +11,9 @@ export * from "@better-fetch/fetch";
|
|
|
11
11
|
//#region src/client/solid/index.d.ts
|
|
12
12
|
type InferResolvedHooks<O extends BetterAuthClientOptions> = O extends {
|
|
13
13
|
plugins: Array<infer Plugin>;
|
|
14
|
-
} ? UnionToIntersection<Plugin extends
|
|
14
|
+
} ? UnionToIntersection<Plugin extends {
|
|
15
|
+
getAtoms?: infer GetAtoms;
|
|
16
|
+
} ? GetAtoms extends ((fetch: any) => infer Atoms) ? Atoms extends Record<string, any> ? { [key in keyof Atoms as IsSignal<key> extends true ? never : key extends string ? `use${Capitalize<key>}` : never]: () => Accessor<ReturnType<Atoms[key]["get"]>> } : {} : {} : {}> : {};
|
|
15
17
|
declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
|
|
16
18
|
useSession: () => Accessor<{
|
|
17
19
|
data: InferClientAPI<Option> extends {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ExtractPluginField, HasRequiredKeys, InferPluginFieldFromTuple, IsAny, OverrideMerge, Prettify, PrettifyDeep, RequiredKeysOf, StripEmptyObjects, UnionToIntersection } from "../../types/helper.mjs";
|
|
2
2
|
import { InferActions, InferClientAPI, InferErrorCodes, IsSignal, SessionQueryParams } from "../types.mjs";
|
|
3
|
-
import { BetterAuthClientOptions
|
|
3
|
+
import { BetterAuthClientOptions } from "@better-auth/core";
|
|
4
4
|
import { BASE_ERROR_CODES } from "@better-auth/core/error";
|
|
5
5
|
import * as nanostores from "nanostores";
|
|
6
6
|
import { Atom } from "nanostores";
|
|
@@ -12,7 +12,9 @@ export * from "@better-fetch/fetch";
|
|
|
12
12
|
//#region src/client/svelte/index.d.ts
|
|
13
13
|
type InferResolvedHooks<O extends BetterAuthClientOptions> = O extends {
|
|
14
14
|
plugins: Array<infer Plugin>;
|
|
15
|
-
} ? UnionToIntersection<Plugin extends
|
|
15
|
+
} ? UnionToIntersection<Plugin extends {
|
|
16
|
+
getAtoms?: infer GetAtoms;
|
|
17
|
+
} ? GetAtoms extends ((fetch: any) => infer Atoms) ? Atoms extends Record<string, any> ? { [key in keyof Atoms as IsSignal<key> extends true ? never : key extends string ? `use${Capitalize<key>}` : never]: () => Atoms[key] } : {} : {} : {}> : {};
|
|
16
18
|
declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
|
|
17
19
|
useSession: () => Atom<{
|
|
18
20
|
data: InferClientAPI<Option> extends {
|
package/dist/client/types.d.mts
CHANGED
|
@@ -3,25 +3,32 @@ import { StripEmptyObjects, UnionToIntersection } from "../types/helper.mjs";
|
|
|
3
3
|
import { InferRoutes } from "./path-to-object.mjs";
|
|
4
4
|
import { Session as Session$1, User as User$1 } from "../types/models.mjs";
|
|
5
5
|
import { Auth } from "../types/auth.mjs";
|
|
6
|
-
import { BetterAuthClientOptions as BetterAuthClientOptions$1, BetterAuthClientPlugin
|
|
7
|
-
import {
|
|
8
|
-
import { RawError } from "@better-auth/core/utils/error-codes";
|
|
6
|
+
import { BetterAuthClientOptions as BetterAuthClientOptions$1, BetterAuthClientPlugin, ClientAtomListener, ClientStore as ClientStore$1 } from "@better-auth/core";
|
|
7
|
+
import { DBFieldAttribute, InferDBFieldsOutput } from "@better-auth/core/db";
|
|
9
8
|
|
|
10
9
|
//#region src/client/types.d.ts
|
|
10
|
+
type ClientPluginError<K extends string = string> = {
|
|
11
|
+
readonly code: K;
|
|
12
|
+
message: string;
|
|
13
|
+
};
|
|
11
14
|
type InferPluginEndpoints<Plugins> = Plugins extends Array<infer Pl> ? UnionToIntersection<Pl extends {
|
|
12
|
-
$InferServerPlugin
|
|
15
|
+
$InferServerPlugin?: infer Plug;
|
|
13
16
|
} ? Plug extends {
|
|
14
|
-
endpoints
|
|
15
|
-
} ? Endpoints : {} : {}> : {};
|
|
17
|
+
endpoints?: infer Endpoints;
|
|
18
|
+
} ? Endpoints extends Record<string, unknown> ? Endpoints : {} : {} : {}> : {};
|
|
16
19
|
type InferClientAPI<O extends BetterAuthClientOptions$1> = InferRoutes<O["plugins"] extends Array<any> ? Omit<Auth["api"], keyof InferPluginEndpoints<O["plugins"]>> & InferPluginEndpoints<O["plugins"]> : Auth["api"], O>;
|
|
17
|
-
type InferActions<O extends BetterAuthClientOptions$1> = (O["plugins"] extends Array<infer Plugin> ? UnionToIntersection<Plugin extends
|
|
20
|
+
type InferActions<O extends BetterAuthClientOptions$1> = (O["plugins"] extends Array<infer Plugin> ? UnionToIntersection<Plugin extends {
|
|
21
|
+
getActions?: infer GetActions;
|
|
22
|
+
} ? GetActions extends ((...args: any) => infer Actions) ? Actions : {} : {}> : {}) & InferRoutes<O["$InferAuth"] extends {
|
|
18
23
|
plugins: infer Plugins;
|
|
19
24
|
} ? Plugins extends Array<infer Plugin> ? Plugin extends {
|
|
20
|
-
endpoints
|
|
21
|
-
} ? Endpoints : {} : {} : {}, O>;
|
|
22
|
-
type InferErrorCodes<O extends BetterAuthClientOptions$1> = O["plugins"] extends Array<infer Plugin> ? UnionToIntersection<Plugin extends
|
|
23
|
-
$
|
|
24
|
-
} ?
|
|
25
|
+
endpoints?: infer Endpoints;
|
|
26
|
+
} ? Endpoints extends Record<string, unknown> ? Endpoints : {} : {} : {} : {}, O>;
|
|
27
|
+
type InferErrorCodes<O extends BetterAuthClientOptions$1> = O["plugins"] extends Array<infer Plugin> ? UnionToIntersection<Plugin extends {
|
|
28
|
+
$InferServerPlugin?: infer ServerPlugin;
|
|
29
|
+
} ? ServerPlugin extends {
|
|
30
|
+
$ERROR_CODES?: infer E;
|
|
31
|
+
} ? { [K in keyof E & string]: E[K] extends ClientPluginError ? ClientPluginError<K> : never } : {} : {}> : {};
|
|
25
32
|
/**
|
|
26
33
|
* signals are just used to recall a computed value.
|
|
27
34
|
* as a convention they start with "$"
|
|
@@ -29,12 +36,16 @@ type InferErrorCodes<O extends BetterAuthClientOptions$1> = O["plugins"] extends
|
|
|
29
36
|
type IsSignal<T> = T extends `$${infer _}` ? true : false;
|
|
30
37
|
type InferSessionFromClient<O extends BetterAuthClientOptions$1> = StripEmptyObjects<Session$1 & UnionToIntersection<InferAdditionalFromClient<O, "session", "output">>>;
|
|
31
38
|
type InferUserFromClient<O extends BetterAuthClientOptions$1> = StripEmptyObjects<User$1 & UnionToIntersection<InferAdditionalFromClient<O, "user", "output">>>;
|
|
32
|
-
type InferAdditionalFromClient<Options extends BetterAuthClientOptions$1, Key extends string, Format extends "input" | "output" = "output"> = Options["plugins"] extends Array<infer Plugin> ? Plugin extends
|
|
33
|
-
|
|
34
|
-
} ?
|
|
39
|
+
type InferAdditionalFromClient<Options extends BetterAuthClientOptions$1, Key extends string, Format extends "input" | "output" = "output"> = Options["plugins"] extends Array<infer Plugin> ? Plugin extends {
|
|
40
|
+
$InferServerPlugin?: infer ServerPlugin;
|
|
41
|
+
} ? ServerPlugin extends {
|
|
42
|
+
schema?: infer Schema;
|
|
43
|
+
} ? Schema extends Record<Key, {
|
|
44
|
+
fields: infer Fields;
|
|
45
|
+
}> ? Fields extends Record<string, DBFieldAttribute> ? Format extends "input" ? InferFieldsInputClient<Fields> : InferDBFieldsOutput<Fields> : {} : {} : {} : {} : {};
|
|
35
46
|
type SessionQueryParams = {
|
|
36
47
|
disableCookieCache?: boolean | undefined;
|
|
37
48
|
disableRefresh?: boolean | undefined;
|
|
38
49
|
};
|
|
39
50
|
//#endregion
|
|
40
|
-
export { type BetterAuthClientOptions$1 as BetterAuthClientOptions, type BetterAuthClientPlugin
|
|
51
|
+
export { type BetterAuthClientOptions$1 as BetterAuthClientOptions, type BetterAuthClientPlugin, type ClientAtomListener, type ClientStore$1 as ClientStore, InferActions, InferAdditionalFromClient, InferClientAPI, InferErrorCodes, InferSessionFromClient, InferUserFromClient, IsSignal, SessionQueryParams };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PrettifyDeep, UnionToIntersection } from "../types/helper.mjs";
|
|
2
2
|
import { InferActions, InferClientAPI, InferErrorCodes, IsSignal, SessionQueryParams } from "./types.mjs";
|
|
3
|
-
import { BetterAuthClientOptions
|
|
3
|
+
import { BetterAuthClientOptions } from "@better-auth/core";
|
|
4
4
|
import { BASE_ERROR_CODES } from "@better-auth/core/error";
|
|
5
5
|
import * as nanostores from "nanostores";
|
|
6
6
|
import { Atom } from "nanostores";
|
|
@@ -10,7 +10,9 @@ import { BetterFetchError } from "@better-fetch/fetch";
|
|
|
10
10
|
//#region src/client/vanilla.d.ts
|
|
11
11
|
type InferResolvedHooks<O extends BetterAuthClientOptions> = O extends {
|
|
12
12
|
plugins: Array<infer Plugin>;
|
|
13
|
-
} ? UnionToIntersection<Plugin extends
|
|
13
|
+
} ? UnionToIntersection<Plugin extends {
|
|
14
|
+
getAtoms?: infer GetAtoms;
|
|
15
|
+
} ? GetAtoms extends ((fetch: any) => infer Atoms) ? Atoms extends Record<string, any> ? { [key in keyof Atoms as IsSignal<key> extends true ? never : key extends string ? `use${Capitalize<key>}` : never]: Atoms[key] } : {} : {} : {}> : {};
|
|
14
16
|
declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
|
|
15
17
|
useSession: Atom<{
|
|
16
18
|
data: InferClientAPI<Option> extends {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ExtractPluginField, HasRequiredKeys, InferPluginFieldFromTuple, IsAny, OverrideMerge, Prettify, PrettifyDeep, RequiredKeysOf, StripEmptyObjects, UnionToIntersection } from "../../types/helper.mjs";
|
|
2
2
|
import { InferActions, InferClientAPI, InferErrorCodes, IsSignal, SessionQueryParams } from "../types.mjs";
|
|
3
|
-
import { BetterAuthClientOptions
|
|
3
|
+
import { BetterAuthClientOptions } from "@better-auth/core";
|
|
4
4
|
import { BASE_ERROR_CODES } from "@better-auth/core/error";
|
|
5
5
|
import * as nanostores from "nanostores";
|
|
6
6
|
import * as _better_fetch_fetch0 from "@better-fetch/fetch";
|
|
@@ -12,7 +12,9 @@ export * from "@better-fetch/fetch";
|
|
|
12
12
|
//#region src/client/vue/index.d.ts
|
|
13
13
|
type InferResolvedHooks<O extends BetterAuthClientOptions> = O extends {
|
|
14
14
|
plugins: Array<infer Plugin>;
|
|
15
|
-
} ? UnionToIntersection<Plugin extends
|
|
15
|
+
} ? UnionToIntersection<Plugin extends {
|
|
16
|
+
getAtoms?: infer GetAtoms;
|
|
17
|
+
} ? GetAtoms extends ((fetch: any) => infer Atoms) ? Atoms extends Record<string, any> ? { [key in keyof Atoms as IsSignal<key> extends true ? never : key extends string ? `use${Capitalize<key>}` : never]: () => DeepReadonly<Ref<ReturnType<Atoms[key]["get"]>>> } : {} : {} : {}> : {};
|
|
16
18
|
declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
|
|
17
19
|
useSession: {
|
|
18
20
|
(): DeepReadonly<Ref<{
|
package/dist/package.mjs
CHANGED
package/dist/plugins/index.d.mts
CHANGED
|
@@ -48,7 +48,7 @@ import { OAUTH_POPUP_COMPLETE_SCRIPT, OAUTH_POPUP_SCRIPT_CSP_HASH, oauthPopup }
|
|
|
48
48
|
import { OAuthProxyOptions, oAuthProxy } from "./oauth-proxy/index.mjs";
|
|
49
49
|
import { OneTapOptions, oneTap } from "./one-tap/index.mjs";
|
|
50
50
|
import { OneTimeTokenOptions, oneTimeToken } from "./one-time-token/index.mjs";
|
|
51
|
-
import { FieldSchema, OpenAPIModelSchema, Path, generator } from "./open-api/generator.mjs";
|
|
51
|
+
import { FieldSchema, OpenAPIModelSchema, OpenAPIParameter, OpenAPISchema, Path, generator } from "./open-api/generator.mjs";
|
|
52
52
|
import { OpenAPIOptions, openAPI } from "./open-api/index.mjs";
|
|
53
53
|
import { PhoneNumberOptions, UserWithPhoneNumber } from "./phone-number/types.mjs";
|
|
54
54
|
import { phoneNumber } from "./phone-number/index.mjs";
|
|
@@ -66,4 +66,4 @@ import { USERNAME_ERROR_CODES } from "./username/error-codes.mjs";
|
|
|
66
66
|
import { UsernameOptions, username } from "./username/index.mjs";
|
|
67
67
|
import { hasPermission } from "./organization/has-permission.mjs";
|
|
68
68
|
import { DefaultOrganizationPlugin, DynamicAccessControlEndpoints, OrganizationCreator, OrganizationEndpoints, OrganizationPlugin, TeamEndpoints, organization, parseRoles } from "./organization/organization.mjs";
|
|
69
|
-
export { AccessControl, AdminOptions, AnonymousOptions, AnonymousSession, ArrayElement, Auth0Options, AuthorizationQuery, AuthorizeResponse, BackupCodeOptions, BaseCaptchaOptions, BaseOAuthProviderOptions, BearerOptions, CaptchaFoxOptions, CaptchaOptions, Client, CloudflareTurnstileOptions, CodeVerificationValue, CustomSessionPluginOptions, DefaultOrganizationPlugin, DeviceAuthorizationOptions, DynamicAccessControlEndpoints, MULTI_SESSION_ERROR_CODES as ERROR_CODES, EmailOTPOptions, ExactRoleStatements, FieldSchema, GenericOAuthConfig, GenericOAuthOptions, GoogleRecaptchaOptions, GumroadOptions, HCaptchaOptions, HIDE_METADATA, HaveIBeenPwnedOptions, HubSpotOptions, InferAdminRolesFromOption, InferInvitation, InferMember, InferOptionSchema, InferOrganization, InferOrganizationRolesFromOption, InferOrganizationZodRolesFromOption, InferPluginContext, InferPluginErrorCodes, InferPluginIDs, InferTeam, Invitation, InvitationInput, InvitationStatus, JWKOptions, JWSAlgorithms, Jwk, JwtOptions, KeycloakOptions, LastLoginMethodOptions, LineOptions, LoginResult, MagicLinkOptions, Member, MemberInput, MicrosoftEntraIdOptions, MultiSessionConfig, OAUTH_POPUP_COMPLETE_SCRIPT, OAUTH_POPUP_DATA_ELEMENT_ID, OAUTH_POPUP_ERROR_CODES, OAUTH_POPUP_MESSAGE_TYPE, OAUTH_POPUP_SCRIPT_CSP_HASH, OAuthAccessToken, OAuthPopupData, OAuthPopupMessage, OAuthProxyOptions, OIDCMetadata, OIDCOptions, OTPOptions, OktaOptions, OneTapOptions, OneTimeTokenOptions, OpenAPIModelSchema, OpenAPIOptions, Organization, OrganizationCreator, OrganizationEndpoints, OrganizationInput, OrganizationOptions, OrganizationPlugin, OrganizationRole, OrganizationSchema, POPUP_MARKER_COOKIE, Path, PatreonOptions, PhoneNumberOptions, Provider, Role, RoleAuthorizeRequest, RoleInput, RoleStatements, SIWEPluginOptions, SessionWithImpersonatedBy, SlackOptions, Statements, SubArray, Subset, TOTPOptions, TWO_FACTOR_ERROR_CODES, Team, TeamEndpoints, TeamInput, TeamMember, TeamMemberInput, TestCookie, TestHelpers, TestUtilsOptions, TimeString, TokenBody, TwoFactorOptions, TwoFactorProvider, TwoFactorTable, USERNAME_ERROR_CODES, UserWithAnonymous, UserWithPhoneNumber, UserWithRole, UserWithTwoFactor, UsernameOptions, admin, anonymous, auth0, backupCode2fa, bearer, captcha, createAccessControl, createJwk, customSession, defaultRolesSchema, deviceAuthorization, deviceAuthorizationOptionsSchema, emailOTP, encodeBackupCodes, generateBackupCodes, generateExportedKeyPair, generator, genericOAuth, getBackupCodes, getClient, getJwtToken, getMCPProtectedResourceMetadata, getMCPProviderMetadata, getMetadata, getOrgAdapter, gumroad, hasPermission, haveIBeenPwned, hubspot, invitationSchema, invitationStatus, jwt, keycloak, lastLoginMethod, line, magicLink, mcp, memberSchema, microsoftEntraId, ms, multiSession, oAuthDiscoveryMetadata, oAuthProtectedResourceMetadata, oAuthProxy, oauthPopup, oidcProvider, okta, oneTap, oneTimeToken, openAPI, organization, organizationRoleSchema, organizationSchema, otp2fa, parseRoles, patreon, phoneNumber, role, roleSchema, sec, signJWT, siwe, slack, teamMemberSchema, teamSchema, testUtils, toExpJWT, totp2fa, twoFactor, twoFactorClient, username, verifyBackupCode, verifyJWT, withMcpAuth };
|
|
69
|
+
export { AccessControl, AdminOptions, AnonymousOptions, AnonymousSession, ArrayElement, Auth0Options, AuthorizationQuery, AuthorizeResponse, BackupCodeOptions, BaseCaptchaOptions, BaseOAuthProviderOptions, BearerOptions, CaptchaFoxOptions, CaptchaOptions, Client, CloudflareTurnstileOptions, CodeVerificationValue, CustomSessionPluginOptions, DefaultOrganizationPlugin, DeviceAuthorizationOptions, DynamicAccessControlEndpoints, MULTI_SESSION_ERROR_CODES as ERROR_CODES, EmailOTPOptions, ExactRoleStatements, FieldSchema, GenericOAuthConfig, GenericOAuthOptions, GoogleRecaptchaOptions, GumroadOptions, HCaptchaOptions, HIDE_METADATA, HaveIBeenPwnedOptions, HubSpotOptions, InferAdminRolesFromOption, InferInvitation, InferMember, InferOptionSchema, InferOrganization, InferOrganizationRolesFromOption, InferOrganizationZodRolesFromOption, InferPluginContext, InferPluginErrorCodes, InferPluginIDs, InferTeam, Invitation, InvitationInput, InvitationStatus, JWKOptions, JWSAlgorithms, Jwk, JwtOptions, KeycloakOptions, LastLoginMethodOptions, LineOptions, LoginResult, MagicLinkOptions, Member, MemberInput, MicrosoftEntraIdOptions, MultiSessionConfig, OAUTH_POPUP_COMPLETE_SCRIPT, OAUTH_POPUP_DATA_ELEMENT_ID, OAUTH_POPUP_ERROR_CODES, OAUTH_POPUP_MESSAGE_TYPE, OAUTH_POPUP_SCRIPT_CSP_HASH, OAuthAccessToken, OAuthPopupData, OAuthPopupMessage, OAuthProxyOptions, OIDCMetadata, OIDCOptions, OTPOptions, OktaOptions, OneTapOptions, OneTimeTokenOptions, OpenAPIModelSchema, OpenAPIOptions, OpenAPIParameter, OpenAPISchema, Organization, OrganizationCreator, OrganizationEndpoints, OrganizationInput, OrganizationOptions, OrganizationPlugin, OrganizationRole, OrganizationSchema, POPUP_MARKER_COOKIE, Path, PatreonOptions, PhoneNumberOptions, Provider, Role, RoleAuthorizeRequest, RoleInput, RoleStatements, SIWEPluginOptions, SessionWithImpersonatedBy, SlackOptions, Statements, SubArray, Subset, TOTPOptions, TWO_FACTOR_ERROR_CODES, Team, TeamEndpoints, TeamInput, TeamMember, TeamMemberInput, TestCookie, TestHelpers, TestUtilsOptions, TimeString, TokenBody, TwoFactorOptions, TwoFactorProvider, TwoFactorTable, USERNAME_ERROR_CODES, UserWithAnonymous, UserWithPhoneNumber, UserWithRole, UserWithTwoFactor, UsernameOptions, admin, anonymous, auth0, backupCode2fa, bearer, captcha, createAccessControl, createJwk, customSession, defaultRolesSchema, deviceAuthorization, deviceAuthorizationOptionsSchema, emailOTP, encodeBackupCodes, generateBackupCodes, generateExportedKeyPair, generator, genericOAuth, getBackupCodes, getClient, getJwtToken, getMCPProtectedResourceMetadata, getMCPProviderMetadata, getMetadata, getOrgAdapter, gumroad, hasPermission, haveIBeenPwned, hubspot, invitationSchema, invitationStatus, jwt, keycloak, lastLoginMethod, line, magicLink, mcp, memberSchema, microsoftEntraId, ms, multiSession, oAuthDiscoveryMetadata, oAuthProtectedResourceMetadata, oAuthProxy, oauthPopup, oidcProvider, okta, oneTap, oneTimeToken, openAPI, organization, organizationRoleSchema, organizationSchema, otp2fa, parseRoles, patreon, phoneNumber, role, roleSchema, sec, signJWT, siwe, slack, teamMemberSchema, teamSchema, testUtils, toExpJWT, totp2fa, twoFactor, twoFactorClient, username, verifyBackupCode, verifyJWT, withMcpAuth };
|
|
@@ -4,63 +4,72 @@ import { OpenAPIParameter, OpenAPISchemaType } from "better-call";
|
|
|
4
4
|
|
|
5
5
|
//#region src/plugins/open-api/generator.d.ts
|
|
6
6
|
interface Path {
|
|
7
|
-
get?:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
bearerAuth: string[];
|
|
13
|
-
}];
|
|
14
|
-
parameters?: OpenAPIParameter[];
|
|
15
|
-
responses?: { [key in string]: {
|
|
16
|
-
description?: string;
|
|
17
|
-
content: {
|
|
18
|
-
"application/json": {
|
|
19
|
-
schema: {
|
|
20
|
-
type?: OpenAPISchemaType;
|
|
21
|
-
properties?: Record<string, any>;
|
|
22
|
-
required?: string[];
|
|
23
|
-
$ref?: string;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
} };
|
|
28
|
-
} | undefined;
|
|
29
|
-
post?: {
|
|
30
|
-
tags?: string[];
|
|
31
|
-
operationId?: string;
|
|
32
|
-
description?: string;
|
|
33
|
-
security?: [{
|
|
34
|
-
bearerAuth: string[];
|
|
35
|
-
}];
|
|
36
|
-
parameters?: OpenAPIParameter[];
|
|
37
|
-
requestBody?: {
|
|
38
|
-
content: {
|
|
39
|
-
"application/json": {
|
|
40
|
-
schema: {
|
|
41
|
-
type?: OpenAPISchemaType;
|
|
42
|
-
properties?: Record<string, any>;
|
|
43
|
-
required?: string[];
|
|
44
|
-
$ref?: string;
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
responses?: { [key in string]: {
|
|
50
|
-
description?: string;
|
|
51
|
-
content: {
|
|
52
|
-
"application/json": {
|
|
53
|
-
schema: {
|
|
54
|
-
type?: OpenAPISchemaType;
|
|
55
|
-
properties?: Record<string, any>;
|
|
56
|
-
required?: string[];
|
|
57
|
-
$ref?: string;
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
} };
|
|
62
|
-
} | undefined;
|
|
7
|
+
get?: OpenAPIOperation | undefined;
|
|
8
|
+
post?: OpenAPIOperation | undefined;
|
|
9
|
+
put?: OpenAPIOperation | undefined;
|
|
10
|
+
patch?: OpenAPIOperation | undefined;
|
|
11
|
+
delete?: OpenAPIOperation | undefined;
|
|
63
12
|
}
|
|
13
|
+
type OpenAPISchemaPrimitiveType = OpenAPISchemaType | "null";
|
|
14
|
+
type OpenAPISchema = {
|
|
15
|
+
type?: OpenAPISchemaPrimitiveType | OpenAPISchemaPrimitiveType[];
|
|
16
|
+
properties?: Record<string, OpenAPISchema>;
|
|
17
|
+
required?: string[];
|
|
18
|
+
$ref?: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
default?: unknown;
|
|
21
|
+
readOnly?: boolean;
|
|
22
|
+
format?: string;
|
|
23
|
+
deprecated?: boolean;
|
|
24
|
+
enum?: unknown[];
|
|
25
|
+
items?: OpenAPISchema;
|
|
26
|
+
minLength?: number;
|
|
27
|
+
maxLength?: number;
|
|
28
|
+
minimum?: number;
|
|
29
|
+
maximum?: number;
|
|
30
|
+
additionalProperties?: boolean | OpenAPISchema;
|
|
31
|
+
propertyNames?: OpenAPISchema;
|
|
32
|
+
allOf?: OpenAPISchema[];
|
|
33
|
+
anyOf?: OpenAPISchema[];
|
|
34
|
+
oneOf?: OpenAPISchema[];
|
|
35
|
+
const?: unknown;
|
|
36
|
+
example?: unknown;
|
|
37
|
+
};
|
|
38
|
+
type OpenAPIParameter$1 = Omit<OpenAPIParameter, "schema"> & {
|
|
39
|
+
schema?: OpenAPISchema;
|
|
40
|
+
};
|
|
41
|
+
type OpenAPIMediaTypeObject = {
|
|
42
|
+
schema?: OpenAPISchema;
|
|
43
|
+
};
|
|
44
|
+
type OpenAPIResponseContent = {
|
|
45
|
+
"application/json"?: OpenAPIMediaTypeObject;
|
|
46
|
+
"text/plain"?: OpenAPIMediaTypeObject;
|
|
47
|
+
"text/html"?: OpenAPIMediaTypeObject;
|
|
48
|
+
[contentType: string]: OpenAPIMediaTypeObject | undefined;
|
|
49
|
+
};
|
|
50
|
+
type OpenAPIResponse = {
|
|
51
|
+
description?: string;
|
|
52
|
+
content?: OpenAPIResponseContent;
|
|
53
|
+
};
|
|
54
|
+
type OpenAPIRequestBody = {
|
|
55
|
+
required?: boolean;
|
|
56
|
+
content: {
|
|
57
|
+
"application/json": {
|
|
58
|
+
schema: OpenAPISchema;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
type OpenAPIOperation = {
|
|
63
|
+
tags?: string[];
|
|
64
|
+
operationId?: string;
|
|
65
|
+
description?: string;
|
|
66
|
+
security?: [{
|
|
67
|
+
bearerAuth: string[];
|
|
68
|
+
}];
|
|
69
|
+
parameters?: OpenAPIParameter$1[];
|
|
70
|
+
requestBody?: OpenAPIRequestBody;
|
|
71
|
+
responses?: Record<string, OpenAPIResponse>;
|
|
72
|
+
};
|
|
64
73
|
type FieldSchema = {
|
|
65
74
|
type: DBFieldType;
|
|
66
75
|
default?: (DBFieldAttributeConfig["defaultValue"] | "Generated at runtime") | undefined;
|
|
@@ -111,4 +120,4 @@ declare function generator(ctx: AuthContext, options: BetterAuthOptions): Promis
|
|
|
111
120
|
paths: Record<string, Path>;
|
|
112
121
|
}>;
|
|
113
122
|
//#endregion
|
|
114
|
-
export { FieldSchema, OpenAPIModelSchema, Path, generator };
|
|
123
|
+
export { FieldSchema, OpenAPIModelSchema, OpenAPIParameter$1 as OpenAPIParameter, OpenAPISchema, Path, generator };
|
|
@@ -3,17 +3,17 @@ import { getEndpoints } from "../../api/index.mjs";
|
|
|
3
3
|
import * as z from "zod";
|
|
4
4
|
import { toPascalCase } from "@better-auth/core/utils/string";
|
|
5
5
|
//#region src/plugins/open-api/generator.ts
|
|
6
|
-
const
|
|
6
|
+
const OPEN_API_SCHEMA_TYPES = new Set([
|
|
7
7
|
"string",
|
|
8
8
|
"number",
|
|
9
9
|
"boolean",
|
|
10
10
|
"array",
|
|
11
11
|
"object"
|
|
12
12
|
]);
|
|
13
|
-
function
|
|
14
|
-
if (zodType instanceof z.ZodDefault) return
|
|
13
|
+
function getOpenApiTypeFromZodType(zodType) {
|
|
14
|
+
if (zodType instanceof z.ZodDefault || zodType instanceof z.ZodPrefault) return getOpenApiTypeFromZodType(unwrapZodSchema(zodType));
|
|
15
15
|
const type = zodType.type;
|
|
16
|
-
return
|
|
16
|
+
return OPEN_API_SCHEMA_TYPES.has(type) ? type : "string";
|
|
17
17
|
}
|
|
18
18
|
function getFieldSchema(field) {
|
|
19
19
|
const schema = {
|
|
@@ -24,6 +24,48 @@ function getFieldSchema(field) {
|
|
|
24
24
|
if (field.input === false) schema.readOnly = true;
|
|
25
25
|
return schema;
|
|
26
26
|
}
|
|
27
|
+
function asZodSchema(schema) {
|
|
28
|
+
return schema;
|
|
29
|
+
}
|
|
30
|
+
function unwrapZodSchema(zodType) {
|
|
31
|
+
return asZodSchema(zodType.unwrap());
|
|
32
|
+
}
|
|
33
|
+
function getZodDef(zodType) {
|
|
34
|
+
return zodType._def;
|
|
35
|
+
}
|
|
36
|
+
function getZodDescription(zodType) {
|
|
37
|
+
return zodType.description;
|
|
38
|
+
}
|
|
39
|
+
function withDescription(schema, zodType) {
|
|
40
|
+
const description = getZodDescription(zodType);
|
|
41
|
+
return description ? {
|
|
42
|
+
...schema,
|
|
43
|
+
description
|
|
44
|
+
} : schema;
|
|
45
|
+
}
|
|
46
|
+
function addNullType(schema) {
|
|
47
|
+
if (schema.type) {
|
|
48
|
+
const type = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
49
|
+
const nullableType = Array.from(new Set([...type, "null"]));
|
|
50
|
+
return {
|
|
51
|
+
...schema,
|
|
52
|
+
type: nullableType
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return { anyOf: [schema, { type: "null" }] };
|
|
56
|
+
}
|
|
57
|
+
function getZodStringSchemaConstraints(zodType) {
|
|
58
|
+
const minLength = zodType.minLength;
|
|
59
|
+
const maxLength = zodType.maxLength;
|
|
60
|
+
return {
|
|
61
|
+
...typeof minLength === "number" ? { minLength } : {},
|
|
62
|
+
...typeof maxLength === "number" ? { maxLength } : {}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function getZodPipeSchema(zodType) {
|
|
66
|
+
const def = getZodDef(zodType);
|
|
67
|
+
return def.in instanceof z.ZodTransform && def.out instanceof z.ZodType ? def.out : def.in;
|
|
68
|
+
}
|
|
27
69
|
function getParameters(options) {
|
|
28
70
|
const parameters = [];
|
|
29
71
|
if (options.metadata?.openapi?.parameters) {
|
|
@@ -31,62 +73,93 @@ function getParameters(options) {
|
|
|
31
73
|
return parameters;
|
|
32
74
|
}
|
|
33
75
|
if (options.query instanceof z.ZodObject) Object.entries(options.query.shape).forEach(([key, value]) => {
|
|
34
|
-
if (value instanceof z.ZodType)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
}
|
|
76
|
+
if (value instanceof z.ZodType) {
|
|
77
|
+
const parameterSchema = toOpenApiSchema(value);
|
|
78
|
+
parameters.push({
|
|
79
|
+
name: key,
|
|
80
|
+
in: "query",
|
|
81
|
+
schema: parameterSchema
|
|
82
|
+
});
|
|
83
|
+
}
|
|
42
84
|
});
|
|
43
85
|
return parameters;
|
|
44
86
|
}
|
|
87
|
+
function getRequestBodySchemaInfo(zodType) {
|
|
88
|
+
return {
|
|
89
|
+
required: !schemaAcceptsUndefined(zodType),
|
|
90
|
+
schema: zodType
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function schemaAcceptsUndefined(zodType) {
|
|
94
|
+
if (zodType instanceof z.ZodOptional || zodType instanceof z.ZodDefault || zodType instanceof z.ZodPrefault || zodType instanceof z.ZodCatch || zodType instanceof z.ZodUndefined || zodType instanceof z.ZodVoid) return true;
|
|
95
|
+
if (zodType instanceof z.ZodNonOptional) return false;
|
|
96
|
+
if (zodType instanceof z.ZodNullable || zodType instanceof z.ZodReadonly) return schemaAcceptsUndefined(unwrapZodSchema(zodType));
|
|
97
|
+
if (zodType instanceof z.ZodPipe) return schemaAcceptsUndefined(getZodPipeSchema(zodType));
|
|
98
|
+
if (zodType instanceof z.ZodUnion) return getZodDef(zodType).options.some((option) => schemaAcceptsUndefined(option));
|
|
99
|
+
if (zodType instanceof z.ZodIntersection) {
|
|
100
|
+
const def = getZodDef(zodType);
|
|
101
|
+
return schemaAcceptsUndefined(def.left) && schemaAcceptsUndefined(def.right);
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
function isUndefinedOnlySchema(zodType) {
|
|
106
|
+
return zodType instanceof z.ZodUndefined || zodType instanceof z.ZodVoid;
|
|
107
|
+
}
|
|
108
|
+
function isMergeableObjectSchema(schema) {
|
|
109
|
+
const type = schema?.type;
|
|
110
|
+
return !!schema && (type === "object" || Array.isArray(type) && type.includes("object")) && schema.$ref === void 0 && schema.allOf === void 0 && schema.anyOf === void 0;
|
|
111
|
+
}
|
|
112
|
+
function schemaAllowsNull(schema) {
|
|
113
|
+
const type = schema?.type;
|
|
114
|
+
return Array.isArray(type) && type.includes("null");
|
|
115
|
+
}
|
|
116
|
+
function areSchemasEqual(left, right) {
|
|
117
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
118
|
+
}
|
|
119
|
+
function areSchemaMembersCompatible(left, right) {
|
|
120
|
+
if (left === void 0 || right === void 0) return true;
|
|
121
|
+
if (typeof left === "boolean" || typeof right === "boolean") return left === right;
|
|
122
|
+
return areSchemasEqual(left, right);
|
|
123
|
+
}
|
|
124
|
+
function mergeObjectSchemas(left, right, description) {
|
|
125
|
+
const properties = { ...left.properties || {} };
|
|
126
|
+
for (const [key, value] of Object.entries(right.properties || {})) {
|
|
127
|
+
if (properties[key] !== void 0 && !areSchemasEqual(properties[key], value)) return;
|
|
128
|
+
properties[key] = value;
|
|
129
|
+
}
|
|
130
|
+
const required = Array.from(new Set([...left.required || [], ...right.required || []]));
|
|
131
|
+
const leftAdditionalProperties = left.additionalProperties;
|
|
132
|
+
const rightAdditionalProperties = right.additionalProperties;
|
|
133
|
+
if (!areSchemaMembersCompatible(leftAdditionalProperties, rightAdditionalProperties)) return;
|
|
134
|
+
const leftPropertyNames = left.propertyNames;
|
|
135
|
+
const rightPropertyNames = right.propertyNames;
|
|
136
|
+
if (!areSchemaMembersCompatible(leftPropertyNames, rightPropertyNames)) return;
|
|
137
|
+
const additionalProperties = leftAdditionalProperties ?? rightAdditionalProperties;
|
|
138
|
+
const propertyNames = leftPropertyNames ?? rightPropertyNames;
|
|
139
|
+
return {
|
|
140
|
+
type: schemaAllowsNull(left) && schemaAllowsNull(right) ? ["object", "null"] : "object",
|
|
141
|
+
...Object.keys(properties).length > 0 ? { properties } : {},
|
|
142
|
+
...required.length > 0 ? { required } : {},
|
|
143
|
+
...additionalProperties !== void 0 ? { additionalProperties } : {},
|
|
144
|
+
...propertyNames !== void 0 ? { propertyNames } : {},
|
|
145
|
+
...description ?? left.description ?? right.description ? { description: description ?? left.description ?? right.description } : {}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
45
148
|
function getRequestBody(options) {
|
|
46
149
|
if (options.metadata?.openapi?.requestBody) return options.metadata.openapi.requestBody;
|
|
47
150
|
if (!options.body) return void 0;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (value instanceof z.ZodType) {
|
|
55
|
-
properties[key] = processZodType(value);
|
|
56
|
-
if (!(value instanceof z.ZodOptional)) required.push(key);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
return {
|
|
60
|
-
required: options.body instanceof z.ZodOptional ? false : options.body ? true : false,
|
|
61
|
-
content: { "application/json": { schema: {
|
|
62
|
-
type: "object",
|
|
63
|
-
properties,
|
|
64
|
-
required
|
|
65
|
-
} } }
|
|
66
|
-
};
|
|
67
|
-
}
|
|
151
|
+
const requestBodySchemaInfo = getRequestBodySchemaInfo(options.body);
|
|
152
|
+
const schema = toOpenApiSchema(requestBodySchemaInfo.schema);
|
|
153
|
+
return {
|
|
154
|
+
required: requestBodySchemaInfo.required,
|
|
155
|
+
content: { "application/json": { schema } }
|
|
156
|
+
};
|
|
68
157
|
}
|
|
69
|
-
function
|
|
70
|
-
if (zodType instanceof z.ZodOptional)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return {
|
|
75
|
-
...innerSchema,
|
|
76
|
-
type: Array.from(new Set([...type, "null"]))
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
return { anyOf: [innerSchema, { type: "null" }] };
|
|
80
|
-
}
|
|
81
|
-
if (zodType instanceof z.ZodDefault) {
|
|
82
|
-
const innerSchema = processZodType(zodType.unwrap());
|
|
83
|
-
const defaultValueDef = zodType._def.defaultValue;
|
|
84
|
-
const defaultValue = typeof defaultValueDef === "function" ? defaultValueDef() : defaultValueDef;
|
|
85
|
-
return {
|
|
86
|
-
...innerSchema,
|
|
87
|
-
default: defaultValue
|
|
88
|
-
};
|
|
89
|
-
}
|
|
158
|
+
function toOpenApiSchema(zodType) {
|
|
159
|
+
if (zodType instanceof z.ZodOptional) return toOpenApiSchema(unwrapZodSchema(zodType));
|
|
160
|
+
if (zodType instanceof z.ZodNullable) return addNullType(toOpenApiSchema(unwrapZodSchema(zodType)));
|
|
161
|
+
if (zodType instanceof z.ZodDefault || zodType instanceof z.ZodPrefault || zodType instanceof z.ZodNonOptional) return toOpenApiSchema(unwrapZodSchema(zodType));
|
|
162
|
+
if (zodType instanceof z.ZodAny) return withDescription({}, zodType);
|
|
90
163
|
if (zodType instanceof z.ZodObject) {
|
|
91
164
|
const shape = zodType.shape;
|
|
92
165
|
if (shape) {
|
|
@@ -94,22 +167,64 @@ function processZodType(zodType) {
|
|
|
94
167
|
const required = [];
|
|
95
168
|
Object.entries(shape).forEach(([key, value]) => {
|
|
96
169
|
if (value instanceof z.ZodType) {
|
|
97
|
-
properties[key] =
|
|
98
|
-
if (!(value
|
|
170
|
+
properties[key] = toOpenApiSchema(value);
|
|
171
|
+
if (!schemaAcceptsUndefined(value)) required.push(key);
|
|
99
172
|
}
|
|
100
173
|
});
|
|
101
|
-
return {
|
|
174
|
+
return withDescription({
|
|
102
175
|
type: "object",
|
|
103
176
|
properties,
|
|
104
|
-
...required.length > 0 ? { required } : {}
|
|
105
|
-
|
|
106
|
-
};
|
|
177
|
+
...required.length > 0 ? { required } : {}
|
|
178
|
+
}, zodType);
|
|
107
179
|
}
|
|
108
180
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
181
|
+
if (zodType instanceof z.ZodRecord) {
|
|
182
|
+
const def = getZodDef(zodType);
|
|
183
|
+
return withDescription({
|
|
184
|
+
type: "object",
|
|
185
|
+
propertyNames: toOpenApiSchema(def.keyType),
|
|
186
|
+
additionalProperties: toOpenApiSchema(def.valueType)
|
|
187
|
+
}, zodType);
|
|
188
|
+
}
|
|
189
|
+
if (zodType instanceof z.ZodIntersection) {
|
|
190
|
+
const def = getZodDef(zodType);
|
|
191
|
+
const leftSchema = toOpenApiSchema(def.left);
|
|
192
|
+
const rightSchema = toOpenApiSchema(def.right);
|
|
193
|
+
if (isMergeableObjectSchema(leftSchema) && isMergeableObjectSchema(rightSchema)) {
|
|
194
|
+
const mergedSchema = mergeObjectSchemas(leftSchema, rightSchema, getZodDescription(zodType));
|
|
195
|
+
if (mergedSchema) return mergedSchema;
|
|
196
|
+
}
|
|
197
|
+
return withDescription({ allOf: [leftSchema, rightSchema] }, zodType);
|
|
198
|
+
}
|
|
199
|
+
if (zodType instanceof z.ZodUnion) {
|
|
200
|
+
const def = getZodDef(zodType);
|
|
201
|
+
const schemas = def.options.filter((option) => !isUndefinedOnlySchema(option)).map((option) => toOpenApiSchema(option));
|
|
202
|
+
if (schemas.length === 0) return withDescription({}, zodType);
|
|
203
|
+
if (schemas.length === 1) {
|
|
204
|
+
const schema = schemas[0];
|
|
205
|
+
if (!schema) return withDescription({}, zodType);
|
|
206
|
+
return withDescription(schema, zodType);
|
|
207
|
+
}
|
|
208
|
+
return withDescription(def.inclusive === false ? { oneOf: schemas } : { anyOf: schemas }, zodType);
|
|
209
|
+
}
|
|
210
|
+
if (zodType instanceof z.ZodArray) return withDescription({
|
|
211
|
+
type: "array",
|
|
212
|
+
items: toOpenApiSchema(getZodDef(zodType).element)
|
|
213
|
+
}, zodType);
|
|
214
|
+
if (zodType instanceof z.ZodLiteral) return withDescription({ enum: Array.from(zodType.values) }, zodType);
|
|
215
|
+
if (zodType instanceof z.ZodEnum) return withDescription({
|
|
216
|
+
type: "string",
|
|
217
|
+
enum: zodType.options
|
|
218
|
+
}, zodType);
|
|
219
|
+
if (zodType instanceof z.ZodPipe) return withDescription(toOpenApiSchema(getZodPipeSchema(zodType)), zodType);
|
|
220
|
+
if (zodType instanceof z.ZodCatch || zodType instanceof z.ZodReadonly) return withDescription(toOpenApiSchema(getZodDef(zodType).innerType), zodType);
|
|
221
|
+
if (zodType instanceof z.ZodNull) return withDescription({ type: "null" }, zodType);
|
|
222
|
+
if (zodType instanceof z.ZodUndefined) return withDescription({}, zodType);
|
|
223
|
+
if (zodType instanceof z.ZodVoid) return withDescription({}, zodType);
|
|
224
|
+
return withDescription({
|
|
225
|
+
type: getOpenApiTypeFromZodType(zodType),
|
|
226
|
+
...zodType instanceof z.ZodString ? getZodStringSchemaConstraints(zodType) : {}
|
|
227
|
+
}, zodType);
|
|
113
228
|
}
|
|
114
229
|
function getResponse(responses) {
|
|
115
230
|
return {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FieldSchema, OpenAPIModelSchema, Path, generator } from "./generator.mjs";
|
|
1
|
+
import { FieldSchema, OpenAPIModelSchema, OpenAPIParameter, OpenAPISchema, Path, generator } from "./generator.mjs";
|
|
2
2
|
import { LiteralString } from "@better-auth/core";
|
|
3
3
|
import * as better_call0 from "better-call";
|
|
4
4
|
|
|
@@ -94,4 +94,4 @@ declare const openAPI: <O extends OpenAPIOptions>(options?: O | undefined) => {
|
|
|
94
94
|
options: NoInfer<O>;
|
|
95
95
|
};
|
|
96
96
|
//#endregion
|
|
97
|
-
export { type FieldSchema, type OpenAPIModelSchema, OpenAPIOptions, type Path, generator, openAPI };
|
|
97
|
+
export { type FieldSchema, type OpenAPIModelSchema, OpenAPIOptions, OpenAPIParameter, OpenAPISchema, type Path, generator, openAPI };
|
|
@@ -5,7 +5,6 @@ import { InferAPI } from "../types/api.mjs";
|
|
|
5
5
|
import { Session, User } from "../types/models.mjs";
|
|
6
6
|
import { Auth } from "../types/auth.mjs";
|
|
7
7
|
import { setCookieToHeader } from "../cookies/cookie-utils.mjs";
|
|
8
|
-
import * as _better_auth_core0 from "@better-auth/core";
|
|
9
8
|
import { Awaitable, BetterAuthClientOptions, BetterAuthOptions } from "@better-auth/core";
|
|
10
9
|
import * as _better_auth_core_oauth20 from "@better-auth/core/oauth2";
|
|
11
10
|
import * as _better_auth_core_utils_error_codes0 from "@better-auth/core/utils/error-codes";
|
|
@@ -38,7 +37,9 @@ declare function getTestInstance<O extends Partial<BetterAuthOptions>, C extends
|
|
|
38
37
|
};
|
|
39
38
|
} ? T extends {
|
|
40
39
|
plugins: Array<infer Plugin>;
|
|
41
|
-
} ? UnionToIntersection<Plugin extends
|
|
40
|
+
} ? UnionToIntersection<Plugin extends {
|
|
41
|
+
getAtoms?: infer GetAtoms;
|
|
42
|
+
} ? GetAtoms extends ((fetch: any) => infer Atoms) ? Atoms extends Record<string, any> ? { [key in keyof Atoms as IsSignal<key> extends true ? never : key extends string ? `use${Capitalize<key>}` : never]: Atoms[key] } : {} : {} : {}> : {} : never : never> & UnionToIntersection<InferRoute<((C extends undefined ? {} : C) & {
|
|
42
43
|
baseURL: string | undefined;
|
|
43
44
|
fetchOptions: {
|
|
44
45
|
customFetchImpl: (url: string | URL | Request, init?: RequestInit | undefined) => Promise<Response>;
|
|
@@ -2010,10 +2011,10 @@ declare function getTestInstance<O extends Partial<BetterAuthOptions>, C extends
|
|
|
2010
2011
|
customFetchImpl: (url: string | URL | Request, init?: RequestInit | undefined) => Promise<Response>;
|
|
2011
2012
|
};
|
|
2012
2013
|
})["plugins"] ? T_1 extends (infer Pl)[] ? UnionToIntersection<Pl extends {
|
|
2013
|
-
$InferServerPlugin
|
|
2014
|
+
$InferServerPlugin?: infer Plug;
|
|
2014
2015
|
} ? Plug extends {
|
|
2015
|
-
endpoints
|
|
2016
|
-
} ? Endpoints : {} : {}> : {} : never : never)> & (((C extends undefined ? {} : C) & {
|
|
2016
|
+
endpoints?: infer Endpoints;
|
|
2017
|
+
} ? Endpoints extends Record<string, unknown> ? Endpoints : {} : {} : {}> : {} : never : never)> & (((C extends undefined ? {} : C) & {
|
|
2017
2018
|
baseURL: string | undefined;
|
|
2018
2019
|
fetchOptions: {
|
|
2019
2020
|
customFetchImpl: (url: string | URL | Request, init?: RequestInit | undefined) => Promise<Response>;
|
|
@@ -2024,10 +2025,10 @@ declare function getTestInstance<O extends Partial<BetterAuthOptions>, C extends
|
|
|
2024
2025
|
customFetchImpl: (url: string | URL | Request, init?: RequestInit | undefined) => Promise<Response>;
|
|
2025
2026
|
};
|
|
2026
2027
|
})["plugins"] ? T_2 extends (infer Pl)[] ? UnionToIntersection<Pl extends {
|
|
2027
|
-
$InferServerPlugin
|
|
2028
|
+
$InferServerPlugin?: infer Plug;
|
|
2028
2029
|
} ? Plug extends {
|
|
2029
|
-
endpoints
|
|
2030
|
-
} ? Endpoints : {} : {}> : {} : never : never) : InferAPI<Prettify$1<{
|
|
2030
|
+
endpoints?: infer Endpoints;
|
|
2031
|
+
} ? Endpoints extends Record<string, unknown> ? Endpoints : {} : {} : {}> : {} : never : never) : InferAPI<Prettify$1<{
|
|
2031
2032
|
readonly ok: better_call0.StrictEndpoint<"/ok", {
|
|
2032
2033
|
method: "GET";
|
|
2033
2034
|
metadata: {
|
|
@@ -3993,7 +3994,9 @@ declare function getTestInstance<O extends Partial<BetterAuthOptions>, C extends
|
|
|
3993
3994
|
fetchOptions: {
|
|
3994
3995
|
customFetchImpl: (url: string | URL | Request, init?: RequestInit | undefined) => Promise<Response>;
|
|
3995
3996
|
};
|
|
3996
|
-
})["plugins"] extends (infer Plugin_1)[] ? UnionToIntersection<Plugin_1 extends
|
|
3997
|
+
})["plugins"] extends (infer Plugin_1)[] ? UnionToIntersection<Plugin_1 extends {
|
|
3998
|
+
getActions?: infer GetActions;
|
|
3999
|
+
} ? GetActions extends ((...args: any) => infer Actions) ? Actions : {} : {}> : {}) & UnionToIntersection<InferRoute<((C extends undefined ? {} : C) & {
|
|
3997
4000
|
baseURL: string | undefined;
|
|
3998
4001
|
fetchOptions: {
|
|
3999
4002
|
customFetchImpl: (url: string | URL | Request, init?: RequestInit | undefined) => Promise<Response>;
|
|
@@ -4001,8 +4004,8 @@ declare function getTestInstance<O extends Partial<BetterAuthOptions>, C extends
|
|
|
4001
4004
|
})["$InferAuth"] extends {
|
|
4002
4005
|
plugins: infer Plugins;
|
|
4003
4006
|
} ? Plugins extends (infer Plugin_2)[] ? Plugin_2 extends {
|
|
4004
|
-
endpoints
|
|
4005
|
-
} ? Endpoints_1 : {} : {} : {}, (C extends undefined ? {} : C) & {
|
|
4007
|
+
endpoints?: infer Endpoints_1;
|
|
4008
|
+
} ? Endpoints_1 extends Record<string, unknown> ? Endpoints_1 : {} : {} : {} : {}, (C extends undefined ? {} : C) & {
|
|
4006
4009
|
baseURL: string | undefined;
|
|
4007
4010
|
fetchOptions: {
|
|
4008
4011
|
customFetchImpl: (url: string | URL | Request, init?: RequestInit | undefined) => Promise<Response>;
|
|
@@ -5981,10 +5984,10 @@ declare function getTestInstance<O extends Partial<BetterAuthOptions>, C extends
|
|
|
5981
5984
|
customFetchImpl: (url: string | URL | Request, init?: RequestInit | undefined) => Promise<Response>;
|
|
5982
5985
|
};
|
|
5983
5986
|
})["plugins"] ? T_3 extends (infer Pl)[] ? UnionToIntersection<Pl extends {
|
|
5984
|
-
$InferServerPlugin
|
|
5987
|
+
$InferServerPlugin?: infer Plug;
|
|
5985
5988
|
} ? Plug extends {
|
|
5986
|
-
endpoints
|
|
5987
|
-
} ? Endpoints : {} : {}> : {} : never : never)> & (((C extends undefined ? {} : C) & {
|
|
5989
|
+
endpoints?: infer Endpoints;
|
|
5990
|
+
} ? Endpoints extends Record<string, unknown> ? Endpoints : {} : {} : {}> : {} : never : never)> & (((C extends undefined ? {} : C) & {
|
|
5988
5991
|
baseURL: string | undefined;
|
|
5989
5992
|
fetchOptions: {
|
|
5990
5993
|
customFetchImpl: (url: string | URL | Request, init?: RequestInit | undefined) => Promise<Response>;
|
|
@@ -5995,10 +5998,10 @@ declare function getTestInstance<O extends Partial<BetterAuthOptions>, C extends
|
|
|
5995
5998
|
customFetchImpl: (url: string | URL | Request, init?: RequestInit | undefined) => Promise<Response>;
|
|
5996
5999
|
};
|
|
5997
6000
|
})["plugins"] ? T_4 extends (infer Pl)[] ? UnionToIntersection<Pl extends {
|
|
5998
|
-
$InferServerPlugin
|
|
6001
|
+
$InferServerPlugin?: infer Plug;
|
|
5999
6002
|
} ? Plug extends {
|
|
6000
|
-
endpoints
|
|
6001
|
-
} ? Endpoints : {} : {}> : {} : never : never) : InferAPI<Prettify$1<{
|
|
6003
|
+
endpoints?: infer Endpoints;
|
|
6004
|
+
} ? Endpoints extends Record<string, unknown> ? Endpoints : {} : {} : {}> : {} : never : never) : InferAPI<Prettify$1<{
|
|
6002
6005
|
readonly ok: better_call0.StrictEndpoint<"/ok", {
|
|
6003
6006
|
method: "GET";
|
|
6004
6007
|
metadata: {
|
|
@@ -10024,10 +10027,10 @@ declare function getTestInstance<O extends Partial<BetterAuthOptions>, C extends
|
|
|
10024
10027
|
customFetchImpl: (url: string | URL | Request, init?: RequestInit | undefined) => Promise<Response>;
|
|
10025
10028
|
};
|
|
10026
10029
|
})["plugins"] ? T_5 extends (infer Pl)[] ? UnionToIntersection<Pl extends {
|
|
10027
|
-
$InferServerPlugin
|
|
10030
|
+
$InferServerPlugin?: infer Plug;
|
|
10028
10031
|
} ? Plug extends {
|
|
10029
|
-
endpoints
|
|
10030
|
-
} ? Endpoints : {} : {}> : {} : never : never)> & (((C extends undefined ? {} : C) & {
|
|
10032
|
+
endpoints?: infer Endpoints;
|
|
10033
|
+
} ? Endpoints extends Record<string, unknown> ? Endpoints : {} : {} : {}> : {} : never : never)> & (((C extends undefined ? {} : C) & {
|
|
10031
10034
|
baseURL: string | undefined;
|
|
10032
10035
|
fetchOptions: {
|
|
10033
10036
|
customFetchImpl: (url: string | URL | Request, init?: RequestInit | undefined) => Promise<Response>;
|
|
@@ -10038,10 +10041,10 @@ declare function getTestInstance<O extends Partial<BetterAuthOptions>, C extends
|
|
|
10038
10041
|
customFetchImpl: (url: string | URL | Request, init?: RequestInit | undefined) => Promise<Response>;
|
|
10039
10042
|
};
|
|
10040
10043
|
})["plugins"] ? T_6 extends (infer Pl)[] ? UnionToIntersection<Pl extends {
|
|
10041
|
-
$InferServerPlugin
|
|
10044
|
+
$InferServerPlugin?: infer Plug;
|
|
10042
10045
|
} ? Plug extends {
|
|
10043
|
-
endpoints
|
|
10044
|
-
} ? Endpoints : {} : {}> : {} : never : never) : InferAPI<Prettify$1<{
|
|
10046
|
+
endpoints?: infer Endpoints;
|
|
10047
|
+
} ? Endpoints extends Record<string, unknown> ? Endpoints : {} : {} : {}> : {} : never : never) : InferAPI<Prettify$1<{
|
|
10045
10048
|
readonly ok: better_call0.StrictEndpoint<"/ok", {
|
|
10046
10049
|
method: "GET";
|
|
10047
10050
|
metadata: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-auth",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.18",
|
|
4
4
|
"description": "The most comprehensive authentication framework for TypeScript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -489,13 +489,13 @@
|
|
|
489
489
|
"kysely": "^0.28.17 || ^0.29.0",
|
|
490
490
|
"nanostores": "^1.1.1",
|
|
491
491
|
"zod": "^4.3.6",
|
|
492
|
-
"@better-auth/core": "1.6.
|
|
493
|
-
"@better-auth/drizzle-adapter": "1.6.
|
|
494
|
-
"@better-auth/kysely-adapter": "1.6.
|
|
495
|
-
"@better-auth/memory-adapter": "1.6.
|
|
496
|
-
"@better-auth/mongo-adapter": "1.6.
|
|
497
|
-
"@better-auth/prisma-adapter": "1.6.
|
|
498
|
-
"@better-auth/telemetry": "1.6.
|
|
492
|
+
"@better-auth/core": "1.6.18",
|
|
493
|
+
"@better-auth/drizzle-adapter": "1.6.18",
|
|
494
|
+
"@better-auth/kysely-adapter": "1.6.18",
|
|
495
|
+
"@better-auth/memory-adapter": "1.6.18",
|
|
496
|
+
"@better-auth/mongo-adapter": "1.6.18",
|
|
497
|
+
"@better-auth/prisma-adapter": "1.6.18",
|
|
498
|
+
"@better-auth/telemetry": "1.6.18"
|
|
499
499
|
},
|
|
500
500
|
"devDependencies": {
|
|
501
501
|
"@lynx-js/react": "^0.116.3",
|