@better-auth/core 1.7.0-rc.4 → 1.7.0-rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/index.d.mts +39 -60
- package/dist/api/index.mjs +39 -26
- package/dist/async_hooks/index.d.mts +1 -0
- package/dist/async_hooks/pure.index.d.mts +1 -0
- package/dist/context/endpoint-context.d.mts +1 -1
- package/dist/context/global.d.mts +1 -0
- package/dist/context/global.mjs +1 -1
- package/dist/context/request-state.d.mts +1 -0
- package/dist/context/transaction.d.mts +2 -3
- package/dist/db/adapter/factory.d.mts +5 -3
- package/dist/db/adapter/factory.mjs +1 -1
- package/dist/db/adapter/get-default-field-name.d.mts +9 -2
- package/dist/db/adapter/get-default-model-name.d.mts +5 -1
- package/dist/db/adapter/get-field-attributes.d.mts +11 -4
- package/dist/db/adapter/get-field-name.d.mts +9 -2
- package/dist/db/adapter/get-id-field.d.mts +12 -4
- package/dist/db/adapter/get-model-name.d.mts +5 -1
- package/dist/db/adapter/index.d.mts +32 -7
- package/dist/db/adapter/types.d.mts +17 -5
- package/dist/db/adapter/utils.d.mts +1 -0
- package/dist/db/database-index.d.mts +12 -2
- package/dist/db/get-tables.d.mts +0 -1
- package/dist/db/plugin.d.mts +3 -3
- package/dist/db/schema/account.d.mts +1 -1
- package/dist/db/schema/rate-limit.d.mts +1 -1
- package/dist/db/schema/session.d.mts +1 -1
- package/dist/db/schema/shared.d.mts +1 -0
- package/dist/db/schema/user.d.mts +1 -1
- package/dist/db/schema/verification.d.mts +1 -1
- package/dist/db/type.d.mts +11 -8
- package/dist/env/logger.d.mts +25 -25
- package/dist/error/codes.d.mts +1 -0
- package/dist/error/index.d.mts +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/instrumentation/attributes.d.mts +1 -0
- package/dist/instrumentation/pure.index.d.mts +1 -0
- package/dist/instrumentation/tracer.mjs +1 -1
- package/dist/oauth2/authorization-params.d.mts +1 -0
- package/dist/oauth2/client-assertion.d.mts +13 -3
- package/dist/oauth2/client-credentials-token.d.mts +17 -3
- package/dist/oauth2/create-authorization-url.d.mts +21 -3
- package/dist/oauth2/dpop.d.mts +23 -2
- package/dist/oauth2/dpop.mjs +1 -1
- package/dist/oauth2/oauth-provider.d.mts +7 -13
- package/dist/oauth2/refresh-access-token.d.mts +19 -3
- package/dist/oauth2/refresh-access-token.mjs +1 -1
- package/dist/oauth2/reject-redirects.mjs +1 -1
- package/dist/oauth2/token-endpoint-auth.d.mts +1 -0
- package/dist/oauth2/utils.d.mts +1 -0
- package/dist/oauth2/utils.mjs +1 -1
- package/dist/oauth2/validate-authorization-code.d.mts +29 -5
- package/dist/oauth2/verify-id-token.d.mts +1 -1
- package/dist/oauth2/verify.d.mts +7 -5
- package/dist/oauth2/verify.mjs +2 -2
- package/dist/social-providers/apple.d.mts +18 -5
- package/dist/social-providers/atlassian.d.mts +15 -4
- package/dist/social-providers/cognito.d.mts +18 -5
- package/dist/social-providers/discord.d.mts +13 -4
- package/dist/social-providers/dropbox.d.mts +15 -4
- package/dist/social-providers/facebook.d.mts +18 -6
- package/dist/social-providers/figma.d.mts +15 -4
- package/dist/social-providers/github.d.mts +16 -4
- package/dist/social-providers/gitlab.d.mts +16 -4
- package/dist/social-providers/google.d.mts +25 -6
- package/dist/social-providers/huggingface.d.mts +15 -4
- package/dist/social-providers/index.d.mts +504 -113
- package/dist/social-providers/kakao.d.mts +13 -4
- package/dist/social-providers/kick.d.mts +15 -4
- package/dist/social-providers/line.d.mts +16 -4
- package/dist/social-providers/linear.d.mts +14 -4
- package/dist/social-providers/linkedin.d.mts +14 -4
- package/dist/social-providers/microsoft-entra-id.d.mts +14 -5
- package/dist/social-providers/microsoft-entra-id.mjs +1 -2
- package/dist/social-providers/naver.d.mts +22 -23
- package/dist/social-providers/notion.d.mts +14 -4
- package/dist/social-providers/paybin.d.mts +16 -4
- package/dist/social-providers/paypal.d.mts +13 -4
- package/dist/social-providers/polar.d.mts +15 -4
- package/dist/social-providers/railway.d.mts +15 -4
- package/dist/social-providers/reddit.d.mts +13 -4
- package/dist/social-providers/roblox.d.mts +13 -4
- package/dist/social-providers/salesforce.d.mts +15 -4
- package/dist/social-providers/slack.d.mts +13 -4
- package/dist/social-providers/spotify.d.mts +15 -4
- package/dist/social-providers/tiktok.d.mts +14 -6
- package/dist/social-providers/twitch.d.mts +13 -4
- package/dist/social-providers/twitter.d.mts +19 -26
- package/dist/social-providers/vercel.d.mts +15 -4
- package/dist/social-providers/vk.d.mts +16 -4
- package/dist/social-providers/wechat.d.mts +12 -4
- package/dist/social-providers/zoom.d.mts +18 -6
- package/dist/types/context.d.mts +2 -2
- package/dist/types/cookie.d.mts +1 -1
- package/dist/types/helper.d.mts +1 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/types/init-options.d.mts +18 -26
- package/dist/types/plugin-client.d.mts +3 -1
- package/dist/types/plugin.d.mts +2 -2
- package/dist/utils/async.d.mts +1 -0
- package/dist/utils/db.d.mts +0 -1
- package/dist/utils/deprecate.d.mts +1 -0
- package/dist/utils/email.d.mts +4 -1
- package/dist/utils/error-codes.d.mts +2 -2
- package/dist/utils/host.d.mts +1 -27
- package/dist/utils/host.mjs +1 -1
- package/dist/utils/ip.d.mts +0 -1
- package/dist/utils/ip.mjs +1 -1
- package/dist/utils/is-api-error.d.mts +1 -0
- package/dist/utils/redirect-uri.d.mts +1 -0
- package/package.json +4 -4
- package/src/api/index.ts +96 -95
- package/src/db/type.ts +2 -1
- package/src/types/init-options.ts +6 -4
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DBFieldAttribute, DBTableIndex } from "./type.mjs";
|
|
2
|
+
|
|
2
3
|
//#region src/db/database-index.d.ts
|
|
3
4
|
declare function getPortableDatabaseIdentifierKey(identifier: string): string;
|
|
4
5
|
/** A table-level index resolved to physical database columns. */
|
|
@@ -18,7 +19,11 @@ declare function getDatabaseIndexName(tableName: string, index: DBTableIndex): s
|
|
|
18
19
|
/** Returns the database name used by legacy field-level index metadata. */
|
|
19
20
|
declare function getDatabaseFieldIndexName(tableName: string, columnName: string, unique: boolean): string;
|
|
20
21
|
/** Resolves logical index fields to their configured database column names. */
|
|
21
|
-
declare function resolveDatabaseTableIndexes({
|
|
22
|
+
declare function resolveDatabaseTableIndexes({
|
|
23
|
+
fields,
|
|
24
|
+
indexes,
|
|
25
|
+
tableName
|
|
26
|
+
}: {
|
|
22
27
|
fields: Readonly<Record<string, DBFieldAttribute>>;
|
|
23
28
|
indexes: readonly DBTableIndex[] | undefined;
|
|
24
29
|
tableName: string;
|
|
@@ -27,7 +32,12 @@ declare function resolveDatabaseTableIndexes({ fields, indexes, tableName }: {
|
|
|
27
32
|
* Returns a safe generated string length for a column across all of its table
|
|
28
33
|
* indexes in byte-limited SQL dialects.
|
|
29
34
|
*/
|
|
30
|
-
declare function getDatabaseIndexStringLength({
|
|
35
|
+
declare function getDatabaseIndexStringLength({
|
|
36
|
+
columnName,
|
|
37
|
+
dialect,
|
|
38
|
+
fields,
|
|
39
|
+
indexes
|
|
40
|
+
}: {
|
|
31
41
|
columnName: string;
|
|
32
42
|
dialect: BoundedDatabaseIndexDialect;
|
|
33
43
|
fields: Readonly<Record<string, DBFieldAttribute>>;
|
package/dist/db/get-tables.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { BetterAuthDBSchema } from "./type.mjs";
|
|
2
2
|
import { ResolvedDBTableIndex } from "./database-index.mjs";
|
|
3
3
|
import { BetterAuthOptions } from "../types/init-options.mjs";
|
|
4
|
-
import "../types/index.mjs";
|
|
5
4
|
//#region src/db/get-tables.d.ts
|
|
6
5
|
declare function getAuthTablesWithResolvedIndexes(options: BetterAuthOptions): {
|
|
7
6
|
indexesByTable: ReadonlyMap<string, readonly ResolvedDBTableIndex[]>;
|
package/dist/db/plugin.d.mts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { DBFieldAttribute, DBTableIndex } from "./type.mjs";
|
|
2
|
+
|
|
2
3
|
//#region src/db/plugin.d.ts
|
|
3
4
|
type BetterAuthPluginDBSchema = { [table in string]: {
|
|
4
5
|
fields: {
|
|
5
6
|
[field: string]: DBFieldAttribute;
|
|
6
|
-
};
|
|
7
|
-
/** Table-level indexes, including compound indexes. */
|
|
7
|
+
}; /** Table-level indexes, including compound indexes. */
|
|
8
8
|
indexes?: readonly DBTableIndex[] | undefined;
|
|
9
9
|
disableMigration?: boolean | undefined;
|
|
10
10
|
modelName?: string | undefined;
|
|
11
|
-
}
|
|
11
|
+
} };
|
|
12
12
|
//#endregion
|
|
13
13
|
export { BetterAuthPluginDBSchema };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { InferDBFieldsFromOptions, InferDBFieldsFromPlugins } from "../type.mjs";
|
|
2
2
|
import { Prettify } from "../../types/helper.mjs";
|
|
3
3
|
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
4
|
-
import "../../types/index.mjs";
|
|
5
4
|
import * as z from "zod";
|
|
5
|
+
|
|
6
6
|
//#region src/db/schema/account.d.ts
|
|
7
7
|
declare const accountSchema: z.ZodObject<{
|
|
8
8
|
id: z.ZodString;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { InferDBFieldsFromOptions, InferDBFieldsFromPlugins } from "../type.mjs";
|
|
2
2
|
import { Prettify } from "../../types/helper.mjs";
|
|
3
3
|
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
4
|
-
import "../../types/index.mjs";
|
|
5
4
|
import * as z from "zod";
|
|
5
|
+
|
|
6
6
|
//#region src/db/schema/rate-limit.d.ts
|
|
7
7
|
declare const rateLimitSchema: z.ZodObject<{
|
|
8
8
|
key: z.ZodString;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { InferDBFieldsFromOptions, InferDBFieldsFromPlugins } from "../type.mjs";
|
|
2
2
|
import { Prettify } from "../../types/helper.mjs";
|
|
3
3
|
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
4
|
-
import "../../types/index.mjs";
|
|
5
4
|
import * as z from "zod";
|
|
5
|
+
|
|
6
6
|
//#region src/db/schema/session.d.ts
|
|
7
7
|
declare const sessionSchema: z.ZodObject<{
|
|
8
8
|
id: z.ZodString;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { InferDBFieldsFromOptions, InferDBFieldsFromPlugins } from "../type.mjs";
|
|
2
2
|
import { Prettify } from "../../types/helper.mjs";
|
|
3
3
|
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
4
|
-
import "../../types/index.mjs";
|
|
5
4
|
import * as z from "zod";
|
|
5
|
+
|
|
6
6
|
//#region src/db/schema/user.d.ts
|
|
7
7
|
declare const userSchema: z.ZodObject<{
|
|
8
8
|
id: z.ZodString;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { InferDBFieldsFromOptions, InferDBFieldsFromPlugins } from "../type.mjs";
|
|
2
2
|
import { Prettify } from "../../types/helper.mjs";
|
|
3
3
|
import { BetterAuthOptions } from "../../types/init-options.mjs";
|
|
4
|
-
import "../../types/index.mjs";
|
|
5
4
|
import * as z from "zod";
|
|
5
|
+
|
|
6
6
|
//#region src/db/schema/verification.d.ts
|
|
7
7
|
declare const verificationSchema: z.ZodObject<{
|
|
8
8
|
id: z.ZodString;
|
package/dist/db/type.d.mts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Awaitable, LiteralString, UnionToIntersection } from "../types/helper.mjs";
|
|
2
2
|
import { BetterAuthOptions } from "../types/init-options.mjs";
|
|
3
|
-
import "../types/index.mjs";
|
|
4
3
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
4
|
+
|
|
5
5
|
//#region src/db/type.d.ts
|
|
6
6
|
type BaseModelNames = "user" | "account" | "session" | "verification";
|
|
7
7
|
type ModelNames<T extends string = LiteralString> = BaseModelNames | T | "rate-limit";
|
|
8
8
|
type InferDBValueType<T extends DBFieldType> = T extends "string" ? string : T extends "number" ? number : T extends "boolean" ? boolean : T extends "date" ? Date : T extends "json" ? Record<string, any> : T extends `${infer U}[]` ? U extends "string" ? string[] : number[] : T extends Array<any> ? T[number] : never;
|
|
9
9
|
type InferDBFieldOutput<T extends DBFieldAttribute> = T["returned"] extends false ? never : T["required"] extends false ? InferDBValueType<T["type"]> | undefined | null : InferDBValueType<T["type"]>;
|
|
10
10
|
type InferDBFieldInput<T extends DBFieldAttribute> = InferDBValueType<T["type"]>;
|
|
11
|
-
type InferDBFieldsInput<Field> = Field extends Record<infer Key, DBFieldAttribute> ? { [key in Key as Field[key]["required"] extends false ? never : Field[key]["defaultValue"] extends string | number | boolean | Date ? never : Field[key]["input"] extends false ? never : key]: InferDBFieldInput<Field[key]
|
|
12
|
-
type InferDBFieldsOutput<Fields extends Record<string, DBFieldAttribute>> = Fields extends Record<infer Key, DBFieldAttribute> ? { [key in Key as Fields[key]["returned"] extends false ? never : Fields[key]["required"] extends false ? Fields[key]["defaultValue"] extends boolean | string | number | Date ? key : never : key]: InferDBFieldOutput<Fields[key]
|
|
11
|
+
type InferDBFieldsInput<Field> = Field extends Record<infer Key, DBFieldAttribute> ? { [key in Key as Field[key]["required"] extends false ? never : Field[key]["defaultValue"] extends string | number | boolean | Date ? never : Field[key]["input"] extends false ? never : key]: InferDBFieldInput<Field[key]> } & { [key in Key as Field[key]["input"] extends false ? never : key]?: InferDBFieldInput<Field[key]> | undefined | null } : {};
|
|
12
|
+
type InferDBFieldsOutput<Fields extends Record<string, DBFieldAttribute>> = Fields extends Record<infer Key, DBFieldAttribute> ? { [key in Key as Fields[key]["returned"] extends false ? never : Fields[key]["required"] extends false ? Fields[key]["defaultValue"] extends boolean | string | number | Date ? key : never : key]: InferDBFieldOutput<Fields[key]> } & { [key in Key as Fields[key]["returned"] extends false ? never : Fields[key]["required"] extends false ? Fields[key]["defaultValue"] extends boolean | string | number | Date ? never : key : never]?: InferDBFieldOutput<Fields[key]> | null } : never;
|
|
13
13
|
type InferDBFieldsFromOptionsInput<DBOptions extends BetterAuthOptions["session"] | BetterAuthOptions["user"] | BetterAuthOptions["verification"] | BetterAuthOptions["account"] | BetterAuthOptions["rateLimit"]> = DBOptions extends {
|
|
14
14
|
additionalFields: Record<string, DBFieldAttribute>;
|
|
15
15
|
} ? InferDBFieldsInput<DBOptions["additionalFields"]> : {};
|
|
@@ -19,12 +19,12 @@ type InferDBFieldsFromOptions<DBOptions extends BetterAuthOptions["session"] | B
|
|
|
19
19
|
type InferDBFieldsFromPluginsInput<ModelName extends string, Plugins extends unknown[] | undefined> = Plugins extends [] ? {} : Plugins extends [infer P, ...infer Rest] ? P extends {
|
|
20
20
|
schema: { [key in ModelName]: {
|
|
21
21
|
fields: infer Fields;
|
|
22
|
-
}
|
|
22
|
+
} };
|
|
23
23
|
} ? Fields extends Record<string, DBFieldAttribute> ? UnionToIntersection<InferDBFieldsInput<Fields> & InferDBFieldsFromPluginsInput<ModelName, Rest>> : InferDBFieldsFromPluginsInput<ModelName, Rest> : InferDBFieldsFromPluginsInput<ModelName, Rest> : {};
|
|
24
24
|
type InferDBFieldsFromPlugins<ModelName extends string, Plugins extends unknown[] | undefined> = Plugins extends [] ? {} : Plugins extends [infer P, ...infer Rest] ? P extends {
|
|
25
25
|
schema: { [key in ModelName]: {
|
|
26
26
|
fields: infer Fields;
|
|
27
|
-
}
|
|
27
|
+
} };
|
|
28
28
|
} ? Fields extends Record<string, DBFieldAttribute> ? UnionToIntersection<InferDBFieldsOutput<Fields> & InferDBFieldsFromPlugins<ModelName, Rest>> : InferDBFieldsFromPlugins<ModelName, Rest> : InferDBFieldsFromPlugins<ModelName, Rest> : {};
|
|
29
29
|
type DBFieldType = "string" | "number" | "boolean" | "date" | "json" | `${"string" | "number"}[]` | Array<LiteralString>;
|
|
30
30
|
type DBPrimitive = string | number | boolean | Date | null | undefined | string[] | number[] | (Record<string, unknown> | unknown[]);
|
|
@@ -89,7 +89,8 @@ type DBFieldAttributeConfig = {
|
|
|
89
89
|
*/
|
|
90
90
|
bigint?: boolean | undefined;
|
|
91
91
|
/**
|
|
92
|
-
* A
|
|
92
|
+
* A Standard Schema to validate the value. Works with any Standard Schema
|
|
93
|
+
* library, such as Zod, Valibot or ArkType.
|
|
93
94
|
*/
|
|
94
95
|
validator?: {
|
|
95
96
|
input?: StandardSchemaV1;
|
|
@@ -132,8 +133,7 @@ type BetterAuthDBSchema = Record<string, {
|
|
|
132
133
|
/**
|
|
133
134
|
* The fields of the table
|
|
134
135
|
*/
|
|
135
|
-
fields: Record<string, DBFieldAttribute>;
|
|
136
|
-
/** Table-level indexes, including compound indexes. */
|
|
136
|
+
fields: Record<string, DBFieldAttribute>; /** Table-level indexes, including compound indexes. */
|
|
137
137
|
indexes?: readonly DBTableIndex[] | undefined;
|
|
138
138
|
/**
|
|
139
139
|
* Whether to disable migrations for this table
|
|
@@ -173,14 +173,17 @@ interface SecondaryStorage {
|
|
|
173
173
|
/**
|
|
174
174
|
* Key to store
|
|
175
175
|
*/
|
|
176
|
+
|
|
176
177
|
key: string,
|
|
177
178
|
/**
|
|
178
179
|
* Value to store
|
|
179
180
|
*/
|
|
181
|
+
|
|
180
182
|
value: string,
|
|
181
183
|
/**
|
|
182
184
|
* Time to live in seconds
|
|
183
185
|
*/
|
|
186
|
+
|
|
184
187
|
ttl?: number | undefined) => Awaitable<void | null | unknown>;
|
|
185
188
|
/**
|
|
186
189
|
*
|
package/dist/env/logger.d.mts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
//#region src/env/logger.d.ts
|
|
2
2
|
declare const TTY_COLORS: {
|
|
3
|
-
readonly reset: "
|
|
4
|
-
readonly bright: "
|
|
5
|
-
readonly dim: "
|
|
6
|
-
readonly undim: "
|
|
7
|
-
readonly underscore: "
|
|
8
|
-
readonly blink: "
|
|
9
|
-
readonly reverse: "
|
|
10
|
-
readonly hidden: "
|
|
3
|
+
readonly reset: "\u001B[0m";
|
|
4
|
+
readonly bright: "\u001B[1m";
|
|
5
|
+
readonly dim: "\u001B[2m";
|
|
6
|
+
readonly undim: "\u001B[22m";
|
|
7
|
+
readonly underscore: "\u001B[4m";
|
|
8
|
+
readonly blink: "\u001B[5m";
|
|
9
|
+
readonly reverse: "\u001B[7m";
|
|
10
|
+
readonly hidden: "\u001B[8m";
|
|
11
11
|
readonly fg: {
|
|
12
|
-
readonly black: "
|
|
13
|
-
readonly red: "
|
|
14
|
-
readonly green: "
|
|
15
|
-
readonly yellow: "
|
|
16
|
-
readonly blue: "
|
|
17
|
-
readonly magenta: "
|
|
18
|
-
readonly cyan: "
|
|
19
|
-
readonly white: "
|
|
12
|
+
readonly black: "\u001B[30m";
|
|
13
|
+
readonly red: "\u001B[31m";
|
|
14
|
+
readonly green: "\u001B[32m";
|
|
15
|
+
readonly yellow: "\u001B[33m";
|
|
16
|
+
readonly blue: "\u001B[34m";
|
|
17
|
+
readonly magenta: "\u001B[35m";
|
|
18
|
+
readonly cyan: "\u001B[36m";
|
|
19
|
+
readonly white: "\u001B[37m";
|
|
20
20
|
};
|
|
21
21
|
readonly bg: {
|
|
22
|
-
readonly black: "
|
|
23
|
-
readonly red: "
|
|
24
|
-
readonly green: "
|
|
25
|
-
readonly yellow: "
|
|
26
|
-
readonly blue: "
|
|
27
|
-
readonly magenta: "
|
|
28
|
-
readonly cyan: "
|
|
29
|
-
readonly white: "
|
|
22
|
+
readonly black: "\u001B[40m";
|
|
23
|
+
readonly red: "\u001B[41m";
|
|
24
|
+
readonly green: "\u001B[42m";
|
|
25
|
+
readonly yellow: "\u001B[43m";
|
|
26
|
+
readonly blue: "\u001B[44m";
|
|
27
|
+
readonly magenta: "\u001B[45m";
|
|
28
|
+
readonly cyan: "\u001B[46m";
|
|
29
|
+
readonly white: "\u001B[47m";
|
|
30
30
|
};
|
|
31
31
|
};
|
|
32
32
|
type LogLevel = "debug" | "info" | "success" | "warn" | "error";
|
|
@@ -39,7 +39,7 @@ interface Logger {
|
|
|
39
39
|
log?: ((level: Exclude<LogLevel, "success">, message: string, ...args: any[]) => void) | undefined;
|
|
40
40
|
}
|
|
41
41
|
type LogHandlerParams = Parameters<NonNullable<Logger["log"]>> extends [LogLevel, ...infer Rest] ? Rest : never;
|
|
42
|
-
type InternalLogger = { [K in LogLevel]: (...params: LogHandlerParams) => void
|
|
42
|
+
type InternalLogger = { [K in LogLevel]: (...params: LogHandlerParams) => void } & {
|
|
43
43
|
get level(): LogLevel;
|
|
44
44
|
};
|
|
45
45
|
declare const createLogger: (options?: Logger | undefined) => InternalLogger;
|
package/dist/error/codes.d.mts
CHANGED
package/dist/error/index.d.mts
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -6,4 +6,4 @@ import { SecretConfig } from "./types/secret.mjs";
|
|
|
6
6
|
import { AuthContext, BetterAuthPluginRegistry, BetterAuthPluginRegistryIdentifier, CookieCacheSigner, GenericEndpointContext, InfoContext, InternalAdapter, PluginContext } from "./types/context.mjs";
|
|
7
7
|
import { BetterAuthClientOptions, BetterAuthClientPlugin, ClientAtomListener, ClientFetchOption, ClientStore } from "./types/plugin-client.mjs";
|
|
8
8
|
import { StandardSchemaV1 } from "./types/index.mjs";
|
|
9
|
-
export
|
|
9
|
+
export { AuthContext, Awaitable, AwaitableFunction, BaseURLConfig, BetterAuthAdvancedOptions, BetterAuthClientOptions, BetterAuthClientPlugin, BetterAuthCookie, BetterAuthCookies, BetterAuthDBOptions, BetterAuthOptions, BetterAuthPlugin, BetterAuthPluginErrorCodePart, BetterAuthPluginRegistry, BetterAuthPluginRegistryIdentifier, BetterAuthRateLimitOptions, BetterAuthRateLimitRule, BetterAuthRateLimitStorage, ClientAtomListener, ClientFetchOption, ClientStore, CookieCachePayload, CookieCacheSigner, DynamicBaseURLConfig, GenerateIdFn, GenericEndpointContext, HookEndpointContext, InfoContext, InternalAdapter, LiteralString, LiteralUnion, PluginContext, Prettify, Primitive, SecretConfig, StandardSchemaV1, StoreIdentifierOption, UnionToIntersection, UserProvisioningSource, ValidateUserInfoAction, ValidateUserInfoMethod, ValidateUserInfoOAuthInfo, ValidateUserInfoResult, ValidateUserInfoSSOInfo, ValidateUserInfoSource };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ATTR_DB_COLLECTION_NAME, ATTR_DB_OPERATION_NAME, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_HTTP_ROUTE } from "@opentelemetry/semantic-conventions";
|
|
2
|
+
|
|
2
3
|
//#region src/instrumentation/attributes.d.ts
|
|
3
4
|
/** Operation identifier (e.g. getSession, signUpWithEmailAndPassword). Uses endpoint operationId when set, otherwise the endpoint key. */
|
|
4
5
|
declare const ATTR_OPERATION_ID: "better_auth.operation_id";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ATTR_CONTEXT, ATTR_DB_COLLECTION_NAME, ATTR_DB_OPERATION_NAME, ATTR_HOOK_TYPE, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_HTTP_ROUTE, ATTR_OPERATION_ID } from "./attributes.mjs";
|
|
2
|
+
|
|
2
3
|
//#region src/instrumentation/pure.index.d.ts
|
|
3
4
|
declare function withSpan<T>(name: string, attributes: Record<string, string | number | boolean>, fn: () => T): T;
|
|
4
5
|
declare function withSpan<T>(name: string, attributes: Record<string, string | number | boolean>, fn: () => Promise<T>): Promise<T>;
|
|
@@ -2,7 +2,7 @@ import { ATTR_HTTP_RESPONSE_STATUS_CODE } from "./attributes.mjs";
|
|
|
2
2
|
import { getOpenTelemetryAPI } from "./api.mjs";
|
|
3
3
|
//#region src/instrumentation/tracer.ts
|
|
4
4
|
const INSTRUMENTATION_SCOPE = "better-auth";
|
|
5
|
-
const INSTRUMENTATION_VERSION = "1.7.0-rc.
|
|
5
|
+
const INSTRUMENTATION_VERSION = "1.7.0-rc.6";
|
|
6
6
|
/**
|
|
7
7
|
* Better-auth uses `throw ctx.redirect(url)` for flow control (e.g. OAuth
|
|
8
8
|
* callbacks). These are APIErrors with 3xx status codes and should not be
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Awaitable } from "../types/helper.mjs";
|
|
2
|
-
import "../types/index.mjs";
|
|
3
2
|
//#region src/oauth2/client-assertion.d.ts
|
|
4
3
|
/** Asymmetric signing algorithms compatible with private_key_jwt (RFC 7523). */
|
|
5
4
|
declare const PRIVATE_KEY_JWT_SIGNING_ALGORITHMS: readonly ["RS256", "RS384", "RS512", "PS256", "PS384", "PS512", "ES256", "ES384", "ES512", "EdDSA"];
|
|
@@ -36,7 +35,15 @@ interface PrivateKeyJwtClientAssertionGetterOptions {
|
|
|
36
35
|
* - jti=unique
|
|
37
36
|
* - iat=now
|
|
38
37
|
*/
|
|
39
|
-
declare function signPrivateKeyJwtClientAssertion({
|
|
38
|
+
declare function signPrivateKeyJwtClientAssertion({
|
|
39
|
+
clientId,
|
|
40
|
+
tokenEndpoint,
|
|
41
|
+
privateKeyJwk,
|
|
42
|
+
privateKeyPem,
|
|
43
|
+
kid,
|
|
44
|
+
algorithm,
|
|
45
|
+
expiresIn
|
|
46
|
+
}: {
|
|
40
47
|
clientId: string;
|
|
41
48
|
tokenEndpoint: string;
|
|
42
49
|
privateKeyJwk?: JsonWebKey;
|
|
@@ -57,7 +64,10 @@ declare function createPrivateKeyJwtClientAssertionGetter(options: PrivateKeyJwt
|
|
|
57
64
|
/**
|
|
58
65
|
* Resolves a client assertion getter into `client_assertion` + `client_assertion_type` params for injection into a token request body.
|
|
59
66
|
*/
|
|
60
|
-
declare function resolveClientAssertionParams({
|
|
67
|
+
declare function resolveClientAssertionParams({
|
|
68
|
+
getClientAssertion,
|
|
69
|
+
context
|
|
70
|
+
}: {
|
|
61
71
|
getClientAssertion: ClientAssertionGetter;
|
|
62
72
|
context: ClientAssertionContext;
|
|
63
73
|
}): Promise<Record<string, string>>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AwaitableFunction } from "../types/helper.mjs";
|
|
2
|
-
import "../types/index.mjs";
|
|
3
2
|
import { OAuth2Tokens, ProviderOptions } from "./oauth-provider.mjs";
|
|
4
3
|
import { TokenEndpointAuth, TokenEndpointSecretAuthentication } from "./token-endpoint-auth.mjs";
|
|
4
|
+
|
|
5
5
|
//#region src/oauth2/client-credentials-token.d.ts
|
|
6
6
|
interface ClientCredentialsTokenRequestInput {
|
|
7
7
|
options: AwaitableFunction<ProviderOptions>;
|
|
@@ -15,10 +15,24 @@ interface ClientCredentialsTokenInput extends ClientCredentialsTokenRequestInput
|
|
|
15
15
|
tokenEndpoint: string;
|
|
16
16
|
scope: string;
|
|
17
17
|
}
|
|
18
|
-
declare function clientCredentialsTokenRequest({
|
|
18
|
+
declare function clientCredentialsTokenRequest({
|
|
19
|
+
options,
|
|
20
|
+
scope,
|
|
21
|
+
authentication,
|
|
22
|
+
tokenEndpointAuth,
|
|
23
|
+
tokenEndpoint,
|
|
24
|
+
resource
|
|
25
|
+
}: ClientCredentialsTokenRequestInput): Promise<{
|
|
19
26
|
body: URLSearchParams;
|
|
20
27
|
headers: Record<string, string>;
|
|
21
28
|
}>;
|
|
22
|
-
declare function clientCredentialsToken({
|
|
29
|
+
declare function clientCredentialsToken({
|
|
30
|
+
options,
|
|
31
|
+
tokenEndpoint,
|
|
32
|
+
scope,
|
|
33
|
+
authentication,
|
|
34
|
+
tokenEndpointAuth,
|
|
35
|
+
resource
|
|
36
|
+
}: ClientCredentialsTokenInput): Promise<OAuth2Tokens>;
|
|
23
37
|
//#endregion
|
|
24
38
|
export { clientCredentialsToken, clientCredentialsTokenRequest };
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { AwaitableFunction } from "../types/helper.mjs";
|
|
2
|
-
import "../types/index.mjs";
|
|
3
2
|
import { ProviderOptions } from "./oauth-provider.mjs";
|
|
4
|
-
import "./index.mjs";
|
|
5
3
|
//#region src/oauth2/create-authorization-url.d.ts
|
|
6
4
|
/**
|
|
7
5
|
* Query-parameter names that are populated by the framework as part of the
|
|
@@ -11,7 +9,27 @@ import "./index.mjs";
|
|
|
11
9
|
*/
|
|
12
10
|
declare const RESERVED_AUTHORIZATION_PARAMS: readonly ["state", "client_id", "redirect_uri", "response_type", "code_challenge", "code_challenge_method", "nonce", "scope"];
|
|
13
11
|
declare const RESERVED_AUTHORIZATION_PARAMS_SET: ReadonlySet<string>;
|
|
14
|
-
declare function createAuthorizationURL({
|
|
12
|
+
declare function createAuthorizationURL({
|
|
13
|
+
id,
|
|
14
|
+
options,
|
|
15
|
+
authorizationEndpoint,
|
|
16
|
+
state,
|
|
17
|
+
codeVerifier,
|
|
18
|
+
scopes,
|
|
19
|
+
claims,
|
|
20
|
+
redirectURI,
|
|
21
|
+
duration,
|
|
22
|
+
prompt,
|
|
23
|
+
accessType,
|
|
24
|
+
responseType,
|
|
25
|
+
display,
|
|
26
|
+
loginHint,
|
|
27
|
+
nonce,
|
|
28
|
+
hd,
|
|
29
|
+
responseMode,
|
|
30
|
+
additionalParams,
|
|
31
|
+
scopeJoiner
|
|
32
|
+
}: {
|
|
15
33
|
id: string;
|
|
16
34
|
options: AwaitableFunction<ProviderOptions>;
|
|
17
35
|
redirectURI: string;
|
package/dist/oauth2/dpop.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { JWK, JWTPayload } from "jose";
|
|
2
|
+
|
|
2
3
|
//#region src/oauth2/dpop.d.ts
|
|
3
4
|
declare const DPOP_AUTHORIZATION_SCHEME = "DPoP";
|
|
4
5
|
declare const BEARER_AUTHORIZATION_SCHEME = "Bearer";
|
|
@@ -85,7 +86,18 @@ declare function deriveDpopJkt(jwk: JWK): Promise<string>;
|
|
|
85
86
|
*/
|
|
86
87
|
declare function getConfirmationJkt(confirmation: unknown): string | undefined;
|
|
87
88
|
declare function getDpopJktFromPayload(payload: JWTPayload): string | undefined;
|
|
88
|
-
declare function verifyDpopProof({
|
|
89
|
+
declare function verifyDpopProof({
|
|
90
|
+
proofJwt,
|
|
91
|
+
method,
|
|
92
|
+
url,
|
|
93
|
+
accessToken,
|
|
94
|
+
expectedJkt,
|
|
95
|
+
requireAth,
|
|
96
|
+
nowSeconds,
|
|
97
|
+
proofMaxAgeSeconds,
|
|
98
|
+
signingAlgorithms,
|
|
99
|
+
replayStore
|
|
100
|
+
}: VerifyDpopProofOptions): Promise<VerifiedDpopProof>;
|
|
89
101
|
type DpopBindingErrorCode = "invalid_token" | "invalid_dpop_proof";
|
|
90
102
|
type DpopBindingError = Error & {
|
|
91
103
|
code: DpopBindingErrorCode;
|
|
@@ -116,6 +128,15 @@ interface EnforceDpopBindingParams {
|
|
|
116
128
|
* `invalid_token` / `invalid_dpop_proof` code into their own transport. Returns
|
|
117
129
|
* normally for a valid bearer token (no `cnf.jkt`, no DPoP scheme).
|
|
118
130
|
*/
|
|
119
|
-
declare function enforceDpopBinding({
|
|
131
|
+
declare function enforceDpopBinding({
|
|
132
|
+
payload,
|
|
133
|
+
authorization,
|
|
134
|
+
proofJwt,
|
|
135
|
+
method,
|
|
136
|
+
url,
|
|
137
|
+
replayStore,
|
|
138
|
+
proofMaxAgeSeconds,
|
|
139
|
+
signingAlgorithms
|
|
140
|
+
}: EnforceDpopBindingParams): Promise<void>;
|
|
120
141
|
//#endregion
|
|
121
142
|
export { AccessTokenAuthorization, AccessTokenAuthorizationScheme, BEARER_AUTHORIZATION_SCHEME, DPOP_AUTHORIZATION_SCHEME, DPOP_PROOF_TYPE, DPOP_SIGNING_ALGORITHMS, DpopBindingError, DpopBindingErrorCode, DpopProofError, DpopProofErrorCode, DpopReplayReservation, DpopReplayReservations, DpopReplayStore, DpopSigningAlgorithm, EnforceDpopBindingParams, VerifiedDpopProof, VerifyDpopProofOptions, createDpopBindingError, createDpopProofError, createDpopReplayStore, createInMemoryDpopReplayStore, deriveDpopAth, deriveDpopJkt, enforceDpopBinding, getConfirmationJkt, getDpopJktFromPayload, isDpopBindingError, isDpopProofError, normalizeDpopHtu, parseAccessTokenAuthorization, stripAccessTokenAuthorizationScheme, verifyDpopProof };
|
package/dist/oauth2/dpop.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Awaitable, LiteralString } from "../types/helper.mjs";
|
|
2
2
|
import { GenericEndpointContext } from "../types/context.mjs";
|
|
3
|
-
import "../types/index.mjs";
|
|
4
3
|
import { JWTVerifyGetKey } from "jose";
|
|
4
|
+
|
|
5
5
|
//#region src/oauth2/oauth-provider.d.ts
|
|
6
6
|
/**
|
|
7
7
|
* id_token verification config for a social provider.
|
|
@@ -17,14 +17,10 @@ type OAuthIdTokenConfig = {
|
|
|
17
17
|
* `createRemoteJWKSet` resolver or a key-resolving function
|
|
18
18
|
* `(protectedHeader) => key`.
|
|
19
19
|
*/
|
|
20
|
-
jwks: JWTVerifyGetKey;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
audience: string | string[];
|
|
25
|
-
/** Permitted JWS algorithms. Defaults to the token's `alg` header. */
|
|
26
|
-
algorithms?: string[] | undefined;
|
|
27
|
-
/** Maximum token age passed to jose (e.g. `"1h"`). */
|
|
20
|
+
jwks: JWTVerifyGetKey; /** Expected `iss`. Omit for providers whose issuer varies per tenant. */
|
|
21
|
+
issuer?: (string | string[]) | undefined; /** Expected `aud`, usually the client ID. */
|
|
22
|
+
audience: string | string[]; /** Permitted JWS algorithms. Defaults to the token's `alg` header. */
|
|
23
|
+
algorithms?: string[] | undefined; /** Maximum token age passed to jose (e.g. `"1h"`). */
|
|
28
24
|
maxTokenAge?: string | undefined;
|
|
29
25
|
/**
|
|
30
26
|
* How the `nonce` claim is compared to the expected nonce.
|
|
@@ -69,8 +65,7 @@ interface OAuth2Tokens {
|
|
|
69
65
|
}
|
|
70
66
|
/** Mutable local-user attributes normalized from an OAuth provider profile. */
|
|
71
67
|
type OAuth2UserInfo = {
|
|
72
|
-
/** Provider identity belongs in raw profile data and `accountSubject`. */
|
|
73
|
-
id?: never;
|
|
68
|
+
/** Provider identity belongs in raw profile data and `accountSubject`. */id?: never;
|
|
74
69
|
name?: string | undefined;
|
|
75
70
|
email?: (string | null) | undefined;
|
|
76
71
|
image?: string | undefined;
|
|
@@ -99,8 +94,7 @@ type OAuthAccountKeyResolver<Profile extends object, Value> = {
|
|
|
99
94
|
type OAuthAccountSubject<Profile extends object = object> = OAuthAccountKeyResolver<Profile, string | number>;
|
|
100
95
|
/** Mutable local-user attributes returned by `mapProfileToUser`. */
|
|
101
96
|
type OAuthMappedUser = {
|
|
102
|
-
/** Provider identity is defined by `accountSubject`, not local user mapping. */
|
|
103
|
-
id?: never;
|
|
97
|
+
/** Provider identity is defined by `accountSubject`, not local user mapping. */id?: never;
|
|
104
98
|
name?: string;
|
|
105
99
|
email?: string | null;
|
|
106
100
|
image?: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AwaitableFunction } from "../types/helper.mjs";
|
|
2
|
-
import "../types/index.mjs";
|
|
3
2
|
import { OAuth2Tokens, ProviderOptions } from "./oauth-provider.mjs";
|
|
4
3
|
import { TokenEndpointAuth, TokenEndpointSecretAuthentication } from "./token-endpoint-auth.mjs";
|
|
4
|
+
|
|
5
5
|
//#region src/oauth2/refresh-access-token.d.ts
|
|
6
6
|
interface RefreshAccessTokenRequestInput {
|
|
7
7
|
refreshToken: string;
|
|
@@ -16,10 +16,26 @@ interface RefreshAccessTokenInput extends RefreshAccessTokenRequestInput {
|
|
|
16
16
|
options: Partial<ProviderOptions>;
|
|
17
17
|
tokenEndpoint: string;
|
|
18
18
|
}
|
|
19
|
-
declare function refreshAccessTokenRequest({
|
|
19
|
+
declare function refreshAccessTokenRequest({
|
|
20
|
+
refreshToken,
|
|
21
|
+
options,
|
|
22
|
+
authentication,
|
|
23
|
+
tokenEndpointAuth,
|
|
24
|
+
tokenEndpoint,
|
|
25
|
+
extraParams,
|
|
26
|
+
resource
|
|
27
|
+
}: RefreshAccessTokenRequestInput): Promise<{
|
|
20
28
|
body: URLSearchParams;
|
|
21
29
|
headers: Record<string, string>;
|
|
22
30
|
}>;
|
|
23
|
-
declare function refreshAccessToken({
|
|
31
|
+
declare function refreshAccessToken({
|
|
32
|
+
refreshToken,
|
|
33
|
+
options,
|
|
34
|
+
tokenEndpoint,
|
|
35
|
+
authentication,
|
|
36
|
+
tokenEndpointAuth,
|
|
37
|
+
extraParams,
|
|
38
|
+
resource
|
|
39
|
+
}: RefreshAccessTokenInput): Promise<OAuth2Tokens>;
|
|
24
40
|
//#endregion
|
|
25
41
|
export { refreshAccessToken, refreshAccessTokenRequest };
|
|
@@ -2,7 +2,7 @@ import { parseScopeField } from "./utils.mjs";
|
|
|
2
2
|
import { fetchRefusingRedirects } from "./reject-redirects.mjs";
|
|
3
3
|
import { applyTokenEndpointAuth } from "./token-endpoint-auth.mjs";
|
|
4
4
|
//#region src/oauth2/refresh-access-token.ts
|
|
5
|
-
const BLOCKED_REFRESH_TOKEN_PARAMS_SET =
|
|
5
|
+
const BLOCKED_REFRESH_TOKEN_PARAMS_SET = new Set([
|
|
6
6
|
"grant_type",
|
|
7
7
|
"refresh_token",
|
|
8
8
|
"__proto__",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BetterAuthError } from "../error/index.mjs";
|
|
2
2
|
import { betterFetch } from "@better-fetch/fetch";
|
|
3
3
|
//#region src/oauth2/reject-redirects.ts
|
|
4
|
-
const httpRedirectStatuses =
|
|
4
|
+
const httpRedirectStatuses = new Set([
|
|
5
5
|
301,
|
|
6
6
|
302,
|
|
7
7
|
303,
|
package/dist/oauth2/utils.d.mts
CHANGED
package/dist/oauth2/utils.mjs
CHANGED
|
@@ -47,7 +47,7 @@ function applyDefaultAccessTokenExpiry(tokens, accessTokenExpiresIn) {
|
|
|
47
47
|
function mergeScopes(stored, incoming) {
|
|
48
48
|
const existing = stored ? stored.split(",").map((scope) => scope.trim()).filter(Boolean) : [];
|
|
49
49
|
const next = (incoming ?? []).map((scope) => scope.trim()).filter(Boolean);
|
|
50
|
-
return [
|
|
50
|
+
return [...new Set([...existing, ...next])].join(",");
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
53
|
* Return the provider's primary Client ID: the single string, or the entry at
|