@nathapp/nestjs-iam-prisma 1.3.1 → 1.3.2

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/README.md CHANGED
@@ -137,6 +137,73 @@ JWT-sized IdP token failed on MySQL. Upgrade a MySQL database built from an
137
137
  earlier fragment with `prisma/sql/long-text-columns.mysql.sql`. PostgreSQL needs
138
138
  nothing: `String` is already `text` there.
139
139
 
140
+ ### Login history status type
141
+
142
+ `LoginHistory.status` is an `Int`, not a `String`: the domain type is the numeric
143
+ `LoginStatus` enum (`1` success, `2` failed, `3` MFA required, `4` locked,
144
+ `5` expired password), every login path supplies a number, and the adapter has
145
+ always read the column back with `Number(...)`. A `String` column rejected every
146
+ write, and `recordLoginHistory` swallowed the error, so `login_histories` stayed
147
+ empty with only an error log line.
148
+
149
+ `Int` is Prisma's portable integer scalar — `integer` on PostgreSQL, `INT` on
150
+ MySQL. It carries no native annotation, so the assembly step that rewrites
151
+ `@db.Timestamptz(6)` for MySQL leaves it untouched. There is no provider-specific
152
+ SQL file for this change: the fragment is the single source of truth, and the
153
+ DDL comes from your own migration tool.
154
+
155
+ For an existing database, run this preflight **before** changing the schema,
156
+ with a client generated from the current fragment. It is provider-neutral
157
+ because it goes through the Prisma client rather than a dialect's regex
158
+ operator:
159
+
160
+ ```ts
161
+ const rows = await prisma.loginHistory.findMany({ select: { id: true, status: true } });
162
+ const offenders = rows.filter((row) => !/^\d+$/.test(String(row.status).trim()));
163
+ ```
164
+
165
+ If `offenders` is non-empty, map or remove those rows first; the integer
166
+ conversion fails on any value that is not an integer literal, so the migration
167
+ aborts rather than coercing it to `0`. The table is normally empty: the shipped
168
+ fragment never allowed a successful write, so rows can only come from a
169
+ consumer's own code.
170
+
171
+ Then update the fragment in your schema, generate the migration with your tool
172
+ (`prisma migrate dev --create-only` for Prisma Migrate) and **review the
173
+ generated file** before applying it. Do not apply the raw derived script on
174
+ PostgreSQL: `prisma migrate diff` renders this change as
175
+
176
+ ```sql
177
+ ALTER TABLE "login_histories" DROP COLUMN "status", ADD COLUMN "status" INTEGER NOT NULL;
178
+ ```
179
+
180
+ which discards every existing row. Replace it with an in-place type change that
181
+ casts:
182
+
183
+ ```sql
184
+ -- PostgreSQL: preserves existing values
185
+ ALTER TABLE "login_histories" ALTER COLUMN "status" TYPE integer USING "status"::integer;
186
+
187
+ -- MySQL: the derived statement is already in place
188
+ ALTER TABLE `login_histories` MODIFY `status` INT NOT NULL;
189
+ ```
190
+
191
+ On Prisma 7 the derivation command is `prisma migrate diff --from-schema
192
+ <old>.prisma --to-schema <new>.prisma --script`; the older
193
+ `--from-schema-datamodel` / `--to-schema-datamodel` flags were removed. Apply the
194
+ column change, regenerate every consumer client, and deploy the adapter as one
195
+ coordinated cutover — an old client (`status` typed as `String`) and a new client
196
+ (`status` typed as `Int`) are not interchangeable against the same column. The
197
+ `db-e2e` suite converts a legacy `VARCHAR` column in place and asserts the
198
+ existing row survives as a number on both providers.
199
+
200
+ `identifier` is bounded, not migrated. `recordLoginHistory` truncates it to
201
+ `LoginSecurityConfig.maxIdentifierLength` code points (default `191`, the
202
+ capacity a bare `String` column has on MySQL) before writing, so an over-long
203
+ value still produces an audit row instead of failing the insert. Raise the limit
204
+ if your column is wider. The truncation is logged at `debug`: the failed-login
205
+ caller supplies that value, so a higher level would let a client flood the log.
206
+
140
207
  ### API-key scopes
141
208
 
142
209
  The shipped `ApiKey` fragment stores `scopes` as `Json @default("[]")`. The
@@ -1 +1 @@
1
- {"version":3,"file":"prisma-login-history.repository.js","sourceRoot":"","sources":["../lib/prisma-login-history.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,0DAAkE;AAClE,sDAAgF;AAMzE,IAAM,4BAA4B,GAAlC,MAAM,4BACX,SAAQ,wCAA+D;IAGvE,YAAyC,EAAuB,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAEtE,aAAa,CAAC,MAAwB,IAAI,O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AC,aAAa,EAAE,CAAC;SACzE,CAAC;IACJ,CAAC;IAGS,mBAAmB,CAAC,EAAyB;QACrD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,MAAc,EAAE,KAAc;QAC/C,MAAM,KAAK,GAAG,IAAI,CAAC,KAA4C,CAAC;QAChE,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;QACtI,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC;CACF,CAAA;AA7CY,oEAA4B;uCAA5B,4BAA4B;IADxC,IAAA,mBAAU,GAAE;IAKE,WAAA,IAAA,eAAM,EAAC,iCAAmB,CAAC,CAAA;;GAJ7B,4BAA4B,CA6CxC"}
@@ -35,7 +35,7 @@ export interface LoginHistoryRow {
35
35
  userAgent: string | null;
36
36
  userAgentId: string | null;
37
37
  method: string;
38
- status: string;
38
+ status: number;
39
39
  failureReason: string | null;
40
40
  createdAt: Date;
41
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nathapp/nestjs-iam-prisma",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Prisma adapter for @nathapp/nestjs-iam",
5
5
  "scripts": {
6
6
  "build": "rimraf dist && tsc -p tsconfig.json",
@@ -26,11 +26,11 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@nathapp/nestjs-data": "^3.3.0 || ^4.0.3",
29
- "@nathapp/nestjs-iam": "1.3.1"
29
+ "@nathapp/nestjs-iam": "1.3.2"
30
30
  },
31
31
  "devDependencies": {
32
- "@nathapp/nestjs-oauth": "1.3.1",
33
- "@nathapp/nestjs-oauth-prisma": "1.3.1",
32
+ "@nathapp/nestjs-oauth": "1.3.2",
33
+ "@nathapp/nestjs-oauth-prisma": "1.3.2",
34
34
  "@nathapp/nestjs-prisma": "^4.1.0",
35
35
  "@prisma/adapter-mariadb": "7.10.1",
36
36
  "@prisma/adapter-pg": "7.10.1",
package/prisma/iam.prisma CHANGED
@@ -67,7 +67,7 @@ model LoginHistory {
67
67
  userAgent String? @db.Text @map("user_agent")
68
68
  userAgentId String? @map("user_agent_id")
69
69
  method String
70
- status String
70
+ status Int
71
71
  failureReason String? @map("failure_reason")
72
72
  createdAt DateTime @db.Timestamptz(6) @default(now()) @map("created_at")
73
73