@camcima/nestjs-rfc9457 0.0.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/LICENSE +21 -0
- package/README.md +753 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/problem-details.factory.d.ts +18 -0
- package/dist/problem-details.factory.js +242 -0
- package/dist/problem-details.factory.js.map +1 -0
- package/dist/problem-type.decorator.d.ts +3 -0
- package/dist/problem-type.decorator.js +11 -0
- package/dist/problem-type.decorator.js.map +1 -0
- package/dist/rfc9457.constants.d.ts +3 -0
- package/dist/rfc9457.constants.js +7 -0
- package/dist/rfc9457.constants.js.map +1 -0
- package/dist/rfc9457.exception-filter.d.ts +11 -0
- package/dist/rfc9457.exception-filter.js +65 -0
- package/dist/rfc9457.exception-filter.js.map +1 -0
- package/dist/rfc9457.interfaces.d.ts +37 -0
- package/dist/rfc9457.interfaces.js +3 -0
- package/dist/rfc9457.interfaces.js.map +1 -0
- package/dist/rfc9457.module.d.ts +7 -0
- package/dist/rfc9457.module.js +93 -0
- package/dist/rfc9457.module.js.map +1 -0
- package/dist/utils/slug.d.ts +1 -0
- package/dist/utils/slug.js +13 -0
- package/dist/utils/slug.js.map +1 -0
- package/dist/validation/rfc9457-validation-pipe-exception.factory.d.ts +2 -0
- package/dist/validation/rfc9457-validation-pipe-exception.factory.js +10 -0
- package/dist/validation/rfc9457-validation-pipe-exception.factory.js.map +1 -0
- package/dist/validation/rfc9457-validation.exception.d.ts +5 -0
- package/dist/validation/rfc9457-validation.exception.js +12 -0
- package/dist/validation/rfc9457-validation.exception.js.map +1 -0
- package/package.json +79 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { Rfc9457Module } from './rfc9457.module';
|
|
2
|
+
export { ProblemDetailsFactory } from './problem-details.factory';
|
|
3
|
+
export { Rfc9457ExceptionFilter } from './rfc9457.exception-filter';
|
|
4
|
+
export { ProblemType } from './problem-type.decorator';
|
|
5
|
+
export { ProblemDetail, ProblemTypeMetadata, Rfc9457ModuleOptions, Rfc9457OptionsFactory, Rfc9457AsyncModuleOptions, InstanceStrategy, Rfc9457Request, } from './rfc9457.interfaces';
|
|
6
|
+
export { RFC9457_MODULE_OPTIONS, PROBLEM_CONTENT_TYPE } from './rfc9457.constants';
|
|
7
|
+
export { Rfc9457ValidationException } from './validation/rfc9457-validation.exception';
|
|
8
|
+
export { createRfc9457ValidationPipeExceptionFactory } from './validation/rfc9457-validation-pipe-exception.factory';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRfc9457ValidationPipeExceptionFactory = exports.Rfc9457ValidationException = exports.PROBLEM_CONTENT_TYPE = exports.RFC9457_MODULE_OPTIONS = exports.ProblemType = exports.Rfc9457ExceptionFilter = exports.ProblemDetailsFactory = exports.Rfc9457Module = void 0;
|
|
4
|
+
var rfc9457_module_1 = require("./rfc9457.module");
|
|
5
|
+
Object.defineProperty(exports, "Rfc9457Module", { enumerable: true, get: function () { return rfc9457_module_1.Rfc9457Module; } });
|
|
6
|
+
var problem_details_factory_1 = require("./problem-details.factory");
|
|
7
|
+
Object.defineProperty(exports, "ProblemDetailsFactory", { enumerable: true, get: function () { return problem_details_factory_1.ProblemDetailsFactory; } });
|
|
8
|
+
var rfc9457_exception_filter_1 = require("./rfc9457.exception-filter");
|
|
9
|
+
Object.defineProperty(exports, "Rfc9457ExceptionFilter", { enumerable: true, get: function () { return rfc9457_exception_filter_1.Rfc9457ExceptionFilter; } });
|
|
10
|
+
var problem_type_decorator_1 = require("./problem-type.decorator");
|
|
11
|
+
Object.defineProperty(exports, "ProblemType", { enumerable: true, get: function () { return problem_type_decorator_1.ProblemType; } });
|
|
12
|
+
var rfc9457_constants_1 = require("./rfc9457.constants");
|
|
13
|
+
Object.defineProperty(exports, "RFC9457_MODULE_OPTIONS", { enumerable: true, get: function () { return rfc9457_constants_1.RFC9457_MODULE_OPTIONS; } });
|
|
14
|
+
Object.defineProperty(exports, "PROBLEM_CONTENT_TYPE", { enumerable: true, get: function () { return rfc9457_constants_1.PROBLEM_CONTENT_TYPE; } });
|
|
15
|
+
var rfc9457_validation_exception_1 = require("./validation/rfc9457-validation.exception");
|
|
16
|
+
Object.defineProperty(exports, "Rfc9457ValidationException", { enumerable: true, get: function () { return rfc9457_validation_exception_1.Rfc9457ValidationException; } });
|
|
17
|
+
var rfc9457_validation_pipe_exception_factory_1 = require("./validation/rfc9457-validation-pipe-exception.factory");
|
|
18
|
+
Object.defineProperty(exports, "createRfc9457ValidationPipeExceptionFactory", { enumerable: true, get: function () { return rfc9457_validation_pipe_exception_factory_1.createRfc9457ValidationPipeExceptionFactory; } });
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mDAAiD;AAAxC,+GAAA,aAAa,OAAA;AACtB,qEAAkE;AAAzD,gIAAA,qBAAqB,OAAA;AAC9B,uEAAoE;AAA3D,kIAAA,sBAAsB,OAAA;AAC/B,mEAAuD;AAA9C,qHAAA,WAAW,OAAA;AAUpB,yDAAmF;AAA1E,2HAAA,sBAAsB,OAAA;AAAE,yHAAA,oBAAoB,OAAA;AACrD,0FAAuF;AAA9E,0IAAA,0BAA0B,OAAA;AACnC,oHAAqH;AAA5G,wKAAA,2CAA2C,OAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ProblemDetail, Rfc9457ModuleOptions, Rfc9457Request } from './rfc9457.interfaces';
|
|
2
|
+
export declare class ProblemDetailsFactory {
|
|
3
|
+
private readonly options;
|
|
4
|
+
constructor(options?: Rfc9457ModuleOptions);
|
|
5
|
+
create(exception: unknown, request: Rfc9457Request): {
|
|
6
|
+
status: number;
|
|
7
|
+
body: ProblemDetail;
|
|
8
|
+
};
|
|
9
|
+
private normalize;
|
|
10
|
+
private resolveStatus;
|
|
11
|
+
private isUriReference;
|
|
12
|
+
private normalizeType;
|
|
13
|
+
private resolveInstance;
|
|
14
|
+
private extractDetail;
|
|
15
|
+
private handleValidation;
|
|
16
|
+
private isDefaultValidationException;
|
|
17
|
+
private flattenValidationError;
|
|
18
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
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;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
45
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.ProblemDetailsFactory = void 0;
|
|
49
|
+
const common_1 = require("@nestjs/common");
|
|
50
|
+
const http = __importStar(require("http"));
|
|
51
|
+
const crypto_1 = require("crypto");
|
|
52
|
+
const rfc9457_constants_1 = require("./rfc9457.constants");
|
|
53
|
+
const rfc9457_validation_exception_1 = require("./validation/rfc9457-validation.exception");
|
|
54
|
+
const slug_1 = require("./utils/slug");
|
|
55
|
+
let ProblemDetailsFactory = class ProblemDetailsFactory {
|
|
56
|
+
constructor(options = {}) {
|
|
57
|
+
this.options = options;
|
|
58
|
+
}
|
|
59
|
+
createFromMapped(mapped, exception, request) {
|
|
60
|
+
const result = { ...mapped };
|
|
61
|
+
return this.normalize(result, exception, request);
|
|
62
|
+
}
|
|
63
|
+
create(exception, request, options) {
|
|
64
|
+
let result = null;
|
|
65
|
+
if (!options?.skipMapper && this.options.exceptionMapper) {
|
|
66
|
+
const mapped = this.options.exceptionMapper(exception, request);
|
|
67
|
+
if (mapped) {
|
|
68
|
+
result = { ...mapped };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (!result && exception != null && typeof exception === 'object') {
|
|
72
|
+
const constructor = exception.constructor;
|
|
73
|
+
if (constructor) {
|
|
74
|
+
const metadata = Reflect.getMetadata(rfc9457_constants_1.PROBLEM_TYPE_METADATA_KEY, constructor);
|
|
75
|
+
if (metadata) {
|
|
76
|
+
result = { ...metadata };
|
|
77
|
+
const detail = this.extractDetail(exception);
|
|
78
|
+
if (detail !== undefined) {
|
|
79
|
+
result.detail = detail;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (!result) {
|
|
85
|
+
result = this.handleValidation(exception, request);
|
|
86
|
+
}
|
|
87
|
+
if (!result && exception instanceof common_1.HttpException) {
|
|
88
|
+
const exceptionStatus = exception.getStatus();
|
|
89
|
+
result = {
|
|
90
|
+
status: exceptionStatus,
|
|
91
|
+
title: http.STATUS_CODES[exceptionStatus] || 'Unknown Error',
|
|
92
|
+
};
|
|
93
|
+
const detail = this.extractDetail(exception);
|
|
94
|
+
if (detail !== undefined) {
|
|
95
|
+
result.detail = detail;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (!result) {
|
|
99
|
+
result = {
|
|
100
|
+
status: 500,
|
|
101
|
+
title: 'Internal Server Error',
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return this.normalize(result, exception, request);
|
|
105
|
+
}
|
|
106
|
+
normalize(result, exception, request) {
|
|
107
|
+
const httpStatus = this.resolveStatus(result, exception);
|
|
108
|
+
result.type = this.normalizeType(result, httpStatus);
|
|
109
|
+
if (!result.title) {
|
|
110
|
+
result.title = http.STATUS_CODES[httpStatus] || 'Unknown Error';
|
|
111
|
+
}
|
|
112
|
+
result.status = httpStatus;
|
|
113
|
+
const instance = this.resolveInstance(request, exception);
|
|
114
|
+
if (instance !== undefined) {
|
|
115
|
+
result.instance = instance;
|
|
116
|
+
}
|
|
117
|
+
return { status: httpStatus, body: result };
|
|
118
|
+
}
|
|
119
|
+
resolveStatus(result, exception) {
|
|
120
|
+
if (result.status !== undefined &&
|
|
121
|
+
typeof result.status === 'number' &&
|
|
122
|
+
result.status >= 100 &&
|
|
123
|
+
result.status < 600) {
|
|
124
|
+
return result.status;
|
|
125
|
+
}
|
|
126
|
+
if (exception instanceof common_1.HttpException) {
|
|
127
|
+
return exception.getStatus();
|
|
128
|
+
}
|
|
129
|
+
return 500;
|
|
130
|
+
}
|
|
131
|
+
isUriReference(value) {
|
|
132
|
+
return /^[a-zA-Z][a-zA-Z0-9+\-.]*:/.test(value);
|
|
133
|
+
}
|
|
134
|
+
normalizeType(result, status) {
|
|
135
|
+
if (result.type) {
|
|
136
|
+
if (this.isUriReference(result.type)) {
|
|
137
|
+
return result.type;
|
|
138
|
+
}
|
|
139
|
+
if (this.options.typeBaseUri) {
|
|
140
|
+
const baseUri = this.options.typeBaseUri.replace(/\/+$/, '');
|
|
141
|
+
return `${baseUri}/${result.type}`;
|
|
142
|
+
}
|
|
143
|
+
return result.type;
|
|
144
|
+
}
|
|
145
|
+
if (this.options.typeBaseUri) {
|
|
146
|
+
const phrase = http.STATUS_CODES[status] || 'Unknown Error';
|
|
147
|
+
const slug = (0, slug_1.toSlug)(phrase);
|
|
148
|
+
const baseUri = this.options.typeBaseUri.replace(/\/+$/, '');
|
|
149
|
+
return `${baseUri}/${slug}`;
|
|
150
|
+
}
|
|
151
|
+
return 'about:blank';
|
|
152
|
+
}
|
|
153
|
+
resolveInstance(request, exception) {
|
|
154
|
+
const strategy = this.options.instanceStrategy || 'none';
|
|
155
|
+
if (strategy === 'none')
|
|
156
|
+
return undefined;
|
|
157
|
+
if (strategy === 'request-uri')
|
|
158
|
+
return request.url;
|
|
159
|
+
if (strategy === 'uuid')
|
|
160
|
+
return `urn:uuid:${(0, crypto_1.randomUUID)()}`;
|
|
161
|
+
if (typeof strategy === 'function')
|
|
162
|
+
return strategy(request, exception);
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
extractDetail(exception) {
|
|
166
|
+
if (exception instanceof common_1.HttpException) {
|
|
167
|
+
const response = exception.getResponse();
|
|
168
|
+
const status = exception.getStatus();
|
|
169
|
+
const defaultPhrase = http.STATUS_CODES[status];
|
|
170
|
+
if (typeof response === 'string') {
|
|
171
|
+
return response === defaultPhrase ? undefined : response;
|
|
172
|
+
}
|
|
173
|
+
if (typeof response === 'object' && response !== null) {
|
|
174
|
+
const msg = response.message;
|
|
175
|
+
if (typeof msg === 'string' && msg.length > 0) {
|
|
176
|
+
return msg === defaultPhrase ? undefined : msg;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
if (exception instanceof Error) {
|
|
182
|
+
return exception.message || undefined;
|
|
183
|
+
}
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
handleValidation(exception, request) {
|
|
187
|
+
if (exception instanceof rfc9457_validation_exception_1.Rfc9457ValidationException) {
|
|
188
|
+
const validationErrors = exception.validationErrors;
|
|
189
|
+
return {
|
|
190
|
+
status: 400,
|
|
191
|
+
title: 'Bad Request',
|
|
192
|
+
detail: 'Request validation failed',
|
|
193
|
+
errors: validationErrors.map((err) => this.flattenValidationError(err)),
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
if (this.isDefaultValidationException(exception)) {
|
|
197
|
+
const response = exception.getResponse();
|
|
198
|
+
const messages = response.message;
|
|
199
|
+
if (this.options.validationExceptionMapper) {
|
|
200
|
+
return this.options.validationExceptionMapper(messages, request);
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
status: 400,
|
|
204
|
+
title: 'Bad Request',
|
|
205
|
+
detail: 'Request validation failed',
|
|
206
|
+
errors: messages,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
isDefaultValidationException(exception) {
|
|
212
|
+
if (!(exception instanceof common_1.HttpException))
|
|
213
|
+
return false;
|
|
214
|
+
if (exception.getStatus() !== 400)
|
|
215
|
+
return false;
|
|
216
|
+
const response = exception.getResponse();
|
|
217
|
+
if (typeof response !== 'object' || response === null)
|
|
218
|
+
return false;
|
|
219
|
+
const resp = response;
|
|
220
|
+
if (resp.error !== 'Bad Request')
|
|
221
|
+
return false;
|
|
222
|
+
const msg = resp.message;
|
|
223
|
+
return Array.isArray(msg) && msg.length > 0 && msg.every((m) => typeof m === 'string');
|
|
224
|
+
}
|
|
225
|
+
flattenValidationError(error) {
|
|
226
|
+
const result = { property: error.property };
|
|
227
|
+
if (error.constraints) {
|
|
228
|
+
result.constraints = error.constraints;
|
|
229
|
+
}
|
|
230
|
+
if (error.children && error.children.length > 0) {
|
|
231
|
+
result.children = error.children.map((child) => this.flattenValidationError(child));
|
|
232
|
+
}
|
|
233
|
+
return result;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
exports.ProblemDetailsFactory = ProblemDetailsFactory;
|
|
237
|
+
exports.ProblemDetailsFactory = ProblemDetailsFactory = __decorate([
|
|
238
|
+
(0, common_1.Injectable)(),
|
|
239
|
+
__param(0, (0, common_1.Inject)(rfc9457_constants_1.RFC9457_MODULE_OPTIONS)),
|
|
240
|
+
__metadata("design:paramtypes", [Object])
|
|
241
|
+
], ProblemDetailsFactory);
|
|
242
|
+
//# sourceMappingURL=problem-details.factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problem-details.factory.js","sourceRoot":"","sources":["../src/problem-details.factory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAmE;AACnE,2CAA6B;AAC7B,mCAAoC;AAOpC,2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CAAC;IAChB,CAAC;CACF,CAAA;AAlQY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,eAAM,EAAC,0CAAsB,CAAC,CAAA;;GAFtB,qBAAqB,CAkQjC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProblemType = ProblemType;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const rfc9457_constants_1 = require("./rfc9457.constants");
|
|
6
|
+
function ProblemType(metadata) {
|
|
7
|
+
return (target) => {
|
|
8
|
+
Reflect.defineMetadata(rfc9457_constants_1.PROBLEM_TYPE_METADATA_KEY, metadata, target);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=problem-type.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problem-type.decorator.js","sourceRoot":"","sources":["../src/problem-type.decorator.ts"],"names":[],"mappings":";;AAIA,kCAIC;AARD,4BAA0B;AAC1B,2DAAgE;AAGhE,SAAgB,WAAW,CAAC,QAA6B;IACvD,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,OAAO,CAAC,cAAc,CAAC,6CAAyB,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IACtE,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PROBLEM_CONTENT_TYPE = exports.PROBLEM_TYPE_METADATA_KEY = exports.RFC9457_MODULE_OPTIONS = void 0;
|
|
4
|
+
exports.RFC9457_MODULE_OPTIONS = Symbol('RFC9457_MODULE_OPTIONS');
|
|
5
|
+
exports.PROBLEM_TYPE_METADATA_KEY = Symbol('RFC9457_PROBLEM_TYPE');
|
|
6
|
+
exports.PROBLEM_CONTENT_TYPE = 'application/problem+json';
|
|
7
|
+
//# sourceMappingURL=rfc9457.constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rfc9457.constants.js","sourceRoot":"","sources":["../src/rfc9457.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,sBAAsB,GAAG,MAAM,CAAC,wBAAwB,CAAC,CAAC;AAC1D,QAAA,yBAAyB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAC3D,QAAA,oBAAoB,GAAG,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ArgumentsHost } from '@nestjs/common';
|
|
2
|
+
import { BaseExceptionFilter, HttpAdapterHost } from '@nestjs/core';
|
|
3
|
+
import { ProblemDetailsFactory } from './problem-details.factory';
|
|
4
|
+
import { Rfc9457ModuleOptions } from './rfc9457.interfaces';
|
|
5
|
+
export declare class Rfc9457ExceptionFilter extends BaseExceptionFilter {
|
|
6
|
+
private readonly factory;
|
|
7
|
+
private readonly options;
|
|
8
|
+
private readonly adapterHost;
|
|
9
|
+
constructor(factory: ProblemDetailsFactory, options: Rfc9457ModuleOptions, adapterHost: HttpAdapterHost);
|
|
10
|
+
catch(exception: unknown, host: ArgumentsHost): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Rfc9457ExceptionFilter = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const core_1 = require("@nestjs/core");
|
|
18
|
+
const problem_details_factory_1 = require("./problem-details.factory");
|
|
19
|
+
const rfc9457_constants_1 = require("./rfc9457.constants");
|
|
20
|
+
let Rfc9457ExceptionFilter = class Rfc9457ExceptionFilter extends core_1.BaseExceptionFilter {
|
|
21
|
+
constructor(factory, options, adapterHost) {
|
|
22
|
+
super(adapterHost.httpAdapter);
|
|
23
|
+
this.factory = factory;
|
|
24
|
+
this.options = options;
|
|
25
|
+
this.adapterHost = adapterHost;
|
|
26
|
+
}
|
|
27
|
+
catch(exception, host) {
|
|
28
|
+
if (host.getType() !== 'http') {
|
|
29
|
+
super.catch(exception, host);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const isHttpException = exception instanceof common_1.HttpException;
|
|
33
|
+
if (this.options.exceptionMapper) {
|
|
34
|
+
const ctx = host.switchToHttp();
|
|
35
|
+
const request = ctx.getRequest();
|
|
36
|
+
const mapped = this.options.exceptionMapper(exception, request);
|
|
37
|
+
if (mapped) {
|
|
38
|
+
const response = ctx.getResponse();
|
|
39
|
+
const { status, body } = this.factory.createFromMapped(mapped, exception, request);
|
|
40
|
+
const httpAdapter = this.adapterHost.httpAdapter;
|
|
41
|
+
httpAdapter.setHeader(response, 'Content-Type', rfc9457_constants_1.PROBLEM_CONTENT_TYPE);
|
|
42
|
+
httpAdapter.reply(response, body, status);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (!isHttpException && !this.options.catchAllExceptions) {
|
|
47
|
+
super.catch(exception, host);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const ctx = host.switchToHttp();
|
|
51
|
+
const request = ctx.getRequest();
|
|
52
|
+
const response = ctx.getResponse();
|
|
53
|
+
const { status, body } = this.factory.create(exception, request, { skipMapper: true });
|
|
54
|
+
const httpAdapter = this.adapterHost.httpAdapter;
|
|
55
|
+
httpAdapter.setHeader(response, 'Content-Type', rfc9457_constants_1.PROBLEM_CONTENT_TYPE);
|
|
56
|
+
httpAdapter.reply(response, body, status);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
exports.Rfc9457ExceptionFilter = Rfc9457ExceptionFilter;
|
|
60
|
+
exports.Rfc9457ExceptionFilter = Rfc9457ExceptionFilter = __decorate([
|
|
61
|
+
(0, common_1.Catch)(),
|
|
62
|
+
__param(1, (0, common_1.Inject)(rfc9457_constants_1.RFC9457_MODULE_OPTIONS)),
|
|
63
|
+
__metadata("design:paramtypes", [problem_details_factory_1.ProblemDetailsFactory, Object, core_1.HttpAdapterHost])
|
|
64
|
+
], Rfc9457ExceptionFilter);
|
|
65
|
+
//# sourceMappingURL=rfc9457.exception-filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rfc9457.exception-filter.js","sourceRoot":"","sources":["../src/rfc9457.exception-filter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA6E;AAC7E,uCAAoE;AACpE,uEAAkE;AAClE,2DAAmF;AAI5E,IAAM,sBAAsB,GAA5B,MAAM,sBAAuB,SAAQ,0BAAmB;IAC7D,YACmB,OAA8B,EACE,OAA6B,EAC7D,WAA4B;QAE7C,KAAK,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;QAJd,YAAO,GAAP,OAAO,CAAuB;QACE,YAAO,GAAP,OAAO,CAAsB;QAC7D,gBAAW,GAAX,WAAW,CAAiB;IAG/C,CAAC;IAED,KAAK,CAAC,SAAkB,EAAE,I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W,EAAE,CAAC;QAEnC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;QACvF,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC;QACjD,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE,cAAc,EAAE,wCAAoB,CAAC,CAAC;QACtE,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IAC5C,CAAC;CACF,CAAA;AAlDY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,cAAK,GAAE;IAIH,WAAA,IAAA,eAAM,EAAC,0CAAsB,CAAC,CAAA;qCADL,+CAAqB,UAEjB,sBAAe;GAJpC,sBAAsB,CAkDlC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Type } from '@nestjs/common';
|
|
2
|
+
export interface Rfc9457Request {
|
|
3
|
+
url: string;
|
|
4
|
+
method: string;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
export interface ProblemDetail {
|
|
8
|
+
type?: string;
|
|
9
|
+
title?: string;
|
|
10
|
+
status?: number;
|
|
11
|
+
detail?: string;
|
|
12
|
+
instance?: string;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
export interface ProblemTypeMetadata {
|
|
16
|
+
type?: string;
|
|
17
|
+
title?: string;
|
|
18
|
+
status?: number;
|
|
19
|
+
}
|
|
20
|
+
export type InstanceStrategy = 'request-uri' | 'uuid' | 'none' | ((request: Rfc9457Request, exception: unknown) => string | undefined);
|
|
21
|
+
export interface Rfc9457ModuleOptions {
|
|
22
|
+
typeBaseUri?: string;
|
|
23
|
+
instanceStrategy?: InstanceStrategy;
|
|
24
|
+
catchAllExceptions?: boolean;
|
|
25
|
+
exceptionMapper?: (exception: unknown, request: Rfc9457Request) => ProblemDetail | null;
|
|
26
|
+
validationExceptionMapper?: (messages: string[], request: Rfc9457Request) => ProblemDetail;
|
|
27
|
+
}
|
|
28
|
+
export interface Rfc9457OptionsFactory {
|
|
29
|
+
createRfc9457Options(): Promise<Rfc9457ModuleOptions> | Rfc9457ModuleOptions;
|
|
30
|
+
}
|
|
31
|
+
export interface Rfc9457AsyncModuleOptions {
|
|
32
|
+
imports?: any[];
|
|
33
|
+
useFactory?: (...args: any[]) => Promise<Rfc9457ModuleOptions> | Rfc9457ModuleOptions;
|
|
34
|
+
inject?: any[];
|
|
35
|
+
useClass?: Type<Rfc9457OptionsFactory>;
|
|
36
|
+
useExisting?: Type<Rfc9457OptionsFactory>;
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rfc9457.interfaces.js","sourceRoot":"","sources":["../src/rfc9457.interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { Rfc9457AsyncModuleOptions, Rfc9457ModuleOptions } from './rfc9457.interfaces';
|
|
3
|
+
export declare class Rfc9457Module {
|
|
4
|
+
static forRoot(options?: Rfc9457ModuleOptions): DynamicModule;
|
|
5
|
+
static forRootAsync(options: Rfc9457AsyncModuleOptions): DynamicModule;
|
|
6
|
+
private static createAsyncProviders;
|
|
7
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var Rfc9457Module_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.Rfc9457Module = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const core_1 = require("@nestjs/core");
|
|
13
|
+
const problem_details_factory_1 = require("./problem-details.factory");
|
|
14
|
+
const rfc9457_exception_filter_1 = require("./rfc9457.exception-filter");
|
|
15
|
+
const rfc9457_constants_1 = require("./rfc9457.constants");
|
|
16
|
+
let Rfc9457Module = Rfc9457Module_1 = class Rfc9457Module {
|
|
17
|
+
static forRoot(options = {}) {
|
|
18
|
+
return {
|
|
19
|
+
module: Rfc9457Module_1,
|
|
20
|
+
global: true,
|
|
21
|
+
providers: [
|
|
22
|
+
{
|
|
23
|
+
provide: rfc9457_constants_1.RFC9457_MODULE_OPTIONS,
|
|
24
|
+
useValue: options,
|
|
25
|
+
},
|
|
26
|
+
problem_details_factory_1.ProblemDetailsFactory,
|
|
27
|
+
rfc9457_exception_filter_1.Rfc9457ExceptionFilter,
|
|
28
|
+
{
|
|
29
|
+
provide: core_1.APP_FILTER,
|
|
30
|
+
useExisting: rfc9457_exception_filter_1.Rfc9457ExceptionFilter,
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
exports: [problem_details_factory_1.ProblemDetailsFactory, rfc9457_constants_1.RFC9457_MODULE_OPTIONS],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
static forRootAsync(options) {
|
|
37
|
+
const asyncProviders = this.createAsyncProviders(options);
|
|
38
|
+
return {
|
|
39
|
+
module: Rfc9457Module_1,
|
|
40
|
+
global: true,
|
|
41
|
+
imports: options.imports || [],
|
|
42
|
+
providers: [
|
|
43
|
+
...asyncProviders,
|
|
44
|
+
problem_details_factory_1.ProblemDetailsFactory,
|
|
45
|
+
rfc9457_exception_filter_1.Rfc9457ExceptionFilter,
|
|
46
|
+
{
|
|
47
|
+
provide: core_1.APP_FILTER,
|
|
48
|
+
useExisting: rfc9457_exception_filter_1.Rfc9457ExceptionFilter,
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
exports: [problem_details_factory_1.ProblemDetailsFactory, rfc9457_constants_1.RFC9457_MODULE_OPTIONS],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
static createAsyncProviders(options) {
|
|
55
|
+
if (options.useFactory) {
|
|
56
|
+
return [
|
|
57
|
+
{
|
|
58
|
+
provide: rfc9457_constants_1.RFC9457_MODULE_OPTIONS,
|
|
59
|
+
useFactory: options.useFactory,
|
|
60
|
+
inject: options.inject || [],
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
if (options.useClass) {
|
|
65
|
+
return [
|
|
66
|
+
{
|
|
67
|
+
provide: options.useClass,
|
|
68
|
+
useClass: options.useClass,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
provide: rfc9457_constants_1.RFC9457_MODULE_OPTIONS,
|
|
72
|
+
useFactory: (factory) => factory.createRfc9457Options(),
|
|
73
|
+
inject: [options.useClass],
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
if (options.useExisting) {
|
|
78
|
+
return [
|
|
79
|
+
{
|
|
80
|
+
provide: rfc9457_constants_1.RFC9457_MODULE_OPTIONS,
|
|
81
|
+
useFactory: (factory) => factory.createRfc9457Options(),
|
|
82
|
+
inject: [options.useExisting],
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
exports.Rfc9457Module = Rfc9457Module;
|
|
90
|
+
exports.Rfc9457Module = Rfc9457Module = Rfc9457Module_1 = __decorate([
|
|
91
|
+
(0, common_1.Module)({})
|
|
92
|
+
], Rfc9457Module);
|
|
93
|
+
//# sourceMappingURL=rfc9457.module.js.map
|
|
@@ -0,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BAC7B;aACF,CAAC;QACJ,CAAC;QACD,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;YACrB,OAAO;gBACL;oBACE,OAAO,EAAE,OAAO,CAAC,QAAQ;oBACzB,QAAQ,EAAE,OAAO,CAAC,QAAQ;iBAC3B;gBACD;oBACE,OAAO,EAAE,0CAAsB;oBAC/B,UAAU,EAAE,CAAC,OAA8B,EAAE,EAAE,CAAC,OAAO,CAAC,oBAAoB,EAAE;oBAC9E,MAAM,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC;iBAC3B;aACF,CAAC;QACJ,CAAC;QACD,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;YACxB,OAAO;gBACL;oBACE,OAAO,EAAE,0CAAsB;oBAC/B,UAAU,EAAE,CAAC,OAA8B,EAAE,EAAE,CAAC,OAAO,CAAC,oBAAoB,EAAE;oBAC9E,MAAM,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC;iBAC9B;aACF,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;CACF,CAAA;AA1EY,sCAAa;wBAAb,aAAa;IADzB,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,aAAa,CA0EzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function toSlug(phrase: string): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toSlug = toSlug;
|
|
4
|
+
function toSlug(phrase) {
|
|
5
|
+
return phrase
|
|
6
|
+
.trim()
|
|
7
|
+
.toLowerCase()
|
|
8
|
+
.replace(/[^a-z0-9\s-]/g, '')
|
|
9
|
+
.replace(/\s+/g, '-')
|
|
10
|
+
.replace(/-+/g, '-')
|
|
11
|
+
.replace(/^-|-$/g, '');
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=slug.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slug.js","sourceRoot":"","sources":["../../src/utils/slug.ts"],"names":[],"mappings":";;AAKA,wBAQC;AARD,SAAgB,MAAM,CAAC,MAAc;IACnC,OAAO,MAAM;SACV,IAAI,EAAE;SACN,WAAW,EAAE;SACb,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC;SAC5B,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRfc9457ValidationPipeExceptionFactory = createRfc9457ValidationPipeExceptionFactory;
|
|
4
|
+
const rfc9457_validation_exception_1 = require("./rfc9457-validation.exception");
|
|
5
|
+
function createRfc9457ValidationPipeExceptionFactory() {
|
|
6
|
+
return (errors) => {
|
|
7
|
+
return new rfc9457_validation_exception_1.Rfc9457ValidationException(errors);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=rfc9457-validation-pipe-exception.factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rfc9457-validation-pipe-exception.factory.js","sourceRoot":"","sources":["../../src/validation/rfc9457-validation-pipe-exception.factory.ts"],"names":[],"mappings":";;AAEA,kGAMC;AARD,iFAA4E;AAE5E,SAAgB,2CAA2C;IAGzD,OAAO,CAAC,MAAiB,EAA8B,EAAE;QACvD,OAAO,IAAI,yDAA0B,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC,CAAC;AACJ,CAAC"}
|