@varaos/db 1.1.18 → 1.1.19

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varaos/db",
3
- "version": "1.1.18",
3
+ "version": "1.1.19",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "files": [
@@ -0,0 +1,37 @@
1
+ /*
2
+ Warnings:
3
+
4
+ - You are about to drop the column `twoFactorSecret` on the `User` table. All the data in the column will be lost.
5
+
6
+ */
7
+ -- CreateEnum
8
+ CREATE TYPE "public"."TwoFactorMethod" AS ENUM ('totp', 'email', 'webauthn');
9
+
10
+ -- AlterTable
11
+ ALTER TABLE "public"."User" DROP COLUMN "twoFactorSecret";
12
+
13
+ -- CreateTable
14
+ CREATE TABLE "public"."UserTwoFactor" (
15
+ "id" TEXT NOT NULL,
16
+ "userId" TEXT NOT NULL,
17
+ "method" "public"."TwoFactorMethod" NOT NULL DEFAULT 'totp',
18
+ "secret" TEXT,
19
+ "enabled" BOOLEAN NOT NULL DEFAULT false,
20
+ "lastVerifiedAt" TIMESTAMP(3),
21
+ "enabledAt" TIMESTAMP(3),
22
+ "recoveryEmailVerifiedAt" TIMESTAMP(3),
23
+ "backupCodes" JSONB,
24
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
25
+ "updatedAt" TIMESTAMP(3) NOT NULL,
26
+
27
+ CONSTRAINT "UserTwoFactor_pkey" PRIMARY KEY ("id")
28
+ );
29
+
30
+ -- CreateIndex
31
+ CREATE UNIQUE INDEX "UserTwoFactor_userId_key" ON "public"."UserTwoFactor"("userId");
32
+
33
+ -- CreateIndex
34
+ CREATE INDEX "UserTwoFactor_userId_idx" ON "public"."UserTwoFactor"("userId");
35
+
36
+ -- AddForeignKey
37
+ ALTER TABLE "public"."UserTwoFactor" ADD CONSTRAINT "UserTwoFactor_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
@@ -76,6 +76,12 @@ enum FileCategory {
76
76
  export
77
77
  }
78
78
 
79
+ enum TwoFactorMethod {
80
+ totp
81
+ email
82
+ webauthn
83
+ }
84
+
79
85
  /// ─────────────────────────────────────────────
80
86
  /// USERS & AUTH
81
87
  /// ─────────────────────────────────────────────
@@ -98,12 +104,14 @@ model User {
98
104
  lastLogin DateTime?
99
105
  lastPasswordChange DateTime?
100
106
  twoFactorEnabled Boolean @default(false)
101
- twoFactorSecret String?
102
- metadata Json?
103
- plan Plan @default(free)
104
- tokenBalance Int @default(0)
105
- creditsUsed Int @default(0)
106
- deletedAt DateTime?
107
+
108
+ userTwoFactor UserTwoFactor?
109
+
110
+ metadata Json?
111
+ plan Plan @default(free)
112
+ tokenBalance Int @default(0)
113
+ creditsUsed Int @default(0)
114
+ deletedAt DateTime?
107
115
 
108
116
  authType AuthType @default(oauth)
109
117
 
@@ -177,12 +185,12 @@ model UserSession {
177
185
  }
178
186
 
179
187
  model UploadIntent {
180
- id String @id
188
+ id String @id
181
189
  userId String
182
190
  category FileCategory
183
191
  size BigInt
184
192
  objectKey String
185
- createdAt DateTime @default(now())
193
+ createdAt DateTime @default(now())
186
194
 
187
195
  @@index([userId])
188
196
  @@index([userId, category])
@@ -200,6 +208,29 @@ model UserEmail {
200
208
  user User @relation(fields: [userId], references: [id], onDelete: Cascade)
201
209
  }
202
210
 
211
+ model UserTwoFactor {
212
+ id String @id @default(uuid())
213
+ userId String @unique
214
+
215
+ method TwoFactorMethod @default(totp)
216
+ secret String? // null when disabled or method != totp
217
+ enabled Boolean @default(false)
218
+
219
+ lastVerifiedAt DateTime?
220
+ enabledAt DateTime?
221
+
222
+ recoveryEmailVerifiedAt DateTime?
223
+
224
+ backupCodes Json? // [{ hash, used, usedAt }]
225
+
226
+ createdAt DateTime @default(now())
227
+ updatedAt DateTime @updatedAt
228
+
229
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
230
+
231
+ @@index([userId])
232
+ }
233
+
203
234
  model Account {
204
235
  id String @id @default(uuid())
205
236
  userId String