@vite-hub/auth 0.1.0 → 0.3.1

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 (89) hide show
  1. package/README.md +333 -49
  2. package/dist/abilities-DfAnFYwG.d.ts +93 -0
  3. package/dist/abilities.d.ts +2 -0
  4. package/dist/abilities.js +43 -0
  5. package/dist/ability-error-CqgBrBfR.js +91 -0
  6. package/dist/ability-error-DcgChwCN.d.ts +34 -0
  7. package/dist/admin-claim-code-CDipqeAU.js +22 -0
  8. package/dist/agent.d.ts +5 -5
  9. package/dist/agent.js +17 -9
  10. package/dist/application-path-DuTpfGFj.js +62 -0
  11. package/dist/auth-instance-CR6b1W80.js +1168 -0
  12. package/dist/bun-sqlite.d.ts +8 -0
  13. package/dist/cli-ubYJpAL_.d.ts +163 -0
  14. package/dist/cli.d.ts +1 -1
  15. package/dist/cli.js +47 -7
  16. package/dist/console-runtime-DTopBP-x.d.ts +71 -0
  17. package/dist/console-runtime-J9_Vx9pT.js +1166 -0
  18. package/dist/console-runtime.d.ts +3 -3
  19. package/dist/console-runtime.js +2 -819
  20. package/dist/console.d.ts +215 -3
  21. package/dist/console.js +1 -1
  22. package/dist/database-options-BRNef9oy.js +29 -0
  23. package/dist/database-schema-options-ENuRMduM.js +12 -0
  24. package/dist/database.d.ts +12 -0
  25. package/dist/database.js +45 -0
  26. package/dist/definition-CqQMcDEK.js +280 -0
  27. package/dist/error-diagnostics-C8XtVz0i.js +138 -0
  28. package/dist/{events-P7mI4IQb.js → events-ByzenEVj.js} +122 -4
  29. package/dist/forward.d.ts +50 -0
  30. package/dist/forward.js +120 -0
  31. package/dist/host-declarations.d.ts +2 -1
  32. package/dist/index.d.ts +24 -3
  33. package/dist/index.js +3 -102
  34. package/dist/internal/server.d.ts +5 -0
  35. package/dist/internal/server.js +858 -0
  36. package/dist/invariant-D8_xBqmZ.js +22 -0
  37. package/dist/mcp.d.ts +187 -0
  38. package/dist/mcp.js +353 -0
  39. package/dist/members-D9lfaEO_.js +533 -0
  40. package/dist/nuxt-bridge-Cl988STZ.js +44 -0
  41. package/dist/nuxt.d.ts +13 -5
  42. package/dist/nuxt.js +90 -13
  43. package/dist/object-Da1zyPCR.js +11 -0
  44. package/dist/page-tools-shared-l4eyj53D.js +19 -0
  45. package/dist/presets.js +1 -1
  46. package/dist/request-z6DHHmrb.js +47 -0
  47. package/dist/runtime/console.d.ts +3 -7
  48. package/dist/runtime/console.js +4 -42
  49. package/dist/runtime/empty-abilities.d.ts +5 -0
  50. package/dist/runtime/empty-abilities.js +4 -0
  51. package/dist/runtime/empty-client.d.ts +6 -0
  52. package/dist/runtime/empty-client.js +5 -0
  53. package/dist/runtime/empty-definition.d.ts +1 -1
  54. package/dist/runtime/nuxt.js +1 -1
  55. package/dist/runtime/server.d.ts +2 -0
  56. package/dist/runtime/server.js +77 -0
  57. package/dist/runtime/vue-nuxt.d.ts +3 -2
  58. package/dist/runtime/vue-nuxt.js +157 -5
  59. package/dist/runtime-state-ojQCzKOc.js +25 -0
  60. package/dist/schema.d.ts +137 -0
  61. package/dist/schema.js +147 -0
  62. package/dist/server-C0qnKN2W.d.ts +143 -0
  63. package/dist/server-bQGzVQ--.d.ts +41 -0
  64. package/dist/server.d.ts +3 -2
  65. package/dist/server.js +3 -3
  66. package/dist/session-cookies-BbH3UR2m.js +227 -0
  67. package/dist/{set-cookie-2as_DbHe.js → set-cookie-C8NOhdRE.js} +27 -12
  68. package/dist/{shared-DnpgYiLF.js → shared-BwcdRGxD.js} +2 -5
  69. package/dist/table-specs-8gq_FCaq.js +771 -0
  70. package/dist/table-specs-DbXyaXWs.d.ts +842 -0
  71. package/dist/test.d.ts +26 -0
  72. package/dist/test.js +25 -0
  73. package/dist/{events-BkmK2dFY.d.ts → types-CNaeH2Fd.d.ts} +240 -157
  74. package/dist/vite-CV400XXY.js +1556 -0
  75. package/dist/vite.d.ts +138 -20
  76. package/dist/vite.js +2 -2
  77. package/dist/vue.d.ts +330 -21
  78. package/dist/vue.js +583 -36
  79. package/package.json +84 -15
  80. package/dist/application-path-C290OAIs.js +0 -18
  81. package/dist/cli-mgXvsBtA.d.ts +0 -85
  82. package/dist/console-B7eERmGv.d.ts +0 -180
  83. package/dist/console-runtime-bZQtnX2Y.d.ts +0 -39
  84. package/dist/error-diagnostics-CL0yjHiM.js +0 -79
  85. package/dist/events-config-CjcFOhTE.js +0 -177
  86. package/dist/inspect-DPtsW8dB.d.ts +0 -36
  87. package/dist/server-B7LU19dS.js +0 -1730
  88. package/dist/server-CTD_JAww.d.ts +0 -77
  89. package/dist/vite-COWkwxsj.js +0 -990
@@ -0,0 +1,771 @@
1
+ import { t as authErrorDiagnostics } from "./error-diagnostics-C8XtVz0i.js";
2
+ //#region src/table-specs.ts
3
+ const requiredString = {
4
+ type: "string",
5
+ required: true
6
+ };
7
+ const optionalString = { type: "string" };
8
+ const optionalDate = { type: "date" };
9
+ const optionalBoolean = { type: "boolean" };
10
+ const userReference = {
11
+ model: "user",
12
+ field: "id",
13
+ onDelete: "cascade"
14
+ };
15
+ /**
16
+ * The Better Auth core tables, with the fields of the plugins that ViteHub ships: `admin()` (`user.role`, bans, and
17
+ * `session.impersonatedBy`), the `jwt()` and `oauthProvider()` tables of `mcpOAuth()`, the tables of
18
+ * `organization()` and of `passkey()` from `@better-auth/passkey`, and the table of Better Auth's limiter. A test checks this
19
+ * list against Better Auth's own `getAuthTables()`, so a Better Auth upgrade that changes a table fails it.
20
+ */
21
+ const authTableSpecs = {
22
+ user: { fields: {
23
+ name: {
24
+ type: "string",
25
+ required: true
26
+ },
27
+ email: {
28
+ type: "string",
29
+ required: true,
30
+ unique: true
31
+ },
32
+ emailVerified: {
33
+ type: "boolean",
34
+ required: true,
35
+ defaultValue: false
36
+ },
37
+ image: { type: "string" },
38
+ createdAt: {
39
+ type: "date",
40
+ required: true,
41
+ defaultValue: "now"
42
+ },
43
+ updatedAt: {
44
+ type: "date",
45
+ required: true,
46
+ defaultValue: "now",
47
+ onUpdate: true
48
+ },
49
+ role: { type: "string" },
50
+ banned: {
51
+ type: "boolean",
52
+ defaultValue: false
53
+ },
54
+ banReason: { type: "string" },
55
+ banExpires: { type: "date" }
56
+ } },
57
+ session: { fields: {
58
+ expiresAt: {
59
+ type: "date",
60
+ required: true
61
+ },
62
+ token: {
63
+ type: "string",
64
+ required: true,
65
+ unique: true
66
+ },
67
+ createdAt: {
68
+ type: "date",
69
+ required: true,
70
+ defaultValue: "now"
71
+ },
72
+ updatedAt: {
73
+ type: "date",
74
+ required: true,
75
+ onUpdate: true
76
+ },
77
+ ipAddress: { type: "string" },
78
+ userAgent: { type: "string" },
79
+ userId: {
80
+ type: "string",
81
+ required: true,
82
+ index: true,
83
+ references: {
84
+ model: "user",
85
+ field: "id",
86
+ onDelete: "cascade"
87
+ }
88
+ },
89
+ impersonatedBy: { type: "string" },
90
+ activeOrganizationId: { type: "string" }
91
+ } },
92
+ account: { fields: {
93
+ accountId: {
94
+ type: "string",
95
+ required: true
96
+ },
97
+ providerId: {
98
+ type: "string",
99
+ required: true
100
+ },
101
+ userId: {
102
+ type: "string",
103
+ required: true,
104
+ index: true,
105
+ references: {
106
+ model: "user",
107
+ field: "id",
108
+ onDelete: "cascade"
109
+ }
110
+ },
111
+ accessToken: { type: "string" },
112
+ refreshToken: { type: "string" },
113
+ idToken: { type: "string" },
114
+ accessTokenExpiresAt: { type: "date" },
115
+ refreshTokenExpiresAt: { type: "date" },
116
+ scope: { type: "string" },
117
+ password: { type: "string" },
118
+ createdAt: {
119
+ type: "date",
120
+ required: true,
121
+ defaultValue: "now"
122
+ },
123
+ updatedAt: {
124
+ type: "date",
125
+ required: true,
126
+ onUpdate: true
127
+ }
128
+ } },
129
+ verification: { fields: {
130
+ identifier: {
131
+ type: "string",
132
+ required: true,
133
+ index: true
134
+ },
135
+ value: {
136
+ type: "string",
137
+ required: true
138
+ },
139
+ expiresAt: {
140
+ type: "date",
141
+ required: true
142
+ },
143
+ createdAt: {
144
+ type: "date",
145
+ required: true,
146
+ defaultValue: "now"
147
+ },
148
+ updatedAt: {
149
+ type: "date",
150
+ required: true,
151
+ defaultValue: "now",
152
+ onUpdate: true
153
+ }
154
+ } },
155
+ jwks: { fields: {
156
+ publicKey: {
157
+ type: "string",
158
+ required: true
159
+ },
160
+ privateKey: {
161
+ type: "string",
162
+ required: true
163
+ },
164
+ createdAt: {
165
+ type: "date",
166
+ required: true
167
+ },
168
+ expiresAt: { type: "date" },
169
+ alg: { type: "string" },
170
+ crv: { type: "string" }
171
+ } },
172
+ oauthClient: { fields: {
173
+ clientId: {
174
+ type: "string",
175
+ required: true,
176
+ unique: true
177
+ },
178
+ clientSecret: { type: "string" },
179
+ clientDiscoveryId: { type: "string" },
180
+ disabled: {
181
+ type: "boolean",
182
+ defaultValue: false
183
+ },
184
+ skipConsent: { type: "boolean" },
185
+ enableEndSession: { type: "boolean" },
186
+ subjectType: { type: "string" },
187
+ scopes: { type: "string[]" },
188
+ clientCredentialsScopes: {
189
+ type: "string[]",
190
+ defaultValue: []
191
+ },
192
+ userId: {
193
+ type: "string",
194
+ index: true,
195
+ references: {
196
+ model: "user",
197
+ field: "id",
198
+ onDelete: "cascade"
199
+ }
200
+ },
201
+ createdAt: { type: "date" },
202
+ updatedAt: { type: "date" },
203
+ name: { type: "string" },
204
+ uri: { type: "string" },
205
+ icon: { type: "string" },
206
+ contacts: { type: "string[]" },
207
+ tos: { type: "string" },
208
+ policy: { type: "string" },
209
+ softwareId: { type: "string" },
210
+ softwareVersion: { type: "string" },
211
+ softwareStatement: { type: "string" },
212
+ redirectUris: {
213
+ type: "string[]",
214
+ required: true
215
+ },
216
+ postLogoutRedirectUris: { type: "string[]" },
217
+ backchannelLogoutUri: { type: "string" },
218
+ backchannelLogoutSessionRequired: { type: "boolean" },
219
+ tokenEndpointAuthMethod: { type: "string" },
220
+ applicationType: { type: "string" },
221
+ jwks: { type: "string" },
222
+ jwksUri: { type: "string" },
223
+ grantTypes: { type: "string[]" },
224
+ responseTypes: { type: "string[]" },
225
+ requirePKCE: { type: "boolean" },
226
+ dpopBoundAccessTokens: {
227
+ type: "boolean",
228
+ defaultValue: false
229
+ },
230
+ referenceId: { type: "string" },
231
+ metadata: { type: "json" }
232
+ } },
233
+ oauthResource: { fields: {
234
+ identifier: {
235
+ type: "string",
236
+ required: true,
237
+ unique: true
238
+ },
239
+ name: {
240
+ type: "string",
241
+ required: true
242
+ },
243
+ accessTokenTtl: { type: "number" },
244
+ refreshTokenTtl: { type: "number" },
245
+ signingAlgorithm: { type: "string" },
246
+ signingKeyId: { type: "string" },
247
+ allowedScopes: { type: "string[]" },
248
+ customClaims: { type: "json" },
249
+ dpopBoundAccessTokensRequired: {
250
+ type: "boolean",
251
+ defaultValue: false
252
+ },
253
+ disabled: {
254
+ type: "boolean",
255
+ defaultValue: false
256
+ },
257
+ createdAt: { type: "date" },
258
+ updatedAt: { type: "date" },
259
+ policyVersion: {
260
+ type: "number",
261
+ defaultValue: 1
262
+ },
263
+ metadata: { type: "json" }
264
+ } },
265
+ oauthClientResource: {
266
+ fields: {
267
+ clientId: {
268
+ type: "string",
269
+ required: true,
270
+ index: true,
271
+ references: {
272
+ model: "oauthClient",
273
+ field: "clientId",
274
+ onDelete: "cascade"
275
+ }
276
+ },
277
+ resourceId: {
278
+ type: "string",
279
+ required: true,
280
+ index: true,
281
+ references: {
282
+ model: "oauthResource",
283
+ field: "identifier",
284
+ onDelete: "cascade"
285
+ }
286
+ },
287
+ metadata: { type: "json" },
288
+ createdAt: { type: "date" }
289
+ },
290
+ unique: [["clientId", "resourceId"]]
291
+ },
292
+ oauthRefreshToken: { fields: {
293
+ token: {
294
+ type: "string",
295
+ required: true,
296
+ unique: true
297
+ },
298
+ clientId: {
299
+ type: "string",
300
+ required: true,
301
+ index: true,
302
+ references: {
303
+ model: "oauthClient",
304
+ field: "clientId",
305
+ onDelete: "cascade"
306
+ }
307
+ },
308
+ sessionId: {
309
+ type: "string",
310
+ index: true,
311
+ references: {
312
+ model: "session",
313
+ field: "id",
314
+ onDelete: "set null"
315
+ }
316
+ },
317
+ userId: {
318
+ type: "string",
319
+ required: true,
320
+ index: true,
321
+ references: {
322
+ model: "user",
323
+ field: "id",
324
+ onDelete: "cascade"
325
+ }
326
+ },
327
+ referenceId: { type: "string" },
328
+ authorizationCodeId: {
329
+ type: "string",
330
+ index: true
331
+ },
332
+ resources: { type: "string[]" },
333
+ requestedUserInfoClaims: { type: "string[]" },
334
+ expiresAt: { type: "date" },
335
+ createdAt: { type: "date" },
336
+ revoked: { type: "date" },
337
+ rotatedAt: { type: "date" },
338
+ rotationReplayResponse: { type: "string" },
339
+ rotationReplayExpiresAt: { type: "date" },
340
+ authTime: { type: "date" },
341
+ confirmation: { type: "json" },
342
+ scopes: {
343
+ type: "string[]",
344
+ required: true
345
+ }
346
+ } },
347
+ oauthAccessToken: { fields: {
348
+ token: {
349
+ type: "string",
350
+ unique: true
351
+ },
352
+ clientId: {
353
+ type: "string",
354
+ required: true,
355
+ index: true,
356
+ references: {
357
+ model: "oauthClient",
358
+ field: "clientId",
359
+ onDelete: "cascade"
360
+ }
361
+ },
362
+ sessionId: {
363
+ type: "string",
364
+ index: true,
365
+ references: {
366
+ model: "session",
367
+ field: "id",
368
+ onDelete: "set null"
369
+ }
370
+ },
371
+ userId: {
372
+ type: "string",
373
+ index: true,
374
+ references: {
375
+ model: "user",
376
+ field: "id",
377
+ onDelete: "cascade"
378
+ }
379
+ },
380
+ referenceId: { type: "string" },
381
+ authorizationCodeId: {
382
+ type: "string",
383
+ index: true
384
+ },
385
+ resources: { type: "string[]" },
386
+ requestedUserInfoClaims: { type: "string[]" },
387
+ refreshId: {
388
+ type: "string",
389
+ index: true,
390
+ references: {
391
+ model: "oauthRefreshToken",
392
+ field: "id",
393
+ onDelete: "cascade"
394
+ }
395
+ },
396
+ expiresAt: { type: "date" },
397
+ createdAt: { type: "date" },
398
+ revoked: { type: "date" },
399
+ confirmation: { type: "json" },
400
+ scopes: {
401
+ type: "string[]",
402
+ required: true
403
+ }
404
+ } },
405
+ oauthConsent: { fields: {
406
+ clientId: {
407
+ type: "string",
408
+ required: true,
409
+ index: true,
410
+ references: {
411
+ model: "oauthClient",
412
+ field: "clientId",
413
+ onDelete: "cascade"
414
+ }
415
+ },
416
+ userId: {
417
+ type: "string",
418
+ index: true,
419
+ references: {
420
+ model: "user",
421
+ field: "id",
422
+ onDelete: "cascade"
423
+ }
424
+ },
425
+ referenceId: { type: "string" },
426
+ resources: { type: "string[]" },
427
+ requestedUserInfoClaims: { type: "string[]" },
428
+ scopes: {
429
+ type: "string[]",
430
+ required: true
431
+ },
432
+ createdAt: { type: "date" },
433
+ updatedAt: { type: "date" }
434
+ } },
435
+ oauthClientAssertion: { fields: { expiresAt: {
436
+ type: "date",
437
+ required: true
438
+ } } },
439
+ rateLimit: { fields: {
440
+ key: {
441
+ type: "string",
442
+ required: true,
443
+ unique: true
444
+ },
445
+ count: {
446
+ type: "number",
447
+ required: true
448
+ },
449
+ lastRequest: {
450
+ type: "number",
451
+ bigint: true,
452
+ required: true,
453
+ defaultValue: "now"
454
+ }
455
+ } },
456
+ organization: { fields: {
457
+ name: {
458
+ type: "string",
459
+ required: true
460
+ },
461
+ slug: {
462
+ type: "string",
463
+ required: true,
464
+ unique: true,
465
+ index: true
466
+ },
467
+ logo: { type: "string" },
468
+ createdAt: {
469
+ type: "date",
470
+ required: true
471
+ },
472
+ metadata: { type: "string" }
473
+ } },
474
+ member: { fields: {
475
+ organizationId: {
476
+ type: "string",
477
+ required: true,
478
+ index: true,
479
+ references: {
480
+ model: "organization",
481
+ field: "id",
482
+ onDelete: "cascade"
483
+ }
484
+ },
485
+ userId: {
486
+ type: "string",
487
+ required: true,
488
+ index: true,
489
+ references: {
490
+ model: "user",
491
+ field: "id",
492
+ onDelete: "cascade"
493
+ }
494
+ },
495
+ role: {
496
+ type: "string",
497
+ required: true,
498
+ defaultValue: "member"
499
+ },
500
+ createdAt: {
501
+ type: "date",
502
+ required: true
503
+ }
504
+ } },
505
+ invitation: { fields: {
506
+ organizationId: {
507
+ type: "string",
508
+ required: true,
509
+ index: true,
510
+ references: {
511
+ model: "organization",
512
+ field: "id",
513
+ onDelete: "cascade"
514
+ }
515
+ },
516
+ email: {
517
+ type: "string",
518
+ required: true,
519
+ index: true
520
+ },
521
+ role: { type: "string" },
522
+ status: {
523
+ type: "string",
524
+ required: true,
525
+ defaultValue: "pending"
526
+ },
527
+ expiresAt: {
528
+ type: "date",
529
+ required: true
530
+ },
531
+ createdAt: {
532
+ type: "date",
533
+ required: true,
534
+ defaultValue: "now"
535
+ },
536
+ inviterId: {
537
+ type: "string",
538
+ required: true,
539
+ references: {
540
+ model: "user",
541
+ field: "id",
542
+ onDelete: "cascade"
543
+ }
544
+ }
545
+ } },
546
+ passkey: { fields: {
547
+ name: { type: "string" },
548
+ publicKey: {
549
+ type: "string",
550
+ required: true
551
+ },
552
+ userId: {
553
+ type: "string",
554
+ required: true,
555
+ index: true,
556
+ references: {
557
+ model: "user",
558
+ field: "id",
559
+ onDelete: "cascade"
560
+ }
561
+ },
562
+ credentialID: {
563
+ type: "string",
564
+ required: true,
565
+ index: true
566
+ },
567
+ counter: {
568
+ type: "number",
569
+ required: true,
570
+ bigint: true
571
+ },
572
+ deviceType: {
573
+ type: "string",
574
+ required: true
575
+ },
576
+ backedUp: {
577
+ type: "boolean",
578
+ required: true
579
+ },
580
+ transports: { type: "string" },
581
+ createdAt: { type: "date" },
582
+ aaguid: { type: "string" }
583
+ } }
584
+ };
585
+ /**
586
+ * The tables and columns of each plugin of `AuthSchemaPlugin`, with all of its options on: a column or table that the
587
+ * options turn off stays empty. A test checks the plugins of `better-auth/plugins` against Better Auth's own
588
+ * `getAuthTables()`. `apiKey()` and `stripe()` are copied from `@better-auth/api-key` and `@better-auth/stripe` 1.7.
589
+ */
590
+ const authPluginSchemas = {
591
+ anonymous: { fields: { user: { isAnonymous: {
592
+ type: "boolean",
593
+ defaultValue: false
594
+ } } } },
595
+ apiKey: { tables: { apikey: { fields: {
596
+ configId: {
597
+ type: "string",
598
+ required: true,
599
+ index: true,
600
+ defaultValue: "default"
601
+ },
602
+ name: optionalString,
603
+ start: optionalString,
604
+ referenceId: {
605
+ type: "string",
606
+ required: true,
607
+ index: true
608
+ },
609
+ prefix: optionalString,
610
+ key: {
611
+ type: "string",
612
+ required: true,
613
+ index: true
614
+ },
615
+ refillInterval: {
616
+ type: "number",
617
+ bigint: true
618
+ },
619
+ refillAmount: { type: "number" },
620
+ lastRefillAt: optionalDate,
621
+ enabled: {
622
+ type: "boolean",
623
+ defaultValue: true
624
+ },
625
+ rateLimitEnabled: {
626
+ type: "boolean",
627
+ defaultValue: true
628
+ },
629
+ rateLimitTimeWindow: {
630
+ type: "number",
631
+ bigint: true,
632
+ defaultValue: 864e5
633
+ },
634
+ rateLimitMax: {
635
+ type: "number",
636
+ defaultValue: 10
637
+ },
638
+ requestCount: {
639
+ type: "number",
640
+ defaultValue: 0
641
+ },
642
+ remaining: { type: "number" },
643
+ lastRequest: optionalDate,
644
+ expiresAt: optionalDate,
645
+ createdAt: {
646
+ type: "date",
647
+ required: true
648
+ },
649
+ updatedAt: {
650
+ type: "date",
651
+ required: true
652
+ },
653
+ permissions: optionalString,
654
+ metadata: optionalString
655
+ } } } },
656
+ lastLoginMethod: { fields: { user: { lastLoginMethod: optionalString } } },
657
+ phoneNumber: { fields: { user: {
658
+ phoneNumber: {
659
+ type: "string",
660
+ unique: true
661
+ },
662
+ phoneNumberVerified: optionalBoolean
663
+ } } },
664
+ stripe: {
665
+ fields: {
666
+ user: { stripeCustomerId: optionalString },
667
+ organization: { stripeCustomerId: optionalString }
668
+ },
669
+ tables: { subscription: { fields: {
670
+ plan: requiredString,
671
+ referenceId: requiredString,
672
+ stripeCustomerId: optionalString,
673
+ stripeSubscriptionId: optionalString,
674
+ status: {
675
+ type: "string",
676
+ defaultValue: "incomplete"
677
+ },
678
+ periodStart: optionalDate,
679
+ periodEnd: optionalDate,
680
+ trialStart: optionalDate,
681
+ trialEnd: optionalDate,
682
+ cancelAtPeriodEnd: {
683
+ type: "boolean",
684
+ defaultValue: false
685
+ },
686
+ cancelAt: optionalDate,
687
+ canceledAt: optionalDate,
688
+ endedAt: optionalDate,
689
+ seats: { type: "number" },
690
+ billingInterval: optionalString,
691
+ stripeScheduleId: optionalString
692
+ } } }
693
+ },
694
+ twoFactor: {
695
+ fields: { user: { twoFactorEnabled: {
696
+ type: "boolean",
697
+ defaultValue: false
698
+ } } },
699
+ tables: { twoFactor: { fields: {
700
+ secret: {
701
+ type: "string",
702
+ required: true,
703
+ index: true
704
+ },
705
+ backupCodes: requiredString,
706
+ userId: {
707
+ type: "string",
708
+ required: true,
709
+ index: true,
710
+ references: userReference
711
+ },
712
+ verified: {
713
+ type: "boolean",
714
+ defaultValue: true
715
+ },
716
+ failedVerificationCount: {
717
+ type: "number",
718
+ defaultValue: 0
719
+ },
720
+ lockedUntil: optionalDate
721
+ } } }
722
+ },
723
+ username: { fields: { user: {
724
+ username: {
725
+ type: "string",
726
+ unique: true
727
+ },
728
+ displayUsername: optionalString
729
+ } } }
730
+ };
731
+ function sameField(left, right) {
732
+ return left.type === right.type && Boolean(left.required) === Boolean(right.required);
733
+ }
734
+ /**
735
+ * The table specs for `options`: `authTableSpecs`, the tables and columns of each plugin, then the additional fields.
736
+ * A field that a table has already must have the same type and `required`.
737
+ */
738
+ function resolveAuthTableSpecs(options = {}) {
739
+ const specs = { ...authTableSpecs };
740
+ const addFields = (model, fields, source) => {
741
+ const spec = specs[model];
742
+ if (!spec) throw authSchemaError(`${source} adds fields to the ${JSON.stringify(model)} table, which Auth does not create`);
743
+ const merged = { ...spec.fields };
744
+ for (const [key, field] of Object.entries(fields)) {
745
+ const existing = merged[key];
746
+ if (existing && !sameField(existing, field)) throw authSchemaError(`${source} declares ${model}.${key} as ${field.type}${field.required ? ", required" : ""}, but the column is ${existing.type}${existing.required ? ", required" : ""}`);
747
+ merged[key] ??= field;
748
+ }
749
+ specs[model] = {
750
+ ...spec,
751
+ fields: merged
752
+ };
753
+ };
754
+ for (const plugin of [...new Set(options.plugins ?? [])].sort()) {
755
+ const schema = authPluginSchemas[plugin];
756
+ Object.assign(specs, schema.tables);
757
+ for (const [model, fields] of Object.entries(schema.fields ?? {})) addFields(model, fields, `${plugin}()`);
758
+ }
759
+ for (const [model, fields] of Object.entries(options.additionalFields ?? {})) addFields(model, fields, `${model}.additionalFields`);
760
+ for (const [model, spec] of Object.entries(specs)) for (const [key, field] of Object.entries(spec.fields)) if (field.references && !specs[field.references.model]) throw authSchemaError(`${model}.${key} references the ${JSON.stringify(field.references.model)} table, which Auth does not create`);
761
+ return specs;
762
+ }
763
+ function authSchemaError(detail) {
764
+ return authErrorDiagnostics.AUTH_C0056({ message: `\`authDatabase()\` cannot build its tables: ${detail}.` });
765
+ }
766
+ /** `emailVerified` becomes `email_verified` and `oauthClient` becomes `oauth_client`, as the Better Auth CLI writes them. */
767
+ function authSqlName(name) {
768
+ return name.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").replace(/([a-z\d])([A-Z])/g, "$1_$2").toLowerCase();
769
+ }
770
+ //#endregion
771
+ export { resolveAuthTableSpecs as i, authSqlName as n, authTableSpecs as r, authPluginSchemas as t };