@better-auth/core 1.6.22 → 1.6.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/dist/api/index.d.mts +28 -28
  2. package/dist/async_hooks/index.d.mts +0 -1
  3. package/dist/async_hooks/pure.index.d.mts +0 -1
  4. package/dist/context/endpoint-context.d.mts +1 -1
  5. package/dist/context/global.d.mts +0 -1
  6. package/dist/context/global.mjs +1 -1
  7. package/dist/context/request-state.d.mts +0 -1
  8. package/dist/context/request-state.mjs +8 -5
  9. package/dist/context/transaction.d.mts +1 -1
  10. package/dist/db/adapter/factory.d.mts +3 -5
  11. package/dist/db/adapter/factory.mjs +1 -1
  12. package/dist/db/adapter/get-default-field-name.d.mts +2 -9
  13. package/dist/db/adapter/get-default-model-name.d.mts +1 -5
  14. package/dist/db/adapter/get-default-model-name.mjs +6 -5
  15. package/dist/db/adapter/get-field-attributes.d.mts +4 -11
  16. package/dist/db/adapter/get-field-name.d.mts +2 -9
  17. package/dist/db/adapter/get-id-field.d.mts +4 -12
  18. package/dist/db/adapter/get-model-name.d.mts +1 -5
  19. package/dist/db/adapter/index.d.mts +7 -32
  20. package/dist/db/adapter/types.d.mts +5 -17
  21. package/dist/db/adapter/utils.d.mts +0 -1
  22. package/dist/db/get-tables.d.mts +1 -0
  23. package/dist/db/get-tables.mjs +2 -2
  24. package/dist/db/plugin.d.mts +1 -2
  25. package/dist/db/schema/account.d.mts +1 -1
  26. package/dist/db/schema/account.mjs +12 -0
  27. package/dist/db/schema/rate-limit.d.mts +1 -1
  28. package/dist/db/schema/rate-limit.mjs +9 -0
  29. package/dist/db/schema/session.d.mts +1 -1
  30. package/dist/db/schema/shared.d.mts +0 -1
  31. package/dist/db/schema/user.d.mts +1 -1
  32. package/dist/db/schema/verification.d.mts +1 -1
  33. package/dist/db/type.d.mts +5 -8
  34. package/dist/env/logger.d.mts +25 -25
  35. package/dist/error/codes.d.mts +0 -1
  36. package/dist/error/index.d.mts +0 -1
  37. package/dist/index.d.mts +1 -1
  38. package/dist/instrumentation/attributes.d.mts +0 -1
  39. package/dist/instrumentation/pure.index.d.mts +0 -1
  40. package/dist/instrumentation/tracer.mjs +1 -1
  41. package/dist/oauth2/client-credentials-token.d.mts +4 -20
  42. package/dist/oauth2/client-credentials-token.mjs +1 -4
  43. package/dist/oauth2/create-authorization-url.d.mts +3 -20
  44. package/dist/oauth2/oauth-provider.d.mts +9 -3
  45. package/dist/oauth2/refresh-access-token.d.mts +4 -22
  46. package/dist/oauth2/refresh-access-token.mjs +2 -8
  47. package/dist/oauth2/reject-redirects.mjs +1 -1
  48. package/dist/oauth2/utils.d.mts +0 -1
  49. package/dist/oauth2/utils.mjs +1 -2
  50. package/dist/oauth2/validate-authorization-code.d.mts +6 -37
  51. package/dist/oauth2/verify.d.mts +12 -10
  52. package/dist/oauth2/verify.mjs +2 -2
  53. package/dist/social-providers/apple.d.mts +7 -28
  54. package/dist/social-providers/apple.mjs +2 -2
  55. package/dist/social-providers/atlassian.d.mts +3 -11
  56. package/dist/social-providers/cognito.d.mts +6 -12
  57. package/dist/social-providers/cognito.mjs +2 -2
  58. package/dist/social-providers/discord.d.mts +3 -9
  59. package/dist/social-providers/dropbox.d.mts +3 -11
  60. package/dist/social-providers/facebook.d.mts +6 -11
  61. package/dist/social-providers/facebook.mjs +2 -2
  62. package/dist/social-providers/figma.d.mts +3 -11
  63. package/dist/social-providers/github.d.mts +3 -12
  64. package/dist/social-providers/gitlab.d.mts +3 -12
  65. package/dist/social-providers/google.d.mts +7 -20
  66. package/dist/social-providers/google.mjs +2 -2
  67. package/dist/social-providers/huggingface.d.mts +3 -11
  68. package/dist/social-providers/index.d.mts +78 -362
  69. package/dist/social-providers/kakao.d.mts +3 -9
  70. package/dist/social-providers/kick.d.mts +3 -11
  71. package/dist/social-providers/line.d.mts +6 -13
  72. package/dist/social-providers/line.mjs +2 -2
  73. package/dist/social-providers/linear.d.mts +3 -10
  74. package/dist/social-providers/linkedin.d.mts +3 -10
  75. package/dist/social-providers/microsoft-entra-id.d.mts +5 -6
  76. package/dist/social-providers/microsoft-entra-id.mjs +4 -3
  77. package/dist/social-providers/naver.d.mts +22 -18
  78. package/dist/social-providers/notion.d.mts +3 -10
  79. package/dist/social-providers/paybin.d.mts +3 -12
  80. package/dist/social-providers/paypal.d.mts +6 -10
  81. package/dist/social-providers/paypal.mjs +2 -2
  82. package/dist/social-providers/polar.d.mts +3 -11
  83. package/dist/social-providers/railway.d.mts +3 -11
  84. package/dist/social-providers/reddit.d.mts +3 -9
  85. package/dist/social-providers/roblox.d.mts +3 -9
  86. package/dist/social-providers/salesforce.d.mts +3 -11
  87. package/dist/social-providers/slack.d.mts +3 -9
  88. package/dist/social-providers/spotify.d.mts +3 -11
  89. package/dist/social-providers/tiktok.d.mts +5 -10
  90. package/dist/social-providers/twitch.d.mts +3 -9
  91. package/dist/social-providers/twitter.d.mts +26 -17
  92. package/dist/social-providers/vercel.d.mts +3 -11
  93. package/dist/social-providers/vk.d.mts +3 -12
  94. package/dist/social-providers/vk.mjs +4 -5
  95. package/dist/social-providers/wechat.d.mts +3 -8
  96. package/dist/social-providers/zoom.d.mts +5 -14
  97. package/dist/types/context.d.mts +2 -1
  98. package/dist/types/cookie.d.mts +0 -1
  99. package/dist/types/helper.d.mts +1 -1
  100. package/dist/types/index.d.mts +1 -1
  101. package/dist/types/init-options.d.mts +10 -7
  102. package/dist/types/plugin-client.d.mts +1 -3
  103. package/dist/types/plugin.d.mts +2 -2
  104. package/dist/utils/async.d.mts +0 -1
  105. package/dist/utils/db.d.mts +1 -0
  106. package/dist/utils/deprecate.d.mts +0 -1
  107. package/dist/utils/error-codes.d.mts +2 -2
  108. package/dist/utils/host.d.mts +27 -1
  109. package/dist/utils/host.mjs +1 -1
  110. package/dist/utils/ip.d.mts +1 -0
  111. package/dist/utils/ip.mjs +1 -1
  112. package/dist/utils/is-api-error.d.mts +0 -1
  113. package/dist/utils/redirect-uri.d.mts +0 -1
  114. package/package.json +2 -2
  115. package/src/context/request-state.ts +26 -6
  116. package/src/db/adapter/get-default-model-name.ts +23 -14
  117. package/src/db/get-tables.ts +17 -2
  118. package/src/oauth2/oauth-provider.ts +20 -4
  119. package/src/social-providers/apple.ts +7 -2
  120. package/src/social-providers/cognito.ts +7 -2
  121. package/src/social-providers/facebook.ts +7 -2
  122. package/src/social-providers/google.ts +7 -2
  123. package/src/social-providers/line.ts +7 -2
  124. package/src/social-providers/microsoft-entra-id.ts +7 -2
  125. package/src/social-providers/paypal.ts +7 -2
@@ -1,20 +1,20 @@
1
1
  import { BetterAuthDBSchema, ModelNames, SecondaryStorage } from "../db/type.mjs";
2
2
  import { DBAdapter } from "../db/adapter/index.mjs";
3
3
  import { createLogger } from "../env/logger.mjs";
4
+ import "../db/index.mjs";
4
5
  import { AuthContext } from "../types/context.mjs";
6
+ import "../types/index.mjs";
5
7
  import { OAuthProvider } from "../oauth2/oauth-provider.mjs";
6
- import * as better_call0 from "better-call";
8
+ import "../oauth2/index.mjs";
7
9
  import { EndpointContext, EndpointOptions, StrictEndpoint } from "better-call";
8
- import * as _better_auth_core0 from "@better-auth/core";
9
-
10
10
  //#region src/api/index.d.ts
11
- declare const optionsMiddleware: <InputCtx extends better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>>(inputContext: InputCtx) => Promise<AuthContext>;
11
+ declare const optionsMiddleware: <InputCtx extends import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>>(inputContext: InputCtx) => Promise<AuthContext>;
12
12
  declare const createAuthMiddleware: {
13
- <Options extends better_call0.MiddlewareOptions, R>(options: Options, handler: (ctx: better_call0.MiddlewareContext<Options, {
13
+ <Options extends import("better-call").MiddlewareOptions, R>(options: Options, handler: (ctx: import("better-call").MiddlewareContext<Options, {
14
14
  returned?: unknown | undefined;
15
15
  responseHeaders?: Headers | undefined;
16
- } & _better_auth_core0.PluginContext<_better_auth_core0.BetterAuthOptions> & _better_auth_core0.InfoContext & {
17
- options: _better_auth_core0.BetterAuthOptions;
16
+ } & import("@better-auth/core").PluginContext<import("@better-auth/core").BetterAuthOptions> & import("@better-auth/core").InfoContext & {
17
+ options: import("@better-auth/core").BetterAuthOptions;
18
18
  trustedOrigins: string[];
19
19
  trustedProviders: string[];
20
20
  isTrustedOrigin: (url: string, settings?: {
@@ -88,19 +88,19 @@ declare const createAuthMiddleware: {
88
88
  } & Record<string, any>;
89
89
  } | null) => void;
90
90
  socialProviders: OAuthProvider[];
91
- authCookies: _better_auth_core0.BetterAuthCookies;
91
+ authCookies: import("@better-auth/core").BetterAuthCookies;
92
92
  logger: ReturnType<typeof createLogger>;
93
93
  rateLimit: {
94
94
  enabled: boolean;
95
95
  window: number;
96
96
  max: number;
97
97
  storage: "memory" | "database" | "secondary-storage";
98
- } & Omit<_better_auth_core0.BetterAuthRateLimitOptions, "enabled" | "window" | "max" | "storage">;
99
- adapter: DBAdapter<_better_auth_core0.BetterAuthOptions>;
100
- internalAdapter: _better_auth_core0.InternalAdapter<_better_auth_core0.BetterAuthOptions>;
101
- createAuthCookie: (cookieName: string, overrideAttributes?: Partial<better_call0.CookieOptions> | undefined) => _better_auth_core0.BetterAuthCookie;
98
+ } & Omit<import("@better-auth/core").BetterAuthRateLimitOptions, "enabled" | "window" | "max" | "storage">;
99
+ adapter: DBAdapter<import("@better-auth/core").BetterAuthOptions>;
100
+ internalAdapter: import("@better-auth/core").InternalAdapter<import("@better-auth/core").BetterAuthOptions>;
101
+ createAuthCookie: (cookieName: string, overrideAttributes?: Partial<import("better-call").CookieOptions> | undefined) => import("@better-auth/core").BetterAuthCookie;
102
102
  secret: string;
103
- secretConfig: string | _better_auth_core0.SecretConfig;
103
+ secretConfig: string | import("@better-auth/core").SecretConfig;
104
104
  sessionConfig: {
105
105
  updateAge: number;
106
106
  expiresIn: number;
@@ -125,7 +125,7 @@ declare const createAuthMiddleware: {
125
125
  minPasswordLength: number;
126
126
  maxPasswordLength: number;
127
127
  };
128
- checkPassword: (userId: string, ctx: _better_auth_core0.GenericEndpointContext<_better_auth_core0.BetterAuthOptions>) => Promise<boolean>;
128
+ checkPassword: (userId: string, ctx: import("@better-auth/core").GenericEndpointContext<import("@better-auth/core").BetterAuthOptions>) => Promise<boolean>;
129
129
  };
130
130
  tables: BetterAuthDBSchema;
131
131
  runMigrations: () => Promise<void>;
@@ -137,13 +137,13 @@ declare const createAuthMiddleware: {
137
137
  skipOriginCheck: boolean | string[];
138
138
  skipCSRFCheck: boolean;
139
139
  runInBackground: (promise: Promise<unknown>) => void;
140
- runInBackgroundOrAwait: (promise: Promise<unknown> | void) => _better_auth_core0.Awaitable<unknown>;
141
- }>) => Promise<R>): (inputContext: better_call0.MiddlewareInputContext<Options>) => Promise<R>;
142
- <Options extends better_call0.MiddlewareOptions, R_1>(handler: (ctx: better_call0.MiddlewareContext<Options, {
140
+ runInBackgroundOrAwait: (promise: Promise<unknown> | void) => import("@better-auth/core").Awaitable<unknown>;
141
+ }>) => Promise<R>): (inputContext: import("better-call").MiddlewareInputContext<Options>) => Promise<R>;
142
+ <Options extends import("better-call").MiddlewareOptions, R_1>(handler: (ctx: import("better-call").MiddlewareContext<Options, {
143
143
  returned?: unknown | undefined;
144
144
  responseHeaders?: Headers | undefined;
145
- } & _better_auth_core0.PluginContext<_better_auth_core0.BetterAuthOptions> & _better_auth_core0.InfoContext & {
146
- options: _better_auth_core0.BetterAuthOptions;
145
+ } & import("@better-auth/core").PluginContext<import("@better-auth/core").BetterAuthOptions> & import("@better-auth/core").InfoContext & {
146
+ options: import("@better-auth/core").BetterAuthOptions;
147
147
  trustedOrigins: string[];
148
148
  trustedProviders: string[];
149
149
  isTrustedOrigin: (url: string, settings?: {
@@ -217,19 +217,19 @@ declare const createAuthMiddleware: {
217
217
  } & Record<string, any>;
218
218
  } | null) => void;
219
219
  socialProviders: OAuthProvider[];
220
- authCookies: _better_auth_core0.BetterAuthCookies;
220
+ authCookies: import("@better-auth/core").BetterAuthCookies;
221
221
  logger: ReturnType<typeof createLogger>;
222
222
  rateLimit: {
223
223
  enabled: boolean;
224
224
  window: number;
225
225
  max: number;
226
226
  storage: "memory" | "database" | "secondary-storage";
227
- } & Omit<_better_auth_core0.BetterAuthRateLimitOptions, "enabled" | "window" | "max" | "storage">;
228
- adapter: DBAdapter<_better_auth_core0.BetterAuthOptions>;
229
- internalAdapter: _better_auth_core0.InternalAdapter<_better_auth_core0.BetterAuthOptions>;
230
- createAuthCookie: (cookieName: string, overrideAttributes?: Partial<better_call0.CookieOptions> | undefined) => _better_auth_core0.BetterAuthCookie;
227
+ } & Omit<import("@better-auth/core").BetterAuthRateLimitOptions, "enabled" | "window" | "max" | "storage">;
228
+ adapter: DBAdapter<import("@better-auth/core").BetterAuthOptions>;
229
+ internalAdapter: import("@better-auth/core").InternalAdapter<import("@better-auth/core").BetterAuthOptions>;
230
+ createAuthCookie: (cookieName: string, overrideAttributes?: Partial<import("better-call").CookieOptions> | undefined) => import("@better-auth/core").BetterAuthCookie;
231
231
  secret: string;
232
- secretConfig: string | _better_auth_core0.SecretConfig;
232
+ secretConfig: string | import("@better-auth/core").SecretConfig;
233
233
  sessionConfig: {
234
234
  updateAge: number;
235
235
  expiresIn: number;
@@ -254,7 +254,7 @@ declare const createAuthMiddleware: {
254
254
  minPasswordLength: number;
255
255
  maxPasswordLength: number;
256
256
  };
257
- checkPassword: (userId: string, ctx: _better_auth_core0.GenericEndpointContext<_better_auth_core0.BetterAuthOptions>) => Promise<boolean>;
257
+ checkPassword: (userId: string, ctx: import("@better-auth/core").GenericEndpointContext<import("@better-auth/core").BetterAuthOptions>) => Promise<boolean>;
258
258
  };
259
259
  tables: BetterAuthDBSchema;
260
260
  runMigrations: () => Promise<void>;
@@ -266,8 +266,8 @@ declare const createAuthMiddleware: {
266
266
  skipOriginCheck: boolean | string[];
267
267
  skipCSRFCheck: boolean;
268
268
  runInBackground: (promise: Promise<unknown>) => void;
269
- runInBackgroundOrAwait: (promise: Promise<unknown> | void) => _better_auth_core0.Awaitable<unknown>;
270
- }>) => Promise<R_1>): (inputContext: better_call0.MiddlewareInputContext<Options>) => Promise<R_1>;
269
+ runInBackgroundOrAwait: (promise: Promise<unknown> | void) => import("@better-auth/core").Awaitable<unknown>;
270
+ }>) => Promise<R_1>): (inputContext: import("better-call").MiddlewareInputContext<Options>) => Promise<R_1>;
271
271
  };
272
272
  type EndpointHandler<Path extends string, Options extends EndpointOptions, R> = (context: EndpointContext<Path, Options, AuthContext>) => Promise<R>;
273
273
  declare function createAuthEndpoint<Path extends string, Options extends EndpointOptions, R>(path: Path, options: Options, handler: EndpointHandler<Path, Options, R>): StrictEndpoint<Path, Options, R>;
@@ -1,5 +1,4 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
-
3
2
  //#region src/async_hooks/index.d.ts
4
3
  declare function getAsyncLocalStorage(): Promise<typeof AsyncLocalStorage>;
5
4
  //#endregion
@@ -1,5 +1,4 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
-
3
2
  //#region src/async_hooks/pure.index.d.ts
4
3
  declare function getAsyncLocalStorage(): Promise<typeof AsyncLocalStorage>;
5
4
  //#endregion
@@ -1,7 +1,7 @@
1
1
  import { AuthContext } from "../types/context.mjs";
2
+ import "../types/index.mjs";
2
3
  import { EndpointContext, InputContext } from "better-call";
3
4
  import { AsyncLocalStorage } from "@better-auth/core/async_hooks";
4
-
5
5
  //#region src/context/endpoint-context.d.ts
6
6
  type AuthEndpointContext = Partial<InputContext<string, any> & EndpointContext<string, any>> & {
7
7
  context: AuthContext;
@@ -1,5 +1,4 @@
1
1
  import { AsyncLocalStorage } from "@better-auth/core/async_hooks";
2
-
3
2
  //#region src/context/global.d.ts
4
3
  declare function getBetterAuthVersion(): string;
5
4
  //#endregion
@@ -2,7 +2,7 @@
2
2
  const symbol = Symbol.for("better-auth:global");
3
3
  let bind = null;
4
4
  const __context = {};
5
- const __betterAuthVersion = "1.6.22";
5
+ const __betterAuthVersion = "1.6.24";
6
6
  /**
7
7
  * We store context instance in the globalThis.
8
8
  *
@@ -1,5 +1,4 @@
1
1
  import { AsyncLocalStorage } from "@better-auth/core/async_hooks";
2
-
3
2
  //#region src/context/request-state.d.ts
4
3
  type RequestStateWeakMap = WeakMap<object, any>;
5
4
  declare function getRequestStateAsyncLocalStorage(): Promise<AsyncLocalStorage<RequestStateWeakMap>>;
@@ -1,13 +1,16 @@
1
1
  import { __getBetterAuthGlobal } from "./global.mjs";
2
2
  import { getAsyncLocalStorage } from "@better-auth/core/async_hooks";
3
3
  //#region src/context/request-state.ts
4
+ let asyncStorageInit = null;
4
5
  const ensureAsyncStorage = async () => {
5
6
  const betterAuthGlobal = __getBetterAuthGlobal();
6
- if (!betterAuthGlobal.context.requestStateAsyncStorage) {
7
- const AsyncLocalStorage = await getAsyncLocalStorage();
8
- betterAuthGlobal.context.requestStateAsyncStorage = new AsyncLocalStorage();
9
- }
10
- return betterAuthGlobal.context.requestStateAsyncStorage;
7
+ const existing = betterAuthGlobal.context.requestStateAsyncStorage;
8
+ if (existing) return existing;
9
+ if (!asyncStorageInit) asyncStorageInit = getAsyncLocalStorage().then((AsyncLocalStorage) => {
10
+ betterAuthGlobal.context.requestStateAsyncStorage ??= new AsyncLocalStorage();
11
+ return betterAuthGlobal.context.requestStateAsyncStorage;
12
+ });
13
+ return asyncStorageInit;
11
14
  };
12
15
  async function getRequestStateAsyncLocalStorage() {
13
16
  return ensureAsyncStorage();
@@ -1,7 +1,7 @@
1
1
  import { DBAdapter, DBTransactionAdapter } from "../db/adapter/index.mjs";
2
2
  import { BetterAuthOptions } from "../types/init-options.mjs";
3
+ import "../types/index.mjs";
3
4
  import { AsyncLocalStorage } from "node:async_hooks";
4
-
5
5
  //#region src/context/transaction.d.ts
6
6
  type StoredAdapter = DBTransactionAdapter<BetterAuthOptions>;
7
7
  type HookContext = {
@@ -7,11 +7,9 @@ import { initGetModelName } from "./get-model-name.mjs";
7
7
  import { AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFactoryOptions, AdapterTestDebugLogs } from "./types.mjs";
8
8
  import { DBAdapter } from "./index.mjs";
9
9
  import { BetterAuthOptions } from "../../types/init-options.mjs";
10
+ import "../../types/index.mjs";
10
11
  //#region src/db/adapter/factory.d.ts
11
12
  type AdapterFactory<Options extends BetterAuthOptions> = (options: Options) => DBAdapter<Options>;
12
- declare const createAdapterFactory: <Options extends BetterAuthOptions>({
13
- adapter: customAdapter,
14
- config: cfg
15
- }: AdapterFactoryOptions) => AdapterFactory<Options>;
13
+ declare const createAdapterFactory: <Options extends BetterAuthOptions>({ adapter: customAdapter, config: cfg }: AdapterFactoryOptions) => AdapterFactory<Options>;
16
14
  //#endregion
17
- export { AdapterFactory, createAdapterFactory };
15
+ export { AdapterFactory, AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFactoryOptions, AdapterTestDebugLogs, createAdapterFactory, initGetDefaultFieldName, initGetDefaultModelName, initGetFieldAttributes, initGetFieldName, initGetIdField, initGetModelName };
@@ -902,4 +902,4 @@ function formatAction(action) {
902
902
  return `${TTY_COLORS.dim}(${action})${TTY_COLORS.reset}`;
903
903
  }
904
904
  //#endregion
905
- export { createAdapterFactory };
905
+ export { createAdapterFactory, initGetDefaultFieldName, initGetDefaultModelName, initGetFieldAttributes, initGetFieldName, initGetIdField, initGetModelName };
@@ -1,16 +1,9 @@
1
1
  import { BetterAuthDBSchema } from "../type.mjs";
2
-
3
2
  //#region src/db/adapter/get-default-field-name.d.ts
4
- declare const initGetDefaultFieldName: ({
5
- schema,
6
- usePlural
7
- }: {
3
+ declare const initGetDefaultFieldName: ({ schema, usePlural }: {
8
4
  schema: BetterAuthDBSchema;
9
5
  usePlural: boolean | undefined;
10
- }) => ({
11
- field,
12
- model: unsafeModel
13
- }: {
6
+ }) => ({ field, model: unsafeModel }: {
14
7
  model: string;
15
8
  field: string;
16
9
  }) => string;
@@ -1,10 +1,6 @@
1
1
  import { BetterAuthDBSchema } from "../type.mjs";
2
-
3
2
  //#region src/db/adapter/get-default-model-name.d.ts
4
- declare const initGetDefaultModelName: ({
5
- usePlural,
6
- schema
7
- }: {
3
+ declare const initGetDefaultModelName: ({ usePlural, schema }: {
8
4
  usePlural: boolean | undefined;
9
5
  schema: BetterAuthDBSchema;
10
6
  }) => (model: string) => string;
@@ -13,14 +13,15 @@ const initGetDefaultModelName = ({ usePlural, schema }) => {
13
13
  * 3. Using this function helps us get the actual model name based on the user's defined custom modelName.
14
14
  */
15
15
  const getDefaultModelName = (model) => {
16
+ const resolve = (candidate) => {
17
+ if (schema[candidate]) return candidate;
18
+ return Object.entries(schema).find(([_, f]) => f.modelName === candidate)?.[0];
19
+ };
16
20
  if (usePlural && model.charAt(model.length - 1) === "s") {
17
- const pluralessModel = model.slice(0, -1);
18
- let m = schema[pluralessModel] ? pluralessModel : void 0;
19
- if (!m) m = Object.entries(schema).find(([_, f]) => f.modelName === pluralessModel)?.[0];
21
+ const m = resolve(model.slice(0, -1));
20
22
  if (m) return m;
21
23
  }
22
- let m = schema[model] ? model : void 0;
23
- if (!m) m = Object.entries(schema).find(([_, f]) => f.modelName === model)?.[0];
24
+ const m = resolve(model);
24
25
  if (!m) throw new BetterAuthError(`Model "${model}" not found in schema`);
25
26
  return m;
26
27
  };
@@ -1,13 +1,9 @@
1
1
  import { BetterAuthDBSchema, DBFieldAttribute, DBFieldType } from "../type.mjs";
2
2
  import { BetterAuthOptions } from "../../types/init-options.mjs";
3
+ import "../index.mjs";
4
+ import "../../types/index.mjs";
3
5
  //#region src/db/adapter/get-field-attributes.d.ts
4
- declare const initGetFieldAttributes: ({
5
- usePlural,
6
- schema,
7
- options,
8
- customIdGenerator,
9
- disableIdGeneration
10
- }: {
6
+ declare const initGetFieldAttributes: ({ usePlural, schema, options, customIdGenerator, disableIdGeneration }: {
11
7
  usePlural?: boolean;
12
8
  schema: BetterAuthDBSchema;
13
9
  options: BetterAuthOptions;
@@ -15,10 +11,7 @@ declare const initGetFieldAttributes: ({
15
11
  customIdGenerator?: ((props: {
16
12
  model: string;
17
13
  }) => string) | undefined;
18
- }) => ({
19
- model,
20
- field
21
- }: {
14
+ }) => ({ model, field }: {
22
15
  model: string;
23
16
  field: string;
24
17
  }) => DBFieldAttribute<DBFieldType>;
@@ -1,16 +1,9 @@
1
1
  import { BetterAuthDBSchema } from "../type.mjs";
2
-
3
2
  //#region src/db/adapter/get-field-name.d.ts
4
- declare const initGetFieldName: ({
5
- schema,
6
- usePlural
7
- }: {
3
+ declare const initGetFieldName: ({ schema, usePlural }: {
8
4
  schema: BetterAuthDBSchema;
9
5
  usePlural: boolean | undefined;
10
- }) => ({
11
- model: modelName,
12
- field: fieldName
13
- }: {
6
+ }) => ({ model: modelName, field: fieldName }: {
14
7
  model: string;
15
8
  field: string;
16
9
  }) => string;
@@ -1,14 +1,9 @@
1
1
  import { BetterAuthDBSchema, DBPrimitive } from "../type.mjs";
2
2
  import { BetterAuthOptions } from "../../types/init-options.mjs";
3
+ import "../index.mjs";
4
+ import "../../types/index.mjs";
3
5
  //#region src/db/adapter/get-id-field.d.ts
4
- declare const initGetIdField: ({
5
- usePlural,
6
- schema,
7
- disableIdGeneration,
8
- options,
9
- customIdGenerator,
10
- supportsUUIDs
11
- }: {
6
+ declare const initGetIdField: ({ usePlural, schema, disableIdGeneration, options, customIdGenerator, supportsUUIDs }: {
12
7
  usePlural?: boolean;
13
8
  schema: BetterAuthDBSchema;
14
9
  options: BetterAuthOptions;
@@ -17,10 +12,7 @@ declare const initGetIdField: ({
17
12
  model: string;
18
13
  }) => string) | undefined;
19
14
  supportsUUIDs?: boolean;
20
- }) => ({
21
- customModelName,
22
- forceAllowId
23
- }: {
15
+ }) => ({ customModelName, forceAllowId }: {
24
16
  customModelName?: string;
25
17
  forceAllowId?: boolean;
26
18
  }) => {
@@ -1,10 +1,6 @@
1
1
  import { BetterAuthDBSchema } from "../type.mjs";
2
-
3
2
  //#region src/db/adapter/get-model-name.d.ts
4
- declare const initGetModelName: ({
5
- usePlural,
6
- schema
7
- }: {
3
+ declare const initGetModelName: ({ usePlural, schema }: {
8
4
  usePlural: boolean | undefined;
9
5
  schema: BetterAuthDBSchema;
10
6
  }) => (model: string) => string;
@@ -9,6 +9,7 @@ import { AdapterFactoryConfig, AdapterFactoryCustomizeAdapterCreator, AdapterFac
9
9
  import { AdapterFactory, createAdapterFactory } from "./factory.mjs";
10
10
  import { deepmerge, withApplyDefault } from "./utils.mjs";
11
11
  import { BetterAuthOptions } from "../../types/init-options.mjs";
12
+ import "../../types/index.mjs";
12
13
  //#region src/db/adapter/index.d.ts
13
14
  type DBAdapterDebugLogOption = boolean | {
14
15
  /**
@@ -490,11 +491,7 @@ type DBAdapter<Options extends BetterAuthOptions = BetterAuthOptions> = {
490
491
  };
491
492
  type CleanedWhere = Required<Where>;
492
493
  interface CustomAdapter {
493
- create: <T extends Record<string, any>>({
494
- data,
495
- model,
496
- select
497
- }: {
494
+ create: <T extends Record<string, any>>({ data, model, select }: {
498
495
  model: string;
499
496
  data: T;
500
497
  select?: string[] | undefined;
@@ -509,26 +506,13 @@ interface CustomAdapter {
509
506
  where: CleanedWhere[];
510
507
  update: Record<string, any>;
511
508
  }) => Promise<number>;
512
- findOne: <T>({
513
- model,
514
- where,
515
- select,
516
- join
517
- }: {
509
+ findOne: <T>({ model, where, select, join }: {
518
510
  model: string;
519
511
  where: CleanedWhere[];
520
512
  select?: string[] | undefined;
521
513
  join?: JoinConfig | undefined;
522
514
  }) => Promise<T | null>;
523
- findMany: <T>({
524
- model,
525
- where,
526
- limit,
527
- select,
528
- sortBy,
529
- offset,
530
- join
531
- }: {
515
+ findMany: <T>({ model, where, limit, select, sortBy, offset, join }: {
532
516
  model: string;
533
517
  where?: CleanedWhere[] | undefined;
534
518
  limit: number;
@@ -540,17 +524,11 @@ interface CustomAdapter {
540
524
  offset?: number | undefined;
541
525
  join?: JoinConfig | undefined;
542
526
  }) => Promise<T[]>;
543
- delete: ({
544
- model,
545
- where
546
- }: {
527
+ delete: ({ model, where }: {
547
528
  model: string;
548
529
  where: CleanedWhere[];
549
530
  }) => Promise<void>;
550
- deleteMany: ({
551
- model,
552
- where
553
- }: {
531
+ deleteMany: ({ model, where }: {
554
532
  model: string;
555
533
  where: CleanedWhere[];
556
534
  }) => Promise<number>;
@@ -586,10 +564,7 @@ interface CustomAdapter {
586
564
  increment: Record<string, number>;
587
565
  set?: Record<string, unknown> | undefined;
588
566
  }) => Promise<T | null>;
589
- count: ({
590
- model,
591
- where
592
- }: {
567
+ count: ({ model, where }: {
593
568
  model: string;
594
569
  where?: CleanedWhere[] | undefined;
595
570
  }) => Promise<number>;
@@ -1,6 +1,7 @@
1
1
  import { BetterAuthDBSchema, DBFieldAttribute } from "../type.mjs";
2
2
  import { CleanedWhere, CustomAdapter, DBAdapterFactoryConfig, DBTransactionAdapter, JoinConfig, Where } from "./index.mjs";
3
3
  import { BetterAuthOptions } from "../../types/init-options.mjs";
4
+ import "../../types/index.mjs";
4
5
  //#region src/db/adapter/types.d.ts
5
6
  type AdapterFactoryOptions = {
6
7
  config: AdapterFactoryConfig;
@@ -35,10 +36,7 @@ type AdapterFactoryCustomizeAdapterCreator = (config: {
35
36
  /**
36
37
  * Get the field name which is expected to be saved in the database based on the user's schema.
37
38
  */
38
- getFieldName: ({
39
- model,
40
- field
41
- }: {
39
+ getFieldName: ({ model, field }: {
42
40
  model: string;
43
41
  field: string;
44
42
  }) => string;
@@ -66,10 +64,7 @@ type AdapterFactoryCustomizeAdapterCreator = (config: {
66
64
  * 2. When using a custom fieldName, doing something like `schema[model].fields[field]` will not work.
67
65
  *
68
66
  */
69
- getDefaultFieldName: ({
70
- model,
71
- field
72
- }: {
67
+ getDefaultFieldName: ({ model, field }: {
73
68
  model: string;
74
69
  field: string;
75
70
  }) => string;
@@ -78,20 +73,13 @@ type AdapterFactoryCustomizeAdapterCreator = (config: {
78
73
  *
79
74
  * Note: any model name or field name is allowed, whether default to schema or not.
80
75
  */
81
- getFieldAttributes: ({
82
- model,
83
- field
84
- }: {
76
+ getFieldAttributes: ({ model, field }: {
85
77
  model: string;
86
78
  field: string;
87
79
  }) => DBFieldAttribute;
88
80
  transformInput: (data: Record<string, unknown>, defaultModelName: string, action: "create" | "update", forceAllowId?: boolean | undefined) => Promise<Record<string, unknown>>;
89
81
  transformOutput: (data: Record<string, unknown>, defaultModelName: string, select?: string[] | undefined, joinConfig?: JoinConfig | undefined) => Promise<Record<string, unknown>>;
90
- transformWhereClause: <W extends Where[] | undefined>({
91
- model,
92
- where,
93
- action
94
- }: {
82
+ transformWhereClause: <W extends Where[] | undefined>({ model, where, action }: {
95
83
  where: W;
96
84
  model: string;
97
85
  action: "create" | "update" | "findOne" | "findMany" | "updateMany" | "delete" | "deleteMany" | "consumeOne" | "incrementOne" | "count";
@@ -1,5 +1,4 @@
1
1
  import { DBFieldAttribute } from "../type.mjs";
2
-
3
2
  //#region src/db/adapter/utils.d.ts
4
3
  declare function withApplyDefault(value: any, field: DBFieldAttribute, action: "create" | "update" | "findOne" | "findMany"): any;
5
4
  declare function deepmerge<T>(target: T, source: Partial<T>): T;
@@ -1,5 +1,6 @@
1
1
  import { BetterAuthDBSchema } from "./type.mjs";
2
2
  import { BetterAuthOptions } from "../types/init-options.mjs";
3
+ import "../types/index.mjs";
3
4
  //#region src/db/get-tables.d.ts
4
5
  declare const getAuthTables: (options: BetterAuthOptions) => BetterAuthDBSchema;
5
6
  //#endregion
@@ -115,7 +115,7 @@ const getAuthTables = (options) => {
115
115
  type: "string",
116
116
  fieldName: options.session?.fields?.userId || "userId",
117
117
  references: {
118
- model: options.user?.modelName || "user",
118
+ model: "user",
119
119
  field: "id",
120
120
  onDelete: "cascade"
121
121
  },
@@ -191,7 +191,7 @@ const getAuthTables = (options) => {
191
191
  userId: {
192
192
  type: "string",
193
193
  references: {
194
- model: options.user?.modelName || "user",
194
+ model: "user",
195
195
  field: "id",
196
196
  onDelete: "cascade"
197
197
  },
@@ -1,5 +1,4 @@
1
1
  import { DBFieldAttribute } from "./type.mjs";
2
-
3
2
  //#region src/db/plugin.d.ts
4
3
  type BetterAuthPluginDBSchema = { [table in string]: {
5
4
  fields: {
@@ -7,6 +6,6 @@ type BetterAuthPluginDBSchema = { [table in string]: {
7
6
  };
8
7
  disableMigration?: boolean | undefined;
9
8
  modelName?: string | undefined;
10
- } };
9
+ }; };
11
10
  //#endregion
12
11
  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";
4
5
  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;
@@ -8,9 +8,21 @@ const accountSchema = coreSchema.extend({
8
8
  accessToken: z.string().nullish(),
9
9
  refreshToken: z.string().nullish(),
10
10
  idToken: z.string().nullish(),
11
+ /**
12
+ * Access token expires at
13
+ */
11
14
  accessTokenExpiresAt: z.date().nullish(),
15
+ /**
16
+ * Refresh token expires at
17
+ */
12
18
  refreshTokenExpiresAt: z.date().nullish(),
19
+ /**
20
+ * The scopes that the user has authorized
21
+ */
13
22
  scope: z.string().nullish(),
23
+ /**
24
+ * Password is only stored in the credential provider
25
+ */
14
26
  password: z.string().nullish()
15
27
  });
16
28
  //#endregion
@@ -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";
4
5
  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,17 @@
1
1
  import * as z from "zod";
2
2
  //#region src/db/schema/rate-limit.ts
3
3
  const rateLimitSchema = z.object({
4
+ /**
5
+ * The key to use for rate limiting
6
+ */
4
7
  key: z.string(),
8
+ /**
9
+ * The number of requests made
10
+ */
5
11
  count: z.number(),
12
+ /**
13
+ * The last request time in milliseconds
14
+ */
6
15
  lastRequest: z.number()
7
16
  });
8
17
  //#endregion
@@ -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";
4
5
  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,5 +1,4 @@
1
1
  import * as z from "zod";
2
-
3
2
  //#region src/db/schema/shared.d.ts
4
3
  declare const coreSchema: z.ZodObject<{
5
4
  id: z.ZodString;