better-auth 1.7.12 → 1.7.14
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 +5 -10
- package/dist/api/dispatch.d.mts +3 -5
- package/dist/api/dispatch.mjs +6 -4
- package/dist/api/index.d.mts +506 -508
- package/dist/api/index.mjs +35 -34
- package/dist/api/middlewares/authorization.d.mts +15 -12
- 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 +4 -7
- package/dist/api/routes/account.d.mts +11 -15
- package/dist/api/routes/account.mjs +7 -4
- package/dist/api/routes/callback.d.mts +2 -5
- package/dist/api/routes/callback.mjs +4 -2
- package/dist/api/routes/email-verification.d.mts +7 -12
- package/dist/api/routes/error.d.mts +2 -5
- package/dist/api/routes/index.d.mts +2 -1
- package/dist/api/routes/ok.d.mts +2 -5
- package/dist/api/routes/password.d.mts +8 -11
- package/dist/api/routes/password.mjs +3 -2
- package/dist/api/routes/session.d.mts +26 -29
- package/dist/api/routes/sign-in.d.mts +4 -6
- package/dist/api/routes/sign-out.d.mts +2 -5
- package/dist/api/routes/sign-up.d.mts +4 -6
- package/dist/api/routes/update-session.d.mts +4 -6
- package/dist/api/routes/update-user.d.mts +14 -16
- package/dist/api/routes/update-user.mjs +1 -1
- package/dist/api/state/oauth.d.mts +0 -3
- package/dist/api/state/oauth.mjs +2 -1
- package/dist/auth/full.d.mts +3 -4
- package/dist/auth/minimal.d.mts +3 -3
- package/dist/client/broadcast-channel.d.mts +6 -7
- package/dist/client/config.d.mts +15 -19
- package/dist/client/config.mjs +2 -2
- package/dist/client/equality.d.mts +3 -5
- package/dist/client/focus-manager.d.mts +4 -5
- package/dist/client/index.d.mts +8 -7
- package/dist/client/lynx/index.d.mts +6 -7
- package/dist/client/lynx/index.mjs +3 -2
- package/dist/client/lynx/lynx-store.d.mts +3 -4
- package/dist/client/online-manager.d.mts +4 -5
- package/dist/client/parser.d.mts +9 -5
- package/dist/client/path-to-object.d.mts +13 -14
- package/dist/client/plugins/index.d.mts +1 -1
- package/dist/client/plugins/infer-plugin.d.mts +2 -4
- package/dist/client/query.d.mts +4 -6
- package/dist/client/react/index.d.mts +6 -7
- package/dist/client/react/index.mjs +3 -2
- package/dist/client/react/react-store.d.mts +3 -4
- package/dist/client/session-atom.d.mts +4 -4
- package/dist/client/session-refresh.d.mts +3 -5
- package/dist/client/solid/index.d.mts +6 -7
- package/dist/client/solid/index.mjs +3 -2
- package/dist/client/svelte/index.d.mts +6 -7
- package/dist/client/svelte/index.mjs +3 -2
- package/dist/client/types.d.mts +11 -11
- package/dist/client/vanilla.d.mts +4 -5
- package/dist/client/vanilla.mjs +3 -2
- package/dist/client/vue/index.d.mts +6 -7
- package/dist/client/vue/index.mjs +3 -2
- package/dist/context/create-context.mjs +7 -7
- package/dist/context/helpers.mjs +9 -7
- package/dist/cookies/cookie-utils.d.mts +13 -13
- package/dist/cookies/cookie-utils.mjs +1 -3
- package/dist/cookies/index.d.mts +17 -18
- package/dist/cookies/index.mjs +11 -7
- package/dist/cookies/jwt.mjs +2 -1
- package/dist/cookies/session-store.d.mts +6 -5
- package/dist/cookies/session-store.mjs +3 -2
- package/dist/crypto/buffer.d.mts +2 -3
- package/dist/crypto/index.d.mts +9 -16
- package/dist/crypto/index.mjs +2 -1
- package/dist/crypto/jwt.d.mts +5 -7
- package/dist/crypto/jwt.mjs +2 -1
- package/dist/crypto/password.d.mts +1 -5
- package/dist/crypto/random.d.mts +2 -3
- package/dist/db/adapter-base.d.mts +2 -4
- package/dist/db/adapter-kysely.d.mts +2 -4
- package/dist/db/field-converter.d.mts +3 -5
- package/dist/db/field.d.mts +11 -12
- package/dist/db/get-migration.d.mts +4 -8
- package/dist/db/get-migration.mjs +22 -22
- package/dist/db/get-schema.d.mts +2 -4
- package/dist/db/internal-adapter.d.mts +2 -4
- package/dist/db/internal-adapter.mjs +6 -4
- package/dist/db/revoke-unproven-account-access.d.mts +3 -4
- package/dist/db/schema.d.mts +15 -16
- package/dist/db/schema.mjs +6 -3
- package/dist/db/to-zod.d.mts +5 -9
- package/dist/db/with-hooks.d.mts +3 -5
- package/dist/index.d.mts +4 -3
- package/dist/integrations/next-js.d.mts +7 -11
- package/dist/integrations/node.d.mts +5 -7
- package/dist/integrations/node.mjs +4 -2
- package/dist/integrations/solid-start.d.mts +2 -3
- package/dist/integrations/svelte-kit.d.mts +6 -14
- package/dist/integrations/tanstack-start-solid.d.mts +4 -8
- package/dist/integrations/tanstack-start.d.mts +4 -8
- package/dist/oauth2/link-account.d.mts +5 -11
- package/dist/oauth2/link-account.mjs +12 -6
- package/dist/oauth2/state.d.mts +5 -7
- package/dist/oauth2/state.mjs +1 -1
- package/dist/oauth2/utils.d.mts +4 -6
- package/dist/package.mjs +1 -1
- package/dist/plugins/access/access.d.mts +4 -6
- package/dist/plugins/access/index.mjs +1 -2
- package/dist/plugins/access/types.d.mts +12 -14
- package/dist/plugins/additional-fields/client.d.mts +2 -4
- package/dist/plugins/admin/access/index.mjs +1 -2
- package/dist/plugins/admin/access/statement.d.mts +7 -7
- package/dist/plugins/admin/admin.d.mts +122 -128
- package/dist/plugins/admin/client.d.mts +32 -32
- package/dist/plugins/admin/client.mjs +1 -1
- package/dist/plugins/admin/error-codes.d.mts +25 -28
- package/dist/plugins/admin/index.d.mts +1 -1
- package/dist/plugins/admin/index.mjs +1 -2
- package/dist/plugins/admin/schema.d.mts +3 -4
- package/dist/plugins/admin/types.d.mts +8 -8
- package/dist/plugins/anonymous/client.d.mts +10 -12
- package/dist/plugins/anonymous/client.mjs +1 -1
- package/dist/plugins/anonymous/error-codes.d.mts +10 -13
- package/dist/plugins/anonymous/index.d.mts +17 -21
- package/dist/plugins/anonymous/schema.d.mts +2 -3
- package/dist/plugins/anonymous/types.d.mts +5 -6
- package/dist/plugins/bearer/index.d.mts +7 -11
- package/dist/plugins/captcha/constants.d.mts +2 -3
- package/dist/plugins/captcha/index.d.mts +6 -9
- package/dist/plugins/captcha/types.d.mts +11 -13
- package/dist/plugins/custom-session/client.d.mts +2 -4
- package/dist/plugins/custom-session/index.d.mts +10 -16
- package/dist/plugins/device-authorization/client.d.mts +2 -4
- package/dist/plugins/device-authorization/index.d.mts +39 -44
- package/dist/plugins/device-authorization/index.mjs +10 -9
- package/dist/plugins/device-authorization/routes.d.mts +7 -5
- package/dist/plugins/device-authorization/routes.mjs +6 -5
- package/dist/plugins/device-authorization/schema.d.mts +2 -3
- package/dist/plugins/email-otp/client.d.mts +5 -7
- package/dist/plugins/email-otp/client.mjs +1 -1
- package/dist/plugins/email-otp/error-codes.d.mts +5 -8
- package/dist/plugins/email-otp/index.d.mts +69 -76
- package/dist/plugins/email-otp/otp-token.mjs +19 -7
- package/dist/plugins/email-otp/types.d.mts +2 -4
- package/dist/plugins/generic-oauth/index.d.mts +9 -13
- package/dist/plugins/generic-oauth/index.mjs +6 -4
- package/dist/plugins/generic-oauth/providers/auth0.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/gumroad.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/hubspot.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/hubspot.mjs +2 -1
- package/dist/plugins/generic-oauth/providers/index.d.mts +2 -1
- package/dist/plugins/generic-oauth/providers/keycloak.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/line.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/okta.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/patreon.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/slack.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/yandex.d.mts +3 -5
- package/dist/plugins/generic-oauth/types.d.mts +6 -7
- package/dist/plugins/haveibeenpwned/index.d.mts +7 -11
- package/dist/plugins/index.d.mts +4 -1
- package/dist/plugins/jwt/client.d.mts +2 -3
- package/dist/plugins/jwt/index.d.mts +11 -14
- package/dist/plugins/jwt/index.mjs +1 -1
- package/dist/plugins/jwt/schema.d.mts +2 -3
- package/dist/plugins/jwt/sign.d.mts +9 -8
- package/dist/plugins/jwt/types.d.mts +7 -8
- package/dist/plugins/jwt/utils.d.mts +6 -9
- package/dist/plugins/jwt/verify.d.mts +2 -4
- package/dist/plugins/last-login-method/client.d.mts +3 -4
- package/dist/plugins/last-login-method/index.d.mts +5 -9
- package/dist/plugins/last-login-method/index.mjs +1 -1
- package/dist/plugins/magic-link/client.d.mts +2 -4
- package/dist/plugins/magic-link/index.d.mts +7 -10
- package/dist/plugins/magic-link/index.mjs +20 -17
- package/dist/plugins/multi-session/client.d.mts +3 -5
- package/dist/plugins/multi-session/client.mjs +1 -1
- package/dist/plugins/multi-session/error-codes.d.mts +3 -6
- package/dist/plugins/multi-session/index.d.mts +10 -14
- package/dist/plugins/oauth-popup/client.d.mts +11 -17
- package/dist/plugins/oauth-popup/client.mjs +6 -4
- package/dist/plugins/oauth-popup/constants.d.mts +5 -6
- package/dist/plugins/oauth-popup/error-codes.d.mts +6 -9
- package/dist/plugins/oauth-popup/index.d.mts +11 -15
- package/dist/plugins/oauth-popup/index.mjs +8 -7
- package/dist/plugins/oauth-popup/types.d.mts +4 -6
- package/dist/plugins/oauth-proxy/index.d.mts +11 -15
- package/dist/plugins/oauth-proxy/index.mjs +10 -7
- package/dist/plugins/one-tap/client.d.mts +6 -9
- package/dist/plugins/one-tap/index.d.mts +4 -7
- package/dist/plugins/one-time-token/client.d.mts +2 -3
- package/dist/plugins/one-time-token/index.d.mts +8 -10
- package/dist/plugins/open-api/generator.d.mts +8 -8
- package/dist/plugins/open-api/generator.mjs +5 -5
- package/dist/plugins/open-api/index.d.mts +5 -7
- package/dist/plugins/organization/access/index.mjs +1 -2
- package/dist/plugins/organization/access/statement.d.mts +8 -8
- package/dist/plugins/organization/adapter.d.mts +60 -87
- package/dist/plugins/organization/adapter.mjs +14 -10
- package/dist/plugins/organization/client.d.mts +108 -107
- package/dist/plugins/organization/client.mjs +9 -5
- package/dist/plugins/organization/error-codes.d.mts +61 -64
- package/dist/plugins/organization/has-permission.d.mts +2 -4
- 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 +20 -20
- package/dist/plugins/organization/organization.mjs +13 -8
- package/dist/plugins/organization/permission.d.mts +4 -5
- package/dist/plugins/organization/routes/crud-access-control.d.mts +28 -28
- package/dist/plugins/organization/routes/crud-invites.d.mts +64 -65
- package/dist/plugins/organization/routes/crud-invites.mjs +21 -18
- package/dist/plugins/organization/routes/crud-members.d.mts +53 -56
- package/dist/plugins/organization/routes/crud-members.mjs +23 -21
- package/dist/plugins/organization/routes/crud-org.d.mts +63 -65
- package/dist/plugins/organization/routes/crud-org.mjs +4 -2
- package/dist/plugins/organization/routes/crud-team.d.mts +65 -66
- package/dist/plugins/organization/routes/crud-team.mjs +4 -2
- package/dist/plugins/organization/schema.d.mts +33 -33
- package/dist/plugins/organization/schema.mjs +1 -1
- package/dist/plugins/organization/types.d.mts +16 -17
- package/dist/plugins/phone-number/client.d.mts +14 -16
- package/dist/plugins/phone-number/client.mjs +1 -1
- package/dist/plugins/phone-number/error-codes.d.mts +14 -17
- package/dist/plugins/phone-number/index.d.mts +48 -54
- package/dist/plugins/phone-number/schema.d.mts +2 -3
- package/dist/plugins/phone-number/types.d.mts +4 -5
- package/dist/plugins/siwe/client.d.mts +2 -4
- package/dist/plugins/siwe/index.d.mts +7 -9
- package/dist/plugins/siwe/index.mjs +1 -1
- package/dist/plugins/siwe/parse-message.mjs +1 -3
- package/dist/plugins/siwe/schema.d.mts +3 -4
- package/dist/plugins/siwe/types.d.mts +4 -4
- package/dist/plugins/test-utils/auth-helpers.mjs +4 -2
- package/dist/plugins/test-utils/index.d.mts +3 -5
- package/dist/plugins/test-utils/types.d.mts +7 -7
- package/dist/plugins/two-factor/backup-codes/index.d.mts +11 -14
- package/dist/plugins/two-factor/backup-codes/index.mjs +12 -6
- package/dist/plugins/two-factor/client.d.mts +16 -19
- package/dist/plugins/two-factor/client.mjs +1 -1
- package/dist/plugins/two-factor/constant.mjs +1 -1
- package/dist/plugins/two-factor/error-code.d.mts +15 -18
- package/dist/plugins/two-factor/index.d.mts +31 -35
- package/dist/plugins/two-factor/index.mjs +6 -3
- package/dist/plugins/two-factor/otp/index.d.mts +5 -8
- package/dist/plugins/two-factor/otp/index.mjs +159 -154
- package/dist/plugins/two-factor/schema.d.mts +2 -3
- package/dist/plugins/two-factor/totp/index.d.mts +7 -10
- package/dist/plugins/two-factor/totp/index.mjs +164 -148
- package/dist/plugins/two-factor/types.d.mts +6 -7
- package/dist/plugins/username/client.d.mts +12 -14
- package/dist/plugins/username/client.mjs +1 -1
- package/dist/plugins/username/error-codes.d.mts +11 -14
- package/dist/plugins/username/index.d.mts +26 -31
- package/dist/plugins/username/schema.d.mts +7 -10
- package/dist/state.d.mts +4 -5
- package/dist/test-utils/headers.d.mts +2 -3
- package/dist/test-utils/http-test-instance.d.mts +26 -29
- package/dist/test-utils/test-instance.d.mts +7 -6
- package/dist/test-utils/test-instance.mjs +4 -2
- package/dist/types/adapter.d.mts +1 -1
- package/dist/types/api.d.mts +4 -6
- package/dist/types/auth.d.mts +2 -4
- package/dist/types/helper.d.mts +11 -12
- package/dist/types/index.d.mts +2 -2
- package/dist/types/models.d.mts +4 -5
- package/dist/types/plugins.d.mts +7 -8
- package/dist/utils/hide-metadata.d.mts +2 -3
- package/dist/utils/index.d.mts +2 -1
- package/dist/utils/is-api-error.mjs +1 -2
- package/dist/utils/time.d.mts +4 -4
- package/dist/utils/url.d.mts +13 -15
- package/dist/utils/wildcard.mjs +5 -3
- package/package.json +12 -12
package/dist/db/field.d.mts
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import { DBFieldAttribute, InferDBValueType } from "@better-auth/core/db";
|
|
2
|
-
|
|
3
2
|
//#region src/db/field.d.ts
|
|
4
|
-
type InferFieldsOutput<Fields extends Record<string, DBFieldAttribute>> = Fields extends Record<infer Key, DBFieldAttribute> ? { [key in Key as Fields[key]["returned"] extends false ? never : Fields[key]["required"] extends false ? Fields[key]["defaultValue"] extends boolean | string | number | Date ? key : never : key]: InferFieldOutput<Fields[key]
|
|
3
|
+
export type InferFieldsOutput<Fields extends Record<string, DBFieldAttribute>> = Fields extends Record<infer Key, DBFieldAttribute> ? { [key in Key as Fields[key]["returned"] extends false ? never : Fields[key]["required"] extends false ? Fields[key]["defaultValue"] extends boolean | string | number | Date ? key : never : key]: InferFieldOutput<Fields[key]>; } & { [key in Key as Fields[key]["returned"] extends false ? never : Fields[key]["required"] extends false ? Fields[key]["defaultValue"] extends boolean | string | number | Date ? never : key : never]?: InferFieldOutput<Fields[key]> | null; } : never;
|
|
5
4
|
/**
|
|
6
5
|
* For client will add "?" on optional fields
|
|
7
6
|
*/
|
|
8
|
-
type InferFieldsInputClient<Fields extends Record<string, DBFieldAttribute>> = Fields extends Record<infer Key, DBFieldAttribute> ? { [key in Key as Fields[key]["required"] extends false ? never : Fields[key]["defaultValue"] extends string | number | boolean | Date ? never : Fields[key]["input"] extends false ? never : key]: InferFieldInput<Fields[key]
|
|
7
|
+
export type InferFieldsInputClient<Fields extends Record<string, DBFieldAttribute>> = Fields extends Record<infer Key, DBFieldAttribute> ? { [key in Key as Fields[key]["required"] extends false ? never : Fields[key]["defaultValue"] extends string | number | boolean | Date ? never : Fields[key]["input"] extends false ? never : key]: InferFieldInput<Fields[key]>; } & { [key in Key as Fields[key]["input"] extends false ? never : Fields[key]["required"] extends false ? key : Fields[key]["defaultValue"] extends string | number | boolean | Date ? key : never]?: InferFieldInput<Fields[key]> | undefined | null; } : never;
|
|
9
8
|
type InferFieldOutput<T extends DBFieldAttribute> = T["returned"] extends false ? never : T["required"] extends false ? InferDBValueType<T["type"]> | undefined | null : InferDBValueType<T["type"]>;
|
|
10
9
|
/**
|
|
11
10
|
* Converts a Record<string, DBFieldAttribute> to an object type
|
|
12
11
|
* with keys and value types inferred from DBFieldAttribute["type"].
|
|
13
12
|
*/
|
|
14
|
-
type FieldAttributeToObject<Fields extends Record<string, DBFieldAttribute>> = AddOptionalFields<{ [K in keyof Fields]: InferDBValueType<Fields[K]["type"]
|
|
13
|
+
export type FieldAttributeToObject<Fields extends Record<string, DBFieldAttribute>> = AddOptionalFields<{ [K in keyof Fields]: InferDBValueType<Fields[K]["type"]>; }, Fields>;
|
|
15
14
|
type AddOptionalFields<T extends Record<string, any>, Fields extends Record<keyof T, DBFieldAttribute>> = { [K in keyof T as Fields[K] extends {
|
|
16
15
|
required: false;
|
|
17
|
-
} ? never : K]: T[K] } & { [K in keyof T as Fields[K] extends {
|
|
16
|
+
} ? never : K]: T[K]; } & { [K in keyof T as Fields[K] extends {
|
|
18
17
|
required: false;
|
|
19
|
-
} ? K : never]?: T[K] };
|
|
18
|
+
} ? K : never]?: T[K]; };
|
|
20
19
|
/**
|
|
21
20
|
* Infer the additional fields from the plugin options.
|
|
22
21
|
* For example, you can infer the additional fields of the org plugin's organization schema like this:
|
|
@@ -27,15 +26,15 @@ type AddOptionalFields<T extends Record<string, any>, Fields extends Record<keyo
|
|
|
27
26
|
* @param isClientSide - When `true` (default), filters out `input: false` fields (clients can't send these).
|
|
28
27
|
* When `false`, includes all fields (for internal/server-side use).
|
|
29
28
|
*/
|
|
30
|
-
type InferAdditionalFieldsFromPluginOptions<SchemaName extends string, Options extends {
|
|
29
|
+
export type InferAdditionalFieldsFromPluginOptions<SchemaName extends string, Options extends {
|
|
31
30
|
schema?: { [key in SchemaName]?: {
|
|
32
31
|
additionalFields?: Record<string, DBFieldAttribute>;
|
|
33
|
-
} } | undefined;
|
|
32
|
+
}; } | undefined;
|
|
34
33
|
}, isClientSide extends boolean = true> = Options["schema"] extends { [key in SchemaName]?: {
|
|
35
34
|
additionalFields: infer Field extends Record<string, DBFieldAttribute>;
|
|
36
|
-
} } ? isClientSide extends true ? FieldAttributeToObject<RemoveFieldsWithInputFalse<Field>> : FieldAttributeToObject<Field> : {};
|
|
37
|
-
type RemoveFieldsWithInputFalse<T extends Record<string, DBFieldAttribute>> = { [K in keyof T as T[K]["input"] extends false ? never : K]: T[K] };
|
|
38
|
-
type RemoveFieldsWithReturnedFalse<T extends Record<string, DBFieldAttribute>> = { [K in keyof T as T[K]["returned"] extends false ? never : K]: T[K] };
|
|
35
|
+
}; } ? isClientSide extends true ? FieldAttributeToObject<RemoveFieldsWithInputFalse<Field>> : FieldAttributeToObject<Field> : {};
|
|
36
|
+
type RemoveFieldsWithInputFalse<T extends Record<string, DBFieldAttribute>> = { [K in keyof T as T[K]["input"] extends false ? never : K]: T[K]; };
|
|
37
|
+
export type RemoveFieldsWithReturnedFalse<T extends Record<string, DBFieldAttribute>> = { [K in keyof T as T[K]["returned"] extends false ? never : K]: T[K]; };
|
|
39
38
|
type InferFieldInput<T extends DBFieldAttribute> = InferDBValueType<T["type"]>;
|
|
40
39
|
//#endregion
|
|
41
|
-
export {
|
|
40
|
+
export {};
|
|
@@ -3,7 +3,6 @@ import { DBFieldAttribute, DBFieldType } from "@better-auth/core/db";
|
|
|
3
3
|
import { BetterAuthError } from "@better-auth/core/error";
|
|
4
4
|
import { KyselyDatabaseType } from "@better-auth/kysely-adapter";
|
|
5
5
|
import { ResolvedDBTableIndex } from "@better-auth/core/db/internal";
|
|
6
|
-
|
|
7
6
|
//#region src/db/get-migration.d.ts
|
|
8
7
|
/**
|
|
9
8
|
* Thrown when {@link getMigrations} refuses to add a required column with no
|
|
@@ -11,8 +10,8 @@ import { ResolvedDBTableIndex } from "@better-auth/core/db/internal";
|
|
|
11
10
|
* {@link BetterAuthError} thrown for index-definition conflicts, so callers
|
|
12
11
|
* can tell the two apart without matching on message text.
|
|
13
12
|
*/
|
|
14
|
-
declare class UnsafeMigrationError extends BetterAuthError {}
|
|
15
|
-
declare function matchType(columnDataType: string, fieldType: DBFieldType, dbType: KyselyDatabaseType): boolean;
|
|
13
|
+
export declare class UnsafeMigrationError extends BetterAuthError {}
|
|
14
|
+
export declare function matchType(columnDataType: string, fieldType: DBFieldType, dbType: KyselyDatabaseType): boolean;
|
|
16
15
|
/**
|
|
17
16
|
* Build the migration plan that `auth migrate` executes and `auth generate`
|
|
18
17
|
* prints for the Kysely adapter.
|
|
@@ -27,9 +26,7 @@ declare function matchType(columnDataType: string, fieldType: DBFieldType, dbTyp
|
|
|
27
26
|
* @throws {BetterAuthError} when an index definition conflicts with an
|
|
28
27
|
* existing or already-planned index.
|
|
29
28
|
*/
|
|
30
|
-
declare function getMigrations(config: BetterAuthOptions, {
|
|
31
|
-
throwOnUnsafe
|
|
32
|
-
}?: {
|
|
29
|
+
export declare function getMigrations(config: BetterAuthOptions, { throwOnUnsafe }?: {
|
|
33
30
|
throwOnUnsafe?: boolean;
|
|
34
31
|
}): Promise<{
|
|
35
32
|
toBeCreated: {
|
|
@@ -52,5 +49,4 @@ declare function getMigrations(config: BetterAuthOptions, {
|
|
|
52
49
|
runMigrations: () => Promise<void>;
|
|
53
50
|
compileMigrations: () => Promise<string>;
|
|
54
51
|
}>;
|
|
55
|
-
//#endregion
|
|
56
|
-
export { UnsafeMigrationError, getMigrations, matchType };
|
|
52
|
+
//#endregion
|
|
@@ -176,8 +176,7 @@ async function getDatabaseIndexMap(db, target, tableNames, introspectIndexes) {
|
|
|
176
176
|
WHERE table_schema = DATABASE()
|
|
177
177
|
`.execute(db)).rows;
|
|
178
178
|
break;
|
|
179
|
-
case "mssql":
|
|
180
|
-
rows = (await sql`
|
|
179
|
+
case "mssql": rows = (await sql`
|
|
181
180
|
SELECT
|
|
182
181
|
tables.name AS "tableName",
|
|
183
182
|
indexes.name AS "indexName",
|
|
@@ -202,7 +201,6 @@ async function getDatabaseIndexMap(db, target, tableNames, introspectIndexes) {
|
|
|
202
201
|
AND indexes.name IS NOT NULL
|
|
203
202
|
AND index_columns.key_ordinal > 0
|
|
204
203
|
`.execute(db)).rows;
|
|
205
|
-
break;
|
|
206
204
|
}
|
|
207
205
|
const indexMetadata = /* @__PURE__ */ new Map();
|
|
208
206
|
for (const row of rows) {
|
|
@@ -253,8 +251,7 @@ async function getDatabaseColumnBounds(db, target) {
|
|
|
253
251
|
WHERE table_schema = DATABASE()
|
|
254
252
|
`.execute(db)).rows;
|
|
255
253
|
break;
|
|
256
|
-
case "mssql":
|
|
257
|
-
rows = (await sql`
|
|
254
|
+
case "mssql": rows = (await sql`
|
|
258
255
|
SELECT
|
|
259
256
|
tables.name AS "tableName",
|
|
260
257
|
columns.name AS "columnName",
|
|
@@ -266,7 +263,6 @@ async function getDatabaseColumnBounds(db, target) {
|
|
|
266
263
|
ON table_schemas.schema_id = tables.schema_id
|
|
267
264
|
WHERE table_schemas.name = ${target.schema}
|
|
268
265
|
`.execute(db)).rows;
|
|
269
|
-
break;
|
|
270
266
|
}
|
|
271
267
|
const bounds = /* @__PURE__ */ new Map();
|
|
272
268
|
for (const row of rows) {
|
|
@@ -370,8 +366,10 @@ async function getMigrations(config, { throwOnUnsafe = true } = {}) {
|
|
|
370
366
|
};
|
|
371
367
|
logger.debug(`PostgreSQL migration: Using schema '${schema}' (${schemaName ? "from database.schemaName" : "from search_path"})`);
|
|
372
368
|
try {
|
|
373
|
-
if (!(await db.introspection.getSchemas()).some(({ name }) => name === schema))
|
|
374
|
-
|
|
369
|
+
if (!(await db.introspection.getSchemas()).some(({ name }) => name === schema)) {
|
|
370
|
+
if (schemaName) logger.debug(`Schema '${schema}' does not exist yet. The migration creates it before creating tables.`);
|
|
371
|
+
else logger.warn(`Schema '${schema}' does not exist. Create it before running migrations or check your database configuration.`);
|
|
372
|
+
}
|
|
375
373
|
} catch (error) {
|
|
376
374
|
logger.debug(`Could not verify schema existence: ${error instanceof Error ? error.message : String(error)}`);
|
|
377
375
|
}
|
|
@@ -396,9 +394,7 @@ async function getMigrations(config, { throwOnUnsafe = true } = {}) {
|
|
|
396
394
|
case "mysql":
|
|
397
395
|
target = { type: "mysql" };
|
|
398
396
|
break;
|
|
399
|
-
case "sqlite":
|
|
400
|
-
target = { type: "sqlite" };
|
|
401
|
-
break;
|
|
397
|
+
case "sqlite": target = { type: "sqlite" };
|
|
402
398
|
}
|
|
403
399
|
const databaseIndexMap = await getDatabaseIndexMap(db, target, allTableMetadata.map((table) => table.name), introspectIndexes);
|
|
404
400
|
const databaseColumnBounds = await getDatabaseColumnBounds(db, target);
|
|
@@ -457,12 +453,13 @@ async function getMigrations(config, { throwOnUnsafe = true } = {}) {
|
|
|
457
453
|
order: value.order || Infinity
|
|
458
454
|
};
|
|
459
455
|
const insertIndex = toBeCreated.findIndex((t) => (t.order || Infinity) > tableData.order);
|
|
460
|
-
if (insertIndex === -1)
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
456
|
+
if (insertIndex === -1) {
|
|
457
|
+
if (tIndex === -1) toBeCreated.push(tableData);
|
|
458
|
+
else toBeCreated[tIndex].fields = {
|
|
459
|
+
...toBeCreated[tIndex].fields,
|
|
460
|
+
...value.fields
|
|
461
|
+
};
|
|
462
|
+
} else toBeCreated.splice(insertIndex, 0, tableData);
|
|
466
463
|
continue;
|
|
467
464
|
}
|
|
468
465
|
const toBeAddedFields = {};
|
|
@@ -618,9 +615,10 @@ async function getMigrations(config, { throwOnUnsafe = true } = {}) {
|
|
|
618
615
|
const built = builder.addColumn(fieldName, type, (col) => {
|
|
619
616
|
col = field.required !== false ? col.notNull() : col;
|
|
620
617
|
if (field.references) col = col.references(getReferencePath(field)).onDelete(field.references.onDelete || "cascade");
|
|
621
|
-
if (timestampDefault)
|
|
622
|
-
|
|
623
|
-
|
|
618
|
+
if (timestampDefault) {
|
|
619
|
+
if (dbType === "mysql") col = col.defaultTo(sql`CURRENT_TIMESTAMP(3)`);
|
|
620
|
+
else col = col.defaultTo(sql`CURRENT_TIMESTAMP`);
|
|
621
|
+
} else if (staticDefault) col = col.defaultTo(typeof field.defaultValue === "boolean" && (dbType === "sqlite" || dbType === "mssql") ? field.defaultValue ? 1 : 0 : field.defaultValue);
|
|
624
622
|
return col;
|
|
625
623
|
});
|
|
626
624
|
migrations.push(built);
|
|
@@ -647,8 +645,10 @@ async function getMigrations(config, { throwOnUnsafe = true } = {}) {
|
|
|
647
645
|
col = field.required !== false ? col.notNull() : col;
|
|
648
646
|
if (field.references) col = col.references(getReferencePath(field)).onDelete(field.references.onDelete || "cascade");
|
|
649
647
|
if (field.unique) col = col.unique();
|
|
650
|
-
if (field.type === "date" && typeof field.defaultValue === "function" && (dbType === "postgres" || dbType === "mysql" || dbType === "mssql"))
|
|
651
|
-
|
|
648
|
+
if (field.type === "date" && typeof field.defaultValue === "function" && (dbType === "postgres" || dbType === "mysql" || dbType === "mssql")) {
|
|
649
|
+
if (dbType === "mysql") col = col.defaultTo(sql`CURRENT_TIMESTAMP(3)`);
|
|
650
|
+
else col = col.defaultTo(sql`CURRENT_TIMESTAMP`);
|
|
651
|
+
}
|
|
652
652
|
return col;
|
|
653
653
|
});
|
|
654
654
|
if (field.index && !field.unique) {
|
package/dist/db/get-schema.d.mts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { BetterAuthOptions } from "@better-auth/core";
|
|
2
2
|
import { DBFieldAttribute } from "@better-auth/core/db";
|
|
3
3
|
import { ResolvedDBTableIndex } from "@better-auth/core/db/internal";
|
|
4
|
-
|
|
5
4
|
//#region src/db/get-schema.d.ts
|
|
6
|
-
declare function getSchema(config: BetterAuthOptions): Record<string, {
|
|
5
|
+
export declare function getSchema(config: BetterAuthOptions): Record<string, {
|
|
7
6
|
fields: Record<string, DBFieldAttribute>;
|
|
8
7
|
indexes?: readonly ResolvedDBTableIndex[] | undefined;
|
|
9
8
|
order: number;
|
|
10
9
|
disableMigrations?: boolean | undefined;
|
|
11
10
|
}>;
|
|
12
|
-
//#endregion
|
|
13
|
-
export { getSchema };
|
|
11
|
+
//#endregion
|
|
@@ -2,13 +2,11 @@ import { DatabaseHooksEntry } from "./with-hooks.mjs";
|
|
|
2
2
|
import { AuthContext, BetterAuthOptions, InternalAdapter } from "@better-auth/core";
|
|
3
3
|
import { InternalLogger } from "@better-auth/core/env";
|
|
4
4
|
import { DBAdapter } from "@better-auth/core/db/adapter";
|
|
5
|
-
|
|
6
5
|
//#region src/db/internal-adapter.d.ts
|
|
7
|
-
declare const createInternalAdapter: (adapter: DBAdapter<BetterAuthOptions>, ctx: {
|
|
6
|
+
export declare const createInternalAdapter: (adapter: DBAdapter<BetterAuthOptions>, ctx: {
|
|
8
7
|
options: Omit<BetterAuthOptions, "logger">;
|
|
9
8
|
logger: InternalLogger;
|
|
10
9
|
hooks: DatabaseHooksEntry[];
|
|
11
10
|
generateId: AuthContext["generateId"];
|
|
12
11
|
}) => InternalAdapter;
|
|
13
|
-
//#endregion
|
|
14
|
-
export { createInternalAdapter };
|
|
12
|
+
//#endregion
|
|
@@ -20,7 +20,7 @@ const createInternalAdapter = (adapter, ctx) => {
|
|
|
20
20
|
const options = ctx.options;
|
|
21
21
|
const secondaryStorage = options.secondaryStorage;
|
|
22
22
|
const verificationConsumeLocks = /* @__PURE__ */ new Map();
|
|
23
|
-
const sessionExpiration = options.session?.expiresIn ||
|
|
23
|
+
const sessionExpiration = options.session?.expiresIn || 604800;
|
|
24
24
|
const databaseSessionFallbackEnabled = !!secondaryStorage && options.session?.storeSessionInDatabase === true && options.session?.preserveSessionInDatabase !== true;
|
|
25
25
|
const { createWithHooks, updateWithHooks, updateManyWithHooks, deleteWithHooks, deleteManyWithHooks, consumeOneWithHooks } = getWithHooks(adapter, ctx);
|
|
26
26
|
/**
|
|
@@ -280,7 +280,7 @@ const createInternalAdapter = (adapter, ctx) => {
|
|
|
280
280
|
* set the session to expire in 1 day.
|
|
281
281
|
* The cookie will be set to expire at the end of the session
|
|
282
282
|
*/
|
|
283
|
-
expiresAt: dontRememberMe ? getDate(
|
|
283
|
+
expiresAt: dontRememberMe ? getDate(86400, "sec") : getDate(sessionExpiration, "sec"),
|
|
284
284
|
userId,
|
|
285
285
|
token: generateId(32),
|
|
286
286
|
createdAt: /* @__PURE__ */ new Date(),
|
|
@@ -773,7 +773,8 @@ const createInternalAdapter = (adapter, ctx) => {
|
|
|
773
773
|
return verification[0] || null;
|
|
774
774
|
},
|
|
775
775
|
deleteVerificationByIdentifier: async (identifier) => {
|
|
776
|
-
const
|
|
776
|
+
const storageOption = getStorageOption(identifier, options.verification?.storeIdentifier);
|
|
777
|
+
const storedIdentifier = await processIdentifier(identifier, storageOption);
|
|
777
778
|
if (secondaryStorage) await secondaryStorage.delete(`verification:${storedIdentifier}`);
|
|
778
779
|
if (!secondaryStorage || options.verification?.storeInDatabase) await deleteWithHooks([{
|
|
779
780
|
field: "identifier",
|
|
@@ -938,7 +939,8 @@ const createInternalAdapter = (adapter, ctx) => {
|
|
|
938
939
|
return true;
|
|
939
940
|
},
|
|
940
941
|
updateVerificationByIdentifier: async (identifier, data) => {
|
|
941
|
-
const
|
|
942
|
+
const storageOption = getStorageOption(identifier, options.verification?.storeIdentifier);
|
|
943
|
+
const storedIdentifier = await processIdentifier(identifier, storageOption);
|
|
942
944
|
if (secondaryStorage) {
|
|
943
945
|
const cached = await secondaryStorage.get(`verification:${storedIdentifier}`);
|
|
944
946
|
if (cached) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { User } from "../types/models.mjs";
|
|
2
|
+
import "../types/index.mjs";
|
|
2
3
|
import { GenericEndpointContext } from "@better-auth/core";
|
|
3
|
-
|
|
4
4
|
//#region src/db/revoke-unproven-account-access.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Strip every account link and session a pre-existing account accrued before
|
|
@@ -16,6 +16,5 @@ import { GenericEndpointContext } from "@better-auth/core";
|
|
|
16
16
|
*
|
|
17
17
|
* @param userId - The pre-existing, not-yet-verified user being promoted.
|
|
18
18
|
*/
|
|
19
|
-
declare function revokeUnprovenAccountAccess(ctx: GenericEndpointContext, userId: string): Promise<User | null>;
|
|
20
|
-
//#endregion
|
|
21
|
-
export { revokeUnprovenAccountAccess };
|
|
19
|
+
export declare function revokeUnprovenAccountAccess(ctx: GenericEndpointContext, userId: string): Promise<User | null>;
|
|
20
|
+
//#endregion
|
package/dist/db/schema.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Account, Session as Session$1, User as User$1 } from "../types/models.mjs";
|
|
2
|
+
import "../types/index.mjs";
|
|
2
3
|
import { BetterAuthOptions } from "@better-auth/core";
|
|
3
4
|
import { BetterAuthPluginDBSchema, DBFieldAttribute } from "@better-auth/core/db";
|
|
4
|
-
|
|
5
5
|
//#region src/db/schema.d.ts
|
|
6
|
-
declare function parseUserOutput<T extends User$1>(options: BetterAuthOptions, user: T): T;
|
|
6
|
+
export declare function parseUserOutput<T extends User$1>(options: BetterAuthOptions, user: T): T;
|
|
7
7
|
/**
|
|
8
8
|
* Builds a synthetic user object that matches the shape of a real user
|
|
9
9
|
* returned from the database. This ensures enumeration protection works
|
|
@@ -16,17 +16,17 @@ declare function parseUserOutput<T extends User$1>(options: BetterAuthOptions, u
|
|
|
16
16
|
* - Applies default values where defined
|
|
17
17
|
* - Always includes the 'id' field (not part of schema but always present)
|
|
18
18
|
*/
|
|
19
|
-
declare function buildSyntheticUserOutput(options: BetterAuthOptions, data: Record<string, unknown>): Record<string, unknown>;
|
|
20
|
-
declare function parseSessionOutput<T extends Session$1>(options: BetterAuthOptions, session: T): T;
|
|
21
|
-
declare function parseAccountOutput<T extends Account>(options: BetterAuthOptions, account: T): Omit<T, "idToken" | "accessToken" | "refreshToken" | "accessTokenExpiresAt" | "refreshTokenExpiresAt" | "password">;
|
|
22
|
-
declare function parseInputData<T extends Record<string, any>>(data: T, schema: {
|
|
19
|
+
export declare function buildSyntheticUserOutput(options: BetterAuthOptions, data: Record<string, unknown>): Record<string, unknown>;
|
|
20
|
+
export declare function parseSessionOutput<T extends Session$1>(options: BetterAuthOptions, session: T): T;
|
|
21
|
+
export declare function parseAccountOutput<T extends Account>(options: BetterAuthOptions, account: T): Omit<T, "idToken" | "accessToken" | "refreshToken" | "accessTokenExpiresAt" | "refreshTokenExpiresAt" | "password">;
|
|
22
|
+
export declare function parseInputData<T extends Record<string, any>>(data: T, schema: {
|
|
23
23
|
fields: Record<string, DBFieldAttribute>;
|
|
24
24
|
action?: ("create" | "update") | undefined;
|
|
25
25
|
}): Partial<T>;
|
|
26
|
-
declare function parseUserInput(options: BetterAuthOptions, user: Record<string, any> | undefined, action: "create" | "update"): Partial<Record<string, any>>;
|
|
27
|
-
declare function parseAdditionalUserInputFromProviderProfile(options: BetterAuthOptions, profile: Record<string, unknown> | undefined, action: "create" | "update"): Partial<Record<string, unknown>>;
|
|
28
|
-
declare function parseAdditionalUserInput(options: BetterAuthOptions, user?: Record<string, any> | undefined): Partial<Record<string, any>>;
|
|
29
|
-
declare function parseAccountInput(options: BetterAuthOptions, account: Partial<Account>): Partial<Partial<{
|
|
26
|
+
export declare function parseUserInput(options: BetterAuthOptions, user: Record<string, any> | undefined, action: "create" | "update"): Partial<Record<string, any>>;
|
|
27
|
+
export declare function parseAdditionalUserInputFromProviderProfile(options: BetterAuthOptions, profile: Record<string, unknown> | undefined, action: "create" | "update"): Partial<Record<string, unknown>>;
|
|
28
|
+
export declare function parseAdditionalUserInput(options: BetterAuthOptions, user?: Record<string, any> | undefined): Partial<Record<string, any>>;
|
|
29
|
+
export declare function parseAccountInput(options: BetterAuthOptions, account: Partial<Account>): Partial<Partial<{
|
|
30
30
|
id: string;
|
|
31
31
|
createdAt: Date;
|
|
32
32
|
updatedAt: Date;
|
|
@@ -41,7 +41,7 @@ declare function parseAccountInput(options: BetterAuthOptions, account: Partial<
|
|
|
41
41
|
scope?: string | null | undefined;
|
|
42
42
|
password?: string | null | undefined;
|
|
43
43
|
}>>;
|
|
44
|
-
declare function parseSessionInput(options: BetterAuthOptions, session: Partial<Session$1>, action?: "create" | "update"): Partial<Partial<{
|
|
44
|
+
export declare function parseSessionInput(options: BetterAuthOptions, session: Partial<Session$1>, action?: "create" | "update"): Partial<Partial<{
|
|
45
45
|
id: string;
|
|
46
46
|
createdAt: Date;
|
|
47
47
|
updatedAt: Date;
|
|
@@ -51,12 +51,11 @@ declare function parseSessionInput(options: BetterAuthOptions, session: Partial<
|
|
|
51
51
|
ipAddress?: string | null | undefined;
|
|
52
52
|
userAgent?: string | null | undefined;
|
|
53
53
|
}>>;
|
|
54
|
-
declare function getSessionDefaultFields(options: BetterAuthOptions): Record<string, any>;
|
|
55
|
-
declare function mergeSchema<S extends BetterAuthPluginDBSchema>(schema: S, newSchema?: { [K in keyof S]?: {
|
|
54
|
+
export declare function getSessionDefaultFields(options: BetterAuthOptions): Record<string, any>;
|
|
55
|
+
export declare function mergeSchema<S extends BetterAuthPluginDBSchema>(schema: S, newSchema?: { [K in keyof S]?: {
|
|
56
56
|
modelName?: string | undefined;
|
|
57
57
|
fields?: {
|
|
58
58
|
[P: string]: string;
|
|
59
59
|
} | undefined;
|
|
60
|
-
} | undefined } | undefined): S;
|
|
61
|
-
//#endregion
|
|
62
|
-
export { buildSyntheticUserOutput, getSessionDefaultFields, mergeSchema, parseAccountInput, parseAccountOutput, parseAdditionalUserInput, parseAdditionalUserInputFromProviderProfile, parseInputData, parseSessionInput, parseSessionOutput, parseUserInput, parseUserOutput };
|
|
60
|
+
} | undefined; } | undefined): S;
|
|
61
|
+
//#endregion
|
package/dist/db/schema.mjs
CHANGED
|
@@ -22,7 +22,8 @@ function getFields(options, modelName, mode) {
|
|
|
22
22
|
return schema;
|
|
23
23
|
}
|
|
24
24
|
function parseUserOutput(options, user) {
|
|
25
|
-
|
|
25
|
+
const schema = getFields(options, "user", "output");
|
|
26
|
+
return filterOutputFields(user, schema);
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
28
29
|
* Builds a synthetic user object that matches the shape of a real user
|
|
@@ -50,10 +51,12 @@ function buildSyntheticUserOutput(options, data) {
|
|
|
50
51
|
return result;
|
|
51
52
|
}
|
|
52
53
|
function parseSessionOutput(options, session) {
|
|
53
|
-
|
|
54
|
+
const schema = getFields(options, "session", "output");
|
|
55
|
+
return filterOutputFields(session, schema);
|
|
54
56
|
}
|
|
55
57
|
function parseAccountOutput(options, account) {
|
|
56
|
-
const
|
|
58
|
+
const schema = getFields(options, "account", "output");
|
|
59
|
+
const { accessToken: _accessToken, refreshToken: _refreshToken, idToken: _idToken, accessTokenExpiresAt: _accessTokenExpiresAt, refreshTokenExpiresAt: _refreshTokenExpiresAt, password: _password, ...rest } = filterOutputFields(account, schema);
|
|
57
60
|
return rest;
|
|
58
61
|
}
|
|
59
62
|
function parseInputData(data, schema) {
|
package/dist/db/to-zod.d.mts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { DBFieldAttribute } from "@better-auth/core/db";
|
|
2
2
|
import * as z from "zod";
|
|
3
|
-
|
|
4
3
|
//#region src/db/to-zod.d.ts
|
|
5
|
-
declare function toZodSchema<Fields extends Record<string, DBFieldAttribute | never>, IsClientSide extends boolean>({
|
|
6
|
-
fields,
|
|
7
|
-
isClientSide
|
|
8
|
-
}: {
|
|
4
|
+
export declare function toZodSchema<Fields extends Record<string, DBFieldAttribute | never>, IsClientSide extends boolean>({ fields, isClientSide }: {
|
|
9
5
|
fields: Fields;
|
|
10
6
|
/**
|
|
11
7
|
* If true, then any fields that have `input: false` will be removed from the schema to prevent user input.
|
|
@@ -13,8 +9,8 @@ declare function toZodSchema<Fields extends Record<string, DBFieldAttribute | ne
|
|
|
13
9
|
isClientSide: IsClientSide;
|
|
14
10
|
}): ZodSchemaForSide<Fields, IsClientSide>;
|
|
15
11
|
type ZodSchemaForSide<Fields extends Record<string, DBFieldAttribute | never>, IsClientSide extends boolean> = IsClientSide extends true ? z.ZodObject<SchemaShape<Fields, true>, z.core.$strip> : z.ZodObject<SchemaShape<Fields, false>, z.core.$strip>;
|
|
16
|
-
type SchemaShape<Fields extends Record<string, DBFieldAttribute | never>, IsClientSide extends boolean> = RemoveNeverProps<{ [key in keyof Fields]: FieldAttributeToSchema<Fields[key], IsClientSide
|
|
17
|
-
type FieldAttributeToSchema<Field extends DBFieldAttribute | Record<string, never>, isClientSide extends boolean = false> = Field extends DBFieldAttribute ? GetSchemaForSide<isClientSide, Field, GetRequired<Field, GetType<Field>>> : Record<string, never>;
|
|
12
|
+
type SchemaShape<Fields extends Record<string, DBFieldAttribute | never>, IsClientSide extends boolean> = RemoveNeverProps<{ [key in keyof Fields]: FieldAttributeToSchema<Fields[key], IsClientSide>; }>;
|
|
13
|
+
export type FieldAttributeToSchema<Field extends DBFieldAttribute | Record<string, never>, isClientSide extends boolean = false> = Field extends DBFieldAttribute ? GetSchemaForSide<isClientSide, Field, GetRequired<Field, GetType<Field>>> : Record<string, never>;
|
|
18
14
|
type GetType<F extends DBFieldAttribute> = F extends {
|
|
19
15
|
type: "string";
|
|
20
16
|
} ? z.ZodString : F extends {
|
|
@@ -32,6 +28,6 @@ type GetSchemaForSide<isClientSide extends boolean, Field extends DBFieldAttribu
|
|
|
32
28
|
} ? never : Schema : Field extends {
|
|
33
29
|
returned: false;
|
|
34
30
|
} ? never : Schema;
|
|
35
|
-
type RemoveNeverProps<T> = { [K in keyof T as [T[K]] extends [never] ? never : K]: T[K] };
|
|
31
|
+
type RemoveNeverProps<T> = { [K in keyof T as [T[K]] extends [never] ? never : K]: T[K]; };
|
|
36
32
|
//#endregion
|
|
37
|
-
export {
|
|
33
|
+
export {};
|
package/dist/db/with-hooks.d.mts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { BetterAuthOptions } from "@better-auth/core";
|
|
2
2
|
import { BaseModelNames } from "@better-auth/core/db";
|
|
3
3
|
import { DBAdapter, Where } from "@better-auth/core/db/adapter";
|
|
4
|
-
|
|
5
4
|
//#region src/db/with-hooks.d.ts
|
|
6
|
-
type DatabaseHooksEntry = {
|
|
5
|
+
export type DatabaseHooksEntry = {
|
|
7
6
|
source: string;
|
|
8
7
|
hooks: Exclude<BetterAuthOptions["databaseHooks"], undefined>;
|
|
9
8
|
};
|
|
10
|
-
declare function getWithHooks(adapter: DBAdapter<BetterAuthOptions>, ctx: {
|
|
9
|
+
export declare function getWithHooks(adapter: DBAdapter<BetterAuthOptions>, ctx: {
|
|
11
10
|
options: BetterAuthOptions;
|
|
12
11
|
hooks: DatabaseHooksEntry[];
|
|
13
12
|
}): {
|
|
@@ -33,5 +32,4 @@ declare function getWithHooks(adapter: DBAdapter<BetterAuthOptions>, ctx: {
|
|
|
33
32
|
} | undefined) => Promise<any>;
|
|
34
33
|
consumeOneWithHooks: <T extends Record<string, any>>(model: BaseModelNames, hookWhere: Where[], consumeFn: () => Promise<T | null>, preSnapshot?: T | null) => Promise<T | null>;
|
|
35
34
|
};
|
|
36
|
-
//#endregion
|
|
37
|
-
export { DatabaseHooksEntry, getWithHooks };
|
|
35
|
+
//#endregion
|
package/dist/index.d.mts
CHANGED
|
@@ -11,6 +11,7 @@ import { GenerateStateOptions, generateIdTokenNonce, generateState, parseState }
|
|
|
11
11
|
import { StateData, generateGenericState, parseGenericState } from "./state.mjs";
|
|
12
12
|
import { HIDE_METADATA } from "./utils/hide-metadata.mjs";
|
|
13
13
|
import { getBaseURL, getHost, getHostFromSource, getOrigin, getProtocol, getProtocolFromSource, isDynamicBaseURLConfig, isRequestLike, matchesHostPattern, resolveBaseURL, resolveDynamicBaseURL, trimTrailingSlashes } from "./utils/url.mjs";
|
|
14
|
+
import "./utils/index.mjs";
|
|
14
15
|
import { APIError } from "./api/index.mjs";
|
|
15
16
|
import { StandardSchemaV1 } from "@better-auth/core";
|
|
16
17
|
import { getCurrentAdapter } from "@better-auth/core/context";
|
|
@@ -25,6 +26,6 @@ export * from "@better-auth/core/utils/error-codes";
|
|
|
25
26
|
export * from "@better-auth/core/utils/id";
|
|
26
27
|
export * from "@better-auth/core/utils/json";
|
|
27
28
|
export * from "@better-auth/core/social-providers";
|
|
28
|
-
export * from "better-call";
|
|
29
|
-
export * from "zod";
|
|
30
|
-
export { APIError, Account, AdditionalSessionFieldsInput, AdditionalUserFieldsInput, Auth, BetterAuthAdvancedOptions, BetterAuthClientOptions, BetterAuthClientPlugin, BetterAuthCookies, BetterAuthOptions, BetterAuthPlugin, BetterAuthRateLimitOptions, ClientAtomListener, ClientStore, DBAdapter, DBAdapterInstance, DBAdapterSchemaCreation, DBTransactionAdapter, ExtractPluginField, FilteredAPI, GenerateStateOptions, HIDE_METADATA, HasRequiredKeys, InferAPI, InferActions, InferAdditionalFromClient, InferClientAPI, InferErrorCodes, InferOptionSchema, InferPluginContext, InferPluginErrorCodes, InferPluginFieldFromTuple, InferPluginIDs, InferPluginTypes, InferSessionAPI, InferSessionFromClient, InferUserFromClient, IsAny, IsSignal, type JSONWebKeySet, type JWTPayload, JoinConfig, JoinOption, OverrideMerge, Prettify, PrettifyDeep, RateLimit, RequiredKeysOf, Session, SessionQueryParams, type StandardSchemaV1, StateData, StoreIdentifierOption, StripEmptyObjects, type TelemetryEvent, UnionToIntersection, User, UserProvisioningSource, ValidateUserInfoAction, ValidateUserInfoMethod, ValidateUserInfoOAuthInfo, ValidateUserInfoResult, ValidateUserInfoSSOInfo, ValidateUserInfoSource, Verification, Where, betterAuth, createTelemetry, generateGenericState, generateIdTokenNonce, generateState, getBaseURL, getCurrentAdapter, getHost, getHostFromSource, getOrigin, getProtocol, getProtocolFromSource, getTelemetryAuthConfig, isDynamicBaseURLConfig, isRequestLike, matchesHostPattern, parseGenericState, parseState, resolveBaseURL, resolveDynamicBaseURL, trimTrailingSlashes };
|
|
29
|
+
export type * from "better-call";
|
|
30
|
+
export type * from "zod";
|
|
31
|
+
export { APIError, type Account, type AdditionalSessionFieldsInput, type AdditionalUserFieldsInput, type Auth, type BetterAuthAdvancedOptions, type BetterAuthClientOptions, type BetterAuthClientPlugin, type BetterAuthCookies, type BetterAuthOptions, type BetterAuthPlugin, type BetterAuthRateLimitOptions, type ClientAtomListener, type ClientStore, type DBAdapter, type DBAdapterInstance, type DBAdapterSchemaCreation, type DBTransactionAdapter, type ExtractPluginField, FilteredAPI, GenerateStateOptions, HIDE_METADATA, type HasRequiredKeys, InferAPI, InferActions, InferAdditionalFromClient, InferClientAPI, InferErrorCodes, type InferOptionSchema, type InferPluginContext, type InferPluginErrorCodes, type InferPluginFieldFromTuple, type InferPluginIDs, type InferPluginTypes, InferSessionAPI, InferSessionFromClient, InferUserFromClient, type IsAny, IsSignal, type JSONWebKeySet, type JWTPayload, type JoinConfig, type JoinOption, type OverrideMerge, type Prettify, type PrettifyDeep, type RateLimit, type RequiredKeysOf, type Session, SessionQueryParams, type StandardSchemaV1, type StateData, type StoreIdentifierOption, type StripEmptyObjects, type TelemetryEvent, type UnionToIntersection, type User, type UserProvisioningSource, type ValidateUserInfoAction, type ValidateUserInfoMethod, type ValidateUserInfoOAuthInfo, type ValidateUserInfoResult, type ValidateUserInfoSSOInfo, type ValidateUserInfoSource, type Verification, type Where, betterAuth, createTelemetry, generateGenericState, generateIdTokenNonce, generateState, getBaseURL, getCurrentAdapter, getHost, getHostFromSource, getOrigin, getProtocol, getProtocolFromSource, getTelemetryAuthConfig, isDynamicBaseURLConfig, isRequestLike, matchesHostPattern, parseGenericState, parseState, resolveBaseURL, resolveDynamicBaseURL, trimTrailingSlashes };
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import * as _$_better_auth_core0 from "@better-auth/core";
|
|
2
|
-
import * as _$better_call0 from "better-call";
|
|
3
|
-
|
|
4
1
|
//#region src/integrations/next-js.d.ts
|
|
5
|
-
declare function toNextJsHandler(auth: {
|
|
2
|
+
export declare function toNextJsHandler(auth: {
|
|
6
3
|
handler: (request: Request) => Promise<Response>;
|
|
7
4
|
} | ((request: Request) => Promise<Response>)): {
|
|
8
5
|
GET: (request: Request) => Promise<Response>;
|
|
@@ -11,19 +8,18 @@ declare function toNextJsHandler(auth: {
|
|
|
11
8
|
PUT: (request: Request) => Promise<Response>;
|
|
12
9
|
DELETE: (request: Request) => Promise<Response>;
|
|
13
10
|
};
|
|
14
|
-
declare const nextCookies: () => {
|
|
11
|
+
export declare const nextCookies: () => {
|
|
15
12
|
id: "next-cookies";
|
|
16
13
|
version: string;
|
|
17
14
|
hooks: {
|
|
18
15
|
before: {
|
|
19
|
-
matcher(ctx:
|
|
20
|
-
handler:
|
|
16
|
+
matcher(ctx: import("@better-auth/core").HookEndpointContext): boolean;
|
|
17
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
21
18
|
}[];
|
|
22
19
|
after: {
|
|
23
|
-
matcher(ctx:
|
|
24
|
-
handler:
|
|
20
|
+
matcher(ctx: import("@better-auth/core").HookEndpointContext): true;
|
|
21
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
25
22
|
}[];
|
|
26
23
|
};
|
|
27
24
|
};
|
|
28
|
-
//#endregion
|
|
29
|
-
export { nextCookies, toNextJsHandler };
|
|
25
|
+
//#endregion
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { Auth } from "../types/auth.mjs";
|
|
2
|
-
import
|
|
2
|
+
import "../types/index.mjs";
|
|
3
3
|
import { IncomingHttpHeaders } from "node:http";
|
|
4
|
-
|
|
5
4
|
//#region src/integrations/node.d.ts
|
|
6
|
-
declare const toNodeHandler: (auth: {
|
|
5
|
+
export declare const toNodeHandler: (auth: {
|
|
7
6
|
handler: Auth["handler"];
|
|
8
|
-
} | Auth["handler"]) => (req:
|
|
9
|
-
declare function fromNodeHeaders(nodeHeaders: IncomingHttpHeaders): Headers;
|
|
10
|
-
//#endregion
|
|
11
|
-
export { fromNodeHeaders, toNodeHandler };
|
|
7
|
+
} | Auth["handler"]) => (req: import("node:http").IncomingMessage, res: import("node:http").ServerResponse) => Promise<void>;
|
|
8
|
+
export declare function fromNodeHeaders(nodeHeaders: IncomingHttpHeaders): Headers;
|
|
9
|
+
//#endregion
|
|
@@ -5,8 +5,10 @@ const toNodeHandler = (auth) => {
|
|
|
5
5
|
};
|
|
6
6
|
function fromNodeHeaders(nodeHeaders) {
|
|
7
7
|
const webHeaders = new Headers();
|
|
8
|
-
for (const [key, value] of Object.entries(nodeHeaders)) if (value !== void 0)
|
|
9
|
-
|
|
8
|
+
for (const [key, value] of Object.entries(nodeHeaders)) if (value !== void 0) {
|
|
9
|
+
if (Array.isArray(value)) value.forEach((v) => webHeaders.append(key, v));
|
|
10
|
+
else webHeaders.set(key, value);
|
|
11
|
+
}
|
|
10
12
|
return webHeaders;
|
|
11
13
|
}
|
|
12
14
|
//#endregion
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/integrations/solid-start.d.ts
|
|
2
|
-
declare function toSolidStartHandler(auth: {
|
|
2
|
+
export declare function toSolidStartHandler(auth: {
|
|
3
3
|
handler: (request: Request) => Promise<Response>;
|
|
4
4
|
} | ((request: Request) => Promise<Response>)): {
|
|
5
5
|
GET: (event: {
|
|
@@ -18,5 +18,4 @@ declare function toSolidStartHandler(auth: {
|
|
|
18
18
|
request: Request;
|
|
19
19
|
}) => Promise<Response>;
|
|
20
20
|
};
|
|
21
|
-
//#endregion
|
|
22
|
-
export { toSolidStartHandler };
|
|
21
|
+
//#endregion
|
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
import { BetterAuthOptions } from "../types/index.mjs";
|
|
2
|
-
import * as _$better_call0 from "better-call";
|
|
3
2
|
import { RequestEvent } from "@sveltejs/kit";
|
|
4
|
-
|
|
5
3
|
//#region src/integrations/svelte-kit.d.ts
|
|
6
|
-
declare const toSvelteKitHandler: (auth: {
|
|
4
|
+
export declare const toSvelteKitHandler: (auth: {
|
|
7
5
|
handler: (request: Request) => Response | Promise<Response>;
|
|
8
6
|
options: BetterAuthOptions;
|
|
9
7
|
}) => (event: {
|
|
10
8
|
request: Request;
|
|
11
9
|
}) => Response | Promise<Response>;
|
|
12
|
-
declare const svelteKitHandler: ({
|
|
13
|
-
auth,
|
|
14
|
-
event,
|
|
15
|
-
resolve,
|
|
16
|
-
building
|
|
17
|
-
}: {
|
|
10
|
+
export declare const svelteKitHandler: ({ auth, event, resolve, building }: {
|
|
18
11
|
auth: {
|
|
19
12
|
handler: (request: Request) => Response | Promise<Response>;
|
|
20
13
|
options: BetterAuthOptions;
|
|
@@ -23,16 +16,15 @@ declare const svelteKitHandler: ({
|
|
|
23
16
|
resolve: (event: RequestEvent) => Response | Promise<Response>;
|
|
24
17
|
building: boolean;
|
|
25
18
|
}) => Promise<Response>;
|
|
26
|
-
declare function isAuthPath(url: string, options: BetterAuthOptions): boolean;
|
|
27
|
-
declare const sveltekitCookies: (getRequestEvent: () => RequestEvent<any, any>) => {
|
|
19
|
+
export declare function isAuthPath(url: string, options: BetterAuthOptions): boolean;
|
|
20
|
+
export declare const sveltekitCookies: (getRequestEvent: () => RequestEvent<any, any>) => {
|
|
28
21
|
id: "sveltekit-cookies";
|
|
29
22
|
version: string;
|
|
30
23
|
hooks: {
|
|
31
24
|
after: {
|
|
32
25
|
matcher(): true;
|
|
33
|
-
handler:
|
|
26
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
34
27
|
}[];
|
|
35
28
|
};
|
|
36
29
|
};
|
|
37
|
-
//#endregion
|
|
38
|
-
export { isAuthPath, svelteKitHandler, sveltekitCookies, toSvelteKitHandler };
|
|
30
|
+
//#endregion
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import * as _$_better_auth_core0 from "@better-auth/core";
|
|
2
|
-
import * as _$better_call0 from "better-call";
|
|
3
|
-
|
|
4
1
|
//#region src/integrations/tanstack-start-solid.d.ts
|
|
5
2
|
/**
|
|
6
3
|
* TanStack Start cookie plugin for Solid.js.
|
|
@@ -19,15 +16,14 @@ import * as _$better_call0 from "better-call";
|
|
|
19
16
|
* });
|
|
20
17
|
* ```
|
|
21
18
|
*/
|
|
22
|
-
declare const tanstackStartCookies: () => {
|
|
19
|
+
export declare const tanstackStartCookies: () => {
|
|
23
20
|
id: "tanstack-start-cookies-solid";
|
|
24
21
|
version: string;
|
|
25
22
|
hooks: {
|
|
26
23
|
after: {
|
|
27
|
-
matcher(ctx:
|
|
28
|
-
handler:
|
|
24
|
+
matcher(ctx: import("@better-auth/core").HookEndpointContext): true;
|
|
25
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
29
26
|
}[];
|
|
30
27
|
};
|
|
31
28
|
};
|
|
32
|
-
//#endregion
|
|
33
|
-
export { tanstackStartCookies };
|
|
29
|
+
//#endregion
|