better-auth 0.2.8-beta.8 → 0.2.8

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 (44) hide show
  1. package/dist/.DS_Store +0 -0
  2. package/dist/access.js +13 -2
  3. package/dist/adapters/drizzle.d.ts +1 -1
  4. package/dist/adapters/drizzle.js +13 -23
  5. package/dist/adapters/mongodb.d.ts +1 -1
  6. package/dist/adapters/mongodb.js +3 -2
  7. package/dist/adapters/prisma.d.ts +1 -1
  8. package/dist/adapters/prisma.js +3 -280
  9. package/dist/api.d.ts +1 -1
  10. package/dist/api.js +407 -269
  11. package/dist/cli.js +213 -55
  12. package/dist/client/plugins.d.ts +5 -3
  13. package/dist/client/plugins.js +49 -34
  14. package/dist/client.d.ts +3 -1
  15. package/dist/client.js +34 -32
  16. package/dist/{index-CKn-Zrry.d.ts → index-C9S3KShG.d.ts} +50 -63
  17. package/dist/{index-DtRHPoYF.d.ts → index-UOcOxfoL.d.ts} +6 -5
  18. package/dist/index.d.ts +1 -1
  19. package/dist/index.js +501 -372
  20. package/dist/next-js.d.ts +1 -1
  21. package/dist/next-js.js +6 -5
  22. package/dist/node.d.ts +1 -1
  23. package/dist/node.js +5 -5
  24. package/dist/plugins.d.ts +8 -5
  25. package/dist/plugins.js +716 -498
  26. package/dist/react.d.ts +4 -2
  27. package/dist/react.js +37 -33
  28. package/dist/social.js +116 -68
  29. package/dist/solid-start.d.ts +1 -1
  30. package/dist/solid-start.js +3 -2
  31. package/dist/solid.d.ts +2 -1
  32. package/dist/solid.js +35 -32
  33. package/dist/svelte-kit.d.ts +1 -1
  34. package/dist/svelte-kit.js +6 -4
  35. package/dist/svelte.d.ts +2 -1
  36. package/dist/svelte.js +33 -32
  37. package/dist/types.d.ts +2 -2
  38. package/dist/types.js +0 -1
  39. package/dist/vue.d.ts +3 -1
  40. package/dist/vue.js +35 -32
  41. package/package.json +2 -3
  42. package/dist/hide-metadata-DEHJp1rk.d.ts +0 -5
  43. package/dist/utils.d.ts +0 -51
  44. package/dist/utils.js +0 -426
package/dist/.DS_Store CHANGED
Binary file
package/dist/access.js CHANGED
@@ -110,5 +110,16 @@ var defaultRoles = {
110
110
  var permissionFromString = (permission) => {
111
111
  return Role.fromString(permission ?? "");
112
112
  };
113
-
114
- export { AccessControl, ParsingError, Role, adminAc, createAccessControl, defaultAc, defaultRoles, defaultStatements, memberAc, ownerAc, permissionFromString };
113
+ export {
114
+ AccessControl,
115
+ ParsingError,
116
+ Role,
117
+ adminAc,
118
+ createAccessControl,
119
+ defaultAc,
120
+ defaultRoles,
121
+ defaultStatements,
122
+ memberAc,
123
+ ownerAc,
124
+ permissionFromString
125
+ };
@@ -1,4 +1,4 @@
1
- import { A as Adapter } from '../index-CKn-Zrry.js';
1
+ import { A as Adapter } from '../index-C9S3KShG.js';
2
2
  import 'kysely';
3
3
  import '../index-JM-i6hLs.js';
4
4
  import 'arctic';
@@ -1,14 +1,5 @@
1
- import { eq, and, or } from 'drizzle-orm';
2
- import { existsSync } from 'fs';
3
- import fs from 'fs/promises';
4
- import 'oslo';
5
- import 'nanoid';
6
- import { createConsola } from 'consola';
7
- import 'oslo/oauth2';
8
- import 'zod';
9
- import 'chalk';
10
-
11
1
  // src/adapters/drizzle-adapter/index.ts
2
+ import { and, eq, or } from "drizzle-orm";
12
3
 
13
4
  // src/db/get-tables.ts
14
5
  var getAuthTables = (options) => {
@@ -178,16 +169,10 @@ var getAuthTables = (options) => {
178
169
  ...shouldAddRateLimitTable ? rateLimitTable : {}
179
170
  };
180
171
  };
181
- createConsola({
182
- formatOptions: {
183
- date: false,
184
- colors: true,
185
- compact: true
186
- },
187
- defaults: {
188
- tag: "Better Auth"
189
- }
190
- });
172
+
173
+ // src/adapters/drizzle-adapter/index.ts
174
+ import { existsSync } from "fs";
175
+ import fs from "fs/promises";
191
176
 
192
177
  // src/error/better-auth-error.ts
193
178
  var BetterAuthError = class extends Error {
@@ -199,6 +184,9 @@ var BetterAuthError = class extends Error {
199
184
  this.stack = "";
200
185
  }
201
186
  };
187
+
188
+ // src/adapters/drizzle-adapter/index.ts
189
+ import "chalk";
202
190
  function getSchema(modelName, options) {
203
191
  const schema = options.schema;
204
192
  if (!schema) {
@@ -318,7 +306,7 @@ var drizzleAdapter = (db, options) => {
318
306
  let code = `import { ${databaseType}Table, text, ${int}, ${timestampAndBoolean} } from "drizzle-orm/${databaseType}-core";
319
307
  `;
320
308
  const fileExist = existsSync(filePath);
321
- fileExist ? await fs.readFile(filePath, "utf-8") : "";
309
+ let fileContent = fileExist ? await fs.readFile(filePath, "utf-8") : "";
322
310
  for (const table in tables) {
323
311
  let getType2 = function(name, type) {
324
312
  if (type === "string") {
@@ -344,6 +332,7 @@ var drizzleAdapter = (db, options) => {
344
332
  return `timestamp('${name}')`;
345
333
  }
346
334
  };
335
+ var getType = getType2;
347
336
  const tableName = tables[table].tableName;
348
337
  const fields = tables[table].fields;
349
338
  const schema2 = `export const ${table} = ${databaseType}Table("${tableName}", {
@@ -365,5 +354,6 @@ ${schema2}
365
354
  }
366
355
  };
367
356
  };
368
-
369
- export { drizzleAdapter };
357
+ export {
358
+ drizzleAdapter
359
+ };
@@ -1,4 +1,4 @@
1
- import { W as Where } from '../index-CKn-Zrry.js';
1
+ import { W as Where } from '../index-C9S3KShG.js';
2
2
  import 'kysely';
3
3
  import '../index-JM-i6hLs.js';
4
4
  import 'arctic';
@@ -97,5 +97,6 @@ var mongodbAdapter = (mongo) => {
97
97
  }
98
98
  };
99
99
  };
100
-
101
- export { mongodbAdapter };
100
+ export {
101
+ mongodbAdapter
102
+ };
@@ -1,4 +1,4 @@
1
- import { A as Adapter } from '../index-CKn-Zrry.js';
1
+ import { A as Adapter } from '../index-C9S3KShG.js';
2
2
  import 'kysely';
3
3
  import '../index-JM-i6hLs.js';
4
4
  import 'arctic';
@@ -1,199 +1,3 @@
1
- import { existsSync } from 'fs';
2
- import path from 'path';
3
- import fs from 'fs/promises';
4
- import { produceSchema } from '@mrleebo/prisma-ast';
5
- import 'oslo';
6
- import 'nanoid';
7
- import { createConsola } from 'consola';
8
- import 'oslo/oauth2';
9
- import 'zod';
10
-
11
- // src/adapters/prisma-adapter/index.ts
12
-
13
- // src/db/get-tables.ts
14
- var getAuthTables = (options) => {
15
- const pluginSchema = options.plugins?.reduce(
16
- (acc, plugin) => {
17
- const schema = plugin.schema;
18
- if (!schema) return acc;
19
- for (const [key, value] of Object.entries(schema)) {
20
- acc[key] = {
21
- fields: {
22
- ...acc[key]?.fields,
23
- ...value.fields
24
- },
25
- tableName: key
26
- };
27
- }
28
- return acc;
29
- },
30
- {}
31
- );
32
- const shouldAddRateLimitTable = options.rateLimit?.storage === "database";
33
- const rateLimitTable = {
34
- rateLimit: {
35
- tableName: options.rateLimit?.tableName || "rateLimit",
36
- fields: {
37
- key: {
38
- type: "string"
39
- },
40
- count: {
41
- type: "number"
42
- },
43
- lastRequest: {
44
- type: "number"
45
- }
46
- }
47
- }
48
- };
49
- const { user, session, account, ...pluginTables } = pluginSchema || {};
50
- const accountFields = options.account?.fields;
51
- const userFields = options.user?.fields;
52
- return {
53
- user: {
54
- tableName: options.user?.modelName || "user",
55
- fields: {
56
- [userFields?.name || "name"]: {
57
- type: "string",
58
- required: true
59
- },
60
- email: {
61
- type: "string",
62
- unique: true,
63
- required: true
64
- },
65
- emailVerified: {
66
- type: "boolean",
67
- defaultValue: () => false,
68
- required: true
69
- },
70
- image: {
71
- type: "string",
72
- required: false
73
- },
74
- createdAt: {
75
- type: "date",
76
- defaultValue: () => /* @__PURE__ */ new Date(),
77
- required: true
78
- },
79
- updatedAt: {
80
- type: "date",
81
- defaultValue: () => /* @__PURE__ */ new Date(),
82
- required: true
83
- },
84
- ...user?.fields
85
- },
86
- order: 0
87
- },
88
- session: {
89
- tableName: options.session?.modelName || "session",
90
- fields: {
91
- expiresAt: {
92
- type: "date",
93
- required: true
94
- },
95
- ipAddress: {
96
- type: "string",
97
- required: false
98
- },
99
- userAgent: {
100
- type: "string",
101
- required: false
102
- },
103
- userId: {
104
- type: "string",
105
- references: {
106
- model: options.user?.modelName || "user",
107
- field: "id",
108
- onDelete: "cascade"
109
- },
110
- required: true
111
- },
112
- ...session?.fields
113
- },
114
- order: 1
115
- },
116
- account: {
117
- tableName: options.account?.modelName || "account",
118
- fields: {
119
- [accountFields?.accountId || "accountId"]: {
120
- type: "string",
121
- required: true
122
- },
123
- providerId: {
124
- type: "string",
125
- required: true
126
- },
127
- userId: {
128
- type: "string",
129
- references: {
130
- model: options.user?.modelName || "user",
131
- field: "id",
132
- onDelete: "cascade"
133
- },
134
- required: true
135
- },
136
- accessToken: {
137
- type: "string",
138
- required: false
139
- },
140
- refreshToken: {
141
- type: "string",
142
- required: false
143
- },
144
- idToken: {
145
- type: "string",
146
- required: false
147
- },
148
- expiresAt: {
149
- type: "date",
150
- required: false
151
- },
152
- password: {
153
- type: "string",
154
- required: false
155
- },
156
- ...account?.fields
157
- },
158
- order: 2
159
- },
160
- verification: {
161
- tableName: options.verification?.modelName || "verification",
162
- fields: {
163
- identifier: {
164
- type: "string",
165
- required: true
166
- },
167
- value: {
168
- type: "string",
169
- required: true
170
- },
171
- expiresAt: {
172
- type: "date",
173
- required: true
174
- }
175
- }
176
- },
177
- ...pluginTables,
178
- ...shouldAddRateLimitTable ? rateLimitTable : {}
179
- };
180
- };
181
- createConsola({
182
- formatOptions: {
183
- date: false,
184
- colors: true,
185
- compact: true
186
- },
187
- defaults: {
188
- tag: "Better Auth"
189
- }
190
- });
191
-
192
- // src/utils/misc.ts
193
- function capitalizeFirstLetter(str) {
194
- return str.charAt(0).toUpperCase() + str.slice(1);
195
- }
196
-
197
1
  // src/adapters/prisma-adapter/index.ts
198
2
  function whereConvertor(where) {
199
3
  if (!where) return {};
@@ -279,90 +83,9 @@ var prismaAdapter = (prisma, {
279
83
  const { model, where } = data;
280
84
  const whereClause = whereConvertor(where);
281
85
  return await db[model].delete({ where: whereClause });
282
- },
283
- async createSchema(options, file) {
284
- const tables = getAuthTables(options);
285
- const filePath = file || "./prisma/schema.prisma";
286
- const schemaPrismaExist = existsSync(path.join(process.cwd(), filePath));
287
- let schemaPrisma = "";
288
- if (schemaPrismaExist) {
289
- schemaPrisma = await fs.readFile(
290
- path.join(process.cwd(), filePath),
291
- "utf-8"
292
- );
293
- } else {
294
- schemaPrisma = getNewPrisma(provider);
295
- }
296
- const schema = produceSchema(schemaPrisma, (builder) => {
297
- for (const table in tables) {
298
- let getType2 = function(type, isOptional) {
299
- if (type === "string") {
300
- return isOptional ? "String?" : "String";
301
- }
302
- if (type === "number") {
303
- return isOptional ? "Int?" : "Int";
304
- }
305
- if (type === "boolean") {
306
- return isOptional ? "Boolean?" : "Boolean";
307
- }
308
- if (type === "date") {
309
- return isOptional ? "DateTime?" : "DateTime";
310
- }
311
- };
312
- const fields = tables[table].fields;
313
- const originalTable = tables[table].tableName;
314
- const tableName = capitalizeFirstLetter(originalTable);
315
- const prismaModel = builder.findByType("model", {
316
- name: tableName
317
- });
318
- !prismaModel && builder.model(tableName).field("id", "String").attribute("id");
319
- for (const field in fields) {
320
- const attr = fields[field];
321
- if (prismaModel) {
322
- const isAlreadyExist = builder.findByType("field", {
323
- name: field,
324
- within: prismaModel.properties
325
- });
326
- if (isAlreadyExist) {
327
- continue;
328
- }
329
- }
330
- builder.model(tableName).field(field, getType2(attr.type, !attr.required));
331
- if (attr.unique) {
332
- builder.model(tableName).blockAttribute(`unique([${field}])`);
333
- }
334
- if (attr.references) {
335
- builder.model(tableName).field(
336
- `${attr.references.model.toLowerCase()}s`,
337
- capitalizeFirstLetter(attr.references.model)
338
- ).attribute(
339
- `relation(fields: [${field}], references: [${attr.references.field}], onDelete: Cascade)`
340
- );
341
- }
342
- }
343
- const hasAttribute = builder.findByType("attribute", {
344
- name: "map",
345
- within: prismaModel?.properties
346
- });
347
- if (originalTable !== tableName && !hasAttribute) {
348
- builder.model(tableName).blockAttribute("map", originalTable);
349
- }
350
- }
351
- });
352
- return {
353
- code: schema.trim() === schemaPrisma.trim() ? "" : schema,
354
- fileName: filePath
355
- };
356
86
  }
357
87
  };
358
88
  };
359
- var getNewPrisma = (provider) => `generator client {
360
- provider = "prisma-client-js"
361
- }
362
-
363
- datasource db {
364
- provider = "${provider}"
365
- url = ${provider === "sqlite" ? `"file:./dev.db"` : `env("DATABASE_URL")`}
366
- }`;
367
-
368
- export { prismaAdapter };
89
+ export {
90
+ prismaAdapter
91
+ };
package/dist/api.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { b as AuthEndpoint, d as AuthMiddleware, y as callbackOAuth, X as changePassword, a as createAuthEndpoint, c as createAuthMiddleware, Q as createEmailVerificationToken, a2 as csrfMiddleware, Z as deleteUser, $ as error, M as forgetPassword, N as forgetPasswordCallback, _ as getCSRFToken, u as getEndpoints, z as getSession, C as getSessionFromCtx, E as listSessions, a0 as ok, o as optionsMiddleware, O as resetPassword, J as revokeSession, K as revokeSessions, v as router, T as sendVerificationEmail, D as sessionMiddleware, Y as setPassword, x as signInEmail, w as signInOAuth, L as signOut, a1 as signUpEmail, V as updateUser, U as verifyEmail } from './index-CKn-Zrry.js';
1
+ export { e as AuthEndpoint, f as AuthMiddleware, n as callbackOAuth, L as changePassword, d as createAuthEndpoint, c as createAuthMiddleware, D as createEmailVerificationToken, V as csrfMiddleware, N as deleteUser, Q as error, y as forgetPassword, z as forgetPasswordCallback, O as getCSRFToken, l as getEndpoints, p as getSession, q as getSessionFromCtx, u as listSessions, T as ok, o as optionsMiddleware, C as resetPassword, v as revokeSession, w as revokeSessions, r as router, E as sendVerificationEmail, t as sessionMiddleware, M as setPassword, m as signInEmail, s as signInOAuth, x as signOut, U as signUpEmail, K as updateUser, J as verifyEmail } from './index-C9S3KShG.js';
2
2
  import 'zod';
3
3
  import './helper-DPDj8Nix.js';
4
4
  import 'better-call';