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