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

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 (124) 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 +14 -23
  4. package/dist/db/adapter/index.d.mts +14 -23
  5. package/dist/db/adapter/index.d.ts +14 -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 +315 -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 +300 -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 +159 -94
  22. package/dist/index.d.mts +159 -94
  23. package/dist/index.d.ts +159 -94
  24. package/dist/middleware/index.cjs +25 -0
  25. package/dist/middleware/index.d.cts +14 -0
  26. package/dist/middleware/index.d.mts +14 -0
  27. package/dist/middleware/index.d.ts +14 -0
  28. package/dist/middleware/index.mjs +21 -0
  29. package/dist/oauth2/index.cjs +368 -0
  30. package/dist/oauth2/index.d.cts +99 -0
  31. package/dist/oauth2/index.d.mts +99 -0
  32. package/dist/oauth2/index.d.ts +99 -0
  33. package/dist/oauth2/index.mjs +357 -0
  34. package/dist/shared/core.2rWMW9q9.d.ts +13 -0
  35. package/dist/shared/core.40VTWh-p.d.cts +217 -0
  36. package/dist/shared/core.BfcVdsSf.d.cts +181 -0
  37. package/dist/shared/core.Bisb2Bdk.d.mts +181 -0
  38. package/dist/shared/core.BwoNUcJQ.d.cts +53 -0
  39. package/dist/shared/core.BwoNUcJQ.d.mts +53 -0
  40. package/dist/shared/core.BwoNUcJQ.d.ts +53 -0
  41. package/dist/shared/core.CErFRCOZ.d.mts +1684 -0
  42. package/dist/shared/core.CGN6D-Mh.d.ts +181 -0
  43. package/dist/shared/core.CPuIItYE.d.ts +217 -0
  44. package/dist/shared/core.CftpHMDz.d.cts +13 -0
  45. package/dist/shared/core.Db7zJyxf.d.ts +1684 -0
  46. package/dist/shared/core.DqaxObkf.d.cts +1684 -0
  47. package/dist/shared/core.MjcDoj7R.d.cts +5 -0
  48. package/dist/shared/core.MjcDoj7R.d.mts +5 -0
  49. package/dist/shared/core.MjcDoj7R.d.ts +5 -0
  50. package/dist/shared/core.g2ZbxAEV.d.mts +217 -0
  51. package/dist/shared/core.g9ACQ8v2.d.mts +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 +99 -2
  63. package/src/db/adapter/index.ts +424 -0
  64. package/src/db/index.ts +4 -0
  65. package/src/db/schema/rate-limit.ts +21 -0
  66. package/src/db/type.ts +29 -10
  67. package/src/env/color-depth.ts +171 -0
  68. package/src/env/env-impl.ts +123 -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 +270 -0
  115. package/src/types/cookie.ts +7 -0
  116. package/src/types/index.ts +19 -1
  117. package/src/types/init-options.ts +1039 -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
  122. package/dist/shared/core.CnvFgghY.d.cts +0 -117
  123. package/dist/shared/core.CnvFgghY.d.mts +0 -117
  124. package/dist/shared/core.CnvFgghY.d.ts +0 -117
@@ -0,0 +1,5 @@
1
+ type Primitive = string | number | symbol | bigint | boolean | null | undefined;
2
+ type LiteralString = "" | (string & Record<never, never>);
3
+ type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
4
+
5
+ export type { LiteralString as L, LiteralUnion as a };
@@ -0,0 +1,5 @@
1
+ type Primitive = string | number | symbol | bigint | boolean | null | undefined;
2
+ type LiteralString = "" | (string & Record<never, never>);
3
+ type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
4
+
5
+ export type { LiteralString as L, LiteralUnion as a };
@@ -0,0 +1,5 @@
1
+ type Primitive = string | number | symbol | bigint | boolean | null | undefined;
2
+ type LiteralString = "" | (string & Record<never, never>);
3
+ type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
4
+
5
+ export type { LiteralString as L, LiteralUnion as a };
@@ -0,0 +1,217 @@
1
+ import * as z from 'zod';
2
+ import { ZodType } from 'zod';
3
+ import { L as LiteralString } from './core.MjcDoj7R.mjs';
4
+
5
+ type DBPreservedModels = "user" | "account" | "session" | "verification" | "rate-limit" | "organization" | "member" | "invitation" | "jwks" | "passkey" | "two-factor";
6
+ type DBFieldType = "string" | "number" | "boolean" | "date" | "json" | `${"string" | "number"}[]` | Array<LiteralString>;
7
+ type DBPrimitive = string | number | boolean | Date | null | undefined | string[] | number[];
8
+ type DBFieldAttributeConfig = {
9
+ /**
10
+ * If the field should be required on a new record.
11
+ * @default true
12
+ */
13
+ required?: boolean;
14
+ /**
15
+ * If the value should be returned on a response body.
16
+ * @default true
17
+ */
18
+ returned?: boolean;
19
+ /**
20
+ * If a value should be provided when creating a new record.
21
+ * @default true
22
+ */
23
+ input?: boolean;
24
+ /**
25
+ * Default value for the field
26
+ *
27
+ * Note: This will not create a default value on the database level. It will only
28
+ * be used when creating a new record.
29
+ */
30
+ defaultValue?: DBPrimitive | (() => DBPrimitive);
31
+ /**
32
+ * Update value for the field
33
+ *
34
+ * Note: This will create an onUpdate trigger on the database level for supported adapters.
35
+ * It will be called when updating a record.
36
+ */
37
+ onUpdate?: () => DBPrimitive;
38
+ /**
39
+ * transform the value before storing it.
40
+ */
41
+ transform?: {
42
+ input?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
43
+ output?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
44
+ };
45
+ /**
46
+ * Reference to another model.
47
+ */
48
+ references?: {
49
+ /**
50
+ * The model to reference.
51
+ */
52
+ model: string;
53
+ /**
54
+ * The field on the referenced model.
55
+ */
56
+ field: string;
57
+ /**
58
+ * The action to perform when the reference is deleted.
59
+ * @default "cascade"
60
+ */
61
+ onDelete?: "no action" | "restrict" | "cascade" | "set null" | "set default";
62
+ };
63
+ unique?: boolean;
64
+ /**
65
+ * If the field should be a bigint on the database instead of integer.
66
+ */
67
+ bigint?: boolean;
68
+ /**
69
+ * A zod schema to validate the value.
70
+ */
71
+ validator?: {
72
+ input?: ZodType;
73
+ output?: ZodType;
74
+ };
75
+ /**
76
+ * The name of the field on the database.
77
+ */
78
+ fieldName?: string;
79
+ /**
80
+ * If the field should be sortable.
81
+ *
82
+ * applicable only for `text` type.
83
+ * It's useful to mark fields varchar instead of text.
84
+ */
85
+ sortable?: boolean;
86
+ };
87
+ type DBFieldAttribute<T extends DBFieldType = DBFieldType> = {
88
+ type: T;
89
+ } & DBFieldAttributeConfig;
90
+ type BetterAuthDBSchema = Record<string, {
91
+ /**
92
+ * The name of the table in the database
93
+ */
94
+ modelName: string;
95
+ /**
96
+ * The fields of the table
97
+ */
98
+ fields: Record<string, DBFieldAttribute>;
99
+ /**
100
+ * Whether to disable migrations for this table
101
+ * @default false
102
+ */
103
+ disableMigrations?: boolean;
104
+ /**
105
+ * The order of the table
106
+ */
107
+ order?: number;
108
+ }>;
109
+ interface SecondaryStorage {
110
+ /**
111
+ *
112
+ * @param key - Key to get
113
+ * @returns - Value of the key
114
+ */
115
+ get: (key: string) => Promise<unknown> | unknown;
116
+ set: (
117
+ /**
118
+ * Key to store
119
+ */
120
+ key: string,
121
+ /**
122
+ * Value to store
123
+ */
124
+ value: string,
125
+ /**
126
+ * Time to live in seconds
127
+ */
128
+ ttl?: number) => Promise<void | null | unknown> | void;
129
+ /**
130
+ *
131
+ * @param key - Key to delete
132
+ */
133
+ delete: (key: string) => Promise<void | null | string> | void;
134
+ }
135
+
136
+ declare const userSchema: z.ZodObject<{
137
+ id: z.ZodString;
138
+ createdAt: z.ZodDefault<z.ZodDate>;
139
+ updatedAt: z.ZodDefault<z.ZodDate>;
140
+ email: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
141
+ emailVerified: z.ZodDefault<z.ZodBoolean>;
142
+ name: z.ZodString;
143
+ image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
144
+ }, z.core.$strip>;
145
+ /**
146
+ * User schema type used by better-auth, note that it's possible that user could have additional fields
147
+ *
148
+ * todo: we should use generics to extend this type with additional fields from plugins and options in the future
149
+ */
150
+ type User = z.infer<typeof userSchema>;
151
+
152
+ declare const accountSchema: z.ZodObject<{
153
+ id: z.ZodString;
154
+ createdAt: z.ZodDefault<z.ZodDate>;
155
+ updatedAt: z.ZodDefault<z.ZodDate>;
156
+ providerId: z.ZodString;
157
+ accountId: z.ZodString;
158
+ userId: z.ZodCoercedString<unknown>;
159
+ accessToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
160
+ refreshToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
161
+ idToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
162
+ accessTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
163
+ refreshTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
164
+ scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
165
+ password: z.ZodOptional<z.ZodNullable<z.ZodString>>;
166
+ }, z.core.$strip>;
167
+ /**
168
+ * Account schema type used by better-auth, note that it's possible that account could have additional fields
169
+ *
170
+ * todo: we should use generics to extend this type with additional fields from plugins and options in the future
171
+ */
172
+ type Account = z.infer<typeof accountSchema>;
173
+
174
+ declare const sessionSchema: z.ZodObject<{
175
+ id: z.ZodString;
176
+ createdAt: z.ZodDefault<z.ZodDate>;
177
+ updatedAt: z.ZodDefault<z.ZodDate>;
178
+ userId: z.ZodCoercedString<unknown>;
179
+ expiresAt: z.ZodDate;
180
+ token: z.ZodString;
181
+ ipAddress: z.ZodOptional<z.ZodNullable<z.ZodString>>;
182
+ userAgent: z.ZodOptional<z.ZodNullable<z.ZodString>>;
183
+ }, z.core.$strip>;
184
+ /**
185
+ * Session schema type used by better-auth, note that it's possible that session could have additional fields
186
+ *
187
+ * todo: we should use generics to extend this type with additional fields from plugins and options in the future
188
+ */
189
+ type Session = z.infer<typeof sessionSchema>;
190
+
191
+ declare const verificationSchema: z.ZodObject<{
192
+ id: z.ZodString;
193
+ createdAt: z.ZodDefault<z.ZodDate>;
194
+ updatedAt: z.ZodDefault<z.ZodDate>;
195
+ value: z.ZodString;
196
+ expiresAt: z.ZodDate;
197
+ identifier: z.ZodString;
198
+ }, z.core.$strip>;
199
+ /**
200
+ * Verification schema type used by better-auth, note that it's possible that verification could have additional fields
201
+ *
202
+ * todo: we should use generics to extend this type with additional fields from plugins and options in the future
203
+ */
204
+ type Verification = z.infer<typeof verificationSchema>;
205
+
206
+ declare const rateLimitSchema: z.ZodObject<{
207
+ key: z.ZodString;
208
+ count: z.ZodNumber;
209
+ lastRequest: z.ZodNumber;
210
+ }, z.core.$strip>;
211
+ /**
212
+ * Rate limit schema type used by better-auth for rate limiting
213
+ */
214
+ type RateLimit = z.infer<typeof rateLimitSchema>;
215
+
216
+ export { accountSchema as e, rateLimitSchema as r, sessionSchema as s, userSchema as u, verificationSchema as v };
217
+ export type { Account as A, BetterAuthDBSchema as B, DBFieldAttribute as D, RateLimit as R, SecondaryStorage as S, User as U, Verification as V, DBFieldAttributeConfig as a, DBFieldType as b, DBPrimitive as c, DBPreservedModels as d, Session as f };
@@ -0,0 +1,13 @@
1
+ import { D as DBFieldAttribute } from './core.g2ZbxAEV.mjs';
2
+
3
+ type BetterAuthPluginDBSchema = {
4
+ [table in string]: {
5
+ fields: {
6
+ [field in string]: DBFieldAttribute;
7
+ };
8
+ disableMigration?: boolean;
9
+ modelName?: string;
10
+ };
11
+ };
12
+
13
+ export type { BetterAuthPluginDBSchema as B };