@vritti/api-sdk 0.0.7 → 0.0.9
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 +267 -0
- package/dist/index.cjs +1006 -216
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +427 -29
- package/dist/index.d.ts +427 -29
- package/dist/index.js +993 -215
- package/dist/index.js.map +1 -1
- package/package.json +9 -5
package/dist/index.cjs
CHANGED
|
@@ -36,13 +36,19 @@ __export(index_exports, {
|
|
|
36
36
|
BadRequestException: () => BadRequestException,
|
|
37
37
|
BaseFieldException: () => BaseFieldException,
|
|
38
38
|
ConflictException: () => ConflictException,
|
|
39
|
+
CorrelationIdMiddleware: () => CorrelationIdMiddleware,
|
|
39
40
|
CsrfGuard: () => CsrfGuard,
|
|
41
|
+
DEFAULT_CORRELATION_HEADER: () => DEFAULT_CORRELATION_HEADER,
|
|
40
42
|
DatabaseModule: () => DatabaseModule,
|
|
41
43
|
ForbiddenException: () => ForbiddenException2,
|
|
42
44
|
GoneException: () => GoneException,
|
|
43
45
|
HttpExceptionFilter: () => HttpExceptionFilter,
|
|
46
|
+
HttpLoggerInterceptor: () => HttpLoggerInterceptor,
|
|
44
47
|
HttpModule: () => HttpModule,
|
|
45
48
|
InternalServerErrorException: () => InternalServerErrorException3,
|
|
49
|
+
LOGGER_MODULE_OPTIONS: () => LOGGER_MODULE_OPTIONS,
|
|
50
|
+
LoggerModule: () => LoggerModule,
|
|
51
|
+
LoggerService: () => LoggerService2,
|
|
46
52
|
MethodNotAllowedException: () => MethodNotAllowedException,
|
|
47
53
|
NotAcceptableException: () => NotAcceptableException,
|
|
48
54
|
NotFoundException: () => NotFoundException,
|
|
@@ -64,7 +70,13 @@ __export(index_exports, {
|
|
|
64
70
|
UnsupportedMediaTypeException: () => UnsupportedMediaTypeException,
|
|
65
71
|
ValidationException: () => ValidationException,
|
|
66
72
|
VrittiAuthGuard: () => VrittiAuthGuard,
|
|
67
|
-
|
|
73
|
+
addCorrelationIdToResponse: () => addCorrelationIdToResponse,
|
|
74
|
+
correlationStorage: () => correlationStorage,
|
|
75
|
+
generateCorrelationId: () => generateCorrelationId,
|
|
76
|
+
getCorrelationContext: () => getCorrelationContext,
|
|
77
|
+
getHttpStatusTitle: () => getHttpStatusTitle,
|
|
78
|
+
runWithCorrelationContext: () => runWithCorrelationContext,
|
|
79
|
+
updateCorrelationContext: () => updateCorrelationContext
|
|
68
80
|
});
|
|
69
81
|
module.exports = __toCommonJS(index_exports);
|
|
70
82
|
|
|
@@ -1943,7 +1955,7 @@ HttpModule = _ts_decorate12([
|
|
|
1943
1955
|
})
|
|
1944
1956
|
], HttpModule);
|
|
1945
1957
|
|
|
1946
|
-
// src/
|
|
1958
|
+
// src/filters/http-exception.filter.ts
|
|
1947
1959
|
var import_common18 = require("@nestjs/common");
|
|
1948
1960
|
function _ts_decorate13(decorators, target, key, desc) {
|
|
1949
1961
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -1952,140 +1964,26 @@ function _ts_decorate13(decorators, target, key, desc) {
|
|
|
1952
1964
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1953
1965
|
}
|
|
1954
1966
|
__name(_ts_decorate13, "_ts_decorate");
|
|
1955
|
-
var HttpExceptionFilter = class _HttpExceptionFilter {
|
|
1956
|
-
static {
|
|
1957
|
-
__name(this, "HttpExceptionFilter");
|
|
1958
|
-
}
|
|
1959
|
-
logger = new import_common18.Logger(_HttpExceptionFilter.name);
|
|
1960
|
-
catch(exception, host) {
|
|
1961
|
-
const ctx = host.switchToHttp();
|
|
1962
|
-
const reply = ctx.getResponse();
|
|
1963
|
-
const request = ctx.getRequest();
|
|
1964
|
-
let status = import_common18.HttpStatus.INTERNAL_SERVER_ERROR;
|
|
1965
|
-
let errors = [];
|
|
1966
|
-
let message;
|
|
1967
|
-
if (exception instanceof import_common18.HttpException) {
|
|
1968
|
-
status = exception.getStatus();
|
|
1969
|
-
const exceptionResponse = exception.getResponse();
|
|
1970
|
-
if (typeof exceptionResponse === "object" && exceptionResponse !== null) {
|
|
1971
|
-
const responseObj = exceptionResponse;
|
|
1972
|
-
if (Array.isArray(responseObj.message)) {
|
|
1973
|
-
errors = this.parseValidationErrors(responseObj.message);
|
|
1974
|
-
message = "Validation failed";
|
|
1975
|
-
} else if (responseObj.message) {
|
|
1976
|
-
errors = [
|
|
1977
|
-
{
|
|
1978
|
-
field: "general",
|
|
1979
|
-
message: responseObj.message
|
|
1980
|
-
}
|
|
1981
|
-
];
|
|
1982
|
-
message = responseObj.message;
|
|
1983
|
-
}
|
|
1984
|
-
} else if (typeof exceptionResponse === "string") {
|
|
1985
|
-
errors = [
|
|
1986
|
-
{
|
|
1987
|
-
field: "general",
|
|
1988
|
-
message: exceptionResponse
|
|
1989
|
-
}
|
|
1990
|
-
];
|
|
1991
|
-
message = exceptionResponse;
|
|
1992
|
-
}
|
|
1993
|
-
} else if (exception instanceof Error) {
|
|
1994
|
-
this.logger.error(`Unhandled error: ${exception.message}`, exception.stack);
|
|
1995
|
-
errors = [
|
|
1996
|
-
{
|
|
1997
|
-
field: "general",
|
|
1998
|
-
message: "Internal server error"
|
|
1999
|
-
}
|
|
2000
|
-
];
|
|
2001
|
-
message = "An unexpected error occurred";
|
|
2002
|
-
} else {
|
|
2003
|
-
this.logger.error("Unknown exception type", exception);
|
|
2004
|
-
errors = [
|
|
2005
|
-
{
|
|
2006
|
-
field: "general",
|
|
2007
|
-
message: "Internal server error"
|
|
2008
|
-
}
|
|
2009
|
-
];
|
|
2010
|
-
message = "An unexpected error occurred";
|
|
2011
|
-
}
|
|
2012
|
-
const errorResponse = {
|
|
2013
|
-
errors,
|
|
2014
|
-
message,
|
|
2015
|
-
statusCode: status,
|
|
2016
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2017
|
-
path: request.url
|
|
2018
|
-
};
|
|
2019
|
-
if (status >= 500) {
|
|
2020
|
-
this.logger.error(`HTTP ${status} Error: ${JSON.stringify(errorResponse)}`, exception instanceof Error ? exception.stack : void 0);
|
|
2021
|
-
} else {
|
|
2022
|
-
this.logger.warn(`HTTP ${status} Error: ${JSON.stringify(errorResponse)}`);
|
|
2023
|
-
}
|
|
2024
|
-
reply.status(status).send(errorResponse);
|
|
2025
|
-
}
|
|
2026
|
-
/**
|
|
2027
|
-
* Parse class-validator error messages into field-specific errors
|
|
2028
|
-
*/
|
|
2029
|
-
parseValidationErrors(messages) {
|
|
2030
|
-
const errors = [];
|
|
2031
|
-
for (const msg of messages) {
|
|
2032
|
-
if (typeof msg === "string") {
|
|
2033
|
-
errors.push({
|
|
2034
|
-
field: "general",
|
|
2035
|
-
message: msg
|
|
2036
|
-
});
|
|
2037
|
-
} else if (typeof msg === "object" && msg.property && msg.constraints) {
|
|
2038
|
-
const field = msg.property;
|
|
2039
|
-
const constraintMessages = Object.values(msg.constraints);
|
|
2040
|
-
for (const constraintMsg of constraintMessages) {
|
|
2041
|
-
errors.push({
|
|
2042
|
-
field,
|
|
2043
|
-
message: constraintMsg
|
|
2044
|
-
});
|
|
2045
|
-
}
|
|
2046
|
-
}
|
|
2047
|
-
}
|
|
2048
|
-
return errors.length > 0 ? errors : [
|
|
2049
|
-
{
|
|
2050
|
-
field: "general",
|
|
2051
|
-
message: "Validation failed"
|
|
2052
|
-
}
|
|
2053
|
-
];
|
|
2054
|
-
}
|
|
2055
|
-
};
|
|
2056
|
-
HttpExceptionFilter = _ts_decorate13([
|
|
2057
|
-
(0, import_common18.Catch)()
|
|
2058
|
-
], HttpExceptionFilter);
|
|
2059
|
-
|
|
2060
|
-
// src/filters/http-exception.filter.ts
|
|
2061
|
-
var import_common19 = require("@nestjs/common");
|
|
2062
|
-
function _ts_decorate14(decorators, target, key, desc) {
|
|
2063
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2064
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2065
|
-
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;
|
|
2066
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2067
|
-
}
|
|
2068
|
-
__name(_ts_decorate14, "_ts_decorate");
|
|
2069
1967
|
function getHttpStatusTitle(status) {
|
|
2070
|
-
const enumKey = Object.entries(
|
|
1968
|
+
const enumKey = Object.entries(import_common18.HttpStatus).find(([key, value]) => value === status && isNaN(Number(key)))?.[0];
|
|
2071
1969
|
if (!enumKey) {
|
|
2072
1970
|
return "Error";
|
|
2073
1971
|
}
|
|
2074
1972
|
return enumKey.split("_").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
2075
1973
|
}
|
|
2076
1974
|
__name(getHttpStatusTitle, "getHttpStatusTitle");
|
|
2077
|
-
var
|
|
1975
|
+
var HttpExceptionFilter = class _HttpExceptionFilter {
|
|
2078
1976
|
static {
|
|
2079
1977
|
__name(this, "HttpExceptionFilter");
|
|
2080
1978
|
}
|
|
2081
|
-
logger = new
|
|
1979
|
+
logger = new import_common18.Logger(_HttpExceptionFilter.name);
|
|
2082
1980
|
catch(exception, host) {
|
|
2083
1981
|
const ctx = host.switchToHttp();
|
|
2084
1982
|
const response = ctx.getResponse();
|
|
2085
|
-
let status =
|
|
1983
|
+
let status = import_common18.HttpStatus.INTERNAL_SERVER_ERROR;
|
|
2086
1984
|
let errors = [];
|
|
2087
1985
|
let detail = "Internal server error";
|
|
2088
|
-
if (exception instanceof
|
|
1986
|
+
if (exception instanceof import_common18.HttpException) {
|
|
2089
1987
|
status = exception.getStatus();
|
|
2090
1988
|
const exceptionResponse = exception.getResponse();
|
|
2091
1989
|
if (typeof exceptionResponse === "object" && exceptionResponse !== null) {
|
|
@@ -2123,7 +2021,9 @@ var HttpExceptionFilter2 = class _HttpExceptionFilter {
|
|
|
2123
2021
|
detail = exceptionResponse;
|
|
2124
2022
|
}
|
|
2125
2023
|
} else {
|
|
2126
|
-
|
|
2024
|
+
const errorMessage = exception instanceof Error ? exception.message : "Unknown error";
|
|
2025
|
+
const stack = exception instanceof Error ? exception.stack : void 0;
|
|
2026
|
+
this.logger.error(`Unexpected error: ${errorMessage}`, stack);
|
|
2127
2027
|
errors = [
|
|
2128
2028
|
{
|
|
2129
2029
|
message: "An unexpected error occurred"
|
|
@@ -2139,13 +2039,13 @@ var HttpExceptionFilter2 = class _HttpExceptionFilter {
|
|
|
2139
2039
|
response.status(status).send(problemDetails);
|
|
2140
2040
|
}
|
|
2141
2041
|
};
|
|
2142
|
-
|
|
2143
|
-
(0,
|
|
2144
|
-
],
|
|
2042
|
+
HttpExceptionFilter = _ts_decorate13([
|
|
2043
|
+
(0, import_common18.Catch)()
|
|
2044
|
+
], HttpExceptionFilter);
|
|
2145
2045
|
|
|
2146
2046
|
// src/exceptions/base-field.exception.ts
|
|
2147
|
-
var
|
|
2148
|
-
var BaseFieldException = class extends
|
|
2047
|
+
var import_common19 = require("@nestjs/common");
|
|
2048
|
+
var BaseFieldException = class extends import_common19.HttpException {
|
|
2149
2049
|
static {
|
|
2150
2050
|
__name(this, "BaseFieldException");
|
|
2151
2051
|
}
|
|
@@ -2155,7 +2055,7 @@ var BaseFieldException = class extends import_common20.HttpException {
|
|
|
2155
2055
|
let finalDetail;
|
|
2156
2056
|
if (Array.isArray(statusOrMessageOrErrors)) {
|
|
2157
2057
|
errors = statusOrMessageOrErrors;
|
|
2158
|
-
httpStatus = messageOrStatus ||
|
|
2058
|
+
httpStatus = messageOrStatus || import_common19.HttpStatus.BAD_REQUEST;
|
|
2159
2059
|
finalDetail = typeof statusOrDetail === "string" ? statusOrDetail : void 0;
|
|
2160
2060
|
} else if (typeof statusOrMessageOrErrors === "string" && typeof messageOrStatus === "string") {
|
|
2161
2061
|
errors = [
|
|
@@ -2194,338 +2094,1216 @@ var BaseFieldException = class extends import_common20.HttpException {
|
|
|
2194
2094
|
};
|
|
2195
2095
|
|
|
2196
2096
|
// src/exceptions/bad-request.exception.ts
|
|
2197
|
-
var
|
|
2097
|
+
var import_common20 = require("@nestjs/common");
|
|
2198
2098
|
var BadRequestException = class extends BaseFieldException {
|
|
2199
2099
|
static {
|
|
2200
2100
|
__name(this, "BadRequestException");
|
|
2201
2101
|
}
|
|
2202
2102
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2203
2103
|
if (Array.isArray(messageOrField)) {
|
|
2204
|
-
super(messageOrField,
|
|
2104
|
+
super(messageOrField, import_common20.HttpStatus.BAD_REQUEST, fieldMessageOrDetail);
|
|
2205
2105
|
} else if (detail !== void 0) {
|
|
2206
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2106
|
+
super(messageOrField, fieldMessageOrDetail, import_common20.HttpStatus.BAD_REQUEST, detail);
|
|
2207
2107
|
} else if (fieldMessageOrDetail) {
|
|
2208
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2108
|
+
super(messageOrField, fieldMessageOrDetail, import_common20.HttpStatus.BAD_REQUEST);
|
|
2209
2109
|
} else {
|
|
2210
|
-
super(messageOrField,
|
|
2110
|
+
super(messageOrField, import_common20.HttpStatus.BAD_REQUEST);
|
|
2211
2111
|
}
|
|
2212
2112
|
}
|
|
2213
2113
|
};
|
|
2214
2114
|
|
|
2215
2115
|
// src/exceptions/unauthorized.exception.ts
|
|
2216
|
-
var
|
|
2116
|
+
var import_common21 = require("@nestjs/common");
|
|
2217
2117
|
var UnauthorizedException4 = class extends BaseFieldException {
|
|
2218
2118
|
static {
|
|
2219
2119
|
__name(this, "UnauthorizedException");
|
|
2220
2120
|
}
|
|
2221
2121
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2222
2122
|
if (Array.isArray(messageOrField)) {
|
|
2223
|
-
super(messageOrField,
|
|
2123
|
+
super(messageOrField, import_common21.HttpStatus.UNAUTHORIZED, fieldMessageOrDetail);
|
|
2224
2124
|
} else if (detail !== void 0) {
|
|
2225
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2125
|
+
super(messageOrField, fieldMessageOrDetail, import_common21.HttpStatus.UNAUTHORIZED, detail);
|
|
2226
2126
|
} else if (fieldMessageOrDetail) {
|
|
2227
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2127
|
+
super(messageOrField, fieldMessageOrDetail, import_common21.HttpStatus.UNAUTHORIZED);
|
|
2228
2128
|
} else {
|
|
2229
|
-
super(messageOrField,
|
|
2129
|
+
super(messageOrField, import_common21.HttpStatus.UNAUTHORIZED);
|
|
2230
2130
|
}
|
|
2231
2131
|
}
|
|
2232
2132
|
};
|
|
2233
2133
|
|
|
2234
2134
|
// src/exceptions/forbidden.exception.ts
|
|
2235
|
-
var
|
|
2135
|
+
var import_common22 = require("@nestjs/common");
|
|
2236
2136
|
var ForbiddenException2 = class extends BaseFieldException {
|
|
2237
2137
|
static {
|
|
2238
2138
|
__name(this, "ForbiddenException");
|
|
2239
2139
|
}
|
|
2240
2140
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2241
2141
|
if (Array.isArray(messageOrField)) {
|
|
2242
|
-
super(messageOrField,
|
|
2142
|
+
super(messageOrField, import_common22.HttpStatus.FORBIDDEN, fieldMessageOrDetail);
|
|
2243
2143
|
} else if (detail !== void 0) {
|
|
2244
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2144
|
+
super(messageOrField, fieldMessageOrDetail, import_common22.HttpStatus.FORBIDDEN, detail);
|
|
2245
2145
|
} else if (fieldMessageOrDetail) {
|
|
2246
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2146
|
+
super(messageOrField, fieldMessageOrDetail, import_common22.HttpStatus.FORBIDDEN);
|
|
2247
2147
|
} else {
|
|
2248
|
-
super(messageOrField,
|
|
2148
|
+
super(messageOrField, import_common22.HttpStatus.FORBIDDEN);
|
|
2249
2149
|
}
|
|
2250
2150
|
}
|
|
2251
2151
|
};
|
|
2252
2152
|
|
|
2253
2153
|
// src/exceptions/not-found.exception.ts
|
|
2254
|
-
var
|
|
2154
|
+
var import_common23 = require("@nestjs/common");
|
|
2255
2155
|
var NotFoundException = class extends BaseFieldException {
|
|
2256
2156
|
static {
|
|
2257
2157
|
__name(this, "NotFoundException");
|
|
2258
2158
|
}
|
|
2259
2159
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2260
2160
|
if (Array.isArray(messageOrField)) {
|
|
2261
|
-
super(messageOrField,
|
|
2161
|
+
super(messageOrField, import_common23.HttpStatus.NOT_FOUND, fieldMessageOrDetail);
|
|
2262
2162
|
} else if (detail !== void 0) {
|
|
2263
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2163
|
+
super(messageOrField, fieldMessageOrDetail, import_common23.HttpStatus.NOT_FOUND, detail);
|
|
2264
2164
|
} else if (fieldMessageOrDetail) {
|
|
2265
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2165
|
+
super(messageOrField, fieldMessageOrDetail, import_common23.HttpStatus.NOT_FOUND);
|
|
2266
2166
|
} else {
|
|
2267
|
-
super(messageOrField,
|
|
2167
|
+
super(messageOrField, import_common23.HttpStatus.NOT_FOUND);
|
|
2268
2168
|
}
|
|
2269
2169
|
}
|
|
2270
2170
|
};
|
|
2271
2171
|
|
|
2272
2172
|
// src/exceptions/conflict.exception.ts
|
|
2273
|
-
var
|
|
2173
|
+
var import_common24 = require("@nestjs/common");
|
|
2274
2174
|
var ConflictException = class extends BaseFieldException {
|
|
2275
2175
|
static {
|
|
2276
2176
|
__name(this, "ConflictException");
|
|
2277
2177
|
}
|
|
2278
2178
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2279
2179
|
if (Array.isArray(messageOrField)) {
|
|
2280
|
-
super(messageOrField,
|
|
2180
|
+
super(messageOrField, import_common24.HttpStatus.CONFLICT, fieldMessageOrDetail);
|
|
2281
2181
|
} else if (detail !== void 0) {
|
|
2282
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2182
|
+
super(messageOrField, fieldMessageOrDetail, import_common24.HttpStatus.CONFLICT, detail);
|
|
2283
2183
|
} else if (fieldMessageOrDetail) {
|
|
2284
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2184
|
+
super(messageOrField, fieldMessageOrDetail, import_common24.HttpStatus.CONFLICT);
|
|
2285
2185
|
} else {
|
|
2286
|
-
super(messageOrField,
|
|
2186
|
+
super(messageOrField, import_common24.HttpStatus.CONFLICT);
|
|
2287
2187
|
}
|
|
2288
2188
|
}
|
|
2289
2189
|
};
|
|
2290
2190
|
|
|
2291
2191
|
// src/exceptions/internal-server-error.exception.ts
|
|
2292
|
-
var
|
|
2192
|
+
var import_common25 = require("@nestjs/common");
|
|
2293
2193
|
var InternalServerErrorException3 = class extends BaseFieldException {
|
|
2294
2194
|
static {
|
|
2295
2195
|
__name(this, "InternalServerErrorException");
|
|
2296
2196
|
}
|
|
2297
2197
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2298
2198
|
if (Array.isArray(messageOrField)) {
|
|
2299
|
-
super(messageOrField,
|
|
2199
|
+
super(messageOrField, import_common25.HttpStatus.INTERNAL_SERVER_ERROR, fieldMessageOrDetail);
|
|
2300
2200
|
} else if (detail !== void 0) {
|
|
2301
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2201
|
+
super(messageOrField, fieldMessageOrDetail, import_common25.HttpStatus.INTERNAL_SERVER_ERROR, detail);
|
|
2302
2202
|
} else if (fieldMessageOrDetail) {
|
|
2303
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2203
|
+
super(messageOrField, fieldMessageOrDetail, import_common25.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
2304
2204
|
} else {
|
|
2305
|
-
super(messageOrField,
|
|
2205
|
+
super(messageOrField, import_common25.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
2306
2206
|
}
|
|
2307
2207
|
}
|
|
2308
2208
|
};
|
|
2309
2209
|
|
|
2310
2210
|
// src/exceptions/validation.exception.ts
|
|
2311
|
-
var
|
|
2211
|
+
var import_common26 = require("@nestjs/common");
|
|
2312
2212
|
var ValidationException = class extends BaseFieldException {
|
|
2313
2213
|
static {
|
|
2314
2214
|
__name(this, "ValidationException");
|
|
2315
2215
|
}
|
|
2316
2216
|
constructor(errors, detail) {
|
|
2317
|
-
super(errors,
|
|
2217
|
+
super(errors, import_common26.HttpStatus.BAD_REQUEST, detail);
|
|
2318
2218
|
}
|
|
2319
2219
|
};
|
|
2320
2220
|
|
|
2321
2221
|
// src/exceptions/unprocessable-entity.exception.ts
|
|
2322
|
-
var
|
|
2222
|
+
var import_common27 = require("@nestjs/common");
|
|
2323
2223
|
var UnprocessableEntityException = class extends BaseFieldException {
|
|
2324
2224
|
static {
|
|
2325
2225
|
__name(this, "UnprocessableEntityException");
|
|
2326
2226
|
}
|
|
2327
2227
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2328
2228
|
if (Array.isArray(messageOrField)) {
|
|
2329
|
-
super(messageOrField,
|
|
2229
|
+
super(messageOrField, import_common27.HttpStatus.UNPROCESSABLE_ENTITY, fieldMessageOrDetail);
|
|
2330
2230
|
} else if (detail !== void 0) {
|
|
2331
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2231
|
+
super(messageOrField, fieldMessageOrDetail, import_common27.HttpStatus.UNPROCESSABLE_ENTITY, detail);
|
|
2332
2232
|
} else if (fieldMessageOrDetail) {
|
|
2333
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2233
|
+
super(messageOrField, fieldMessageOrDetail, import_common27.HttpStatus.UNPROCESSABLE_ENTITY);
|
|
2334
2234
|
} else {
|
|
2335
|
-
super(messageOrField,
|
|
2235
|
+
super(messageOrField, import_common27.HttpStatus.UNPROCESSABLE_ENTITY);
|
|
2336
2236
|
}
|
|
2337
2237
|
}
|
|
2338
2238
|
};
|
|
2339
2239
|
|
|
2340
2240
|
// src/exceptions/too-many-requests.exception.ts
|
|
2341
|
-
var
|
|
2241
|
+
var import_common28 = require("@nestjs/common");
|
|
2342
2242
|
var TooManyRequestsException = class extends BaseFieldException {
|
|
2343
2243
|
static {
|
|
2344
2244
|
__name(this, "TooManyRequestsException");
|
|
2345
2245
|
}
|
|
2346
2246
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2347
2247
|
if (Array.isArray(messageOrField)) {
|
|
2348
|
-
super(messageOrField,
|
|
2248
|
+
super(messageOrField, import_common28.HttpStatus.TOO_MANY_REQUESTS, fieldMessageOrDetail);
|
|
2349
2249
|
} else if (detail !== void 0) {
|
|
2350
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2250
|
+
super(messageOrField, fieldMessageOrDetail, import_common28.HttpStatus.TOO_MANY_REQUESTS, detail);
|
|
2351
2251
|
} else if (fieldMessageOrDetail) {
|
|
2352
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2252
|
+
super(messageOrField, fieldMessageOrDetail, import_common28.HttpStatus.TOO_MANY_REQUESTS);
|
|
2353
2253
|
} else {
|
|
2354
|
-
super(messageOrField,
|
|
2254
|
+
super(messageOrField, import_common28.HttpStatus.TOO_MANY_REQUESTS);
|
|
2355
2255
|
}
|
|
2356
2256
|
}
|
|
2357
2257
|
};
|
|
2358
2258
|
|
|
2359
2259
|
// src/exceptions/service-unavailable.exception.ts
|
|
2360
|
-
var
|
|
2260
|
+
var import_common29 = require("@nestjs/common");
|
|
2361
2261
|
var ServiceUnavailableException = class extends BaseFieldException {
|
|
2362
2262
|
static {
|
|
2363
2263
|
__name(this, "ServiceUnavailableException");
|
|
2364
2264
|
}
|
|
2365
2265
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2366
2266
|
if (Array.isArray(messageOrField)) {
|
|
2367
|
-
super(messageOrField,
|
|
2267
|
+
super(messageOrField, import_common29.HttpStatus.SERVICE_UNAVAILABLE, fieldMessageOrDetail);
|
|
2368
2268
|
} else if (detail !== void 0) {
|
|
2369
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2269
|
+
super(messageOrField, fieldMessageOrDetail, import_common29.HttpStatus.SERVICE_UNAVAILABLE, detail);
|
|
2370
2270
|
} else if (fieldMessageOrDetail) {
|
|
2371
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2271
|
+
super(messageOrField, fieldMessageOrDetail, import_common29.HttpStatus.SERVICE_UNAVAILABLE);
|
|
2372
2272
|
} else {
|
|
2373
|
-
super(messageOrField,
|
|
2273
|
+
super(messageOrField, import_common29.HttpStatus.SERVICE_UNAVAILABLE);
|
|
2374
2274
|
}
|
|
2375
2275
|
}
|
|
2376
2276
|
};
|
|
2377
2277
|
|
|
2378
2278
|
// src/exceptions/method-not-allowed.exception.ts
|
|
2379
|
-
var
|
|
2279
|
+
var import_common30 = require("@nestjs/common");
|
|
2380
2280
|
var MethodNotAllowedException = class extends BaseFieldException {
|
|
2381
2281
|
static {
|
|
2382
2282
|
__name(this, "MethodNotAllowedException");
|
|
2383
2283
|
}
|
|
2384
2284
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2385
2285
|
if (Array.isArray(messageOrField)) {
|
|
2386
|
-
super(messageOrField,
|
|
2286
|
+
super(messageOrField, import_common30.HttpStatus.METHOD_NOT_ALLOWED, fieldMessageOrDetail);
|
|
2387
2287
|
} else if (detail !== void 0) {
|
|
2388
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2288
|
+
super(messageOrField, fieldMessageOrDetail, import_common30.HttpStatus.METHOD_NOT_ALLOWED, detail);
|
|
2389
2289
|
} else if (fieldMessageOrDetail) {
|
|
2390
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2290
|
+
super(messageOrField, fieldMessageOrDetail, import_common30.HttpStatus.METHOD_NOT_ALLOWED);
|
|
2391
2291
|
} else {
|
|
2392
|
-
super(messageOrField,
|
|
2292
|
+
super(messageOrField, import_common30.HttpStatus.METHOD_NOT_ALLOWED);
|
|
2393
2293
|
}
|
|
2394
2294
|
}
|
|
2395
2295
|
};
|
|
2396
2296
|
|
|
2397
2297
|
// src/exceptions/gone.exception.ts
|
|
2398
|
-
var
|
|
2298
|
+
var import_common31 = require("@nestjs/common");
|
|
2399
2299
|
var GoneException = class extends BaseFieldException {
|
|
2400
2300
|
static {
|
|
2401
2301
|
__name(this, "GoneException");
|
|
2402
2302
|
}
|
|
2403
2303
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2404
2304
|
if (Array.isArray(messageOrField)) {
|
|
2405
|
-
super(messageOrField,
|
|
2305
|
+
super(messageOrField, import_common31.HttpStatus.GONE, fieldMessageOrDetail);
|
|
2406
2306
|
} else if (detail !== void 0) {
|
|
2407
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2307
|
+
super(messageOrField, fieldMessageOrDetail, import_common31.HttpStatus.GONE, detail);
|
|
2408
2308
|
} else if (fieldMessageOrDetail) {
|
|
2409
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2309
|
+
super(messageOrField, fieldMessageOrDetail, import_common31.HttpStatus.GONE);
|
|
2410
2310
|
} else {
|
|
2411
|
-
super(messageOrField,
|
|
2311
|
+
super(messageOrField, import_common31.HttpStatus.GONE);
|
|
2412
2312
|
}
|
|
2413
2313
|
}
|
|
2414
2314
|
};
|
|
2415
2315
|
|
|
2416
2316
|
// src/exceptions/not-acceptable.exception.ts
|
|
2417
|
-
var
|
|
2317
|
+
var import_common32 = require("@nestjs/common");
|
|
2418
2318
|
var NotAcceptableException = class extends BaseFieldException {
|
|
2419
2319
|
static {
|
|
2420
2320
|
__name(this, "NotAcceptableException");
|
|
2421
2321
|
}
|
|
2422
2322
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2423
2323
|
if (Array.isArray(messageOrField)) {
|
|
2424
|
-
super(messageOrField,
|
|
2324
|
+
super(messageOrField, import_common32.HttpStatus.NOT_ACCEPTABLE, fieldMessageOrDetail);
|
|
2425
2325
|
} else if (detail !== void 0) {
|
|
2426
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2326
|
+
super(messageOrField, fieldMessageOrDetail, import_common32.HttpStatus.NOT_ACCEPTABLE, detail);
|
|
2427
2327
|
} else if (fieldMessageOrDetail) {
|
|
2428
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2328
|
+
super(messageOrField, fieldMessageOrDetail, import_common32.HttpStatus.NOT_ACCEPTABLE);
|
|
2429
2329
|
} else {
|
|
2430
|
-
super(messageOrField,
|
|
2330
|
+
super(messageOrField, import_common32.HttpStatus.NOT_ACCEPTABLE);
|
|
2431
2331
|
}
|
|
2432
2332
|
}
|
|
2433
2333
|
};
|
|
2434
2334
|
|
|
2435
2335
|
// src/exceptions/request-timeout.exception.ts
|
|
2436
|
-
var
|
|
2336
|
+
var import_common33 = require("@nestjs/common");
|
|
2437
2337
|
var RequestTimeoutException = class extends BaseFieldException {
|
|
2438
2338
|
static {
|
|
2439
2339
|
__name(this, "RequestTimeoutException");
|
|
2440
2340
|
}
|
|
2441
2341
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2442
2342
|
if (Array.isArray(messageOrField)) {
|
|
2443
|
-
super(messageOrField,
|
|
2343
|
+
super(messageOrField, import_common33.HttpStatus.REQUEST_TIMEOUT, fieldMessageOrDetail);
|
|
2444
2344
|
} else if (detail !== void 0) {
|
|
2445
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2345
|
+
super(messageOrField, fieldMessageOrDetail, import_common33.HttpStatus.REQUEST_TIMEOUT, detail);
|
|
2446
2346
|
} else if (fieldMessageOrDetail) {
|
|
2447
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2347
|
+
super(messageOrField, fieldMessageOrDetail, import_common33.HttpStatus.REQUEST_TIMEOUT);
|
|
2448
2348
|
} else {
|
|
2449
|
-
super(messageOrField,
|
|
2349
|
+
super(messageOrField, import_common33.HttpStatus.REQUEST_TIMEOUT);
|
|
2450
2350
|
}
|
|
2451
2351
|
}
|
|
2452
2352
|
};
|
|
2453
2353
|
|
|
2454
2354
|
// src/exceptions/payload-too-large.exception.ts
|
|
2455
|
-
var
|
|
2355
|
+
var import_common34 = require("@nestjs/common");
|
|
2456
2356
|
var PayloadTooLargeException = class extends BaseFieldException {
|
|
2457
2357
|
static {
|
|
2458
2358
|
__name(this, "PayloadTooLargeException");
|
|
2459
2359
|
}
|
|
2460
2360
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2461
2361
|
if (Array.isArray(messageOrField)) {
|
|
2462
|
-
super(messageOrField,
|
|
2362
|
+
super(messageOrField, import_common34.HttpStatus.PAYLOAD_TOO_LARGE, fieldMessageOrDetail);
|
|
2463
2363
|
} else if (detail !== void 0) {
|
|
2464
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2364
|
+
super(messageOrField, fieldMessageOrDetail, import_common34.HttpStatus.PAYLOAD_TOO_LARGE, detail);
|
|
2465
2365
|
} else if (fieldMessageOrDetail) {
|
|
2466
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2366
|
+
super(messageOrField, fieldMessageOrDetail, import_common34.HttpStatus.PAYLOAD_TOO_LARGE);
|
|
2467
2367
|
} else {
|
|
2468
|
-
super(messageOrField,
|
|
2368
|
+
super(messageOrField, import_common34.HttpStatus.PAYLOAD_TOO_LARGE);
|
|
2469
2369
|
}
|
|
2470
2370
|
}
|
|
2471
2371
|
};
|
|
2472
2372
|
|
|
2473
2373
|
// src/exceptions/unsupported-media-type.exception.ts
|
|
2474
|
-
var
|
|
2374
|
+
var import_common35 = require("@nestjs/common");
|
|
2475
2375
|
var UnsupportedMediaTypeException = class extends BaseFieldException {
|
|
2476
2376
|
static {
|
|
2477
2377
|
__name(this, "UnsupportedMediaTypeException");
|
|
2478
2378
|
}
|
|
2479
2379
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2480
2380
|
if (Array.isArray(messageOrField)) {
|
|
2481
|
-
super(messageOrField,
|
|
2381
|
+
super(messageOrField, import_common35.HttpStatus.UNSUPPORTED_MEDIA_TYPE, fieldMessageOrDetail);
|
|
2482
2382
|
} else if (detail !== void 0) {
|
|
2483
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2383
|
+
super(messageOrField, fieldMessageOrDetail, import_common35.HttpStatus.UNSUPPORTED_MEDIA_TYPE, detail);
|
|
2484
2384
|
} else if (fieldMessageOrDetail) {
|
|
2485
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2385
|
+
super(messageOrField, fieldMessageOrDetail, import_common35.HttpStatus.UNSUPPORTED_MEDIA_TYPE);
|
|
2486
2386
|
} else {
|
|
2487
|
-
super(messageOrField,
|
|
2387
|
+
super(messageOrField, import_common35.HttpStatus.UNSUPPORTED_MEDIA_TYPE);
|
|
2488
2388
|
}
|
|
2489
2389
|
}
|
|
2490
2390
|
};
|
|
2491
2391
|
|
|
2492
2392
|
// src/exceptions/not-implemented.exception.ts
|
|
2493
|
-
var
|
|
2393
|
+
var import_common36 = require("@nestjs/common");
|
|
2494
2394
|
var NotImplementedException = class extends BaseFieldException {
|
|
2495
2395
|
static {
|
|
2496
2396
|
__name(this, "NotImplementedException");
|
|
2497
2397
|
}
|
|
2498
2398
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2499
2399
|
if (Array.isArray(messageOrField)) {
|
|
2500
|
-
super(messageOrField,
|
|
2400
|
+
super(messageOrField, import_common36.HttpStatus.NOT_IMPLEMENTED, fieldMessageOrDetail);
|
|
2501
2401
|
} else if (detail !== void 0) {
|
|
2502
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2402
|
+
super(messageOrField, fieldMessageOrDetail, import_common36.HttpStatus.NOT_IMPLEMENTED, detail);
|
|
2503
2403
|
} else if (fieldMessageOrDetail) {
|
|
2504
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2404
|
+
super(messageOrField, fieldMessageOrDetail, import_common36.HttpStatus.NOT_IMPLEMENTED);
|
|
2505
2405
|
} else {
|
|
2506
|
-
super(messageOrField,
|
|
2406
|
+
super(messageOrField, import_common36.HttpStatus.NOT_IMPLEMENTED);
|
|
2507
2407
|
}
|
|
2508
2408
|
}
|
|
2509
2409
|
};
|
|
2510
2410
|
|
|
2511
2411
|
// src/exceptions/bad-gateway.exception.ts
|
|
2512
|
-
var
|
|
2412
|
+
var import_common37 = require("@nestjs/common");
|
|
2513
2413
|
var BadGatewayException = class extends BaseFieldException {
|
|
2514
2414
|
static {
|
|
2515
2415
|
__name(this, "BadGatewayException");
|
|
2516
2416
|
}
|
|
2517
2417
|
constructor(messageOrField, fieldMessageOrDetail, detail) {
|
|
2518
2418
|
if (Array.isArray(messageOrField)) {
|
|
2519
|
-
super(messageOrField,
|
|
2419
|
+
super(messageOrField, import_common37.HttpStatus.BAD_GATEWAY, fieldMessageOrDetail);
|
|
2520
2420
|
} else if (detail !== void 0) {
|
|
2521
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2421
|
+
super(messageOrField, fieldMessageOrDetail, import_common37.HttpStatus.BAD_GATEWAY, detail);
|
|
2522
2422
|
} else if (fieldMessageOrDetail) {
|
|
2523
|
-
super(messageOrField, fieldMessageOrDetail,
|
|
2423
|
+
super(messageOrField, fieldMessageOrDetail, import_common37.HttpStatus.BAD_GATEWAY);
|
|
2524
2424
|
} else {
|
|
2525
|
-
super(messageOrField,
|
|
2425
|
+
super(messageOrField, import_common37.HttpStatus.BAD_GATEWAY);
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2428
|
+
};
|
|
2429
|
+
|
|
2430
|
+
// src/logger/logger.module.ts
|
|
2431
|
+
var import_common41 = require("@nestjs/common");
|
|
2432
|
+
|
|
2433
|
+
// src/logger/services/logger.service.ts
|
|
2434
|
+
var import_common38 = require("@nestjs/common");
|
|
2435
|
+
var import_winston = require("winston");
|
|
2436
|
+
var import_winston_daily_rotate_file = __toESM(require("winston-daily-rotate-file"), 1);
|
|
2437
|
+
|
|
2438
|
+
// src/logger/utils/index.ts
|
|
2439
|
+
var import_node_async_hooks = require("async_hooks");
|
|
2440
|
+
var import_node_crypto = require("crypto");
|
|
2441
|
+
var correlationStorage = new import_node_async_hooks.AsyncLocalStorage();
|
|
2442
|
+
function getCorrelationContext() {
|
|
2443
|
+
return correlationStorage.getStore();
|
|
2444
|
+
}
|
|
2445
|
+
__name(getCorrelationContext, "getCorrelationContext");
|
|
2446
|
+
function runWithCorrelationContext(context, callback) {
|
|
2447
|
+
return correlationStorage.run(context, callback);
|
|
2448
|
+
}
|
|
2449
|
+
__name(runWithCorrelationContext, "runWithCorrelationContext");
|
|
2450
|
+
function updateCorrelationContext(updates) {
|
|
2451
|
+
const context = correlationStorage.getStore();
|
|
2452
|
+
if (context) {
|
|
2453
|
+
Object.assign(context, updates);
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
__name(updateCorrelationContext, "updateCorrelationContext");
|
|
2457
|
+
var DEFAULT_CORRELATION_HEADER = "x-correlation-id";
|
|
2458
|
+
function generateCorrelationId() {
|
|
2459
|
+
return (0, import_node_crypto.randomUUID)();
|
|
2460
|
+
}
|
|
2461
|
+
__name(generateCorrelationId, "generateCorrelationId");
|
|
2462
|
+
function addCorrelationIdToResponse(reply, correlationId, headerName = DEFAULT_CORRELATION_HEADER) {
|
|
2463
|
+
if (typeof reply.header === "function") {
|
|
2464
|
+
reply.header(headerName, correlationId);
|
|
2465
|
+
} else if (reply.raw && typeof reply.raw.setHeader === "function") {
|
|
2466
|
+
reply.raw.setHeader(headerName, correlationId);
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
__name(addCorrelationIdToResponse, "addCorrelationIdToResponse");
|
|
2470
|
+
|
|
2471
|
+
// src/logger/services/logger.service.ts
|
|
2472
|
+
function _ts_decorate14(decorators, target, key, desc) {
|
|
2473
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2474
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2475
|
+
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;
|
|
2476
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2477
|
+
}
|
|
2478
|
+
__name(_ts_decorate14, "_ts_decorate");
|
|
2479
|
+
function _ts_metadata8(k, v) {
|
|
2480
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2481
|
+
}
|
|
2482
|
+
__name(_ts_metadata8, "_ts_metadata");
|
|
2483
|
+
function _ts_param4(paramIndex, decorator) {
|
|
2484
|
+
return function(target, key) {
|
|
2485
|
+
decorator(target, key, paramIndex);
|
|
2486
|
+
};
|
|
2487
|
+
}
|
|
2488
|
+
__name(_ts_param4, "_ts_param");
|
|
2489
|
+
var LoggerService2 = class _LoggerService {
|
|
2490
|
+
static {
|
|
2491
|
+
__name(this, "LoggerService");
|
|
2492
|
+
}
|
|
2493
|
+
defaultLogger;
|
|
2494
|
+
activeLogger;
|
|
2495
|
+
options;
|
|
2496
|
+
context;
|
|
2497
|
+
constructor(options = {}, defaultLogger) {
|
|
2498
|
+
this.defaultLogger = defaultLogger;
|
|
2499
|
+
this.options = options;
|
|
2500
|
+
const provider = options.provider ?? "winston";
|
|
2501
|
+
if (provider === "default") {
|
|
2502
|
+
if (!this.defaultLogger) {
|
|
2503
|
+
throw new Error("LoggerService: Default Logger not provided");
|
|
2504
|
+
}
|
|
2505
|
+
this.activeLogger = this.defaultLogger;
|
|
2506
|
+
} else {
|
|
2507
|
+
this.activeLogger = this.createWinstonLogger(options);
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2510
|
+
/**
|
|
2511
|
+
* Creates a Winston logger instance with inline configuration.
|
|
2512
|
+
* Consolidates winston-config.factory.ts logic.
|
|
2513
|
+
*/
|
|
2514
|
+
createWinstonLogger(opts) {
|
|
2515
|
+
const level = opts.level ?? "debug";
|
|
2516
|
+
const logFormat = opts.format ?? "text";
|
|
2517
|
+
const baseFormatters = [
|
|
2518
|
+
import_winston.format.timestamp({
|
|
2519
|
+
format: "YYYY-MM-DDTHH:mm:ss.SSSZ"
|
|
2520
|
+
}),
|
|
2521
|
+
import_winston.format.errors({
|
|
2522
|
+
stack: true
|
|
2523
|
+
})
|
|
2524
|
+
];
|
|
2525
|
+
const consoleTransport = logFormat === "json" ? new import_winston.transports.Console({
|
|
2526
|
+
level,
|
|
2527
|
+
format: import_winston.format.combine(...baseFormatters, import_winston.format.json())
|
|
2528
|
+
}) : new import_winston.transports.Console({
|
|
2529
|
+
level,
|
|
2530
|
+
format: import_winston.format.combine(...baseFormatters, import_winston.format.printf((info) => {
|
|
2531
|
+
const { timestamp, level: level2, message, context, correlationId, trace } = info;
|
|
2532
|
+
const parts = [
|
|
2533
|
+
timestamp,
|
|
2534
|
+
level2.toUpperCase().padEnd(7),
|
|
2535
|
+
correlationId ? `[${correlationId.toString().slice(-6)}]` : "",
|
|
2536
|
+
context ? `[${context}]` : "",
|
|
2537
|
+
message
|
|
2538
|
+
].filter(Boolean);
|
|
2539
|
+
let output = parts.join(" ");
|
|
2540
|
+
if (trace) {
|
|
2541
|
+
output += "\n" + trace;
|
|
2542
|
+
}
|
|
2543
|
+
return output;
|
|
2544
|
+
}), import_winston.format.colorize({
|
|
2545
|
+
all: true
|
|
2546
|
+
}))
|
|
2547
|
+
});
|
|
2548
|
+
const winstonTransports = [
|
|
2549
|
+
consoleTransport
|
|
2550
|
+
];
|
|
2551
|
+
if (opts.enableFileLogger) {
|
|
2552
|
+
const filePath = opts.filePath ?? "./logs";
|
|
2553
|
+
const maxFiles = opts.maxFiles ?? "14d";
|
|
2554
|
+
winstonTransports.push(new import_winston_daily_rotate_file.default({
|
|
2555
|
+
level,
|
|
2556
|
+
filename: `${filePath}/%DATE%-combined.log`,
|
|
2557
|
+
datePattern: "YYYY-MM-DD",
|
|
2558
|
+
maxSize: "20m",
|
|
2559
|
+
maxFiles,
|
|
2560
|
+
format: import_winston.format.combine(import_winston.format.timestamp(), import_winston.format.json())
|
|
2561
|
+
}), new import_winston_daily_rotate_file.default({
|
|
2562
|
+
level: "error",
|
|
2563
|
+
filename: `${filePath}/%DATE%-error.log`,
|
|
2564
|
+
datePattern: "YYYY-MM-DD",
|
|
2565
|
+
maxSize: "20m",
|
|
2566
|
+
maxFiles,
|
|
2567
|
+
format: import_winston.format.combine(import_winston.format.timestamp(), import_winston.format.json())
|
|
2568
|
+
}));
|
|
2569
|
+
}
|
|
2570
|
+
const config = {
|
|
2571
|
+
level,
|
|
2572
|
+
transports: winstonTransports,
|
|
2573
|
+
exitOnError: false
|
|
2574
|
+
};
|
|
2575
|
+
if (opts.defaultMeta || opts.appName) {
|
|
2576
|
+
config.defaultMeta = {
|
|
2577
|
+
...opts.defaultMeta,
|
|
2578
|
+
appName: opts.appName,
|
|
2579
|
+
environment: opts.environment
|
|
2580
|
+
};
|
|
2581
|
+
}
|
|
2582
|
+
return (0, import_winston.createLogger)(config);
|
|
2583
|
+
}
|
|
2584
|
+
// NestJS LoggerService interface methods
|
|
2585
|
+
log(message, context) {
|
|
2586
|
+
this._log("log", message, context);
|
|
2587
|
+
}
|
|
2588
|
+
error(message, trace, context) {
|
|
2589
|
+
this._log("error", message, context, trace);
|
|
2590
|
+
}
|
|
2591
|
+
warn(message, context) {
|
|
2592
|
+
this._log("warn", message, context);
|
|
2593
|
+
}
|
|
2594
|
+
debug(message, context) {
|
|
2595
|
+
this._log("debug", message, context);
|
|
2596
|
+
}
|
|
2597
|
+
verbose(message, context) {
|
|
2598
|
+
this._log("verbose", message, context);
|
|
2599
|
+
}
|
|
2600
|
+
setContext(context) {
|
|
2601
|
+
this.context = context;
|
|
2602
|
+
}
|
|
2603
|
+
/**
|
|
2604
|
+
* Unified internal logging method that handles both Winston and NestJS Logger.
|
|
2605
|
+
*/
|
|
2606
|
+
_log(level, message, context, trace) {
|
|
2607
|
+
const ctx = context ?? this.context;
|
|
2608
|
+
if ("format" in this.activeLogger && "transports" in this.activeLogger) {
|
|
2609
|
+
const winstonLogger = this.activeLogger;
|
|
2610
|
+
const winstonLevel = level === "log" ? "info" : level;
|
|
2611
|
+
const formattedMessage = this.formatMessage(message);
|
|
2612
|
+
const metadata = this.enrichMetadata({}, ctx, trace);
|
|
2613
|
+
winstonLogger.log({
|
|
2614
|
+
level: winstonLevel,
|
|
2615
|
+
message: formattedMessage,
|
|
2616
|
+
...metadata
|
|
2617
|
+
});
|
|
2618
|
+
} else {
|
|
2619
|
+
const nestLogger = this.activeLogger;
|
|
2620
|
+
if (level === "error" && trace) {
|
|
2621
|
+
ctx ? nestLogger.error(message, trace, ctx) : nestLogger.error(message, trace);
|
|
2622
|
+
} else if (level === "log") {
|
|
2623
|
+
ctx ? nestLogger.log(message, ctx) : nestLogger.log(message);
|
|
2624
|
+
} else if (level === "warn") {
|
|
2625
|
+
ctx ? nestLogger.warn(message, ctx) : nestLogger.warn(message);
|
|
2626
|
+
} else if (level === "debug" && nestLogger.debug) {
|
|
2627
|
+
ctx ? nestLogger.debug(message, ctx) : nestLogger.debug(message);
|
|
2628
|
+
} else if (level === "verbose" && nestLogger.verbose) {
|
|
2629
|
+
ctx ? nestLogger.verbose(message, ctx) : nestLogger.verbose(message);
|
|
2630
|
+
}
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
/**
|
|
2634
|
+
* Logs with custom metadata (Winston only).
|
|
2635
|
+
*/
|
|
2636
|
+
logWithMetadata(level, message, metadata, context) {
|
|
2637
|
+
const ctx = context ?? this.context;
|
|
2638
|
+
if ("format" in this.activeLogger && "transports" in this.activeLogger) {
|
|
2639
|
+
const winstonLogger = this.activeLogger;
|
|
2640
|
+
const winstonLevel = level === "log" ? "info" : level;
|
|
2641
|
+
winstonLogger.log({
|
|
2642
|
+
level: winstonLevel,
|
|
2643
|
+
message: this.formatMessage(message),
|
|
2644
|
+
...metadata
|
|
2645
|
+
});
|
|
2646
|
+
} else {
|
|
2647
|
+
const messageWithMeta = metadata ? `${message} ${JSON.stringify(metadata)}` : message;
|
|
2648
|
+
this[level](messageWithMeta, ctx);
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2651
|
+
formatMessage(message) {
|
|
2652
|
+
if (message instanceof Error) return message.message;
|
|
2653
|
+
if (typeof message === "object" && message !== null) {
|
|
2654
|
+
try {
|
|
2655
|
+
return JSON.stringify(message);
|
|
2656
|
+
} catch {
|
|
2657
|
+
return String(message);
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2660
|
+
return String(message);
|
|
2661
|
+
}
|
|
2662
|
+
/**
|
|
2663
|
+
* Enriches metadata with correlation context from AsyncLocalStorage.
|
|
2664
|
+
* Inline from winston-logger.service.ts
|
|
2665
|
+
*/
|
|
2666
|
+
enrichMetadata(metadata = {}, context, trace) {
|
|
2667
|
+
const enriched = {
|
|
2668
|
+
...metadata
|
|
2669
|
+
};
|
|
2670
|
+
if (context) enriched.context = context;
|
|
2671
|
+
const correlationContext = getCorrelationContext();
|
|
2672
|
+
if (correlationContext) {
|
|
2673
|
+
if (correlationContext.correlationId) enriched.correlationId = correlationContext.correlationId;
|
|
2674
|
+
for (const [key, value] of Object.entries(correlationContext)) {
|
|
2675
|
+
if (key !== "correlationId") {
|
|
2676
|
+
enriched[key] = value;
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
}
|
|
2680
|
+
if (trace) enriched.trace = trace;
|
|
2681
|
+
return enriched;
|
|
2682
|
+
}
|
|
2683
|
+
child(context) {
|
|
2684
|
+
const childLogger = new _LoggerService(this.options, this.defaultLogger);
|
|
2685
|
+
childLogger.setContext(context);
|
|
2686
|
+
return childLogger;
|
|
2687
|
+
}
|
|
2688
|
+
};
|
|
2689
|
+
LoggerService2 = _ts_decorate14([
|
|
2690
|
+
(0, import_common38.Injectable)(),
|
|
2691
|
+
_ts_param4(0, (0, import_common38.Optional)()),
|
|
2692
|
+
_ts_param4(1, (0, import_common38.Optional)()),
|
|
2693
|
+
_ts_metadata8("design:type", Function),
|
|
2694
|
+
_ts_metadata8("design:paramtypes", [
|
|
2695
|
+
typeof LoggerModuleOptions === "undefined" ? Object : LoggerModuleOptions,
|
|
2696
|
+
typeof import_common38.Logger === "undefined" ? Object : import_common38.Logger
|
|
2697
|
+
])
|
|
2698
|
+
], LoggerService2);
|
|
2699
|
+
|
|
2700
|
+
// src/logger/middleware/correlation-id.middleware.ts
|
|
2701
|
+
var import_common39 = require("@nestjs/common");
|
|
2702
|
+
function _ts_decorate15(decorators, target, key, desc) {
|
|
2703
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2704
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2705
|
+
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;
|
|
2706
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2707
|
+
}
|
|
2708
|
+
__name(_ts_decorate15, "_ts_decorate");
|
|
2709
|
+
function _ts_metadata9(k, v) {
|
|
2710
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2711
|
+
}
|
|
2712
|
+
__name(_ts_metadata9, "_ts_metadata");
|
|
2713
|
+
var CorrelationIdMiddleware = class {
|
|
2714
|
+
static {
|
|
2715
|
+
__name(this, "CorrelationIdMiddleware");
|
|
2716
|
+
}
|
|
2717
|
+
includeInResponse;
|
|
2718
|
+
responseHeader;
|
|
2719
|
+
constructor(options = {}) {
|
|
2720
|
+
this.includeInResponse = options.includeInResponse ?? true;
|
|
2721
|
+
this.responseHeader = options.responseHeader ?? DEFAULT_CORRELATION_HEADER;
|
|
2722
|
+
}
|
|
2723
|
+
/**
|
|
2724
|
+
* Middleware handler for processing requests.
|
|
2725
|
+
*/
|
|
2726
|
+
use(req, reply, next) {
|
|
2727
|
+
const correlationId = generateCorrelationId();
|
|
2728
|
+
if (this.includeInResponse) {
|
|
2729
|
+
addCorrelationIdToResponse(reply, correlationId, this.responseHeader);
|
|
2730
|
+
}
|
|
2731
|
+
runWithCorrelationContext({
|
|
2732
|
+
correlationId
|
|
2733
|
+
}, () => {
|
|
2734
|
+
next();
|
|
2735
|
+
});
|
|
2736
|
+
}
|
|
2737
|
+
/**
|
|
2738
|
+
* Fastify hook handler for onRequest.
|
|
2739
|
+
* This is an async function that returns a Promise, ensuring the AsyncLocalStorage
|
|
2740
|
+
* context persists throughout the entire request lifecycle.
|
|
2741
|
+
*/
|
|
2742
|
+
async onRequest(req, reply) {
|
|
2743
|
+
const correlationId = generateCorrelationId();
|
|
2744
|
+
if (this.includeInResponse) {
|
|
2745
|
+
addCorrelationIdToResponse(reply, correlationId, this.responseHeader);
|
|
2746
|
+
}
|
|
2747
|
+
const store = correlationStorage.getStore();
|
|
2748
|
+
if (!store) {
|
|
2749
|
+
correlationStorage.enterWith({
|
|
2750
|
+
correlationId
|
|
2751
|
+
});
|
|
2752
|
+
}
|
|
2753
|
+
}
|
|
2754
|
+
};
|
|
2755
|
+
CorrelationIdMiddleware = _ts_decorate15([
|
|
2756
|
+
(0, import_common39.Injectable)(),
|
|
2757
|
+
_ts_metadata9("design:type", Function),
|
|
2758
|
+
_ts_metadata9("design:paramtypes", [
|
|
2759
|
+
typeof CorrelationIdMiddlewareOptions === "undefined" ? Object : CorrelationIdMiddlewareOptions
|
|
2760
|
+
])
|
|
2761
|
+
], CorrelationIdMiddleware);
|
|
2762
|
+
|
|
2763
|
+
// src/logger/interceptors/http-logger.interceptor.ts
|
|
2764
|
+
var import_common40 = require("@nestjs/common");
|
|
2765
|
+
var import_operators2 = require("rxjs/operators");
|
|
2766
|
+
function _ts_decorate16(decorators, target, key, desc) {
|
|
2767
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2768
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2769
|
+
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;
|
|
2770
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2771
|
+
}
|
|
2772
|
+
__name(_ts_decorate16, "_ts_decorate");
|
|
2773
|
+
function _ts_metadata10(k, v) {
|
|
2774
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2775
|
+
}
|
|
2776
|
+
__name(_ts_metadata10, "_ts_metadata");
|
|
2777
|
+
function _ts_param5(paramIndex, decorator) {
|
|
2778
|
+
return function(target, key) {
|
|
2779
|
+
decorator(target, key, paramIndex);
|
|
2780
|
+
};
|
|
2781
|
+
}
|
|
2782
|
+
__name(_ts_param5, "_ts_param");
|
|
2783
|
+
var HttpLoggerInterceptor = class {
|
|
2784
|
+
static {
|
|
2785
|
+
__name(this, "HttpLoggerInterceptor");
|
|
2786
|
+
}
|
|
2787
|
+
logger;
|
|
2788
|
+
enableRequestLog;
|
|
2789
|
+
enableResponseLog;
|
|
2790
|
+
slowRequestThreshold;
|
|
2791
|
+
constructor(logger, options) {
|
|
2792
|
+
this.logger = logger;
|
|
2793
|
+
this.enableRequestLog = options?.enableRequestLog ?? true;
|
|
2794
|
+
this.enableResponseLog = options?.enableResponseLog ?? true;
|
|
2795
|
+
this.slowRequestThreshold = options?.slowRequestThreshold ?? 3e3;
|
|
2796
|
+
}
|
|
2797
|
+
intercept(context, next) {
|
|
2798
|
+
if (context.getType() !== "http") {
|
|
2799
|
+
return next.handle();
|
|
2800
|
+
}
|
|
2801
|
+
const httpContext = context.switchToHttp();
|
|
2802
|
+
const request = httpContext.getRequest();
|
|
2803
|
+
const response = httpContext.getResponse();
|
|
2804
|
+
const startTime = Date.now();
|
|
2805
|
+
if (this.enableRequestLog) {
|
|
2806
|
+
this.logRequest(request);
|
|
2807
|
+
}
|
|
2808
|
+
return next.handle().pipe((0, import_operators2.tap)(() => {
|
|
2809
|
+
if (this.enableResponseLog) {
|
|
2810
|
+
const duration = Date.now() - startTime;
|
|
2811
|
+
this.logResponse(request, response, duration);
|
|
2812
|
+
}
|
|
2813
|
+
}), (0, import_operators2.catchError)((error) => {
|
|
2814
|
+
const duration = Date.now() - startTime;
|
|
2815
|
+
this.logError(request, response, duration, error);
|
|
2816
|
+
throw error;
|
|
2817
|
+
}));
|
|
2818
|
+
}
|
|
2819
|
+
logRequest(request) {
|
|
2820
|
+
try {
|
|
2821
|
+
const correlationContext = getCorrelationContext();
|
|
2822
|
+
const metadata = {
|
|
2823
|
+
type: "http_request",
|
|
2824
|
+
method: request.method,
|
|
2825
|
+
url: request.url,
|
|
2826
|
+
correlationId: correlationContext?.correlationId,
|
|
2827
|
+
ip: request.ip,
|
|
2828
|
+
userAgent: request.headers["user-agent"]
|
|
2829
|
+
};
|
|
2830
|
+
this.logger.logWithMetadata("log", `Incoming ${request.method} ${request.url}`, metadata);
|
|
2831
|
+
} catch (error) {
|
|
2832
|
+
this.logger.error("Failed to log HTTP request", error.stack);
|
|
2833
|
+
}
|
|
2834
|
+
}
|
|
2835
|
+
logResponse(request, response, duration) {
|
|
2836
|
+
try {
|
|
2837
|
+
const correlationContext = getCorrelationContext();
|
|
2838
|
+
const statusCode = response.statusCode;
|
|
2839
|
+
const logLevel = statusCode >= 500 ? "error" : statusCode >= 400 ? "warn" : "log";
|
|
2840
|
+
const metadata = {
|
|
2841
|
+
type: "http_response",
|
|
2842
|
+
method: request.method,
|
|
2843
|
+
url: request.url,
|
|
2844
|
+
statusCode,
|
|
2845
|
+
duration,
|
|
2846
|
+
correlationId: correlationContext?.correlationId
|
|
2847
|
+
};
|
|
2848
|
+
if (duration > this.slowRequestThreshold) {
|
|
2849
|
+
metadata.slowRequest = true;
|
|
2850
|
+
}
|
|
2851
|
+
const message = metadata.slowRequest ? `SLOW ${request.method} ${request.url} ${statusCode} - ${duration}ms` : `${request.method} ${request.url} ${statusCode} - ${duration}ms`;
|
|
2852
|
+
this.logger.logWithMetadata(logLevel, message, metadata);
|
|
2853
|
+
} catch (error) {
|
|
2854
|
+
this.logger.error("Failed to log HTTP response", error.stack);
|
|
2855
|
+
}
|
|
2856
|
+
}
|
|
2857
|
+
logError(request, response, duration, error) {
|
|
2858
|
+
try {
|
|
2859
|
+
const correlationContext = getCorrelationContext();
|
|
2860
|
+
const statusCode = response.statusCode || 500;
|
|
2861
|
+
const metadata = {
|
|
2862
|
+
type: "http_error",
|
|
2863
|
+
method: request.method,
|
|
2864
|
+
url: request.url,
|
|
2865
|
+
statusCode,
|
|
2866
|
+
duration,
|
|
2867
|
+
correlationId: correlationContext?.correlationId,
|
|
2868
|
+
errorName: error?.name || "Error",
|
|
2869
|
+
errorMessage: error?.message || "Unknown error"
|
|
2870
|
+
};
|
|
2871
|
+
if (error?.stack) {
|
|
2872
|
+
metadata.trace = error.stack;
|
|
2873
|
+
}
|
|
2874
|
+
if (error?.response) {
|
|
2875
|
+
metadata.errorDetails = error.response;
|
|
2876
|
+
}
|
|
2877
|
+
const message = `ERROR ${request.method} ${request.url} ${statusCode} - ${error?.message || "Unknown error"}`;
|
|
2878
|
+
this.logger.logWithMetadata("error", message, metadata);
|
|
2879
|
+
} catch (loggingError) {
|
|
2880
|
+
this.logger.error("Failed to log HTTP error", loggingError.stack);
|
|
2881
|
+
}
|
|
2882
|
+
}
|
|
2883
|
+
};
|
|
2884
|
+
HttpLoggerInterceptor = _ts_decorate16([
|
|
2885
|
+
(0, import_common40.Injectable)(),
|
|
2886
|
+
_ts_param5(1, (0, import_common40.Optional)()),
|
|
2887
|
+
_ts_metadata10("design:type", Function),
|
|
2888
|
+
_ts_metadata10("design:paramtypes", [
|
|
2889
|
+
typeof LoggerService === "undefined" ? Object : LoggerService,
|
|
2890
|
+
typeof HttpLoggerOptions === "undefined" ? Object : HttpLoggerOptions
|
|
2891
|
+
])
|
|
2892
|
+
], HttpLoggerInterceptor);
|
|
2893
|
+
|
|
2894
|
+
// src/logger/logger.module.ts
|
|
2895
|
+
function _ts_decorate17(decorators, target, key, desc) {
|
|
2896
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2897
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2898
|
+
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;
|
|
2899
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2900
|
+
}
|
|
2901
|
+
__name(_ts_decorate17, "_ts_decorate");
|
|
2902
|
+
var LOGGER_MODULE_OPTIONS = Symbol("LOGGER_MODULE_OPTIONS");
|
|
2903
|
+
var DEFAULT_LOGGER_OPTIONS = {
|
|
2904
|
+
provider: "winston",
|
|
2905
|
+
enableCorrelationId: true,
|
|
2906
|
+
enableHttpLogger: true,
|
|
2907
|
+
filePath: "./logs",
|
|
2908
|
+
maxFiles: "14d"
|
|
2909
|
+
};
|
|
2910
|
+
var ENVIRONMENT_PRESETS = {
|
|
2911
|
+
/**
|
|
2912
|
+
* Development preset - maximum verbosity for local development
|
|
2913
|
+
*/
|
|
2914
|
+
development: {
|
|
2915
|
+
provider: "winston",
|
|
2916
|
+
level: "debug",
|
|
2917
|
+
format: "text",
|
|
2918
|
+
enableFileLogger: false,
|
|
2919
|
+
enableCorrelationId: true,
|
|
2920
|
+
enableHttpLogger: true,
|
|
2921
|
+
httpLogger: {
|
|
2922
|
+
enableRequestLog: true,
|
|
2923
|
+
enableResponseLog: true,
|
|
2924
|
+
slowRequestThreshold: 1e3
|
|
2925
|
+
}
|
|
2926
|
+
},
|
|
2927
|
+
/**
|
|
2928
|
+
* Staging preset - moderate verbosity with file logging
|
|
2929
|
+
*/
|
|
2930
|
+
staging: {
|
|
2931
|
+
provider: "winston",
|
|
2932
|
+
level: "log",
|
|
2933
|
+
format: "json",
|
|
2934
|
+
enableFileLogger: true,
|
|
2935
|
+
enableCorrelationId: true,
|
|
2936
|
+
enableHttpLogger: true,
|
|
2937
|
+
httpLogger: {
|
|
2938
|
+
enableRequestLog: true,
|
|
2939
|
+
enableResponseLog: true,
|
|
2940
|
+
slowRequestThreshold: 3e3
|
|
2941
|
+
}
|
|
2942
|
+
},
|
|
2943
|
+
/**
|
|
2944
|
+
* Production preset - minimal verbosity with all safety features enabled
|
|
2945
|
+
*/
|
|
2946
|
+
production: {
|
|
2947
|
+
provider: "winston",
|
|
2948
|
+
level: "warn",
|
|
2949
|
+
format: "json",
|
|
2950
|
+
enableFileLogger: true,
|
|
2951
|
+
enableCorrelationId: true,
|
|
2952
|
+
enableHttpLogger: true,
|
|
2953
|
+
httpLogger: {
|
|
2954
|
+
enableRequestLog: false,
|
|
2955
|
+
enableResponseLog: true,
|
|
2956
|
+
slowRequestThreshold: 5e3
|
|
2957
|
+
}
|
|
2958
|
+
},
|
|
2959
|
+
/**
|
|
2960
|
+
* Test preset - errors only, minimal features for faster test execution
|
|
2961
|
+
*/
|
|
2962
|
+
test: {
|
|
2963
|
+
provider: "winston",
|
|
2964
|
+
level: "error",
|
|
2965
|
+
format: "json",
|
|
2966
|
+
enableFileLogger: false,
|
|
2967
|
+
enableCorrelationId: false,
|
|
2968
|
+
enableHttpLogger: false
|
|
2969
|
+
}
|
|
2970
|
+
};
|
|
2971
|
+
function mergeWithDefaults(options = {}) {
|
|
2972
|
+
const preset = options.environment ? ENVIRONMENT_PRESETS[options.environment] ?? ENVIRONMENT_PRESETS.development : ENVIRONMENT_PRESETS.development;
|
|
2973
|
+
const filteredOptions = Object.fromEntries(Object.entries(options).filter(([_, value]) => value !== void 0));
|
|
2974
|
+
if (filteredOptions.httpLogger && preset?.httpLogger) {
|
|
2975
|
+
filteredOptions.httpLogger = {
|
|
2976
|
+
...preset.httpLogger,
|
|
2977
|
+
...Object.fromEntries(Object.entries(filteredOptions.httpLogger).filter(([_, value]) => value !== void 0))
|
|
2978
|
+
};
|
|
2979
|
+
}
|
|
2980
|
+
const merged = {
|
|
2981
|
+
...DEFAULT_LOGGER_OPTIONS,
|
|
2982
|
+
...preset,
|
|
2983
|
+
...filteredOptions
|
|
2984
|
+
};
|
|
2985
|
+
return merged;
|
|
2986
|
+
}
|
|
2987
|
+
__name(mergeWithDefaults, "mergeWithDefaults");
|
|
2988
|
+
function createDefaultLoggerProvider(options) {
|
|
2989
|
+
return {
|
|
2990
|
+
provide: import_common41.Logger,
|
|
2991
|
+
useFactory: /* @__PURE__ */ __name(() => {
|
|
2992
|
+
const logger = new import_common41.Logger();
|
|
2993
|
+
if (options.level && typeof logger.setLogLevels === "function") {
|
|
2994
|
+
const levels = getLevelsUpTo(options.level);
|
|
2995
|
+
logger.setLogLevels(levels);
|
|
2996
|
+
}
|
|
2997
|
+
return logger;
|
|
2998
|
+
}, "useFactory")
|
|
2999
|
+
};
|
|
3000
|
+
}
|
|
3001
|
+
__name(createDefaultLoggerProvider, "createDefaultLoggerProvider");
|
|
3002
|
+
function createLoggerProviders(options = {}) {
|
|
3003
|
+
const mergedOptions = mergeWithDefaults(options);
|
|
3004
|
+
const providers = [
|
|
3005
|
+
// Options provider
|
|
3006
|
+
{
|
|
3007
|
+
provide: LOGGER_MODULE_OPTIONS,
|
|
3008
|
+
useValue: mergedOptions
|
|
3009
|
+
}
|
|
3010
|
+
];
|
|
3011
|
+
if (mergedOptions.provider === "default") {
|
|
3012
|
+
providers.push(createDefaultLoggerProvider(mergedOptions));
|
|
3013
|
+
}
|
|
3014
|
+
providers.push({
|
|
3015
|
+
provide: LoggerService2,
|
|
3016
|
+
useFactory: /* @__PURE__ */ __name((opts, defaultLogger) => {
|
|
3017
|
+
return new LoggerService2(opts, defaultLogger);
|
|
3018
|
+
}, "useFactory"),
|
|
3019
|
+
inject: [
|
|
3020
|
+
LOGGER_MODULE_OPTIONS,
|
|
3021
|
+
{
|
|
3022
|
+
token: import_common41.Logger,
|
|
3023
|
+
optional: true
|
|
3024
|
+
}
|
|
3025
|
+
]
|
|
3026
|
+
});
|
|
3027
|
+
providers.push({
|
|
3028
|
+
provide: CorrelationIdMiddleware,
|
|
3029
|
+
useFactory: /* @__PURE__ */ __name(() => {
|
|
3030
|
+
return new CorrelationIdMiddleware({
|
|
3031
|
+
includeInResponse: true,
|
|
3032
|
+
responseHeader: "x-correlation-id"
|
|
3033
|
+
});
|
|
3034
|
+
}, "useFactory")
|
|
3035
|
+
});
|
|
3036
|
+
providers.push({
|
|
3037
|
+
provide: HttpLoggerInterceptor,
|
|
3038
|
+
useFactory: /* @__PURE__ */ __name((logger, opts) => {
|
|
3039
|
+
const httpLoggerOptions = opts.httpLogger ?? {
|
|
3040
|
+
enableRequestLog: opts.enableHttpLogger,
|
|
3041
|
+
enableResponseLog: opts.enableHttpLogger
|
|
3042
|
+
};
|
|
3043
|
+
return new HttpLoggerInterceptor(logger, httpLoggerOptions);
|
|
3044
|
+
}, "useFactory"),
|
|
3045
|
+
inject: [
|
|
3046
|
+
LoggerService2,
|
|
3047
|
+
LOGGER_MODULE_OPTIONS
|
|
3048
|
+
]
|
|
3049
|
+
});
|
|
3050
|
+
return providers;
|
|
3051
|
+
}
|
|
3052
|
+
__name(createLoggerProviders, "createLoggerProviders");
|
|
3053
|
+
function getLevelsUpTo(level) {
|
|
3054
|
+
const allLevels = [
|
|
3055
|
+
"error",
|
|
3056
|
+
"warn",
|
|
3057
|
+
"log",
|
|
3058
|
+
"debug",
|
|
3059
|
+
"verbose"
|
|
3060
|
+
];
|
|
3061
|
+
const levelIndex = allLevels.indexOf(level);
|
|
3062
|
+
if (levelIndex === -1) {
|
|
3063
|
+
return [
|
|
3064
|
+
"error",
|
|
3065
|
+
"warn",
|
|
3066
|
+
"log"
|
|
3067
|
+
];
|
|
3068
|
+
}
|
|
3069
|
+
return allLevels.slice(0, levelIndex + 1);
|
|
3070
|
+
}
|
|
3071
|
+
__name(getLevelsUpTo, "getLevelsUpTo");
|
|
3072
|
+
var LoggerModule = class _LoggerModule {
|
|
3073
|
+
static {
|
|
3074
|
+
__name(this, "LoggerModule");
|
|
3075
|
+
}
|
|
3076
|
+
/**
|
|
3077
|
+
* Configures the logger module with static options.
|
|
3078
|
+
*
|
|
3079
|
+
* Users must explicitly pass `environment` to select a preset.
|
|
3080
|
+
* All preset values can be overridden by passing explicit options.
|
|
3081
|
+
*
|
|
3082
|
+
* @param options - Logger configuration options
|
|
3083
|
+
* @returns Dynamic module configuration
|
|
3084
|
+
*
|
|
3085
|
+
* @example
|
|
3086
|
+
* ```typescript
|
|
3087
|
+
* // Production preset with app name
|
|
3088
|
+
* LoggerModule.forRoot({
|
|
3089
|
+
* environment: 'production',
|
|
3090
|
+
* appName: 'my-service'
|
|
3091
|
+
* })
|
|
3092
|
+
*
|
|
3093
|
+
* // Development preset with custom level
|
|
3094
|
+
* LoggerModule.forRoot({
|
|
3095
|
+
* environment: 'development',
|
|
3096
|
+
* level: 'verbose',
|
|
3097
|
+
* enableFileLogger: true
|
|
3098
|
+
* })
|
|
3099
|
+
*
|
|
3100
|
+
* // Use default NestJS logger
|
|
3101
|
+
* LoggerModule.forRoot({
|
|
3102
|
+
* provider: 'default',
|
|
3103
|
+
* environment: 'development'
|
|
3104
|
+
* })
|
|
3105
|
+
* ```
|
|
3106
|
+
*/
|
|
3107
|
+
static forRoot(options = {}) {
|
|
3108
|
+
const providers = createLoggerProviders(options);
|
|
3109
|
+
return {
|
|
3110
|
+
module: _LoggerModule,
|
|
3111
|
+
providers,
|
|
3112
|
+
exports: [
|
|
3113
|
+
LoggerService2,
|
|
3114
|
+
CorrelationIdMiddleware,
|
|
3115
|
+
HttpLoggerInterceptor,
|
|
3116
|
+
LOGGER_MODULE_OPTIONS
|
|
3117
|
+
]
|
|
3118
|
+
};
|
|
3119
|
+
}
|
|
3120
|
+
/**
|
|
3121
|
+
* Configures the logger module with async options.
|
|
3122
|
+
*
|
|
3123
|
+
* Supports dynamic configuration using:
|
|
3124
|
+
* - `useFactory`: Factory function with dependency injection
|
|
3125
|
+
* - `useClass`: Class implementing `LoggerOptionsFactory`
|
|
3126
|
+
* - `useExisting`: Existing provider implementing `LoggerOptionsFactory`
|
|
3127
|
+
*
|
|
3128
|
+
* Options from the factory/class are merged with environment preset defaults.
|
|
3129
|
+
*
|
|
3130
|
+
* @param options - Async configuration options
|
|
3131
|
+
* @returns Dynamic module configuration
|
|
3132
|
+
*
|
|
3133
|
+
* @example
|
|
3134
|
+
* ```typescript
|
|
3135
|
+
* // Factory with ConfigService
|
|
3136
|
+
* LoggerModule.forRootAsync({
|
|
3137
|
+
* imports: [ConfigModule],
|
|
3138
|
+
* useFactory: (config: ConfigService) => ({
|
|
3139
|
+
* environment: config.get('NODE_ENV', 'development'),
|
|
3140
|
+
* provider: config.get('LOG_PROVIDER', 'winston'),
|
|
3141
|
+
* level: config.get('LOG_LEVEL'),
|
|
3142
|
+
* appName: config.get('APP_NAME'),
|
|
3143
|
+
* }),
|
|
3144
|
+
* inject: [ConfigService]
|
|
3145
|
+
* })
|
|
3146
|
+
*
|
|
3147
|
+
* // Factory class
|
|
3148
|
+
* @Injectable()
|
|
3149
|
+
* class LoggerConfigService implements LoggerOptionsFactory {
|
|
3150
|
+
* createLoggerOptions(): LoggerModuleOptions {
|
|
3151
|
+
* return {
|
|
3152
|
+
* environment: 'production',
|
|
3153
|
+
* appName: 'my-service'
|
|
3154
|
+
* };
|
|
3155
|
+
* }
|
|
3156
|
+
* }
|
|
3157
|
+
*
|
|
3158
|
+
* LoggerModule.forRootAsync({
|
|
3159
|
+
* useClass: LoggerConfigService
|
|
3160
|
+
* })
|
|
3161
|
+
* ```
|
|
3162
|
+
*/
|
|
3163
|
+
static forRootAsync(options) {
|
|
3164
|
+
const asyncProviders = this.createAsyncProviders(options);
|
|
3165
|
+
return {
|
|
3166
|
+
module: _LoggerModule,
|
|
3167
|
+
imports: options.imports || [],
|
|
3168
|
+
providers: [
|
|
3169
|
+
...asyncProviders,
|
|
3170
|
+
// Default logger provider
|
|
3171
|
+
{
|
|
3172
|
+
provide: import_common41.Logger,
|
|
3173
|
+
useFactory: /* @__PURE__ */ __name((opts) => {
|
|
3174
|
+
if (opts.provider === "default") {
|
|
3175
|
+
const logger = new import_common41.Logger();
|
|
3176
|
+
if (opts.level && typeof logger.setLogLevels === "function") {
|
|
3177
|
+
const levels = getLevelsUpTo(opts.level);
|
|
3178
|
+
logger.setLogLevels(levels);
|
|
3179
|
+
}
|
|
3180
|
+
return logger;
|
|
3181
|
+
}
|
|
3182
|
+
return null;
|
|
3183
|
+
}, "useFactory"),
|
|
3184
|
+
inject: [
|
|
3185
|
+
LOGGER_MODULE_OPTIONS
|
|
3186
|
+
]
|
|
3187
|
+
},
|
|
3188
|
+
// Unified logger service
|
|
3189
|
+
{
|
|
3190
|
+
provide: LoggerService2,
|
|
3191
|
+
useFactory: /* @__PURE__ */ __name((opts, defaultLogger) => {
|
|
3192
|
+
return new LoggerService2(opts, defaultLogger);
|
|
3193
|
+
}, "useFactory"),
|
|
3194
|
+
inject: [
|
|
3195
|
+
LOGGER_MODULE_OPTIONS,
|
|
3196
|
+
{
|
|
3197
|
+
token: import_common41.Logger,
|
|
3198
|
+
optional: true
|
|
3199
|
+
}
|
|
3200
|
+
]
|
|
3201
|
+
},
|
|
3202
|
+
// Correlation ID middleware
|
|
3203
|
+
{
|
|
3204
|
+
provide: CorrelationIdMiddleware,
|
|
3205
|
+
useFactory: /* @__PURE__ */ __name(() => {
|
|
3206
|
+
return new CorrelationIdMiddleware({
|
|
3207
|
+
includeInResponse: true,
|
|
3208
|
+
responseHeader: "x-correlation-id"
|
|
3209
|
+
});
|
|
3210
|
+
}, "useFactory")
|
|
3211
|
+
},
|
|
3212
|
+
// HTTP logger interceptor
|
|
3213
|
+
{
|
|
3214
|
+
provide: HttpLoggerInterceptor,
|
|
3215
|
+
useFactory: /* @__PURE__ */ __name((logger, opts) => {
|
|
3216
|
+
const httpLoggerOptions = opts.httpLogger ?? {
|
|
3217
|
+
enableRequestLog: opts.enableHttpLogger,
|
|
3218
|
+
enableResponseLog: opts.enableHttpLogger
|
|
3219
|
+
};
|
|
3220
|
+
return new HttpLoggerInterceptor(logger, httpLoggerOptions);
|
|
3221
|
+
}, "useFactory"),
|
|
3222
|
+
inject: [
|
|
3223
|
+
LoggerService2,
|
|
3224
|
+
LOGGER_MODULE_OPTIONS
|
|
3225
|
+
]
|
|
3226
|
+
}
|
|
3227
|
+
],
|
|
3228
|
+
exports: [
|
|
3229
|
+
LoggerService2,
|
|
3230
|
+
CorrelationIdMiddleware,
|
|
3231
|
+
HttpLoggerInterceptor,
|
|
3232
|
+
LOGGER_MODULE_OPTIONS
|
|
3233
|
+
]
|
|
3234
|
+
};
|
|
3235
|
+
}
|
|
3236
|
+
/**
|
|
3237
|
+
* Configures middleware for the module.
|
|
3238
|
+
* Middleware is registered globally in main.ts using Fastify hooks.
|
|
3239
|
+
*/
|
|
3240
|
+
configure(consumer) {
|
|
3241
|
+
}
|
|
3242
|
+
/**
|
|
3243
|
+
* Creates async providers for dynamic module configuration.
|
|
3244
|
+
*/
|
|
3245
|
+
static createAsyncProviders(options) {
|
|
3246
|
+
if (options.useFactory) {
|
|
3247
|
+
return [
|
|
3248
|
+
this.createAsyncOptionsProvider(options)
|
|
3249
|
+
];
|
|
3250
|
+
}
|
|
3251
|
+
const providers = [
|
|
3252
|
+
this.createAsyncOptionsProvider(options)
|
|
3253
|
+
];
|
|
3254
|
+
if (options.useClass) {
|
|
3255
|
+
providers.push({
|
|
3256
|
+
provide: options.useClass,
|
|
3257
|
+
useClass: options.useClass
|
|
3258
|
+
});
|
|
3259
|
+
}
|
|
3260
|
+
return providers;
|
|
3261
|
+
}
|
|
3262
|
+
/**
|
|
3263
|
+
* Creates the async options provider.
|
|
3264
|
+
*/
|
|
3265
|
+
static createAsyncOptionsProvider(options) {
|
|
3266
|
+
if (options.useFactory) {
|
|
3267
|
+
return {
|
|
3268
|
+
provide: LOGGER_MODULE_OPTIONS,
|
|
3269
|
+
useFactory: /* @__PURE__ */ __name(async (...args) => {
|
|
3270
|
+
const userOptions = await options.useFactory(...args);
|
|
3271
|
+
return mergeWithDefaults(userOptions);
|
|
3272
|
+
}, "useFactory"),
|
|
3273
|
+
inject: options.inject || []
|
|
3274
|
+
};
|
|
3275
|
+
}
|
|
3276
|
+
if (options.useClass) {
|
|
3277
|
+
return {
|
|
3278
|
+
provide: LOGGER_MODULE_OPTIONS,
|
|
3279
|
+
useFactory: /* @__PURE__ */ __name(async (optionsFactory) => {
|
|
3280
|
+
const userOptions = await optionsFactory.createLoggerOptions();
|
|
3281
|
+
return mergeWithDefaults(userOptions);
|
|
3282
|
+
}, "useFactory"),
|
|
3283
|
+
inject: [
|
|
3284
|
+
options.useClass
|
|
3285
|
+
]
|
|
3286
|
+
};
|
|
3287
|
+
}
|
|
3288
|
+
if (options.useExisting) {
|
|
3289
|
+
return {
|
|
3290
|
+
provide: LOGGER_MODULE_OPTIONS,
|
|
3291
|
+
useFactory: /* @__PURE__ */ __name(async (optionsFactory) => {
|
|
3292
|
+
const userOptions = await optionsFactory.createLoggerOptions();
|
|
3293
|
+
return mergeWithDefaults(userOptions);
|
|
3294
|
+
}, "useFactory"),
|
|
3295
|
+
inject: [
|
|
3296
|
+
options.useExisting
|
|
3297
|
+
]
|
|
3298
|
+
};
|
|
2526
3299
|
}
|
|
3300
|
+
throw new Error("LoggerModule.forRootAsync() requires one of: useFactory, useClass, or useExisting");
|
|
2527
3301
|
}
|
|
2528
3302
|
};
|
|
3303
|
+
LoggerModule = _ts_decorate17([
|
|
3304
|
+
(0, import_common41.Global)(),
|
|
3305
|
+
(0, import_common41.Module)({})
|
|
3306
|
+
], LoggerModule);
|
|
2529
3307
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2530
3308
|
0 && (module.exports = {
|
|
2531
3309
|
AuthConfigModule,
|
|
@@ -2533,13 +3311,19 @@ var BadGatewayException = class extends BaseFieldException {
|
|
|
2533
3311
|
BadRequestException,
|
|
2534
3312
|
BaseFieldException,
|
|
2535
3313
|
ConflictException,
|
|
3314
|
+
CorrelationIdMiddleware,
|
|
2536
3315
|
CsrfGuard,
|
|
3316
|
+
DEFAULT_CORRELATION_HEADER,
|
|
2537
3317
|
DatabaseModule,
|
|
2538
3318
|
ForbiddenException,
|
|
2539
3319
|
GoneException,
|
|
2540
3320
|
HttpExceptionFilter,
|
|
3321
|
+
HttpLoggerInterceptor,
|
|
2541
3322
|
HttpModule,
|
|
2542
3323
|
InternalServerErrorException,
|
|
3324
|
+
LOGGER_MODULE_OPTIONS,
|
|
3325
|
+
LoggerModule,
|
|
3326
|
+
LoggerService,
|
|
2543
3327
|
MethodNotAllowedException,
|
|
2544
3328
|
NotAcceptableException,
|
|
2545
3329
|
NotFoundException,
|
|
@@ -2561,6 +3345,12 @@ var BadGatewayException = class extends BaseFieldException {
|
|
|
2561
3345
|
UnsupportedMediaTypeException,
|
|
2562
3346
|
ValidationException,
|
|
2563
3347
|
VrittiAuthGuard,
|
|
2564
|
-
|
|
3348
|
+
addCorrelationIdToResponse,
|
|
3349
|
+
correlationStorage,
|
|
3350
|
+
generateCorrelationId,
|
|
3351
|
+
getCorrelationContext,
|
|
3352
|
+
getHttpStatusTitle,
|
|
3353
|
+
runWithCorrelationContext,
|
|
3354
|
+
updateCorrelationContext
|
|
2565
3355
|
});
|
|
2566
3356
|
//# sourceMappingURL=index.cjs.map
|