@better-auth/core 1.3.27 → 1.3.29

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 (121) hide show
  1. package/.turbo/turbo-build.log +54 -4
  2. package/build.config.ts +6 -0
  3. package/dist/db/adapter/index.d.cts +13 -23
  4. package/dist/db/adapter/index.d.mts +13 -23
  5. package/dist/db/adapter/index.d.ts +13 -23
  6. package/dist/db/index.cjs +16 -0
  7. package/dist/db/index.d.cts +6 -83
  8. package/dist/db/index.d.mts +6 -83
  9. package/dist/db/index.d.ts +6 -83
  10. package/dist/db/index.mjs +16 -1
  11. package/dist/env/index.cjs +312 -0
  12. package/dist/env/index.d.cts +36 -0
  13. package/dist/env/index.d.mts +36 -0
  14. package/dist/env/index.d.ts +36 -0
  15. package/dist/env/index.mjs +297 -0
  16. package/dist/error/index.cjs +44 -0
  17. package/dist/error/index.d.cts +33 -0
  18. package/dist/error/index.d.mts +33 -0
  19. package/dist/error/index.d.ts +33 -0
  20. package/dist/error/index.mjs +41 -0
  21. package/dist/index.d.cts +156 -101
  22. package/dist/index.d.mts +156 -101
  23. package/dist/index.d.ts +156 -101
  24. package/dist/middleware/index.cjs +25 -0
  25. package/dist/middleware/index.d.cts +13 -0
  26. package/dist/middleware/index.d.mts +13 -0
  27. package/dist/middleware/index.d.ts +13 -0
  28. package/dist/middleware/index.mjs +21 -0
  29. package/dist/oauth2/index.cjs +368 -0
  30. package/dist/oauth2/index.d.cts +100 -0
  31. package/dist/oauth2/index.d.mts +100 -0
  32. package/dist/oauth2/index.d.ts +100 -0
  33. package/dist/oauth2/index.mjs +357 -0
  34. package/dist/shared/core.Bl6TpxyD.d.mts +181 -0
  35. package/dist/shared/core.Bqe5IGAi.d.ts +13 -0
  36. package/dist/shared/core.Bshk2o_x.d.ts +1721 -0
  37. package/dist/shared/core.BwoNUcJQ.d.cts +53 -0
  38. package/dist/shared/core.BwoNUcJQ.d.mts +53 -0
  39. package/dist/shared/core.BwoNUcJQ.d.ts +53 -0
  40. package/dist/shared/core.C6_2xGyf.d.mts +1721 -0
  41. package/dist/shared/{core.CnvFgghY.d.cts → core.CajxAutx.d.cts} +27 -1
  42. package/dist/shared/{core.CnvFgghY.d.mts → core.CajxAutx.d.mts} +27 -1
  43. package/dist/shared/{core.CnvFgghY.d.ts → core.CajxAutx.d.ts} +27 -1
  44. package/dist/shared/core.CfqdiZTu.d.cts +1721 -0
  45. package/dist/shared/core.DkdZ1o38.d.ts +181 -0
  46. package/dist/shared/core.Dl-70uns.d.cts +84 -0
  47. package/dist/shared/core.Dl-70uns.d.mts +84 -0
  48. package/dist/shared/core.Dl-70uns.d.ts +84 -0
  49. package/dist/shared/core.DyEdx0m7.d.cts +181 -0
  50. package/dist/shared/core.E9DfzGLz.d.mts +13 -0
  51. package/dist/shared/core.HqYn20Fi.d.cts +13 -0
  52. package/dist/social-providers/index.cjs +2793 -0
  53. package/dist/social-providers/index.d.cts +3903 -0
  54. package/dist/social-providers/index.d.mts +3903 -0
  55. package/dist/social-providers/index.d.ts +3903 -0
  56. package/dist/social-providers/index.mjs +2743 -0
  57. package/dist/utils/index.cjs +7 -0
  58. package/dist/utils/index.d.cts +10 -0
  59. package/dist/utils/index.d.mts +10 -0
  60. package/dist/utils/index.d.ts +10 -0
  61. package/dist/utils/index.mjs +5 -0
  62. package/package.json +98 -2
  63. package/src/db/adapter/index.ts +424 -0
  64. package/src/db/index.ts +2 -0
  65. package/src/db/schema/rate-limit.ts +21 -0
  66. package/src/db/type.ts +28 -0
  67. package/src/env/color-depth.ts +172 -0
  68. package/src/env/env-impl.ts +124 -0
  69. package/src/env/index.ts +23 -0
  70. package/src/env/logger.test.ts +33 -0
  71. package/src/env/logger.ts +145 -0
  72. package/src/error/codes.ts +31 -0
  73. package/src/error/index.ts +11 -0
  74. package/src/index.ts +0 -2
  75. package/src/middleware/index.ts +33 -0
  76. package/src/oauth2/client-credentials-token.ts +102 -0
  77. package/src/oauth2/create-authorization-url.ts +85 -0
  78. package/src/oauth2/index.ts +22 -0
  79. package/src/oauth2/oauth-provider.ts +194 -0
  80. package/src/oauth2/refresh-access-token.ts +124 -0
  81. package/src/oauth2/utils.ts +36 -0
  82. package/src/oauth2/validate-authorization-code.ts +156 -0
  83. package/src/social-providers/apple.ts +213 -0
  84. package/src/social-providers/atlassian.ts +130 -0
  85. package/src/social-providers/cognito.ts +269 -0
  86. package/src/social-providers/discord.ts +172 -0
  87. package/src/social-providers/dropbox.ts +112 -0
  88. package/src/social-providers/facebook.ts +204 -0
  89. package/src/social-providers/figma.ts +115 -0
  90. package/src/social-providers/github.ts +154 -0
  91. package/src/social-providers/gitlab.ts +152 -0
  92. package/src/social-providers/google.ts +171 -0
  93. package/src/social-providers/huggingface.ts +116 -0
  94. package/src/social-providers/index.ts +118 -0
  95. package/src/social-providers/kakao.ts +178 -0
  96. package/src/social-providers/kick.ts +95 -0
  97. package/src/social-providers/line.ts +169 -0
  98. package/src/social-providers/linear.ts +120 -0
  99. package/src/social-providers/linkedin.ts +110 -0
  100. package/src/social-providers/microsoft-entra-id.ts +243 -0
  101. package/src/social-providers/naver.ts +112 -0
  102. package/src/social-providers/notion.ts +106 -0
  103. package/src/social-providers/paypal.ts +261 -0
  104. package/src/social-providers/reddit.ts +122 -0
  105. package/src/social-providers/roblox.ts +110 -0
  106. package/src/social-providers/salesforce.ts +157 -0
  107. package/src/social-providers/slack.ts +114 -0
  108. package/src/social-providers/spotify.ts +93 -0
  109. package/src/social-providers/tiktok.ts +211 -0
  110. package/src/social-providers/twitch.ts +111 -0
  111. package/src/social-providers/twitter.ts +194 -0
  112. package/src/social-providers/vk.ts +128 -0
  113. package/src/social-providers/zoom.ts +218 -0
  114. package/src/types/context.ts +334 -0
  115. package/src/types/cookie.ts +7 -0
  116. package/src/types/index.ts +19 -1
  117. package/src/types/init-options.ts +1048 -2
  118. package/src/types/plugin-client.ts +69 -0
  119. package/src/types/plugin.ts +134 -0
  120. package/src/utils/error-codes.ts +51 -0
  121. package/src/utils/index.ts +1 -0
package/dist/index.d.ts CHANGED
@@ -1,124 +1,179 @@
1
- import { L as LiteralUnion, M as Models } from './shared/core.CnvFgghY.js';
2
- export { a as LiteralString } from './shared/core.CnvFgghY.js';
3
- import { CookieOptions } from 'better-call';
1
+ import { L as LiteralString } from './shared/core.CajxAutx.js';
2
+ export { a as LiteralUnion } from './shared/core.CajxAutx.js';
3
+ import { A as AuthContext, B as BetterAuthOptions, a as AuthMiddleware } from './shared/core.Bshk2o_x.js';
4
+ export { b as BetterAuthAdvancedOptions, d as BetterAuthCookies, c as BetterAuthRateLimitOptions, G as GenerateIdFn, e as GenericEndpointContext, I as InternalAdapter } from './shared/core.Bshk2o_x.js';
5
+ import { Migration } from 'kysely';
6
+ import { Endpoint, Middleware, EndpointContext, InputContext } from 'better-call';
7
+ import { B as BetterAuthPluginDBSchema } from './shared/core.Bqe5IGAi.js';
8
+ import { BetterFetch, BetterFetchOption, BetterFetchPlugin } from '@better-fetch/fetch';
9
+ import { WritableAtom, Atom } from 'nanostores';
4
10
  import 'zod';
11
+ import './shared/core.Dl-70uns.js';
12
+ import 'bun:sqlite';
13
+ import 'node:sqlite';
14
+ import './social-providers/index.js';
15
+ import '@better-auth/core/oauth2';
16
+ import './shared/core.DkdZ1o38.js';
17
+ import './shared/core.BwoNUcJQ.js';
18
+ import '@better-auth/core';
5
19
 
6
- type GenerateIdFn = (options: {
7
- model: LiteralUnion<Models, string>;
8
- size?: number;
9
- }) => string | false;
10
- type BetterAuthAdvancedOptions = {
20
+ type Awaitable<T> = T | Promise<T>;
21
+ type DeepPartial<T> = T extends Function ? T : T extends object ? {
22
+ [K in keyof T]?: DeepPartial<T[K]>;
23
+ } : T;
24
+ type HookEndpointContext = EndpointContext<string, any> & Omit<InputContext<string, any>, "method"> & {
25
+ context: AuthContext & {
26
+ returned?: unknown;
27
+ responseHeaders?: Headers;
28
+ };
29
+ headers?: Headers;
30
+ };
31
+ type BetterAuthPlugin = {
32
+ id: LiteralString;
11
33
  /**
12
- * Ip address configuration
34
+ * The init function is called when the plugin is initialized.
35
+ * You can return a new context or modify the existing context.
13
36
  */
14
- ipAddress?: {
15
- /**
16
- * List of headers to use for ip address
17
- *
18
- * Ip address is used for rate limiting and session tracking
19
- *
20
- * @example ["x-client-ip", "x-forwarded-for", "cf-connecting-ip"]
21
- *
22
- * @default
23
- * @link https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/utils/get-request-ip.ts#L8
24
- */
25
- ipAddressHeaders?: string[];
26
- /**
27
- * Disable ip tracking
28
- *
29
- * ⚠︎ This is a security risk and it may expose your application to abuse
30
- */
31
- disableIpTracking?: boolean;
37
+ init?: (ctx: AuthContext) => Awaitable<{
38
+ context?: DeepPartial<Omit<AuthContext, "options">>;
39
+ options?: Partial<BetterAuthOptions>;
40
+ }> | void | Promise<void>;
41
+ endpoints?: {
42
+ [key: string]: Endpoint;
43
+ };
44
+ middlewares?: {
45
+ path: string;
46
+ middleware: Middleware;
47
+ }[];
48
+ onRequest?: (request: Request, ctx: AuthContext) => Promise<{
49
+ response: Response;
50
+ } | {
51
+ request: Request;
52
+ } | void>;
53
+ onResponse?: (response: Response, ctx: AuthContext) => Promise<{
54
+ response: Response;
55
+ } | void>;
56
+ hooks?: {
57
+ before?: {
58
+ matcher: (context: HookEndpointContext) => boolean;
59
+ handler: AuthMiddleware;
60
+ }[];
61
+ after?: {
62
+ matcher: (context: HookEndpointContext) => boolean;
63
+ handler: AuthMiddleware;
64
+ }[];
32
65
  };
33
66
  /**
34
- * Use secure cookies
67
+ * Schema the plugin needs
68
+ *
69
+ * This will also be used to migrate the database. If the fields are dynamic from the plugins
70
+ * configuration each time the configuration is changed a new migration will be created.
35
71
  *
36
- * @default false
72
+ * NOTE: If you want to create migrations manually using
73
+ * migrations option or any other way you
74
+ * can disable migration per table basis.
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * schema: {
79
+ * user: {
80
+ * fields: {
81
+ * email: {
82
+ * type: "string",
83
+ * },
84
+ * emailVerified: {
85
+ * type: "boolean",
86
+ * defaultValue: false,
87
+ * },
88
+ * },
89
+ * }
90
+ * } as AuthPluginSchema
91
+ * ```
37
92
  */
38
- useSecureCookies?: boolean;
93
+ schema?: BetterAuthPluginDBSchema;
39
94
  /**
40
- * Disable trusted origins check
95
+ * The migrations of the plugin. If you define schema that will automatically create
96
+ * migrations for you.
41
97
  *
42
- * ⚠︎ This is a security risk and it may expose your application to CSRF attacks
98
+ * ⚠️ Only uses this if you dont't want to use the schema option and you disabled migrations for
99
+ * the tables.
43
100
  */
44
- disableCSRFCheck?: boolean;
101
+ migrations?: Record<string, Migration>;
45
102
  /**
46
- * Configure cookies to be cross subdomains
103
+ * The options of the plugin
47
104
  */
48
- crossSubDomainCookies?: {
49
- /**
50
- * Enable cross subdomain cookies
51
- */
52
- enabled: boolean;
53
- /**
54
- * Additional cookies to be shared across subdomains
55
- */
56
- additionalCookies?: string[];
57
- /**
58
- * The domain to use for the cookies
59
- *
60
- * By default, the domain will be the root
61
- * domain from the base URL.
62
- */
63
- domain?: string;
64
- };
65
- cookies?: {
66
- [key: string]: {
67
- name?: string;
68
- attributes?: CookieOptions;
69
- };
70
- };
71
- defaultCookieAttributes?: CookieOptions;
105
+ options?: Record<string, any> | undefined;
72
106
  /**
73
- * Prefix for cookies. If a cookie name is provided
74
- * in cookies config, this will be overridden.
75
- *
76
- * @default
77
- * ```txt
78
- * "appName" -> which defaults to "better-auth"
79
- * ```
107
+ * types to be inferred
80
108
  */
81
- cookiePrefix?: string;
109
+ $Infer?: Record<string, any>;
82
110
  /**
83
- * Database configuration.
111
+ * The rate limit rules to apply to specific paths.
84
112
  */
85
- database?: {
86
- /**
87
- * The default number of records to return from the database
88
- * when using the `findMany` adapter method.
89
- *
90
- * @default 100
91
- */
92
- defaultFindManyLimit?: number;
93
- /**
94
- * If your database auto increments number ids, set this to `true`.
95
- *
96
- * Note: If enabled, we will not handle ID generation (including if you use `generateId`), and it would be expected that your database will provide the ID automatically.
97
- *
98
- * @default false
99
- */
100
- useNumberId?: boolean;
101
- /**
102
- * Custom generateId function.
103
- *
104
- * If not provided, random ids will be generated.
105
- * If set to false, the database's auto generated id will be used.
106
- */
107
- generateId?: GenerateIdFn | false;
108
- };
113
+ rateLimit?: {
114
+ window: number;
115
+ max: number;
116
+ pathMatcher: (path: string) => boolean;
117
+ }[];
109
118
  /**
110
- * Custom generateId function.
111
- *
112
- * If not provided, random ids will be generated.
113
- * If set to false, the database's auto generated id will be used.
114
- *
115
- * @deprecated Please use `database.generateId` instead. This will be potentially removed in future releases.
119
+ * The error codes returned by the plugin
116
120
  */
117
- generateId?: GenerateIdFn | false;
121
+ $ERROR_CODES?: Record<string, string>;
118
122
  };
119
123
 
120
- interface BetterAuthMutators<O, C> {
124
+ interface ClientStore {
125
+ notify: (signal: string) => void;
126
+ listen: (signal: string, listener: () => void) => void;
127
+ atoms: Record<string, WritableAtom<any>>;
128
+ }
129
+ type ClientAtomListener = {
130
+ matcher: (path: string) => boolean;
131
+ signal: "$sessionSignal" | Omit<string, "$sessionSignal">;
132
+ };
133
+ interface BetterAuthClientOptions {
134
+ fetchOptions?: BetterFetchOption;
135
+ plugins?: BetterAuthClientPlugin[];
136
+ baseURL?: string;
137
+ basePath?: string;
138
+ disableDefaultFetchPlugins?: boolean;
139
+ $InferAuth?: BetterAuthOptions;
140
+ }
141
+ interface BetterAuthClientPlugin {
142
+ id: LiteralString;
143
+ /**
144
+ * only used for type inference. don't pass the
145
+ * actual plugin
146
+ */
147
+ $InferServerPlugin?: BetterAuthPlugin;
148
+ /**
149
+ * Custom actions
150
+ */
151
+ getActions?: ($fetch: BetterFetch, $store: ClientStore,
152
+ /**
153
+ * better-auth client options
154
+ */
155
+ options: BetterAuthClientOptions | undefined) => Record<string, any>;
156
+ /**
157
+ * State atoms that'll be resolved by each framework
158
+ * auth store.
159
+ */
160
+ getAtoms?: ($fetch: BetterFetch) => Record<string, Atom<any>>;
161
+ /**
162
+ * specify path methods for server plugin inferred
163
+ * endpoints to force a specific method.
164
+ */
165
+ pathMethods?: Record<string, "POST" | "GET">;
166
+ /**
167
+ * Better fetch plugins
168
+ */
169
+ fetchPlugins?: BetterFetchPlugin[];
170
+ /**
171
+ * a list of recaller based on a matcher function.
172
+ * The signal name needs to match a signal in this
173
+ * plugin or any plugin the user might have added.
174
+ */
175
+ atomListeners?: ClientAtomListener[];
121
176
  }
122
177
 
123
- export { LiteralUnion };
124
- export type { BetterAuthAdvancedOptions, BetterAuthMutators, GenerateIdFn };
178
+ export { AuthContext, BetterAuthOptions, LiteralString };
179
+ export type { BetterAuthClientOptions, BetterAuthClientPlugin, BetterAuthPlugin, ClientAtomListener, ClientStore };
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ const betterCall = require('better-call');
4
+
5
+ const optionsMiddleware = betterCall.createMiddleware(async () => {
6
+ return {};
7
+ });
8
+ const createAuthMiddleware = betterCall.createMiddleware.create({
9
+ use: [
10
+ optionsMiddleware,
11
+ /**
12
+ * Only use for post hooks
13
+ */
14
+ betterCall.createMiddleware(async () => {
15
+ return {};
16
+ })
17
+ ]
18
+ });
19
+ const createAuthEndpoint = betterCall.createEndpoint.create({
20
+ use: [optionsMiddleware]
21
+ });
22
+
23
+ exports.createAuthEndpoint = createAuthEndpoint;
24
+ exports.createAuthMiddleware = createAuthMiddleware;
25
+ exports.optionsMiddleware = optionsMiddleware;
@@ -0,0 +1,13 @@
1
+ import 'better-call';
2
+ import '../shared/core.CajxAutx.cjs';
3
+ export { n as AuthEndpoint, a as AuthMiddleware, m as createAuthEndpoint, l as createAuthMiddleware, o as optionsMiddleware } from '../shared/core.CfqdiZTu.cjs';
4
+ import 'zod';
5
+ import 'kysely';
6
+ import '../shared/core.Dl-70uns.cjs';
7
+ import 'bun:sqlite';
8
+ import 'node:sqlite';
9
+ import '../social-providers/index.cjs';
10
+ import '@better-auth/core/oauth2';
11
+ import '../shared/core.DyEdx0m7.cjs';
12
+ import '../shared/core.BwoNUcJQ.cjs';
13
+ import '@better-auth/core';
@@ -0,0 +1,13 @@
1
+ import 'better-call';
2
+ import '../shared/core.CajxAutx.mjs';
3
+ export { n as AuthEndpoint, a as AuthMiddleware, m as createAuthEndpoint, l as createAuthMiddleware, o as optionsMiddleware } from '../shared/core.C6_2xGyf.mjs';
4
+ import 'zod';
5
+ import 'kysely';
6
+ import '../shared/core.Dl-70uns.mjs';
7
+ import 'bun:sqlite';
8
+ import 'node:sqlite';
9
+ import '../social-providers/index.mjs';
10
+ import '@better-auth/core/oauth2';
11
+ import '../shared/core.Bl6TpxyD.mjs';
12
+ import '../shared/core.BwoNUcJQ.mjs';
13
+ import '@better-auth/core';
@@ -0,0 +1,13 @@
1
+ import 'better-call';
2
+ import '../shared/core.CajxAutx.js';
3
+ export { n as AuthEndpoint, a as AuthMiddleware, m as createAuthEndpoint, l as createAuthMiddleware, o as optionsMiddleware } from '../shared/core.Bshk2o_x.js';
4
+ import 'zod';
5
+ import 'kysely';
6
+ import '../shared/core.Dl-70uns.js';
7
+ import 'bun:sqlite';
8
+ import 'node:sqlite';
9
+ import '../social-providers/index.js';
10
+ import '@better-auth/core/oauth2';
11
+ import '../shared/core.DkdZ1o38.js';
12
+ import '../shared/core.BwoNUcJQ.js';
13
+ import '@better-auth/core';
@@ -0,0 +1,21 @@
1
+ import { createMiddleware, createEndpoint } from 'better-call';
2
+
3
+ const optionsMiddleware = createMiddleware(async () => {
4
+ return {};
5
+ });
6
+ const createAuthMiddleware = createMiddleware.create({
7
+ use: [
8
+ optionsMiddleware,
9
+ /**
10
+ * Only use for post hooks
11
+ */
12
+ createMiddleware(async () => {
13
+ return {};
14
+ })
15
+ ]
16
+ });
17
+ const createAuthEndpoint = createEndpoint.create({
18
+ use: [optionsMiddleware]
19
+ });
20
+
21
+ export { createAuthEndpoint, createAuthMiddleware, optionsMiddleware };