@nathapp/nestjs-prisma 3.3.0 → 4.0.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 (43) hide show
  1. package/package.json +10 -7
  2. package/.eslintrc.js +0 -8
  3. package/.turbo/turbo-build.log +0 -4
  4. package/CHANGELOG.md +0 -279
  5. package/docs/20260215-fix-plan-prisma.md +0 -37
  6. package/docs/20260215-review-prisma.md +0 -598
  7. package/docs/20260216-plan-prisma-a-minus.md +0 -70
  8. package/lib/errors/prisma-error.mapper.ts +0 -164
  9. package/lib/filter/prisma-exception.filter.ts +0 -67
  10. package/lib/index.ts +0 -12
  11. package/lib/pagination/index.ts +0 -1
  12. package/lib/pagination/paginate.ts +0 -44
  13. package/lib/prisma.constants.ts +0 -40
  14. package/lib/prisma.decorator.ts +0 -8
  15. package/lib/prisma.health.ts +0 -40
  16. package/lib/prisma.interfaces.ts +0 -51
  17. package/lib/prisma.module.ts +0 -281
  18. package/lib/prisma.service.ts +0 -179
  19. package/lib/repository/abstract-prisma.repository.ts +0 -138
  20. package/lib/repository/index.ts +0 -1
  21. package/lib/testing/index.ts +0 -1
  22. package/lib/testing/prisma-testing.utils.ts +0 -29
  23. package/lib/transaction/index.ts +0 -2
  24. package/lib/transaction/prisma-transaction-manager.ts +0 -77
  25. package/lib/transaction/prisma-transaction.constants.ts +0 -29
  26. package/test/error-mapping.spec.ts +0 -231
  27. package/test/jest-nax.json +0 -27
  28. package/test/jest-test.json +0 -29
  29. package/test/lifecycle.spec.ts +0 -241
  30. package/test/multi-db-als.spec.ts +0 -142
  31. package/test/multi-db-transaction.spec.ts +0 -75
  32. package/test/pagination/paginate.spec.ts +0 -359
  33. package/test/prisma-exception-filter.spec.ts +0 -213
  34. package/test/prisma-transaction-manager.spec.ts +0 -285
  35. package/test/prisma.decorator.spec.ts +0 -257
  36. package/test/prisma.health.spec.ts +0 -226
  37. package/test/prisma.module.spec.ts +0 -506
  38. package/test/prisma.service.spec.ts +0 -359
  39. package/test/repository/abstract-prisma.repository.spec.ts +0 -157
  40. package/test/transaction-manager-e2e.spec.ts +0 -496
  41. package/test/transaction.spec.ts +0 -371
  42. package/test/transparent-transaction.spec.ts +0 -500
  43. package/tsconfig.json +0 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nathapp/nestjs-prisma",
3
- "version": "3.3.0",
3
+ "version": "4.0.1",
4
4
  "description": "NestJS Prisma integration with multi-database support",
5
5
  "scripts": {
6
6
  "clean": "rimraf dist/ .turbo/",
@@ -13,23 +13,26 @@
13
13
  },
14
14
  "author": "William Khoo",
15
15
  "license": "ISC",
16
+ "engines": {
17
+ "node": "^20.19.0 || >=22.12.0"
18
+ },
16
19
  "types": "dist/index.d.ts",
17
20
  "main": "dist/index.js",
18
21
  "dependencies": {
19
- "@nathapp/nestjs-common": "^3.3.0",
20
- "@nathapp/nestjs-data": "^3.3.0"
22
+ "@nathapp/nestjs-common": "^4.0.1",
23
+ "@nathapp/nestjs-data": "^4.0.1"
21
24
  },
22
25
  "devDependencies": {
23
26
  "@nathapp/eslint-config": "1.0.1",
24
27
  "@nathapp/typescript-config": "1.0.1",
25
- "@golevelup/ts-jest": "^0.6.1",
28
+ "@golevelup/ts-jest": "^3.0.0",
26
29
  "eslint": "^8.57.0",
27
30
  "typescript": "^5"
28
31
  },
29
32
  "peerDependencies": {
30
- "@nathapp/nestjs-common": "^3.0.0",
31
- "@nestjs/common": "^10.0.0 || ^11.0.0",
32
- "@nestjs/core": "^10.0.0 || ^11.0.0",
33
+ "@nathapp/nestjs-common": "^4.0.0-rc.0",
34
+ "@nestjs/common": "^10.0.0 || ^11.0.0 || ^12.0.0",
35
+ "@nestjs/core": "^10.0.0 || ^11.0.0 || ^12.0.0",
33
36
  "@prisma/client": "^6.0.0"
34
37
  }
35
38
  }
package/.eslintrc.js DELETED
@@ -1,8 +0,0 @@
1
- module.exports = {
2
- root: true,
3
- extends: ["@nathapp/eslint-config/library.js"],
4
- parser: "@typescript-eslint/parser",
5
- parserOptions: {
6
- project: true,
7
- },
8
- };
@@ -1,4 +0,0 @@
1
-
2
- > @nathapp/nestjs-prisma@3.3.0 build
3
- > rimraf dist && tsc -p tsconfig.json
4
-
package/CHANGELOG.md DELETED
@@ -1,279 +0,0 @@
1
- # @nathapp/nestjs-prisma
2
-
3
- ## 3.3.0
4
-
5
- ### Patch Changes
6
-
7
- - @nathapp/nestjs-common@3.3.0
8
- - @nathapp/nestjs-data@3.3.0
9
-
10
- ## 3.2.2
11
-
12
- ### Patch Changes
13
-
14
- - 73d5885: Comprehensive code review of the entire NestJS monorepo covering security, memory leaks, performance, and correctness bugs. All CRITICAL/HIGH/MEDIUM findings fixed; only LOW findings remain.
15
-
16
- ### Security Fixes
17
-
18
- - **nestjs-typeorm**: `DatabaseErrorMapper` now strips raw DB error details (`originalError`, `dbCode`, `dbErrno`) from `AppException.args` — these are logged server-side instead of exposed in HTTP responses
19
- - **nestjs-notification**: `EmailProvider` now extracts `err.message` instead of `JSON.stringify(err)` (which always returned `"{}"` for Error objects)
20
- - **nestjs-common**: `createAsyncOptionsProvider` throws on invalid async options instead of silently returning a broken provider
21
- - **nestjs-queue**: RabbitMQ provider logs and re-queues sanitized error messages (strips raw stack traces from DLQ metadata)
22
- - **nestjs-storage**: OSS callback validates pub-key URL prefix before fetching (prevents SSRF)
23
-
24
- ### Memory Leak Fixes
25
-
26
- - **nestjs-notification**: `UserTokenStore.addToken()` was pushing to a local array copy without calling `cache.set()` — tokens were lost immediately after being added
27
- - **nestjs-cache**: Validated config warning uses NestJS `Logger` (not `console.warn`) for consistent log routing
28
- - **nestjs-common**: `RequestIpSecurity` uses NestJS `Logger` instead of `console.warn`
29
- - **nestjs-queue**: BullMQ/Kafka/RabbitMQ providers properly clean up workers, event listeners, and queues in `close()`
30
-
31
- ### Bug Fixes
32
-
33
- - **nestjs-queue**: Restored BullMQ branch in idempotency provider switch (was accidentally removed)
34
- - **nestjs-queue**: RabbitMQ `resume()` remains warn-only — does not throw (interface contract)
35
- - **nestjs-auth**: JWT refresh strategy passes `undefined` (not `{}`) as req when `passReqToCallback=false`
36
- - **nestjs-microservices**: `canActivateGrpc` now calls `strategyProvider.validate()` and sets `request.user = principal` (not raw JWT payload)
37
- - **nestjs-storage**: OSS callback signature verification stays on RSA-MD5 (Alibaba OSS protocol mandates MD5)
38
-
39
- ### Code Quality
40
-
41
- - **nestjs-common**: `sanitizeHeader` strips non-word characters (spaces become empty) — documented in tests
42
- - **nestjs-common**: `isValidLocaleCode` enforces strict `xx_XX` format (bare `en` is invalid)
43
- - **nestjs-queue**: TypeScript union casts use `as unknown as T` pattern to avoid overlap errors
44
-
45
- - Updated dependencies [73d5885]
46
- - @nathapp/nestjs-common@3.2.3
47
-
48
- ## 3.2.1
49
-
50
- ### Patch Changes
51
-
52
- - 0610b83: Fix Exception Bug on nestjs-common
53
- - Updated dependencies [0610b83]
54
- - @nathapp/nestjs-common@3.2.1
55
- - @nathapp/nestjs-data@3.2.1
56
-
57
- ## 3.2.0
58
-
59
- ### Minor Changes
60
-
61
- - 1876b9a: ### nestjs-auth
62
-
63
- - Add JWKS support via `JwksJwtStrategyProvider` and `createJwksStrategyProvider` factory — enables remote key resolution through `jwks-rsa` (optional peer dep)
64
- - Add `validateJwksOptions` security guard and `JwksOptions` interface
65
- - Export `JwksJwtStrategyProvider` and `JwksOptions` from the public API
66
- - Fix permission guard and JWT module immutability issues from code review
67
-
68
- ### nestjs-typeorm
69
-
70
- - Add `AbstractTypeOrmRepository<TDomain, TEntity, TId>` — portable `IRepository` implementation decoupled from TypeORM internals
71
- - Add `TYPEORM_TRANSACTION_ALS` DI token and publish it from `forRoot`/`forRootAsync`
72
- - `forCustomRepository` now instantiates `AbstractTypeOrmRepository` subclasses with the correct per-DataSource tx manager token
73
- - Add `getTypeOrmTransactionManagerToken(name?)` helper for multi-DataSource wiring
74
- - Named DataSource tx tokens no longer collide; default DataSource still aliases the global `TRANSACTION_MANAGER` symbol
75
-
76
- ### nestjs-prisma
77
-
78
- - Add `getPrismaTransactionManagerToken(name?)` helper for multi-DataSource wiring
79
- - `forRoot` / `forRootAsync` register named tx manager token + default-only guard to prevent collision
80
-
81
- ### nestjs-data
82
-
83
- - Add `IRepository<TDomain, TId>` portable repository contract
84
- - Fix missing `@nathapp/nestjs-common` peer dep for turborepo build resolution
85
-
86
- ### nestjs-common
87
-
88
- - Add `request-ip` utility for extracting client IP across Express and Fastify adapters
89
-
90
- ### nestjs-cache
91
-
92
- - Fix cache interceptor, cache manager, and cache tag registry immutability and type issues
93
-
94
- ### nestjs-app
95
-
96
- - Fix `nathapp.ts` and `app-factory.ts` code review findings (immutability, error handling)
97
-
98
- ### nestjs-queue
99
-
100
- - Upgrade `uuid` dependency from `^9.0.0` to `^11.1.1` (security)
101
- - Fix BullMQ health check to use `IRedisClient.info()` (aligned with BullMQ interface)
102
-
103
- ### nestjs-notification
104
-
105
- - Upgrade `nodemailer` dev dep from `^7` to `^8` — resolves SMTP command injection CVEs (GHSA-c7w3-x93f-qmm8, GHSA-vvjj-xcjg-gr5g)
106
-
107
- ### nestjs-storage
108
-
109
- - Fix code review findings (immutability, validation)
110
-
111
- ### nestjs-throttler
112
-
113
- - Fix code review findings
114
-
115
- ### All packages
116
-
117
- - Upgrade AJV to v8 (removes root override that broke `@fastify/ajv-compiler`)
118
- - Align all package versions to 3.1.3 as baseline for this minor release
119
-
120
- ### Patch Changes
121
-
122
- - Updated dependencies [1876b9a]
123
- - @nathapp/nestjs-common@3.2.0
124
- - @nathapp/nestjs-data@3.2.0
125
-
126
- ## 3.1.3
127
-
128
- ### Patch Changes
129
-
130
- - a48beb2: transaction manager symbol bug fix
131
- - Updated dependencies [a48beb2]
132
- - @nathapp/nestjs-data@3.0.4
133
-
134
- ## 3.1.2
135
-
136
- ### Patch Changes
137
-
138
- - cb97b64: fix typeorm and transactionManager issue
139
- - Updated dependencies [cb97b64]
140
- - @nathapp/nestjs-data@3.0.3
141
-
142
- ## 3.1.1
143
-
144
- ### Patch Changes
145
-
146
- - a448f5b: add irepository and abstract repository
147
- - Updated dependencies [a448f5b]
148
- - @nathapp/nestjs-data@3.0.2
149
-
150
- ## 3.1.0
151
-
152
- ### Minor Changes
153
-
154
- - feat: add transparent transaction support via `transaction: true` option
155
-
156
- **nestjs-prisma:**
157
-
158
- - `PrismaModule.forRoot({ transaction: true })` wraps the injected client in a transparent proxy
159
- - Repos automatically use the transaction client inside `txManager.run()` — no code changes needed
160
- - Provides `TRANSACTION_MANAGER` token from `@nathapp/nestjs-data`
161
- - `PrismaTransactionManager` accepts optional shared AsyncLocalStorage for proxy integration
162
-
163
- **nestjs-typeorm:**
164
-
165
- - `TypeOrmExModule.forRoot({ transaction: true })` provides `TRANSACTION_MANAGER` token
166
- - TypeORM repos use explicit injection pattern (`@Optional() @Inject(TRANSACTION_MANAGER)`)
167
- - Transparent proxy not feasible for TypeORM (repos hold manager references at creation time)
168
- - `TypeOrmTransactionManager` accepts optional shared AsyncLocalStorage
169
-
170
- ## 3.0.1
171
-
172
- ### Patch Changes
173
-
174
- - Add ITransactionManager interface and ORM-specific implementations
175
-
176
- - **nestjs-data**: New package with `ITransactionManager` interface and `TRANSACTION_MANAGER` DI token for ORM-agnostic transaction management via AsyncLocalStorage
177
- - **nestjs-prisma**: Add `PrismaTransactionManager` implementing `ITransactionManager` with Prisma interactive transactions
178
- - **nestjs-typeorm**: Add `TypeOrmTransactionManager` implementing `ITransactionManager` with TypeORM QueryRunner transactions
179
-
180
- - Updated dependencies
181
- - @nathapp/nestjs-data@3.0.1
182
-
183
- ## 3.0.0
184
-
185
- ### Major Changes
186
-
187
- - 86a36b8: # 🚀 v3.0.0 Monorepo Enterprise Upgrade
188
-
189
- This release brings significant security hardening, strict typing, improved observability, and comprehensive documentation across the entire Nathapp NestJS ecosystem.
190
-
191
- ## ⚠️ Breaking Changes
192
-
193
- ### nestjs-common
194
-
195
- - **Trust Proxy (Fail-Closed)**: Trust proxy is now disabled by default. Production deployments behind a reverse proxy MUST configure `trustedProxies` or use a preset (`cloudflare`, `aws-alb`, `nginx-local`, etc.). See `docs/trust-proxy-security.md`.
196
- - **SerializableInterceptor**: Now uses pure transformation — original response objects are no longer mutated. Primitives in arrays are preserved correctly.
197
- - **AppException**: Now generic `AppException<T>` for strict argument typing.
198
-
199
- ### nestjs-logging
200
-
201
- - **Redaction**: Default redact paths are now constrained to 3 levels deep (`*.*.key`).
202
- - **Structured Logs**: Standardized field names for ELK/Loki/Datadog compatibility.
203
- - **Graceful Drain**: Logger now implements `OnModuleDestroy` to flush pending writes on shutdown.
204
-
205
- ### nestjs-typeorm
206
-
207
- - **Connection Validation**: `TypeOrmExModule.forRoot()` now throws `"Connection Not Supported"` when no valid connection type is provided (previously defaulted silently to MySQL).
208
-
209
- ## 🔒 Security
210
-
211
- - **nestjs-common**: Trust proxy fail-closed default prevents IP spoofing when misconfigured. Comprehensive security documentation with provider presets.
212
- - **nestjs-storage**: GDrive refreshToken security best practices documented. Provider capability matrix added.
213
- - **nestjs-throttler**: Documented that `getTracker()` executes synchronously — no async TOCTOU race condition in rate limiting.
214
- - **nestjs-typeorm**: Stored procedure name validation with whitelist pattern (`/^[a-zA-Z_][a-zA-Z0-9_.]*$/`) prevents SQL injection.
215
- - **nestjs-cache**: Tag registry now receives TTL for proper expiration of tag-to-key mappings.
216
- - **nestjs-microservices**: Fixed gRPC Bearer token extraction whitespace bug. Full test coverage for all guards.
217
- - **nestjs-auth-2fa**: Timing-safe TOTP verification prevents timing attacks.
218
-
219
- ## ✨ Features & Improvements
220
-
221
- - **nestjs-storage**: Added native support for **Azure Blob Storage** and **Google Cloud Storage**. Provider capability matrix documents supported methods per provider.
222
- - **nestjs-microservices**: Full guard coverage (100%), Service Identity JWT + HMAC authentication, `ServicePermissionRegistry` for fine-grained access control.
223
- - **nestjs-typeorm**: Automatic mapping of database errors to `AppException` via `TypeOrmExceptionFilter`.
224
- - **nestjs-auth-2fa**: `BaseTwoFactorGuard` with flexible policy engine. DI-aware provider factory with comprehensive architectural documentation.
225
- - **nestjs-cache**: Deep-cloning of cached objects to prevent cross-request state leakage. Touch fallback avoided for distributed strategies (race condition prevention).
226
- - **nestjs-queue**: Race-condition fixes in BullMQ/RabbitMQ batch accumulators.
227
- - **nestjs-prisma**: `PrismaExceptionFilter` and transaction helper. Parallel query execution validated.
228
- - **nestjs-auth**: Comprehensive JSDoc on all public APIs. All TODO comments resolved.
229
- - **nestjs-common**: `ConfigurableModuleBuilder` with `externallyConfigured()` support.
230
- - **Global**: 2,500+ tests across all 13 packages. Comprehensive JSDoc for all public APIs.
231
-
232
- ## 📚 Documentation
233
-
234
- - `nestjs-common/docs/trust-proxy-security.md` — IP spoofing risks, preset configurations, verification steps
235
- - `nestjs-storage/docs/gdrive-security.md` — refreshToken security best practices
236
- - `nestjs-storage/docs/provider-capabilities.md` — method support matrix per provider
237
- - All packages: JSDoc on public APIs, MIGRATION.md guides where applicable
238
-
239
- ### Patch Changes
240
-
241
- - Updated dependencies [86a36b8]
242
- - @nathapp/nestjs-common@3.0.0
243
-
244
- ## 3.0.0-rc.0
245
-
246
- ### Major Changes
247
-
248
- - # 🚀 v3.0.0-rc Monorepo Enterprise Upgrade
249
-
250
- This release brings significant security, reliability, and observability improvements across the entire Nathapp ecosystem.
251
-
252
- ## ⚠️ [BREAKING CHANGES]
253
-
254
- ### nestjs-common
255
-
256
- - **Trust Proxy (Fail-Closed)**: Trust proxy is now disabled by default. Production deployments MUST configure `trustedProxies` or use a preset (`cloudflare`, `aws-alb`, etc.).
257
- - **SerializableInterceptor**: Now uses pure transformation. Original response objects are no longer mutated.
258
- - **AppException**: Now generic `AppException<T>` for strict argument typing.
259
-
260
- ### nestjs-logging
261
-
262
- - **Redaction**: Default redact paths are now constrained to 3 levels deep (`*.*.key`).
263
- - **Structured Logs**: Standardized field names for ELK/Loki/Datadog compatibility.
264
-
265
- ## ✨ Features & Improvements
266
-
267
- - **nestjs-storage**: Added native support for **Azure Blob Storage** and **Google Cloud Storage**.
268
- - **nestjs-microservices**: Full guard coverage and secured gRPC Bearer token extraction.
269
- - **nestjs-typeorm**: Automatic mapping of database errors to `AppException`.
270
- - **nestjs-auth-2fa**: Timing-safe TOTP verification and flexible policy engine.
271
- - **nestjs-cache**: Deep-cloning of cached objects to prevent cross-request state leakage.
272
- - **nestjs-queue**: Race-condition fixes in BullMQ/RabbitMQ batch accumulators.
273
- - **nestjs-throttler**: Added async trust proxy support.
274
- - **Global**: Comprehensive JSDoc for all public APIs across all packages.
275
-
276
- ### Patch Changes
277
-
278
- - Updated dependencies
279
- - @nathapp/nestjs-common@3.0.0-rc.0
@@ -1,37 +0,0 @@
1
- # Fix Plan: @nathapp/nestjs-prisma Enterprise Upgrade
2
- **Date:** 2026-02-15
3
- **Branch:** feat/monorepo-enterprise-upgrade
4
-
5
- ## Phase 1: Error Handling & Security
6
- ### Fix P1: Prisma Error -> AppException Mapping
7
- **Files:**
8
- - `packages/nestjs-prisma/lib/errors/prisma-error.mapper.ts` (New)
9
- - `packages/nestjs-prisma/lib/filter/prisma-exception.filter.ts` (New)
10
- **Impact:** Standardizes error reporting for Prisma-based services.
11
- **Change:** Implement a mapper for Prisma Client Known Request Errors (P2002, P2025, etc.) and a global filter.
12
-
13
- ## Phase 2: Lifecycle & Reliability
14
- ### Fix P2: Event Listener Memory Leak
15
- **File:** `packages/nestjs-prisma/lib/prisma.service.ts`
16
- **Impact:** Prevents memory leaks during hot-reloads or module destruction.
17
- **Change:** Ensure `$on('query', ...)` listeners are properly cleaned up in `onModuleDestroy()`.
18
-
19
- ## Phase 3: Transaction Support
20
- ### Fix P3: Transaction Helper Utility
21
- **File:** `packages/nestjs-prisma/lib/prisma.service.ts`
22
- **Impact:** Simplifies transactional logic for consumers.
23
- **Change:** Add a `withTransaction()` helper that wraps the native `$transaction` API with standard error mapping.
24
-
25
- ## Test Strategy
26
- - Mode: two-session-tdd
27
- - TDD targets:
28
- - `packages/nestjs-prisma/test/error-mapping.spec.ts` (Prisma error codes to AppException)
29
- - `packages/nestjs-prisma/test/lifecycle.spec.ts` (Listener cleanup verification)
30
- - `packages/nestjs-prisma/test/transaction.spec.ts` (Transaction success/rollback)
31
- - Test-after targets:
32
- - `packages/nestjs-prisma/test/prisma.service.spec.ts` (Regression check)
33
-
34
- ## Commits
35
- - `feat(nestjs-prisma): implement PrismaExceptionFilter for AppException consistency`
36
- - `fix(nestjs-prisma): resolve memory leak in query event listeners`
37
- - `feat(nestjs-prisma): add withTransaction helper with standard error mapping`