@better-auth/core 1.4.0-beta.6 → 1.4.0-beta.7

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 (39) hide show
  1. package/.turbo/turbo-build.log +14 -9
  2. package/build.config.ts +6 -1
  3. package/dist/async_hooks/index.cjs +27 -0
  4. package/dist/async_hooks/index.d.cts +10 -0
  5. package/dist/async_hooks/index.d.mts +10 -0
  6. package/dist/async_hooks/index.d.ts +10 -0
  7. package/dist/async_hooks/index.mjs +25 -0
  8. package/dist/db/adapter/index.cjs +2 -0
  9. package/dist/db/adapter/index.d.cts +23 -0
  10. package/dist/db/adapter/index.d.mts +23 -0
  11. package/dist/db/adapter/index.d.ts +23 -0
  12. package/dist/db/adapter/index.mjs +1 -0
  13. package/dist/db/index.cjs +73 -0
  14. package/dist/db/index.d.cts +91 -105
  15. package/dist/db/index.d.mts +91 -105
  16. package/dist/db/index.d.ts +91 -105
  17. package/dist/db/index.mjs +54 -0
  18. package/dist/index.d.cts +114 -1
  19. package/dist/index.d.mts +114 -1
  20. package/dist/index.d.ts +114 -1
  21. package/dist/shared/core.CnvFgghY.d.cts +117 -0
  22. package/dist/shared/core.CnvFgghY.d.mts +117 -0
  23. package/dist/shared/core.CnvFgghY.d.ts +117 -0
  24. package/package.json +24 -1
  25. package/src/async_hooks/index.ts +43 -0
  26. package/src/db/adapter/index.ts +24 -0
  27. package/src/db/index.ts +11 -0
  28. package/src/db/plugin.ts +11 -0
  29. package/src/db/schema/account.ts +34 -0
  30. package/src/db/schema/session.ts +17 -0
  31. package/src/db/schema/shared.ts +7 -0
  32. package/src/db/schema/user.ts +16 -0
  33. package/src/db/schema/verification.ts +15 -0
  34. package/src/db/type.ts +22 -0
  35. package/src/index.ts +3 -1
  36. package/src/types/helper.ts +5 -0
  37. package/src/types/index.ts +2 -1
  38. package/src/types/init-options.ts +119 -0
  39. package/tsconfig.json +1 -1
@@ -0,0 +1,16 @@
1
+ import * as z from "zod";
2
+ import { coreSchema } from "./shared";
3
+
4
+ export const userSchema = coreSchema.extend({
5
+ email: z.string().transform((val) => val.toLowerCase()),
6
+ emailVerified: z.boolean().default(false),
7
+ name: z.string(),
8
+ image: z.string().nullish(),
9
+ });
10
+
11
+ /**
12
+ * User schema type used by better-auth, note that it's possible that user could have additional fields
13
+ *
14
+ * todo: we should use generics to extend this type with additional fields from plugins and options in the future
15
+ */
16
+ export type User = z.infer<typeof userSchema>;
@@ -0,0 +1,15 @@
1
+ import * as z from "zod";
2
+ import { coreSchema } from "./shared";
3
+
4
+ export const verificationSchema = coreSchema.extend({
5
+ value: z.string(),
6
+ expiresAt: z.date(),
7
+ identifier: z.string(),
8
+ });
9
+
10
+ /**
11
+ * Verification schema type used by better-auth, note that it's possible that verification could have additional fields
12
+ *
13
+ * todo: we should use generics to extend this type with additional fields from plugins and options in the future
14
+ */
15
+ export type Verification = z.infer<typeof verificationSchema>;
package/src/db/type.ts CHANGED
@@ -1,6 +1,28 @@
1
1
  import type { ZodType } from "zod";
2
2
  import type { LiteralString } from "../types";
3
3
 
4
+ declare module "../index" {
5
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
+ interface BetterAuthMutators<O, C> {
7
+ "better-auth/db": {
8
+ // todo: we should infer the schema from the adapter
9
+ };
10
+ }
11
+ }
12
+
13
+ export type Models =
14
+ | "user"
15
+ | "account"
16
+ | "session"
17
+ | "verification"
18
+ | "rate-limit"
19
+ | "organization"
20
+ | "member"
21
+ | "invitation"
22
+ | "jwks"
23
+ | "passkey"
24
+ | "two-factor";
25
+
4
26
  export type DBFieldType =
5
27
  | "string"
6
28
  | "number"
package/src/index.ts CHANGED
@@ -1 +1,3 @@
1
- export {};
1
+ // Shared types and interfaces for BetterAuth, allowing plugins to extend functionality.
2
+ export interface BetterAuthMutators<O, C> {}
3
+ export * from "./types";
@@ -1 +1,6 @@
1
+ type Primitive = string | number | symbol | bigint | boolean | null | undefined;
2
+
1
3
  export type LiteralString = "" | (string & Record<never, never>);
4
+ export type LiteralUnion<LiteralType, BaseType extends Primitive> =
5
+ | LiteralType
6
+ | (BaseType & Record<never, never>);
@@ -1 +1,2 @@
1
- export * from "./helper";
1
+ export type * from "./helper";
2
+ export type { BetterAuthAdvancedOptions, GenerateIdFn } from "./init-options";
@@ -0,0 +1,119 @@
1
+ import type { CookieOptions } from "better-call";
2
+ import type { LiteralUnion } from "./helper";
3
+ import type { Models } from "../db/type";
4
+
5
+ export type GenerateIdFn = (options: {
6
+ model: LiteralUnion<Models, string>;
7
+ size?: number;
8
+ }) => string | false;
9
+
10
+ export type BetterAuthAdvancedOptions = {
11
+ /**
12
+ * Ip address configuration
13
+ */
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;
32
+ };
33
+ /**
34
+ * Use secure cookies
35
+ *
36
+ * @default false
37
+ */
38
+ useSecureCookies?: boolean;
39
+ /**
40
+ * Disable trusted origins check
41
+ *
42
+ * ⚠︎ This is a security risk and it may expose your application to CSRF attacks
43
+ */
44
+ disableCSRFCheck?: boolean;
45
+ /**
46
+ * Configure cookies to be cross subdomains
47
+ */
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
+ /*
66
+ * Allows you to change default cookie names and attributes
67
+ *
68
+ * default cookie names:
69
+ * - "session_token"
70
+ * - "session_data"
71
+ * - "dont_remember"
72
+ *
73
+ * plugins can also add additional cookies
74
+ */
75
+ cookies?: {
76
+ [key: string]: {
77
+ name?: string;
78
+ attributes?: CookieOptions;
79
+ };
80
+ };
81
+ defaultCookieAttributes?: CookieOptions;
82
+ /**
83
+ * Prefix for cookies. If a cookie name is provided
84
+ * in cookies config, this will be overridden.
85
+ *
86
+ * @default
87
+ * ```txt
88
+ * "appName" -> which defaults to "better-auth"
89
+ * ```
90
+ */
91
+ cookiePrefix?: string;
92
+ /**
93
+ * Database configuration.
94
+ */
95
+ database?: {
96
+ /**
97
+ * The default number of records to return from the database
98
+ * when using the `findMany` adapter method.
99
+ *
100
+ * @default 100
101
+ */
102
+ defaultFindManyLimit?: number;
103
+ /**
104
+ * If your database auto increments number ids, set this to `true`.
105
+ *
106
+ * 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.
107
+ *
108
+ * @default false
109
+ */
110
+ useNumberId?: boolean;
111
+ /**
112
+ * Custom generateId function.
113
+ *
114
+ * If not provided, random ids will be generated.
115
+ * If set to false, the database's auto generated id will be used.
116
+ */
117
+ generateId?: GenerateIdFn | false;
118
+ };
119
+ };
package/tsconfig.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "rootDir": "./src",
5
5
  "outDir": "./dist",
6
6
  "lib": ["esnext", "dom", "dom.iterable"],
7
- "types": []
7
+ "types": ["node"]
8
8
  },
9
9
  "include": ["src"]
10
10
  }