@better-auth/core 1.7.0-rc.5 → 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.
Files changed (111) hide show
  1. package/dist/api/index.d.mts +28 -28
  2. package/dist/async_hooks/index.d.mts +1 -0
  3. package/dist/async_hooks/pure.index.d.mts +1 -0
  4. package/dist/context/endpoint-context.d.mts +1 -1
  5. package/dist/context/global.d.mts +1 -0
  6. package/dist/context/global.mjs +1 -1
  7. package/dist/context/request-state.d.mts +1 -0
  8. package/dist/context/transaction.d.mts +2 -3
  9. package/dist/db/adapter/factory.d.mts +5 -3
  10. package/dist/db/adapter/factory.mjs +1 -1
  11. package/dist/db/adapter/get-default-field-name.d.mts +9 -2
  12. package/dist/db/adapter/get-default-model-name.d.mts +5 -1
  13. package/dist/db/adapter/get-field-attributes.d.mts +11 -4
  14. package/dist/db/adapter/get-field-name.d.mts +9 -2
  15. package/dist/db/adapter/get-id-field.d.mts +12 -4
  16. package/dist/db/adapter/get-model-name.d.mts +5 -1
  17. package/dist/db/adapter/index.d.mts +32 -7
  18. package/dist/db/adapter/types.d.mts +17 -5
  19. package/dist/db/adapter/utils.d.mts +1 -0
  20. package/dist/db/database-index.d.mts +12 -2
  21. package/dist/db/get-tables.d.mts +0 -1
  22. package/dist/db/plugin.d.mts +3 -3
  23. package/dist/db/schema/account.d.mts +1 -1
  24. package/dist/db/schema/rate-limit.d.mts +1 -1
  25. package/dist/db/schema/session.d.mts +1 -1
  26. package/dist/db/schema/shared.d.mts +1 -0
  27. package/dist/db/schema/user.d.mts +1 -1
  28. package/dist/db/schema/verification.d.mts +1 -1
  29. package/dist/db/type.d.mts +11 -8
  30. package/dist/env/logger.d.mts +25 -25
  31. package/dist/error/codes.d.mts +1 -0
  32. package/dist/error/index.d.mts +1 -0
  33. package/dist/index.d.mts +1 -1
  34. package/dist/instrumentation/attributes.d.mts +1 -0
  35. package/dist/instrumentation/pure.index.d.mts +1 -0
  36. package/dist/instrumentation/tracer.mjs +1 -1
  37. package/dist/oauth2/authorization-params.d.mts +1 -0
  38. package/dist/oauth2/client-assertion.d.mts +13 -3
  39. package/dist/oauth2/client-credentials-token.d.mts +17 -3
  40. package/dist/oauth2/create-authorization-url.d.mts +21 -3
  41. package/dist/oauth2/dpop.d.mts +23 -2
  42. package/dist/oauth2/dpop.mjs +1 -1
  43. package/dist/oauth2/oauth-provider.d.mts +7 -13
  44. package/dist/oauth2/refresh-access-token.d.mts +19 -3
  45. package/dist/oauth2/refresh-access-token.mjs +1 -1
  46. package/dist/oauth2/reject-redirects.mjs +1 -1
  47. package/dist/oauth2/token-endpoint-auth.d.mts +1 -0
  48. package/dist/oauth2/utils.d.mts +1 -0
  49. package/dist/oauth2/utils.mjs +1 -1
  50. package/dist/oauth2/validate-authorization-code.d.mts +29 -5
  51. package/dist/oauth2/verify-id-token.d.mts +1 -1
  52. package/dist/oauth2/verify.d.mts +7 -5
  53. package/dist/oauth2/verify.mjs +2 -2
  54. package/dist/social-providers/apple.d.mts +18 -5
  55. package/dist/social-providers/atlassian.d.mts +15 -4
  56. package/dist/social-providers/cognito.d.mts +18 -5
  57. package/dist/social-providers/discord.d.mts +13 -4
  58. package/dist/social-providers/dropbox.d.mts +15 -4
  59. package/dist/social-providers/facebook.d.mts +18 -6
  60. package/dist/social-providers/figma.d.mts +15 -4
  61. package/dist/social-providers/github.d.mts +16 -4
  62. package/dist/social-providers/gitlab.d.mts +16 -4
  63. package/dist/social-providers/google.d.mts +25 -6
  64. package/dist/social-providers/huggingface.d.mts +15 -4
  65. package/dist/social-providers/index.d.mts +504 -113
  66. package/dist/social-providers/kakao.d.mts +13 -4
  67. package/dist/social-providers/kick.d.mts +15 -4
  68. package/dist/social-providers/line.d.mts +16 -4
  69. package/dist/social-providers/linear.d.mts +14 -4
  70. package/dist/social-providers/linkedin.d.mts +14 -4
  71. package/dist/social-providers/microsoft-entra-id.d.mts +14 -5
  72. package/dist/social-providers/microsoft-entra-id.mjs +1 -2
  73. package/dist/social-providers/naver.d.mts +22 -23
  74. package/dist/social-providers/notion.d.mts +14 -4
  75. package/dist/social-providers/paybin.d.mts +16 -4
  76. package/dist/social-providers/paypal.d.mts +13 -4
  77. package/dist/social-providers/polar.d.mts +15 -4
  78. package/dist/social-providers/railway.d.mts +15 -4
  79. package/dist/social-providers/reddit.d.mts +13 -4
  80. package/dist/social-providers/roblox.d.mts +13 -4
  81. package/dist/social-providers/salesforce.d.mts +15 -4
  82. package/dist/social-providers/slack.d.mts +13 -4
  83. package/dist/social-providers/spotify.d.mts +15 -4
  84. package/dist/social-providers/tiktok.d.mts +14 -6
  85. package/dist/social-providers/twitch.d.mts +13 -4
  86. package/dist/social-providers/twitter.d.mts +19 -26
  87. package/dist/social-providers/vercel.d.mts +15 -4
  88. package/dist/social-providers/vk.d.mts +16 -4
  89. package/dist/social-providers/wechat.d.mts +12 -4
  90. package/dist/social-providers/zoom.d.mts +18 -6
  91. package/dist/types/context.d.mts +2 -2
  92. package/dist/types/cookie.d.mts +1 -1
  93. package/dist/types/helper.d.mts +1 -1
  94. package/dist/types/index.d.mts +1 -1
  95. package/dist/types/init-options.d.mts +18 -26
  96. package/dist/types/plugin-client.d.mts +3 -1
  97. package/dist/types/plugin.d.mts +2 -2
  98. package/dist/utils/async.d.mts +1 -0
  99. package/dist/utils/db.d.mts +0 -1
  100. package/dist/utils/deprecate.d.mts +1 -0
  101. package/dist/utils/email.d.mts +4 -1
  102. package/dist/utils/error-codes.d.mts +2 -2
  103. package/dist/utils/host.d.mts +1 -27
  104. package/dist/utils/host.mjs +1 -1
  105. package/dist/utils/ip.d.mts +0 -1
  106. package/dist/utils/ip.mjs +1 -1
  107. package/dist/utils/is-api-error.d.mts +1 -0
  108. package/dist/utils/redirect-uri.d.mts +1 -0
  109. package/package.json +2 -2
  110. package/src/db/type.ts +2 -1
  111. package/src/types/init-options.ts +6 -4
@@ -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]>; } & { [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;
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 zod schema to validate the value.
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
  *
@@ -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;
@@ -1,4 +1,5 @@
1
1
  import { RawError } from "../utils/error-codes.mjs";
2
+
2
3
  //#region src/error/codes.d.ts
3
4
  declare module "@better-auth/core" {
4
5
  interface BetterAuthPluginRegistry<AuthOptions, Options> {
@@ -1,5 +1,6 @@
1
1
  import { APIErrorCode, BASE_ERROR_CODES } from "./codes.mjs";
2
2
  import { APIError as APIError$1 } from "better-call/error";
3
+
3
4
  //#region src/error/index.d.ts
4
5
  declare class BetterAuthError extends Error {
5
6
  constructor(message: string, options?: {
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 type { 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 };
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";
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,4 +1,5 @@
1
1
  import * as z from "zod";
2
+
2
3
  //#region src/oauth2/authorization-params.d.ts
3
4
  /**
4
5
  * Zod schema for the `additionalParams` field on social sign-in and
@@ -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({ clientId, tokenEndpoint, privateKeyJwk, privateKeyPem, kid, algorithm, expiresIn }: {
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({ getClientAssertion, context }: {
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({ options, scope, authentication, tokenEndpointAuth, tokenEndpoint, resource }: ClientCredentialsTokenRequestInput): Promise<{
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({ options, tokenEndpoint, scope, authentication, tokenEndpointAuth, resource }: ClientCredentialsTokenInput): Promise<OAuth2Tokens>;
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({ id, options, authorizationEndpoint, state, codeVerifier, scopes, claims, redirectURI, duration, prompt, accessType, responseType, display, loginHint, nonce, hd, responseMode, additionalParams, scopeJoiner }: {
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;
@@ -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({ proofJwt, method, url, accessToken, expectedJkt, requireAth, nowSeconds, proofMaxAgeSeconds, signingAlgorithms, replayStore }: VerifyDpopProofOptions): Promise<VerifiedDpopProof>;
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({ payload, authorization, proofJwt, method, url, replayStore, proofMaxAgeSeconds, signingAlgorithms }: EnforceDpopBindingParams): Promise<void>;
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 };
@@ -12,7 +12,7 @@ const DPOP_SIGNING_ALGORITHMS = [
12
12
  ];
13
13
  const DEFAULT_DPOP_PROOF_MAX_AGE_SECONDS = 300;
14
14
  const MAX_DPOP_JTI_LENGTH = 512;
15
- const JWK_PRIVATE_FIELDS = /* @__PURE__ */ new Set([
15
+ const JWK_PRIVATE_FIELDS = new Set([
16
16
  "d",
17
17
  "p",
18
18
  "q",
@@ -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
- /** Expected `iss`. Omit for providers whose issuer varies per tenant. */
22
- issuer?: (string | string[]) | undefined;
23
- /** Expected `aud`, usually the client ID. */
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({ refreshToken, options, authentication, tokenEndpointAuth, tokenEndpoint, extraParams, resource }: RefreshAccessTokenRequestInput): Promise<{
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({ refreshToken, options, tokenEndpoint, authentication, tokenEndpointAuth, extraParams, resource }: RefreshAccessTokenInput): Promise<OAuth2Tokens>;
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 = /* @__PURE__ */ new 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 = /* @__PURE__ */ new Set([
4
+ const httpRedirectStatuses = new Set([
5
5
  301,
6
6
  302,
7
7
  303,
@@ -1,4 +1,5 @@
1
1
  import { ClientAssertionGetter } from "./client-assertion.mjs";
2
+
2
3
  //#region src/oauth2/token-endpoint-auth.d.ts
3
4
  type TokenEndpointAuth = {
4
5
  method: "none";
@@ -1,4 +1,5 @@
1
1
  import { OAuth2Tokens } from "./oauth-provider.mjs";
2
+
2
3
  //#region src/oauth2/utils.d.ts
3
4
  declare function getOAuth2Tokens(data: Record<string, any>): OAuth2Tokens;
4
5
  /**
@@ -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 [.../* @__PURE__ */ new Set([...existing, ...next])].join(",");
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
@@ -1,8 +1,8 @@
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";
5
- import "./index.mjs";
4
+ import * as _$jose from "jose";
5
+
6
6
  //#region src/oauth2/validate-authorization-code.d.ts
7
7
  interface AuthorizationCodeRequestInput {
8
8
  code: string;
@@ -20,14 +20,38 @@ interface AuthorizationCodeRequestInput {
20
20
  interface ValidateAuthorizationCodeInput extends AuthorizationCodeRequestInput {
21
21
  tokenEndpoint: string;
22
22
  }
23
- declare function authorizationCodeRequest({ code, codeVerifier, redirectURI, options, authentication, tokenEndpointAuth, tokenEndpoint, deviceId, headers, additionalParams, resource }: AuthorizationCodeRequestInput): Promise<{
23
+ declare function authorizationCodeRequest({
24
+ code,
25
+ codeVerifier,
26
+ redirectURI,
27
+ options,
28
+ authentication,
29
+ tokenEndpointAuth,
30
+ tokenEndpoint,
31
+ deviceId,
32
+ headers,
33
+ additionalParams,
34
+ resource
35
+ }: AuthorizationCodeRequestInput): Promise<{
24
36
  body: URLSearchParams;
25
37
  headers: Record<string, string>;
26
38
  }>;
27
- declare function validateAuthorizationCode({ code, codeVerifier, redirectURI, options, tokenEndpoint, authentication, tokenEndpointAuth, deviceId, headers, additionalParams, resource }: ValidateAuthorizationCodeInput): Promise<OAuth2Tokens>;
39
+ declare function validateAuthorizationCode({
40
+ code,
41
+ codeVerifier,
42
+ redirectURI,
43
+ options,
44
+ tokenEndpoint,
45
+ authentication,
46
+ tokenEndpointAuth,
47
+ deviceId,
48
+ headers,
49
+ additionalParams,
50
+ resource
51
+ }: ValidateAuthorizationCodeInput): Promise<OAuth2Tokens>;
28
52
  declare function validateToken(token: string, jwksEndpoint: string, options?: {
29
53
  audience?: string | string[];
30
54
  issuer?: string | string[];
31
- }): Promise<import("jose").JWTVerifyResult<import("jose").JWTPayload> & import("jose").ResolvedKey>;
55
+ }): Promise<_$jose.JWTVerifyResult<_$jose.JWTPayload> & _$jose.ResolvedKey>;
32
56
  //#endregion
33
57
  export { authorizationCodeRequest, validateAuthorizationCode, validateToken };
@@ -1,6 +1,6 @@
1
1
  import { GenericEndpointContext } from "../types/context.mjs";
2
- import "../types/index.mjs";
3
2
  import { OAuthProvider } from "./oauth-provider.mjs";
3
+
4
4
  //#region src/oauth2/verify-id-token.d.ts
5
5
  type ProviderWithIdTokenConfig = Pick<OAuthProvider, "idToken" | "options">;
6
6
  /**
@@ -1,10 +1,10 @@
1
1
  import { DpopReplayStore } from "./dpop.mjs";
2
2
  import { APIError } from "better-call";
3
3
  import { JSONWebKeySet, JWTPayload, JWTVerifyOptions } from "jose";
4
+
4
5
  //#region src/oauth2/verify.d.ts
5
6
  type JwksFetchOptions = {
6
- /** Jwks url or promise of a Jwks */
7
- jwksFetch: string | (() => Promise<JSONWebKeySet | undefined>);
7
+ /** Jwks url or promise of a Jwks */jwksFetch: string | (() => Promise<JSONWebKeySet | undefined>);
8
8
  /**
9
9
  * Stable object to cache the result of a function `jwksFetch` under,
10
10
  * with the same TTL and kid-miss refetch rules as string sources.
@@ -12,6 +12,9 @@ type JwksFetchOptions = {
12
12
  */
13
13
  jwksCacheKey?: object;
14
14
  };
15
+ /**
16
+ * @internal
17
+ */
15
18
  interface VerifyAccessTokenRemote {
16
19
  /** Full url of the introspect endpoint. Should end with `/oauth2/introspect` */
17
20
  introspectUrl: string;
@@ -90,8 +93,7 @@ declare function requestToResourceInput(request: Request): ResourceRequestInput;
90
93
  * Can also be configured for remote verification.
91
94
  */
92
95
  declare function verifyJwsAccessToken(token: string, opts: JwksFetchOptions & {
93
- /** Verify options */
94
- verifyOptions: JWTVerifyOptions & Required<Pick<JWTVerifyOptions, "audience" | "issuer">>;
96
+ /** Verify options */verifyOptions: JWTVerifyOptions & Required<Pick<JWTVerifyOptions, "audience" | "issuer">>;
95
97
  }): Promise<JWTPayload>;
96
98
  declare function getJwks(token: string, opts: JwksFetchOptions): Promise<JSONWebKeySet>;
97
99
  declare function createInsufficientScopeError(requiredScopes: readonly string[], description?: string): APIError;
@@ -121,4 +123,4 @@ declare function verifyBearerToken(token: string, opts: VerifyAccessTokenOptions
121
123
  */
122
124
  declare function verifyAccessTokenRequest(request: ResourceRequestInput, opts: VerifyAccessTokenRequestOptions): Promise<JWTPayload>;
123
125
  //#endregion
124
- export { ResourceRequestInput, VerifyAccessTokenOptions, VerifyAccessTokenRemote, VerifyAccessTokenRequestOptions, createInsufficientScopeError, getJwks, isInsufficientScopeError, requestToResourceInput, verifyAccessTokenRequest, verifyBearerToken, verifyJwsAccessToken };
126
+ export { ResourceRequestInput, VerifyAccessTokenOptions, VerifyAccessTokenRequestOptions, createInsufficientScopeError, getJwks, isInsufficientScopeError, requestToResourceInput, verifyAccessTokenRequest, verifyBearerToken, verifyJwsAccessToken };
@@ -4,7 +4,7 @@ import { createInMemoryDpopReplayStore, enforceDpopBinding, getDpopJktFromPayloa
4
4
  import { APIError } from "better-call";
5
5
  import { UnsecuredJWT, createLocalJWKSet, decodeProtectedHeader, errors, jwtVerify } from "jose";
6
6
  //#region src/oauth2/verify.ts
7
- const joseInfrastructureErrorCodes = /* @__PURE__ */ new Set([
7
+ const joseInfrastructureErrorCodes = new Set([
8
8
  errors.JWKSTimeout.code,
9
9
  errors.JWKSInvalid.code,
10
10
  errors.JWKSMultipleMatchingKeys.code
@@ -330,4 +330,4 @@ async function verifyAccessTokenRequest(request, opts) {
330
330
  return payload;
331
331
  }
332
332
  //#endregion
333
- export { createInsufficientScopeError, getJwks, isInsufficientScopeError, jwksCache, requestToResourceInput, verifyAccessTokenRequest, verifyBearerToken, verifyJwsAccessToken };
333
+ export { createInsufficientScopeError, getJwks, isInsufficientScopeError, requestToResourceInput, verifyAccessTokenRequest, verifyBearerToken, verifyJwsAccessToken };