@nathapp/nestjs-prisma 3.2.0 → 3.2.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +47 -0
- package/dist/errors/prisma-error.mapper.d.ts +1 -0
- package/dist/errors/prisma-error.mapper.js +12 -3
- package/dist/errors/prisma-error.mapper.js.map +1 -1
- package/dist/filter/prisma-exception.filter.d.ts +1 -0
- package/dist/filter/prisma-exception.filter.js +9 -4
- package/dist/filter/prisma-exception.filter.js.map +1 -1
- package/dist/prisma.interfaces.d.ts +1 -0
- package/dist/prisma.module.d.ts +0 -1
- package/dist/prisma.module.js +6 -5
- package/dist/prisma.module.js.map +1 -1
- package/dist/prisma.service.js +2 -1
- package/dist/prisma.service.js.map +1 -1
- package/lib/errors/prisma-error.mapper.ts +29 -5
- package/lib/filter/prisma-exception.filter.ts +9 -4
- package/lib/prisma.interfaces.ts +1 -0
- package/lib/prisma.module.ts +11 -12
- package/lib/prisma.service.ts +3 -2
- package/package.json +3 -3
- package/test/error-mapping.spec.ts +45 -6
- package/test/prisma-exception-filter.spec.ts +5 -5
- package/test/prisma.module.spec.ts +23 -1
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,52 @@
|
|
|
1
1
|
# @nathapp/nestjs-prisma
|
|
2
2
|
|
|
3
|
+
## 3.2.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 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.
|
|
8
|
+
|
|
9
|
+
### Security Fixes
|
|
10
|
+
|
|
11
|
+
- **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
|
|
12
|
+
- **nestjs-notification**: `EmailProvider` now extracts `err.message` instead of `JSON.stringify(err)` (which always returned `"{}"` for Error objects)
|
|
13
|
+
- **nestjs-common**: `createAsyncOptionsProvider` throws on invalid async options instead of silently returning a broken provider
|
|
14
|
+
- **nestjs-queue**: RabbitMQ provider logs and re-queues sanitized error messages (strips raw stack traces from DLQ metadata)
|
|
15
|
+
- **nestjs-storage**: OSS callback validates pub-key URL prefix before fetching (prevents SSRF)
|
|
16
|
+
|
|
17
|
+
### Memory Leak Fixes
|
|
18
|
+
|
|
19
|
+
- **nestjs-notification**: `UserTokenStore.addToken()` was pushing to a local array copy without calling `cache.set()` — tokens were lost immediately after being added
|
|
20
|
+
- **nestjs-cache**: Validated config warning uses NestJS `Logger` (not `console.warn`) for consistent log routing
|
|
21
|
+
- **nestjs-common**: `RequestIpSecurity` uses NestJS `Logger` instead of `console.warn`
|
|
22
|
+
- **nestjs-queue**: BullMQ/Kafka/RabbitMQ providers properly clean up workers, event listeners, and queues in `close()`
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
- **nestjs-queue**: Restored BullMQ branch in idempotency provider switch (was accidentally removed)
|
|
27
|
+
- **nestjs-queue**: RabbitMQ `resume()` remains warn-only — does not throw (interface contract)
|
|
28
|
+
- **nestjs-auth**: JWT refresh strategy passes `undefined` (not `{}`) as req when `passReqToCallback=false`
|
|
29
|
+
- **nestjs-microservices**: `canActivateGrpc` now calls `strategyProvider.validate()` and sets `request.user = principal` (not raw JWT payload)
|
|
30
|
+
- **nestjs-storage**: OSS callback signature verification stays on RSA-MD5 (Alibaba OSS protocol mandates MD5)
|
|
31
|
+
|
|
32
|
+
### Code Quality
|
|
33
|
+
|
|
34
|
+
- **nestjs-common**: `sanitizeHeader` strips non-word characters (spaces become empty) — documented in tests
|
|
35
|
+
- **nestjs-common**: `isValidLocaleCode` enforces strict `xx_XX` format (bare `en` is invalid)
|
|
36
|
+
- **nestjs-queue**: TypeScript union casts use `as unknown as T` pattern to avoid overlap errors
|
|
37
|
+
|
|
38
|
+
- Updated dependencies [73d5885]
|
|
39
|
+
- @nathapp/nestjs-common@3.2.3
|
|
40
|
+
|
|
41
|
+
## 3.2.1
|
|
42
|
+
|
|
43
|
+
### Patch Changes
|
|
44
|
+
|
|
45
|
+
- 0610b83: Fix Exception Bug on nestjs-common
|
|
46
|
+
- Updated dependencies [0610b83]
|
|
47
|
+
- @nathapp/nestjs-common@3.2.1
|
|
48
|
+
- @nathapp/nestjs-data@3.2.1
|
|
49
|
+
|
|
3
50
|
## 3.2.0
|
|
4
51
|
|
|
5
52
|
### Minor Changes
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PrismaErrorMapper = exports.PrismaAppException = exports.PRISMA_ERROR_CODES = void 0;
|
|
4
4
|
const nestjs_common_1 = require("@nathapp/nestjs-common");
|
|
5
5
|
const library_1 = require("@prisma/client/runtime/library");
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
6
7
|
exports.PRISMA_ERROR_CODES = {
|
|
7
8
|
VALUE_TOO_LONG: 'VALUE_TOO_LONG',
|
|
8
9
|
RECORD_NOT_FOUND: 'RECORD_NOT_FOUND',
|
|
@@ -25,6 +26,7 @@ class PrismaAppException extends nestjs_common_1.AppException {
|
|
|
25
26
|
exports.PrismaAppException = PrismaAppException;
|
|
26
27
|
class PrismaErrorMapper {
|
|
27
28
|
static map(error) {
|
|
29
|
+
var _a;
|
|
28
30
|
if (!error) {
|
|
29
31
|
return new PrismaAppException(9999, exports.PRISMA_ERROR_CODES.UNKNOWN_ERROR, { message: 'An unknown error occurred' }, 500);
|
|
30
32
|
}
|
|
@@ -33,14 +35,21 @@ class PrismaErrorMapper {
|
|
|
33
35
|
if (isPrismaError) {
|
|
34
36
|
const errorConfig = this.ERROR_MAP[error.code];
|
|
35
37
|
if (errorConfig) {
|
|
36
|
-
|
|
38
|
+
const safeArgs = error.code === 'P2002' && ((_a = error.meta) === null || _a === void 0 ? void 0 : _a.target)
|
|
39
|
+
? { target: error.meta.target }
|
|
40
|
+
: {};
|
|
41
|
+
this.logger.error(`Prisma error ${error.code}: ${error.message}`, { meta: error.meta, clientVersion: error.clientVersion });
|
|
42
|
+
return new PrismaAppException(errorConfig.numericCode, errorConfig.stringCode, safeArgs, errorConfig.httpStatus);
|
|
37
43
|
}
|
|
38
|
-
|
|
44
|
+
this.logger.error(`Unknown Prisma error ${error.code}: ${error.message}`, { meta: error.meta });
|
|
45
|
+
return new PrismaAppException(9998, exports.PRISMA_ERROR_CODES.DATABASE_ERROR, {}, 500);
|
|
39
46
|
}
|
|
40
|
-
|
|
47
|
+
this.logger.error('Unexpected database error', { message: error.message || String(error) });
|
|
48
|
+
return new PrismaAppException(9999, exports.PRISMA_ERROR_CODES.UNKNOWN_ERROR, {}, 500);
|
|
41
49
|
}
|
|
42
50
|
}
|
|
43
51
|
exports.PrismaErrorMapper = PrismaErrorMapper;
|
|
52
|
+
PrismaErrorMapper.logger = new common_1.Logger(PrismaErrorMapper.name);
|
|
44
53
|
PrismaErrorMapper.ERROR_MAP = {
|
|
45
54
|
P1008: { httpStatus: 503, numericCode: 1008, stringCode: exports.PRISMA_ERROR_CODES.CONNECTION_TIMEOUT },
|
|
46
55
|
P2000: { httpStatus: 400, numericCode: 2000, stringCode: exports.PRISMA_ERROR_CODES.VALUE_TOO_LONG },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prisma-error.mapper.js","sourceRoot":"","sources":["../../lib/errors/prisma-error.mapper.ts"],"names":[],"mappings":";;;AAAA,0DAAsD;AACtD,4DAA+E;
|
|
1
|
+
{"version":3,"file":"prisma-error.mapper.js","sourceRoot":"","sources":["../../lib/errors/prisma-error.mapper.ts"],"names":[],"mappings":";;;AAAA,0DAAsD;AACtD,4DAA+E;AAC/E,2CAAwC;AAe3B,QAAA,kBAAkB,GAAG;IAChC,cAAc,EAAE,gBAAgB;IAChC,gBAAgB,EAAE,kBAAkB;IACpC,eAAe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cAAc,EAAE;IAG5F,KAAK,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,0BAAkB,CAAC,gBAAgB,EAAE;IAG9F,KAAK,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,0BAAkB,CAAC,eAAe,EAAE;IAG7F,KAAK,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,0BAAkB,CAAC,iBAAiB,EAAE;IAG/F,KAAK,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,0BAAkB,CAAC,kBAAkB,EAAE;IAGhG,KAAK,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,0BAAkB,CAAC,gBAAgB,EAAE;CAC/F,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
|
|
2
2
|
import { PrismaClientKnownRequestError, PrismaClientValidationError } from '@prisma/client/runtime/library';
|
|
3
3
|
export declare class PrismaExceptionFilter implements ExceptionFilter {
|
|
4
|
+
private readonly logger;
|
|
4
5
|
catch(exception: PrismaClientKnownRequestError | PrismaClientValidationError, host: ArgumentsHost): void;
|
|
5
6
|
}
|
|
@@ -5,22 +5,27 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
+
var PrismaExceptionFilter_1;
|
|
8
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
10
|
exports.PrismaExceptionFilter = void 0;
|
|
10
11
|
const common_1 = require("@nestjs/common");
|
|
11
12
|
const library_1 = require("@prisma/client/runtime/library");
|
|
12
13
|
const prisma_error_mapper_1 = require("../errors/prisma-error.mapper");
|
|
13
|
-
let PrismaExceptionFilter = class PrismaExceptionFilter {
|
|
14
|
+
let PrismaExceptionFilter = PrismaExceptionFilter_1 = class PrismaExceptionFilter {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.logger = new common_1.Logger(PrismaExceptionFilter_1.name);
|
|
17
|
+
}
|
|
14
18
|
catch(exception, host) {
|
|
15
19
|
const ctx = host.switchToHttp();
|
|
16
20
|
const response = ctx.getResponse();
|
|
17
21
|
if (exception instanceof library_1.PrismaClientValidationError) {
|
|
22
|
+
this.logger.error('PrismaClientValidationError', { message: exception.message });
|
|
18
23
|
response.status(400).json({
|
|
19
24
|
success: false,
|
|
20
25
|
error: {
|
|
21
26
|
code: prisma_error_mapper_1.PRISMA_ERROR_CODES.DATABASE_ERROR,
|
|
22
27
|
message: 'Invalid query parameters',
|
|
23
|
-
args: {
|
|
28
|
+
args: {},
|
|
24
29
|
},
|
|
25
30
|
});
|
|
26
31
|
return;
|
|
@@ -30,14 +35,14 @@ let PrismaExceptionFilter = class PrismaExceptionFilter {
|
|
|
30
35
|
success: false,
|
|
31
36
|
error: {
|
|
32
37
|
code: appException.code,
|
|
33
|
-
message:
|
|
38
|
+
message: 'A database error occurred',
|
|
34
39
|
args: appException.args,
|
|
35
40
|
},
|
|
36
41
|
});
|
|
37
42
|
}
|
|
38
43
|
};
|
|
39
44
|
exports.PrismaExceptionFilter = PrismaExceptionFilter;
|
|
40
|
-
exports.PrismaExceptionFilter = PrismaExceptionFilter = __decorate([
|
|
45
|
+
exports.PrismaExceptionFilter = PrismaExceptionFilter = PrismaExceptionFilter_1 = __decorate([
|
|
41
46
|
(0, common_1.Catch)(library_1.PrismaClientKnownRequestError, library_1.PrismaClientValidationError)
|
|
42
47
|
], PrismaExceptionFilter);
|
|
43
48
|
//# sourceMappingURL=prisma-exception.filter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prisma-exception.filter.js","sourceRoot":"","sources":["../../lib/filter/prisma-exception.filter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prisma-exception.filter.js","sourceRoot":"","sources":["../../lib/filter/prisma-exception.filter.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAA+E;AAC/E,4DAGwC;AACxC,uEAAsF;AAyB/E,IAAM,qBAAqB,6BAA3B,MAAM,qBAAqB;IAA3B;QACY,WAAM,GAAG,IAAI,eAAM,CAAC,uBAAqB,CAAC,IAAI,CAAC,CAAC;IAmCnE,CAAC;IAjCC,KAAK,CAAC,SAAsE,EAAE,IAAmB;QAC/F,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QAGnC,IAAI,SAAS,YAAY,qCAA2B,EAAE,CAAC;YAErD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6B,EAAE,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;YACjF,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACxB,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE;oBACL,IAAI,EAAE,wCAAkB,CAAC,cAAc;oBACvC,OAAO,EAAE,0BAA0B;oBACnC,IAAI,EAAE,EAAE;iBACT;aACF,CAAC,CAAC;YACH,OAAO;QACT,CAAC;QAID,MAAM,YAAY,GAAG,uCAAiB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAGtD,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,UAAU,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;YACnD,OAAO,EAAE,KAAK;YACd,KAAK,EAAE;gBACL,IAAI,EAAE,YAAY,CAAC,IAAI;gBACvB,OAAO,EAAE,2BAA2B;gBACpC,IAAI,EAAE,YAAY,CAAC,IAAI;aACxB;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AApCY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,cAAK,EAAC,uCAA6B,EAAE,qCAA2B,CAAC;GACrD,qBAAqB,CAoCjC"}
|
|
@@ -3,6 +3,7 @@ export interface PrismaClientLike {
|
|
|
3
3
|
$connect(): Promise<void>;
|
|
4
4
|
$disconnect(): Promise<void>;
|
|
5
5
|
$on?(event: string, listener: (...args: any[]) => void): void;
|
|
6
|
+
$off?(event: string, listener: (...args: any[]) => void): void;
|
|
6
7
|
}
|
|
7
8
|
export interface PrismaModuleOptions {
|
|
8
9
|
name?: string;
|
package/dist/prisma.module.d.ts
CHANGED
package/dist/prisma.module.js
CHANGED
|
@@ -121,8 +121,12 @@ let PrismaModule = PrismaModule_1 = class PrismaModule {
|
|
|
121
121
|
const alsToken = (0, prisma_transaction_constants_1.getPrismaTransactionAlsToken)(name);
|
|
122
122
|
providers.push({
|
|
123
123
|
provide: alsToken,
|
|
124
|
-
inject: [connectionToken],
|
|
125
|
-
useFactory: () =>
|
|
124
|
+
inject: [connectionToken, prisma_constants_1.PRISMA_MODULE_OPTIONS],
|
|
125
|
+
useFactory: (_service, opts) => {
|
|
126
|
+
if (!opts.transaction)
|
|
127
|
+
return undefined;
|
|
128
|
+
return ctx.als;
|
|
129
|
+
},
|
|
126
130
|
});
|
|
127
131
|
const namedTxToken = (0, prisma_constants_1.getPrismaTransactionManagerToken)(name);
|
|
128
132
|
const isDefaultConnection = !name || name === 'default';
|
|
@@ -227,9 +231,6 @@ let PrismaModule = PrismaModule_1 = class PrismaModule {
|
|
|
227
231
|
}
|
|
228
232
|
throw new Error('Invalid PrismaModuleAsyncOptions: must provide useFactory, useClass, or useExisting');
|
|
229
233
|
}
|
|
230
|
-
static createAsyncProviders(options, connectionToken) {
|
|
231
|
-
return this.createAsyncProvidersWithCtx(options, connectionToken, {});
|
|
232
|
-
}
|
|
233
234
|
};
|
|
234
235
|
exports.PrismaModule = PrismaModule;
|
|
235
236
|
exports.PrismaModule = PrismaModule = PrismaModule_1 = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prisma.module.js","sourceRoot":"","sources":["../lib/prisma.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAiE;AACjE,6CAAgD;AAChD,sDAA2D;AAE3D,qDAAiD;AACjD,yFAAoF;AACpF,yDAA6G;AAC7G,
|
|
1
|
+
{"version":3,"file":"prisma.module.js","sourceRoot":"","sources":["../lib/prisma.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAiE;AACjE,6CAAgD;AAChD,sDAA2D;AAE3D,qDAAiD;AACjD,yFAAoF;AACpF,yDAA6G;AAC7G,6FAA0F;AAE1F,SAAS,gCAAgC,CAAC,IAAa;IACrD,MAAM,cAAc,GAAG,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,SAAS,CAAC;IACzC,MAAM,OAAO,GACX,8CAA8C,cAAc,qBAAqB;UAC/E,mGAAmG,CAAC;IAExG,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,qDAAwB,CAAC,SAAS,CAAC,EAAE;QACtE,KAAK,CAAC,GAAG;YACP,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;QACD,SAAS;YACP,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;QACD,eAAe;YACb,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAMD,SAAS,yBAAyB,CAChC,aAA+B,EAC/B,GAAwC;IAExC,MAAM,cAAc,GAAG,aAAa,CAAC,MAAM,CAAC;IAC5C,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,cAAc,EAAE;QACtC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ;YACxB,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;YAChC,IA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GAAG,OAAO,CAAC,MAAM,CAAC;4BACpC,yBAAyB,CAAC,OAAO,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;wBAC9C,CAAC;wBACD,OAAO,OAAO,CAAC;oBACjB,CAAC;oBACD,MAAM,EAAE,CAAC,wCAAqB,CAAC;iBAChC;aACF,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,qFAAqF,CAAC,CAAC;IACzG,CAAC;CAEF,CAAA;AArOY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,YAAY,CAqOxB"}
|
package/dist/prisma.service.js
CHANGED
|
@@ -56,7 +56,7 @@ let PrismaService = PrismaService_1 = class PrismaService {
|
|
|
56
56
|
}
|
|
57
57
|
this.isDestroying = true;
|
|
58
58
|
try {
|
|
59
|
-
if (this.queryListener &&
|
|
59
|
+
if (this.queryListener && typeof this._client.$off === 'function') {
|
|
60
60
|
try {
|
|
61
61
|
this._client.$off('query', this.queryListener);
|
|
62
62
|
this.queryListener = undefined;
|
|
@@ -73,6 +73,7 @@ let PrismaService = PrismaService_1 = class PrismaService {
|
|
|
73
73
|
}
|
|
74
74
|
catch (error) {
|
|
75
75
|
this._isConnected = false;
|
|
76
|
+
this.isDestroying = false;
|
|
76
77
|
const errorMessage = (error === null || error === void 0 ? void 0 : error.message) || String(error);
|
|
77
78
|
const errorStack = (error === null || error === void 0 ? void 0 : error.stack) || '';
|
|
78
79
|
this.logger.error(`Prisma [${this.connectionName}] failed to disconnect: ${errorMessage}`, errorStack);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prisma.service.js","sourceRoot":"","sources":["../lib/prisma.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAmF;AAEnF,sEAAiE;AAG1D,IAAM,aAAa,qBAAnB,MAAM,aAAa;IAUxB,YAA6B,OAA4B;QAA5B,YAAO,GAAP,OAAO,CAAqB;QAPxC,WAAM,GAAG,IAAI,eAAM,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AAE,EACtG,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,KAAI,EAAE,CACnB,CAAC;YACJ,CAAC;YAID,MAAM,aAAa,GACjB,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;gBAC7C,CAAC,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;YAEpF,IAAI,aAAa,EAAE,CAAC;gBAClB,MAAM,WAAW,GAAG,uCAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBACjD,MAAM,WAAW,CAAC;YACpB,CAAC;YAGD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF,CAAA;AA7KY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;;GACA,aAAa,CA6KzB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AppException } from '@nathapp/nestjs-common';
|
|
2
2
|
import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library';
|
|
3
|
+
import { Logger } from '@nestjs/common';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Error code string constants for Prisma errors.
|
|
@@ -55,6 +56,8 @@ export class PrismaAppException extends AppException {
|
|
|
55
56
|
* Provides consistent error responses across Prisma-based services.
|
|
56
57
|
*/
|
|
57
58
|
export class PrismaErrorMapper {
|
|
59
|
+
private static readonly logger = new Logger(PrismaErrorMapper.name);
|
|
60
|
+
|
|
58
61
|
/**
|
|
59
62
|
* Error code mapping table for Prisma Client Known Request Errors.
|
|
60
63
|
* Maps Prisma error codes to HTTP status codes, numeric codes, and string codes.
|
|
@@ -112,28 +115,49 @@ export class PrismaErrorMapper {
|
|
|
112
115
|
const errorConfig = this.ERROR_MAP[error.code];
|
|
113
116
|
|
|
114
117
|
if (errorConfig) {
|
|
118
|
+
// P2002 (unique constraint) intentionally exposes only the conflicting field name(s)
|
|
119
|
+
// via `meta.target` so callers can produce "X already taken" UX. This is the single
|
|
120
|
+
// deliberate exception to the no-raw-meta rule; the full meta is still logged
|
|
121
|
+
// server-side only. Note: for some connectors `meta.target` is the constraint/index
|
|
122
|
+
// name rather than the logical field — acceptable for this use case.
|
|
123
|
+
// For all other known errors, pass no raw meta to avoid leaking DB internals.
|
|
124
|
+
const safeArgs: Record<string, unknown> =
|
|
125
|
+
error.code === 'P2002' && error.meta?.target
|
|
126
|
+
? { target: error.meta.target }
|
|
127
|
+
: {};
|
|
128
|
+
|
|
129
|
+
this.logger.error(
|
|
130
|
+
`Prisma error ${error.code}: ${error.message}`,
|
|
131
|
+
{ meta: error.meta, clientVersion: error.clientVersion }
|
|
132
|
+
);
|
|
133
|
+
|
|
115
134
|
return new PrismaAppException(
|
|
116
135
|
errorConfig.numericCode,
|
|
117
136
|
errorConfig.stringCode,
|
|
118
|
-
|
|
137
|
+
safeArgs,
|
|
119
138
|
errorConfig.httpStatus
|
|
120
139
|
);
|
|
121
140
|
}
|
|
122
141
|
|
|
123
|
-
// Unknown Prisma error code -
|
|
142
|
+
// Unknown Prisma error code - log full details server-side, return generic response
|
|
143
|
+
this.logger.error(
|
|
144
|
+
`Unknown Prisma error ${error.code}: ${error.message}`,
|
|
145
|
+
{ meta: error.meta }
|
|
146
|
+
);
|
|
124
147
|
return new PrismaAppException(
|
|
125
148
|
9998,
|
|
126
149
|
PRISMA_ERROR_CODES.DATABASE_ERROR,
|
|
127
|
-
{
|
|
150
|
+
{},
|
|
128
151
|
500
|
|
129
152
|
);
|
|
130
153
|
}
|
|
131
154
|
|
|
132
|
-
// Handle generic errors
|
|
155
|
+
// Handle generic errors - log server-side, return no internal details
|
|
156
|
+
this.logger.error('Unexpected database error', { message: error.message || String(error) });
|
|
133
157
|
return new PrismaAppException(
|
|
134
158
|
9999,
|
|
135
159
|
PRISMA_ERROR_CODES.UNKNOWN_ERROR,
|
|
136
|
-
{
|
|
160
|
+
{},
|
|
137
161
|
500
|
|
138
162
|
);
|
|
139
163
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ArgumentsHost, Catch, ExceptionFilter } from '@nestjs/common';
|
|
1
|
+
import { ArgumentsHost, Catch, ExceptionFilter, Logger } from '@nestjs/common';
|
|
2
2
|
import {
|
|
3
3
|
PrismaClientKnownRequestError,
|
|
4
4
|
PrismaClientValidationError
|
|
@@ -29,32 +29,37 @@ import { PrismaErrorMapper, PRISMA_ERROR_CODES } from '../errors/prisma-error.ma
|
|
|
29
29
|
*/
|
|
30
30
|
@Catch(PrismaClientKnownRequestError, PrismaClientValidationError)
|
|
31
31
|
export class PrismaExceptionFilter implements ExceptionFilter {
|
|
32
|
+
private readonly logger = new Logger(PrismaExceptionFilter.name);
|
|
33
|
+
|
|
32
34
|
catch(exception: PrismaClientKnownRequestError | PrismaClientValidationError, host: ArgumentsHost): void {
|
|
33
35
|
const ctx = host.switchToHttp();
|
|
34
36
|
const response = ctx.getResponse();
|
|
35
37
|
|
|
36
38
|
// Handle PrismaClientValidationError separately
|
|
37
39
|
if (exception instanceof PrismaClientValidationError) {
|
|
40
|
+
// Log full validation error server-side; never expose raw message in the HTTP response
|
|
41
|
+
this.logger.error('PrismaClientValidationError', { message: exception.message });
|
|
38
42
|
response.status(400).json({
|
|
39
43
|
success: false,
|
|
40
44
|
error: {
|
|
41
45
|
code: PRISMA_ERROR_CODES.DATABASE_ERROR,
|
|
42
46
|
message: 'Invalid query parameters',
|
|
43
|
-
args: {
|
|
47
|
+
args: {},
|
|
44
48
|
},
|
|
45
49
|
});
|
|
46
50
|
return;
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
// Map Prisma known request error to PrismaAppException
|
|
54
|
+
// PrismaErrorMapper.map() already logs full details and strips sensitive data from args
|
|
50
55
|
const appException = PrismaErrorMapper.map(exception);
|
|
51
56
|
|
|
52
|
-
// Send standardized error response
|
|
57
|
+
// Send standardized error response — args contain only safe, sanitized fields
|
|
53
58
|
response.status(appException.httpStatus || 500).json({
|
|
54
59
|
success: false,
|
|
55
60
|
error: {
|
|
56
61
|
code: appException.code,
|
|
57
|
-
message:
|
|
62
|
+
message: 'A database error occurred',
|
|
58
63
|
args: appException.args,
|
|
59
64
|
},
|
|
60
65
|
});
|
package/lib/prisma.interfaces.ts
CHANGED
|
@@ -8,6 +8,7 @@ export interface PrismaClientLike {
|
|
|
8
8
|
$connect(): Promise<void>;
|
|
9
9
|
$disconnect(): Promise<void>;
|
|
10
10
|
$on?(event: string, listener: (...args: any[]) => void): void;
|
|
11
|
+
$off?(event: string, listener: (...args: any[]) => void): void;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export interface PrismaModuleOptions {
|
package/lib/prisma.module.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { PrismaModuleOptions, PrismaModuleAsyncOptions, PrismaOptionsFactor
|
|
|
5
5
|
import { PrismaService } from './prisma.service';
|
|
6
6
|
import { PrismaTransactionManager } from './transaction/prisma-transaction-manager';
|
|
7
7
|
import { getPrismaToken, getPrismaTransactionManagerToken, PRISMA_MODULE_OPTIONS } from './prisma.constants';
|
|
8
|
-
import {
|
|
8
|
+
import { getPrismaTransactionAlsToken } from './transaction/prisma-transaction.constants';
|
|
9
9
|
|
|
10
10
|
function createDisabledTransactionManager(name?: string) {
|
|
11
11
|
const connectionName = name ?? 'default';
|
|
@@ -144,13 +144,19 @@ export class PrismaModule {
|
|
|
144
144
|
});
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
// Publish the ALS as a DI token so external consumers
|
|
148
|
-
// when
|
|
147
|
+
// Publish the ALS as a DI token so external consumers can share the same instance
|
|
148
|
+
// when transaction support is enabled. With async options, the transaction flag is
|
|
149
|
+
// only known at factory-resolution time, so the provider is always registered and its
|
|
150
|
+
// factory returns `undefined` when transactions are disabled. Consumers that inject this
|
|
151
|
+
// token must therefore tolerate an `undefined` value (transactions off).
|
|
149
152
|
const alsToken = getPrismaTransactionAlsToken(name);
|
|
150
153
|
providers.push({
|
|
151
154
|
provide: alsToken,
|
|
152
|
-
inject: [connectionToken],
|
|
153
|
-
useFactory: () =>
|
|
155
|
+
inject: [connectionToken, PRISMA_MODULE_OPTIONS],
|
|
156
|
+
useFactory: (_service: PrismaService, opts: PrismaModuleOptions) => {
|
|
157
|
+
if (!opts.transaction) return undefined;
|
|
158
|
+
return ctx.als;
|
|
159
|
+
},
|
|
154
160
|
});
|
|
155
161
|
|
|
156
162
|
const namedTxToken = getPrismaTransactionManagerToken(name);
|
|
@@ -272,11 +278,4 @@ export class PrismaModule {
|
|
|
272
278
|
throw new Error('Invalid PrismaModuleAsyncOptions: must provide useFactory, useClass, or useExisting');
|
|
273
279
|
}
|
|
274
280
|
|
|
275
|
-
// Keep the original createAsyncProviders for any external callers — delegate to the new one with a discarded ctx.
|
|
276
|
-
private static createAsyncProviders(
|
|
277
|
-
options: PrismaModuleAsyncOptions,
|
|
278
|
-
connectionToken: string,
|
|
279
|
-
): Provider[] {
|
|
280
|
-
return this.createAsyncProvidersWithCtx(options, connectionToken, {});
|
|
281
|
-
}
|
|
282
281
|
}
|
package/lib/prisma.service.ts
CHANGED
|
@@ -67,9 +67,9 @@ export class PrismaService<T extends PrismaClientLike = PrismaClientLike>
|
|
|
67
67
|
|
|
68
68
|
try {
|
|
69
69
|
// Clean up query event listener before disconnecting
|
|
70
|
-
if (this.queryListener &&
|
|
70
|
+
if (this.queryListener && typeof this._client.$off === 'function') {
|
|
71
71
|
try {
|
|
72
|
-
|
|
72
|
+
this._client.$off('query', this.queryListener);
|
|
73
73
|
this.queryListener = undefined;
|
|
74
74
|
} catch (cleanupError: any) {
|
|
75
75
|
// Log cleanup errors but don't throw - continue with disconnect
|
|
@@ -88,6 +88,7 @@ export class PrismaService<T extends PrismaClientLike = PrismaClientLike>
|
|
|
88
88
|
}
|
|
89
89
|
} catch (error: any) {
|
|
90
90
|
this._isConnected = false;
|
|
91
|
+
this.isDestroying = false;
|
|
91
92
|
const errorMessage = error?.message || String(error);
|
|
92
93
|
const errorStack = error?.stack || '';
|
|
93
94
|
this.logger.error(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nathapp/nestjs-prisma",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.2",
|
|
4
4
|
"description": "NestJS Prisma integration with multi-database support",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rimraf dist/ .turbo/",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"types": "dist/index.d.ts",
|
|
14
14
|
"main": "dist/index.js",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@nathapp/nestjs-common": "^3.2.
|
|
17
|
-
"@nathapp/nestjs-data": "^3.2.
|
|
16
|
+
"@nathapp/nestjs-common": "^3.2.3",
|
|
17
|
+
"@nathapp/nestjs-data": "^3.2.1"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@nathapp/eslint-config": "1.0.1",
|
|
@@ -39,7 +39,7 @@ describe('PrismaErrorMapper', () => {
|
|
|
39
39
|
expect(result).toBeInstanceOf(AppException);
|
|
40
40
|
expect(result.httpStatus).toBe(404);
|
|
41
41
|
expect(result.code).toBe('RECORD_NOT_FOUND');
|
|
42
|
-
expect(result.args).toEqual({
|
|
42
|
+
expect(result.args).toEqual({}); // raw meta not exposed in args (security)
|
|
43
43
|
});
|
|
44
44
|
|
|
45
45
|
it('should map P2003 (foreign key constraint) to AppException with bad request status', () => {
|
|
@@ -57,7 +57,7 @@ describe('PrismaErrorMapper', () => {
|
|
|
57
57
|
expect(result).toBeInstanceOf(AppException);
|
|
58
58
|
expect(result.httpStatus).toBe(400);
|
|
59
59
|
expect(result.code).toBe('INVALID_REFERENCE');
|
|
60
|
-
expect(result.args).toEqual({
|
|
60
|
+
expect(result.args).toEqual({}); // raw meta not exposed in args (security)
|
|
61
61
|
});
|
|
62
62
|
|
|
63
63
|
it('should map P2014 (relation violation) to AppException with conflict status', () => {
|
|
@@ -75,7 +75,7 @@ describe('PrismaErrorMapper', () => {
|
|
|
75
75
|
expect(result).toBeInstanceOf(AppException);
|
|
76
76
|
expect(result.httpStatus).toBe(409);
|
|
77
77
|
expect(result.code).toBe('RELATION_VIOLATION');
|
|
78
|
-
expect(result.args).toEqual({
|
|
78
|
+
expect(result.args).toEqual({}); // raw meta not exposed in args (security)
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
it('should map unknown Prisma error codes to internal server error', () => {
|
|
@@ -143,7 +143,7 @@ describe('PrismaErrorMapper', () => {
|
|
|
143
143
|
expect(result).toBeInstanceOf(AppException);
|
|
144
144
|
expect(result.httpStatus).toBe(400);
|
|
145
145
|
expect(result.code).toBe('VALUE_TOO_LONG');
|
|
146
|
-
expect(result.args).toEqual({
|
|
146
|
+
expect(result.args).toEqual({}); // raw meta not exposed in args (security)
|
|
147
147
|
});
|
|
148
148
|
|
|
149
149
|
it('should map P2001 (record does not exist) to AppException with not found status', () => {
|
|
@@ -161,7 +161,7 @@ describe('PrismaErrorMapper', () => {
|
|
|
161
161
|
expect(result).toBeInstanceOf(AppException);
|
|
162
162
|
expect(result.httpStatus).toBe(404);
|
|
163
163
|
expect(result.code).toBe('RECORD_NOT_FOUND');
|
|
164
|
-
expect(result.args).toEqual({
|
|
164
|
+
expect(result.args).toEqual({}); // raw meta not exposed in args (security)
|
|
165
165
|
});
|
|
166
166
|
|
|
167
167
|
it('should map P1008 (connection timeout) to AppException with service unavailable status', () => {
|
|
@@ -179,7 +179,46 @@ describe('PrismaErrorMapper', () => {
|
|
|
179
179
|
expect(result).toBeInstanceOf(AppException);
|
|
180
180
|
expect(result.httpStatus).toBe(503);
|
|
181
181
|
expect(result.code).toBe('CONNECTION_TIMEOUT');
|
|
182
|
-
expect(result.args).toEqual({
|
|
182
|
+
expect(result.args).toEqual({}); // raw meta not exposed in args (security)
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// --- P2002 intentional target exposure (pinning tests) ---
|
|
186
|
+
// P2002 is the single deliberate exception to the no-raw-meta rule: it exposes
|
|
187
|
+
// `meta.target` so callers can produce "X already taken" UX. These tests lock
|
|
188
|
+
// in that behavior so it cannot be accidentally removed.
|
|
189
|
+
|
|
190
|
+
it('exposes only the conflicting target field for P2002 and nothing else', () => {
|
|
191
|
+
const prismaError = new PrismaClientKnownRequestError(
|
|
192
|
+
'Unique constraint failed on the fields: (`email`)',
|
|
193
|
+
{
|
|
194
|
+
code: 'P2002',
|
|
195
|
+
clientVersion: '6.0.0',
|
|
196
|
+
meta: { target: ['email'] },
|
|
197
|
+
}
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
const result = PrismaErrorMapper.map(prismaError);
|
|
201
|
+
|
|
202
|
+
expect(result).toBeInstanceOf(AppException);
|
|
203
|
+
expect(result.args).toEqual({ target: ['email'] });
|
|
204
|
+
// Confirm no other meta fields leak through
|
|
205
|
+
expect(Object.keys(result.args ?? {})).toEqual(['target']);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('returns empty args (no DB internals) for non-P2002 known errors', () => {
|
|
209
|
+
const prismaError = new PrismaClientKnownRequestError(
|
|
210
|
+
'An operation failed because it depends on one or more records that were required but not found.',
|
|
211
|
+
{
|
|
212
|
+
code: 'P2025',
|
|
213
|
+
clientVersion: '6.0.0',
|
|
214
|
+
meta: { cause: 'Record to delete does not exist' },
|
|
215
|
+
}
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
const result = PrismaErrorMapper.map(prismaError);
|
|
219
|
+
|
|
220
|
+
expect(result).toBeInstanceOf(AppException);
|
|
221
|
+
expect(result.args).toEqual({});
|
|
183
222
|
});
|
|
184
223
|
});
|
|
185
224
|
|
|
@@ -76,7 +76,7 @@ describe('PrismaExceptionFilter', () => {
|
|
|
76
76
|
error: {
|
|
77
77
|
code: PRISMA_ERROR_CODES.RECORD_NOT_FOUND,
|
|
78
78
|
message: expect.any(String),
|
|
79
|
-
args: {
|
|
79
|
+
args: {}, // raw meta not exposed in args (security)
|
|
80
80
|
},
|
|
81
81
|
});
|
|
82
82
|
});
|
|
@@ -99,7 +99,7 @@ describe('PrismaExceptionFilter', () => {
|
|
|
99
99
|
error: {
|
|
100
100
|
code: PRISMA_ERROR_CODES.INVALID_REFERENCE,
|
|
101
101
|
message: expect.any(String),
|
|
102
|
-
args: {
|
|
102
|
+
args: {}, // raw meta not exposed in args (security)
|
|
103
103
|
},
|
|
104
104
|
});
|
|
105
105
|
});
|
|
@@ -122,7 +122,7 @@ describe('PrismaExceptionFilter', () => {
|
|
|
122
122
|
error: {
|
|
123
123
|
code: PRISMA_ERROR_CODES.CONNECTION_TIMEOUT,
|
|
124
124
|
message: expect.any(String),
|
|
125
|
-
args: {
|
|
125
|
+
args: {}, // raw meta not exposed in args (security)
|
|
126
126
|
},
|
|
127
127
|
});
|
|
128
128
|
});
|
|
@@ -144,7 +144,7 @@ describe('PrismaExceptionFilter', () => {
|
|
|
144
144
|
error: {
|
|
145
145
|
code: PRISMA_ERROR_CODES.DATABASE_ERROR,
|
|
146
146
|
message: expect.any(String),
|
|
147
|
-
args:
|
|
147
|
+
args: {}, // raw meta not exposed in args (security)
|
|
148
148
|
},
|
|
149
149
|
});
|
|
150
150
|
});
|
|
@@ -170,7 +170,7 @@ describe('PrismaExceptionFilter', () => {
|
|
|
170
170
|
error: {
|
|
171
171
|
code: PRISMA_ERROR_CODES.DATABASE_ERROR,
|
|
172
172
|
message: 'Invalid query parameters',
|
|
173
|
-
args: {
|
|
173
|
+
args: {}, // raw error message not exposed in args (security)
|
|
174
174
|
},
|
|
175
175
|
});
|
|
176
176
|
});
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Test
|
|
1
|
+
import { Test } from '@nestjs/testing';
|
|
2
2
|
import { Injectable } from '@nestjs/common';
|
|
3
3
|
import { PrismaModule } from '../lib/prisma.module';
|
|
4
4
|
import { PrismaService } from '../lib/prisma.service';
|
|
5
5
|
import { getPrismaToken, getPrismaTransactionManagerToken } from '../lib/prisma.constants';
|
|
6
|
+
import { getPrismaTransactionAlsToken } from '../lib/transaction/prisma-transaction.constants';
|
|
6
7
|
import { PrismaTransactionManager } from '../lib/transaction/prisma-transaction-manager';
|
|
7
8
|
import type { PrismaModuleOptions, PrismaOptionsFactory, PrismaClientLike } from '../lib/prisma.interfaces';
|
|
8
9
|
|
|
@@ -356,6 +357,27 @@ describe('PrismaModule', () => {
|
|
|
356
357
|
expect(typeof (tx as any).run).toBe('function');
|
|
357
358
|
});
|
|
358
359
|
|
|
360
|
+
it('ALS token resolves to undefined when transaction support is disabled', async () => {
|
|
361
|
+
const ClientClass = jest.fn(() => mockClient);
|
|
362
|
+
|
|
363
|
+
const moduleRef = await Test.createTestingModule({
|
|
364
|
+
imports: [
|
|
365
|
+
PrismaModule.forRootAsync({
|
|
366
|
+
useFactory: () => ({
|
|
367
|
+
client: ClientClass as any,
|
|
368
|
+
transaction: false,
|
|
369
|
+
}),
|
|
370
|
+
}),
|
|
371
|
+
],
|
|
372
|
+
}).compile();
|
|
373
|
+
|
|
374
|
+
// The ALS provider is always registered (transaction flag is only known at
|
|
375
|
+
// factory-resolution time with async options), so the token is resolvable but
|
|
376
|
+
// returns undefined when transactions are disabled. This test pins that behavior.
|
|
377
|
+
const als = moduleRef.get(getPrismaTransactionAlsToken(), { strict: false });
|
|
378
|
+
expect(als).toBeUndefined();
|
|
379
|
+
});
|
|
380
|
+
|
|
359
381
|
it('should respect isGlobal option', async () => {
|
|
360
382
|
const ClientClass = jest.fn(() => mockClient);
|
|
361
383
|
|